comparison mercurial/patch.py @ 24020:cc81e6da0757

trydiff: move git-header code out of diffline function This collects more of the code for writing git headers in a single place and makes diffline() close on a few variables less.
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 16 Jan 2015 14:58:06 -0800
parents 2c166f6b5d10
children f51a822dcf3b
comparison
equal deleted inserted replaced
24019:26fbf07482b2 24020:cc81e6da0757
1752 else: 1752 else:
1753 aprefix = 'a/' 1753 aprefix = 'a/'
1754 bprefix = 'b/' 1754 bprefix = 'b/'
1755 1755
1756 def diffline(a, b, revs): 1756 def diffline(a, b, revs):
1757 if opts.git: 1757 if not repo.ui.quiet:
1758 line = 'diff --git %s%s %s%s\n' % (aprefix, a, bprefix, b)
1759 elif not repo.ui.quiet:
1760 if revs: 1758 if revs:
1761 revinfo = ' '.join(["-r %s" % rev for rev in revs]) 1759 revinfo = ' '.join(["-r %s" % rev for rev in revs])
1762 line = 'diff %s %s\n' % (revinfo, a) 1760 line = 'diff %s %s\n' % (revinfo, a)
1763 else: 1761 else:
1764 line = 'diff %s\n' % a 1762 line = 'diff %s\n' % a
1845 losedatafn(f) 1843 losedatafn(f)
1846 1844
1847 path1 = posixpath.join(prefix, f1) 1845 path1 = posixpath.join(prefix, f1)
1848 path2 = posixpath.join(prefix, f2) 1846 path2 = posixpath.join(prefix, f2)
1849 header = [] 1847 header = []
1850 if opts.git or revs: 1848 if revs:
1851 header.append(diffline(path1, path2, revs)) 1849 header.append(diffline(path1, path2, revs))
1852 if opts.git: 1850 elif opts.git:
1851 header.append('diff --git %s%s %s%s\n' %
1852 (aprefix, path1, bprefix, path2))
1853 if content1 is None: # added 1853 if content1 is None: # added
1854 header.append('new file mode %s\n' % gitmode[flag2]) 1854 header.append('new file mode %s\n' % gitmode[flag2])
1855 elif content2 is None: # removed 1855 elif content2 is None: # removed
1856 header.append('deleted file mode %s\n' % gitmode[flag1]) 1856 header.append('deleted file mode %s\n' % gitmode[flag1])
1857 else: # modified/copied/renamed 1857 else: # modified/copied/renamed