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

View file

@ -19,8 +19,10 @@ import Utility.DataUnits
import Types.Key
def :: [Command]
def = [noCommit $ noMessages $ withOptions [formatOption, print0Option, jsonOption] $
command "find" paramPaths seek SectionQuery "lists available files"]
def = [mkCommand $ command "find" paramPaths seek SectionQuery "lists available files"]
mkCommand :: Command -> Command
mkCommand = noCommit . noMessages . withOptions [formatOption, print0Option, jsonOption]
formatOption :: Option
formatOption = fieldOption [] "format" paramFormat "control format of output"

20
Command/FindRef.hs Normal file
View file

@ -0,0 +1,20 @@
{- git-annex command
-
- Copyright 2014 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.FindRef where
import Command
import qualified Command.Find as Find
def :: [Command]
def = [Find.mkCommand $ command "findref" paramRef seek SectionPlumbing
"lists files in a git ref"]
seek :: CommandSeek
seek refs = do
format <- Find.getFormat
Find.start format `withFilesInRefs` refs

1
debian/changelog vendored
View file

@ -28,6 +28,7 @@ git-annex (5.20140413) UNRELEASED; urgency=medium
unncessarily losing file permissions on non-crippled systems.
* webapp: Start even if the current directory is listed in
~/.config/git-annex/autostart but no longer has a git repository in it.
* findref: New command, like find but shows files in a specified git ref.
-- Joey Hess <joeyh@debian.org> Fri, 11 Apr 2014 21:33:35 -0400

View file

@ -927,6 +927,14 @@ subdirectories).
With `--force`, even files whose content is not currently available will
be rekeyed. Use with caution.
* `findref [ref]`
This is similar to the find command, but instead of finding files in the
current work tree, it finds files in the specified git ref.
Most MATCHING OPTIONS can be used with findref, to limit the files it
finds. However, the --include and --exclude options will not work.
* `test`
This runs git-annex's built-in test suite.