[PATCH 3 of 8] diff: Rewrite diffline
bisho (Guillermo)
bisho at fb.com
Thu Nov 15 11:41:34 CST 2012
Ok, will split this patch into three:
- Use ui.quiet to determine wether to print revs in diffline
- args change + opts from context
- diffline cleanups
Will be that ok?
On 11/14/12 13:48 , "Matt Mackall" <mpm at selenic.com> wrote:
>On Tue, 2012-11-13 at 14:25 -0800, Guillermo Pérez wrote:
>> # HG changeset patch
>> # User Guillermo Pérez <bisho at fb.com>
>> # Date 1352307040 28800
>> # Node ID 6dde23de905ecf20b64487b28e8b69cbce6c0b77
>> # Parent ebdfe79a0649f0fdb28734680c06be59bec7dd22
>> diff: Rewrite diffline
>
>This sort of patch is review-hostile (and, relatedly, hostile to anyone
>in the future who ever needs to understand it for archaeological
>purposes).
>
>> Modifications:
>> - Before, quiet mode produced not diffline header for mercurial
>> as a side effect of not populating "revs", weird side effect
>> and we will always need revs for git index header that will
>> be added in upcoming patches, so now we just check ui.quiet
>> from diffline directly.
>
>Sounds good.
>
>> - More readable, diffline format is a string with placeholders
>> rather than appending to a list from many ifs.
>
>Cleanup that obscures this patch, belongs in a separate patch.
>
>> - Args order swapped, since a, b are more important than revs
>> that is only used on non-git format.
>
>Cleanup that obscures this patch, belongs in a separate patch.
>
>> - Read opts from context
>
>Cleanup that obscures this patch, belongs in a separate patch.
>
>> diff --git a/mercurial/patch.py b/mercurial/patch.py
>> --- a/mercurial/patch.py
>> +++ b/mercurial/patch.py
>> @@ -1584,9 +1584,8 @@
>> return []
>>
>> revs = None
>> - if not repo.ui.quiet:
>> - hexfunc = repo.ui.debugflag and hex or short
>> - revs = [hexfunc(node) for node in [node1, node2] if node]
>> + hexfunc = repo.ui.debugflag and hex or short
>> + revs = [hexfunc(node) for node in [node1, node2] if node]
>>
>> copy = {}
>> if opts.git or opts.upgrade:
>> @@ -1665,18 +1664,18 @@
>> header.append('old mode %s\n' % omode)
>> header.append('new mode %s\n' % nmode)
>>
>> - def diffline(revs, a, b, opts):
>> - parts = ['diff']
>> + def diffline(a, b, revs):
>> 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)
>> + line = 'diff --git a/%s b/%s\n' % (a, b)
>> + elif not repo.ui.quiet:
>> + if revs:
>> + revinfo = ' '.join(["-r %s" % rev for rev in revs])
>> + line = 'diff %s %s\n' % (revinfo, a)
>> + else:
>> + line = 'diff %s\n' % a
>> else:
>> - parts.append(a)
>> - return ' '.join(parts) + '\n'
>> + line = ''
>> + return line
>>
>> date1 = util.datestr(ctx1.date())
>> man1 = ctx1.manifest()
>> @@ -1763,7 +1762,7 @@
>>
>> if dodiff:
>> if opts.git or revs:
>> - header.insert(0, diffline(revs, join(a), join(b),
>>opts))
>> + header.insert(0, diffline(join(a), join(b), revs))
>> if dodiff == 'binary':
>> text = mdiff.b85diff(to, tn)
>> else:
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel at selenic.com
>> http://selenic.com/mailman/listinfo/mercurial-devel
>
>
>--
>Mathematics is the supreme nostalgia of our time.
>
>
More information about the Mercurial-devel
mailing list