diffdriver: Added --get option

Removed the dontCheck repoExists, because running it in a repo that has not
been initialized yet would update location log with nouuid. And I guess
it's ok for it to only support running in git-annex repos.
This commit is contained in:
Joey Hess 2023-08-22 11:58:13 -04:00
parent 724ceeb1a9
commit 379d58b499
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 42 additions and 20 deletions

View file

@ -7,7 +7,6 @@ git-annex (10.20230803) UNRELEASED; urgency=medium
* Fix behavior when importing a tree from a directory remote when the
directory does not exist. An empty tree was imported, rather than the
import failing.
* Stop bundling curl in the OSX dmg and linux standalone image.
* sync, assist, push, pull: Skip more types of remotes when they
are not present due to eg being on a drive that is offline.
(directory, borg, bup, ddar, gcrypt, rsync)
@ -18,6 +17,9 @@ git-annex (10.20230803) UNRELEASED; urgency=medium
* Avoid using curl when annex.security.allowed-ip-addresses is set
but neither annex.web-options nor annex.security.allowed-url-schemes
is set to a value that needs curl.
* Stop bundling curl in the OSX dmg and linux standalone image.
* diffdriver: Added --get option.
* diffdriver: Refuse to run when not in a git-annex repository.
-- Joey Hess <id@joeyh.name> Mon, 07 Aug 2023 13:04:13 -0400

View file

@ -11,15 +11,16 @@ import Command
import Annex.Content
import Annex.Link
import Git.Types
import qualified Command.Get
cmd :: Command
cmd = dontCheck repoExists $
command "diffdriver" SectionPlumbing
"git diff driver"
("-- cmd --") (seek <$$> optParser)
cmd = command "diffdriver" SectionPlumbing
"git diff driver"
("-- cmd --") (seek <$$> optParser)
data Options = Options
{ textDiff :: Bool
, getOption :: Bool
, restOptions :: CmdParams
}
@ -29,16 +30,16 @@ optParser desc = Options
( long "text"
<> help "diff text files with diff(1)"
)
<*> switch
( long "get"
<> help "get file contents from remotes"
)
<*> cmdParams desc
seek :: Options -> CommandSeek
seek = commandAction . start
start :: Options -> CommandStart
start opts = do
seek opts = do
let (req, differ) = parseReq opts
void $ liftIO . exitBool =<< liftIO . differ =<< fixupReq req
stop
void $ liftIO . exitBool =<< liftIO . differ =<< fixupReq req opts
data Req
= Req
@ -99,22 +100,35 @@ parseReq opts
-
- In either case, adjust the Req to instead point to the actual
- location of the annexed object (which may or may not be present).
-
- This also gets objects from remotes when the getOption is set.
-}
fixupReq :: Req -> Annex Req
fixupReq req@(UnmergedReq {}) = return req
fixupReq req@(Req {}) =
fixupReq :: Req -> Options -> Annex Req
fixupReq req@(UnmergedReq {}) _ = return req
fixupReq req@(Req {}) opts =
check rOldFile rOldMode (\r f -> r { rOldFile = f }) req
>>= check rNewFile rNewMode (\r f -> r { rNewFile = f })
where
check getfile getmode setfile r = case readTreeItemType (encodeBS (getmode r)) of
Just TreeSymlink -> do
v <- getAnnexLinkTarget' f False
maybe (return r) repoint (parseLinkTargetOrPointer =<< v)
_ -> maybe (return r) repoint =<< liftIO (isPointerFile f)
maybe (return r) go (parseLinkTargetOrPointer =<< v)
_ -> maybe (return r) go =<< liftIO (isPointerFile f)
where
f = toRawFilePath (getfile r)
go k = do
when (getOption opts) $
unlessM (inAnnex k) $
commandAction $
starting "get" ai si $
Command.Get.perform k af
repoint k
where
ai = OnlyActionOn k (ActionItemKey k)
si = SeekInput []
af = AssociatedFile (Just f)
repoint k = withObjectLoc k $
pure . setfile r . fromRawFilePath
f = toRawFilePath (getfile r)
externalDiffer :: String -> [String] -> Differ
externalDiffer c ps = \req -> boolSystem c (map Param ps ++ serializeReq req )

View file

@ -4,9 +4,9 @@ git-annex diffdriver - git diff driver
# SYNOPSIS
git annex diffdriver --text [-- --opts --]
`git annex diffdriver [--get,--text] [-- --diffopts --]`
git annex diffdriver `-- cmd --opts --`
`git annex diffdriver -- cmd --cmdopts --`
# DESCRIPTION
@ -41,7 +41,11 @@ set `GIT_EXTERNAL_DIFF="git-annex diffdriver -- j-c-diff --"`
# OPTIONS
To diff text files with diff(1), use the "--text" option.
To get the contents of annexed files from remotes when they are not already
present, use the `--get` option. The file contents will remain in the
repository for later use until dropped in the usual ways.
To diff text files with diff(1), use the `--text` option.
To pass additional options to diff(1), use eg "--text -- --color --"
To use an external diff driver command, the options must start with

View file

@ -1,3 +1,5 @@
since there is no generic 'fuse' mode, I would like to request to have `--get` (or `--auto-get`) option for diffdriver. I am trying to compare files across two branches on a repo I just cloned. I cannot download all the files and downloading differing keys across branches for the same file is a bit painful. So I felt that it would be super nice if git annex could auto get those files from somewhere (well -- original clone)
[[!tag confirmed]]
> [[done]] --[[Joey]]