findref: New command, like find but shows files in a specified git ref.

This commit is contained in:
Joey Hess 2014-04-17 18:41:24 -04:00
parent e880d0d22c
commit ecc3dc8433
7 changed files with 53 additions and 2 deletions

View file

@ -49,6 +49,7 @@ import qualified Command.Unlock
import qualified Command.Lock
import qualified Command.PreCommit
import qualified Command.Find
import qualified Command.FindRef
import qualified Command.Whereis
import qualified Command.List
import qualified Command.Log
@ -158,6 +159,7 @@ cmds = concat
, Command.DropUnused.def
, Command.AddUnused.def
, Command.Find.def
, Command.FindRef.def
, Command.Whereis.def
, Command.List.def
, Command.Log.def

View file

@ -19,6 +19,8 @@ import qualified Annex
import qualified Git
import qualified Git.Command
import qualified Git.LsFiles as LsFiles
import qualified Git.LsTree as LsTree
import Git.FilePath
import qualified Limit
import CmdLine.Option
import CmdLine.Action
@ -49,6 +51,20 @@ withFilesNotInGit skipdotfiles a params
go l = seekActions $ prepFiltered a $
return $ concat $ segmentPaths params l
withFilesInRefs :: (FilePath -> Key -> CommandStart) -> CommandSeek
withFilesInRefs a = mapM_ go
where
go r = do
matcher <- Limit.getMatcher
l <- inRepo $ LsTree.lsTree (Git.Ref r)
forM_ l $ \i -> do
let f = getTopFilePath $ LsTree.file i
v <- catKey (Git.Ref $ LsTree.sha i) (LsTree.mode i)
case v of
Nothing -> noop
Just k -> whenM (matcher $ MatchingKey k) $
void $ commandAction $ a f k
withPathContents :: ((FilePath, FilePath) -> CommandStart) -> CommandSeek
withPathContents a params = seekActions $
map a . concat <$> liftIO (mapM get params)

View file

@ -93,6 +93,8 @@ paramFormat :: String
paramFormat = "FORMAT"
paramFile :: String
paramFile = "FILE"
paramRef :: String
paramRef = "REF"
paramGroup :: String
paramGroup = "GROUP"
paramExpression :: String