Rev 3255: Nicer default attachment names in bzr send (abentley) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Mar 7 21:35:47 GMT 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3255
revision-id:pqm at pqm.ubuntu.com-20080307213538-tsypuh27294se5h1
parent: pqm at pqm.ubuntu.com-20080306171300-yr2n8r9w4a4ettbo
parent: aaron at aaronbentley.com-20080307182128-p63rszbhci9jah92
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2008-03-07 21:35:38 +0000
message:
Nicer default attachment names in bzr send (abentley)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/mail_client.py mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
bzrlib/merge_directive.py merge_directive.py-20070228184838-ja62280spt1g7f4x-1
bzrlib/tests/test_merge_directive.py test_merge_directive-20070228184838-ja62280spt1g7f4x-2
------------------------------------------------------------
revno: 3251.2.2
revision-id:aaron at aaronbentley.com-20080307182128-p63rszbhci9jah92
parent: aaron at aaronbentley.com-20080307181713-gq97309x7jnbvs67
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: send-nick
timestamp: Fri 2008-03-07 18:21:28 +0000
message:
Fix bug in last revno handling
modified:
bzrlib/merge_directive.py merge_directive.py-20070228184838-ja62280spt1g7f4x-1
------------------------------------------------------------
revno: 3251.2.1
revision-id:aaron at aaronbentley.com-20080307181713-gq97309x7jnbvs67
parent: pqm at pqm.ubuntu.com-20080305131343-toq33x607hecihie
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: send-nick
timestamp: Fri 2008-03-07 18:17:13 +0000
message:
Use nick/revno-based names for merge directives
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/mail_client.py mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
bzrlib/merge_directive.py merge_directive.py-20070228184838-ja62280spt1g7f4x-1
bzrlib/tests/test_merge_directive.py test_merge_directive-20070228184838-ja62280spt1g7f4x-2
=== modified file 'NEWS'
--- a/NEWS 2008-03-06 17:13:00 +0000
+++ b/NEWS 2008-03-07 21:35:38 +0000
@@ -42,6 +42,9 @@
* Branch6.generate_revision_history is faster. (Aaron Bentley)
+ * Merge directives that are automatically attached to emails have nicer
+ filenames, based on branch-nick + revno. (Aaron Bentley)
+
BUGFIXES:
* Disable plink's interactive prompt for password.
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2008-03-04 16:53:03 +0000
+++ b/bzrlib/builtins.py 2008-03-07 21:35:38 +0000
@@ -4165,8 +4165,9 @@
else:
revision = branch.repository.get_revision(revision_id)
subject += revision.get_summary()
+ basename = directive.get_disk_name(branch)
mail_client.compose_merge_request(mail_to, subject,
- outfile.getvalue())
+ outfile.getvalue(), basename)
finally:
if output != '-':
outfile.close()
=== modified file 'bzrlib/mail_client.py'
--- a/bzrlib/mail_client.py 2007-11-28 17:27:10 +0000
+++ b/bzrlib/mail_client.py 2008-03-07 18:17:13 +0000
@@ -36,7 +36,7 @@
self.config = config
def compose(self, prompt, to, subject, attachment, mime_subtype,
- extension):
+ extension, basename=None):
"""Compose (and possibly send) an email message
Must be implemented by subclasses.
@@ -51,21 +51,25 @@
"plain", "x-patch", etc.
:param extension: The file extension associated with the attachment
type, e.g. ".patch"
+ :param basename: The name to use for the attachment, e.g.
+ "send-nick-3252"
"""
raise NotImplementedError
- def compose_merge_request(self, to, subject, directive):
+ def compose_merge_request(self, to, subject, directive, basename=None):
"""Compose (and possibly send) a merge request
:param to: The address to send the request to
:param subject: The subject line to use for the request
:param directive: A merge directive representing the merge request, as
a bytestring.
+ :param basename: The name to use for the attachment, e.g.
+ "send-nick-3252"
"""
prompt = self._get_merge_prompt("Please describe these changes:", to,
subject, directive)
self.compose(prompt, to, subject, directive,
- 'x-patch', '.patch')
+ 'x-patch', '.patch', basename)
def _get_merge_prompt(self, prompt, to, subject, attachment):
"""Generate a prompt string. Overridden by Editor.
@@ -90,7 +94,7 @@
attachment.decode('utf-8', 'replace')))
def compose(self, prompt, to, subject, attachment, mime_subtype,
- extension):
+ extension, basename=None):
"""See MailClient.compose"""
if not to:
raise errors.NoMailAddressSpecified()
@@ -118,17 +122,22 @@
return self._client_commands
def compose(self, prompt, to, subject, attachment, mime_subtype,
- extension):
+ extension, basename=None):
"""See MailClient.compose.
Writes the attachment to a temporary file, invokes _compose.
"""
- fd, pathname = tempfile.mkstemp(extension, 'bzr-mail-')
+ if basename is None:
+ basename = 'attachment'
+ pathname = tempfile.mkdtemp(prefix='bzr-mail-')
+ attach_path = osutils.pathjoin(pathname, basename + extension)
+ outfile = open(attach_path, 'wb')
try:
- os.write(fd, attachment)
+ outfile.write(attachment)
finally:
- os.close(fd)
- self._compose(prompt, to, subject, pathname, mime_subtype, extension)
+ outfile.close()
+ self._compose(prompt, to, subject, attach_path, mime_subtype,
+ extension)
def _compose(self, prompt, to, subject, attach_path, mime_subtype,
extension):
@@ -295,12 +304,12 @@
return XDGEmail(self.config)
def compose(self, prompt, to, subject, attachment, mime_subtype,
- extension):
+ extension, basename=None):
"""See MailClient.compose"""
try:
return self._mail_client().compose(prompt, to, subject,
attachment, mimie_subtype,
- extension)
+ extension, basename)
except errors.MailClientNotFound:
return Editor(self.config).compose(prompt, to, subject,
attachment, mimie_subtype, extension)
=== modified file 'bzrlib/merge_directive.py'
--- a/bzrlib/merge_directive.py 2007-12-14 04:44:58 +0000
+++ b/bzrlib/merge_directive.py 2008-03-07 18:21:28 +0000
@@ -136,6 +136,20 @@
return klass(revision_id, t.as_sha1(), time, timezone, target_branch,
patch, patch_type, public_branch, message)
+ def get_disk_name(self, branch):
+ """Generate a suitable basename for storing this directive on disk
+
+ :param branch: The Branch this merge directive was generated fro
+ :return: A string
+ """
+ revno, revision_id = branch.last_revision_info()
+ if self.revision_id == revision_id:
+ revno = [revno]
+ else:
+ revno = branch.get_revision_id_to_revno_map().get(self.revision_id,
+ ['merge'])
+ return '%s-%s' % (branch.nick, '.'.join(str(n) for n in revno))
+
@staticmethod
def _generate_diff(repository, revision_id, ancestor_id):
tree_1 = repository.revision_tree(ancestor_id)
=== modified file 'bzrlib/tests/test_merge_directive.py'
--- a/bzrlib/tests/test_merge_directive.py 2007-12-10 15:20:39 +0000
+++ b/bzrlib/tests/test_merge_directive.py 2008-03-07 18:17:13 +0000
@@ -372,6 +372,20 @@
tree_d.branch.base, patch_type='diff',
public_branch=tree_a.branch.base)
+ def test_disk_name(self):
+ tree_a, tree_b, branch_c = self.make_trees()
+ tree_a.branch.nick = 'fancy-name'
+ md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 120,
+ tree_b.branch.base)
+ self.assertEqual('fancy-name-2', md.get_disk_name(tree_a.branch))
+
+ def test_disk_name_old_revno(self):
+ tree_a, tree_b, branch_c = self.make_trees()
+ tree_a.branch.nick = 'fancy-name'
+ md = self.from_objects(tree_a.branch.repository, 'rev1', 500, 120,
+ tree_b.branch.base)
+ self.assertEqual('fancy-name-1', md.get_disk_name(tree_a.branch))
+
def test_generate_patch(self):
tree_a, tree_b, branch_c = self.make_trees()
md2 = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 120,
More information about the bazaar-commits
mailing list