[PATCH v2] transplant: use absolute_import

timeless timeless at mozdev.org
Wed Mar 2 16:54:28 EST 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1456808023 0
#      Tue Mar 01 04:53:43 2016 +0000
# Node ID 9272ce25eea5e2decb8d06094c7ba95dccc3025a
# Parent  c7f89ad87baef87f00c507545dfd4cc824bc3131
transplant: use absolute_import

diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -13,13 +13,27 @@
 Transplanted patches are recorded in .hg/transplant/transplants, as a
 map from a changeset hash to its hash in the source repository.
 '''
+from __future__ import absolute_import
 
+import os
+import tempfile
 from mercurial.i18n import _
-import os, tempfile
-from mercurial.node import short
-from mercurial import bundlerepo, hg, merge, match
-from mercurial import patch, revlog, scmutil, util, error, cmdutil
-from mercurial import revset, templatekw, exchange
+from mercurial import (
+    bundlerepo,
+    cmdutil,
+    error,
+    exchange,
+    hg,
+    match,
+    merge,
+    node as nodemod,
+    patch,
+    revlog,
+    revset,
+    scmutil,
+    templatekw,
+    util,
+)
 
 class TransplantError(error.Abort):
     pass
@@ -64,7 +78,7 @@
             fp = self.opener(self.transplantfile, 'w')
             for list in self.transplants.itervalues():
                 for t in list:
-                    l, r = map(revlog.hex, (t.lnode, t.rnode))
+                    l, r = map(nodemod.hex, (t.lnode, t.rnode))
                     fp.write(l + ':' + r + '\n')
             fp.close()
         self.dirty = False
@@ -133,7 +147,7 @@
             tr = repo.transaction('transplant')
             for rev in revs:
                 node = revmap[rev]
-                revstr = '%s:%s' % (rev, short(node))
+                revstr = '%s:%s' % (rev, nodemod.short(node))
 
                 if self.applied(repo, node, p1):
                     self.ui.warn(_('skipping already applied revision %s\n') %
@@ -168,13 +182,14 @@
                 if parents[1] != revlog.nullid:
                     if not opts.get('parent'):
                         self.ui.note(_('skipping merge changeset %s:%s\n')
-                                     % (rev, short(node)))
+                                     % (rev, nodemod.short(node)))
                         skipmerge = True
                     else:
                         parent = source.lookup(opts['parent'])
                         if parent not in parents:
                             raise error.Abort(_('%s is not a parent of %s') %
-                                             (short(parent), short(node)))
+                                              (nodemod.short(parent),
+                                               nodemod.short(node)))
                 else:
                     parent = parents[0]
 
@@ -204,11 +219,11 @@
                             raise
                         if n and domerge:
                             self.ui.status(_('%s merged at %s\n') % (revstr,
-                                      short(n)))
+                                      nodemod.short(n)))
                         elif n:
                             self.ui.status(_('%s transplanted to %s\n')
-                                           % (short(node),
-                                              short(n)))
+                                           % (nodemod.short(node),
+                                              nodemod.short(n)))
                     finally:
                         if patchfile:
                             os.unlink(patchfile)
@@ -241,7 +256,7 @@
             self.ui.system('%s %s %s' % (filter, util.shellquote(headerfile),
                                          util.shellquote(patchfile)),
                            environ={'HGUSER': changelog[1],
-                                    'HGREVISION': revlog.hex(node),
+                                    'HGREVISION': nodemod.hex(node),
                                     },
                            onerr=error.Abort, errprefix=_('filter failed'))
             user, date, msg = self.parselog(file(headerfile))[1:4]
@@ -261,9 +276,9 @@
 
         if log:
             # we don't translate messages inserted into commits
-            message += '\n(transplanted from %s)' % revlog.hex(node)
+            message += '\n(transplanted from %s)' % nodemod.hex(node)
 
-        self.ui.status(_('applying %s\n') % short(node))
+        self.ui.status(_('applying %s\n') % nodemod.short(node))
         self.ui.note('%s %s\n%s\n' % (user, date, message))
 
         if not patchfile and not merge:
@@ -295,7 +310,8 @@
         n = repo.commit(message, user, date, extra=extra, match=m,
                         editor=self.getcommiteditor())
         if not n:
-            self.ui.warn(_('skipping emptied changeset %s\n') % short(node))
+            self.ui.warn(_('skipping emptied changeset %s\n') %
+                           nodemod.short(node))
             return None
         if not merge:
             self.transplants.set(n, node)
@@ -310,11 +326,12 @@
         if os.path.exists(os.path.join(self.path, 'journal')):
             n, node = self.recover(repo, source, opts)
             if n:
-                self.ui.status(_('%s transplanted as %s\n') % (short(node),
-                                                               short(n)))
+                self.ui.status(_('%s transplanted as %s\n') %
+                                 (nodemod.short(node),
+                                  nodemod.short(n)))
             else:
                 self.ui.status(_('%s skipped due to empty diff\n')
-                               % (short(node),))
+                               % (nodemod.short(node),))
         seriespath = os.path.join(self.path, 'series')
         if not os.path.exists(seriespath):
             self.transplants.write()
@@ -341,7 +358,8 @@
                 parent = source.lookup(opts['parent'])
                 if parent not in parents:
                     raise error.Abort(_('%s is not a parent of %s') %
-                                     (short(parent), short(node)))
+                                      (nodemod.short(parent),
+                                       nodemod.short(node)))
             else:
                 merge = True
 
@@ -350,7 +368,7 @@
             p1, p2 = repo.dirstate.parents()
             if p1 != parent:
                 raise error.Abort(_('working directory not at transplant '
-                                   'parent %s') % revlog.hex(parent))
+                                   'parent %s') % nodemod.hex(parent))
             if merge:
                 repo.setparents(p1, parents[1])
             modified, added, removed, deleted = repo.status()[:4]
@@ -391,11 +409,11 @@
             os.mkdir(self.path)
         series = self.opener('series', 'w')
         for rev in sorted(revmap):
-            series.write(revlog.hex(revmap[rev]) + '\n')
+            series.write(nodemod.hex(revmap[rev]) + '\n')
         if merges:
             series.write('# Merges\n')
             for m in merges:
-                series.write(revlog.hex(m) + '\n')
+                series.write(nodemod.hex(m) + '\n')
         series.close()
 
     def parselog(self, fp):
@@ -431,10 +449,10 @@
         fp = self.opener('journal', 'w')
         fp.write('# User %s\n' % user)
         fp.write('# Date %s\n' % date)
-        fp.write('# Node ID %s\n' % revlog.hex(p2))
-        fp.write('# Parent ' + revlog.hex(p1) + '\n')
+        fp.write('# Node ID %s\n' % nodemod.hex(p2))
+        fp.write('# Parent ' + nodemod.hex(p1) + '\n')
         if merge:
-            fp.write('# Parent ' + revlog.hex(p2) + '\n')
+            fp.write('# Parent ' + nodemod.hex(p2) + '\n')
         fp.write(message.rstrip() + '\n')
         fp.close()
 
@@ -711,7 +729,7 @@
     """:transplanted: String. The node identifier of the transplanted
     changeset if any."""
     n = ctx.extra().get('transplant_source')
-    return n and revlog.hex(n) or ''
+    return n and nodemod.hex(n) or ''
 
 def extsetup(ui):
     revsetpredicate.setup()
diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t
+++ b/tests/test-check-py3-compat.t
@@ -83,7 +83,6 @@
   hgext/share.py not using absolute_import
   hgext/shelve.py not using absolute_import
   hgext/strip.py not using absolute_import
-  hgext/transplant.py not using absolute_import
   hgext/win32mbcs.py not using absolute_import
   hgext/win32text.py not using absolute_import
   hgext/zeroconf/Zeroconf.py not using absolute_import


More information about the Mercurial-devel mailing list