git-gui: prevent double UTF-8 conversion
Convert author's name and e-mail address from the UTF-8 (or any other) encoding in load_last_commit function the same way commit message is converted. Amending commits in git-gui without such conversion breaks UTF-8 strings. For example, "\305\201ukasz" (as written by git cat-file) becomes "\303\205\302\201ukasz" in an amended commit. Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Łukasz Stelmach committed
Dec 5, 2017 at 15:23 UTC
331450f18a7fd298ddd6b85cc5e8ed9dba09f9da
1 file changed
+9
-3
lib/commit.tcl
+9
-3
@@ -25,6 +25,8 @@ You are currently in the middle of a merge that has not been fully completed. Y
25
set msg {}
26
set parents [list]
27
if {[catch {
28
+ set name ""
29
+ set email ""
30
set fd [git_read cat-file commit $curHEAD]
31
fconfigure $fd -encoding binary -translation lf
32
# By default commits are assumed to be in utf-8
@@ -34,9 +36,7 @@ You are currently in the middle of a merge that has not been fully completed. Y
36
lappend parents [string range $line 7 end]
37
} elseif {[string match {encoding *} $line]} {
38
set enc [string tolower [string range $line 9 end]]
37
- } elseif {[regexp "author (.*)\\s<(.*)>\\s(\\d.*$)" $line all name email time]} {
38
- set commit_author [list name $name email $email date $time]
39
- }
39
+ } elseif {[regexp "author (.*)\\s<(.*)>\\s(\\d.*$)" $line all name email time]} { }
40
}
41
set msg [read $fd]
42
close $fd
@@ -44,7 +44,13 @@ You are currently in the middle of a merge that has not been fully completed. Y
44
set enc [tcl_encoding $enc]
45
if {$enc ne {}} {
46
set msg [encoding convertfrom $enc $msg]
47
+ set name [encoding convertfrom $enc $name]
48
+ set email [encoding convertfrom $enc $email]
49
}
50
+ if {$name ne {} && $email ne {}} {
51
+ set commit_author [list name $name email $email date $time]
52
+ }
53
+
54
set msg [string trim $msg]
55
} err]} {
56
error_popup [strcat [mc "Error loading commit data for amend:"] "\n\n$err"]