patch: extract local function addmodehdr
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Wed, 22 Oct 2008 09:29:26 +0200
changeset 7198 df79ee9b6278
parent 7197 f60730693efc
child 7199 dd891d0d97a3
patch: extract local function addmodehdr
mercurial/patch.py
--- a/mercurial/patch.py	Tue Oct 21 11:29:27 2008 +0200
+++ b/mercurial/patch.py	Wed Oct 22 09:29:26 2008 +0200
@@ -1166,6 +1166,11 @@
     ret.append('\n')
     return ''.join(ret)
 
+def _addmodehdr(header, omode, nmode):
+    if omode != nmode:
+        header.append('old mode %s\n' % omode)
+        header.append('new mode %s\n' % nmode)
+
 def diff(repo, node1=None, node2=None, match=None,
          fp=None, changes=None, opts=None):
     '''print diff of changes to files between two nodes, or node and
@@ -1230,17 +1235,12 @@
             tn = getfilectx(f, ctx2).data()
         a, b = f, f
         if opts.git:
-            def addmodehdr(header, omode, nmode):
-                if omode != nmode:
-                    header.append('old mode %s\n' % omode)
-                    header.append('new mode %s\n' % nmode)
-
             if f in added:
                 mode = gitmode[ctx2.flags(f)]
                 if f in copy:
                     a = copy[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[a] = 1
@@ -1263,7 +1263,7 @@
             else:
                 omode = gitmode[man1.flags(f)]
                 nmode = gitmode[ctx2.flags(f)]
-                addmodehdr(header, omode, nmode)
+                _addmodehdr(header, omode, nmode)
                 if util.binary(to) or util.binary(tn):
                     dodiff = 'binary'
             r = None