changeset 337:ebfd1b96a013 stable

obsolete: convert try to guess what invalid node id are invalid input are probably short version of node
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Wed, 04 Jul 2012 18:00:43 +0200
parents 7db8107eef30
children b922d144f93d
files hgext/obsolete.py
diffstat 1 files changed, 20 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/obsolete.py	Wed Jul 04 17:51:33 2012 +0200
+++ b/hgext/obsolete.py	Wed Jul 04 18:00:43 2012 +0200
@@ -569,7 +569,7 @@
 def cmddebugconvertobsolete(ui, repo):
     """import markers from an .hg/obsolete-relations file"""
     cnt = 0
-    error = 0
+    err = 0
     l = repo.lock()
     some = False
     try:
@@ -601,22 +601,29 @@
         if data:
             some = True
             for oldmark in json.loads(data):
-                del oldmark['id'] # dropped for now
-                del oldmark['reason'] # unused until then
-                oldobject = oldmark['object']
-                oldsubjects = oldmark['subjects']
-                oldmark['subjects'] = [bin(n) for n in oldmark['subjects']]
-                oldmark['object'] = bin(oldmark['object'])
+                del oldmark['id']  # dropped for now
+                del oldmark['reason']  # unused until then
+                oldobject = str(oldmark.pop('object'))
+                oldsubjects = [str(s) for s in oldmark.pop('subjects')]
+                if len(oldobject) != 40:
+                    try:
+                        oldobject = repo[oldobject].node()
+                    except error.RepoLookupError:
+                        pass
+                if any(len(s) != 40 for s in oldsubjects):
+                    try:
+                        oldsubjects = [repo[s].node() for s in oldsubjects]
+                    except error.RepoLookupError:
+                        pass
+
                 oldmark['date'] = '%i %i' % tuple(oldmark['date'])
-                assert oldmark['object'], repr(oldmark['object'])
                 try:
-                    store.create(oldmark.pop('object'),
-                                 oldmark.pop('subjects'),
+                    store.create(bin(oldobject), [bin(n) for n in oldsubjects],
                                  0, oldmark)
                 except ValueError:
                     repo.ui.write_err("invalid marker %s -> %s\n"
                                  % (oldobject, oldsubjects))
-                    error += 1
+                    err += 1
                 cnt += 1
             util.unlink(repo.sjoin('obsoletemarkers'))
     finally:
@@ -625,8 +632,8 @@
     if not some:
             ui.warn('nothing to do\n')
     ui.status('%i obsolete marker converted\n' % cnt)
-    if error:
-        ui.write_err('%i conversion failed. check you graph!\n' % error)
+    if err:
+        ui.write_err('%i conversion failed. check you graph!\n' % err)
 
 @command('debugsuccessors', [], '')
 def cmddebugsuccessors(ui, repo):