summaryrefslogtreecommitdiff
path: root/lib/choose_rev.tcl
diff options
context:
space:
mode:
authorLibravatar Shawn O. Pearce <spearce@spearce.org>2007-07-08 18:40:56 -0400
committerLibravatar Shawn O. Pearce <spearce@spearce.org>2007-07-08 22:34:46 -0400
commitd41b43eb4c73044d0fff2057211fc78e4e7b2094 (patch)
treeebab56d146f4cafef1b1adf740949403329f71ea /lib/choose_rev.tcl
parentgit-gui: Refactor our ui_status_value update technique (diff)
downloadtgif-d41b43eb4c73044d0fff2057211fc78e4e7b2094.tar.xz
git-gui: Refactor branch switch to support detached head
This is a major rewrite of the way we perform switching between branches and the subsequent update of the working directory. Like core Git we now use a single code path to perform all changes: our new checkout_op class. We also use it for branch creation/update as it integrates the tracking branch fetch process along with a very basic merge (fast-forward and reset only currently). Because some users have literally hundreds of local branches we use the standard revision picker (with its branch filtering tool) to select the local branch, rather than keeping all of the local branches in the Branch menu. The branch menu listing out all of the available branches is simply not sane for those types of huge repositories. Users can now checkout a detached head by ticking off the option in the checkout dialog. This option is off by default for the obvious reason, but it can be easily enabled for any local branch by simply checking it. We also detach the head if any non local branch was selected, or if a revision expression was entered. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'lib/choose_rev.tcl')
-rw-r--r--lib/choose_rev.tcl43
1 files changed, 36 insertions, 7 deletions
diff --git a/lib/choose_rev.tcl b/lib/choose_rev.tcl
index e6af073595..7f2b4e603d 100644
--- a/lib/choose_rev.tcl
+++ b/lib/choose_rev.tcl
@@ -18,7 +18,7 @@ field spec_trck ; # list of all tracking branch specs
field spec_tag ; # list of all tag specs
constructor new {path {title {}}} {
- global all_heads current_branch
+ global current_branch is_detached
set w $path
@@ -29,6 +29,15 @@ constructor new {path {title {}}} {
}
bind $w <Destroy> [cb _delete %W]
+ if {$is_detached} {
+ radiobutton $w.detachedhead_r \
+ -anchor w \
+ -text {This Detached Checkout} \
+ -value HEAD \
+ -variable @revtype
+ grid $w.detachedhead_r -sticky we -padx {0 5} -columnspan 2
+ }
+
radiobutton $w.expr_r \
-text {Revision Expression:} \
-value expr \
@@ -86,14 +95,18 @@ constructor new {path {title {}}} {
grid $w.list -sticky nswe -padx {20 5} -columnspan 2
grid columnconfigure $w 1 -weight 1
- grid rowconfigure $w 2 -weight 1
+ if {$is_detached} {
+ grid rowconfigure $w 3 -weight 1
+ } else {
+ grid rowconfigure $w 2 -weight 1
+ }
trace add variable @revtype write [cb _select]
bind $w_filter <Key-Return> [list focus $w_list]\;break
bind $w_filter <Key-Down> [list focus $w_list]
set spec_head [list]
- foreach name $all_heads {
+ foreach name [load_all_heads] {
lappend spec_head [list $name refs/heads/$name]
}
@@ -109,7 +122,8 @@ constructor new {path {title {}}} {
lappend spec_tag [list $name refs/tags/$name]
}
- if {[llength $spec_head] > 0} { set revtype head
+ if {$is_detached} { set revtype HEAD
+ } elseif {[llength $spec_head] > 0} { set revtype head
} elseif {[llength $spec_trck] > 0} { set revtype trck
} elseif {[llength $spec_tag ] > 0} { set revtype tag
} else { set revtype expr
@@ -153,6 +167,7 @@ method get {} {
}
}
+ HEAD { return HEAD }
expr { return $c_expr }
none { return {} }
default { error "unknown type of revision" }
@@ -163,6 +178,20 @@ method pick_tracking_branch {} {
set revtype trck
}
+method focus_filter {} {
+ if {[$w_filter cget -state] eq {normal}} {
+ focus $w_filter
+ }
+}
+
+method get_local_branch {} {
+ if {$revtype eq {head}} {
+ return [_expr $this]
+ } else {
+ return {}
+ }
+}
+
method get_tracking_branch {} {
set i [$w_list curselection]
if {$i eq {} || $revtype ne {trck}} {
@@ -222,6 +251,7 @@ method _expr {} {
error "Revision expression is empty."
}
}
+ HEAD { return HEAD }
none { return {} }
default { error "unknown type of revision" }
}
@@ -249,9 +279,7 @@ method _filter {P} {
method _select {args} {
_rebuild $this $filter
- if {[$w_filter cget -state] eq {normal}} {
- focus $w_filter
- }
+ focus_filter $this
}
method _rebuild {pat} {
@@ -261,6 +289,7 @@ method _rebuild {pat} {
trck { set new $spec_trck }
tag { set new $spec_tag }
expr -
+ HEAD -
none {
set new [list]
set ste disabled