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

View file

@ -5,11 +5,12 @@
- Licensed under the GNU AGPL version 3 or higher.
-}
module Logs.File (writeLogFile, appendLogFile, streamLogFile) where
module Logs.File (writeLogFile, withLogHandle, appendLogFile, streamLogFile) where
import Annex.Common
import Annex.Perms
import Annex.LockFile
import Annex.ReplaceFile
import qualified Git
import Utility.Tmp
@ -23,6 +24,19 @@ writeLogFile f c = createDirWhenNeeded f $ viaTmp writelog f c
liftIO $ writeFile f' c'
setAnnexFilePerm f'
-- | Runs the action with a handle connected to a temp file.
-- The temp file replaces the log file once the action succeeds.
withLogHandle :: FilePath -> (Handle -> Annex a) -> Annex a
withLogHandle f a = do
createAnnexDirectory (parentDir f)
replaceFile f $ \tmp ->
bracket (setup tmp) cleanup a
where
setup tmp = do
setAnnexFilePerm tmp
liftIO $ openFile tmp WriteMode
cleanup h = liftIO $ hClose h
-- | Appends a line to a log file, first locking it to prevent
-- concurrent writers.
appendLogFile :: FilePath -> (Git.Repo -> FilePath) -> String -> Annex ()