From 8f4893639129acfc866c71583317090aa2a46eab Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Fri, 13 Jul 2007 19:49:37 +1000 Subject: [PATCH 001/131] gitk: Show changes in index and changes in working directory separately This makes gitk show up to two fake commits when there are local changes in the repository; one to represent the state of the index and one to represent the state of the working directory. The commit representing the working directory is colored red as before; the commit representing the index state is colored magenta (as being between red and blue in some sense). Signed-off-by: Paul Mackerras --- gitk | 197 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 139 insertions(+), 58 deletions(-) diff --git a/gitk b/gitk index 39e452aba9..7ce86b849e 100755 --- a/gitk +++ b/gitk @@ -262,11 +262,11 @@ proc chewcommits {view} { set tlimit [expr {[clock clicks -milliseconds] + 50}] set more [layoutmore $tlimit $allread] if {$allread && !$more} { - global displayorder nullid commitidx phase + global displayorder commitidx phase global numcommits startmsecs if {[info exists pending_select]} { - set row [expr {[lindex $displayorder 0] eq $nullid}] + set row [first_real_row] selectline $row 1 } if {$commitidx($curview) > 0} { @@ -437,6 +437,19 @@ proc readrefs {} { } } +# skip over fake commits +proc first_real_row {} { + global nullid nullid2 displayorder numcommits + + for {set row 0} {$row < $numcommits} {incr row} { + set id [lindex $displayorder $row] + if {$id ne $nullid && $id ne $nullid2} { + break + } + } + return $row +} + # update things for a head moved to a child of its previous location proc movehead {id name} { global headids idheads @@ -1871,7 +1884,7 @@ proc showview {n} { } elseif {$selid ne {}} { set pending_select $selid } else { - set row [expr {[lindex $displayorder 0] eq $nullid}] + set row [first_real_row] if {$row < $numcommits} { selectline $row 0 } else { @@ -2643,7 +2656,7 @@ proc layoutmore {tmax allread} { proc showstuff {canshow last} { global numcommits commitrow pending_select selectedline curview - global lookingforhead mainheadid displayorder nullid selectfirst + global lookingforhead mainheadid displayorder selectfirst global lastscrollset if {$numcommits == 0} { @@ -2676,7 +2689,7 @@ proc showstuff {canshow last} { if {[info exists selectedline] || [info exists pending_select]} { set selectfirst 0 } else { - set l [expr {[lindex $displayorder 0] eq $nullid}] + set l [first_real_row] selectline $l 1 set selectfirst 0 } @@ -2700,48 +2713,93 @@ proc doshowlocalchanges {} { } proc dohidelocalchanges {} { - global lookingforhead localrow lserial + global lookingforhead localfrow localirow lserial set lookingforhead 0 - if {$localrow >= 0} { - removerow $localrow - set localrow -1 + if {$localfrow >= 0} { + removerow $localfrow + set localfrow -1 + if {$localirow > 0} { + incr localirow -1 + } + } + if {$localirow >= 0} { + removerow $localirow + set localirow -1 } incr lserial } -# spawn off a process to do git diff-index HEAD +# spawn off a process to do git diff-index --cached HEAD proc dodiffindex {} { - global localrow lserial + global localirow localfrow lserial incr lserial - set localrow -1 - set fd [open "|git diff-index HEAD" r] + set localfrow -1 + set localirow -1 + set fd [open "|git diff-index --cached HEAD" r] fconfigure $fd -blocking 0 filerun $fd [list readdiffindex $fd $lserial] } proc readdiffindex {fd serial} { - global localrow commitrow mainheadid nullid curview + global localirow commitrow mainheadid nullid2 curview global commitinfo commitdata lserial + set isdiff 1 if {[gets $fd line] < 0} { - if {[eof $fd]} { - close $fd - return 0 + if {![eof $fd]} { + return 1 } - return 1 + set isdiff 0 } # we only need to see one line and we don't really care what it says... close $fd - if {$serial == $lserial && $localrow == -1} { + # now see if there are any local changes not checked in to the index + if {$serial == $lserial} { + set fd [open "|git diff-files" r] + fconfigure $fd -blocking 0 + filerun $fd [list readdifffiles $fd $serial] + } + + if {$isdiff && $serial == $lserial && $localirow == -1} { + # add the line for the changes in the index to the graph + set localirow $commitrow($curview,$mainheadid) + set hl "Local changes checked in to index but not committed" + set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"] + set commitdata($nullid2) "\n $hl\n" + insertrow $localirow $nullid2 + } + return 0 +} + +proc readdifffiles {fd serial} { + global localirow localfrow commitrow mainheadid nullid curview + global commitinfo commitdata lserial + + set isdiff 1 + if {[gets $fd line] < 0} { + if {![eof $fd]} { + return 1 + } + set isdiff 0 + } + # we only need to see one line and we don't really care what it says... + close $fd + + if {$isdiff && $serial == $lserial && $localfrow == -1} { # add the line for the local diff to the graph - set localrow $commitrow($curview,$mainheadid) - set hl "Local uncommitted changes" + if {$localirow >= 0} { + set localfrow $localirow + incr localirow + } else { + set localfrow $commitrow($curview,$mainheadid) + } + set hl "Local uncommitted changes, not checked in to index" set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"] set commitdata($nullid) "\n $hl\n" - insertrow $localrow $nullid + insertrow $localfrow $nullid } return 0 } @@ -3338,12 +3396,14 @@ proc drawcmittext {id row col} { global commitlisted commitinfo rowidlist parentlist global rowtextx idpos idtags idheads idotherrefs global linehtag linentag linedtag markingmatches - global mainfont canvxmax boldrows boldnamerows fgcolor nullid + global mainfont canvxmax boldrows boldnamerows fgcolor nullid nullid2 # listed is 0 for boundary, 1 for normal, 2 for left, 3 for right set listed [lindex $commitlisted $row] if {$id eq $nullid} { set ofill red + } elseif {$id eq $nullid2} { + set ofill magenta } else { set ofill [expr {$listed != 0? "blue": "white"}] } @@ -4582,16 +4642,19 @@ proc goforw {} { } proc gettree {id} { - global treefilelist treeidlist diffids diffmergeid treepending nullid + global treefilelist treeidlist diffids diffmergeid treepending + global nullid nullid2 set diffids $id catch {unset diffmergeid} if {![info exists treefilelist($id)]} { if {![info exists treepending]} { - if {$id ne $nullid} { - set cmd [concat | git ls-tree -r $id] + if {$id eq $nullid} { + set cmd [list | git ls-files] + } elseif {$id eq $nullid2} { + set cmd [list | git ls-files --stage -t] } else { - set cmd [concat | git ls-files] + set cmd [list | git ls-tree -r $id] } if {[catch {set gtf [open $cmd r]}]} { return @@ -4608,12 +4671,14 @@ proc gettree {id} { } proc gettreeline {gtf id} { - global treefilelist treeidlist treepending cmitmode diffids nullid + global treefilelist treeidlist treepending cmitmode diffids nullid nullid2 set nl 0 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} { - if {$diffids ne $nullid} { - if {[lindex $line 1] ne "blob"} continue + if {$diffids eq $nullid} { + set fname $line + } else { + if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue set i [string first "\t" $line] if {$i < 0} continue set sha1 [lindex $line 2] @@ -4622,8 +4687,6 @@ proc gettreeline {gtf id} { set fname [lindex $fname 0] } lappend treeidlist($id) $sha1 - } else { - set fname $line } lappend treefilelist($id) $fname } @@ -4645,7 +4708,7 @@ proc gettreeline {gtf id} { } proc showfile {f} { - global treefilelist treeidlist diffids nullid + global treefilelist treeidlist diffids nullid nullid2 global ctext commentend set i [lsearch -exact $treefilelist($diffids) $f] @@ -4653,15 +4716,15 @@ proc showfile {f} { puts "oops, $f not in list for id $diffids" return } - if {$diffids ne $nullid} { - set blob [lindex $treeidlist($diffids) $i] - if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} { - puts "oops, error reading blob $blob: $err" + if {$diffids eq $nullid} { + if {[catch {set bf [open $f r]} err]} { + puts "oops, can't read $f: $err" return } } else { - if {[catch {set bf [open $f r]} err]} { - puts "oops, can't read $f: $err" + set blob [lindex $treeidlist($diffids) $i] + if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} { + puts "oops, error reading blob $blob: $err" return } } @@ -4789,11 +4852,13 @@ proc getmergediffline {mdf id np} { } proc startdiff {ids} { - global treediffs diffids treepending diffmergeid nullid + global treediffs diffids treepending diffmergeid nullid nullid2 set diffids $ids catch {unset diffmergeid} - if {![info exists treediffs($ids)] || [lsearch -exact $ids $nullid] >= 0} { + if {![info exists treediffs($ids)] || + [lsearch -exact $ids $nullid] >= 0 || + [lsearch -exact $ids $nullid2] >= 0} { if {![info exists treepending]} { gettreediffs $ids } @@ -4809,22 +4874,41 @@ proc addtocflist {ids} { } proc diffcmd {ids flags} { - global nullid + global nullid nullid2 set i [lsearch -exact $ids $nullid] + set j [lsearch -exact $ids $nullid2] if {$i >= 0} { - set cmd [concat | git diff-index $flags] - if {[llength $ids] > 1} { + if {[llength $ids] > 1 && $j < 0} { + # comparing working directory with some specific revision + set cmd [concat | git diff-index $flags] if {$i == 0} { lappend cmd -R [lindex $ids 1] } else { lappend cmd [lindex $ids 0] } } else { + # comparing working directory with index + set cmd [concat | git diff-files $flags] + if {$j == 1} { + lappend cmd -R + } + } + } elseif {$j >= 0} { + set cmd [concat | git diff-index --cached $flags] + if {[llength $ids] > 1} { + # comparing index with specific revision + if {$i == 0} { + lappend cmd -R [lindex $ids 1] + } else { + lappend cmd [lindex $ids 0] + } + } else { + # comparing index with HEAD lappend cmd HEAD } } else { - set cmd [concat | git diff-tree --no-commit-id -r $flags $ids] + set cmd [concat | git diff-tree -r $flags $ids] } return $cmd } @@ -4834,7 +4918,7 @@ proc gettreediffs {ids} { set treepending $ids set treediff {} - if {[catch {set gdtf [open [diffcmd $ids {}] r]}]} return + if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return fconfigure $gdtf -blocking 0 filerun $gdtf [list gettreediffline $gdtf $ids] } @@ -4877,7 +4961,7 @@ proc getblobdiffs {ids} { global diffinhdr treediffs set env(GIT_DIFF_OPTS) $diffopts - if {[catch {set bdf [open [diffcmd $ids {-p -C}] r]} err]} { + if {[catch {set bdf [open [diffcmd $ids {-p -C --no-commit-id}] r]} err]} { puts "error getting diffs: $err" return } @@ -5468,7 +5552,7 @@ proc mstime {} { proc rowmenu {x y id} { global rowctxmenu commitrow selectedline rowmenuid curview - global nullid fakerowmenu mainhead + global nullid nullid2 fakerowmenu mainhead set rowmenuid $id if {![info exists selectedline] @@ -5477,7 +5561,7 @@ proc rowmenu {x y id} { } else { set state normal } - if {$id ne $nullid} { + if {$id ne $nullid && $id ne $nullid2} { set menu $rowctxmenu $menu entryconfigure 7 -label "Reset $mainhead branch to here" } else { @@ -5596,18 +5680,12 @@ proc mkpatchrev {} { } proc mkpatchgo {} { - global patchtop nullid + global patchtop nullid nullid2 set oldid [$patchtop.fromsha1 get] set newid [$patchtop.tosha1 get] set fname [$patchtop.fname get] - if {$newid eq $nullid} { - set cmd [list git diff-index -p $oldid] - } elseif {$oldid eq $nullid} { - set cmd [list git diff-index -p -R $newid] - } else { - set cmd [list git diff-tree -p $oldid $newid] - } + set cmd [diffcmd [list $oldid $newid] -p] lappend cmd >$fname & if {[catch {eval exec $cmd} err]} { error_popup "Error creating patch: $err" @@ -7522,6 +7600,8 @@ if {$i >= [llength $argv] && $revtreeargs ne {}} { } set nullid "0000000000000000000000000000000000000000" +set nullid2 "0000000000000000000000000000000000000001" + set runq {} set history {} @@ -7550,7 +7630,8 @@ set stopped 0 set stuffsaved 0 set patchnum 0 set lookingforhead 0 -set localrow -1 +set localirow -1 +set localfrow -1 set lserial 0 setcoords makewindow From 99c01de402b543647a6500ceeaca7f62e343b144 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sun, 15 Jul 2007 11:46:11 +0200 Subject: [PATCH 002/131] contrib/emacs/Makefile: Also install .el files. Signed-off-by: David Kastrup Signed-off-by: Junio C Hamano --- contrib/emacs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/emacs/Makefile b/contrib/emacs/Makefile index 5e94d6fcd3..a48540a92b 100644 --- a/contrib/emacs/Makefile +++ b/contrib/emacs/Makefile @@ -13,7 +13,7 @@ all: $(ELC) install: all $(INSTALL) -d $(DESTDIR)$(emacsdir) - $(INSTALL_ELC) $(ELC) $(DESTDIR)$(emacsdir) + $(INSTALL_ELC) $(ELC:.elc=.el) $(ELC) $(DESTDIR)$(emacsdir) %.elc: %.el $(EMACS) -batch -f batch-byte-compile $< From 29633bb91c7bcff31ff3bb59378709e3e3ef627d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 15 Jul 2007 21:53:50 -0700 Subject: [PATCH 003/131] git-svn: fix commiting renames over DAV with funky file names Renaming files with non-URI friendly characters caused breakage when committing to DAV repositories (over http(s)). Even if I try leaving out the $self->{url} from the return value of url_path(), a partial (without host), unescaped path name does not work. Filenames for DAV repos need to be URI-encoded before being passed to the library. Since this bug did not affect file:// and svn:// repos, the git-svn test library needed to be expanded to include support for starting Apache with mod_dav_svn enabled. This new test is not enabled by default, but can be enabled by setting SVN_HTTPD_PORT to any available TCP/IP port on 127.0.0.1. Additionally, for running this test, the following variables (with defaults shown) can be changed for the suitable system. The default values are set for Debian systems: SVN_HTTPD_MODULE_PATH=/usr/lib/apache2/modules SVN_HTTPD_PATH=/usr/sbin/apache2 Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 3 + t/lib-git-svn.sh | 34 ++++++++ t/t9115-git-svn-dcommit-funky-renames.sh | 54 ++++++++++++ t/t9115/funky-names.dump | 103 +++++++++++++++++++++++ 4 files changed, 194 insertions(+) create mode 100755 t/t9115-git-svn-dcommit-funky-renames.sh create mode 100644 t/t9115/funky-names.dump diff --git a/git-svn.perl b/git-svn.perl index 299b40f938..01c3904271 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -2724,6 +2724,9 @@ sub repo_path { sub url_path { my ($self, $path) = @_; + if ($self->{url} =~ m#^https?://#) { + $path =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; + } $self->{url} . '/' . $self->repo_path($path); } diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh index f6fe78cd27..8d4a447213 100644 --- a/t/lib-git-svn.sh +++ b/t/lib-git-svn.sh @@ -48,3 +48,37 @@ svnrepo="file://$svnrepo" poke() { test-chmtime +1 "$1" } + +SVN_HTTPD_MODULE_PATH=${SVN_HTTPD_MODULE_PATH-'/usr/lib/apache2/modules'} +SVN_HTTPD_PATH=${SVN_HTTPD_PATH-'/usr/sbin/apache2'} + +start_httpd () { + if test -z "$SVN_HTTPD_PORT" + then + echo >&2 'SVN_HTTPD_PORT is not defined!' + return + fi + + mkdir "$GIT_DIR"/logs + + cat > "$GIT_DIR/httpd.conf" < + DAV svn + SVNPath $rawsvnrepo + +EOF + "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k start + svnrepo=http://127.0.0.1:$SVN_HTTPD_PORT/svn +} + +stop_httpd () { + test -z "$SVN_HTTPD_PORT" && return + "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k stop +} diff --git a/t/t9115-git-svn-dcommit-funky-renames.sh b/t/t9115-git-svn-dcommit-funky-renames.sh new file mode 100755 index 0000000000..182299cbb5 --- /dev/null +++ b/t/t9115-git-svn-dcommit-funky-renames.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# +# Copyright (c) 2007 Eric Wong + + +test_description='git-svn dcommit can commit renames of files with ugly names' + +. ./lib-git-svn.sh + +test_expect_success 'load repository with strange names' " + svnadmin load -q $rawsvnrepo < ../t9115/funky-names.dump && + start_httpd + " + +test_expect_success 'init and fetch repository' " + git svn init $svnrepo && + git svn fetch && + git reset --hard git-svn + " + +test_expect_success 'create file in existing ugly and empty dir' ' + mkdir "#{bad_directory_name}" && + echo hi > "#{bad_directory_name}/ foo" && + git update-index --add "#{bad_directory_name}/ foo" && + git commit -m "new file in ugly parent" && + git svn dcommit + ' + +test_expect_success 'rename ugly file' ' + git mv "#{bad_directory_name}/ foo" "file name with feces" && + git commit -m "rename ugly file" && + git svn dcommit + ' + +test_expect_success 'rename pretty file' ' + echo :x > pretty && + git update-index --add pretty && + git commit -m "pretty :x" && + git svn dcommit && + mkdir regular_dir_name && + git mv pretty regular_dir_name/pretty && + git commit -m "moved pretty file" && + git svn dcommit + ' + +test_expect_success 'rename pretty file into ugly one' ' + git mv regular_dir_name/pretty "#{bad_directory_name}/ booboo" && + git commit -m booboo && + git svn dcommit + ' + +stop_httpd + +test_done diff --git a/t/t9115/funky-names.dump b/t/t9115/funky-names.dump new file mode 100644 index 0000000000..42422f791e --- /dev/null +++ b/t/t9115/funky-names.dump @@ -0,0 +1,103 @@ +SVN-fs-dump-format-version: 2 + +UUID: 819c44fe-2bcc-4066-88e4-985e2bc0b418 + +Revision-number: 0 +Prop-content-length: 56 +Content-length: 56 + +K 8 +svn:date +V 27 +2007-07-12T07:54:26.062914Z +PROPS-END + +Revision-number: 1 +Prop-content-length: 152 +Content-length: 152 + +K 7 +svn:log +V 44 +what will those wacky people think of next? + +K 10 +svn:author +V 12 +normalperson +K 8 +svn:date +V 27 +2007-07-12T08:00:05.011573Z +PROPS-END + +Node-path: leading space +Node-kind: dir +Node-action: add +Prop-content-length: 10 +Content-length: 10 + +PROPS-END + + +Node-path: leading space file +Node-kind: file +Node-action: add +Prop-content-length: 10 +Text-content-length: 5 +Text-content-md5: e4fa20c67542cdc21271e08d329397ab +Content-length: 15 + +PROPS-END +ugly + + +Node-path: #{bad_directory_name} +Node-kind: dir +Node-action: add +Prop-content-length: 10 +Content-length: 10 + +PROPS-END + + +Node-path: #{cool_name} +Node-kind: file +Node-action: add +Prop-content-length: 10 +Text-content-length: 18 +Text-content-md5: 87dac40ca337dfa3dcc8911388c3ddda +Content-length: 28 + +PROPS-END +strange name here + + +Node-path: dir name with spaces +Node-kind: dir +Node-action: add +Prop-content-length: 10 +Content-length: 10 + +PROPS-END + + +Node-path: file name with spaces +Node-kind: file +Node-action: add +Prop-content-length: 10 +Text-content-length: 7 +Text-content-md5: c1f10cfd640618484a2a475c11410fd3 +Content-length: 17 + +PROPS-END +spaces + + +Node-path: regular_dir_name +Node-kind: dir +Node-action: add +Prop-content-length: 10 +Content-length: 10 + +PROPS-END From 2dfa54c6cb39c443652440f1ee6fdf5a6067364a Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 16 Jul 2007 02:39:07 -0400 Subject: [PATCH 004/131] git-gui: Skip -dirty suffix on core git versions If the user is running a 'dirty' version of git (one compiled in a working directory with modified files) we want to just assume it was a committed version, as we really only look at the part that came from a real annotated tag anyway. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/git-gui.sh b/git-gui.sh index 2077261e64..bdb557184e 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -544,6 +544,7 @@ if {![regsub {^git version } $_git_version {} _git_version]} { error_popup "Cannot parse Git version string:\n\n$_git_version" exit 1 } +regsub {-dirty$} $_git_version {} _git_version regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version regsub {\.rc[0-9]+$} $_git_version {} _git_version From ec4fceece4a9f155afcadec254caff5cef781c67 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 16 Jul 2007 18:44:23 -0400 Subject: [PATCH 005/131] git-gui: Brown paper bag "dirty git version fix" My prior change to allow git-gui to run with a version of Git that was built from a working directory that had uncommitted changes didn't account for the pattern starting with -, and that confused Tcl. 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 bdb557184e..38084515cb 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -544,7 +544,7 @@ if {![regsub {^git version } $_git_version {} _git_version]} { error_popup "Cannot parse Git version string:\n\n$_git_version" exit 1 } -regsub {-dirty$} $_git_version {} _git_version +regsub -- {-dirty$} $_git_version {} _git_version regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version regsub {\.rc[0-9]+$} $_git_version {} _git_version From 33b1f3d54406dce2cc9cbed35993e55829a94626 Mon Sep 17 00:00:00 2001 From: Francis Moreau Date: Mon, 16 Jul 2007 13:38:47 +0200 Subject: [PATCH 006/131] Fix git-branch documentation when using remote refs Signed-off-by: Francis Moreau Signed-off-by: Junio C Hamano --- Documentation/git-branch.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index bb6b57dc2d..bc6aa88417 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -130,8 +130,8 @@ Delete unneeded branch:: ------------ $ git clone git://git.kernel.org/.../git.git my.git $ cd my.git -$ git branch -d -r todo html man <1> -$ git branch -D test <2> +$ git branch -d -r origin/todo origin/html origin/man <1> +$ git branch -D test <2> ------------ + <1> delete remote-tracking branches "todo", "html", "man" From 6eb420ef61317b2efa2993868a6302afed6ae60a Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 17 Jul 2007 01:50:10 -0400 Subject: [PATCH 007/131] git-gui: Always disable the Tcl EOF character when reading On Windows (which includes Cygwin) Tcl defaults to leaving the EOF character of input file streams set to the ASCII EOF character, but if that character were to appear in the data stream then Tcl will close the channel early. So we have to disable eofchar on Windows. Since the default is disabled on all platforms except Windows, we can just disable it everywhere to prevent any sort of read problem. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 2 ++ lib/blame.tcl | 1 + lib/commit.tcl | 2 +- lib/diff.tcl | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/git-gui.sh b/git-gui.sh index 38084515cb..d0b75c044c 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -414,6 +414,7 @@ proc _open_stdout_stderr {cmd} { error $err } } + fconfigure $fd -eofchar {} return $fd } @@ -828,6 +829,7 @@ proc load_message {file} { if {[catch {set fd [open $f r]}]} { return 0 } + fconfigure $fd -eofchar {} set content [string trim [read $fd]] close $fd regsub -all -line {[ \r\t]+$} $content {} content diff --git a/lib/blame.tcl b/lib/blame.tcl index 4bdb9a27a3..1bcb4b471f 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -370,6 +370,7 @@ method _load {jump} { $w_path conf -text [escape_path $path] if {$commit eq {}} { set fd [open $path r] + fconfigure $fd -eofchar {} } else { set fd [git_read cat-file blob "$commit:$path"] } diff --git a/lib/commit.tcl b/lib/commit.tcl index 46a78c158f..0f3b16dfeb 100644 --- a/lib/commit.tcl +++ b/lib/commit.tcl @@ -209,7 +209,7 @@ A good commit message has the following format: ui_status {Calling pre-commit hook...} set pch_error {} set fd_ph [open "| $pchook" r] - fconfigure $fd_ph -blocking 0 -translation binary + fconfigure $fd_ph -blocking 0 -translation binary -eofchar {} fileevent $fd_ph readable \ [list commit_prehook_wait $fd_ph $curHEAD $msg] } diff --git a/lib/diff.tcl b/lib/diff.tcl index 9cb9d0604a..e09e1257e1 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -86,6 +86,7 @@ proc show_diff {path w {lno {}}} { 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] From 9f90c7335e223c26d19f3c01a6d89e6c0cd8b827 Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Sun, 15 Jul 2007 20:58:10 -0700 Subject: [PATCH 008/131] git-p4: use subprocess in p4CmdList This allows bidirectional piping - useful for "-x -" to avoid commandline arguments - and is a step toward bypassing the shell. Signed-off-by: Scott Lamb Signed-off-by: Simon Hausmann --- contrib/fast-import/git-p4 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index d877150f41..d93e656155 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -63,21 +63,34 @@ def system(cmd): if os.system(cmd) != 0: die("command failed: %s" % cmd) -def p4CmdList(cmd): +def p4CmdList(cmd, stdin=None, stdin_mode='w+b'): cmd = "p4 -G %s" % cmd if verbose: sys.stderr.write("Opening pipe: %s\n" % cmd) - pipe = os.popen(cmd, "rb") + + # Use a temporary file to avoid deadlocks without + # subprocess.communicate(), which would put another copy + # of stdout into memory. + stdin_file = None + if stdin is not None: + stdin_file = tempfile.TemporaryFile(prefix='p4-stdin', mode=stdin_mode) + stdin_file.write(stdin) + stdin_file.flush() + stdin_file.seek(0) + + p4 = subprocess.Popen(cmd, shell=True, + stdin=stdin_file, + stdout=subprocess.PIPE) result = [] try: while True: - entry = marshal.load(pipe) + entry = marshal.load(p4.stdout) result.append(entry) except EOFError: pass - exitCode = pipe.close() - if exitCode != None: + exitCode = p4.wait() + if exitCode != 0: entry = {} entry["p4ExitCode"] = exitCode result.append(entry) From 788001908c8960daa162c32baf3dc0f9ad1c16f8 Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Sun, 15 Jul 2007 20:58:11 -0700 Subject: [PATCH 009/131] git-p4: input to "p4 files" by stdin instead of arguments This approach, suggested by Alex Riesen, bypasses the need for xargs-style argument list handling. The handling in question looks broken in a corner case with SC_ARG_MAX=4096 and final argument over 96 characters. Signed-off-by: Scott Lamb Signed-off-by: Simon Hausmann --- contrib/fast-import/git-p4 | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index d93e656155..54053e3f3d 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -725,27 +725,13 @@ class P4Sync(Command): if not files: return - # We cannot put all the files on the command line - # OS have limitations on the max lenght of arguments - # POSIX says it's 4096 bytes, default for Linux seems to be 130 K. - # and all OS from the table below seems to be higher than POSIX. - # See http://www.in-ulm.de/~mascheck/various/argmax/ - if (self.isWindows): - argmax = 2000 - else: - argmax = min(4000, os.sysconf('SC_ARG_MAX')) - - chunk = '' - filedata = [] - for i in xrange(len(files)): - f = files[i] - chunk += '"%s#%s" ' % (f['path'], f['rev']) - if len(chunk) > argmax or i == len(files)-1: - data = p4CmdList('print %s' % chunk) - if "p4ExitCode" in data[0]: - die("Problems executing p4. Error: [%d]." % (data[0]['p4ExitCode'])); - filedata.extend(data) - chunk = '' + filedata = p4CmdList('-x - print', + stdin='\n'.join(['%s#%s' % (f['path'], f['rev']) + for f in files]), + stdin_mode='w+') + if "p4ExitCode" in filedata[0]: + die("Problems executing p4. Error: [%d]." + % (filedata[0]['p4ExitCode'])); j = 0; contents = {} From 726f9bced9717fb8b3c1e91228be1cdce514a98e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 16 Jul 2007 23:59:54 -0700 Subject: [PATCH 010/131] Update INSTALL We haven't used bignum in rev-list from openssl nor elsewhere for a long time. Also git-gui is now part of git.git itself, and depends on wish. Signed-off-by: Junio C Hamano --- INSTALL | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/INSTALL b/INSTALL index 63ba1480a6..79e71b6922 100644 --- a/INSTALL +++ b/INSTALL @@ -56,9 +56,8 @@ Issues of note: - "zlib", the compression library. Git won't build without it. - - "openssl". The git-rev-list program uses bignum support from - openssl, and unless you specify otherwise, you'll also get the - SHA1 library from here. + - "openssl". Unless you specify otherwise, you'll get the SHA1 + library from here. If you don't have openssl, you can use one of the SHA1 libraries that come with git (git includes the one from Mozilla, and has @@ -73,7 +72,7 @@ Issues of note: management over DAV. Similar to "curl" above, this is optional. - "wish", the Tcl/Tk windowing shell is used in gitk to show the - history graphically + history graphically, and in git-gui. - "ssh" is used to push and pull over the net From 91464dfb102d6143182d8f312b68486e9dceb103 Mon Sep 17 00:00:00 2001 From: Julian Phillips Date: Tue, 17 Jul 2007 22:14:06 +0100 Subject: [PATCH 011/131] git-gui: Handle git versions of the form n.n.n.GIT The git-gui version check doesn't handle versions of the form n.n.n.GIT which you can get by installing from an tarball produced by git-archive. Without this change you get an error of the form: 'Error in startup script: expected version number but got "1.5.3.GIT"' Signed-off-by: Julian Phillips Signed-off-by: Shawn O. Pearce --- git-gui.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/git-gui.sh b/git-gui.sh index d0b75c044c..ebc270866e 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -548,6 +548,7 @@ if {![regsub {^git version } $_git_version {} _git_version]} { regsub -- {-dirty$} $_git_version {} _git_version regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version regsub {\.rc[0-9]+$} $_git_version {} _git_version +regsub {\.GIT$} $_git_version {} _git_version proc git-version {args} { global _git_version From 6f62b4f782c51bdf0dfdef3da5b5049c9006ff70 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 17 Jul 2007 22:31:16 -0400 Subject: [PATCH 012/131] git-gui: Delay searching for 'nice' until its really asked for Not every caller of 'git' or 'git_pipe' wants to use nice to lower the priority of the process its executing. In many cases we may never use the nice process to launch git. So we can avoid searching our $PATH to locate a suitable nice if we'll never actually use it. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index ebc270866e..5ca946a184 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -367,16 +367,25 @@ proc _which {what} { return {} } +proc _lappend_nice {cmd_var} { + global _nice + upvar $cmd_var cmd + + if {![info exists _nice]} { + set _nice [_which nice] + } + if {$_nice ne {}} { + lappend cmd $_nice + } +} + proc git {args} { set opt [list exec] while {1} { switch -- [lindex $args 0] { --nice { - global _nice - if {$_nice ne {}} { - lappend opt $_nice - } + _lappend_nice opt } default { @@ -424,10 +433,7 @@ proc git_read {args} { while {1} { switch -- [lindex $args 0] { --nice { - global _nice - if {$_nice ne {}} { - lappend opt $_nice - } + _lappend_nice opt } --stderr { @@ -455,10 +461,7 @@ proc git_write {args} { while {1} { switch -- [lindex $args 0] { --nice { - global _nice - if {$_nice ne {}} { - lappend opt $_nice - } + _lappend_nice opt } default { @@ -525,7 +528,6 @@ if {$_git eq {}} { error_popup "Cannot find git in PATH." exit 1 } -set _nice [_which nice] ###################################################################### ## From 2370164f3ceb833b9b4128d80bdfcc81e58682f9 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 17 Jul 2007 22:45:53 -0400 Subject: [PATCH 013/131] git-gui: Don't crash in ask_popup if we haven't mapped main window yet If we have more than our desired number of objects and we try to open the "Do you want to repack now?" dialog we cannot include a -parent . argument if the main window has not been mapped yet. On Mac OS X it appears this window isn't mapped right away, so we had better hang avoid including it. Signed-off-by: Shawn O. Pearce --- lib/error.tcl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/error.tcl b/lib/error.tcl index d0253ae2ff..16a22187b2 100644 --- a/lib/error.tcl +++ b/lib/error.tcl @@ -51,12 +51,15 @@ proc ask_popup {msg} { if {[reponame] ne {}} { append title " ([reponame])" } - return [tk_messageBox \ - -parent . \ + set cmd [list tk_messageBox \ -icon question \ -type yesno \ -title $title \ -message $msg] + if {[winfo ismapped .]} { + lappend cmd -parent . + } + eval $cmd } proc hook_failed_popup {hook msg} { From d164b7548ab61e50d4404d1fbc0da3a8f6c0cc87 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 17 Jul 2007 22:49:44 -0400 Subject: [PATCH 014/131] git-gui: Change our initial GC hint to be an estimate Instead of running a full git-count-objects to count all of the loose objects we can get a reasonably close approximation by counting the number of files in the .git/objects/42 subdirectory. This works out reasonably well because the SHA-1 hash has a fairly even distribution, so every .git/objects/?? subdirectory should get a relatively equal number of files. If we have at least 8 files in .git/objects/42 than it is very likely there is about 8 files in every other directory, leaving us with around 2048 loose objects. This check is much faster, as we need to only perform a readdir of a single directory, and we can do it directly from Tcl and avoid the costly fork+exec. All of the credit on how clever this is goes to Linus Torvalds; he suggested using this trick in a post commit hook to repack every so often. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 5ca946a184..cd2b093723 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2560,12 +2560,21 @@ if {[is_enabled transport]} { # -- Only suggest a gc run if we are going to stay running. # if {[is_enabled multicommit]} { - set object_limit 2000 - if {[is_Windows]} {set object_limit 200} - regexp {^([0-9]+) objects,} [git count-objects] _junk objects_current + set object_limit 8 + if {[is_Windows]} { + set object_limit 1 + } + set objects_current [llength [glob \ + -directory [gitdir objects 42] \ + -nocomplain \ + -tails \ + -- \ + *]] if {$objects_current >= $object_limit} { + set objects_current [expr {$objects_current * 256}] + set object_limit [expr {$object_limit * 256}] if {[ask_popup \ - "This repository currently has $objects_current loose objects. + "This repository currently has approximately $objects_current loose objects. To maintain optimal performance it is strongly recommended that you compress the database when more than $object_limit loose objects exist. @@ -2573,7 +2582,7 @@ Compress the database now?"] eq yes} { do_gc } } - unset object_limit _junk objects_current + unset object_limit objects_current } lock_index begin-read From 301dfaa9daeb64c66d616efe50fac29d542c9414 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 17 Jul 2007 23:09:31 -0400 Subject: [PATCH 015/131] git-gui: Let the user continue even if we cannot understand git version Some users may do odd things, like tag their own private version of Git with an annotated tag such as 'testver', then compile that git and try to use it with git-gui. In such a case `git --version` will give us 'git version testver', which is not a numeric argument that we can pass off to our version comparsion routine. We now check that the cleaned up git version is a going to pass the version comparsion routine without failure. If it has a non-numeric component, or lacks at least a minor revision then we ask the user to confirm they really want to use this version of git within git-gui. If they do we shall assume it is git 1.5.0 and run with only the code that will support. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index cd2b093723..2127557f9d 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -547,11 +547,35 @@ if {![regsub {^git version } $_git_version {} _git_version]} { error_popup "Cannot parse Git version string:\n\n$_git_version" exit 1 } + +set _real_git_version $_git_version regsub -- {-dirty$} $_git_version {} _git_version regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version regsub {\.rc[0-9]+$} $_git_version {} _git_version regsub {\.GIT$} $_git_version {} _git_version +if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} { + catch {wm withdraw .} + if {[tk_messageBox \ + -icon warning \ + -type yesno \ + -default no \ + -title "[appname]: warning" \ + -message "Git version cannot be determined. + +$_git claims it is version '$_real_git_version'. + +[appname] requires at least Git 1.5.0 or later. + +Assume '$_real_git_version' is version 1.5.0? +"] eq {yes}} { + set _git_version 1.5.0 + } else { + exit 1 + } +} +unset _real_git_version + proc git-version {args} { global _git_version @@ -2586,4 +2610,7 @@ Compress the database now?"] eq yes} { } lock_index begin-read +if {![winfo ismapped .]} { + wm deiconify . +} after 1 do_rescan From 3972b987d373759ae4868012fe8133ca1e26ea20 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 17 Jul 2007 23:20:56 -0400 Subject: [PATCH 016/131] git-gui: Delay the GC hint until after we are running I'm moving the code related to looking to see if we should GC now into a procedure closer to where it belongs, the database module. This reduces our script by a few lines for the single commit case (aka citool). But really it just is to help organize the code. We now perform the check after we have been running for at least 1 second. This way the main window has time to open up and our dialog (if we open it) will attach to the main window, instead of floating out in no-mans-land like it did before on Mac OS X. I had to use a wait of a full second here as a wait of 1 millisecond made our console install itself into the main window. Apparently we had a race condition with the console code where both the console and the main window thought they were the main window. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 31 +++---------------------------- lib/database.tcl | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 2127557f9d..0443129796 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2581,36 +2581,11 @@ if {[is_enabled transport]} { populate_push_menu } -# -- Only suggest a gc run if we are going to stay running. -# -if {[is_enabled multicommit]} { - set object_limit 8 - if {[is_Windows]} { - set object_limit 1 - } - set objects_current [llength [glob \ - -directory [gitdir objects 42] \ - -nocomplain \ - -tails \ - -- \ - *]] - if {$objects_current >= $object_limit} { - set objects_current [expr {$objects_current * 256}] - set object_limit [expr {$object_limit * 256}] - if {[ask_popup \ - "This repository currently has approximately $objects_current loose objects. - -To maintain optimal performance it is strongly recommended that you compress the database when more than $object_limit loose objects exist. - -Compress the database now?"] eq yes} { - do_gc - } - } - unset object_limit objects_current -} - lock_index begin-read if {![winfo ismapped .]} { wm deiconify . } after 1 do_rescan +if {[is_enabled multicommit]} { + after 1000 hint_gc +} diff --git a/lib/database.tcl b/lib/database.tcl index 87c815d7ac..0657cc2245 100644 --- a/lib/database.tcl +++ b/lib/database.tcl @@ -87,3 +87,30 @@ proc do_fsck_objects {} { lappend cmd --strict console::exec $w $cmd } + +proc hint_gc {} { + set object_limit 8 + if {[is_Windows]} { + set object_limit 1 + } + + set objects_current [llength [glob \ + -directory [gitdir objects 42] \ + -nocomplain \ + -tails \ + -- \ + *]] + + if {$objects_current >= $object_limit} { + set objects_current [expr {$objects_current * 256}] + set object_limit [expr {$object_limit * 256}] + if {[ask_popup \ + "This repository currently has approximately $objects_current loose objects. + +To maintain optimal performance it is strongly recommended that you compress the database when more than $object_limit loose objects exist. + +Compress the database now?"] eq yes} { + do_gc + } + } +} From ba7cc6609e5726ddc59158b60ac01f5fc9717ab3 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 17 Jul 2007 23:23:56 -0400 Subject: [PATCH 017/131] git-gui: Move feature option selection before GIT_DIR init By moving our feature option determination up before we look for GIT_DIR we can make a decision about whether or not we need a working tree up front, before we look for GIT_DIR. A future change could then allow us to start in a bare Git repository if we only need access to the ODB. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 74 +++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 0443129796..f13fa80b46 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -630,6 +630,43 @@ You are using [git-version]: exit 1 } +###################################################################### +## +## feature option selection + +if {[regexp {^git-(.+)$} [appname] _junk subcommand]} { + unset _junk +} else { + set subcommand gui +} +if {$subcommand eq {gui.sh}} { + set subcommand gui +} +if {$subcommand eq {gui} && [llength $argv] > 0} { + set subcommand [lindex $argv 0] + set argv [lrange $argv 1 end] +} + +enable_option multicommit +enable_option branch +enable_option transport + +switch -- $subcommand { +browser - +blame { + disable_option multicommit + disable_option branch + disable_option transport +} +citool { + enable_option singlecommit + + disable_option multicommit + disable_option branch + disable_option transport +} +} + ###################################################################### ## ## repository setup @@ -1596,43 +1633,6 @@ set font_descs { load_config 0 apply_config -###################################################################### -## -## feature option selection - -if {[regexp {^git-(.+)$} [appname] _junk subcommand]} { - unset _junk -} else { - set subcommand gui -} -if {$subcommand eq {gui.sh}} { - set subcommand gui -} -if {$subcommand eq {gui} && [llength $argv] > 0} { - set subcommand [lindex $argv 0] - set argv [lrange $argv 1 end] -} - -enable_option multicommit -enable_option branch -enable_option transport - -switch -- $subcommand { -browser - -blame { - disable_option multicommit - disable_option branch - disable_option transport -} -citool { - enable_option singlecommit - - disable_option multicommit - disable_option branch - disable_option transport -} -} - ###################################################################### ## ## ui construction From c52c94524bdf9bbe515137b7f3f0240bc10a7f63 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 17 Jul 2007 23:58:56 -0400 Subject: [PATCH 018/131] git-gui: Allow blame/browser subcommands on bare repositories A long time ago Linus Torvalds tried to run git-gui on a bare repository to look at the blame viewer, but it failed to start because we required that the user run us only from within a working directory that had a normal git repository associated with it. This change relaxes that requirement so that you can start the tree browser or the blame viewer against a bare repository. In the latter case we do require that you provide a revision and a pathname if we cannot find the pathname in the current working directory. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index f13fa80b46..9ddb61ea90 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -650,10 +650,13 @@ if {$subcommand eq {gui} && [llength $argv] > 0} { enable_option multicommit enable_option branch enable_option transport +disable_option bare switch -- $subcommand { browser - blame { + enable_option bare + disable_option multicommit disable_option branch disable_option transport @@ -691,19 +694,24 @@ if {![file isdirectory $_gitdir]} { error_popup "Git directory not found:\n\n$_gitdir" exit 1 } -if {[lindex [file split $_gitdir] end] ne {.git}} { - catch {wm withdraw .} - error_popup "Cannot use funny .git directory:\n\n$_gitdir" - exit 1 +if {![is_enabled bare]} { + if {[lindex [file split $_gitdir] end] ne {.git}} { + catch {wm withdraw .} + error_popup "Cannot use funny .git directory:\n\n$_gitdir" + exit 1 + } + if {[catch {cd [file dirname $_gitdir]} err]} { + catch {wm withdraw .} + error_popup "No working directory [file dirname $_gitdir]:\n\n$err" + exit 1 + } } -if {[catch {cd [file dirname $_gitdir]} err]} { - catch {wm withdraw .} - error_popup "No working directory [file dirname $_gitdir]:\n\n$err" - exit 1 +set _reponame [file split [file normalize $_gitdir]] +if {[lindex $_reponame end] eq {.git}} { + set _reponame [lindex $_reponame end-1] +} else { + set _reponame [lindex $_reponame end] } -set _reponame [lindex [file split \ - [file normalize [file dirname $_gitdir]]] \ - end] ###################################################################### ## @@ -1990,7 +1998,8 @@ browser { return } blame { - set subcommand_args {rev? path?} + set subcommand_args {rev? path} + if {$argv eq {}} usage set head {} set path {} set is_path 0 @@ -2009,12 +2018,18 @@ blame { } elseif {$head eq {}} { if {$head ne {}} usage set head $a + set is_path 1 } else { usage } } unset is_path + if {$head ne {} && $path eq {}} { + set path $_prefix$head + set head {} + } + if {$head eq {}} { load_current_branch } else { @@ -2029,7 +2044,11 @@ blame { set current_branch $head } - if {$path eq {}} usage + if {$head eq {} && ![file exists $path]} { + puts stderr "fatal: cannot stat path $path: No such file or directory" + exit 1 + } + blame::new $head $path return } From 85d2d59760e5de7f288109cb278eb91da0d5f9bf Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 18 Jul 2007 00:53:14 -0400 Subject: [PATCH 019/131] git-gui: Allow browser subcommand to start in subdirectory Like our blame subcommand the browser subcommand now accepts both a revision and a path, just a revision or just a path. This way the user can start the subcommand on any branch, or on any subtree. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 46 ++++++++++++++++++++-------------------------- lib/browser.tcl | 10 +++++++--- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 9ddb61ea90..267d606218 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1976,27 +1976,7 @@ proc usage {} { # -- Not a normal commit type invocation? Do that instead! # switch -- $subcommand { -browser { - set subcommand_args {rev?} - switch [llength $argv] { - 0 { load_current_branch } - 1 { - set current_branch [lindex $argv 0] - if {[regexp {^[0-9a-f]{1,39}$} $current_branch]} { - if {[catch { - set current_branch \ - [git rev-parse --verify $current_branch] - } err]} { - puts stderr $err - exit 1 - } - } - } - default usage - } - browser::new $current_branch - return -} +browser - blame { set subcommand_args {rev? path} if {$argv eq {}} usage @@ -2044,12 +2024,26 @@ blame { set current_branch $head } - if {$head eq {} && ![file exists $path]} { - puts stderr "fatal: cannot stat path $path: No such file or directory" - exit 1 + switch -- $subcommand { + browser { + if {$head eq {}} { + if {$path ne {} && [file isdirectory $path]} { + set head $current_branch + } else { + set head $path + set path {} + } + } + browser::new $head $path + } + blame { + if {$head eq {} && ![file exists $path]} { + puts stderr "fatal: cannot stat path $path: No such file or directory" + exit 1 + } + blame::new $head $path + } } - - blame::new $head $path return } citool - diff --git a/lib/browser.tcl b/lib/browser.tcl index 911e5af7f4..e8802d0011 100644 --- a/lib/browser.tcl +++ b/lib/browser.tcl @@ -13,13 +13,13 @@ field browser_busy 1 field ls_buf {}; # Buffered record output from ls-tree -constructor new {commit} { +constructor new {commit {path {}}} { global cursor_ptr M1B make_toplevel top w wm title $top "[appname] ([reponame]): File Browser" set browser_commit $commit - set browser_path $browser_commit: + set browser_path $browser_commit:$path label $w.path \ -textvariable @browser_path \ @@ -73,7 +73,11 @@ constructor new {commit} { bind $w_list [list focus $w_list] set w $w_list - _ls $this $browser_commit + if {$path ne {}} { + _ls $this $browser_commit:$path $path + } else { + _ls $this $browser_commit $path + } return $this } From 8e891facbef4b0196e51fe2065602175f28508c3 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 18 Jul 2007 01:39:27 -0400 Subject: [PATCH 020/131] git-gui: Allow users to browse any branch, not just the current one We now allow users to pick which commit they want to browse through our revision picking mega-widget. This opens up in a dialog first, and then opens a tree browser for that selected commit. It is a very simple approach and requires minimal code changes. I also clarified the language a bit in the Repository menu, to show that these actions will access files. Just in case a user is not quite sure what specific action they are looking for, but they know they want some sort of file thing. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 7 +++++-- lib/browser.tcl | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 267d606218..ac04bc0b26 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1670,9 +1670,12 @@ if {[is_enabled transport]} { menu .mbar.repository .mbar.repository add command \ - -label {Browse Current Branch} \ + -label {Browse Current Branch's Files} \ -command {browser::new $current_branch} -trace add variable current_branch write ".mbar.repository entryconf [.mbar.repository index last] -label \"Browse \$current_branch\" ;#" +trace add variable current_branch write ".mbar.repository entryconf [.mbar.repository index last] -label \"Browse \$current_branch's Files\" ;#" +.mbar.repository add command \ + -label {Browse Branch Files...} \ + -command browser_open::dialog .mbar.repository add separator .mbar.repository add command \ diff --git a/lib/browser.tcl b/lib/browser.tcl index e8802d0011..b684c67148 100644 --- a/lib/browser.tcl +++ b/lib/browser.tcl @@ -243,3 +243,56 @@ method _read {fd} { } } + +class browser_open { + +field w ; # widget path +field w_rev ; # mega-widget to pick the initial revision + +constructor dialog {} { + make_toplevel top w + wm title $top "[appname] ([reponame]): Browse Branch Files" + if {$top ne {.}} { + wm geometry $top "+[winfo rootx .]+[winfo rooty .]" + } + + label $w.header \ + -text {Browse Branch Files} \ + -font font_uibold + pack $w.header -side top -fill x + + frame $w.buttons + button $w.buttons.browse -text Browse \ + -default active \ + -command [cb _open] + pack $w.buttons.browse -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 [cb _open] + pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5 + + bind $w [cb _visible] + bind $w [list destroy $w] + bind $w [cb _open]\;break + tkwait window $w +} + +method _open {} { + if {[catch {$w_rev commit_or_die} err]} { + return + } + set name [$w_rev get] + destroy $w + browser::new $name +} + +method _visible {} { + grab $w + $w_rev focus_filter +} + +} From 4040971269e28676037448c4a6754d760eea1a64 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 18 Jul 2007 01:48:41 -0400 Subject: [PATCH 021/131] git-gui: Clarify the visualize history menu options Users who are new to Git may not realize that visualizing things in a repository involves looking at history. Adding in a small amount of text to the menu items really helps to understand what the action might do, before you invoke it. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index ac04bc0b26..2473488790 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1679,11 +1679,11 @@ trace add variable current_branch write ".mbar.repository entryconf [.mbar.repos .mbar.repository add separator .mbar.repository add command \ - -label {Visualize Current Branch} \ + -label {Visualize Current Branch's History} \ -command {do_gitk $current_branch} -trace add variable current_branch write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch\" ;#" +trace add variable current_branch write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch's History\" ;#" .mbar.repository add command \ - -label {Visualize All Branches} \ + -label {Visualize All Branch History} \ -command {do_gitk --all} .mbar.repository add separator From 46a2df3ac20c53eaec1d2081d5324f7c85b1adef Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 18 Jul 2007 02:27:39 -0400 Subject: [PATCH 022/131] git-gui: Increase the default height of the revision picker Showing only five lines of heads/tags is not very useful to a user when they have about 10 branches that match the filter expression. The list is just too short to really be able to read easily, at least not without scrolling up and down. Expanding the list out to 10 really makes the revision picker easier to read and access, as you can read the matching branches much more quickly. Signed-off-by: Shawn O. Pearce --- lib/choose_rev.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/choose_rev.tcl b/lib/choose_rev.tcl index afd81707ce..6c4c3188f0 100644 --- a/lib/choose_rev.tcl +++ b/lib/choose_rev.tcl @@ -86,7 +86,7 @@ constructor new {path {title {}}} { listbox $w_list \ -font font_diff \ -width 50 \ - -height 5 \ + -height 10 \ -selectmode browse \ -exportselection false \ -xscrollcommand [cb _sb_set $w.list.sbx h] \ From ff749c114a9642e79a1e93250828034f0338f1be Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 18 Jul 2007 02:56:44 -0400 Subject: [PATCH 023/131] git-gui: Convert merge dialog to use class system I've found that the class code makes it a whole lot easier to create more complex GUI code, especially the dialogs. So before I make any major improvements to the merge dialog's interface I'm going to first switch it to use the class system, so the code is slightly cleaner. Signed-off-by: Shawn O. Pearce --- lib/merge.tcl | 106 +++++++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 41 deletions(-) diff --git a/lib/merge.tcl b/lib/merge.tcl index 288d7ac889..6caf25f2be 100644 --- a/lib/merge.tcl +++ b/lib/merge.tcl @@ -1,9 +1,13 @@ # git-gui branch merge support # Copyright (C) 2006, 2007 Shawn Pearce -namespace eval merge { +class merge { -proc _can_merge {} { +field w ; # top level window +field w_list ; # widget of available branches +field list ; # list of available branches + +method _can_merge {} { global HEAD commit_type file_states if {[string match amend* $commit_type]} { @@ -63,26 +67,26 @@ You should complete the current commit before starting a merge. Doing so will h return 1 } -proc _refs {w list} { +method _refs {} { set r {} - foreach i [$w.source.l curselection] { + foreach i [$w_list curselection] { lappend r [lindex [lindex $list $i] 0] } return $r } -proc _visualize {w list} { - set revs [_refs $w $list] +method _visualize {} { + set revs [_refs $this] if {$revs eq {}} return lappend revs --not HEAD do_gitk $revs } -proc _start {w list} { +method _start {} { global HEAD current_branch set cmd [list git merge] - set names [_refs $w $list] + set names [_refs $this] set revcnt [llength $names] append cmd { } $names @@ -123,15 +127,14 @@ Please select fewer branches. To merge more than 15 branches, merge the branche set msg "Merging $current_branch, [join $names {, }]" ui_status "$msg..." set cons [console::new "Merge" $msg] - console::exec $cons $cmd \ - [namespace code [list _finish $revcnt $cons]] + console::exec $cons $cmd [cb _finish $revcnt $cons] wm protocol $w WM_DELETE_WINDOW {} destroy $w } -proc _finish {revcnt w ok} { - console::done $w $ok +method _finish {revcnt cons ok} { + console::done $cons $ok if {$ok} { set msg {Merge completed successfully.} } else { @@ -148,8 +151,7 @@ You can attempt this merge again by merging only one branch at a time." $w set fd [git_read read-tree --reset -u HEAD] fconfigure $fd -blocking 0 -translation binary - fileevent $fd readable \ - [namespace code [list _reset_wait $fd]] + fileevent $fd readable [cb _reset_wait $fd] ui_status {Aborting... please wait...} return } @@ -158,13 +160,17 @@ You can attempt this merge again by merging only one branch at a time." $w } unlock_index rescan [list ui_status $msg] + delete_this } -proc dialog {} { +constructor dialog {} { global current_branch global M1B - if {![_can_merge]} return + if {![_can_merge $this]} { + delete_this + return + } set fmt {list %(objectname) %(*objectname) %(refname) %(subject)} set fr_fd [git_read for-each-ref \ @@ -187,23 +193,25 @@ proc dialog {} { } close $fr_fd - set to_show {} + set list [list] set fr_fd [git_read rev-list --all --not HEAD] while {[gets $fr_fd line] > 0} { if {[catch {set ref $sha1($line)}]} continue foreach n $ref { - lappend to_show [list $n $line] + lappend list [list $n $line] } } close $fr_fd - set to_show [lsort -unique $to_show] + set list [lsort -unique $list] - set w .merge_setup - toplevel $w - wm geometry $w "+[winfo rootx .]+[winfo rooty .]" + make_toplevel top w + wm title $top "[appname] ([reponame]): Merge" + if {$top ne {.}} { + wm geometry $top "+[winfo rootx .]+[winfo rooty .]" + } - set _visualize [namespace code [list _visualize $w $to_show]] - set _start [namespace code [list _start $w $to_show]] + set _visualize [cb _visualize] + set _start [cb _start] label $w.header \ -text "Merge Into $current_branch" \ @@ -217,49 +225,65 @@ proc dialog {} { pack $w.buttons.create -side right button $w.buttons.cancel \ -text {Cancel} \ - -command "unlock_index;destroy $w" + -command [cb _cancel] pack $w.buttons.cancel -side right -padx 5 pack $w.buttons -side bottom -fill x -pady 10 -padx 10 labelframe $w.source -text {Source Branches} - listbox $w.source.l \ + set w_list $w.source.l + listbox $w_list \ -height 10 \ -width 70 \ -font font_diff \ -selectmode extended \ -yscrollcommand [list $w.source.sby set] - scrollbar $w.source.sby -command [list $w.source.l yview] + scrollbar $w.source.sby -command [list $w_list yview] pack $w.source.sby -side right -fill y - pack $w.source.l -side left -fill both -expand 1 + pack $w_list -side left -fill both -expand 1 pack $w.source -fill both -expand 1 -pady 5 -padx 5 - foreach ref $to_show { + foreach ref $list { set n [lindex $ref 0] if {[string length $n] > 20} { set n "[string range $n 0 16]..." } - $w.source.l insert end [format {%s %-20s %s} \ + $w_list insert end [format {%s %-20s %s} \ [string range [lindex $ref 1] 0 5] \ $n \ $subj([lindex $ref 0])] } - bind $w.source.l [list event generate %W ] - bind $w.source.l [list event generate %W ] - bind $w.source.l [list event generate %W ] - bind $w.source.l [list event generate %W ] - bind $w.source.l [list event generate %W ] - bind $w.source.l [list event generate %W ] - bind $w.source.l $_visualize + bind $w_list [list event generate %W ] + bind $w_list [list event generate %W ] + bind $w_list [list event generate %W ] + bind $w_list [list event generate %W ] + bind $w_list [list event generate %W ] + bind $w_list [list event generate %W ] + bind $w_list $_visualize bind $w <$M1B-Key-Return> $_start - bind $w "grab $w; focus $w.source.l" - bind $w "unlock_index;destroy $w" - wm protocol $w WM_DELETE_WINDOW "unlock_index;destroy $w" - wm title $w "[appname] ([reponame]): Merge" + bind $w [cb _visible] + bind $w [cb _cancel] + wm protocol $w WM_DELETE_WINDOW [cb _cancel] tkwait window $w } +method _visible {} { + grab $w + focus $w_list +} + +method _cancel {} { + wm protocol $w WM_DELETE_WINDOW {} + unlock_index + destroy $w + delete_this +} + +} + +namespace eval merge { + proc reset_hard {} { global HEAD commit_type file_states From fa2e71c9e794c43634670b62d1b4bf58d1ae7e60 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 17 Jul 2007 22:58:28 -0700 Subject: [PATCH 024/131] Do not expect unlink(2) to fail on a directory. When "git checkout-index" checks out path A/B/C, it makes sure A and A/B are truly directories; if there is a regular file or symlink at A, we prefer to remove it. We used to do this by catching an error return from mkdir(2), and on EEXIST did unlink(2), and when it succeeded, tried another mkdir(2). Thomas Glanzmann found out the above does not work on Solaris for a root user, as unlink(2) was so old fashioned there that it allowed to unlink a directory. As pointed out, this still doesn't guarantee that git won't call "unlink()" on a directory (race conditions etc), but that's fundamentally true (there is no "funlink()" like there is "fstat()"), and besides, that is in no way git-specific (ie it's true of any application that gets run as root). Acked-by: Linus Torvalds Signed-off-by: Junio C Hamano --- entry.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/entry.c b/entry.c index 82bf7259a7..23687af7d5 100644 --- a/entry.c +++ b/entry.c @@ -8,17 +8,40 @@ static void create_directories(const char *path, const struct checkout *state) const char *slash = path; while ((slash = strchr(slash+1, '/')) != NULL) { + struct stat st; + int stat_status; + len = slash - path; memcpy(buf, path, len); buf[len] = 0; + + if (len <= state->base_dir_len) + /* + * checkout-index --prefix=; is + * allowed to be a symlink to an existing + * directory. + */ + stat_status = stat(buf, &st); + else + /* + * if there currently is a symlink, we would + * want to replace it with a real directory. + */ + stat_status = lstat(buf, &st); + + if (!stat_status && S_ISDIR(st.st_mode)) + continue; /* ok, it is already a directory. */ + + /* + * We know stat_status == 0 means something exists + * there and this mkdir would fail, but that is an + * error codepath; we do not care, as we unlink and + * mkdir again in such a case. + */ if (mkdir(buf, 0777)) { - if (errno == EEXIST) { - struct stat st; - if (len > state->base_dir_len && state->force && !unlink(buf) && !mkdir(buf, 0777)) - continue; - if (!stat(buf, &st) && S_ISDIR(st.st_mode)) - continue; /* ok */ - } + if (errno == EEXIST && state->force && + !unlink(buf) && !mkdir(buf, 0777)) + continue; die("cannot create directory at %s", buf); } } From 062410bb9d6553e6bc4f8fa7f0cab1ed63b75628 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 18 Jul 2007 10:56:31 +0200 Subject: [PATCH 025/131] git-p4: Cleanup, make listExistingP4Branches a global function for later use. Signed-off-by: Simon Hausmann Signed-off-by: Marius Storm-Olsen --- contrib/fast-import/git-p4 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 54053e3f3d..d4a2f14311 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -181,6 +181,29 @@ def gitBranchExists(branch): def gitConfig(key): return read_pipe("git config %s" % key, ignore_error=True).strip() +def p4BranchesInGit(branchesAreInRemotes = True): + branches = {} + + cmdline = "git rev-parse --symbolic " + if branchesAreInRemotes: + cmdline += " --remotes" + else: + cmdline += " --branches" + + for line in read_pipe_lines(cmdline): + line = line.strip() + + ## only import to p4/ + if not line.startswith('p4/') or line == "p4/HEAD": + continue + branch = line + + # strip off p4 + branch = re.sub ("^p4/", "", line) + + branches[branch] = parseRevision(line) + return branches + def findUpstreamBranchPoint(head = "HEAD"): settings = None branchPoint = "" From 86506fe54c8e9e5f75a73956840497e3e5744f86 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 18 Jul 2007 12:40:12 +0200 Subject: [PATCH 026/131] git-p4: Fix upstream branch detection for submit/rebase with multiple branches. Don't use git name-rev to locate the upstream git-p4 branch for rebase and submit but instead locate the branch by comparing the depot paths. name-rev may produce results like wrongbranch~12 as it uses the first match. Signed-off-by: Simon Hausmann Signed-off-by: Marius Storm-Olsen --- contrib/fast-import/git-p4 | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index d4a2f14311..a65f53a47b 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -205,26 +205,31 @@ def p4BranchesInGit(branchesAreInRemotes = True): return branches def findUpstreamBranchPoint(head = "HEAD"): + branches = p4BranchesInGit() + # map from depot-path to branch name + branchByDepotPath = {} + for branch in branches.keys(): + tip = branches[branch] + log = extractLogMessageFromGitCommit(tip) + settings = extractSettingsGitLog(log) + if settings.has_key("depot-paths"): + paths = ",".join(settings["depot-paths"]) + branchByDepotPath[paths] = "remotes/p4/" + branch + settings = None - branchPoint = "" parent = 0 while parent < 65535: commit = head + "~%s" % parent log = extractLogMessageFromGitCommit(commit) settings = extractSettingsGitLog(log) - if not settings.has_key("depot-paths"): - parent = parent + 1 - continue + if settings.has_key("depot-paths"): + paths = ",".join(settings["depot-paths"]) + if branchByDepotPath.has_key(paths): + return [branchByDepotPath[paths], settings] - names = read_pipe_lines("git name-rev \"--refs=refs/remotes/p4/*\" \"%s\"" % commit) - if len(names) <= 0: - continue + parent = parent + 1 - # strip away the beginning of 'HEAD~42 refs/remotes/p4/foo' - branchPoint = names[0].strip()[len(commit) + 1:] - break - - return [branchPoint, settings] + return ["", settings] class Command: def __init__(self): From 144ff46b196e49fd52b2ecf0aaa1db4c190393b9 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 18 Jul 2007 17:27:50 +0200 Subject: [PATCH 027/131] git-p4: Cleanup, used common function for listing imported p4 branches Signed-off-by: Simon Hausmann --- contrib/fast-import/git-p4 | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index a65f53a47b..e3404ca853 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -1006,27 +1006,11 @@ class P4Sync(Command): self.knownBranches[branch] = branch def listExistingP4GitBranches(self): - self.p4BranchesInGit = [] - - cmdline = "git rev-parse --symbolic " - if self.importIntoRemotes: - cmdline += " --remotes" - else: - cmdline += " --branches" - - for line in read_pipe_lines(cmdline): - line = line.strip() - - ## only import to p4/ - if not line.startswith('p4/') or line == "p4/HEAD": - continue - branch = line - - # strip off p4 - branch = re.sub ("^p4/", "", line) - - self.p4BranchesInGit.append(branch) - self.initialParents[self.refPrefix + branch] = parseRevision(line) + # branches holds mapping from name to commit + branches = p4BranchesInGit(self.importIntoRemotes) + self.p4BranchesInGit = branches.keys() + for branch in branches.keys(): + self.initialParents[self.refPrefix + branch] = branches[branch] def createOrUpdateBranchesFromOrigin(self): if not self.silent: From 281a53bb79786a6d7e54f9715cc8ad46fc2bdb0e Mon Sep 17 00:00:00 2001 From: Julian Phillips Date: Wed, 18 Jul 2007 22:33:57 +0100 Subject: [PATCH 028/131] Force listingblocks to be monospaced in manpages For the html output we can use a stylesheet to make sure that the listingblocks are presented in a monospaced font. For the manpages do it manually by inserting a ".ft C" before and ".ft" after the block in question. In order for these roff commands to get through to the manpage they have to be element encoded to prevent quoting. Signed-off-by: Julian Phillips Signed-off-by: Junio C Hamano --- Documentation/asciidoc.conf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/asciidoc.conf b/Documentation/asciidoc.conf index e061f73867..a0d8459e21 100644 --- a/Documentation/asciidoc.conf +++ b/Documentation/asciidoc.conf @@ -27,7 +27,13 @@ ifdef::backend-docbook[] [listingblock] {title} +ifdef::doctype-manpage[] + .ft C +endif::doctype-manpage[] | +ifdef::doctype-manpage[] + .ft +endif::doctype-manpage[] {title#} endif::backend-docbook[] From 0cf7375542504e3762753cdc4cff3bb5c8fc628e Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 17 Jul 2007 20:28:28 +0200 Subject: [PATCH 029/131] unpack-trees.c: assume submodules are clean during check-out In particular, when moving back to a commit without a given submodule and then moving back forward to a commit with the given submodule, we shouldn't complain that updating would lose untracked file in the submodule, because git currently does not checkout subprojects during superproject check-out. Signed-off-by: Sven Verdoolaege Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 9 +++++ unpack-trees.c | 75 +++++++++++++++++++++++++------------- 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 5e91db64e9..e8ce7cdb83 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -21,6 +21,10 @@ subcommands of git-submodule. # -add an entry to .gitmodules for submodule 'example' # test_expect_success 'Prepare submodule testing' ' + : > t && + git-add t && + git-commit -m "initial commit" && + git branch initial HEAD && mkdir lib && cd lib && git init && @@ -166,4 +170,9 @@ test_expect_success 'status should be "up-to-date" after update' ' git-submodule status | grep "^ $rev1" ' +test_expect_success 'checkout superproject with subproject already present' ' + git-checkout initial && + git-checkout master +' + test_done diff --git a/unpack-trees.c b/unpack-trees.c index 89dd279f89..7cc029e564 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -5,6 +5,7 @@ #include "cache-tree.h" #include "unpack-trees.h" #include "progress.h" +#include "refs.h" #define DBRT_DEBUG 1 @@ -425,11 +426,24 @@ static void invalidate_ce_path(struct cache_entry *ce) cache_tree_invalidate_path(active_cache_tree, ce->name); } -static int verify_clean_subdirectory(const char *path, const char *action, +/* + * Check that checking out ce->sha1 in subdir ce->name is not + * going to overwrite any working files. + * + * Currently, git does not checkout subprojects during a superproject + * checkout, so it is not going to overwrite anything. + */ +static int verify_clean_submodule(struct cache_entry *ce, const char *action, + struct unpack_trees_options *o) +{ + return 0; +} + +static int verify_clean_subdirectory(struct cache_entry *ce, const char *action, struct unpack_trees_options *o) { /* - * we are about to extract "path"; we would not want to lose + * we are about to extract "ce->name"; we would not want to lose * anything in the existing directory there. */ int namelen; @@ -437,13 +451,24 @@ static int verify_clean_subdirectory(const char *path, const char *action, struct dir_struct d; char *pathbuf; int cnt = 0; + unsigned char sha1[20]; + + if (S_ISGITLINK(ntohl(ce->ce_mode)) && + resolve_gitlink_ref(ce->name, "HEAD", sha1) == 0) { + /* If we are not going to update the submodule, then + * we don't care. + */ + if (!hashcmp(sha1, ce->sha1)) + return 0; + return verify_clean_submodule(ce, action, o); + } /* * First let's make sure we do not have a local modification * in that directory. */ - namelen = strlen(path); - pos = cache_name_pos(path, namelen); + namelen = strlen(ce->name); + pos = cache_name_pos(ce->name, namelen); if (0 <= pos) return cnt; /* we have it as nondirectory */ pos = -pos - 1; @@ -451,7 +476,7 @@ static int verify_clean_subdirectory(const char *path, const char *action, struct cache_entry *ce = active_cache[i]; int len = ce_namelen(ce); if (len < namelen || - strncmp(path, ce->name, namelen) || + strncmp(ce->name, ce->name, namelen) || ce->name[namelen] != '/') break; /* @@ -469,16 +494,16 @@ static int verify_clean_subdirectory(const char *path, const char *action, * present file that is not ignored. */ pathbuf = xmalloc(namelen + 2); - memcpy(pathbuf, path, namelen); + memcpy(pathbuf, ce->name, namelen); strcpy(pathbuf+namelen, "/"); memset(&d, 0, sizeof(d)); if (o->dir) d.exclude_per_dir = o->dir->exclude_per_dir; - i = read_directory(&d, path, pathbuf, namelen+1, NULL); + i = read_directory(&d, ce->name, pathbuf, namelen+1, NULL); if (i) die("Updating '%s' would lose untracked files in it", - path); + ce->name); free(pathbuf); return cnt; } @@ -487,7 +512,7 @@ static int verify_clean_subdirectory(const char *path, const char *action, * We do not want to remove or overwrite a working tree file that * is not tracked, unless it is ignored. */ -static void verify_absent(const char *path, const char *action, +static void verify_absent(struct cache_entry *ce, const char *action, struct unpack_trees_options *o) { struct stat st; @@ -495,15 +520,15 @@ static void verify_absent(const char *path, const char *action, if (o->index_only || o->reset || !o->update) return; - if (has_symlink_leading_path(path, NULL)) + if (has_symlink_leading_path(ce->name, NULL)) return; - if (!lstat(path, &st)) { + if (!lstat(ce->name, &st)) { int cnt; - if (o->dir && excluded(o->dir, path)) + if (o->dir && excluded(o->dir, ce->name)) /* - * path is explicitly excluded, so it is Ok to + * ce->name is explicitly excluded, so it is Ok to * overwrite it. */ return; @@ -515,7 +540,7 @@ static void verify_absent(const char *path, const char *action, * files that are in "foo/" we would lose * it. */ - cnt = verify_clean_subdirectory(path, action, o); + cnt = verify_clean_subdirectory(ce, action, o); /* * If this removed entries from the index, @@ -543,7 +568,7 @@ static void verify_absent(const char *path, const char *action, * delete this path, which is in a subdirectory that * is being replaced with a blob. */ - cnt = cache_name_pos(path, strlen(path)); + cnt = cache_name_pos(ce->name, strlen(ce->name)); if (0 <= cnt) { struct cache_entry *ce = active_cache[cnt]; if (!ce_stage(ce) && !ce->ce_mode) @@ -551,7 +576,7 @@ static void verify_absent(const char *path, const char *action, } die("Untracked working tree file '%s' " - "would be %s by merge.", path, action); + "would be %s by merge.", ce->name, action); } } @@ -575,7 +600,7 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old, } } else { - verify_absent(merge->name, "overwritten", o); + verify_absent(merge, "overwritten", o); invalidate_ce_path(merge); } @@ -590,7 +615,7 @@ static int deleted_entry(struct cache_entry *ce, struct cache_entry *old, if (old) verify_uptodate(old, o); else - verify_absent(ce->name, "removed", o); + verify_absent(ce, "removed", o); ce->ce_mode = 0; add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE); invalidate_ce_path(ce); @@ -707,18 +732,18 @@ int threeway_merge(struct cache_entry **stages, if (o->aggressive) { int head_deleted = !head && !df_conflict_head; int remote_deleted = !remote && !df_conflict_remote; - const char *path = NULL; + struct cache_entry *ce = NULL; if (index) - path = index->name; + ce = index; else if (head) - path = head->name; + ce = head; else if (remote) - path = remote->name; + ce = remote; else { for (i = 1; i < o->head_idx; i++) { if (stages[i] && stages[i] != o->df_conflict_entry) { - path = stages[i]->name; + ce = stages[i]; break; } } @@ -733,8 +758,8 @@ int threeway_merge(struct cache_entry **stages, (remote_deleted && head && head_match)) { if (index) return deleted_entry(index, index, o); - else if (path && !head_deleted) - verify_absent(path, "removed", o); + else if (ce && !head_deleted) + verify_absent(ce, "removed", o); return 0; } /* From ec96e0f6a4244e3bccc745eeb4cb6daa80a347e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=97=E3=82=89=E3=81=84=E3=81=97=E3=81=AA=E3=81=AA?= =?UTF-8?q?=E3=81=93?= Date: Tue, 17 Jul 2007 17:15:42 +0900 Subject: [PATCH 030/131] Document "git stash message..." The command was recently updated to take message on the command line, but this feature has not been documented. Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano --- Documentation/git-stash.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt index ad95ed9ce1..17121ade56 100644 --- a/Documentation/git-stash.txt +++ b/Documentation/git-stash.txt @@ -8,7 +8,8 @@ git-stash - Stash the changes in a dirty working directory away SYNOPSIS -------- [verse] -'git-stash' (save | list | show [] | apply [] | clear) +'git-stash' (list | show [] | apply [] | clear) +'git-stash' [save] [message...] DESCRIPTION ----------- @@ -22,7 +23,9 @@ The modifications stashed away by this command can be listed with `git-stash list`, inspected with `git-stash show`, and restored (potentially on top of a different commit) with `git-stash apply`. Calling git-stash without any arguments is equivalent to `git-stash -save`. +save`. A stash is by default listed as "WIP on 'branchname' ...", but +you can give a more descriptive message on the command line when +you create one. The latest stash you created is stored in `$GIT_DIR/refs/stash`; older stashes are found in the reflog of this reference and can be named using @@ -48,8 +51,8 @@ list:: based on. + ---------------------------------------------------------------- -stash@{0}: submit: 6ebd0e2... Add git-stash -stash@{1}: master: 9cc0589... Merge branch 'master' of gfi +stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation +stash@{1}: On master: 9cc0589... Add git-stash ---------------------------------------------------------------- show []:: From b59d398beab604e577846ef8393735478c1ca3c2 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 17 Jul 2007 10:34:44 -0700 Subject: [PATCH 031/131] Do a better job at guessing unknown character sets At least in the kernel development community, we're generally slowly converting to UTF-8 everywhere, and the old default of Latin1 in emails is being supplanted by UTF-8, and it doesn't necessarily show up as such in the mail headers (because, quite frankly, when people send patches around, they want the email client to do as little as humanly possible about the patch) Despite that, it's often the case that email addresses etc still have Latin1, so I've seen emails where this is a mixed bag, with Signed-off parts being copied from email (and containing Latin1 characters), and the rest of the email being a patch in UTF-8. So this suggests a very natural change: if the target character set is utf-8 (the default), and if the source already looks like utf-8, just assume that it doesn't need any conversion at all. Only assume that it needs conversion if it isn't already valid utf-8, in which case we (for historical reasons) will assume it's Latin1. Basically no really _valid_ latin1 will ever look like utf-8, so while this changes our historical behaviour, it doesn't do so in practice, and makes the default behaviour saner for the case where the input was already in proper format. We could do a more fancy guess, of course, but this correctly handled a series of patches I just got from Andrew that had a mixture of Latin1 and UTF-8 (in different emails, but without any character set indication). Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- builtin-mailinfo.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c index 489c2c58c0..a37a4fff39 100644 --- a/builtin-mailinfo.c +++ b/builtin-mailinfo.c @@ -499,15 +499,40 @@ static int decode_b_segment(char *in, char *ot, char *ep) return 0; } +/* + * When there is no known charset, guess. + * + * Right now we assume that if the target is UTF-8 (the default), + * and it already looks like UTF-8 (which includes US-ASCII as its + * subset, of course) then that is what it is and there is nothing + * to do. + * + * Otherwise, we default to assuming it is Latin1 for historical + * reasons. + */ +static const char *guess_charset(const char *line, const char *target_charset) +{ + if (is_encoding_utf8(target_charset)) { + if (is_utf8(line)) + return NULL; + } + return "latin1"; +} + static void convert_to_utf8(char *line, const char *charset) { - static const char latin_one[] = "latin1"; - const char *input_charset = *charset ? charset : latin_one; - char *out = reencode_string(line, metainfo_charset, input_charset); + char *out; + if (!charset || !*charset) { + charset = guess_charset(line, metainfo_charset); + if (!charset) + return; + } + + out = reencode_string(line, metainfo_charset, charset); if (!out) die("cannot convert from %s to %s\n", - input_charset, metainfo_charset); + charset, metainfo_charset); strcpy(line, out); free(out); } From 575d025c0d0fdc9d8b5d68cb802957c527eb0d14 Mon Sep 17 00:00:00 2001 From: Richard MUSIL Date: Tue, 17 Jul 2007 19:02:57 +0200 Subject: [PATCH 032/131] git-svn: Minimalistic patch which allows svn usernames with space(s). Changed filter for username in svn-authors file, so even 'user name' is accepted. Acked-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-svn.perl b/git-svn.perl index 01c3904271..6c692a79e7 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -740,7 +740,7 @@ sub load_authors { my $log = $cmd eq 'log'; while (<$authors>) { chomp; - next unless /^(\S+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/; + next unless /^(.+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/; my ($user, $name, $email) = ($1, $2, $3); if ($log) { $Git::SVN::Log::rusers{"$name <$email>"} = $user; From af580e9c5afcffe7020e6f955f5136ee4220834f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Jul 2007 14:17:43 +0100 Subject: [PATCH 033/131] filter-branch: get rid of "set -e" It was reported by Alex Riesen that "set -e" can break something as trivial as "unset CDPATH" in bash. So get rid of "set -e". Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-filter-branch.sh | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/git-filter-branch.sh b/git-filter-branch.sh index 54019706dc..0d000ed306 100755 --- a/git-filter-branch.sh +++ b/git-filter-branch.sh @@ -8,8 +8,6 @@ # a new branch. You can specify a number of filters to modify the commits, # files and trees. -set -e - USAGE="git-filter-branch [-d TEMPDIR] [FILTERS] DESTBRANCH [REV-RANGE]" . git-sh-setup @@ -141,9 +139,10 @@ git show-ref "refs/heads/$dstbranch" 2> /dev/null && die "branch $dstbranch already exists" test ! -e "$tempdir" || die "$tempdir already exists, please remove it" -mkdir -p "$tempdir/t" -cd "$tempdir/t" -workdir="$(pwd)" +mkdir -p "$tempdir/t" && +cd "$tempdir/t" && +workdir="$(pwd)" || +die "" case "$GIT_DIR" in /*) @@ -155,12 +154,12 @@ esac export GIT_DIR GIT_WORK_TREE=. export GIT_INDEX_FILE="$(pwd)/../index" -git read-tree # seed the index file +git read-tree || die "Could not seed the index" ret=0 - -mkdir ../map # map old->new commit ids for rewriting parents +# map old->new commit ids for rewriting parents +mkdir ../map || die "Could not create map/ directory" case "$filter_subdir" in "") @@ -170,7 +169,7 @@ case "$filter_subdir" in *) git rev-list --reverse --topo-order --default HEAD \ --parents --full-history "$@" -- "$filter_subdir" -esac > ../revs +esac > ../revs || die "Could not get the commits" commits=$(wc -l <../revs | tr -d " ") test $commits -eq 0 && die "Found nothing to rewrite" @@ -186,10 +185,11 @@ while read commit parents; do ;; *) git read-tree -i -m $commit:"$filter_subdir" - esac + esac || die "Could not initialize the index" export GIT_COMMIT=$commit - git cat-file commit "$commit" >../commit + git cat-file commit "$commit" >../commit || + die "Cannot read commit $commit" eval "$(set_ident AUTHOR <../commit)" || die "setting author failed for commit $commit" @@ -199,7 +199,8 @@ while read commit parents; do die "env filter failed: $filter_env" if [ "$filter_tree" ]; then - git checkout-index -f -u -a + git checkout-index -f -u -a || + die "Could not checkout the index" # files that $commit removed are now still in the working tree; # remove them, else they would be added again git ls-files -z --others | xargs -0 rm -f @@ -240,7 +241,8 @@ case "$target_head" in echo Nothing rewritten ;; *) - git update-ref refs/heads/"$dstbranch" $target_head + git update-ref refs/heads/"$dstbranch" $target_head || + die "Could not update $dstbranch with $target_head" if [ $(wc -l <../map/$src_head) -gt 1 ]; then echo "WARNING: Your commit filter caused the head commit to expand to several rewritten commits. Only the first such commit was recorded as the current $dstbranch head but you will need to resolve the situation now (probably by manually merging the other commits). These are all the commits:" >&2 sed 's/^/ /' ../map/$src_head >&2 @@ -277,7 +279,8 @@ if [ "$filter_tag_name" ]; then warn "unreferencing tag object $sha1t" fi - git update-ref "refs/tags/$new_ref" "$new_sha1" + git update-ref "refs/tags/$new_ref" "$new_sha1" || + die "Could not write tag $new_ref" done fi From c4fba0a358d43fdb2301dd122d68c49dd8471d71 Mon Sep 17 00:00:00 2001 From: Carlos Rica Date: Wed, 18 Jul 2007 20:31:03 +0200 Subject: [PATCH 034/131] Rename read_pipe() with read_fd() and make its buffer nul-terminated. The new name is closer to the purpose of the function. A NUL-terminated buffer makes things easier when callers need that. Since the function returns only the memory written with data, almost always allocating more space than needed because final size is unknown, an extra NUL terminating the buffer is harmless. It is not included in the returned size, so the function remains working as before. Also, now the function allows the buffer passed to be NULL at first, and alloc_nr is now used for growing the buffer, instead size=*2. Signed-off-by: Carlos Rica Signed-off-by: Junio C Hamano --- builtin-stripspace.c | 4 +++- cache.h | 2 +- mktag.c | 2 +- sha1_file.c | 21 +++++++++++++++------ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/builtin-stripspace.c b/builtin-stripspace.c index 0c970aa945..55716873dc 100644 --- a/builtin-stripspace.c +++ b/builtin-stripspace.c @@ -79,8 +79,10 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix) size = 1024; buffer = xmalloc(size); - if (read_pipe(0, &buffer, &size)) + if (read_fd(0, &buffer, &size)) { + free(buffer); die("could not read the input"); + } size = stripspace(buffer, size, 0); write_or_die(1, buffer, size); diff --git a/cache.h b/cache.h index 328c1ad411..53801b8089 100644 --- a/cache.h +++ b/cache.h @@ -265,7 +265,7 @@ extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, int); extern int ce_path_match(const struct cache_entry *ce, const char **pathspec); extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path); -extern int read_pipe(int fd, char** return_buf, unsigned long* return_size); +extern int read_fd(int fd, char **return_buf, unsigned long *return_size); extern int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object); extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object); extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); diff --git a/mktag.c b/mktag.c index b82e377bd8..38acd5a295 100644 --- a/mktag.c +++ b/mktag.c @@ -120,7 +120,7 @@ int main(int argc, char **argv) setup_git_directory(); - if (read_pipe(0, &buffer, &size)) { + if (read_fd(0, &buffer, &size)) { free(buffer); die("could not read from stdin"); } diff --git a/sha1_file.c b/sha1_file.c index 1efd9ae19a..aca741b79c 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2304,27 +2304,36 @@ int has_sha1_file(const unsigned char *sha1) * * returns 0 if anything went fine and -1 otherwise * + * The buffer is always NUL-terminated, not including it in returned size. + * * NOTE: both buf and size may change, but even when -1 is returned * you still have to free() it yourself. */ -int read_pipe(int fd, char** return_buf, unsigned long* return_size) +int read_fd(int fd, char **return_buf, unsigned long *return_size) { - char* buf = *return_buf; + char *buf = *return_buf; unsigned long size = *return_size; ssize_t iret; unsigned long off = 0; + if (!buf || size <= 1) { + size = 1024; + buf = xrealloc(buf, size); + } + do { - iret = xread(fd, buf + off, size - off); + iret = xread(fd, buf + off, (size - 1) - off); if (iret > 0) { off += iret; - if (off == size) { - size *= 2; + if (off == size - 1) { + size = alloc_nr(size); buf = xrealloc(buf, size); } } } while (iret > 0); + buf[off] = '\0'; + *return_buf = buf; *return_size = off; @@ -2339,7 +2348,7 @@ int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object) char *buf = xmalloc(size); int ret; - if (read_pipe(fd, &buf, &size)) { + if (read_fd(fd, &buf, &size)) { free(buf); return -1; } From dc5ccdc6cab41e8a4b2ace991b1564fe9bdd172d Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 18 Jul 2007 09:37:27 -0400 Subject: [PATCH 035/131] Don't offer my special Tools/Migrate hack unless in multicommit Users shouldn't see this menu option if they startup a browser or blame from the command line, especially if they are doing so on a bare repository. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/git-gui.sh b/git-gui.sh index 2473488790..7b6a96e4f2 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1888,7 +1888,9 @@ if {[is_MacOSX]} { # -- Tools Menu # - if {[is_Cygwin] && [file exists /usr/local/miga/lib/gui-miga]} { + if {[is_Cygwin] + && [is_enabled multicommit] + && [file exists /usr/local/miga/lib/gui-miga]} { proc do_miga {} { if {![lock_index update]} return set cmd [list sh --login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""] From a870ddc0997881d5e73c0ec4562f3521274c5960 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 19 Jul 2007 00:39:23 -0400 Subject: [PATCH 036/131] git-gui: Bind Ctrl/Cmd-M to merge action Users who merge often may want to access the merge action quickly, so we now bind M to the merge action. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 7b6a96e4f2..0aabfba6b7 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1846,14 +1846,14 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} { if {[is_enabled branch]} { menu .mbar.merge .mbar.merge add command -label {Local Merge...} \ - -command merge::dialog + -command merge::dialog \ + -accelerator $M1T-M lappend disable_on_lock \ [list .mbar.merge entryconf [.mbar.merge index last] -state] .mbar.merge add command -label {Abort Merge...} \ -command merge::reset_hard lappend disable_on_lock \ [list .mbar.merge entryconf [.mbar.merge index last] -state] - } # -- Transport Menu @@ -2508,6 +2508,8 @@ if {[is_enabled branch]} { bind . <$M1B-Key-N> branch_create::dialog bind . <$M1B-Key-o> branch_checkout::dialog bind . <$M1B-Key-O> branch_checkout::dialog + bind . <$M1B-Key-m> merge::dialog + bind . <$M1B-Key-M> merge::dialog } if {[is_enabled transport]} { bind . <$M1B-Key-p> do_push_anywhere From d36cd968378cd3e509434b1b9f43f1417fdba57e Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 19 Jul 2007 00:43:16 -0400 Subject: [PATCH 037/131] git-gui: Avoid unnecessary global statements when possible Running global takes slightly longer than just accessing the variable via its package name, especially if the variable is just only once in the procedure, or isn't even used at all in the procedure. So this is a minor cleanup for some of our commonly invoked procedures. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 0aabfba6b7..c5ff7c8a83 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -154,12 +154,10 @@ proc gitexec {args} { } proc reponame {} { - global _reponame - return $_reponame + return $::_reponame } proc is_MacOSX {} { - global tcl_platform tk_library if {[tk windowingsystem] eq {aqua}} { return 1 } @@ -167,17 +165,16 @@ proc is_MacOSX {} { } proc is_Windows {} { - global tcl_platform - if {$tcl_platform(platform) eq {windows}} { + if {$::tcl_platform(platform) eq {windows}} { return 1 } return 0 } proc is_Cygwin {} { - global tcl_platform _iscygwin + global _iscygwin if {$_iscygwin eq {}} { - if {$tcl_platform(platform) eq {windows}} { + if {$::tcl_platform(platform) eq {windows}} { if {[catch {set p [exec cygpath --windir]} err]} { set _iscygwin 0 } else { From c4638f662c9ba5f4150ab97dbbf0e540392aad55 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 19 Jul 2007 01:13:29 -0400 Subject: [PATCH 038/131] git-gui: Translate standard encoding names to Tcl ones This is a essentially a copy of Paul Mackerras encoding support from gitk. I stole the code from gitk commit fd8ccbec4f0161, as Paul has already done all of the hard work setting up this translation table. Signed-off-by: Shawn O. Pearce --- lib/blame.tcl | 19 ++-- lib/commit.tcl | 20 +++- lib/encoding.tcl | 276 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 304 insertions(+), 11 deletions(-) create mode 100644 lib/encoding.tcl diff --git a/lib/blame.tcl b/lib/blame.tcl index 1bcb4b471f..4da60ac9af 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -771,15 +771,20 @@ method _showcommit {cur_w lno} { set enc [string tolower [string range $line 9 end]] } } - set msg [encoding convertfrom $enc [read $fd]] - set msg [string trim $msg] + set msg [read $fd] close $fd - set author_name [encoding convertfrom $enc $author_name] - set committer_name [encoding convertfrom $enc $committer_name] - - set header($cmit,author) $author_name - set header($cmit,committer) $committer_name + set enc [tcl_encoding $enc] + if {$enc ne {}} { + set msg [encoding convertfrom $enc $msg] + set author_name [encoding convertfrom $enc $author_name] + set committer_name [encoding convertfrom $enc $committer_name] + set header($cmit,author) $author_name + set header($cmit,committer) $committer_name + set header($cmit,summary) \ + [encoding convertfrom $enc $header($cmit,summary)] + } + set msg [string trim $msg] } set header($cmit,message) $msg } diff --git a/lib/commit.tcl b/lib/commit.tcl index 0f3b16dfeb..75b13a0d99 100644 --- a/lib/commit.tcl +++ b/lib/commit.tcl @@ -37,9 +37,14 @@ You are currently in the middle of a merge that has not been fully completed. Y set enc [string tolower [string range $line 9 end]] } } - set msg [encoding convertfrom $enc [read $fd]] - set msg [string trim $msg] + set msg [read $fd] close $fd + + set enc [tcl_encoding $enc] + if {$enc ne {}} { + set msg [encoding convertfrom $enc $msg] + } + set msg [string trim $msg] } err]} { error_popup "Error loading commit data for amend:\n\n$err" return @@ -287,11 +292,18 @@ A rescan will be automatically started now. # set msg_p [gitdir COMMIT_EDITMSG] set msg_wt [open $msg_p w] + fconfigure $msg_wt -translation lf if {[catch {set enc $repo_config(i18n.commitencoding)}]} { set enc utf-8 } - fconfigure $msg_wt -encoding binary -translation binary - puts -nonewline $msg_wt [encoding convertto $enc $msg] + set use_enc [tcl_encoding $enc] + if {$use_enc ne {}} { + fconfigure $msg_wt -encoding $use_enc + } else { + puts stderr "warning: Tcl does not support encoding '$enc'." + fconfigure $msg_wt -encoding utf-8 + } + puts -nonewline $msg_wt $msg close $msg_wt # -- Create the commit. diff --git a/lib/encoding.tcl b/lib/encoding.tcl new file mode 100644 index 0000000000..7f06b0d47f --- /dev/null +++ b/lib/encoding.tcl @@ -0,0 +1,276 @@ +# git-gui encoding support +# Copyright (C) 2005 Paul Mackerras +# (Copied from gitk, commit fd8ccbec4f0161) + +# This list of encoding names and aliases is distilled from +# http://www.iana.org/assignments/character-sets. +# Not all of them are supported by Tcl. +set encoding_aliases { + { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII + ISO646-US US-ASCII us IBM367 cp367 csASCII } + { ISO-10646-UTF-1 csISO10646UTF1 } + { ISO_646.basic:1983 ref csISO646basic1983 } + { INVARIANT csINVARIANT } + { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion } + { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom } + { NATS-SEFI iso-ir-8-1 csNATSSEFI } + { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD } + { NATS-DANO iso-ir-9-1 csNATSDANO } + { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD } + { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish } + { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames } + { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 } + { ISO-2022-KR csISO2022KR } + { EUC-KR csEUCKR } + { ISO-2022-JP csISO2022JP } + { ISO-2022-JP-2 csISO2022JP2 } + { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7 + csISO13JISC6220jp } + { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro } + { IT iso-ir-15 ISO646-IT csISO15Italian } + { PT iso-ir-16 ISO646-PT csISO16Portuguese } + { ES iso-ir-17 ISO646-ES csISO17Spanish } + { greek7-old iso-ir-18 csISO18Greek7Old } + { latin-greek iso-ir-19 csISO19LatinGreek } + { DIN_66003 iso-ir-21 de ISO646-DE csISO21German } + { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French } + { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 } + { ISO_5427 iso-ir-37 csISO5427Cyrillic } + { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 } + { BS_viewdata iso-ir-47 csISO47BSViewdata } + { INIS iso-ir-49 csISO49INIS } + { INIS-8 iso-ir-50 csISO50INIS8 } + { INIS-cyrillic iso-ir-51 csISO51INISCyrillic } + { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 } + { ISO_5428:1980 iso-ir-55 csISO5428Greek } + { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 } + { GB_2312-80 iso-ir-58 chinese csISO58GB231280 } + { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian + csISO60Norwegian1 } + { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 } + { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French } + { videotex-suppl iso-ir-70 csISO70VideotexSupp1 } + { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 } + { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 } + { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian } + { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 } + { greek7 iso-ir-88 csISO88Greek7 } + { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 } + { iso-ir-90 csISO90 } + { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a } + { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b + csISO92JISC62991984b } + { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd } + { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand } + { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add + csISO95JIS62291984handadd } + { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana } + { ISO_2033-1983 iso-ir-98 e13b csISO2033 } + { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS } + { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819 + CP819 csISOLatin1 } + { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 } + { T.61-7bit iso-ir-102 csISO102T617bit } + { T.61-8bit T.61 iso-ir-103 csISO103T618bit } + { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 } + { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 } + { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic } + { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 } + { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 } + { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr } + { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708 + arabic csISOLatinArabic } + { ISO_8859-6-E csISO88596E ISO-8859-6-E } + { ISO_8859-6-I csISO88596I ISO-8859-6-I } + { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118 + greek greek8 csISOLatinGreek } + { T.101-G2 iso-ir-128 csISO128T101G2 } + { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew + csISOLatinHebrew } + { ISO_8859-8-E csISO88598E ISO-8859-8-E } + { ISO_8859-8-I csISO88598I ISO-8859-8-I } + { CSN_369103 iso-ir-139 csISO139CSN369103 } + { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 } + { ISO_6937-2-add iso-ir-142 csISOTextComm } + { IEC_P27-1 iso-ir-143 csISO143IECP271 } + { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic + csISOLatinCyrillic } + { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian } + { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian } + { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 } + { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT } + { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba } + { ISO_6937-2-25 iso-ir-152 csISO6937Add } + { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 } + { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp } + { ISO_10367-box iso-ir-155 csISO10367Box } + { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 } + { latin-lap lap iso-ir-158 csISO158Lap } + { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 } + { DS_2089 DS2089 ISO646-DK dk csISO646Danish } + { us-dk csUSDK } + { dk-us csDKUS } + { JIS_X0201 X0201 csHalfWidthKatakana } + { KSC5636 ISO646-KR csKSC5636 } + { ISO-10646-UCS-2 csUnicode } + { ISO-10646-UCS-4 csUCS4 } + { DEC-MCS dec csDECMCS } + { hp-roman8 roman8 r8 csHPRoman8 } + { macintosh mac csMacintosh } + { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl + csIBM037 } + { IBM038 EBCDIC-INT cp038 csIBM038 } + { IBM273 CP273 csIBM273 } + { IBM274 EBCDIC-BE CP274 csIBM274 } + { IBM275 EBCDIC-BR cp275 csIBM275 } + { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 } + { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 } + { IBM280 CP280 ebcdic-cp-it csIBM280 } + { IBM281 EBCDIC-JP-E cp281 csIBM281 } + { IBM284 CP284 ebcdic-cp-es csIBM284 } + { IBM285 CP285 ebcdic-cp-gb csIBM285 } + { IBM290 cp290 EBCDIC-JP-kana csIBM290 } + { IBM297 cp297 ebcdic-cp-fr csIBM297 } + { IBM420 cp420 ebcdic-cp-ar1 csIBM420 } + { IBM423 cp423 ebcdic-cp-gr csIBM423 } + { IBM424 cp424 ebcdic-cp-he csIBM424 } + { IBM437 cp437 437 csPC8CodePage437 } + { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 } + { IBM775 cp775 csPC775Baltic } + { IBM850 cp850 850 csPC850Multilingual } + { IBM851 cp851 851 csIBM851 } + { IBM852 cp852 852 csPCp852 } + { IBM855 cp855 855 csIBM855 } + { IBM857 cp857 857 csIBM857 } + { IBM860 cp860 860 csIBM860 } + { IBM861 cp861 861 cp-is csIBM861 } + { IBM862 cp862 862 csPC862LatinHebrew } + { IBM863 cp863 863 csIBM863 } + { IBM864 cp864 csIBM864 } + { IBM865 cp865 865 csIBM865 } + { IBM866 cp866 866 csIBM866 } + { IBM868 CP868 cp-ar csIBM868 } + { IBM869 cp869 869 cp-gr csIBM869 } + { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 } + { IBM871 CP871 ebcdic-cp-is csIBM871 } + { IBM880 cp880 EBCDIC-Cyrillic csIBM880 } + { IBM891 cp891 csIBM891 } + { IBM903 cp903 csIBM903 } + { IBM904 cp904 904 csIBBM904 } + { IBM905 CP905 ebcdic-cp-tr csIBM905 } + { IBM918 CP918 ebcdic-cp-ar2 csIBM918 } + { IBM1026 CP1026 csIBM1026 } + { EBCDIC-AT-DE csIBMEBCDICATDE } + { EBCDIC-AT-DE-A csEBCDICATDEA } + { EBCDIC-CA-FR csEBCDICCAFR } + { EBCDIC-DK-NO csEBCDICDKNO } + { EBCDIC-DK-NO-A csEBCDICDKNOA } + { EBCDIC-FI-SE csEBCDICFISE } + { EBCDIC-FI-SE-A csEBCDICFISEA } + { EBCDIC-FR csEBCDICFR } + { EBCDIC-IT csEBCDICIT } + { EBCDIC-PT csEBCDICPT } + { EBCDIC-ES csEBCDICES } + { EBCDIC-ES-A csEBCDICESA } + { EBCDIC-ES-S csEBCDICESS } + { EBCDIC-UK csEBCDICUK } + { EBCDIC-US csEBCDICUS } + { UNKNOWN-8BIT csUnknown8BiT } + { MNEMONIC csMnemonic } + { MNEM csMnem } + { VISCII csVISCII } + { VIQR csVIQR } + { KOI8-R csKOI8R } + { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro } + { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro } + { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro } + { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro } + { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro } + { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro } + { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro } + { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro } + { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro } + { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro } + { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro } + { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro } + { IBM1047 IBM-1047 } + { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian } + { Amiga-1251 Ami1251 Amiga1251 Ami-1251 } + { UNICODE-1-1 csUnicode11 } + { CESU-8 csCESU-8 } + { BOCU-1 csBOCU-1 } + { UNICODE-1-1-UTF-7 csUnicode11UTF7 } + { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic + l8 } + { ISO-8859-15 ISO_8859-15 Latin-9 } + { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 } + { GBK CP936 MS936 windows-936 } + { JIS_Encoding csJISEncoding } + { Shift_JIS MS_Kanji csShiftJIS } + { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese + EUC-JP } + { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese } + { ISO-10646-UCS-Basic csUnicodeASCII } + { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 } + { ISO-Unicode-IBM-1261 csUnicodeIBM1261 } + { ISO-Unicode-IBM-1268 csUnicodeIBM1268 } + { ISO-Unicode-IBM-1276 csUnicodeIBM1276 } + { ISO-Unicode-IBM-1264 csUnicodeIBM1264 } + { ISO-Unicode-IBM-1265 csUnicodeIBM1265 } + { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 } + { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 } + { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 } + { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 } + { Adobe-Standard-Encoding csAdobeStandardEncoding } + { Ventura-US csVenturaUS } + { Ventura-International csVenturaInternational } + { PC8-Danish-Norwegian csPC8DanishNorwegian } + { PC8-Turkish csPC8Turkish } + { IBM-Symbols csIBMSymbols } + { IBM-Thai csIBMThai } + { HP-Legal csHPLegal } + { HP-Pi-font csHPPiFont } + { HP-Math8 csHPMath8 } + { Adobe-Symbol-Encoding csHPPSMath } + { HP-DeskTop csHPDesktop } + { Ventura-Math csVenturaMath } + { Microsoft-Publishing csMicrosoftPublishing } + { Windows-31J csWindows31J } + { GB2312 csGB2312 } + { Big5 csBig5 } +} + +proc tcl_encoding {enc} { + global encoding_aliases + set names [encoding names] + set lcnames [string tolower $names] + set enc [string tolower $enc] + set i [lsearch -exact $lcnames $enc] + if {$i < 0} { + # look for "isonnn" instead of "iso-nnn" or "iso_nnn" + if {[regsub {^iso[-_]} $enc iso encx]} { + set i [lsearch -exact $lcnames $encx] + } + } + if {$i < 0} { + foreach l $encoding_aliases { + set ll [string tolower $l] + if {[lsearch -exact $ll $enc] < 0} continue + # look through the aliases for one that tcl knows about + foreach e $ll { + set i [lsearch -exact $lcnames $e] + if {$i < 0} { + if {[regsub {^iso[-_]} $e iso ex]} { + set i [lsearch -exact $lcnames $ex] + } + } + if {$i >= 0} break + } + break + } + } + if {$i >= 0} { + return [lindex $names $i] + } + return {} +} From a42289621e372763d5ef34067d5e38a0872fab15 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 19 Jul 2007 01:45:42 -0400 Subject: [PATCH 039/131] git-gui: Don't show blame tooltips that we have no data for If we haven't yet loaded any commit information for a given line but our tooltip timer fired and tried to draw the tooltip we shouldn't; there is nothing to show. Signed-off-by: Shawn O. Pearce --- lib/blame.tcl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/blame.tcl b/lib/blame.tcl index 4da60ac9af..96072847a2 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -879,6 +879,11 @@ method _open_tooltip {cur_w} { set org [lindex $amov_data $lno] } + if {$dat eq {}} { + _hide_tooltip $this + return + } + set cmit [lindex $dat 0] set tooltip_commit [list $cmit] From 5dc2cae6f4c5d7218c4323ceafb96ab8469be52e Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 19 Jul 2007 02:24:25 -0400 Subject: [PATCH 040/131] git-gui: Completely remove support for creating octopus merges I'm working on refactoring the UI of the merge dialog, because as it currently stands the dialog is absolutely horrible, especially when you have 200+ branches available from a single remote system. In that refactoring I plan on using the choose_rev widget to allow the user to select exactly which branch/commit they want to merge. However since that only selects a single commit I'm first removing the code that supports octopus merges. A brief consultation on #git tonight seemed to indicate that the octopus merge strategy is not as useful as originally thought when it was invented, and that most people don't commonly use them. So making users fall back to the command line to create an octopus is actually maybe a good idea here, as they might think twice before they use it. Signed-off-by: Shawn O. Pearce --- lib/merge.tcl | 85 +++++++++++---------------------------------------- 1 file changed, 17 insertions(+), 68 deletions(-) diff --git a/lib/merge.tcl b/lib/merge.tcl index 6caf25f2be..e5a752507b 100644 --- a/lib/merge.tcl +++ b/lib/merge.tcl @@ -67,95 +67,44 @@ You should complete the current commit before starting a merge. Doing so will h return 1 } -method _refs {} { - set r {} - foreach i [$w_list curselection] { - lappend r [lindex [lindex $list $i] 0] +method _rev {} { + set i [$w_list curselection] + if {$i >= 0} { + return [lindex [lindex $list $i] 0] } - return $r + return {} } method _visualize {} { - set revs [_refs $this] - if {$revs eq {}} return - lappend revs --not HEAD - do_gitk $revs + set rev [_rev $this] + if {$rev ne {}} { + do_gitk [list $rev --not HEAD] + } } method _start {} { global HEAD current_branch - set cmd [list git merge] - set names [_refs $this] - set revcnt [llength $names] - append cmd { } $names - - if {$revcnt == 0} { - return - } elseif {$revcnt == 1} { - set unit branch - } elseif {$revcnt <= 15} { - set unit branches - - if {[tk_dialog \ - $w.confirm_octopus \ - [wm title $w] \ - "Use octopus merge strategy? - -You are merging $revcnt branches at once. This requires using the octopus merge driver, which may not succeed if there are file-level conflicts. -" \ - question \ - 0 \ - {Cancel} \ - {Use octopus} \ - ] != 1} return - } else { - tk_messageBox \ - -icon error \ - -type ok \ - -title [wm title $w] \ - -parent $w \ - -message "Too many branches selected. - -You have requested to merge $revcnt branches in an octopus merge. This exceeds Git's internal limit of 15 branches per merge. - -Please select fewer branches. To merge more than 15 branches, merge the branches in batches. -" + set name [_rev $this] + if {$name eq {}} { return } - set msg "Merging $current_branch, [join $names {, }]" + set cmd [list git merge $name] + set msg "Merging $current_branch and $name" ui_status "$msg..." - set cons [console::new "Merge" $msg] - console::exec $cons $cmd [cb _finish $revcnt $cons] + set cons [console::new "Merge" $cmd] + console::exec $cons $cmd [cb _finish $cons] wm protocol $w WM_DELETE_WINDOW {} destroy $w } -method _finish {revcnt cons ok} { +method _finish {cons ok} { console::done $cons $ok if {$ok} { set msg {Merge completed successfully.} } else { - if {$revcnt != 1} { - info_popup "Octopus merge failed. - -Your merge of $revcnt branches has failed. - -There are file-level conflicts between the branches which must be resolved manually. - -The working directory will now be reset. - -You can attempt this merge again by merging only one branch at a time." $w - - set fd [git_read read-tree --reset -u HEAD] - fconfigure $fd -blocking 0 -translation binary - fileevent $fd readable [cb _reset_wait $fd] - ui_status {Aborting... please wait...} - return - } - set msg {Merge failed. Conflict resolution is required.} } unlock_index @@ -235,7 +184,7 @@ constructor dialog {} { -height 10 \ -width 70 \ -font font_diff \ - -selectmode extended \ + -selectmode browse \ -yscrollcommand [list $w.source.sby set] scrollbar $w.source.sby -command [list $w_list yview] pack $w.source.sby -side right -fill y From a7738c77f1f17ced885ce96e986b948a0b256452 Mon Sep 17 00:00:00 2001 From: Steven Grimm Date: Thu, 19 Jul 2007 03:43:51 -0700 Subject: [PATCH 041/131] Document how to tell git to not launch a pager Signed-off-by: Steven Grimm Signed-off-by: Junio C Hamano --- Documentation/git.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/git.txt b/Documentation/git.txt index 3fbfd45ffe..4c4d1746e0 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -417,7 +417,9 @@ other See gitlink:git-merge[1] 'GIT_PAGER':: - This environment variable overrides `$PAGER`. + This environment variable overrides `$PAGER`. If it is set + to an empty string or to the value "cat", git will not launch + a pager. 'GIT_FLUSH':: If this environment variable is set to "1", then commands such From ef0c2abf3e5061f891b7f07953ef3b0695f52c89 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 19 Jul 2007 22:09:35 -0700 Subject: [PATCH 042/131] Add GIT_EDITOR environment and core.editor configuration variables These variables let you specify an editor that will be launched in preference to the EDITOR and VISUAL environment variables. The order of preference is GIT_EDITOR, core.editor, EDITOR, VISUAL. [jc: added a test and config variable documentation] Signed-off-by: Adam Roben Signed-off-by: Junio C Hamano --- Documentation/config.txt | 8 +++ Documentation/git-commit.txt | 10 ++-- Documentation/git-send-email.txt | 4 +- git-am.sh | 2 +- git-commit.sh | 11 +--- git-rebase--interactive.sh | 2 +- git-send-email.perl | 7 ++- git-sh-setup.sh | 15 ++++++ git-tag.sh | 2 +- t/t7005-editor.sh | 91 ++++++++++++++++++++++++++++++++ 10 files changed, 129 insertions(+), 23 deletions(-) create mode 100755 t/t7005-editor.sh diff --git a/Documentation/config.txt b/Documentation/config.txt index d0e9a175f4..a850d55bf6 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -281,6 +281,14 @@ core.excludesfile:: of files which are not meant to be tracked. See gitlink:gitignore[5]. +core.editor:: + Commands such as `commit` and `tag` that lets you edit + messages by lauching an editor uses the value of this + variable when it is set, and the environment variable + `GIT_EDITOR` is not set. The order of preference is + `GIT_EDITOR` environment, `core.editor`, `EDITOR` and + `VISUAL` environment variables and then finally `vi`. + core.pager:: The command that git will use to paginate output. Can be overridden with the `GIT_PAGER` environment variable. diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index f96142f96a..8e0e7e2d04 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -244,10 +244,12 @@ on the Subject: line and the rest of the commit in the body. include::i18n.txt[] -ENVIRONMENT VARIABLES ---------------------- -The command specified by either the VISUAL or EDITOR environment -variables is used to edit the commit log message. +ENVIRONMENT AND CONFIGURATION VARIABLES +--------------------------------------- +The editor used to edit the commit log message will be chosen from the +GIT_EDITOR environment variable, the core.editor configuration variable, the +VISUAL environment variable, or the EDITOR environment variable (in that +order). HOOKS ----- diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index 293686c31f..d243ed1e3a 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -44,8 +44,8 @@ The --cc option must be repeated for each user you want on the cc list. value; if that is unspecified, default to --chain-reply-to. --compose:: - Use $EDITOR to edit an introductory message for the - patch series. + Use $GIT_EDITOR, core.editor, $VISUAL, or $EDITOR to edit an + introductory message for the patch series. --from:: Specify the sender of the emails. This will default to diff --git a/git-am.sh b/git-am.sh index e5e6f2c91c..bfd65dcf95 100755 --- a/git-am.sh +++ b/git-am.sh @@ -364,7 +364,7 @@ do [yY]*) action=yes ;; [aA]*) action=yes interactive= ;; [nN]*) action=skip ;; - [eE]*) "${VISUAL:-${EDITOR:-vi}}" "$dotest/final-commit" + [eE]*) git_editor "$dotest/final-commit" action=again ;; [vV]*) action=again LESS=-S ${PAGER:-less} "$dotest/patch" ;; diff --git a/git-commit.sh b/git-commit.sh index 3f3de1729e..92749df1e7 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -544,18 +544,9 @@ fi case "$no_edit" in '') - case "${VISUAL:-$EDITOR},$TERM" in - ,dumb) - echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined." - echo >&2 "Please supply the commit log message using either" - echo >&2 "-m or -F option. A boilerplate log message has" - echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG" - exit 1 - ;; - esac git-var GIT_AUTHOR_IDENT > /dev/null || die git-var GIT_COMMITTER_IDENT > /dev/null || die - ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG" + git_editor "$GIT_DIR/COMMIT_EDITMSG" ;; esac diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index f3950767ea..a2d4d09f5d 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -414,7 +414,7 @@ EOF die_abort "Nothing to do" cp "$TODO" "$TODO".backup - ${VISUAL:-${EDITOR:-vi}} "$TODO" || + git_editor "$TODO" || die "Could not execute editor" test -z "$(grep -ve '^$' -e '^#' < $TODO)" && diff --git a/git-send-email.perl b/git-send-email.perl index 7552caca4b..a09b1c9650 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -49,8 +49,8 @@ Options: --bcc Specify a list of email addresses that should be Bcc: on all the emails. - --compose Use \$EDITOR to edit an introductory message for the - patch series. + --compose Use \$GIT_EDITOR, core.editor, \$EDITOR, or \$VISUAL to edit + an introductory message for the patch series. --subject Specify the initial "Subject:" line. Only necessary if --compose is also set. If --compose @@ -341,8 +341,7 @@ GIT: for the patch you are writing. EOT close(C); - my $editor = $ENV{EDITOR}; - $editor = 'vi' unless defined $editor; + my $editor = $ENV{GIT_EDITOR} || $repo->config("core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi"; system($editor, $compose_filename); open(C2,">",$compose_filename . ".final") diff --git a/git-sh-setup.sh b/git-sh-setup.sh index 4ed07e9ddc..c51985e4c3 100755 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -28,6 +28,21 @@ set_reflog_action() { fi } +git_editor() { + GIT_EDITOR=${GIT_EDITOR:-$(git config core.editor || echo ${VISUAL:-${EDITOR}})} + case "$GIT_EDITOR,$TERM" in + ,dumb) + echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL," + echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb." + echo >&2 "Please set one of these variables to an appropriate" + echo >&2 "editor or run $0 with options that will not cause an" + echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)." + exit 1 + ;; + esac + "${GIT_EDITOR:-vi}" "$1" +} + is_bare_repository () { git rev-parse --is-bare-repository } diff --git a/git-tag.sh b/git-tag.sh index 1c25d88c72..5ee3f50a3c 100755 --- a/git-tag.sh +++ b/git-tag.sh @@ -177,7 +177,7 @@ if [ "$annotate" ]; then ( echo "#" echo "# Write a tag message" echo "#" ) > "$GIT_DIR"/TAG_EDITMSG - ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit + git_editor "$GIT_DIR"/TAG_EDITMSG || exit else printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG fi diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh new file mode 100755 index 0000000000..28643b0da4 --- /dev/null +++ b/t/t7005-editor.sh @@ -0,0 +1,91 @@ +#!/bin/sh + +test_description='GIT_EDITOR, core.editor, and stuff' + +. ./test-lib.sh + +for i in GIT_EDITOR core_editor EDITOR VISUAL vi +do + cat >e-$i.sh <<-EOF + echo "Edited by $i" >"\$1" + EOF + chmod +x e-$i.sh +done +unset vi +mv e-vi.sh vi +PATH=".:$PATH" +unset EDITOR VISUAL GIT_EDITOR + +test_expect_success setup ' + + msg="Hand edited" && + echo "$msg" >expect && + git add vi && + test_tick && + git commit -m "$msg" && + git show -s --pretty=oneline | + sed -e "s/^[0-9a-f]* //" >actual && + diff actual expect + +' + +TERM=dumb +export TERM +test_expect_success 'dumb should error out when falling back on vi' ' + + if git commit --amend + then + echo "Oops?" + exit 1 + else + : happy + fi +' + +TERM=vt100 +export TERM +for i in vi EDITOR VISUAL core_editor GIT_EDITOR +do + echo "Edited by $i" >expect + unset EDITOR VISUAL GIT_EDITOR + git config --unset-all core.editor + case "$i" in + core_editor) + git config core.editor ./e-core_editor.sh + ;; + [A-Z]*) + eval "$i=./e-$i.sh" + export $i + ;; + esac + test_expect_success "Using $i" ' + git commit --amend && + git show -s --pretty=oneline | + sed -e "s/^[0-9a-f]* //" >actual && + diff actual expect + ' +done + +unset EDITOR VISUAL GIT_EDITOR +git config --unset-all core.editor +for i in vi EDITOR VISUAL core_editor GIT_EDITOR +do + echo "Edited by $i" >expect + case "$i" in + core_editor) + git config core.editor ./e-core_editor.sh + ;; + [A-Z]*) + eval "$i=./e-$i.sh" + export $i + ;; + esac + test_expect_success "Using $i (override)" ' + git commit --amend && + git show -s --pretty=oneline | + sed -e "s/^[0-9a-f]* //" >actual && + diff actual expect + ' +done + +test_done From 69a9b41c15f25e1e91df5d9c4d5e3d56706f8f0e Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Fri, 20 Jul 2007 02:15:09 +0200 Subject: [PATCH 043/131] gitweb cleanup: Move @diff_opts declaration earlier Move @diff_opts declaration earlier, so that all gitweb options are together (and not separated by %feature hash and some subroutines), with the exception of $GITWEB_CONFIG which must be after all option variables including %feature hash. While at it, in the moved comment, note that diff option '-C' implies '-M', instead of suggesting that '-M', '-C' is required. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index c8ba3a27a3..6754e26873 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -104,6 +104,16 @@ our $mimetypes_file = undef; # could be even 'utf-8' for the old behavior) our $fallback_encoding = 'latin1'; +# rename detection options for git-diff and git-diff-tree +# - default is '-M', with the cost proportional to +# (number of removed files) * (number of new files). +# - more costly is '-C' (which implies '-M'), with the cost proportional to +# (number of changed files + number of removed files) * (number of new files) +# - even more costly is '-C', '--find-copies-harder' with cost +# (number of files in the original tree) * (number of new files) +# - one might want to include '-B' option, e.g. '-B', '-M' +our @diff_opts = ('-M'); # taken from git_commit + # You define site-wide feature defaults here; override them with # $GITWEB_CONFIG as necessary. our %feature = ( @@ -310,16 +320,6 @@ sub check_export_ok { (!$export_ok || -e "$dir/$export_ok")); } -# rename detection options for git-diff and git-diff-tree -# - default is '-M', with the cost proportional to -# (number of removed files) * (number of new files). -# - more costly is '-C' (or '-C', '-M'), with the cost proportional to -# (number of changed files + number of removed files) * (number of new files) -# - even more costly is '-C', '--find-copies-harder' with cost -# (number of files in the original tree) * (number of new files) -# - one might want to include '-B' option, e.g. '-B', '-M' -our @diff_opts = ('-M'); # taken from git_commit - our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++"; do $GITWEB_CONFIG if -e $GITWEB_CONFIG; From e1abc69b72401c5b2eb0e402e0fe10e8e0e5db27 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 20 Jul 2007 23:11:19 -0700 Subject: [PATCH 044/131] Fix up duplicate parents removal This removes duplicate parents properly, making gitk happy again. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- revision.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/revision.c b/revision.c index 28b5f2eace..7036cf2246 100644 --- a/revision.c +++ b/revision.c @@ -1323,16 +1323,17 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp static void remove_duplicate_parents(struct commit *commit) { - struct commit_list *p; - struct commit_list **pp = &commit->parents; + struct commit_list **pp, *p; /* Examine existing parents while marking ones we have seen... */ - for (p = commit->parents; p; p = p->next) { + pp = &commit->parents; + while ((p = *pp) != NULL) { struct commit *parent = p->item; - if (parent->object.flags & TMP_MARK) + if (parent->object.flags & TMP_MARK) { + *pp = p->next; continue; + } parent->object.flags |= TMP_MARK; - *pp = p; pp = &p->next; } /* ... and clear the temporary mark */ From 4578c5cb690df98d0d5fbea043114b4b7dec8f57 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 21 Jul 2007 04:57:57 -0400 Subject: [PATCH 045/131] git-gui: Automatically backup the user's commit buffer A few users have been seeing crashes in Tk when using the undo key binding to undo the last few keystroke events in the commit buffer. Unfortunately that means the user loses their commit message and must start over from scratch when the user restarts the process. git-gui now saves the user's commit message buffer every couple of seconds to a temporary file under .git (specifically .git/GITGUI_BCK). At exit time we rename this file to .git/GITGUI_MSG if there is a message, the file exists, and it is currently synchronized with the Tk buffer. Otherwise we do our usual routine of saving the Tk buffer to .git/GITGUI_MSG and delete .git/GITGUI_BCK, if it exists. During startup we favor .git/GITGUI_BCK over .git/GITGUI_MSG. This way a crash doesn't take out the user's message buffer but instead will cause the user to lose only a few keystrokes. Most people do not type more than 200 WPM, and with 30 possible saves per minute we are unlikely to lose more than 7 words. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 88 +++++++++++++++++++++++++++++++++++++++++++------- lib/commit.tcl | 4 +++ 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index c5ff7c8a83..d85d7076e2 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1417,6 +1417,7 @@ set is_quitting 0 proc do_quit {} { global ui_comm is_quitting repo_config commit_type + global GITGUI_BCK_exists GITGUI_BCK_i if {$is_quitting} return set is_quitting 1 @@ -1425,18 +1426,30 @@ proc do_quit {} { # -- Stash our current commit buffer. # set save [gitdir GITGUI_MSG] - set msg [string trim [$ui_comm get 0.0 end]] - regsub -all -line {[ \r\t]+$} $msg {} msg - if {(![string match amend* $commit_type] - || [$ui_comm edit modified]) - && $msg ne {}} { - catch { - set fd [open $save w] - puts -nonewline $fd $msg - close $fd - } + if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} { + file rename -force [gitdir GITGUI_BCK] $save + set GITGUI_BCK_exists 0 } else { - catch {file delete $save} + set msg [string trim [$ui_comm get 0.0 end]] + regsub -all -line {[ \r\t]+$} $msg {} msg + if {(![string match amend* $commit_type] + || [$ui_comm edit modified]) + && $msg ne {}} { + catch { + set fd [open $save w] + puts -nonewline $fd $msg + close $fd + } + } else { + catch {file delete $save} + } + } + + # -- Remove our editor backup, its not needed. + # + after cancel $GITGUI_BCK_i + if {$GITGUI_BCK_exists} { + catch {file delete [gitdir GITGUI_BCK]} } # -- Stash our current window geometry into this repository. @@ -2598,6 +2611,59 @@ if {[is_enabled transport]} { populate_push_menu } +if {[winfo exists $ui_comm]} { + set GITGUI_BCK_exists [load_message GITGUI_BCK] + + # -- If both our backup and message files exist use the + # newer of the two files to initialize the buffer. + # + if {$GITGUI_BCK_exists} { + set m [gitdir GITGUI_MSG] + if {[file isfile $m]} { + if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} { + catch {file delete [gitdir GITGUI_MSG]} + } else { + $ui_comm delete 0.0 end + $ui_comm edit reset + $ui_comm edit modified false + catch {file delete [gitdir GITGUI_BCK]} + set GITGUI_BCK_exists 0 + } + } + unset m + } + + proc backup_commit_buffer {} { + global ui_comm GITGUI_BCK_exists + + set m [$ui_comm edit modified] + if {$m || $GITGUI_BCK_exists} { + set msg [string trim [$ui_comm get 0.0 end]] + regsub -all -line {[ \r\t]+$} $msg {} msg + + if {$msg eq {}} { + if {$GITGUI_BCK_exists} { + catch {file delete [gitdir GITGUI_BCK]} + set GITGUI_BCK_exists 0 + } + } elseif {$m} { + catch { + set fd [open [gitdir GITGUI_BCK] w] + puts -nonewline $fd $msg + close $fd + set GITGUI_BCK_exists 1 + } + } + + $ui_comm edit modified false + } + + set ::GITGUI_BCK_i [after 2000 backup_commit_buffer] + } + + backup_commit_buffer +} + lock_index begin-read if {![winfo ismapped .]} { wm deiconify . diff --git a/lib/commit.tcl b/lib/commit.tcl index 75b13a0d99..6b86f9808e 100644 --- a/lib/commit.tcl +++ b/lib/commit.tcl @@ -379,6 +379,10 @@ A rescan will be automatically started now. $ui_comm delete 0.0 end $ui_comm edit reset $ui_comm edit modified false + if {$::GITGUI_BCK_exists} { + catch {file delete [gitdir GITGUI_BCK]} + set $::GITGUI_BCK_exists 0 + } if {[is_enabled singlecommit]} do_quit From 60f7352fe1ae3d42ca7bd7611b6b787ff70cd813 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 20 Jul 2007 02:13:24 -0400 Subject: [PATCH 046/131] git-gui: Save the merge base during checkout_op processing I've decided to teach checkout_op how to perform more than just a fast-forward and reset type of merge. This way we can also do a full recursive merge even when we are recreating an existing branch from a remote. To help with that process I'm saving the merge-base we computed during the ff/reset/fail decision process, in case we need it later on when we actually start a true merge operation. Signed-off-by: Shawn O. Pearce --- lib/checkout_op.tcl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/checkout_op.tcl b/lib/checkout_op.tcl index 00a994be12..262dc96895 100644 --- a/lib/checkout_op.tcl +++ b/lib/checkout_op.tcl @@ -12,6 +12,7 @@ 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 merge_base {}; # merge base if we have another ref involved 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? @@ -180,15 +181,14 @@ method _update_ref {} { # No merge would be required, don't compute anything. # } else { - set mrb {} - catch {set mrb [git merge-base $new $cur]} + catch {set merge_base [git merge-base $new $cur]} switch -- $merge_type { ff { - if {$mrb eq $new} { + if {$merge_base eq $new} { # The current branch is actually newer. # set new $cur - } elseif {$mrb eq $cur} { + } elseif {$merge_base eq $cur} { # The current branch is older. # set reflog_msg "merge $new_expr: Fast-forward" @@ -198,7 +198,7 @@ method _update_ref {} { } } reset { - if {$mrb eq $cur} { + if {$merge_base eq $cur} { # The current branch is older. # set reflog_msg "merge $new_expr: Fast-forward" From f66b8a68f21d7dba6b80ba213315974476001b93 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 20 Jul 2007 03:34:56 -0400 Subject: [PATCH 047/131] git-gui: Factor out common fast-forward merge case In both the ff and reset merge_types supported by checkout_op the result is the same if the merge base of our target commit and the existing commit is the existing commit: its a fast-forward as the existing commit is fully contained in the target commit. This minor cleanup in logic will make it easier to implement a new kind of merge_type that actually merges the two trees with a real merge strategy, such as git-merge-recursive. Signed-off-by: Shawn O. Pearce --- lib/checkout_op.tcl | 46 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/lib/checkout_op.tcl b/lib/checkout_op.tcl index 262dc96895..6d87830dd6 100644 --- a/lib/checkout_op.tcl +++ b/lib/checkout_op.tcl @@ -182,27 +182,23 @@ method _update_ref {} { # } else { catch {set merge_base [git merge-base $new $cur]} - switch -- $merge_type { - ff { - if {$merge_base eq $new} { - # The current branch is actually newer. - # - set new $cur - } elseif {$merge_base 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 + if {$merge_base eq $cur} { + # The current branch is older. + # + set reflog_msg "merge $new_expr: Fast-forward" + } else { + switch -- $merge_type { + ff { + if {$merge_base eq $new} { + # The current branch is actually newer. + # + set new $cur + } else { + _error $this "Branch '$newbranch' already exists.\n\nIt cannot fast-forward to $new_expr.\nA merge is required." + return 0 + } } - } - reset { - if {$merge_base eq $cur} { - # The current branch is older. - # - set reflog_msg "merge $new_expr: Fast-forward" - } else { + reset { # The current branch will lose things. # if {[_confirm_reset $this $cur]} { @@ -211,11 +207,11 @@ method _update_ref {} { return 0 } } - } - default { - _error $this "Only 'ff' and 'reset' merge is currently supported." - return 0 - } + default { + _error $this "Only 'ff' and 'reset' merge is currently supported." + return 0 + } + } } } From eea1ab6e23db4c929500fb11464a438b0ba569f0 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 20 Jul 2007 03:37:43 -0400 Subject: [PATCH 048/131] git-gui: Simplify error case for unsupported merge types If we are given a merge type we don't understand in checkout_op there is probably a bug in git-gui somewhere that allowed this unknown merge strategy to come into this part of the code path. We currently only recognize three merge types ('none', 'ff' and 'reset') but are going to be supporting more in the future. Rather than keep editing this message I'm going with a very generic "Uh, we don't do that!" type of error. 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 6d87830dd6..554c107032 100644 --- a/lib/checkout_op.tcl +++ b/lib/checkout_op.tcl @@ -208,7 +208,7 @@ method _update_ref {} { } } default { - _error $this "Only 'ff' and 'reset' merge is currently supported." + _error $this "Merge strategy '$merge_type' not supported." return 0 } } From dba07411da8debf9e39bf8d28f642b09c5794aff Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 20 Jul 2007 03:56:06 -0400 Subject: [PATCH 049/131] git-gui: Skip unnecessary read-tree work during checkout I totally missed this obvious optimization in the checkout code path. If our current repository HEAD is actually at the commit we are moving to, and we agreed to perform this switch earlier, then we have no files to update in the working directory and any stale mtimes are simply not of consequence right now. We can pretend like we ran a read-tree and skip right into the post-read-tree work, such as updating the branch and setting the symbolic-ref. Signed-off-by: Shawn O. Pearce --- lib/checkout_op.tcl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/checkout_op.tcl b/lib/checkout_op.tcl index 554c107032..cb04d1e57e 100644 --- a/lib/checkout_op.tcl +++ b/lib/checkout_op.tcl @@ -266,7 +266,9 @@ The rescan will be automatically started now. return } - if {[is_config_true gui.trustmtime]} { + if {$curHEAD eq $new_hash} { + _after_readtree $this + } elseif {[is_config_true gui.trustmtime]} { _readtree $this } else { ui_status {Refreshing file status...} From 54febd4fe62cc32b1337cd928af17a5a09624d74 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 20 Jul 2007 04:10:13 -0400 Subject: [PATCH 050/131] git-gui: Internally allow fetch without storing for future pull support This is actually just an underlying code improvement that has no user visible component yet. UI improvements to actually fetch and merge via an arbitrary remote with no tracking branches must still follow to make this change useful for the end-user. Our tracking branch specifications are a Tcl list of three components: - local tracking branch name - remote name/url - remote branch name/tag name This change just makes the first element optional. If it is an empty string we will run the fetch, but have the value be saved only into the special .git/FETCH_HEAD, where we can pick it up and use it for this one time operation. Signed-off-by: Shawn O. Pearce --- lib/checkout_op.tcl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/checkout_op.tcl b/lib/checkout_op.tcl index cb04d1e57e..0571115128 100644 --- a/lib/checkout_op.tcl +++ b/lib/checkout_op.tcl @@ -66,14 +66,19 @@ method run {} { set r_head [lindex $fetch_spec 2] regsub ^refs/heads/ $r_head {} r_name + set cmd [list git fetch $remote] + if {$l_trck ne {}} { + lappend cmd +$r_head:$l_trck + } else { + lappend cmd $r_head + } + _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] + $w_cons exec $cmd [cb _finish_fetch] bind $w <$M1B-Key-w> break bind $w <$M1B-Key-W> break @@ -114,6 +119,9 @@ method _noop {} {} method _finish_fetch {ok} { if {$ok} { set l_trck [lindex $fetch_spec 0] + if {$l_trck eq {}} { + set l_trck FETCH_HEAD + } if {[catch {set new_hash [git rev-parse --verify "$l_trck^0"]} err]} { set ok 0 $w_cons insert "fatal: Cannot resolve $l_trck" From 6368f3f8e701cb080b83ceb8ee622636046c514c Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 21 Jul 2007 18:09:41 +0100 Subject: [PATCH 051/131] rebase -i: call editor just once for a multi-squash Sometimes you want to squash more than two commits. Before this patch, the editor was fired up for each squash command. Now the editor is started only with the last squash command. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 56 ++++++++++++++++++++++++++++------- t/t3404-rebase-interactive.sh | 9 ++++++ 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index a2d4d09f5d..579a45ebbb 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -19,6 +19,8 @@ require_work_tree DOTEST="$GIT_DIR/.dotest-merge" TODO="$DOTEST"/todo DONE="$DOTEST"/done +MSG="$DOTEST"/message +SQUASH_MSG="$DOTEST"/message-squash REWRITTEN="$DOTEST"/rewritten PRESERVE_MERGES= STRATEGY= @@ -158,6 +160,38 @@ pick_one_preserving_merges () { esac } +nth_string () { + case "$1" in + *1[0-9]|*[04-9]) echo "$1"th;; + *1) echo "$1"st;; + *2) echo "$1"nd;; + *3) echo "$1"rd;; + esac +} + +make_squash_message () { + if [ -f "$SQUASH_MSG" ]; then + COUNT=$(($(sed -n "s/^# This is [^0-9]*\([0-9]\+\).*/\1/p" \ + < "$SQUASH_MSG" | tail -n 1)+1)) + echo "# This is a combination of $COUNT commits." + sed -n "2,\$p" < "$SQUASH_MSG" + else + COUNT=2 + echo "# This is a combination of two commits." + echo "# The first commit's message is:" + echo + git cat-file commit HEAD | sed -e '1,/^$/d' + echo + fi + echo "# This is the $(nth_string $COUNT) commit message:" + echo + git cat-file commit $1 | sed -e '1,/^$/d' +} + +peek_next_command () { + sed -n "1s/ .*$//p" < "$TODO" +} + do_next () { test -f "$DOTEST"/message && rm "$DOTEST"/message test -f "$DOTEST"/author-script && rm "$DOTEST"/author-script @@ -194,17 +228,19 @@ do_next () { die "Cannot 'squash' without a previous commit" mark_action_done - MSG="$DOTEST"/message - echo "# This is a combination of two commits." > "$MSG" - echo "# The first commit's message is:" >> "$MSG" - echo >> "$MSG" - git cat-file commit HEAD | sed -e '1,/^$/d' >> "$MSG" - echo >> "$MSG" + make_squash_message $sha1 > "$MSG" + case "$(peek_next_command)" in + squash) + EDIT_COMMIT= + cp "$MSG" "$SQUASH_MSG" + ;; + *) + EDIT_COMMIT=-e + test -f "$SQUASH_MSG" && rm "$SQUASH_MSG" + esac + failed=f pick_one -n $sha1 || failed=t - echo "# And this is the 2nd commit message:" >> "$MSG" - echo >> "$MSG" - git cat-file commit $sha1 | sed -e '1,/^$/d' >> "$MSG" git reset --soft HEAD^ author_script=$(get_author_ident_from_commit $sha1) echo "$author_script" > "$DOTEST"/author-script @@ -213,7 +249,7 @@ do_next () { # This is like --amend, but with a different message eval "$author_script" export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE - git commit -F "$MSG" -e + git commit -F "$MSG" $EDIT_COMMIT ;; t) cp "$MSG" "$GIT_DIR"/MERGE_MSG diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 43a6675caa..8206436cc7 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -65,6 +65,7 @@ cat > fake-editor.sh << EOF #!/bin/sh test "\$1" = .git/COMMIT_EDITMSG && { test -z "\$FAKE_COMMIT_MESSAGE" || echo "\$FAKE_COMMIT_MESSAGE" > "\$1" + test -z "\$FAKE_COMMIT_AMEND" || echo "\$FAKE_COMMIT_AMEND" >> "\$1" exit } test -z "\$FAKE_LINES" && exit @@ -212,4 +213,12 @@ test_expect_success 'verbose flag is heeded, even after --continue' ' grep "^ file1 | 2 +-$" output ' +test_expect_success 'multi-squash only fires up editor once' ' + base=$(git rev-parse HEAD~4) && + FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \ + git rebase -i $base && + test $base = $(git rev-parse HEAD^) && + test 1 = $(git show | grep ONCE | wc -l) +' + test_done From a3c8ab30a54c30a6a434760bedf04548425416ef Mon Sep 17 00:00:00 2001 From: Matt McCutchen Date: Sun, 22 Jul 2007 01:30:27 +0200 Subject: [PATCH 052/131] gitweb: snapshot cleanups & support for offering multiple formats - Centralize knowledge about snapshot formats (mime types, extensions, commands) in %known_snapshot_formats and improve how some of that information is specified. In particular, zip files are no longer a special case. - Add support for offering multiple snapshot formats to the user so that he/she can download a snapshot in the format he/she prefers. The site-wide or project configuration now gives a list of formats to offer, and if more than one format is offered, the "_snapshot_" link becomes something like "snapshot (_tar.bz2_ _zip_)". - If only one format is offered, a tooltip on the "_snapshot_" link tells the user what it is. - Fix out-of-date "tarball" -> "archive" in comment. Alert for gitweb site administrators: This patch changes the format of $feature{'snapshot'}{'default'} in gitweb_config.perl from a list of three pieces of information about a single format to a list of one or more formats you wish to offer from the set ('tgz', 'tbz2', 'zip'). Update your gitweb_config.perl appropriately. There was taken care for old-style gitweb configuration to work as it used to, but this backward compatibility works only for the values which correspond to gitweb.snapshot values of 'gzip', 'bzip2' and 'zip', i.e. ['x-gzip', 'gz', 'gzip'] ['x-bzip2', 'bz2', 'bzip2'] ['x-zip', 'zip', ''] The preferred names for gitweb.snapshot in repository configuration have also changed from 'gzip' and 'bzip2' to 'tgz' and 'tbz2', but the old names are still recognized for compatibility. Signed-off-by: Matt McCutchen Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 166 +++++++++++++++++++++++++++++++-------------- 1 file changed, 116 insertions(+), 50 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 6754e26873..c4f88245aa 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -114,6 +114,49 @@ our $fallback_encoding = 'latin1'; # - one might want to include '-B' option, e.g. '-B', '-M' our @diff_opts = ('-M'); # taken from git_commit +# information about snapshot formats that gitweb is capable of serving +our %known_snapshot_formats = ( + # name => { + # 'display' => display name, + # 'type' => mime type, + # 'suffix' => filename suffix, + # 'format' => --format for git-archive, + # 'compressor' => [compressor command and arguments] + # (array reference, optional)} + # + 'tgz' => { + 'display' => 'tar.gz', + 'type' => 'application/x-gzip', + 'suffix' => '.tar.gz', + 'format' => 'tar', + 'compressor' => ['gzip']}, + + 'tbz2' => { + 'display' => 'tar.bz2', + 'type' => 'application/x-bzip2', + 'suffix' => '.tar.bz2', + 'format' => 'tar', + 'compressor' => ['bzip2']}, + + 'zip' => { + 'display' => 'zip', + 'type' => 'application/x-zip', + 'suffix' => '.zip', + 'format' => 'zip'}, +); + +# Aliases so we understand old gitweb.snapshot values in repository +# configuration. +our %known_snapshot_format_aliases = ( + 'gzip' => 'tgz', + 'bzip2' => 'tbz2', + + # backward compatibility: legacy gitweb config support + 'x-gzip' => undef, 'gz' => undef, + 'x-bzip2' => undef, 'bz2' => undef, + 'x-zip' => undef, '' => undef, +); + # You define site-wide feature defaults here; override them with # $GITWEB_CONFIG as necessary. our %feature = ( @@ -144,20 +187,22 @@ our %feature = ( 'override' => 0, 'default' => [0]}, - # Enable the 'snapshot' link, providing a compressed tarball of any + # Enable the 'snapshot' link, providing a compressed archive of any # tree. This can potentially generate high traffic if you have large # project. + # Value is a list of formats defined in %known_snapshot_formats that + # you wish to offer. # To disable system wide have in $GITWEB_CONFIG - # $feature{'snapshot'}{'default'} = [undef]; + # $feature{'snapshot'}{'default'} = []; # To have project specific config enable override in $GITWEB_CONFIG # $feature{'snapshot'}{'override'} = 1; - # and in project config gitweb.snapshot = none|gzip|bzip2|zip; + # and in project config, a comma-separated list of formats or "none" + # to disable. Example: gitweb.snapshot = tbz2,zip; 'snapshot' => { 'sub' => \&feature_snapshot, 'override' => 0, - # => [content-encoding, suffix, program] - 'default' => ['x-gzip', 'gz', 'gzip']}, + 'default' => ['tgz']}, # Enable text search, which will list the commits which match author, # committer or commit text to a given string. Enabled by default. @@ -256,28 +301,19 @@ sub feature_blame { } sub feature_snapshot { - my ($ctype, $suffix, $command) = @_; + my (@fmts) = @_; my ($val) = git_get_project_config('snapshot'); - if ($val eq 'gzip') { - return ('x-gzip', 'gz', 'gzip'); - } elsif ($val eq 'bzip2') { - return ('x-bzip2', 'bz2', 'bzip2'); - } elsif ($val eq 'zip') { - return ('x-zip', 'zip', ''); - } elsif ($val eq 'none') { - return (); + if ($val) { + @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val); + @fmts = grep { defined } map { + exists $known_snapshot_format_aliases{$_} ? + $known_snapshot_format_aliases{$_} : $_ } @fmts; + @fmts = grep(exists $known_snapshot_formats{$_}, @fmts); } - return ($ctype, $suffix, $command); -} - -sub gitweb_have_snapshot { - my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot'); - my $have_snapshot = (defined $ctype && defined $suffix); - - return $have_snapshot; + return @fmts; } sub feature_grep { @@ -563,6 +599,7 @@ sub href(%) { order => "o", searchtext => "s", searchtype => "st", + snapshot_format => "sf", ); my %mapping = @mapping; @@ -1257,6 +1294,39 @@ sub format_diff_line { return "
" . esc_html($line, -nbsp=>1) . "
\n"; } +# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)", +# linked. Pass the hash of the tree/commit to snapshot. +sub format_snapshot_links { + my ($hash) = @_; + my @snapshot_fmts = gitweb_check_feature('snapshot'); + my $num_fmts = @snapshot_fmts; + if ($num_fmts > 1) { + # A parenthesized list of links bearing format names. + return "snapshot (" . join(' ', map + $cgi->a({ + -href => href( + action=>"snapshot", + hash=>$hash, + snapshot_format=>$_ + ) + }, $known_snapshot_formats{$_}{'display'}) + , @snapshot_fmts) . ")"; + } elsif ($num_fmts == 1) { + # A single "snapshot" link whose tooltip bears the format name. + my ($fmt) = @snapshot_fmts; + return $cgi->a({ + -href => href( + action=>"snapshot", + hash=>$hash, + snapshot_format=>$fmt + ), + -title => "in format: $known_snapshot_formats{$fmt}{'display'}" + }, "snapshot"); + } else { # $num_fmts == 0 + return undef; + } +} + ## ---------------------------------------------------------------------- ## git utility subroutines, invoking git commands @@ -3321,8 +3391,6 @@ sub git_shortlog_body { # uses global variable $project my ($commitlist, $from, $to, $refs, $extra) = @_; - my $have_snapshot = gitweb_have_snapshot(); - $from = 0 unless defined $from; $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to); @@ -3349,8 +3417,9 @@ sub git_shortlog_body { $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " . $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " . $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree"); - if ($have_snapshot) { - print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot"); + my $snapshot_links = format_snapshot_links($commit); + if (defined $snapshot_links) { + print " | " . $snapshot_links; } print "\n" . "\n"; @@ -4132,8 +4201,6 @@ sub git_blob { } sub git_tree { - my $have_snapshot = gitweb_have_snapshot(); - if (!defined $hash_base) { $hash_base = "HEAD"; } @@ -4167,11 +4234,10 @@ sub git_tree { hash_base=>"HEAD", file_name=>$file_name)}, "HEAD"), } - if ($have_snapshot) { + my $snapshot_links = format_snapshot_links($hash); + if (defined $snapshot_links) { # FIXME: Should be available when we have no hash base as well. - push @views_nav, - $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, - "snapshot"); + push @views_nav, $snapshot_links; } git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav)); git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base); @@ -4235,33 +4301,36 @@ sub git_tree { } sub git_snapshot { - my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot'); - my $have_snapshot = (defined $ctype && defined $suffix); - if (!$have_snapshot) { - die_error('403 Permission denied', "Permission denied"); + my @supported_fmts = gitweb_check_feature('snapshot'); + + my $format = $cgi->param('sf'); + unless ($format =~ m/[a-z0-9]+/ + && exists($known_snapshot_formats{$format}) + && grep($_ eq $format, @supported_fmts)) { + die_error(undef, "Unsupported snapshot format"); } if (!defined $hash) { $hash = git_get_head_hash($project); } - my $git = git_cmd_str(); + my $git_command = git_cmd_str(); my $name = $project; $name =~ s,([^/])/*\.git$,$1,; $name = basename($name); my $filename = to_utf8($name); $name =~ s/\047/\047\\\047\047/g; my $cmd; - if ($suffix eq 'zip') { - $filename .= "-$hash.$suffix"; - $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash"; - } else { - $filename .= "-$hash.tar.$suffix"; - $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"; + $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}"; + $cmd = "$git_command archive " . + "--format=$known_snapshot_formats{$format}{'format'}" . + "--prefix=\'$name\'/ $hash"; + if (exists $known_snapshot_formats{$format}{'compressor'}) { + $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}}; } print $cgi->header( - -type => "application/$ctype", + -type => $known_snapshot_formats{$format}{'type'}, -content_disposition => 'inline; filename="' . "$filename" . '"', -status => '200 OK'); @@ -4271,7 +4340,6 @@ sub git_snapshot { print <$fd>; binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi close $fd; - } sub git_log { @@ -4390,8 +4458,6 @@ sub git_commit { my $refs = git_get_references(); my $ref = format_ref_marker($refs, $co{'id'}); - my $have_snapshot = gitweb_have_snapshot(); - git_header_html(undef, $expires); git_print_page_nav('commit', '', $hash, $co{'tree'}, $hash, @@ -4430,9 +4496,9 @@ sub git_commit { "" . $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, "tree"); - if ($have_snapshot) { - print " | " . - $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot"); + my $snapshot_links = format_snapshot_links($hash); + if (defined $snapshot_links) { + print " | " . $snapshot_links; } print "" . "\n"; From a644ffde0afabc873863ac57d9fdaf5f605f50b7 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 21 Jul 2007 22:37:56 -0700 Subject: [PATCH 053/131] Fix VISUAL/EDITOR preference order in Documentation/config.txt. I screwed up when amending ef0c2abf. Signed-off-by: Junio C Hamano --- Documentation/config.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index a850d55bf6..dd98d95d97 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -286,8 +286,8 @@ core.editor:: messages by lauching an editor uses the value of this variable when it is set, and the environment variable `GIT_EDITOR` is not set. The order of preference is - `GIT_EDITOR` environment, `core.editor`, `EDITOR` and - `VISUAL` environment variables and then finally `vi`. + `GIT_EDITOR` environment, `core.editor`, `VISUAL` and + `EDITOR` environment variables and then finally `vi`. core.pager:: The command that git will use to paginate output. Can be overridden From 98ec4ad7f908a6df8c2d4eedf309c06fe840c5c3 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sun, 22 Jul 2007 01:53:49 +0200 Subject: [PATCH 054/131] Documentation/gitignore.txt: Fix the seriously misleading priority explanation Signed-off-by: David Kastrup Signed-off-by: Junio C Hamano --- Documentation/gitignore.txt | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt index ea79d74b88..9c83095693 100644 --- a/Documentation/gitignore.txt +++ b/Documentation/gitignore.txt @@ -18,21 +18,26 @@ pattern. When deciding whether to ignore a path, git normally checks `gitignore` patterns from multiple sources, with the following -order of precedence: +order of precedence, from highest to lowest (within one level of +precedence, the last matching pattern decides the outcome): - * Patterns read from the file specified by the configuration - variable 'core.excludesfile'. - - * Patterns read from `$GIT_DIR/info/exclude`. + * Patterns read from the command line for those commands that support + them. * Patterns read from a `.gitignore` file in the same directory - as the path, or in any parent directory, ordered from the - deepest such file to a file in the root of the repository. + as the path, or in any parent directory, with patterns in the + higher level files (up to the root) being overriden by those in + lower level files down to the directory containing the file. These patterns match relative to the location of the `.gitignore` file. A project normally includes such `.gitignore` files in its repository, containing patterns for files generated as part of the project build. + * Patterns read from `$GIT_DIR/info/exclude`. + + * Patterns read from the file specified by the configuration + variable 'core.excludesfile'. + The underlying git plumbing tools, such as gitlink:git-ls-files[1] and gitlink:git-read-tree[1], read `gitignore` patterns specified by command-line options, or from @@ -49,7 +54,8 @@ Patterns have the following format: - An optional prefix '!' which negates the pattern; any matching file excluded by a previous pattern will become - included again. + included again. If a negated pattern matches, this will + override lower precedence patterns sources. - If the pattern does not contain a slash '/', git treats it as a shell glob pattern and checks for a match against the From 854ffd3046ba9776934ffea79c5aceb1d51cf3c5 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 21 Jul 2007 16:32:42 -0400 Subject: [PATCH 055/131] git-gui: Completely remove my Tools/Migrate hack This menu option of Tools/Migrate has been living inside of git-gui as a local hack to support some coworkers of mine. It has no value to anyone outside of my day-job team and never really should have been in a release version of git-gui. So I'm pulling it out, so that nobody else has to deal with this garbage. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index d85d7076e2..07a478c793 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1895,35 +1895,6 @@ if {[is_MacOSX]} { .mbar.edit add separator .mbar.edit add command -label {Options...} \ -command do_options - - # -- Tools Menu - # - if {[is_Cygwin] - && [is_enabled multicommit] - && [file exists /usr/local/miga/lib/gui-miga]} { - proc do_miga {} { - if {![lock_index update]} return - set cmd [list sh --login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""] - set miga_fd [open "|$cmd" r] - fconfigure $miga_fd -blocking 0 - fileevent $miga_fd readable [list miga_done $miga_fd] - ui_status {Running miga...} - } - proc miga_done {fd} { - read $fd 512 - if {[eof $fd]} { - close $fd - unlock_index - rescan ui_ready - } - } - .mbar add cascade -label Tools -menu .mbar.tools - menu .mbar.tools - .mbar.tools add command -label "Migrate" \ - -command do_miga - lappend disable_on_lock \ - [list .mbar.tools entryconf [.mbar.tools index last] -state] - } } # -- Help Menu From 7bd197c7ba0b93744bf0f804ec4fb0d448044e83 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 22 Jul 2007 04:09:53 -0400 Subject: [PATCH 056/131] git-gui: Fix unnecessary fast-forward during checkout If we are trying to checkout a local branch which is matched to a remote tracking branch, but the local branch is newer than the remote tracking branch we actually just want to switch to the local branch. The local branch is "Already up to date". Unfortunately we tossed away the local branch's commit SHA-1 and kept the remote tracking branch's SHA-1, which meant that the user lost the local changes when we updated the working directory. At least we did not update the local branch ref, so the user's data was still intact. We now toss the tracking branch's SHA-1 and replace with the local branch's SHA-1 before the checkout, ensuring that we pass of the right tree to git-read-tree when we update the working directory. Signed-off-by: Shawn O. Pearce --- lib/checkout_op.tcl | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/checkout_op.tcl b/lib/checkout_op.tcl index 0571115128..8c42ca8005 100644 --- a/lib/checkout_op.tcl +++ b/lib/checkout_op.tcl @@ -201,6 +201,7 @@ method _update_ref {} { # The current branch is actually newer. # set new $cur + set new_hash $cur } else { _error $this "Branch '$newbranch' already exists.\n\nIt cannot fast-forward to $new_expr.\nA merge is required." return 0 From e5633cbb8577b430f175f62cf4e7ed53f2434a89 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 21 Jul 2007 23:18:33 -0700 Subject: [PATCH 057/131] Synonyms: -i == --regexp-ignore-case, -E == --extended-regexp These options to log family were too long to type. Give them shorter synonyms. Fix the parsing of the long options while at it. Signed-off-by: Junio C Hamano --- Documentation/git-rev-list.txt | 7 ++++--- revision.c | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt index 08e7573b9e..0430139093 100644 --- a/Documentation/git-rev-list.txt +++ b/Documentation/git-rev-list.txt @@ -27,7 +27,8 @@ SYNOPSIS [ \--cherry-pick ] [ \--encoding[=] ] [ \--(author|committer|grep)= ] - [ \--regexp-ignore-case ] [ \--extended-regexp ] + [ \--regexp-ignore-case | \-i ] + [ \--extended-regexp | \-E ] [ \--date={local|relative|default|iso|rfc|short} ] [ [\--objects | \--objects-edge] [ \--unpacked ] ] [ \--pretty | \--header ] @@ -227,11 +228,11 @@ limiting may be applied. Limit the commits output to ones with log message that matches the specified pattern (regular expression). ---regexp-ignore-case:: +-i, --regexp-ignore-case:: Match the regexp limiting patterns without regard to letters case. ---extended-regexp:: +-E, --extended-regexp:: Consider the limiting patterns to be extended regular expressions instead of the default basic regular expressions. diff --git a/revision.c b/revision.c index 7036cf2246..00b75bc10b 100644 --- a/revision.c +++ b/revision.c @@ -1165,11 +1165,13 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch add_message_grep(revs, arg+7); continue; } - if (!prefixcmp(arg, "--extended-regexp")) { + if (!strcmp(arg, "--extended-regexp") || + !strcmp(arg, "-E")) { regflags |= REG_EXTENDED; continue; } - if (!prefixcmp(arg, "--regexp-ignore-case")) { + if (!strcmp(arg, "--regexp-ignore-case") || + !strcmp(arg, "-i")) { regflags |= REG_ICASE; continue; } From c4640fe8d9e25fd3e206a39233c71a6dbb68917e Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 22 Jul 2007 10:23:05 +0200 Subject: [PATCH 058/131] Avoid to duplicate commit message when is not encoded When a commit message doesn't have encoding information and encoding output is utf-8 (default) then an useless xstrdup() of commit message is done. If we assume most of users live in an utf-8 world, this useless copy is the common case. Performance issue found with KCachegrind. Signed-off-by: Marco Costalba Signed-off-by: Junio C Hamano --- commit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commit.c b/commit.c index 4c5dfa9af0..dc5a0643f3 100644 --- a/commit.c +++ b/commit.c @@ -721,7 +721,10 @@ static char *logmsg_reencode(const struct commit *commit, encoding = get_header(commit, "encoding"); use_encoding = encoding ? encoding : utf8; if (!strcmp(use_encoding, output_encoding)) - out = xstrdup(commit->buffer); + if (encoding) /* we'll strip encoding header later */ + out = xstrdup(commit->buffer); + else + return NULL; /* nothing to do */ else out = reencode_string(commit->buffer, output_encoding, use_encoding); From ef3192b8345ba73c1d7c86ed0a1f318f26d97dc6 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Sun, 22 Jul 2007 22:05:30 +1000 Subject: [PATCH 059/131] gitk: Make the fake commit for the index changes green rather than magenta The magenta was a bit close in color to the normal blue commits. This makes them green instead as suggested by Linus. Signed-off-by: Paul Mackerras --- gitk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitk b/gitk index 7ce86b849e..995833fa52 100755 --- a/gitk +++ b/gitk @@ -3403,7 +3403,7 @@ proc drawcmittext {id row col} { if {$id eq $nullid} { set ofill red } elseif {$id eq $nullid2} { - set ofill magenta + set ofill green } else { set ofill [expr {$listed != 0? "blue": "white"}] } From 86da5b6c978be1e64ec42c8b08e815a83f02493e Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Tue, 17 Jul 2007 18:42:04 -0400 Subject: [PATCH 060/131] [PATCH] gitk: Ignore ctrl-z as EOF on windows Cygwin's Tcl is configured to honor any occurence of ctrl-z as an end-of-file marker, while some commits in the git repository and possibly elsewhere include that character in the commit comment. This causes gitk ignore commit history following such a comment and incorrect graphs. This change affects only Windows as Tcl on other platforms already has eofchar == {}. This fixes problems noted by me and by Ray Lehtiniemi, and the fix was suggested by Shawn Pierce. Signed-off-by: Mark Levedahl Signed-off-by: Paul Mackerras --- gitk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitk b/gitk index 995833fa52..d6f62b2a0f 100755 --- a/gitk +++ b/gitk @@ -101,7 +101,7 @@ proc start_rev_list {view} { set commfd($view) $fd set leftover($view) {} set lookingforhead $showlocalchanges - fconfigure $fd -blocking 0 -translation lf + fconfigure $fd -blocking 0 -translation lf -eofchar {} if {$tclencoding != {}} { fconfigure $fd -encoding $tclencoding } From d23d98d3ba21b2a7a1d30be049bfb5d9c0a4e943 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 19 Jul 2007 00:37:58 -0400 Subject: [PATCH 061/131] [PATCH] gitk: Bind keyboard actions to the command key on Mac OS git-gui already uses the command key for accelerators, but gitk has never done so. I'm actually finding it very hard to move back and forth between the two applications as git-gui is following the Mac OS X conventions and gitk is not. This trick is the same one that git-gui uses to determine which key to bind actions to. Signed-off-by: Shawn O. Pearce Signed-off-by: Paul Mackerras --- gitk | 75 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/gitk b/gitk index d6f62b2a0f..66e4a643d6 100755 --- a/gitk +++ b/gitk @@ -809,6 +809,12 @@ proc makewindow {} { wm geometry . "$geometry(main)" } + if {[tk windowingsystem] eq {aqua}} { + set M1B M1 + } else { + set M1B Control + } + bind .pwbottom {resizecdetpanes %W %w} pack .ctop -fill both -expand 1 bindall <1> {selcanvline %W %x %y} @@ -827,12 +833,12 @@ proc makewindow {} { bindkey "goback" bind . "selnextpage -1" bind . "selnextpage 1" - bind . "allcanvs yview moveto 0.0" - bind . "allcanvs yview moveto 1.0" - bind . "allcanvs yview scroll -1 units" - bind . "allcanvs yview scroll 1 units" - bind . "allcanvs yview scroll -1 pages" - bind . "allcanvs yview scroll 1 pages" + bind . <$M1B-Home> "allcanvs yview moveto 0.0" + bind . <$M1B-End> "allcanvs yview moveto 1.0" + bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units" + bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units" + bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages" + bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages" bindkey "$ctext yview scroll -1 pages" bindkey "$ctext yview scroll -1 pages" bindkey "$ctext yview scroll 1 pages" @@ -852,15 +858,15 @@ proc makewindow {} { bindkey ? findprev bindkey f nextfile bindkey updatecommits - bind . doquit - bind . dofind - bind . {findnext 0} - bind . dosearchback - bind . dosearch - bind . {incrfont 1} - bind . {incrfont 1} - bind . {incrfont -1} - bind . {incrfont -1} + bind . <$M1B-q> doquit + bind . <$M1B-f> dofind + bind . <$M1B-g> {findnext 0} + bind . <$M1B-r> dosearchback + bind . <$M1B-s> dosearch + bind . <$M1B-equal> {incrfont 1} + bind . <$M1B-KP_Add> {incrfont 1} + bind . <$M1B-minus> {incrfont -1} + bind . <$M1B-KP_Subtract> {incrfont -1} wm protocol . WM_DELETE_WINDOW doquit bind . "click %W" bind $fstring dofind @@ -1101,12 +1107,17 @@ proc keys {} { raise $w return } + if {[tk windowingsystem] eq {aqua}} { + set M1T Cmd + } else { + set M1T Ctrl + } toplevel $w wm title $w "Gitk key bindings" - message $w.m -text { + message $w.m -text " Gitk key bindings: - Quit +<$M1T-Q> Quit Move to first commit Move to last commit , p, i Move up one commit @@ -1115,12 +1126,12 @@ Gitk key bindings: , x, l Go forward in history list Move up one page in commit list Move down one page in commit list - Scroll to top of commit list - Scroll to bottom of commit list - Scroll commit list up one line - Scroll commit list down one line - Scroll commit list up one page - Scroll commit list down one page +<$M1T-Home> Scroll to top of commit list +<$M1T-End> Scroll to bottom of commit list +<$M1T-Up> Scroll commit list up one line +<$M1T-Down> Scroll commit list down one line +<$M1T-PageUp> Scroll commit list up one page +<$M1T-PageDown> Scroll commit list down one page Move to previous highlighted line Move to next highlighted line , b Scroll diff view up one page @@ -1128,20 +1139,20 @@ Gitk key bindings: Scroll diff view down one page u Scroll diff view up 18 lines d Scroll diff view down 18 lines - Find - Move to next find hit +<$M1T-F> Find +<$M1T-G> Move to next find hit Move to next find hit / Move to next find hit, or redo find ? Move to previous find hit f Scroll diff view to next file - Search for next hit in diff view - Search for previous hit in diff view - Increase font size - Increase font size - Decrease font size - Decrease font size +<$M1T-S> Search for next hit in diff view +<$M1T-R> Search for previous hit in diff view +<$M1T-KP+> Increase font size +<$M1T-plus> Increase font size +<$M1T-KP-> Decrease font size +<$M1T-minus> Decrease font size Update -} \ +" \ -justify left -bg white -border 2 -relief groove pack $w.m -side top -fill both -padx 2 -pady 2 $w.m configure -font $uifont From 16a7fcfe5e568b50ddebe2369600e71da67d1405 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 22 Jul 2007 21:20:26 +0100 Subject: [PATCH 062/131] fsck --lost-found: write blob's contents, not their SHA-1 When looking for a lost blob, it is much nicer to be able to grep through .git/lost-found/other/* than to write an inefficient loop over the file names. So write the contents of the dangling blobs, not their object names. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/git-fsck.txt | 6 ++++-- builtin-fsck.c | 12 +++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Documentation/git-fsck.txt b/Documentation/git-fsck.txt index 1a432f2319..45c0bee50a 100644 --- a/Documentation/git-fsck.txt +++ b/Documentation/git-fsck.txt @@ -65,8 +65,10 @@ index file and all SHA1 references in .git/refs/* as heads. Be chatty. --lost-found:: - Write dangling refs into .git/lost-found/commit/ or - .git/lost-found/other/, depending on type. + Write dangling objects into .git/lost-found/commit/ or + .git/lost-found/other/, depending on type. If the object is + a blob, the contents are written into the file, rather than + its object name. It tests SHA1 and general object sanity, and it does full tracking of the resulting reachability and everything else. It prints out any diff --git a/builtin-fsck.c b/builtin-fsck.c index 350ec5e144..8d12287f03 100644 --- a/builtin-fsck.c +++ b/builtin-fsck.c @@ -152,7 +152,17 @@ static void check_unreachable_object(struct object *obj) } if (!(f = fopen(filename, "w"))) die("Could not open %s", filename); - fprintf(f, "%s\n", sha1_to_hex(obj->sha1)); + if (obj->type == OBJ_BLOB) { + enum object_type type; + unsigned long size; + char *buf = read_sha1_file(obj->sha1, + &type, &size); + if (buf) { + fwrite(buf, size, 1, f); + free(buf); + } + } else + fprintf(f, "%s\n", sha1_to_hex(obj->sha1)); fclose(f); } return; From a781785d8f1eb7adf05a24b121104716a086a67a Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sun, 22 Jul 2007 23:41:20 +0200 Subject: [PATCH 063/131] gitweb: Fix support for legacy gitweb config for snapshots Earlier commit which cleaned up snapshot support and introduced support for multiple snapshot formats changed the format of $feature{'snapshot'}{'default'} (gitweb configuration) and gitweb.snapshot configuration variable (repository configuration). It supported old gitweb.snapshot values of 'gzip', 'bzip2' and 'zip' and tried to support, but failed to do that, old values of $feature{'snapshot'}{'default'}; at least those corresponding to old gitweb.snapshot values of 'gzip', 'bzip2' and 'zip', i.e. ['x-gzip', 'gz', 'gzip'] ['x-bzip2', 'bz2', 'bzip2'] ['x-zip', 'zip', ''] This commit moves legacy configuration support out of feature_snapshot subroutine to separate filter_snapshot_fmts subroutine. The filter_snapshot_fmts is used on result on result of gitweb_check_feature('snapshot'). This way feature_snapshot deals _only_ with repository config. As a byproduct you can now use 'gzip' and 'bzip2' as aliases to 'tgz' and 'tbz2' also in $feature{'snapshot'}{'default'}, not only in gitweb.snapshot. While at it do some whitespace cleanup: use tabs for indent, but spaces for align. Noticed-by: Matt McCutchen Signed-off-by: Jakub Narebski Tested-by: Matt McCutchen Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index c4f88245aa..fdfce311fd 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -307,10 +307,6 @@ sub feature_snapshot { if ($val) { @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val); - @fmts = grep { defined } map { - exists $known_snapshot_format_aliases{$_} ? - $known_snapshot_format_aliases{$_} : $_ } @fmts; - @fmts = grep(exists $known_snapshot_formats{$_}, @fmts); } return @fmts; @@ -356,6 +352,18 @@ sub check_export_ok { (!$export_ok || -e "$dir/$export_ok")); } +# process alternate names for backward compatibility +# filter out unsupported (unknown) snapshot formats +sub filter_snapshot_fmts { + my @fmts = @_; + + @fmts = map { + exists $known_snapshot_format_aliases{$_} ? + $known_snapshot_format_aliases{$_} : $_} @fmts; + @fmts = grep(exists $known_snapshot_formats{$_}, @fmts); + +} + our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++"; do $GITWEB_CONFIG if -e $GITWEB_CONFIG; @@ -1299,9 +1307,11 @@ sub format_diff_line { sub format_snapshot_links { my ($hash) = @_; my @snapshot_fmts = gitweb_check_feature('snapshot'); + @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts); my $num_fmts = @snapshot_fmts; if ($num_fmts > 1) { # A parenthesized list of links bearing format names. + # e.g. "snapshot (_tar.gz_ _zip_)" return "snapshot (" . join(' ', map $cgi->a({ -href => href( @@ -1313,8 +1323,10 @@ sub format_snapshot_links { , @snapshot_fmts) . ")"; } elsif ($num_fmts == 1) { # A single "snapshot" link whose tooltip bears the format name. + # i.e. "_snapshot_" my ($fmt) = @snapshot_fmts; - return $cgi->a({ + return + $cgi->a({ -href => href( action=>"snapshot", hash=>$hash, @@ -4302,11 +4314,12 @@ sub git_tree { sub git_snapshot { my @supported_fmts = gitweb_check_feature('snapshot'); + @supported_fmts = filter_snapshot_fmts(@supported_fmts); my $format = $cgi->param('sf'); unless ($format =~ m/[a-z0-9]+/ - && exists($known_snapshot_formats{$format}) - && grep($_ eq $format, @supported_fmts)) { + && exists($known_snapshot_formats{$format}) + && grep($_ eq $format, @supported_fmts)) { die_error(undef, "Unsupported snapshot format"); } From e7d7b1a34ea3d3e4ee44471acbc97eda9bfffb55 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 23 Jul 2007 00:12:30 -0400 Subject: [PATCH 064/131] git-gui: Clarify meaning of add tracked menu option Junio recently pointed out on the mailing list that our "Add Existing" feature is a lot like `git add -u`, which is generally described as "(Re)Add Tracked Files". This came up during discussion of how to translate "Add Existing" into Japanese, as the individual working on the translation was not quite sure what the option meant and therefore had some trouble selecting the best translation. I'm changing the menu option to "Add Tracked Files To Commit" and the button to "Add Tracked". This should help new users to better understand the actions behind those GUI widgets. 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 07a478c793..67aed3ada5 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1822,7 +1822,7 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} { lappend disable_on_lock \ [list .mbar.commit entryconf [.mbar.commit index last] -state] - .mbar.commit add command -label {Add Existing To Commit} \ + .mbar.commit add command -label {Add Tracked Files To Commit} \ -command do_add_all \ -accelerator $M1T-I lappend disable_on_lock \ @@ -2144,7 +2144,7 @@ pack .vpane.lower.commarea.buttons.rescan -side top -fill x lappend disable_on_lock \ {.vpane.lower.commarea.buttons.rescan conf -state} -button .vpane.lower.commarea.buttons.incall -text {Add Existing} \ +button .vpane.lower.commarea.buttons.incall -text {Add Tracked} \ -command do_add_all pack .vpane.lower.commarea.buttons.incall -side top -fill x lappend disable_on_lock \ From 9c5a3c7797449e1b3e6455327394677c21f0f908 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 23 Jul 2007 00:20:04 -0400 Subject: [PATCH 065/131] git-gui: Paper bag fix quitting crash after commit My earlier introduction of the GITGUI_BCK file (which saves the user's commit message buffer while they are typing it) broke the Quit function. If the user makes a commit we delete the GITGUI_BCK file; if they then immediately quit the application we fail to rename the GITGUI_BCK file to GITGUI_MSG. This is because the file does not exist, but our flag still says it does. The root cause is we did not unset the flag during commit. Signed-off-by: Shawn O. Pearce --- lib/commit.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commit.tcl b/lib/commit.tcl index 6b86f9808e..1f5c2c3d44 100644 --- a/lib/commit.tcl +++ b/lib/commit.tcl @@ -381,7 +381,7 @@ A rescan will be automatically started now. $ui_comm edit modified false if {$::GITGUI_BCK_exists} { catch {file delete [gitdir GITGUI_BCK]} - set $::GITGUI_BCK_exists 0 + set ::GITGUI_BCK_exists 0 } if {[is_enabled singlecommit]} do_quit From 83751fc109e951a5cbde9ee39970f6b1d2da07c7 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 23 Jul 2007 00:36:39 -0400 Subject: [PATCH 066/131] git-gui: Refactor diff popup into a procedure to ease i18n work The folks working on the i18n version of git-gui have had some trouble trying to convert these English strings into [mc] calls due to the double evaluation. Moving this block into a standard procedure eliminates the double evaluation, making their work easier. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 67aed3ada5..2912872d2e 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2418,17 +2418,19 @@ lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] $ctxm add separator $ctxm add command -label {Options...} \ -command do_options -bind_button3 $ui_diff " - set cursorX %x - set cursorY %y - if {\$ui_index eq \$current_diff_side} { - $ctxm entryconf $ui_diff_applyhunk -label {Unstage Hunk From Commit} +proc popup_diff_menu {ctxm x y X Y} { + set ::cursorX $x + set ::cursorY $y + if {$::ui_index eq $::current_diff_side} { + $ctxm entryconf $::ui_diff_applyhunk \ + -label {Unstage Hunk From Commit} } else { - $ctxm entryconf $ui_diff_applyhunk -label {Stage Hunk For Commit} + $ctxm entryconf $::ui_diff_applyhunk \ + -label {Stage Hunk For Commit} } - tk_popup $ctxm %X %Y -" -unset ui_diff_applyhunk + tk_popup $ctxm $X $Y +} +bind_button3 $ui_diff [list popup_diff_menu $ctxm %x %y %X %Y] # -- Status Bar # From a8139888f8d250c6d173ddbe892e98fc49763702 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 23 Jul 2007 01:11:08 -0400 Subject: [PATCH 067/131] git-gui: Refactor current branch menu items to make i18n easier The i18n team has also identified a rather ugly block of code in git-gui that is used to make a pair of Repository menu items show the current branch name. This code is difficult to convert to use [mc ...] to lookup the translation, so I'm refactoring it into a procedure. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 2912872d2e..a38293a347 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1682,7 +1682,7 @@ menu .mbar.repository .mbar.repository add command \ -label {Browse Current Branch's Files} \ -command {browser::new $current_branch} -trace add variable current_branch write ".mbar.repository entryconf [.mbar.repository index last] -label \"Browse \$current_branch's Files\" ;#" +set ui_browse_current [.mbar.repository index last] .mbar.repository add command \ -label {Browse Branch Files...} \ -command browser_open::dialog @@ -1691,12 +1691,21 @@ trace add variable current_branch write ".mbar.repository entryconf [.mbar.repos .mbar.repository add command \ -label {Visualize Current Branch's History} \ -command {do_gitk $current_branch} -trace add variable current_branch write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch's History\" ;#" +set ui_visualize_current [.mbar.repository index last] .mbar.repository add command \ -label {Visualize All Branch History} \ -command {do_gitk --all} .mbar.repository add separator +proc current_branch_write {args} { + global current_branch + .mbar.repository entryconf $::ui_browse_current \ + -label "Browse $current_branch's Files" + .mbar.repository entryconf $::ui_visualize_current \ + -label "Visualize $current_branch's History" +} +trace add variable current_branch write current_branch_write + if {[is_enabled multicommit]} { .mbar.repository add command -label {Database Statistics} \ -command do_stats From 7d5266a704ea55b11799bf0431d1648282f53d54 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 22 Jul 2007 04:49:06 -0400 Subject: [PATCH 068/131] git-gui: Avoid unnecessary symbolic-ref call during checkout If we are checking out the branch we are already on then there is no need to call symbolic-ref to update the HEAD pointer to the "new" branch name, it is already correct. Currently this situation does not happen very often, but it can be seen in some workflows where the user always recreates their local branch from a remote tracking branch and more-or-less ignores what branch he/she is on right now. As they say, ignorance is bliss. This case will however become a tad more common when we overload checkout_op to actually also perform all of our merges. In that case we will likely see that the branch we want to "checkout" is the current branch, as we are actually just merging into it. Signed-off-by: Shawn O. Pearce --- lib/checkout_op.tcl | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/checkout_op.tcl b/lib/checkout_op.tcl index 8c42ca8005..40cc73a527 100644 --- a/lib/checkout_op.tcl +++ b/lib/checkout_op.tcl @@ -385,22 +385,24 @@ method _after_readtree {} { 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 + if {$is_detached || $current_branch ne $new_branch} { + 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 } - 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 + if {$new_hash ne $HEAD} { + append log " to $new_expr" + if {[catch { + _detach_HEAD $log $new_hash + } err]} { + _fatal $this $err + } } set current_branch HEAD set is_detached 1 From 0eafba1405bf4db29bca0b535477beb3046441bf Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 23 Jul 2007 21:35:03 +1000 Subject: [PATCH 069/131] gitk: Wait for the window to become visible after creating it When the git log process returned an error immediately, we were sometimes getting no main window and no error window displayed, with the gitk process just hanging waiting for something. It appears that the tkwait in show_error, which waits for the error window to be destroyed, wasn't sufficient to allow the main window or the error window to be mapped. This adds a wait in the main startup code after the main window has been created to wait until it is visible. This seems to fix the problem. Signed-off-by: Paul Mackerras --- gitk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gitk b/gitk index 66e4a643d6..5cfb1cc391 100755 --- a/gitk +++ b/gitk @@ -7646,6 +7646,8 @@ set localfrow -1 set lserial 0 setcoords makewindow +# wait for the window to become visible +tkwait visibility . wm title . "[file tail $argv0]: [file tail [pwd]]" readrefs From 7296096c9d7e9fa12901c02fd1d12f4f996043e2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 24 Jul 2007 01:03:26 +0100 Subject: [PATCH 070/131] mailinfo: fix 'fatal: cannot convert from utf-8 to utf-8' For some reason, I got this error message. Maybe it does not make sense, but then we should not really try to convert the text when it is not necessary. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-mailinfo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c index a37a4fff39..b4f6e913b3 100644 --- a/builtin-mailinfo.c +++ b/builtin-mailinfo.c @@ -529,6 +529,8 @@ static void convert_to_utf8(char *line, const char *charset) return; } + if (!strcmp(metainfo_charset, charset)) + return; out = reencode_string(line, metainfo_charset, charset); if (!out) die("cannot convert from %s to %s\n", From dfa49f33489dbb142bcc796a4e932863f9dcce1f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 23 Jul 2007 23:45:49 +0100 Subject: [PATCH 071/131] Shut "git rebase -i" up when no --verbose was given Up to now, git rebase -i was quite chatty, showing through all the nice core programs it called. Now it only shows a progress meter by default. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 50 ++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 579a45ebbb..ac1f5a2d3f 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -33,6 +33,20 @@ warn () { echo "$*" >&2 } +output () { + case "$VERBOSE" in + '') + "$@" > "$DOTEST"/output 2>&1 + status=$? + test $status != 0 && + cat "$DOTEST"/output + return $status + ;; + *) + "$@" + esac +} + require_clean_work_tree () { # test if working tree is dirty git rev-parse --verify HEAD > /dev/null && @@ -56,6 +70,10 @@ mark_action_done () { sed -e 1q < "$TODO" >> "$DONE" sed -e 1d < "$TODO" >> "$TODO".new mv -f "$TODO".new "$TODO" + count=$(($(wc -l < "$DONE"))) + total=$(($count+$(wc -l < "$TODO"))) + printf "Rebasing (%d/%d)\r" $count $total + test -z "$VERBOSE" || echo } make_patch () { @@ -79,18 +97,18 @@ die_abort () { pick_one () { case "$1" in -n) sha1=$2 ;; *) sha1=$1 ;; esac - git rev-parse --verify $sha1 || die "Invalid commit name: $sha1" + output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1" test -d "$REWRITTEN" && pick_one_preserving_merges "$@" && return parent_sha1=$(git rev-parse --verify $sha1^ 2>/dev/null) current_sha1=$(git rev-parse --verify HEAD) if [ $current_sha1 = $parent_sha1 ]; then - git reset --hard $sha1 - test "a$1" = a-n && git reset --soft $current_sha1 + output git reset --hard $sha1 + test "a$1" = a-n && output git reset --soft $current_sha1 sha1=$(git rev-parse --short $sha1) - warn Fast forward to $sha1 + output warn Fast forward to $sha1 else - git cherry-pick $STRATEGY "$@" + output git cherry-pick $STRATEGY "$@" fi } @@ -127,7 +145,7 @@ pick_one_preserving_merges () { done case $fast_forward in t) - echo "Fast forward to $sha1" + output warn "Fast forward to $sha1" test $preserve=f && echo $sha1 > "$REWRITTEN"/$sha1 ;; f) @@ -135,7 +153,7 @@ pick_one_preserving_merges () { first_parent=$(expr "$new_parents" : " \([^ ]*\)") # detach HEAD to current parent - git checkout $first_parent 2> /dev/null || + output git checkout $first_parent 2> /dev/null || die "Cannot move HEAD to $first_parent" echo $sha1 > "$DOTEST"/current-commit @@ -147,14 +165,14 @@ pick_one_preserving_merges () { msg="$(git cat-file commit $sha1 | \ sed -e '1,/^$/d' -e "s/[\"\\]/\\\\&/g")" # NEEDSWORK: give rerere a chance - if ! git merge $STRATEGY -m "$msg" $new_parents + if ! output git merge $STRATEGY -m "$msg" $new_parents then echo "$msg" > "$GIT_DIR"/MERGE_MSG die Error redoing merge $sha1 fi ;; *) - git cherry-pick $STRATEGY "$@" || + output git cherry-pick $STRATEGY "$@" || die_with_patch $sha1 "Could not pick $sha1" esac esac @@ -241,7 +259,7 @@ do_next () { failed=f pick_one -n $sha1 || failed=t - git reset --soft HEAD^ + output git reset --soft HEAD^ author_script=$(get_author_ident_from_commit $sha1) echo "$author_script" > "$DOTEST"/author-script case $failed in @@ -249,7 +267,7 @@ do_next () { # This is like --amend, but with a different message eval "$author_script" export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE - git commit -F "$MSG" $EDIT_COMMIT + output git commit -F "$MSG" $EDIT_COMMIT ;; t) cp "$MSG" "$GIT_DIR"/MERGE_MSG @@ -324,7 +342,7 @@ do HEADNAME=$(cat "$DOTEST"/head-name) HEAD=$(cat "$DOTEST"/head) git symbolic-ref HEAD $HEADNAME && - git reset --hard $HEAD && + output git reset --hard $HEAD && rm -rf "$DOTEST" exit ;; @@ -333,7 +351,7 @@ do test -d "$DOTEST" || die "No interactive rebase running" - git reset --hard && do_rest + output git reset --hard && do_rest ;; -s|--strategy) shift @@ -387,9 +405,9 @@ do if [ ! -z "$2"] then - git show-ref --verify --quiet "refs/heads/$2" || + output git show-ref --verify --quiet "refs/heads/$2" || die "Invalid branchname: $2" - git checkout "$2" || + output git checkout "$2" || die "Could not checkout $2" fi @@ -456,7 +474,7 @@ EOF test -z "$(grep -ve '^$' -e '^#' < $TODO)" && die_abort "Nothing to do" - git checkout $ONTO && do_rest + output git checkout $ONTO && do_rest esac shift done From 3b38ec16d51a84bb5d4ef349f441de5f7ecd54f2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 24 Jul 2007 03:18:28 +0100 Subject: [PATCH 072/131] rebase -i: exchange all "if [ .. ]" by "if test .." This patch is literally :%s/if \[ *\(.*[^ ]\) *\]/if test \1/ in vi, after making sure that the other instances of "[..]" are not actually invocations of "test". Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index ac1f5a2d3f..93289c050a 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -102,7 +102,7 @@ pick_one () { pick_one_preserving_merges "$@" && return parent_sha1=$(git rev-parse --verify $sha1^ 2>/dev/null) current_sha1=$(git rev-parse --verify HEAD) - if [ $current_sha1 = $parent_sha1 ]; then + if test $current_sha1 = $parent_sha1; then output git reset --hard $sha1 test "a$1" = a-n && output git reset --soft $current_sha1 sha1=$(git rev-parse --short $sha1) @@ -116,7 +116,7 @@ pick_one_preserving_merges () { case "$1" in -n) sha1=$2 ;; *) sha1=$1 ;; esac sha1=$(git rev-parse $sha1) - if [ -f "$DOTEST"/current-commit ] + if test -f "$DOTEST"/current-commit then current_commit=$(cat "$DOTEST"/current-commit) && git rev-parse HEAD > "$REWRITTEN"/$current_commit && @@ -130,7 +130,7 @@ pick_one_preserving_merges () { new_parents= for p in $(git rev-list --parents -1 $sha1 | cut -d\ -f2-) do - if [ -f "$REWRITTEN"/$p ] + if test -f "$REWRITTEN"/$p then preserve=f new_p=$(cat "$REWRITTEN"/$p) @@ -188,7 +188,7 @@ nth_string () { } make_squash_message () { - if [ -f "$SQUASH_MSG" ]; then + if test -f "$SQUASH_MSG"; then COUNT=$(($(sed -n "s/^# This is [^0-9]*\([0-9]\+\).*/\1/p" \ < "$SQUASH_MSG" | tail -n 1)+1)) echo "# This is a combination of $COUNT commits." @@ -286,7 +286,7 @@ do_next () { HEADNAME=$(cat "$DOTEST"/head-name) && OLDHEAD=$(cat "$DOTEST"/head) && SHORTONTO=$(git rev-parse --short $(cat "$DOTEST"/onto)) && - if [ -d "$REWRITTEN" ] + if test -d "$REWRITTEN" then test -f "$DOTEST"/current-commit && current_commit=$(cat "$DOTEST"/current-commit) && @@ -403,7 +403,7 @@ do require_clean_work_tree - if [ ! -z "$2"] + if test ! -z "$2" then output git show-ref --verify --quiet "refs/heads/$2" || die "Invalid branchname: $2" @@ -426,7 +426,7 @@ do echo $ONTO > "$DOTEST"/onto test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy test t = "$VERBOSE" && : > "$DOTEST"/verbose - if [ t = "$PRESERVE_MERGES" ] + if test t = "$PRESERVE_MERGES" then # $REWRITTEN contains files for each commit that is # reachable by at least one merge base of $HEAD and From dfd05e38f07f76505158399cc433b0b1870a769a Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 23 Jul 2007 18:34:13 +0100 Subject: [PATCH 073/131] filter-branch: Big syntax change; support rewriting multiple refs We used to take the first non-option argument as the name for the new branch. This syntax is not extensible to support rewriting more than just HEAD. Instead, we now have the following syntax: git filter-branch [...] [] All positive refs given in are rewritten. Yes, in-place. If a ref was changed, the original head is stored in refs/original/$ref now, for your inspecting pleasure, in addition to the reflogs (since it is easier to inspect "git show-ref | grep original" than to inspect all the reflogs). This commit also adds the --force option to remove .git-rewrite/ and all refs from refs/original/ before filtering. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/git-filter-branch.txt | 51 +++++----- git-filter-branch.sh | 150 ++++++++++++++++++++++++---- t/t7003-filter-branch.sh | 41 +++++--- 3 files changed, 182 insertions(+), 60 deletions(-) diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt index eaea82d0a6..915258f410 100644 --- a/Documentation/git-filter-branch.txt +++ b/Documentation/git-filter-branch.txt @@ -12,7 +12,7 @@ SYNOPSIS [--index-filter ] [--parent-filter ] [--msg-filter ] [--commit-filter ] [--tag-name-filter ] [--subdirectory-filter ] - [-d ] [...] + [-d ] [-f | --force] [...] DESCRIPTION ----------- @@ -26,10 +26,9 @@ information) will be preserved. The command takes the new branch name as a mandatory argument and the filters as optional arguments. If you specify no filters, the commits will be recommitted without any changes, which would normally -have no effect and result in the new branch pointing to the same -branch as your current branch. Nevertheless, this may be useful in -the future for compensating for some git bugs or such, therefore -such a usage is permitted. +have no effect. Nevertheless, this may be useful in the future for +compensating for some git bugs or such, therefore such a usage is +permitted. *WARNING*! The rewritten history will have different object names for all the objects and will not converge with the original branch. You will not @@ -38,8 +37,9 @@ original branch. Please do not use this command if you do not know the full implications, and avoid using it anyway, if a simple single commit would suffice to fix your problem. -Always verify that the rewritten version is correct before disposing -the original branch. +Always verify that the rewritten version is correct: The original refs, +if different from the rewritten ones, will be stored in the namespace +'refs/original/'. Note that since this operation is extensively I/O expensive, it might be a good idea to redirect the temporary directory off-disk, e.g. on @@ -142,6 +142,11 @@ definition impossible to preserve signatures at any rate.) does this in the '.git-rewrite/' directory but you can override that choice by this parameter. +-f\|--force:: + `git filter-branch` refuses to start with an existing temporary + directory or when there are already refs starting with + 'refs/original/', unless forced. + :: When options are given after the new branch name, they will be passed to gitlink:git-rev-list[1]. Only commits in the resulting @@ -156,14 +161,14 @@ Suppose you want to remove a file (containing confidential information or copyright violation) from all commits: ------------------------------------------------------- -git filter-branch --tree-filter 'rm filename' newbranch +git filter-branch --tree-filter 'rm filename' HEAD ------------------------------------------------------- A significantly faster version: -------------------------------------------------------------------------------- -git filter-branch --index-filter 'git update-index --remove filename' newbranch -------------------------------------------------------------------------------- +-------------------------------------------------------------------------- +git filter-branch --index-filter 'git update-index --remove filename' HEAD +-------------------------------------------------------------------------- Now, you will get the rewritten history saved in the branch 'newbranch' (your current branch is left untouched). @@ -172,25 +177,25 @@ To set a commit (which typically is at the tip of another history) to be the parent of the current initial commit, in order to paste the other history behind the current history: ------------------------------------------------------------------------- -git filter-branch --parent-filter 'sed "s/^\$/-p /"' newbranch ------------------------------------------------------------------------- +------------------------------------------------------------------- +git filter-branch --parent-filter 'sed "s/^\$/-p /"' HEAD +------------------------------------------------------------------- (if the parent string is empty - therefore we are dealing with the initial commit - add graftcommit as a parent). Note that this assumes history with a single root (that is, no merge without common ancestors happened). If this is not the case, use: -------------------------------------------------------------------------------- +-------------------------------------------------------------------------- git filter-branch --parent-filter \ - 'cat; test $GIT_COMMIT = && echo "-p "' newbranch -------------------------------------------------------------------------------- + 'cat; test $GIT_COMMIT = && echo "-p "' HEAD +-------------------------------------------------------------------------- or even simpler: ----------------------------------------------- echo "$commit-id $graft-id" >> .git/info/grafts -git filter-branch newbranch $graft-id.. +git filter-branch $graft-id..HEAD ----------------------------------------------- To remove commits authored by "Darl McBribe" from the history: @@ -208,7 +213,7 @@ git filter-branch --commit-filter ' done; else git commit-tree "$@"; - fi' newbranch + fi' HEAD ------------------------------------------------------------------------------ The shift magic first throws away the tree id and then the -p @@ -238,14 +243,14 @@ A--B-----C To rewrite only commits D,E,F,G,H, but leave A, B and C alone, use: -------------------------------- -git filter-branch ... new-H C..H +git filter-branch ... C..H -------------------------------- To rewrite commits E,F,G,H, use one of these: ---------------------------------------- -git filter-branch ... new-H C..H --not D -git filter-branch ... new-H D..H --not C +git filter-branch ... C..H --not D +git filter-branch ... D..H --not C ---------------------------------------- To move the whole tree into a subdirectory, or remove it from there: @@ -255,7 +260,7 @@ git filter-branch --index-filter \ 'git ls-files -s | sed "s-\t-&newsubdir/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new \ git update-index --index-info && - mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' directorymoved + mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD --------------------------------------------------------------- diff --git a/git-filter-branch.sh b/git-filter-branch.sh index 0d000ed306..0ff3475525 100755 --- a/git-filter-branch.sh +++ b/git-filter-branch.sh @@ -78,6 +78,8 @@ filter_msg=cat filter_commit='git commit-tree "$@"' filter_tag_name= filter_subdir= +orig_namespace=refs/original/ +force= while case "$#" in 0) usage;; esac do case "$1" in @@ -85,6 +87,11 @@ do shift break ;; + --force|-f) + shift + force=t + continue + ;; -*) ;; *) @@ -126,24 +133,43 @@ do --subdirectory-filter) filter_subdir="$OPTARG" ;; + --original) + orig_namespace="$OPTARG" + ;; *) usage ;; esac done -dstbranch="$1" -shift -test -n "$dstbranch" || die "missing branch name" -git show-ref "refs/heads/$dstbranch" 2> /dev/null && - die "branch $dstbranch already exists" - -test ! -e "$tempdir" || die "$tempdir already exists, please remove it" +case "$force" in +t) + rm -rf "$tempdir" +;; +'') + test -d "$tempdir" && + die "$tempdir already exists, please remove it" +esac mkdir -p "$tempdir/t" && +tempdir="$(cd "$tempdir"; pwd)" && cd "$tempdir/t" && workdir="$(pwd)" || die "" +# Make sure refs/original is empty +git for-each-ref > "$tempdir"/backup-refs +while read sha1 type name +do + case "$force,$name" in + ,$orig_namespace*) + die "Namespace $orig_namespace not empty" + ;; + t,$orig_namespace*) + git update-ref -d "$name" $sha1 + ;; + esac +done < "$tempdir"/backup-refs + case "$GIT_DIR" in /*) ;; @@ -153,6 +179,29 @@ case "$GIT_DIR" in esac export GIT_DIR GIT_WORK_TREE=. +# These refs should be updated if their heads were rewritten + +git rev-parse --revs-only --symbolic "$@" | +while read ref +do + # normalize ref + case "$ref" in + HEAD) + ref="$(git symbolic-ref "$ref")" + ;; + refs/*) + ;; + *) + ref="$(git for-each-ref --format='%(refname)' | + grep /"$ref")" + esac + + git check-ref-format "$ref" && echo "$ref" +done > "$tempdir"/heads + +test -s "$tempdir"/heads || + die "Which ref do you want to rewrite?" + export GIT_INDEX_FILE="$(pwd)/../index" git read-tree || die "Could not seed the index" @@ -174,6 +223,8 @@ commits=$(wc -l <../revs | tr -d " ") test $commits -eq 0 && die "Found nothing to rewrite" +# Rewrite the commits + i=0 while read commit parents; do i=$(($i+1)) @@ -234,22 +285,75 @@ while read commit parents; do $(git write-tree) $parentstr < ../message > ../map/$commit done <../revs -src_head=$(tail -n 1 ../revs | sed -e 's/ .*//') -target_head=$(head -n 1 ../map/$src_head) -case "$target_head" in -'') - echo Nothing rewritten +# In case of a subdirectory filter, it is possible that a specified head +# is not in the set of rewritten commits, because it was pruned by the +# revision walker. Fix it by mapping these heads to the next rewritten +# ancestor(s), i.e. the boundaries in the set of rewritten commits. + +# NEEDSWORK: we should sort the unmapped refs topologically first +while read ref +do + sha1=$(git rev-parse "$ref"^0) + test -f "$workdir"/../map/$sha1 && continue + # Assign the boundarie(s) in the set of rewritten commits + # as the replacement commit(s). + # (This would look a bit nicer if --not --stdin worked.) + for p in $((cd "$workdir"/../map; ls | sed "s/^/^/") | + git rev-list $ref --boundary --stdin | + sed -n "s/^-//p") + do + map $p >> "$workdir"/../map/$sha1 + done +done < "$tempdir"/heads + +# Finally update the refs + +_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' +_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" +count=0 +echo +while read ref +do + # avoid rewriting a ref twice + test -f "$orig_namespace$ref" && continue + + sha1=$(git rev-parse "$ref"^0) + rewritten=$(map $sha1) + + test $sha1 = "$rewritten" && + warn "WARNING: Ref '$ref' is unchanged" && + continue + + case "$rewritten" in + '') + echo "Ref '$ref' was deleted" + git update-ref -m "filter-branch: delete" -d "$ref" $sha1 || + die "Could not delete $ref" ;; -*) - git update-ref refs/heads/"$dstbranch" $target_head || - die "Could not update $dstbranch with $target_head" - if [ $(wc -l <../map/$src_head) -gt 1 ]; then - echo "WARNING: Your commit filter caused the head commit to expand to several rewritten commits. Only the first such commit was recorded as the current $dstbranch head but you will need to resolve the situation now (probably by manually merging the other commits). These are all the commits:" >&2 - sed 's/^/ /' ../map/$src_head >&2 - ret=1 - fi + $_x40) + echo "Ref '$ref' was rewritten" + git update-ref -m "filter-branch: rewrite" \ + "$ref" $rewritten $sha1 || + die "Could not rewrite $ref" ;; -esac + *) + # NEEDSWORK: possibly add -Werror, making this an error + warn "WARNING: '$ref' was rewritten into multiple commits:" + warn "$rewritten" + warn "WARNING: Ref '$ref' points to the first one now." + rewritten=$(echo "$rewritten" | head -n 1) + git update-ref -m "filter-branch: rewrite to first" \ + "$ref" $rewritten $sha1 || + die "Could not rewrite $ref" + ;; + esac + git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 + count=$(($count+1)) +done < "$tempdir"/heads + +# TODO: This should possibly go, with the semantics that all positive given +# refs are updated, and their original heads stored in refs/original/ +# Filter tags if [ "$filter_tag_name" ]; then git for-each-ref --format='%(objectname) %(objecttype) %(refname)' refs/tags | @@ -286,6 +390,8 @@ fi cd ../.. rm -rf "$tempdir" -printf "\nRewritten history saved to the $dstbranch branch\n" +echo +test $count -gt 0 && echo "These refs were rewritten:" +git show-ref | grep ^"$orig_namespace" exit $ret diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 4ddd656e84..bc6e2ddb19 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -30,24 +30,24 @@ test_expect_success 'setup' ' H=$(git rev-parse H) test_expect_success 'rewrite identically' ' - git-filter-branch H2 + git-filter-branch branch ' - test_expect_success 'result is really identical' ' - test $H = $(git rev-parse H2) + test $H = $(git rev-parse HEAD) ' test_expect_success 'rewrite, renaming a specific file' ' - git-filter-branch --tree-filter "mv d doh || :" H3 + git-filter-branch -f --tree-filter "mv d doh || :" HEAD ' test_expect_success 'test that the file was renamed' ' - test d = $(git show H3:doh) + test d = $(git show HEAD:doh) ' -git tag oldD H3~4 +git tag oldD HEAD~4 test_expect_success 'rewrite one branch, keeping a side branch' ' - git-filter-branch --tree-filter "mv b boh || :" modD D..oldD + git branch modD oldD && + git-filter-branch -f --tree-filter "mv b boh || :" D..modD ' test_expect_success 'common ancestor is still common (unchanged)' ' @@ -69,7 +69,8 @@ test_expect_success 'filter subdirectory only' ' git rm a && test_tick && git commit -m "again not subdir" && - git-filter-branch --subdirectory-filter subdir sub + git branch sub && + git-filter-branch -f --subdirectory-filter subdir refs/heads/sub ' test_expect_success 'subdirectory filter result looks okay' ' @@ -89,7 +90,8 @@ test_expect_success 'setup and filter history that requires --full-history' ' test_tick && git commit -m "again subdir on master" && git merge branch && - git-filter-branch --subdirectory-filter subdir sub-master + git branch sub-master && + git-filter-branch -f --subdirectory-filter subdir sub-master ' test_expect_success 'subdirectory filter result looks okay' ' @@ -100,7 +102,8 @@ test_expect_success 'subdirectory filter result looks okay' ' ' test_expect_success 'use index-filter to move into a subdirectory' ' - git-filter-branch --index-filter \ + git branch directorymoved && + git-filter-branch -f --index-filter \ "git ls-files -s | sed \"s-\\t-&newsubdir/-\" | GIT_INDEX_FILE=\$GIT_INDEX_FILE.new \ git update-index --index-info && @@ -108,9 +111,10 @@ test_expect_success 'use index-filter to move into a subdirectory' ' test -z "$(git diff HEAD directorymoved:newsubdir)"' test_expect_success 'stops when msg filter fails' ' - ! git-filter-branch --msg-filter false nonono && - rm -rf .git-rewrite && - ! git rev-parse nonono + old=$(git rev-parse HEAD) && + ! git-filter-branch -f --msg-filter false && + test $old = $(git rev-parse HEAD) && + rm -rf .git-rewrite ' test_expect_success 'author information is preserved' ' @@ -118,7 +122,8 @@ test_expect_success 'author information is preserved' ' git add i && test_tick && GIT_AUTHOR_NAME="B V Uips" git commit -m bvuips && - git-filter-branch --msg-filter "cat; \ + git branch preserved-author && + git-filter-branch -f --msg-filter "cat; \ test \$GIT_COMMIT != $(git rev-parse master) || \ echo Hallo" \ preserved-author && @@ -129,7 +134,8 @@ test_expect_success "remove a certain author's commits" ' echo i > i && test_tick && git commit -m i i && - git-filter-branch --commit-filter "\ + git branch removed-author && + git-filter-branch -f --commit-filter "\ if [ \"\$GIT_AUTHOR_NAME\" = \"B V Uips\" ];\ then\ shift;\ @@ -148,4 +154,9 @@ test_expect_success "remove a certain author's commits" ' test 0 = $(git rev-list --author="B V Uips" removed-author | wc -l) ' +test_expect_success 'barf on invalid name' ' + ! git filter-branch -f master xy-problem && + ! git filter-branch -f HEAD^ +' + test_done From 8e64006eee9c82eba513b98306c179c9e2385e4e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 24 Jul 2007 00:38:40 +0100 Subject: [PATCH 074/131] Teach revision machinery about --no-walk The flag "no_walk" is present in struct rev_info since a long time, but so far has been in use exclusively by "git show". With this flag, you can see all your refs, ordered by date of the last commit: $ git log --abbrev-commit --pretty=oneline --decorate --all --no-walk which is extremely helpful if you have to juggle with a lot topic branches, and do not remember in which one you introduced that uber debug option, or simply want to get an overview what is cooking. (Note that the "git log" invocation above does not output the same as $ git show --abbrev-commit --pretty=oneline --decorate --all --quiet since "git show" keeps the alphabetic order that "--all" returns the refs in, even if the option "--date-order" was passed.) For good measure, this also adds the "--do-walk" option which overrides "--no-walk". Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/git-rev-list.txt | 9 +++++++++ revision.c | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt index 0430139093..1c1978140f 100644 --- a/Documentation/git-rev-list.txt +++ b/Documentation/git-rev-list.txt @@ -37,6 +37,7 @@ SYNOPSIS [ \--merge ] [ \--reverse ] [ \--walk-reflogs ] + [ \--no-walk ] [ \--do-walk ] ... [ \-- ... ] DESCRIPTION @@ -398,6 +399,14 @@ These options are mostly targeted for packing of git repositories. Only useful with '--objects'; print the object IDs that are not in packs. +--no-walk:: + + Only show the given revs, but do not traverse their ancestors. + +--do-walk:: + + Overrides a previous --no-walk. + include::pretty-formats.txt[] diff --git a/revision.c b/revision.c index 00b75bc10b..16f35c7c18 100644 --- a/revision.c +++ b/revision.c @@ -1191,6 +1191,14 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch revs->reverse ^= 1; continue; } + if (!strcmp(arg, "--no-walk")) { + revs->no_walk = 1; + continue; + } + if (!strcmp(arg, "--do-walk")) { + revs->no_walk = 0; + continue; + } opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i); if (opts > 0) { From 1cffddd654d3c094b632e3c41b0ed4641cfa33df Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 24 Jul 2007 00:46:35 -0700 Subject: [PATCH 075/131] Mark user-manual as UTF-8 There have been several complaints against k.org's user-manual page. The document is generated in ISO-8859-1 by the xsltproc toolchain (I suspect this is because released docbook.xsl we use has xsl:output element that says the output is ISO-8859-1) but server delivers it with "charset=UTF-8", and all h*ll breaks loose. This attempts to force UTF-8 on the generating end. Signed-off-by: Junio C Hamano --- Documentation/Makefile | 2 +- Documentation/docbook.xsl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Documentation/docbook.xsl diff --git a/Documentation/Makefile b/Documentation/Makefile index b06275726d..3bc5357ec9 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -131,7 +131,7 @@ clean: user-manual.xml: user-manual.txt user-manual.conf $(ASCIIDOC) -b docbook -d book $< -XSLT = http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl +XSLT = docbook.xsl XSLTOPTS = --xinclude --stringparam html.stylesheet docbook-xsl.css user-manual.html: user-manual.xml diff --git a/Documentation/docbook.xsl b/Documentation/docbook.xsl new file mode 100644 index 0000000000..9a6912c641 --- /dev/null +++ b/Documentation/docbook.xsl @@ -0,0 +1,5 @@ + + + + From 1130845be8b72aa47b7264186c16d788d52fda63 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 24 Jul 2007 01:58:51 -0700 Subject: [PATCH 076/131] user-manual: fix typolets. Signed-off-by: Junio C Hamano --- Documentation/user-manual.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 14825c6411..0071cd070e 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -449,7 +449,7 @@ Exploring git history Git is best thought of as a tool for storing the history of a collection of files. It does this by storing compressed snapshots of -the contents of a file heirarchy, together with "commits" which show +the contents of a file hierarchy, together with "commits" which show the relationships between these snapshots. Git provides extremely flexible and fast tools for exploring the @@ -1070,7 +1070,7 @@ about to commit: ------------------------------------------------- $ git diff --cached # difference between HEAD and the index; what - # would be commited if you ran "commit" now. + # would be committed if you ran "commit" now. $ git diff # difference between the index file and your # working directory; changes that would not # be included if you ran "commit" now. @@ -1257,7 +1257,7 @@ index 802992c,2b60207..0000000 ++>>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt ------------------------------------------------- -Recall that the commit which will be commited after we resolve this +Recall that the commit which will be committed after we resolve this conflict will have two parents instead of the usual one: one parent will be HEAD, the tip of the current branch; the other will be the tip of the other branch, which is stored temporarily in MERGE_HEAD. @@ -1351,7 +1351,7 @@ away, you can always return to the pre-merge state with $ git reset --hard HEAD ------------------------------------------------- -Or, if you've already commited the merge that you want to throw away, +Or, if you've already committed the merge that you want to throw away, ------------------------------------------------- $ git reset --hard ORIG_HEAD From 93c22eeb30d2f43fc1e7a397e71f9bf8fb767962 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 24 Jul 2007 12:12:47 +0200 Subject: [PATCH 077/131] git.el: Support for incremental status updates. When we know which files have been modified, we can now run diff-index or ls-files with a file list to refresh only the specified files instead of the whole project. This also allows proper refreshing of files upon add/delete/resolve, instead of making assumptions about the new file state. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 220 ++++++++++++++++++++++--------------------- 1 file changed, 111 insertions(+), 109 deletions(-) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index 457f95fc05..b92bbe8728 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -314,8 +314,8 @@ and returns the process output as a string." (sort-lines nil (point-min) (point-max)) (save-buffer)) (when created - (git-run-command nil nil "update-index" "--info-only" "--add" "--" (file-relative-name ignore-name))) - (git-add-status-file (if created 'added 'modified) (file-relative-name ignore-name)))) + (git-run-command nil nil "update-index" "--add" "--" (file-relative-name ignore-name))) + (git-update-status-files (list (file-relative-name ignore-name)) 'unknown))) ; propertize definition for XEmacs, stolen from erc-compat (eval-when-compile @@ -523,23 +523,39 @@ and returns the process output as a string." " " (git-escape-file-name (git-fileinfo->name info)) (git-rename-as-string info)))) -(defun git-parse-status (status) - "Parse the output of git-diff-index in the current buffer." - (goto-char (point-min)) - (while (re-search-forward - ":\\([0-7]\\{6\\}\\) \\([0-7]\\{6\\}\\) [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\(\\([ADMU]\\)\0\\([^\0]+\\)\\|\\([CR]\\)[0-9]*\0\\([^\0]+\\)\0\\([^\0]+\\)\\)\0" - nil t 1) - (let ((old-perm (string-to-number (match-string 1) 8)) - (new-perm (string-to-number (match-string 2) 8)) - (state (or (match-string 4) (match-string 6))) - (name (or (match-string 5) (match-string 7))) - (new-name (match-string 8))) - (if new-name ; copy or rename - (if (eq ?C (string-to-char state)) - (ewoc-enter-last status (git-create-fileinfo 'added new-name old-perm new-perm 'copy name)) - (ewoc-enter-last status (git-create-fileinfo 'deleted name 0 0 'rename new-name)) - (ewoc-enter-last status (git-create-fileinfo 'added new-name old-perm new-perm 'rename name))) - (ewoc-enter-last status (git-create-fileinfo (git-state-code state) name old-perm new-perm)))))) +(defun git-insert-fileinfo (status info &optional refresh) + "Insert INFO in the status buffer, optionally refreshing an existing one." + (let ((node (and refresh + (git-find-status-file status (git-fileinfo->name info))))) + (setf (git-fileinfo->needs-refresh info) t) + (when node ;preserve the marked flag + (setf (git-fileinfo->marked info) (git-fileinfo->marked (ewoc-data node)))) + (if node (ewoc-set-data node info) (ewoc-enter-last status info)))) + +(defun git-run-diff-index (status files) + "Run git-diff-index on FILES and parse the results into STATUS. +Return the list of files that haven't been handled." + (let ((refresh files)) + (with-temp-buffer + (apply #'git-run-command t nil "diff-index" "-z" "-M" "HEAD" "--" files) + (goto-char (point-min)) + (while (re-search-forward + ":\\([0-7]\\{6\\}\\) \\([0-7]\\{6\\}\\) [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\(\\([ADMU]\\)\0\\([^\0]+\\)\\|\\([CR]\\)[0-9]*\0\\([^\0]+\\)\0\\([^\0]+\\)\\)\0" + nil t 1) + (let ((old-perm (string-to-number (match-string 1) 8)) + (new-perm (string-to-number (match-string 2) 8)) + (state (or (match-string 4) (match-string 6))) + (name (or (match-string 5) (match-string 7))) + (new-name (match-string 8))) + (if new-name ; copy or rename + (if (eq ?C (string-to-char state)) + (git-insert-fileinfo status (git-create-fileinfo 'added new-name old-perm new-perm 'copy name) refresh) + (git-insert-fileinfo status (git-create-fileinfo 'deleted name 0 0 'rename new-name) refresh) + (git-insert-fileinfo status (git-create-fileinfo 'added new-name old-perm new-perm 'rename name)) refresh) + (git-insert-fileinfo status (git-create-fileinfo (git-state-code state) name old-perm new-perm) refresh)) + (setq files (delete name files)) + (when new-name (setq files (delete new-name files))))))) + files) (defun git-find-status-file (status file) "Find a given file in the status ewoc and return its node." @@ -548,32 +564,59 @@ and returns the process output as a string." (setq node (ewoc-next status node))) node)) -(defun git-parse-ls-files (status default-state &optional skip-existing) - "Parse the output of git-ls-files in the current buffer." - (goto-char (point-min)) - (let (infolist) - (while (re-search-forward "\\([HMRCK?]\\) \\([^\0]*\\)\0" nil t 1) - (let ((state (match-string 1)) - (name (match-string 2))) - (unless (and skip-existing (git-find-status-file status name)) - (push (git-create-fileinfo (or (git-state-code state) default-state) name) infolist)))) - (dolist (info (nreverse infolist)) - (ewoc-enter-last status info)))) +(defun git-run-ls-files (status files default-state &rest options) + "Run git-ls-files on FILES and parse the results into STATUS. +Return the list of files that haven't been handled." + (let ((refresh files)) + (with-temp-buffer + (apply #'git-run-command t nil "ls-files" "-z" "-t" (append options (list "--") files)) + (goto-char (point-min)) + (while (re-search-forward "\\([HMRCK?]\\) \\([^\0]*\\)\0" nil t 1) + (let ((state (match-string 1)) + (name (match-string 2))) + (git-insert-fileinfo status (git-create-fileinfo (or (git-state-code state) default-state) name) refresh) + (setq files (delete name files)))))) + files) -(defun git-parse-ls-unmerged (status) - "Parse the output of git-ls-files -u in the current buffer." - (goto-char (point-min)) - (let (files) - (while (re-search-forward "[0-7]\\{6\\} [0-9a-f]\\{40\\} [123]\t\\([^\0]+\\)\0" nil t) - (let ((node (git-find-status-file status (match-string 1)))) - (when node (push (ewoc-data node) files)))) - (git-set-files-state files 'unmerged))) +(defun git-run-ls-unmerged (status files) + "Run git-ls-files -u on FILES and parse the results into STATUS." + (with-temp-buffer + (apply #'git-run-command t nil "ls-files" "-z" "-u" "--" files) + (goto-char (point-min)) + (let (unmerged-files) + (while (re-search-forward "[0-7]\\{6\\} [0-9a-f]\\{40\\} [123]\t\\([^\0]+\\)\0" nil t) + (let ((node (git-find-status-file status (match-string 1)))) + (when node (push (ewoc-data node) unmerged-files)))) + (git-set-files-state unmerged-files 'unmerged)))) -(defun git-add-status-file (state name) - "Add a new file to the status list (if not existing already) and return its node." +(defun git-update-status-files (files &optional default-state) + "Update the status of FILES from the index." (unless git-status (error "Not in git-status buffer.")) - (or (git-find-status-file git-status name) - (ewoc-enter-last git-status (git-create-fileinfo state name)))) + (let* ((status git-status) + (remaining-files + (if (git-empty-db-p) ; we need some special handling for an empty db + (git-run-ls-files status files 'added "-c") + (git-run-diff-index status files)))) + (git-run-ls-unmerged status files) + (when (and (or (not files) remaining-files) + (file-readable-p ".git/info/exclude")) + (setq remaining-files (git-run-ls-files status remaining-files + 'unknown "-o" "--exclude-from=.git/info/exclude" + (concat "--exclude-per-directory=" git-per-dir-ignore-file)))) + ; mark remaining files with the default state (or remove them if nil) + (when remaining-files + (if default-state + (ewoc-map (lambda (info) + (when (member (git-fileinfo->name info) remaining-files) + (git-set-files-state (list info) default-state)) + nil) + status) + (ewoc-filter status + (lambda (info files) + (not (member (git-fileinfo->name info) files))) + remaining-files))) + (git-refresh-files) + (git-refresh-ewoc-hf status))) (defun git-marked-files () "Return a list of all marked files, or if none a list containing just the file at cursor position." @@ -789,54 +832,34 @@ and returns the process output as a string." (defun git-add-file () "Add marked file(s) to the index cache." (interactive) - (let ((files (git-marked-files-state 'unknown))) + (let ((files (git-get-filenames (git-marked-files-state 'unknown)))) (unless files - (push (ewoc-data - (git-add-status-file 'added (file-relative-name - (read-file-name "File to add: " nil nil t)))) - files)) - (apply #'git-run-command nil nil "update-index" "--info-only" "--add" "--" (git-get-filenames files)) - (git-set-files-state files 'added) - (git-refresh-files))) + (push (file-relative-name (read-file-name "File to add: " nil nil t)) files)) + (apply #'git-run-command nil nil "update-index" "--add" "--" files) + (git-update-status-files files 'uptodate))) (defun git-ignore-file () "Add marked file(s) to the ignore list." (interactive) - (let ((files (git-marked-files-state 'unknown))) + (let ((files (git-get-filenames (git-marked-files-state 'unknown)))) (unless files - (push (ewoc-data - (git-add-status-file 'unknown (file-relative-name - (read-file-name "File to ignore: " nil nil t)))) - files)) - (dolist (info files) (git-append-to-ignore (git-fileinfo->name info))) - (git-set-files-state files 'ignored) - (git-refresh-files))) + (push (file-relative-name (read-file-name "File to ignore: " nil nil t)) files)) + (dolist (f files) (git-append-to-ignore f)) + (git-update-status-files files 'ignored))) (defun git-remove-file () "Remove the marked file(s)." (interactive) - (let ((files (git-marked-files-state 'added 'modified 'unknown 'uptodate))) + (let ((files (git-get-filenames (git-marked-files-state 'added 'modified 'unknown 'uptodate)))) (unless files - (push (ewoc-data - (git-add-status-file 'unknown (file-relative-name - (read-file-name "File to remove: " nil nil t)))) - files)) + (push (file-relative-name (read-file-name "File to remove: " nil nil t)) files)) (if (yes-or-no-p (format "Remove %d file%s? " (length files) (if (> (length files) 1) "s" ""))) (progn - (dolist (info files) - (let ((name (git-fileinfo->name info))) - (when (file-exists-p name) (delete-file name)))) - (apply #'git-run-command nil nil "update-index" "--info-only" "--remove" "--" (git-get-filenames files)) - ; remove unknown files from the list, set the others to deleted - (ewoc-filter git-status - (lambda (info files) - (not (and (memq info files) (eq (git-fileinfo->state info) 'unknown)))) - files) - (git-set-files-state files 'deleted) - (git-refresh-files) - (unless (ewoc-nth git-status 0) ; refresh header if list is empty - (git-refresh-ewoc-hf git-status))) + (dolist (name files) + (when (file-exists-p name) (delete-file name))) + (apply #'git-run-command nil nil "update-index" "--remove" "--" files) + (git-update-status-files files nil)) (message "Aborting")))) (defun git-revert-file () @@ -849,26 +872,23 @@ and returns the process output as a string." (format "Revert %d file%s? " (length files) (if (> (length files) 1) "s" "")))) (dolist (info files) (case (git-fileinfo->state info) - ('added (push info added)) - ('deleted (push info modified)) - ('unmerged (push info modified)) - ('modified (push info modified)))) + ('added (push (git-fileinfo->name info) added)) + ('deleted (push (git-fileinfo->name info) modified)) + ('unmerged (push (git-fileinfo->name info) modified)) + ('modified (push (git-fileinfo->name info) modified)))) (when added - (apply #'git-run-command nil nil "update-index" "--force-remove" "--" (git-get-filenames added)) - (git-set-files-state added 'unknown)) + (apply #'git-run-command nil nil "update-index" "--force-remove" "--" added)) (when modified - (apply #'git-run-command nil nil "checkout" "HEAD" (git-get-filenames modified)) - (git-set-files-state modified 'uptodate)) - (git-refresh-files)))) + (apply #'git-run-command nil nil "checkout" "HEAD" modified)) + (git-update-status-files (append added modified) 'uptodate)))) (defun git-resolve-file () "Resolve conflicts in marked file(s)." (interactive) - (let ((files (git-marked-files-state 'unmerged))) + (let ((files (git-get-filenames (git-marked-files-state 'unmerged)))) (when files - (apply #'git-run-command nil nil "update-index" "--" (git-get-filenames files)) - (git-set-files-state files 'modified) - (git-refresh-files)))) + (apply #'git-run-command nil nil "update-index" "--" files) + (git-update-status-files files 'uptodate)))) (defun git-remove-handled () "Remove handled files from the status list." @@ -1071,27 +1091,9 @@ and returns the process output as a string." (pos (ewoc-locate status)) (cur-name (and pos (git-fileinfo->name (ewoc-data pos))))) (unless status (error "Not in git-status buffer.")) + (git-run-command nil nil "update-index" "--refresh") (git-clear-status status) - (git-run-command nil nil "update-index" "--info-only" "--refresh") - (if (git-empty-db-p) - ; we need some special handling for an empty db - (with-temp-buffer - (git-run-command t nil "ls-files" "-z" "-t" "-c") - (git-parse-ls-files status 'added)) - (with-temp-buffer - (git-run-command t nil "diff-index" "-z" "-M" "HEAD") - (git-parse-status status))) - (with-temp-buffer - (git-run-command t nil "ls-files" "-z" "-u") - (git-parse-ls-unmerged status)) - (when (file-readable-p ".git/info/exclude") - (with-temp-buffer - (git-run-command t nil "ls-files" "-z" "-t" "-o" - "--exclude-from=.git/info/exclude" - (concat "--exclude-per-directory=" git-per-dir-ignore-file)) - (git-parse-ls-files status 'unknown))) - (git-refresh-files) - (git-refresh-ewoc-hf status) + (git-update-status-files nil) ; move point to the current file name if any (let ((node (and cur-name (git-find-status-file status cur-name)))) (when node (ewoc-goto-node status node))))) From 3473e7df5f8c7f8dc3e2c3f2fdc99a1d1a719c16 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Wed, 25 Jul 2007 01:19:58 +0200 Subject: [PATCH 078/131] gitweb: More detailed error messages for snapshot format Improve error messages for snapshot format in git_snapshot: distinguish between situation where snapshots are turned off, where snapshot format ('sf') parameter is invalid, where given snapshot format does not exist in %known_snapshot_formats hash, and where gitweb was given unsupported snapshot format. While at it, use first from all supported snapshots format as default, if no snapshot format was provided. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index fdfce311fd..0acd0cafb3 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -4317,9 +4317,16 @@ sub git_snapshot { @supported_fmts = filter_snapshot_fmts(@supported_fmts); my $format = $cgi->param('sf'); - unless ($format =~ m/[a-z0-9]+/ - && exists($known_snapshot_formats{$format}) - && grep($_ eq $format, @supported_fmts)) { + if (!@supported_fmts) { + die_error('403 Permission denied', "Permission denied"); + } + # default to first supported snapshot format + $format ||= $supported_fmts[0]; + if ($format !~ m/^[a-z0-9]+$/) { + die_error(undef, "Invalid snapshot format parameter"); + } elsif (!exists($known_snapshot_formats{$format})) { + die_error(undef, "Unknown snapshot format"); + } elsif (!grep($_ eq $format, @supported_fmts)) { die_error(undef, "Unsupported snapshot format"); } From 24d00634948452d0bec1b373b6a2eb9145fc8bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 24 Jul 2007 23:29:29 +0200 Subject: [PATCH 079/131] filter-branch: fix dash complaining about "Missing '))'" On e.g. Ubuntu, dash is used as /bin/sh. Unlike bash it parses commands like a=$((echo stuff) | wc) as an arithmetic expression while what we want is a subshell inside a command substitution. Resolve the ambiguity by placing a space between the two opening parentheses. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- git-filter-branch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-filter-branch.sh b/git-filter-branch.sh index 0ff3475525..b5fa44920d 100755 --- a/git-filter-branch.sh +++ b/git-filter-branch.sh @@ -298,7 +298,7 @@ do # Assign the boundarie(s) in the set of rewritten commits # as the replacement commit(s). # (This would look a bit nicer if --not --stdin worked.) - for p in $((cd "$workdir"/../map; ls | sed "s/^/^/") | + for p in $( (cd "$workdir"/../map; ls | sed "s/^/^/") | git rev-list $ref --boundary --stdin | sed -n "s/^-//p") do From 1843d8d545de0e94dc4c7d3c9125fb47a99962c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 24 Jul 2007 23:54:25 +0200 Subject: [PATCH 080/131] cleanup unpack-trees.c: shrink struct tree_entry_list Remove the two write-only fields executable and symlink from struct tree_entry_list. Also replace usage of the field directory with S_ISDIR checks on the mode field, and then remove this now obsolete field, too. Noticed by David Kastrup. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- unpack-trees.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index 7cc029e564..3b32718436 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -11,9 +11,6 @@ struct tree_entry_list { struct tree_entry_list *next; - unsigned directory : 1; - unsigned executable : 1; - unsigned symlink : 1; unsigned int mode; const char *name; const unsigned char *sha1; @@ -38,9 +35,6 @@ static struct tree_entry_list *create_tree_entry_list(struct tree *tree) entry->name = one.path; entry->sha1 = one.sha1; entry->mode = one.mode; - entry->directory = S_ISDIR(one.mode) != 0; - entry->executable = (one.mode & S_IXUSR) != 0; - entry->symlink = S_ISLNK(one.mode) != 0; entry->next = NULL; *list_p = entry; @@ -141,9 +135,9 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len, #endif if (!first || entcmp(first, firstdir, posns[i]->name, - posns[i]->directory) > 0) { + S_ISDIR(posns[i]->mode)) > 0) { first = posns[i]->name; - firstdir = posns[i]->directory; + firstdir = S_ISDIR(posns[i]->mode); } } /* No name means we're done */ @@ -177,7 +171,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len, continue; } - if (posns[i]->directory) { + if (S_ISDIR(posns[i]->mode)) { struct tree *tree = lookup_tree(posns[i]->sha1); any_dirs = 1; parse_tree(tree); From f836f1ae9b1535d6a1aeb4a0e8a33d65edaf9ff8 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Wed, 25 Jul 2007 00:56:20 +0200 Subject: [PATCH 081/131] cvsexportcommit: avoid racy CVS problem. If git cvsexportcommit is executed fast enough in sequence, the CVS timestamps could end up being the same. CVS tries to fix this by sleeping until the CPU clock changes seconds. Unfortunately, the CPU clock and the file system clock are not necessarily the same, so the timestamps could be the same anyway. When that happens CVS may not recognize changed files and cvs will forget to commit some files. Signed-off-by: Robin Rosenberg Signed-off-by: Junio C Hamano --- git-cvsexportcommit.perl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl index e9832d2bb9..a33fa8d4c8 100755 --- a/git-cvsexportcommit.perl +++ b/git-cvsexportcommit.perl @@ -281,6 +281,11 @@ if ($opt_c) { # clean up unlink(".cvsexportcommit.diff"); +# CVS version 1.11.x and 1.12.x sleeps the wrong way to ensure the timestamp +# used by CVS and the one set by subsequence file modifications are different. +# If they are not different CVS will not detect changes. +sleep(1); + sub usage { print STDERR < Date: Tue, 24 Jul 2007 09:50:38 -0500 Subject: [PATCH 082/131] send-email: Update regex parsing for pine aliases The pine address book format is tab seperated and the first field is the nickname/alias and the third field is the email address as per: http://www.washington.edu/pine/tech-notes/low-level.html Signed-off-by: Kumar Gala Signed-off-by: Junio C Hamano --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index a09b1c9650..f43f92f957 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -237,7 +237,7 @@ my %parse_alias = ( $aliases{$1} = [ split(/\s+/, $2) ]; }}}, pine => sub { my $fh = shift; while (<$fh>) { - if (/^(\S+)\s+(.*)$/) { + if (/^(\S+)\t.*\t(.*)$/) { $aliases{$1} = [ split(/\s*,\s*/, $2) ]; }}}, gnus => sub { my $fh = shift; while (<$fh>) { From 7b69b873faf3cfd592bb64a496c6982a540aa7ea Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 24 Jul 2007 00:39:50 +0100 Subject: [PATCH 083/131] git log -g: Complain, but do not fail, when no reflogs are there When asking "git log -g --all", clearly you want to see only those refs that do have reflogs, but you do not want it to fail, either. So instead of die()ing, complain about it, but move on to the other refs. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- reflog-walk.c | 7 ++++--- reflog-walk.h | 2 +- revision.c | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/reflog-walk.c b/reflog-walk.c index c983858259..ee1456b45a 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -136,7 +136,7 @@ void init_reflog_walk(struct reflog_walk_info** info) *info = xcalloc(sizeof(struct reflog_walk_info), 1); } -void add_reflog_for_walk(struct reflog_walk_info *info, +int add_reflog_for_walk(struct reflog_walk_info *info, struct commit *commit, const char *name) { unsigned long timestamp = 0; @@ -188,7 +188,7 @@ void add_reflog_for_walk(struct reflog_walk_info *info, } } if (!reflogs || reflogs->nr == 0) - die("No reflogs found for '%s'", branch); + return -1; path_list_insert(branch, &info->complete_reflogs)->util = reflogs; } @@ -200,13 +200,14 @@ void add_reflog_for_walk(struct reflog_walk_info *info, if (commit_reflog->recno < 0) { free(branch); free(commit_reflog); - return; + return -1; } } else commit_reflog->recno = reflogs->nr - recno - 1; commit_reflog->reflogs = reflogs; add_commit_info(commit, commit_reflog, &info->reflogs); + return 0; } void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit) diff --git a/reflog-walk.h b/reflog-walk.h index a4f7015d3e..7ca1438f4d 100644 --- a/reflog-walk.h +++ b/reflog-walk.h @@ -2,7 +2,7 @@ #define REFLOG_WALK_H extern void init_reflog_walk(struct reflog_walk_info** info); -extern void add_reflog_for_walk(struct reflog_walk_info *info, +extern int add_reflog_for_walk(struct reflog_walk_info *info, struct commit *commit, const char *name); extern void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit); diff --git a/revision.c b/revision.c index 16f35c7c18..038693caba 100644 --- a/revision.c +++ b/revision.c @@ -118,10 +118,11 @@ static void add_pending_object_with_mode(struct rev_info *revs, struct object *o { if (revs->no_walk && (obj->flags & UNINTERESTING)) die("object ranges do not make sense when not walking revisions"); + if (revs->reflog_info && obj->type == OBJ_COMMIT && + add_reflog_for_walk(revs->reflog_info, + (struct commit *)obj, name)) + return; add_object_array_with_mode(obj, name, &revs->pending, mode); - if (revs->reflog_info && obj->type == OBJ_COMMIT) - add_reflog_for_walk(revs->reflog_info, - (struct commit *)obj, name); } void add_pending_object(struct rev_info *revs, struct object *obj, const char *name) From af66366a9feb0194ed04b1f538998021ece268a8 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 24 Jul 2007 19:18:34 +0100 Subject: [PATCH 084/131] Teach approxidate() to understand "never" If you want to keep the reflogs around for a really long time, you should be able to say so: $ git config gc.reflogExpire never Now it works, too. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- date.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/date.c b/date.c index 45b0b1deb3..93bef6efbe 100644 --- a/date.c +++ b/date.c @@ -660,6 +660,14 @@ static void date_am(struct tm *tm, int *num) tm->tm_hour = (hour % 12); } +static void date_never(struct tm *tm, int *num) +{ + tm->tm_mon = tm->tm_wday = tm->tm_yday + = tm->tm_hour = tm->tm_min = tm->tm_sec = 0; + tm->tm_year = 70; + tm->tm_mday = 1; +} + static const struct special { const char *name; void (*fn)(struct tm *, int *); @@ -670,6 +678,7 @@ static const struct special { { "tea", date_tea }, { "PM", date_pm }, { "AM", date_am }, + { "never", date_never }, { NULL } }; From d1cc130a5eb50d5bfe1e8b76cab3d8970fd70ad1 Mon Sep 17 00:00:00 2001 From: Steven Grimm Date: Sun, 22 Jul 2007 21:17:42 -0700 Subject: [PATCH 085/131] Teach git-commit about commit message templates. These are useful in organizations that enforce particular formats for commit messages, e.g., to specify bug IDs or test plans. Use of the template is not enforced; it is simply used as the initial content when the editor is invoked. Signed-off-by: Steven Grimm Signed-off-by: Junio C Hamano --- Documentation/git-commit.txt | 8 +++ git-commit.sh | 54 ++++++++++++++++++-- t/t7500-commit.sh | 96 ++++++++++++++++++++++++++++++++++++ t/t7500/add-comments | 4 ++ t/t7500/add-content | 3 ++ t/t7500/add-signed-off | 3 ++ 6 files changed, 163 insertions(+), 5 deletions(-) create mode 100755 t/t7500-commit.sh create mode 100755 t/t7500/add-comments create mode 100755 t/t7500/add-content create mode 100755 t/t7500/add-signed-off diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 8e0e7e2d04..3f36c6782f 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -74,6 +74,14 @@ OPTIONS -m |--message=:: Use the given as the commit message. +-t |--template=:: + Use the contents of the given file as the initial version + of the commit message. The editor is invoked and you can + make subsequent changes. If a message is specified using + the `-m` or `-F` options, this option has no effect. The + template file may also be specified using the `commit.template` + configuration variable. + -s|--signoff:: Add Signed-off-by line at the end of the commit message. diff --git a/git-commit.sh b/git-commit.sh index 92749df1e7..4290ae2dd2 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Linus Torvalds # Copyright (c) 2006 Junio C Hamano -USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m | -F | (-C|-c) | --amend] [-u] [-e] [--author ] [[-i | -o] ...]' +USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m | -F | (-C|-c) | --amend] [-u] [-e] [--author ] [--template ] [[-i | -o] ...]' SUBDIRECTORY_OK=Yes . git-sh-setup require_work_tree @@ -87,6 +87,7 @@ signoff= force_author= only_include_assumed= untracked_files= +templatefile="`git config commit.template`" while case "$#" in 0) break;; esac do case "$1" in @@ -248,6 +249,13 @@ $1" signoff=t shift ;; + -t|--t|--te|--tem|--temp|--templ|--templa|--templat|--template) + case "$#" in 1) usage ;; esac + shift + templatefile="$1" + no_edit= + shift + ;; -q|--q|--qu|--qui|--quie|--quiet) quiet=t shift @@ -321,6 +329,14 @@ t,,[1-9]*) die "No paths with -i does not make sense." ;; esac +if test ! -z "$templatefile" -a -z "$log_given" +then + if test ! -f "$templatefile" + then + die "Commit template file does not exist." + fi +fi + ################################################################ # Prepare index to have a tree to be committed @@ -454,6 +470,9 @@ then elif test -f "$GIT_DIR/SQUASH_MSG" then cat "$GIT_DIR/SQUASH_MSG" +elif test "$templatefile" != "" +then + cat "$templatefile" fi | git stripspace >"$GIT_DIR"/COMMIT_EDITMSG case "$signoff" in @@ -572,10 +591,35 @@ else fi | git stripspace >"$GIT_DIR"/COMMIT_MSG -if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG | - git stripspace | - wc -l` && - test 0 -lt $cnt +# Test whether the commit message has any content we didn't supply. +have_commitmsg= +grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG | + git stripspace > "$GIT_DIR"/COMMIT_BAREMSG + +# Is the commit message totally empty? +if test -s "$GIT_DIR"/COMMIT_BAREMSG +then + if test "$templatefile" != "" + then + # Test whether this is just the unaltered template. + if cnt=`sed -e '/^#/d' < "$templatefile" | + git stripspace | + diff "$GIT_DIR"/COMMIT_BAREMSG - | + wc -l` && + test 0 -lt $cnt + then + have_commitmsg=t + fi + else + # No template, so the content in the commit message must + # have come from the user. + have_commitmsg=t + fi +fi + +rm -f "$GIT_DIR"/COMMIT_BAREMSG + +if test "$have_commitmsg" = "t" then if test -z "$TMP_INDEX" then diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh new file mode 100755 index 0000000000..f11ada8617 --- /dev/null +++ b/t/t7500-commit.sh @@ -0,0 +1,96 @@ +#!/bin/sh +# +# Copyright (c) 2007 Steven Grimm +# + +test_description='git-commit + +Tests for selected commit options.' + +. ./test-lib.sh + +commit_msg_is () { + test "`git log --pretty=format:%s%b -1`" = "$1" +} + +# A sanity check to see if commit is working at all. +test_expect_success 'a basic commit in an empty tree should succeed' ' + echo content > foo && + git add foo && + git commit -m "initial commit" +' + +test_expect_success 'nonexistent template file should return error' ' + echo changes >> foo && + git add foo && + ! git commit --template "$PWD"/notexist +' + +test_expect_success 'nonexistent template file in config should return error' ' + git config commit.template "$PWD"/notexist && + ! git commit && + git config --unset commit.template +' + +# From now on we'll use a template file that exists. +TEMPLATE="$PWD"/template + +test_expect_success 'unedited template should not commit' ' + echo "template line" > "$TEMPLATE" && + ! git commit --template "$TEMPLATE" +' + +test_expect_success 'unedited template with comments should not commit' ' + echo "# comment in template" >> "$TEMPLATE" && + ! git commit --template "$TEMPLATE" +' + +test_expect_success 'a Signed-off-by line by itself should not commit' ' + ! GIT_EDITOR=../t7500/add-signed-off git commit --template "$TEMPLATE" +' + +test_expect_success 'adding comments to a template should not commit' ' + ! GIT_EDITOR=../t7500/add-comments git commit --template "$TEMPLATE" +' + +test_expect_success 'adding real content to a template should commit' ' + GIT_EDITOR=../t7500/add-content git commit --template "$TEMPLATE" && + commit_msg_is "template linecommit message" +' + +test_expect_success '-t option should be short for --template' ' + echo "short template" > "$TEMPLATE" && + echo "new content" >> foo && + git add foo && + GIT_EDITOR=../t7500/add-content git commit -t "$TEMPLATE" && + commit_msg_is "short templatecommit message" +' + +test_expect_success 'config-specified template should commit' ' + echo "new template" > "$TEMPLATE" && + git config commit.template "$TEMPLATE" && + echo "more content" >> foo && + git add foo && + GIT_EDITOR=../t7500/add-content git commit && + git config --unset commit.template && + commit_msg_is "new templatecommit message" +' + +test_expect_success 'explicit commit message should override template' ' + echo "still more content" >> foo && + git add foo && + GIT_EDITOR=../t7500/add-content git commit --template "$TEMPLATE" \ + -m "command line msg" && + commit_msg_is "command line msg" +' + +test_expect_success 'commit message from file should override template' ' + echo "content galore" >> foo && + git add foo && + echo "standard input msg" | + GIT_EDITOR=../t7500/add-content git commit \ + --template "$TEMPLATE" --file - && + commit_msg_is "standard input msg" +' + +test_done diff --git a/t/t7500/add-comments b/t/t7500/add-comments new file mode 100755 index 0000000000..a72e65c891 --- /dev/null +++ b/t/t7500/add-comments @@ -0,0 +1,4 @@ +#!/bin/sh +echo "# this is a new comment" >> "$1" +echo "# and so is this" >> "$1" +exit 0 diff --git a/t/t7500/add-content b/t/t7500/add-content new file mode 100755 index 0000000000..2fa3d86a10 --- /dev/null +++ b/t/t7500/add-content @@ -0,0 +1,3 @@ +#!/bin/sh +echo "commit message" >> "$1" +exit 0 diff --git a/t/t7500/add-signed-off b/t/t7500/add-signed-off new file mode 100755 index 0000000000..e1d856af6d --- /dev/null +++ b/t/t7500/add-signed-off @@ -0,0 +1,3 @@ +#!/bin/sh +echo "Signed-off-by: foo " >> "$1" +exit 0 From ca193cf1ad5bf8982db2e42abb2fa713011ee726 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 24 Jul 2007 01:02:25 +0100 Subject: [PATCH 086/131] git am: skip pine's internal folder data Test if the From: line contains "Mail System Internal Data" and if it is, skip this mail. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-am.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/git-am.sh b/git-am.sh index bfd65dcf95..6cf0eeee71 100755 --- a/git-am.sh +++ b/git-am.sh @@ -284,6 +284,12 @@ do git mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \ <"$dotest/$msgnum" >"$dotest/info" || stop_here $this + + # skip pine's internal folder data + grep '^Author: Mail System Internal Data$' \ + <"$dotest"/info >/dev/null && + go_next && continue + test -s $dotest/patch || { echo "Patch is empty. Was it split wrong?" stop_here $this From c4eaed49c22366f1994a75179adeac47e7863794 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 24 Jul 2007 23:25:38 -0700 Subject: [PATCH 087/131] t9200: Be careful when checking CVS/Entries CVS/Entries file can contain a line with single D to say "this directory does not have any subdirectories". Do not get confused with such an entry. Signed-off-by: Junio C Hamano --- t/t9200-git-cvsexportcommit.sh | 64 +++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh index 4efa0c926c..910c584f24 100755 --- a/t/t9200-git-cvsexportcommit.sh +++ b/t/t9200-git-cvsexportcommit.sh @@ -28,6 +28,18 @@ git add empty && git commit -q -a -m "Initial" 2>/dev/null || exit 1 +check_entries () { + # $1 == directory, $2 == expected + grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual + if test -z "$2" + then + >expected + else + printf '%s\n' "$2" | tr '|' '\012' >expected + fi + diff -u expected actual +} + test_expect_success \ 'New file' \ 'mkdir A B C D E F && @@ -43,10 +55,10 @@ test_expect_success \ id=$(git rev-list --max-count=1 HEAD) && (cd "$CVSWORK" && git cvsexportcommit -c $id && - test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "newfile1.txt/1.1/" && - test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "newfile2.txt/1.1/" && - test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "newfile3.png/1.1/-kb" && - test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "newfile4.png/1.1/-kb" && + check_entries A "newfile1.txt/1.1/" && + check_entries B "newfile2.txt/1.1/" && + check_entries C "newfile3.png/1.1/-kb" && + check_entries D "newfile4.png/1.1/-kb" && diff A/newfile1.txt ../A/newfile1.txt && diff B/newfile2.txt ../B/newfile2.txt && diff C/newfile3.png ../C/newfile3.png && @@ -67,12 +79,12 @@ test_expect_success \ id=$(git rev-list --max-count=1 HEAD) && (cd "$CVSWORK" && git cvsexportcommit -c $id && - test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "newfile1.txt/1.2/" && - test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "" && - test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "" && - test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "newfile4.png/1.2/-kb" && - test "$(echo $(sort E/CVS/Entries|cut -d/ -f2,3,5))" = "newfile5.txt/1.1/" && - test "$(echo $(sort F/CVS/Entries|cut -d/ -f2,3,5))" = "newfile6.png/1.1/-kb" && + check_entries A "newfile1.txt/1.2/" && + check_entries B "" && + check_entries C "" && + check_entries D "newfile4.png/1.2/-kb" && + check_entries E "newfile5.txt/1.1/" && + check_entries F "newfile6.png/1.1/-kb" && diff A/newfile1.txt ../A/newfile1.txt && diff D/newfile4.png ../D/newfile4.png && diff E/newfile5.txt ../E/newfile5.txt && @@ -115,12 +127,12 @@ test_expect_success \ id=$(git rev-list --max-count=1 HEAD) && (cd "$CVSWORK" && git cvsexportcommit -c $id && - test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "newfile1.txt/1.2/" && - test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "" && - test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "" && - test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "" && - test "$(echo $(sort E/CVS/Entries|cut -d/ -f2,3,5))" = "newfile5.txt/1.1/" && - test "$(echo $(sort F/CVS/Entries|cut -d/ -f2,3,5))" = "newfile6.png/1.1/-kb" && + check_entries A "newfile1.txt/1.2/" && + check_entries B "" && + check_entries C "" && + check_entries D "" && + check_entries E "newfile5.txt/1.1/" && + check_entries F "newfile6.png/1.1/-kb" && diff A/newfile1.txt ../A/newfile1.txt && diff E/newfile5.txt ../E/newfile5.txt && diff F/newfile6.png ../F/newfile6.png @@ -133,12 +145,12 @@ test_expect_success \ id=$(git rev-list --max-count=1 HEAD) && (cd "$CVSWORK" && git cvsexportcommit -c $id && - test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "" && - test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "" && - test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "" && - test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "" && - test "$(echo $(sort E/CVS/Entries|cut -d/ -f2,3,5))" = "newfile5.txt/1.1/" && - test "$(echo $(sort F/CVS/Entries|cut -d/ -f2,3,5))" = "newfile6.png/1.1/-kb" && + check_entries A "" && + check_entries B "" && + check_entries C "" && + check_entries D "" && + check_entries E "newfile5.txt/1.1/" && + check_entries F "newfile6.png/1.1/-kb" && diff E/newfile5.txt ../E/newfile5.txt && diff F/newfile6.png ../F/newfile6.png )' @@ -154,7 +166,7 @@ test_expect_success \ id=$(git rev-list --max-count=1 HEAD) && (cd "$CVSWORK" && git-cvsexportcommit -c $id && - test "$(echo $(sort "G g/CVS/Entries"|cut -d/ -f2,3,5))" = "with spaces.png/1.1/-kb with spaces.txt/1.1/" + check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/" )' test_expect_success \ @@ -166,7 +178,7 @@ test_expect_success \ id=$(git rev-list --max-count=1 HEAD) && (cd "$CVSWORK" && git-cvsexportcommit -c $id - test "$(echo $(sort "G g/CVS/Entries"|cut -d/ -f2,3,5))" = "with spaces.png/1.2/-kb with spaces.txt/1.2/" + check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/" )' # Some filesystems mangle pathnames with UTF-8 characters -- @@ -191,7 +203,9 @@ test_expect_success \ id=$(git rev-list --max-count=1 HEAD) && (cd "$CVSWORK" && git-cvsexportcommit -v -c $id && - test "$(echo $(sort Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/CVS/Entries|cut -d/ -f2,3,5))" = "gårdetsågårdet.png/1.1/-kb gårdetsågårdet.txt/1.1/" + check_entries \ + "Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö" \ + "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/" )' fi From 1c911dc86cd8c504fbad98a75b28cbc92317a0e8 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 24 Jul 2007 20:59:47 +0200 Subject: [PATCH 088/131] pretty-options.txt: tiny doc fix Signed-off-by: Jim Meyering Signed-off-by: Junio C Hamano --- Documentation/pretty-options.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/pretty-options.txt b/Documentation/pretty-options.txt index 746bc5b7f9..973d8dd733 100644 --- a/Documentation/pretty-options.txt +++ b/Documentation/pretty-options.txt @@ -1,9 +1,9 @@ --pretty[='']:: - Pretty print the contents of the commit logs in a given format, + Pretty-print the contents of the commit logs in a given format, where '' can be one of 'oneline', 'short', 'medium', 'full', 'fuller', 'email', 'raw' and 'format:'. - When left out the format default to 'medium'. + When omitted, the format defaults to 'medium'. --abbrev-commit:: Instead of showing the full 40-byte hexadecimal commit object From ceefa44fe2d72f73548c4c36b42916b9c60ae16b Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 24 Jul 2007 12:02:28 +0200 Subject: [PATCH 089/131] git.el: Pass an explicit argument to enable smerge-mode. Without argument the mode is toggled, which would do the wrong thing if the file was already open. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index b92bbe8728..53dd703260 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -1058,7 +1058,7 @@ Return the list of files that haven't been handled." (let ((info (ewoc-data (ewoc-locate git-status)))) (find-file (git-fileinfo->name info)) (when (eq 'unmerged (git-fileinfo->state info)) - (smerge-mode)))) + (smerge-mode 1)))) (defun git-find-file-other-window () "Visit the current file in its own buffer in another window." From f48a203a563ae8a46daa8b8923b5d81dc40502fb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 24 Jul 2007 21:39:33 -0700 Subject: [PATCH 090/131] GIT 1.5.3-rc3 Signed-off-by: Junio C Hamano --- Documentation/RelNotes-1.5.3.txt | 36 +++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Documentation/RelNotes-1.5.3.txt b/Documentation/RelNotes-1.5.3.txt index 896ff1d95a..785bd38455 100644 --- a/Documentation/RelNotes-1.5.3.txt +++ b/Documentation/RelNotes-1.5.3.txt @@ -32,8 +32,9 @@ Updates since v1.5.2 - "git rebase" learned an "interactive" mode that let you pick and reorder which commits to rebuild. - - "git fsck" can save its findings in $GIT_DIR/lost-found, - without a separate invocation of "git lost-found" command. + - "git fsck" can save its findings in $GIT_DIR/lost-found, without a + separate invocation of "git lost-found" command. The blobs stored by + lost-found are stored in plain format to allow you to grep in them. - $GIT_WORK_TREE environment variable can be used together with $GIT_DIR to work in a subdirectory of a working tree that is @@ -49,6 +50,10 @@ Updates since v1.5.2 - "git-cvsserver" learned new options (--base-path, --export-all, --strict-paths) inspired by git-daemon. + - "git-commit" can use "-t templatefile" option and commit.template + configuration variable to prime the commit message given to you in the + editor. + - "git-submodule" command helps you manage the projects from the superproject that contain them. @@ -105,9 +110,30 @@ Updates since v1.5.2 * Updated behavior of existing commands. + - "gitweb" can offer multiple snapshot formats. + + ***NOTE*** Unfortunately, this changes the format of the + $feature{snapshot}{default} entry in the per-site + configuration file 'gitweb_config.perl'. It used to be a + three-element tuple that describe a single format; with the + new configuration item format, you only have to say the name + of the format ('tgz', 'tbz2' or 'zip'). Please update the + your configuration file accordingly. + + - The editor to use with many interactive commands can be + overridden with GIT_EDITOR environment variable, or if it + does not exist, with core.editor configuration variable. As + before, if you have neither, environment variables VISUAL + and EDITOR are consulted in this order, and then finally we + fall back on "vi". + - "git rm --cached" does not complain when removing a newly added file from the index anymore. + - Options to "git log" to affect how --grep/--author options look for + given strings now have shorter abbreviations. -i is for ignore case, + and -E is for extended regexp. + - "git svn dcommit" retains local merge information. - "git config" to set values also honors type flags like --bool @@ -189,6 +215,10 @@ Updates since v1.5.2 git-fast-import (also in contrib). The man page and p4 rpm have been removed as well. + - "git mailinfo" (hence "am") now tries to see if the message + is in utf-8 first, instead of assuming iso-8859-1, if + incoming e-mail does not say what encoding it is in. + * Builds - old-style function definitions (most notably, a function @@ -232,6 +262,6 @@ this release, unless otherwise noted. -- exec >/var/tmp/1 -O=v1.5.3-rc2 +O=v1.5.3-rc3 echo O=`git describe refs/heads/master` git shortlog --no-merges $O..refs/heads/master ^refs/heads/maint From 30d1990584301132892e9f184bff9705f74a1565 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 25 Jul 2007 03:27:57 -0400 Subject: [PATCH 091/131] git-gui: Save remote urls obtained from config/remotes setup I'm storing the URLs of any pre-configured remote repositories that we happen to come across so that we can later use these URLs to show to the user in parts of the UI that might care. Signed-off-by: Shawn O. Pearce --- lib/remote.tcl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/remote.tcl b/lib/remote.tcl index e235ca8876..cf9b9d5829 100644 --- a/lib/remote.tcl +++ b/lib/remote.tcl @@ -57,6 +57,7 @@ proc all_tracking_branches {} { proc load_all_remotes {} { global repo_config global all_remotes tracking_branches some_heads_tracking + global remote_url set some_heads_tracking 0 set all_remotes [list] @@ -76,6 +77,10 @@ proc load_all_remotes {} { catch { set fd [open [file join $rm_dir $name] r] while {[gets $fd line] >= 0} { + if {[regexp {^URL:[ ]*(.+)$} $line line url]} { + set remote_url($name) $url + continue + } if {![regexp {^Pull:[ ]*([^:]+):(.+)$} \ $line line src dst]} continue if {[string index $src 0] eq {+}} { @@ -100,6 +105,7 @@ proc load_all_remotes {} { foreach line [array names repo_config remote.*.url] { if {![regexp ^remote\.(.*)\.url\$ $line line name]} continue lappend all_remotes $name + set remote_url($name) $repo_config(remote.$name.url) if {[catch {set fl $repo_config(remote.$name.fetch)}]} { set fl {} From 844c3f6fe9d4d2bdc4e76f6a3bf3dfe86ce8c544 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 25 Jul 2007 04:13:00 -0400 Subject: [PATCH 092/131] git-gui: Display commit/tag/remote info in tooltip of revision picker Our revision chooser mega-widget now sets up tooltips for itself so that it displays details about a commit (or a tag and the commit it refers to) when the user mouses over that line in the filtered ref list. If the item is from a remote tracking branch then we also show the remote url and what branch on that remote we fetch from, so the user has a clear concept of where that revision data originated. To help the merge dialog I've also added a new constructor that makes the dialog only offer unmerged revisions (those not in HEAD), as this allows users to avoid performing merges only to get "Already up to date" messages back from core Git. Signed-off-by: Shawn O. Pearce --- lib/choose_rev.tcl | 236 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 230 insertions(+), 6 deletions(-) diff --git a/lib/choose_rev.tcl b/lib/choose_rev.tcl index 6c4c3188f0..bb6966eb93 100644 --- a/lib/choose_rev.tcl +++ b/lib/choose_rev.tcl @@ -16,8 +16,21 @@ 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 +field tip_data ; # array of tip commit info by refname -constructor new {path {title {}}} { +field tooltip_wm {} ; # Current tooltip toplevel, if open +field tooltip_t {} ; # Text widget in $tooltip_wm +field tooltip_timer {} ; # Current timer event for our tooltip + +proc new {path {title {}}} { + return [_new $path 0 $title] +} + +proc new_unmerged {path {title {}}} { + return [_new $path 1 $title] +} + +constructor _new {path unmerged_only title} { global current_branch is_detached set w $path @@ -93,6 +106,10 @@ constructor new {path {title {}}} { -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 + bind $w_list [cb _show_tooltip @%x,%y] + bind $w_list [cb _hide_tooltip] + bind $w_list [cb _hide_tooltip] + bind $w_list [cb _hide_tooltip] grid columnconfigure $w 1 -weight 1 if {$is_detached} { @@ -105,21 +122,89 @@ constructor new {path {title {}}} { bind $w_filter [list focus $w_list]\;break bind $w_filter [list focus $w_list] + set fmt list + append fmt { %(refname)} + append fmt { [list} + append fmt { %(objecttype)} + append fmt { %(objectname)} + append fmt { [concat %(taggername) %(authorname)]} + append fmt { [concat %(taggerdate) %(authordate)]} + append fmt { %(subject)} + append fmt {] [list} + append fmt { %(*objecttype)} + append fmt { %(*objectname)} + append fmt { %(*authorname)} + append fmt { %(*authordate)} + append fmt { %(*subject)} + append fmt {]} + set all_refn [list] + set fr_fd [git_read for-each-ref \ + --tcl \ + --sort=-taggerdate \ + --format=$fmt \ + refs/heads \ + refs/remotes \ + refs/tags \ + ] + fconfigure $fr_fd -translation lf -encoding utf-8 + while {[gets $fr_fd line] > 0} { + set line [eval $line] + if {[lindex $line 1 0] eq {tag}} { + if {[lindex $line 2 0] eq {commit}} { + set sha1 [lindex $line 2 1] + } else { + continue + } + } elseif {[lindex $line 1 0] eq {commit}} { + set sha1 [lindex $line 1 1] + } else { + continue + } + set refn [lindex $line 0] + set tip_data($refn) [lrange $line 1 end] + lappend cmt_refn($sha1) $refn + lappend all_refn $refn + } + close $fr_fd + + if {$unmerged_only} { + set fr_fd [git_read rev-list --all ^$::HEAD] + while {[gets $fr_fd sha1] > 0} { + if {[catch {set rlst $cmt_refn($sha1)}]} continue + foreach refn $rlst { + set inc($refn) 1 + } + } + close $fr_fd + } else { + foreach refn $all_refn { + set inc($refn) 1 + } + } + set spec_head [list] foreach name [load_all_heads] { - lappend spec_head [list $name refs/heads/$name] + set refn refs/heads/$name + if {[info exists inc($refn)]} { + lappend spec_head [list $name $refn] + } } 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 refn [lindex $spec 0] + if {[info exists inc($refn)]} { + regsub ^refs/(heads|remotes)/ $refn {} name + lappend spec_trck [concat $name $spec] + } } set spec_tag [list] foreach name [load_all_tags] { - lappend spec_tag [list $name refs/tags/$name] + set refn refs/tags/$name + if {[info exists inc($refn)]} { + lappend spec_tag [list $name $refn] + } } if {$is_detached} { set revtype HEAD @@ -364,4 +449,143 @@ method _sb_set {sb orient first last} { $sb set $first $last } +method _show_tooltip {pos} { + if {$tooltip_wm ne {}} { + _open_tooltip $this + } elseif {$tooltip_timer eq {}} { + set tooltip_timer [after 1000 [cb _open_tooltip]] + } +} + +method _open_tooltip {} { + global remote_url + + set tooltip_timer {} + set pos_x [winfo pointerx $w_list] + set pos_y [winfo pointery $w_list] + if {[winfo containing $pos_x $pos_y] ne $w_list} { + _hide_tooltip $this + return + } + + set pos @[join [list \ + [expr {$pos_x - [winfo rootx $w_list]}] \ + [expr {$pos_y - [winfo rooty $w_list]}]] ,] + set lno [$w_list index $pos] + if {$lno eq {}} { + _hide_tooltip $this + return + } + + set spec [lindex $cur_specs $lno] + set refn [lindex $spec 1] + if {$refn eq {}} { + _hide_tooltip $this + return + } + + if {$tooltip_wm eq {}} { + set tooltip_wm [toplevel $w_list.tooltip -borderwidth 1] + wm overrideredirect $tooltip_wm 1 + wm transient $tooltip_wm [winfo toplevel $w_list] + set tooltip_t $tooltip_wm.label + text $tooltip_t \ + -takefocus 0 \ + -highlightthickness 0 \ + -relief flat \ + -borderwidth 0 \ + -wrap none \ + -background lightyellow \ + -foreground black + $tooltip_t tag conf section_header -font font_uibold + bind $tooltip_wm [cb _hide_tooltip] + pack $tooltip_t + } else { + $tooltip_t conf -state normal + $tooltip_t delete 0.0 end + } + + set data $tip_data($refn) + if {[lindex $data 0 0] eq {tag}} { + set tag [lindex $data 0] + if {[lindex $data 1 0] eq {commit}} { + set cmit [lindex $data 1] + } else { + set cmit {} + } + } elseif {[lindex $data 0 0] eq {commit}} { + set tag {} + set cmit [lindex $data 0] + } + + $tooltip_t insert end "[lindex $spec 0]\n" + + if {$tag ne {}} { + $tooltip_t insert end "\n" + $tooltip_t insert end "tag" section_header + $tooltip_t insert end " [lindex $tag 1]\n" + $tooltip_t insert end [lindex $tag 2] + $tooltip_t insert end " ([lindex $tag 3])\n" + $tooltip_t insert end [lindex $tag 4] + $tooltip_t insert end "\n" + } + + if {$cmit ne {}} { + $tooltip_t insert end "\n" + $tooltip_t insert end "commit" section_header + $tooltip_t insert end " [lindex $cmit 1]\n" + $tooltip_t insert end [lindex $cmit 2] + $tooltip_t insert end " ([lindex $cmit 3])\n" + $tooltip_t insert end [lindex $cmit 4] + } + + if {[llength $spec] > 2} { + $tooltip_t insert end "\n" + $tooltip_t insert end "remote" section_header + $tooltip_t insert end " [lindex $spec 2]\n" + $tooltip_t insert end "url" + $tooltip_t insert end " $remote_url([lindex $spec 2])\n" + $tooltip_t insert end "branch" + $tooltip_t insert end " [lindex $spec 3]" + } + + $tooltip_t conf -state disabled + _position_tooltip $this +} + +method _position_tooltip {} { + set max_h [lindex [split [$tooltip_t index end] .] 0] + set max_w 0 + for {set i 1} {$i <= $max_h} {incr i} { + set c [lindex [split [$tooltip_t index "$i.0 lineend"] .] 1] + if {$c > $max_w} {set max_w $c} + } + $tooltip_t conf -width $max_w -height $max_h + + set req_w [winfo reqwidth $tooltip_t] + set req_h [winfo reqheight $tooltip_t] + set pos_x [expr {[winfo pointerx .] + 5}] + set pos_y [expr {[winfo pointery .] + 10}] + + set g "${req_w}x${req_h}" + if {$pos_x >= 0} {append g +} + append g $pos_x + if {$pos_y >= 0} {append g +} + append g $pos_y + + wm geometry $tooltip_wm $g + raise $tooltip_wm +} + +method _hide_tooltip {} { + if {$tooltip_wm ne {}} { + destroy $tooltip_wm + set tooltip_wm {} + } + if {$tooltip_timer ne {}} { + after cancel $tooltip_timer + set tooltip_timer {} + } +} + } From becafaace69980d2980802432e86e7873317a4b6 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 25 Jul 2007 04:20:02 -0400 Subject: [PATCH 093/131] git-gui: Show ref last update times in revision chooser tooltips If we can we now show the last modification date of a loose ref as part of the tooltip information shown in the revision picker. This gives the user an indication of when was the last time that the ref was modified locally, and may especially be of interest when looking at a tracking branch. If we cannot find the loose ref file than we try to fallback on the reflog and scan it for the date of the last record. We don't start with the reflog however as scanning it backwards from the end is not an easy thing to do in Tcl. So I'm being lazy here and just going through the entire file, line by line. Since that is less efficient than a single stat system call, its our fallback strategy. Signed-off-by: Shawn O. Pearce --- lib/choose_rev.tcl | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/choose_rev.tcl b/lib/choose_rev.tcl index bb6966eb93..4147b7c5bc 100644 --- a/lib/choose_rev.tcl +++ b/lib/choose_rev.tcl @@ -17,6 +17,7 @@ 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 field tip_data ; # array of tip commit info by refname +field log_last ; # array of reflog date by refname field tooltip_wm {} ; # Current tooltip toplevel, if open field tooltip_t {} ; # Text widget in $tooltip_wm @@ -518,7 +519,14 @@ method _open_tooltip {} { set cmit [lindex $data 0] } - $tooltip_t insert end "[lindex $spec 0]\n" + $tooltip_t insert end [lindex $spec 0] + set last [_reflog_last $this [lindex $spec 1]] + if {$last ne {}} { + $tooltip_t insert end "\n" + $tooltip_t insert end "updated" + $tooltip_t insert end " $last" + } + $tooltip_t insert end "\n" if {$tag ne {}} { $tooltip_t insert end "\n" @@ -553,6 +561,30 @@ method _open_tooltip {} { _position_tooltip $this } +method _reflog_last {name} { + if {[info exists reflog_last($name)]} { + return reflog_last($name) + } + + set last {} + if {[catch {set last [file mtime [gitdir $name]]}] + && ![catch {set g [open [gitdir logs $name] r]}]} { + fconfigure $g -translation binary + while {[gets $g line] >= 0} { + if {[regexp {> ([1-9][0-9]*) } $line line when]} { + set last $when + } + } + close $g + } + + if {$last ne {}} { + set last [clock format $last -format {%a %b %e %H:%M:%S %Y}] + } + set reflog_last($name) $last + return $last +} + method _position_tooltip {} { set max_h [lindex [split [$tooltip_t index end] .] 0] set max_w 0 From 350a35f0a17af071af3f6f76d9fc6f63265b23d2 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 25 Jul 2007 03:44:50 -0400 Subject: [PATCH 094/131] git-gui: Replace merge dialog with our revision picker widget Now that we only support merging one branch we can offer the user a better user interface experience by allowing them to select the revision they want to merge through our revision picking widget. This change neatly solves the problem of locating a branch out of a sea of 200 tracking branches, and of dealing with very long branch names that all have a common prefix. Signed-off-by: Shawn O. Pearce --- lib/merge.tcl | 81 +++++++-------------------------------------------- 1 file changed, 11 insertions(+), 70 deletions(-) diff --git a/lib/merge.tcl b/lib/merge.tcl index e5a752507b..f8d92b320e 100644 --- a/lib/merge.tcl +++ b/lib/merge.tcl @@ -4,8 +4,7 @@ class merge { field w ; # top level window -field w_list ; # widget of available branches -field list ; # list of available branches +field w_rev ; # mega-widget to pick the revision to merge method _can_merge {} { global HEAD commit_type file_states @@ -68,11 +67,10 @@ You should complete the current commit before starting a merge. Doing so will h } method _rev {} { - set i [$w_list curselection] - if {$i >= 0} { - return [lindex [lindex $list $i] 0] + if {[catch {$w_rev commit_or_die}]} { + return {} } - return {} + return [$w_rev get] } method _visualize {} { @@ -121,38 +119,6 @@ constructor dialog {} { return } - set fmt {list %(objectname) %(*objectname) %(refname) %(subject)} - set fr_fd [git_read for-each-ref \ - --tcl \ - --format=$fmt \ - refs/heads \ - refs/remotes \ - refs/tags \ - ] - fconfigure $fr_fd -translation binary - while {[gets $fr_fd line] > 0} { - set line [eval $line] - set ref [lindex $line 2] - regsub ^refs/(heads|remotes|tags)/ $ref {} ref - set subj($ref) [lindex $line 3] - lappend sha1([lindex $line 0]) $ref - if {[lindex $line 1] ne {}} { - lappend sha1([lindex $line 1]) $ref - } - } - close $fr_fd - - set list [list] - set fr_fd [git_read rev-list --all --not HEAD] - while {[gets $fr_fd line] > 0} { - if {[catch {set ref $sha1($line)}]} continue - foreach n $ref { - lappend list [list $n $line] - } - } - close $fr_fd - set list [lsort -unique $list] - make_toplevel top w wm title $top "[appname] ([reponame]): Merge" if {$top ne {.}} { @@ -178,39 +144,11 @@ constructor dialog {} { pack $w.buttons.cancel -side right -padx 5 pack $w.buttons -side bottom -fill x -pady 10 -padx 10 - labelframe $w.source -text {Source Branches} - set w_list $w.source.l - listbox $w_list \ - -height 10 \ - -width 70 \ - -font font_diff \ - -selectmode browse \ - -yscrollcommand [list $w.source.sby set] - scrollbar $w.source.sby -command [list $w_list yview] - pack $w.source.sby -side right -fill y - pack $w_list -side left -fill both -expand 1 - pack $w.source -fill both -expand 1 -pady 5 -padx 5 - - foreach ref $list { - set n [lindex $ref 0] - if {[string length $n] > 20} { - set n "[string range $n 0 16]..." - } - $w_list insert end [format {%s %-20s %s} \ - [string range [lindex $ref 1] 0 5] \ - $n \ - $subj([lindex $ref 0])] - } - - bind $w_list [list event generate %W ] - bind $w_list [list event generate %W ] - bind $w_list [list event generate %W ] - bind $w_list [list event generate %W ] - bind $w_list [list event generate %W ] - bind $w_list [list event generate %W ] - bind $w_list $_visualize + set w_rev [::choose_rev::new_unmerged $w.rev {Revision To Merge}] + pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5 bind $w <$M1B-Key-Return> $_start + bind $w $_start bind $w [cb _visible] bind $w [cb _cancel] wm protocol $w WM_DELETE_WINDOW [cb _cancel] @@ -219,7 +157,10 @@ constructor dialog {} { method _visible {} { grab $w - focus $w_list + if {[is_config_true gui.matchtrackingbranch]} { + $w_rev pick_tracking_branch + } + $w_rev focus_filter } method _cancel {} { From 9feefbd2d285f9af629cff9075eff06cf33d9de9 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 25 Jul 2007 04:32:18 -0400 Subject: [PATCH 095/131] git-gui: Cleanup bindings within merge dialog Misc. code cleanups in the merge dialog's binding setup and action button creation. Signed-off-by: Shawn O. Pearce --- lib/merge.tcl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/merge.tcl b/lib/merge.tcl index f8d92b320e..62434ff310 100644 --- a/lib/merge.tcl +++ b/lib/merge.tcl @@ -125,7 +125,6 @@ constructor dialog {} { wm geometry $top "+[winfo rootx .]+[winfo rooty .]" } - set _visualize [cb _visualize] set _start [cb _start] label $w.header \ @@ -134,10 +133,14 @@ constructor dialog {} { pack $w.header -side top -fill x frame $w.buttons - button $w.buttons.visualize -text Visualize -command $_visualize + button $w.buttons.visualize \ + -text Visualize \ + -command [cb _visualize] pack $w.buttons.visualize -side left - button $w.buttons.create -text Merge -command $_start - pack $w.buttons.create -side right + button $w.buttons.merge \ + -text Merge \ + -command $_start + pack $w.buttons.merge -side right button $w.buttons.cancel \ -text {Cancel} \ -command [cb _cancel] @@ -149,9 +152,10 @@ constructor dialog {} { bind $w <$M1B-Key-Return> $_start bind $w $_start - bind $w [cb _visible] bind $w [cb _cancel] wm protocol $w WM_DELETE_WINDOW [cb _cancel] + + bind $w.buttons.merge [cb _visible] tkwait window $w } From ead49f5a4f6c87e5dc61ed5daaeda1bae7644d05 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 25 Jul 2007 04:54:53 -0400 Subject: [PATCH 096/131] git-gui: Format tracking branch merges as though they were pulls If we are merging a tracking branch we know exactly what remote URL that branch is fetched from, and what its name is on that remote repository. In this case we can setup a merge message that looks just like a standard `git-pull $remote $branch` operation by filling out FETCH_HEAD before we start git-merge, and then run git-merge just like git-pull does. I think the result of this behavior is that merges look a lot nicer when the came off of local tracking branches, because they no longer say "commit 'origin/...'" to describe the commit being merged but instead now mention the specific repository we fetched those commits from. Signed-off-by: Shawn O. Pearce --- lib/merge.tcl | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/merge.tcl b/lib/merge.tcl index 62434ff310..c8b486710a 100644 --- a/lib/merge.tcl +++ b/lib/merge.tcl @@ -81,17 +81,41 @@ method _visualize {} { } method _start {} { - global HEAD current_branch + global HEAD current_branch remote_url set name [_rev $this] if {$name eq {}} { return } - set cmd [list git merge $name] - set msg "Merging $current_branch and $name" + set spec [$w_rev get_tracking_branch] + set cmit [$w_rev get_commit] + set cmd [list git] + lappend cmd merge + lappend cmd --strategy=recursive + + set fh [open [gitdir FETCH_HEAD] w] + fconfigure $fh -translation lf + if {$spec eq {}} { + set remote . + set branch $name + set stitle $branch + } else { + set remote $remote_url([lindex $spec 1]) + set branch [lindex $spec 2] + set stitle "$branch of $remote" + } + regsub ^refs/heads/ $branch {} branch + puts $fh "$cmit\t\tbranch '$branch' of $remote" + close $fh + + lappend cmd [git fmt-merge-msg <[gitdir FETCH_HEAD]] + lappend cmd HEAD + lappend cmd $cmit + + set msg "Merging $current_branch and $stitle" ui_status "$msg..." - set cons [console::new "Merge" $cmd] + set cons [console::new "Merge" "merge $stitle"] console::exec $cons $cmd [cb _finish $cons] wm protocol $w WM_DELETE_WINDOW {} From bc318ea86d3ecd4074ecde3122b1e65f84cf9996 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 25 Jul 2007 05:02:38 -0400 Subject: [PATCH 097/131] git-gui: Remove usernames from absolute SSH urls during merging If we are being asked to merge a tracking branch that comes from a remote repository accessed by the very common SSH URL format of "user@host:/path/to/repo" then we really don't need the username as part of the merge message, it only clutters up the history and makes things more confusing. So we instead clip the username part off if the local filesystem path is absolute, as its probably not going to be an ambiguous URL even when it is missing the username. On the other hand we cannot clip the username off if the URL is not absolute, because in such cases (e.g. "user@host:myrepo") the directory that the repository path is resolved in is relative to the user's home directory, and the username becomes important. Signed-off-by: Shawn O. Pearce --- lib/merge.tcl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/merge.tcl b/lib/merge.tcl index c8b486710a..148d859c5c 100644 --- a/lib/merge.tcl +++ b/lib/merge.tcl @@ -102,6 +102,9 @@ method _start {} { set stitle $branch } else { set remote $remote_url([lindex $spec 1]) + if {[regexp {^[^:@]*@[^:]*:/} $remote]} { + regsub {^[^:@]*@} $remote {} remote + } set branch [lindex $spec 2] set stitle "$branch of $remote" } From 4eb994733d75d40cab87e7b4736166cf33e7787a Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Wed, 25 Jul 2007 12:08:17 +0200 Subject: [PATCH 098/131] Document --unified/-U option Signed-off-by: Robin Rosenberg Signed-off-by: Junio C Hamano --- Documentation/diff-options.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 3d2b9d0a06..82165763ba 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -4,6 +4,13 @@ -u:: Synonym for "-p". +-U:: + Shorthand for "--unified=". + +--unified=:: + Generate diffs with lines of context instead of + the usual three. Implies "-p". + --raw:: Generate the raw format. From ceff079bdcaebb67b0379a1036a32b4dfebb6012 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 25 Jul 2007 15:32:22 -0700 Subject: [PATCH 099/131] Make sure git-stash works from subdirectory. We say "SUBDIRECTORY_OK" but we did not chdir to toplevel; this is fine as long as everything we use can be started from a subdirectory, but unfortunately "merge-recursive" is not one of the programs you can safely use from a subdirectory. Signed-off-by: Junio C Hamano --- git-stash.sh | 1 + t/t3903-stash.sh | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/git-stash.sh b/git-stash.sh index de13dd1812..d9cd42d4b3 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -6,6 +6,7 @@ USAGE='[ | list | show | apply | clear]' SUBDIRECTORY_OK=Yes . git-sh-setup require_work_tree +cd_to_toplevel TMP="$GIT_DIR/.git-stash.$$" trap 'rm -f "$TMP-*"' 0 diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 392ac1c5c5..9a9a250d2c 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -66,4 +66,11 @@ test_expect_success 'apply stashed changes (including index)' ' test 1 = $(git show HEAD:file) ' +test_expect_success 'unstashing in a subdirectory' ' + git reset --hard HEAD && + mkdir subdir && + cd subdir && + git stash apply +' + test_done From 887c5266d64e0a724986af1610985bb42af5bd47 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 25 Jul 2007 15:49:55 -0700 Subject: [PATCH 100/131] gitweb: fix broken snapshot Recent updates to snapshot code had a typo that broke the command line to invoke underlying "git archive" command. This is a simple typofix for it. Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 0acd0cafb3..b381692119 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -4343,7 +4343,7 @@ sub git_snapshot { my $cmd; $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}"; $cmd = "$git_command archive " . - "--format=$known_snapshot_formats{$format}{'format'}" . + "--format=$known_snapshot_formats{$format}{'format'} " . "--prefix=\'$name\'/ $hash"; if (exists $known_snapshot_formats{$format}{'compressor'}) { $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}}; From 537601ac74db2d93665b20a67ba05851703bb2c3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 25 Jul 2007 15:51:26 -0700 Subject: [PATCH 101/131] git-submodule module_name: avoid using unwieldy "value_regexp" feature. "module_name $path" function wants to look up a configuration variable "submodule..path" whose value is $path, and return the found. "git-config --get-regexp" is the natural thing to use for this, but (1) its value matching has an unfortunate "feature" that takes leading '!' specially, and (2) its output needs to be parsed with sed to extract part anyway. This changes the call to "git-config --get-regexp" not to use the value-regexp part, and moves the "pick the one whose value is $path" part to the downstream sed. Signed-off-by: Junio C Hamano --- git-submodule.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 1f0cb99dcb..afbaec7a74 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -46,8 +46,11 @@ get_repo_base() { # module_name() { - name=$(GIT_CONFIG=.gitmodules git config --get-regexp '^submodule\..*\.path$' "$1" | - sed -nre 's/^submodule\.(.+)\.path .+$/\1/p') + # Do we have "submodule..path = $1" defined in .gitmodules file? + re=$(printf '%s' "$1" | sed -e 's/\([^a-zA-Z0-9_]\)/\\\1/g') + name=$( GIT_CONFIG=.gitmodules \ + git config --get-regexp '^submodule\..*\.path$' | + sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' ) test -z "$name" && die "No submodule mapping found in .gitmodules for path '$path'" echo "$name" From b2d2d16af7ff686fb96d344daaf49653fd67366a Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 25 Jul 2007 09:31:38 +0200 Subject: [PATCH 102/131] git-p4: Fix p4 user cache population on Windows. Fall back to USERPROFILE if HOME isn't set. Signed-off-by: Simon Hausmann Signed-off-by: Marius Storm-Olsen Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index e3404ca853..1f5a56ee7f 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -901,7 +901,8 @@ class P4Sync(Command): % (labelDetails["label"], change)) def getUserCacheFilename(self): - return os.environ["HOME"] + "/.gitp4-usercache.txt" + home = os.environ.get("HOME", os.environ.get("USERPROFILE")) + return home + "/.gitp4-usercache.txt" def getUserMapFromPerforceServer(self): if self.userMapFromPerforceServer: From 1a44be9a0ff6fa623ff6061992f5ad1831dc7cab Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 25 Jul 2007 16:13:55 -0700 Subject: [PATCH 103/131] git-submodule: remove redundant call to git-describe The code to find a more descriptive name given a commit in a submodule were improved in bffe71f, but it forgot to remove the older logic the patch replaced. Signed-off-by: Junio C Hamano --- git-submodule.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/git-submodule.sh b/git-submodule.sh index afbaec7a74..2cfeaddbc2 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -236,7 +236,6 @@ modules_list() say "-$sha1 $path" continue; fi - revname=$(unset GIT_DIR && cd "$path" && git describe --tags $sha1) set_name_rev "$path" "$sha1" if git diff-files --quiet -- "$path" then From d58e8d34b019d435b424811c6f972910dfac6f55 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 25 Jul 2007 16:22:55 -0700 Subject: [PATCH 104/131] When locking in a symlinked repository, try to lock the original. In a working tree prepared in new-workdir (in contrib/), some files in .git/ directory are symbolic links to the original repository. The usual sequence of lock-write-rename would break the symbolic link. Ideally we should resolve relative symbolic link with maxdepth, but I do not want to risk too elaborate patch before 1.5.3 release, so this is a minimum and trivially obvious fix. new-workdir creates its symbolic links absolute, and does not link from a symlinked workdir, so this fix should suffice for now. Signed-off-by: Junio C Hamano --- lockfile.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lockfile.c b/lockfile.c index fb8f13bbb9..9202472498 100644 --- a/lockfile.c +++ b/lockfile.c @@ -28,6 +28,19 @@ static void remove_lock_file_on_signal(int signo) static int lock_file(struct lock_file *lk, const char *path) { int fd; + struct stat st; + + if ((!lstat(path, &st)) && S_ISLNK(st.st_mode)) { + ssize_t sz; + static char target[PATH_MAX]; + sz = readlink(path, target, sizeof(target)); + if (sz < 0) + warning("Cannot readlink %s", path); + else if (target[0] != '/') + warning("Cannot lock target of relative symlink %s", path); + else + path = target; + } sprintf(lk->filename, "%s.lock", path); fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666); if (0 <= fd) { From e7a7be8831b159b9a7331b34c3ec6915d4a72190 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 25 Jul 2007 21:34:53 -0700 Subject: [PATCH 105/131] git_mkstemp(): be careful not to overflow the path buffer. If user's TMPDIR is insanely long, return negative after setting errno to ENAMETOOLONG, pretending that the underlying mkstemp() choked on a temporary file path that is too long. Signed-off-by: Junio C Hamano --- diff.c | 2 +- path.c | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/diff.c b/diff.c index cd6b0c4e0b..a5fc56bdad 100644 --- a/diff.c +++ b/diff.c @@ -1695,7 +1695,7 @@ static void prep_temp_blob(struct diff_tempfile *temp, fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX"); if (fd < 0) - die("unable to create temp-file"); + die("unable to create temp-file: %s", strerror(errno)); if (write_in_full(fd, blob, size) != size) die("unable to write temp-file"); close(fd); diff --git a/path.c b/path.c index c4ce96236a..dfff41f626 100644 --- a/path.c +++ b/path.c @@ -71,21 +71,17 @@ char *git_path(const char *fmt, ...) /* git_mkstemp() - create tmp file honoring TMPDIR variable */ int git_mkstemp(char *path, size_t len, const char *template) { - char *env, *pch = path; + const char *tmp; + size_t n; - if ((env = getenv("TMPDIR")) == NULL) { - strcpy(pch, "/tmp/"); - len -= 5; - pch += 5; - } else { - size_t n = snprintf(pch, len, "%s/", env); - - len -= n; - pch += n; + tmp = getenv("TMPDIR"); + if (!tmp) + tmp = "/tmp"; + n = snprintf(path, len, "%s/%s", tmp, template); + if (len <= n) { + errno = ENAMETOOLONG; + return -1; } - - strlcpy(pch, template, len); - return mkstemp(path); } From b87841e1645f900fbec0a937a45f98b70b5684ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 25 Jul 2007 23:14:54 -0400 Subject: [PATCH 106/131] git-write-tree should not crash if prefix does not exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin-write-tree.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin-write-tree.c b/builtin-write-tree.c index 391de53972..88f34ba7d6 100644 --- a/builtin-write-tree.c +++ b/builtin-write-tree.c @@ -52,6 +52,8 @@ int write_tree(unsigned char *sha1, int missing_ok, const char *prefix) if (prefix) { struct cache_tree *subtree = cache_tree_find(active_cache_tree, prefix); + if (!subtree) + die("git-write-tree: prefix %s not found", prefix); hashcpy(sha1, subtree->sha1); } else From 91e1ee776283a238cc135fbbfc3f812492bcbd86 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 26 Jul 2007 07:35:51 +0100 Subject: [PATCH 107/131] rebase -i: fix overzealous output redirection When squashing, you no longer saw what the editor had to say to you after commit 'Shut "git rebase -i" up when no --verbose was given' (if you used a console based editor, at least). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 93289c050a..9a88335c5f 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -250,10 +250,12 @@ do_next () { case "$(peek_next_command)" in squash) EDIT_COMMIT= + USE_OUTPUT=output cp "$MSG" "$SQUASH_MSG" ;; *) EDIT_COMMIT=-e + USE_OUTPUT= test -f "$SQUASH_MSG" && rm "$SQUASH_MSG" esac @@ -267,7 +269,7 @@ do_next () { # This is like --amend, but with a different message eval "$author_script" export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE - output git commit -F "$MSG" $EDIT_COMMIT + $USE_OUTPUT git commit -F "$MSG" $EDIT_COMMIT ;; t) cp "$MSG" "$GIT_DIR"/MERGE_MSG From 654a7ccc56f5dee3d11fbf6e928c14402c7495de Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 25 Jul 2007 23:45:42 -0700 Subject: [PATCH 108/131] Update description of -z option. The NUL you see in "git log" (without diff) output are between records, not at the end of each record. Signed-off-by: Junio C Hamano --- Documentation/diff-options.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 82165763ba..228ccaf10a 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -43,7 +43,9 @@ Synonym for "-p --stat". -z:: - \0 line termination on output + NUL-line termination on output. This affects the --raw + output field terminator. Also output from commands such + as "git-log" will be delimited with NUL between commits. --name-only:: Show only names of changed files. From 005a2f4e6df7060561817828d4fa4245f87ccadf Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Thu, 26 Jul 2007 22:36:39 +1000 Subject: [PATCH 109/131] gitk: Fix bugs in the Find function This fixes the problem reported by Brian Downing where searching for a string that doesn't exist would give a Tcl error. The basic problem was that we weren't reading the data for the last commit since it wasn't terminated with a null. This effectively adds a null on the end (if there isn't one already) to make sure we process the last commit. This also makes the yellow background behind instances of the search string appear more consistently, and fixes a bug where the "/" key would just find the same commit again and again instead of advancing. Signed-off-by: Paul Mackerras --- gitk | 88 ++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 35 deletions(-) diff --git a/gitk b/gitk index 5cfb1cc391..f74ce51379 100755 --- a/gitk +++ b/gitk @@ -139,6 +139,10 @@ proc getcommitlines {fd view} { global vparentlist vdisporder vcmitlisted set stuff [read $fd 500000] + # git log doesn't terminate the last commit with a null... + if {$stuff == {} && $leftover($view) ne {} && [eof $fd]} { + set stuff "\0" + } if {$stuff == {}} { if {![eof $fd]} { return 1 @@ -2157,7 +2161,7 @@ proc readfhighlight {} { proc find_change {name ix op} { global nhighlights mainfont boldnamerows - global findstring findpattern findtype markingmatches + global findstring findpattern findtype # delete previous highlights, if any foreach row $boldnamerows { @@ -2172,7 +2176,6 @@ proc find_change {name ix op} { $findstring] set findpattern "*$e*" } - set markingmatches [expr {$findstring ne {}}] drawvisible } @@ -2218,26 +2221,32 @@ proc askfindhighlight {row id} { } } if {$markingmatches} { - markrowmatches $row [lindex $info 0] [lindex $info 1] + markrowmatches $row $id } } set nhighlights($row) $isbold } -proc markrowmatches {row headline author} { - global canv canv2 linehtag linentag +proc markrowmatches {row id} { + global canv canv2 linehtag linentag commitinfo findloc + set headline [lindex $commitinfo($id) 0] + set author [lindex $commitinfo($id) 1] $canv delete match$row $canv2 delete match$row - set m [findmatches $headline] - if {$m ne {}} { - markmatches $canv $row $headline $linehtag($row) $m \ - [$canv itemcget $linehtag($row) -font] + if {$findloc eq "All fields" || $findloc eq "Headline"} { + set m [findmatches $headline] + if {$m ne {}} { + markmatches $canv $row $headline $linehtag($row) $m \ + [$canv itemcget $linehtag($row) -font] $row + } } - set m [findmatches $author] - if {$m ne {}} { - markmatches $canv2 $row $author $linentag($row) $m \ - [$canv2 itemcget $linentag($row) -font] + if {$findloc eq "All fields" || $findloc eq "Author"} { + set m [findmatches $author] + if {$m ne {}} { + markmatches $canv2 $row $author $linentag($row) $m \ + [$canv2 itemcget $linentag($row) -font] $row + } } } @@ -3406,7 +3415,7 @@ proc drawcmittext {id row col} { global linespc canv canv2 canv3 canvy0 fgcolor curview global commitlisted commitinfo rowidlist parentlist global rowtextx idpos idtags idheads idotherrefs - global linehtag linentag linedtag markingmatches + global linehtag linentag linedtag global mainfont canvxmax boldrows boldnamerows fgcolor nullid nullid2 # listed is 0 for boundary, 1 for normal, 2 for left, 3 for right @@ -3483,9 +3492,6 @@ proc drawcmittext {id row col} { set linedtag($row) [$canv3 create text 3 $y -anchor w -fill $fgcolor \ -text $date -font $mainfont -tags text] set xr [expr {$xt + [font measure $mainfont $headline]}] - if {$markingmatches} { - markrowmatches $row $headline $name - } if {$xr > $canvxmax} { set canvxmax $xr setcanvscroll @@ -3494,7 +3500,7 @@ proc drawcmittext {id row col} { proc drawcmitrow {row} { global displayorder rowidlist - global iddrawn + global iddrawn markingmatches global commitinfo parentlist numcommits global filehighlight fhighlights findstring nhighlights global hlview vhighlights @@ -3515,18 +3521,22 @@ proc drawcmitrow {row} { if {$highlight_related ne "None" && ![info exists rhighlights($row)]} { askrelhighlight $row $id } - if {[info exists iddrawn($id)]} return - set col [lsearch -exact [lindex $rowidlist $row] $id] - if {$col < 0} { - puts "oops, row $row id $id not in list" - return + if {![info exists iddrawn($id)]} { + set col [lsearch -exact [lindex $rowidlist $row] $id] + if {$col < 0} { + puts "oops, row $row id $id not in list" + return + } + if {![info exists commitinfo($id)]} { + getcommit $id + } + assigncolor $id + drawcmittext $id $row $col + set iddrawn($id) 1 } - if {![info exists commitinfo($id)]} { - getcommit $id + if {$markingmatches} { + markrowmatches $row $id } - assigncolor $id - drawcmittext $id $row $col - set iddrawn($id) 1 } proc drawcommits {row {endrow {}}} { @@ -4044,7 +4054,6 @@ proc dofind {{rev 0}} { if {!$rev} { run findmore } else { - set findcurline $findstartline if {$findcurline == 0} { set findcurline $numcommits } @@ -4079,7 +4088,7 @@ proc findprev {} { proc findmore {} { global commitdata commitinfo numcommits findstring findpattern findloc - global findstartline findcurline markingmatches displayorder + global findstartline findcurline displayorder set fldtypes {Headline Author Date Committer CDate Comments} set l [expr {$findcurline + 1}] @@ -4097,6 +4106,8 @@ proc findmore {} { set last 0 for {} {$l < $lim} {incr l} { set id [lindex $displayorder $l] + # shouldn't happen unless git log doesn't give all the commits... + if {![info exists commitdata($id)]} continue if {![doesmatch $commitdata($id)]} continue if {![info exists commitinfo($id)]} { getcommit $id @@ -4105,7 +4116,6 @@ proc findmore {} { foreach f $info ty $fldtypes { if {($findloc eq "All fields" || $findloc eq $ty) && [doesmatch $f]} { - set markingmatches 1 findselectline $l notbusy finding return 0 @@ -4124,7 +4134,7 @@ proc findmore {} { proc findmorerev {} { global commitdata commitinfo numcommits findstring findpattern findloc - global findstartline findcurline markingmatches displayorder + global findstartline findcurline displayorder set fldtypes {Headline Author Date Committer CDate Comments} set l $findcurline @@ -4151,7 +4161,6 @@ proc findmorerev {} { foreach f $info ty $fldtypes { if {($findloc eq "All fields" || $findloc eq $ty) && [doesmatch $f]} { - set markingmatches 1 findselectline $l notbusy finding return 0 @@ -4169,7 +4178,10 @@ proc findmorerev {} { } proc findselectline {l} { - global findloc commentend ctext + global findloc commentend ctext findcurline markingmatches + + set markingmatches 1 + set findcurline $l selectline $l 1 if {$findloc == "All fields" || $findloc == "Comments"} { # highlight the matches in the comments @@ -4181,10 +4193,13 @@ proc findselectline {l} { $ctext tag add found "1.0 + $start c" "1.0 + $end c" } } + drawvisible } # mark the bits of a headline or author that match a find string -proc markmatches {canv l str tag matches font} { +proc markmatches {canv l str tag matches font row} { + global selectedline + set bbox [$canv bbox $tag] set x0 [lindex $bbox 0] set y0 [lindex $bbox 1] @@ -4199,6 +4214,9 @@ proc markmatches {canv l str tag matches font} { [expr {$x0+$xlen+2}] $y1 \ -outline {} -tags [list match$l matches] -fill yellow] $canv lower $t + if {[info exists selectedline] && $row == $selectedline} { + $canv raise $t secsel + } } } From 383e45cec40a0b881e59e44e011c410218ef476a Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Thu, 26 Jul 2007 16:34:59 -0400 Subject: [PATCH 110/131] Document commit.template configuration variable. Add it to the list in config.txt and explicitly say that the --template option to git-commit overrides the configuration variable. Signed-off-by: Junio C Hamano --- Documentation/config.txt | 3 +++ Documentation/git-commit.txt | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index dd98d95d97..3135cb7a66 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -393,6 +393,9 @@ color.status.:: or `untracked` (files which are not tracked by git). The values of these variables may be specified as in color.branch.. +commit.template:: + Specify a file to use as the template for new commit messages. + diff.renameLimit:: The number of files to consider when performing the copy/rename detection; equivalent to the git diff option '-l'. diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 3f36c6782f..627994eb97 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -78,9 +78,8 @@ OPTIONS Use the contents of the given file as the initial version of the commit message. The editor is invoked and you can make subsequent changes. If a message is specified using - the `-m` or `-F` options, this option has no effect. The - template file may also be specified using the `commit.template` - configuration variable. + the `-m` or `-F` options, this option has no effect. This + overrides the `commit.template` configuration variable. -s|--signoff:: Add Signed-off-by line at the end of the commit message. From 7ab3cc70a6aad2e4f8ccaa98e5520aa126eaef8f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 26 Jul 2007 23:24:28 -0700 Subject: [PATCH 111/131] git-stash: do not remove a ref by hand. Somebody on #git noticed that "git stash clear" left a packed ref behind for ref/stash. Signed-off-by: Junio C Hamano --- git-stash.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/git-stash.sh b/git-stash.sh index d9cd42d4b3..f90dffd4ca 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -19,9 +19,10 @@ no_changes () { } clear_stash () { - logfile="$GIT_DIR/logs/$ref_stash" && - mkdir -p "$(dirname "$logfile")" && - : >"$logfile" + if current=$(git rev-parse --verify $ref_stash 2>/dev/null) + then + git update-ref -d refs/stash $current + fi } save_stash () { From 1e0a92fdf74caa0bf850f73e284818473c8f76e0 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 27 Jul 2007 02:30:15 -0400 Subject: [PATCH 112/131] git-gui: Don't kill modified commit message buffer with merge templates If the user is in the middle of a merge and has already started to modify their commit message we were losing the user's changes when they pressed 'Rescan' after resolving issues or making changes in the working directory. The problem here was our background timer that saves the commit message buffer. It marks the commit message buffer as not being modified when it writes it out to disk, so during the rescan we assumed the buffer should be replaced with what we read from the MERGE_MSG file. So we now only read these files from .git if we have a valid backup file. Since we clear it on commit this will only have an impact while the user is actively editing the current commit. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index a38293a347..f87b955fdb 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -829,8 +829,9 @@ proc rescan {after {honor_trustmtime 1}} { array unset file_states - if {![$ui_comm edit modified] - || [string trim [$ui_comm get 0.0 end]] eq {}} { + if {!$::GITGUI_BCK_exists && + (![$ui_comm edit modified] + || [string trim [$ui_comm get 0.0 end]] eq {})} { if {[string match amend* $commit_type]} { } elseif {[load_message GITGUI_MSG]} { } elseif {[load_message MERGE_MSG]} { From fb47cfbd59b12ea67e1a5c6a9d0bd665fcae4581 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 24 Jul 2007 21:43:09 +0100 Subject: [PATCH 113/131] rebase -i: fix interrupted squashing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a squashing merge failed, the first commit would not be replaced, due to "git reset --soft" being called with an unmerged index. Noticed by Uwe Kleine-König. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 2 +- t/t3404-rebase-interactive.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 9a88335c5f..c987311499 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -260,8 +260,8 @@ do_next () { esac failed=f - pick_one -n $sha1 || failed=t output git reset --soft HEAD^ + pick_one -n $sha1 || failed=t author_script=$(get_author_ident_from_commit $sha1) echo "$author_script" > "$DOTEST"/author-script case $failed in diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 8206436cc7..817f614cde 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -221,4 +221,34 @@ test_expect_success 'multi-squash only fires up editor once' ' test 1 = $(git show | grep ONCE | wc -l) ' +test_expect_success 'squash works as expected' ' + for n in one two three four + do + echo $n >> file$n && + git add file$n && + git commit -m $n + done && + one=$(git rev-parse HEAD~3) && + FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 && + test $one = $(git rev-parse HEAD~2) +' + +test_expect_success 'interrupted squash works as expected' ' + for n in one two three four + do + echo $n >> conflict && + git add conflict && + git commit -m $n + done && + one=$(git rev-parse HEAD~3) && + ! FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 && + (echo one; echo two; echo four) > conflict && + git add conflict && + ! git rebase --continue && + echo resolved > conflict && + git add conflict && + git rebase --continue && + test $one = $(git rev-parse HEAD~2) +' + test_done From f12e925ac23ad6169e046cfe05b8438a1611ad58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=97=E3=82=89=E3=81=84=E3=81=97=E3=81=AA=E3=81=AA?= =?UTF-8?q?=E3=81=93?= Date: Sat, 28 Jul 2007 10:44:48 +0900 Subject: [PATCH 114/131] git-stash: Make sure reflog is created for refs/stash Earlier commit 7ab3cc70 fixed "stash clear" but broke save_stash, because it forgot to make sure the reflog file exists before saving. Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano --- git-stash.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/git-stash.sh b/git-stash.sh index f90dffd4ca..0073e9df5f 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -36,6 +36,9 @@ save_stash () { test -f "$GIT_DIR/logs/$ref_stash" || clear_stash || die "Cannot initialize stash" + # Make sure the reflog for stash is kept. + : >>"$GIT_DIR/logs/$ref_stash" + # state of the base commit if b_commit=$(git rev-parse --verify HEAD) then From cbeaccc316affa2e0fb0b60f569d5da9bf444881 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 27 Jul 2007 23:41:31 -0700 Subject: [PATCH 115/131] Fix git-stash apply --index Two bugs that made the command practically unusable were fixed with this. - A stash created with a clean index does not have any difference between the base tree and the index tree. Trying to apply the diff between them to the index would error out with "No changes". Even when the user asked to unstash with --index, do not bother with --index action if the base tree and the index tree match. - After successfully performing the working tree merge, the index was reloaded from an earlier state of unstashed index with "read-tree"; this left all the paths cache dirty. By moving the call to git-status after this read-tree, match the cached stat information in the index. Signed-off-by: Junio C Hamano --- git-stash.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/git-stash.sh b/git-stash.sh index 0073e9df5f..873e7be6ad 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -128,19 +128,24 @@ apply_stash () { c_tree=$(git write-tree) || die 'Cannot apply a stash in the middle of a merge' + # stash records the work tree, and is a merge between the + # base commit (first parent) and the index tree (second parent). s=$(git rev-parse --revs-only --no-flags --default $ref_stash "$@") && w_tree=$(git rev-parse --verify "$s:") && - b_tree=$(git rev-parse --verify "$s^:") || + b_tree=$(git rev-parse --verify "$s^1:") && + i_tree=$(git rev-parse --verify "$s^2:") || die "$*: no valid stashed state found" - test -z "$unstash_index" || { + unstashed_index_tree= + if test -n "$unstash_index" && test "$b_tree" != "$i_tree" + then git diff --binary $s^2^..$s^2 | git apply --cached test $? -ne 0 && die 'Conflicts in index. Try without --index.' unstashed_index_tree=$(git-write-tree) || die 'Could not save index tree' git reset - } + fi eval " GITHEAD_$w_tree='Stashed changes' && @@ -157,13 +162,19 @@ apply_stash () { git read-tree --reset $c_tree && git update-index --add --stdin <"$a" || die "Cannot unstage modified files" - git-status rm -f "$a" - test -z "$unstash_index" || git read-tree $unstashed_index_tree + if test -n "$unstashed_index_tree" + then + git read-tree "$unstashed_index_tree" + fi + git status || : else # Merge conflict; keep the exit status from merge-recursive status=$? - test -z "$unstash_index" || echo 'Index was not unstashed.' >&2 + if test -n "$unstash_index" + then + echo >&2 'Index was not unstashed.' + fi exit $status fi } From 83b3df7d582429d9036f34d2c95abfff7bf0ab24 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 27 Jul 2007 23:51:45 -0700 Subject: [PATCH 116/131] git-stash apply --index: optimize postprocessing Originally, "apply --index" codepath was bolted on to the "update working tree files and index, but then revert the changes we make to the index except for added files so that we do not forget about them" codepath, almost as an afterthought. Because "apply --index" first prepares the final index state upfront, "revert except the added paths" postprocessing does not have to be done. Signed-off-by: Junio C Hamano --- git-stash.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/git-stash.sh b/git-stash.sh index 873e7be6ad..30425ce6df 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -157,15 +157,16 @@ apply_stash () { if git-merge-recursive $b_tree -- $c_tree $w_tree then # No conflict - a="$TMP-added" && - git diff --cached --name-only --diff-filter=A $c_tree >"$a" && - git read-tree --reset $c_tree && - git update-index --add --stdin <"$a" || - die "Cannot unstage modified files" - rm -f "$a" if test -n "$unstashed_index_tree" then git read-tree "$unstashed_index_tree" + else + a="$TMP-added" && + git diff --cached --name-only --diff-filter=A $c_tree >"$a" && + git read-tree --reset $c_tree && + git update-index --add --stdin <"$a" || + die "Cannot unstage modified files" + rm -f "$a" fi git status || : else From 90ae710e0b642b177d44df4528966c7ae37ebf5f Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 28 Jul 2007 20:24:27 -0400 Subject: [PATCH 117/131] Documentation/git-diff: remove -r from --name-status example Calling 'git-diff --name-status' will recursively show any changes already, and it has for quite some time (at least as far back as v1.4.1). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/git-diff.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 639b969315..b1f5e7f93f 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -102,17 +102,14 @@ Limiting the diff output:: + ------------ $ git diff --diff-filter=MRC <1> -$ git diff --name-status -r <2> +$ git diff --name-status <2> $ git diff arch/i386 include/asm-i386 <3> ------------ + <1> show only modification, rename and copy, but not addition nor deletion. <2> show only names and the nature of change, but not actual -diff output. --name-status disables usual patch generation -which in turn also disables recursive behavior, so without -r -you would only see the directory name if there is a change in a -file in a subdirectory. +diff output. <3> limit diff output to named subtrees. Munging the diff output:: From 01ac1e38dbb1ae3ad3c4bbea60a9c0855606ae11 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 28 Jul 2007 16:27:31 +0200 Subject: [PATCH 118/131] gitweb: Show submodule entries in the 'tree' view Add S_ISGITLINK subroutine and S_IFGITLINK, S_IFINVALID constants. Add support for "commit" (submodule) entries in the tree object to mode_str ('m---------', following cgit), file_type and file_type_long ('submodule') subroutines. There is only link to the history of submodule entry in the supermodule (current repository) for now, because gitweb doesn't know where to search for submodule repository objects. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index b381692119..1aceedec8e 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -890,11 +890,25 @@ sub age_string { return $age_str; } +use constant { + S_IFINVALID => 0030000, + S_IFGITLINK => 0160000, +}; + +# submodule/subproject, a commit object reference +sub S_ISGITLINK($) { + my $mode = shift; + + return (($mode & S_IFMT) == S_IFGITLINK) +} + # convert file mode in octal to symbolic file mode string sub mode_str { my $mode = oct shift; - if (S_ISDIR($mode & S_IFMT)) { + if (S_ISGITLINK($mode)) { + return 'm---------'; + } elsif (S_ISDIR($mode & S_IFMT)) { return 'drwxr-xr-x'; } elsif (S_ISLNK($mode)) { return 'lrwxrwxrwx'; @@ -920,7 +934,9 @@ sub file_type { $mode = oct $mode; } - if (S_ISDIR($mode & S_IFMT)) { + if (S_ISGITLINK($mode)) { + return "submodule"; + } elsif (S_ISDIR($mode & S_IFMT)) { return "directory"; } elsif (S_ISLNK($mode)) { return "symlink"; @@ -941,7 +957,9 @@ sub file_type_long { $mode = oct $mode; } - if (S_ISDIR($mode & S_IFMT)) { + if (S_ISGITLINK($mode)) { + return "submodule"; + } elsif (S_ISDIR($mode & S_IFMT)) { return "directory"; } elsif (S_ISLNK($mode)) { return "symlink"; @@ -2707,6 +2725,20 @@ sub git_print_tree_entry { "history"); } print "\n"; + } else { + # unknown object: we can only present history for it + # (this includes 'commit' object, i.e. submodule support) + print "" . + esc_path($t->{'name'}) . + "\n"; + print ""; + if (defined $hash_base) { + print $cgi->a({-href => href(action=>"history", + hash_base=>$hash_base, + file_name=>"$basedir$t->{'name'}")}, + "history"); + } + print "\n"; } } From 12075103ddc9a061cf6f3b04feb206123bb78e2f Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 28 Jul 2007 16:27:32 +0200 Subject: [PATCH 119/131] gitweb: Simplify 'opt' parameter validation, add "no merges" feeds Simplify and make more readable validation of 'opt' (extra options) parameter, using exists($hash{key}) instead of grepping keys of a hash for value. Move 'opt' parameter to be the last (for now) in the URL. Make use of '--no-merges' extra option ('opt') by adding "no merges" RSS and Atom feeds to the HTML header. Note that alternate format links in the RSS and Atom views do not use '--no-merges' option yet! Adds tests for the 'opt' parameter to t9500-gitweb-standalone-no-errors.sh Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 17 +++++++++++----- t/t9500-gitweb-standalone-no-errors.sh | 28 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 1aceedec8e..8a32899655 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -436,12 +436,11 @@ my %allowed_options = ( our @extra_options = $cgi->param('opt'); if (defined @extra_options) { - foreach(@extra_options) - { - if (not grep(/^$_$/, keys %allowed_options)) { + foreach my $opt (@extra_options) { + if (not exists $allowed_options{$opt}) { die_error(undef, "Invalid option parameter"); } - if (not grep(/^$action$/, @{$allowed_options{$_}})) { + if (not grep(/^$action$/, @{$allowed_options{$opt}})) { die_error(undef, "Invalid option parameter for this action"); } } @@ -598,7 +597,6 @@ sub href(%) { action => "a", file_name => "f", file_parent => "fp", - extra_options => "opt", hash => "h", hash_parent => "hp", hash_base => "hb", @@ -608,6 +606,7 @@ sub href(%) { searchtext => "s", searchtype => "st", snapshot_format => "sf", + extra_options => "opt", ); my %mapping = @mapping; @@ -2285,9 +2284,17 @@ EOF printf(''."\n", esc_param($project), href(action=>"rss")); + printf(''."\n", + esc_param($project), href(action=>"rss", + extra_options=>"--no-merges")); printf(''."\n", esc_param($project), href(action=>"atom")); + printf(''."\n", + esc_param($project), href(action=>"atom", + extra_options=>"--no-merges")); } else { printf(''."\n", diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh index d948724566..fa32598b0c 100755 --- a/t/t9500-gitweb-standalone-no-errors.sh +++ b/t/t9500-gitweb-standalone-no-errors.sh @@ -521,4 +521,32 @@ test_expect_success \ 'gitweb_run "p=.git;a=log"' test_debug 'cat gitweb.log' +# ---------------------------------------------------------------------- +# extra options + +test_expect_success \ + 'opt: log --no-merges' \ + 'gitweb_run "p=.git;a=log;opt=--no-merges"' +test_debug 'cat gitweb.log' + +test_expect_success \ + 'opt: atom --no-merges' \ + 'gitweb_run "p=.git;a=log;opt=--no-merges"' +test_debug 'cat gitweb.log' + +test_expect_success \ + 'opt: "file" history --no-merges' \ + 'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"' +test_debug 'cat gitweb.log' + +test_expect_success \ + 'opt: log --no-such-option (invalid option)' \ + 'gitweb_run "p=.git;a=log;opt=--no-such-option"' +test_debug 'cat gitweb.log' + +test_expect_success \ + 'opt: tree --no-merges (invalid option for action)' \ + 'gitweb_run "p=.git;a=tree;opt=--no-merges"' +test_debug 'cat gitweb.log' + test_done From 8b4aee015e2d81dc6cc53328aedc66742a5306d8 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Sat, 28 Jul 2007 20:26:35 +0200 Subject: [PATCH 120/131] Don't rely on unspecified behavior Calling access(p, m) with p == NULL is not specified, so don't do that. On GNU/Hurd systems doing so will result in a SIGSEGV. Signed-off-by: Thomas Schwinge Signed-off-by: Junio C Hamano --- builtin-add.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-add.c b/builtin-add.c index 734547994f..de5c108f8f 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -60,7 +60,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec, path = git_path("info/exclude"); if (!access(path, R_OK)) add_excludes_from_file(dir, path); - if (!access(excludes_file, R_OK)) + if (excludes_file != NULL && !access(excludes_file, R_OK)) add_excludes_from_file(dir, excludes_file); } From f22cca44ba5022d93bfd895ec08682fbda7efb8c Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sun, 29 Jul 2007 01:04:09 +0200 Subject: [PATCH 121/131] gitweb: Allow for multivalued parameters passed to href subroutine Make it possible to generate URLs with multivalued parameters in the href() subroutine, via passing reference to array of values. Example: href(action=>"log", extra_options=>["--no-merges", "--first-parent"]) Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 8a32899655..498b936dd4 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -629,7 +629,13 @@ sub href(%) { for (my $i = 0; $i < @mapping; $i += 2) { my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]); if (defined $params{$name}) { - push @result, $symbol . "=" . esc_param($params{$name}); + if (ref($params{$name}) eq "ARRAY") { + foreach my $par (@{$params{$name}}) { + push @result, $symbol . "=" . esc_param($par); + } + } else { + push @result, $symbol . "=" . esc_param($params{$name}); + } } } $href .= "?" . join(';', @result) if scalar @result; From c22486c9677682416ae6ad3ee77688e8b6923ee3 Mon Sep 17 00:00:00 2001 From: Seth Falcon Date: Sat, 28 Jul 2007 16:44:40 -0700 Subject: [PATCH 122/131] Rename git-rebase interactive buffer: todo => git-rebase-todo When using emacsclient or similar, a temporary buffer (file) named 'todo' could cause confusion with a pre-existing buffer of the same name. Signed-off-by: Seth Falcon Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index c987311499..061cd0a69e 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -17,7 +17,7 @@ USAGE='(--continue | --abort | --skip | [--preserve-merges] [--verbose] require_work_tree DOTEST="$GIT_DIR/.dotest-merge" -TODO="$DOTEST"/todo +TODO="$DOTEST"/git-rebase-todo DONE="$DOTEST"/done MSG="$DOTEST"/message SQUASH_MSG="$DOTEST"/message-squash From 360cc106e76ea2a4ba424905c4924e9ed6a4165d Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sat, 28 Jul 2007 22:17:10 +0200 Subject: [PATCH 123/131] git-gui: Unify wording to say "to stage" instead of "to add" Also, the warning message when clicking "Reset" is adapted to the wording "Reset" rather than a confusion "Cancel commit?". Signed-off-by: Christian Stimming Signed-off-by: Shawn O. Pearce --- git-gui.sh | 6 +++--- lib/checkout_op.tcl | 2 +- lib/commit.tcl | 4 ++-- lib/index.tcl | 2 +- lib/merge.tcl | 20 ++++++++++++-------- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index f87b955fdb..d7fad46e5e 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1827,12 +1827,12 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} { lappend disable_on_lock \ [list .mbar.commit entryconf [.mbar.commit index last] -state] - .mbar.commit add command -label {Add To Commit} \ + .mbar.commit add command -label {Stage To Commit} \ -command do_add_selection lappend disable_on_lock \ [list .mbar.commit entryconf [.mbar.commit index last] -state] - .mbar.commit add command -label {Add Tracked Files To Commit} \ + .mbar.commit add command -label {Stage Changed Files To Commit} \ -command do_add_all \ -accelerator $M1T-I lappend disable_on_lock \ @@ -2154,7 +2154,7 @@ pack .vpane.lower.commarea.buttons.rescan -side top -fill x lappend disable_on_lock \ {.vpane.lower.commarea.buttons.rescan conf -state} -button .vpane.lower.commarea.buttons.incall -text {Add Tracked} \ +button .vpane.lower.commarea.buttons.incall -text {Stage Changed} \ -command do_add_all pack .vpane.lower.commarea.buttons.incall -side top -fill x lappend disable_on_lock \ diff --git a/lib/checkout_op.tcl b/lib/checkout_op.tcl index 40cc73a527..170f737f61 100644 --- a/lib/checkout_op.tcl +++ b/lib/checkout_op.tcl @@ -248,7 +248,7 @@ method _checkout {} { if {[lock_index checkout_op]} { after idle [cb _start_checkout] } else { - _error $this "Index is already locked." + _error $this "Staging area (index) is already locked." delete_this } } diff --git a/lib/commit.tcl b/lib/commit.tcl index 1f5c2c3d44..f857a2ff5b 100644 --- a/lib/commit.tcl +++ b/lib/commit.tcl @@ -153,7 +153,7 @@ The rescan will be automatically started now. U? { error_popup "Unmerged files cannot be committed. -File [short_path $path] has merge conflicts. You must resolve them and add the file before committing. +File [short_path $path] has merge conflicts. You must resolve them and stage the file before committing. " unlock_index return @@ -169,7 +169,7 @@ File [short_path $path] cannot be committed by this program. if {!$files_ready && ![string match *merge $curType]} { info_popup {No changes to commit. -You must add at least 1 file before you can commit. +You must stage at least 1 file before you can commit. } unlock_index return diff --git a/lib/index.tcl b/lib/index.tcl index 3ea72e1ec9..f47f9290c8 100644 --- a/lib/index.tcl +++ b/lib/index.tcl @@ -360,7 +360,7 @@ proc revert_helper {txt paths} { "[appname] ([reponame])" \ "Revert changes in $s? -Any unadded changes will be permanently lost by the revert." \ +Any unstaged changes will be permanently lost by the revert." \ question \ 1 \ {Do Nothing} \ diff --git a/lib/merge.tcl b/lib/merge.tcl index 148d859c5c..f6a2df3c06 100644 --- a/lib/merge.tcl +++ b/lib/merge.tcl @@ -45,7 +45,7 @@ The rescan will be automatically started now. File [short_path $path] has merge conflicts. -You must resolve them, add the file, and commit to complete the current merge. Only then can you begin another merge. +You must resolve them, stage the file, and commit to complete the current merge. Only then can you begin another merge. " unlock_index return 0 @@ -219,16 +219,20 @@ You must finish amending this commit. if {![lock_index abort]} return if {[string match *merge* $commit_type]} { - set op merge + set op_question "Abort merge? + +Aborting the current merge will cause *ALL* uncommitted changes to be lost. + +Continue with aborting the current merge?" } else { - set op commit + set op_question "Reset changes? + +Resetting the changes will cause *ALL* uncommitted changes to be lost. + +Continue with resetting the current changes?" } - if {[ask_popup "Abort $op? - -Aborting the current $op will cause *ALL* uncommitted changes to be lost. - -Continue with aborting the current $op?"] eq {yes}} { + if {[ask_popup $op_question] eq {yes}} { set fd [git_read read-tree --reset -u HEAD] fconfigure $fd -blocking 0 -translation binary fileevent $fd readable [namespace code [list _reset_wait $fd]] From 94a4dd9bfda79a226f8dd57fd20c39c6603ec194 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 29 Jul 2007 03:22:27 -0400 Subject: [PATCH 124/131] git-gui: Honor core.excludesfile when listing extra files Recent git versions have a git-status that honors the core.excludesfile configuration option when it reports on untracked files. Unfortunately I missed the introduction of this configuration option in the core porcelain implementation, so it was not reflected here in git-gui. Found and reported by Lars Noschinski . Signed-off-by: Shawn O. Pearce --- git-gui.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index d7fad46e5e..4e3b58cfd3 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -872,6 +872,10 @@ proc rescan_stage2 {fd after} { if {[file readable $info_exclude]} { lappend ls_others "--exclude-from=$info_exclude" } + set user_exclude [get_config core.excludesfile] + if {$user_exclude ne {} && [file readable $user_exclude]} { + lappend ls_others "--exclude-from=$user_exclude" + } set buf_rdi {} set buf_rdf {} From 0fe055cd2480763393b20676a10fd0bea56b2fc2 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 29 Jul 2007 04:06:51 -0400 Subject: [PATCH 125/131] git-gui: Use progress bar while resetting/aborting files Resetting a large number of files on a slow filesystem can take considerable time, just as switching branches in such a case can take more than two seconds. We now take advantage of the progress meter output by read-tree and show it in the main window status bar, just like we do during checkout (branch switch). Signed-off-by: Shawn O. Pearce --- lib/merge.tcl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/merge.tcl b/lib/merge.tcl index f6a2df3c06..66d1bcd826 100644 --- a/lib/merge.tcl +++ b/lib/merge.tcl @@ -233,10 +233,10 @@ Continue with resetting the current changes?" } if {[ask_popup $op_question] eq {yes}} { - set fd [git_read read-tree --reset -u HEAD] + set fd [git_read --stderr read-tree --reset -u -v HEAD] fconfigure $fd -blocking 0 -translation binary fileevent $fd readable [namespace code [list _reset_wait $fd]] - ui_status {Aborting... please wait...} + $::main_status start {Aborting} {files reset} } else { unlock_index } @@ -245,9 +245,12 @@ Continue with resetting the current changes?" proc _reset_wait {fd} { global ui_comm - read $fd + $::main_status update_meter [read $fd] + + fconfigure $fd -blocking 1 if {[eof $fd]} { - close $fd + set fail [catch {close $fd} err] + $::main_status stop unlock_index $ui_comm delete 0.0 end @@ -259,7 +262,12 @@ proc _reset_wait {fd} { catch {file delete [gitdir MERGE_MSG]} catch {file delete [gitdir GITGUI_MSG]} + if {$fail} { + warn_popup "Abort failed.\n\n$err" + } rescan {ui_status {Abort completed. Ready.}} + } else { + fconfigure $fd -blocking 0 } } From 82cb8afa9bf24d2f77a6d565cdc08d6aa1febeb4 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 29 Jul 2007 05:49:56 -0400 Subject: [PATCH 126/131] git-diff: turn on recursion by default The tree recursion behavior of git-diff may appear inconsistent to the user because it depends on the format of the patch as well as whether one is diffing between trees or against the index. Since git-diff is a porcelain wrapper for low-level diff commands, it makes sense for its behavior to be consistent no matter what is being diffed. This patch turns on recursion in all cases. Signed-off-by: Junio C Hamano --- builtin-diff.c | 1 + t/t9300-fast-import.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin-diff.c b/builtin-diff.c index 7f367b6b9d..b48121e6e2 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -233,6 +233,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) die("diff_setup_done failed"); } rev.diffopt.allow_external = 1; + rev.diffopt.recursive = 1; /* Do we have --cached and not have a pending object, then * default to HEAD by hand. Eek. diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 4b920be331..6f95305bf4 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -577,7 +577,7 @@ EXPECT_END test_expect_success \ 'L: verify internal tree sorting' \ 'git-fast-import output && + git diff-tree --abbrev --raw L^ L >output && git diff expect output' ### From 89b2f19cb516249b8d9546bb1f3f46a1ec5b3242 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sun, 29 Jul 2007 15:23:28 -0700 Subject: [PATCH 127/131] Makefile: use $(FIND) instead of find Some people might prefer to be able to specify the find utility to use. Signed-off-by: David Kastrup Signed-off-by: Junio C Hamano --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 73b487fba9..c58a4c2a09 100644 --- a/Makefile +++ b/Makefile @@ -176,6 +176,7 @@ CC = gcc AR = ar RM = rm -f TAR = tar +FIND = find INSTALL = install RPMBUILD = rpmbuild TCL_PATH = tclsh @@ -903,11 +904,11 @@ doc: TAGS: $(RM) TAGS - find . -name '*.[hcS]' -print | xargs etags -a + $(FIND) . -name '*.[hcS]' -print | xargs etags -a tags: $(RM) tags - find . -name '*.[hcS]' -print | xargs ctags -a + $(FIND) . -name '*.[hcS]' -print | xargs ctags -a ### Detect prefix changes TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\ From 95af4d8de16e8e681c196fce6d42e40909933115 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 29 Jul 2007 21:26:42 -0400 Subject: [PATCH 128/131] git-gui: Make sure remotes are loaded when picking revisions If we are started for only a blame/browser/citool run we don't usually initialize the list of remotes, or determine which refs are tracking branches and which are local branch heads. This is because some of that work is relatively expensive and is usually not going to be needed if we are started only for a blame, or to make a single commit. However by not loading the remote configuration we were crashing if the user tried to open a browser for another branch through the Repository menu, as our load_all_heads procedure was unable to decide which refs/heads/ items were actually local heads. We now force all remote configuration data to be loaded if we have not done so already and we are trying to create a revision mega widget. Signed-off-by: Shawn O. Pearce --- lib/choose_rev.tcl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/choose_rev.tcl b/lib/choose_rev.tcl index 4147b7c5bc..ec064b3e13 100644 --- a/lib/choose_rev.tcl +++ b/lib/choose_rev.tcl @@ -34,6 +34,10 @@ proc new_unmerged {path {title {}}} { constructor _new {path unmerged_only title} { global current_branch is_detached + if {![info exists ::all_remotes]} { + load_all_remotes + } + set w $path if {$title ne {}} { From 37e2199c4c5b45e060f973097d814726cabe2a86 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 29 Jul 2007 20:29:52 -0400 Subject: [PATCH 129/131] git-gui: Don't offer to stage hunks from untracked files If the user looks at an untracked file in our diff pane we used to offer "Stage Hunk For Commit" in the context menu when they right-clicked in that pane. The problem is we don't actually have any diff hunks in untracked files, so there is nothing to really select for staging. So we now grey out the menu item, so the user cannot invoke it and think its broken when it does not perform any useful action. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index 4e3b58cfd3..0180756155 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2437,9 +2437,15 @@ proc popup_diff_menu {ctxm x y X Y} { set ::cursorY $y if {$::ui_index eq $::current_diff_side} { $ctxm entryconf $::ui_diff_applyhunk \ + -state normal \ -label {Unstage Hunk From Commit} + } elseif {{_O} eq [lindex $::file_states($::current_diff_path) 0]} { + $ctxm entryconf $::ui_diff_applyhunk \ + -state disabled \ + -label {Stage Hunk For Commit} } else { $ctxm entryconf $::ui_diff_applyhunk \ + -state normal \ -label {Stage Hunk For Commit} } tk_popup $ctxm $X $Y From dac70892638d08f50c49c539155c4cb54a9b9c28 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 29 Jul 2007 21:19:54 -0400 Subject: [PATCH 130/131] git-gui: Use more modern looking icons in the tree browser This is a replacement of all of the icons in our tree browser window, as the prior icons just looked too 1980s Tk-ish. The icons used here are actually from a KDE themed look, so they might actually be familiar to some users of git-gui. Aside from using more modern looking icons we now have a special icon for executable blobs, to make them stand out from the normal non-executable blobs. We also denote symlinks now with a different icon, so they stand out from the other types of objects in the tree. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 26 -------------------------- lib/browser.tcl | 22 ++++++++++++++++++---- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 0180756155..671b8873f2 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1296,32 +1296,6 @@ static unsigned char file_merge_bits[] = { 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f}; } -maskdata $filemask -set file_dir_data { -#define file_width 18 -#define file_height 18 -static unsigned char file_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x00, - 0x0c, 0x03, 0x00, 0x04, 0xfe, 0x00, 0x06, 0x80, 0x00, 0xff, 0x9f, 0x00, - 0x03, 0x98, 0x00, 0x02, 0x90, 0x00, 0x06, 0xb0, 0x00, 0x04, 0xa0, 0x00, - 0x0c, 0xe0, 0x00, 0x08, 0xc0, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -} -image create bitmap file_dir -background white -foreground blue \ - -data $file_dir_data -maskdata $file_dir_data -unset file_dir_data - -set file_uplevel_data { -#define up_width 15 -#define up_height 15 -static unsigned char up_bits[] = { - 0x80, 0x00, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f, 0xfc, 0x1f, - 0xfe, 0x3f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, - 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00}; -} -image create bitmap file_uplevel -background white -foreground red \ - -data $file_uplevel_data -maskdata $file_uplevel_data -unset file_uplevel_data - set ui_index .vpane.files.index.list set ui_workdir .vpane.files.workdir.list diff --git a/lib/browser.tcl b/lib/browser.tcl index b684c67148..888db3c889 100644 --- a/lib/browser.tcl +++ b/lib/browser.tcl @@ -3,6 +3,13 @@ class browser { +image create photo ::browser::img_parent -data {R0lGODlhEAAQAIUAAPwCBBxSHBxOHMTSzNzu3KzCtBRGHCSKFIzCjLzSxBQ2FAxGHDzCLCyeHBQ+FHSmfAwuFBxKLDSCNMzizISyjJzOnDSyLAw+FAQSDAQeDBxWJAwmDAQOBKzWrDymNAQaDAQODAwaDDyKTFSyXFTGTEy6TAQCBAQKDAwiFBQyHAwSFAwmHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAZ1QIBwSCwaj0hiQCBICpcDQsFgGAaIguhhi0gohIsrQEDYMhiNrRfgeAQC5fMCAolIDhD2hFI5WC4YRBkaBxsOE2l/RxsHHA4dHmkfRyAbIQ4iIyQlB5NFGCAACiakpSZEJyinTgAcKSesACorgU4mJ6uxR35BACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs=} +image create photo ::browser::img_rblob -data {R0lGODlhEAAQAIUAAPwCBFxaXNze3Ly2rJSWjPz+/Ozq7GxqbJyanPT29HRydMzOzDQyNIyKjERCROTi3Pz69PTy7Pzy7PTu5Ozm3LyqlJyWlJSSjJSOhOzi1LyulPz27PTq3PTm1OzezLyqjIyKhJSKfOzaxPz29OzizLyidIyGdIyCdOTOpLymhOzavOTStMTCtMS+rMS6pMSynMSulLyedAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaQQIAQECgajcNkQMBkDgKEQFK4LFgLhkMBIVUKroWEYlEgMLxbBKLQUBwc52HgAQ4LBo049atWQyIPA3pEdFcQEhMUFYNVagQWFxgZGoxfYRsTHB0eH5UJCJAYICEinUoPIxIcHCQkIiIllQYEGCEhJicoKYwPmiQeKisrKLFKLCwtLi8wHyUlMYwM0tPUDH5BACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs=} +image create photo ::browser::img_xblob -data {R0lGODlhEAAQAIYAAPwCBFRWVFxaXNza3OTi3Nze3Ly2tJyanPz+/Ozq7GxubNzSxMzOzMTGxHRybDQyNLy+vHRydHx6fKSipISChIyKjGxqbERCRCwuLLy6vGRiZExKTCQiJAwKDLSytLy2rJSSlHx+fDw6PKyqrBQWFPTu5Ozm3LyulLS2tCQmJAQCBPTq3Ozi1MSynCwqLAQGBOTazOzizOzezLyqjBweHNzSvOzaxKyurHRuZNzOtLymhDw+PIyCdOzWvOTOpLyidNzKtOTStLyifMTCtMS+rLyedAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAfZgACCAAEChYeGg4oCAwQFjgYBBwGKggEECJkICQoIkwADCwwNDY2mDA4Lng8QDhESsLARExQVDhYXGBkWExIaGw8cHR4SCQQfFQ8eFgUgIQEiwiMSBMYfGB4atwEXDyQd0wQlJicPKAHoFyIpJCoeDgMrLC0YKBsX6i4kL+4OMDEyZijr5oLGNxUqUCioEcPGDAwjPNyI6MEDChQjcOSwsUDHgw07RIgI4KCkAgs8cvTw8eOBogAxQtXIASTISiEuBwUYMoRIixYnZggpUgTDywdIkWJIitRPIAAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7} +image create photo ::browser::img_tree -data {R0lGODlhEAAQAIYAAPwCBAQCBExKTBwWHMzKzOzq7ERCRExGTCwqLARqnAQ+ZHR2dKyqrNTOzHx2fCQiJMTi9NTu9HzC3AxmnAQ+XPTm7Dy67DymzITC3IzG5AxypHRydKymrMzOzOzu7BweHByy9AyGtFyy1IzG3NTu/ARupFRSVByazBR6rAyGvFyuzJTK3MTm9BR+tAxWhHS61MTi7Pz+/IymvCxulBRelAx2rHS63Pz6/PTy9PTu9Nza3ISitBRupFSixNTS1CxqnDQyNMzGzOTi5MTCxMTGxGxubGxqbLy2vLSutGRiZLy6vLSytKyurDQuNFxaXKSipDw6PAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAfDgACCAAECg4eIAAMEBQYHCImDBgkKCwwNBQIBBw4Bhw8QERITFJYEFQUFnoIPFhcYoRkaFBscHR4Ggh8gIRciEiMQJBkltCa6JyUoKSkXKhIrLCQYuQAPLS4TEyUhKb0qLzDVAjEFMjMuNBMoNcw21QY3ODkFOjs82RM1PfDzFRU3fOggcM7Fj2pAgggRokOHDx9DhhAZUqQaISBGhjwMEvEIkiIHEgUAkgSJkiNLmFSMJChAEydPGBSBwvJQgAc0/QQCACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs=} +image create photo ::browser::img_symlink -data {R0lGODlhEAAQAIQAAPwCBCwqLLSytLy+vERGRFRWVDQ2NKSmpAQCBKyurMTGxISChJyanHR2dIyKjGxubHRydGRmZIyOjFxeXHx6fAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAVbICACwWieY1CibCCsrBkMb0zchSEcNYskCtqBBzshFkOGQFk0IRqOxqPBODRHCMhCQKteRc9FI/KQWGOIyFYgkDC+gPR4snCcfRGKOIKIgSMQE31+f4OEYCZ+IQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7} +image create photo ::browser::img_unknown -data {R0lGODlhEAAQAIUAAPwCBFxaXIyKjNTW1Nze3LS2tJyanER2RGS+VPz+/PTu5GxqbPz69BQ6BCxeLFSqRPT29HRydMzOzDQyNERmPKSypCRWHIyKhERCRDyGPKz2nESiLBxGHCyCHGxubPz6/PTy7Ozi1Ly2rKSipOzm3LyqlKSWhCRyFOzizLymhNTKtNzOvOzaxOTStPz27OzWvOTOpLSupLyedMS+rMS6pMSulLyqjLymfLyifAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAamQIAQECgajcOkYEBoDgoBQyAJOCCuiENCsWBIh9aGw9F4HCARiXciRDQoBUnlYRlcIgsMG5CxXAgMGhscBRAEBRd7AB0eBBoIgxUfICEiikSPgyMMIAokJZcBkBybJgomIaBJAZoMpyCmqkMBFCcVCrgKKAwpoSorKqchKCwtvasIFBIhLiYvLzDHsxQNMcMKLDAwMqEz3jQ1NTY3ONyrE+jp6hN+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7} + field w field browser_commit field browser_path @@ -177,7 +184,7 @@ method _ls {tree_id {name {}}} { $w image create end \ -align center -padx 5 -pady 1 \ -name icon0 \ - -image file_uplevel + -image ::browser::img_parent $w insert end {[Up To Parent]} lappend browser_files parent } @@ -207,14 +214,21 @@ method _read {fd} { switch -- $type { blob { - set image file_mod + scan [lindex $info 0] %o mode + if {$mode == 0120000} { + set image ::browser::img_symlink + } elseif {($mode & 0100) != 0} { + set image ::browser::img_xblob + } else { + set image ::browser::img_rblob + } } tree { - set image file_dir + set image ::browser::img_tree append path / } default { - set image file_question + set image ::browser::img_unknown } } From 84f67537b13bf0a959b1cad50b0d490071dc921a Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 29 Jul 2007 20:21:54 -0400 Subject: [PATCH 131/131] git-gui: Minor refactoring of merge command line in merge support This is just a small code movement to cleanup how we generate the command line for a merge. I'm only doing it to make the next series of changes slightly more readable. Signed-off-by: Shawn O. Pearce --- lib/merge.tcl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/merge.tcl b/lib/merge.tcl index 66d1bcd826..5de0d82b14 100644 --- a/lib/merge.tcl +++ b/lib/merge.tcl @@ -90,9 +90,6 @@ method _start {} { set spec [$w_rev get_tracking_branch] set cmit [$w_rev get_commit] - set cmd [list git] - lappend cmd merge - lappend cmd --strategy=recursive set fh [open [gitdir FETCH_HEAD] w] fconfigure $fh -translation lf @@ -112,6 +109,9 @@ method _start {} { puts $fh "$cmit\t\tbranch '$branch' of $remote" close $fh + set cmd [list git] + lappend cmd merge + lappend cmd --strategy=recursive lappend cmd [git fmt-merge-msg <[gitdir FETCH_HEAD]] lappend cmd HEAD lappend cmd $cmit