work around strange auto-init bug

git-annex get when run as the first git-annex command in a new repo did not
populate unlocked files. (Reversion in version 8.20210621)

I am not entirely happy with this, because I don't understand how
428c91606b caused the problem in the first
place, and I don't fully understand how skipping calling scanAnnexedFiles
during autoinit avoids the problem.

Kept the explicit call to scanAnnexedFiles during git-annex init,
so that when reconcileStaged is expensive, it can be made to run then,
rather than at some later point when the information is needed.

Sponsored-by: Brock Spratlen on Patreon
This commit is contained in:
Joey Hess 2021-07-30 18:36:03 -04:00
parent 9f94d2894e
commit b3c4579c79
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
9 changed files with 33 additions and 20 deletions

View file

@ -96,8 +96,8 @@ genDescription Nothing = do
Right username -> [username, at, hostname, ":", reldir] Right username -> [username, at, hostname, ":", reldir]
Left _ -> [hostname, ":", reldir] Left _ -> [hostname, ":", reldir]
initialize :: Maybe String -> Maybe RepoVersion -> Annex () initialize :: Bool -> Maybe String -> Maybe RepoVersion -> Annex ()
initialize mdescription mversion = checkInitializeAllowed $ do initialize autoinit mdescription mversion = checkInitializeAllowed $ do
{- Has to come before any commits are made as the shared {- Has to come before any commits are made as the shared
- clone heuristic expects no local objects. -} - clone heuristic expects no local objects. -}
sharedclone <- checkSharedClone sharedclone <- checkSharedClone
@ -107,10 +107,10 @@ initialize mdescription mversion = checkInitializeAllowed $ do
ensureCommit $ Annex.Branch.create ensureCommit $ Annex.Branch.create
prepUUID prepUUID
initialize' mversion initialize' autoinit mversion
initSharedClone sharedclone initSharedClone sharedclone
u <- getUUID u <- getUUID
{- Avoid overwriting existing description with a default {- Avoid overwriting existing description with a default
- description. -} - description. -}
@ -119,8 +119,8 @@ initialize mdescription mversion = checkInitializeAllowed $ do
-- Everything except for uuid setup, shared clone setup, and initial -- Everything except for uuid setup, shared clone setup, and initial
-- description. -- description.
initialize' :: Maybe RepoVersion -> Annex () initialize' :: Bool -> Maybe RepoVersion -> Annex ()
initialize' mversion = checkInitializeAllowed $ do initialize' autoinit mversion = checkInitializeAllowed $ do
checkLockSupport checkLockSupport
checkFifoSupport checkFifoSupport
checkCrippledFileSystem checkCrippledFileSystem
@ -135,9 +135,11 @@ initialize' mversion = checkInitializeAllowed $ do
then configureSmudgeFilter then configureSmudgeFilter
else deconfigureSmudgeFilter else deconfigureSmudgeFilter
unlessM isBareRepo $ do unlessM isBareRepo $ do
scanAnnexedFiles
hookWrite postCheckoutHook hookWrite postCheckoutHook
hookWrite postMergeHook hookWrite postMergeHook
unless autoinit $
scanAnnexedFiles
AdjustedBranch.checkAdjustedClone >>= \case AdjustedBranch.checkAdjustedClone >>= \case
AdjustedBranch.InAdjustedClone -> return () AdjustedBranch.InAdjustedClone -> return ()
AdjustedBranch.NotInAdjustedClone -> AdjustedBranch.NotInAdjustedClone ->
@ -198,7 +200,7 @@ ensureInitialized = getInitializedVersion >>= maybe needsinit checkUpgrade
where where
needsinit = ifM autoInitializeAllowed needsinit = ifM autoInitializeAllowed
( do ( do
initialize Nothing Nothing initialize True Nothing Nothing
autoEnableSpecialRemotes autoEnableSpecialRemotes
, giveup "First run: git-annex init" , giveup "First run: git-annex init"
) )
@ -232,7 +234,7 @@ autoInitialize = getInitializedVersion >>= maybe needsinit checkUpgrade
where where
needsinit = needsinit =
whenM (initializeAllowed <&&> autoInitializeAllowed) $ do whenM (initializeAllowed <&&> autoInitializeAllowed) $ do
initialize Nothing Nothing initialize True Nothing Nothing
autoEnableSpecialRemotes autoEnableSpecialRemotes
{- Checks if a repository is initialized. Does not check version for ugrade. -} {- Checks if a repository is initialized. Does not check version for ugrade. -}

View file

@ -58,10 +58,10 @@ ifAnnexed file yes no = maybe no yes =<< lookupKey file
- Normally the keys database is updated incrementally when it's being - Normally the keys database is updated incrementally when it's being
- opened, and changes are noticed. Calling this explicitly allows - opened, and changes are noticed. Calling this explicitly allows
- running the update at an earlier point. - running the update at an earlier point.
-
- All that needs to be done is to open the database,
- that will result in Database.Keys.reconcileStaged
- running, and doing the work.
-} -}
scanAnnexedFiles :: Annex () scanAnnexedFiles :: Annex ()
scanAnnexedFiles = scanAnnexedFiles = Database.Keys.runWriter (const noop)
-- All that needs to be done is to open the database,
-- that will result in Database.Keys.reconcileStaged
-- running, and doing the work.
Database.Keys.runWriter (const noop)

View file

@ -85,7 +85,7 @@ initRepo False _ dir desc mgroup = inDir dir $ do
initRepo' :: Maybe String -> Maybe StandardGroup -> Annex () initRepo' :: Maybe String -> Maybe StandardGroup -> Annex ()
initRepo' desc mgroup = unlessM isInitialized $ do initRepo' desc mgroup = unlessM isInitialized $ do
initialize desc Nothing initialize False desc Nothing
u <- getUUID u <- getUUID
maybe noop (defaultStandardGroup u) mgroup maybe noop (defaultStandardGroup u) mgroup
{- Ensure branch gets committed right away so it is {- Ensure branch gets committed right away so it is

View file

@ -23,6 +23,9 @@ git-annex (8.20210715) UNRELEASED; urgency=medium
in a repository that was upgraded from v7. in a repository that was upgraded from v7.
* fsck: Detect and correct stale or missing inode caches. * fsck: Detect and correct stale or missing inode caches.
* Fix a rounding bug in display of data sizes. * Fix a rounding bug in display of data sizes.
* git-annex get when run as the first git-annex command in a new repo
did not populate unlocked files.
(Reversion in version 8.20210621)
-- Joey Hess <id@joeyh.name> Wed, 14 Jul 2021 14:26:36 -0400 -- Joey Hess <id@joeyh.name> Wed, 14 Jul 2021 14:26:36 -0400

View file

@ -47,7 +47,7 @@ findOrGenUUID = do
else ifM (Annex.Branch.hasSibling <||> (isJust <$> Fields.getField Fields.autoInit)) else ifM (Annex.Branch.hasSibling <||> (isJust <$> Fields.getField Fields.autoInit))
( do ( do
liftIO checkNotReadOnly liftIO checkNotReadOnly
initialize Nothing Nothing initialize True Nothing Nothing
getUUID getUUID
, return NoUUID , return NoUUID
) )

View file

@ -70,7 +70,7 @@ perform os = do
Just v | v /= wantversion -> Just v | v /= wantversion ->
giveup $ "This repository is already a initialized with version " ++ show (fromRepoVersion v) ++ ", not changing to requested version." giveup $ "This repository is already a initialized with version " ++ show (fromRepoVersion v) ++ ", not changing to requested version."
_ -> noop _ -> noop
initialize initialize False
(if null (initDesc os) then Nothing else Just (initDesc os)) (if null (initDesc os) then Nothing else Just (initDesc os))
(initVersion os) (initVersion os)
Annex.SpecialRemote.autoEnable Annex.SpecialRemote.autoEnable

View file

@ -35,6 +35,6 @@ perform s = do
then return $ toUUID s then return $ toUUID s
else Remote.nameToUUID s else Remote.nameToUUID s
storeUUID u storeUUID u
initialize' Nothing initialize' False Nothing
Annex.SpecialRemote.autoEnable Annex.SpecialRemote.autoEnable
next $ return True next $ return True

View file

@ -45,6 +45,6 @@ start (UpgradeOptions { autoOnly = True }) =
start _ = start _ =
starting "upgrade" (ActionItemOther Nothing) (SeekInput []) $ do starting "upgrade" (ActionItemOther Nothing) (SeekInput []) $ do
whenM (isNothing <$> getVersion) $ do whenM (isNothing <$> getVersion) $ do
initialize Nothing Nothing initialize False Nothing Nothing
r <- upgrade False latestVersion r <- upgrade False latestVersion
next $ return r next $ return r

View file

@ -6,4 +6,12 @@ If any other git-annex command is run before the get, it avoids the
problem. So the problem has to do with autoinit followed by reading problem. So the problem has to do with autoinit followed by reading
associated files from the keys db. associated files from the keys db.
Besected to [[!commit 428c91606b434512d1986622e751c795edf4df44]] --[[Joey]] Bisected to [[!commit 428c91606b434512d1986622e751c795edf4df44]] --[[Joey]]
It seems that reconcileStaged is populating the
associated files, but later when they're queried, the query returns an
empty list. So something to do with database write caching.
Somehow, not having init call `scanAnnexedFiles` makes this bug go away.
> [[fixed|done]] --[[Joey]]