summaryrefslogtreecommitdiff
path: root/Git
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-10-21 16:41:46 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-10-21 16:41:46 -0400
commitc06cf8f140f2c5f461ce38d709777f1390503aa2 (patch)
treee17b771b26125f5959445c6e1413b9e28b3b422d /Git
parentafe0cc0bb4fbe3876c35462dece4670617263877 (diff)
add reflog
Diffstat (limited to 'Git')
-rw-r--r--Git/RecoverRepository.hs30
-rw-r--r--Git/RefLog.hs23
2 files changed, 35 insertions, 18 deletions
diff --git a/Git/RecoverRepository.hs b/Git/RecoverRepository.hs
index 330063abe..8dce04f1e 100644
--- a/Git/RecoverRepository.hs
+++ b/Git/RecoverRepository.hs
@@ -23,6 +23,7 @@ import qualified Git.Config
import qualified Git.Construct
import qualified Git.LsTree as LsTree
import qualified Git.Ref as Ref
+import qualified Git.RefLog as RefLog
import Utility.Tmp
import Utility.Rsync
@@ -186,16 +187,8 @@ resetLocalBranches missing goodcommits r =
reset b c
go (b:changed) deleted gcs' bs
Nothing -> do
- (mc', gcs'') <- findOldBranch missing gcs' b r
- case mc' of
- Just c
- | c == b -> go changed deleted gcs' bs
- | otherwise -> do
- reset b c
- go (b:changed) deleted gcs'' bs
- Nothing -> do
- nukeBranchRef b r
- go changed (b:deleted) gcs'' bs
+ nukeBranchRef b r
+ go changed (b:deleted) gcs' bs
reset b c = do
nukeBranchRef b r
void $ runBool
@@ -274,7 +267,9 @@ nukeBranchRef b r = void $ usegit <||> byhand
{- Finds the most recent commit to a branch that does not need any
- of the missing objects. If the input branch is good as-is, returns it.
- Otherwise, tries to traverse the commits in the branch to find one
- - that is ok (might fail, if one of them is corrupt).
+ - that is ok. That might fail, if one of them is corrupt, or if an object
+ - at the root of the branch is missing. Finally, looks for an old version
+ - of the branch from the reflog.
-}
findUncorruptedCommit :: MissingObjects -> GoodCommits -> Branch -> Repo -> IO (Maybe Sha, GoodCommits)
findUncorruptedCommit missing goodcommits branch r = do
@@ -288,7 +283,12 @@ findUncorruptedCommit missing goodcommits branch r = do
, Param "--format=%H"
, Param (show branch)
] r
- cleanup `after` findfirst goodcommits (catMaybes $ map extractSha ls)
+ let branchshas = catMaybes $ map extractSha ls
+ reflogshas <- RefLog.get branch r
+ -- XXX Could try a bit harder here, and look
+ -- for uncorrupted old commits in branches in the
+ -- reflog.
+ cleanup `after` findfirst goodcommits (branchshas ++ reflogshas)
where
findfirst gcs [] = return (Nothing, gcs)
findfirst gcs (c:cs) = do
@@ -297,12 +297,6 @@ findUncorruptedCommit missing goodcommits branch r = do
then return (Just c, gcs')
else findfirst gcs' cs
-{- Looks through the reflog to find an old version of a branch that
- - does not need any of the missing objects.
- -}
-findOldBranch :: MissingObjects -> GoodCommits -> Branch -> Repo -> IO (Maybe Sha, GoodCommits)
-findOldBranch missing goodcommits branch r = error "TODO"
-
{- Verifies tha none of the missing objects in the set are used by
- the commit. Also adds to a set of commit shas that have been verified to
- be good, which can be passed into subsequent calls to avoid
diff --git a/Git/RefLog.hs b/Git/RefLog.hs
new file mode 100644
index 000000000..7502f14b3
--- /dev/null
+++ b/Git/RefLog.hs
@@ -0,0 +1,23 @@
+{- git reflog interface
+ -
+ - Copyright 2013 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Git.RefLog where
+
+import Common
+import Git
+import Git.Command
+import Git.Sha
+import Git.CatFile
+
+{- Gets the reflog for a given branch. -}
+get :: Branch -> Repo -> IO [Sha]
+get b = mapMaybe extractSha . lines <$$> pipeReadStrict
+ [ Param "log"
+ , Param "-g"
+ , Param "--format=%H"
+ , Param (show b)
+ ]