[PATCH] transplant: use absolute_import

timeless timeless at mozdev.org
Wed Mar 2 09:58:41 EST 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1456808023 0
#      Tue Mar 01 04:53:43 2016 +0000
# Node ID 6b82849877fbd26414356d6fe08be08e03608eb0
# 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,
+    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(node.hex, (t.lnode, t.rnode))
                     fp.write(l + ':' + r + '\n')
             fp.close()
         self.dirty = False
@@ -132,21 +146,21 @@
             lock = repo.lock()
             tr = repo.transaction('transplant')
             for rev in revs:
-                node = revmap[rev]
-                revstr = '%s:%s' % (rev, short(node))
+                old = revmap[rev]
+                revstr = '%s:%s' % (rev, node.short(old))
 
-                if self.applied(repo, node, p1):
+                if self.applied(repo, old, p1):
                     self.ui.warn(_('skipping already applied revision %s\n') %
                                  revstr)
                     continue
 
-                parents = source.changelog.parents(node)
+                parents = source.changelog.parents(old)
                 if not (opts.get('filter') or opts.get('log')):
                     # If the changeset parent is the same as the
                     # wdir's parent, just pull it.
                     if parents[0] == p1:
-                        pulls.append(node)
-                        p1 = node
+                        pulls.append(old)
+                        p1 = old
                         continue
                     if pulls:
                         if source != repo:
@@ -156,25 +170,26 @@
                         pulls = []
 
                 domerge = False
-                if node in merges:
+                if old in merges:
                     # pulling all the merge revs at once would mean we
                     # couldn't transplant after the latest even if
                     # transplants before them fail.
                     domerge = True
-                    if not hasnode(repo, node):
-                        exchange.pull(repo, source.peer(), heads=[node])
+                    if not hasnode(repo, old):
+                        exchange.pull(repo, source.peer(), heads=[old])
 
                 skipmerge = False
                 if parents[1] != revlog.nullid:
                     if not opts.get('parent'):
                         self.ui.note(_('skipping merge changeset %s:%s\n')
-                                     % (rev, short(node)))
+                                     % (rev, node.short(old)))
                         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)))
+                                              (node.short(parent),
+                                               node.short(old)))
                 else:
                     parent = parents[0]
 
@@ -183,7 +198,7 @@
                 else:
                     fd, patchfile = tempfile.mkstemp(prefix='hg-transplant-')
                     fp = os.fdopen(fd, 'w')
-                    gen = patch.diff(source, parent, node, opts=diffopts)
+                    gen = patch.diff(source, parent, old, opts=diffopts)
                     for chunk in gen:
                         fp.write(chunk)
                     fp.close()
@@ -192,8 +207,8 @@
                 if patchfile or domerge:
                     try:
                         try:
-                            n = self.applyone(repo, node,
-                                              source.changelog.read(node),
+                            n = self.applyone(repo, old,
+                                              source.changelog.read(old),
                                               patchfile, merge=domerge,
                                               log=opts.get('log'),
                                               filter=opts.get('filter'))
@@ -204,11 +219,11 @@
                             raise
                         if n and domerge:
                             self.ui.status(_('%s merged at %s\n') % (revstr,
-                                      short(n)))
+                                      node.short(n)))
                         elif n:
                             self.ui.status(_('%s transplanted to %s\n')
-                                           % (short(node),
-                                              short(n)))
+                                           % (node.short(old),
+                                              node.short(n)))
                     finally:
                         if patchfile:
                             os.unlink(patchfile)
@@ -224,7 +239,7 @@
             if lock:
                 lock.release()
 
-    def filter(self, filter, node, changelog, patchfile):
+    def filter(self, filter, n, changelog, patchfile):
         '''arbitrarily rewrite changeset before applying it'''
 
         self.ui.status(_('filtering %s\n') % 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': node.hex(n),
                                     },
                            onerr=error.Abort, errprefix=_('filter failed'))
             user, date, msg = self.parselog(file(headerfile))[1:4]
@@ -250,20 +265,20 @@
 
         return (user, date, msg)
 
-    def applyone(self, repo, node, cl, patchfile, merge=False, log=False,
+    def applyone(self, repo, old, cl, patchfile, merge=False, log=False,
                  filter=None):
         '''apply the patch in patchfile to the repository as a transplant'''
         (manifest, user, (time, timezone), files, message) = cl[:5]
         date = "%d %d" % (time, timezone)
-        extra = {'transplant_source': node}
+        extra = {'transplant_source': old}
         if filter:
-            (user, date, message) = self.filter(filter, node, cl, patchfile)
+            (user, date, message) = self.filter(filter, old, cl, patchfile)
 
         if log:
             # we don't translate messages inserted into commits
-            message += '\n(transplanted from %s)' % revlog.hex(node)
+            message += '\n(transplanted from %s)' % node.hex(old)
 
-        self.ui.status(_('applying %s\n') % short(node))
+        self.ui.status(_('applying %s\n') % node.short(old))
         self.ui.note('%s %s\n%s\n' % (user, date, message))
 
         if not patchfile and not merge:
@@ -278,7 +293,7 @@
                 if os.path.exists(seriespath):
                     os.unlink(seriespath)
                 p1 = repo.dirstate.p1()
-                p2 = node
+                p2 = old
                 self.log(user, date, message, p1, p2, merge=merge)
                 self.ui.write(str(inst) + '\n')
                 raise TransplantError(_('fix up the working directory and run '
@@ -287,7 +302,7 @@
             files = None
         if merge:
             p1, p2 = repo.dirstate.parents()
-            repo.setparents(p1, node)
+            repo.setparents(p1, old)
             m = match.always(repo.root, '')
         else:
             m = match.exact(repo.root, '', files)
@@ -295,10 +310,10 @@
         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') % node.short(old))
             return None
         if not merge:
-            self.transplants.set(n, node)
+            self.transplants.set(n, old)
 
         return n
 
@@ -308,13 +323,13 @@
     def resume(self, repo, source, opts):
         '''recover last transaction and apply remaining changesets'''
         if os.path.exists(os.path.join(self.path, 'journal')):
-            n, node = self.recover(repo, source, opts)
+            n, old = 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') % (node.short(old),
+                                                               node.short(n)))
             else:
                 self.ui.status(_('%s skipped due to empty diff\n')
-                               % (short(node),))
+                               % (node.short(old),))
         seriespath = os.path.join(self.path, 'series')
         if not os.path.exists(seriespath):
             self.transplants.write()
@@ -329,7 +344,7 @@
 
     def recover(self, repo, source, opts):
         '''commit working directory using journal metadata'''
-        node, user, date, message, parents = self.readlog()
+        old, user, date, message, parents = self.readlog()
         merge = False
 
         if not user or not date or not message or not parents[0]:
@@ -341,31 +356,31 @@
                 parent = source.lookup(opts['parent'])
                 if parent not in parents:
                     raise error.Abort(_('%s is not a parent of %s') %
-                                     (short(parent), short(node)))
+                                     (node.short(parent), node.short(old)))
             else:
                 merge = True
 
-        extra = {'transplant_source': node}
+        extra = {'transplant_source': old}
         try:
             p1, p2 = repo.dirstate.parents()
             if p1 != parent:
                 raise error.Abort(_('working directory not at transplant '
-                                   'parent %s') % revlog.hex(parent))
+                                   'parent %s') % node.hex(parent))
             if merge:
                 repo.setparents(p1, parents[1])
             modified, added, removed, deleted = repo.status()[:4]
             if merge or modified or added or removed or deleted:
-                n = repo.commit(message, user, date, extra=extra,
-                                editor=self.getcommiteditor())
-                if not n:
+                tnode = repo.commit(message, user, date, extra=extra,
+                                  editor=self.getcommiteditor())
+                if not tnode:
                     raise error.Abort(_('commit failed'))
                 if not merge:
-                    self.transplants.set(n, node)
+                    self.transplants.set(tnode, old)
             else:
-                n = None
+                tnode = None
             self.unlog()
 
-            return n, node
+            return tnode, old
         finally:
             # TODO: get rid of this meaningless try/finally enclosing.
             # this is kept only to reduce changes in a patch.
@@ -391,11 +406,11 @@
             os.mkdir(self.path)
         series = self.opener('series', 'w')
         for rev in sorted(revmap):
-            series.write(revlog.hex(revmap[rev]) + '\n')
+            series.write(node.hex(revmap[rev]) + '\n')
         if merges:
             series.write('# Merges\n')
             for m in merges:
-                series.write(revlog.hex(m) + '\n')
+                series.write(node.hex(m) + '\n')
         series.close()
 
     def parselog(self, fp):
@@ -431,10 +446,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' % node.hex(p2))
+        fp.write('# Parent ' + node.hex(p1) + '\n')
         if merge:
-            fp.write('# Parent ' + revlog.hex(p2) + '\n')
+            fp.write('# Parent ' + node.hex(p2) + '\n')
         fp.write(message.rstrip() + '\n')
         fp.close()
 
@@ -711,7 +726,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 node.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