# HG changeset patch # User Dirkjan Ochtman # Date 1224674092 -7200 # Node ID ca5ac40949dc84abfe3420037a6c6699114a1ed9 # Parent dd891d0d97a34c169c9149ffa1cd907dd0385755 patch/diff: use a separate function to write the first line of a file diff diff -r dd891d0d97a3 -r ca5ac40949dc mercurial/mdiff.py --- a/mercurial/mdiff.py Wed Oct 22 12:56:28 2008 +0200 +++ b/mercurial/mdiff.py Wed Oct 22 13:14:52 2008 +0200 @@ -66,6 +66,19 @@ text = re.sub('\n+', '', text) return text +def diffline(revs, a, b, opts): + parts = ['diff'] + if opts.git: + parts.append('--git') + if revs and not opts.git: + parts.append(' '.join(["-r %s" % rev for rev in revs])) + if opts.git: + parts.append('a/%s' % a) + parts.append('b/%s' % b) + else: + parts.append(a) + return ' '.join(parts) + '\n' + def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts): def datetag(date, addtab=True): if not opts.git and not opts.nodates: @@ -113,8 +126,7 @@ l[ln] += "\n\ No newline at end of file\n" if r: - l.insert(0, "diff %s %s\n" % - (' '.join(["-r %s" % rev for rev in r]), fn1)) + l.insert(0, diffline(r, fn1, fn2, opts)) return "".join(l) diff -r dd891d0d97a3 -r ca5ac40949dc mercurial/patch.py --- a/mercurial/patch.py Wed Oct 22 12:56:28 2008 +0200 +++ b/mercurial/patch.py Wed Oct 22 13:14:52 2008 +0200 @@ -1266,7 +1266,7 @@ if util.binary(to) or util.binary(tn): dodiff = 'binary' r = None - header.insert(0, 'diff --git a/%s b/%s\n' % (a, b)) + header.insert(0, mdiff.diffline(r, a, b, opts)) if dodiff: if dodiff == 'binary': text = b85diff(to, tn)