summaryrefslogtreecommitdiff
path: root/Logs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-08-31 18:06:49 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-08-31 18:06:49 -0400
commit441a5dfc2fd112fd165b95fb1106f15a1255e72a (patch)
tree856b1ee18a302d8d781b3094833ed5990ee1981d /Logs
parentc9629ab97875721c8d36bdaceec25768de610b5e (diff)
graft exported tree into git-annex branch
So it will be available later and elsewhere, even after GC. I first though to use git update-index to do this, but feeding it a line with a tree object seems to always cause it to generate a git subtree merge. So, fell back to using the Git.Tree interface to maniupulate the trees, and not involving the git-annex branch index file at all. This commit was sponsored by Andreas Karlsson.
Diffstat (limited to 'Logs')
-rw-r--r--Logs/Export.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/Logs/Export.hs b/Logs/Export.hs
index a0019a06c..1fd1460fc 100644
--- a/Logs/Export.hs
+++ b/Logs/Export.hs
@@ -12,6 +12,9 @@ import qualified Data.Map as M
import Annex.Common
import qualified Annex.Branch
import qualified Git
+import qualified Git.Branch
+import Git.Tree
+import Git.FilePath
import Logs
import Logs.UUIDBased
import Annex.UUID
@@ -40,6 +43,9 @@ data ExportChange = ExportChange
-- newTreeish. This way, when multiple repositories are exporting to
-- the same special remote, there's no conflict as long as they move
-- forward in lock-step.
+--
+-- Also, the newTreeish is grafted into the git-annex branch. This is done
+-- to ensure that it's available later.
recordExport :: UUID -> ExportChange -> Annex ()
recordExport remoteuuid ec = do
c <- liftIO currentVectorClock
@@ -50,6 +56,7 @@ recordExport remoteuuid ec = do
. changeLog c u val
. M.mapWithKey (updateothers c u)
. parseLogNew parseExportLog
+ graftTreeish (newTreeish ec)
where
updateothers c u theiru le@(LogEntry _ (ExportLog t remoteuuid'))
| u == theiru || remoteuuid' /= remoteuuid || t `notElem` oldTreeish ec = le
@@ -65,3 +72,20 @@ parseExportLog :: String -> Maybe ExportLog
parseExportLog s = case words s of
(t:u:[]) -> Just $ ExportLog (Git.Ref t) (toUUID u)
_ -> Nothing
+
+-- To prevent git-annex branch merge conflicts, the treeish is
+-- first grafted in and then removed in a subsequent commit.
+graftTreeish :: Git.Ref -> Annex ()
+graftTreeish treeish = do
+ branchref <- Annex.Branch.getBranch
+ Tree t <- inRepo $ getTree branchref
+ t' <- inRepo $ recordTree $ Tree $
+ RecordedSubTree (asTopFilePath graftpoint) treeish [] : t
+ commit <- inRepo $ Git.Branch.commitTree Git.Branch.AutomaticCommit
+ "export tree" [branchref] t'
+ origtree <- inRepo $ recordTree (Tree t)
+ commit' <- inRepo $ Git.Branch.commitTree Git.Branch.AutomaticCommit
+ "export tree cleanup" [commit] origtree
+ inRepo $ Git.Branch.update' Annex.Branch.fullname commit'
+ where
+ graftpoint = "export.tree"