* [PATCH 1/3] git-multimail: Add an option to filter on branches
@ 2015-04-21 23:04 Dave Boutcher
2015-04-21 23:04 ` [PATCH 2/3] git-multimail: Add a quiet option to prevent outputting email addresses from hook Dave Boutcher
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Dave Boutcher @ 2015-04-21 23:04 UTC (permalink / raw)
To: git; +Cc: mhagger, Dave Boutcher
Add a branches option to the config. Only changes
pushed to specified branches will generate emails. Changes to tags
will continue to generate emails.
Signed-off-by: Dave Boutcher <daveboutcher@gmail.com>
---
git-multimail/README | 7 +++++++
git-multimail/git_multimail.py | 44 ++++++++++++++++++++++++++++++++++--------
2 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/git-multimail/README b/git-multimail/README
index 51add52..a40847a 100644
--- a/git-multimail/README
+++ b/git-multimail/README
@@ -170,6 +170,13 @@ multimailhook.repoName
for gitolite repositories, or otherwise to derive this value from
the repository path name.
+multimailhook.branches
+
+ A comma separated list of branches to monitor. If not set,
+ notifications will be sent for updates to any branch. Branch
+ names can contain regular expressions, and this configuration
+ option can be multivalued.
+
multimailhook.mailingList
The list of email addresses to which notification emails should be
diff --git a/git-multimail/git_multimail.py b/git-multimail/git_multimail.py
index 4374907..5ed253f 100755
--- a/git-multimail/git_multimail.py
+++ b/git-multimail/git_multimail.py
@@ -1548,6 +1548,12 @@ class Environment(object):
get_reply_to_commit() is used for individual commit
emails.
+ get_branches()
+
+ Return a list of branches to be handled as a list of regex
+ patterns. If empty list, all branches are handled. Branches
+ can contain regular expressions (such as foo/.*)
+
They should also define the following attributes:
announce_show_shortlog (bool)
@@ -1619,6 +1625,9 @@ class Environment(object):
def get_pusher_email(self):
return None
+ def get_branches(self):
+ return []
+
def get_administrator(self):
return 'the administrator of this repository'
@@ -1809,6 +1818,10 @@ class ConfigOptionsEnvironmentMixin(ConfigEnvironmentMixin):
else:
return self.get_sender()
+ def get_branches(self):
+ branches = self.config.get_all('branches',[])
+ return [re.compile('refs/heads/'+b.strip()) for bs in branches for b in bs.split(',')]
+
def get_reply_to_refchange(self, refchange):
if self.__reply_to_refchange is None:
return super(ConfigOptionsEnvironmentMixin, self).get_reply_to_refchange(refchange)
@@ -2220,8 +2233,9 @@ class Push(object):
])
)
- def __init__(self, changes):
+ def __init__(self, changes, environment):
self.changes = sorted(changes, key=self._sort_key)
+ self.environment = environment
# The SHA-1s of commits referred to by references unaffected
# by this push:
@@ -2246,6 +2260,12 @@ class Push(object):
def _sort_key(klass, change):
return (klass.SORT_ORDER[change.__class__, change.change_type], change.refname,)
+ def branches_match(self, branch):
+ branches = self.environment.get_branches()
+ if not branches:
+ return [True]
+ return [x for x in [r.match(branch) for r in branches] if x]
+
def _compute_other_ref_sha1s(self):
"""Return the GitObjects referred to by references unaffected by this push."""
@@ -2264,6 +2284,10 @@ class Push(object):
)
for line in read_git_lines(['for-each-ref', '--format=%s' % (fmt,)]):
(sha1, type, name) = line.split(' ', 2)
+ # If we are using a branch filter, skip other branches
+ if type == 'commit' and not self.branches_match(name):
+ continue
+
if sha1 and type == 'commit' and name not in updated_refs:
sha1s.add(sha1)
@@ -2334,6 +2358,16 @@ class Push(object):
unhandled_sha1s = set(self.get_new_commits())
send_date = IncrementalDateTime()
for change in self.changes:
+ sha1s = []
+ for sha1 in reversed(list(self.get_new_commits(change))):
+ if sha1 in unhandled_sha1s:
+ sha1s.append(sha1)
+ unhandled_sha1s.remove(sha1)
+
+ # if we are filtering on branches, skip branches we don't care about
+ if change.refname_type == 'branch' and not self.branches_match(change.refname):
+ continue
+
# Check if we've got anyone to send to
if not change.recipients:
sys.stderr.write(
@@ -2349,12 +2383,6 @@ class Push(object):
change.recipients,
)
- sha1s = []
- for sha1 in reversed(list(self.get_new_commits(change))):
- if sha1 in unhandled_sha1s:
- sha1s.append(sha1)
- unhandled_sha1s.remove(sha1)
-
max_emails = change.environment.maxcommitemails
if max_emails and len(sha1s) > max_emails:
sys.stderr.write(
@@ -2389,7 +2417,7 @@ def run_as_post_receive_hook(environment, mailer):
changes.append(
ReferenceChange.create(environment, oldrev, newrev, refname)
)
- push = Push(changes)
+ push = Push(changes, environment)
push.send_emails(mailer, body_filter=environment.filter_body)
--
2.3.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] git-multimail: Add a quiet option to prevent outputting email addresses from hook
2015-04-21 23:04 [PATCH 1/3] git-multimail: Add an option to filter on branches Dave Boutcher
@ 2015-04-21 23:04 ` Dave Boutcher
2015-04-21 23:04 ` [PATCH 3/3] git-multimail: Add stdout option to config Dave Boutcher
2015-04-22 10:39 ` [PATCH 1/3] git-multimail: Add an option to filter on branches Michael Haggerty
2 siblings, 0 replies; 7+ messages in thread
From: Dave Boutcher @ 2015-04-21 23:04 UTC (permalink / raw)
To: git; +Cc: mhagger, Dave Boutcher
We have a very log list of recipients...displaying that list
on every push is annoying
Add an option to prevent printing the list of email addresses from
the hook
Signed-off-by: Dave Boutcher <daveboutcher@gmail.com>
---
git-multimail/README | 3 +++
git-multimail/git_multimail.py | 11 ++++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/git-multimail/README b/git-multimail/README
index a40847a..49e0937 100644
--- a/git-multimail/README
+++ b/git-multimail/README
@@ -396,6 +396,9 @@ multimailhook.replyToRefchange
- The value "none", in which case the Reply-To: field will be
omitted.
+multimailhook.quiet
+
+ Do not output the list of email recipients from the hook
Email filtering aids
--------------------
diff --git a/git-multimail/git_multimail.py b/git-multimail/git_multimail.py
index 5ed253f..095110a 100755
--- a/git-multimail/git_multimail.py
+++ b/git-multimail/git_multimail.py
@@ -1582,6 +1582,9 @@ class Environment(object):
commit mail. The value should be a list of strings
representing words to be passed to the command.
+ quiet (bool)
+ On success do not write to stderr
+
"""
REPO_NAME_RE = re.compile(r'^(?P<name>.+?)(?:\.git)$')
@@ -1594,6 +1597,7 @@ class Environment(object):
self.logopts = []
self.refchange_showlog = False
self.commitlogopts = ['-C', '--stat', '-p', '--cc']
+ self.quiet = False
self.COMPUTED_KEYS = [
'administrator',
@@ -1745,6 +1749,10 @@ class ConfigOptionsEnvironmentMixin(ConfigEnvironmentMixin):
'refchangeshowlog', default=self.refchange_showlog
)
+ self.quiet = config.get_bool(
+ 'quiet', default=False
+ )
+
maxcommitemails = config.get('maxcommitemails')
if maxcommitemails is not None:
try:
@@ -2376,7 +2384,8 @@ class Push(object):
% (change.refname, change.old.sha1, change.new.sha1,)
)
else:
- sys.stderr.write('Sending notification emails to: %s\n' % (change.recipients,))
+ if not self.environment.quiet:
+ sys.stderr.write('Sending notification emails to: %s\n' % (change.recipients,))
extra_values = {'send_date': send_date.next()}
mailer.send(
change.generate_email(self, body_filter, extra_values),
--
2.3.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] git-multimail: Add stdout option to config
2015-04-21 23:04 [PATCH 1/3] git-multimail: Add an option to filter on branches Dave Boutcher
2015-04-21 23:04 ` [PATCH 2/3] git-multimail: Add a quiet option to prevent outputting email addresses from hook Dave Boutcher
@ 2015-04-21 23:04 ` Dave Boutcher
2015-04-22 10:39 ` [PATCH 1/3] git-multimail: Add an option to filter on branches Michael Haggerty
2 siblings, 0 replies; 7+ messages in thread
From: Dave Boutcher @ 2015-04-21 23:04 UTC (permalink / raw)
To: git; +Cc: mhagger, Dave Boutcher
Add a stdout option to the config that is equivalent to the --stdout
command line option. This allows for easier debugging for a hook
Signed-off-by: Dave Boutcher <daveboutcher@gmail.com>
---
git-multimail/README | 5 +++++
git-multimail/git_multimail.py | 10 +++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/git-multimail/README b/git-multimail/README
index 49e0937..0235b83 100644
--- a/git-multimail/README
+++ b/git-multimail/README
@@ -400,6 +400,11 @@ multimailhook.quiet
Do not output the list of email recipients from the hook
+multimailhook.stdout
+
+ For debugging, send emails to stdout rather than to the
+ mailer. Equivalent to the --stdout command line option
+
Email filtering aids
--------------------
diff --git a/git-multimail/git_multimail.py b/git-multimail/git_multimail.py
index 095110a..35a1140 100755
--- a/git-multimail/git_multimail.py
+++ b/git-multimail/git_multimail.py
@@ -1585,6 +1585,9 @@ class Environment(object):
quiet (bool)
On success do not write to stderr
+ stdout (bool)
+ Write email to stdout rather than emailing. Useful for debugging
+
"""
REPO_NAME_RE = re.compile(r'^(?P<name>.+?)(?:\.git)$')
@@ -1598,6 +1601,7 @@ class Environment(object):
self.refchange_showlog = False
self.commitlogopts = ['-C', '--stat', '-p', '--cc']
self.quiet = False
+ self.stdout = False
self.COMPUTED_KEYS = [
'administrator',
@@ -1753,6 +1757,10 @@ class ConfigOptionsEnvironmentMixin(ConfigEnvironmentMixin):
'quiet', default=False
)
+ self.stdout = config.get_bool(
+ 'stdout', default=False
+ )
+
maxcommitemails = config.get('maxcommitemails')
if maxcommitemails is not None:
try:
@@ -2563,7 +2571,7 @@ def main(args):
sys.stderr.write(' %s : %r\n' % (k, v))
sys.stderr.write('\n')
- if options.stdout:
+ if options.stdout or environment.stdout:
mailer = OutputMailer(sys.stdout)
else:
mailer = choose_mailer(config, environment)
--
2.3.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] git-multimail: Add an option to filter on branches
2015-04-21 23:04 [PATCH 1/3] git-multimail: Add an option to filter on branches Dave Boutcher
2015-04-21 23:04 ` [PATCH 2/3] git-multimail: Add a quiet option to prevent outputting email addresses from hook Dave Boutcher
2015-04-21 23:04 ` [PATCH 3/3] git-multimail: Add stdout option to config Dave Boutcher
@ 2015-04-22 10:39 ` Michael Haggerty
2015-04-22 10:46 ` Dave Boutcher
2 siblings, 1 reply; 7+ messages in thread
From: Michael Haggerty @ 2015-04-22 10:39 UTC (permalink / raw)
To: Dave Boutcher, git
On 04/22/2015 01:04 AM, Dave Boutcher wrote:
> Add a branches option to the config. Only changes
> pushed to specified branches will generate emails. Changes to tags
> will continue to generate emails.
Thanks for the patches. Patches 2 and 3 seem uncontroversial, so I
already merged them. Patch 1 is more interesting, and there have been
other proposals for similar features, so I created a pull request for it:
https://github.com/git-multimail/git-multimail/pull/75
(Note the new URL--I just created a GitHub "organization" for
git-multimail to make it easier for other people to get involved. More
info soon...)
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] git-multimail: Add an option to filter on branches
2015-04-22 10:39 ` [PATCH 1/3] git-multimail: Add an option to filter on branches Michael Haggerty
@ 2015-04-22 10:46 ` Dave Boutcher
2015-04-22 11:44 ` Michael Haggerty
0 siblings, 1 reply; 7+ messages in thread
From: Dave Boutcher @ 2015-04-22 10:46 UTC (permalink / raw)
To: Michael Haggerty; +Cc: git
Thanks Michael,
The only code I'm not fond of is matching on a list of regular
expressions. There must be a more pythonic way to do:
+ return [x for x in [r.match(branch) for r in branches] if x]
which basically returns true if "branch" matches any regular
expression in the list.
I pushed this change out to our production git server (its good to be
the king.) I'll obviously update here if it does anything too
unfortunate.
On Wed, Apr 22, 2015 at 6:39 PM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
> On 04/22/2015 01:04 AM, Dave Boutcher wrote:
>> Add a branches option to the config. Only changes
>> pushed to specified branches will generate emails. Changes to tags
>> will continue to generate emails.
>
> Thanks for the patches. Patches 2 and 3 seem uncontroversial, so I
> already merged them. Patch 1 is more interesting, and there have been
> other proposals for similar features, so I created a pull request for it:
>
> https://github.com/git-multimail/git-multimail/pull/75
>
> (Note the new URL--I just created a GitHub "organization" for
> git-multimail to make it easier for other people to get involved. More
> info soon...)
>
> Michael
>
> --
> Michael Haggerty
> mhagger@alum.mit.edu
>
--
Dave B
包小龙
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] git-multimail: Add an option to filter on branches
2015-04-22 10:46 ` Dave Boutcher
@ 2015-04-22 11:44 ` Michael Haggerty
2015-04-23 1:48 ` Dave Boutcher
0 siblings, 1 reply; 7+ messages in thread
From: Michael Haggerty @ 2015-04-22 11:44 UTC (permalink / raw)
To: Dave Boutcher; +Cc: git
On 04/22/2015 12:46 PM, Dave Boutcher wrote:
> The only code I'm not fond of is matching on a list of regular
> expressions. There must be a more pythonic way to do:
>
> + return [x for x in [r.match(branch) for r in branches] if x]
>
> which basically returns true if "branch" matches any regular
> expression in the list.
I think what you are looking for is
return any(r.match(branch) for r in branches)
This also has the advantage of stopping processing as soon as it finds a
match.
I was also wondering why you decided to support comma-separated lists of
regexps *and* multivalued config settings. It seems that supporting only
multivalued settings would suffice.
Maybe you are following the precedent of our email configuration
settings, which support comma-separated lists of email addresses? If so,
I don't think that is necessary. The email support is there for
backwards compatibility and because comma-separated email addresses are
a thing in RFC 2822. Neither of these arguments apply to branch regexps.
> I pushed this change out to our production git server (its good to be
> the king.) I'll obviously update here if it does anything too
> unfortunate.
Thanks.
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] git-multimail: Add an option to filter on branches
2015-04-22 11:44 ` Michael Haggerty
@ 2015-04-23 1:48 ` Dave Boutcher
0 siblings, 0 replies; 7+ messages in thread
From: Dave Boutcher @ 2015-04-23 1:48 UTC (permalink / raw)
To: Michael Haggerty; +Cc: git
On Wed, Apr 22, 2015 at 7:44 PM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
> I think what you are looking for is
>
> return any(r.match(branch) for r in branches)
Yup, thats exactly what I wanted. I'll submit an updated patch
> I was also wondering why you decided to support comma-separated lists of
> regexps *and* multivalued config settings. It seems that supporting only
> multivalued settings would suffice.
In practice we are using gitolite and git-multimail. Allowing both
means our gitolite.conf file can look like
repo foo
# always notify on master
config multimailhook.branches = master
# notify for the current pre-release branches
config multimailhook.branches = v1.7-pre, v1.8-pre
--
Dave B
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-04-23 1:48 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-21 23:04 [PATCH 1/3] git-multimail: Add an option to filter on branches Dave Boutcher
2015-04-21 23:04 ` [PATCH 2/3] git-multimail: Add a quiet option to prevent outputting email addresses from hook Dave Boutcher
2015-04-21 23:04 ` [PATCH 3/3] git-multimail: Add stdout option to config Dave Boutcher
2015-04-22 10:39 ` [PATCH 1/3] git-multimail: Add an option to filter on branches Michael Haggerty
2015-04-22 10:46 ` Dave Boutcher
2015-04-22 11:44 ` Michael Haggerty
2015-04-23 1:48 ` Dave Boutcher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).