add back non-preferred files to imported tree

Prevents merging the import from deleting the non-preferred files from
the branch it's merged into.

adjustTree previously appended the new list of items to the old, which
could result in it generating a tree with multiple files with the same
name. That is not good and confuses some parts of git. Gave it a
function to resolve such conflicts.

That allowed dealing with the problem of what happens when the import
contains some files (or subtrees) with the same name as files that were
filtered out of the export. The files from the import win.
This commit is contained in:
Joey Hess 2019-05-20 16:37:04 -04:00
parent 7d177b78e4
commit 97fd9da6e7
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
9 changed files with 185 additions and 47 deletions

View file

@ -15,6 +15,8 @@ module Logs.Export (
incompleteExportedTreeishes,
recordExport,
recordExportBeginning,
logExportExcluded,
getExportExcluded,
) where
import qualified Data.Map as M
@ -26,6 +28,9 @@ import Git.Sha
import Git.FilePath
import Logs
import Logs.MapLog
import Logs.File
import qualified Git.LsTree
import qualified Git.Tree
import Annex.UUID
import qualified Data.ByteString.Lazy as L
@ -156,3 +161,23 @@ exportedParser = Exported <$> refparser <*> many refparser
where
refparser = (Git.Ref . decodeBS <$> A8.takeWhile1 (/= ' ') )
<* ((const () <$> A8.char ' ') <|> A.endOfInput)
logExportExcluded :: UUID -> ((Git.Tree.TreeItem -> IO ()) -> Annex a) -> Annex a
logExportExcluded u a = do
logf <- fromRepo $ gitAnnexExportExcludeLog u
withLogHandle logf $ \logh -> do
liftIO $ hSetNewlineMode logh noNewlineTranslation
a (writer logh)
where
writer logh = hPutStrLn logh
. Git.LsTree.formatLsTree
. Git.Tree.treeItemToLsTreeItem
getExportExcluded :: UUID -> Annex [Git.Tree.TreeItem]
getExportExcluded u = do
logf <- fromRepo $ gitAnnexExportExcludeLog u
liftIO $ catchDefaultIO [] $
(map parser . lines)
<$> readFile logf
where
parser = Git.Tree.lsTreeItemToTreeItem . Git.LsTree.parseLsTree