obslog: make {patch} not be indented and leave that to the template
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 15 Nov 2019 09:53:42 -0800
changeset 4952 b135591bec1a
parent 4951 7bfd3fed5d1f
child 4953 5c41bb482867
child 4954 a76ed637acba
obslog: make {patch} not be indented and leave that to the template This removes some unwanted indentation from the tests. In the first case, it's because indent() doesn't indent a blank line. In the second case, it's because we used templating with {patch} and had not requested indentation (but we still got it before this patch). Note that tests will only pass with a very recent Mercurial (one with https://phab.mercurial-scm.org/D7432 applied).
hgext3rd/evolve/obshistory.py
tests/test-evolve-obshistory-amend.t
--- a/hgext3rd/evolve/obshistory.py	Thu Nov 07 13:40:53 2019 -0800
+++ b/hgext3rd/evolve/obshistory.py	Fri Nov 15 09:53:42 2019 -0800
@@ -159,15 +159,17 @@
 TEMPLATE_USER = b"""by {label("evolve.user", user)}"""
 TEMPLATE_DATE = b"""{label("evolve.date", "({date(date, "%a %b %d %H:%M:%S %Y %1%2")})")}"""
 TEMPLATE_NOTE = b"""{if(note, "\n    note: {label("evolve.note", note)}")}"""
+TEMPLATE_PATCH = b"""{if(patch, "{patch}")}{if(nopatchreason, "\n(No patch available, {nopatchreason})")}"""
 DEFAULT_TEMPLATE = (b"""%(firstline)s
-{markers %% "  {separate(" ", "%(rewrite)s", "%(operation)s", "%(user)s", "%(date)s")}%(note)s{descdiff}{if(patch, "{patch}")}{if(nopatchreason, "\n    (No patch available, {nopatchreason})")}\n"}
+{markers %% "  {separate(" ", "%(rewrite)s", "%(operation)s", "%(user)s", "%(date)s")}%(note)s{descdiff}{indent("%(patch)s", "    ")}\n"}
 """) % {
     b"firstline": TEMPLATE_FIRST_LINE,
     b"rewrite": TEMPLATE_REWRITE,
     b"operation": TEMPLATE_OPERATION,
     b"user": TEMPLATE_USER,
     b"date": TEMPLATE_DATE,
-    b"note": TEMPLATE_NOTE
+    b"note": TEMPLATE_NOTE,
+    b"patch": TEMPLATE_PATCH,
 }
 
 class obsmarker_printer(compat.changesetprinter):
@@ -638,7 +640,6 @@
                     ui.write(b'\n')
                     firstline = False
                 if linestart:
-                    ui.write(b'    ')
                     linestart = False
                 if chunk == b'\n':
                     linestart = True
--- a/tests/test-evolve-obshistory-amend.t	Thu Nov 07 13:40:53 2019 -0800
+++ b/tests/test-evolve-obshistory-amend.t	Fri Nov 15 09:53:42 2019 -0800
@@ -110,7 +110,7 @@
       @@ -1,1 +1,2 @@
        A0
       +42
-      
+  
   
 
 Test that content diff works with templating
@@ -121,13 +121,13 @@
   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]
-         ```
+     [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