gitk: Cope with commit messages with carriage-returns and initial blank lines
In some repositories imported from other systems we can get carriage return characters in the commit message, which leads to a multi-line headline being displayed in the summary window, which looks bad. Also some commit messages start with one or more blank lines, which leads to an empty headline. This fixes these problems. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Sep 27, 2006 at 10:56 UTC
43c25074381dea404518318dacd360ed4f2abf3d
1 file changed
+14
-6
gitk
+14
-6
@@ -341,12 +341,16 @@ proc parsecommit {id contents listed} {
341
}
342
}
343
set headline {}
344
- # take the first line of the comment as the headline
345
- set i [string first "\n" $comment]
344
+ # take the first non-blank line of the comment as the headline
345
+ set headline [string trimleft $comment]
346
+ set i [string first "\n" $headline]
347
if {$i >= 0} {
347
- set headline [string trim [string range $comment 0 $i]]
348
- } else {
349
- set headline $comment
348
+ set headline [string range $headline 0 $i]
349
+ }
350
+ set headline [string trimright $headline]
351
+ set i [string first "\r" $headline]
352
+ if {$i >= 0} {
353
+ set headline [string trimright [string range $headline 0 $i]]
354
}
355
if {!$listed} {
356
# git rev-list indents the comment by 4 spaces;
@@ -4157,7 +4161,11 @@ proc selectline {l isnew} {
4161
dispneartags 1
4162
}
4163
$ctext insert end "\n"
4160
- appendwithlinks [lindex $info 5] {comment}
4164
+ set comment [lindex $info 5]
4165
+ if {[string first "\r" $comment] >= 0} {
4166
+ set comment [string map {"\r" "\n "} $comment]
4167
+ }
4168
+ appendwithlinks $comment {comment}
4169
4170
$ctext tag delete Comments
4171
$ctext tag remove found 1.0 end