Patchwork transplant: use hex directly

login
register
mail settings
Submitter timeless@mozdev.org
Date March 1, 2016, 5:30 a.m.
Message ID <7e6c4a1aefec8ef0047c.1456810239@waste.org>
Download mbox | patch
Permalink /patch/13485/
State Changes Requested
Headers show

Comments

timeless@mozdev.org - March 1, 2016, 5:30 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1456808023 0
#      Tue Mar 01 04:53:43 2016 +0000
# Node ID 7e6c4a1aefec8ef0047c58a76e8775b8a14768ff
# Parent  c7f89ad87baef87f00c507545dfd4cc824bc3131
transplant: use hex directly
Augie Fackler - March 1, 2016, 6:41 p.m.
On Mon, Feb 29, 2016 at 11:30:39PM -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1456808023 0
> #      Tue Mar 01 04:53:43 2016 +0000
> # Node ID 7e6c4a1aefec8ef0047c58a76e8775b8a14768ff
> # Parent  c7f89ad87baef87f00c507545dfd4cc824bc3131
> transplant: use hex directly

from mercurial.node import hex forces demandimport to resolve the
module early. Instead reference it as node.hex in this file, and
import the module.

(I know 'from mercurial.node import hex' is common throughout hg, but
I still don't like it.)
Gregory Szorc - March 2, 2016, 8:39 p.m.
> On Mar 1, 2016, at 10:41, Augie Fackler <raf@durin42.com> wrote:
> 
>> On Mon, Feb 29, 2016 at 11:30:39PM -0600, timeless wrote:
>> # HG changeset patch
>> # User timeless <timeless@mozdev.org>
>> # Date 1456808023 0
>> #      Tue Mar 01 04:53:43 2016 +0000
>> # Node ID 7e6c4a1aefec8ef0047c58a76e8775b8a14768ff
>> # Parent  c7f89ad87baef87f00c507545dfd4cc824bc3131
>> transplant: use hex directly
> 
> from mercurial.node import hex forces demandimport to resolve the
> module early. Instead reference it as node.hex in this file, and
> import the module.
> 
> (I know 'from mercurial.node import hex' is common throughout hg, but
> I still don't like it.

I'm pretty sure mercurial.node (and tons of other modules) will be imported by the time a command runs. So I don't think there's anything worth worrying about here.

Patch

diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -20,6 +20,9 @@ 
 from mercurial import bundlerepo, hg, merge, match
 from mercurial import patch, revlog, scmutil, util, error, cmdutil
 from mercurial import revset, templatekw, exchange
+from mercurial.node import (
+    hex,
+)
 
 class TransplantError(error.Abort):
     pass
@@ -64,7 +67,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(hex, (t.lnode, t.rnode))
                     fp.write(l + ':' + r + '\n')
             fp.close()
         self.dirty = False
@@ -241,7 +244,7 @@ 
             self.ui.system('%s %s %s' % (filter, util.shellquote(headerfile),
                                          util.shellquote(patchfile)),
                            environ={'HGUSER': changelog[1],
-                                    'HGREVISION': revlog.hex(node),
+                                    'HGREVISION': hex(node),
                                     },
                            onerr=error.Abort, errprefix=_('filter failed'))
             user, date, msg = self.parselog(file(headerfile))[1:4]
@@ -261,7 +264,7 @@ 
 
         if log:
             # we don't translate messages inserted into commits
-            message += '\n(transplanted from %s)' % revlog.hex(node)
+            message += '\n(transplanted from %s)' % hex(node)
 
         self.ui.status(_('applying %s\n') % short(node))
         self.ui.note('%s %s\n%s\n' % (user, date, message))
@@ -350,7 +353,7 @@ 
             p1, p2 = repo.dirstate.parents()
             if p1 != parent:
                 raise error.Abort(_('working directory not at transplant '
-                                   'parent %s') % revlog.hex(parent))
+                                   'parent %s') % hex(parent))
             if merge:
                 repo.setparents(p1, parents[1])
             modified, added, removed, deleted = repo.status()[:4]
@@ -391,11 +394,11 @@ 
             os.mkdir(self.path)
         series = self.opener('series', 'w')
         for rev in sorted(revmap):
-            series.write(revlog.hex(revmap[rev]) + '\n')
+            series.write(hex(revmap[rev]) + '\n')
         if merges:
             series.write('# Merges\n')
             for m in merges:
-                series.write(revlog.hex(m) + '\n')
+                series.write(hex(m) + '\n')
         series.close()
 
     def parselog(self, fp):
@@ -431,10 +434,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' % hex(p2))
+        fp.write('# Parent ' + hex(p1) + '\n')
         if merge:
-            fp.write('# Parent ' + revlog.hex(p2) + '\n')
+            fp.write('# Parent ' + hex(p2) + '\n')
         fp.write(message.rstrip() + '\n')
         fp.close()
 
@@ -711,7 +714,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 hex(n) or ''
 
 def extsetup(ui):
     revsetpredicate.setup()