Patchwork [2,of,3,stable] convert: fix crash when existing converted revision didn't come from source

login
register
mail settings
Submitter Mads Kiilerich
Date Oct. 2, 2013, 5:50 p.m.
Message ID <ba16c06cd5c53b1c8d27.1380736249@mk-desktop>
Download mbox | patch
Permalink /patch/2705/
State Accepted
Commit daeab82fa6443015755050ab91909730d02d1b55
Headers show

Comments

Mads Kiilerich - Oct. 2, 2013, 5:50 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1380736008 -7200
#      Wed Oct 02 19:46:48 2013 +0200
# Branch stable
# Node ID ba16c06cd5c53b1c8d27c76ebf57675ba73cfa50
# Parent  2cf9645bb2a21f470c2a134a05b521dff0f91905
convert: fix crash when existing converted revision didn't come from source

This case can happen when converting from multiple repositories with filemap.

Patch

diff --git a/hgext/convert/filemap.py b/hgext/convert/filemap.py
--- a/hgext/convert/filemap.py
+++ b/hgext/convert/filemap.py
@@ -7,7 +7,7 @@ 
 import posixpath
 import shlex
 from mercurial.i18n import _
-from mercurial import util
+from mercurial import util, error
 from common import SKIPREV, converter_source
 
 def rpairs(name):
@@ -195,12 +195,19 @@ 
         self.seenchildren.clear()
         for rev, wanted, arg in self.convertedorder:
             if rev not in self.origparents:
-                self.origparents[rev] = self.getcommit(rev).parents
+                try:
+                    self.origparents[rev] = self.getcommit(rev).parents
+                except error.RepoLookupError:
+                    self.ui.debug("unknown revmap source: %s\n" % rev)
+                    continue
             if arg is not None:
                 self.children[arg] = self.children.get(arg, 0) + 1
 
         for rev, wanted, arg in self.convertedorder:
-            parents = self.origparents[rev]
+            try:
+                parents = self.origparents[rev]
+            except KeyError:
+                continue # unknown revmap source
             if wanted:
                 self.mark_wanted(rev, parents)
             else:
diff --git a/tests/test-convert-filemap.t b/tests/test-convert-filemap.t
--- a/tests/test-convert-filemap.t
+++ b/tests/test-convert-filemap.t
@@ -410,6 +410,32 @@ 
   o  0 "addb" files: b
   
 
+Test rebuilding of map with unknown revisions in shamap - it used to crash
+
+  $ cd branchpruning
+  $ hg up -r 2
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg merge 4
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg ci -m 'merging something'
+  $ cd ..
+  $ echo "53792d18237d2b64971fa571936869156655338d 6d955580116e82c4b029bd30f321323bae71a7f0" >> branchpruning-hg2/.hg/shamap
+  $ hg convert --filemap branchpruning/filemap branchpruning branchpruning-hg2 --debug
+  run hg source pre-conversion action
+  run hg sink pre-conversion action
+  scanning source...
+  scanning: 1 revisions
+  sorting...
+  converting...
+  0 merging something
+  source: 2503605b178fe50e8fbbb0e77b97939540aa8c87
+  converting: 0/1 revisions (0.00%)
+  unknown revmap source: 53792d18237d2b64971fa571936869156655338d
+  run hg sink post-conversion action
+  run hg source post-conversion action
+
+
 filemap rename undoing revision rename
 
   $ hg init renameundo