From 6e4ba05c7fee0d0140e2057b63f5ca4eea9a6053 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 2 Sep 2007 15:19:07 -0400 Subject: git-gui: Correct starting of git-remote to handle -w option Current versions of git-remote apparently are passing the -w option to Perl as part of the shbang line: #!/usr/bin/perl -w this caused a problem in git-gui and gave the user a Tcl error with the message: "git-remote not supported: #!/usr/bin/perl -w". The fix for this is to treat the shbang line as a Tcl list and look at the first element only for guessing the executable name. Once we know the executable name we use the remaining elements (if any exist) as arguments to the executable, before the script filename. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index fa30ccc5d6..e495046c3b 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -261,7 +261,7 @@ proc _git_cmd {name} { set s [gets $f] close $f - switch -glob -- $s { + switch -glob -- [lindex $s 0] { #!*sh { set i sh } #!*perl { set i perl } #!*python { set i python } @@ -275,7 +275,7 @@ proc _git_cmd {name} { if {$interp eq {}} { error "git-$name requires $i (not in PATH)" } - set v [list $interp $p] + set v [concat [list $interp] [lrange $s 1 end] [list $p]] } else { # Assume it is builtin to git somehow and we # aren't actually able to see a file for it. -- cgit v1.2.3 From 881d8f24cab5bf4e0fa71b17a3ab82e27b2e8ed7 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 2 Sep 2007 15:30:26 -0400 Subject: git-gui: Fix detaching current branch during checkout If the user tried to detach their HEAD while keeping the working directory on the same commit we actually did not completely do a detach operation internally. The problem was caused by git-gui not forcing the HEAD symbolic ref to be updated to a SHA-1 hash when we were not switching revisions. Now we update the HEAD ref if we aren't currently detached or the hashes don't match. Signed-off-by: Shawn O. Pearce --- lib/checkout_op.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkout_op.tcl b/lib/checkout_op.tcl index 170f737f61..76f04f2854 100644 --- a/lib/checkout_op.tcl +++ b/lib/checkout_op.tcl @@ -396,7 +396,7 @@ method _after_readtree {} { set is_detached 0 } } else { - if {$new_hash ne $HEAD} { + if {!$is_detached || $new_hash ne $HEAD} { append log " to $new_expr" if {[catch { _detach_HEAD $log $new_hash -- cgit v1.2.3 From 047d94d505c9837a60c28e121de65471dadce74b Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 2 Sep 2007 15:38:04 -0400 Subject: git-gui: Properly set the state of "Stage/Unstage Hunk" action Today I found yet another way for the "Stage Hunk" and "Unstage Hunk" context menu actions to leave the wrong state enabled in the UI. The problem this time was that I connected the state determination to the value of $::current_diff_side (the side the diff is from). When the user was last looking at a diff from the index side and unstages everything the diff panel goes empty, but the action stayed enabled as we always assumed unstaging was a valid action. This change moves the logic for determining when the action is enabled away from the individual side selection, as they really are two unrelated concepts. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index e495046c3b..44977aa212 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2441,20 +2441,17 @@ proc popup_diff_menu {ctxm x y X Y} { set ::cursorX $x set ::cursorY $y if {$::ui_index eq $::current_diff_side} { - set s normal set l "Unstage Hunk From Commit" } else { - if {$current_diff_path eq {} - || ![info exists file_states($current_diff_path)] - || {_O} eq [lindex $file_states($current_diff_path) 0]} { - set s disabled - } else { - set s normal - } set l "Stage Hunk For Commit" } - if {$::is_3way_diff} { + if {$::is_3way_diff + || $current_diff_path eq {} + || ![info exists file_states($current_diff_path)] + || {_O} eq [lindex $file_states($current_diff_path) 0]} { set s disabled + } else { + set s normal } $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l tk_popup $ctxm $X $Y -- cgit v1.2.3 From 0b883ab30c869c4f22a19e49aedc1604d335cd91 Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Fri, 7 Sep 2007 17:16:59 +0000 Subject: git-gui: lib/index.tcl: handle files with % in the filename properly Steps to reproduce the bug: $ mkdir repo && cd repo && git init Initialized empty Git repository in .git/ $ touch 'foo%3Fsuite' $ git-gui Then click on the 'foo%3Fsuite' icon to include it in a changeset, a popup comes with: 'Error: bad field specifier "F"' Vincent Danjean noticed the problem and also suggested the fix, reported through http://bugs.debian.org/441167 Signed-off-by: Gerrit Pape Signed-off-by: Shawn O. Pearce --- lib/index.tcl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/index.tcl b/lib/index.tcl index f47f9290c8..cbbce13a77 100644 --- a/lib/index.tcl +++ b/lib/index.tcl @@ -13,7 +13,8 @@ proc update_indexinfo {msg pathList after} { if {$batch > 25} {set batch 25} ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg \ $update_index_cp \ $totalCnt \ 0.0] @@ -68,7 +69,8 @@ proc write_update_indexinfo {fd pathList totalCnt batch msg after} { } ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg \ $update_index_cp \ $totalCnt \ [expr {100.0 * $update_index_cp / $totalCnt}]] @@ -86,7 +88,8 @@ proc update_index {msg pathList after} { if {$batch > 25} {set batch 25} ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg \ $update_index_cp \ $totalCnt \ 0.0] @@ -145,7 +148,8 @@ proc write_update_index {fd pathList totalCnt batch msg after} { } ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg \ $update_index_cp \ $totalCnt \ [expr {100.0 * $update_index_cp / $totalCnt}]] @@ -163,7 +167,8 @@ proc checkout_index {msg pathList after} { if {$batch > 25} {set batch 25} ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg $update_index_cp \ $totalCnt \ 0.0] @@ -218,7 +223,8 @@ proc write_checkout_index {fd pathList totalCnt batch msg after} { } ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg \ $update_index_cp \ $totalCnt \ [expr {100.0 * $update_index_cp / $totalCnt}]] -- cgit v1.2.3 From cff93397ab185898fd93b6a260cc6f3068c4ac30 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 8 Sep 2007 23:47:00 -0400 Subject: git-gui: Disable Tk send in all git-gui sessions The Tk designers blessed us with the "send" command, which on X11 will allow anyone who can connect to your X server to evaluate any Tcl code they desire within any running Tk process. This is just plain nuts. If git-gui wants someone running Tcl code within it then would ask someone to supply that Tcl code to it; waiting for someone to drop any random Tcl code into us is not fantastic idea. By renaming send to the empty name the procedure will be removed from the global namespace and Tk will stop responding to random Tcl evaluation requests sent through the X server. Since there is no facility to filter these requests it is unlikely that we will ever consider enabling this command. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index 44977aa212..6d676097a6 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -42,6 +42,8 @@ if {[catch {package require Tcl 8.4} err] exit 1 } +rename send {} ; # What an evil concept... + ###################################################################### ## ## enable verbose loading? -- cgit v1.2.3 From c63fe3b2dc90120a4bdba7194f92efc2f3c342ed Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 8 Sep 2007 23:05:43 -0400 Subject: git-gui: Avoid use of libdir in Makefile Dmitry V. Levin pointed out that on GNU linux libdir is often used in Makefiles to mean "/usr/lib" or "/usr/lib64", a directory that is meant to hold platform-specific binary files. Using a different libdir meaning here in git-gui's Makefile breaks idomatic expressions like rpm specifile "make libdir=%_libdir". Originally I asked that the git.git Makefile undefine libdir before it calls git-gui's own Makefile but it turns out this is very hard to do, if not impossible. Renaming our libdir to gg_libdir resolves this case with a minimum amount of fuss on our part. Signed-off-by: Shawn O. Pearce --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1bac6fed46..f11cf26760 100644 --- a/Makefile +++ b/Makefile @@ -76,8 +76,8 @@ SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) TCL_PATH_SQ = $(subst ','\'',$(TCL_PATH)) TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH)) -libdir ?= $(sharedir)/git-gui/lib -libdir_SQ = $(subst ','\'',$(libdir)) +gg_libdir ?= $(sharedir)/git-gui/lib +libdir_SQ = $(subst ','\'',$(gg_libdir)) exedir = $(dir $(gitexecdir))share/git-gui/lib exedir_SQ = $(subst ','\'',$(exedir)) @@ -126,7 +126,7 @@ TRACK_VARS = \ $(subst ','\'',TCL_PATH='$(TCL_PATH_SQ)') \ $(subst ','\'',TCLTK_PATH='$(TCLTK_PATH_SQ)') \ $(subst ','\'',gitexecdir='$(gitexecdir_SQ)') \ - $(subst ','\'',libdir='$(libdir_SQ)') \ + $(subst ','\'',gg_libdir='$(libdir_SQ)') \ #end TRACK_VARS GIT-GUI-VARS: .FORCE-GIT-GUI-VARS -- cgit v1.2.3 From 2d19f8e921a1cdc562783814747819b0d5a12641 Mon Sep 17 00:00:00 2001 From: Michele Ballabio Date: Sun, 9 Sep 2007 21:04:45 +0200 Subject: git-gui: show unstaged symlinks in diff viewer git-gui has a minor problem with regards to symlinks that point to directories. git init mkdir realdir ln -s realdir linkdir git gui Now clicking on file names in the "unstaged changes" window, there's a problem coming from the "linkdir" symlink: git-gui complains with error reading "file4": illegal operation on a directory ...even though git-gui can add that same symlink to the index just fine. This patch fix this by adding a check. [sp: Minor fix to use {link} instead of "link" in condition and to only open the path if it is not a symlink.] Signed-off-by: Michele Ballabio Signed-off-by: Shawn O. Pearce --- lib/diff.tcl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/diff.tcl b/lib/diff.tcl index e09e1257e1..9eeff2ed35 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -85,11 +85,16 @@ proc show_diff {path w {lno {}}} { if {$m eq {_O}} { set max_sz [expr {128 * 1024}] if {[catch { - set fd [open $path r] - fconfigure $fd -eofchar {} - set content [read $fd $max_sz] - close $fd - set sz [file size $path] + if {[file type $path] == {link}} { + set content [file readlink $path] + set sz [string length $content] + } else { + set fd [open $path r] + fconfigure $fd -eofchar {} + set content [read $fd $max_sz] + close $fd + set sz [file size $path] + } } err ]} { set diff_active 0 unlock_index -- cgit v1.2.3 From 4ed1a190d09c7d6a248038edb11addda77af7550 Mon Sep 17 00:00:00 2001 From: Michele Ballabio Date: Sun, 9 Sep 2007 21:09:07 +0200 Subject: git-gui: handle "deleted symlink" diff marker Signed-off-by: Michele Ballabio Signed-off-by: Shawn O. Pearce --- lib/diff.tcl | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/diff.tcl b/lib/diff.tcl index 9eeff2ed35..a1d5e523d2 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -203,6 +203,7 @@ proc read_diff {fd} { if {[string match {mode *} $line] || [string match {new file *} $line] || [string match {deleted file *} $line] + || [string match {deleted symlink} $line] || [string match {Binary files * and * differ} $line] || $line eq {\ No newline at end of file} || [regexp {^\* Unmerged path } $line]} { -- cgit v1.2.3 From 3b9dfde3d636aeb961318d41b3ab59f72414d010 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 9 Sep 2007 20:13:10 -0400 Subject: git-gui: Assume untracked directories are Git submodules If `git ls-files --others` returned us the name of a directory then it is because Git has decided that this directory itself contains a valid Git repository and its files shouldn't be listed as untracked for this repository. In such a case we should label the object as a Git repository and not just as a directory. Signed-off-by: Shawn O. Pearce --- lib/diff.tcl | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/diff.tcl b/lib/diff.tcl index a1d5e523d2..694834ab7a 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -84,17 +84,30 @@ proc show_diff {path w {lno {}}} { # if {$m eq {_O}} { set max_sz [expr {128 * 1024}] + set type unknown if {[catch { - if {[file type $path] == {link}} { + set type [file type $path] + switch -- $type { + directory { + set type submodule + set content {} + set sz 0 + } + link { set content [file readlink $path] set sz [string length $content] - } else { + } + file { set fd [open $path r] fconfigure $fd -eofchar {} set content [read $fd $max_sz] close $fd set sz [file size $path] } + default { + error "'$type' not supported" + } + } } err ]} { set diff_active 0 unlock_index @@ -103,7 +116,9 @@ proc show_diff {path w {lno {}}} { return } $ui_diff conf -state normal - if {![catch {set type [exec file $path]}]} { + if {$type eq {submodule}} { + $ui_diff insert end "* Git Repository (subproject)\n" d_@ + } elseif {![catch {set type [exec file $path]}]} { set n [string length $path] if {[string equal -length $n $path $type]} { set type [string range $type $n end] -- cgit v1.2.3 From 8938410189315979255c1dfcc3c0b7a4bf9953e5 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 9 Sep 2007 20:38:05 -0400 Subject: git-gui: Trim trailing slashes from untracked submodule names Oddly enough `git ls-files --others` supplies us the name of an untracked submodule by including the trailing slash but that same git version will not accept the name with a trailing slash through `git update-index --stdin`. Stripping off that final slash character before loading it into our file lists allows git-gui to stage changes to submodules just like any other file. This change should give git-gui users some basic submodule support, but it is strictly at the plumbing level as we do not actually know about calling the git-submodule porcelain that is a recent addition to git 1.5.3. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/git-gui.sh b/git-gui.sh index 6d676097a6..26eb5ac309 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1010,7 +1010,11 @@ proc read_ls_others {fd after} { set pck [split $buf_rlo "\0"] set buf_rlo [lindex $pck end] foreach p [lrange $pck 0 end-1] { - merge_state [encoding convertfrom $p] ?O + set p [encoding convertfrom $p] + if {[string index $p end] eq {/}} { + set p [string range $p 0 end-1] + } + merge_state $p ?O } rescan_done $fd buf_rlo $after } -- cgit v1.2.3 From 63c4024ff080430004967fa27b8af8fe243e2ea3 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 11 Sep 2007 13:37:45 -0400 Subject: git-gui: Don't delete send on Windows as it doesn't exist The Windows port of Tk does not have the send command so we cannot delete it from our global namespace, but the Mac OS X and X11 ports do have it. Switching this delete attempt into a catch makes send go away, or stay away. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-gui.sh b/git-gui.sh index 26eb5ac309..e221d5b511 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -42,7 +42,7 @@ if {[catch {package require Tcl 8.4} err] exit 1 } -rename send {} ; # What an evil concept... +catch {rename send {}} ; # What an evil concept... ###################################################################### ## -- cgit v1.2.3 From e7034d66ecd9c16ae8bd8d331fc41efc48e925f1 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 13 Sep 2007 19:04:14 -0400 Subject: git-gui: Make backporting changes from i18n version easier This is a very trivial hack to define a global mc procedure that does not actually perform i18n translations on its input strings. By declaring an mc procedure here in our maint version of git-gui we can take patches that are intended for the latest development version of git-gui and easily backport them without needing to tweak the mc calls first. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index e221d5b511..31a36cb49f 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -62,6 +62,18 @@ if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} { } } +###################################################################### +## +## Fake internationalization to ease backporting of changes. + +proc mc {fmt args} { + set cmk [string first @@ $fmt] + if {$cmk > 0} { + set fmt [string range $fmt 0 [expr {$cmk - 1}]] + } + return [eval [list format $fmt] $args] +} + ###################################################################### ## ## read only globals -- cgit v1.2.3 From afe2098ddd3e21d1d1afc428d3c8d91f37b01692 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 13 Sep 2007 19:07:46 -0400 Subject: git-gui: Font chooser to handle a large number of font families Simon Sasburg noticed that on X11 if there are more fonts than can fit in the height of the screen Tk's native tk_optionMenu does not offer scroll arrows to the user and it is not possible to review all choices or to select those that are off-screen. On Mac OS X the tk_optionMenu works properly but is awkward to navigate if the list is long. This is a rewrite of our font selection by providing a new modal dialog that the user can launch from the git-gui Options panel. The dialog offers the user a scrolling list of fonts in a pane. An example text shows the user what the font looks like at the size they have selected. But I have to admit the example pane is less than ideal. For example in the case of our diff font we really should show the user an example diff complete with our native diff syntax coloring. Signed-off-by: Shawn O. Pearce Acked-by: Simon Sasburg --- lib/choose_font.tcl | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/option.tcl | 28 +++++---- 2 files changed, 182 insertions(+), 11 deletions(-) create mode 100644 lib/choose_font.tcl diff --git a/lib/choose_font.tcl b/lib/choose_font.tcl new file mode 100644 index 0000000000..b69215c91e --- /dev/null +++ b/lib/choose_font.tcl @@ -0,0 +1,165 @@ +# git-gui font chooser +# Copyright (C) 2007 Shawn Pearce + +class choose_font { + +field w +field w_family ; # UI widget of all known family names +field w_example ; # Example to showcase the chosen font + +field f_family ; # Currently chosen family name +field f_size ; # Currently chosen point size + +field v_family ; # Name of global variable for family +field v_size ; # Name of global variable for size + +variable all_families [list] ; # All fonts known to Tk + +constructor pick {path title a_family a_size} { + variable all_families + + set v_family $a_family + set v_size $a_size + + upvar #0 $v_family pv_family + upvar #0 $v_size pv_size + + set f_family $pv_family + set f_size $pv_size + + make_toplevel top w + wm title $top "[appname] ([reponame]): $title" + wm geometry $top "+[winfo rootx $path]+[winfo rooty $path]" + + label $w.header -text $title -font font_uibold + pack $w.header -side top -fill x + + frame $w.buttons + button $w.buttons.select \ + -text [mc Select] \ + -default active \ + -command [cb _select] + button $w.buttons.cancel \ + -text [mc Cancel] \ + -command [list destroy $w] + pack $w.buttons.select -side right + pack $w.buttons.cancel -side right -padx 5 + pack $w.buttons -side bottom -fill x -pady 10 -padx 10 + + frame $w.inner + + frame $w.inner.family + label $w.inner.family.l \ + -text [mc "Font Family"] \ + -anchor w + set w_family $w.inner.family.v + text $w_family \ + -background white \ + -borderwidth 1 \ + -relief sunken \ + -cursor $::cursor_ptr \ + -wrap none \ + -width 30 \ + -height 10 \ + -yscrollcommand [list $w.inner.family.sby set] + scrollbar $w.inner.family.sby -command [list $w_family yview] + pack $w.inner.family.l -side top -fill x + pack $w.inner.family.sby -side right -fill y + pack $w_family -fill both -expand 1 + + frame $w.inner.size + label $w.inner.size.l \ + -text [mc "Font Size"] \ + -anchor w + spinbox $w.inner.size.v \ + -textvariable @f_size \ + -from 2 -to 80 -increment 1 \ + -width 3 + bind $w.inner.size.v {%W selection range 0 end} + pack $w.inner.size.l -fill x -side top + pack $w.inner.size.v -fill x -padx 2 + + grid configure $w.inner.family $w.inner.size -sticky nsew + grid rowconfigure $w.inner 0 -weight 1 + grid columnconfigure $w.inner 0 -weight 1 + pack $w.inner -fill both -expand 1 -padx 5 -pady 5 + + frame $w.example + label $w.example.l \ + -text [mc "Font Example"] \ + -anchor w + set w_example $w.example.t + text $w_example \ + -background white \ + -borderwidth 1 \ + -relief sunken \ + -height 3 \ + -width 40 + $w_example tag conf example -justify center + $w_example insert end [mc "This is example text.\nIf you like this text, it can be your font."] example + $w_example conf -state disabled + pack $w.example.l -fill x + pack $w_example -fill x + pack $w.example -fill x -padx 5 + + if {$all_families eq {}} { + set all_families [lsort [font families]] + } + + $w_family tag conf pick + $w_family tag bind pick [cb _pick_family %x %y]\;break + $w_family tag conf cpck -background lightgray + foreach f $all_families { + set sel [list pick] + if {$f eq $f_family} { + lappend sel cpck + } + $w_family insert end "$f\n" $sel + } + $w_family conf -state disabled + _update $this + + trace add variable @f_size write [cb _update] + bind $w [list destroy $w] + bind $w [cb _select]\;break + bind $w " + grab $w + focus $w + " + tkwait window $w +} + +method _select {} { + upvar #0 $v_family pv_family + upvar #0 $v_size pv_size + + set pv_family $f_family + set pv_size $f_size + + destroy $w +} + +method _pick_family {x y} { + variable all_families + + set i [lindex [split [$w_family index @$x,$y] .] 0] + set n [lindex $all_families [expr {$i - 1}]] + if {$n ne {}} { + $w_family tag remove cpck 0.0 end + $w_family tag add cpck $i.0 [expr {$i + 1}].0 + set f_family $n + _update $this + } +} + +method _update {args} { + variable all_families + + set i [lsearch -exact $all_families $f_family] + if {$i < 0} return + + $w_example tag conf example -font [list $f_family $f_size] + $w_family see [expr {$i + 1}].0 +} + +} diff --git a/lib/option.tcl b/lib/option.tcl index aa9f783afd..063f5df6f7 100644 --- a/lib/option.tcl +++ b/lib/option.tcl @@ -255,17 +255,23 @@ proc do_options {} { frame $w.global.$name label $w.global.$name.l -text "$text:" - pack $w.global.$name.l -side left -anchor w -fill x - eval tk_optionMenu $w.global.$name.family \ - global_config_new(gui.$font^^family) \ - $all_fonts - spinbox $w.global.$name.size \ - -textvariable global_config_new(gui.$font^^size) \ - -from 2 -to 80 -increment 1 \ - -width 3 - bind $w.global.$name.size {%W selection range 0 end} - pack $w.global.$name.size -side right -anchor e - pack $w.global.$name.family -side right -anchor e + button $w.global.$name.b \ + -text [mc "Change Font"] \ + -command [list \ + choose_font::pick \ + $w \ + [mc "Choose %s" $text] \ + global_config_new(gui.$font^^family) \ + global_config_new(gui.$font^^size) \ + ] + label $w.global.$name.f -textvariable global_config_new(gui.$font^^family) + label $w.global.$name.s -textvariable global_config_new(gui.$font^^size) + label $w.global.$name.pt -text [mc "pt."] + pack $w.global.$name.l -side left -anchor w + pack $w.global.$name.b -side right -anchor e + pack $w.global.$name.pt -side right -anchor w + pack $w.global.$name.s -side right -anchor w + pack $w.global.$name.f -side right -anchor w pack $w.global.$name -side top -anchor w -fill x } -- cgit v1.2.3 From 042f53c569c92b40e63c6993c8998d2aac22e383 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 13 Sep 2007 19:50:35 -0400 Subject: git-gui: Provide 'uninstall' Makefile target to undo an installation Several users have requested a "make uninstall" target be provided in the stock git-gui Makefile so that they can undo an install if git-gui goes to the wrong place during the initial install, or if they are unhappy with the tool and want to remove it from their system. We currently assume that the complete set of files we need to delete are those defined by our Makefile and current source directory. This could differ from what the user actually has installed if they installed one version then attempt to use another to perform the uninstall. Right now I'm just going to say that is "pilot error". Users should uninstall git-gui using the same version of source that they used to make the installation. Perhaps in the future we could read tclIndex and base our uninstall decisions on its contents. Signed-off-by: Shawn O. Pearce --- Makefile | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f11cf26760..18e6750137 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,9 @@ ifndef INSTALL INSTALL = install endif +RM_F ?= rm -f +RMDIR ?= rmdir + INSTALL_D0 = $(INSTALL) -d -m755 # space is required here INSTALL_D1 = INSTALL_R0 = $(INSTALL) -m644 # space is required here @@ -42,6 +45,12 @@ INSTALL_L1 = && ln # space is required here INSTALL_L2 = INSTALL_L3 = +REMOVE_D0 = $(RMDIR) # space is required here +REMOVE_D1 = || true +REMOVE_F0 = $(RM_F) # space is required here +REMOVE_F1 = +CLEAN_DST = true + ifndef V QUIET = @ QUIET_GEN = $(QUIET)echo ' ' GEN $@ && @@ -60,6 +69,12 @@ ifndef V INSTALL_L1 = && src= INSTALL_L2 = && dst= INSTALL_L3 = && echo ' ' 'LINK ' `basename "$$dst"` '->' `basename "$$src"` && rm -f "$$dst" && ln "$$src" "$$dst" + + CLEAN_DST = echo ' ' UNINSTALL + REMOVE_D0 = dir= + REMOVE_D1 = && echo ' ' REMOVE $$dir && test -d "$$dir" && $(RMDIR) "$$dir" || true + REMOVE_F0 = dst= + REMOVE_F1 = && echo ' ' REMOVE `basename "$$dst"` && $(RM_F) "$$dst" endif TCL_PATH ?= tclsh @@ -146,6 +161,17 @@ install: all $(QUIET)$(INSTALL_R0)lib/tclIndex $(INSTALL_R1) '$(DESTDIR_SQ)$(libdir_SQ)' $(QUIET)$(foreach p,$(ALL_LIBFILES), $(INSTALL_R0)$p $(INSTALL_R1) '$(DESTDIR_SQ)$(libdir_SQ)' &&) true +uninstall: + $(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(gitexecdir_SQ)' + $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui $(REMOVE_F1) + $(QUIET)$(foreach p,$(GITGUI_BUILT_INS), $(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/$p $(REMOVE_F1) &&) true + $(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(libdir_SQ)' + $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(libdir_SQ)'/tclIndex $(REMOVE_F1) + $(QUIET)$(foreach p,$(ALL_LIBFILES), $(REMOVE_F0)'$(DESTDIR_SQ)$(libdir_SQ)'/$(notdir $p) $(REMOVE_F1) &&) true + $(QUIET)$(REMOVE_D0)'$(DESTDIR_SQ)$(gitexecdir_SQ)' $(REMOVE_D1) + $(QUIET)$(REMOVE_D0)'$(DESTDIR_SQ)$(libdir_SQ)' $(REMOVE_D1) + $(QUIET)$(REMOVE_D0)`dirname '$(DESTDIR_SQ)$(libdir_SQ)'` $(REMOVE_D1) + dist-version: @mkdir -p $(TARDIR) @echo $(GITGUI_VERSION) > $(TARDIR)/version @@ -154,6 +180,6 @@ clean:: rm -f $(ALL_PROGRAMS) lib/tclIndex rm -f GIT-VERSION-FILE GIT-GUI-VARS -.PHONY: all install dist-version clean +.PHONY: all install uninstall dist-version clean .PHONY: .FORCE-GIT-VERSION-FILE .PHONY: .FORCE-GIT-GUI-VARS -- cgit v1.2.3 From 55bad4f096b1f18eec94169c864c39bf0abda1db Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 13 Sep 2007 20:08:53 -0400 Subject: git-gui: Paper bag fix "Commit->Revert" format arguments The recent bug fix to correctly handle filenames with %s (or any other valid Tcl format specifier) missed a \ on this line and caused the remaining format arguments to not be supplied when we updated the status bar. This caused a Tcl error anytime the user was trying to perform a file revert. Signed-off-by: Shawn O. Pearce --- lib/index.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.tcl b/lib/index.tcl index cbbce13a77..44689ab63b 100644 --- a/lib/index.tcl +++ b/lib/index.tcl @@ -168,7 +168,7 @@ proc checkout_index {msg pathList after} { ui_status [format \ "%s... %i/%i files (%.2f%%)" \ - $msg + $msg \ $update_index_cp \ $totalCnt \ 0.0] -- cgit v1.2.3 From 3849bfba84fb5b0e9d46920f62105b4e1dd97e63 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 16 Sep 2007 23:12:19 -0400 Subject: git-gui: Disable native platform text selection in "lists" Sometimes we use a Tk text widget as though it were a listbox. This happens typically when we want to show an icon to the left of the text label or just when a text widget is generally a better choice then the native listbox widget. In these cases if we want the user to have control over the selection we implement our own "in_sel" tag that shows the selected region and we perform our own selection management in the background via keybindings and mouse bindings. In such uses we don't want the user to be able to activate the native platform selection by dragging their mouse through the text widget. Doing so creates a very confusing display and the user is left wondering what it may mean to have two different types of selection in the same widget. Tk doesn't allow us to delete the "sel" tag that it uses internally to manage the native selection but it will allow us to make it invisible by setting the tag to have the same display properties as unselected text. So long as we don't actually use the "sel" tag for anything in code its effectively invisible. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 14 ++++++++++++-- lib/browser.tcl | 4 +--- lib/choose_font.tcl | 9 +++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 31a36cb49f..f789e91b66 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -481,6 +481,16 @@ proc tk_optionMenu {w varName args} { return $m } +proc rmsel_tag {text} { + $text tag conf sel \ + -background [$text cget -background] \ + -foreground [$text cget -foreground] \ + -borderwidth 0 + $text tag conf in_sel -background lightgray + bind $text break + return $text +} + ###################################################################### ## ## find git @@ -2151,8 +2161,8 @@ pack $ui_workdir -side left -fill both -expand 1 .vpane.files add .vpane.files.workdir -sticky nsew foreach i [list $ui_index $ui_workdir] { - $i tag conf in_diff -background lightgray - $i tag conf in_sel -background lightgray + rmsel_tag $i + $i tag conf in_diff -background [$i tag cget in_sel -background] } unset i diff --git a/lib/browser.tcl b/lib/browser.tcl index 888db3c889..31349009ae 100644 --- a/lib/browser.tcl +++ b/lib/browser.tcl @@ -47,9 +47,7 @@ constructor new {commit {path {}}} { -width 70 \ -xscrollcommand [list $w.list.sbx set] \ -yscrollcommand [list $w.list.sby set] - $w_list tag conf in_sel \ - -background [$w_list cget -foreground] \ - -foreground [$w_list cget -background] + rmsel_tag $w_list scrollbar $w.list.sbx -orient h -command [list $w_list xview] scrollbar $w.list.sby -orient v -command [list $w_list yview] pack $w.list.sbx -side bottom -fill x diff --git a/lib/choose_font.tcl b/lib/choose_font.tcl index b69215c91e..0c4051b375 100644 --- a/lib/choose_font.tcl +++ b/lib/choose_font.tcl @@ -62,6 +62,7 @@ constructor pick {path title a_family a_size} { -width 30 \ -height 10 \ -yscrollcommand [list $w.inner.family.sby set] + rmsel_tag $w_family scrollbar $w.inner.family.sby -command [list $w_family yview] pack $w.inner.family.l -side top -fill x pack $w.inner.family.sby -side right -fill y @@ -95,6 +96,7 @@ constructor pick {path title a_family a_size} { -relief sunken \ -height 3 \ -width 40 + rmsel_tag $w_example $w_example tag conf example -justify center $w_example insert end [mc "This is example text.\nIf you like this text, it can be your font."] example $w_example conf -state disabled @@ -108,11 +110,10 @@ constructor pick {path title a_family a_size} { $w_family tag conf pick $w_family tag bind pick [cb _pick_family %x %y]\;break - $w_family tag conf cpck -background lightgray foreach f $all_families { set sel [list pick] if {$f eq $f_family} { - lappend sel cpck + lappend sel in_sel } $w_family insert end "$f\n" $sel } @@ -145,8 +146,8 @@ method _pick_family {x y} { set i [lindex [split [$w_family index @$x,$y] .] 0] set n [lindex $all_families [expr {$i - 1}]] if {$n ne {}} { - $w_family tag remove cpck 0.0 end - $w_family tag add cpck $i.0 [expr {$i + 1}].0 + $w_family tag remove in_sel 0.0 end + $w_family tag add in_sel $i.0 [expr {$i + 1}].0 set f_family $n _update $this } -- cgit v1.2.3 From be510cfef3d8344007bd34128ca6eb799b714c8c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 17 Sep 2007 21:18:20 -0700 Subject: send-email: make message-id generation a bit more robust Earlier code took Unix time and appended a few random digits. If you are firing off many messages within a second, you could issue the same id to different messages, which is a no-no. If you send out 31 messages within a single second, with random integer taken out of rand(4200), you have about 10% chance of producing the same message ID. This fixes the problem by uses a prefix string which is constant-per-invocation (time and pid), with a serial number for each message generated by the process appended at the end. Signed-off-by: Junio C Hamano --- git-send-email.perl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 195fe6f70a..9547cc37a1 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -437,10 +437,17 @@ sub extract_valid_address { # We'll setup a template for the message id, using the "from" address: +my ($message_id_stamp, $message_id_serial); sub make_message_id { - my $date = time; - my $pseudo_rand = int (rand(4200)); + my $uniq; + if (!defined $message_id_stamp) { + $message_id_stamp = sprintf("%s-%s", time, $$); + $message_id_serial = 0; + } + $message_id_serial++; + $uniq = "$message_id_stamp-$message_id_serial"; + my $du_part; for ($sender, $repocommitter, $repoauthor) { $du_part = extract_valid_address(sanitize_address($_)); @@ -450,8 +457,8 @@ sub make_message_id use Sys::Hostname qw(); $du_part = 'user@' . Sys::Hostname::hostname(); } - my $message_id_template = "<%s-git-send-email-$du_part>"; - $message_id = sprintf $message_id_template, "$date$pseudo_rand"; + my $message_id_template = "<%s-git-send-email-%s>"; + $message_id = sprintf($message_id_template, $uniq, $du_part); #print "new message id = $message_id\n"; # Was useful for debugging } -- cgit v1.2.3 From 64586e75af3c84844b80652575a8b63a9612b24a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 12 Sep 2007 16:04:22 -0700 Subject: git-commit: Allow partial commit of file removal. When making a partial commit, git-commit uses git-ls-files with the --error-unmatch option to expand and sanity check the user supplied path patterns. When any path pattern does not match with the paths known to the index, it errors out, in order to catch a common mistake to say "git commit Makefiel cache.h" and end up with a commit that touches only cache.h (notice the misspelled "Makefile"). This detection however does not work well when the path has already been removed from the index. If you drop a path from the index and try to commit that partially, i.e. $ git rm COPYING $ git commit -m 'Remove COPYING' COPYING the command complains because git does not know anything about COPYING anymore. This introduces a new option --with-tree to git-ls-files and uses it in git-commit when we build a temporary index to write a tree object for the partial commit. When --with-tree= option is specified, names from the given tree are added to the set of names the index knows about, so we can treat COPYING file in the example as known. Of course, there is no reason to use "git rm" and git-aware people have long time done: $ rm COPYING $ git commit -m 'Remove COPYING' COPYING which works just fine. But this caused a constant confusion. Signed-off-by: Junio C Hamano --- builtin-ls-files.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ git-commit.sh | 5 +++- t/t7501-commit.sh | 21 +++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/builtin-ls-files.c b/builtin-ls-files.c index cce17b5ced..6c1db86e80 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -9,6 +9,7 @@ #include "quote.h" #include "dir.h" #include "builtin.h" +#include "tree.h" static int abbrev; static int show_deleted; @@ -26,6 +27,7 @@ static int prefix_offset; static const char **pathspec; static int error_unmatch; static char *ps_matched; +static const char *with_tree; static const char *tag_cached = ""; static const char *tag_unmerged = ""; @@ -247,6 +249,8 @@ static void show_files(struct dir_struct *dir, const char *prefix) continue; if (show_unmerged && !ce_stage(ce)) continue; + if (ce->ce_flags & htons(CE_UPDATE)) + continue; show_ce_entry(ce_stage(ce) ? tag_unmerged : tag_cached, ce); } } @@ -332,6 +336,67 @@ static const char *verify_pathspec(const char *prefix) return real_prefix; } +/* + * Read the tree specified with --with-tree option + * (typically, HEAD) into stage #1 and then + * squash them down to stage #0. This is used for + * --error-unmatch to list and check the path patterns + * that were given from the command line. We are not + * going to write this index out. + */ +static void overlay_tree(const char *tree_name, const char *prefix) +{ + struct tree *tree; + unsigned char sha1[20]; + const char **match; + struct cache_entry *last_stage0 = NULL; + int i; + + if (get_sha1(tree_name, sha1)) + die("tree-ish %s not found.", tree_name); + tree = parse_tree_indirect(sha1); + if (!tree) + die("bad tree-ish %s", tree_name); + + /* Hoist the unmerged entries up to stage #3 to make room */ + for (i = 0; i < active_nr; i++) { + struct cache_entry *ce = active_cache[i]; + if (!ce_stage(ce)) + continue; + ce->ce_flags |= htons(CE_STAGEMASK); + } + + if (prefix) { + static const char *(matchbuf[2]); + matchbuf[0] = prefix; + matchbuf [1] = NULL; + match = matchbuf; + } else + match = NULL; + if (read_tree(tree, 1, match)) + die("unable to read tree entries %s", tree_name); + + for (i = 0; i < active_nr; i++) { + struct cache_entry *ce = active_cache[i]; + switch (ce_stage(ce)) { + case 0: + last_stage0 = ce; + /* fallthru */ + default: + continue; + case 1: + /* + * If there is stage #0 entry for this, we do not + * need to show it. We use CE_UPDATE bit to mark + * such an entry. + */ + if (last_stage0 && + !strcmp(last_stage0->name, ce->name)) + ce->ce_flags |= htons(CE_UPDATE); + } + } +} + static const char ls_files_usage[] = "git-ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* " "[ --ignored ] [--exclude=] [--exclude-from=] " @@ -452,6 +517,10 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) error_unmatch = 1; continue; } + if (!prefixcmp(arg, "--with-tree=")) { + with_tree = arg + 12; + continue; + } if (!prefixcmp(arg, "--abbrev=")) { abbrev = strtoul(arg+9, NULL, 10); if (abbrev && abbrev < MINIMUM_ABBREV) @@ -503,6 +572,15 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) read_cache(); if (prefix) prune_cache(prefix); + if (with_tree) { + /* + * Basic sanity check; show-stages and show-unmerged + * would not make any sense with this option. + */ + if (show_stage || show_unmerged) + die("ls-files --with-tree is incompatible with -s or -u"); + overlay_tree(with_tree, prefix); + } show_files(&dir, prefix); if (ps_matched) { diff --git a/git-commit.sh b/git-commit.sh index 41538f16e5..5ea3fd0076 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -379,8 +379,11 @@ t,) then refuse_partial "Cannot do a partial commit during a merge." fi + TMP_INDEX="$GIT_DIR/tmp-index$$" - commit_only=`git ls-files --error-unmatch -- "$@"` || exit + W= + test -z "$initial_commit" && W=--with-tree=HEAD + commit_only=`git ls-files --error-unmatch $W -- "$@"` || exit # Build a temporary index and update the real index # the same way. diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index 6bd3c9e3e0..f178f56208 100644 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -131,4 +131,25 @@ test_expect_success \ 'validate git-rev-list output.' \ 'diff current expected' +test_expect_success 'partial commit that involve removal (1)' ' + + git rm --cached file && + mv file elif && + git add elif && + git commit -m "Partial: add elif" elif && + git diff-tree --name-status HEAD^ HEAD >current && + echo "A elif" >expected && + diff expected current + +' + +test_expect_success 'partial commit that involve removal (2)' ' + + git commit -m "Partial: remove file" file && + git diff-tree --name-status HEAD^ HEAD >current && + echo "D file" >expected && + diff expected current + +' + test_done -- cgit v1.2.3 From cba8d4896187abedd9c35936504b7254a2ecbd91 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Sep 2007 16:53:58 -0700 Subject: git-commit: partial commit of paths only removed from the index Because a partial commit is meant to be a way to ignore what are staged in the index, "git rm --cached A && git commit A" should just record what is in A on the filesystem. The previous patch made the command sequence to barf, saying that A has not been added yet. This fixes it. Signed-off-by: Junio C Hamano --- git-commit.sh | 2 +- t/t7501-commit.sh | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/git-commit.sh b/git-commit.sh index 5ea3fd0076..bb113e858b 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -404,7 +404,7 @@ t,) ( GIT_INDEX_FILE="$NEXT_INDEX" export GIT_INDEX_FILE - git update-index --remove --stdin + git update-index --add --remove --stdin ) || exit ;; esac diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index f178f56208..b151b51a34 100644 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -131,7 +131,7 @@ test_expect_success \ 'validate git-rev-list output.' \ 'diff current expected' -test_expect_success 'partial commit that involve removal (1)' ' +test_expect_success 'partial commit that involves removal (1)' ' git rm --cached file && mv file elif && @@ -143,7 +143,7 @@ test_expect_success 'partial commit that involve removal (1)' ' ' -test_expect_success 'partial commit that involve removal (2)' ' +test_expect_success 'partial commit that involves removal (2)' ' git commit -m "Partial: remove file" file && git diff-tree --name-status HEAD^ HEAD >current && @@ -152,4 +152,15 @@ test_expect_success 'partial commit that involve removal (2)' ' ' +test_expect_success 'partial commit that involves removal (3)' ' + + git rm --cached elif && + echo elif >elif && + git commit -m "Partial: modify elif" elif && + git diff-tree --name-status HEAD^ HEAD >current && + echo "M elif" >expected && + diff expected current + +' + test_done -- cgit v1.2.3 From 7a461b5a33239cfba3bbf0a1deef544c7f1dcfeb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Sep 2007 16:59:04 -0700 Subject: Document ls-files --with-tree= Signed-off-by: Junio C Hamano --- Documentation/git-ls-files.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt index 997594549f..9e454f0a4d 100644 --- a/Documentation/git-ls-files.txt +++ b/Documentation/git-ls-files.txt @@ -15,7 +15,7 @@ SYNOPSIS [-x |--exclude=] [-X |--exclude-from=] [--exclude-per-directory=] - [--error-unmatch] + [--error-unmatch] [--with-tree=] [--full-name] [--abbrev] [--] []\* DESCRIPTION @@ -81,6 +81,13 @@ OPTIONS If any does not appear in the index, treat this as an error (return 1). +--with-tree=:: + When using --error-unmatch to expand the user supplied + (i.e. path pattern) arguments to paths, pretend + that paths which were removed in the index since the + named are still present. Using this option + with `-s` or `-u` options does not make any sense. + -t:: Identify the file status with the following tags (followed by a space) at the start of each line: -- cgit v1.2.3