# HG changeset patch # User Patrick Mezard # Date 2010-01-01 13:29:36 # Node ID a9f60014a20f9eb4c7621a48bf25be52b759a423 # Parent 513c89a60f203a8387d8dfa6f2dc67b21725790a # Parent 83cfa1baf8ad6d3f28eff03dec4c2ab282d87b65 Merge with crew-stable diff --git a/mercurial/copies.py b/mercurial/copies.py --- a/mercurial/copies.py +++ b/mercurial/copies.py @@ -50,7 +50,9 @@ def _findoldnames(fctx, limit): return [o[1] for o in sorted(old.values())] def _findlimit(repo, a, b): - "find the earliest revision that's an ancestor of a or b but not both" + """Find the earliest revision that's an ancestor of a or b but not both, + None if no such revision exists. + """ # basic idea: # - mark a and b with different sides # - if a parent's children are all on the same side, the parent is @@ -73,6 +75,7 @@ def _findlimit(repo, a, b): visit = [-a, -b] heapq.heapify(visit) interesting = len(visit) + hascommonancestor = False limit = working while interesting: @@ -82,6 +85,8 @@ def _findlimit(repo, a, b): else: parents = cl.parentrevs(r) for p in parents: + if p < 0: + continue if p not in side: # first time we see p; add it to visit side[p] = side[r] @@ -92,9 +97,13 @@ def _findlimit(repo, a, b): # p was interesting but now we know better side[p] = 0 interesting -= 1 + hascommonancestor = True if side[r]: limit = r # lowest rev visited interesting -= 1 + + if not hascommonancestor: + return None return limit def copies(repo, c1, c2, ca, checkdirs=False): @@ -110,6 +119,9 @@ def copies(repo, c1, c2, ca, checkdirs=F return repo.dirstate.copies(), {} limit = _findlimit(repo, c1.rev(), c2.rev()) + if limit is None: + # no common ancestor, no copies + return {}, {} m1 = c1.manifest() m2 = c2.manifest() ma = ca.manifest() diff --git a/tests/test-mv-cp-st-diff b/tests/test-mv-cp-st-diff --- a/tests/test-mv-cp-st-diff +++ b/tests/test-mv-cp-st-diff @@ -78,3 +78,18 @@ tb "hg cp a b" "hg cp b c" "hg cp c d" " tb "add a a1" "hg mv a b" "hg mv b a" "circular rename" tb "hg mv x y" "add y/x x1" "add y/x x2" "directory move" + +# Cannot implement unrelated branch with tb +echo '% testing copies with unrelated branch' +hg init unrelated +cd unrelated +add a a +hg ci -Am adda +hg mv a b +hg ci -m movea +hg up -C null +add a a +hg ci -Am addunrelateda +echo '% unrelated branch diff' +hg diff --git -r 2 -r 1 +cd .. diff --git a/tests/test-mv-cp-st-diff.out b/tests/test-mv-cp-st-diff.out --- a/tests/test-mv-cp-st-diff.out +++ b/tests/test-mv-cp-st-diff.out @@ -1234,3 +1234,21 @@ new file mode 100644 +y1 +% testing copies with unrelated branch +adding a +0 files updated, 0 files merged, 1 files removed, 0 files unresolved +adding a +created new head +% unrelated branch diff +diff --git a/a b/a +deleted file mode 100644 +--- a/a ++++ /dev/null +@@ -1,1 +0,0 @@ +-a +diff --git a/b b/b +new file mode 100644 +--- /dev/null ++++ b/b +@@ -0,0 +1,1 @@ ++a