Patchwork [stable] graft: fix collision detection with origin revisions that are missing

login
register
mail settings
Submitter Mads Kiilerich
Date Aug. 27, 2014, 2:33 p.m.
Message ID <3e70daf8fe69c7a3a472.1409149986@mk-desktop>
Download mbox | patch
Permalink /patch/5608/
State Accepted
Headers show

Comments

Mads Kiilerich - Aug. 27, 2014, 2:33 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1409146209 -7200
#      Wed Aug 27 15:30:09 2014 +0200
# Branch stable
# Node ID 3e70daf8fe69c7a3a4720577c6da79ce8d504411
# Parent  510cafe720043af3d0c11b4b70345b63b54d17b1
graft: fix collision detection with origin revisions that are missing

When grafting something with a matching origin, it would normally be skipped:
  skipping already grafted revision 123 (23 also has origin 12)

But after stripping a graft origin, graft could fail with a reference to the
origin that no longer exists:
  abort: unknown revision '5c095ad7e90f871700f02dd1fa5012cb4498a2d4'!

Instead, detect that the origin is unknown and skip it anyway, like:
  skipping already grafted revision 8 (2 also has unknown origin 5c095ad7e90f871700f02dd1fa5012cb4498a2d4)
Matt Mackall - Aug. 27, 2014, 2:48 p.m.
On Wed, 2014-08-27 at 16:33 +0200, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1409146209 -7200
> #      Wed Aug 27 15:30:09 2014 +0200
> # Branch stable
> # Node ID 3e70daf8fe69c7a3a4720577c6da79ce8d504411
> # Parent  510cafe720043af3d0c11b4b70345b63b54d17b1
> graft: fix collision detection with origin revisions that are missing

Queued for stable, thanks.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3183,14 +3183,23 @@  def graft(ui, repo, *revs, **opts):
         ctx = repo[rev]
         n = ctx.extra().get('source')
         if n in ids:
-            r = repo[n].rev()
+            try:
+                r = repo[n].rev()
+            except error.RepoLookupError:
+                r = None
             if r in revs:
                 ui.warn(_('skipping revision %s (already grafted to %s)\n')
                         % (r, rev))
                 revs.remove(r)
             elif ids[n] in revs:
-                ui.warn(_('skipping already grafted revision %s '
-                            '(%s also has origin %d)\n') % (ids[n], rev, r))
+                if r is None:
+                    ui.warn(_('skipping already grafted revision %s '
+                              '(%s also has unknown origin %s)\n')
+                            % (ids[n], rev, n))
+                else:
+                    ui.warn(_('skipping already grafted revision %s '
+                              '(%s also has origin %d)\n')
+                            % (ids[n], rev, r))
                 revs.remove(ids[n])
         elif ctx.hex() in ids:
             r = ids[ctx.hex()]
diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -631,3 +631,15 @@  graft works on complex revset
   grafting revision 13
   grafting revision 19
   merging b
+
+
+Continue testing same origin policy, using revision numbers from test above
+but do some destructive editing of the repo:
+
+  $ hg up -qC 7
+  $ hg tag -l -r 13 tmp
+  $ hg --config extensions.mq= strip 2
+  saved backup bundle to $TESTTMP/a/.hg/strip-backup/5c095ad7e90f-backup.hg (glob)
+  $ hg graft tmp
+  skipping already grafted revision 8 (2 also has unknown origin 5c095ad7e90f871700f02dd1fa5012cb4498a2d4)
+  [255]