Re: [PATCH v2 3/3] gitk: Allow displaying time zones from author and commit timestamps

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH v2 3/3] gitk: Allow displaying time zones from author and commit timestamps

From: Andreas Schwab <hidden>
Date: 2016-06-15 22:51:21

Anders Kaseorg [off-list ref] writes:
+		catch {set savedTZ $env(TZ)}
                if {[info exits env(TZ)]} {set savedTZ $env(TZ)}

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

Re: [PATCH v2 3/3] gitk: Allow displaying time zones from author and commit timestamps

From: Anders Kaseorg <hidden>
Date: 2016-06-15 22:51:21

On Mon, 30 May 2011, Andreas Schwab wrote:
quoted
+		catch {set savedTZ $env(TZ)}
                if {[info exits env(TZ)]} {set savedTZ $env(TZ)}
That felt like a lot of noise just to save and restore an environment 
variable, but since I more or less learned Tcl just to write this patch, 
I’ll defer to your judgement of style here.

Thanks,
Anders

diff --git a/gitk b/gitk
index c77771e..6a4c8ed 100755
--- a/gitk
+++ b/gitk
@@ -11026,14 +11026,20 @@ proc formatdate {d} {
 	if {[string match {*%[zZ]*} $datetimeformat]} {
 	    if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} {
 		# Tcl < 8.5 does not support -timezone.  Emulate it by
-		# setting TZ=Unknown±NNNN.
+		# setting TZ=Unknown±NN:NN.
 		global env
-		catch {set savedTZ $env(TZ)}
+		if {[info exists env(TZ)]} {
+		    set savedTZ $env(TZ)
+		}
 		set zone [lindex $d 1]
 		set sign [string map {+ - - +} [string index $zone 0]]
 		set env(TZ) Unknown$sign[string range $zone 1 2]:[string range $zone 3 4]
 		set d [clock format [lindex $d 0] -format $datetimeformat]
-		if {[catch {set env(TZ) $savedTZ}]} {unset env(TZ)}
+		if {[info exists savedTZ]} {
+		    set env(TZ) $savedTZ
+		} else {
+		    unset env(TZ)
+		}
 	    }
 	} else {
 	    set d [clock format [lindex $d 0] -format $datetimeformat]

[PATCH v3 3/3] gitk: Allow displaying time zones from author and commit timestamps

From: Anders Kaseorg <hidden>
Date: 2016-06-15 22:51:21

Now gitk can be configured to display author and commit dates in their
original timezone, by putting %z into datetimeformat in ~/.gitk.

Signed-off-by: Anders Kaseorg <redacted>
---
 gitk |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/gitk b/gitk
index 8e15572..6a4c8ed 100755
--- a/gitk
+++ b/gitk
@@ -11021,7 +11021,29 @@ proc prefsok {} {
 proc formatdate {d} {
     global datetimeformat
     if {$d ne {}} {
-	set d [clock format [lindex $d 0] -format $datetimeformat]
+	# If $datetimeformat includes a timezone, display in the
+	# timezone of the argument.  Otherwise, display in local time.
+	if {[string match {*%[zZ]*} $datetimeformat]} {
+	    if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} {
+		# Tcl < 8.5 does not support -timezone.  Emulate it by
+		# setting TZ=Unknown±NN:NN.
+		global env
+		if {[info exists env(TZ)]} {
+		    set savedTZ $env(TZ)
+		}
+		set zone [lindex $d 1]
+		set sign [string map {+ - - +} [string index $zone 0]]
+		set env(TZ) Unknown$sign[string range $zone 1 2]:[string range $zone 3 4]
+		set d [clock format [lindex $d 0] -format $datetimeformat]
+		if {[info exists savedTZ]} {
+		    set env(TZ) $savedTZ
+		} else {
+		    unset env(TZ)
+		}
+	    }
+	} else {
+	    set d [clock format [lindex $d 0] -format $datetimeformat]
+	}
     }
     return $d
 }
-- 
1.7.5.3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help