From 051810ad0afddde24ff4a54d03928d98f00ed094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 17 May 2026 10:46:55 +0200 Subject: Repo: merge base and more flexible commit litsing --- src/Repo.hs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Repo.hs b/src/Repo.hs index c878b1e..4222f2f 100644 --- a/src/Repo.hs +++ b/src/Repo.hs @@ -13,7 +13,8 @@ module Repo ( readTree, readTreeId, tryReadTree, readBranch, readTag, - listCommits, + listCommits, listCommitsFrom, + mergeBase, findUpstreamRef, getCommitTree, @@ -231,12 +232,33 @@ readTag repo tag = do listCommits :: MonadIO m => Repo -> Text -> m [ Commit ] listCommits commitRepo range = liftIO $ do - out <- runGitCommand commitRepo [ "log", "--pretty=%H", "--first-parent", "--reverse", T.unpack range ] + out <- runGitCommand commitRepo [ "rev-list", "--first-parent", "--reverse", T.unpack range ] forM (lines out) $ \cid -> do let commitId_ = CommitId (BC.pack cid) commitDetails <- newMVar Nothing return Commit {..} +listCommitsFrom :: MonadIO m => Repo -> [ CommitId ] -> [ CommitId ] -> m [ Commit ] +listCommitsFrom commitRepo from except = liftIO $ do + out <- runGitCommand commitRepo $ concat + [ [ "rev-list", "--first-parent", "--reverse" ] + , map showCommitId from + , "--not" : map showCommitId except + ] + forM (lines out) $ \cid -> do + let commitId_ = CommitId (BC.pack cid) + commitDetails <- newMVar Nothing + return Commit {..} + +mergeBase :: MonadIO m => Repo -> [ CommitId ] -> m [ Commit ] +mergeBase commitRepo cids = liftIO $ do + out <- runGitCommand commitRepo $ "merge-base" : "--all" : "--octopus" : map showCommitId cids + forM (lines out) $ \cid -> do + let commitId_ = CommitId (BC.pack cid) + commitDetails <- newMVar Nothing + return Commit {..} + + findUpstreamRef :: MonadIO m => Repo -> Text -> m (Maybe Text) findUpstreamRef repo@GitRepo {..} ref = liftIO $ do deref <- readProcessWithExitCode "git" [ "--git-dir=" <> gitDir, "symbolic-ref", "--quiet", T.unpack ref ] "" >>= \case -- cgit v1.2.3