[PATCH 3/3] hg view: allow creation and deletion of local tags
Darren Salt
linux at youmustbejoking.demon.co.uk
Wed Apr 26 21:44:54 UTC 2006
hg view: allow creation and deletion of local tags.
Button 3 on the tag for a menu.
Creation uses hg tag -l.
Deletion removes all references to the tag from .hg/localtags.
diff -r 9681d3c51841 -r 0c768c0d0887 contrib/hgk
--- a/contrib/hgk Wed Apr 26 22:31:47 2006 +0100
+++ b/contrib/hgk Wed Apr 26 22:34:16 2006 +0100
@@ -306,6 +306,7 @@ proc makewindow {} {
global entries sha1entry sha1string sha1but
global maincursor textcursor curtextcursor
global rowctxmenu gaudydiff mergemax
+ global localtagctxmenu
menu .bar
.bar add cascade -label "File" -menu .bar.file
@@ -507,7 +508,12 @@ proc makewindow {} {
-command {diffvssel 1}
$rowctxmenu add command -label "Make patch" -command mkpatch
$rowctxmenu add command -label "Create tag" -command mktag
+ $rowctxmenu add command -label "Create local tag" -command mktaglocal
$rowctxmenu add command -label "Write commit to file" -command writecommit
+
+ set localtagctxmenu .localtagctxmenu
+ menu $localtagctxmenu -tearoff 0
+ $localtagctxmenu add command -label "Delete local tag" -command rmtaglocal
}
# when we make a key binding for the toplevel, make sure
@@ -929,6 +935,9 @@ proc drawtags {id x xt y1} {
-font $mainfont -tags tag.$id]
if {$ntags >= 0} {
$canv bind $t <1> [list showtag $tag 1]
+ if {[info exists localtags($tag)]} {
+ $canv bind $t <Button-3> "localtagmenu %X %Y $tag"
+ }
}
}
return $xt
@@ -3287,6 +3296,12 @@ proc rowmenu {x y id} {
$rowctxmenu entryconfigure 2 -state $state
set rowmenuid $id
tk_popup $rowctxmenu $x $y
+}
+
+proc localtagmenu {x y id} {
+ global localtagctxmenu localtagmenuid
+ set localtagmenuid $id
+ tk_popup $localtagctxmenu $x $y
}
proc diffvssel {dirn} {
@@ -3419,14 +3434,18 @@ proc mkpatchcan {} {
unset patchtop
}
-proc mktag {} {
- global rowmenuid mktagtop commitinfo
+proc mktag_internal {} {
+ global rowmenuid mktagtop mktaglocal commitinfo
set top .maketag
set mktagtop $top
catch {destroy $top}
toplevel $top
- label $top.title -text "Create tag"
+ if {$mktaglocal == {}} {
+ label $top.title -text "Create tag"
+ } else {
+ label $top.title -text "Create local tag"
+ }
grid $top.title - -pady 10
label $top.id -text "ID:"
entry $top.sha1 -width 40 -relief flat
@@ -3437,12 +3456,18 @@ proc mktag {} {
$top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
$top.head conf -state readonly
grid x $top.head -sticky w
- label $top.tlab -text "Tag name:"
+ if {$mktaglocal == {}} {
+ label $top.tlab -text "Tag name:"
+ } else {
+ label $top.tlab -text "Local tag name:"
+ }
entry $top.tag -width 60
grid $top.tlab $top.tag -sticky w
- label $top.mlab -text "Commit message:"
- entry $top.msg -width 60
- grid $top.mlab $top.msg -sticky w -pady 5
+ if {$mktaglocal == {}} {
+ label $top.mlab -text "Commit message:"
+ entry $top.msg -width 60
+ grid $top.mlab $top.msg -sticky w -pady 5
+ }
frame $top.buts
button $top.buts.gen -text "Create" -command mktaggo
button $top.buts.can -text "Cancel" -command mktagcan
@@ -3451,10 +3476,58 @@ proc mktag {} {
grid columnconfigure $top.buts 1 -weight 1 -uniform a
grid $top.buts - -pady 10 -sticky ew
focus $top.tag
+ set $top.localtag {}
+}
+
+proc mktag {} {
+ global mktaglocal
+ set mktaglocal {}
+ mktag_internal
+}
+
+proc mktaglocal {} {
+ global mktaglocal
+ set mktaglocal 1
+ mktag_internal
+}
+
+proc rmtaglocal {} {
+ global tagids idtags tagcontents localtags localtagmenuid
+
+ set tagsfile [file join [gitdir] "localtags"]
+ set newtagsfile [join {$tagsfile "." [pid]} ""]
+ if {[file isfile $tagsfile]} {
+ if [catch {
+ set readfd [open $tagsfile r]
+ set stuff [string trim [read $readfd]]
+ close $readfd
+ set lines [split $stuff "\n"]
+ set writefd [open $newtagsfile w]
+ foreach f $lines {
+ set f [regexp -all -inline {\S+} $f]
+ if {$localtagmenuid != [lindex $f 1]} {
+ puts $writefd [concat [lindex $f 0] [lindex $f 1]]
+ }
+ }
+ close $writefd
+ exec mv $newtagsfile $tagsfile
+ } err] {
+ if ([file isfile $newtagsfile]) {
+ if [catch { exec unlink $newtagsfile } err2] {
+ error_popup "Error deleting tag: $err\nError removing temporary file: $err2"
+ } else {
+ error_popup "Error deleting tag: $err"
+ }
+ } else {
+ error_popup "Error deleting tag: $err"
+ }
+ }
+ rereadrefs
+ }
}
proc domktag {} {
- global mktagtop env tagids idtags
+ global mktagtop mktaglocal env tagids idtags localtags
set id [$mktagtop.sha1 get]
set tag [$mktagtop.tag get]
@@ -3467,11 +3540,15 @@ proc domktag {} {
return
}
if {[catch {
- set msg [$mktagtop.msg get]
- if {$msg == {}} {
- set out [exec hg tag -r $id $tag]
+ if {$mktaglocal == 1} {
+ set out [exec hg tag -l -r $id $tag]
} else {
- set out [exec hg tag -r $id -m "$msg" $tag]
+ set msg [$mktagtop.msg get]
+ if {$msg == {}} {
+ set out [exec hg tag -r $id $tag]
+ } else {
+ set out [exec hg tag -r $id -m "$msg" $tag]
+ }
}
} err]} {
error_popup "Error creating tag: $err"
@@ -3480,6 +3557,9 @@ proc domktag {} {
set tagids($tag) $id
lappend idtags($id) $tag
+ if {$mktaglocal != {}} {
+ lappend localtags($tag) $id
+ }
redrawtags $id
}
--
| Darren Salt | linux or ds at | nr. Ashington, | Toon
| RISC OS, Linux | youmustbejoking,demon,co,uk | Northumberland | Army
| + Buy less and make it last longer. INDUSTRY CAUSES GLOBAL WARMING.
You will live to see your grandchildren.
More information about the Mercurial
mailing list