comparison mercurial/patch.py @ 23997:8b88870cbd1e

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
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 16 Jan 2015 10:57:13 -0800
parents 0188c2d90356
children b65637247c69
comparison
equal deleted inserted replaced
23996:0188c2d90356 23997:8b88870cbd1e
1740 copy, getfilectx, opts, losedatafn, prefix): 1740 copy, getfilectx, opts, losedatafn, prefix):
1741 1741
1742 def join(f): 1742 def join(f):
1743 return posixpath.join(prefix, f) 1743 return posixpath.join(prefix, f)
1744 1744
1745 def addmodehdr(header, omode, nmode): 1745 def addmodehdr(header, mode1, mode2):
1746 if omode != nmode: 1746 if mode1 != mode2:
1747 header.append('old mode %s\n' % omode) 1747 header.append('old mode %s\n' % mode1)
1748 header.append('new mode %s\n' % nmode) 1748 header.append('new mode %s\n' % mode2)
1749 1749
1750 def addindexmeta(meta, oindex, nindex): 1750 def addindexmeta(meta, index1, index2):
1751 meta.append('index %s..%s\n' % (oindex, nindex)) 1751 meta.append('index %s..%s\n' % (index1, index2))
1752 1752
1753 def gitindex(text): 1753 def gitindex(text):
1754 if not text: 1754 if not text:
1755 text = "" 1755 text = ""
1756 l = len(text) 1756 l = len(text)
1793 # modifications during merges 1793 # modifications during merges
1794 for f in modified: 1794 for f in modified:
1795 if f not in ctx1: 1795 if f not in ctx1:
1796 addedset.add(f) 1796 addedset.add(f)
1797 for f in sorted(modified + added + removed): 1797 for f in sorted(modified + added + removed):
1798 to = None 1798 content1 = None
1799 tn = None 1799 content2 = None
1800 binarydiff = False 1800 binarydiff = False
1801 header = [] 1801 header = []
1802 if f not in addedset: 1802 if f not in addedset:
1803 to = getfilectx(f, ctx1).data() 1803 content1 = getfilectx(f, ctx1).data()
1804 if f not in removedset: 1804 if f not in removedset:
1805 tn = getfilectx(f, ctx2).data() 1805 content2 = getfilectx(f, ctx2).data()
1806 a, b = f, f 1806 f1, f2 = f, f
1807 if opts.git or losedatafn: 1807 if opts.git or losedatafn:
1808 if f in addedset: 1808 if f in addedset:
1809 mode = gitmode[ctx2.flags(f)] 1809 mode2 = gitmode[ctx2.flags(f)]
1810 if f in copy: 1810 if f in copy:
1811 if opts.git: 1811 if opts.git:
1812 a = copy[f] 1812 f1 = copy[f]
1813 omode = gitmode[ctx1.flags(a)] 1813 mode1 = gitmode[ctx1.flags(f1)]
1814 addmodehdr(header, omode, mode) 1814 addmodehdr(header, mode1, mode2)
1815 if a in removedset and a not in gone: 1815 if f1 in removedset and f1 not in gone:
1816 op = 'rename' 1816 op = 'rename'
1817 gone.add(a) 1817 gone.add(f1)
1818 else: 1818 else:
1819 op = 'copy' 1819 op = 'copy'
1820 header.append('%s from %s\n' % (op, join(a))) 1820 header.append('%s from %s\n' % (op, join(f1)))
1821 header.append('%s to %s\n' % (op, join(f))) 1821 header.append('%s to %s\n' % (op, join(f)))
1822 to = getfilectx(a, ctx1).data() 1822 content1 = getfilectx(f1, ctx1).data()
1823 else: 1823 else:
1824 losedatafn(f) 1824 losedatafn(f)
1825 else: 1825 else:
1826 if opts.git: 1826 if opts.git:
1827 header.append('new file mode %s\n' % mode) 1827 header.append('new file mode %s\n' % mode2)
1828 elif ctx2.flags(f): 1828 elif ctx2.flags(f):
1829 losedatafn(f) 1829 losedatafn(f)
1830 if util.binary(to) or util.binary(tn): 1830 if util.binary(content1) or util.binary(content2):
1831 if opts.git: 1831 if opts.git:
1832 binarydiff = True 1832 binarydiff = True
1833 else: 1833 else:
1834 losedatafn(f) 1834 losedatafn(f)
1835 if not opts.git and not tn: 1835 if not opts.git and not content2:
1836 # regular diffs cannot represent new empty file 1836 # regular diffs cannot represent new empty file
1837 losedatafn(f) 1837 losedatafn(f)
1838 elif f in removedset: 1838 elif f in removedset:
1839 if opts.git: 1839 if opts.git:
1840 # have we already reported a copy above? 1840 # have we already reported a copy above?
1842 and copy[copyto[f]] == f): 1842 and copy[copyto[f]] == f):
1843 continue 1843 continue
1844 else: 1844 else:
1845 header.append('deleted file mode %s\n' % 1845 header.append('deleted file mode %s\n' %
1846 gitmode[ctx1.flags(f)]) 1846 gitmode[ctx1.flags(f)])
1847 if util.binary(to): 1847 if util.binary(content1):
1848 binarydiff = True 1848 binarydiff = True
1849 elif not to or util.binary(to): 1849 elif not content1 or util.binary(content1):
1850 # regular diffs cannot represent empty file deletion 1850 # regular diffs cannot represent empty file deletion
1851 losedatafn(f) 1851 losedatafn(f)
1852 else: 1852 else:
1853 oflag = ctx1.flags(f) 1853 flag1 = ctx1.flags(f)
1854 nflag = ctx2.flags(f) 1854 flag2 = ctx2.flags(f)
1855 binary = util.binary(to) or util.binary(tn) 1855 binary = util.binary(content1) or util.binary(content2)
1856 if opts.git: 1856 if opts.git:
1857 addmodehdr(header, gitmode[oflag], gitmode[nflag]) 1857 addmodehdr(header, gitmode[flag1], gitmode[flag2])
1858 if binary: 1858 if binary:
1859 binarydiff = True 1859 binarydiff = True
1860 elif binary or nflag != oflag: 1860 elif binary or flag2 != flag1:
1861 losedatafn(f) 1861 losedatafn(f)
1862 1862
1863 if opts.git or revs: 1863 if opts.git or revs:
1864 header.insert(0, diffline(join(a), join(b), revs)) 1864 header.insert(0, diffline(join(f1), join(f2), revs))
1865 if binarydiff and not opts.nobinary: 1865 if binarydiff and not opts.nobinary:
1866 text = mdiff.b85diff(to, tn) 1866 text = mdiff.b85diff(content1, content2)
1867 if text and opts.git: 1867 if text and opts.git:
1868 addindexmeta(header, gitindex(to), gitindex(tn)) 1868 addindexmeta(header, gitindex(content1), gitindex(content2))
1869 else: 1869 else:
1870 text = mdiff.unidiff(to, date1, 1870 text = mdiff.unidiff(content1, date1,
1871 tn, date2, 1871 content2, date2,
1872 join(a), join(b), opts=opts) 1872 join(f1), join(f2), opts=opts)
1873 if header and (text or len(header) > 1): 1873 if header and (text or len(header) > 1):
1874 yield ''.join(header) 1874 yield ''.join(header)
1875 if text: 1875 if text:
1876 yield text 1876 yield text
1877 1877