@matheusbsbs / matheus-bagliano / commits / 66c75a5c9f
Fork 0

git-gui: Localize commit/author dates when displaying them

Currently the Git plumbing is not localized so it does not know how to output weekday and month names that conform to the user's locale preferences. This doesn't fit with the rest of git-gui's UI as some of our dates are formatted in Tcl and some are just read from the Git plumbing so dates aren't consistently presented. Since git-for-each-ref is presenting us formatted dates and it offers no way to change that setting even in git 1.5.3.1 we need to first do a parse of the text strings it produces, correct for timezones, then reformat the timestamp using Tcl's formatting routines. Not exactly what I wanted to do but it gets us consistently presented date strings in areas like the blame viewer and the revision picker mega-widget's tooltips. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Sep 10, 2007 at 01:54 UTC 66c75a5c9f7434d857d836440dc1c3046c59b5f3
3 files changed +60 -19
lib/blame.tcl
+4 -16
@@ -743,20 +743,14 @@ method _showcommit {cur_w lno} {
743 set author_time {}
744 catch {set author_name $header($cmit,author)}
745 catch {set author_email $header($cmit,author-mail)}
746 - catch {set author_time [clock format \
747 - $header($cmit,author-time) \
748 - -format {%Y-%m-%d %H:%M:%S}
749 - ]}
746 + catch {set author_time [format_date $header($cmit,author-time)]}
747
748 set committer_name {}
749 set committer_email {}
750 set committer_time {}
751 catch {set committer_name $header($cmit,committer)}
752 catch {set committer_email $header($cmit,committer-mail)}
756 - catch {set committer_time [clock format \
757 - $header($cmit,committer-time) \
758 - -format {%Y-%m-%d %H:%M:%S}
759 - ]}
753 + catch {set committer_time [format_date $header($cmit,committer-time)]}
754
755 if {[catch {set msg $header($cmit,message)}]} {
756 set msg {}
@@ -892,10 +886,7 @@ method _open_tooltip {cur_w} {
886 set author_time {}
887 catch {set author_name $header($cmit,author)}
888 catch {set summary $header($cmit,summary)}
895 - catch {set author_time [clock format \
896 - $header($cmit,author-time) \
897 - -format {%Y-%m-%d %H:%M:%S}
898 - ]}
889 + catch {set author_time [format_date $header($cmit,author-time)]}
890
891 $tooltip_t insert end "commit $cmit\n"
892 $tooltip_t insert end "$author_name $author_time\n"
@@ -914,10 +905,7 @@ method _open_tooltip {cur_w} {
905 set author_time {}
906 catch {set author_name $header($cmit,author)}
907 catch {set summary $header($cmit,summary)}
917 - catch {set author_time [clock format \
918 - $header($cmit,author-time) \
919 - -format {%Y-%m-%d %H:%M:%S}
920 - ]}
908 + catch {set author_time [foramt_date $header($cmit,author-time)]}
909
910 $tooltip_t insert end "Originally By:\n" section_header
911 $tooltip_t insert end "commit $cmit\n"
lib/choose_rev.tcl
+3 -3
@@ -133,13 +133,13 @@ constructor _new {path unmerged_only title} {
133 append fmt { %(objecttype)}
134 append fmt { %(objectname)}
135 append fmt { [concat %(taggername) %(authorname)]}
136 - append fmt { [concat %(taggerdate) %(authordate)]}
136 + append fmt { [reformat_date [concat %(taggerdate) %(authordate)]]}
137 append fmt { %(subject)}
138 append fmt {] [list}
139 append fmt { %(*objecttype)}
140 append fmt { %(*objectname)}
141 append fmt { %(*authorname)}
142 - append fmt { %(*authordate)}
142 + append fmt { [reformat_date %(*authordate)]}
143 append fmt { %(*subject)}
144 append fmt {]}
145 set all_refn [list]
@@ -583,7 +583,7 @@ method _reflog_last {name} {
583 }
584
585 if {$last ne {}} {
586 - set last [clock format $last -format {%a %b %e %H:%M:%S %Y}]
586 + set last [format_date $last]
587 }
588 set reflog_last($name) $last
589 return $last
lib/date.tcl new
+53
@@ -0,0 +1,53 @@
1 +# git-gui date processing support
2 +# Copyright (C) 2007 Shawn Pearce
3 +
4 +set git_month(Jan) 1
5 +set git_month(Feb) 2
6 +set git_month(Mar) 3
7 +set git_month(Apr) 4
8 +set git_month(May) 5
9 +set git_month(Jun) 6
10 +set git_month(Jul) 7
11 +set git_month(Aug) 8
12 +set git_month(Sep) 9
13 +set git_month(Oct) 10
14 +set git_month(Nov) 11
15 +set git_month(Dec) 12
16 +
17 +proc parse_git_date {s} {
18 + if {$s eq {}} {
19 + return {}
20 + }
21 +
22 + if {![regexp \
23 + {^... (...) (\d{1,2}) (\d\d):(\d\d):(\d\d) (\d{4}) ([+-]?)(\d\d)(\d\d)$} $s s \
24 + month day hr mm ss yr ew tz_h tz_m]} {
25 + error [mc "Invalid date from Git: %s" $s]
26 + }
27 +
28 + set s [clock scan [format {%4.4i%2.2i%2.2iT%2s%2s%2s} \
29 + $yr $::git_month($month) $day \
30 + $hr $mm $ss] \
31 + -gmt 1]
32 +
33 + regsub ^0 $tz_h {} tz_h
34 + regsub ^0 $tz_m {} tz_m
35 + switch -- $ew {
36 + - {set ew +}
37 + + {set ew -}
38 + {} {set ew -}
39 + }
40 +
41 + return [expr "$s $ew ($tz_h * 3600 + $tz_m * 60)"]
42 +}
43 +
44 +proc format_date {s} {
45 + if {$s eq {}} {
46 + return {}
47 + }
48 + return [clock format $s -format {%a %b %e %H:%M:%S %Y}]
49 +}
50 +
51 +proc reformat_date {s} {
52 + return [format_date [parse_git_date $s]]
53 +}