Mercurial > hg-stable
diff hgext/convert/filemap.py @ 17103:5146de7bce96
convert: keep branch switching merges with ancestors (issue3340)
When running convert with a filemap, merge parents which are ancestors
of other parents are ignored. This is hardly a problem when parents
belong to the same branch, but the result could be confusing when named
branches are involved. With:
-o-a1-a2-a3... <- A
\ \
b1-b2-b3...-m- <- B
If all b* revisions are discarded, it is useful to preserve 'm' even if
it is empty after filtering to record the branch switch.
This patch makes filemap preserve "ancestor parents" if there is no
"non-ancestor parent" on the same branch than the merge revision.
Remarks:
- I am not completely convinced by the reasons given above and those
detailed by Matt in this thread:
http://selenic.com/pipermail/mercurial-devel/2012-May/040627.html
The properties we try to preserve are not clearly defined. That said,
I know this patch already helped someone on IRC and the tests output
look reasonable.
- This is a new version of the original "convert: filemap must preserve
fast-forward merges" patch. It has exactly the same output for 2
parents merges, the additional complexity is here to handle more than
two parents.
author | Patrick Mezard <patrick@mezard.eu> |
---|---|
date | Mon, 18 Jun 2012 18:19:28 +0200 |
parents | 3992c7df85f2 |
children | f76e2196ee70 |
line wrap: on
line diff
--- a/hgext/convert/filemap.py Wed Jun 13 23:32:58 2012 +0200 +++ b/hgext/convert/filemap.py Mon Jun 18 18:19:28 2012 +0200 @@ -294,23 +294,34 @@ # A parent p is interesting if its mapped version (self.parentmap[p]): # - is not SKIPREV # - is still not in the list of parents (we don't want duplicates) - # - is not an ancestor of the mapped versions of the other parents + # - is not an ancestor of the mapped versions of the other parents or + # there is no parent in the same branch than the current revision. mparents = [] - wp = None + knownparents = set() + branch = self.commits[rev].branch + hasbranchparent = False for i, p1 in enumerate(parents): mp1 = self.parentmap[p1] - if mp1 == SKIPREV or mp1 in mparents: + if mp1 == SKIPREV or mp1 in knownparents: continue - for p2 in parents: - if p1 == p2 or mp1 == self.parentmap[p2]: - continue - if mp1 in self.wantedancestors[p2]: - break - else: - mparents.append(mp1) - wp = i - - if wp is None and parents: + isancestor = util.any(p2 for p2 in parents + if p1 != p2 and mp1 != self.parentmap[p2] + and mp1 in self.wantedancestors[p2]) + if not isancestor and not hasbranchparent and len(parents) > 1: + # This could be expensive, avoid unnecessary calls. + if self._cachedcommit(p1).branch == branch: + hasbranchparent = True + mparents.append((p1, mp1, i, isancestor)) + knownparents.add(mp1) + # Discard parents ancestors of other parents if there is a + # non-ancestor one on the same branch than current revision. + if hasbranchparent: + mparents = [p for p in mparents if not p[3]] + wp = None + if mparents: + wp = max(p[2] for p in mparents) + mparents = [p[1] for p in mparents] + elif parents: wp = 0 self.origparents[rev] = parents @@ -319,7 +330,6 @@ if 'close' in self.commits[rev].extra: # A branch closing revision is only useful if one of its # parents belong to the branch being closed - branch = self.commits[rev].branch pbranches = [self._cachedcommit(p).branch for p in mparents] if branch in pbranches: closed = True