Browse Source
* commit 'git-gui/master': (36 commits) git-gui: Change prior tree SHA-1 verification to use git_read git-gui: Include a space in Cygwin shortcut command lines git-gui: Use sh.exe in Cygwin shortcuts git-gui: Paper bag fix for Cygwin shortcut creation git-gui: Improve the Windows and Mac OS X shortcut creators git-gui: Teach console widget to use git_read git-gui: Perform our own magic shbang detection on Windows git-gui: Treat `git version` as `git --version` git-gui: Assume unfound commands are known by git wrapper git-gui: Correct gitk installation location git-gui: Always use absolute path to all git executables git-gui: Show a progress meter for checking out files git-gui: Change the main window progress bar to use status_bar git-gui: Extract blame viewer status bar into mega-widget git-gui: Allow double-click in checkout dialog to start checkout git-gui: Default selection to first matching ref git-gui: Unabbreviate commit SHA-1s prior to display git-gui: Refactor branch switch to support detached head git-gui: Refactor our ui_status_value update technique git-gui: Better handling of detached HEAD ...maint

23 changed files with 2210 additions and 888 deletions
@ -0,0 +1,89 @@
@@ -0,0 +1,89 @@
|
||||
# git-gui branch checkout support |
||||
# Copyright (C) 2007 Shawn Pearce |
||||
|
||||
class branch_checkout { |
||||
|
||||
field w ; # widget path |
||||
field w_rev ; # mega-widget to pick the initial revision |
||||
|
||||
field opt_fetch 1; # refetch tracking branch if used? |
||||
field opt_detach 0; # force a detached head case? |
||||
|
||||
constructor dialog {} { |
||||
make_toplevel top w |
||||
wm title $top "[appname] ([reponame]): Checkout Branch" |
||||
if {$top ne {.}} { |
||||
wm geometry $top "+[winfo rootx .]+[winfo rooty .]" |
||||
} |
||||
|
||||
label $w.header -text {Checkout Branch} -font font_uibold |
||||
pack $w.header -side top -fill x |
||||
|
||||
frame $w.buttons |
||||
button $w.buttons.create -text Checkout \ |
||||
-default active \ |
||||
-command [cb _checkout] |
||||
pack $w.buttons.create -side right |
||||
button $w.buttons.cancel -text {Cancel} \ |
||||
-command [list destroy $w] |
||||
pack $w.buttons.cancel -side right -padx 5 |
||||
pack $w.buttons -side bottom -fill x -pady 10 -padx 10 |
||||
|
||||
set w_rev [::choose_rev::new $w.rev {Revision}] |
||||
$w_rev bind_listbox <Double-Button-1> [cb _checkout] |
||||
pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5 |
||||
|
||||
labelframe $w.options -text {Options} |
||||
|
||||
checkbutton $w.options.fetch \ |
||||
-text {Fetch Tracking Branch} \ |
||||
-variable @opt_fetch |
||||
pack $w.options.fetch -anchor nw |
||||
|
||||
checkbutton $w.options.detach \ |
||||
-text {Detach From Local Branch} \ |
||||
-variable @opt_detach |
||||
pack $w.options.detach -anchor nw |
||||
|
||||
pack $w.options -anchor nw -fill x -pady 5 -padx 5 |
||||
|
||||
bind $w <Visibility> [cb _visible] |
||||
bind $w <Key-Escape> [list destroy $w] |
||||
bind $w <Key-Return> [cb _checkout]\;break |
||||
tkwait window $w |
||||
} |
||||
|
||||
method _checkout {} { |
||||
set spec [$w_rev get_tracking_branch] |
||||
if {$spec ne {} && $opt_fetch} { |
||||
set new {} |
||||
} elseif {[catch {set new [$w_rev commit_or_die]}]} { |
||||
return |
||||
} |
||||
|
||||
if {$opt_detach} { |
||||
set ref {} |
||||
} else { |
||||
set ref [$w_rev get_local_branch] |
||||
} |
||||
|
||||
set co [::checkout_op::new [$w_rev get] $new $ref] |
||||
$co parent $w |
||||
$co enable_checkout 1 |
||||
if {$spec ne {} && $opt_fetch} { |
||||
$co enable_fetch $spec |
||||
} |
||||
|
||||
if {[$co run]} { |
||||
destroy $w |
||||
} else { |
||||
$w_rev focus_filter |
||||
} |
||||
} |
||||
|
||||
method _visible {} { |
||||
grab $w |
||||
$w_rev focus_filter |
||||
} |
||||
|
||||
} |
@ -0,0 +1,220 @@
@@ -0,0 +1,220 @@
|
||||
# git-gui branch create support |
||||
# Copyright (C) 2006, 2007 Shawn Pearce |
||||
|
||||
class branch_create { |
||||
|
||||
field w ; # widget path |
||||
field w_rev ; # mega-widget to pick the initial revision |
||||
field w_name ; # new branch name widget |
||||
|
||||
field name {}; # name of the branch the user has chosen |
||||
field name_type user; # type of branch name to use |
||||
|
||||
field opt_merge ff; # type of merge to apply to existing branch |
||||
field opt_checkout 1; # automatically checkout the new branch? |
||||
field opt_fetch 1; # refetch tracking branch if used? |
||||
field reset_ok 0; # did the user agree to reset? |
||||
|
||||
constructor dialog {} { |
||||
global repo_config |
||||
|
||||
make_toplevel top w |
||||
wm title $top "[appname] ([reponame]): Create Branch" |
||||
if {$top ne {.}} { |
||||
wm geometry $top "+[winfo rootx .]+[winfo rooty .]" |
||||
} |
||||
|
||||
label $w.header -text {Create New Branch} -font font_uibold |
||||
pack $w.header -side top -fill x |
||||
|
||||
frame $w.buttons |
||||
button $w.buttons.create -text Create \ |
||||
-default active \ |
||||
-command [cb _create] |
||||
pack $w.buttons.create -side right |
||||
button $w.buttons.cancel -text {Cancel} \ |
||||
-command [list destroy $w] |
||||
pack $w.buttons.cancel -side right -padx 5 |
||||
pack $w.buttons -side bottom -fill x -pady 10 -padx 10 |
||||
|
||||
labelframe $w.desc -text {Branch Name} |
||||
radiobutton $w.desc.name_r \ |
||||
-anchor w \ |
||||
-text {Name:} \ |
||||
-value user \ |
||||
-variable @name_type |
||||
set w_name $w.desc.name_t |
||||
entry $w_name \ |
||||
-borderwidth 1 \ |
||||
-relief sunken \ |
||||
-width 40 \ |
||||
-textvariable @name \ |
||||
-validate key \ |
||||
-validatecommand [cb _validate %d %S] |
||||
grid $w.desc.name_r $w_name -sticky we -padx {0 5} |
||||
|
||||
radiobutton $w.desc.match_r \ |
||||
-anchor w \ |
||||
-text {Match Tracking Branch Name} \ |
||||
-value match \ |
||||
-variable @name_type |
||||
grid $w.desc.match_r -sticky we -padx {0 5} -columnspan 2 |
||||
|
||||
grid columnconfigure $w.desc 1 -weight 1 |
||||
pack $w.desc -anchor nw -fill x -pady 5 -padx 5 |
||||
|
||||
set w_rev [::choose_rev::new $w.rev {Starting Revision}] |
||||
pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5 |
||||
|
||||
labelframe $w.options -text {Options} |
||||
|
||||
frame $w.options.merge |
||||
label $w.options.merge.l -text {Update Existing Branch:} |
||||
pack $w.options.merge.l -side left |
||||
radiobutton $w.options.merge.no \ |
||||
-text No \ |
||||
-value none \ |
||||
-variable @opt_merge |
||||
pack $w.options.merge.no -side left |
||||
radiobutton $w.options.merge.ff \ |
||||
-text {Fast Forward Only} \ |
||||
-value ff \ |
||||
-variable @opt_merge |
||||
pack $w.options.merge.ff -side left |
||||
radiobutton $w.options.merge.reset \ |
||||
-text {Reset} \ |
||||
-value reset \ |
||||
-variable @opt_merge |
||||
pack $w.options.merge.reset -side left |
||||
pack $w.options.merge -anchor nw |
||||
|
||||
checkbutton $w.options.fetch \ |
||||
-text {Fetch Tracking Branch} \ |
||||
-variable @opt_fetch |
||||
pack $w.options.fetch -anchor nw |
||||
|
||||
checkbutton $w.options.checkout \ |
||||
-text {Checkout After Creation} \ |
||||
-variable @opt_checkout |
||||
pack $w.options.checkout -anchor nw |
||||
pack $w.options -anchor nw -fill x -pady 5 -padx 5 |
||||
|
||||
trace add variable @name_type write [cb _select] |
||||
|
||||
set name $repo_config(gui.newbranchtemplate) |
||||
if {[is_config_true gui.matchtrackingbranch]} { |
||||
set name_type match |
||||
} |
||||
|
||||
bind $w <Visibility> [cb _visible] |
||||
bind $w <Key-Escape> [list destroy $w] |
||||
bind $w <Key-Return> [cb _create]\;break |
||||
tkwait window $w |
||||
} |
||||
|
||||
method _create {} { |
||||
global repo_config |
||||
global M1B |
||||
|
||||
set spec [$w_rev get_tracking_branch] |
||||
switch -- $name_type { |
||||
user { |
||||
set newbranch $name |
||||
} |
||||
match { |
||||
if {$spec eq {}} { |
||||
tk_messageBox \ |
||||
-icon error \ |
||||
-type ok \ |
||||
-title [wm title $w] \ |
||||
-parent $w \ |
||||
-message "Please select a tracking branch." |
||||
return |
||||
} |
||||
if {![regsub ^refs/heads/ [lindex $spec 2] {} newbranch]} { |
||||
tk_messageBox \ |
||||
-icon error \ |
||||
-type ok \ |
||||
-title [wm title $w] \ |
||||
-parent $w \ |
||||
-message "Tracking branch [$w get] is not a branch in the remote repository." |
||||
return |
||||
} |
||||
} |
||||
} |
||||
|
||||
if {$newbranch eq {} |
||||
|| $newbranch eq $repo_config(gui.newbranchtemplate)} { |
||||
tk_messageBox \ |
||||
-icon error \ |
||||
-type ok \ |
||||
-title [wm title $w] \ |
||||
-parent $w \ |
||||
-message "Please supply a branch name." |
||||
focus $w_name |
||||
return |
||||
} |
||||
|
||||
if {[catch {git check-ref-format "heads/$newbranch"}]} { |
||||
tk_messageBox \ |
||||
-icon error \ |
||||
-type ok \ |
||||
-title [wm title $w] \ |
||||
-parent $w \ |
||||
-message "'$newbranch' is not an acceptable branch name." |
||||
focus $w_name |
||||
return |
||||
} |
||||
|
||||
if {$spec ne {} && $opt_fetch} { |
||||
set new {} |
||||
} elseif {[catch {set new [$w_rev commit_or_die]}]} { |
||||
return |
||||
} |
||||
|
||||
set co [::checkout_op::new \ |
||||
[$w_rev get] \ |
||||
$new \ |
||||
refs/heads/$newbranch] |
||||
$co parent $w |
||||
$co enable_create 1 |
||||
$co enable_merge $opt_merge |
||||
$co enable_checkout $opt_checkout |
||||
if {$spec ne {} && $opt_fetch} { |
||||
$co enable_fetch $spec |
||||
} |
||||
|
||||
if {[$co run]} { |
||||
destroy $w |
||||
} else { |
||||
focus $w_name |
||||
} |
||||
} |
||||
|
||||
method _validate {d S} { |
||||
if {$d == 1} { |
||||
if {[regexp {[~^:?*\[\0- ]} $S]} { |
||||
return 0 |
||||
} |
||||
if {[string length $S] > 0} { |
||||
set name_type user |
||||
} |
||||
} |
||||
return 1 |
||||
} |
||||
|
||||
method _select {args} { |
||||
if {$name_type eq {match}} { |
||||
$w_rev pick_tracking_branch |
||||
} |
||||
} |
||||
|
||||
method _visible {} { |
||||
grab $w |
||||
if {$name_type eq {user}} { |
||||
$w_name icursor end |
||||
focus $w_name |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,149 @@
@@ -0,0 +1,149 @@
|
||||
# git-gui branch delete support |
||||
# Copyright (C) 2007 Shawn Pearce |
||||
|
||||
class branch_delete { |
||||
|
||||
field w ; # widget path |
||||
field w_heads ; # listbox of local head names |
||||
field w_check ; # revision picker for merge test |
||||
field w_delete ; # delete button |
||||
|
||||
constructor dialog {} { |
||||
global current_branch |
||||
|
||||
make_toplevel top w |
||||
wm title $top "[appname] ([reponame]): Delete Branch" |
||||
if {$top ne {.}} { |
||||
wm geometry $top "+[winfo rootx .]+[winfo rooty .]" |
||||
} |
||||
|
||||
label $w.header -text {Delete Local Branch} -font font_uibold |
||||
pack $w.header -side top -fill x |
||||
|
||||
frame $w.buttons |
||||
set w_delete $w.buttons.delete |
||||
button $w_delete \ |
||||
-text Delete \ |
||||
-default active \ |
||||
-state disabled \ |
||||
-command [cb _delete] |
||||
pack $w_delete -side right |
||||
button $w.buttons.cancel \ |
||||
-text {Cancel} \ |
||||
-command [list destroy $w] |
||||
pack $w.buttons.cancel -side right -padx 5 |
||||
pack $w.buttons -side bottom -fill x -pady 10 -padx 10 |
||||
|
||||
labelframe $w.list -text {Local Branches} |
||||
set w_heads $w.list.l |
||||
listbox $w_heads \ |
||||
-height 10 \ |
||||
-width 70 \ |
||||
-selectmode extended \ |
||||
-exportselection false \ |
||||
-yscrollcommand [list $w.list.sby set] |
||||
scrollbar $w.list.sby -command [list $w.list.l yview] |
||||
pack $w.list.sby -side right -fill y |
||||
pack $w.list.l -side left -fill both -expand 1 |
||||
pack $w.list -fill both -expand 1 -pady 5 -padx 5 |
||||
|
||||
set w_check [choose_rev::new \ |
||||
$w.check \ |
||||
{Delete Only If Merged Into} \ |
||||
] |
||||
$w_check none {Always (Do not perform merge test.)} |
||||
pack $w.check -anchor nw -fill x -pady 5 -padx 5 |
||||
|
||||
foreach h [load_all_heads] { |
||||
if {$h ne $current_branch} { |
||||
$w_heads insert end $h |
||||
} |
||||
} |
||||
|
||||
bind $w_heads <<ListboxSelect>> [cb _select] |
||||
bind $w <Visibility> " |
||||
grab $w |
||||
focus $w |
||||
" |
||||
bind $w <Key-Escape> [list destroy $w] |
||||
bind $w <Key-Return> [cb _delete]\;break |
||||
tkwait window $w |
||||
} |
||||
|
||||
method _select {} { |
||||
if {[$w_heads curselection] eq {}} { |
||||
$w_delete configure -state disabled |
||||
} else { |
||||
$w_delete configure -state normal |
||||
} |
||||
} |
||||
|
||||
method _delete {} { |
||||
if {[catch {set check_cmt [$w_check commit_or_die]}]} { |
||||
return |
||||
} |
||||
|
||||
set to_delete [list] |
||||
set not_merged [list] |
||||
foreach i [$w_heads curselection] { |
||||
set b [$w_heads get $i] |
||||
if {[catch { |
||||
set o [git rev-parse --verify "refs/heads/$b"] |
||||
}]} continue |
||||
if {$check_cmt ne {}} { |
||||
if {[catch {set m [git merge-base $o $check_cmt]}]} continue |
||||
if {$o ne $m} { |
||||
lappend not_merged $b |
||||
continue |
||||
} |
||||
} |
||||
lappend to_delete [list $b $o] |
||||
} |
||||
if {$not_merged ne {}} { |
||||
set msg "The following branches are not completely merged into [$w_check get]: |
||||
|
||||
- [join $not_merged "\n - "]" |
||||
tk_messageBox \ |
||||
-icon info \ |
||||
-type ok \ |
||||
-title [wm title $w] \ |
||||
-parent $w \ |
||||
-message $msg |
||||
} |
||||
if {$to_delete eq {}} return |
||||
if {$check_cmt eq {}} { |
||||
set msg {Recovering deleted branches is difficult. |
||||
|
||||
Delete the selected branches?} |
||||
if {[tk_messageBox \ |
||||
-icon warning \ |
||||
-type yesno \ |
||||
-title [wm title $w] \ |
||||
-parent $w \ |
||||
-message $msg] ne yes} { |
||||
return |
||||
} |
||||
} |
||||
|
||||
set failed {} |
||||
foreach i $to_delete { |
||||
set b [lindex $i 0] |
||||
set o [lindex $i 1] |
||||
if {[catch {git update-ref -d "refs/heads/$b" $o} err]} { |
||||
append failed " - $b: $err\n" |
||||
} |
||||
} |
||||
|
||||
if {$failed ne {}} { |
||||
tk_messageBox \ |
||||
-icon error \ |
||||
-type ok \ |
||||
-title [wm title $w] \ |
||||
-parent $w \ |
||||
-message "Failed to delete branches:\n$failed" |
||||
} |
||||
|
||||
destroy $w |
||||
} |
||||
|
||||
} |
@ -0,0 +1,579 @@
@@ -0,0 +1,579 @@
|
||||
# git-gui commit checkout support |
||||
# Copyright (C) 2007 Shawn Pearce |
||||
|
||||
class checkout_op { |
||||
|
||||
field w {}; # our window (if we have one) |
||||
field w_cons {}; # embedded console window object |
||||
|
||||
field new_expr ; # expression the user saw/thinks this is |
||||
field new_hash ; # commit SHA-1 we are switching to |
||||
field new_ref ; # ref we are updating/creating |
||||
|
||||
field parent_w .; # window that started us |
||||
field merge_type none; # type of merge to apply to existing branch |
||||
field fetch_spec {}; # refetch tracking branch if used? |
||||
field checkout 1; # actually checkout the branch? |
||||
field create 0; # create the branch if it doesn't exist? |
||||
|
||||
field reset_ok 0; # did the user agree to reset? |
||||
field fetch_ok 0; # did the fetch succeed? |
||||
|
||||
field readtree_d {}; # buffered output from read-tree |
||||
field update_old {}; # was the update-ref call deferred? |
||||
field reflog_msg {}; # log message for the update-ref call |
||||
|
||||
constructor new {expr hash {ref {}}} { |
||||
set new_expr $expr |
||||
set new_hash $hash |
||||
set new_ref $ref |
||||
|
||||
return $this |
||||
} |
||||
|
||||
method parent {path} { |
||||
set parent_w [winfo toplevel $path] |
||||
} |
||||
|
||||
method enable_merge {type} { |
||||
set merge_type $type |
||||
} |
||||
|
||||
method enable_fetch {spec} { |
||||
set fetch_spec $spec |
||||
} |
||||
|
||||
method enable_checkout {co} { |
||||
set checkout $co |
||||
} |
||||
|
||||
method enable_create {co} { |
||||
set create $co |
||||
} |
||||
|
||||
method run {} { |
||||
if {$fetch_spec ne {}} { |
||||
global M1B |
||||
|
||||
# We were asked to refresh a single tracking branch |
||||
# before we get to work. We should do that before we |
||||
# consider any ref updating. |
||||
# |
||||
set fetch_ok 0 |
||||
set l_trck [lindex $fetch_spec 0] |
||||
set remote [lindex $fetch_spec 1] |
||||
set r_head [lindex $fetch_spec 2] |
||||
regsub ^refs/heads/ $r_head {} r_name |
||||
|
||||
_toplevel $this {Refreshing Tracking Branch} |
||||
set w_cons [::console::embed \ |
||||
$w.console \ |
||||
"Fetching $r_name from $remote"] |
||||
pack $w.console -fill both -expand 1 |
||||
$w_cons exec \ |
||||
[list git fetch $remote +$r_head:$l_trck] \ |
||||
[cb _finish_fetch] |
||||
|
||||
bind $w <$M1B-Key-w> break |
||||
bind $w <$M1B-Key-W> break |
||||
bind $w <Visibility> " |
||||
[list grab $w] |
||||
[list focus $w] |
||||
" |
||||
wm protocol $w WM_DELETE_WINDOW [cb _noop] |
||||
tkwait window $w |
||||
|
||||
if {!$fetch_ok} { |
||||
delete_this |
||||
return 0 |
||||
} |
||||
} |
||||
|
||||
if {$new_ref ne {}} { |
||||
# If we have a ref we need to update it before we can |
||||
# proceed with a checkout (if one was enabled). |
||||
# |
||||
if {![_update_ref $this]} { |
||||
delete_this |
||||
return 0 |
||||
} |
||||
} |
||||
|
||||
if {$checkout} { |
||||
_checkout $this |
||||
return 1 |
||||
} |
||||
|
||||
delete_this |
||||
return 1 |
||||
} |
||||
|
||||
method _noop {} {} |
||||
|
||||
method _finish_fetch {ok} { |
||||
if {$ok} { |
||||
set l_trck [lindex $fetch_spec 0] |
||||
if {[catch {set new_hash [git rev-parse --verify "$l_trck^0"]} err]} { |
||||
set ok 0 |
||||
$w_cons insert "fatal: Cannot resolve $l_trck" |
||||
$w_cons insert $err |
||||
} |
||||
} |
||||
|
||||
$w_cons done $ok |
||||
set w_cons {} |
||||
wm protocol $w WM_DELETE_WINDOW {} |
||||
|
||||
if {$ok} { |
||||
destroy $w |
||||
set w {} |
||||
} else { |
||||
button $w.close -text Close -command [list destroy $w] |
||||
pack $w.close -side bottom -anchor e -padx 10 -pady 10 |
||||
} |
||||
|
||||
set fetch_ok $ok |
||||
} |
||||
|
||||
method _update_ref {} { |
||||
global null_sha1 current_branch |
||||
|
||||
set ref $new_ref |
||||
set new $new_hash |
||||
|
||||
set is_current 0 |
||||
set rh refs/heads/ |
||||
set rn [string length $rh] |
||||
if {[string equal -length $rn $rh $ref]} { |
||||
set newbranch [string range $ref $rn end] |
||||
if {$current_branch eq $newbranch} { |
||||
set is_current 1 |
||||
} |
||||
} else { |
||||
set newbranch $ref |
||||
} |
||||
|
||||
if {[catch {set cur [git rev-parse --verify "$ref^0"]}]} { |
||||
# Assume it does not exist, and that is what the error was. |
||||
# |
||||
if {!$create} { |
||||
_error $this "Branch '$newbranch' does not exist." |
||||
return 0 |
||||
} |
||||
|
||||
set reflog_msg "branch: Created from $new_expr" |
||||
set cur $null_sha1 |
||||
} elseif {$create && $merge_type eq {none}} { |
||||
# We were told to create it, but not do a merge. |
||||
# Bad. Name shouldn't have existed. |
||||
# |
||||
_error $this "Branch '$newbranch' already exists." |
||||
return 0 |
||||
} elseif {!$create && $merge_type eq {none}} { |
||||
# We aren't creating, it exists and we don't merge. |
||||
# We are probably just a simple branch switch. |
||||
# Use whatever value we just read. |
||||
# |
||||
set new $cur |
||||
set new_hash $cur |
||||
} elseif {$new eq $cur} { |
||||
# No merge would be required, don't compute anything. |
||||
# |
||||
} else { |
||||
set mrb {} |
||||
catch {set mrb [git merge-base $new $cur]} |
||||
switch -- $merge_type { |
||||
ff { |
||||
if {$mrb eq $new} { |
||||
# The current branch is actually newer. |
||||
# |
||||
set new $cur |
||||
} elseif {$mrb eq $cur} { |
||||
# The current branch is older. |
||||
# |
||||
set reflog_msg "merge $new_expr: Fast-forward" |
||||
} else { |
||||
_error $this "Branch '$newbranch' already exists.\n\nIt cannot fast-forward to $new_expr.\nA merge is required." |
||||
return 0 |
||||
} |
||||
} |
||||
reset { |
||||
if {$mrb eq $cur} { |
||||
# The current branch is older. |
||||
# |
||||
set reflog_msg "merge $new_expr: Fast-forward" |
||||
} else { |
||||
# The current branch will lose things. |
||||
# |
||||
if {[_confirm_reset $this $cur]} { |
||||
set reflog_msg "reset $new_expr" |
||||
} else { |
||||
return 0 |
||||
} |
||||
} |
||||
} |
||||
default { |
||||
_error $this "Only 'ff' and 'reset' merge is currently supported." |
||||
return 0 |
||||
} |
||||
} |
||||
} |
||||
|
||||
if {$new ne $cur} { |
||||
if {$is_current} { |
||||
# No so fast. We should defer this in case |
||||
# we cannot update the working directory. |
||||
# |
||||
set update_old $cur |
||||
return 1 |
||||
} |
||||
|
||||
if {[catch { |
||||
git update-ref -m $reflog_msg $ref $new $cur |
||||
} err]} { |
||||
_error $this "Failed to update '$newbranch'.\n\n$err" |
||||
return 0 |
||||
} |
||||
} |
||||
|
||||
return 1 |
||||
} |
||||
|
||||
method _checkout {} { |
||||
if {[lock_index checkout_op]} { |
||||
after idle [cb _start_checkout] |
||||
} else { |
||||
_error $this "Index is already locked." |
||||
delete_this |
||||
} |
||||
} |
||||
|
||||
method _start_checkout {} { |
||||
global HEAD commit_type |
||||
|
||||
# -- Our in memory state should match the repository. |
||||
# |
||||
repository_state curType curHEAD curMERGE_HEAD |
||||
if {[string match amend* $commit_type] |
||||
&& $curType eq {normal} |
||||
&& $curHEAD eq $HEAD} { |
||||
} elseif {$commit_type ne $curType || $HEAD ne $curHEAD} { |
||||
info_popup {Last scanned state does not match repository state. |
||||
|
||||
Another Git program has modified this repository since the last scan. A rescan must be performed before the current branch can be changed. |
||||
|
||||
The rescan will be automatically started now. |
||||
} |
||||
unlock_index |
||||
rescan ui_ready |
||||
delete_this |
||||
return |
||||
} |
||||
|
||||
if {[is_config_true gui.trustmtime]} { |
||||
_readtree $this |
||||
} else { |
||||
ui_status {Refreshing file status...} |
||||
set fd [git_read update-index \ |
||||
-q \ |
||||
--unmerged \ |
||||
--ignore-missing \ |
||||
--refresh \ |
||||
] |
||||
fconfigure $fd -blocking 0 -translation binary |
||||
fileevent $fd readable [cb _refresh_wait $fd] |
||||
} |
||||
} |
||||
|
||||
method _refresh_wait {fd} { |
||||
read $fd |
||||
if {[eof $fd]} { |
||||
close $fd |
||||
_readtree $this |
||||
} |
||||
} |
||||
|
||||
method _name {} { |
||||
if {$new_ref eq {}} { |
||||
return [string range $new_hash 0 7] |
||||
} |
||||
|
||||
set rh refs/heads/ |
||||
set rn [string length $rh] |
||||
if {[string equal -length $rn $rh $new_ref]} { |
||||
return [string range $new_ref $rn end] |
||||
} else { |
||||
return $new_ref |
||||
} |
||||
} |
||||
|
||||
method _readtree {} { |
||||
global HEAD |
||||
|
||||
set readtree_d {} |
||||
$::main_status start \ |
||||
"Updating working directory to '[_name $this]'..." \ |
||||
{files checked out} |
||||
|
||||
set fd [git_read --stderr read-tree \ |
||||
-m \ |
||||
-u \ |
||||
-v \ |
||||
--exclude-per-directory=.gitignore \ |
||||
$HEAD \ |
||||
$new_hash \ |
||||
] |
||||
fconfigure $fd -blocking 0 -translation binary |
||||
fileevent $fd readable [cb _readtree_wait $fd] |
||||
} |
||||
|
||||
method _readtree_wait {fd} { |
||||
global current_branch |
||||
|
||||
set buf [read $fd] |
||||
$::main_status update_meter $buf |
||||
append readtree_d $buf |
||||
|
||||
fconfigure $fd -blocking 1 |
||||
if {![eof $fd]} { |
||||
fconfigure $fd -blocking 0 |
||||
return |
||||
} |
||||
|
||||
if {[catch {close $fd}]} { |
||||
set err $readtree_d |
||||
regsub {^fatal: } $err {} err |
||||
$::main_status stop "Aborted checkout of '[_name $this]' (file level merging is required)." |
||||
warn_popup "File level merge required. |
||||
|
||||
$err |
||||
|
||||
Staying on branch '$current_branch'." |
||||
unlock_index |
||||
delete_this |
||||
return |
||||
} |
||||
|
||||
$::main_status stop |
||||
_after_readtree $this |
||||
} |
||||
|
||||
method _after_readtree {} { |
||||
global selected_commit_type commit_type HEAD MERGE_HEAD PARENT |
||||
global current_branch is_detached |
||||
global ui_comm |
||||
|
||||
set name [_name $this] |
||||
set log "checkout: moving" |
||||
if {!$is_detached} { |
||||
append log " from $current_branch" |
||||
} |
||||
|
||||
# -- Move/create HEAD as a symbolic ref. Core git does not |
||||
# even check for failure here, it Just Works(tm). If it |
||||
# doesn't we are in some really ugly state that is difficult |
||||
# to recover from within git-gui. |
||||
# |
||||
set rh refs/heads/ |
||||
set rn [string length $rh] |
||||
if {[string equal -length $rn $rh $new_ref]} { |
||||
set new_branch [string range $new_ref $rn end] |
||||
append log " to $new_branch" |
||||
|
||||
if {[catch { |
||||
git symbolic-ref -m $log HEAD $new_ref |
||||
} err]} { |
||||
_fatal $this $err |
||||
} |
||||
set current_branch $new_branch |
||||
set is_detached 0 |
||||
} else { |
||||
append log " to $new_expr" |
||||
|
||||
if {[catch { |
||||
_detach_HEAD $log $new_hash |
||||
} err]} { |
||||
_fatal $this $err |
||||
} |
||||
set current_branch HEAD |
||||
set is_detached 1 |
||||
} |
||||
|
||||
# -- We had to defer updating the branch itself until we |
||||
# knew the working directory would update. So now we |
||||
# need to finish that work. If it fails we're in big |
||||
# trouble. |
||||
# |
||||
if {$update_old ne {}} { |
||||
if {[catch { |
||||
git update-ref \ |
||||
-m $reflog_msg \ |
||||
$new_ref \ |
||||
$new_hash \ |
||||
$update_old |
||||
} err]} { |
||||
_fatal $this $err |
||||
} |
||||
} |
||||
|
||||
if {$is_detached} { |
||||
info_popup "You are no longer on a local branch. |
||||
|
||||
If you wanted to be on a branch, create one now starting from 'This Detached Checkout'." |
||||
} |
||||
|
||||
# -- Update our repository state. If we were previously in |
||||
# amend mode we need to toss the current buffer and do a |
||||
# full rescan to update our file lists. If we weren't in |
||||
# amend mode our file lists are accurate and we can avoid |
||||
# the rescan. |
||||
# |
||||
unlock_index |
||||
set selected_commit_type new |
||||
if {[string match amend* $commit_type]} { |
||||
$ui_comm delete 0.0 end |
||||
$ui_comm edit reset |
||||
$ui_comm edit modified false |
||||
rescan [list ui_status "Checked out '$name'."] |
||||
} else { |
||||
repository_state commit_type HEAD MERGE_HEAD |
||||
set PARENT $HEAD |
||||
ui_status "Checked out '$name'." |
||||
} |
||||
delete_this |
||||
} |
||||
|
||||
git-version proc _detach_HEAD {log new} { |
||||
>= 1.5.3 { |
||||
git update-ref --no-deref -m $log HEAD $new |
||||
} |
||||
default { |
||||
set p [gitdir HEAD] |
||||
file delete $p |
||||
set fd [open $p w] |
||||
fconfigure $fd -translation lf -encoding utf-8 |
||||
puts $fd $new |
||||
close $fd |
||||
} |
||||
} |
||||
|
||||
method _confirm_reset {cur} { |
||||
set reset_ok 0 |
||||
set name [_name $this] |
||||
set gitk [list do_gitk [list $cur ^$new_hash]] |
||||
|
||||
_toplevel $this {Confirm Branch Reset} |
||||
pack [label $w.msg1 \ |
||||
-anchor w \ |
||||
-justify left \ |
||||
-text "Resetting '$name' to $new_expr will lose the following commits:" \ |
||||
] -anchor w |
||||
|
||||
set list $w.list.l |
||||
frame $w.list |
||||
text $list \ |
||||
-font font_diff \ |
||||
-width 80 \ |
||||
-height 10 \ |
||||
-wrap none \ |
||||
-xscrollcommand [list $w.list.sbx set] \ |
||||
-yscrollcommand [list $w.list.sby set] |
||||
scrollbar $w.list.sbx -orient h -command [list $list xview] |
||||
scrollbar $w.list.sby -orient v -command [list $list yview] |
||||
pack $w.list.sbx -fill x -side bottom |
||||
pack $w.list.sby -fill y -side right |
||||
pack $list -fill both -expand 1 |
||||
pack $w.list -fill both -expand 1 -padx 5 -pady 5 |
||||
|
||||
pack [label $w.msg2 \ |
||||
-anchor w \ |
||||
-justify left \ |
||||
-text {Recovering lost commits may not be easy.} \ |
||||
] |
||||
pack [label $w.msg3 \ |
||||
-anchor w \ |
||||
-justify left \ |
||||
-text "Reset '$name'?" \ |
||||
] |
||||
|
||||
frame $w.buttons |
||||
button $w.buttons.visualize \ |
||||
-text Visualize \ |
||||
-command $gitk |
||||
pack $w.buttons.visualize -side left |
||||
button $w.buttons.reset \ |
||||
-text Reset \ |
||||
-command " |
||||
set @reset_ok 1 |
||||
destroy $w |
||||
" |
||||
pack $w.buttons.reset -side right |
||||
button $w.buttons.cancel \ |
||||
-default active \ |
||||
-text Cancel \ |
||||
-command [list destroy $w] |
||||
pack $w.buttons.cancel -side right -padx 5 |
||||
pack $w.buttons -side bottom -fill x -pady 10 -padx 10 |
||||
|
||||
set fd [git_read rev-list --pretty=oneline $cur ^$new_hash] |
||||
while {[gets $fd line] > 0} { |
||||
set abbr [string range $line 0 7] |
||||
set subj [string range $line 41 end] |
||||
$list insert end "$abbr $subj\n" |
||||
} |
||||
close $fd |
||||
$list configure -state disabled |
||||
|
||||
bind $w <Key-v> $gitk |
||||
bind $w <Visibility> " |
||||
grab $w |
||||
focus $w.buttons.cancel |
||||
" |
||||
bind $w <Key-Return> [list destroy $w] |
||||
bind $w <Key-Escape> [list destroy $w] |
||||
tkwait window $w |
||||
return $reset_ok |
||||
} |
||||
|
||||
method _error {msg} { |
||||
if {[winfo ismapped $parent_w]} { |
||||
set p $parent_w |
||||
} else { |
||||
set p . |
||||
} |
||||
|
||||
tk_messageBox \ |
||||
-icon error \ |
||||
-type ok \ |
||||
-title [wm title $p] \ |
||||
-parent $p \ |
||||
-message $msg |
||||
} |
||||
|
||||
method _toplevel {title} { |
||||
regsub -all {::} $this {__} w |
||||
set w .$w |
||||
|
||||
if {[winfo ismapped $parent_w]} { |
||||
set p $parent_w |
||||
} else { |
||||
set p . |
||||
} |
||||
|
||||
toplevel $w |
||||
wm title $w $title |
||||
wm geometry $w "+[winfo rootx $p]+[winfo rooty $p]" |
||||
} |
||||
|
||||
method _fatal {err} { |
||||
error_popup "Failed to set current branch. |
||||
|
||||
This working directory is only partially switched. We successfully updated your files, but failed to update an internal Git file. |
||||
|
||||
This should not have occurred. [appname] will now close and give up. |
||||
|
||||
$err" |
||||
exit 1 |
||||
} |
||||
|
||||
} |
@ -0,0 +1,367 @@
@@ -0,0 +1,367 @@
|
||||
# git-gui revision chooser |
||||
# Copyright (C) 2006, 2007 Shawn Pearce |
||||
|
||||
class choose_rev { |
||||
|
||||
image create photo ::choose_rev::img_find -data {R0lGODlhEAAQAIYAAPwCBCQmJDw+PBQSFAQCBMza3NTm5MTW1HyChOT29Ozq7MTq7Kze5Kzm7Oz6/NTy9Iza5GzGzKzS1Nzy9Nz29Kzq9HTGzHTK1Lza3AwKDLzu9JTi7HTW5GTCzITO1Mzq7Hza5FTK1ESyvHzKzKzW3DQyNDyqtDw6PIzW5HzGzAT+/Dw+RKyurNTOzMTGxMS+tJSGdATCxHRydLSqpLymnLSijBweHERCRNze3Pz69PTy9Oze1OTSxOTGrMSqlLy+vPTu5OzSvMymjNTGvNS+tMy2pMyunMSefAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAe4gACCAAECA4OIiAIEBQYHBAKJgwIICQoLDA0IkZIECQ4PCxARCwSSAxITFA8VEBYXGBmJAQYLGhUbHB0eH7KIGRIMEBAgISIjJKaIJQQLFxERIialkieUGigpKRoIBCqJKyyLBwvJAioEyoICLS4v6QQwMQQyLuqLli8zNDU2BCf1lN3AkUPHDh49fAQAAEnGD1MCCALZEaSHkIUMBQS8wWMIkSJGhBzBmFEGgRsBUqpMiSgdAD+BAAAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7} |
||||
|
||||
field w ; # our megawidget path |
||||
field w_list ; # list of currently filtered specs |
||||
field w_filter ; # filter entry for $w_list |
||||
|
||||
field c_expr {}; # current revision expression |
||||
field filter ; # current filter string |
||||
field revtype head; # type of revision chosen |
||||
field cur_specs [list]; # list of specs for $revtype |
||||
field spec_head ; # list of all head specs |
||||
field spec_trck ; # list of all tracking branch specs |
||||
field spec_tag ; # list of all tag specs |
||||
|
||||
constructor new {path {title {}}} { |
||||
global current_branch is_detached |
||||
|
||||
set w $path |
||||
|
||||
if {$title ne {}} { |
||||
labelframe $w -text $title |
||||
} else { |
||||
frame $w |
||||
} |
||||
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 \ |
||||
-variable @revtype |
||||
entry $w.expr_t \ |
||||
-borderwidth 1 \ |
||||
-relief sunken \ |
||||
-width 50 \ |
||||
-textvariable @c_expr \ |
||||
-validate key \ |
||||
-validatecommand [cb _validate %d %S] |
||||
grid $w.expr_r $w.expr_t -sticky we -padx {0 5} |
||||
|
||||
frame $w.types |
||||
radiobutton $w.types.head_r \ |
||||
-text {Local Branch} \ |
||||
-value head \ |
||||
-variable @revtype |
||||
pack $w.types.head_r -side left |
||||
radiobutton $w.types.trck_r \ |
||||
-text {Tracking Branch} \ |
||||
-value trck \ |
||||
-variable @revtype |
||||
pack $w.types.trck_r -side left |
||||
radiobutton $w.types.tag_r \ |
||||
-text {Tag} \ |
||||
-value tag \ |
||||
-variable @revtype |
||||
pack $w.types.tag_r -side left |
||||
set w_filter $w.types.filter |
||||
entry $w_filter \ |
||||
-borderwidth 1 \ |
||||
-relief sunken \ |
||||
-width 12 \ |
||||
-textvariable @filter \ |
||||
-validate key \ |
||||
-validatecommand [cb _filter %P] |
||||
pack $w_filter -side right |
||||
pack [label $w.types.filter_icon \ |
||||
-image ::choose_rev::img_find \ |
||||
] -side right |
||||
grid $w.types -sticky we -padx {0 5} -columnspan 2 |
||||
|
||||
frame $w.list |
||||
set w_list $w.list.l |
||||
listbox $w_list \ |
||||
-font font_diff \ |
||||
-width 50 \ |
||||
-height 5 \ |
||||
-selectmode browse \ |
||||
-exportselection false \ |
||||
-xscrollcommand [cb _sb_set $w.list.sbx h] \ |
||||
-yscrollcommand [cb _sb_set $w.list.sby v] |
||||
pack $w_list -fill both -expand 1 |
||||
grid $w.list -sticky nswe -padx {20 5} -columnspan 2 |
||||
|
||||
grid columnconfigure $w 1 -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 [load_all_heads] { |
||||
lappend spec_head [list $name refs/heads/$name] |
||||
} |
||||
|
||||
set spec_trck [list] |
||||
foreach spec [all_tracking_branches] { |
||||
set name [lindex $spec 0] |
||||
regsub ^refs/(heads|remotes)/ $name {} name |
||||
lappend spec_trck [concat $name $spec] |
||||
} |
||||
|
||||
set spec_tag [list] |
||||
foreach name [load_all_tags] { |
||||
lappend spec_tag [list $name refs/tags/$name] |
||||
} |
||||
|
||||
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 |
||||
} |
||||
|
||||
if {$revtype eq {head} && $current_branch ne {}} { |
||||
set i 0 |
||||
foreach spec $spec_head { |
||||
if {[lindex $spec 0] eq $current_branch} { |
||||
$w_list selection clear 0 end |
||||
$w_list selection set $i |
||||
break |
||||
} |
||||
incr i |
||||
} |
||||
} |
||||
|
||||
return $this |
||||
} |
||||
|
||||
method none {text} { |
||||
if {![winfo exists $w.none_r]} { |
||||
radiobutton $w.none_r \ |
||||
-anchor w \ |
||||
-value none \ |
||||
-variable @revtype |
||||
grid $w.none_r -sticky we -padx {0 5} -columnspan 2 |
||||
} |
||||
$w.none_r configure -text $text |
||||
} |
||||
|
||||
method get {} { |
||||
switch -- $revtype { |
||||
head - |
||||
trck - |
||||
tag { |
||||
set i [$w_list curselection] |
||||
if {$i ne {}} { |
||||
return [lindex $cur_specs $i 0] |
||||
} else { |
||||
return {} |
||||
} |
||||
} |
||||
|
||||
HEAD { return HEAD } |
||||
expr { return $c_expr } |
||||
none { return {} } |
||||
default { error "unknown type of revision" } |
||||
} |
||||
} |
||||
|
||||
method pick_tracking_branch {} { |
||||
set revtype trck |
||||
} |
||||
|
||||
method focus_filter {} { |
||||
if {[$w_filter cget -state] eq {normal}} { |
||||
focus $w_filter |
||||
} |
||||
} |
||||
|
||||
method bind_listbox {event script} { |
||||
bind $w_list $event $script |
||||
} |
||||
|
||||
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}} { |
||||
return {} |
||||
} |
||||
return [lrange [lindex $cur_specs $i] 1 end] |
||||
} |
||||
|
||||
method get_commit {} { |
||||
set e [_expr $this] |
||||
if {$e eq {}} { |
||||
return {} |
||||
} |
||||
return [git rev-parse --verify "$e^0"] |
||||
} |
||||
|
||||
method commit_or_die {} { |
||||
if {[catch {set new [get_commit $this]} err]} { |
||||
|
||||
# Cleanup the not-so-friendly error from rev-parse. |
||||
# |
||||
regsub {^fatal:\s*} $err {} err |
||||
if {$err eq {Needed a single revision}} { |
||||
set err {} |
||||
} |
||||
|
||||
set top [winfo toplevel $w] |
||||
set msg "Invalid revision: [get $this]\n\n$err" |
||||
tk_messageBox \ |
||||
-icon error \ |
||||
-type ok \ |
||||
-title [wm title $top] \ |
||||
-parent $top \ |
||||
-message $msg |
||||
error $msg |
||||
} |
||||
return $new |
||||
} |
||||
|
||||
method _expr {} { |
||||
switch -- $revtype { |
||||
head - |
||||
trck - |
||||
tag { |
||||
set i [$w_list curselection] |
||||
if {$i ne {}} { |
||||
return [lindex $cur_specs $i 1] |
||||
} else { |
||||
error "No revision selected." |
||||
} |
||||
} |
||||
|
||||
expr { |
||||
if {$c_expr ne {}} { |
||||
return $c_expr |
||||
} else { |
||||
error "Revision expression is empty." |
||||
} |
||||
} |
||||
HEAD { return HEAD } |
||||
none { return {} } |
||||
default { error "unknown type of revision" } |
||||
} |
||||
} |
||||
|
||||
method _validate {d S} { |
||||
if {$d == 1} { |
||||
if {[regexp {\s} $S]} { |
||||
return 0 |
||||
} |
||||
if {[string length $S] > 0} { |
||||
set revtype expr |
||||
} |
||||
} |
||||
return 1 |
||||
} |
||||
|
||||
method _filter {P} { |
||||
if {[regexp {\s} $P]} { |
||||
return 0 |
||||
} |
||||
_rebuild $this $P |
||||
return 1 |
||||
} |
||||
|
||||
method _select {args} { |
||||
_rebuild $this $filter |
||||
focus_filter $this |
||||
} |
||||
|
||||
method _rebuild {pat} { |
||||
set ste normal |
||||
switch -- $revtype { |
||||
head { set new $spec_head } |
||||
trck { set new $spec_trck } |
||||
tag { set new $spec_tag } |
||||
expr - |
||||
HEAD - |
||||
none { |
||||
set new [list] |
||||
set ste disabled |
||||
} |
||||
} |
||||
|
||||
if {[$w_list cget -state] eq {disabled}} { |
||||
$w_list configure -state normal |
||||
} |
||||
$w_list delete 0 end |
||||
|
||||
if {$pat ne {}} { |
||||
set pat *${pat}* |
||||
} |
||||
set cur_specs [list] |
||||
foreach spec $new { |
||||
set txt [lindex $spec 0] |
||||
if {$pat eq {} || [string match $pat $txt]} { |
||||
lappend cur_specs $spec |
||||
$w_list insert end $txt |
||||
} |
||||
} |
||||
if {$cur_specs ne {}} { |
||||
$w_list selection clear 0 end |
||||
$w_list selection set 0 |
||||
} |
||||
|
||||
if {[$w_filter cget -state] ne $ste} { |
||||
$w_list configure -state $ste |
||||
$w_filter configure -state $ste |
||||
} |
||||
} |
||||
|
||||
method _delete {current} { |
||||
if {$current eq $w} { |
||||
delete_this |
||||
} |
||||
} |
||||
|
||||
method _sb_set {sb orient first last} { |
||||
set old_focus [focus -lastfor $w] |
||||
|
||||
if {$first == 0 && $last == 1} { |
||||
if {[winfo exists $sb]} { |
||||
destroy $sb |
||||
if {$old_focus ne {}} { |
||||
update |
||||
focus $old_focus |
||||
} |
||||
} |
||||
return |
||||
} |
||||
|
||||
if {![winfo exists $sb]} { |
||||
if {$orient eq {h}} { |
||||
scrollbar $sb -orient h -command [list $w_list xview] |
||||
pack $sb -fill x -side bottom -before $w_list |
||||
} else { |
||||
scrollbar $sb -orient v -command [list $w_list yview] |
||||
pack $sb -fill y -side right -before $w_list |
||||
} |
||||
if {$old_focus ne {}} { |
||||
update |
||||
focus $old_focus |
||||
} |
||||
} |
||||
$sb set $first $last |
||||
} |
||||
|
||||
} |
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
# git-gui status bar mega-widget |
||||
# Copyright (C) 2007 Shawn Pearce |
||||
|
||||
class status_bar { |
||||
|
||||
field w ; # our own window path |
||||
field w_l ; # text widget we draw messages into |
||||
field w_c ; # canvas we draw a progress bar into |
||||
field status {}; # single line of text we show |
||||
field prefix {}; # text we format into status |
||||
field units {}; # unit of progress |
||||
field meter {}; # current core git progress meter (if active) |
||||
|
||||
constructor new {path} { |
||||
set w $path |
||||
set w_l $w.l |
||||
set w_c $w.c |
||||
|
||||
frame $w \ |
||||
-borderwidth 1 \ |
||||
-relief sunken |
||||
label $w_l \ |
||||
-textvariable @status \ |
||||
-anchor w \ |
||||
-justify left |
||||
pack $w_l -side left |
||||
|
||||
bind $w <Destroy> [cb _delete %W] |
||||
return $this |
||||
} |
||||
|
||||
method start {msg uds} { |
||||
if {[winfo exists $w_c]} { |
||||
$w_c coords bar 0 0 0 20 |
||||
} else { |
||||
canvas $w_c \ |
||||
-width 100 \ |
||||
-height [expr {int([winfo reqheight $w_l] * 0.6)}] \ |
||||
-borderwidth 1 \ |
||||
-relief groove \ |
||||
-highlightt 0 |
||||
$w_c create rectangle 0 0 0 20 -tags bar -fill navy |
||||
pack $w_c -side right |
||||
} |
||||
|
||||
set status $msg |
||||
set prefix $msg |
||||
set units $uds |
||||
set meter {} |
||||
} |
||||
|
||||
method update {have total} { |
||||
set pdone 0 |
||||
if {$total > 0} { |
||||
set pdone [expr {100 * $have / $total}] |
||||
} |
||||
|
||||
set status [format "%s ... %i of %i %s (%2i%%)" \ |
||||
$prefix $have $total $units $pdone] |
||||
$w_c coords bar 0 0 $pdone 20 |
||||
} |
||||
|
||||
method update_meter {buf} { |
||||
append meter $buf |
||||
set r [string last "\r" $meter] |
||||
if {$r == -1} { |
||||
return |
||||
} |
||||
|
||||
set prior [string range $meter 0 $r] |
||||
set meter [string range $meter [expr {$r + 1}] end] |
||||
if {[regexp "\\((\\d+)/(\\d+)\\)\\s+done\r\$" $prior _j a b]} { |
||||
update $this $a $b |
||||
} |
||||
} |
||||
|
||||
method stop {{msg {}}} { |
||||
destroy $w_c |
||||
if {$msg ne {}} { |
||||
set status $msg |
||||
} |
||||
} |
||||
|
||||
method show {msg {test {}}} { |
||||
if {$test eq {} || $status eq $test} { |
||||
set status $msg |
||||
} |
||||
} |
||||
|
||||
method _delete {current} { |
||||
if {$current eq $w} { |
||||
delete_this |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue