unused: Bug fix when a new file was added to the annex, and then removed (but not git rmed). git still has the add staged in this case, so the content should not be unused and was wrongly treated as such.

So, we need to look at both the file on disk to see if it's a annex link,
and the file in the index too. lookupFile doesn't look in the index if the file
is not present on disk.
This commit is contained in:
Joey Hess 2016-01-06 16:30:49 -04:00
parent f263316c16
commit 03cb2c8ece
Failed to extract signature
3 changed files with 17 additions and 10 deletions

View file

@ -26,6 +26,7 @@ import qualified Git.LsFiles as LsFiles
import qualified Git.DiffTree as DiffTree import qualified Git.DiffTree as DiffTree
import qualified Remote import qualified Remote
import qualified Annex.Branch import qualified Annex.Branch
import Annex.Link
import Annex.CatFile import Annex.CatFile
import Types.Key import Types.Key
import Types.RefSpec import Types.RefSpec
@ -214,8 +215,12 @@ withKeysReferenced' mdir initial a = do
Just dir -> inRepo $ LsFiles.inRepo [dir] Just dir -> inRepo $ LsFiles.inRepo [dir]
go v [] = return v go v [] = return v
go v (f:fs) = do go v (f:fs) = do
x <- lookupFile f mk <- getM id
case x of [ isAnnexLink f
, liftIO (isPointerFile f)
, catKeyFile f
]
case mk of
Nothing -> go v fs Nothing -> go v fs
Just k -> do Just k -> do
!v' <- a k f v !v' <- a k f v

15
Test.hs
View file

@ -705,8 +705,8 @@ test_fsck_basic = intmpclonerepo $ do
git_annex "get" [f] @? "get of file failed" git_annex "get" [f] @? "get of file failed"
Utility.FileMode.allowWrite f Utility.FileMode.allowWrite f
writeFile f (changedcontent f) writeFile f (changedcontent f)
ifM (annexeval Config.isDirect) ifM (annexeval Config.isDirect <||> unlockedFiles <$> getTestMode)
( git_annex "fsck" [] @? "fsck failed in direct mode with changed file content" ( git_annex "fsck" [] @? "fsck failed on unlocked file with changed file content"
, not <$> git_annex "fsck" [] @? "fsck failed to fail with corrupted file content" , not <$> git_annex "fsck" [] @? "fsck failed to fail with corrupted file content"
) )
git_annex "fsck" [] @? "fsck unexpectedly failed again; previous one did not fix problem with " ++ f git_annex "fsck" [] @? "fsck unexpectedly failed again; previous one did not fix problem with " ++ f
@ -828,7 +828,7 @@ test_unused = intmpclonerepoInDirect $ do
checkunused [unusedfilekey] "with renamed link deleted" checkunused [unusedfilekey] "with renamed link deleted"
-- unused used to miss symlinks that were deleted or modified -- unused used to miss symlinks that were deleted or modified
-- manually, but commited as such. -- manually
writeFile "unusedfile" "unusedcontent" writeFile "unusedfile" "unusedcontent"
git_annex "add" ["unusedfile"] @? "add of unusedfile failed" git_annex "add" ["unusedfile"] @? "add of unusedfile failed"
boolSystem "git" [Param "add", File "unusedfile"] @? "git add failed" boolSystem "git" [Param "add", File "unusedfile"] @? "git add failed"
@ -837,15 +837,14 @@ test_unused = intmpclonerepoInDirect $ do
boolSystem "git" [Param "rm", Param "-qf", File "unusedfile"] @? "git rm failed" boolSystem "git" [Param "rm", Param "-qf", File "unusedfile"] @? "git rm failed"
checkunused [unusedfilekey'] "with staged link deleted" checkunused [unusedfilekey'] "with staged link deleted"
-- unused used to miss symlinks that were deleted or modified -- unused used to false positive on symlinks that were
-- manually, but not staged as such. -- deleted or modified manually, but not staged as such
writeFile "unusedfile" "unusedcontent" writeFile "unusedfile" "unusedcontent"
git_annex "add" ["unusedfile"] @? "add of unusedfile failed" git_annex "add" ["unusedfile"] @? "add of unusedfile failed"
boolSystem "git" [Param "add", File "unusedfile"] @? "git add failed" boolSystem "git" [Param "add", File "unusedfile"] @? "git add failed"
unusedfilekey'' <- annexeval $ findkey "unusedfile" checkunused [] "with staged file"
checkunused [] "with unstaged deleted link"
removeFile "unusedfile" removeFile "unusedfile"
checkunused [unusedfilekey''] "with unstaged link deleted" checkunused [] "with staged deleted file"
where where
checkunused expectedkeys desc = do checkunused expectedkeys desc = do

3
debian/changelog vendored
View file

@ -40,6 +40,9 @@ git-annex (6.20151219) UNRELEASED; urgency=medium
This may break existing parsers of this json output, if there were any. This may break existing parsers of this json output, if there were any.
* whereis --json: Make url list be included in machine-parseable form. * whereis --json: Make url list be included in machine-parseable form.
* test: Added --keep-failures option. * test: Added --keep-failures option.
* unused: Bug fix when a new file was added to the annex, and then
removed (but not git rmed). git still has the add staged in this case,
so the content should not be unused and was wrongly treated as such.
-- Joey Hess <id@joeyh.name> Sat, 19 Dec 2015 13:31:17 -0400 -- Joey Hess <id@joeyh.name> Sat, 19 Dec 2015 13:31:17 -0400