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:
parent
fc2f0e8b1a
commit
7f7ae7a3b1
6 changed files with 17 additions and 2 deletions
2
Annex.hs
2
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -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
|
||||
|
||||
|
|
|
@ -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]]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue