[PATCH] Use the first line of commit message in "log --line"

Matthieu Moy Matthieu.Moy at imag.fr
Sun May 28 12:11:21 BST 2006


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

Thanks,

-- 
Matthieu

=== 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)

=== 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)
 
 

=== modified file 'bzrlib/tests/blackbox/test_too_much.py'
--- bzrlib/tests/blackbox/test_too_much.py                                                                                  
+++ bzrlib/tests/blackbox/test_too_much.py      
@@ -831,7 +831,8 @@
         max_width = terminal_width() - 1
         for line in log_out.splitlines():
             self.assert_(len(line) <= max_width, len(line))
-        self.assert_("this is my new commit and" in log_out)
+        self.assert_("this is my new commit and" not in log_out)
+        self.assert_("this is my new commit" in log_out)
 
         progress("file with spaces in name")
         mkdir('sub directory')






More information about the bazaar mailing list