You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
212 lines
4.5 KiB
212 lines
4.5 KiB
18 years ago
|
# git-gui remote management
|
||
|
# Copyright (C) 2006, 2007 Shawn Pearce
|
||
|
|
||
18 years ago
|
set some_heads_tracking 0; # assume not
|
||
|
|
||
18 years ago
|
proc is_tracking_branch {name} {
|
||
|
global tracking_branches
|
||
18 years ago
|
foreach spec $tracking_branches {
|
||
|
set t [lindex $spec 0]
|
||
|
if {$t eq $name || [string match $t $name]} {
|
||
18 years ago
|
return 1
|
||
|
}
|
||
|
}
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
proc all_tracking_branches {} {
|
||
|
global tracking_branches
|
||
|
|
||
18 years ago
|
set all [list]
|
||
|
set pat [list]
|
||
|
set cmd [list]
|
||
|
|
||
18 years ago
|
foreach spec $tracking_branches {
|
||
18 years ago
|
set dst [lindex $spec 0]
|
||
|
if {[string range $dst end-1 end] eq {/*}} {
|
||
|
lappend pat $spec
|
||
|
lappend cmd [string range $dst 0 end-2]
|
||
18 years ago
|
} else {
|
||
18 years ago
|
lappend all $spec
|
||
18 years ago
|
}
|
||
|
}
|
||
|
|
||
18 years ago
|
if {$pat ne {}} {
|
||
18 years ago
|
set fd [eval git_read for-each-ref --format=%(refname) $cmd]
|
||
18 years ago
|
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
|
||
|
}
|
||
|
}
|
||
18 years ago
|
}
|
||
|
close $fd
|
||
|
}
|
||
|
|
||
18 years ago
|
return [lsort -index 0 -unique $all]
|
||
18 years ago
|
}
|
||
|
|
||
|
proc load_all_remotes {} {
|
||
|
global repo_config
|
||
18 years ago
|
global all_remotes tracking_branches some_heads_tracking
|
||
18 years ago
|
global remote_url
|
||
18 years ago
|
|
||
18 years ago
|
set some_heads_tracking 0
|
||
18 years ago
|
set all_remotes [list]
|
||
18 years ago
|
set trck [list]
|
||
18 years ago
|
|
||
18 years ago
|
set rh_str refs/heads/
|
||
|
set rh_len [string length $rh_str]
|
||
18 years ago
|
set rm_dir [gitdir remotes]
|
||
|
if {[file isdirectory $rm_dir]} {
|
||
|
set all_remotes [glob \
|
||
|
-types f \
|
||
|
-tails \
|
||
|
-nocomplain \
|
||
|
-directory $rm_dir *]
|
||
|
|
||
|
foreach name $all_remotes {
|
||
|
catch {
|
||
|
set fd [open [file join $rm_dir $name] r]
|
||
|
while {[gets $fd line] >= 0} {
|
||
18 years ago
|
if {[regexp {^URL:[ ]*(.+)$} $line line url]} {
|
||
|
set remote_url($name) $url
|
||
|
continue
|
||
|
}
|
||
18 years ago
|
if {![regexp {^Pull:[ ]*([^:]+):(.+)$} \
|
||
|
$line line src dst]} continue
|
||
18 years ago
|
if {[string index $src 0] eq {+}} {
|
||
|
set src [string range $src 1 end]
|
||
|
}
|
||
18 years ago
|
if {![string equal -length 5 refs/ $src]} {
|
||
|
set src $rh_str$src
|
||
|
}
|
||
|
if {![string equal -length 5 refs/ $dst]} {
|
||
|
set dst $rh_str$dst
|
||
18 years ago
|
}
|
||
18 years ago
|
if {[string equal -length $rh_len $rh_str $dst]} {
|
||
|
set some_heads_tracking 1
|
||
|
}
|
||
|
lappend trck [list $dst $name $src]
|
||
18 years ago
|
}
|
||
|
close $fd
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
foreach line [array names repo_config remote.*.url] {
|
||
|
if {![regexp ^remote\.(.*)\.url\$ $line line name]} continue
|
||
|
lappend all_remotes $name
|
||
18 years ago
|
set remote_url($name) $repo_config(remote.$name.url)
|
||
18 years ago
|
|
||
|
if {[catch {set fl $repo_config(remote.$name.fetch)}]} {
|
||
|
set fl {}
|
||
|
}
|
||
|
foreach line $fl {
|
||
|
if {![regexp {^([^:]+):(.+)$} $line line src dst]} continue
|
||
18 years ago
|
if {[string index $src 0] eq {+}} {
|
||
|
set src [string range $src 1 end]
|
||
|
}
|
||
18 years ago
|
if {![string equal -length 5 refs/ $src]} {
|
||
|
set src $rh_str$src
|
||
|
}
|
||
|
if {![string equal -length 5 refs/ $dst]} {
|
||
|
set dst $rh_str$dst
|
||
|
}
|
||
|
if {[string equal -length $rh_len $rh_str $dst]} {
|
||
|
set some_heads_tracking 1
|
||
18 years ago
|
}
|
||
18 years ago
|
lappend trck [list $dst $name $src]
|
||
18 years ago
|
}
|
||
|
}
|
||
|
|
||
18 years ago
|
set tracking_branches [lsort -index 0 -unique $trck]
|
||
18 years ago
|
set all_remotes [lsort -unique $all_remotes]
|
||
|
}
|
||
|
|
||
|
proc populate_fetch_menu {} {
|
||
|
global all_remotes repo_config
|
||
|
|
||
|
set m .mbar.fetch
|
||
18 years ago
|
set prune_list [list]
|
||
18 years ago
|
foreach r $all_remotes {
|
||
|
set enable 0
|
||
|
if {![catch {set a $repo_config(remote.$r.url)}]} {
|
||
|
if {![catch {set a $repo_config(remote.$r.fetch)}]} {
|
||
|
set enable 1
|
||
|
}
|
||
|
} else {
|
||
|
catch {
|
||
|
set fd [open [gitdir remotes $r] r]
|
||
|
while {[gets $fd n] >= 0} {
|
||
|
if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
|
||
|
set enable 1
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
close $fd
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if {$enable} {
|
||
18 years ago
|
lappend prune_list $r
|
||
18 years ago
|
$m add command \
|
||
|
-label "Fetch from $r..." \
|
||
|
-command [list fetch_from $r]
|
||
|
}
|
||
|
}
|
||
18 years ago
|
|
||
|
if {$prune_list ne {}} {
|
||
|
$m add separator
|
||
|
}
|
||
|
foreach r $prune_list {
|
||
|
$m add command \
|
||
|
-label "Prune from $r..." \
|
||
|
-command [list prune_from $r]
|
||
|
}
|
||
18 years ago
|
}
|
||
|
|
||
|
proc populate_push_menu {} {
|
||
|
global all_remotes repo_config
|
||
|
|
||
|
set m .mbar.push
|
||
|
set fast_count 0
|
||
|
foreach r $all_remotes {
|
||
|
set enable 0
|
||
|
if {![catch {set a $repo_config(remote.$r.url)}]} {
|
||
|
if {![catch {set a $repo_config(remote.$r.push)}]} {
|
||
|
set enable 1
|
||
|
}
|
||
|
} else {
|
||
|
catch {
|
||
|
set fd [open [gitdir remotes $r] r]
|
||
|
while {[gets $fd n] >= 0} {
|
||
|
if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
|
||
|
set enable 1
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
close $fd
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if {$enable} {
|
||
|
if {!$fast_count} {
|
||
|
$m add separator
|
||
|
}
|
||
|
$m add command \
|
||
|
-label "Push to $r..." \
|
||
|
-command [list push_to $r]
|
||
|
incr fast_count
|
||
|
}
|
||
|
}
|
||
|
}
|