From 3cd204e518ce832402c291be73292baa149d0240 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Thu, 23 Nov 2006 21:06:16 +1100 Subject: [PATCH 1/8] gitk: Fix enabling/disabling of menu items on Mac OS X It seems that under Mac OS X, the menus get some extra entries (or possibly fewer entries), leading to references to entries by an absolute number being off. This leads to an error when invoking gitk --all under Mac OS X, because the "Edit view" and "Delete view" entries aren't were gitk expects them, and so enabling them gives an error. This changes the code so it refers to menu entries by their content, which should solve the problem. Signed-off-by: Paul Mackerras --- gitk | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gitk b/gitk index ab383b3ad2..3dabc69516 100755 --- a/gitk +++ b/gitk @@ -554,7 +554,7 @@ proc makewindow {} { pack .ctop.top.lbar.vlabel -side left -fill y global viewhlmenu selectedhlview set viewhlmenu [tk_optionMenu .ctop.top.lbar.vhl selectedhlview None] - $viewhlmenu entryconf 0 -command delvhighlight + $viewhlmenu entryconf None -command delvhighlight $viewhlmenu conf -font $uifont .ctop.top.lbar.vhl conf -font $uifont pack .ctop.top.lbar.vhl -side left -fill y @@ -1474,7 +1474,7 @@ proc doviewmenu {m first cmd op argv} { proc allviewmenus {n op args} { global viewhlmenu - doviewmenu .bar.view 7 [list showview $n] $op $args + doviewmenu .bar.view 5 [list showview $n] $op $args doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args } @@ -1516,7 +1516,7 @@ proc newviewok {top n} { set viewperm($n) $newviewperm($n) if {$newviewname($n) ne $viewname($n)} { set viewname($n) $newviewname($n) - doviewmenu .bar.view 7 [list showview $n] \ + doviewmenu .bar.view 5 [list showview $n] \ entryconf [list -label $viewname($n)] doviewmenu $viewhlmenu 1 [list addvhighlight $n] \ entryconf [list -label $viewname($n) -value $viewname($n)] @@ -1632,8 +1632,8 @@ proc showview {n} { set curview $n set selectedview $n - .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}] - .bar.view entryconf 3 -state [expr {$n == 0? "disabled": "normal"}] + .bar.view entryconf Edit* -state [expr {$n == 0? "disabled": "normal"}] + .bar.view entryconf Delete* -state [expr {$n == 0? "disabled": "normal"}] if {![info exists viewdata($n)]} { set pending_select $selid @@ -4899,9 +4899,9 @@ proc rowmenu {x y id} { } else { set state normal } - $rowctxmenu entryconfigure 0 -state $state - $rowctxmenu entryconfigure 1 -state $state - $rowctxmenu entryconfigure 2 -state $state + $rowctxmenu entryconfigure "Diff this*" -state $state + $rowctxmenu entryconfigure "Diff selected*" -state $state + $rowctxmenu entryconfigure "Make patch" -state $state set rowmenuid $id tk_popup $rowctxmenu $x $y } @@ -6305,8 +6305,8 @@ if {$cmdline_files ne {} || $revtreeargs ne {}} { set viewargs(1) $revtreeargs set viewperm(1) 0 addviewmenu 1 - .bar.view entryconf 2 -state normal - .bar.view entryconf 3 -state normal + .bar.view entryconf Edit* -state normal + .bar.view entryconf Delete* -state normal } if {[info exists permviews]} { From 67c08ce14fb488562666ab896541ad75f1bdcca6 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 29 Nov 2006 17:15:48 -0500 Subject: [PATCH 2/8] pack-objects: remove redundent status information The final 'nr_result' and 'written' values must always be the same otherwise we're in deep trouble. So let's remove a redundent report. And for paranoia sake let's make sure those two variables are actually equal after all objects are written (one never knows). Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 753bcd57b0..a2dc7d1d9d 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -514,6 +514,8 @@ static void write_pack_file(void) if (do_progress) fputc('\n', stderr); done: + if (written != nr_result) + die("wrote %d objects while expecting %d", written, nr_result); sha1close(f, pack_file_sha1, 1); } @@ -1662,7 +1664,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) } } if (progress) - fprintf(stderr, "Total %d, written %d (delta %d), reused %d (delta %d)\n", - nr_result, written, written_delta, reused, reused_delta); + fprintf(stderr, "Total %d (delta %d), reused %d (delta %d)\n", + written, written_delta, reused, reused_delta); return 0; } From ced7b828fadbf3d6de49d75392f1516b4ceb4491 Mon Sep 17 00:00:00 2001 From: Andreas Ericsson Date: Thu, 30 Nov 2006 12:28:28 +0100 Subject: [PATCH 3/8] ls-files: Give hints when errors happen. Without this patch "git commit file.c file2.c" produces the not so stellar output: error: pathspec 'file.c' did not match any. error: pathspec 'file2.c' did not match any. With this patch, the output is changed to: error: pathspec 'file.c' did not match any file(s) known to git. error: pathspec 'file2.c' did not match any file(s) known to git. Did you forget to 'git add'? Signed-off-by: Andreas Ericsson Signed-off-by: Junio C Hamano --- builtin-ls-files.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/builtin-ls-files.c b/builtin-ls-files.c index ad8c41e731..bc79ce40fc 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -487,10 +487,14 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) for (num = 0; pathspec[num]; num++) { if (ps_matched[num]) continue; - error("pathspec '%s' did not match any.", + error("pathspec '%s' did not match any file(s) known to git.", pathspec[num] + prefix_offset); errors++; } + + if (errors) + fprintf(stderr, "Did you forget to 'git add'?\n"); + return errors ? 1 : 0; } From 4c81c213a479e4aae0653a56ad6e8db5c31f019c Mon Sep 17 00:00:00 2001 From: Andreas Ericsson Date: Thu, 30 Nov 2006 12:43:13 +0100 Subject: [PATCH 4/8] git-diff: Introduce --index and deprecate --cached. 'git diff --cached' still works, but its use is discouraged in the documentation. 'git diff --index' does the same thing and is consistent with how 'git apply --index' works. Signed-off-by: Andreas Ericsson Signed-off-by: Junio C Hamano --- Documentation/git-diff.txt | 6 ++++-- builtin-diff.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 228c4d95bd..3144864d85 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -22,8 +22,10 @@ the number of trees given to the command. * When one is given, the working tree and the named tree are compared, using `git-diff-index`. The option - `--cached` can be given to compare the index file and + `--index` can be given to compare the index file and the named tree. + `--cached` is a deprecated alias for `--index`. It's use is + discouraged. * When two s are given, these two trees are compared using `git-diff-tree`. @@ -47,7 +49,7 @@ Various ways to check your working tree:: + ------------ $ git diff <1> -$ git diff --cached <2> +$ git diff --index <2> $ git diff HEAD <3> ------------ + diff --git a/builtin-diff.c b/builtin-diff.c index a6590205e8..1c535b1dd6 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -137,7 +137,7 @@ static int builtin_diff_index(struct rev_info *revs, int cached = 0; while (1 < argc) { const char *arg = argv[1]; - if (!strcmp(arg, "--cached")) + if (!strcmp(arg, "--index") || !strcmp(arg, "--cached")) cached = 1; else usage(builtin_diff_usage); From 22b1c7ee01ef5bc7f81e620bb88a6fad79c1c605 Mon Sep 17 00:00:00 2001 From: Andy Parkins Date: Thu, 30 Nov 2006 10:50:28 +0000 Subject: [PATCH 5/8] De-emphasise the symbolic link documentation. The fact that git has previously used symbolic links for representing symbolic refs doesn't seem relevant to the current function of git-symbolic-ref. This patch makes less of a big deal about the symbolic link history and instead focuses on what git does now. Signed-off-by: Andy Parkins Signed-off-by: Junio C Hamano --- Documentation/git-symbolic-ref.txt | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/Documentation/git-symbolic-ref.txt b/Documentation/git-symbolic-ref.txt index 68ac6a65df..4bc35a1d4b 100644 --- a/Documentation/git-symbolic-ref.txt +++ b/Documentation/git-symbolic-ref.txt @@ -19,29 +19,22 @@ argument to see on which branch your working tree is on. Give two arguments, create or update a symbolic ref to point at the given branch . -Traditionally, `.git/HEAD` is a symlink pointing at -`refs/heads/master`. When we want to switch to another branch, -we did `ln -sf refs/heads/newbranch .git/HEAD`, and when we want +A symbolic ref is a regular file that stores a string that +begins with `ref: refs/`. For example, your `.git/HEAD` is +a regular file whose contents is `ref: refs/heads/master`. + +NOTES +----- +In the past, `.git/HEAD` was a symbolic link pointing at +`refs/heads/master`. When we wanted to switch to another branch, +we did `ln -sf refs/heads/newbranch .git/HEAD`, and when we wanted to find out which branch we are on, we did `readlink .git/HEAD`. This was fine, and internally that is what still happens by default, but on platforms that do not have working symlinks, or that do not have the `readlink(1)` command, this was a bit cumbersome. On some platforms, `ln -sf` does not even work as -advertised (horrors). - -A symbolic ref can be a regular file that stores a string that -begins with `ref: refs/`. For example, your `.git/HEAD` *can* -be a regular file whose contents is `ref: refs/heads/master`. -This can be used on a filesystem that does not support symbolic -links. Instead of doing `readlink .git/HEAD`, `git-symbolic-ref -HEAD` can be used to find out which branch we are on. To point -the HEAD to `newbranch`, instead of `ln -sf refs/heads/newbranch -.git/HEAD`, `git-symbolic-ref HEAD refs/heads/newbranch` can be -used. - -Currently, .git/HEAD uses a regular file symbolic ref on Cygwin, -and everywhere else it is implemented as a symlink. This can be -changed at compilation time. +advertised (horrors). Therefore symbolic links are now deprecated +and symbolic refs are used by default. Author ------ From 3683dc5a9afaf88d00e55c9e6c67a2160ca7fc9c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 2 Dec 2006 16:58:30 -0800 Subject: [PATCH 6/8] git-merge: fix confusion between tag and branch In a repository with core.warnambiguousrefs turned off, and with a branch and a tag that have the same name 'frotz', git merge frotz would merge the commit pointed at by the tag 'frotz' but incorrectly would identify what was merged as 'branch frotz' in the merge message. Signed-off-by: Junio C Hamano --- git-merge.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/git-merge.sh b/git-merge.sh index 75af10d3e4..272f004622 100755 --- a/git-merge.sh +++ b/git-merge.sh @@ -189,13 +189,13 @@ else merge_name=$(for remote do rh=$(git-rev-parse --verify "$remote"^0 2>/dev/null) && - if git show-ref -q --verify "refs/heads/$remote" + bh=$(git show-ref -s --verify "refs/heads/$remote") && + if test "$rh" = "$bh" then - what=branch + echo "$rh branch '$remote' of ." else - what=commit - fi && - echo "$rh $what '$remote'" + echo "$rh commit '$remote'" + fi done | git-fmt-merge-msg ) merge_msg="${merge_msg:+$merge_msg$LF$LF}$merge_name" From 6173c197c9a23fa8594f18fd2c856407d4af31c1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 2 Dec 2006 16:19:31 -0800 Subject: [PATCH 7/8] git-svn: avoid fetching files twice in the same revision SVN is not entirely consistent in returning log information and sometimes returns file information when adding subdirectories, and sometimes it does not (only returning information about the directory that was added). This caused git-svn to occasionally add a file to the list of files to be fetched twice. Now we change the data structure to be hash to avoid repeated fetches. As of now (in master), this only affects repositories fetched without deltas enabled (file://, and when manually overriden with GIT_SVN_DELTA_FETCH=0); so this bug mainly affects users of 1.4.4.1 and maint. Thanks to Florian Weimer for reporting this bug. [jc: backported for maint] Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index bb8935afe6..b53273eaea 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -2778,7 +2778,7 @@ sub process_rm { sub libsvn_fetch { my ($last_commit, $paths, $rev, $author, $date, $msg) = @_; open my $gui, '| git-update-index -z --index-info' or croak $!; - my @amr; + my %amr; foreach my $f (keys %$paths) { my $m = $paths->{$f}->action(); $f =~ s#^/+##; @@ -2792,7 +2792,7 @@ sub libsvn_fetch { my $t = $SVN->check_path($f, $rev, $pool); if ($t == $SVN::Node::file) { if ($m =~ /^[AMR]$/) { - push @amr, [ $m, $f ]; + $amr{$f} = $m; } else { die "Unrecognized action: $m, ($f r$rev)\n"; } @@ -2800,13 +2800,13 @@ sub libsvn_fetch { my @traversed = (); libsvn_traverse($gui, '', $f, $rev, \@traversed); foreach (@traversed) { - push @amr, [ $m, $_ ] + $amr{$_} = $m; } } $pool->clear; } - foreach (@amr) { - libsvn_get_file($gui, $_->[1], $rev, $_->[0]); + foreach (keys %amr) { + libsvn_get_file($gui, $_, $rev, $amr{$_}); } close $gui or croak $?; return libsvn_log_entry($rev, $author, $date, $msg, [$last_commit]); From a2a92ab17fe120f6b28d123ac2fd41f066f0de1e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 29 Nov 2006 18:53:13 -0800 Subject: [PATCH 8/8] git-merge: preserve and merge local changes when doing fast forward The idea and the logic are identical to what "checkout -m" does when switching the branches. Instead of refusing the two-way merge, perform the three-way merge between the old head, the working tree and the new head, and leave the (potentially conflicted) merge result in the working tree. When the resulting conflict were too much to handle for the user, there is no easy way to get that back, so they are stashed away in $GIT_DIR/LOCAL_DIFF file. We do the same for "git checkout -m". If this turns out to be a sane thing to do, we probably should make the common logic between "checkout -m" and this into a built-in command. Signed-off-by: Junio C Hamano --- git-checkout.sh | 7 +++++++ git-merge.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/git-checkout.sh b/git-checkout.sh index 737abd0c09..5bf399a276 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -168,6 +168,9 @@ else exit 1 ;; esac + # First stash away the local changes + git diff-index --binary -p HEAD >"$GIT_DIR"/LOCAL_DIFF + # Match the index to the working tree, and do a three-way. git diff-files --name-only | git update-index --remove --stdin && work=`git write-tree` && @@ -195,6 +198,10 @@ else sed -e 's/^[0-7]* [0-9a-f]* /'"0 $z40 /" echo "$unmerged" ) | git update-index --index-info + + echo >&2 "Conflicts in locally modified files:" + git diff --name-only --diff-filter=U >&2 + echo >&2 "Your local changes are found in $GIT_DIR/LOCAL_DIFF" ;; esac exit 0 diff --git a/git-merge.sh b/git-merge.sh index 272f004622..798aad3576 100755 --- a/git-merge.sh +++ b/git-merge.sh @@ -91,6 +91,51 @@ finish () { esac } +merge_local_changes () { + merge_error=$(git-read-tree -m -u $1 $2 2>&1) || ( + + # First stash away the local changes + git diff-index --binary -p HEAD >"$GIT_DIR"/LOCAL_DIFF + + # Match the index to the working tree, and do a three-way. + git diff-files --name-only | + git update-index --remove --stdin && + work=`git write-tree` && + git read-tree --reset -u $2 && + git read-tree -m -u --aggressive $1 $2 $work || exit + + echo >&2 "Carrying local changes forward." + if result=`git write-tree 2>/dev/null` + then + echo >&2 "Trivially automerged." + else + git merge-index -o git-merge-one-file -a + fi + + # Do not register the cleanly merged paths in the index + # yet; this is not a real merge before committing, but + # just carrying the working tree changes along. + unmerged=`git ls-files -u` + git read-tree --reset $2 + case "$unmerged" in + '') ;; + *) + ( + z40=0000000000000000000000000000000000000000 + echo "$unmerged" | + sed -e 's/^[0-7]* [0-9a-f]* /'"0 $z40 /" + echo "$unmerged" + ) | git update-index --index-info + + echo >&2 "Conflicts in locally modified files:" + git diff --name-only --diff-filter=U >&2 + echo >&2 "Your local changes are found in $GIT_DIR/LOCAL_DIFF" + ;; + esac + exit 0 + ) +} + case "$#" in 0) usage ;; esac rloga= have_message= @@ -264,7 +309,7 @@ f,*) echo "Updating $(git-rev-parse --short $head)..$(git-rev-parse --short $1)" git-update-index --refresh 2>/dev/null new_head=$(git-rev-parse --verify "$1^0") && - git-read-tree -u -v -m $head "$new_head" && + merge_local_changes $head $new_head && finish "$new_head" "Fast forward" dropsave exit 0