git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] gitk: alter the ordering for the "Tags and heads" view
@ 2016-03-09 18:18 Michael Rappazzo
  2016-03-09 18:18 ` [PATCH 1/2] " Michael Rappazzo
  2016-03-09 18:18 ` [PATCH 2/2] gitk: add an option to enable sorting the "Tags and heads" view by ref type Michael Rappazzo
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Rappazzo @ 2016-03-09 18:18 UTC (permalink / raw)
  To: paulus; +Cc: git, Michael Rappazzo

In a codebase with a large number of remote branches, the "Tags and heads"
view can split the local refs around the name "remotes".  I wanted to make
this view more useful as a quick view of the refs that are important to me
at the moment (the branches that I am actively working on).

This patch series adds a command line option to change the ordering of the
view (`--sort-refs-by-type`) which will sort the refs in the following
order:

    local refs
    remote refs which are tracked (upstream) by local refs
    remote refs
    tags
    other refs

Each of these lists is independently sorted before being put into the main
ref list.  Also note that the upstream refs are _not_ duplicated in the
remote refs list.

Michael Rappazzo (2):
  gitk: alter the ordering for the "Tags and heads" view
  gitk: add an option to enable sorting the "Tags and heads" view by ref
    type

 gitk | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 52 insertions(+), 7 deletions(-)

-- 
2.7.2

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] gitk: alter the ordering for the "Tags and heads" view
  2016-03-09 18:18 [PATCH 0/2] gitk: alter the ordering for the "Tags and heads" view Michael Rappazzo
@ 2016-03-09 18:18 ` Michael Rappazzo
  2016-03-09 18:18 ` [PATCH 2/2] gitk: add an option to enable sorting the "Tags and heads" view by ref type Michael Rappazzo
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Rappazzo @ 2016-03-09 18:18 UTC (permalink / raw)
  To: paulus; +Cc: git, Michael Rappazzo

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@gmail.com>
---
 gitk | 48 ++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 6 deletions(-)

diff --git a/gitk b/gitk
index 5f1255c..32fbc50 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"
+		    catch {set exists [exec git rev-parse --verify $locally_tracked_remote_ref]}
+		    if {$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]
+			}
+		    }
+		    set exists ""
+		}
 	    } 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.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] gitk: add an option to enable sorting the "Tags and heads" view by ref type
  2016-03-09 18:18 [PATCH 0/2] gitk: alter the ordering for the "Tags and heads" view Michael Rappazzo
  2016-03-09 18:18 ` [PATCH 1/2] " Michael Rappazzo
@ 2016-03-09 18:18 ` Michael Rappazzo
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Rappazzo @ 2016-03-09 18:18 UTC (permalink / raw)
  To: paulus; +Cc: git, Michael Rappazzo

Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
---
 gitk | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gitk b/gitk
index 32fbc50..c933233 100755
--- a/gitk
+++ b/gitk
@@ -158,6 +158,7 @@ proc parseviewargs {n arglist} {
     global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
     global vinlinediff
     global worddiff git_version
+    global sort_refs_by_type
 
     set vdatemode($n) 0
     set vmergeonly($n) 0
@@ -170,6 +171,7 @@ proc parseviewargs {n arglist} {
     set allknown 1
     set filtered 0
     set i -1
+    set sort_refs_by_type "0"
     foreach arg $arglist {
 	incr i
 	if {$nextisval} {
@@ -261,6 +263,9 @@ proc parseviewargs {n arglist} {
 	    "--no-replace-objects" {
 		set env(GIT_NO_REPLACE_OBJECTS) "1"
 	    }
+	    "--sort-refs-by-type" {
+		set sort_refs_by_type "1"
+	    }
 	    "-*" {
 		# Other flag arguments including -<n>
 		if {[string is digit -strict [string range $arg 1 end]]} {
@@ -9929,7 +9934,7 @@ proc reflistfilter_change {n1 n2 op} {
 }
 
 proc refill_reflist {} {
-    global reflist reflistfilter showrefstop headids tagids otherrefids
+    global reflist reflistfilter showrefstop headids tagids otherrefids sort_refs_by_type
     global curview
 
     if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
@@ -9998,6 +10003,10 @@ proc refill_reflist {} {
     }
     set otherrefs [lsort -index 0 $otherrefs]
     lappend refs {*}$localrefs {*}$locally_tracked_remote_refs {*}$remoterefs {*}$tagrefs {*}$otherrefs
+    if {$sort_refs_by_type ne "1"} {
+       set refs [lsort -index 0 $refs]
+    }
+
     if {$refs eq $reflist} return
 
     # Update the contents of $showrefstop.list according to the
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-09 18:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-09 18:18 [PATCH 0/2] gitk: alter the ordering for the "Tags and heads" view Michael Rappazzo
2016-03-09 18:18 ` [PATCH 1/2] " Michael Rappazzo
2016-03-09 18:18 ` [PATCH 2/2] gitk: add an option to enable sorting the "Tags and heads" view by ref type Michael Rappazzo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).