obslog: colorize the patch shown using `hg obslog -p`
This patch adds color support to the patch shown in obslog command.
--- a/CHANGELOG Wed Dec 27 04:09:50 2017 +0530
+++ b/CHANGELOG Wed Jan 10 19:47:43 2018 +0530
@@ -20,6 +20,7 @@
* evolve: preserve phase information with --continue (issue5720)
* evolve: --continue now properly reports merges as evolve
* commit: suggest using topic on new heads
+ * obslog: add color support to content-diff output with --patch
topic (0.7.1)
--- a/hgext3rd/evolve/obshistory.py Wed Dec 27 04:09:50 2017 +0530
+++ b/hgext3rd/evolve/obshistory.py Wed Jan 10 19:47:43 2018 +0530
@@ -167,18 +167,6 @@
extra = ' ' * indent
return "".join(extra + line for line in content.splitlines(True))
-def getmarkercontentpatch(repo, node, succ):
- # Todo get the ops from the cmd
- diffopts = patch.diffallopts(repo.ui, {})
- matchfn = scmutil.matchall(repo)
-
- repo.ui.pushbuffer()
- cmdutil.diffordiffstat(repo.ui, repo, diffopts, node, succ,
- match=matchfn, stat=False)
- buffer = repo.ui.popbuffer()
-
- return _indent(buffer)
-
def getmarkerdescriptionpatch(repo, base, succ):
basectx = repo[base]
succctx = repo[succ]
@@ -518,15 +506,24 @@
fm.plain(descriptionpatch)
# Content patch
- contentpatch = getmarkercontentpatch(repo, node, succ)
- if contentpatch:
- fm.plain("\n")
- fm.plain(contentpatch)
+ diffopts = patch.diffallopts(repo.ui, {})
+ matchfn = scmutil.matchall(repo)
+ firstline = True
+ for chunk, label in patch.diffui(repo, node, succ, matchfn,
+ changes=None, opts=diffopts,
+ prefix='', relroot='',
+ hunksfilterfn=None):
+ if firstline:
+ fm.plain('\n')
+ firstline = False
+ if chunk and chunk != '\n':
+ fm.plain(' ')
+ fm.write('patch', '%s', chunk, label=label)
else:
- patch = " (No patch available, %s)" % _patchavailable[1]
+ nopatch = " (No patch available, %s)" % _patchavailable[1]
fm.plain("\n")
# TODO: should be in json too
- fm.plain(patch)
+ fm.plain(nopatch)
fm.plain("\n")
--- a/tests/test-evolve-obshistory.t Wed Dec 27 04:09:50 2017 +0530
+++ b/tests/test-evolve-obshistory.t Wed Jan 10 19:47:43 2018 +0530
@@ -72,6 +72,27 @@
+42
+ $ hg obslog --patch --color debug
+ @ [evolve.node|4ae3a4151de9] [evolve.rev|(2)] [evolve.short_description|A1]
+ |
+ x [evolve.node|471f378eab4c] [evolve.rev|(1)] [evolve.short_description|A0]
+ [evolve.verb|rewritten](description, content) as [evolve.node|4ae3a4151de9] by [evolve.user|test] [evolve.date|(Thu Jan 01 00:00:00 1970 +0000)]
+ --- a/471f378eab4c-changeset-description
+ +++ b/4ae3a4151de9-changeset-description
+ @@ -1,1 +1,3 @@
+ -A0
+ +A1
+ +
+ +Better commit message
+
+ [diff.diffline|diff -r 471f378eab4c -r 4ae3a4151de9 A0]
+ [diff.file_a|--- a/A0 Thu Jan 01 00:00:00 1970 +0000]
+ [diff.file_b|+++ b/A0 Thu Jan 01 00:00:00 1970 +0000]
+ [diff.hunk|@@ -1,1 +1,2 @@]
+ A0
+ [diff.inserted|+42]
+
+
$ hg obslog --no-graph --patch 4ae3a4151de9
4ae3a4151de9 (2) A1