[PATCH 2 of 9] notify: do not load style file if template is specified (BC)

Yuya Nishihara yuya at tcha.org
Fri Apr 15 09:15:41 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1459777850 -32400
#      Mon Apr 04 22:50:50 2016 +0900
# Node ID a6bfba7f79df88616e005b693157221528c41c0d
# Parent  f57c8f4f61459d76e62c72412e4a5c0eee28c947
notify: do not load style file if template is specified (BC)

This patch makes sure that either "tmpl" or "mapfile" is exclusively set,
which is the same behavior as common log-like templates and formatter outputs.

See the previous patch for why.

diff --git a/hgext/notify.py b/hgext/notify.py
--- a/hgext/notify.py
+++ b/hgext/notify.py
@@ -196,9 +196,11 @@ class notifier(object):
         self.subs = self.subscribers()
         self.merge = self.ui.configbool('notify', 'merge', True)
 
-        mapfile = self.ui.config('notify', 'style')
+        mapfile = None
         template = (self.ui.config('notify', hooktype) or
                     self.ui.config('notify', 'template'))
+        if not template:
+            mapfile = self.ui.config('notify', 'style')
         if not mapfile and not template:
             template = deftemplates.get(hooktype) or single_template
         self.t = cmdutil.changeset_templater(self.ui, self.repo, False, None,
diff --git a/tests/test-notify.t b/tests/test-notify.t
--- a/tests/test-notify.t
+++ b/tests/test-notify.t
@@ -553,3 +553,76 @@ from different branch
   description: test
   (run 'hg heads' to see heads)
 
+default template:
+
+  $ grep -v '^template =' $HGRCPATH > "$HGRCPATH.new"
+  $ mv "$HGRCPATH.new" $HGRCPATH
+  $ echo a >> a/a
+  $ hg --cwd a commit -m 'default template'
+  $ hg --cwd b pull ../a -q | \
+  >   $PYTHON -c 'import sys,re; print re.sub("\n\t", " ", sys.stdin.read()),'
+  Content-Type: text/plain; charset="us-ascii"
+  MIME-Version: 1.0
+  Content-Transfer-Encoding: 7bit
+  Date: * (glob)
+  Subject: changeset in b: default template
+  From: test at test.com
+  X-Hg-Notification: changeset 3548c9e294b6
+  Message-Id: <hg.3548c9e294b6.*.*@*> (glob)
+  To: baz at test.com, foo at bar
+  
+  changeset 3548c9e294b6 in $TESTTMP/b
+  details: http://test/b?cmd=changeset;node=3548c9e294b6
+  description: default template
+
+with style:
+
+  $ cat <<EOF > notifystyle.map
+  > changeset = "Subject: {desc|firstline|strip}
+  >              From: {author}
+  >              {""}
+  >              changeset {node|short}"
+  > EOF
+  $ cat <<EOF >> $HGRCPATH
+  > [notify]
+  > style = $TESTTMP/notifystyle.map
+  > EOF
+  $ echo a >> a/a
+  $ hg --cwd a commit -m 'with style'
+  $ hg --cwd b pull ../a -q | \
+  >   $PYTHON -c 'import sys,re; print re.sub("\n\t", " ", sys.stdin.read()),'
+  Content-Type: text/plain; charset="us-ascii"
+  MIME-Version: 1.0
+  Content-Transfer-Encoding: 7bit
+  Date: * (glob)
+  Subject: with style
+  From: test at test.com
+  X-Hg-Notification: changeset e917dbd961d3
+  Message-Id: <hg.e917dbd961d3.*.*@*> (glob)
+  To: baz at test.com, foo at bar
+  
+  changeset e917dbd961d3
+
+with template (overrides style):
+
+  $ cat <<EOF >> $HGRCPATH
+  > template = Subject: {node|short}: {desc|firstline|strip}
+  >            From: {author}
+  >            {""}
+  >            {desc}
+  > EOF
+  $ echo a >> a/a
+  $ hg --cwd a commit -m 'with template'
+  $ hg --cwd b pull ../a -q | \
+  >   $PYTHON -c 'import sys,re; print re.sub("\n\t", " ", sys.stdin.read()),'
+  Content-Type: text/plain; charset="us-ascii"
+  MIME-Version: 1.0
+  Content-Transfer-Encoding: 7bit
+  Date: * (glob)
+  Subject: a09743fd3edd: with template
+  From: test at test.com
+  X-Hg-Notification: changeset a09743fd3edd
+  Message-Id: <hg.a09743fd3edd.*.*@*> (glob)
+  To: baz at test.com, foo at bar
+  
+  with template


More information about the Mercurial-devel mailing list