Patchwork D10707: templates: fix `revset('parents()') % ...` in amend message template

login
register
mail settings
Submitter phabricator
Date May 11, 2021, 7:27 p.m.
Message ID <differential-rev-PHID-DREV-eq5ptrlylqbrpgk7j5pu-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49026/
State Superseded
Headers show

Comments

phabricator - May 11, 2021, 7:27 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I don't understand why, but putting `revset('parents()') % {desc}` in
  the commit message template for amend resulted in a crash because
  `memctx.hex()` did `hex(self.node())` and its node was None. This
  patch fixes that.
  
  Martin von Zweigbergk <martinvonz@google.com>

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10707

AFFECTED FILES
  mercurial/context.py
  tests/test-commit-amend.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -957,6 +957,7 @@ 
   $ cat >> .hg/hgrc <<EOF
   > [committemplate]
   > changeset.commit.amend = {desc}\n
+  >     HG: {revset('parents()') % 'parent: {desc|firstline}\n'}
   >     HG: M: {file_mods}
   >     HG: A: {file_adds}
   >     HG: R: {file_dels}
@@ -971,6 +972,8 @@ 
   $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of foo"
   expecting diff of foo
   
+  HG: parent: editor should be suppressed
+  
   HG: M: 
   HG: A: foo
   HG: R: 
@@ -985,6 +988,8 @@ 
   $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of foo and y"
   expecting diff of foo and y
   
+  HG: parent: expecting diff of foo
+  
   HG: M: 
   HG: A: foo y
   HG: R: 
@@ -1003,6 +1008,8 @@ 
   $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of a, foo and y"
   expecting diff of a, foo and y
   
+  HG: parent: expecting diff of foo and y
+  
   HG: M: 
   HG: A: foo y
   HG: R: a
@@ -1027,6 +1034,8 @@ 
   $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of a, foo, x and y"
   expecting diff of a, foo, x and y
   
+  HG: parent: expecting diff of a, foo and y
+  
   HG: M: 
   HG: A: foo y
   HG: R: a x
@@ -1058,6 +1067,8 @@ 
   $ HGEDITOR=cat hg commit --amend -e -m "cc should be excluded" -X cc
   cc should be excluded
   
+  HG: parent: expecting diff of a, foo, x and y
+  
   HG: M: 
   HG: A: foo y
   HG: R: a x
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1392,6 +1392,9 @@ 
     def __bytes__(self):
         return bytes(self._parents[0]) + b"+"
 
+    def hex(self):
+        hex(self._repo.nodeconstants.wdirid)
+
     __str__ = encoding.strmethod(__bytes__)
 
     def __nonzero__(self):