2007-05-08 05:35:48 +02:00
|
|
|
# git-gui remote management
|
|
|
|
# Copyright (C) 2006, 2007 Shawn Pearce
|
|
|
|
|
2007-07-04 06:15:41 +02:00
|
|
|
set some_heads_tracking 0; # assume not
|
|
|
|
|
2007-05-08 05:35:48 +02:00
|
|
|
proc is_tracking_branch {name} {
|
|
|
|
global tracking_branches
|
2007-07-04 06:15:41 +02:00
|
|
|
foreach spec $tracking_branches {
|
|
|
|
set t [lindex $spec 0]
|
|
|
|
if {$t eq $name || [string match $t $name]} {
|
2007-05-08 05:35:48 +02:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
proc all_tracking_branches {} {
|
|
|
|
global tracking_branches
|
|
|
|
|
|
|
|
set all_trackings {}
|
|
|
|
set cmd {}
|
2007-07-04 06:15:41 +02:00
|
|
|
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]
|
2007-05-08 05:35:48 +02:00
|
|
|
} else {
|
|
|
|
regsub ^refs/(heads|remotes)/ $name {} name
|
|
|
|
lappend all_trackings $name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
|
|
|
|
return [lsort -unique $all_trackings]
|
|
|
|
}
|
|
|
|
|
|
|
|
proc load_all_remotes {} {
|
|
|
|
global repo_config
|
2007-07-04 06:15:41 +02:00
|
|
|
global all_remotes tracking_branches some_heads_tracking
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-04 06:15:41 +02:00
|
|
|
set some_heads_tracking 0
|
2007-05-08 05:35:48 +02:00
|
|
|
set all_remotes [list]
|
2007-07-04 06:15:41 +02:00
|
|
|
set trck [list]
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-04 06:15:41 +02:00
|
|
|
set rh_str refs/heads/
|
|
|
|
set rh_len [string length $rh_str]
|
2007-05-08 05:35:48 +02:00
|
|
|
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} {
|
|
|
|
if {![regexp {^Pull:[ ]*([^:]+):(.+)$} \
|
|
|
|
$line line src dst]} continue
|
2007-07-04 06:15:41 +02:00
|
|
|
if {![string equal -length 5 refs/ $src]} {
|
|
|
|
set src $rh_str$src
|
|
|
|
}
|
|
|
|
if {![string equal -length 5 refs/ $dst]} {
|
|
|
|
set dst $rh_str$dst
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
2007-07-04 06:15:41 +02:00
|
|
|
if {[string equal -length $rh_len $rh_str $dst]} {
|
|
|
|
set some_heads_tracking 1
|
|
|
|
}
|
|
|
|
lappend trck [list $dst $name $src]
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach line [array names repo_config remote.*.url] {
|
|
|
|
if {![regexp ^remote\.(.*)\.url\$ $line line name]} continue
|
|
|
|
lappend all_remotes $name
|
|
|
|
|
|
|
|
if {[catch {set fl $repo_config(remote.$name.fetch)}]} {
|
|
|
|
set fl {}
|
|
|
|
}
|
|
|
|
foreach line $fl {
|
|
|
|
if {![regexp {^([^:]+):(.+)$} $line line src dst]} continue
|
2007-07-04 06:15:41 +02:00
|
|
|
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
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
2007-07-04 06:15:41 +02:00
|
|
|
lappend trck [list $dst $name $src]
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 06:15:41 +02:00
|
|
|
set tracking_branches [lsort -index 0 -unique $trck]
|
2007-05-08 05:35:48 +02:00
|
|
|
set all_remotes [lsort -unique $all_remotes]
|
|
|
|
}
|
|
|
|
|
|
|
|
proc populate_fetch_menu {} {
|
|
|
|
global all_remotes repo_config
|
|
|
|
|
|
|
|
set m .mbar.fetch
|
2007-05-28 17:04:59 +02:00
|
|
|
set prune_list [list]
|
2007-05-08 05:35:48 +02:00
|
|
|
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} {
|
2007-05-28 17:04:59 +02:00
|
|
|
lappend prune_list $r
|
2007-05-08 05:35:48 +02:00
|
|
|
$m add command \
|
|
|
|
-label "Fetch from $r..." \
|
|
|
|
-command [list fetch_from $r]
|
|
|
|
}
|
|
|
|
}
|
2007-05-28 17:04:59 +02:00
|
|
|
|
|
|
|
if {$prune_list ne {}} {
|
|
|
|
$m add separator
|
|
|
|
}
|
|
|
|
foreach r $prune_list {
|
|
|
|
$m add command \
|
|
|
|
-label "Prune from $r..." \
|
|
|
|
-command [list prune_from $r]
|
|
|
|
}
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|