migrate --update gets keys

The git log is outputting the diff, but this only looks at the new
files. When we have a new file, we can get the old filename by just
replacing "new" with "old". And then use branchFileRef to refer to it
allows catting the old key.

While this does have to skip past the old files in the diff, it's still
faster than calling git diff separately.

Sponsored-by: Nicholas Golder-Manning on Patreon
This commit is contained in:
Joey Hess 2023-12-07 17:03:58 -04:00
parent f1ce15036f
commit 7c7c9912c1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 38 additions and 22 deletions

View file

@ -16,7 +16,7 @@ import Data.Time
import Data.Time.Clock.POSIX
-- A change made to a file.
data RefChange t = RefChange
data LoggedFileChange t = LoggedFileChange
{ changetime :: POSIXTime
, changed :: t
, changedfile :: FilePath
@ -25,7 +25,9 @@ data RefChange t = RefChange
}
deriving (Show)
-- Get the git log. Note that the returned cleanup action should only be
-- Get the git log of changes to files.
--
-- Note that the returned cleanup action should only be
-- run after processing the returned list.
getGitLog
:: Ref
@ -34,7 +36,7 @@ getGitLog
-> [CommandParam]
-> (Sha -> FilePath -> Maybe t)
-> Repo
-> IO ([RefChange t], IO Bool)
-> IO ([LoggedFileChange t], IO Bool)
getGitLog ref stopref fs os selector repo = do
(ls, cleanup) <- pipeNullSplit ps repo
return (parseGitRawLog selector (map decodeBL ls), cleanup)
@ -73,7 +75,7 @@ commitinfoFormat = "%H %ct"
--
-- The commitinfo is not included before all changelines, so
-- keep track of the most recently seen commitinfo.
parseGitRawLog :: (Ref -> FilePath -> Maybe t) -> [String] -> [RefChange t]
parseGitRawLog :: (Ref -> FilePath -> Maybe t) -> [String] -> [LoggedFileChange t]
parseGitRawLog selector = parse (deleteSha, epoch)
where
epoch = toEnum 0 :: POSIXTime
@ -90,7 +92,7 @@ parseGitRawLog selector = parse (deleteSha, epoch)
mrc = do
(old, new) <- parseRawChangeLine cl
v <- selector commitsha c2
return $ RefChange
return $ LoggedFileChange
{ changetime = ts
, changed = v
, changedfile = c2