display filenames in migrate --update
authorJoey Hess <joeyh@joeyh.name>
Thu, 7 Dec 2023 22:00:09 +0000 (18:00 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 7 Dec 2023 22:00:09 +0000 (18:00 -0400)
Have to go to a lot of bother to find them, but I think it's worth it
for usability.

Sponsored-by: Luke T. Shumaker on Patreon
Command/Migrate.hs
doc/git-annex-migrate.mdwn

index 188dd03532dcf00c963afc17cc2c741df1206052..732a0b1d460be89fdd5a257b0fc421126b8a8152 100644 (file)
@@ -20,6 +20,9 @@ import Logs.MetaData
 import Logs.Web
 import Logs.Location
 import Utility.Metered
+import qualified Database.Keys
+import Git.FilePath
+import Annex.Link
 
 cmd :: Command
 cmd = withAnnexOptions [backendOption, annexedMatchingOptions, jsonOptions] $
@@ -50,7 +53,8 @@ seek o
        | updateOption o = do
                unless (null (migrateThese o)) $
                        error "Cannot combine --update with files to migrate."
-               commandAction update
+               streamNewDistributedMigrations $ \oldkey newkey ->
+                       commandAction $ update oldkey newkey
        | otherwise = do
                withFilesInGitAnnex ww seeker =<< workTreeItems ww (migrateThese o)
                commitMigration
@@ -143,10 +147,22 @@ perform onlyremovesize o file oldkey oldkeyrec oldbackend newbackend = go =<< ge
                | otherwise = k
        afile = AssociatedFile (Just file)
 
-update :: CommandStart
-update = starting "migrate" (ActionItemOther Nothing) (SeekInput []) $ do
-       streamNewDistributedMigrations $ \oldkey newkey ->
-               unlessM (inAnnex newkey) $
-                       whenM (Command.ReKey.linkKey' oldkey newkey) $
-                               logStatus newkey InfoPresent
-       next $ return True
+update :: Key -> Key -> CommandStart
+update oldkey newkey =
+       stopUnless ((not <$> inAnnex newkey) <&&> inAnnex oldkey) $ do
+               ai <- findworktreefile >>= return . \case
+                       Just f -> ActionItemAssociatedFile (AssociatedFile (Just f)) newkey
+                       Nothing -> ActionItemKey newkey
+               starting "migrate" ai (SeekInput []) $
+                       ifM (Command.ReKey.linkKey' oldkey newkey)
+                               ( do
+                                       logStatus newkey InfoPresent
+                                       next $ return True
+                               , next $ return False
+                               )
+  where
+       findworktreefile = do
+               fs <- Database.Keys.getAssociatedFiles newkey
+               g <- Annex.gitRepo
+               firstM (\f -> (== Just newkey) <$> isAnnexLink f) $
+                       map (\f -> simplifyPath (fromTopFilePath f g)) fs
index 7361ca03f95b8e38fc36fba8d5fadc2f5e1ed5d7..85b356723662d198fe6bff9e5691aa8720a84da5 100644 (file)
@@ -12,10 +12,11 @@ git annex migrate --update
 
 Changes the specified annexed files to use the default key-value backend
 (or the one specified with `--backend`). Only files whose content
-is currently available are migrated.
+is currently present are migrated.
 
-Note that the content is also still available using the old key after
-migration. Use `git annex unused` to find and remove the old key.
+Note that the content is also still stored using the old keys after
+migration. When possible, hard links are used to avoid that taking up
+extra disk space. Use `git annex unused` to find and remove the old keys.
 
 Normally, nothing will be done to files already using the new backend.
 However, if a backend changes the information it uses to construct a key,