gitk: Add a row context-menu item for creating a new branch
Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Aug 2, 2006 at 09:41 UTC
d6ac1a86e932fdb48705b9b1b6e2849aaea9ad24
1 file changed
+80
gitk
+80
@@ -711,6 +711,7 @@ proc makewindow {} {
711
$rowctxmenu add command -label "Make patch" -command mkpatch
712
$rowctxmenu add command -label "Create tag" -command mktag
713
$rowctxmenu add command -label "Write commit to file" -command writecommit
714
+ $rowctxmenu add command -label "Create new branch" -command mkbranch
715
}
716
717
# mouse-2 makes all windows scan vertically, but only the one
@@ -5018,6 +5019,61 @@ proc wrcomcan {} {
5019
unset wrcomtop
5020
}
5021
5022
+proc mkbranch {} {
5023
+ global rowmenuid mkbrtop
5024
+
5025
+ set top .makebranch
5026
+ catch {destroy $top}
5027
+ toplevel $top
5028
+ label $top.title -text "Create new branch"
5029
+ grid $top.title - -pady 10
5030
+ label $top.id -text "ID:"
5031
+ entry $top.sha1 -width 40 -relief flat
5032
+ $top.sha1 insert 0 $rowmenuid
5033
+ $top.sha1 conf -state readonly
5034
+ grid $top.id $top.sha1 -sticky w
5035
+ label $top.nlab -text "Name:"
5036
+ entry $top.name -width 40
5037
+ grid $top.nlab $top.name -sticky w
5038
+ frame $top.buts
5039
+ button $top.buts.go -text "Create" -command [list mkbrgo $top]
5040
+ button $top.buts.can -text "Cancel" -command "catch {destroy $top}"
5041
+ grid $top.buts.go $top.buts.can
5042
+ grid columnconfigure $top.buts 0 -weight 1 -uniform a
5043
+ grid columnconfigure $top.buts 1 -weight 1 -uniform a
5044
+ grid $top.buts - -pady 10 -sticky ew
5045
+ focus $top.name
5046
+}
5047
+
5048
+proc mkbrgo {top} {
5049
+ global headids idheads
5050
+
5051
+ set name [$top.name get]
5052
+ set id [$top.sha1 get]
5053
+ if {$name eq {}} {
5054
+ error_popup "Please specify a name for the new branch"
5055
+ return
5056
+ }
5057
+ catch {destroy $top}
5058
+ nowbusy newbranch
5059
+ update
5060
+ if {[catch {
5061
+ exec git branch $name $id
5062
+ } err]} {
5063
+ notbusy newbranch
5064
+ error_popup $err
5065
+ } else {
5066
+ set headids($name) $id
5067
+ if {![info exists idheads($id)]} {
5068
+ addedhead $id
5069
+ }
5070
+ lappend idheads($id) $name
5071
+ # XXX should update list of heads displayed for selected commit
5072
+ notbusy newbranch
5073
+ redrawtags $id
5074
+ }
5075
+}
5076
+
5077
# Stuff for finding nearby tags
5078
proc getallcommits {} {
5079
global allcstart allcommits allcfd allids
@@ -5218,6 +5274,30 @@ proc restartatags {} {
5274
dispneartags
5275
}
5276
5277
+# update the desc_heads array for a new head just added
5278
+proc addedhead {hid} {
5279
+ global desc_heads allparents
5280
+
5281
+ set todo [list $hid]
5282
+ while {$todo ne {}} {
5283
+ set do [lindex $todo 0]
5284
+ set todo [lrange $todo 1 end]
5285
+ if {![info exists desc_heads($do)] ||
5286
+ [lsearch -exact $desc_heads($do) $hid] >= 0} continue
5287
+ set oldheads $desc_heads($do)
5288
+ lappend desc_heads($do) $hid
5289
+ set heads $desc_heads($do)
5290
+ while {1} {
5291
+ set p $allparents($do)
5292
+ if {[llength $p] != 1 || ![info exists desc_heads($p)] ||
5293
+ $desc_heads($p) ne $oldheads} break
5294
+ set do $p
5295
+ set desc_heads($do) $heads
5296
+ }
5297
+ set todo [concat $todo $p]
5298
+ }
5299
+}
5300
+
5301
proc changedrefs {} {
5302
global desc_heads desc_tags anc_tags allcommits allids
5303
global allchildren allparents idtags travindex