add reflog

This commit is contained in:
Joey Hess 2013-10-21 16:41:46 -04:00
parent 18487c779f
commit 2fb08acda5
3 changed files with 36 additions and 19 deletions

View file

@ -23,6 +23,7 @@ import qualified Git.Config
import qualified Git.Construct import qualified Git.Construct
import qualified Git.LsTree as LsTree import qualified Git.LsTree as LsTree
import qualified Git.Ref as Ref import qualified Git.Ref as Ref
import qualified Git.RefLog as RefLog
import Utility.Tmp import Utility.Tmp
import Utility.Rsync import Utility.Rsync
@ -186,16 +187,8 @@ resetLocalBranches missing goodcommits r =
reset b c reset b c
go (b:changed) deleted gcs' bs go (b:changed) deleted gcs' bs
Nothing -> do Nothing -> do
(mc', gcs'') <- findOldBranch missing gcs' b r nukeBranchRef b r
case mc' of go changed (b:deleted) gcs' bs
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
reset b c = do reset b c = do
nukeBranchRef b r nukeBranchRef b r
void $ runBool 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 {- 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. - 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 - 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 :: MissingObjects -> GoodCommits -> Branch -> Repo -> IO (Maybe Sha, GoodCommits)
findUncorruptedCommit missing goodcommits branch r = do findUncorruptedCommit missing goodcommits branch r = do
@ -288,7 +283,12 @@ findUncorruptedCommit missing goodcommits branch r = do
, Param "--format=%H" , Param "--format=%H"
, Param (show branch) , Param (show branch)
] r ] 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 where
findfirst gcs [] = return (Nothing, gcs) findfirst gcs [] = return (Nothing, gcs)
findfirst gcs (c:cs) = do findfirst gcs (c:cs) = do
@ -297,12 +297,6 @@ findUncorruptedCommit missing goodcommits branch r = do
then return (Just c, gcs') then return (Just c, gcs')
else findfirst gcs' cs 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 {- 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 - 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 - be good, which can be passed into subsequent calls to avoid

23
Git/RefLog.hs Normal file
View file

@ -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)
]

View file

@ -35,7 +35,7 @@ parseArgs = do
enableDebugOutput :: IO () enableDebugOutput :: IO ()
enableDebugOutput = do enableDebugOutput = do
s <- setFormatter s <- setFormatter
<$> streamHandler stderr DEBUG -- NOTICE <$> streamHandler stderr NOTICE
<*> pure (simpleLogFormatter "$msg") <*> pure (simpleLogFormatter "$msg")
updateGlobalLogger rootLoggerName (setLevel DEBUG . setHandlers [s]) updateGlobalLogger rootLoggerName (setLevel DEBUG . setHandlers [s])