@matheusbsbs / matheus-bagliano / commits / 79a060e477
Fork 0

git-gui: Maintain remote and source ref for tracking branches

In the next change I want to let the user create their local branch name to match the remote branch name, so that the existing push dialog can push the branch back up to the remote repository without needing to do any sort of remapping. To do that we need to know exactly what branch name the remote system is using. So all_tracking_branches returns a list of specifications, where each specification is itself a list of: - local ref name (destination we fetch into) - remote name (repository we fetch from) - remote ref name (source ref we fetch from) Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jul 4, 2007 at 01:10 UTC 79a060e477a743ad49508aec9a491fe1aa7d7c3b
2 files changed +60 -18
lib/choose_rev.tcl
+29 -6
@@ -11,6 +11,8 @@ field c_trck {}; # selected tracking branch
11 field c_tag {}; # selected tag
12 field c_expr {}; # current revision expression
13
14 +field trck_spec ; # array of specifications
15 +
16 constructor new {path {title {}}} {
17 global all_heads current_branch
18
@@ -37,19 +39,30 @@ constructor new {path {title {}}} {
39 trace add variable @c_head write [cb _select head]
40 }
41
40 - set all_trackings [all_tracking_branches]
41 - if {$all_trackings ne {}} {
42 - set c_trck [lindex $all_trackings 0]
42 + set trck_list [all_tracking_branches]
43 + if {$trck_list ne {}} {
44 + set nam [list]
45 + foreach spec $trck_list {
46 + set txt [lindex $spec 0]
47 + regsub ^refs/(heads/|remotes/)? $txt {} txt
48 + set trck_spec($txt) $spec
49 + lappend nam $txt
50 + }
51 + set nam [lsort -unique $nam]
52 +
53 radiobutton $w.trck_r \
54 -text {Tracking Branch:} \
55 -value trck \
56 -variable @revtype
47 - eval tk_optionMenu $w.trck_m @c_trck $all_trackings
57 + eval tk_optionMenu $w.trck_m @c_trck $nam
58 grid $w.trck_r $w.trck_m -sticky w
59 +
60 + set c_trck [lindex $nam 0]
61 if {$revtype eq {}} {
62 set revtype trck
63 }
64 trace add variable @c_trck write [cb _select trck]
65 + unset nam spec txt
66 }
67
68 set all_tags [load_all_tags]
@@ -115,12 +128,22 @@ method get {} {
128 }
129 }
130
131 +method get_expr {} {
132 + switch -- $revtype {
133 + head { return refs/heads/$c_head }
134 + trck { return [lindex $trck_spec($c_trck) 0] }
135 + tag { return refs/tags/$c_tag }
136 + expr { return $c_expr }
137 + none { return {} }
138 + default { error "unknown type of revision" }
139 + }
140 +}
141 +
142 method get_commit {} {
143 if {$revtype eq {none}} {
144 return {}
145 }
122 - set rev [get $this]
123 - return [git rev-parse --verify "${rev}^0"]
146 + return [git rev-parse --verify "[get_expr $this]^0"]
147 }
148
149 method _validate {d S} {
lib/remote.tcl
+31 -12
@@ -17,28 +17,41 @@ proc is_tracking_branch {name} {
17 proc all_tracking_branches {} {
18 global tracking_branches
19
20 - set all_trackings {}
21 - set cmd {}
20 + set all [list]
21 + set pat [list]
22 + set cmd [list]
23 +
24 foreach spec $tracking_branches {
23 - set name [lindex $spec 0]
24 - if {[string range $name end-1 end] eq {/*}} {
25 - lappend cmd [string range $name 0 end-2]
25 + set dst [lindex $spec 0]
26 + if {[string range $dst end-1 end] eq {/*}} {
27 + lappend pat $spec
28 + lappend cmd [string range $dst 0 end-2]
29 } else {
27 - regsub ^refs/(heads|remotes)/ $name {} name
28 - lappend all_trackings $name
30 + lappend all $spec
31 }
32 }
33
32 - if {$cmd ne {}} {
34 + if {$pat ne {}} {
35 set fd [open "| git for-each-ref --format=%(refname) $cmd" r]
34 - while {[gets $fd name] > 0} {
35 - regsub ^refs/(heads|remotes)/ $name {} name
36 - lappend all_trackings $name
36 + while {[gets $fd n] > 0} {
37 + foreach spec $pat {
38 + set dst [string range [lindex $spec 0] 0 end-2]
39 + set len [string length $dst]
40 + if {[string equal -length $len $dst $n]} {
41 + set src [string range [lindex $spec 2] 0 end-2]
42 + set spec [list \
43 + $n \
44 + [lindex $spec 1] \
45 + $src[string range $n $len end] \
46 + ]
47 + lappend all $spec
48 + }
49 + }
50 }
51 close $fd
52 }
53
41 - return [lsort -unique $all_trackings]
54 + return [lsort -index 0 -unique $all]
55 }
56
57 proc load_all_remotes {} {
@@ -65,6 +78,9 @@ proc load_all_remotes {} {
78 while {[gets $fd line] >= 0} {
79 if {![regexp {^Pull:[ ]*([^:]+):(.+)$} \
80 $line line src dst]} continue
81 + if {[string index $src 0] eq {+}} {
82 + set src [string range $src 1 end]
83 + }
84 if {![string equal -length 5 refs/ $src]} {
85 set src $rh_str$src
86 }
@@ -90,6 +106,9 @@ proc load_all_remotes {} {
106 }
107 foreach line $fl {
108 if {![regexp {^([^:]+):(.+)$} $line line src dst]} continue
109 + if {[string index $src 0] eq {+}} {
110 + set src [string range $src 1 end]
111 + }
112 if {![string equal -length 5 refs/ $src]} {
113 set src $rh_str$src
114 }