Mercurial > evolve
changeset 4946:bd992b1d4426
obslog: make content and description patches available to templater
The code was repeatedly calling fm.write() with the same field
("patch" and "descdiff"). I think that led to the value constantly
getting replaced, so when it was used in a template (as {patch} or
{descdiff}), it would only get the last value, which was always an
empty string.
This patch fixes it by writing the full patch to a temporary buffer
and then assigning the whole patch to the formatter field.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 07 Nov 2019 16:34:01 -0800 |
parents | bd50608f54d8 |
children | 0ad2000854c4 |
files | hgext3rd/evolve/obshistory.py tests/test-evolve-obshistory-amend.t |
diffstat | 2 files changed, 67 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/obshistory.py Thu Nov 07 17:22:44 2019 -0800 +++ b/hgext3rd/evolve/obshistory.py Thu Nov 07 16:34:01 2019 -0800 @@ -179,7 +179,7 @@ succs = sorted(succs) for successor in succs: - _debugobshistorydisplaymarker(markerfm, successor, + _debugobshistorydisplaymarker(self.ui, markerfm, successor, ctx.node(), self.repo, self._includediff) @@ -191,7 +191,7 @@ if not markers: continue successors = succset[b"successors"] - _debugobshistorydisplaysuccsandmarkers(markerfm, successors, markers, ctx.node(), self.repo, self._includediff) + _debugobshistorydisplaysuccsandmarkers(self.ui, markerfm, successors, markers, ctx.node(), self.repo, self._includediff) markerfm.end() @@ -455,7 +455,7 @@ markerfm = fm.nested(b"markers") for successor in sorted(succs): includediff = opts and opts.get("patch") - _debugobshistorydisplaymarker(markerfm, successor, ctxnode, unfi, includediff) + _debugobshistorydisplaymarker(ui, markerfm, successor, ctxnode, unfi, includediff) markerfm.end() precs = precursors.get(ctxnode, ()) @@ -497,7 +497,7 @@ label=b"evolve.node evolve.missing_change_ctx") fm.plain(b'\n') -def _debugobshistorydisplaymarker(fm, marker, node, repo, includediff=False): +def _debugobshistorydisplaymarker(ui, fm, marker, node, repo, includediff=False): succnodes = marker[1] date = marker[4] metadata = dict(marker[3]) @@ -593,15 +593,18 @@ def tolist(text): return [text] - fm.plain(b"\n") + ui.pushbuffer(labeled=True) + ui.write(b"\n") for chunk, label in patch.difflabel(tolist, descriptionpatch): chunk = chunk.strip(b'\t') if chunk and chunk != b'\n': - fm.plain(b' ') - fm.write(b'descdiff', b'%s', chunk, label=label) + ui.write(b' ') + ui.write(chunk, label=label) + fm.write(b'descdiff', b'%s', ui.popbuffer()) # Content patch + ui.pushbuffer(labeled=True) diffopts = patch.diffallopts(repo.ui, {}) matchfn = scmutil.matchall(repo) firstline = True @@ -609,14 +612,15 @@ for chunk, label in patch.diffui(repo, node, succ, matchfn, opts=diffopts): if firstline: - fm.plain(b'\n') + ui.write(b'\n') firstline = False if linestart: - fm.plain(b' ') + ui.write(b' ') linestart = False if chunk == b'\n': linestart = True - fm.write(b'patch', b'%s', chunk, label=label) + ui.write(chunk, label=label) + fm.write(b'patch', b'%s', ui.popbuffer()) else: nopatch = b" (No patch available, %s)" % _patchavailable[1] fm.plain(b"\n") @@ -625,7 +629,7 @@ fm.plain(b"\n") -def _debugobshistorydisplaysuccsandmarkers(fm, succnodes, markers, node, repo, includediff=False): +def _debugobshistorydisplaysuccsandmarkers(ui, fm, succnodes, markers, node, repo, includediff=False): """ This function is a duplication of _debugobshistorydisplaymarker modified to accept multiple markers as input. @@ -733,15 +737,18 @@ def tolist(text): return [text] - fm.plain(b"\n") + ui.pushbuffer(labeled=True) + ui.write(b"\n") for chunk, label in patch.difflabel(tolist, descriptionpatch): chunk = chunk.strip(b'\t') if chunk and chunk != b'\n': - fm.plain(b' ') - fm.write(b'descdiff', b'%s', chunk, label=label) + ui.write(b' ') + ui.write(chunk, label=label) + fm.write(b'descdiff', b'%s', ui.popbuffer()) # Content patch + ui.pushbuffer(labeled=True) diffopts = patch.diffallopts(repo.ui, {}) matchfn = scmutil.matchall(repo) firstline = True @@ -749,14 +756,15 @@ for chunk, label in patch.diffui(repo, node, succ, matchfn, opts=diffopts): if firstline: - fm.plain(b'\n') + ui.write(b'\n') firstline = False if linestart: - fm.plain(b' ') + ui.write(b' ') linestart = False if chunk == b'\n': linestart = True - fm.write(b'patch', b'%s', chunk, label=label) + ui.write(chunk, label=label) + fm.write(b'patch', b'%s', ui.popbuffer()) else: nopatch = b" (No patch available, %s)" % _patchavailable[1] fm.plain(b"\n")
--- a/tests/test-evolve-obshistory-amend.t Thu Nov 07 17:22:44 2019 -0800 +++ b/tests/test-evolve-obshistory-amend.t Thu Nov 07 16:34:01 2019 -0800 @@ -112,14 +112,20 @@ Test that content diff works with templating -BROKEN: should show content diff $ hg obslog --color=debug --patch 4ae3a4151de9 \ > -T '{node} {desc|firstline}\n{markers % "patch:\n```{patch}```\n"}' @ 4ae3a4151de9 A1 | x 471f378eab4c A0 patch: - `````` + ``` + [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 4ae3a4151de9 --graph -T'{label("log.summary", desc|firstline)} {if(markers, join(markers % "at {date|hgdate} by {user|person} ", " also "))}' @ A1 @@ -362,20 +368,48 @@ Test that description diff works with templating -BROKEN: should show description diff $ hg obslog --color=debug --patch 92210308515b \ > -T '{node} {desc|firstline}\n{markers % "description diff:\n```{descdiff}```\n"}' @ 92210308515b A3 | - x 4f1685185907 + x 4f1685185907 A2 | description diff: - | `````` + | ``` + | [diff.diffline|diff -r 4f1685185907 -r 92210308515b changeset-description] + | [diff.file_a|--- a/changeset-description] + | [diff.file_b|+++ b/changeset-description] + | [diff.hunk|@@ -1,3 +1,3 @@] + | [diff.deleted|-A2] + | [diff.inserted|+A3] + | + | [diff.deleted|-Better better commit message] + | [diff.inserted|+Better better better commit message] + | ``` x 4ae3a4151de9 A1 | description diff: - | `````` - x 471f378eab4c + | ``` + | [diff.diffline|diff -r 4ae3a4151de9 -r 4f1685185907 changeset-description] + | [diff.file_a|--- a/changeset-description] + | [diff.file_b|+++ b/changeset-description] + | [diff.hunk|@@ -1,3 +1,3 @@] + | [diff.deleted|-A1] + | [diff.inserted|+A2] + | + | [diff.deleted|-Better commit message] + | [diff.inserted|+Better better commit message] + | ``` + x 471f378eab4c A0 description diff: - `````` + ``` + [diff.diffline|diff -r 471f378eab4c -r 4ae3a4151de9 changeset-description] + [diff.file_a|--- a/changeset-description] + [diff.file_b|+++ b/changeset-description] + [diff.hunk|@@ -1,1 +1,3 @@] + [diff.deleted|-A0] + [diff.inserted|+A1] + [diff.inserted|+] + [diff.inserted|+Better commit message] + ``` Check the output on the server ------------------------------