work around strange auto-init bug
authorJoey Hess <joeyh@joeyh.name>
Fri, 30 Jul 2021 22:36:03 +0000 (18:36 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 30 Jul 2021 22:36:03 +0000 (18:36 -0400)
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
428c91606b434512d1986622e751c795edf4df44 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
Annex/Init.hs
Annex/WorkTree.hs
Assistant/MakeRepo.hs
CHANGELOG
Command/ConfigList.hs
Command/Init.hs
Command/Reinit.hs
Command/Upgrade.hs
doc/bugs/initial_get_of_unlocked_file_fails_to_populate_pointer.mdwn

index adbee093331e2e34b24b3d40890c3445e57e12a8..7bfd13b1180009fd060498ef36790d695506578b 100644 (file)
@@ -96,8 +96,8 @@ genDescription Nothing = do
                Right username -> [username, at, hostname, ":", reldir]
                Left _ -> [hostname, ":", reldir]
 
-initialize :: Maybe String -> Maybe RepoVersion -> Annex ()
-initialize mdescription mversion = checkInitializeAllowed $ do
+initialize :: Bool -> Maybe String -> Maybe RepoVersion -> Annex ()
+initialize autoinit mdescription mversion = checkInitializeAllowed $ do
        {- Has to come before any commits are made as the shared
         - clone heuristic expects no local objects. -}
        sharedclone <- checkSharedClone
@@ -107,10 +107,10 @@ initialize mdescription mversion = checkInitializeAllowed $ do
        ensureCommit $ Annex.Branch.create
 
        prepUUID
-       initialize' mversion
+       initialize' autoinit mversion
        
        initSharedClone sharedclone
-
+       
        u <- getUUID
        {- Avoid overwriting existing description with a default
         - description. -}
@@ -119,8 +119,8 @@ initialize mdescription mversion = checkInitializeAllowed $ do
 
 -- Everything except for uuid setup, shared clone setup, and initial
 -- description.
-initialize' :: Maybe RepoVersion -> Annex ()
-initialize' mversion = checkInitializeAllowed $ do
+initialize' :: Bool -> Maybe RepoVersion -> Annex ()
+initialize' autoinit mversion = checkInitializeAllowed $ do
        checkLockSupport
        checkFifoSupport
        checkCrippledFileSystem
@@ -135,9 +135,11 @@ initialize' mversion = checkInitializeAllowed $ do
                then configureSmudgeFilter
                else deconfigureSmudgeFilter
        unlessM isBareRepo $ do
-               scanAnnexedFiles
                hookWrite postCheckoutHook
                hookWrite postMergeHook
+               unless autoinit $
+                       scanAnnexedFiles
+
        AdjustedBranch.checkAdjustedClone >>= \case
                AdjustedBranch.InAdjustedClone -> return ()
                AdjustedBranch.NotInAdjustedClone ->
@@ -198,7 +200,7 @@ ensureInitialized = getInitializedVersion >>= maybe needsinit checkUpgrade
   where
        needsinit = ifM autoInitializeAllowed
                ( do
-                       initialize Nothing Nothing
+                       initialize True Nothing Nothing
                        autoEnableSpecialRemotes
                , giveup "First run: git-annex init"
                )
@@ -232,7 +234,7 @@ autoInitialize = getInitializedVersion >>= maybe needsinit checkUpgrade
   where
        needsinit =
                whenM (initializeAllowed <&&> autoInitializeAllowed) $ do
-                       initialize Nothing Nothing
+                       initialize True Nothing Nothing
                        autoEnableSpecialRemotes
 
 {- Checks if a repository is initialized. Does not check version for ugrade. -}
index 7bb4b9fe00b98078dc5d125bfc0be1ceb412b2cd..d7e423c6e856ee7169ac62fa0e0f723f415b95e5 100644 (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
  - opened, and changes are noticed. Calling this explicitly allows
  - 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 =
-       -- 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)
+scanAnnexedFiles = Database.Keys.runWriter (const noop)
index 10f76287430a01e7b66a9adb7066a30b27c58803..8132dbca53df1e76e05fada2ca48e9b99e91023c 100644 (file)
@@ -85,7 +85,7 @@ initRepo False _ dir desc mgroup = inDir dir $ do
 
 initRepo' :: Maybe String -> Maybe StandardGroup -> Annex ()
 initRepo' desc mgroup = unlessM isInitialized $ do
-       initialize desc Nothing
+       initialize False desc Nothing
        u <- getUUID
        maybe noop (defaultStandardGroup u) mgroup
        {- Ensure branch gets committed right away so it is
index 44d25e8e774b198cc065246ddc14b6112048adef..7f00a838198f7ee68dab96c780fa724901e499a8 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -23,6 +23,9 @@ git-annex (8.20210715) UNRELEASED; urgency=medium
     in a repository that was upgraded from v7.
   * fsck: Detect and correct stale or missing inode caches.
   * 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
 
index bb33f7102b9085cf37fab51196b08c0143d694dd..d259b87409f48492f5446669b40be20153854e0d 100644 (file)
@@ -47,7 +47,7 @@ findOrGenUUID = do
                else ifM (Annex.Branch.hasSibling <||> (isJust <$> Fields.getField Fields.autoInit))
                        ( do
                                liftIO checkNotReadOnly
-                               initialize Nothing Nothing
+                               initialize True Nothing Nothing
                                getUUID
                        , return NoUUID
                        )
index 179a21e04620e0eb18b5ac1ad4aeee4858ceec86..d1a01697246c5d682b9c28fc09e2740866485ff4 100644 (file)
@@ -70,7 +70,7 @@ perform os = do
                        Just v | v /= wantversion ->
                                giveup $ "This repository is already a initialized with version " ++ show (fromRepoVersion v) ++ ", not changing to requested version."
                        _ -> noop
-       initialize
+       initialize False
                (if null (initDesc os) then Nothing else Just (initDesc os))
                (initVersion os)
        Annex.SpecialRemote.autoEnable
index abf9b1cdaf5891d70e9ba3819da7555954a51551..1b525cbd422117ea74ebef1017a7545748a1f6ca 100644 (file)
@@ -35,6 +35,6 @@ perform s = do
                then return $ toUUID s
                else Remote.nameToUUID s
        storeUUID u
-       initialize' Nothing
+       initialize' False Nothing
        Annex.SpecialRemote.autoEnable
        next $ return True
index 77f569a15bfe942653b3c82632cf88e442929d1e..f2f05122fca04ba9b245c8ad148a94a59e565bdf 100644 (file)
@@ -45,6 +45,6 @@ start (UpgradeOptions { autoOnly = True }) =
 start _ =
        starting "upgrade" (ActionItemOther Nothing) (SeekInput []) $ do
                whenM (isNothing <$> getVersion) $ do
-                       initialize Nothing Nothing
+                       initialize False Nothing Nothing
                r <- upgrade False latestVersion
                next $ return r
index a3dd95ebf8ea658737a336122148c47136e193d1..d2eea4c95da7d355d97311bff98abec518f6f409 100644 (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
 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]]