patch: make _addmodehdr a function under trydiff
authorGuillermo Pérez <bisho@fb.com>
Thu, 15 Nov 2012 15:06:32 -0800
changeset 17945 45766e2a7384
parent 17944 7ac2a7720724
child 17946 1e13b1184292
patch: make _addmodehdr a function under trydiff addmodehdr is a header helper, same as diffline, so it doesn't need to be a top-level function and can be nested under trydiff. In upcoming patches we will generalize this approach for all headers.
mercurial/patch.py
--- a/mercurial/patch.py	Thu Nov 15 13:57:03 2012 -0800
+++ b/mercurial/patch.py	Thu Nov 15 15:06:32 2012 -0800
@@ -1651,18 +1651,17 @@
     '''like diff(), but yields 2-tuples of (output, label) for ui.write()'''
     return difflabel(diff, *args, **kw)
 
-
-def _addmodehdr(header, omode, nmode):
-    if omode != nmode:
-        header.append('old mode %s\n' % omode)
-        header.append('new mode %s\n' % nmode)
-
 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
             copy, getfilectx, opts, losedatafn, prefix):
 
     def join(f):
         return os.path.join(prefix, f)
 
+    def addmodehdr(header, omode, nmode):
+        if omode != nmode:
+            header.append('old mode %s\n' % omode)
+            header.append('new mode %s\n' % nmode)
+
     def diffline(a, b, revs):
         if opts.git:
             line = 'diff --git a/%s b/%s\n' % (a, b)
@@ -1707,7 +1706,7 @@
                         else:
                             a = copyto[f]
                         omode = gitmode[man1.flags(a)]
-                        _addmodehdr(header, omode, mode)
+                        addmodehdr(header, omode, mode)
                         if a in removed and a not in gone:
                             op = 'rename'
                             gone.add(a)
@@ -1753,7 +1752,7 @@
                 nflag = ctx2.flags(f)
                 binary = util.binary(to) or util.binary(tn)
                 if opts.git:
-                    _addmodehdr(header, gitmode[oflag], gitmode[nflag])
+                    addmodehdr(header, gitmode[oflag], gitmode[nflag])
                     if binary:
                         dodiff = 'binary'
                 elif binary or nflag != oflag: