From 8f4893639129acfc866c71583317090aa2a46eab Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Fri, 13 Jul 2007 19:49:37 +1000 Subject: [PATCH 001/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] [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/201] [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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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/201] 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 5d5a7a67384ad03007eea1f365ee255c02a40fa3 Mon Sep 17 00:00:00 2001 From: "Bradford C. Smith" Date: Thu, 26 Jul 2007 13:34:14 -0400 Subject: [PATCH 113/201] fully resolve symlinks when creating lockfiles Make the code for resolving symlinks in lockfile.c more robust as follows: 1. Handle relative symlinks 2. recursively resolve symlink chains up to 5 [jc: removed lstat/stat calls to do things stupid way] Signed-off-by: Bradford C. Smith Signed-off-by: Junio C Hamano --- lockfile.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 101 insertions(+), 13 deletions(-) diff --git a/lockfile.c b/lockfile.c index 9202472498..9a1f64d8d7 100644 --- a/lockfile.c +++ b/lockfile.c @@ -25,23 +25,111 @@ static void remove_lock_file_on_signal(int signo) raise(signo); } +/* + * p = absolute or relative path name + * + * Return a pointer into p showing the beginning of the last path name + * element. If p is empty or the root directory ("/"), just return p. + */ +static char *last_path_elm(char *p) +{ + /* r starts pointing to null at the end of the string */ + char *r = strchr(p, '\0'); + + if (r == p) + return p; /* just return empty string */ + + r--; /* back up to last non-null character */ + + /* back up past trailing slashes, if any */ + while (r > p && *r == '/') + r--; + + /* + * then go backwards until I hit a slash, or the beginning of + * the string + */ + while (r > p && *(r-1) != '/') + r--; + return r; +} + + +/* We allow "recursive" symbolic links. Only within reason, though */ +#define MAXDEPTH 5 + +/* + * p = path that may be a symlink + * s = full size of p + * + * If p is a symlink, attempt to overwrite p with a path to the real + * file or directory (which may or may not exist), following a chain of + * symlinks if necessary. Otherwise, leave p unmodified. + * + * This is a best-effort routine. If an error occurs, p will either be + * left unmodified or will name a different symlink in a symlink chain + * that started with p's initial contents. + * + * Always returns p. + */ + +static char *resolve_symlink(char *p, size_t s) +{ + int depth = MAXDEPTH; + + while (depth--) { + char link[PATH_MAX]; + int link_len = readlink(p, link, sizeof(link)); + if (link_len < 0) { + /* not a symlink anymore */ + return p; + } + else if (link_len < sizeof(link)) + /* readlink() never null-terminates */ + link[link_len] = '\0'; + else { + warning("%s: symlink too long", p); + return p; + } + + if (link[0] == '/') { + /* absolute path simply replaces p */ + if (link_len < s) + strcpy(p, link); + else { + warning("%s: symlink too long", p); + return p; + } + } else { + /* + * link is a relative path, so I must replace the + * last element of p with it. + */ + char *r = (char*)last_path_elm(p); + if (r - p + link_len < s) + strcpy(r, link); + else { + warning("%s: symlink too long", p); + return p; + } + } + } + return p; +} + + 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); + if (strlen(path) >= sizeof(lk->filename)) return -1; + strcpy(lk->filename, path); + /* + * subtract 5 from size to make sure there's room for adding + * ".lock" for the lock file name + */ + resolve_symlink(lk->filename, sizeof(lk->filename)-5); + strcat(lk->filename, ".lock"); fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666); if (0 <= fd) { if (!lock_file_list) { From 6cbf973c9a6f06e9c45b3f6a76f0ceae8e7fd291 Mon Sep 17 00:00:00 2001 From: "Bradford C. Smith" Date: Thu, 26 Jul 2007 12:55:28 -0400 Subject: [PATCH 114/201] use lockfile.c routines in git_commit_set_multivar() Changed git_commit_set_multivar() to use the routines provided by lockfile.c to reduce code duplication and ensure consistent behavior. Signed-off-by: Bradford C. Smith Signed-off-by: Junio C Hamano --- config.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/config.c b/config.c index f89a611915..dd2de6e38e 100644 --- a/config.c +++ b/config.c @@ -715,7 +715,7 @@ int git_config_set_multivar(const char* key, const char* value, int fd = -1, in_fd; int ret; char* config_filename; - char* lock_file; + struct lock_file *lock = NULL; const char* last_dot = strrchr(key, '.'); config_filename = getenv(CONFIG_ENVIRONMENT); @@ -725,7 +725,6 @@ int git_config_set_multivar(const char* key, const char* value, config_filename = git_path("config"); } config_filename = xstrdup(config_filename); - lock_file = xstrdup(mkpath("%s.lock", config_filename)); /* * Since "key" actually contains the section name and the real @@ -770,11 +769,12 @@ int git_config_set_multivar(const char* key, const char* value, store.key[i] = 0; /* - * The lock_file serves a purpose in addition to locking: the new + * The lock serves a purpose in addition to locking: the new * contents of .git/config will be written into it. */ - fd = open(lock_file, O_WRONLY | O_CREAT | O_EXCL, 0666); - if (fd < 0 || adjust_shared_perm(lock_file)) { + lock = xcalloc(sizeof(struct lock_file), 1); + fd = hold_lock_file_for_update(lock, config_filename, 0); + if (fd < 0) { fprintf(stderr, "could not lock config file\n"); free(store.key); ret = -1; @@ -914,25 +914,31 @@ int git_config_set_multivar(const char* key, const char* value, goto write_err_out; munmap(contents, contents_sz); - unlink(config_filename); } - if (rename(lock_file, config_filename) < 0) { - fprintf(stderr, "Could not rename the lock file?\n"); + if (close(fd) || commit_lock_file(lock) < 0) { + fprintf(stderr, "Cannot commit config file!\n"); ret = 4; goto out_free; } + /* fd is closed, so don't try to close it below. */ + fd = -1; + /* + * lock is committed, so don't try to roll it back below. + * NOTE: Since lockfile.c keeps a linked list of all created + * lock_file structures, it isn't safe to free(lock). It's + * better to just leave it hanging around. + */ + lock = NULL; ret = 0; out_free: if (0 <= fd) close(fd); + if (lock) + rollback_lock_file(lock); free(config_filename); - if (lock_file) { - unlink(lock_file); - free(lock_file); - } return ret; write_err_out: From 65a5a21d024373674d6068a03c71558035775e0c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 26 Jul 2007 22:13:12 -0700 Subject: [PATCH 115/201] Add test for symlinked configuration file updates. Signed-off-by: Junio C Hamano --- t/t1300-repo-config.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 1c43cc333d..187ca2df5c 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -595,4 +595,19 @@ echo >>result test_expect_success '--null --get-regexp' 'cmp result expect' +test_expect_success 'symlinked configuration' ' + + ln -s notyet myconfig && + GIT_CONFIG=myconfig git config test.frotz nitfol && + test -h myconfig && + test -f notyet && + test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol && + GIT_CONFIG=myconfig git config test.xyzzy rezrov && + test -h myconfig && + test -f notyet && + test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol && + test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov + +' + test_done From fb47cfbd59b12ea67e1a5c6a9d0bd665fcae4581 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 24 Jul 2007 21:43:09 +0100 Subject: [PATCH 116/201] 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 117/201] 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 118/201] 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 119/201] 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 120/201] 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 121/201] 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 122/201] 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 123/201] 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 124/201] 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 125/201] 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 126/201] 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 127/201] 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 128/201] 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 129/201] 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 130/201] 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 131/201] 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 132/201] 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 133/201] 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 134/201] 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 From 0ec29a4760e7c1dd1e168f6dbdd22b87559a26e9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 28 Jul 2007 17:17:17 -0700 Subject: [PATCH 135/201] log_ref_write() -- do not chomp reflog message at the first LF A reflog file is organized as one-line-per-entry records, and we enforced the file format integrity by chomping the given message at the first LF. This changes it to convert them to SP, which is more in line with the --pretty=oneline format. Signed-off-by: Junio C Hamano --- refs.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/refs.c b/refs.c index 2694e7066d..fac6548001 100644 --- a/refs.c +++ b/refs.c @@ -1036,6 +1036,32 @@ void unlock_ref(struct ref_lock *lock) free(lock); } +/* + * copy the reflog message msg to buf, which has been allocated sufficiently + * large, while cleaning up the whitespaces. Especially, convert LF to space, + * because reflog file is one line per entry. + */ +static int copy_msg(char *buf, const char *msg) +{ + char *cp = buf; + char c; + int wasspace = 1; + + *cp++ = '\t'; + while ((c = *msg++)) { + if (wasspace && isspace(c)) + continue; + wasspace = isspace(c); + if (wasspace) + c = ' '; + *cp++ = c; + } + while (buf < cp && isspace(cp[-1])) + cp--; + *cp++ = '\n'; + return cp - buf; +} + static int log_ref_write(const char *ref_name, const unsigned char *old_sha1, const unsigned char *new_sha1, const char *msg) { @@ -1080,21 +1106,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1, adjust_shared_perm(log_file); - msglen = 0; - if (msg) { - /* clean up the message and make sure it is a single line */ - for ( ; *msg; msg++) - if (!isspace(*msg)) - break; - if (*msg) { - const char *ep = strchr(msg, '\n'); - if (ep) - msglen = ep - msg; - else - msglen = strlen(msg); - } - } - + msglen = msg ? strlen(msg) : 0; committer = git_committer_info(-1); maxlen = strlen(committer) + msglen + 100; logrec = xmalloc(maxlen); @@ -1103,7 +1115,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1, sha1_to_hex(new_sha1), committer); if (msglen) - len += sprintf(logrec + len - 1, "\t%.*s\n", msglen, msg) - 1; + len += copy_msg(logrec + len - 1, msg) - 1; written = len <= maxlen ? write_in_full(logfd, logrec, len) : -1; free(logrec); if (close(logfd) != 0 || written != len) From 283884422f35594db9eab491d3f8c91e49f9d62f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 28 Jul 2007 17:20:52 -0700 Subject: [PATCH 136/201] symbolic-ref, update-ref: do not refuse reflog message with LF Earlier these tools refused to create a reflog entry when the message given by the calling Porcelain had a LF in it, partially to keep the file format integrity of reflog file, which is one-entry-per-line. These tools should not be dictating such a policy. Instead, let the codepath to write out the reflog entry worry about the format integrity and allow messages with LF in them. Signed-off-by: Junio C Hamano --- builtin-symbolic-ref.c | 2 -- builtin-update-ref.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/builtin-symbolic-ref.c b/builtin-symbolic-ref.c index d41b40640b..9eb95e50da 100644 --- a/builtin-symbolic-ref.c +++ b/builtin-symbolic-ref.c @@ -43,8 +43,6 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix) msg = argv[1]; if (!*msg) die("Refusing to perform update with empty message"); - if (strchr(msg, '\n')) - die("Refusing to perform update with \\n in message"); } else if (!strcmp("--", arg)) { argc--; diff --git a/builtin-update-ref.c b/builtin-update-ref.c index feac2ed12d..8339cf19e2 100644 --- a/builtin-update-ref.c +++ b/builtin-update-ref.c @@ -23,8 +23,6 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) msg = argv[++i]; if (!*msg) die("Refusing to perform update with empty message."); - if (strchr(msg, '\n')) - die("Refusing to perform update with \\n in message."); continue; } if (!strcmp("-d", argv[i])) { From d7f6bae28142e07e544efdab73260cf9f60ca899 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 28 Jul 2007 17:57:25 -0700 Subject: [PATCH 137/201] rebase: try not to munge commit log message This makes rebase/am keep the original commit log message better, even when it does not conform to "single line paragraph to say what it does, then explain and defend why it is a good change in later paragraphs" convention. This change is a two-edged sword. While the earlier behaviour would make such commit log messages more friendly to readers who expect to get the birds-eye view with oneline summary formats, users who primarily use git as a way to interact with foreign SCM systems would not care much about the convenience of oneline git log tools, but care more about preserving their own convention. This changes their commits less useful to readers who read them with git tools while keeping them more consistent with the foreign SCM systems they interact with. Signed-off-by: Junio C Hamano --- builtin-mailinfo.c | 29 ++++++++++++++++++---- t/t3405-rebase-malformed.sh | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 5 deletions(-) create mode 100755 t/t3405-rebase-malformed.sh diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c index b4f6e913b3..b558754142 100644 --- a/builtin-mailinfo.c +++ b/builtin-mailinfo.c @@ -237,8 +237,6 @@ static int eatspace(char *line) static char *cleanup_subject(char *subject) { - if (keep_subject) - return subject; for (;;) { char *p; int len, remove; @@ -425,6 +423,7 @@ static int read_one_header_line(char *line, int sz, FILE *in) if (addlen >= sz - len) addlen = sz - len - 1; memcpy(line + len, continuation, addlen); + line[len] = '\n'; len += addlen; } } @@ -846,6 +845,22 @@ static void handle_body(void) return; } +static void output_header_lines(FILE *fout, const char *hdr, char *data) +{ + while (1) { + char *ep = strchr(data, '\n'); + int len; + if (!ep) + len = strlen(data); + else + len = ep - data; + fprintf(fout, "%s: %.*s\n", hdr, len, data); + if (!ep) + break; + data = ep + 1; + } +} + static void handle_info(void) { char *sub; @@ -863,9 +878,13 @@ static void handle_info(void) continue; if (!memcmp(header[i], "Subject", 7)) { - sub = cleanup_subject(hdr); - cleanup_space(sub); - fprintf(fout, "Subject: %s\n", sub); + if (keep_subject) + sub = hdr; + else { + sub = cleanup_subject(hdr); + cleanup_space(sub); + } + output_header_lines(fout, "Subject", sub); } else if (!memcmp(header[i], "From", 4)) { handle_from(hdr); fprintf(fout, "Author: %s\n", name); diff --git a/t/t3405-rebase-malformed.sh b/t/t3405-rebase-malformed.sh new file mode 100755 index 0000000000..e4e2e649ed --- /dev/null +++ b/t/t3405-rebase-malformed.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +test_description='rebase should not insist on git message convention' + +. ./test-lib.sh + +cat >F <<\EOF +This is an example of a commit log message +that does not conform to git commit convention. + +It has two paragraphs, but its first paragraph is not friendly +to oneline summary format. +EOF + +test_expect_success setup ' + + >file1 && + >file2 && + git add file1 file2 && + test_tick && + git commit -m "Initial commit" && + + git checkout -b side && + cat F >file2 && + git add file2 && + test_tick && + git commit -F F && + + git cat-file commit HEAD | sed -e "1,/^\$/d" >F0 && + + git checkout master && + + echo One >file1 && + test_tick && + git add file1 && + git commit -m "Second commit" +' + +test_expect_success rebase ' + + git rebase master side && + git cat-file commit HEAD | sed -e "1,/^\$/d" >F1 && + + diff -u F0 F1 && + diff -u F F0 +' + +test_done From 5c759f96d020d7021a7e674c8d1e5bebd17dcd2f Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Sun, 29 Jul 2007 22:50:24 -0300 Subject: [PATCH 138/201] Documentation/gitattributes.txt: typofix The file used for per-repository attribute setting is not $GIT_DIR/info/gitattributes, but $GIT_DIR/info/attributes. Signed-off-by: Junio C Hamano --- Documentation/gitattributes.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index 810df07217..8b90a5b980 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -405,7 +405,7 @@ the attributes given to path `t/abc` are computed as follows: and `bar` attributes should be given to this path, so it leaves `foo` and `bar` unset. Attribute `baz` is set. -3. Finally it examines `$GIT_DIR/info/gitattributes`. This file +3. Finally it examines `$GIT_DIR/info/attributes`. This file is used to override the in-tree settings. The first line is a match, and `foo` is set, `bar` is reverted to unspecified state, and `baz` is unset. From 299726d53841984450524f4ade428112e51c853e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Jul 2007 00:24:38 +0100 Subject: [PATCH 139/201] white space fixes in setup.c Some lines were not indented by tabs but by spaces. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- setup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.c b/setup.c index 7b07144af7..b54d65fd07 100644 --- a/setup.c +++ b/setup.c @@ -382,11 +382,11 @@ int git_config_perm(const char *var, const char *value) int check_repository_format_version(const char *var, const char *value) { - if (strcmp(var, "core.repositoryformatversion") == 0) - repository_format_version = git_config_int(var, value); + if (strcmp(var, "core.repositoryformatversion") == 0) + repository_format_version = git_config_int(var, value); else if (strcmp(var, "core.sharedrepository") == 0) shared_repository = git_config_perm(var, value); - return 0; + return 0; } int check_repository_format(void) From bf655fd7009bf5b8f493c52ca77c0d9e09dcb762 Mon Sep 17 00:00:00 2001 From: Robert Ewald Date: Mon, 30 Jul 2007 11:08:21 +0200 Subject: [PATCH 140/201] git-svn: Translate invalid characters in refname In git some characters are invalid as documented in git-check-ref-format. In subversion these characters might be valid, so a translation is required. This patch does this translation by url escaping characters, that are not allowed. Credit goes to Eric Wong, martin f. krafft and Jan Hudec Signed-off-by: Robert Ewald Acked-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index 6c692a79e7..ee7ef693fa 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -938,8 +938,8 @@ sub resolve_local_globs { foreach (command(qw#for-each-ref --format=%(refname) refs/remotes#)) { next unless m#^refs/remotes/$ref->{regex}$#; my $p = $1; - my $pathname = $path->full_path($p); - my $refname = $ref->full_path($p); + my $pathname = desanitize_refname($path->full_path($p)); + my $refname = desanitize_refname($ref->full_path($p)); if (my $existing = $fetch->{$pathname}) { if ($existing ne $refname) { die "Refspec conflict:\n", @@ -1239,7 +1239,40 @@ sub new { $self; } -sub refname { "refs/remotes/$_[0]->{ref_id}" } +sub refname { + my ($refname) = "refs/remotes/$_[0]->{ref_id}" ; + + # It cannot end with a slash /, we'll throw up on this because + # SVN can't have directories with a slash in their name, either: + if ($refname =~ m{/$}) { + die "ref: '$refname' ends with a trailing slash, this is ", + "not permitted by git nor Subversion\n"; + } + + # It cannot have ASCII control character space, tilde ~, caret ^, + # colon :, question-mark ?, asterisk *, space, or open bracket [ + # anywhere. + # + # Additionally, % must be escaped because it is used for escaping + # and we want our escaped refname to be reversible + $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg; + + # no slash-separated component can begin with a dot . + # /.* becomes /%2E* + $refname =~ s{/\.}{/%2E}g; + + # It cannot have two consecutive dots .. anywhere + # .. becomes %2E%2E + $refname =~ s{\.\.}{%2E%2E}g; + + return $refname; +} + +sub desanitize_refname { + my ($refname) = @_; + $refname =~ s{%(?:([0-9A-F]{2}))}{chr hex($1)}eg; + return $refname; +} sub svm_uuid { my ($self) = @_; From 0781b8a9b2fe760fc4ed519a3a26e4b9bd6ccffe Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 30 Jul 2007 17:12:58 -0700 Subject: [PATCH 141/201] add_file_to_index: skip rehashing if the cached stat already matches An earlier commit 366bfcb6 broke git-add by moving read_cache() call down, because it wanted the directory walking code to grab paths that are already in the index. The change serves its purpose, but introduces a regression because the responsibility of avoiding unnecessary reindexing by matching the cached stat is shifted nowhere. This makes it the job of add_file_to_index() function. Signed-off-by: Junio C Hamano --- read-cache.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/read-cache.c b/read-cache.c index a363f312c7..e060392d1d 100644 --- a/read-cache.c +++ b/read-cache.c @@ -380,7 +380,7 @@ static int index_name_pos_also_unmerged(struct index_state *istate, int add_file_to_index(struct index_state *istate, const char *path, int verbose) { - int size, namelen; + int size, namelen, pos; struct stat st; struct cache_entry *ce; @@ -414,6 +414,15 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose) ce->ce_mode = ce_mode_from_stat(ent, st.st_mode); } + pos = index_name_pos(istate, ce->name, namelen); + if (0 <= pos && + !ce_stage(istate->cache[pos]) && + !ie_modified(istate, istate->cache[pos], &st, 1)) { + /* Nothing changed, really */ + free(ce); + return 0; + } + if (index_path(ce->sha1, path, &st, 1)) die("unable to index file %s", path); if (add_index_entry(istate, ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE)) From 18508c39c48d457fd095e0e30391471658698a1a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 30 Jul 2007 22:16:40 -0700 Subject: [PATCH 142/201] Unset GIT_EDITOR while running tests. Signed-off-by: Junio C Hamano --- t/test-lib.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/test-lib.sh b/t/test-lib.sh index 78d7e87e86..cc1253ccab 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -11,6 +11,7 @@ TZ=UTC export LANG LC_ALL PAGER TZ EDITOR=: VISUAL=: +unset GIT_EDITOR unset AUTHOR_DATE unset AUTHOR_EMAIL unset AUTHOR_NAME From bef19da9b663044887ecac5ee091ca93567ef331 Mon Sep 17 00:00:00 2001 From: Robert Schiele Date: Sun, 29 Jul 2007 20:35:45 +0200 Subject: [PATCH 143/201] add option to find zlib in custom path Some systems do not provide zlib development headers and libraries in default search path of the compiler. For these systems we should allow specifying the location by --with-zlib=PATH or by setting ZLIB_PATH in the makefile. Signed-off-by: Robert Schiele Signed-off-by: Junio C Hamano --- Makefile | 8 +++++++- configure.ac | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c58a4c2a09..ca1247d0e4 100644 --- a/Makefile +++ b/Makefile @@ -373,7 +373,7 @@ BUILTIN_OBJS = \ builtin-pack-refs.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) -EXTLIBS = -lz +EXTLIBS = # # Platform specific tweaks @@ -518,6 +518,12 @@ ifndef NO_CURL endif endif +ifdef ZLIB_PATH + BASIC_CFLAGS += -I$(ZLIB_PATH)/include + EXTLIBS += -L$(ZLIB_PATH)/lib $(CC_LD_DYNPATH)$(ZLIB_PATH)/lib +endif +EXTLIBS += -lz + ifndef NO_OPENSSL OPENSSL_LIBSSL = -lssl ifdef OPENSSLDIR diff --git a/configure.ac b/configure.ac index 50d2b85ace..b2f196585d 100644 --- a/configure.ac +++ b/configure.ac @@ -75,6 +75,9 @@ GIT_ARG_SET_PATH(shell) # Define PERL_PATH to provide path to Perl. GIT_ARG_SET_PATH(perl) # +# Define ZLIB_PATH to provide path to zlib. +GIT_ARG_SET_PATH(zlib) +# # Declare the with-tcltk/without-tcltk options. AC_ARG_WITH(tcltk, AS_HELP_STRING([--with-tcltk],[use Tcl/Tk GUI (default is YES)]) From cf32190aa6966dea519e77cdcc80b87026beb3b4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 31 Jul 2007 02:06:14 -0700 Subject: [PATCH 144/201] git.c: execution path The comment before executing git subcommands were stale and confusing. Noticed by Jeff King. Signed-off-by: Junio C Hamano --- git.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/git.c b/git.c index a647f9c61e..7a788b9cfc 100644 --- a/git.c +++ b/git.c @@ -443,11 +443,11 @@ int main(int argc, const char **argv) cmd = argv[0]; /* - * We search for git commands in the following order: - * - git_exec_path() - * - the path of the "git" command if we could find it - * in $0 - * - the regular PATH. + * We execute external git command via execv_git_cmd(), + * which looks at "--exec-path" option, GIT_EXEC_PATH + * environment, and $(gitexecdir) in Makefile while built, + * in this order. For scripted commands, we prepend + * the value of the exec_path variable to the PATH. */ if (exec_path) prepend_to_path(exec_path, strlen(exec_path)); From 4e0b2bbc578f8729cf43939acb36e8db02ed8825 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Tue, 31 Jul 2007 14:48:29 +0200 Subject: [PATCH 145/201] rev-list --bisect: fix allocation of "int*" instead of "int". Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin-rev-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-rev-list.c b/builtin-rev-list.c index ebf53f5944..2eb919f39c 100644 --- a/builtin-rev-list.c +++ b/builtin-rev-list.c @@ -310,7 +310,7 @@ static struct commit_list *find_bisection(struct commit_list *list, show_list("bisection 2 sorted", 0, nr, list); *all = nr; - weights = xcalloc(on_list, sizeof(int*)); + weights = xcalloc(on_list, sizeof(*weights)); counted = 0; for (n = 0, p = list; p; p = p->next) { From 10861beaa89a4cec61e04dd4954452da24b7a757 Mon Sep 17 00:00:00 2001 From: Robert Schiele Date: Wed, 1 Aug 2007 06:30:35 +0200 Subject: [PATCH 146/201] make the name of the library directory a config option Introduce new makefile variable lib to hold the name of the lib directory ("lib" by default). Also introduce a switch for configure to specify this name with --with-lib=ARG. This is useful for systems that use a different name than "lib" (like "lib64" on some 64 bit Linux architectures). Signed-off-by: Robert Schiele Signed-off-by: Junio C Hamano --- Makefile | 11 ++++++----- configure.ac | 11 +++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index ca1247d0e4..ff5fc5fbe2 100644 --- a/Makefile +++ b/Makefile @@ -151,6 +151,7 @@ sysconfdir = /etc else sysconfdir = $(prefix)/etc endif +lib = lib ETC_GITCONFIG = $(sysconfdir)/gitconfig # DESTDIR= @@ -500,9 +501,9 @@ endif ifndef NO_CURL ifdef CURLDIR - # Try "-Wl,-rpath=$(CURLDIR)/lib" in such a case. + # Try "-Wl,-rpath=$(CURLDIR)/$(lib)" in such a case. BASIC_CFLAGS += -I$(CURLDIR)/include - CURL_LIBCURL = -L$(CURLDIR)/lib $(CC_LD_DYNPATH)$(CURLDIR)/lib -lcurl + CURL_LIBCURL = -L$(CURLDIR)/$(lib) $(CC_LD_DYNPATH)$(CURLDIR)/$(lib) -lcurl else CURL_LIBCURL = -lcurl endif @@ -520,7 +521,7 @@ endif ifdef ZLIB_PATH BASIC_CFLAGS += -I$(ZLIB_PATH)/include - EXTLIBS += -L$(ZLIB_PATH)/lib $(CC_LD_DYNPATH)$(ZLIB_PATH)/lib + EXTLIBS += -L$(ZLIB_PATH)/$(lib) $(CC_LD_DYNPATH)$(ZLIB_PATH)/$(lib) endif EXTLIBS += -lz @@ -528,7 +529,7 @@ ifndef NO_OPENSSL OPENSSL_LIBSSL = -lssl ifdef OPENSSLDIR BASIC_CFLAGS += -I$(OPENSSLDIR)/include - OPENSSL_LINK = -L$(OPENSSLDIR)/lib $(CC_LD_DYNPATH)$(OPENSSLDIR)/lib + OPENSSL_LINK = -L$(OPENSSLDIR)/$(lib) $(CC_LD_DYNPATH)$(OPENSSLDIR)/$(lib) else OPENSSL_LINK = endif @@ -545,7 +546,7 @@ endif ifdef NEEDS_LIBICONV ifdef ICONVDIR BASIC_CFLAGS += -I$(ICONVDIR)/include - ICONV_LINK = -L$(ICONVDIR)/lib $(CC_LD_DYNPATH)$(ICONVDIR)/lib + ICONV_LINK = -L$(ICONVDIR)/$(lib) $(CC_LD_DYNPATH)$(ICONVDIR)/$(lib) else ICONV_LINK = endif diff --git a/configure.ac b/configure.ac index b2f196585d..84fd7f1e1f 100644 --- a/configure.ac +++ b/configure.ac @@ -69,6 +69,17 @@ fi \ ## Site configuration related to programs (before tests) ## --with-PACKAGE[=ARG] and --without-PACKAGE # +# Set lib to alternative name of lib directory (e.g. lib64) +AC_ARG_WITH([lib], + [AS_HELP_STRING([--with-lib=ARG], + [ARG specifies alternative name for lib directory])], + [if test "$withval" = "no" -o "$withval" = "yes"; then \ + AC_MSG_WARN([You should provide name for --with-lib=ARG]); \ +else \ + GIT_CONF_APPEND_LINE(lib=$withval); \ +fi; \ +],[]) +# # Define SHELL_PATH to provide path to shell. GIT_ARG_SET_PATH(shell) # From 67d454fed6ae1f127d2daa57db946df200f2382a Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Tue, 31 Jul 2007 11:58:43 +0200 Subject: [PATCH 147/201] Add an option to specify a file to config builtin There are (really!) systems where using environment variables is very cumbersome (yes, Windows, it has problems unsetting them). Besides this form is shorter. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- Documentation/git-config.txt | 29 ++++++++++++++++------------- builtin-config.c | 9 ++++++++- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 5f66a7fcd5..88acf6ce98 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -9,17 +9,17 @@ git-config - Get and set repository or global options SYNOPSIS -------- [verse] -'git-config' [--system | --global] [type] [-z|--null] name [value [value_regex]] -'git-config' [--system | --global] [type] --add name value -'git-config' [--system | --global] [type] --replace-all name [value [value_regex]] -'git-config' [--system | --global] [type] [-z|--null] --get name [value_regex] -'git-config' [--system | --global] [type] [-z|--null] --get-all name [value_regex] -'git-config' [--system | --global] [type] [-z|--null] --get-regexp name_regex [value_regex] -'git-config' [--system | --global] --unset name [value_regex] -'git-config' [--system | --global] --unset-all name [value_regex] -'git-config' [--system | --global] --rename-section old_name new_name -'git-config' [--system | --global] --remove-section name -'git-config' [--system | --global] [-z|--null] -l | --list +'git-config' [--system | --global | [-f|--file] config-file] [type] [-z|--null] name [value [value_regex]] +'git-config' [--system | --global | [-f|--file] config-file] [type] --add name value +'git-config' [--system | --global | [-f|--file] config-file] [type] --replace-all name [value [value_regex]] +'git-config' [--system | --global | [-f|--file] config-file] [type] [-z|--null] --get name [value_regex] +'git-config' [--system | --global | [-f|--file] config-file] [type] [-z|--null] --get-all name [value_regex] +'git-config' [--system | --global | [-f|--file] config-file] [type] [-z|--null] --get-regexp name_regex [value_regex] +'git-config' [--system | --global | [-f|--file] config-file] --unset name [value_regex] +'git-config' [--system | --global | [-f|--file] config-file] --unset-all name [value_regex] +'git-config' [--system | --global | [-f|--file] config-file] --rename-section old_name new_name +'git-config' [--system | --global | [-f|--file] config-file] --remove-section name +'git-config' [--system | --global | [-f|--file] config-file] [-z|--null] -l | --list DESCRIPTION ----------- @@ -42,8 +42,8 @@ no checks or transformations are performed on the value. This command will fail if: -. The .git/config file is invalid, -. Can not write to .git/config, +. The config file is invalid, +. Can not write to the config file, . no section was provided, . the section or key is invalid, . you try to unset an option which does not exist, @@ -93,6 +93,9 @@ rather than from all available files. + See also <>. +-f config-file, --file config-file:: + Use the given config file instead of the one specified by GIT_CONFIG. + --remove-section:: Remove the given section from the configuration file. diff --git a/builtin-config.c b/builtin-config.c index 7d2063c1d2..0a605e01ac 100644 --- a/builtin-config.c +++ b/builtin-config.c @@ -2,7 +2,7 @@ #include "cache.h" static const char git_config_set_usage[] = -"git-config [ --global | --system ] [ --bool | --int ] [ -z | --null ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --remove-section name | --list"; +"git-config [ --global | --system | [ -f | --file ] config-file ] [ --bool | --int ] [ -z | --null ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --remove-section name | --list"; static char *key; static regex_t *key_regexp; @@ -186,6 +186,13 @@ int cmd_config(int argc, const char **argv, const char *prefix) } else if (!strcmp(argv[1], "--system")) setenv(CONFIG_ENVIRONMENT, ETC_GITCONFIG, 1); + else if (!strcmp(argv[1], "--file") || !strcmp(argv[1], "-f")) { + if (argc < 3) + usage(git_config_set_usage); + setenv(CONFIG_ENVIRONMENT, argv[2], 1); + argc--; + argv++; + } else if (!strcmp(argv[1], "--null") || !strcmp(argv[1], "-z")) { term = '\0'; delim = '\n'; From 773a69fb09acfdfa2ce5566548d8a8a370a59fde Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Tue, 31 Jul 2007 12:30:52 +0200 Subject: [PATCH 148/201] Add a test for git-config --file Check for non-0 exit code if the confiog file does not exist and if it works exactly like when setting GIT_CONFIG. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- t/t1300-repo-config.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 187ca2df5c..1d2bf2c060 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -325,6 +325,9 @@ EOF test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect' +test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \ + 'git config --file non-existing-config -l; test $? != 0' + cat > other-config << EOF [ein] bahn = strasse @@ -338,6 +341,9 @@ GIT_CONFIG=other-config git config -l > output test_expect_success 'alternative GIT_CONFIG' 'cmp output expect' +test_expect_success 'alternative GIT_CONFIG (--file)' \ + 'git config --file other-config -l > output && cmp output expect' + GIT_CONFIG=other-config git config anwohner.park ausweis cat > expect << EOF From be52a41c4ea02fe7fabfef4ea9af821cdfd69a15 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Wed, 1 Aug 2007 00:01:17 +0200 Subject: [PATCH 149/201] Make verse of git-config manpage more readable Also mention '--file' in FILES. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- Documentation/git-config.txt | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 88acf6ce98..8451cccf8a 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -9,17 +9,17 @@ git-config - Get and set repository or global options SYNOPSIS -------- [verse] -'git-config' [--system | --global | [-f|--file] config-file] [type] [-z|--null] name [value [value_regex]] -'git-config' [--system | --global | [-f|--file] config-file] [type] --add name value -'git-config' [--system | --global | [-f|--file] config-file] [type] --replace-all name [value [value_regex]] -'git-config' [--system | --global | [-f|--file] config-file] [type] [-z|--null] --get name [value_regex] -'git-config' [--system | --global | [-f|--file] config-file] [type] [-z|--null] --get-all name [value_regex] -'git-config' [--system | --global | [-f|--file] config-file] [type] [-z|--null] --get-regexp name_regex [value_regex] -'git-config' [--system | --global | [-f|--file] config-file] --unset name [value_regex] -'git-config' [--system | --global | [-f|--file] config-file] --unset-all name [value_regex] -'git-config' [--system | --global | [-f|--file] config-file] --rename-section old_name new_name -'git-config' [--system | --global | [-f|--file] config-file] --remove-section name -'git-config' [--system | --global | [-f|--file] config-file] [-z|--null] -l | --list +'git-config' [] [type] [-z|--null] name [value [value_regex]] +'git-config' [] [type] --add name value +'git-config' [] [type] --replace-all name [value [value_regex]] +'git-config' [] [type] [-z|--null] --get name [value_regex] +'git-config' [] [type] [-z|--null] --get-all name [value_regex] +'git-config' [] [type] [-z|--null] --get-regexp name_regex [value_regex] +'git-config' [] --unset name [value_regex] +'git-config' [] --unset-all name [value_regex] +'git-config' [] --rename-section old_name new_name +'git-config' [] --remove-section name +'git-config' [] [-z|--null] -l | --list DESCRIPTION ----------- @@ -40,6 +40,12 @@ convert the value to the canonical form (simple decimal number for int, a "true" or "false" string for bool). If no type specifier is passed, no checks or transformations are performed on the value. +The file-option can be one of '--system', '--global' or '--file' +which specify where the values will be read from or written to. +The default is to assume the config file of the current repository, +.git/config unless defined otherwise with GIT_DIR and GIT_CONFIG +(see <>). + This command will fail if: . The config file is invalid, @@ -133,8 +139,8 @@ See also <>. FILES ----- -There are three files where git-config will search for configuration -options: +If not set explicitely with '--file', there are three files where +git-config will search for configuration options: .git/config:: Repository specific configuration file. (The filename is From 61988f1127587f8597b8b41da78a65717851e1fa Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 31 Jul 2007 23:03:41 -0700 Subject: [PATCH 150/201] git.el: Avoid using ewoc-set-data for compatibility with Emacs 21. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexandre Julliard Acked-by: Karl Hasselström 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 53dd703260..7470f13185 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -530,7 +530,7 @@ and returns the process output as a string." (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)))) + (if node (setf (ewoc-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. From 274e13e0e9c7e475bbc342a10d614dd40b0e4c15 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 31 Jul 2007 12:36:32 +0200 Subject: [PATCH 151/201] git.el: Take into account the core.excludesfile config option. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also don't require .git/info/exclude to exist in order to list unknown files. Signed-off-by: Alexandre Julliard Acked-by: Karl Hasselström Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index 7470f13185..f6102fc344 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -589,6 +589,16 @@ Return the list of files that haven't been handled." (when node (push (ewoc-data node) unmerged-files)))) (git-set-files-state unmerged-files 'unmerged)))) +(defun git-get-exclude-files () + "Get the list of exclude files to pass to git-ls-files." + (let (files + (config (git-config "core.excludesfile"))) + (when (file-readable-p ".git/info/exclude") + (push ".git/info/exclude" files)) + (when (and config (file-readable-p config)) + (push config files)) + files)) + (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.")) @@ -598,11 +608,11 @@ Return the list of files that haven't been handled." (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)))) + (when (or (not files) remaining-files) + (let ((exclude-files (git-get-exclude-files))) + (setq remaining-files (apply #'git-run-ls-files status remaining-files 'unknown "-o" + (concat "--exclude-per-directory=" git-per-dir-ignore-file) + (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files))))) ; mark remaining files with the default state (or remove them if nil) (when remaining-files (if default-state From 12ace0b20de33d57100435a60e09bb3971420003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Tue, 31 Jul 2007 15:37:30 -0400 Subject: [PATCH 152/201] Add test case for basic commit functionality. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kristian Høgsberg Signed-off-by: Junio C Hamano --- t/t7501-commit.sh | 134 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 t/t7501-commit.sh diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh new file mode 100644 index 0000000000..8cc2cd9e60 --- /dev/null +++ b/t/t7501-commit.sh @@ -0,0 +1,134 @@ +#!/bin/sh +# +# Copyright (c) 2007 Kristian Høgsberg +# + +# FIXME: Test the various index usages, -i and -o, test reflog, +# signoff, hooks + +test_description='git-commit' +. ./test-lib.sh + +test_tick + +test_expect_success \ + "initial status" \ + "echo 'bongo bongo' >file && + git-add file && \ + git-status | grep 'Initial commit'" + +test_expect_failure \ + "fail initial amend" \ + "git-commit --amend" + +test_expect_success \ + "initial commit" \ + "git-commit -m initial" + +test_expect_failure \ + "invalid options 1" \ + "git-commit --amend -F file" + +test_expect_failure \ + "invalid options 2" \ + "git-commit -C HEAD -m illegal" + +test_expect_failure \ + "using invalid commit with -C" \ + "git-commit -C bogus" + +test_expect_failure \ + "testing nothing to commit" \ + "git-commit -m initial" + +test_expect_success \ + "next commit" \ + "echo 'bongo bongo bongo' >file \ + git-commit -m next -a" + +test_expect_failure \ + "commit message from non-existing file" \ + "echo 'more bongo: bongo bongo bongo bongo' >file && \ + git-commit -F gah -a" + +# Empty except stray tabs and spaces on a few lines. +sed -e 's/@$//' >msg <msg && \ + git-commit -F msg -a" + +cat >editor <<\EOF +#!/bin/sh +sed -i -e "s/a file/an amend commit/g" $1 +EOF +chmod 755 editor + +test_expect_success \ + "amend commit" \ + "VISUAL=./editor git-commit --amend" + +test_expect_failure \ + "passing --amend and -F" \ + "echo 'enough with the bongos' >file && \ + git-commit -F msg --amend ." + +test_expect_success \ + "using message from other commit" \ + "git-commit -C HEAD^ ." + +cat >editor <<\EOF +#!/bin/sh +sed -i -e "s/amend/older/g" $1 +EOF +chmod 755 editor + +test_expect_success \ + "editing message from other commit" \ + "echo 'hula hula' >file && \ + VISUAL=./editor git-commit -c HEAD^ -a" + +test_expect_success \ + "message from stdin" \ + "echo 'silly new contents' >file && \ + echo commit message from stdin | git-commit -F - -a" + +test_expect_success \ + "overriding author from command line" \ + "echo 'gak' >file && \ + git-commit -m 'author' --author 'Rubber Duck ' -a" + +test_expect_success \ + "interactive add" \ + "echo 7 | git-commit --interactive | grep 'What now'" + +test_expect_success \ + "showing committed revisions" \ + "git-rev-list HEAD >current" + +# We could just check the head sha1, but checking each commit makes it +# easier to isolate bugs. + +cat >expected <<\EOF +72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca +9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2 +3536bbb352c3a1ef9a420f5b4242d48578b92aa7 +d381ac431806e53f3dd7ac2f1ae0534f36d738b9 +4fd44095ad6334f3ef72e4c5ec8ddf108174b54a +402702b49136e7587daa9280e91e4bb7cb2179f7 +EOF + +test_expect_success \ + 'validate git-rev-list output.' \ + 'diff current expected' + +test_done From 73a7a65663223d08d8cabac8d873de21b7e9678d Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 27 Jul 2007 14:00:29 -0700 Subject: [PATCH 153/201] --base-path-relaxed option I switched git.kernel.dk to --base-path a few minutes ago, to get rid of a /data/git postfix in the posted urls. But transitioning is tricky, since now all old paths will fail miserably. So I added this --base-path-relaxed option, that will make git-daemon try the absolute path without prefixing --base-path before giving up. With this in place and --base-path-relaxed added, both my new url of git://git.kernel.dk/linux-2.6-block.git and the old git://git.kernel.dk/data/git/linux-2.6-block.git work fine. Signed-off-by: Jens Axboe Signed-off-by: Junio C Hamano --- Documentation/git-daemon.txt | 6 ++++++ daemon.c | 26 ++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt index 4b30b18b42..f902161c08 100644 --- a/Documentation/git-daemon.txt +++ b/Documentation/git-daemon.txt @@ -54,6 +54,12 @@ OPTIONS 'git://example.com/hello.git', `git-daemon` will interpret the path as '/srv/git/hello.git'. +--base-path-relaxed:: + If --base-path is enabled and repo lookup fails, with this option + `git-daemon` will attempt to lookup without prefixing the base path. + This is useful for switching to --base-path usage, while still + allowing the old paths. + --interpolated-path=pathtemplate:: To support virtual hosting, an interpolated path template can be used to dynamically construct alternate paths. The template diff --git a/daemon.c b/daemon.c index a3f2ac1d81..9cf22fef41 100644 --- a/daemon.c +++ b/daemon.c @@ -16,7 +16,8 @@ static int reuseaddr; static const char daemon_usage[] = "git-daemon [--verbose] [--syslog] [--export-all]\n" " [--timeout=n] [--init-timeout=n] [--strict-paths]\n" -" [--base-path=path] [--user-path | --user-path=path]\n" +" [--base-path=path] [--base-path-relaxed]\n" +" [--user-path | --user-path=path]\n" " [--interpolated-path=path]\n" " [--reuseaddr] [--detach] [--pid-file=file]\n" " [--[enable|disable|allow-override|forbid-override]=service]\n" @@ -34,6 +35,7 @@ static int export_all_trees; /* Take all paths relative to this one if non-NULL */ static char *base_path; static char *interpolated_path; +static int base_path_relaxed; /* Flag indicating client sent extra args. */ static int saw_extended_args; @@ -180,6 +182,7 @@ static char *path_ok(struct interp *itable) { static char rpath[PATH_MAX]; static char interp_path[PATH_MAX]; + int retried_path = 0; char *path; char *dir; @@ -235,7 +238,22 @@ static char *path_ok(struct interp *itable) dir = rpath; } - path = enter_repo(dir, strict_paths); + do { + path = enter_repo(dir, strict_paths); + if (path) + break; + + /* + * if we fail and base_path_relaxed is enabled, try without + * prefixing the base path + */ + if (base_path && base_path_relaxed && !retried_path) { + dir = itable[INTERP_SLOT_DIR].value; + retried_path = 1; + continue; + } + break; + } while (1); if (!path) { logerror("'%s': unable to chdir or not a git archive", dir); @@ -1061,6 +1079,10 @@ int main(int argc, char **argv) base_path = arg+12; continue; } + if (!strcmp(arg, "--base-path-relaxed")) { + base_path_relaxed = 1; + continue; + } if (!prefixcmp(arg, "--interpolated-path=")) { interpolated_path = arg+20; continue; From e5392c51469c25851f9c6e53165d75fc61901768 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Aug 2007 01:28:59 +0100 Subject: [PATCH 154/201] Add is_absolute_path() and make_absolute_path() This patch adds convenience functions to work with absolute paths. The function is_absolute_path() should help the efforts to integrate the MinGW fork. Note that make_absolute_path() returns a pointer to a static buffer. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Makefile | 2 +- cache.h | 5 ++++ path.c | 65 ++++++++++++++++++++++++++++++++++++++++++++ t/t0000-basic.sh | 16 +++++++++++ test-absolute-path.c | 11 ++++++++ 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 test-absolute-path.c diff --git a/Makefile b/Makefile index ff5fc5fbe2..b593446efb 100644 --- a/Makefile +++ b/Makefile @@ -944,7 +944,7 @@ endif ### Testing rules -TEST_PROGRAMS = test-chmtime$X test-genrandom$X test-date$X test-delta$X test-sha1$X test-match-trees$X +TEST_PROGRAMS = test-chmtime$X test-genrandom$X test-date$X test-delta$X test-sha1$X test-match-trees$X test-absolute-path$X all:: $(TEST_PROGRAMS) diff --git a/cache.h b/cache.h index 53801b8089..98af53040d 100644 --- a/cache.h +++ b/cache.h @@ -358,6 +358,11 @@ int git_config_perm(const char *var, const char *value); int adjust_shared_perm(const char *path); int safe_create_leading_directories(char *path); char *enter_repo(char *path, int strict); +static inline int is_absolute_path(const char *path) +{ + return path[0] == '/'; +} +const char *make_absolute_path(const char *path); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); diff --git a/path.c b/path.c index dfff41f626..42609524a5 100644 --- a/path.c +++ b/path.c @@ -288,3 +288,68 @@ int adjust_shared_perm(const char *path) return -2; return 0; } + +/* We allow "recursive" symbolic links. Only within reason, though. */ +#define MAXDEPTH 5 + +const char *make_absolute_path(const char *path) +{ + static char bufs[2][PATH_MAX + 1], *buf = bufs[0], *next_buf = bufs[1]; + char cwd[1024] = ""; + int buf_index = 1, len; + + int depth = MAXDEPTH; + char *last_elem = NULL; + struct stat st; + + if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX) + die ("Too long path: %.*s", 60, path); + + while (depth--) { + if (stat(buf, &st) || !S_ISDIR(st.st_mode)) { + char *last_slash = strrchr(buf, '/'); + if (last_slash) { + *last_slash = '\0'; + last_elem = xstrdup(last_slash + 1); + } else + last_elem = xstrdup(buf); + } + + if (*buf) { + if (!*cwd && !getcwd(cwd, sizeof(cwd))) + die ("Could not get current working directory"); + + if (chdir(buf)) + die ("Could not switch to '%s'", buf); + } + if (!getcwd(buf, PATH_MAX)) + die ("Could not get current working directory"); + + if (last_elem) { + int len = strlen(buf); + if (len + strlen(last_elem) + 2 > PATH_MAX) + die ("Too long path name: '%s/%s'", + buf, last_elem); + buf[len] = '/'; + strcpy(buf + len + 1, last_elem); + free(last_elem); + last_elem = NULL; + } + + if (!lstat(buf, &st) && S_ISLNK(st.st_mode)) { + len = readlink(buf, next_buf, PATH_MAX); + if (len < 0) + die ("Invalid symlink: %s", buf); + next_buf[len] = '\0'; + buf = next_buf; + buf_index = 1 - buf_index; + next_buf = bufs[buf_index]; + } else + break; + } + + if (*cwd && chdir(cwd)) + die ("Could not change back to '%s'", cwd); + + return buf; +} diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 4bba9c0717..4e49d59065 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -281,4 +281,20 @@ test_expect_success 'update-index D/F conflict' ' test $numpath0 = 1 ' +test_expect_success 'absolute path works as expected' ' + mkdir first && + ln -s ../.git first/.git && + mkdir second && + ln -s ../first second/other && + mkdir third && + dir="$(cd .git; pwd -P)" && + dir2=third/../second/other/.git && + test "$dir" = "$(test-absolute-path $dir2)" && + file="$dir"/index && + test "$file" = "$(test-absolute-path $dir2/index)" && + ln -s ../first/file .git/syml && + sym="$(cd first; pwd -P)"/file && + test "$sym" = "$(test-absolute-path $dir2/syml)" +' + test_done diff --git a/test-absolute-path.c b/test-absolute-path.c new file mode 100644 index 0000000000..c959ea20d3 --- /dev/null +++ b/test-absolute-path.c @@ -0,0 +1,11 @@ +#include "cache.h" + +int main(int argc, char **argv) +{ + while (argc > 1) { + puts(make_absolute_path(argv[1])); + argc--; + argv++; + } + return 0; +} From e663674722d8a64a208d8c176d5bfc340c04b964 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Aug 2007 01:29:17 +0100 Subject: [PATCH 155/201] Add functions get_relative_cwd() and is_inside_dir() The function get_relative_cwd() works just as getcwd(), only that it takes an absolute path as additional parameter, returning the prefix of the current working directory relative to the given path. If the cwd is no subdirectory of the given path, it returns NULL. is_inside_dir() is just a trivial wrapper over get_relative_cwd(). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- dir.c | 38 ++++++++++++++++++++++++++++++++++++++ dir.h | 3 +++ 2 files changed, 41 insertions(+) diff --git a/dir.c b/dir.c index 8d8faf5d78..b3329f41b2 100644 --- a/dir.c +++ b/dir.c @@ -642,3 +642,41 @@ file_exists(const char *f) struct stat sb; return stat(f, &sb) == 0; } + +/* + * get_relative_cwd() gets the prefix of the current working directory + * relative to 'dir'. If we are not inside 'dir', it returns NULL. + * As a convenience, it also returns NULL if 'dir' is already NULL. + */ +char *get_relative_cwd(char *buffer, int size, const char *dir) +{ + char *cwd = buffer; + + /* + * a lazy caller can pass a NULL returned from get_git_work_tree() + * and rely on this function to return NULL. + */ + if (!dir) + return NULL; + if (!getcwd(buffer, size)) + die("can't find the current directory: %s", strerror(errno)); + + if (!is_absolute_path(dir)) + dir = make_absolute_path(dir); + + while (*dir && *dir == *cwd) { + dir++; + cwd++; + } + if (*dir) + return NULL; + if (*cwd == '/') + return cwd + 1; + return cwd; +} + +int is_inside_dir(const char *dir) +{ + char buffer[PATH_MAX]; + return get_relative_cwd(buffer, sizeof(buffer), dir) != NULL; +} diff --git a/dir.h b/dir.h index ec0e8ababc..f55a87b2cd 100644 --- a/dir.h +++ b/dir.h @@ -61,4 +61,7 @@ extern void add_exclude(const char *string, const char *base, extern int file_exists(const char *); extern struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len); +extern char *get_relative_cwd(char *buffer, int size, const char *dir); +extern int is_inside_dir(const char *dir); + #endif From d7ac12b25d375d32372b13f74e90425ca21d5dc1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Aug 2007 01:29:38 +0100 Subject: [PATCH 156/201] Add set_git_dir() function With the function set_git_dir() you can reset the path that will be used for git_path(), git_dir() and friends. The responsibility to close files and throw away information from the old git_dir lies with the caller. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 1 + environment.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/cache.h b/cache.h index 98af53040d..e1f94cbade 100644 --- a/cache.h +++ b/cache.h @@ -214,6 +214,7 @@ extern char *get_object_directory(void); extern char *get_refs_directory(void); extern char *get_index_file(void); extern char *get_graft_file(void); +extern int set_git_dir(const char *path); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" diff --git a/environment.c b/environment.c index f83fb9e448..a571fae607 100644 --- a/environment.c +++ b/environment.c @@ -107,3 +107,11 @@ char *get_graft_file(void) setup_git_env(); return git_graft_file; } + +int set_git_dir(const char *path) +{ + if (setenv(GIT_DIR_ENVIRONMENT, path, 1)) + return error("Could not set GIT_DIR to '%s'", path); + setup_git_env(); + return 0; +} From e90fdc39b6903502192b2dd11e5503cea721a1ad Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Aug 2007 01:30:14 +0100 Subject: [PATCH 157/201] Clean up work-tree handling The old version of work-tree support was an unholy mess, barely readable, and not to the point. For example, why do you have to provide a worktree, when it is not used? As in "git status". Now it works. Another riddle was: if you can have work trees inside the git dir, why are some programs complaining that they need a work tree? IOW it is allowed to call $ git --git-dir=../ --work-tree=. bla when you really want to. In this case, you are both in the git directory and in the working tree. So, programs have to actually test for the right thing, namely if they are inside a working tree, and not if they are inside a git directory. Also, GIT_DIR=../.git should behave the same as if no GIT_DIR was specified, unless there is a repository in the current working directory. It does now. The logic to determine if a repository is bare, or has a work tree (tertium non datur), is this: --work-tree=bla overrides GIT_WORK_TREE, which overrides core.bare = true, which overrides core.worktree, which overrides GIT_DIR/.. when GIT_DIR ends in /.git, which overrides the directory in which .git/ was found. In related news, a long standing bug was fixed: when in .git/bla/x.git/, which is a bare repository, git formerly assumed ../.. to be the appropriate git dir. This problem was reported by Shawn Pearce to have caused much pain, where a colleague mistakenly ran "git init" in "/" a long time ago, and bare repositories just would not work. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-init-db.c | 48 ++------ builtin-ls-files.c | 8 +- builtin-rev-parse.c | 7 ++ cache.h | 2 + environment.c | 35 ++++-- git-sh-setup.sh | 3 +- git.c | 11 +- setup.c | 279 ++++++++++++++++++++----------------------- t/t1500-rev-parse.sh | 20 ++-- t/t1501-worktree.sh | 24 +++- 10 files changed, 216 insertions(+), 221 deletions(-) diff --git a/builtin-init-db.c b/builtin-init-db.c index 66ddaebcc5..0d9b1e0559 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -174,36 +174,7 @@ static void copy_templates(const char *git_dir, int len, const char *template_di closedir(dir); } -/* - * Get the full path to the working tree specified in $GIT_WORK_TREE - * or NULL if no working tree is specified. - */ -static const char *get_work_tree(void) -{ - const char *git_work_tree; - char cwd[PATH_MAX]; - static char worktree[PATH_MAX]; - - git_work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT); - if (!git_work_tree) - return NULL; - if (!getcwd(cwd, sizeof(cwd))) - die("Unable to read current working directory"); - if (chdir(git_work_tree)) - die("Cannot change directory to specified working tree '%s'", - git_work_tree); - if (git_work_tree[0] != '/') { - if (!getcwd(worktree, sizeof(worktree))) - die("Unable to read current working directory"); - git_work_tree = worktree; - } - if (chdir(cwd)) - die("Cannot come back to cwd"); - return git_work_tree; -} - -static int create_default_files(const char *git_dir, const char *git_work_tree, - const char *template_path) +static int create_default_files(const char *git_dir, const char *template_path) { unsigned len = strlen(git_dir); static char path[PATH_MAX]; @@ -282,16 +253,16 @@ static int create_default_files(const char *git_dir, const char *git_work_tree, } git_config_set("core.filemode", filemode ? "true" : "false"); - if (is_bare_repository() && !git_work_tree) { + if (is_bare_repository()) git_config_set("core.bare", "true"); - } else { + const char *work_tree = get_git_work_tree(); git_config_set("core.bare", "false"); /* allow template config file to override the default */ if (log_all_ref_updates == -1) git_config_set("core.logallrefupdates", "true"); - if (git_work_tree) - git_config_set("core.worktree", git_work_tree); + if (work_tree != git_work_tree_cfg) + git_config_set("core.worktree", work_tree); } return reinit; } @@ -308,7 +279,6 @@ static const char init_db_usage[] = int cmd_init_db(int argc, const char **argv, const char *prefix) { const char *git_dir; - const char *git_work_tree; const char *sha1_dir; const char *template_dir = NULL; char *path; @@ -329,7 +299,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) usage(init_db_usage); } - git_work_tree = get_work_tree(); + git_work_tree_cfg = xcalloc(PATH_MAX, 1); + if (!getcwd(git_work_tree_cfg, PATH_MAX)) + die ("Cannot access current working directory."); + if (access(get_git_work_tree(), X_OK)) + die ("Cannot access work tree '%s'", get_git_work_tree()); /* * Set up the default .git directory contents @@ -346,7 +320,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) */ check_repository_format(); - reinit = create_default_files(git_dir, git_work_tree, template_dir); + reinit = create_default_files(git_dir, template_dir); /* * And set up the object store. diff --git a/builtin-ls-files.c b/builtin-ls-files.c index 61577ea13f..d36181a755 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -469,9 +469,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) break; } - if (require_work_tree && - (!is_inside_work_tree() || is_inside_git_dir())) - die("This operation must be run in a work tree"); + if (require_work_tree && !is_inside_work_tree()) { + const char *work_tree = get_git_work_tree(); + if (!work_tree || chdir(work_tree)) + die("This operation must be run in a work tree"); + } pathspec = get_pathspec(prefix, argv + i); diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c index 497903a85a..8d78b69c90 100644 --- a/builtin-rev-parse.c +++ b/builtin-rev-parse.c @@ -321,6 +321,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) } if (!strcmp(arg, "--show-cdup")) { const char *pfx = prefix; + if (!is_inside_work_tree()) { + const char *work_tree = + get_git_work_tree(); + if (work_tree) + printf("%s\n", work_tree); + continue; + } while (pfx) { pfx = strchr(pfx, '/'); if (pfx) { diff --git a/cache.h b/cache.h index e1f94cbade..e97af18eea 100644 --- a/cache.h +++ b/cache.h @@ -208,6 +208,7 @@ enum object_type { extern int is_bare_repository_cfg; extern int is_bare_repository(void); extern int is_inside_git_dir(void); +extern char *git_work_tree_cfg; extern int is_inside_work_tree(void); extern const char *get_git_dir(void); extern char *get_object_directory(void); @@ -215,6 +216,7 @@ extern char *get_refs_directory(void); extern char *get_index_file(void); extern char *get_graft_file(void); extern int set_git_dir(const char *path); +extern const char *get_git_work_tree(void); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" diff --git a/environment.c b/environment.c index a571fae607..2af12fd689 100644 --- a/environment.c +++ b/environment.c @@ -35,6 +35,10 @@ int pager_in_use; int pager_use_color = 1; int auto_crlf = 0; /* 1: both ways, -1: only when adding git objects */ +/* This is set by setup_git_dir_gently() and/or git_default_config() */ +char *git_work_tree_cfg; +static const char *work_tree; + static const char *git_dir; static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file; @@ -62,15 +66,8 @@ static void setup_git_env(void) int is_bare_repository(void) { - const char *dir, *s; - if (0 <= is_bare_repository_cfg) - return is_bare_repository_cfg; - - dir = get_git_dir(); - if (!strcmp(dir, DEFAULT_GIT_DIR_ENVIRONMENT)) - return 0; - s = strrchr(dir, '/'); - return !s || strcmp(s + 1, DEFAULT_GIT_DIR_ENVIRONMENT); + /* if core.bare is not 'false', let's see if there is a work tree */ + return is_bare_repository_cfg && !get_git_work_tree(); } const char *get_git_dir(void) @@ -80,6 +77,26 @@ const char *get_git_dir(void) return git_dir; } +const char *get_git_work_tree(void) +{ + static int initialized = 0; + if (!initialized) { + work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT); + /* core.bare = true overrides implicit and config work tree */ + if (!work_tree && is_bare_repository_cfg < 1) { + work_tree = git_work_tree_cfg; + /* make_absolute_path also normalizes the path */ + if (work_tree && !is_absolute_path(work_tree)) + work_tree = xstrdup(make_absolute_path(git_path(work_tree))); + } else if (work_tree) + work_tree = xstrdup(make_absolute_path(work_tree)); + initialized = 1; + if (work_tree) + is_bare_repository_cfg = 0; + } + return work_tree; +} + char *get_object_directory(void) { if (!git_object_dir) diff --git a/git-sh-setup.sh b/git-sh-setup.sh index c51985e4c3..7bef43f39d 100755 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -59,8 +59,7 @@ cd_to_toplevel () { } require_work_tree () { - test $(git rev-parse --is-inside-work-tree) = true && - test $(git rev-parse --is-inside-git-dir) = false || + test $(git rev-parse --is-inside-work-tree) = true || die "fatal: $0 cannot be used without a working tree." } diff --git a/git.c b/git.c index 7a788b9cfc..25b8274d3e 100644 --- a/git.c +++ b/git.c @@ -272,9 +272,14 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv) prefix = setup_git_directory(); if (p->option & USE_PAGER) setup_pager(); - if ((p->option & NEED_WORK_TREE) && - (!is_inside_work_tree() || is_inside_git_dir())) - die("%s must be run in a work tree", p->cmd); + if (p->option & NEED_WORK_TREE) { + const char *work_tree = get_git_work_tree(); + const char *git_dir = get_git_dir(); + if (!is_absolute_path(git_dir)) + set_git_dir(make_absolute_path(git_dir)); + if (!work_tree || chdir(work_tree)) + die("%s must be run in a work tree", p->cmd); + } trace_argv_printf(argv, argc, "trace: built-in: git"); status = p->fn(argc, argv, prefix); diff --git a/setup.c b/setup.c index b54d65fd07..3653092ab6 100644 --- a/setup.c +++ b/setup.c @@ -1,4 +1,8 @@ #include "cache.h" +#include "dir.h" + +static int inside_git_dir = -1; +static int inside_work_tree = -1; const char *prefix_path(const char *prefix, int len, const char *path) { @@ -170,100 +174,89 @@ static int is_git_directory(const char *suspect) return 1; } -static int inside_git_dir = -1; - int is_inside_git_dir(void) { - if (inside_git_dir >= 0) - return inside_git_dir; - die("BUG: is_inside_git_dir called before setup_git_directory"); + if (inside_git_dir < 0) + inside_git_dir = is_inside_dir(get_git_dir()); + return inside_git_dir; } -static int inside_work_tree = -1; - int is_inside_work_tree(void) { - if (inside_git_dir >= 0) - return inside_work_tree; - die("BUG: is_inside_work_tree called before setup_git_directory"); + if (inside_work_tree < 0) + inside_work_tree = is_inside_dir(get_git_work_tree()); + return inside_work_tree; } -static char *gitworktree_config; - -static int git_setup_config(const char *var, const char *value) +/* + * If no worktree was given, and we are outside of a default work tree, + * now is the time to set it. + * + * In other words, if the user calls git with something like + * + * git --git-dir=/some/where/else/.git bla + * + * default to /some/where/else as working directory; if the specified + * git-dir does not end in "/.git", the cwd is used as working directory. + */ +const char *set_work_tree(const char *dir) { - if (!strcmp(var, "core.worktree")) { - if (gitworktree_config) - strlcpy(gitworktree_config, value, PATH_MAX); - return 0; + char dir_buffer[PATH_MAX]; + static char buffer[PATH_MAX + 1], *rel = NULL; + int len, postfix_len = strlen(DEFAULT_GIT_DIR_ENVIRONMENT) + 1; + + /* strip the variable 'dir' of the postfix "/.git" if it has it */ + len = strlen(dir); + if (len > postfix_len && !strcmp(dir + len - postfix_len, + "/" DEFAULT_GIT_DIR_ENVIRONMENT)) { + strncpy(dir_buffer, dir, len - postfix_len); + + /* are we inside the default work tree? */ + rel = get_relative_cwd(buffer, sizeof(buffer), dir_buffer); } - return git_default_config(var, value); + /* if rel is set, the cwd is _not_ the current working tree */ + if (rel && *rel) { + if (!is_absolute_path(dir)) + set_git_dir(make_absolute_path(dir)); + dir = dir_buffer; + chdir(dir); + strcat(rel, "/"); + inside_git_dir = 0; + } else { + rel = NULL; + dir = getcwd(buffer, sizeof(buffer)); + } + git_work_tree_cfg = xstrdup(dir); + inside_work_tree = 1; + + return rel; } +/* + * We cannot decide in this function whether we are in the work tree or + * not, since the config can only be read _after_ this function was called. + */ const char *setup_git_directory_gently(int *nongit_ok) { + const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT); static char cwd[PATH_MAX+1]; - char worktree[PATH_MAX+1], gitdir[PATH_MAX+1]; - const char *gitdirenv, *gitworktree; - int wt_rel_gitdir = 0; + const char *gitdirenv; + int len, offset; + /* + * If GIT_DIR is set explicitly, we're not going + * to do any discovery, but we still do repository + * validation. + */ gitdirenv = getenv(GIT_DIR_ENVIRONMENT); - if (!gitdirenv) { - int len, offset; - - if (!getcwd(cwd, sizeof(cwd)-1)) - die("Unable to read current working directory"); - - offset = len = strlen(cwd); - for (;;) { - if (is_git_directory(".git")) - break; - if (offset == 0) { - offset = -1; - break; - } - chdir(".."); - while (cwd[--offset] != '/') - ; /* do nothing */ - } - - if (offset >= 0) { - inside_work_tree = 1; - git_config(git_default_config); - if (offset == len) { - inside_git_dir = 0; - return NULL; - } - - cwd[len++] = '/'; - cwd[len] = '\0'; - inside_git_dir = !prefixcmp(cwd + offset + 1, ".git/"); - return cwd + offset + 1; - } - - if (chdir(cwd)) - die("Cannot come back to cwd"); - if (!is_git_directory(".")) { - if (nongit_ok) { - *nongit_ok = 1; - return NULL; - } - die("Not a git repository"); - } - setenv(GIT_DIR_ENVIRONMENT, cwd, 1); - gitdirenv = getenv(GIT_DIR_ENVIRONMENT); - if (!gitdirenv) - die("getenv after setenv failed"); - } - - if (PATH_MAX - 40 < strlen(gitdirenv)) { - if (nongit_ok) { - *nongit_ok = 1; + if (gitdirenv) { + if (PATH_MAX - 40 < strlen(gitdirenv)) + die("'$%s' too big", GIT_DIR_ENVIRONMENT); + if (is_git_directory(gitdirenv)) { + if (!work_tree_env) + return set_work_tree(gitdirenv); return NULL; } - die("$%s too big", GIT_DIR_ENVIRONMENT); - } - if (!is_git_directory(gitdirenv)) { if (nongit_ok) { *nongit_ok = 1; return NULL; @@ -273,92 +266,53 @@ const char *setup_git_directory_gently(int *nongit_ok) if (!getcwd(cwd, sizeof(cwd)-1)) die("Unable to read current working directory"); - if (chdir(gitdirenv)) { - if (nongit_ok) { - *nongit_ok = 1; - return NULL; - } - die("Cannot change directory to $%s '%s'", - GIT_DIR_ENVIRONMENT, gitdirenv); - } - if (!getcwd(gitdir, sizeof(gitdir)-1)) - die("Unable to read current working directory"); - if (chdir(cwd)) - die("Cannot come back to cwd"); /* - * In case there is a work tree we may change the directory, - * therefore make GIT_DIR an absolute path. + * Test in the following order (relative to the cwd): + * - .git/ + * - ./ (bare) + * - ../.git/ + * - ../ (bare) + * - ../../.git/ + * etc. */ - if (gitdirenv[0] != '/') { - setenv(GIT_DIR_ENVIRONMENT, gitdir, 1); - gitdirenv = getenv(GIT_DIR_ENVIRONMENT); - if (!gitdirenv) - die("getenv after setenv failed"); - if (PATH_MAX - 40 < strlen(gitdirenv)) { - if (nongit_ok) { - *nongit_ok = 1; - return NULL; - } - die("$%s too big after expansion to absolute path", - GIT_DIR_ENVIRONMENT); - } - } - - strcat(cwd, "/"); - strcat(gitdir, "/"); - inside_git_dir = !prefixcmp(cwd, gitdir); - - gitworktree = getenv(GIT_WORK_TREE_ENVIRONMENT); - if (!gitworktree) { - gitworktree_config = worktree; - worktree[0] = '\0'; - } - git_config(git_setup_config); - if (!gitworktree) { - gitworktree_config = NULL; - if (worktree[0]) - gitworktree = worktree; - if (gitworktree && gitworktree[0] != '/') - wt_rel_gitdir = 1; - } - - if (wt_rel_gitdir && chdir(gitdirenv)) - die("Cannot change directory to $%s '%s'", - GIT_DIR_ENVIRONMENT, gitdirenv); - if (gitworktree && chdir(gitworktree)) { - if (nongit_ok) { - if (wt_rel_gitdir && chdir(cwd)) - die("Cannot come back to cwd"); - *nongit_ok = 1; + offset = len = strlen(cwd); + for (;;) { + if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT)) + break; + if (is_git_directory(".")) { + inside_git_dir = 1; + if (!work_tree_env) + inside_work_tree = 0; + setenv(GIT_DIR_ENVIRONMENT, ".", 1); return NULL; } - if (wt_rel_gitdir) - die("Cannot change directory to working tree '%s'" - " from $%s", gitworktree, GIT_DIR_ENVIRONMENT); - else - die("Cannot change directory to working tree '%s'", - gitworktree); - } - if (!getcwd(worktree, sizeof(worktree)-1)) - die("Unable to read current working directory"); - strcat(worktree, "/"); - inside_work_tree = !prefixcmp(cwd, worktree); - - if (gitworktree && inside_work_tree && !prefixcmp(worktree, gitdir) && - strcmp(worktree, gitdir)) { - inside_git_dir = 0; + chdir(".."); + do { + if (!offset) { + if (nongit_ok) { + if (chdir(cwd)) + die("Cannot come back to cwd"); + *nongit_ok = 1; + return NULL; + } + die("Not a git repository"); + } + } while (cwd[--offset] != '/'); } - if (!inside_work_tree) { - if (chdir(cwd)) - die("Cannot come back to cwd"); + inside_git_dir = 0; + if (!work_tree_env) + inside_work_tree = 1; + git_work_tree_cfg = xstrndup(cwd, offset); + if (offset == len) return NULL; - } - if (!strcmp(cwd, worktree)) - return NULL; - return cwd+strlen(worktree); + /* Make "offset" point to past the '/', and add a '/' at the end */ + offset++; + cwd[len++] = '/'; + cwd[len] = 0; + return cwd + offset; } int git_config_perm(const char *var, const char *value) @@ -386,6 +340,16 @@ int check_repository_format_version(const char *var, const char *value) repository_format_version = git_config_int(var, value); else if (strcmp(var, "core.sharedrepository") == 0) shared_repository = git_config_perm(var, value); + else if (strcmp(var, "core.bare") == 0) { + is_bare_repository_cfg = git_config_bool(var, value); + if (is_bare_repository_cfg == 1) + inside_work_tree = -1; + } else if (strcmp(var, "core.worktree") == 0) { + if (git_work_tree_cfg) + free(git_work_tree_cfg); + git_work_tree_cfg = xstrdup(value); + inside_work_tree = -1; + } return 0; } @@ -402,5 +366,16 @@ const char *setup_git_directory(void) { const char *retval = setup_git_directory_gently(NULL); check_repository_format(); + + /* If the work tree is not the default one, recompute prefix */ + if (inside_work_tree < 0) { + static char buffer[PATH_MAX + 1]; + char *rel; + if (retval && chdir(retval)) + die ("Could not jump back into original cwd"); + rel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree()); + return rel && *rel ? strcat(rel, "/") : NULL; + } + return retval; } diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh index ec4996637d..bea40cba8d 100755 --- a/t/t1500-rev-parse.sh +++ b/t/t1500-rev-parse.sh @@ -31,9 +31,9 @@ test_rev_parse() { test_rev_parse toplevel false false true '' cd .git || exit 1 -test_rev_parse .git/ false true true .git/ +test_rev_parse .git/ true true false '' cd objects || exit 1 -test_rev_parse .git/objects/ false true true .git/objects/ +test_rev_parse .git/objects/ true true false '' cd ../.. || exit 1 mkdir -p sub/dir || exit 1 @@ -42,7 +42,7 @@ test_rev_parse subdirectory false false true sub/dir/ cd ../.. || exit 1 git config core.bare true -test_rev_parse 'core.bare = true' true false true +test_rev_parse 'core.bare = true' true false false git config --unset core.bare test_rev_parse 'core.bare undefined' false false true @@ -50,28 +50,28 @@ test_rev_parse 'core.bare undefined' false false true mkdir work || exit 1 cd work || exit 1 export GIT_DIR=../.git -export GIT_CONFIG="$GIT_DIR"/config +export GIT_CONFIG="$(pwd)"/../.git/config git config core.bare false -test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true '' +test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true work/ git config core.bare true -test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false true '' +test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false '' git config --unset core.bare -test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true '' +test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true work/ mv ../.git ../repo.git || exit 1 export GIT_DIR=../repo.git -export GIT_CONFIG="$GIT_DIR"/config +export GIT_CONFIG="$(pwd)"/../repo.git/config git config core.bare false test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true '' git config core.bare true -test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false true '' +test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false false '' git config --unset core.bare -test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' true false true '' +test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' false false true '' test_done diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index aadeeab9ab..732216184f 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -33,17 +33,17 @@ mv .git repo.git || exit 1 say "core.worktree = relative path" export GIT_DIR=repo.git -export GIT_CONFIG=$GIT_DIR/config +export GIT_CONFIG="$(pwd)"/$GIT_DIR/config unset GIT_WORK_TREE git config core.worktree ../work test_rev_parse 'outside' false false false cd work || exit 1 export GIT_DIR=../repo.git -export GIT_CONFIG=$GIT_DIR/config +export GIT_CONFIG="$(pwd)"/$GIT_DIR/config test_rev_parse 'inside' false false true '' cd sub/dir || exit 1 export GIT_DIR=../../../repo.git -export GIT_CONFIG=$GIT_DIR/config +export GIT_CONFIG="$(pwd)"/$GIT_DIR/config test_rev_parse 'subdirectory' false false true sub/dir/ cd ../../.. || exit 1 @@ -84,9 +84,23 @@ test_rev_parse 'in repo.git' false true false cd objects || exit 1 test_rev_parse 'in repo.git/objects' false true false cd ../work || exit 1 -test_rev_parse 'in repo.git/work' false false true '' +test_rev_parse 'in repo.git/work' false true true '' cd sub/dir || exit 1 -test_rev_parse 'in repo.git/sub/dir' false false true sub/dir/ +test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/ cd ../../../.. || exit 1 +test_expect_success 'repo finds its work tree' ' + (cd repo.git && + : > work/sub/dir/untracked && + test sub/dir/untracked = "$(git ls-files --others)") +' + +test_expect_success 'repo finds its work tree from work tree, too' ' + (cd repo.git/work/sub/dir && + : > tracked && + git --git-dir=../../.. add tracked && + cd ../../.. && + test sub/dir/tracked = "$(git ls-files)") +' + test_done From 420acb31acbfbd78e0c35ac0c614de8717daed0a Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Aug 2007 19:26:59 +0100 Subject: [PATCH 158/201] get_relative_cwd(): clarify why it handles dir == NULL The comment did not make a good case why it makes sense. Clarify, and remove stale comment about the caller being lazy. The behaviour on NULL input is pretty much intentional. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- dir.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dir.c b/dir.c index b3329f41b2..eb6c3abd30 100644 --- a/dir.c +++ b/dir.c @@ -646,16 +646,21 @@ file_exists(const char *f) /* * get_relative_cwd() gets the prefix of the current working directory * relative to 'dir'. If we are not inside 'dir', it returns NULL. - * As a convenience, it also returns NULL if 'dir' is already NULL. + * + * As a convenience, it also returns NULL if 'dir' is already NULL. The + * reason for this behaviour is that it is natural for functions returning + * directory names to return NULL to say "this directory does not exist" + * or "this directory is invalid". These cases are usually handled the + * same as if the cwd is not inside 'dir' at all, so get_relative_cwd() + * returns NULL for both of them. + * + * Most notably, get_relative_cwd(buffer, size, get_git_work_tree()) + * unifies the handling of "outside work tree" with "no work tree at all". */ char *get_relative_cwd(char *buffer, int size, const char *dir) { char *cwd = buffer; - /* - * a lazy caller can pass a NULL returned from get_git_work_tree() - * and rely on this function to return NULL. - */ if (!dir) return NULL; if (!getcwd(buffer, size)) From 96ffe892e307ea512abbc633f822558c568cece1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Aug 2007 15:59:35 +0100 Subject: [PATCH 159/201] rebase -i: ignore patches that are already in the upstream Non-interactive rebase had this from the beginning -- match it by using --cherry-pick option to rev-list. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 5 +++-- t/t3404-rebase-interactive.sh | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 061cd0a69e..d3addd4290 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -463,8 +463,9 @@ do # EOF git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \ - --abbrev=7 --reverse $UPSTREAM..$HEAD | \ - sed "s/^/pick /" >> "$TODO" + --abbrev=7 --reverse --left-right --cherry-pick \ + $UPSTREAM...$HEAD | \ + sed -n "s/^>/pick /p" >> "$TODO" test -z "$(grep -ve '^$' -e '^#' < $TODO)" && die_abort "Nothing to do" diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 817f614cde..dc436d768e 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -68,6 +68,9 @@ test "\$1" = .git/COMMIT_EDITMSG && { test -z "\$FAKE_COMMIT_AMEND" || echo "\$FAKE_COMMIT_AMEND" >> "\$1" exit } +test -z "\$EXPECT_COUNT" || + test "\$EXPECT_COUNT" = \$(grep -ve "^#" -e "^$" < "\$1" | wc -l) || + exit test -z "\$FAKE_LINES" && exit grep -v "^#" < "\$1" > "\$1".tmp rm "\$1" @@ -251,4 +254,16 @@ test_expect_success 'interrupted squash works as expected' ' test $one = $(git rev-parse HEAD~2) ' +test_expect_success 'ignore patch if in upstream' ' + HEAD=$(git rev-parse HEAD) && + git checkout -b has-cherry-picked HEAD^ && + echo unrelated > file7 && + git add file7 && + test_tick && + git commit -m "unrelated change" && + git cherry-pick $HEAD && + EXPECT_COUNT=1 git rebase -i $HEAD && + test $HEAD = $(git rev-parse HEAD^) +' + test_done From 21e9757e31d136fad0c04f3ce9da11b8b128b4f2 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Wed, 1 Aug 2007 14:57:43 +0200 Subject: [PATCH 160/201] Hack git-add--interactive to make it work with ActiveState Perl It wont work for arguments with special characters (like ", : or *). It is generally not possible on Windows, so I didn't even try. Signed-off-by: Junio C Hamano --- git-add--interactive.perl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index dc3038091d..7921cde8cb 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -3,9 +3,16 @@ use strict; sub run_cmd_pipe { - my $fh = undef; - open($fh, '-|', @_) or die; - return <$fh>; + if ($^O eq 'MSWin32') { + my @invalid = grep {m/[":*]/} @_; + die "$^O does not support: @invalid\n" if @invalid; + my @args = map { m/ /o ? "\"$_\"": $_ } @_; + return qx{@args}; + } else { + my $fh = undef; + open($fh, '-|', @_) or die; + return <$fh>; + } } my ($GIT_DIR) = run_cmd_pipe(qw(git rev-parse --git-dir)); @@ -17,7 +24,7 @@ chomp($GIT_DIR); sub refresh { my $fh; - open $fh, '-|', qw(git update-index --refresh) + open $fh, 'git update-index --refresh |' or die; while (<$fh>) { ;# ignore 'needs update' @@ -296,7 +303,7 @@ sub revert_cmd { my @lines = run_cmd_pipe(qw(git ls-tree HEAD --), map { $_->{VALUE} } @update); my $fh; - open $fh, '|-', qw(git update-index --index-info) + open $fh, '| git update-index --index-info' or die; for (@lines) { print $fh $_; @@ -725,7 +732,7 @@ sub patch_update_cmd { if (@result) { my $fh; - open $fh, '|-', qw(git apply --cached); + open $fh, '| git apply --cached'; for (@{$head->{TEXT}}, @result) { print $fh $_; } From 08874658b450600e72bb7cb0d0747c1ec4b0bfe1 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Wed, 1 Aug 2007 23:47:20 +0200 Subject: [PATCH 161/201] git-sh-setup.sh: make GIT_EDITOR/core.editor/VISUAL/EDITOR accept commands The previous code only allowed specifying a single executable rather than a complete command like "emacsclient --alternate-editor vi" in those variables. Since VISUAL/EDITOR appear to be traditionally passed to a shell for interpretation (as corroborated with "less", "mail" and "mailx", while the really ancient "more" indeed allows only an executable name), the shell function git_editor has been amended appropriately. "eval" is employed to have quotes and similar interpreted _after_ expansion, so that specifying EDITOR='"/home/dak/My Commands/notepad.exe"' can be used for actually using commands with blanks. Instead of passing just the first argument of git_editor on, we pass all of them (so that +lineno might be employed at a later point of time, or so that multiple files may be edited when appropriate). Strictly speaking, there is a change in behavior: when git config core.editor returns a valid but empty string, the fallbacks are still searched. This is more consistent, and the old code was problematic with regard to multiple blanks. Putting in additional quotes might have worked, but quotes inside of command substitution inside of quotes is nasty enough to not reliably work the same across "Bourne shells". Signed-off-by: David Kastrup Signed-off-by: Junio C Hamano --- git-sh-setup.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/git-sh-setup.sh b/git-sh-setup.sh index 7bef43f39d..8cbd153b62 100755 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -29,7 +29,8 @@ set_reflog_action() { } git_editor() { - GIT_EDITOR=${GIT_EDITOR:-$(git config core.editor || echo ${VISUAL:-${EDITOR}})} + : "${GIT_EDITOR:=$(git config core.editor)}" + : "${GIT_EDITOR:=${VISUAL:-${EDITOR}}}" case "$GIT_EDITOR,$TERM" in ,dumb) echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL," @@ -40,7 +41,7 @@ git_editor() { exit 1 ;; esac - "${GIT_EDITOR:-vi}" "$1" + eval "${GIT_EDITOR:=vi}" '"$@"' } is_bare_repository () { From 6d4bbebd35e3a6e8091d7188f1c4d49af7f054e3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 1 Aug 2007 18:14:41 -0700 Subject: [PATCH 162/201] git-commit.sh: Permit the --amend message to be given with -m/-c/-C/-F. [jc: adjusted t/t7501 as this makes -F and --amend compatible] Signed-off-by: David Kastrup Signed-off-by: Junio C Hamano --- git-commit.sh | 5 ++--- t/t7501-commit.sh | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/git-commit.sh b/git-commit.sh index 4290ae2dd2..d7e7028c15 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -190,7 +190,6 @@ $1" ;; --a|--am|--ame|--amen|--amend) amend=t - log_given=t$log_given use_commit=HEAD shift ;; @@ -298,9 +297,9 @@ esac case "$log_given" in tt*) - die "Only one of -c/-C/-F/--amend can be used." ;; + die "Only one of -c/-C/-F can be used." ;; *tm*|*mt*) - die "Option -m cannot be combined with -c/-C/-F/--amend." ;; + die "Option -m cannot be combined with -c/-C/-F." ;; esac case "$#,$also,$only,$amend" in diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index 8cc2cd9e60..6bd3c9e3e0 100644 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -27,7 +27,7 @@ test_expect_success \ test_expect_failure \ "invalid options 1" \ - "git-commit --amend -F file" + "git-commit -m foo -m bar -F file" test_expect_failure \ "invalid options 2" \ @@ -78,9 +78,9 @@ test_expect_success \ "VISUAL=./editor git-commit --amend" test_expect_failure \ - "passing --amend and -F" \ + "passing -m and -F" \ "echo 'enough with the bongos' >file && \ - git-commit -F msg --amend ." + git-commit -F msg -m amending ." test_expect_success \ "using message from other commit" \ From 434e6ef89d73dcc812b3a44dfaff0ca8204a206e Mon Sep 17 00:00:00 2001 From: Steve Hoelzer Date: Wed, 1 Aug 2007 10:43:06 -0500 Subject: [PATCH 163/201] Try to be consistent with capitalization in the documentation Signed-off-by: Steve Hoelzer Signed-off-by: Junio C Hamano --- Documentation/git-branch.txt | 4 ++-- Documentation/git-diff.txt | 22 +++++++++++----------- Documentation/git-merge.txt | 10 +++++----- Documentation/git-reset.txt | 16 ++++++++-------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index bc6aa88417..33bc31b0d4 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -134,8 +134,8 @@ $ git branch -d -r origin/todo origin/html origin/man <1> $ git branch -D test <2> ------------ + -<1> delete remote-tracking branches "todo", "html", "man" -<2> delete "test" branch even if the "master" branch does not have all +<1> Delete remote-tracking branches "todo", "html", "man" +<2> Delete "test" branch even if the "master" branch does not have all commits from test branch. diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index b1f5e7f93f..b36e705dd0 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -76,10 +76,10 @@ $ git diff --cached <2> $ git diff HEAD <3> ------------ + -<1> changes in the working tree not yet staged for the next commit. -<2> changes between the index and your last commit; what you +<1> Changes in the working tree not yet staged for the next commit. +<2> Changes between the index and your last commit; what you would be committing if you run "git commit" without "-a" option. -<3> changes in the working tree since your last commit; what you +<3> Changes in the working tree since your last commit; what you would be committing if you run "git commit -a" Comparing with arbitrary commits:: @@ -90,12 +90,12 @@ $ git diff HEAD -- ./test <2> $ git diff HEAD^ HEAD <3> ------------ + -<1> instead of using the tip of the current branch, compare with the +<1> Instead of using the tip of the current branch, compare with the tip of "test" branch. -<2> instead of comparing with the tip of "test" branch, compare with +<2> Instead of comparing with the tip of "test" branch, compare with the tip of the current branch, but limit the comparison to the file "test". -<3> compare the version before the last commit and the last commit. +<3> Compare the version before the last commit and the last commit. Limiting the diff output:: @@ -106,11 +106,11 @@ $ git diff --name-status <2> $ git diff arch/i386 include/asm-i386 <3> ------------ + -<1> show only modification, rename and copy, but not addition +<1> Show only modification, rename and copy, but not addition nor deletion. -<2> show only names and the nature of change, but not actual +<2> Show only names and the nature of change, but not actual diff output. -<3> limit diff output to named subtrees. +<3> Limit diff output to named subtrees. Munging the diff output:: + @@ -119,9 +119,9 @@ $ git diff --find-copies-harder -B -C <1> $ git diff -R <2> ------------ + -<1> spend extra cycles to find renames, copies and complete +<1> Spend extra cycles to find renames, copies and complete rewrites (very expensive). -<2> output diff in reverse. +<2> Output diff in reverse. Author diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index 2c9db98a3c..144bc16ff2 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -107,11 +107,11 @@ pull after you are done and ready. When things cleanly merge, these things happen: -1. the results are updated both in the index file and in your - working tree, -2. index file is written out as a tree, -3. the tree gets committed, and -4. the `HEAD` pointer gets advanced. +1. The results are updated both in the index file and in your + working tree; +2. Index file is written out as a tree; +3. The tree gets committed; and +4. The `HEAD` pointer gets advanced. Because of 2., we require that the original state of the index file to match exactly the current `HEAD` commit; otherwise we diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 19c5b9bbda..15e3aca9a1 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -63,7 +63,7 @@ $ git commit -a -c ORIG_HEAD <3> <1> This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset". -<2> make corrections to working tree files. +<2> Make corrections to working tree files. <3> "reset" copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead. @@ -106,17 +106,17 @@ $ git reset <3> $ git pull git://info.example.com/ nitfol <4> ------------ + -<1> you are happily working on something, and find the changes +<1> You are happily working on something, and find the changes in these files are in good order. You do not want to see them when you run "git diff", because you plan to work on other files and changes with these files are distracting. -<2> somebody asks you to pull, and the changes sounds worthy of merging. -<3> however, you already dirtied the index (i.e. your index does +<2> Somebody asks you to pull, and the changes sounds worthy of merging. +<3> However, you already dirtied the index (i.e. your index does not match the HEAD commit). But you know the pull you are going to make does not affect frotz.c nor filfre.c, so you revert the index changes for these two files. Your changes in working tree remain there. -<4> then you can pull and merge, leaving frotz.c and filfre.c +<4> Then you can pull and merge, leaving frotz.c and filfre.c changes still in the working tree. Undo a merge or pull:: @@ -133,15 +133,15 @@ Fast forward $ git reset --hard ORIG_HEAD <4> ------------ + -<1> try to update from the upstream resulted in a lot of +<1> Try to update from the upstream resulted in a lot of conflicts; you were not ready to spend a lot of time merging right now, so you decide to do that later. <2> "pull" has not made merge commit, so "git reset --hard" which is a synonym for "git reset --hard HEAD" clears the mess from the index file and the working tree. -<3> merge a topic branch into the current branch, which resulted +<3> Merge a topic branch into the current branch, which resulted in a fast forward. -<4> but you decided that the topic branch is not ready for public +<4> But you decided that the topic branch is not ready for public consumption yet. "pull" or "merge" always leaves the original tip of the current branch in ORIG_HEAD, so resetting hard to it brings your index file and the working tree back to that state, From c9e6589288b09f4e631c7f12f0f9a77c29851632 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Aug 2007 23:31:03 +0100 Subject: [PATCH 164/201] rebase -i: fix for optional [branch] parameter When calling "git rebase -i ", git should switch to first. This worked before, but I broke it by my "Shut git rebase -i up" patch. Fix that, and add a test to make sure that it does not break again. Signed-off-by: Johannes Schindelin Acked-by: Alex Riesen Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 2 +- t/t3404-rebase-interactive.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index d3addd4290..bdec462609 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -405,6 +405,7 @@ do require_clean_work_tree + mkdir "$DOTEST" || die "Could not create temporary $DOTEST" if test ! -z "$2" then output git show-ref --verify --quiet "refs/heads/$2" || @@ -418,7 +419,6 @@ do test -z "$ONTO" && ONTO=$UPSTREAM - mkdir "$DOTEST" || die "Could not create temporary $DOTEST" : > "$DOTEST"/interactive || die "Could not mark as interactive" git symbolic-ref HEAD > "$DOTEST"/head-name || die "Could not get HEAD" diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index dc436d768e..a9b552ff08 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -98,6 +98,14 @@ test_expect_success 'no changes are a nop' ' test $(git rev-parse I) = $(git rev-parse HEAD) ' +test_expect_success 'test the [branch] option' ' + git checkout -b dead-end && + git rm file6 && + git commit -m "stop here" && + git rebase -i F branch2 && + test $(git rev-parse I) = $(git rev-parse HEAD) +' + test_expect_success 'rebase on top of a non-conflicting commit' ' git checkout branch1 && git tag original-branch1 && From 50cff52f1a896118d5260c752900188e7d231cf6 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Thu, 2 Aug 2007 01:48:44 +0200 Subject: [PATCH 165/201] When generating manpages, delete outdated targets first. This makes "make doc" work even if you made "sudo make doc" previously by mistake. Apparently an oversight: the other targets did this already. Signed-off-by: David Kastrup Signed-off-by: Junio C Hamano --- Documentation/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/Makefile b/Documentation/Makefile index 3bc5357ec9..443114b046 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -120,6 +120,7 @@ clean: mv $@+ $@ %.1 %.5 %.7 : %.xml + $(RM) $@ xmlto -m callouts.xsl man $< %.xml : %.txt From 68d4229847b0f94982b4f2f58ce5e9cbd0f6f8fc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 2 Aug 2007 00:13:03 -0700 Subject: [PATCH 166/201] RelNotes 1.5.3 updates before -rc4 Signed-off-by: Junio C Hamano --- Documentation/RelNotes-1.5.3.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Documentation/RelNotes-1.5.3.txt b/Documentation/RelNotes-1.5.3.txt index 785bd38455..03d18430e8 100644 --- a/Documentation/RelNotes-1.5.3.txt +++ b/Documentation/RelNotes-1.5.3.txt @@ -40,6 +40,9 @@ Updates since v1.5.2 $GIT_DIR to work in a subdirectory of a working tree that is not located at "$GIT_DIR/..". + - Giving "--file=" option to "git config" is the same as + running the command with GIT_CONFIG= environment. + - "git log" learned a new option "--follow", to follow renaming history of a single file. @@ -50,6 +53,9 @@ Updates since v1.5.2 - "git-cvsserver" learned new options (--base-path, --export-all, --strict-paths) inspired by git-daemon. + - "git daemon --base-path-relaxed" can help migrating a repository URL + that did not use to use --base-path to use --base-path. + - "git-commit" can use "-t templatefile" option and commit.template configuration variable to prime the commit message given to you in the editor. @@ -120,6 +126,9 @@ Updates since v1.5.2 of the format ('tgz', 'tbz2' or 'zip'). Please update the your configuration file accordingly. + - "git diff" (but not the plumbing level "git diff-tree") now + recursively descends into trees by default. + - 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 @@ -165,6 +174,9 @@ Updates since v1.5.2 - The diffstat given after a merge (or a pull) honors the color.diff configuration. + - "git commit --amend" is now compatible with various message source + options such as -m/-C/-c/-F. + - "git-apply --whitespace=strip" removes blank lines added at the end of the file. @@ -262,6 +274,6 @@ this release, unless otherwise noted. -- exec >/var/tmp/1 -O=v1.5.3-rc3 +O=v1.5.3-rc3-119-g50cff52 echo O=`git describe refs/heads/master` git shortlog --no-merges $O..refs/heads/master ^refs/heads/maint From a4eba020f96e1b85f856a992782b8bb2bab6a719 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 23 Jul 2007 15:51:49 -0700 Subject: [PATCH 167/201] Sort output of "p4 change" in incremental import before further processing P4 change outputs the changes sorted for each directory separately. We want the global ordering on the changes, hence we sort. Signed-off-by: Han-Wen Nienhuys Signed-off-by: Simon Hausmann --- contrib/fast-import/git-p4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 1f5a56ee7f..f00c691a7b 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -1296,7 +1296,7 @@ class P4Sync(Command): changeNum = line.split(" ")[1] changes.append(changeNum) - changes.reverse() + changes.sort() if len(self.maxChanges) > 0: changes = changes[0:min(int(self.maxChanges), len(changes))] From 7fcff9def564fae7de5d2a34a095229a999b80b0 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 23 Jul 2007 15:56:37 -0700 Subject: [PATCH 168/201] Fix style nit in Python slicing. Python slices start at 0 by default. Signed-off-by: Han-Wen Nienhuys Signed-off-by: Simon Hausmann --- contrib/fast-import/git-p4 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index f00c691a7b..41e86e76cb 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -1181,11 +1181,11 @@ class P4Sync(Command): elif ',' not in self.changeRange: self.revision = self.changeRange self.changeRange = "" - p = p[0:atIdx] + p = p[:atIdx] elif p.find("#") != -1: hashIdx = p.index("#") self.revision = p[hashIdx:] - p = p[0:hashIdx] + p = p[:hashIdx] elif self.previousDepotPaths == []: self.revision = "#head" @@ -1299,7 +1299,7 @@ class P4Sync(Command): changes.sort() if len(self.maxChanges) > 0: - changes = changes[0:min(int(self.maxChanges), len(changes))] + changes = changes[:min(int(self.maxChanges), len(changes))] if len(changes) == 0: if not self.silent: From c29ba0c3edc513259eee572f9c9257ec7cd94a56 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Thu, 2 Aug 2007 10:56:42 +0200 Subject: [PATCH 169/201] Support building on GNU/Hurd GNU/Hurd systems don't have strlcpy. Signed-off-by: Thomas Schwinge Signed-off-by: Junio C Hamano --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index b593446efb..2f3b9b23e3 100644 --- a/Makefile +++ b/Makefile @@ -458,6 +458,10 @@ ifeq ($(uname_S),AIX) NO_STRLCPY = YesPlease NEEDS_LIBICONV=YesPlease endif +ifeq ($(uname_S),GNU) + # GNU/Hurd + NO_STRLCPY=YesPlease +endif ifeq ($(uname_S),IRIX64) NO_IPV6=YesPlease NO_SETENV=YesPlease From d825a974950b397c6ffbf44b84a7158bfcaba819 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 2 Aug 2007 22:36:37 +0100 Subject: [PATCH 170/201] read-tree: remove unnecessary call to setup_git_directory() read-tree is already marked with RUN_SETUP in git.c, so there is no need to call setup_git_directory() a second time. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-read-tree.c | 1 - 1 file changed, 1 deletion(-) diff --git a/builtin-read-tree.c b/builtin-read-tree.c index 41f8110238..a3b17a3bd9 100644 --- a/builtin-read-tree.c +++ b/builtin-read-tree.c @@ -97,7 +97,6 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix) memset(&opts, 0, sizeof(opts)); opts.head_idx = -1; - setup_git_directory(); git_config(git_default_config); newfd = hold_locked_index(&lock_file, 1); From 29093c28a21d75500e9388ad103b9af9a0bab1ae Mon Sep 17 00:00:00 2001 From: David Symonds Date: Fri, 3 Aug 2007 08:45:56 +1000 Subject: [PATCH 171/201] Fix documentation for core.gitproxy to reflect code The current implementation of core.gitproxy only operates on git:// URLs, so the ssh:// examples and custom protocol examples have been removed or edited. Signed-off-by: Junio C Hamano --- Documentation/config.txt | 2 +- Documentation/git-config.txt | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 3135cb7a66..de9e72b562 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -101,7 +101,7 @@ Example # Proxy settings [core] - gitProxy="ssh" for "ssh://kernel.org/" + gitProxy="ssh" for "kernel.org" gitProxy=default-proxy ; for the rest Variables diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 8451cccf8a..c3dffffe32 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -214,9 +214,7 @@ Given a .git/config like this: ; Proxy settings [core] - gitproxy="ssh" for "ssh://kernel.org/" gitproxy="proxy-command" for kernel.org - gitproxy="myprotocol-command" for "my://" gitproxy=default-proxy ; for all the rest you can set the filemode to true with @@ -291,7 +289,7 @@ To actually match only values with an exclamation mark, you have to To add a new proxy, without altering any of the existing ones, use ------------ -% git config core.gitproxy '"proxy" for example.com' +% git config core.gitproxy '"proxy-command" for example.com' ------------ From 6490a3383f1d0d96c122069e510ef1af1d019fbb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 2 Aug 2007 15:10:56 -0700 Subject: [PATCH 172/201] Fix work-tree related breakages In set_work_tree(), variable rel needs to be reinitialized to NULL on every call (it should not be static). Make sure the incoming dir variable is not too long before copying to the temporary buffer, and make sure chdir to the resulting directory succeeds. This was spotted and fixed by Alex and Johannes in a handful patch exchanges. Here is the final version. Signed-off-by: Junio C Hamano Acked-by: Johannes Schindelin --- setup.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/setup.c b/setup.c index 3653092ab6..4945eb3134 100644 --- a/setup.c +++ b/setup.c @@ -201,26 +201,32 @@ int is_inside_work_tree(void) */ const char *set_work_tree(const char *dir) { - char dir_buffer[PATH_MAX]; - static char buffer[PATH_MAX + 1], *rel = NULL; - int len, postfix_len = strlen(DEFAULT_GIT_DIR_ENVIRONMENT) + 1; + char dir_buffer[PATH_MAX], *rel = NULL; + static char buffer[PATH_MAX + 1]; + int len, suffix_len = strlen(DEFAULT_GIT_DIR_ENVIRONMENT) + 1; /* strip the variable 'dir' of the postfix "/.git" if it has it */ len = strlen(dir); - if (len > postfix_len && !strcmp(dir + len - postfix_len, - "/" DEFAULT_GIT_DIR_ENVIRONMENT)) { - strncpy(dir_buffer, dir, len - postfix_len); + if (len > suffix_len && + !strcmp(dir + len - suffix_len, "/" DEFAULT_GIT_DIR_ENVIRONMENT)) { + if ((len - suffix_len) >= sizeof(dir_buffer)) + die("directory name too long"); + memcpy(dir_buffer, dir, len - suffix_len); + dir_buffer[len - suffix_len] = '\0'; /* are we inside the default work tree? */ rel = get_relative_cwd(buffer, sizeof(buffer), dir_buffer); } + /* if rel is set, the cwd is _not_ the current working tree */ if (rel && *rel) { if (!is_absolute_path(dir)) set_git_dir(make_absolute_path(dir)); dir = dir_buffer; - chdir(dir); - strcat(rel, "/"); + if (chdir(dir)) + die("cannot chdir to %s: %s", dir, strerror(errno)); + else + strcat(rel, "/"); inside_git_dir = 0; } else { rel = NULL; From d20602eec97caa8766820150eff2a07e205c44e1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 27 Jul 2007 01:23:03 -0700 Subject: [PATCH 173/201] gitweb: do not choke on recursive symlink If somebody used to advertise his repository that physically resides at /pub/lic.git/ as: git://git.example.com/pub/lic.git/ but now wants to use --base-path to allow: git://git.example.com/lic.git/ she can start git-daemon with --base-path option, like this: git-daemon --base-path=/pub --export-all During the transition, however, she would also want to allow older URL as well. One natural way to achieve that is to create a symlink: ln -s /pub /pub/pub so that a request to git://git.example.com/pub/lic.git/ is first translated by --base-path to a request to /pub/pub/lic.git/ which goes to /pub/lic.git, thanks to the symlink. So far so good. However, gitweb chokes if there is such a symlink (File::Find barfs with "/pub/pub is a recursive symbolic link"). Make the code ignore such a symlink. Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 1 + 1 file changed, 1 insertion(+) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 498b936dd4..077eb2f4ca 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1515,6 +1515,7 @@ sub git_get_projects_list { File::Find::find({ follow_fast => 1, # follow symbolic links + follow_skip => 2, # ignore duplicates dangling_symlinks => 0, # ignore dangling symlinks, silently wanted => sub { # skip project-list toplevel, if we get it. From a697ec69cbd3eb1a8fb70e4e0587e5049cd1ad83 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 3 Aug 2007 14:31:47 -0700 Subject: [PATCH 174/201] Fix bogus use of printf in t3700 test The hashed contents did not matter in the end result, but it passed an uninitialized variable to printf, which caused it to emit empty while giving an error/usage message. Signed-off-by: Junio C Hamano --- t/t3700-add.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t3700-add.sh b/t/t3700-add.sh index b52fde8577..213e9249da 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -131,8 +131,8 @@ test_expect_success 'git add with filemode=0, symlinks=0 prefers stage 2 over st ( echo "100644 $(git hash-object -w stage1) 1 file" echo "100755 $(git hash-object -w stage2) 2 file" - echo "100644 $(printf $s | git hash-object -w -t blob --stdin) 1 symlink" - echo "120000 $(printf $s | git hash-object -w -t blob --stdin) 2 symlink" + echo "100644 $(printf 1 | git hash-object -w -t blob --stdin) 1 symlink" + echo "120000 $(printf 2 | git hash-object -w -t blob --stdin) 2 symlink" ) | git update-index --index-info && git config core.filemode 0 && git config core.symlinks 0 && From 4f8f03d6435e3e1c0d4f95d43022b81c95d6347f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 3 Aug 2007 15:33:57 -0700 Subject: [PATCH 175/201] GIT 1.5.3-rc4 Signed-off-by: Junio C Hamano --- Documentation/RelNotes-1.5.3.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/RelNotes-1.5.3.txt b/Documentation/RelNotes-1.5.3.txt index 03d18430e8..21bb1fc6f2 100644 --- a/Documentation/RelNotes-1.5.3.txt +++ b/Documentation/RelNotes-1.5.3.txt @@ -47,8 +47,8 @@ Updates since v1.5.2 renaming history of a single file. - "git-filter-branch" lets you rewrite the revision history of - the current branch, creating a new branch. You can specify a - number of filters to modify the commits, files and trees. + specified branches. You can specify a number of filters to + modify the commits, files and trees. - "git-cvsserver" learned new options (--base-path, --export-all, --strict-paths) inspired by git-daemon. @@ -274,6 +274,6 @@ this release, unless otherwise noted. -- exec >/var/tmp/1 -O=v1.5.3-rc3-119-g50cff52 +O=v1.5.3-rc4 echo O=`git describe refs/heads/master` git shortlog --no-merges $O..refs/heads/master ^refs/heads/maint From 7fd53fce1c574f6a4940eedf36383a4e9ed7ae6a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 3 Aug 2007 02:04:37 -0700 Subject: [PATCH 176/201] git-completion: add "git stash" This is a new addition to 1.5.3; let's teach it to the completion before the final release. [sp: Added missing git-stash completion configuration] Signed-off-by: Junio C Hamano Signed-off-by: Shawn O. Pearce --- contrib/completion/git-completion.bash | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index f2b10fa5f6..82b9ed40d8 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -972,6 +972,11 @@ _git_show () __git_complete_file } +_git_stash () +{ + __gitcomp 'list show apply clear' +} + _git () { local i c=1 command __git_dir @@ -1028,6 +1033,7 @@ _git () shortlog) _git_shortlog ;; show) _git_show ;; show-branch) _git_log ;; + stash) _git_stash ;; whatchanged) _git_log ;; *) COMPREPLY=() ;; esac @@ -1073,6 +1079,7 @@ complete -o default -o nospace -F _git_remote git-remote complete -o default -o nospace -F _git_reset git-reset complete -o default -o nospace -F _git_shortlog git-shortlog complete -o default -o nospace -F _git_show git-show +complete -o default -o nospace -F _git_stash git-stash complete -o default -o nospace -F _git_log git-show-branch complete -o default -o nospace -F _git_log git-whatchanged From 33f243308589120a700f084b54ee597ce6c26069 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Fri, 3 Aug 2007 19:50:42 +0200 Subject: [PATCH 177/201] gitweb: Fix handling of $file_name in feed generation The commit b6093a5c, by Robert Fitzsimons: "gitweb: Change atom, rss actions to use parse_commits." forgot to pass $file_name parameter to parse_commits subroutine. If git_feed is provided a file name, it ought to show only the history affecting that file or a directory. The title was being set correctly, but all commits from history were being shown. Signed-off-by: Steven Walter Signed-off-by: Jakub Narebski 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 077eb2f4ca..f282a677aa 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -5366,7 +5366,7 @@ sub git_feed { # log/feed of current (HEAD) branch, log of given branch, history of file/directory my $head = $hash || 'HEAD'; - my @commitlist = parse_commits($head, 150); + my @commitlist = parse_commits($head, 150, 0, undef, $file_name); my %latest_commit; my %latest_date; From 2ec39edad9c3be74b5fed5ab5c122493e6a53c66 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 3 Aug 2007 20:19:09 -0700 Subject: [PATCH 178/201] INSTALL: add warning on docbook-xsl 1.72 and 1.73 Signed-off-by: Junio C Hamano --- INSTALL | 4 ++++ .../docbook-xsl-manpages-charmap.patch | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 contrib/patches/docbook-xsl-manpages-charmap.patch diff --git a/INSTALL b/INSTALL index 79e71b6922..c62b12c288 100644 --- a/INSTALL +++ b/INSTALL @@ -116,3 +116,7 @@ Issues of note: would instead give you a copy of what you see at: http://www.kernel.org/pub/software/scm/git/docs/ + + It has been reported that docbook-xsl version 1.72 and 1.73 are + buggy; 1.72 misformats manual pages for callouts, and 1.73 needs + the patch in contrib/patches/docbook-xsl-manpages-charmap.patch diff --git a/contrib/patches/docbook-xsl-manpages-charmap.patch b/contrib/patches/docbook-xsl-manpages-charmap.patch new file mode 100644 index 0000000000..f2b08b4f4a --- /dev/null +++ b/contrib/patches/docbook-xsl-manpages-charmap.patch @@ -0,0 +1,21 @@ +From: Ismail Dönmez + +Trying to build the documentation with docbook-xsl 1.73 may result in +the following error. This patch fixes it. + +$ xmlto -m callouts.xsl man git-add.xml +runtime error: file +file:///usr/share/sgml/docbook/xsl-stylesheets-1.73.0/manpages/other.xsl line +129 element call-template +The called template 'read-character-map' was not found. + +--- docbook-xsl-1.73.0/manpages/docbook.xsl.manpages-charmap 2007-07-23 16:24:23.000000000 +0100 ++++ docbook-xsl-1.73.0/manpages/docbook.xsl 2007-07-23 16:25:16.000000000 +0100 +@@ -37,6 +37,7 @@ + + + ++ + + + From d5538b418d658d507f7fb9f359b31152a9b5f8e0 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 4 Aug 2007 02:06:52 -0400 Subject: [PATCH 179/201] Document GIT_SSH environment variable alongside other variables The GIT_SSH environment variable has survived for quite a while without being documented, but has been mentioned on list and on my day-job repositories can only be accessed via magic supplied through the wonderous hack that is GIT_SSH. Advertising it alongside other "low level magic" such as GIT_PAGER and GIT_MERGE_VERBOSITY will certainly help others who need to spread their own pixie dust to make things work. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- Documentation/git.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Documentation/git.txt b/Documentation/git.txt index 4c4d1746e0..18f8b6a0a1 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -421,6 +421,22 @@ other to an empty string or to the value "cat", git will not launch a pager. +'GIT_SSH':: + If this environment variable is set then gitlink:git-fetch[1] + and gitlink:git-push[1] will use this command instead + of `ssh` when they need to connect to a remote system. + The 'GIT_SSH' command will be given exactly two arguments: + the 'username@host' (or just 'host') from the URL and the + shell command to execute on that remote system. ++ +To pass options to the program that you want to list in GIT_SSH +you will need to wrap the program and options into a shell script, +then set GIT_SSH to refer to the shell script. ++ +Usually it is easier to configure any desired options through your +personal `.ssh/config` file. Please consult your ssh documentation +for further details. + 'GIT_FLUSH':: If this environment variable is set to "1", then commands such as git-blame (in incremental mode), git-rev-list, git-log, From 936800bb559afb8e24d79d5fab555bf061a4a88c Mon Sep 17 00:00:00 2001 From: "Randal L. Schwartz" Date: Sat, 4 Aug 2007 01:57:29 -0700 Subject: [PATCH 180/201] add "test-absolute-path" to .gitignore New file requires new ignore. Signed-off-by: Junio C Hamano --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 20ee642420..63c918c667 100644 --- a/.gitignore +++ b/.gitignore @@ -148,6 +148,7 @@ git-write-tree git-core-*/?* gitk-wish gitweb/gitweb.cgi +test-absolute-path test-chmtime test-date test-delta From 4465f410d6a8fa7abc5436aac6f58196f2b618d8 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 4 Aug 2007 23:20:07 +0100 Subject: [PATCH 181/201] checkout-index needs a working tree Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git.c b/git.c index 25b8274d3e..f8c4545208 100644 --- a/git.c +++ b/git.c @@ -315,7 +315,8 @@ static void handle_internal_command(int argc, const char **argv) { "branch", cmd_branch, RUN_SETUP }, { "bundle", cmd_bundle }, { "cat-file", cmd_cat_file, RUN_SETUP }, - { "checkout-index", cmd_checkout_index, RUN_SETUP }, + { "checkout-index", cmd_checkout_index, + RUN_SETUP | NEED_WORK_TREE}, { "check-ref-format", cmd_check_ref_format }, { "check-attr", cmd_check_attr, RUN_SETUP | NEED_WORK_TREE }, { "cherry", cmd_cherry, RUN_SETUP }, From 64a476e691cb08c2f8bd6d40cc88fb8ccb9ed955 Mon Sep 17 00:00:00 2001 From: Jyotirmoy Bhattacharya Date: Sun, 5 Aug 2007 10:52:15 +0530 Subject: [PATCH 182/201] Fixed git-push manpage In git-push it is the remote repository and not the local repository which is fast forwarded. The description of the -f option in the git-push manpage gets it the other way round. Signed-off-by: Jyotirmoy Bhattacharya Signed-off-by: Junio C Hamano --- Documentation/git-push.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index 74a0da1ed4..0dd9caf867 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -79,7 +79,7 @@ the remote repository. -f, \--force:: Usually, the command refuses to update a remote ref that is - not a descendant of the local ref used to overwrite it. + not an ancestor of the local ref used to overwrite it. This flag disables the check. This can cause the remote repository to lose commits; use it with care. From 936492d3cf96817f03182712ca14eb4744c721ef Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 3 Aug 2007 22:13:09 -0700 Subject: [PATCH 183/201] unpack-trees.c: assume submodules are clean during check-out Sven originally raised this issue: If you have a submodule checked out and you go back (or forward) to a revision of the supermodule that contains a different revision of the submodule and then switch to another revision, it will complain that the submodule is not uptodate, because git simply didn't update the submodule in the first move. The current policy is to consider it is perfectly normal that checked-out submodule is out-of-sync wrt the supermodule index. At least until we introduce a superproject repository configuration option that says "in this repository, I do care about this submodule and at any time I move around in the superproject, recursively check out the submodule to match", it is a reasonable policy, as we currently do not recursively checkout the submodules at all. The most extreme case of this policy is that the superproject index knows about the submodule but the subdirectory does not even have to be checked out. The function verify_uptodate(), called during the two-way merge aka branch switching, is about "make sure the filesystem entity that corresponds to this cache entry is up to date, lest we lose the local modifications". As we explicitly allow submodule checkout to drift from the supermodule index entry, the check should say "Ok, for submodules, not matching is the norm" for now. Later when we have the ability to mark "I care about this submodule to be always in sync with the superproject" (thereby implementing automatic recursive checkout and perhaps diff, among other things), we should check if the submodule in question is marked as such and perform the current test. Acked-by: Lars Hjemli Acked-by: Sven Verdoolaege Signed-off-by: Junio C Hamano --- unpack-trees.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/unpack-trees.c b/unpack-trees.c index 3b32718436..dfd985b0ef 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -407,6 +407,15 @@ static void verify_uptodate(struct cache_entry *ce, unsigned changed = ce_match_stat(ce, &st, 1); if (!changed) return; + /* + * NEEDSWORK: the current default policy is to allow + * submodule to be out of sync wrt the supermodule + * index. This needs to be tightened later for + * submodules that are marked to be automatically + * checked out. + */ + if (S_ISGITLINK(ntohl(ce->ce_mode))) + return; errno = 0; } if (errno == ENOENT) From 00d8c5180dde7434930bfbdf20bc296e9241e4fc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 4 Aug 2007 23:48:27 -0700 Subject: [PATCH 184/201] Fix install-doc-quick target The script starts in a subdirectory of the source directory to muck with a branch whose structure does not have anything to do with the actual work tree. Go up to the top to make it clear that we operate on the whole tree. It also exported GIT_DIR without any good reason. Remove it. Signed-off-by: Junio C Hamano --- Documentation/install-doc-quick.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/install-doc-quick.sh b/Documentation/install-doc-quick.sh index e6601bdd82..07d227f093 100755 --- a/Documentation/install-doc-quick.sh +++ b/Documentation/install-doc-quick.sh @@ -7,7 +7,7 @@ mandir="$2" SUBDIRECTORY_OK=t USAGE=' ' . git-sh-setup -export GIT_DIR +cd_to_toplevel test -z "$mandir" && usage if ! git rev-parse --verify "$head^0" >/dev/null; then @@ -18,6 +18,8 @@ fi GIT_INDEX_FILE=`pwd`/.quick-doc.index export GIT_INDEX_FILE rm -f "$GIT_INDEX_FILE" +trap 'rm -f "$GIT_INDEX_FILE"' 0 + git read-tree $head git checkout-index -a -f --prefix="$mandir"/ From 0eb4f7cdf85273c88feb95c677a808cee9cfd859 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sun, 5 Aug 2007 17:18:52 -0400 Subject: [PATCH 185/201] user-manual: update for new default --track behavior Update documentation to reflect the --track default. That change seems to have happened in the 1.5.3 -rc's, so bump the "for version x.y.z or newer" warning as well. Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 0071cd070e..c0820e9036 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -1,4 +1,4 @@ -Git User's Manual (for version 1.5.1 or newer) +Git User's Manual (for version 1.5.3 or newer) ______________________________________________ @@ -1667,24 +1667,19 @@ one step: $ git pull origin master ------------------------------------------------- -In fact, "origin" is normally the default repository to pull from, -and the default branch is normally the HEAD of the remote repository, -so often you can accomplish the above with just +In fact, if you have "master" checked out, then by default "git pull" +merges from the HEAD branch of the origin repository. So often you can +accomplish the above with just a simple ------------------------------------------------- $ git pull ------------------------------------------------- -See the descriptions of the branch..remote and branch..merge -options in gitlink:git-config[1] to learn how to control these defaults -depending on the current branch. Also note that the --track option to -gitlink:git-branch[1] and gitlink:git-checkout[1] can be used to -automatically set the default remote branch to pull from at the time -that a branch is created: - -------------------------------------------------- -$ git checkout --track -b maint origin/maint -------------------------------------------------- +More generally, a branch that is created from a remote branch will pull +by default from that branch. See the descriptions of the +branch..remote and branch..merge options in +gitlink:git-config[1], and the discussion of the --track option in +gitlink:git-checkout[1], to learn how to control these defaults. In addition to saving you keystrokes, "git pull" also helps you by producing a default commit message documenting the branch and From 7a7cc594ca294a58b6d7ae5aa50a65378538e875 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 3 Aug 2007 15:22:59 -0700 Subject: [PATCH 186/201] user-manual: mention git stash Mention the git-stash command as a way to temporarily set aside work in progress. Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index c0820e9036..9efe85ce2f 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -1484,6 +1484,38 @@ $ git show HEAD^:path/to/file which will display the given version of the file. +[[interrupted-work]] +Temporarily setting aside work in progress +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +While you are in the middle of working on something complicated, you +find an unrelated but obvious and trivial bug. You would like to fix it +before continuing. You can use gitlink:git-stash[1] to save the current +state of your work, and after fixing the bug (or, optionally after doing +so on a different branch and then coming back), unstash the +work-in-progress changes. + +------------------------------------------------ +$ git stash "work in progress for foo feature" +------------------------------------------------ + +This command will save your changes away to the `stash`, and +reset your working tree and the index to match the tip of your +current branch. Then you can make your fix as usual. + +------------------------------------------------ +... edit and test ... +$ git commit -a -m "blorpl: typofix" +------------------------------------------------ + +After that, you can go back to what you were working on with +`git stash apply`: + +------------------------------------------------ +$ git stash apply +------------------------------------------------ + + [[ensuring-good-performance]] Ensuring good performance ------------------------- From 407c0c87e15b3cf60347f4fc0bcdb4d239de4163 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sun, 5 Aug 2007 18:12:37 -0400 Subject: [PATCH 187/201] user-manual: mention git-gui The git gui project seems to be still in early stages, but at a point where it's worth mentioning as an alternative way of creating commits. One feature of interest is the ability to manipulate individual diff hunks. However, people have found that feature not to be easily discoverable from the user-interface. Pending some ui improvements, a parenthetical hint here may help. (Thanks to Steffen Prohask and Junio Hamano for suggesting the language.) Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 9efe85ce2f..f89952ad84 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -1079,6 +1079,11 @@ $ git diff HEAD # difference between HEAD and working tree; what $ git status # a brief per-file summary of the above. ------------------------------------------------- +You can also use gitlink:git-gui[1] to create commits, view changes in +the index and the working tree files, and individually select diff hunks +for inclusion in the index (by right-clicking on the diff hunk and +choosing "Stage Hunk For Commit"). + [[creating-good-commit-messages]] Creating good commit messages ----------------------------- @@ -2506,8 +2511,10 @@ $ gitk origin..mywork & And browse through the list of patches in the mywork branch using gitk, applying them (possibly in a different order) to mywork-new using -cherry-pick, and possibly modifying them as you go using commit ---amend. +cherry-pick, and possibly modifying them as you go using commit --amend. +The git-gui[1] command may also help as it allows you to individually +select diff hunks for inclusion in the index (by right-clicking on the +diff hunk and choosing "Stage Hunk for Commit"). Another technique is to use git-format-patch to create a series of patches, then reset the state to before the patches: From 5f42ac921fe06bbb80df82d8fa5cb15701ec2f60 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sun, 5 Aug 2007 19:16:09 -0400 Subject: [PATCH 188/201] documentation: use the word "index" in the git-add manual page It was a neat trick to show that you could introduce the git-add manual page without using the word "index", and it was certainly an improvement over the previous man page (which started out "A simple wrapper for git-update-index to add files to the index..."). But it's possible to use the standard terminology without sacrificing user-friendliness. So, rewrite to use the word "index" when appropriate. Signed-off-by: J. Bruce Fields --- Documentation/git-add.txt | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index a0c9f68580..37077b523e 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -3,7 +3,7 @@ git-add(1) NAME ---- -git-add - Add file contents to the changeset to be committed next +git-add - Add file contents to the index SYNOPSIS -------- @@ -11,24 +11,27 @@ SYNOPSIS DESCRIPTION ----------- -All the changed file contents to be committed together in a single set -of changes must be "added" with the 'add' command before using the -'commit' command. This is not only for adding new files. Even modified -files must be added to the set of changes about to be committed. +This command adds the current content of new or modified files to the +index, thus staging that content for inclusion in the next commit. -This command can be performed multiple times before a commit. The added -content corresponds to the state of specified file(s) at the time the -'add' command is used. This means the 'commit' command will not consider -subsequent changes to already added content if it is not added again before -the commit. +The "index" holds a snapshot of the content of the working tree, and it +is this snapshot that is taken as the contents of the next commit. Thus +after making any changes to the working directory, and before running +the commit command, you must use the 'add' command to add any new or +modified files to the index. -The 'git status' command can be used to obtain a summary of what is included -for the next commit. +This command can be performed multiple times before a commit. It only +adds the content of the specified file(s) at the time the add command is +run; if you want subsequent changes included in the next commit, then +you must run 'git add' again to add the new content to the index. -This command can be used to add ignored files with `-f` (force) -option, but they have to be -explicitly and exactly specified from the command line. File globbing -and recursive behaviour do not add ignored files. +The 'git status' command can be used to obtain a summary of which +files have changes that are staged for the next commit. + +The 'add' command can be used to add ignored files with `-f` (force) +option, but they have to be explicitly and exactly specified from the +command line. File globbing and recursive behaviour do not add ignored +files. Please see gitlink:git-commit[1] for alternative ways to add content to a commit. From a76c2acb28146f5630592f2ba738c0ebf0f3c1c4 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Mon, 6 Aug 2007 00:34:02 -0400 Subject: [PATCH 189/201] documentation: use the word "index" in the git-commit man page As with git-add, I think previous updates to the git-commit man page did indeed help make it more user-friendly. But I think the banishment of the word "index" from the description goes too far; reinstate its use, to simplify some of the language slightly and smooth the transition to other documentation. Signed-off-by: J. Bruce Fields Signed-off-by: Junio C Hamano --- Documentation/git-commit.txt | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 627994eb97..63599d3828 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -15,26 +15,26 @@ SYNOPSIS DESCRIPTION ----------- -Use 'git commit' when you want to record your changes into the repository -along with a log message describing what the commit is about. All changes -to be committed must be explicitly identified using one of the following -methods: +Use 'git commit' to store the current contents of the index in a new +commit along with a log message describing the changes you have made. +The content to be added can be specified in several ways: 1. by using gitlink:git-add[1] to incrementally "add" changes to the - next commit before using the 'commit' command (Note: even modified + index before using the 'commit' command (Note: even modified files must be "added"); -2. by using gitlink:git-rm[1] to identify content removal for the next - commit, again before using the 'commit' command; +2. by using gitlink:git-rm[1] to remove files from the working tree + and the index, again before using the 'commit' command; -3. by directly listing files containing changes to be committed as arguments - to the 'commit' command, in which cases only those files alone will be - considered for the commit; +3. by listing files as arguments to the 'commit' command, in which + case the commit will ignore changes staged in the index, and instead + record the current content of the listed files; -4. by using the -a switch with the 'commit' command to automatically "add" - changes from all known files i.e. files that have already been committed - before, and to automatically "rm" files that have been - removed from the working tree, and perform the actual commit. +4. by using the -a switch with the 'commit' command to automatically + "add" changes from all known files (i.e. all files that are already + listed in the index) and to automatically "rm" files in the index + that have been removed from the working tree, and then perform the + actual commit; 5. by using the --interactive switch with the 'commit' command to decide one by one which files should be part of the commit, before finalizing the From 33a798c880f9a8bed1fe95531349e5e5ef1e0cd2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 6 Aug 2007 00:20:06 -0700 Subject: [PATCH 190/201] setup.c:verify_non_filename(): don't die unnecessarily while disambiguating If you have a working tree _file_ "foo", attempt to refer to a branch "foo/bar" without -- to disambiguate, like this: $ git log foo/bar tried to make sure that foo/bar cannot be naming a working tree file "foo/bar" (in which case we would say "which one do you want? A rev or a working tree file? clarify with -- please"). We run lstat("foo/bar") to check that. If it does not succeed, there is no ambiguity. That is good. But we also checked the error status for the lstat() and expected it to fail with ENOENT. In this particular case, however, it fails with ENOTDIR. That should be treated as "expected error" as well. Signed-off-by: Junio C Hamano --- setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.c b/setup.c index a45ea8309a..2b8e8c0e5e 100644 --- a/setup.c +++ b/setup.c @@ -103,7 +103,7 @@ void verify_non_filename(const char *prefix, const char *arg) if (!lstat(name, &st)) die("ambiguous argument '%s': both revision and filename\n" "Use '--' to separate filenames from revisions", arg); - if (errno != ENOENT) + if (errno != ENOENT && errno != ENOTDIR) die("'%s': %s", arg, strerror(errno)); } From 93969438dca50c7f0039fcf35e7ab82776d4122f Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 4 Aug 2007 21:48:08 -0700 Subject: [PATCH 191/201] apply: remove directory that becomes empty by renaming the last file away We attempt to remove directory that becomes empty after removal of a file. We should do the same when we rename an existing file away. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- builtin-apply.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-apply.c b/builtin-apply.c index 490e23ef40..9ee9393662 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -2489,7 +2489,7 @@ static void write_out_one_result(struct patch *patch, int phase) * thing: remove the old, write the new */ if (phase == 0) - remove_file(patch, 0); + remove_file(patch, patch->is_rename); if (phase == 1) create_file(patch); } From 7d4aef4027e6a95fa112fa7b069f945cad294a23 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 6 Aug 2007 01:16:43 -0700 Subject: [PATCH 192/201] Documentation/git-svn: how to clone a git-svn-created repository These instructions tell you how to create a clone of a repository created with git-svn, that can in turn be used with git-svn. Signed-off-by: Adam Roben Signed-off-by: Junio C Hamano --- Documentation/git-svn.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index 0a210e4bea..816340b944 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -435,6 +435,26 @@ Tracking and contributing to an entire Subversion-managed project # of dcommit/rebase/show-ignore should be the same as above. ------------------------------------------------------------------------ +The initial 'git-svn clone' can be quite time-consuming +(especially for large Subversion repositories). If multiple +people (or one person with multiple machines) want to use +git-svn to interact with the same Subversion repository, you can +do the initial 'git-svn clone' to a repository on a server and +have each person clone that repository with 'git clone': + +------------------------------------------------------------------------ +# Do the initial import on a server + ssh server "cd /pub && git-svn clone http://svn.foo.org/project +# Clone locally + git clone server:/pub/project +# Tell git-svn which branch contains the Subversion commits + git update-ref refs/remotes/git-svn origin/master +# Initialize git-svn locally (be sure to use the same URL and -T/-b/-t options as were used on server) + git-svn init http://svn.foo.org/project +# Pull the latest changes from Subversion + git-svn rebase +------------------------------------------------------------------------ + REBASE VS. PULL/MERGE --------------------- From 3f0a8f3c015f5f2502228a72d8c944d9e700c559 Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Mon, 6 Aug 2007 14:15:30 +0000 Subject: [PATCH 193/201] git-am: initialize variable $resume on startup git-am expects the variable $resume to be empty or unset, which might not be the case if $resume is set in the user's environment. So initialize it to an empty value on startup. The problem was noticed by Pierre Habouzit and reported through http://bugs.debian.org/435807 Signed-off-by: Gerrit Pape Signed-off-by: Junio C Hamano --- git-am.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-am.sh b/git-am.sh index 6cf0eeee71..b5ed8ca15c 100755 --- a/git-am.sh +++ b/git-am.sh @@ -103,7 +103,8 @@ It does not apply to blobs recorded in its index." } prec=4 -dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary= resolvemsg= +dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary= +resolvemsg= resume= git_apply_opt= while case "$#" in 0) break;; esac From cad3a2056d2aef3f57c3bb0eccc10614ae69926f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 6 Aug 2007 21:08:43 -0700 Subject: [PATCH 194/201] pager: find out pager setting from configuration It was very unfortunate that we added core.pager setting to the configuration file; even when the underlying command does not care if there is no git repository is involved (think "git diff --no-index"), the user would now rightfully want the configuration setting to be honored, which means we would need to read the configuration file before we launch the pager. This is a minimum change in the sense that it restores the old behaviour of not even reading config in setup_git_directory(), but have the core.pager honored when we know it matters. Note that this does not cover "git -p --git-dir where command"; the -p option immediately trigger the pager settings before we even see --git-dir to learn where the configuration file is, so we will end up reading the configuration from the place where we would _normally_ find the git repository. Signed-off-by: Junio C Hamano --- pager.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pager.c b/pager.c index 3bfed02599..8bac9d9903 100644 --- a/pager.c +++ b/pager.c @@ -31,8 +31,11 @@ void setup_pager(void) if (!isatty(1)) return; - if (!pager) + if (!pager) { + if (!pager_program) + git_config(git_default_config); pager = pager_program; + } if (!pager) pager = getenv("PAGER"); if (!pager) From 87027ae4494cd09c428e85b85337fed45a42e29c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 6 Aug 2007 21:15:15 -0700 Subject: [PATCH 195/201] Fix "make GZ=1 quick-install-doc" The basic idea is from Mark Levedahl. I do not use GZ=1 nor quick-install-doc myself (there obviously is a chicken-and-egg issue with quick-install-doc for me). Signed-off-by: Junio C Hamano --- Documentation/install-doc-quick.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Documentation/install-doc-quick.sh b/Documentation/install-doc-quick.sh index 07d227f093..5433cf8ced 100755 --- a/Documentation/install-doc-quick.sh +++ b/Documentation/install-doc-quick.sh @@ -24,10 +24,8 @@ git read-tree $head git checkout-index -a -f --prefix="$mandir"/ if test -n "$GZ"; then - cd "$mandir" - for i in `git ls-tree -r --name-only $head` - do - gzip < $i > $i.gz && rm $i - done + git ls-tree -r --name-only $head | + xargs printf "$mandir/%s\n" | + xargs gzip -f fi rm -f "$GIT_INDEX_FILE" From 5b56aaa29e9d7c0371b6d47bd8a6b12a0c4292dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=1B=2CAv=1B=28Bnig?= Date: Mon, 6 Aug 2007 22:34:50 +0200 Subject: [PATCH 196/201] send-email: teach sanitize_address to do rfc2047 quoting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this patch I'm not able to properly send emails as I have a non-ascii character in my name. I removed the _rfc822 suffix from the function name as it now does more than rfc822 quoting. I dug through rfc822 to do the double quoting right. Only if that is not possible rfc2047 quoting is applied. Signed-off-by: Uwe Kleine-K,Av(Bnig Cc: Jakub Narebski Signed-off-by: Junio C Hamano --- git-send-email.perl | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index f43f92f957..39e433b76b 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -289,7 +289,7 @@ sub expand_aliases { } @to = expand_aliases(@to); -@to = (map { sanitize_address_rfc822($_) } @to); +@to = (map { sanitize_address($_) } @to); @initial_cc = expand_aliases(@initial_cc); @bcclist = expand_aliases(@bcclist); @@ -459,22 +459,41 @@ sub unquote_rfc2047 { return "$_"; } -# If an address contains a . in the name portion, the name must be quoted. -sub sanitize_address_rfc822 +# use the simplest quoting being able to handle the recipient +sub sanitize_address { my ($recipient) = @_; - my ($recipient_name) = ($recipient =~ /^(.*?)\s+@,;:\\".\000-\037\177]/) { + $recipient_name =~ s/(["\\\r])/\\$1/; + $recipient_name = "\"$recipient_name\""; + } + + return "$recipient_name $recipient_addr"; + } sub send_message { my @recipients = unique_email_list(@to); - @cc = (map { sanitize_address_rfc822($_) } @cc); + @cc = (map { sanitize_address($_) } @cc); my $to = join (",\n\t", @recipients); @recipients = unique_email_list(@recipients,@cc,@bcclist); @recipients = (map { extract_valid_address($_) } @recipients); @@ -489,7 +508,7 @@ sub send_message if ($cc ne '') { $ccline = "\nCc: $cc"; } - $from = sanitize_address_rfc822($from); + $from = sanitize_address($from); make_message_id(); my $header = "From: $from From f9935bf9312dd6681e5051fbdce03204b6458c73 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Mon, 6 Aug 2007 14:56:32 +0200 Subject: [PATCH 197/201] Documentation/git-commit.txt: correct bad list formatting. Signed-off-by: David Kastrup Signed-off-by: Junio C Hamano --- Documentation/git-commit.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 63599d3828..e54fb12103 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -19,6 +19,7 @@ Use 'git commit' to store the current contents of the index in a new commit along with a log message describing the changes you have made. The content to be added can be specified in several ways: + 1. by using gitlink:git-add[1] to incrementally "add" changes to the index before using the 'commit' command (Note: even modified files must be "added"); From 4cf3ef97406ea10261cf6faa487520861f8b424b Mon Sep 17 00:00:00 2001 From: Steven Grimm Date: Mon, 6 Aug 2007 22:57:47 -0700 Subject: [PATCH 198/201] Add a note about the index being updated by git-status in some cases Signed-off-by: Steven Grimm Signed-off-by: Junio C Hamano --- Documentation/git-status.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt index 6f16eb0328..8fd0fc6236 100644 --- a/Documentation/git-status.txt +++ b/Documentation/git-status.txt @@ -27,6 +27,13 @@ The command takes the same set of options as `git-commit`; it shows what would be committed if the same options are given to `git-commit`. +If any paths have been touched in the working tree (that is, +their modification times have changed) but their contents and +permissions are identical to those in the index file, the command +updates the index file. Running `git-status` can thus speed up +subsequent operations such as `git-diff` if the working tree +contains many paths that have been touched but not modified. + OUTPUT ------ From e2c6de1c62373bd4aecf00e91ea7982c8fd6807e Mon Sep 17 00:00:00 2001 From: Steve Hoelzer Date: Tue, 7 Aug 2007 12:39:03 -0500 Subject: [PATCH 199/201] git-stash documentation: stash numbering starts at zero, not one Signed-off-by: Steve Hoelzer Signed-off-by: Junio C Hamano --- Documentation/git-stash.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt index 17121ade56..14e76d7745 100644 --- a/Documentation/git-stash.txt +++ b/Documentation/git-stash.txt @@ -29,8 +29,8 @@ 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 -the usual reflog syntax (e.g. `stash@\{1}` is the most recently -created stash, `stash@\{2}` is the one before it, `stash@\{2.hours.ago}` +the usual reflog syntax (e.g. `stash@\{0}` is the most recently +created stash, `stash@\{1}` is the one before it, `stash@\{2.hours.ago}` is also possible). OPTIONS @@ -61,7 +61,7 @@ show []:: stashed state and its original parent. When no `` is given, shows the latest one. By default, the command shows the diffstat, but it will accept any format known to `git-diff` (e.g., `git-stash show - -p stash@\{2}` to view the second most recent stash in patch form). + -p stash@\{1}` to view the second most recent stash in patch form). apply []:: From 3671757546ce78bb04611aa5481c2aa77a1ffc90 Mon Sep 17 00:00:00 2001 From: Steve Hoelzer Date: Tue, 7 Aug 2007 12:38:29 -0500 Subject: [PATCH 200/201] git-stash documentation: add missing backtick Signed-off-by: Steve Hoelzer Signed-off-by: Junio C Hamano --- Documentation/git-stash.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt index 14e76d7745..05f40cff6c 100644 --- a/Documentation/git-stash.txt +++ b/Documentation/git-stash.txt @@ -45,7 +45,7 @@ save:: list:: List the stashes that you currently have. Each 'stash' is listed - with its name (e.g. `stash@\{0}` is the latest stash, `stash@\{1} is + with its name (e.g. `stash@\{0}` is the latest stash, `stash@\{1}` is the one before, etc.), the name of the branch that was current when the stash was made, and a short description of the commit the stash was based on. From 74276ec6f2d2123714066cee24b26a629930e7a8 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 7 Aug 2007 12:28:00 +0200 Subject: [PATCH 201/201] git-p4: Fix support for symlinks. Detect symlinks as file type, set the git file mode accordingly and strip off the trailing newline in the p4 print output. Make the mode handling a bit more readable at the same time. Signed-off-by: Simon Hausmann Acked-by: Brian Swetland Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 41e86e76cb..3cbb2da221 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -839,16 +839,20 @@ class P4Sync(Command): if file["action"] == "delete": self.gitStream.write("D %s\n" % relPath) else: - mode = 644 - if file["type"].startswith("x"): - mode = 755 - data = file['data'] + mode = "644" + if file["type"].startswith("x"): + mode = "755" + elif file["type"] == "symlink": + mode = "120000" + # p4 print on a symlink contains "target\n", so strip it off + data = data[:-1] + if self.isWindows and file["type"].endswith("text"): data = data.replace("\r\n", "\n") - self.gitStream.write("M %d inline %s\n" % (mode, relPath)) + self.gitStream.write("M %s inline %s\n" % (mode, relPath)) self.gitStream.write("data %s\n" % len(data)) self.gitStream.write(data) self.gitStream.write("\n")