Patchwork [3,of,3] trydiff: make variable names more consistent

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 2, 2015, 6:10 a.m.
Message ID <25c0cadcff9a7108ce32.1422857420@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7589/
State Accepted
Commit 8b88870cbd1eeefaee0af053ae36728f8c0a1847
Headers show

Comments

Martin von Zweigbergk - Feb. 2, 2015, 6:10 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1421434633 28800
#      Fri Jan 16 10:57:13 2015 -0800
# Branch stable
# Node ID 25c0cadcff9a7108ce328bb96993b73661f04f2e
# Parent  42117e61f40155ee5067b50a24c6e2e7f1b90754
trydiff: make variable names more consistent

Use '1' and '2' as suffix for names just like in the parameters
'ctx[12]':

to,tn -> content1,content2
a,b -> f1, f2
omode,mode -> mode1,mode2
omode,nmode -> mode1,mode2
onode,nnode -> node1,node2
oflag,nflag -> flag1,flag2
oindex,nindex -> index1,index2
Matt Mackall - Feb. 2, 2015, 10:41 p.m.
On Sun, 2015-02-01 at 22:10 -0800, Martin von Zweigbergk wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1421434633 28800
> #      Fri Jan 16 10:57:13 2015 -0800
> # Branch stable
> # Node ID 25c0cadcff9a7108ce328bb96993b73661f04f2e
> # Parent  42117e61f40155ee5067b50a24c6e2e7f1b90754
> trydiff: make variable names more consistent

Queued for default, thanks.

Patch

diff -r 42117e61f401 -r 25c0cadcff9a mercurial/patch.py
--- a/mercurial/patch.py	Fri Jan 16 17:01:58 2015 -0800
+++ b/mercurial/patch.py	Fri Jan 16 10:57:13 2015 -0800
@@ -1742,13 +1742,13 @@ 
     def join(f):
         return posixpath.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 addmodehdr(header, mode1, mode2):
+        if mode1 != mode2:
+            header.append('old mode %s\n' % mode1)
+            header.append('new mode %s\n' % mode2)
 
-    def addindexmeta(meta, oindex, nindex):
-        meta.append('index %s..%s\n' % (oindex, nindex))
+    def addindexmeta(meta, index1, index2):
+        meta.append('index %s..%s\n' % (index1, index2))
 
     def gitindex(text):
         if not text:
@@ -1795,44 +1795,44 @@ 
         if f not in ctx1:
             addedset.add(f)
     for f in sorted(modified + added + removed):
-        to = None
-        tn = None
+        content1 = None
+        content2 = None
         binarydiff = False
         header = []
         if f not in addedset:
-            to = getfilectx(f, ctx1).data()
+            content1 = getfilectx(f, ctx1).data()
         if f not in removedset:
-            tn = getfilectx(f, ctx2).data()
-        a, b = f, f
+            content2 = getfilectx(f, ctx2).data()
+        f1, f2 = f, f
         if opts.git or losedatafn:
             if f in addedset:
-                mode = gitmode[ctx2.flags(f)]
+                mode2 = gitmode[ctx2.flags(f)]
                 if f in copy:
                     if opts.git:
-                        a = copy[f]
-                        omode = gitmode[ctx1.flags(a)]
-                        addmodehdr(header, omode, mode)
-                        if a in removedset and a not in gone:
+                        f1 = copy[f]
+                        mode1 = gitmode[ctx1.flags(f1)]
+                        addmodehdr(header, mode1, mode2)
+                        if f1 in removedset and f1 not in gone:
                             op = 'rename'
-                            gone.add(a)
+                            gone.add(f1)
                         else:
                             op = 'copy'
-                        header.append('%s from %s\n' % (op, join(a)))
+                        header.append('%s from %s\n' % (op, join(f1)))
                         header.append('%s to %s\n' % (op, join(f)))
-                        to = getfilectx(a, ctx1).data()
+                        content1 = getfilectx(f1, ctx1).data()
                     else:
                         losedatafn(f)
                 else:
                     if opts.git:
-                        header.append('new file mode %s\n' % mode)
+                        header.append('new file mode %s\n' % mode2)
                     elif ctx2.flags(f):
                         losedatafn(f)
-                if util.binary(to) or util.binary(tn):
+                if util.binary(content1) or util.binary(content2):
                     if opts.git:
                         binarydiff = True
                     else:
                         losedatafn(f)
-                if not opts.git and not tn:
+                if not opts.git and not content2:
                     # regular diffs cannot represent new empty file
                     losedatafn(f)
             elif f in removedset:
@@ -1844,32 +1844,32 @@ 
                     else:
                         header.append('deleted file mode %s\n' %
                                       gitmode[ctx1.flags(f)])
-                        if util.binary(to):
+                        if util.binary(content1):
                             binarydiff = True
-                elif not to or util.binary(to):
+                elif not content1 or util.binary(content1):
                     # regular diffs cannot represent empty file deletion
                     losedatafn(f)
             else:
-                oflag = ctx1.flags(f)
-                nflag = ctx2.flags(f)
-                binary = util.binary(to) or util.binary(tn)
+                flag1 = ctx1.flags(f)
+                flag2 = ctx2.flags(f)
+                binary = util.binary(content1) or util.binary(content2)
                 if opts.git:
-                    addmodehdr(header, gitmode[oflag], gitmode[nflag])
+                    addmodehdr(header, gitmode[flag1], gitmode[flag2])
                     if binary:
                         binarydiff = True
-                elif binary or nflag != oflag:
+                elif binary or flag2 != flag1:
                     losedatafn(f)
 
         if opts.git or revs:
-            header.insert(0, diffline(join(a), join(b), revs))
+            header.insert(0, diffline(join(f1), join(f2), revs))
         if binarydiff and not opts.nobinary:
-            text = mdiff.b85diff(to, tn)
+            text = mdiff.b85diff(content1, content2)
             if text and opts.git:
-                addindexmeta(header, gitindex(to), gitindex(tn))
+                addindexmeta(header, gitindex(content1), gitindex(content2))
         else:
-            text = mdiff.unidiff(to, date1,
-                                 tn, date2,
-                                 join(a), join(b), opts=opts)
+            text = mdiff.unidiff(content1, date1,
+                                 content2, date2,
+                                 join(f1), join(f2), opts=opts)
         if header and (text or len(header) > 1):
             yield ''.join(header)
         if text: