have whereused also check the reflog
Since the stash is part of that, it can also find stashed content. Sponsored-by: Boyd Stephen Smith Jr. on Patreon
This commit is contained in:
parent
8c0ac094ed
commit
d6f056eca3
2 changed files with 73 additions and 53 deletions
|
@ -76,57 +76,75 @@ display key loc = putStrLn (serializeKey key ++ " " ++ loc)
|
||||||
|
|
||||||
findHistorical :: Key -> Annex ()
|
findHistorical :: Key -> Annex ()
|
||||||
findHistorical key = do
|
findHistorical key = do
|
||||||
Annex.inRepo $ \repo -> do
|
-- Find most recent change to the key, in all branches and
|
||||||
-- Find most recent change to the key, in all branches and
|
-- tags, except the git-annex branch.
|
||||||
-- tags, except the git-annex branch.
|
found <- searchLog key
|
||||||
(output, cleanup) <- Git.Command.pipeNullSplit
|
-- Search all local branches, except git-annex branch.
|
||||||
[ Param "log"
|
[ Param ("--exclude=*/" ++ fromRef (Annex.Branch.name))
|
||||||
, Param "-z"
|
, Param "--glob=*"
|
||||||
-- Don't convert pointer files.
|
-- Also search remote branches
|
||||||
, Param "--no-textconv"
|
, Param ("--exclude=" ++ fromRef (Annex.Branch.name))
|
||||||
-- Only find the most recent commit, for speed.
|
, Param "--remotes=*"
|
||||||
, Param "-n1"
|
-- And search tags.
|
||||||
-- Find commits that contain the key.
|
, Param "--tags=*"
|
||||||
, Param ("-S" ++ fromRawFilePath (keyFile key))
|
-- Output the commit hash
|
||||||
-- Skip commits where the file was deleted,
|
, Param "--pretty=%H"
|
||||||
-- only find those where it was added or modified.
|
] $ \h fs repo -> do
|
||||||
, Param "--diff-filter=ACMRTUX"
|
commitsha <- getSha "log" (pure h)
|
||||||
-- Search all local branches, except git-annex branch.
|
commitdesc <- S.takeWhile (/= fromIntegral (ord '\n'))
|
||||||
, Param ("--exclude=*/" ++ fromRef (Annex.Branch.name))
|
<$> Git.Command.pipeReadStrict
|
||||||
, Param "--glob=*"
|
[ Param "describe"
|
||||||
-- Also search remote branches
|
, Param "--contains"
|
||||||
, Param ("--exclude=" ++ fromRef (Annex.Branch.name))
|
, Param "--all"
|
||||||
, Param "--remotes=*"
|
, Param (fromRef commitsha)
|
||||||
-- And search tags.
|
] repo
|
||||||
, Param "--tags=*"
|
if S.null commitdesc
|
||||||
-- Output the commit hash
|
then return False
|
||||||
, Param "--pretty=%H"
|
else process fs $
|
||||||
-- And the raw diff.
|
displayreffile (Ref commitdesc)
|
||||||
, Param "--raw"
|
|
||||||
-- Don't abbreviate hashes.
|
|
||||||
, Param "--no-abbrev"
|
|
||||||
] repo
|
|
||||||
found <- case output of
|
|
||||||
(h:rest) -> do
|
|
||||||
commitsha <- getSha "log" (pure (L.toStrict h))
|
|
||||||
let diff = DiffTree.parseDiffRaw rest
|
|
||||||
forM_ (map (flip fromTopFilePath repo . DiffTree.file) diff) $ \f -> do
|
|
||||||
commitdesc <- S.takeWhile (/= fromIntegral (ord '\n'))
|
|
||||||
<$> Git.Command.pipeReadStrict
|
|
||||||
[ Param "describe"
|
|
||||||
, Param "--contains"
|
|
||||||
, Param "--all"
|
|
||||||
, Param (fromRef commitsha)
|
|
||||||
] repo
|
|
||||||
if S.null commitdesc
|
|
||||||
then return False
|
|
||||||
else do
|
|
||||||
rf <- relPathCwdToFile f
|
|
||||||
let fref = Git.Ref.branchFileRef (Ref commitdesc) rf
|
|
||||||
display key (fromRef fref)
|
|
||||||
return True
|
|
||||||
_ -> return False
|
|
||||||
void cleanup
|
|
||||||
|
|
||||||
unless found $ do
|
unless found $
|
||||||
error "todo reflog"
|
void $ searchLog key
|
||||||
|
[ Param "--walk-reflogs"
|
||||||
|
-- Output the reflog selector
|
||||||
|
, Param "--pretty=%gd"
|
||||||
|
] $ \h fs _ -> process fs $
|
||||||
|
displayreffile (Ref h)
|
||||||
|
where
|
||||||
|
process fs a = or <$> forM fs a
|
||||||
|
|
||||||
|
displayreffile r f = do
|
||||||
|
let fref = Git.Ref.branchFileRef r f
|
||||||
|
display key (fromRef fref)
|
||||||
|
return True
|
||||||
|
|
||||||
|
searchLog :: Key -> [CommandParam] -> (S.ByteString -> [RawFilePath] -> Repo -> IO Bool) -> Annex Bool
|
||||||
|
searchLog key ps a = Annex.inRepo $ \repo -> do
|
||||||
|
(output, cleanup) <- Git.Command.pipeNullSplit ps' repo
|
||||||
|
found <- case output of
|
||||||
|
(h:rest) -> do
|
||||||
|
let diff = DiffTree.parseDiffRaw rest
|
||||||
|
let fs = map (flip fromTopFilePath repo . DiffTree.file) diff
|
||||||
|
rfs <- mapM relPathCwdToFile fs
|
||||||
|
a (L.toStrict h) rfs repo
|
||||||
|
_ -> return False
|
||||||
|
void cleanup
|
||||||
|
return found
|
||||||
|
where
|
||||||
|
ps' =
|
||||||
|
[ Param "log"
|
||||||
|
, Param "-z"
|
||||||
|
-- Don't convert pointer files.
|
||||||
|
, Param "--no-textconv"
|
||||||
|
-- Don't abbreviate hashes.
|
||||||
|
, Param "--no-abbrev"
|
||||||
|
-- Only find the most recent commit, for speed.
|
||||||
|
, Param "-n1"
|
||||||
|
-- Find commits that contain the key.
|
||||||
|
, Param ("-S" ++ fromRawFilePath (keyFile key))
|
||||||
|
-- Skip commits where the file was deleted,
|
||||||
|
-- only find those where it was added or modified.
|
||||||
|
, Param "--diff-filter=ACMRTUX"
|
||||||
|
-- Output the raw diff.
|
||||||
|
, Param "--raw"
|
||||||
|
] ++ ps
|
||||||
|
|
|
@ -40,3 +40,5 @@ considers a key used despite a previous git rev referring to it. Eg:
|
||||||
>
|
>
|
||||||
> Or, if it was found in the ref log, take the "HEAD@{n}" from log
|
> Or, if it was found in the ref log, take the "HEAD@{n}" from log
|
||||||
> output, and add ":filename"
|
> output, and add ":filename"
|
||||||
|
|
||||||
|
[[done]] --[[Joey]]
|
||||||
|
|
Loading…
Reference in a new issue