Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 24025:bbb011f4eb32
trydiff: join elements in 'header' list by '\n'
It seems natural that each element in the list corresponds to one line
of output. That is currently true, but only because each element in
the list has a trailing newline. Let's drop those newlines and instead
add them when we print the headers.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 16 Jan 2015 15:34:03 -0800 |
parents | a5c7e86a81c1 |
children | 7f4e6b5fce03 |
comparison
equal
deleted
inserted
replaced
24024:a5c7e86a81c1 | 24025:bbb011f4eb32 |
---|---|
1753 aprefix = 'a/' | 1753 aprefix = 'a/' |
1754 bprefix = 'b/' | 1754 bprefix = 'b/' |
1755 | 1755 |
1756 def diffline(f, revs): | 1756 def diffline(f, revs): |
1757 revinfo = ' '.join(["-r %s" % rev for rev in revs]) | 1757 revinfo = ' '.join(["-r %s" % rev for rev in revs]) |
1758 return 'diff %s %s\n' % (revinfo, f) | 1758 return 'diff %s %s' % (revinfo, f) |
1759 | 1759 |
1760 date1 = util.datestr(ctx1.date()) | 1760 date1 = util.datestr(ctx1.date()) |
1761 date2 = util.datestr(ctx2.date()) | 1761 date2 = util.datestr(ctx2.date()) |
1762 | 1762 |
1763 gone = set() | 1763 gone = set() |
1834 | 1834 |
1835 path1 = posixpath.join(prefix, f1) | 1835 path1 = posixpath.join(prefix, f1) |
1836 path2 = posixpath.join(prefix, f2) | 1836 path2 = posixpath.join(prefix, f2) |
1837 header = [] | 1837 header = [] |
1838 if opts.git: | 1838 if opts.git: |
1839 header.append('diff --git %s%s %s%s\n' % | 1839 header.append('diff --git %s%s %s%s' % |
1840 (aprefix, path1, bprefix, path2)) | 1840 (aprefix, path1, bprefix, path2)) |
1841 if content1 is None: # added | 1841 if content1 is None: # added |
1842 header.append('new file mode %s\n' % gitmode[flag2]) | 1842 header.append('new file mode %s' % gitmode[flag2]) |
1843 elif content2 is None: # removed | 1843 elif content2 is None: # removed |
1844 header.append('deleted file mode %s\n' % gitmode[flag1]) | 1844 header.append('deleted file mode %s' % gitmode[flag1]) |
1845 else: # modified/copied/renamed | 1845 else: # modified/copied/renamed |
1846 mode1, mode2 = gitmode[flag1], gitmode[flag2] | 1846 mode1, mode2 = gitmode[flag1], gitmode[flag2] |
1847 if mode1 != mode2: | 1847 if mode1 != mode2: |
1848 header.append('old mode %s\n' % mode1) | 1848 header.append('old mode %s' % mode1) |
1849 header.append('new mode %s\n' % mode2) | 1849 header.append('new mode %s' % mode2) |
1850 if op is not None: | 1850 if op is not None: |
1851 header.append('%s from %s\n' % (op, path1)) | 1851 header.append('%s from %s' % (op, path1)) |
1852 header.append('%s to %s\n' % (op, path2)) | 1852 header.append('%s to %s' % (op, path2)) |
1853 elif revs and not repo.ui.quiet: | 1853 elif revs and not repo.ui.quiet: |
1854 header.append(diffline(path1, revs)) | 1854 header.append(diffline(path1, revs)) |
1855 | 1855 |
1856 if binarydiff and not opts.nobinary: | 1856 if binarydiff and not opts.nobinary: |
1857 text = mdiff.b85diff(content1, content2) | 1857 text = mdiff.b85diff(content1, content2) |
1858 if text and opts.git: | 1858 if text and opts.git: |
1859 header.append('index %s..%s\n' % | 1859 header.append('index %s..%s' % |
1860 (gitindex(content1), gitindex(content2))) | 1860 (gitindex(content1), gitindex(content2))) |
1861 else: | 1861 else: |
1862 text = mdiff.unidiff(content1, date1, | 1862 text = mdiff.unidiff(content1, date1, |
1863 content2, date2, | 1863 content2, date2, |
1864 path1, path2, opts=opts) | 1864 path1, path2, opts=opts) |
1865 if header and (text or len(header) > 1): | 1865 if header and (text or len(header) > 1): |
1866 yield ''.join(header) | 1866 yield '\n'.join(header) + '\n' |
1867 if text: | 1867 if text: |
1868 yield text | 1868 yield text |
1869 | 1869 |
1870 def diffstatsum(stats): | 1870 def diffstatsum(stats): |
1871 maxfile, maxtotal, addtotal, removetotal, binary = 0, 0, 0, 0, False | 1871 maxfile, maxtotal, addtotal, removetotal, binary = 0, 0, 0, 0, False |