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 <spearce@spearce.org>
Shawn O. Pearce committed
Jul 25, 2007 at 04:20 UTC
becafaace69980d2980802432e86e7873317a4b6
1 file changed
+33
-1
lib/choose_rev.tcl
+33
-1
@@ -17,6 +17,7 @@ field spec_head ; # list of all head specs
17
field spec_trck ; # list of all tracking branch specs
18
field spec_tag ; # list of all tag specs
19
field tip_data ; # array of tip commit info by refname
20
+field log_last ; # array of reflog date by refname
21
22
field tooltip_wm {} ; # Current tooltip toplevel, if open
23
field tooltip_t {} ; # Text widget in $tooltip_wm
@@ -518,7 +519,14 @@ method _open_tooltip {} {
519
set cmit [lindex $data 0]
520
}
521
521
- $tooltip_t insert end "[lindex $spec 0]\n"
522
+ $tooltip_t insert end [lindex $spec 0]
523
+ set last [_reflog_last $this [lindex $spec 1]]
524
+ if {$last ne {}} {
525
+ $tooltip_t insert end "\n"
526
+ $tooltip_t insert end "updated"
527
+ $tooltip_t insert end " $last"
528
+ }
529
+ $tooltip_t insert end "\n"
530
531
if {$tag ne {}} {
532
$tooltip_t insert end "\n"
@@ -553,6 +561,30 @@ method _open_tooltip {} {
561
_position_tooltip $this
562
}
563
564
+method _reflog_last {name} {
565
+ if {[info exists reflog_last($name)]} {
566
+ return reflog_last($name)
567
+ }
568
+
569
+ set last {}
570
+ if {[catch {set last [file mtime [gitdir $name]]}]
571
+ && ![catch {set g [open [gitdir logs $name] r]}]} {
572
+ fconfigure $g -translation binary
573
+ while {[gets $g line] >= 0} {
574
+ if {[regexp {> ([1-9][0-9]*) } $line line when]} {
575
+ set last $when
576
+ }
577
+ }
578
+ close $g
579
+ }
580
+
581
+ if {$last ne {}} {
582
+ set last [clock format $last -format {%a %b %e %H:%M:%S %Y}]
583
+ }
584
+ set reflog_last($name) $last
585
+ return $last
586
+}
587
+
588
method _position_tooltip {} {
589
set max_h [lindex [split [$tooltip_t index end] .] 0]
590
set max_w 0