findref: New command, like find but shows files in a specified git ref.
This commit is contained in:
parent
e880d0d22c
commit
ecc3dc8433
7 changed files with 53 additions and 2 deletions
|
@ -49,6 +49,7 @@ import qualified Command.Unlock
|
||||||
import qualified Command.Lock
|
import qualified Command.Lock
|
||||||
import qualified Command.PreCommit
|
import qualified Command.PreCommit
|
||||||
import qualified Command.Find
|
import qualified Command.Find
|
||||||
|
import qualified Command.FindRef
|
||||||
import qualified Command.Whereis
|
import qualified Command.Whereis
|
||||||
import qualified Command.List
|
import qualified Command.List
|
||||||
import qualified Command.Log
|
import qualified Command.Log
|
||||||
|
@ -158,6 +159,7 @@ cmds = concat
|
||||||
, Command.DropUnused.def
|
, Command.DropUnused.def
|
||||||
, Command.AddUnused.def
|
, Command.AddUnused.def
|
||||||
, Command.Find.def
|
, Command.Find.def
|
||||||
|
, Command.FindRef.def
|
||||||
, Command.Whereis.def
|
, Command.Whereis.def
|
||||||
, Command.List.def
|
, Command.List.def
|
||||||
, Command.Log.def
|
, Command.Log.def
|
||||||
|
|
|
@ -19,6 +19,8 @@ import qualified Annex
|
||||||
import qualified Git
|
import qualified Git
|
||||||
import qualified Git.Command
|
import qualified Git.Command
|
||||||
import qualified Git.LsFiles as LsFiles
|
import qualified Git.LsFiles as LsFiles
|
||||||
|
import qualified Git.LsTree as LsTree
|
||||||
|
import Git.FilePath
|
||||||
import qualified Limit
|
import qualified Limit
|
||||||
import CmdLine.Option
|
import CmdLine.Option
|
||||||
import CmdLine.Action
|
import CmdLine.Action
|
||||||
|
@ -49,6 +51,20 @@ withFilesNotInGit skipdotfiles a params
|
||||||
go l = seekActions $ prepFiltered a $
|
go l = seekActions $ prepFiltered a $
|
||||||
return $ concat $ segmentPaths params l
|
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 :: ((FilePath, FilePath) -> CommandStart) -> CommandSeek
|
||||||
withPathContents a params = seekActions $
|
withPathContents a params = seekActions $
|
||||||
map a . concat <$> liftIO (mapM get params)
|
map a . concat <$> liftIO (mapM get params)
|
||||||
|
|
|
@ -93,6 +93,8 @@ paramFormat :: String
|
||||||
paramFormat = "FORMAT"
|
paramFormat = "FORMAT"
|
||||||
paramFile :: String
|
paramFile :: String
|
||||||
paramFile = "FILE"
|
paramFile = "FILE"
|
||||||
|
paramRef :: String
|
||||||
|
paramRef = "REF"
|
||||||
paramGroup :: String
|
paramGroup :: String
|
||||||
paramGroup = "GROUP"
|
paramGroup = "GROUP"
|
||||||
paramExpression :: String
|
paramExpression :: String
|
||||||
|
|
|
@ -19,8 +19,10 @@ import Utility.DataUnits
|
||||||
import Types.Key
|
import Types.Key
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [noCommit $ noMessages $ withOptions [formatOption, print0Option, jsonOption] $
|
def = [mkCommand $ command "find" paramPaths seek SectionQuery "lists available files"]
|
||||||
command "find" paramPaths seek SectionQuery "lists available files"]
|
|
||||||
|
mkCommand :: Command -> Command
|
||||||
|
mkCommand = noCommit . noMessages . withOptions [formatOption, print0Option, jsonOption]
|
||||||
|
|
||||||
formatOption :: Option
|
formatOption :: Option
|
||||||
formatOption = fieldOption [] "format" paramFormat "control format of output"
|
formatOption = fieldOption [] "format" paramFormat "control format of output"
|
||||||
|
|
20
Command/FindRef.hs
Normal file
20
Command/FindRef.hs
Normal 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
1
debian/changelog
vendored
|
@ -28,6 +28,7 @@ git-annex (5.20140413) UNRELEASED; urgency=medium
|
||||||
unncessarily losing file permissions on non-crippled systems.
|
unncessarily losing file permissions on non-crippled systems.
|
||||||
* webapp: Start even if the current directory is listed in
|
* webapp: Start even if the current directory is listed in
|
||||||
~/.config/git-annex/autostart but no longer has a git repository in it.
|
~/.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
|
-- Joey Hess <joeyh@debian.org> Fri, 11 Apr 2014 21:33:35 -0400
|
||||||
|
|
||||||
|
|
|
@ -927,6 +927,14 @@ subdirectories).
|
||||||
With `--force`, even files whose content is not currently available will
|
With `--force`, even files whose content is not currently available will
|
||||||
be rekeyed. Use with caution.
|
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`
|
* `test`
|
||||||
|
|
||||||
This runs git-annex's built-in test suite.
|
This runs git-annex's built-in test suite.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue