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?
This commit is contained in:
Joey Hess 2011-11-22 14:06:31 -04:00
parent fc2f0e8b1a
commit 7f7ae7a3b1
6 changed files with 17 additions and 2 deletions

View file

@ -60,6 +60,7 @@ data AnnexState = AnnexState
, force :: Bool , force :: Bool
, fast :: Bool , fast :: Bool
, auto :: Bool , auto :: Bool
, print0 :: Bool
, branchstate :: BranchState , branchstate :: BranchState
, catfilehandle :: Maybe CatFileHandle , catfilehandle :: Maybe CatFileHandle
, forcebackend :: Maybe String , forcebackend :: Maybe String
@ -82,6 +83,7 @@ newState gitrepo = AnnexState
, force = False , force = False
, fast = False , fast = False
, auto = False , auto = False
, print0 = False
, branchstate = startBranchState , branchstate = startBranchState
, catfilehandle = Nothing , catfilehandle = Nothing
, forcebackend = Nothing , forcebackend = Nothing

View file

@ -11,6 +11,7 @@ import Common.Annex
import Command import Command
import Annex.Content import Annex.Content
import Limit import Limit
import qualified Annex
def :: [Command] def :: [Command]
def = [command "find" paramPaths seek "lists available files"] def = [command "find" paramPaths seek "lists available files"]
@ -22,6 +23,9 @@ start :: FilePath -> (Key, Backend Annex) -> CommandStart
start file (key, _) = do start file (key, _) = do
-- only files inAnnex are shown, unless the user has requested -- only files inAnnex are shown, unless the user has requested
-- others via a limit -- others via a limit
whenM (liftM2 (||) (inAnnex key) limited) $ whenM (liftM2 (||) (inAnnex key) limited) $ do
liftIO $ putStrLn file print0 <- Annex.getState Annex.print0
if print0
then liftIO $ putStr (file ++ "\0")
else liftIO $ putStrLn file
stop stop

View file

@ -103,6 +103,8 @@ options = commonOptions ++
"override trust setting to untrusted" "override trust setting to untrusted"
, Option ['c'] ["config"] (ReqArg setgitconfig "NAME=VALUE") , Option ['c'] ["config"] (ReqArg setgitconfig "NAME=VALUE")
"override git configuration setting" "override git configuration setting"
, Option [] ["print0"] (NoArg (setprint0 True))
"terminate filename with null"
, Option ['x'] ["exclude"] (ReqArg Limit.addExclude paramGlob) , Option ['x'] ["exclude"] (ReqArg Limit.addExclude paramGlob)
"skip files matching the glob pattern" "skip files matching the glob pattern"
, Option ['i'] ["in"] (ReqArg Limit.addIn paramRemote) , Option ['i'] ["in"] (ReqArg Limit.addIn paramRemote)
@ -114,6 +116,7 @@ options = commonOptions ++
setto v = Annex.changeState $ \s -> s { Annex.toremote = Just v } setto v = Annex.changeState $ \s -> s { Annex.toremote = Just v }
setfrom v = Annex.changeState $ \s -> s { Annex.fromremote = Just v } setfrom v = Annex.changeState $ \s -> s { Annex.fromremote = Just v }
setnumcopies v = Annex.changeState $ \s -> s {Annex.forcenumcopies = readMaybe v } setnumcopies v = Annex.changeState $ \s -> s {Annex.forcenumcopies = readMaybe v }
setprint0 v = Annex.changeState $ \s -> s { Annex.print0 = v }
setgitconfig :: String -> Annex () setgitconfig :: String -> Annex ()
setgitconfig v = do setgitconfig v = do
newg <- inRepo $ Git.configStore v newg <- inRepo $ Git.configStore v

1
debian/changelog vendored
View file

@ -19,6 +19,7 @@ git-annex (3.20111112) UNRELEASED; urgency=low
* migrate: Don't fall over a stale temp file. * migrate: Don't fall over a stale temp file.
* Avoid excessive escaping for rsync special remotes that are not accessed * Avoid excessive escaping for rsync special remotes that are not accessed
over ssh. over ssh.
* find: Support --print0
-- Joey Hess <joeyh@debian.org> Sat, 12 Nov 2011 14:50:21 -0400 -- Joey Hess <joeyh@debian.org> Sat, 12 Nov 2011 14:50:21 -0400

View file

@ -1,3 +1,5 @@
It would be nice if git annex find supported a --print0 option as GNU 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 find does. That way, file names that are printed could be piped to
xargs even if they have spaces. xargs even if they have spaces.
> Done. --[[Joey]]

View file

@ -232,6 +232,9 @@ subdirectories).
With no parameters, defaults to finding all files in the current directory With no parameters, defaults to finding all files in the current directory
and its subdirectories. and its subdirectories.
To output filenames terminated with nulls, for use with xargs -0,
specify --print0.
* whereis [path ...] * whereis [path ...]
Displays a list of repositories known to contain the content of the Displays a list of repositories known to contain the content of the