scanAnnexedFiles in smudge --update
authorJoey Hess <joeyh@joeyh.name>
Tue, 8 Jun 2021 15:34:46 +0000 (11:34 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 8 Jun 2021 15:37:47 +0000 (11:37 -0400)
This makes git checkout and git merge hooks do the work to catch up with
changes that they made to the tree. Rather than doing it at some later
point when the user is not thinking about that past operation.

Sponsored-by: Dartmouth College's Datalad project
Annex/Init.hs
Annex/WorkTree.hs
Command/Smudge.hs
Upgrade/V5.hs
doc/todo/display_when_reconcileStaged_is_taking_a_long_time/comment_1_7efa1d29b475b445cea6fe44d402b275._comment [new file with mode: 0644]

index 4bd0955eaafbfd03da41598a62b434c97c3d4442..a552046a3a5e64403193359bb94aa946b5ecc801 100644 (file)
@@ -37,7 +37,6 @@ import Annex.UUID
 import Annex.WorkTree
 import Annex.Fixup
 import Annex.Path
-import Annex.Concurrent
 import Config
 import Config.Files
 import Config.Smudge
@@ -134,8 +133,7 @@ initialize' mversion = checkInitializeAllowed $ do
                then configureSmudgeFilter
                else deconfigureSmudgeFilter
        unlessM isBareRepo $ do
-               showSideActionAfter oneSecond "scanning for annexed files" $
-                       scanAnnexedFiles
+               scanAnnexedFiles True
                hookWrite postCheckoutHook
                hookWrite postMergeHook
        AdjustedBranch.checkAdjustedClone >>= \case
index ac9c49b27d43fd56f63541923481624a3ed41682..33d90948729d448e0da1d0733a5aba6f11985d64 100644 (file)
@@ -15,6 +15,8 @@ import Annex.Content
 import Annex.ReplaceFile
 import Annex.CurrentBranch
 import Annex.InodeSentinal
+import Annex.Concurrent
+import Utility.ThreadScheduler
 import Utility.InodeCache
 import Git.FilePath
 import Git.CatFile
@@ -78,8 +80,8 @@ ifAnnexed file yes no = maybe no yes =<< lookupKey file
  - But if worktree file does not have a pointer file's content, it is left
  - as-is.
  -}
-scanAnnexedFiles :: Annex ()
-scanAnnexedFiles = whenM (inRepo Git.Ref.headExists <&&> not <$> isBareRepo) $ do
+scanAnnexedFiles :: Bool -> Annex ()
+scanAnnexedFiles initscan = showSideActionAfter oneSecond "scanning for annexed files" $ do
        -- This gets the keys database populated with all annexed files,
        -- by running Database.Keys.reconcileStaged.
        Database.Keys.runWriter (const noop)
@@ -88,14 +90,19 @@ scanAnnexedFiles = whenM (inRepo Git.Ref.headExists <&&> not <$> isBareRepo) $ d
        -- annex object file already exists, but its inode is not yet
        -- cached and annex.thin is set. So, the rest of this makes
        -- another pass over the tree to do that.
-       whenM (annexThin <$> Annex.getGitConfig) $ do
-               g <- Annex.gitRepo
-               (l, cleanup) <- inRepo $ Git.LsTree.lsTree
-                       Git.LsTree.LsTreeRecursive
-                       (Git.LsTree.LsTreeLong True)
-                       Git.Ref.headRef
-               catObjectStreamLsTree l want g go
-               liftIO $ void cleanup
+       whenM
+               ( pure initscan
+               <&&> annexThin <$> Annex.getGitConfig
+               <&&> inRepo Git.Ref.headExists
+               <&&> not <$> isBareRepo
+               ) $ do
+                       g <- Annex.gitRepo
+                       (l, cleanup) <- inRepo $ Git.LsTree.lsTree
+                               Git.LsTree.LsTreeRecursive
+                               (Git.LsTree.LsTreeLong True)
+                               Git.Ref.headRef
+                       catObjectStreamLsTree l want g go
+                       liftIO $ void cleanup
   where
        -- Want to process symlinks, and regular files.
        want i = case Git.Types.toTreeItemType (Git.LsTree.mode i) of
index cbecd055f695a0bbbadaedb66531ed6bad993fa5..70fc9235ad8302d8e9c9235eec4f54803fc8fe13 100644 (file)
@@ -13,6 +13,7 @@ import Annex.Link
 import Annex.FileMatcher
 import Annex.Ingest
 import Annex.CatFile
+import Annex.WorkTree
 import Logs.Smudge
 import Logs.Location
 import qualified Database.Keys
@@ -262,6 +263,11 @@ getMoveRaceRecovery k file = void $ tryNonAsync $
 
 update :: CommandStart
 update = do
+       -- This gets run after a git checkout or merge, so it's a good
+       -- point to refresh the keys database for changes to annexed files.
+       -- Doing it explicitly here avoids a later pause in the middle of
+       -- some other action.
+       scanAnnexedFiles False
        updateSmudged (Restage True)
        stop
 
index 2db92d57f95b793a5edc341f5d198d58ddb26d87..22200b0c80cc80197d9af1d5436ef8175bc94e7f 100644 (file)
@@ -47,7 +47,7 @@ upgrade automatic = flip catchNonAsync onexception $ do
                , do
                        checkGitVersionForIndirectUpgrade
                )
-       scanAnnexedFiles
+       scanAnnexedFiles True
        configureSmudgeFilter
        -- Inode sentinal file was only used in direct mode and when
        -- locking down files as they were added. In v6, it's used more
diff --git a/doc/todo/display_when_reconcileStaged_is_taking_a_long_time/comment_1_7efa1d29b475b445cea6fe44d402b275._comment b/doc/todo/display_when_reconcileStaged_is_taking_a_long_time/comment_1_7efa1d29b475b445cea6fe44d402b275._comment
new file mode 100644 (file)
index 0000000..517e507
--- /dev/null
@@ -0,0 +1,12 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 1"""
+ date="2021-06-08T15:21:02Z"
+ content="""
+Made `git-annex smudge --update` run the scan, and so the post-checkout or
+post-merge hook will call it. 
+
+That avoids the scenario shown above. But adding a lot of files to the
+index can still cause a later pause for reconcileStaged without indication
+what it's doing.
+"""]]