Code

Merge branch 'js/bisect-no-checkout' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 1 Nov 2011 23:03:35 +0000 (16:03 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 1 Nov 2011 23:03:35 +0000 (16:03 -0700)
* js/bisect-no-checkout:
  bisect: fix exiting when checkout failed in bisect_start()

326 files changed:
Documentation/.gitignore
Documentation/Makefile
Documentation/RelNotes/1.7.6.1.txt [new file with mode: 0644]
Documentation/RelNotes/1.7.6.2.txt [new file with mode: 0644]
Documentation/RelNotes/1.7.6.3.txt [new file with mode: 0644]
Documentation/RelNotes/1.7.6.4.txt [new file with mode: 0644]
Documentation/RelNotes/1.7.7.1.txt [new file with mode: 0644]
Documentation/RelNotes/1.7.7.txt
Documentation/SubmittingPatches
Documentation/config.txt
Documentation/diff-options.txt
Documentation/git-am.txt
Documentation/git-archive.txt
Documentation/git-branch.txt
Documentation/git-check-attr.txt
Documentation/git-cherry-pick.txt
Documentation/git-clean.txt
Documentation/git-daemon.txt
Documentation/git-fast-export.txt
Documentation/git-fast-import.txt
Documentation/git-format-patch.txt
Documentation/git-grep.txt
Documentation/git-gui.txt
Documentation/git-http-backend.txt
Documentation/git-http-fetch.txt
Documentation/git-log.txt
Documentation/git-merge-file.txt
Documentation/git-mergetool.txt
Documentation/git-notes.txt
Documentation/git-push.txt
Documentation/git-read-tree.txt
Documentation/git-receive-pack.txt
Documentation/git-remote-fd.txt
Documentation/git-remote-helpers.txt
Documentation/git-remote-testgit.txt [new file with mode: 0644]
Documentation/git-revert.txt
Documentation/git-rm.txt
Documentation/git-show.txt
Documentation/git-submodule.txt
Documentation/git-svn.txt
Documentation/git-tar-tree.txt
Documentation/git-update-index.txt
Documentation/git-upload-pack.txt
Documentation/git-whatchanged.txt
Documentation/git.txt
Documentation/gitattributes.txt
Documentation/gitnamespaces.txt [new file with mode: 0644]
Documentation/gitrepository-layout.txt
Documentation/howto/maintain-git.txt
Documentation/technical/api-argv-array.txt [new file with mode: 0644]
Documentation/technical/api-builtin.txt
Documentation/technical/api-gitattributes.txt
Documentation/technical/api-ref-iteration.txt [new file with mode: 0644]
Documentation/technical/api-sha1-array.txt [new file with mode: 0644]
Documentation/technical/api-string-list.txt
GIT-VERSION-GEN
Makefile
RelNotes
abspath.c
archive.c
argv-array.c [new file with mode: 0644]
argv-array.h [new file with mode: 0644]
attr.c
attr.h
bisect.c
branch.c
branch.h
builtin/apply.c
builtin/archive.c
builtin/branch.c
builtin/bundle.c
builtin/check-attr.c
builtin/check-ref-format.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clean.c
builtin/clone.c
builtin/commit.c
builtin/config.c
builtin/describe.c
builtin/diff.c
builtin/fast-export.c
builtin/fetch-pack.c
builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/fsck.c
builtin/grep.c
builtin/init-db.c
builtin/log.c
builtin/ls-files.c
builtin/ls-tree.c
builtin/merge.c
builtin/mv.c
builtin/pack-objects.c
builtin/patch-id.c
builtin/push.c
builtin/receive-pack.c
builtin/reflog.c
builtin/remote.c
builtin/reset.c
builtin/revert.c
builtin/show-branch.c
builtin/update-ref.c
bundle.c
bundle.h
cache.h
color.c
color.h
combine-diff.c
commit.c
commit.h
compat/mingw.c
compat/obstack.c [new file with mode: 0644]
compat/obstack.h [new file with mode: 0644]
compat/qsort.c
config.c
connect.c
contrib/completion/git-completion.bash
contrib/fast-import/git-p4
contrib/fast-import/git-p4.txt
contrib/hooks/post-receive-email
convert.c
date.c
diff-lib.c
diff.c
diff.h
diffcore-pickaxe.c
diffcore.h
environment.c
fast-import.c
fsck.c
generate-cmdlist.sh
git-am.sh
git-bisect.sh
git-compat-util.h
git-difftool--helper.sh
git-filter-branch.sh
git-merge-one-file.sh
git-mergetool--lib.sh
git-mergetool.sh
git-pull.sh
git-rebase--interactive.sh
git-rebase.sh
git-remote-testgit.py
git-sh-i18n.sh
git-stash.sh
git-submodule.sh
git-svn.perl
git.c
git_remote_helpers/git/exporter.py
git_remote_helpers/git/importer.py
git_remote_helpers/git/non_local.py
git_remote_helpers/git/repo.py
git_remote_helpers/util.py
gitweb/INSTALL
gitweb/Makefile
gitweb/README
gitweb/gitweb.perl
gitweb/static/js/javascript-detection.js
graph.c
grep.c
grep.h
http-fetch.c
http-push.c
http.c
kwset.c [new file with mode: 0644]
kwset.h [new file with mode: 0644]
ll-merge.c
log-tree.c
merge-recursive.c
merge-recursive.h
mergetools/araxis [new file with mode: 0644]
mergetools/bc3 [new file with mode: 0644]
mergetools/defaults [new file with mode: 0644]
mergetools/diffuse [new file with mode: 0644]
mergetools/ecmerge [new file with mode: 0644]
mergetools/emerge [new file with mode: 0644]
mergetools/kdiff3 [new file with mode: 0644]
mergetools/kompare [new file with mode: 0644]
mergetools/meld [new file with mode: 0644]
mergetools/opendiff [new file with mode: 0644]
mergetools/p4merge [new file with mode: 0644]
mergetools/tkdiff [new file with mode: 0644]
mergetools/tortoisemerge [new file with mode: 0644]
mergetools/vim [new file with mode: 0644]
mergetools/xxdiff [new file with mode: 0644]
notes-merge.c
notes.c
pager.c
parse-options-cb.c [new file with mode: 0644]
parse-options.c
parse-options.h
path.c
quote.c
quote.h
read-cache.c
refs.c
refs.h
remote-curl.c
remote.c
remote.h
revision.c
revision.h
run-command.c
setup.c
sha1_file.c
show-index.c
strbuf.c
streaming.c
string-list.c
string-list.h
submodule.c
submodule.h
t/lib-diff-alternative.sh [new file with mode: 0644]
t/t0003-attributes.sh
t/t0006-date.sh
t/t1013-loose-object-format.sh [new file with mode: 0755]
t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 [new file with mode: 0644]
t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 [new file with mode: 0644]
t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd [new file with mode: 0644]
t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 [new file with mode: 0644]
t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e [new file with mode: 0644]
t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 [new file with mode: 0644]
t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd [new file with mode: 0644]
t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb [new file with mode: 0644]
t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 [new file with mode: 0644]
t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 [new file with mode: 0644]
t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 [new file with mode: 0644]
t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa [new file with mode: 0644]
t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f [new file with mode: 0644]
t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 [new file with mode: 0644]
t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 [new file with mode: 0644]
t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 [new file with mode: 0644]
t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a [new file with mode: 0644]
t/t1020-subdirectory.sh
t/t1300-repo-config.sh
t/t1304-default-acl.sh
t/t1402-check-ref-format.sh
t/t1412-reflog-loop.sh
t/t1450-fsck.sh
t/t2018-checkout-branch.sh
t/t2022-checkout-paths.sh [new file with mode: 0755]
t/t3005-ls-files-relative.sh [new file with mode: 0755]
t/t3030-merge-recursive.sh
t/t3103-ls-tree-misc.sh [new file with mode: 0755]
t/t3200-branch.sh
t/t3307-notes-man.sh
t/t3404-rebase-interactive.sh
t/t3503-cherry-pick-root.sh
t/t3900-i18n-commit.sh
t/t3902-quoted.sh
t/t3903-stash.sh
t/t4012-diff-binary.sh
t/t4014-format-patch.sh
t/t4033-diff-patience.sh
t/t4050-diff-histogram.sh [new file with mode: 0755]
t/t4150-am.sh
t/t4254-am-corrupt.sh [new file with mode: 0755]
t/t5000-tar-tree.sh
t/t5505-remote.sh
t/t5509-fetch-push-namespaces.sh [new file with mode: 0755]
t/t5510-fetch.sh
t/t5531-deep-submodule-push.sh
t/t5540-http-push.sh
t/t5601-clone.sh
t/t5707-clone-detached.sh [new file with mode: 0755]
t/t5800-remote-helpers.sh
t/t6019-rev-list-ancestry-path.sh
t/t6020-merge-df.sh
t/t6022-merge-rename.sh
t/t6023-merge-file.sh
t/t6027-merge-binary.sh
t/t6030-bisect-porcelain.sh
t/t6036-recursive-corner-cases.sh
t/t6040-tracking-info.sh
t/t6042-merge-rename-corner-cases.sh [new file with mode: 0755]
t/t7006-pager.sh
t/t7008-grep-binary.sh
t/t7102-reset.sh
t/t7400-submodule-basic.sh
t/t7511-status-index.sh [new file with mode: 0755]
t/t7602-merge-octopus-many.sh
t/t7607-merge-overwrite.sh
t/t7609-merge-co-error-msgs.sh
t/t7610-mergetool.sh
t/t7800-difftool.sh
t/t7810-grep.sh
t/t9158-git-svn-mergeinfo.sh
t/t9159-git-svn-no-parent-mergeinfo.sh
t/t9160-git-svn-preserve-empty-dirs.sh [new file with mode: 0755]
t/t9161-git-svn-mergeinfo-push.sh [new file with mode: 0755]
t/t9161/branches.dump [new file with mode: 0644]
t/t9200-git-cvsexportcommit.sh
t/t9300-fast-import.sh
t/t9350-fast-export.sh
t/t9800-git-p4.sh
t/test-binary-1.png [new file with mode: 0644]
t/test-binary-2.png [new file with mode: 0644]
t/test-lib.sh
t/test4012.png [deleted file]
t/test9200a.png [deleted file]
t/test9200b.png [deleted file]
templates/hooks--post-commit.sample [deleted file]
templates/hooks--post-receive.sample [deleted file]
templates/hooks--pre-commit.sample
test-path-utils.c
transport-helper.c
transport.c
transport.h
tree-walk.c
tree-walk.h
unpack-trees.c
unpack-trees.h
upload-pack.c
usage.c
userdiff.c
ws.c
wt-status.c
xdiff/xdiff.h
xdiff/xdiffi.c
xdiff/xdiffi.h
xdiff/xhistogram.c [new file with mode: 0644]
xdiff/xpatience.c
xdiff/xprepare.c
xdiff/xutils.c
xdiff/xutils.h

index 1c3a9fead579a9b52037f1bbe245998db8a2f40b..d62aebd848b2a44f977ad4d7c4b75b6ff72b2163 100644 (file)
@@ -3,6 +3,7 @@
 *.[1-8]
 *.made
 *.texi
+*.pdf
 git.info
 gitman.info
 howto-index.txt
index 36989b7f6541cb8444385b64d2c955ae2a1f6d1b..6346a75dda72533667a96eea2bd65bb280383f99 100644 (file)
@@ -6,7 +6,7 @@ MAN5_TXT=gitattributes.txt gitignore.txt gitmodules.txt githooks.txt \
        gitrepository-layout.txt
 MAN7_TXT=gitcli.txt gittutorial.txt gittutorial-2.txt \
        gitcvs-migration.txt gitcore-tutorial.txt gitglossary.txt \
-       gitdiffcore.txt gitrevisions.txt gitworkflows.txt
+       gitdiffcore.txt gitnamespaces.txt gitrevisions.txt gitworkflows.txt
 
 MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT)
 MAN_XML=$(patsubst %.txt,%.xml,$(MAN_TXT))
@@ -232,6 +232,7 @@ cmd-list.made: cmd-list.perl ../command-list.txt $(MAN1_TXT)
 clean:
        $(RM) *.xml *.xml+ *.html *.html+ *.1 *.5 *.7
        $(RM) *.texi *.texi+ *.texi++ git.info gitman.info
+       $(RM) *.pdf
        $(RM) howto-index.txt howto/*.html doc.dep
        $(RM) technical/api-*.html technical/api-index.txt
        $(RM) $(cmds_txt) *.made
diff --git a/Documentation/RelNotes/1.7.6.1.txt b/Documentation/RelNotes/1.7.6.1.txt
new file mode 100644 (file)
index 0000000..42e46ab
--- /dev/null
@@ -0,0 +1,63 @@
+Git v1.7.6.1 Release Notes
+==========================
+
+Fixes since v1.7.6
+------------------
+
+ * Various codepaths that invoked zlib deflate/inflate assumed that these
+   functions can compress or uncompress more than 4GB data in one call on
+   platforms with 64-bit long, which has been corrected.
+
+ * "git unexecutable" reported that "unexecutable" was not found, even
+   though the actual error was that "unexecutable" was found but did
+   not have a proper she-bang line to be executed.
+
+ * Error exits from $PAGER were silently ignored.
+
+ * "git checkout -b <branch>" was confused when attempting to create a
+   branch whose name ends with "-g" followed by hexadecimal digits,
+   and refused to work.
+
+ * "git checkout -b <branch>" sometimes wrote a bogus reflog entry,
+   causing later "git checkout -" to fail.
+
+ * "git diff --cc" learned to correctly ignore binary files.
+
+ * "git diff -c/--cc" mishandled a deletion that resolves a conflict, and
+   looked in the working tree instead.
+
+ * "git fast-export" forgot to quote pathnames with unsafe characters
+   in its output.
+
+ * "git fetch" over smart-http transport used to abort when the
+   repository was updated between the initial connection and the
+   subsequent object transfer.
+
+ * "git fetch" did not recurse into submodules in subdirectories.
+
+ * "git ls-tree" did not error out when asked to show a corrupt tree.
+
+ * "git pull" without any argument left an extra whitespace after the
+   command name in its reflog.
+
+ * "git push --quiet" was not really quiet.
+
+ * "git rebase -i -p" incorrectly dropped commits from side branches.
+
+ * "git reset [<commit>] paths..." did not reset the index entry correctly
+   for unmerged paths.
+
+ * "git submodule add" did not allow a relative repository path when
+   the superproject did not have any default remote url.
+
+ * "git submodule foreach" failed to correctly give the standard input to
+   the user-supplied command it invoked.
+
+ * submodules that the user has never showed interest in by running
+   "git submodule init" was incorrectly marked as interesting by "git
+   submodule sync".
+
+ * "git submodule update --quiet" was not really quiet.
+
+  * "git tag -l <glob>..." did not take multiple glob patterns from the
+   command line.
diff --git a/Documentation/RelNotes/1.7.6.2.txt b/Documentation/RelNotes/1.7.6.2.txt
new file mode 100644 (file)
index 0000000..67ae414
--- /dev/null
@@ -0,0 +1,8 @@
+Git v1.7.6.2 Release Notes
+==========================
+
+Fixes since v1.7.6.1
+--------------------
+
+ * v1.7.6.1 broke "git push --quiet"; it used to be a no-op against an old
+   version of Git running on the other end, but v1.7.6.1 made it abort.
diff --git a/Documentation/RelNotes/1.7.6.3.txt b/Documentation/RelNotes/1.7.6.3.txt
new file mode 100644 (file)
index 0000000..9597183
--- /dev/null
@@ -0,0 +1,24 @@
+Git v1.7.6.3 Release Notes
+==========================
+
+Fixes since v1.7.6.2
+--------------------
+
+ * "git -c var=value subcmd" misparsed the custom configuration when
+   value contained an equal sign.
+
+ * "git fetch" had a major performance regression, wasting many
+   needless cycles in a repository where there is no submodules
+   present. This was especially bad, when there were many refs.
+
+ * "git reflog $refname" did not default to the "show" subcommand as
+   the documentation advertised the command to do.
+
+ * "git reset" did not leave meaningful log message in the reflog.
+
+ * "git status --ignored" did not show ignored items when there is no
+   untracked items.
+
+ * "git tag --contains $commit" was unnecessarily inefficient.
+
+Also contains minor fixes and documentation updates.
diff --git a/Documentation/RelNotes/1.7.6.4.txt b/Documentation/RelNotes/1.7.6.4.txt
new file mode 100644 (file)
index 0000000..e19acac
--- /dev/null
@@ -0,0 +1,32 @@
+Git v1.7.6.4 Release Notes
+==========================
+
+Fixes since v1.7.6.3
+--------------------
+
+ * The error reporting logic of "git am" when the command is fed a file
+   whose mail-storage format is unknown was fixed.
+
+ * "git branch --set-upstream @{-1} foo" did not expand @{-1} correctly.
+
+ * "git check-ref-format --print" used to parrot a candidate string that
+   began with a slash (e.g. /refs/heads/master) without stripping it, to make
+   the result a suitably normalized string the caller can append to "$GIT_DIR/".
+
+ * "git clone" failed to clone locally from a ".git" file that itself
+   is not a directory but is a pointer to one.
+
+ * "git clone" from a local repository that borrows from another
+   object store using a relative path in its objects/info/alternates
+   file did not adjust the alternates in the resulting repository.
+
+ * "git describe --dirty" did not refresh the index before checking the
+   state of the working tree files.
+
+ * "git ls-files ../$path" that is run from a subdirectory reported errors
+   incorrectly when there is no such path that matches the given pathspec.
+
+ * "git mergetool" could loop forever prompting when nothing can be read
+   from the standard input.
+
+Also contains minor fixes and documentation updates.
diff --git a/Documentation/RelNotes/1.7.7.1.txt b/Documentation/RelNotes/1.7.7.1.txt
new file mode 100644 (file)
index 0000000..ac9b838
--- /dev/null
@@ -0,0 +1,60 @@
+Git v1.7.7.1 Release Notes
+==========================
+
+Fixes since v1.7.7
+------------------
+
+ * On some BSD systems, adding +s bit on directories is detrimental
+   (it is not necessary on BSD to begin with). "git init --shared"
+   has been updated to take this into account without extra makefile
+   settings on platforms the Makefile knows about.
+
+ * After incorrectly written third-party tools store a tag object in
+   HEAD, git diagnosed it as a repository corruption and refused to
+   proceed in order to avoid spreading the damage. We now gracefully
+   recover from such a situation by pretending as if the commit that
+   is pointed at by the tag were in HEAD.
+
+ * "git apply --whitespace=error" did not bother to report the exact
+   line number in the patch that introduced new blank lines at the end
+   of the file.
+
+ * "git apply --index" did not check corrupted patch.
+
+ * "git checkout $tree $directory/" resurrected paths locally removed or
+   modified only in the working tree in $directory/ that did not appear
+   in $directory of the given $tree. They should have been kept intact.
+
+ * "git diff $tree $path" used to apply the pathspec at the output stage,
+   reading the whole tree, wasting resources.
+
+ * The code to check for updated submodules during a "git fetch" of the
+   superproject had an unnecessary quadratic loop.
+
+ * "git fetch" from a large bundle did not enable the progress output.
+
+ * When "git fsck --lost-and-found" found that an empty blob object in the
+   object store is unreachable, it incorrectly reported an error after
+   writing the lost blob out successfully.
+
+ * "git filter-branch" did not refresh the index before checking that the
+   working tree was clean.
+
+ * "git grep $tree" when run with multiple threads had an unsafe access to
+   the object database that should have been protected with mutex.
+
+ * The "--ancestry-path" option to "git log" and friends misbehaved in a
+   history with complex criss-cross merges and showed an uninteresting
+   side history as well.
+
+ * Test t1304 assumed LOGNAME is always set, which may not be true on
+   some systems.
+
+ * Tests with --valgrind failed to find "mergetool" scriptlets.
+
+ * "git patch-id" miscomputed the patch-id in a patch that has a line longer
+   than 1kB.
+
+ * When an "exec" insn failed after modifying the index and/or the working
+   tree during "rebase -i", we now check and warn that the changes need to
+   be cleaned up.
index 6d3bfd19680faaee7272d2451e12cea4e7440cdb..7655cccfaa1585a14257b5a86d663f501c06bf1d 100644 (file)
@@ -6,48 +6,119 @@ Updates since v1.7.6
 
  * The scripting part of the codebase is getting prepared for i18n/l10n.
 
- * Interix and Cygwin ports got updated.
+ * Interix, Cygwin and Minix ports got updated.
+
+ * Various updates to git-p4 (in contrib/), fast-import, and git-svn.
+
+ * Gitweb learned to read from /etc/gitweb-common.conf when it exists,
+   before reading from gitweb_config.perl or from /etc/gitweb.conf
+   (this last one is read only when per-repository gitweb_config.perl
+   does not exist).
 
  * Various codepaths that invoked zlib deflate/inflate assumed that these
    functions can compress or uncompress more than 4GB data in one call on
    platforms with 64-bit long, which has been corrected.
 
+ * Git now recognizes loose objects written by other implementations that
+   use a non-standard window size for zlib deflation (e.g. Agit running on
+   Android with 4kb window). We used to reject anything that was not
+   deflated with 32kb window.
+
+ * Interaction between the use of pager and coloring of the output has
+   been improved, especially when a command that is not built-in was
+   involved.
+
+ * "git am" learned to pass the "--exclude=<path>" option through to underlying
+   "git apply".
+
+ * You can now feed many empty lines before feeding an mbox file to
+   "git am".
+
  * "git archive" can be told to pass the output to gzip compression and
    produce "archive.tar.gz".
 
+ * "git bisect" can be used in a bare repository (provided that the test
+   you perform per each iteration does not need a working tree, of
+   course).
+
+ * The length of abbreviated object names in "git branch -v" output
+   now honors the core.abbrev configuration variable.
+
+ * "git check-attr" can take relative paths from the command line.
+
+ * "git check-attr" learned an "--all" option to list the attributes for a
+   given path.
+
  * "git checkout" (both the code to update the files upon checking out a
-   different branch, the code to checkout specific set of files) learned
+   different branch and the code to checkout a specific set of files) learned
    to stream the data from object store when possible, without having to
-   read the entire contents of a file in memory first.
+   read the entire contents of a file into memory first. An earlier round
+   of this code that is not in any released version had a large leak but
+   now it has been plugged.
 
- * "git clone" can now take "--config key=value" option to set the
+ * "git clone" can now take "--config key=value" option to set the
    repository configuration options that affect the initial checkout.
 
- * "git diff --stat" learned --stat-count option to limit the output of
-   diffstat report.
+ * "git commit <paths>..." now lets you feed relative pathspecs that
+   refer to outside your current subdirectory.
+
+ * "git diff --stat" learned a --stat-count option to limit the output of
+   a diffstat report.
+
+ * "git diff" learned a "--histogram" option to use a different diff
+   generation machinery stolen from jgit, which might give better
+   performance.
+
+ * "git diff" had a weird worst case behaviour that can be triggered
+   when comparing files with potentially many places that could match.
 
  * "git fetch", "git push" and friends no longer show connection
-   errors for addresses that couldn't be connected when at least one
+   errors for addresses that couldn't be connected to when at least one
    address succeeds (this is arguably a regression but a deliberate
    one).
 
- * "git grep" learned --break and --heading options, to let users mimic
-   output format of "ack".
+ * "git grep" learned "--break" and "--heading" options, to let users mimic
+   the output format of "ack".
+
+ * "git grep" learned a "-W" option that shows wider context using the same
+   logic used by "git diff" to determine the hunk header.
+
+ * Invoking the low-level "git http-fetch" without "-a" option (which
+   git itself never did---normal users should not have to worry about
+   this) is now deprecated.
+
+ * The "--decorate" option to "git log" and its family learned to
+   highlight grafted and replaced commits.
 
  * "git rebase master topci" no longer spews usage hints after giving
-   "fatal: no such branch: topci" error message.
+   the "fatal: no such branch: topci" error message.
 
- * "git stash" learned --include-untracked option.
+ * The recursive merge strategy implementation got a fairly large
+   fix for many corner cases that may rarely happen in real world
+   projects (it has been verified that none of the 16000+ merges in
+   the Linux kernel history back to v2.6.12 is affected with the
+   corner case bugs this update fixes).
+
+ * "git stash" learned an "--include-untracked option".
 
  * "git submodule update" used to stop at the first error updating a
    submodule; it now goes on to update other submodules that can be
    updated, and reports the ones with errors at the end.
 
+ * "git push" can be told with the "--recurse-submodules=check" option to
+   refuse pushing of the supermodule, if any of its submodules'
+   commits hasn't been pushed out to their remotes.
+
+ * "git upload-pack" and "git receive-pack" learned to pretend that only a
+   subset of the refs exist in a repository. This may help a site to
+   put many tiny repositories into one repository (this would not be
+   useful for larger repositories as repacking would be problematic).
+
  * "git verify-pack" has been rewritten to use the "index-pack" machinery
    that is more efficient in reading objects in packfiles.
 
  * test scripts for gitweb tried to run even when CGI-related perl modules
-   are not installed; it now exits early when they are unavailable.
+   are not installed; they now exit early when the latter are unavailable.
 
 Also contains various documentation updates and minor miscellaneous
 changes.
@@ -56,43 +127,8 @@ changes.
 Fixes since v1.7.6
 ------------------
 
-Unless otherwise noted, all the fixes in 1.7.6.X maintenance track are
+Unless otherwise noted, all fixes in the 1.7.6.X maintenance track are
 included in this release.
 
- * "git checkout -b <branch>" sometimes wrote a bogus reflog entry,
-   causing later "git checkout -" fail.
-   (merge 71ee7fd jc/checkout-reflog-fix~1 later).
-
- * "git diff --cc" learned to correctly ignore binary files.
-   (merge 0508fe5 jk/combine-diff-binary-etc later)
-
- * "git fetch" did not recurse into submodules in subdirectories.
-   (merge ea2d325 jl/maint-fetch-recursive-fix later)
-
- * "git rebase -i -p" incorrectly dropped commits from side branches.
-   (merge 12bf828 aw/rebase-i-p later)
-
- * "git submodule add" did not allow a relative repository path when
-   the superproject did not have any default remote url.
-   (merge f22a17e8 jl/submodule-add-relurl-wo-upstream later)
-
- * "git submodule foreach" failed to correctly give the standard input to
-   the user-supplied command it invoked.
-   (merge 4dca1aa bc/submodule-foreach-stdin-fix-1.7.4 later)
-
- * submodules that the user has never showed interest in by running
-   "git submodule init" was incorrectly marked as interesting by "git
-   submodule sync".
-   (merge 2cd9de3 jc/submodule-sync-no-auto-vivify later)
-
- * "git tag -l <glob>..." did not take multiple glob patterns from the
-   command line.
-   (merge 588d0e8 jk/tag-list-multiple-patterns later)
-
---
-exec >/var/tmp/1
-echo O=$(git describe master)
-O=v1.7.6-344-g22f4128
-git log --first-parent --oneline $O..master
-echo
-git shortlog --no-merges ^maint ^$O master
+ * "git branch -m" and "git checkout -b" incorrectly allowed the tip
+   of the branch that is currently checked out updated.
index 938eccf2a5ac9dd629be1bc6bb53a59723c99083..0dbf2c9843dd3eed014d788892c8719036287308 100644 (file)
@@ -134,8 +134,7 @@ Another thing: NULL pointers shall be written as NULL, not as 0.
 
 (2) Generate your patch using git tools out of your commits.
 
-git based diff tools (git, Cogito, and StGIT included) generate
-unidiff which is the preferred format.
+git based diff tools generate unidiff which is the preferred format.
 
 You do not have to be afraid to use -M option to "git diff" or
 "git format-patch", if your patch involves file renames.  The
index 0658ffb889320d408f2cad9214e138879059c766..eae75a39c0bcc779ed2c66ef6fa9b03a24a4a2fd 100644 (file)
@@ -147,7 +147,7 @@ advice.*::
 
 core.fileMode::
        If false, the executable bit differences between the index and
-       the working copy are ignored; useful on broken filesystems like FAT.
+       the working tree are ignored; useful on broken filesystems like FAT.
        See linkgit:git-update-index[1].
 +
 The default is true, except linkgit:git-clone[1] or linkgit:git-init[1]
@@ -179,7 +179,7 @@ is created.
 
 core.trustctime::
        If false, the ctime differences between the index and the
-       working copy are ignored; useful when the inode change time
+       working tree are ignored; useful when the inode change time
        is regularly modified by something outside Git (file system
        crawlers and some backup systems).
        See linkgit:git-update-index[1]. True by default.
@@ -292,7 +292,7 @@ core.ignoreStat::
        If true, commands which modify both the working tree and the index
        will mark the updated paths with the "assume unchanged" bit in the
        index. These marked files are then assumed to stay unchanged in the
-       working copy, until you mark them otherwise manually - Git will not
+       working tree, until you mark them otherwise manually - Git will not
        detect the file changes by lstat() calls. This is useful on systems
        where those are very slow, such as Microsoft Windows.
        See linkgit:git-update-index[1].
@@ -1453,7 +1453,8 @@ notes.rewriteRef::
        You may also specify this configuration several times.
 +
 Does not have a default value; you must configure this variable to
-enable note rewriting.
+enable note rewriting.  Set it to `refs/notes/commits` to enable
+rewriting for the default commit notes.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_REF`
 environment variable, which must be a colon separated list of refs or
index b620b3afeca14166840fb76b4cefe1e4038fb47e..5c53bdba948ea817e01e169a9fc183d4fc2d1313 100644 (file)
@@ -45,6 +45,10 @@ ifndef::git-format-patch[]
        Synonym for `-p --raw`.
 endif::git-format-patch[]
 
+--minimal::
+       Spend extra time to make sure the smallest possible
+       diff is produced.
+
 --patience::
        Generate a diff using the "patience diff" algorithm.
 
index 6b1b5af64e2daec1ecc8ee832f58f5186d740a79..887466d7777bb3cedce976b55d446f0f7803c423 100644 (file)
@@ -13,7 +13,8 @@ SYNOPSIS
         [--3way] [--interactive] [--committer-date-is-author-date]
         [--ignore-date] [--ignore-space-change | --ignore-whitespace]
         [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
-        [--reject] [-q | --quiet] [--scissors | --no-scissors]
+        [--exclude=<path>] [--reject] [-q | --quiet]
+        [--scissors | --no-scissors]
         [(<mbox> | <Maildir>)...]
 'git am' (--continue | --skip | --abort)
 
@@ -87,6 +88,7 @@ default.   You can use `--no-utf8` to override this.
 -C<n>::
 -p<n>::
 --directory=<dir>::
+--exclude=<path>::
 --reject::
        These flags are passed to the 'git apply' (see linkgit:git-apply[1])
        program that applies
index 1320c873ad61281ef33891170da8683dc785f011..ac7006e6400d85c31bf31a3022a38225373fe3f7 100644 (file)
@@ -142,41 +142,41 @@ while archiving any tree in your `$GIT_DIR/info/attributes` file.
 
 EXAMPLES
 --------
-git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)::
+`git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)`::
 
        Create a tar archive that contains the contents of the
        latest commit on the current branch, and extract it in the
        `/var/tmp/junk` directory.
 
-git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz::
+`git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz`::
 
        Create a compressed tarball for v1.4.0 release.
 
-git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git-1.4.0.tar.gz::
+`git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git-1.4.0.tar.gz`::
 
        Same as above, but using the builtin tar.gz handling.
 
-git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0::
+`git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0`::
 
        Same as above, but the format is inferred from the output file.
 
-git archive --format=tar --prefix=git-1.4.0/ v1.4.0{caret}\{tree\} | gzip >git-1.4.0.tar.gz::
+`git archive --format=tar --prefix=git-1.4.0/ v1.4.0{caret}\{tree\} | gzip >git-1.4.0.tar.gz`::
 
        Create a compressed tarball for v1.4.0 release, but without a
        global extended pax header.
 
-git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip::
+`git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip`::
 
        Put everything in the current head's Documentation/ directory
        into 'git-1.4.0-docs.zip', with the prefix 'git-docs/'.
 
-git archive -o latest.zip HEAD::
+`git archive -o latest.zip HEAD`::
 
        Create a Zip archive that contains the contents of the latest
        commit on the current branch. Note that the output format is
        inferred by the extension of the output file.
 
-git config tar.tar.xz.command "xz -c"::
+`git config tar.tar.xz.command "xz -c"`::
 
        Configure a "tar.xz" format for making LZMA-compressed tarfiles.
        You can use it specifying `--format=tar.xz`, or by creating an
index c50f1898272f6b2a9a1c1cd236d3b27621d4fdb9..507b8d0ab2a2d524a607c5b91e6d17f6d2f36392 100644 (file)
@@ -113,7 +113,8 @@ OPTIONS
 
 --abbrev=<length>::
        Alter the sha1's minimum display length in the output listing.
-       The default value is 7.
+       The default value is 7 and can be overridden by the `core.abbrev`
+       config option.
 
 --no-abbrev::
        Display the full sha1s in the output listing rather than abbreviating them.
index 30eca6cee62ad7b9ccfc9d71209a17287c65d48c..1f7312a1895ae66901e5472132406d01303da1f8 100644 (file)
@@ -9,8 +9,8 @@ git-check-attr - Display gitattributes information
 SYNOPSIS
 --------
 [verse]
-'git check-attr' attr... [--] pathname...
-'git check-attr' --stdin [-z] attr... < <list-of-paths>
+'git check-attr' [-a | --all | attr...] [--] pathname...
+'git check-attr' --stdin [-z] [-a | --all | attr...] < <list-of-paths>
 
 DESCRIPTION
 -----------
@@ -19,6 +19,11 @@ For every pathname, this command will list if each attribute is 'unspecified',
 
 OPTIONS
 -------
+-a, --all::
+       List all attributes that are associated with the specified
+       paths.  If this option is used, then 'unspecified' attributes
+       will not be included in the output.
+
 --stdin::
        Read file names from stdin instead of from the command-line.
 
@@ -28,8 +33,11 @@ OPTIONS
 
 \--::
        Interpret all preceding arguments as attributes and all following
-       arguments as path names. If not supplied, only the first argument will
-       be treated as an attribute.
+       arguments as path names.
+
+If none of `--stdin`, `--all`, or `--` is used, the first argument
+will be treated as an attribute and the rest of the arguments as
+pathnames.
 
 OUTPUT
 ------
@@ -69,6 +77,13 @@ org/example/MyClass.java: diff: java
 org/example/MyClass.java: myAttr: set
 ---------------
 
+* Listing all attributes for a file:
+---------------
+$ git check-attr --all -- org/example/MyClass.java
+org/example/MyClass.java: diff: java
+org/example/MyClass.java: myAttr: set
+---------------
+
 * Listing an attribute for multiple files:
 ---------------
 $ git check-attr myAttr -- org/example/MyClass.java org/example/NoMyAttr.java
index 6c9c2cb3831698bb2d262344ab76baa601e8dde2..7cfa3d92ac8dc7a90068311c0047c667f98515a8 100644 (file)
@@ -112,31 +112,31 @@ effect to your index in a row.
 
 EXAMPLES
 --------
-git cherry-pick master::
+`git cherry-pick master`::
 
        Apply the change introduced by the commit at the tip of the
        master branch and create a new commit with this change.
 
-git cherry-pick ..master::
-git cherry-pick ^HEAD master::
+`git cherry-pick ..master`::
+`git cherry-pick ^HEAD master`::
 
        Apply the changes introduced by all commits that are ancestors
        of master but not of HEAD to produce new commits.
 
-git cherry-pick master{tilde}4 master{tilde}2::
+`git cherry-pick master{tilde}4 master{tilde}2`::
 
        Apply the changes introduced by the fifth and third last
        commits pointed to by master and create 2 new commits with
        these changes.
 
-git cherry-pick -n master~1 next::
+`git cherry-pick -n master~1 next`::
 
        Apply to the working tree and the index the changes introduced
        by the second last commit pointed to by master and by the last
        commit pointed to by next, but do not create any commit with
        these changes.
 
-git cherry-pick --ff ..next::
+`git cherry-pick --ff ..next`::
 
        If history is linear and HEAD is an ancestor of next, update
        the working tree and advance the HEAD pointer to match next.
@@ -144,7 +144,7 @@ git cherry-pick --ff ..next::
        are in next but not HEAD to the current branch, creating a new
        commit for each new change.
 
-git rev-list --reverse master \-- README | git cherry-pick -n --stdin::
+`git rev-list --reverse master \-- README | git cherry-pick -n --stdin`::
 
        Apply the changes introduced by all commits on the master
        branch that touched README to the working tree and index,
index 974e04ef1abaf4a3018b83b0323a46cbaa5339d4..79fb9841441d02cd635dcdd2aecef42d38c6b59d 100644 (file)
@@ -47,12 +47,14 @@ OPTIONS
 
 -e <pattern>::
 --exclude=<pattern>::
-       Specify special exceptions to not be cleaned.  Each <pattern> is
-       the same form as in $GIT_DIR/info/excludes and this option can be
-       given multiple times.
+       In addition to those found in .gitignore (per directory) and
+       $GIT_DIR/info/exclude, also consider these patterns to be in the
+       set of the ignore rules in effect.
 
 -x::
-       Don't use the ignore rules.  This allows removing all untracked
+       Don't use the standard ignore rules read from .gitignore (per
+       directory) and $GIT_DIR/info/exclude, but do still use the ignore
+       rules given with `-e` options.  This allows removing all untracked
        files, including build products.  This can be used (possibly in
        conjunction with 'git reset') to create a pristine
        working directory to test a clean build.
index ebd13be72e58cf0d0a66ddd0105117747ac900be..69a1e4af9ec007a6cc59cce07298a6a825369ef1 100644 (file)
@@ -93,14 +93,14 @@ OPTIONS
        Listen on an alternative port.  Incompatible with '--inetd' option.
 
 --init-timeout=<n>::
-       Timeout between the moment the connection is established and the
-       client request is received (typically a rather low value, since
+       Timeout (in seconds) between the moment the connection is established
+       and the client request is received (typically a rather low value, since
        that should be basically immediate).
 
 --timeout=<n>::
-       Timeout for specific client sub-requests. This includes the time
-       it takes for the server to process the sub-request and the time spent
-       waiting for the next client's request.
+       Timeout (in seconds) for specific client sub-requests. This includes
+       the time it takes for the server to process the sub-request and the
+       time spent waiting for the next client's request.
 
 --max-connections=<n>::
        Maximum number of concurrent clients, defaults to 32.  Set it to
index a29ac021d9c7ff62e3a761ffa23b7808420b5faa..f37eada63a449995861f41e5020c04f26d40c6f2 100644 (file)
@@ -83,6 +83,10 @@ marks the same across runs.
        allow that.  So fake a tagger to be able to fast-import the
        output.
 
+--use-done-feature::
+       Start the stream with a 'feature done' stanza, and terminate
+       it with a 'done' command.
+
 --no-data::
        Skip output of blob objects and instead refer to blobs via
        their original SHA-1 hash.  This is useful when rewriting the
index 95e480ef7968af9d3bb055e8fd9750b08d620622..ec6ef3119792a9e66a3a46bf6f0754458ea6a061 100644 (file)
@@ -102,6 +102,12 @@ OPTIONS
        when the `cat-blob` command is encountered in the stream.
        The default behaviour is to write to `stdout`.
 
+--done::
+       Require a `done` command at the end of the stream.
+       This option might be useful for detecting errors that
+       cause the frontend to terminate before it has started to
+       write a stream.
+
 --export-pack-edges=<file>::
        After creating a packfile, print a line of data to
        <file> listing the filename of the packfile and the last
@@ -331,6 +337,11 @@ and control the current import process.  More detailed discussion
        standard output.  This command is optional and is not needed
        to perform an import.
 
+`done`::
+       Marks the end of the stream. This command is optional
+       unless the `done` feature was requested using the
+       `--done` command line option or `feature done` command.
+
 `cat-blob`::
        Causes fast-import to print a blob in 'cat-file --batch'
        format to the file descriptor set with `--cat-blob-fd` or
@@ -414,8 +425,8 @@ Here `<name>` is the person's display name (for example
 (``cm@example.com'').  `LT` and `GT` are the literal less-than (\x3c)
 and greater-than (\x3e) symbols.  These are required to delimit
 the email address from the other fields in the line.  Note that
-`<name>` is free-form and may contain any sequence of bytes, except
-`LT` and `LF`.  It is typically UTF-8 encoded.
+`<name>` and `<email>` are free-form and may contain any sequence
+of bytes, except `LT`, `GT` and `LF`.  `<name>` is typically UTF-8 encoded.
 
 The time of the change is specified by `<when>` using the date format
 that was selected by the \--date-format=<fmt> command line option.
@@ -1001,10 +1012,14 @@ force::
        (see OPTIONS, above).
 
 import-marks::
+import-marks-if-exists::
        Like --import-marks except in two respects: first, only one
-       "feature import-marks" command is allowed per stream;
-       second, an --import-marks= command-line option overrides
-       any "feature import-marks" command in the stream.
+       "feature import-marks" or "feature import-marks-if-exists"
+       command is allowed per stream; second, an --import-marks=
+       or --import-marks-if-exists command-line option overrides
+       any of these "feature" commands in the stream; third,
+       "feature import-marks-if-exists" like a corresponding
+       command-line option silently skips a nonexistent file.
 
 cat-blob::
 ls::
@@ -1021,6 +1036,11 @@ notes::
        Versions of fast-import not supporting notes will exit
        with a message indicating so.
 
+done::
+       Error out if the stream ends without a 'done' command.
+       Without this feature, errors causing the frontend to end
+       abruptly at a convenient point in the stream can go
+       undetected.
 
 `option`
 ~~~~~~~~
@@ -1050,6 +1070,15 @@ not be passed as option:
 * cat-blob-fd
 * force
 
+`done`
+~~~~~~
+If the `done` feature is not in use, treated as if EOF was read.
+This can be used to tell fast-import to finish early.
+
+If the `--done` command line option or `feature done` command is
+in use, the `done` command is mandatory and marks the end of the
+stream.
+
 Crash Reports
 -------------
 If fast-import is supplied invalid input it will terminate with a
index d13c9b23f7bce6379f638e5bf86b30c95abef30e..6ea9be775c09111c14668e0de390a04a301f3235 100644 (file)
@@ -166,15 +166,22 @@ will want to ensure that threading is disabled for `git send-email`.
 --to=<email>::
        Add a `To:` header to the email headers. This is in addition
        to any configured headers, and may be used multiple times.
+       The negated form `--no-to` discards all `To:` headers added so
+       far (from config or command line).
 
 --cc=<email>::
        Add a `Cc:` header to the email headers. This is in addition
        to any configured headers, and may be used multiple times.
+       The negated form `--no-cc` discards all `Cc:` headers added so
+       far (from config or command line).
 
 --add-header=<header>::
        Add an arbitrary header to the email headers.  This is in addition
        to any configured headers, and may be used multiple times.
-       For example, `--add-header="Organization: git-foo"`
+       For example, `--add-header="Organization: git-foo"`.
+       The negated form `--no-add-header` discards *all* (`To:`,
+       `Cc:`, and custom) headers added so far from config or command
+       line.
 
 --cover-letter::
        In addition to the patches, generate a cover letter file
index 07b3c6a0866c5b4ff0b4653b462b332ea0d348c9..e44a4988b7a7ed7100da6e2ba098d7fda17a2f83 100644 (file)
@@ -155,15 +155,6 @@ OPTIONS
        Show the filename above the matches in that file instead of
        at the start of each shown line.
 
--[ABC] <context>::
-       Show `context` trailing (`A` -- after), or leading (`B`
-       -- before), or both (`C` -- context) lines, and place a
-       line containing `--` between contiguous groups of
-       matches.
-
--<num>::
-       A shortcut for specifying `-C<num>`.
-
 -p::
 --show-function::
        Show the preceding line that contains the function name of
@@ -172,6 +163,29 @@ OPTIONS
        patch hunk headers (see 'Defining a custom hunk-header' in
        linkgit:gitattributes[5]).
 
+-<num>::
+-C <num>::
+--context <num>::
+       Show <num> leading and trailing lines, and place a line
+       containing `--` between contiguous groups of matches.
+
+-A <num>::
+--after-context <num>::
+       Show <num> trailing lines, and place a line containing
+       `--` between contiguous groups of matches.
+
+-B <num>::
+--before-context <num>::
+       Show <num> leading lines, and place a line containing
+       `--` between contiguous groups of matches.
+
+-W::
+--function-context::
+       Show the surrounding text from the previous line containing a
+       function name up to the one before the next function name,
+       effectively showing the whole function in which the match was
+       found.
+
 -f <file>::
        Read patterns from <file>, one per line.
 
@@ -215,15 +229,15 @@ OPTIONS
 Examples
 --------
 
-git grep {apostrophe}time_t{apostrophe} \-- {apostrophe}*.[ch]{apostrophe}::
+`git grep {apostrophe}time_t{apostrophe} \-- {apostrophe}*.[ch]{apostrophe}`::
        Looks for `time_t` in all tracked .c and .h files in the working
        directory and its subdirectories.
 
-git grep -e {apostrophe}#define{apostrophe} --and \( -e MAX_PATH -e PATH_MAX \)::
+`git grep -e {apostrophe}#define{apostrophe} --and \( -e MAX_PATH -e PATH_MAX \)`::
        Looks for a line that has `#define` and either `MAX_PATH` or
        `PATH_MAX`.
 
-git grep --all-match -e NODE -e Unexpected::
+`git grep --all-match -e NODE -e Unexpected`::
        Looks for a line that has `NODE` or `Unexpected` in
        files that have lines that match both.
 
index 18f713b67a629ecbfd54e6aab1ef4fde89745d2f..0041994443c42033ee7c378ffad8983b0163489e 100644 (file)
@@ -50,7 +50,7 @@ version::
 
 Examples
 --------
-git gui blame Makefile::
+`git gui blame Makefile`::
 
        Show the contents of the file 'Makefile' in the current
        working directory, and provide annotations for both the
@@ -59,41 +59,41 @@ git gui blame Makefile::
        uncommitted changes (if any) are explicitly attributed to
        'Not Yet Committed'.
 
-git gui blame v0.99.8 Makefile::
+`git gui blame v0.99.8 Makefile`::
 
        Show the contents of 'Makefile' in revision 'v0.99.8'
        and provide annotations for each line.  Unlike the above
        example the file is read from the object database and not
        the working directory.
 
-git gui blame --line=100 Makefile::
+`git gui blame --line=100 Makefile`::
 
        Loads annotations as described above and automatically
        scrolls the view to center on line '100'.
 
-git gui citool::
+`git gui citool`::
 
        Make one commit and return to the shell when it is complete.
        This command returns a non-zero exit code if the window was
        closed in any way other than by making a commit.
 
-git gui citool --amend::
+`git gui citool --amend`::
 
        Automatically enter the 'Amend Last Commit' mode of
        the interface.
 
-git gui citool --nocommit::
+`git gui citool --nocommit`::
 
        Behave as normal citool, but instead of making a commit
        simply terminate with a zero exit code. It still checks
        that the index does not contain any unmerged entries, so
        you can use it as a GUI version of linkgit:git-mergetool[1]
 
-git citool::
+`git citool`::
 
        Same as `git gui citool` (above).
 
-git gui browser maint::
+`git gui browser maint`::
 
        Show a browser for the tree of the 'maint' branch.  Files
        selected in the browser can be viewed with the internal
index 277d9e141bf81bddb4ba661e43763b7774a1417d..f4e0741c115905f61a0e92c5255658f4b8e25711 100644 (file)
@@ -119,6 +119,14 @@ ScriptAliasMatch \
 
 ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/
 ----------------------------------------------------------------
++
+To serve multiple repositories from different linkgit:gitnamespaces[7] in a
+single repository:
++
+----------------------------------------------------------------
+SetEnvIf Request_URI "^/git/([^/]*)" GIT_NAMESPACE=$1
+ScriptAliasMatch ^/git/[^/]*(.*) /usr/libexec/git-core/git-http-backend/storage.git$1
+----------------------------------------------------------------
 
 Accelerated static Apache 2.x::
        Similar to the above, but Apache can be used to return static
index 4d42073867b09317dc674b0c0f5f1b76d4129a03..070cd1e6ed93b064bdd1fdfc1767a3f9a999d321 100644 (file)
@@ -15,6 +15,9 @@ DESCRIPTION
 -----------
 Downloads a remote git repository via HTTP.
 
+*NOTE*: use of this command without -a is deprecated.  The -a
+behaviour will become the default in a future release.
+
 OPTIONS
 -------
 commit-id::
index 59f8be0be372acc26c98d162437702d19fd8ed36..249fc878ec2058f9fcfc6655ecaeb299ba5622a7 100644 (file)
@@ -69,10 +69,13 @@ produced by --stat etc.
        its size is not included.
 
 [\--] <path>...::
-       Show only commits that affect any of the specified paths. To
-       prevent confusion with options and branch names, paths may need
-       to be prefixed with "\-- " to separate them from options or
-       refnames.
+       Show only commits that are enough to explain how the files
+       that match the specified paths came to be.  See "History
+       Simplification" below for details and other simplification
+       modes.
++
+To prevent confusion with options and branch names, paths may need to
+be prefixed with "\-- " to separate them from options or refnames.
 
 include::rev-list-options.txt[]
 
@@ -88,45 +91,45 @@ include::diff-generate-patch.txt[]
 
 Examples
 --------
-git log --no-merges::
+`git log --no-merges`::
 
        Show the whole commit history, but skip any merges
 
-git log v2.6.12.. include/scsi drivers/scsi::
+`git log v2.6.12.. include/scsi drivers/scsi`::
 
        Show all commits since version 'v2.6.12' that changed any file
        in the include/scsi or drivers/scsi subdirectories
 
-git log --since="2 weeks ago" \-- gitk::
+`git log --since="2 weeks ago" \-- gitk`::
 
        Show the changes during the last two weeks to the file 'gitk'.
        The "--" is necessary to avoid confusion with the *branch* named
        'gitk'
 
-git log --name-status release..test::
+`git log --name-status release..test`::
 
        Show the commits that are in the "test" branch but not yet
        in the "release" branch, along with the list of paths
        each commit modifies.
 
-git log --follow builtin-rev-list.c::
+`git log --follow builtin-rev-list.c`::
 
        Shows the commits that changed builtin-rev-list.c, including
        those commits that occurred before the file was given its
        present name.
 
-git log --branches --not --remotes=origin::
+`git log --branches --not --remotes=origin`::
 
        Shows all commits that are in any of local branches but not in
        any of remote-tracking branches for 'origin' (what you have that
        origin doesn't).
 
-git log master --not --remotes=*/master::
+`git log master --not --remotes=*/master`::
 
        Shows all commits that are in local master but not in any remote
        repository master branches.
 
-git log -p -m --first-parent::
+`git log -p -m --first-parent`::
 
        Shows the history including change diffs, but only from the
        "main branch" perspective, skipping commits that come from merged
index 635c66956e90452c58938f2d48e84454983f22e6..d7db2a3737fbdb032747bc6dd2740be1a56dfced 100644 (file)
@@ -76,12 +76,12 @@ OPTIONS
 EXAMPLES
 --------
 
-git merge-file README.my README README.upstream::
+`git merge-file README.my README README.upstream`::
 
        combines the changes of README.my and README.upstream since README,
        tries to merge them and writes the result into README.my.
 
-git merge-file -L a -L b -L c tmp/a123 tmp/b234 tmp/c345::
+`git merge-file -L a -L b -L c tmp/a123 tmp/b234 tmp/c345`::
 
        merges tmp/a123 and tmp/c345 with the base tmp/b234, but uses labels
        `a` and `c` instead of `tmp/a123` and `tmp/c345`.
index 347091010995af95e43ced744b159b277bdb6cdc..2a49de7cfe5188b531bc02f1115e253bfa10e0e0 100644 (file)
@@ -17,9 +17,10 @@ Use `git mergetool` to run one of several merge utilities to resolve
 merge conflicts.  It is typically run after 'git merge'.
 
 If one or more <file> parameters are given, the merge tool program will
-be run to resolve differences on each file.  If no <file> names are
-specified, 'git mergetool' will run the merge tool program on every file
-with merge conflicts.
+be run to resolve differences on each file (skipping those without
+conflicts).  Specifying a directory will include all unresolved files in
+that path.  If no <file> names are specified, 'git mergetool' will run
+the merge tool program on every file with merge conflicts.
 
 OPTIONS
 -------
index 6a187f2e2336575fb4974b8c492359913a8c7a9e..e8319eac6928300d1eb12070874e705b9be060b6 100644 (file)
@@ -142,8 +142,9 @@ OPTIONS
 
 -C <object>::
 --reuse-message=<object>::
-       Take the note message from the given blob object (for
-       example, another note).
+       Take the given blob object (for example, another note) as the
+       note message. (Use `git notes copy <object>` instead to
+       copy notes between objects.)
 
 -c <object>::
 --reedit-message=<object>::
@@ -285,6 +286,8 @@ $ blob=$(git hash-object -w a.out)
 $ git notes --ref=built add -C "$blob" HEAD
 ------------
 
+(You cannot simply use `git notes --ref=built add -F a.out HEAD`
+because that is not binary-safe.)
 Of course, it doesn't make much sense to display non-text-format notes
 with 'git log', so if you use such notes, you'll probably need to write
 some special-purpose tools to do something useful with them.
index 88acfcd4cc8e0eeafc809df0d72b37daded6f8a6..aede48877fb080bd12c346c74cf7453860d7de21 100644 (file)
@@ -162,6 +162,12 @@ useful if you write an alias or script around 'git push'.
        is specified. This flag forces progress status even if the
        standard error stream is not directed to a terminal.
 
+--recurse-submodules=check::
+       Check whether all submodule commits used by the revisions to be
+       pushed are available on a remote tracking branch. Otherwise the
+       push will be aborted and the command will exit with non-zero status.
+
+
 include::urls-remotes.txt[]
 
 OUTPUT
@@ -327,12 +333,12 @@ a case where you do mean to lose history.
 Examples
 --------
 
-git push::
+`git push`::
        Works like `git push <remote>`, where <remote> is the
        current branch's remote (or `origin`, if no remote is
        configured for the current branch).
 
-git push origin::
+`git push origin`::
        Without additional configuration, works like
        `git push origin :`.
 +
@@ -344,45 +350,45 @@ use `git config remote.origin.push HEAD`.  Any valid <refspec> (like
 the ones in the examples below) can be configured as the default for
 `git push origin`.
 
-git push origin :::
+`git push origin :`::
        Push "matching" branches to `origin`. See
        <refspec> in the <<OPTIONS,OPTIONS>> section above for a
        description of "matching" branches.
 
-git push origin master::
+`git push origin master`::
        Find a ref that matches `master` in the source repository
        (most likely, it would find `refs/heads/master`), and update
        the same ref (e.g. `refs/heads/master`) in `origin` repository
        with it.  If `master` did not exist remotely, it would be
        created.
 
-git push origin HEAD::
+`git push origin HEAD`::
        A handy way to push the current branch to the same name on the
        remote.
 
-git push origin master:satellite/master dev:satellite/dev::
+`git push origin master:satellite/master dev:satellite/dev`::
        Use the source ref that matches `master` (e.g. `refs/heads/master`)
        to update the ref that matches `satellite/master` (most probably
        `refs/remotes/satellite/master`) in the `origin` repository, then
        do the same for `dev` and `satellite/dev`.
 
-git push origin HEAD:master::
+`git push origin HEAD:master`::
        Push the current branch to the remote ref matching `master` in the
        `origin` repository. This form is convenient to push the current
        branch without thinking about its local name.
 
-git push origin master:refs/heads/experimental::
+`git push origin master:refs/heads/experimental`::
        Create the branch `experimental` in the `origin` repository
        by copying the current `master` branch.  This form is only
        needed to create a new branch or tag in the remote repository when
        the local name and the remote name are different; otherwise,
        the ref name on its own will work.
 
-git push origin :experimental::
+`git push origin :experimental`::
        Find a ref that matches `experimental` in the `origin` repository
        (e.g. `refs/heads/experimental`), and delete it.
 
-git push origin {plus}dev:master::
+`git push origin {plus}dev:master`::
        Update the origin repository's master branch with the dev branch,
        allowing non-fast-forward updates.  *This can leave unreferenced
        commits dangling in the origin repository.*  Consider the
index c45d53c6e150479bd01bf3d643354348d8ce9273..5375549820bd6b9fecf3540b1e60ae50e74da0e6 100644 (file)
@@ -47,7 +47,7 @@ OPTIONS
 
 -i::
        Usually a merge requires the index file as well as the
-       files in the working tree are up to date with the
+       files in the working tree to be up to date with the
        current head commit, in order not to lose local
        changes.  This flag disables the check with the working
        tree and is meant to be used when creating a merge of
@@ -71,21 +71,21 @@ OPTIONS
 --aggressive::
        Usually a three-way merge by 'git read-tree' resolves
        the merge for really trivial cases and leaves other
-       cases unresolved in the index, so that Porcelains can
+       cases unresolved in the index, so that porcelains can
        implement different merge policies.  This flag makes the
-       command to resolve a few more cases internally:
+       command resolve a few more cases internally:
 +
 * when one side removes a path and the other side leaves the path
   unmodified.  The resolution is to remove that path.
 * when both sides remove a path.  The resolution is to remove that path.
-* when both sides adds a path identically.  The resolution
+* when both sides add a path identically.  The resolution
   is to add that path.
 
 --prefix=<prefix>/::
        Keep the current index contents, and read the contents
-       of named tree-ish under directory at `<prefix>`.  The
+       of the named tree-ish under the directory at `<prefix>`. The
        original index file cannot have anything at the path
-       `<prefix>` itself, and have nothing in `<prefix>/`
+       `<prefix>` itself, nor anything in the `<prefix>/`
        directory.  Note that the `<prefix>/` value must end
        with a slash.
 
@@ -379,45 +379,45 @@ have finished your work-in-progress), attempt the merge again.
 Sparse checkout
 ---------------
 
-"Sparse checkout" allows to sparsely populate working directory.
-It uses skip-worktree bit (see linkgit:git-update-index[1]) to tell
-Git whether a file on working directory is worth looking at.
+"Sparse checkout" allows populating the working directory sparsely.
+It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
+Git whether a file in the working directory is worth looking at.
 
-"git read-tree" and other merge-based commands ("git merge", "git
-checkout"...) can help maintaining skip-worktree bitmap and working
+'git read-tree' and other merge-based commands ('git merge', 'git
+checkout'...) can help maintaining the skip-worktree bitmap and working
 directory update. `$GIT_DIR/info/sparse-checkout` is used to
-define the skip-worktree reference bitmap. When "git read-tree" needs
-to update working directory, it will reset skip-worktree bit in index
+define the skip-worktree reference bitmap. When 'git read-tree' needs
+to update the working directory, it resets the skip-worktree bit in the index
 based on this file, which uses the same syntax as .gitignore files.
-If an entry matches a pattern in this file, skip-worktree will be
-set on that entry. Otherwise, skip-worktree will be unset.
+If an entry matches a pattern in this file, skip-worktree will not be
+set on that entry. Otherwise, skip-worktree will be set.
 
 Then it compares the new skip-worktree value with the previous one. If
-skip-worktree turns from unset to set, it will add the corresponding
-file back. If it turns from set to unset, that file will be removed.
+skip-worktree turns from set to unset, it will add the corresponding
+file back. If it turns from unset to set, that file will be removed.
 
 While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
-files are in. You can also specify what files are _not_ in, using
-negate patterns. For example, to remove file "unwanted":
+files are in, you can also specify what files are _not_ in, using
+negate patterns. For example, to remove the file `unwanted`:
 
 ----------------
-*
+/*
 !unwanted
 ----------------
 
-Another tricky thing is fully repopulating working directory when you
+Another tricky thing is fully repopulating the working directory when you
 no longer want sparse checkout. You cannot just disable "sparse
-checkout" because skip-worktree are still in the index and you working
-directory is still sparsely populated. You should re-populate working
+checkout" because skip-worktree bits are still in the index and your working
+directory is still sparsely populated. You should re-populate the working
 directory with the `$GIT_DIR/info/sparse-checkout` file content as
 follows:
 
 ----------------
-*
+/*
 ----------------
 
-Then you can disable sparse checkout. Sparse checkout support in "git
-read-tree" and similar commands is disabled by default. You need to
+Then you can disable sparse checkout. Sparse checkout support in 'git
+read-tree' and similar commands is disabled by default. You need to
 turn `core.sparseCheckout` on in order to have sparse checkout
 support.
 
index 459c08598f31fccf1b5db31f2f1cd9680654b389..b1f7dc643a0e9b6b232e1c75b39d7f784ab21b4a 100644 (file)
@@ -150,7 +150,7 @@ if the repository is packed and is served via a dumb transport.
 
 SEE ALSO
 --------
-linkgit:git-send-pack[1]
+linkgit:git-send-pack[1], linkgit:gitnamespaces[7]
 
 GIT
 ---
index 4aecd4d1878e0af6c3e6c87a63df1375606ff65a..f095d57d09f215e48e1f832ca0698e5666119f2b 100644 (file)
@@ -35,19 +35,19 @@ GIT_TRANSLOOP_DEBUG::
 
 EXAMPLES
 --------
-git fetch fd::17 master::
+`git fetch fd::17 master`::
        Fetch master, using file descriptor #17 to communicate with
        git-upload-pack.
 
-git fetch fd::17/foo master::
+`git fetch fd::17/foo master`::
        Same as above.
 
-git push fd::7,8 master (as URL)::
+`git push fd::7,8 master (as URL)`::
        Push master, using file descriptor #7 to read data from
        git-receive-pack and file descriptor #8 to write data to
        same service.
 
-git push fd::7,8/bar master::
+`git push fd::7,8/bar master`::
        Same as above.
 
 Documentation
index 930b4034ac5dc60481afe34f9cd82fd756639190..674797cd8308801dc3e3b4f3d6f581005a0a0d2a 100644 (file)
@@ -24,22 +24,141 @@ output. Because a remote helper runs as an independent process from
 git, there is no need to re-link git to add a new helper, nor any
 need to link the helper with the implementation of git.
 
-Every helper must support the "capabilities" command, which git will
-use to determine what other commands the helper will accept.  Other
-commands generally concern facilities like discovering and updating
-remote refs, transporting objects between the object database and
-the remote repository, and updating the local object store.
-
-Helpers supporting the 'fetch' capability can discover refs from the
-remote repository and transfer objects reachable from those refs to
-the local object store. Helpers supporting the 'push' capability can
-transfer local objects to the remote repository and update remote refs.
+Every helper must support the "capabilities" command, which git
+uses to determine what other commands the helper will accept.  Those
+other commands can be used to discover and update remote refs,
+transport objects between the object database and the remote repository,
+and update the local object store.
 
 Git comes with a "curl" family of remote helpers, that handle various
 transport protocols, such as 'git-remote-http', 'git-remote-https',
 'git-remote-ftp' and 'git-remote-ftps'. They implement the capabilities
 'fetch', 'option', and 'push'.
 
+INPUT FORMAT
+------------
+
+Git sends the remote helper a list of commands on standard input, one
+per line.  The first command is always the 'capabilities' command, in
+response to which the remote helper must print a list of the
+capabilities it supports (see below) followed by a blank line.  The
+response to the capabilities command determines what commands Git uses
+in the remainder of the command stream.
+
+The command stream is terminated by a blank line.  In some cases
+(indicated in the documentation of the relevant commands), this blank
+line is followed by a payload in some other protocol (e.g., the pack
+protocol), while in others it indicates the end of input.
+
+Capabilities
+~~~~~~~~~~~~
+
+Each remote helper is expected to support only a subset of commands.
+The operations a helper supports are declared to git in the response
+to the `capabilities` command (see COMMANDS, below).
+
+'option'::
+       For specifying settings like `verbosity` (how much output to
+       write to stderr) and `depth` (how much history is wanted in the
+       case of a shallow clone) that affect how other commands are
+       carried out.
+
+'connect'::
+       For fetching and pushing using git's native packfile protocol
+       that requires a bidirectional, full-duplex connection.
+
+'push'::
+       For listing remote refs and pushing specified objects from the
+       local object store to remote refs.
+
+'fetch'::
+       For listing remote refs and fetching the associated history to
+       the local object store.
+
+'import'::
+       For listing remote refs and fetching the associated history as
+       a fast-import stream.
+
+'refspec' <refspec>::
+       This modifies the 'import' capability, allowing the produced
+       fast-import stream to modify refs in a private namespace
+       instead of writing to refs/heads or refs/remotes directly.
+       It is recommended that all importers providing the 'import'
+       capability use this.
++
+A helper advertising the capability
+`refspec refs/heads/{asterisk}:refs/svn/origin/branches/{asterisk}`
+is saying that, when it is asked to `import refs/heads/topic`, the
+stream it outputs will update the `refs/svn/origin/branches/topic`
+ref.
++
+This capability can be advertised multiple times.  The first
+applicable refspec takes precedence.  The left-hand of refspecs
+advertised with this capability must cover all refs reported by
+the list command.  If no 'refspec' capability is advertised,
+there is an implied `refspec {asterisk}:{asterisk}`.
+
+Capabilities for Pushing
+~~~~~~~~~~~~~~~~~~~~~~~~
+'connect'::
+       Can attempt to connect to 'git receive-pack' (for pushing),
+       'git upload-pack', etc for communication using the
+       packfile protocol.
++
+Supported commands: 'connect'.
+
+'push'::
+       Can discover remote refs and push local commits and the
+       history leading up to them to new or existing remote refs.
++
+Supported commands: 'list for-push', 'push'.
+
+If a helper advertises both 'connect' and 'push', git will use
+'connect' if possible and fall back to 'push' if the helper requests
+so when connecting (see the 'connect' command under COMMANDS).
+
+Capabilities for Fetching
+~~~~~~~~~~~~~~~~~~~~~~~~~
+'connect'::
+       Can try to connect to 'git upload-pack' (for fetching),
+       'git receive-pack', etc for communication using the
+       packfile protocol.
++
+Supported commands: 'connect'.
+
+'fetch'::
+       Can discover remote refs and transfer objects reachable from
+       them to the local object store.
++
+Supported commands: 'list', 'fetch'.
+
+'import'::
+       Can discover remote refs and output objects reachable from
+       them as a stream in fast-import format.
++
+Supported commands: 'list', 'import'.
+
+If a helper advertises 'connect', git will use it if possible and
+fall back to another capability if the helper requests so when
+connecting (see the 'connect' command under COMMANDS).
+When choosing between 'fetch' and 'import', git prefers 'fetch'.
+Other frontends may have some other order of preference.
+
+'refspec' <refspec>::
+       This modifies the 'import' capability.
++
+A helper advertising
+`refspec refs/heads/{asterisk}:refs/svn/origin/branches/{asterisk}`
+in its capabilities is saying that, when it handles
+`import refs/heads/topic`, the stream it outputs will update the
+`refs/svn/origin/branches/topic` ref.
++
+This capability can be advertised multiple times.  The first
+applicable refspec takes precedence.  The left-hand of refspecs
+advertised with this capability must cover all refs reported by
+the list command.  If no 'refspec' capability is advertised,
+there is an implied `refspec {asterisk}:{asterisk}`.
+
 INVOCATION
 ----------
 
@@ -48,6 +167,9 @@ arguments. The first argument specifies a remote repository as in git;
 it is either the name of a configured remote or a URL. The second
 argument specifies a URL; it is usually of the form
 '<transport>://<address>', but any arbitrary string is possible.
+The 'GIT_DIR' environment variable is set up for the remote helper
+and can be used to determine where to store additional data or from
+which directory to invoke auxiliary git commands.
 
 When git encounters a URL of the form '<transport>://<address>', where
 '<transport>' is a protocol that it cannot handle natively, it
@@ -119,7 +241,22 @@ Supported if the helper has the "fetch" capability.
 'push' +<src>:<dst>::
        Pushes the given local <src> commit or branch to the
        remote branch described by <dst>.  A batch sequence of
-       one or more push commands is terminated with a blank line.
+       one or more 'push' commands is terminated with a blank line
+       (if there is only one reference to push, a single 'push' command
+       is followed by a blank line). For example, the following would
+       be two batches of 'push', the first asking the remote-helper
+       to push the local ref 'master' to the remote ref 'master' and
+       the local 'HEAD' to the remote 'branch', and the second
+       asking to push ref 'foo' to ref 'bar' (forced update requested
+       by the '+').
++
+------------
+push refs/heads/master:refs/heads/master
+push HEAD:refs/heads/branch
+\n
+push +refs/heads/foo:refs/heads/bar
+\n
+------------
 +
 Zero or more protocol options may be entered after the last 'push'
 command, before the batch's terminating blank line.
@@ -144,6 +281,11 @@ Supported if the helper has the "push" capability.
 Especially useful for interoperability with a foreign versioning
 system.
 +
+Just like 'push', a batch sequence of one or more 'import' is
+terminated with a blank line. For each batch of 'import', the remote
+helper should produce a fast-import stream terminated by a 'done'
+command.
++
 Supported if the helper has the "import" capability.
 
 'connect' <service>::
@@ -168,26 +310,6 @@ completing a valid response for the current command.
 Additional commands may be supported, as may be determined from
 capabilities reported by the helper.
 
-CAPABILITIES
-------------
-
-'fetch'::
-'option'::
-'push'::
-'import'::
-'connect'::
-       This helper supports the corresponding command with the same name.
-
-'refspec' 'spec'::
-       When using the import command, expect the source ref to have
-       been written to the destination ref. The earliest applicable
-       refspec takes precedence. For example
-       "refs/heads/{asterisk}:refs/svn/origin/branches/{asterisk}" means
-       that, after an "import refs/heads/name", the script has written to
-       refs/svn/origin/branches/name. If this capability is used at
-       all, it must cover all refs reported by the list command; if
-       it is not used, it is effectively "{asterisk}:{asterisk}"
-
 REF LIST ATTRIBUTES
 -------------------
 
@@ -240,6 +362,8 @@ SEE ALSO
 --------
 linkgit:git-remote[1]
 
+linkgit:git-remote-testgit[1]
+
 GIT
 ---
 Part of the linkgit:git[1] suite
diff --git a/Documentation/git-remote-testgit.txt b/Documentation/git-remote-testgit.txt
new file mode 100644 (file)
index 0000000..2a67d45
--- /dev/null
@@ -0,0 +1,30 @@
+git-remote-testgit(1)
+=====================
+
+NAME
+----
+git-remote-testgit - Example remote-helper
+
+
+SYNOPSIS
+--------
+[verse]
+git clone testgit::<source-repo> [<destination>]
+
+DESCRIPTION
+-----------
+
+This command is a simple remote-helper, that is used both as a
+testcase for the remote-helper functionality, and as an example to
+show remote-helper authors one possible implementation.
+
+The best way to learn more is to read the comments and source code in
+'git-remote-testgit.py'.
+
+SEE ALSO
+--------
+linkgit:git-remote-helpers[1]
+
+GIT
+---
+Part of the linkgit:git[1] suite
index 3d0a7d1dac5614d6644a0ea226d65bd9f667143a..b311d59c7c06dd696e3c667c97a5982137bdd87a 100644 (file)
@@ -93,12 +93,12 @@ effect to your index in a row.
 
 EXAMPLES
 --------
-git revert HEAD~3::
+`git revert HEAD~3`::
 
        Revert the changes specified by the fourth last commit in HEAD
        and create a new commit with the reverted changes.
 
-git revert -n master{tilde}5..master{tilde}2::
+`git revert -n master{tilde}5..master{tilde}2`::
 
        Revert the changes done by commits from the fifth last commit
        in master (included) to the third last commit in master
index da0215d20c61c11307ffd4347026cc295b0dc685..665ad4ddab14da173142914407680605dad9dae6 100644 (file)
@@ -137,7 +137,7 @@ git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
 
 EXAMPLES
 --------
-git rm Documentation/\*.txt::
+`git rm Documentation/\*.txt`::
        Removes all `*.txt` files from the index that are under the
        `Documentation` directory and any of its subdirectories.
 +
@@ -145,7 +145,7 @@ Note that the asterisk `*` is quoted from the shell in this
 example; this lets git, and not the shell, expand the pathnames
 of files and subdirectories under the `Documentation/` directory.
 
-git rm -f git-*.sh::
+`git rm -f git-*.sh`::
        Because this example lets the shell expand the asterisk
        (i.e. you are listing the files explicitly), it
        does not remove `subdir/git-foo.sh`.
index 1f0e30b912f3fe4aa487129fd81ddc1dfa47a88e..1e38819e67cda4282ec7ede004ee5668d0a478c8 100644 (file)
@@ -48,23 +48,23 @@ include::pretty-formats.txt[]
 EXAMPLES
 --------
 
-git show v1.0.0::
+`git show v1.0.0`::
        Shows the tag `v1.0.0`, along with the object the tags
        points at.
 
-git show v1.0.0^\{tree\}::
+`git show v1.0.0^\{tree\}`::
        Shows the tree pointed to by the tag `v1.0.0`.
 
-git show -s --format=%s v1.0.0^\{commit\}::
+`git show -s --format=%s v1.0.0^\{commit\}`::
        Shows the subject of the commit pointed to by the
        tag `v1.0.0`.
 
-git show next~10:Documentation/README::
+`git show next~10:Documentation/README`::
        Shows the contents of the file `Documentation/README` as
        they were current in the 10th last commit of the branch
        `next`.
 
-git show master:Makefile master:t/Makefile::
+`git show master:Makefile master:t/Makefile`::
        Concatenates the contents of said Makefiles in the head
        of the branch `master`.
 
index 0ec85742ddc1c360d066659fb562898a259e48f7..67cf5f0f8b8a280891e47ecb7705d260bfc4232b 100644 (file)
@@ -15,7 +15,8 @@ SYNOPSIS
 'git submodule' [--quiet] init [--] [<path>...]
 'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase]
              [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
-'git submodule' [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
+'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
+             [commit] [--] [<path>...]
 'git submodule' [--quiet] foreach [--recursive] <command>
 'git submodule' [--quiet] sync [--] [<path>...]
 
@@ -108,8 +109,13 @@ status::
        repository and `U` if the submodule has merge conflicts.
        This command is the default command for 'git submodule'.
 +
-If '--recursive' is specified, this command will recurse into nested
+If `--recursive` is specified, this command will recurse into nested
 submodules, and show their status as well.
++
+If you are only interested in changes of the currently initialized
+submodules with respect to the commit recorded in the index or the HEAD,
+linkgit:git-status[1] and linkgit:git-diff[1] will provide that information
+too (and can also report changes to a submodule's work tree).
 
 init::
        Initialize the submodules, i.e. register each submodule name
@@ -125,26 +131,29 @@ init::
 update::
        Update the registered submodules, i.e. clone missing submodules and
        checkout the commit specified in the index of the containing repository.
-       This will make the submodules HEAD be detached unless '--rebase' or
-       '--merge' is specified or the key `submodule.$name.update` is set to
+       This will make the submodules HEAD be detached unless `--rebase` or
+       `--merge` is specified or the key `submodule.$name.update` is set to
        `rebase` or `merge`.
 +
 If the submodule is not yet initialized, and you just want to use the
 setting as stored in .gitmodules, you can automatically initialize the
-submodule with the --init option.
+submodule with the `--init` option.
 +
-If '--recursive' is specified, this command will recurse into the
+If `--recursive` is specified, this command will recurse into the
 registered submodules, and update any nested submodules within.
 
 summary::
        Show commit summary between the given commit (defaults to HEAD) and
        working tree/index. For a submodule in question, a series of commits
        in the submodule between the given super project commit and the
-       index or working tree (switched by --cached) are shown. If the option
-       --files is given, show the series of commits in the submodule between
+       index or working tree (switched by `--cached`) are shown. If the option
+       `--files` is given, show the series of commits in the submodule between
        the index of the super project and the working tree of the submodule
-       (this option doesn't allow to use the --cached option or to provide an
+       (this option doesn't allow to use the `--cached` option or to provide an
        explicit commit).
++
+Using the `--submodule=log` option with linkgit:git-diff[1] will provide that
+information too.
 
 foreach::
        Evaluates an arbitrary shell command in each checked out submodule.
@@ -155,9 +164,9 @@ foreach::
        superproject, $sha1 is the commit as recorded in the superproject,
        and $toplevel is the absolute path to the top-level of the superproject.
        Any submodules defined in the superproject but not checked out are
-       ignored by this command. Unless given --quiet, foreach prints the name
+       ignored by this command. Unless given `--quiet`, foreach prints the name
        of each submodule before evaluating the command.
-       If --recursive is given, submodules are traversed recursively (i.e.
+       If `--recursive` is given, submodules are traversed recursively (i.e.
        the given shell command is evaluated in nested submodules as well).
        A non-zero return from the command in any submodule causes
        the processing to terminate. This can be overridden by adding '|| :'
@@ -237,13 +246,18 @@ OPTIONS
        If the key `submodule.$name.update` is set to `rebase`, this option is
        implicit.
 
+--init::
+       This option is only valid for the update command.
+       Initialize all submodules for which "git submodule init" has not been
+       called so far before updating.
+
 --reference <repository>::
        This option is only valid for add and update commands.  These
        commands sometimes need to clone a remote repository. In this case,
        this option will be passed to the linkgit:git-clone[1] command.
 +
 *NOTE*: Do *not* use this option unless you have read the note
-for linkgit:git-clone[1]'s --reference and --shared options carefully.
+for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
 
 --recursive::
        This option is only valid for foreach, update and status commands.
index ed5eca1fcef50f910d74abb495360dc6c3fbf35b..f977e8780b5e152b18d07a61fde8c2f86f98a0ce 100644 (file)
@@ -157,6 +157,17 @@ Skip "branches" and "tags" of first level directories;;
        affecting the working tree; and the 'rebase' command will be
        able to update the working tree with the latest changes.
 
+--preserve-empty-dirs;;
+       Create a placeholder file in the local Git repository for each
+       empty directory fetched from Subversion.  This includes directories
+       that become empty by removing all entries in the Subversion
+       repository (but not the directory itself).  The placeholder files
+       are also tracked and removed when no longer necessary.
+
+--placeholder-filename=<filename>;;
+       Set the name of placeholder files created by --preserve-empty-dirs.
+       Default: ".gitignore"
+
 'rebase'::
        This fetches revisions from the SVN parent of the current HEAD
        and rebases the current (uncommitted to SVN) work against it.
@@ -211,8 +222,17 @@ discouraged.
        Add the given merge information during the dcommit
        (e.g. `--mergeinfo="/branches/foo:1-10"`). All svn server versions can
        store this information (as a property), and svn clients starting from
-       version 1.5 can make use of it. 'git svn' currently does not use it
-       and does not set it automatically.
+       version 1.5 can make use of it. To specify merge information from multiple
+       branches, use a single space character between the branches
+       (`--mergeinfo="/branches/foo:1-10 /branches/bar:3,5-6,8"`)
++
+[verse]
+config key: svn.pushmergeinfo
++
+This option will cause git-svn to attempt to automatically populate the
+svn:mergeinfo property in the SVN repository when possible. Currently, this can
+only be done when dcommitting non-fast-forward merges where all parents but the
+first have already been pushed into SVN.
 
 'branch'::
        Create a branch in the SVN repository.
@@ -298,7 +318,7 @@ Any other arguments are passed directly to 'git log'
        Show what revision and author last modified each line of a file. The
        output of this mode is format-compatible with the output of
        `svn blame' by default. Like the SVN blame command,
-       local uncommitted changes in the working copy are ignored;
+       local uncommitted changes in the working tree are ignored;
        the version of the file in the HEAD revision is annotated. Unknown
        arguments are passed directly to 'git blame'.
 +
index 95b135d8ad9c8e6d5f136d526c8a7a86541b4d35..346e7a20797c22a29733f09e5fe241c84a46bfa9 100644 (file)
@@ -53,26 +53,26 @@ tar.umask::
 
 EXAMPLES
 --------
-git tar-tree HEAD junk | (cd /var/tmp/ && tar xf -)::
+`git tar-tree HEAD junk | (cd /var/tmp/ && tar xf -)`::
 
        Create a tar archive that contains the contents of the
        latest commit on the current branch, and extracts it in
        `/var/tmp/junk` directory.
 
-git tar-tree v1.4.0 git-1.4.0 | gzip >git-1.4.0.tar.gz::
+`git tar-tree v1.4.0 git-1.4.0 | gzip >git-1.4.0.tar.gz`::
 
        Create a tarball for v1.4.0 release.
 
-git tar-tree v1.4.0{caret}\{tree\} git-1.4.0 | gzip >git-1.4.0.tar.gz::
+`git tar-tree v1.4.0{caret}\{tree\} git-1.4.0 | gzip >git-1.4.0.tar.gz`::
 
        Create a tarball for v1.4.0 release, but without a
        global extended pax header.
 
-git tar-tree --remote=example.com:git.git v1.4.0 >git-1.4.0.tar::
+`git tar-tree --remote=example.com:git.git v1.4.0 >git-1.4.0.tar`::
 
        Get a tarball v1.4.0 from example.com.
 
-git tar-tree HEAD:Documentation/ git-docs > git-1.4.0-docs.tar::
+`git tar-tree HEAD:Documentation/ git-docs > git-1.4.0-docs.tar`::
 
        Put everything in the current head's Documentation/ directory
        into 'git-1.4.0-docs.tar', with the prefix 'git-docs/'.
index d3931294d174e5c06adb81e428e31e00fbfa3b5e..a3081f4e237747dc858fd105302cbb9a489de41b 100644 (file)
@@ -264,7 +264,9 @@ tree files, you have to explicitly tell git about it by dropping
 "assume unchanged" bit, either before or after you modify them.
 
 In order to set "assume unchanged" bit, use `--assume-unchanged`
-option.  To unset, use `--no-assume-unchanged`.
+option.  To unset, use `--no-assume-unchanged`. To see which files
+have the "assume unchanged" bit set, use `git ls-files -v`
+(see linkgit:git-ls-files[1]).
 
 The command looks at `core.ignorestat` configuration variable.  When
 this is true, paths updated with `git update-index paths...` and
@@ -363,7 +365,8 @@ ctime for marking files processed) (see linkgit:git-config[1]).
 SEE ALSO
 --------
 linkgit:git-config[1],
-linkgit:git-add[1]
+linkgit:git-add[1],
+linkgit:git-ls-files[1]
 
 GIT
 ---
index a58e90ca8dada4a9847886374968635ea6bc3f9f..71f16083d6b2c366a54db1d966e17ab2aeda1ef1 100644 (file)
@@ -34,6 +34,10 @@ OPTIONS
 <directory>::
        The repository to sync from.
 
+SEE ALSO
+--------
+linkgit:gitnamespaces[7]
+
 GIT
 ---
 Part of the linkgit:git[1] suite
index 99388bd3744dd593a97dbf34c022d4d5125bba6c..76c7f7eec5bb8ba01262762909939070b55ef5c9 100644 (file)
@@ -53,12 +53,12 @@ include::pretty-formats.txt[]
 
 Examples
 --------
-git whatchanged -p v2.6.12.. include/scsi drivers/scsi::
+`git whatchanged -p v2.6.12.. include/scsi drivers/scsi`::
 
        Show as patches the commits since version 'v2.6.12' that changed
        any file in the include/scsi or drivers/scsi subdirectories
 
-git whatchanged --since="2 weeks ago" \-- gitk::
+`git whatchanged --since="2 weeks ago" \-- gitk`::
 
        Show the changes during the last two weeks to the file 'gitk'.
        The "--" is necessary to avoid confusion with the *branch* named
index 0172cd70149914897862fbf0f3f221c7ef31ea5c..5e80cfd71a5529225b607bd3f1732d19f05d0c1d 100644 (file)
@@ -10,8 +10,8 @@ SYNOPSIS
 --------
 [verse]
 'git' [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
-    [-p|--paginate|--no-pager] [--no-replace-objects]
-    [--bare] [--git-dir=<path>] [--work-tree=<path>]
+    [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
+    [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
     [-c <name>=<value>]
     [--help] <command> [<args>]
 
@@ -44,9 +44,19 @@ unreleased) version of git, that is available from 'master'
 branch of the `git.git` repository.
 Documentation for older releases are available here:
 
-* link:v1.7.6/git.html[documentation for release 1.7.6]
+* link:v1.7.7.1/git.html[documentation for release 1.7.7.1]
 
 * release notes for
+  link:RelNotes/1.7.7.1.txt[1.7.7.1],
+  link:RelNotes/1.7.7.txt[1.7.7].
+
+* link:v1.7.6.4/git.html[documentation for release 1.7.6.4]
+
+* release notes for
+  link:RelNotes/1.7.6.4.txt[1.7.6.4],
+  link:RelNotes/1.7.6.3.txt[1.7.6.3],
+  link:RelNotes/1.7.6.2.txt[1.7.6.2],
+  link:RelNotes/1.7.6.1.txt[1.7.6.1],
   link:RelNotes/1.7.6.txt[1.7.6].
 
 * link:v1.7.5.4/git.html[documentation for release 1.7.5.4]
@@ -330,6 +340,11 @@ help ...`.
        variable (see core.worktree in linkgit:git-config[1] for a
        more detailed discussion).
 
+--namespace=<path>::
+       Set the git namespace.  See linkgit:gitnamespaces[7] for more
+       details.  Equivalent to setting the `GIT_NAMESPACE` environment
+       variable.
+
 --bare::
        Treat the repository as a bare repository.  If GIT_DIR
        environment is not set, it is set to the current working
@@ -593,6 +608,10 @@ git so take care if using Cogito etc.
        This can also be controlled by the '--work-tree' command line
        option and the core.worktree configuration variable.
 
+'GIT_NAMESPACE'::
+       Set the git namespace; see linkgit:gitnamespaces[7] for details.
+       The '--namespace' command-line option also sets this value.
+
 'GIT_CEILING_DIRECTORIES'::
        This should be a colon-separated list of absolute paths.
        If set, it is a list of directories that git should not chdir
index 412c55b549354471a56a4e56ca5533277c83bc54..25e46aeb7a32287c7dc2666d2633c4787ae1c59a 100644 (file)
@@ -79,7 +79,7 @@ Attributes for all users on a system should be placed in the
 `$(prefix)/etc/gitattributes` file.
 
 Sometimes you would need to override an setting of an attribute
-for a path to `unspecified` state.  This can be done by listing
+for a path to `Unspecified` state.  This can be done by listing
 the name of the attribute prefixed with an exclamation point `!`.
 
 
@@ -868,7 +868,7 @@ If this attribute is not set or has an invalid value, the value of the
 (See linkgit:git-config[1]).
 
 
-USING ATTRIBUTE MACROS
+USING MACRO ATTRIBUTES
 ----------------------
 
 You do not want any end-of-line conversions applied to, nor textual diffs
@@ -879,24 +879,27 @@ produced for, any binary file you track.  You would need to specify e.g.
 ------------
 
 but that may become cumbersome, when you have many attributes.  Using
-attribute macros, you can specify groups of attributes set or unset at
-the same time.  The system knows a built-in attribute macro, `binary`:
+macro attributes, you can define an attribute that, when set, also
+sets or unsets a number of other attributes at the same time.  The
+system knows a built-in macro attribute, `binary`:
 
 ------------
 *.jpg binary
 ------------
 
-which is equivalent to the above.  Note that the attribute macros can only
-be "Set" (see the above example that sets "binary" macro as if it were an
-ordinary attribute --- setting it in turn unsets "text" and "diff").
+Setting the "binary" attribute also unsets the "text" and "diff"
+attributes as above.  Note that macro attributes can only be "Set",
+though setting one might have the effect of setting or unsetting other
+attributes or even returning other attributes to the "Unspecified"
+state.
 
 
-DEFINING ATTRIBUTE MACROS
+DEFINING MACRO ATTRIBUTES
 -------------------------
 
-Custom attribute macros can be defined only in the `.gitattributes` file
-at the toplevel (i.e. not in any subdirectory).  The built-in attribute
-macro "binary" is equivalent to:
+Custom macro attributes can be defined only in the `.gitattributes`
+file at the toplevel (i.e. not in any subdirectory).  The built-in
+macro attribute "binary" is equivalent to:
 
 ------------
 [attr]binary -diff -text
@@ -952,6 +955,9 @@ frotz       unspecified
 ----------------------------------------------------------------
 
 
+SEE ALSO
+--------
+linkgit:git-check-attr[1].
 
 GIT
 ---
diff --git a/Documentation/gitnamespaces.txt b/Documentation/gitnamespaces.txt
new file mode 100644 (file)
index 0000000..c6713cf
--- /dev/null
@@ -0,0 +1,82 @@
+gitnamespaces(7)
+================
+
+NAME
+----
+gitnamespaces - Git namespaces
+
+SYNOPSIS
+--------
+[verse]
+GIT_NAMESPACE=<namespace> 'git upload-pack'
+GIT_NAMESPACE=<namespace> 'git receive-pack'
+
+
+DESCRIPTION
+-----------
+
+Git supports dividing the refs of a single repository into multiple
+namespaces, each of which has its own branches, tags, and HEAD.  Git can
+expose each namespace as an independent repository to pull from and push
+to, while sharing the object store, and exposing all the refs to
+operations such as linkgit:git-gc[1].
+
+Storing multiple repositories as namespaces of a single repository
+avoids storing duplicate copies of the same objects, such as when
+storing multiple branches of the same source.  The alternates mechanism
+provides similar support for avoiding duplicates, but alternates do not
+prevent duplication between new objects added to the repositories
+without ongoing maintenance, while namespaces do.
+
+To specify a namespace, set the `GIT_NAMESPACE` environment variable to
+the namespace.  For each ref namespace, git stores the corresponding
+refs in a directory under `refs/namespaces/`.  For example,
+`GIT_NAMESPACE=foo` will store refs under `refs/namespaces/foo/`.  You
+can also specify namespaces via the `--namespace` option to
+linkgit:git[1].
+
+Note that namespaces which include a `/` will expand to a hierarchy of
+namespaces; for example, `GIT_NAMESPACE=foo/bar` will store refs under
+`refs/namespaces/foo/refs/namespaces/bar/`.  This makes paths in
+`GIT_NAMESPACE` behave hierarchically, so that cloning with
+`GIT_NAMESPACE=foo/bar` produces the same result as cloning with
+`GIT_NAMESPACE=foo` and cloning from that repo with `GIT_NAMESPACE=bar`.  It
+also avoids ambiguity with strange namespace paths such as `foo/refs/heads/`,
+which could otherwise generate directory/file conflicts within the `refs`
+directory.
+
+linkgit:git-upload-pack[1] and linkgit:git-receive-pack[1] rewrite the
+names of refs as specified by `GIT_NAMESPACE`.  git-upload-pack and
+git-receive-pack will ignore all references outside the specified
+namespace.
+
+The smart HTTP server, linkgit:git-http-backend[1], will pass
+GIT_NAMESPACE through to the backend programs; see
+linkgit:git-http-backend[1] for sample configuration to expose
+repository namespaces as repositories.
+
+For a simple local test, you can use linkgit:git-remote-ext[1]:
+
+----------
+git clone ext::'git --namespace=foo %s /tmp/prefixed.git'
+----------
+
+SECURITY
+--------
+
+Anyone with access to any namespace within a repository can potentially
+access objects from any other namespace stored in the same repository.
+You can't directly say "give me object ABCD" if you don't have a ref to
+it, but you can do some other sneaky things like:
+
+. Claiming to push ABCD, at which point the server will optimize out the
+  need for you to actually send it. Now you have a ref to ABCD and can
+  fetch it (claiming not to have it, of course).
+
+. Requesting other refs, claiming that you have ABCD, at which point the
+  server may generate deltas against ABCD.
+
+None of this causes a problem if you only host public repositories, or
+if everyone who may read one namespace may also read everything in every
+other namespace (for instance, if everyone in an organization has read
+permission to every repository).
index eb3d040783e8202f502d05e8b4dc4e3b39736779..5c891f1169b35e53bccc19f0423b5b7e98db720b 100644 (file)
@@ -23,32 +23,25 @@ objects::
        Object store associated with this repository.  Usually
        an object store is self sufficient (i.e. all the objects
        that are referred to by an object found in it are also
-       found in it), but there are couple of ways to violate
-       it.
+       found in it), but there are a few ways to violate it.
 +
-. You could populate the repository by running a commit walker
-without `-a` option.  Depending on which options are given, you
-could have only commit objects without associated blobs and
-trees this way, for example.  A repository with this kind of
-incomplete object store is not suitable to be published to the
-outside world but sometimes useful for private repository.
-. You also could have an incomplete but locally usable repository
-by cloning shallowly.  See linkgit:git-clone[1].
-. You can be using `objects/info/alternates` mechanism, or
-`$GIT_ALTERNATE_OBJECT_DIRECTORIES` mechanism to 'borrow'
+. You could have an incomplete but locally usable repository
+by creating a shallow clone.  See linkgit:git-clone[1].
+. You could be using the `objects/info/alternates` or
+`$GIT_ALTERNATE_OBJECT_DIRECTORIES` mechanisms to 'borrow'
 objects from other object stores.  A repository with this kind
 of incomplete object store is not suitable to be published for
 use with dumb transports but otherwise is OK as long as
-`objects/info/alternates` points at the right object stores
-it borrows from.
+`objects/info/alternates` points at the object stores it
+borrows from.
 
 objects/[0-9a-f][0-9a-f]::
-       Traditionally, each object is stored in its own file.
-       They are split into 256 subdirectories using the first
-       two letters from its object name to keep the number of
-       directory entries `objects` directory itself needs to
-       hold.  Objects found here are often called 'unpacked'
-       (or 'loose') objects.
+       A newly created object is stored in its own file.
+       The objects are splayed over 256 subdirectories using
+       the first two characters of the sha1 object name to
+       keep the number of directory entries in `objects`
+       itself to a manageable number. Objects found
+       here are often called 'unpacked' (or 'loose') objects.
 
 objects/pack::
        Packs (files that store many object in compressed form,
@@ -85,7 +78,7 @@ objects/info/http-alternates::
 
 refs::
        References are stored in subdirectories of this
-       directory.  The 'git prune' command knows to keep
+       directory.  The 'git prune' command knows to preserve
        objects reachable from refs found in this directory and
        its subdirectories.
 
@@ -119,16 +112,17 @@ HEAD::
 +
 HEAD can also record a specific commit directly, instead of
 being a symref to point at the current branch.  Such a state
-is often called 'detached HEAD', and almost all commands work
-identically as normal.  See linkgit:git-checkout[1] for
-details.
+is often called 'detached HEAD.'  See linkgit:git-checkout[1]
+for details.
 
 branches::
        A slightly deprecated way to store shorthands to be used
-       to specify URL to 'git fetch', 'git pull' and 'git push'
-       commands is to store a file in `branches/<name>` and
-       give 'name' to these commands in place of 'repository'
-       argument.
+       to specify a URL to 'git fetch', 'git pull' and 'git push'.
+       A file can be stored as `branches/<name>` and then
+       'name' can be given to these commands in place of
+       'repository' argument.  See the REMOTES section in
+       linkgit:git-fetch[1] for details.  This mechanism is legacy
+       and not likely to be found in modern repositories.
 
 hooks::
        Hooks are customization scripts used by various git
@@ -173,9 +167,11 @@ info/exclude::
        at it.  See also: linkgit:gitignore[5].
 
 remotes::
-       Stores shorthands to be used to give URL and default
-       refnames to interact with remote repository to
-       'git fetch', 'git pull' and 'git push' commands.
+       Stores shorthands for URL and default refnames for use
+       when interacting with remote repositories via 'git fetch',
+       'git pull' and 'git push' commands.  See the REMOTES section
+       in linkgit:git-fetch[1] for details.  This mechanism is legacy
+       and not likely to be found in modern repositories.
 
 logs::
        Records of changes made to refs are stored in this
index d527b307707c676e82a08f18cb9fdd7d3abcb228..8823a37067811037487a9f0496736bfafdc8b7ad 100644 (file)
@@ -176,7 +176,7 @@ by doing the following:
  - Update "What's cooking" message to review the updates to
    existing topics, newly added topics and graduated topics.
 
-   This step is helped with Meta/UWC script (where Meta/ contains
+   This step is helped with Meta/cook script (where Meta/ contains
    a checkout of the 'todo' branch).
 
  - Merge topics to 'next'.  For each branch whose tip is not
@@ -197,10 +197,9 @@ by doing the following:
 
    - Nothing is next-worthy; do not do anything.
 
- - Rebase topics that do not have any commit in next yet.  This
-   step is optional but sometimes is worth doing when an old
-   series that is not in next can take advantage of low-level
-   framework change that is merged to 'master' already.
+ - [** OBSOLETE **] Optionally rebase topics that do not have any commit
+   in next yet, when they can take advantage of low-level framework
+   change that is merged to 'master' already.
 
      $ git rebase master ai/topic
 
@@ -209,7 +208,7 @@ by doing the following:
    pre-rebase hook to make sure that topics that are already in
    'next' are not rebased beyond the merged commit.
 
- - Rebuild "pu" to merge the tips of topics not in 'next'.
+ - [** OBSOLETE **] Rebuild "pu" to merge the tips of topics not in 'next'.
 
      $ git checkout pu
      $ git reset --hard next
@@ -241,7 +240,7 @@ by doing the following:
 
  - Fetch html and man branches back from k.org, and push four
    integration branches and the two documentation branches to
-   repo.or.cz
+   repo.or.cz and other mirrors.
 
 
 Some observations to be made.
diff --git a/Documentation/technical/api-argv-array.txt b/Documentation/technical/api-argv-array.txt
new file mode 100644 (file)
index 0000000..49b3d52
--- /dev/null
@@ -0,0 +1,46 @@
+argv-array API
+==============
+
+The argv-array API allows one to dynamically build and store
+NULL-terminated lists.  An argv-array maintains the invariant that the
+`argv` member always points to a non-NULL array, and that the array is
+always NULL-terminated at the element pointed to by `argv[argc]`. This
+makes the result suitable for passing to functions expecting to receive
+argv from main(), or the link:api-run-command.html[run-command API].
+
+The link:api-string-list.html[string-list API] is similar, but cannot be
+used for these purposes; instead of storing a straight string pointer,
+it contains an item structure with a `util` field that is not compatible
+with the traditional argv interface.
+
+Each `argv_array` manages its own memory. Any strings pushed into the
+array are duplicated, and all memory is freed by argv_array_clear().
+
+Data Structures
+---------------
+
+`struct argv_array`::
+
+       A single array. This should be initialized by assignment from
+       `ARGV_ARRAY_INIT`, or by calling `argv_array_init`. The `argv`
+       member contains the actual array; the `argc` member contains the
+       number of elements in the array, not including the terminating
+       NULL.
+
+Functions
+---------
+
+`argv_array_init`::
+       Initialize an array. This is no different than assigning from
+       `ARGV_ARRAY_INIT`.
+
+`argv_array_push`::
+       Push a copy of a string onto the end of the array.
+
+`argv_array_pushf`::
+       Format a string and push it onto the end of the array. This is a
+       convenience wrapper combining `strbuf_addf` and `argv_array_push`.
+
+`argv_array_clear`::
+       Free all memory associated with the array and return it to the
+       initial, empty state.
index 5cb2b0590abb1fc4e4685097ba3cdd3d0683a95f..b0cafe87bee046dc9b2d4e61e0d057e787a6f1f6 100644 (file)
@@ -49,6 +49,8 @@ Additionally, if `foo` is a new command, there are 3 more things to do:
 
 . Add an entry for `git-foo` to `command-list.txt`.
 
+. Add an entry for `/git-foo` to `.gitignore`.
+
 
 How a built-in is called
 ------------------------
index 9d97eaa9dee99eef7e66072c4c51cfff3000bba3..ce363b6305ec117810d66308b0066814871f54e1 100644 (file)
@@ -11,27 +11,15 @@ Data Structure
 `struct git_attr`::
 
        An attribute is an opaque object that is identified by its name.
-       Pass the name and its length to `git_attr()` function to obtain
-       the object of this type.  The internal representation of this
-       structure is of no interest to the calling programs.
+       Pass the name to `git_attr()` function to obtain the object of
+       this type.  The internal representation of this structure is
+       of no interest to the calling programs.  The name of the
+       attribute can be retrieved by calling `git_attr_name()`.
 
 `struct git_attr_check`::
 
        This structure represents a set of attributes to check in a call
-       to `git_checkattr()` function, and receives the results.
-
-
-Calling Sequence
-----------------
-
-* Prepare an array of `struct git_attr_check` to define the list of
-  attributes you would want to check.  To populate this array, you would
-  need to define necessary attributes by calling `git_attr()` function.
-
-* Call git_checkattr() to check the attributes for the path.
-
-* Inspect `git_attr_check` structure to see how each of the attribute in
-  the array is defined for the path.
+       to `git_check_attr()` function, and receives the results.
 
 
 Attribute Values
@@ -57,6 +45,19 @@ If none of the above returns true, `.value` member points at a string
 value of the attribute for the path.
 
 
+Querying Specific Attributes
+----------------------------
+
+* Prepare an array of `struct git_attr_check` to define the list of
+  attributes you would want to check.  To populate this array, you would
+  need to define necessary attributes by calling `git_attr()` function.
+
+* Call `git_check_attr()` to check the attributes for the path.
+
+* Inspect `git_attr_check` structure to see how each of the attribute in
+  the array is defined for the path.
+
+
 Example
 -------
 
@@ -72,18 +73,18 @@ static void setup_check(void)
 {
        if (check[0].attr)
                return; /* already done */
-       check[0].attr = git_attr("crlf", 4);
-       check[1].attr = git_attr("ident", 5);
+       check[0].attr = git_attr("crlf");
+       check[1].attr = git_attr("ident");
 }
 ------------
 
-. Call `git_checkattr()` with the prepared array of `struct git_attr_check`:
+. Call `git_check_attr()` with the prepared array of `struct git_attr_check`:
 
 ------------
        const char *path;
 
        setup_check();
-       git_checkattr(path, ARRAY_SIZE(check), check);
+       git_check_attr(path, ARRAY_SIZE(check), check);
 ------------
 
 . Act on `.value` member of the result, left in `check[]`:
@@ -108,4 +109,20 @@ static void setup_check(void)
        }
 ------------
 
-(JC)
+
+Querying All Attributes
+-----------------------
+
+To get the values of all attributes associated with a file:
+
+* Call `git_all_attrs()`, which returns an array of `git_attr_check`
+  structures.
+
+* Iterate over the `git_attr_check` array to examine the attribute
+  names and values.  The name of the attribute described by a
+  `git_attr_check` object can be retrieved via
+  `git_attr_name(check[i].attr)`.  (Please note that no items will be
+  returned for unset attributes, so `ATTR_UNSET()` will return false
+  for all returned `git_array_check` objects.)
+
+* Free the `git_array_check` array.
diff --git a/Documentation/technical/api-ref-iteration.txt b/Documentation/technical/api-ref-iteration.txt
new file mode 100644 (file)
index 0000000..dbbea95
--- /dev/null
@@ -0,0 +1,81 @@
+ref iteration API
+=================
+
+
+Iteration of refs is done by using an iterate function which will call a
+callback function for every ref. The callback function has this
+signature:
+
+       int handle_one_ref(const char *refname, const unsigned char *sha1,
+                          int flags, void *cb_data);
+
+There are different kinds of iterate functions which all take a
+callback of this type. The callback is then called for each found ref
+until the callback returns nonzero. The returned value is then also
+returned by the iterate function.
+
+Iteration functions
+-------------------
+
+* `head_ref()` just iterates the head ref.
+
+* `for_each_ref()` iterates all refs.
+
+* `for_each_ref_in()` iterates all refs which have a defined prefix and
+  strips that prefix from the passed variable refname.
+
+* `for_each_tag_ref()`, `for_each_branch_ref()`, `for_each_remote_ref()`,
+  `for_each_replace_ref()` iterate refs from the respective area.
+
+* `for_each_glob_ref()` iterates all refs that match the specified glob
+  pattern.
+
+* `for_each_glob_ref_in()` the previous and `for_each_ref_in()` combined.
+
+* `head_ref_submodule()`, `for_each_ref_submodule()`,
+  `for_each_ref_in_submodule()`, `for_each_tag_ref_submodule()`,
+  `for_each_branch_ref_submodule()`, `for_each_remote_ref_submodule()`
+  do the same as the functions descibed above but for a specified
+  submodule.
+
+* `for_each_rawref()` can be used to learn about broken ref and symref.
+
+* `for_each_reflog()` iterates each reflog file.
+
+Submodules
+----------
+
+If you want to iterate the refs of a submodule you first need to add the
+submodules object database. You can do this by a code-snippet like
+this:
+
+       const char *path = "path/to/submodule"
+       if (!add_submodule_odb(path))
+               die("Error submodule '%s' not populated.", path);
+
+`add_submodule_odb()` will return an non-zero value on success. If you
+do not do this you will get an error for each ref that it does not point
+to a valid object.
+
+Note: As a side-effect of this you can not safely assume that all
+objects you lookup are available in superproject. All submodule objects
+will be available the same way as the superprojects objects.
+
+Example:
+--------
+
+----
+static int handle_remote_ref(const char *refname,
+               const unsigned char *sha1, int flags, void *cb_data)
+{
+       struct strbuf *output = cb_data;
+       strbuf_addf(output, "%s\n", refname);
+       return 0;
+}
+
+...
+
+       struct strbuf output = STRBUF_INIT;
+       for_each_remote_ref(handle_remote_ref, &output);
+       printf("%s", output.buf);
+----
diff --git a/Documentation/technical/api-sha1-array.txt b/Documentation/technical/api-sha1-array.txt
new file mode 100644 (file)
index 0000000..4a4bae8
--- /dev/null
@@ -0,0 +1,79 @@
+sha1-array API
+==============
+
+The sha1-array API provides storage and manipulation of sets of SHA1
+identifiers. The emphasis is on storage and processing efficiency,
+making them suitable for large lists. Note that the ordering of items is
+not preserved over some operations.
+
+Data Structures
+---------------
+
+`struct sha1_array`::
+
+       A single array of SHA1 hashes. This should be initialized by
+       assignment from `SHA1_ARRAY_INIT`.  The `sha1` member contains
+       the actual data. The `nr` member contains the number of items in
+       the set.  The `alloc` and `sorted` members are used internally,
+       and should not be needed by API callers.
+
+Functions
+---------
+
+`sha1_array_append`::
+       Add an item to the set. The sha1 will be placed at the end of
+       the array (but note that some operations below may lose this
+       ordering).
+
+`sha1_array_sort`::
+       Sort the elements in the array.
+
+`sha1_array_lookup`::
+       Perform a binary search of the array for a specific sha1.
+       If found, returns the offset (in number of elements) of the
+       sha1. If not found, returns a negative integer. If the array is
+       not sorted, this function has the side effect of sorting it.
+
+`sha1_array_clear`::
+       Free all memory associated with the array and return it to the
+       initial, empty state.
+
+`sha1_array_for_each_unique`::
+       Efficiently iterate over each unique element of the list,
+       executing the callback function for each one. If the array is
+       not sorted, this function has the side effect of sorting it.
+
+Examples
+--------
+
+-----------------------------------------
+void print_callback(const unsigned char sha1[20],
+                   void *data)
+{
+       printf("%s\n", sha1_to_hex(sha1));
+}
+
+void some_func(void)
+{
+       struct sha1_array hashes = SHA1_ARRAY_INIT;
+       unsigned char sha1[20];
+
+       /* Read objects into our set */
+       while (read_object_from_stdin(sha1))
+               sha1_array_append(&hashes, sha1);
+
+       /* Check if some objects are in our set */
+       while (read_object_from_stdin(sha1)) {
+               if (sha1_array_lookup(&hashes, sha1) >= 0)
+                       printf("it's in there!\n");
+
+       /*
+        * Print the unique set of objects. We could also have
+        * avoided adding duplicate objects in the first place,
+        * but we would end up re-sorting the array repeatedly.
+        * Instead, this will sort once and then skip duplicates
+        * in linear time.
+        */
+       sha1_array_for_each_unique(&hashes, print_callback, NULL);
+}
+-----------------------------------------
index 3f575bdcff3a6b38304710b22371784c2e7443c9..ce24eb96f5efdee579f8600323731368fee4048b 100644 (file)
@@ -29,6 +29,9 @@ member (you need this if you add things later) and you should set the
 
 . Can sort an unsorted list using `sort_string_list`.
 
+. Can remove individual items of an unsorted list using
+  `unsorted_string_list_delete_item`.
+
 . Finally it should free the list using `string_list_clear`.
 
 Example:
@@ -112,6 +115,13 @@ write `string_list_insert(...)->util = ...;`.
 The above two functions need to look through all items, as opposed to their
 counterpart for sorted lists, which performs a binary search.
 
+`unsorted_string_list_delete_item`::
+
+       Remove an item from a string_list. The `string` pointer of the items
+       will be freed in case the `strdup_strings` member of the string_list
+       is set. The third parameter controls if the `util` pointer of the
+       items should be freed or not.
+
 Data structures
 ---------------
 
index 8270abb5f982463119309423eded333a8153317e..dbdb4c137f162cc807ee57adcc52a10e067029c9 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v1.7.6.GIT
+DEF_VER=v1.7.7.1
 
 LF='
 '
index 4ed7996f7bcc3a044b0da54e8319fc0339ff009d..71b853ffaf740aaba2415a18377326f37c27d584 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -30,15 +30,15 @@ all::
 # Define LIBPCREDIR=/foo/bar if your libpcre header and library files are in
 # /foo/bar/include and /foo/bar/lib directories.
 #
-# Define NO_CURL if you do not have libcurl installed.  git-http-pull and
+# Define NO_CURL if you do not have libcurl installed.  git-http-fetch and
 # git-http-push are not built, and you cannot use http:// and https://
-# transports.
+# transports (neither smart nor dumb).
 #
 # Define CURLDIR=/foo/bar if your curl header and library files are in
 # /foo/bar/include and /foo/bar/lib directories.
 #
 # Define NO_EXPAT if you do not have expat installed.  git-http-push is
-# not built, and you cannot push using http:// and https:// transports.
+# not built, and you cannot push using http:// and https:// transports (dumb).
 #
 # Define EXPATDIR=/foo/bar if your expat header and library files are in
 # /foo/bar/include and /foo/bar/lib directories.
@@ -115,6 +115,10 @@ all::
 #
 # Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin).
 #
+# Define NEEDS_SSL_WITH_CURL if you need -lssl with -lcurl (Minix).
+#
+# Define NEEDS_IDN_WITH_CURL if you need -lidn when using -lcurl (Minix).
+#
 # Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
 #
 # Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
@@ -298,6 +302,7 @@ bindir = $(prefix)/$(bindir_relative)
 mandir = share/man
 infodir = share/info
 gitexecdir = libexec/git-core
+mergetoolsdir = $(gitexecdir)/mergetools
 sharedir = $(prefix)/share
 gitwebdir = $(sharedir)/gitweb
 template_dir = share/git-core/templates
@@ -500,6 +505,7 @@ VCSSVN_LIB=vcs-svn/lib.a
 
 LIB_H += advice.h
 LIB_H += archive.h
+LIB_H += argv-array.h
 LIB_H += attr.h
 LIB_H += blob.h
 LIB_H += builtin.h
@@ -510,6 +516,7 @@ LIB_H += commit.h
 LIB_H += compat/bswap.h
 LIB_H += compat/cygwin.h
 LIB_H += compat/mingw.h
+LIB_H += compat/obstack.h
 LIB_H += compat/win32/pthread.h
 LIB_H += compat/win32/syslog.h
 LIB_H += compat/win32/sys/poll.h
@@ -528,6 +535,7 @@ LIB_H += graph.h
 LIB_H += grep.h
 LIB_H += hash.h
 LIB_H += help.h
+LIB_H += kwset.h
 LIB_H += levenshtein.h
 LIB_H += list-objects.h
 LIB_H += ll-merge.h
@@ -579,6 +587,7 @@ LIB_OBJS += alloc.o
 LIB_OBJS += archive.o
 LIB_OBJS += archive-tar.o
 LIB_OBJS += archive-zip.o
+LIB_OBJS += argv-array.o
 LIB_OBJS += attr.o
 LIB_OBJS += base85.o
 LIB_OBJS += bisect.o
@@ -589,6 +598,7 @@ LIB_OBJS += cache-tree.o
 LIB_OBJS += color.o
 LIB_OBJS += combine-diff.o
 LIB_OBJS += commit.o
+LIB_OBJS += compat/obstack.o
 LIB_OBJS += config.o
 LIB_OBJS += connect.o
 LIB_OBJS += convert.o
@@ -618,6 +628,7 @@ LIB_OBJS += hash.o
 LIB_OBJS += help.o
 LIB_OBJS += hex.o
 LIB_OBJS += ident.o
+LIB_OBJS += kwset.o
 LIB_OBJS += levenshtein.o
 LIB_OBJS += list-objects.o
 LIB_OBJS += ll-merge.o
@@ -638,6 +649,7 @@ LIB_OBJS += pack-revindex.o
 LIB_OBJS += pack-write.o
 LIB_OBJS += pager.o
 LIB_OBJS += parse-options.o
+LIB_OBJS += parse-options-cb.o
 LIB_OBJS += patch-delta.o
 LIB_OBJS += patch-ids.o
 LIB_OBJS += path.o
@@ -810,6 +822,7 @@ ifeq ($(uname_S),GNU/kFreeBSD)
        NO_STRLCPY = YesPlease
        NO_MKSTEMPS = YesPlease
        HAVE_PATHS_H = YesPlease
+       DIR_HAS_BSD_GROUP_SEMANTICS = YesPlease
 endif
 ifeq ($(uname_S),UnixWare)
        CC = cc
@@ -1149,6 +1162,20 @@ ifeq ($(uname_S),Interix)
                NO_FNMATCH_CASEFOLD = YesPlease
        endif
 endif
+ifeq ($(uname_S),Minix)
+       NO_IPV6 = YesPlease
+       NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
+       NO_NSEC = YesPlease
+       NEEDS_LIBGEN =
+       NEEDS_CRYPTO_WITH_SSL = YesPlease
+       NEEDS_IDN_WITH_CURL = YesPlease
+       NEEDS_SSL_WITH_CURL = YesPlease
+       NEEDS_RESOLV =
+       NO_HSTRERROR = YesPlease
+       NO_MMAP = YesPlease
+       NO_CURL =
+       NO_EXPAT =
+endif
 ifneq (,$(findstring MINGW,$(uname_S)))
        pathsep = ;
        NO_PREAD = YesPlease
@@ -1293,6 +1320,16 @@ else
        else
                CURL_LIBCURL = -lcurl
        endif
+       ifdef NEEDS_SSL_WITH_CURL
+               CURL_LIBCURL += -lssl
+               ifdef NEEDS_CRYPTO_WITH_SSL
+                       CURL_LIBCURL += -lcrypto
+               endif
+       endif
+       ifdef NEEDS_IDN_WITH_CURL
+               CURL_LIBCURL += -lidn
+       endif
+
        REMOTE_CURL_PRIMARY = git-remote-http$X
        REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X
        REMOTE_CURL_NAMES = $(REMOTE_CURL_PRIMARY) $(REMOTE_CURL_ALIASES)
@@ -1329,7 +1366,7 @@ ifndef NO_OPENSSL
                OPENSSL_LINK =
        endif
        ifdef NEEDS_CRYPTO_WITH_SSL
-               OPENSSL_LINK += -lcrypto
+               OPENSSL_LIBSSL += -lcrypto
        endif
 else
        BASIC_CFLAGS += -DNO_OPENSSL
@@ -1848,7 +1885,7 @@ ifndef NO_CURL
        GIT_OBJS += http.o http-walker.o remote-curl.o
 endif
 XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
-       xdiff/xmerge.o xdiff/xpatience.o
+       xdiff/xmerge.o xdiff/xpatience.o xdiff/xhistogram.o
 VCSSVN_OBJS = vcs-svn/string_pool.o vcs-svn/line_buffer.o \
        vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o
 VCSSVN_TEST_OBJS = test-obj-pool.o test-string-pool.o \
@@ -2176,7 +2213,7 @@ test-delta$X: diff-delta.o patch-delta.o
 
 test-line-buffer$X: vcs-svn/lib.a
 
-test-parse-options$X: parse-options.o
+test-parse-options$X: parse-options.o parse-options-cb.o
 
 test-string-pool$X: vcs-svn/lib.a
 
@@ -2229,6 +2266,13 @@ endif
 gitexec_instdir_SQ = $(subst ','\'',$(gitexec_instdir))
 export gitexec_instdir
 
+ifneq ($(filter /%,$(firstword $(mergetoolsdir))),)
+mergetools_instdir = $(mergetoolsdir)
+else
+mergetools_instdir = $(prefix)/$(mergetoolsdir)
+endif
+mergetools_instdir_SQ = $(subst ','\'',$(mergetools_instdir))
+
 install_bindir_programs := $(patsubst %,%$X,$(BINDIR_PROGRAMS_NEED_X)) $(BINDIR_PROGRAMS_NO_X)
 
 install: all
@@ -2238,6 +2282,9 @@ install: all
        $(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
        $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
        $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
+       $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
+       (cd mergetools && $(TAR) cf - .) | \
+       (cd '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' && umask 022 && $(TAR) xof -)
 ifndef NO_PERL
        $(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
        $(MAKE) -C gitweb install
index 6372427426d80b01b03437fd1a55fd412fb8f75d..77a28d448a76cb0387565b254d4f886924c315b6 120000 (symlink)
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/1.7.7.txt
\ No newline at end of file
+Documentation/RelNotes/1.7.7.1.txt
\ No newline at end of file
index 37287f86c18f8b532feb38b5c70541c8cb3d3a44..f04ac18e33063f7e2cb9ab9eab9a6b86cb089b5a 100644 (file)
--- a/abspath.c
+++ b/abspath.c
@@ -139,3 +139,31 @@ const char *absolute_path(const char *path)
        }
        return buf;
 }
+
+/*
+ * Unlike prefix_path, this should be used if the named file does
+ * not have to interact with index entry; i.e. name of a random file
+ * on the filesystem.
+ */
+const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
+{
+       static char path[PATH_MAX];
+#ifndef WIN32
+       if (!pfx_len || is_absolute_path(arg))
+               return arg;
+       memcpy(path, pfx, pfx_len);
+       strcpy(path + pfx_len, arg);
+#else
+       char *p;
+       /* don't add prefix to absolute paths, but still replace '\' by '/' */
+       if (is_absolute_path(arg))
+               pfx_len = 0;
+       else if (pfx_len)
+               memcpy(path, pfx, pfx_len);
+       strcpy(path + pfx_len, arg);
+       for (p = path + pfx_len; *p; p++)
+               if (*p == '\\')
+                       *p = '/';
+#endif
+       return path;
+}
index 2a7a28e3ed35fe9db03ccf70b71867f7f8a22b8e..3fd7f475f1d8ff5efe602a10f02ea3e1c3aa9edd 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -123,7 +123,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
        path_without_prefix = path.buf + args->baselen;
 
        setup_archive_check(check);
-       if (!git_checkattr(path_without_prefix, ARRAY_SIZE(check), check)) {
+       if (!git_check_attr(path_without_prefix, ARRAY_SIZE(check), check)) {
                if (ATTR_TRUE(check[0].value))
                        return 0;
                convert = ATTR_TRUE(check[1].value);
diff --git a/argv-array.c b/argv-array.c
new file mode 100644 (file)
index 0000000..a4e0420
--- /dev/null
@@ -0,0 +1,51 @@
+#include "cache.h"
+#include "argv-array.h"
+#include "strbuf.h"
+
+static const char *empty_argv_storage = NULL;
+const char **empty_argv = &empty_argv_storage;
+
+void argv_array_init(struct argv_array *array)
+{
+       array->argv = empty_argv;
+       array->argc = 0;
+       array->alloc = 0;
+}
+
+static void argv_array_push_nodup(struct argv_array *array, const char *value)
+{
+       if (array->argv == empty_argv)
+               array->argv = NULL;
+
+       ALLOC_GROW(array->argv, array->argc + 2, array->alloc);
+       array->argv[array->argc++] = value;
+       array->argv[array->argc] = NULL;
+}
+
+void argv_array_push(struct argv_array *array, const char *value)
+{
+       argv_array_push_nodup(array, xstrdup(value));
+}
+
+void argv_array_pushf(struct argv_array *array, const char *fmt, ...)
+{
+       va_list ap;
+       struct strbuf v = STRBUF_INIT;
+
+       va_start(ap, fmt);
+       strbuf_vaddf(&v, fmt, ap);
+       va_end(ap);
+
+       argv_array_push_nodup(array, strbuf_detach(&v, NULL));
+}
+
+void argv_array_clear(struct argv_array *array)
+{
+       if (array->argv != empty_argv) {
+               int i;
+               for (i = 0; i < array->argc; i++)
+                       free((char **)array->argv[i]);
+               free(array->argv);
+       }
+       argv_array_init(array);
+}
diff --git a/argv-array.h b/argv-array.h
new file mode 100644 (file)
index 0000000..74dd2b1
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef ARGV_ARRAY_H
+#define ARGV_ARRAY_H
+
+extern const char **empty_argv;
+
+struct argv_array {
+       const char **argv;
+       int argc;
+       int alloc;
+};
+
+#define ARGV_ARRAY_INIT { empty_argv, 0, 0 }
+
+void argv_array_init(struct argv_array *);
+void argv_array_push(struct argv_array *, const char *);
+__attribute__((format (printf,2,3)))
+void argv_array_pushf(struct argv_array *, const char *fmt, ...);
+void argv_array_clear(struct argv_array *);
+
+#endif /* ARGV_ARRAY_H */
diff --git a/attr.c b/attr.c
index f6b3f7e850f9fcf5672031049ef1d6f43e619f63..76b079f0f530e1372b2866f40cce21ec5266394c 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -1,7 +1,17 @@
+/*
+ * Handle git attributes.  See gitattributes(5) for a description of
+ * the file syntax, and Documentation/technical/api-gitattributes.txt
+ * for a description of the API.
+ *
+ * One basic design decision here is that we are not going to support
+ * an insanely large number of attributes.
+ */
+
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "exec_cmd.h"
 #include "attr.h"
+#include "dir.h"
 
 const char git_attr__true[] = "(builtin)true";
 const char git_attr__false[] = "\0(builtin)false";
@@ -11,14 +21,7 @@ static const char git_attr__unknown[] = "(builtin)unknown";
 #define ATTR__UNSET NULL
 #define ATTR__UNKNOWN git_attr__unknown
 
-static const char *attributes_file;
-
-/*
- * The basic design decision here is that we are not going to have
- * insanely large number of attributes.
- *
- * This is a randomly chosen prime.
- */
+/* This is a randomly chosen prime. */
 #define HASHSIZE 257
 
 #ifndef DEBUG_ATTR
@@ -36,6 +39,11 @@ static int attr_nr;
 static struct git_attr_check *check_all_attr;
 static struct git_attr *(git_attr_hash[HASHSIZE]);
 
+char *git_attr_name(struct git_attr *attr)
+{
+       return attr->name;
+}
+
 static unsigned hash_name(const char *name, int namelen)
 {
        unsigned val = 0, c;
@@ -50,12 +58,10 @@ static unsigned hash_name(const char *name, int namelen)
 static int invalid_attr_name(const char *name, int namelen)
 {
        /*
-        * Attribute name cannot begin with '-' and from
-        * [-A-Za-z0-9_.].  We'd specifically exclude '=' for now,
-        * as we might later want to allow non-binary value for
-        * attributes, e.g. "*.svg      merge=special-merge-program-for-svg"
+        * Attribute name cannot begin with '-' and must consist of
+        * characters from [-A-Za-z0-9_.].
         */
-       if (*name == '-')
+       if (namelen <= 0 || *name == '-')
                return -1;
        while (namelen--) {
                char ch = *name++;
@@ -103,22 +109,26 @@ struct git_attr *git_attr(const char *name)
        return git_attr_internal(name, strlen(name));
 }
 
-/*
- * .gitattributes file is one line per record, each of which is
- *
- * (1) glob pattern.
- * (2) whitespace
- * (3) whitespace separated list of attribute names, each of which
- *     could be prefixed with '-' to mean "set to false", '!' to mean
- *     "unset".
- */
-
 /* What does a matched pattern decide? */
 struct attr_state {
        struct git_attr *attr;
        const char *setto;
 };
 
+/*
+ * One rule, as from a .gitattributes file.
+ *
+ * If is_macro is true, then u.attr is a pointer to the git_attr being
+ * defined.
+ *
+ * If is_macro is false, then u.pattern points at the filename pattern
+ * to which the rule applies.  (The memory pointed to is part of the
+ * memory block allocated for the match_attr instance.)
+ *
+ * In either case, num_attr is the number of attributes affected by
+ * this rule, and state is an array listing them.  The attributes are
+ * listed as they appear in the file (macros unexpanded).
+ */
 struct match_attr {
        union {
                char *pattern;
@@ -131,8 +141,15 @@ struct match_attr {
 
 static const char blank[] = " \t\r\n";
 
+/*
+ * Parse a whitespace-delimited attribute state (i.e., "attr",
+ * "-attr", "!attr", or "attr=value") from the string starting at src.
+ * If e is not NULL, write the results to *e.  Return a pointer to the
+ * remainder of the string (with leading whitespace removed), or NULL
+ * if there was an error.
+ */
 static const char *parse_attr(const char *src, int lineno, const char *cp,
-                             int *num_attr, struct match_attr *res)
+                             struct attr_state *e)
 {
        const char *ep, *equals;
        int len;
@@ -145,7 +162,7 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
                len = equals - cp;
        else
                len = ep - cp;
-       if (!res) {
+       if (!e) {
                if (*cp == '-' || *cp == '!') {
                        cp++;
                        len--;
@@ -157,9 +174,6 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
                        return NULL;
                }
        } else {
-               struct attr_state *e;
-
-               e = &(res->state[*num_attr]);
                if (*cp == '-' || *cp == '!') {
                        e->setto = (*cp == '-') ? ATTR__FALSE : ATTR__UNSET;
                        cp++;
@@ -172,7 +186,6 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
                }
                e->attr = git_attr_internal(cp, len);
        }
-       (*num_attr)++;
        return ep + strspn(ep, blank);
 }
 
@@ -180,10 +193,9 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
                                          int lineno, int macro_ok)
 {
        int namelen;
-       int num_attr;
-       const char *cp, *name;
+       int num_attr, i;
+       const char *cp, *name, *states;
        struct match_attr *res = NULL;
-       int pass;
        int is_macro;
 
        cp = line + strspn(line, blank);
@@ -212,32 +224,35 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
        else
                is_macro = 0;
 
-       for (pass = 0; pass < 2; pass++) {
-               /* pass 0 counts and allocates, pass 1 fills */
-               num_attr = 0;
-               cp = name + namelen;
-               cp = cp + strspn(cp, blank);
-               while (*cp) {
-                       cp = parse_attr(src, lineno, cp, &num_attr, res);
-                       if (!cp)
-                               return NULL;
-               }
-               if (pass)
-                       break;
-               res = xcalloc(1,
-                             sizeof(*res) +
-                             sizeof(struct attr_state) * num_attr +
-                             (is_macro ? 0 : namelen + 1));
-               if (is_macro)
-                       res->u.attr = git_attr_internal(name, namelen);
-               else {
-                       res->u.pattern = (char *)&(res->state[num_attr]);
-                       memcpy(res->u.pattern, name, namelen);
-                       res->u.pattern[namelen] = 0;
-               }
-               res->is_macro = is_macro;
-               res->num_attr = num_attr;
+       states = name + namelen;
+       states += strspn(states, blank);
+
+       /* First pass to count the attr_states */
+       for (cp = states, num_attr = 0; *cp; num_attr++) {
+               cp = parse_attr(src, lineno, cp, NULL);
+               if (!cp)
+                       return NULL;
        }
+
+       res = xcalloc(1,
+                     sizeof(*res) +
+                     sizeof(struct attr_state) * num_attr +
+                     (is_macro ? 0 : namelen + 1));
+       if (is_macro)
+               res->u.attr = git_attr_internal(name, namelen);
+       else {
+               res->u.pattern = (char *)&(res->state[num_attr]);
+               memcpy(res->u.pattern, name, namelen);
+               res->u.pattern[namelen] = 0;
+       }
+       res->is_macro = is_macro;
+       res->num_attr = num_attr;
+
+       /* Second pass to fill the attr_states */
+       for (cp = states, i = 0; *cp; i++) {
+               cp = parse_attr(src, lineno, cp, &(res->state[i]));
+       }
+
        return res;
 }
 
@@ -478,14 +493,6 @@ static int git_attr_system(void)
        return !git_env_bool("GIT_ATTR_NOSYSTEM", 0);
 }
 
-static int git_attr_config(const char *var, const char *value, void *dummy)
-{
-       if (!strcmp(var, "core.attributesfile"))
-               return git_config_pathname(&attributes_file, var, value);
-
-       return 0;
-}
-
 static void bootstrap_attr_stack(void)
 {
        if (!attr_stack) {
@@ -505,9 +512,8 @@ static void bootstrap_attr_stack(void)
                        }
                }
 
-               git_config(git_attr_config, NULL);
-               if (attributes_file) {
-                       elem = read_attr_from_file(attributes_file, 1);
+               if (git_attributes_file) {
+                       elem = read_attr_from_file(git_attributes_file, 1);
                        if (elem) {
                                elem->origin = NULL;
                                elem->prev = attr_stack;
@@ -517,7 +523,7 @@ static void bootstrap_attr_stack(void)
 
                if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
                        elem = read_attr(GITATTRIBUTES_FILE, 1);
-                       elem->origin = strdup("");
+                       elem->origin = xstrdup("");
                        elem->prev = attr_stack;
                        attr_stack = elem;
                        debug_push(elem);
@@ -532,13 +538,17 @@ static void bootstrap_attr_stack(void)
        }
 }
 
-static void prepare_attr_stack(const char *path, int dirlen)
+static void prepare_attr_stack(const char *path)
 {
        struct attr_stack *elem, *info;
-       int len;
-       struct strbuf pathbuf;
+       int dirlen, len;
+       const char *cp;
 
-       strbuf_init(&pathbuf, dirlen+2+strlen(GITATTRIBUTES_FILE));
+       cp = strrchr(path, '/');
+       if (!cp)
+               dirlen = 0;
+       else
+               dirlen = cp - path;
 
        /*
         * At the bottom of the attribute stack is the built-in
@@ -555,8 +565,7 @@ static void prepare_attr_stack(const char *path, int dirlen)
         * .gitattributes in deeper directories to shallower ones,
         * and finally use the built-in set as the default.
         */
-       if (!attr_stack)
-               bootstrap_attr_stack();
+       bootstrap_attr_stack();
 
        /*
         * Pop the "info" one that is always at the top of the stack.
@@ -585,27 +594,28 @@ static void prepare_attr_stack(const char *path, int dirlen)
         * Read from parent directories and push them down
         */
        if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
-               while (1) {
-                       char *cp;
+               struct strbuf pathbuf = STRBUF_INIT;
 
+               while (1) {
                        len = strlen(attr_stack->origin);
                        if (dirlen <= len)
                                break;
-                       strbuf_reset(&pathbuf);
-                       strbuf_add(&pathbuf, path, dirlen);
+                       cp = memchr(path + len + 1, '/', dirlen - len - 1);
+                       if (!cp)
+                               cp = path + dirlen;
+                       strbuf_add(&pathbuf, path, cp - path);
                        strbuf_addch(&pathbuf, '/');
-                       cp = strchr(pathbuf.buf + len + 1, '/');
-                       strcpy(cp + 1, GITATTRIBUTES_FILE);
+                       strbuf_addstr(&pathbuf, GITATTRIBUTES_FILE);
                        elem = read_attr(pathbuf.buf, 0);
-                       *cp = '\0';
-                       elem->origin = strdup(pathbuf.buf);
+                       strbuf_setlen(&pathbuf, cp - path);
+                       elem->origin = strbuf_detach(&pathbuf, NULL);
                        elem->prev = attr_stack;
                        attr_stack = elem;
                        debug_push(elem);
                }
-       }
 
-       strbuf_release(&pathbuf);
+               strbuf_release(&pathbuf);
+       }
 
        /*
         * Finally push the "info" one at the top of the stack.
@@ -622,7 +632,7 @@ static int path_matches(const char *pathname, int pathlen,
                /* match basename */
                const char *basename = strrchr(pathname, '/');
                basename = basename ? basename + 1 : pathname;
-               return (fnmatch(pattern, basename, 0) == 0);
+               return (fnmatch_icase(pattern, basename, 0) == 0);
        }
        /*
         * match with FNM_PATHNAME; the pattern has base implicitly
@@ -636,7 +646,7 @@ static int path_matches(const char *pathname, int pathlen,
                return 0;
        if (baselen != 0)
                baselen++;
-       return fnmatch(pattern, pathname + baselen, FNM_PATHNAME) == 0;
+       return fnmatch_icase(pattern, pathname + baselen, FNM_PATHNAME) == 0;
 }
 
 static int macroexpand_one(int attr_nr, int rem);
@@ -703,26 +713,30 @@ static int macroexpand_one(int attr_nr, int rem)
        return rem;
 }
 
-int git_checkattr(const char *path, int num, struct git_attr_check *check)
+/*
+ * Collect all attributes for path into the array pointed to by
+ * check_all_attr.
+ */
+static void collect_all_attrs(const char *path)
 {
        struct attr_stack *stk;
-       const char *cp;
-       int dirlen, pathlen, i, rem;
+       int i, pathlen, rem;
 
-       bootstrap_attr_stack();
+       prepare_attr_stack(path);
        for (i = 0; i < attr_nr; i++)
                check_all_attr[i].value = ATTR__UNKNOWN;
 
        pathlen = strlen(path);
-       cp = strrchr(path, '/');
-       if (!cp)
-               dirlen = 0;
-       else
-               dirlen = cp - path;
-       prepare_attr_stack(path, dirlen);
        rem = attr_nr;
        for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
                rem = fill(path, pathlen, stk, rem);
+}
+
+int git_check_attr(const char *path, int num, struct git_attr_check *check)
+{
+       int i;
+
+       collect_all_attrs(path);
 
        for (i = 0; i < num; i++) {
                const char *value = check_all_attr[check[i].attr->attr_nr].value;
@@ -734,6 +748,34 @@ int git_checkattr(const char *path, int num, struct git_attr_check *check)
        return 0;
 }
 
+int git_all_attrs(const char *path, int *num, struct git_attr_check **check)
+{
+       int i, count, j;
+
+       collect_all_attrs(path);
+
+       /* Count the number of attributes that are set. */
+       count = 0;
+       for (i = 0; i < attr_nr; i++) {
+               const char *value = check_all_attr[i].value;
+               if (value != ATTR__UNSET && value != ATTR__UNKNOWN)
+                       ++count;
+       }
+       *num = count;
+       *check = xmalloc(sizeof(**check) * count);
+       j = 0;
+       for (i = 0; i < attr_nr; i++) {
+               const char *value = check_all_attr[i].value;
+               if (value != ATTR__UNSET && value != ATTR__UNKNOWN) {
+                       (*check)[j].attr = check_all_attr[i].attr;
+                       (*check)[j].value = value;
+                       ++j;
+               }
+       }
+
+       return 0;
+}
+
 void git_attr_set_direction(enum git_attr_direction new, struct index_state *istate)
 {
        enum git_attr_direction old = direction;
diff --git a/attr.h b/attr.h
index 8b3f19be67f17c1fbf6edb37ac3ea27002ca6415..eb8ca0d7c067417a8ff2802179e50bddcdff3367 100644 (file)
--- a/attr.h
+++ b/attr.h
@@ -20,7 +20,7 @@ extern const char git_attr__false[];
 #define ATTR_UNSET(v) ((v) == NULL)
 
 /*
- * Send one or more git_attr_check to git_checkattr(), and
+ * Send one or more git_attr_check to git_check_attr(), and
  * each 'value' member tells what its value is.
  * Unset one is returned as NULL.
  */
@@ -29,7 +29,23 @@ struct git_attr_check {
        const char *value;
 };
 
-int git_checkattr(const char *path, int, struct git_attr_check *);
+/*
+ * Return the name of the attribute represented by the argument.  The
+ * return value is a pointer to a null-delimited string that is part
+ * of the internal data structure; it should not be modified or freed.
+ */
+char *git_attr_name(struct git_attr *);
+
+int git_check_attr(const char *path, int, struct git_attr_check *);
+
+/*
+ * Retrieve all attributes that apply to the specified path.  *num
+ * will be set the the number of attributes on the path; **check will
+ * be set to point at a newly-allocated array of git_attr_check
+ * objects describing the attributes and their values.  *check must be
+ * free()ed by the caller.
+ */
+int git_all_attrs(const char *path, int *num, struct git_attr_check **check);
 
 enum git_attr_direction {
        GIT_ATTR_CHECKIN,
index c7b7d7913dc444926b0260211e8bc3aa75eeffdb..de05bf824620324e42b7a27571ecd3e763cf7e8f 100644 (file)
--- a/bisect.c
+++ b/bisect.c
 #include "log-tree.h"
 #include "bisect.h"
 #include "sha1-array.h"
+#include "argv-array.h"
 
 static struct sha1_array good_revs;
 static struct sha1_array skipped_revs;
 
 static const unsigned char *current_bad_sha1;
 
-struct argv_array {
-       const char **argv;
-       int argv_nr;
-       int argv_alloc;
-};
-
 static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
 static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
 static const char *argv_update_ref[] = {"update-ref", "--no-deref", "BISECT_HEAD", NULL, NULL};
@@ -405,21 +400,6 @@ struct commit_list *find_bisection(struct commit_list *list,
        return best;
 }
 
-static void argv_array_push(struct argv_array *array, const char *string)
-{
-       ALLOC_GROW(array->argv, array->argv_nr + 1, array->argv_alloc);
-       array->argv[array->argv_nr++] = string;
-}
-
-static void argv_array_push_sha1(struct argv_array *array,
-                                const unsigned char *sha1,
-                                const char *format)
-{
-       struct strbuf buf = STRBUF_INIT;
-       strbuf_addf(&buf, format, sha1_to_hex(sha1));
-       argv_array_push(array, strbuf_detach(&buf, NULL));
-}
-
 static int register_ref(const char *refname, const unsigned char *sha1,
                        int flags, void *cb_data)
 {
@@ -449,16 +429,10 @@ static void read_bisect_paths(struct argv_array *array)
                die_errno("Could not open file '%s'", filename);
 
        while (strbuf_getline(&str, fp, '\n') != EOF) {
-               char *quoted;
-               int res;
-
                strbuf_trim(&str);
-               quoted = strbuf_detach(&str, NULL);
-               res = sq_dequote_to_argv(quoted, &array->argv,
-                                        &array->argv_nr, &array->argv_alloc);
-               if (res)
+               if (sq_dequote_to_argv_array(str.buf, array))
                        die("Badly quoted content in file '%s': %s",
-                           filename, quoted);
+                           filename, str.buf);
        }
 
        strbuf_release(&str);
@@ -623,7 +597,7 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
                             const char *bad_format, const char *good_format,
                             int read_paths)
 {
-       struct argv_array rev_argv = { NULL, 0, 0 };
+       struct argv_array rev_argv = ARGV_ARRAY_INIT;
        int i;
 
        init_revisions(revs, prefix);
@@ -631,17 +605,17 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
        revs->commit_format = CMIT_FMT_UNSPECIFIED;
 
        /* rev_argv.argv[0] will be ignored by setup_revisions */
-       argv_array_push(&rev_argv, xstrdup("bisect_rev_setup"));
-       argv_array_push_sha1(&rev_argv, current_bad_sha1, bad_format);
+       argv_array_push(&rev_argv, "bisect_rev_setup");
+       argv_array_pushf(&rev_argv, bad_format, sha1_to_hex(current_bad_sha1));
        for (i = 0; i < good_revs.nr; i++)
-               argv_array_push_sha1(&rev_argv, good_revs.sha1[i],
-                                    good_format);
-       argv_array_push(&rev_argv, xstrdup("--"));
+               argv_array_pushf(&rev_argv, good_format,
+                                sha1_to_hex(good_revs.sha1[i]));
+       argv_array_push(&rev_argv, "--");
        if (read_paths)
                read_bisect_paths(&rev_argv);
-       argv_array_push(&rev_argv, NULL);
 
-       setup_revisions(rev_argv.argv_nr, rev_argv.argv, revs, NULL);
+       setup_revisions(rev_argv.argc, rev_argv.argv, revs, NULL);
+       /* XXX leak rev_argv, as "revs" may still be pointing to it */
 }
 
 static void bisect_common(struct rev_info *revs)
index c0c865a4b1b0fca038f32b77f2239d7987438ff5..fecedd3b4635c79adcbe0e26613af079beff64d0 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -135,6 +135,28 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
        return 0;
 }
 
+int validate_new_branchname(const char *name, struct strbuf *ref,
+                           int force, int attr_only)
+{
+       if (strbuf_check_branch_ref(ref, name))
+               die("'%s' is not a valid branch name.", name);
+
+       if (!ref_exists(ref->buf))
+               return 0;
+       else if (!force && !attr_only)
+               die("A branch named '%s' already exists.", ref->buf + strlen("refs/heads/"));
+
+       if (!attr_only) {
+               const char *head;
+               unsigned char sha1[20];
+
+               head = resolve_ref("HEAD", sha1, 0, NULL);
+               if (!is_bare_repository() && head && !strcmp(head, ref->buf))
+                       die("Cannot force update the current branch.");
+       }
+       return 1;
+}
+
 void create_branch(const char *head,
                   const char *name, const char *start_name,
                   int force, int reflog, enum branch_track track)
@@ -151,17 +173,12 @@ void create_branch(const char *head,
        if (track == BRANCH_TRACK_EXPLICIT || track == BRANCH_TRACK_OVERRIDE)
                explicit_tracking = 1;
 
-       if (strbuf_check_branch_ref(&ref, name))
-               die("'%s' is not a valid branch name.", name);
-
-       if (resolve_ref(ref.buf, sha1, 1, NULL)) {
-               if (!force && track == BRANCH_TRACK_OVERRIDE)
+       if (validate_new_branchname(name, &ref, force,
+                                   track == BRANCH_TRACK_OVERRIDE)) {
+               if (!force)
                        dont_change_ref = 1;
-               else if (!force)
-                       die("A branch named '%s' already exists.", name);
-               else if (!is_bare_repository() && head && !strcmp(head, name))
-                       die("Cannot force update the current branch.");
-               forcing = 1;
+               else
+                       forcing = 1;
        }
 
        real_ref = NULL;
@@ -210,7 +227,7 @@ void create_branch(const char *head,
                         start_name);
 
        if (real_ref && track)
-               setup_tracking(name, real_ref, track);
+               setup_tracking(ref.buf+11, real_ref, track);
 
        if (!dont_change_ref)
                if (write_ref_sha1(lock, sha1, msg) < 0)
index 4026e3832b265c4cef6e5bc151976771867b3da9..1285158dd4f26e5bbb0e0d7133055f168fee773f 100644 (file)
--- a/branch.h
+++ b/branch.h
 void create_branch(const char *head, const char *name, const char *start_name,
                   int force, int reflog, enum branch_track track);
 
+/*
+ * Validates that the requested branch may be created, returning the
+ * interpreted ref in ref, force indicates whether (non-head) branches
+ * may be overwritten. A non-zero return value indicates that the force
+ * parameter was non-zero and the branch already exists.
+ *
+ * Contrary to all of the above, when attr_only is 1, the caller is
+ * not interested in verifying if it is Ok to update the named
+ * branch to point at a potentially different commit. It is merely
+ * asking if it is OK to change some attribute for the named branch
+ * (e.g. tracking upstream).
+ *
+ * NEEDSWORK: This needs to be split into two separate functions in the
+ * longer run for sanity.
+ *
+ */
+int validate_new_branchname(const char *name, struct strbuf *ref, int force, int attr_only);
+
 /*
  * Remove information about the state of working on the current
  * branch. (E.g., MERGE_HEAD)
index f2edc52818e817e83717f992a6bbd66dad4ef24d..311a94e18195c611b55de7d1619da890aca240af 100644 (file)
@@ -1407,6 +1407,9 @@ static int find_header(char *line, unsigned long size, int *hdrsize, struct patc
                                            "%d leading pathname components (line %d)" , p_value, linenr);
                                patch->old_name = patch->new_name = patch->def_name;
                        }
+                       if (!patch->is_delete && !patch->new_name)
+                               die("git diff header lacks filename information "
+                                   "(line %d)", linenr);
                        patch->is_toplevel_relative = 1;
                        *hdrsize = git_hdr_len;
                        return offset;
@@ -2447,6 +2450,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
        char *old, *oldlines;
        struct strbuf newlines;
        int new_blank_lines_at_end = 0;
+       int found_new_blank_lines_at_end = 0;
+       int hunk_linenr = frag->linenr;
        unsigned long leading, trailing;
        int pos, applied_pos;
        struct image preimage;
@@ -2540,14 +2545,18 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
                                error("invalid start of line: '%c'", first);
                        return -1;
                }
-               if (added_blank_line)
+               if (added_blank_line) {
+                       if (!new_blank_lines_at_end)
+                               found_new_blank_lines_at_end = hunk_linenr;
                        new_blank_lines_at_end++;
+               }
                else if (is_blank_context)
                        ;
                else
                        new_blank_lines_at_end = 0;
                patch += len;
                size -= len;
+               hunk_linenr++;
        }
        if (inaccurate_eof &&
            old > oldlines && old[-1] == '\n' &&
@@ -2629,7 +2638,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
                    preimage.nr + applied_pos >= img->nr &&
                    (ws_rule & WS_BLANK_AT_EOF) &&
                    ws_error_action != nowarn_ws_error) {
-                       record_ws_error(WS_BLANK_AT_EOF, "+", 1, frag->linenr);
+                       record_ws_error(WS_BLANK_AT_EOF, "+", 1,
+                                       found_new_blank_lines_at_end);
                        if (ws_error_action == correct_ws_error) {
                                while (new_blank_lines_at_end--)
                                        remove_last_line(&postimage);
index 883c0092ad43d602136e68d2afde8e319a904676..931956def986bbdf5b77e163f1b18c961e7be09c 100644 (file)
@@ -61,6 +61,8 @@ static int run_remote_archiver(int argc, const char **argv,
        if (strcmp(buf, "ACK")) {
                if (len > 5 && !prefixcmp(buf, "NACK "))
                        die(_("git archive: NACK %s"), buf + 5);
+               if (len > 4 && !prefixcmp(buf, "ERR "))
+                       die(_("remote error: %s"), buf + 4);
                die(_("git archive: protocol error"));
        }
 
index 3142daa57a6fa1c8a7d21095946bf5d26443d0e0..f49596f826228e22d354194ddbb73ec100d8728e 100644 (file)
@@ -71,7 +71,7 @@ static int parse_branch_color_slot(const char *var, int ofs)
 static int git_branch_config(const char *var, const char *value, void *cb)
 {
        if (!strcmp(var, "color.branch")) {
-               branch_use_color = git_config_colorbool(var, value, -1);
+               branch_use_color = git_config_colorbool(var, value);
                return 0;
        }
        if (!prefixcmp(var, "color.branch.")) {
@@ -88,7 +88,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
 
 static const char *branch_get_color(enum color_branch ix)
 {
-       if (branch_use_color > 0)
+       if (want_color(branch_use_color))
                return branch_colors[ix];
        return "";
 }
@@ -566,11 +566,7 @@ static void rename_branch(const char *oldname, const char *newname, int force)
                        die(_("Invalid branch name: '%s'"), oldname);
        }
 
-       if (strbuf_check_branch_ref(&newref, newname))
-               die(_("Invalid branch name: '%s'"), newname);
-
-       if (resolve_ref(newref.buf, sha1, 1, NULL) && !force)
-               die(_("A branch named '%s' already exists."), newref.buf + 11);
+       validate_new_branchname(newname, &newref, force, 0);
 
        strbuf_addf(&logmsg, "Branch: renamed %s to %s",
                 oldref.buf, newref.buf);
@@ -613,7 +609,7 @@ static int opt_parse_merge_filter(const struct option *opt, const char *arg, int
 int cmd_branch(int argc, const char **argv, const char *prefix)
 {
        int delete = 0, rename = 0, force_create = 0;
-       int verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;
+       int verbose = 0, abbrev = -1, detached = 0;
        int reflog = 0;
        enum branch_track track;
        int kinds = REF_LOCAL_BRANCH;
@@ -673,9 +669,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 
        git_config(git_branch_config, NULL);
 
-       if (branch_use_color == -1)
-               branch_use_color = git_use_color_default;
-
        track = git_branch_track;
 
        head = resolve_ref("HEAD", head_sha1, 0, NULL);
@@ -696,6 +689,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
        if (!!delete + !!rename + !!force_create > 1)
                usage_with_options(builtin_branch_usage, options);
 
+       if (abbrev == -1)
+               abbrev = DEFAULT_ABBREV;
+
        if (delete)
                return delete_branches(argc, argv, delete > 1, kinds);
        else if (argc == 0)
index 81046a9cb870aab59a56492e175a51c032ad96ce..92a8a6026a9bd6da5394e7b37f07dbe91f73db9c 100644 (file)
@@ -58,7 +58,7 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
        } else if (!strcmp(cmd, "unbundle")) {
                if (!startup_info->have_repository)
                        die(_("Need a repository to unbundle."));
-               return !!unbundle(&header, bundle_fd) ||
+               return !!unbundle(&header, bundle_fd, 0) ||
                        list_bundle_refs(&header, argc, argv);
        } else
                usage(builtin_bundle_usage);
index 3016d29caa610caf4618e9bc1684a532fd3a18a1..abb11650fdd936d01210552b68739f2bff82ed06 100644 (file)
@@ -4,28 +4,28 @@
 #include "quote.h"
 #include "parse-options.h"
 
+static int all_attrs;
 static int stdin_paths;
 static const char * const check_attr_usage[] = {
-"git check-attr attr... [--] pathname...",
-"git check-attr --stdin attr... < <list-of-paths>",
+"git check-attr [-a | --all | attr...] [--] pathname...",
+"git check-attr --stdin [-a | --all | attr...] < <list-of-paths>",
 NULL
 };
 
 static int null_term_line;
 
 static const struct option check_attr_options[] = {
+       OPT_BOOLEAN('a', "all", &all_attrs, "report all attributes set on file"),
        OPT_BOOLEAN(0 , "stdin", &stdin_paths, "read file names from stdin"),
        OPT_BOOLEAN('z', NULL, &null_term_line,
                "input paths are terminated by a null character"),
        OPT_END()
 };
 
-static void check_attr(int cnt, struct git_attr_check *check,
-       const char** name, const char *file)
+static void output_attr(int cnt, struct git_attr_check *check,
+       const char *file)
 {
        int j;
-       if (git_checkattr(file, cnt, check))
-               die("git_checkattr died");
        for (j = 0; j < cnt; j++) {
                const char *value = check[j].value;
 
@@ -37,12 +37,30 @@ static void check_attr(int cnt, struct git_attr_check *check,
                        value = "unspecified";
 
                quote_c_style(file, NULL, stdout, 0);
-               printf(": %s: %s\n", name[j], value);
+               printf(": %s: %s\n", git_attr_name(check[j].attr), value);
        }
 }
 
-static void check_attr_stdin_paths(int cnt, struct git_attr_check *check,
-       const char** name)
+static void check_attr(const char *prefix, int cnt,
+       struct git_attr_check *check, const char *file)
+{
+       char *full_path =
+               prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
+       if (check != NULL) {
+               if (git_check_attr(full_path, cnt, check))
+                       die("git_check_attr died");
+               output_attr(cnt, check, file);
+       } else {
+               if (git_all_attrs(full_path, &cnt, &check))
+                       die("git_all_attrs died");
+               output_attr(cnt, check, file);
+               free(check);
+       }
+       free(full_path);
+}
+
+static void check_attr_stdin_paths(const char *prefix, int cnt,
+       struct git_attr_check *check)
 {
        struct strbuf buf, nbuf;
        int line_termination = null_term_line ? 0 : '\n';
@@ -56,23 +74,28 @@ static void check_attr_stdin_paths(int cnt, struct git_attr_check *check,
                                die("line is badly quoted");
                        strbuf_swap(&buf, &nbuf);
                }
-               check_attr(cnt, check, name, buf.buf);
+               check_attr(prefix, cnt, check, buf.buf);
                maybe_flush_or_die(stdout, "attribute to stdout");
        }
        strbuf_release(&buf);
        strbuf_release(&nbuf);
 }
 
+static NORETURN void error_with_usage(const char *msg)
+{
+       error("%s", msg);
+       usage_with_options(check_attr_usage, check_attr_options);
+}
+
 int cmd_check_attr(int argc, const char **argv, const char *prefix)
 {
        struct git_attr_check *check;
-       int cnt, i, doubledash;
-       const char *errstr = NULL;
+       int cnt, i, doubledash, filei;
+
+       git_config(git_default_config, NULL);
 
        argc = parse_options(argc, argv, prefix, check_attr_options,
                             check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
-       if (!argc)
-               usage_with_options(check_attr_usage, check_attr_options);
 
        if (read_cache() < 0) {
                die("invalid cache");
@@ -84,39 +107,63 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
                        doubledash = i;
        }
 
-       /* If there is no double dash, we handle only one attribute */
-       if (doubledash < 0) {
-               cnt = 1;
-               doubledash = 0;
-       } else
+       /* Process --all and/or attribute arguments: */
+       if (all_attrs) {
+               if (doubledash >= 1)
+                       error_with_usage("Attributes and --all both specified");
+
+               cnt = 0;
+               filei = doubledash + 1;
+       } else if (doubledash == 0) {
+               error_with_usage("No attribute specified");
+       } else if (doubledash < 0) {
+               if (!argc)
+                       error_with_usage("No attribute specified");
+
+               if (stdin_paths) {
+                       /* Treat all arguments as attribute names. */
+                       cnt = argc;
+                       filei = argc;
+               } else {
+                       /* Treat exactly one argument as an attribute name. */
+                       cnt = 1;
+                       filei = 1;
+               }
+       } else {
                cnt = doubledash;
-       doubledash++;
-
-       if (cnt <= 0)
-               errstr = "No attribute specified";
-       else if (stdin_paths && doubledash < argc)
-               errstr = "Can't specify files with --stdin";
-       if (errstr) {
-               error("%s", errstr);
-               usage_with_options(check_attr_usage, check_attr_options);
+               filei = doubledash + 1;
        }
 
-       check = xcalloc(cnt, sizeof(*check));
-       for (i = 0; i < cnt; i++) {
-               const char *name;
-               struct git_attr *a;
-               name = argv[i];
-               a = git_attr(name);
-               if (!a)
-                       return error("%s: not a valid attribute name", name);
-               check[i].attr = a;
+       /* Check file argument(s): */
+       if (stdin_paths) {
+               if (filei < argc)
+                       error_with_usage("Can't specify files with --stdin");
+       } else {
+               if (filei >= argc)
+                       error_with_usage("No file specified");
+       }
+
+       if (all_attrs) {
+               check = NULL;
+       } else {
+               check = xcalloc(cnt, sizeof(*check));
+               for (i = 0; i < cnt; i++) {
+                       const char *name;
+                       struct git_attr *a;
+                       name = argv[i];
+                       a = git_attr(name);
+                       if (!a)
+                               return error("%s: not a valid attribute name",
+                                       name);
+                       check[i].attr = a;
+               }
        }
 
        if (stdin_paths)
-               check_attr_stdin_paths(cnt, check, argv);
+               check_attr_stdin_paths(prefix, cnt, check);
        else {
-               for (i = doubledash; i < argc; i++)
-                       check_attr(cnt, check, argv, argv[i]);
+               for (i = filei; i < argc; i++)
+                       check_attr(prefix, cnt, check, argv[i]);
                maybe_flush_or_die(stdout, "attribute to stdout");
        }
        return 0;
index ae3f28115a7a4d65d8bb6f284cd1ececa4f9c2ef..0723cf245e52e6c0ab99cbe92c74010f9f7d7167 100644 (file)
@@ -12,8 +12,8 @@ static const char builtin_check_ref_format_usage[] =
 "   or: git check-ref-format --branch <branchname-shorthand>";
 
 /*
- * Replace each run of adjacent slashes in src with a single slash,
- * and write the result to dst.
+ * Remove leading slashes and replace each run of adjacent slashes in
+ * src with a single slash, and write the result to dst.
  *
  * This function is similar to normalize_path_copy(), but stripped down
  * to meet check_ref_format's simpler needs.
@@ -21,7 +21,7 @@ static const char builtin_check_ref_format_usage[] =
 static void collapse_slashes(char *dst, const char *src)
 {
        char ch;
-       char prev = '\0';
+       char prev = '/';
 
        while ((ch = *src++) != '\0') {
                if (prev == '/' && ch == prev)
index f1fec24745a854e77555a1b4bea3bc8d7ab04367..c16d82b7de652026b70fc3d949ddc849f749eee8 100644 (file)
@@ -3,38 +3,6 @@
  *
  * Copyright (C) 2005 Linus Torvalds
  *
- * Careful: order of argument flags does matter. For example,
- *
- *     git checkout-index -a -f file.c
- *
- * Will first check out all files listed in the cache (but not
- * overwrite any old ones), and then force-checkout "file.c" a
- * second time (ie that one _will_ overwrite any old contents
- * with the same filename).
- *
- * Also, just doing "git checkout-index" does nothing. You probably
- * meant "git checkout-index -a". And if you want to force it, you
- * want "git checkout-index -f -a".
- *
- * Intuitiveness is not the goal here. Repeatability is. The
- * reason for the "no arguments means no work" thing is that
- * from scripts you are supposed to be able to do things like
- *
- *     find . -name '*.h' -print0 | xargs -0 git checkout-index -f --
- *
- * or:
- *
- *     find . -name '*.h' -print0 | git checkout-index -f -z --stdin
- *
- * which will force all existing *.h files to be replaced with
- * their cached copies. If an empty command line implied "all",
- * then this would force-refresh everything in the cache, which
- * was not the point.
- *
- * Oh, and the "--" is just a good idea when you know the rest
- * will be filenames. Just so that you wouldn't have a filename
- * of "-a" causing problems (not possible in the above example,
- * but get used to it in scripting!).
  */
 #include "builtin.h"
 #include "cache.h"
index d647a313036df65d928d028463564b5390756901..a7a493cecf08b20f32e4161dd5009fd2c3b97448 100644 (file)
@@ -19,6 +19,7 @@
 #include "ll-merge.h"
 #include "resolve-undo.h"
 #include "submodule.h"
+#include "argv-array.h"
 
 static const char * const checkout_usage[] = {
        "git checkout [options] <branch>",
@@ -71,7 +72,7 @@ static int update_some(const unsigned char *sha1, const char *base, int baselen,
        hashcpy(ce->sha1, sha1);
        memcpy(ce->name, base, baselen);
        memcpy(ce->name + baselen, pathname, len - baselen);
-       ce->ce_flags = create_ce_flags(len, 0);
+       ce->ce_flags = create_ce_flags(len, 0) | CE_UPDATE;
        ce->ce_mode = create_ce_mode(mode);
        add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
        return 0;
@@ -201,7 +202,7 @@ static int checkout_merged(int pos, struct checkout *state)
 }
 
 static int checkout_paths(struct tree *source_tree, const char **pathspec,
-                         struct checkout_opts *opts)
+                         const char *prefix, struct checkout_opts *opts)
 {
        int pos;
        struct checkout state;
@@ -228,10 +229,12 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
 
        for (pos = 0; pos < active_nr; pos++) {
                struct cache_entry *ce = active_cache[pos];
+               if (source_tree && !(ce->ce_flags & CE_UPDATE))
+                       continue;
                match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, ps_matched);
        }
 
-       if (report_path_error(ps_matched, pathspec, 0))
+       if (report_path_error(ps_matched, pathspec, prefix))
                return 1;
 
        /* "checkout -m path" to recreate conflicted state */
@@ -266,6 +269,8 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
        state.refresh_cache = 1;
        for (pos = 0; pos < active_nr; pos++) {
                struct cache_entry *ce = active_cache[pos];
+               if (source_tree && !(ce->ce_flags & CE_UPDATE))
+                       continue;
                if (match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) {
                        if (!ce_stage(ce)) {
                                errs |= checkout_entry(ce, &state, NULL);
@@ -588,24 +593,12 @@ static void update_refs_for_switch(struct checkout_opts *opts,
                report_tracking(new);
 }
 
-struct rev_list_args {
-       int argc;
-       int alloc;
-       const char **argv;
-};
-
-static void add_one_rev_list_arg(struct rev_list_args *args, const char *s)
-{
-       ALLOC_GROW(args->argv, args->argc + 1, args->alloc);
-       args->argv[args->argc++] = s;
-}
-
 static int add_one_ref_to_rev_list_arg(const char *refname,
                                       const unsigned char *sha1,
                                       int flags,
                                       void *cb_data)
 {
-       add_one_rev_list_arg(cb_data, refname);
+       argv_array_push(cb_data, refname);
        return 0;
 }
 
@@ -685,15 +678,14 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
  */
 static void orphaned_commit_warning(struct commit *commit)
 {
-       struct rev_list_args args = { 0, 0, NULL };
+       struct argv_array args = ARGV_ARRAY_INIT;
        struct rev_info revs;
 
-       add_one_rev_list_arg(&args, "(internal)");
-       add_one_rev_list_arg(&args, sha1_to_hex(commit->object.sha1));
-       add_one_rev_list_arg(&args, "--not");
+       argv_array_push(&args, "(internal)");
+       argv_array_push(&args, sha1_to_hex(commit->object.sha1));
+       argv_array_push(&args, "--not");
        for_each_ref(add_one_ref_to_rev_list_arg, &args);
-       add_one_rev_list_arg(&args, "--");
-       add_one_rev_list_arg(&args, NULL);
+       argv_array_push(&args, "--");
 
        init_revisions(&revs, NULL);
        if (setup_revisions(args.argc - 1, args.argv, &revs, NULL) != 1)
@@ -705,6 +697,7 @@ static void orphaned_commit_warning(struct commit *commit)
        else
                describe_detached_head(_("Previous HEAD position was"), commit);
 
+       argv_array_clear(&args);
        clear_commit_marks(commit, -1);
        for_each_ref(clear_commit_marks_from_one_ref, NULL);
 }
@@ -1064,7 +1057,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                if (1 < !!opts.writeout_stage + !!opts.force + !!opts.merge)
                        die(_("git checkout: --ours/--theirs, --force and --merge are incompatible when\nchecking out of the index."));
 
-               return checkout_paths(source_tree, pathspec, &opts);
+               return checkout_paths(source_tree, pathspec, prefix, &opts);
        }
 
        if (patch_mode)
@@ -1072,15 +1065,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 
        if (opts.new_branch) {
                struct strbuf buf = STRBUF_INIT;
-               if (strbuf_check_branch_ref(&buf, opts.new_branch))
-                       die(_("git checkout: we do not like '%s' as a branch name."),
-                           opts.new_branch);
-               if (ref_exists(buf.buf)) {
-                       opts.branch_exists = 1;
-                       if (!opts.new_branch_force)
-                               die(_("git checkout: branch %s already exists"),
-                                   opts.new_branch);
-               }
+
+               opts.branch_exists = validate_new_branchname(opts.new_branch, &buf,
+                                                            !!opts.new_branch_force, 0);
+
                strbuf_release(&buf);
        }
 
index 75697f711116e42df1e21e608c21829f49549b08..0c7b3d0f4c28c9e9c721c961e529196751271d11 100644 (file)
@@ -54,7 +54,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
                OPT_BOOLEAN('d', NULL, &remove_directories,
                                "remove whole directories"),
                { OPTION_CALLBACK, 'e', "exclude", &exclude_list, "pattern",
-                 "exclude <pattern>", PARSE_OPT_NONEG, exclude_cb },
+                 "add <pattern> to ignore rules", PARSE_OPT_NONEG, exclude_cb },
                OPT_BOOLEAN('x', NULL, &ignored, "remove ignored files, too"),
                OPT_BOOLEAN('X', NULL, &ignored_only,
                                "remove only ignored files"),
@@ -98,7 +98,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
                setup_standard_excludes(&dir);
 
        for (i = 0; i < exclude_list.nr; i++)
-               add_exclude(exclude_list.items[i].string, "", 0, dir.exclude_list);
+               add_exclude(exclude_list.items[i].string, "", 0,
+                           &dir.exclude_list[EXC_CMDL]);
 
        pathspec = get_pathspec(prefix, argv);
 
index a15784a7b8406be3ead20839aab0f8de2cc52f3d..efe8b6cce5a9f2ae40c6f69755debecfb6b501ca 100644 (file)
@@ -39,7 +39,7 @@ static const char * const builtin_clone_usage[] = {
 
 static int option_no_checkout, option_bare, option_mirror;
 static int option_local, option_no_hardlinks, option_shared, option_recursive;
-static char *option_template, *option_reference, *option_depth;
+static char *option_template, *option_depth;
 static char *option_origin = NULL;
 static char *option_branch = NULL;
 static const char *real_git_dir;
@@ -47,6 +47,16 @@ static char *option_upload_pack = "git-upload-pack";
 static int option_verbosity;
 static int option_progress;
 static struct string_list option_config;
+static struct string_list option_reference;
+
+static int opt_parse_reference(const struct option *opt, const char *arg, int unset)
+{
+       struct string_list *option_reference = opt->value;
+       if (!arg)
+               return -1;
+       string_list_append(option_reference, arg);
+       return 0;
+}
 
 static struct option builtin_clone_options[] = {
        OPT__VERBOSITY(&option_verbosity),
@@ -72,8 +82,8 @@ static struct option builtin_clone_options[] = {
                    "initialize submodules in the clone"),
        OPT_STRING(0, "template", &option_template, "template-directory",
                   "directory from which templates will be used"),
-       OPT_STRING(0, "reference", &option_reference, "repo",
-                  "reference repository"),
+       OPT_CALLBACK(0 , "reference", &option_reference, "repo",
+                    "reference repository", &opt_parse_reference),
        OPT_STRING('o', "origin", &option_origin, "branch",
                   "use <branch> instead of 'origin' to track upstream"),
        OPT_STRING('b', "branch", &option_branch, "branch",
@@ -103,9 +113,26 @@ static char *get_repo_path(const char *repo, int *is_bundle)
        for (i = 0; i < ARRAY_SIZE(suffix); i++) {
                const char *path;
                path = mkpath("%s%s", repo, suffix[i]);
-               if (is_directory(path)) {
+               if (stat(path, &st))
+                       continue;
+               if (S_ISDIR(st.st_mode)) {
                        *is_bundle = 0;
                        return xstrdup(absolute_path(path));
+               } else if (S_ISREG(st.st_mode) && st.st_size > 8) {
+                       /* Is it a "gitfile"? */
+                       char signature[8];
+                       int len, fd = open(path, O_RDONLY);
+                       if (fd < 0)
+                               continue;
+                       len = read_in_full(fd, signature, 8);
+                       close(fd);
+                       if (len != 8 || strncmp(signature, "gitdir: ", 8))
+                               continue;
+                       path = read_gitfile(path);
+                       if (path) {
+                               *is_bundle = 0;
+                               return xstrdup(absolute_path(path));
+                       }
                }
        }
 
@@ -199,39 +226,80 @@ static void strip_trailing_slashes(char *dir)
        *end = '\0';
 }
 
-static void setup_reference(const char *repo)
+static int add_one_reference(struct string_list_item *item, void *cb_data)
 {
-       const char *ref_git;
-       char *ref_git_copy;
-
+       char *ref_git;
+       struct strbuf alternate = STRBUF_INIT;
        struct remote *remote;
        struct transport *transport;
        const struct ref *extra;
 
-       ref_git = real_path(option_reference);
-
-       if (is_directory(mkpath("%s/.git/objects", ref_git)))
-               ref_git = mkpath("%s/.git", ref_git);
-       else if (!is_directory(mkpath("%s/objects", ref_git)))
+       /* Beware: real_path() and mkpath() return static buffer */
+       ref_git = xstrdup(real_path(item->string));
+       if (is_directory(mkpath("%s/.git/objects", ref_git))) {
+               char *ref_git_git = xstrdup(mkpath("%s/.git", ref_git));
+               free(ref_git);
+               ref_git = ref_git_git;
+       } else if (!is_directory(mkpath("%s/objects", ref_git)))
                die(_("reference repository '%s' is not a local directory."),
-                   option_reference);
-
-       ref_git_copy = xstrdup(ref_git);
+                   item->string);
 
-       add_to_alternates_file(ref_git_copy);
+       strbuf_addf(&alternate, "%s/objects", ref_git);
+       add_to_alternates_file(alternate.buf);
+       strbuf_release(&alternate);
 
-       remote = remote_get(ref_git_copy);
-       transport = transport_get(remote, ref_git_copy);
+       remote = remote_get(ref_git);
+       transport = transport_get(remote, ref_git);
        for (extra = transport_get_remote_refs(transport); extra;
             extra = extra->next)
                add_extra_ref(extra->name, extra->old_sha1, 0);
 
        transport_disconnect(transport);
+       free(ref_git);
+       return 0;
+}
 
-       free(ref_git_copy);
+static void setup_reference(void)
+{
+       for_each_string_list(&option_reference, add_one_reference, NULL);
 }
 
-static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
+static void copy_alternates(struct strbuf *src, struct strbuf *dst,
+                           const char *src_repo)
+{
+       /*
+        * Read from the source objects/info/alternates file
+        * and copy the entries to corresponding file in the
+        * destination repository with add_to_alternates_file().
+        * Both src and dst have "$path/objects/info/alternates".
+        *
+        * Instead of copying bit-for-bit from the original,
+        * we need to append to existing one so that the already
+        * created entry via "clone -s" is not lost, and also
+        * to turn entries with paths relative to the original
+        * absolute, so that they can be used in the new repository.
+        */
+       FILE *in = fopen(src->buf, "r");
+       struct strbuf line = STRBUF_INIT;
+
+       while (strbuf_getline(&line, in, '\n') != EOF) {
+               char *abs_path, abs_buf[PATH_MAX];
+               if (!line.len || line.buf[0] == '#')
+                       continue;
+               if (is_absolute_path(line.buf)) {
+                       add_to_alternates_file(line.buf);
+                       continue;
+               }
+               abs_path = mkpath("%s/objects/%s", src_repo, line.buf);
+               normalize_path_copy(abs_buf, abs_path);
+               add_to_alternates_file(abs_buf);
+       }
+       strbuf_release(&line);
+       fclose(in);
+}
+
+static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,
+                                  const char *src_repo, int src_baselen)
 {
        struct dirent *de;
        struct stat buf;
@@ -267,7 +335,14 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
                }
                if (S_ISDIR(buf.st_mode)) {
                        if (de->d_name[0] != '.')
-                               copy_or_link_directory(src, dest);
+                               copy_or_link_directory(src, dest,
+                                                      src_repo, src_baselen);
+                       continue;
+               }
+
+               /* Files that cannot be copied bit-for-bit... */
+               if (!strcmp(src->buf + src_baselen, "/info/alternates")) {
+                       copy_alternates(src, dest, src_repo);
                        continue;
                }
 
@@ -290,17 +365,20 @@ static const struct ref *clone_local(const char *src_repo,
                                     const char *dest_repo)
 {
        const struct ref *ret;
-       struct strbuf src = STRBUF_INIT;
-       struct strbuf dest = STRBUF_INIT;
        struct remote *remote;
        struct transport *transport;
 
-       if (option_shared)
-               add_to_alternates_file(src_repo);
-       else {
+       if (option_shared) {
+               struct strbuf alt = STRBUF_INIT;
+               strbuf_addf(&alt, "%s/objects", src_repo);
+               add_to_alternates_file(alt.buf);
+               strbuf_release(&alt);
+       } else {
+               struct strbuf src = STRBUF_INIT;
+               struct strbuf dest = STRBUF_INIT;
                strbuf_addf(&src, "%s/objects", src_repo);
                strbuf_addf(&dest, "%s/objects", dest_repo);
-               copy_or_link_directory(&src, &dest);
+               copy_or_link_directory(&src, &dest, src_repo, src.len);
                strbuf_release(&src);
                strbuf_release(&dest);
        }
@@ -345,8 +423,9 @@ static void remove_junk_on_signal(int signo)
 static struct ref *wanted_peer_refs(const struct ref *refs,
                struct refspec *refspec)
 {
-       struct ref *local_refs = NULL;
-       struct ref **tail = &local_refs;
+       struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
+       struct ref *local_refs = head;
+       struct ref **tail = head ? &head->next : &local_refs;
 
        get_fetch_map(refs, refspec, &tail, 0);
        if (!option_mirror)
@@ -359,8 +438,11 @@ static void write_remote_refs(const struct ref *local_refs)
 {
        const struct ref *r;
 
-       for (r = local_refs; r; r = r->next)
+       for (r = local_refs; r; r = r->next) {
+               if (!r->peer_ref)
+                       continue;
                add_extra_ref(r->peer_ref->name, r->old_sha1, 0);
+       }
 
        pack_refs(PACK_REFS_ALL);
        clear_extra_refs();
@@ -495,9 +577,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
        if (0 <= option_verbosity) {
                if (option_bare)
-                       printf(_("Cloning into bare repository %s...\n"), dir);
+                       printf(_("Cloning into bare repository '%s'...\n"), dir);
                else
-                       printf(_("Cloning into %s...\n"), dir);
+                       printf(_("Cloning into '%s'...\n"), dir);
        }
        init_db(option_template, INIT_DB_QUIET);
        write_config(&option_config);
@@ -540,8 +622,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        git_config_set(key.buf, repo);
        strbuf_reset(&key);
 
-       if (option_reference)
-               setup_reference(git_dir);
+       if (option_reference.nr)
+               setup_reference();
 
        fetch_pattern = value.buf;
        refspec = parse_fetch_refspec(1, &fetch_pattern);
index e1af9b19f0be71484ae9341762dc2bf89cabb70c..66ffe31736933d1ad15fdeb7bb321f10fcab1dd3 100644 (file)
@@ -62,8 +62,6 @@ N_("The previous cherry-pick is now empty, possibly due to conflict resolution.\
 "\n"
 "Otherwise, please use 'git reset'\n");
 
-static unsigned char head_sha1[20];
-
 static const char *use_message_buffer;
 static const char commit_editmsg[] = "COMMIT_EDITMSG";
 static struct lock_file index_lock; /* real index */
@@ -102,7 +100,7 @@ static enum {
 static char *cleanup_arg;
 
 static enum commit_whence whence;
-static int use_editor = 1, initial_commit, include_status = 1;
+static int use_editor = 1, include_status = 1;
 static int show_ignored_in_status;
 static const char *only_include_assumed;
 static struct strbuf message;
@@ -256,8 +254,10 @@ static int list_paths(struct string_list *list, const char *with_tree,
                ;
        m = xcalloc(1, i);
 
-       if (with_tree)
-               overlay_tree_on_cache(with_tree, prefix);
+       if (with_tree) {
+               const char *max_prefix = pathspec_prefix(prefix, pattern);
+               overlay_tree_on_cache(with_tree, max_prefix);
+       }
 
        for (i = 0; i < active_nr; i++) {
                struct cache_entry *ce = active_cache[i];
@@ -272,7 +272,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
                        item->util = item; /* better a valid pointer than a fake one */
        }
 
-       return report_path_error(m, pattern, prefix ? strlen(prefix) : 0);
+       return report_path_error(m, pattern, prefix);
 }
 
 static void add_remove_files(struct string_list *list)
@@ -294,13 +294,13 @@ static void add_remove_files(struct string_list *list)
        }
 }
 
-static void create_base_index(void)
+static void create_base_index(const struct commit *current_head)
 {
        struct tree *tree;
        struct unpack_trees_options opts;
        struct tree_desc t;
 
-       if (initial_commit) {
+       if (!current_head) {
                discard_cache();
                return;
        }
@@ -313,7 +313,7 @@ static void create_base_index(void)
        opts.dst_index = &the_index;
 
        opts.fn = oneway_merge;
-       tree = parse_tree_indirect(head_sha1);
+       tree = parse_tree_indirect(current_head->object.sha1);
        if (!tree)
                die(_("failed to unpack HEAD tree object"));
        parse_tree(tree);
@@ -332,7 +332,8 @@ static void refresh_cache_or_die(int refresh_flags)
                die_resolve_conflict("commit");
 }
 
-static char *prepare_index(int argc, const char **argv, const char *prefix, int is_status)
+static char *prepare_index(int argc, const char **argv, const char *prefix,
+                          const struct commit *current_head, int is_status)
 {
        int fd;
        struct string_list partial;
@@ -448,7 +449,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
 
        memset(&partial, 0, sizeof(partial));
        partial.strdup_strings = 1;
-       if (list_paths(&partial, initial_commit ? NULL : "HEAD", prefix, pathspec))
+       if (list_paths(&partial, !current_head ? NULL : "HEAD", prefix, pathspec))
                exit(1);
 
        discard_cache();
@@ -467,7 +468,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
                                                (uintmax_t) getpid()),
                                       LOCK_DIE_ON_ERROR);
 
-       create_base_index();
+       create_base_index(current_head);
        add_remove_files(&partial);
        refresh_cache(REFRESH_QUIET);
 
@@ -516,12 +517,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
        return s->commitable;
 }
 
-static int is_a_merge(const unsigned char *sha1)
+static int is_a_merge(const struct commit *current_head)
 {
-       struct commit *commit = lookup_commit(sha1);
-       if (!commit || parse_commit(commit))
-               die(_("could not parse HEAD commit"));
-       return !!(commit->parents && commit->parents->next);
+       return !!(current_head->parents && current_head->parents->next);
 }
 
 static const char sign_off_header[] = "Signed-off-by: ";
@@ -625,6 +623,7 @@ static char *cut_ident_timestamp_part(char *string)
 }
 
 static int prepare_to_commit(const char *index_file, const char *prefix,
+                            struct commit *current_head,
                             struct wt_status *s,
                             struct strbuf *author_ident)
 {
@@ -846,7 +845,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
         * empty due to conflict resolution, which the user should okay.
         */
        if (!commitable && whence != FROM_MERGE && !allow_empty &&
-           !(amend && is_a_merge(head_sha1))) {
+           !(amend && is_a_merge(current_head))) {
                run_status(stdout, index_file, prefix, 0, s);
                if (amend)
                        fputs(_(empty_amend_advice), stderr);
@@ -1004,6 +1003,7 @@ static const char *read_commit_message(const char *name)
 static int parse_and_validate_options(int argc, const char *argv[],
                                      const char * const usage[],
                                      const char *prefix,
+                                     struct commit *current_head,
                                      struct wt_status *s)
 {
        int f = 0;
@@ -1024,11 +1024,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
        if (!use_editor)
                setenv("GIT_EDITOR", ":", 1);
 
-       if (get_sha1("HEAD", head_sha1))
-               initial_commit = 1;
-
        /* Sanity check options */
-       if (amend && initial_commit)
+       if (amend && !current_head)
                die(_("You have nothing to amend."));
        if (amend && whence != FROM_COMMIT)
                die(_("You are in the middle of a %s -- cannot amend."), whence_s());
@@ -1100,12 +1097,12 @@ static int parse_and_validate_options(int argc, const char *argv[],
 }
 
 static int dry_run_commit(int argc, const char **argv, const char *prefix,
-                         struct wt_status *s)
+                         const struct commit *current_head, struct wt_status *s)
 {
        int commitable;
        const char *index_file;
 
-       index_file = prepare_index(argc, argv, prefix, 1);
+       index_file = prepare_index(argc, argv, prefix, current_head, 1);
        commitable = run_status(stdout, index_file, prefix, 0, s);
        rollback_index_files();
 
@@ -1144,7 +1141,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
                return 0;
        }
        if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
-               s->use_color = git_config_colorbool(k, v, -1);
+               s->use_color = git_config_colorbool(k, v);
                return 0;
        }
        if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
@@ -1237,10 +1234,6 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
        if (s.relative_paths)
                s.prefix = prefix;
-       if (s.use_color == -1)
-               s.use_color = git_use_color_default;
-       if (diff_use_color_default == -1)
-               diff_use_color_default = git_use_color_default;
 
        switch (status_format) {
        case STATUS_FORMAT_SHORT:
@@ -1258,7 +1251,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
        return 0;
 }
 
-static void print_summary(const char *prefix, const unsigned char *sha1)
+static void print_summary(const char *prefix, const unsigned char *sha1,
+                         int initial_commit)
 {
        struct rev_info rev;
        struct commit *commit;
@@ -1380,12 +1374,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        struct strbuf author_ident = STRBUF_INIT;
        const char *index_file, *reflog_msg;
        char *nl, *p;
-       unsigned char commit_sha1[20];
+       unsigned char sha1[20];
        struct ref_lock *ref_lock;
        struct commit_list *parents = NULL, **pptr = &parents;
        struct stat statbuf;
        int allow_fast_forward = 1;
        struct wt_status s;
+       struct commit *current_head = NULL;
 
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage_with_options(builtin_commit_usage, builtin_commit_options);
@@ -1394,48 +1389,47 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        git_config(git_commit_config, &s);
        determine_whence(&s);
 
-       if (s.use_color == -1)
-               s.use_color = git_use_color_default;
-       argc = parse_and_validate_options(argc, argv, builtin_commit_usage,
-                                         prefix, &s);
-       if (dry_run) {
-               if (diff_use_color_default == -1)
-                       diff_use_color_default = git_use_color_default;
-               return dry_run_commit(argc, argv, prefix, &s);
+       if (get_sha1("HEAD", sha1))
+               current_head = NULL;
+       else {
+               current_head = lookup_commit_or_die(sha1, "HEAD");
+               if (!current_head || parse_commit(current_head))
+                       die(_("could not parse HEAD commit"));
        }
-       index_file = prepare_index(argc, argv, prefix, 0);
+       argc = parse_and_validate_options(argc, argv, builtin_commit_usage,
+                                         prefix, current_head, &s);
+       if (dry_run)
+               return dry_run_commit(argc, argv, prefix, current_head, &s);
+       index_file = prepare_index(argc, argv, prefix, current_head, 0);
 
        /* Set up everything for writing the commit object.  This includes
           running hooks, writing the trees, and interacting with the user.  */
-       if (!prepare_to_commit(index_file, prefix, &s, &author_ident)) {
+       if (!prepare_to_commit(index_file, prefix,
+                              current_head, &s, &author_ident)) {
                rollback_index_files();
                return 1;
        }
 
        /* Determine parents */
        reflog_msg = getenv("GIT_REFLOG_ACTION");
-       if (initial_commit) {
+       if (!current_head) {
                if (!reflog_msg)
                        reflog_msg = "commit (initial)";
        } else if (amend) {
                struct commit_list *c;
-               struct commit *commit;
 
                if (!reflog_msg)
                        reflog_msg = "commit (amend)";
-               commit = lookup_commit(head_sha1);
-               if (!commit || parse_commit(commit))
-                       die(_("could not parse HEAD commit"));
-
-               for (c = commit->parents; c; c = c->next)
+               for (c = current_head->parents; c; c = c->next)
                        pptr = &commit_list_insert(c->item, pptr)->next;
        } else if (whence == FROM_MERGE) {
                struct strbuf m = STRBUF_INIT;
+               struct commit *commit;
                FILE *fp;
 
                if (!reflog_msg)
                        reflog_msg = "commit (merge)";
-               pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
+               pptr = &commit_list_insert(current_head, pptr)->next;
                fp = fopen(git_path("MERGE_HEAD"), "r");
                if (fp == NULL)
                        die_errno(_("could not open '%s' for reading"),
@@ -1444,7 +1438,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                        unsigned char sha1[20];
                        if (get_sha1_hex(m.buf, sha1) < 0)
                                die(_("Corrupt MERGE_HEAD file (%s)"), m.buf);
-                       pptr = &commit_list_insert(lookup_commit(sha1), pptr)->next;
+                       commit = lookup_commit_or_die(sha1, "MERGE_HEAD");
+                       pptr = &commit_list_insert(commit, pptr)->next;
                }
                fclose(fp);
                strbuf_release(&m);
@@ -1461,7 +1456,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                        reflog_msg = (whence == FROM_CHERRY_PICK)
                                        ? "commit (cherry-pick)"
                                        : "commit";
-               pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
+               pptr = &commit_list_insert(current_head, pptr)->next;
        }
 
        /* Finally, get the commit message */
@@ -1487,7 +1482,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                exit(1);
        }
 
-       if (commit_tree(sb.buf, active_cache_tree->sha1, parents, commit_sha1,
+       if (commit_tree(sb.buf, active_cache_tree->sha1, parents, sha1,
                        author_ident.buf)) {
                rollback_index_files();
                die(_("failed to write commit object"));
@@ -1495,7 +1490,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        strbuf_release(&author_ident);
 
        ref_lock = lock_any_ref_for_update("HEAD",
-                                          initial_commit ? NULL : head_sha1,
+                                          !current_head
+                                          ? NULL
+                                          : current_head->object.sha1,
                                           0);
 
        nl = strchr(sb.buf, '\n');
@@ -1510,7 +1507,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                rollback_index_files();
                die(_("cannot lock HEAD ref"));
        }
-       if (write_ref_sha1(ref_lock, commit_sha1, sb.buf) < 0) {
+       if (write_ref_sha1(ref_lock, sha1, sb.buf) < 0) {
                rollback_index_files();
                die(_("cannot update HEAD ref"));
        }
@@ -1532,13 +1529,14 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                struct notes_rewrite_cfg *cfg;
                cfg = init_copy_notes_for_rewrite("amend");
                if (cfg) {
-                       copy_note_for_rewrite(cfg, head_sha1, commit_sha1);
+                       /* we are amending, so current_head is not NULL */
+                       copy_note_for_rewrite(cfg, current_head->object.sha1, sha1);
                        finish_copy_notes_for_rewrite(cfg);
                }
-               run_rewrite_hook(head_sha1, commit_sha1);
+               run_rewrite_hook(current_head->object.sha1, sha1);
        }
        if (!quiet)
-               print_summary(prefix, commit_sha1);
+               print_summary(prefix, sha1, !current_head);
 
        return 0;
 }
index 211e118d575411b712ccf0387db2408708576902..0315ad76f881aab9a64084f8d2fdd2019907e4cb 100644 (file)
@@ -99,6 +99,7 @@ static int show_config(const char *key_, const char *value_, void *cb)
        const char *vptr = value;
        int must_free_vptr = 0;
        int dup_error = 0;
+       int must_print_delim = 0;
 
        if (!use_key_regexp && strcmp(key_, key))
                return 0;
@@ -109,10 +110,8 @@ static int show_config(const char *key_, const char *value_, void *cb)
                return 0;
 
        if (show_keys) {
-               if (value_)
-                       printf("%s%c", key_, key_delim);
-               else
-                       printf("%s", key_);
+               printf("%s", key_);
+               must_print_delim = 1;
        }
        if (seen && !do_all)
                dup_error = 1;
@@ -130,16 +129,23 @@ static int show_config(const char *key_, const char *value_, void *cb)
        } else if (types == TYPE_PATH) {
                git_config_pathname(&vptr, key_, value_);
                must_free_vptr = 1;
+       } else if (value_) {
+               vptr = value_;
+       } else {
+               /* Just show the key name */
+               vptr = "";
+               must_print_delim = 0;
        }
-       else
-               vptr = value_?value_:"";
        seen++;
        if (dup_error) {
                error("More than one value for the key %s: %s",
                                key_, vptr);
        }
-       else
+       else {
+               if (must_print_delim)
+                       printf("%c", key_delim);
                printf("%s%c", vptr, term);
+       }
        if (must_free_vptr)
                /* If vptr must be freed, it's a pointer to a
                 * dynamically allocated buffer, it's safe to cast to
@@ -303,24 +309,18 @@ static void get_color(const char *def_color)
        fputs(parsed_color, stdout);
 }
 
-static int stdout_is_tty;
 static int get_colorbool_found;
 static int get_diff_color_found;
+static int get_color_ui_found;
 static int git_get_colorbool_config(const char *var, const char *value,
                void *cb)
 {
-       if (!strcmp(var, get_colorbool_slot)) {
-               get_colorbool_found =
-                       git_config_colorbool(var, value, stdout_is_tty);
-       }
-       if (!strcmp(var, "diff.color")) {
-               get_diff_color_found =
-                       git_config_colorbool(var, value, stdout_is_tty);
-       }
-       if (!strcmp(var, "color.ui")) {
-               git_use_color_default = git_config_colorbool(var, value, stdout_is_tty);
-               return 0;
-       }
+       if (!strcmp(var, get_colorbool_slot))
+               get_colorbool_found = git_config_colorbool(var, value);
+       else if (!strcmp(var, "diff.color"))
+               get_diff_color_found = git_config_colorbool(var, value);
+       else if (!strcmp(var, "color.ui"))
+               get_color_ui_found = git_config_colorbool(var, value);
        return 0;
 }
 
@@ -334,9 +334,11 @@ static int get_colorbool(int print)
                if (!strcmp(get_colorbool_slot, "color.diff"))
                        get_colorbool_found = get_diff_color_found;
                if (get_colorbool_found < 0)
-                       get_colorbool_found = git_use_color_default;
+                       get_colorbool_found = get_color_ui_found;
        }
 
+       get_colorbool_found = want_color(get_colorbool_found);
+
        if (print) {
                printf("%s\n", get_colorbool_found ? "true" : "false");
                return 0;
@@ -510,9 +512,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
        }
        else if (actions == ACTION_GET_COLORBOOL) {
                if (argc == 1)
-                       stdout_is_tty = git_config_bool("command line", argv[0]);
-               else if (argc == 0)
-                       stdout_is_tty = isatty(1);
+                       color_stdout_is_tty = git_config_bool("command line", argv[0]);
                return get_colorbool(argc != 0);
        }
 
index 66fc291c8a81de71dee7b597c9ab0dc9d70e8e29..9f63067f50a6f49d61d40474608535905bec905b 100644 (file)
@@ -462,8 +462,21 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                die(_("No names found, cannot describe anything."));
 
        if (argc == 0) {
-               if (dirty && !cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1, diff_index_args, prefix))
-                       dirty = NULL;
+               if (dirty) {
+                       static struct lock_file index_lock;
+                       int fd;
+
+                       read_cache_preload(NULL);
+                       refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
+                                     NULL, NULL, NULL);
+                       fd = hold_locked_index(&index_lock, 0);
+                       if (0 <= fd)
+                               update_index_if_able(&the_index, &index_lock);
+
+                       if (!cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1,
+                                           diff_index_args, prefix))
+                               dirty = NULL;
+               }
                describe("HEAD", 1);
        } else if (dirty) {
                die(_("--dirty is incompatible with committishes"));
index 69cd5eed78cb402839813e7eca65b5598afa4a90..1118689fb246b864ce758039543327c4304cdaa4 100644 (file)
@@ -277,9 +277,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
        gitmodules_config();
        git_config(git_diff_ui_config, NULL);
 
-       if (diff_use_color_default == -1)
-               diff_use_color_default = git_use_color_default;
-
        init_revisions(&rev, prefix);
 
        /* If this is a no-index diff, just run it and exit there. */
index daf19451ba7df541d1314c880679749232ccce35..9836e6b7ca22e254c06d8d766d510ef43a8cbe90 100644 (file)
@@ -16,6 +16,7 @@
 #include "string-list.h"
 #include "utf8.h"
 #include "parse-options.h"
+#include "quote.h"
 
 static const char *fast_export_usage[] = {
        "git fast-export [rev-list-opts]",
@@ -26,6 +27,7 @@ static int progress;
 static enum { ABORT, VERBATIM, WARN, STRIP } signed_tag_mode = ABORT;
 static enum { ERROR, DROP, REWRITE } tag_of_filtered_mode = ABORT;
 static int fake_missing_tagger;
+static int use_done_feature;
 static int no_data;
 static int full_tree;
 
@@ -178,6 +180,15 @@ static int depth_first(const void *a_, const void *b_)
        return (a->status == 'R') - (b->status == 'R');
 }
 
+static void print_path(const char *path)
+{
+       int need_quote = quote_c_style(path, NULL, NULL, 0);
+       if (need_quote)
+               quote_c_style(path, NULL, stdout, 0);
+       else
+               printf("%s", path);
+}
+
 static void show_filemodify(struct diff_queue_struct *q,
                            struct diff_options *options, void *data)
 {
@@ -195,13 +206,18 @@ static void show_filemodify(struct diff_queue_struct *q,
 
                switch (q->queue[i]->status) {
                case DIFF_STATUS_DELETED:
-                       printf("D %s\n", spec->path);
+                       printf("D ");
+                       print_path(spec->path);
+                       putchar('\n');
                        break;
 
                case DIFF_STATUS_COPIED:
                case DIFF_STATUS_RENAMED:
-                       printf("%c \"%s\" \"%s\"\n", q->queue[i]->status,
-                              ospec->path, spec->path);
+                       printf("%c ", q->queue[i]->status);
+                       print_path(ospec->path);
+                       putchar(' ');
+                       print_path(spec->path);
+                       putchar('\n');
 
                        if (!hashcmp(ospec->sha1, spec->sha1) &&
                            ospec->mode == spec->mode)
@@ -216,13 +232,15 @@ static void show_filemodify(struct diff_queue_struct *q,
                         * output the SHA-1 verbatim.
                         */
                        if (no_data || S_ISGITLINK(spec->mode))
-                               printf("M %06o %s %s\n", spec->mode,
-                                      sha1_to_hex(spec->sha1), spec->path);
+                               printf("M %06o %s ", spec->mode,
+                                      sha1_to_hex(spec->sha1));
                        else {
                                struct object *object = lookup_object(spec->sha1);
-                               printf("M %06o :%d %s\n", spec->mode,
-                                      get_object_mark(object), spec->path);
+                               printf("M %06o :%d ", spec->mode,
+                                      get_object_mark(object));
                        }
+                       print_path(spec->path);
+                       putchar('\n');
                        break;
 
                default:
@@ -627,6 +645,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
                             "Fake a tagger when tags lack one"),
                OPT_BOOLEAN(0, "full-tree", &full_tree,
                             "Output full tree for each commit"),
+               OPT_BOOLEAN(0, "use-done-feature", &use_done_feature,
+                            "Use the done feature to terminate the stream"),
                { OPTION_NEGBIT, 0, "data", &no_data, NULL,
                        "Skip output of blob data",
                        PARSE_OPT_NOARG | PARSE_OPT_NEGHELP, NULL, 1 },
@@ -648,6 +668,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
        if (argc > 1)
                usage_with_options (fast_export_usage, options);
 
+       if (use_done_feature)
+               printf("feature done\n");
+
        if (import_filename)
                import_marks(import_filename);
 
@@ -675,5 +698,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
        if (export_filename)
                export_marks(export_filename);
 
+       if (use_done_feature)
+               printf("done\n");
+
        return 0;
 }
index 436798410210b868cfbe439a1603b0a340a32c50..412bd327b5b396c159c768b25be189e00531c38e 100644 (file)
@@ -185,6 +185,36 @@ static void consume_shallow_list(int fd)
        }
 }
 
+struct write_shallow_data {
+       struct strbuf *out;
+       int use_pack_protocol;
+       int count;
+};
+
+static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
+{
+       struct write_shallow_data *data = cb_data;
+       const char *hex = sha1_to_hex(graft->sha1);
+       data->count++;
+       if (data->use_pack_protocol)
+               packet_buf_write(data->out, "shallow %s", hex);
+       else {
+               strbuf_addstr(data->out, hex);
+               strbuf_addch(data->out, '\n');
+       }
+       return 0;
+}
+
+static int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
+{
+       struct write_shallow_data data;
+       data.out = out;
+       data.use_pack_protocol = use_pack_protocol;
+       data.count = 0;
+       for_each_commit_graft(write_one_shallow, &data);
+       return data.count;
+}
+
 static enum ack_type get_ack(int fd, unsigned char *result_sha1)
 {
        static char line[1000];
@@ -395,6 +425,8 @@ static int find_common(int fd[2], unsigned char *result_sha1,
                                case ACK_continue: {
                                        struct commit *commit =
                                                lookup_commit(result_sha1);
+                                       if (!commit)
+                                               die("invalid commit %s", sha1_to_hex(result_sha1));
                                        if (args.stateless_rpc
                                         && ack == ACK_common
                                         && !(commit->object.flags & COMMON)) {
index 93c99385a95e6ab525fa64c1dbb70d5d4ca103ba..9d481f8ca9d9470311b356e9bd5356fa362ffd6a 100644 (file)
@@ -540,10 +540,10 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
        return ret;
 }
 
-static int prune_refs(struct transport *transport, struct ref *ref_map)
+static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map)
 {
        int result = 0;
-       struct ref *ref, *stale_refs = get_stale_heads(transport->remote, ref_map);
+       struct ref *ref, *stale_refs = get_stale_heads(refs, ref_count, ref_map);
        const char *dangling_msg = dry_run
                ? _("   (%s will become dangling)\n")
                : _("   (%s has become dangling)\n");
@@ -734,8 +734,31 @@ static int do_fetch(struct transport *transport,
                free_refs(ref_map);
                return 1;
        }
-       if (prune)
-               prune_refs(transport, ref_map);
+       if (prune) {
+               /* If --tags was specified, pretend the user gave us the canonical tags refspec */
+               if (tags == TAGS_SET) {
+                       const char *tags_str = "refs/tags/*:refs/tags/*";
+                       struct refspec *tags_refspec, *refspec;
+
+                       /* Copy the refspec and add the tags to it */
+                       refspec = xcalloc(ref_count + 1, sizeof(struct refspec));
+                       tags_refspec = parse_fetch_refspec(1, &tags_str);
+                       memcpy(refspec, refs, ref_count * sizeof(struct refspec));
+                       memcpy(&refspec[ref_count], tags_refspec, sizeof(struct refspec));
+                       ref_count++;
+
+                       prune_refs(refspec, ref_count, ref_map);
+
+                       ref_count--;
+                       /* The rest of the strings belong to fetch_one */
+                       free_refspec(1, tags_refspec);
+                       free(refspec);
+               } else if (ref_count) {
+                       prune_refs(refs, ref_count, ref_map);
+               } else {
+                       prune_refs(transport->remote->fetch, transport->remote->fetch_refspec_nr, ref_map);
+               }
+       }
        free_refs(ref_map);
 
        /* if neither --no-tags nor --tags was specified, do automated tag
@@ -918,7 +941,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
        atexit(unlock_pack);
        refspec = parse_fetch_refspec(ref_nr, refs);
        exit_code = do_fetch(transport, refspec, ref_nr);
-       free(refspec);
+       free_refspec(ref_nr, refspec);
        transport_disconnect(transport);
        transport = NULL;
        return exit_code;
@@ -941,6 +964,15 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix,
                             builtin_fetch_options, builtin_fetch_usage, 0);
 
+       if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
+               if (recurse_submodules_default) {
+                       int arg = parse_fetch_recurse_submodules_arg("--recurse-submodules-default", recurse_submodules_default);
+                       set_config_fetch_recurse_submodules(arg);
+               }
+               gitmodules_config();
+               git_config(submodule_config, NULL);
+       }
+
        if (all) {
                if (argc == 1)
                        die(_("fetch --all does not take a repository argument"));
@@ -976,12 +1008,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
        if (!result && (recurse_submodules != RECURSE_SUBMODULES_OFF)) {
                const char *options[10];
                int num_options = 0;
-               if (recurse_submodules_default) {
-                       int arg = parse_fetch_recurse_submodules_arg("--recurse-submodules-default", recurse_submodules_default);
-                       set_config_fetch_recurse_submodules(arg);
-               }
-               gitmodules_config();
-               git_config(submodule_config, NULL);
                add_options_to_argv(&num_options, options);
                result = fetch_populated_submodules(num_options, options,
                                                    submodule_prefix,
index 75816329d6153c35e0763b35f70cfaf165f2a4b8..7e2f22589dcb14d5ba95ce1331ef816a458533d0 100644 (file)
@@ -293,7 +293,7 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
                struct commit *head;
                struct rev_info rev;
 
-               head = lookup_commit(head_sha1);
+               head = lookup_commit_or_die(head_sha1, "HEAD");
                init_revisions(&rev, NULL);
                rev.commit_format = CMIT_FMT_ONELINE;
                rev.ignore_merges = 1;
index 5ae0366bc8cfe52f226c2af151a66d39b9df02aa..df1a88b51ae7773a15276d144113c0002fddb1cd 100644 (file)
@@ -231,12 +231,9 @@ static void check_unreachable_object(struct object *obj)
                                unsigned long size;
                                char *buf = read_sha1_file(obj->sha1,
                                                &type, &size);
-                               if (buf) {
-                                       if (fwrite(buf, size, 1, f) != 1)
-                                               die_errno("Could not write '%s'",
-                                                         filename);
-                                       free(buf);
-                               }
+                               if (buf && fwrite(buf, 1, size, f) != size)
+                                       die_errno("Could not write '%s'", filename);
+                               free(buf);
                        } else
                                fprintf(f, "%s\n", sha1_to_hex(obj->sha1));
                        if (fclose(f))
index cccf8da6d2a600154536ea642250699d9356f148..a286692e467710d92346ab6900e98f1126cb967d 100644 (file)
@@ -325,7 +325,7 @@ static int grep_config(const char *var, const char *value, void *cb)
        }
 
        if (!strcmp(var, "color.grep"))
-               opt->color = git_config_colorbool(var, value, -1);
+               opt->color = git_config_colorbool(var, value);
        else if (!strcmp(var, "color.grep.context"))
                color = opt->color_context;
        else if (!strcmp(var, "color.grep.filename"))
@@ -598,8 +598,11 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
                struct strbuf base;
                int hit, len;
 
+               read_sha1_lock();
                data = read_object_with_reference(obj->sha1, tree_type,
                                                  &size, NULL);
+               read_sha1_unlock();
+
                if (!data)
                        die(_("unable to read tree (%s)"), sha1_to_hex(obj->sha1));
 
@@ -827,17 +830,19 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                OPT_BOOLEAN(0, "heading", &opt.heading,
                        "show filename only once above matches from same file"),
                OPT_GROUP(""),
-               OPT_CALLBACK('C', NULL, &opt, "n",
+               OPT_CALLBACK('C', "context", &opt, "n",
                        "show <n> context lines before and after matches",
                        context_callback),
-               OPT_INTEGER('B', NULL, &opt.pre_context,
+               OPT_INTEGER('B', "before-context", &opt.pre_context,
                        "show <n> context lines before matches"),
-               OPT_INTEGER('A', NULL, &opt.post_context,
+               OPT_INTEGER('A', "after-context", &opt.post_context,
                        "show <n> context lines after matches"),
                OPT_NUMBER_CALLBACK(&opt, "shortcut for -C NUM",
                        context_callback),
                OPT_BOOLEAN('p', "show-function", &opt.funcname,
                        "show a line with the function name before matches"),
+               OPT_BOOLEAN('W', "function-context", &opt.funcbody,
+                       "show the surrounding function"),
                OPT_GROUP(""),
                OPT_CALLBACK('f', NULL, &opt, "file",
                        "read patterns from file", file_callback),
@@ -896,8 +901,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
        strcpy(opt.color_sep, GIT_COLOR_CYAN);
        opt.color = -1;
        git_config(grep_config, &opt);
-       if (opt.color == -1)
-               opt.color = git_use_color_default;
 
        /*
         * If there is no -- then the paths must exist in the working
@@ -980,7 +983,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                use_threads = 0;
 
        if (use_threads) {
-               if (opt.pre_context || opt.post_context || opt.file_break)
+               if (opt.pre_context || opt.post_context || opt.file_break ||
+                   opt.funcbody)
                        skip_first_line = 1;
                start_threads(&opt);
        }
index 025aa47c804e4400cfa16ae8acd8dc2a5175e7c0..d07554c8844a9b7dd3d4ae2b5efe2cbde623e4af 100644 (file)
@@ -347,7 +347,7 @@ static void separate_git_dir(const char *git_dir)
                const char *src;
 
                if (S_ISREG(st.st_mode))
-                       src = read_gitfile_gently(git_link);
+                       src = read_gitfile(git_link);
                else if (S_ISDIR(st.st_mode))
                        src = git_link;
                else
index 5c2af590047d92554d87acc5d7113a2f1f730a96..f5d49305903911eb7aa0fb3f73e0fd950b896228 100644 (file)
@@ -359,9 +359,6 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
 
        git_config(git_log_config, NULL);
 
-       if (diff_use_color_default == -1)
-               diff_use_color_default = git_use_color_default;
-
        init_revisions(&rev, prefix);
        rev.diff = 1;
        rev.simplify_history = 0;
@@ -446,9 +443,6 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 
        git_config(git_log_config, NULL);
 
-       if (diff_use_color_default == -1)
-               diff_use_color_default = git_use_color_default;
-
        init_pathspec(&match_all, NULL);
        init_revisions(&rev, prefix);
        rev.diff = 1;
@@ -524,9 +518,6 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
 
        git_config(git_log_config, NULL);
 
-       if (diff_use_color_default == -1)
-               diff_use_color_default = git_use_color_default;
-
        init_revisions(&rev, prefix);
        init_reflog_walk(&rev.reflog_info);
        rev.verbose_header = 1;
@@ -549,9 +540,6 @@ int cmd_log(int argc, const char **argv, const char *prefix)
 
        git_config(git_log_config, NULL);
 
-       if (diff_use_color_default == -1)
-               diff_use_color_default = git_use_color_default;
-
        init_revisions(&rev, prefix);
        rev.always_show_header = 1;
        memset(&opt, 0, sizeof(opt));
@@ -620,7 +608,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
                string_list_append(&extra_cc, value);
                return 0;
        }
-       if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
+       if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff") ||
+           !strcmp(var, "color.ui")) {
                return 0;
        }
        if (!strcmp(var, "format.numbered")) {
index 15701233e29b240cfa1abdb56bd489306e74c677..e8a800d3ac42bfce328bea786d8e1efa4ff695c7 100644 (file)
@@ -276,41 +276,6 @@ static void prune_cache(const char *prefix)
        active_nr = last;
 }
 
-static const char *pathspec_prefix(const char *prefix)
-{
-       const char **p, *n, *prev;
-       unsigned long max;
-
-       if (!pathspec) {
-               max_prefix_len = prefix ? strlen(prefix) : 0;
-               return prefix;
-       }
-
-       prev = NULL;
-       max = PATH_MAX;
-       for (p = pathspec; (n = *p) != NULL; p++) {
-               int i, len = 0;
-               for (i = 0; i < max; i++) {
-                       char c = n[i];
-                       if (prev && prev[i] != c)
-                               break;
-                       if (!c || c == '*' || c == '?')
-                               break;
-                       if (c == '/')
-                               len = i+1;
-               }
-               prev = n;
-               if (len < max) {
-                       max = len;
-                       if (!max)
-                               break;
-               }
-       }
-
-       max_prefix_len = max;
-       return max ? xmemdupz(prev, max) : NULL;
-}
-
 static void strip_trailing_slash_from_submodules(void)
 {
        const char **p;
@@ -388,11 +353,13 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
        }
 }
 
-int report_path_error(const char *ps_matched, const char **pathspec, int prefix_len)
+int report_path_error(const char *ps_matched, const char **pathspec, const char *prefix)
 {
        /*
         * Make sure all pathspec matched; otherwise it is an error.
         */
+       struct strbuf sb = STRBUF_INIT;
+       const char *name;
        int num, errors = 0;
        for (num = 0; pathspec[num]; num++) {
                int other, found_dup;
@@ -417,10 +384,12 @@ int report_path_error(const char *ps_matched, const char **pathspec, int prefix_
                if (found_dup)
                        continue;
 
+               name = quote_path_relative(pathspec[num], -1, &sb, prefix);
                error("pathspec '%s' did not match any file(s) known to git.",
-                     pathspec[num] + prefix_len);
+                     name);
                errors++;
        }
+       strbuf_release(&sb);
        return errors;
 }
 
@@ -576,7 +545,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
                strip_trailing_slash_from_submodules();
 
        /* Find common prefix for all pathspec's */
-       max_prefix = pathspec_prefix(prefix);
+       max_prefix = pathspec_prefix(prefix, pathspec);
+       max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
 
        /* Treat unmatching pathspec elements as errors */
        if (pathspec && error_unmatch) {
@@ -611,7 +581,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
 
        if (ps_matched) {
                int bad;
-               bad = report_path_error(ps_matched, pathspec, prefix_len);
+               bad = report_path_error(ps_matched, pathspec, prefix);
                if (bad)
                        fprintf(stderr, "Did you forget to 'git add'?\n");
 
index f08c5b0c942eec58b85ab41e5e5fb1ec216df683..6b666e1e87017f41d2f53c50b157f280b3a5f282 100644 (file)
@@ -173,7 +173,5 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
        tree = parse_tree_indirect(sha1);
        if (!tree)
                die("not a tree object");
-       read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
-
-       return 0;
+       return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
 }
index 325891edb610945d01899b102993202af279bf3f..581f494aee01f97bb87a94dbfd1fba4d14afaa69 100644 (file)
@@ -50,7 +50,6 @@ static int fast_forward_only;
 static int allow_trivial = 1, have_message;
 static struct strbuf merge_msg;
 static struct commit_list *remoteheads;
-static unsigned char head[20], stash[20];
 static struct strategy **use_strategies;
 static size_t use_strategies_nr, use_strategies_alloc;
 static const char **xopts;
@@ -217,7 +216,7 @@ static void drop_save(void)
        unlink(git_path("MERGE_MODE"));
 }
 
-static void save_state(void)
+static int save_state(unsigned char *stash)
 {
        int len;
        struct child_process cp;
@@ -236,11 +235,12 @@ static void save_state(void)
 
        if (finish_command(&cp) || len < 0)
                die(_("stash failed"));
-       else if (!len)
-               return;
+       else if (!len)          /* no changes */
+               return -1;
        strbuf_setlen(&buffer, buffer.len-1);
        if (get_sha1(buffer.buf, stash))
                die(_("not a valid object: %s"), buffer.buf);
+       return 0;
 }
 
 static void read_empty(unsigned const char *sha1, int verbose)
@@ -278,7 +278,8 @@ static void reset_hard(unsigned const char *sha1, int verbose)
                die(_("read-tree failed"));
 }
 
-static void restore_state(void)
+static void restore_state(const unsigned char *head,
+                         const unsigned char *stash)
 {
        struct strbuf sb = STRBUF_INIT;
        const char *args[] = { "stash", "apply", NULL, NULL };
@@ -308,10 +309,9 @@ static void finish_up_to_date(const char *msg)
        drop_save();
 }
 
-static void squash_message(void)
+static void squash_message(struct commit *commit)
 {
        struct rev_info rev;
-       struct commit *commit;
        struct strbuf out = STRBUF_INIT;
        struct commit_list *j;
        int fd;
@@ -326,7 +326,6 @@ static void squash_message(void)
        rev.ignore_merges = 1;
        rev.commit_format = CMIT_FMT_MEDIUM;
 
-       commit = lookup_commit(head);
        commit->object.flags |= UNINTERESTING;
        add_pending_object(&rev, &commit->object, NULL);
 
@@ -355,9 +354,11 @@ static void squash_message(void)
        strbuf_release(&out);
 }
 
-static void finish(const unsigned char *new_head, const char *msg)
+static void finish(struct commit *head_commit,
+                  const unsigned char *new_head, const char *msg)
 {
        struct strbuf reflog_message = STRBUF_INIT;
+       const unsigned char *head = head_commit->object.sha1;
 
        if (!msg)
                strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION"));
@@ -368,7 +369,7 @@ static void finish(const unsigned char *new_head, const char *msg)
                        getenv("GIT_REFLOG_ACTION"), msg);
        }
        if (squash) {
-               squash_message();
+               squash_message(head_commit);
        } else {
                if (verbosity >= 0 && !merge_msg.len)
                        printf(_("No merge message -- not updating HEAD\n"));
@@ -390,8 +391,6 @@ static void finish(const unsigned char *new_head, const char *msg)
                opts.output_format |=
                        DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
                opts.detect_rename = DIFF_DETECT_RENAME;
-               if (diff_use_color_default > 0)
-                       DIFF_OPT_SET(&opts, COLOR_DIFF);
                if (diff_setup_done(&opts) < 0)
                        die(_("diff_setup_done failed"));
                diff_tree_sha1(head, new_head, "", &opts);
@@ -663,7 +662,7 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
 }
 
 static int try_merge_strategy(const char *strategy, struct commit_list *common,
-                             const char *head_arg)
+                             struct commit *head, const char *head_arg)
 {
        int index_fd;
        struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
@@ -709,7 +708,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
                        commit_list_insert(j->item, &reversed);
 
                index_fd = hold_locked_index(lock, 1);
-               clean = merge_recursive(&o, lookup_commit(head),
+               clean = merge_recursive(&o, head,
                                remoteheads->item, reversed, &result);
                if (active_cache_changed &&
                                (write_cache(index_fd, active_cache, active_nr) ||
@@ -860,25 +859,26 @@ static void run_prepare_commit_msg(void)
        read_merge_msg();
 }
 
-static int merge_trivial(void)
+static int merge_trivial(struct commit *head)
 {
        unsigned char result_tree[20], result_commit[20];
        struct commit_list *parent = xmalloc(sizeof(*parent));
 
        write_tree_trivial(result_tree);
        printf(_("Wonderful.\n"));
-       parent->item = lookup_commit(head);
+       parent->item = head;
        parent->next = xmalloc(sizeof(*parent->next));
        parent->next->item = remoteheads->item;
        parent->next->next = NULL;
        run_prepare_commit_msg();
        commit_tree(merge_msg.buf, result_tree, parent, result_commit, NULL);
-       finish(result_commit, "In-index merge");
+       finish(head, result_commit, "In-index merge");
        drop_save();
        return 0;
 }
 
-static int finish_automerge(struct commit_list *common,
+static int finish_automerge(struct commit *head,
+                           struct commit_list *common,
                            unsigned char *result_tree,
                            const char *wt_strategy)
 {
@@ -889,12 +889,12 @@ static int finish_automerge(struct commit_list *common,
        free_commit_list(common);
        if (allow_fast_forward) {
                parents = remoteheads;
-               commit_list_insert(lookup_commit(head), &parents);
+               commit_list_insert(head, &parents);
                parents = reduce_heads(parents);
        } else {
                struct commit_list **pptr = &parents;
 
-               pptr = &commit_list_insert(lookup_commit(head),
+               pptr = &commit_list_insert(head,
                                pptr)->next;
                for (j = remoteheads; j; j = j->next)
                        pptr = &commit_list_insert(j->item, pptr)->next;
@@ -903,8 +903,8 @@ static int finish_automerge(struct commit_list *common,
        strbuf_addch(&merge_msg, '\n');
        run_prepare_commit_msg();
        commit_tree(merge_msg.buf, result_tree, parents, result_commit, NULL);
-       strbuf_addf(&buf, "Merge made by %s.", wt_strategy);
-       finish(result_commit, buf.buf);
+       strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
+       finish(head, result_commit, buf.buf);
        strbuf_release(&buf);
        drop_save();
        return 0;
@@ -938,7 +938,8 @@ static int suggest_conflicts(int renormalizing)
        return 1;
 }
 
-static struct commit *is_old_style_invocation(int argc, const char **argv)
+static struct commit *is_old_style_invocation(int argc, const char **argv,
+                                             const unsigned char *head)
 {
        struct commit *second_token = NULL;
        if (argc > 2) {
@@ -1010,9 +1011,12 @@ static int setup_with_upstream(const char ***argv)
 int cmd_merge(int argc, const char **argv, const char *prefix)
 {
        unsigned char result_tree[20];
+       unsigned char stash[20];
+       unsigned char head_sha1[20];
+       struct commit *head_commit;
        struct strbuf buf = STRBUF_INIT;
        const char *head_arg;
-       int flag, head_invalid = 0, i;
+       int flag, i;
        int best_cnt = -1, merge_was_ok = 0, automerge_was_ok = 0;
        struct commit_list *common = NULL;
        const char *best_strategy = NULL, *wt_strategy = NULL;
@@ -1025,18 +1029,16 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
         * Check if we are _not_ on a detached HEAD, i.e. if there is a
         * current branch.
         */
-       branch = resolve_ref("HEAD", head, 0, &flag);
+       branch = resolve_ref("HEAD", head_sha1, 0, &flag);
        if (branch && !prefixcmp(branch, "refs/heads/"))
                branch += 11;
-       if (is_null_sha1(head))
-               head_invalid = 1;
+       if (!branch || is_null_sha1(head_sha1))
+               head_commit = NULL;
+       else
+               head_commit = lookup_commit_or_die(head_sha1, "HEAD");
 
        git_config(git_merge_config, NULL);
 
-       /* for color.ui */
-       if (diff_use_color_default == -1)
-               diff_use_color_default = git_use_color_default;
-
        if (branch_mergeoptions)
                parse_branch_merge_options(branch_mergeoptions);
        argc = parse_options(argc, argv, prefix, builtin_merge_options,
@@ -1110,12 +1112,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
         * additional safety measure to check for it.
         */
 
-       if (!have_message && is_old_style_invocation(argc, argv)) {
+       if (!have_message && head_commit &&
+           is_old_style_invocation(argc, argv, head_commit->object.sha1)) {
                strbuf_addstr(&merge_msg, argv[0]);
                head_arg = argv[1];
                argv += 2;
                argc -= 2;
-       } else if (head_invalid) {
+       } else if (!head_commit) {
                struct object *remote_head;
                /*
                 * If the merged head is a valid one there is no reason
@@ -1162,7 +1165,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                }
        }
 
-       if (head_invalid || !argc)
+       if (!head_commit || !argc)
                usage_with_options(builtin_merge_usage,
                        builtin_merge_options);
 
@@ -1203,17 +1206,16 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        }
 
        if (!remoteheads->next)
-               common = get_merge_bases(lookup_commit(head),
-                               remoteheads->item, 1);
+               common = get_merge_bases(head_commit, remoteheads->item, 1);
        else {
                struct commit_list *list = remoteheads;
-               commit_list_insert(lookup_commit(head), &list);
+               commit_list_insert(head_commit, &list);
                common = get_octopus_merge_bases(list);
                free(list);
        }
 
-       update_ref("updating ORIG_HEAD", "ORIG_HEAD", head, NULL, 0,
-               DIE_ON_ERR);
+       update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.sha1,
+                  NULL, 0, DIE_ON_ERR);
 
        if (!common)
                ; /* No common ancestors found. We need a real merge. */
@@ -1227,13 +1229,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                return 0;
        } else if (allow_fast_forward && !remoteheads->next &&
                        !common->next &&
-                       !hashcmp(common->item->object.sha1, head)) {
+                       !hashcmp(common->item->object.sha1, head_commit->object.sha1)) {
                /* Again the most common case of merging one remote. */
                struct strbuf msg = STRBUF_INIT;
                struct object *o;
                char hex[41];
 
-               strcpy(hex, find_unique_abbrev(head, DEFAULT_ABBREV));
+               strcpy(hex, find_unique_abbrev(head_commit->object.sha1, DEFAULT_ABBREV));
 
                if (verbosity >= 0)
                        printf(_("Updating %s..%s\n"),
@@ -1249,10 +1251,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                if (!o)
                        return 1;
 
-               if (checkout_fast_forward(head, remoteheads->item->object.sha1))
+               if (checkout_fast_forward(head_commit->object.sha1, remoteheads->item->object.sha1))
                        return 1;
 
-               finish(o->sha1, msg.buf);
+               finish(head_commit, o->sha1, msg.buf);
                drop_save();
                return 0;
        } else if (!remoteheads->next && common->next)
@@ -1272,8 +1274,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                        git_committer_info(IDENT_ERROR_ON_NO_NAME);
                        printf(_("Trying really trivial in-index merge...\n"));
                        if (!read_tree_trivial(common->item->object.sha1,
-                                       head, remoteheads->item->object.sha1))
-                               return merge_trivial();
+                                       head_commit->object.sha1, remoteheads->item->object.sha1))
+                               return merge_trivial(head_commit);
                        printf(_("Nope.\n"));
                }
        } else {
@@ -1292,8 +1294,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                         * merge_bases again, otherwise "git merge HEAD^
                         * HEAD^^" would be missed.
                         */
-                       common_one = get_merge_bases(lookup_commit(head),
-                               j->item, 1);
+                       common_one = get_merge_bases(head_commit, j->item, 1);
                        if (hashcmp(common_one->item->object.sha1,
                                j->item->object.sha1)) {
                                up_to_date = 0;
@@ -1320,21 +1321,18 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
         * sync with the head commit.  The strategies are responsible
         * to ensure this.
         */
-       if (use_strategies_nr != 1) {
-               /*
-                * Stash away the local changes so that we can try more
-                * than one.
-                */
-               save_state();
-       } else {
-               memcpy(stash, null_sha1, 20);
-       }
+       if (use_strategies_nr == 1 ||
+           /*
+            * Stash away the local changes so that we can try more than one.
+            */
+           save_state(stash))
+               hashcpy(stash, null_sha1);
 
        for (i = 0; i < use_strategies_nr; i++) {
                int ret;
                if (i) {
                        printf(_("Rewinding the tree to pristine...\n"));
-                       restore_state();
+                       restore_state(head_commit->object.sha1, stash);
                }
                if (use_strategies_nr != 1)
                        printf(_("Trying merge strategy %s...\n"),
@@ -1346,7 +1344,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                wt_strategy = use_strategies[i]->name;
 
                ret = try_merge_strategy(use_strategies[i]->name,
-                       common, head_arg);
+                                        common, head_commit, head_arg);
                if (!option_commit && !ret) {
                        merge_was_ok = 1;
                        /*
@@ -1388,14 +1386,15 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
         * auto resolved the merge cleanly.
         */
        if (automerge_was_ok)
-               return finish_automerge(common, result_tree, wt_strategy);
+               return finish_automerge(head_commit, common, result_tree,
+                                       wt_strategy);
 
        /*
         * Pick the result from the best strategy and have the user fix
         * it up.
         */
        if (!best_strategy) {
-               restore_state();
+               restore_state(head_commit->object.sha1, stash);
                if (use_strategies_nr > 1)
                        fprintf(stderr,
                                _("No merge strategy handled the merge.\n"));
@@ -1407,14 +1406,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                ; /* We already have its result in the working tree. */
        else {
                printf(_("Rewinding the tree to pristine...\n"));
-               restore_state();
+               restore_state(head_commit->object.sha1, stash);
                printf(_("Using the %s to prepare resolving by hand.\n"),
                        best_strategy);
-               try_merge_strategy(best_strategy, common, head_arg);
+               try_merge_strategy(best_strategy, common, head_commit, head_arg);
        }
 
        if (squash)
-               finish(NULL, NULL);
+               finish(head_commit, NULL, NULL);
        else {
                int fd;
                struct commit_list *j;
index 40f33ca4d0e6d0bb1733e0544029c6f588d09b59..5efe6c5760c43d0059a940ab9d4610b97092c8bd 100644 (file)
@@ -29,7 +29,11 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
                        to_copy--;
                if (to_copy != length || base_name) {
                        char *it = xmemdupz(result[i], to_copy);
-                       result[i] = base_name ? strdup(basename(it)) : it;
+                       if (base_name) {
+                               result[i] = xstrdup(basename(it));
+                               free(it);
+                       } else
+                               result[i] = it;
                }
        }
        return get_pathspec(prefix, result);
index 84e6dafb12657a6f0431f2a287d0cca976269c35..a9c67c18ba159c8f04fa6bfff52ed9718965190a 100644 (file)
@@ -51,6 +51,8 @@ struct object_entry {
                                       * objects against.
                                       */
        unsigned char no_try_delta;
+       unsigned char tagged; /* near the very tip of refs */
+       unsigned char filled; /* assigned write-order */
 };
 
 /*
@@ -96,6 +98,7 @@ static unsigned long window_memory_limit = 0;
  */
 static int *object_ix;
 static int object_ix_hashsz;
+static struct object_entry *locate_object_entry(const unsigned char *sha1);
 
 /*
  * stats
@@ -200,6 +203,7 @@ static void copy_pack_data(struct sha1file *f,
        }
 }
 
+/* Return 0 if we will bust the pack-size limit */
 static unsigned long write_object(struct sha1file *f,
                                  struct object_entry *entry,
                                  off_t write_offset)
@@ -434,6 +438,134 @@ static int write_one(struct sha1file *f,
        return 1;
 }
 
+static int mark_tagged(const char *path, const unsigned char *sha1, int flag,
+                      void *cb_data)
+{
+       unsigned char peeled[20];
+       struct object_entry *entry = locate_object_entry(sha1);
+
+       if (entry)
+               entry->tagged = 1;
+       if (!peel_ref(path, peeled)) {
+               entry = locate_object_entry(peeled);
+               if (entry)
+                       entry->tagged = 1;
+       }
+       return 0;
+}
+
+static void add_to_write_order(struct object_entry **wo,
+                              int *endp,
+                              struct object_entry *e)
+{
+       if (e->filled)
+               return;
+       wo[(*endp)++] = e;
+       e->filled = 1;
+}
+
+static void add_descendants_to_write_order(struct object_entry **wo,
+                                          int *endp,
+                                          struct object_entry *e)
+{
+       struct object_entry *child;
+
+       for (child = e->delta_child; child; child = child->delta_sibling)
+               add_to_write_order(wo, endp, child);
+       for (child = e->delta_child; child; child = child->delta_sibling)
+               add_descendants_to_write_order(wo, endp, child);
+}
+
+static void add_family_to_write_order(struct object_entry **wo,
+                                     int *endp,
+                                     struct object_entry *e)
+{
+       struct object_entry *root;
+
+       for (root = e; root->delta; root = root->delta)
+               ; /* nothing */
+       add_to_write_order(wo, endp, root);
+       add_descendants_to_write_order(wo, endp, root);
+}
+
+static struct object_entry **compute_write_order(void)
+{
+       int i, wo_end;
+
+       struct object_entry **wo = xmalloc(nr_objects * sizeof(*wo));
+
+       for (i = 0; i < nr_objects; i++) {
+               objects[i].tagged = 0;
+               objects[i].filled = 0;
+               objects[i].delta_child = NULL;
+               objects[i].delta_sibling = NULL;
+       }
+
+       /*
+        * Fully connect delta_child/delta_sibling network.
+        * Make sure delta_sibling is sorted in the original
+        * recency order.
+        */
+       for (i = nr_objects - 1; 0 <= i; i--) {
+               struct object_entry *e = &objects[i];
+               if (!e->delta)
+                       continue;
+               /* Mark me as the first child */
+               e->delta_sibling = e->delta->delta_child;
+               e->delta->delta_child = e;
+       }
+
+       /*
+        * Mark objects that are at the tip of tags.
+        */
+       for_each_tag_ref(mark_tagged, NULL);
+
+       /*
+        * Give the commits in the original recency order until
+        * we see a tagged tip.
+        */
+       for (i = wo_end = 0; i < nr_objects; i++) {
+               if (objects[i].tagged)
+                       break;
+               add_to_write_order(wo, &wo_end, &objects[i]);
+       }
+
+       /*
+        * Then fill all the tagged tips.
+        */
+       for (; i < nr_objects; i++) {
+               if (objects[i].tagged)
+                       add_to_write_order(wo, &wo_end, &objects[i]);
+       }
+
+       /*
+        * And then all remaining commits and tags.
+        */
+       for (i = 0; i < nr_objects; i++) {
+               if (objects[i].type != OBJ_COMMIT &&
+                   objects[i].type != OBJ_TAG)
+                       continue;
+               add_to_write_order(wo, &wo_end, &objects[i]);
+       }
+
+       /*
+        * And then all the trees.
+        */
+       for (i = 0; i < nr_objects; i++) {
+               if (objects[i].type != OBJ_TREE)
+                       continue;
+               add_to_write_order(wo, &wo_end, &objects[i]);
+       }
+
+       /*
+        * Finally all the rest in really tight order
+        */
+       for (i = 0; i < nr_objects; i++)
+               add_family_to_write_order(wo, &wo_end, &objects[i]);
+
+       return wo;
+}
+
 static void write_pack_file(void)
 {
        uint32_t i = 0, j;
@@ -442,10 +574,12 @@ static void write_pack_file(void)
        struct pack_header hdr;
        uint32_t nr_remaining = nr_result;
        time_t last_mtime = 0;
+       struct object_entry **write_order;
 
        if (progress > pack_to_stdout)
                progress_state = start_progress("Writing objects", nr_result);
        written_list = xmalloc(nr_objects * sizeof(*written_list));
+       write_order = compute_write_order();
 
        do {
                unsigned char sha1[20];
@@ -469,7 +603,8 @@ static void write_pack_file(void)
                offset = sizeof(hdr);
                nr_written = 0;
                for (; i < nr_objects; i++) {
-                       if (!write_one(f, objects + i, &offset))
+                       struct object_entry *e = write_order[i];
+                       if (!write_one(f, e, &offset))
                                break;
                        display_progress(progress_state, written);
                }
@@ -546,6 +681,7 @@ static void write_pack_file(void)
        } while (nr_remaining && i < nr_objects);
 
        free(written_list);
+       free(write_order);
        stop_progress(&progress_state);
        if (written != nr_result)
                die("wrote %"PRIu32" objects while expecting %"PRIu32,
@@ -634,7 +770,7 @@ static int no_try_delta(const char *path)
        struct git_attr_check check[1];
 
        setup_delta_attr_check(check);
-       if (git_checkattr(path, ARRAY_SIZE(check), check))
+       if (git_check_attr(path, ARRAY_SIZE(check), check))
                return 0;
        if (ATTR_FALSE(check->value))
                return 1;
index f821eb3f0b864c26d5e822cc7c5b0747340abee5..3cfe02d5a5716de1a3aaa5edc1ca0e3d74c03b03 100644 (file)
@@ -56,13 +56,13 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
        return 1;
 }
 
-static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx)
+static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx, struct strbuf *line_buf)
 {
-       static char line[1000];
        int patchlen = 0, found_next = 0;
        int before = -1, after = -1;
 
-       while (fgets(line, sizeof(line), stdin) != NULL) {
+       while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
+               char *line = line_buf->buf;
                char *p = line;
                int len;
 
@@ -133,14 +133,16 @@ static void generate_id_list(void)
        unsigned char sha1[20], n[20];
        git_SHA_CTX ctx;
        int patchlen;
+       struct strbuf line_buf = STRBUF_INIT;
 
        git_SHA1_Init(&ctx);
        hashclr(sha1);
        while (!feof(stdin)) {
-               patchlen = get_one_patchid(n, &ctx);
+               patchlen = get_one_patchid(n, &ctx, &line_buf);
                flush_current_id(patchlen, sha1, &ctx);
                hashcpy(sha1, n);
        }
+       strbuf_release(&line_buf);
 }
 
 static const char patch_id_usage[] = "git patch-id < patch";
index 9cebf9ea234d968eab638f7dcdc65370f77c0047..35cce532f2bb632e01c0de0a8e6f9e1395eece88 100644 (file)
@@ -8,6 +8,7 @@
 #include "remote.h"
 #include "transport.h"
 #include "parse-options.h"
+#include "submodule.h"
 
 static const char * const push_usage[] = {
        "git push [<options>] [<repository> [<refspec>...]]",
@@ -219,6 +220,21 @@ static int do_push(const char *repo, int flags)
        return !!errs;
 }
 
+static int option_parse_recurse_submodules(const struct option *opt,
+                                  const char *arg, int unset)
+{
+       int *flags = opt->value;
+       if (arg) {
+               if (!strcmp(arg, "check"))
+                       *flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
+               else
+                       die("bad %s argument: %s", opt->long_name, arg);
+       } else
+               die("option %s needs an argument (check)", opt->long_name);
+
+       return 0;
+}
+
 int cmd_push(int argc, const char **argv, const char *prefix)
 {
        int flags = 0;
@@ -236,6 +252,9 @@ int cmd_push(int argc, const char **argv, const char *prefix)
                OPT_BIT('n' , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN),
                OPT_BIT( 0,  "porcelain", &flags, "machine-readable output", TRANSPORT_PUSH_PORCELAIN),
                OPT_BIT('f', "force", &flags, "force updates", TRANSPORT_PUSH_FORCE),
+               { OPTION_CALLBACK, 0, "recurse-submodules", &flags, "check",
+                       "controls recursive pushing of submodules",
+                       PARSE_OPT_OPTARG, option_parse_recurse_submodules },
                OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"),
                OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", "receive pack program"),
                OPT_STRING( 0 , "exec", &receivepack, "receive-pack", "receive pack program"),
index e1a687ad0761e46f6ec95659bb585b9014d4abf4..af429e101777f1c5df09734433278cfb075e978c 100644 (file)
@@ -120,9 +120,25 @@ static int show_ref(const char *path, const unsigned char *sha1, int flag, void
        return 0;
 }
 
+static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *cb_data)
+{
+       path = strip_namespace(path);
+       /*
+        * Advertise refs outside our current namespace as ".have"
+        * refs, so that the client can use them to minimize data
+        * transfer but will otherwise ignore them. This happens to
+        * cover ".have" that are thrown in by add_one_alternate_ref()
+        * to mark histories that are complete in our alternates as
+        * well.
+        */
+       if (!path)
+               path = ".have";
+       return show_ref(path, sha1, flag, cb_data);
+}
+
 static void write_head_info(void)
 {
-       for_each_ref(show_ref, NULL);
+       for_each_ref(show_ref_cb, NULL);
        if (!sent_capabilities)
                show_ref("capabilities^{}", null_sha1, 0, NULL);
 
@@ -189,21 +205,15 @@ static int copy_to_sideband(int in, int out, void *arg)
        return 0;
 }
 
-static int run_receive_hook(struct command *commands, const char *hook_name)
+typedef int (*feed_fn)(void *, const char **, size_t *);
+static int run_and_feed_hook(const char *hook_name, feed_fn feed, void *feed_state)
 {
-       static char buf[sizeof(commands->old_sha1) * 2 + PATH_MAX + 4];
-       struct command *cmd;
        struct child_process proc;
        struct async muxer;
        const char *argv[2];
-       int have_input = 0, code;
-
-       for (cmd = commands; !have_input && cmd; cmd = cmd->next) {
-               if (!cmd->error_string)
-                       have_input = 1;
-       }
+       int code;
 
-       if (!have_input || access(hook_name, X_OK) < 0)
+       if (access(hook_name, X_OK) < 0)
                return 0;
 
        argv[0] = hook_name;
@@ -231,15 +241,13 @@ static int run_receive_hook(struct command *commands, const char *hook_name)
                return code;
        }
 
-       for (cmd = commands; cmd; cmd = cmd->next) {
-               if (!cmd->error_string) {
-                       size_t n = snprintf(buf, sizeof(buf), "%s %s %s\n",
-                               sha1_to_hex(cmd->old_sha1),
-                               sha1_to_hex(cmd->new_sha1),
-                               cmd->ref_name);
-                       if (write_in_full(proc.in, buf, n) != n)
-                               break;
-               }
+       while (1) {
+               const char *buf;
+               size_t n;
+               if (feed(feed_state, &buf, &n))
+                       break;
+               if (write_in_full(proc.in, buf, n) != n)
+                       break;
        }
        close(proc.in);
        if (use_sideband)
@@ -247,6 +255,47 @@ static int run_receive_hook(struct command *commands, const char *hook_name)
        return finish_command(&proc);
 }
 
+struct receive_hook_feed_state {
+       struct command *cmd;
+       struct strbuf buf;
+};
+
+static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep)
+{
+       struct receive_hook_feed_state *state = state_;
+       struct command *cmd = state->cmd;
+
+       while (cmd && cmd->error_string)
+               cmd = cmd->next;
+       if (!cmd)
+               return -1; /* EOF */
+       strbuf_reset(&state->buf);
+       strbuf_addf(&state->buf, "%s %s %s\n",
+                   sha1_to_hex(cmd->old_sha1), sha1_to_hex(cmd->new_sha1),
+                   cmd->ref_name);
+       state->cmd = cmd->next;
+       if (bufp) {
+               *bufp = state->buf.buf;
+               *sizep = state->buf.len;
+       }
+       return 0;
+}
+
+static int run_receive_hook(struct command *commands, const char *hook_name)
+{
+       struct receive_hook_feed_state state;
+       int status;
+
+       strbuf_init(&state.buf, 0);
+       state.cmd = commands;
+       if (feed_receive_hook(&state, NULL, NULL))
+               return 0;
+       state.cmd = commands;
+       status = run_and_feed_hook(hook_name, feed_receive_hook, &state);
+       strbuf_release(&state.buf);
+       return status;
+}
+
 static int run_update_hook(struct command *cmd)
 {
        static const char update_hook[] = "hooks/update";
@@ -333,6 +382,8 @@ static void refuse_unconfigured_deny_delete_current(void)
 static const char *update(struct command *cmd)
 {
        const char *name = cmd->ref_name;
+       struct strbuf namespaced_name_buf = STRBUF_INIT;
+       const char *namespaced_name;
        unsigned char *old_sha1 = cmd->old_sha1;
        unsigned char *new_sha1 = cmd->new_sha1;
        struct ref_lock *lock;
@@ -343,7 +394,10 @@ static const char *update(struct command *cmd)
                return "funny refname";
        }
 
-       if (is_ref_checked_out(name)) {
+       strbuf_addf(&namespaced_name_buf, "%s%s", get_git_namespace(), name);
+       namespaced_name = strbuf_detach(&namespaced_name_buf, NULL);
+
+       if (is_ref_checked_out(namespaced_name)) {
                switch (deny_current_branch) {
                case DENY_IGNORE:
                        break;
@@ -371,7 +425,7 @@ static const char *update(struct command *cmd)
                        return "deletion prohibited";
                }
 
-               if (!strcmp(name, head_name)) {
+               if (!strcmp(namespaced_name, head_name)) {
                        switch (deny_delete_current) {
                        case DENY_IGNORE:
                                break;
@@ -427,14 +481,14 @@ static const char *update(struct command *cmd)
                        rp_warning("Allowing deletion of corrupt ref.");
                        old_sha1 = NULL;
                }
-               if (delete_ref(name, old_sha1, 0)) {
+               if (delete_ref(namespaced_name, old_sha1, 0)) {
                        rp_error("failed to delete %s", name);
                        return "failed to delete";
                }
                return NULL; /* good */
        }
        else {
-               lock = lock_any_ref_for_update(name, old_sha1, 0);
+               lock = lock_any_ref_for_update(namespaced_name, old_sha1, 0);
                if (!lock) {
                        rp_error("failed to lock %s", name);
                        return "failed to lock";
@@ -491,17 +545,29 @@ static void run_update_post_hook(struct command *commands)
 
 static void check_aliased_update(struct command *cmd, struct string_list *list)
 {
+       struct strbuf buf = STRBUF_INIT;
+       const char *dst_name;
        struct string_list_item *item;
        struct command *dst_cmd;
        unsigned char sha1[20];
        char cmd_oldh[41], cmd_newh[41], dst_oldh[41], dst_newh[41];
        int flag;
 
-       const char *dst_name = resolve_ref(cmd->ref_name, sha1, 0, &flag);
+       strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
+       dst_name = resolve_ref(buf.buf, sha1, 0, &flag);
+       strbuf_release(&buf);
 
        if (!(flag & REF_ISSYMREF))
                return;
 
+       dst_name = strip_namespace(dst_name);
+       if (!dst_name) {
+               rp_error("refusing update to broken symref '%s'", cmd->ref_name);
+               cmd->skip_update = 1;
+               cmd->error_string = "broken symref";
+               return;
+       }
+
        if ((item = string_list_lookup(list, dst_name)) == NULL)
                return;
 
index ebf610e64a267c5ca769d70203b282fb8f96a434..3a9c80f3dbfe26d5623c118fc0fcaa257e01b973 100644 (file)
@@ -777,6 +777,5 @@ int cmd_reflog(int argc, const char **argv, const char *prefix)
        if (!strcmp(argv[1], "delete"))
                return cmd_reflog_delete(argc - 1, argv + 1, prefix);
 
-       /* Not a recognized reflog command..*/
-       usage(reflog_usage);
+       return cmd_log_reflog(argc, argv, prefix);
 }
index 05b1f5b76de36b19ef4bebba32aff1b40cbc2030..e1285becffd768c88b4802425f0f5901cda83f06 100644 (file)
@@ -349,7 +349,8 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
                else
                        string_list_append(&states->tracked, abbrev_branch(ref->name));
        }
-       stale_refs = get_stale_heads(states->remote, fetch_map);
+       stale_refs = get_stale_heads(states->remote->fetch,
+                                    states->remote->fetch_refspec_nr, fetch_map);
        for (ref = stale_refs; ref; ref = ref->next) {
                struct string_list_item *item =
                        string_list_append(&states->stale, abbrev_branch(ref->name));
@@ -570,7 +571,7 @@ static int read_remote_branches(const char *refname,
        unsigned char orig_sha1[20];
        const char *symref;
 
-       strbuf_addf(&buf, "refs/remotes/%s", rename->old);
+       strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
        if (!prefixcmp(refname, buf.buf)) {
                item = string_list_append(rename->remote_branches, xstrdup(refname));
                symref = resolve_ref(refname, orig_sha1, 1, &flag);
@@ -621,10 +622,11 @@ static int mv(int argc, const char **argv)
                OPT_END()
        };
        struct remote *oldremote, *newremote;
-       struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT;
+       struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT,
+               old_remote_context = STRBUF_INIT;
        struct string_list remote_branches = STRING_LIST_INIT_NODUP;
        struct rename_info rename;
-       int i;
+       int i, refspec_updated = 0;
 
        if (argc != 3)
                usage_with_options(builtin_remote_rename_usage, options);
@@ -659,15 +661,25 @@ static int mv(int argc, const char **argv)
        strbuf_addf(&buf, "remote.%s.fetch", rename.new);
        if (git_config_set_multivar(buf.buf, NULL, NULL, 1))
                return error("Could not remove config section '%s'", buf.buf);
+       strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old);
        for (i = 0; i < oldremote->fetch_refspec_nr; i++) {
                char *ptr;
 
                strbuf_reset(&buf2);
                strbuf_addstr(&buf2, oldremote->fetch_refspec[i]);
-               ptr = strstr(buf2.buf, rename.old);
-               if (ptr)
-                       strbuf_splice(&buf2, ptr-buf2.buf, strlen(rename.old),
-                                       rename.new, strlen(rename.new));
+               ptr = strstr(buf2.buf, old_remote_context.buf);
+               if (ptr) {
+                       refspec_updated = 1;
+                       strbuf_splice(&buf2,
+                                     ptr-buf2.buf + strlen(":refs/remotes/"),
+                                     strlen(rename.old), rename.new,
+                                     strlen(rename.new));
+               } else
+                       warning("Not updating non-default fetch respec\n"
+                               "\t%s\n"
+                               "\tPlease update the configuration manually if necessary.",
+                               buf2.buf);
+
                if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
                        return error("Could not append '%s'", buf.buf);
        }
@@ -685,6 +697,9 @@ static int mv(int argc, const char **argv)
                }
        }
 
+       if (!refspec_updated)
+               return 0;
+
        /*
         * First remove symrefs, then rename the rest, finally create
         * the new symrefs.
@@ -1103,7 +1118,7 @@ static int show(int argc, const char **argv)
                        url = states.remote->url;
                        url_nr = states.remote->url_nr;
                }
-               for (i=0; i < url_nr; i++)
+               for (i = 0; i < url_nr; i++)
                        printf("  Push  URL: %s\n", url[i]);
                if (!i)
                        printf("  Push  URL: %s\n", "(no URL)");
index 98bca044c1267fa63cb084a45aaf621e85f7d9b6..811e8e252c1c6a54e65179557203daf2bc42bdb9 100644 (file)
@@ -33,25 +33,6 @@ static const char *reset_type_names[] = {
        N_("mixed"), N_("soft"), N_("hard"), N_("merge"), N_("keep"), NULL
 };
 
-static char *args_to_str(const char **argv)
-{
-       char *buf = NULL;
-       unsigned long len, space = 0, nr = 0;
-
-       for (; *argv; argv++) {
-               len = strlen(*argv);
-               ALLOC_GROW(buf, nr + 1 + len, space);
-               if (nr)
-                       buf[nr++] = ' ';
-               memcpy(buf + nr, *argv, len);
-               nr += len;
-       }
-       ALLOC_GROW(buf, nr + 1, space);
-       buf[nr] = '\0';
-
-       return buf;
-}
-
 static inline int is_merge(void)
 {
        return !access(git_path("MERGE_HEAD"), F_OK);
@@ -162,7 +143,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
 
        for (i = 0; i < q->nr; i++) {
                struct diff_filespec *one = q->queue[i]->one;
-               if (one->mode) {
+               if (one->mode && !is_null_sha1(one->sha1)) {
                        struct cache_entry *ce;
                        ce = make_cache_entry(one->mode, one->sha1, one->path,
                                0, 0);
@@ -215,14 +196,18 @@ static int read_from_tree(const char *prefix, const char **argv,
        return update_index_refresh(index_fd, lock, refresh_flags);
 }
 
-static void prepend_reflog_action(const char *action, char *buf, size_t size)
+static void set_reflog_message(struct strbuf *sb, const char *action,
+                              const char *rev)
 {
-       const char *sep = ": ";
        const char *rla = getenv("GIT_REFLOG_ACTION");
-       if (!rla)
-               rla = sep = "";
-       if (snprintf(buf, size, "%s%s%s", rla, sep, action) >= size)
-               warning(_("Reflog action message too long: %.*s..."), 50, buf);
+
+       strbuf_reset(sb);
+       if (rla)
+               strbuf_addf(sb, "%s: %s", rla, action);
+       else if (rev)
+               strbuf_addf(sb, "reset: moving to %s", rev);
+       else
+               strbuf_addf(sb, "reset: %s", action);
 }
 
 static void die_if_unmerged_cache(int reset_type)
@@ -241,7 +226,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
        unsigned char sha1[20], *orig = NULL, sha1_orig[20],
                                *old_orig = NULL, sha1_old_orig[20];
        struct commit *commit;
-       char *reflog_action, msg[1024];
+       struct strbuf msg = STRBUF_INIT;
        const struct option options[] = {
                OPT__QUIET(&quiet, "be quiet, only report errors"),
                OPT_SET_INT(0, "mixed", &reset_type,
@@ -261,8 +246,6 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 
        argc = parse_options(argc, argv, prefix, options, git_reset_usage,
                                                PARSE_OPT_KEEP_DASHDASH);
-       reflog_action = args_to_str(argv);
-       setenv("GIT_REFLOG_ACTION", reflog_action, 0);
 
        /*
         * Possible arguments are:
@@ -357,13 +340,13 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                old_orig = sha1_old_orig;
        if (!get_sha1("HEAD", sha1_orig)) {
                orig = sha1_orig;
-               prepend_reflog_action("updating ORIG_HEAD", msg, sizeof(msg));
-               update_ref(msg, "ORIG_HEAD", orig, old_orig, 0, MSG_ON_ERR);
+               set_reflog_message(&msg, "updating ORIG_HEAD", NULL);
+               update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0, MSG_ON_ERR);
        }
        else if (old_orig)
                delete_ref("ORIG_HEAD", old_orig, 0);
-       prepend_reflog_action("updating HEAD", msg, sizeof(msg));
-       update_ref_status = update_ref(msg, "HEAD", sha1, orig, 0, MSG_ON_ERR);
+       set_reflog_message(&msg, "updating HEAD", rev);
+       update_ref_status = update_ref(msg.buf, "HEAD", sha1, orig, 0, MSG_ON_ERR);
 
        switch (reset_type) {
        case HARD:
@@ -380,7 +363,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 
        remove_branch_state();
 
-       free(reflog_action);
+       strbuf_release(&msg);
 
        return update_ref_status;
 }
index 1f27c63343904a969e60ab19408495007f59d133..3117776c2c030bec03563f043c4dc8bb34eb17cd 100644 (file)
@@ -258,12 +258,7 @@ static void write_message(struct strbuf *msgbuf, const char *filename)
 
 static struct tree *empty_tree(void)
 {
-       struct tree *tree = xcalloc(1, sizeof(struct tree));
-
-       tree->object.parsed = 1;
-       tree->object.type = OBJ_TREE;
-       pretend_sha1_file(NULL, 0, OBJ_TREE, tree->object.sha1);
-       return tree;
+       return lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN);
 }
 
 static NORETURN void die_dirty_index(const char *me)
index facc63a79ec0c86fd9df59792cd4f20030af5db1..4b480d7c7ca6c6258a5cd82cfc88df62cd0d218f 100644 (file)
@@ -26,14 +26,14 @@ static const char **default_arg;
 
 static const char *get_color_code(int idx)
 {
-       if (showbranch_use_color)
+       if (want_color(showbranch_use_color))
                return column_colors_ansi[idx % column_colors_ansi_max];
        return "";
 }
 
 static const char *get_color_reset_code(void)
 {
-       if (showbranch_use_color)
+       if (want_color(showbranch_use_color))
                return GIT_COLOR_RESET;
        return "";
 }
@@ -573,7 +573,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
        }
 
        if (!strcmp(var, "color.showbranch")) {
-               showbranch_use_color = git_config_colorbool(var, value, -1);
+               showbranch_use_color = git_config_colorbool(var, value);
                return 0;
        }
 
@@ -685,9 +685,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 
        git_config(git_show_branch_config, NULL);
 
-       if (showbranch_use_color == -1)
-               showbranch_use_color = git_use_color_default;
-
        /* If nothing is specified, try the default first */
        if (ac == 1 && default_num) {
                ac = default_num;
index 76ba1d5881b3cddc527bd363dec340c83dde605f..835c62ab15c742af2f75e7bf66e35501701ed15a 100644 (file)
@@ -11,7 +11,7 @@ static const char * const git_update_ref_usage[] = {
 
 int cmd_update_ref(int argc, const char **argv, const char *prefix)
 {
-       const char *refname, *oldval, *msg=NULL;
+       const char *refname, *oldval, *msg = NULL;
        unsigned char sha1[20], oldsha1[20];
        int delete = 0, no_deref = 0, flags = 0;
        struct option options[] = {
index f48fd7d4c1c706b68e879e4dfabdd3fb8597a328..6bf849740c6de45fe8ca11eca2a06a52c7ebc0bb 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -380,12 +380,15 @@ int create_bundle(struct bundle_header *header, const char *path,
        return 0;
 }
 
-int unbundle(struct bundle_header *header, int bundle_fd)
+int unbundle(struct bundle_header *header, int bundle_fd, int flags)
 {
        const char *argv_index_pack[] = {"index-pack",
-               "--fix-thin", "--stdin", NULL};
+                                        "--fix-thin", "--stdin", NULL, NULL};
        struct child_process ip;
 
+       if (flags & BUNDLE_VERBOSE)
+               argv_index_pack[3] = "-v";
+
        if (verify_bundle(header, 0))
                return -1;
        memset(&ip, 0, sizeof(ip));
index e2aedd60d6ad1482bb6da173c853e6ba4805c8d7..c5a22c8d10c7bf5e27536a3b84033b77f3542445 100644 (file)
--- a/bundle.h
+++ b/bundle.h
@@ -18,7 +18,8 @@ int read_bundle_header(const char *path, struct bundle_header *header);
 int create_bundle(struct bundle_header *header, const char *path,
                int argc, const char **argv);
 int verify_bundle(struct bundle_header *header, int verbose);
-int unbundle(struct bundle_header *header, int bundle_fd);
+#define BUNDLE_VERBOSE 1
+int unbundle(struct bundle_header *header, int bundle_fd, int flags);
 int list_bundle_refs(struct bundle_header *header,
                int argc, const char **argv);
 
diff --git a/cache.h b/cache.h
index 9e12d55470435102215f2dd99eb3432856612dbd..8d95fb25a2505a408aea4beba43409facb578213 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -394,6 +394,7 @@ static inline enum object_type object_type(unsigned int mode)
 }
 
 #define GIT_DIR_ENVIRONMENT "GIT_DIR"
+#define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"
 #define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
 #define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
 #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
@@ -434,13 +435,16 @@ extern char *get_object_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_namespace(void);
+extern const char *strip_namespace(const char *namespaced_ref);
 extern const char *get_git_work_tree(void);
-extern const char *read_gitfile_gently(const char *path);
+extern const char *read_gitfile(const char *path);
 extern void set_git_work_tree(const char *tree);
 
 #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
 
 extern const char **get_pathspec(const char *prefix, const char **pathspec);
+extern const char *pathspec_prefix(const char *prefix, const char **pathspec);
 extern void setup_work_tree(void);
 extern const char *setup_git_directory_gently(int *);
 extern const char *setup_git_directory(void);
@@ -585,6 +589,7 @@ extern int warn_ambiguous_refs;
 extern int shared_repository;
 extern const char *apply_default_whitespace;
 extern const char *apply_default_ignorewhitespace;
+extern const char *git_attributes_file;
 extern int zlib_compression_level;
 extern int core_compression_level;
 extern int core_compression_seen;
@@ -773,6 +778,9 @@ extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
 /* global flag to enable extra checks when accessing packed objects */
 extern int do_check_packed_object_crc;
 
+/* for development: log offset of pack access */
+extern const char *log_pack_access;
+
 extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
 
 extern int move_temp_to_file(const char *tmpfile, const char *filename);
@@ -1188,7 +1196,7 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
 #define ws_tab_width(rule)     ((rule) & WS_TAB_WIDTH_MASK)
 
 /* ls-files */
-int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset);
+int report_path_error(const char *ps_matched, const char **pathspec, const char *prefix);
 void overlay_tree_on_cache(const char *tree_name, const char *prefix);
 
 char *alias_lookup(const char *alias);
diff --git a/color.c b/color.c
index 3db214c24720496f13481b718e46810c21f53b8d..e8e26818b3b1f2ffce1374e2edf88b40c575c3dd 100644 (file)
--- a/color.c
+++ b/color.c
@@ -1,7 +1,8 @@
 #include "cache.h"
 #include "color.h"
 
-int git_use_color_default = 0;
+static int git_use_color_default = 0;
+int color_stdout_is_tty = -1;
 
 /*
  * The list of available column colors.
@@ -157,7 +158,7 @@ bad:
        die("bad color value '%.*s' for variable '%s'", value_len, value, var);
 }
 
-int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
+int git_config_colorbool(const char *var, const char *value)
 {
        if (value) {
                if (!strcasecmp(value, "never"))
@@ -165,7 +166,7 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
                if (!strcasecmp(value, "always"))
                        return 1;
                if (!strcasecmp(value, "auto"))
-                       goto auto_color;
+                       return GIT_COLOR_AUTO;
        }
 
        if (!var)
@@ -176,10 +177,14 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
                return 0;
 
        /* any normal truth value defaults to 'auto' */
- auto_color:
-       if (stdout_is_tty < 0)
-               stdout_is_tty = isatty(1);
-       if (stdout_is_tty || (pager_in_use() && pager_use_color)) {
+       return GIT_COLOR_AUTO;
+}
+
+static int check_auto_color(void)
+{
+       if (color_stdout_is_tty < 0)
+               color_stdout_is_tty = isatty(1);
+       if (color_stdout_is_tty || (pager_in_use() && pager_use_color)) {
                char *term = getenv("TERM");
                if (term && strcmp(term, "dumb"))
                        return 1;
@@ -187,13 +192,36 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
        return 0;
 }
 
-int git_color_default_config(const char *var, const char *value, void *cb)
+int want_color(int var)
+{
+       static int want_auto = -1;
+
+       if (var < 0)
+               var = git_use_color_default;
+
+       if (var == GIT_COLOR_AUTO) {
+               if (want_auto < 0)
+                       want_auto = check_auto_color();
+               return want_auto;
+       }
+       return var;
+}
+
+int git_color_config(const char *var, const char *value, void *cb)
 {
        if (!strcmp(var, "color.ui")) {
-               git_use_color_default = git_config_colorbool(var, value, -1);
+               git_use_color_default = git_config_colorbool(var, value);
                return 0;
        }
 
+       return 0;
+}
+
+int git_color_default_config(const char *var, const char *value, void *cb)
+{
+       if (git_color_config(var, value, cb) < 0)
+               return -1;
+
        return git_default_config(var, value, cb);
 }
 
diff --git a/color.h b/color.h
index 68a926a2cdfb870ae0da0bfbc4c5b36681609911..9a8495bb7ff06eb4e94e190d902b48c23fc021f9 100644 (file)
--- a/color.h
+++ b/color.h
@@ -49,20 +49,34 @@ struct strbuf;
 #define GIT_COLOR_NIL "NIL"
 
 /*
- * This variable stores the value of color.ui
+ * The first three are chosen to match common usage in the code, and what is
+ * returned from git_config_colorbool. The "auto" value can be returned from
+ * config_colorbool, and will be converted by want_color() into either 0 or 1.
  */
-extern int git_use_color_default;
+#define GIT_COLOR_UNKNOWN -1
+#define GIT_COLOR_NEVER  0
+#define GIT_COLOR_ALWAYS 1
+#define GIT_COLOR_AUTO   2
 
 /* A default list of colors to use for commit graphs and show-branch output */
 extern const char *column_colors_ansi[];
 extern const int column_colors_ansi_max;
 
 /*
- * Use this instead of git_default_config if you need the value of color.ui.
+ * Generally the color code will lazily figure this out itself, but
+ * this provides a mechanism for callers to override autodetection.
  */
+extern int color_stdout_is_tty;
+
+/*
+ * Use the first one if you need only color config; the second is a convenience
+ * if you are just going to change to git_default_config, too.
+ */
+int git_color_config(const char *var, const char *value, void *cb);
 int git_color_default_config(const char *var, const char *value, void *cb);
 
-int git_config_colorbool(const char *var, const char *value, int stdout_is_tty);
+int git_config_colorbool(const char *var, const char *value);
+int want_color(int var);
 void color_parse(const char *value, const char *var, char *dst);
 void color_parse_mem(const char *value, int len, const char *var, char *dst);
 __attribute__((format (printf, 3, 4)))
index be67cfcd45469497f81e0c36ed87a11fd409daee..214014dc645e43ae257e46f1046c8ca0d21d3472 100644 (file)
@@ -702,9 +702,8 @@ static void show_combined_header(struct combine_diff_path *elem,
        int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
        const char *a_prefix = opt->a_prefix ? opt->a_prefix : "a/";
        const char *b_prefix = opt->b_prefix ? opt->b_prefix : "b/";
-       int use_color = DIFF_OPT_TST(opt, COLOR_DIFF);
-       const char *c_meta = diff_get_color(use_color, DIFF_METAINFO);
-       const char *c_reset = diff_get_color(use_color, DIFF_RESET);
+       const char *c_meta = diff_get_color_opt(opt, DIFF_METAINFO);
+       const char *c_reset = diff_get_color_opt(opt, DIFF_RESET);
        const char *abb;
        int added = 0;
        int deleted = 0;
@@ -768,7 +767,8 @@ static void show_combined_header(struct combine_diff_path *elem,
 }
 
 static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
-                           int dense, struct rev_info *rev)
+                           int dense, int working_tree_file,
+                           struct rev_info *rev)
 {
        struct diff_options *opt = &rev->diffopt;
        unsigned long result_size, cnt, lno;
@@ -777,7 +777,6 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
        struct sline *sline; /* survived lines */
        int mode_differs = 0;
        int i, show_hunks;
-       int working_tree_file = is_null_sha1(elem->sha1);
        mmfile_t result_file;
        struct userdiff_driver *userdiff;
        struct userdiff_driver *textconv = NULL;
@@ -964,7 +963,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                show_combined_header(elem, num_parent, dense, rev,
                                     mode_differs, 1);
                dump_sline(sline, cnt, num_parent,
-                          DIFF_OPT_TST(opt, COLOR_DIFF), result_deleted);
+                          opt->use_color, result_deleted);
        }
        free(result);
 
@@ -1028,6 +1027,12 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
        write_name_quoted(p->path, stdout, line_termination);
 }
 
+/*
+ * The result (p->elem) is from the working tree and their
+ * parents are typically from multiple stages during a merge
+ * (i.e. diff-files) or the state in HEAD and in the index
+ * (i.e. diff-index).
+ */
 void show_combined_diff(struct combine_diff_path *p,
                       int num_parent,
                       int dense,
@@ -1041,7 +1046,73 @@ void show_combined_diff(struct combine_diff_path *p,
                                  DIFF_FORMAT_NAME_STATUS))
                show_raw_diff(p, num_parent, rev);
        else if (opt->output_format & DIFF_FORMAT_PATCH)
-               show_patch_diff(p, num_parent, dense, rev);
+               show_patch_diff(p, num_parent, dense, 1, rev);
+}
+
+static void free_combined_pair(struct diff_filepair *pair)
+{
+       free(pair->two);
+       free(pair);
+}
+
+/*
+ * A combine_diff_path expresses N parents on the LHS against 1 merge
+ * result. Synthesize a diff_filepair that has N entries on the "one"
+ * side and 1 entry on the "two" side.
+ *
+ * In the future, we might want to add more data to combine_diff_path
+ * so that we can fill fields we are ignoring (most notably, size) here,
+ * but currently nobody uses it, so this should suffice for now.
+ */
+static struct diff_filepair *combined_pair(struct combine_diff_path *p,
+                                          int num_parent)
+{
+       int i;
+       struct diff_filepair *pair;
+       struct diff_filespec *pool;
+
+       pair = xmalloc(sizeof(*pair));
+       pool = xcalloc(num_parent + 1, sizeof(struct diff_filespec));
+       pair->one = pool + 1;
+       pair->two = pool;
+
+       for (i = 0; i < num_parent; i++) {
+               pair->one[i].path = p->path;
+               pair->one[i].mode = p->parent[i].mode;
+               hashcpy(pair->one[i].sha1, p->parent[i].sha1);
+               pair->one[i].sha1_valid = !is_null_sha1(p->parent[i].sha1);
+               pair->one[i].has_more_entries = 1;
+       }
+       pair->one[num_parent - 1].has_more_entries = 0;
+
+       pair->two->path = p->path;
+       pair->two->mode = p->mode;
+       hashcpy(pair->two->sha1, p->sha1);
+       pair->two->sha1_valid = !is_null_sha1(p->sha1);
+       return pair;
+}
+
+static void handle_combined_callback(struct diff_options *opt,
+                                    struct combine_diff_path *paths,
+                                    int num_parent,
+                                    int num_paths)
+{
+       struct combine_diff_path *p;
+       struct diff_queue_struct q;
+       int i;
+
+       q.queue = xcalloc(num_paths, sizeof(struct diff_filepair *));
+       q.alloc = num_paths;
+       q.nr = num_paths;
+       for (i = 0, p = paths; p; p = p->next) {
+               if (!p->len)
+                       continue;
+               q.queue[i++] = combined_pair(p, num_parent);
+       }
+       opt->format_callback(&q, opt, opt->format_callback_data);
+       for (i = 0; i < num_paths; i++)
+               free_combined_pair(q.queue[i]);
+       free(q.queue);
 }
 
 void diff_tree_combined(const unsigned char *sha1,
@@ -1103,13 +1174,16 @@ void diff_tree_combined(const unsigned char *sha1,
                else if (opt->output_format &
                         (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT))
                        needsep = 1;
+               else if (opt->output_format & DIFF_FORMAT_CALLBACK)
+                       handle_combined_callback(opt, paths, num_parent, num_paths);
+
                if (opt->output_format & DIFF_FORMAT_PATCH) {
                        if (needsep)
                                putchar(opt->line_termination);
                        for (p = paths; p; p = p->next) {
                                if (p->len)
                                        show_patch_diff(p, num_parent, dense,
-                                                       rev);
+                                                       0, rev);
                        }
                }
        }
index ac337c7d7dc1724fa918f9340816d3102edb10bd..9f4cc636dd74e99a1311500e15501bdb4875cb9d 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -39,6 +39,18 @@ struct commit *lookup_commit_reference(const unsigned char *sha1)
        return lookup_commit_reference_gently(sha1, 0);
 }
 
+struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_name)
+{
+       struct commit *c = lookup_commit_reference(sha1);
+       if (!c)
+               die(_("could not parse %s"), ref_name);
+       if (hashcmp(sha1, c->object.sha1)) {
+               warning(_("%s %s is not a commit!"),
+                       ref_name, sha1_to_hex(sha1));
+       }
+       return c;
+}
+
 struct commit *lookup_commit(const unsigned char *sha1)
 {
        struct object *obj = lookup_object(sha1);
@@ -214,22 +226,12 @@ struct commit_graft *lookup_commit_graft(const unsigned char *sha1)
        return commit_graft[pos];
 }
 
-int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
+int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
 {
-       int i, count = 0;
-       for (i = 0; i < commit_graft_nr; i++)
-               if (commit_graft[i]->nr_parent < 0) {
-                       const char *hex =
-                               sha1_to_hex(commit_graft[i]->sha1);
-                       count++;
-                       if (use_pack_protocol)
-                               packet_buf_write(out, "shallow %s", hex);
-                       else {
-                               strbuf_addstr(out, hex);
-                               strbuf_addch(out, '\n');
-                       }
-               }
-       return count;
+       int i, ret;
+       for (i = ret = 0; i < commit_graft_nr && !ret; i++)
+               ret = fn(commit_graft[i], cb_data);
+       return ret;
 }
 
 int unregister_shallow(const unsigned char *sha1)
@@ -515,7 +517,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
 
                commit = work_item->item;
                for (parents = commit->parents; parents ; parents = parents->next) {
-                       struct commit *parent=parents->item;
+                       struct commit *parent = parents->item;
 
                        if (!parent->indegree)
                                continue;
index a2d571b97410fa857b4c177325c4556dac50fe3f..14f6a5a2ed91e2176cce4543798774f88a8628b1 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -38,6 +38,13 @@ struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
                                              int quiet);
 struct commit *lookup_commit_reference_by_name(const char *name);
 
+/*
+ * Look up object named by "sha1", dereference tag as necessary,
+ * get a commit and return it. If "sha1" does not dereference to
+ * a commit, use ref_name to report an error and die.
+ */
+struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_name);
+
 int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size);
 int parse_commit(struct commit *item);
 
@@ -142,6 +149,7 @@ struct commit_graft {
        int nr_parent; /* < 0 if shallow commit */
        unsigned char parent[FLEX_ARRAY][20]; /* more */
 };
+typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
 
 struct commit_graft *read_graft_line(char *buf, int len);
 int register_commit_graft(struct commit_graft *, int);
@@ -153,7 +161,7 @@ extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
 
 extern int register_shallow(const unsigned char *sha1);
 extern int unregister_shallow(const unsigned char *sha1);
-extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
+extern int for_each_commit_graft(each_commit_graft_fn, void *);
 extern int is_repository_shallow(void);
 extern struct commit_list *get_shallow_commits(struct object_array *heads,
                int depth, int shallow_flag, int not_shallow_flag);
index 6ef0cc4f99becd772a6fed1cfe2484a67b3a9000..8947418ce78faa3619779c12319c0dd99b1557d3 100644 (file)
@@ -1183,7 +1183,7 @@ static int WSAAPI getaddrinfo_stub(const char *node, const char *service,
        }
        ai->ai_addrlen = sizeof(struct sockaddr_in);
        if (hints && (hints->ai_flags & AI_CANONNAME))
-               ai->ai_canonname = h ? strdup(h->h_name) : NULL;
+               ai->ai_canonname = h ? xstrdup(h->h_name) : NULL;
        else
                ai->ai_canonname = NULL;
 
diff --git a/compat/obstack.c b/compat/obstack.c
new file mode 100644 (file)
index 0000000..a89ab5b
--- /dev/null
@@ -0,0 +1,414 @@
+/* obstack.c - subroutines used implicitly by object stack macros
+   Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998,
+   1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
+
+#include "git-compat-util.h"
+#include <gettext.h>
+#include "obstack.h"
+
+/* NOTE BEFORE MODIFYING THIS FILE: This version number must be
+   incremented whenever callers compiled using an old obstack.h can no
+   longer properly call the functions in this obstack.c.  */
+#define OBSTACK_INTERFACE_VERSION 1
+
+/* Comment out all this code if we are using the GNU C Library, and are not
+   actually compiling the library itself, and the installed library
+   supports the same library interface we do.  This code is part of the GNU
+   C Library, but also included in many other GNU distributions.  Compiling
+   and linking in this code is a waste when using the GNU C library
+   (especially if it is a shared library).  Rather than having every GNU
+   program understand `configure --with-gnu-libc' and omit the object
+   files, it is simpler to just do this in the source for each such file.  */
+
+#include <stdio.h>             /* Random thing to get __GNU_LIBRARY__.  */
+#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
+# include <gnu-versions.h>
+# if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
+#  define ELIDE_CODE
+# endif
+#endif
+
+#include <stddef.h>
+
+#ifndef ELIDE_CODE
+
+
+# if HAVE_INTTYPES_H
+#  include <inttypes.h>
+# endif
+# if HAVE_STDINT_H || defined _LIBC
+#  include <stdint.h>
+# endif
+
+/* Determine default alignment.  */
+union fooround
+{
+  uintmax_t i;
+  long double d;
+  void *p;
+};
+struct fooalign
+{
+  char c;
+  union fooround u;
+};
+/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
+   But in fact it might be less smart and round addresses to as much as
+   DEFAULT_ROUNDING.  So we prepare for it to do that.  */
+enum
+  {
+    DEFAULT_ALIGNMENT = offsetof (struct fooalign, u),
+    DEFAULT_ROUNDING = sizeof (union fooround)
+  };
+
+/* When we copy a long block of data, this is the unit to do it with.
+   On some machines, copying successive ints does not work;
+   in such a case, redefine COPYING_UNIT to `long' (if that works)
+   or `char' as a last resort.  */
+# ifndef COPYING_UNIT
+#  define COPYING_UNIT int
+# endif
+
+
+/* The functions allocating more room by calling `obstack_chunk_alloc'
+   jump to the handler pointed to by `obstack_alloc_failed_handler'.
+   This can be set to a user defined function which should either
+   abort gracefully or use longjump - but shouldn't return.  This
+   variable by default points to the internal function
+   `print_and_abort'.  */
+static void print_and_abort (void);
+void (*obstack_alloc_failed_handler) (void) = print_and_abort;
+
+# ifdef _LIBC
+#  if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4)
+/* A looong time ago (before 1994, anyway; we're not sure) this global variable
+   was used by non-GNU-C macros to avoid multiple evaluation.  The GNU C
+   library still exports it because somebody might use it.  */
+struct obstack *_obstack_compat;
+compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0);
+#  endif
+# endif
+
+/* Define a macro that either calls functions with the traditional malloc/free
+   calling interface, or calls functions with the mmalloc/mfree interface
+   (that adds an extra first argument), based on the state of use_extra_arg.
+   For free, do not use ?:, since some compilers, like the MIPS compilers,
+   do not allow (expr) ? void : void.  */
+
+# define CALL_CHUNKFUN(h, size) \
+  (((h) -> use_extra_arg) \
+   ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
+   : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size)))
+
+# define CALL_FREEFUN(h, old_chunk) \
+  do { \
+    if ((h) -> use_extra_arg) \
+      (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
+    else \
+      (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
+  } while (0)
+
+\f
+/* Initialize an obstack H for use.  Specify chunk size SIZE (0 means default).
+   Objects start on multiples of ALIGNMENT (0 means use default).
+   CHUNKFUN is the function to use to allocate chunks,
+   and FREEFUN the function to free them.
+
+   Return nonzero if successful, calls obstack_alloc_failed_handler if
+   allocation fails.  */
+
+int
+_obstack_begin (struct obstack *h,
+               int size, int alignment,
+               void *(*chunkfun) (long),
+               void (*freefun) (void *))
+{
+  register struct _obstack_chunk *chunk; /* points to new chunk */
+
+  if (alignment == 0)
+    alignment = DEFAULT_ALIGNMENT;
+  if (size == 0)
+    /* Default size is what GNU malloc can fit in a 4096-byte block.  */
+    {
+      /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
+        Use the values for range checking, because if range checking is off,
+        the extra bytes won't be missed terribly, but if range checking is on
+        and we used a larger request, a whole extra 4096 bytes would be
+        allocated.
+
+        These number are irrelevant to the new GNU malloc.  I suspect it is
+        less sensitive to the size of the request.  */
+      int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
+                   + 4 + DEFAULT_ROUNDING - 1)
+                  & ~(DEFAULT_ROUNDING - 1));
+      size = 4096 - extra;
+    }
+
+  h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun;
+  h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
+  h->chunk_size = size;
+  h->alignment_mask = alignment - 1;
+  h->use_extra_arg = 0;
+
+  chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
+  if (!chunk)
+    (*obstack_alloc_failed_handler) ();
+  h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
+                                              alignment - 1);
+  h->chunk_limit = chunk->limit
+    = (char *) chunk + h->chunk_size;
+  chunk->prev = 0;
+  /* The initial chunk now contains no empty object.  */
+  h->maybe_empty_object = 0;
+  h->alloc_failed = 0;
+  return 1;
+}
+
+int
+_obstack_begin_1 (struct obstack *h, int size, int alignment,
+                 void *(*chunkfun) (void *, long),
+                 void (*freefun) (void *, void *),
+                 void *arg)
+{
+  register struct _obstack_chunk *chunk; /* points to new chunk */
+
+  if (alignment == 0)
+    alignment = DEFAULT_ALIGNMENT;
+  if (size == 0)
+    /* Default size is what GNU malloc can fit in a 4096-byte block.  */
+    {
+      /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
+        Use the values for range checking, because if range checking is off,
+        the extra bytes won't be missed terribly, but if range checking is on
+        and we used a larger request, a whole extra 4096 bytes would be
+        allocated.
+
+        These number are irrelevant to the new GNU malloc.  I suspect it is
+        less sensitive to the size of the request.  */
+      int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
+                   + 4 + DEFAULT_ROUNDING - 1)
+                  & ~(DEFAULT_ROUNDING - 1));
+      size = 4096 - extra;
+    }
+
+  h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
+  h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
+  h->chunk_size = size;
+  h->alignment_mask = alignment - 1;
+  h->extra_arg = arg;
+  h->use_extra_arg = 1;
+
+  chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
+  if (!chunk)
+    (*obstack_alloc_failed_handler) ();
+  h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
+                                              alignment - 1);
+  h->chunk_limit = chunk->limit
+    = (char *) chunk + h->chunk_size;
+  chunk->prev = 0;
+  /* The initial chunk now contains no empty object.  */
+  h->maybe_empty_object = 0;
+  h->alloc_failed = 0;
+  return 1;
+}
+
+/* Allocate a new current chunk for the obstack *H
+   on the assumption that LENGTH bytes need to be added
+   to the current object, or a new object of length LENGTH allocated.
+   Copies any partial object from the end of the old chunk
+   to the beginning of the new one.  */
+
+void
+_obstack_newchunk (struct obstack *h, int length)
+{
+  register struct _obstack_chunk *old_chunk = h->chunk;
+  register struct _obstack_chunk *new_chunk;
+  register long        new_size;
+  register long obj_size = h->next_free - h->object_base;
+  register long i;
+  long already;
+  char *object_base;
+
+  /* Compute size for new chunk.  */
+  new_size = (obj_size + length) + (obj_size >> 3) + h->alignment_mask + 100;
+  if (new_size < h->chunk_size)
+    new_size = h->chunk_size;
+
+  /* Allocate and initialize the new chunk.  */
+  new_chunk = CALL_CHUNKFUN (h, new_size);
+  if (!new_chunk)
+    (*obstack_alloc_failed_handler) ();
+  h->chunk = new_chunk;
+  new_chunk->prev = old_chunk;
+  new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;
+
+  /* Compute an aligned object_base in the new chunk */
+  object_base =
+    __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask);
+
+  /* Move the existing object to the new chunk.
+     Word at a time is fast and is safe if the object
+     is sufficiently aligned.  */
+  if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT)
+    {
+      for (i = obj_size / sizeof (COPYING_UNIT) - 1;
+          i >= 0; i--)
+       ((COPYING_UNIT *)object_base)[i]
+         = ((COPYING_UNIT *)h->object_base)[i];
+      /* We used to copy the odd few remaining bytes as one extra COPYING_UNIT,
+        but that can cross a page boundary on a machine
+        which does not do strict alignment for COPYING_UNITS.  */
+      already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT);
+    }
+  else
+    already = 0;
+  /* Copy remaining bytes one by one.  */
+  for (i = already; i < obj_size; i++)
+    object_base[i] = h->object_base[i];
+
+  /* If the object just copied was the only data in OLD_CHUNK,
+     free that chunk and remove it from the chain.
+     But not if that chunk might contain an empty object.  */
+  if (! h->maybe_empty_object
+      && (h->object_base
+         == __PTR_ALIGN ((char *) old_chunk, old_chunk->contents,
+                         h->alignment_mask)))
+    {
+      new_chunk->prev = old_chunk->prev;
+      CALL_FREEFUN (h, old_chunk);
+    }
+
+  h->object_base = object_base;
+  h->next_free = h->object_base + obj_size;
+  /* The new chunk certainly contains no empty object yet.  */
+  h->maybe_empty_object = 0;
+}
+# ifdef _LIBC
+libc_hidden_def (_obstack_newchunk)
+# endif
+
+/* Return nonzero if object OBJ has been allocated from obstack H.
+   This is here for debugging.
+   If you use it in a program, you are probably losing.  */
+
+/* Suppress -Wmissing-prototypes warning.  We don't want to declare this in
+   obstack.h because it is just for debugging.  */
+int _obstack_allocated_p (struct obstack *h, void *obj);
+
+int
+_obstack_allocated_p (struct obstack *h, void *obj)
+{
+  register struct _obstack_chunk *lp;  /* below addr of any objects in this chunk */
+  register struct _obstack_chunk *plp; /* point to previous chunk if any */
+
+  lp = (h)->chunk;
+  /* We use >= rather than > since the object cannot be exactly at
+     the beginning of the chunk but might be an empty object exactly
+     at the end of an adjacent chunk.  */
+  while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
+    {
+      plp = lp->prev;
+      lp = plp;
+    }
+  return lp != 0;
+}
+\f
+/* Free objects in obstack H, including OBJ and everything allocate
+   more recently than OBJ.  If OBJ is zero, free everything in H.  */
+
+# undef obstack_free
+
+void
+obstack_free (struct obstack *h, void *obj)
+{
+  register struct _obstack_chunk *lp;  /* below addr of any objects in this chunk */
+  register struct _obstack_chunk *plp; /* point to previous chunk if any */
+
+  lp = h->chunk;
+  /* We use >= because there cannot be an object at the beginning of a chunk.
+     But there can be an empty object at that address
+     at the end of another chunk.  */
+  while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
+    {
+      plp = lp->prev;
+      CALL_FREEFUN (h, lp);
+      lp = plp;
+      /* If we switch chunks, we can't tell whether the new current
+        chunk contains an empty object, so assume that it may.  */
+      h->maybe_empty_object = 1;
+    }
+  if (lp)
+    {
+      h->object_base = h->next_free = (char *) (obj);
+      h->chunk_limit = lp->limit;
+      h->chunk = lp;
+    }
+  else if (obj != 0)
+    /* obj is not in any of the chunks! */
+    abort ();
+}
+
+# ifdef _LIBC
+/* Older versions of libc used a function _obstack_free intended to be
+   called by non-GCC compilers.  */
+strong_alias (obstack_free, _obstack_free)
+# endif
+\f
+int
+_obstack_memory_used (struct obstack *h)
+{
+  register struct _obstack_chunk* lp;
+  register int nbytes = 0;
+
+  for (lp = h->chunk; lp != 0; lp = lp->prev)
+    {
+      nbytes += lp->limit - (char *) lp;
+    }
+  return nbytes;
+}
+\f
+# ifdef _LIBC
+#  include <libio/iolibio.h>
+# endif
+
+# ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later.  */
+#  if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
+#   define __attribute__(Spec) /* empty */
+#  endif
+# endif
+
+static void
+__attribute__ ((noreturn))
+print_and_abort (void)
+{
+  /* Don't change any of these strings.  Yes, it would be possible to add
+     the newline to the string and use fputs or so.  But this must not
+     happen because the "memory exhausted" message appears in other places
+     like this and the translation should be reused instead of creating
+     a very similar string which requires a separate translation.  */
+# ifdef _LIBC
+  (void) __fxprintf (NULL, "%s\n", _("memory exhausted"));
+# else
+  fprintf (stderr, "%s\n", _("memory exhausted"));
+# endif
+  exit (1);
+}
+
+#endif /* !ELIDE_CODE */
diff --git a/compat/obstack.h b/compat/obstack.h
new file mode 100644 (file)
index 0000000..d178bd6
--- /dev/null
@@ -0,0 +1,506 @@
+/* obstack.h - object stack macros
+   Copyright (C) 1988-1994,1996-1999,2003,2004,2005,2009
+       Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
+
+/* Summary:
+
+All the apparent functions defined here are macros. The idea
+is that you would use these pre-tested macros to solve a
+very specific set of problems, and they would run fast.
+Caution: no side-effects in arguments please!! They may be
+evaluated MANY times!!
+
+These macros operate a stack of objects.  Each object starts life
+small, and may grow to maturity.  (Consider building a word syllable
+by syllable.)  An object can move while it is growing.  Once it has
+been "finished" it never changes address again.  So the "top of the
+stack" is typically an immature growing object, while the rest of the
+stack is of mature, fixed size and fixed address objects.
+
+These routines grab large chunks of memory, using a function you
+supply, called `obstack_chunk_alloc'.  On occasion, they free chunks,
+by calling `obstack_chunk_free'.  You must define them and declare
+them before using any obstack macros.
+
+Each independent stack is represented by a `struct obstack'.
+Each of the obstack macros expects a pointer to such a structure
+as the first argument.
+
+One motivation for this package is the problem of growing char strings
+in symbol tables.  Unless you are "fascist pig with a read-only mind"
+--Gosper's immortal quote from HAKMEM item 154, out of context--you
+would not like to put any arbitrary upper limit on the length of your
+symbols.
+
+In practice this often means you will build many short symbols and a
+few long symbols.  At the time you are reading a symbol you don't know
+how long it is.  One traditional method is to read a symbol into a
+buffer, realloc()ating the buffer every time you try to read a symbol
+that is longer than the buffer.  This is beaut, but you still will
+want to copy the symbol from the buffer to a more permanent
+symbol-table entry say about half the time.
+
+With obstacks, you can work differently.  Use one obstack for all symbol
+names.  As you read a symbol, grow the name in the obstack gradually.
+When the name is complete, finalize it.  Then, if the symbol exists already,
+free the newly read name.
+
+The way we do this is to take a large chunk, allocating memory from
+low addresses.  When you want to build a symbol in the chunk you just
+add chars above the current "high water mark" in the chunk.  When you
+have finished adding chars, because you got to the end of the symbol,
+you know how long the chars are, and you can create a new object.
+Mostly the chars will not burst over the highest address of the chunk,
+because you would typically expect a chunk to be (say) 100 times as
+long as an average object.
+
+In case that isn't clear, when we have enough chars to make up
+the object, THEY ARE ALREADY CONTIGUOUS IN THE CHUNK (guaranteed)
+so we just point to it where it lies.  No moving of chars is
+needed and this is the second win: potentially long strings need
+never be explicitly shuffled. Once an object is formed, it does not
+change its address during its lifetime.
+
+When the chars burst over a chunk boundary, we allocate a larger
+chunk, and then copy the partly formed object from the end of the old
+chunk to the beginning of the new larger chunk.  We then carry on
+accreting characters to the end of the object as we normally would.
+
+A special macro is provided to add a single char at a time to a
+growing object.  This allows the use of register variables, which
+break the ordinary 'growth' macro.
+
+Summary:
+       We allocate large chunks.
+       We carve out one object at a time from the current chunk.
+       Once carved, an object never moves.
+       We are free to append data of any size to the currently
+         growing object.
+       Exactly one object is growing in an obstack at any one time.
+       You can run one obstack per control block.
+       You may have as many control blocks as you dare.
+       Because of the way we do it, you can `unwind' an obstack
+         back to a previous state. (You may remove objects much
+         as you would with a stack.)
+*/
+
+
+/* Don't do the contents of this file more than once.  */
+
+#ifndef _OBSTACK_H
+#define _OBSTACK_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+\f
+/* We need the type of a pointer subtraction.  If __PTRDIFF_TYPE__ is
+   defined, as with GNU C, use that; that way we don't pollute the
+   namespace with <stddef.h>'s symbols.  Otherwise, include <stddef.h>
+   and use ptrdiff_t.  */
+
+#ifdef __PTRDIFF_TYPE__
+# define PTR_INT_TYPE __PTRDIFF_TYPE__
+#else
+# include <stddef.h>
+# define PTR_INT_TYPE ptrdiff_t
+#endif
+
+/* If B is the base of an object addressed by P, return the result of
+   aligning P to the next multiple of A + 1.  B and P must be of type
+   char *.  A + 1 must be a power of 2.  */
+
+#define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
+
+/* Similiar to _BPTR_ALIGN (B, P, A), except optimize the common case
+   where pointers can be converted to integers, aligned as integers,
+   and converted back again.  If PTR_INT_TYPE is narrower than a
+   pointer (e.g., the AS/400), play it safe and compute the alignment
+   relative to B.  Otherwise, use the faster strategy of computing the
+   alignment relative to 0.  */
+
+#define __PTR_ALIGN(B, P, A)                                               \
+  __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \
+               P, A)
+
+#include <string.h>
+
+struct _obstack_chunk          /* Lives at front of each chunk. */
+{
+  char  *limit;                        /* 1 past end of this chunk */
+  struct _obstack_chunk *prev; /* address of prior chunk or NULL */
+  char contents[4];            /* objects begin here */
+};
+
+struct obstack         /* control current object in current chunk */
+{
+  long chunk_size;             /* preferred size to allocate chunks in */
+  struct _obstack_chunk *chunk;        /* address of current struct obstack_chunk */
+  char *object_base;           /* address of object we are building */
+  char *next_free;             /* where to add next char to current object */
+  char *chunk_limit;           /* address of char after current chunk */
+  union
+  {
+    PTR_INT_TYPE tempint;
+    void *tempptr;
+  } temp;                      /* Temporary for some macros.  */
+  int   alignment_mask;                /* Mask of alignment for each object. */
+  /* These prototypes vary based on `use_extra_arg', and we use
+     casts to the prototypeless function type in all assignments,
+     but having prototypes here quiets -Wstrict-prototypes.  */
+  struct _obstack_chunk *(*chunkfun) (void *, long);
+  void (*freefun) (void *, struct _obstack_chunk *);
+  void *extra_arg;             /* first arg for chunk alloc/dealloc funcs */
+  unsigned use_extra_arg:1;    /* chunk alloc/dealloc funcs take extra arg */
+  unsigned maybe_empty_object:1;/* There is a possibility that the current
+                                  chunk contains a zero-length object.  This
+                                  prevents freeing the chunk if we allocate
+                                  a bigger chunk to replace it. */
+  unsigned alloc_failed:1;     /* No longer used, as we now call the failed
+                                  handler on error, but retained for binary
+                                  compatibility.  */
+};
+
+/* Declare the external functions we use; they are in obstack.c.  */
+
+extern void _obstack_newchunk (struct obstack *, int);
+extern int _obstack_begin (struct obstack *, int, int,
+                           void *(*) (long), void (*) (void *));
+extern int _obstack_begin_1 (struct obstack *, int, int,
+                            void *(*) (void *, long),
+                            void (*) (void *, void *), void *);
+extern int _obstack_memory_used (struct obstack *);
+
+void obstack_free (struct obstack *, void *);
+
+\f
+/* Error handler called when `obstack_chunk_alloc' failed to allocate
+   more memory.  This can be set to a user defined function which
+   should either abort gracefully or use longjump - but shouldn't
+   return.  The default action is to print a message and abort.  */
+extern void (*obstack_alloc_failed_handler) (void);
+\f
+/* Pointer to beginning of object being allocated or to be allocated next.
+   Note that this might not be the final address of the object
+   because a new chunk might be needed to hold the final size.  */
+
+#define obstack_base(h) ((void *) (h)->object_base)
+
+/* Size for allocating ordinary chunks.  */
+
+#define obstack_chunk_size(h) ((h)->chunk_size)
+
+/* Pointer to next byte not yet allocated in current chunk.  */
+
+#define obstack_next_free(h)   ((h)->next_free)
+
+/* Mask specifying low bits that should be clear in address of an object.  */
+
+#define obstack_alignment_mask(h) ((h)->alignment_mask)
+
+/* To prevent prototype warnings provide complete argument list.  */
+#define obstack_init(h)                                                \
+  _obstack_begin ((h), 0, 0,                                   \
+                 (void *(*) (long)) obstack_chunk_alloc,       \
+                 (void (*) (void *)) obstack_chunk_free)
+
+#define obstack_begin(h, size)                                 \
+  _obstack_begin ((h), (size), 0,                              \
+                 (void *(*) (long)) obstack_chunk_alloc,       \
+                 (void (*) (void *)) obstack_chunk_free)
+
+#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun)  \
+  _obstack_begin ((h), (size), (alignment),                               \
+                 (void *(*) (long)) (chunkfun),                           \
+                 (void (*) (void *)) (freefun))
+
+#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
+  _obstack_begin_1 ((h), (size), (alignment),                          \
+                   (void *(*) (void *, long)) (chunkfun),              \
+                   (void (*) (void *, void *)) (freefun), (arg))
+
+#define obstack_chunkfun(h, newchunkfun) \
+  ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))
+
+#define obstack_freefun(h, newfreefun) \
+  ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
+
+#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar))
+
+#define obstack_blank_fast(h,n) ((h)->next_free += (n))
+
+#define obstack_memory_used(h) _obstack_memory_used (h)
+\f
+#if defined __GNUC__ && defined __STDC__ && __STDC__
+/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
+   does not implement __extension__.  But that compiler doesn't define
+   __GNUC_MINOR__.  */
+# if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
+#  define __extension__
+# endif
+
+/* For GNU C, if not -traditional,
+   we can define these macros to compute all args only once
+   without using a global variable.
+   Also, we can avoid using the `temp' slot, to make faster code.  */
+
+# define obstack_object_size(OBSTACK)                                  \
+  __extension__                                                                \
+  ({ struct obstack const *__o = (OBSTACK);                            \
+     (unsigned) (__o->next_free - __o->object_base); })
+
+# define obstack_room(OBSTACK)                                         \
+  __extension__                                                                \
+  ({ struct obstack const *__o = (OBSTACK);                            \
+     (unsigned) (__o->chunk_limit - __o->next_free); })
+
+# define obstack_make_room(OBSTACK,length)                             \
+__extension__                                                          \
+({ struct obstack *__o = (OBSTACK);                                    \
+   int __len = (length);                                               \
+   if (__o->chunk_limit - __o->next_free < __len)                      \
+     _obstack_newchunk (__o, __len);                                   \
+   (void) 0; })
+
+# define obstack_empty_p(OBSTACK)                                      \
+  __extension__                                                                \
+  ({ struct obstack const *__o = (OBSTACK);                            \
+     (__o->chunk->prev == 0                                            \
+      && __o->next_free == __PTR_ALIGN ((char *) __o->chunk,           \
+                                       __o->chunk->contents,           \
+                                       __o->alignment_mask)); })
+
+# define obstack_grow(OBSTACK,where,length)                            \
+__extension__                                                          \
+({ struct obstack *__o = (OBSTACK);                                    \
+   int __len = (length);                                               \
+   if (__o->next_free + __len > __o->chunk_limit)                      \
+     _obstack_newchunk (__o, __len);                                   \
+   memcpy (__o->next_free, where, __len);                              \
+   __o->next_free += __len;                                            \
+   (void) 0; })
+
+# define obstack_grow0(OBSTACK,where,length)                           \
+__extension__                                                          \
+({ struct obstack *__o = (OBSTACK);                                    \
+   int __len = (length);                                               \
+   if (__o->next_free + __len + 1 > __o->chunk_limit)                  \
+     _obstack_newchunk (__o, __len + 1);                               \
+   memcpy (__o->next_free, where, __len);                              \
+   __o->next_free += __len;                                            \
+   *(__o->next_free)++ = 0;                                            \
+   (void) 0; })
+
+# define obstack_1grow(OBSTACK,datum)                                  \
+__extension__                                                          \
+({ struct obstack *__o = (OBSTACK);                                    \
+   if (__o->next_free + 1 > __o->chunk_limit)                          \
+     _obstack_newchunk (__o, 1);                                       \
+   obstack_1grow_fast (__o, datum);                                    \
+   (void) 0; })
+
+/* These assume that the obstack alignment is good enough for pointers
+   or ints, and that the data added so far to the current object
+   shares that much alignment.  */
+
+# define obstack_ptr_grow(OBSTACK,datum)                               \
+__extension__                                                          \
+({ struct obstack *__o = (OBSTACK);                                    \
+   if (__o->next_free + sizeof (void *) > __o->chunk_limit)            \
+     _obstack_newchunk (__o, sizeof (void *));                         \
+   obstack_ptr_grow_fast (__o, datum); })                              \
+
+# define obstack_int_grow(OBSTACK,datum)                               \
+__extension__                                                          \
+({ struct obstack *__o = (OBSTACK);                                    \
+   if (__o->next_free + sizeof (int) > __o->chunk_limit)               \
+     _obstack_newchunk (__o, sizeof (int));                            \
+   obstack_int_grow_fast (__o, datum); })
+
+# define obstack_ptr_grow_fast(OBSTACK,aptr)                           \
+__extension__                                                          \
+({ struct obstack *__o1 = (OBSTACK);                                   \
+   *(const void **) __o1->next_free = (aptr);                          \
+   __o1->next_free += sizeof (const void *);                           \
+   (void) 0; })
+
+# define obstack_int_grow_fast(OBSTACK,aint)                           \
+__extension__                                                          \
+({ struct obstack *__o1 = (OBSTACK);                                   \
+   *(int *) __o1->next_free = (aint);                                  \
+   __o1->next_free += sizeof (int);                                    \
+   (void) 0; })
+
+# define obstack_blank(OBSTACK,length)                                 \
+__extension__                                                          \
+({ struct obstack *__o = (OBSTACK);                                    \
+   int __len = (length);                                               \
+   if (__o->chunk_limit - __o->next_free < __len)                      \
+     _obstack_newchunk (__o, __len);                                   \
+   obstack_blank_fast (__o, __len);                                    \
+   (void) 0; })
+
+# define obstack_alloc(OBSTACK,length)                                 \
+__extension__                                                          \
+({ struct obstack *__h = (OBSTACK);                                    \
+   obstack_blank (__h, (length));                                      \
+   obstack_finish (__h); })
+
+# define obstack_copy(OBSTACK,where,length)                            \
+__extension__                                                          \
+({ struct obstack *__h = (OBSTACK);                                    \
+   obstack_grow (__h, (where), (length));                              \
+   obstack_finish (__h); })
+
+# define obstack_copy0(OBSTACK,where,length)                           \
+__extension__                                                          \
+({ struct obstack *__h = (OBSTACK);                                    \
+   obstack_grow0 (__h, (where), (length));                             \
+   obstack_finish (__h); })
+
+/* The local variable is named __o1 to avoid a name conflict
+   when obstack_blank is called.  */
+# define obstack_finish(OBSTACK)                                       \
+__extension__                                                          \
+({ struct obstack *__o1 = (OBSTACK);                                   \
+   void *__value = (void *) __o1->object_base;                         \
+   if (__o1->next_free == __value)                                     \
+     __o1->maybe_empty_object = 1;                                     \
+   __o1->next_free                                                     \
+     = __PTR_ALIGN (__o1->object_base, __o1->next_free,                        \
+                   __o1->alignment_mask);                              \
+   if (__o1->next_free - (char *)__o1->chunk                           \
+       > __o1->chunk_limit - (char *)__o1->chunk)                      \
+     __o1->next_free = __o1->chunk_limit;                              \
+   __o1->object_base = __o1->next_free;                                        \
+   __value; })
+
+# define obstack_free(OBSTACK, OBJ)                                    \
+__extension__                                                          \
+({ struct obstack *__o = (OBSTACK);                                    \
+   void *__obj = (OBJ);                                                        \
+   if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit)  \
+     __o->next_free = __o->object_base = (char *)__obj;                        \
+   else (obstack_free) (__o, __obj); })
+\f
+#else /* not __GNUC__ or not __STDC__ */
+
+# define obstack_object_size(h) \
+ (unsigned) ((h)->next_free - (h)->object_base)
+
+# define obstack_room(h)               \
+ (unsigned) ((h)->chunk_limit - (h)->next_free)
+
+# define obstack_empty_p(h) \
+ ((h)->chunk->prev == 0                                                        \
+  && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk,               \
+                                   (h)->chunk->contents,               \
+                                   (h)->alignment_mask))
+
+/* Note that the call to _obstack_newchunk is enclosed in (..., 0)
+   so that we can avoid having void expressions
+   in the arms of the conditional expression.
+   Casting the third operand to void was tried before,
+   but some compilers won't accept it.  */
+
+# define obstack_make_room(h,length)                                   \
+( (h)->temp.tempint = (length),                                                \
+  (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit)             \
+   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0))
+
+# define obstack_grow(h,where,length)                                  \
+( (h)->temp.tempint = (length),                                                \
+  (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit)             \
+   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0),             \
+  memcpy ((h)->next_free, where, (h)->temp.tempint),                   \
+  (h)->next_free += (h)->temp.tempint)
+
+# define obstack_grow0(h,where,length)                                 \
+( (h)->temp.tempint = (length),                                                \
+  (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit)         \
+   ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0),         \
+  memcpy ((h)->next_free, where, (h)->temp.tempint),                   \
+  (h)->next_free += (h)->temp.tempint,                                 \
+  *((h)->next_free)++ = 0)
+
+# define obstack_1grow(h,datum)                                                \
+( (((h)->next_free + 1 > (h)->chunk_limit)                             \
+   ? (_obstack_newchunk ((h), 1), 0) : 0),                             \
+  obstack_1grow_fast (h, datum))
+
+# define obstack_ptr_grow(h,datum)                                     \
+( (((h)->next_free + sizeof (char *) > (h)->chunk_limit)               \
+   ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0),               \
+  obstack_ptr_grow_fast (h, datum))
+
+# define obstack_int_grow(h,datum)                                     \
+( (((h)->next_free + sizeof (int) > (h)->chunk_limit)                  \
+   ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0),                  \
+  obstack_int_grow_fast (h, datum))
+
+# define obstack_ptr_grow_fast(h,aptr)                                 \
+  (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))
+
+# define obstack_int_grow_fast(h,aint)                                 \
+  (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint))
+
+# define obstack_blank(h,length)                                       \
+( (h)->temp.tempint = (length),                                                \
+  (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint)             \
+   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0),             \
+  obstack_blank_fast (h, (h)->temp.tempint))
+
+# define obstack_alloc(h,length)                                       \
+ (obstack_blank ((h), (length)), obstack_finish ((h)))
+
+# define obstack_copy(h,where,length)                                  \
+ (obstack_grow ((h), (where), (length)), obstack_finish ((h)))
+
+# define obstack_copy0(h,where,length)                                 \
+ (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
+
+# define obstack_finish(h)                                             \
+( ((h)->next_free == (h)->object_base                                  \
+   ? (((h)->maybe_empty_object = 1), 0)                                        \
+   : 0),                                                               \
+  (h)->temp.tempptr = (h)->object_base,                                        \
+  (h)->next_free                                                       \
+    = __PTR_ALIGN ((h)->object_base, (h)->next_free,                   \
+                  (h)->alignment_mask),                                \
+  (((h)->next_free - (char *) (h)->chunk                               \
+    > (h)->chunk_limit - (char *) (h)->chunk)                          \
+   ? ((h)->next_free = (h)->chunk_limit) : 0),                         \
+  (h)->object_base = (h)->next_free,                                   \
+  (h)->temp.tempptr)
+
+# define obstack_free(h,obj)                                           \
+( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk,            \
+  ((((h)->temp.tempint > 0                                             \
+    && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk))    \
+   ? (int) ((h)->next_free = (h)->object_base                          \
+           = (h)->temp.tempint + (char *) (h)->chunk)                  \
+   : (((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0)))
+
+#endif /* not __GNUC__ or not __STDC__ */
+
+#ifdef __cplusplus
+}      /* C++ */
+#endif
+
+#endif /* obstack.h */
index d93dce2cf8fa33bd1fbefe131d2e41a6b954da61..9574d537bd38d3aa72ee040b106456088ee16a07 100644 (file)
@@ -55,7 +55,7 @@ void git_qsort(void *b, size_t n, size_t s,
                msort_with_tmp(b, n, s, cmp, buf);
        } else {
                /* It's somewhat large, so malloc it.  */
-               char *tmp = malloc(size);
+               char *tmp = xmalloc(size);
                msort_with_tmp(b, n, s, cmp, tmp);
                free(tmp);
        }
index e42c59b190986d28ec535861e08b843739356b9a..d3bcaa023d1f238d8fa9b2c416ae7448eff36d17 100644 (file)
--- a/config.c
+++ b/config.c
@@ -491,6 +491,9 @@ static int git_default_core_config(const char *var, const char *value)
                return 0;
        }
 
+       if (!strcmp(var, "core.attributesfile"))
+               return git_config_pathname(&git_attributes_file, var, value);
+
        if (!strcmp(var, "core.bare")) {
                is_bare_repository_cfg = git_config_bool(var, value);
                return 0;
@@ -576,6 +579,9 @@ static int git_default_core_config(const char *var, const char *value)
                return 0;
        }
 
+       if (!strcmp(var, "core.logpackaccess"))
+               return git_config_string(&log_pack_access, var, value);
+
        if (!strcmp(var, "core.autocrlf")) {
                if (value && !strcasecmp(value, "input")) {
                        if (core_eol == EOL_CRLF)
index 844107e2954f6cb8354990d69c6568b9d3091470..ee1d4b4b46f789168c155eb170b87dbed85fb590 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -217,7 +217,7 @@ static int git_tcp_connect_sock(char *host, int flags)
        if (flags & CONNECT_VERBOSE)
                fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port);
 
-       for (ai0 = ai; ai; ai = ai->ai_next) {
+       for (ai0 = ai; ai; ai = ai->ai_next, cnt++) {
                sockfd = socket(ai->ai_family,
                                ai->ai_socktype, ai->ai_protocol);
                if ((sockfd < 0) ||
@@ -254,7 +254,8 @@ static int git_tcp_connect_sock(char *host, int flags)
  */
 static int git_tcp_connect_sock(char *host, int flags)
 {
-       int sockfd = -1, saved_errno = 0;
+       struct strbuf error_message = STRBUF_INIT;
+       int sockfd = -1;
        const char *port = STR(DEFAULT_GIT_PORT);
        char *ep;
        struct hostent *he;
@@ -284,25 +285,21 @@ static int git_tcp_connect_sock(char *host, int flags)
                fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port);
 
        for (cnt = 0, ap = he->h_addr_list; *ap; ap++, cnt++) {
-               sockfd = socket(he->h_addrtype, SOCK_STREAM, 0);
-               if (sockfd < 0) {
-                       saved_errno = errno;
-                       continue;
-               }
-
                memset(&sa, 0, sizeof sa);
                sa.sin_family = he->h_addrtype;
                sa.sin_port = htons(nport);
                memcpy(&sa.sin_addr, *ap, he->h_length);
 
-               if (connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) {
-                       saved_errno = errno;
-                       fprintf(stderr, "%s[%d: %s]: errno=%s\n",
+               sockfd = socket(he->h_addrtype, SOCK_STREAM, 0);
+               if ((sockfd < 0) ||
+                   connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) {
+                       strbuf_addf(&error_message, "%s[%d: %s]: errno=%s\n",
                                host,
                                cnt,
                                inet_ntoa(*(struct in_addr *)&sa.sin_addr),
-                               strerror(saved_errno));
-                       close(sockfd);
+                               strerror(errno));
+                       if (0 <= sockfd)
+                               close(sockfd);
                        sockfd = -1;
                        continue;
                }
@@ -313,7 +310,7 @@ static int git_tcp_connect_sock(char *host, int flags)
        }
 
        if (sockfd < 0)
-               die("unable to connect a socket (%s)", strerror(saved_errno));
+               die("unable to connect to %s:\n%s", host, error_message.buf);
 
        if (flags & CONNECT_VERBOSE)
                fprintf(stderr, "done.\n");
index 5a8309076dc633f431797c4bd59876490b0d7408..8648a36e7b8239e969dc8971f451431c298e405e 100755 (executable)
@@ -1469,7 +1469,7 @@ _git_help ()
        __gitcomp "$__git_all_commands $(__git_aliases)
                attributes cli core-tutorial cvs-migration
                diffcore gitk glossary hooks ignore modules
-               repository-layout tutorial tutorial-2
+               namespaces repository-layout tutorial tutorial-2
                workflows
                "
 }
@@ -2640,6 +2640,7 @@ _git ()
                        --exec-path
                        --html-path
                        --work-tree=
+                       --namespace=
                        --help
                        "
                        ;;
index 98d2aee67fc1f6bfdfc960527b6f0bf6acf5122a..2f7b270566471ebe8088cd2f024c0ca5e49eee4c 100755 (executable)
@@ -342,6 +342,11 @@ def gitConfig(key, args = None): # set args to "--bool", for instance
         _gitConfig[key] = read_pipe(cmd, ignore_error=True).strip()
     return _gitConfig[key]
 
+def gitConfigList(key):
+    if not _gitConfig.has_key(key):
+        _gitConfig[key] = read_pipe("git config --get-all %s" % key, ignore_error=True).strip().split(os.linesep)
+    return _gitConfig[key]
+
 def p4BranchesInGit(branchesAreInRemotes = True):
     branches = {}
 
@@ -774,17 +779,22 @@ class P4Submit(Command, P4UserMap):
 
         if not self.detectRenames:
             # If not explicitly set check the config variable
-            self.detectRenames = gitConfig("git-p4.detectRenames").lower() == "true"
+            self.detectRenames = gitConfig("git-p4.detectRenames")
 
-        if self.detectRenames:
+        if self.detectRenames.lower() == "false" or self.detectRenames == "":
+            diffOpts = ""
+        elif self.detectRenames.lower() == "true":
             diffOpts = "-M"
         else:
-            diffOpts = ""
+            diffOpts = "-M%s" % self.detectRenames
 
-        if gitConfig("git-p4.detectCopies").lower() == "true":
+        detectCopies = gitConfig("git-p4.detectCopies")
+        if detectCopies.lower() == "true":
             diffOpts += " -C"
+        elif detectCopies != "" and detectCopies.lower() != "false":
+            diffOpts += " -C%s" % detectCopies
 
-        if gitConfig("git-p4.detectCopiesHarder").lower() == "true":
+        if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true":
             diffOpts += " --find-copies-harder"
 
         diff = read_pipe_lines("git diff-tree -r %s \"%s^\" \"%s\"" % (diffOpts, id, id))
@@ -1450,7 +1460,13 @@ class P4Sync(Command, P4UserMap):
     def getBranchMapping(self):
         lostAndFoundBranches = set()
 
-        for info in p4CmdList("branches"):
+        user = gitConfig("git-p4.branchUser")
+        if len(user) > 0:
+            command = "branches -u %s" % user
+        else:
+            command = "branches"
+
+        for info in p4CmdList(command):
             details = p4Cmd("branch -o %s" % info["branch"])
             viewIdx = 0
             while details.has_key("View%s" % viewIdx):
@@ -1479,6 +1495,25 @@ class P4Sync(Command, P4UserMap):
                     if source not in self.knownBranches:
                         lostAndFoundBranches.add(source)
 
+        # Perforce does not strictly require branches to be defined, so we also
+        # check git config for a branch list.
+        #
+        # Example of branch definition in git config file:
+        # [git-p4]
+        #   branchList=main:branchA
+        #   branchList=main:branchB
+        #   branchList=branchA:branchC
+        configBranches = gitConfigList("git-p4.branchList")
+        for branch in configBranches:
+            if branch:
+                (source, destination) = branch.split(":")
+                self.knownBranches[destination] = source
+
+                lostAndFoundBranches.discard(destination)
+
+                if source not in self.knownBranches:
+                    lostAndFoundBranches.add(source)
+
 
         for branch in lostAndFoundBranches:
             self.knownBranches[branch] = branch
@@ -1649,7 +1684,8 @@ class P4Sync(Command, P4UserMap):
     def importHeadRevision(self, revision):
         print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch)
 
-        details = { "user" : "git perforce import user", "time" : int(time.time()) }
+        details = {}
+        details["user"] = "git perforce import user"
         details["desc"] = ("Initial import of %s from the state at revision %s\n"
                            % (' '.join(self.depotPaths), revision))
         details["change"] = revision
@@ -1689,6 +1725,18 @@ class P4Sync(Command, P4UserMap):
             fileCnt = fileCnt + 1
 
         details["change"] = newestRevision
+
+        # Use time from top-most change so that all git-p4 clones of
+        # the same p4 repo have the same commit SHA1s.
+        res = p4CmdList("describe -s %d" % newestRevision)
+        newestTime = None
+        for r in res:
+            if r.has_key('time'):
+                newestTime = int(r['time'])
+        if newestTime is None:
+            die("\"describe -s\" on newest change %d did not give a time")
+        details["time"] = newestTime
+
         self.updateOptionDict(details)
         try:
             self.commit(details, self.extractFilesFromCommit(details), self.branch, self.depotPaths)
@@ -1811,12 +1859,14 @@ class P4Sync(Command, P4UserMap):
                     else:
                         paths = []
                         for (prev, cur) in zip(self.previousDepotPaths, depotPaths):
-                            for i in range(0, min(len(cur), len(prev))):
-                                if cur[i] <> prev[i]:
+                            prev_list = prev.split("/")
+                            cur_list = cur.split("/")
+                            for i in range(0, min(len(cur_list), len(prev_list))):
+                                if cur_list[i] <> prev_list[i]:
                                     i = i - 1
                                     break
 
-                            paths.append (cur[:i + 1])
+                            paths.append ("/".join(cur_list[:i + 1]))
 
                         self.previousDepotPaths = paths
 
index caa4bb3e30c081394b464de6e92ca3298a87fdd1..52003ae9045626077009811cd8e10c1135d69cd0 100644 (file)
@@ -232,6 +232,44 @@ git-p4.skipUserNameCheck
 When submitting, git-p4 checks that the git commits are authored by the current
 p4 user, and warns if they are not. This disables the check.
 
+git-p4.detectRenames
+
+Detect renames when submitting changes to Perforce server. Will enable -M git
+argument. Can be optionally set to a number representing the threshold
+percentage value of the rename detection.
+
+  git config [--global] git-p4.detectRenames true
+  git config [--global] git-p4.detectRenames 50
+
+git-p4.detectCopies
+
+Detect copies when submitting changes to Perforce server. Will enable -C git
+argument. Can be optionally set to a number representing the threshold
+percentage value of the copy detection.
+
+  git config [--global] git-p4.detectCopies true
+  git config [--global] git-p4.detectCopies 80
+
+git-p4.detectCopiesHarder
+
+Detect copies even between files that did not change when submitting changes to
+Perforce server. Will enable --find-copies-harder git argument.
+
+  git config [--global] git-p4.detectCopies true
+
+git-p4.branchUser
+
+Only use branch specifications defined by the selected username.
+
+  git config [--global] git-p4.branchUser username
+
+git-p4.branchList
+
+List of branches to be imported when branch detection is enabled.
+
+  git config [--global] git-p4.branchList main:branchA
+  git config [--global] --add git-p4.branchList main:branchB
+
 Implementation Details...
 =========================
 
index 21989fc6ab84c0503cdc9418673d9d0bf06f9d49..ba077c13f96779d5b29237e83974b0910b4bbdde 100755 (executable)
 # will have put this somewhere standard.  You should make this script
 # executable then link to it in the repository you would like to use it in.
 # For example, on debian the hook is stored in
-# /usr/share/doc/git-core/contrib/hooks/post-receive-email:
+# /usr/share/git-core/contrib/hooks/post-receive-email:
 #
 #  chmod a+x post-receive-email
 #  cd /path/to/your/repository.git
-#  ln -sf /usr/share/doc/git-core/contrib/hooks/post-receive-email hooks/post-receive
+#  ln -sf /usr/share/git-core/contrib/hooks/post-receive-email hooks/post-receive
 #
 # This hook script assumes it is enabled on the central repository of a
 # project, with all users pushing only to it and not between each other.  It
 #   email body. If not specified, there is no limit.
 #   Lines beyond the limit are suppressed and counted, and a final
 #   line is added indicating the number of suppressed lines.
+# hooks.diffopts
+#   Alternate options for the git diff-tree invocation that shows changes.
+#   Default is "--stat --summary --find-copies-harder". Add -p to those
+#   options to include a unified diff of changes in addition to the usual
+#   summary output.
 #
 # Notes
 # -----
@@ -446,7 +451,7 @@ generate_update_branch_email()
        # non-fast-forward updates.
        echo ""
        echo "Summary of changes:"
-       git diff-tree --stat --summary --find-copies-harder $oldrev..$newrev
+       git diff-tree $diffopts $oldrev..$newrev
 }
 
 #
@@ -723,6 +728,8 @@ envelopesender=$(git config hooks.envelopesender)
 emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')
 custom_showrev=$(git config hooks.showrev)
 maxlines=$(git config hooks.emailmaxlines)
+diffopts=$(git config hooks.diffopts)
+: ${diffopts:="--stat --summary --find-copies-harder"}
 
 # --- Main loop
 # Allow dual mode: run from the command line just like the update hook, or
index 85939c29be67d4179a2afb9069b575afed4d8bb2..3bb5a4dd57c669bc59be0e2317ef33b64b024992 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -533,7 +533,7 @@ static int ident_to_git(const char *path, const char *src, size_t len,
                dollar = memchr(src, '$', len);
                if (!dollar)
                        break;
-               memcpy(dst, src, dollar + 1 - src);
+               memmove(dst, src, dollar + 1 - src);
                dst += dollar + 1 - src;
                len -= dollar + 1 - src;
                src  = dollar + 1;
@@ -553,7 +553,7 @@ static int ident_to_git(const char *path, const char *src, size_t len,
                        src  = dollar + 1;
                }
        }
-       memcpy(dst, src, len);
+       memmove(dst, src, len);
        strbuf_setlen(buf, dst + len - buf->buf);
        return 1;
 }
@@ -727,7 +727,7 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
                git_config(read_convert_config, NULL);
        }
 
-       if (!git_checkattr(path, NUM_CONV_ATTRS, ccheck)) {
+       if (!git_check_attr(path, NUM_CONV_ATTRS, ccheck)) {
                ca->crlf_action = git_path_check_crlf(path, ccheck + 4);
                if (ca->crlf_action == CRLF_GUESS)
                        ca->crlf_action = git_path_check_crlf(path, ccheck + 0);
diff --git a/date.c b/date.c
index 896fbb48060c673b8dc2f2aa6ea3de3c1042fbd2..353e0a5e53f13c36549e65452931f254de3423c4 100644 (file)
--- a/date.c
+++ b/date.c
@@ -552,23 +552,35 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
 static int match_tz(const char *date, int *offp)
 {
        char *end;
-       int offset = strtoul(date+1, &end, 10);
-       int min, hour;
-       int n = end - date - 1;
+       int hour = strtoul(date + 1, &end, 10);
+       int n = end - (date + 1);
+       int min = 0;
 
-       min = offset % 100;
-       hour = offset / 100;
+       if (n == 4) {
+               /* hhmm */
+               min = hour % 100;
+               hour = hour / 100;
+       } else if (n != 2) {
+               min = 99; /* random crap */
+       } else if (*end == ':') {
+               /* hh:mm? */
+               min = strtoul(end + 1, &end, 10);
+               if (end - (date + 1) != 5)
+                       min = 99; /* random crap */
+       } /* otherwise we parsed "hh" */
 
        /*
-        * Don't accept any random crap.. At least 3 digits, and
-        * a valid minute. We might want to check that the minutes
-        * are divisible by 30 or something too.
+        * Don't accept any random crap. Even though some places have
+        * offset larger than 12 hours (e.g. Pacific/Kiritimati is at
+        * UTC+14), there is something wrong if hour part is much
+        * larger than that. We might also want to check that the
+        * minutes are divisible by 15 or something too. (Offset of
+        * Kathmandu, Nepal is UTC+5:45)
         */
-       if (min < 60 && n > 2) {
-               offset = hour*60+min;
+       if (min < 60 && hour < 24) {
+               int offset = hour * 60 + min;
                if (*date == '-')
                        offset = -offset;
-
                *offp = offset;
        }
        return end - date;
index 2e09500c8210e22d6c81484aa198f1d811a9933d..62f4cd94cfbc4d3fe9e46c84f318af6624349a48 100644 (file)
@@ -289,7 +289,7 @@ static void show_new_file(struct rev_info *revs,
 
        /*
         * New file in the index: it might actually be different in
-        * the working copy.
+        * the working tree.
         */
        if (get_stat_data(new, &sha1, &mode, cached, match_missing,
            &dirty_submodule, &revs->diffopt) < 0)
@@ -379,7 +379,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
        if (cached && idx && ce_stage(idx)) {
                struct diff_filepair *pair;
                pair = diff_unmerge(&revs->diffopt, idx->name);
-               fill_filespec(pair->one, idx->sha1, idx->ce_mode);
+               if (tree)
+                       fill_filespec(pair->one, tree->sha1, tree->ce_mode);
                return;
        }
 
@@ -444,20 +445,19 @@ static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
        return 0;
 }
 
-int run_diff_index(struct rev_info *revs, int cached)
+static int diff_cache(struct rev_info *revs,
+                     const unsigned char *tree_sha1,
+                     const char *tree_name,
+                     int cached)
 {
-       struct object *ent;
        struct tree *tree;
-       const char *tree_name;
-       struct unpack_trees_options opts;
        struct tree_desc t;
+       struct unpack_trees_options opts;
 
-       ent = revs->pending.objects[0].item;
-       tree_name = revs->pending.objects[0].name;
-       tree = parse_tree_indirect(ent->sha1);
+       tree = parse_tree_indirect(tree_sha1);
        if (!tree)
-               return error("bad tree object %s", tree_name);
-
+               return error("bad tree object %s",
+                            tree_name ? tree_name : sha1_to_hex(tree_sha1));
        memset(&opts, 0, sizeof(opts));
        opts.head_idx = 1;
        opts.index_only = cached;
@@ -468,9 +468,18 @@ int run_diff_index(struct rev_info *revs, int cached)
        opts.unpack_data = revs;
        opts.src_index = &the_index;
        opts.dst_index = NULL;
+       opts.pathspec = &revs->diffopt.pathspec;
 
        init_tree_desc(&t, tree->buffer, tree->size);
-       if (unpack_trees(1, &t, &opts))
+       return unpack_trees(1, &t, &opts);
+}
+
+int run_diff_index(struct rev_info *revs, int cached)
+{
+       struct object_array_entry *ent;
+
+       ent = revs->pending.objects;
+       if (diff_cache(revs, ent->item->sha1, ent->name, cached))
                exit(128);
 
        diff_set_mnemonic_prefix(&revs->diffopt, "c/", cached ? "i/" : "w/");
@@ -482,53 +491,13 @@ int run_diff_index(struct rev_info *revs, int cached)
 
 int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
 {
-       struct tree *tree;
        struct rev_info revs;
-       int i;
-       struct cache_entry **dst;
-       struct cache_entry *last = NULL;
-       struct unpack_trees_options opts;
-       struct tree_desc t;
-
-       /*
-        * This is used by git-blame to run diff-cache internally;
-        * it potentially needs to repeatedly run this, so we will
-        * start by removing the higher order entries the last round
-        * left behind.
-        */
-       dst = active_cache;
-       for (i = 0; i < active_nr; i++) {
-               struct cache_entry *ce = active_cache[i];
-               if (ce_stage(ce)) {
-                       if (last && !strcmp(ce->name, last->name))
-                               continue;
-                       cache_tree_invalidate_path(active_cache_tree,
-                                                  ce->name);
-                       last = ce;
-                       ce->ce_flags |= CE_REMOVE;
-               }
-               *dst++ = ce;
-       }
-       active_nr = dst - active_cache;
 
        init_revisions(&revs, NULL);
        init_pathspec(&revs.prune_data, opt->pathspec.raw);
-       tree = parse_tree_indirect(tree_sha1);
-       if (!tree)
-               die("bad tree object %s", sha1_to_hex(tree_sha1));
+       revs.diffopt = *opt;
 
-       memset(&opts, 0, sizeof(opts));
-       opts.head_idx = 1;
-       opts.index_only = 1;
-       opts.diff_index_cached = !DIFF_OPT_TST(opt, FIND_COPIES_HARDER);
-       opts.merge = 1;
-       opts.fn = oneway_diff;
-       opts.unpack_data = &revs;
-       opts.src_index = &the_index;
-       opts.dst_index = &the_index;
-
-       init_tree_desc(&t, tree->buffer, tree->size);
-       if (unpack_trees(1, &t, &opts))
+       if (diff_cache(&revs, tree_sha1, NULL, 1))
                exit(128);
        return 0;
 }
diff --git a/diff.c b/diff.c
index 93ef9a265ca6b52b644468979dba732c70b5097a..977ca7125b9acc603ce6c1d27c57a75c9d21fbdf 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -137,7 +137,7 @@ static int git_config_rename(const char *var, const char *value)
 int git_diff_ui_config(const char *var, const char *value, void *cb)
 {
        if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
-               diff_use_color_default = git_config_colorbool(var, value, -1);
+               diff_use_color_default = git_config_colorbool(var, value);
                return 0;
        }
        if (!strcmp(var, "diff.renames")) {
@@ -164,6 +164,9 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
        if (!strcmp(var, "diff.ignoresubmodules"))
                handle_ignore_submodules_arg(&default_diff_options, value);
 
+       if (git_color_config(var, value, cb) < 0)
+               return -1;
+
        return git_diff_basic_config(var, value, cb);
 }
 
@@ -212,7 +215,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
        if (!prefixcmp(var, "submodule."))
                return parse_submodule_config_option(var, value);
 
-       return git_color_default_config(var, value, cb);
+       return git_default_config(var, value, cb);
 }
 
 static char *quote_two(const char *one, const char *two)
@@ -583,11 +586,10 @@ static void emit_rewrite_diff(const char *name_a,
                              struct diff_options *o)
 {
        int lc_a, lc_b;
-       int color_diff = DIFF_OPT_TST(o, COLOR_DIFF);
        const char *name_a_tab, *name_b_tab;
-       const char *metainfo = diff_get_color(color_diff, DIFF_METAINFO);
-       const char *fraginfo = diff_get_color(color_diff, DIFF_FRAGINFO);
-       const char *reset = diff_get_color(color_diff, DIFF_RESET);
+       const char *metainfo = diff_get_color(o->use_color, DIFF_METAINFO);
+       const char *fraginfo = diff_get_color(o->use_color, DIFF_FRAGINFO);
+       const char *reset = diff_get_color(o->use_color, DIFF_RESET);
        static struct strbuf a_name = STRBUF_INIT, b_name = STRBUF_INIT;
        const char *a_prefix, *b_prefix;
        char *data_one, *data_two;
@@ -623,7 +625,7 @@ static void emit_rewrite_diff(const char *name_a,
        size_two = fill_textconv(textconv_two, two, &data_two);
 
        memset(&ecbdata, 0, sizeof(ecbdata));
-       ecbdata.color_diff = color_diff;
+       ecbdata.color_diff = want_color(o->use_color);
        ecbdata.found_changesp = &o->found_changes;
        ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a);
        ecbdata.opt = o;
@@ -1004,7 +1006,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
 
 const char *diff_get_color(int diff_use_color, enum color_diff ix)
 {
-       if (diff_use_color)
+       if (want_color(diff_use_color))
                return diff_colors[ix];
        return "";
 }
@@ -1808,11 +1810,10 @@ static int is_conflict_marker(const char *line, int marker_size, unsigned long l
 static void checkdiff_consume(void *priv, char *line, unsigned long len)
 {
        struct checkdiff_t *data = priv;
-       int color_diff = DIFF_OPT_TST(data->o, COLOR_DIFF);
        int marker_size = data->conflict_marker_size;
-       const char *ws = diff_get_color(color_diff, DIFF_WHITESPACE);
-       const char *reset = diff_get_color(color_diff, DIFF_RESET);
-       const char *set = diff_get_color(color_diff, DIFF_FILE_NEW);
+       const char *ws = diff_get_color(data->o->use_color, DIFF_WHITESPACE);
+       const char *reset = diff_get_color(data->o->use_color, DIFF_RESET);
+       const char *set = diff_get_color(data->o->use_color, DIFF_FILE_NEW);
        char *err;
        char *line_prefix = "";
        struct strbuf *msgbuf;
@@ -2157,7 +2158,7 @@ static void builtin_diff(const char *name_a,
                memset(&xecfg, 0, sizeof(xecfg));
                memset(&ecbdata, 0, sizeof(ecbdata));
                ecbdata.label_path = lbl;
-               ecbdata.color_diff = DIFF_OPT_TST(o, COLOR_DIFF);
+               ecbdata.color_diff = want_color(o->use_color);
                ecbdata.found_changesp = &o->found_changes;
                ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a);
                if (ecbdata.ws_rule & WS_BLANK_AT_EOF)
@@ -2205,7 +2206,7 @@ static void builtin_diff(const char *name_a,
                                        break;
                                }
                        }
-                       if (DIFF_OPT_TST(o, COLOR_DIFF)) {
+                       if (want_color(o->use_color)) {
                                struct diff_words_style *st = ecbdata.diff_words->style;
                                st->old.color = diff_get_color_opt(o, DIFF_FILE_OLD);
                                st->new.color = diff_get_color_opt(o, DIFF_FILE_NEW);
@@ -2855,7 +2856,7 @@ static void run_diff_cmd(const char *pgm,
                 */
                fill_metainfo(msg, name, other, one, two, o, p,
                              &must_show_header,
-                             DIFF_OPT_TST(o, COLOR_DIFF) && !pgm);
+                             want_color(o->use_color) && !pgm);
                xfrm_msg = msg->len ? msg->buf : NULL;
        }
 
@@ -3021,8 +3022,7 @@ void diff_setup(struct diff_options *options)
 
        options->change = diff_change;
        options->add_remove = diff_addremove;
-       if (diff_use_color_default > 0)
-               DIFF_OPT_SET(options, COLOR_DIFF);
+       options->use_color = diff_use_color_default;
        options->detect_rename = diff_detect_rename_default;
 
        if (diff_no_prefix) {
@@ -3385,6 +3385,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
        }
 
        /* xdiff options */
+       else if (!strcmp(arg, "--minimal"))
+               DIFF_XDL_SET(options, NEED_MINIMAL);
+       else if (!strcmp(arg, "--no-minimal"))
+               DIFF_XDL_CLR(options, NEED_MINIMAL);
        else if (!strcmp(arg, "-w") || !strcmp(arg, "--ignore-all-space"))
                DIFF_XDL_SET(options, IGNORE_WHITESPACE);
        else if (!strcmp(arg, "-b") || !strcmp(arg, "--ignore-space-change"))
@@ -3393,6 +3397,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
        else if (!strcmp(arg, "--patience"))
                DIFF_XDL_SET(options, PATIENCE_DIFF);
+       else if (!strcmp(arg, "--histogram"))
+               DIFF_XDL_SET(options, HISTOGRAM_DIFF);
 
        /* flags options */
        else if (!strcmp(arg, "--binary")) {
@@ -3410,24 +3416,21 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
        else if (!strcmp(arg, "--follow"))
                DIFF_OPT_SET(options, FOLLOW_RENAMES);
        else if (!strcmp(arg, "--color"))
-               DIFF_OPT_SET(options, COLOR_DIFF);
+               options->use_color = 1;
        else if (!prefixcmp(arg, "--color=")) {
-               int value = git_config_colorbool(NULL, arg+8, -1);
-               if (value == 0)
-                       DIFF_OPT_CLR(options, COLOR_DIFF);
-               else if (value > 0)
-                       DIFF_OPT_SET(options, COLOR_DIFF);
-               else
+               int value = git_config_colorbool(NULL, arg+8);
+               if (value < 0)
                        return error("option `color' expects \"always\", \"auto\", or \"never\"");
+               options->use_color = value;
        }
        else if (!strcmp(arg, "--no-color"))
-               DIFF_OPT_CLR(options, COLOR_DIFF);
+               options->use_color = 0;
        else if (!strcmp(arg, "--color-words")) {
-               DIFF_OPT_SET(options, COLOR_DIFF);
+               options->use_color = 1;
                options->word_diff = DIFF_WORDS_COLOR;
        }
        else if (!prefixcmp(arg, "--color-words=")) {
-               DIFF_OPT_SET(options, COLOR_DIFF);
+               options->use_color = 1;
                options->word_diff = DIFF_WORDS_COLOR;
                options->word_regex = arg + 14;
        }
@@ -3440,7 +3443,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                if (!strcmp(type, "plain"))
                        options->word_diff = DIFF_WORDS_PLAIN;
                else if (!strcmp(type, "color")) {
-                       DIFF_OPT_SET(options, COLOR_DIFF);
+                       options->use_color = 1;
                        options->word_diff = DIFF_WORDS_COLOR;
                }
                else if (!strcmp(type, "porcelain"))
diff --git a/diff.h b/diff.h
index b920a20f80936ab66f5fe88c950dd35e38e1e856..8c66b59517305546d3e2f66fca652284468e1da1 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -58,7 +58,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
 #define DIFF_OPT_SILENT_ON_REMOVE    (1 <<  5)
 #define DIFF_OPT_FIND_COPIES_HARDER  (1 <<  6)
 #define DIFF_OPT_FOLLOW_RENAMES      (1 <<  7)
-#define DIFF_OPT_COLOR_DIFF          (1 <<  8)
+/* (1 <<  8) unused */
 /* (1 <<  9) unused */
 #define DIFF_OPT_HAS_CHANGES         (1 << 10)
 #define DIFF_OPT_QUICK               (1 << 11)
@@ -101,6 +101,7 @@ struct diff_options {
        const char *single_follow;
        const char *a_prefix, *b_prefix;
        unsigned flags;
+       int use_color;
        int context;
        int interhunkcontext;
        int break_opt;
@@ -160,7 +161,7 @@ enum color_diff {
 };
 const char *diff_get_color(int diff_use_color, enum color_diff ix);
 #define diff_get_color_opt(o, ix) \
-       diff_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)
+       diff_get_color((o)->use_color, ix)
 
 
 extern const char mime_boundary_leader[];
index ea03b9107eb2e85dd4a4c5ad93ac08dfe7e1c9f0..c3760cfefd5dd123481b869eac3081b6e7d93201 100644 (file)
@@ -6,6 +6,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "xdiff-interface.h"
+#include "kwset.h"
 
 struct diffgrep_cb {
        regex_t *regexp;
@@ -146,7 +147,7 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
 
 static unsigned int contains(struct diff_filespec *one,
                             const char *needle, unsigned long len,
-                            regex_t *regexp)
+                            regex_t *regexp, kwset_t kws)
 {
        unsigned int cnt;
        unsigned long sz;
@@ -175,9 +176,12 @@ static unsigned int contains(struct diff_filespec *one,
 
        } else { /* Classic exact string match */
                while (sz) {
-                       const char *found = memmem(data, sz, needle, len);
-                       if (!found)
+                       size_t offset = kwsexec(kws, data, sz, NULL);
+                       const char *found;
+                       if (offset == -1)
                                break;
+                       else
+                               found = data + offset;
                        sz -= found - data + len;
                        data = found + len;
                        cnt++;
@@ -195,6 +199,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
        unsigned long len = strlen(needle);
        int i, has_changes;
        regex_t regex, *regexp = NULL;
+       kwset_t kws = NULL;
        struct diff_queue_struct outq;
        DIFF_QUEUE_CLEAR(&outq);
 
@@ -209,6 +214,10 @@ static void diffcore_pickaxe_count(struct diff_options *o)
                        die("invalid pickaxe regex: %s", errbuf);
                }
                regexp = &regex;
+       } else {
+               kws = kwsalloc(NULL);
+               kwsincr(kws, needle, len);
+               kwsprep(kws);
        }
 
        if (opts & DIFF_PICKAXE_ALL) {
@@ -219,16 +228,16 @@ static void diffcore_pickaxe_count(struct diff_options *o)
                                if (!DIFF_FILE_VALID(p->two))
                                        continue; /* ignore unmerged */
                                /* created */
-                               if (contains(p->two, needle, len, regexp))
+                               if (contains(p->two, needle, len, regexp, kws))
                                        has_changes++;
                        }
                        else if (!DIFF_FILE_VALID(p->two)) {
-                               if (contains(p->one, needle, len, regexp))
+                               if (contains(p->one, needle, len, regexp, kws))
                                        has_changes++;
                        }
                        else if (!diff_unmodified_pair(p) &&
-                                contains(p->one, needle, len, regexp) !=
-                                contains(p->two, needle, len, regexp))
+                                contains(p->one, needle, len, regexp, kws) !=
+                                contains(p->two, needle, len, regexp, kws))
                                has_changes++;
                }
                if (has_changes)
@@ -251,16 +260,17 @@ static void diffcore_pickaxe_count(struct diff_options *o)
                                if (!DIFF_FILE_VALID(p->two))
                                        ; /* ignore unmerged */
                                /* created */
-                               else if (contains(p->two, needle, len, regexp))
+                               else if (contains(p->two, needle, len, regexp,
+                                                 kws))
                                        has_changes = 1;
                        }
                        else if (!DIFF_FILE_VALID(p->two)) {
-                               if (contains(p->one, needle, len, regexp))
+                               if (contains(p->one, needle, len, regexp, kws))
                                        has_changes = 1;
                        }
                        else if (!diff_unmodified_pair(p) &&
-                                contains(p->one, needle, len, regexp) !=
-                                contains(p->two, needle, len, regexp))
+                                contains(p->one, needle, len, regexp, kws) !=
+                                contains(p->two, needle, len, regexp, kws))
                                has_changes = 1;
 
                        if (has_changes)
@@ -271,6 +281,8 @@ static void diffcore_pickaxe_count(struct diff_options *o)
 
        if (opts & DIFF_PICKAXE_REGEX)
                regfree(&regex);
+       else
+               kwsfree(kws);
 
        free(q->queue);
        *q = outq;
index b8f1fdecf4d9e5e8f8e834eb55a374f1af8352fd..8f32b824cdc1bac1f094d743f3bee9f32890edca 100644 (file)
@@ -45,7 +45,7 @@ struct diff_filespec {
        unsigned dirty_submodule : 2;  /* For submodules: its work tree is dirty */
 #define DIRTY_SUBMODULE_UNTRACKED 1
 #define DIRTY_SUBMODULE_MODIFIED  2
-
+       unsigned has_more_entries : 1; /* only appear in combined diff */
        struct userdiff_driver *driver;
        /* data should be considered "binary"; -1 means "don't know yet" */
        int is_binary;
index 94d58fd24413ec1d1a5769029bd5149b609f0d4e..d60b73f6a5a88632a2a36140bf719484adec9f39 100644 (file)
@@ -8,6 +8,7 @@
  * are.
  */
 #include "cache.h"
+#include "refs.h"
 
 char git_default_email[MAX_GITNAME];
 char git_default_name[MAX_GITNAME];
@@ -28,6 +29,7 @@ const char *git_log_output_encoding;
 int shared_repository = PERM_UMASK;
 const char *apply_default_whitespace;
 const char *apply_default_ignorewhitespace;
+const char *git_attributes_file;
 int zlib_compression_level = Z_BEST_SPEED;
 int core_compression_level;
 int core_compression_seen;
@@ -36,6 +38,7 @@ size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
 size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
 size_t delta_base_cache_limit = 16 * 1024 * 1024;
 unsigned long big_file_threshold = 512 * 1024 * 1024;
+const char *log_pack_access;
 const char *pager_program;
 int pager_use_color = 1;
 const char *editor_program;
@@ -65,6 +68,9 @@ int core_preload_index = 0;
 char *git_work_tree_cfg;
 static char *work_tree;
 
+static const char *namespace;
+static size_t namespace_len;
+
 static const char *git_dir;
 static char *git_object_dir, *git_index_file, *git_graft_file;
 
@@ -86,12 +92,33 @@ const char * const local_repo_env[LOCAL_REPO_ENV_SIZE + 1] = {
        NULL
 };
 
+static char *expand_namespace(const char *raw_namespace)
+{
+       struct strbuf buf = STRBUF_INIT;
+       struct strbuf **components, **c;
+
+       if (!raw_namespace || !*raw_namespace)
+               return xstrdup("");
+
+       strbuf_addstr(&buf, raw_namespace);
+       components = strbuf_split(&buf, '/');
+       strbuf_reset(&buf);
+       for (c = components; *c; c++)
+               if (strcmp((*c)->buf, "/") != 0)
+                       strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf);
+       strbuf_list_free(components);
+       if (check_ref_format(buf.buf) != CHECK_REF_FORMAT_OK)
+               die("bad git namespace path \"%s\"", raw_namespace);
+       strbuf_addch(&buf, '/');
+       return strbuf_detach(&buf, NULL);
+}
+
 static void setup_git_env(void)
 {
        git_dir = getenv(GIT_DIR_ENVIRONMENT);
        git_dir = git_dir ? xstrdup(git_dir) : NULL;
        if (!git_dir) {
-               git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
+               git_dir = read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
                git_dir = git_dir ? xstrdup(git_dir) : NULL;
        }
        if (!git_dir)
@@ -111,6 +138,8 @@ static void setup_git_env(void)
                git_graft_file = git_pathdup("info/grafts");
        if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
                read_replace_refs = 0;
+       namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
+       namespace_len = strlen(namespace);
 }
 
 int is_bare_repository(void)
@@ -131,6 +160,20 @@ const char *get_git_dir(void)
        return git_dir;
 }
 
+const char *get_git_namespace(void)
+{
+       if (!namespace)
+               setup_git_env();
+       return namespace;
+}
+
+const char *strip_namespace(const char *namespaced_ref)
+{
+       if (prefixcmp(namespaced_ref, get_git_namespace()) != 0)
+               return NULL;
+       return namespaced_ref + namespace_len;
+}
+
 static int git_work_tree_initialized;
 
 /*
index 9e8d1868aa3b178f4b61ef57430883854898b044..742e7da6b8b58dd0803d89c6ad6c59589274a31b 100644 (file)
@@ -170,6 +170,11 @@ Format of STDIN stream:
 #define DEPTH_BITS 13
 #define MAX_DEPTH ((1<<DEPTH_BITS)-1)
 
+/*
+ * We abuse the setuid bit on directories to mean "do not delta".
+ */
+#define NO_DELTA S_ISUID
+
 struct object_entry {
        struct pack_idx_entry idx;
        struct object_entry *next;
@@ -284,6 +289,7 @@ static uintmax_t marks_set_count;
 static uintmax_t object_count_by_type[1 << TYPE_BITS];
 static uintmax_t duplicate_count_by_type[1 << TYPE_BITS];
 static uintmax_t delta_count_by_type[1 << TYPE_BITS];
+static uintmax_t delta_count_attempts_by_type[1 << TYPE_BITS];
 static unsigned long object_count;
 static unsigned long branch_count;
 static unsigned long branch_load_count;
@@ -355,6 +361,7 @@ static unsigned int cmd_save = 100;
 static uintmax_t next_mark;
 static struct strbuf new_data = STRBUF_INIT;
 static int seen_data_command;
+static int require_explicit_termination;
 
 /* Signal handling */
 static volatile sig_atomic_t checkpoint_requested;
@@ -1044,6 +1051,7 @@ static int store_object(
        }
 
        if (last && last->data.buf && last->depth < max_depth && dat->len > 20) {
+               delta_count_attempts_by_type[type]++;
                delta = diff_delta(last->data.buf, last->data.len,
                        dat->buf, dat->len,
                        &deltalen, dat->len - 20);
@@ -1415,8 +1423,9 @@ static void mktree(struct tree_content *t, int v, struct strbuf *b)
                struct tree_entry *e = t->entries[i];
                if (!e->versions[v].mode)
                        continue;
-               strbuf_addf(b, "%o %s%c", (unsigned int)e->versions[v].mode,
-                                       e->name->str_dat, '\0');
+               strbuf_addf(b, "%o %s%c",
+                       (unsigned int)(e->versions[v].mode & ~NO_DELTA),
+                       e->name->str_dat, '\0');
                strbuf_add(b, e->versions[v].sha1, 20);
        }
 }
@@ -1426,7 +1435,7 @@ static void store_tree(struct tree_entry *root)
        struct tree_content *t = root->tree;
        unsigned int i, j, del;
        struct last_object lo = { STRBUF_INIT, 0, 0, /* no_swap */ 1 };
-       struct object_entry *le;
+       struct object_entry *le = NULL;
 
        if (!is_null_sha1(root->versions[1].sha1))
                return;
@@ -1436,7 +1445,8 @@ static void store_tree(struct tree_entry *root)
                        store_tree(t->entries[i]);
        }
 
-       le = find_object(root->versions[0].sha1);
+       if (!(root->versions[0].mode & NO_DELTA))
+               le = find_object(root->versions[0].sha1);
        if (S_ISDIR(root->versions[0].mode) && le && le->pack_id == pack_id) {
                mktree(t, 0, &old_tree);
                lo.data = old_tree;
@@ -1470,6 +1480,7 @@ static void tree_content_replace(
 {
        if (!S_ISDIR(mode))
                die("Root cannot be a non-directory");
+       hashclr(root->versions[0].sha1);
        hashcpy(root->versions[1].sha1, sha1);
        if (root->tree)
                release_tree_content_recursive(root->tree);
@@ -1514,6 +1525,23 @@ static int tree_content_set(
                                if (e->tree)
                                        release_tree_content_recursive(e->tree);
                                e->tree = subtree;
+
+                               /*
+                                * We need to leave e->versions[0].sha1 alone
+                                * to avoid modifying the preimage tree used
+                                * when writing out the parent directory.
+                                * But after replacing the subdir with a
+                                * completely different one, it's not a good
+                                * delta base any more, and besides, we've
+                                * thrown away the tree entries needed to
+                                * make a delta against it.
+                                *
+                                * So let's just explicitly disable deltas
+                                * for the subtree.
+                                */
+                               if (S_ISDIR(e->versions[0].mode))
+                                       e->versions[0].mode |= NO_DELTA;
+
                                hashclr(root->versions[1].sha1);
                                return 1;
                        }
@@ -1968,32 +1996,41 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
 
 static char *parse_ident(const char *buf)
 {
-       const char *gt;
+       const char *ltgt;
        size_t name_len;
        char *ident;
 
-       gt = strrchr(buf, '>');
-       if (!gt)
+       /* ensure there is a space delimiter even if there is no name */
+       if (*buf == '<')
+               --buf;
+
+       ltgt = buf + strcspn(buf, "<>");
+       if (*ltgt != '<')
+               die("Missing < in ident string: %s", buf);
+       if (ltgt != buf && ltgt[-1] != ' ')
+               die("Missing space before < in ident string: %s", buf);
+       ltgt = ltgt + 1 + strcspn(ltgt + 1, "<>");
+       if (*ltgt != '>')
                die("Missing > in ident string: %s", buf);
-       gt++;
-       if (*gt != ' ')
+       ltgt++;
+       if (*ltgt != ' ')
                die("Missing space after > in ident string: %s", buf);
-       gt++;
-       name_len = gt - buf;
+       ltgt++;
+       name_len = ltgt - buf;
        ident = xmalloc(name_len + 24);
        strncpy(ident, buf, name_len);
 
        switch (whenspec) {
        case WHENSPEC_RAW:
-               if (validate_raw_date(gt, ident + name_len, 24) < 0)
-                       die("Invalid raw date \"%s\" in ident: %s", gt, buf);
+               if (validate_raw_date(ltgt, ident + name_len, 24) < 0)
+                       die("Invalid raw date \"%s\" in ident: %s", ltgt, buf);
                break;
        case WHENSPEC_RFC2822:
-               if (parse_date(gt, ident + name_len, 24) < 0)
-                       die("Invalid rfc2822 date \"%s\" in ident: %s", gt, buf);
+               if (parse_date(ltgt, ident + name_len, 24) < 0)
+                       die("Invalid rfc2822 date \"%s\" in ident: %s", ltgt, buf);
                break;
        case WHENSPEC_NOW:
-               if (strcmp("now", gt))
+               if (strcmp("now", ltgt))
                        die("Date in ident must be 'now': %s", buf);
                datestamp(ident + name_len, 24);
                break;
@@ -2689,13 +2726,13 @@ static void parse_new_tag(void)
                type = oe->type;
                hashcpy(sha1, oe->idx.sha1);
        } else if (!get_sha1(from, sha1)) {
-               unsigned long size;
-               char *buf;
-
-               buf = read_sha1_file(sha1, &type, &size);
-               if (!buf || size < 46)
-                       die("Not a valid commit: %s", from);
-               free(buf);
+               struct object_entry *oe = find_object(sha1);
+               if (!oe) {
+                       type = sha1_object_info(sha1, NULL);
+                       if (type < 0)
+                               die("Not a valid object: %s", from);
+               } else
+                       type = oe->type;
        } else
                die("Invalid ref name or SHA1 expression: %s", from);
        read_next_command();
@@ -2799,7 +2836,12 @@ static void cat_blob(struct object_entry *oe, unsigned char sha1[20])
        strbuf_release(&line);
        cat_blob_write(buf, size);
        cat_blob_write("\n", 1);
-       free(buf);
+       if (oe && oe->pack_id == pack_id) {
+               last_blob.offset = oe->idx.offset;
+               strbuf_attach(&last_blob.data, buf, size, size);
+               last_blob.depth = oe->depth;
+       } else
+               free(buf);
 }
 
 static void parse_cat_blob(void)
@@ -2928,7 +2970,7 @@ static void print_ls(int mode, const unsigned char *sha1, const char *path)
                /* mode SP type SP object_name TAB path LF */
                strbuf_reset(&line);
                strbuf_addf(&line, "%06o %s %s\t",
-                               mode, type, sha1_to_hex(sha1));
+                               mode & ~NO_DELTA, type, sha1_to_hex(sha1));
                quote_c_style(path, &line, NULL, 0);
                strbuf_addch(&line, '\n');
        }
@@ -3140,6 +3182,8 @@ static int parse_one_feature(const char *feature, int from_stream)
                relative_marks_paths = 1;
        } else if (!strcmp(feature, "no-relative-marks")) {
                relative_marks_paths = 0;
+       } else if (!strcmp(feature, "done")) {
+               require_explicit_termination = 1;
        } else if (!strcmp(feature, "force")) {
                force_update = 1;
        } else if (!strcmp(feature, "notes") || !strcmp(feature, "ls")) {
@@ -3290,6 +3334,8 @@ int main(int argc, const char **argv)
                        parse_reset_branch();
                else if (!strcmp("checkpoint", command_buf.buf))
                        parse_checkpoint();
+               else if (!strcmp("done", command_buf.buf))
+                       break;
                else if (!prefixcmp(command_buf.buf, "progress "))
                        parse_progress();
                else if (!prefixcmp(command_buf.buf, "feature "))
@@ -3309,6 +3355,9 @@ int main(int argc, const char **argv)
        if (!seen_data_command)
                parse_argv();
 
+       if (require_explicit_termination && feof(stdin))
+               die("stream ends early");
+
        end_packfile();
 
        dump_branches();
@@ -3330,10 +3379,10 @@ int main(int argc, const char **argv)
                fprintf(stderr, "---------------------------------------------------------------------\n");
                fprintf(stderr, "Alloc'd objects: %10" PRIuMAX "\n", alloc_count);
                fprintf(stderr, "Total objects:   %10" PRIuMAX " (%10" PRIuMAX " duplicates                  )\n", total_count, duplicate_count);
-               fprintf(stderr, "      blobs  :   %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]);
-               fprintf(stderr, "      trees  :   %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]);
-               fprintf(stderr, "      commits:   %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]);
-               fprintf(stderr, "      tags   :   %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG]);
+               fprintf(stderr, "      blobs  :   %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas of %10" PRIuMAX" attempts)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB], delta_count_attempts_by_type[OBJ_BLOB]);
+               fprintf(stderr, "      trees  :   %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas of %10" PRIuMAX" attempts)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE], delta_count_attempts_by_type[OBJ_TREE]);
+               fprintf(stderr, "      commits:   %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas of %10" PRIuMAX" attempts)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT], delta_count_attempts_by_type[OBJ_COMMIT]);
+               fprintf(stderr, "      tags   :   %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas of %10" PRIuMAX" attempts)\n", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG], delta_count_attempts_by_type[OBJ_TAG]);
                fprintf(stderr, "Total branches:  %10lu (%10lu loads     )\n", branch_count, branch_load_count);
                fprintf(stderr, "      marks:     %10" PRIuMAX " (%10" PRIuMAX " unique    )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count);
                fprintf(stderr, "      atoms:     %10u\n", atom_cnt);
diff --git a/fsck.c b/fsck.c
index 60bd4bbf6a2206e2b1991093ea5d84be7f338f73..6c855f84f01c19678399d85181da1094bd61b371 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -224,13 +224,15 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
 
 static int fsck_ident(char **ident, struct object *obj, fsck_error error_func)
 {
-       if (**ident == '<' || **ident == '\n')
-               return error_func(obj, FSCK_ERROR, "invalid author/committer line - missing space before email");
-       *ident += strcspn(*ident, "<\n");
-       if ((*ident)[-1] != ' ')
+       if (**ident == '<')
                return error_func(obj, FSCK_ERROR, "invalid author/committer line - missing space before email");
+       *ident += strcspn(*ident, "<>\n");
+       if (**ident == '>')
+               return error_func(obj, FSCK_ERROR, "invalid author/committer line - bad name");
        if (**ident != '<')
                return error_func(obj, FSCK_ERROR, "invalid author/committer line - missing email");
+       if ((*ident)[-1] != ' ')
+               return error_func(obj, FSCK_ERROR, "invalid author/committer line - missing space before email");
        (*ident)++;
        *ident += strcspn(*ident, "<>\n");
        if (**ident != '>')
index 3ef4861d04ed5fed14d31b92e047a03cf5362970..1093ef4ad6b9793fb829403c41391a09a07e57a2 100755 (executable)
@@ -15,8 +15,8 @@ do
      sed -n '
      /^NAME/,/git-'"$cmd"'/H
      ${
-            x
-            s/.*git-'"$cmd"' - \(.*\)/  {"'"$cmd"'", "\1"},/
+           x
+           s/.*git-'"$cmd"' - \(.*\)/  {"'"$cmd"'", "\1"},/
            p
      }' "Documentation/git-$cmd.txt"
 done
index 463c741dfc259927b4429f19972ced21d87c215e..016b5056eb29fb24d06667c340ad372ed096d4dc 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
@@ -22,6 +22,7 @@ whitespace=     pass it through git-apply
 ignore-space-change pass it through git-apply
 ignore-whitespace pass it through git-apply
 directory=      pass it through git-apply
+exclude=        pass it through git-apply
 C=              pass it through git-apply
 p=              pass it through git-apply
 patch-format=   format the patch(es) are in
@@ -89,11 +90,8 @@ safe_to_abort () {
        then
                return 0
        fi
-       (
-               gettext "You seem to have moved HEAD since the last 'am' failure.
-Not rewinding to ORIG_HEAD" &&
-               echo
-       ) >&2
+               gettextln "You seem to have moved HEAD since the last 'am' failure.
+Not rewinding to ORIG_HEAD" >&2
        return 1
 }
 
@@ -102,9 +100,9 @@ stop_here_user_resolve () {
            printf '%s\n' "$resolvemsg"
            stop_here $1
     fi
-    eval_gettext "When you have resolved this problem run \"\$cmdline --resolved\".
+    eval_gettextln "When you have resolved this problem run \"\$cmdline --resolved\".
 If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
-To restore the original branch and stop patching run \"\$cmdline --abort\"."; echo
+To restore the original branch and stop patching run \"\$cmdline --abort\"."
 
     stop_here $1
 }
@@ -118,7 +116,7 @@ go_next () {
 
 cannot_fallback () {
        echo "$1"
-       gettext "Cannot fall back to three-way merge."; echo
+       gettextln "Cannot fall back to three-way merge."
        exit 1
 }
 
@@ -196,10 +194,15 @@ check_patch_format () {
                return 0
        fi
 
-       # otherwise, check the first few lines of the first patch to try
-       # to detect its format
+       # otherwise, check the first few non-blank lines of the first
+       # patch to try to detect its format
        {
-               read l1
+               # Start from first line containing non-whitespace
+               l1=
+               while test -z "$l1"
+               do
+                       read l1
+               done
                read l2
                read l3
                case "$l1" in
@@ -292,7 +295,7 @@ split_patches () {
                        perl -ne 'BEGIN { $subject = 0 }
                                if ($subject > 1) { print ; }
                                elsif (/^\s+$/) { next ; }
-                               elsif (/^Author:/) { print s/Author/From/ ; }
+                               elsif (/^Author:/) { s/Author/From/ ; print ;}
                                elsif (/^(From|Date)/) { print ; }
                                elsif ($subject) {
                                        $subject = 2 ;
@@ -309,7 +312,8 @@ split_patches () {
                msgnum=
                ;;
        *)
-               if test -n "$parse_patch" ; then
+               if test -n "$patch_format"
+               then
                        clean_abort "$(eval_gettext "Patch format \$patch_format is not supported.")"
                else
                        clean_abort "$(gettext "Patch format detection failed.")"
@@ -366,7 +370,7 @@ do
                ;;
        --resolvemsg)
                shift; resolvemsg=$1 ;;
-       --whitespace|--directory)
+       --whitespace|--directory|--exclude)
                git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;;
        -C|-p)
                git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;;
@@ -511,6 +515,8 @@ else
        fi
 fi
 
+git update-index -q --refresh
+
 case "$resolved" in
 '')
        case "$HAS_HEAD" in
@@ -611,9 +617,9 @@ do
                        go_next && continue
 
                test -s "$dotest/patch" || {
-                       eval_gettext "Patch is empty.  Was it split wrong?
+                       eval_gettextln "Patch is empty.  Was it split wrong?
 If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
-To restore the original branch and stop patching run \"\$cmdline --abort\"."; echo
+To restore the original branch and stop patching run \"\$cmdline --abort\"."
                        stop_here $this
                }
                rm -f "$dotest/original-commit" "$dotest/author-script"
@@ -648,7 +654,7 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."; ec
 
        if test -z "$GIT_AUTHOR_EMAIL"
        then
-               gettext "Patch does not have a valid e-mail address."; echo
+               gettextln "Patch does not have a valid e-mail address."
                stop_here $this
        fi
 
@@ -699,7 +705,7 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."; ec
            action=again
            while test "$action" = again
            do
-               gettext "Commit Body is:"; echo
+               gettextln "Commit Body is:"
                echo "--------------------------"
                cat "$dotest/final-commit"
                echo "--------------------------"
@@ -763,16 +769,16 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."; ec
                # working tree.
                resolved=
                git diff-index --quiet --cached HEAD -- && {
-                       gettext "No changes - did you forget to use 'git add'?
+                       gettextln "No changes - did you forget to use 'git add'?
 If there is nothing left to stage, chances are that something else
-already introduced the same changes; you might want to skip this patch."; echo
+already introduced the same changes; you might want to skip this patch."
                        stop_here_user_resolve $this
                }
                unmerged=$(git ls-files -u)
                if test -n "$unmerged"
                then
-                       gettext "You still have unmerged paths in your index
-did you forget to use 'git add'?"; echo
+                       gettextln "You still have unmerged paths in your index
+did you forget to use 'git add'?"
                        stop_here_user_resolve $this
                fi
                apply_status=0
@@ -797,7 +803,7 @@ did you forget to use 'git add'?"; echo
        fi
        if test $apply_status != 0
        then
-               eval_gettext 'Patch failed at $msgnum $FIRSTLINE'; echo
+               eval_gettextln 'Patch failed at $msgnum $FIRSTLINE'
                stop_here_user_resolve $this
        fi
 
index 5fb42917a0a9c498dfc0c661f2f088d231024fd9..99efbe884528ffa730d6c0297e20d9de93d5ad9e 100755 (executable)
@@ -45,10 +45,7 @@ bisect_head()
 
 bisect_autostart() {
        test -s "$GIT_DIR/BISECT_START" || {
-               (
-                       gettext "You need to start by \"git bisect start\"" &&
-                       echo
-               ) >&2
+               gettextln "You need to start by \"git bisect start\"" >&2
                if test -t 0
                then
                        # TRANSLATORS: Make sure to include [Y] and [n] in your
@@ -273,10 +270,7 @@ bisect_next_check() {
        t,,good)
                # have bad but not good.  we could bisect although
                # this is less optimum.
-               (
-                       gettext "Warning: bisecting only with a bad commit." &&
-                       echo
-               ) >&2
+               gettextln "Warning: bisecting only with a bad commit." >&2
                if test -t 0
                then
                        # TRANSLATORS: Make sure to include [Y] and [n] in your
@@ -292,18 +286,12 @@ bisect_next_check() {
 
                if test -s "$GIT_DIR/BISECT_START"
                then
-                       (
-                               gettext "You need to give me at least one good and one bad revisions.
-(You can use \"git bisect bad\" and \"git bisect good\" for that.)" &&
-                               echo
-                       ) >&2
+                       gettextln "You need to give me at least one good and one bad revisions.
+(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
                else
-                       (
-                               gettext "You need to start by \"git bisect start\".
+                       gettextln "You need to start by \"git bisect start\".
 You then need to give me at least one good and one bad revisions.
-(You can use \"git bisect bad\" and \"git bisect good\" for that.)" &&
-                               echo
-                       ) >&2
+(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
                fi
                exit 1 ;;
        esac
@@ -356,7 +344,7 @@ bisect_visualize() {
 
 bisect_reset() {
        test -s "$GIT_DIR/BISECT_START" || {
-               gettext "We are not bisecting."; echo
+               gettextln "We are not bisecting."
                return
        }
        case "$#" in
@@ -429,18 +417,15 @@ bisect_run () {
        while true
        do
                command="$@"
-               eval_gettext "running \$command"; echo
+               eval_gettextln "running \$command"
                "$@"
                res=$?
 
                # Check for really bad run error.
                if [ $res -lt 0 -o $res -ge 128 ]
                then
-                       (
-                               eval_gettext "bisect run failed:
-exit code \$res from '\$command' is < 0 or >= 128" &&
-                               echo
-                       ) >&2
+                       eval_gettextln "bisect run failed:
+exit code \$res from '\$command' is < 0 or >= 128" >&2
                        exit $res
                fi
 
@@ -465,26 +450,20 @@ exit code \$res from '\$command' is < 0 or >= 128" &&
                if sane_grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
                        > /dev/null
                then
-                       (
-                               gettext "bisect run cannot continue any more" &&
-                               echo
-                       ) >&2
+                       gettextln "bisect run cannot continue any more" >&2
                        exit $res
                fi
 
                if [ $res -ne 0 ]
                then
-                       (
-                               eval_gettext "bisect run failed:
-'bisect_state \$state' exited with error code \$res" &&
-                               echo
-                       ) >&2
+                       eval_gettextln "bisect run failed:
+'bisect_state \$state' exited with error code \$res" >&2
                        exit $res
                fi
 
                if sane_grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null
                then
-                       gettext "bisect run success"; echo
+                       gettextln "bisect run success"
                        exit 0;
                fi
 
index ddfbf771492c599e7a6ca04bb39962cf4c7a784c..5ef8ff76f6fd262c3109d25d706ebd3db35c73fa 100644 (file)
@@ -240,6 +240,7 @@ extern char *gitbasename(char *);
 
 /* General helper functions */
 extern void vreportf(const char *prefix, const char *err, va_list params);
+extern void vwritef(int fd, const char *prefix, const char *err, va_list params);
 extern NORETURN void usage(const char *err);
 extern NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
@@ -248,6 +249,7 @@ extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
 
 extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
+extern void set_error_routine(void (*routine)(const char *err, va_list params));
 
 extern int prefixcmp(const char *str, const char *prefix);
 extern int suffixcmp(const char *str, const char *suffix);
index 0594bf7ca54c6b91d5f96dd86d8962e93459d004..8452890be974d30942f0acaa3f19282c1b8b25b2 100755 (executable)
@@ -13,7 +13,8 @@ TOOL_MODE=diff
 should_prompt () {
        prompt_merge=$(git config --bool mergetool.prompt || echo true)
        prompt=$(git config --bool difftool.prompt || echo $prompt_merge)
-       if test "$prompt" = true; then
+       if test "$prompt" = true
+       then
                test -z "$GIT_DIFFTOOL_NO_PROMPT"
        else
                test -n "$GIT_DIFFTOOL_PROMPT"
@@ -37,9 +38,11 @@ launch_merge_tool () {
 
        # $LOCAL and $REMOTE are temporary files so prompt
        # the user with the real $MERGED name before launching $merge_tool.
-       if should_prompt; then
+       if should_prompt
+       then
                printf "\nViewing: '$MERGED'\n"
-               if use_ext_cmd; then
+               if use_ext_cmd
+               then
                        printf "Hit return to launch '%s': " \
                                "$GIT_DIFFTOOL_EXTCMD"
                else
@@ -48,7 +51,8 @@ launch_merge_tool () {
                read ans
        fi
 
-       if use_ext_cmd; then
+       if use_ext_cmd
+       then
                export BASE
                eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
        else
@@ -56,8 +60,10 @@ launch_merge_tool () {
        fi
 }
 
-if ! use_ext_cmd; then
-       if test -n "$GIT_DIFF_TOOL"; then
+if ! use_ext_cmd
+then
+       if test -n "$GIT_DIFF_TOOL"
+       then
                merge_tool="$GIT_DIFF_TOOL"
        else
                merge_tool="$(get_merge_tool)" || exit
index 962a93b586571eb6fc60aae53c77f6e6b9fb281f..add2c0247fa91e0f629428c295fc581f19cf85e1 100755 (executable)
@@ -12,7 +12,7 @@
 
 functions=$(cat << \EOF
 warn () {
-        echo "$*" >&2
+       echo "$*" >&2
 }
 
 map()
@@ -98,19 +98,17 @@ set_ident () {
 }
 
 USAGE="[--env-filter <command>] [--tree-filter <command>]
-            [--index-filter <command>] [--parent-filter <command>]
-            [--msg-filter <command>] [--commit-filter <command>]
-            [--tag-name-filter <command>] [--subdirectory-filter <directory>]
-            [--original <namespace>] [-d <directory>] [-f | --force]
-            [<rev-list options>...]"
+       [--index-filter <command>] [--parent-filter <command>]
+       [--msg-filter <command>] [--commit-filter <command>]
+       [--tag-name-filter <command>] [--subdirectory-filter <directory>]
+       [--original <namespace>] [-d <directory>] [-f | --force]
+       [<rev-list options>...]"
 
 OPTIONS_SPEC=
 . git-sh-setup
 
 if [ "$(is_bare_repository)" = false ]; then
-       git diff-files --ignore-submodules --quiet &&
-       git diff-index --cached --quiet HEAD -- ||
-       die "Cannot rewrite branch(es) with a dirty working directory."
+       require_clean_work_tree 'rewrite branches'
 fi
 
 tempdir=.git-rewrite
@@ -363,7 +361,7 @@ while read commit parents; do
        sed -e '1,/^$/d' <../commit | \
                eval "$filter_msg" > ../message ||
                        die "msg filter failed: $filter_msg"
-       @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
+       workdir=$workdir @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
                $(git write-tree) $parentstr < ../message > ../map/$commit ||
                        die "could not write rewritten commit"
 done <../revs
index 7aeb96952f668baef2fd18383806e13a20415f19..f612cb847aca981e16cb6006fa08d870497c6263 100755 (executable)
@@ -117,7 +117,7 @@ case "${1:-.}${2:-.}${3:-.}" in
 
                # If we do not have enough common material, it is not
                # worth trying two-file merge using common subsections.
-               expr "$sz0" \< "$sz1" \* 2 >/dev/null || : >$orig
+               expr $sz0 \< $sz1 \* 2 >/dev/null || : >$orig
                ;;
        *)
                echo "Auto-merging $4"
index 91f90acfba2a710644f4a076d27d50e0fbb33c2d..ed630b208a80a36d729b5074a39bc53df0cabd59 100644 (file)
@@ -9,36 +9,19 @@ merge_mode() {
 }
 
 translate_merge_tool_path () {
-       case "$1" in
-       araxis)
-               echo compare
-               ;;
-       bc3)
-               echo bcompare
-               ;;
-       emerge)
-               echo emacs
-               ;;
-       gvimdiff|gvimdiff2)
-               echo gvim
-               ;;
-       vimdiff|vimdiff2)
-               echo vim
-               ;;
-       *)
-               echo "$1"
-               ;;
-       esac
+       echo "$1"
 }
 
 check_unchanged () {
-       if test "$MERGED" -nt "$BACKUP"; then
+       if test "$MERGED" -nt "$BACKUP"
+       then
                status=0
        else
-               while true; do
+               while true
+               do
                        echo "$MERGED seems unchanged."
                        printf "Was the merge successful? [y/n] "
-                       read answer
+                       read answer || return 1
                        case "$answer" in
                        y*|Y*) status=0; break ;;
                        n*|N*) status=1; break ;;
@@ -47,44 +30,65 @@ check_unchanged () {
        fi
 }
 
+valid_tool_config () {
+       if test -n "$(get_merge_tool_cmd "$1")"
+       then
+               return 0
+       else
+               return 1
+       fi
+}
+
 valid_tool () {
+       setup_tool "$1" || valid_tool_config "$1"
+}
+
+setup_tool () {
        case "$1" in
-       araxis | bc3 | diffuse | ecmerge | emerge | gvimdiff | gvimdiff2 | \
-       kdiff3 | meld | opendiff | p4merge | tkdiff | vimdiff | vimdiff2 | xxdiff)
-               ;; # happy
-       kompare)
-               if ! diff_mode; then
-                       return 1
-               fi
-               ;;
-       tortoisemerge)
-               if ! merge_mode; then
-                       return 1
-               fi
+       vim*|gvim*)
+               tool=vim
                ;;
        *)
-               if test -z "$(get_merge_tool_cmd "$1")"; then
-                       return 1
-               fi
+               tool="$1"
                ;;
        esac
+       mergetools="$(git --exec-path)/mergetools"
+
+       # Load the default definitions
+       . "$mergetools/defaults"
+       if ! test -f "$mergetools/$tool"
+       then
+               return 1
+       fi
+
+       # Load the redefined functions
+       . "$mergetools/$tool"
+
+       if merge_mode && ! can_merge
+       then
+               echo "error: '$tool' can not be used to resolve merges" >&2
+               exit 1
+       elif diff_mode && ! can_diff
+       then
+               echo "error: '$tool' can only be used to resolve merges" >&2
+               exit 1
+       fi
+       return 0
 }
 
 get_merge_tool_cmd () {
        # Prints the custom command for a merge tool
-       if test -n "$1"; then
-               merge_tool="$1"
-       else
-               merge_tool="$(get_merge_tool)"
-       fi
-       if diff_mode; then
+       merge_tool="$1"
+       if diff_mode
+       then
                echo "$(git config difftool.$merge_tool.cmd ||
-                       git config mergetool.$merge_tool.cmd)"
+                       git config mergetool.$merge_tool.cmd)"
        else
                echo "$(git config mergetool.$merge_tool.cmd)"
        fi
 }
 
+# Entry point for running tools
 run_merge_tool () {
        # If GIT_PREFIX is empty then we cannot use it in tools
        # that expect to be able to chdir() to its value.
@@ -95,271 +99,29 @@ run_merge_tool () {
        base_present="$2"
        status=0
 
-       case "$1" in
-       araxis)
-               if merge_mode; then
-                       touch "$BACKUP"
-                       if $base_present; then
-                               "$merge_tool_path" -wait -merge -3 -a1 \
-                                       "$BASE" "$LOCAL" "$REMOTE" "$MERGED" \
-                                       >/dev/null 2>&1
-                       else
-                               "$merge_tool_path" -wait -2 \
-                                       "$LOCAL" "$REMOTE" "$MERGED" \
-                                       >/dev/null 2>&1
-                       fi
-                       check_unchanged
-               else
-                       "$merge_tool_path" -wait -2 "$LOCAL" "$REMOTE" \
-                               >/dev/null 2>&1
-               fi
-               ;;
-       bc3)
-               if merge_mode; then
-                       touch "$BACKUP"
-                       if $base_present; then
-                               "$merge_tool_path" "$LOCAL" "$REMOTE" "$BASE" \
-                                       -mergeoutput="$MERGED"
-                       else
-                               "$merge_tool_path" "$LOCAL" "$REMOTE" \
-                                       -mergeoutput="$MERGED"
-                       fi
-                       check_unchanged
-               else
-                       "$merge_tool_path" "$LOCAL" "$REMOTE"
-               fi
-               ;;
-       diffuse)
-               if merge_mode; then
-                       touch "$BACKUP"
-                       if $base_present; then
-                               "$merge_tool_path" \
-                                       "$LOCAL" "$MERGED" "$REMOTE" \
-                                       "$BASE" | cat
-                       else
-                               "$merge_tool_path" \
-                                       "$LOCAL" "$MERGED" "$REMOTE" | cat
-                       fi
-                       check_unchanged
-               else
-                       "$merge_tool_path" "$LOCAL" "$REMOTE" | cat
-               fi
-               ;;
-       ecmerge)
-               if merge_mode; then
-                       touch "$BACKUP"
-                       if $base_present; then
-                               "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" \
-                                       --default --mode=merge3 --to="$MERGED"
-                       else
-                               "$merge_tool_path" "$LOCAL" "$REMOTE" \
-                                       --default --mode=merge2 --to="$MERGED"
-                       fi
-                       check_unchanged
-               else
-                       "$merge_tool_path" --default --mode=diff2 \
-                               "$LOCAL" "$REMOTE"
-               fi
-               ;;
-       emerge)
-               if merge_mode; then
-                       if $base_present; then
-                               "$merge_tool_path" \
-                                       -f emerge-files-with-ancestor-command \
-                                       "$LOCAL" "$REMOTE" "$BASE" \
-                                       "$(basename "$MERGED")"
-                       else
-                               "$merge_tool_path" \
-                                       -f emerge-files-command \
-                                       "$LOCAL" "$REMOTE" \
-                                       "$(basename "$MERGED")"
-                       fi
-                       status=$?
-               else
-                       "$merge_tool_path" -f emerge-files-command \
-                               "$LOCAL" "$REMOTE"
-               fi
-               ;;
-       gvimdiff|vimdiff)
-               if merge_mode; then
-                       touch "$BACKUP"
-                       if $base_present; then
-                               "$merge_tool_path" -f -d -c "wincmd J" \
-                                       "$MERGED" "$LOCAL" "$BASE" "$REMOTE"
-                       else
-                               "$merge_tool_path" -f -d -c "wincmd l" \
-                                       "$LOCAL" "$MERGED" "$REMOTE"
-                       fi
-                       check_unchanged
-               else
-                       "$merge_tool_path" -R -f -d -c "wincmd l" \
-                               -c 'cd $GIT_PREFIX' \
-                               "$LOCAL" "$REMOTE"
-               fi
-               ;;
-       gvimdiff2|vimdiff2)
-               if merge_mode; then
-                       touch "$BACKUP"
-                       "$merge_tool_path" -f -d -c "wincmd l" \
-                               "$LOCAL" "$MERGED" "$REMOTE"
-                       check_unchanged
-               else
-                       "$merge_tool_path" -R -f -d -c "wincmd l" \
-                               -c 'cd $GIT_PREFIX' \
-                               "$LOCAL" "$REMOTE"
-               fi
-               ;;
-       kdiff3)
-               if merge_mode; then
-                       if $base_present; then
-                               ("$merge_tool_path" --auto \
-                                       --L1 "$MERGED (Base)" \
-                                       --L2 "$MERGED (Local)" \
-                                       --L3 "$MERGED (Remote)" \
-                                       -o "$MERGED" \
-                                       "$BASE" "$LOCAL" "$REMOTE" \
-                               > /dev/null 2>&1)
-                       else
-                               ("$merge_tool_path" --auto \
-                                       --L1 "$MERGED (Local)" \
-                                       --L2 "$MERGED (Remote)" \
-                                       -o "$MERGED" \
-                                       "$LOCAL" "$REMOTE" \
-                               > /dev/null 2>&1)
-                       fi
-                       status=$?
-               else
-                       ("$merge_tool_path" --auto \
-                               --L1 "$MERGED (A)" \
-                               --L2 "$MERGED (B)" "$LOCAL" "$REMOTE" \
-                       > /dev/null 2>&1)
-               fi
-               ;;
-       kompare)
-               "$merge_tool_path" "$LOCAL" "$REMOTE"
-               ;;
-       meld)
-               if merge_mode; then
-                       touch "$BACKUP"
-                       "$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE"
-                       check_unchanged
-               else
-                       "$merge_tool_path" "$LOCAL" "$REMOTE"
-               fi
-               ;;
-       opendiff)
-               if merge_mode; then
-                       touch "$BACKUP"
-                       if $base_present; then
-                               "$merge_tool_path" "$LOCAL" "$REMOTE" \
-                                       -ancestor "$BASE" \
-                                       -merge "$MERGED" | cat
-                       else
-                               "$merge_tool_path" "$LOCAL" "$REMOTE" \
-                                       -merge "$MERGED" | cat
-                       fi
-                       check_unchanged
-               else
-                       "$merge_tool_path" "$LOCAL" "$REMOTE" | cat
-               fi
-               ;;
-       p4merge)
-               if merge_mode; then
-                       touch "$BACKUP"
-                       $base_present || >"$BASE"
-                       "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
-                       check_unchanged
-               else
-                       "$merge_tool_path" "$LOCAL" "$REMOTE"
-               fi
-               ;;
-       tkdiff)
-               if merge_mode; then
-                       if $base_present; then
-                               "$merge_tool_path" -a "$BASE" \
-                                       -o "$MERGED" "$LOCAL" "$REMOTE"
-                       else
-                               "$merge_tool_path" \
-                                       -o "$MERGED" "$LOCAL" "$REMOTE"
-                       fi
-                       status=$?
-               else
-                       "$merge_tool_path" "$LOCAL" "$REMOTE"
-               fi
-               ;;
-       tortoisemerge)
-               if $base_present; then
-                       touch "$BACKUP"
-                       "$merge_tool_path" \
-                               -base:"$BASE" -mine:"$LOCAL" \
-                               -theirs:"$REMOTE" -merged:"$MERGED"
-                       check_unchanged
-               else
-                       echo "TortoiseMerge cannot be used without a base" 1>&2
-                       status=1
-               fi
-               ;;
-       xxdiff)
-               if merge_mode; then
-                       touch "$BACKUP"
-                       if $base_present; then
-                               "$merge_tool_path" -X --show-merged-pane \
-                                       -R 'Accel.SaveAsMerged: "Ctrl-S"' \
-                                       -R 'Accel.Search: "Ctrl+F"' \
-                                       -R 'Accel.SearchForward: "Ctrl-G"' \
-                                       --merged-file "$MERGED" \
-                                       "$LOCAL" "$BASE" "$REMOTE"
-                       else
-                               "$merge_tool_path" -X $extra \
-                                       -R 'Accel.SaveAsMerged: "Ctrl-S"' \
-                                       -R 'Accel.Search: "Ctrl+F"' \
-                                       -R 'Accel.SearchForward: "Ctrl-G"' \
-                                       --merged-file "$MERGED" \
-                                       "$LOCAL" "$REMOTE"
-                       fi
-                       check_unchanged
-               else
-                       "$merge_tool_path" \
-                               -R 'Accel.Search: "Ctrl+F"' \
-                               -R 'Accel.SearchForward: "Ctrl-G"' \
-                               "$LOCAL" "$REMOTE"
-               fi
-               ;;
-       *)
-               merge_tool_cmd="$(get_merge_tool_cmd "$1")"
-               if test -z "$merge_tool_cmd"; then
-                       if merge_mode; then
-                               status=1
-                       fi
-                       break
-               fi
-               if merge_mode; then
-                       trust_exit_code="$(git config --bool \
-                               mergetool."$1".trustExitCode || echo false)"
-                       if test "$trust_exit_code" = "false"; then
-                               touch "$BACKUP"
-                               ( eval $merge_tool_cmd )
-                               check_unchanged
-                       else
-                               ( eval $merge_tool_cmd )
-                               status=$?
-                       fi
-               else
-                       ( eval $merge_tool_cmd )
-               fi
-               ;;
-       esac
+       # Bring tool-specific functions into scope
+       setup_tool "$1"
+
+       if merge_mode
+       then
+               merge_cmd "$1"
+       else
+               diff_cmd "$1"
+       fi
        return $status
 }
 
 guess_merge_tool () {
-       if merge_mode; then
+       if merge_mode
+       then
                tools="tortoisemerge"
        else
                tools="kompare"
        fi
-       if test -n "$DISPLAY"; then
-               if test -n "$GNOME_DESKTOP_SESSION_ID" ; then
+       if test -n "$DISPLAY"
+       then
+               if test -n "$GNOME_DESKTOP_SESSION_ID"
+               then
                        tools="meld opendiff kdiff3 tkdiff xxdiff $tools"
                else
                        tools="opendiff kdiff3 tkdiff xxdiff meld $tools"
@@ -380,7 +142,8 @@ guess_merge_tool () {
        for i in $tools
        do
                merge_tool_path="$(translate_merge_tool_path "$i")"
-               if type "$merge_tool_path" > /dev/null 2>&1; then
+               if type "$merge_tool_path" >/dev/null 2>&1
+               then
                        echo "$i"
                        return 0
                fi
@@ -393,12 +156,14 @@ guess_merge_tool () {
 get_configured_merge_tool () {
        # Diff mode first tries diff.tool and falls back to merge.tool.
        # Merge mode only checks merge.tool
-       if diff_mode; then
+       if diff_mode
+       then
                merge_tool=$(git config diff.tool || git config merge.tool)
        else
                merge_tool=$(git config merge.tool)
        fi
-       if test -n "$merge_tool" && ! valid_tool "$merge_tool"; then
+       if test -n "$merge_tool" && ! valid_tool "$merge_tool"
+       then
                echo >&2 "git config option $TOOL_MODE.tool set to unknown tool: $merge_tool"
                echo >&2 "Resetting to default..."
                return 1
@@ -408,28 +173,28 @@ get_configured_merge_tool () {
 
 get_merge_tool_path () {
        # A merge tool has been set, so verify that it's valid.
-       if test -n "$1"; then
-               merge_tool="$1"
-       else
-               merge_tool="$(get_merge_tool)"
-       fi
-       if ! valid_tool "$merge_tool"; then
+       merge_tool="$1"
+       if ! valid_tool "$merge_tool"
+       then
                echo >&2 "Unknown merge tool $merge_tool"
                exit 1
        fi
-       if diff_mode; then
+       if diff_mode
+       then
                merge_tool_path=$(git config difftool."$merge_tool".path ||
-                                 git config mergetool."$merge_tool".path)
+                                 git config mergetool."$merge_tool".path)
        else
                merge_tool_path=$(git config mergetool."$merge_tool".path)
        fi
-       if test -z "$merge_tool_path"; then
+       if test -z "$merge_tool_path"
+       then
                merge_tool_path="$(translate_merge_tool_path "$merge_tool")"
        fi
        if test -z "$(get_merge_tool_cmd "$merge_tool")" &&
-       ! type "$merge_tool_path" > /dev/null 2>&1; then
+               ! type "$merge_tool_path" >/dev/null 2>&1
+       then
                echo >&2 "The $TOOL_MODE tool $merge_tool is not available as"\
-                        "'$merge_tool_path'"
+                        "'$merge_tool_path'"
                exit 1
        fi
        echo "$merge_tool_path"
@@ -437,9 +202,10 @@ get_merge_tool_path () {
 
 get_merge_tool () {
        # Check if a merge tool has been configured
-       merge_tool=$(get_configured_merge_tool)
+       merge_tool="$(get_configured_merge_tool)"
        # Try to guess an appropriate merge tool if no tool has been set.
-       if test -z "$merge_tool"; then
+       if test -z "$merge_tool"
+       then
                merge_tool="$(guess_merge_tool)" || exit
        fi
        echo "$merge_tool"
index 3c157bcd26232c758572bf908add44216cb8e2e7..085e213a126e5864befc8e3436832ae3c587a624 100755 (executable)
@@ -72,7 +72,7 @@ describe_file () {
 resolve_symlink_merge () {
     while true; do
        printf "Use (l)ocal or (r)emote, or (a)bort? "
-       read ans
+       read ans || return 1
        case "$ans" in
            [lL]*)
                git checkout-index -f --stage=2 -- "$MERGED"
@@ -342,64 +342,42 @@ merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo fa
 
 last_status=0
 rollup_status=0
-rerere=false
-
-files_to_merge() {
-    if test "$rerere" = true
-    then
-       git rerere remaining
-    else
-       git ls-files -u | sed -e 's/^[^ ]*      //' | sort -u
-    fi
-}
-
+files=
 
 if test $# -eq 0 ; then
     cd_to_toplevel
 
     if test -e "$GIT_DIR/MERGE_RR"
     then
-       rerere=true
-    fi
-
-    files=$(files_to_merge)
-    if test -z "$files" ; then
-       echo "No files need merging"
-       exit 0
+       files=$(git rerere remaining)
+    else
+       files=$(git ls-files -u | sed -e 's/^[^ ]*      //' | sort -u)
     fi
+else
+    files=$(git ls-files -u -- "$@" | sed -e 's/^[^    ]*      //' | sort -u)
+fi
 
-    # Save original stdin
-    exec 3<&0
+if test -z "$files" ; then
+    echo "No files need merging"
+    exit 0
+fi
 
-    printf "Merging:\n"
-    printf "$files\n"
+printf "Merging:\n"
+printf "$files\n"
 
-    files_to_merge |
-    while IFS= read i
-    do
-       if test $last_status -ne 0; then
-           prompt_after_failed_merge <&3 || exit 1
-       fi
-       printf "\n"
-       merge_file "$i" <&3
-       last_status=$?
-       if test $last_status -ne 0; then
-           rollup_status=1
-       fi
-    done
-else
-    while test $# -gt 0; do
-       if test $last_status -ne 0; then
-           prompt_after_failed_merge || exit 1
-       fi
-       printf "\n"
-       merge_file "$1"
-       last_status=$?
-       if test $last_status -ne 0; then
-           rollup_status=1
-       fi
-       shift
-    done
-fi
+IFS='
+'
+for i in $files
+do
+    if test $last_status -ne 0; then
+       prompt_after_failed_merge || exit 1
+    fi
+    printf "\n"
+    merge_file "$i"
+    last_status=$?
+    if test $last_status -ne 0; then
+       rollup_status=1
+    fi
+done
 
 exit $rollup_status
index a10b1290bc9218942fcec54b9e930f072ca11bce..63da37bcc2730358140ae4b862040ed8fb0ed77e 100755 (executable)
@@ -10,7 +10,7 @@ SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
 . git-sh-setup
 . git-sh-i18n
-set_reflog_action "pull $*"
+set_reflog_action "pull${1+ $*}"
 require_work_tree
 cd_to_toplevel
 
@@ -217,12 +217,9 @@ then
        # $orig_head commit, but we are merging into $curr_head.
        # First update the working tree to match $curr_head.
 
-       (
-               eval_gettext "Warning: fetch updated the current branch head.
+       eval_gettextln "Warning: fetch updated the current branch head.
 Warning: fast-forwarding your working tree from
-Warning: commit \$orig_head." &&
-               echo
-       ) >&2
+Warning: commit \$orig_head." >&2
        git update-index -q --refresh
        git read-tree -u -m "$orig_head" "$curr_head" ||
                die "$(eval_gettext "Cannot fast-forward your working tree.
index c6ba7c15510935353bd17b2b8d8188fe16052907..94f36c254c53366ba53d256c0bd50a1de07cdb85 100644 (file)
@@ -472,18 +472,24 @@ do_next () {
                git rev-parse --verify HEAD > "$state_dir"/stopped-sha
                ${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
                status=$?
+               # Run in subshell because require_clean_work_tree can die.
+               dirty=f
+               (require_clean_work_tree "rebase" 2>/dev/null) || dirty=t
                if test "$status" -ne 0
                then
                        warn "Execution failed: $rest"
+                       test "$dirty" = f ||
+                       warn "and made changes to the index and/or the working tree"
+
                        warn "You can fix the problem, and then run"
                        warn
                        warn "  git rebase --continue"
                        warn
                        exit "$status"
-               fi
-               # Run in subshell because require_clean_work_tree can die.
-               if ! (require_clean_work_tree "rebase")
+               elif test "$dirty" = t
                then
+                       warn "Execution succeeded: $rest"
+                       warn "but left changes to the index and/or the working tree"
                        warn "Commit or stash your changes, and then run"
                        warn
                        warn "  git rebase --continue"
@@ -647,8 +653,24 @@ continue)
        then
                : Nothing to commit -- skip this
        else
+               if ! test -f "$author_script"
+               then
+                       die "You have staged changes in your working tree. If these changes are meant to be
+squashed into the previous commit, run:
+
+  git commit --amend
+
+If they are meant to go into a new commit, run:
+
+  git commit
+
+In both case, once you're done, continue with:
+
+  git rebase --continue
+"
+               fi
                . "$author_script" ||
-                       die "Cannot find the author identity"
+                       die "Error trying to find the author identity to amend commit"
                current_head=
                if test -f "$amend"
                then
index 266a4c13bb3607ad635df19bf6dd80f205effae2..6759702c573f51ac00bf1b5c8abccf252cb4ff1d 100755 (executable)
@@ -22,7 +22,7 @@ currently checked out branch is used.
 
 Example:       git-rebase master~1 topic
 
-        A---B---C topic                   A'\''--B'\''--C'\'' topic
+       A---B---C topic                   A'\''--B'\''--C'\'' topic
        /                   -->           /
   D---E---F---G master          D---E---F---G master
 '
index df9d512f1a966635828cb7a8dadde3b0c2b7b9d8..3dc4851cfc70a2804b23a8eca4dac7702ae93c87 100644 (file)
@@ -1,5 +1,18 @@
 #!/usr/bin/env python
 
+# This command is a simple remote-helper, that is used both as a
+# testcase for the remote-helper functionality, and as an example to
+# show remote-helper authors one possible implementation.
+#
+# This is a Git <-> Git importer/exporter, that simply uses git
+# fast-import and git fast-export to consume and produce fast-import
+# streams.
+#
+# To understand better the way things work, one can activate debug
+# traces by setting (to any value) the environment variables
+# GIT_TRANSPORT_HELPER_DEBUG and GIT_DEBUG_TESTGIT, to see messages
+# from the transport-helper side, or from this example remote-helper.
+
 # hashlib is only available in python >= 2.5
 try:
     import hashlib
@@ -35,7 +48,7 @@ def get_repo(alias, url):
     prefix = 'refs/testgit/%s/' % alias
     debug("prefix: '%s'", prefix)
 
-    repo.gitdir = ""
+    repo.gitdir = os.environ["GIT_DIR"]
     repo.alias = alias
     repo.prefix = prefix
 
@@ -70,9 +83,19 @@ def do_capabilities(repo, args):
 
     print "import"
     print "export"
-    print "gitdir"
     print "refspec refs/heads/*:%s*" % repo.prefix
 
+    dirname = repo.get_base_path(repo.gitdir)
+
+    if not os.path.exists(dirname):
+        os.makedirs(dirname)
+
+    path = os.path.join(dirname, 'testgit.marks')
+
+    print "*export-marks %s" % path
+    if os.path.exists(path):
+        print "*import-marks %s" % path
+
     print # end capabilities
 
 
@@ -121,8 +144,24 @@ def do_import(repo, args):
     if not repo.gitdir:
         die("Need gitdir to import")
 
+    ref = args[0]
+    refs = [ref]
+
+    while True:
+        line = sys.stdin.readline()
+        if line == '\n':
+            break
+        if not line.startswith('import '):
+            die("Expected import line.")
+
+        # strip of leading 'import '
+        ref = line[7:].strip()
+        refs.append(ref)
+
     repo = update_local_repo(repo)
-    repo.exporter.export_repo(repo.gitdir)
+    repo.exporter.export_repo(repo.gitdir, refs)
+
+    print "done"
 
 
 def do_export(repo, args):
@@ -132,32 +171,15 @@ def do_export(repo, args):
     if not repo.gitdir:
         die("Need gitdir to export")
 
-    dirname = repo.get_base_path(repo.gitdir)
-
-    if not os.path.exists(dirname):
-        os.makedirs(dirname)
-
-    path = os.path.join(dirname, 'testgit.marks')
-    print path
-    if os.path.exists(path):
-        print path
-    else:
-        print ""
-    sys.stdout.flush()
-
     update_local_repo(repo)
-    repo.importer.do_import(repo.gitdir)
-    repo.non_local.push(repo.gitdir)
-
-
-def do_gitdir(repo, args):
-    """Stores the location of the gitdir.
-    """
+    changed = repo.importer.do_import(repo.gitdir)
 
-    if not args:
-        die("gitdir needs an argument")
+    if not repo.local:
+        repo.non_local.push(repo.gitdir)
 
-    repo.gitdir = ' '.join(args)
+    for ref in changed:
+        print "ok %s" % ref
+    print
 
 
 COMMANDS = {
@@ -165,7 +187,6 @@ COMMANDS = {
     'list': do_list,
     'import': do_import,
     'export': do_export,
-    'gitdir': do_gitdir,
 }
 
 
index 32ca59de82b6a26879128650bf40882f4ed16aa0..e672366f0c3db3b547233af146cd1bba275c0042 100644 (file)
@@ -11,19 +11,38 @@ then
                printf "%s" "$1"
        }
 
+       gettextln() {
+               printf "%s\n" "$1"
+       }
+
        eval_gettext () {
                printf "%s" "$1" | (
                        export PATH $(git sh-i18n--envsubst --variables "$1");
                        git sh-i18n--envsubst "$1"
                )
        }
+
+       eval_gettextln () {
+               printf "%s\n" "$1" | (
+                       export PATH $(git sh-i18n--envsubst --variables "$1");
+                       git sh-i18n--envsubst "$1"
+               )
+       }
 else
        gettext () {
                printf "%s" "# GETTEXT POISON #"
        }
 
+       gettextln () {
+               printf "%s\n" "# GETTEXT POISON #"
+       }
+
        eval_gettext () {
                printf "%s" "# GETTEXT POISON #"
        }
+
+       eval_gettextln () {
+               printf "%s\n" "# GETTEXT POISON #"
+       }
 fi
 
index f4e6f05ee212f452a1b3e13c492960a9222029f7..31dec0abf13ee7d6ded313b24253cd12254f1685 100755 (executable)
@@ -198,8 +198,8 @@ save_stash () {
                        #    $ git stash save --blah-blah 2>&1 | head -n 2
                        #    error: unknown option for 'stash save': --blah-blah
                        #           To provide a message, use git stash save -- '--blah-blah'
-                       eval_gettext "$("error: unknown option for 'stash save': \$option
-       To provide a message, use git stash save -- '\$option'")"; echo
+                       eval_gettextln "$("error: unknown option for 'stash save': \$option
+       To provide a message, use git stash save -- '\$option'")"
                        usage
                        ;;
                *)
@@ -470,10 +470,7 @@ apply_stash () {
                status=$?
                if test -n "$INDEX_OPTION"
                then
-                       (
-                               gettext "Index was not unstashed." &&
-                               echo
-                       ) >&2
+                       gettextln "Index was not unstashed." >&2
                fi
                exit $status
        fi
index bc1d3fa663a5eb39dd96f6ad2ca17437073ceb0a..814d0d914eaf994462e61559b0692c958f97513b 100755 (executable)
@@ -122,12 +122,17 @@ module_clone()
        path=$1
        url=$2
        reference="$3"
+       quiet=
+       if test -n "$GIT_QUIET"
+       then
+               quiet=-q
+       fi
 
        if test -n "$reference"
        then
-               git-clone "$reference" -n "$url" "$path"
+               git-clone $quiet "$reference" -n "$url" "$path"
        else
-               git-clone -n "$url" "$path"
+               git-clone $quiet -n "$url" "$path"
        fi ||
        die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")"
 }
@@ -223,12 +228,9 @@ cmd_add()
 
        if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
        then
-               (
-                       eval_gettext "The following path is ignored by one of your .gitignore files:
+               eval_gettextln "The following path is ignored by one of your .gitignore files:
 \$path
-Use -f if you really want to add it." &&
-                       echo
-               ) >&2
+Use -f if you really want to add it." >&2
                exit 1
        fi
 
@@ -237,7 +239,7 @@ Use -f if you really want to add it." &&
        then
                if test -d "$path"/.git -o -f "$path"/.git
                then
-                       eval_gettext "Adding existing repo at '\$path' to the index"; echo
+                       eval_gettextln "Adding existing repo at '\$path' to the index"
                else
                        die "$(eval_gettext "'\$path' already exists and is not a valid git repo")"
                fi
@@ -696,10 +698,7 @@ cmd_summary() {
                                ;; # removed
                        *)
                                # unexpected type
-                               (
-                                       eval_gettext "unexpected mode \$mod_dst" &&
-                                       echo
-                               ) >&2
+                               eval_gettextln "unexpected mode \$mod_dst" >&2
                                continue ;;
                        esac
                fi
@@ -786,9 +785,9 @@ cmd_summary() {
        done |
        if test -n "$for_status"; then
                if [ -n "$files" ]; then
-                       gettext "# Submodules changed but not updated:"; echo
+                       gettextln "# Submodules changed but not updated:"
                else
-                       gettext "# Submodule changes to be committed:"; echo
+                       gettextln "# Submodule changes to be committed:"
                fi
                echo "#"
                sed -e 's|^|# |' -e 's|^# $|#|'
index 89f83fd27abe315804173a809b3c7ef00ead6527..351e743a902568c8b6f68ffaf4030f087ba8568d 100755 (executable)
@@ -89,6 +89,7 @@ my ($_stdin, $_help, $_edit,
        $_prefix, $_no_checkout, $_url, $_verbose,
        $_git_format, $_commit_url, $_tag, $_merge_info);
 $Git::SVN::_follow_parent = 1;
+$SVN::Git::Fetcher::_placeholder_filename = ".gitignore";
 $_q ||= 0;
 my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
                     'config-dir=s' => \$Git::SVN::Ra::config_dir,
@@ -139,6 +140,10 @@ my %cmd = (
                           %fc_opts } ],
        clone => [ \&cmd_clone, "Initialize and fetch revisions",
                        { 'revision|r=s' => \$_revision,
+                         'preserve-empty-dirs' =>
+                               \$SVN::Git::Fetcher::_preserve_empty_dirs,
+                         'placeholder-filename=s' =>
+                               \$SVN::Git::Fetcher::_placeholder_filename,
                           %fc_opts, %init_opts } ],
        init => [ \&cmd_init, "Initialize a repo for tracking" .
                          " (requires URL argument)",
@@ -386,6 +391,12 @@ sub do_git_init_db {
        my $ignore_regex = \$SVN::Git::Fetcher::_ignore_regex;
        command_noisy('config', "$pfx.ignore-paths", $$ignore_regex)
                if defined $$ignore_regex;
+
+       if (defined $SVN::Git::Fetcher::_preserve_empty_dirs) {
+               my $fname = \$SVN::Git::Fetcher::_placeholder_filename;
+               command_noisy('config', "$pfx.preserve-empty-dirs", 'true');
+               command_noisy('config', "$pfx.placeholder-filename", $$fname);
+       }
 }
 
 sub init_subdir {
@@ -497,6 +508,195 @@ sub cmd_set_tree {
        unlink $gs->{index};
 }
 
+sub split_merge_info_range {
+       my ($range) = @_;
+       if ($range =~ /(\d+)-(\d+)/) {
+               return (int($1), int($2));
+       } else {
+               return (int($range), int($range));
+       }
+}
+
+sub combine_ranges {
+       my ($in) = @_;
+
+       my @fnums = ();
+       my @arr = split(/,/, $in);
+       for my $element (@arr) {
+               my ($start, $end) = split_merge_info_range($element);
+               push @fnums, $start;
+       }
+
+       my @sorted = @arr [ sort {
+               $fnums[$a] <=> $fnums[$b]
+       } 0..$#arr ];
+
+       my @return = ();
+       my $last = -1;
+       my $first = -1;
+       for my $element (@sorted) {
+               my ($start, $end) = split_merge_info_range($element);
+
+               if ($last == -1) {
+                       $first = $start;
+                       $last = $end;
+                       next;
+               }
+               if ($start <= $last+1) {
+                       if ($end > $last) {
+                               $last = $end;
+                       }
+                       next;
+               }
+               if ($first == $last) {
+                       push @return, "$first";
+               } else {
+                       push @return, "$first-$last";
+               }
+               $first = $start;
+               $last = $end;
+       }
+
+       if ($first != -1) {
+               if ($first == $last) {
+                       push @return, "$first";
+               } else {
+                       push @return, "$first-$last";
+               }
+       }
+
+       return join(',', @return);
+}
+
+sub merge_revs_into_hash {
+       my ($hash, $minfo) = @_;
+       my @lines = split(' ', $minfo);
+
+       for my $line (@lines) {
+               my ($branchpath, $revs) = split(/:/, $line);
+
+               if (exists($hash->{$branchpath})) {
+                       # Merge the two revision sets
+                       my $combined = "$hash->{$branchpath},$revs";
+                       $hash->{$branchpath} = combine_ranges($combined);
+               } else {
+                       # Just do range combining for consolidation
+                       $hash->{$branchpath} = combine_ranges($revs);
+               }
+       }
+}
+
+sub merge_merge_info {
+       my ($mergeinfo_one, $mergeinfo_two) = @_;
+       my %result_hash = ();
+
+       merge_revs_into_hash(\%result_hash, $mergeinfo_one);
+       merge_revs_into_hash(\%result_hash, $mergeinfo_two);
+
+       my $result = '';
+       # Sort below is for consistency's sake
+       for my $branchname (sort keys(%result_hash)) {
+               my $revlist = $result_hash{$branchname};
+               $result .= "$branchname:$revlist\n"
+       }
+       return $result;
+}
+
+sub populate_merge_info {
+       my ($d, $gs, $uuid, $linear_refs, $rewritten_parent) = @_;
+
+       my %parentshash;
+       read_commit_parents(\%parentshash, $d);
+       my @parents = @{$parentshash{$d}};
+       if ($#parents > 0) {
+               # Merge commit
+               my $all_parents_ok = 1;
+               my $aggregate_mergeinfo = '';
+               my $rooturl = $gs->repos_root;
+
+               if (defined($rewritten_parent)) {
+                       # Replace first parent with newly-rewritten version
+                       shift @parents;
+                       unshift @parents, $rewritten_parent;
+               }
+
+               foreach my $parent (@parents) {
+                       my ($branchurl, $svnrev, $paruuid) =
+                               cmt_metadata($parent);
+
+                       unless (defined($svnrev)) {
+                               # Should have been caught be preflight check
+                               fatal "merge commit $d has ancestor $parent, but that change "
+                     ."does not have git-svn metadata!";
+                       }
+                       unless ($branchurl =~ /^$rooturl(.*)/) {
+                               fatal "commit $parent git-svn metadata changed mid-run!";
+                       }
+                       my $branchpath = $1;
+
+                       my $ra = Git::SVN::Ra->new($branchurl);
+                       my (undef, undef, $props) =
+                               $ra->get_dir(canonicalize_path("."), $svnrev);
+                       my $par_mergeinfo = $props->{'svn:mergeinfo'};
+                       unless (defined $par_mergeinfo) {
+                               $par_mergeinfo = '';
+                       }
+                       # Merge previous mergeinfo values
+                       $aggregate_mergeinfo =
+                               merge_merge_info($aggregate_mergeinfo,
+                                                                $par_mergeinfo, 0);
+
+                       next if $parent eq $parents[0]; # Skip first parent
+                       # Add new changes being placed in tree by merge
+                       my @cmd = (qw/rev-list --reverse/,
+                                          $parent, qw/--not/);
+                       foreach my $par (@parents) {
+                               unless ($par eq $parent) {
+                                       push @cmd, $par;
+                               }
+                       }
+                       my @revsin = ();
+                       my ($revlist, $ctx) = command_output_pipe(@cmd);
+                       while (<$revlist>) {
+                               my $irev = $_;
+                               chomp $irev;
+                               my (undef, $csvnrev, undef) =
+                                       cmt_metadata($irev);
+                               unless (defined $csvnrev) {
+                                       # A child is missing SVN annotations...
+                                       # this might be OK, or might not be.
+                                       warn "W:child $irev is merged into revision "
+                                                ."$d but does not have git-svn metadata. "
+                                                ."This means git-svn cannot determine the "
+                                                ."svn revision numbers to place into the "
+                                                ."svn:mergeinfo property. You must ensure "
+                                                ."a branch is entirely committed to "
+                                                ."SVN before merging it in order for "
+                                                ."svn:mergeinfo population to function "
+                                                ."properly";
+                               }
+                               push @revsin, $csvnrev;
+                       }
+                       command_close_pipe($revlist, $ctx);
+
+                       last unless $all_parents_ok;
+
+                       # We now have a list of all SVN revnos which are
+                       # merged by this particular parent. Integrate them.
+                       next if $#revsin == -1;
+                       my $newmergeinfo = "$branchpath:" . join(',', @revsin);
+                       $aggregate_mergeinfo =
+                               merge_merge_info($aggregate_mergeinfo,
+                                                                $newmergeinfo, 1);
+               }
+               if ($all_parents_ok and $aggregate_mergeinfo) {
+                       return $aggregate_mergeinfo;
+               }
+       }
+
+       return undef;
+}
+
 sub cmd_dcommit {
        my $head = shift;
        command_noisy(qw/update-index --refresh/);
@@ -547,7 +747,66 @@ sub cmd_dcommit {
                     "without --no-rebase may be required."
        }
        my $expect_url = $url;
+
+       my $push_merge_info = eval {
+               command_oneline(qw/config --get svn.pushmergeinfo/)
+               };
+       if (not defined($push_merge_info)
+                       or $push_merge_info eq "false"
+                       or $push_merge_info eq "no"
+                       or $push_merge_info eq "never") {
+               $push_merge_info = 0;
+       }
+
+       unless (defined($_merge_info) || ! $push_merge_info) {
+               # Preflight check of changes to ensure no issues with mergeinfo
+               # This includes check for uncommitted-to-SVN parents
+               # (other than the first parent, which we will handle),
+               # information from different SVN repos, and paths
+               # which are not underneath this repository root.
+               my $rooturl = $gs->repos_root;
+               foreach my $d (@$linear_refs) {
+                       my %parentshash;
+                       read_commit_parents(\%parentshash, $d);
+                       my @realparents = @{$parentshash{$d}};
+                       if ($#realparents > 0) {
+                               # Merge commit
+                               shift @realparents; # Remove/ignore first parent
+                               foreach my $parent (@realparents) {
+                                       my ($branchurl, $svnrev, $paruuid) = cmt_metadata($parent);
+                                       unless (defined $paruuid) {
+                                               # A parent is missing SVN annotations...
+                                               # abort the whole operation.
+                                               fatal "$parent is merged into revision $d, "
+                                                        ."but does not have git-svn metadata. "
+                                                        ."Either dcommit the branch or use a "
+                                                        ."local cherry-pick, FF merge, or rebase "
+                                                        ."instead of an explicit merge commit.";
+                                       }
+
+                                       unless ($paruuid eq $uuid) {
+                                               # Parent has SVN metadata from different repository
+                                               fatal "merge parent $parent for change $d has "
+                                                        ."git-svn uuid $paruuid, while current change "
+                                                        ."has uuid $uuid!";
+                                       }
+
+                                       unless ($branchurl =~ /^$rooturl(.*)/) {
+                                               # This branch is very strange indeed.
+                                               fatal "merge parent $parent for $d is on branch "
+                                                        ."$branchurl, which is not under the "
+                                                        ."git-svn root $rooturl!";
+                                       }
+                               }
+                       }
+               }
+       }
+
+       my $rewritten_parent;
        Git::SVN::remove_username($expect_url);
+       if (defined($_merge_info)) {
+               $_merge_info =~ tr{ }{\n};
+       }
        while (1) {
                my $d = shift @$linear_refs or last;
                unless (defined $last_rev) {
@@ -561,6 +820,14 @@ sub cmd_dcommit {
                        print "diff-tree $d~1 $d\n";
                } else {
                        my $cmt_rev;
+
+                       unless (defined($_merge_info) || ! $push_merge_info) {
+                               $_merge_info = populate_merge_info($d, $gs,
+                                                            $uuid,
+                                                            $linear_refs,
+                                                            $rewritten_parent);
+                       }
+
                        my %ed_opts = ( r => $last_rev,
                                        log => get_commit_entry($d)->{log},
                                        ra => Git::SVN::Ra->new($url),
@@ -603,6 +870,9 @@ sub cmd_dcommit {
                                @finish = qw/reset --mixed/;
                        }
                        command_noisy(@finish, $gs->refname);
+
+                       $rewritten_parent = command_oneline(qw/rev-parse HEAD/);
+
                        if (@diff) {
                                @refs = ();
                                my ($url_, $rev_, $uuid_, $gs_) =
@@ -3011,7 +3281,7 @@ sub other_gs {
                        my (undef, $max_commit) = $gs->rev_map_max(1);
                        last if (!$max_commit);
                        my ($url) = ::cmt_metadata($max_commit);
-                       last if ($url eq $gs->full_url);
+                       last if ($url eq $gs->metadata_url);
                        $ref_id .= '-';
                }
                print STDERR "Initializing parent: $ref_id\n" unless $::_q > 1;
@@ -4080,12 +4350,13 @@ sub _read_password {
 }
 
 package SVN::Git::Fetcher;
-use vars qw/@ISA/;
+use vars qw/@ISA $_ignore_regex $_preserve_empty_dirs $_placeholder_filename
+            @deleted_gpath %added_placeholder $repo_id/;
 use strict;
 use warnings;
 use Carp qw/croak/;
+use File::Basename qw/dirname/;
 use IO::File qw//;
-use vars qw/$_ignore_regex/;
 
 # file baton members: path, mode_a, mode_b, pool, fh, blob, base
 sub new {
@@ -4097,8 +4368,34 @@ sub new {
                $self->{empty_symlinks} =
                                  _mark_empty_symlinks($git_svn, $switch_path);
        }
-       $self->{ignore_regex} = eval { command_oneline('config', '--get',
-                            "svn-remote.$git_svn->{repo_id}.ignore-paths") };
+
+       # some options are read globally, but can be overridden locally
+       # per [svn-remote "..."] section.  Command-line options will *NOT*
+       # override options set in an [svn-remote "..."] section
+       $repo_id = $git_svn->{repo_id};
+       my $k = "svn-remote.$repo_id.ignore-paths";
+       my $v = eval { command_oneline('config', '--get', $k) };
+       $self->{ignore_regex} = $v;
+
+       $k = "svn-remote.$repo_id.preserve-empty-dirs";
+       $v = eval { command_oneline('config', '--get', '--bool', $k) };
+       if ($v && $v eq 'true') {
+               $_preserve_empty_dirs = 1;
+               $k = "svn-remote.$repo_id.placeholder-filename";
+               $v = eval { command_oneline('config', '--get', $k) };
+               $_placeholder_filename = $v;
+       }
+
+       # Load the list of placeholder files added during previous invocations.
+       $k = "svn-remote.$repo_id.added-placeholder";
+       $v = eval { command_oneline('config', '--get-all', $k) };
+       if ($_preserve_empty_dirs && $v) {
+               # command() prints errors to stderr, so we only call it if
+               # command_oneline() succeeded.
+               my @v = command('config', '--get-all', $k);
+               $added_placeholder{ dirname($_) } = $_ foreach @v;
+       }
+
        $self->{empty} = {};
        $self->{dir_prop} = {};
        $self->{file_prop} = {};
@@ -4227,6 +4524,8 @@ sub delete_entry {
                $self->{gii}->remove($gpath);
                print "\tD\t$gpath\n" unless $::_q;
        }
+       # Don't add to @deleted_gpath if we're deleting a placeholder file.
+       push @deleted_gpath, $gpath unless $added_placeholder{dirname($path)};
        $self->{empty}->{$path} = 0;
        undef;
 }
@@ -4259,7 +4558,15 @@ sub add_file {
                my ($dir, $file) = ($path =~ m#^(.*?)/?([^/]+)$#);
                delete $self->{empty}->{$dir};
                $mode = '100644';
+
+               if ($added_placeholder{$dir}) {
+                       # Remove our placeholder file, if we created one.
+                       delete_entry($self, $added_placeholder{$dir})
+                               unless $path eq $added_placeholder{$dir};
+                       delete $added_placeholder{$dir}
+               }
        }
+
        { path => $path, mode_a => $mode, mode_b => $mode,
          pool => SVN::Pool->new, action => 'A' };
 }
@@ -4277,6 +4584,7 @@ sub add_directory {
                        chomp;
                        $self->{gii}->remove($_);
                        print "\tD\t$_\n" unless $::_q;
+                       push @deleted_gpath, $gpath;
                }
                command_close_pipe($ls, $ctx);
                $self->{empty}->{$path} = 0;
@@ -4284,6 +4592,13 @@ sub add_directory {
        my ($dir, $file) = ($path =~ m#^(.*?)/?([^/]+)$#);
        delete $self->{empty}->{$dir};
        $self->{empty}->{$path} = 1;
+
+       if ($added_placeholder{$dir}) {
+               # Remove our placeholder file, if we created one.
+               delete_entry($self, $added_placeholder{$dir});
+               delete $added_placeholder{$dir}
+       }
+
 out:
        { path => $path };
 }
@@ -4447,12 +4762,96 @@ sub abort_edit {
 
 sub close_edit {
        my $self = shift;
+
+       if ($_preserve_empty_dirs) {
+               my @empty_dirs;
+
+               # Any entry flagged as empty that also has an associated
+               # dir_prop represents a newly created empty directory.
+               foreach my $i (keys %{$self->{empty}}) {
+                       push @empty_dirs, $i if exists $self->{dir_prop}->{$i};
+               }
+
+               # Search for directories that have become empty due subsequent
+               # file deletes.
+               push @empty_dirs, $self->find_empty_directories();
+
+               # Finally, add a placeholder file to each empty directory.
+               $self->add_placeholder_file($_) foreach (@empty_dirs);
+
+               $self->stash_placeholder_list();
+       }
+
        $self->{git_commit_ok} = 1;
        $self->{nr} = $self->{gii}->{nr};
        delete $self->{gii};
        $self->SUPER::close_edit(@_);
 }
 
+sub find_empty_directories {
+       my ($self) = @_;
+       my @empty_dirs;
+       my %dirs = map { dirname($_) => 1 } @deleted_gpath;
+
+       foreach my $dir (sort keys %dirs) {
+               next if $dir eq ".";
+
+               # If there have been any additions to this directory, there is
+               # no reason to check if it is empty.
+               my $skip_added = 0;
+               foreach my $t (qw/dir_prop file_prop/) {
+                       foreach my $path (keys %{ $self->{$t} }) {
+                               if (exists $self->{$t}->{dirname($path)}) {
+                                       $skip_added = 1;
+                                       last;
+                               }
+                       }
+                       last if $skip_added;
+               }
+               next if $skip_added;
+
+               # Use `git ls-tree` to get the filenames of this directory
+               # that existed prior to this particular commit.
+               my $ls = command('ls-tree', '-z', '--name-only',
+                                $self->{c}, "$dir/");
+               my %files = map { $_ => 1 } split(/\0/, $ls);
+
+               # Remove the filenames that were deleted during this commit.
+               delete $files{$_} foreach (@deleted_gpath);
+
+               # Report the directory if there are no filenames left.
+               push @empty_dirs, $dir unless (scalar %files);
+       }
+       @empty_dirs;
+}
+
+sub add_placeholder_file {
+       my ($self, $dir) = @_;
+       my $path = "$dir/$_placeholder_filename";
+       my $gpath = $self->git_path($path);
+
+       my $fh = $::_repository->temp_acquire($gpath);
+       my $hash = $::_repository->hash_and_insert_object(Git::temp_path($fh));
+       Git::temp_release($fh, 1);
+       $self->{gii}->update('100644', $hash, $gpath) or croak $!;
+
+       # The directory should no longer be considered empty.
+       delete $self->{empty}->{$dir} if exists $self->{empty}->{$dir};
+
+       # Keep track of any placeholder files we create.
+       $added_placeholder{$dir} = $path;
+}
+
+sub stash_placeholder_list {
+       my ($self) = @_;
+       my $k = "svn-remote.$repo_id.added-placeholder";
+       my $v = eval { command_oneline('config', '--get-all', $k) };
+       command_noisy('config', '--unset-all', $k) if $v;
+       foreach (values %added_placeholder) {
+               command_noisy('config', '--add', $k, $_);
+       }
+}
+
 package SVN::Git::Editor;
 use vars qw/@ISA $_rmdir $_cp_similarity $_find_copies_harder $_rename_limit/;
 use strict;
diff --git a/git.c b/git.c
index 7fdcab29345b071a29a8040a39cfe2b6d4b29d7c..8e34903a65c8775b19b993d3e9ddf47c23d5254e 100644 (file)
--- a/git.c
+++ b/git.c
@@ -7,8 +7,8 @@
 
 const char git_usage_string[] =
        "git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n"
-       "           [-p|--paginate|--no-pager] [--no-replace-objects]\n"
-       "           [--bare] [--git-dir=<path>] [--work-tree=<path>]\n"
+       "           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\n"
+       "           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
        "           [-c name=value] [--help]\n"
        "           <command> [<args>]";
 
@@ -126,6 +126,20 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                        setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
                        if (envchanged)
                                *envchanged = 1;
+               } else if (!strcmp(cmd, "--namespace")) {
+                       if (*argc < 2) {
+                               fprintf(stderr, "No namespace given for --namespace.\n" );
+                               usage(git_usage_string);
+                       }
+                       setenv(GIT_NAMESPACE_ENVIRONMENT, (*argv)[1], 1);
+                       if (envchanged)
+                               *envchanged = 1;
+                       (*argv)++;
+                       (*argc)--;
+               } else if (!prefixcmp(cmd, "--namespace=")) {
+                       setenv(GIT_NAMESPACE_ENVIRONMENT, cmd + 12, 1);
+                       if (envchanged)
+                               *envchanged = 1;
                } else if (!strcmp(cmd, "--work-tree")) {
                        if (*argc < 2) {
                                fprintf(stderr, "No directory given for --work-tree.\n" );
@@ -459,6 +473,8 @@ static void execv_dashed_external(const char **argv)
        const char *tmp;
        int status;
 
+       if (use_pager == -1)
+               use_pager = check_pager_config(argv[0]);
        commit_pager_choice();
 
        strbuf_addf(&cmd, "git-%s", argv[0]);
index f40f9d6a29cda39ee7f989e11ef66cdf3d54d625..9ee5f96d4ce313f4f94505ff65b560943bfd21cb 100644 (file)
@@ -2,6 +2,8 @@ import os
 import subprocess
 import sys
 
+from git_remote_helpers.util import check_call
+
 
 class GitExporter(object):
     """An exporter for testgit repositories.
@@ -15,7 +17,7 @@ class GitExporter(object):
 
         self.repo = repo
 
-    def export_repo(self, base):
+    def export_repo(self, base, refs=None):
         """Exports a fast-export stream for the given directory.
 
         Simply delegates to git fast-epxort and pipes it through sed
@@ -23,8 +25,13 @@ class GitExporter(object):
         default refs/heads. This is to demonstrate how the export
         data can be stored under it's own ref (using the refspec
         capability).
+
+        If None, refs defaults to ["HEAD"].
         """
 
+        if not refs:
+            refs = ["HEAD"]
+
         dirname = self.repo.get_base_path(base)
         path = os.path.abspath(os.path.join(dirname, 'testgit.marks'))
 
@@ -42,12 +49,10 @@ class GitExporter(object):
         if os.path.exists(path):
             args.append("--import-marks=" + path)
 
-        args.append("HEAD")
+        args.extend(refs)
 
         p1 = subprocess.Popen(args, stdout=subprocess.PIPE)
 
         args = ["sed", "s_refs/heads/_" + self.repo.prefix + "_g"]
 
-        child = subprocess.Popen(args, stdin=p1.stdout)
-        if child.wait() != 0:
-            raise CalledProcessError
+        check_call(args, stdin=p1.stdout)
index 70a712729b63047b9760b72d3e2b0a45ff176646..5c6b595e16665bc508625ab0e96c95776bacba1a 100644 (file)
@@ -1,6 +1,8 @@
 import os
 import subprocess
 
+from git_remote_helpers.util import check_call, check_output
+
 
 class GitImporter(object):
     """An importer for testgit repositories.
@@ -14,6 +16,18 @@ class GitImporter(object):
 
         self.repo = repo
 
+    def get_refs(self, gitdir):
+        """Returns a dictionary with refs.
+        """
+        args = ["git", "--git-dir=" + gitdir, "for-each-ref", "refs/heads"]
+        lines = check_output(args).strip().split('\n')
+        refs = {}
+        for line in lines:
+            value, name = line.split(' ')
+            name = name.strip('commit\t')
+            refs[name] = value
+        return refs
+
     def do_import(self, base):
         """Imports a fast-import stream to the given directory.
 
@@ -30,11 +44,23 @@ class GitImporter(object):
         if not os.path.exists(dirname):
             os.makedirs(dirname)
 
+        refs_before = self.get_refs(gitdir)
+
         args = ["git", "--git-dir=" + gitdir, "fast-import", "--quiet", "--export-marks=" + path]
 
         if os.path.exists(path):
             args.append("--import-marks=" + path)
 
-        child = subprocess.Popen(args)
-        if child.wait() != 0:
-            raise CalledProcessError
+        check_call(args)
+
+        refs_after = self.get_refs(gitdir)
+
+        changed = {}
+
+        for name, value in refs_after.iteritems():
+            if refs_before.get(name) == value:
+                continue
+
+            changed[name] = value
+
+        return changed
index f27389bb945ef423dc412c2368762439086f593e..e70025095dcfb31d3944e72ac1f83dd7d4109103 100644 (file)
@@ -1,7 +1,7 @@
 import os
 import subprocess
 
-from git_remote_helpers.util import die, warn
+from git_remote_helpers.util import check_call, die, warn
 
 
 class NonLocalGit(object):
@@ -29,9 +29,7 @@ class NonLocalGit(object):
         os.makedirs(path)
         args = ["git", "clone", "--bare", "--quiet", self.repo.gitpath, path]
 
-        child = subprocess.Popen(args)
-        if child.wait() != 0:
-            raise CalledProcessError
+        check_call(args)
 
         return path
 
@@ -45,14 +43,10 @@ class NonLocalGit(object):
             die("could not find repo at %s", path)
 
         args = ["git", "--git-dir=" + path, "fetch", "--quiet", self.repo.gitpath]
-        child = subprocess.Popen(args)
-        if child.wait() != 0:
-            raise CalledProcessError
+        check_call(args)
 
         args = ["git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD"]
-        child = subprocess.Popen(args)
-        if child.wait() != 0:
-            raise CalledProcessError
+        child = check_call(args)
 
     def push(self, base):
         """Pushes from the non-local repo to base.
@@ -63,7 +57,5 @@ class NonLocalGit(object):
         if not os.path.exists(path):
             die("could not find repo at %s", path)
 
-        args = ["git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath]
-        child = subprocess.Popen(args)
-        if child.wait() != 0:
-            raise CalledProcessError
+        args = ["git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath, "--all"]
+        child = check_call(args)
index 58e1cdb560fa0fe1a4745f971064e5e967408502..acbf8d7785e2253777456f8910e2352992dda474 100644 (file)
@@ -1,6 +1,9 @@
 import os
 import subprocess
 
+from git_remote_helpers.util import check_call
+
+
 def sanitize(rev, sep='\t'):
     """Converts a for-each-ref line to a name/value pair.
     """
@@ -53,9 +56,7 @@ class GitRepo(object):
         path = ".cached_revs"
         ofile = open(path, "w")
 
-        child = subprocess.Popen(args, stdout=ofile)
-        if child.wait() != 0:
-            raise CalledProcessError
+        check_call(args, stdout=ofile)
         output = open(path).readlines()
         self.revmap = dict(sanitize(i) for i in output)
         if "HEAD" in self.revmap:
index dce83e60660825ba115c503ce0776955d90c1a44..fbbb01b14619c1d2ed6bcc8f304f019fbe98697f 100644 (file)
@@ -11,6 +11,21 @@ import sys
 import os
 import subprocess
 
+try:
+    from subprocess import CalledProcessError
+except ImportError:
+    # from python2.7:subprocess.py
+    # Exception classes used by this module.
+    class CalledProcessError(Exception):
+        """This exception is raised when a process run by check_call() returns
+        a non-zero exit status.  The exit status will be stored in the
+        returncode attribute."""
+        def __init__(self, returncode, cmd):
+            self.returncode = returncode
+            self.cmd = cmd
+        def __str__(self):
+            return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
+
 
 # Whether or not to show debug messages
 DEBUG = False
@@ -128,6 +143,72 @@ def run_command (args, cwd = None, shell = False, add_env = None,
     return (exit_code, output, errors)
 
 
+# from python2.7:subprocess.py
+def call(*popenargs, **kwargs):
+    """Run command with arguments.  Wait for command to complete, then
+    return the returncode attribute.
+
+    The arguments are the same as for the Popen constructor.  Example:
+
+    retcode = call(["ls", "-l"])
+    """
+    return subprocess.Popen(*popenargs, **kwargs).wait()
+
+
+# from python2.7:subprocess.py
+def check_call(*popenargs, **kwargs):
+    """Run command with arguments.  Wait for command to complete.  If
+    the exit code was zero then return, otherwise raise
+    CalledProcessError.  The CalledProcessError object will have the
+    return code in the returncode attribute.
+
+    The arguments are the same as for the Popen constructor.  Example:
+
+    check_call(["ls", "-l"])
+    """
+    retcode = call(*popenargs, **kwargs)
+    if retcode:
+        cmd = kwargs.get("args")
+        if cmd is None:
+            cmd = popenargs[0]
+        raise CalledProcessError(retcode, cmd)
+    return 0
+
+
+# from python2.7:subprocess.py
+def check_output(*popenargs, **kwargs):
+    r"""Run command with arguments and return its output as a byte string.
+
+    If the exit code was non-zero it raises a CalledProcessError.  The
+    CalledProcessError object will have the return code in the returncode
+    attribute and output in the output attribute.
+
+    The arguments are the same as for the Popen constructor.  Example:
+
+    >>> check_output(["ls", "-l", "/dev/null"])
+    'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'
+
+    The stdout argument is not allowed as it is used internally.
+    To capture standard error in the result, use stderr=STDOUT.
+
+    >>> check_output(["/bin/sh", "-c",
+    ...               "ls -l non_existent_file ; exit 0"],
+    ...              stderr=STDOUT)
+    'ls: non_existent_file: No such file or directory\n'
+    """
+    if 'stdout' in kwargs:
+        raise ValueError('stdout argument not allowed, it will be overridden.')
+    process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
+    output, unused_err = process.communicate()
+    retcode = process.poll()
+    if retcode:
+        cmd = kwargs.get("args")
+        if cmd is None:
+            cmd = popenargs[0]
+        raise subprocess.CalledProcessError(retcode, cmd)
+    return output
+
+
 def file_reader_method (missing_ok = False):
     """Decorator for simplifying reading of files.
 
index c5236fee9dced35ab35d02eb7d42109f0107a165..f5efe7454ca42decbe7b113388bc6233e2311c1e 100644 (file)
@@ -231,7 +231,7 @@ Gitweb config file
 See also "Runtime gitweb configuration" section in README file
 for gitweb (in gitweb/README).
 
-- You can configure gitweb further using the gitweb configuration file;
+- You can configure gitweb further using the per-instance gitweb configuration file;
   by default this is a file named gitweb_config.perl in the same place as
   gitweb.cgi script. You can control the default place for the config file
   using the GITWEB_CONFIG build configuration variable, and you can set it
@@ -241,6 +241,17 @@ for gitweb (in gitweb/README).
   GITWEB_CONFIG_SYSTEM build configuration variable, and override it
   through the GITWEB_CONFIG_SYSTEM environment variable.
 
+  Note that if per-instance configuration file exists, then system-wide
+  configuration is _not used at all_.  This is quite untypical and suprising
+  behavior.  On the other hand changing current behavior would break backwards
+  compatibility and can lead to unexpected changes in gitweb behavior.
+  Therefore gitweb also looks for common system-wide configuration file,
+  normally /etc/gitweb-common.conf (set during build time using build time
+  configuration variable GITWEB_CONFIG_COMMON, set it at runtime using
+  environment variable with the same name).  Settings from per-instance or
+  system-wide configuration file override those from common system-wide
+  configuration file.
+
 - The gitweb config file is a fragment of perl code. You can set variables
   using "our $variable = value"; text from "#" character until the end
   of a line is ignored. See perlsyn(1) for details.
index 5d20515fba9251123e29be623178047d4131fc01..1c85b5fda8bc994e0ecd249e11e8f2331098bea9 100644 (file)
@@ -20,6 +20,7 @@ INSTALL ?= install
 # default configuration for gitweb
 GITWEB_CONFIG = gitweb_config.perl
 GITWEB_CONFIG_SYSTEM = /etc/gitweb.conf
+GITWEB_CONFIG_COMMON = /etc/gitweb-common.conf
 GITWEB_HOME_LINK_STR = projects
 GITWEB_SITENAME =
 GITWEB_PROJECTROOT = /pub/git
@@ -129,6 +130,7 @@ GITWEB_REPLACE = \
        -e 's|++GIT_BINDIR++|$(bindir)|g' \
        -e 's|++GITWEB_CONFIG++|$(GITWEB_CONFIG)|g' \
        -e 's|++GITWEB_CONFIG_SYSTEM++|$(GITWEB_CONFIG_SYSTEM)|g' \
+       -e 's|++GITWEB_CONFIG_COMMON++|$(GITWEB_CONFIG_COMMON)|g' \
        -e 's|++GITWEB_HOME_LINK_STR++|$(GITWEB_HOME_LINK_STR)|g' \
        -e 's|++GITWEB_SITENAME++|$(GITWEB_SITENAME)|g' \
        -e 's|++GITWEB_PROJECTROOT++|$(GITWEB_PROJECTROOT)|g' \
index a4cfcb42cd989c063c49b6511393ba936e93978a..a9988200d6b67066b837e7298e0e1529057a4bca 100644 (file)
@@ -10,9 +10,30 @@ From the git version 1.4.0 gitweb is bundled with git.
 Runtime gitweb configuration
 ----------------------------
 
-You can adjust gitweb behaviour using the file specified in `GITWEB_CONFIG`
-(defaults to 'gitweb_config.perl' in the same directory as the CGI), and
-as a fallback `GITWEB_CONFIG_SYSTEM` (defaults to /etc/gitweb.conf).
+Gitweb obtains configuration data from the following sources in the
+following order:
+
+1. built-in values (some set during build stage),
+2. common system-wide configuration file (`GITWEB_CONFIG_COMMON`,
+   defaults to '/etc/gitweb-common.conf'),
+3. either per-instance configuration file (`GITWEB_CONFIG`, defaults to
+   'gitweb_config.perl' in the same directory as the installed gitweb),
+   or if it does not exists then system-wide configuration file
+   (`GITWEB_CONFIG_SYSTEM`, defaults to '/etc/gitweb.conf').
+
+Values obtained in later configuration files override values obtained earlier
+in above sequence.
+
+You can read defaults in system-wide GITWEB_CONFIG_SYSTEM from GITWEB_CONFIG
+by adding
+
+  read_config_file($GITWEB_CONFIG_SYSTEM);
+
+at very beginning of per-instance GITWEB_CONFIG file.  In this case
+settings in said per-instance file will override settings from
+system-wide configuration file.  Note that read_config_file checks
+itself that the $GITWEB_CONFIG_SYSTEM file exists.
+
 The most notable thing that is not configurable at compile time are the
 optional features, stored in the '%features' variable.
 
index dab89f2eb013c78fa7c3b4fadba3061ef6d7f1ed..85d64b244dead86132de8a2a980cfbfc27c86494 100755 (executable)
@@ -665,13 +665,25 @@ sub read_config_file {
        return;
 }
 
-our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
+our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM, $GITWEB_CONFIG_COMMON);
 sub evaluate_gitweb_config {
        our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
        our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
+       our $GITWEB_CONFIG_COMMON = $ENV{'GITWEB_CONFIG_COMMON'} || "++GITWEB_CONFIG_COMMON++";
 
-       # use first config file that exists
-       read_config_file($GITWEB_CONFIG) or
+       # Protect agains duplications of file names, to not read config twice.
+       # Only one of $GITWEB_CONFIG and $GITWEB_CONFIG_SYSTEM is used, so
+       # there possibility of duplication of filename there doesn't matter.
+       $GITWEB_CONFIG = ""        if ($GITWEB_CONFIG eq $GITWEB_CONFIG_COMMON);
+       $GITWEB_CONFIG_SYSTEM = "" if ($GITWEB_CONFIG_SYSTEM eq $GITWEB_CONFIG_COMMON);
+
+       # Common system-wide settings for convenience.
+       # Those settings can be ovverriden by GITWEB_CONFIG or GITWEB_CONFIG_SYSTEM.
+       read_config_file($GITWEB_CONFIG_COMMON);
+
+       # Use first config file that exists.  This means use the per-instance
+       # GITWEB_CONFIG if exists, otherwise use GITWEB_SYSTEM_CONFIG.
+       read_config_file($GITWEB_CONFIG) and return;
        read_config_file($GITWEB_CONFIG_SYSTEM);
 }
 
@@ -1505,6 +1517,17 @@ sub esc_path {
        return $str;
 }
 
+# Sanitize for use in XHTML + application/xml+xhtm (valid XML 1.0)
+sub sanitize {
+       my $str = shift;
+
+       return undef unless defined $str;
+
+       $str = to_utf8($str);
+       $str =~ s|([[:cntrl:]])|($1 =~ /[\t\n\r]/ ? $1 : quot_cec($1))|eg;
+       return $str;
+}
+
 # Make control characters "printable", using character escape codes (CEC)
 sub quot_cec {
        my $cntrl = shift;
@@ -2514,6 +2537,13 @@ sub git_get_project_config {
 
        # key sanity check
        return unless ($key);
+       # only subsection, if exists, is case sensitive,
+       # and not lowercased by 'git config -z -l'
+       if (my ($hi, $mi, $lo) = ($key =~ /^([^.]*)\.(.*)\.([^.]*)$/)) {
+               $key = join(".", lc($hi), $mi, lc($lo));
+       } else {
+               $key = lc($key);
+       }
        $key =~ s/^gitweb\.//;
        return if ($key =~ m/\W/);
 
@@ -6465,7 +6495,8 @@ sub git_blob {
                        $nr++;
                        $line = untabify($line);
                        printf qq!<div class="pre"><a id="l%i" href="%s#l%i" class="linenr">%4i</a> %s</div>\n!,
-                              $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? $line : esc_html($line, -nbsp=>1);
+                              $nr, esc_attr(href(-replay => 1)), $nr, $nr,
+                              $syntax ? sanitize($line) : esc_html($line, -nbsp=>1);
                }
        }
        close $fd
index 93dd2bdd91b2b4b851f4ddc3b806e58bde792d56..fa2596f77c645b87e79aceb242d6074d6b2764ea 100644 (file)
@@ -16,7 +16,7 @@
  * and other reasons to not add 'js=1' param at the end of link
  * @constant
  */
-var jsExceptionsRe = /[;?]js=[01]$/;
+var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
 
 /**
  * Add '?js=1' or ';js=1' to the end of every link in the document
@@ -33,9 +33,9 @@ function fixLinks() {
        var allLinks = document.getElementsByTagName("a") || document.links;
        for (var i = 0, len = allLinks.length; i < len; i++) {
                var link = allLinks[i];
-               if (!jsExceptionsRe.test(link)) { // =~ /[;?]js=[01]$/;
-                       link.href +=
-                               (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1';
+               if (!jsExceptionsRe.test(link)) {
+                       link.href = link.href.replace(/(#|$)/,
+                               (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');
                }
        }
 }
diff --git a/graph.c b/graph.c
index 2f6893dc4f97dfbccad6f22f66861c24021a3c46..7358416a72e855b406e026036cf61bcdd15e5142 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -347,7 +347,7 @@ static struct commit_list *first_interesting_parent(struct git_graph *graph)
 
 static unsigned short graph_get_current_column_color(const struct git_graph *graph)
 {
-       if (!DIFF_OPT_TST(&graph->revs->diffopt, COLOR_DIFF))
+       if (!want_color(graph->revs->diffopt.use_color))
                return column_colors_max;
        return graph->default_column_color;
 }
diff --git a/grep.c b/grep.c
index 04e9ba4ec46b9f2002135293ede1bc5570fa73dc..b29d09c7f6a5a7f9621fb5287eb07e72ece7f484 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -137,16 +137,50 @@ static void free_pcre_regexp(struct grep_pat *p)
 }
 #endif /* !USE_LIBPCRE */
 
+static int is_fixed(const char *s, size_t len)
+{
+       size_t i;
+
+       /* regcomp cannot accept patterns with NULs so we
+        * consider any pattern containing a NUL fixed.
+        */
+       if (memchr(s, 0, len))
+               return 1;
+
+       for (i = 0; i < len; i++) {
+               if (is_regex_special(s[i]))
+                       return 0;
+       }
+
+       return 1;
+}
+
 static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
 {
        int err;
 
        p->word_regexp = opt->word_regexp;
        p->ignore_case = opt->ignore_case;
-       p->fixed = opt->fixed;
 
-       if (p->fixed)
+       if (opt->fixed || is_fixed(p->pattern, p->patternlen))
+               p->fixed = 1;
+       else
+               p->fixed = 0;
+
+       if (p->fixed) {
+               if (opt->regflags & REG_ICASE || p->ignore_case) {
+                       static char trans[256];
+                       int i;
+                       for (i = 0; i < 256; i++)
+                               trans[i] = tolower(i);
+                       p->kws = kwsalloc(trans);
+               } else {
+                       p->kws = kwsalloc(NULL);
+               }
+               kwsincr(p->kws, p->pattern, p->patternlen);
+               kwsprep(p->kws);
                return;
+       }
 
        if (opt->pcre) {
                compile_pcre_regexp(p, opt);
@@ -395,7 +429,9 @@ void free_grep_patterns(struct grep_opt *opt)
                case GREP_PATTERN: /* atom */
                case GREP_PATTERN_HEAD:
                case GREP_PATTERN_BODY:
-                       if (p->pcre_regexp)
+                       if (p->kws)
+                               kwsfree(p->kws);
+                       else if (p->pcre_regexp)
                                free_pcre_regexp(p);
                        else
                                regfree(&p->regexp);
@@ -430,7 +466,7 @@ static int word_char(char ch)
 static void output_color(struct grep_opt *opt, const void *data, size_t size,
                         const char *color)
 {
-       if (opt->color && color && color[0]) {
+       if (want_color(opt->color) && color && color[0]) {
                opt->output(opt, color, strlen(color));
                opt->output(opt, data, size);
                opt->output(opt, GIT_COLOR_RESET, strlen(GIT_COLOR_RESET));
@@ -455,26 +491,14 @@ static void show_name(struct grep_opt *opt, const char *name)
 static int fixmatch(struct grep_pat *p, char *line, char *eol,
                    regmatch_t *match)
 {
-       char *hit;
-
-       if (p->ignore_case) {
-               char *s = line;
-               do {
-                       hit = strcasestr(s, p->pattern);
-                       if (hit)
-                               break;
-                       s += strlen(s) + 1;
-               } while (s < eol);
-       } else
-               hit = memmem(line, eol - line, p->pattern, p->patternlen);
-
-       if (!hit) {
+       struct kwsmatch kwsm;
+       size_t offset = kwsexec(p->kws, line, eol - line, &kwsm);
+       if (offset == -1) {
                match->rm_so = match->rm_eo = -1;
                return REG_NOMATCH;
-       }
-       else {
-               match->rm_so = hit - line;
-               match->rm_eo = match->rm_so + p->patternlen;
+       } else {
+               match->rm_so = offset;
+               match->rm_eo = match->rm_so + kwsm.size[0];
                return 0;
        }
 }
@@ -724,7 +748,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
        if (opt->file_break && opt->last_shown == 0) {
                if (opt->show_hunk_mark)
                        opt->output(opt, "\n", 1);
-       } else if (opt->pre_context || opt->post_context) {
+       } else if (opt->pre_context || opt->post_context || opt->funcbody) {
                if (opt->last_shown == 0) {
                        if (opt->show_hunk_mark) {
                                output_color(opt, "--", 2, opt->color_sep);
@@ -819,10 +843,13 @@ static void show_funcname_line(struct grep_opt *opt, const char *name,
 }
 
 static void show_pre_context(struct grep_opt *opt, const char *name, char *buf,
-                            char *bol, unsigned lno)
+                            char *bol, char *end, unsigned lno)
 {
        unsigned cur = lno, from = 1, funcname_lno = 0;
-       int funcname_needed = opt->funcname;
+       int funcname_needed = !!opt->funcname;
+
+       if (opt->funcbody && !match_funcname(opt, bol, end))
+               funcname_needed = 2;
 
        if (opt->pre_context < lno)
                from = lno - opt->pre_context;
@@ -830,7 +857,8 @@ static void show_pre_context(struct grep_opt *opt, const char *name, char *buf,
                from = opt->last_shown + 1;
 
        /* Rewind. */
-       while (bol > buf && cur > from) {
+       while (bol > buf &&
+              cur > (funcname_needed == 2 ? opt->last_shown + 1 : from)) {
                char *eol = --bol;
 
                while (bol > buf && bol[-1] != '\n')
@@ -942,13 +970,15 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
        int binary_match_only = 0;
        unsigned count = 0;
        int try_lookahead = 0;
+       int show_function = 0;
        enum grep_context ctx = GREP_CONTEXT_HEAD;
        xdemitconf_t xecfg;
 
        if (!opt->output)
                opt->output = std_output;
 
-       if (opt->pre_context || opt->post_context || opt->file_break) {
+       if (opt->pre_context || opt->post_context || opt->file_break ||
+           opt->funcbody) {
                /* Show hunk marks, except for the first file. */
                if (opt->last_shown)
                        opt->show_hunk_mark = 1;
@@ -1004,7 +1034,8 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
                 */
                if (try_lookahead
                    && !(last_hit
-                        && lno <= last_hit + opt->post_context)
+                        && (show_function ||
+                            lno <= last_hit + opt->post_context))
                    && look_ahead(opt, &left, &lno, &bol))
                        break;
                eol = end_of_line(bol, &left);
@@ -1051,15 +1082,20 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
                        /* Hit at this line.  If we haven't shown the
                         * pre-context lines, we would need to show them.
                         */
-                       if (opt->pre_context)
-                               show_pre_context(opt, name, buf, bol, lno);
+                       if (opt->pre_context || opt->funcbody)
+                               show_pre_context(opt, name, buf, bol, eol, lno);
                        else if (opt->funcname)
                                show_funcname_line(opt, name, buf, bol, lno);
                        show_line(opt, bol, eol, name, lno, ':');
                        last_hit = lno;
+                       if (opt->funcbody)
+                               show_function = 1;
+                       goto next_line;
                }
-               else if (last_hit &&
-                        lno <= last_hit + opt->post_context) {
+               if (show_function && match_funcname(opt, bol, eol))
+                       show_function = 0;
+               if (show_function ||
+                   (last_hit && lno <= last_hit + opt->post_context)) {
                        /* If the last hit is within the post context,
                         * we need to show this line.
                         */
diff --git a/grep.h b/grep.h
index c5682973eaf696099b0d0367e21df6c0a4624836..a65280026d5dee8ab059bead79f05d6a1111147a 100644 (file)
--- a/grep.h
+++ b/grep.h
@@ -7,6 +7,7 @@
 typedef int pcre;
 typedef int pcre_extra;
 #endif
+#include "kwset.h"
 
 enum grep_pat_token {
        GREP_PATTERN,
@@ -41,6 +42,7 @@ struct grep_pat {
        regex_t regexp;
        pcre *pcre_regexp;
        pcre_extra *pcre_extra_info;
+       kwset_t kws;
        unsigned fixed:1;
        unsigned ignore_case:1;
        unsigned word_regexp:1;
@@ -98,6 +100,7 @@ struct grep_opt {
        int color;
        int max_depth;
        int funcname;
+       int funcbody;
        char color_context[COLOR_MAXLEN];
        char color_filename[COLOR_MAXLEN];
        char color_function[COLOR_MAXLEN];
index 3af4c71bd0fb8370c6f08b0e3d43adc722cac2f4..8c4c5d2224a2493a648e6a34257bc150f2712dd0 100644 (file)
@@ -56,6 +56,10 @@ int main(int argc, const char **argv)
                commits = 1;
        }
 
+       if (get_all == 0)
+               warning("http-fetch: use without -a is deprecated.\n"
+                       "In a future release, -a will become the default.");
+
        if (argv[arg])
                str_end_url_with_slash(argv[arg], &url);
 
index 6e8f6d09abb6397f1782fa32d9d273fc4fc740fe..44f814cda2a9756a55cb7f332d5fef0e5484256b 100644 (file)
@@ -1606,10 +1606,10 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
        strbuf_release(&buffer);
 }
 
-static int verify_merge_base(unsigned char *head_sha1, unsigned char *branch_sha1)
+static int verify_merge_base(unsigned char *head_sha1, struct ref *remote)
 {
-       struct commit *head = lookup_commit(head_sha1);
-       struct commit *branch = lookup_commit(branch_sha1);
+       struct commit *head = lookup_commit_or_die(head_sha1, "HEAD");
+       struct commit *branch = lookup_commit_or_die(remote->old_sha1, remote->name);
        struct commit_list *merge_bases = get_merge_bases(head, branch, 1);
 
        return (merge_bases && !merge_bases->next && merge_bases->item == branch);
@@ -1655,7 +1655,7 @@ static int delete_remote_branch(const char *pattern, int force)
                return error("Remote HEAD is not a symref");
 
        /* Remote branch must not be the remote HEAD */
-       for (i=0; symref && i<MAXDEPTH; i++) {
+       for (i = 0; symref && i < MAXDEPTH; i++) {
                if (!strcmp(remote_ref->name, symref))
                        return error("Remote branch %s is the current HEAD",
                                     remote_ref->name);
@@ -1680,7 +1680,7 @@ static int delete_remote_branch(const char *pattern, int force)
                        return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, sha1_to_hex(remote_ref->old_sha1));
 
                /* Remote branch must be an ancestor of remote HEAD */
-               if (!verify_merge_base(head_sha1, remote_ref->old_sha1)) {
+               if (!verify_merge_base(head_sha1, remote_ref)) {
                        return error("The branch '%s' is not an ancestor "
                                     "of your current HEAD.\n"
                                     "If you are sure you want to delete it,"
diff --git a/http.c b/http.c
index a1ea3db499eebc2deabf1a64e43b063cbe63ad2a..fb3465f50c95ab9cb3e6fae1d1e594f6ae0b9c42 100644 (file)
--- a/http.c
+++ b/http.c
@@ -851,8 +851,13 @@ static int http_request(const char *url, void *result, int target, int options)
                                init_curl_http_auth(slot->curl);
                                ret = HTTP_REAUTH;
                        }
-               } else
+               } else {
+                       if (!curl_errorstr[0])
+                               strlcpy(curl_errorstr,
+                                       curl_easy_strerror(results.curl_result),
+                                       sizeof(curl_errorstr));
                        ret = HTTP_ERROR;
+               }
        } else {
                error("Unable to start HTTP request for %s", url);
                ret = HTTP_START_FAILED;
@@ -908,7 +913,7 @@ int http_error(const char *url, int ret)
 {
        /* http_request has already handled HTTP_START_FAILED. */
        if (ret != HTTP_START_FAILED)
-               error("%s while accessing %s\n", curl_errorstr, url);
+               error("%s while accessing %s", curl_errorstr, url);
 
        return ret;
 }
@@ -1121,9 +1126,8 @@ struct http_pack_request *new_http_pack_request(
        struct strbuf buf = STRBUF_INIT;
        struct http_pack_request *preq;
 
-       preq = xmalloc(sizeof(*preq));
+       preq = xcalloc(1, sizeof(*preq));
        preq->target = target;
-       preq->range_header = NULL;
 
        end_url_with_slash(&buf, base_url);
        strbuf_addf(&buf, "objects/pack/pack-%s.pack",
@@ -1215,7 +1219,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
        struct curl_slist *range_header = NULL;
        struct http_object_request *freq;
 
-       freq = xmalloc(sizeof(*freq));
+       freq = xcalloc(1, sizeof(*freq));
        hashcpy(freq->sha1, sha1);
        freq->localfile = -1;
 
@@ -1253,8 +1257,6 @@ struct http_object_request *new_http_object_request(const char *base_url,
                goto abort;
        }
 
-       memset(&freq->stream, 0, sizeof(freq->stream));
-
        git_inflate_init(&freq->stream);
 
        git_SHA1_Init(&freq->c);
@@ -1329,7 +1331,6 @@ struct http_object_request *new_http_object_request(const char *base_url,
        return freq;
 
 abort:
-       free(filename);
        free(freq->url);
        free(freq);
        return NULL;
diff --git a/kwset.c b/kwset.c
new file mode 100644 (file)
index 0000000..956ae72
--- /dev/null
+++ b/kwset.c
@@ -0,0 +1,771 @@
+/*
+ * This file has been copied from commit e7ac713d^ in the GNU grep git
+ * repository. A few small changes have been made to adapt the code to
+ * Git.
+ */
+
+/* kwset.c - search for any of a set of keywords.
+   Copyright 1989, 1998, 2000, 2005 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
+
+/* Written August 1989 by Mike Haertel.
+   The author may be reached (Email) at the address mike@ai.mit.edu,
+   or (US mail) as Mike Haertel c/o Free Software Foundation. */
+
+/* The algorithm implemented by these routines bears a startling resemblence
+   to one discovered by Beate Commentz-Walter, although it is not identical.
+   See "A String Matching Algorithm Fast on the Average," Technical Report,
+   IBM-Germany, Scientific Center Heidelberg, Tiergartenstrasse 15, D-6900
+   Heidelberg, Germany.  See also Aho, A.V., and M. Corasick, "Efficient
+   String Matching:  An Aid to Bibliographic Search," CACM June 1975,
+   Vol. 18, No. 6, which describes the failure function used below. */
+
+#include "cache.h"
+
+#include "kwset.h"
+#include "compat/obstack.h"
+
+#define NCHAR (UCHAR_MAX + 1)
+#define obstack_chunk_alloc xmalloc
+#define obstack_chunk_free free
+
+#define U(c) ((unsigned char) (c))
+
+/* Balanced tree of edges and labels leaving a given trie node. */
+struct tree
+{
+  struct tree *llink;          /* Left link; MUST be first field. */
+  struct tree *rlink;          /* Right link (to larger labels). */
+  struct trie *trie;           /* Trie node pointed to by this edge. */
+  unsigned char label;         /* Label on this edge. */
+  char balance;                        /* Difference in depths of subtrees. */
+};
+
+/* Node of a trie representing a set of reversed keywords. */
+struct trie
+{
+  unsigned int accepting;      /* Word index of accepted word, or zero. */
+  struct tree *links;          /* Tree of edges leaving this node. */
+  struct trie *parent;         /* Parent of this node. */
+  struct trie *next;           /* List of all trie nodes in level order. */
+  struct trie *fail;           /* Aho-Corasick failure function. */
+  int depth;                   /* Depth of this node from the root. */
+  int shift;                   /* Shift function for search failures. */
+  int maxshift;                        /* Max shift of self and descendents. */
+};
+
+/* Structure returned opaquely to the caller, containing everything. */
+struct kwset
+{
+  struct obstack obstack;      /* Obstack for node allocation. */
+  int words;                   /* Number of words in the trie. */
+  struct trie *trie;           /* The trie itself. */
+  int mind;                    /* Minimum depth of an accepting node. */
+  int maxd;                    /* Maximum depth of any node. */
+  unsigned char delta[NCHAR];  /* Delta table for rapid search. */
+  struct trie *next[NCHAR];    /* Table of children of the root. */
+  char *target;                        /* Target string if there's only one. */
+  int mind2;                   /* Used in Boyer-Moore search for one string. */
+  char const *trans;           /* Character translation table. */
+};
+
+/* Allocate and initialize a keyword set object, returning an opaque
+   pointer to it.  Return NULL if memory is not available. */
+kwset_t
+kwsalloc (char const *trans)
+{
+  struct kwset *kwset;
+
+  kwset = (struct kwset *) xmalloc(sizeof (struct kwset));
+
+  obstack_init(&kwset->obstack);
+  kwset->words = 0;
+  kwset->trie
+    = (struct trie *) obstack_alloc(&kwset->obstack, sizeof (struct trie));
+  if (!kwset->trie)
+    {
+      kwsfree((kwset_t) kwset);
+      return NULL;
+    }
+  kwset->trie->accepting = 0;
+  kwset->trie->links = NULL;
+  kwset->trie->parent = NULL;
+  kwset->trie->next = NULL;
+  kwset->trie->fail = NULL;
+  kwset->trie->depth = 0;
+  kwset->trie->shift = 0;
+  kwset->mind = INT_MAX;
+  kwset->maxd = -1;
+  kwset->target = NULL;
+  kwset->trans = trans;
+
+  return (kwset_t) kwset;
+}
+
+/* This upper bound is valid for CHAR_BIT >= 4 and
+   exact for CHAR_BIT in { 4..11, 13, 15, 17, 19 }. */
+#define DEPTH_SIZE (CHAR_BIT + CHAR_BIT/2)
+
+/* Add the given string to the contents of the keyword set.  Return NULL
+   for success, an error message otherwise. */
+const char *
+kwsincr (kwset_t kws, char const *text, size_t len)
+{
+  struct kwset *kwset;
+  register struct trie *trie;
+  register unsigned char label;
+  register struct tree *link;
+  register int depth;
+  struct tree *links[DEPTH_SIZE];
+  enum { L, R } dirs[DEPTH_SIZE];
+  struct tree *t, *r, *l, *rl, *lr;
+
+  kwset = (struct kwset *) kws;
+  trie = kwset->trie;
+  text += len;
+
+  /* Descend the trie (built of reversed keywords) character-by-character,
+     installing new nodes when necessary. */
+  while (len--)
+    {
+      label = kwset->trans ? kwset->trans[U(*--text)] : *--text;
+
+      /* Descend the tree of outgoing links for this trie node,
+        looking for the current character and keeping track
+        of the path followed. */
+      link = trie->links;
+      links[0] = (struct tree *) &trie->links;
+      dirs[0] = L;
+      depth = 1;
+
+      while (link && label != link->label)
+       {
+         links[depth] = link;
+         if (label < link->label)
+           dirs[depth++] = L, link = link->llink;
+         else
+           dirs[depth++] = R, link = link->rlink;
+       }
+
+      /* The current character doesn't have an outgoing link at
+        this trie node, so build a new trie node and install
+        a link in the current trie node's tree. */
+      if (!link)
+       {
+         link = (struct tree *) obstack_alloc(&kwset->obstack,
+                                              sizeof (struct tree));
+         if (!link)
+           return "memory exhausted";
+         link->llink = NULL;
+         link->rlink = NULL;
+         link->trie = (struct trie *) obstack_alloc(&kwset->obstack,
+                                                    sizeof (struct trie));
+         if (!link->trie)
+           {
+             obstack_free(&kwset->obstack, link);
+             return "memory exhausted";
+           }
+         link->trie->accepting = 0;
+         link->trie->links = NULL;
+         link->trie->parent = trie;
+         link->trie->next = NULL;
+         link->trie->fail = NULL;
+         link->trie->depth = trie->depth + 1;
+         link->trie->shift = 0;
+         link->label = label;
+         link->balance = 0;
+
+         /* Install the new tree node in its parent. */
+         if (dirs[--depth] == L)
+           links[depth]->llink = link;
+         else
+           links[depth]->rlink = link;
+
+         /* Back up the tree fixing the balance flags. */
+         while (depth && !links[depth]->balance)
+           {
+             if (dirs[depth] == L)
+               --links[depth]->balance;
+             else
+               ++links[depth]->balance;
+             --depth;
+           }
+
+         /* Rebalance the tree by pointer rotations if necessary. */
+         if (depth && ((dirs[depth] == L && --links[depth]->balance)
+                       || (dirs[depth] == R && ++links[depth]->balance)))
+           {
+             switch (links[depth]->balance)
+               {
+               case (char) -2:
+                 switch (dirs[depth + 1])
+                   {
+                   case L:
+                     r = links[depth], t = r->llink, rl = t->rlink;
+                     t->rlink = r, r->llink = rl;
+                     t->balance = r->balance = 0;
+                     break;
+                   case R:
+                     r = links[depth], l = r->llink, t = l->rlink;
+                     rl = t->rlink, lr = t->llink;
+                     t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
+                     l->balance = t->balance != 1 ? 0 : -1;
+                     r->balance = t->balance != (char) -1 ? 0 : 1;
+                     t->balance = 0;
+                     break;
+                   default:
+                     abort ();
+                   }
+                 break;
+               case 2:
+                 switch (dirs[depth + 1])
+                   {
+                   case R:
+                     l = links[depth], t = l->rlink, lr = t->llink;
+                     t->llink = l, l->rlink = lr;
+                     t->balance = l->balance = 0;
+                     break;
+                   case L:
+                     l = links[depth], r = l->rlink, t = r->llink;
+                     lr = t->llink, rl = t->rlink;
+                     t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
+                     l->balance = t->balance != 1 ? 0 : -1;
+                     r->balance = t->balance != (char) -1 ? 0 : 1;
+                     t->balance = 0;
+                     break;
+                   default:
+                     abort ();
+                   }
+                 break;
+               default:
+                 abort ();
+               }
+
+             if (dirs[depth - 1] == L)
+               links[depth - 1]->llink = t;
+             else
+               links[depth - 1]->rlink = t;
+           }
+       }
+
+      trie = link->trie;
+    }
+
+  /* Mark the node we finally reached as accepting, encoding the
+     index number of this word in the keyword set so far. */
+  if (!trie->accepting)
+    trie->accepting = 1 + 2 * kwset->words;
+  ++kwset->words;
+
+  /* Keep track of the longest and shortest string of the keyword set. */
+  if (trie->depth < kwset->mind)
+    kwset->mind = trie->depth;
+  if (trie->depth > kwset->maxd)
+    kwset->maxd = trie->depth;
+
+  return NULL;
+}
+
+/* Enqueue the trie nodes referenced from the given tree in the
+   given queue. */
+static void
+enqueue (struct tree *tree, struct trie **last)
+{
+  if (!tree)
+    return;
+  enqueue(tree->llink, last);
+  enqueue(tree->rlink, last);
+  (*last) = (*last)->next = tree->trie;
+}
+
+/* Compute the Aho-Corasick failure function for the trie nodes referenced
+   from the given tree, given the failure function for their parent as
+   well as a last resort failure node. */
+static void
+treefails (register struct tree const *tree, struct trie const *fail,
+          struct trie *recourse)
+{
+  register struct tree *link;
+
+  if (!tree)
+    return;
+
+  treefails(tree->llink, fail, recourse);
+  treefails(tree->rlink, fail, recourse);
+
+  /* Find, in the chain of fails going back to the root, the first
+     node that has a descendent on the current label. */
+  while (fail)
+    {
+      link = fail->links;
+      while (link && tree->label != link->label)
+       if (tree->label < link->label)
+         link = link->llink;
+       else
+         link = link->rlink;
+      if (link)
+       {
+         tree->trie->fail = link->trie;
+         return;
+       }
+      fail = fail->fail;
+    }
+
+  tree->trie->fail = recourse;
+}
+
+/* Set delta entries for the links of the given tree such that
+   the preexisting delta value is larger than the current depth. */
+static void
+treedelta (register struct tree const *tree,
+          register unsigned int depth,
+          unsigned char delta[])
+{
+  if (!tree)
+    return;
+  treedelta(tree->llink, depth, delta);
+  treedelta(tree->rlink, depth, delta);
+  if (depth < delta[tree->label])
+    delta[tree->label] = depth;
+}
+
+/* Return true if A has every label in B. */
+static int
+hasevery (register struct tree const *a, register struct tree const *b)
+{
+  if (!b)
+    return 1;
+  if (!hasevery(a, b->llink))
+    return 0;
+  if (!hasevery(a, b->rlink))
+    return 0;
+  while (a && b->label != a->label)
+    if (b->label < a->label)
+      a = a->llink;
+    else
+      a = a->rlink;
+  return !!a;
+}
+
+/* Compute a vector, indexed by character code, of the trie nodes
+   referenced from the given tree. */
+static void
+treenext (struct tree const *tree, struct trie *next[])
+{
+  if (!tree)
+    return;
+  treenext(tree->llink, next);
+  treenext(tree->rlink, next);
+  next[tree->label] = tree->trie;
+}
+
+/* Compute the shift for each trie node, as well as the delta
+   table and next cache for the given keyword set. */
+const char *
+kwsprep (kwset_t kws)
+{
+  register struct kwset *kwset;
+  register int i;
+  register struct trie *curr;
+  register char const *trans;
+  unsigned char delta[NCHAR];
+
+  kwset = (struct kwset *) kws;
+
+  /* Initial values for the delta table; will be changed later.  The
+     delta entry for a given character is the smallest depth of any
+     node at which an outgoing edge is labeled by that character. */
+  memset(delta, kwset->mind < UCHAR_MAX ? kwset->mind : UCHAR_MAX, NCHAR);
+
+  /* Check if we can use the simple boyer-moore algorithm, instead
+     of the hairy commentz-walter algorithm. */
+  if (kwset->words == 1 && kwset->trans == NULL)
+    {
+      char c;
+
+      /* Looking for just one string.  Extract it from the trie. */
+      kwset->target = obstack_alloc(&kwset->obstack, kwset->mind);
+      if (!kwset->target)
+       return "memory exhausted";
+      for (i = kwset->mind - 1, curr = kwset->trie; i >= 0; --i)
+       {
+         kwset->target[i] = curr->links->label;
+         curr = curr->links->trie;
+       }
+      /* Build the Boyer Moore delta.  Boy that's easy compared to CW. */
+      for (i = 0; i < kwset->mind; ++i)
+       delta[U(kwset->target[i])] = kwset->mind - (i + 1);
+      /* Find the minimal delta2 shift that we might make after
+        a backwards match has failed. */
+      c = kwset->target[kwset->mind - 1];
+      for (i = kwset->mind - 2; i >= 0; --i)
+       if (kwset->target[i] == c)
+         break;
+      kwset->mind2 = kwset->mind - (i + 1);
+    }
+  else
+    {
+      register struct trie *fail;
+      struct trie *last, *next[NCHAR];
+
+      /* Traverse the nodes of the trie in level order, simultaneously
+        computing the delta table, failure function, and shift function. */
+      for (curr = last = kwset->trie; curr; curr = curr->next)
+       {
+         /* Enqueue the immediate descendents in the level order queue. */
+         enqueue(curr->links, &last);
+
+         curr->shift = kwset->mind;
+         curr->maxshift = kwset->mind;
+
+         /* Update the delta table for the descendents of this node. */
+         treedelta(curr->links, curr->depth, delta);
+
+         /* Compute the failure function for the decendents of this node. */
+         treefails(curr->links, curr->fail, kwset->trie);
+
+         /* Update the shifts at each node in the current node's chain
+            of fails back to the root. */
+         for (fail = curr->fail; fail; fail = fail->fail)
+           {
+             /* If the current node has some outgoing edge that the fail
+                doesn't, then the shift at the fail should be no larger
+                than the difference of their depths. */
+             if (!hasevery(fail->links, curr->links))
+               if (curr->depth - fail->depth < fail->shift)
+                 fail->shift = curr->depth - fail->depth;
+
+             /* If the current node is accepting then the shift at the
+                fail and its descendents should be no larger than the
+                difference of their depths. */
+             if (curr->accepting && fail->maxshift > curr->depth - fail->depth)
+               fail->maxshift = curr->depth - fail->depth;
+           }
+       }
+
+      /* Traverse the trie in level order again, fixing up all nodes whose
+        shift exceeds their inherited maxshift. */
+      for (curr = kwset->trie->next; curr; curr = curr->next)
+       {
+         if (curr->maxshift > curr->parent->maxshift)
+           curr->maxshift = curr->parent->maxshift;
+         if (curr->shift > curr->maxshift)
+           curr->shift = curr->maxshift;
+       }
+
+      /* Create a vector, indexed by character code, of the outgoing links
+        from the root node. */
+      for (i = 0; i < NCHAR; ++i)
+       next[i] = NULL;
+      treenext(kwset->trie->links, next);
+
+      if ((trans = kwset->trans) != NULL)
+       for (i = 0; i < NCHAR; ++i)
+         kwset->next[i] = next[U(trans[i])];
+      else
+       memcpy(kwset->next, next, NCHAR * sizeof(struct trie *));
+    }
+
+  /* Fix things up for any translation table. */
+  if ((trans = kwset->trans) != NULL)
+    for (i = 0; i < NCHAR; ++i)
+      kwset->delta[i] = delta[U(trans[i])];
+  else
+    memcpy(kwset->delta, delta, NCHAR);
+
+  return NULL;
+}
+
+/* Fast boyer-moore search. */
+static size_t
+bmexec (kwset_t kws, char const *text, size_t size)
+{
+  struct kwset const *kwset;
+  register unsigned char const *d1;
+  register char const *ep, *sp, *tp;
+  register int d, gc, i, len, md2;
+
+  kwset = (struct kwset const *) kws;
+  len = kwset->mind;
+
+  if (len == 0)
+    return 0;
+  if (len > size)
+    return -1;
+  if (len == 1)
+    {
+      tp = memchr (text, kwset->target[0], size);
+      return tp ? tp - text : -1;
+    }
+
+  d1 = kwset->delta;
+  sp = kwset->target + len;
+  gc = U(sp[-2]);
+  md2 = kwset->mind2;
+  tp = text + len;
+
+  /* Significance of 12: 1 (initial offset) + 10 (skip loop) + 1 (md2). */
+  if (size > 12 * len)
+    /* 11 is not a bug, the initial offset happens only once. */
+    for (ep = text + size - 11 * len;;)
+      {
+       while (tp <= ep)
+         {
+           d = d1[U(tp[-1])], tp += d;
+           d = d1[U(tp[-1])], tp += d;
+           if (d == 0)
+             goto found;
+           d = d1[U(tp[-1])], tp += d;
+           d = d1[U(tp[-1])], tp += d;
+           d = d1[U(tp[-1])], tp += d;
+           if (d == 0)
+             goto found;
+           d = d1[U(tp[-1])], tp += d;
+           d = d1[U(tp[-1])], tp += d;
+           d = d1[U(tp[-1])], tp += d;
+           if (d == 0)
+             goto found;
+           d = d1[U(tp[-1])], tp += d;
+           d = d1[U(tp[-1])], tp += d;
+         }
+       break;
+      found:
+       if (U(tp[-2]) == gc)
+         {
+           for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
+             ;
+           if (i > len)
+             return tp - len - text;
+         }
+       tp += md2;
+      }
+
+  /* Now we have only a few characters left to search.  We
+     carefully avoid ever producing an out-of-bounds pointer. */
+  ep = text + size;
+  d = d1[U(tp[-1])];
+  while (d <= ep - tp)
+    {
+      d = d1[U((tp += d)[-1])];
+      if (d != 0)
+       continue;
+      if (U(tp[-2]) == gc)
+       {
+         for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
+           ;
+         if (i > len)
+           return tp - len - text;
+       }
+      d = md2;
+    }
+
+  return -1;
+}
+
+/* Hairy multiple string search. */
+static size_t
+cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
+{
+  struct kwset const *kwset;
+  struct trie * const *next;
+  struct trie const *trie;
+  struct trie const *accept;
+  char const *beg, *lim, *mch, *lmch;
+  register unsigned char c;
+  register unsigned char const *delta;
+  register int d;
+  register char const *end, *qlim;
+  register struct tree const *tree;
+  register char const *trans;
+
+  accept = NULL;
+
+  /* Initialize register copies and look for easy ways out. */
+  kwset = (struct kwset *) kws;
+  if (len < kwset->mind)
+    return -1;
+  next = kwset->next;
+  delta = kwset->delta;
+  trans = kwset->trans;
+  lim = text + len;
+  end = text;
+  if ((d = kwset->mind) != 0)
+    mch = NULL;
+  else
+    {
+      mch = text, accept = kwset->trie;
+      goto match;
+    }
+
+  if (len >= 4 * kwset->mind)
+    qlim = lim - 4 * kwset->mind;
+  else
+    qlim = NULL;
+
+  while (lim - end >= d)
+    {
+      if (qlim && end <= qlim)
+       {
+         end += d - 1;
+         while ((d = delta[c = *end]) && end < qlim)
+           {
+             end += d;
+             end += delta[U(*end)];
+             end += delta[U(*end)];
+           }
+         ++end;
+       }
+      else
+       d = delta[c = (end += d)[-1]];
+      if (d)
+       continue;
+      beg = end - 1;
+      trie = next[c];
+      if (trie->accepting)
+       {
+         mch = beg;
+         accept = trie;
+       }
+      d = trie->shift;
+      while (beg > text)
+       {
+         c = trans ? trans[U(*--beg)] : *--beg;
+         tree = trie->links;
+         while (tree && c != tree->label)
+           if (c < tree->label)
+             tree = tree->llink;
+           else
+             tree = tree->rlink;
+         if (tree)
+           {
+             trie = tree->trie;
+             if (trie->accepting)
+               {
+                 mch = beg;
+                 accept = trie;
+               }
+           }
+         else
+           break;
+         d = trie->shift;
+       }
+      if (mch)
+       goto match;
+    }
+  return -1;
+
+ match:
+  /* Given a known match, find the longest possible match anchored
+     at or before its starting point.  This is nearly a verbatim
+     copy of the preceding main search loops. */
+  if (lim - mch > kwset->maxd)
+    lim = mch + kwset->maxd;
+  lmch = 0;
+  d = 1;
+  while (lim - end >= d)
+    {
+      if ((d = delta[c = (end += d)[-1]]) != 0)
+       continue;
+      beg = end - 1;
+      if (!(trie = next[c]))
+       {
+         d = 1;
+         continue;
+       }
+      if (trie->accepting && beg <= mch)
+       {
+         lmch = beg;
+         accept = trie;
+       }
+      d = trie->shift;
+      while (beg > text)
+       {
+         c = trans ? trans[U(*--beg)] : *--beg;
+         tree = trie->links;
+         while (tree && c != tree->label)
+           if (c < tree->label)
+             tree = tree->llink;
+           else
+             tree = tree->rlink;
+         if (tree)
+           {
+             trie = tree->trie;
+             if (trie->accepting && beg <= mch)
+               {
+                 lmch = beg;
+                 accept = trie;
+               }
+           }
+         else
+           break;
+         d = trie->shift;
+       }
+      if (lmch)
+       {
+         mch = lmch;
+         goto match;
+       }
+      if (!d)
+       d = 1;
+    }
+
+  if (kwsmatch)
+    {
+      kwsmatch->index = accept->accepting / 2;
+      kwsmatch->offset[0] = mch - text;
+      kwsmatch->size[0] = accept->depth;
+    }
+  return mch - text;
+}
+
+/* Search through the given text for a match of any member of the
+   given keyword set.  Return a pointer to the first character of
+   the matching substring, or NULL if no match is found.  If FOUNDLEN
+   is non-NULL store in the referenced location the length of the
+   matching substring.  Similarly, if FOUNDIDX is non-NULL, store
+   in the referenced location the index number of the particular
+   keyword matched. */
+size_t
+kwsexec (kwset_t kws, char const *text, size_t size,
+        struct kwsmatch *kwsmatch)
+{
+  struct kwset const *kwset = (struct kwset *) kws;
+  if (kwset->words == 1 && kwset->trans == NULL)
+    {
+      size_t ret = bmexec (kws, text, size);
+      if (kwsmatch != NULL && ret != (size_t) -1)
+       {
+         kwsmatch->index = 0;
+         kwsmatch->offset[0] = ret;
+         kwsmatch->size[0] = kwset->mind;
+       }
+      return ret;
+    }
+  else
+    return cwexec(kws, text, size, kwsmatch);
+}
+
+/* Free the components of the given keyword set. */
+void
+kwsfree (kwset_t kws)
+{
+  struct kwset *kwset;
+
+  kwset = (struct kwset *) kws;
+  obstack_free(&kwset->obstack, NULL);
+  free(kws);
+}
diff --git a/kwset.h b/kwset.h
new file mode 100644 (file)
index 0000000..a21b2ea
--- /dev/null
+++ b/kwset.h
@@ -0,0 +1,63 @@
+/* This file has been copied from commit e7ac713d^ in the GNU grep git
+ * repository. A few small changes have been made to adapt the code to
+ * Git.
+ */
+
+/* kwset.h - header declaring the keyword set library.
+   Copyright (C) 1989, 1998, 2005 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
+
+/* Written August 1989 by Mike Haertel.
+   The author may be reached (Email) at the address mike@ai.mit.edu,
+   or (US mail) as Mike Haertel c/o Free Software Foundation. */
+
+struct kwsmatch
+{
+  int index;                   /* Index number of matching keyword. */
+  size_t offset[1];            /* Offset of each submatch. */
+  size_t size[1];              /* Length of each submatch. */
+};
+
+struct kwset_t;
+typedef struct kwset_t* kwset_t;
+
+/* Return an opaque pointer to a newly allocated keyword set, or NULL
+   if enough memory cannot be obtained.  The argument if non-NULL
+   specifies a table of character translations to be applied to all
+   pattern and search text. */
+extern kwset_t kwsalloc(char const *);
+
+/* Incrementally extend the keyword set to include the given string.
+   Return NULL for success, or an error message.  Remember an index
+   number for each keyword included in the set. */
+extern const char *kwsincr(kwset_t, char const *, size_t);
+
+/* When the keyword set has been completely built, prepare it for
+   use.  Return NULL for success, or an error message. */
+extern const char *kwsprep(kwset_t);
+
+/* Search through the given buffer for a member of the keyword set.
+   Return a pointer to the leftmost longest match found, or NULL if
+   no match is found.  If foundlen is non-NULL, store the length of
+   the matching substring in the integer it points to.  Similarly,
+   if foundindex is non-NULL, store the index of the particular
+   keyword found therein. */
+extern size_t kwsexec(kwset_t, char const *, size_t, struct kwsmatch *);
+
+/* Deallocate the given keyword set and all its associated storage. */
+extern void kwsfree(kwset_t);
+
index 6ce512efc4cce8042481e8a6947d033c272e78e6..da59738c9b787ae082ad062a91345a60628e704a 100644 (file)
@@ -330,7 +330,7 @@ static int git_path_check_merge(const char *path, struct git_attr_check check[2]
                check[0].attr = git_attr("merge");
                check[1].attr = git_attr("conflict-marker-size");
        }
-       return git_checkattr(path, 2, check);
+       return git_check_attr(path, 2, check);
 }
 
 static void normalize_file(mmfile_t *mm, const char *path)
@@ -387,7 +387,7 @@ int ll_merge_marker_size(const char *path)
 
        if (!check.attr)
                check.attr = git_attr("conflict-marker-size");
-       if (!git_checkattr(path, 1, &check) && check.value) {
+       if (!git_check_attr(path, 1, &check) && check.value) {
                marker_size = atoi(check.value);
                if (marker_size <= 0)
                        marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
index e9457019d5ac7aff1e185e195f37b851732f6210..24c295ea1dc91180b9685299f48812593162bdfe 100644 (file)
@@ -18,6 +18,7 @@ enum decoration_type {
        DECORATION_REF_TAG,
        DECORATION_REF_STASH,
        DECORATION_REF_HEAD,
+       DECORATION_GRAFTED,
 };
 
 static char decoration_colors[][COLOR_MAXLEN] = {
@@ -27,11 +28,12 @@ static char decoration_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_BOLD_YELLOW,  /* REF_TAG */
        GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */
        GIT_COLOR_BOLD_CYAN,    /* REF_HEAD */
+       GIT_COLOR_BOLD_BLUE,    /* GRAFTED */
 };
 
 static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
 {
-       if (decorate_use_color)
+       if (want_color(decorate_use_color))
                return decoration_colors[ix];
        return "";
 }
@@ -77,7 +79,7 @@ int parse_decorate_color_config(const char *var, const int ofs, const char *valu
  * for showing the commit sha1, use the same check for --decorate
  */
 #define decorate_get_color_opt(o, ix) \
-       decorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)
+       decorate_get_color((o)->use_color, ix)
 
 static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
 {
@@ -90,16 +92,32 @@ static void add_name_decoration(enum decoration_type type, const char *name, str
 
 static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
 {
-       struct object *obj = parse_object(sha1);
+       struct object *obj;
        enum decoration_type type = DECORATION_NONE;
+
+       if (!prefixcmp(refname, "refs/replace/")) {
+               unsigned char original_sha1[20];
+               if (!read_replace_refs)
+                       return 0;
+               if (get_sha1_hex(refname + 13, original_sha1)) {
+                       warning("invalid replace ref %s", refname);
+                       return 0;
+               }
+               obj = parse_object(original_sha1);
+               if (obj)
+                       add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
+               return 0;
+       }
+
+       obj = parse_object(sha1);
        if (!obj)
                return 0;
 
-       if (!prefixcmp(refname, "refs/heads"))
+       if (!prefixcmp(refname, "refs/heads/"))
                type = DECORATION_REF_LOCAL;
-       else if (!prefixcmp(refname, "refs/remotes"))
+       else if (!prefixcmp(refname, "refs/remotes/"))
                type = DECORATION_REF_REMOTE;
-       else if (!prefixcmp(refname, "refs/tags"))
+       else if (!prefixcmp(refname, "refs/tags/"))
                type = DECORATION_REF_TAG;
        else if (!prefixcmp(refname, "refs/stash"))
                type = DECORATION_REF_STASH;
@@ -118,6 +136,15 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
        return 0;
 }
 
+static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
+{
+       struct commit *commit = lookup_commit(graft->sha1);
+       if (!commit)
+               return 0;
+       add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
+       return 0;
+}
+
 void load_ref_decorations(int flags)
 {
        static int loaded;
@@ -125,6 +152,7 @@ void load_ref_decorations(int flags)
                loaded = 1;
                for_each_ref(add_ref_decoration, &flags);
                head_ref(add_ref_decoration, &flags);
+               for_each_commit_graft(add_graft_decoration, NULL);
        }
 }
 
index db9ba19ddf94fec3a5cfff450b35f5bb7b46c35e..c34a4f148b65cf81f28e2aed6c35e141e175b324 100644 (file)
@@ -66,10 +66,12 @@ static int sha_eq(const unsigned char *a, const unsigned char *b)
 enum rename_type {
        RENAME_NORMAL = 0,
        RENAME_DELETE,
-       RENAME_ONE_FILE_TO_TWO
+       RENAME_ONE_FILE_TO_ONE,
+       RENAME_ONE_FILE_TO_TWO,
+       RENAME_TWO_FILES_TO_ONE
 };
 
-struct rename_df_conflict_info {
+struct rename_conflict_info {
        enum rename_type rename_type;
        struct diff_filepair *pair1;
        struct diff_filepair *pair2;
@@ -77,6 +79,8 @@ struct rename_df_conflict_info {
        const char *branch2;
        struct stage_data *dst_entry1;
        struct stage_data *dst_entry2;
+       struct diff_filespec ren1_other;
+       struct diff_filespec ren2_other;
 };
 
 /*
@@ -88,34 +92,54 @@ struct stage_data {
                unsigned mode;
                unsigned char sha[20];
        } stages[4];
-       struct rename_df_conflict_info *rename_df_conflict_info;
+       struct rename_conflict_info *rename_conflict_info;
        unsigned processed:1;
 };
 
-static inline void setup_rename_df_conflict_info(enum rename_type rename_type,
-                                                struct diff_filepair *pair1,
-                                                struct diff_filepair *pair2,
-                                                const char *branch1,
-                                                const char *branch2,
-                                                struct stage_data *dst_entry1,
-                                                struct stage_data *dst_entry2)
+static inline void setup_rename_conflict_info(enum rename_type rename_type,
+                                             struct diff_filepair *pair1,
+                                             struct diff_filepair *pair2,
+                                             const char *branch1,
+                                             const char *branch2,
+                                             struct stage_data *dst_entry1,
+                                             struct stage_data *dst_entry2,
+                                             struct merge_options *o,
+                                             struct stage_data *src_entry1,
+                                             struct stage_data *src_entry2)
 {
-       struct rename_df_conflict_info *ci = xcalloc(1, sizeof(struct rename_df_conflict_info));
+       struct rename_conflict_info *ci = xcalloc(1, sizeof(struct rename_conflict_info));
        ci->rename_type = rename_type;
        ci->pair1 = pair1;
        ci->branch1 = branch1;
        ci->branch2 = branch2;
 
        ci->dst_entry1 = dst_entry1;
-       dst_entry1->rename_df_conflict_info = ci;
+       dst_entry1->rename_conflict_info = ci;
        dst_entry1->processed = 0;
 
        assert(!pair2 == !dst_entry2);
        if (dst_entry2) {
                ci->dst_entry2 = dst_entry2;
                ci->pair2 = pair2;
-               dst_entry2->rename_df_conflict_info = ci;
-               dst_entry2->processed = 0;
+               dst_entry2->rename_conflict_info = ci;
+       }
+
+       if (rename_type == RENAME_TWO_FILES_TO_ONE) {
+               /*
+                * For each rename, there could have been
+                * modifications on the side of history where that
+                * file was not renamed.
+                */
+               int ostage1 = o->branch1 == branch1 ? 3 : 2;
+               int ostage2 = ostage1 ^ 1;
+
+               ci->ren1_other.path = pair1->one->path;
+               hashcpy(ci->ren1_other.sha1, src_entry1->stages[ostage1].sha);
+               ci->ren1_other.mode = src_entry1->stages[ostage1].mode;
+
+               ci->ren2_other.path = pair2->one->path;
+               hashcpy(ci->ren2_other.sha1, src_entry2->stages[ostage2].sha);
+               ci->ren2_other.mode = src_entry2->stages[ostage2].mode;
        }
 }
 
@@ -230,7 +254,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
                for (i = 0; i < active_nr; i++) {
                        struct cache_entry *ce = active_cache[i];
                        if (ce_stage(ce))
-                               fprintf(stderr, "BUG: %d %.*s", ce_stage(ce),
+                               fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce),
                                        (int)ce_namelen(ce), ce->name);
                }
                die("Bug in merge-recursive.c");
@@ -333,44 +357,90 @@ static struct string_list *get_unmerged(void)
        return unmerged;
 }
 
-static void make_room_for_directories_of_df_conflicts(struct merge_options *o,
-                                                     struct string_list *entries)
+static int string_list_df_name_compare(const void *a, const void *b)
 {
-       /* If there are D/F conflicts, and the paths currently exist
-        * in the working copy as a file, we want to remove them to
-        * make room for the corresponding directory.  Such paths will
-        * later be processed in process_df_entry() at the end.  If
-        * the corresponding directory ends up being removed by the
-        * merge, then the file will be reinstated at that time;
-        * otherwise, if the file is not supposed to be removed by the
-        * merge, the contents of the file will be placed in another
-        * unique filename.
+       const struct string_list_item *one = a;
+       const struct string_list_item *two = b;
+       int onelen = strlen(one->string);
+       int twolen = strlen(two->string);
+       /*
+        * Here we only care that entries for D/F conflicts are
+        * adjacent, in particular with the file of the D/F conflict
+        * appearing before files below the corresponding directory.
+        * The order of the rest of the list is irrelevant for us.
         *
-        * NOTE: This function relies on the fact that entries for a
-        * D/F conflict will appear adjacent in the index, with the
-        * entries for the file appearing before entries for paths
-        * below the corresponding directory.
+        * To achieve this, we sort with df_name_compare and provide
+        * the mode S_IFDIR so that D/F conflicts will sort correctly.
+        * We use the mode S_IFDIR for everything else for simplicity,
+        * since in other cases any changes in their order due to
+        * sorting cause no problems for us.
+        */
+       int cmp = df_name_compare(one->string, onelen, S_IFDIR,
+                                 two->string, twolen, S_IFDIR);
+       /*
+        * Now that 'foo' and 'foo/bar' compare equal, we have to make sure
+        * that 'foo' comes before 'foo/bar'.
         */
+       if (cmp)
+               return cmp;
+       return onelen - twolen;
+}
+
+static void record_df_conflict_files(struct merge_options *o,
+                                    struct string_list *entries)
+{
+       /* If there is a D/F conflict and the file for such a conflict
+        * currently exist in the working tree, we want to allow it to be
+        * removed to make room for the corresponding directory if needed.
+        * The files underneath the directories of such D/F conflicts will
+        * be processed before the corresponding file involved in the D/F
+        * conflict.  If the D/F directory ends up being removed by the
+        * merge, then we won't have to touch the D/F file.  If the D/F
+        * directory needs to be written to the working copy, then the D/F
+        * file will simply be removed (in make_room_for_path()) to make
+        * room for the necessary paths.  Note that if both the directory
+        * and the file need to be present, then the D/F file will be
+        * reinstated with a new unique name at the time it is processed.
+        */
+       struct string_list df_sorted_entries;
        const char *last_file = NULL;
        int last_len = 0;
        int i;
 
+       /*
+        * If we're merging merge-bases, we don't want to bother with
+        * any working directory changes.
+        */
+       if (o->call_depth)
+               return;
+
+       /* Ensure D/F conflicts are adjacent in the entries list. */
+       memset(&df_sorted_entries, 0, sizeof(struct string_list));
        for (i = 0; i < entries->nr; i++) {
-               const char *path = entries->items[i].string;
+               struct string_list_item *next = &entries->items[i];
+               string_list_append(&df_sorted_entries, next->string)->util =
+                                  next->util;
+       }
+       qsort(df_sorted_entries.items, entries->nr, sizeof(*entries->items),
+             string_list_df_name_compare);
+
+       string_list_clear(&o->df_conflict_file_set, 1);
+       for (i = 0; i < df_sorted_entries.nr; i++) {
+               const char *path = df_sorted_entries.items[i].string;
                int len = strlen(path);
-               struct stage_data *e = entries->items[i].util;
+               struct stage_data *e = df_sorted_entries.items[i].util;
 
                /*
                 * Check if last_file & path correspond to a D/F conflict;
                 * i.e. whether path is last_file+'/'+<something>.
-                * If so, remove last_file to make room for path and friends.
+                * If so, record that it's okay to remove last_file to make
+                * room for path and friends if needed.
                 */
                if (last_file &&
                    len > last_len &&
                    memcmp(path, last_file, last_len) == 0 &&
                    path[last_len] == '/') {
-                       output(o, 3, "Removing %s to make room for subdirectory; may re-add later.", last_file);
-                       unlink(last_file);
+                       string_list_insert(&o->df_conflict_file_set, last_file);
                }
 
                /*
@@ -386,6 +456,7 @@ static void make_room_for_directories_of_df_conflicts(struct merge_options *o,
                        last_file = NULL;
                }
        }
+       string_list_clear(&df_sorted_entries, 0);
 }
 
 struct rename {
@@ -461,10 +532,21 @@ static struct string_list *get_renames(struct merge_options *o,
        return renames;
 }
 
-static int update_stages_options(const char *path, struct diff_filespec *o,
-                        struct diff_filespec *a, struct diff_filespec *b,
-                        int clear, int options)
+static int update_stages(const char *path, const struct diff_filespec *o,
+                        const struct diff_filespec *a,
+                        const struct diff_filespec *b)
 {
+
+       /*
+        * NOTE: It is usually a bad idea to call update_stages on a path
+        * before calling update_file on that same path, since it can
+        * sometimes lead to spurious "refusing to lose untracked file..."
+        * messages from update_file (via make_room_for path via
+        * would_lose_untracked).  Instead, reverse the order of the calls
+        * (executing update_file first and then update_stages).
+        */
+       int clear = 1;
+       int options = ADD_CACHE_OK_TO_ADD | ADD_CACHE_SKIP_DFCHECK;
        if (clear)
                if (remove_file_from_cache(path))
                        return -1;
@@ -480,23 +562,11 @@ static int update_stages_options(const char *path, struct diff_filespec *o,
        return 0;
 }
 
-static int update_stages(const char *path, struct diff_filespec *o,
-                        struct diff_filespec *a, struct diff_filespec *b,
-                        int clear)
+static void update_entry(struct stage_data *entry,
+                        struct diff_filespec *o,
+                        struct diff_filespec *a,
+                        struct diff_filespec *b)
 {
-       int options = ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE;
-       return update_stages_options(path, o, a, b, clear, options);
-}
-
-static int update_stages_and_entry(const char *path,
-                                  struct stage_data *entry,
-                                  struct diff_filespec *o,
-                                  struct diff_filespec *a,
-                                  struct diff_filespec *b,
-                                  int clear)
-{
-       int options;
-
        entry->processed = 0;
        entry->stages[1].mode = o->mode;
        entry->stages[2].mode = a->mode;
@@ -504,8 +574,6 @@ static int update_stages_and_entry(const char *path,
        hashcpy(entry->stages[1].sha, o->sha1);
        hashcpy(entry->stages[2].sha, a->sha1);
        hashcpy(entry->stages[3].sha, b->sha1);
-       options = ADD_CACHE_OK_TO_ADD | ADD_CACHE_SKIP_DFCHECK;
-       return update_stages_options(path, o, a, b, clear, options);
 }
 
 static int remove_file(struct merge_options *o, int clean,
@@ -563,7 +631,31 @@ static void flush_buffer(int fd, const char *buf, unsigned long size)
        }
 }
 
-static int would_lose_untracked(const char *path)
+static int dir_in_way(const char *path, int check_working_copy)
+{
+       int pos, pathlen = strlen(path);
+       char *dirpath = xmalloc(pathlen + 2);
+       struct stat st;
+
+       strcpy(dirpath, path);
+       dirpath[pathlen] = '/';
+       dirpath[pathlen+1] = '\0';
+
+       pos = cache_name_pos(dirpath, pathlen+1);
+
+       if (pos < 0)
+               pos = -1 - pos;
+       if (pos < active_nr &&
+           !strncmp(dirpath, active_cache[pos]->name, pathlen+1)) {
+               free(dirpath);
+               return 1;
+       }
+
+       free(dirpath);
+       return check_working_copy && !lstat(path, &st) && S_ISDIR(st.st_mode);
+}
+
+static int was_tracked(const char *path)
 {
        int pos = cache_name_pos(path, strlen(path));
 
@@ -580,18 +672,42 @@ static int would_lose_untracked(const char *path)
                switch (ce_stage(active_cache[pos])) {
                case 0:
                case 2:
-                       return 0;
+                       return 1;
                }
                pos++;
        }
-       return file_exists(path);
+       return 0;
 }
 
-static int make_room_for_path(const char *path)
+static int would_lose_untracked(const char *path)
 {
-       int status;
+       return !was_tracked(path) && file_exists(path);
+}
+
+static int make_room_for_path(struct merge_options *o, const char *path)
+{
+       int status, i;
        const char *msg = "failed to create path '%s'%s";
 
+       /* Unlink any D/F conflict files that are in the way */
+       for (i = 0; i < o->df_conflict_file_set.nr; i++) {
+               const char *df_path = o->df_conflict_file_set.items[i].string;
+               size_t pathlen = strlen(path);
+               size_t df_pathlen = strlen(df_path);
+               if (df_pathlen < pathlen &&
+                   path[df_pathlen] == '/' &&
+                   strncmp(path, df_path, df_pathlen) == 0) {
+                       output(o, 3,
+                              "Removing %s to make room for subdirectory\n",
+                              df_path);
+                       unlink(df_path);
+                       unsorted_string_list_delete_item(&o->df_conflict_file_set,
+                                                        i, 0);
+                       break;
+               }
+       }
+
+       /* Make sure leading directories are created */
        status = safe_create_leading_directories_const(path);
        if (status) {
                if (status == -3) {
@@ -659,7 +775,7 @@ static void update_file_flags(struct merge_options *o,
                        }
                }
 
-               if (make_room_for_path(path) < 0) {
+               if (make_room_for_path(o, path) < 0) {
                        update_wd = 0;
                        free(buf);
                        goto update_index;
@@ -712,9 +828,9 @@ struct merge_file_info {
 
 static int merge_3way(struct merge_options *o,
                      mmbuffer_t *result_buf,
-                     struct diff_filespec *one,
-                     struct diff_filespec *a,
-                     struct diff_filespec *b,
+                     const struct diff_filespec *one,
+                     const struct diff_filespec *a,
+                     const struct diff_filespec *b,
                      const char *branch1,
                      const char *branch2)
 {
@@ -771,12 +887,12 @@ static int merge_3way(struct merge_options *o,
        return merge_status;
 }
 
-static struct merge_file_info merge_file(struct merge_options *o,
-                                        struct diff_filespec *one,
-                                        struct diff_filespec *a,
-                                        struct diff_filespec *b,
-                                        const char *branch1,
-                                        const char *branch2)
+static struct merge_file_info merge_file_1(struct merge_options *o,
+                                          const struct diff_filespec *one,
+                                          const struct diff_filespec *a,
+                                          const struct diff_filespec *b,
+                                          const char *branch1,
+                                          const char *branch2)
 {
        struct merge_file_info result;
        result.merge = 0;
@@ -845,94 +961,303 @@ static struct merge_file_info merge_file(struct merge_options *o,
        return result;
 }
 
+static struct merge_file_info
+merge_file_special_markers(struct merge_options *o,
+                          const struct diff_filespec *one,
+                          const struct diff_filespec *a,
+                          const struct diff_filespec *b,
+                          const char *branch1,
+                          const char *filename1,
+                          const char *branch2,
+                          const char *filename2)
+{
+       char *side1 = NULL;
+       char *side2 = NULL;
+       struct merge_file_info mfi;
+
+       if (filename1) {
+               side1 = xmalloc(strlen(branch1) + strlen(filename1) + 2);
+               sprintf(side1, "%s:%s", branch1, filename1);
+       }
+       if (filename2) {
+               side2 = xmalloc(strlen(branch2) + strlen(filename2) + 2);
+               sprintf(side2, "%s:%s", branch2, filename2);
+       }
+
+       mfi = merge_file_1(o, one, a, b,
+                          side1 ? side1 : branch1, side2 ? side2 : branch2);
+       free(side1);
+       free(side2);
+       return mfi;
+}
+
+static struct merge_file_info merge_file(struct merge_options *o,
+                                        const char *path,
+                                        const unsigned char *o_sha, int o_mode,
+                                        const unsigned char *a_sha, int a_mode,
+                                        const unsigned char *b_sha, int b_mode,
+                                        const char *branch1,
+                                        const char *branch2)
+{
+       struct diff_filespec one, a, b;
+
+       one.path = a.path = b.path = (char *)path;
+       hashcpy(one.sha1, o_sha);
+       one.mode = o_mode;
+       hashcpy(a.sha1, a_sha);
+       a.mode = a_mode;
+       hashcpy(b.sha1, b_sha);
+       b.mode = b_mode;
+       return merge_file_1(o, &one, &a, &b, branch1, branch2);
+}
+
+static void handle_change_delete(struct merge_options *o,
+                                const char *path,
+                                const unsigned char *o_sha, int o_mode,
+                                const unsigned char *a_sha, int a_mode,
+                                const unsigned char *b_sha, int b_mode,
+                                const char *change, const char *change_past)
+{
+       char *renamed = NULL;
+       if (dir_in_way(path, !o->call_depth)) {
+               renamed = unique_path(o, path, a_sha ? o->branch1 : o->branch2);
+       }
+
+       if (o->call_depth) {
+               /*
+                * We cannot arbitrarily accept either a_sha or b_sha as
+                * correct; since there is no true "middle point" between
+                * them, simply reuse the base version for virtual merge base.
+                */
+               remove_file_from_cache(path);
+               update_file(o, 0, o_sha, o_mode, renamed ? renamed : path);
+       } else if (!a_sha) {
+               output(o, 1, "CONFLICT (%s/delete): %s deleted in %s "
+                      "and %s in %s. Version %s of %s left in tree%s%s.",
+                      change, path, o->branch1,
+                      change_past, o->branch2, o->branch2, path,
+                      NULL == renamed ? "" : " at ",
+                      NULL == renamed ? "" : renamed);
+               update_file(o, 0, b_sha, b_mode, renamed ? renamed : path);
+       } else {
+               output(o, 1, "CONFLICT (%s/delete): %s deleted in %s "
+                      "and %s in %s. Version %s of %s left in tree%s%s.",
+                      change, path, o->branch2,
+                      change_past, o->branch1, o->branch1, path,
+                      NULL == renamed ? "" : " at ",
+                      NULL == renamed ? "" : renamed);
+               if (renamed)
+                       update_file(o, 0, a_sha, a_mode, renamed);
+               /*
+                * No need to call update_file() on path when !renamed, since
+                * that would needlessly touch path.  We could call
+                * update_file_flags() with update_cache=0 and update_wd=0,
+                * but that's a no-op.
+                */
+       }
+       free(renamed);
+}
+
 static void conflict_rename_delete(struct merge_options *o,
                                   struct diff_filepair *pair,
                                   const char *rename_branch,
                                   const char *other_branch)
 {
-       char *dest_name = pair->two->path;
-       int df_conflict = 0;
-       struct stat st;
+       const struct diff_filespec *orig = pair->one;
+       const struct diff_filespec *dest = pair->two;
+       const unsigned char *a_sha = NULL;
+       const unsigned char *b_sha = NULL;
+       int a_mode = 0;
+       int b_mode = 0;
+
+       if (rename_branch == o->branch1) {
+               a_sha = dest->sha1;
+               a_mode = dest->mode;
+       } else {
+               b_sha = dest->sha1;
+               b_mode = dest->mode;
+       }
 
-       output(o, 1, "CONFLICT (rename/delete): Rename %s->%s in %s "
-              "and deleted in %s",
-              pair->one->path, pair->two->path, rename_branch,
-              other_branch);
-       if (!o->call_depth)
-               update_stages(dest_name, NULL,
-                             rename_branch == o->branch1 ? pair->two : NULL,
-                             rename_branch == o->branch1 ? NULL : pair->two,
-                             1);
-       if (lstat(dest_name, &st) == 0 && S_ISDIR(st.st_mode)) {
-               dest_name = unique_path(o, dest_name, rename_branch);
-               df_conflict = 1;
+       handle_change_delete(o,
+                            o->call_depth ? orig->path : dest->path,
+                            orig->sha1, orig->mode,
+                            a_sha, a_mode,
+                            b_sha, b_mode,
+                            "rename", "renamed");
+
+       if (o->call_depth) {
+               remove_file_from_cache(dest->path);
+       } else {
+               update_stages(dest->path, NULL,
+                             rename_branch == o->branch1 ? dest : NULL,
+                             rename_branch == o->branch1 ? NULL : dest);
        }
-       update_file(o, 0, pair->two->sha1, pair->two->mode, dest_name);
-       if (df_conflict)
-               free(dest_name);
+
 }
 
-static void conflict_rename_rename_1to2(struct merge_options *o,
-                                       struct diff_filepair *pair1,
-                                       const char *branch1,
-                                       struct diff_filepair *pair2,
-                                       const char *branch2)
+static struct diff_filespec *filespec_from_entry(struct diff_filespec *target,
+                                                struct stage_data *entry,
+                                                int stage)
 {
-       /* One file was renamed in both branches, but to different names. */
-       char *del[2];
-       int delp = 0;
-       const char *ren1_dst = pair1->two->path;
-       const char *ren2_dst = pair2->two->path;
-       const char *dst_name1 = ren1_dst;
-       const char *dst_name2 = ren2_dst;
-       struct stat st;
-       if (lstat(ren1_dst, &st) == 0 && S_ISDIR(st.st_mode)) {
-               dst_name1 = del[delp++] = unique_path(o, ren1_dst, branch1);
-               output(o, 1, "%s is a directory in %s adding as %s instead",
-                      ren1_dst, branch2, dst_name1);
+       unsigned char *sha = entry->stages[stage].sha;
+       unsigned mode = entry->stages[stage].mode;
+       if (mode == 0 || is_null_sha1(sha))
+               return NULL;
+       hashcpy(target->sha1, sha);
+       target->mode = mode;
+       return target;
+}
+
+static void handle_file(struct merge_options *o,
+                       struct diff_filespec *rename,
+                       int stage,
+                       struct rename_conflict_info *ci)
+{
+       char *dst_name = rename->path;
+       struct stage_data *dst_entry;
+       const char *cur_branch, *other_branch;
+       struct diff_filespec other;
+       struct diff_filespec *add;
+
+       if (stage == 2) {
+               dst_entry = ci->dst_entry1;
+               cur_branch = ci->branch1;
+               other_branch = ci->branch2;
+       } else {
+               dst_entry = ci->dst_entry2;
+               cur_branch = ci->branch2;
+               other_branch = ci->branch1;
        }
-       if (lstat(ren2_dst, &st) == 0 && S_ISDIR(st.st_mode)) {
-               dst_name2 = del[delp++] = unique_path(o, ren2_dst, branch2);
-               output(o, 1, "%s is a directory in %s adding as %s instead",
-                      ren2_dst, branch1, dst_name2);
+
+       add = filespec_from_entry(&other, dst_entry, stage ^ 1);
+       if (add) {
+               char *add_name = unique_path(o, rename->path, other_branch);
+               update_file(o, 0, add->sha1, add->mode, add_name);
+
+               remove_file(o, 0, rename->path, 0);
+               dst_name = unique_path(o, rename->path, cur_branch);
+       } else {
+               if (dir_in_way(rename->path, !o->call_depth)) {
+                       dst_name = unique_path(o, rename->path, cur_branch);
+                       output(o, 1, "%s is a directory in %s adding as %s instead",
+                              rename->path, other_branch, dst_name);
+               }
        }
+       update_file(o, 0, rename->sha1, rename->mode, dst_name);
+       if (stage == 2)
+               update_stages(rename->path, NULL, rename, add);
+       else
+               update_stages(rename->path, NULL, add, rename);
+
+       if (dst_name != rename->path)
+               free(dst_name);
+}
+
+static void conflict_rename_rename_1to2(struct merge_options *o,
+                                       struct rename_conflict_info *ci)
+{
+       /* One file was renamed in both branches, but to different names. */
+       struct diff_filespec *one = ci->pair1->one;
+       struct diff_filespec *a = ci->pair1->two;
+       struct diff_filespec *b = ci->pair2->two;
+
+       output(o, 1, "CONFLICT (rename/rename): "
+              "Rename \"%s\"->\"%s\" in branch \"%s\" "
+              "rename \"%s\"->\"%s\" in \"%s\"%s",
+              one->path, a->path, ci->branch1,
+              one->path, b->path, ci->branch2,
+              o->call_depth ? " (left unresolved)" : "");
        if (o->call_depth) {
-               remove_file_from_cache(dst_name1);
-               remove_file_from_cache(dst_name2);
+               struct merge_file_info mfi;
+               struct diff_filespec other;
+               struct diff_filespec *add;
+               mfi = merge_file(o, one->path,
+                                one->sha1, one->mode,
+                                a->sha1, a->mode,
+                                b->sha1, b->mode,
+                                ci->branch1, ci->branch2);
                /*
-                * Uncomment to leave the conflicting names in the resulting tree
-                *
-                * update_file(o, 0, pair1->two->sha1, pair1->two->mode, dst_name1);
-                * update_file(o, 0, pair2->two->sha1, pair2->two->mode, dst_name2);
+                * FIXME: For rename/add-source conflicts (if we could detect
+                * such), this is wrong.  We should instead find a unique
+                * pathname and then either rename the add-source file to that
+                * unique path, or use that unique path instead of src here.
                 */
-       } else {
-               update_stages(ren1_dst, NULL, pair1->two, NULL, 1);
-               update_stages(ren2_dst, NULL, NULL, pair2->two, 1);
+               update_file(o, 0, mfi.sha, mfi.mode, one->path);
 
-               update_file(o, 0, pair1->two->sha1, pair1->two->mode, dst_name1);
-               update_file(o, 0, pair2->two->sha1, pair2->two->mode, dst_name2);
+               /*
+                * Above, we put the merged content at the merge-base's
+                * path.  Now we usually need to delete both a->path and
+                * b->path.  However, the rename on each side of the merge
+                * could also be involved in a rename/add conflict.  In
+                * such cases, we should keep the added file around,
+                * resolving the conflict at that path in its favor.
+                */
+               add = filespec_from_entry(&other, ci->dst_entry1, 2 ^ 1);
+               if (add)
+                       update_file(o, 0, add->sha1, add->mode, a->path);
+               else
+                       remove_file_from_cache(a->path);
+               add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);
+               if (add)
+                       update_file(o, 0, add->sha1, add->mode, b->path);
+               else
+                       remove_file_from_cache(b->path);
+       } else {
+               handle_file(o, a, 2, ci);
+               handle_file(o, b, 3, ci);
        }
-       while (delp--)
-               free(del[delp]);
 }
 
 static void conflict_rename_rename_2to1(struct merge_options *o,
-                                       struct rename *ren1,
-                                       const char *branch1,
-                                       struct rename *ren2,
-                                       const char *branch2)
+                                       struct rename_conflict_info *ci)
 {
-       /* Two files were renamed to the same thing. */
-       char *new_path1 = unique_path(o, ren1->pair->two->path, branch1);
-       char *new_path2 = unique_path(o, ren2->pair->two->path, branch2);
-       output(o, 1, "Renaming %s to %s and %s to %s instead",
-              ren1->pair->one->path, new_path1,
-              ren2->pair->one->path, new_path2);
-       remove_file(o, 0, ren1->pair->two->path, 0);
-       update_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path1);
-       update_file(o, 0, ren2->pair->two->sha1, ren2->pair->two->mode, new_path2);
-       free(new_path2);
-       free(new_path1);
+       /* Two files, a & b, were renamed to the same thing, c. */
+       struct diff_filespec *a = ci->pair1->one;
+       struct diff_filespec *b = ci->pair2->one;
+       struct diff_filespec *c1 = ci->pair1->two;
+       struct diff_filespec *c2 = ci->pair2->two;
+       char *path = c1->path; /* == c2->path */
+       struct merge_file_info mfi_c1;
+       struct merge_file_info mfi_c2;
+
+       output(o, 1, "CONFLICT (rename/rename): "
+              "Rename %s->%s in %s. "
+              "Rename %s->%s in %s",
+              a->path, c1->path, ci->branch1,
+              b->path, c2->path, ci->branch2);
+
+       remove_file(o, 1, a->path, would_lose_untracked(a->path));
+       remove_file(o, 1, b->path, would_lose_untracked(b->path));
+
+       mfi_c1 = merge_file_special_markers(o, a, c1, &ci->ren1_other,
+                                           o->branch1, c1->path,
+                                           o->branch2, ci->ren1_other.path);
+       mfi_c2 = merge_file_special_markers(o, b, &ci->ren2_other, c2,
+                                           o->branch1, ci->ren2_other.path,
+                                           o->branch2, c2->path);
+
+       if (o->call_depth) {
+               /*
+                * If mfi_c1.clean && mfi_c2.clean, then it might make
+                * sense to do a two-way merge of those results.  But, I
+                * think in all cases, it makes sense to have the virtual
+                * merge base just undo the renames; they can be detected
+                * again later for the non-recursive merge.
+                */
+               remove_file(o, 0, path, 0);
+               update_file(o, 0, mfi_c1.sha, mfi_c1.mode, a->path);
+               update_file(o, 0, mfi_c2.sha, mfi_c2.mode, b->path);
+       } else {
+               char *new_path1 = unique_path(o, path, ci->branch1);
+               char *new_path2 = unique_path(o, path, ci->branch2);
+               output(o, 1, "Renaming %s to %s and %s to %s instead",
+                      a->path, new_path1, b->path, new_path2);
+               remove_file(o, 0, path, 0);
+               update_file(o, 0, mfi_c1.sha, mfi_c1.mode, new_path1);
+               update_file(o, 0, mfi_c2.sha, mfi_c2.mode, new_path2);
+               free(new_path2);
+               free(new_path1);
+       }
 }
 
 static int process_renames(struct merge_options *o,
@@ -947,12 +1272,12 @@ static int process_renames(struct merge_options *o,
        for (i = 0; i < a_renames->nr; i++) {
                sre = a_renames->items[i].util;
                string_list_insert(&a_by_dst, sre->pair->two->path)->util
-                       = sre->dst_entry;
+                       = (void *)sre;
        }
        for (i = 0; i < b_renames->nr; i++) {
                sre = b_renames->items[i].util;
                string_list_insert(&b_by_dst, sre->pair->two->path)->util
-                       = sre->dst_entry;
+                       = (void *)sre;
        }
 
        for (i = 0, j = 0; i < a_renames->nr || j < b_renames->nr;) {
@@ -960,6 +1285,7 @@ static int process_renames(struct merge_options *o,
                struct rename *ren1 = NULL, *ren2 = NULL;
                const char *branch1, *branch2;
                const char *ren1_src, *ren1_dst;
+               struct string_list_item *lookup;
 
                if (i >= a_renames->nr) {
                        ren2 = b_renames->items[j++].util;
@@ -991,44 +1317,82 @@ static int process_renames(struct merge_options *o,
                        ren1 = tmp;
                }
 
-               ren1->dst_entry->processed = 1;
-               ren1->src_entry->processed = 1;
-
                if (ren1->processed)
                        continue;
                ren1->processed = 1;
+               ren1->dst_entry->processed = 1;
+               /* BUG: We should only mark src_entry as processed if we
+                * are not dealing with a rename + add-source case.
+                */
+               ren1->src_entry->processed = 1;
 
                ren1_src = ren1->pair->one->path;
                ren1_dst = ren1->pair->two->path;
 
                if (ren2) {
+                       /* One file renamed on both sides */
                        const char *ren2_src = ren2->pair->one->path;
                        const char *ren2_dst = ren2->pair->two->path;
-                       /* Renamed in 1 and renamed in 2 */
+                       enum rename_type rename_type;
                        if (strcmp(ren1_src, ren2_src) != 0)
-                               die("ren1.src != ren2.src");
+                               die("ren1_src != ren2_src");
                        ren2->dst_entry->processed = 1;
                        ren2->processed = 1;
                        if (strcmp(ren1_dst, ren2_dst) != 0) {
-                               setup_rename_df_conflict_info(RENAME_ONE_FILE_TO_TWO,
-                                                             ren1->pair,
-                                                             ren2->pair,
-                                                             branch1,
-                                                             branch2,
-                                                             ren1->dst_entry,
-                                                             ren2->dst_entry);
+                               rename_type = RENAME_ONE_FILE_TO_TWO;
+                               clean_merge = 0;
                        } else {
+                               rename_type = RENAME_ONE_FILE_TO_ONE;
+                               /* BUG: We should only remove ren1_src in
+                                * the base stage (think of rename +
+                                * add-source cases).
+                                */
                                remove_file(o, 1, ren1_src, 1);
-                               update_stages_and_entry(ren1_dst,
-                                                       ren1->dst_entry,
-                                                       ren1->pair->one,
-                                                       ren1->pair->two,
-                                                       ren2->pair->two,
-                                                       1 /* clear */);
+                               update_entry(ren1->dst_entry,
+                                            ren1->pair->one,
+                                            ren1->pair->two,
+                                            ren2->pair->two);
                        }
+                       setup_rename_conflict_info(rename_type,
+                                                  ren1->pair,
+                                                  ren2->pair,
+                                                  branch1,
+                                                  branch2,
+                                                  ren1->dst_entry,
+                                                  ren2->dst_entry,
+                                                  o,
+                                                  NULL,
+                                                  NULL);
+               } else if ((lookup = string_list_lookup(renames2Dst, ren1_dst))) {
+                       /* Two different files renamed to the same thing */
+                       char *ren2_dst;
+                       ren2 = lookup->util;
+                       ren2_dst = ren2->pair->two->path;
+                       if (strcmp(ren1_dst, ren2_dst) != 0)
+                               die("ren1_dst != ren2_dst");
+
+                       clean_merge = 0;
+                       ren2->processed = 1;
+                       /*
+                        * BUG: We should only mark src_entry as processed
+                        * if we are not dealing with a rename + add-source
+                        * case.
+                        */
+                       ren2->src_entry->processed = 1;
+
+                       setup_rename_conflict_info(RENAME_TWO_FILES_TO_ONE,
+                                                  ren1->pair,
+                                                  ren2->pair,
+                                                  branch1,
+                                                  branch2,
+                                                  ren1->dst_entry,
+                                                  ren2->dst_entry,
+                                                  o,
+                                                  ren1->src_entry,
+                                                  ren2->src_entry);
+
                } else {
                        /* Renamed in 1, maybe changed in 2 */
-                       struct string_list_item *item;
                        /* we only use sha1 and mode of these */
                        struct diff_filespec src_other, dst_other;
                        int try_merge;
@@ -1042,7 +1406,12 @@ static int process_renames(struct merge_options *o,
                        int renamed_stage = a_renames == renames1 ? 2 : 3;
                        int other_stage =   a_renames == renames1 ? 3 : 2;
 
-                       remove_file(o, 1, ren1_src, o->call_depth || renamed_stage == 2);
+                       /* BUG: We should only remove ren1_src in the base
+                        * stage and in other_stage (think of rename +
+                        * add-source case).
+                        */
+                       remove_file(o, 1, ren1_src,
+                                   renamed_stage == 2 || !was_tracked(ren1_src));
 
                        hashcpy(src_other.sha1, ren1->src_entry->stages[other_stage].sha);
                        src_other.mode = ren1->src_entry->stages[other_stage].mode;
@@ -1051,27 +1420,33 @@ static int process_renames(struct merge_options *o,
                        try_merge = 0;
 
                        if (sha_eq(src_other.sha1, null_sha1)) {
-                               if (string_list_has_string(&o->current_directory_set, ren1_dst)) {
-                                       ren1->dst_entry->processed = 0;
-                                       setup_rename_df_conflict_info(RENAME_DELETE,
-                                                                     ren1->pair,
-                                                                     NULL,
-                                                                     branch1,
-                                                                     branch2,
-                                                                     ren1->dst_entry,
-                                                                     NULL);
-                               } else {
-                                       clean_merge = 0;
-                                       conflict_rename_delete(o, ren1->pair, branch1, branch2);
-                               }
+                               setup_rename_conflict_info(RENAME_DELETE,
+                                                          ren1->pair,
+                                                          NULL,
+                                                          branch1,
+                                                          branch2,
+                                                          ren1->dst_entry,
+                                                          NULL,
+                                                          o,
+                                                          NULL,
+                                                          NULL);
                        } else if ((dst_other.mode == ren1->pair->two->mode) &&
                                   sha_eq(dst_other.sha1, ren1->pair->two->sha1)) {
-                               /* Added file on the other side
-                                  identical to the file being
-                                  renamed: clean merge */
-                               update_file(o, 1, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);
+                               /*
+                                * Added file on the other side identical to
+                                * the file being renamed: clean merge.
+                                * Also, there is no need to overwrite the
+                                * file already in the working copy, so call
+                                * update_file_flags() instead of
+                                * update_file().
+                                */
+                               update_file_flags(o,
+                                                 ren1->pair->two->sha1,
+                                                 ren1->pair->two->mode,
+                                                 ren1_dst,
+                                                 1, /* update_cache */
+                                                 0  /* update_wd    */);
                        } else if (!sha_eq(dst_other.sha1, null_sha1)) {
-                               const char *new_path;
                                clean_merge = 0;
                                try_merge = 1;
                                output(o, 1, "CONFLICT (rename/add): Rename %s->%s in %s. "
@@ -1080,40 +1455,19 @@ static int process_renames(struct merge_options *o,
                                       ren1_dst, branch2);
                                if (o->call_depth) {
                                        struct merge_file_info mfi;
-                                       struct diff_filespec one, a, b;
-
-                                       one.path = a.path = b.path =
-                                               (char *)ren1_dst;
-                                       hashcpy(one.sha1, null_sha1);
-                                       one.mode = 0;
-                                       hashcpy(a.sha1, ren1->pair->two->sha1);
-                                       a.mode = ren1->pair->two->mode;
-                                       hashcpy(b.sha1, dst_other.sha1);
-                                       b.mode = dst_other.mode;
-                                       mfi = merge_file(o, &one, &a, &b,
-                                                        branch1,
-                                                        branch2);
+                                       mfi = merge_file(o, ren1_dst, null_sha1, 0,
+                                                        ren1->pair->two->sha1, ren1->pair->two->mode,
+                                                        dst_other.sha1, dst_other.mode,
+                                                        branch1, branch2);
                                        output(o, 1, "Adding merged %s", ren1_dst);
-                                       update_file(o, 0,
-                                                   mfi.sha,
-                                                   mfi.mode,
-                                                   ren1_dst);
+                                       update_file(o, 0, mfi.sha, mfi.mode, ren1_dst);
                                        try_merge = 0;
                                } else {
-                                       new_path = unique_path(o, ren1_dst, branch2);
+                                       char *new_path = unique_path(o, ren1_dst, branch2);
                                        output(o, 1, "Adding as %s instead", new_path);
                                        update_file(o, 0, dst_other.sha1, dst_other.mode, new_path);
+                                       free(new_path);
                                }
-                       } else if ((item = string_list_lookup(renames2Dst, ren1_dst))) {
-                               ren2 = item->util;
-                               clean_merge = 0;
-                               ren2->processed = 1;
-                               output(o, 1, "CONFLICT (rename/rename): "
-                                      "Rename %s->%s in %s. "
-                                      "Rename %s->%s in %s",
-                                      ren1_src, ren1_dst, branch1,
-                                      ren2->pair->one->path, ren2->pair->two->path, branch2);
-                               conflict_rename_rename_2to1(o, ren1, branch1, ren2, branch2);
                        } else
                                try_merge = 1;
 
@@ -1129,16 +1483,17 @@ static int process_renames(struct merge_options *o,
                                        b = ren1->pair->two;
                                        a = &src_other;
                                }
-                               update_stages_and_entry(ren1_dst, ren1->dst_entry, one, a, b, 1);
-                               if (string_list_has_string(&o->current_directory_set, ren1_dst)) {
-                                       setup_rename_df_conflict_info(RENAME_NORMAL,
-                                                                     ren1->pair,
-                                                                     NULL,
-                                                                     branch1,
-                                                                     NULL,
-                                                                     ren1->dst_entry,
-                                                                     NULL);
-                               }
+                               update_entry(ren1->dst_entry, one, a, b);
+                               setup_rename_conflict_info(RENAME_NORMAL,
+                                                          ren1->pair,
+                                                          NULL,
+                                                          branch1,
+                                                          NULL,
+                                                          ren1->dst_entry,
+                                                          NULL,
+                                                          o,
+                                                          NULL,
+                                                          NULL);
                        }
                }
        }
@@ -1200,29 +1555,18 @@ error_return:
        return ret;
 }
 
-static void handle_delete_modify(struct merge_options *o,
+static void handle_modify_delete(struct merge_options *o,
                                 const char *path,
-                                const char *new_path,
+                                unsigned char *o_sha, int o_mode,
                                 unsigned char *a_sha, int a_mode,
                                 unsigned char *b_sha, int b_mode)
 {
-       if (!a_sha) {
-               output(o, 1, "CONFLICT (delete/modify): %s deleted in %s "
-                      "and modified in %s. Version %s of %s left in tree%s%s.",
-                      path, o->branch1,
-                      o->branch2, o->branch2, path,
-                      path == new_path ? "" : " at ",
-                      path == new_path ? "" : new_path);
-               update_file(o, 0, b_sha, b_mode, new_path);
-       } else {
-               output(o, 1, "CONFLICT (delete/modify): %s deleted in %s "
-                      "and modified in %s. Version %s of %s left in tree%s%s.",
-                      path, o->branch2,
-                      o->branch1, o->branch1, path,
-                      path == new_path ? "" : " at ",
-                      path == new_path ? "" : new_path);
-               update_file(o, 0, a_sha, a_mode, new_path);
-       }
+       handle_change_delete(o,
+                            path,
+                            o_sha, o_mode,
+                            a_sha, a_mode,
+                            b_sha, b_mode,
+                            "modify", "modified");
 }
 
 static int merge_content(struct merge_options *o,
@@ -1230,12 +1574,12 @@ static int merge_content(struct merge_options *o,
                         unsigned char *o_sha, int o_mode,
                         unsigned char *a_sha, int a_mode,
                         unsigned char *b_sha, int b_mode,
-                        const char *df_rename_conflict_branch)
+                        struct rename_conflict_info *rename_conflict_info)
 {
        const char *reason = "content";
+       const char *path1 = NULL, *path2 = NULL;
        struct merge_file_info mfi;
        struct diff_filespec one, a, b;
-       struct stat st;
        unsigned df_conflict_remains = 0;
 
        if (!o_sha) {
@@ -1250,16 +1594,43 @@ static int merge_content(struct merge_options *o,
        hashcpy(b.sha1, b_sha);
        b.mode = b_mode;
 
-       mfi = merge_file(o, &one, &a, &b, o->branch1, o->branch2);
-       if (df_rename_conflict_branch &&
-           lstat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
-               df_conflict_remains = 1;
+       if (rename_conflict_info) {
+               struct diff_filepair *pair1 = rename_conflict_info->pair1;
+
+               path1 = (o->branch1 == rename_conflict_info->branch1) ?
+                       pair1->two->path : pair1->one->path;
+               /* If rename_conflict_info->pair2 != NULL, we are in
+                * RENAME_ONE_FILE_TO_ONE case.  Otherwise, we have a
+                * normal rename.
+                */
+               path2 = (rename_conflict_info->pair2 ||
+                        o->branch2 == rename_conflict_info->branch1) ?
+                       pair1->two->path : pair1->one->path;
+
+               if (dir_in_way(path, !o->call_depth))
+                       df_conflict_remains = 1;
        }
+       mfi = merge_file_special_markers(o, &one, &a, &b,
+                                        o->branch1, path1,
+                                        o->branch2, path2);
 
        if (mfi.clean && !df_conflict_remains &&
-           sha_eq(mfi.sha, a_sha) && mfi.mode == a.mode)
+           sha_eq(mfi.sha, a_sha) && mfi.mode == a_mode) {
+               int path_renamed_outside_HEAD;
                output(o, 3, "Skipped %s (merged same as existing)", path);
-       else
+               /*
+                * The content merge resulted in the same file contents we
+                * already had.  We can return early if those file contents
+                * are recorded at the correct path (which may not be true
+                * if the merge involves a rename).
+                */
+               path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
+               if (!path_renamed_outside_HEAD) {
+                       add_cacheinfo(mfi.mode, mfi.sha, path,
+                                     0, (!o->call_depth), 0);
+                       return mfi.clean;
+               }
+       } else
                output(o, 2, "Auto-merging %s", path);
 
        if (!mfi.clean) {
@@ -1267,16 +1638,34 @@ static int merge_content(struct merge_options *o,
                        reason = "submodule";
                output(o, 1, "CONFLICT (%s): Merge conflict in %s",
                                reason, path);
+               if (rename_conflict_info && !df_conflict_remains)
+                       update_stages(path, &one, &a, &b);
        }
 
        if (df_conflict_remains) {
-               const char *new_path;
-               update_file_flags(o, mfi.sha, mfi.mode, path,
-                                 o->call_depth || mfi.clean, 0);
-               new_path = unique_path(o, path, df_rename_conflict_branch);
-               mfi.clean = 0;
+               char *new_path;
+               if (o->call_depth) {
+                       remove_file_from_cache(path);
+               } else {
+                       if (!mfi.clean)
+                               update_stages(path, &one, &a, &b);
+                       else {
+                               int file_from_stage2 = was_tracked(path);
+                               struct diff_filespec merged;
+                               hashcpy(merged.sha1, mfi.sha);
+                               merged.mode = mfi.mode;
+
+                               update_stages(path, NULL,
+                                             file_from_stage2 ? &merged : NULL,
+                                             file_from_stage2 ? NULL : &merged);
+                       }
+
+               }
+               new_path = unique_path(o, path, rename_conflict_info->branch1);
                output(o, 1, "Adding as %s instead", new_path);
-               update_file_flags(o, mfi.sha, mfi.mode, new_path, 0, 1);
+               update_file(o, 0, mfi.sha, mfi.mode, new_path);
+               free(new_path);
+               mfi.clean = 0;
        } else {
                update_file(o, mfi.clean, mfi.sha, mfi.mode, path);
        }
@@ -1301,104 +1690,15 @@ static int process_entry(struct merge_options *o,
        unsigned char *a_sha = stage_sha(entry->stages[2].sha, a_mode);
        unsigned char *b_sha = stage_sha(entry->stages[3].sha, b_mode);
 
-       if (entry->rename_df_conflict_info)
-               return 1; /* Such cases are handled elsewhere. */
-
-       entry->processed = 1;
-       if (o_sha && (!a_sha || !b_sha)) {
-               /* Case A: Deleted in one */
-               if ((!a_sha && !b_sha) ||
-                   (!b_sha && blob_unchanged(o_sha, a_sha, normalize, path)) ||
-                   (!a_sha && blob_unchanged(o_sha, b_sha, normalize, path))) {
-                       /* Deleted in both or deleted in one and
-                        * unchanged in the other */
-                       if (a_sha)
-                               output(o, 2, "Removing %s", path);
-                       /* do not touch working file if it did not exist */
-                       remove_file(o, 1, path, !a_sha);
-               } else if (string_list_has_string(&o->current_directory_set,
-                                                 path)) {
-                       entry->processed = 0;
-                       return 1; /* Assume clean until processed */
-               } else {
-                       /* Deleted in one and changed in the other */
-                       clean_merge = 0;
-                       handle_delete_modify(o, path, path,
-                                            a_sha, a_mode, b_sha, b_mode);
-               }
-
-       } else if ((!o_sha && a_sha && !b_sha) ||
-                  (!o_sha && !a_sha && b_sha)) {
-               /* Case B: Added in one. */
-               unsigned mode;
-               const unsigned char *sha;
-
-               if (a_sha) {
-                       mode = a_mode;
-                       sha = a_sha;
-               } else {
-                       mode = b_mode;
-                       sha = b_sha;
-               }
-               if (string_list_has_string(&o->current_directory_set, path)) {
-                       /* Handle D->F conflicts after all subfiles */
-                       entry->processed = 0;
-                       return 1; /* Assume clean until processed */
-               } else {
-                       output(o, 2, "Adding %s", path);
-                       update_file(o, 1, sha, mode, path);
-               }
-       } else if (a_sha && b_sha) {
-               /* Case C: Added in both (check for same permissions) and */
-               /* case D: Modified in both, but differently. */
-               clean_merge = merge_content(o, path,
-                                           o_sha, o_mode, a_sha, a_mode, b_sha, b_mode,
-                                           NULL);
-       } else if (!o_sha && !a_sha && !b_sha) {
-               /*
-                * this entry was deleted altogether. a_mode == 0 means
-                * we had that path and want to actively remove it.
-                */
-               remove_file(o, 1, path, !a_mode);
-       } else
-               die("Fatal merge failure, shouldn't happen.");
-
-       return clean_merge;
-}
-
-/*
- * Per entry merge function for D/F (and/or rename) conflicts.  In the
- * cases we can cleanly resolve D/F conflicts, process_entry() can
- * clean out all the files below the directory for us.  All D/F
- * conflict cases must be handled here at the end to make sure any
- * directories that can be cleaned out, are.
- *
- * Some rename conflicts may also be handled here that don't necessarily
- * involve D/F conflicts, since the code to handle them is generic enough
- * to handle those rename conflicts with or without D/F conflicts also
- * being involved.
- */
-static int process_df_entry(struct merge_options *o,
-                           const char *path, struct stage_data *entry)
-{
-       int clean_merge = 1;
-       unsigned o_mode = entry->stages[1].mode;
-       unsigned a_mode = entry->stages[2].mode;
-       unsigned b_mode = entry->stages[3].mode;
-       unsigned char *o_sha = stage_sha(entry->stages[1].sha, o_mode);
-       unsigned char *a_sha = stage_sha(entry->stages[2].sha, a_mode);
-       unsigned char *b_sha = stage_sha(entry->stages[3].sha, b_mode);
-       struct stat st;
-
        entry->processed = 1;
-       if (entry->rename_df_conflict_info) {
-               struct rename_df_conflict_info *conflict_info = entry->rename_df_conflict_info;
-               char *src;
+       if (entry->rename_conflict_info) {
+               struct rename_conflict_info *conflict_info = entry->rename_conflict_info;
                switch (conflict_info->rename_type) {
                case RENAME_NORMAL:
+               case RENAME_ONE_FILE_TO_ONE:
                        clean_merge = merge_content(o, path,
                                                    o_sha, o_mode, a_sha, a_mode, b_sha, b_mode,
-                                                   conflict_info->branch1);
+                                                   conflict_info);
                        break;
                case RENAME_DELETE:
                        clean_merge = 0;
@@ -1407,39 +1707,39 @@ static int process_df_entry(struct merge_options *o,
                                               conflict_info->branch2);
                        break;
                case RENAME_ONE_FILE_TO_TWO:
-                       src = conflict_info->pair1->one->path;
                        clean_merge = 0;
-                       output(o, 1, "CONFLICT (rename/rename): "
-                              "Rename \"%s\"->\"%s\" in branch \"%s\" "
-                              "rename \"%s\"->\"%s\" in \"%s\"%s",
-                              src, conflict_info->pair1->two->path, conflict_info->branch1,
-                              src, conflict_info->pair2->two->path, conflict_info->branch2,
-                              o->call_depth ? " (left unresolved)" : "");
-                       if (o->call_depth) {
-                               remove_file_from_cache(src);
-                               update_file(o, 0, conflict_info->pair1->one->sha1,
-                                           conflict_info->pair1->one->mode, src);
-                       }
-                       conflict_rename_rename_1to2(o, conflict_info->pair1,
-                                                   conflict_info->branch1,
-                                                   conflict_info->pair2,
-                                                   conflict_info->branch2);
-                       conflict_info->dst_entry2->processed = 1;
+                       conflict_rename_rename_1to2(o, conflict_info);
+                       break;
+               case RENAME_TWO_FILES_TO_ONE:
+                       clean_merge = 0;
+                       conflict_rename_rename_2to1(o, conflict_info);
                        break;
                default:
                        entry->processed = 0;
                        break;
                }
        } else if (o_sha && (!a_sha || !b_sha)) {
-               /* Modify/delete; deleted side may have put a directory in the way */
-               const char *new_path = path;
-               if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode))
-                       new_path = unique_path(o, path, a_sha ? o->branch1 : o->branch2);
-               clean_merge = 0;
-               handle_delete_modify(o, path, new_path,
-                                    a_sha, a_mode, b_sha, b_mode);
-       } else if (!o_sha && !!a_sha != !!b_sha) {
-               /* directory -> (directory, file) */
+               /* Case A: Deleted in one */
+               if ((!a_sha && !b_sha) ||
+                   (!b_sha && blob_unchanged(o_sha, a_sha, normalize, path)) ||
+                   (!a_sha && blob_unchanged(o_sha, b_sha, normalize, path))) {
+                       /* Deleted in both or deleted in one and
+                        * unchanged in the other */
+                       if (a_sha)
+                               output(o, 2, "Removing %s", path);
+                       /* do not touch working file if it did not exist */
+                       remove_file(o, 1, path, !a_sha);
+               } else {
+                       /* Modify/delete; deleted side may have put a directory in the way */
+                       clean_merge = 0;
+                       handle_modify_delete(o, path, o_sha, o_mode,
+                                            a_sha, a_mode, b_sha, b_mode);
+               }
+       } else if ((!o_sha && a_sha && !b_sha) ||
+                  (!o_sha && !a_sha && b_sha)) {
+               /* Case B: Added in one. */
+               /* [nothing|directory] -> ([nothing|directory], file) */
+
                const char *add_branch;
                const char *other_branch;
                unsigned mode;
@@ -1459,21 +1759,37 @@ static int process_df_entry(struct merge_options *o,
                        sha = b_sha;
                        conf = "directory/file";
                }
-               if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
-                       const char *new_path = unique_path(o, path, add_branch);
+               if (dir_in_way(path, !o->call_depth)) {
+                       char *new_path = unique_path(o, path, add_branch);
                        clean_merge = 0;
                        output(o, 1, "CONFLICT (%s): There is a directory with name %s in %s. "
                               "Adding %s as %s",
                               conf, path, other_branch, path, new_path);
+                       if (o->call_depth)
+                               remove_file_from_cache(path);
                        update_file(o, 0, sha, mode, new_path);
+                       if (o->call_depth)
+                               remove_file_from_cache(path);
+                       free(new_path);
                } else {
                        output(o, 2, "Adding %s", path);
-                       update_file(o, 1, sha, mode, path);
+                       /* do not overwrite file if already present */
+                       update_file_flags(o, sha, mode, path, 1, !a_sha);
                }
-       } else {
-               entry->processed = 0;
-               return 1; /* not handled; assume clean until processed */
-       }
+       } else if (a_sha && b_sha) {
+               /* Case C: Added in both (check for same permissions) and */
+               /* case D: Modified in both, but differently. */
+               clean_merge = merge_content(o, path,
+                                           o_sha, o_mode, a_sha, a_mode, b_sha, b_mode,
+                                           NULL);
+       } else if (!o_sha && !a_sha && !b_sha) {
+               /*
+                * this entry was deleted altogether. a_mode == 0 means
+                * we had that path and want to actively remove it.
+                */
+               remove_file(o, 1, path, !a_mode);
+       } else
+               die("Fatal merge failure, shouldn't happen.");
 
        return clean_merge;
 }
@@ -1517,24 +1833,17 @@ int merge_trees(struct merge_options *o,
                get_files_dirs(o, merge);
 
                entries = get_unmerged();
-               make_room_for_directories_of_df_conflicts(o, entries);
+               record_df_conflict_files(o, entries);
                re_head  = get_renames(o, head, common, head, merge, entries);
                re_merge = get_renames(o, merge, common, head, merge, entries);
                clean = process_renames(o, re_head, re_merge);
-               for (i = 0; i < entries->nr; i++) {
+               for (i = entries->nr-1; 0 <= i; i--) {
                        const char *path = entries->items[i].string;
                        struct stage_data *e = entries->items[i].util;
                        if (!e->processed
                                && !process_entry(o, path, e))
                                clean = 0;
                }
-               for (i = 0; i < entries->nr; i++) {
-                       const char *path = entries->items[i].string;
-                       struct stage_data *e = entries->items[i].util;
-                       if (!e->processed
-                               && !process_df_entry(o, path, e))
-                               clean = 0;
-               }
                for (i = 0; i < entries->nr; i++) {
                        struct stage_data *e = entries->items[i].util;
                        if (!e->processed)
@@ -1601,12 +1910,10 @@ int merge_recursive(struct merge_options *o,
 
        merged_common_ancestors = pop_commit(&ca);
        if (merged_common_ancestors == NULL) {
-               /* if there is no common ancestor, make an empty tree */
-               struct tree *tree = xcalloc(1, sizeof(struct tree));
+               /* if there is no common ancestor, use an empty tree */
+               struct tree *tree;
 
-               tree->object.parsed = 1;
-               tree->object.type = OBJ_TREE;
-               pretend_sha1_file(NULL, 0, OBJ_TREE, tree->object.sha1);
+               tree = lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN);
                merged_common_ancestors = make_virtual_commit(tree, "ancestor");
        }
 
@@ -1743,6 +2050,8 @@ void init_merge_options(struct merge_options *o)
        o->current_file_set.strdup_strings = 1;
        memset(&o->current_directory_set, 0, sizeof(struct string_list));
        o->current_directory_set.strdup_strings = 1;
+       memset(&o->df_conflict_file_set, 0, sizeof(struct string_list));
+       o->df_conflict_file_set.strdup_strings = 1;
 }
 
 int parse_merge_opt(struct merge_options *o, const char *s)
@@ -1759,6 +2068,8 @@ int parse_merge_opt(struct merge_options *o, const char *s)
                o->subtree_shift = s + strlen("subtree=");
        else if (!strcmp(s, "patience"))
                o->xdl_opts |= XDF_PATIENCE_DIFF;
+       else if (!strcmp(s, "histogram"))
+               o->xdl_opts |= XDF_HISTOGRAM_DIFF;
        else if (!strcmp(s, "ignore-space-change"))
                o->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
        else if (!strcmp(s, "ignore-all-space"))
index 7e1e972b13cb8a9f2fae084f769fffede24c8dbb..58f3435e9e854ab82c2fd0c10c55520bc69e5ed0 100644 (file)
@@ -26,6 +26,7 @@ struct merge_options {
        struct strbuf obuf;
        struct string_list current_file_set;
        struct string_list current_directory_set;
+       struct string_list df_conflict_file_set;
 };
 
 /* merge_trees() but with recursive ancestor consolidation */
diff --git a/mergetools/araxis b/mergetools/araxis
new file mode 100644 (file)
index 0000000..64f97c5
--- /dev/null
@@ -0,0 +1,20 @@
+diff_cmd () {
+       "$merge_tool_path" -wait -2 "$LOCAL" "$REMOTE" >/dev/null 2>&1
+}
+
+merge_cmd () {
+       touch "$BACKUP"
+       if $base_present
+       then
+               "$merge_tool_path" -wait -merge -3 -a1 \
+                       "$BASE" "$LOCAL" "$REMOTE" "$MERGED" >/dev/null 2>&1
+       else
+               "$merge_tool_path" -wait -2 \
+                       "$LOCAL" "$REMOTE" "$MERGED" >/dev/null 2>&1
+       fi
+       check_unchanged
+}
+
+translate_merge_tool_path() {
+       echo compare
+}
diff --git a/mergetools/bc3 b/mergetools/bc3
new file mode 100644 (file)
index 0000000..27b3dd4
--- /dev/null
@@ -0,0 +1,20 @@
+diff_cmd () {
+       "$merge_tool_path" "$LOCAL" "$REMOTE"
+}
+
+merge_cmd () {
+       touch "$BACKUP"
+       if $base_present
+       then
+               "$merge_tool_path" "$LOCAL" "$REMOTE" "$BASE" \
+                       -mergeoutput="$MERGED"
+       else
+               "$merge_tool_path" "$LOCAL" "$REMOTE" \
+                       -mergeoutput="$MERGED"
+       fi
+       check_unchanged
+}
+
+translate_merge_tool_path() {
+       echo bcompare
+}
diff --git a/mergetools/defaults b/mergetools/defaults
new file mode 100644 (file)
index 0000000..1d8f2a3
--- /dev/null
@@ -0,0 +1,46 @@
+# Redefined by builtin tools
+can_merge () {
+       return 0
+}
+
+can_diff () {
+       return 0
+}
+
+diff_cmd () {
+       merge_tool_cmd="$(get_merge_tool_cmd "$1")"
+       if test -z "$merge_tool_cmd"
+       then
+               status=1
+               break
+       fi
+       ( eval $merge_tool_cmd )
+       status=$?
+       return $status
+}
+
+merge_cmd () {
+       merge_tool_cmd="$(get_merge_tool_cmd "$1")"
+       if test -z "$merge_tool_cmd"
+       then
+               status=1
+               break
+       fi
+       trust_exit_code="$(git config --bool \
+               mergetool."$1".trustExitCode || echo false)"
+       if test "$trust_exit_code" = "false"
+       then
+               touch "$BACKUP"
+               ( eval $merge_tool_cmd )
+               status=$?
+               check_unchanged
+       else
+               ( eval $merge_tool_cmd )
+               status=$?
+       fi
+       return $status
+}
+
+translate_merge_tool_path () {
+       echo "$1"
+}
diff --git a/mergetools/diffuse b/mergetools/diffuse
new file mode 100644 (file)
index 0000000..02e0843
--- /dev/null
@@ -0,0 +1,17 @@
+diff_cmd () {
+       "$merge_tool_path" "$LOCAL" "$REMOTE" | cat
+}
+
+merge_cmd () {
+       touch "$BACKUP"
+       if $base_present
+       then
+               "$merge_tool_path" \
+                       "$LOCAL" "$MERGED" "$REMOTE" \
+                       "$BASE" | cat
+       else
+               "$merge_tool_path" \
+                       "$LOCAL" "$MERGED" "$REMOTE" | cat
+       fi
+       check_unchanged
+}
diff --git a/mergetools/ecmerge b/mergetools/ecmerge
new file mode 100644 (file)
index 0000000..13c2e43
--- /dev/null
@@ -0,0 +1,16 @@
+diff_cmd () {
+       "$merge_tool_path" --default --mode=diff2 "$LOCAL" "$REMOTE"
+}
+
+merge_cmd () {
+       touch "$BACKUP"
+       if $base_present
+       then
+               "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" \
+                       --default --mode=merge3 --to="$MERGED"
+       else
+               "$merge_tool_path" "$LOCAL" "$REMOTE" \
+                       --default --mode=merge2 --to="$MERGED"
+       fi
+       check_unchanged
+}
diff --git a/mergetools/emerge b/mergetools/emerge
new file mode 100644 (file)
index 0000000..f96d9e5
--- /dev/null
@@ -0,0 +1,23 @@
+diff_cmd () {
+       "$merge_tool_path" -f emerge-files-command "$LOCAL" "$REMOTE"
+}
+
+merge_cmd () {
+       if $base_present
+       then
+               "$merge_tool_path" \
+                       -f emerge-files-with-ancestor-command \
+                       "$LOCAL" "$REMOTE" "$BASE" \
+                       "$(basename "$MERGED")"
+       else
+               "$merge_tool_path" \
+                       -f emerge-files-command \
+                       "$LOCAL" "$REMOTE" \
+                       "$(basename "$MERGED")"
+       fi
+       status=$?
+}
+
+translate_merge_tool_path() {
+       echo emacs
+}
diff --git a/mergetools/kdiff3 b/mergetools/kdiff3
new file mode 100644 (file)
index 0000000..28fead4
--- /dev/null
@@ -0,0 +1,24 @@
+diff_cmd () {
+       "$merge_tool_path" --auto \
+               --L1 "$MERGED (A)" --L2 "$MERGED (B)" \
+               "$LOCAL" "$REMOTE" >/dev/null 2>&1
+}
+
+merge_cmd () {
+       if $base_present
+       then
+               "$merge_tool_path" --auto \
+                       --L1 "$MERGED (Base)" \
+                       --L2 "$MERGED (Local)" \
+                       --L3 "$MERGED (Remote)" \
+                       -o "$MERGED" "$BASE" "$LOCAL" "$REMOTE" \
+               >/dev/null 2>&1
+       else
+               "$merge_tool_path" --auto \
+                       --L1 "$MERGED (Local)" \
+                       --L2 "$MERGED (Remote)" \
+                       -o "$MERGED" "$LOCAL" "$REMOTE" \
+               >/dev/null 2>&1
+       fi
+       status=$?
+}
diff --git a/mergetools/kompare b/mergetools/kompare
new file mode 100644 (file)
index 0000000..433686c
--- /dev/null
@@ -0,0 +1,7 @@
+can_merge () {
+       return 1
+}
+
+diff_cmd () {
+       "$merge_tool_path" "$LOCAL" "$REMOTE"
+}
diff --git a/mergetools/meld b/mergetools/meld
new file mode 100644 (file)
index 0000000..eaa115c
--- /dev/null
@@ -0,0 +1,32 @@
+diff_cmd () {
+       "$merge_tool_path" "$LOCAL" "$REMOTE"
+}
+
+merge_cmd () {
+       if test -z "${meld_has_output_option:+set}"
+       then
+               check_meld_for_output_version
+       fi
+       touch "$BACKUP"
+       if test "$meld_has_output_option" = true
+       then
+               "$merge_tool_path" --output "$MERGED" \
+                       "$LOCAL" "$BASE" "$REMOTE"
+       else
+               "$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE"
+       fi
+       check_unchanged
+}
+
+# Check whether 'meld --output <file>' is supported
+check_meld_for_output_version () {
+       meld_path="$(git config mergetool.meld.path)"
+       meld_path="${meld_path:-meld}"
+
+       if "$meld_path" --output /dev/null --help >/dev/null 2>&1
+       then
+               meld_has_output_option=true
+       else
+               meld_has_output_option=false
+       fi
+}
diff --git a/mergetools/opendiff b/mergetools/opendiff
new file mode 100644 (file)
index 0000000..0942b2a
--- /dev/null
@@ -0,0 +1,16 @@
+diff_cmd () {
+       "$merge_tool_path" "$LOCAL" "$REMOTE" | cat
+}
+
+merge_cmd () {
+       touch "$BACKUP"
+       if $base_present
+       then
+               "$merge_tool_path" "$LOCAL" "$REMOTE" \
+                       -ancestor "$BASE" -merge "$MERGED" | cat
+       else
+               "$merge_tool_path" "$LOCAL" "$REMOTE" \
+                       -merge "$MERGED" | cat
+       fi
+       check_unchanged
+}
diff --git a/mergetools/p4merge b/mergetools/p4merge
new file mode 100644 (file)
index 0000000..1a45c1b
--- /dev/null
@@ -0,0 +1,10 @@
+diff_cmd () {
+       "$merge_tool_path" "$LOCAL" "$REMOTE"
+}
+
+merge_cmd () {
+       touch "$BACKUP"
+       $base_present || >"$BASE"
+       "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
+       check_unchanged
+}
diff --git a/mergetools/tkdiff b/mergetools/tkdiff
new file mode 100644 (file)
index 0000000..618c438
--- /dev/null
@@ -0,0 +1,12 @@
+diff_cmd () {
+       "$merge_tool_path" "$LOCAL" "$REMOTE"
+}
+
+merge_cmd () {
+       if $base_present
+       then
+               "$merge_tool_path" -a "$BASE" -o "$MERGED" "$LOCAL" "$REMOTE"
+       else
+               "$merge_tool_path" -o "$MERGED" "$LOCAL" "$REMOTE"
+       fi
+}
diff --git a/mergetools/tortoisemerge b/mergetools/tortoisemerge
new file mode 100644 (file)
index 0000000..ed7db49
--- /dev/null
@@ -0,0 +1,17 @@
+can_diff () {
+       return 1
+}
+
+merge_cmd () {
+       if $base_present
+       then
+               touch "$BACKUP"
+               "$merge_tool_path" \
+                       -base:"$BASE" -mine:"$LOCAL" \
+                       -theirs:"$REMOTE" -merged:"$MERGED"
+               check_unchanged
+       else
+               echo "TortoiseMerge cannot be used without a base" 1>&2
+               return 1
+       fi
+}
diff --git a/mergetools/vim b/mergetools/vim
new file mode 100644 (file)
index 0000000..619594a
--- /dev/null
@@ -0,0 +1,44 @@
+diff_cmd () {
+       case "$1" in
+       gvimdiff|vimdiff)
+               "$merge_tool_path" -R -f -d \
+                       -c 'wincmd l' -c 'cd $GIT_PREFIX' "$LOCAL" "$REMOTE"
+               ;;
+       gvimdiff2|vimdiff2)
+               "$merge_tool_path" -R -f -d \
+                       -c 'wincmd l' -c 'cd $GIT_PREFIX' "$LOCAL" "$REMOTE"
+               ;;
+       esac
+}
+
+merge_cmd () {
+       touch "$BACKUP"
+       case "$1" in
+       gvimdiff|vimdiff)
+               if $base_present
+               then
+                       "$merge_tool_path" -f -d -c 'wincmd J' \
+                               "$MERGED" "$LOCAL" "$BASE" "$REMOTE"
+               else
+                       "$merge_tool_path" -f -d -c 'wincmd l' \
+                               "$LOCAL" "$MERGED" "$REMOTE"
+               fi
+               ;;
+       gvimdiff2|vimdiff2)
+               "$merge_tool_path" -f -d -c 'wincmd l' \
+                       "$LOCAL" "$MERGED" "$REMOTE"
+               ;;
+       esac
+       check_unchanged
+}
+
+translate_merge_tool_path() {
+       case "$1" in
+       gvimdiff|gvimdiff2)
+               echo gvim
+               ;;
+       vimdiff|vimdiff2)
+               echo vim
+               ;;
+       esac
+}
diff --git a/mergetools/xxdiff b/mergetools/xxdiff
new file mode 100644 (file)
index 0000000..05b4433
--- /dev/null
@@ -0,0 +1,25 @@
+diff_cmd () {
+       "$merge_tool_path" \
+               -R 'Accel.Search: "Ctrl+F"' \
+               -R 'Accel.SearchForward: "Ctrl-G"' \
+               "$LOCAL" "$REMOTE"
+}
+
+merge_cmd () {
+       touch "$BACKUP"
+       if $base_present
+       then
+               "$merge_tool_path" -X --show-merged-pane \
+                       -R 'Accel.SaveAsMerged: "Ctrl-S"' \
+                       -R 'Accel.Search: "Ctrl+F"' \
+                       -R 'Accel.SearchForward: "Ctrl-G"' \
+                       --merged-file "$MERGED" "$LOCAL" "$BASE" "$REMOTE"
+       else
+               "$merge_tool_path" -X $extra \
+                       -R 'Accel.SaveAsMerged: "Ctrl-S"' \
+                       -R 'Accel.Search: "Ctrl+F"' \
+                       -R 'Accel.SearchForward: "Ctrl-G"' \
+                       --merged-file "$MERGED" "$LOCAL" "$REMOTE"
+       fi
+       check_unchanged
+}
index e1aaf43b438d0cfb6b7b0c723060a662a915bcea..baaf31f4aed4e4cfd967c278b7cfd4bee6a0ab30 100644 (file)
@@ -680,7 +680,7 @@ int notes_merge_commit(struct notes_merge_options *o,
         * Finally store the new commit object SHA1 into 'result_sha1'.
         */
        struct dir_struct dir;
-       const char *path = git_path(NOTES_MERGE_WORKTREE "/");
+       char *path = xstrdup(git_path(NOTES_MERGE_WORKTREE "/"));
        int path_len = strlen(path), i;
        const char *msg = strstr(partial_commit->buffer, "\n\n");
 
@@ -720,6 +720,7 @@ int notes_merge_commit(struct notes_merge_options *o,
                            result_sha1);
        OUTPUT(o, 4, "Finalized notes merge commit: %s",
               sha1_to_hex(result_sha1));
+       free(path);
        return 0;
 }
 
diff --git a/notes.c b/notes.c
index f6ce8489d31e48d30dfbc6aef4edf6dbb8314234..93e9868d5d1aa536b70e981d3a4cd3c7969764d3 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -1105,7 +1105,7 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
        hashcpy(l.key_sha1, object_sha1);
        hashclr(l.val_sha1);
        note_tree_remove(t, t->root, 0, &l);
-       if (is_null_sha1(l.val_sha1)) // no note was removed
+       if (is_null_sha1(l.val_sha1)) /* no note was removed */
                return 1;
        t->dirty = 1;
        return 0;
diff --git a/pager.c b/pager.c
index dac358f047550a07dd8d90b2e410feab3eebd534..975955ba82a0dbb128d6733090cd74c2b509ea81 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -11,8 +11,6 @@
  * something different on Windows.
  */
 
-static int spawned_pager;
-
 #ifndef WIN32
 static void pager_preexec(void)
 {
@@ -78,7 +76,7 @@ void setup_pager(void)
        if (!pager)
                return;
 
-       spawned_pager = 1; /* means we are emitting to terminal */
+       setenv("GIT_PAGER_IN_USE", "true", 1);
 
        /* spawn the pager */
        pager_argv[0] = pager;
@@ -109,10 +107,6 @@ void setup_pager(void)
 int pager_in_use(void)
 {
        const char *env;
-
-       if (spawned_pager)
-               return 1;
-
        env = getenv("GIT_PAGER_IN_USE");
        return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0;
 }
diff --git a/parse-options-cb.c b/parse-options-cb.c
new file mode 100644 (file)
index 0000000..6db0921
--- /dev/null
@@ -0,0 +1,125 @@
+#include "git-compat-util.h"
+#include "parse-options.h"
+#include "cache.h"
+#include "commit.h"
+#include "color.h"
+#include "string-list.h"
+
+/*----- some often used options -----*/
+
+int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
+{
+       int v;
+
+       if (!arg) {
+               v = unset ? 0 : DEFAULT_ABBREV;
+       } else {
+               v = strtol(arg, (char **)&arg, 10);
+               if (*arg)
+                       return opterror(opt, "expects a numerical value", 0);
+               if (v && v < MINIMUM_ABBREV)
+                       v = MINIMUM_ABBREV;
+               else if (v > 40)
+                       v = 40;
+       }
+       *(int *)(opt->value) = v;
+       return 0;
+}
+
+int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
+                            int unset)
+{
+       *(unsigned long *)(opt->value) = approxidate(arg);
+       return 0;
+}
+
+int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
+                           int unset)
+{
+       int value;
+
+       if (!arg)
+               arg = unset ? "never" : (const char *)opt->defval;
+       value = git_config_colorbool(NULL, arg);
+       if (value < 0)
+               return opterror(opt,
+                       "expects \"always\", \"auto\", or \"never\"", 0);
+       *(int *)opt->value = value;
+       return 0;
+}
+
+int parse_opt_verbosity_cb(const struct option *opt, const char *arg,
+                          int unset)
+{
+       int *target = opt->value;
+
+       if (unset)
+               /* --no-quiet, --no-verbose */
+               *target = 0;
+       else if (opt->short_name == 'v') {
+               if (*target >= 0)
+                       (*target)++;
+               else
+                       *target = 1;
+       } else {
+               if (*target <= 0)
+                       (*target)--;
+               else
+                       *target = -1;
+       }
+       return 0;
+}
+
+int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)
+{
+       unsigned char sha1[20];
+       struct commit *commit;
+
+       if (!arg)
+               return -1;
+       if (get_sha1(arg, sha1))
+               return error("malformed object name %s", arg);
+       commit = lookup_commit_reference(sha1);
+       if (!commit)
+               return error("no such commit %s", arg);
+       commit_list_insert(commit, opt->value);
+       return 0;
+}
+
+int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
+{
+       int *target = opt->value;
+       *target = unset ? 2 : 1;
+       return 0;
+}
+
+int parse_options_concat(struct option *dst, size_t dst_size, struct option *src)
+{
+       int i, j;
+
+       for (i = 0; i < dst_size; i++)
+               if (dst[i].type == OPTION_END)
+                       break;
+       for (j = 0; i < dst_size; i++, j++) {
+               dst[i] = src[j];
+               if (src[j].type == OPTION_END)
+                       return 0;
+       }
+       return -1;
+}
+
+int parse_opt_string_list(const struct option *opt, const char *arg, int unset)
+{
+       struct string_list *v = opt->value;
+
+       if (unset) {
+               string_list_clear(v, 0);
+               return 0;
+       }
+
+       if (!arg)
+               return -1;
+
+       string_list_append(v, xstrdup(arg));
+       return 0;
+}
index 879ea82a3158ca5e6d4ca397e0c2dd2265e15edc..503ab5d500c8ca2fe30f50601717979e752b9254 100644 (file)
@@ -3,7 +3,6 @@
 #include "cache.h"
 #include "commit.h"
 #include "color.h"
-#include "string-list.h"
 
 static int parse_options_usage(struct parse_opt_ctx_t *ctx,
                               const char * const *usagestr,
@@ -12,14 +11,14 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,
 #define OPT_SHORT 1
 #define OPT_UNSET 2
 
-static int optbug(const struct option *opt, const char *reason)
+int optbug(const struct option *opt, const char *reason)
 {
        if (opt->long_name)
                return error("BUG: option '%s' %s", opt->long_name, reason);
        return error("BUG: switch '%c' %s", opt->short_name, reason);
 }
 
-static int opterror(const struct option *opt, const char *reason, int flags)
+int opterror(const struct option *opt, const char *reason, int flags)
 {
        if (flags & OPT_SHORT)
                return error("switch `%c' %s", opt->short_name, reason);
@@ -584,123 +583,3 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,
        return usage_with_options_internal(ctx, usagestr, opts, 0, err);
 }
 
-
-/*----- some often used options -----*/
-#include "cache.h"
-
-int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
-{
-       int v;
-
-       if (!arg) {
-               v = unset ? 0 : DEFAULT_ABBREV;
-       } else {
-               v = strtol(arg, (char **)&arg, 10);
-               if (*arg)
-                       return opterror(opt, "expects a numerical value", 0);
-               if (v && v < MINIMUM_ABBREV)
-                       v = MINIMUM_ABBREV;
-               else if (v > 40)
-                       v = 40;
-       }
-       *(int *)(opt->value) = v;
-       return 0;
-}
-
-int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
-                            int unset)
-{
-       *(unsigned long *)(opt->value) = approxidate(arg);
-       return 0;
-}
-
-int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
-                           int unset)
-{
-       int value;
-
-       if (!arg)
-               arg = unset ? "never" : (const char *)opt->defval;
-       value = git_config_colorbool(NULL, arg, -1);
-       if (value < 0)
-               return opterror(opt,
-                       "expects \"always\", \"auto\", or \"never\"", 0);
-       *(int *)opt->value = value;
-       return 0;
-}
-
-int parse_opt_verbosity_cb(const struct option *opt, const char *arg,
-                          int unset)
-{
-       int *target = opt->value;
-
-       if (unset)
-               /* --no-quiet, --no-verbose */
-               *target = 0;
-       else if (opt->short_name == 'v') {
-               if (*target >= 0)
-                       (*target)++;
-               else
-                       *target = 1;
-       } else {
-               if (*target <= 0)
-                       (*target)--;
-               else
-                       *target = -1;
-       }
-       return 0;
-}
-
-int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)
-{
-       unsigned char sha1[20];
-       struct commit *commit;
-
-       if (!arg)
-               return -1;
-       if (get_sha1(arg, sha1))
-               return error("malformed object name %s", arg);
-       commit = lookup_commit_reference(sha1);
-       if (!commit)
-               return error("no such commit %s", arg);
-       commit_list_insert(commit, opt->value);
-       return 0;
-}
-
-int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
-{
-       int *target = opt->value;
-       *target = unset ? 2 : 1;
-       return 0;
-}
-
-int parse_options_concat(struct option *dst, size_t dst_size, struct option *src)
-{
-       int i, j;
-
-       for (i = 0; i < dst_size; i++)
-               if (dst[i].type == OPTION_END)
-                       break;
-       for (j = 0; i < dst_size; i++, j++) {
-               dst[i] = src[j];
-               if (src[j].type == OPTION_END)
-                       return 0;
-       }
-       return -1;
-}
-
-int parse_opt_string_list(const struct option *opt, const char *arg, int unset)
-{
-       struct string_list *v = opt->value;
-
-       if (unset) {
-               string_list_clear(v, 0);
-               return 0;
-       }
-
-       if (!arg)
-               return -1;
-
-       string_list_append(v, xstrdup(arg));
-       return 0;
-}
index 05eb09b878fd94cfcc549622a35a0b897fa56cb9..59e0b524bdcbe1c061f49b8e5f3c6365a9f2eba4 100644 (file)
@@ -165,6 +165,8 @@ extern NORETURN void usage_msg_opt(const char *msg,
                                   const char * const *usagestr,
                                   const struct option *options);
 
+extern int optbug(const struct option *opt, const char *reason);
+extern int opterror(const struct option *opt, const char *reason, int flags);
 /*----- incremental advanced APIs -----*/
 
 enum {
diff --git a/path.c b/path.c
index 4d73cc9cd26708b4cb41e86fb319b93f526cb2f2..6f3f5d56c0ed76f50d1aa37646d18ae280f1edbb 100644 (file)
--- a/path.c
+++ b/path.c
@@ -139,7 +139,7 @@ char *git_path_submodule(const char *path, const char *fmt, ...)
                strbuf_addch(&buf, '/');
        strbuf_addstr(&buf, ".git");
 
-       git_dir = read_gitfile_gently(buf.buf);
+       git_dir = read_gitfile(buf.buf);
        if (git_dir) {
                strbuf_reset(&buf);
                strbuf_addstr(&buf, git_dir);
diff --git a/quote.c b/quote.c
index 63d3b018183abc05a5231dfd7e134dd7394f7a9b..911229fdf3caffe29a87aea76f38dc50863797d4 100644 (file)
--- a/quote.c
+++ b/quote.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "quote.h"
+#include "argv-array.h"
 
 int quote_path_fully = 1;
 
@@ -120,7 +121,9 @@ char *sq_dequote(char *arg)
        return sq_dequote_step(arg, NULL);
 }
 
-int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc)
+static int sq_dequote_to_argv_internal(char *arg,
+                                      const char ***argv, int *nr, int *alloc,
+                                      struct argv_array *array)
 {
        char *next = arg;
 
@@ -130,13 +133,27 @@ int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc)
                char *dequoted = sq_dequote_step(next, &next);
                if (!dequoted)
                        return -1;
-               ALLOC_GROW(*argv, *nr + 1, *alloc);
-               (*argv)[(*nr)++] = dequoted;
+               if (argv) {
+                       ALLOC_GROW(*argv, *nr + 1, *alloc);
+                       (*argv)[(*nr)++] = dequoted;
+               }
+               if (array)
+                       argv_array_push(array, dequoted);
        } while (next);
 
        return 0;
 }
 
+int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc)
+{
+       return sq_dequote_to_argv_internal(arg, argv, nr, alloc, NULL);
+}
+
+int sq_dequote_to_argv_array(char *arg, struct argv_array *array)
+{
+       return sq_dequote_to_argv_internal(arg, NULL, NULL, NULL, array);
+}
+
 /* 1 means: quote as octal
  * 0 means: quote as octal if (quote_path_fully)
  * -1 means: never quote
@@ -325,8 +342,12 @@ static const char *path_relative(const char *in, int len,
 
        if (len < 0)
                len = strlen(in);
-       if (prefix && prefix_len < 0)
-               prefix_len = strlen(prefix);
+       if (prefix_len < 0) {
+               if (prefix)
+                       prefix_len = strlen(prefix);
+               else
+                       prefix_len = 0;
+       }
 
        off = 0;
        i = 0;
diff --git a/quote.h b/quote.h
index 024e21d80ceaa37ec1f893acc907a62092560d21..133155a48b4baa56cd70c07af8a477771f373105 100644 (file)
--- a/quote.h
+++ b/quote.h
@@ -40,12 +40,19 @@ extern char *sq_dequote(char *);
 
 /*
  * Same as the above, but can be used to unwrap many arguments in the
- * same string separated by space. "next" is changed to point to the
- * next argument that should be passed as first parameter. When there
- * is no more argument to be dequoted, "next" is updated to point to NULL.
+ * same string separated by space. Like sq_quote, it works in place,
+ * modifying arg and appending pointers into it to argv.
  */
 extern int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc);
 
+/*
+ * Same as above, but store the unquoted strings in an argv_array. We will
+ * still modify arg in place, but unlike sq_dequote_to_argv, the argv_array
+ * will duplicate and take ownership of the strings.
+ */
+struct argv_array;
+extern int sq_dequote_to_argv_array(char *arg, struct argv_array *);
+
 extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);
 extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq);
 extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);
index 46a9e60708ad98db5299f9242db05de5915a0ebb..5790a91044e4fdf5b2eec515051a66c110e0daa4 100644 (file)
@@ -1084,7 +1084,7 @@ static void show_file(const char * fmt, const char * name, int in_porcelain,
 {
        if (in_porcelain && *first && header_msg) {
                printf("%s\n", header_msg);
-               *first=0;
+               *first = 0;
        }
        printf(fmt, name);
 }
@@ -1249,9 +1249,9 @@ static void convert_from_disk(struct ondisk_cache_entry *ondisk, struct cache_en
 
 static inline size_t estimate_cache_size(size_t ondisk_size, unsigned int entries)
 {
-       long per_entry;
-
-       per_entry = sizeof(struct cache_entry) - sizeof(struct ondisk_cache_entry);
+       size_t fix_size_mem = offsetof(struct cache_entry, name);
+       size_t fix_size_dsk = offsetof(struct ondisk_cache_entry, name);
+       long per_entry = (fix_size_mem - fix_size_dsk + 7) & ~7;
 
        /*
         * Alignment can cause differences. This should be "alignof", but
diff --git a/refs.c b/refs.c
index 3a8789d3857d17a3a0a94ba2750e9f22857b8667..a615043b34cd6d0507d8a30f7bd69445ec9f2456 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -451,7 +451,7 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *re
        memcpy(gitdir + len, "/.git", 6);
        len += 5;
 
-       tmp = read_gitfile_gently(gitdir);
+       tmp = read_gitfile(gitdir);
        if (tmp) {
                free(gitdir);
                len = strlen(tmp);
@@ -584,7 +584,7 @@ int read_ref(const char *ref, unsigned char *sha1)
 static int do_one_ref(const char *base, each_ref_fn fn, int trim,
                      int flags, void *cb_data, struct ref_list *entry)
 {
-       if (strncmp(base, entry->name, trim))
+       if (prefixcmp(entry->name, base))
                return 0;
 
        if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) {
@@ -728,12 +728,12 @@ int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
 
 int for_each_ref(each_ref_fn fn, void *cb_data)
 {
-       return do_for_each_ref(NULL, "refs/", fn, 0, 0, cb_data);
+       return do_for_each_ref(NULL, "", fn, 0, 0, cb_data);
 }
 
 int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
 {
-       return do_for_each_ref(submodule, "refs/", fn, 0, 0, cb_data);
+       return do_for_each_ref(submodule, "", fn, 0, 0, cb_data);
 }
 
 int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
@@ -782,6 +782,31 @@ int for_each_replace_ref(each_ref_fn fn, void *cb_data)
        return do_for_each_ref(NULL, "refs/replace/", fn, 13, 0, cb_data);
 }
 
+int head_ref_namespaced(each_ref_fn fn, void *cb_data)
+{
+       struct strbuf buf = STRBUF_INIT;
+       int ret = 0;
+       unsigned char sha1[20];
+       int flag;
+
+       strbuf_addf(&buf, "%sHEAD", get_git_namespace());
+       if (resolve_ref(buf.buf, sha1, 1, &flag))
+               ret = fn(buf.buf, sha1, flag, cb_data);
+       strbuf_release(&buf);
+
+       return ret;
+}
+
+int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
+{
+       struct strbuf buf = STRBUF_INIT;
+       int ret;
+       strbuf_addf(&buf, "%srefs/", get_git_namespace());
+       ret = do_for_each_ref(NULL, buf.buf, fn, 0, 0, cb_data);
+       strbuf_release(&buf);
+       return ret;
+}
+
 int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
        const char *prefix, void *cb_data)
 {
@@ -819,7 +844,7 @@ int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
 
 int for_each_rawref(each_ref_fn fn, void *cb_data)
 {
-       return do_for_each_ref(NULL, "refs/", fn, 0,
+       return do_for_each_ref(NULL, "", fn, 0,
                               DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
 }
 
@@ -837,7 +862,7 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
 
 static inline int bad_ref_char(int ch)
 {
-       if (((unsigned) ch) <= ' ' ||
+       if (((unsigned) ch) <= ' ' || ch == 0x7f ||
            ch == '~' || ch == '^' || ch == ':' || ch == '\\')
                return 1;
        /* 2.13 Pattern Matching Notation */
diff --git a/refs.h b/refs.h
index 5de06e57e7a9644a7dd51832552e9d1afa53c8cd..dfb086e93346aa3fb6f600b2ed07b5736716bf9c 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -36,6 +36,9 @@ extern int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, voi
 extern int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
 extern int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
 
+extern int head_ref_namespaced(each_ref_fn fn, void *cb_data);
+extern int for_each_namespaced_ref(each_ref_fn fn, void *cb_data);
+
 static inline const char *has_glob_specials(const char *pattern)
 {
        return strpbrk(pattern, "?*[");
index 69831e931af1fe2a3e668239e8c4bb73a7bfb936..0aa4bfed309d6c439fac4ff2a0df6a468307e7bf 100644 (file)
@@ -573,7 +573,14 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
 
        close(client.in);
        client.in = -1;
-       strbuf_read(&rpc->result, client.out, 0);
+       if (!err) {
+               strbuf_read(&rpc->result, client.out, 0);
+       } else {
+               char buf[4096];
+               for (;;)
+                       if (xread(client.out, buf, sizeof(buf)) <= 0)
+                               break;
+       }
 
        close(client.out);
        client.out = -1;
@@ -855,7 +862,14 @@ int main(int argc, const char **argv)
        http_init(remote);
 
        do {
-               if (strbuf_getline(&buf, stdin, '\n') == EOF)
+               if (strbuf_getline(&buf, stdin, '\n') == EOF) {
+                       if (ferror(stdin))
+                               fprintf(stderr, "Error reading command stream\n");
+                       else
+                               fprintf(stderr, "Unexpected end of command stream\n");
+                       return 1;
+               }
+               if (buf.len == 0)
                        break;
                if (!prefixcmp(buf.buf, "fetch ")) {
                        if (nongit)
@@ -895,6 +909,7 @@ int main(int argc, const char **argv)
                        printf("\n");
                        fflush(stdout);
                } else {
+                       fprintf(stderr, "Unknown command '%s'\n", buf.buf);
                        return 1;
                }
                strbuf_reset(&buf);
index ca42a126ad04514f0ed8378768ebce98cfc5a659..6ececc4a7703f6d54caf919b1162ed454b45a47e 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -828,59 +828,56 @@ static int match_name_with_pattern(const char *key, const char *name,
        return ret;
 }
 
-char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
-                    const char *name)
+static int query_refspecs(struct refspec *refs, int ref_count, struct refspec *query)
 {
        int i;
-       char *ret = NULL;
-       for (i = 0; i < nr_refspec; i++) {
-               struct refspec *refspec = refspecs + i;
-               if (refspec->pattern) {
-                       if (match_name_with_pattern(refspec->src, name,
-                                                   refspec->dst, &ret))
-                               return ret;
-               } else if (!strcmp(refspec->src, name))
-                       return strdup(refspec->dst);
-       }
-       return NULL;
-}
+       int find_src = !query->src;
 
-int remote_find_tracking(struct remote *remote, struct refspec *refspec)
-{
-       int find_src = refspec->src == NULL;
-       char *needle, **result;
-       int i;
+       if (find_src && !query->dst)
+               return error("query_refspecs: need either src or dst");
 
-       if (find_src) {
-               if (!refspec->dst)
-                       return error("find_tracking: need either src or dst");
-               needle = refspec->dst;
-               result = &refspec->src;
-       } else {
-               needle = refspec->src;
-               result = &refspec->dst;
-       }
+       for (i = 0; i < ref_count; i++) {
+               struct refspec *refspec = &refs[i];
+               const char *key = find_src ? refspec->dst : refspec->src;
+               const char *value = find_src ? refspec->src : refspec->dst;
+               const char *needle = find_src ? query->dst : query->src;
+               char **result = find_src ? &query->src : &query->dst;
 
-       for (i = 0; i < remote->fetch_refspec_nr; i++) {
-               struct refspec *fetch = &remote->fetch[i];
-               const char *key = find_src ? fetch->dst : fetch->src;
-               const char *value = find_src ? fetch->src : fetch->dst;
-               if (!fetch->dst)
+               if (!refspec->dst)
                        continue;
-               if (fetch->pattern) {
+               if (refspec->pattern) {
                        if (match_name_with_pattern(key, needle, value, result)) {
-                               refspec->force = fetch->force;
+                               query->force = refspec->force;
                                return 0;
                        }
                } else if (!strcmp(needle, key)) {
                        *result = xstrdup(value);
-                       refspec->force = fetch->force;
+                       query->force = refspec->force;
                        return 0;
                }
        }
        return -1;
 }
 
+char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
+                    const char *name)
+{
+       struct refspec query;
+
+       memset(&query, 0, sizeof(struct refspec));
+       query.src = (char *)name;
+
+       if (query_refspecs(refspecs, nr_refspec, &query))
+               return NULL;
+
+       return query.dst;
+}
+
+int remote_find_tracking(struct remote *remote, struct refspec *refspec)
+{
+       return query_refspecs(remote->fetch, remote->fetch_refspec_nr, refspec);
+}
+
 static struct ref *alloc_ref_with_prefix(const char *prefix, size_t prefixlen,
                const char *name)
 {
@@ -896,7 +893,7 @@ struct ref *alloc_ref(const char *name)
        return alloc_ref_with_prefix("", 0, name);
 }
 
-static struct ref *copy_ref(const struct ref *ref)
+struct ref *copy_ref(const struct ref *ref)
 {
        struct ref *cpy;
        size_t len;
@@ -1667,7 +1664,9 @@ struct ref *guess_remote_head(const struct ref *head,
 
        /* Look for another ref that points there */
        for (r = refs; r; r = r->next) {
-               if (r != head && !hashcmp(r->old_sha1, head->old_sha1)) {
+               if (r != head &&
+                   !prefixcmp(r->name, "refs/heads/") &&
+                   !hashcmp(r->old_sha1, head->old_sha1)) {
                        *tail = copy_ref(r);
                        tail = &((*tail)->next);
                        if (!all)
@@ -1679,36 +1678,47 @@ struct ref *guess_remote_head(const struct ref *head,
 }
 
 struct stale_heads_info {
-       struct remote *remote;
        struct string_list *ref_names;
        struct ref **stale_refs_tail;
+       struct refspec *refs;
+       int ref_count;
 };
 
 static int get_stale_heads_cb(const char *refname,
        const unsigned char *sha1, int flags, void *cb_data)
 {
        struct stale_heads_info *info = cb_data;
-       struct refspec refspec;
-       memset(&refspec, 0, sizeof(refspec));
-       refspec.dst = (char *)refname;
-       if (!remote_find_tracking(info->remote, &refspec)) {
-               if (!((flags & REF_ISSYMREF) ||
-                   string_list_has_string(info->ref_names, refspec.src))) {
-                       struct ref *ref = make_linked_ref(refname, &info->stale_refs_tail);
-                       hashcpy(ref->new_sha1, sha1);
-               }
+       struct refspec query;
+       memset(&query, 0, sizeof(struct refspec));
+       query.dst = (char *)refname;
+
+       if (query_refspecs(info->refs, info->ref_count, &query))
+               return 0; /* No matches */
+
+       /*
+        * If we did find a suitable refspec and it's not a symref and
+        * it's not in the list of refs that currently exist in that
+        * remote we consider it to be stale.
+        */
+       if (!((flags & REF_ISSYMREF) ||
+             string_list_has_string(info->ref_names, query.src))) {
+               struct ref *ref = make_linked_ref(refname, &info->stale_refs_tail);
+               hashcpy(ref->new_sha1, sha1);
        }
+
+       free(query.src);
        return 0;
 }
 
-struct ref *get_stale_heads(struct remote *remote, struct ref *fetch_map)
+struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fetch_map)
 {
        struct ref *ref, *stale_refs = NULL;
        struct string_list ref_names = STRING_LIST_INIT_NODUP;
        struct stale_heads_info info;
-       info.remote = remote;
        info.ref_names = &ref_names;
        info.stale_refs_tail = &stale_refs;
+       info.refs = refs;
+       info.ref_count = ref_count;
        for (ref = fetch_map; ref; ref = ref->next)
                string_list_append(&ref_names, ref->name);
        sort_string_list(&ref_names);
index 888d7c15de2eacc56d869a96d4463aefca7a7a06..f2541b5a29a552fb9fab736f5b47a545c2eee383 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -70,7 +70,7 @@ struct refspec {
 extern const struct refspec *tag_refspec;
 
 struct ref *alloc_ref(const char *name);
-
+struct ref *copy_ref(const struct ref *ref);
 struct ref *copy_ref_list(const struct ref *ref);
 
 int check_ref_type(const struct ref *ref, int flags);
@@ -164,6 +164,6 @@ struct ref *guess_remote_head(const struct ref *head,
                              int all);
 
 /* Return refs which no longer exist on remote */
-struct ref *get_stale_heads(struct remote *remote, struct ref *fetch_map);
+struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fetch_map);
 
 #endif
index c46cfaa3e4d2f06fd67ccd71c7ba47891796fd60..3d2deedaf8e50c6a71b9750dacf602bb5b9238b9 100644 (file)
@@ -729,12 +729,16 @@ static void limit_to_ancestry(struct commit_list *bottom, struct commit_list *li
  * to filter the result of "A..B" further to the ones that can actually
  * reach A.
  */
-static struct commit_list *collect_bottom_commits(struct commit_list *list)
+static struct commit_list *collect_bottom_commits(struct rev_info *revs)
 {
-       struct commit_list *elem, *bottom = NULL;
-       for (elem = list; elem; elem = elem->next)
-               if (elem->item->object.flags & UNINTERESTING)
-                       commit_list_insert(elem->item, &bottom);
+       struct commit_list *bottom = NULL;
+       int i;
+       for (i = 0; i < revs->cmdline.nr; i++) {
+               struct rev_cmdline_entry *elem = &revs->cmdline.rev[i];
+               if ((elem->flags & UNINTERESTING) &&
+                   elem->item->type == OBJ_COMMIT)
+                       commit_list_insert((struct commit *)elem->item, &bottom);
+       }
        return bottom;
 }
 
@@ -765,7 +769,7 @@ static int limit_list(struct rev_info *revs)
        struct commit_list *bottom = NULL;
 
        if (revs->ancestry_path) {
-               bottom = collect_bottom_commits(list);
+               bottom = collect_bottom_commits(revs);
                if (!bottom)
                        die("--ancestry-path given but there are no bottom commits");
        }
@@ -822,6 +826,23 @@ static int limit_list(struct rev_info *revs)
        return 0;
 }
 
+static void add_rev_cmdline(struct rev_info *revs,
+                           struct object *item,
+                           const char *name,
+                           int whence,
+                           unsigned flags)
+{
+       struct rev_cmdline_info *info = &revs->cmdline;
+       int nr = info->nr;
+
+       ALLOC_GROW(info->rev, nr + 1, info->alloc);
+       info->rev[nr].item = item;
+       info->rev[nr].name = name;
+       info->rev[nr].whence = whence;
+       info->rev[nr].flags = flags;
+       info->nr++;
+}
+
 struct all_refs_cb {
        int all_flags;
        int warned_bad_reflog;
@@ -834,6 +855,7 @@ static int handle_one_ref(const char *path, const unsigned char *sha1, int flag,
        struct all_refs_cb *cb = cb_data;
        struct object *object = get_reference(cb->all_revs, path, sha1,
                                              cb->all_flags);
+       add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags);
        add_pending_object(cb->all_revs, object, path);
        return 0;
 }
@@ -860,6 +882,7 @@ static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
                struct object *o = parse_object(sha1);
                if (o) {
                        o->flags |= cb->all_flags;
+                       /* ??? CMDLINEFLAGS ??? */
                        add_pending_object(cb->all_revs, o, "");
                }
                else if (!cb->warned_bad_reflog) {
@@ -896,12 +919,13 @@ static void handle_reflog(struct rev_info *revs, unsigned flags)
        for_each_reflog(handle_one_reflog, &cb);
 }
 
-static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
+static int add_parents_only(struct rev_info *revs, const char *arg_, int flags)
 {
        unsigned char sha1[20];
        struct object *it;
        struct commit *commit;
        struct commit_list *parents;
+       const char *arg = arg_;
 
        if (*arg == '^') {
                flags ^= UNINTERESTING;
@@ -925,6 +949,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
        for (parents = commit->parents; parents; parents = parents->next) {
                it = &parents->item->object;
                it->flags |= flags;
+               add_rev_cmdline(revs, it, arg_, REV_CMD_PARENTS_ONLY, flags);
                add_pending_object(revs, it, arg);
        }
        return 1;
@@ -986,10 +1011,12 @@ static void prepare_show_merge(struct rev_info *revs)
        const char **prune = NULL;
        int i, prune_num = 1; /* counting terminating NULL */
 
-       if (get_sha1("HEAD", sha1) || !(head = lookup_commit(sha1)))
+       if (get_sha1("HEAD", sha1))
                die("--merge without HEAD?");
-       if (get_sha1("MERGE_HEAD", sha1) || !(other = lookup_commit(sha1)))
+       head = lookup_commit_or_die(sha1, "HEAD");
+       if (get_sha1("MERGE_HEAD", sha1))
                die("--merge without MERGE_HEAD?");
+       other = lookup_commit_or_die(sha1, "MERGE_HEAD");
        add_pending_object(revs, &head->object, "HEAD");
        add_pending_object(revs, &other->object, "MERGE_HEAD");
        bases = get_merge_bases(head, other, 1);
@@ -1018,7 +1045,7 @@ static void prepare_show_merge(struct rev_info *revs)
        revs->limited = 1;
 }
 
-int handle_revision_arg(const char *arg, struct rev_info *revs,
+int handle_revision_arg(const char *arg_, struct rev_info *revs,
                        int flags,
                        int cant_be_filename)
 {
@@ -1027,6 +1054,7 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
        struct object *object;
        unsigned char sha1[20];
        int local_flags;
+       const char *arg = arg_;
 
        dotdot = strstr(arg, "..");
        if (dotdot) {
@@ -1035,6 +1063,7 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
                const char *this = arg;
                int symmetric = *next == '.';
                unsigned int flags_exclude = flags ^ UNINTERESTING;
+               unsigned int a_flags;
 
                *dotdot = 0;
                next += symmetric;
@@ -1069,10 +1098,15 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
                                add_pending_commit_list(revs, exclude,
                                                        flags_exclude);
                                free_commit_list(exclude);
-                               a->object.flags |= flags | SYMMETRIC_LEFT;
+                               a_flags = flags | SYMMETRIC_LEFT;
                        } else
-                               a->object.flags |= flags_exclude;
+                               a_flags = flags_exclude;
+                       a->object.flags |= a_flags;
                        b->object.flags |= flags;
+                       add_rev_cmdline(revs, &a->object, this,
+                                       REV_CMD_LEFT, a_flags);
+                       add_rev_cmdline(revs, &b->object, next,
+                                       REV_CMD_RIGHT, flags);
                        add_pending_object(revs, &a->object, this);
                        add_pending_object(revs, &b->object, next);
                        return 0;
@@ -1103,6 +1137,7 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
        if (!cant_be_filename)
                verify_non_filename(revs->prefix, arg);
        object = get_reference(revs, arg, sha1, flags ^ local_flags);
+       add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags);
        add_pending_object_with_mode(revs, object, arg, mode);
        return 0;
 }
index 3d64adad18e2c889b7a7b7367f99c239f958dc70..93d31556cb44d3e4c5162d21c8e92d572a36508e 100644 (file)
@@ -24,6 +24,23 @@ struct rev_info;
 struct log_info;
 struct string_list;
 
+struct rev_cmdline_info {
+       unsigned int nr;
+       unsigned int alloc;
+       struct rev_cmdline_entry {
+               struct object *item;
+               const char *name;
+               enum {
+                       REV_CMD_REF,
+                       REV_CMD_PARENTS_ONLY,
+                       REV_CMD_LEFT,
+                       REV_CMD_RIGHT,
+                       REV_CMD_REV
+               } whence;
+               unsigned flags;
+       } *rev;
+};
+
 struct rev_info {
        /* Starting list */
        struct commit_list *commits;
@@ -32,6 +49,9 @@ struct rev_info {
        /* Parents of shown commits */
        struct object_array boundary_commits;
 
+       /* The end-points specified by the end user */
+       struct rev_cmdline_info cmdline;
+
        /* Basic information */
        const char *prefix;
        const char *def;
index 70e8a249d0fe07b6a32b4da4ac8224d1c2f06b1b..1c5104388429e50722769358d5d89948c55bb3aa 100644 (file)
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "run-command.h"
 #include "exec_cmd.h"
+#include "argv-array.h"
 
 static inline void close_pair(int fd[2])
 {
@@ -77,16 +78,14 @@ static void notify_parent(void)
 
 static NORETURN void die_child(const char *err, va_list params)
 {
-       char msg[4096];
-       int len = vsnprintf(msg, sizeof(msg), err, params);
-       if (len > sizeof(msg))
-               len = sizeof(msg);
-
-       write_in_full(child_err, "fatal: ", 7);
-       write_in_full(child_err, msg, len);
-       write_in_full(child_err, "\n", 1);
+       vwritef(child_err, "fatal: ", err, params);
        exit(128);
 }
+
+static void error_child(const char *err, va_list params)
+{
+       vwritef(child_err, "error: ", err, params);
+}
 #endif
 
 static inline void set_cloexec(int fd)
@@ -127,9 +126,6 @@ static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
                if (code == 127) {
                        code = -1;
                        failed_errno = ENOENT;
-                       if (!silent_exec_failure)
-                               error("cannot run %s: %s", argv0,
-                                       strerror(ENOENT));
                }
        } else {
                error("waitpid is confused (%s)", argv0);
@@ -217,6 +213,7 @@ fail_pipe:
                        set_cloexec(child_err);
                }
                set_die_routine(die_child);
+               set_error_routine(error_child);
 
                close(notify_pipe[0]);
                set_cloexec(notify_pipe[1]);
@@ -283,14 +280,14 @@ fail_pipe:
                } else {
                        execvp(cmd->argv[0], (char *const*) cmd->argv);
                }
-               /*
-                * Do not check for cmd->silent_exec_failure; the parent
-                * process will check it when it sees this exit code.
-                */
-               if (errno == ENOENT)
+               if (errno == ENOENT) {
+                       if (!cmd->silent_exec_failure)
+                               error("cannot run %s: %s", cmd->argv[0],
+                                       strerror(ENOENT));
                        exit(127);
-               else
+               } else {
                        die_errno("cannot exec '%s'", cmd->argv[0]);
+               }
        }
        if (cmd->pid < 0)
                error("cannot fork() for %s: %s", cmd->argv[0],
@@ -609,26 +606,23 @@ int finish_async(struct async *async)
 int run_hook(const char *index_file, const char *name, ...)
 {
        struct child_process hook;
-       const char **argv = NULL, *env[2];
+       struct argv_array argv = ARGV_ARRAY_INIT;
+       const char *p, *env[2];
        char index[PATH_MAX];
        va_list args;
        int ret;
-       size_t i = 0, alloc = 0;
 
        if (access(git_path("hooks/%s", name), X_OK) < 0)
                return 0;
 
        va_start(args, name);
-       ALLOC_GROW(argv, i + 1, alloc);
-       argv[i++] = git_path("hooks/%s", name);
-       while (argv[i-1]) {
-               ALLOC_GROW(argv, i + 1, alloc);
-               argv[i++] = va_arg(args, const char *);
-       }
+       argv_array_push(&argv, git_path("hooks/%s", name));
+       while ((p = va_arg(args, const char *)))
+               argv_array_push(&argv, p);
        va_end(args);
 
        memset(&hook, 0, sizeof(hook));
-       hook.argv = argv;
+       hook.argv = argv.argv;
        hook.no_stdin = 1;
        hook.stdout_to_stderr = 1;
        if (index_file) {
@@ -639,6 +633,6 @@ int run_hook(const char *index_file, const char *name, ...)
        }
 
        ret = run_command(&hook);
-       free(argv);
+       argv_array_clear(&argv);
        return ret;
 }
diff --git a/setup.c b/setup.c
index 5ea5502e4881a806ebb3aa9fd38f146cf9f65cf9..27c1d4787a2c2efd8420a225b43e36b76464ce42 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -40,34 +40,6 @@ char *prefix_path(const char *prefix, int len, const char *path)
        return sanitized;
 }
 
-/*
- * Unlike prefix_path, this should be used if the named file does
- * not have to interact with index entry; i.e. name of a random file
- * on the filesystem.
- */
-const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
-{
-       static char path[PATH_MAX];
-#ifndef WIN32
-       if (!pfx_len || is_absolute_path(arg))
-               return arg;
-       memcpy(path, pfx, pfx_len);
-       strcpy(path + pfx_len, arg);
-#else
-       char *p;
-       /* don't add prefix to absolute paths, but still replace '\' by '/' */
-       if (is_absolute_path(arg))
-               pfx_len = 0;
-       else if (pfx_len)
-               memcpy(path, pfx, pfx_len);
-       strcpy(path + pfx_len, arg);
-       for (p = path + pfx_len; *p; p++)
-               if (*p == '\\')
-                       *p = '/';
-#endif
-       return path;
-}
-
 int check_filename(const char *prefix, const char *arg)
 {
        const char *name;
@@ -264,6 +236,38 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
        return pathspec;
 }
 
+const char *pathspec_prefix(const char *prefix, const char **pathspec)
+{
+       const char **p, *n, *prev;
+       unsigned long max;
+
+       if (!pathspec)
+               return prefix ? xmemdupz(prefix, strlen(prefix)) : NULL;
+
+       prev = NULL;
+       max = PATH_MAX;
+       for (p = pathspec; (n = *p) != NULL; p++) {
+               int i, len = 0;
+               for (i = 0; i < max; i++) {
+                       char c = n[i];
+                       if (prev && prev[i] != c)
+                               break;
+                       if (!c || c == '*' || c == '?')
+                               break;
+                       if (c == '/')
+                               len = i+1;
+               }
+               prev = n;
+               if (len < max) {
+                       max = len;
+                       if (!max)
+                               break;
+               }
+       }
+
+       return max ? xmemdupz(prev, max) : NULL;
+}
+
 /*
  * Test if it looks like we're at a git directory.
  * We want to see:
@@ -375,7 +379,7 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
  * Try to read the location of the git directory from the .git file,
  * return path to git directory if found.
  */
-const char *read_gitfile_gently(const char *path)
+const char *read_gitfile(const char *path)
 {
        char *buf;
        char *dir;
@@ -437,7 +441,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
        if (PATH_MAX - 40 < strlen(gitdirenv))
                die("'$%s' too big", GIT_DIR_ENVIRONMENT);
 
-       gitfile = (char*)read_gitfile_gently(gitdirenv);
+       gitfile = (char*)read_gitfile(gitdirenv);
        if (gitfile) {
                gitfile = xstrdup(gitfile);
                gitdirenv = gitfile;
@@ -661,7 +665,7 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
        if (one_filesystem)
                current_device = get_device_or_die(".", NULL);
        for (;;) {
-               gitfile = (char*)read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
+               gitfile = (char*)read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
                if (gitfile)
                        gitdirenv = gitfile = xstrdup(gitfile);
                else {
index 89d7e5eb57ea80a7bca3f361530903032fbe2b03..e002056b85ce89c089dd09c1300461d60d81dffa 100644 (file)
@@ -380,7 +380,7 @@ void add_to_alternates_file(const char *reference)
 {
        struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
        int fd = hold_lock_file_for_append(lock, git_path("objects/info/alternates"), LOCK_DIE_ON_ERROR);
-       char *alt = mkpath("%s/objects\n", reference);
+       char *alt = mkpath("%s\n", reference);
        write_or_die(fd, alt, strlen(alt));
        if (commit_lock_file(lock))
                die("could not close alternates file");
@@ -1217,14 +1217,34 @@ static int experimental_loose_object(unsigned char *map)
        unsigned int word;
 
        /*
-        * Is it a zlib-compressed buffer? If so, the first byte
-        * must be 0x78 (15-bit window size, deflated), and the
-        * first 16-bit word is evenly divisible by 31. If so,
-        * we are looking at the official format, not the experimental
-        * one.
+        * We must determine if the buffer contains the standard
+        * zlib-deflated stream or the experimental format based
+        * on the in-pack object format. Compare the header byte
+        * for each format:
+        *
+        * RFC1950 zlib w/ deflate : 0www1000 : 0 <= www <= 7
+        * Experimental pack-based : Stttssss : ttt = 1,2,3,4
+        *
+        * If bit 7 is clear and bits 0-3 equal 8, the buffer MUST be
+        * in standard loose-object format, UNLESS it is a Git-pack
+        * format object *exactly* 8 bytes in size when inflated.
+        *
+        * However, RFC1950 also specifies that the 1st 16-bit word
+        * must be divisible by 31 - this checksum tells us our buffer
+        * is in the standard format, giving a false positive only if
+        * the 1st word of the Git-pack format object happens to be
+        * divisible by 31, ie:
+        *      ((byte0 * 256) + byte1) % 31 = 0
+        *   =>        0ttt10000www1000 % 31 = 0
+        *
+        * As it happens, this case can only arise for www=3 & ttt=1
+        * - ie, a Commit object, which would have to be 8 bytes in
+        * size. As no Commit can be that small, we find that the
+        * combination of these two criteria (bitmask & checksum)
+        * can always correctly determine the buffer format.
         */
        word = (map[0] << 8) + map[1];
-       if (map[0] == 0x78 && !(word % 31))
+       if ((map[0] & 0x8F) == 0x08 && !(word % 31))
                return 0;
        else
                return 1;
@@ -1797,6 +1817,24 @@ static void *unpack_delta_entry(struct packed_git *p,
        return result;
 }
 
+static void write_pack_access_log(struct packed_git *p, off_t obj_offset)
+{
+       static FILE *log_file;
+
+       if (!log_file) {
+               log_file = fopen(log_pack_access, "w");
+               if (!log_file) {
+                       error("cannot open pack access log '%s' for writing: %s",
+                             log_pack_access, strerror(errno));
+                       log_pack_access = NULL;
+                       return;
+               }
+       }
+       fprintf(log_file, "%s %"PRIuMAX"\n",
+               p->pack_name, (uintmax_t)obj_offset);
+       fflush(log_file);
+}
+
 int do_check_packed_object_crc;
 
 void *unpack_entry(struct packed_git *p, off_t obj_offset,
@@ -1806,6 +1844,9 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
        off_t curpos = obj_offset;
        void *data;
 
+       if (log_pack_access)
+               write_pack_access_log(p, obj_offset);
+
        if (do_check_packed_object_crc && p->index_version > 1) {
                struct revindex_entry *revidx = find_pack_revindex(p, obj_offset);
                unsigned long len = revidx[1].offset - obj_offset;
index 4c0ac138aff7b5add73e17fc9c3c4e409fd918e2..63f9da53237d4233bede66a28e4bcf27d5b44af1 100644 (file)
@@ -48,7 +48,7 @@ int main(int argc, char **argv)
                        unsigned char sha1[20];
                        uint32_t crc;
                        uint32_t off;
-               } *entries = malloc(nr * sizeof(entries[0]));
+               } *entries = xmalloc(nr * sizeof(entries[0]));
                for (i = 0; i < nr; i++)
                        if (fread(entries[i].sha1, 20, 1, stdin) != 1)
                                die("unable to read sha1 %u/%u", i, nr);
index 1a7df12e8f233863cd931a960d453d54050f5584..3ad2cc00160fbf24e1e4904bb37ce44e8c414ce5 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -30,10 +30,8 @@ void strbuf_init(struct strbuf *sb, size_t hint)
 {
        sb->alloc = sb->len = 0;
        sb->buf = strbuf_slopbuf;
-       if (hint) {
+       if (hint)
                strbuf_grow(sb, hint);
-               sb->buf[0] = '\0';
-       }
 }
 
 void strbuf_release(struct strbuf *sb)
@@ -65,12 +63,15 @@ void strbuf_attach(struct strbuf *sb, void *buf, size_t len, size_t alloc)
 
 void strbuf_grow(struct strbuf *sb, size_t extra)
 {
+       int new_buf = !sb->alloc;
        if (unsigned_add_overflows(extra, 1) ||
            unsigned_add_overflows(sb->len, extra + 1))
                die("you want to use way too much memory");
-       if (!sb->alloc)
+       if (new_buf)
                sb->buf = NULL;
        ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc);
+       if (new_buf)
+               sb->buf[0] = '\0';
 }
 
 void strbuf_trim(struct strbuf *sb)
@@ -356,7 +357,6 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
 {
        int ch;
 
-       strbuf_grow(sb, 0);
        if (feof(fp))
                return EOF;
 
index 25c9a209bb1ba9cec8bb49623ae45fc19fdca2c7..71072e1b1da670cdb4b048a3a6e83a4ae806bf5f 100644 (file)
@@ -94,7 +94,9 @@ struct git_istream {
 
 int close_istream(struct git_istream *st)
 {
-       return st->vtbl->close(st);
+       int r = st->vtbl->close(st);
+       free(st);
+       return r;
 }
 
 ssize_t read_istream(struct git_istream *st, char *buf, size_t sz)
index 51681189e8380cc43ed26d35526a6dff78f1a24c..d9810aba421cbbc844b45ea5ca713a480a699eb2 100644 (file)
@@ -185,3 +185,12 @@ int unsorted_string_list_has_string(struct string_list *list,
        return unsorted_string_list_lookup(list, string) != NULL;
 }
 
+void unsorted_string_list_delete_item(struct string_list *list, int i, int free_util)
+{
+       if (list->strdup_strings)
+               free(list->items[i].string);
+       if (free_util)
+               free(list->items[i].util);
+       list->items[i] = list->items[list->nr-1];
+       list->nr--;
+}
index bda69839832d2030c15bbd86c4d8d79aa3cc4785..0684cb73bfd27846182479a4e192d682a44f201a 100644 (file)
@@ -44,4 +44,5 @@ void sort_string_list(struct string_list *list);
 int unsorted_string_list_has_string(struct string_list *list, const char *string);
 struct string_list_item *unsorted_string_list_lookup(struct string_list *list,
                                                     const char *string);
+void unsorted_string_list_delete_item(struct string_list *list, int i, int free_util);
 #endif /* STRING_LIST_H */
index 1ba9646d3484fe2a11c1faba339c4e333186085e..0b709bc2914335853e7525076f5e1d026d5dd779 100644 (file)
@@ -8,12 +8,18 @@
 #include "diffcore.h"
 #include "refs.h"
 #include "string-list.h"
+#include "sha1-array.h"
+#include "argv-array.h"
 
 static struct string_list config_name_for_path;
 static struct string_list config_fetch_recurse_submodules_for_name;
 static struct string_list config_ignore_for_name;
 static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
 static struct string_list changed_submodule_paths;
+static int initialized_fetch_ref_tips;
+static struct sha1_array ref_tips_before_fetch;
+static struct sha1_array ref_tips_after_fetch;
+
 /*
  * The following flag is set if the .gitmodules file is unmerged. We then
  * disable recursion for all submodules where .git/config doesn't have a
@@ -32,7 +38,7 @@ static int add_submodule_odb(const char *path)
        const char *git_dir;
 
        strbuf_addf(&objects_directory, "%s/.git", path);
-       git_dir = read_gitfile_gently(objects_directory.buf);
+       git_dir = read_gitfile(objects_directory.buf);
        if (git_dir) {
                strbuf_reset(&objects_directory);
                strbuf_addstr(&objects_directory, git_dir);
@@ -308,6 +314,114 @@ void set_config_fetch_recurse_submodules(int value)
        config_fetch_recurse_submodules = value;
 }
 
+static int has_remote(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
+{
+       return 1;
+}
+
+static int submodule_needs_pushing(const char *path, const unsigned char sha1[20])
+{
+       if (add_submodule_odb(path) || !lookup_commit_reference(sha1))
+               return 0;
+
+       if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {
+               struct child_process cp;
+               const char *argv[] = {"rev-list", NULL, "--not", "--remotes", "-n", "1" , NULL};
+               struct strbuf buf = STRBUF_INIT;
+               int needs_pushing = 0;
+
+               argv[1] = sha1_to_hex(sha1);
+               memset(&cp, 0, sizeof(cp));
+               cp.argv = argv;
+               cp.env = local_repo_env;
+               cp.git_cmd = 1;
+               cp.no_stdin = 1;
+               cp.out = -1;
+               cp.dir = path;
+               if (start_command(&cp))
+                       die("Could not run 'git rev-list %s --not --remotes -n 1' command in submodule %s",
+                               sha1_to_hex(sha1), path);
+               if (strbuf_read(&buf, cp.out, 41))
+                       needs_pushing = 1;
+               finish_command(&cp);
+               close(cp.out);
+               strbuf_release(&buf);
+               return needs_pushing;
+       }
+
+       return 0;
+}
+
+static void collect_submodules_from_diff(struct diff_queue_struct *q,
+                                        struct diff_options *options,
+                                        void *data)
+{
+       int i;
+       int *needs_pushing = data;
+
+       for (i = 0; i < q->nr; i++) {
+               struct diff_filepair *p = q->queue[i];
+               if (!S_ISGITLINK(p->two->mode))
+                       continue;
+               if (submodule_needs_pushing(p->two->path, p->two->sha1)) {
+                       *needs_pushing = 1;
+                       break;
+               }
+       }
+}
+
+
+static void commit_need_pushing(struct commit *commit, struct commit_list *parent, int *needs_pushing)
+{
+       const unsigned char (*parents)[20];
+       unsigned int i, n;
+       struct rev_info rev;
+
+       n = commit_list_count(parent);
+       parents = xmalloc(n * sizeof(*parents));
+
+       for (i = 0; i < n; i++) {
+               hashcpy((unsigned char *)(parents + i), parent->item->object.sha1);
+               parent = parent->next;
+       }
+
+       init_revisions(&rev, NULL);
+       rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
+       rev.diffopt.format_callback = collect_submodules_from_diff;
+       rev.diffopt.format_callback_data = needs_pushing;
+       diff_tree_combined(commit->object.sha1, parents, n, 1, &rev);
+
+       free(parents);
+}
+
+int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remotes_name)
+{
+       struct rev_info rev;
+       struct commit *commit;
+       const char *argv[] = {NULL, NULL, "--not", "NULL", NULL};
+       int argc = ARRAY_SIZE(argv) - 1;
+       char *sha1_copy;
+       int needs_pushing = 0;
+       struct strbuf remotes_arg = STRBUF_INIT;
+
+       strbuf_addf(&remotes_arg, "--remotes=%s", remotes_name);
+       init_revisions(&rev, NULL);
+       sha1_copy = xstrdup(sha1_to_hex(new_sha1));
+       argv[1] = sha1_copy;
+       argv[3] = remotes_arg.buf;
+       setup_revisions(argc, argv, &rev, NULL);
+       if (prepare_revision_walk(&rev))
+               die("revision walk setup failed");
+
+       while ((commit = get_revision(&rev)) && !needs_pushing)
+               commit_need_pushing(commit, commit->parents, &needs_pushing);
+
+       free(sha1_copy);
+       strbuf_release(&remotes_arg);
+
+       return needs_pushing;
+}
+
 static int is_submodule_commit_present(const char *path, unsigned char sha1[20])
 {
        int is_present = 0;
@@ -366,16 +480,46 @@ static void submodule_collect_changed_cb(struct diff_queue_struct *q,
        }
 }
 
+static int add_sha1_to_array(const char *ref, const unsigned char *sha1,
+                            int flags, void *data)
+{
+       sha1_array_append(data, sha1);
+       return 0;
+}
+
 void check_for_new_submodule_commits(unsigned char new_sha1[20])
+{
+       if (!initialized_fetch_ref_tips) {
+               for_each_ref(add_sha1_to_array, &ref_tips_before_fetch);
+               initialized_fetch_ref_tips = 1;
+       }
+
+       sha1_array_append(&ref_tips_after_fetch, new_sha1);
+}
+
+static void add_sha1_to_argv(const unsigned char sha1[20], void *data)
+{
+       argv_array_push(data, sha1_to_hex(sha1));
+}
+
+static void calculate_changed_submodule_paths(void)
 {
        struct rev_info rev;
        struct commit *commit;
-       const char *argv[] = {NULL, NULL, "--not", "--all", NULL};
-       int argc = ARRAY_SIZE(argv) - 1;
+       struct argv_array argv = ARGV_ARRAY_INIT;
+
+       /* No need to check if there are no submodules configured */
+       if (!config_name_for_path.nr)
+               return;
 
        init_revisions(&rev, NULL);
-       argv[1] = xstrdup(sha1_to_hex(new_sha1));
-       setup_revisions(argc, argv, &rev, NULL);
+       argv_array_push(&argv, "--"); /* argv[0] program name */
+       sha1_array_for_each_unique(&ref_tips_after_fetch,
+                                  add_sha1_to_argv, &argv);
+       argv_array_push(&argv, "--not");
+       sha1_array_for_each_unique(&ref_tips_before_fetch,
+                                  add_sha1_to_argv, &argv);
+       setup_revisions(argv.argc, argv.argv, &rev, NULL);
        if (prepare_revision_walk(&rev))
                die("revision walk setup failed");
 
@@ -399,7 +543,11 @@ void check_for_new_submodule_commits(unsigned char new_sha1[20])
                        parent = parent->next;
                }
        }
-       free((char *)argv[1]);
+
+       argv_array_clear(&argv);
+       sha1_array_clear(&ref_tips_before_fetch);
+       sha1_array_clear(&ref_tips_after_fetch);
+       initialized_fetch_ref_tips = 0;
 }
 
 int fetch_populated_submodules(int num_options, const char **options,
@@ -433,6 +581,8 @@ int fetch_populated_submodules(int num_options, const char **options,
        cp.git_cmd = 1;
        cp.no_stdin = 1;
 
+       calculate_changed_submodule_paths();
+
        for (i = 0; i < active_nr; i++) {
                struct strbuf submodule_path = STRBUF_INIT;
                struct strbuf submodule_git_dir = STRBUF_INIT;
@@ -479,7 +629,7 @@ int fetch_populated_submodules(int num_options, const char **options,
                strbuf_addf(&submodule_path, "%s/%s", work_tree, ce->name);
                strbuf_addf(&submodule_git_dir, "%s/.git", submodule_path.buf);
                strbuf_addf(&submodule_prefix, "%s%s/", prefix, ce->name);
-               git_dir = read_gitfile_gently(submodule_git_dir.buf);
+               git_dir = read_gitfile(submodule_git_dir.buf);
                if (!git_dir)
                        git_dir = submodule_git_dir.buf;
                if (is_directory(git_dir)) {
@@ -517,7 +667,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
        const char *git_dir;
 
        strbuf_addf(&buf, "%s/.git", path);
-       git_dir = read_gitfile_gently(buf.buf);
+       git_dir = read_gitfile(buf.buf);
        if (!git_dir)
                git_dir = buf.buf;
        if (!is_directory(git_dir)) {
index 5350b0d5a0d16e12e96b983e6510cb1d4098f962..799c22d6c6a459756983420960bc099da20336b3 100644 (file)
@@ -29,5 +29,6 @@ int fetch_populated_submodules(int num_options, const char **options,
 unsigned is_submodule_modified(const char *path, int ignore_untracked);
 int merge_submodule(unsigned char result[20], const char *path, const unsigned char base[20],
                    const unsigned char a[20], const unsigned char b[20]);
+int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remotes_name);
 
 #endif
diff --git a/t/lib-diff-alternative.sh b/t/lib-diff-alternative.sh
new file mode 100644 (file)
index 0000000..75ffd91
--- /dev/null
@@ -0,0 +1,165 @@
+#!/bin/sh
+
+test_diff_frobnitz() {
+       cat >file1 <<\EOF
+#include <stdio.h>
+
+// Frobs foo heartily
+int frobnitz(int foo)
+{
+    int i;
+    for(i = 0; i < 10; i++)
+    {
+        printf("Your answer is: ");
+        printf("%d\n", foo);
+    }
+}
+
+int fact(int n)
+{
+    if(n > 1)
+    {
+        return fact(n-1) * n;
+    }
+    return 1;
+}
+
+int main(int argc, char **argv)
+{
+    frobnitz(fact(10));
+}
+EOF
+
+       cat >file2 <<\EOF
+#include <stdio.h>
+
+int fib(int n)
+{
+    if(n > 2)
+    {
+        return fib(n-1) + fib(n-2);
+    }
+    return 1;
+}
+
+// Frobs foo heartily
+int frobnitz(int foo)
+{
+    int i;
+    for(i = 0; i < 10; i++)
+    {
+        printf("%d\n", foo);
+    }
+}
+
+int main(int argc, char **argv)
+{
+    frobnitz(fib(10));
+}
+EOF
+
+       cat >expect <<\EOF
+diff --git a/file1 b/file2
+index 6faa5a3..e3af329 100644
+--- a/file1
++++ b/file2
+@@ -1,26 +1,25 @@
+ #include <stdio.h>
++int fib(int n)
++{
++    if(n > 2)
++    {
++        return fib(n-1) + fib(n-2);
++    }
++    return 1;
++}
++
+ // Frobs foo heartily
+ int frobnitz(int foo)
+ {
+     int i;
+     for(i = 0; i < 10; i++)
+     {
+-        printf("Your answer is: ");
+         printf("%d\n", foo);
+     }
+ }
+-int fact(int n)
+-{
+-    if(n > 1)
+-    {
+-        return fact(n-1) * n;
+-    }
+-    return 1;
+-}
+-
+ int main(int argc, char **argv)
+ {
+-    frobnitz(fact(10));
++    frobnitz(fib(10));
+ }
+EOF
+
+       STRATEGY=$1
+
+       test_expect_success "$STRATEGY diff" '
+               test_must_fail git diff --no-index "--$STRATEGY" file1 file2 > output &&
+               test_cmp expect output
+       '
+
+       test_expect_success "$STRATEGY diff output is valid" '
+               mv file2 expect &&
+               git apply < output &&
+               test_cmp expect file2
+       '
+}
+
+test_diff_unique() {
+       cat >uniq1 <<\EOF
+1
+2
+3
+4
+5
+6
+EOF
+
+       cat >uniq2 <<\EOF
+a
+b
+c
+d
+e
+f
+EOF
+
+       cat >expect <<\EOF
+diff --git a/uniq1 b/uniq2
+index b414108..0fdf397 100644
+--- a/uniq1
++++ b/uniq2
+@@ -1,6 +1,6 @@
+-1
+-2
+-3
+-4
+-5
+-6
++a
++b
++c
++d
++e
++f
+EOF
+
+       STRATEGY=$1
+
+       test_expect_success 'completely different files' '
+               test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output &&
+               test_cmp expect output
+       '
+}
+
index ebbc7554a7d4dce4c2ed33a79f5d4feb3a520f05..6946c4b82f9291f6618d49de2e3892a2c203d337 100755 (executable)
@@ -9,16 +9,17 @@ attr_check () {
        path="$1"
        expect="$2"
 
-       git check-attr test -- "$path" >actual &&
+       git $3 check-attr test -- "$path" >actual 2>err &&
        echo "$path: test: $2" >expect &&
-       test_cmp expect actual
+       test_cmp expect actual &&
+       test_line_count = 0 err
 
 }
 
 
 test_expect_success 'setup' '
 
-       mkdir -p a/b/d a/c &&
+       mkdir -p a/b/d a/c &&
        (
                echo "[attr]notest !test"
                echo "f test=f"
@@ -26,6 +27,7 @@ test_expect_success 'setup' '
                echo "onoff test -test"
                echo "offon -test test"
                echo "no notest"
+               echo "A/e/F test=A/e/F"
        ) >.gitattributes &&
        (
                echo "g test=a/g" &&
@@ -35,10 +37,42 @@ test_expect_success 'setup' '
                echo "h test=a/b/h" &&
                echo "d/* test=a/b/d/*"
                echo "d/yes notest"
-       ) >a/b/.gitattributes
+       ) >a/b/.gitattributes &&
        (
                echo "global test=global"
-       ) >"$HOME"/global-gitattributes
+       ) >"$HOME"/global-gitattributes &&
+       cat <<EOF >expect-all
+f: test: f
+a/f: test: f
+a/c/f: test: f
+a/g: test: a/g
+a/b/g: test: a/b/g
+b/g: test: unspecified
+a/b/h: test: a/b/h
+a/b/d/g: test: a/b/d/*
+onoff: test: unset
+offon: test: set
+no: notest: set
+no: test: unspecified
+a/b/d/no: notest: set
+a/b/d/no: test: a/b/d/*
+a/b/d/yes: notest: set
+a/b/d/yes: test: unspecified
+EOF
+
+'
+
+test_expect_success 'command line checks' '
+
+       test_must_fail git check-attr &&
+       test_must_fail git check-attr -- &&
+       test_must_fail git check-attr test &&
+       test_must_fail git check-attr test -- &&
+       test_must_fail git check-attr -- f &&
+       echo "f" | test_must_fail git check-attr --stdin &&
+       echo "f" | test_must_fail git check-attr --stdin -- f &&
+       echo "f" | test_must_fail git check-attr --stdin test -- f &&
+       test_must_fail git check-attr "" -- f
 
 '
 
@@ -60,6 +94,84 @@ test_expect_success 'attribute test' '
 
 '
 
+test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' '
+
+       test_must_fail attr_check F f "-c core.ignorecase=0" &&
+       test_must_fail attr_check a/F f "-c core.ignorecase=0" &&
+       test_must_fail attr_check a/c/F f "-c core.ignorecase=0" &&
+       test_must_fail attr_check a/G a/g "-c core.ignorecase=0" &&
+       test_must_fail attr_check a/B/g a/b/g "-c core.ignorecase=0" &&
+       test_must_fail attr_check a/b/G a/b/g "-c core.ignorecase=0" &&
+       test_must_fail attr_check a/b/H a/b/h "-c core.ignorecase=0" &&
+       test_must_fail attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=0" &&
+       test_must_fail attr_check oNoFf unset "-c core.ignorecase=0" &&
+       test_must_fail attr_check oFfOn set "-c core.ignorecase=0" &&
+       attr_check NO unspecified "-c core.ignorecase=0" &&
+       test_must_fail attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=0" &&
+       attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" &&
+       test_must_fail attr_check a/E/f "A/e/F" "-c core.ignorecase=0"
+
+'
+
+test_expect_success 'attribute matching is case insensitive when core.ignorecase=1' '
+
+       attr_check F f "-c core.ignorecase=1" &&
+       attr_check a/F f "-c core.ignorecase=1" &&
+       attr_check a/c/F f "-c core.ignorecase=1" &&
+       attr_check a/G a/g "-c core.ignorecase=1" &&
+       attr_check a/B/g a/b/g "-c core.ignorecase=1" &&
+       attr_check a/b/G a/b/g "-c core.ignorecase=1" &&
+       attr_check a/b/H a/b/h "-c core.ignorecase=1" &&
+       attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=1" &&
+       attr_check oNoFf unset "-c core.ignorecase=1" &&
+       attr_check oFfOn set "-c core.ignorecase=1" &&
+       attr_check NO unspecified "-c core.ignorecase=1" &&
+       attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=1" &&
+       attr_check a/b/d/YES unspecified "-c core.ignorecase=1" &&
+       attr_check a/E/f "A/e/F" "-c core.ignorecase=1"
+
+'
+
+test_expect_success 'check whether FS is case-insensitive' '
+       mkdir junk &&
+       echo good >junk/CamelCase &&
+       echo bad >junk/camelcase &&
+       if test "$(cat junk/CamelCase)" != good
+       then
+               test_set_prereq CASE_INSENSITIVE_FS
+       fi
+'
+
+test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' '
+       test_must_fail attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=0" &&
+       test_must_fail attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=0" &&
+       attr_check A/b/h a/b/h "-c core.ignorecase=1" &&
+       attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" &&
+       attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1"
+'
+
+test_expect_success 'unnormalized paths' '
+
+       attr_check ./f f &&
+       attr_check ./a/g a/g &&
+       attr_check a/./g a/g &&
+       attr_check a/c/../b/g a/b/g
+
+'
+
+test_expect_success 'relative paths' '
+
+       (cd a && attr_check ../f f) &&
+       (cd a && attr_check f f) &&
+       (cd a && attr_check i a/i) &&
+       (cd a && attr_check g a/g) &&
+       (cd a && attr_check b/g a/b/g) &&
+       (cd b && attr_check ../a/f f) &&
+       (cd b && attr_check ../a/g a/g) &&
+       (cd b && attr_check ../a/b/g a/b/g)
+
+'
+
 test_expect_success 'core.attributesfile' '
        attr_check global unspecified &&
        git config core.attributesfile "$HOME/global-gitattributes" &&
@@ -72,26 +184,19 @@ test_expect_success 'core.attributesfile' '
 
 test_expect_success 'attribute test: read paths from stdin' '
 
-       cat <<EOF > expect &&
-f: test: f
-a/f: test: f
-a/c/f: test: f
-a/g: test: a/g
-a/b/g: test: a/b/g
-b/g: test: unspecified
-a/b/h: test: a/b/h
-a/b/d/g: test: a/b/d/*
-onoff: test: unset
-offon: test: set
-no: test: unspecified
-a/b/d/no: test: a/b/d/*
-a/b/d/yes: test: unspecified
-EOF
-
+       grep -v notest < expect-all > expect &&
        sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
        test_cmp expect actual
 '
 
+test_expect_success 'attribute test: --all option' '
+
+       grep -v unspecified < expect-all | sort > expect &&
+       sed -e "s/:.*//" < expect-all | uniq |
+               git check-attr --stdin --all | sort > actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'root subdir attribute test' '
 
        attr_check a/i a/i &&
index f87abb5a0682d7a2fc7c3947789301c4157d331d..1d29810a7a94dad15645869c2f4f015a470fa622 100755 (executable)
@@ -40,6 +40,12 @@ check_parse 2008-02 bad
 check_parse 2008-02-14 bad
 check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 +0000'
 check_parse '2008-02-14 20:30:45 -0500' '2008-02-14 20:30:45 -0500'
+check_parse '2008-02-14 20:30:45 -0015' '2008-02-14 20:30:45 -0015'
+check_parse '2008-02-14 20:30:45 -5' '2008-02-14 20:30:45 +0000'
+check_parse '2008-02-14 20:30:45 -5:' '2008-02-14 20:30:45 +0000'
+check_parse '2008-02-14 20:30:45 -05' '2008-02-14 20:30:45 -0500'
+check_parse '2008-02-14 20:30:45 -:30' '2008-02-14 20:30:45 +0000'
+check_parse '2008-02-14 20:30:45 -05:00' '2008-02-14 20:30:45 -0500'
 check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 -0500' EST5
 
 check_approxidate() {
diff --git a/t/t1013-loose-object-format.sh b/t/t1013-loose-object-format.sh
new file mode 100755 (executable)
index 0000000..0a9cedd
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/sh
+#
+# Copyright (c) 2011 Roberto Tyley
+#
+
+test_description='Correctly identify and parse loose object headers
+
+There are two file formats for loose objects - the original standard
+format, and the experimental format introduced with Git v1.4.3, later
+deprecated with v1.5.3. Although Git no longer writes the
+experimental format, objects in both formats must be read, with the
+format for a given file being determined by the header.
+
+Detecting file format based on header is not entirely trivial, not
+least because the first byte of a zlib-deflated stream will vary
+depending on how much memory was allocated for the deflation window
+buffer when the object was written out (for example 4KB on Android,
+rather that 32KB on a normal PC).
+
+The loose objects used as test vectors have been generated with the
+following Git versions:
+
+standard format: Git v1.7.4.1
+experimental format: Git v1.4.3 (legacyheaders=false)
+standard format, deflated with 4KB window size: Agit/JGit on Android
+'
+
+. ./test-lib.sh
+
+assert_blob_equals() {
+       printf "%s" "$2" >expected &&
+       git cat-file -p "$1" >actual &&
+       test_cmp expected actual
+}
+
+test_expect_success setup '
+       cp -R "$TEST_DIRECTORY/t1013/objects" .git/
+       git --version
+'
+
+test_expect_success 'read standard-format loose objects' '
+       git cat-file tag 8d4e360d6c70fbd72411991c02a09c442cf7a9fa &&
+       git cat-file commit 6baee0540ea990d9761a3eb9ab183003a71c3696 &&
+       git ls-tree 7a37b887a73791d12d26c0d3e39568a8fb0fa6e8 &&
+       assert_blob_equals "257cc5642cb1a054f08cc83f2d943e56fd3ebe99" "foo$LF"
+'
+
+test_expect_success 'read experimental-format loose objects' '
+       git cat-file tag 76e7fa9941f4d5f97f64fea65a2cba436bc79cbb &&
+       git cat-file commit 7875c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 &&
+       git ls-tree 95b1625de3ba8b2214d1e0d0591138aea733f64f &&
+       assert_blob_equals "2e65efe2a145dda7ee51d1741299f848e5bf752e" "a" &&
+       assert_blob_equals "9ae9e86b7bd6cb1472d9373702d8249973da0832" "ab" &&
+       assert_blob_equals "85df50785d62d3b05ab03d9cbf7e4a0b49449730" "abcd" &&
+       assert_blob_equals "1656f9233d999f61ef23ef390b9c71d75399f435" "abcdefgh" &&
+       assert_blob_equals "1e72a6b2c4a577ab0338860fa9fe87f761fc9bbd" "abcdefghi" &&
+       assert_blob_equals "70e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd" "abcdefghijklmnop" &&
+       assert_blob_equals "bd15045f6ce8ff75747562173640456a394412c8" "abcdefghijklmnopqrstuvwx"
+'
+
+test_expect_success 'read standard-format objects deflated with smaller window buffer' '
+       git cat-file tag f816d5255855ac160652ee5253b06cd8ee14165a &&
+       git cat-file tag 149cedb5c46929d18e0f118e9fa31927487af3b6
+'
+
+test_done
diff --git a/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 b/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6
new file mode 100644 (file)
index 0000000..472fd14
Binary files /dev/null and b/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 differ
diff --git a/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 b/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435
new file mode 100644 (file)
index 0000000..c379d74
Binary files /dev/null and b/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 differ
diff --git a/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd b/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd
new file mode 100644 (file)
index 0000000..9370630
Binary files /dev/null and b/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd differ
diff --git a/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 b/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99
new file mode 100644 (file)
index 0000000..bdcf704
Binary files /dev/null and b/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 differ
diff --git a/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e b/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e
new file mode 100644 (file)
index 0000000..ad62c43
Binary files /dev/null and b/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e differ
diff --git a/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 b/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696
new file mode 100644 (file)
index 0000000..3d2f033
Binary files /dev/null and b/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 differ
diff --git a/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd b/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd
new file mode 100644 (file)
index 0000000..b3f71a6
Binary files /dev/null and b/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd differ
diff --git a/t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb b/t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb
new file mode 100644 (file)
index 0000000..af4e9a7
--- /dev/null
@@ -0,0 +1,2 @@
\vx\9c%ÌA\ e\820\10@Ñ}O1{cSZ(\98\18ãνá\ 2Ãthª\94\92Z\8cÜÞ Ëÿ\16?\r\ f¦\ 2m×6dµi\9d\19É9\85¤Gå\98h\a´Ø¨ÁZR'Q¶\85\81R\8c¡\88\82\1eø³p\ e\91ç\82ÓqL9âÏ=g¸§\81sIÐo\13opÎÿ\94eÏ«_1»\80³¤$×ç\ 5*Si«ëNwpP\95RBôûÅÁú
\87[(ð®d-\8dø\ 2ÁL9á
\ No newline at end of file
diff --git a/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 b/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09
new file mode 100644 (file)
index 0000000..3dd28be
Binary files /dev/null and b/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 differ
diff --git a/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 b/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8
new file mode 100644 (file)
index 0000000..2b97b26
Binary files /dev/null and b/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 differ
diff --git a/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 b/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730
new file mode 100644 (file)
index 0000000..6dff746
Binary files /dev/null and b/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 differ
diff --git a/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa b/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa
new file mode 100644 (file)
index 0000000..cb41e92
Binary files /dev/null and b/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa differ
diff --git a/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f b/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f
new file mode 100644 (file)
index 0000000..7ac46b4
Binary files /dev/null and b/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f differ
diff --git a/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 b/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832
new file mode 100644 (file)
index 0000000..9d8316d
Binary files /dev/null and b/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 differ
diff --git a/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 b/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8
new file mode 100644 (file)
index 0000000..eebf239
Binary files /dev/null and b/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 differ
diff --git a/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
new file mode 100644 (file)
index 0000000..134cf19
Binary files /dev/null and b/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 differ
diff --git a/t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a b/t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a
new file mode 100644 (file)
index 0000000..26b75ae
--- /dev/null
@@ -0,0 +1 @@
+H\89\15ÌÁ\ e\820\f\80aÏ{\8aÞ\rI»e\1d&Æø*¥\1d\88\ 1\17ß^¸ýù\ e¿Ë\ 4DåÒ\86wU\87Ò\97¬\1cS±4ª\19\8aÆ\11­ª\9e ,\19\afÅ[ðßVAÛºÎ\1eüxÈÇö6[wtG§Lu\a¸?\97¦²¼Ú×\1f@\89"gì{\86+\12b\b\7fy¾%M
\ No newline at end of file
index 865b8ed26d577e154276887f88c8af9d13e62170..3b1b985996e9a6b52b032ef45c5be9b1c57b60f6 100755 (executable)
@@ -17,8 +17,6 @@ test_expect_success setup '
        cp one original.one &&
        cp dir/two original.two
 '
-LF='
-'
 
 test_expect_success 'update-index and ls-files' '
        git update-index --add one &&
index 3e140c18f4183c41c76aaab0834f1d23ce7bcd2d..dffccf84f8f67ae8dc13eae4547eb4c7c687de1d 100755 (executable)
@@ -333,6 +333,12 @@ test_expect_success 'get-regexp variable with no value' \
        'git config --get-regexp novalue > output &&
         cmp output expect'
 
+echo 'novalue.variable true' > expect
+
+test_expect_success 'get-regexp --bool variable with no value' \
+       'git config --bool --get-regexp novalue > output &&
+        cmp output expect'
+
 echo 'emptyvalue.variable ' > expect
 
 test_expect_success 'get-regexp variable with empty value' \
index b5d89a2250e41afe544b0d0f59f638e02d570cdd..2b962cfda70d998e9c2799cf8fc720b330cd118a 100755 (executable)
@@ -25,6 +25,11 @@ else
        test_set_prereq SETFACL
 fi
 
+if test -z "$LOGNAME"
+then
+       LOGNAME=$USER
+fi
+
 check_perms_and_acl () {
        test -r "$1" &&
        getfacl "$1" > actual &&
index 1b0f82fa4c7928fc4605ccf31a3ae45e6ac9f38e..ed4275afe3100491ea57025632665182127f33cf 100755 (executable)
@@ -18,6 +18,9 @@ invalid_ref 'foo'
 valid_ref 'foo/bar/baz'
 valid_ref 'refs///heads/foo'
 invalid_ref 'heads/foo/'
+valid_ref '/heads/foo'
+valid_ref '///heads/foo'
+invalid_ref '/foo'
 invalid_ref './foo'
 invalid_ref '.refs/foo'
 invalid_ref 'heads/foo..bar'
@@ -27,6 +30,9 @@ invalid_ref 'heads/foo.lock'
 valid_ref 'heads/foo@bar'
 invalid_ref 'heads/v@{ation'
 invalid_ref 'heads/foo\bar'
+invalid_ref "$(printf 'heads/foo\t')"
+invalid_ref "$(printf 'heads/foo\177')"
+valid_ref "$(printf 'heads/fu\303\237')"
 
 test_expect_success "check-ref-format --branch @{-1}" '
        T=$(git write-tree) &&
@@ -70,7 +76,10 @@ invalid_ref_normalized() {
 
 valid_ref_normalized 'heads/foo' 'heads/foo'
 valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
+valid_ref_normalized '/heads/foo' 'heads/foo'
+valid_ref_normalized '///heads/foo' 'heads/foo'
 invalid_ref_normalized 'foo'
+invalid_ref_normalized '/foo'
 invalid_ref_normalized 'heads/foo/../bar'
 invalid_ref_normalized 'heads/./foo'
 invalid_ref_normalized 'heads\foo'
index 7f519e5ebeac0780aee1c6d9c4458e00b62a273d..647d888507a4b74b82ae4016c2f30f7d171e98ca 100755 (executable)
@@ -21,10 +21,10 @@ test_expect_success 'setup reflog with alternating commits' '
 
 test_expect_success 'reflog shows all entries' '
        cat >expect <<-\EOF
-               topic@{0} two: updating HEAD
-               topic@{1} one: updating HEAD
-               topic@{2} two: updating HEAD
-               topic@{3} one: updating HEAD
+               topic@{0} reset: moving to two
+               topic@{1} reset: moving to one
+               topic@{2} reset: moving to two
+               topic@{3} reset: moving to one
                topic@{4} branch: Created from HEAD
        EOF
        git log -g --format="%gd %gs" topic >actual &&
index bb01d5ab8f8ebcaf49ef238d48ae89e3845d5f4b..523ce9c45b75d85a129015a56004473a5fccf926 100755 (executable)
@@ -110,6 +110,42 @@ test_expect_success 'email with embedded > is not okay' '
        grep "error in commit $new" out
 '
 
+test_expect_success 'missing < email delimiter is reported nicely' '
+       git cat-file commit HEAD >basis &&
+       sed "s/<//" basis >bad-email-2 &&
+       new=$(git hash-object -t commit -w --stdin <bad-email-2) &&
+       test_when_finished "remove_object $new" &&
+       git update-ref refs/heads/bogus "$new" &&
+       test_when_finished "git update-ref -d refs/heads/bogus" &&
+       git fsck 2>out &&
+       cat out &&
+       grep "error in commit $new.* - bad name" out
+'
+
+test_expect_success 'missing email is reported nicely' '
+       git cat-file commit HEAD >basis &&
+       sed "s/[a-z]* <[^>]*>//" basis >bad-email-3 &&
+       new=$(git hash-object -t commit -w --stdin <bad-email-3) &&
+       test_when_finished "remove_object $new" &&
+       git update-ref refs/heads/bogus "$new" &&
+       test_when_finished "git update-ref -d refs/heads/bogus" &&
+       git fsck 2>out &&
+       cat out &&
+       grep "error in commit $new.* - missing email" out
+'
+
+test_expect_success '> in name is reported' '
+       git cat-file commit HEAD >basis &&
+       sed "s/ </> </" basis >bad-email-4 &&
+       new=$(git hash-object -t commit -w --stdin <bad-email-4) &&
+       test_when_finished "remove_object $new" &&
+       git update-ref refs/heads/bogus "$new" &&
+       test_when_finished "git update-ref -d refs/heads/bogus" &&
+       git fsck 2>out &&
+       cat out &&
+       grep "error in commit $new" out
+'
+
 test_expect_success 'tag pointing to nonexistent' '
        cat >invalid-tag <<-\EOF &&
        object ffffffffffffffffffffffffffffffffffffffff
index a42e03967b1df3001df24089f2c50008c092ac51..75874e85dfbcae8ea9634693a93524841b741559 100755 (executable)
@@ -118,6 +118,15 @@ test_expect_success 'checkout -b to an existing branch fails' '
        test_must_fail do_checkout branch2 $HEAD2
 '
 
+test_expect_success 'checkout -b to @{-1} fails with the right branch name' '
+       git reset --hard HEAD &&
+       git checkout branch1 &&
+       git checkout branch2 &&
+       echo  >expect "fatal: A branch named '\''branch1'\'' already exists." &&
+       test_must_fail git checkout -b @{-1} 2>actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'checkout -B to an existing branch resets branch to HEAD' '
        git checkout branch1 &&
 
@@ -180,4 +189,12 @@ test_expect_success 'checkout -b <describe>' '
        test_cmp expect actual
 '
 
+test_expect_success 'checkout -B to the current branch fails before merging' '
+       git checkout branch1 &&
+       setup_dirty_mergeable &&
+       git commit -mfooble &&
+       test_must_fail git checkout -B branch1 initial &&
+       test_must_fail test_dirty_mergeable
+'
+
 test_done
diff --git a/t/t2022-checkout-paths.sh b/t/t2022-checkout-paths.sh
new file mode 100755 (executable)
index 0000000..56090d2
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+test_description='checkout $tree -- $paths'
+. ./test-lib.sh
+
+test_expect_success setup '
+       mkdir dir &&
+       >dir/master &&
+       echo common >dir/common &&
+       git add dir/master dir/common &&
+       test_tick && git commit -m "master has dir/master" &&
+       git checkout -b next &&
+       git mv dir/master dir/next0 &&
+       echo next >dir/next1 &&
+       git add dir &&
+       test_tick && git commit -m "next has dir/next but not dir/master"
+'
+
+test_expect_success 'checking out paths out of a tree does not clobber unrelated paths' '
+       git checkout next &&
+       git reset --hard &&
+       rm dir/next0 &&
+       cat dir/common >expect.common &&
+       echo modified >expect.next1 &&
+       cat expect.next1 >dir/next1 &&
+       echo untracked >expect.next2 &&
+       cat expect.next2 >dir/next2 &&
+
+       git checkout master dir &&
+
+       test_cmp expect.common dir/common &&
+       test_path_is_file dir/master &&
+       git diff --exit-code master dir/master &&
+
+       test_path_is_missing dir/next0 &&
+       test_cmp expect.next1 dir/next1 &&
+       test_path_is_file dir/next2 &&
+       test_must_fail git ls-files --error-unmatch dir/next2 &&
+       test_cmp expect.next2 dir/next2
+'
+
+test_done
diff --git a/t/t3005-ls-files-relative.sh b/t/t3005-ls-files-relative.sh
new file mode 100755 (executable)
index 0000000..3778694
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/sh
+
+test_description='ls-files tests with relative paths
+
+This test runs git ls-files with various relative path arguments.
+'
+
+. ./test-lib.sh
+
+new_line='
+'
+sq=\'
+
+test_expect_success 'prepare' '
+       : >never-mind-me &&
+       git add never-mind-me &&
+       mkdir top &&
+       (
+               cd top &&
+               mkdir sub &&
+               x="x xa xbc xdef xghij xklmno" &&
+               y=$(echo "$x" | tr x y) &&
+               touch $x &&
+               touch $y &&
+               cd sub &&
+               git add ../x*
+       )
+'
+
+test_expect_success 'ls-files with mixed levels' '
+       (
+               cd top/sub &&
+               cat >expect <<-EOF &&
+               ../../never-mind-me
+               ../x
+               EOF
+               git ls-files $(cat expect) >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'ls-files -c' '
+       (
+               cd top/sub &&
+               for f in ../y*
+               do
+                       echo "error: pathspec $sq$f$sq did not match any file(s) known to git."
+               done >expect.err &&
+               echo "Did you forget to ${sq}git add${sq}?" >>expect.err &&
+               ls ../x* >expect.out &&
+               test_must_fail git ls-files -c --error-unmatch ../[xy]* >actual.out 2>actual.err &&
+               test_cmp expect.out actual.out &&
+               test_cmp expect.err actual.err
+       )
+'
+
+test_expect_success 'ls-files -o' '
+       (
+               cd top/sub &&
+               for f in ../x*
+               do
+                       echo "error: pathspec $sq$f$sq did not match any file(s) known to git."
+               done >expect.err &&
+               echo "Did you forget to ${sq}git add${sq}?" >>expect.err &&
+               ls ../y* >expect.out &&
+               test_must_fail git ls-files -o --error-unmatch ../[xy]* >actual.out 2>actual.err &&
+               test_cmp expect.out actual.out &&
+               test_cmp expect.err actual.err
+       )
+'
+
+test_done
index 0c02d569520ddc81b32db7d248197562d00bd7ea..55ef1895d7fd15348c47a5dc4a7f93541a1d38c1 100755 (executable)
@@ -267,7 +267,8 @@ test_expect_success 'setup 8' '
                ln -s e a &&
                git add a e &&
                test_tick &&
-               git commit -m "rename a->e, symlink a->e"
+               git commit -m "rename a->e, symlink a->e" &&
+               oln=`printf e | git hash-object --stdin`
        fi
 '
 
@@ -630,16 +631,18 @@ test_expect_success 'merge-recursive copy vs. rename' '
 
 if test_have_prereq SYMLINKS
 then
-       test_expect_success 'merge-recursive rename vs. rename/symlink' '
+       test_expect_failure 'merge-recursive rename vs. rename/symlink' '
 
                git checkout -f rename &&
                git merge rename-ln &&
                ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
                (
+                       echo "120000 blob $oln  a"
                        echo "100644 blob $o0   b"
                        echo "100644 blob $o0   c"
                        echo "100644 blob $o0   d/e"
                        echo "100644 blob $o0   e"
+                       echo "120000 $oln 0     a"
                        echo "100644 $o0 0      b"
                        echo "100644 $o0 0      c"
                        echo "100644 $o0 0      d/e"
diff --git a/t/t3103-ls-tree-misc.sh b/t/t3103-ls-tree-misc.sh
new file mode 100755 (executable)
index 0000000..09dcf04
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+test_description='
+Miscellaneous tests for git ls-tree.
+
+             1. git ls-tree fails in presence of tree damage.
+
+'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       mkdir a &&
+       touch a/one &&
+       git add a/one &&
+       git commit -m test
+'
+
+test_expect_success 'ls-tree fails with non-zero exit code on broken tree' '
+       rm -f .git/objects/5f/cffbd6e4c5c5b8d81f5e9314b20e338e3ffff5 &&
+       test_must_fail git ls-tree -r HEAD
+'
+
+test_done
index 9e69c8c926620f06343e64e7b3aa3e4ada5a6b69..7633930bb472e1c9aebf2799f3eaf3bc53c7263c 100755 (executable)
@@ -98,6 +98,18 @@ test_expect_success 'git branch -m q r/q should fail when r exists' '
        test_must_fail git branch -m q r/q
 '
 
+test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
+       git branch bar &&
+       git checkout -b foo &&
+       test_must_fail git branch -M bar foo
+'
+
+test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
+       git checkout -b baz &&
+       git branch bam &&
+       git branch -M baz bam
+'
+
 mv .git/config .git/config-saved
 
 test_expect_success 'git branch -m q q2 without config should succeed' '
@@ -542,4 +554,17 @@ test_expect_success 'attempt to delete a branch merged to its base' '
        test_must_fail git branch -d my10
 '
 
+test_expect_success 'use set-upstream on the current branch' '
+       git checkout master &&
+       git --bare init myupstream.git &&
+       git push myupstream.git master:refs/heads/frotz &&
+       git remote add origin myupstream.git &&
+       git fetch &&
+       git branch --set-upstream master origin/frotz &&
+
+       test "z$(git config branch.master.remote)" = "zorigin" &&
+       test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
+
+'
+
 test_done
index 2ea3be6546f43fd5c224aa8df6add96fa9df6ac2..1aa366a410e9a3e2ad4c2fa84431198fbb553a5f 100755 (executable)
@@ -26,13 +26,13 @@ test_expect_success 'example 1: notes to add an Acked-by line' '
 '
 
 test_expect_success 'example 2: binary notes' '
-       cp "$TEST_DIRECTORY"/test4012.png . &&
+       cp "$TEST_DIRECTORY"/test-binary-1.png . &&
        git checkout B &&
-       blob=$(git hash-object -w test4012.png) &&
+       blob=$(git hash-object -w test-binary-1.png) &&
        git notes --ref=logo add -C "$blob" &&
        git notes --ref=logo copy B C &&
        git notes --ref=logo show C >actual &&
-       test_cmp test4012.png actual
+       test_cmp test-binary-1.png actual
 '
 
 test_done
index 8538813d1d0dfa72008da1d711cf2c042796a6ee..b981572d736a1adf8da5281f31e580982e2059af 100755 (executable)
@@ -527,6 +527,20 @@ test_expect_success 'auto-amend only edited commits after "edit"' '
        git rebase --abort
 '
 
+test_expect_success 'clean error after failed "exec"' '
+       test_tick &&
+       test_when_finished "git rebase --abort || :" &&
+       (
+               FAKE_LINES="1 exec_false" &&
+               export FAKE_LINES &&
+               test_must_fail git rebase -i HEAD^
+       ) &&
+       echo "edited again" > file7 &&
+       git add file7 &&
+       test_must_fail git rebase --continue 2>error &&
+       grep "You have staged changes in your working tree." error
+'
+
 test_expect_success 'rebase a detached HEAD' '
        grandparent=$(git rev-parse HEAD~2) &&
        git checkout $(git rev-parse HEAD) &&
index 9aefe3a1becac200f2c29beee84fab278f9fcfa0..e27f39d1e5b0fb0ac3a1fc6417f0f3240934f07d 100755 (executable)
@@ -16,12 +16,20 @@ test_expect_success setup '
        echo second > file2 &&
        git add file2 &&
        test_tick &&
-       git commit -m "second"
+       git commit -m "second" &&
+
+       git symbolic-ref HEAD refs/heads/third &&
+       rm .git/index file2 &&
+       echo third > file3 &&
+       git add file3 &&
+       test_tick &&
+       git commit -m "third"
 
 '
 
 test_expect_success 'cherry-pick a root commit' '
 
+       git checkout second^0 &&
        git cherry-pick master &&
        echo first >expect &&
        test_cmp expect file1
@@ -50,4 +58,21 @@ test_expect_success 'revert a root commit with an external strategy' '
 
 '
 
+test_expect_success 'cherry-pick two root commits' '
+
+       echo first >expect.file1 &&
+       echo second >expect.file2 &&
+       echo third >expect.file3 &&
+
+       git checkout second^0 &&
+       git cherry-pick master third &&
+
+       test_cmp expect.file1 file1 &&
+       test_cmp expect.file2 file2 &&
+       test_cmp expect.file3 file3 &&
+       git rev-parse --verify HEAD^^ &&
+       test_must_fail git rev-parse --verify HEAD^^^
+
+'
+
 test_done
index c06a5ee7660c3fd7ca15860cfb761b2c4d953e08..1f62c151b0aa63b4c85f9bc76f501d53967b0260 100755 (executable)
@@ -147,7 +147,7 @@ test_commit_autosquash_flags () {
                git commit -a -m "intermediate commit" &&
                test_tick &&
                echo $H $flag >>F &&
-               git commit -a --$flag HEAD~1 $3 &&
+               git commit -a --$flag HEAD~1 &&
                E=$(git cat-file commit '$H-$flag' |
                        sed -ne "s/^encoding //p") &&
                test "z$E" = "z$H" &&
@@ -160,6 +160,6 @@ test_commit_autosquash_flags () {
 
 test_commit_autosquash_flags eucJP fixup
 
-test_commit_autosquash_flags ISO-2022-JP squash '-m "squash message"'
+test_commit_autosquash_flags ISO-2022-JP squash
 
 test_done
index da82b655b3b33520b2c39d3992bc40368bf652be..534ee08a44b9d8501b234f228302e9a266d67f8c 100755 (executable)
@@ -10,8 +10,6 @@ test_description='quoted output'
 FN='濱野'
 GN='純'
 HT='   '
-LF='
-'
 DQ='"'
 
 echo foo 2>/dev/null > "Name and an${HT}HT"
index 7197aae1ed10add49aa72748188fecb4c2ef90a4..fcdb18217a777f5dbb77b0071af7159c6985656d 100755 (executable)
@@ -542,7 +542,7 @@ test_expect_success 'ref with non-existent reflog' '
        echo bar6 > file2 &&
        git add file2 &&
        git stash &&
-       ! "git rev-parse --quiet --verify does-not-exist" &&
+       test_must_fail git rev-parse --quiet --verify does-not-exist &&
        test_must_fail git stash drop does-not-exist &&
        test_must_fail git stash drop does-not-exist@{0} &&
        test_must_fail git stash pop does-not-exist &&
index 05ec0628322ccc103343515feb70d27a9a0e6c76..2d9f9a0cf1555cab24af19f264d495e134c27352 100755 (executable)
@@ -12,7 +12,7 @@ test_expect_success 'prepare repository' \
        'echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d &&
         git update-index --add a b c d &&
         echo git >a &&
-        cat "$TEST_DIRECTORY"/test4012.png >b &&
+        cat "$TEST_DIRECTORY"/test-binary-1.png >b &&
         echo git >c &&
         cat b b >d'
 
index 92248d24c48a65ab89a5b0ad255357f6034e6ad4..67975129bc3703e16fe52eb916c2e08b7908ff87 100755 (executable)
@@ -179,12 +179,21 @@ test_expect_success 'configuration To: header' '
        grep "^To: R. E. Cipient <rcipient@example.com>\$" patch9
 '
 
+# check_patch <patch>: Verify that <patch> looks like a half-sane
+# patch email to avoid a false positive with !grep
+check_patch () {
+       grep -e "^From:" "$1" &&
+       grep -e "^Date:" "$1" &&
+       grep -e "^Subject:" "$1"
+}
+
 test_expect_success '--no-to overrides config.to' '
 
        git config --replace-all format.to \
                "R. E. Cipient <rcipient@example.com>" &&
        git format-patch --no-to --stdout master..side |
        sed -e "/^\$/q" >patch10 &&
+       check_patch patch10 &&
        ! grep "^To: R. E. Cipient <rcipient@example.com>\$" patch10
 '
 
@@ -195,6 +204,7 @@ test_expect_success '--no-to and --to replaces config.to' '
        git format-patch --no-to --to="Someone Else <else@out.there>" \
                --stdout master..side |
        sed -e "/^\$/q" >patch11 &&
+       check_patch patch11 &&
        ! grep "^To: Someone <someone@out.there>\$" patch11 &&
        grep "^To: Someone Else <else@out.there>\$" patch11
 '
@@ -205,15 +215,17 @@ test_expect_success '--no-cc overrides config.cc' '
                "C. E. Cipient <rcipient@example.com>" &&
        git format-patch --no-cc --stdout master..side |
        sed -e "/^\$/q" >patch12 &&
+       check_patch patch12 &&
        ! grep "^Cc: C. E. Cipient <rcipient@example.com>\$" patch12
 '
 
-test_expect_success '--no-add-headers overrides config.headers' '
+test_expect_success '--no-add-header overrides config.headers' '
 
        git config --replace-all format.headers \
                "Header1: B. E. Cipient <rcipient@example.com>" &&
-       git format-patch --no-add-headers --stdout master..side |
+       git format-patch --no-add-header --stdout master..side |
        sed -e "/^\$/q" >patch13 &&
+       check_patch patch13 &&
        ! grep "^Header1: B. E. Cipient <rcipient@example.com>\$" patch13
 '
 
@@ -445,22 +457,22 @@ test_expect_success 'thread deep cover-letter in-reply-to' '
 '
 
 test_expect_success 'thread via config' '
-       git config format.thread true &&
+       test_config format.thread true &&
        check_threading expect.thread master
 '
 
 test_expect_success 'thread deep via config' '
-       git config format.thread deep &&
+       test_config format.thread deep &&
        check_threading expect.deep master
 '
 
 test_expect_success 'thread config + override' '
-       git config format.thread deep &&
+       test_config format.thread deep &&
        check_threading expect.thread --thread master
 '
 
 test_expect_success 'thread config + --no-thread' '
-       git config format.thread deep &&
+       test_config format.thread deep &&
        check_threading expect.no-threading --no-thread master
 '
 
@@ -480,6 +492,7 @@ test_expect_success 'cover-letter inherits diff options' '
        git mv file foo &&
        git commit -m foo &&
        git format-patch --cover-letter -1 &&
+       check_patch 0000-cover-letter.patch &&
        ! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
        git format-patch --cover-letter -1 -M &&
        grep "file => foo .* 0 *\$" 0000-cover-letter.patch
@@ -657,6 +670,7 @@ test_expect_success 'format-patch --no-signature ignores format.signature' '
        git config format.signature "config sig" &&
        git format-patch --stdout --signature="my sig" --no-signature \
                -1 >output &&
+       check_patch output &&
        ! grep "config sig" output &&
        ! grep "my sig" output &&
        ! grep "^-- \$" output
@@ -673,17 +687,20 @@ test_expect_success 'format-patch --signature --cover-letter' '
 test_expect_success 'format.signature="" supresses signatures' '
        git config format.signature "" &&
        git format-patch --stdout -1 >output &&
+       check_patch output &&
        ! grep "^-- \$" output
 '
 
 test_expect_success 'format-patch --no-signature supresses signatures' '
        git config --unset-all format.signature &&
        git format-patch --stdout --no-signature -1 >output &&
+       check_patch output &&
        ! grep "^-- \$" output
 '
 
 test_expect_success 'format-patch --signature="" supresses signatures' '
-       git format-patch --signature="" -1 >output &&
+       git format-patch --stdout --signature="" -1 >output &&
+       check_patch output &&
        ! grep "^-- \$" output
 '
 
@@ -869,4 +886,12 @@ test_expect_success 'empty subject prefix does not have extra space' '
        test_cmp expect actual
 '
 
+test_expect_success 'format patch ignores color.ui' '
+       test_unconfig color.ui &&
+       git format-patch --stdout -1 >expect &&
+       test_config color.ui always &&
+       git format-patch --stdout -1 >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 1eb14989df0bffe7d41111607d67da6a90c1fbf5..3c9932edf3f3dd44eaef98c0509a6cbe4b0091f5 100755 (executable)
 test_description='patience diff algorithm'
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-diff-alternative.sh
 
-cat >file1 <<\EOF
-#include <stdio.h>
+test_diff_frobnitz "patience"
 
-// Frobs foo heartily
-int frobnitz(int foo)
-{
-    int i;
-    for(i = 0; i < 10; i++)
-    {
-        printf("Your answer is: ");
-        printf("%d\n", foo);
-    }
-}
-
-int fact(int n)
-{
-    if(n > 1)
-    {
-        return fact(n-1) * n;
-    }
-    return 1;
-}
-
-int main(int argc, char **argv)
-{
-    frobnitz(fact(10));
-}
-EOF
-
-cat >file2 <<\EOF
-#include <stdio.h>
-
-int fib(int n)
-{
-    if(n > 2)
-    {
-        return fib(n-1) + fib(n-2);
-    }
-    return 1;
-}
-
-// Frobs foo heartily
-int frobnitz(int foo)
-{
-    int i;
-    for(i = 0; i < 10; i++)
-    {
-        printf("%d\n", foo);
-    }
-}
-
-int main(int argc, char **argv)
-{
-    frobnitz(fib(10));
-}
-EOF
-
-cat >expect <<\EOF
-diff --git a/file1 b/file2
-index 6faa5a3..e3af329 100644
---- a/file1
-+++ b/file2
-@@ -1,26 +1,25 @@
- #include <stdio.h>
-+int fib(int n)
-+{
-+    if(n > 2)
-+    {
-+        return fib(n-1) + fib(n-2);
-+    }
-+    return 1;
-+}
-+
- // Frobs foo heartily
- int frobnitz(int foo)
- {
-     int i;
-     for(i = 0; i < 10; i++)
-     {
--        printf("Your answer is: ");
-         printf("%d\n", foo);
-     }
- }
--int fact(int n)
--{
--    if(n > 1)
--    {
--        return fact(n-1) * n;
--    }
--    return 1;
--}
--
- int main(int argc, char **argv)
- {
--    frobnitz(fact(10));
-+    frobnitz(fib(10));
- }
-EOF
-
-test_expect_success 'patience diff' '
-
-       test_must_fail git diff --no-index --patience file1 file2 > output &&
-       test_cmp expect output
-
-'
-
-test_expect_success 'patience diff output is valid' '
-
-       mv file2 expect &&
-       git apply < output &&
-       test_cmp expect file2
-
-'
-
-cat >uniq1 <<\EOF
-1
-2
-3
-4
-5
-6
-EOF
-
-cat >uniq2 <<\EOF
-a
-b
-c
-d
-e
-f
-EOF
-
-cat >expect <<\EOF
-diff --git a/uniq1 b/uniq2
-index b414108..0fdf397 100644
---- a/uniq1
-+++ b/uniq2
-@@ -1,6 +1,6 @@
--1
--2
--3
--4
--5
--6
-+a
-+b
-+c
-+d
-+e
-+f
-EOF
-
-test_expect_success 'completely different files' '
-
-       test_must_fail git diff --no-index --patience uniq1 uniq2 > output &&
-       test_cmp expect output
-
-'
+test_diff_unique "patience"
 
 test_done
diff --git a/t/t4050-diff-histogram.sh b/t/t4050-diff-histogram.sh
new file mode 100755 (executable)
index 0000000..fd3e86a
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+test_description='histogram diff algorithm'
+
+. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-diff-alternative.sh
+
+test_diff_frobnitz "histogram"
+
+test_diff_unique "histogram"
+
+test_done
index 151404e0908c55f3c0d399d03225b077dc226562..d7d9ccc1c8c31ef3b2d4763532344d0637a18b5c 100755 (executable)
@@ -96,6 +96,13 @@ test_expect_success setup '
                echo "X-Fake-Field: Line Three" &&
                git format-patch --stdout first | sed -e "1d"
        } | append_cr >patch1-crlf.eml &&
+       {
+               printf "%255s\\n" ""
+               echo "X-Fake-Field: Line One" &&
+               echo "X-Fake-Field: Line Two" &&
+               echo "X-Fake-Field: Line Three" &&
+               git format-patch --stdout first | sed -e "1d"
+       } > patch1-ws.eml &&
 
        sed -n -e "3,\$p" msg >file &&
        git add file &&
@@ -167,6 +174,17 @@ test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
        test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
 '
 
+test_expect_success 'am applies patch e-mail with preceding whitespace' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout first &&
+       git am patch1-ws.eml &&
+       ! test -d .git/rebase-apply &&
+       git diff --exit-code second &&
+       test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
+       test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
+'
+
 test_expect_success 'setup: new author and committer' '
        GIT_AUTHOR_NAME="Another Thor" &&
        GIT_AUTHOR_EMAIL="a.thor@example.com" &&
diff --git a/t/t4254-am-corrupt.sh b/t/t4254-am-corrupt.sh
new file mode 100755 (executable)
index 0000000..b7da95f
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+test_description='git am with corrupt input'
+. ./test-lib.sh
+
+# Note the missing "+++" line:
+cat > bad-patch.diff <<'EOF'
+From: A U Thor <au.thor@example.com>
+diff --git a/f b/f
+index 7898192..6178079 100644
+--- a/f
+@@ -1 +1 @@
+-a
++b
+EOF
+
+test_expect_success setup '
+       test $? = 0 &&
+       echo a > f &&
+       git add f &&
+       test_tick &&
+       git commit -m initial
+'
+
+# This used to fail before, too, but with a different diagnostic.
+#   fatal: unable to write file '(null)' mode 100644: Bad address
+# Also, it had the unwanted side-effect of deleting f.
+test_expect_success 'try to apply corrupted patch' '
+       git am bad-patch.diff 2> actual
+       test $? = 1
+'
+
+cat > expected <<EOF
+fatal: git diff header lacks filename information (line 4)
+EOF
+
+test_expect_success 'compare diagnostic; ensure file is still here' '
+       test $? = 0 &&
+       test -f f &&
+       test_cmp expected actual
+'
+
+test_done
index 9e3ba98fc8d6f0242af38c3f7dc062e6c6ab9604..d9068981f8475c37d30e584bc6b795075a2f3063 100755 (executable)
@@ -266,7 +266,7 @@ test_expect_success 'archive --list mentions user filter' '
        grep "^bar\$" output
 '
 
-test_expect_success 'archive --list shows only enabled remote filters' '
+test_expect_success NOT_MINGW 'archive --list shows only enabled remote filters' '
        git archive --list --remote=. >output &&
        ! grep "^tar\.foo\$" output &&
        grep "^bar\$" output
@@ -298,7 +298,7 @@ test_expect_success 'extension matching requires dot' '
        test_cmp b.tar config-implicittar.foo
 '
 
-test_expect_success 'only enabled filters are available remotely' '
+test_expect_success NOT_MINGW 'only enabled filters are available remotely' '
        test_must_fail git archive --remote=. --format=tar.foo HEAD \
                >remote.tar.foo &&
        git archive --remote=. --format=bar >remote.bar HEAD &&
@@ -341,12 +341,12 @@ test_expect_success GZIP,GUNZIP 'extract tgz file' '
        test_cmp b.tar j.tar
 '
 
-test_expect_success GZIP 'remote tar.gz is allowed by default' '
+test_expect_success GZIP,NOT_MINGW 'remote tar.gz is allowed by default' '
        git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
        test_cmp j.tgz remote.tar.gz
 '
 
-test_expect_success GZIP 'remote tar.gz can be disabled' '
+test_expect_success GZIP,NOT_MINGW 'remote tar.gz can be disabled' '
        git config tar.tar.gz.remote false &&
        test_must_fail git archive --remote=. --format=tar.gz HEAD \
                >remote.tar.gz
index 0d0222ea2ace733ffe3fbfbdee58520abcd40e92..e8af615e6dcdf365416ef9f71825c17a0d601186 100755 (executable)
@@ -631,6 +631,37 @@ test_expect_success 'rename a remote' '
 
 '
 
+test_expect_success 'rename does not update a non-default fetch refspec' '
+
+       git clone one four.one &&
+       (cd four.one &&
+        git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
+        git remote rename origin upstream &&
+        test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
+        git rev-parse -q origin/master)
+
+'
+
+test_expect_success 'rename a remote with name part of fetch spec' '
+
+       git clone one four.two &&
+       (cd four.two &&
+        git remote rename origin remote &&
+        git remote rename remote upstream &&
+        test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*")
+
+'
+
+test_expect_success 'rename a remote with name prefix of other remote' '
+
+       git clone one four.three &&
+       (cd four.three &&
+        git remote add o git://example.com/repo.git &&
+        git remote rename o upstream &&
+        test "$(git rev-parse origin/master)" = "$(git rev-parse master)")
+
+'
+
 cat > remotes_origin << EOF
 URL: $(pwd)/one
 Push: refs/heads/master:refs/heads/upstream
diff --git a/t/t5509-fetch-push-namespaces.sh b/t/t5509-fetch-push-namespaces.sh
new file mode 100755 (executable)
index 0000000..cc0b31f
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/sh
+
+test_description='fetch/push involving ref namespaces'
+. ./test-lib.sh
+
+test_expect_success setup '
+       test_tick &&
+       git init original &&
+       (
+               cd original &&
+               echo 0 >count &&
+               git add count &&
+               test_commit 0 &&
+               echo 1 >count &&
+               git add count &&
+               test_commit 1 &&
+               git remote add pushee-namespaced "ext::git --namespace=namespace %s ../pushee" &&
+               git remote add pushee-unnamespaced ../pushee
+       ) &&
+       commit0=$(cd original && git rev-parse HEAD^) &&
+       commit1=$(cd original && git rev-parse HEAD) &&
+       git init pushee &&
+       git init puller
+'
+
+test_expect_success 'pushing into a repository using a ref namespace' '
+       (
+               cd original &&
+               git push pushee-namespaced master &&
+               git ls-remote pushee-namespaced >actual &&
+               printf "$commit1\trefs/heads/master\n" >expected &&
+               test_cmp expected actual &&
+               git push pushee-namespaced --tags &&
+               git ls-remote pushee-namespaced >actual &&
+               printf "$commit0\trefs/tags/0\n" >>expected &&
+               printf "$commit1\trefs/tags/1\n" >>expected &&
+               test_cmp expected actual &&
+               # Verify that the GIT_NAMESPACE environment variable works as well
+               GIT_NAMESPACE=namespace git ls-remote "ext::git %s ../pushee" >actual &&
+               test_cmp expected actual &&
+               # Verify that --namespace overrides GIT_NAMESPACE
+               GIT_NAMESPACE=garbage git ls-remote pushee-namespaced >actual &&
+               test_cmp expected actual &&
+               # Try a namespace with no content
+               git ls-remote "ext::git --namespace=garbage %s ../pushee" >actual &&
+               test_cmp /dev/null actual &&
+               git ls-remote pushee-unnamespaced >actual &&
+               sed -e "s|refs/|refs/namespaces/namespace/refs/|" expected >expected.unnamespaced &&
+               test_cmp expected.unnamespaced actual
+       )
+'
+
+test_expect_success 'pulling from a repository using a ref namespace' '
+       (
+               cd puller &&
+               git remote add -f pushee-namespaced "ext::git --namespace=namespace %s ../pushee" &&
+               git for-each-ref refs/ >actual &&
+               printf "$commit1 commit\trefs/remotes/pushee-namespaced/master\n" >expected &&
+               printf "$commit0 commit\trefs/tags/0\n" >>expected &&
+               printf "$commit1 commit\trefs/tags/1\n" >>expected &&
+               test_cmp expected actual
+       )
+'
+
+# This test with clone --mirror checks for possible regressions in clone
+# or the machinery underneath it. It ensures that no future change
+# causes clone to ignore refs in refs/namespaces/*. In particular, it
+# protects against a regression caused by any future change to the refs
+# machinery that might cause it to ignore refs outside of refs/heads/*
+# or refs/tags/*. More generally, this test also checks the high-level
+# functionality of using clone --mirror to back up a set of repos hosted
+# in the namespaces of a single repo.
+test_expect_success 'mirroring a repository using a ref namespace' '
+       git clone --mirror pushee mirror &&
+       (
+               cd mirror &&
+               git for-each-ref refs/ >actual &&
+               printf "$commit1 commit\trefs/namespaces/namespace/refs/heads/master\n" >expected &&
+               printf "$commit0 commit\trefs/namespaces/namespace/refs/tags/0\n" >>expected &&
+               printf "$commit1 commit\trefs/namespaces/namespace/refs/tags/1\n" >>expected &&
+               test_cmp expected actual
+       )
+'
+
+test_done
index 7e433b179f9fcb0b3ccdd0ec83c6ec850735e391..e0af4c4e62c40a563f692361944cc58e2c8e38e2 100755 (executable)
@@ -76,6 +76,56 @@ test_expect_success "fetch test for-merge" '
        cut -f -2 .git/FETCH_HEAD >actual &&
        test_cmp expected actual'
 
+test_expect_success 'fetch --prune on its own works as expected' '
+       cd "$D" &&
+       git clone . prune &&
+       cd prune &&
+       git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
+
+       git fetch --prune origin &&
+       test_must_fail git rev-parse origin/extrabranch
+'
+
+test_expect_success 'fetch --prune with a branch name keeps branches' '
+       cd "$D" &&
+       git clone . prune-branch &&
+       cd prune-branch &&
+       git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
+
+       git fetch --prune origin master &&
+       git rev-parse origin/extrabranch
+'
+
+test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
+       cd "$D" &&
+       git clone . prune-namespace &&
+       cd prune-namespace &&
+
+       git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
+       git rev-parse origin/master
+'
+
+test_expect_success 'fetch --prune --tags does not delete the remote-tracking branches' '
+       cd "$D" &&
+       git clone . prune-tags &&
+       cd prune-tags &&
+       git fetch origin refs/heads/master:refs/tags/sometag &&
+
+       git fetch --prune --tags origin &&
+       git rev-parse origin/master &&
+       test_must_fail git rev-parse somebranch
+'
+
+test_expect_success 'fetch --prune --tags with branch does not delete other remote-tracking branches' '
+       cd "$D" &&
+       git clone . prune-tags-branch &&
+       cd prune-tags-branch &&
+       git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
+
+       git fetch --prune --tags origin master &&
+       git rev-parse origin/extrabranch
+'
+
 test_expect_success 'fetch tags when there is no tags' '
 
     cd "$D" &&
index faa2e9633783e96609f4a31beb4bcccedb876338..30bec4b5f9f286cd97c57b70e3635c6c5c8cf85a 100755 (executable)
@@ -32,4 +32,91 @@ test_expect_success push '
        )
 '
 
+test_expect_success 'push if submodule has no remote' '
+       (
+               cd work/gar/bage &&
+               >junk2 &&
+               git add junk2 &&
+               git commit -m "Second junk"
+       ) &&
+       (
+               cd work &&
+               git add gar/bage &&
+               git commit -m "Second commit for gar/bage" &&
+               git push --recurse-submodules=check ../pub.git master
+       )
+'
+
+test_expect_success 'push fails if submodule commit not on remote' '
+       (
+               cd work/gar &&
+               git clone --bare bage ../../submodule.git &&
+               cd bage &&
+               git remote add origin ../../../submodule.git &&
+               git fetch &&
+               >junk3 &&
+               git add junk3 &&
+               git commit -m "Third junk"
+       ) &&
+       (
+               cd work &&
+               git add gar/bage &&
+               git commit -m "Third commit for gar/bage" &&
+               test_must_fail git push --recurse-submodules=check ../pub.git master
+       )
+'
+
+test_expect_success 'push succeeds after commit was pushed to remote' '
+       (
+               cd work/gar/bage &&
+               git push origin master
+       ) &&
+       (
+               cd work &&
+               git push --recurse-submodules=check ../pub.git master
+       )
+'
+
+test_expect_success 'push fails when commit on multiple branches if one branch has no remote' '
+       (
+               cd work/gar/bage &&
+               >junk4 &&
+               git add junk4 &&
+               git commit -m "Fourth junk"
+       ) &&
+       (
+               cd work &&
+               git branch branch2 &&
+               git add gar/bage &&
+               git commit -m "Fourth commit for gar/bage" &&
+               git checkout branch2 &&
+               (
+                       cd gar/bage &&
+                       git checkout HEAD~1
+               ) &&
+               >junk1 &&
+               git add junk1 &&
+               git commit -m "First junk" &&
+               test_must_fail git push --recurse-submodules=check ../pub.git
+       )
+'
+
+test_expect_success 'push succeeds if submodule has no remote and is on the first superproject commit' '
+       git init --bare a
+       git clone a a1 &&
+       (
+               cd a1 &&
+               git init b
+               (
+                       cd b &&
+                       >junk &&
+                       git add junk &&
+                       git commit -m "initial"
+               ) &&
+               git add b &&
+               git commit -m "added submodule" &&
+               git push --recurse-submodule=check origin master
+       )
+'
+
 test_done
index a266ca56361347fe751495e1531b5a26e4733493..64767d87055c9ad65a225432b5193497c9fad405 100755 (executable)
@@ -132,8 +132,12 @@ x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
 x40="$x38$x2"
 
 test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
-       sed -e "s/PUT /OP /" -e "s/MOVE /OP /" "$HTTPD_ROOT_PATH"/access.log |
-       grep -e "\"OP .*/objects/$x2/${x38}_$x40 HTTP/[.0-9]*\" 20[0-9] "
+       sed \
+               -e "s/PUT /OP /" \
+               -e "s/MOVE /OP /" \
+           -e "s|/objects/$x2/${x38}_$x40|WANTED_PATH_REQUEST|" \
+               "$HTTPD_ROOT_PATH"/access.log |
+       grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "
 
 '
 
index 151ea531bdfeb5a012e57407749beb4f26de6d2a..e8103144bb026afb12f5b058b9ec399b70abebbd 100755 (executable)
@@ -202,9 +202,36 @@ test_expect_success 'clone separate gitdir: output' '
        test_cmp expected dst/.git
 '
 
+test_expect_success 'clone from .git file' '
+       git clone dst/.git dst2
+'
+
 test_expect_success 'clone separate gitdir where target already exists' '
        rm -rf dst &&
        test_must_fail git clone --separate-git-dir realgitdir src dst
 '
 
+test_expect_success 'clone --reference from original' '
+       git clone --shared --bare src src-1 &&
+       git clone --bare src src-2 &&
+       git clone --reference=src-2 --bare src-1 target-8 &&
+       grep /src-2/ target-8/objects/info/alternates
+'
+
+test_expect_success 'clone with more than one --reference' '
+       git clone --bare src src-3 &&
+       git clone --bare src src-4 &&
+       git clone --reference=src-3 --reference=src-4 src target-9 &&
+       grep /src-3/ target-9/.git/objects/info/alternates &&
+       grep /src-4/ target-9/.git/objects/info/alternates
+'
+
+test_expect_success 'clone from original with relative alternate' '
+       mkdir nest &&
+       git clone --bare src nest/src-5 &&
+       echo ../../../src/.git/objects >nest/src-5/objects/info/alternates &&
+       git clone --bare nest/src-5 target-10 &&
+       grep /src/\\.git/objects target-10/objects/info/alternates
+'
+
 test_done
diff --git a/t/t5707-clone-detached.sh b/t/t5707-clone-detached.sh
new file mode 100755 (executable)
index 0000000..8b0d607
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/sh
+
+test_description='test cloning a repository with detached HEAD'
+. ./test-lib.sh
+
+head_is_detached() {
+       git --git-dir=$1/.git rev-parse --verify HEAD &&
+       test_must_fail git --git-dir=$1/.git symbolic-ref HEAD
+}
+
+test_expect_success 'setup' '
+       echo one >file &&
+       git add file &&
+       git commit -m one &&
+       echo two >file &&
+       git commit -a -m two &&
+       git tag two &&
+       echo three >file &&
+       git commit -a -m three
+'
+
+test_expect_success 'clone repo (detached HEAD points to branch)' '
+       git checkout master^0 &&
+       git clone "file://$PWD" detached-branch
+'
+test_expect_success 'cloned HEAD matches' '
+       echo three >expect &&
+       git --git-dir=detached-branch/.git log -1 --format=%s >actual &&
+       test_cmp expect actual
+'
+test_expect_failure 'cloned HEAD is detached' '
+       head_is_detached detached-branch
+'
+
+test_expect_success 'clone repo (detached HEAD points to tag)' '
+       git checkout two^0 &&
+       git clone "file://$PWD" detached-tag
+'
+test_expect_success 'cloned HEAD matches' '
+       echo two >expect &&
+       git --git-dir=detached-tag/.git log -1 --format=%s >actual &&
+       test_cmp expect actual
+'
+test_expect_success 'cloned HEAD is detached' '
+       head_is_detached detached-tag
+'
+
+test_expect_success 'clone repo (detached HEAD points to history)' '
+       git checkout two^ &&
+       git clone "file://$PWD" detached-history
+'
+test_expect_success 'cloned HEAD matches' '
+       echo one >expect &&
+       git --git-dir=detached-history/.git log -1 --format=%s >actual &&
+       test_cmp expect actual
+'
+test_expect_success 'cloned HEAD is detached' '
+       head_is_detached detached-history
+'
+
+test_expect_success 'clone repo (orphan detached HEAD)' '
+       git checkout master^0 &&
+       echo four >file &&
+       git commit -a -m four &&
+       git clone "file://$PWD" detached-orphan
+'
+test_expect_success 'cloned HEAD matches' '
+       echo four >expect &&
+       git --git-dir=detached-orphan/.git log -1 --format=%s >actual &&
+       test_cmp expect actual
+'
+test_expect_success 'cloned HEAD is detached' '
+       head_is_detached detached-orphan
+'
+
+test_done
index 1fb6380fceb294f1a7cc73359f5e39740260d8f0..1c62001fce76a73cc951dd18bcf6cb6f650f69e8 100755 (executable)
@@ -7,17 +7,27 @@ test_description='Test remote-helper import and export commands'
 
 . ./test-lib.sh
 
-if test_have_prereq PYTHON && "$PYTHON_PATH" -c '
+if ! test_have_prereq PYTHON ; then
+       skip_all='skipping git-remote-hg tests, python not available'
+       test_done
+fi
+
+"$PYTHON_PATH" -c '
 import sys
 if sys.hexversion < 0x02040000:
     sys.exit(1)
-'
-then
-    # Requires Python 2.4 or newer
-       test_set_prereq PYTHON_24
-fi
+' || {
+       skip_all='skipping git-remote-hg tests, python version < 2.4'
+       test_done
+}
+
+compare_refs() {
+       git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
+       git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
+       test_cmp expect actual
+}
 
-test_expect_success PYTHON_24 'setup repository' '
+test_expect_success 'setup repository' '
        git init --bare server/.git &&
        git clone server public &&
        (cd public &&
@@ -27,54 +37,99 @@ test_expect_success PYTHON_24 'setup repository' '
         git push origin master)
 '
 
-test_expect_success PYTHON_24 'cloning from local repo' '
+test_expect_success 'cloning from local repo' '
        git clone "testgit::${PWD}/server" localclone &&
        test_cmp public/file localclone/file
 '
 
-test_expect_success PYTHON_24 'cloning from remote repo' '
+test_expect_success 'cloning from remote repo' '
        git clone "testgit::file://${PWD}/server" clone &&
        test_cmp public/file clone/file
 '
 
-test_expect_success PYTHON_24 'create new commit on remote' '
+test_expect_success 'create new commit on remote' '
        (cd public &&
         echo content >>file &&
         git commit -a -m two &&
         git push)
 '
 
-test_expect_success PYTHON_24 'pulling from local repo' '
+test_expect_success 'pulling from local repo' '
        (cd localclone && git pull) &&
        test_cmp public/file localclone/file
 '
 
-test_expect_success PYTHON_24 'pulling from remote remote' '
+test_expect_success 'pulling from remote remote' '
        (cd clone && git pull) &&
        test_cmp public/file clone/file
 '
 
-test_expect_success PYTHON_24 'pushing to local repo' '
+test_expect_success 'pushing to local repo' '
        (cd localclone &&
        echo content >>file &&
        git commit -a -m three &&
        git push) &&
-       HEAD=$(git --git-dir=localclone/.git rev-parse --verify HEAD) &&
-       test $HEAD = $(git --git-dir=server/.git rev-parse --verify HEAD)
+       compare_refs localclone HEAD server HEAD
 '
 
-test_expect_success PYTHON_24 'synch with changes from localclone' '
+test_expect_success 'synch with changes from localclone' '
        (cd clone &&
         git pull)
 '
 
-test_expect_success PYTHON_24 'pushing remote local repo' '
+test_expect_success 'pushing remote local repo' '
        (cd clone &&
        echo content >>file &&
        git commit -a -m four &&
        git push) &&
-       HEAD=$(git --git-dir=clone/.git rev-parse --verify HEAD) &&
-       test $HEAD = $(git --git-dir=server/.git rev-parse --verify HEAD)
+       compare_refs clone HEAD server HEAD
+'
+
+test_expect_success 'fetch new branch' '
+       (cd public &&
+        git checkout -b new &&
+        echo content >>file &&
+        git commit -a -m five &&
+        git push origin new
+       ) &&
+       (cd localclone &&
+        git fetch origin new
+       ) &&
+       compare_refs public HEAD localclone FETCH_HEAD
+'
+
+test_expect_success 'fetch multiple branches' '
+       (cd localclone &&
+        git fetch
+       ) &&
+       compare_refs server master localclone refs/remotes/origin/master &&
+       compare_refs server new localclone refs/remotes/origin/new
+'
+
+test_expect_success 'push when remote has extra refs' '
+       (cd clone &&
+        echo content >>file &&
+        git commit -a -m six &&
+        git push
+       ) &&
+       compare_refs clone master server master
+'
+
+test_expect_success 'push new branch by name' '
+       (cd clone &&
+        git checkout -b new-name  &&
+        echo content >>file &&
+        git commit -a -m seven &&
+        git push origin new-name
+       ) &&
+       compare_refs clone HEAD server refs/heads/new-name
+'
+
+test_expect_failure 'push new branch with old:new refspec' '
+       (cd clone &&
+        git push origin new-name:new-refspec
+       ) &&
+       compare_refs clone HEAD server refs/heads/new-refspec
 '
 
 test_done
index 76410293b34ecede219445e09b1eccb8175ee115..39b4cb0ecdc8801b355b815a0566c6e2df5c5a39 100755 (executable)
@@ -70,4 +70,42 @@ test_expect_success 'rev-list --ancestry-patch D..M -- M.t' '
        test_cmp expect actual
 '
 
+#   b---bc
+#  / \ /
+# a   X
+#  \ / \
+#   c---cb
+#
+# All refnames prefixed with 'x' to avoid confusion with the tags
+# generated by test_commit on case-insensitive systems.
+test_expect_success 'setup criss-cross' '
+       mkdir criss-cross &&
+       (cd criss-cross &&
+        git init &&
+        test_commit A &&
+        git checkout -b xb master &&
+        test_commit B &&
+        git checkout -b xc master &&
+        test_commit C &&
+        git checkout -b xbc xb -- &&
+        git merge xc &&
+        git checkout -b xcb xc -- &&
+        git merge xb &&
+        git checkout master)
+'
+
+# no commits in bc descend from cb
+test_expect_success 'criss-cross: rev-list --ancestry-path cb..bc' '
+       (cd criss-cross &&
+        git rev-list --ancestry-path xcb..xbc > actual &&
+        test -z "$(cat actual)")
+'
+
+# no commits in repository descend from cb
+test_expect_success 'criss-cross: rev-list --ancestry-path --all ^cb' '
+       (cd criss-cross &&
+        git rev-list --ancestry-path --all ^xcb > actual &&
+        test -z "$(cat actual)")
+'
+
 test_done
index eec8f4e3edd85e350f5b8d8c86415317cce2aba1..27c3d73961dfc9b50c3eafc7360662076cb31260 100755 (executable)
@@ -59,15 +59,19 @@ test_expect_success 'setup modify/delete + directory/file conflict' '
        git add letters &&
        git commit -m initial &&
 
+       # Throw in letters.txt for sorting order fun
+       # ("letters.txt" sorts between "letters" and "letters/file")
        echo i >>letters &&
-       git add letters &&
+       echo "version 2" >letters.txt &&
+       git add letters letters.txt &&
        git commit -m modified &&
 
        git checkout -b delete HEAD^ &&
        git rm letters &&
        mkdir letters &&
        >letters/file &&
-       git add letters &&
+       echo "version 1" >letters.txt &&
+       git add letters letters.txt &&
        git commit -m deleted
 '
 
@@ -75,25 +79,31 @@ test_expect_success 'modify/delete + directory/file conflict' '
        git checkout delete^0 &&
        test_must_fail git merge modify &&
 
-       test 3 = $(git ls-files -s | wc -l) &&
-       test 2 = $(git ls-files -u | wc -l) &&
-       test 1 = $(git ls-files -o | wc -l) &&
+       test 5 -eq $(git ls-files -s | wc -l) &&
+       test 4 -eq $(git ls-files -u | wc -l) &&
+       test 1 -eq $(git ls-files -o | wc -l) &&
 
        test -f letters/file &&
+       test -f letters.txt &&
        test -f letters~modify
 '
 
 test_expect_success 'modify/delete + directory/file conflict; other way' '
+       # Yes, we really need the double reset since "letters" appears as
+       # both a file and a directory.
+       git reset --hard &&
        git reset --hard &&
        git clean -f &&
        git checkout modify^0 &&
+
        test_must_fail git merge delete &&
 
-       test 3 = $(git ls-files -s | wc -l) &&
-       test 2 = $(git ls-files -u | wc -l) &&
-       test 1 = $(git ls-files -o | wc -l) &&
+       test 5 -eq $(git ls-files -s | wc -l) &&
+       test 4 -eq $(git ls-files -u | wc -l) &&
+       test 1 -eq $(git ls-files -o | wc -l) &&
 
        test -f letters/file &&
+       test -f letters.txt &&
        test -f letters~HEAD
 '
 
index 1ed259d864b4ef4c8c7060fa5f22634a25c8e032..9d8584e957a26cadda2f04d38d27fd0c4b97ae29 100755 (executable)
@@ -252,6 +252,7 @@ test_expect_success 'setup for rename + d/f conflicts' '
        git reset --hard &&
        git checkout --orphan dir-in-way &&
        git rm -rf . &&
+       git clean -fdqx &&
 
        mkdir sub &&
        mkdir dir &&
@@ -302,11 +303,11 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
        git checkout -q renamed-file-has-no-conflicts^0 &&
        test_must_fail git merge --strategy=recursive dir-in-way >output &&
 
-       grep "CONFLICT (delete/modify): dir/file-in-the-way" output &&
+       grep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
        grep "Auto-merging dir" output &&
        grep "Adding as dir~HEAD instead" output &&
 
-       test 2 -eq "$(git ls-files -u | wc -l)" &&
+       test 3 -eq "$(git ls-files -u | wc -l)" &&
        test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
 
        test_must_fail git diff --quiet &&
@@ -324,11 +325,11 @@ test_expect_success 'Same as previous, but merged other way' '
        test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors &&
 
        ! grep "error: refusing to lose untracked file at" errors &&
-       grep "CONFLICT (delete/modify): dir/file-in-the-way" output &&
+       grep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
        grep "Auto-merging dir" output &&
        grep "Adding as dir~renamed-file-has-no-conflicts instead" output &&
 
-       test 2 -eq "$(git ls-files -u | wc -l)" &&
+       test 3 -eq "$(git ls-files -u | wc -l)" &&
        test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
 
        test_must_fail git diff --quiet &&
@@ -350,11 +351,11 @@ cat >expected <<\EOF &&
 8
 9
 10
-<<<<<<< HEAD
+<<<<<<< HEAD:dir
 12
 =======
 11
->>>>>>> dir-not-in-way
+>>>>>>> dir-not-in-way:sub/file
 EOF
 
 test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
@@ -404,11 +405,11 @@ cat >expected <<\EOF &&
 8
 9
 10
-<<<<<<< HEAD
+<<<<<<< HEAD:sub/file
 11
 =======
 12
->>>>>>> renamed-file-has-conflicts
+>>>>>>> renamed-file-has-conflicts:dir
 EOF
 
 test_expect_success 'Same as previous, but merged other way' '
@@ -609,4 +610,278 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
        ! test -f original
 '
 
+test_expect_success 'setup avoid unnecessary update, normal rename' '
+       git reset --hard &&
+       git checkout --orphan avoid-unnecessary-update-1 &&
+       git rm -rf . &&
+       git clean -fdqx &&
+
+       printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
+       git add -A &&
+       git commit -m "Common commmit" &&
+
+       git mv original rename &&
+       echo 11 >>rename &&
+       git add -u &&
+       git commit -m "Renamed and modified" &&
+
+       git checkout -b merge-branch-1 HEAD~1 &&
+       echo "random content" >random-file &&
+       git add -A &&
+       git commit -m "Random, unrelated changes"
+'
+
+test_expect_success 'avoid unnecessary update, normal rename' '
+       git checkout -q avoid-unnecessary-update-1^0 &&
+       test-chmtime =1000000000 rename &&
+       test-chmtime -v +0 rename >expect &&
+       git merge merge-branch-1 &&
+       test-chmtime -v +0 rename >actual &&
+       test_cmp expect actual # "rename" should have stayed intact
+'
+
+test_expect_success 'setup to test avoiding unnecessary update, with D/F conflict' '
+       git reset --hard &&
+       git checkout --orphan avoid-unnecessary-update-2 &&
+       git rm -rf . &&
+       git clean -fdqx &&
+
+       mkdir df &&
+       printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
+       git add -A &&
+       git commit -m "Common commmit" &&
+
+       git mv df/file temp &&
+       rm -rf df &&
+       git mv temp df &&
+       echo 11 >>df &&
+       git add -u &&
+       git commit -m "Renamed and modified" &&
+
+       git checkout -b merge-branch-2 HEAD~1 &&
+       >unrelated-change &&
+       git add unrelated-change &&
+       git commit -m "Only unrelated changes"
+'
+
+test_expect_success 'avoid unnecessary update, with D/F conflict' '
+       git checkout -q avoid-unnecessary-update-2^0 &&
+       test-chmtime =1000000000 df &&
+       test-chmtime -v +0 df >expect &&
+       git merge merge-branch-2 &&
+       test-chmtime -v +0 df >actual &&
+       test_cmp expect actual # "df" should have stayed intact
+'
+
+test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       >irrelevant &&
+       mkdir df &&
+       >df/file &&
+       git add -A &&
+       git commit -mA &&
+
+       git checkout -b side
+       git rm -rf df &&
+       git commit -mB &&
+
+       git checkout master &&
+       git rm -rf df &&
+       echo bla >df &&
+       git add -A &&
+       git commit -m "Add a newfile"
+'
+
+test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
+       git checkout -q master^0 &&
+       test-chmtime =1000000000 df &&
+       test-chmtime -v +0 df >expect &&
+       git merge side &&
+       test-chmtime -v +0 df >actual &&
+       test_cmp expect actual # "df" should have stayed intact
+'
+
+test_expect_success 'setup avoid unnecessary update, modify/delete' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       >irrelevant &&
+       >file &&
+       git add -A &&
+       git commit -mA &&
+
+       git checkout -b side
+       git rm -f file &&
+       git commit -m "Delete file" &&
+
+       git checkout master &&
+       echo bla >file &&
+       git add -A &&
+       git commit -m "Modify file"
+'
+
+test_expect_success 'avoid unnecessary update, modify/delete' '
+       git checkout -q master^0 &&
+       test-chmtime =1000000000 file &&
+       test-chmtime -v +0 file >expect &&
+       test_must_fail git merge side &&
+       test-chmtime -v +0 file >actual &&
+       test_cmp expect actual # "file" should have stayed intact
+'
+
+test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
+       git add -A &&
+       git commit -mA &&
+
+       git checkout -b side
+       cp file newfile &&
+       git add -A &&
+       git commit -m "Add file copy" &&
+
+       git checkout master &&
+       git mv file newfile &&
+       git commit -m "Rename file"
+'
+
+test_expect_success 'avoid unnecessary update, rename/add-dest' '
+       git checkout -q master^0 &&
+       test-chmtime =1000000000 newfile &&
+       test-chmtime -v +0 newfile >expect &&
+       git merge side &&
+       test-chmtime -v +0 newfile >actual &&
+       test_cmp expect actual # "file" should have stayed intact
+'
+
+test_expect_success 'setup merge of rename + small change' '
+       git reset --hard &&
+       git checkout --orphan rename-plus-small-change &&
+       git rm -rf . &&
+       git clean -fdqx &&
+
+       echo ORIGINAL >file &&
+       git add file &&
+
+       test_tick &&
+       git commit -m Initial &&
+       git checkout -b rename_branch &&
+       git mv file renamed_file &&
+       git commit -m Rename &&
+       git checkout rename-plus-small-change &&
+       echo NEW-VERSION >file &&
+       git commit -a -m Reformat
+'
+
+test_expect_success 'merge rename + small change' '
+       git merge rename_branch &&
+
+       test 1 -eq $(git ls-files -s | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+       test $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)
+'
+
+test_expect_success 'setup for use of extended merge markers' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
+       git add original_file &&
+       git commit -mA &&
+
+       git checkout -b rename &&
+       echo 9 >>original_file &&
+       git add original_file &&
+       git mv original_file renamed_file &&
+       git commit -mB &&
+
+       git checkout master &&
+       echo 8.5 >>original_file &&
+       git add original_file &&
+       git commit -mC
+'
+
+cat >expected <<\EOF &&
+1
+2
+3
+4
+5
+6
+7
+8
+<<<<<<< HEAD:renamed_file
+9
+=======
+8.5
+>>>>>>> master^0:original_file
+EOF
+
+test_expect_success 'merge master into rename has correct extended markers' '
+       git checkout rename^0 &&
+       test_must_fail git merge -s recursive master^0 &&
+       test_cmp expected renamed_file
+'
+
+cat >expected <<\EOF &&
+1
+2
+3
+4
+5
+6
+7
+8
+<<<<<<< HEAD:original_file
+8.5
+=======
+9
+>>>>>>> rename^0:renamed_file
+EOF
+
+test_expect_success 'merge rename into master has correct extended markers' '
+       git reset --hard &&
+       git checkout master^0 &&
+       test_must_fail git merge -s recursive rename^0 &&
+       test_cmp expected renamed_file
+'
+
+test_expect_success 'setup spurious "refusing to lose untracked" message' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       > irrelevant_file &&
+       printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
+       git add irrelevant_file original_file &&
+       git commit -mA &&
+
+       git checkout -b rename &&
+       git mv original_file renamed_file &&
+       git commit -mB &&
+
+       git checkout master &&
+       git rm original_file &&
+       git commit -mC
+'
+
+test_expect_success 'no spurious "refusing to lose untracked" message' '
+       git checkout master^0 &&
+       test_must_fail git merge rename^0 2>errors.txt &&
+       ! grep "refusing to lose untracked file" errors.txt
+'
+
 test_done
index d9f343942c7eb9d1e80e98db2252cb29135544fa..432f086c063198e82ad8a2f7c8dd175a8685fdf5 100755 (executable)
@@ -154,7 +154,7 @@ test_expect_success "expected conflict markers" "test_cmp expect out"
 
 test_expect_success 'binary files cannot be merged' '
        test_must_fail git merge-file -p \
-               orig.txt "$TEST_DIRECTORY"/test4012.png new1.txt 2> merge.err &&
+               orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err &&
        grep "Cannot merge binary files" merge.err
 '
 
index b519626ca09255a433b0d1cb32780a6feafa09f6..07735410b9536ba7639134c7ca0cda4f486f8291 100755 (executable)
@@ -6,7 +6,7 @@ test_description='ask merge-recursive to merge binary files'
 
 test_expect_success setup '
 
-       cat "$TEST_DIRECTORY"/test4012.png >m &&
+       cat "$TEST_DIRECTORY"/test-binary-1.png >m &&
        git add m &&
        git ls-files -s | sed -e "s/ 0  / 1     /" >E1 &&
        test_tick &&
index 62125eca8163f1ca52d57959fb872340479b9002..c6f1f9f8ab2353ec81401828f8500cb7c1a869fb 100755 (executable)
@@ -732,7 +732,7 @@ test_expect_success 'bisect: demonstrate identification of damage boundary' "
        git bisect reset &&
        git checkout broken &&
        git bisect start broken master --no-checkout &&
-       git bisect run sh -c '
+       git bisect run \"\$SHELL_PATH\" -c '
                GOOD=\$(git for-each-ref \"--format=%(objectname)\" refs/bisect/good-*) &&
                git rev-list --objects BISECT_HEAD --not \$GOOD >tmp.\$\$ &&
                git pack-objects --stdout >/dev/null < tmp.\$\$
index 871577d90cc2817ffcc0cfe1ecf76aab6be61723..dfee7d159b3b5198b4773f2d3869e809095b11f7 100755 (executable)
@@ -1,9 +1,15 @@
 #!/bin/sh
 
-test_description='recursive merge corner cases'
+test_description='recursive merge corner cases involving criss-cross merges'
 
 . ./test-lib.sh
 
+get_clean_checkout () {
+       git reset --hard &&
+       git clean -fdqx &&
+       git checkout "$1"
+}
+
 #
 #  L1  L2
 #   o---o
@@ -51,23 +57,15 @@ test_expect_success 'merge simple rename+criss-cross with no modifications' '
 
        test_must_fail git merge -s recursive R2^0 &&
 
-       test 5 = $(git ls-files -s | wc -l) &&
-       test 3 = $(git ls-files -u | wc -l) &&
-       test 0 = $(git ls-files -o | wc -l) &&
+       test 2 = $(git ls-files -s | wc -l) &&
+       test 2 = $(git ls-files -u | wc -l) &&
+       test 2 = $(git ls-files -o | wc -l) &&
 
-       test $(git rev-parse :0:one) = $(git rev-parse L2:one) &&
-       test $(git rev-parse :0:two) = $(git rev-parse R2:two) &&
        test $(git rev-parse :2:three) = $(git rev-parse L2:three) &&
        test $(git rev-parse :3:three) = $(git rev-parse R2:three) &&
 
-       cp two merged &&
-       >empty &&
-       test_must_fail git merge-file \
-               -L "Temporary merge branch 2" \
-               -L "" \
-               -L "Temporary merge branch 1" \
-               merged empty one &&
-       test $(git rev-parse :1:three) = $(git hash-object merged)
+       test $(git rev-parse L2:three) = $(git hash-object three~HEAD) &&
+       test $(git rev-parse R2:three) = $(git hash-object three~R2^0)
 '
 
 #
@@ -126,24 +124,15 @@ test_expect_success 'merge criss-cross + rename merges with basic modification'
 
        test_must_fail git merge -s recursive R2^0 &&
 
-       test 5 = $(git ls-files -s | wc -l) &&
-       test 3 = $(git ls-files -u | wc -l) &&
-       test 0 = $(git ls-files -o | wc -l) &&
+       test 2 = $(git ls-files -s | wc -l) &&
+       test 2 = $(git ls-files -u | wc -l) &&
+       test 2 = $(git ls-files -o | wc -l) &&
 
-       test $(git rev-parse :0:one) = $(git rev-parse L2:one) &&
-       test $(git rev-parse :0:two) = $(git rev-parse R2:two) &&
        test $(git rev-parse :2:three) = $(git rev-parse L2:three) &&
        test $(git rev-parse :3:three) = $(git rev-parse R2:three) &&
 
-       head -n 10 two >merged &&
-       cp one merge-me &&
-       >empty &&
-       test_must_fail git merge-file \
-               -L "Temporary merge branch 2" \
-               -L "" \
-               -L "Temporary merge branch 1" \
-               merged empty merge-me &&
-       test $(git rev-parse :1:three) = $(git hash-object merged)
+       test $(git rev-parse L2:three) = $(git hash-object three~HEAD) &&
+       test $(git rev-parse R2:three) = $(git hash-object three~R2^0)
 '
 
 #
@@ -231,4 +220,557 @@ test_expect_success 'git detects differently handled merges conflict' '
        test $(git rev-parse :1:new_a) = $(git hash-object merged)
 '
 
+#
+# criss-cross + modify/delete:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: file with contents 'A\n'
+#   Commit B: file with contents 'B\n'
+#   Commit C: file not present
+#   Commit D: file with contents 'B\n'
+#   Commit E: file not present
+#
+# Merging commits D & E should result in modify/delete conflict.
+
+test_expect_success 'setup criss-cross + modify/delete resolved differently' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       echo A >file &&
+       git add file &&
+       test_tick &&
+       git commit -m A &&
+
+       git branch B &&
+       git checkout -b C &&
+       git rm file &&
+       test_tick &&
+       git commit -m C &&
+
+       git checkout B &&
+       echo B >file &&
+       git add file &&
+       test_tick &&
+       git commit -m B &&
+
+       git checkout B^0 &&
+       test_must_fail git merge C &&
+       echo B >file &&
+       git add file &&
+       test_tick &&
+       git commit -m D &&
+       git tag D &&
+
+       git checkout C^0 &&
+       test_must_fail git merge B &&
+       git rm file &&
+       test_tick &&
+       git commit -m E &&
+       git tag E
+'
+
+test_expect_success 'git detects conflict merging criss-cross+modify/delete' '
+       git checkout D^0 &&
+
+       test_must_fail git merge -s recursive E^0 &&
+
+       test 2 -eq $(git ls-files -s | wc -l) &&
+       test 2 -eq $(git ls-files -u | wc -l) &&
+
+       test $(git rev-parse :1:file) = $(git rev-parse master:file) &&
+       test $(git rev-parse :2:file) = $(git rev-parse B:file)
+'
+
+test_expect_success 'git detects conflict merging criss-cross+modify/delete, reverse direction' '
+       git reset --hard &&
+       git checkout E^0 &&
+
+       test_must_fail git merge -s recursive D^0 &&
+
+       test 2 -eq $(git ls-files -s | wc -l) &&
+       test 2 -eq $(git ls-files -u | wc -l) &&
+
+       test $(git rev-parse :1:file) = $(git rev-parse master:file) &&
+       test $(git rev-parse :3:file) = $(git rev-parse B:file)
+'
+
+#
+# criss-cross + modify/modify with very contrived file contents:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: file with contents 'A\n'
+#   Commit B: file with contents 'B\n'
+#   Commit C: file with contents 'C\n'
+#   Commit D: file with contents 'D\n'
+#   Commit E: file with contents:
+#      <<<<<<< Temporary merge branch 1
+#      C
+#      =======
+#      B
+#      >>>>>>> Temporary merge branch 2
+#
+# Now, when we merge commits D & E, does git detect the conflict?
+
+test_expect_success 'setup differently handled merges of content conflict' '
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       echo A >file &&
+       git add file &&
+       test_tick &&
+       git commit -m A &&
+
+       git branch B &&
+       git checkout -b C &&
+       echo C >file &&
+       git add file &&
+       test_tick &&
+       git commit -m C &&
+
+       git checkout B &&
+       echo B >file &&
+       git add file &&
+       test_tick &&
+       git commit -m B &&
+
+       git checkout B^0 &&
+       test_must_fail git merge C &&
+       echo D >file &&
+       git add file &&
+       test_tick &&
+       git commit -m D &&
+       git tag D &&
+
+       git checkout C^0 &&
+       test_must_fail git merge B &&
+       cat <<EOF >file &&
+<<<<<<< Temporary merge branch 1
+C
+=======
+B
+>>>>>>> Temporary merge branch 2
+EOF
+       git add file &&
+       test_tick &&
+       git commit -m E &&
+       git tag E
+'
+
+test_expect_failure 'git detects conflict w/ criss-cross+contrived resolution' '
+       git checkout D^0 &&
+
+       test_must_fail git merge -s recursive E^0 &&
+
+       test 3 -eq $(git ls-files -s | wc -l) &&
+       test 3 -eq $(git ls-files -u | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse :2:file) = $(git rev-parse D:file) &&
+       test $(git rev-parse :3:file) = $(git rev-parse E:file)
+'
+
+#
+# criss-cross + d/f conflict via add/add:
+#   Commit A: Neither file 'a' nor directory 'a/' exist.
+#   Commit B: Introduce 'a'
+#   Commit C: Introduce 'a/file'
+#   Commit D: Merge B & C, keeping 'a' and deleting 'a/'
+#
+# Two different later cases:
+#   Commit E1: Merge B & C, deleting 'a' but keeping 'a/file'
+#   Commit E2: Merge B & C, deleting 'a' but keeping a slightly modified 'a/file'
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E1 or E2
+#
+# Merging D & E1 requires we first create a virtual merge base X from
+# merging A & B in memory.  Now, if X could keep both 'a' and 'a/file' in
+# the index, then the merge of D & E1 could be resolved cleanly with both
+# 'a' and 'a/file' removed.  Since git does not currently allow creating
+# such a tree, the best we can do is have X contain both 'a~<unique>' and
+# 'a/file' resulting in the merge of D and E1 having a rename/delete
+# conflict for 'a'.  (Although this merge appears to be unsolvable with git
+# currently, git could do a lot better than it currently does with these
+# d/f conflicts, which is the purpose of this test.)
+#
+# Merge of D & E2 has similar issues for path 'a', but should always result
+# in a modify/delete conflict for path 'a/file'.
+#
+# We run each merge in both directions, to check for directional issues
+# with D/F conflict handling.
+#
+
+test_expect_success 'setup differently handled merges of directory/file conflict' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       >ignore-me &&
+       git add ignore-me &&
+       test_tick &&
+       git commit -m A &&
+       git tag A &&
+
+       git branch B &&
+       git checkout -b C &&
+       mkdir a &&
+       echo 10 >a/file &&
+       git add a/file &&
+       test_tick &&
+       git commit -m C &&
+
+       git checkout B &&
+       echo 5 >a &&
+       git add a &&
+       test_tick &&
+       git commit -m B &&
+
+       git checkout B^0 &&
+       test_must_fail git merge C &&
+       git clean -f &&
+       rm -rf a/ &&
+       echo 5 >a &&
+       git add a &&
+       test_tick &&
+       git commit -m D &&
+       git tag D &&
+
+       git checkout C^0 &&
+       test_must_fail git merge B &&
+       git clean -f &&
+       git rm --cached a &&
+       echo 10 >a/file &&
+       git add a/file &&
+       test_tick &&
+       git commit -m E1 &&
+       git tag E1 &&
+
+       git checkout C^0 &&
+       test_must_fail git merge B &&
+       git clean -f &&
+       git rm --cached a &&
+       printf "10\n11\n" >a/file &&
+       git add a/file &&
+       test_tick &&
+       git commit -m E2 &&
+       git tag E2
+'
+
+test_expect_success 'merge of D & E1 fails but has appropriate contents' '
+       get_clean_checkout D^0 &&
+
+       test_must_fail git merge -s recursive E1^0 &&
+
+       test 2 -eq $(git ls-files -s | wc -l) &&
+       test 1 -eq $(git ls-files -u | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
+       test $(git rev-parse :2:a) = $(git rev-parse B:a)
+'
+
+test_expect_success 'merge of E1 & D fails but has appropriate contents' '
+       get_clean_checkout E1^0 &&
+
+       test_must_fail git merge -s recursive D^0 &&
+
+       test 2 -eq $(git ls-files -s | wc -l) &&
+       test 1 -eq $(git ls-files -u | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
+       test $(git rev-parse :3:a) = $(git rev-parse B:a)
+'
+
+test_expect_success 'merge of D & E2 fails but has appropriate contents' '
+       get_clean_checkout D^0 &&
+
+       test_must_fail git merge -s recursive E2^0 &&
+
+       test 4 -eq $(git ls-files -s | wc -l) &&
+       test 3 -eq $(git ls-files -u | wc -l) &&
+       test 1 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse :2:a) = $(git rev-parse B:a) &&
+       test $(git rev-parse :3:a/file) = $(git rev-parse E2:a/file) &&
+       test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file) &&
+       test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
+
+       test -f a~HEAD
+'
+
+test_expect_success 'merge of E2 & D fails but has appropriate contents' '
+       get_clean_checkout E2^0 &&
+
+       test_must_fail git merge -s recursive D^0 &&
+
+       test 4 -eq $(git ls-files -s | wc -l) &&
+       test 3 -eq $(git ls-files -u | wc -l) &&
+       test 1 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse :3:a) = $(git rev-parse B:a) &&
+       test $(git rev-parse :2:a/file) = $(git rev-parse E2:a/file) &&
+       test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file)
+       test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
+
+       test -f a~D^0
+'
+
+#
+# criss-cross with rename/rename(1to2)/modify followed by
+# rename/rename(2to1)/modify:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: new file: a
+#   Commit B: rename a->b, modifying by adding a line
+#   Commit C: rename a->c
+#   Commit D: merge B&C, resolving conflict by keeping contents in newname
+#   Commit E: merge B&C, resolving conflict similar to D but adding another line
+#
+# There is a conflict merging B & C, but one of filename not of file
+# content.  Whoever created D and E chose specific resolutions for that
+# conflict resolution.  Now, since: (1) there is no content conflict
+# merging B & C, (2) D does not modify that merged content further, and (3)
+# both D & E resolve the name conflict in the same way, the modification to
+# newname in E should not cause any conflicts when it is merged with D.
+# (Note that this can be accomplished by having the virtual merge base have
+# the merged contents of b and c stored in a file named a, which seems like
+# the most logical choice anyway.)
+#
+# Comment from Junio: I do not necessarily agree with the choice "a", but
+# it feels sound to say "B and C do not agree what the final pathname
+# should be, but we know this content was derived from the common A:a so we
+# use one path whose name is arbitrary in the virtual merge base X between
+# D and E" and then further let the rename detection to notice that that
+# arbitrary path gets renamed between X-D to "newname" and X-E also to
+# "newname" to resolve it as both sides renaming it to the same new
+# name. It is akin to what we do at the content level, i.e. "B and C do not
+# agree what the final contents should be, so we leave the conflict marker
+# but that may cancel out at the final merge stage".
+
+test_expect_success 'setup rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' '
+       git reset --hard &&
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       printf "1\n2\n3\n4\n5\n6\n" >a &&
+       git add a &&
+       git commit -m A &&
+       git tag A &&
+
+       git checkout -b B A &&
+       git mv a b &&
+       echo 7 >>b &&
+       git add -u &&
+       git commit -m B &&
+
+       git checkout -b C A &&
+       git mv a c &&
+       git commit -m C &&
+
+       git checkout -q B^0 &&
+       git merge --no-commit -s ours C^0 &&
+       git mv b newname &&
+       git commit -m "Merge commit C^0 into HEAD" &&
+       git tag D &&
+
+       git checkout -q C^0 &&
+       git merge --no-commit -s ours B^0 &&
+       git mv c newname &&
+       printf "7\n8\n" >>newname &&
+       git add -u &&
+       git commit -m "Merge commit B^0 into HEAD" &&
+       git tag E
+'
+
+test_expect_success 'handle rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' '
+       git checkout D^0 &&
+
+       git merge -s recursive E^0 &&
+
+       test 1 -eq $(git ls-files -s | wc -l) &&
+       test 0 -eq $(git ls-files -u | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse HEAD:newname) = $(git rev-parse E:newname)
+'
+
+#
+# criss-cross with rename/rename(1to2)/add-source + resolvable modify/modify:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: new file: a
+#   Commit B: rename a->b
+#   Commit C: rename a->c, add different a
+#   Commit D: merge B&C, keeping b&c and (new) a modified at beginning
+#   Commit E: merge B&C, keeping b&c and (new) a modified at end
+#
+# Merging commits D & E should result in no conflict; doing so correctly
+# requires getting the virtual merge base (from merging B&C) right, handling
+# renaming carefully (both in the virtual merge base and later), and getting
+# content merge handled.
+
+test_expect_success 'setup criss-cross + rename/rename/add + modify/modify' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       printf "lots\nof\nwords\nand\ncontent\n" >a &&
+       git add a &&
+       git commit -m A &&
+       git tag A &&
+
+       git checkout -b B A &&
+       git mv a b &&
+       git commit -m B &&
+
+       git checkout -b C A &&
+       git mv a c &&
+       printf "2\n3\n4\n5\n6\n7\n" >a &&
+       git add a &&
+       git commit -m C &&
+
+       git checkout B^0 &&
+       git merge --no-commit -s ours C^0 &&
+       git checkout C -- a c &&
+       mv a old_a &&
+       echo 1 >a &&
+       cat old_a >>a &&
+       rm old_a &&
+       git add -u &&
+       git commit -m "Merge commit C^0 into HEAD" &&
+       git tag D &&
+
+       git checkout C^0 &&
+       git merge --no-commit -s ours B^0 &&
+       git checkout B -- b &&
+       echo 8 >>a &&
+       git add -u &&
+       git commit -m "Merge commit B^0 into HEAD" &&
+       git tag E
+'
+
+test_expect_failure 'detect rename/rename/add-source for virtual merge-base' '
+       git checkout D^0 &&
+
+       git merge -s recursive E^0 &&
+
+       test 3 -eq $(git ls-files -s | wc -l) &&
+       test 0 -eq $(git ls-files -u | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
+       test $(git rev-parse HEAD:c) = $(git rev-parse A:a) &&
+       test "$(cat a)" = "$(printf "1\n2\n3\n4\n5\n6\n7\n8\n")"
+'
+
+#
+# criss-cross with rename/rename(1to2)/add-dest + simple modify:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: new file: a
+#   Commit B: rename a->b, add c
+#   Commit C: rename a->c
+#   Commit D: merge B&C, keeping A:a and B:c
+#   Commit E: merge B&C, keeping A:a and slightly modified c from B
+#
+# Merging commits D & E should result in no conflict.  The virtual merge
+# base of B & C needs to not delete B:c for that to work, though...
+
+test_expect_success 'setup criss-cross+rename/rename/add-dest + simple modify' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       >a &&
+       git add a &&
+       git commit -m A &&
+       git tag A &&
+
+       git checkout -b B A &&
+       git mv a b &&
+       printf "1\n2\n3\n4\n5\n6\n7\n" >c &&
+       git add c &&
+       git commit -m B &&
+
+       git checkout -b C A &&
+       git mv a c &&
+       git commit -m C &&
+
+       git checkout B^0 &&
+       git merge --no-commit -s ours C^0 &&
+       git mv b a &&
+       git commit -m "D is like B but renames b back to a" &&
+       git tag D &&
+
+       git checkout B^0 &&
+       git merge --no-commit -s ours C^0 &&
+       git mv b a &&
+       echo 8 >>c &&
+       git add c &&
+       git commit -m "E like D but has mod in c" &&
+       git tag E
+'
+
+test_expect_success 'virtual merge base handles rename/rename(1to2)/add-dest' '
+       git checkout D^0 &&
+
+       git merge -s recursive E^0 &&
+
+       test 2 -eq $(git ls-files -s | wc -l) &&
+       test 0 -eq $(git ls-files -u | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse HEAD:a) = $(git rev-parse A:a) &&
+       test $(git rev-parse HEAD:c) = $(git rev-parse E:c)
+'
+
 test_done
index a9b0ac1efc0eac3f50bd9fe26e5900307eddaba2..19de5b16eb530d428f66e5161a3ab48fce34049d 100755 (executable)
@@ -110,4 +110,18 @@ test_expect_success '--set-upstream does not change branch' '
        grep -q "^refs/heads/master$" actual &&
        cmp expect2 actual2
 '
+
+test_expect_success '--set-upstream @{-1}' '
+       git checkout from-master &&
+       git checkout from-master2 &&
+       git config branch.from-master2.merge > expect2 &&
+       git branch --set-upstream @{-1} follower &&
+       git config branch.from-master.merge > actual &&
+       git config branch.from-master2.merge > actual2 &&
+       git branch --set-upstream from-master follower &&
+       git config branch.from-master.merge > expect &&
+       test_cmp expect2 actual2 &&
+       test_cmp expect actual
+'
+
 test_done
diff --git a/t/t6042-merge-rename-corner-cases.sh b/t/t6042-merge-rename-corner-cases.sh
new file mode 100755 (executable)
index 0000000..32591f9
--- /dev/null
@@ -0,0 +1,578 @@
+#!/bin/sh
+
+test_description="recursive merge corner cases w/ renames but not criss-crosses"
+# t6036 has corner cases that involve both criss-cross merges and renames
+
+. ./test-lib.sh
+
+test_expect_success 'setup rename/delete + untracked file' '
+       echo "A pretty inscription" >ring &&
+       git add ring &&
+       test_tick &&
+       git commit -m beginning &&
+
+       git branch people &&
+       git checkout -b rename-the-ring &&
+       git mv ring one-ring-to-rule-them-all &&
+       test_tick &&
+       git commit -m fullname &&
+
+       git checkout people &&
+       git rm ring &&
+       echo gollum >owner &&
+       git add owner &&
+       test_tick &&
+       git commit -m track-people-instead-of-objects &&
+       echo "Myyy PRECIOUSSS" >ring
+'
+
+test_expect_success "Does git preserve Gollum's precious artifact?" '
+       test_must_fail git merge -s recursive rename-the-ring &&
+
+       # Make sure git did not delete an untracked file
+       test -f ring
+'
+
+# Testcase setup for rename/modify/add-source:
+#   Commit A: new file: a
+#   Commit B: modify a slightly
+#   Commit C: rename a->b, add completely different a
+#
+# We should be able to merge B & C cleanly
+
+test_expect_success 'setup rename/modify/add-source conflict' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
+       git add a &&
+       git commit -m A &&
+       git tag A &&
+
+       git checkout -b B A &&
+       echo 8 >>a &&
+       git add a &&
+       git commit -m B &&
+
+       git checkout -b C A &&
+       git mv a b &&
+       echo something completely different >a &&
+       git add a &&
+       git commit -m C
+'
+
+test_expect_failure 'rename/modify/add-source conflict resolvable' '
+       git checkout B^0 &&
+
+       git merge -s recursive C^0 &&
+
+       test $(git rev-parse B:a) = $(git rev-parse b) &&
+       test $(git rev-parse C:a) = $(git rev-parse a)
+'
+
+test_expect_success 'setup resolvable conflict missed if rename missed' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       printf "1\n2\n3\n4\n5\n" >a &&
+       echo foo >b &&
+       git add a b &&
+       git commit -m A &&
+       git tag A &&
+
+       git checkout -b B A &&
+       git mv a c &&
+       echo "Completely different content" >a &&
+       git add a &&
+       git commit -m B &&
+
+       git checkout -b C A &&
+       echo 6 >>a &&
+       git add a &&
+       git commit -m C
+'
+
+test_expect_failure 'conflict caused if rename not detected' '
+       git checkout -q C^0 &&
+       git merge -s recursive B^0 &&
+
+       test 3 -eq $(git ls-files -s | wc -l) &&
+       test 0 -eq $(git ls-files -u | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test 6 -eq $(wc -l < c) &&
+       test $(git rev-parse HEAD:a) = $(git rev-parse B:a) &&
+       test $(git rev-parse HEAD:b) = $(git rev-parse A:b)
+'
+
+test_expect_success 'setup conflict resolved wrong if rename missed' '
+       git reset --hard &&
+       git clean -f &&
+
+       git checkout -b D A &&
+       echo 7 >>a &&
+       git add a &&
+       git mv a c &&
+       echo "Completely different content" >a &&
+       git add a &&
+       git commit -m D &&
+
+       git checkout -b E A &&
+       git rm a &&
+       echo "Completely different content" >>a &&
+       git add a &&
+       git commit -m E
+'
+
+test_expect_failure 'missed conflict if rename not detected' '
+       git checkout -q E^0 &&
+       test_must_fail git merge -s recursive D^0
+'
+
+# Tests for undetected rename/add-source causing a file to erroneously be
+# deleted (and for mishandled rename/rename(1to1) causing the same issue).
+#
+# This test uses a rename/rename(1to1)+add-source conflict (1to1 means the
+# same file is renamed on both sides to the same thing; it should trigger
+# the 1to2 logic, which it would do if the add-source didn't cause issues
+# for git's rename detection):
+#   Commit A: new file: a
+#   Commit B: rename a->b
+#   Commit C: rename a->b, add unrelated a
+
+test_expect_success 'setup undetected rename/add-source causes data loss' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       printf "1\n2\n3\n4\n5\n" >a &&
+       git add a &&
+       git commit -m A &&
+       git tag A &&
+
+       git checkout -b B A &&
+       git mv a b &&
+       git commit -m B &&
+
+       git checkout -b C A &&
+       git mv a b &&
+       echo foobar >a &&
+       git add a &&
+       git commit -m C
+'
+
+test_expect_failure 'detect rename/add-source and preserve all data' '
+       git checkout B^0 &&
+
+       git merge -s recursive C^0 &&
+
+       test 2 -eq $(git ls-files -s | wc -l) &&
+       test 2 -eq $(git ls-files -u | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test -f a &&
+       test -f b &&
+
+       test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
+       test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
+'
+
+test_expect_failure 'detect rename/add-source and preserve all data, merge other way' '
+       git checkout C^0 &&
+
+       git merge -s recursive B^0 &&
+
+       test 2 -eq $(git ls-files -s | wc -l) &&
+       test 2 -eq $(git ls-files -u | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test -f a &&
+       test -f b &&
+
+       test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
+       test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
+'
+
+test_expect_success 'setup content merge + rename/directory conflict' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       printf "1\n2\n3\n4\n5\n6\n" >file &&
+       git add file &&
+       test_tick &&
+       git commit -m base &&
+       git tag base &&
+
+       git checkout -b right &&
+       echo 7 >>file &&
+       mkdir newfile &&
+       echo junk >newfile/realfile &&
+       git add file newfile/realfile &&
+       test_tick &&
+       git commit -m right &&
+
+       git checkout -b left-conflict base &&
+       echo 8 >>file &&
+       git add file &&
+       git mv file newfile &&
+       test_tick &&
+       git commit -m left &&
+
+       git checkout -b left-clean base &&
+       echo 0 >newfile &&
+       cat file >>newfile &&
+       git add newfile &&
+       git rm file &&
+       test_tick &&
+       git commit -m left
+'
+
+test_expect_success 'rename/directory conflict + clean content merge' '
+       git reset --hard &&
+       git reset --hard &&
+       git clean -fdqx &&
+
+       git checkout left-clean^0 &&
+
+       test_must_fail git merge -s recursive right^0 &&
+
+       test 2 -eq $(git ls-files -s | wc -l) &&
+       test 1 -eq $(git ls-files -u | wc -l) &&
+       test 1 -eq $(git ls-files -o | wc -l) &&
+
+       echo 0 >expect &&
+       git cat-file -p base:file >>expect &&
+       echo 7 >>expect &&
+       test_cmp expect newfile~HEAD &&
+
+       test $(git rev-parse :2:newfile) = $(git hash-object expect) &&
+
+       test -f newfile/realfile &&
+       test -f newfile~HEAD
+'
+
+test_expect_success 'rename/directory conflict + content merge conflict' '
+       git reset --hard &&
+       git reset --hard &&
+       git clean -fdqx &&
+
+       git checkout left-conflict^0 &&
+
+       test_must_fail git merge -s recursive right^0 &&
+
+       test 4 -eq $(git ls-files -s | wc -l) &&
+       test 3 -eq $(git ls-files -u | wc -l) &&
+       test 1 -eq $(git ls-files -o | wc -l) &&
+
+       git cat-file -p left-conflict:newfile >left &&
+       git cat-file -p base:file    >base &&
+       git cat-file -p right:file   >right &&
+       test_must_fail git merge-file \
+               -L "HEAD:newfile" \
+               -L "" \
+               -L "right^0:file" \
+               left base right &&
+       test_cmp left newfile~HEAD &&
+
+       test $(git rev-parse :1:newfile) = $(git rev-parse base:file) &&
+       test $(git rev-parse :2:newfile) = $(git rev-parse left-conflict:newfile) &&
+       test $(git rev-parse :3:newfile) = $(git rev-parse right:file) &&
+
+       test -f newfile/realfile &&
+       test -f newfile~HEAD
+'
+
+test_expect_success 'setup content merge + rename/directory conflict w/ disappearing dir' '
+       git reset --hard &&
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       mkdir sub &&
+       printf "1\n2\n3\n4\n5\n6\n" >sub/file &&
+       git add sub/file &&
+       test_tick &&
+       git commit -m base &&
+       git tag base &&
+
+       git checkout -b right &&
+       echo 7 >>sub/file &&
+       git add sub/file &&
+       test_tick &&
+       git commit -m right &&
+
+       git checkout -b left base &&
+       echo 0 >newfile &&
+       cat sub/file >>newfile &&
+       git rm sub/file &&
+       mv newfile sub &&
+       git add sub &&
+       test_tick &&
+       git commit -m left
+'
+
+test_expect_success 'disappearing dir in rename/directory conflict handled' '
+       git reset --hard &&
+       git clean -fdqx &&
+
+       git checkout left^0 &&
+
+       git merge -s recursive right^0 &&
+
+       test 1 -eq $(git ls-files -s | wc -l) &&
+       test 0 -eq $(git ls-files -u | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       echo 0 >expect &&
+       git cat-file -p base:sub/file >>expect &&
+       echo 7 >>expect &&
+       test_cmp expect sub &&
+
+       test -f sub
+'
+
+# Test for all kinds of things that can go wrong with rename/rename (2to1):
+#   Commit A: new files: a & b
+#   Commit B: rename a->c, modify b
+#   Commit C: rename b->c, modify a
+#
+# Merging of B & C should NOT be clean.  Questions:
+#   * Both a & b should be removed by the merge; are they?
+#   * The two c's should contain modifications to a & b; do they?
+#   * The index should contain two files, both for c; does it?
+#   * The working copy should have two files, both of form c~<unique>; does it?
+#   * Nothing else should be present.  Is anything?
+
+test_expect_success 'setup rename/rename (2to1) + modify/modify' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       printf "1\n2\n3\n4\n5\n" >a &&
+       printf "5\n4\n3\n2\n1\n" >b &&
+       git add a b &&
+       git commit -m A &&
+       git tag A &&
+
+       git checkout -b B A &&
+       git mv a c &&
+       echo 0 >>b &&
+       git add b &&
+       git commit -m B &&
+
+       git checkout -b C A &&
+       git mv b c &&
+       echo 6 >>a &&
+       git add a &&
+       git commit -m C
+'
+
+test_expect_success 'handle rename/rename (2to1) conflict correctly' '
+       git checkout B^0 &&
+
+       test_must_fail git merge -s recursive C^0 >out &&
+       grep "CONFLICT (rename/rename)" out &&
+
+       test 2 -eq $(git ls-files -s | wc -l) &&
+       test 2 -eq $(git ls-files -u | wc -l) &&
+       test 2 -eq $(git ls-files -u c | wc -l) &&
+       test 3 -eq $(git ls-files -o | wc -l) &&
+
+       test ! -f a &&
+       test ! -f b &&
+       test -f c~HEAD &&
+       test -f c~C^0 &&
+
+       test $(git hash-object c~HEAD) = $(git rev-parse C:a) &&
+       test $(git hash-object c~C^0) = $(git rev-parse B:b)
+'
+
+# Testcase setup for simple rename/rename (1to2) conflict:
+#   Commit A: new file: a
+#   Commit B: rename a->b
+#   Commit C: rename a->c
+test_expect_success 'setup simple rename/rename (1to2) conflict' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       echo stuff >a &&
+       git add a &&
+       test_tick &&
+       git commit -m A &&
+       git tag A &&
+
+       git checkout -b B A &&
+       git mv a b &&
+       test_tick &&
+       git commit -m B &&
+
+       git checkout -b C A &&
+       git mv a c &&
+       test_tick &&
+       git commit -m C
+'
+
+test_expect_success 'merge has correct working tree contents' '
+       git checkout C^0 &&
+
+       test_must_fail git merge -s recursive B^0 &&
+
+       test 3 -eq $(git ls-files -s | wc -l) &&
+       test 3 -eq $(git ls-files -u | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse :1:a) = $(git rev-parse A:a) &&
+       test $(git rev-parse :3:b) = $(git rev-parse A:a) &&
+       test $(git rev-parse :2:c) = $(git rev-parse A:a) &&
+
+       test ! -f a &&
+       test $(git hash-object b) = $(git rev-parse A:a) &&
+       test $(git hash-object c) = $(git rev-parse A:a)
+'
+
+# Testcase setup for rename/rename(1to2)/add-source conflict:
+#   Commit A: new file: a
+#   Commit B: rename a->b
+#   Commit C: rename a->c, add completely different a
+#
+# Merging of B & C should NOT be clean; there's a rename/rename conflict
+
+test_expect_success 'setup rename/rename(1to2)/add-source conflict' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
+       git add a &&
+       git commit -m A &&
+       git tag A &&
+
+       git checkout -b B A &&
+       git mv a b &&
+       git commit -m B &&
+
+       git checkout -b C A &&
+       git mv a c &&
+       echo something completely different >a &&
+       git add a &&
+       git commit -m C
+'
+
+test_expect_failure 'detect conflict with rename/rename(1to2)/add-source merge' '
+       git checkout B^0 &&
+
+       test_must_fail git merge -s recursive C^0 &&
+
+       test 4 -eq $(git ls-files -s | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse 3:a) = $(git rev-parse C:a) &&
+       test $(git rev-parse 1:a) = $(git rev-parse A:a) &&
+       test $(git rev-parse 2:b) = $(git rev-parse B:b) &&
+       test $(git rev-parse 3:c) = $(git rev-parse C:c) &&
+
+       test -f a &&
+       test -f b &&
+       test -f c
+'
+
+test_expect_success 'setup rename/rename(1to2)/add-source resolvable conflict' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       >a &&
+       git add a &&
+       test_tick &&
+       git commit -m base &&
+       git tag A &&
+
+       git checkout -b B A &&
+       git mv a b &&
+       test_tick &&
+       git commit -m one &&
+
+       git checkout -b C A &&
+       git mv a b &&
+       echo important-info >a &&
+       git add a &&
+       test_tick &&
+       git commit -m two
+'
+
+test_expect_failure 'rename/rename/add-source still tracks new a file' '
+       git checkout C^0 &&
+       git merge -s recursive B^0 &&
+
+       test 2 -eq $(git ls-files -s | wc -l) &&
+       test 0 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse HEAD:a) = $(git rev-parse C:a) &&
+       test $(git rev-parse HEAD:b) = $(git rev-parse A:a)
+'
+
+test_expect_success 'setup rename/rename(1to2)/add-dest conflict' '
+       git rm -rf . &&
+       git clean -fdqx &&
+       rm -rf .git &&
+       git init &&
+
+       echo stuff >a &&
+       git add a &&
+       test_tick &&
+       git commit -m base &&
+       git tag A &&
+
+       git checkout -b B A &&
+       git mv a b &&
+       echo precious-data >c &&
+       git add c &&
+       test_tick &&
+       git commit -m one &&
+
+       git checkout -b C A &&
+       git mv a c &&
+       echo important-info >b &&
+       git add b &&
+       test_tick &&
+       git commit -m two
+'
+
+test_expect_success 'rename/rename/add-dest merge still knows about conflicting file versions' '
+       git checkout C^0 &&
+       test_must_fail git merge -s recursive B^0 &&
+
+       test 5 -eq $(git ls-files -s | wc -l) &&
+       test 2 -eq $(git ls-files -u b | wc -l) &&
+       test 2 -eq $(git ls-files -u c | wc -l) &&
+       test 4 -eq $(git ls-files -o | wc -l) &&
+
+       test $(git rev-parse :1:a) = $(git rev-parse A:a) &&
+       test $(git rev-parse :2:b) = $(git rev-parse C:b) &&
+       test $(git rev-parse :3:b) = $(git rev-parse B:b) &&
+       test $(git rev-parse :2:c) = $(git rev-parse C:c) &&
+       test $(git rev-parse :3:c) = $(git rev-parse B:c) &&
+
+       test $(git hash-object c~HEAD) = $(git rev-parse C:c) &&
+       test $(git hash-object c~B\^0) = $(git rev-parse B:c) &&
+       test $(git hash-object b~HEAD) = $(git rev-parse C:b) &&
+       test $(git hash-object b~B\^0) = $(git rev-parse B:b) &&
+
+       test ! -f b &&
+       test ! -f c
+'
+
+test_done
index ed7575d0fdf9eebf65d808fa810ab4cc03095025..320e1d1dbe62c81e29186d7a32b73447d2f998b8 100755 (executable)
@@ -13,7 +13,7 @@ cleanup_fail() {
 
 test_expect_success 'setup' '
        sane_unset GIT_PAGER GIT_PAGER_IN_USE &&
-       test_might_fail git config --unset core.pager &&
+       test_unconfig core.pager &&
 
        PAGER="cat >paginated.out" &&
        export PAGER &&
@@ -94,21 +94,19 @@ test_expect_success TTY 'no pager with --no-pager' '
 
 test_expect_success TTY 'configuration can disable pager' '
        rm -f paginated.out &&
-       test_might_fail git config --unset pager.grep &&
+       test_unconfig pager.grep &&
        test_terminal git grep initial &&
        test -e paginated.out &&
 
        rm -f paginated.out &&
-       git config pager.grep false &&
-       test_when_finished "git config --unset pager.grep" &&
+       test_config pager.grep false &&
        test_terminal git grep initial &&
        ! test -e paginated.out
 '
 
 test_expect_success TTY 'git config uses a pager if configured to' '
        rm -f paginated.out &&
-       git config pager.config true &&
-       test_when_finished "git config --unset pager.config" &&
+       test_config pager.config true &&
        test_terminal git config --list &&
        test -e paginated.out
 '
@@ -116,8 +114,7 @@ test_expect_success TTY 'git config uses a pager if configured to' '
 test_expect_success TTY 'configuration can enable pager (from subdir)' '
        rm -f paginated.out &&
        mkdir -p subdir &&
-       git config pager.bundle true &&
-       test_when_finished "git config --unset pager.bundle" &&
+       test_config pager.bundle true &&
 
        git bundle create test.bundle --all &&
        rm -f paginated.out subdir/paginated.out &&
@@ -150,7 +147,7 @@ test_expect_success 'tests can detect color' '
 
 test_expect_success 'no color when stdout is a regular file' '
        rm -f colorless.log &&
-       git config color.ui auto ||
+       test_config color.ui auto ||
        cleanup_fail &&
 
        git log >colorless.log &&
@@ -159,7 +156,7 @@ test_expect_success 'no color when stdout is a regular file' '
 
 test_expect_success TTY 'color when writing to a pager' '
        rm -f paginated.out &&
-       git config color.ui auto ||
+       test_config color.ui auto ||
        cleanup_fail &&
 
        (
@@ -170,9 +167,21 @@ test_expect_success TTY 'color when writing to a pager' '
        colorful paginated.out
 '
 
+test_expect_success TTY 'colors are suppressed by color.pager' '
+       rm -f paginated.out &&
+       test_config color.ui auto &&
+       test_config color.pager false &&
+       (
+               TERM=vt100 &&
+               export TERM &&
+               test_terminal git log
+       ) &&
+       ! colorful paginated.out
+'
+
 test_expect_success 'color when writing to a file intended for a pager' '
        rm -f colorful.log &&
-       git config color.ui auto ||
+       test_config color.ui auto ||
        cleanup_fail &&
 
        (
@@ -184,6 +193,17 @@ test_expect_success 'color when writing to a file intended for a pager' '
        colorful colorful.log
 '
 
+test_expect_success TTY 'colors are sent to pager for external commands' '
+       test_config alias.externallog "!git log" &&
+       test_config color.ui auto &&
+       (
+               TERM=vt100 &&
+               export TERM &&
+               test_terminal git -p externallog
+       ) &&
+       colorful paginated.out
+'
+
 # Use this helper to make it easy for the caller of your
 # terminal-using function to specify whether it should fail.
 # If you write
@@ -221,7 +241,7 @@ test_default_pager() {
 
        $test_expectation SIMPLEPAGER,TTY "$cmd - default pager is used by default" "
                sane_unset PAGER GIT_PAGER &&
-               test_might_fail git config --unset core.pager &&
+               test_unconfig core.pager &&
                rm -f default_pager_used ||
                cleanup_fail &&
 
@@ -244,7 +264,7 @@ test_PAGER_overrides() {
 
        $test_expectation TTY "$cmd - PAGER overrides default pager" "
                sane_unset GIT_PAGER &&
-               test_might_fail git config --unset core.pager &&
+               test_unconfig core.pager &&
                rm -f PAGER_used ||
                cleanup_fail &&
 
@@ -277,7 +297,7 @@ test_core_pager() {
 
                PAGER=wc &&
                export PAGER &&
-               git config core.pager 'wc >core.pager_used' &&
+               test_config core.pager 'wc >core.pager_used' &&
                $full_command &&
                ${if_local_config}test -e core.pager_used
        "
@@ -307,7 +327,7 @@ test_pager_subdir_helper() {
                PAGER=wc &&
                stampname=\$(pwd)/core.pager_used &&
                export PAGER stampname &&
-               git config core.pager 'wc >\"\$stampname\"' &&
+               test_config core.pager 'wc >\"\$stampname\"' &&
                mkdir sub &&
                (
                        cd sub &&
@@ -324,7 +344,7 @@ test_GIT_PAGER_overrides() {
                rm -f GIT_PAGER_used ||
                cleanup_fail &&
 
-               git config core.pager wc &&
+               test_config core.pager wc &&
                GIT_PAGER='wc >GIT_PAGER_used' &&
                export GIT_PAGER &&
                $full_command &&
@@ -402,21 +422,21 @@ test_core_pager_subdir    expect_success test_must_fail \
                                         'git -p apply </dev/null'
 
 test_expect_success TTY 'command-specific pager' '
-       unset PAGER GIT_PAGER;
+       sane_unset PAGER GIT_PAGER &&
        echo "foo:initial" >expect &&
        >actual &&
-       git config --unset core.pager &&
-       git config pager.log "sed s/^/foo:/ >actual" &&
+       test_unconfig core.pager &&
+       test_config pager.log "sed s/^/foo:/ >actual" &&
        test_terminal git log --format=%s -1 &&
        test_cmp expect actual
 '
 
 test_expect_success TTY 'command-specific pager overrides core.pager' '
-       unset PAGER GIT_PAGER;
+       sane_unset PAGER GIT_PAGER &&
        echo "foo:initial" >expect &&
        >actual &&
-       git config core.pager "exit 1"
-       git config pager.log "sed s/^/foo:/ >actual" &&
+       test_config core.pager "exit 1"
+       test_config pager.log "sed s/^/foo:/ >actual" &&
        test_terminal git log --format=%s -1 &&
        test_cmp expect actual
 '
@@ -425,9 +445,45 @@ test_expect_success TTY 'command-specific pager overridden by environment' '
        GIT_PAGER="sed s/^/foo:/ >actual" && export GIT_PAGER &&
        >actual &&
        echo "foo:initial" >expect &&
-       git config pager.log "exit 1" &&
+       test_config pager.log "exit 1" &&
        test_terminal git log --format=%s -1 &&
        test_cmp expect actual
 '
 
+test_expect_success 'setup external command' '
+       cat >git-external <<-\EOF &&
+       #!/bin/sh
+       git "$@"
+       EOF
+       chmod +x git-external
+'
+
+test_expect_success TTY 'command-specific pager works for external commands' '
+       sane_unset PAGER GIT_PAGER &&
+       echo "foo:initial" >expect &&
+       >actual &&
+       test_config pager.external "sed s/^/foo:/ >actual" &&
+       test_terminal git --exec-path="`pwd`" external log --format=%s -1 &&
+       test_cmp expect actual
+'
+
+test_expect_success TTY 'sub-commands of externals use their own pager' '
+       sane_unset PAGER GIT_PAGER &&
+       echo "foo:initial" >expect &&
+       >actual &&
+       test_config pager.log "sed s/^/foo:/ >actual" &&
+       test_terminal git --exec-path=. external log --format=%s -1 &&
+       test_cmp expect actual
+'
+
+test_expect_success TTY 'external command pagers override sub-commands' '
+       sane_unset PAGER GIT_PAGER &&
+       >expect &&
+       >actual &&
+       test_config pager.external false &&
+       test_config pager.log "sed s/^/log:/ >actual" &&
+       test_terminal git --exec-path=. external log --format=%s -1 &&
+       test_cmp expect actual
+'
+
 test_done
index e058d184d1c072bd3078fe17ad41f1026f093201..917a264eea6c6b3593e9f19caadbef715daace20 100755 (executable)
@@ -84,7 +84,7 @@ test_expect_success 'git grep -Fi Y<NUL>f a' "
        git grep -f f -Fi a
 "
 
-test_expect_failure 'git grep -Fi Y<NUL>x a' "
+test_expect_success 'git grep -Fi Y<NUL>x a' "
        printf 'YQx' | q_to_nul >f &&
        test_must_fail git grep -f f -Fi a
 "
@@ -94,7 +94,7 @@ test_expect_success 'git grep y<NUL>f a' "
        git grep -f f a
 "
 
-test_expect_failure 'git grep y<NUL>x a' "
+test_expect_success 'git grep y<NUL>x a' "
        printf 'yQx' | q_to_nul >f &&
        test_must_fail git grep -f f a
 "
index f1cfc9ac959ee281d50f7b8a51fdcefd2d0670e7..b096dc88c2f4caf28887cf8fea5d700f0132f5a3 100755 (executable)
@@ -429,6 +429,21 @@ test_expect_success '--mixed refreshes the index' '
        test_i18ncmp expect output
 '
 
+test_expect_success 'resetting specific path that is unmerged' '
+       git rm --cached file2 &&
+       F1=$(git rev-parse HEAD:file1) &&
+       F2=$(git rev-parse HEAD:file2) &&
+       F3=$(git rev-parse HEAD:secondfile) &&
+       {
+               echo "100644 $F1 1      file2" &&
+               echo "100644 $F2 2      file2" &&
+               echo "100644 $F3 3      file2"
+       } | git update-index --index-info &&
+       git ls-files -u &&
+       test_must_fail git reset HEAD file2 &&
+       git diff-index --exit-code --cached HEAD
+'
+
 test_expect_success 'disambiguation (1)' '
 
        git reset --hard &&
index 14dc92723c3dc96c1c3c15724df668226edf578e..69115269c2a284dcfc99abd2f7feb3d87f4e5bcc 100755 (executable)
@@ -77,7 +77,8 @@ test_expect_success 'submodule add' '
 
        (
                cd addtest &&
-               git submodule add "$submodurl" submod &&
+               git submodule add -q "$submodurl" submod >actual &&
+               test ! -s actual &&
                git submodule init
        ) &&
 
@@ -275,7 +276,8 @@ test_expect_success 'update should work when path is an empty dir' '
        echo "$rev1" >expect &&
 
        mkdir init &&
-       git submodule update &&
+       git submodule update -q >update.out &&
+       test ! -s update.out &&
 
        inspect init &&
        test_cmp expect head-sha1
diff --git a/t/t7511-status-index.sh b/t/t7511-status-index.sh
new file mode 100755 (executable)
index 0000000..bca359d
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+test_description='git status with certain file name lengths'
+
+. ./test-lib.sh
+
+files="0 1 2 3 4 5 6 7 8 9 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"
+
+check() {
+       len=$1
+       prefix=$2
+
+       for i in $files
+       do
+               : >$prefix$i
+       done
+
+       test_expect_success "status, filename length $len" "
+               git add $prefix* &&
+               git status
+       "
+       rm $prefix* .git/index
+}
+
+check  1
+check  2 p
+check  3 pr
+check  4 pre
+check  5 pref
+check  6 prefi
+check  7 prefix
+check  8 prefix-
+check  9 prefix-p
+check 10 prefix-pr
+check 11 prefix-pre
+check 12 prefix-pref
+check 13 prefix-prefi
+check 14 prefix-prefix
+check 15 prefix-prefix-
+check 16 prefix-prefix-p
+check 17 prefix-prefix-pr
+check 18 prefix-prefix-pre
+check 19 prefix-prefix-pref
+check 20 prefix-prefix-prefi
+check 21 prefix-prefix-prefix
+check 22 prefix-prefix-prefix-
+check 23 prefix-prefix-prefix-p
+check 24 prefix-prefix-prefix-pr
+
+test_done
index 0a46795ae785fd4dfa0e565bfa0153ca107a904d..61f36baa1f3459d68ac30e67680e096093cbe414 100755 (executable)
@@ -53,7 +53,7 @@ cat >expected <<\EOF
 Trying simple merge with c2
 Trying simple merge with c3
 Trying simple merge with c4
-Merge made by octopus.
+Merge made by the 'octopus' strategy.
  c2.c |    1 +
  c3.c |    1 +
  c4.c |    1 +
@@ -72,7 +72,7 @@ test_expect_success 'merge output uses pretty names' '
 cat >expected <<\EOF
 Already up-to-date with c4
 Trying simple merge with c5
-Merge made by octopus.
+Merge made by the 'octopus' strategy.
  c5.c |    1 +
  1 files changed, 1 insertions(+), 0 deletions(-)
  create mode 100644 c5.c
@@ -86,7 +86,7 @@ test_expect_success 'merge up-to-date output uses pretty names' '
 cat >expected <<\EOF
 Fast-forwarding to: c1
 Trying simple merge with c2
-Merge made by octopus.
+Merge made by the 'octopus' strategy.
  c1.c |    1 +
  c2.c |    1 +
  2 files changed, 2 insertions(+), 0 deletions(-)
index 72a8731d5e28d71577d0c53fc25a5ddc1d2ad6de..aa74184c31cd6b2bd2e0e566e6805e60eed7aff8 100755 (executable)
@@ -107,6 +107,7 @@ error: The following untracked working tree files would be overwritten by merge:
        sub
        sub2
 Please move or remove them before you can merge.
+Aborting
 EOF
 
 test_expect_success 'will not overwrite untracked file in leading path' '
index c994836c53224dd0a8302f7a6ab63b35f8b493e3..0e4a682c6428a96af4d98bb7e24b0de7f4be865c 100755 (executable)
@@ -32,6 +32,7 @@ error: The following untracked working tree files would be overwritten by merge:
        three
        two
 Please move or remove them before you can merge.
+Aborting
 EOF
 
 test_expect_success 'untracked files overwritten by merge (fast and non-fast forward)' '
@@ -56,6 +57,7 @@ Please, commit your changes or stash them before you can merge.
 error: The following untracked working tree files would be overwritten by merge:
        five
 Please move or remove them before you can merge.
+Aborting
 EOF
 
 test_expect_success 'untracked files or local changes ovewritten by merge' '
@@ -71,6 +73,7 @@ error: Your local changes to the following files would be overwritten by checkou
        rep/one
        rep/two
 Please, commit your changes or stash them before you can switch branches.
+Aborting
 EOF
 
 test_expect_success 'cannot switch branches because of local changes' '
@@ -92,6 +95,7 @@ error: Your local changes to the following files would be overwritten by checkou
        rep/one
        rep/two
 Please, commit your changes or stash them before you can switch branches.
+Aborting
 EOF
 
 test_expect_success 'not uptodate file porcelain checkout error' '
@@ -105,6 +109,7 @@ error: Updating the following directories would lose untracked files in it:
        rep
        rep2
 
+Aborting
 EOF
 
 test_expect_success 'not_uptodate_dir porcelain checkout error' '
index cbc08e32761c6e35a3eb25519873e74218fd441a..4aab2a75b8ef5836a58f30b6c27a8eec4a733afc 100755 (executable)
@@ -16,6 +16,7 @@ Testing basic merge tool invocation'
 test_expect_success 'setup' '
     git config rerere.enabled true &&
     echo master >file1 &&
+    echo master spaced >"spaced name" &&
     echo master file11 >file11 &&
     echo master file12 >file12 &&
     echo master file13 >file13 &&
@@ -30,13 +31,14 @@ test_expect_success 'setup' '
        git commit -m "Add foo"
     ) &&
     git submodule add git://example.com/submod submod &&
-    git add file1 file1[1-4] subdir/file3 .gitmodules submod &&
+    git add file1 "spaced name" file1[1-4] subdir/file3 .gitmodules submod &&
     git commit -m "add initial versions" &&
 
     git checkout -b branch1 master &&
     git submodule update -N &&
     echo branch1 change >file1 &&
     echo branch1 newfile >file2 &&
+    echo branch1 spaced >"spaced name" &&
     echo branch1 change file11 >file11 &&
     echo branch1 change file13 >file13 &&
     echo branch1 sub >subdir/file3 &&
@@ -47,7 +49,7 @@ test_expect_success 'setup' '
        git commit -m "Add bar on branch1" &&
        git checkout -b submod-branch1
     ) &&
-    git add file1 file11 file13 file2 subdir/file3 submod &&
+    git add file1 "spaced name" file11 file13 file2 subdir/file3 submod &&
     git rm file12 &&
     git commit -m "branch1 changes" &&
 
@@ -55,6 +57,7 @@ test_expect_success 'setup' '
     git submodule update -N &&
     echo master updated >file1 &&
     echo master new >file2 &&
+    echo master updated spaced >"spaced name" &&
     echo master updated file12 >file12 &&
     echo master updated file14 >file14 &&
     echo master new sub >subdir/file3 &&
@@ -65,7 +68,7 @@ test_expect_success 'setup' '
        git commit -m "Add bar on master" &&
        git checkout -b submod-master
     ) &&
-    git add file1 file12 file14 file2 subdir/file3 submod &&
+    git add file1 "spaced name" file12 file14 file2 subdir/file3 submod &&
     git rm file11 &&
     git commit -m "master updates" &&
 
@@ -78,8 +81,8 @@ test_expect_success 'custom mergetool' '
     git checkout -b test1 branch1 &&
     git submodule update -N &&
     test_must_fail git merge master >/dev/null 2>&1 &&
-    ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
-    ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
+    ( yes "" | git mergetool file1 file1 ) &&
+    ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) &&
     ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
@@ -97,6 +100,7 @@ test_expect_success 'mergetool crlf' '
     test_must_fail git merge master >/dev/null 2>&1 &&
     ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
     ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
+    ( yes "" | git mergetool "spaced name" >/dev/null 2>&1 ) &&
     ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
@@ -126,7 +130,7 @@ test_expect_success 'mergetool on file in parent dir' '
     (
        cd subdir &&
        ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
-       ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) &&
+       ( yes "" | git mergetool ../file2 ../spaced\ name >/dev/null 2>&1 ) &&
        ( yes "d" | git mergetool ../file11 >/dev/null 2>&1 ) &&
        ( yes "d" | git mergetool ../file12 >/dev/null 2>&1 ) &&
        ( yes "l" | git mergetool ../submod >/dev/null 2>&1 ) &&
@@ -180,6 +184,24 @@ test_expect_success 'mergetool skips resolved paths when rerere is active' '
     git reset --hard
 '
 
+test_expect_success 'mergetool takes partial path' '
+    git config rerere.enabled false &&
+    git checkout -b test12 branch1 &&
+    git submodule update -N &&
+    test_must_fail git merge master &&
+
+    #shouldnt need these lines
+    #( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
+    #( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
+    #( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
+    #( yes "" | git mergetool file1 file2 >/dev/null 2>&1 ) &&
+
+    ( yes "" | git mergetool subdir ) &&
+
+    test "$(cat subdir/file3)" = "master new sub" &&
+    git reset --hard
+'
+
 test_expect_success 'deleted vs modified submodule' '
     git checkout -b test6 branch1 &&
     git submodule update -N &&
@@ -189,7 +211,7 @@ test_expect_success 'deleted vs modified submodule' '
     git checkout -b test6.a test6 &&
     test_must_fail git merge master &&
     test -n "$(git ls-files -u)" &&
-    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
     ( yes "r" | git mergetool submod ) &&
     rmdir submod && mv submod-movedaside submod &&
@@ -205,7 +227,7 @@ test_expect_success 'deleted vs modified submodule' '
     git submodule update -N &&
     test_must_fail git merge master &&
     test -n "$(git ls-files -u)" &&
-    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
     ( yes "l" | git mergetool submod ) &&
     test ! -e submod &&
@@ -218,7 +240,7 @@ test_expect_success 'deleted vs modified submodule' '
     git submodule update -N &&
     test_must_fail git merge test6 &&
     test -n "$(git ls-files -u)" &&
-    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
     ( yes "r" | git mergetool submod ) &&
     test ! -e submod &&
@@ -233,7 +255,7 @@ test_expect_success 'deleted vs modified submodule' '
     git submodule update -N &&
     test_must_fail git merge test6 &&
     test -n "$(git ls-files -u)" &&
-    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
     ( yes "l" | git mergetool submod ) &&
     test "$(cat submod/bar)" = "master submodule" &&
@@ -256,7 +278,7 @@ test_expect_success 'file vs modified submodule' '
     git checkout -b test7.a branch1 &&
     test_must_fail git merge master &&
     test -n "$(git ls-files -u)" &&
-    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
     ( yes "r" | git mergetool submod ) &&
     rmdir submod && mv submod-movedaside submod &&
@@ -271,7 +293,7 @@ test_expect_success 'file vs modified submodule' '
     git checkout -b test7.b test7 &&
     test_must_fail git merge master &&
     test -n "$(git ls-files -u)" &&
-    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
     ( yes "l" | git mergetool submod ) &&
     git submodule update -N &&
@@ -286,7 +308,7 @@ test_expect_success 'file vs modified submodule' '
     git submodule update -N &&
     test_must_fail git merge test7 &&
     test -n "$(git ls-files -u)" &&
-    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
     ( yes "r" | git mergetool submod ) &&
     test -d submod.orig &&
@@ -301,7 +323,7 @@ test_expect_success 'file vs modified submodule' '
     git submodule update -N &&
     test_must_fail git merge test7 &&
     test -n "$(git ls-files -u)" &&
-    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
     ( yes "l" | git mergetool submod ) &&
     test "$(cat submod/bar)" = "master submodule" &&
@@ -388,7 +410,7 @@ test_expect_success 'directory vs modified submodule' '
     test "$(cat submod/file16)" = "not a submodule" &&
     rm -rf submod.orig &&
 
-    git reset --hard &&
+    git reset --hard >/dev/null 2>&1 &&
     test_must_fail git merge master &&
     test -n "$(git ls-files -u)" &&
     test ! -e submod.orig &&
@@ -400,7 +422,7 @@ test_expect_success 'directory vs modified submodule' '
     ( cd submod && git clean -f && git reset --hard ) &&
     git submodule update -N &&
     test "$(cat submod/bar)" = "master submodule" &&
-    git reset --hard && rm -rf submod-movedaside &&
+    git reset --hard >/dev/null 2>&1 && rm -rf submod-movedaside &&
 
     git checkout -b test11.c master &&
     git submodule update -N &&
@@ -410,7 +432,7 @@ test_expect_success 'directory vs modified submodule' '
     git submodule update -N &&
     test "$(cat submod/bar)" = "master submodule" &&
 
-    git reset --hard &&
+    git reset --hard >/dev/null 2>&1 &&
     git submodule update -N &&
     test_must_fail git merge test11 &&
     test -n "$(git ls-files -u)" &&
@@ -418,7 +440,7 @@ test_expect_success 'directory vs modified submodule' '
     ( yes "r" | git mergetool submod ) &&
     test "$(cat submod/file16)" = "not a submodule" &&
 
-    git reset --hard master &&
+    git reset --hard master >/dev/null 2>&1 &&
     ( cd submod && git clean -f && git reset --hard ) &&
     git submodule update -N
 '
index 4048d106d4936ae1eef2ca3788a147e659bda65d..395adfc8a946bfd67b8a61cbef1366b78d9d855e 100755 (executable)
@@ -10,9 +10,6 @@ Testing basic diff tool invocation
 
 . ./test-lib.sh
 
-LF='
-'
-
 remove_config_vars()
 {
        # Unset all config variables used by git-difftool
index a29ae45b399f89123f886f5b35580bcdc0e803f1..0d600163c8284a318fbd21f3a00dd7853b2f8956 100755 (executable)
@@ -509,6 +509,20 @@ test_expect_success 'grep -p -B5' '
        test_cmp expected actual
 '
 
+cat >expected <<EOF
+hello.c=int main(int argc, const char **argv)
+hello.c-{
+hello.c-       printf("Hello world.\n");
+hello.c:       return 0;
+hello.c-       /* char ?? */
+hello.c-}
+EOF
+
+test_expect_success 'grep -W' '
+       git grep -W return >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'grep from a subdirectory to search wider area (1)' '
        mkdir -p s &&
        (
index 3ab43902b3412d887794b7ca41d37b67af657361..8c9539e1b47a817fff98bad1ed1a99e890386ec9 100755 (executable)
@@ -38,4 +38,17 @@ test_expect_success 'verify svn:mergeinfo' '
        test "$mergeinfo" = "/branches/foo:1-10"
 '
 
+test_expect_success 'change svn:mergeinfo multiline' '
+       touch baz &&
+       git add baz &&
+       git commit -m "baz" &&
+       git svn dcommit --mergeinfo="/branches/bar:1-10 /branches/other:3-5,8,10-11"
+'
+
+test_expect_success 'verify svn:mergeinfo multiline' '
+       mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/trunk)
+       test "$mergeinfo" = "/branches/bar:1-10
+/branches/other:3-5,8,10-11"
+'
+
 test_done
index 85120b70db8cfb60b8d8c38f85a9038aa856468a..69e4815781c190207d406a4871a5dc5252690239 100755 (executable)
@@ -2,6 +2,14 @@
 test_description='git svn handling of root commits in merge ranges'
 . ./lib-git-svn.sh
 
+svn_ver="$(svn --version --quiet)"
+case $svn_ver in
+0.* | 1.[0-4].*)
+       skip_all="skipping git-svn test - SVN too old ($svn_ver)"
+       test_done
+       ;;
+esac
+
 test_expect_success 'test handling of root commits in merge ranges' '
        mkdir -p init/trunk init/branches init/tags &&
        echo "r1" > init/trunk/file.txt &&
diff --git a/t/t9160-git-svn-preserve-empty-dirs.sh b/t/t9160-git-svn-preserve-empty-dirs.sh
new file mode 100755 (executable)
index 0000000..b4a4434
--- /dev/null
@@ -0,0 +1,153 @@
+#!/bin/sh
+#
+# Copyright (c) 2011 Ray Chen
+#
+
+test_description='git svn test (option --preserve-empty-dirs)
+
+This test uses git to clone a Subversion repository that contains empty
+directories, and checks that corresponding directories are created in the
+local Git repository with placeholder files.'
+
+. ./lib-git-svn.sh
+
+say 'define NO_SVN_TESTS to skip git svn tests'
+GIT_REPO=git-svn-repo
+
+test_expect_success 'initialize source svn repo containing empty dirs' '
+       svn_cmd mkdir -m x "$svnrepo"/trunk &&
+       svn_cmd co "$svnrepo"/trunk "$SVN_TREE" &&
+       (
+               cd "$SVN_TREE" &&
+               mkdir -p 1 2 3/a 3/b 4 5 6 &&
+               echo "First non-empty file"  > 2/file1.txt &&
+               echo "Second non-empty file" > 2/file2.txt &&
+               echo "Third non-empty file"  > 3/a/file1.txt &&
+               echo "Fourth non-empty file" > 3/b/file1.txt &&
+               svn_cmd add 1 2 3 4 5 6 &&
+               svn_cmd commit -m "initial commit" &&
+
+               mkdir 4/a &&
+               svn_cmd add 4/a &&
+               svn_cmd commit -m "nested empty directory" &&
+               mkdir 4/a/b &&
+               svn_cmd add 4/a/b &&
+               svn_cmd commit -m "deeply nested empty directory" &&
+               mkdir 4/a/b/c &&
+               svn_cmd add 4/a/b/c &&
+               svn_cmd commit -m "really deeply nested empty directory" &&
+               echo "Kill the placeholder file" > 4/a/b/c/foo &&
+               svn_cmd add 4/a/b/c/foo &&
+               svn_cmd commit -m "Regular file to remove placeholder" &&
+
+               svn_cmd del 2/file2.txt &&
+               svn_cmd del 3/b &&
+               svn_cmd commit -m "delete non-last entry in directory" &&
+
+               svn_cmd del 2/file1.txt &&
+               svn_cmd del 3/a &&
+               svn_cmd commit -m "delete last entry in directory" &&
+
+               echo "Conflict file" > 5/.placeholder &&
+               mkdir 6/.placeholder &&
+               svn_cmd add 5/.placeholder 6/.placeholder &&
+               svn_cmd commit -m "Placeholder Namespace conflict"
+       ) &&
+       rm -rf "$SVN_TREE"
+'
+
+test_expect_success 'clone svn repo with --preserve-empty-dirs' '
+       git svn clone "$svnrepo"/trunk --preserve-empty-dirs "$GIT_REPO"
+'
+
+# "$GIT_REPO"/1 should only contain the placeholder file.
+test_expect_success 'directory empty from inception' '
+       test -f "$GIT_REPO"/1/.gitignore &&
+       test $(find "$GIT_REPO"/1 -type f | wc -l) = "1"
+'
+
+# "$GIT_REPO"/2 and "$GIT_REPO"/3 should only contain the placeholder file.
+test_expect_success 'directory empty from subsequent svn commit' '
+       test -f "$GIT_REPO"/2/.gitignore &&
+       test $(find "$GIT_REPO"/2 -type f | wc -l) = "1" &&
+       test -f "$GIT_REPO"/3/.gitignore &&
+       test $(find "$GIT_REPO"/3 -type f | wc -l) = "1"
+'
+
+# No placeholder files should exist in "$GIT_REPO"/4, even though one was
+# generated for every sub-directory at some point in the repo's history.
+test_expect_success 'add entry to previously empty directory' '
+       test $(find "$GIT_REPO"/4 -type f | wc -l) = "1" &&
+       test -f "$GIT_REPO"/4/a/b/c/foo
+'
+
+# The HEAD~2 commit should not have introduced .gitignore placeholder files.
+test_expect_success 'remove non-last entry from directory' '
+       (
+               cd "$GIT_REPO" &&
+               git checkout HEAD~2
+       ) &&
+       test_must_fail test -f "$GIT_REPO"/2/.gitignore &&
+       test_must_fail test -f "$GIT_REPO"/3/.gitignore
+'
+
+# After re-cloning the repository with --placeholder-file specified, there
+# should be 5 files named ".placeholder" in the local Git repo.
+test_expect_success 'clone svn repo with --placeholder-file specified' '
+       rm -rf "$GIT_REPO" &&
+       git svn clone "$svnrepo"/trunk --preserve-empty-dirs \
+               --placeholder-file=.placeholder "$GIT_REPO" &&
+       find "$GIT_REPO" -type f -name ".placeholder" &&
+       test $(find "$GIT_REPO" -type f -name ".placeholder" | wc -l) = "5"
+'
+
+# "$GIT_REPO"/5/.placeholder should be a file, and non-empty.
+test_expect_success 'placeholder namespace conflict with file' '
+       test -s "$GIT_REPO"/5/.placeholder
+'
+
+# "$GIT_REPO"/6/.placeholder should be a directory, and the "$GIT_REPO"/6 tree
+# should only contain one file: the placeholder.
+test_expect_success 'placeholder namespace conflict with directory' '
+       test -d "$GIT_REPO"/6/.placeholder &&
+       test -f "$GIT_REPO"/6/.placeholder/.placeholder &&
+       test $(find "$GIT_REPO"/6 -type f | wc -l) = "1"
+'
+
+# Prepare a second set of svn commits to test persistence during rebase.
+test_expect_success 'second set of svn commits and rebase' '
+       svn_cmd co "$svnrepo"/trunk "$SVN_TREE" &&
+       (
+               cd "$SVN_TREE" &&
+               mkdir -p 7 &&
+               echo "This should remove placeholder" > 1/file1.txt &&
+               echo "This should not remove placeholder" > 5/file1.txt &&
+               svn_cmd add 7 1/file1.txt 5/file1.txt &&
+               svn_cmd commit -m "subsequent svn commit for persistence tests"
+       ) &&
+       rm -rf "$SVN_TREE" &&
+       (
+               cd "$GIT_REPO" &&
+               git svn rebase
+       )
+'
+
+# Check that --preserve-empty-dirs and --placeholder-file flag state
+# stays persistent over multiple invocations.
+test_expect_success 'flag persistence during subsqeuent rebase' '
+       test -f "$GIT_REPO"/7/.placeholder &&
+       test $(find "$GIT_REPO"/7 -type f | wc -l) = "1"
+'
+
+# Check that placeholder files are properly removed when unnecessary,
+# even across multiple invocations.
+test_expect_success 'placeholder list persistence during subsqeuent rebase' '
+       test -f "$GIT_REPO"/1/file1.txt &&
+       test $(find "$GIT_REPO"/1 -type f | wc -l) = "1" &&
+
+       test -f "$GIT_REPO"/5/file1.txt &&
+       test -f "$GIT_REPO"/5/.placeholder &&
+       test $(find "$GIT_REPO"/5 -type f | wc -l) = "2"
+'
+
+test_done
diff --git a/t/t9161-git-svn-mergeinfo-push.sh b/t/t9161-git-svn-mergeinfo-push.sh
new file mode 100755 (executable)
index 0000000..6ef0c0b
--- /dev/null
@@ -0,0 +1,104 @@
+#!/bin/sh
+#
+# Portions copyright (c) 2007, 2009 Sam Vilain
+# Portions copyright (c) 2011 Bryan Jacobs
+#
+
+test_description='git-svn svn mergeinfo propagation'
+
+. ./lib-git-svn.sh
+
+test_expect_success 'load svn dump' "
+       svnadmin load -q '$rawsvnrepo' \
+         < '$TEST_DIRECTORY/t9161/branches.dump' &&
+       git svn init --minimize-url -R svnmerge \
+         -T trunk -b branches '$svnrepo' &&
+       git svn fetch --all
+       "
+
+test_expect_success 'propagate merge information' '
+       git config svn.pushmergeinfo yes &&
+       git checkout svnb1 &&
+       git merge --no-ff svnb2 &&
+       git svn dcommit
+       '
+
+test_expect_success 'check svn:mergeinfo' '
+       mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb1)
+       test "$mergeinfo" = "/branches/svnb2:3,8"
+       '
+
+test_expect_success 'merge another branch' '
+       git merge --no-ff svnb3 &&
+       git svn dcommit
+       '
+
+test_expect_success 'check primary parent mergeinfo respected' '
+       mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb1)
+       test "$mergeinfo" = "/branches/svnb2:3,8
+/branches/svnb3:4,9"
+       '
+
+test_expect_success 'merge existing merge' '
+       git merge --no-ff svnb4 &&
+       git svn dcommit
+       '
+
+test_expect_success "check both parents' mergeinfo respected" '
+       mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb1)
+       test "$mergeinfo" = "/branches/svnb2:3,8
+/branches/svnb3:4,9
+/branches/svnb4:5-6,10-12
+/branches/svnb5:6,11"
+       '
+
+test_expect_success 'make further commits to branch' '
+       git checkout svnb2 &&
+       touch newb2file &&
+       git add newb2file &&
+       git commit -m "later b2 commit" &&
+       touch newb2file-2 &&
+       git add newb2file-2 &&
+       git commit -m "later b2 commit 2" &&
+       git svn dcommit
+       '
+
+test_expect_success 'second forward merge' '
+       git checkout svnb1 &&
+       git merge --no-ff svnb2 &&
+       git svn dcommit
+       '
+
+test_expect_success 'check new mergeinfo added' '
+       mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb1)
+       test "$mergeinfo" = "/branches/svnb2:3,8,16-17
+/branches/svnb3:4,9
+/branches/svnb4:5-6,10-12
+/branches/svnb5:6,11"
+       '
+
+test_expect_success 'reintegration merge' '
+       git checkout svnb4 &&
+       git merge --no-ff svnb1 &&
+       git svn dcommit
+       '
+
+test_expect_success 'check reintegration mergeinfo' '
+       mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb4)
+       test "$mergeinfo" = "/branches/svnb1:2-4,7-9,13-18
+/branches/svnb2:3,8,16-17
+/branches/svnb3:4,9
+/branches/svnb4:5-6,10-12
+/branches/svnb5:6,11"
+       '
+
+test_expect_success 'dcommit a merge at the top of a stack' '
+       git checkout svnb1 &&
+       touch anotherfile &&
+       git add anotherfile &&
+       git commit -m "a commit" &&
+       git merge svnb4 &&
+       git svn dcommit
+       '
+
+test_done
diff --git a/t/t9161/branches.dump b/t/t9161/branches.dump
new file mode 100644 (file)
index 0000000..e61c3e7
--- /dev/null
@@ -0,0 +1,374 @@
+SVN-fs-dump-format-version: 2
+
+UUID: 1ef08553-f2d1-45df-b38c-19af6b7c926d
+
+Revision-number: 0
+Prop-content-length: 56
+Content-length: 56
+
+K 8
+svn:date
+V 27
+2011-09-02T16:08:02.941384Z
+PROPS-END
+
+Revision-number: 1
+Prop-content-length: 114
+Content-length: 114
+
+K 7
+svn:log
+V 12
+Base commit
+
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:08:27.205062Z
+PROPS-END
+
+Node-path: branches
+Node-kind: dir
+Node-action: add
+Prop-content-length: 10
+Content-length: 10
+
+PROPS-END
+
+
+Node-path: trunk
+Node-kind: dir
+Node-action: add
+Prop-content-length: 10
+Content-length: 10
+
+PROPS-END
+
+
+Revision-number: 2
+Prop-content-length: 121
+Content-length: 121
+
+K 7
+svn:log
+V 19
+Create branch svnb1
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:09:43.628137Z
+PROPS-END
+
+Node-path: branches/svnb1
+Node-kind: dir
+Node-action: add
+Node-copyfrom-rev: 1
+Node-copyfrom-path: trunk
+
+
+Revision-number: 3
+Prop-content-length: 121
+Content-length: 121
+
+K 7
+svn:log
+V 19
+Create branch svnb2
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:09:46.339930Z
+PROPS-END
+
+Node-path: branches/svnb2
+Node-kind: dir
+Node-action: add
+Node-copyfrom-rev: 1
+Node-copyfrom-path: trunk
+
+
+Revision-number: 4
+Prop-content-length: 121
+Content-length: 121
+
+K 7
+svn:log
+V 19
+Create branch svnb3
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:09:49.394515Z
+PROPS-END
+
+Node-path: branches/svnb3
+Node-kind: dir
+Node-action: add
+Node-copyfrom-rev: 1
+Node-copyfrom-path: trunk
+
+
+Revision-number: 5
+Prop-content-length: 121
+Content-length: 121
+
+K 7
+svn:log
+V 19
+Create branch svnb4
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:09:54.114607Z
+PROPS-END
+
+Node-path: branches/svnb4
+Node-kind: dir
+Node-action: add
+Node-copyfrom-rev: 1
+Node-copyfrom-path: trunk
+
+
+Revision-number: 6
+Prop-content-length: 121
+Content-length: 121
+
+K 7
+svn:log
+V 19
+Create branch svnb5
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:09:58.602623Z
+PROPS-END
+
+Node-path: branches/svnb5
+Node-kind: dir
+Node-action: add
+Node-copyfrom-rev: 1
+Node-copyfrom-path: trunk
+
+
+Revision-number: 7
+Prop-content-length: 110
+Content-length: 110
+
+K 7
+svn:log
+V 9
+b1 commit
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:10:20.292369Z
+PROPS-END
+
+Node-path: branches/svnb1/b1file
+Node-kind: file
+Node-action: add
+Prop-content-length: 10
+Text-content-length: 0
+Text-content-md5: d41d8cd98f00b204e9800998ecf8427e
+Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709
+Content-length: 10
+
+PROPS-END
+
+
+Revision-number: 8
+Prop-content-length: 110
+Content-length: 110
+
+K 7
+svn:log
+V 9
+b2 commit
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:10:38.429199Z
+PROPS-END
+
+Node-path: branches/svnb2/b2file
+Node-kind: file
+Node-action: add
+Prop-content-length: 10
+Text-content-length: 0
+Text-content-md5: d41d8cd98f00b204e9800998ecf8427e
+Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709
+Content-length: 10
+
+PROPS-END
+
+
+Revision-number: 9
+Prop-content-length: 110
+Content-length: 110
+
+K 7
+svn:log
+V 9
+b3 commit
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:10:52.843023Z
+PROPS-END
+
+Node-path: branches/svnb3/b3file
+Node-kind: file
+Node-action: add
+Prop-content-length: 10
+Text-content-length: 0
+Text-content-md5: d41d8cd98f00b204e9800998ecf8427e
+Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709
+Content-length: 10
+
+PROPS-END
+
+
+Revision-number: 10
+Prop-content-length: 110
+Content-length: 110
+
+K 7
+svn:log
+V 9
+b4 commit
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:11:17.489870Z
+PROPS-END
+
+Node-path: branches/svnb4/b4file
+Node-kind: file
+Node-action: add
+Prop-content-length: 10
+Text-content-length: 0
+Text-content-md5: d41d8cd98f00b204e9800998ecf8427e
+Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709
+Content-length: 10
+
+PROPS-END
+
+
+Revision-number: 11
+Prop-content-length: 110
+Content-length: 110
+
+K 7
+svn:log
+V 9
+b5 commit
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:11:32.277404Z
+PROPS-END
+
+Node-path: branches/svnb5/b5file
+Node-kind: file
+Node-action: add
+Prop-content-length: 10
+Text-content-length: 0
+Text-content-md5: d41d8cd98f00b204e9800998ecf8427e
+Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709
+Content-length: 10
+
+PROPS-END
+
+
+Revision-number: 12
+Prop-content-length: 192
+Content-length: 192
+
+K 7
+svn:log
+V 90
+Merge remote-tracking branch 'svnb5' into HEAD
+
+* svnb5:
+  b5 commit
+  Create branch svnb5
+K 10
+svn:author
+V 7
+bjacobs
+K 8
+svn:date
+V 27
+2011-09-02T16:11:54.274722Z
+PROPS-END
+
+Node-path: branches/svnb4
+Node-kind: dir
+Node-action: change
+Prop-content-length: 56
+Content-length: 56
+
+K 13
+svn:mergeinfo
+V 21
+/branches/svnb5:6,11
+
+PROPS-END
+
+
+Node-path: branches/svnb4/b5file
+Node-kind: file
+Node-action: add
+Prop-content-length: 10
+Text-content-length: 0
+Text-content-md5: d41d8cd98f00b204e9800998ecf8427e
+Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709
+Content-length: 10
+
+PROPS-END
+
+
index e5da65b99fa1459836e516772fe8d13d038f502e..41db05cb4af6f42ef3065ba0576d8cfa3509c0ca 100755 (executable)
@@ -50,8 +50,8 @@ test_expect_success \
     'mkdir A B C D E F &&
      echo hello1 >A/newfile1.txt &&
      echo hello2 >B/newfile2.txt &&
-     cp "$TEST_DIRECTORY"/test9200a.png C/newfile3.png &&
-     cp "$TEST_DIRECTORY"/test9200a.png D/newfile4.png &&
+     cp "$TEST_DIRECTORY"/test-binary-1.png C/newfile3.png &&
+     cp "$TEST_DIRECTORY"/test-binary-1.png D/newfile4.png &&
      git add A/newfile1.txt &&
      git add B/newfile2.txt &&
      git add C/newfile3.png &&
@@ -76,8 +76,8 @@ test_expect_success \
      rm -f B/newfile2.txt &&
      rm -f C/newfile3.png &&
      echo Hello5  >E/newfile5.txt &&
-     cp "$TEST_DIRECTORY"/test9200b.png D/newfile4.png &&
-     cp "$TEST_DIRECTORY"/test9200a.png F/newfile6.png &&
+     cp "$TEST_DIRECTORY"/test-binary-2.png D/newfile4.png &&
+     cp "$TEST_DIRECTORY"/test-binary-1.png F/newfile6.png &&
      git add E/newfile5.txt &&
      git add F/newfile6.png &&
      git commit -a -m "Test: Remove, add and update" &&
@@ -165,7 +165,7 @@ test_expect_success \
      'mkdir "G g" &&
       echo ok then >"G g/with spaces.txt" &&
       git add "G g/with spaces.txt" && \
-      cp "$TEST_DIRECTORY"/test9200a.png "G g/with spaces.png" && \
+      cp "$TEST_DIRECTORY"/test-binary-1.png "G g/with spaces.png" && \
       git add "G g/with spaces.png" &&
       git commit -a -m "With spaces" &&
       id=$(git rev-list --max-count=1 HEAD) &&
@@ -177,7 +177,7 @@ test_expect_success \
 test_expect_success \
      'Update file with spaces in file name' \
      'echo Ok then >>"G g/with spaces.txt" &&
-      cat "$TEST_DIRECTORY"/test9200a.png >>"G g/with spaces.png" && \
+      cat "$TEST_DIRECTORY"/test-binary-1.png >>"G g/with spaces.png" && \
       git add "G g/with spaces.png" &&
       git commit -a -m "Update with spaces" &&
       id=$(git rev-list --max-count=1 HEAD) &&
@@ -202,7 +202,7 @@ test_expect_success \
      'mkdir -p Å/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/å/ä/ö &&
       echo Foo >Å/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.txt &&
       git add Å/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.txt &&
-      cp "$TEST_DIRECTORY"/test9200a.png Å/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 &&
+      cp "$TEST_DIRECTORY"/test-binary-1.png Å/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 &&
       git add Å/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 &&
       git commit -a -m "Går det så går det" && \
       id=$(git rev-list --max-count=1 HEAD) &&
index 2a53640c5b29c19a2327570148638dbf94bc2afa..1a6c06631c1c2a8fc29b66c9265541b54e8a9715 100755 (executable)
@@ -94,6 +94,12 @@ data <<EOF
 An annotated tag without a tagger
 EOF
 
+tag series-A-blob
+from :3
+data <<EOF
+An annotated tag that annotates a blob.
+EOF
+
 INPUT_END
 test_expect_success \
     'A: create pack from stdin' \
@@ -151,6 +157,18 @@ test_expect_success 'A: verify tag/series-A' '
        test_cmp expect actual
 '
 
+cat >expect <<EOF
+object $(git rev-parse refs/heads/master:file3)
+type blob
+tag series-A-blob
+
+An annotated tag that annotates a blob.
+EOF
+test_expect_success 'A: verify tag/series-A-blob' '
+       git cat-file tag tags/series-A-blob >actual &&
+       test_cmp expect actual
+'
+
 cat >expect <<EOF
 :2 `git rev-parse --verify master:file2`
 :3 `git rev-parse --verify master:file3`
@@ -169,6 +187,55 @@ test_expect_success \
                </dev/null &&
        test_cmp expect marks.new'
 
+test_tick
+new_blob=$(echo testing | git hash-object --stdin)
+cat >input <<INPUT_END
+tag series-A-blob-2
+from $(git rev-parse refs/heads/master:file3)
+data <<EOF
+Tag blob by sha1.
+EOF
+
+blob
+mark :6
+data <<EOF
+testing
+EOF
+
+commit refs/heads/new_blob
+committer  <> 0 +0000
+data 0
+M 644 :6 new_blob
+#pretend we got sha1 from fast-import
+ls "new_blob"
+
+tag series-A-blob-3
+from $new_blob
+data <<EOF
+Tag new_blob.
+EOF
+INPUT_END
+
+cat >expect <<EOF
+object $(git rev-parse refs/heads/master:file3)
+type blob
+tag series-A-blob-2
+
+Tag blob by sha1.
+object $new_blob
+type blob
+tag series-A-blob-3
+
+Tag new_blob.
+EOF
+
+test_expect_success \
+       'A: tag blob by sha1' \
+       'git fast-import <input &&
+       git cat-file tag tags/series-A-blob-2 >actual &&
+       git cat-file tag tags/series-A-blob-3 >>actual &&
+       test_cmp expect actual'
+
 test_tick
 cat >input <<INPUT_END
 commit refs/heads/verify--import-marks
@@ -324,6 +391,105 @@ test_expect_success \
         test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
 rm -f .git/TEMP_TAG
 
+git gc 2>/dev/null >/dev/null
+git prune 2>/dev/null >/dev/null
+
+cat >input <<INPUT_END
+commit refs/heads/empty-committer-1
+committer  <> $GIT_COMMITTER_DATE
+data <<COMMIT
+empty commit
+COMMIT
+INPUT_END
+test_expect_success 'B: accept empty committer' '
+       git fast-import <input &&
+       out=$(git fsck) &&
+       echo "$out" &&
+       test -z "$out"
+'
+git update-ref -d refs/heads/empty-committer-1 || true
+
+git gc 2>/dev/null >/dev/null
+git prune 2>/dev/null >/dev/null
+
+cat >input <<INPUT_END
+commit refs/heads/empty-committer-2
+committer <a@b.com> $GIT_COMMITTER_DATE
+data <<COMMIT
+empty commit
+COMMIT
+INPUT_END
+test_expect_success 'B: accept and fixup committer with no name' '
+       git fast-import <input &&
+       out=$(git fsck) &&
+       echo "$out" &&
+       test -z "$out"
+'
+git update-ref -d refs/heads/empty-committer-2 || true
+
+git gc 2>/dev/null >/dev/null
+git prune 2>/dev/null >/dev/null
+
+cat >input <<INPUT_END
+commit refs/heads/invalid-committer
+committer Name email> $GIT_COMMITTER_DATE
+data <<COMMIT
+empty commit
+COMMIT
+INPUT_END
+test_expect_success 'B: fail on invalid committer (1)' '
+       test_must_fail git fast-import <input
+'
+git update-ref -d refs/heads/invalid-committer || true
+
+cat >input <<INPUT_END
+commit refs/heads/invalid-committer
+committer Name <e<mail> $GIT_COMMITTER_DATE
+data <<COMMIT
+empty commit
+COMMIT
+INPUT_END
+test_expect_success 'B: fail on invalid committer (2)' '
+       test_must_fail git fast-import <input
+'
+git update-ref -d refs/heads/invalid-committer || true
+
+cat >input <<INPUT_END
+commit refs/heads/invalid-committer
+committer Name <email>> $GIT_COMMITTER_DATE
+data <<COMMIT
+empty commit
+COMMIT
+INPUT_END
+test_expect_success 'B: fail on invalid committer (3)' '
+       test_must_fail git fast-import <input
+'
+git update-ref -d refs/heads/invalid-committer || true
+
+cat >input <<INPUT_END
+commit refs/heads/invalid-committer
+committer Name <email $GIT_COMMITTER_DATE
+data <<COMMIT
+empty commit
+COMMIT
+INPUT_END
+test_expect_success 'B: fail on invalid committer (4)' '
+       test_must_fail git fast-import <input
+'
+git update-ref -d refs/heads/invalid-committer || true
+
+cat >input <<INPUT_END
+commit refs/heads/invalid-committer
+committer Name<email> $GIT_COMMITTER_DATE
+data <<COMMIT
+empty commit
+COMMIT
+INPUT_END
+test_expect_success 'B: fail on invalid committer (5)' '
+       test_must_fail git fast-import <input
+'
+git update-ref -d refs/heads/invalid-committer || true
+
 ###
 ### series C
 ###
@@ -734,6 +900,47 @@ test_expect_success \
         git diff-tree --abbrev --raw L^ L >output &&
         test_cmp expect output'
 
+cat >input <<INPUT_END
+blob
+mark :1
+data <<EOF
+the data
+EOF
+
+commit refs/heads/L2
+committer C O Mitter <committer@example.com> 1112912473 -0700
+data <<COMMIT
+init L2
+COMMIT
+M 644 :1 a/b/c
+M 644 :1 a/b/d
+M 644 :1 a/e/f
+
+commit refs/heads/L2
+committer C O Mitter <committer@example.com> 1112912473 -0700
+data <<COMMIT
+update L2
+COMMIT
+C a g
+C a/e g/b
+M 644 :1 g/b/h
+INPUT_END
+
+cat <<EOF >expect
+g/b/f
+g/b/h
+EOF
+
+test_expect_success \
+    'L: nested tree copy does not corrupt deltas' \
+       'git fast-import <input &&
+       git ls-tree L2 g/b/ >tmp &&
+       cat tmp | cut -f 2 >actual &&
+       test_cmp expect actual &&
+       git fsck `git rev-parse L2`'
+
+git update-ref -d refs/heads/L2
+
 ###
 ### series M
 ###
@@ -1882,6 +2089,53 @@ test_expect_success 'R: --import-marks-if-exists' '
        test_cmp expect io.marks
 '
 
+test_expect_success 'R: feature import-marks-if-exists' '
+       rm -f io.marks &&
+       >expect &&
+
+       git fast-import --export-marks=io.marks <<-\EOF &&
+       feature import-marks-if-exists=not_io.marks
+       EOF
+       test_cmp expect io.marks &&
+
+       blob=$(echo hi | git hash-object --stdin) &&
+
+       echo ":1 $blob" >io.marks &&
+       echo ":1 $blob" >expect &&
+       echo ":2 $blob" >>expect &&
+
+       git fast-import --export-marks=io.marks <<-\EOF &&
+       feature import-marks-if-exists=io.marks
+       blob
+       mark :2
+       data 3
+       hi
+
+       EOF
+       test_cmp expect io.marks &&
+
+       echo ":3 $blob" >>expect &&
+
+       git fast-import --import-marks=io.marks \
+                       --export-marks=io.marks <<-\EOF &&
+       feature import-marks-if-exists=not_io.marks
+       blob
+       mark :3
+       data 3
+       hi
+
+       EOF
+       test_cmp expect io.marks &&
+
+       >expect &&
+
+       git fast-import --import-marks-if-exists=not_io.marks \
+                       --export-marks=io.marks <<-\EOF
+       feature import-marks-if-exists=io.marks
+       EOF
+       test_cmp expect io.marks
+'
+
 cat >input << EOF
 feature import-marks=marks.out
 feature export-marks=marks.new
@@ -2197,6 +2451,48 @@ test_expect_success 'R: quiet option results in no stats being output' '
     test_cmp empty output
 '
 
+test_expect_success 'R: feature done means terminating "done" is mandatory' '
+       echo feature done | test_must_fail git fast-import &&
+       test_must_fail git fast-import --done </dev/null
+'
+
+test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
+       git fast-import <<-\EOF &&
+       feature done
+       done
+       trailing gibberish
+       EOF
+       git fast-import <<-\EOF
+       done
+       more trailing gibberish
+       EOF
+'
+
+test_expect_success 'R: terminating "done" within commit' '
+       cat >expect <<-\EOF &&
+       OBJID
+       :000000 100644 OBJID OBJID A    hello.c
+       :000000 100644 OBJID OBJID A    hello2.c
+       EOF
+       git fast-import <<-EOF &&
+       commit refs/heads/done-ends
+       committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+       data <<EOT
+       Commit terminated by "done" command
+       EOT
+       M 100644 inline hello.c
+       data <<EOT
+       Hello, world.
+       EOT
+       C hello.c hello2.c
+       done
+       EOF
+       git rev-list done-ends |
+       git diff-tree -r --stdin --root --always |
+       sed -e "s/$_x40/OBJID/g" >actual &&
+       test_cmp expect actual
+'
+
 cat >input <<EOF
 option git non-existing-option
 EOF
index f823c05305e5021a8cca98d49256af3b1c008fb9..950d0ff498fda58c2d3d68dfb2cf50512f8f81ba 100755 (executable)
@@ -228,7 +228,7 @@ test_expect_success 'fast-export -C -C | fast-import' '
        mkdir new &&
        git --git-dir=new/.git init &&
        git fast-export -C -C --signed-tags=strip --all > output &&
-       grep "^C \"file6\" \"file7\"\$" output &&
+       grep "^C file6 file7\$" output &&
        cat output |
        (cd new &&
         git fast-import &&
@@ -414,4 +414,30 @@ test_expect_success SYMLINKS 'directory becomes symlink'        '
        (cd result && git show master:foo)
 '
 
+test_expect_success 'fast-export quotes pathnames' '
+       git init crazy-paths &&
+       (cd crazy-paths &&
+        blob=`echo foo | git hash-object -w --stdin` &&
+        git update-index --add \
+               --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
+               --cacheinfo 100644 $blob "path with \"quote\"" \
+               --cacheinfo 100644 $blob "path with \\backslash" \
+               --cacheinfo 100644 $blob "path with space" &&
+        git commit -m addition &&
+        git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
+        git read-tree --empty &&
+        git update-index -z --index-info <index &&
+        git commit -m rename &&
+        git read-tree --empty &&
+        git commit -m deletion &&
+        git fast-export HEAD >export.out &&
+        git rev-list HEAD >expect &&
+        git init result &&
+        cd result &&
+        git fast-import <../export.out &&
+        git rev-list HEAD >actual &&
+        test_cmp ../expect actual
+       )
+'
+
 test_done
index 33b0127651da0c4c178e62c269179b641e15f9f6..01ba041fdefe61a3e712344bfe257a1b9cba3b4b 100755 (executable)
@@ -45,29 +45,33 @@ test_expect_success 'add p4 files' '
        cd "$TRASH_DIRECTORY"
 '
 
+cleanup_git() {
+       cd "$TRASH_DIRECTORY" &&
+       rm -rf "$git" &&
+       mkdir "$git"
+}
+
 test_expect_success 'basic git-p4 clone' '
        "$GITP4" clone --dest="$git" //depot &&
+       test_when_finished cleanup_git &&
        cd "$git" &&
        git log --oneline >lines &&
-       test_line_count = 1 lines &&
-       cd .. &&
-       rm -rf "$git" && mkdir "$git"
+       test_line_count = 1 lines
 '
 
 test_expect_success 'git-p4 clone @all' '
        "$GITP4" clone --dest="$git" //depot@all &&
+       test_when_finished cleanup_git &&
        cd "$git" &&
        git log --oneline >lines &&
-       test_line_count = 2 lines &&
-       cd .. &&
-       rm -rf "$git" && mkdir "$git"
+       test_line_count = 2 lines
 '
 
 test_expect_success 'git-p4 sync uninitialized repo' '
        test_create_repo "$git" &&
+       test_when_finished cleanup_git &&
        cd "$git" &&
-       test_must_fail "$GITP4" sync &&
-       rm -rf "$git" && mkdir "$git"
+       test_must_fail "$GITP4" sync
 '
 
 #
@@ -76,19 +80,18 @@ test_expect_success 'git-p4 sync uninitialized repo' '
 #
 test_expect_success 'git-p4 sync new branch' '
        test_create_repo "$git" &&
+       test_when_finished cleanup_git &&
        cd "$git" &&
        test_commit head &&
        "$GITP4" sync --branch=refs/remotes/p4/depot //depot@all &&
        git log --oneline p4/depot >lines &&
-       cat lines &&
-       test_line_count = 2 lines &&
-       cd .. &&
-       rm -rf "$git" && mkdir "$git"
+       test_line_count = 2 lines
 '
 
 test_expect_success 'exit when p4 fails to produce marshaled output' '
        badp4dir="$TRASH_DIRECTORY/badp4dir" &&
        mkdir -p "$badp4dir" &&
+       test_when_finished "rm -rf $badp4dir" &&
        cat >"$badp4dir"/p4 <<-EOF &&
        #!$SHELL_PATH
        exit 1
@@ -106,29 +109,26 @@ test_expect_success 'add p4 files with wildcards in the names' '
        echo file-wild-at >file-wild@at &&
        echo file-wild-percent >file-wild%percent &&
        p4 add -f file-wild* &&
-       p4 submit -d "file wildcards" &&
-       cd "$TRASH_DIRECTORY"
+       p4 submit -d "file wildcards"
 '
 
 test_expect_success 'wildcard files git-p4 clone' '
        "$GITP4" clone --dest="$git" //depot &&
+       test_when_finished cleanup_git &&
        cd "$git" &&
        test -f file-wild#hash &&
        test -f file-wild\*star &&
        test -f file-wild@at &&
-       test -f file-wild%percent &&
-       cd "$TRASH_DIRECTORY" &&
-       rm -rf "$git" && mkdir "$git"
+       test -f file-wild%percent
 '
 
 test_expect_success 'clone bare' '
        "$GITP4" clone --dest="$git" --bare //depot &&
+       test_when_finished cleanup_git &&
        cd "$git" &&
        test ! -d .git &&
        bare=`git config --get core.bare` &&
-       test "$bare" = true &&
-       cd "$TRASH_DIRECTORY" &&
-       rm -rf "$git" && mkdir "$git"
+       test "$bare" = true
 '
 
 p4_add_user() {
@@ -173,6 +173,7 @@ test_expect_success 'preserve users' '
        p4_add_user bob Bob &&
        p4_grant_admin alice &&
        "$GITP4" clone --dest="$git" //depot &&
+       test_when_finished cleanup_git &&
        cd "$git" &&
        echo "username: a change by alice" >> file1 &&
        echo "username: a change by bob" >> file2 &&
@@ -181,29 +182,28 @@ test_expect_success 'preserve users' '
        git config git-p4.skipSubmitEditCheck true &&
        P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user &&
        p4_check_commit_author file1 alice &&
-       p4_check_commit_author file2 bob &&
-       cd "$TRASH_DIRECTORY" &&
-       rm -rf "$git" && mkdir "$git"
+       p4_check_commit_author file2 bob
 '
 
 # Test username support, submitting as bob, who lacks admin rights. Should
 # not submit change to p4 (git diff should show deltas).
 test_expect_success 'refuse to preserve users without perms' '
        "$GITP4" clone --dest="$git" //depot &&
+       test_when_finished cleanup_git &&
        cd "$git" &&
+       git config git-p4.skipSubmitEditCheck true &&
        echo "username-noperms: a change by alice" >> file1 &&
        git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 &&
        ! P4EDITOR=touch P4USER=bob P4PASSWD=secret "$GITP4" commit --preserve-user &&
-       ! git diff --exit-code HEAD..p4/master > /dev/null &&
-       cd "$TRASH_DIRECTORY" &&
-       rm -rf "$git" && mkdir "$git"
+       ! git diff --exit-code HEAD..p4/master > /dev/null
 '
 
 # What happens with unknown author? Without allowMissingP4Users it should fail.
 test_expect_success 'preserve user where author is unknown to p4' '
        "$GITP4" clone --dest="$git" //depot &&
+       test_when_finished cleanup_git &&
        cd "$git" &&
-       git config git-p4.skipSubmitEditCheck true
+       git config git-p4.skipSubmitEditCheck true &&
        echo "username-bob: a change by bob" >> file1 &&
        git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 &&
        echo "username-unknown: a change by charlie" >> file1 &&
@@ -215,9 +215,7 @@ test_expect_success 'preserve user where author is unknown to p4' '
        git config git-p4.preserveUser true &&
        P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit &&
        git diff --exit-code HEAD..p4/master > /dev/null &&
-       p4_check_commit_author file1 alice &&
-       cd "$TRASH_DIRECTORY" &&
-       rm -rf "$git" && mkdir "$git"
+       p4_check_commit_author file1 alice
 '
 
 # If we're *not* using --preserve-user, git-p4 should warn if we're submitting
@@ -226,33 +224,247 @@ test_expect_success 'preserve user where author is unknown to p4' '
 # Test: warning disabled and user is the same.
 test_expect_success 'not preserving user with mixed authorship' '
        "$GITP4" clone --dest="$git" //depot &&
-       (
-               cd "$git" &&
-               git config git-p4.skipSubmitEditCheck true &&
-               p4_add_user derek Derek &&
-
-               make_change_by_user usernamefile3 Derek derek@localhost &&
-               P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
-               grep "git author derek@localhost does not match" actual &&
-
-               make_change_by_user usernamefile3 Charlie charlie@localhost &&
-               P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
-               grep "git author charlie@localhost does not match" actual &&
-
-               make_change_by_user usernamefile3 alice alice@localhost &&
-               P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
-               ! grep "git author.*does not match" actual &&
-
-               git config git-p4.skipUserNameCheck true &&
-               make_change_by_user usernamefile3 Charlie charlie@localhost &&
-               P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
-               ! grep "git author.*does not match" actual &&
-
-               p4_check_commit_author usernamefile3 alice
-       ) &&
-       rm -rf "$git" && mkdir "$git"
+       test_when_finished cleanup_git &&
+       cd "$git" &&
+       git config git-p4.skipSubmitEditCheck true &&
+       p4_add_user derek Derek &&
+
+       make_change_by_user usernamefile3 Derek derek@localhost &&
+       P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
+       grep "git author derek@localhost does not match" actual &&
+
+       make_change_by_user usernamefile3 Charlie charlie@localhost &&
+       P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
+       grep "git author charlie@localhost does not match" actual &&
+
+       make_change_by_user usernamefile3 alice alice@localhost &&
+       P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
+       ! grep "git author.*does not match" actual &&
+
+       git config git-p4.skipUserNameCheck true &&
+       make_change_by_user usernamefile3 Charlie charlie@localhost &&
+       P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
+       ! grep "git author.*does not match" actual &&
+
+       p4_check_commit_author usernamefile3 alice
 '
 
+marshal_dump() {
+       what=$1
+       python -c 'import marshal, sys; d = marshal.load(sys.stdin); print d["'$what'"]'
+}
+
+# Sleep a bit so that the top-most p4 change did not happen "now".  Then
+# import the repo and make sure that the initial import has the same time
+# as the top-most change.
+test_expect_success 'initial import time from top change time' '
+       p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) &&
+       p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) &&
+       sleep 3 &&
+       "$GITP4" clone --dest="$git" //depot &&
+       test_when_finished cleanup_git &&
+       cd "$git" &&
+       gittime=$(git show -s --raw --pretty=format:%at HEAD) &&
+       echo $p4time $gittime &&
+       test $p4time = $gittime
+'
+
+# Rename a file and confirm that rename is not detected in P4.
+# Rename the new file again with detectRenames option enabled and confirm that
+# this is detected in P4.
+# Rename the new file again adding an extra line, configure a big threshold in
+# detectRenames and confirm that rename is not detected in P4.
+# Repeat, this time with a smaller threshold and confirm that the rename is
+# detected in P4.
+test_expect_success 'detect renames' '
+       "$GITP4" clone --dest="$git" //depot@all &&
+       test_when_finished cleanup_git &&
+       cd "$git" &&
+       git config git-p4.skipSubmitEditCheck true &&
+
+       git mv file1 file4 &&
+       git commit -a -m "Rename file1 to file4" &&
+       git diff-tree -r -M HEAD &&
+       "$GITP4" submit &&
+       p4 filelog //depot/file4 &&
+       ! p4 filelog //depot/file4 | grep -q "branch from" &&
+
+       git mv file4 file5 &&
+       git commit -a -m "Rename file4 to file5" &&
+       git diff-tree -r -M HEAD &&
+       git config git-p4.detectRenames true &&
+       "$GITP4" submit &&
+       p4 filelog //depot/file5 &&
+       p4 filelog //depot/file5 | grep -q "branch from //depot/file4" &&
+
+       git mv file5 file6 &&
+       echo update >>file6 &&
+       git add file6 &&
+       git commit -a -m "Rename file5 to file6 with changes" &&
+       git diff-tree -r -M HEAD &&
+       level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
+       test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
+       git config git-p4.detectRenames $((level + 2)) &&
+       "$GITP4" submit &&
+       p4 filelog //depot/file6 &&
+       ! p4 filelog //depot/file6 | grep -q "branch from" &&
+
+       git mv file6 file7 &&
+       echo update >>file7 &&
+       git add file7 &&
+       git commit -a -m "Rename file6 to file7 with changes" &&
+       git diff-tree -r -M HEAD &&
+       level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
+       test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
+       git config git-p4.detectRenames $((level - 2)) &&
+       "$GITP4" submit &&
+       p4 filelog //depot/file7 &&
+       p4 filelog //depot/file7 | grep -q "branch from //depot/file6"
+'
+
+# Copy a file and confirm that copy is not detected in P4.
+# Copy a file with detectCopies option enabled and confirm that copy is not
+# detected in P4.
+# Modify and copy a file with detectCopies option enabled and confirm that copy
+# is detected in P4.
+# Copy a file with detectCopies and detectCopiesHarder options enabled and
+# confirm that copy is detected in P4.
+# Modify and copy a file, configure a bigger threshold in detectCopies and
+# confirm that copy is not detected in P4.
+# Modify and copy a file, configure a smaller threshold in detectCopies and
+# confirm that copy is detected in P4.
+test_expect_success 'detect copies' '
+       "$GITP4" clone --dest="$git" //depot@all &&
+       test_when_finished cleanup_git &&
+       cd "$git" &&
+       git config git-p4.skipSubmitEditCheck true &&
+
+       cp file2 file8 &&
+       git add file8 &&
+       git commit -a -m "Copy file2 to file8" &&
+       git diff-tree -r -C HEAD &&
+       "$GITP4" submit &&
+       p4 filelog //depot/file8 &&
+       ! p4 filelog //depot/file8 | grep -q "branch from" &&
+
+       cp file2 file9 &&
+       git add file9 &&
+       git commit -a -m "Copy file2 to file9" &&
+       git diff-tree -r -C HEAD &&
+       git config git-p4.detectCopies true &&
+       "$GITP4" submit &&
+       p4 filelog //depot/file9 &&
+       ! p4 filelog //depot/file9 | grep -q "branch from" &&
+
+       echo "file2" >>file2 &&
+       cp file2 file10 &&
+       git add file2 file10 &&
+       git commit -a -m "Modify and copy file2 to file10" &&
+       git diff-tree -r -C HEAD &&
+       "$GITP4" submit &&
+       p4 filelog //depot/file10 &&
+       p4 filelog //depot/file10 | grep -q "branch from //depot/file" &&
+
+       cp file2 file11 &&
+       git add file11 &&
+       git commit -a -m "Copy file2 to file11" &&
+       git diff-tree -r -C --find-copies-harder HEAD &&
+       src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
+       test "$src" = file10 &&
+       git config git-p4.detectCopiesHarder true &&
+       "$GITP4" submit &&
+       p4 filelog //depot/file11 &&
+       p4 filelog //depot/file11 | grep -q "branch from //depot/file" &&
+
+       cp file2 file12 &&
+       echo "some text" >>file12 &&
+       git add file12 &&
+       git commit -a -m "Copy file2 to file12 with changes" &&
+       git diff-tree -r -C --find-copies-harder HEAD &&
+       level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
+       test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
+       src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
+       test "$src" = file10 &&
+       git config git-p4.detectCopies $((level + 2)) &&
+       "$GITP4" submit &&
+       p4 filelog //depot/file12 &&
+       ! p4 filelog //depot/file12 | grep -q "branch from" &&
+
+       cp file2 file13 &&
+       echo "different text" >>file13 &&
+       git add file13 &&
+       git commit -a -m "Copy file2 to file13 with changes" &&
+       git diff-tree -r -C --find-copies-harder HEAD &&
+       level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
+       test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
+       src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
+       test "$src" = file10 &&
+       git config git-p4.detectCopies $((level - 2)) &&
+       "$GITP4" submit &&
+       p4 filelog //depot/file13 &&
+       p4 filelog //depot/file13 | grep -q "branch from //depot/file"
+'
+
+# Create a simple branch structure in P4 depot to check if it is correctly
+# cloned.
+test_expect_success 'add simple p4 branches' '
+       cd "$cli" &&
+       mkdir branch1 &&
+       cd branch1 &&
+       echo file1 >file1 &&
+       echo file2 >file2 &&
+       p4 add file1 file2 &&
+       p4 submit -d "branch1" &&
+       p4 integrate //depot/branch1/... //depot/branch2/... &&
+       p4 submit -d "branch2" &&
+       echo file3 >file3 &&
+       p4 add file3 &&
+       p4 submit -d "add file3 in branch1" &&
+       p4 open file2 &&
+       echo update >>file2 &&
+       p4 submit -d "update file2 in branch1" &&
+       p4 integrate //depot/branch1/... //depot/branch3/... &&
+       p4 submit -d "branch3" &&
+       cd "$TRASH_DIRECTORY"
+'
+
+# Configure branches through git-config and clone them.
+# All files are tested to make sure branches were cloned correctly.
+# Finally, make an update to branch1 on P4 side to check if it is imported
+# correctly by git-p4.
+test_expect_success 'git-p4 clone simple branches' '
+       test_when_finished cleanup_git &&
+       test_create_repo "$git" &&
+       cd "$git" &&
+       git config git-p4.branchList branch1:branch2 &&
+       git config --add git-p4.branchList branch1:branch3 &&
+       "$GITP4" clone --dest=. --detect-branches //depot@all &&
+       git log --all --graph --decorate --stat &&
+       git reset --hard p4/depot/branch1 &&
+       test -f file1 &&
+       test -f file2 &&
+       test -f file3 &&
+       grep -q update file2 &&
+       git reset --hard p4/depot/branch2 &&
+       test -f file1 &&
+       test -f file2 &&
+       test ! -f file3 &&
+       ! grep -q update file2 &&
+       git reset --hard p4/depot/branch3 &&
+       test -f file1 &&
+       test -f file2 &&
+       test -f file3 &&
+       grep -q update file2 &&
+       cd "$cli" &&
+       cd branch1 &&
+       p4 edit file2 &&
+       echo file2_ >>file2 &&
+       p4 submit -d "update file2 in branch1" &&
+       cd "$git" &&
+       git reset --hard p4/depot/branch1 &&
+       "$GITP4" rebase &&
+       grep -q file2_ file2
+'
 
 test_expect_success 'shutdown' '
        pid=`pgrep -f p4d` &&
diff --git a/t/test-binary-1.png b/t/test-binary-1.png
new file mode 100644 (file)
index 0000000..7b181d1
Binary files /dev/null and b/t/test-binary-1.png differ
diff --git a/t/test-binary-2.png b/t/test-binary-2.png
new file mode 100644 (file)
index 0000000..ac22ccb
Binary files /dev/null and b/t/test-binary-2.png differ
index df25f1792923a65aab2c4ce88e7b528effb381f5..bdd9513b84301275330d3dd7e49af05081ef9cd7 100644 (file)
@@ -92,6 +92,10 @@ _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
 # Zero SHA-1
 _z40=0000000000000000000000000000000000000000
 
+# Line feed
+LF='
+'
+
 # Each test should start with something like this, after copyright notices:
 #
 # test_description='Description of this test...
@@ -357,6 +361,24 @@ test_chmod () {
        git update-index --add "--chmod=$@"
 }
 
+# Unset a configuration variable, but don't fail if it doesn't exist.
+test_unconfig () {
+       git config --unset-all "$@"
+       config_status=$?
+       case "$config_status" in
+       5) # ok, nothing to unset
+               config_status=0
+               ;;
+       esac
+       return $config_status
+}
+
+# Set git config, automatically unsetting it after the test is over.
+test_config () {
+       test_when_finished "test_unconfig '$1'" &&
+       git config "$@"
+}
+
 # Use test_set_prereq to tell that a particular prerequisite is available.
 # The prerequisite can later be checked for in two ways:
 #
@@ -444,20 +466,26 @@ test_debug () {
        test "$debug" = "" || eval "$1"
 }
 
+test_eval_ () {
+       # This is a separate function because some tests use
+       # "return" to end a test_expect_success block early.
+       eval >&3 2>&4 "$*"
+}
+
 test_run_ () {
        test_cleanup=:
        expecting_failure=$2
-       eval >&3 2>&4 "$1"
+       test_eval_ "$1"
        eval_ret=$?
 
        if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure"
        then
-               eval >&3 2>&4 "$test_cleanup"
+               test_eval_ "$test_cleanup"
        fi
        if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"; then
                echo ""
        fi
-       return 0
+       return "$eval_ret"
 }
 
 test_skip () {
@@ -502,8 +530,7 @@ test_expect_failure () {
        if ! test_skip "$@"
        then
                say >&3 "checking known breakage: $2"
-               test_run_ "$2" expecting_failure
-               if [ "$?" = 0 -a "$eval_ret" = 0 ]
+               if test_run_ "$2" expecting_failure
                then
                        test_known_broken_ok_ "$1"
                else
@@ -521,8 +548,7 @@ test_expect_success () {
        if ! test_skip "$@"
        then
                say >&3 "expecting success: $2"
-               test_run_ "$2"
-               if [ "$?" = 0 -a "$eval_ret" = 0 ]
+               if test_run_ "$2"
                then
                        test_ok_ "$1"
                else
@@ -924,6 +950,8 @@ then
        do
                make_valgrind_symlink $file
        done
+       # special-case the mergetools loadables
+       make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools"
        OLDIFS=$IFS
        IFS=:
        for path in $PATH
diff --git a/t/test4012.png b/t/test4012.png
deleted file mode 100644 (file)
index 7b181d1..0000000
Binary files a/t/test4012.png and /dev/null differ
diff --git a/t/test9200a.png b/t/test9200a.png
deleted file mode 100644 (file)
index 7b181d1..0000000
Binary files a/t/test9200a.png and /dev/null differ
diff --git a/t/test9200b.png b/t/test9200b.png
deleted file mode 100644 (file)
index ac22ccb..0000000
Binary files a/t/test9200b.png and /dev/null differ
diff --git a/templates/hooks--post-commit.sample b/templates/hooks--post-commit.sample
deleted file mode 100755 (executable)
index 2266821..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-#
-# An example hook script that is called after a successful
-# commit is made.
-#
-# To enable this hook, rename this file to "post-commit".
-
-: Nothing
diff --git a/templates/hooks--post-receive.sample b/templates/hooks--post-receive.sample
deleted file mode 100755 (executable)
index 7a83e17..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-#
-# An example hook script for the "post-receive" event.
-#
-# The "post-receive" script is run after receive-pack has accepted a pack
-# and the repository has been updated.  It is passed arguments in through
-# stdin in the form
-#  <oldrev> <newrev> <refname>
-# For example:
-#  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
-#
-# see contrib/hooks/ for a sample, or uncomment the next line and
-# rename the file to "post-receive".
-
-#. /usr/share/doc/git-core/contrib/hooks/post-receive-email
index b187c4bb1f256e19c25f80dd64f3451ced77e123..18c48297652174ffae65b877dd131711a5746181 100755 (executable)
@@ -18,6 +18,9 @@ fi
 # If you want to allow non-ascii filenames set this variable to true.
 allownonascii=$(git config hooks.allownonascii)
 
+# Redirect output to stderr.
+exec 1>&2
+
 # Cross platform projects tend to avoid non-ascii filenames; prevent
 # them from being added to the repository. We exploit the fact that the
 # printable range starts at the space character and ends with tilde.
@@ -25,8 +28,8 @@ if [ "$allownonascii" != "true" ] &&
        # Note that the use of brackets around a tr range is ok here, (it's
        # even required, for portability to Solaris 10's /usr/bin/tr), since
        # the square bracket bytes happen to fall in the designated range.
-       test "$(git diff --cached --name-only --diff-filter=A -z $against |
-         LC_ALL=C tr -d '[ -~]\0')"
+       test $(git diff --cached --name-only --diff-filter=A -z $against |
+         LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
 then
        echo "Error: Attempt to add a non-ascii file name."
        echo
@@ -43,4 +46,5 @@ then
        exit 1
 fi
 
+# If there are whitespace errors, print the offending file names and fail.
 exec git diff-index --check --cached $against --
index e7671593df6bf014f3a9d8bd5173d1edcfd6545b..3bc20e91da561f4edd5c3eddb0988735759234e4 100644 (file)
@@ -20,12 +20,34 @@ int main(int argc, char **argv)
                return 0;
        }
 
+       if (argc >= 2 && !strcmp(argv[1], "absolute_path")) {
+               while (argc > 2) {
+                       puts(absolute_path(argv[2]));
+                       argc--;
+                       argv++;
+               }
+               return 0;
+       }
+
        if (argc == 4 && !strcmp(argv[1], "longest_ancestor_length")) {
                int len = longest_ancestor_length(argv[2], argv[3]);
                printf("%d\n", len);
                return 0;
        }
 
+       if (argc >= 4 && !strcmp(argv[1], "prefix_path")) {
+               char *prefix = argv[2];
+               int prefix_len = strlen(prefix);
+               int nongit_ok;
+               setup_git_directory_gently(&nongit_ok);
+               while (argc > 3) {
+                       puts(prefix_path(prefix, prefix_len, argv[3]));
+                       argc--;
+                       argv++;
+               }
+               return 0;
+       }
+
        if (argc == 4 && !strcmp(argv[1], "strip_path_suffix")) {
                char *prefix = strip_path_suffix(argv[2], argv[3]);
                printf("%s\n", prefix ? prefix : "(null)");
index 660147f9e96be7b69379a9040c4220c141c7be4c..07131261fefeab2066636a7f83bce05796329a54 100644 (file)
@@ -23,6 +23,8 @@ struct helper_data {
                push : 1,
                connect : 1,
                no_disconnect_req : 1;
+       char *export_marks;
+       char *import_marks;
        /* These go from remote name (as in "list") to private name */
        struct refspec *refspecs;
        int refspec_nr;
@@ -105,6 +107,12 @@ static struct child_process *get_helper(struct transport *transport)
        int refspec_alloc = 0;
        int duped;
        int code;
+       char git_dir_buf[sizeof(GIT_DIR_ENVIRONMENT) + PATH_MAX + 1];
+       const char *helper_env[] = {
+               git_dir_buf,
+               NULL
+       };
+
 
        if (data->helper)
                return data->helper;
@@ -120,6 +128,10 @@ static struct child_process *get_helper(struct transport *transport)
        helper->argv[2] = remove_ext_force(transport->url);
        helper->git_cmd = 0;
        helper->silent_exec_failure = 1;
+
+       snprintf(git_dir_buf, sizeof(git_dir_buf), "%s=%s", GIT_DIR_ENVIRONMENT, get_git_dir());
+       helper->env = helper_env;
+
        code = start_command(helper);
        if (code < 0 && errno == ENOENT)
                die("Unable to find remote helper for '%s'", data->name);
@@ -171,14 +183,19 @@ static struct child_process *get_helper(struct transport *transport)
                        ALLOC_GROW(refspecs,
                                   refspec_nr + 1,
                                   refspec_alloc);
-                       refspecs[refspec_nr++] = strdup(buf.buf + strlen("refspec "));
+                       refspecs[refspec_nr++] = xstrdup(capname + strlen("refspec "));
                } else if (!strcmp(capname, "connect")) {
                        data->connect = 1;
-               } else if (!strcmp(buf.buf, "gitdir")) {
-                       struct strbuf gitdir = STRBUF_INIT;
-                       strbuf_addf(&gitdir, "gitdir %s\n", get_git_dir());
-                       sendline(data, &gitdir);
-                       strbuf_release(&gitdir);
+               } else if (!prefixcmp(capname, "export-marks ")) {
+                       struct strbuf arg = STRBUF_INIT;
+                       strbuf_addstr(&arg, "--export-marks=");
+                       strbuf_addstr(&arg, capname + strlen("export-marks "));
+                       data->export_marks = strbuf_detach(&arg, NULL);
+               } else if (!prefixcmp(capname, "import-marks")) {
+                       struct strbuf arg = STRBUF_INIT;
+                       strbuf_addstr(&arg, "--import-marks=");
+                       strbuf_addstr(&arg, capname + strlen("import-marks "));
+                       data->import_marks = strbuf_detach(&arg, NULL);
                } else if (mandatory) {
                        die("Unknown mandatory capability %s. This remote "
                            "helper probably needs newer version of Git.\n",
@@ -204,6 +221,7 @@ static int disconnect_helper(struct transport *transport)
 {
        struct helper_data *data = transport->data;
        struct strbuf buf = STRBUF_INIT;
+       int res = 0;
 
        if (data->helper) {
                if (debug)
@@ -215,13 +233,13 @@ static int disconnect_helper(struct transport *transport)
                close(data->helper->in);
                close(data->helper->out);
                fclose(data->out);
-               finish_command(data->helper);
+               res = finish_command(data->helper);
                free((char *)data->helper->argv[0]);
                free(data->helper->argv);
                free(data->helper);
                data->helper = NULL;
        }
-       return 0;
+       return res;
 }
 
 static const char *unsupported_options[] = {
@@ -299,12 +317,13 @@ static void standard_options(struct transport *t)
 
 static int release_helper(struct transport *transport)
 {
+       int res = 0;
        struct helper_data *data = transport->data;
        free_refspec(data->refspec_nr, data->refspecs);
        data->refspecs = NULL;
-       disconnect_helper(transport);
+       res = disconnect_helper(transport);
        free(transport->data);
-       return 0;
+       return res;
 }
 
 static int fetch_with_fetch(struct transport *transport,
@@ -362,10 +381,9 @@ static int get_importer(struct transport *transport, struct child_process *fasti
 
 static int get_exporter(struct transport *transport,
                        struct child_process *fastexport,
-                       const char *export_marks,
-                       const char *import_marks,
                        struct string_list *revlist_args)
 {
+       struct helper_data *data = transport->data;
        struct child_process *helper = get_helper(transport);
        int argc = 0, i;
        memset(fastexport, 0, sizeof(*fastexport));
@@ -373,12 +391,13 @@ static int get_exporter(struct transport *transport,
        /* we need to duplicate helper->in because we want to use it after
         * fastexport is done with it. */
        fastexport->out = dup(helper->in);
-       fastexport->argv = xcalloc(4 + revlist_args->nr, sizeof(*fastexport->argv));
+       fastexport->argv = xcalloc(5 + revlist_args->nr, sizeof(*fastexport->argv));
        fastexport->argv[argc++] = "fast-export";
-       if (export_marks)
-               fastexport->argv[argc++] = export_marks;
-       if (import_marks)
-               fastexport->argv[argc++] = import_marks;
+       fastexport->argv[argc++] = "--use-done-feature";
+       if (data->export_marks)
+               fastexport->argv[argc++] = data->export_marks;
+       if (data->import_marks)
+               fastexport->argv[argc++] = data->import_marks;
 
        for (i = 0; i < revlist_args->nr; i++)
                fastexport->argv[argc++] = revlist_args->items[i].string;
@@ -410,8 +429,11 @@ static int fetch_with_import(struct transport *transport,
                sendline(data, &buf);
                strbuf_reset(&buf);
        }
-       disconnect_helper(transport);
-       finish_command(&fastimport);
+
+       write_constant(data->helper->in, "\n");
+
+       if (finish_command(&fastimport))
+               die("Error while running fast-import");
        free(fastimport.argv);
        fastimport.argv = NULL;
 
@@ -423,7 +445,7 @@ static int fetch_with_import(struct transport *transport,
                if (data->refspecs)
                        private = apply_refspecs(data->refspecs, data->refspec_nr, posn->name);
                else
-                       private = strdup(posn->name);
+                       private = xstrdup(posn->name);
                read_ref(private, posn->old_sha1);
                free(private);
        }
@@ -554,6 +576,88 @@ static int fetch(struct transport *transport,
        return -1;
 }
 
+static void push_update_ref_status(struct strbuf *buf,
+                                  struct ref **ref,
+                                  struct ref *remote_refs)
+{
+       char *refname, *msg;
+       int status;
+
+       if (!prefixcmp(buf->buf, "ok ")) {
+               status = REF_STATUS_OK;
+               refname = buf->buf + 3;
+       } else if (!prefixcmp(buf->buf, "error ")) {
+               status = REF_STATUS_REMOTE_REJECT;
+               refname = buf->buf + 6;
+       } else
+               die("expected ok/error, helper said '%s'\n", buf->buf);
+
+       msg = strchr(refname, ' ');
+       if (msg) {
+               struct strbuf msg_buf = STRBUF_INIT;
+               const char *end;
+
+               *msg++ = '\0';
+               if (!unquote_c_style(&msg_buf, msg, &end))
+                       msg = strbuf_detach(&msg_buf, NULL);
+               else
+                       msg = xstrdup(msg);
+               strbuf_release(&msg_buf);
+
+               if (!strcmp(msg, "no match")) {
+                       status = REF_STATUS_NONE;
+                       free(msg);
+                       msg = NULL;
+               }
+               else if (!strcmp(msg, "up to date")) {
+                       status = REF_STATUS_UPTODATE;
+                       free(msg);
+                       msg = NULL;
+               }
+               else if (!strcmp(msg, "non-fast forward")) {
+                       status = REF_STATUS_REJECT_NONFASTFORWARD;
+                       free(msg);
+                       msg = NULL;
+               }
+       }
+
+       if (*ref)
+               *ref = find_ref_by_name(*ref, refname);
+       if (!*ref)
+               *ref = find_ref_by_name(remote_refs, refname);
+       if (!*ref) {
+               warning("helper reported unexpected status of %s", refname);
+               return;
+       }
+
+       if ((*ref)->status != REF_STATUS_NONE) {
+               /*
+                * Earlier, the ref was marked not to be pushed, so ignore the ref
+                * status reported by the remote helper if the latter is 'no match'.
+                */
+               if (status == REF_STATUS_NONE)
+                       return;
+       }
+
+       (*ref)->status = status;
+       (*ref)->remote_status = msg;
+}
+
+static void push_update_refs_status(struct helper_data *data,
+                                   struct ref *remote_refs)
+{
+       struct strbuf buf = STRBUF_INIT;
+       struct ref *ref = remote_refs;
+       for (;;) {
+               recvline(data, &buf);
+               if (!buf.len)
+                       break;
+
+               push_update_ref_status(&buf, &ref, remote_refs);
+       }
+       strbuf_release(&buf);
+}
+
 static int push_refs_with_push(struct transport *transport,
                struct ref *remote_refs, int flags)
 {
@@ -608,76 +712,9 @@ static int push_refs_with_push(struct transport *transport,
 
        strbuf_addch(&buf, '\n');
        sendline(data, &buf);
-
-       ref = remote_refs;
-       while (1) {
-               char *refname, *msg;
-               int status;
-
-               recvline(data, &buf);
-               if (!buf.len)
-                       break;
-
-               if (!prefixcmp(buf.buf, "ok ")) {
-                       status = REF_STATUS_OK;
-                       refname = buf.buf + 3;
-               } else if (!prefixcmp(buf.buf, "error ")) {
-                       status = REF_STATUS_REMOTE_REJECT;
-                       refname = buf.buf + 6;
-               } else
-                       die("expected ok/error, helper said '%s'\n", buf.buf);
-
-               msg = strchr(refname, ' ');
-               if (msg) {
-                       struct strbuf msg_buf = STRBUF_INIT;
-                       const char *end;
-
-                       *msg++ = '\0';
-                       if (!unquote_c_style(&msg_buf, msg, &end))
-                               msg = strbuf_detach(&msg_buf, NULL);
-                       else
-                               msg = xstrdup(msg);
-                       strbuf_release(&msg_buf);
-
-                       if (!strcmp(msg, "no match")) {
-                               status = REF_STATUS_NONE;
-                               free(msg);
-                               msg = NULL;
-                       }
-                       else if (!strcmp(msg, "up to date")) {
-                               status = REF_STATUS_UPTODATE;
-                               free(msg);
-                               msg = NULL;
-                       }
-                       else if (!strcmp(msg, "non-fast forward")) {
-                               status = REF_STATUS_REJECT_NONFASTFORWARD;
-                               free(msg);
-                               msg = NULL;
-                       }
-               }
-
-               if (ref)
-                       ref = find_ref_by_name(ref, refname);
-               if (!ref)
-                       ref = find_ref_by_name(remote_refs, refname);
-               if (!ref) {
-                       warning("helper reported unexpected status of %s", refname);
-                       continue;
-               }
-
-               if (ref->status != REF_STATUS_NONE) {
-                       /*
-                        * Earlier, the ref was marked not to be pushed, so ignore the ref
-                        * status reported by the remote helper if the latter is 'no match'.
-                        */
-                       if (status == REF_STATUS_NONE)
-                               continue;
-               }
-
-               ref->status = status;
-               ref->remote_status = msg;
-       }
        strbuf_release(&buf);
+
+       push_update_refs_status(data, remote_refs);
        return 0;
 }
 
@@ -687,7 +724,6 @@ static int push_refs_with_export(struct transport *transport,
        struct ref *ref;
        struct child_process *helper, exporter;
        struct helper_data *data = transport->data;
-       char *export_marks = NULL, *import_marks = NULL;
        struct string_list revlist_args = STRING_LIST_INIT_NODUP;
        struct strbuf buf = STRBUF_INIT;
 
@@ -695,26 +731,6 @@ static int push_refs_with_export(struct transport *transport,
 
        write_constant(helper->in, "export\n");
 
-       recvline(data, &buf);
-       if (debug)
-               fprintf(stderr, "Debug: Got export_marks '%s'\n", buf.buf);
-       if (buf.len) {
-               struct strbuf arg = STRBUF_INIT;
-               strbuf_addstr(&arg, "--export-marks=");
-               strbuf_addbuf(&arg, &buf);
-               export_marks = strbuf_detach(&arg, NULL);
-       }
-
-       recvline(data, &buf);
-       if (debug)
-               fprintf(stderr, "Debug: Got import_marks '%s'\n", buf.buf);
-       if (buf.len) {
-               struct strbuf arg = STRBUF_INIT;
-               strbuf_addstr(&arg, "--import-marks=");
-               strbuf_addbuf(&arg, &buf);
-               import_marks = strbuf_detach(&arg, NULL);
-       }
-
        strbuf_reset(&buf);
 
        for (ref = remote_refs; ref; ref = ref->next) {
@@ -728,18 +744,23 @@ static int push_refs_with_export(struct transport *transport,
                        strbuf_addf(&buf, "^%s", private);
                        string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
                }
+               free(private);
+
+               if (ref->deletion) {
+                       die("remote-helpers do not support ref deletion");
+               }
 
-               string_list_append(&revlist_args, ref->name);
+               if (ref->peer_ref)
+                       string_list_append(&revlist_args, ref->peer_ref->name);
 
        }
 
-       if (get_exporter(transport, &exporter,
-                        export_marks, import_marks, &revlist_args))
+       if (get_exporter(transport, &exporter, &revlist_args))
                die("Couldn't run fast-export");
 
-       data->no_disconnect_req = 1;
-       finish_command(&exporter);
-       disconnect_helper(transport);
+       if (finish_command(&exporter))
+               die("Error while running fast-export");
+       push_update_refs_status(data, remote_refs);
        return 0;
 }
 
index c9c8056f9de69bd378cd271d70363b5560f13e07..e1940615e28ebc3b16f80b8f647f216031f64ee8 100644 (file)
@@ -10,6 +10,7 @@
 #include "refs.h"
 #include "branch.h"
 #include "url.h"
+#include "submodule.h"
 
 /* rsync support */
 
@@ -431,7 +432,8 @@ static int fetch_refs_from_bundle(struct transport *transport,
                               int nr_heads, struct ref **to_fetch)
 {
        struct bundle_transport_data *data = transport->data;
-       return unbundle(&data->header, data->fd);
+       return unbundle(&data->header, data->fd,
+                       transport->progress ? BUNDLE_VERBOSE : 0);
 }
 
 static int close_bundle(struct transport *transport)
@@ -1041,6 +1043,14 @@ int transport_push(struct transport *transport,
                        flags & TRANSPORT_PUSH_MIRROR,
                        flags & TRANSPORT_PUSH_FORCE);
 
+               if ((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) && !is_bare_repository()) {
+                       struct ref *ref = remote_refs;
+                       for (; ref; ref = ref->next)
+                               if (!is_null_sha1(ref->new_sha1) &&
+                                   check_submodule_needs_pushing(ref->new_sha1,transport->remote->name))
+                                       die("There are unpushed submodules, aborting.");
+               }
+
                push_ret = transport->push_refs(transport, remote_refs, flags);
                err = push_had_errors(remote_refs);
                ret = push_ret | err;
index 161d724bba5c132950b45866286c558148560d01..059b3303e20f8335cea388dfccfc2740d3c3d43e 100644 (file)
@@ -101,6 +101,7 @@ struct transport {
 #define TRANSPORT_PUSH_MIRROR 8
 #define TRANSPORT_PUSH_PORCELAIN 16
 #define TRANSPORT_PUSH_SET_UPSTREAM 32
+#define TRANSPORT_RECURSE_SUBMODULES_CHECK 64
 
 #define TRANSPORT_SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
 
index 33f749e1e77484694e7b8f40a65755a7818c4abb..808bb55ba3f21d113e6358f6874e2e20cb33bbea 100644 (file)
@@ -309,6 +309,18 @@ static void free_extended_entry(struct tree_desc_x *t)
        }
 }
 
+static inline int prune_traversal(struct name_entry *e,
+                                 struct traverse_info *info,
+                                 struct strbuf *base,
+                                 int still_interesting)
+{
+       if (!info->pathspec || still_interesting == 2)
+               return 2;
+       if (still_interesting < 0)
+               return still_interesting;
+       return tree_entry_interesting(e, base, 0, info->pathspec);
+}
+
 int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
 {
        int ret = 0;
@@ -316,10 +328,18 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
        struct name_entry *entry = xmalloc(n*sizeof(*entry));
        int i;
        struct tree_desc_x *tx = xcalloc(n, sizeof(*tx));
+       struct strbuf base = STRBUF_INIT;
+       int interesting = 1;
 
        for (i = 0; i < n; i++)
                tx[i].d = t[i];
 
+       if (info->prev) {
+               strbuf_grow(&base, info->pathlen);
+               make_traverse_path(base.buf, info->prev, &info->name);
+               base.buf[info->pathlen-1] = '/';
+               strbuf_setlen(&base, info->pathlen);
+       }
        for (;;) {
                unsigned long mask, dirmask;
                const char *first = NULL;
@@ -376,16 +396,22 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
                        mask |= 1ul << i;
                        if (S_ISDIR(entry[i].mode))
                                dirmask |= 1ul << i;
+                       e = &entry[i];
                }
                if (!mask)
                        break;
-               ret = info->fn(n, mask, dirmask, entry, info);
-               if (ret < 0) {
-                       error = ret;
-                       if (!info->show_all_errors)
-                               break;
+               interesting = prune_traversal(e, info, &base, interesting);
+               if (interesting < 0)
+                       break;
+               if (interesting) {
+                       ret = info->fn(n, mask, dirmask, entry, info);
+                       if (ret < 0) {
+                               error = ret;
+                               if (!info->show_all_errors)
+                                       break;
+                       }
+                       mask &= ret;
                }
-               mask &= ret;
                ret = 0;
                for (i = 0; i < n; i++)
                        if (mask & (1ul << i))
@@ -395,6 +421,7 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
        for (i = 0; i < n; i++)
                free_extended_entry(tx + i);
        free(tx);
+       strbuf_release(&base);
        return error;
 }
 
index 39524b7dba6a1d0b63c4cd2b42db59a27a030b21..0089581e1dd55800302799a7381d4a7ad01bd79d 100644 (file)
@@ -44,6 +44,7 @@ struct traverse_info {
        struct traverse_info *prev;
        struct name_entry name;
        int pathlen;
+       struct pathspec *pathspec;
 
        unsigned long conflicts;
        traverse_callback_t fn;
index cc616c3f991a655d10fcac15055fcdfafa8620fd..237aed8c766638c55d8d6b870c86ef2ad13a74d3 100644 (file)
@@ -159,7 +159,7 @@ static void display_error_msgs(struct unpack_trees_options *o)
                string_list_clear(rejects, 0);
        }
        if (something_displayed)
-               printf("Aborting\n");
+               fprintf(stderr, "Aborting\n");
 }
 
 /*
@@ -444,6 +444,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
 
        newinfo = *info;
        newinfo.prev = info;
+       newinfo.pathspec = info->pathspec;
        newinfo.name = *p;
        newinfo.pathlen += tree_entry_len(p->path, p->sha1) + 1;
        newinfo.conflicts |= df_conflicts;
@@ -1040,6 +1041,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
                info.fn = unpack_callback;
                info.data = o;
                info.show_all_errors = o->show_all_errors;
+               info.pathspec = o->pathspec;
 
                if (o->prefix) {
                        /*
index 79989483079970e9dad42512e522eef8ea2a75a4..5e432f576eb2304a63510a61a71182e11f777092 100644 (file)
@@ -52,6 +52,7 @@ struct unpack_trees_options {
        const char *prefix;
        int cache_bottom;
        struct dir_struct *dir;
+       struct pathspec *pathspec;
        merge_fn_t fn;
        const char *msgs[NB_UNPACK_TREES_ERROR_TYPES];
        /*
index ce5cbbea6be45a6dfa79bcc8c8244ae0b99c7ca3..8739bfacdfd4e01e16a614dd419388fa93a904b6 100644 (file)
@@ -10,6 +10,7 @@
 #include "revision.h"
 #include "list-objects.h"
 #include "run-command.h"
+#include "sigchain.h"
 
 static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>";
 
@@ -498,11 +499,97 @@ static int get_common_commits(void)
        }
 }
 
+static void check_non_tip(void)
+{
+       static const char *argv[] = {
+               "rev-list", "--stdin", NULL,
+       };
+       static struct child_process cmd;
+       struct object *o;
+       char namebuf[42]; /* ^ + SHA-1 + LF */
+       int i;
+
+       /* In the normal in-process case non-tip request can never happen */
+       if (!stateless_rpc)
+               goto error;
+
+       cmd.argv = argv;
+       cmd.git_cmd = 1;
+       cmd.no_stderr = 1;
+       cmd.in = -1;
+       cmd.out = -1;
+
+       if (start_command(&cmd))
+               goto error;
+
+       /*
+        * If rev-list --stdin encounters an unknown commit, it
+        * terminates, which will cause SIGPIPE in the write loop
+        * below.
+        */
+       sigchain_push(SIGPIPE, SIG_IGN);
+
+       namebuf[0] = '^';
+       namebuf[41] = '\n';
+       for (i = get_max_object_index(); 0 < i; ) {
+               o = get_indexed_object(--i);
+               if (!o)
+                       continue;
+               if (!(o->flags & OUR_REF))
+                       continue;
+               memcpy(namebuf + 1, sha1_to_hex(o->sha1), 40);
+               if (write_in_full(cmd.in, namebuf, 42) < 0)
+                       goto error;
+       }
+       namebuf[40] = '\n';
+       for (i = 0; i < want_obj.nr; i++) {
+               o = want_obj.objects[i].item;
+               if (o->flags & OUR_REF)
+                       continue;
+               memcpy(namebuf, sha1_to_hex(o->sha1), 40);
+               if (write_in_full(cmd.in, namebuf, 41) < 0)
+                       goto error;
+       }
+       close(cmd.in);
+
+       sigchain_pop(SIGPIPE);
+
+       /*
+        * The commits out of the rev-list are not ancestors of
+        * our ref.
+        */
+       i = read_in_full(cmd.out, namebuf, 1);
+       if (i)
+               goto error;
+       close(cmd.out);
+
+       /*
+        * rev-list may have died by encountering a bad commit
+        * in the history, in which case we do want to bail out
+        * even when it showed no commit.
+        */
+       if (finish_command(&cmd))
+               goto error;
+
+       /* All the non-tip ones are ancestors of what we advertised */
+       return;
+
+error:
+       /* Pick one of them (we know there at least is one) */
+       for (i = 0; i < want_obj.nr; i++) {
+               o = want_obj.objects[i].item;
+               if (!(o->flags & OUR_REF))
+                       die("git upload-pack: not our ref %s",
+                           sha1_to_hex(o->sha1));
+       }
+}
+
 static void receive_needs(void)
 {
        struct object_array shallows = OBJECT_ARRAY_INIT;
        static char line[1000];
        int len, depth = 0;
+       int has_non_tip = 0;
 
        shallow_nr = 0;
        if (debug_fd)
@@ -559,26 +646,30 @@ static void receive_needs(void)
                if (strstr(line+45, "include-tag"))
                        use_include_tag = 1;
 
-               /* We have sent all our refs already, and the other end
-                * should have chosen out of them; otherwise they are
-                * asking for nonsense.
-                *
-                * Hmph.  We may later want to allow "want" line that
-                * asks for something like "master~10" (symbolic)...
-                * would it make sense?  I don't know.
-                */
                o = lookup_object(sha1_buf);
-               if (!o || !(o->flags & OUR_REF))
+               if (!o)
                        die("git upload-pack: not our ref %s",
                            sha1_to_hex(sha1_buf));
                if (!(o->flags & WANTED)) {
                        o->flags |= WANTED;
+                       if (!(o->flags & OUR_REF))
+                               has_non_tip = 1;
                        add_object_array(o, NULL, &want_obj);
                }
        }
        if (debug_fd)
                write_str_in_full(debug_fd, "#E\n");
 
+       /*
+        * We have sent all our refs already, and the other end
+        * should have chosen out of them. When we are operating
+        * in the stateless RPC mode, however, their choice may
+        * have been based on the set of older refs advertised
+        * by another process that handled the initial request.
+        */
+       if (has_non_tip)
+               check_non_tip();
+
        if (!use_sideband && daemon_mode)
                no_progress = 1;
 
@@ -641,16 +732,17 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
                " side-band-64k ofs-delta shallow no-progress"
                " include-tag multi_ack_detailed";
        struct object *o = parse_object(sha1);
+       const char *refname_nons = strip_namespace(refname);
 
        if (!o)
                die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
 
        if (capabilities)
-               packet_write(1, "%s %s%c%s%s\n", sha1_to_hex(sha1), refname,
+               packet_write(1, "%s %s%c%s%s\n", sha1_to_hex(sha1), refname_nons,
                             0, capabilities,
                             stateless_rpc ? " no-done" : "");
        else
-               packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname);
+               packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname_nons);
        capabilities = NULL;
        if (!(o->flags & OUR_REF)) {
                o->flags |= OUR_REF;
@@ -659,7 +751,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
        if (o->type == OBJ_TAG) {
                o = deref_tag(o, refname, 0);
                if (o)
-                       packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
+                       packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname_nons);
        }
        return 0;
 }
@@ -680,12 +772,12 @@ static void upload_pack(void)
 {
        if (advertise_refs || !stateless_rpc) {
                reset_timeout();
-               head_ref(send_ref, NULL);
-               for_each_ref(send_ref, NULL);
+               head_ref_namespaced(send_ref, NULL);
+               for_each_namespaced_ref(send_ref, NULL);
                packet_flush(1);
        } else {
-               head_ref(mark_our_ref, NULL);
-               for_each_ref(mark_our_ref, NULL);
+               head_ref_namespaced(mark_our_ref, NULL);
+               for_each_namespaced_ref(mark_our_ref, NULL);
        }
        if (advertise_refs)
                return;
diff --git a/usage.c b/usage.c
index b5e67e3d0d4a46a69d72371f4c6a0002e40a0bf1..a2a667800474e315a362e1d0623c17dafaad1022 100644 (file)
--- a/usage.c
+++ b/usage.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "git-compat-util.h"
+#include "cache.h"
 
 void vreportf(const char *prefix, const char *err, va_list params)
 {
@@ -12,6 +13,18 @@ void vreportf(const char *prefix, const char *err, va_list params)
        fprintf(stderr, "%s%s\n", prefix, msg);
 }
 
+void vwritef(int fd, const char *prefix, const char *err, va_list params)
+{
+       char msg[4096];
+       int len = vsnprintf(msg, sizeof(msg), err, params);
+       if (len > sizeof(msg))
+               len = sizeof(msg);
+
+       write_in_full(fd, prefix, strlen(prefix));
+       write_in_full(fd, msg, len);
+       write_in_full(fd, "\n", 1);
+}
+
 static NORETURN void usage_builtin(const char *err, va_list params)
 {
        vreportf("usage: ", err, params);
@@ -46,6 +59,11 @@ void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list param
        die_routine = routine;
 }
 
+void set_error_routine(void (*routine)(const char *err, va_list params))
+{
+       error_routine = routine;
+}
+
 void NORETURN usagef(const char *err, ...)
 {
        va_list params;
index 01d3a8b81e628b0a088e3e9fc0ca59acf7d9c58d..bf553ad91b55de8a762d56a6ffc6c86e959e878c 100644 (file)
@@ -270,7 +270,7 @@ struct userdiff_driver *userdiff_find_by_path(const char *path)
 
        if (!path)
                return NULL;
-       if (git_checkattr(path, 1, &check))
+       if (git_check_attr(path, 1, &check))
                return NULL;
 
        if (ATTR_TRUE(check.value))
diff --git a/ws.c b/ws.c
index 9fb9b14760b100972a1adb5198bff9d6a9941808..b498d7599d5ac09c2688ee829b29aa36a866ac9c 100644 (file)
--- a/ws.c
+++ b/ws.c
@@ -88,7 +88,7 @@ unsigned whitespace_rule(const char *pathname)
        struct git_attr_check attr_whitespace_rule;
 
        setup_whitespace_attr_check(&attr_whitespace_rule);
-       if (!git_checkattr(pathname, 1, &attr_whitespace_rule)) {
+       if (!git_check_attr(pathname, 1, &attr_whitespace_rule)) {
                const char *value;
 
                value = attr_whitespace_rule.value;
index 02377729c401fa6e041a713a89fe986fa0f562a0..70fdb76ff2b5100c6d20f9f3b758e1ac8df314e1 100644 (file)
@@ -26,7 +26,9 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
 
 static const char *color(int slot, struct wt_status *s)
 {
-       const char *c = s->use_color > 0 ? s->color_palette[slot] : "";
+       const char *c = "";
+       if (want_color(s->use_color))
+               c = s->color_palette[slot];
        if (slot == WT_STATUS_ONBRANCH && color_is_nil(c))
                c = s->color_palette[WT_STATUS_HEADER];
        return c;
@@ -394,7 +396,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
        if (s->ignore_submodule_arg) {
                DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG);
                handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg);
-    }
+       }
        rev.diffopt.format_callback = wt_status_collect_changed_cb;
        rev.diffopt.format_callback_data = s;
        init_pathspec(&rev.prune_data, s->pathspec);
@@ -681,7 +683,7 @@ static void wt_status_print_verbose(struct wt_status *s)
         * will have checked isatty on stdout).
         */
        if (s->fp != stdout)
-               DIFF_OPT_CLR(&rev.diffopt, COLOR_DIFF);
+               rev.diffopt.use_color = 0;
        run_diff_index(&rev, 1);
 }
 
index 711048ea36dda1d814b395efa8bc69ab142425ca..4beb10c678702a34b14914f8b292dd65b5c273cd 100644 (file)
@@ -33,6 +33,7 @@ extern "C" {
 #define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3)
 #define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 4)
 #define XDF_PATIENCE_DIFF (1 << 5)
+#define XDF_HISTOGRAM_DIFF (1 << 6)
 #define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL)
 
 #define XDL_PATCH_NORMAL '-'
@@ -105,7 +106,6 @@ typedef struct s_bdiffparam {
 #define xdl_realloc(ptr,x) realloc(ptr,x)
 
 void *xdl_mmfile_first(mmfile_t *mmf, long *size);
-void *xdl_mmfile_next(mmfile_t *mmf, long *size);
 long xdl_mmfile_size(mmfile_t *mmf);
 
 int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
index da67c04357dfe4d3283c589f5d47be9c5f2b7fcf..75a39227501715504cdd12ccc1b4854568a54ad7 100644 (file)
@@ -331,6 +331,9 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
        if (xpp->flags & XDF_PATIENCE_DIFF)
                return xdl_do_patience_diff(mf1, mf2, xpp, xe);
 
+       if (xpp->flags & XDF_HISTOGRAM_DIFF)
+               return xdl_do_histogram_diff(mf1, mf2, xpp, xe);
+
        if (xdl_prepare_env(mf1, mf2, xpp, xe) < 0) {
 
                return -1;
index ad033a8e6a79600b6a3ba0cc16244ede0e9437ea..7a92ea9c4d84a559ae1d0bd90ebe667828d8f9cb 100644 (file)
@@ -57,5 +57,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
                  xdemitconf_t const *xecfg);
 int xdl_do_patience_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
                xdfenv_t *env);
+int xdl_do_histogram_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
+               xdfenv_t *env);
 
 #endif /* #if !defined(XDIFFI_H) */
diff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c
new file mode 100644 (file)
index 0000000..18f6f99
--- /dev/null
@@ -0,0 +1,363 @@
+/*
+ * Copyright (C) 2010, Google Inc.
+ * and other copyright owners as documented in JGit's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials provided
+ *   with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ *   names of its contributors may be used to endorse or promote
+ *   products derived from this software without specific prior
+ *   written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "xinclude.h"
+#include "xtypes.h"
+#include "xdiff.h"
+
+#define MAX_PTR        UINT_MAX
+#define MAX_CNT        UINT_MAX
+
+#define LINE_END(n) (line##n + count##n - 1)
+#define LINE_END_PTR(n) (*line##n + *count##n - 1)
+
+struct histindex {
+       struct record {
+               unsigned int ptr, cnt;
+               struct record *next;
+       } **records, /* an ocurrence */
+         **line_map; /* map of line to record chain */
+       chastore_t rcha;
+       unsigned int *next_ptrs;
+       unsigned int table_bits,
+                    records_size,
+                    line_map_size;
+
+       unsigned int max_chain_length,
+                    key_shift,
+                    ptr_shift;
+
+       unsigned int cnt,
+                    has_common;
+
+       xdfenv_t *env;
+       xpparam_t const *xpp;
+};
+
+struct region {
+       unsigned int begin1, end1;
+       unsigned int begin2, end2;
+};
+
+#define LINE_MAP(i, a) (i->line_map[(a) - i->ptr_shift])
+
+#define NEXT_PTR(index, ptr) \
+       (index->next_ptrs[(ptr) - index->ptr_shift])
+
+#define CNT(index, ptr) \
+       ((LINE_MAP(index, ptr))->cnt)
+
+#define REC(env, s, l) \
+       (env->xdf##s.recs[l - 1])
+
+static int cmp_recs(xpparam_t const *xpp,
+       xrecord_t *r1, xrecord_t *r2)
+{
+       return r1->ha == r2->ha &&
+               xdl_recmatch(r1->ptr, r1->size, r2->ptr, r2->size,
+                           xpp->flags);
+}
+
+#define CMP_ENV(xpp, env, s1, l1, s2, l2) \
+       (cmp_recs(xpp, REC(env, s1, l1), REC(env, s2, l2)))
+
+#define CMP(i, s1, l1, s2, l2) \
+       (cmp_recs(i->xpp, REC(i->env, s1, l1), REC(i->env, s2, l2)))
+
+#define TABLE_HASH(index, side, line) \
+       XDL_HASHLONG((REC(index->env, side, line))->ha, index->table_bits)
+
+static int scanA(struct histindex *index, int line1, int count1)
+{
+       unsigned int ptr, tbl_idx;
+       unsigned int chain_len;
+       struct record **rec_chain, *rec;
+
+       for (ptr = LINE_END(1); line1 <= ptr; ptr--) {
+               tbl_idx = TABLE_HASH(index, 1, ptr);
+               rec_chain = index->records + tbl_idx;
+               rec = *rec_chain;
+
+               chain_len = 0;
+               while (rec) {
+                       if (CMP(index, 1, rec->ptr, 1, ptr)) {
+                               /*
+                                * ptr is identical to another element. Insert
+                                * it onto the front of the existing element
+                                * chain.
+                                */
+                               NEXT_PTR(index, ptr) = rec->ptr;
+                               rec->ptr = ptr;
+                               /* cap rec->cnt at MAX_CNT */
+                               rec->cnt = XDL_MIN(MAX_CNT, rec->cnt + 1);
+                               LINE_MAP(index, ptr) = rec;
+                               goto continue_scan;
+                       }
+
+                       rec = rec->next;
+                       chain_len++;
+               }
+
+               if (chain_len == index->max_chain_length)
+                       return -1;
+
+               /*
+                * This is the first time we have ever seen this particular
+                * element in the sequence. Construct a new chain for it.
+                */
+               if (!(rec = xdl_cha_alloc(&index->rcha)))
+                       return -1;
+               rec->ptr = ptr;
+               rec->cnt = 1;
+               rec->next = *rec_chain;
+               *rec_chain = rec;
+               LINE_MAP(index, ptr) = rec;
+
+continue_scan:
+               ; /* no op */
+       }
+
+       return 0;
+}
+
+static int try_lcs(struct histindex *index, struct region *lcs, int b_ptr,
+       int line1, int count1, int line2, int count2)
+{
+       unsigned int b_next = b_ptr + 1;
+       struct record *rec = index->records[TABLE_HASH(index, 2, b_ptr)];
+       unsigned int as, ae, bs, be, np, rc;
+       int should_break;
+
+       for (; rec; rec = rec->next) {
+               if (rec->cnt > index->cnt) {
+                       if (!index->has_common)
+                               index->has_common = CMP(index, 1, rec->ptr, 2, b_ptr);
+                       continue;
+               }
+
+               as = rec->ptr;
+               if (!CMP(index, 1, as, 2, b_ptr))
+                       continue;
+
+               index->has_common = 1;
+               for (;;) {
+                       should_break = 0;
+                       np = NEXT_PTR(index, as);
+                       bs = b_ptr;
+                       ae = as;
+                       be = bs;
+                       rc = rec->cnt;
+
+                       while (line1 < as && line2 < bs
+                               && CMP(index, 1, as - 1, 2, bs - 1)) {
+                               as--;
+                               bs--;
+                               if (1 < rc)
+                                       rc = XDL_MIN(rc, CNT(index, as));
+                       }
+                       while (ae < LINE_END(1) && be < LINE_END(2)
+                               && CMP(index, 1, ae + 1, 2, be + 1)) {
+                               ae++;
+                               be++;
+                               if (1 < rc)
+                                       rc = XDL_MIN(rc, CNT(index, ae));
+                       }
+
+                       if (b_next <= be)
+                               b_next = be + 1;
+                       if (lcs->end1 - lcs->begin1 < ae - as || rc < index->cnt) {
+                               lcs->begin1 = as;
+                               lcs->begin2 = bs;
+                               lcs->end1 = ae;
+                               lcs->end2 = be;
+                               index->cnt = rc;
+                       }
+
+                       if (np == 0)
+                               break;
+
+                       while (np <= ae) {
+                               np = NEXT_PTR(index, np);
+                               if (np == 0) {
+                                       should_break = 1;
+                                       break;
+                               }
+                       }
+
+                       if (should_break)
+                               break;
+
+                       as = np;
+               }
+       }
+       return b_next;
+}
+
+static int find_lcs(struct histindex *index, struct region *lcs,
+       int line1, int count1, int line2, int count2) {
+       int b_ptr;
+
+       if (scanA(index, line1, count1))
+               return -1;
+
+       index->cnt = index->max_chain_length + 1;
+
+       for (b_ptr = line2; b_ptr <= LINE_END(2); )
+               b_ptr = try_lcs(index, lcs, b_ptr, line1, count1, line2, count2);
+
+       return index->has_common && index->max_chain_length < index->cnt;
+}
+
+static int fall_back_to_classic_diff(struct histindex *index,
+               int line1, int count1, int line2, int count2)
+{
+       xpparam_t xpp;
+       xpp.flags = index->xpp->flags & ~XDF_HISTOGRAM_DIFF;
+
+       return xdl_fall_back_diff(index->env, &xpp,
+                                 line1, count1, line2, count2);
+}
+
+static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
+       int line1, int count1, int line2, int count2)
+{
+       struct histindex index;
+       struct region lcs;
+       int sz;
+       int result = -1;
+
+       if (count1 <= 0 && count2 <= 0)
+               return 0;
+
+       if (LINE_END(1) >= MAX_PTR)
+               return -1;
+
+       if (!count1) {
+               while(count2--)
+                       env->xdf2.rchg[line2++ - 1] = 1;
+               return 0;
+       } else if (!count2) {
+               while(count1--)
+                       env->xdf1.rchg[line1++ - 1] = 1;
+               return 0;
+       }
+
+       memset(&index, 0, sizeof(index));
+
+       index.env = env;
+       index.xpp = xpp;
+
+       index.records = NULL;
+       index.line_map = NULL;
+       /* in case of early xdl_cha_free() */
+       index.rcha.head = NULL;
+
+       index.table_bits = xdl_hashbits(count1);
+       sz = index.records_size = 1 << index.table_bits;
+       sz *= sizeof(struct record *);
+       if (!(index.records = (struct record **) xdl_malloc(sz)))
+               goto cleanup;
+       memset(index.records, 0, sz);
+
+       sz = index.line_map_size = count1;
+       sz *= sizeof(struct record *);
+       if (!(index.line_map = (struct record **) xdl_malloc(sz)))
+               goto cleanup;
+       memset(index.line_map, 0, sz);
+
+       sz = index.line_map_size;
+       sz *= sizeof(unsigned int);
+       if (!(index.next_ptrs = (unsigned int *) xdl_malloc(sz)))
+               goto cleanup;
+       memset(index.next_ptrs, 0, sz);
+
+       /* lines / 4 + 1 comes from xprepare.c:xdl_prepare_ctx() */
+       if (xdl_cha_init(&index.rcha, sizeof(struct record), count1 / 4 + 1) < 0)
+               goto cleanup;
+
+       index.ptr_shift = line1;
+       index.max_chain_length = 64;
+
+       memset(&lcs, 0, sizeof(lcs));
+       if (find_lcs(&index, &lcs, line1, count1, line2, count2))
+               result = fall_back_to_classic_diff(&index, line1, count1, line2, count2);
+       else {
+               if (lcs.begin1 == 0 && lcs.begin2 == 0) {
+                       while (count1--)
+                               env->xdf1.rchg[line1++ - 1] = 1;
+                       while (count2--)
+                               env->xdf2.rchg[line2++ - 1] = 1;
+                       result = 0;
+               } else {
+                       result = histogram_diff(xpp, env,
+                                               line1, lcs.begin1 - line1,
+                                               line2, lcs.begin2 - line2);
+                       if (result)
+                               goto cleanup;
+                       result = histogram_diff(xpp, env,
+                                               lcs.end1 + 1, LINE_END(1) - lcs.end1,
+                                               lcs.end2 + 1, LINE_END(2) - lcs.end2);
+                       if (result)
+                               goto cleanup;
+               }
+       }
+
+cleanup:
+       xdl_free(index.records);
+       xdl_free(index.line_map);
+       xdl_free(index.next_ptrs);
+       xdl_cha_free(&index.rcha);
+
+       return result;
+}
+
+int xdl_do_histogram_diff(mmfile_t *file1, mmfile_t *file2,
+       xpparam_t const *xpp, xdfenv_t *env)
+{
+       if (xdl_prepare_env(file1, file2, xpp, env) < 0)
+               return -1;
+
+       return histogram_diff(xpp, env,
+               env->xdf1.dstart + 1, env->xdf1.dend - env->xdf1.dstart + 1,
+               env->xdf2.dstart + 1, env->xdf2.dend - env->xdf2.dstart + 1);
+}
index e42c16a807609b967c6a807a99d4ecbe2e1e0af8..fdd7d0263f576a8dc1a8e791ef50f8dbe25c7ee5 100644 (file)
@@ -287,34 +287,11 @@ static int walk_common_sequence(struct hashmap *map, struct entry *first,
 static int fall_back_to_classic_diff(struct hashmap *map,
                int line1, int count1, int line2, int count2)
 {
-       /*
-        * This probably does not work outside Git, since
-        * we have a very simple mmfile structure.
-        *
-        * Note: ideally, we would reuse the prepared environment, but
-        * the libxdiff interface does not (yet) allow for diffing only
-        * ranges of lines instead of the whole files.
-        */
-       mmfile_t subfile1, subfile2;
        xpparam_t xpp;
-       xdfenv_t env;
-
-       subfile1.ptr = (char *)map->env->xdf1.recs[line1 - 1]->ptr;
-       subfile1.size = map->env->xdf1.recs[line1 + count1 - 2]->ptr +
-               map->env->xdf1.recs[line1 + count1 - 2]->size - subfile1.ptr;
-       subfile2.ptr = (char *)map->env->xdf2.recs[line2 - 1]->ptr;
-       subfile2.size = map->env->xdf2.recs[line2 + count2 - 2]->ptr +
-               map->env->xdf2.recs[line2 + count2 - 2]->size - subfile2.ptr;
        xpp.flags = map->xpp->flags & ~XDF_PATIENCE_DIFF;
-       if (xdl_do_diff(&subfile1, &subfile2, &xpp, &env) < 0)
-               return -1;
 
-       memcpy(map->env->xdf1.rchg + line1 - 1, env.xdf1.rchg, count1);
-       memcpy(map->env->xdf2.rchg + line2 - 1, env.xdf2.rchg, count2);
-
-       xdl_free_env(&env);
-
-       return 0;
+       return xdl_fall_back_diff(map->env, &xpp,
+                                 line1, count1, line2, count2);
 }
 
 /*
index 16890852350cb62bb9f9aec5e52eea8ba46f1192..e419f4f726019a5b0365c589285439fb3bfb8db2 100644 (file)
@@ -26,6 +26,8 @@
 #define XDL_KPDIS_RUN 4
 #define XDL_MAX_EQLIMIT 1024
 #define XDL_SIMSCAN_WINDOW 100
+#define XDL_GUESS_NLINES1 256
+#define XDL_GUESS_NLINES2 20
 
 
 typedef struct s_xdlclass {
@@ -34,6 +36,7 @@ typedef struct s_xdlclass {
        char const *line;
        long size;
        long idx;
+       long len1, len2;
 } xdlclass_t;
 
 typedef struct s_xdlclassifier {
@@ -41,6 +44,8 @@ typedef struct s_xdlclassifier {
        long hsize;
        xdlclass_t **rchash;
        chastore_t ncha;
+       xdlclass_t **rcrecs;
+       long alloc;
        long count;
        long flags;
 } xdlclassifier_t;
@@ -50,22 +55,20 @@ typedef struct s_xdlclassifier {
 
 static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags);
 static void xdl_free_classifier(xdlclassifier_t *cf);
-static int xdl_classify_record(xdlclassifier_t *cf, xrecord_t **rhash, unsigned int hbits,
-                              xrecord_t *rec);
-static int xdl_prepare_ctx(mmfile_t *mf, long narec, xpparam_t const *xpp,
+static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t **rhash,
+                              unsigned int hbits, xrecord_t *rec);
+static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_t const *xpp,
                           xdlclassifier_t *cf, xdfile_t *xdf);
 static void xdl_free_ctx(xdfile_t *xdf);
 static int xdl_clean_mmatch(char const *dis, long i, long s, long e);
-static int xdl_cleanup_records(xdfile_t *xdf1, xdfile_t *xdf2);
+static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2);
 static int xdl_trim_ends(xdfile_t *xdf1, xdfile_t *xdf2);
-static int xdl_optimize_ctxs(xdfile_t *xdf1, xdfile_t *xdf2);
+static int xdl_optimize_ctxs(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2);
 
 
 
 
 static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {
-       long i;
-
        cf->flags = flags;
 
        cf->hbits = xdl_hashbits((unsigned int) size);
@@ -80,8 +83,15 @@ static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {
                xdl_cha_free(&cf->ncha);
                return -1;
        }
-       for (i = 0; i < cf->hsize; i++)
-               cf->rchash[i] = NULL;
+       memset(cf->rchash, 0, cf->hsize * sizeof(xdlclass_t *));
+
+       cf->alloc = size;
+       if (!(cf->rcrecs = (xdlclass_t **) xdl_malloc(cf->alloc * sizeof(xdlclass_t *)))) {
+
+               xdl_free(cf->rchash);
+               xdl_cha_free(&cf->ncha);
+               return -1;
+       }
 
        cf->count = 0;
 
@@ -91,16 +101,18 @@ static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {
 
 static void xdl_free_classifier(xdlclassifier_t *cf) {
 
+       xdl_free(cf->rcrecs);
        xdl_free(cf->rchash);
        xdl_cha_free(&cf->ncha);
 }
 
 
-static int xdl_classify_record(xdlclassifier_t *cf, xrecord_t **rhash, unsigned int hbits,
-                              xrecord_t *rec) {
+static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t **rhash,
+                              unsigned int hbits, xrecord_t *rec) {
        long hi;
        char const *line;
        xdlclass_t *rcrec;
+       xdlclass_t **rcrecs;
 
        line = rec->ptr;
        hi = (long) XDL_HASHLONG(rec->ha, cf->hbits);
@@ -116,13 +128,25 @@ static int xdl_classify_record(xdlclassifier_t *cf, xrecord_t **rhash, unsigned
                        return -1;
                }
                rcrec->idx = cf->count++;
+               if (cf->count > cf->alloc) {
+                       cf->alloc *= 2;
+                       if (!(rcrecs = (xdlclass_t **) xdl_realloc(cf->rcrecs, cf->alloc * sizeof(xdlclass_t *)))) {
+
+                               return -1;
+                       }
+                       cf->rcrecs = rcrecs;
+               }
+               cf->rcrecs[rcrec->idx] = rcrec;
                rcrec->line = line;
                rcrec->size = rec->size;
                rcrec->ha = rec->ha;
+               rcrec->len1 = rcrec->len2 = 0;
                rcrec->next = cf->rchash[hi];
                cf->rchash[hi] = rcrec;
        }
 
+       (pass == 1) ? rcrec->len1++ : rcrec->len2++;
+
        rec->ha = (unsigned long) rcrec->idx;
 
        hi = (long) XDL_HASHLONG(rec->ha, hbits);
@@ -133,10 +157,10 @@ static int xdl_classify_record(xdlclassifier_t *cf, xrecord_t **rhash, unsigned
 }
 
 
-static int xdl_prepare_ctx(mmfile_t *mf, long narec, xpparam_t const *xpp,
+static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_t const *xpp,
                           xdlclassifier_t *cf, xdfile_t *xdf) {
        unsigned int hbits;
-       long i, nrec, hsize, bsize;
+       long nrec, hsize, bsize;
        unsigned long hav;
        char const *blk, *cur, *top, *prev;
        xrecord_t *crec;
@@ -146,96 +170,59 @@ static int xdl_prepare_ctx(mmfile_t *mf, long narec, xpparam_t const *xpp,
        char *rchg;
        long *rindex;
 
-       if (xdl_cha_init(&xdf->rcha, sizeof(xrecord_t), narec / 4 + 1) < 0) {
-
-               return -1;
-       }
-       if (!(recs = (xrecord_t **) xdl_malloc(narec * sizeof(xrecord_t *)))) {
-
-               xdl_cha_free(&xdf->rcha);
-               return -1;
-       }
-
-       hbits = xdl_hashbits((unsigned int) narec);
-       hsize = 1 << hbits;
-       if (!(rhash = (xrecord_t **) xdl_malloc(hsize * sizeof(xrecord_t *)))) {
-
-               xdl_free(recs);
-               xdl_cha_free(&xdf->rcha);
-               return -1;
+       ha = NULL;
+       rindex = NULL;
+       rchg = NULL;
+       rhash = NULL;
+       recs = NULL;
+
+       if (xdl_cha_init(&xdf->rcha, sizeof(xrecord_t), narec / 4 + 1) < 0)
+               goto abort;
+       if (!(recs = (xrecord_t **) xdl_malloc(narec * sizeof(xrecord_t *))))
+               goto abort;
+
+       if (xpp->flags & XDF_HISTOGRAM_DIFF)
+               hbits = hsize = 0;
+       else {
+               hbits = xdl_hashbits((unsigned int) narec);
+               hsize = 1 << hbits;
+               if (!(rhash = (xrecord_t **) xdl_malloc(hsize * sizeof(xrecord_t *))))
+                       goto abort;
+               memset(rhash, 0, hsize * sizeof(xrecord_t *));
        }
-       for (i = 0; i < hsize; i++)
-               rhash[i] = NULL;
 
        nrec = 0;
        if ((cur = blk = xdl_mmfile_first(mf, &bsize)) != NULL) {
-               for (top = blk + bsize;;) {
-                       if (cur >= top) {
-                               if (!(cur = blk = xdl_mmfile_next(mf, &bsize)))
-                                       break;
-                               top = blk + bsize;
-                       }
+               for (top = blk + bsize; cur < top; ) {
                        prev = cur;
                        hav = xdl_hash_record(&cur, top, xpp->flags);
                        if (nrec >= narec) {
                                narec *= 2;
-                               if (!(rrecs = (xrecord_t **) xdl_realloc(recs, narec * sizeof(xrecord_t *)))) {
-
-                                       xdl_free(rhash);
-                                       xdl_free(recs);
-                                       xdl_cha_free(&xdf->rcha);
-                                       return -1;
-                               }
+                               if (!(rrecs = (xrecord_t **) xdl_realloc(recs, narec * sizeof(xrecord_t *))))
+                                       goto abort;
                                recs = rrecs;
                        }
-                       if (!(crec = xdl_cha_alloc(&xdf->rcha))) {
-
-                               xdl_free(rhash);
-                               xdl_free(recs);
-                               xdl_cha_free(&xdf->rcha);
-                               return -1;
-                       }
+                       if (!(crec = xdl_cha_alloc(&xdf->rcha)))
+                               goto abort;
                        crec->ptr = prev;
                        crec->size = (long) (cur - prev);
                        crec->ha = hav;
                        recs[nrec++] = crec;
 
-                       if (xdl_classify_record(cf, rhash, hbits, crec) < 0) {
-
-                               xdl_free(rhash);
-                               xdl_free(recs);
-                               xdl_cha_free(&xdf->rcha);
-                               return -1;
-                       }
+                       if (!(xpp->flags & XDF_HISTOGRAM_DIFF) &&
+                               xdl_classify_record(pass, cf, rhash, hbits, crec) < 0)
+                               goto abort;
                }
        }
 
-       if (!(rchg = (char *) xdl_malloc((nrec + 2) * sizeof(char)))) {
-
-               xdl_free(rhash);
-               xdl_free(recs);
-               xdl_cha_free(&xdf->rcha);
-               return -1;
-       }
+       if (!(rchg = (char *) xdl_malloc((nrec + 2) * sizeof(char))))
+               goto abort;
        memset(rchg, 0, (nrec + 2) * sizeof(char));
 
-       if (!(rindex = (long *) xdl_malloc((nrec + 1) * sizeof(long)))) {
-
-               xdl_free(rchg);
-               xdl_free(rhash);
-               xdl_free(recs);
-               xdl_cha_free(&xdf->rcha);
-               return -1;
-       }
-       if (!(ha = (unsigned long *) xdl_malloc((nrec + 1) * sizeof(unsigned long)))) {
-
-               xdl_free(rindex);
-               xdl_free(rchg);
-               xdl_free(rhash);
-               xdl_free(recs);
-               xdl_cha_free(&xdf->rcha);
-               return -1;
-       }
+       if (!(rindex = (long *) xdl_malloc((nrec + 1) * sizeof(long))))
+               goto abort;
+       if (!(ha = (unsigned long *) xdl_malloc((nrec + 1) * sizeof(unsigned long))))
+               goto abort;
 
        xdf->nrec = nrec;
        xdf->recs = recs;
@@ -249,6 +236,15 @@ static int xdl_prepare_ctx(mmfile_t *mf, long narec, xpparam_t const *xpp,
        xdf->dend = nrec - 1;
 
        return 0;
+
+abort:
+       xdl_free(ha);
+       xdl_free(rindex);
+       xdl_free(rchg);
+       xdl_free(rhash);
+       xdl_free(recs);
+       xdl_cha_free(&xdf->rcha);
+       return -1;
 }
 
 
@@ -265,39 +261,53 @@ static void xdl_free_ctx(xdfile_t *xdf) {
 
 int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
                    xdfenv_t *xe) {
-       long enl1, enl2;
+       long enl1, enl2, sample;
        xdlclassifier_t cf;
 
-       enl1 = xdl_guess_lines(mf1) + 1;
-       enl2 = xdl_guess_lines(mf2) + 1;
+       memset(&cf, 0, sizeof(cf));
+
+       /*
+        * For histogram diff, we can afford a smaller sample size and
+        * thus a poorer estimate of the number of lines, as the hash
+        * table (rhash) won't be filled up/grown. The number of lines
+        * (nrecs) will be updated correctly anyway by
+        * xdl_prepare_ctx().
+        */
+       sample = xpp->flags & XDF_HISTOGRAM_DIFF ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1;
+
+       enl1 = xdl_guess_lines(mf1, sample) + 1;
+       enl2 = xdl_guess_lines(mf2, sample) + 1;
 
-       if (xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) {
+       if (!(xpp->flags & XDF_HISTOGRAM_DIFF) &&
+               xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) {
 
                return -1;
        }
 
-       if (xdl_prepare_ctx(mf1, enl1, xpp, &cf, &xe->xdf1) < 0) {
+       if (xdl_prepare_ctx(1, mf1, enl1, xpp, &cf, &xe->xdf1) < 0) {
 
                xdl_free_classifier(&cf);
                return -1;
        }
-       if (xdl_prepare_ctx(mf2, enl2, xpp, &cf, &xe->xdf2) < 0) {
+       if (xdl_prepare_ctx(2, mf2, enl2, xpp, &cf, &xe->xdf2) < 0) {
 
                xdl_free_ctx(&xe->xdf1);
                xdl_free_classifier(&cf);
                return -1;
        }
 
-       xdl_free_classifier(&cf);
-
        if (!(xpp->flags & XDF_PATIENCE_DIFF) &&
-                       xdl_optimize_ctxs(&xe->xdf1, &xe->xdf2) < 0) {
+                       !(xpp->flags & XDF_HISTOGRAM_DIFF) &&
+                       xdl_optimize_ctxs(&cf, &xe->xdf1, &xe->xdf2) < 0) {
 
                xdl_free_ctx(&xe->xdf2);
                xdl_free_ctx(&xe->xdf1);
                return -1;
        }
 
+       if (!(xpp->flags & XDF_HISTOGRAM_DIFF))
+               xdl_free_classifier(&cf);
+
        return 0;
 }
 
@@ -372,11 +382,10 @@ static int xdl_clean_mmatch(char const *dis, long i, long s, long e) {
  * matches on the other file. Also, lines that have multiple matches
  * might be potentially discarded if they happear in a run of discardable.
  */
-static int xdl_cleanup_records(xdfile_t *xdf1, xdfile_t *xdf2) {
-       long i, nm, rhi, nreff, mlim;
-       unsigned long hav;
+static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2) {
+       long i, nm, nreff, mlim;
        xrecord_t **recs;
-       xrecord_t *rec;
+       xdlclass_t *rcrec;
        char *dis, *dis1, *dis2;
 
        if (!(dis = (char *) xdl_malloc(xdf1->nrec + xdf2->nrec + 2))) {
@@ -390,22 +399,16 @@ static int xdl_cleanup_records(xdfile_t *xdf1, xdfile_t *xdf2) {
        if ((mlim = xdl_bogosqrt(xdf1->nrec)) > XDL_MAX_EQLIMIT)
                mlim = XDL_MAX_EQLIMIT;
        for (i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart]; i <= xdf1->dend; i++, recs++) {
-               hav = (*recs)->ha;
-               rhi = (long) XDL_HASHLONG(hav, xdf2->hbits);
-               for (nm = 0, rec = xdf2->rhash[rhi]; rec; rec = rec->next)
-                       if (rec->ha == hav && ++nm == mlim)
-                               break;
+               rcrec = cf->rcrecs[(*recs)->ha];
+               nm = rcrec ? rcrec->len2 : 0;
                dis1[i] = (nm == 0) ? 0: (nm >= mlim) ? 2: 1;
        }
 
        if ((mlim = xdl_bogosqrt(xdf2->nrec)) > XDL_MAX_EQLIMIT)
                mlim = XDL_MAX_EQLIMIT;
        for (i = xdf2->dstart, recs = &xdf2->recs[xdf2->dstart]; i <= xdf2->dend; i++, recs++) {
-               hav = (*recs)->ha;
-               rhi = (long) XDL_HASHLONG(hav, xdf1->hbits);
-               for (nm = 0, rec = xdf1->rhash[rhi]; rec; rec = rec->next)
-                       if (rec->ha == hav && ++nm == mlim)
-                               break;
+               rcrec = cf->rcrecs[(*recs)->ha];
+               nm = rcrec ? rcrec->len1 : 0;
                dis2[i] = (nm == 0) ? 0: (nm >= mlim) ? 2: 1;
        }
 
@@ -468,10 +471,10 @@ static int xdl_trim_ends(xdfile_t *xdf1, xdfile_t *xdf2) {
 }
 
 
-static int xdl_optimize_ctxs(xdfile_t *xdf1, xdfile_t *xdf2) {
+static int xdl_optimize_ctxs(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2) {
 
        if (xdl_trim_ends(xdf1, xdf2) < 0 ||
-           xdl_cleanup_records(xdf1, xdf2) < 0) {
+           xdl_cleanup_records(cf, xdf1, xdf2) < 0) {
 
                return -1;
        }
index ab6503460f760356a393a3c7b3b8438213e1ee94..0de084e53f5144153373cc66cae7b523b4ae2812 100644 (file)
 
 
 
-#define XDL_GUESS_NLINES 256
-
-
-
 
 long xdl_bogosqrt(long n) {
        long i;
@@ -71,12 +67,6 @@ void *xdl_mmfile_first(mmfile_t *mmf, long *size)
 }
 
 
-void *xdl_mmfile_next(mmfile_t *mmf, long *size)
-{
-       return NULL;
-}
-
-
 long xdl_mmfile_size(mmfile_t *mmf)
 {
        return mmf->size;
@@ -159,18 +149,12 @@ void *xdl_cha_next(chastore_t *cha) {
 }
 
 
-long xdl_guess_lines(mmfile_t *mf) {
+long xdl_guess_lines(mmfile_t *mf, long sample) {
        long nl = 0, size, tsize = 0;
        char const *data, *cur, *top;
 
        if ((cur = data = xdl_mmfile_first(mf, &size)) != NULL) {
-               for (top = data + size; nl < XDL_GUESS_NLINES;) {
-                       if (cur >= top) {
-                               tsize += (long) (cur - data);
-                               if (!(cur = data = xdl_mmfile_next(mf, &size)))
-                                       break;
-                               top = data + size;
-                       }
+               for (top = data + size; nl < sample && cur < top; ) {
                        nl++;
                        if (!(cur = memchr(cur, '\n', top - cur)))
                                cur = top;
@@ -402,3 +386,34 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
 
        return 0;
 }
+
+int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,
+               int line1, int count1, int line2, int count2)
+{
+       /*
+        * This probably does not work outside Git, since
+        * we have a very simple mmfile structure.
+        *
+        * Note: ideally, we would reuse the prepared environment, but
+        * the libxdiff interface does not (yet) allow for diffing only
+        * ranges of lines instead of the whole files.
+        */
+       mmfile_t subfile1, subfile2;
+       xdfenv_t env;
+
+       subfile1.ptr = (char *)diff_env->xdf1.recs[line1 - 1]->ptr;
+       subfile1.size = diff_env->xdf1.recs[line1 + count1 - 2]->ptr +
+               diff_env->xdf1.recs[line1 + count1 - 2]->size - subfile1.ptr;
+       subfile2.ptr = (char *)diff_env->xdf2.recs[line2 - 1]->ptr;
+       subfile2.size = diff_env->xdf2.recs[line2 + count2 - 2]->ptr +
+               diff_env->xdf2.recs[line2 + count2 - 2]->size - subfile2.ptr;
+       if (xdl_do_diff(&subfile1, &subfile2, xpp, &env) < 0)
+               return -1;
+
+       memcpy(diff_env->xdf1.rchg + line1 - 1, env.xdf1.rchg, count1);
+       memcpy(diff_env->xdf2.rchg + line2 - 1, env.xdf2.rchg, count2);
+
+       xdl_free_env(&env);
+
+       return 0;
+}
index d5de8292e05e7c36c4b68857c1cf9855e3d2f70a..714719a89cba9170820bf7d54b9c569d42861aa4 100644 (file)
@@ -33,7 +33,7 @@ void xdl_cha_free(chastore_t *cha);
 void *xdl_cha_alloc(chastore_t *cha);
 void *xdl_cha_first(chastore_t *cha);
 void *xdl_cha_next(chastore_t *cha);
-long xdl_guess_lines(mmfile_t *mf);
+long xdl_guess_lines(mmfile_t *mf, long sample);
 int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags);
 unsigned long xdl_hash_record(char const **data, char const *top, long flags);
 unsigned int xdl_hashbits(unsigned int size);
@@ -41,6 +41,8 @@ int xdl_num_out(char *out, long val);
 long xdl_atol(char const *str, char const **next);
 int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
                      const char *func, long funclen, xdemitcb_t *ecb);
+int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,
+                      int line1, int count1, int line2, int count2);