summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-22 14:06:31 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-22 14:06:31 -0400
commit7f7ae7a3b1cdfbc61879189dfe04a637690015aa (patch)
tree842546a50ff6def034f19a0e6e5c616a66d9a9d5
parentfc2f0e8b1a4bd016ac29606381dfb7034c88e9f5 (diff)
find: Support --print0
It would be nice if command-specific options were supported. The first difficulty is that which command is being called is not known until after getopt; but that could be worked around by finding the first non-dashed parameter. Storing the settings without putting them in the annex monad is the next difficulty; it could perhaps be handled by making the seek stage pass applicable settings into the start stage (and from there on to perform as needed). But that still leaves a problem, what data type to use to represent the options between getopt and seek?
-rw-r--r--Annex.hs2
-rw-r--r--Command/Find.hs8
-rw-r--r--GitAnnex.hs3
-rw-r--r--debian/changelog1
-rw-r--r--doc/forum/--print0_option_as_in___34__find__34__.mdwn2
-rw-r--r--doc/git-annex.mdwn3
6 files changed, 17 insertions, 2 deletions
diff --git a/Annex.hs b/Annex.hs
index 24cc78a64..6d245a92d 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -60,6 +60,7 @@ data AnnexState = AnnexState
, force :: Bool
, fast :: Bool
, auto :: Bool
+ , print0 :: Bool
, branchstate :: BranchState
, catfilehandle :: Maybe CatFileHandle
, forcebackend :: Maybe String
@@ -82,6 +83,7 @@ newState gitrepo = AnnexState
, force = False
, fast = False
, auto = False
+ , print0 = False
, branchstate = startBranchState
, catfilehandle = Nothing
, forcebackend = Nothing
diff --git a/Command/Find.hs b/Command/Find.hs
index c816ff071..47058fa25 100644
--- a/Command/Find.hs
+++ b/Command/Find.hs
@@ -11,6 +11,7 @@ import Common.Annex
import Command
import Annex.Content
import Limit
+import qualified Annex
def :: [Command]
def = [command "find" paramPaths seek "lists available files"]
@@ -22,6 +23,9 @@ start :: FilePath -> (Key, Backend Annex) -> CommandStart
start file (key, _) = do
-- only files inAnnex are shown, unless the user has requested
-- others via a limit
- whenM (liftM2 (||) (inAnnex key) limited) $
- liftIO $ putStrLn file
+ whenM (liftM2 (||) (inAnnex key) limited) $ do
+ print0 <- Annex.getState Annex.print0
+ if print0
+ then liftIO $ putStr (file ++ "\0")
+ else liftIO $ putStrLn file
stop
diff --git a/GitAnnex.hs b/GitAnnex.hs
index 7b51602be..f563c08cb 100644
--- a/GitAnnex.hs
+++ b/GitAnnex.hs
@@ -103,6 +103,8 @@ options = commonOptions ++
"override trust setting to untrusted"
, Option ['c'] ["config"] (ReqArg setgitconfig "NAME=VALUE")
"override git configuration setting"
+ , Option [] ["print0"] (NoArg (setprint0 True))
+ "terminate filename with null"
, Option ['x'] ["exclude"] (ReqArg Limit.addExclude paramGlob)
"skip files matching the glob pattern"
, Option ['i'] ["in"] (ReqArg Limit.addIn paramRemote)
@@ -114,6 +116,7 @@ options = commonOptions ++
setto v = Annex.changeState $ \s -> s { Annex.toremote = Just v }
setfrom v = Annex.changeState $ \s -> s { Annex.fromremote = Just v }
setnumcopies v = Annex.changeState $ \s -> s {Annex.forcenumcopies = readMaybe v }
+ setprint0 v = Annex.changeState $ \s -> s { Annex.print0 = v }
setgitconfig :: String -> Annex ()
setgitconfig v = do
newg <- inRepo $ Git.configStore v
diff --git a/debian/changelog b/debian/changelog
index 9f96a4fff..3c4fa05aa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -19,6 +19,7 @@ git-annex (3.20111112) UNRELEASED; urgency=low
* migrate: Don't fall over a stale temp file.
* Avoid excessive escaping for rsync special remotes that are not accessed
over ssh.
+ * find: Support --print0
-- Joey Hess <joeyh@debian.org> Sat, 12 Nov 2011 14:50:21 -0400
diff --git a/doc/forum/--print0_option_as_in___34__find__34__.mdwn b/doc/forum/--print0_option_as_in___34__find__34__.mdwn
index cd537f8ad..7d9a2284d 100644
--- a/doc/forum/--print0_option_as_in___34__find__34__.mdwn
+++ b/doc/forum/--print0_option_as_in___34__find__34__.mdwn
@@ -1,3 +1,5 @@
It would be nice if git annex find supported a --print0 option as GNU
find does. That way, file names that are printed could be piped to
xargs even if they have spaces.
+
+> Done. --[[Joey]]
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index e91e5a0e3..c225529de 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -232,6 +232,9 @@ subdirectories).
With no parameters, defaults to finding all files in the current directory
and its subdirectories.
+ To output filenames terminated with nulls, for use with xargs -0,
+ specify --print0.
+
* whereis [path ...]
Displays a list of repositories known to contain the content of the