Patchwork [1,of,2] annotate: rename formatter variable

login
register
mail settings
Submitter Yuya Nishihara
Date June 2, 2017, 4:02 p.m.
Message ID <52237356336d4141f9f1.1496419346@mimosa>
Download mbox | patch
Permalink /patch/21137/
State Accepted
Headers show

Comments

Yuya Nishihara - June 2, 2017, 4:02 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1496415912 -32400
#      Sat Jun 03 00:05:12 2017 +0900
# Node ID 52237356336d4141f9f1a31995276703cbb436b7
# Parent  8dda0a0e543c4ecd615cbd7981ffcaee313a8d30
annotate: rename formatter variable

So we can add a nested 'fm' of narrow scope.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -299,7 +299,7 @@  def annotate(ui, repo, *pats, **opts):
 
     ctx = scmutil.revsingle(repo, opts.get('rev'))
 
-    fm = ui.formatter('annotate', opts)
+    rootfm = ui.formatter('annotate', opts)
     if ui.quiet:
         datefunc = util.shortdate
     else:
@@ -309,7 +309,7 @@  def annotate(ui, repo, *pats, **opts):
             if node is None:
                 return None
             else:
-                return fm.hexfunc(node)
+                return rootfm.hexfunc(node)
         if opts.get('changeset'):
             # omit "+" suffix which is appended to node hex
             def formatrev(rev):
@@ -325,11 +325,11 @@  def annotate(ui, repo, *pats, **opts):
                     return '%d ' % rev
         def formathex(hex):
             if hex is None:
-                return '%s+' % fm.hexfunc(ctx.p1().node())
+                return '%s+' % rootfm.hexfunc(ctx.p1().node())
             else:
                 return '%s ' % hex
     else:
-        hexfn = fm.hexfunc
+        hexfn = rootfm.hexfunc
         formatrev = formathex = str
 
     opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser),
@@ -351,7 +351,7 @@  def annotate(ui, repo, *pats, **opts):
 
     ui.pager('annotate')
 
-    if fm.isplain():
+    if rootfm.isplain():
         def makefunc(get, fmt):
             return lambda x: fmt(get(x))
     else:
@@ -378,9 +378,11 @@  def annotate(ui, repo, *pats, **opts):
     for abs in ctx.walk(m):
         fctx = ctx[abs]
         if not opts.get('text') and fctx.isbinary():
-            fm.plain(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
+            rootfm.plain(_("%s: binary file\n")
+                         % ((pats and m.rel(abs)) or abs))
             continue
 
+        fm = rootfm
         lines = fctx.annotate(follow=follow, linenumber=linenumber,
                               skiprevs=skiprevs, diffopts=diffopts)
         if not lines:
@@ -406,7 +408,7 @@  def annotate(ui, repo, *pats, **opts):
         if not lines[-1][1].endswith('\n'):
             fm.plain('\n')
 
-    fm.end()
+    rootfm.end()
 
 @command('archive',
     [('', 'no-decode', None, _('do not pass files through decoders')),