comparison mercurial/patch.py @ 23999:e02888efc5aa

trydiff: join filename with prefix only once
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 16 Jan 2015 14:46:03 -0800
parents b65637247c69
children 82e3324c4df9
comparison
equal deleted inserted replaced
23998:b65637247c69 23999:e02888efc5aa
1737 return difflabel(diff, *args, **kw) 1737 return difflabel(diff, *args, **kw)
1738 1738
1739 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed, 1739 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
1740 copy, getfilectx, opts, losedatafn, prefix): 1740 copy, getfilectx, opts, losedatafn, prefix):
1741 1741
1742 def join(f):
1743 return posixpath.join(prefix, f)
1744
1745 def addmodehdr(header, mode1, mode2): 1742 def addmodehdr(header, mode1, mode2):
1746 if mode1 != mode2: 1743 if mode1 != mode2:
1747 header.append('old mode %s\n' % mode1) 1744 header.append('old mode %s\n' % mode1)
1748 header.append('new mode %s\n' % mode2) 1745 header.append('new mode %s\n' % mode2)
1749 1746
1853 if binary: 1850 if binary:
1854 binarydiff = True 1851 binarydiff = True
1855 elif binary or flag2 != flag1: 1852 elif binary or flag2 != flag1:
1856 losedatafn(f) 1853 losedatafn(f)
1857 1854
1855 path1 = posixpath.join(prefix, f1)
1856 path2 = posixpath.join(prefix, f2)
1858 header = [] 1857 header = []
1859 if opts.git: 1858 if opts.git:
1860 if content1 is None: # added 1859 if content1 is None: # added
1861 header.append('new file mode %s\n' % gitmode[flag2]) 1860 header.append('new file mode %s\n' % gitmode[flag2])
1862 elif content2 is None: # removed 1861 elif content2 is None: # removed
1863 header.append('deleted file mode %s\n' % gitmode[flag1]) 1862 header.append('deleted file mode %s\n' % gitmode[flag1])
1864 else: # modified/copied/renamed 1863 else: # modified/copied/renamed
1865 addmodehdr(header, gitmode[flag1], gitmode[flag2]) 1864 addmodehdr(header, gitmode[flag1], gitmode[flag2])
1866 if op is not None: 1865 if op is not None:
1867 header.append('%s from %s\n' % (op, join(f1))) 1866 header.append('%s from %s\n' % (op, path1))
1868 header.append('%s to %s\n' % (op, join(f2))) 1867 header.append('%s to %s\n' % (op, path2))
1869 1868
1870 if opts.git or revs: 1869 if opts.git or revs:
1871 header.insert(0, diffline(join(f1), join(f2), revs)) 1870 header.insert(0, diffline(path1, path2, revs))
1872 if binarydiff and not opts.nobinary: 1871 if binarydiff and not opts.nobinary:
1873 text = mdiff.b85diff(content1, content2) 1872 text = mdiff.b85diff(content1, content2)
1874 if text and opts.git: 1873 if text and opts.git:
1875 addindexmeta(header, gitindex(content1), gitindex(content2)) 1874 addindexmeta(header, gitindex(content1), gitindex(content2))
1876 else: 1875 else:
1877 text = mdiff.unidiff(content1, date1, 1876 text = mdiff.unidiff(content1, date1,
1878 content2, date2, 1877 content2, date2,
1879 join(f1), join(f2), opts=opts) 1878 path1, path2, opts=opts)
1880 if header and (text or len(header) > 1): 1879 if header and (text or len(header) > 1):
1881 yield ''.join(header) 1880 yield ''.join(header)
1882 if text: 1881 if text:
1883 yield text 1882 yield text
1884 1883