Merge lp:~danigm/bzr-email/branch-commit-to into lp:bzr-email

Proposed by danigm
Status: Rejected
Rejected by: Jelmer Vernooij
Proposed branch: lp:~danigm/bzr-email/branch-commit-to
Merge into: lp:bzr-email
Diff against target: 214 lines (+111/-25)
2 files modified
__init__.py (+41/-0)
emailer.py (+70/-25)
To merge this branch: bzr merge lp:~danigm/bzr-email/branch-commit-to
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) code Disapprove
Robert Collins (community) Needs Information
Review via email: mp+15536@code.launchpad.net
To post a comment you must log in.
Revision history for this message
danigm (danigm) wrote :

Post commit to per repository

Revision history for this message
Robert Collins (lifeless) wrote :

Hi, thanks for this merge proposal.

I don't understand why all this is needed, and you proposal doesn't
explain either. There are a number of structural issues, such as using
GlobalConfig directly, and using private variables, which I can't assess
until I know the reason for the changes.

Could you please explain in more detail what was wrong that you needed
to change to make things work.

Thanks,
Rob

 review: needsinfo

review: Needs Information
Revision history for this message
danigm (danigm) wrote :

> Hi, thanks for this merge proposal.
>
> I don't understand why all this is needed, and you proposal doesn't
> explain either. There are a number of structural issues, such as using
> GlobalConfig directly, and using private variables, which I can't assess
> until I know the reason for the changes.
>
> Could you please explain in more detail what was wrong that you needed
> to change to make things work.
>

When I use bazaar in my computer I have a lot of branch of a lot of projects. And if I set post_commit_to to an email, all branches send an email when I do commit, and I only want to send to different email accounts depending on wich branch I'm working.

This branch add the option to configure a post_commit_to for each branch in your machine.

I think that this resolve that bug #309560

Revision history for this message
Robert Collins (lifeless) wrote :

On Thu, 2009-12-03 at 08:55 +0000, danigm wrote:
> > Hi, thanks for this merge proposal.
> >
> > I don't understand why all this is needed, and you proposal doesn't
> > explain either. There are a number of structural issues, such as using
> > GlobalConfig directly, and using private variables, which I can't assess
> > until I know the reason for the changes.
> >
> > Could you please explain in more detail what was wrong that you needed
> > to change to make things work.
> >
>
> When I use bazaar in my computer I have a lot of branch of a lot of projects. And if I set post_commit_to to an email, all branches send an email when I do commit, and I only want to send to different email accounts depending on wich branch I'm working.
>
> This branch add the option to configure a post_commit_to for each branch in your machine.
>
> I think that this resolve that bug #309560

You should already be able to do that in branch.conf, are you saying
that that doesn't work?

-Rob

Revision history for this message
danigm (danigm) wrote :

> On Thu, 2009-12-03 at 08:55 +0000, danigm wrote:
> > > Hi, thanks for this merge proposal.
> > >
> > > I don't understand why all this is needed, and you proposal doesn't
> > > explain either. There are a number of structural issues, such as using
> > > GlobalConfig directly, and using private variables, which I can't assess
> > > until I know the reason for the changes.
> > >
> > > Could you please explain in more detail what was wrong that you needed
> > > to change to make things work.
> > >
> >
> > When I use bazaar in my computer I have a lot of branch of a lot of
> projects. And if I set post_commit_to to an email, all branches send an email
> when I do commit, and I only want to send to different email accounts
> depending on wich branch I'm working.
> >
> > This branch add the option to configure a post_commit_to for each branch in
> your machine.
> >
> > I think that this resolve that bug #309560
>
> You should already be able to do that in branch.conf, are you saying
> that that doesn't work?
>
> -Rob

mmm... ok, that isn't documented... or it's... anyway I don't know nothing about branch.conf, I need to read about it. Today I learn something new.

Sorry, then this branch has no sense, and bug report is invalid too.

Thanks.

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

> > On Thu, 2009-12-03 at 08:55 +0000, danigm wrote:
> > > > Hi, thanks for this merge proposal.
> > > >
> > > > I don't understand why all this is needed, and you proposal doesn't
> > > > explain either. There are a number of structural issues, such as using
> > > > GlobalConfig directly, and using private variables, which I can't assess
> > > > until I know the reason for the changes.
> > > >
> > > > Could you please explain in more detail what was wrong that you needed
> > > > to change to make things work.
> > > >
> > >
> > > When I use bazaar in my computer I have a lot of branch of a lot of
> > projects. And if I set post_commit_to to an email, all branches send an
> email
> > when I do commit, and I only want to send to different email accounts
> > depending on wich branch I'm working.
> > >
> > > This branch add the option to configure a post_commit_to for each branch
> in
> > your machine.
> > >
> > > I think that this resolve that bug #309560
> >
> > You should already be able to do that in branch.conf, are you saying
> > that that doesn't work?

> mmm... ok, that isn't documented... or it's... anyway I don't know nothing
> about branch.conf, I need to read about it. Today I learn something new.
We should definitely improve the documentation for branch.conf - I agree it's not as clear at the moment as it could be.

Newer versions of bzr have a "bzr config" command which allows you to see and modify all relevant configuration options, both global and per-branch.

> Sorry, then this branch has no sense, and bug report is invalid too.
The bug report is about a repository-specific configuration (rather than a branch-specific configuration, which branch.conf is).

I'll mark this MP as rejected, since it overlaps with functionality we already have.

review: Disapprove (code)

Unmerged revisions

42. By danigm

added mailto commad

41. By danigm

Configure post_commit_to per repository #309560

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2008-12-09 20:09:15 +0000
3+++ __init__.py 2009-12-02 10:40:24 +0000
4@@ -71,6 +71,10 @@
5 from bzrlib import errors
6 from bzrlib.branch import Branch
7 from bzrlib.lazy_import import lazy_import
8+from bzrlib.commands import Command, register_command
9+from bzrlib.config import GlobalConfig
10+from bzrlib.errors import InvalidURL, BzrCommandError, NotBranchError
11+from bzrlib.option import Option
12
13 # lazy_import emailer so that it doesn't get loaded if it isn't used
14 lazy_import(globals(), """\
15@@ -119,6 +123,41 @@
16 result.addTest(bzrlib.plugins.email.tests.test_suite())
17 return result
18
19+class cmd_mailto(Command):
20+ """Add, remove or modify a mailto on commit by branch."""
21+
22+ _see_also = ["mailto"]
23+
24+ takes_args = ['email', 'location?']
25+ takes_options = [
26+ Option('delete', help='Delete this bookmark.'),
27+ ]
28+
29+ def run(self, email=None, location='.', delete=False):
30+ self.set_email(email, location)
31+ if delete:
32+ self.del_email(location)
33+
34+ def get_url(self, location='.'):
35+ self.branch = Branch.open_containing(location)[0]
36+ url = "EMAIL:%s" % self.branch.base[7:]
37+ return url
38+
39+ def del_email(self, location):
40+ config = GlobalConfig()
41+ parser = config._get_parser()
42+ url = self.get_url(location)
43+ del parser[url]["post_commit_to"]
44+ parser.write(file(config._get_filename(), 'wb'))
45+
46+ def set_email(self, email, location):
47+ config = GlobalConfig()
48+ parser = config._get_parser()
49+ url = self.get_url(location)
50+ if url not in parser:
51+ parser[url] = {}
52+ parser[url]["post_commit_to"] = email
53+ parser.write(file(config._get_filename(), 'wb'))
54
55 # setup the email plugin with > 0.15 hooks.
56 try:
57@@ -130,3 +169,5 @@
58 except errors.UnknownHook:
59 # bzr 0.15 dev before post_commit was added
60 use_legacy = True
61+
62+register_command(cmd_mailto)
63
64=== modified file 'emailer.py'
65--- emailer.py 2008-12-09 20:09:15 +0000
66+++ emailer.py 2009-12-02 10:40:24 +0000
67@@ -16,6 +16,8 @@
68
69 import errno
70 import subprocess
71+from bzrlib.config import GlobalConfig
72+
73
74 from bzrlib import (
75 errors,
76@@ -43,6 +45,9 @@
77 self.revno = None
78 self.op = op
79
80+ c = GlobalConfig()
81+ self.parser = c._get_parser()
82+
83 def _setup_revision_and_revno(self):
84 self.revision = self.repository.get_revision(self._revision_id)
85 self.revno = self.branch.revision_id_to_revno(self._revision_id)
86@@ -125,20 +130,28 @@
87
88 def difflimit(self):
89 """Maximum number of lines of diff to show."""
90- result = self.config.get_user_option('post_commit_difflimit')
91- if result is None:
92- result = 1000
93- return int(result)
94+ opt = self.get_custom_opt('post_commit_difflimit')
95+ if opt:
96+ return opt
97+ else:
98+ result = self.config.get_user_option('post_commit_difflimit')
99+ if result is None:
100+ result = 1000
101+ return int(result)
102
103 def mailer(self):
104 """What mail program to use."""
105- result = self.config.get_user_option('post_commit_mailer')
106- if result is None:
107- result = "mail"
108- return result
109+ opt = self.get_custom_opt('post_commit_mailer')
110+ if opt:
111+ return opt
112+ else:
113+ result = self.config.get_user_option('post_commit_mailer')
114+ if result is None:
115+ result = "mail"
116+ return result
117
118 def _command_line(self):
119- cmd = [self.mailer(), '-s', self.subject(), '-a',
120+ cmd = [self.mailer(), '-s', self.subject(),
121 "From: " + self.from_address()]
122 to = self.to()
123 if isinstance(to, basestring):
124@@ -147,13 +160,31 @@
125 cmd.extend(to)
126 return cmd
127
128+ def get_custom_opt(self, option):
129+ url = "EMAIL:%s" % self.branch.base[7:]
130+ if url in self.parser:
131+ try:
132+ return self.parser[url][option]
133+ except:
134+ return None
135+ else:
136+ return None
137+
138 def to(self):
139 """What is the address the mail should go to."""
140- return self.config.get_user_option('post_commit_to')
141+ opt = self.get_custom_opt('post_commit_to')
142+ if opt:
143+ return opt
144+ else:
145+ return self.config.get_user_option('post_commit_to')
146
147 def url(self):
148 """What URL to display in the subject of the mail"""
149- url = self.config.get_user_option('post_commit_url')
150+ url = self.get_custom_opt('post_commit_url')
151+ if url is None:
152+ url = self.get_custom_opt('public_branch')
153+ if url is None:
154+ url = self.config.get_user_option('post_commit_url')
155 if url is None:
156 url = self.config.get_user_option('public_branch')
157 if url is None:
158@@ -162,10 +193,14 @@
159
160 def from_address(self):
161 """What address should I send from."""
162- result = self.config.get_user_option('post_commit_sender')
163- if result is None:
164- result = self.config.username()
165- return result
166+ opt = self.get_custom_opt('post_commit_sender')
167+ if opt:
168+ return opt
169+ else:
170+ result = self.config.get_user_option('post_commit_sender')
171+ if result is None:
172+ result = self.config.username()
173+ return result
174
175 def send(self):
176 """Send the email.
177@@ -232,18 +267,28 @@
178 self.diff_filename())
179
180 def should_send(self):
181- result = self.config.get_user_option('post_commit_difflimit')
182- post_commit_push_pull = self.config.get_user_option(
183- 'post_commit_push_pull') == 'True'
184- if post_commit_push_pull and self.op == 'commit':
185- # We will be called again with a push op, send the mail then.
186- return False
187- if not post_commit_push_pull and self.op != 'commit':
188- # Mailing on commit only, and this is a push/pull operation.
189- return False
190- return bool(self.to() and self.from_address())
191+ opt = self.get_custom_opt('post_commit_difflimit')
192+ if opt:
193+ return opt
194+ else:
195+ opt_push_pull = self.get_custom_opt('post_commit_push_pull')
196+ if not opt_push_pull:
197+ opt_push_pull = self.config.get_user_option('post_commit_push_pull')
198+
199+ result = self.config.get_user_option('post_commit_difflimit')
200+ post_commit_push_pull = opt_push_pull == 'True'
201+ if post_commit_push_pull and self.op == 'commit':
202+ # We will be called again with a push op, send the mail then.
203+ return False
204+ if not post_commit_push_pull and self.op != 'commit':
205+ # Mailing on commit only, and this is a push/pull operation.
206+ return False
207+ return bool(self.to() and self.from_address())
208
209 def send_maybe(self):
210+ config = GlobalConfig()
211+ parser = config._get_parser()
212+
213 if self.should_send():
214 self.send()
215

Subscribers

People subscribed via source and target branches

to all changes: