X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fremote.tcl;h=0e86ddac0981fbb575a7dd5294ddaed29f7c3917;hb=7cce5b2cbc12a73eca3f62a885e9dbad17b250a5;hp=55a6dc33011701902f12c9af575074808bbcbcba;hpb=6f2a3fc812623bc82fb4997adb5a9a547b5dae1a;p=git.git diff --git a/lib/remote.tcl b/lib/remote.tcl index 55a6dc330..0e86ddac0 100644 --- a/lib/remote.tcl +++ b/lib/remote.tcl @@ -17,33 +17,47 @@ proc is_tracking_branch {name} { proc all_tracking_branches {} { global tracking_branches - set all_trackings {} - set cmd {} + set all [list] + set pat [list] + set cmd [list] + foreach spec $tracking_branches { - set name [lindex $spec 0] - if {[string range $name end-1 end] eq {/*}} { - lappend cmd [string range $name 0 end-2] + set dst [lindex $spec 0] + if {[string range $dst end-1 end] eq {/*}} { + lappend pat $spec + lappend cmd [string range $dst 0 end-2] } else { - regsub ^refs/(heads|remotes)/ $name {} name - lappend all_trackings $name + lappend all $spec } } - if {$cmd ne {}} { - set fd [open "| git for-each-ref --format=%(refname) $cmd" r] - while {[gets $fd name] > 0} { - regsub ^refs/(heads|remotes)/ $name {} name - lappend all_trackings $name + if {$pat ne {}} { + set fd [eval git_read for-each-ref --format=%(refname) $cmd] + while {[gets $fd n] > 0} { + foreach spec $pat { + set dst [string range [lindex $spec 0] 0 end-2] + set len [string length $dst] + if {[string equal -length $len $dst $n]} { + set src [string range [lindex $spec 2] 0 end-2] + set spec [list \ + $n \ + [lindex $spec 1] \ + $src[string range $n $len end] \ + ] + lappend all $spec + } + } } close $fd } - return [lsort -unique $all_trackings] + return [lsort -index 0 -unique $all] } proc load_all_remotes {} { global repo_config global all_remotes tracking_branches some_heads_tracking + global remote_url set some_heads_tracking 0 set all_remotes [list] @@ -63,8 +77,15 @@ proc load_all_remotes {} { catch { set fd [open [file join $rm_dir $name] r] while {[gets $fd line] >= 0} { + if {[regexp {^URL:[ ]*(.+)$} $line line url]} { + set remote_url($name) $url + continue + } if {![regexp {^Pull:[ ]*([^:]+):(.+)$} \ $line line src dst]} continue + if {[string index $src 0] eq {+}} { + set src [string range $src 1 end] + } if {![string equal -length 5 refs/ $src]} { set src $rh_str$src } @@ -84,12 +105,16 @@ proc load_all_remotes {} { foreach line [array names repo_config remote.*.url] { if {![regexp ^remote\.(.*)\.url\$ $line line name]} continue lappend all_remotes $name + set remote_url($name) $repo_config(remote.$name.url) if {[catch {set fl $repo_config(remote.$name.fetch)}]} { set fl {} } foreach line $fl { if {![regexp {^([^:]+):(.+)$} $line line src dst]} continue + if {[string index $src 0] eq {+}} { + set src [string range $src 1 end] + } if {![string equal -length 5 refs/ $src]} { set src $rh_str$src } @@ -110,8 +135,10 @@ proc load_all_remotes {} { proc populate_fetch_menu {} { global all_remotes repo_config - set m .mbar.fetch - set prune_list [list] + set remote_m .mbar.remote + set fetch_m $remote_m.fetch + set prune_m $remote_m.prune + foreach r $all_remotes { set enable 0 if {![catch {set a $repo_config(remote.$r.url)}]} { @@ -132,28 +159,34 @@ proc populate_fetch_menu {} { } if {$enable} { - lappend prune_list $r - $m add command \ - -label "Fetch from $r..." \ + if {![winfo exists $fetch_m]} { + menu $prune_m + $remote_m insert 0 cascade \ + -label [mc "Prune from"] \ + -menu $prune_m + + menu $fetch_m + $remote_m insert 0 cascade \ + -label [mc "Fetch from"] \ + -menu $fetch_m + } + + $fetch_m add command \ + -label $r \ -command [list fetch_from $r] + $prune_m add command \ + -label $r \ + -command [list prune_from $r] } } - - if {$prune_list ne {}} { - $m add separator - } - foreach r $prune_list { - $m add command \ - -label "Prune from $r..." \ - -command [list prune_from $r] - } } proc populate_push_menu {} { global all_remotes repo_config - set m .mbar.push - set fast_count 0 + set remote_m .mbar.remote + set push_m $remote_m.push + foreach r $all_remotes { set enable 0 if {![catch {set a $repo_config(remote.$r.url)}]} { @@ -174,13 +207,16 @@ proc populate_push_menu {} { } if {$enable} { - if {!$fast_count} { - $m add separator + if {![winfo exists $push_m]} { + menu $push_m + $remote_m insert 0 cascade \ + -label [mc "Push to"] \ + -menu $push_m } - $m add command \ - -label "Push to $r..." \ + + $push_m add command \ + -label $r \ -command [list push_to $r] - incr fast_count } } }