D3402: notify: add maxdiffstat option to truncate long file lists

joerg.sonnenberger (Joerg Sonnenberger) phabricator at mercurial-scm.org
Tue Apr 17 11:47:32 UTC 2018


joerg.sonnenberger created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Large scale changes like a new GCC version can easily result in 1MB+
  emails due to diffstat alone. The new maxdiffstat option truncates the
  list similar to what maxdiff already provides for the diffs.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/notify.py
  tests/test-notify.t

CHANGE DETAILS

diff --git a/tests/test-notify.t b/tests/test-notify.t
--- a/tests/test-notify.t
+++ b/tests/test-notify.t
@@ -121,6 +121,10 @@
     Maximum number of diff lines to include in notification email. Set to 0 to
     disable the diff, or -1 to include all of it. Default: 300.
   
+  notify.maxdiffstat
+    Maximum number of diffstat lines to include in notification email. Set to -1
+    to include all of it. Default: -1.
+  
   notify.maxsubject
     Maximum number of characters in email's subject line. Default: 67.
   
@@ -152,19 +156,21 @@
   no commands defined
   $ hg init a
   $ echo a > a/a
+  $ echo b > a/b
 
 commit
 
   $ hg --cwd a commit -Ama -d '0 0'
   adding a
-
+  adding b
 
 clone
 
   $ hg --traceback clone a b
   updating to branch default
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ echo a >> a/a
+  $ echo b >> a/b
 
 commit
 
@@ -187,29 +193,34 @@
   adding changesets
   adding manifests
   adding file changes
-  added 1 changesets with 1 changes to 1 files
-  new changesets 0647d048b600
+  added 1 changesets with 2 changes to 2 files
+  new changesets 00a13f371396
   MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: 7bit
   Date: * (glob)
   Subject: changeset in $TESTTMP/b: b
   From: test
-  X-Hg-Notification: changeset 0647d048b600
+  X-Hg-Notification: changeset 00a13f371396
   Message-Id: <*> (glob)
   To: baz, foo at bar
   
-  changeset 0647d048b600 in $TESTTMP/b
-  details: $TESTTMP/b?cmd=changeset;node=0647d048b600
+  changeset 00a13f371396 in $TESTTMP/b
+  details: $TESTTMP/b?cmd=changeset;node=00a13f371396
   description: b
   
-  diffs (6 lines):
+  diffs (12 lines):
   
-  diff -r cb9a9f314b8b -r 0647d048b600 a
+  diff -r 0cd96de13884 -r 00a13f371396 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:01 1970 +0000
   @@ -1,1 +1,2 @@ a
   +a
+  diff -r 0cd96de13884 -r 00a13f371396 b
+  --- a/b	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/b	Thu Jan 01 00:00:01 1970 +0000
+  @@ -1,1 +1,2 @@ b
+  +b
   (run 'hg update' to get a working copy)
 
   $ cat <<EOF >> $HGRCPATH
@@ -241,28 +252,33 @@
   adding changesets
   adding manifests
   adding file changes
-  added 1 changesets with 1 changes to 1 files
-  new changesets 0647d048b600
+  added 1 changesets with 2 changes to 2 files
+  new changesets 00a13f371396
   MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: 7bit
   X-Test: foo
   Date: * (glob)
   Subject: b
   From: test at test.com
-  X-Hg-Notification: changeset 0647d048b600
+  X-Hg-Notification: changeset 00a13f371396
   Message-Id: <*> (glob)
   To: baz at test.com, foo at bar
   
-  changeset 0647d048b600 in b
+  changeset 00a13f371396 in b
   description: b
-  diffs (6 lines):
+  diffs (12 lines):
   
-  diff -r cb9a9f314b8b -r 0647d048b600 a
+  diff -r 0cd96de13884 -r 00a13f371396 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:01 1970 +0000
   @@ -1,1 +1,2 @@ a
   +a
+  diff -r 0cd96de13884 -r 00a13f371396 b
+  --- a/b	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/b	Thu Jan 01 00:00:01 1970 +0000
+  @@ -1,1 +1,2 @@ b
+  +b
   (run 'hg update' to get a working copy)
 
   $ cat << EOF >> $HGRCPATH
@@ -278,49 +294,54 @@
 
   $ hg --cwd b rollback
   repository tip rolled back to revision 0 (undo pull)
-  $ hg --traceback --cwd b pull ../a | $PYTHON $TESTTMP/filter.py
+  $ hg --traceback --config notify.maxdiffstat=1 --cwd b pull ../a | $PYTHON $TESTTMP/filter.py
   pulling from ../a
   searching for changes
   adding changesets
   adding manifests
   adding file changes
-  added 1 changesets with 1 changes to 1 files
-  new changesets 0647d048b600
+  added 1 changesets with 2 changes to 2 files
+  new changesets 00a13f371396
   MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: 7bit
   X-Test: foo
   Date: * (glob)
   Subject: b
   From: test at test.com
-  X-Hg-Notification: changeset 0647d048b600
+  X-Hg-Notification: changeset 00a13f371396
   Message-Id: <*> (glob)
   To: baz at test.com, foo at bar
   
-  changeset 0647d048b600 in b
+  changeset 00a13f371396 in b
   description: b
-  diffstat:
-   a |  1 + 1 files changed, 1 insertions(+), 0 deletions(-)
+  diffstat (truncated from 2 to 1 lines):
+   a |  1 + 2 files changed, 2 insertions(+), 0 deletions(-)
   
-  diffs (6 lines):
+  diffs (12 lines):
   
-  diff -r cb9a9f314b8b -r 0647d048b600 a
+  diff -r 0cd96de13884 -r 00a13f371396 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:01 1970 +0000
   @@ -1,1 +1,2 @@ a
   +a
+  diff -r 0cd96de13884 -r 00a13f371396 b
+  --- a/b	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/b	Thu Jan 01 00:00:01 1970 +0000
+  @@ -1,1 +1,2 @@ b
+  +b
   (run 'hg update' to get a working copy)
 
 test merge
 
   $ cd a
   $ hg up -C 0
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ echo a >> a
   $ hg ci -Am adda2 -d '2 0'
   created new head
   $ hg merge
-  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ hg ci -m merge -d '3 0'
   $ cd ..
@@ -331,26 +352,26 @@
   adding manifests
   adding file changes
   added 2 changesets with 0 changes to 0 files
-  new changesets 0a184ce6067f:6a0cf76b2701
+  new changesets 3332653e1f3c:fccf66cd0c35
   MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: 7bit
   X-Test: foo
   Date: * (glob)
   Subject: adda2
   From: test at test.com
-  X-Hg-Notification: changeset 0a184ce6067f
+  X-Hg-Notification: changeset 3332653e1f3c
   Message-Id: <*> (glob)
   To: baz at test.com, foo at bar
   
-  changeset 0a184ce6067f in b
+  changeset 3332653e1f3c in b
   description: adda2
   diffstat:
    a |  1 + 1 files changed, 1 insertions(+), 0 deletions(-)
   
   diffs (6 lines):
   
-  diff -r cb9a9f314b8b -r 0a184ce6067f a
+  diff -r 0cd96de13884 -r 3332653e1f3c a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:02 1970 +0000
   @@ -1,1 +1,2 @@ a
@@ -362,12 +383,22 @@
   Date: * (glob)
   Subject: merge
   From: test at test.com
-  X-Hg-Notification: changeset 6a0cf76b2701
+  X-Hg-Notification: changeset fccf66cd0c35
   Message-Id: <*> (glob)
   To: baz at test.com, foo at bar
   
-  changeset 6a0cf76b2701 in b
+  changeset fccf66cd0c35 in b
   description: merge
+  diffstat:
+   b |  1 + 1 files changed, 1 insertions(+), 0 deletions(-)
+  
+  diffs (6 lines):
+  
+  diff -r 3332653e1f3c -r fccf66cd0c35 b
+  --- a/b	Thu Jan 01 00:00:02 1970 +0000
+  +++ b/b	Thu Jan 01 00:00:03 1970 +0000
+  @@ -1,1 +1,2 @@ b
+  +b
   (run 'hg update' to get a working copy)
 
 non-ascii content and truncation of multi-byte subject
@@ -387,26 +418,26 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
-  new changesets 7ea05ad269dc
+  new changesets 0f25f9c22b4c
   MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: 8bit
   X-Test: foo
   Date: * (glob)
   Subject: \xc3\xa0... (esc)
   From: test at test.com
-  X-Hg-Notification: changeset 7ea05ad269dc
+  X-Hg-Notification: changeset 0f25f9c22b4c
   Message-Id: <*> (glob)
   To: baz at test.com, foo at bar
   
-  changeset 7ea05ad269dc in b
+  changeset 0f25f9c22b4c in b
   description: \xc3\xa0\xc3\xa1\xc3\xa2\xc3\xa3\xc3\xa4 (esc)
   diffstat:
    a |  1 + 1 files changed, 1 insertions(+), 0 deletions(-)
   
   diffs (7 lines):
   
-  diff -r 6a0cf76b2701 -r 7ea05ad269dc a
+  diff -r fccf66cd0c35 -r 0f25f9c22b4c a
   --- a/a	Thu Jan 01 00:00:03 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,2 +1,3 @@ a a
@@ -430,7 +461,7 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
-  new changesets a323cae54f6e
+  new changesets a846b5f6ebb7
   notify: sending 2 subscribers 1 changes
   (run 'hg update' to get a working copy)
   $ $PYTHON $TESTTMP/filter.py < b/mbox
@@ -442,18 +473,18 @@
   Date: * (glob)
   Subject: long line
   From: test at test.com
-  X-Hg-Notification: changeset a323cae54f6e
-  Message-Id: <hg.a323cae54f6e.*.*@*> (glob)
+  X-Hg-Notification: changeset a846b5f6ebb7
+  Message-Id: <hg.a846b5f6ebb7.*.*@*> (glob)
   To: baz at test.com, foo at bar
   
-  changeset a323cae54f6e in b
+  changeset a846b5f6ebb7 in b
   description: long line
   diffstat:
    a |  1 + 1 files changed, 1 insertions(+), 0 deletions(-)
   
   diffs (8 lines):
   
-  diff -r 7ea05ad269dc -r a323cae54f6e a
+  diff -r 0f25f9c22b4c -r a846b5f6ebb7 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,3 +1,4 @@ a a a
@@ -500,19 +531,19 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
-  new changesets b7cf10b2bdec
+  new changesets f7e5aaed4080
   MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: 7bit
   X-Test: foo
   Date: * (glob)
   Subject: test
   From: test at test.com
-  X-Hg-Notification: changeset b7cf10b2bdec
-  Message-Id: <hg.b7cf10b2bdec.*.*@*> (glob)
+  X-Hg-Notification: changeset f7e5aaed4080
+  Message-Id: <hg.f7e5aaed4080.*.*@*> (glob)
   To: baz at test.com, foo at bar, notify at example.com
   
-  changeset b7cf10b2bdec in b
+  changeset f7e5aaed4080 in b
   description: test
   (run 'hg update' to get a working copy)
 
@@ -530,19 +561,19 @@
   adding manifests
   adding file changes
   added 1 changesets with 0 changes to 0 files (+1 heads)
-  new changesets 5a07df312a79
+  new changesets 645eb6690ecf
   MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: 7bit
   X-Test: foo
   Date: * (glob)
   Subject: test
   From: test at test.com
-  X-Hg-Notification: changeset 5a07df312a79
-  Message-Id: <hg.5a07df312a79.*.*@*> (glob)
+  X-Hg-Notification: changeset 645eb6690ecf
+  Message-Id: <hg.645eb6690ecf.*.*@*> (glob)
   To: baz at test.com, foo at bar
   
-  changeset 5a07df312a79 in b
+  changeset 645eb6690ecf in b
   description: test
   (run 'hg heads' to see heads)
 
@@ -559,12 +590,12 @@
   Date: * (glob)
   Subject: changeset in b: default template
   From: test at test.com
-  X-Hg-Notification: changeset f5e8ec95bf59
-  Message-Id: <hg.f5e8ec95bf59.*.*@*> (glob)
+  X-Hg-Notification: changeset 5cd4346eed47
+  Message-Id: <hg.5cd4346eed47.*.*@*> (glob)
   To: baz at test.com, foo at bar
   
-  changeset f5e8ec95bf59 in $TESTTMP/b
-  details: http://test/b?cmd=changeset;node=f5e8ec95bf59
+  changeset 5cd4346eed47 in $TESTTMP/b
+  details: http://test/b?cmd=changeset;node=5cd4346eed47
   description: default template
 
 with style:
@@ -588,11 +619,11 @@
   Date: * (glob)
   Subject: with style
   From: test at test.com
-  X-Hg-Notification: changeset 9e2c3a8e9c43
-  Message-Id: <hg.9e2c3a8e9c43.*.*@*> (glob)
+  X-Hg-Notification: changeset ec8d9d852f56
+  Message-Id: <hg.ec8d9d852f56.*.*@*> (glob)
   To: baz at test.com, foo at bar
   
-  changeset 9e2c3a8e9c43
+  changeset ec8d9d852f56
 
 with template (overrides style):
 
@@ -609,10 +640,10 @@
   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: 7bit
   Date: * (glob)
-  Subject: e2cbf5bf18a7: with template
+  Subject: 14721b538ae3: with template
   From: test at test.com
-  X-Hg-Notification: changeset e2cbf5bf18a7
-  Message-Id: <hg.e2cbf5bf18a7.*.*@*> (glob)
+  X-Hg-Notification: changeset 14721b538ae3
+  Message-Id: <hg.14721b538ae3.*.*@*> (glob)
   To: baz at test.com, foo at bar
   
   with template
diff --git a/hgext/notify.py b/hgext/notify.py
--- a/hgext/notify.py
+++ b/hgext/notify.py
@@ -103,6 +103,10 @@
   Maximum number of diff lines to include in notification email. Set to 0
   to disable the diff, or -1 to include all of it. Default: 300.
 
+notify.maxdiffstat
+  Maximum number of diffstat lines to include in notification email. Set to -1
+  to include all of it. Default: -1.
+
 notify.maxsubject
   Maximum number of characters in email's subject line. Default: 67.
 
@@ -184,6 +188,9 @@
 configitem('notify', 'maxdiff',
     default=300,
 )
+configitem('notify', 'maxdiffstat',
+    default=-1,
+)
 configitem('notify', 'maxsubject',
     default=67,
 )
@@ -418,10 +425,17 @@
         difflines = ''.join(chunks).splitlines()
 
         if self.ui.configbool('notify', 'diffstat'):
+            maxdiffstat = int(self.ui.config('notify', 'maxdiffstat'))
             s = patch.diffstat(difflines)
             # s may be nil, don't include the header if it is
             if s:
-                self.ui.write(_('\ndiffstat:\n\n%s') % s)
+                if maxdiffstat >= 0 and s.count("\n") > maxdiffstat + 1:
+                    s = s.split("\n")
+                    msg = _('\ndiffstat (truncated from %d to %d lines):\n\n')
+                    self.ui.write(msg % (len(s) - 2, maxdiffstat))
+                    self.ui.write("\n".join(s[:maxdiffstat] + s[-2:]))
+                else:
+                    self.ui.write(_('\ndiffstat:\n\n%s') % s)
 
         if maxdiff == 0:
             return



To: joerg.sonnenberger, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list