sync --no-content import from directory special remote

sync: When run without --content, import without copying from
importtree=yes directory special remotes. (Other special remotes may
support this later as well.)

This commit was sponsored by Svenne Krap on Patreon.
This commit is contained in:
Joey Hess 2020-09-28 15:29:08 -04:00
parent 3eaaec3113
commit 658ea7ca3c
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 17 additions and 3 deletions

View file

@ -12,6 +12,7 @@ module Annex.Import (
ImportCommitConfig(..), ImportCommitConfig(..),
buildImportCommit, buildImportCommit,
buildImportTrees, buildImportTrees,
canImportKeys,
importKeys, importKeys,
filterImportableContents, filterImportableContents,
makeImportMatcher, makeImportMatcher,
@ -281,6 +282,12 @@ buildImportTrees basetree msubdir importable = History
topf = asTopFilePath $ topf = asTopFilePath $
maybe lf (\sd -> getTopFilePath sd P.</> lf) msubdir maybe lf (\sd -> getTopFilePath sd P.</> lf) msubdir
canImportKeys :: Remote -> Bool -> Bool
canImportKeys remote importcontent =
importcontent || isJust (Remote.importKey ia)
where
ia = Remote.importActions remote
{- Downloads all new ContentIdentifiers, or when importcontent is False, {- Downloads all new ContentIdentifiers, or when importcontent is False,
- generates Keys without downloading. - generates Keys without downloading.
- -
@ -304,7 +311,7 @@ importKeys
-> ImportableContents (ContentIdentifier, ByteSize) -> ImportableContents (ContentIdentifier, ByteSize)
-> Annex (Maybe (ImportableContents (Either Sha Key))) -> Annex (Maybe (ImportableContents (Either Sha Key)))
importKeys remote importtreeconfig importcontent importablecontents = do importKeys remote importtreeconfig importcontent importablecontents = do
when (not importcontent && isNothing (Remote.importKey ia)) $ unless (canImportKeys remote importcontent) $
giveup "This remote does not support importing without downloading content." giveup "This remote does not support importing without downloading content."
-- This map is used to remember content identifiers that -- This map is used to remember content identifiers that
-- were just imported, before they have necessarily been -- were just imported, before they have necessarily been

View file

@ -27,6 +27,9 @@ git-annex (8.20200909) UNRELEASED; urgency=medium
files into git, the same as is done when importing with content. files into git, the same as is done when importing with content.
If the largefiles expression needs the file content available If the largefiles expression needs the file content available
(due to mimetype or mimeencoding being used), the import will fail. (due to mimetype or mimeencoding being used), the import will fail.
* sync: When run without --content, import without copying from
importtree=yes directory special remotes.
(Other special remotes may support this later as well.)
-- Joey Hess <id@joeyh.name> Mon, 14 Sep 2020 18:34:37 -0400 -- Joey Hess <id@joeyh.name> Mon, 14 Sep 2020 18:34:37 -0400

View file

@ -66,6 +66,7 @@ import Annex.UpdateInstead
import Annex.Export import Annex.Export
import Annex.TaggedPush import Annex.TaggedPush
import Annex.CurrentBranch import Annex.CurrentBranch
import Annex.Import (canImportKeys)
import Types.FileMatcher import Types.FileMatcher
import qualified Database.Export as Export import qualified Database.Export as Export
import Utility.Bloom import Utility.Bloom
@ -468,8 +469,11 @@ importRemote importcontent o mergeconfig remote currbranch
let subdir = if S.null p let subdir = if S.null p
then Nothing then Nothing
else Just (asTopFilePath p) else Just (asTopFilePath p)
if canImportKeys remote importcontent
then do
Command.Import.seekRemote remote branch subdir importcontent Command.Import.seekRemote remote branch subdir importcontent
void $ mergeRemote remote currbranch mergeconfig o void $ mergeRemote remote currbranch mergeconfig o
else warning $ "Cannot import from " ++ Remote.name remote ++ " when not syncing content."
where where
wantpull = remoteAnnexPull (Remote.gitconfig remote) wantpull = remoteAnnexPull (Remote.gitconfig remote)