aboutsummaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-02-09 15:40:44 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-02-09 15:41:00 -0400
commit1a71d33190a0744f4416be176c944ad938fa17ee (patch)
tree389fd88359d2680dc0216306b65f23869d67b2fa /Command
parent8346e57d14c3f6547499188d8a8ae9dc6739e6b5 (diff)
import --reinject-duplicates
This is the same as running git annex reinject --known, followed by git-annex import. The advantage to having it in one command is that it only has to hash each file once; the two commands have to hash the imported files a second time. This commit was sponsored by Shane-o on Patreon.
Diffstat (limited to 'Command')
-rw-r--r--Command/Import.hs15
-rw-r--r--Command/Reinject.hs25
2 files changed, 25 insertions, 15 deletions
diff --git a/Command/Import.hs b/Command/Import.hs
index ea2ec71e4..6d872b1cb 100644
--- a/Command/Import.hs
+++ b/Command/Import.hs
@@ -11,6 +11,7 @@ import Command
import qualified Git
import qualified Annex
import qualified Command.Add
+import qualified Command.Reinject
import Utility.CopyFile
import Backend
import Types.KeySource
@@ -28,7 +29,7 @@ cmd = withGlobalOptions (jobsOption : jsonOption : fileMatchingOptions) $ notBar
"move and add files from outside git working copy"
paramPaths (seek <$$> optParser)
-data DuplicateMode = Default | Duplicate | DeDuplicate | CleanDuplicates | SkipDuplicates
+data DuplicateMode = Default | Duplicate | DeDuplicate | CleanDuplicates | SkipDuplicates | ReinjectDuplicates
deriving (Eq)
data ImportOptions = ImportOptions
@@ -57,7 +58,11 @@ duplicateModeParser =
)
<|> flag' SkipDuplicates
( long "skip-duplicates"
- <> help "import only new files"
+ <> help "import only new files (do not delete source files)"
+ )
+ <|> flag' ReinjectDuplicates
+ ( long "reinject-duplicates"
+ <> help "import new files, and reinject the content of files that were imported before"
)
seek :: ImportOptions -> CommandSeek
@@ -88,6 +93,9 @@ start largematcher mode (srcfile, destfile) =
warning "Could not verify that the content is still present in the annex; not removing from the import location."
stop
)
+ reinject k = do
+ showNote "reinjecting"
+ Command.Reinject.perform srcfile k
importfile ld k = checkdestdir $ do
ignored <- not <$> Annex.getState Annex.force <&&> checkIgnored destfile
if ignored
@@ -184,6 +192,9 @@ start largematcher mode (srcfile, destfile) =
SkipDuplicates -> checkdup k
(skipbecause "duplicate")
(importfile ld k)
+ ReinjectDuplicates -> checkdup k
+ (reinject k)
+ (importfile ld k)
_ -> importfile ld k
skipbecause s = showNote (s ++ "; skipping") >> next (return True)
diff --git a/Command/Reinject.hs b/Command/Reinject.hs
index 7d2da9420..8fe7587fa 100644
--- a/Command/Reinject.hs
+++ b/Command/Reinject.hs
@@ -43,9 +43,12 @@ startSrcDest (src:dest:[])
| src == dest = stop
| otherwise = notAnnexed src $ do
showStart "reinject" dest
- next $ ifAnnexed dest
- (\key -> perform src key (verifyKeyContent DefaultVerify UnVerified key src))
- stop
+ next $ ifAnnexed dest go stop
+ where
+ go key = ifM (verifyKeyContent DefaultVerify UnVerified key src)
+ ( perform src key
+ , error "failed"
+ )
startSrcDest _ = giveup "specify a src file and a dest file"
startKnown :: FilePath -> CommandStart
@@ -55,7 +58,7 @@ startKnown src = notAnnexed src $ do
case mkb of
Nothing -> error "Failed to generate key"
Just (key, _) -> ifM (isKnownKey key)
- ( next $ perform src key (return True)
+ ( next $ perform src key
, do
warning "Not known content; skipping"
next $ next $ return True
@@ -65,19 +68,15 @@ notAnnexed :: FilePath -> CommandStart -> CommandStart
notAnnexed src = ifAnnexed src $
giveup $ "cannot used annexed file as src: " ++ src
-perform :: FilePath -> Key -> Annex Bool -> CommandPerform
-perform src key verify = ifM move
+perform :: FilePath -> Key -> CommandPerform
+perform src key = ifM move
( next $ cleanup key
, error "failed"
)
where
- move = checkDiskSpaceToGet key False $
- ifM verify
- ( do
- moveAnnex key src
- return True
- , return False
- )
+ move = checkDiskSpaceToGet key False $ do
+ moveAnnex key src
+ return True
cleanup :: Key -> CommandCleanup
cleanup key = do