40
40
_smtplib_implementation = SMTPConnection
42
42
def __init__(self, branch, revision_id, config, local_branch=None,
44
44
self.config = config
45
45
self.branch = branch
46
46
self.repository = branch.repository
47
47
if (local_branch is not None and
48
local_branch.repository.has_revision(revision_id)):
48
local_branch.repository.has_revision(revision_id)):
49
49
self.repository = local_branch.repository
50
50
self._revision_id = revision_id
51
51
self.revision = None
126
126
revid_new = self.revision.revision_id
127
127
if self.revision.parent_ids:
128
128
revid_old = self.revision.parent_ids[0]
129
tree_new, tree_old = self.repository.revision_trees((revid_new, revid_old))
129
tree_new, tree_old = self.repository.revision_trees(
130
(revid_new, revid_old))
131
132
# revision_trees() doesn't allow None or 'null:' to be passed as a
132
133
# revision. So we need to call revision_tree() twice.
140
141
diff_content = StringIO()
141
142
diff_options = self.config.get('post_commit_diffoptions')
142
143
show_diff_trees(tree_old, tree_new, diff_content, None, diff_options)
143
numlines = diff_content.getvalue().count('\n')+1
144
numlines = diff_content.getvalue().count('\n') + 1
144
145
if numlines <= difflimit:
145
146
return diff_content.getvalue()
269
271
def subject(self):
270
272
_subject = self.config.get('post_commit_subject')
271
273
if _subject is None:
272
_subject = ("Rev %d: %s in %s" %
274
self.revision.get_summary(),
274
_subject = ("Rev %d: %s in %s" %
276
self.revision.get_summary(),
276
278
return self._format(_subject)
278
280
def diff_filename(self):
282
284
opt_post_commit_body = Option("post_commit_body",
283
help="Body for post commit emails.")
285
help="Body for post commit emails.")
284
286
opt_post_commit_subject = Option("post_commit_subject",
285
help="Subject for post commit emails.")
287
help="Subject for post commit emails.")
286
288
opt_post_commit_log_format = Option('post_commit_log_format',
287
default='long', help="Log format for option.")
289
default='long', help="Log format for option.")
288
290
opt_post_commit_difflimit = Option('post_commit_difflimit',
289
default=1000, from_unicode=int_from_store,
290
help="Maximum number of lines in diffs.")
291
default=1000, from_unicode=int_from_store,
292
help="Maximum number of lines in diffs.")
291
293
opt_post_commit_push_pull = Option('post_commit_push_pull',
292
from_unicode=bool_from_store,
293
help="Whether to send emails on push and pull.")
294
from_unicode=bool_from_store,
295
help="Whether to send emails on push and pull.")
294
296
opt_post_commit_diffoptions = Option('post_commit_diffoptions',
295
help="Diff options to use.")
297
help="Diff options to use.")
296
298
opt_post_commit_sender = Option('post_commit_sender',
297
help='From address to use for emails.')
299
help='From address to use for emails.')
298
300
opt_post_commit_to = ListOption('post_commit_to',
299
help='Address to send commit emails to.')
301
help='Address to send commit emails to.')
300
302
opt_post_commit_mailer = Option('post_commit_mailer',
301
help='Mail client to use.', default='mail')
303
help='Mail client to use.', default='mail')
302
304
opt_post_commit_url = Option('post_commit_url',
303
help='URL to mention for branch in post commit messages.')
305
help='URL to mention for branch in post commit messages.')
304
306
opt_revision_mail_headers = ListOption('revision_mail_headers',
305
help="Extra revision headers.")
307
help="Extra revision headers.")