Rev 2305: [merge] James Westby allow passing a default message to commit in http://bzr.arbash-meinel.com/branches/bzr/jam-integration
John Arbash Meinel
john at arbash-meinel.com
Wed Feb 28 15:19:32 GMT 2007
At http://bzr.arbash-meinel.com/branches/bzr/jam-integration
------------------------------------------------------------
revno: 2305
revision-id: john at arbash-meinel.com-20070228151923-1s7oa2i2kk9u9ufo
parent: pqm at pqm.ubuntu.com-20070228065654-50cafaf8459ede53
parent: jw+debian at jameswestby.net-20070226214805-umfrbzkqnvvrna64
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: jam-integration
timestamp: Wed 2007-02-28 09:19:23 -0600
message:
[merge] James Westby allow passing a default message to commit
Also clean up NEWS a bit to reduce conflicts and conform to rST.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/msgeditor.py msgeditor.py-20050901111708-ef6d8de98f5d8f2f
bzrlib/tests/test_msgeditor.py test_msgeditor.py-20051202041359-920315ec6011ee51
------------------------------------------------------------
revno: 2258.3.4
merged: jw+debian at jameswestby.net-20070226214805-umfrbzkqnvvrna64
parent: jw+debian at jameswestby.net-20070205235821-09fbu7wbof8xc9k8
committer: James Westby <jw+debian at jameswestby.net>
branch nick: bzr.dev.editmsg
timestamp: Mon 2007-02-26 21:48:05 +0000
message:
Make the handling of the msgfile more sane.
* Close it in a finally block for more safety.
* Open it at the start and just write to it instead of building up the
message.
* Don't close the fileno from mkstemp, just convert it to a filehandle
straight away.
------------------------------------------------------------
revno: 2258.3.3
merged: jw+debian at jameswestby.net-20070205235821-09fbu7wbof8xc9k8
parent: jw+debian at jameswestby.net-20070204215850-64v3uwm4lc906nyy
committer: James Westby <jw+debian at jameswestby.net>
branch nick: bzr.dev.editmsg
timestamp: Mon 2007-02-05 23:58:21 +0000
message:
Refactor again from John and Alexander's comments.
------------------------------------------------------------
revno: 2258.3.2
merged: jw+debian at jameswestby.net-20070204215850-64v3uwm4lc906nyy
parent: jw+debian at jameswestby.net-20070203135827-15twzpv89r1uygks
committer: James Westby <jw+debian at jameswestby.net>
branch nick: bzr.dev.editmsg
timestamp: Sun 2007-02-04 21:58:50 +0000
message:
Allow an empty start message.
Following comments from Robert the start_message is now allowed to be empty.
The tests are also split out more.
------------------------------------------------------------
revno: 2258.3.1
merged: jw+debian at jameswestby.net-20070203135827-15twzpv89r1uygks
parent: pqm at pqm.ubuntu.com-20070202204950-910381483d737306
committer: James Westby <jw+debian at jameswestby.net>
branch nick: bzr.dev.editmsg
timestamp: Sat 2007-02-03 13:58:27 +0000
message:
Add a way to specify a template commit message.
Add start_message to the edit_commit_message function. This adds the text
above the separator so that it will not be removed after the user has edited.
Allows a template commit message to be specified. It however does nothing to
make it easy to actually hook in and set that.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2007-02-28 06:56:54 +0000
+++ b/NEWS 2007-02-28 15:19:23 +0000
@@ -99,9 +99,14 @@
This is expected to grow to cover a number of related uses mainly
related to bzr info. (Robert Collins)
- * Log formatters are now managed with a registry. log.register_formatter
- continues to work, but callers accessed the FORMATTERS dictionary
- directly will not.
+ * Log formatters are now managed with a registry.
+ ``log.register_formatter`` continues to work, but callers accessing
+ the FORMATTERS dictionary directly will not.
+
+ * Allow a start message to be passed to the ``edit_commit_message``
+ function. This will be placed in the message offered to the user
+ for editing above the separator. It allows a template commit message
+ to be used more easily. (James Westby)
* ``GPGStrategy.sign()`` will now raise ``BzrBadParameterUnicode`` if
you pass a Unicode string rather than an 8-bit string. Callers need
=== modified file 'bzrlib/msgeditor.py'
--- a/bzrlib/msgeditor.py 2006-11-11 19:25:25 +0000
+++ b/bzrlib/msgeditor.py 2007-02-26 21:48:05 +0000
@@ -80,7 +80,8 @@
{ 'bar' : '-' * 14, 'msg' : 'This line and the following will be ignored' }
-def edit_commit_message(infotext, ignoreline=DEFAULT_IGNORE_LINE):
+def edit_commit_message(infotext, ignoreline=DEFAULT_IGNORE_LINE,
+ start_message=None):
"""Let the user edit a commit message in a temp file.
This is run if they don't give a message or
@@ -90,21 +91,34 @@
Text to be displayed at bottom of message for
the user's reference; currently similar to
'bzr status'.
+
+ ignoreline:
+ The separator to use above the infotext.
+
+ start_message:
+ The text to place above the separator, if any. This will not be
+ removed from the message after the user has edited it.
"""
import tempfile
msgfilename = None
try:
tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr_log.', dir=u'.')
- msgfile = os.close(tmp_fileno)
- if infotext is not None and infotext != "":
- hasinfo = True
- msgfile = file(msgfilename, "w")
- msgfile.write("\n\n%s\n\n%s" % (ignoreline,
- infotext.encode(bzrlib.user_encoding, 'replace')))
+ msgfile = os.fdopen(tmp_fileno, 'w')
+ try:
+ if start_message is not None:
+ msgfile.write("%s\n" % start_message.encode(
+ bzrlib.user_encoding, 'replace'))
+
+ if infotext is not None and infotext != "":
+ hasinfo = True
+ msgfile.write("\n\n%s\n\n%s" % (ignoreline,
+ infotext.encode(bzrlib.user_encoding,
+ 'replace')))
+ else:
+ hasinfo = False
+ finally:
msgfile.close()
- else:
- hasinfo = False
if not _run_editor(msgfilename):
return None
=== modified file 'bzrlib/tests/test_msgeditor.py'
--- a/bzrlib/tests/test_msgeditor.py 2006-10-11 23:08:27 +0000
+++ b/bzrlib/tests/test_msgeditor.py 2007-02-04 21:58:50 +0000
@@ -80,9 +80,12 @@
self.assertEqual(True, bzrlib.msgeditor._run_editor(''),
'Unable to run dummy fake editor')
- def test_edit_commit_message(self):
- working_tree = self.make_uncommitted_tree()
- # make fake editor
+ def make_fake_editor(self):
+ """Set up environment so that an editor will be a known script.
+
+ Sets up BZR_EDITOR so that if an editor is spawned it will run a
+ script that just adds a known message to the start of the file.
+ """
f = file('fed.py', 'wb')
f.write('#!%s\n' % sys.executable)
f.write("""\
@@ -112,6 +115,10 @@
os.chmod('fed.py', 0755)
os.environ['BZR_EDITOR'] = './fed.py'
+ def test_edit_commit_message(self):
+ working_tree = self.make_uncommitted_tree()
+ self.make_fake_editor()
+
mutter('edit_commit_message without infotext')
self.assertEqual('test message from fed\n',
bzrlib.msgeditor.edit_commit_message(''))
@@ -120,6 +127,16 @@
self.assertEqual('test message from fed\n',
bzrlib.msgeditor.edit_commit_message(u'\u1234'))
+ def test_start_message(self):
+ self.make_uncommitted_tree()
+ self.make_fake_editor()
+ self.assertEqual('test message from fed\nstart message\n',
+ bzrlib.msgeditor.edit_commit_message('',
+ start_message='start message\n'))
+ self.assertEqual('test message from fed\n',
+ bzrlib.msgeditor.edit_commit_message('',
+ start_message=''))
+
def test_deleted_commit_message(self):
working_tree = self.make_uncommitted_tree()
More information about the bazaar-commits
mailing list