consistently use importKey when available

This avoids import with --no-content and with --content potentially
generating two different trees, leading to a merge conflict when run in
two different clones of a repo. And it's necessary groundwork to make
git-annex sync --no-content import from special remotes that support
importKey.

Only the directory special remote currently supports importKey, and it
generates the same key as git-annex usually does, so there is no
behavior change for it.

Future special remotes will need to take care when adding importKey,
if it generates different keys. Added some warnings about that to
comments.

This commit was sponsored by Noam Kremen on Patreon.
This commit is contained in:
Joey Hess 2020-09-28 15:03:15 -04:00
parent 15c1ee16d9
commit 3eaaec3113
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 84 additions and 49 deletions

View file

@ -225,10 +225,13 @@ seek' o = do
, map (withbranch . pullRemote o mergeConfig) gitremotes
, [ mergeAnnex ]
]
whenM (shouldSyncContent o) $ do
mapM_ (withbranch . importRemote o mergeConfig) importremotes
content <- shouldSyncContent o
forM_ importremotes $
withbranch . importRemote content o mergeConfig
when content $ do
-- Send content to any exports before other
-- repositories, in case that lets content
-- be dropped from other repositories.
@ -454,8 +457,8 @@ pullRemote o mergeconfig remote branch = stopUnless (pure $ pullOption o && want
ai = ActionItemOther (Just (Remote.name remote))
si = SeekInput []
importRemote :: SyncOptions -> [Git.Merge.MergeConfig] -> Remote -> CurrBranch -> CommandSeek
importRemote o mergeconfig remote currbranch
importRemote :: Bool -> SyncOptions -> [Git.Merge.MergeConfig] -> Remote -> CurrBranch -> CommandSeek
importRemote importcontent o mergeconfig remote currbranch
| not (pullOption o) || not wantpull = noop
| otherwise = case remoteAnnexTrackingBranch (Remote.gitconfig remote) of
Nothing -> noop
@ -465,7 +468,7 @@ importRemote o mergeconfig remote currbranch
let subdir = if S.null p
then Nothing
else Just (asTopFilePath p)
Command.Import.seekRemote remote branch subdir True
Command.Import.seekRemote remote branch subdir importcontent
void $ mergeRemote remote currbranch mergeconfig o
where
wantpull = remoteAnnexPull (Remote.gitconfig remote)