changeset 28370:c1878afb063a

convert: hg use absolute_import
author timeless <timeless@mozdev.org>
date Wed, 02 Mar 2016 15:26:49 +0000
parents 71176606fa0a
children 630f5f04bc74
files hgext/convert/hg.py tests/test-check-py3-compat.t
diffstat 2 files changed, 52 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/hg.py	Wed Mar 02 14:56:29 2016 +0000
+++ b/hgext/convert/hg.py	Wed Mar 02 15:26:49 2016 +0000
@@ -16,24 +16,36 @@
 #   identifier to be stored in the converted revision. This will cause
 #   the converted revision to have a different identity than the
 #   source.
+from __future__ import absolute_import
 
+import cStringIO
+import os
+import re
+import time
 
-import os, time, cStringIO
+from mercurial import (
+    bookmarks,
+    context,
+    error,
+    exchange,
+    hg,
+    lock as lockmod,
+    merge as mergemod,
+    node as nodemod,
+    phases,
+    scmutil,
+    util,
+)
 from mercurial.i18n import _
-from mercurial.node import bin, hex, nullid
-from mercurial import hg, util, context, bookmarks, error, scmutil, exchange
-from mercurial import phases
-from mercurial import lock as lockmod
-from mercurial import merge as mergemod
+from . import common
+mapfile = common.mapfile
+NoRepo = common.NoRepo
 
-from common import NoRepo, commit, converter_source, converter_sink, mapfile
-
-import re
 sha1re = re.compile(r'\b[0-9a-f]{12,40}\b')
 
-class mercurial_sink(converter_sink):
+class mercurial_sink(common.converter_sink):
     def __init__(self, ui, path):
-        converter_sink.__init__(self, ui, path)
+        common.converter_sink.__init__(self, ui, path)
         self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
         self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False)
         self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default')
@@ -132,7 +144,7 @@
                 continue
             revid = revmap.get(source.lookuprev(s[0]))
             if not revid:
-                if s[0] == hex(nullid):
+                if s[0] == nodemod.nullhex:
                     revid = s[0]
                 else:
                     continue
@@ -148,7 +160,7 @@
 
             revid = s[0]
             subpath = s[1]
-            if revid != hex(nullid):
+            if revid != nodemod.nullhex:
                 revmap = self.subrevmaps.get(subpath)
                 if revmap is None:
                     revmap = mapfile(self.ui,
@@ -250,13 +262,13 @@
         parents = pl
         nparents = len(parents)
         if self.filemapmode and nparents == 1:
-            m1node = self.repo.changelog.read(bin(parents[0]))[0]
+            m1node = self.repo.changelog.read(nodemod.bin(parents[0]))[0]
             parent = parents[0]
 
         if len(parents) < 2:
-            parents.append(nullid)
+            parents.append(nodemod.nullid)
         if len(parents) < 2:
-            parents.append(nullid)
+            parents.append(nodemod.nullid)
         p2 = parents.pop(0)
 
         text = commit.desc
@@ -283,12 +295,12 @@
 
             # Only transplant stores its reference in binary
             if label == 'transplant_source':
-                node = hex(node)
+                node = nodemod.hex(node)
 
             newrev = revmap.get(node)
             if newrev is not None:
                 if label == 'transplant_source':
-                    newrev = bin(newrev)
+                    newrev = nodemod.bin(newrev)
 
                 extra[label] = newrev
 
@@ -302,7 +314,7 @@
             p2 = parents.pop(0)
             p1ctx = self.repo[p1]
             p2ctx = None
-            if p2 != nullid:
+            if p2 != nodemod.nullid:
                 p2ctx = self.repo[p2]
             fileset = set(files)
             if full:
@@ -324,7 +336,7 @@
                                    phases.phasenames[commit.phase], 'convert')
 
             with self.repo.transaction("convert") as tr:
-                node = hex(self.repo.commitctx(ctx))
+                node = nodemod.hex(self.repo.commitctx(ctx))
 
                 # If the node value has changed, but the phase is lower than
                 # draft, set it back to draft since it hasn't been exposed
@@ -340,7 +352,7 @@
 
         if self.filemapmode and nparents == 1:
             man = self.repo.manifest
-            mnode = self.repo.changelog.read(bin(p2))[0]
+            mnode = self.repo.changelog.read(nodemod.bin(p2))[0]
             closed = 'close' in commit.extra
             if not closed and not man.cmp(m1node, man.revision(mnode)):
                 self.ui.status(_("filtering out empty revision\n"))
@@ -354,7 +366,7 @@
             tagparent = parentctx.node()
         except error.RepoError:
             parentctx = None
-            tagparent = nullid
+            tagparent = nodemod.nullid
 
         oldlines = set()
         for branch, heads in self.repo.branchmap().iteritems():
@@ -397,7 +409,7 @@
                              [".hgtags"], getfilectx, "convert-repo", date,
                              extra)
         node = self.repo.commitctx(ctx)
-        return hex(node), hex(tagparent)
+        return nodemod.hex(node), nodemod.hex(tagparent)
 
     def setfilemapmode(self, active):
         self.filemapmode = active
@@ -413,7 +425,7 @@
             self.ui.status(_("updating bookmarks\n"))
             destmarks = self.repo._bookmarks
             for bookmark in updatedbookmark:
-                destmarks[bookmark] = bin(updatedbookmark[bookmark])
+                destmarks[bookmark] = nodemod.bin(updatedbookmark[bookmark])
             destmarks.recordchange(tr)
             tr.close()
         finally:
@@ -430,9 +442,9 @@
                                'are not implemented)') % rev)
         return rev in self.repo
 
-class mercurial_source(converter_source):
+class mercurial_source(common.converter_source):
     def __init__(self, ui, path, revs=None):
-        converter_source.__init__(self, ui, path, revs)
+        common.converter_source.__init__(self, ui, path, revs)
         self.ignoreerrors = ui.configbool('convert', 'hg.ignoreerrors', False)
         self.ignored = set()
         self.saverev = ui.configbool('convert', 'hg.saverev', False)
@@ -493,7 +505,7 @@
         return [p for p in ctx.parents() if p and self.keep(p.node())]
 
     def getheads(self):
-        return [hex(h) for h in self._heads if self.keep(h)]
+        return [nodemod.hex(h) for h in self._heads if self.keep(h)]
 
     def getfile(self, name, rev):
         try:
@@ -572,18 +584,23 @@
         parents = [p.hex() for p in self._parents(ctx)]
         crev = rev
 
-        return commit(author=ctx.user(),
-                      date=util.datestr(ctx.date(), '%Y-%m-%d %H:%M:%S %1%2'),
-                      desc=ctx.description(), rev=crev, parents=parents,
-                      branch=ctx.branch(), extra=ctx.extra(),
-                      sortkey=ctx.rev(), saverev=self.saverev,
-                      phase=ctx.phase())
+        return common.commit(author=ctx.user(),
+                             date=util.datestr(ctx.date(),
+                                               '%Y-%m-%d %H:%M:%S %1%2'),
+                             desc=ctx.description(),
+                             rev=crev,
+                             parents=parents,
+                             branch=ctx.branch(),
+                             extra=ctx.extra(),
+                             sortkey=ctx.rev(),
+                             saverev=self.saverev,
+                             phase=ctx.phase())
 
     def gettags(self):
         # This will get written to .hgtags, filter non global tags out.
         tags = [t for t in self.repo.tagslist()
                 if self.repo.tagtype(t[0]) == 'global']
-        return dict([(name, hex(node)) for name, node in tags
+        return dict([(name, nodemod.hex(node)) for name, node in tags
                      if self.keep(node)])
 
     def getchangedfiles(self, rev, i):
@@ -622,7 +639,7 @@
 
     def lookuprev(self, rev):
         try:
-            return hex(self.repo.lookup(rev))
+            return nodemod.hex(self.repo.lookup(rev))
         except (error.RepoError, error.LookupError):
             return None
 
--- a/tests/test-check-py3-compat.t	Wed Mar 02 14:56:29 2016 +0000
+++ b/tests/test-check-py3-compat.t	Wed Mar 02 15:26:49 2016 +0000
@@ -29,7 +29,6 @@
   hgext/convert/common.py not using absolute_import
   hgext/convert/convcmd.py not using absolute_import
   hgext/convert/cvs.py not using absolute_import
-  hgext/convert/hg.py not using absolute_import
   hgext/convert/monotone.py not using absolute_import
   hgext/convert/p4.py not using absolute_import
   hgext/convert/subversion.py not using absolute_import