[PATCH v2 1/2] gitk: alter the ordering for the "Tags and heads" view

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In the "Tags and heads" view, the list of refs is globally sorted.
Because of this, the list of local refs (heads) can be interrupted by the
list of remote refs.  This change re-orders the view to be: local refs,
remote refs tracked by local refs, remote refs, tags, and then other refs.

Signed-off-by: Michael Rappazzo <rappazzo@xxxxxxxxx>
---
 gitk | 48 ++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 6 deletions(-)

diff --git a/gitk b/gitk
index 5f1255c..d6d3136 100755
--- a/gitk
+++ b/gitk
@@ -9933,35 +9933,71 @@ proc refill_reflist {} {
     global curview
 
     if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
-    set refs {}
+    set localrefs {}
+    set remoterefs {}
+    set locally_tracked_remote_refs {}
+    set tagrefs {}
+    set otherrefs {}
     foreach n [array names headids] {
-	if {[string match $reflistfilter $n]} {
+	if {![string match "remotes/*" $n] && [string match $reflistfilter $n]} {
 	    if {[commitinview $headids($n) $curview]} {
-		lappend refs [list $n H]
+		lappend localrefs [list $n H]
+		catch {set remote_name [exec git config --get branch.$n.remote]}
+		if {$remote_name ne ""} {
+		    catch {set remote_ref [exec git config --get branch.$n.merge]}
+		    set remote_ref [string map {"refs/heads/" ""} $remote_ref]
+		    set locally_tracked_remote_ref "remotes/$remote_name/$remote_ref"
+		    set upstream_exists ""
+		    catch {set upstream_exists [exec git rev-parse --verify $locally_tracked_remote_ref]}
+		    if {$upstream_exists ne ""} {
+			if {[lsearch $locally_tracked_remote_refs [list $locally_tracked_remote_ref H]] < 0} {
+			    lappend locally_tracked_remote_refs [list $locally_tracked_remote_ref H]
+			}
+		    }
+		}
 	    } else {
 		interestedin $headids($n) {run refill_reflist}
 	    }
 	}
     }
+    set locally_tracked_remote_refs [lsort -index 0 $locally_tracked_remote_refs]
+    set localrefs [lsort -index 0 $localrefs]
+
+    foreach n [array names headids] {
+	if {[string match "remotes/*" $n] && [string match $reflistfilter $n]} {
+	    if {[commitinview $headids($n) $curview]} {
+		if {[lsearch $locally_tracked_remote_refs [list $n H]] < 0} {
+		    lappend remoterefs [list $n H]
+		}
+	    } else {
+		interestedin $headids($n) {run refill_reflist}
+	    }
+	}
+    }
+    set remoterefs [lsort -index 0 $remoterefs]
+
     foreach n [array names tagids] {
 	if {[string match $reflistfilter $n]} {
 	    if {[commitinview $tagids($n) $curview]} {
-		lappend refs [list $n T]
+		lappend tagrefs [list $n T]
 	    } else {
 		interestedin $tagids($n) {run refill_reflist}
 	    }
 	}
     }
+    set tagrefs [lsort -index 0 $tagrefs]
+
     foreach n [array names otherrefids] {
 	if {[string match $reflistfilter $n]} {
 	    if {[commitinview $otherrefids($n) $curview]} {
-		lappend refs [list $n o]
+		lappend otherrefs [list "$n" o]
 	    } else {
 		interestedin $otherrefids($n) {run refill_reflist}
 	    }
 	}
     }
-    set refs [lsort -index 0 $refs]
+    set otherrefs [lsort -index 0 $otherrefs]
+    lappend refs {*}$localrefs {*}$locally_tracked_remote_refs {*}$remoterefs {*}$tagrefs {*}$otherrefs
     if {$refs eq $reflist} return
 
     # Update the contents of $showrefstop.list according to the
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]