summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-04-17 18:41:24 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-04-17 18:41:24 -0400
commite23a4eb3c9e9a6bc39a5a59fe45300e8fdfb0916 (patch)
treed3a75a3f65edb6f8a02b7ce54553e3a9960fcc34
parente9b6c350b15a93d82affadfabca18b3e95840cb1 (diff)
findref: New command, like find but shows files in a specified git ref.
-rw-r--r--CmdLine/GitAnnex.hs2
-rw-r--r--CmdLine/Seek.hs16
-rw-r--r--CmdLine/Usage.hs2
-rw-r--r--Command/Find.hs6
-rw-r--r--Command/FindRef.hs20
-rw-r--r--debian/changelog1
-rw-r--r--doc/git-annex.mdwn8
7 files changed, 53 insertions, 2 deletions
diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs
index 523c3f055..c37e44a2d 100644
--- a/CmdLine/GitAnnex.hs
+++ b/CmdLine/GitAnnex.hs
@@ -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
diff --git a/CmdLine/Seek.hs b/CmdLine/Seek.hs
index abbe52af8..431b2e118 100644
--- a/CmdLine/Seek.hs
+++ b/CmdLine/Seek.hs
@@ -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)
diff --git a/CmdLine/Usage.hs b/CmdLine/Usage.hs
index 1d0bba954..6e0a1ca80 100644
--- a/CmdLine/Usage.hs
+++ b/CmdLine/Usage.hs
@@ -93,6 +93,8 @@ paramFormat :: String
paramFormat = "FORMAT"
paramFile :: String
paramFile = "FILE"
+paramRef :: String
+paramRef = "REF"
paramGroup :: String
paramGroup = "GROUP"
paramExpression :: String
diff --git a/Command/Find.hs b/Command/Find.hs
index bcf83729a..c800933f9 100644
--- a/Command/Find.hs
+++ b/Command/Find.hs
@@ -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"
diff --git a/Command/FindRef.hs b/Command/FindRef.hs
new file mode 100644
index 000000000..26007f7c0
--- /dev/null
+++ b/Command/FindRef.hs
@@ -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
diff --git a/debian/changelog b/debian/changelog
index fb09d89bd..cefdca193 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -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
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index 32680b32c..d5408a2ae 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -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.