[PATCH] add exclude to the notify extension.

Alexander Saltanov a at nearbird.ru
Tue Mar 3 07:01:01 CST 2009


# HG changeset patch
# User Alexander Saltanov <a at nearbird.ru>
# Date 1236084662 -10800
# Node ID f2a532ecc62a408e300e61cc180a8f7ac1f2c790
# Parent  6d99ff7b79b54f624eee18f2c1e3be6f6efed98a
This patch adds parameter 'exclude' to the notify extension.

It is useful in projects with lots of automatically created and edited  
files,
like XCode projects or VisualStudio files. Now you may add
'exclude = *.xcodeproj/*' into repository's hgrc and MacOS X developer
will stop annoying you.

All changes are held within notify.py to isolate possible inefficiency
on large diffs.

diff -r 6d99ff7b79b5 -r f2a532ecc62a hgext/notify.py
--- a/hgext/notify.py	Fri Feb 27 08:13:42 2009 -0600
+++ b/hgext/notify.py	Tue Mar 03 15:51:02 2009 +0300
@@ -42,8 +42,12 @@
     diffstat = True        # add a diffstat before the diff content
     sources = serve        # notify if source of incoming changes in  
this list
                            # (serve == ssh or http, push, pull, bundle)
+   exclude = ..., ...     # patterns to exclude files from email report
+                          # (exclude = *.xcodeproj/ will exclude  
whole directory)
+
     [email]
     from = user at host.com   # email address to send as if none given
+
     [web]
     baseurl = http://hgserver/... # root of hg web site for browsing  
commits

@@ -68,6 +72,7 @@
  from mercurial.node import bin, short
  from mercurial import patch, cmdutil, templater, util, mail
  import email.Parser, fnmatch, socket, time
+import re

  # template for single changeset can include email headers.
  single_template = '''
@@ -120,6 +125,20 @@
              template = templater.parsestring(template, quoted=False)
              self.t.use_template(template)

+    def excludes(self):
+        '''return list of compiled regexps to match paths
+           to exclude from email report.'''
+
+        matchers = []
+        wildcards = self.ui.config('notify', 'exclude')
+        if wildcards:
+            for pat in wildcards.split(','):
+                # do not use util.expanded_glob:
+                # it doesn't match a/a.txt and b/b.txt with pattern  
'*.txt'
+                pattern = pat.strip().replace('*',  
'[^/]*').replace('.', '\.')
+                matchers.append(re.compile(pattern, re.IGNORECASE))
+        return matchers
+
      def strip(self, path):
          '''strip leading slashes from local path, turn into web-safe  
path.'''

@@ -240,7 +259,24 @@
          prev = ctx.parents()[0].node()
          ref = ref and ref.node() or ctx.node()
          chunks = patch.diff(self.repo, prev, ref,  
opts=patch.diffopts(self.ui))
-        difflines = ''.join(chunks).splitlines()
+        origdiff = ''.join(chunks).splitlines()
+
+        difflines = []
+        excludes = self.excludes()
+        if excludes:
+            skipline = False
+            for line in origdiff:
+                if line.rfind("diff ") == 0:
+                    for regexp in excludes:
+                        if regexp.search(line):
+                            skipline = True
+                            break
+                        else:
+                            skipline = False
+                if not skipline:
+                    difflines.append(line)
+        else:
+            difflines = origdiff

          if self.ui.configbool('notify', 'diffstat', True):
              s = patch.diffstat(difflines)
diff -r 6d99ff7b79b5 -r f2a532ecc62a tests/test-notify
--- a/tests/test-notify	Fri Feb 27 08:13:42 2009 -0600
+++ b/tests/test-notify	Tue Mar 03 15:51:02 2009 +0300
@@ -98,3 +98,28 @@
    -e 's/changeset \([0-9a-f]*\) in .*/changeset \1/' \
    -e 's/^Date:.*/Date:/'

+echo % test exclude
+hg --cwd b rollback
+
+cat << EOF >> $HGRCPATH
+[notify]
+exclude = *.excludeme, *.excludemetoo/
+EOF
+
+cd a
+echo a >> a
+echo a >> a.excludeme
+mkdir bb
+cd bb
+echo a >> b.excludeme
+cd ..
+mkdir cc.excludemetoo
+cd cc.excludemetoo
+echo a >> a
+echo b >> b
+cd ..
+hg --traceback commit -Am exclude -d '4 0'
+cd ..
+hg --traceback --cwd b pull ../a 2>&1 | sed -e 's/\(Message-Id:\).*/ 
\1/' \
+  -e 's/changeset \([0-9a-f]*\) in .*/changeset \1/' \
+  -e 's/^Date:.*/Date:/'
diff -r 6d99ff7b79b5 -r f2a532ecc62a tests/test-notify.out
--- a/tests/test-notify.out	Fri Feb 27 08:13:42 2009 -0600
+++ b/tests/test-notify.out	Tue Mar 03 15:51:02 2009 +0300
@@ -35,8 +35,12 @@
     diffstat = True        # add a diffstat before the diff content
     sources = serve        # notify if source of incoming changes in  
this list
                            # (serve == ssh or http, push, pull, bundle)
+   exclude = ..., ...     # patterns to exclude files from email report
+                          # (exclude = *.xcodeproj/ will exclude  
whole directory)
+
     [email]
     from = user at host.com   # email address to send as if none given
+
     [web]
     baseurl = http://hgserver/... # root of hg web site for browsing  
commits

@@ -217,3 +221,85 @@
  description:
  	merge
  (run 'hg update' to get a working copy)
+% test exclude
+rolling back last transaction
+adding a.excludeme
+adding bb/b.excludeme
+adding cc.excludemetoo/a
+adding cc.excludemetoo/b
+pulling from ../a
+searching for changes
+adding changesets
+adding manifests
+adding file changes
+added 3 changesets with 5 changes to 5 files
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+X-Test: foo
+Date:
+Subject: adda2
+From: test at test.com
+X-Hg-Notification: changeset 0a184ce6067f
+Message-Id:
+To: baz at test.com, foo at bar
+
+changeset 0a184ce6067f
+description:
+	adda2
+diffstat:
+
+ a |  1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
+
+diffs (6 lines):
+
+diff -r cb9a9f314b8b -r 0a184ce6067f 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
++a
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+X-Test: foo
+Date:
+Subject: merge
+From: test at test.com
+X-Hg-Notification: changeset 22c88b85aa27
+Message-Id:
+To: baz at test.com, foo at bar
+
+changeset 22c88b85aa27
+description:
+	merge
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+X-Test: foo
+Date:
+Subject: exclude
+From: test at test.com
+X-Hg-Notification: changeset d49e5456c708
+Message-Id:
+To: baz at test.com, foo at bar
+
+changeset d49e5456c708
+description:
+	exclude
+diffstat:
+
+ a |  1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
+
+diffs (7 lines):
+
+diff -r 22c88b85aa27 -r d49e5456c708 a
+--- a/a	Thu Jan 01 00:00:03 1970 +0000
++++ b/a	Thu Jan 01 00:00:04 1970 +0000
+@@ -1,2 +1,3 @@
+ a
+ a
++a
+(run 'hg update' to get a working copy)



More information about the Mercurial-devel mailing list