changeset 348:afbe4fc8de42

Merge with debugconvertobsolete update
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Tue, 10 Jul 2012 01:05:13 +0200
parents 631cdf4295bc (current diff) 62de989b2a02 (diff)
children 9c156b9caa4f
files hgext/obsolete.py
diffstat 2 files changed, 39 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Sun Jul 08 19:18:07 2012 +0200
+++ b/.hgtags	Tue Jul 10 01:05:13 2012 +0200
@@ -1,3 +1,4 @@
 6c6bb7a23bb5125bf06da73265f039dd3447dafa 0.1.0
 d3f20770b86a31dba56ae7b252089e12b34702da 0.2.0
 c046b083a5e0b21af69027f31cee141800cf894b 0.3.0
+9bbcd274689829d9239978236e16610688978233 0.4.0
--- a/hgext/obsolete.py	Sun Jul 08 19:18:07 2012 +0200
+++ b/hgext/obsolete.py	Tue Jul 10 01:05:13 2012 +0200
@@ -526,6 +526,7 @@
 def cmddebugconvertobsolete(ui, repo):
     """import markers from an .hg/obsolete-relations file"""
     cnt = 0
+    err = 0
     l = repo.lock()
     some = False
     try:
@@ -545,8 +546,13 @@
                         'date':  '%i %i' % util.makedate(),
                         'user': ui.username(),
                         }
-                    store.create(prec, sucs, 0, meta)
-                    cnt += 1
+                    try:
+                        store.create(prec, sucs, 0, meta)
+                        cnt += 1
+                    except ValueError:
+                        repo.ui.write_err("invalid old marker line: %s"
+                                          % (line))
+                        err += 1
             finally:
                 f.close()
             util.unlink(repo.join('obsolete-relations'))
@@ -557,15 +563,33 @@
         if data:
             some = True
             for oldmark in json.loads(data):
-                del oldmark['id'] # dropped for now
-                del oldmark['reason'] # unused until then
-                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')]
+                LOOKUP_ERRORS = (error.RepoLookupError, error.LookupError)
+                if len(oldobject) != 40:
+                    try:
+                        oldobject = repo[oldobject].node()
+                    except LOOKUP_ERRORS:
+                        pass
+                if any(len(s) != 40 for s in oldsubjects):
+                    try:
+                        oldsubjects = [repo[s].node() for s in oldsubjects]
+                    except LOOKUP_ERRORS:
+                        pass
+
                 oldmark['date'] = '%i %i' % tuple(oldmark['date'])
-                store.create(oldmark.pop('object'),
-                             oldmark.pop('subjects'),
-                             0, oldmark)
-                cnt += 1
+                meta = dict((k.encode('utf-8'), v.encode('utf-8'))
+                             for k, v in oldmark.iteritems())
+                try:
+                    store.create(bin(oldobject), [bin(n) for n in oldsubjects],
+                                 0, meta)
+                    cnt += 1
+                except ValueError:
+                    repo.ui.write_err("invalid marker %s -> %s\n"
+                                 % (oldobject, oldsubjects))
+                    err += 1
             util.unlink(repo.sjoin('obsoletemarkers'))
     finally:
         del repo._importoldobsolete
@@ -573,6 +597,8 @@
     if not some:
             ui.warn('nothing to do\n')
     ui.status('%i obsolete marker converted\n' % cnt)
+    if err:
+        ui.write_err('%i conversion failed. check you graph!\n' % err)
 
 @command('debugsuccessors', [], '')
 def cmddebugsuccessors(ui, repo):
@@ -736,6 +762,8 @@
     if not repo.local():
         return
 
+    if not util.safehasattr(repo.opener, 'tryread'):
+        raise util.Abort('Obsolete extension require Mercurial 2.2 (or later)')
     opull = repo.pull
     opush = repo.push
     olock = repo.lock