2014-11-24 20:14:01 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2021-04-08 18:32:09 +00:00
|
|
|
- Copyright 2014-2021 Joey Hess <id@joeyh.name>
|
2014-11-24 20:14:01 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-11-24 20:14:01 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.DiffDriver where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import Annex.Content
|
|
|
|
import Annex.Link
|
|
|
|
import Git.Types
|
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
|
|
|
cmd = dontCheck repoExists $
|
2015-07-08 19:08:02 +00:00
|
|
|
command "diffdriver" SectionPlumbing
|
|
|
|
"external git diff driver shim"
|
|
|
|
("-- cmd --") (withParams seek)
|
2014-11-24 20:14:01 +00:00
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2018-10-01 18:12:06 +00:00
|
|
|
seek = withWords (commandAction . start)
|
2014-11-24 20:14:01 +00:00
|
|
|
|
|
|
|
start :: [String] -> CommandStart
|
|
|
|
start opts = do
|
|
|
|
let (req, differ) = parseReq opts
|
|
|
|
void $ liftIO . exitBool =<< liftIO . differ =<< fixupReq req
|
|
|
|
stop
|
|
|
|
|
|
|
|
data Req
|
|
|
|
= Req
|
|
|
|
{ rPath :: FilePath
|
|
|
|
, rOldFile :: FilePath
|
|
|
|
, rOldHex :: String
|
|
|
|
, rOldMode :: String
|
|
|
|
, rNewFile :: FilePath
|
|
|
|
, rNewHex :: String
|
|
|
|
, rNewMode ::String
|
|
|
|
}
|
|
|
|
| UnmergedReq
|
|
|
|
{ rPath :: FilePath
|
|
|
|
}
|
|
|
|
|
|
|
|
type Differ = Req -> IO Bool
|
|
|
|
|
|
|
|
serializeReq :: Req -> [CommandParam]
|
|
|
|
serializeReq req@(UnmergedReq {}) = [Param $ rPath req]
|
|
|
|
serializeReq req@(Req {}) = map Param
|
|
|
|
[ rPath req
|
|
|
|
, rOldFile req
|
|
|
|
, rOldHex req
|
|
|
|
, rOldMode req
|
|
|
|
, rNewFile req
|
|
|
|
, rNewHex req
|
|
|
|
, rNewMode req
|
|
|
|
]
|
|
|
|
|
|
|
|
parseReq :: [String] -> (Req, Differ)
|
|
|
|
parseReq opts = case separate (== "--") opts of
|
|
|
|
(c:ps, l) -> (mk l, externalDiffer c ps)
|
|
|
|
([],_) -> badopts
|
|
|
|
where
|
|
|
|
mk (path:old_file:old_hex:old_mode:new_file:new_hex:new_mode:[]) =
|
|
|
|
Req
|
|
|
|
{ rPath = path
|
|
|
|
, rOldFile = old_file
|
|
|
|
, rOldHex = old_hex
|
|
|
|
, rOldMode = old_mode
|
|
|
|
, rNewFile = new_file
|
|
|
|
, rNewHex = new_hex
|
|
|
|
, rNewMode = new_mode
|
|
|
|
}
|
|
|
|
mk (unmergedpath:[]) = UnmergedReq { rPath = unmergedpath }
|
|
|
|
mk _ = badopts
|
|
|
|
|
2016-11-16 01:29:54 +00:00
|
|
|
badopts = giveup $ "Unexpected input: " ++ unwords opts
|
2014-11-24 20:14:01 +00:00
|
|
|
|
|
|
|
{- Check if either file is a symlink to a git-annex object,
|
|
|
|
- which git-diff will leave as a normal file containing the link text.
|
2021-04-08 18:32:09 +00:00
|
|
|
-
|
|
|
|
- Also check if either file is a pointer file, as used for unlocked files.
|
|
|
|
-
|
|
|
|
- In either case, adjust the Req to instead point to the actual
|
|
|
|
- location of the annexed object (which may or may not be present).
|
|
|
|
-}
|
2014-11-24 20:14:01 +00:00
|
|
|
fixupReq :: Req -> Annex Req
|
|
|
|
fixupReq req@(UnmergedReq {}) = return req
|
|
|
|
fixupReq req@(Req {}) =
|
|
|
|
check rOldFile rOldMode (\r f -> r { rOldFile = f }) req
|
|
|
|
>>= check rNewFile rNewMode (\r f -> r { rNewFile = f })
|
|
|
|
where
|
2019-12-05 18:36:43 +00:00
|
|
|
check getfile getmode setfile r = case readTreeItemType (encodeBS' (getmode r)) of
|
2018-05-14 18:22:44 +00:00
|
|
|
Just TreeSymlink -> do
|
2021-04-08 18:32:09 +00:00
|
|
|
v <- getAnnexLinkTarget' f False
|
|
|
|
maybe (return r) repoint (parseLinkTargetOrPointer =<< v)
|
|
|
|
_ -> maybe (return r) repoint =<< liftIO (isPointerFile f)
|
|
|
|
where
|
|
|
|
repoint k = withObjectLoc k $
|
|
|
|
pure . setfile r . fromRawFilePath
|
|
|
|
f = toRawFilePath (getfile r)
|
2014-11-24 20:14:01 +00:00
|
|
|
|
|
|
|
externalDiffer :: String -> [String] -> Differ
|
|
|
|
externalDiffer c ps = \req -> boolSystem c (map Param ps ++ serializeReq req )
|