adapt recent bug fixes to support private journal
authorJoey Hess <joeyh@joeyh.name>
Wed, 21 Apr 2021 19:54:37 +0000 (15:54 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 21 Apr 2021 20:01:13 +0000 (16:01 -0400)
At this point, private repos should mostly work, except for a few
commands that directly read from the git-annex branch and will not see
the private journal.

Private index not yet implemented.

Annex/Branch.hs
Annex/Journal.hs

index e8b4d776940fee8c6247906a382be0d8ad15ce08..36b8024c8de749bbc89af46665fce2ba33204618 100644 (file)
@@ -274,7 +274,8 @@ precache file branchcontent = do
        st <- getState
        content <- if journalIgnorable st
                then pure branchcontent
-               else fromMaybe branchcontent <$> getJournalFileStale file
+               else fromMaybe branchcontent
+                       <$> getJournalFileStale (GetPrivate True) file
        Annex.BranchState.setCache file content
 
 {- Like get, but does not merge the branch, so the info returned may not
@@ -439,17 +440,21 @@ files :: Annex ([RawFilePath], IO Bool)
 files = do
        _  <- update
        (bfs, cleanup) <- branchFiles
-       -- ++ forces the content of all but the last list to be buffered in
-       -- memory, so use getJournalledFilesStale which should be much smaller
+       -- ++ forces the content of the first list to be buffered in
+       -- memory, so use journalledFiles, which should be much smaller
        -- most of the time. branchFiles will stream as the list is consumed.
-       l <- (\a b c -> a ++ b ++ c)
-               <$> (if privateUUIDsKnown 
-                       then getJournalledFilesStale gitAnnexPrivateJournalDir
-                       else pure [])
-               <*> (getJournalledFilesStale gitAnnexJournalDir)
-               <*> pure bfs
+       l <- (++) <$> journalledFiles <*> pure bfs
        return (l, cleanup)
 
+{- Lists all files currently in the journal. There may be duplicates in
+ - the list when using a private journal. -}
+journalledFiles :: Annex [RawFilePath]
+journalledFiles
+       | privateUUIDsKnown = (++)
+               <$> getJournalledFilesStale gitAnnexPrivateJournalDir
+               <*> getJournalledFilesStale gitAnnexJournalDir
+       | otherwise = getJournalledFilesStale gitAnnexJournalDir
+
 {- Files in the branch, not including any from journalled changes,
  - and without updating the branch. -}
 branchFiles :: Annex ([RawFilePath], IO Bool)
@@ -801,7 +806,8 @@ overBranchFileContents select go = do
                        -- committed to the branch
                        content' <- if journalIgnorable st
                                then pure content
-                               else maybe content Just <$> getJournalFileStale f
+                               else maybe content Just 
+                                       <$> getJournalFileStale (GetPrivate True) f
                        return (Just (v, f, content'))
                Nothing
                        | journalIgnorable st -> return Nothing
@@ -812,7 +818,7 @@ overBranchFileContents select go = do
                        -- This can cause the action to be run a
                        -- second time with a file it already ran on.
                        | otherwise -> liftIO (tryTakeMVar buf) >>= \case
-                               Nothing -> drain buf =<< getJournalledFilesStale
+                               Nothing -> drain buf =<< journalledFiles
                                Just fs -> drain buf fs
        catObjectStreamLsTree l (select' . getTopFilePath . Git.LsTree.file) g go'
        liftIO $ void cleanup
@@ -825,7 +831,7 @@ overBranchFileContents select go = do
        drain buf fs = case getnext fs of
                Just (v, f, fs') -> do
                        liftIO $ putMVar buf fs'
-                       content <- getJournalFileStale f
+                       content <- getJournalFileStale (GetPrivate True) f
                        return (Just (v, f, content))
                Nothing -> do
                        liftIO $ putMVar buf []
index 11c1692f6ffe680700f03d6fcf08ca1e91a6a88b..359ebe07a704af3a60940e5a947f65fe4622bcd2 100644 (file)
@@ -49,13 +49,14 @@ instance Journalable Builder where
 data RegardingUUID = RegardingUUID [UUID]
 
 regardingPrivateUUID :: RegardingUUID -> Bool
-regardingPrivateUUID _ = False -- TODO
+regardingPrivateUUID (RegardingUUID []) = False
+regardingPrivateUUID (RegardingUUID _) = True -- TODO
 
 -- Are any private UUIDs known to exist? If so, extra work has to be done,
 -- to check for information separately recorded for them, outside the usual
 -- locations.
 privateUUIDsKnown :: Bool
-privateUUIDsKnown = False -- TODO
+privateUUIDsKnown = True -- TODO
 
 {- Records content for a file in the branch to the journal.
  -