[PATCH] Use the first line of commit message in "log --line"
Robert Collins
robertc at robertcollins.net
Tue May 30 00:19:25 BST 2006
On Sun, 2006-05-28 at 13:11 +0200, Matthieu Moy wrote:
> Hi,
>
> I started a discussion some time ago about enforcing the convention in
> bzr that the first line of commit messages would be the patch summary,
> and the following would be the detailed log.
>
> There were two things to do for that:
>
> 1) Make "bzr log --line" show only the first line
>
> 2) Allow someone to enter a multi-line comment with -m "something".
> (without relying on the shell's multi-line support)
>
> The following path does this. For 2), I've simply allowed "\n" to be
> used as a line separator in the argument of -m.
>
> For example:
>
> moy at moy:/tmp/proj$ bzr commit -m "first line\nsecond line"
> added foo
> Committed revision 1.
> moy at moy:/tmp/proj$ bzr log --short
> 1 Matthieu Moy 2006-05-28
> first line
> second line
>
> moy at moy:/tmp/proj$ bzr log --line
> 1: Matthieu Moy 2006-05-28 first line
>
>
> It also does this (for free!) for merge summary in "bzr status".
>
> Martin agreed on the principle. Now looking for +1's
I agree with 1) for sure. The escaping for 2) is more problematic..
=== modified file
'bzrlib/builtins.py'
---
bzrlib/builtins.py
+++ bzrlib/builtins.py
@@ -1592,6 +1592,8 @@
if local and not tree.branch.get_bound_location():
raise errors.LocalRequiresBoundBranch()
+ if message:
+ message = message.replace("\\n", "\n")
if message is None and not file:
template = make_commit_message_template(tree,
selected_list)
message = edit_commit_message(template)
This change here is problematic. If I do:
bzr commit
(editor opens)
and I type in:
====
Change the handling of '\n' sequences so that we round trip correctly
with broken foobar servers.
====
With your change, bzr will record:
====
Change the handling of '
' sequences so that we round trip correctly with broken foobar servers.
====
Which is clearly wrong.
I think that using the shell to provide newlines in commit messages is
fine: we have pop up editors, the shell has full facilities, and we have
the ability to supply a preformatted file too.
I'm -1 on this part of the patch.
=== modified file 'bzrlib/log.py'
---
bzrlib/log.py
+++ bzrlib/log.py
@@ -431,6 +431,13 @@
return str
return str[:max_len-3]+'...'
+ def firstline(self, str):
+ idx = str.find("\n")
+ if idx != -1:
+ return str[:idx]
+ else:
+ return str
+
def date_string(self, rev):
from bzrlib.osutils import format_date
return format_date(rev.timestamp, rev.timezone or 0,
@@ -461,7 +468,7 @@
out.append("%d:" % revno)
out.append(self.truncate(self.short_committer(rev), 20))
out.append(self.date_string(rev))
- out.append(self.message(rev).replace('\n', ' '))
+ out.append(self.firstline(self.message(rev)))
return self.truncate(" ".join(out).rstrip('\n'), max_chars)
firstline seems a little overcomplicated. A simpler version:
def firstline(self, string):
# using a type name as a variable name is frowned upon which is why we
# use string, not str
return "".join(string.splitlines()[:1])
That said, firstline should not be defined here : it should be on rev so
you can go
rev.summary_line
or
rev.get_summary()
or some such.
With that change, +1 on this part of the patch.
Rob
--
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060530/a2298d9f/attachment.pgp
More information about the bazaar
mailing list