Anonymous committed becafaa

git-gui: Show ref last update times in revision chooser tooltips

If we can we now show the last modification date of a loose ref as
part of the tooltip information shown in the revision picker. This
gives the user an indication of when was the last time that the ref
was modified locally, and may especially be of interest when looking
at a tracking branch.

If we cannot find the loose ref file than we try to fallback on the
reflog and scan it for the date of the last record. We don't start
with the reflog however as scanning it backwards from the end is not
an easy thing to do in Tcl. So I'm being lazy here and just going
through the entire file, line by line. Since that is less efficient
than a single stat system call, its our fallback strategy.

Signed-off-by: Shawn O. Pearce <>

Comments (0)

Files changed (1)


 field spec_trck       ; # list of all tracking branch specs
 field spec_tag        ; # list of all tag specs
 field tip_data        ; # array of tip commit info by refname
+field log_last        ; # array of reflog date by refname
 field tooltip_wm        {} ; # Current tooltip toplevel, if open
 field tooltip_t         {} ; # Text widget in $tooltip_wm
 		set cmit [lindex $data 0]
-	$tooltip_t insert end "[lindex $spec 0]\n"
+	$tooltip_t insert end [lindex $spec 0]
+	set last [_reflog_last $this [lindex $spec 1]]
+	if {$last ne {}} {
+		$tooltip_t insert end "\n"
+		$tooltip_t insert end "updated"
+		$tooltip_t insert end " $last"
+	}
+	$tooltip_t insert end "\n"
 	if {$tag ne {}} {
 		$tooltip_t insert end "\n"
 	_position_tooltip $this
+method _reflog_last {name} {
+	if {[info exists reflog_last($name)]} {
+		return reflog_last($name)
+	}
+	set last {}
+	if {[catch {set last [file mtime [gitdir $name]]}]
+	&& ![catch {set g [open [gitdir logs $name] r]}]} {
+		fconfigure $g -translation binary
+		while {[gets $g line] >= 0} {
+			if {[regexp {> ([1-9][0-9]*) } $line line when]} {
+				set last $when
+			}
+		}
+		close $g
+	}
+	if {$last ne {}} {
+		set last [clock format $last -format {%a %b %e %H:%M:%S %Y}]
+	}
+	set reflog_last($name) $last
+	return $last
 method _position_tooltip {} {
 	set max_h [lindex [split [$tooltip_t index end] .] 0]
 	set max_w 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.