Skip to content

Commit 43c2507

Browse files
committed
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 <[email protected]>
1 parent 7eb3cb9 commit 43c2507

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

gitk

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,16 @@ proc parsecommit {id contents listed} {
341341
}
342342
}
343343
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]
346347
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]]
350354
}
351355
if {!$listed} {
352356
# git rev-list indents the comment by 4 spaces;
@@ -4157,7 +4161,11 @@ proc selectline {l isnew} {
41574161
dispneartags 1
41584162
}
41594163
$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}
41614169

41624170
$ctext tag delete Comments
41634171
$ctext tag remove found 1.0 end

0 commit comments

Comments
 (0)