Improve shape of commit tree when importing from unversioned special remotes
Make the import have the previous import as a parent, so eg `git log --stat` displays a useful diff. Also a minor optimisation, only calculate the depth of the imported history once.
This commit is contained in:
parent
5af9e7f3d0
commit
5e1221ad53
3 changed files with 29 additions and 13 deletions
|
@ -163,40 +163,44 @@ buildImportCommit remote importtreeconfig importcommitconfig importable =
|
||||||
buildImportCommit' :: ImportCommitConfig -> Maybe Sha -> History Sha -> Annex (Maybe Sha)
|
buildImportCommit' :: ImportCommitConfig -> Maybe Sha -> History Sha -> Annex (Maybe Sha)
|
||||||
buildImportCommit' importcommitconfig mtrackingcommit imported@(History ti _) =
|
buildImportCommit' importcommitconfig mtrackingcommit imported@(History ti _) =
|
||||||
case mtrackingcommit of
|
case mtrackingcommit of
|
||||||
Nothing -> Just <$> mkcommits imported
|
Nothing -> Just <$> mkcommitsunconnected imported
|
||||||
Just trackingcommit -> do
|
Just trackingcommit -> do
|
||||||
-- Get history of tracking branch to at most
|
-- Get history of tracking branch to at most
|
||||||
-- one more level deep than what was imported,
|
-- one more level deep than what was imported,
|
||||||
-- so we'll have enough history to compare,
|
-- so we'll have enough history to compare,
|
||||||
-- but not spend too much time getting it.
|
-- but not spend too much time getting it.
|
||||||
let maxdepth = succ (historyDepth imported)
|
let maxdepth = succ importeddepth
|
||||||
inRepo (getHistoryToDepth maxdepth trackingcommit)
|
inRepo (getHistoryToDepth maxdepth trackingcommit)
|
||||||
>>= go trackingcommit
|
>>= go trackingcommit
|
||||||
where
|
where
|
||||||
go _ Nothing = Just <$> mkcommits imported
|
go _ Nothing = Just <$> mkcommitsunconnected imported
|
||||||
go trackingcommit (Just h)
|
go trackingcommit (Just h)
|
||||||
-- If the tracking branch head is a merge commit
|
-- If the tracking branch head is a merge commit
|
||||||
-- with a tree that matches the head of the history,
|
-- with a tree that matches the head of the history,
|
||||||
-- and one side of the merge matches the history,
|
-- and one side of the merge matches the history,
|
||||||
-- nothing new needs to be committed.
|
-- nothing new needs to be committed.
|
||||||
| t == ti && any (sametodepth imported) (S.toList s) = return Nothing
|
| t == ti && any sametodepth (S.toList s) = return Nothing
|
||||||
-- If the tracking branch matches the history,
|
-- If the tracking branch matches the history,
|
||||||
-- nothing new needs to be committed.
|
-- nothing new needs to be committed.
|
||||||
-- (This is unlikely to happen.)
|
-- (This is unlikely to happen.)
|
||||||
| sametodepth imported h' = return Nothing
|
| sametodepth h' = return Nothing
|
||||||
| otherwise = do
|
| otherwise = do
|
||||||
importedcommit <- case getRemoteTrackingBranchImportHistory h of
|
importedcommit <- case getRemoteTrackingBranchImportHistory h of
|
||||||
Nothing ->
|
Nothing -> mkcommitsunconnected imported
|
||||||
mkcommits imported
|
Just oldimported@(History oldhc _)
|
||||||
Just oldimported@(History oldhc _) -> do
|
| importeddepth == 1 ->
|
||||||
let oldimportedtrees = mapHistory historyCommitTree oldimported
|
mkcommitconnected imported oldimported
|
||||||
mknewcommits oldhc oldimportedtrees imported
|
| otherwise -> do
|
||||||
|
let oldimportedtrees = mapHistory historyCommitTree oldimported
|
||||||
|
mknewcommits oldhc oldimportedtrees imported
|
||||||
Just <$> makeRemoteTrackingBranchMergeCommit'
|
Just <$> makeRemoteTrackingBranchMergeCommit'
|
||||||
trackingcommit importedcommit ti
|
trackingcommit importedcommit ti
|
||||||
where
|
where
|
||||||
h'@(History t s) = mapHistory historyCommitTree h
|
h'@(History t s) = mapHistory historyCommitTree h
|
||||||
|
|
||||||
sametodepth a b = a == truncateHistoryToDepth (historyDepth a) b
|
importeddepth = historyDepth imported
|
||||||
|
|
||||||
|
sametodepth b = imported == truncateHistoryToDepth importeddepth b
|
||||||
|
|
||||||
mkcommit parents tree = inRepo $ Git.Branch.commitTree
|
mkcommit parents tree = inRepo $ Git.Branch.commitTree
|
||||||
(importCommitMode importcommitconfig)
|
(importCommitMode importcommitconfig)
|
||||||
|
@ -204,8 +208,16 @@ buildImportCommit' importcommitconfig mtrackingcommit imported@(History ti _) =
|
||||||
parents
|
parents
|
||||||
tree
|
tree
|
||||||
|
|
||||||
mkcommits (History importedtree hs) = do
|
-- Start a new history of import commits, not connected to any
|
||||||
parents <- mapM mkcommits (S.toList hs)
|
-- prior import commits.
|
||||||
|
mkcommitsunconnected (History importedtree hs) = do
|
||||||
|
parents <- mapM mkcommitsunconnected (S.toList hs)
|
||||||
|
mkcommit parents importedtree
|
||||||
|
|
||||||
|
-- Commit the new history connected with the old history.
|
||||||
|
-- Used when the import is not versioned, so the history depth is 1.
|
||||||
|
mkcommitconnected (History importedtree _) (History oldhc _) = do
|
||||||
|
let parents = [historyCommit oldhc]
|
||||||
mkcommit parents importedtree
|
mkcommit parents importedtree
|
||||||
|
|
||||||
-- Reuse the commits from the old imported History when possible.
|
-- Reuse the commits from the old imported History when possible.
|
||||||
|
|
|
@ -5,6 +5,8 @@ git-annex (7.20190508) UNRELEASED; urgency=medium
|
||||||
* Makefile: Added install-completions to install target.
|
* Makefile: Added install-completions to install target.
|
||||||
* Added the ability to run one job per CPU (core), by setting
|
* Added the ability to run one job per CPU (core), by setting
|
||||||
annex.jobs=cpus, or using option --jobs=cpus or -Jcpus.
|
annex.jobs=cpus, or using option --jobs=cpus or -Jcpus.
|
||||||
|
* Improve shape of commit tree when importing from unversioned special
|
||||||
|
remotes.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Mon, 06 May 2019 13:52:02 -0400
|
-- Joey Hess <id@joeyh.name> Mon, 06 May 2019 13:52:02 -0400
|
||||||
|
|
||||||
|
|
|
@ -18,3 +18,5 @@ and adds more commits on top of those, so this is mostly not a problem
|
||||||
there. If the old and new imported histories are disjoint, a commit or
|
there. If the old and new imported histories are disjoint, a commit or
|
||||||
commits will be made with no parent, but that seems acceptable; it's an
|
commits will be made with no parent, but that seems acceptable; it's an
|
||||||
edge case and it's replicating the information from the remote.
|
edge case and it's replicating the information from the remote.
|
||||||
|
|
||||||
|
> [[done]] --[[Joey]]
|
||||||
|
|
Loading…
Add table
Reference in a new issue