]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Git 1.7.2.5 v1.7.2.5
authorJunio C Hamano <gitster@pobox.com>
Wed, 15 Dec 2010 19:45:36 +0000 (11:45 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Dec 2010 19:45:36 +0000 (11:45 -0800)
Signed-off-by: Junio C Hamano <gitster@pobox.com>
406 files changed:
.gitignore
Documentation/Makefile
Documentation/RelNotes-1.5.6.3.txt
Documentation/RelNotes-1.6.0.2.txt
Documentation/RelNotes-1.6.4.3.txt
Documentation/RelNotes-1.6.5.4.txt
Documentation/RelNotes-1.6.5.7.txt
Documentation/RelNotes-1.6.6.txt
Documentation/RelNotes-1.7.0.txt
Documentation/RelNotes-1.7.2.1.txt [new file with mode: 0644]
Documentation/RelNotes-1.7.2.2.txt [new file with mode: 0644]
Documentation/RelNotes-1.7.2.3.txt [new file with mode: 0644]
Documentation/RelNotes-1.7.2.txt [new file with mode: 0644]
Documentation/RelNotes/1.7.2.4.txt [new file with mode: 0644]
Documentation/RelNotes/1.7.2.5.txt [new file with mode: 0644]
Documentation/config.txt
Documentation/diff-options.txt
Documentation/fetch-options.txt
Documentation/git-add.txt
Documentation/git-apply.txt
Documentation/git-bisect-lk2009.txt
Documentation/git-cat-file.txt
Documentation/git-check-ref-format.txt
Documentation/git-checkout.txt
Documentation/git-cherry-pick.txt
Documentation/git-commit.txt
Documentation/git-cvsimport.txt
Documentation/git-cvsserver.txt
Documentation/git-diff.txt
Documentation/git-fast-import.txt
Documentation/git-for-each-ref.txt
Documentation/git-format-patch.txt
Documentation/git-gc.txt
Documentation/git-grep.txt
Documentation/git-hash-object.txt
Documentation/git-instaweb.txt
Documentation/git-log.txt
Documentation/git-ls-files.txt
Documentation/git-notes.txt
Documentation/git-prune.txt
Documentation/git-pull.txt
Documentation/git-push.txt
Documentation/git-read-tree.txt
Documentation/git-reflog.txt
Documentation/git-remote.txt
Documentation/git-reset.txt
Documentation/git-rev-parse.txt
Documentation/git-revert.txt
Documentation/git-show-branch.txt
Documentation/git-show-ref.txt
Documentation/git-show.txt
Documentation/git-status.txt
Documentation/git-submodule.txt
Documentation/git-svn.txt
Documentation/git.txt
Documentation/gitattributes.txt
Documentation/gitcore-tutorial.txt
Documentation/gitk.txt
Documentation/gitrepository-layout.txt
Documentation/gitrevisions.txt [new file with mode: 0644]
Documentation/howto/revert-a-faulty-merge.txt
Documentation/install-webdoc.sh
Documentation/pretty-formats.txt
Documentation/pretty-options.txt
Documentation/rev-list-options.txt
Documentation/revisions.txt [new file with mode: 0644]
Documentation/technical/api-run-command.txt
Documentation/technical/api-string-list.txt
Documentation/urls.txt
Documentation/user-manual.txt
GIT-VERSION-GEN
INSTALL
Makefile
RelNotes
aclocal.m4 [new file with mode: 0644]
archive.c
attr.c
attr.h
base85.c
block-sha1/sha1.c
builtin.h
builtin/add.c
builtin/apply.c
builtin/blame.c
builtin/branch.c
builtin/cat-file.c
builtin/check-ref-format.c
builtin/checkout.c
builtin/clone.c
builtin/commit-tree.c
builtin/commit.c
builtin/config.c
builtin/diff.c
builtin/fast-export.c
builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/for-each-ref.c
builtin/grep.c
builtin/help.c
builtin/index-pack.c
builtin/log.c
builtin/ls-files.c
builtin/ls-remote.c
builtin/mailinfo.c
builtin/mailsplit.c
builtin/merge-recursive.c
builtin/merge-tree.c
builtin/merge.c
builtin/mv.c
builtin/notes.c
builtin/pack-objects.c
builtin/patch-id.c
builtin/prune.c
builtin/push.c
builtin/read-tree.c
builtin/receive-pack.c
builtin/reflog.c
builtin/remote.c
builtin/rerere.c
builtin/rev-list.c
builtin/rev-parse.c
builtin/revert.c
builtin/shortlog.c
builtin/show-ref.c
cache-tree.c
cache.h
color.c
color.h
commit.c
commit.h
compat/mingw.c
compat/mingw.h
compat/nedmalloc/malloc.c.h
compat/regex/regex.c
compat/win32/pthread.c
compat/win32/pthread.h
config.c
config.mak.in
configure.ac
connect.c
contrib/completion/git-completion.bash
contrib/examples/git-commit.sh
contrib/examples/git-fetch.sh
contrib/git-resurrect.sh
contrib/hooks/post-receive-email
contrib/svn-fe/.gitignore [new file with mode: 0644]
contrib/svn-fe/Makefile [new file with mode: 0644]
contrib/svn-fe/svn-fe.c [new file with mode: 0644]
contrib/svn-fe/svn-fe.txt [new file with mode: 0644]
contrib/workdir/git-new-workdir
convert.c
ctype.c
daemon.c
date.c
diff-delta.c
diff-lib.c
diff-no-index.c
diff.c
diff.h
diffcore-break.c
diffcore-pickaxe.c
diffcore-rename.c
diffcore.h
dir.c
dir.h
environment.c
fast-import.c
fsck.c
git-am.sh
git-compat-util.h
git-cvsserver.perl
git-gui/git-gui.sh
git-gui/lib/blame.tcl
git-gui/lib/choose_repository.tcl
git-gui/lib/diff.tcl
git-gui/lib/option.tcl
git-gui/lib/shortcut.tcl
git-gui/lib/status_bar.tcl
git-gui/lib/win32.tcl
git-gui/windows/git-gui.sh
git-instaweb.sh
git-merge-one-file.sh
git-pull.sh
git-rebase--interactive.sh
git-rebase.sh
git-remote-testgit.py [new file with mode: 0644]
git-request-pull.sh
git-stash.sh
git-submodule.sh
git-svn.perl
git-web--browse.sh
git.c
git.spec.in
git_remote_helpers/git/exporter.py [new file with mode: 0644]
git_remote_helpers/git/importer.py [new file with mode: 0644]
git_remote_helpers/git/non_local.py [new file with mode: 0644]
git_remote_helpers/git/repo.py [new file with mode: 0644]
gitweb/INSTALL
gitweb/Makefile
gitweb/README
gitweb/gitweb.perl
gitweb/static/git-favicon.png [moved from gitweb/git-favicon.png with 100% similarity]
gitweb/static/git-logo.png [moved from gitweb/git-logo.png with 100% similarity]
gitweb/static/gitweb.css [moved from gitweb/gitweb.css with 93% similarity]
gitweb/static/gitweb.js [moved from gitweb/gitweb.js with 100% similarity]
graph.c
grep.c
grep.h
http-backend.c
http-push.c
http-walker.c
http.h
imap-send.c
ll-merge.c
log-tree.c
log-tree.h
mailmap.c
merge-recursive.c
merge-recursive.h
notes-cache.c [new file with mode: 0644]
notes-cache.h [new file with mode: 0644]
notes.c
notes.h
object.c
pack-check.c
pack-refs.c
parse-options.c
parse-options.h
pretty.c
read-cache.c
reflog-walk.c
refs.c
refs.h
remote-curl.c
remote.c
remote.h
rerere.c
resolve-undo.c
revision.c
revision.h
run-command.c
run-command.h
setup.c
sha1_file.c
sha1_name.c
string-list.c
string-list.h
submodule.c
submodule.h
t/Makefile
t/README
t/aggregate-results.sh
t/gitweb-lib.sh
t/lib-cvs.sh
t/lib-git-svn.sh
t/lib-httpd.sh
t/lib-pager.sh [new file with mode: 0644]
t/lib-patch-mode.sh
t/lib-t6000.sh
t/t0000-basic.sh
t/t0006-date.sh
t/t0020-crlf.sh
t/t0021-conversion.sh
t/t0025-crlf-auto.sh [new file with mode: 0755]
t/t0026-eol-config.sh [new file with mode: 0755]
t/t0040-parse-options.sh
t/t1001-read-tree-m-2way.sh
t/t1020-subdirectory.sh
t/t1300-repo-config.sh
t/t1304-default-acl.sh
t/t1402-check-ref-format.sh
t/t1450-fsck.sh
t/t1502-rev-parse-parseopt.sh
t/t1509-root-worktree.sh
t/t2007-checkout-symlink.sh
t/t2017-checkout-orphan.sh [new file with mode: 0755]
t/t2102-update-index-symlinks.sh
t/t3000-ls-files-others.sh
t/t3030-merge-recursive.sh
t/t3101-ls-tree-dirname.sh
t/t3200-branch.sh
t/t3210-pack-refs.sh
t/t3300-funny-names.sh
t/t3301-notes.sh
t/t3302-notes-index-expensive.sh
t/t3306-notes-prune.sh
t/t3400-rebase.sh
t/t3404-rebase-interactive.sh
t/t3418-rebase-continue.sh [new file with mode: 0755]
t/t3500-cherry.sh
t/t3501-revert-cherry-pick.sh
t/t3508-cherry-pick-many-commits.sh [new file with mode: 0755]
t/t3600-rm.sh
t/t3700-add.sh
t/t3701-add-interactive.sh
t/t3902-quoted.sh
t/t3903-stash.sh
t/t4002-diff-basic.sh
t/t4004-diff-rename-symlink.sh
t/t4011-diff-symlink.sh
t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^
t/t4014-format-patch.sh
t/t4015-diff-whitespace.sh
t/t4016-diff-quote.sh
t/t4023-diff-rename-typechange.sh
t/t4027-diff-submodule.sh
t/t4034-diff-words.sh
t/t4041-diff-submodule-option.sh [moved from t/t4041-diff-submodule.sh with 74% similarity]
t/t4042-diff-textconv-caching.sh [new file with mode: 0755]
t/t4044-diff-index-unique-abbrev.sh [new file with mode: 0755]
t/t4045-diff-relative.sh [new file with mode: 0755]
t/t4114-apply-typechange.sh
t/t4115-apply-symlink.sh
t/t4122-apply-symlink-inside.sh
t/t4124-apply-ws-rule.sh
t/t4127-apply-same-fn.sh
t/t4150-am.sh
t/t4151-am-abort.sh
t/t4200-rerere.sh
t/t4202-log.sh
t/t4204-patch-id.sh
t/t4205-log-pretty-formats.sh [new file with mode: 0755]
t/t4206-log-follow-harder-copies.sh [new file with mode: 0755]
t/t4207-log-decoration-colors.sh [new file with mode: 0755]
t/t4300-merge-tree.sh [new file with mode: 0755]
t/t5001-archive-attr.sh
t/t5150-request-pull.sh [new file with mode: 0755]
t/t5300-pack-object.sh
t/t5302-pack-index.sh
t/t5503-tagfollow.sh
t/t5505-remote.sh
t/t5510-fetch.sh
t/t5512-ls-remote.sh
t/t5516-fetch-push.sh
t/t5520-pull.sh
t/t5522-pull-symlink.sh
t/t5525-fetch-tagopt.sh [new file with mode: 0755]
t/t5530-upload-pack-error.sh
t/t5540-http-push.sh
t/t5541-http-push.sh
t/t5550-http-fetch.sh
t/t5551-http-fetch.sh
t/t5561-http-backend.sh
t/t5601-clone.sh
t/t5700-clone-reference.sh
t/t5705-clone-2gb.sh
t/t5800-remote-helpers.sh [new file with mode: 0755]
t/t6001-rev-list-graft.sh
t/t6006-rev-list-format.sh
t/t6007-rev-list-cherry-pick-file.sh
t/t6018-rev-list-glob.sh
t/t6019-rev-list-ancestry-path.sh [new file with mode: 0755]
t/t6022-merge-rename.sh
t/t6035-merge-dir-to-symlink.sh
t/t6050-replace.sh
t/t6300-for-each-ref.sh
t/t7003-filter-branch.sh
t/t7004-tag.sh
t/t7005-editor.sh
t/t7006-pager.sh
t/t7008-grep-binary.sh [new file with mode: 0755]
t/t7400-submodule-basic.sh
t/t7403-submodule-sync.sh
t/t7407-submodule-foreach.sh
t/t7500-commit.sh
t/t7508-status.sh
t/t7600-merge.sh
t/t7700-repack.sh
t/t7701-repack-unpack-unreachable.sh
t/t7800-difftool.sh
t/t7810-grep.sh [moved from t/t7002-grep.sh with 98% similarity]
t/t7811-grep-open.sh [new file with mode: 0755]
t/t8006-blame-textconv.sh [new file with mode: 0755]
t/t8007-cat-file-textconv.sh [new file with mode: 0755]
t/t9001-send-email.sh
t/t9100-git-svn-basic.sh
t/t9118-git-svn-funky-branch-names.sh
t/t9119-git-svn-info.sh
t/t9129-git-svn-i18n-commitencoding.sh
t/t9143-git-svn-gc.sh
t/t9200-git-cvsexportcommit.sh
t/t9300-fast-import.sh
t/t9400-git-cvsserver-server.sh
t/t9401-git-cvsserver-crlf.sh
t/t9500-gitweb-standalone-no-errors.sh
t/t9600-cvsimport.sh
t/t9700-perl-git.sh
t/t9700/test.pl
t/test-lib.sh
tag.c
trace.c
transport-helper.c
transport.c
tree-diff.c
tree-walk.h
unpack-trees.c
url.c [new file with mode: 0644]
url.h [new file with mode: 0644]
usage.c
userdiff.c
userdiff.h
wrapper.c
ws.c
wt-status.c
wt-status.h
xdiff-interface.c

index dbf1b90c63573b08efc894ed8c1e02de58fd53e4..fcdd822d8a3c97621fb712a1e14b7f62cbdd6d3b 100644 (file)
 /git-remote-https
 /git-remote-ftp
 /git-remote-ftps
+/git-remote-testgit
 /git-repack
 /git-replace
 /git-repo-config
 /gitk-git/gitk-wish
 /gitweb/GITWEB-BUILD-OPTIONS
 /gitweb/gitweb.cgi
-/gitweb/gitweb.min.*
+/gitweb/static/gitweb.min.*
 /test-chmtime
 /test-ctype
 /test-date
index 04f69cf64e5d989bac3cd1c235e6a7e657c6c103..a4c4063e50d3eb3bd36d94b399f790e56fe4b050 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 gitworkflows.txt
+       gitdiffcore.txt gitrevisions.txt gitworkflows.txt
 
 MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT)
 MAN_XML=$(patsubst %.txt,%.xml,$(MAN_TXT))
index 942611299d59abd4bdd820e1258662067a304d62..f61dd3504afb9dc3fb7bb2d522e3adb573ef132f 100644 (file)
@@ -4,7 +4,7 @@ GIT v1.5.6.3 Release Notes
 Fixes since v1.5.6.2
 --------------------
 
-* Setting core.sharerepository to traditional "true" value was supposed to make
+* Setting core.sharedrepository to traditional "true" value was supposed to make
   the repository group writable but should not affect permission for others.
   However, since 1.5.6, it was broken to drop permission for others when umask is
   022, making the repository unreadable by others.
index 51b32f5d94c050f6cb5eae0b94cedda187e00312..e1e24b3295d4079c1bf784d11a8d6ec1691ec819 100644 (file)
@@ -17,7 +17,7 @@ Fixes since v1.6.0.1
 * Many commands did not use the correct working tree location when used
   with GIT_WORK_TREE environment settings.
 
-* Some systems needs to use compatibility fnmach and regex libraries
+* Some systems need to use compatibility fnmatch and regex libraries
   independent from each other; the compat/ area has been reorganized to
   allow this.
 
index 4f29babdeb03f9eddf73b7a6cb2a2e9b069baa4f..5643e6537de55ca961245cd1d7d01f46d9e9b855 100644 (file)
@@ -11,7 +11,7 @@ Fixes since v1.6.4.2
   been deprecated.
 
 * "git fetch" and "git clone" had an extra sanity check to verify the
-  presense of the corresponding *.pack file before downloading *.idx
+  presence of the corresponding *.pack file before downloading *.idx
   file by issuing a HEAD request.  Github server however sometimes
   gave 500 (Internal server error) response to HEAD even if a GET
   request for *.pack file to the same URL would have succeeded, and broke
index e42f8b239706465c7d1daf64ae052a31fa8ffcc8..d3a2a3e71243dc4612050d28a8cc779f34ab51ae 100644 (file)
@@ -26,7 +26,7 @@ Fixes since v1.6.5.3
    future versions, but not in this release,
 
  * "git merge -m <message> <branch>..." added the standard merge message
-   on its own after user-supplied message, which should have overrided the
+   on its own after user-supplied message, which should have overridden the
    standard one.
 
 Other minor documentation updates are included.
index 5b49ea53beb5592f97ccc68840d1b97616b18f23..dc5302c21cd2108a175235bc22efb0debac29670 100644 (file)
@@ -10,7 +10,7 @@ Fixes since v1.6.5.6
   an older version of git should just ignore them.  Instead we diagnosed
   it as an error.
 
-* With help.autocorrect set to non-zero value, the logic to guess typoes
+* With help.autocorrect set to non-zero value, the logic to guess typos
   in the subcommand name misfired and ran a random nonsense command.
 
 * If a command is run with an absolute path as a pathspec inside a bare
index 04e205c457cd11cba91327ad1e8b2c023743ac74..c50b59c4957a5def22fa6b2fc55cc85f3d46d0bc 100644 (file)
@@ -29,7 +29,7 @@ or adjust to the new behaviour, on the day their sysadmin decides to install
 the new version of git.  When we switched from "git-foo" to "git foo" in
 1.6.0, even though the change had been advertised and the transition
 guide had been provided for a very long time, the users procrastinated
-during the entire transtion period, and ended up panicking on the day
+during the entire transition period, and ended up panicking on the day
 their sysadmins updated their git installation.  We are trying to avoid
 repeating that unpleasantness in the 1.7.0 release.
 
@@ -94,7 +94,7 @@ users will fare this time.
  * "git diff" traditionally treated various "ignore whitespace" options
    only as a way to filter the patch output.  "git diff --exit-code -b"
    exited with non-zero status even if all changes were about changing the
-   ammount of whitespace and nothing else.  and "git diff -b" showed the
+   amount of whitespace and nothing else.  and "git diff -b" showed the
    "diff --git" header line for such a change without patch text.
 
    In 1.7.0, the "ignore whitespaces" will affect the semantics of the
index 43e3f336150e1869bdae01823471d7ab216584a8..0bb8c0b2a2a771ac95b5e5c1fc9b44eac5f2fe5d 100644 (file)
@@ -202,7 +202,7 @@ release, unless otherwise noted.
    the branch is fully merged to its upstream branch if it is not merged
    to the current branch.  It now deletes it in such a case.
 
- * "fiter-branch" command incorrectly said --prune-empty and --filter-commit
+ * "filter-branch" command incorrectly said --prune-empty and --filter-commit
    were incompatible; the latter should be read as --commit-filter.
 
  * When using "git status" or asking "git diff" to compare the work tree
diff --git a/Documentation/RelNotes-1.7.2.1.txt b/Documentation/RelNotes-1.7.2.1.txt
new file mode 100644 (file)
index 0000000..1103c47
--- /dev/null
@@ -0,0 +1,25 @@
+Git v1.7.2.1 Release Notes
+==========================
+
+Fixes since v1.7.2
+------------------
+
+ * "git instaweb" wasn't useful when your Apache was installed under a
+   name other than apache2 (e.g. "httpd").
+
+ * Similarly, "git web--browse" (invoked by "git help -w") learned that
+   chrome browser is sometimes called google-chrome.
+
+ * An overlong line after ".gitdir: " in a git file caused out of bounds
+   access to an array on the stack.
+
+ * "git config --path conf.var" to attempt to expand a variable conf.var
+   that uses "~/" short-hand segfaulted when $HOME environment variable
+   was not set.
+
+ * Documentation on Cygwin failed to build.
+
+ * The error message from "git pull blarg" when 'blarg' is an unknown
+   remote name has been improved.
+
+And other minor fixes and documentation updates.
diff --git a/Documentation/RelNotes-1.7.2.2.txt b/Documentation/RelNotes-1.7.2.2.txt
new file mode 100644 (file)
index 0000000..71eb6a8
--- /dev/null
@@ -0,0 +1,22 @@
+Git v1.7.2.2 Release Notes
+==========================
+
+Fixes since v1.7.2.1
+--------------------
+
+ * Object transfer over smart http transport deadlocked the client when
+   the remote HTTP server returned a failure, instead of erroring it out.
+
+ * git-gui honors custom textconv filters when showing diff and blame;
+
+ * git diff --relative=subdir (without the necessary trailing /) did not
+   work well;
+
+ * "git diff-files -p --submodule" was recently broken;
+
+ * "git checkout -b n ':/token'" did not work;
+
+ * "git index-pack" (hence "git fetch/clone/pull/push") enabled the object
+   replacement machinery by mistake (it never should have);
+
+And other minor fixes and documentation updates.
diff --git a/Documentation/RelNotes-1.7.2.3.txt b/Documentation/RelNotes-1.7.2.3.txt
new file mode 100644 (file)
index 0000000..610960c
--- /dev/null
@@ -0,0 +1,39 @@
+Git v1.7.2.3 Release Notes
+==========================
+
+Fixes since v1.7.2.2
+--------------------
+
+ * When people try insane things such as delta-compressing 4GiB files, we
+   threw an assertion failure.
+
+ * "git archive" gave the full commit ID for "$Format:%h$".
+
+ * "git fetch --tags" did not fetch tags when remote.<nick>.tagopt was set
+   to --no-tags.  The command line option now overrides the configuration
+   setting.
+
+ * "git for-each-ref --format='%(objectname:short)'" has been completely
+   broken for a long time.
+
+ * "git gc" incorrectly pruned a rerere record that was created long
+   time ago but still is actively and repeatedly used.
+
+ * "git log --follow -M -p" was seriously broken in 1.7.2, reporting
+   assertion failure.
+
+ * Running "git log" with an incorrect option started pager nevertheless,
+   forcing the user to dismiss it.
+
+ * "git rebase" did not work well when the user has diff.renames
+   configuration variable set.
+
+ * An earlier (and rather old) fix to "git rebase" against a rebased
+   upstream broke a more normal, non rebased upstream case rather badly,
+   attempting to re-apply patches that are already accepted upstream.
+
+ * "git submodule sync" forgot to update the superproject's config file
+   when submodule URL changed.
+
+ * "git pack-refs --all --prune" did not remove a directory that has
+   become empty.
diff --git a/Documentation/RelNotes-1.7.2.txt b/Documentation/RelNotes-1.7.2.txt
new file mode 100644 (file)
index 0000000..15cf011
--- /dev/null
@@ -0,0 +1,151 @@
+Git v1.7.2 Release Notes
+========================
+
+Updates since v1.7.1
+--------------------
+
+ * core.eol configuration and text/eol attributes are the new way to control
+   the end of line conventions for files in the working tree.
+
+ * core.autocrlf has been made safer - it will now only handle line
+   endings for new files and files that are LF-only in the
+   repository. To normalize content that has been checked in with
+   CRLF, use the new eol/text attributes.
+
+ * The whitespace rules used in "git apply --whitespace" and "git diff"
+   gained a new member in the family (tab-in-indent) to help projects with
+   policy to indent only with spaces.
+
+ * When working from a subdirectory, by default, git does not look for its
+   metadirectory ".git" across filesystems, primarily to help people who
+   have invocations of git in their custom PS1 prompts, as being outside
+   of a git repository would look for ".git" all the way up to the root
+   directory, and NFS mounts are often slow.  DISCOVERY_ACROSS_FILESYSTEM
+   environment variable can be used to tell git not to stop at a
+   filesystem boundary.
+
+ * Usage help messages generated by parse-options library (i.e. most
+   of the Porcelain commands) are sent to the standard output now.
+
+ * ':/<string>' notation to look for a commit now takes regular expression
+   and it is not anchored at the beginning of the commit log message
+   anymore (this is a backward incompatible change).
+
+ * "git" wrapper learned "-c name=value" option to override configuration
+   variable from the command line.
+
+ * Improved portability for various platforms including older SunOS,
+   HP-UX 10/11, AIX, Tru64, etc. and platforms with Python 2.4.
+
+ * The message from "git am -3" has been improved when conflict
+   resolution ended up making the patch a no-op.
+
+ * "git blame" applies the textconv filter to the contents it works
+   on, when available.
+
+ * "git checkout --orphan newbranch" is similar to "-b newbranch" but
+   prepares to create a root commit that is not connected to any existing
+   commit.
+
+ * "git cherry-pick" learned to pick a range of commits
+   (e.g. "cherry-pick A..B" and "cherry-pick --stdin"), so did "git
+   revert"; these do not support the nicer sequencing control "rebase
+   [-i]" has, though.
+
+ * "git cherry-pick" and "git revert" learned --strategy option to specify
+   the merge strategy to be used when performing three-way merges.
+
+ * "git cvsserver" can be told to use pserver; its password file can be
+   stored outside the repository.
+
+ * The output from the textconv filter used by "git diff" can be cached to
+   speed up their reuse.
+
+ * "git diff --word-diff=<mode>" extends the existing "--color-words"
+   option, making it more useful in color-challenged environments.
+
+ * The regexp to detect function headers used by "git diff" for PHP has
+   been enhanced for visibility modifiers (public, protected, etc.) to
+   better support PHP5.
+
+ * "diff.noprefix" configuration variable can be used to implicitly
+   ask for "diff --no-prefix" behaviour.
+
+ * "git for-each-ref" learned "%(objectname:short)" that gives the object
+   name abbreviated.
+
+ * "git format-patch" learned --signature option and format.signature
+   configuration variable to customize the e-mail signature used in the
+   output.
+
+ * Various options to "git grep" (e.g. --count, --name-only) work better
+   with binary files.
+
+ * "git grep" learned "-Ovi" to open the files with hits in your editor.
+
+ * "git help -w" learned "chrome" and "chromium" browsers.
+
+ * "git log --decorate" shows commit decorations in various colours.
+
+ * "git log --follow <path>" follows across copies (it used to only follow
+   renames).  This may make the processing more expensive.
+
+ * "git log --pretty=format:<template>" specifier learned "% <something>"
+   magic that inserts a space only when %<something> expands to a
+   non-empty string; this is similar to "%+<something>" magic, but is
+   useful in a context to generate a single line output.
+
+ * "git notes prune" learned "-n" (dry-run) and "-v" options, similar to
+   what "git prune" has.
+
+ * "git patch-id" can be fed a mbox without getting confused by the
+   signature line in the format-patch output.
+
+ * "git remote" learned "set-branches" subcommand.
+
+ * "git rev-list A..B" learned --ancestry-path option to further limit
+   the result to the commits that are on the ancestry chain between A and
+   B (i.e. commits that are not descendants of A are excluded).
+
+ * "git show -5" is equivalent to "git show --do-walk 5"; this is similar
+   to the update to make "git show master..next" walk the history,
+   introduced in 1.6.4.
+
+ * "git status [-s] --ignored" can be used to list ignored paths.
+
+ * "git status -s -b" shows the current branch in the output.
+
+ * "git status" learned "--ignore-submodules" option.
+
+ * Various "gitweb" enhancements and clean-ups, including syntax
+   highlighting, "plackup" support for instaweb, .fcgi suffix to run
+   it as FastCGI script, etc.
+
+ * The test harness has been updated to produce TAP-friendly output.
+
+ * Many documentation improvement patches are also included.
+
+
+Fixes since v1.7.1
+------------------
+
+All of the fixes in v1.7.1.X maintenance series are included in this
+release, unless otherwise noted.
+
+ * We didn't URL decode "file:///path/to/repo" correctly when path/to/repo
+   had percent-encoded characters (638794c, 9d2e942, ce83eda, 3c73a1d).
+
+ * "git clone" did not configure remote.origin.url correctly for bare
+   clones (df61c889).
+
+ * "git diff --graph" works better with "--color-words" and other options
+   (81fa024..4297c0a).
+
+ * "git diff" could show ambiguous abbreviation of blob object names on
+   its "index" line (3e5a188).
+
+ * "git reset --hard" started from a wrong directory and a working tree in
+   a nonstandard location is in use got confused (560fb6a1).
+
+ * "git read-tree -m A B" used to switch to branch B while retaining
+   local changes added an incorrect cache-tree information (b1f47514).
diff --git a/Documentation/RelNotes/1.7.2.4.txt b/Documentation/RelNotes/1.7.2.4.txt
new file mode 100644 (file)
index 0000000..f7950a4
--- /dev/null
@@ -0,0 +1,10 @@
+Git v1.7.2.4 Release Notes
+==========================
+
+This is primarily to backport support for the new "add.ignoreErrors"
+name given to the existing "add.ignore-errors" configuration variable.
+
+The next version, Git 1.7.4, and future versions, will support both
+old and incorrect name and the new corrected name, but without this
+backport, users who want to use the new name "add.ignoreErrors" in
+their repositories cannot use older versions of Git.
diff --git a/Documentation/RelNotes/1.7.2.5.txt b/Documentation/RelNotes/1.7.2.5.txt
new file mode 100644 (file)
index 0000000..bf976c4
--- /dev/null
@@ -0,0 +1,8 @@
+Git v1.7.2.5 Release Notes
+==========================
+
+Fixes since v1.7.2.4
+--------------------
+
+ * "gitweb" can sometimes be tricked into parrotting a filename argument
+   given in a request without properly quoting.
index 6a07fe60e726f95158f2a16a80a266bc5fbe2e7d..5506e31318517831c6f2143d7a8b01e46763da1a 100644 (file)
@@ -128,7 +128,7 @@ advice.*::
                when writing commit messages. Default: true.
        commitBeforeMerge::
                Advice shown when linkgit:git-merge[1] refuses to
-               merge to avoid overwritting local changes.
+               merge to avoid overwriting local changes.
                Default: true.
        resolveConflict::
                Advices shown by various commands when conflicts
@@ -196,20 +196,17 @@ core.quotepath::
        quoted without `-z` regardless of the setting of this
        variable.
 
-core.autocrlf::
-       If true, makes git convert `CRLF` at the end of lines in text files to
-       `LF` when reading from the work tree, and convert in reverse when
-       writing to the work tree.  The variable can be set to
-       'input', in which case the conversion happens only while
-       reading from the work tree but files are written out to the work
-       tree with `LF` at the end of lines.  A file is considered
-       "text" (i.e. be subjected to the autocrlf mechanism) based on
-       the file's `crlf` attribute, or if `crlf` is unspecified,
-       based on the file's contents.  See linkgit:gitattributes[5].
+core.eol::
+       Sets the line ending type to use in the working directory for
+       files that have the `text` property set.  Alternatives are
+       'lf', 'crlf' and 'native', which uses the platform's native
+       line ending.  The default value is `native`.  See
+       linkgit:gitattributes[5] for more information on end-of-line
+       conversion.
 
 core.safecrlf::
-       If true, makes git check if converting `CRLF` as controlled by
-       `core.autocrlf` is reversible.  Git will verify if a command
+       If true, makes git check if converting `CRLF` is reversible when
+       end-of-line conversion is active.  Git will verify if a command
        modifies a file in the work tree either directly or indirectly.
        For example, committing a file followed by checking out the
        same file should yield the original file in the work tree.  If
@@ -219,7 +216,7 @@ core.safecrlf::
        irreversible conversion but continue the operation.
 +
 CRLF conversion bears a slight chance of corrupting data.
-autocrlf=true will convert CRLF to LF during commit and LF to
+When it is enabled, git will convert CRLF to LF during commit and LF to
 CRLF during checkout.  A file that contains a mixture of LF and
 CRLF before the commit cannot be recreated by git.  For text
 files this is the right thing to do: it corrects line endings
@@ -243,15 +240,25 @@ converting CRLFs corrupts data.
 +
 Note, this safety check does not mean that a checkout will generate a
 file identical to the original file for a different setting of
-`core.autocrlf`, but only for the current one.  For example, a text
-file with `LF` would be accepted with `core.autocrlf=input` and could
-later be checked out with `core.autocrlf=true`, in which case the
+`core.eol` and `core.autocrlf`, but only for the current one.  For
+example, a text file with `LF` would be accepted with `core.eol=lf`
+and could later be checked out with `core.eol=crlf`, in which case the
 resulting file would contain `CRLF`, although the original file
 contained `LF`.  However, in both work trees the line endings would be
 consistent, that is either all `LF` or all `CRLF`, but never mixed.  A
 file with mixed line endings would be reported by the `core.safecrlf`
 mechanism.
 
+core.autocrlf::
+       Setting this variable to "true" is almost the same as setting
+       the `text` attribute to "auto" on all files except that text
+       files are not guaranteed to be normalized: files that contain
+       `CRLF` in the repository will not be touched.  Use this
+       setting if you want to have `CRLF` line endings in your
+       working directory even though the repository does not have
+       normalized line endings.  This variable can be set to 'input',
+       in which case no output conversion is performed.
+
 core.symlinks::
        If false, symbolic links are checked out as small plain files that
        contain the link text. linkgit:git-update-index[1] and
@@ -411,7 +418,7 @@ Common unit suffixes of 'k', 'm', or 'g' are supported.
 
 core.deltaBaseCacheLimit::
        Maximum number of bytes to reserve for caching base objects
-       that multiple deltafied objects reference.  By storing the
+       that may be referenced by multiple deltified objects.  By storing the
        entire decompressed base objects in a cache Git is able
        to avoid unpacking and decompressing frequently used base
        objects multiple times.
@@ -481,6 +488,8 @@ core.whitespace::
   error (enabled by default).
 * `indent-with-non-tab` treats a line that is indented with 8 or more
   space characters as an error (not enabled by default).
+* `tab-in-indent` treats a tab character in the initial indent part of
+  the line as an error (not enabled by default).
 * `blank-at-eof` treats blank lines added at the end of file as an error
   (enabled by default).
 * `trailing-space` is a short-hand to cover both `blank-at-eol` and
@@ -558,7 +567,7 @@ not necessarily be the current directory.
 am.keepcr::
        If true, git-am will call git-mailsplit for patches in mbox format
        with parameter '--keep-cr'. In this case git-mailsplit will
-       not remove `\r` from lines ending with `\r\n`. Can be overrriden
+       not remove `\r` from lines ending with `\r\n`. Can be overridden
        by giving '--no-keep-cr' from the command line.
        See linkgit:git-am[1], linkgit:git-mailsplit[1].
 
@@ -685,6 +694,11 @@ color.diff.<slot>::
        (highlighting whitespace errors). The values of these variables may be
        specified as in color.branch.<slot>.
 
+color.decorate.<slot>::
+       Use customized color for 'git log --decorate' output.  `<slot>` is one
+       of `branch`, `remoteBranch`, `tag`, `stash` or `HEAD` for local
+       branches, remote tracking branches, tags, stash and HEAD, respectively.
+
 color.grep::
        When set to `always`, always highlight matches.  When `false` (or
        `never`), never.  When set to `true` or `auto`, use color only
@@ -805,6 +819,9 @@ diff.mnemonicprefix::
 `git diff --no-index a b`;;
        compares two non-git things (1) and (2).
 
+diff.noprefix::
+       If set, 'git diff' does not show any source or destination prefix.
+
 diff.renameLimit::
        The number of files to consider when performing the copy/rename
        detection; equivalent to the 'git diff' option '-l'.
@@ -884,6 +901,12 @@ format.subjectprefix::
        The default for format-patch is to output files with the '[PATCH]'
        subject prefix. Use this variable to change that prefix.
 
+format.signature::
+       The default for format-patch is to output a signature containing
+       the git version number. Use this variable to change that default.
+       Set this variable to the empty string ("") to suppress
+       signature generation.
+
 format.suffix::
        The default for format-patch is to output files with the suffix
        `.patch`. Use this variable to change that suffix (make sure to
@@ -944,13 +967,19 @@ gc.pruneexpire::
        unreachable objects immediately.
 
 gc.reflogexpire::
+gc.<pattern>.reflogexpire::
        'git reflog expire' removes reflog entries older than
-       this time; defaults to 90 days.
+       this time; defaults to 90 days.  With "<pattern>" (e.g.
+       "refs/stash") in the middle the setting applies only to
+       the refs that match the <pattern>.
 
 gc.reflogexpireunreachable::
+gc.<ref>.reflogexpireunreachable::
        'git reflog expire' removes reflog entries older than
        this time and are not reachable from the current tip;
-       defaults to 30 days.
+       defaults to 30 days.  With "<pattern>" (e.g. "refs/stash")
+       in the middle, the setting applies only to the refs that
+       match the <pattern>.
 
 gc.rerereresolved::
        Records of conflicted merge you resolved earlier are
@@ -975,13 +1004,15 @@ gitcvs.logfile::
        various stuff. See linkgit:git-cvsserver[1].
 
 gitcvs.usecrlfattr::
-       If true, the server will look up the `crlf` attribute for
-       files to determine the '-k' modes to use. If `crlf` is set,
-       the '-k' mode will be left blank, so cvs clients will
-       treat it as text. If `crlf` is explicitly unset, the file
+       If true, the server will look up the end-of-line conversion
+       attributes for files to determine the '-k' modes to use. If
+       the attributes force git to treat a file as text,
+       the '-k' mode will be left blank so CVS clients will
+       treat it as text. If they suppress text conversion, the file
        will be set with '-kb' mode, which suppresses any newline munging
-       the client might otherwise do. If `crlf` is not specified,
-       then 'gitcvs.allbinary' is used. See linkgit:gitattributes[5].
+       the client might otherwise do. If the attributes do not allow
+       the file type to be determined, then 'gitcvs.allbinary' is
+       used. See linkgit:gitattributes[5].
 
 gitcvs.allbinary::
        This is used if 'gitcvs.usecrlfattr' does not resolve
@@ -1249,7 +1280,9 @@ instaweb.local::
        be bound to the local IP (127.0.0.1).
 
 instaweb.modulepath::
-       The module path for an apache httpd used by linkgit:git-instaweb[1].
+       The default module path for linkgit:git-instaweb[1] to use
+       instead of /usr/lib/apache2/modules.  Only used if httpd
+       is Apache.
 
 instaweb.port::
        The port number to bind the gitweb httpd to. See
@@ -1268,6 +1301,13 @@ log.date::
        following alternatives: {relative,local,default,iso,rfc,short}.
        See linkgit:git-log[1].
 
+log.decorate::
+       Print out the ref names of any commits that are shown by the log
+       command. If 'short' is specified, the ref name prefixes 'refs/heads/',
+       'refs/tags/' and 'refs/remotes/' will not be printed. If 'full' is
+       specified, the full ref name (including prefix) will be printed.
+       This is the same as the log commands '--decorate' option.
+
 log.showroot::
        If true, the initial commit will be shown as a big creation event.
        This is equivalent to a diff against an empty tree.
@@ -1466,6 +1506,16 @@ pager.<cmd>::
        it takes precedence over this option.  To disable pagination for
        all commands, set `core.pager` or `GIT_PAGER` to `cat`.
 
+pretty.<name>::
+       Alias for a --pretty= format string, as specified in
+       linkgit:git-log[1]. Any aliases defined here can be used just
+       as the built-in pretty formats could. For example,
+       running `git config pretty.changelog "format:{asterisk} %H %s"`
+       would cause the invocation `git log --pretty=changelog`
+       to be equivalent to running `git log "--pretty=format:{asterisk} %H %s"`.
+       Note that an alias with the same name as a built-in format
+       will be silently ignored.
+
 pull.octopus::
        The default merge strategy to use when pulling multiple branches
        at once.
@@ -1515,6 +1565,10 @@ receive.denyDeletes::
        If set to true, git-receive-pack will deny a ref update that deletes
        the ref. Use this to prevent such a ref deletion via a push.
 
+receive.denyDeleteCurrent::
+       If set to true, git-receive-pack will deny a ref update that
+       deletes the currently checked out branch of a non-bare repository.
+
 receive.denyCurrentBranch::
        If set to true or "refuse", git-receive-pack will deny a ref update
        to the currently checked out branch of a non-bare repository.
@@ -1578,7 +1632,11 @@ remote.<name>.uploadpack::
 
 remote.<name>.tagopt::
        Setting this value to \--no-tags disables automatic tag following when
-       fetching from remote <name>
+       fetching from remote <name>. Setting it to \--tags will fetch every
+       tag from remote <name>, even if they are not reachable from remote
+       branch heads. Passing these flags directly to linkgit:git-fetch[1] can
+       override this setting. See options \--tags and \--no-tags of
+       linkgit:git-fetch[1].
 
 remote.<name>.vcs::
        Setting this to a value <vcs> will cause git to interact with
index 3070dddfe2870b235dced1cf53da22d33ca8fb40..eecedaab6e172f227f2451f4b3d35c9e6e99bf1e 100644 (file)
@@ -21,6 +21,7 @@ endif::git-format-patch[]
 ifndef::git-format-patch[]
 -p::
 -u::
+--patch::
        Generate patch (see section on generating patches).
        {git-diff? This is the default.}
 endif::git-format-patch[]
@@ -126,11 +127,39 @@ any of those replacements occurred.
        gives the default to color output.
        Same as `--color=never`.
 
---color-words[=<regex>]::
-       Show colored word diff, i.e., color words which have changed.
-       By default, words are separated by whitespace.
+--word-diff[=<mode>]::
+       Show a word diff, using the <mode> to delimit changed words.
+       By default, words are delimited by whitespace; see
+       `--word-diff-regex` below.  The <mode> defaults to 'plain', and
+       must be one of:
++
+--
+color::
+       Highlight changed words using only colors.  Implies `--color`.
+plain::
+       Show words as `[-removed-]` and `{+added+}`.  Makes no
+       attempts to escape the delimiters if they appear in the input,
+       so the output may be ambiguous.
+porcelain::
+       Use a special line-based format intended for script
+       consumption.  Added/removed/unchanged runs are printed in the
+       usual unified diff format, starting with a `+`/`-`/` `
+       character at the beginning of the line and extending to the
+       end of the line.  Newlines in the input are represented by a
+       tilde `~` on a line of its own.
+none::
+       Disable word diff again.
+--
 +
-When a <regex> is specified, every non-overlapping match of the
+Note that despite the name of the first mode, color is used to
+highlight the changed parts in all modes if enabled.
+
+--word-diff-regex=<regex>::
+       Use <regex> to decide what a word is, instead of considering
+       runs of non-whitespace to be a word.  Also implies
+       `--word-diff` unless it was already enabled.
++
+Every non-overlapping match of the
 <regex> is considered a word.  Anything between these matches is
 considered whitespace and ignored(!) for the purposes of finding
 differences.  You may want to append `|[^[:space:]]` to your regular
@@ -142,6 +171,10 @@ The regex can also be set via a diff driver or configuration option, see
 linkgit:gitattributes[1] or linkgit:git-config[1].  Giving it explicitly
 overrides any diff driver or configuration setting.  Diff drivers
 override configuration settings.
+
+--color-words[=<regex>]::
+       Equivalent to `--word-diff=color` plus (if a regex was
+       specified) `--word-diff-regex=<regex>`.
 endif::git-format-patch[]
 
 --no-renames::
@@ -173,10 +206,29 @@ endif::git-format-patch[]
        the diff-patch output format.  Non default number of
        digits can be specified with `--abbrev=<n>`.
 
--B::
-       Break complete rewrite changes into pairs of delete and create.
-
--M::
+-B[<n>][/<m>]::
+       Break complete rewrite changes into pairs of delete and
+       create. This serves two purposes:
++
+It affects the way a change that amounts to a total rewrite of a file
+not as a series of deletion and insertion mixed together with a very
+few lines that happen to match textually as the context, but as a
+single deletion of everything old followed by a single insertion of
+everything new, and the number `m` controls this aspect of the -B
+option (defaults to 60%). `-B/70%` specifies that less than 30% of the
+original should remain in the result for git to consider it a total
+rewrite (i.e. otherwise the resulting patch will be a series of
+deletion and insertion mixed together with context lines).
++
+When used with -M, a totally-rewritten file is also considered as the
+source of a rename (usually -M only considers a file that disappeared
+as the source of a rename), and the number `n` controls this aspect of
+the -B option (defaults to 50%). `-B20%` specifies that a change with
+addition and deletion compared to 20% or more of the file's size are
+eligible for being picked up as a possible source of a rename to
+another file.
+
+-M[<n>]::
 ifndef::git-log[]
        Detect renames.
 endif::git-log[]
@@ -185,9 +237,15 @@ ifdef::git-log[]
        For following files across renames while traversing history, see
        `--follow`.
 endif::git-log[]
+       If `n` is specified, it is a is a threshold on the similarity
+       index (i.e. amount of addition/deletions compared to the
+       file's size). For example, `-M90%` means git should consider a
+       delete/add pair to be a rename if more than 90% of the file
+       hasn't changed.
 
--C::
+-C[<n>]::
        Detect copies as well as renames.  See also `--find-copies-harder`.
+       If `n` is specified, it has the same meaning as for `-M<n>`.
 
 ifndef::git-format-patch[]
 --diff-filter=[ACDMRTUXB*]::
@@ -295,8 +353,14 @@ endif::git-format-patch[]
 --no-ext-diff::
        Disallow external diff drivers.
 
---ignore-submodules::
-       Ignore changes to submodules in the diff generation.
+--ignore-submodules[=<when>]::
+       Ignore changes to submodules in the diff generation. <when> can be
+       either "untracked", "dirty" or "all", which is the default. When
+       "untracked" is used submodules are not considered dirty when they only
+       contain untracked content (but they are still scanned for modified
+       content). Using "dirty" ignores all changes to the work tree of submodules,
+       only changes to the commits stored in the superproject are shown (this was
+       the behavior until 1.7.0). Using "all" hides all changes to submodules.
 
 --src-prefix=<prefix>::
        Show the given source prefix instead of "a/".
index 9333c42c558464ce2430df39e9864f932e786b36..470ac31396606a18298f69329b050a86943c580c 100644 (file)
@@ -49,7 +49,9 @@ ifndef::git-pull[]
 endif::git-pull[]
        By default, tags that point at objects that are downloaded
        from the remote repository are fetched and stored locally.
-       This option disables this automatic tag following.
+       This option disables this automatic tag following. The default
+       behavior for a remote may be specified with the remote.<name>.tagopt
+       setting. See linkgit:git-config[1].
 
 -t::
 --tags::
@@ -58,7 +60,9 @@ endif::git-pull[]
        objects reachable from the branch heads that are being
        tracked will not be fetched by this mechanism.  This
        flag lets all tags and their associated objects be
-       downloaded.
+       downloaded. The default behavior for a remote may be
+       specified with the remote.<name>.tagopt setting. See
+       linkgit:git-config[1].
 
 -u::
 --update-head-ok::
index 74741a42f409a7af5c60584a0d3b7a0be851811c..e22a62f06592c7d233fc06da022962cae59d105a 100644 (file)
@@ -10,7 +10,8 @@ SYNOPSIS
 [verse]
 'git add' [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]
          [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]
-         [--refresh] [--ignore-errors] [--] [<filepattern>...]
+         [--refresh] [--ignore-errors] [--ignore-missing] [--]
+         [<filepattern>...]
 
 DESCRIPTION
 -----------
@@ -57,7 +58,8 @@ OPTIONS
 
 -n::
 --dry-run::
-        Don't actually add the file(s), just show if they exist.
+       Don't actually add the file(s), just show if they exist and/or will
+       be ignored.
 
 -v::
 --verbose::
@@ -131,6 +133,12 @@ subdirectories.
        them, do not abort the operation, but continue adding the
        others. The command shall still exit with non-zero status.
 
+--ignore-missing::
+       This option can only be used together with --dry-run. By using
+       this option the user can check if any of the given files would
+       be ignored, no matter if they are already present in the work
+       tree or not.
+
 \--::
        This option can be used to separate command-line options from
        the list of files, (useful when filenames might be mistaken
index 8463439ac5047d5f1921db4d6f2d765e7728c73b..4a74b23d403d970643fcb8e0438ab6649f54e54c 100644 (file)
@@ -26,6 +26,10 @@ with the `--cache` option the patch is only applied to the index.
 Without these options, the command applies the patch only to files,
 and does not require them to be in a git repository.
 
+This command applies the patch but does not create a commit.  Use
+linkgit:git-am[1] to create commits from patches generated by
+linkgit:git-format-patch[1] and/or received by email.
+
 OPTIONS
 -------
 <patch>...::
@@ -242,6 +246,12 @@ If `--index` is not specified, then the submodule commits in the patch
 are ignored and only the absence or presence of the corresponding
 subdirectory is checked and (if possible) updated.
 
+
+SEE ALSO
+--------
+linkgit:git-am[1].
+
+
 Author
 ------
 Written by Linus Torvalds <torvalds@osdl.org>
index 86b3015c134938c03a396b9fbcfcd5cd47e96718..efbe3790bb4a0521c954650ad43075f583500c7b 100644 (file)
@@ -971,7 +971,7 @@ logical change in each commit.
 The smaller the changes in your commit, the most effective "git
 bisect" will be. And you will probably need "git bisect" less in the
 first place, as small changes are easier to review even if they are
-only reviewed by the commiter.
+only reviewed by the committer.
 
 Another good idea is to have good commit messages. They can be very
 helpful to understand why some changes were made.
index 58c8d65772af4ef20ad573af9dd28691f5357437..a3f56b07fd251cbd121c28189d1f9018b892b48e 100644 (file)
@@ -9,14 +9,15 @@ git-cat-file - Provide content or type and size information for repository objec
 SYNOPSIS
 --------
 [verse]
-'git cat-file' (-t | -s | -e | -p | <type>) <object>
+'git cat-file' (-t | -s | -e | -p | <type> | --textconv ) <object>
 'git cat-file' (--batch | --batch-check) < <list-of-objects>
 
 DESCRIPTION
 -----------
 In its first form, the command provides the content or the type of an object in
 the repository. The type is required unless '-t' or '-p' is used to find the
-object type, or '-s' is used to find the object size.
+object type, or '-s' is used to find the object size, or '--textconv' is used
+(which implies type "blob").
 
 In the second form, a list of objects (separated by linefeeds) is provided on
 stdin, and the SHA1, type, and size of each object is printed on stdout.
@@ -26,7 +27,7 @@ OPTIONS
 <object>::
        The name of the object to show.
        For a more complete list of ways to spell object names, see
-       the "SPECIFYING REVISIONS" section in linkgit:git-rev-parse[1].
+       the "SPECIFYING REVISIONS" section in linkgit:gitrevisions[1].
 
 -t::
        Instead of the content, show the object type identified by
@@ -51,6 +52,11 @@ OPTIONS
        or to ask for a "blob" with <object> being a tag object that
        points at it.
 
+--textconv::
+       Show the content as transformed by a textconv filter. In this case,
+       <object> has be of the form <treeish>:<path>, or :<path> in order
+       to apply the filter to the content recorded in the index at <path>.
+
 --batch::
        Print the SHA1, type, size, and contents of each object provided on
        stdin. May not be combined with any other options or arguments.
index 379eee6734323ee566480d5f9159dd28ed27ecd2..f5c2e0601db6782b2a8690c687611b93da935024 100644 (file)
@@ -49,7 +49,7 @@ git imposes the following rules on how references are named:
 These rules make it easy for shell script based tools to parse
 reference names, pathname expansion by the shell when a reference name is used
 unquoted (by mistake), and also avoids ambiguities in certain
-reference name expressions (see linkgit:git-rev-parse[1]):
+reference name expressions (see linkgit:gitrevisions[1]):
 
 . A double-dot `..` is often used as in `ref1..ref2`, and in some
   contexts this notation means `{caret}ref1 ref2` (i.e. not in
index 7b831622239872b1567eada42fa03331a6b3494f..1bacd2e1044f5b3b7d5a60e1687387cc277fc52a 100644 (file)
@@ -9,7 +9,7 @@ SYNOPSIS
 --------
 [verse]
 'git checkout' [-q] [-f] [-m] [<branch>]
-'git checkout' [-q] [-f] [-m] [-b <new_branch>] [<start_point>]
+'git checkout' [-q] [-f] [-m] [[-b|--orphan] <new_branch>] [<start_point>]
 'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
 'git checkout' --patch [<tree-ish>] [--] [<paths>...]
 
@@ -98,6 +98,31 @@ explicitly give a name with '-b' in such a case.
        Create the new branch's reflog; see linkgit:git-branch[1] for
        details.
 
+--orphan::
+       Create a new 'orphan' branch, named <new_branch>, started from
+       <start_point> and switch to it.  The first commit made on this
+       new branch will have no parents and it will be the root of a new
+       history totally disconnected from all the other branches and
+       commits.
++
+The index and the working tree are adjusted as if you had previously run
+"git checkout <start_point>".  This allows you to start a new history
+that records a set of paths similar to <start_point> by easily running
+"git commit -a" to make the root commit.
++
+This can be useful when you want to publish the tree from a commit
+without exposing its full history. You might want to do this to publish
+an open source branch of a project whose current tree is "clean", but
+whose full history contains proprietary or otherwise encumbered bits of
+code.
++
+If you want to start a disconnected history that records a set of paths
+that is totally different from the one of <start_point>, then you should
+clear the index and the working tree right after creating the orphan
+branch by running "git rm -rf ." from the top level of the working tree.
+Afterwards you will be ready to prepare your new files, repopulating the
+working tree, by copying them from elsewhere, extracting a tarball, etc.
+
 -m::
 --merge::
        When switching branches,
index d71607a85d03062c76f7d17d4fd8e8b4168a279d..2cef579316ba11e68d65dc4d7309f2e56a465b3d 100644 (file)
@@ -3,24 +3,28 @@ git-cherry-pick(1)
 
 NAME
 ----
-git-cherry-pick - Apply the change introduced by an existing commit
+git-cherry-pick - Apply the changes introduced by some existing commits
 
 SYNOPSIS
 --------
-'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>
+'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>...
 
 DESCRIPTION
 -----------
-Given one existing commit, apply the change the patch introduces, and record a
-new commit that records it.  This requires your working tree to be clean (no
-modifications from the HEAD commit).
+
+Given one or more existing commits, apply the change each one
+introduces, recording a new commit for each.  This requires your
+working tree to be clean (no modifications from the HEAD commit).
 
 OPTIONS
 -------
-<commit>::
-       Commit to cherry-pick.
-       For a more complete list of ways to spell commits, see the
-       "SPECIFYING REVISIONS" section in linkgit:git-rev-parse[1].
+<commit>...::
+       Commits to cherry-pick.
+       For a more complete list of ways to spell commits, see
+       linkgit:gitrevisions[1].
+       Sets of commits can be passed but no traversal is done by
+       default, as if the '--no-walk' option was specified, see
+       linkgit:git-rev-list[1].
 
 -e::
 --edit::
@@ -55,10 +59,10 @@ OPTIONS
 
 -n::
 --no-commit::
-       Usually the command automatically creates a commit.
-       This flag applies the change necessary to cherry-pick
-       the named commit to your working tree and the index,
-       but does not make the commit.  In addition, when this
+       Usually the command automatically creates a sequence of commits.
+       This flag applies the changes necessary to cherry-pick
+       each named commit to your working tree and the index,
+       without making any commit.  In addition, when this
        option is used, your index does not have to match the
        HEAD commit.  The cherry-pick is done against the
        beginning state of your index.
@@ -75,6 +79,47 @@ effect to your index in a row.
        cherry-pick'ed commit, then a fast forward to this commit will
        be performed.
 
+EXAMPLES
+--------
+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::
+
+       Apply the changes introduced by all commits that are ancestors
+       of master but not of HEAD to produce new commits.
+
+git cherry-pick master\~4 master~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::
+
+       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::
+
+       If history is linear and HEAD is an ancestor of next, update
+       the working tree and advance the HEAD pointer to match next.
+       Otherwise, apply the changes introduced by those commits that
+       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::
+
+       Apply the changes introduced by all commits on the master
+       branch that touched README to the working tree and index,
+       so the result can be inspected and made into a single new
+       commit if suitable.
+
 Author
 ------
 Written by Junio C Hamano <gitster@pobox.com>
@@ -83,6 +128,10 @@ Documentation
 --------------
 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
 
+SEE ALSO
+--------
+linkgit:git-revert[1]
+
 GIT
 ---
 Part of the linkgit:git[1] suite
index 69eb86e4506411b0d8029f849fd4ebff47166d05..ec7b577b85ae5a320b1006380f5abd03946ba44b 100644 (file)
@@ -10,9 +10,9 @@ SYNOPSIS
 [verse]
 'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
           [(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
-          [--allow-empty] [--no-verify] [-e] [--author=<author>]
-          [--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--]
-          [[-i | -o ]<file>...]
+          [--allow-empty] [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
+          [--date=<date>] [--cleanup=<mode>] [--status | --no-status]
+          [-i | -o] [--] [<file>...]
 
 DESCRIPTION
 -----------
@@ -130,7 +130,13 @@ OPTIONS
        Usually recording a commit that has the exact same tree as its
        sole parent commit is a mistake, and the command prevents you
        from making such a commit.  This option bypasses the safety, and
-       is primarily for use by foreign scm interface scripts.
+       is primarily for use by foreign SCM interface scripts.
+
+--allow-empty-message::
+       Like --allow-empty this command is primarily for use by foreign
+       SCM interface scripts. It allows you to create a commit with an
+       empty commit message without using plumbing commands like
+       linkgit:git-commit-tree[1].
 
 --cleanup=<mode>::
        This option sets how the commit message is cleaned up.
index 8bcd875a677ab6ff91fc4600d541eac4750efce7..608cd63fc359d591e2aafbb8bd2fbae9b868b68b 100644 (file)
@@ -188,7 +188,7 @@ ISSUES
 ------
 Problems related to timestamps:
 
- * If timestamps of commits in the cvs repository are not stable enough
+ * If timestamps of commits in the CVS repository are not stable enough
    to be used for ordering commits changes may show up in the wrong
    order.
  * If any files were ever "cvs import"ed more than once (e.g., import of
@@ -201,7 +201,7 @@ Problems related to branches:
 
  * Branches on which no commits have been made are not imported.
  * All files from the branching point are added to a branch even if
-   never added in cvs.
+   never added in CVS.
  * This applies to files added to the source branch *after* a daughter
    branch was created: if previously no commit was made on the daughter
    branch they will erroneously be added to the daughter branch in git.
index dbb053ee17fbc9e254aac42bf87d204655e00614..f4472c61dbb297d61053ef2e8503ad7c56d06148 100644 (file)
@@ -72,9 +72,6 @@ plugin. Most functionality works fine with both of these clients.
 LIMITATIONS
 -----------
 
-Currently cvsserver works over SSH connections for read/write clients, and
-over pserver for anonymous CVS access.
-
 CVS clients cannot tag, branch or perform GIT merges.
 
 'git-cvsserver' maps GIT branches to CVS modules. This is very different
@@ -84,7 +81,7 @@ one or more directories.
 INSTALLATION
 ------------
 
-1. If you are going to offer anonymous CVS access via pserver, add a line in
+1. If you are going to offer CVS access via pserver, add a line in
    /etc/inetd.conf like
 +
 --
@@ -101,6 +98,38 @@ looks like
    cvspserver stream tcp nowait nobody /usr/bin/git-cvsserver git-cvsserver pserver
 
 ------
+
+Only anonymous access is provided by pserve by default. To commit you
+will have to create pserver accounts, simply add a gitcvs.authdb
+setting in the config file of the repositories you want the cvsserver
+to allow writes to, for example:
+
+------
+
+   [gitcvs]
+       authdb = /etc/cvsserver/passwd
+
+------
+The format of these files is username followed by the crypted password,
+for example:
+
+------
+   myuser:$1Oyx5r9mdGZ2
+   myuser:$1$BA)@$vbnMJMDym7tA32AamXrm./
+------
+You can use the 'htpasswd' facility that comes with Apache to make these
+files, but Apache's MD5 crypt method differs from the one used by most C
+library's crypt() function, so don't use the -m option.
+
+Alternatively you can produce the password with perl's crypt() operator:
+-----
+   perl -e 'my ($user, $pass) = @ARGV; printf "%s:%s\n", $user, crypt($user, $pass)' $USER password
+-----
+
+Then provide your password via the pserver method, for example:
+------
+   cvs -d:pserver:someuser:somepassword <at> server/path/repo.git co <HEAD_name>
+------
 No special setup is needed for SSH access, other than having GIT tools
 in the PATH. If you have clients that do not accept the CVS_SERVER
 environment variable, you can rename 'git-cvsserver' to `cvs`.
@@ -337,19 +366,16 @@ CRLF Line Ending Conversions
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 By default the server leaves the '-k' mode blank for all files,
-which causes the cvs client to treat them as a text files, subject
-to crlf conversion on some platforms.
+which causes the CVS client to treat them as a text files, subject
+to end-of-line conversion on some platforms.
 
-You can make the server use `crlf` attributes to set the '-k' modes
-for files by setting the `gitcvs.usecrlfattr` config variable.
-In this case, if `crlf` is explicitly unset ('-crlf'), then the
-server will set '-kb' mode for binary files. If `crlf` is set,
-then the '-k' mode will explicitly be left blank.  See
-also linkgit:gitattributes[5] for more information about the `crlf`
-attribute.
+You can make the server use the end-of-line conversion attributes to
+set the '-k' modes for files by setting the `gitcvs.usecrlfattr`
+config variable.  See linkgit:gitattributes[5] for more information
+about end-of-line conversion.
 
 Alternatively, if `gitcvs.usecrlfattr` config is not enabled
-or if the `crlf` attribute is unspecified for a filename, then
+or the attributes do not allow automatic detection for a filename, then
 the server uses the `gitcvs.allbinary` config for the default setting.
 If `gitcvs.allbinary` is set, then file not otherwise
 specified will default to '-kb' mode. Otherwise the '-k' mode
index 723a64872fd4b43612d576781d915a7538189f46..08fd4099addac3959e5aedbd1a0668367f07bb21 100644 (file)
@@ -68,11 +68,11 @@ for the last two forms that use ".." notations, can be any
 <tree-ish>.
 
 For a more complete list of ways to spell <commit>, see
-"SPECIFYING REVISIONS" section in linkgit:git-rev-parse[1].
+"SPECIFYING REVISIONS" section in linkgit:gitrevisions[1].
 However, "diff" is about comparing two _endpoints_, not ranges,
 and the range notations ("<commit>..<commit>" and
 "<commit>\...<commit>") do not mean a range as defined in the
-"SPECIFYING RANGES" section in linkgit:git-rev-parse[1].
+"SPECIFYING RANGES" section in linkgit:gitrevisions[1].
 
 OPTIONS
 -------
index 19082b04eb7ec77bcf974e0c76b8d20bb736c021..77a0a2481a34f987aab4688002a6e6a0ae2e497f 100644 (file)
@@ -439,7 +439,7 @@ Marks must be declared (via `mark`) before they can be used.
 * A complete 40 byte or abbreviated commit SHA-1 in hex.
 
 * Any valid Git SHA-1 expression that resolves to a commit.  See
-  ``SPECIFYING REVISIONS'' in linkgit:git-rev-parse[1] for details.
+  ``SPECIFYING REVISIONS'' in linkgit:gitrevisions[1] for details.
 
 The special case of restarting an incremental import from the
 current branch value should be written as:
index 7e83288d1846a7fcd53ec46776160a2f5ffbad84..390d85ccaea6ada3f3bce6148bcdd84d4f0bc2ac 100644 (file)
@@ -86,6 +86,7 @@ objectsize::
 
 objectname::
        The object name (aka SHA-1).
+       For a non-ambiguous abbreviation of the object name append `:short`.
 
 upstream::
        The name of a local ref which can be considered ``upstream''
index 835fb7135b9d159281ef8eb81daf699c6aeec57b..4b3f5ba5358da469feff4e861e69717f16e81d21 100644 (file)
@@ -13,6 +13,7 @@ SYNOPSIS
                   [--no-thread | --thread[=<style>]]
                   [(--attach|--inline)[=<boundary>] | --no-attach]
                   [-s | --signoff]
+                  [--signature=<signature> | --no-signature]
                   [-n | --numbered | -N | --no-numbered]
                   [--start-number <n>] [--numbered-files]
                   [--in-reply-to=Message-Id] [--suffix=.<sfx>]
@@ -38,7 +39,7 @@ There are two ways to specify which commits to operate on.
    that leads to the <since> to be output.
 
 2. Generic <revision range> expression (see "SPECIFYING
-   REVISIONS" section in linkgit:git-rev-parse[1]) means the
+   REVISIONS" section in linkgit:gitrevisions[1]) means the
    commits in the specified range.
 
 The first rule takes precedence in the case of a single <commit>.  To
@@ -180,6 +181,12 @@ will want to ensure that threading is disabled for `git send-email`.
        containing the shortlog and the overall diffstat.  You can
        fill in a description in the file before sending it out.
 
+--[no]-signature=<signature>::
+       Add a signature to each message produced. Per RFC 3676 the signature
+       is separated from the body by a line with '-- ' on it. If the
+       signature option is omitted the signature defaults to the git version
+       number.
+
 --suffix=.<sfx>::
        Instead of using `.patch` as the suffix for generated
        filenames, use specified suffix.  A common alternative is
index cbe74d531af500c0e47e158830474907556a15db..315f07ef1c6997c98c4e446af507c3e1e4566218 100644 (file)
@@ -88,6 +88,16 @@ commits prior to the amend or rebase occurring.  Since these changes
 are not part of the current project most users will want to expire
 them sooner.  This option defaults to '30 days'.
 
+The above two configuration variables can be given to a pattern.  For
+example, this sets non-default expiry values only to remote tracking
+branches:
+
+------------
+[gc "refs/remotes/*"]
+       reflogExpire = never
+       reflogexpireUnreachable = 3 days
+------------
+
 The optional configuration variable 'gc.rerereresolved' indicates
 how long records of conflicted merge you resolved earlier are
 kept.  This defaults to 60 days.
index 912bddd7b67bb486a703814f116a73fa047e667c..5474dd7f94c4b3217230808e656662d0edcef207 100644 (file)
@@ -14,6 +14,7 @@ SYNOPSIS
           [-E | --extended-regexp] [-G | --basic-regexp]
           [-F | --fixed-strings] [-n]
           [-l | --files-with-matches] [-L | --files-without-match]
+          [(-O | --open-files-in-pager) [<pager>]]
           [-z | --null]
           [-c | --count] [--all-match] [-q | --quiet]
           [--max-depth <depth>]
@@ -104,6 +105,13 @@ OPTIONS
        For better compatibility with 'git diff', `--name-only` is a
        synonym for `--files-with-matches`.
 
+-O [<pager>]::
+--open-files-in-pager [<pager>]::
+       Open the matching files in the pager (not the output of 'grep').
+       If the pager happens to be "less" or "vi", and the user
+       specified only one pattern, the first file is positioned at
+       the first match automatically.
+
 -z::
 --null::
        Output \0 instead of the character that normally follows a
index 6904739a48443ba255b2506ad92c10f91fa61d21..51edeecbe5b546c6fbbbe117f39b51f352cb6bc8 100644 (file)
@@ -49,7 +49,7 @@ OPTIONS
 
 --no-filters::
        Hash the contents as is, ignoring any input filter that would
-       have been chosen by the attributes mechanism, including crlf
+       have been chosen by the attributes mechanism, including the end-of-line
        conversion. If the file is read from standard input then this
        is always implied, unless the --path option is given.
 
index a1f17df0744361ab999314b1834c2e2384af90bd..2c3c4d299472a265bfc4486816933ca3dc69b44f 100644 (file)
@@ -29,7 +29,7 @@ OPTIONS
        The HTTP daemon command-line that will be executed.
        Command-line options may be specified here, and the
        configuration file will be added at the end of the command-line.
-       Currently apache2, lighttpd, mongoose and webrick are supported.
+       Currently apache2, lighttpd, mongoose, plackup and webrick are supported.
        (Default: lighttpd)
 
 -m::
index d7f6a9cc3ee335c5437e27dd362ef47c8753ff43..c213bdbdc500b1117805bc84cb2a0f31eeff3bcd 100644 (file)
@@ -23,9 +23,6 @@ each commit introduces are shown.
 OPTIONS
 -------
 
-:git-log: 1
-include::diff-options.txt[]
-
 -<n>::
        Limits the number of commits to show.
 
@@ -34,10 +31,14 @@ include::diff-options.txt[]
        either <since> or <until> is omitted, it defaults to
        `HEAD`, i.e. the tip of the current branch.
        For a more complete list of ways to spell <since>
-       and <until>, see "SPECIFYING REVISIONS" section in
-       linkgit:git-rev-parse[1].
+       and <until>, see linkgit:gitrevisions[1].
 
---decorate[=short|full]::
+--follow::
+       Continue listing the history of a file beyond renames
+       (works only for a single file).
+
+--no-decorate::
+--decorate[=short|full|no]::
        Print out the ref names of any commits that are shown. If 'short' is
        specified, the ref name prefixes 'refs/heads/', 'refs/tags/' and
        'refs/remotes/' will not be printed. If 'full' is specified, the
@@ -54,9 +55,9 @@ include::diff-options.txt[]
        paths.  With this, the full diff is shown for commits that touch
        the specified paths; this means that "<path>..." limits only
        commits, and doesn't limit diff for those commits.
-
---follow::
-       Continue listing the history of a file beyond renames.
++
+Note that this affects all diff-based output types, e.g. those
+produced by --stat etc.
 
 --log-size::
        Before the log message print out its size in bytes. Intended
@@ -71,6 +72,11 @@ include::diff-options.txt[]
        to be prefixed with "\-- " to separate them from options or
        refnames.
 
+Common diff options
+~~~~~~~~~~~~~~~~~~~
+
+:git-log: 1
+include::diff-options.txt[]
 
 include::rev-list-options.txt[]
 
index 3521637b582687978c088dc463e8784817a92217..bd919f2dfddc0165f7749e425a9b1d393558d46f 100644 (file)
@@ -106,8 +106,16 @@ OPTIONS
        with `-s` or `-u` options does not make any sense.
 
 -t::
-       Identify the file status with the following tags (followed by
-       a space) at the start of each line:
+       This feature is semi-deprecated. For scripting purpose,
+       linkgit:git-status[1] `--porcelain` and
+       linkgit:git-diff-files[1] `--name-status` are almost always
+       superior alternatives, and users should look at
+       linkgit:git-status[1] `--short` or linkgit:git-diff[1]
+       `--name-status` for more user-friendly alternatives.
++
+This option identifies the file status with the following tags (followed by
+a space) at the start of each line:
+
        H::     cached
        S::     skip-worktree
        M::     unmerged
index de63ef0745a82136eeee6a2f0993984f2ed2f4ec..2981d8c5efd4e7e0f65d051cfe3b28d3430e3213 100644 (file)
@@ -15,7 +15,7 @@ SYNOPSIS
 'git notes' edit [<object>]
 'git notes' show [<object>]
 'git notes' remove [<object>]
-'git notes' prune
+'git notes' prune [-n | -v]
 
 
 DESCRIPTION
@@ -128,6 +128,15 @@ OPTIONS
        'GIT_NOTES_REF' and the "core.notesRef" configuration.  The ref
        is taken to be in `refs/notes/` if it is not qualified.
 
+-n::
+--dry-run::
+       Do not remove anything; just report the object names whose notes
+       would be removed.
+
+-v::
+--verbose::
+       Report all object names whose notes are removed.
+
 
 DISCUSSION
 ----------
index 15cfb7a8dc8e5e6eb25ee58b8fe15d89ad62dc8a..4d673a56864ca88de0e98f54a6de469e99ea0f44 100644 (file)
@@ -31,10 +31,12 @@ OPTIONS
 -------
 
 -n::
+--dry-run::
        Do not remove anything; just report what it would
        remove.
 
 -v::
+--verbose::
        Report all removed objects.
 
 \--::
index ab4de103586e8382801dad7de2f43c57f4758e7e..c50f7dcb890139d829bae51c30b513d54fd7761e 100644 (file)
@@ -8,29 +8,72 @@ git-pull - Fetch from and merge with another repository or a local branch
 
 SYNOPSIS
 --------
-'git pull' <options> <repository> <refspec>...
+'git pull' [options] [<repository> [<refspec>...]]
 
 
 DESCRIPTION
 -----------
-Runs 'git fetch' with the given parameters, and calls 'git merge'
-to merge the retrieved head(s) into the current branch.
-With `--rebase`, calls 'git rebase' instead of 'git merge'.
 
-Note that you can use `.` (current directory) as the
-<repository> to pull from the local repository -- this is useful
-when merging local branches into the current branch.
+Incorporates changes from a remote repository into the current
+branch.  In its default mode, `git pull` is shorthand for
+`git fetch` followed by `git merge FETCH_HEAD`.
 
-Also note that options meant for 'git pull' itself and underlying
-'git merge' must be given before the options meant for 'git fetch'.
+More precisely, 'git pull' runs 'git fetch' with the given
+parameters and calls 'git merge' to merge the retrieved branch
+heads into the current branch.
+With `--rebase`, it runs 'git rebase' instead of 'git merge'.
 
-*Warning*: Running 'git pull' (actually, the underlying 'git merge')
+<repository> should be the name of a remote repository as
+passed to linkgit:git-fetch[1].  <refspec> can name an
+arbitrary remote ref (for example, the name of a tag) or even
+a collection of refs with corresponding remote tracking branches
+(e.g., refs/heads/*:refs/remotes/origin/*), but usually it is
+the name of a branch in the remote repository.
+
+Default values for <repository> and <branch> are read from the
+"remote" and "merge" configuration for the current branch
+as set by linkgit:git-branch[1] `--track`.
+
+Assume the following history exists and the current branch is
+"`master`":
+
+------------
+         A---B---C master on origin
+        /
+    D---E---F---G master
+------------
+
+Then "`git pull`" will fetch and replay the changes from the remote
+`master` branch since it diverged from the local `master` (i.e., `E`)
+until its current commit (`C`) on top of `master` and record the
+result in a new commit along with the names of the two parent commits
+and a log message from the user describing the changes.
+
+------------
+         A---B---C remotes/origin/master
+        /         \
+    D---E---F---G---H master
+------------
+
+See linkgit:git-merge[1] for details, including how conflicts
+are presented and handled.
+
+In git 1.7.0 or later, to cancel a conflicting merge, use
+`git reset --merge`.  *Warning*: In older versions of git, running 'git pull'
 with uncommitted changes is discouraged: while possible, it leaves you
-in a state that is hard to back out of in the case of a conflict.
+in a state that may be hard to back out of in the case of a conflict.
+
+If any of the remote changes overlap with local uncommitted changes,
+the merge will be automatically cancelled and the work tree untouched.
+It is generally best to get any local changes in working order before
+pulling or stash them away with linkgit:git-stash[1].
 
 OPTIONS
 -------
 
+Options meant for 'git pull' itself and the underlying 'git merge'
+must be given before the options meant for 'git fetch'.
+
 -q::
 --quiet::
        This is passed to both underlying git-fetch to squelch reporting of
index 48570242fb2dda31a5684e2d678d40690d3c4cab..658ff2ff67f23e9a9d2942e38528dba415139ac3 100644 (file)
@@ -41,7 +41,7 @@ OPTIONS[[OPTIONS]]
 +
 The <src> is often the name of the branch you would want to push, but
 it can be any arbitrary "SHA-1 expression", such as `master~4` or
-`HEAD` (see linkgit:git-rev-parse[1]).
+`HEAD` (see linkgit:gitrevisions[1]).
 +
 The <dst> tells which ref on the remote side is updated with this
 push. Arbitrary expressions cannot be used here, an actual ref must
@@ -200,16 +200,29 @@ summary::
        For a successfully pushed ref, the summary shows the old and new
        values of the ref in a form suitable for using as an argument to
        `git log` (this is `<old>..<new>` in most cases, and
-       `<old>...<new>` for forced non-fast-forward updates). For a
-       failed update, more details are given for the failure.
-       The string `rejected` indicates that git did not try to send the
-       ref at all (typically because it is not a fast-forward). The
-       string `remote rejected` indicates that the remote end refused
-       the update; this rejection is typically caused by a hook on the
-       remote side. The string `remote failure` indicates that the
-       remote end did not report the successful update of the ref
-       (perhaps because of a temporary error on the remote side, a
-       break in the network connection, or other transient error).
+       `<old>...<new>` for forced non-fast-forward updates).
++
+For a failed update, more details are given:
++
+--
+rejected::
+       Git did not try to send the ref at all, typically because it
+       is not a fast-forward and you did not force the update.
+
+remote rejected::
+       The remote end refused the update.  Usually caused by a hook
+       on the remote side, or because the remote repository has one
+       of the following safety options in effect:
+       `receive.denyCurrentBranch` (for pushes to the checked out
+       branch), `receive.denyNonFastForwards` (for forced
+       non-fast-forward updates), `receive.denyDeletes` or
+       `receive.denyDeleteCurrent`.  See linkgit:git-config[1].
+
+remote failure::
+       The remote end did not report the successful update of the ref,
+       perhaps because of a temporary error on the remote side, a
+       break in the network connection, or other transient error.
+--
 
 from::
        The name of the local ref being pushed, minus its
index f6037c4f6a7c6988a9a497455e555979d44e2600..2e78da448f30ad260cb7683a5610f424d0c5ffea 100644 (file)
@@ -412,6 +412,13 @@ turn `core.sparseCheckout` on in order to have sparse checkout
 support.
 
 
+BUGS
+----
+In order to match a directory with $GIT_DIR/info/sparse-checkout,
+trailing slash must be used. The form without trailing slash, while
+works with .gitignore, does not work with sparse checkout.
+
+
 SEE ALSO
 --------
 linkgit:git-write-tree[1]; linkgit:git-ls-files[1];
index 4eaa62b6913f15c354e8008c2884f476428ebb0b..5a0451aaf377d13590d6112a9ee8cf51e217a21d 100644 (file)
@@ -40,7 +40,7 @@ see linkgit:git-log[1].
 The reflog is useful in various git commands, to specify the old value
 of a reference. For example, `HEAD@\{2\}` means "where HEAD used to be
 two moves ago", `master@\{one.week.ago\}` means "where master used to
-point to one week ago", and so on. See linkgit:git-rev-parse[1] for
+point to one week ago", and so on. See linkgit:gitrevisions[1] for
 more details.
 
 To delete single entries from the reflog, use the subcommand "delete"
index 3fc599c0c7d5495ada81b20e4d37fa4936708270..aa021b0cb803a9cd9f08566f6a6fe407eb025e4b 100644 (file)
@@ -10,10 +10,11 @@ SYNOPSIS
 --------
 [verse]
 'git remote' [-v | --verbose]
-'git remote add' [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>
+'git remote add' [-t <branch>] [-m <master>] [-f] [--tags|--no-tags] [--mirror] <name> <url>
 'git remote rename' <old> <new>
 'git remote rm' <name>
 'git remote set-head' <name> (-a | -d | <branch>)
+'git remote set-branches' <name> [--add] <branch>...
 'git remote set-url' [--push] <name> <newurl> [<oldurl>]
 'git remote set-url --add' [--push] <name> <newurl>
 'git remote set-url --delete' [--push] <name> <url>
@@ -51,6 +52,12 @@ update remote-tracking branches <name>/<branch>.
 With `-f` option, `git fetch <name>` is run immediately after
 the remote information is set up.
 +
+With `--tags` option, `git fetch <name>` imports every tag from the
+remote repository.
++
+With `--no-tags` option, `git fetch <name>` does not import tags from
+the remote repository.
++
 With `-t <branch>` option, instead of the default glob
 refspec for the remote to track all branches under
 `$GIT_DIR/remotes/<name>/`, a refspec to track only `<branch>`
@@ -104,6 +111,18 @@ remote set-head origin master" will set `$GIT_DIR/refs/remotes/origin/HEAD` to
 `refs/remotes/origin/master` already exists; if not it must be fetched first.
 +
 
+'set-branches'::
+
+Changes the list of branches tracked by the named remote.
+This can be used to track a subset of the available remote branches
+after the initial setup for a remote.
++
+The named branches will be interpreted as if specified with the
+`-t` option on the 'git remote add' command line.
++
+With `--add`, instead of replacing the list of currently tracked
+branches, adds to that list.
+
 'set-url'::
 
 Changes URL remote points to. Sets first URL remote points to matching
index 645f0c17485d35e6696be950fc61f5fdcf3dd14e..9cf31485feec4b03850edb1f2f3a4b765245f4cc 100644 (file)
@@ -8,40 +8,50 @@ git-reset - Reset current HEAD to the specified state
 SYNOPSIS
 --------
 [verse]
-'git reset' [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]
 'git reset' [-q] [<commit>] [--] <paths>...
 'git reset' --patch [<commit>] [--] [<paths>...]
+'git reset' [--soft | --mixed | --hard | --merge | --keep] [-q] [<commit>]
 
 DESCRIPTION
 -----------
-Sets the current head to the specified commit and optionally resets the
-index and working tree to match.
-
-This command is useful if you notice some small error in a recent
-commit (or set of commits) and want to redo that part without showing
-the undo in the history.
-
-If you want to undo a commit other than the latest on a branch,
-linkgit:git-revert[1] is your friend.
-
-The second and third forms with 'paths' and/or --patch are used to
-revert selected paths in the index from a given commit, without moving
-HEAD.
-
+In the first and second form, copy entries from <commit> to the index.
+In the third form, set the current branch to <commit>, optionally
+modifying index and worktree to match.  The <commit> defaults to HEAD
+in all forms.
+
+'git reset' [-q] [<commit>] [--] <paths>...::
+       This form resets the index entries for all <paths> to their
+       state at the <commit>.  (It does not affect the worktree, nor
+       the current branch.)
++
+This means that `git reset <paths>` is the opposite of `git add
+<paths>`.
 
-OPTIONS
--------
---mixed::
-       Resets the index but not the working tree (i.e., the changed files
-       are preserved but not marked for commit) and reports what has not
-       been updated. This is the default action.
+'git reset' --patch|-p [<commit>] [--] [<paths>...]::
+       Interactively select hunks in the difference between the index
+       and <commit> (defaults to HEAD).  The chosen hunks are applied
+       in reverse to the index.
++
+This means that `git reset -p` is the opposite of `git add -p` (see
+linkgit:git-add[1]).
 
+'git reset' [--<mode>] [<commit>]::
+       This form points the current branch to <commit> and then
+       updates index and working tree according to <mode>, which must
+       be one of the following:
++
+--
 --soft::
        Does not touch the index file nor the working tree at all, but
        requires them to be in a good order. This leaves all your changed
        files "Changes to be committed", as 'git status' would
        put it.
 
+--mixed::
+       Resets the index but not the working tree (i.e., the changed files
+       are preserved but not marked for commit) and reports what has not
+       been updated. This is the default action.
+
 --hard::
        Matches the working tree and index to that of the tree being
        switched to. Any changes to tracked files in the working tree
@@ -59,132 +69,46 @@ OPTIONS
        the given commit.  If a file that is different between the
        current commit and the given commit has local changes, reset
        is aborted.
+--
 
--p::
---patch::
-       Interactively select hunks in the difference between the index
-       and <commit> (defaults to HEAD).  The chosen hunks are applied
-       in reverse to the index.
-+
-This means that `git reset -p` is the opposite of `git add -p` (see
-linkgit:git-add[1]).
+If you want to undo a commit other than the latest on a branch,
+linkgit:git-revert[1] is your friend.
+
+
+OPTIONS
+-------
 
 -q::
 --quiet::
        Be quiet, only report errors.
 
-<commit>::
-       Commit to make the current HEAD. If not given defaults to HEAD.
-
-DISCUSSION
-----------
 
-The tables below show what happens when running:
-
-----------
-git reset --option target
-----------
-
-to reset the HEAD to another commit (`target`) with the different
-reset options depending on the state of the files.
-
-In these tables, A, B, C and D are some different states of a
-file. For example, the first line of the first table means that if a
-file is in state A in the working tree, in state B in the index, in
-state C in HEAD and in state D in the target, then "git reset --soft
-target" will put the file in state A in the working tree, in state B
-in the index and in state D in HEAD.
-
-      working index HEAD target         working index HEAD
-      ----------------------------------------------------
-       A       B     C    D     --soft   A       B     D
-                               --mixed  A       D     D
-                               --hard   D       D     D
-                               --merge (disallowed)
-                               --keep  (disallowed)
-
-      working index HEAD target         working index HEAD
-      ----------------------------------------------------
-       A       B     C    C     --soft   A       B     C
-                               --mixed  A       C     C
-                               --hard   C       C     C
-                               --merge (disallowed)
-                               --keep   A       C     C
-
-      working index HEAD target         working index HEAD
-      ----------------------------------------------------
-       B       B     C    D     --soft   B       B     D
-                               --mixed  B       D     D
-                               --hard   D       D     D
-                               --merge  D       D     D
-                               --keep  (disallowed)
-
-      working index HEAD target         working index HEAD
-      ----------------------------------------------------
-       B       B     C    C     --soft   B       B     C
-                               --mixed  B       C     C
-                               --hard   C       C     C
-                               --merge  C       C     C
-                               --keep   B       C     C
-
-      working index HEAD target         working index HEAD
-      ----------------------------------------------------
-       B       C     C    D     --soft   B       C     D
-                               --mixed  B       D     D
-                               --hard   D       D     D
-                               --merge (disallowed)
-                               --keep  (disallowed)
-
-      working index HEAD target         working index HEAD
-      ----------------------------------------------------
-       B       C     C    C     --soft   B       C     C
-                               --mixed  B       C     C
-                               --hard   C       C     C
-                               --merge  B       C     C
-                               --keep   B       C     C
-
-"reset --merge" is meant to be used when resetting out of a conflicted
-merge. Any mergy operation guarantees that the work tree file that is
-involved in the merge does not have local change wrt the index before
-it starts, and that it writes the result out to the work tree. So if
-we see some difference between the index and the target and also
-between the index and the work tree, then it means that we are not
-resetting out from a state that a mergy operation left after failing
-with a conflict. That is why we disallow --merge option in this case.
-
-"reset --keep" is meant to be used when removing some of the last
-commits in the current branch while keeping changes in the working
-tree. If there could be conflicts between the changes in the commit we
-want to remove and the changes in the working tree we want to keep,
-the reset is disallowed. That's why it is disallowed if there are both
-changes between the working tree and HEAD, and between HEAD and the
-target. To be safe, it is also disallowed when there are unmerged
-entries.
-
-The following tables show what happens when there are unmerged
-entries:
-
-      working index HEAD target         working index HEAD
-      ----------------------------------------------------
-       X       U     A    B     --soft  (disallowed)
-                               --mixed  X       B     B
-                               --hard   B       B     B
-                               --merge  B       B     B
-                               --keep  (disallowed)
-
-      working index HEAD target         working index HEAD
-      ----------------------------------------------------
-       X       U     A    A     --soft  (disallowed)
-                               --mixed  X       A     A
-                               --hard   A       A     A
-                               --merge  A       A     A
-                               --keep  (disallowed)
-
-X means any state and U means an unmerged index.
-
-Examples
+EXAMPLES
 --------
 
+Undo add::
++
+------------
+$ edit                                     <1>
+$ git add frotz.c filfre.c
+$ mailx                                    <2>
+$ git reset                                <3>
+$ git pull git://info.example.com/ nitfol  <4>
+------------
++
+<1> You are happily working on something, and find the changes
+in these files are in good order.  You do not want to see them
+when you run "git diff", because you plan to work on other files
+and changes with these files are distracting.
+<2> Somebody asks you to pull, and the changes sounds worthy of merging.
+<3> However, you already dirtied the index (i.e. your index does
+not match the HEAD commit).  But you know the pull you are going
+to make does not affect frotz.c nor filfre.c, so you revert the
+index changes for these two files.  Your changes in working tree
+remain there.
+<4> Then you can pull and merge, leaving frotz.c and filfre.c
+changes still in the working tree.
+
 Undo a commit and redo::
 +
 ------------
@@ -204,19 +128,6 @@ edit the message further, you can give -C option instead.
 +
 See also the --amend option to linkgit:git-commit[1].
 
-Undo commits permanently::
-+
-------------
-$ git commit ...
-$ git reset --hard HEAD~3   <1>
-------------
-+
-<1> The last three commits (HEAD, HEAD^, and HEAD~2) were bad
-and you do not want to ever see them again.  Do *not* do this if
-you have already given these commits to somebody else.  (See the
-"RECOVERING FROM UPSTREAM REBASE" section in linkgit:git-rebase[1] for
-the implications of doing so.)
-
 Undo a commit, making it a topic branch::
 +
 ------------
@@ -232,28 +143,18 @@ current HEAD.
 <2> Rewind the master branch to get rid of those three commits.
 <3> Switch to "topic/wip" branch and keep working.
 
-Undo add::
+Undo commits permanently::
 +
 ------------
-$ edit                                     <1>
-$ git add frotz.c filfre.c
-$ mailx                                    <2>
-$ git reset                                <3>
-$ git pull git://info.example.com/ nitfol  <4>
+$ git commit ...
+$ git reset --hard HEAD~3   <1>
 ------------
 +
-<1> You are happily working on something, and find the changes
-in these files are in good order.  You do not want to see them
-when you run "git diff", because you plan to work on other files
-and changes with these files are distracting.
-<2> Somebody asks you to pull, and the changes sounds worthy of merging.
-<3> However, you already dirtied the index (i.e. your index does
-not match the HEAD commit).  But you know the pull you are going
-to make does not affect frotz.c nor filfre.c, so you revert the
-index changes for these two files.  Your changes in working tree
-remain there.
-<4> Then you can pull and merge, leaving frotz.c and filfre.c
-changes still in the working tree.
+<1> The last three commits (HEAD, HEAD^, and HEAD~2) were bad
+and you do not want to ever see them again.  Do *not* do this if
+you have already given these commits to somebody else.  (See the
+"RECOVERING FROM UPSTREAM REBASE" section in linkgit:git-rebase[1] for
+the implications of doing so.)
 
 Undo a merge or pull::
 +
@@ -355,7 +256,7 @@ Keep changes in working tree while discarding some previous commits::
 Suppose you are working on something and you commit it, and then you
 continue working a bit more, but now you think that what you have in
 your working tree should be in another branch that has nothing to do
-with what you commited previously. You can start a new branch and
+with what you committed previously. You can start a new branch and
 reset it while keeping the changes in your work tree.
 +
 ------------
@@ -376,6 +277,114 @@ $ git reset --keep start                    <3>
 <3> But you can use "reset --keep" to remove the unwanted commit after
     you switched to "branch2".
 
+
+DISCUSSION
+----------
+
+The tables below show what happens when running:
+
+----------
+git reset --option target
+----------
+
+to reset the HEAD to another commit (`target`) with the different
+reset options depending on the state of the files.
+
+In these tables, A, B, C and D are some different states of a
+file. For example, the first line of the first table means that if a
+file is in state A in the working tree, in state B in the index, in
+state C in HEAD and in state D in the target, then "git reset --soft
+target" will put the file in state A in the working tree, in state B
+in the index and in state D in HEAD.
+
+      working index HEAD target         working index HEAD
+      ----------------------------------------------------
+       A       B     C    D     --soft   A       B     D
+                               --mixed  A       D     D
+                               --hard   D       D     D
+                               --merge (disallowed)
+                               --keep  (disallowed)
+
+      working index HEAD target         working index HEAD
+      ----------------------------------------------------
+       A       B     C    C     --soft   A       B     C
+                               --mixed  A       C     C
+                               --hard   C       C     C
+                               --merge (disallowed)
+                               --keep   A       C     C
+
+      working index HEAD target         working index HEAD
+      ----------------------------------------------------
+       B       B     C    D     --soft   B       B     D
+                               --mixed  B       D     D
+                               --hard   D       D     D
+                               --merge  D       D     D
+                               --keep  (disallowed)
+
+      working index HEAD target         working index HEAD
+      ----------------------------------------------------
+       B       B     C    C     --soft   B       B     C
+                               --mixed  B       C     C
+                               --hard   C       C     C
+                               --merge  C       C     C
+                               --keep   B       C     C
+
+      working index HEAD target         working index HEAD
+      ----------------------------------------------------
+       B       C     C    D     --soft   B       C     D
+                               --mixed  B       D     D
+                               --hard   D       D     D
+                               --merge (disallowed)
+                               --keep  (disallowed)
+
+      working index HEAD target         working index HEAD
+      ----------------------------------------------------
+       B       C     C    C     --soft   B       C     C
+                               --mixed  B       C     C
+                               --hard   C       C     C
+                               --merge  B       C     C
+                               --keep   B       C     C
+
+"reset --merge" is meant to be used when resetting out of a conflicted
+merge. Any mergy operation guarantees that the work tree file that is
+involved in the merge does not have local change wrt the index before
+it starts, and that it writes the result out to the work tree. So if
+we see some difference between the index and the target and also
+between the index and the work tree, then it means that we are not
+resetting out from a state that a mergy operation left after failing
+with a conflict. That is why we disallow --merge option in this case.
+
+"reset --keep" is meant to be used when removing some of the last
+commits in the current branch while keeping changes in the working
+tree. If there could be conflicts between the changes in the commit we
+want to remove and the changes in the working tree we want to keep,
+the reset is disallowed. That's why it is disallowed if there are both
+changes between the working tree and HEAD, and between HEAD and the
+target. To be safe, it is also disallowed when there are unmerged
+entries.
+
+The following tables show what happens when there are unmerged
+entries:
+
+      working index HEAD target         working index HEAD
+      ----------------------------------------------------
+       X       U     A    B     --soft  (disallowed)
+                               --mixed  X       B     B
+                               --hard   B       B     B
+                               --merge  B       B     B
+                               --keep  (disallowed)
+
+      working index HEAD target         working index HEAD
+      ----------------------------------------------------
+       X       U     A    A     --soft  (disallowed)
+                               --mixed  X       A     A
+                               --hard   A       A     A
+                               --merge  A       A     A
+                               --keep  (disallowed)
+
+X means any state and U means an unmerged index.
+
+
 Author
 ------
 Written by Junio C Hamano <gitster@pobox.com> and Linus Torvalds <torvalds@osdl.org>
index 833a2a29ccf65afe275bc35fa0eaa3c5afd21fae..be4c0533603443cd9b4df5bf732bbcdd31802a11 100644 (file)
@@ -174,205 +174,7 @@ shown.  If the pattern does not contain a globbing character (`?`,
        Flags and parameters to be parsed.
 
 
-SPECIFYING REVISIONS
---------------------
-
-A revision parameter typically, but not necessarily, names a
-commit object.  They use what is called an 'extended SHA1'
-syntax.  Here are various ways to spell object names.  The
-ones listed near the end of this list are to name trees and
-blobs contained in a commit.
-
-* The full SHA1 object name (40-byte hexadecimal string), or
-  a substring of such that is unique within the repository.
-  E.g. dae86e1950b1277e545cee180551750029cfe735 and dae86e both
-  name the same commit object if there are no other object in
-  your repository whose object name starts with dae86e.
-
-* An output from 'git describe'; i.e. a closest tag, optionally
-  followed by a dash and a number of commits, followed by a dash, a
-  `g`, and an abbreviated object name.
-
-* A symbolic ref name.  E.g. 'master' typically means the commit
-  object referenced by refs/heads/master.  If you
-  happen to have both heads/master and tags/master, you can
-  explicitly say 'heads/master' to tell git which one you mean.
-  When ambiguous, a `<name>` is disambiguated by taking the
-  first match in the following rules:
-
-  . if `$GIT_DIR/<name>` exists, that is what you mean (this is usually
-    useful only for `HEAD`, `FETCH_HEAD`, `ORIG_HEAD` and `MERGE_HEAD`);
-
-  . otherwise, `refs/<name>` if exists;
-
-  . otherwise, `refs/tags/<name>` if exists;
-
-  . otherwise, `refs/heads/<name>` if exists;
-
-  . otherwise, `refs/remotes/<name>` if exists;
-
-  . otherwise, `refs/remotes/<name>/HEAD` if exists.
-+
-HEAD names the commit your changes in the working tree is based on.
-FETCH_HEAD records the branch you fetched from a remote repository
-with your last 'git fetch' invocation.
-ORIG_HEAD is created by commands that moves your HEAD in a drastic
-way, to record the position of the HEAD before their operation, so that
-you can change the tip of the branch back to the state before you ran
-them easily.
-MERGE_HEAD records the commit(s) you are merging into your branch
-when you run 'git merge'.
-+
-Note that any of the `refs/*` cases above may come either from
-the `$GIT_DIR/refs` directory or from the `$GIT_DIR/packed-refs` file.
-
-* A ref followed by the suffix '@' with a date specification
-  enclosed in a brace
-  pair (e.g. '\{yesterday\}', '\{1 month 2 weeks 3 days 1 hour 1
-  second ago\}' or '\{1979-02-26 18:30:00\}') to specify the value
-  of the ref at a prior point in time.  This suffix may only be
-  used immediately following a ref name and the ref must have an
-  existing log ($GIT_DIR/logs/<ref>). Note that this looks up the state
-  of your *local* ref at a given time; e.g., what was in your local
-  `master` branch last week. If you want to look at commits made during
-  certain times, see `--since` and `--until`.
-
-* A ref followed by the suffix '@' with an ordinal specification
-  enclosed in a brace pair (e.g. '\{1\}', '\{15\}') to specify
-  the n-th prior value of that ref.  For example 'master@\{1\}'
-  is the immediate prior value of 'master' while 'master@\{5\}'
-  is the 5th prior value of 'master'. This suffix may only be used
-  immediately following a ref name and the ref must have an existing
-  log ($GIT_DIR/logs/<ref>).
-
-* You can use the '@' construct with an empty ref part to get at a
-  reflog of the current branch. For example, if you are on the
-  branch 'blabla', then '@\{1\}' means the same as 'blabla@\{1\}'.
-
-* The special construct '@\{-<n>\}' means the <n>th branch checked out
-  before the current one.
-
-* The suffix '@\{upstream\}' to a ref (short form 'ref@\{u\}') refers to
-  the branch the ref is set to build on top of.  Missing ref defaults
-  to the current branch.
-
-* A suffix '{caret}' to a revision parameter (e.g. 'HEAD{caret}') means the first parent of
-  that commit object.  '{caret}<n>' means the <n>th parent (i.e.
-  'rev{caret}'
-  is equivalent to 'rev{caret}1').  As a special rule,
-  'rev{caret}0' means the commit itself and is used when 'rev' is the
-  object name of a tag object that refers to a commit object.
-
-* A suffix '{tilde}<n>' to a revision parameter means the commit
-  object that is the <n>th generation grand-parent of the named
-  commit object, following only the first parent.  I.e. rev~3 is
-  equivalent to rev{caret}{caret}{caret} which is equivalent to
-  rev{caret}1{caret}1{caret}1.  See below for a illustration of
-  the usage of this form.
-
-* A suffix '{caret}' followed by an object type name enclosed in
-  brace pair (e.g. `v0.99.8{caret}\{commit\}`) means the object
-  could be a tag, and dereference the tag recursively until an
-  object of that type is found or the object cannot be
-  dereferenced anymore (in which case, barf).  `rev{caret}0`
-  introduced earlier is a short-hand for `rev{caret}\{commit\}`.
-
-* A suffix '{caret}' followed by an empty brace pair
-  (e.g. `v0.99.8{caret}\{\}`) means the object could be a tag,
-  and dereference the tag recursively until a non-tag object is
-  found.
-
-* A colon, followed by a slash, followed by a text (e.g. `:/fix nasty bug`): this names
-  a commit whose commit message starts with the specified text.
-  This name returns the youngest matching commit which is
-  reachable from any ref.  If the commit message starts with a
-  '!', you have to repeat that;  the special sequence ':/!',
-  followed by something else than '!' is reserved for now.
-
-* A suffix ':' followed by a path (e.g. `HEAD:README`); this names the blob or tree
-  at the given path in the tree-ish object named by the part
-  before the colon.
-  ':path' (with an empty part before the colon, e.g. `:README`)
-  is a special case of the syntax described next: content
-  recorded in the index at the given path.
-
-* A colon, optionally followed by a stage number (0 to 3) and a
-  colon, followed by a path (e.g. `:0:README`); this names a blob object in the
-  index at the given path. Missing stage number (and the colon
-  that follows it, e.g. `:README`) names a stage 0 entry. During a merge, stage
-  1 is the common ancestor, stage 2 is the target branch's version
-  (typically the current branch), and stage 3 is the version from
-  the branch being merged.
-
-Here is an illustration, by Jon Loeliger.  Both commit nodes B
-and C are parents of commit node A.  Parent commits are ordered
-left-to-right.
-
-........................................
-G   H   I   J
- \ /     \ /
-  D   E   F
-   \  |  / \
-    \ | /   |
-     \|/    |
-      B     C
-       \   /
-        \ /
-         A
-........................................
-
-    A =      = A^0
-    B = A^   = A^1     = A~1
-    C = A^2  = A^2
-    D = A^^  = A^1^1   = A~2
-    E = B^2  = A^^2
-    F = B^3  = A^^3
-    G = A^^^ = A^1^1^1 = A~3
-    H = D^2  = B^^2    = A^^^2  = A~2^2
-    I = F^   = B^3^    = A^^3^
-    J = F^2  = B^3^2   = A^^3^2
-
-
-SPECIFYING RANGES
------------------
-
-History traversing commands such as 'git log' operate on a set
-of commits, not just a single commit.  To these commands,
-specifying a single revision with the notation described in the
-previous section means the set of commits reachable from that
-commit, following the commit ancestry chain.
-
-To exclude commits reachable from a commit, a prefix `{caret}`
-notation is used.  E.g. `{caret}r1 r2` means commits reachable
-from `r2` but exclude the ones reachable from `r1`.
-
-This set operation appears so often that there is a shorthand
-for it.  When you have two commits `r1` and `r2` (named according
-to the syntax explained in SPECIFYING REVISIONS above), you can ask
-for commits that are reachable from r2 excluding those that are reachable
-from r1 by `{caret}r1 r2` and it can be written as `r1..r2`.
-
-A similar notation `r1\...r2` is called symmetric difference
-of `r1` and `r2` and is defined as
-`r1 r2 --not $(git merge-base --all r1 r2)`.
-It is the set of commits that are reachable from either one of
-`r1` or `r2` but not from both.
-
-Two other shorthands for naming a set that is formed by a commit
-and its parent commits exist.  The `r1{caret}@` notation means all
-parents of `r1`.  `r1{caret}!` includes commit `r1` but excludes
-all of its parents.
-
-Here are a handful of examples:
-
-   D                G H D
-   D F              G H I J D F
-   ^G D             H D
-   ^D B             E I J F B
-   B...C            G H D E B C
-   ^D B C           E I J F B C
-   C^@              I J F
-   F^! D            G H D F
+include::revisions.txt[]
 
 PARSEOPT
 --------
@@ -382,10 +184,13 @@ scripts the same facilities C builtins have. It works as an option normalizer
 (e.g. splits single switches aggregate values), a bit like `getopt(1)` does.
 
 It takes on the standard input the specification of the options to parse and
-understand, and echoes on the standard output a line suitable for `sh(1)` `eval`
+understand, and echoes on the standard output a string suitable for `sh(1)` `eval`
 to replace the arguments with normalized ones.  In case of error, it outputs
 usage on the standard error stream, and exits with code 129.
 
+Note: Make sure you quote the result when passing it to `eval`.  See
+below for an example.
+
 Input Format
 ~~~~~~~~~~~~
 
@@ -442,7 +247,7 @@ bar=      some cool option --bar with an argument
   An option group Header
 C?        option C with an optional argument"
 
-eval `echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?`
+eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
 ------------
 
 SQ-QUOTE
index c66bf8072e6720d3edfc17d234fc09c8d01bbb2c..b7d9ef7e4726db40f3b0d1ec9474494bb6e07dcf 100644 (file)
@@ -3,20 +3,22 @@ git-revert(1)
 
 NAME
 ----
-git-revert - Revert an existing commit
+git-revert - Revert some existing commits
 
 SYNOPSIS
 --------
-'git revert' [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>
+'git revert' [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>...
 
 DESCRIPTION
 -----------
-Given one existing commit, revert the change the patch introduces, and record a
-new commit that records it.  This requires your working tree to be clean (no
-modifications from the HEAD commit).
 
-Note: 'git revert' is used to record a new commit to reverse the
-effect of an earlier commit (often a faulty one).  If you want to
+Given one or more existing commits, revert the changes that the
+related patches introduce, and record some new commits that record
+them.  This requires your working tree to be clean (no modifications
+from the HEAD commit).
+
+Note: 'git revert' is used to record some new commits to reverse the
+effect of some earlier commits (often only a faulty one).  If you want to
 throw away all uncommitted changes in your working directory, you
 should see linkgit:git-reset[1], particularly the '--hard' option.  If
 you want to extract specific files as they were in another commit, you
@@ -26,10 +28,13 @@ both will discard uncommitted changes in your working directory.
 
 OPTIONS
 -------
-<commit>::
-       Commit to revert.
+<commit>...::
+       Commits to revert.
        For a more complete list of ways to spell commit names, see
-       "SPECIFYING REVISIONS" section in linkgit:git-rev-parse[1].
+       linkgit:gitrevisions[1].
+       Sets of commits can also be given but no traversal is done by
+       default, see linkgit:git-rev-list[1] and its '--no-walk'
+       option.
 
 -e::
 --edit::
@@ -59,11 +64,11 @@ more details.
 
 -n::
 --no-commit::
-       Usually the command automatically creates a commit with
-       a commit log message stating which commit was
-       reverted.  This flag applies the change necessary
-       to revert the named commit to your working tree
-       and the index, but does not make the commit.  In addition,
+       Usually the command automatically creates some commits with
+       commit log messages stating which commits were
+       reverted.  This flag applies the changes necessary
+       to revert the named commits to your working tree
+       and the index, but does not make the commits.  In addition,
        when this option is used, your index does not have to match
        the HEAD commit.  The revert is done against the
        beginning state of your index.
@@ -75,6 +80,20 @@ effect to your index in a row.
 --signoff::
        Add Signed-off-by line at the end of the commit message.
 
+EXAMPLES
+--------
+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\~5..master~2::
+
+       Revert the changes done by commits from the fifth last commit
+       in master (included) to the third last commit in master
+       (included), but do not create any commit with the reverted
+       changes. The revert only modifies the working tree and the
+       index.
 
 Author
 ------
@@ -84,6 +103,10 @@ Documentation
 --------------
 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
 
+SEE ALSO
+--------
+linkgit:git-cherry-pick[1]
+
 GIT
 ---
 Part of the linkgit:git[1] suite
index f1499bba88028775032819708db22a3250b5b840..81ba29669c52a7c50fb126b7b70c3a867df25f00 100644 (file)
@@ -32,7 +32,7 @@ no <rev> nor <glob> is given on the command line.
 OPTIONS
 -------
 <rev>::
-       Arbitrary extended SHA1 expression (see linkgit:git-rev-parse[1])
+       Arbitrary extended SHA1 expression (see linkgit:gitrevisions[1])
        that typically names a branch head or a tag.
 
 <glob>::
index 3f9d9c6db39e030c82e1159043c45c834a47012c..75780d7d63894e220bf938da0b4f5dca40d6301d 100644 (file)
@@ -163,9 +163,15 @@ flag, so you can do
 
 to get a listing of all tags together with what they dereference.
 
+FILES
+-----
+`.git/refs/*`, `.git/packed-refs`
+
 SEE ALSO
 --------
-linkgit:git-ls-remote[1]
+linkgit:git-ls-remote[1],
+linkgit:git-update-ref[1],
+linkgit:gitrepository-layout[5]
 
 AUTHORS
 -------
index 55e687a7c7f2113615c80e1719c4f3a2120ba7fa..0002bfb0455b38eecf6b29da6a2464058ba42c57 100644 (file)
@@ -36,7 +36,7 @@ OPTIONS
 <object>...::
        The names of objects to show.
        For a more complete list of ways to spell object names, see
-       "SPECIFYING REVISIONS" section in linkgit:git-rev-parse[1].
+       "SPECIFYING REVISIONS" section in linkgit:gitrevisions[1].
 
 include::pretty-options.txt[]
 
index 2d4bbfcaf4cc2d2b92ad827662dc3b4b4ef355c0..2fd054c1040ce43949382e4744a0d7a814a8d9bd 100644 (file)
@@ -27,6 +27,10 @@ OPTIONS
 --short::
        Give the output in the short-format.
 
+-b::
+--branch::
+       Show the branch and tracking info even in short-format.
+
 --porcelain::
        Give the output in a stable, easy-to-parse format for scripts.
        Currently this is identical to --short output, but is guaranteed
@@ -49,6 +53,17 @@ See linkgit:git-config[1] for configuration variable
 used to change the default for when the option is not
 specified.
 
+--ignore-submodules[=<when>]::
+       Ignore changes to submodules when looking for changes. <when> can be
+       either "untracked", "dirty" or "all", which is the default. When
+       "untracked" is used submodules are not considered dirty when they only
+       contain untracked content (but they are still scanned for modified
+       content). Using "dirty" ignores all changes to the work tree of submodules,
+       only changes to the commits stored in the superproject are shown (this was
+       the behavior before 1.7.0). Using "all" hides all changes to submodules
+       (and suppresses the output of submodule summaries when the config option
+       `status.submodulesummary` is set).
+
 -z::
        Terminate entries with NUL, instead of LF.  This implies
        the `--porcelain` output format if no other format is given.
@@ -120,6 +135,10 @@ Ignored files are not listed.
     ?           ?    untracked
     -------------------------------------------------
 
+If -b is used the short-format status is preceded by a line
+
+## branchname tracking info
+
 There is an alternate -z format recommended for machine parsing.  In
 that format, the status field is the same, but some other things
 change.  First, the '->' is omitted from rename entries and the field
@@ -128,7 +147,7 @@ order is reversed (e.g 'from -> to' becomes 'to from'). Second, a NUL
 and the terminating newline (but a space still separates the status
 field from the first filename).  Third, filenames containing special
 characters are not specially formatted; no quoting or
-backslash-escaping is performed.
+backslash-escaping is performed. Fourth, there is no branch line.
 
 CONFIGURATION
 -------------
index 2502531a3dfd0cee67f6d1d9fc1db1d69cf20e30..1ed331c599d4b492b0dec112332bb83db5506d74 100644 (file)
@@ -9,7 +9,7 @@ git-submodule - Initialize, update or inspect submodules
 SYNOPSIS
 --------
 [verse]
-'git submodule' [--quiet] add [-b branch]
+'git submodule' [--quiet] add [-b branch] [-f|--force]
              [--reference <repository>] [--] <repository> [<path>]
 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
 'git submodule' [--quiet] init [--] [<path>...]
@@ -145,10 +145,12 @@ summary::
 
 foreach::
        Evaluates an arbitrary shell command in each checked out submodule.
-       The command has access to the variables $name, $path and $sha1:
+       The command has access to the variables $name, $path, $sha1 and
+       $toplevel:
        $name is the name of the relevant submodule section in .gitmodules,
        $path is the name of the submodule directory relative to the
-       superproject, and $sha1 is the commit as recorded in the superproject.
+       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
        of each submodule before evaluating the command.
@@ -181,6 +183,11 @@ OPTIONS
 --branch::
        Branch of repository to add as submodule.
 
+-f::
+--force::
+       This option is only valid for the add command.
+       Allow adding an otherwise ignored submodule path.
+
 --cached::
        This option is only valid for status and summary commands.  These
        commands typically use the commit found in the submodule HEAD, but
index 99f3c1ea6c41b1cda7069f82bd8e38bbbe27a711..b09bd9761faa42f2bc87306ee5c1890647dce769 100644 (file)
@@ -243,7 +243,7 @@ where <name> is the name of the SVN repository as specified by the -R option to
 
 --username;;
        Specify the SVN username to perform the commit as.  This option overrides
-       configuration property 'username'.
+       the 'username' configuration property.
 
 --commit-url;;
        Use the specified URL to connect to the destination Subversion
index b5a4e3d4031961d648b52abc1c64df5b4acfb32c..93e3b07c6cdf6c580cd7dff0d973478b91178481 100644 (file)
@@ -12,6 +12,7 @@ SYNOPSIS
 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
     [-p|--paginate|--no-pager] [--no-replace-objects]
     [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
+    [-c name=value]
     [--help] COMMAND [ARGS]
 
 DESCRIPTION
@@ -43,6 +44,13 @@ 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.2.3/git.html[documentation for release 1.7.2.3]
+
+* release notes for
+  link:RelNotes-1.7.2.3.txt[1.7.2.3],
+  link:RelNotes-1.7.2.2.txt[1.7.2.2],
+  link:RelNotes-1.7.2.1.txt[1.7.2.1],
+  link:RelNotes-1.7.2.txt[1.7.2].
 
 * link:v1.7.1.2/git.html[documentation for release 1.7.1.2]
 
@@ -232,6 +240,12 @@ displayed. See linkgit:git-help[1] for more information,
 because `git --help ...` is converted internally into `git
 help ...`.
 
+-c <name>=<value>::
+       Pass a configuration parameter to the command. The value
+       given will override values from configuration files.
+       The <name> is expected in the same format as listed by
+       'git config' (subkeys separated by dots).
+
 --exec-path::
        Path to wherever your core git programs are installed.
        This can also be controlled by setting the GIT_EXEC_PATH
@@ -475,7 +489,7 @@ HEAD::
        (i.e. the contents of `$GIT_DIR/refs/heads/<head>`).
 
 For a more complete list of ways to spell object names, see
-"SPECIFYING REVISIONS" section in linkgit:git-rev-parse[1].
+"SPECIFYING REVISIONS" section in linkgit:gitrevisions[1].
 
 
 File/Directory Structure
@@ -542,6 +556,16 @@ git so take care if using Cogito etc.
        a GIT_DIR set on the command line or in the environment.
        (Useful for excluding slow-loading network directories.)
 
+'GIT_DISCOVERY_ACROSS_FILESYSTEM'::
+       When run in a directory that does not have ".git" repository
+       directory, git tries to find such a directory in the parent
+       directories to find the top of the working tree, but by default it
+       does not cross filesystem boundaries.  This environment variable
+       can be set to true to tell git not to stop at filesystem
+       boundaries.  Like 'GIT_CEILING_DIRECTORIES', this will not affect
+       an explicit repository directory set via 'GIT_DIR' or on the
+       command line.
+
 git Commits
 ~~~~~~~~~~~
 'GIT_AUTHOR_NAME'::
@@ -705,6 +729,13 @@ The documentation for git suite was started by David Greaves
 <david@dgreaves.com>, and later enhanced greatly by the
 contributors on the git-list <git@vger.kernel.org>.
 
+Reporting Bugs
+--------------
+
+Report bugs to the Git mailing list <git@vger.kernel.org> where the
+development and maintenance is primarily done.  You do not have to be
+subscribed to the list to send a message there.
+
 SEE ALSO
 --------
 linkgit:gittutorial[7], linkgit:gittutorial-2[7],
index d892e642eded92fd0409e39fc34c005f88bc4a9b..564586b943f439cb5ae04c4e76bc19d093c625da 100644 (file)
@@ -92,53 +92,154 @@ such as 'git checkout' and 'git merge' run.  They also affect how
 git stores the contents you prepare in the working tree in the
 repository upon 'git add' and 'git commit'.
 
-`crlf`
+`text`
 ^^^^^^
 
-This attribute controls the line-ending convention.
+This attribute enables and controls end-of-line normalization.  When a
+text file is normalized, its line endings are converted to LF in the
+repository.  To control what line ending style is used in the working
+directory, use the `eol` attribute for a single file and the
+`core.eol` configuration variable for all text files.
 
 Set::
 
-       Setting the `crlf` attribute on a path is meant to mark
-       the path as a "text" file.  'core.autocrlf' conversion
-       takes place without guessing the content type by
-       inspection.
+       Setting the `text` attribute on a path enables end-of-line
+       normalization and marks the path as a text file.  End-of-line
+       conversion takes place without guessing the content type.
 
 Unset::
 
-       Unsetting the `crlf` attribute on a path tells git not to
+       Unsetting the `text` attribute on a path tells git not to
        attempt any end-of-line conversion upon checkin or checkout.
 
+Set to string value "auto"::
+
+       When `text` is set to "auto", the path is marked for automatic
+       end-of-line normalization.  If git decides that the content is
+       text, its line endings are normalized to LF on checkin.
+
 Unspecified::
 
-       Unspecified `crlf` attribute tells git to apply the
-       `core.autocrlf` conversion when the file content looks
-       like text.
+       If the `text` attribute is unspecified, git uses the
+       `core.autocrlf` configuration variable to determine if the
+       file should be converted.
 
-Set to string value "input"::
+Any other value causes git to act as if `text` has been left
+unspecified.
 
-       This is similar to setting the attribute to `true`, but
-       also forces git to act as if `core.autocrlf` is set to
-       `input` for the path.
+`eol`
+^^^^^
 
-Any other value set to `crlf` attribute is ignored and git acts
-as if the attribute is left unspecified.
+This attribute sets a specific line-ending style to be used in the
+working directory.  It enables end-of-line normalization without any
+content checks, effectively setting the `text` attribute.
 
+Set to string value "crlf"::
 
-The `core.autocrlf` conversion
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+       This setting forces git to normalize line endings for this
+       file on checkin and convert them to CRLF when the file is
+       checked out.
+
+Set to string value "lf"::
+
+       This setting forces git to normalize line endings to LF on
+       checkin and prevents conversion to CRLF when the file is
+       checked out.
+
+Backwards compatibility with `crlf` attribute
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+For backwards compatibility, the `crlf` attribute is interpreted as
+follows:
+
+------------------------
+crlf           text
+-crlf          -text
+crlf=input     eol=lf
+------------------------
+
+End-of-line conversion
+^^^^^^^^^^^^^^^^^^^^^^
+
+While git normally leaves file contents alone, it can be configured to
+normalize line endings to LF in the repository and, optionally, to
+convert them to CRLF when files are checked out.
+
+Here is an example that will make git normalize .txt, .vcproj and .sh
+files, ensure that .vcproj files have CRLF and .sh files have LF in
+the working directory, and prevent .jpg files from being normalized
+regardless of their content.
+
+------------------------
+*.txt          text
+*.vcproj       eol=crlf
+*.sh           eol=lf
+*.jpg          -text
+------------------------
+
+Other source code management systems normalize all text files in their
+repositories, and there are two ways to enable similar automatic
+normalization in git.
+
+If you simply want to have CRLF line endings in your working directory
+regardless of the repository you are working with, you can set the
+config variable "core.autocrlf" without changing any attributes.
 
-If the configuration variable `core.autocrlf` is false, no
-conversion is done.
+------------------------
+[core]
+       autocrlf = true
+------------------------
+
+This does not force normalization of all text files, but does ensure
+that text files that you introduce to the repository have their line
+endings normalized to LF when they are added, and that files that are
+already normalized in the repository stay normalized.
+
+If you want to interoperate with a source code management system that
+enforces end-of-line normalization, or you simply want all text files
+in your repository to be normalized, you should instead set the `text`
+attribute to "auto" for _all_ files.
+
+------------------------
+*      text=auto
+------------------------
+
+This ensures that all files that git considers to be text will have
+normalized (LF) line endings in the repository.  The `core.eol`
+configuration variable controls which line endings git will use for
+normalized files in your working directory; the default is to use the
+native line ending for your platform, or CRLF if `core.autocrlf` is
+set.
+
+NOTE: When `text=auto` normalization is enabled in an existing
+repository, any text files containing CRLFs should be normalized.  If
+they are not they will be normalized the next time someone tries to
+change them, causing unfortunate misattribution.  From a clean working
+directory:
+
+-------------------------------------------------
+$ echo "* text=auto" >>.gitattributes
+$ rm .git/index     # Remove the index to force git to
+$ git reset         # re-scan the working directory
+$ git status        # Show files that will be normalized
+$ git add -u
+$ git add .gitattributes
+$ git commit -m "Introduce end-of-line normalization"
+-------------------------------------------------
+
+If any files that should not be normalized show up in 'git status',
+unset their `text` attribute before running 'git add -u'.
 
-When `core.autocrlf` is true, it means that the platform wants
-CRLF line endings for files in the working tree, and you want to
-convert them back to the normal LF line endings when checking
-in to the repository.
+------------------------
+manual.pdf     -text
+------------------------
 
-When `core.autocrlf` is set to "input", line endings are
-converted to LF upon checkin, but there is no conversion done
-upon checkout.
+Conversely, text files that git does not detect can have normalization
+enabled manually.
+
+------------------------
+weirdchars.txt text
+------------------------
 
 If `core.safecrlf` is set to "true" or "warn", git verifies if
 the conversion is reversible for the current setting of
@@ -223,11 +324,11 @@ Interaction between checkin/checkout attributes
 In the check-in codepath, the worktree file is first converted
 with `filter` driver (if specified and corresponding driver
 defined), then the result is processed with `ident` (if
-specified), and then finally with `crlf` (again, if specified
+specified), and then finally with `text` (again, if specified
 and applicable).
 
 In the check-out codepath, the blob content is first converted
-with `crlf`, and then `ident` and fed to `filter`.
+with `text`, and then `ident` and fed to `filter`.
 
 
 Generating diff text
@@ -360,7 +461,7 @@ patterns are available:
 Customizing word diff
 ^^^^^^^^^^^^^^^^^^^^^
 
-You can customize the rules that `git diff --color-words` uses to
+You can customize the rules that `git diff --word-diff` uses to
 split words in a line, by specifying an appropriate regular expression
 in the "diff.*.wordRegex" configuration variable.  For example, in TeX
 a backslash followed by a sequence of letters forms a command, but
@@ -414,6 +515,26 @@ because it quickly conveys the changes you have made), you
 should generate it separately and send it as a comment _in
 addition to_ the usual binary diff that you might send.
 
+Because text conversion can be slow, especially when doing a
+large number of them with `git log -p`, git provides a mechanism
+to cache the output and use it in future diffs.  To enable
+caching, set the "cachetextconv" variable in your diff driver's
+config. For example:
+
+------------------------
+[diff "jpg"]
+       textconv = exif
+       cachetextconv = true
+------------------------
+
+This will cache the result of running "exif" on each blob
+indefinitely. If you change the textconv config variable for a
+diff driver, git will automatically invalidate the cache entries
+and re-run the textconv filter. If you want to invalidate the
+cache manually (e.g., because your version of "exif" was updated
+and now produces better output), you can remove the cache
+manually with `git update-ref -d refs/notes/textconv/jpg` (where
+"jpg" is the name of the diff driver, as in the example above).
 
 Performing a three-way merge
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -631,7 +752,7 @@ You do not want any end-of-line conversions applied to, nor textual diffs
 produced for, any binary file you track.  You would need to specify e.g.
 
 ------------
-*.jpg -crlf -diff
+*.jpg -text -diff
 ------------
 
 but that may become cumbersome, when you have many attributes.  Using
@@ -644,7 +765,7 @@ the same time.  The system knows a built-in attribute macro, `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 "crlf" and "diff").
+ordinary attribute --- setting it in turn unsets "text" and "diff").
 
 
 DEFINING ATTRIBUTE MACROS
@@ -655,7 +776,7 @@ at the toplevel (i.e. not in any subdirectory).  The built-in attribute
 macro "binary" is equivalent to:
 
 ------------
-[attr]binary -diff -crlf
+[attr]binary -diff -text
 ------------
 
 
index f7815e96a268f0eac7602e03255c28ea2fe04e6b..ed3ddc92cb51eaeb3d4a988e396a4f90297037c6 100644 (file)
@@ -971,7 +971,7 @@ commits from the master branch.  The string inside brackets
 before the commit log message is a short name you can use to
 name the commit.  In the above example, 'master' and 'mybranch'
 are branch heads.  'master^' is the first parent of 'master'
-branch head.  Please see linkgit:git-rev-parse[1] if you want to
+branch head.  Please see linkgit:gitrevisions[1] if you want to
 see more complex cases.
 
 [NOTE]
index 99baa24a2d5c8c703d3ad5ce7442bb8363359cd6..05ac1c79f768352be8756eeb483e71f0d09131de 100644 (file)
@@ -69,7 +69,7 @@ frequently used options.
        the form "'<from>'..'<to>'" to show all revisions between '<from>' and
        back to '<to>'. Note, more advanced revision selection can be applied.
        For a more complete list of ways to spell object names, see
-       "SPECIFYING REVISIONS" section in linkgit:git-rev-parse[1].
+       linkgit:gitrevisions[1].
 
 <path>...::
 
index 3cd32d6803874909d671a2d3f48c1d5701ce89cf..eb3d040783e8202f502d05e8b4dc4e3b39736779 100644 (file)
@@ -16,7 +16,7 @@ You may find these things in your git repository (`.git`
 directory for a repository associated with your working tree, or
 `<project>.git` directory for a public 'bare' repository. It is
 also possible to have a working tree where `.git` is a plain
-ascii file containing `gitdir: <path>`, i.e. the path to the
+ASCII file containing `gitdir: <path>`, i.e. the path to the
 real git repository).
 
 objects::
diff --git a/Documentation/gitrevisions.txt b/Documentation/gitrevisions.txt
new file mode 100644 (file)
index 0000000..fc4789f
--- /dev/null
@@ -0,0 +1,35 @@
+gitrevisions(7)
+================
+
+NAME
+----
+gitrevisions - specifying revisions and ranges for git
+
+SYNOPSIS
+--------
+gitrevisions
+
+
+DESCRIPTION
+-----------
+
+Many Git commands take revision parameters as arguments. Depending on
+the command, they denote a specific commit or, for commands which
+walk the revision graph (such as linkgit:git-log[1]), all commits which can
+be reached from that commit. In the latter case one can also specify a
+range of revisions explicitly.
+
+In addition, some Git commands (such as linkgit:git-show[1]) also take
+revision parameters which denote other objects than commits, e.g. blobs
+("files") or trees ("directories of files").
+
+include::revisions.txt[]
+
+
+SEE ALSO
+--------
+linkgit:git-rev-parse[1]
+
+GIT
+---
+Part of the linkgit:git[1] suite
index ff5c0bc27a416de16f106c15b9076082c6509e42..6fd711996a775d1da8ab2051db98896a601c8971 100644 (file)
@@ -229,7 +229,7 @@ reverting W.  Mainline's history would look like this:
    A---B---C
 
 But if you don't actually need to change commit A, then you need some way to
-recreate it as a new commit with the same changes in it.  The rebase commmand's
+recreate it as a new commit with the same changes in it.  The rebase command's
 --no-ff option provides a way to do this:
 
     $ git rebase [-i] --no-ff P
index 2135a8ee1f4f56a8c799437949ba76d7526164c0..34d02a24188921ebac1b70f7cf0c6517a45e8fb1 100755 (executable)
@@ -12,7 +12,7 @@ do
        then
                : did not match
        elif test -f "$T/$h" &&
-          diff -u -I'Last updated [0-9][0-9]-[A-Z][a-z][a-z]-' "$T/$h" "$h"
+          $DIFF -u -I'Last updated [0-9][0-9]-[A-Z][a-z][a-z]-' "$T/$h" "$h"
        then
                :; # up to date
        else
index c85a52c0cc27a187abbdea17cd25cec51b808064..561cc9f7d7ef1a2502d608e59e2eae345bffd685 100644 (file)
@@ -11,7 +11,12 @@ have limited your view of history: for example, if you are
 only interested in changes related to a certain directory or
 file.
 
-Here are some additional details for each format:
+There are several built-in formats, and you can define
+additional formats by setting a pretty.<name>
+config option to either another format name, or a
+'format:' string, as described below (see
+linkgit:git-config[1]). Here are the details of the
+built-in formats:
 
 * 'oneline'
 
@@ -123,6 +128,7 @@ The placeholders are:
 - '%s': subject
 - '%f': sanitized subject line, suitable for a filename
 - '%b': body
+- '%B': raw body (unwrapped subject and body)
 - '%N': commit notes
 - '%gD': reflog selector, e.g., `refs/stash@\{1\}`
 - '%gd': shortened reflog selector, e.g., `stash@\{1\}`
@@ -153,6 +159,10 @@ If you add a `-` (minus sign) after '%' of a placeholder, line-feeds that
 immediately precede the expansion are deleted if and only if the
 placeholder expands to an empty string.
 
+If you add a ` ` (space) after '%' of a placeholder, a space
+is inserted immediately before the expansion if and only if the
+placeholder expands to a non-empty string.
+
 * 'tformat:'
 +
 The 'tformat:' format works exactly like 'format:', except that it
index d78e121c76ef12b2d72fbdf1558fa967dfdba85b..9b6f3899ec28fb431c1f3969bf5bfb717c12f346 100644 (file)
@@ -1,5 +1,5 @@
 --pretty[='<format>']::
---format[='<format>']::
+--format='<format>'::
 
        Pretty-print the contents of the commit logs in a given format,
        where '<format>' can be one of 'oneline', 'short', 'medium',
index b9fb7a86bd4bf91205b77275fb51ff13a3bc5622..cc562a057af3694d3518bc91b52ae322b6b1d9cc 100644 (file)
@@ -98,6 +98,15 @@ you would get an output like this:
 This implies the '--topo-order' option by default, but the
 '--date-order' option may also be specified.
 
+ifdef::git-rev-list[]
+--count::
+       Print a number stating how many commits would have been
+       listed, and suppress all other output.  When used together
+       with '--left-right', instead print the counts for left and
+       right commits, separated by a tab.
+endif::git-rev-list[]
+
+
 ifndef::git-rev-list[]
 Diff Formatting
 ~~~~~~~~~~~~~~~
@@ -384,6 +393,14 @@ Default mode::
        merges from the resulting history, as there are no selected
        commits contributing to this merge.
 
+--ancestry-path::
+
+       When given a range of commits to display (e.g. 'commit1..commit2'
+       or 'commit2 {caret}commit1'), only display commits that exist
+       directly on the ancestry chain between the 'commit1' and
+       'commit2', i.e. commits that are both descendants of 'commit1',
+       and ancestors of 'commit2'.
+
 A more detailed explanation follows.
 
 Suppose you specified `foo` as the <paths>.  We shall call commits
@@ -440,7 +457,7 @@ This results in:
 +
 -----------------------------------------------------------------------
          .-A---N---O
-        /         /
+        /     /   /
        I---------D
 -----------------------------------------------------------------------
 +
@@ -511,8 +528,6 @@ Note that without '\--full-history', this still simplifies merges: if
 one of the parents is TREESAME, we follow only that one, so the other
 sides of the merge are never walked.
 
-Finally, there is a fourth simplification mode available:
-
 --simplify-merges::
 
        First, build a history graph in the same way that
@@ -554,6 +569,46 @@ Note the major differences in `N` and `P` over '\--full-history':
   removed completely, because it had one parent and is TREESAME.
 --
 
+Finally, there is a fifth simplification mode available:
+
+--ancestry-path::
+
+       Limit the displayed commits to those directly on the ancestry
+       chain between the "from" and "to" commits in the given commit
+       range. I.e. only display commits that are ancestor of the "to"
+       commit, and descendants of the "from" commit.
++
+As an example use case, consider the following commit history:
++
+-----------------------------------------------------------------------
+           D---E-------F
+          /     \       \
+         B---C---G---H---I---J
+        /                     \
+       A-------K---------------L--M
+-----------------------------------------------------------------------
++
+A regular 'D..M' computes the set of commits that are ancestors of `M`,
+but excludes the ones that are ancestors of `D`. This is useful to see
+what happened to the history leading to `M` since `D`, in the sense
+that "what does `M` have that did not exist in `D`". The result in this
+example would be all the commits, except `A` and `B` (and `D` itself,
+of course).
++
+When we want to find out what commits in `M` are contaminated with the
+bug introduced by `D` and need fixing, however, we might want to view
+only the subset of 'D..M' that are actually descendants of `D`, i.e.
+excluding `C` and `K`. This is exactly what the '\--ancestry-path'
+option does. Applied to the 'D..M' range, it results in:
++
+-----------------------------------------------------------------------
+               E-------F
+                \       \
+                 G---H---I---J
+                              \
+                               L--M
+-----------------------------------------------------------------------
+
 The '\--simplify-by-decoration' option allows you to view only the
 big picture of the topology of the history, by omitting commits
 that are not referenced by tags.  Commits are marked as !TREESAME
diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
new file mode 100644 (file)
index 0000000..fe846f0
--- /dev/null
@@ -0,0 +1,199 @@
+SPECIFYING REVISIONS
+--------------------
+
+A revision parameter typically, but not necessarily, names a
+commit object.  They use what is called an 'extended SHA1'
+syntax.  Here are various ways to spell object names.  The
+ones listed near the end of this list are to name trees and
+blobs contained in a commit.
+
+* The full SHA1 object name (40-byte hexadecimal string), or
+  a substring of such that is unique within the repository.
+  E.g. dae86e1950b1277e545cee180551750029cfe735 and dae86e both
+  name the same commit object if there are no other object in
+  your repository whose object name starts with dae86e.
+
+* An output from 'git describe'; i.e. a closest tag, optionally
+  followed by a dash and a number of commits, followed by a dash, a
+  `g`, and an abbreviated object name.
+
+* A symbolic ref name.  E.g. 'master' typically means the commit
+  object referenced by refs/heads/master.  If you
+  happen to have both heads/master and tags/master, you can
+  explicitly say 'heads/master' to tell git which one you mean.
+  When ambiguous, a `<name>` is disambiguated by taking the
+  first match in the following rules:
+
+  . if `$GIT_DIR/<name>` exists, that is what you mean (this is usually
+    useful only for `HEAD`, `FETCH_HEAD`, `ORIG_HEAD` and `MERGE_HEAD`);
+
+  . otherwise, `refs/<name>` if exists;
+
+  . otherwise, `refs/tags/<name>` if exists;
+
+  . otherwise, `refs/heads/<name>` if exists;
+
+  . otherwise, `refs/remotes/<name>` if exists;
+
+  . otherwise, `refs/remotes/<name>/HEAD` if exists.
++
+HEAD names the commit your changes in the working tree is based on.
+FETCH_HEAD records the branch you fetched from a remote repository
+with your last 'git fetch' invocation.
+ORIG_HEAD is created by commands that moves your HEAD in a drastic
+way, to record the position of the HEAD before their operation, so that
+you can change the tip of the branch back to the state before you ran
+them easily.
+MERGE_HEAD records the commit(s) you are merging into your branch
+when you run 'git merge'.
++
+Note that any of the `refs/*` cases above may come either from
+the `$GIT_DIR/refs` directory or from the `$GIT_DIR/packed-refs` file.
+
+* A ref followed by the suffix '@' with a date specification
+  enclosed in a brace
+  pair (e.g. '\{yesterday\}', '\{1 month 2 weeks 3 days 1 hour 1
+  second ago\}' or '\{1979-02-26 18:30:00\}') to specify the value
+  of the ref at a prior point in time.  This suffix may only be
+  used immediately following a ref name and the ref must have an
+  existing log ($GIT_DIR/logs/<ref>). Note that this looks up the state
+  of your *local* ref at a given time; e.g., what was in your local
+  `master` branch last week. If you want to look at commits made during
+  certain times, see `--since` and `--until`.
+
+* A ref followed by the suffix '@' with an ordinal specification
+  enclosed in a brace pair (e.g. '\{1\}', '\{15\}') to specify
+  the n-th prior value of that ref.  For example 'master@\{1\}'
+  is the immediate prior value of 'master' while 'master@\{5\}'
+  is the 5th prior value of 'master'. This suffix may only be used
+  immediately following a ref name and the ref must have an existing
+  log ($GIT_DIR/logs/<ref>).
+
+* You can use the '@' construct with an empty ref part to get at a
+  reflog of the current branch. For example, if you are on the
+  branch 'blabla', then '@\{1\}' means the same as 'blabla@\{1\}'.
+
+* The special construct '@\{-<n>\}' means the <n>th branch checked out
+  before the current one.
+
+* The suffix '@\{upstream\}' to a ref (short form 'ref@\{u\}') refers to
+  the branch the ref is set to build on top of.  Missing ref defaults
+  to the current branch.
+
+* A suffix '{caret}' to a revision parameter (e.g. 'HEAD{caret}') means the first parent of
+  that commit object.  '{caret}<n>' means the <n>th parent (i.e.
+  'rev{caret}'
+  is equivalent to 'rev{caret}1').  As a special rule,
+  'rev{caret}0' means the commit itself and is used when 'rev' is the
+  object name of a tag object that refers to a commit object.
+
+* A suffix '{tilde}<n>' to a revision parameter means the commit
+  object that is the <n>th generation grand-parent of the named
+  commit object, following only the first parent.  I.e. rev~3 is
+  equivalent to rev{caret}{caret}{caret} which is equivalent to
+  rev{caret}1{caret}1{caret}1.  See below for a illustration of
+  the usage of this form.
+
+* A suffix '{caret}' followed by an object type name enclosed in
+  brace pair (e.g. `v0.99.8{caret}\{commit\}`) means the object
+  could be a tag, and dereference the tag recursively until an
+  object of that type is found or the object cannot be
+  dereferenced anymore (in which case, barf).  `rev{caret}0`
+  introduced earlier is a short-hand for `rev{caret}\{commit\}`.
+
+* A suffix '{caret}' followed by an empty brace pair
+  (e.g. `v0.99.8{caret}\{\}`) means the object could be a tag,
+  and dereference the tag recursively until a non-tag object is
+  found.
+
+* A colon, followed by a slash, followed by a text (e.g. `:/fix nasty bug`): this names
+  a commit whose commit message starts with the specified text.
+  This name returns the youngest matching commit which is
+  reachable from any ref.  If the commit message starts with a
+  '!', you have to repeat that;  the special sequence ':/!',
+  followed by something else than '!' is reserved for now.
+
+* A suffix ':' followed by a path (e.g. `HEAD:README`); this names the blob or tree
+  at the given path in the tree-ish object named by the part
+  before the colon.
+  ':path' (with an empty part before the colon, e.g. `:README`)
+  is a special case of the syntax described next: content
+  recorded in the index at the given path.
+
+* A colon, optionally followed by a stage number (0 to 3) and a
+  colon, followed by a path (e.g. `:0:README`); this names a blob object in the
+  index at the given path. Missing stage number (and the colon
+  that follows it, e.g. `:README`) names a stage 0 entry. During a merge, stage
+  1 is the common ancestor, stage 2 is the target branch's version
+  (typically the current branch), and stage 3 is the version from
+  the branch being merged.
+
+Here is an illustration, by Jon Loeliger.  Both commit nodes B
+and C are parents of commit node A.  Parent commits are ordered
+left-to-right.
+
+........................................
+G   H   I   J
+ \ /     \ /
+  D   E   F
+   \  |  / \
+    \ | /   |
+     \|/    |
+      B     C
+       \   /
+        \ /
+         A
+........................................
+
+    A =      = A^0
+    B = A^   = A^1     = A~1
+    C = A^2  = A^2
+    D = A^^  = A^1^1   = A~2
+    E = B^2  = A^^2
+    F = B^3  = A^^3
+    G = A^^^ = A^1^1^1 = A~3
+    H = D^2  = B^^2    = A^^^2  = A~2^2
+    I = F^   = B^3^    = A^^3^
+    J = F^2  = B^3^2   = A^^3^2
+
+
+SPECIFYING RANGES
+-----------------
+
+History traversing commands such as 'git log' operate on a set
+of commits, not just a single commit.  To these commands,
+specifying a single revision with the notation described in the
+previous section means the set of commits reachable from that
+commit, following the commit ancestry chain.
+
+To exclude commits reachable from a commit, a prefix `{caret}`
+notation is used.  E.g. `{caret}r1 r2` means commits reachable
+from `r2` but exclude the ones reachable from `r1`.
+
+This set operation appears so often that there is a shorthand
+for it.  When you have two commits `r1` and `r2` (named according
+to the syntax explained in SPECIFYING REVISIONS above), you can ask
+for commits that are reachable from r2 excluding those that are reachable
+from r1 by `{caret}r1 r2` and it can be written as `r1..r2`.
+
+A similar notation `r1\...r2` is called symmetric difference
+of `r1` and `r2` and is defined as
+`r1 r2 --not $(git merge-base --all r1 r2)`.
+It is the set of commits that are reachable from either one of
+`r1` or `r2` but not from both.
+
+Two other shorthands for naming a set that is formed by a commit
+and its parent commits exist.  The `r1{caret}@` notation means all
+parents of `r1`.  `r1{caret}!` includes commit `r1` but excludes
+all of its parents.
+
+Here are a handful of examples:
+
+   D                G H D
+   D F              G H I J D F
+   ^G D             H D
+   ^D B             E I J F B
+   B...C            G H D E B C
+   ^D B C           E I J F B C
+   C^@              I J F
+   F^! D            G H D F
index 44876fa703578f4952d6e928993e15ddec70439c..f18b4f4817448530a5adbe2c8835bb7791add42a 100644 (file)
@@ -231,8 +231,9 @@ The function pointer in .proc has the following signature:
 
 
 There are serious restrictions on what the asynchronous function can do
-because this facility is implemented by a pipe to a forked process on
-UNIX, but by a thread in the same address space on Windows:
+because this facility is implemented by a thread in the same address
+space on most platforms (when pthreads is available), but by a pipe to
+a forked process otherwise:
 
 . It cannot change the program's state (global variables, environment,
   etc.) in a way that the caller notices; in other words, .in and .out
index 6d8c24bb1e68e86d70d4a68d02e3a4d5ccb94c2a..3f575bdcff3a6b38304710b22371784c2e7443c9 100644 (file)
@@ -38,8 +38,8 @@ struct string_list list;
 int i;
 
 memset(&list, 0, sizeof(struct string_list));
-string_list_append("foo", &list);
-string_list_append("bar", &list);
+string_list_append(&list, "foo");
+string_list_append(&list, "bar");
 for (i = 0; i < list.nr; i++)
        printf("%s\n", list.items[i].string)
 ----
index 1dcd1e7f1ede3382ae992a266f5437fe06f8dc75..289019478d16719e5d2c86b7a17017005bd9a80d 100644 (file)
@@ -25,7 +25,7 @@ The ssh and git protocols additionally support ~username expansion:
 - git://host.xz{startsb}:port{endsb}/~{startsb}user{endsb}/path/to/repo.git/
 - {startsb}user@{endsb}host.xz:/~{startsb}user{endsb}/path/to/repo.git/
 
-For local respositories, also supported by git natively, the following
+For local repositories, also supported by git natively, the following
 syntaxes may be used:
 
 - /path/to/repo.git/
index fe6fb722da1a5c288c7ae3757622aac8cac79a73..22aee34d4a49b242370e5244f35d542ad0b79391 100644 (file)
@@ -397,7 +397,7 @@ is usually a shortcut for the HEAD branch in the repository "origin".
 For the complete list of paths which git checks for references, and
 the order it uses to decide which to choose when there are multiple
 references with the same shorthand name, see the "SPECIFYING
-REVISIONS" section of linkgit:git-rev-parse[1].
+REVISIONS" section of linkgit:gitrevisions[1].
 
 [[Updating-a-repository-With-git-fetch]]
 Updating a repository with git fetch
@@ -568,7 +568,7 @@ We have seen several ways of naming commits already:
        - HEAD: refers to the head of the current branch
 
 There are many more; see the "SPECIFYING REVISIONS" section of the
-linkgit:git-rev-parse[1] man page for the complete list of ways to
+linkgit:gitrevisions[1] man page for the complete list of ways to
 name revisions.  Some examples:
 
 -------------------------------------------------
@@ -909,7 +909,7 @@ commits reachable from some head but not from any tag in the repository:
 $ gitk $( git show-ref --heads ) --not  $( git show-ref --tags )
 -------------------------------------------------
 
-(See linkgit:git-rev-parse[1] for explanations of commit-selecting
+(See linkgit:gitrevisions[1] for explanations of commit-selecting
 syntax such as `--not`.)
 
 [[making-a-release]]
@@ -1635,7 +1635,7 @@ you've checked out.
 The reflogs are kept by default for 30 days, after which they may be
 pruned.  See linkgit:git-reflog[1] and linkgit:git-gc[1] to learn
 how to control this pruning, and see the "SPECIFYING REVISIONS"
-section of linkgit:git-rev-parse[1] for details.
+section of linkgit:gitrevisions[1] for details.
 
 Note that the reflog history is very different from normal git history.
 While normal history is shared by every repository that works on the
index 5e8077ebf47ebf749adbc63ee550028fb74d5378..ec4c49a90daacc11072f8285e5879378156c22a8 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v1.7.1.4
+DEF_VER=v1.7.2.5
 
 LF='
 '
diff --git a/INSTALL b/INSTALL
index 61086ab1204a4304cb1d84eeea9d1649878ac9e1..59200b730ec00a63f981691f7fd37f2eacb11653 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -157,3 +157,36 @@ Issues of note:
    It has been reported that docbook-xsl version 1.72 and 1.73 are
    buggy; 1.72 misformats manual pages for callouts, and 1.73 needs
    the patch in contrib/patches/docbook-xsl-manpages-charmap.patch
+
+   Users attempting to build the documentation on Cygwin may need to ensure
+   that the /etc/xml/catalog file looks something like this:
+
+   <?xml version="1.0"?>
+   <!DOCTYPE catalog PUBLIC
+      "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
+      "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"
+   >
+   <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
+     <rewriteURI
+       uriStartString = "http://docbook.sourceforge.net/release/xsl/current"
+       rewritePrefix = "/usr/share/sgml/docbook/xsl-stylesheets"
+     />
+     <rewriteURI
+       uriStartString="http://www.oasis-open.org/docbook/xml/4.5"
+       rewritePrefix="/usr/share/sgml/docbook/xml-dtd-4.5"
+     />
+  </catalog>
+
+  This can be achieved with the following two xmlcatalog commands:
+
+  xmlcatalog --noout \
+     --add rewriteURI \
+        http://docbook.sourceforge.net/release/xsl/current \
+        /usr/share/sgml/docbook/xsl-stylesheets \
+     /etc/xml/catalog
+
+  xmlcatalog --noout \
+     --add rewriteURI \
+         http://www.oasis-open.org/docbook/xml/4.5/xsl/current \
+         /usr/share/sgml/docbook/xml-dtd-4.5 \
+     /etc/xml/catalog
index b18768e0aedfbf246173293f74049456070deec3..38d3bf28595ff297d88260ebb535c35a21d0e22b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,12 @@ all::
 # Define SANE_TOOL_PATH to a colon-separated list of paths to prepend
 # to PATH if your tools in /usr/bin are broken.
 #
+# Define SOCKLEN_T to a suitable type (such as 'size_t') if your
+# system headers do not define a socklen_t type.
+#
+# Define INLINE to a suitable substitute (such as '__inline' or '') if git
+# fails to compile with errors about undefined inline functions or similar.
+#
 # Define SNPRINTF_RETURNS_BOGUS if your are on a system which snprintf()
 # or vsnprintf() return -1 instead of number of characters which would
 # have been written to the final string if enough space had been available.
@@ -227,6 +233,8 @@ all::
 #
 # Define CHECK_HEADER_DEPENDENCIES to check for problems in the hard-coded
 # dependency rules.
+#
+# Define NATIVE_CRLF if your platform uses CRLF for line endings.
 
 GIT-VERSION-FILE: FORCE
        @$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -249,7 +257,7 @@ endif
 
 CFLAGS = -g -O2 -Wall
 LDFLAGS =
-ALL_CFLAGS = $(CFLAGS)
+ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
 STRIP ?= strip
 
@@ -272,6 +280,7 @@ mandir = share/man
 infodir = share/info
 gitexecdir = libexec/git-core
 sharedir = $(prefix)/share
+gitwebdir = $(sharedir)/gitweb
 template_dir = share/git-core/templates
 htmldir = share/doc/git-doc
 ifeq ($(prefix),/usr)
@@ -285,11 +294,12 @@ lib = lib
 # DESTDIR=
 pathsep = :
 
-export prefix bindir sharedir sysconfdir
+export prefix bindir sharedir sysconfdir gitwebdir
 
 CC = gcc
 AR = ar
 RM = rm -f
+DIFF = diff
 TAR = tar
 FIND = find
 INSTALL = install
@@ -297,6 +307,7 @@ RPMBUILD = rpmbuild
 TCL_PATH = tclsh
 TCLTK_PATH = wish
 PTHREAD_LIBS = -lpthread
+PTHREAD_CFLAGS =
 
 export TCL_PATH TCLTK_PATH
 
@@ -369,6 +380,8 @@ SCRIPT_PERL += git-relink.perl
 SCRIPT_PERL += git-send-email.perl
 SCRIPT_PERL += git-svn.perl
 
+SCRIPT_PYTHON += git-remote-testgit.py
+
 SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
          $(patsubst %.perl,%,$(SCRIPT_PERL)) \
          $(patsubst %.py,%,$(SCRIPT_PYTHON)) \
@@ -489,6 +502,7 @@ LIB_H += log-tree.h
 LIB_H += mailmap.h
 LIB_H += merge-recursive.h
 LIB_H += notes.h
+LIB_H += notes-cache.h
 LIB_H += object.h
 LIB_H += pack.h
 LIB_H += pack-refs.h
@@ -578,6 +592,7 @@ LIB_OBJS += merge-file.o
 LIB_OBJS += merge-recursive.o
 LIB_OBJS += name-hash.o
 LIB_OBJS += notes.o
+LIB_OBJS += notes-cache.o
 LIB_OBJS += object.o
 LIB_OBJS += pack-check.o
 LIB_OBJS += pack-refs.o
@@ -623,6 +638,7 @@ LIB_OBJS += tree-diff.o
 LIB_OBJS += tree.o
 LIB_OBJS += tree-walk.o
 LIB_OBJS += unpack-trees.o
+LIB_OBJS += url.o
 LIB_OBJS += usage.o
 LIB_OBJS += userdiff.o
 LIB_OBJS += utf8.o
@@ -735,6 +751,13 @@ EXTLIBS =
 # because maintaining the nesting to match is a pain.  If
 # we had "elif" things would have been much nicer...
 
+ifeq ($(uname_S),OSF1)
+       # Need this for u_short definitions et al
+       BASIC_CFLAGS += -D_OSF_SOURCE
+       SOCKLEN_T = int
+       NO_STRTOULL = YesPlease
+       NO_NSEC = YesPlease
+endif
 ifeq ($(uname_S),Linux)
        NO_STRLCPY = YesPlease
        NO_MKSTEMPS = YesPlease
@@ -809,6 +832,18 @@ ifeq ($(uname_S),SunOS)
        NO_MKDTEMP = YesPlease
        NO_MKSTEMPS = YesPlease
        NO_REGEX = YesPlease
+       ifeq ($(uname_R),5.6)
+               SOCKLEN_T = int
+               NO_HSTRERROR = YesPlease
+               NO_IPV6 = YesPlease
+               NO_SOCKADDR_STORAGE = YesPlease
+               NO_UNSETENV = YesPlease
+               NO_SETENV = YesPlease
+               NO_STRLCPY = YesPlease
+               NO_C99_FORMAT = YesPlease
+               NO_STRTOUMAX = YesPlease
+               GIT_TEST_CMP = cmp
+       endif
        ifeq ($(uname_R),5.7)
                NEEDS_RESOLV = YesPlease
                NO_IPV6 = YesPlease
@@ -818,18 +853,21 @@ ifeq ($(uname_S),SunOS)
                NO_STRLCPY = YesPlease
                NO_C99_FORMAT = YesPlease
                NO_STRTOUMAX = YesPlease
+               GIT_TEST_CMP = cmp
        endif
        ifeq ($(uname_R),5.8)
                NO_UNSETENV = YesPlease
                NO_SETENV = YesPlease
                NO_C99_FORMAT = YesPlease
                NO_STRTOUMAX = YesPlease
+               GIT_TEST_CMP = cmp
        endif
        ifeq ($(uname_R),5.9)
                NO_UNSETENV = YesPlease
                NO_SETENV = YesPlease
                NO_C99_FORMAT = YesPlease
                NO_STRTOUMAX = YesPlease
+               GIT_TEST_CMP = cmp
        endif
        INSTALL = /usr/ucb/install
        TAR = gtar
@@ -907,7 +945,13 @@ ifeq ($(uname_S),AIX)
        BASIC_CFLAGS += -D_LARGE_FILES
        ifeq ($(shell expr "$(uname_V)" : '[1234]'),1)
                NO_PTHREADS = YesPlease
+       else
+               PTHREAD_LIBS = -lpthread
+       endif
+       ifeq ($(shell expr "$(uname_V).$(uname_R)" : '5\.1'),3)
+               INLINE=''
        endif
+       GIT_TEST_CMP = cmp
 endif
 ifeq ($(uname_S),GNU)
        # GNU/Hurd
@@ -952,6 +996,7 @@ ifeq ($(uname_S),IRIX64)
        NEEDS_LIBGEN = YesPlease
 endif
 ifeq ($(uname_S),HP-UX)
+       INLINE = __inline
        NO_IPV6=YesPlease
        NO_SETENV=YesPlease
        NO_STRCASESTR=YesPlease
@@ -963,6 +1008,20 @@ ifeq ($(uname_S),HP-UX)
        NO_HSTRERROR = YesPlease
        NO_SYS_SELECT_H = YesPlease
        SNPRINTF_RETURNS_BOGUS = YesPlease
+       NO_NSEC = YesPlease
+       ifeq ($(uname_R),B.11.00)
+               NO_INET_NTOP = YesPlease
+               NO_INET_PTON = YesPlease
+       endif
+       ifeq ($(uname_R),B.10.20)
+               # Override HP-UX 11.x setting:
+               INLINE =
+               SOCKLEN_T = size_t
+               NO_PREAD = YesPlease
+               NO_INET_NTOP = YesPlease
+               NO_INET_PTON = YesPlease
+       endif
+       GIT_TEST_CMP = cmp
 endif
 ifeq ($(uname_S),Windows)
        GIT_VERSION := $(GIT_VERSION).MSVC
@@ -999,6 +1058,7 @@ ifeq ($(uname_S),Windows)
        NO_CURL = YesPlease
        NO_PYTHON = YesPlease
        BLK_SHA1 = YesPlease
+       NATIVE_CRLF = YesPlease
 
        CC = compat/vcbuild/scripts/clink.pl
        AR = compat/vcbuild/scripts/lib.pl
@@ -1036,7 +1096,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
        NO_STRTOUMAX = YesPlease
        NO_MKDTEMP = YesPlease
        NO_MKSTEMPS = YesPlease
-       SNPRINTF_RETURNS_BOGUS = YesPlease
        NO_SVN_TESTS = YesPlease
        NO_PERL_MAKEMAKER = YesPlease
        RUNTIME_PREFIX = YesPlease
@@ -1073,6 +1132,7 @@ endif
 -include config.mak
 
 ifdef CHECK_HEADER_DEPENDENCIES
+COMPUTE_HEADER_DEPENDENCIES =
 USE_COMPUTED_HEADER_DEPENDENCIES =
 endif
 
@@ -1088,6 +1148,14 @@ else
 BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
 endif
 
+ifneq (,$(INLINE))
+       BASIC_CFLAGS += -Dinline=$(INLINE)
+endif
+
+ifneq (,$(SOCKLEN_T))
+       BASIC_CFLAGS += -Dsocklen_t=$(SOCKLEN_T)
+endif
+
 ifeq ($(uname_S),Darwin)
        ifndef NO_FINK
                ifeq ($(shell test -d /sw/lib && echo y),y)
@@ -1359,6 +1427,7 @@ endif
 ifdef NO_PTHREADS
        BASIC_CFLAGS += -DNO_PTHREADS
 else
+       BASIC_CFLAGS += $(PTHREAD_CFLAGS)
        EXTLIBS += $(PTHREAD_LIBS)
        LIB_OBJS += thread-utils.o
 endif
@@ -1379,10 +1448,14 @@ ifdef NO_REGEX
 endif
 
 ifdef USE_NED_ALLOCATOR
-       COMPAT_CFLAGS += -DUSE_NED_ALLOCATOR -DOVERRIDE_STRDUP -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR -Icompat/nedmalloc
+       COMPAT_CFLAGS += -Icompat/nedmalloc
        COMPAT_OBJS += compat/nedmalloc/nedmalloc.o
 endif
 
+ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
+       export GIT_TEST_CMP_USE_COPIED_CONTEXT
+endif
+
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK=NoThanks
 endif
@@ -1439,11 +1512,13 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
 template_dir_SQ = $(subst ','\'',$(template_dir))
 htmldir_SQ = $(subst ','\'',$(htmldir))
 prefix_SQ = $(subst ','\'',$(prefix))
+gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
 
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
 TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
+DIFF_SQ = $(subst ','\'',$(DIFF))
 
 LIBS = $(GITLIBS) $(EXTLIBS)
 
@@ -1470,7 +1545,7 @@ endif
 ALL_CFLAGS += $(BASIC_CFLAGS)
 ALL_LDFLAGS += $(BASIC_LDFLAGS)
 
-export TAR INSTALL DESTDIR SHELL_PATH
+export DIFF TAR INSTALL DESTDIR SHELL_PATH
 
 
 ### Build rules
@@ -1532,6 +1607,7 @@ define cmd_munge_script
 $(RM) $@ $@+ && \
 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
     -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
+    -e 's|@@DIFF@@|$(DIFF_SQ)|' \
     -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
     -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
     -e $(BROKEN_PATH_FIX) \
@@ -1559,11 +1635,10 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl
        sed -e '1{' \
            -e '        s|#!.*perl|#!$(PERL_PATH_SQ)|' \
            -e '        h' \
-           -e '        s=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "@@INSTLIBDIR@@"));=' \
+           -e '        s=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \
            -e '        H' \
            -e '        x' \
            -e '}' \
-           -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \
            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
            $@.perl >$@+ && \
        chmod +x $@+ && \
@@ -1575,45 +1650,38 @@ gitweb:
        $(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) all
 
 ifdef JSMIN
-GITWEB_PROGRAMS += gitweb/gitweb.min.js
-GITWEB_JS = gitweb/gitweb.min.js
+GITWEB_PROGRAMS += gitweb/static/gitweb.min.js
+GITWEB_JS = gitweb/static/gitweb.min.js
 else
-GITWEB_JS = gitweb/gitweb.js
+GITWEB_JS = gitweb/static/gitweb.js
 endif
 ifdef CSSMIN
-GITWEB_PROGRAMS += gitweb/gitweb.min.css
-GITWEB_CSS = gitweb/gitweb.min.css
+GITWEB_PROGRAMS += gitweb/static/gitweb.min.css
+GITWEB_CSS = gitweb/static/gitweb.min.css
 else
-GITWEB_CSS = gitweb/gitweb.css
+GITWEB_CSS = gitweb/static/gitweb.css
 endif
 OTHER_PROGRAMS +=  gitweb/gitweb.cgi  $(GITWEB_PROGRAMS)
 gitweb/gitweb.cgi: gitweb/gitweb.perl $(GITWEB_PROGRAMS)
        $(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)
 
 ifdef JSMIN
-gitweb/gitweb.min.js: gitweb/gitweb.js
+gitweb/static/gitweb.min.js: gitweb/static/gitweb.js
        $(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)
 endif # JSMIN
 ifdef CSSMIN
-gitweb/gitweb.min.css: gitweb/gitweb.css
+gitweb/static/gitweb.min.css: gitweb/static/gitweb.css
        $(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)
 endif # CSSMIN
 
 
-git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css gitweb/gitweb.js
+git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/static/gitweb.css gitweb/static/gitweb.js
        $(QUIET_GEN)$(RM) $@ $@+ && \
        sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
            -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
-           -e '/@@GITWEB_CGI@@/r gitweb/gitweb.cgi' \
-           -e '/@@GITWEB_CGI@@/d' \
-           -e '/@@GITWEB_CSS@@/r $(GITWEB_CSS)' \
-           -e '/@@GITWEB_CSS@@/d' \
-           -e '/@@GITWEB_JS@@/r $(GITWEB_JS)' \
-           -e '/@@GITWEB_JS@@/d' \
+           -e 's|@@GITWEBDIR@@|$(gitwebdir_SQ)|g' \
            -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
-            -e 's|@@GITWEB_CSS_NAME@@|$(GITWEB_CSS)|' \
-            -e 's|@@GITWEB_JS_NAME@@|$(GITWEB_JS)|' \
            $@.sh > $@+ && \
        chmod +x $@+ && \
        mv $@+ $@
@@ -1634,13 +1702,8 @@ $(patsubst %.py,%,$(SCRIPT_PYTHON)): % : %.py
        INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C git_remote_helpers -s \
                --no-print-directory prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' \
                instlibdir` && \
-       sed -e '1{' \
-           -e '        s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
-           -e '}' \
-           -e 's|^import sys.*|&; \\\
-                  import os; \\\
-                  sys.path.insert(0, os.getenv("GITPYTHONLIB",\
-                                               "@@INSTLIBDIR@@"));|' \
+       sed -e '1s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
+           -e 's|\(os\.getenv("GITPYTHONLIB"\)[^)]*)|\1,"@@INSTLIBDIR@@")|' \
            -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \
            $@.py >$@+ && \
        chmod +x $@+ && \
@@ -1670,7 +1733,10 @@ git.o git.spec \
 
 TEST_OBJS := $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS))
 GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \
-       git.o http.o http-walker.o remote-curl.o
+       git.o
+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
 OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS)
@@ -1788,8 +1854,9 @@ builtin/prune.o builtin/reflog.o reachable.o: reachable.h
 builtin/commit.o builtin/revert.o wt-status.o: wt-status.h
 builtin/tar-tree.o archive-tar.o: tar.h
 builtin/pack-objects.o: thread-utils.h
+connect.o transport.o http-backend.o: url.h
 http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
-http.o http-walker.o http-push.o remote-curl.o: http.h
+http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h
 
 xdiff-interface.o $(XDIFF_OBJS): \
        xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \
@@ -1812,6 +1879,11 @@ ifdef NO_EXPAT
 http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
 endif
 
+ifdef USE_NED_ALLOCATOR
+compat/nedmalloc/nedmalloc.o: EXTRA_CPPFLAGS = \
+       -DNDEBUG -DOVERRIDE_STRDUP -DREPLACE_SYSTEM_ALLOCATOR
+endif
+
 git-%$X: %.o $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 
@@ -1887,10 +1959,18 @@ GIT-CFLAGS: FORCE
 GIT-BUILD-OPTIONS: FORCE
        @echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@
        @echo PERL_PATH=\''$(subst ','\'',$(PERL_PATH_SQ))'\' >>$@
+       @echo DIFF=\''$(subst ','\'',$(subst ','\'',$(DIFF)))'\' >>$@
+       @echo PYTHON_PATH=\''$(subst ','\'',$(PYTHON_PATH_SQ))'\' >>$@
        @echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@
        @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@
        @echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@
        @echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@
+ifdef GIT_TEST_CMP
+       @echo GIT_TEST_CMP=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_CMP)))'\' >>$@
+endif
+ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
+       @echo GIT_TEST_CMP_USE_COPIED_CONTEXT=YesPlease >>$@
+endif
 
 ### Detect Tck/Tk interpreter path changes
 ifndef NO_TCLTK
@@ -1985,6 +2065,7 @@ install: all
        $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
 ifndef NO_PERL
        $(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
+       $(MAKE) -C gitweb install
 endif
 ifndef NO_PYTHON
        $(MAKE) -C git_remote_helpers prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
@@ -2000,25 +2081,37 @@ endif
        bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
        execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
        { test "$$bindir/" = "$$execdir/" || \
-               { $(RM) "$$execdir/git$X" && \
+         for p in git$X $(filter $(install_bindir_programs),$(ALL_PROGRAMS)); do \
+               $(RM) "$$execdir/$$p" && \
                test -z "$(NO_CROSS_DIRECTORY_HARDLINKS)" && \
-               ln "$$bindir/git$X" "$$execdir/git$X" 2>/dev/null || \
-               cp "$$bindir/git$X" "$$execdir/git$X"; } ; } && \
-       { for p in $(BUILT_INS); do \
+               ln "$$bindir/$$p" "$$execdir/$$p" 2>/dev/null || \
+               cp "$$bindir/$$p" "$$execdir/$$p" || exit; \
+         done; \
+       } && \
+       for p in $(filter $(install_bindir_programs),$(BUILT_INS)); do \
+               $(RM) "$$bindir/$$p" && \
+               ln "$$bindir/git$X" "$$bindir/$$p" 2>/dev/null || \
+               ln -s "git$X" "$$bindir/$$p" 2>/dev/null || \
+               cp "$$bindir/git$X" "$$bindir/$$p" || exit; \
+       done && \
+       for p in $(BUILT_INS); do \
                $(RM) "$$execdir/$$p" && \
                ln "$$execdir/git$X" "$$execdir/$$p" 2>/dev/null || \
                ln -s "git$X" "$$execdir/$$p" 2>/dev/null || \
                cp "$$execdir/git$X" "$$execdir/$$p" || exit; \
-         done; } && \
-       { test x"$(REMOTE_CURL_ALIASES)" = x || \
-               { for p in $(REMOTE_CURL_ALIASES); do \
+       done && \
+       remote_curl_aliases="$(REMOTE_CURL_ALIASES)" && \
+       for p in $$remote_curl_aliases; do \
                $(RM) "$$execdir/$$p" && \
                ln "$$execdir/git-remote-http$X" "$$execdir/$$p" 2>/dev/null || \
                ln -s "git-remote-http$X" "$$execdir/$$p" 2>/dev/null || \
                cp "$$execdir/git-remote-http$X" "$$execdir/$$p" || exit; \
-         done; } ; } && \
+       done && \
        ./check_bindir "z$$bindir" "z$$execdir" "$$bindir/git-add$X"
 
+install-gitweb:
+       $(MAKE) -C gitweb install
+
 install-doc:
        $(MAKE) -C Documentation install
 
@@ -2176,6 +2269,7 @@ check-docs::
                documented,gitglossary | \
                documented,githooks | \
                documented,gitrepository-layout | \
+               documented,gitrevisions | \
                documented,gittutorial | \
                documented,gittutorial-2 | \
                documented,git-bisect-lk2009 | \
index 86af99bd3774d6e35785c12725e1134da023a223..17d37af54951e3179282cad837ee0beb271eb4e9 120000 (symlink)
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/1.7.1.4.txt
\ No newline at end of file
+Documentation/RelNotes/1.7.2.5.txt
\ No newline at end of file
diff --git a/aclocal.m4 b/aclocal.m4
new file mode 100644 (file)
index 0000000..d399de2
--- /dev/null
@@ -0,0 +1,40 @@
+dnl Check for socklen_t: historically on BSD it is an int, and in
+dnl POSIX 1g it is a type of its own, but some platforms use different
+dnl types for the argument to getsockopt, getpeername, etc.  So we
+dnl have to test to find something that will work.
+AC_DEFUN([TYPE_SOCKLEN_T],
+[
+   AC_CHECK_TYPE([socklen_t], ,[
+      AC_MSG_CHECKING([for socklen_t equivalent])
+      AC_CACHE_VAL([git_cv_socklen_t_equiv],
+      [
+         # Systems have either "struct sockaddr *" or
+         # "void *" as the second argument to getpeername
+         git_cv_socklen_t_equiv=
+         for arg2 in "struct sockaddr" void; do
+            for t in int size_t unsigned long "unsigned long"; do
+               AC_TRY_COMPILE([
+                  #include <sys/types.h>
+                  #include <sys/socket.h>
+
+                  int getpeername (int, $arg2 *, $t *);
+               ],[
+                  $t len;
+                  getpeername(0,0,&len);
+               ],[
+                  git_cv_socklen_t_equiv="$t"
+                  break 2
+               ])
+            done
+         done
+
+         if test "x$git_cv_socklen_t_equiv" = x; then
+            AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
+         fi
+      ])
+      AC_MSG_RESULT($git_cv_socklen_t_equiv)
+      AC_DEFINE_UNQUOTED(socklen_t, $git_cv_socklen_t_equiv,
+                       [type to use in place of socklen_t if not defined])],
+      [#include <sys/types.h>
+#include <sys/socket.h>])
+])
index d700af3b62f35091f9c628a5a2c0d8449e2fe439..edd68534fa847ad839fe8554e6864b39de4fcde0 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -33,6 +33,7 @@ static void format_subst(const struct commit *commit,
        struct strbuf fmt = STRBUF_INIT;
        struct pretty_print_context ctx = {0};
        ctx.date_mode = DATE_NORMAL;
+       ctx.abbrev = DEFAULT_ABBREV;
 
        if (src == buf->buf)
                to_free = strbuf_detach(buf, NULL);
diff --git a/attr.c b/attr.c
index 7467baf2d6c81f94a7d043dcde13d463b3b46272..8ba606c933088e27ac08aabb546b764745f8187e 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -287,7 +287,7 @@ static void free_attr_elem(struct attr_stack *e)
 }
 
 static const char *builtin_attr[] = {
-       "[attr]binary -diff -crlf",
+       "[attr]binary -diff -text",
        NULL,
 };
 
diff --git a/attr.h b/attr.h
index 450f49d648a013ffddc6321b7fd79b3fc1b66f7a..8b3f19be67f17c1fbf6edb37ac3ea27002ca6415 100644 (file)
--- a/attr.h
+++ b/attr.h
@@ -34,7 +34,7 @@ int git_checkattr(const char *path, int, struct git_attr_check *);
 enum git_attr_direction {
        GIT_ATTR_CHECKIN,
        GIT_ATTR_CHECKOUT,
-       GIT_ATTR_INDEX,
+       GIT_ATTR_INDEX
 };
 void git_attr_set_direction(enum git_attr_direction, struct index_state *);
 
index e459feebbf90c6557dbf3ff913f83a57a8afb210..781b5754f0e533008694e71ac7cfe2e52b2d0ac6 100644 (file)
--- a/base85.c
+++ b/base85.c
@@ -7,9 +7,9 @@
 #define say1(a,b) fprintf(stderr, a, b)
 #define say2(a,b,c) fprintf(stderr, a, b, c)
 #else
-#define say(a) do {} while(0)
-#define say1(a,b) do {} while(0)
-#define say2(a,b,c) do {} while(0)
+#define say(a) do { /* nothing */ } while (0)
+#define say1(a,b) do { /* nothing */ } while (0)
+#define say2(a,b,c) do { /* nothing */ } while (0)
 #endif
 
 static const char en85[] = {
index d880a5336ecbee175162a86a3336a783c79b0eb0..c0054a0b0a441090184a141ee73954a94a2904d5 100644 (file)
@@ -70,6 +70,7 @@
  */
 
 #if defined(__i386__) || defined(__x86_64__) || \
+    defined(_M_IX86) || defined(_M_X64) || \
     defined(__ppc__) || defined(__ppc64__) || \
     defined(__powerpc__) || defined(__powerpc64__) || \
     defined(__s390__) || defined(__s390x__)
index fdae0279ef3e4ba4d6b03f651d19e772a239ddc0..ed6ee26933430e1db4e29e62badfaf0b217935ad 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -17,9 +17,6 @@ extern void prune_packed_objects(int);
 extern int fmt_merge_msg(int merge_summary, struct strbuf *in,
        struct strbuf *out);
 extern int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out);
-extern int commit_tree(const char *msg, unsigned char *tree,
-               struct commit_list *parents, unsigned char *ret,
-               const char *author);
 extern int commit_notes(struct notes_tree *t, const char *msg);
 
 struct notes_rewrite_cfg {
@@ -40,6 +37,8 @@ void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);
 
 extern int check_pager_config(const char *cmd);
 
+extern int textconv_object(const char *path, const unsigned char *sha1, char **buf, unsigned long *buf_size);
+
 extern int cmd_add(int argc, const char **argv, const char *prefix);
 extern int cmd_annotate(int argc, const char **argv, const char *prefix);
 extern int cmd_apply(int argc, const char **argv, const char *prefix);
index 51eeabad867ee1e271d07d41dcb031e2c98cbf9f..3a5fca51590db53747f8712f733aa01e5840d8fb 100644 (file)
@@ -261,12 +261,14 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
 {
        char *file = xstrdup(git_path("ADD_EDIT.patch"));
        const char *apply_argv[] = { "apply", "--recount", "--cached",
-               file, NULL };
+               NULL, NULL };
        struct child_process child;
        struct rev_info rev;
        int out;
        struct stat st;
 
+       apply_argv[3] = file;
+
        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
 
        if (read_cache() < 0)
@@ -308,7 +310,7 @@ static const char ignore_error[] =
 "The following paths are ignored by one of your .gitignore files:\n";
 
 static int verbose = 0, show_only = 0, ignored_too = 0, refresh_only = 0;
-static int ignore_add_errors, addremove, intent_to_add;
+static int ignore_add_errors, addremove, intent_to_add, ignore_missing = 0;
 
 static struct option builtin_add_options[] = {
        OPT__DRY_RUN(&show_only),
@@ -323,6 +325,7 @@ static struct option builtin_add_options[] = {
        OPT_BOOLEAN('A', "all", &addremove, "add all, noticing removal of tracked files"),
        OPT_BOOLEAN( 0 , "refresh", &refresh_only, "don't add, only refresh the index"),
        OPT_BOOLEAN( 0 , "ignore-errors", &ignore_add_errors, "just skip files which cannot be added because of errors"),
+       OPT_BOOLEAN( 0 , "ignore-missing", &ignore_missing, "check if - even missing - files are ignored in dry run"),
        OPT_END(),
 };
 
@@ -384,6 +387,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 
        if (addremove && take_worktree_changes)
                die("-A and -u are mutually incompatible");
+       if (!show_only && ignore_missing)
+               die("Option --ignore-missing can only be used together with --dry-run");
        if ((addremove || take_worktree_changes) && !argc) {
                static const char *here[2] = { ".", NULL };
                argc = 1;
@@ -440,9 +445,14 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                        seen = find_used_pathspec(pathspec);
                for (i = 0; pathspec[i]; i++) {
                        if (!seen[i] && pathspec[i][0]
-                           && !file_exists(pathspec[i]))
-                               die("pathspec '%s' did not match any files",
-                                   pathspec[i]);
+                           && !file_exists(pathspec[i])) {
+                               if (ignore_missing) {
+                                       if (excluded(&dir, pathspec[i], DT_UNKNOWN))
+                                               dir_add_ignored(&dir, pathspec[i], strlen(pathspec[i]));
+                               } else
+                                       die("pathspec '%s' did not match any files",
+                                           pathspec[i]);
+                       }
                }
                free(seen);
        }
index 59bbcdb1323cb70432e90ccc2d6a1c60a562c706..f38c1f7b88fafa18550762685e3bb5b15bfa701f 100644 (file)
@@ -56,7 +56,7 @@ static enum ws_error_action {
        nowarn_ws_error,
        warn_on_ws_error,
        die_on_ws_error,
-       correct_ws_error,
+       correct_ws_error
 } ws_error_action = warn_on_ws_error;
 static int whitespace_error;
 static int squelch_whitespace_errors = 5;
@@ -64,7 +64,7 @@ static int applied_after_fixing_ws;
 
 static enum ws_ignore {
        ignore_ws_none,
-       ignore_ws_change,
+       ignore_ws_change
 } ws_ignore_action = ignore_ws_none;
 
 
@@ -1854,6 +1854,8 @@ static int match_fragment(struct image *img,
 {
        int i;
        char *fixed_buf, *buf, *orig, *target;
+       struct strbuf fixed;
+       size_t fixed_len;
        int preimage_limit;
 
        if (preimage->nr + try_lno <= img->nr) {
@@ -1977,12 +1979,12 @@ static int match_fragment(struct image *img,
                 * use the whitespace from the preimage.
                 */
                extra_chars = preimage_end - preimage_eof;
-               fixed_buf = xmalloc(imgoff + extra_chars);
-               memcpy(fixed_buf, img->buf + try, imgoff);
-               memcpy(fixed_buf + imgoff, preimage_eof, extra_chars);
-               imgoff += extra_chars;
+               strbuf_init(&fixed, imgoff + extra_chars);
+               strbuf_add(&fixed, img->buf + try, imgoff);
+               strbuf_add(&fixed, preimage_eof, extra_chars);
+               fixed_buf = strbuf_detach(&fixed, &fixed_len);
                update_pre_post_images(preimage, postimage,
-                               fixed_buf, imgoff, postlen);
+                               fixed_buf, fixed_len, postlen);
                return 1;
        }
 
@@ -1999,27 +2001,22 @@ static int match_fragment(struct image *img,
         * but in this loop we will only handle the part of the
         * preimage that falls within the file.
         */
-       fixed_buf = xmalloc(preimage->len + 1);
-       buf = fixed_buf;
+       strbuf_init(&fixed, preimage->len + 1);
        orig = preimage->buf;
        target = img->buf + try;
        for (i = 0; i < preimage_limit; i++) {
-               size_t fixlen; /* length after fixing the preimage */
                size_t oldlen = preimage->line[i].len;
                size_t tgtlen = img->line[try_lno + i].len;
-               size_t tgtfixlen; /* length after fixing the target line */
-               char tgtfixbuf[1024], *tgtfix;
+               size_t fixstart = fixed.len;
+               struct strbuf tgtfix;
                int match;
 
                /* Try fixing the line in the preimage */
-               fixlen = ws_fix_copy(buf, orig, oldlen, ws_rule, NULL);
+               ws_fix_copy(&fixed, orig, oldlen, ws_rule, NULL);
 
                /* Try fixing the line in the target */
-               if (sizeof(tgtfixbuf) > tgtlen)
-                       tgtfix = tgtfixbuf;
-               else
-                       tgtfix = xmalloc(tgtlen);
-               tgtfixlen = ws_fix_copy(tgtfix, target, tgtlen, ws_rule, NULL);
+               strbuf_init(&tgtfix, tgtlen);
+               ws_fix_copy(&tgtfix, target, tgtlen, ws_rule, NULL);
 
                /*
                 * If they match, either the preimage was based on
@@ -2031,15 +2028,15 @@ static int match_fragment(struct image *img,
                 * so we might as well take the fix together with their
                 * real change.
                 */
-               match = (tgtfixlen == fixlen && !memcmp(tgtfix, buf, fixlen));
+               match = (tgtfix.len == fixed.len - fixstart &&
+                        !memcmp(tgtfix.buf, fixed.buf + fixstart,
+                                            fixed.len - fixstart));
 
-               if (tgtfix != tgtfixbuf)
-                       free(tgtfix);
+               strbuf_release(&tgtfix);
                if (!match)
                        goto unmatch_exit;
 
                orig += oldlen;
-               buf += fixlen;
                target += tgtlen;
        }
 
@@ -2051,19 +2048,18 @@ static int match_fragment(struct image *img,
         * false).
         */
        for ( ; i < preimage->nr; i++) {
-               size_t fixlen; /* length after fixing the preimage */
+               size_t fixstart = fixed.len; /* start of the fixed preimage */
                size_t oldlen = preimage->line[i].len;
                int j;
 
                /* Try fixing the line in the preimage */
-               fixlen = ws_fix_copy(buf, orig, oldlen, ws_rule, NULL);
+               ws_fix_copy(&fixed, orig, oldlen, ws_rule, NULL);
 
-               for (j = 0; j < fixlen; j++)
-                       if (!isspace(buf[j]))
+               for (j = fixstart; j < fixed.len; j++)
+                       if (!isspace(fixed.buf[j]))
                                goto unmatch_exit;
 
                orig += oldlen;
-               buf += fixlen;
        }
 
        /*
@@ -2071,12 +2067,13 @@ static int match_fragment(struct image *img,
         * has whitespace breakages unfixed, and fixing them makes the
         * hunk match.  Update the context lines in the postimage.
         */
+       fixed_buf = strbuf_detach(&fixed, &fixed_len);
        update_pre_post_images(preimage, postimage,
-                              fixed_buf, buf - fixed_buf, 0);
+                              fixed_buf, fixed_len, 0);
        return 1;
 
  unmatch_exit:
-       free(fixed_buf);
+       strbuf_release(&fixed);
        return 0;
 }
 
@@ -2244,7 +2241,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
        int match_beginning, match_end;
        const char *patch = frag->patch;
        int size = frag->size;
-       char *old, *new, *oldlines, *newlines;
+       char *old, *oldlines;
+       struct strbuf newlines;
        int new_blank_lines_at_end = 0;
        unsigned long leading, trailing;
        int pos, applied_pos;
@@ -2254,16 +2252,16 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
        memset(&preimage, 0, sizeof(preimage));
        memset(&postimage, 0, sizeof(postimage));
        oldlines = xmalloc(size);
-       newlines = xmalloc(size);
+       strbuf_init(&newlines, size);
 
        old = oldlines;
-       new = newlines;
        while (size > 0) {
                char first;
                int len = linelen(patch, size);
-               int plen, added;
+               int plen;
                int added_blank_line = 0;
                int is_blank_context = 0;
+               size_t start;
 
                if (!len)
                        break;
@@ -2293,7 +2291,7 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
                                /* ... followed by '\No newline'; nothing */
                                break;
                        *old++ = '\n';
-                       *new++ = '\n';
+                       strbuf_addch(&newlines, '\n');
                        add_line_info(&preimage, "\n", 1, LINE_COMMON);
                        add_line_info(&postimage, "\n", 1, LINE_COMMON);
                        is_blank_context = 1;
@@ -2315,18 +2313,17 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
                        if (first == '+' && no_add)
                                break;
 
+                       start = newlines.len;
                        if (first != '+' ||
                            !whitespace_error ||
                            ws_error_action != correct_ws_error) {
-                               memcpy(new, patch + 1, plen);
-                               added = plen;
+                               strbuf_add(&newlines, patch + 1, plen);
                        }
                        else {
-                               added = ws_fix_copy(new, patch + 1, plen, ws_rule, &applied_after_fixing_ws);
+                               ws_fix_copy(&newlines, patch + 1, plen, ws_rule, &applied_after_fixing_ws);
                        }
-                       add_line_info(&postimage, new, added,
+                       add_line_info(&postimage, newlines.buf + start, newlines.len - start,
                                      (first == '+' ? 0 : LINE_COMMON));
-                       new += added;
                        if (first == '+' &&
                            (ws_rule & WS_BLANK_AT_EOF) &&
                            ws_blank_line(patch + 1, plen, ws_rule))
@@ -2351,9 +2348,9 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
        }
        if (inaccurate_eof &&
            old > oldlines && old[-1] == '\n' &&
-           new > newlines && new[-1] == '\n') {
+           newlines.len > 0 && newlines.buf[newlines.len - 1] == '\n') {
                old--;
-               new--;
+               strbuf_setlen(&newlines, newlines.len - 1);
        }
 
        leading = frag->leading;
@@ -2385,8 +2382,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
        pos = frag->newpos ? (frag->newpos - 1) : 0;
        preimage.buf = oldlines;
        preimage.len = old - oldlines;
-       postimage.buf = newlines;
-       postimage.len = new - newlines;
+       postimage.buf = newlines.buf;
+       postimage.len = newlines.len;
        preimage.line = preimage.line_allocated;
        postimage.line = postimage.line_allocated;
 
@@ -2462,7 +2459,7 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
        }
 
        free(oldlines);
-       free(newlines);
+       strbuf_release(&newlines);
        free(preimage.line_allocated);
        free(postimage.line_allocated);
 
@@ -2631,7 +2628,7 @@ static struct patch *in_fn_table(const char *name)
        if (name == NULL)
                return NULL;
 
-       item = string_list_lookup(name, &fn_table);
+       item = string_list_lookup(&fn_table, name);
        if (item != NULL)
                return (struct patch *)item->util;
 
@@ -2667,7 +2664,7 @@ static void add_to_fn_table(struct patch *patch)
         * file creations and copies
         */
        if (patch->new_name != NULL) {
-               item = string_list_insert(patch->new_name, &fn_table);
+               item = string_list_insert(&fn_table, patch->new_name);
                item->util = patch;
        }
 
@@ -2676,7 +2673,7 @@ static void add_to_fn_table(struct patch *patch)
         * later chunks shouldn't patch old names
         */
        if ((patch->new_name == NULL) || (patch->is_rename)) {
-               item = string_list_insert(patch->old_name, &fn_table);
+               item = string_list_insert(&fn_table, patch->old_name);
                item->util = PATH_WAS_DELETED;
        }
 }
@@ -2689,7 +2686,7 @@ static void prepare_fn_table(struct patch *patch)
        while (patch) {
                if ((patch->new_name == NULL) || (patch->is_rename)) {
                        struct string_list_item *item;
-                       item = string_list_insert(patch->old_name, &fn_table);
+                       item = string_list_insert(&fn_table, patch->old_name);
                        item->util = PATH_TO_BE_DELETED;
                }
                patch = patch->next;
@@ -2982,8 +2979,7 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
                else if (get_sha1(patch->old_sha1_prefix, sha1))
                        /* git diff has no index line for mode/type changes */
                        if (!patch->lines_added && !patch->lines_deleted) {
-                               if (get_current_sha1(patch->new_name, sha1) ||
-                                   get_current_sha1(patch->old_name, sha1))
+                               if (get_current_sha1(patch->old_name, sha1))
                                        die("mode change for %s, which is not "
                                                "in current HEAD", name);
                                sha1_ptr = sha1;
@@ -3397,7 +3393,7 @@ static void add_name_limit(const char *name, int exclude)
 {
        struct string_list_item *it;
 
-       it = string_list_append(name, &limit_by_name);
+       it = string_list_append(&limit_by_name, name);
        it->util = exclude ? NULL : (void *) 1;
 }
 
index 8506286dd271d4e92369d81ec2cce9240a559d64..28e3be2eadadc71723da96334b8ff1dd22e73205 100644 (file)
@@ -20,6 +20,7 @@
 #include "mailmap.h"
 #include "parse-options.h"
 #include "utf8.h"
+#include "userdiff.h"
 
 static char blame_usage[] = "git blame [options] [rev-opts] [rev] [--] file";
 
@@ -85,17 +86,51 @@ struct origin {
        char path[FLEX_ARRAY];
 };
 
+/*
+ * Prepare diff_filespec and convert it using diff textconv API
+ * if the textconv driver exists.
+ * Return 1 if the conversion succeeds, 0 otherwise.
+ */
+int textconv_object(const char *path,
+                   const unsigned char *sha1,
+                   char **buf,
+                   unsigned long *buf_size)
+{
+       struct diff_filespec *df;
+       struct userdiff_driver *textconv;
+
+       df = alloc_filespec(path);
+       fill_filespec(df, sha1, S_IFREG | 0664);
+       textconv = get_textconv(df);
+       if (!textconv) {
+               free_filespec(df);
+               return 0;
+       }
+
+       *buf_size = fill_textconv(textconv, df, buf);
+       free_filespec(df);
+       return 1;
+}
+
 /*
  * Given an origin, prepare mmfile_t structure to be used by the
  * diff machinery
  */
-static void fill_origin_blob(struct origin *o, mmfile_t *file)
+static void fill_origin_blob(struct diff_options *opt,
+                            struct origin *o, mmfile_t *file)
 {
        if (!o->file.ptr) {
                enum object_type type;
+               unsigned long file_size;
+
                num_read_blob++;
-               file->ptr = read_sha1_file(o->blob_sha1, &type,
-                                          (unsigned long *)(&(file->size)));
+               if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&
+                   textconv_object(o->path, o->blob_sha1, &file->ptr, &file_size))
+                       ;
+               else
+                       file->ptr = read_sha1_file(o->blob_sha1, &type, &file_size);
+               file->size = file_size;
+
                if (!file->ptr)
                        die("Cannot read blob %s for path %s",
                            sha1_to_hex(o->blob_sha1),
@@ -282,7 +317,6 @@ static struct origin *get_origin(struct scoreboard *sb,
 static int fill_blob_sha1(struct origin *origin)
 {
        unsigned mode;
-
        if (!is_null_sha1(origin->blob_sha1))
                return 0;
        if (get_tree_entry(origin->commit->object.sha1,
@@ -733,16 +767,17 @@ static int pass_blame_to_parent(struct scoreboard *sb,
 {
        int last_in_target;
        mmfile_t file_p, file_o;
-       struct blame_chunk_cb_data d = { sb, target, parent, 0, 0 };
+       struct blame_chunk_cb_data d;
        xpparam_t xpp;
        xdemitconf_t xecfg;
-
+       memset(&d, 0, sizeof(d));
+       d.sb = sb; d.target = target; d.parent = parent;
        last_in_target = find_last_in_target(sb, target);
        if (last_in_target < 0)
                return 1; /* nothing remains for this target */
 
-       fill_origin_blob(parent, &file_p);
-       fill_origin_blob(target, &file_o);
+       fill_origin_blob(&sb->revs->diffopt, parent, &file_p);
+       fill_origin_blob(&sb->revs->diffopt, target, &file_o);
        num_get_patch++;
 
        memset(&xpp, 0, sizeof(xpp));
@@ -875,10 +910,11 @@ static void find_copy_in_blob(struct scoreboard *sb,
        const char *cp;
        int cnt;
        mmfile_t file_o;
-       struct handle_split_cb_data d = { sb, ent, parent, split, 0, 0 };
+       struct handle_split_cb_data d;
        xpparam_t xpp;
        xdemitconf_t xecfg;
-
+       memset(&d, 0, sizeof(d));
+       d.sb = sb; d.ent = ent; d.parent = parent; d.split = split;
        /*
         * Prepare mmfile that contains only the lines in ent.
         */
@@ -922,7 +958,7 @@ static int find_move_in_parent(struct scoreboard *sb,
        if (last_in_target < 0)
                return 1; /* nothing remains for this target */
 
-       fill_origin_blob(parent, &file_p);
+       fill_origin_blob(&sb->revs->diffopt, parent, &file_p);
        if (!file_p.ptr)
                return 0;
 
@@ -1063,7 +1099,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
 
                        norigin = get_origin(sb, parent, p->one->path);
                        hashcpy(norigin->blob_sha1, p->one->sha1);
-                       fill_origin_blob(norigin, &file_p);
+                       fill_origin_blob(&sb->revs->diffopt, norigin, &file_p);
                        if (!file_p.ptr)
                                continue;
 
@@ -1983,6 +2019,16 @@ static int git_blame_config(const char *var, const char *value, void *cb)
                blame_date_mode = parse_date_format(value);
                return 0;
        }
+
+       switch (userdiff_config(var, value)) {
+       case 0:
+               break;
+       case -1:
+               return -1;
+       default:
+               return 0;
+       }
+
        return git_default_config(var, value, cb);
 }
 
@@ -1990,7 +2036,9 @@ static int git_blame_config(const char *var, const char *value, void *cb)
  * Prepare a dummy commit that represents the work tree (or staged) item.
  * Note that annotating work tree item never works in the reverse.
  */
-static struct commit *fake_working_tree_commit(const char *path, const char *contents_from)
+static struct commit *fake_working_tree_commit(struct diff_options *opt,
+                                              const char *path,
+                                              const char *contents_from)
 {
        struct commit *commit;
        struct origin *origin;
@@ -2018,6 +2066,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
        if (!contents_from || strcmp("-", contents_from)) {
                struct stat st;
                const char *read_from;
+               unsigned long buf_len;
 
                if (contents_from) {
                        if (stat(contents_from, &st) < 0)
@@ -2030,9 +2079,13 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
                        read_from = path;
                }
                mode = canon_mode(st.st_mode);
+
                switch (st.st_mode & S_IFMT) {
                case S_IFREG:
-                       if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
+                       if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&
+                           textconv_object(read_from, null_sha1, &buf.buf, &buf_len))
+                               buf.len = buf_len;
+                       else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
                                die_errno("cannot open or read '%s'", read_from);
                        break;
                case S_IFLNK:
@@ -2248,6 +2301,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        git_config(git_blame_config, NULL);
        init_revisions(&revs, NULL);
        revs.date_mode = blame_date_mode;
+       DIFF_OPT_SET(&revs.diffopt, ALLOW_TEXTCONV);
 
        save_commit_buffer = 0;
        dashdash_pos = 0;
@@ -2322,11 +2376,11 @@ parse_done:
         *
         * The remaining are:
         *
-        * (1) if dashdash_pos != 0, its either
+        * (1) if dashdash_pos != 0, it is either
         *     "blame [revisions] -- <path>" or
         *     "blame -- <path> <rev>"
         *
-        * (2) otherwise, its one of the two:
+        * (2) otherwise, it is one of the two:
         *     "blame [revisions] <path>"
         *     "blame <path> <rev>"
         *
@@ -2384,7 +2438,8 @@ parse_done:
                 * or "--contents".
                 */
                setup_work_tree();
-               sb.final = fake_working_tree_commit(path, contents_from);
+               sb.final = fake_working_tree_commit(&sb.revs->diffopt,
+                                                   path, contents_from);
                add_pending_object(&revs, &(sb.final->object), ":");
        }
        else if (contents_from)
@@ -2411,8 +2466,14 @@ parse_done:
                if (fill_blob_sha1(o))
                        die("no such path %s in %s", path, final_commit_name);
 
-               sb.final_buf = read_sha1_file(o->blob_sha1, &type,
-                                             &sb.final_buf_size);
+               if (DIFF_OPT_TST(&sb.revs->diffopt, ALLOW_TEXTCONV) &&
+                   textconv_object(path, o->blob_sha1, (char **) &sb.final_buf,
+                                   &sb.final_buf_size))
+                       ;
+               else
+                       sb.final_buf = read_sha1_file(o->blob_sha1, &type,
+                                                     &sb.final_buf_size);
+
                if (!sb.final_buf)
                        die("Cannot read blob %s for path %s",
                            sha1_to_hex(o->blob_sha1),
index 6cf7e721e6b59f50c7a8018296aa49848deecda3..87976f0921d87f2a8564eb54aa3b81d30ee7f214 100644 (file)
@@ -43,13 +43,13 @@ enum color_branch {
        BRANCH_COLOR_PLAIN = 1,
        BRANCH_COLOR_REMOTE = 2,
        BRANCH_COLOR_LOCAL = 3,
-       BRANCH_COLOR_CURRENT = 4,
+       BRANCH_COLOR_CURRENT = 4
 };
 
 static enum merge_filter {
        NO_FILTER = 0,
        SHOW_NOT_MERGED,
-       SHOW_MERGED,
+       SHOW_MERGED
 } merge_filter;
 static unsigned char merge_filter_ref[20];
 
@@ -257,9 +257,15 @@ static char *resolve_symref(const char *src, const char *prefix)
        return xstrdup(dst);
 }
 
+struct append_ref_cb {
+       struct ref_list *ref_list;
+       int ret;
+};
+
 static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
 {
-       struct ref_list *ref_list = (struct ref_list*)(cb_data);
+       struct append_ref_cb *cb = (struct append_ref_cb *)(cb_data);
+       struct ref_list *ref_list = cb->ref_list;
        struct ref_item *newitem;
        struct commit *commit;
        int kind, i;
@@ -293,8 +299,10 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
        commit = NULL;
        if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
                commit = lookup_commit_reference_gently(sha1, 1);
-               if (!commit)
-                       return error("branch '%s' does not point at a commit", refname);
+               if (!commit) {
+                       cb->ret = error("branch '%s' does not point at a commit", refname);
+                       return 0;
+               }
 
                /* Filter with with_commit if specified */
                if (!is_descendant_of(commit, ref_list->with_commit))
@@ -484,9 +492,10 @@ static void show_detached(struct ref_list *ref_list)
        }
 }
 
-static void print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit)
+static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit)
 {
        int i;
+       struct append_ref_cb cb;
        struct ref_list ref_list;
 
        memset(&ref_list, 0, sizeof(ref_list));
@@ -496,7 +505,9 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
        ref_list.with_commit = with_commit;
        if (merge_filter != NO_FILTER)
                init_revisions(&ref_list.revs, NULL);
-       for_each_rawref(append_ref, &ref_list);
+       cb.ref_list = &ref_list;
+       cb.ret = 0;
+       for_each_rawref(append_ref, &cb);
        if (merge_filter != NO_FILTER) {
                struct commit *filter;
                filter = lookup_commit_reference_gently(merge_filter_ref, 0);
@@ -527,6 +538,11 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
        }
 
        free_ref_list(&ref_list);
+
+       if (cb.ret)
+               error("some refs could not be read");
+
+       return cb.ret;
 }
 
 static void rename_branch(const char *oldname, const char *newname, int force)
@@ -679,7 +695,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
        if (delete)
                return delete_branches(argc, argv, delete > 1, kinds);
        else if (argc == 0)
-               print_ref_list(kinds, detached, verbose, abbrev, with_commit);
+               return print_ref_list(kinds, detached, verbose, abbrev, with_commit);
        else if (rename && (argc == 1))
                rename_branch(head, argv[0], rename > 1);
        else if (rename && (argc == 2))
index a933eaa043257c84f35e1d86728ca91be035caff..76ec3fec9279f38520fa4b5b525ce2c03cc9cbb0 100644 (file)
@@ -9,6 +9,8 @@
 #include "tree.h"
 #include "builtin.h"
 #include "parse-options.h"
+#include "diff.h"
+#include "userdiff.h"
 
 #define BATCH 1
 #define BATCH_CHECK 2
@@ -84,10 +86,11 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
 {
        unsigned char sha1[20];
        enum object_type type;
-       void *buf;
+       char *buf;
        unsigned long size;
+       struct object_context obj_context;
 
-       if (get_sha1(obj_name, sha1))
+       if (get_sha1_with_context(obj_name, sha1, &obj_context))
                die("Not a valid object name %s", obj_name);
 
        buf = NULL;
@@ -118,7 +121,9 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
 
                /* custom pretty-print here */
                if (type == OBJ_TREE) {
-                       const char *ls_args[3] = {"ls-tree", obj_name, NULL};
+                       const char *ls_args[3] = { NULL };
+                       ls_args[0] =  "ls-tree";
+                       ls_args[1] =  obj_name;
                        return cmd_ls_tree(2, ls_args, NULL);
                }
 
@@ -132,6 +137,17 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
 
                /* otherwise just spit out the data */
                break;
+
+       case 'c':
+               if (!obj_context.path[0])
+                       die("git cat-file --textconv %s: <object> must be <sha1:path>",
+                           obj_name);
+
+               if (!textconv_object(obj_context.path, sha1, &buf, &size))
+                       die("git cat-file --textconv: unable to run textconv on %s",
+                           obj_name);
+               break;
+
        case 0:
                buf = read_object_with_reference(sha1, exp_type, &size, NULL);
                break;
@@ -201,11 +217,25 @@ static int batch_objects(int print_contents)
 }
 
 static const char * const cat_file_usage[] = {
-       "git cat-file (-t|-s|-e|-p|<type>) <object>",
+       "git cat-file (-t|-s|-e|-p|<type>|--textconv) <object>",
        "git cat-file (--batch|--batch-check) < <list_of_objects>",
        NULL
 };
 
+static int git_cat_file_config(const char *var, const char *value, void *cb)
+{
+       switch (userdiff_config(var, value)) {
+       case 0:
+               break;
+       case -1:
+               return -1;
+       default:
+               return 0;
+       }
+
+       return git_default_config(var, value, cb);
+}
+
 int cmd_cat_file(int argc, const char **argv, const char *prefix)
 {
        int opt = 0, batch = 0;
@@ -218,6 +248,8 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
                OPT_SET_INT('e', NULL, &opt,
                            "exit with zero when there's no error", 'e'),
                OPT_SET_INT('p', NULL, &opt, "pretty-print object's content", 'p'),
+               OPT_SET_INT(0, "textconv", &opt,
+                           "for blob objects, run textconv on object's content", 'c'),
                OPT_SET_INT(0, "batch", &batch,
                            "show info and content of objects fed from the standard input",
                            BATCH),
@@ -227,7 +259,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
                OPT_END()
        };
 
-       git_config(git_default_config, NULL);
+       git_config(git_cat_file_config, NULL);
 
        if (argc != 3 && argc != 2)
                usage_with_options(cat_file_usage, options);
index b106c65d80dfc8fe794d46e34ea1ff78b04f3056..ae3f28115a7a4d65d8bb6f284cd1ececa4f9c2ef 100644 (file)
@@ -33,28 +33,38 @@ static void collapse_slashes(char *dst, const char *src)
        *dst = '\0';
 }
 
+static int check_ref_format_branch(const char *arg)
+{
+       struct strbuf sb = STRBUF_INIT;
+       int nongit;
+
+       setup_git_directory_gently(&nongit);
+       if (strbuf_check_branch_ref(&sb, arg))
+               die("'%s' is not a valid branch name", arg);
+       printf("%s\n", sb.buf + 11);
+       return 0;
+}
+
+static int check_ref_format_print(const char *arg)
+{
+       char *refname = xmalloc(strlen(arg) + 1);
+
+       if (check_ref_format(arg))
+               return 1;
+       collapse_slashes(refname, arg);
+       printf("%s\n", refname);
+       return 0;
+}
+
 int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
 {
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage(builtin_check_ref_format_usage);
 
-       if (argc == 3 && !strcmp(argv[1], "--branch")) {
-               struct strbuf sb = STRBUF_INIT;
-
-               if (strbuf_check_branch_ref(&sb, argv[2]))
-                       die("'%s' is not a valid branch name", argv[2]);
-               printf("%s\n", sb.buf + 11);
-               exit(0);
-       }
-       if (argc == 3 && !strcmp(argv[1], "--print")) {
-               char *refname = xmalloc(strlen(argv[2]) + 1);
-
-               if (check_ref_format(argv[2]))
-                       exit(1);
-               collapse_slashes(refname, argv[2]);
-               printf("%s\n", refname);
-               exit(0);
-       }
+       if (argc == 3 && !strcmp(argv[1], "--branch"))
+               return check_ref_format_branch(argv[2]);
+       if (argc == 3 && !strcmp(argv[1], "--print"))
+               return check_ref_format_print(argv[2]);
        if (argc != 2)
                usage(builtin_check_ref_format_usage);
        return !!check_ref_format(argv[1]);
index 88b1f43e05e64f0e8dcd6dd0461bbebd6fab1e25..eef2b48d9856c90b2d8fd7b2e06f8179c08faeac 100644 (file)
@@ -33,6 +33,7 @@ struct checkout_opts {
        int writeout_error;
 
        const char *new_branch;
+       const char *new_orphan_branch;
        int new_branch_log;
        enum branch_track track;
 };
@@ -278,7 +279,6 @@ static void show_local_changes(struct object *head)
        struct rev_info rev;
        /* I think we want full paths, even if we're in a subdirectory. */
        init_revisions(&rev, NULL);
-       rev.abbrev = 0;
        rev.diffopt.output_format |= DIFF_FORMAT_NAME_STATUS;
        if (diff_setup_done(&rev.diffopt) < 0)
                die("diff_setup_done failed");
@@ -492,8 +492,26 @@ static void update_refs_for_switch(struct checkout_opts *opts,
        struct strbuf msg = STRBUF_INIT;
        const char *old_desc;
        if (opts->new_branch) {
-               create_branch(old->name, opts->new_branch, new->name, 0,
-                             opts->new_branch_log, opts->track);
+               if (opts->new_orphan_branch) {
+                       if (opts->new_branch_log && !log_all_ref_updates) {
+                               int temp;
+                               char log_file[PATH_MAX];
+                               char *ref_name = mkpath("refs/heads/%s", opts->new_orphan_branch);
+
+                               temp = log_all_ref_updates;
+                               log_all_ref_updates = 1;
+                               if (log_ref_setup(ref_name, log_file, sizeof(log_file))) {
+                                       fprintf(stderr, "Can not do reflog for '%s'\n",
+                                           opts->new_orphan_branch);
+                                       log_all_ref_updates = temp;
+                                       return;
+                               }
+                               log_all_ref_updates = temp;
+                       }
+               }
+               else
+                       create_branch(old->name, opts->new_branch, new->name, 0,
+                                     opts->new_branch_log, opts->track);
                new->name = opts->new_branch;
                setup_branch_path(new);
        }
@@ -515,6 +533,14 @@ static void update_refs_for_switch(struct checkout_opts *opts,
                                        opts->new_branch ? " a new" : "",
                                        new->name);
                }
+               if (old->path && old->name) {
+                       char log_file[PATH_MAX], ref_file[PATH_MAX];
+
+                       git_snpath(log_file, sizeof(log_file), "logs/%s", old->path);
+                       git_snpath(ref_file, sizeof(ref_file), "%s", old->path);
+                       if (!file_exists(ref_file) && file_exists(log_file))
+                               remove_path(log_file);
+               }
        } else if (strcmp(new->name, "HEAD")) {
                update_ref(msg.buf, "HEAD", new->commit->object.sha1, NULL,
                           REF_NODEREF, DIE_ON_ERR);
@@ -609,7 +635,8 @@ static int check_tracking_name(const char *refname, const unsigned char *sha1,
 
 static const char *unique_tracking_name(const char *name)
 {
-       struct tracking_name_data cb_data = { name, NULL, 1 };
+       struct tracking_name_data cb_data = { NULL, NULL, 1 };
+       cb_data.name = name;
        for_each_ref(check_tracking_name, &cb_data);
        if (cb_data.unique)
                return cb_data.remote;
@@ -633,6 +660,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                OPT_BOOLEAN('l', NULL, &opts.new_branch_log, "log for new branch"),
                OPT_SET_INT('t', "track",  &opts.track, "track",
                        BRANCH_TRACK_EXPLICIT),
+               OPT_STRING(0, "orphan", &opts.new_orphan_branch, "new branch", "new unparented branch"),
                OPT_SET_INT('2', "ours", &opts.writeout_stage, "stage",
                            2),
                OPT_SET_INT('3', "theirs", &opts.writeout_stage, "stage",
@@ -678,6 +706,14 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                opts.new_branch = argv0 + 1;
        }
 
+       if (opts.new_orphan_branch) {
+               if (opts.new_branch)
+                       die("--orphan and -b are mutually exclusive");
+               if (opts.track > 0)
+                       die("--orphan cannot be used with -t");
+               opts.new_branch = opts.new_orphan_branch;
+       }
+
        if (conflict_style) {
                opts.merge = 1; /* implied */
                git_xmerge_config("merge.conflictstyle", conflict_style, NULL);
index 3a3625b2ad97472c8486c9fbdd4ac6333699a37d..efb1e6faa539935de0e9dc590237185a1d222322 100644 (file)
@@ -475,9 +475,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
         */
        unsetenv(CONFIG_ENVIRONMENT);
 
-       if (option_reference)
-               setup_reference(git_dir);
-
        git_config(git_default_config, NULL);
 
        if (option_bare) {
@@ -503,12 +500,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                        git_config_set(key.buf, "true");
                        strbuf_reset(&key);
                }
-
-               strbuf_addf(&key, "remote.%s.url", option_origin);
-               git_config_set(key.buf, repo);
-               strbuf_reset(&key);
        }
 
+       strbuf_addf(&key, "remote.%s.url", option_origin);
+       git_config_set(key.buf, repo);
+       strbuf_reset(&key);
+
+       if (option_reference)
+               setup_reference(git_dir);
+
        fetch_pattern = value.buf;
        refspec = parse_fetch_refspec(1, &fetch_pattern);
 
@@ -518,7 +518,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                refs = clone_local(path, git_dir);
                mapped_refs = wanted_peer_refs(refs, refspec);
        } else {
-               struct remote *remote = remote_get(argv[0]);
+               struct remote *remote = remote_get(option_origin);
                transport = transport_get(remote, remote->url[0]);
 
                if (!transport->get_refs_list || !transport->fetch)
index 90dac349a3137405baaea63bfb6c798d2f8c92a3..87f0591c2f68a03e06c73b352282426b803450ba 100644 (file)
@@ -9,19 +9,6 @@
 #include "builtin.h"
 #include "utf8.h"
 
-/*
- * FIXME! Share the code with "write-tree.c"
- */
-static void check_valid(unsigned char *sha1, enum object_type expect)
-{
-       enum object_type type = sha1_object_info(sha1, NULL);
-       if (type < 0)
-               die("%s is not a valid object", sha1_to_hex(sha1));
-       if (type != expect)
-               die("%s is not a valid '%s' object", sha1_to_hex(sha1),
-                   typename(expect));
-}
-
 static const char commit_tree_usage[] = "git commit-tree <sha1> [-p <sha1>]* < changelog";
 
 static void new_parent(struct commit *parent, struct commit_list **parents_p)
@@ -38,61 +25,6 @@ static void new_parent(struct commit *parent, struct commit_list **parents_p)
        commit_list_insert(parent, parents_p);
 }
 
-static const char commit_utf8_warn[] =
-"Warning: commit message does not conform to UTF-8.\n"
-"You may want to amend it after fixing the message, or set the config\n"
-"variable i18n.commitencoding to the encoding your project uses.\n";
-
-int commit_tree(const char *msg, unsigned char *tree,
-               struct commit_list *parents, unsigned char *ret,
-               const char *author)
-{
-       int result;
-       int encoding_is_utf8;
-       struct strbuf buffer;
-
-       check_valid(tree, OBJ_TREE);
-
-       /* Not having i18n.commitencoding is the same as having utf-8 */
-       encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
-
-       strbuf_init(&buffer, 8192); /* should avoid reallocs for the headers */
-       strbuf_addf(&buffer, "tree %s\n", sha1_to_hex(tree));
-
-       /*
-        * NOTE! This ordering means that the same exact tree merged with a
-        * different order of parents will be a _different_ changeset even
-        * if everything else stays the same.
-        */
-       while (parents) {
-               struct commit_list *next = parents->next;
-               strbuf_addf(&buffer, "parent %s\n",
-                       sha1_to_hex(parents->item->object.sha1));
-               free(parents);
-               parents = next;
-       }
-
-       /* Person/date information */
-       if (!author)
-               author = git_author_info(IDENT_ERROR_ON_NO_NAME);
-       strbuf_addf(&buffer, "author %s\n", author);
-       strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
-       if (!encoding_is_utf8)
-               strbuf_addf(&buffer, "encoding %s\n", git_commit_encoding);
-       strbuf_addch(&buffer, '\n');
-
-       /* And add the comment */
-       strbuf_addstr(&buffer, msg);
-
-       /* And check the encoding */
-       if (encoding_is_utf8 && !is_utf8(buffer.buf))
-               fprintf(stderr, commit_utf8_warn);
-
-       result = write_sha1_file(buffer.buf, buffer.len, commit_type, ret);
-       strbuf_release(&buffer);
-       return result;
-}
-
 int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 {
        int i;
@@ -117,7 +49,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 
                if (get_sha1(b, sha1))
                        die("Not a valid object name %s", b);
-               check_valid(sha1, OBJ_COMMIT);
+               assert_sha1_type(sha1, OBJ_COMMIT);
                new_parent(lookup_commit(sha1), &parents);
        }
 
index 80c621dc061f9bb67a521dfb857ec52b536eacfd..c4a577d5c5595a6c50ecaaba90690c286d30b7e2 100644 (file)
@@ -62,7 +62,7 @@ static struct lock_file false_lock; /* used only for partial commits */
 static enum {
        COMMIT_AS_IS = 1,
        COMMIT_NORMAL,
-       COMMIT_PARTIAL,
+       COMMIT_PARTIAL
 } commit_style;
 
 static const char *logfile, *force_author;
@@ -71,8 +71,8 @@ static char *edit_message, *use_message;
 static char *author_name, *author_email, *author_date;
 static int all, edit_flag, also, interactive, only, amend, signoff;
 static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
-static int no_post_rewrite;
-static char *untracked_files_arg, *force_date;
+static int no_post_rewrite, allow_empty_message;
+static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
 /*
  * The default commit message cleanup mode will remove the lines
  * beginning with # (shell comments) and leading and trailing
@@ -83,11 +83,12 @@ static char *untracked_files_arg, *force_date;
 static enum {
        CLEANUP_SPACE,
        CLEANUP_NONE,
-       CLEANUP_ALL,
+       CLEANUP_ALL
 } cleanup_mode;
 static char *cleanup_arg;
 
 static int use_editor = 1, initial_commit, in_merge, include_status = 1;
+static int show_ignored_in_status;
 static const char *only_include_assumed;
 static struct strbuf message;
 
@@ -95,8 +96,9 @@ static int null_termination;
 static enum {
        STATUS_FORMAT_LONG,
        STATUS_FORMAT_SHORT,
-       STATUS_FORMAT_PORCELAIN,
+       STATUS_FORMAT_PORCELAIN
 } status_format = STATUS_FORMAT_LONG;
+static int status_show_branch;
 
 static int opt_parse_m(const struct option *opt, const char *arg, int unset)
 {
@@ -138,16 +140,23 @@ static struct option builtin_commit_options[] = {
        OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
        OPT_SET_INT(0, "short", &status_format, "show status concisely",
                    STATUS_FORMAT_SHORT),
+       OPT_BOOLEAN(0, "branch", &status_show_branch, "show branch information"),
        OPT_SET_INT(0, "porcelain", &status_format,
                    "show porcelain output format", STATUS_FORMAT_PORCELAIN),
        OPT_BOOLEAN('z', "null", &null_termination,
                    "terminate entries with NUL"),
        OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
        OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
-       { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
-       OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
+       { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
        /* end commit contents options */
 
+       { OPTION_BOOLEAN, 0, "allow-empty", &allow_empty, NULL,
+         "ok to record an empty change",
+         PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
+       { OPTION_BOOLEAN, 0, "allow-empty-message", &allow_empty_message, NULL,
+         "ok to record a change with an empty message",
+         PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
+
        OPT_END()
 };
 
@@ -210,7 +219,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
                        continue;
                if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
                        continue;
-               item = string_list_insert(ce->name, list);
+               item = string_list_insert(list, ce->name);
                if (ce_skip_worktree(ce))
                        item->util = item; /* better a valid pointer than a fake one */
        }
@@ -334,9 +343,13 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
        if (!pathspec || !*pathspec) {
                fd = hold_locked_index(&index_lock, 1);
                refresh_cache_or_die(refresh_flags);
-               if (write_cache(fd, active_cache, active_nr) ||
-                   commit_locked_index(&index_lock))
-                       die("unable to write new_index file");
+               if (active_cache_changed) {
+                       if (write_cache(fd, active_cache, active_nr) ||
+                           commit_locked_index(&index_lock))
+                               die("unable to write new_index file");
+               } else {
+                       rollback_lock_file(&index_lock);
+               }
                commit_style = COMMIT_AS_IS;
                return get_index_file();
        }
@@ -422,7 +435,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 
        switch (status_format) {
        case STATUS_FORMAT_SHORT:
-               wt_shortstatus_print(s, null_termination);
+               wt_shortstatus_print(s, null_termination, status_show_branch);
                break;
        case STATUS_FORMAT_PORCELAIN:
                wt_porcelain_print(s, null_termination);
@@ -730,7 +743,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 
        if (use_editor) {
                char index[PATH_MAX];
-               const char *env[2] = { index, NULL };
+               const char *env[2] = { NULL };
+               env[0] =  index;
                snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
                if (launch_editor(git_path(commit_editmsg), NULL, env)) {
                        fprintf(stderr,
@@ -1036,6 +1050,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
                OPT__VERBOSE(&verbose),
                OPT_SET_INT('s', "short", &status_format,
                            "show status concisely", STATUS_FORMAT_SHORT),
+               OPT_BOOLEAN('b', "branch", &status_show_branch,
+                           "show branch information"),
                OPT_SET_INT(0, "porcelain", &status_format,
                            "show porcelain output format",
                            STATUS_FORMAT_PORCELAIN),
@@ -1045,6 +1061,11 @@ int cmd_status(int argc, const char **argv, const char *prefix)
                  "mode",
                  "show untracked files, optional modes: all, normal, no. (Default: all)",
                  PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
+               OPT_BOOLEAN(0, "ignored", &show_ignored_in_status,
+                           "show ignored files"),
+               { OPTION_STRING, 0, "ignore-submodules", &ignore_submodule_arg, "when",
+                 "ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)",
+                 PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
                OPT_END(),
        };
 
@@ -1058,7 +1079,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
                             builtin_status_options,
                             builtin_status_usage, 0);
        handle_untracked_files_arg(&s);
-
+       if (show_ignored_in_status)
+               s.show_ignored_files = 1;
        if (*argv)
                s.pathspec = get_pathspec(prefix, argv);
 
@@ -1067,13 +1089,16 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
        fd = hold_locked_index(&index_lock, 0);
        if (0 <= fd) {
-               if (!write_cache(fd, active_cache, active_nr))
+               if (active_cache_changed &&
+                   !write_cache(fd, active_cache, active_nr))
                        commit_locked_index(&index_lock);
-               rollback_lock_file(&index_lock);
+               else
+                       rollback_lock_file(&index_lock);
        }
 
        s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
        s.in_merge = in_merge;
+       s.ignore_submodule_arg = ignore_submodule_arg;
        wt_status_collect(&s);
 
        if (s.relative_paths)
@@ -1085,13 +1110,14 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
        switch (status_format) {
        case STATUS_FORMAT_SHORT:
-               wt_shortstatus_print(&s, null_termination);
+               wt_shortstatus_print(&s, null_termination, status_show_branch);
                break;
        case STATUS_FORMAT_PORCELAIN:
                wt_porcelain_print(&s, null_termination);
                break;
        case STATUS_FORMAT_LONG:
                s.verbose = verbose;
+               s.ignore_submodule_arg = ignore_submodule_arg;
                wt_status_print(&s);
                break;
        }
@@ -1137,7 +1163,6 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
        init_revisions(&rev, prefix);
        setup_revisions(0, NULL, &rev, NULL);
 
-       rev.abbrev = 0;
        rev.diff = 1;
        rev.diffopt.output_format =
                DIFF_FORMAT_SHORTSTAT | DIFF_FORMAT_SUMMARY;
@@ -1318,7 +1343,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
        if (cleanup_mode != CLEANUP_NONE)
                stripspace(&sb, cleanup_mode == CLEANUP_ALL);
-       if (message_is_empty(&sb)) {
+       if (message_is_empty(&sb) && !allow_empty_message) {
                rollback_index_files();
                fprintf(stderr, "Aborting commit due to empty commit message.\n");
                exit(1);
index 4bc46b15fde00d913577a2980778746f8315bb70..f3d1660d023f7893373436617a9f729ce1d60f4d 100644 (file)
@@ -197,7 +197,11 @@ static int get_value(const char *key_, const char *regex_)
                git_config_from_file(show_config, system_wide, NULL);
        if (do_all && global)
                git_config_from_file(show_config, global, NULL);
-       git_config_from_file(show_config, local, NULL);
+       if (do_all)
+               git_config_from_file(show_config, local, NULL);
+       git_config_from_parameters(show_config, NULL);
+       if (!do_all && !seen)
+               git_config_from_file(show_config, local, NULL);
        if (!do_all && !seen && global)
                git_config_from_file(show_config, global, NULL);
        if (!do_all && !seen && system_wide)
index ffcdd055ca0b9b30bec2ce1f22e348ec15d58c81..89ae89cde1e6d8a0a2e02209f5396263a81bda5b 100644 (file)
@@ -407,17 +407,19 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
                result = builtin_diff_index(&rev, argc, argv);
        else if (ents == 2)
                result = builtin_diff_tree(&rev, argc, argv, ent);
-       else if ((ents == 3) && (ent[0].item->flags & UNINTERESTING)) {
-               /* diff A...B where there is one sane merge base between
-                * A and B.  We have ent[0] == merge-base, ent[1] == A,
-                * and ent[2] == B.  Show diff between the base and B.
+       else if (ent[0].item->flags & UNINTERESTING) {
+               /*
+                * diff A...B where there is at least one merge base
+                * between A and B.  We have ent[0] == merge-base,
+                * ent[ents-2] == A, and ent[ents-1] == B.  Show diff
+                * between the base and B.  Note that we pick one
+                * merge base at random if there are more than one.
                 */
-               ent[1] = ent[2];
+               ent[1] = ent[ents-1];
                result = builtin_diff_tree(&rev, argc, argv, ent);
-       }
-       else
+       } else
                result = builtin_diff_combined(&rev, argc, argv,
-                                            ent, ents);
+                                              ent, ents);
        result = diff_result_code(&rev.diffopt, result);
        if (1 < rev.diffopt.skip_stat_unmatch)
                refresh_index_quietly();
index c6dd71a7bcd0dfcb4691c9ca66a0c3a7bd4dcaae..9fe25ff0b3dc0ae89c668b146b46a4ccbd457361 100644 (file)
@@ -438,7 +438,7 @@ static void get_tags_and_duplicates(struct object_array *pending,
                        /* handle nested tags */
                        while (tag && tag->object.type == OBJ_TAG) {
                                parse_object(tag->object.sha1);
-                               string_list_append(full_name, extra_refs)->util = tag;
+                               string_list_append(extra_refs, full_name)->util = tag;
                                tag = (struct tag *)tag->tagged;
                        }
                        if (!tag)
@@ -464,7 +464,7 @@ static void get_tags_and_duplicates(struct object_array *pending,
                }
                if (commit->util)
                        /* more than one name for the same object */
-                       string_list_append(full_name, extra_refs)->util = commit;
+                       string_list_append(extra_refs, full_name)->util = commit;
                else
                        commit->util = full_name;
        }
index 8470850415c14cad8ceeca9f6baef46ab6feabc3..7a5314415312e4c0e6e17e5a8934099d3d1274c4 100644 (file)
@@ -528,7 +528,7 @@ static int add_existing(const char *refname, const unsigned char *sha1,
                        int flag, void *cbdata)
 {
        struct string_list *list = (struct string_list *)cbdata;
-       struct string_list_item *item = string_list_insert(refname, list);
+       struct string_list_item *item = string_list_insert(list, refname);
        item->util = (void *)sha1;
        return 0;
 }
@@ -574,9 +574,10 @@ static void find_non_local_tags(struct transport *transport,
 {
        struct string_list existing_refs = { NULL, 0, 0, 0 };
        struct string_list remote_refs = { NULL, 0, 0, 0 };
-       struct tag_data data = {head, tail};
+       struct tag_data data;
        const struct ref *ref;
        struct string_list_item *item = NULL;
+       data.head = head; data.tail = tail;
 
        for_each_ref(add_existing, &existing_refs);
        for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
@@ -616,7 +617,7 @@ static void find_non_local_tags(struct transport *transport,
                    string_list_has_string(&existing_refs, ref->name))
                        continue;
 
-               item = string_list_insert(ref->name, &remote_refs);
+               item = string_list_insert(&remote_refs, ref->name);
                item->util = (void *)ref->old_sha1;
        }
        string_list_clear(&existing_refs, 0);
@@ -633,7 +634,7 @@ static void find_non_local_tags(struct transport *transport,
         * For all the tags in the remote_refs string list, call
         * add_to_tail to add them to the list of refs to be fetched
         */
-       for_each_string_list(add_to_tail, &remote_refs, &data);
+       for_each_string_list(&remote_refs, add_to_tail, &data);
 
        string_list_clear(&remote_refs, 0);
 }
@@ -674,10 +675,12 @@ static int do_fetch(struct transport *transport,
 
        for_each_ref(add_existing, &existing_refs);
 
-       if (transport->remote->fetch_tags == 2 && tags != TAGS_UNSET)
-               tags = TAGS_SET;
-       if (transport->remote->fetch_tags == -1)
-               tags = TAGS_UNSET;
+       if (tags == TAGS_DEFAULT) {
+               if (transport->remote->fetch_tags == 2)
+                       tags = TAGS_SET;
+               if (transport->remote->fetch_tags == -1)
+                       tags = TAGS_UNSET;
+       }
 
        if (!transport->get_refs_list || !transport->fetch)
                die("Don't know how to fetch from %s", transport->url);
@@ -695,8 +698,8 @@ static int do_fetch(struct transport *transport,
 
        for (rm = ref_map; rm; rm = rm->next) {
                if (rm->peer_ref) {
-                       peer_item = string_list_lookup(rm->peer_ref->name,
-                                                      &existing_refs);
+                       peer_item = string_list_lookup(&existing_refs,
+                                                      rm->peer_ref->name);
                        if (peer_item)
                                hashcpy(rm->peer_ref->old_sha1,
                                        peer_item->util);
@@ -745,7 +748,7 @@ static int get_one_remote_for_fetch(struct remote *remote, void *priv)
 {
        struct string_list *list = priv;
        if (!remote->skip_default_update)
-               string_list_append(remote->name, list);
+               string_list_append(list, remote->name);
        return 0;
 }
 
@@ -764,8 +767,8 @@ static int get_remote_group(const char *key, const char *value, void *priv)
                int space = strcspn(value, " \t\n");
                while (*value) {
                        if (space > 1) {
-                               string_list_append(xstrndup(value, space),
-                                                  g->list);
+                               string_list_append(g->list,
+                                                  xstrndup(value, space));
                        }
                        value += space + (value[space] != '\0');
                        space = strcspn(value, " \t\n");
@@ -778,7 +781,8 @@ static int get_remote_group(const char *key, const char *value, void *priv)
 static int add_remote_or_group(const char *name, struct string_list *list)
 {
        int prev_nr = list->nr;
-       struct remote_group_data g = { name, list };
+       struct remote_group_data g;
+       g.name = name; g.list = list;
 
        git_config(get_remote_group, &g);
        if (list->nr == prev_nr) {
@@ -786,7 +790,7 @@ static int add_remote_or_group(const char *name, struct string_list *list)
                if (!remote_is_configured(name))
                        return 0;
                remote = remote_get(name);
-               string_list_append(remote->name, list);
+               string_list_append(list, remote->name);
        }
        return 1;
 }
@@ -843,7 +847,8 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
        int exit_code;
 
        if (!remote)
-               die("Where do you want to fetch from today?");
+               die("No remote repository specified.  Please, specify either a URL or a\n"
+                   "remote name from which new revisions should be fetched.");
 
        transport = transport_get(remote, NULL);
        transport_set_verbosity(transport, verbosity, progress);
index 44204257c72afd3a6a24966b9a11cf9f2374e9ce..bc3c5e6d3ec50eaa9829358ee0a82a1438c19f89 100644 (file)
@@ -82,7 +82,7 @@ static int handle_line(char *line)
 
        item = unsorted_string_list_lookup(&srcs, src);
        if (!item) {
-               item = string_list_append(src, &srcs);
+               item = string_list_append(&srcs, src);
                item->util = xcalloc(1, sizeof(struct src_data));
                init_src_data(item->util);
        }
@@ -93,19 +93,19 @@ static int handle_line(char *line)
                src_data->head_status |= 1;
        } else if (!prefixcmp(line, "branch ")) {
                origin = line + 7;
-               string_list_append(origin, &src_data->branch);
+               string_list_append(&src_data->branch, origin);
                src_data->head_status |= 2;
        } else if (!prefixcmp(line, "tag ")) {
                origin = line;
-               string_list_append(origin + 4, &src_data->tag);
+               string_list_append(&src_data->tag, origin + 4);
                src_data->head_status |= 2;
        } else if (!prefixcmp(line, "remote branch ")) {
                origin = line + 14;
-               string_list_append(origin, &src_data->r_branch);
+               string_list_append(&src_data->r_branch, origin);
                src_data->head_status |= 2;
        } else {
                origin = src;
-               string_list_append(line, &src_data->generic);
+               string_list_append(&src_data->generic, line);
                src_data->head_status |= 2;
        }
 
@@ -118,7 +118,7 @@ static int handle_line(char *line)
                sprintf(new_origin, "%s of %s", origin, src);
                origin = new_origin;
        }
-       string_list_append(origin, &origins)->util = sha1;
+       string_list_append(&origins, origin)->util = sha1;
        return 0;
 }
 
@@ -176,10 +176,10 @@ static void shortlog(const char *name, unsigned char *sha1,
                strbuf_ltrim(&sb);
 
                if (!sb.len)
-                       string_list_append(sha1_to_hex(commit->object.sha1),
-                                          &subjects);
+                       string_list_append(&subjects,
+                                          sha1_to_hex(commit->object.sha1));
                else
-                       string_list_append(strbuf_detach(&sb, NULL), &subjects);
+                       string_list_append(&subjects, strbuf_detach(&sb, NULL));
        }
 
        if (count > limit)
index 7f5011f75ef9eb549b33861d9546f3d18a94c256..89e75c6894e6fdb2abbe464d825f5c7186a14141 100644 (file)
@@ -227,6 +227,10 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
                        strcpy(s, sha1_to_hex(obj->sha1));
                        v->s = s;
                }
+               else if (!strcmp(name, "objectname:short")) {
+                       v->s = xstrdup(find_unique_abbrev(obj->sha1,
+                                                         DEFAULT_ABBREV));
+               }
        }
 }
 
index b194ea3cea531f3a6c81d6d27b5b3028641ba9ce..597f76bc42f51e0fc1906c287981e3d37dc0f536 100644 (file)
@@ -11,6 +11,8 @@
 #include "tree-walk.h"
 #include "builtin.h"
 #include "parse-options.h"
+#include "string-list.h"
+#include "run-command.h"
 #include "userdiff.h"
 #include "grep.h"
 #include "quote.h"
@@ -556,6 +558,33 @@ static int grep_file(struct grep_opt *opt, const char *filename)
        }
 }
 
+static void append_path(struct grep_opt *opt, const void *data, size_t len)
+{
+       struct string_list *path_list = opt->output_priv;
+
+       if (len == 1 && *(const char *)data == '\0')
+               return;
+       string_list_append(path_list, xstrndup(data, len));
+}
+
+static void run_pager(struct grep_opt *opt, const char *prefix)
+{
+       struct string_list *path_list = opt->output_priv;
+       const char **argv = xmalloc(sizeof(const char *) * (path_list->nr + 1));
+       int i, status;
+
+       for (i = 0; i < path_list->nr; i++)
+               argv[i] = path_list->items[i].string;
+       argv[path_list->nr] = NULL;
+
+       if (prefix && chdir(prefix))
+               die("Failed to chdir: %s", prefix);
+       status = run_command_v_opt(argv, RUN_USING_SHELL);
+       if (status)
+               exit(status);
+       free(argv);
+}
+
 static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
 {
        int hit = 0;
@@ -590,7 +619,6 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
                if (hit && opt->status_only)
                        break;
        }
-       free_grep_patterns(opt);
        return hit;
 }
 
@@ -675,6 +703,25 @@ static int grep_object(struct grep_opt *opt, const char **paths,
        die("unable to grep from object of type %s", typename(obj->type));
 }
 
+static int grep_objects(struct grep_opt *opt, const char **paths,
+                       const struct object_array *list)
+{
+       unsigned int i;
+       int hit = 0;
+       const unsigned int nr = list->nr;
+
+       for (i = 0; i < nr; i++) {
+               struct object *real_obj;
+               real_obj = deref_tag(list->objects[i].item, NULL, 0);
+               if (grep_object(opt, paths, real_obj, list->objects[i].name)) {
+                       hit = 1;
+                       if (opt->status_only)
+                               break;
+               }
+       }
+       return hit;
+}
+
 static int grep_directory(struct grep_opt *opt, const char **paths)
 {
        struct dir_struct dir;
@@ -689,7 +736,6 @@ static int grep_directory(struct grep_opt *opt, const char **paths)
                if (hit && opt->status_only)
                        break;
        }
-       free_grep_patterns(opt);
        return hit;
 }
 
@@ -724,11 +770,15 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
        if (!patterns)
                die_errno("cannot open '%s'", arg);
        while (strbuf_getline(&sb, patterns, '\n') == 0) {
+               char *s;
+               size_t len;
+
                /* ignore empty line like grep does */
                if (sb.len == 0)
                        continue;
-               append_grep_pattern(grep_opt, strbuf_detach(&sb, NULL), arg,
-                                   ++lno, GREP_PATTERN);
+
+               s = strbuf_detach(&sb, &len);
+               append_grep_pat(grep_opt, s, len, arg, ++lno, GREP_PATTERN);
        }
        fclose(patterns);
        strbuf_release(&sb);
@@ -782,9 +832,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
        int cached = 0;
        int seen_dashdash = 0;
        int external_grep_allowed__ignored;
+       const char *show_in_pager = NULL, *default_pager = "dummy";
        struct grep_opt opt;
        struct object_array list = { 0, 0, NULL };
        const char **paths = NULL;
+       struct string_list path_list = { NULL, 0, 0, 0 };
        int i;
        int dummy;
        int nongit = 0, use_index = 1;
@@ -868,6 +920,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                OPT_BOOLEAN(0, "all-match", &opt.all_match,
                        "show only matches from files that match all patterns"),
                OPT_GROUP(""),
+               { OPTION_STRING, 'O', "open-files-in-pager", &show_in_pager,
+                       "pager", "show matching files in the pager",
+                       PARSE_OPT_OPTARG, NULL, (intptr_t)default_pager },
                OPT_BOOLEAN(0, "ext-grep", &external_grep_allowed__ignored,
                            "allow calling of grep(1) (ignored by this build)"),
                { OPTION_CALLBACK, 0, "help-all", &options, NULL, "show usage",
@@ -943,6 +998,18 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                argc--;
        }
 
+       if (show_in_pager == default_pager)
+               show_in_pager = git_pager(1);
+       if (show_in_pager) {
+               opt.color = 0;
+               opt.name_only = 1;
+               opt.null_following_name = 1;
+               opt.output_priv = &path_list;
+               opt.output = append_path;
+               string_list_append(&path_list, show_in_pager);
+               use_threads = 0;
+       }
+
        if (!opt.pattern_list)
                die("no pattern given.");
        if (!opt.fixed && opt.ignore_case)
@@ -999,44 +1066,51 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                paths[1] = NULL;
        }
 
+       if (show_in_pager && (cached || list.nr))
+               die("--open-files-in-pager only works on the worktree");
+
+       if (show_in_pager && opt.pattern_list && !opt.pattern_list->next) {
+               const char *pager = path_list.items[0].string;
+               int len = strlen(pager);
+
+               if (len > 4 && is_dir_sep(pager[len - 5]))
+                       pager += len - 4;
+
+               if (!strcmp("less", pager) || !strcmp("vi", pager)) {
+                       struct strbuf buf = STRBUF_INIT;
+                       strbuf_addf(&buf, "+/%s%s",
+                                       strcmp("less", pager) ? "" : "*",
+                                       opt.pattern_list->pattern);
+                       string_list_append(&path_list, buf.buf);
+                       strbuf_detach(&buf, NULL);
+               }
+       }
+
+       if (!show_in_pager)
+               setup_pager();
+
+
        if (!use_index) {
-               int hit;
                if (cached)
                        die("--cached cannot be used with --no-index.");
                if (list.nr)
                        die("--no-index cannot be used with revs.");
                hit = grep_directory(&opt, paths);
-               if (use_threads)
-                       hit |= wait_all();
-               return !hit;
-       }
-
-       if (!list.nr) {
-               int hit;
+       } else if (!list.nr) {
                if (!cached)
                        setup_work_tree();
 
                hit = grep_cache(&opt, paths, cached);
-               if (use_threads)
-                       hit |= wait_all();
-               return !hit;
-       }
-
-       if (cached)
-               die("both --cached and trees are given.");
-
-       for (i = 0; i < list.nr; i++) {
-               struct object *real_obj;
-               real_obj = deref_tag(list.objects[i].item, NULL, 0);
-               if (grep_object(&opt, paths, real_obj, list.objects[i].name)) {
-                       hit = 1;
-                       if (opt.status_only)
-                               break;
-               }
+       } else {
+               if (cached)
+                       die("both --cached and trees are given.");
+               hit = grep_objects(&opt, paths, &list);
        }
 
        if (use_threads)
                hit |= wait_all();
+       if (hit && show_in_pager)
+               run_pager(&opt, prefix);
        free_grep_patterns(&opt);
        return !hit;
 }
index 3182a2bec466c50a9a1db1e91888bad3335414b1..61ff79839bc4778451425d0ae1cfd199247954a1 100644 (file)
@@ -26,7 +26,7 @@ enum help_format {
        HELP_FORMAT_NONE,
        HELP_FORMAT_MAN,
        HELP_FORMAT_INFO,
-       HELP_FORMAT_WEB,
+       HELP_FORMAT_WEB
 };
 
 static int show_all = 0;
@@ -120,7 +120,7 @@ static void exec_woman_emacs(const char *path, const char *page)
                if (!path)
                        path = "emacsclient";
                strbuf_addf(&man_page, "(woman \"%s\")", page);
-               execlp(path, "emacsclient", "-e", man_page.buf, NULL);
+               execlp(path, "emacsclient", "-e", man_page.buf, (char *)NULL);
                warning("failed to exec '%s': %s", path, strerror(errno));
        }
 }
@@ -148,7 +148,7 @@ static void exec_man_konqueror(const char *path, const char *page)
                } else
                        path = "kfmclient";
                strbuf_addf(&man_page, "man:%s(1)", page);
-               execlp(path, filename, "newTab", man_page.buf, NULL);
+               execlp(path, filename, "newTab", man_page.buf, (char *)NULL);
                warning("failed to exec '%s': %s", path, strerror(errno));
        }
 }
@@ -157,7 +157,7 @@ static void exec_man_man(const char *path, const char *page)
 {
        if (!path)
                path = "man";
-       execlp(path, "man", page, NULL);
+       execlp(path, "man", page, (char *)NULL);
        warning("failed to exec '%s': %s", path, strerror(errno));
 }
 
@@ -165,7 +165,7 @@ static void exec_man_cmd(const char *cmd, const char *page)
 {
        struct strbuf shell_cmd = STRBUF_INIT;
        strbuf_addf(&shell_cmd, "%s %s", cmd, page);
-       execl("/bin/sh", "sh", "-c", shell_cmd.buf, NULL);
+       execl("/bin/sh", "sh", "-c", shell_cmd.buf, (char *)NULL);
        warning("failed to exec '%s': %s", cmd, strerror(errno));
 }
 
@@ -372,7 +372,7 @@ static void show_info_page(const char *git_cmd)
 {
        const char *page = cmd_to_page(git_cmd);
        setenv("INFOPATH", system_path(GIT_INFO_PATH), 1);
-       execlp("info", "info", "gitman", page, NULL);
+       execlp("info", "info", "gitman", page, (char *)NULL);
        die("no info viewer handled the request");
 }
 
@@ -398,7 +398,7 @@ static void get_html_page_path(struct strbuf *page_path, const char *page)
 #ifndef open_html
 static void open_html(const char *path)
 {
-       execl_git_cmd("web--browse", "-c", "help.browser", path, NULL);
+       execl_git_cmd("web--browse", "-c", "help.browser", path, (char *)NULL);
 }
 #endif
 
index a89ae831dd6251d7332e06470273d30fd9cb31eb..fad76bf7a84a6a103de20732752119d5245e9638 100644 (file)
@@ -884,6 +884,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage(index_pack_usage);
 
+       read_replace_refs = 0;
+
        /*
         * We wish to read the repository's config file if any, and
         * for that it is necessary to call setup_git_directory_gently().
index 6208703c061abb868201073795cf516bf81b2602..eaa1ee0fa71a344af747dec038c6a5907c8273a5 100644 (file)
@@ -24,6 +24,7 @@
 static const char *default_date_mode = NULL;
 
 static int default_show_root = 1;
+static int decoration_style;
 static const char *fmt_patch_subject_prefix = "PATCH";
 static const char *fmt_pretty;
 
@@ -31,11 +32,28 @@ static const char * const builtin_log_usage =
        "git log [<options>] [<since>..<until>] [[--] <path>...]\n"
        "   or: git show [options] <object>...";
 
+static int parse_decoration_style(const char *var, const char *value)
+{
+       switch (git_config_maybe_bool(var, value)) {
+       case 1:
+               return DECORATE_SHORT_REFS;
+       case 0:
+               return 0;
+       default:
+               break;
+       }
+       if (!strcmp(value, "full"))
+               return DECORATE_FULL_REFS;
+       else if (!strcmp(value, "short"))
+               return DECORATE_SHORT_REFS;
+       return -1;
+}
+
 static void cmd_log_init(int argc, const char **argv, const char *prefix,
                         struct rev_info *rev, struct setup_revision_opt *opt)
 {
        int i;
-       int decoration_style = 0;
+       int decoration_given = 0;
        struct userformat_want w;
 
        rev->abbrev = DEFAULT_ABBREV;
@@ -78,14 +96,15 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
                const char *arg = argv[i];
                if (!strcmp(arg, "--decorate")) {
                        decoration_style = DECORATE_SHORT_REFS;
+                       decoration_given = 1;
                } else if (!prefixcmp(arg, "--decorate=")) {
                        const char *v = skip_prefix(arg, "--decorate=");
-                       if (!strcmp(v, "full"))
-                               decoration_style = DECORATE_FULL_REFS;
-                       else if (!strcmp(v, "short"))
-                               decoration_style = DECORATE_SHORT_REFS;
-                       else
+                       decoration_style = parse_decoration_style(arg, v);
+                       if (decoration_style < 0)
                                die("invalid --decorate option: %s", arg);
+                       decoration_given = 1;
+               } else if (!strcmp(arg, "--no-decorate")) {
+                       decoration_style = 0;
                } else if (!strcmp(arg, "--source")) {
                        rev->show_source = 1;
                } else if (!strcmp(arg, "-h")) {
@@ -93,10 +112,20 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
                } else
                        die("unrecognized argument: %s", arg);
        }
+
+       /*
+        * defeat log.decorate configuration interacting with --pretty=raw
+        * from the command line.
+        */
+       if (!decoration_given && rev->pretty_given
+           && rev->commit_format == CMIT_FMT_RAW)
+               decoration_style = 0;
+
        if (decoration_style) {
                rev->show_decorations = 1;
                load_ref_decorations(decoration_style);
        }
+       setup_pager();
 }
 
 /*
@@ -258,10 +287,19 @@ static int git_log_config(const char *var, const char *value, void *cb)
                return git_config_string(&fmt_patch_subject_prefix, var, value);
        if (!strcmp(var, "log.date"))
                return git_config_string(&default_date_mode, var, value);
+       if (!strcmp(var, "log.decorate")) {
+               decoration_style = parse_decoration_style(var, value);
+               if (decoration_style < 0)
+                       decoration_style = 0; /* maybe warn? */
+               return 0;
+       }
        if (!strcmp(var, "log.showroot")) {
                default_show_root = git_config_bool(var, value);
                return 0;
        }
+       if (!prefixcmp(var, "color.decorate."))
+               return parse_decorate_color_config(var, 15, value);
+
        return git_diff_ui_config(var, value, cb);
 }
 
@@ -454,12 +492,6 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
        rev.use_terminator = 1;
        rev.always_show_header = 1;
 
-       /*
-        * We get called through "git reflog", so unlike the other log
-        * routines, we need to set up our pager manually..
-        */
-       setup_pager();
-
        return cmd_log_walk(&rev);
 }
 
@@ -501,13 +533,13 @@ static void add_header(const char *value)
                len--;
 
        if (!strncasecmp(value, "to: ", 4)) {
-               item = string_list_append(value + 4, &extra_to);
+               item = string_list_append(&extra_to, value + 4);
                len -= 4;
        } else if (!strncasecmp(value, "cc: ", 4)) {
-               item = string_list_append(value + 4, &extra_cc);
+               item = string_list_append(&extra_cc, value + 4);
                len -= 4;
        } else {
-               item = string_list_append(value, &extra_hdr);
+               item = string_list_append(&extra_hdr, value);
        }
 
        item->string[len] = '\0';
@@ -515,8 +547,9 @@ static void add_header(const char *value)
 
 #define THREAD_SHALLOW 1
 #define THREAD_DEEP 2
-static int thread = 0;
-static int do_signoff = 0;
+static int thread;
+static int do_signoff;
+static const char *signature = git_version_string;
 
 static int git_format_config(const char *var, const char *value, void *cb)
 {
@@ -531,13 +564,13 @@ static int git_format_config(const char *var, const char *value, void *cb)
        if (!strcmp(var, "format.to")) {
                if (!value)
                        return config_error_nonbool(var);
-               string_list_append(value, &extra_to);
+               string_list_append(&extra_to, value);
                return 0;
        }
        if (!strcmp(var, "format.cc")) {
                if (!value)
                        return config_error_nonbool(var);
-               string_list_append(value, &extra_cc);
+               string_list_append(&extra_cc, value);
                return 0;
        }
        if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
@@ -575,6 +608,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
                do_signoff = git_config_bool(var, value);
                return 0;
        }
+       if (!strcmp(var, "format.signature"))
+               return git_config_string(&signature, var, value);
 
        return git_log_config(var, value, cb);
 }
@@ -669,6 +704,12 @@ static void gen_message_id(struct rev_info *info, char *base)
        info->message_id = strbuf_detach(&buf, NULL);
 }
 
+static void print_signature(void)
+{
+       if (signature && *signature)
+               printf("-- \n%s\n\n", signature);
+}
+
 static void make_cover_letter(struct rev_info *rev, int use_stdout,
                              int numbered, int numbered_files,
                              struct commit *origin,
@@ -762,6 +803,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
        diff_flush(&opts);
 
        printf("\n");
+       print_signature();
 }
 
 static const char *clean_message_id(const char *msg_id)
@@ -915,7 +957,7 @@ static int to_callback(const struct option *opt, const char *arg, int unset)
        if (unset)
                string_list_clear(&extra_to, 0);
        else
-               string_list_append(arg, &extra_to);
+               string_list_append(&extra_to, arg);
        return 0;
 }
 
@@ -924,7 +966,7 @@ static int cc_callback(const struct option *opt, const char *arg, int unset)
        if (unset)
                string_list_clear(&extra_cc, 0);
        else
-               string_list_append(arg, &extra_cc);
+               string_list_append(&extra_cc, arg);
        return 0;
 }
 
@@ -1001,6 +1043,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                { OPTION_CALLBACK, 0, "thread", &thread, "style",
                            "enable message threading, styles: shallow, deep",
                            PARSE_OPT_OPTARG, thread_callback },
+               OPT_STRING(0, "signature", &signature, "signature",
+                           "add a signature"),
                OPT_END()
        };
 
@@ -1205,7 +1249,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
        if (in_reply_to) {
                const char *msgid = clean_message_id(in_reply_to);
-               string_list_append(msgid, rev.ref_message_ids);
+               string_list_append(rev.ref_message_ids, msgid);
        }
        rev.numbered_files = numbered_files;
        rev.patch_suffix = fmt_patch_suffix;
@@ -1252,8 +1296,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                                    && (!cover_letter || rev.nr > 1))
                                        free(rev.message_id);
                                else
-                                       string_list_append(rev.message_id,
-                                                          rev.ref_message_ids);
+                                       string_list_append(rev.ref_message_ids,
+                                                          rev.message_id);
                        }
                        gen_message_id(&rev, sha1_to_hex(commit->object.sha1));
                }
@@ -1279,7 +1323,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                                       mime_boundary_leader,
                                       rev.mime_boundary);
                        else
-                               printf("-- \n%s\n\n", git_version_string);
+                               print_signature();
                }
                if (!use_stdout)
                        fclose(stdout);
index 080404769365fef8176c75fff5f526cf6138df6a..1b9b8a8b4ac2baff6b9676bcf23b148f147dac6a 100644 (file)
@@ -190,7 +190,7 @@ static void show_ru_info(void)
 {
        if (!the_index.resolve_undo)
                return;
-       for_each_string_list(show_one_ru, the_index.resolve_undo, NULL);
+       for_each_string_list(the_index.resolve_undo, show_one_ru, NULL);
 }
 
 static void show_files(struct dir_struct *dir)
index 70f5622d9d49aae4080b38ee4487cc6e403a9d2c..34480cfad6a8842d65ae61f6257c597a2a987b33 100644 (file)
@@ -4,7 +4,8 @@
 #include "remote.h"
 
 static const char ls_remote_usage[] =
-"git ls-remote [--heads] [--tags]  [-u <exec> | --upload-pack <exec>] <repository> <refs>...";
+"git ls-remote [--heads] [--tags]  [-u <exec> | --upload-pack <exec>]\n"
+"                     [-q|--quiet] [<repository> [<refs>...]]";
 
 /*
  * Is there one among the list of patterns that match the tail part
@@ -33,6 +34,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
        const char *dest = NULL;
        int nongit;
        unsigned flags = 0;
+       int quiet = 0;
        const char *uploadpack = NULL;
        const char **pattern = NULL;
 
@@ -66,6 +68,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                                flags |= REF_NORMAL;
                                continue;
                        }
+                       if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) {
+                               quiet = 1;
+                               continue;
+                       }
                        usage(ls_remote_usage);
                }
                dest = arg;
@@ -73,9 +79,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                break;
        }
 
-       if (!dest)
-               usage(ls_remote_usage);
-
        if (argv[i]) {
                int j;
                pattern = xcalloc(sizeof(const char *), argc - i + 1);
@@ -87,6 +90,11 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                }
        }
        remote = remote_get(dest);
+       if (!remote) {
+               if (dest)
+                       die("bad repository '%s'", dest);
+               die("No remote configured to list refs from.");
+       }
        if (!remote->url_nr)
                die("remote %s has no configured URL", dest);
        transport = transport_get(remote, NULL);
@@ -96,6 +104,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
        ref = transport_get_remote_refs(transport);
        if (transport_disconnect(transport))
                return 1;
+
+       if (!dest && !quiet)
+               fprintf(stderr, "From %s\n", *remote->url);
        for ( ; ref; ref = ref->next) {
                if (!check_ref_type(ref, flags))
                        continue;
index 4a9729b9b388a1e589e9250d8157e723c68140de..2320d981ceab220e287e42c21f3c9f3be5b3722f 100644 (file)
@@ -17,10 +17,10 @@ static struct strbuf name = STRBUF_INIT;
 static struct strbuf email = STRBUF_INIT;
 
 static enum  {
-       TE_DONTCARE, TE_QP, TE_BASE64,
+       TE_DONTCARE, TE_QP, TE_BASE64
 } transfer_encoding;
 static enum  {
-       TYPE_TEXT, TYPE_OTHER,
+       TYPE_TEXT, TYPE_OTHER
 } message_type;
 
 static struct strbuf charset = STRBUF_INIT;
index cdfc1b70429dc5d47e42e7aabc9449a585623b0f..e4560da19138cd67843f93a05bc6509d51cfe076 100644 (file)
@@ -121,7 +121,7 @@ static int populate_maildir_list(struct string_list *list, const char *path)
                        if (dent->d_name[0] == '.')
                                continue;
                        snprintf(name, sizeof(name), "%s/%s", *sub, dent->d_name);
-                       string_list_insert(name, list);
+                       string_list_insert(list, name);
                }
 
                closedir(dir);
index d8875d589240e0c78a9e241a7d2bdde1d10ab800..3d00adbfc79aa0d5e4e6b3367bc5b70f8df36857 100644 (file)
@@ -3,6 +3,9 @@
 #include "tag.h"
 #include "merge-recursive.h"
 
+static const char builtin_merge_recursive_usage[] =
+       "git %s <base>... -- <head> <remote> ...";
+
 static const char *better_branch_name(const char *branch)
 {
        static char githead_env[8 + 40 + 1];
@@ -29,7 +32,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
                o.subtree_shift = "";
 
        if (argc < 4)
-               usagef("%s <base>... -- <head> <remote> ...", argv[0]);
+               usagef(builtin_merge_recursive_usage, argv[0]);
 
        for (i = 1; i < argc; ++i) {
                const char *arg = argv[i];
index fc00d794d641c146023a78d7d8e4143f0fdac302..9b25ddc9794efe489ee9ec9fd3203ffa997f03f7 100644 (file)
@@ -60,6 +60,7 @@ static void *result(struct merge_list *entry, unsigned long *size)
 {
        enum object_type type;
        struct blob *base, *our, *their;
+       const char *path = entry->path;
 
        if (!entry->stage)
                return read_sha1_file(entry->blob->object.sha1, &type, size);
@@ -76,7 +77,7 @@ static void *result(struct merge_list *entry, unsigned long *size)
        their = NULL;
        if (entry)
                their = entry->blob;
-       return merge_file(entry->path, base, our, their, size);
+       return merge_file(path, base, our, their, size);
 }
 
 static void *origin(struct merge_list *entry, unsigned long *size)
index cae1cbee26535635cfe0d7e3a6f98e3a36e94cf7..37ce4f589f6582abf0d1ef5bd263f590a16853d5 100644 (file)
@@ -548,13 +548,53 @@ static void write_tree_trivial(unsigned char *sha1)
                die("git write-tree failed to write a tree");
 }
 
-static int try_merge_strategy(const char *strategy, struct commit_list *common,
-                             const char *head_arg)
+int try_merge_command(const char *strategy, struct commit_list *common,
+                     const char *head_arg, struct commit_list *remotes)
 {
        const char **args;
        int i = 0, x = 0, ret;
        struct commit_list *j;
        struct strbuf buf = STRBUF_INIT;
+
+       args = xmalloc((4 + xopts_nr + commit_list_count(common) +
+                       commit_list_count(remotes)) * sizeof(char *));
+       strbuf_addf(&buf, "merge-%s", strategy);
+       args[i++] = buf.buf;
+       for (x = 0; x < xopts_nr; x++) {
+               char *s = xmalloc(strlen(xopts[x])+2+1);
+               strcpy(s, "--");
+               strcpy(s+2, xopts[x]);
+               args[i++] = s;
+       }
+       for (j = common; j; j = j->next)
+               args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
+       args[i++] = "--";
+       args[i++] = head_arg;
+       for (j = remotes; j; j = j->next)
+               args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
+       args[i] = NULL;
+       ret = run_command_v_opt(args, RUN_GIT_CMD);
+       strbuf_release(&buf);
+       i = 1;
+       for (x = 0; x < xopts_nr; x++)
+               free((void *)args[i++]);
+       for (j = common; j; j = j->next)
+               free((void *)args[i++]);
+       i += 2;
+       for (j = remotes; j; j = j->next)
+               free((void *)args[i++]);
+       free(args);
+       discard_cache();
+       if (read_cache() < 0)
+               die("failed to read the cache");
+       resolve_undo_clear();
+
+       return ret;
+}
+
+static int try_merge_strategy(const char *strategy, struct commit_list *common,
+                             const char *head_arg)
+{
        int index_fd;
        struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
 
@@ -567,12 +607,13 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
        rollback_lock_file(lock);
 
        if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
-               int clean;
+               int clean, x;
                struct commit *result;
                struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
                int index_fd;
                struct commit_list *reversed = NULL;
                struct merge_options o;
+               struct commit_list *j;
 
                if (remoteheads->next) {
                        error("Not handling anything other than two heads merge.");
@@ -612,39 +653,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
                rollback_lock_file(lock);
                return clean ? 0 : 1;
        } else {
-               args = xmalloc((4 + xopts_nr + commit_list_count(common) +
-                                       commit_list_count(remoteheads)) * sizeof(char *));
-               strbuf_addf(&buf, "merge-%s", strategy);
-               args[i++] = buf.buf;
-               for (x = 0; x < xopts_nr; x++) {
-                       char *s = xmalloc(strlen(xopts[x])+2+1);
-                       strcpy(s, "--");
-                       strcpy(s+2, xopts[x]);
-                       args[i++] = s;
-               }
-               for (j = common; j; j = j->next)
-                       args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
-               args[i++] = "--";
-               args[i++] = head_arg;
-               for (j = remoteheads; j; j = j->next)
-                       args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
-               args[i] = NULL;
-               ret = run_command_v_opt(args, RUN_GIT_CMD);
-               strbuf_release(&buf);
-               i = 1;
-               for (x = 0; x < xopts_nr; x++)
-                       free((void *)args[i++]);
-               for (j = common; j; j = j->next)
-                       free((void *)args[i++]);
-               i += 2;
-               for (j = remoteheads; j; j = j->next)
-                       free((void *)args[i++]);
-               free(args);
-               discard_cache();
-               if (read_cache() < 0)
-                       die("failed to read the cache");
-               resolve_undo_clear();
-               return ret;
+               return try_merge_command(strategy, common, head_arg, remoteheads);
        }
 }
 
index c07f53b34380200eaba223d2e1f8f977c1f9fd18..38574b89f7cfc127b2ea5044b3ebb5dabe726fb4 100644 (file)
@@ -180,7 +180,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                } else if (string_list_has_string(&src_for_dst, dst))
                        bad = "multiple sources for the same target";
                else
-                       string_list_insert(dst, &src_for_dst);
+                       string_list_insert(&src_for_dst, dst);
 
                if (bad) {
                        if (ignore_errors) {
index f678f9cb520fa331de4899e372502cffccd9682c..fbc347c9f09e0da4ba43982a5f7b29882080f150 100644 (file)
@@ -26,7 +26,7 @@ static const char * const git_notes_usage[] = {
        "git notes [--ref <notes_ref>] edit [<object>]",
        "git notes [--ref <notes_ref>] show [<object>]",
        "git notes [--ref <notes_ref>] remove [<object>]",
-       "git notes [--ref <notes_ref>] prune",
+       "git notes [--ref <notes_ref>] prune [-n | -v]",
        NULL
 };
 
@@ -67,7 +67,7 @@ static const char * const git_notes_remove_usage[] = {
 };
 
 static const char * const git_notes_prune_usage[] = {
-       "git notes prune",
+       "git notes prune [<options>]",
        NULL
 };
 
@@ -796,7 +796,11 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
 static int prune(int argc, const char **argv, const char *prefix)
 {
        struct notes_tree *t;
+       int show_only = 0, verbose = 0;
        struct option options[] = {
+               OPT_BOOLEAN('n', "dry-run", &show_only,
+                           "do not remove, show only"),
+               OPT_BOOLEAN('v', "verbose", &verbose, "report pruned notes"),
                OPT_END()
        };
 
@@ -810,8 +814,10 @@ static int prune(int argc, const char **argv, const char *prefix)
 
        t = init_notes_check("prune");
 
-       prune_notes(t);
-       commit_notes(t, "Notes removed by 'git notes prune'");
+       prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
+               (show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );
+       if (!show_only)
+               commit_notes(t, "Notes removed by 'git notes prune'");
        free_notes(t);
        return 0;
 }
index 214d7ef2b12d41e8d70539fe4a4b16fde71a780a..0e8167311884d38c48a9421bf8aede89e7f2c22d 100644 (file)
@@ -1529,6 +1529,8 @@ static void try_to_free_from_threads(size_t size)
        read_unlock();
 }
 
+try_to_free_t old_try_to_free_routine;
+
 /*
  * The main thread waits on the condition that (at least) one of the workers
  * has stopped working (which is indicated in the .working member of
@@ -1563,12 +1565,12 @@ static void init_threaded_search(void)
        pthread_mutex_init(&cache_mutex, NULL);
        pthread_mutex_init(&progress_mutex, NULL);
        pthread_cond_init(&progress_cond, NULL);
-       set_try_to_free_routine(try_to_free_from_threads);
+       old_try_to_free_routine = set_try_to_free_routine(try_to_free_from_threads);
 }
 
 static void cleanup_threaded_search(void)
 {
-       set_try_to_free_routine(NULL);
+       set_try_to_free_routine(old_try_to_free_routine);
        pthread_cond_destroy(&progress_cond);
        pthread_mutex_destroy(&read_mutex);
        pthread_mutex_destroy(&cache_mutex);
index af0911e4bd54848eadc7485c985e2a010e720e7f..512530022edac398f8541ee6c400c7312659e730 100644 (file)
@@ -28,16 +28,42 @@ static int remove_space(char *line)
        return dst - line;
 }
 
-static void generate_id_list(void)
+static int scan_hunk_header(const char *p, int *p_before, int *p_after)
+{
+       static const char digits[] = "0123456789";
+       const char *q, *r;
+       int n;
+
+       q = p + 4;
+       n = strspn(q, digits);
+       if (q[n] == ',') {
+               q += n + 1;
+               n = strspn(q, digits);
+       }
+       if (n == 0 || q[n] != ' ' || q[n+1] != '+')
+               return 0;
+
+       r = q + n + 2;
+       n = strspn(r, digits);
+       if (r[n] == ',') {
+               r += n + 1;
+               n = strspn(r, digits);
+       }
+       if (n == 0)
+               return 0;
+
+       *p_before = atoi(q);
+       *p_after = atoi(r);
+       return 1;
+}
+
+int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx)
 {
-       static unsigned char sha1[20];
        static char line[1000];
-       git_SHA_CTX ctx;
-       int patchlen = 0;
+       int patchlen = 0, found_next = 0;
+       int before = -1, after = -1;
 
-       git_SHA1_Init(&ctx);
        while (fgets(line, sizeof(line), stdin) != NULL) {
-               unsigned char n[20];
                char *p = line;
                int len;
 
@@ -45,32 +71,75 @@ static void generate_id_list(void)
                        p += 10;
                else if (!memcmp(line, "commit ", 7))
                        p += 7;
+               else if (!memcmp(line, "From ", 5))
+                       p += 5;
 
-               if (!get_sha1_hex(p, n)) {
-                       flush_current_id(patchlen, sha1, &ctx);
-                       hashcpy(sha1, n);
-                       patchlen = 0;
-                       continue;
+               if (!get_sha1_hex(p, next_sha1)) {
+                       found_next = 1;
+                       break;
                }
 
                /* Ignore commit comments */
                if (!patchlen && memcmp(line, "diff ", 5))
                        continue;
 
-               /* Ignore git-diff index header */
-               if (!memcmp(line, "index ", 6))
-                       continue;
+               /* Parsing diff header?  */
+               if (before == -1) {
+                       if (!memcmp(line, "index ", 6))
+                               continue;
+                       else if (!memcmp(line, "--- ", 4))
+                               before = after = 1;
+                       else if (!isalpha(line[0]))
+                               break;
+               }
 
-               /* Ignore line numbers when computing the SHA1 of the patch */
-               if (!memcmp(line, "@@ -", 4))
-                       continue;
+               /* Looking for a valid hunk header?  */
+               if (before == 0 && after == 0) {
+                       if (!memcmp(line, "@@ -", 4)) {
+                               /* Parse next hunk, but ignore line numbers.  */
+                               scan_hunk_header(line, &before, &after);
+                               continue;
+                       }
+
+                       /* Split at the end of the patch.  */
+                       if (memcmp(line, "diff ", 5))
+                               break;
+
+                       /* Else we're parsing another header.  */
+                       before = after = -1;
+               }
+
+               /* If we get here, we're inside a hunk.  */
+               if (line[0] == '-' || line[0] == ' ')
+                       before--;
+               if (line[0] == '+' || line[0] == ' ')
+                       after--;
 
                /* Compute the sha without whitespace */
                len = remove_space(line);
                patchlen += len;
-               git_SHA1_Update(&ctx, line, len);
+               git_SHA1_Update(ctx, line, len);
+       }
+
+       if (!found_next)
+               hashclr(next_sha1);
+
+       return patchlen;
+}
+
+static void generate_id_list(void)
+{
+       unsigned char sha1[20], n[20];
+       git_SHA_CTX ctx;
+       int patchlen;
+
+       git_SHA1_Init(&ctx);
+       hashclr(sha1);
+       while (!feof(stdin)) {
+               patchlen = get_one_patchid(n, &ctx);
+               flush_current_id(patchlen, sha1, &ctx);
+               hashcpy(sha1, n);
        }
-       flush_current_id(patchlen, sha1, &ctx);
 }
 
 static const char patch_id_usage[] = "git patch-id < patch";
index 81f915ec315eb75e529fed8f2f6bab436755f598..99218ba49e2c6ea7ff7185e6397bb73bca213a66 100644 (file)
@@ -125,10 +125,9 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 {
        struct rev_info revs;
        const struct option options[] = {
-               OPT_BOOLEAN('n', NULL, &show_only,
+               OPT_BOOLEAN('n', "dry-run", &show_only,
                            "do not remove, show only"),
-               OPT_BOOLEAN('v', NULL, &verbose,
-                       "report pruned objects"),
+               OPT_BOOLEAN('v', "verbose", &verbose, "report pruned objects"),
                OPT_DATE(0, "expire", &expire,
                         "expire objects older than <time>"),
                OPT_END()
index f4358b9d230f6d8d7a9a67fdfbc60279c5ec71ee..69bc2f27ac414ce3532f6babcc68671b0b95d65a 100644 (file)
@@ -130,8 +130,8 @@ static int push_with_options(struct transport *transport, int flags)
 
        if (nonfastforward && advice_push_nonfastforward) {
                fprintf(stderr, "To prevent you from losing history, non-fast-forward updates were rejected\n"
-                               "Merge the remote changes before pushing again.  See the 'Note about\n"
-                               "fast-forwards' section of 'git push --help' for details.\n");
+                               "Merge the remote changes (e.g. 'git pull') before pushing again.  See the\n"
+                               "'Note about fast-forwards' section of 'git push --help' for details.\n");
        }
 
        return 1;
index 8bdcab11389e8b4facab355f27f0e1926134b86f..9ad1e66916545dd2aeeb110661e56edfa5921019 100644 (file)
@@ -219,14 +219,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
         * "-m ent" or "--reset ent" form), we can obtain a fully
         * valid cache-tree because the index must match exactly
         * what came from the tree.
-        *
-        * The same holds true if we are switching between two trees
-        * using read-tree -m A B.  The index must match B after that.
         */
        if (nr_trees == 1 && !opts.prefix)
                prime_cache_tree(&active_cache_tree, trees[0]);
-       else if (nr_trees == 2 && opts.merge)
-               prime_cache_tree(&active_cache_tree, trees[1]);
 
        if (write_cache(newfd, active_cache, active_nr) ||
            commit_locked_index(&lock_file))
index 7e4129ddc85e1408300947ff9c041524a1c10f48..d634b5a3d5212b8e49217d94430c294b911dfc7d 100644 (file)
@@ -17,7 +17,7 @@ enum deny_action {
        DENY_UNCONFIGURED,
        DENY_IGNORE,
        DENY_WARN,
-       DENY_REFUSE,
+       DENY_REFUSE
 };
 
 static int deny_deletes;
@@ -501,7 +501,7 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
        if (!(flag & REF_ISSYMREF))
                return;
 
-       if ((item = string_list_lookup(dst_name, list)) == NULL)
+       if ((item = string_list_lookup(list, dst_name)) == NULL)
                return;
 
        cmd->skip_update = 1;
@@ -534,7 +534,7 @@ static void check_aliased_updates(struct command *commands)
 
        for (cmd = commands; cmd; cmd = cmd->next) {
                struct string_list_item *item =
-                       string_list_append(cmd->ref_name, &ref_list);
+                       string_list_append(&ref_list, cmd->ref_name);
                item->util = (void *)cmd;
        }
        sort_string_list(&ref_list);
index bd7880dc04830253daae932ba534f02db85f6d2a..ebf610e64a267c5ca769d70203b282fb8f96a434 100644 (file)
@@ -34,8 +34,13 @@ struct cmd_reflog_expire_cb {
 
 struct expire_reflog_cb {
        FILE *newlog;
-       const char *ref;
-       struct commit *ref_commit;
+       enum {
+               UE_NORMAL,
+               UE_ALWAYS,
+               UE_HEAD
+       } unreachable_expire_kind;
+       struct commit_list *mark_list;
+       unsigned long mark_limit;
        struct cmd_reflog_expire_cb *cmd;
        unsigned char last_kept_sha1[20];
 };
@@ -210,46 +215,23 @@ static int keep_entry(struct commit **it, unsigned char *sha1)
        return 1;
 }
 
-static int unreachable(struct expire_reflog_cb *cb, struct commit *commit, unsigned char *sha1)
+/*
+ * Starting from commits in the cb->mark_list, mark commits that are
+ * reachable from them.  Stop the traversal at commits older than
+ * the expire_limit and queue them back, so that the caller can call
+ * us again to restart the traversal with longer expire_limit.
+ */
+static void mark_reachable(struct expire_reflog_cb *cb)
 {
-       /*
-        * We may or may not have the commit yet - if not, look it
-        * up using the supplied sha1.
-        */
-       if (!commit) {
-               if (is_null_sha1(sha1))
-                       return 0;
-
-               commit = lookup_commit_reference_gently(sha1, 1);
-
-               /* Not a commit -- keep it */
-               if (!commit)
-                       return 0;
-       }
-
-       /* Reachable from the current ref?  Don't prune. */
-       if (commit->object.flags & REACHABLE)
-               return 0;
-       if (in_merge_bases(commit, &cb->ref_commit, 1))
-               return 0;
-
-       /* We can't reach it - prune it. */
-       return 1;
-}
+       struct commit *commit;
+       struct commit_list *pending;
+       unsigned long expire_limit = cb->mark_limit;
+       struct commit_list *leftover = NULL;
 
-static void mark_reachable(struct commit *commit, unsigned long expire_limit)
-{
-       /*
-        * We need to compute whether the commit on either side of a reflog
-        * entry is reachable from the tip of the ref for all entries.
-        * Mark commits that are reachable from the tip down to the
-        * time threshold first; we know a commit marked thusly is
-        * reachable from the tip without running in_merge_bases()
-        * at all.
-        */
-       struct commit_list *pending = NULL;
+       for (pending = cb->mark_list; pending; pending = pending->next)
+               pending->item->object.flags &= ~REACHABLE;
 
-       commit_list_insert(commit, &pending);
+       pending = cb->mark_list;
        while (pending) {
                struct commit_list *entry = pending;
                struct commit_list *parent;
@@ -261,8 +243,11 @@ static void mark_reachable(struct commit *commit, unsigned long expire_limit)
                if (parse_commit(commit))
                        continue;
                commit->object.flags |= REACHABLE;
-               if (commit->date < expire_limit)
+               if (commit->date < expire_limit) {
+                       commit_list_insert(commit, &leftover);
                        continue;
+               }
+               commit->object.flags |= REACHABLE;
                parent = commit->parents;
                while (parent) {
                        commit = parent->item;
@@ -272,6 +257,36 @@ static void mark_reachable(struct commit *commit, unsigned long expire_limit)
                        commit_list_insert(commit, &pending);
                }
        }
+       cb->mark_list = leftover;
+}
+
+static int unreachable(struct expire_reflog_cb *cb, struct commit *commit, unsigned char *sha1)
+{
+       /*
+        * We may or may not have the commit yet - if not, look it
+        * up using the supplied sha1.
+        */
+       if (!commit) {
+               if (is_null_sha1(sha1))
+                       return 0;
+
+               commit = lookup_commit_reference_gently(sha1, 1);
+
+               /* Not a commit -- keep it */
+               if (!commit)
+                       return 0;
+       }
+
+       /* Reachable from the current ref?  Don't prune. */
+       if (commit->object.flags & REACHABLE)
+               return 0;
+
+       if (cb->mark_list && cb->mark_limit) {
+               cb->mark_limit = 0; /* dig down to the root */
+               mark_reachable(cb);
+       }
+
+       return !(commit->object.flags & REACHABLE);
 }
 
 static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
@@ -293,7 +308,7 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
                goto prune;
 
        if (timestamp < cb->cmd->expire_unreachable) {
-               if (!cb->ref_commit)
+               if (cb->unreachable_expire_kind == UE_ALWAYS)
                        goto prune;
                if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1))
                        goto prune;
@@ -320,12 +335,27 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
        return 0;
 }
 
+static int push_tip_to_list(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
+{
+       struct commit_list **list = cb_data;
+       struct commit *tip_commit;
+       if (flags & REF_ISSYMREF)
+               return 0;
+       tip_commit = lookup_commit_reference_gently(sha1, 1);
+       if (!tip_commit)
+               return 0;
+       commit_list_insert(tip_commit, list);
+       return 0;
+}
+
 static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, void *cb_data)
 {
        struct cmd_reflog_expire_cb *cmd = cb_data;
        struct expire_reflog_cb cb;
        struct ref_lock *lock;
        char *log_file, *newlog_path = NULL;
+       struct commit *tip_commit;
+       struct commit_list *tips;
        int status = 0;
 
        memset(&cb, 0, sizeof(cb));
@@ -345,14 +375,49 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
                cb.newlog = fopen(newlog_path, "w");
        }
 
-       cb.ref_commit = lookup_commit_reference_gently(sha1, 1);
-       cb.ref = ref;
        cb.cmd = cmd;
-       if (cb.ref_commit)
-               mark_reachable(cb.ref_commit, cmd->expire_total);
+
+       if (!cmd->expire_unreachable || !strcmp(ref, "HEAD")) {
+               tip_commit = NULL;
+               cb.unreachable_expire_kind = UE_HEAD;
+       } else {
+               tip_commit = lookup_commit_reference_gently(sha1, 1);
+               if (!tip_commit)
+                       cb.unreachable_expire_kind = UE_ALWAYS;
+               else
+                       cb.unreachable_expire_kind = UE_NORMAL;
+       }
+
+       if (cmd->expire_unreachable <= cmd->expire_total)
+               cb.unreachable_expire_kind = UE_ALWAYS;
+
+       cb.mark_list = NULL;
+       tips = NULL;
+       if (cb.unreachable_expire_kind != UE_ALWAYS) {
+               if (cb.unreachable_expire_kind == UE_HEAD) {
+                       struct commit_list *elem;
+                       for_each_ref(push_tip_to_list, &tips);
+                       for (elem = tips; elem; elem = elem->next)
+                               commit_list_insert(elem->item, &cb.mark_list);
+               } else {
+                       commit_list_insert(tip_commit, &cb.mark_list);
+               }
+               cb.mark_limit = cmd->expire_total;
+               mark_reachable(&cb);
+       }
+
        for_each_reflog_ent(ref, expire_reflog_ent, &cb);
-       if (cb.ref_commit)
-               clear_commit_marks(cb.ref_commit, REACHABLE);
+
+       if (cb.unreachable_expire_kind != UE_ALWAYS) {
+               if (cb.unreachable_expire_kind == UE_HEAD) {
+                       struct commit_list *elem;
+                       for (elem = tips; elem; elem = elem->next)
+                               clear_commit_marks(tip_commit, REACHABLE);
+                       free_commit_list(tips);
+               } else {
+                       clear_commit_marks(tip_commit, REACHABLE);
+               }
+       }
  finish:
        if (cb.newlog) {
                if (fclose(cb.newlog)) {
index 277765b864202b2b6f20069e0cb3f95eaef4fcaa..6699bc571235167f5cae60106522c09a10ae341d 100644 (file)
@@ -16,6 +16,7 @@ static const char * const builtin_remote_usage[] = {
        "git remote [-v | --verbose] show [-n] <name>",
        "git remote prune [-n | --dry-run] <name>",
        "git remote [-v | --verbose] update [-p | --prune] [group | remote]",
+       "git remote set-branches <name> [--add] <branch>...",
        "git remote set-url <name> <newurl> [<oldurl>]",
        "git remote set-url --add <name> <newurl>",
        "git remote set-url --delete <name> <url>",
@@ -42,6 +43,12 @@ static const char * const builtin_remote_sethead_usage[] = {
        NULL
 };
 
+static const char * const builtin_remote_setbranches_usage[] = {
+       "git remote set-branches <name> <branch>...",
+       "git remote set-branches --add <name> <branch>...",
+       NULL
+};
+
 static const char * const builtin_remote_show_usage[] = {
        "git remote show [<options>] <name>",
        NULL
@@ -87,7 +94,7 @@ static int opt_parse_track(const struct option *opt, const char *arg, int not)
        if (not)
                string_list_clear(list, 0);
        else
-               string_list_append(arg, list);
+               string_list_append(list, arg);
        return 0;
 }
 
@@ -104,9 +111,29 @@ static int fetch_remote(const char *name)
        return 0;
 }
 
+enum {
+       TAGS_UNSET = 0,
+       TAGS_DEFAULT = 1,
+       TAGS_SET = 2
+};
+
+static int add_branch(const char *key, const char *branchname,
+               const char *remotename, int mirror, struct strbuf *tmp)
+{
+       strbuf_reset(tmp);
+       strbuf_addch(tmp, '+');
+       if (mirror)
+               strbuf_addf(tmp, "refs/%s:refs/%s",
+                               branchname, branchname);
+       else
+               strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s",
+                               branchname, remotename, branchname);
+       return git_config_set_multivar(key, tmp->buf, "^$", 0);
+}
+
 static int add(int argc, const char **argv)
 {
-       int fetch = 0, mirror = 0;
+       int fetch = 0, mirror = 0, fetch_tags = TAGS_DEFAULT;
        struct string_list track = { NULL, 0, 0 };
        const char *master = NULL;
        struct remote *remote;
@@ -116,6 +143,11 @@ static int add(int argc, const char **argv)
 
        struct option options[] = {
                OPT_BOOLEAN('f', "fetch", &fetch, "fetch the remote branches"),
+               OPT_SET_INT(0, "tags", &fetch_tags,
+                           "import all tags and associated objects when fetching",
+                           TAGS_SET),
+               OPT_SET_INT(0, NULL, &fetch_tags,
+                           "or do not fetch any tag at all (--no-tags)", TAGS_UNSET),
                OPT_CALLBACK('t', "track", &track, "branch",
                        "branch(es) to track", opt_parse_track),
                OPT_STRING('m', "master", &master, "branch", "master branch"),
@@ -149,19 +181,10 @@ static int add(int argc, const char **argv)
        strbuf_addf(&buf, "remote.%s.fetch", name);
 
        if (track.nr == 0)
-               string_list_append("*", &track);
+               string_list_append(&track, "*");
        for (i = 0; i < track.nr; i++) {
-               struct string_list_item *item = track.items + i;
-
-               strbuf_reset(&buf2);
-               strbuf_addch(&buf2, '+');
-               if (mirror)
-                       strbuf_addf(&buf2, "refs/%s:refs/%s",
-                                       item->string, item->string);
-               else
-                       strbuf_addf(&buf2, "refs/heads/%s:refs/remotes/%s/%s",
-                                       item->string, name, item->string);
-               if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
+               if (add_branch(buf.buf, track.items[i].string,
+                               name, mirror, &buf2))
                        return 1;
        }
 
@@ -172,6 +195,14 @@ static int add(int argc, const char **argv)
                        return 1;
        }
 
+       if (fetch_tags != TAGS_DEFAULT) {
+               strbuf_reset(&buf);
+               strbuf_addf(&buf, "remote.%s.tagopt", name);
+               if (git_config_set(buf.buf,
+                       fetch_tags == TAGS_SET ? "--tags" : "--no-tags"))
+                       return 1;
+       }
+
        if (fetch && fetch_remote(name))
                return 1;
 
@@ -232,7 +263,7 @@ static int config_read_branches(const char *key, const char *value, void *cb)
                } else
                        return 0;
 
-               item = string_list_insert(name, &branch_list);
+               item = string_list_insert(&branch_list, name);
 
                if (!item->util)
                        item->util = xcalloc(sizeof(struct branch_info), 1);
@@ -247,11 +278,11 @@ static int config_read_branches(const char *key, const char *value, void *cb)
                        while (space) {
                                char *merge;
                                merge = xstrndup(value, space - value);
-                               string_list_append(merge, &info->merge);
+                               string_list_append(&info->merge, merge);
                                value = abbrev_branch(space + 1);
                                space = strchr(value, ' ');
                        }
-                       string_list_append(xstrdup(value), &info->merge);
+                       string_list_append(&info->merge, xstrdup(value));
                } else
                        info->rebase = git_config_bool(orig_key, value);
        }
@@ -288,14 +319,14 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
        for (ref = fetch_map; ref; ref = ref->next) {
                unsigned char sha1[20];
                if (!ref->peer_ref || read_ref(ref->peer_ref->name, sha1))
-                       string_list_append(abbrev_branch(ref->name), &states->new);
+                       string_list_append(&states->new, abbrev_branch(ref->name));
                else
-                       string_list_append(abbrev_branch(ref->name), &states->tracked);
+                       string_list_append(&states->tracked, abbrev_branch(ref->name));
        }
        stale_refs = get_stale_heads(states->remote, fetch_map);
        for (ref = stale_refs; ref; ref = ref->next) {
                struct string_list_item *item =
-                       string_list_append(abbrev_branch(ref->name), &states->stale);
+                       string_list_append(&states->stale, abbrev_branch(ref->name));
                item->util = xstrdup(ref->name);
        }
        free_refs(stale_refs);
@@ -317,7 +348,7 @@ struct push_info {
                PUSH_STATUS_UPTODATE,
                PUSH_STATUS_FASTFORWARD,
                PUSH_STATUS_OUTOFDATE,
-               PUSH_STATUS_NOTQUERIED,
+               PUSH_STATUS_NOTQUERIED
        } status;
 };
 
@@ -344,8 +375,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
                        continue;
                hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
 
-               item = string_list_append(abbrev_branch(ref->peer_ref->name),
-                                         &states->push);
+               item = string_list_append(&states->push,
+                                         abbrev_branch(ref->peer_ref->name));
                item->util = xcalloc(sizeof(struct push_info), 1);
                info = item->util;
                info->forced = ref->force;
@@ -380,7 +411,7 @@ static int get_push_ref_states_noquery(struct ref_states *states)
 
        states->push.strdup_strings = 1;
        if (!remote->push_refspec_nr) {
-               item = string_list_append("(matching)", &states->push);
+               item = string_list_append(&states->push, "(matching)");
                info = item->util = xcalloc(sizeof(struct push_info), 1);
                info->status = PUSH_STATUS_NOTQUERIED;
                info->dest = xstrdup(item->string);
@@ -388,11 +419,11 @@ static int get_push_ref_states_noquery(struct ref_states *states)
        for (i = 0; i < remote->push_refspec_nr; i++) {
                struct refspec *spec = remote->push + i;
                if (spec->matching)
-                       item = string_list_append("(matching)", &states->push);
+                       item = string_list_append(&states->push, "(matching)");
                else if (strlen(spec->src))
-                       item = string_list_append(spec->src, &states->push);
+                       item = string_list_append(&states->push, spec->src);
                else
-                       item = string_list_append("(delete)", &states->push);
+                       item = string_list_append(&states->push, "(delete)");
 
                info = item->util = xcalloc(sizeof(struct push_info), 1);
                info->forced = spec->force;
@@ -416,7 +447,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
        matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
                                    fetch_map, 1);
        for (ref = matches; ref; ref = ref->next)
-               string_list_append(abbrev_branch(ref->name), &states->heads);
+               string_list_append(&states->heads, abbrev_branch(ref->name));
 
        free_refs(fetch_map);
        free_refs(matches);
@@ -480,8 +511,8 @@ static int add_branch_for_removal(const char *refname,
        if (prefixcmp(refname, "refs/remotes")) {
                /* advise user how to delete local branches */
                if (!prefixcmp(refname, "refs/heads/"))
-                       string_list_append(abbrev_branch(refname),
-                                          branches->skipped);
+                       string_list_append(branches->skipped,
+                                          abbrev_branch(refname));
                /* silently skip over other non-remote refs */
                return 0;
        }
@@ -490,7 +521,7 @@ static int add_branch_for_removal(const char *refname,
        if (flags & REF_ISSYMREF)
                return unlink(git_path("%s", refname));
 
-       item = string_list_append(refname, branches->branches);
+       item = string_list_append(branches->branches, refname);
        item->util = xmalloc(20);
        hashcpy(item->util, sha1);
 
@@ -515,7 +546,7 @@ static int read_remote_branches(const char *refname,
 
        strbuf_addf(&buf, "refs/remotes/%s", rename->old);
        if (!prefixcmp(refname, buf.buf)) {
-               item = string_list_append(xstrdup(refname), rename->remote_branches);
+               item = string_list_append(rename->remote_branches, xstrdup(refname));
                symref = resolve_ref(refname, orig_sha1, 1, &flag);
                if (flag & REF_ISSYMREF)
                        item->util = xstrdup(symref);
@@ -705,11 +736,14 @@ static int rm(int argc, const char **argv)
        struct known_remotes known_remotes = { NULL, NULL };
        struct string_list branches = { NULL, 0, 0, 1 };
        struct string_list skipped = { NULL, 0, 0, 1 };
-       struct branches_for_remote cb_data = {
-               NULL, &branches, &skipped, &known_remotes
-       };
+       struct branches_for_remote cb_data;
        int i, result;
 
+       memset(&cb_data, 0, sizeof(cb_data));
+       cb_data.branches = &branches;
+       cb_data.skipped = &skipped;
+       cb_data.keep = &known_remotes;
+
        if (argc != 2)
                usage_with_options(builtin_remote_rm_usage, options);
 
@@ -798,7 +832,7 @@ static int append_ref_to_tracked_list(const char *refname,
        memset(&refspec, 0, sizeof(refspec));
        refspec.dst = (char *)refname;
        if (!remote_find_tracking(states->remote, &refspec))
-               string_list_append(abbrev_branch(refspec.src), &states->tracked);
+               string_list_append(&states->tracked, abbrev_branch(refspec.src));
 
        return 0;
 }
@@ -851,7 +885,7 @@ static int add_remote_to_show_info(struct string_list_item *item, void *cb_data)
        int n = strlen(item->string);
        if (n > info->width)
                info->width = n;
-       string_list_insert(item->string, info->list);
+       string_list_insert(info->list, item->string);
        return 0;
 }
 
@@ -898,7 +932,7 @@ static int add_local_to_show_info(struct string_list_item *branch_item, void *cb
        if (branch_info->rebase)
                show_info->any_rebase = 1;
 
-       item = string_list_insert(branch_item->string, show_info->list);
+       item = string_list_insert(show_info->list, branch_item->string);
        item->util = branch_info;
 
        return 0;
@@ -946,7 +980,7 @@ static int add_push_to_show_info(struct string_list_item *push_item, void *cb_da
                show_info->width = n;
        if ((n = strlen(push_info->dest)) > show_info->width2)
                show_info->width2 = n;
-       item = string_list_append(push_item->string, show_info->list);
+       item = string_list_append(show_info->list, push_item->string);
        item->util = push_item->util;
        return 0;
 }
@@ -1062,24 +1096,24 @@ static int show(int argc, const char **argv)
 
                /* remote branch info */
                info.width = 0;
-               for_each_string_list(add_remote_to_show_info, &states.new, &info);
-               for_each_string_list(add_remote_to_show_info, &states.tracked, &info);
-               for_each_string_list(add_remote_to_show_info, &states.stale, &info);
+               for_each_string_list(&states.new, add_remote_to_show_info, &info);
+               for_each_string_list(&states.tracked, add_remote_to_show_info, &info);
+               for_each_string_list(&states.stale, add_remote_to_show_info, &info);
                if (info.list->nr)
                        printf("  Remote branch%s:%s\n",
                               info.list->nr > 1 ? "es" : "",
                                no_query ? " (status not queried)" : "");
-               for_each_string_list(show_remote_info_item, info.list, &info);
+               for_each_string_list(info.list, show_remote_info_item, &info);
                string_list_clear(info.list, 0);
 
                /* git pull info */
                info.width = 0;
                info.any_rebase = 0;
-               for_each_string_list(add_local_to_show_info, &branch_list, &info);
+               for_each_string_list(&branch_list, add_local_to_show_info, &info);
                if (info.list->nr)
                        printf("  Local branch%s configured for 'git pull':\n",
                               info.list->nr > 1 ? "es" : "");
-               for_each_string_list(show_local_info_item, info.list, &info);
+               for_each_string_list(info.list, show_local_info_item, &info);
                string_list_clear(info.list, 0);
 
                /* git push info */
@@ -1087,14 +1121,14 @@ static int show(int argc, const char **argv)
                        printf("  Local refs will be mirrored by 'git push'\n");
 
                info.width = info.width2 = 0;
-               for_each_string_list(add_push_to_show_info, &states.push, &info);
+               for_each_string_list(&states.push, add_push_to_show_info, &info);
                qsort(info.list->items, info.list->nr,
                        sizeof(*info.list->items), cmp_string_with_push);
                if (info.list->nr)
                        printf("  Local ref%s configured for 'git push'%s:\n",
                                info.list->nr > 1 ? "s" : "",
                                no_query ? " (status not queried)" : "");
-               for_each_string_list(show_push_info_item, info.list, &info);
+               for_each_string_list(info.list, show_push_info_item, &info);
                string_list_clear(info.list, 0);
 
                free_remote_ref_states(&states);
@@ -1265,6 +1299,72 @@ static int update(int argc, const char **argv)
        return run_command_v_opt(fetch_argv, RUN_GIT_CMD);
 }
 
+static int remove_all_fetch_refspecs(const char *remote, const char *key)
+{
+       return git_config_set_multivar(key, NULL, NULL, 1);
+}
+
+static int add_branches(struct remote *remote, const char **branches,
+                       const char *key)
+{
+       const char *remotename = remote->name;
+       int mirror = remote->mirror;
+       struct strbuf refspec = STRBUF_INIT;
+
+       for (; *branches; branches++)
+               if (add_branch(key, *branches, remotename, mirror, &refspec)) {
+                       strbuf_release(&refspec);
+                       return 1;
+               }
+
+       strbuf_release(&refspec);
+       return 0;
+}
+
+static int set_remote_branches(const char *remotename, const char **branches,
+                               int add_mode)
+{
+       struct strbuf key = STRBUF_INIT;
+       struct remote *remote;
+
+       strbuf_addf(&key, "remote.%s.fetch", remotename);
+
+       if (!remote_is_configured(remotename))
+               die("No such remote '%s'", remotename);
+       remote = remote_get(remotename);
+
+       if (!add_mode && remove_all_fetch_refspecs(remotename, key.buf)) {
+               strbuf_release(&key);
+               return 1;
+       }
+       if (add_branches(remote, branches, key.buf)) {
+               strbuf_release(&key);
+               return 1;
+       }
+
+       strbuf_release(&key);
+       return 0;
+}
+
+static int set_branches(int argc, const char **argv)
+{
+       int add_mode = 0;
+       struct option options[] = {
+               OPT_BOOLEAN('\0', "add", &add_mode, "add branch"),
+               OPT_END()
+       };
+
+       argc = parse_options(argc, argv, NULL, options,
+                            builtin_remote_setbranches_usage, 0);
+       if (argc == 0) {
+               error("no remote specified");
+               usage_with_options(builtin_remote_seturl_usage, options);
+       }
+       argv[argc] = NULL;
+
+       return set_remote_branches(argv[0], argv + 1, add_mode);
+}
+
 static int set_url(int argc, const char **argv)
 {
        int i, push_mode = 0, add_mode = 0, delete_mode = 0;
@@ -1360,10 +1460,10 @@ static int get_one_entry(struct remote *remote, void *priv)
 
        if (remote->url_nr > 0) {
                strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]);
-               string_list_append(remote->name, list)->util =
+               string_list_append(list, remote->name)->util =
                                strbuf_detach(&url_buf, NULL);
        } else
-               string_list_append(remote->name, list)->util = NULL;
+               string_list_append(list, remote->name)->util = NULL;
        if (remote->pushurl_nr) {
                url = remote->pushurl;
                url_nr = remote->pushurl_nr;
@@ -1374,7 +1474,7 @@ static int get_one_entry(struct remote *remote, void *priv)
        for (i = 0; i < url_nr; i++)
        {
                strbuf_addf(&url_buf, "%s (push)", url[i]);
-               string_list_append(remote->name, list)->util =
+               string_list_append(list, remote->name)->util =
                                strbuf_detach(&url_buf, NULL);
        }
 
@@ -1430,6 +1530,8 @@ int cmd_remote(int argc, const char **argv, const char *prefix)
                result = rm(argc, argv);
        else if (!strcmp(argv[0], "set-head"))
                result = set_head(argc, argv);
+       else if (!strcmp(argv[0], "set-branches"))
+               result = set_branches(argc, argv);
        else if (!strcmp(argv[0], "set-url"))
                result = set_url(argc, argv);
        else if (!strcmp(argv[0], "show"))
index 0048f9ef7fee24e5e058ef226f3b0fc93703fcf1..0c7202eb9e637b69bcbbf3641d8ed72f44fd7684 100644 (file)
@@ -19,6 +19,12 @@ static time_t rerere_created_at(const char *name)
        return stat(rerere_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
 }
 
+static time_t rerere_last_used_at(const char *name)
+{
+       struct stat st;
+       return stat(rerere_path(name, "postimage"), &st) ? (time_t) 0 : st.st_mtime;
+}
+
 static void unlink_rr_item(const char *name)
 {
        unlink(rerere_path(name, "thisimage"));
@@ -53,13 +59,18 @@ static void garbage_collect(struct string_list *rr)
        while ((e = readdir(dir))) {
                if (is_dot_or_dotdot(e->d_name))
                        continue;
-               then = rerere_created_at(e->d_name);
-               if (!then)
-                       continue;
-               cutoff = (has_rerere_resolution(e->d_name)
-                         ? cutoff_resolve : cutoff_noresolve);
+
+               then = rerere_last_used_at(e->d_name);
+               if (then) {
+                       cutoff = cutoff_resolve;
+               } else {
+                       then = rerere_created_at(e->d_name);
+                       if (!then)
+                               continue;
+                       cutoff = cutoff_noresolve;
+               }
                if (then < now - cutoff * 86400)
-                       string_list_append(e->d_name, &to_remove);
+                       string_list_append(&to_remove, e->d_name);
        }
        for (i = 0; i < to_remove.nr; i++)
                unlink_rr_item(to_remove.items[i].string);
@@ -135,7 +146,7 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
                        if (!has_rerere_resolution(name))
                                unlink_rr_item(name);
                }
-               unlink_or_warn(git_path("rr-cache/MERGE_RR"));
+               unlink_or_warn(git_path("MERGE_RR"));
        } else if (!strcmp(argv[1], "gc"))
                garbage_collect(&merge_rr);
        else if (!strcmp(argv[1], "status"))
index 51ceb19d88918445c90eccc37f1fe5f90cedd385..efe9360e2fdb9aac3bae0c61c85531041f24708a 100644 (file)
@@ -50,6 +50,15 @@ static void show_commit(struct commit *commit, void *data)
 
        graph_show_commit(revs->graph);
 
+       if (revs->count) {
+               if (commit->object.flags & SYMMETRIC_LEFT)
+                       revs->count_left++;
+               else
+                       revs->count_right++;
+               finish_commit(commit, data);
+               return;
+       }
+
        if (info->show_timestamp)
                printf("%lu ", commit->date);
        if (info->header_prefix)
@@ -400,5 +409,12 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
                             quiet ? finish_object : show_object,
                             &info);
 
+       if (revs.count) {
+               if (revs.left_right)
+                       printf("%d\t%d\n", revs.count_left, revs.count_right);
+               else
+                       printf("%d\n", revs.count_left + revs.count_right);
+       }
+
        return 0;
 }
index 95c59fa686de7c8a90ce935aecc35bc83c68076d..a5a1c86e92720e8beefd8275acfc5df2dbdce175 100644 (file)
@@ -408,7 +408,8 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
        memset(opts + onb, 0, sizeof(opts[onb]));
        argc = parse_options(argc, argv, prefix, opts, usage,
                        (keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0) |
-                       (stop_at_non_option ? PARSE_OPT_STOP_AT_NON_OPTION : 0));
+                       (stop_at_non_option ? PARSE_OPT_STOP_AT_NON_OPTION : 0) |
+                       PARSE_OPT_SHELL_EVAL);
 
        strbuf_addf(&parsed, " --");
        sq_quote_argv(&parsed, argv, 0);
index 7d68ef714eee5011d82952ca1829016c90827f61..54d13cf5ef87b7cfa29ac2c204fc6e30d5211a67 100644 (file)
@@ -39,29 +39,34 @@ static const char * const cherry_pick_usage[] = {
 static int edit, no_replay, no_commit, mainline, signoff, allow_ff;
 static enum { REVERT, CHERRY_PICK } action;
 static struct commit *commit;
-static const char *commit_name;
+static int commit_argc;
+static const char **commit_argv;
 static int allow_rerere_auto;
 
 static const char *me;
+static const char *strategy;
 
 #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
 
 static char *get_encoding(const char *message);
 
+static const char * const *revert_or_cherry_pick_usage(void)
+{
+       return action == REVERT ? revert_usage : cherry_pick_usage;
+}
+
 static void parse_args(int argc, const char **argv)
 {
-       const char * const * usage_str =
-               action == REVERT ?  revert_usage : cherry_pick_usage;
-       unsigned char sha1[20];
+       const char * const * usage_str = revert_or_cherry_pick_usage();
        int noop;
        struct option options[] = {
                OPT_BOOLEAN('n', "no-commit", &no_commit, "don't automatically commit"),
                OPT_BOOLEAN('e', "edit", &edit, "edit the commit message"),
-               OPT_BOOLEAN('x', NULL, &no_replay, "append commit name when cherry-picking"),
                OPT_BOOLEAN('r', NULL, &noop, "no-op (backward compatibility)"),
                OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
                OPT_INTEGER('m', "mainline", &mainline, "parent number"),
                OPT_RERERE_AUTOUPDATE(&allow_rerere_auto),
+               OPT_STRING(0, "strategy", &strategy, "strategy", "merge strategy"),
                OPT_END(),
                OPT_END(),
                OPT_END(),
@@ -69,6 +74,7 @@ static void parse_args(int argc, const char **argv)
 
        if (action == CHERRY_PICK) {
                struct option cp_extra[] = {
+                       OPT_BOOLEAN('x', NULL, &no_replay, "append commit name"),
                        OPT_BOOLEAN(0, "ff", &allow_ff, "allow fast-forward"),
                        OPT_END(),
                };
@@ -76,15 +82,13 @@ static void parse_args(int argc, const char **argv)
                        die("program error");
        }
 
-       if (parse_options(argc, argv, NULL, options, usage_str, 0) != 1)
+       commit_argc = parse_options(argc, argv, NULL, options, usage_str,
+                                   PARSE_OPT_KEEP_ARGV0 |
+                                   PARSE_OPT_KEEP_UNKNOWN);
+       if (commit_argc < 2)
                usage_with_options(usage_str, options);
 
-       commit_name = argv[0];
-       if (get_sha1(commit_name, sha1))
-               die ("Cannot find '%s'", commit_name);
-       commit = lookup_commit_reference(sha1);
-       if (!commit)
-               exit(1);
+       commit_argv = argv;
 }
 
 struct commit_message {
@@ -174,28 +178,17 @@ static char *get_encoding(const char *message)
        return NULL;
 }
 
-static struct lock_file msg_file;
-static int msg_fd;
-
-static void add_to_msg(const char *string)
-{
-       int len = strlen(string);
-       if (write_in_full(msg_fd, string, len) < 0)
-               die_errno ("Could not write to MERGE_MSG");
-}
-
-static void add_message_to_msg(const char *message)
+static void add_message_to_msg(struct strbuf *msgbuf, const char *message)
 {
        const char *p = message;
        while (*p && (*p != '\n' || p[1] != '\n'))
                p++;
 
        if (!*p)
-               add_to_msg(sha1_to_hex(commit->object.sha1));
+               strbuf_addstr(msgbuf, sha1_to_hex(commit->object.sha1));
 
        p += 2;
-       add_to_msg(p);
-       return;
+       strbuf_addstr(msgbuf, p);
 }
 
 static void set_author_ident_env(const char *message)
@@ -248,7 +241,7 @@ static void set_author_ident_env(const char *message)
                        sha1_to_hex(commit->object.sha1));
 }
 
-static char *help_msg(const char *name)
+static char *help_msg(void)
 {
        struct strbuf helpbuf = STRBUF_INIT;
        char *msg = getenv("GIT_CHERRY_PICK_HELP");
@@ -264,13 +257,26 @@ static char *help_msg(const char *name)
                strbuf_addf(&helpbuf, " with: \n"
                        "\n"
                        "        git commit -c %s\n",
-                       name);
+                           sha1_to_hex(commit->object.sha1));
        }
        else
                strbuf_addch(&helpbuf, '.');
        return strbuf_detach(&helpbuf, NULL);
 }
 
+static void write_message(struct strbuf *msgbuf, const char *filename)
+{
+       static struct lock_file msg_file;
+
+       int msg_fd = hold_lock_file_for_update(&msg_file, filename,
+                                              LOCK_DIE_ON_ERROR);
+       if (write_in_full(msg_fd, msgbuf->buf, msgbuf->len) < 0)
+               die_errno("Could not write to %s.", filename);
+       strbuf_release(msgbuf);
+       if (commit_lock_file(&msg_file) < 0)
+               die("Error wrapping up %s", filename);
+}
+
 static struct tree *empty_tree(void)
 {
        struct tree *tree = xcalloc(1, sizeof(struct tree));
@@ -305,40 +311,71 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from)
        return write_ref_sha1(ref_lock, to, "cherry-pick");
 }
 
-static int revert_or_cherry_pick(int argc, const char **argv)
+static void do_recursive_merge(struct commit *base, struct commit *next,
+                              const char *base_label, const char *next_label,
+                              unsigned char *head, struct strbuf *msgbuf,
+                              char *defmsg)
 {
-       unsigned char head[20];
-       struct commit *base, *next, *parent;
-       const char *base_label, *next_label;
-       int i, index_fd, clean;
-       struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
-       char *defmsg = NULL;
        struct merge_options o;
        struct tree *result, *next_tree, *base_tree, *head_tree;
+       int clean, index_fd;
        static struct lock_file index_lock;
 
-       git_config(git_default_config, NULL);
-       me = action == REVERT ? "revert" : "cherry-pick";
-       setenv(GIT_REFLOG_ACTION, me, 0);
-       parse_args(argc, argv);
+       index_fd = hold_locked_index(&index_lock, 1);
 
-       /* this is copied from the shell script, but it's never triggered... */
-       if (action == REVERT && !no_replay)
-               die("revert is incompatible with replay");
+       read_cache();
+       init_merge_options(&o);
+       o.ancestor = base ? base_label : "(empty tree)";
+       o.branch1 = "HEAD";
+       o.branch2 = next ? next_label : "(empty tree)";
 
-       if (allow_ff) {
-               if (signoff)
-                       die("cherry-pick --ff cannot be used with --signoff");
-               if (no_commit)
-                       die("cherry-pick --ff cannot be used with --no-commit");
-               if (no_replay)
-                       die("cherry-pick --ff cannot be used with -x");
-               if (edit)
-                       die("cherry-pick --ff cannot be used with --edit");
+       head_tree = parse_tree_indirect(head);
+       next_tree = next ? next->tree : empty_tree();
+       base_tree = base ? base->tree : empty_tree();
+
+       clean = merge_trees(&o,
+                           head_tree,
+                           next_tree, base_tree, &result);
+
+       if (active_cache_changed &&
+           (write_cache(index_fd, active_cache, active_nr) ||
+            commit_locked_index(&index_lock)))
+               die("%s: Unable to write new index file", me);
+       rollback_lock_file(&index_lock);
+
+       if (!clean) {
+               int i;
+               strbuf_addstr(msgbuf, "\nConflicts:\n\n");
+               for (i = 0; i < active_nr;) {
+                       struct cache_entry *ce = active_cache[i++];
+                       if (ce_stage(ce)) {
+                               strbuf_addch(msgbuf, '\t');
+                               strbuf_addstr(msgbuf, ce->name);
+                               strbuf_addch(msgbuf, '\n');
+                               while (i < active_nr && !strcmp(ce->name,
+                                               active_cache[i]->name))
+                                       i++;
+                       }
+               }
+               write_message(msgbuf, defmsg);
+               fprintf(stderr, "Automatic %s failed.%s\n",
+                       me, help_msg());
+               rerere(allow_rerere_auto);
+               exit(1);
        }
+       write_message(msgbuf, defmsg);
+       fprintf(stderr, "Finished one %s.\n", me);
+}
+
+static int do_pick_commit(void)
+{
+       unsigned char head[20];
+       struct commit *base, *next, *parent;
+       const char *base_label, *next_label;
+       struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
+       char *defmsg = NULL;
+       struct strbuf msgbuf = STRBUF_INIT;
 
-       if (read_cache() < 0)
-               die("git %s: failed to read the index", me);
        if (no_commit) {
                /*
                 * We do not intend to commit immediately.  We just want to
@@ -403,86 +440,61 @@ static int revert_or_cherry_pick(int argc, const char **argv)
         */
 
        defmsg = git_pathdup("MERGE_MSG");
-       msg_fd = hold_lock_file_for_update(&msg_file, defmsg,
-                                          LOCK_DIE_ON_ERROR);
-
-       index_fd = hold_locked_index(&index_lock, 1);
 
        if (action == REVERT) {
                base = commit;
                base_label = msg.label;
                next = parent;
                next_label = msg.parent_label;
-               add_to_msg("Revert \"");
-               add_to_msg(msg.subject);
-               add_to_msg("\"\n\nThis reverts commit ");
-               add_to_msg(sha1_to_hex(commit->object.sha1));
+               strbuf_addstr(&msgbuf, "Revert \"");
+               strbuf_addstr(&msgbuf, msg.subject);
+               strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
+               strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
 
                if (commit->parents->next) {
-                       add_to_msg(", reversing\nchanges made to ");
-                       add_to_msg(sha1_to_hex(parent->object.sha1));
+                       strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
+                       strbuf_addstr(&msgbuf, sha1_to_hex(parent->object.sha1));
                }
-               add_to_msg(".\n");
+               strbuf_addstr(&msgbuf, ".\n");
        } else {
                base = parent;
                base_label = msg.parent_label;
                next = commit;
                next_label = msg.label;
                set_author_ident_env(msg.message);
-               add_message_to_msg(msg.message);
+               add_message_to_msg(&msgbuf, msg.message);
                if (no_replay) {
-                       add_to_msg("(cherry picked from commit ");
-                       add_to_msg(sha1_to_hex(commit->object.sha1));
-                       add_to_msg(")\n");
+                       strbuf_addstr(&msgbuf, "(cherry picked from commit ");
+                       strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
+                       strbuf_addstr(&msgbuf, ")\n");
                }
        }
 
-       read_cache();
-       init_merge_options(&o);
-       o.ancestor = base ? base_label : "(empty tree)";
-       o.branch1 = "HEAD";
-       o.branch2 = next ? next_label : "(empty tree)";
-
-       head_tree = parse_tree_indirect(head);
-       next_tree = next ? next->tree : empty_tree();
-       base_tree = base ? base->tree : empty_tree();
-
-       clean = merge_trees(&o,
-                           head_tree,
-                           next_tree, base_tree, &result);
-
-       if (active_cache_changed &&
-           (write_cache(index_fd, active_cache, active_nr) ||
-            commit_locked_index(&index_lock)))
-               die("%s: Unable to write new index file", me);
-       rollback_lock_file(&index_lock);
-
-       if (!clean) {
-               add_to_msg("\nConflicts:\n\n");
-               for (i = 0; i < active_nr;) {
-                       struct cache_entry *ce = active_cache[i++];
-                       if (ce_stage(ce)) {
-                               add_to_msg("\t");
-                               add_to_msg(ce->name);
-                               add_to_msg("\n");
-                               while (i < active_nr && !strcmp(ce->name,
-                                               active_cache[i]->name))
-                                       i++;
-                       }
+       if (!strategy || !strcmp(strategy, "recursive") || action == REVERT)
+               do_recursive_merge(base, next, base_label, next_label,
+                                  head, &msgbuf, defmsg);
+       else {
+               int res;
+               struct commit_list *common = NULL;
+               struct commit_list *remotes = NULL;
+               write_message(&msgbuf, defmsg);
+               commit_list_insert(base, &common);
+               commit_list_insert(next, &remotes);
+               res = try_merge_command(strategy, common,
+                                       sha1_to_hex(head), remotes);
+               free_commit_list(common);
+               free_commit_list(remotes);
+               if (res) {
+                       fprintf(stderr, "Automatic %s with strategy %s failed.%s\n",
+                               me, strategy, help_msg());
+                       rerere(allow_rerere_auto);
+                       exit(1);
                }
-               if (commit_lock_file(&msg_file) < 0)
-                       die ("Error wrapping up %s", defmsg);
-               fprintf(stderr, "Automatic %s failed.%s\n",
-                       me, help_msg(commit_name));
-               rerere(allow_rerere_auto);
-               exit(1);
        }
-       if (commit_lock_file(&msg_file) < 0)
-               die ("Error wrapping up %s", defmsg);
-       fprintf(stderr, "Finished one %s.\n", me);
+
+       free_message(&msg);
 
        /*
-        *
         * If we are cherry-pick, and if the merge did not result in
         * hand-editing, we will hit this commit and inherit the original
         * author date and name.
@@ -493,7 +505,9 @@ static int revert_or_cherry_pick(int argc, const char **argv)
        if (!no_commit) {
                /* 6 is max possible length of our args array including NULL */
                const char *args[6];
+               int res;
                int i = 0;
+
                args[i++] = "commit";
                args[i++] = "-n";
                if (signoff)
@@ -503,26 +517,81 @@ static int revert_or_cherry_pick(int argc, const char **argv)
                        args[i++] = defmsg;
                }
                args[i] = NULL;
-               return execv_git_cmd(args);
+               res = run_command_v_opt(args, RUN_GIT_CMD);
+               free(defmsg);
+
+               return res;
        }
-       free_message(&msg);
+
        free(defmsg);
 
        return 0;
 }
 
+static void prepare_revs(struct rev_info *revs)
+{
+       int argc;
+
+       init_revisions(revs, NULL);
+       revs->no_walk = 1;
+       if (action != REVERT)
+               revs->reverse = 1;
+
+       argc = setup_revisions(commit_argc, commit_argv, revs, NULL);
+       if (argc > 1)
+               usage(*revert_or_cherry_pick_usage());
+
+       if (prepare_revision_walk(revs))
+               die("revision walk setup failed");
+
+       if (!revs->commits)
+               die("empty commit set passed");
+}
+
+static int revert_or_cherry_pick(int argc, const char **argv)
+{
+       struct rev_info revs;
+
+       git_config(git_default_config, NULL);
+       me = action == REVERT ? "revert" : "cherry-pick";
+       setenv(GIT_REFLOG_ACTION, me, 0);
+       parse_args(argc, argv);
+
+       if (allow_ff) {
+               if (signoff)
+                       die("cherry-pick --ff cannot be used with --signoff");
+               if (no_commit)
+                       die("cherry-pick --ff cannot be used with --no-commit");
+               if (no_replay)
+                       die("cherry-pick --ff cannot be used with -x");
+               if (edit)
+                       die("cherry-pick --ff cannot be used with --edit");
+       }
+
+       if (read_cache() < 0)
+               die("git %s: failed to read the index", me);
+
+       prepare_revs(&revs);
+
+       while ((commit = get_revision(&revs))) {
+               int res = do_pick_commit();
+               if (res)
+                       return res;
+       }
+
+       return 0;
+}
+
 int cmd_revert(int argc, const char **argv, const char *prefix)
 {
        if (isatty(0))
                edit = 1;
-       no_replay = 1;
        action = REVERT;
        return revert_or_cherry_pick(argc, argv);
 }
 
 int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
 {
-       no_replay = 0;
        action = CHERRY_PICK;
        return revert_or_cherry_pick(argc, argv);
 }
index 5089502800d5f477f47b6cd6499d278097f11e67..0a9681ba7ece52e751b1b54d53f3e8fb4c19464e 100644 (file)
@@ -84,7 +84,7 @@ static void insert_one_record(struct shortlog *log,
                snprintf(namebuf + len, room, " <%.*s>", maillen, emailbuf);
        }
 
-       item = string_list_insert(namebuf, &log->list);
+       item = string_list_insert(&log->list, namebuf);
        if (item->util == NULL)
                item->util = xcalloc(1, sizeof(struct string_list));
 
@@ -115,7 +115,7 @@ static void insert_one_record(struct shortlog *log,
                }
        }
 
-       string_list_append(buffer, item->util);
+       string_list_append(item->util, buffer);
 }
 
 static void read_from_stdin(struct shortlog *log)
index 17ada88dfb9543ba782b84507b451fabfec28e10..0b2a9ad1a9a8a825c2e2104f8a9f729a9cb03d1a 100644 (file)
@@ -105,7 +105,7 @@ match:
 static int add_existing(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
 {
        struct string_list *list = (struct string_list *)cbdata;
-       string_list_insert(refname, list);
+       string_list_insert(list, refname);
        return 0;
 }
 
index d91743775dfbe98d99d8ab25a270af320c8b984e..f755590da827234830d8b4359720cfbfd87a3dea 100644 (file)
@@ -22,8 +22,10 @@ void cache_tree_free(struct cache_tree **it_p)
        if (!it)
                return;
        for (i = 0; i < it->subtree_nr; i++)
-               if (it->down[i])
+               if (it->down[i]) {
                        cache_tree_free(&it->down[i]->cache_tree);
+                       free(it->down[i]);
+               }
        free(it->down);
        free(it);
        *it_p = NULL;
@@ -328,9 +330,11 @@ static int update_one(struct cache_tree *it,
                        mode = ce->ce_mode;
                        entlen = pathlen - baselen;
                }
-               if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))
+               if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1)) {
+                       strbuf_release(&buffer);
                        return error("invalid object %06o %s for '%.*s'",
                                mode, sha1_to_hex(sha1), entlen+baselen, path);
+               }
 
                if (ce->ce_flags & CE_REMOVE)
                        continue; /* entry being removed */
diff --git a/cache.h b/cache.h
index 0d101e4913f380a0eda0b3bf9e1d8b76e34c6fd8..1e690d1240fb0fb752c0f0660c4c2dff2102e37f 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -361,7 +361,7 @@ enum object_type {
        OBJ_OFS_DELTA = 6,
        OBJ_REF_DELTA = 7,
        OBJ_ANY,
-       OBJ_MAX,
+       OBJ_MAX
 };
 
 static inline enum object_type object_type(unsigned int mode)
@@ -449,7 +449,7 @@ extern int init_db(const char *template_dir, unsigned int flags);
                                alloc = alloc_nr(alloc); \
                        x = xrealloc((x), alloc * sizeof(*(x))); \
                } \
-       } while(0)
+       } while (0)
 
 /* Initialize and use the cache information */
 extern int read_index(struct index_state *);
@@ -547,7 +547,6 @@ extern int core_compression_seen;
 extern size_t packed_git_window_size;
 extern size_t packed_git_limit;
 extern size_t delta_base_cache_limit;
-extern int auto_crlf;
 extern int read_replace_refs;
 extern int fsync_object_files;
 extern int core_preload_index;
@@ -556,32 +555,53 @@ extern int core_apply_sparse_checkout;
 enum safe_crlf {
        SAFE_CRLF_FALSE = 0,
        SAFE_CRLF_FAIL = 1,
-       SAFE_CRLF_WARN = 2,
+       SAFE_CRLF_WARN = 2
 };
 
 extern enum safe_crlf safe_crlf;
 
+enum auto_crlf {
+       AUTO_CRLF_FALSE = 0,
+       AUTO_CRLF_TRUE = 1,
+       AUTO_CRLF_INPUT = -1,
+};
+
+extern enum auto_crlf auto_crlf;
+
+enum eol {
+       EOL_UNSET,
+       EOL_CRLF,
+       EOL_LF,
+#ifdef NATIVE_CRLF
+       EOL_NATIVE = EOL_CRLF
+#else
+       EOL_NATIVE = EOL_LF
+#endif
+};
+
+extern enum eol eol;
+
 enum branch_track {
        BRANCH_TRACK_UNSPECIFIED = -1,
        BRANCH_TRACK_NEVER = 0,
        BRANCH_TRACK_REMOTE,
        BRANCH_TRACK_ALWAYS,
        BRANCH_TRACK_EXPLICIT,
-       BRANCH_TRACK_OVERRIDE,
+       BRANCH_TRACK_OVERRIDE
 };
 
 enum rebase_setup_type {
        AUTOREBASE_NEVER = 0,
        AUTOREBASE_LOCAL,
        AUTOREBASE_REMOTE,
-       AUTOREBASE_ALWAYS,
+       AUTOREBASE_ALWAYS
 };
 
 enum push_default_type {
        PUSH_DEFAULT_NOTHING = 0,
        PUSH_DEFAULT_MATCHING,
        PUSH_DEFAULT_TRACKING,
-       PUSH_DEFAULT_CURRENT,
+       PUSH_DEFAULT_CURRENT
 };
 
 extern enum branch_track git_branch_track;
@@ -590,7 +610,7 @@ extern enum push_default_type push_default;
 
 enum object_creation_mode {
        OBJECT_CREATION_USES_HARDLINKS = 0,
-       OBJECT_CREATION_USES_RENAMES = 1,
+       OBJECT_CREATION_USES_RENAMES = 1
 };
 
 extern enum object_creation_mode object_creation_mode;
@@ -670,7 +690,7 @@ enum sharedrepo {
        OLD_PERM_GROUP      = 1,
        OLD_PERM_EVERYBODY  = 2,
        PERM_GROUP          = 0660,
-       PERM_EVERYBODY      = 0664,
+       PERM_EVERYBODY      = 0664
 };
 int git_config_perm(const char *var, const char *value);
 int set_shared_perm(const char *path, int mode);
@@ -718,6 +738,8 @@ extern int has_loose_object_nonlocal(const unsigned char *sha1);
 
 extern int has_pack_index(const unsigned char *sha1);
 
+extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect);
+
 extern const signed char hexval_table[256];
 static inline unsigned int hexval(unsigned char c)
 {
@@ -728,12 +750,23 @@ static inline unsigned int hexval(unsigned char c)
 #define MINIMUM_ABBREV 4
 #define DEFAULT_ABBREV 7
 
+struct object_context {
+       unsigned char tree[20];
+       char path[PATH_MAX];
+       unsigned mode;
+};
+
 extern int get_sha1(const char *str, unsigned char *sha1);
 extern int get_sha1_with_mode_1(const char *str, unsigned char *sha1, unsigned *mode, int gently, const char *prefix);
 static inline int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode)
 {
        return get_sha1_with_mode_1(str, sha1, mode, 1, NULL);
 }
+extern int get_sha1_with_context_1(const char *name, unsigned char *sha1, struct object_context *orc, int gently, const char *prefix);
+static inline int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc)
+{
+       return get_sha1_with_context_1(str, sha1, orc, 1, NULL);
+}
 extern int get_sha1_hex(const char *hex, unsigned char *sha1);
 extern char *sha1_to_hex(const unsigned char *sha1);   /* static buffer result! */
 extern int read_ref(const char *filename, unsigned char *sha1);
@@ -880,7 +913,7 @@ struct ref {
                REF_STATUS_REJECT_NODELETE,
                REF_STATUS_UPTODATE,
                REF_STATUS_REMOTE_REJECT,
-               REF_STATUS_EXPECTING_REPORT,
+               REF_STATUS_EXPECTING_REPORT
        } status;
        char *remote_status;
        struct ref *peer_ref; /* when renaming */
@@ -937,12 +970,15 @@ extern int update_server_info(int);
 typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int git_default_config(const char *, const char *, void *);
 extern int git_config_from_file(config_fn_t fn, const char *, void *);
+extern int git_config_parse_parameter(const char *text);
+extern int git_config_from_parameters(config_fn_t fn, void *data);
 extern int git_config(config_fn_t fn, void *);
 extern int git_parse_ulong(const char *, unsigned long *);
 extern int git_config_int(const char *, const char *);
 extern unsigned long git_config_ulong(const char *, const char *);
 extern int git_config_bool_or_int(const char *, const char *, int *);
 extern int git_config_bool(const char *, const char *);
+extern int git_config_maybe_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
 extern int git_config_pathname(const char **, const char *, const char *);
 extern int git_config_set(const char *, const char *);
@@ -950,6 +986,7 @@ extern int git_config_set_multivar(const char *, const char *, const char *, int
 extern int git_config_rename_section(const char *, const char *);
 extern const char *git_etc_gitconfig(void);
 extern int check_repository_format_version(const char *var, const char *value, void *cb);
+extern int git_env_bool(const char *, int);
 extern int git_config_system(void);
 extern int git_config_global(void);
 extern int config_error_nonbool(const char *);
@@ -1041,6 +1078,7 @@ void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char *
 #define WS_INDENT_WITH_NON_TAB 04
 #define WS_CR_AT_EOL           010
 #define WS_BLANK_AT_EOF        020
+#define WS_TAB_IN_INDENT       040
 #define WS_TRAILING_SPACE      (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF)
 #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB)
 extern unsigned whitespace_rule_cfg;
@@ -1049,7 +1087,7 @@ extern unsigned parse_whitespace_rule(const char *);
 extern unsigned ws_check(const char *line, int len, unsigned ws_rule);
 extern void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws);
 extern char *whitespace_error_string(unsigned ws);
-extern int ws_fix_copy(char *, const char *, int, unsigned, int *);
+extern void ws_fix_copy(struct strbuf *, const char *, int, unsigned, int *);
 extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
 
 /* ls-files */
diff --git a/color.c b/color.c
index bcf4e2c192c31136729aabcc2575a94f809d2980..1b00554dd50d2960b4e66f229b0d2d0da8eb8c28 100644 (file)
--- a/color.c
+++ b/color.c
@@ -211,31 +211,3 @@ int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...)
        va_end(args);
        return r;
 }
-
-/*
- * This function splits the buffer by newlines and colors the lines individually.
- *
- * Returns 0 on success.
- */
-int color_fwrite_lines(FILE *fp, const char *color,
-               size_t count, const char *buf)
-{
-       if (!*color)
-               return fwrite(buf, count, 1, fp) != 1;
-       while (count) {
-               char *p = memchr(buf, '\n', count);
-               if (p != buf && (fputs(color, fp) < 0 ||
-                               fwrite(buf, p ? p - buf : count, 1, fp) != 1 ||
-                               fputs(GIT_COLOR_RESET, fp) < 0))
-                       return -1;
-               if (!p)
-                       return 0;
-               if (fputc('\n', fp) < 0)
-                       return -1;
-               count -= p + 1 - buf;
-               buf = p + 1;
-       }
-       return 0;
-}
-
-
diff --git a/color.h b/color.h
index 5c264b0ce3b95edb5f86cc003d2aca04033d098f..03ca0647485e8044d4131f2c61c37b4e9408cd2a 100644 (file)
--- a/color.h
+++ b/color.h
@@ -61,6 +61,5 @@ __attribute__((format (printf, 3, 4)))
 int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
 __attribute__((format (printf, 3, 4)))
 int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
-int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf);
 
 #endif /* COLOR_H */
index 731191e63bd39a89a8ea4ed0390c49d5605cdbed..e9b07509678f5a4f61e5bedadea14b726e290ed1 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -790,3 +790,58 @@ struct commit_list *reduce_heads(struct commit_list *heads)
        free(other);
        return result;
 }
+
+static const char commit_utf8_warn[] =
+"Warning: commit message does not conform to UTF-8.\n"
+"You may want to amend it after fixing the message, or set the config\n"
+"variable i18n.commitencoding to the encoding your project uses.\n";
+
+int commit_tree(const char *msg, unsigned char *tree,
+               struct commit_list *parents, unsigned char *ret,
+               const char *author)
+{
+       int result;
+       int encoding_is_utf8;
+       struct strbuf buffer;
+
+       assert_sha1_type(tree, OBJ_TREE);
+
+       /* Not having i18n.commitencoding is the same as having utf-8 */
+       encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
+
+       strbuf_init(&buffer, 8192); /* should avoid reallocs for the headers */
+       strbuf_addf(&buffer, "tree %s\n", sha1_to_hex(tree));
+
+       /*
+        * NOTE! This ordering means that the same exact tree merged with a
+        * different order of parents will be a _different_ changeset even
+        * if everything else stays the same.
+        */
+       while (parents) {
+               struct commit_list *next = parents->next;
+               strbuf_addf(&buffer, "parent %s\n",
+                       sha1_to_hex(parents->item->object.sha1));
+               free(parents);
+               parents = next;
+       }
+
+       /* Person/date information */
+       if (!author)
+               author = git_author_info(IDENT_ERROR_ON_NO_NAME);
+       strbuf_addf(&buffer, "author %s\n", author);
+       strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
+       if (!encoding_is_utf8)
+               strbuf_addf(&buffer, "encoding %s\n", git_commit_encoding);
+       strbuf_addch(&buffer, '\n');
+
+       /* And add the comment */
+       strbuf_addstr(&buffer, msg);
+
+       /* And check the encoding */
+       if (encoding_is_utf8 && !is_utf8(buffer.buf))
+               fprintf(stderr, commit_utf8_warn);
+
+       result = write_sha1_file(buffer.buf, buffer.len, commit_type, ret);
+       strbuf_release(&buffer);
+       return result;
+}
index 26ec8c0d1cebcf5e79564be690517cd2eb9c6413..eb2b8ac3cd5f375e70354e8c364abd036b0966ed 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -28,6 +28,7 @@ extern const char *commit_type;
 extern struct decoration name_decoration;
 struct name_decoration {
        struct name_decoration *next;
+       int type;
        char name[1];
 };
 
@@ -60,7 +61,7 @@ enum cmit_fmt {
        CMIT_FMT_EMAIL,
        CMIT_FMT_USERFORMAT,
 
-       CMIT_FMT_UNSPECIFIED,
+       CMIT_FMT_UNSPECIFIED
 };
 
 struct pretty_print_context
@@ -163,4 +164,8 @@ static inline int single_parent(struct commit *commit)
 
 struct commit_list *reduce_heads(struct commit_list *heads);
 
+extern int commit_tree(const char *msg, unsigned char *tree,
+               struct commit_list *parents, unsigned char *ret,
+               const char *author);
+
 #endif /* COMMIT_H */
index 9a8e3365827d303c6513475726113a3952fe0040..f2d9e1fd974b7271366da09370e10fafd2c50f08 100644 (file)
@@ -304,8 +304,13 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
                goto revert_attrs;
        }
 
-       time_t_to_filetime(times->modtime, &mft);
-       time_t_to_filetime(times->actime, &aft);
+       if (times) {
+               time_t_to_filetime(times->modtime, &mft);
+               time_t_to_filetime(times->actime, &aft);
+       } else {
+               GetSystemTimeAsFileTime(&mft);
+               aft = mft;
+       }
        if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) {
                errno = EINVAL;
                rc = -1;
@@ -641,7 +646,7 @@ static char *lookup_prog(const char *dir, const char *cmd, int isexe, int exe_on
 }
 
 /*
- * Determines the absolute path of cmd using the the split path in path.
+ * Determines the absolute path of cmd using the split path in path.
  * If cmd contains a slash or backslash, no lookup is performed.
  */
 static char *path_lookup(const char *cmd, char **path, int exe_only)
index 0e3e74304138ab2f279c74599ee934ade72ae37d..3b2477be5f658be665f19a12b48cc47fa07d1c6b 100644 (file)
@@ -80,7 +80,7 @@ static inline int fork(void)
 static inline unsigned int alarm(unsigned int seconds)
 { return 0; }
 static inline int fsync(int fd)
-{ return 0; }
+{ return _commit(fd); }
 static inline int getppid(void)
 { return 1; }
 static inline void sync(void)
@@ -89,7 +89,7 @@ static inline int getuid()
 { return 1; }
 static inline struct passwd *getpwnam(const char *name)
 { return NULL; }
-static inline int fcntl(int fd, int cmd, long arg)
+static inline int fcntl(int fd, int cmd, ...)
 {
        if (cmd == F_GETFD || cmd == F_SETFD)
                return 0;
index 74c42e31626480900898aba8e12704335330e11e..87260d26425dbb167f64710e71235f60e467a9b5 100644 (file)
@@ -2069,7 +2069,7 @@ static void init_malloc_global_mutex() {
   Each freshly allocated chunk must have both cinuse and pinuse set.
   That is, each allocated chunk borders either a previously allocated
   and still in-use chunk, or the base of its memory arena. This is
-  ensured by making all allocations from the the `lowest' part of any
+  ensured by making all allocations from the `lowest' part of any
   found chunk.  Further, no free chunk physically borders another one,
   so each free chunk is known to be preceded and followed by either
   inuse chunks or the ends of memory.
index 556d8ab11f40550335066f491d08383557e02a00..be851fc50267b10ae311dce042eec27c0f498461 100644 (file)
@@ -3122,7 +3122,7 @@ re_match (bufp, string, size, pos, regs)
 
 
 /* re_match_2 matches the compiled pattern in BUFP against the
-   the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1
+   (virtual) concatenation of STRING1 and STRING2 (of length SIZE1
    and SIZE2, respectively).  We start matching at POS, and stop
    matching at STOP.
 
index 0f949fc4250b5de4a3545931506fc48373ad8c6b..010e875ec4dd8d7154a0911661570165ac1ae874 100644 (file)
@@ -16,6 +16,7 @@
 static unsigned __stdcall win32_start_routine(void *arg)
 {
        pthread_t *thread = arg;
+       thread->tid = GetCurrentThreadId();
        thread->arg = thread->start_routine(thread->arg);
        return 0;
 }
@@ -49,6 +50,13 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr)
        }
 }
 
+pthread_t pthread_self(void)
+{
+       pthread_t t = { 0 };
+       t.tid = GetCurrentThreadId();
+       return t;
+}
+
 int pthread_cond_init(pthread_cond_t *cond, const void *unused)
 {
        cond->waiters = 0;
index a45f8d66df8d1e452d9392945bf12a74c32bbca9..2e205485570bf62a11112c665624203207c724a9 100644 (file)
@@ -58,6 +58,7 @@ typedef struct {
        HANDLE handle;
        void *(*start_routine)(void*);
        void *arg;
+       DWORD tid;
 } pthread_t;
 
 extern int pthread_create(pthread_t *thread, const void *unused,
@@ -71,4 +72,28 @@ extern int pthread_create(pthread_t *thread, const void *unused,
 
 extern int win32_pthread_join(pthread_t *thread, void **value_ptr);
 
+#define pthread_equal(t1, t2) ((t1).tid == (t2).tid)
+extern pthread_t pthread_self(void);
+
+static inline int pthread_exit(void *ret)
+{
+       ExitThread((DWORD)ret);
+}
+
+typedef DWORD pthread_key_t;
+static inline int pthread_key_create(pthread_key_t *keyp, void (*destructor)(void *value))
+{
+       return (*keyp = TlsAlloc()) == TLS_OUT_OF_INDEXES ? EAGAIN : 0;
+}
+
+static inline int pthread_setspecific(pthread_key_t key, const void *value)
+{
+       return TlsSetValue(key, (void *)value) ? 0 : EINVAL;
+}
+
+static inline void *pthread_getspecific(pthread_key_t key)
+{
+       return TlsGetValue(key);
+}
+
 #endif /* PTHREAD_H */
index 6963fbea43e6420f5f8dafc5b94fb5c27de6ffd2..cdcf5836c6c374eb59e80f89dbcf525fd6bf780f 100644 (file)
--- a/config.c
+++ b/config.c
@@ -7,6 +7,7 @@
  */
 #include "cache.h"
 #include "exec_cmd.h"
+#include "strbuf.h"
 
 #define MAXNAME (256)
 
@@ -18,6 +19,48 @@ static int zlib_compression_seen;
 
 const char *config_exclusive_filename = NULL;
 
+struct config_item
+{
+       struct config_item *next;
+       char *name;
+       char *value;
+};
+static struct config_item *config_parameters;
+static struct config_item **config_parameters_tail = &config_parameters;
+
+static void lowercase(char *p)
+{
+       for (; *p; p++)
+               *p = tolower(*p);
+}
+
+int git_config_parse_parameter(const char *text)
+{
+       struct config_item *ct;
+       struct strbuf tmp = STRBUF_INIT;
+       struct strbuf **pair;
+       strbuf_addstr(&tmp, text);
+       pair = strbuf_split(&tmp, '=');
+       if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=')
+               strbuf_setlen(pair[0], pair[0]->len - 1);
+       strbuf_trim(pair[0]);
+       if (!pair[0]->len) {
+               strbuf_list_free(pair);
+               return -1;
+       }
+       ct = xcalloc(1, sizeof(struct config_item));
+       ct->name = strbuf_detach(pair[0], NULL);
+       if (pair[1]) {
+               strbuf_trim(pair[1]);
+               ct->value = strbuf_detach(pair[1], NULL);
+       }
+       strbuf_list_free(pair);
+       lowercase(ct->name);
+       *config_parameters_tail = ct;
+       config_parameters_tail = &ct->next;
+       return 0;
+}
+
 static int get_next_char(void)
 {
        int c;
@@ -322,17 +365,30 @@ unsigned long git_config_ulong(const char *name, const char *value)
        return ret;
 }
 
-int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
+int git_config_maybe_bool(const char *name, const char *value)
 {
-       *is_bool = 1;
        if (!value)
                return 1;
        if (!*value)
                return 0;
-       if (!strcasecmp(value, "true") || !strcasecmp(value, "yes") || !strcasecmp(value, "on"))
+       if (!strcasecmp(value, "true")
+           || !strcasecmp(value, "yes")
+           || !strcasecmp(value, "on"))
                return 1;
-       if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off"))
+       if (!strcasecmp(value, "false")
+           || !strcasecmp(value, "no")
+           || !strcasecmp(value, "off"))
                return 0;
+       return -1;
+}
+
+int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
+{
+       int v = git_config_maybe_bool(name, value);
+       if (0 <= v) {
+               *is_bool = 1;
+               return v;
+       }
        *is_bool = 0;
        return git_config_int(name, value);
 }
@@ -461,7 +517,9 @@ static int git_default_core_config(const char *var, const char *value)
 
        if (!strcmp(var, "core.autocrlf")) {
                if (value && !strcasecmp(value, "input")) {
-                       auto_crlf = -1;
+                       if (eol == EOL_CRLF)
+                               return error("core.autocrlf=input conflicts with core.eol=crlf");
+                       auto_crlf = AUTO_CRLF_INPUT;
                        return 0;
                }
                auto_crlf = git_config_bool(var, value);
@@ -477,6 +535,20 @@ static int git_default_core_config(const char *var, const char *value)
                return 0;
        }
 
+       if (!strcmp(var, "core.eol")) {
+               if (value && !strcasecmp(value, "lf"))
+                       eol = EOL_LF;
+               else if (value && !strcasecmp(value, "crlf"))
+                       eol = EOL_CRLF;
+               else if (value && !strcasecmp(value, "native"))
+                       eol = EOL_NATIVE;
+               else
+                       eol = EOL_UNSET;
+               if (eol == EOL_CRLF && auto_crlf == AUTO_CRLF_INPUT)
+                       return error("core.autocrlf=input conflicts with core.eol=crlf");
+               return 0;
+       }
+
        if (!strcmp(var, "core.notesref")) {
                notes_ref_name = xstrdup(value);
                return 0;
@@ -683,7 +755,7 @@ const char *git_etc_gitconfig(void)
        return system_wide;
 }
 
-static int git_env_bool(const char *k, int def)
+int git_env_bool(const char *k, int def)
 {
        const char *v = getenv(k);
        return v ? git_config_bool(k, v) : def;
@@ -699,6 +771,15 @@ int git_config_global(void)
        return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0);
 }
 
+int git_config_from_parameters(config_fn_t fn, void *data)
+{
+       const struct config_item *ct;
+       for (ct = config_parameters; ct; ct = ct->next)
+               if (fn(ct->name, ct->value, data) < 0)
+                       return -1;
+       return 0;
+}
+
 int git_config(config_fn_t fn, void *data)
 {
        int ret = 0, found = 0;
@@ -730,6 +811,12 @@ int git_config(config_fn_t fn, void *data)
                found += 1;
        }
        free(repo_config);
+
+       if (config_parameters) {
+               ret += git_config_from_parameters(fn, data);
+               found += 1;
+       }
+
        if (found == 0)
                return -1;
        return ret;
index 0d4b64d076b8041a3701715a83ca46a4675ac9d6..b4e65c32b235eafafefeed1c755be7e1ad5c71ae 100644 (file)
@@ -3,10 +3,12 @@
 
 CC = @CC@
 CFLAGS = @CFLAGS@
+CPPFLAGS = @CPPFLAGS@
 LDFLAGS = @LDFLAGS@
 CC_LD_DYNPATH = @CC_LD_DYNPATH@
 AR = @AR@
 TAR = @TAR@
+DIFF = @DIFF@
 #INSTALL = @INSTALL@           # needs install-sh or install.sh in sources
 TCLTK_PATH = @TCLTK_PATH@
 
@@ -42,6 +44,7 @@ NO_D_TYPE_IN_DIRENT=@NO_D_TYPE_IN_DIRENT@
 NO_SOCKADDR_STORAGE=@NO_SOCKADDR_STORAGE@
 NO_IPV6=@NO_IPV6@
 NO_C99_FORMAT=@NO_C99_FORMAT@
+NO_HSTRERROR=@NO_HSTRERROR@
 NO_STRCASESTR=@NO_STRCASESTR@
 NO_MEMMEM=@NO_MEMMEM@
 NO_STRLCPY=@NO_STRLCPY@
@@ -51,10 +54,15 @@ NO_SETENV=@NO_SETENV@
 NO_UNSETENV=@NO_UNSETENV@
 NO_MKDTEMP=@NO_MKDTEMP@
 NO_MKSTEMPS=@NO_MKSTEMPS@
+NO_INET_NTOP=@NO_INET_NTOP@
+NO_INET_PTON=@NO_INET_PTON@
 NO_ICONV=@NO_ICONV@
 OLD_ICONV=@OLD_ICONV@
 NO_DEFLATE_BOUND=@NO_DEFLATE_BOUND@
+INLINE=@INLINE@
+SOCKLEN_T=@SOCKLEN_T@
 FREAD_READS_DIRECTORIES=@FREAD_READS_DIRECTORIES@
 SNPRINTF_RETURNS_BOGUS=@SNPRINTF_RETURNS_BOGUS@
 NO_PTHREADS=@NO_PTHREADS@
+PTHREAD_CFLAGS=@PTHREAD_CFLAGS@
 PTHREAD_LIBS=@PTHREAD_LIBS@
index 71038fcf1cd04fdfa3bcd133b6fc82974a135141..5601e8bac953c670e35f32ffe48d157dd5694ce7 100644 (file)
@@ -327,6 +327,12 @@ GIT_PARSE_WITH(tcltk))
 AC_MSG_NOTICE([CHECKS for programs])
 #
 AC_PROG_CC([cc gcc])
+AC_C_INLINE
+case $ac_cv_c_inline in
+  inline | yes | no)   ;;
+  *)                   AC_SUBST([INLINE], [$ac_cv_c_inline]) ;;
+esac
+
 # which switch to pass runtime path to dynamic libraries to the linker
 AC_CACHE_CHECK([if linker supports -R], git_cv_ld_dashr, [
    SAVE_LDFLAGS="${LDFLAGS}"
@@ -362,6 +368,7 @@ fi
 #AC_PROG_INSTALL               # needs install-sh or install.sh in sources
 AC_CHECK_TOOLS(AR, [gar ar], :)
 AC_CHECK_PROGS(TAR, [gtar tar])
+AC_CHECK_PROGS(DIFF, [gnudiff gdiff diff])
 # TCLTK_PATH will be set to some value if we want Tcl/Tk
 # or will be empty otherwise.
 if test -z "$NO_TCLTK"; then
@@ -544,13 +551,47 @@ AC_SUBST(NEEDS_SOCKET)
 test -n "$NEEDS_SOCKET" && LIBS="$LIBS -lsocket"
 
 #
-# Define NEEDS_RESOLV if linking with -lnsl and/or -lsocket is not enough.
-# Notably on Solaris hstrerror resides in libresolv and on Solaris 7
-# inet_ntop and inet_pton additionally reside there.
-AC_CHECK_LIB([c], [hstrerror],
-[NEEDS_RESOLV=],
-[NEEDS_RESOLV=YesPlease])
+# The next few tests will define NEEDS_RESOLV if linking with
+# libresolv provides some of the functions we would normally get
+# from libc.
+NEEDS_RESOLV=
 AC_SUBST(NEEDS_RESOLV)
+#
+# Define NO_INET_NTOP if linking with -lresolv is not enough.
+# Solaris 2.7 in particular hos inet_ntop in -lresolv.
+NO_INET_NTOP=
+AC_SUBST(NO_INET_NTOP)
+AC_CHECK_FUNC([inet_ntop],
+       [],
+    [AC_CHECK_LIB([resolv], [inet_ntop],
+           [NEEDS_RESOLV=YesPlease],
+       [NO_INET_NTOP=YesPlease])
+])
+#
+# Define NO_INET_PTON if linking with -lresolv is not enough.
+# Solaris 2.7 in particular hos inet_pton in -lresolv.
+NO_INET_PTON=
+AC_SUBST(NO_INET_PTON)
+AC_CHECK_FUNC([inet_pton],
+       [],
+    [AC_CHECK_LIB([resolv], [inet_pton],
+           [NEEDS_RESOLV=YesPlease],
+       [NO_INET_PTON=YesPlease])
+])
+#
+# Define NO_HSTRERROR if linking with -lresolv is not enough.
+# Solaris 2.6 in particular has no hstrerror, even in -lresolv.
+NO_HSTRERROR=
+AC_CHECK_FUNC([hstrerror],
+       [],
+    [AC_CHECK_LIB([resolv], [hstrerror],
+           [NEEDS_RESOLV=YesPlease],
+       [NO_HSTRERROR=YesPlease])
+])
+AC_SUBST(NO_HSTRERROR)
+#
+# If any of the above tests determined that -lresolv is needed at
+# build-time, also set it here for remaining configure-time checks.
 test -n "$NEEDS_RESOLV" && LIBS="$LIBS -lresolv"
 
 AC_CHECK_LIB([c], [basename],
@@ -598,6 +639,12 @@ AC_SUBST(OLD_ICONV)
 ## Checks for typedefs, structures, and compiler characteristics.
 AC_MSG_NOTICE([CHECKS for typedefs, structures, and compiler characteristics])
 #
+TYPE_SOCKLEN_T
+case $ac_cv_type_socklen_t in
+  yes) ;;
+  *)   AC_SUBST([SOCKLEN_T], [$git_cv_socklen_t_equiv]) ;;
+esac
+
 # Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent.
 AC_CHECK_MEMBER(struct dirent.d_ino,
 [NO_D_INO_IN_DIRENT=],
@@ -808,7 +855,11 @@ AC_DEFUN([PTHREADTEST_SRC], [
 int main(void)
 {
        pthread_mutex_t test_mutex;
-       return (0);
+       int retcode = 0;
+       retcode |= pthread_mutex_init(&test_mutex,(void *)0);
+       retcode |= pthread_mutex_lock(&test_mutex);
+       retcode |= pthread_mutex_unlock(&test_mutex);
+       return retcode;
 }
 ])
 
@@ -825,7 +876,8 @@ if test -n "$USER_NOPTHREAD"; then
 # handle these separately since PTHREAD_CFLAGS could be '-lpthreads
 # -D_REENTRANT' or some such.
 elif test -z "$PTHREAD_CFLAGS"; then
-  for opt in -pthread -lpthread; do
+  threads_found=no
+  for opt in -mt -pthread -lpthread; do
      old_CFLAGS="$CFLAGS"
      CFLAGS="$opt $CFLAGS"
      AC_MSG_CHECKING([Checking for POSIX Threads with '$opt'])
@@ -833,11 +885,18 @@ elif test -z "$PTHREAD_CFLAGS"; then
        [AC_MSG_RESULT([yes])
                NO_PTHREADS=
                PTHREAD_LIBS="$opt"
+               PTHREAD_CFLAGS="$opt"
+               threads_found=yes
                break
        ],
        [AC_MSG_RESULT([no])])
       CFLAGS="$old_CFLAGS"
   done
+  if test $threads_found != yes; then
+    AC_CHECK_LIB([pthread], [pthread_create],
+       [PTHREAD_LIBS="-lpthread"],
+       [NO_PTHREADS=UnfortunatelyYes])
+  fi
 else
   old_CFLAGS="$CFLAGS"
   CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
@@ -854,6 +913,7 @@ fi
 
 CFLAGS="$old_CFLAGS"
 
+AC_SUBST(PTHREAD_CFLAGS)
 AC_SUBST(PTHREAD_LIBS)
 AC_SUBST(NO_PTHREADS)
 
index 9ae991ac42544716599ff8bf3ebaaa376c8119e4..02e738a0146a5c46aaf3f1d8edc3c055a99e98b9 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -5,6 +5,7 @@
 #include "refs.h"
 #include "run-command.h"
 #include "remote.h"
+#include "url.h"
 
 static char *server_capabilities;
 
@@ -131,7 +132,7 @@ int path_match(const char *path, int nr, char **match)
 enum protocol {
        PROTO_LOCAL = 1,
        PROTO_SSH,
-       PROTO_GIT,
+       PROTO_GIT
 };
 
 static enum protocol get_protocol(const char *name)
@@ -450,7 +451,7 @@ static struct child_process no_fork;
 struct child_process *git_connect(int fd[2], const char *url_orig,
                                  const char *prog, int flags)
 {
-       char *url = xstrdup(url_orig);
+       char *url;
        char *host, *path;
        char *end;
        int c;
@@ -466,6 +467,11 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
         */
        signal(SIGCHLD, SIG_DFL);
 
+       if (is_url(url_orig))
+               url = url_decode(url_orig);
+       else
+               url = xstrdup(url_orig);
+
        host = strstr(url, "://");
        if (host) {
                *host = '\0';
index 57245a8c01fa3aba4f9e3f2bc258b40f38f446c0..82e6609689d7a72ff28420a1ee23923194e91c36 100755 (executable)
 #       set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
 #       untracked files, then a '%' will be shown next to the branch name.
 #
+#       If you would like to see the difference between HEAD and its
+#       upstream, set GIT_PS1_SHOWUPSTREAM="auto".  A "<" indicates
+#       you are behind, ">" indicates you are ahead, and "<>"
+#       indicates you have diverged.  You can further control
+#       behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated
+#       list of values:
+#           verbose       show number of commits ahead/behind (+/-) upstream
+#           legacy        don't use the '--count' option available in recent
+#                         versions of git-rev-list
+#           git           always compare HEAD to @{upstream}
+#           svn           always compare HEAD to your SVN upstream
+#       By default, __git_ps1 will compare HEAD to your SVN upstream
+#       if it can find one, or @{upstream} otherwise.  Once you have
+#       set GIT_PS1_SHOWUPSTREAM, you can override it on a
+#       per-repository basis by setting the bash.showUpstream config
+#       variable.
+#
+#
 # To submit patches:
 #
 #    *) Read Documentation/SubmittingPatches
@@ -78,14 +96,133 @@ __gitdir ()
        fi
 }
 
+# stores the divergence from upstream in $p
+# used by GIT_PS1_SHOWUPSTREAM
+__git_ps1_show_upstream ()
+{
+       local key value
+       local svn_remote=() svn_url_pattern count n
+       local upstream=git legacy="" verbose=""
+
+       # get some config options from git-config
+       while read key value; do
+               case "$key" in
+               bash.showupstream)
+                       GIT_PS1_SHOWUPSTREAM="$value"
+                       if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
+                               p=""
+                               return
+                       fi
+                       ;;
+               svn-remote.*.url)
+                       svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
+                       svn_url_pattern+="\\|$value"
+                       upstream=svn+git # default upstream is SVN if available, else git
+                       ;;
+               esac
+       done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
+
+       # parse configuration values
+       for option in ${GIT_PS1_SHOWUPSTREAM}; do
+               case "$option" in
+               git|svn) upstream="$option" ;;
+               verbose) verbose=1 ;;
+               legacy)  legacy=1  ;;
+               esac
+       done
+
+       # Find our upstream
+       case "$upstream" in
+       git)    upstream="@{upstream}" ;;
+       svn*)
+               # get the upstream from the "git-svn-id: ..." in a commit message
+               # (git-svn uses essentially the same procedure internally)
+               local svn_upstream=($(git log --first-parent -1 \
+                                       --grep="^git-svn-id: \(${svn_url_pattern:2}\)" 2>/dev/null))
+               if [[ 0 -ne ${#svn_upstream[@]} ]]; then
+                       svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
+                       svn_upstream=${svn_upstream%@*}
+                       for ((n=1; "$n" <= "${#svn_remote[@]}"; ++n)); do
+                               svn_upstream=${svn_upstream#${svn_remote[$n]}}
+                       done
+
+                       if [[ -z "$svn_upstream" ]]; then
+                               # default branch name for checkouts with no layout:
+                               upstream=${GIT_SVN_ID:-git-svn}
+                       else
+                               upstream=${svn_upstream#/}
+                       fi
+               elif [[ "svn+git" = "$upstream" ]]; then
+                       upstream="@{upstream}"
+               fi
+               ;;
+       esac
+
+       # Find how many commits we are ahead/behind our upstream
+       if [[ -z "$legacy" ]]; then
+               count="$(git rev-list --count --left-right \
+                               "$upstream"...HEAD 2>/dev/null)"
+       else
+               # produce equivalent output to --count for older versions of git
+               local commits
+               if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
+               then
+                       local commit behind=0 ahead=0
+                       for commit in $commits
+                       do
+                               case "$commit" in
+                               "<"*) let ++behind
+                                       ;;
+                               *)    let ++ahead
+                                       ;;
+                               esac
+                       done
+                       count="$behind  $ahead"
+               else
+                       count=""
+               fi
+       fi
+
+       # calculate the result
+       if [[ -z "$verbose" ]]; then
+               case "$count" in
+               "") # no upstream
+                       p="" ;;
+               "0      0") # equal to upstream
+                       p="=" ;;
+               "0      "*) # ahead of upstream
+                       p=">" ;;
+               *"      0") # behind upstream
+                       p="<" ;;
+               *)          # diverged from upstream
+                       p="<>" ;;
+               esac
+       else
+               case "$count" in
+               "") # no upstream
+                       p="" ;;
+               "0      0") # equal to upstream
+                       p=" u=" ;;
+               "0      "*) # ahead of upstream
+                       p=" u+${count#0 }" ;;
+               *"      0") # behind upstream
+                       p=" u-${count%  0}" ;;
+               *)          # diverged from upstream
+                       p=" u+${count#* }-${count%      *}" ;;
+               esac
+       fi
+
+}
+
+
 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
 # returns text to add to bash PS1 prompt (includes branch name)
 __git_ps1 ()
 {
        local g="$(__gitdir)"
        if [ -n "$g" ]; then
-               local r
-               local b
+               local r=""
+               local b=""
                if [ -f "$g/rebase-merge/interactive" ]; then
                        r="|REBASE-i"
                        b="$(cat "$g/rebase-merge/head-name")"
@@ -118,7 +255,7 @@ __git_ps1 ()
                                (describe)
                                        git describe HEAD ;;
                                (* | default)
-                                       git describe --exact-match HEAD ;;
+                                       git describe --tags --exact-match HEAD ;;
                                esac 2>/dev/null)" ||
 
                                b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
@@ -127,11 +264,12 @@ __git_ps1 ()
                        }
                fi
 
-               local w
-               local i
-               local s
-               local u
-               local c
+               local w=""
+               local i=""
+               local s=""
+               local u=""
+               local c=""
+               local p=""
 
                if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
                        if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
@@ -159,10 +297,14 @@ __git_ps1 ()
                              u="%"
                           fi
                        fi
+
+                       if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
+                               __git_ps1_show_upstream
+                       fi
                fi
 
                local f="$w$i$s$u"
-               printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r"
+               printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
        fi
 }
 
@@ -842,7 +984,7 @@ _git_checkout ()
        --*)
                __gitcomp "
                        --quiet --ours --theirs --track --no-track --merge
-                       --conflict= --patch
+                       --conflict= --orphan --patch
                        "
                ;;
        *)
@@ -1052,7 +1194,7 @@ _git_format_patch ()
                        --numbered --start-number
                        --numbered-files
                        --keep-subject
-                       --signoff
+                       --signoff --signature --no-signature
                        --in-reply-to= --cc=
                        --full-index --binary
                        --not --all
@@ -1726,6 +1868,7 @@ _git_config ()
                format.headers
                format.numbered
                format.pretty
+               format.signature
                format.signoff
                format.subjectprefix
                format.suffix
index 5c72f655c7e4fb1bd18e979d33bd94062fce8c1a..23ffb028d1ece96d8c363ddeacca83d2b20b628f 100755 (executable)
@@ -631,7 +631,7 @@ then
        if test -z "$quiet"
        then
                commit=`git diff-tree --always --shortstat --pretty="format:%h: %s"\
-                      --summary --root HEAD --`
+                      --abbrev --summary --root HEAD --`
                echo "Created${initial_commit:+ initial} commit $commit"
        fi
 fi
index e44af2c86d8e7e44bc79aafcc8ccef3806804720..a314273bd51a865d9d5fc5cd899a51ffa70388a5 100755 (executable)
@@ -127,10 +127,12 @@ then
        orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
 fi
 
-# Allow --notags from remote.$1.tagopt
+# Allow --tags/--notags from remote.$1.tagopt
 case "$tags$no_tags" in
 '')
        case "$(git config --get "remote.$1.tagopt")" in
+       --tags)
+               tags=t ;;
        --no-tags)
                no_tags=t ;;
        esac
index c364dda696912037cfafdb5e182b6e58f99e0a7e..a4ed4c3c62f0d5abcee36000a6c3a8f43dc02112 100755 (executable)
@@ -9,6 +9,7 @@ other/Merge <other> into <name> (respectively) commit subjects, which
 is rather slow but allows you to resurrect other people's topic
 branches."
 
+OPTIONS_KEEPDASHDASH=
 OPTIONS_SPEC="\
 git resurrect $USAGE
 --
index 30ae63d74da065a31cced0b161708680f39c04c0..09c524105cfa5fca3a5a860bbbed35f5eff84f79 100755 (executable)
@@ -203,7 +203,7 @@ generate_email_header()
        # Generate header
        cat <<-EOF
        To: $recipients
-       Subject: ${emailprefix}$projectdesc $refname_type, $short_refname, ${change_type}d. $describe
+       Subject: ${emailprefix}$projectdesc $refname_type $short_refname ${change_type}d. $describe
        X-Git-Refname: $refname
        X-Git-Reftype: $refname_type
        X-Git-Oldrev: $oldrev
diff --git a/contrib/svn-fe/.gitignore b/contrib/svn-fe/.gitignore
new file mode 100644 (file)
index 0000000..02a7791
--- /dev/null
@@ -0,0 +1,4 @@
+/*.xml
+/*.1
+/*.html
+/svn-fe
diff --git a/contrib/svn-fe/Makefile b/contrib/svn-fe/Makefile
new file mode 100644 (file)
index 0000000..360d8da
--- /dev/null
@@ -0,0 +1,63 @@
+all:: svn-fe$X
+
+CC = gcc
+RM = rm -f
+MV = mv
+
+CFLAGS = -g -O2 -Wall
+LDFLAGS =
+ALL_CFLAGS = $(CFLAGS)
+ALL_LDFLAGS = $(LDFLAGS)
+EXTLIBS =
+
+GIT_LIB = ../../libgit.a
+VCSSVN_LIB = ../../vcs-svn/lib.a
+LIBS = $(VCSSVN_LIB) $(GIT_LIB) $(EXTLIBS)
+
+QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
+QUIET_SUBDIR1 =
+
+ifneq ($(findstring $(MAKEFLAGS),w),w)
+PRINT_DIR = --no-print-directory
+else # "make -w"
+NO_SUBDIR = :
+endif
+
+ifneq ($(findstring $(MAKEFLAGS),s),s)
+ifndef V
+       QUIET_CC      = @echo '   ' CC $@;
+       QUIET_LINK    = @echo '   ' LINK $@;
+       QUIET_SUBDIR0 = +@subdir=
+       QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
+                       $(MAKE) $(PRINT_DIR) -C $$subdir
+endif
+endif
+
+svn-fe$X: svn-fe.o $(VCSSVN_LIB) $(GIT_LIB)
+       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ svn-fe.o \
+               $(ALL_LDFLAGS) $(LIBS)
+
+svn-fe.o: svn-fe.c ../../vcs-svn/svndump.h
+       $(QUIET_CC)$(CC) -I../../vcs-svn -o $*.o -c $(ALL_CFLAGS) $<
+
+svn-fe.html: svn-fe.txt
+       $(QUIET_SUBDIR0)../../Documentation $(QUIET_SUBDIR1) \
+               MAN_TXT=../contrib/svn-fe/svn-fe.txt \
+               ../contrib/svn-fe/$@
+
+svn-fe.1: svn-fe.txt
+       $(QUIET_SUBDIR0)../../Documentation $(QUIET_SUBDIR1) \
+               MAN_TXT=../contrib/svn-fe/svn-fe.txt \
+               ../contrib/svn-fe/$@
+       $(MV) ../../Documentation/svn-fe.1 .
+
+../../vcs-svn/lib.a: FORCE
+       $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) vcs-svn/lib.a
+
+../../libgit.a: FORCE
+       $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) libgit.a
+
+clean:
+       $(RM) svn-fe$X svn-fe.o svn-fe.html svn-fe.xml svn-fe.1
+
+.PHONY: all clean FORCE
diff --git a/contrib/svn-fe/svn-fe.c b/contrib/svn-fe/svn-fe.c
new file mode 100644 (file)
index 0000000..e9b9ba4
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * This file is in the public domain.
+ * You may freely use, modify, distribute, and relicense it.
+ */
+
+#include <stdlib.h>
+#include "svndump.h"
+
+int main(int argc, char **argv)
+{
+       svndump_init(NULL);
+       svndump_read((argc > 1) ? argv[1] : NULL);
+       svndump_reset();
+       return 0;
+}
diff --git a/contrib/svn-fe/svn-fe.txt b/contrib/svn-fe/svn-fe.txt
new file mode 100644 (file)
index 0000000..de30f83
--- /dev/null
@@ -0,0 +1,66 @@
+svn-fe(1)
+=========
+
+NAME
+----
+svn-fe - convert an SVN "dumpfile" to a fast-import stream
+
+SYNOPSIS
+--------
+svnadmin dump --incremental REPO | svn-fe [url] | git fast-import
+
+DESCRIPTION
+-----------
+
+Converts a Subversion dumpfile (version: 2) into input suitable for
+git-fast-import(1) and similar importers. REPO is a path to a
+Subversion repository mirrored on the local disk. Remote Subversion
+repositories can be mirrored on local disk using the `svnsync`
+command.
+
+INPUT FORMAT
+------------
+Subversion's repository dump format is documented in full in
+`notes/dump-load-format.txt` from the Subversion source tree.
+Files in this format can be generated using the 'svnadmin dump' or
+'svk admin dump' command.
+
+OUTPUT FORMAT
+-------------
+The fast-import format is documented by the git-fast-import(1)
+manual page.
+
+NOTES
+-----
+Subversion dumps do not record a separate author and committer for
+each revision, nor a separate display name and email address for
+each author.  Like git-svn(1), 'svn-fe' will use the name
+
+---------
+user <user@UUID>
+---------
+
+as committer, where 'user' is the value of the `svn:author` property
+and 'UUID' the repository's identifier.
+
+To support incremental imports, 'svn-fe' will put a `git-svn-id`
+line at the end of each commit log message if passed an url on the
+command line.  This line has the form `git-svn-id: URL@REVNO UUID`.
+
+Empty directories and unknown properties are silently discarded.
+
+The resulting repository will generally require further processing
+to put each project in its own repository and to separate the history
+of each branch.  The 'git filter-branch --subdirectory-filter' command
+may be useful for this purpose.
+
+BUGS
+----
+Litters the current working directory with .bin files for
+persistence. Will be fixed when the svn-fe infrastructure is aware of
+a Git working directory.
+
+SEE ALSO
+--------
+git-svn(1), svn2git(1), svk(1), git-filter-branch(1), git-fast-import(1),
+https://svn.apache.org/repos/asf/subversion/trunk/notes/dump-load-format.txt
index 993cacf324b8595e5be583ff372b25353c7af95c..3ad2c0cea56392fb941282ec6225c5f9a3ce05ea 100755 (executable)
@@ -54,13 +54,13 @@ then
        die "destination directory '$new_workdir' already exists."
 fi
 
-# make sure the the links use full paths
+# make sure the links use full paths
 git_dir=$(cd "$git_dir"; pwd)
 
 # create the workdir
 mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!"
 
-# create the links to the original repo.  explictly exclude index, HEAD and
+# create the links to the original repo.  explicitly exclude index, HEAD and
 # logs/HEAD from the list since they are purely related to the current working
 # directory, and should not be shared.
 for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn
index 4f8fcb7bbb00b66f1eaa354119784e6ef57e1eb4..e41a31e4807e92e210854214d46767b9752c5181 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -8,13 +8,17 @@
  * This should use the pathname to decide on whether it wants to do some
  * more interesting conversions (automatic gzip/unzip, general format
  * conversions etc etc), but by default it just does automatic CRLF<->LF
- * translation when the "auto_crlf" option is set.
+ * translation when the "text" attribute or "auto_crlf" option is set.
  */
 
-#define CRLF_GUESS     (-1)
-#define CRLF_BINARY    0
-#define CRLF_TEXT      1
-#define CRLF_INPUT     2
+enum action {
+       CRLF_GUESS = -1,
+       CRLF_BINARY = 0,
+       CRLF_TEXT,
+       CRLF_INPUT,
+       CRLF_CRLF,
+       CRLF_AUTO,
+};
 
 struct text_stat {
        /* NUL, CR, LF and CRLF counts */
@@ -89,49 +93,111 @@ static int is_binary(unsigned long size, struct text_stat *stats)
        return 0;
 }
 
-static void check_safe_crlf(const char *path, int action,
+static enum eol determine_output_conversion(enum action action) {
+       switch (action) {
+       case CRLF_BINARY:
+               return EOL_UNSET;
+       case CRLF_CRLF:
+               return EOL_CRLF;
+       case CRLF_INPUT:
+               return EOL_LF;
+       case CRLF_GUESS:
+               if (!auto_crlf)
+                       return EOL_UNSET;
+               /* fall through */
+       case CRLF_TEXT:
+       case CRLF_AUTO:
+               if (auto_crlf == AUTO_CRLF_TRUE)
+                       return EOL_CRLF;
+               else if (auto_crlf == AUTO_CRLF_INPUT)
+                       return EOL_LF;
+               else if (eol == EOL_UNSET)
+                       return EOL_NATIVE;
+       }
+       return eol;
+}
+
+static void check_safe_crlf(const char *path, enum action action,
                             struct text_stat *stats, enum safe_crlf checksafe)
 {
        if (!checksafe)
                return;
 
-       if (action == CRLF_INPUT || auto_crlf <= 0) {
+       if (determine_output_conversion(action) == EOL_LF) {
                /*
                 * CRLFs would not be restored by checkout:
                 * check if we'd remove CRLFs
                 */
                if (stats->crlf) {
                        if (checksafe == SAFE_CRLF_WARN)
-                               warning("CRLF will be replaced by LF in %s.", path);
+                               warning("CRLF will be replaced by LF in %s.\nThe file will have its original line endings in your working directory.", path);
                        else /* i.e. SAFE_CRLF_FAIL */
                                die("CRLF would be replaced by LF in %s.", path);
                }
-       } else if (auto_crlf > 0) {
+       } else if (determine_output_conversion(action) == EOL_CRLF) {
                /*
                 * CRLFs would be added by checkout:
                 * check if we have "naked" LFs
                 */
                if (stats->lf != stats->crlf) {
                        if (checksafe == SAFE_CRLF_WARN)
-                               warning("LF will be replaced by CRLF in %s", path);
+                               warning("LF will be replaced by CRLF in %s.\nThe file will have its original line endings in your working directory.", path);
                        else /* i.e. SAFE_CRLF_FAIL */
                                die("LF would be replaced by CRLF in %s", path);
                }
        }
 }
 
+static int has_cr_in_index(const char *path)
+{
+       int pos, len;
+       unsigned long sz;
+       enum object_type type;
+       void *data;
+       int has_cr;
+       struct index_state *istate = &the_index;
+
+       len = strlen(path);
+       pos = index_name_pos(istate, path, len);
+       if (pos < 0) {
+               /*
+                * We might be in the middle of a merge, in which
+                * case we would read stage #2 (ours).
+                */
+               int i;
+               for (i = -pos - 1;
+                    (pos < 0 && i < istate->cache_nr &&
+                     !strcmp(istate->cache[i]->name, path));
+                    i++)
+                       if (ce_stage(istate->cache[i]) == 2)
+                               pos = i;
+       }
+       if (pos < 0)
+               return 0;
+       data = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);
+       if (!data || type != OBJ_BLOB) {
+               free(data);
+               return 0;
+       }
+
+       has_cr = memchr(data, '\r', sz) != NULL;
+       free(data);
+       return has_cr;
+}
+
 static int crlf_to_git(const char *path, const char *src, size_t len,
-                       struct strbuf *buf, int action, enum safe_crlf checksafe)
+                      struct strbuf *buf, enum action action, enum safe_crlf checksafe)
 {
        struct text_stat stats;
        char *dst;
 
-       if ((action == CRLF_BINARY) || !auto_crlf || !len)
+       if (action == CRLF_BINARY ||
+           (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE) || !len)
                return 0;
 
        gather_stats(src, len, &stats);
 
-       if (action == CRLF_GUESS) {
+       if (action == CRLF_AUTO || action == CRLF_GUESS) {
                /*
                 * We're currently not going to even try to convert stuff
                 * that has bare CR characters. Does anybody do that crazy
@@ -145,6 +211,15 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
                 */
                if (is_binary(len, &stats))
                        return 0;
+
+               if (action == CRLF_GUESS) {
+                       /*
+                        * If the file in the index has any CR in it, do not convert.
+                        * This is the new safer autocrlf handling.
+                        */
+                       if (has_cr_in_index(path))
+                               return 0;
+               }
        }
 
        check_safe_crlf(path, action, &stats, checksafe);
@@ -157,7 +232,7 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
        if (strbuf_avail(buf) + buf->len < len)
                strbuf_grow(buf, len - buf->len);
        dst = buf->buf;
-       if (action == CRLF_GUESS) {
+       if (action == CRLF_AUTO || action == CRLF_GUESS) {
                /*
                 * If we guessed, we already know we rejected a file with
                 * lone CR, and we can strip a CR without looking at what
@@ -180,16 +255,12 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
 }
 
 static int crlf_to_worktree(const char *path, const char *src, size_t len,
-                            struct strbuf *buf, int action)
+                           struct strbuf *buf, enum action action)
 {
        char *to_free = NULL;
        struct text_stat stats;
 
-       if ((action == CRLF_BINARY) || (action == CRLF_INPUT) ||
-           auto_crlf <= 0)
-               return 0;
-
-       if (!len)
+       if (!len || determine_output_conversion(action) != EOL_CRLF)
                return 0;
 
        gather_stats(src, len, &stats);
@@ -202,7 +273,14 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,
        if (stats.lf == stats.crlf)
                return 0;
 
-       if (action == CRLF_GUESS) {
+       if (action == CRLF_AUTO || action == CRLF_GUESS) {
+               if (action == CRLF_GUESS) {
+                       /* If we have any CR or CRLF line endings, we do not touch it */
+                       /* This is the new safer autocrlf-handling */
+                       if (stats.cr > 0 || stats.crlf > 0)
+                               return 0;
+               }
+
                /* If we have any bare CR characters, we're not going to touch it */
                if (stats.cr != stats.crlf)
                        return 0;
@@ -249,7 +327,9 @@ static int filter_buffer(int in, int out, void *data)
        struct child_process child_process;
        struct filter_params *params = (struct filter_params *)data;
        int write_err, status;
-       const char *argv[] = { params->cmd, NULL };
+       const char *argv[] = { NULL, NULL };
+
+       argv[0] = params->cmd;
 
        memset(&child_process, 0, sizeof(child_process));
        child_process.argv = argv;
@@ -374,12 +454,16 @@ static int read_convert_config(const char *var, const char *value, void *cb)
 
 static void setup_convert_check(struct git_attr_check *check)
 {
+       static struct git_attr *attr_text;
        static struct git_attr *attr_crlf;
+       static struct git_attr *attr_eol;
        static struct git_attr *attr_ident;
        static struct git_attr *attr_filter;
 
-       if (!attr_crlf) {
+       if (!attr_text) {
+               attr_text = git_attr("text");
                attr_crlf = git_attr("crlf");
+               attr_eol = git_attr("eol");
                attr_ident = git_attr("ident");
                attr_filter = git_attr("filter");
                user_convert_tail = &user_convert;
@@ -388,6 +472,8 @@ static void setup_convert_check(struct git_attr_check *check)
        check[0].attr = attr_crlf;
        check[1].attr = attr_ident;
        check[2].attr = attr_filter;
+       check[3].attr = attr_eol;
+       check[4].attr = attr_text;
 }
 
 static int count_ident(const char *cp, unsigned long size)
@@ -425,6 +511,8 @@ static int count_ident(const char *cp, unsigned long size)
                                cnt++;
                                break;
                        }
+                       if (ch == '\n')
+                               break;
                }
        }
        return cnt;
@@ -455,6 +543,11 @@ static int ident_to_git(const char *path, const char *src, size_t len,
                        dollar = memchr(src + 3, '$', len - 3);
                        if (!dollar)
                                break;
+                       if (memchr(src + 3, '\n', dollar - src - 3)) {
+                               /* Line break before the next dollar. */
+                               continue;
+                       }
+
                        memcpy(dst, "Id$", 3);
                        dst += 3;
                        len -= dollar + 1 - src;
@@ -470,7 +563,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
                              struct strbuf *buf, int ident)
 {
        unsigned char sha1[20];
-       char *to_free = NULL, *dollar;
+       char *to_free = NULL, *dollar, *spc;
        int cnt;
 
        if (!ident)
@@ -506,7 +599,10 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
                } else if (src[2] == ':') {
                        /*
                         * It's possible that an expanded Id has crept its way into the
-                        * repository, we cope with that by stripping the expansion out
+                        * repository, we cope with that by stripping the expansion out.
+                        * This is probably not a good idea, since it will cause changes
+                        * on checkout, which won't go away by stash, but let's keep it
+                        * for git-style ids.
                         */
                        dollar = memchr(src + 3, '$', len - 3);
                        if (!dollar) {
@@ -514,6 +610,20 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
                                break;
                        }
 
+                       if (memchr(src + 3, '\n', dollar - src - 3)) {
+                               /* Line break before the next dollar. */
+                               continue;
+                       }
+
+                       spc = memchr(src + 4, ' ', dollar - src - 4);
+                       if (spc && spc < dollar-1) {
+                               /* There are spaces in unexpected places.
+                                * This is probably an id from some other
+                                * versioning system. Keep it for now.
+                                */
+                               continue;
+                       }
+
                        len -= dollar + 1 - src;
                        src  = dollar + 1;
                } else {
@@ -544,9 +654,24 @@ static int git_path_check_crlf(const char *path, struct git_attr_check *check)
                ;
        else if (!strcmp(value, "input"))
                return CRLF_INPUT;
+       else if (!strcmp(value, "auto"))
+               return CRLF_AUTO;
        return CRLF_GUESS;
 }
 
+static int git_path_check_eol(const char *path, struct git_attr_check *check)
+{
+       const char *value = check->value;
+
+       if (ATTR_UNSET(value))
+               ;
+       else if (!strcmp(value, "lf"))
+               return EOL_LF;
+       else if (!strcmp(value, "crlf"))
+               return EOL_CRLF;
+       return EOL_UNSET;
+}
+
 static struct convert_driver *git_path_check_convert(const char *path,
                                             struct git_attr_check *check)
 {
@@ -568,20 +693,34 @@ static int git_path_check_ident(const char *path, struct git_attr_check *check)
        return !!ATTR_TRUE(value);
 }
 
+enum action determine_action(enum action text_attr, enum eol eol_attr) {
+       if (text_attr == CRLF_BINARY)
+               return CRLF_BINARY;
+       if (eol_attr == EOL_LF)
+               return CRLF_INPUT;
+       if (eol_attr == EOL_CRLF)
+               return CRLF_CRLF;
+       return text_attr;
+}
+
 int convert_to_git(const char *path, const char *src, size_t len,
                    struct strbuf *dst, enum safe_crlf checksafe)
 {
-       struct git_attr_check check[3];
-       int crlf = CRLF_GUESS;
+       struct git_attr_check check[5];
+       enum action action = CRLF_GUESS;
+       enum eol eol_attr = EOL_UNSET;
        int ident = 0, ret = 0;
        const char *filter = NULL;
 
        setup_convert_check(check);
        if (!git_checkattr(path, ARRAY_SIZE(check), check)) {
                struct convert_driver *drv;
-               crlf = git_path_check_crlf(path, check + 0);
+               action = git_path_check_crlf(path, check + 4);
+               if (action == CRLF_GUESS)
+                       action = git_path_check_crlf(path, check + 0);
                ident = git_path_check_ident(path, check + 1);
                drv = git_path_check_convert(path, check + 2);
+               eol_attr = git_path_check_eol(path, check + 3);
                if (drv && drv->clean)
                        filter = drv->clean;
        }
@@ -591,7 +730,8 @@ int convert_to_git(const char *path, const char *src, size_t len,
                src = dst->buf;
                len = dst->len;
        }
-       ret |= crlf_to_git(path, src, len, dst, crlf, checksafe);
+       action = determine_action(action, eol_attr);
+       ret |= crlf_to_git(path, src, len, dst, action, checksafe);
        if (ret) {
                src = dst->buf;
                len = dst->len;
@@ -601,17 +741,21 @@ int convert_to_git(const char *path, const char *src, size_t len,
 
 int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)
 {
-       struct git_attr_check check[3];
-       int crlf = CRLF_GUESS;
+       struct git_attr_check check[5];
+       enum action action = CRLF_GUESS;
+       enum eol eol_attr = EOL_UNSET;
        int ident = 0, ret = 0;
        const char *filter = NULL;
 
        setup_convert_check(check);
        if (!git_checkattr(path, ARRAY_SIZE(check), check)) {
                struct convert_driver *drv;
-               crlf = git_path_check_crlf(path, check + 0);
+               action = git_path_check_crlf(path, check + 4);
+               if (action == CRLF_GUESS)
+                       action = git_path_check_crlf(path, check + 0);
                ident = git_path_check_ident(path, check + 1);
                drv = git_path_check_convert(path, check + 2);
+               eol_attr = git_path_check_eol(path, check + 3);
                if (drv && drv->smudge)
                        filter = drv->smudge;
        }
@@ -621,7 +765,8 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc
                src = dst->buf;
                len = dst->len;
        }
-       ret |= crlf_to_worktree(path, src, len, dst, crlf);
+       action = determine_action(action, eol_attr);
+       ret |= crlf_to_worktree(path, src, len, dst, action);
        if (ret) {
                src = dst->buf;
                len = dst->len;
diff --git a/ctype.c b/ctype.c
index 7ee64c7d77dd4a5665f70d80ffba1bcdecb9a408..de600279eef4765db497599e6654c2bedd978129 100644 (file)
--- a/ctype.c
+++ b/ctype.c
@@ -10,7 +10,7 @@ enum {
        A = GIT_ALPHA,
        D = GIT_DIGIT,
        G = GIT_GLOB_SPECIAL,   /* *, ?, [, \\ */
-       R = GIT_REGEX_SPECIAL,  /* $, (, ), +, ., ^, {, | */
+       R = GIT_REGEX_SPECIAL   /* $, (, ), +, ., ^, {, | */
 };
 
 unsigned char sane_ctype[256] = {
index a90ab10505a3694de83a0ffd8fc472518f12cf2b..e22a2b7fa5f6fcfc5b26541a21c10d3c8b7eda81 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -141,15 +141,14 @@ static char *path_ok(char *directory)
        }
        else if (interpolated_path && saw_extended_args) {
                struct strbuf expanded_path = STRBUF_INIT;
-               struct strbuf_expand_dict_entry dict[] = {
-                       { "H", hostname },
-                       { "CH", canon_hostname },
-                       { "IP", ip_address },
-                       { "P", tcp_port },
-                       { "D", directory },
-                       { NULL }
-               };
-
+               struct strbuf_expand_dict_entry dict[6];
+
+               dict[0].placeholder = "H"; dict[0].value = hostname;
+               dict[1].placeholder = "CH"; dict[1].value = canon_hostname;
+               dict[2].placeholder = "IP"; dict[2].value = ip_address;
+               dict[3].placeholder = "P"; dict[3].value = tcp_port;
+               dict[4].placeholder = "D"; dict[4].value = directory;
+               dict[5].placeholder = NULL; dict[5].value = NULL;
                if (*dir != '/') {
                        /* Allow only absolute */
                        logerror("'%s': Non-absolute path denied (interpolated-path active)", dir);
@@ -343,7 +342,9 @@ static int upload_pack(void)
 {
        /* Timeout as string */
        char timeout_buf[64];
-       const char *argv[] = { "upload-pack", "--strict", timeout_buf, ".", NULL };
+       const char *argv[] = { "upload-pack", "--strict", NULL, ".", NULL };
+
+       argv[2] = timeout_buf;
 
        snprintf(timeout_buf, sizeof timeout_buf, "--timeout=%u", timeout);
        return run_service_command(argv);
diff --git a/date.c b/date.c
index 6bae49ca330a69df5e2cf29e1e461f2490d99b2f..3c981f7eb5ebaed1ba621f3d4cd960f14145b97a 100644 (file)
--- a/date.c
+++ b/date.c
@@ -586,11 +586,17 @@ static int date_string(unsigned long date, int offset, char *buf, int len)
 
 /* Gr. strptime is crap for this; it doesn't have a way to require RFC2822
    (i.e. English) day/month names, and it doesn't work correctly with %z. */
-int parse_date(const char *date, char *result, int maxlen)
+int parse_date_toffset(const char *date, unsigned long *timestamp, int *offset)
 {
        struct tm tm;
-       int offset, tm_gmt;
-       time_t then;
+       int tm_gmt;
+       unsigned long dummy_timestamp;
+       int dummy_offset;
+
+       if (!timestamp)
+               timestamp = &dummy_timestamp;
+       if (!offset)
+               offset = &dummy_offset;
 
        memset(&tm, 0, sizeof(tm));
        tm.tm_year = -1;
@@ -600,7 +606,7 @@ int parse_date(const char *date, char *result, int maxlen)
        tm.tm_hour = -1;
        tm.tm_min = -1;
        tm.tm_sec = -1;
-       offset = -1;
+       *offset = -1;
        tm_gmt = 0;
 
        for (;;) {
@@ -612,11 +618,11 @@ int parse_date(const char *date, char *result, int maxlen)
                        break;
 
                if (isalpha(c))
-                       match = match_alpha(date, &tm, &offset);
+                       match = match_alpha(date, &tm, offset);
                else if (isdigit(c))
-                       match = match_digit(date, &tm, &offset, &tm_gmt);
+                       match = match_digit(date, &tm, offset, &tm_gmt);
                else if ((c == '-' || c == '+') && isdigit(date[1]))
-                       match = match_tz(date, &offset);
+                       match = match_tz(date, offset);
 
                if (!match) {
                        /* BAD CRAP */
@@ -627,16 +633,26 @@ int parse_date(const char *date, char *result, int maxlen)
        }
 
        /* mktime uses local timezone */
-       then = tm_to_time_t(&tm);
-       if (offset == -1)
-               offset = (then - mktime(&tm)) / 60;
+       *timestamp = tm_to_time_t(&tm);
+       if (*offset == -1)
+               *offset = ((time_t)*timestamp - mktime(&tm)) / 60;
 
-       if (then == -1)
+       if (*timestamp == -1)
                return -1;
 
        if (!tm_gmt)
-               then -= offset * 60;
-       return date_string(then, offset, result, maxlen);
+               *timestamp -= *offset * 60;
+       return 1; /* success */
+}
+
+int parse_date(const char *date, char *result, int maxlen)
+{
+       unsigned long timestamp;
+       int offset;
+       if (parse_date_toffset(date, &timestamp, &offset) > 0)
+               return date_string(timestamp, offset, result, maxlen);
+       else
+               return -1;
 }
 
 enum date_mode parse_date_format(const char *format)
@@ -984,11 +1000,12 @@ static unsigned long approxidate_str(const char *date,
 
 unsigned long approxidate_relative(const char *date, const struct timeval *tv)
 {
-       char buffer[50];
+       unsigned long timestamp;
+       int offset;
        int errors = 0;
 
-       if (parse_date(date, buffer, sizeof(buffer)) > 0)
-               return strtoul(buffer, NULL, 0);
+       if (parse_date_toffset(date, &timestamp, &offset) > 0)
+               return timestamp;
 
        return approxidate_str(date, tv, &errors);
 }
@@ -996,14 +1013,15 @@ unsigned long approxidate_relative(const char *date, const struct timeval *tv)
 unsigned long approxidate_careful(const char *date, int *error_ret)
 {
        struct timeval tv;
-       char buffer[50];
+       unsigned long timestamp;
+       int offset;
        int dummy = 0;
        if (!error_ret)
                error_ret = &dummy;
 
-       if (parse_date(date, buffer, sizeof(buffer)) > 0) {
+       if (parse_date_toffset(date, &timestamp, &offset) > 0) {
                *error_ret = 0;
-               return strtoul(buffer, NULL, 0);
+               return timestamp;
        }
 
        gettimeofday(&tv, NULL);
index 464ac3ffc0a45e95637e2cecdf97b3d39e5c7933..93385e12baa0d90ae475bd02500edf5ddcce320c 100644 (file)
@@ -146,7 +146,14 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
        /* Determine index hash size.  Note that indexing skips the
           first byte to allow for optimizing the Rabin's polynomial
           initialization in create_delta(). */
-       entries = (bufsize - 1)  / RABIN_WINDOW;
+       entries = (bufsize - 1) / RABIN_WINDOW;
+       if (bufsize >= 0xffffffffUL) {
+               /*
+                * Current delta format can't encode offsets into
+                * reference buffer with more than 32 bits.
+                */
+               entries = 0xfffffffeU / RABIN_WINDOW;
+       }
        hsize = entries / 4;
        for (i = 4; (1u << i) < hsize && i < 31; i++);
        hsize = 1 << i;
index c9f6e05badf7b752188dcb5fa28a9bef53521dee..8b8978ae6d1b4d947952b7fe9ec9cea013aaa8c3 100644 (file)
@@ -70,6 +70,7 @@ static int match_stat_with_submodule(struct diff_options *diffopt,
        int changed = ce_match_stat(ce, st, ce_option);
        if (S_ISGITLINK(ce->ce_mode)
            && !DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES)
+           && !DIFF_OPT_TST(diffopt, IGNORE_DIRTY_SUBMODULES)
            && (!changed || DIFF_OPT_TST(diffopt, DIRTY_SUBMODULES))) {
                *dirty_submodule = is_submodule_modified(ce->name, DIFF_OPT_TST(diffopt, IGNORE_UNTRACKED_IN_SUBMODULES));
        }
index 4cd9dacbe8e98d1420ebe1a217b0f927d24d125a..43aeeba2e0fd9c3c175dbc74a6f488e2c352c928 100644 (file)
@@ -26,7 +26,7 @@ static int read_directory(const char *path, struct string_list *list)
 
        while ((e = readdir(dir)))
                if (strcmp(".", e->d_name) && strcmp("..", e->d_name))
-                       string_list_insert(e->d_name, list);
+                       string_list_insert(list, e->d_name);
 
        closedir(dir);
        return 0;
diff --git a/diff.c b/diff.c
index 57e1212fbcc9783d3fdbd248762247d8e0efd886..19b5bf63ed37aa49c00e63f7aec621ce601b6daa 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -30,6 +30,7 @@ static const char *diff_word_regex_cfg;
 static const char *external_diff_cmd_cfg;
 int diff_auto_refresh_index = 1;
 static int diff_mnemonic_prefix;
+static int diff_no_prefix;
 
 static char diff_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_RESET,
@@ -43,9 +44,6 @@ static char diff_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_NORMAL,       /* FUNCINFO */
 };
 
-static void diff_filespec_load_driver(struct diff_filespec *one);
-static char *run_textconv(const char *, struct diff_filespec *, size_t *);
-
 static int parse_diff_color_slot(const char *var, int ofs)
 {
        if (!strcasecmp(var+ofs, "plain"))
@@ -100,6 +98,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
                diff_mnemonic_prefix = git_config_bool(var, value);
                return 0;
        }
+       if (!strcmp(var, "diff.noprefix")) {
+               diff_no_prefix = git_config_bool(var, value);
+               return 0;
+       }
        if (!strcmp(var, "diff.external"))
                return git_config_string(&external_diff_cmd_cfg, var, value);
        if (!strcmp(var, "diff.wordregex"))
@@ -193,8 +195,8 @@ struct emit_callback {
        sane_truncate_fn truncate;
        const char **label_path;
        struct diff_words_data *diff_words;
+       struct diff_options *opt;
        int *found_changesp;
-       FILE *file;
        struct strbuf *header;
 };
 
@@ -281,11 +283,19 @@ static void check_blank_at_eof(mmfile_t *mf1, mmfile_t *mf2,
        ecbdata->blank_at_eof_in_postimage = (at - l2) + 1;
 }
 
-static void emit_line_0(FILE *file, const char *set, const char *reset,
+static void emit_line_0(struct diff_options *o, const char *set, const char *reset,
                        int first, const char *line, int len)
 {
        int has_trailing_newline, has_trailing_carriage_return;
        int nofirst;
+       FILE *file = o->file;
+
+       if (o->output_prefix) {
+               struct strbuf *msg = NULL;
+               msg = o->output_prefix(o, o->output_prefix_data);
+               assert(msg);
+               fwrite(msg->buf, msg->len, 1, file);
+       }
 
        if (len == 0) {
                has_trailing_newline = (first == '\n');
@@ -315,10 +325,10 @@ static void emit_line_0(FILE *file, const char *set, const char *reset,
                fputc('\n', file);
 }
 
-static void emit_line(FILE *file, const char *set, const char *reset,
+static void emit_line(struct diff_options *o, const char *set, const char *reset,
                      const char *line, int len)
 {
-       emit_line_0(file, set, reset, line[0], line+1, len-1);
+       emit_line_0(o, set, reset, line[0], line+1, len-1);
 }
 
 static int new_blank_line_at_eof(struct emit_callback *ecbdata, const char *line, int len)
@@ -340,15 +350,15 @@ static void emit_add_line(const char *reset,
        const char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_NEW);
 
        if (!*ws)
-               emit_line_0(ecbdata->file, set, reset, '+', line, len);
+               emit_line_0(ecbdata->opt, set, reset, '+', line, len);
        else if (new_blank_line_at_eof(ecbdata, line, len))
                /* Blank line at EOF - paint '+' as well */
-               emit_line_0(ecbdata->file, ws, reset, '+', line, len);
+               emit_line_0(ecbdata->opt, ws, reset, '+', line, len);
        else {
                /* Emit just the prefix, then the rest. */
-               emit_line_0(ecbdata->file, set, reset, '+', "", 0);
+               emit_line_0(ecbdata->opt, set, reset, '+', "", 0);
                ws_check_emit(line, len, ecbdata->ws_rule,
-                             ecbdata->file, set, reset, ws);
+                             ecbdata->opt->file, set, reset, ws);
        }
 }
 
@@ -361,6 +371,9 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
        const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
        static const char atat[2] = { '@', '@' };
        const char *cp, *ep;
+       struct strbuf msgbuf = STRBUF_INIT;
+       int org_len = len;
+       int i = 1;
 
        /*
         * As a hunk header must begin with "@@ -<old>, +<new> @@",
@@ -369,23 +382,42 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
        if (len < 10 ||
            memcmp(line, atat, 2) ||
            !(ep = memmem(line + 2, len - 2, atat, 2))) {
-               emit_line(ecbdata->file, plain, reset, line, len);
+               emit_line(ecbdata->opt, plain, reset, line, len);
                return;
        }
        ep += 2; /* skip over @@ */
 
        /* The hunk header in fraginfo color */
-       emit_line(ecbdata->file, frag, reset, line, ep - line);
+       strbuf_add(&msgbuf, frag, strlen(frag));
+       strbuf_add(&msgbuf, line, ep - line);
+       strbuf_add(&msgbuf, reset, strlen(reset));
+
+       /*
+        * trailing "\r\n"
+        */
+       for ( ; i < 3; i++)
+               if (line[len - i] == '\r' || line[len - i] == '\n')
+                       len--;
 
        /* blank before the func header */
        for (cp = ep; ep - line < len; ep++)
                if (*ep != ' ' && *ep != '\t')
                        break;
-       if (ep != cp)
-               emit_line(ecbdata->file, plain, reset, cp, ep - cp);
+       if (ep != cp) {
+               strbuf_add(&msgbuf, plain, strlen(plain));
+               strbuf_add(&msgbuf, cp, ep - cp);
+               strbuf_add(&msgbuf, reset, strlen(reset));
+       }
+
+       if (ep < line + len) {
+               strbuf_add(&msgbuf, func, strlen(func));
+               strbuf_add(&msgbuf, ep, line + len - ep);
+               strbuf_add(&msgbuf, reset, strlen(reset));
+       }
 
-       if (ep < line + len)
-               emit_line(ecbdata->file, func, reset, ep, line + len - ep);
+       strbuf_add(&msgbuf, line + len, org_len - len);
+       emit_line(ecbdata->opt, "", "", msgbuf.buf, msgbuf.len);
+       strbuf_release(&msgbuf);
 }
 
 static struct diff_tempfile *claim_diff_tempfile(void) {
@@ -445,7 +477,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,
                len = endp ? (endp - data + 1) : size;
                if (prefix != '+') {
                        ecb->lno_in_preimage++;
-                       emit_line_0(ecb->file, old, reset, '-',
+                       emit_line_0(ecb->opt, old, reset, '-',
                                    data, len);
                } else {
                        ecb->lno_in_postimage++;
@@ -457,7 +489,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,
        if (!endp) {
                const char *plain = diff_get_color(ecb->color_diff,
                                                   DIFF_PLAIN);
-               emit_line_0(ecb->file, plain, reset, '\\',
+               emit_line_0(ecb->opt, plain, reset, '\\',
                            nneof, strlen(nneof));
        }
 }
@@ -466,8 +498,8 @@ static void emit_rewrite_diff(const char *name_a,
                              const char *name_b,
                              struct diff_filespec *one,
                              struct diff_filespec *two,
-                             const char *textconv_one,
-                             const char *textconv_two,
+                             struct userdiff_driver *textconv_one,
+                             struct userdiff_driver *textconv_two,
                              struct diff_options *o)
 {
        int lc_a, lc_b;
@@ -478,9 +510,16 @@ static void emit_rewrite_diff(const char *name_a,
        const char *reset = diff_get_color(color_diff, DIFF_RESET);
        static struct strbuf a_name = STRBUF_INIT, b_name = STRBUF_INIT;
        const char *a_prefix, *b_prefix;
-       const char *data_one, *data_two;
+       char *data_one, *data_two;
        size_t size_one, size_two;
        struct emit_callback ecbdata;
+       char *line_prefix = "";
+       struct strbuf *msgbuf;
+
+       if (o && o->output_prefix) {
+               msgbuf = o->output_prefix(o, o->output_prefix_data);
+               line_prefix = msgbuf->buf;
+       }
 
        if (diff_mnemonic_prefix && DIFF_OPT_TST(o, REVERSE_DIFF)) {
                a_prefix = o->b_prefix;
@@ -500,32 +539,14 @@ static void emit_rewrite_diff(const char *name_a,
        quote_two_c_style(&a_name, a_prefix, name_a, 0);
        quote_two_c_style(&b_name, b_prefix, name_b, 0);
 
-       diff_populate_filespec(one, 0);
-       diff_populate_filespec(two, 0);
-       if (textconv_one) {
-               data_one = run_textconv(textconv_one, one, &size_one);
-               if (!data_one)
-                       die("unable to read files to diff");
-       }
-       else {
-               data_one = one->data;
-               size_one = one->size;
-       }
-       if (textconv_two) {
-               data_two = run_textconv(textconv_two, two, &size_two);
-               if (!data_two)
-                       die("unable to read files to diff");
-       }
-       else {
-               data_two = two->data;
-               size_two = two->size;
-       }
+       size_one = fill_textconv(textconv_one, one, &data_one);
+       size_two = fill_textconv(textconv_two, two, &data_two);
 
        memset(&ecbdata, 0, sizeof(ecbdata));
        ecbdata.color_diff = color_diff;
        ecbdata.found_changesp = &o->found_changes;
        ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a);
-       ecbdata.file = o->file;
+       ecbdata.opt = o;
        if (ecbdata.ws_rule & WS_BLANK_AT_EOF) {
                mmfile_t mf1, mf2;
                mf1.ptr = (char *)data_one;
@@ -540,9 +561,10 @@ static void emit_rewrite_diff(const char *name_a,
        lc_a = count_lines(data_one, size_one);
        lc_b = count_lines(data_two, size_two);
        fprintf(o->file,
-               "%s--- %s%s%s\n%s+++ %s%s%s\n%s@@ -",
-               metainfo, a_name.buf, name_a_tab, reset,
-               metainfo, b_name.buf, name_b_tab, reset, fraginfo);
+               "%s%s--- %s%s%s\n%s%s+++ %s%s%s\n%s%s@@ -",
+               line_prefix, metainfo, a_name.buf, name_a_tab, reset,
+               line_prefix, metainfo, b_name.buf, name_b_tab, reset,
+               line_prefix, fraginfo);
        print_line_count(o->file, lc_a);
        fprintf(o->file, " +");
        print_line_count(o->file, lc_b);
@@ -577,23 +599,134 @@ static void diff_words_append(char *line, unsigned long len,
        buffer->text.ptr[buffer->text.size] = '\0';
 }
 
+struct diff_words_style_elem
+{
+       const char *prefix;
+       const char *suffix;
+       const char *color; /* NULL; filled in by the setup code if
+                           * color is enabled */
+};
+
+struct diff_words_style
+{
+       enum diff_words_type type;
+       struct diff_words_style_elem new, old, ctx;
+       const char *newline;
+};
+
+struct diff_words_style diff_words_styles[] = {
+       { DIFF_WORDS_PORCELAIN, {"+", "\n"}, {"-", "\n"}, {" ", "\n"}, "~\n" },
+       { DIFF_WORDS_PLAIN, {"{+", "+}"}, {"[-", "-]"}, {"", ""}, "\n" },
+       { DIFF_WORDS_COLOR, {"", ""}, {"", ""}, {"", ""}, "\n" }
+};
+
 struct diff_words_data {
        struct diff_words_buffer minus, plus;
        const char *current_plus;
-       FILE *file;
+       int last_minus;
+       struct diff_options *opt;
        regex_t *word_regex;
+       enum diff_words_type type;
+       struct diff_words_style *style;
 };
 
+static int fn_out_diff_words_write_helper(FILE *fp,
+                                         struct diff_words_style_elem *st_el,
+                                         const char *newline,
+                                         size_t count, const char *buf,
+                                         const char *line_prefix)
+{
+       int print = 0;
+
+       while (count) {
+               char *p = memchr(buf, '\n', count);
+               if (print)
+                       fputs(line_prefix, fp);
+               if (p != buf) {
+                       if (st_el->color && fputs(st_el->color, fp) < 0)
+                               return -1;
+                       if (fputs(st_el->prefix, fp) < 0 ||
+                           fwrite(buf, p ? p - buf : count, 1, fp) != 1 ||
+                           fputs(st_el->suffix, fp) < 0)
+                               return -1;
+                       if (st_el->color && *st_el->color
+                           && fputs(GIT_COLOR_RESET, fp) < 0)
+                               return -1;
+               }
+               if (!p)
+                       return 0;
+               if (fputs(newline, fp) < 0)
+                       return -1;
+               count -= p + 1 - buf;
+               buf = p + 1;
+               print = 1;
+       }
+       return 0;
+}
+
+/*
+ * '--color-words' algorithm can be described as:
+ *
+ *   1. collect a the minus/plus lines of a diff hunk, divided into
+ *      minus-lines and plus-lines;
+ *
+ *   2. break both minus-lines and plus-lines into words and
+ *      place them into two mmfile_t with one word for each line;
+ *
+ *   3. use xdiff to run diff on the two mmfile_t to get the words level diff;
+ *
+ * And for the common parts of the both file, we output the plus side text.
+ * diff_words->current_plus is used to trace the current position of the plus file
+ * which printed. diff_words->last_minus is used to trace the last minus word
+ * printed.
+ *
+ * For '--graph' to work with '--color-words', we need to output the graph prefix
+ * on each line of color words output. Generally, there are two conditions on
+ * which we should output the prefix.
+ *
+ *   1. diff_words->last_minus == 0 &&
+ *      diff_words->current_plus == diff_words->plus.text.ptr
+ *
+ *      that is: the plus text must start as a new line, and if there is no minus
+ *      word printed, a graph prefix must be printed.
+ *
+ *   2. diff_words->current_plus > diff_words->plus.text.ptr &&
+ *      *(diff_words->current_plus - 1) == '\n'
+ *
+ *      that is: a graph prefix must be printed following a '\n'
+ */
+static int color_words_output_graph_prefix(struct diff_words_data *diff_words)
+{
+       if ((diff_words->last_minus == 0 &&
+               diff_words->current_plus == diff_words->plus.text.ptr) ||
+               (diff_words->current_plus > diff_words->plus.text.ptr &&
+               *(diff_words->current_plus - 1) == '\n')) {
+               return 1;
+       } else {
+               return 0;
+       }
+}
+
 static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
 {
        struct diff_words_data *diff_words = priv;
+       struct diff_words_style *style = diff_words->style;
        int minus_first, minus_len, plus_first, plus_len;
        const char *minus_begin, *minus_end, *plus_begin, *plus_end;
+       struct diff_options *opt = diff_words->opt;
+       struct strbuf *msgbuf;
+       char *line_prefix = "";
 
        if (line[0] != '@' || parse_hunk_header(line, len,
                        &minus_first, &minus_len, &plus_first, &plus_len))
                return;
 
+       assert(opt);
+       if (opt->output_prefix) {
+               msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
+               line_prefix = msgbuf->buf;
+       }
+
        /* POSIX requires that first be decremented by one if len == 0... */
        if (minus_len) {
                minus_begin = diff_words->minus.orig[minus_first].begin;
@@ -609,20 +742,32 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
        } else
                plus_begin = plus_end = diff_words->plus.orig[plus_first].end;
 
-       if (diff_words->current_plus != plus_begin)
-               fwrite(diff_words->current_plus,
-                               plus_begin - diff_words->current_plus, 1,
-                               diff_words->file);
-       if (minus_begin != minus_end)
-               color_fwrite_lines(diff_words->file,
-                               diff_get_color(1, DIFF_FILE_OLD),
-                               minus_end - minus_begin, minus_begin);
-       if (plus_begin != plus_end)
-               color_fwrite_lines(diff_words->file,
-                               diff_get_color(1, DIFF_FILE_NEW),
-                               plus_end - plus_begin, plus_begin);
+       if (color_words_output_graph_prefix(diff_words)) {
+               fputs(line_prefix, diff_words->opt->file);
+       }
+       if (diff_words->current_plus != plus_begin) {
+               fn_out_diff_words_write_helper(diff_words->opt->file,
+                               &style->ctx, style->newline,
+                               plus_begin - diff_words->current_plus,
+                               diff_words->current_plus, line_prefix);
+               if (*(plus_begin - 1) == '\n')
+                       fputs(line_prefix, diff_words->opt->file);
+       }
+       if (minus_begin != minus_end) {
+               fn_out_diff_words_write_helper(diff_words->opt->file,
+                               &style->old, style->newline,
+                               minus_end - minus_begin, minus_begin,
+                               line_prefix);
+       }
+       if (plus_begin != plus_end) {
+               fn_out_diff_words_write_helper(diff_words->opt->file,
+                               &style->new, style->newline,
+                               plus_end - plus_begin, plus_begin,
+                               line_prefix);
+       }
 
        diff_words->current_plus = plus_end;
+       diff_words->last_minus = minus_first;
 }
 
 /* This function starts looking at *begin, and returns 0 iff a word was found. */
@@ -701,17 +846,31 @@ static void diff_words_show(struct diff_words_data *diff_words)
        xpparam_t xpp;
        xdemitconf_t xecfg;
        mmfile_t minus, plus;
+       struct diff_words_style *style = diff_words->style;
+
+       struct diff_options *opt = diff_words->opt;
+       struct strbuf *msgbuf;
+       char *line_prefix = "";
+
+       assert(opt);
+       if (opt->output_prefix) {
+               msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
+               line_prefix = msgbuf->buf;
+       }
 
        /* special case: only removal */
        if (!diff_words->plus.text.size) {
-               color_fwrite_lines(diff_words->file,
-                       diff_get_color(1, DIFF_FILE_OLD),
-                       diff_words->minus.text.size, diff_words->minus.text.ptr);
+               fputs(line_prefix, diff_words->opt->file);
+               fn_out_diff_words_write_helper(diff_words->opt->file,
+                       &style->old, style->newline,
+                       diff_words->minus.text.size,
+                       diff_words->minus.text.ptr, line_prefix);
                diff_words->minus.text.size = 0;
                return;
        }
 
        diff_words->current_plus = diff_words->plus.text.ptr;
+       diff_words->last_minus = 0;
 
        memset(&xpp, 0, sizeof(xpp));
        memset(&xecfg, 0, sizeof(xecfg));
@@ -725,11 +884,15 @@ static void diff_words_show(struct diff_words_data *diff_words)
        free(minus.ptr);
        free(plus.ptr);
        if (diff_words->current_plus != diff_words->plus.text.ptr +
-                       diff_words->plus.text.size)
-               fwrite(diff_words->current_plus,
+                       diff_words->plus.text.size) {
+               if (color_words_output_graph_prefix(diff_words))
+                       fputs(line_prefix, diff_words->opt->file);
+               fn_out_diff_words_write_helper(diff_words->opt->file,
+                       &style->ctx, style->newline,
                        diff_words->plus.text.ptr + diff_words->plus.text.size
-                       - diff_words->current_plus, 1,
-                       diff_words->file);
+                       - diff_words->current_plus, diff_words->current_plus,
+                       line_prefix);
+       }
        diff_words->minus.text.size = diff_words->plus.text.size = 0;
 }
 
@@ -749,7 +912,10 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
                free (ecbdata->diff_words->minus.orig);
                free (ecbdata->diff_words->plus.text.ptr);
                free (ecbdata->diff_words->plus.orig);
-               free(ecbdata->diff_words->word_regex);
+               if (ecbdata->diff_words->word_regex) {
+                       regfree(ecbdata->diff_words->word_regex);
+                       free(ecbdata->diff_words->word_regex);
+               }
                free(ecbdata->diff_words);
                ecbdata->diff_words = NULL;
        }
@@ -801,9 +967,17 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
        const char *meta = diff_get_color(ecbdata->color_diff, DIFF_METAINFO);
        const char *plain = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);
        const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
+       struct diff_options *o = ecbdata->opt;
+       char *line_prefix = "";
+       struct strbuf *msgbuf;
+
+       if (o && o->output_prefix) {
+               msgbuf = o->output_prefix(o, o->output_prefix_data);
+               line_prefix = msgbuf->buf;
+       }
 
        if (ecbdata->header) {
-               fprintf(ecbdata->file, "%s", ecbdata->header->buf);
+               fprintf(ecbdata->opt->file, "%s", ecbdata->header->buf);
                strbuf_reset(ecbdata->header);
                ecbdata->header = NULL;
        }
@@ -815,10 +989,10 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
                name_a_tab = strchr(ecbdata->label_path[0], ' ') ? "\t" : "";
                name_b_tab = strchr(ecbdata->label_path[1], ' ') ? "\t" : "";
 
-               fprintf(ecbdata->file, "%s--- %s%s%s\n",
-                       meta, ecbdata->label_path[0], reset, name_a_tab);
-               fprintf(ecbdata->file, "%s+++ %s%s%s\n",
-                       meta, ecbdata->label_path[1], reset, name_b_tab);
+               fprintf(ecbdata->opt->file, "%s%s--- %s%s%s\n",
+                       line_prefix, meta, ecbdata->label_path[0], reset, name_a_tab);
+               fprintf(ecbdata->opt->file, "%s%s+++ %s%s%s\n",
+                       line_prefix, meta, ecbdata->label_path[1], reset, name_b_tab);
                ecbdata->label_path[0] = ecbdata->label_path[1] = NULL;
        }
 
@@ -835,12 +1009,15 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
                find_lno(line, ecbdata);
                emit_hunk_header(ecbdata, line, len);
                if (line[len-1] != '\n')
-                       putc('\n', ecbdata->file);
+                       putc('\n', ecbdata->opt->file);
                return;
        }
 
        if (len < 1) {
-               emit_line(ecbdata->file, reset, reset, line, len);
+               emit_line(ecbdata->opt, reset, reset, line, len);
+               if (ecbdata->diff_words
+                   && ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN)
+                       fputs("~\n", ecbdata->opt->file);
                return;
        }
 
@@ -855,9 +1032,13 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
                        return;
                }
                diff_words_flush(ecbdata);
-               line++;
-               len--;
-               emit_line(ecbdata->file, plain, reset, line, len);
+               if (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) {
+                       emit_line(ecbdata->opt, plain, reset, line, len);
+                       fputs("~\n", ecbdata->opt->file);
+               } else {
+                       /* don't print the prefix character */
+                       emit_line(ecbdata->opt, plain, reset, line+1, len-1);
+               }
                return;
        }
 
@@ -868,7 +1049,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
                ecbdata->lno_in_preimage++;
                if (line[0] == ' ')
                        ecbdata->lno_in_postimage++;
-               emit_line(ecbdata->file, color, reset, line, len);
+               emit_line(ecbdata->opt, color, reset, line, len);
        } else {
                ecbdata->lno_in_postimage++;
                emit_add_line(reset, ecbdata, line + 1, len - 1);
@@ -1048,10 +1229,17 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
        int total_files = data->nr;
        int width, name_width;
        const char *reset, *set, *add_c, *del_c;
+       const char *line_prefix = "";
+       struct strbuf *msg = NULL;
 
        if (data->nr == 0)
                return;
 
+       if (options->output_prefix) {
+               msg = options->output_prefix(options, options->output_prefix_data);
+               line_prefix = msg->buf;
+       }
+
        width = options->stat_width ? options->stat_width : 80;
        name_width = options->stat_name_width ? options->stat_name_width : 50;
 
@@ -1121,6 +1309,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
                }
 
                if (data->files[i]->is_binary) {
+                       fprintf(options->file, "%s", line_prefix);
                        show_name(options->file, prefix, name, len);
                        fprintf(options->file, "  Bin ");
                        fprintf(options->file, "%s%"PRIuMAX"%s",
@@ -1133,6 +1322,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
                        continue;
                }
                else if (data->files[i]->is_unmerged) {
+                       fprintf(options->file, "%s", line_prefix);
                        show_name(options->file, prefix, name, len);
                        fprintf(options->file, "  Unmerged\n");
                        continue;
@@ -1155,6 +1345,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
                        add = scale_linear(add, width, max_change);
                        del = scale_linear(del, width, max_change);
                }
+               fprintf(options->file, "%s", line_prefix);
                show_name(options->file, prefix, name, len);
                fprintf(options->file, "%5"PRIuMAX"%s", added + deleted,
                                added + deleted ? " " : "");
@@ -1162,6 +1353,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
                show_graph(options->file, '-', del, del_c, reset);
                fprintf(options->file, "\n");
        }
+       fprintf(options->file, "%s", line_prefix);
        fprintf(options->file,
               " %d files changed, %d insertions(+), %d deletions(-)\n",
               total_files, adds, dels);
@@ -1188,6 +1380,12 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
                        }
                }
        }
+       if (options->output_prefix) {
+               struct strbuf *msg = NULL;
+               msg = options->output_prefix(options,
+                               options->output_prefix_data);
+               fprintf(options->file, "%s", msg->buf);
+       }
        fprintf(options->file, " %d files changed, %d insertions(+), %d deletions(-)\n",
               total_files, adds, dels);
 }
@@ -1202,6 +1400,13 @@ static void show_numstat(struct diffstat_t *data, struct diff_options *options)
        for (i = 0; i < data->nr; i++) {
                struct diffstat_file *file = data->files[i];
 
+               if (options->output_prefix) {
+                       struct strbuf *msg = NULL;
+                       msg = options->output_prefix(options,
+                                       options->output_prefix_data);
+                       fprintf(options->file, "%s", msg->buf);
+               }
+
                if (file->is_binary)
                        fprintf(options->file, "-\t-\t");
                else
@@ -1237,10 +1442,18 @@ struct dirstat_dir {
        int alloc, nr, percent, cumulative;
 };
 
-static long gather_dirstat(FILE *file, struct dirstat_dir *dir, unsigned long changed, const char *base, int baselen)
+static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
+               unsigned long changed, const char *base, int baselen)
 {
        unsigned long this_dir = 0;
        unsigned int sources = 0;
+       const char *line_prefix = "";
+       struct strbuf *msg = NULL;
+
+       if (opt->output_prefix) {
+               msg = opt->output_prefix(opt, opt->output_prefix_data);
+               line_prefix = msg->buf;
+       }
 
        while (dir->nr) {
                struct dirstat_file *f = dir->files;
@@ -1255,7 +1468,7 @@ static long gather_dirstat(FILE *file, struct dirstat_dir *dir, unsigned long ch
                slash = strchr(f->name + baselen, '/');
                if (slash) {
                        int newbaselen = slash + 1 - f->name;
-                       this = gather_dirstat(file, dir, changed, f->name, newbaselen);
+                       this = gather_dirstat(opt, dir, changed, f->name, newbaselen);
                        sources++;
                } else {
                        this = f->changed;
@@ -1277,7 +1490,8 @@ static long gather_dirstat(FILE *file, struct dirstat_dir *dir, unsigned long ch
                if (permille) {
                        int percent = permille / 10;
                        if (percent >= dir->percent) {
-                               fprintf(file, "%4d.%01d%% %.*s\n", percent, permille % 10, baselen, base);
+                               fprintf(opt->file, "%s%4d.%01d%% %.*s\n", line_prefix,
+                                       percent, permille % 10, baselen, base);
                                if (!dir->cumulative)
                                        return 0;
                        }
@@ -1357,7 +1571,7 @@ static void show_dirstat(struct diff_options *options)
 
        /* Show all directories with more than x% of the changes */
        qsort(dir.files, dir.nr, sizeof(dir.files[0]), dirstat_compare);
-       gather_dirstat(options->file, &dir, changed, "", 0);
+       gather_dirstat(options, &dir, changed, "", 0);
 }
 
 static void free_diffstat_info(struct diffstat_t *diffstat)
@@ -1415,6 +1629,15 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
        const char *reset = diff_get_color(color_diff, DIFF_RESET);
        const char *set = diff_get_color(color_diff, DIFF_FILE_NEW);
        char *err;
+       char *line_prefix = "";
+       struct strbuf *msgbuf;
+
+       assert(data->o);
+       if (data->o->output_prefix) {
+               msgbuf = data->o->output_prefix(data->o,
+                       data->o->output_prefix_data);
+               line_prefix = msgbuf->buf;
+       }
 
        if (line[0] == '+') {
                unsigned bad;
@@ -1422,18 +1645,18 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
                if (is_conflict_marker(line + 1, marker_size, len - 1)) {
                        data->status |= 1;
                        fprintf(data->o->file,
-                               "%s:%d: leftover conflict marker\n",
-                               data->filename, data->lineno);
+                               "%s%s:%d: leftover conflict marker\n",
+                               line_prefix, data->filename, data->lineno);
                }
                bad = ws_check(line + 1, len - 1, data->ws_rule);
                if (!bad)
                        return;
                data->status |= bad;
                err = whitespace_error_string(bad);
-               fprintf(data->o->file, "%s:%d: %s.\n",
-                       data->filename, data->lineno, err);
+               fprintf(data->o->file, "%s%s:%d: %s.\n",
+                       line_prefix, data->filename, data->lineno, err);
                free(err);
-               emit_line(data->o->file, set, reset, line, 1);
+               emit_line(data->o, set, reset, line, 1);
                ws_check_emit(line + 1, len - 1, data->ws_rule,
                              data->o->file, set, reset, ws);
        } else if (line[0] == ' ') {
@@ -1471,7 +1694,7 @@ static unsigned char *deflate_it(char *data,
        return deflated;
 }
 
-static void emit_binary_diff_body(FILE *file, mmfile_t *one, mmfile_t *two)
+static void emit_binary_diff_body(FILE *file, mmfile_t *one, mmfile_t *two, char *prefix)
 {
        void *cp;
        void *delta;
@@ -1500,13 +1723,13 @@ static void emit_binary_diff_body(FILE *file, mmfile_t *one, mmfile_t *two)
        }
 
        if (delta && delta_size < deflate_size) {
-               fprintf(file, "delta %lu\n", orig_size);
+               fprintf(file, "%sdelta %lu\n", prefix, orig_size);
                free(deflated);
                data = delta;
                data_size = delta_size;
        }
        else {
-               fprintf(file, "literal %lu\n", two->size);
+               fprintf(file, "%sliteral %lu\n", prefix, two->size);
                free(delta);
                data = deflated;
                data_size = deflate_size;
@@ -1524,18 +1747,19 @@ static void emit_binary_diff_body(FILE *file, mmfile_t *one, mmfile_t *two)
                        line[0] = bytes - 26 + 'a' - 1;
                encode_85(line + 1, cp, bytes);
                cp = (char *) cp + bytes;
+               fprintf(file, "%s", prefix);
                fputs(line, file);
                fputc('\n', file);
        }
-       fprintf(file, "\n");
+       fprintf(file, "%s\n", prefix);
        free(data);
 }
 
-static void emit_binary_diff(FILE *file, mmfile_t *one, mmfile_t *two)
+static void emit_binary_diff(FILE *file, mmfile_t *one, mmfile_t *two, char *prefix)
 {
-       fprintf(file, "GIT binary patch\n");
-       emit_binary_diff_body(file, one, two);
-       emit_binary_diff_body(file, two, one);
+       fprintf(file, "%sGIT binary patch\n", prefix);
+       emit_binary_diff_body(file, one, two, prefix);
+       emit_binary_diff_body(file, two, one, prefix);
 }
 
 static void diff_filespec_load_driver(struct diff_filespec *one)
@@ -1585,14 +1809,26 @@ void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const
                options->b_prefix = b;
 }
 
-static const char *get_textconv(struct diff_filespec *one)
+struct userdiff_driver *get_textconv(struct diff_filespec *one)
 {
        if (!DIFF_FILE_VALID(one))
                return NULL;
        if (!S_ISREG(one->mode))
                return NULL;
        diff_filespec_load_driver(one);
-       return one->driver->textconv;
+       if (!one->driver->textconv)
+               return NULL;
+
+       if (one->driver->textconv_want_cache && !one->driver->textconv_cache) {
+               struct notes_cache *c = xmalloc(sizeof(*c));
+               struct strbuf name = STRBUF_INIT;
+
+               strbuf_addf(&name, "textconv/%s", one->driver->name);
+               notes_cache_init(c, name.buf, one->driver->textconv);
+               one->driver->textconv_cache = c;
+       }
+
+       return one->driver;
 }
 
 static void builtin_diff(const char *name_a,
@@ -1610,8 +1846,16 @@ static void builtin_diff(const char *name_a,
        const char *set = diff_get_color_opt(o, DIFF_METAINFO);
        const char *reset = diff_get_color_opt(o, DIFF_RESET);
        const char *a_prefix, *b_prefix;
-       const char *textconv_one = NULL, *textconv_two = NULL;
+       struct userdiff_driver *textconv_one = NULL;
+       struct userdiff_driver *textconv_two = NULL;
        struct strbuf header = STRBUF_INIT;
+       struct strbuf *msgbuf;
+       char *line_prefix = "";
+
+       if (o->output_prefix) {
+               msgbuf = o->output_prefix(o, o->output_prefix_data);
+               line_prefix = msgbuf->buf;
+       }
 
        if (DIFF_OPT_TST(o, SUBMODULE_LOG) &&
                        (!one->mode || S_ISGITLINK(one->mode)) &&
@@ -1646,24 +1890,24 @@ static void builtin_diff(const char *name_a,
        b_two = quote_two(b_prefix, name_b + (*name_b == '/'));
        lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
        lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
-       strbuf_addf(&header, "%sdiff --git %s %s%s\n", set, a_one, b_two, reset);
+       strbuf_addf(&header, "%s%sdiff --git %s %s%s\n", line_prefix, set, a_one, b_two, reset);
        if (lbl[0][0] == '/') {
                /* /dev/null */
-               strbuf_addf(&header, "%snew file mode %06o%s\n", set, two->mode, reset);
+               strbuf_addf(&header, "%s%snew file mode %06o%s\n", line_prefix, set, two->mode, reset);
                if (xfrm_msg)
                        strbuf_addstr(&header, xfrm_msg);
                must_show_header = 1;
        }
        else if (lbl[1][0] == '/') {
-               strbuf_addf(&header, "%sdeleted file mode %06o%s\n", set, one->mode, reset);
+               strbuf_addf(&header, "%s%sdeleted file mode %06o%s\n", line_prefix, set, one->mode, reset);
                if (xfrm_msg)
                        strbuf_addstr(&header, xfrm_msg);
                must_show_header = 1;
        }
        else {
                if (one->mode != two->mode) {
-                       strbuf_addf(&header, "%sold mode %06o%s\n", set, one->mode, reset);
-                       strbuf_addf(&header, "%snew mode %06o%s\n", set, two->mode, reset);
+                       strbuf_addf(&header, "%s%sold mode %06o%s\n", line_prefix, set, one->mode, reset);
+                       strbuf_addf(&header, "%s%snew mode %06o%s\n", line_prefix, set, two->mode, reset);
                        must_show_header = 1;
                }
                if (xfrm_msg)
@@ -1687,12 +1931,11 @@ static void builtin_diff(const char *name_a,
                }
        }
 
-       if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
-               die("unable to read files to diff");
-
        if (!DIFF_OPT_TST(o, TEXT) &&
-           ( (diff_filespec_is_binary(one) && !textconv_one) ||
-             (diff_filespec_is_binary(two) && !textconv_two) )) {
+           ( (!textconv_one && diff_filespec_is_binary(one)) ||
+             (!textconv_two && diff_filespec_is_binary(two)) )) {
+               if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
+                       die("unable to read files to diff");
                /* Quite common confusing case */
                if (mf1.size == mf2.size &&
                    !memcmp(mf1.ptr, mf2.ptr, mf1.size)) {
@@ -1703,10 +1946,10 @@ static void builtin_diff(const char *name_a,
                fprintf(o->file, "%s", header.buf);
                strbuf_reset(&header);
                if (DIFF_OPT_TST(o, BINARY))
-                       emit_binary_diff(o->file, &mf1, &mf2);
+                       emit_binary_diff(o->file, &mf1, &mf2, line_prefix);
                else
-                       fprintf(o->file, "Binary files %s and %s differ\n",
-                               lbl[0], lbl[1]);
+                       fprintf(o->file, "%sBinary files %s and %s differ\n",
+                               line_prefix, lbl[0], lbl[1]);
                o->found_changes = 1;
        }
        else {
@@ -1722,20 +1965,8 @@ static void builtin_diff(const char *name_a,
                        strbuf_reset(&header);
                }
 
-               if (textconv_one) {
-                       size_t size;
-                       mf1.ptr = run_textconv(textconv_one, one, &size);
-                       if (!mf1.ptr)
-                               die("unable to read files to diff");
-                       mf1.size = size;
-               }
-               if (textconv_two) {
-                       size_t size;
-                       mf2.ptr = run_textconv(textconv_two, two, &size);
-                       if (!mf2.ptr)
-                               die("unable to read files to diff");
-                       mf2.size = size;
-               }
+               mf1.size = fill_textconv(textconv_one, one, &mf1.ptr);
+               mf2.size = fill_textconv(textconv_two, two, &mf2.ptr);
 
                pe = diff_funcname_pattern(one);
                if (!pe)
@@ -1750,7 +1981,7 @@ static void builtin_diff(const char *name_a,
                ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a);
                if (ecbdata.ws_rule & WS_BLANK_AT_EOF)
                        check_blank_at_eof(&mf1, &mf2, &ecbdata);
-               ecbdata.file = o->file;
+               ecbdata.opt = o;
                ecbdata.header = header.len ? &header : NULL;
                xpp.flags = o->xdl_opts;
                xecfg.ctxlen = o->context;
@@ -1764,10 +1995,13 @@ static void builtin_diff(const char *name_a,
                        xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
                else if (!prefixcmp(diffopts, "-u"))
                        xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
-               if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS)) {
+               if (o->word_diff) {
+                       int i;
+
                        ecbdata.diff_words =
                                xcalloc(1, sizeof(struct diff_words_data));
-                       ecbdata.diff_words->file = o->file;
+                       ecbdata.diff_words->type = o->word_diff;
+                       ecbdata.diff_words->opt = o;
                        if (!o->word_regex)
                                o->word_regex = userdiff_word_regex(one);
                        if (!o->word_regex)
@@ -1783,10 +2017,23 @@ static void builtin_diff(const char *name_a,
                                        die ("Invalid regular expression: %s",
                                                        o->word_regex);
                        }
+                       for (i = 0; i < ARRAY_SIZE(diff_words_styles); i++) {
+                               if (o->word_diff == diff_words_styles[i].type) {
+                                       ecbdata.diff_words->style =
+                                               &diff_words_styles[i];
+                                       break;
+                               }
+                       }
+                       if (DIFF_OPT_TST(o, COLOR_DIFF)) {
+                               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);
+                               st->ctx.color = diff_get_color_opt(o, DIFF_PLAIN);
+                       }
                }
                xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
                              &xpp, &xecfg);
-               if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS))
+               if (o->word_diff)
                        free_diff_words_data(&ecbdata);
                if (textconv_one)
                        free(mf1.ptr);
@@ -2332,31 +2579,41 @@ static void fill_metainfo(struct strbuf *msg,
 {
        const char *set = diff_get_color(use_color, DIFF_METAINFO);
        const char *reset = diff_get_color(use_color, DIFF_RESET);
+       struct strbuf *msgbuf;
+       char *line_prefix = "";
 
        *must_show_header = 1;
+       if (o->output_prefix) {
+               msgbuf = o->output_prefix(o, o->output_prefix_data);
+               line_prefix = msgbuf->buf;
+       }
        strbuf_init(msg, PATH_MAX * 2 + 300);
        switch (p->status) {
        case DIFF_STATUS_COPIED:
-               strbuf_addf(msg, "%ssimilarity index %d%%",
-                           set, similarity_index(p));
-               strbuf_addf(msg, "%s\n%scopy from ", reset, set);
+               strbuf_addf(msg, "%s%ssimilarity index %d%%",
+                           line_prefix, set, similarity_index(p));
+               strbuf_addf(msg, "%s\n%s%scopy from ",
+                           reset,  line_prefix, set);
                quote_c_style(name, msg, NULL, 0);
-               strbuf_addf(msg, "%s\n%scopy to ", reset, set);
+               strbuf_addf(msg, "%s\n%s%scopy to ", reset, line_prefix, set);
                quote_c_style(other, msg, NULL, 0);
                strbuf_addf(msg, "%s\n", reset);
                break;
        case DIFF_STATUS_RENAMED:
-               strbuf_addf(msg, "%ssimilarity index %d%%",
-                           set, similarity_index(p));
-               strbuf_addf(msg, "%s\n%srename from ", reset, set);
+               strbuf_addf(msg, "%s%ssimilarity index %d%%",
+                           line_prefix, set, similarity_index(p));
+               strbuf_addf(msg, "%s\n%s%srename from ",
+                           reset, line_prefix, set);
                quote_c_style(name, msg, NULL, 0);
-               strbuf_addf(msg, "%s\n%srename to ", reset, set);
+               strbuf_addf(msg, "%s\n%s%srename to ",
+                           reset, line_prefix, set);
                quote_c_style(other, msg, NULL, 0);
                strbuf_addf(msg, "%s\n", reset);
                break;
        case DIFF_STATUS_MODIFIED:
                if (p->score) {
-                       strbuf_addf(msg, "%sdissimilarity index %d%%%s\n",
+                       strbuf_addf(msg, "%s%sdissimilarity index %d%%%s\n",
+                                   line_prefix,
                                    set, similarity_index(p), reset);
                        break;
                }
@@ -2373,9 +2630,9 @@ static void fill_metainfo(struct strbuf *msg,
                            (!fill_mmfile(&mf, two) && diff_filespec_is_binary(two)))
                                abbrev = 40;
                }
-               strbuf_addf(msg, "%sindex %.*s..%.*s", set,
-                           abbrev, sha1_to_hex(one->sha1),
-                           abbrev, sha1_to_hex(two->sha1));
+               strbuf_addf(msg, "%s%sindex %s..", line_prefix, set,
+                           find_unique_abbrev(one->sha1, abbrev));
+               strbuf_addstr(msg, find_unique_abbrev(two->sha1, abbrev));
                if (one->mode == two->mode)
                        strbuf_addf(msg, " %06o", one->mode);
                strbuf_addf(msg, "%s\n", reset);
@@ -2450,10 +2707,16 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
 static void strip_prefix(int prefix_length, const char **namep, const char **otherp)
 {
        /* Strip the prefix but do not molest /dev/null and absolute paths */
-       if (*namep && **namep != '/')
+       if (*namep && **namep != '/') {
                *namep += prefix_length;
-       if (*otherp && **otherp != '/')
+               if (**namep == '/')
+                       ++*namep;
+       }
+       if (*otherp && **otherp != '/') {
                *otherp += prefix_length;
+               if (**otherp == '/')
+                       ++*otherp;
+       }
 }
 
 static void run_diff(struct diff_filepair *p, struct diff_options *o)
@@ -2575,7 +2838,9 @@ void diff_setup(struct diff_options *options)
                DIFF_OPT_SET(options, COLOR_DIFF);
        options->detect_rename = diff_detect_rename_default;
 
-       if (!diff_mnemonic_prefix) {
+       if (diff_no_prefix) {
+               options->a_prefix = options->b_prefix = "";
+       } else if (!diff_mnemonic_prefix) {
                options->a_prefix = "a/";
                options->b_prefix = "b/";
        }
@@ -2738,7 +3003,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
        const char *arg = av[0];
 
        /* Output format options */
-       if (!strcmp(arg, "-p") || !strcmp(arg, "-u"))
+       if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch"))
                options->output_format |= DIFF_FORMAT_PATCH;
        else if (opt_arg(arg, 'U', "unified", &options->context))
                options->output_format |= DIFF_FORMAT_PATCH;
@@ -2866,13 +3131,37 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                DIFF_OPT_CLR(options, COLOR_DIFF);
        else if (!strcmp(arg, "--color-words")) {
                DIFF_OPT_SET(options, COLOR_DIFF);
-               DIFF_OPT_SET(options, COLOR_DIFF_WORDS);
+               options->word_diff = DIFF_WORDS_COLOR;
        }
        else if (!prefixcmp(arg, "--color-words=")) {
                DIFF_OPT_SET(options, COLOR_DIFF);
-               DIFF_OPT_SET(options, COLOR_DIFF_WORDS);
+               options->word_diff = DIFF_WORDS_COLOR;
                options->word_regex = arg + 14;
        }
+       else if (!strcmp(arg, "--word-diff")) {
+               if (options->word_diff == DIFF_WORDS_NONE)
+                       options->word_diff = DIFF_WORDS_PLAIN;
+       }
+       else if (!prefixcmp(arg, "--word-diff=")) {
+               const char *type = arg + 12;
+               if (!strcmp(type, "plain"))
+                       options->word_diff = DIFF_WORDS_PLAIN;
+               else if (!strcmp(type, "color")) {
+                       DIFF_OPT_SET(options, COLOR_DIFF);
+                       options->word_diff = DIFF_WORDS_COLOR;
+               }
+               else if (!strcmp(type, "porcelain"))
+                       options->word_diff = DIFF_WORDS_PORCELAIN;
+               else if (!strcmp(type, "none"))
+                       options->word_diff = DIFF_WORDS_NONE;
+               else
+                       die("bad --word-diff argument: %s", type);
+       }
+       else if (!prefixcmp(arg, "--word-diff-regex=")) {
+               if (options->word_diff == DIFF_WORDS_NONE)
+                       options->word_diff = DIFF_WORDS_PLAIN;
+               options->word_regex = arg + 18;
+       }
        else if (!strcmp(arg, "--exit-code"))
                DIFF_OPT_SET(options, EXIT_WITH_STATUS);
        else if (!strcmp(arg, "--quiet"))
@@ -2886,7 +3175,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
        else if (!strcmp(arg, "--no-textconv"))
                DIFF_OPT_CLR(options, ALLOW_TEXTCONV);
        else if (!strcmp(arg, "--ignore-submodules"))
-               DIFF_OPT_SET(options, IGNORE_SUBMODULES);
+               handle_ignore_submodules_arg(options, "all");
+       else if (!prefixcmp(arg, "--ignore-submodules="))
+               handle_ignore_submodules_arg(options, arg + 20);
        else if (!strcmp(arg, "--submodule"))
                DIFF_OPT_SET(options, SUBMODULE_LOG);
        else if (!prefixcmp(arg, "--submodule=")) {
@@ -3059,6 +3350,11 @@ static void diff_flush_raw(struct diff_filepair *p, struct diff_options *opt)
 {
        int line_termination = opt->line_termination;
        int inter_name_termination = line_termination ? '\t' : '\0';
+       if (opt->output_prefix) {
+               struct strbuf *msg = NULL;
+               msg = opt->output_prefix(opt, opt->output_prefix_data);
+               fprintf(opt->file, "%s", msg->buf);
+       }
 
        if (!(opt->output_format & DIFF_FORMAT_NAME_STATUS)) {
                fprintf(opt->file, ":%06o %06o %s ", p->one->mode, p->two->mode,
@@ -3304,48 +3600,62 @@ static void show_file_mode_name(FILE *file, const char *newdelete, struct diff_f
 }
 
 
-static void show_mode_change(FILE *file, struct diff_filepair *p, int show_name)
+static void show_mode_change(FILE *file, struct diff_filepair *p, int show_name,
+               const char *line_prefix)
 {
        if (p->one->mode && p->two->mode && p->one->mode != p->two->mode) {
-               fprintf(file, " mode change %06o => %06o%c", p->one->mode, p->two->mode,
-                       show_name ? ' ' : '\n');
+               fprintf(file, "%s mode change %06o => %06o%c", line_prefix, p->one->mode,
+                       p->two->mode, show_name ? ' ' : '\n');
                if (show_name) {
                        write_name_quoted(p->two->path, file, '\n');
                }
        }
 }
 
-static void show_rename_copy(FILE *file, const char *renamecopy, struct diff_filepair *p)
+static void show_rename_copy(FILE *file, const char *renamecopy, struct diff_filepair *p,
+                       const char *line_prefix)
 {
        char *names = pprint_rename(p->one->path, p->two->path);
 
        fprintf(file, " %s %s (%d%%)\n", renamecopy, names, similarity_index(p));
        free(names);
-       show_mode_change(file, p, 0);
+       show_mode_change(file, p, 0, line_prefix);
 }
 
-static void diff_summary(FILE *file, struct diff_filepair *p)
+static void diff_summary(struct diff_options *opt, struct diff_filepair *p)
 {
+       FILE *file = opt->file;
+       char *line_prefix = "";
+
+       if (opt->output_prefix) {
+               struct strbuf *buf = opt->output_prefix(opt, opt->output_prefix_data);
+               line_prefix = buf->buf;
+       }
+
        switch(p->status) {
        case DIFF_STATUS_DELETED:
+               fputs(line_prefix, file);
                show_file_mode_name(file, "delete", p->one);
                break;
        case DIFF_STATUS_ADDED:
+               fputs(line_prefix, file);
                show_file_mode_name(file, "create", p->two);
                break;
        case DIFF_STATUS_COPIED:
-               show_rename_copy(file, "copy", p);
+               fputs(line_prefix, file);
+               show_rename_copy(file, "copy", p, line_prefix);
                break;
        case DIFF_STATUS_RENAMED:
-               show_rename_copy(file, "rename", p);
+               fputs(line_prefix, file);
+               show_rename_copy(file, "rename", p, line_prefix);
                break;
        default:
                if (p->score) {
-                       fputs(" rewrite ", file);
+                       fprintf(file, "%s rewrite ", line_prefix);
                        write_name_quoted(p->two->path, file, ' ');
                        fprintf(file, "(%d%%)\n", similarity_index(p));
                }
-               show_mode_change(file, p, !p->score);
+               show_mode_change(file, p, !p->score, line_prefix);
                break;
        }
 }
@@ -3477,8 +3787,7 @@ int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1)
                diff_free_filepair(q->queue[i]);
 
        free(q->queue);
-       q->queue = NULL;
-       q->nr = q->alloc = 0;
+       DIFF_QUEUE_CLEAR(q);
 
        return result;
 }
@@ -3555,8 +3864,9 @@ void diff_flush(struct diff_options *options)
                show_dirstat(options);
 
        if (output_format & DIFF_FORMAT_SUMMARY && !is_summary_empty(q)) {
-               for (i = 0; i < q->nr; i++)
-                       diff_summary(options->file, q->queue[i]);
+               for (i = 0; i < q->nr; i++) {
+                       diff_summary(options, q->queue[i]);
+               }
                separator++;
        }
 
@@ -3606,8 +3916,7 @@ void diff_flush(struct diff_options *options)
                diff_free_filepair(q->queue[i]);
 free_queue:
        free(q->queue);
-       q->queue = NULL;
-       q->nr = q->alloc = 0;
+       DIFF_QUEUE_CLEAR(q);
        if (options->close_file)
                fclose(options->file);
 
@@ -3629,8 +3938,7 @@ static void diffcore_apply_filter(const char *filter)
        int i;
        struct diff_queue_struct *q = &diff_queued_diff;
        struct diff_queue_struct outq;
-       outq.queue = NULL;
-       outq.nr = outq.alloc = 0;
+       DIFF_QUEUE_CLEAR(&outq);
 
        if (!filter)
                return;
@@ -3698,8 +4006,7 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
        int i;
        struct diff_queue_struct *q = &diff_queued_diff;
        struct diff_queue_struct outq;
-       outq.queue = NULL;
-       outq.nr = outq.alloc = 0;
+       DIFF_QUEUE_CLEAR(&outq);
 
        for (i = 0; i < q->nr; i++) {
                struct diff_filepair *p = q->queue[i];
@@ -3762,23 +4069,30 @@ void diffcore_std(struct diff_options *options)
 {
        if (options->skip_stat_unmatch)
                diffcore_skip_stat_unmatch(options);
-       if (options->break_opt != -1)
-               diffcore_break(options->break_opt);
-       if (options->detect_rename)
-               diffcore_rename(options);
-       if (options->break_opt != -1)
-               diffcore_merge_broken();
+       if (!options->found_follow) {
+               /* See try_to_follow_renames() in tree-diff.c */
+               if (options->break_opt != -1)
+                       diffcore_break(options->break_opt);
+               if (options->detect_rename)
+                       diffcore_rename(options);
+               if (options->break_opt != -1)
+                       diffcore_merge_broken();
+       }
        if (options->pickaxe)
                diffcore_pickaxe(options->pickaxe, options->pickaxe_opts);
        if (options->orderfile)
                diffcore_order(options->orderfile);
-       diff_resolve_rename_copy();
+       if (!options->found_follow)
+               /* See try_to_follow_renames() in tree-diff.c */
+               diff_resolve_rename_copy();
        diffcore_apply_filter(options->filter);
 
        if (diff_queued_diff.nr && !DIFF_OPT_TST(options, DIFF_FROM_CONTENTS))
                DIFF_OPT_SET(options, HAS_CHANGES);
        else
                DIFF_OPT_CLR(options, HAS_CHANGES);
+
+       options->found_follow = 0;
 }
 
 int diff_result_code(struct diff_options *opt, int status)
@@ -3932,3 +4246,47 @@ static char *run_textconv(const char *pgm, struct diff_filespec *spec,
 
        return strbuf_detach(&buf, outsize);
 }
+
+size_t fill_textconv(struct userdiff_driver *driver,
+                    struct diff_filespec *df,
+                    char **outbuf)
+{
+       size_t size;
+
+       if (!driver || !driver->textconv) {
+               if (!DIFF_FILE_VALID(df)) {
+                       *outbuf = "";
+                       return 0;
+               }
+               if (diff_populate_filespec(df, 0))
+                       die("unable to read files to diff");
+               *outbuf = df->data;
+               return df->size;
+       }
+
+       if (driver->textconv_cache) {
+               *outbuf = notes_cache_get(driver->textconv_cache, df->sha1,
+                                         &size);
+               if (*outbuf)
+                       return size;
+       }
+
+       *outbuf = run_textconv(driver->textconv, df, &size);
+       if (!*outbuf)
+               die("unable to read files to diff");
+
+       if (driver->textconv_cache) {
+               /* ignore errors, as we might be in a readonly repository */
+               notes_cache_put(driver->textconv_cache, df->sha1, *outbuf,
+                               size);
+               /*
+                * we could save up changes and flush them all at the end,
+                * but we would need an extra call after all diffing is done.
+                * Since generating a cache entry is the slow path anyway,
+                * this extra overhead probably isn't a big deal.
+                */
+               notes_cache_write(driver->textconv_cache);
+       }
+
+       return size;
+}
diff --git a/diff.h b/diff.h
index 6a71013dc63fc0912fd4f3d27f70ae909917f1f6..6fff024e3ad9462c717595cd90d7fcca1da6410c 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -9,6 +9,9 @@
 struct rev_info;
 struct diff_options;
 struct diff_queue_struct;
+struct strbuf;
+struct diff_filespec;
+struct userdiff_driver;
 
 typedef void (*change_fn_t)(struct diff_options *options,
                 unsigned old_mode, unsigned new_mode,
@@ -25,6 +28,8 @@ typedef void (*add_remove_fn_t)(struct diff_options *options,
 typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
                struct diff_options *options, void *data);
 
+typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data);
+
 #define DIFF_FORMAT_RAW                0x0001
 #define DIFF_FORMAT_DIFFSTAT   0x0002
 #define DIFF_FORMAT_NUMSTAT    0x0004
@@ -54,7 +59,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
 #define DIFF_OPT_FIND_COPIES_HARDER  (1 <<  6)
 #define DIFF_OPT_FOLLOW_RENAMES      (1 <<  7)
 #define DIFF_OPT_COLOR_DIFF          (1 <<  8)
-#define DIFF_OPT_COLOR_DIFF_WORDS    (1 <<  9)
+/* (1 <<  9) unused */
 #define DIFF_OPT_HAS_CHANGES         (1 << 10)
 #define DIFF_OPT_QUICK               (1 << 11)
 #define DIFF_OPT_NO_INDEX            (1 << 12)
@@ -71,6 +76,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
 #define DIFF_OPT_SUBMODULE_LOG       (1 << 23)
 #define DIFF_OPT_DIRTY_SUBMODULES    (1 << 24)
 #define DIFF_OPT_IGNORE_UNTRACKED_IN_SUBMODULES (1 << 25)
+#define DIFF_OPT_IGNORE_DIRTY_SUBMODULES (1 << 26)
 
 #define DIFF_OPT_TST(opts, flag)    ((opts)->flags & DIFF_OPT_##flag)
 #define DIFF_OPT_SET(opts, flag)    ((opts)->flags |= DIFF_OPT_##flag)
@@ -79,6 +85,13 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
 #define DIFF_XDL_SET(opts, flag)    ((opts)->xdl_opts |= XDF_##flag)
 #define DIFF_XDL_CLR(opts, flag)    ((opts)->xdl_opts &= ~XDF_##flag)
 
+enum diff_words_type {
+       DIFF_WORDS_NONE = 0,
+       DIFF_WORDS_PORCELAIN,
+       DIFF_WORDS_PLAIN,
+       DIFF_WORDS_COLOR
+};
+
 struct diff_options {
        const char *filter;
        const char *orderfile;
@@ -108,10 +121,14 @@ struct diff_options {
        int stat_width;
        int stat_name_width;
        const char *word_regex;
+       enum diff_words_type word_diff;
 
        /* this is set by diffcore for DIFF_FORMAT_PATCH */
        int found_changes;
 
+       /* to support internal diff recursion by --follow hack*/
+       int found_follow;
+
        FILE *file;
        int close_file;
 
@@ -122,6 +139,8 @@ struct diff_options {
        add_remove_fn_t add_remove;
        diff_format_fn_t format_callback;
        void *format_callback_data;
+       diff_prefix_fn_t output_prefix;
+       void *output_prefix_data;
 };
 
 enum color_diff {
@@ -133,7 +152,7 @@ enum color_diff {
        DIFF_FILE_NEW = 5,
        DIFF_COMMIT = 6,
        DIFF_WHITESPACE = 7,
-       DIFF_FUNCINFO = 8,
+       DIFF_FUNCINFO = 8
 };
 const char *diff_get_color(int diff_use_color, enum color_diff ix);
 #define diff_get_color_opt(o, ix) \
@@ -279,4 +298,10 @@ extern void diff_no_index(struct rev_info *, int, const char **, int, const char
 
 extern int index_differs_from(const char *def, int diff_flags);
 
+extern size_t fill_textconv(struct userdiff_driver *driver,
+                           struct diff_filespec *df,
+                           char **outbuf);
+
+extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
+
 #endif /* DIFF_H */
index 3a7b60a037b2e3c869afe76a23b671cfd5311338..44f8678d22ea466b0867591429bbcc3285cdaf91 100644 (file)
@@ -162,8 +162,7 @@ void diffcore_break(int break_score)
        if (!merge_score)
                merge_score = DEFAULT_MERGE_SCORE;
 
-       outq.nr = outq.alloc = 0;
-       outq.queue = NULL;
+       DIFF_QUEUE_CLEAR(&outq);
 
        for (i = 0; i < q->nr; i++) {
                struct diff_filepair *p = q->queue[i];
@@ -256,8 +255,7 @@ void diffcore_merge_broken(void)
        struct diff_queue_struct outq;
        int i, j;
 
-       outq.nr = outq.alloc = 0;
-       outq.queue = NULL;
+       DIFF_QUEUE_CLEAR(&outq);
 
        for (i = 0; i < q->nr; i++) {
                struct diff_filepair *p = q->queue[i];
index d0ef8397008824fb5139680856e3229ecf2c4eb1..929de15aa9228099b3a772be788d746e440a9e8c 100644 (file)
@@ -55,8 +55,7 @@ void diffcore_pickaxe(const char *needle, int opts)
        int i, has_changes;
        regex_t regex, *regexp = NULL;
        struct diff_queue_struct outq;
-       outq.queue = NULL;
-       outq.nr = outq.alloc = 0;
+       DIFF_QUEUE_CLEAR(&outq);
 
        if (opts & DIFF_PICKAXE_REGEX) {
                int err;
index d6fd3cacd6de4757994c61903dd07e0c4d74a9e9..df41be56deab60d4d39a45920a1e62b05d0474f6 100644 (file)
@@ -569,8 +569,7 @@ void diffcore_rename(struct diff_options *options)
        /* At this point, we have found some renames and copies and they
         * are recorded in rename_dst.  The original list is still in *q.
         */
-       outq.queue = NULL;
-       outq.nr = outq.alloc = 0;
+       DIFF_QUEUE_CLEAR(&outq);
        for (i = 0; i < q->nr; i++) {
                struct diff_filepair *p = q->queue[i];
                struct diff_filepair *pair_to_free = NULL;
index fcd00bf27aee4e1f2823f05ab3dba1d3c70a509d..8b3241ad137f5934e32336cd1caf8d99ca11d1f5 100644 (file)
@@ -18,7 +18,7 @@
 #define MAX_SCORE 60000.0
 #define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */
 #define DEFAULT_BREAK_SCORE  30000 /* minimum for break to happen (50%) */
-#define DEFAULT_MERGE_SCORE  36000 /* maximum for break-merge to happen 60%) */
+#define DEFAULT_MERGE_SCORE  36000 /* maximum for break-merge to happen (60%) */
 
 #define MINIMUM_BREAK_SIZE     400 /* do not break a file smaller than this */
 
@@ -92,6 +92,11 @@ struct diff_queue_struct {
        int alloc;
        int nr;
 };
+#define DIFF_QUEUE_CLEAR(q) \
+       do { \
+               (q)->queue = NULL; \
+               (q)->nr = (q)->alloc = 0; \
+       } while (0)
 
 extern struct diff_queue_struct diff_queued_diff;
 extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
@@ -111,9 +116,9 @@ void diff_debug_filespec(struct diff_filespec *, int, const char *);
 void diff_debug_filepair(const struct diff_filepair *, int);
 void diff_debug_queue(const char *, struct diff_queue_struct *);
 #else
-#define diff_debug_filespec(a,b,c) do {} while(0)
-#define diff_debug_filepair(a,b) do {} while(0)
-#define diff_debug_queue(a,b) do {} while(0)
+#define diff_debug_filespec(a,b,c) do { /* nothing */ } while (0)
+#define diff_debug_filepair(a,b) do { /* nothing */ } while (0)
+#define diff_debug_queue(a,b) do { /* nothing */ } while (0)
 #endif
 
 extern int diffcore_count_changes(struct diff_filespec *src,
diff --git a/dir.c b/dir.c
index 7f912c76f268e2f27857a67d565e77be0e43660d..133f472a1e73786e781c1021eea17e543858937f 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -453,7 +453,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathna
        return dir->entries[dir->nr++] = dir_entry_new(pathname, len);
 }
 
-static struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)
+struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)
 {
        if (!cache_name_is_other(pathname, len))
                return NULL;
@@ -465,7 +465,7 @@ static struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pat
 enum exist_status {
        index_nonexistent = 0,
        index_directory,
-       index_gitdir,
+       index_gitdir
 };
 
 /*
@@ -533,7 +533,7 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len)
 enum directory_treatment {
        show_directory,
        ignore_directory,
-       recurse_into_directory,
+       recurse_into_directory
 };
 
 static enum directory_treatment treat_directory(struct dir_struct *dir,
@@ -684,7 +684,7 @@ static int get_dtype(struct dirent *de, const char *path, int len)
 enum path_treatment {
        path_ignored,
        path_handled,
-       path_recurse,
+       path_recurse
 };
 
 static enum path_treatment treat_one_path(struct dir_struct *dir,
diff --git a/dir.h b/dir.h
index 3bead5f0e25a864c34f515b7bff4c89b55ce84fe..278d84cdf7df01c33a45e6dc9c20592cecff9d85 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -72,6 +72,7 @@ extern int read_directory(struct dir_struct *, const char *path, int len, const
 extern int excluded_from_list(const char *pathname, int pathlen, const char *basename,
                              int *dtype, struct exclude_list *el);
 extern int excluded(struct dir_struct *, const char *, int *);
+struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len);
 extern int add_excludes_from_file_to_list(const char *fname, const char *base, int baselen,
                                          char **buf_p, struct exclude_list *which, int check_index);
 extern void add_excludes_from_file(struct dir_struct *, const char *fname);
index 876c5e53410250b5f2744671e39907c234771af3..83d38d3c2354e8582d5af91c6d529a2f2836dc2c 100644 (file)
@@ -38,8 +38,9 @@ const char *pager_program;
 int pager_use_color = 1;
 const char *editor_program;
 const char *excludes_file;
-int auto_crlf = 0;     /* 1: both ways, -1: only when adding git objects */
+enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
 int read_replace_refs = 1;
+enum eol eol = EOL_UNSET;
 enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
 unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
 enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
index 309f2c58a2ba431a82a56f757482a5093cc8257d..ddad289dae37c2115f57f88dc207f0d2fa6ab1f3 100644 (file)
@@ -267,7 +267,7 @@ struct hash_list
 typedef enum {
        WHENSPEC_RAW = 1,
        WHENSPEC_RFC2822,
-       WHENSPEC_NOW,
+       WHENSPEC_NOW
 } whenspec_type;
 
 struct recent_command
@@ -1666,7 +1666,7 @@ static void dump_marks_helper(FILE *f,
        if (m->shift) {
                for (k = 0; k < 1024; k++) {
                        if (m->data.sets[k])
-                               dump_marks_helper(f, (base + k) << m->shift,
+                               dump_marks_helper(f, base + (k << m->shift),
                                        m->data.sets[k]);
                }
        } else {
@@ -2707,6 +2707,7 @@ static void option_import_marks(const char *marks, int from_stream)
        }
 
        import_marks_file = make_fast_import_path(marks);
+       safe_create_leading_directories_const(import_marks_file);
        import_marks_file_from_stream = from_stream;
 }
 
@@ -2737,6 +2738,7 @@ static void option_active_branches(const char *branches)
 static void option_export_marks(const char *marks)
 {
        export_marks_file = make_fast_import_path(marks);
+       safe_create_leading_directories_const(export_marks_file);
 }
 
 static void option_export_pack_edges(const char *edges)
diff --git a/fsck.c b/fsck.c
index 89278c1459d36a3e2b718661ca71483522f587fd..3d05d4a794a4158a421ce1265422d241e28a5278 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -222,12 +222,47 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
        return retval;
 }
 
+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] != ' ')
+               return error_func(obj, FSCK_ERROR, "invalid author/committer line - missing space before email");
+       if (**ident != '<')
+               return error_func(obj, FSCK_ERROR, "invalid author/committer line - missing email");
+       (*ident)++;
+       *ident += strcspn(*ident, "<>\n");
+       if (**ident != '>')
+               return error_func(obj, FSCK_ERROR, "invalid author/committer line - bad email");
+       (*ident)++;
+       if (**ident != ' ')
+               return error_func(obj, FSCK_ERROR, "invalid author/committer line - missing space before date");
+       (*ident)++;
+       if (**ident == '0' && (*ident)[1] != ' ')
+               return error_func(obj, FSCK_ERROR, "invalid author/committer line - zero-padded date");
+       *ident += strspn(*ident, "0123456789");
+       if (**ident != ' ')
+               return error_func(obj, FSCK_ERROR, "invalid author/committer line - bad date");
+       (*ident)++;
+       if ((**ident != '+' && **ident != '-') ||
+           !isdigit((*ident)[1]) ||
+           !isdigit((*ident)[2]) ||
+           !isdigit((*ident)[3]) ||
+           !isdigit((*ident)[4]) ||
+           ((*ident)[5] != '\n'))
+               return error_func(obj, FSCK_ERROR, "invalid author/committer line - bad time zone");
+       (*ident) += 6;
+       return 0;
+}
+
 static int fsck_commit(struct commit *commit, fsck_error error_func)
 {
        char *buffer = commit->buffer;
        unsigned char tree_sha1[20], sha1[20];
        struct commit_graft *graft;
        int parents = 0;
+       int err;
 
        if (commit->date == ULONG_MAX)
                return error_func(&commit->object, FSCK_ERROR, "invalid author/committer line");
@@ -266,6 +301,16 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
        }
        if (memcmp(buffer, "author ", 7))
                return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'author' line");
+       buffer += 7;
+       err = fsck_ident(&buffer, &commit->object, error_func);
+       if (err)
+               return err;
+       if (memcmp(buffer, "committer ", strlen("committer ")))
+               return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'committer' line");
+       buffer += strlen("committer ");
+       err = fsck_ident(&buffer, &commit->object, error_func);
+       if (err)
+               return err;
        if (!commit->tree)
                return error_func(&commit->object, FSCK_ERROR, "could not load commit's tree %s", sha1_to_hex(tree_sha1));
 
index 1df5b04146a118831f4b8d30652aa506c7e4b02e..e7f008c7baae2ff484e16882e199b6b9d75195aa 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
@@ -52,6 +52,16 @@ else
        HAS_HEAD=
 fi
 
+cmdline="git am"
+if test '' != "$interactive"
+then
+       cmdline="$cmdline -i"
+fi
+if test '' != "$threeway"
+then
+       cmdline="$cmdline -3"
+fi
+
 sq () {
        git rev-parse --sq-quote "$@"
 }
@@ -66,15 +76,6 @@ stop_here_user_resolve () {
            printf '%s\n' "$resolvemsg"
            stop_here $1
     fi
-    cmdline="git am"
-    if test '' != "$interactive"
-    then
-        cmdline="$cmdline -i"
-    fi
-    if test '' != "$threeway"
-    then
-        cmdline="$cmdline -3"
-    fi
     echo "When you have resolved this problem run \"$cmdline --resolved\"."
     echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"."
     echo "To restore the original branch and stop patching run \"$cmdline --abort\"."
@@ -591,6 +592,8 @@ do
 
                test -s "$dotest/patch" || {
                        echo "Patch is empty.  Was it split wrong?"
+                       echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"."
+                       echo "To restore the original branch and stop patching run \"$cmdline --abort\"."
                        stop_here $this
                }
                rm -f "$dotest/original-commit" "$dotest/author-script"
@@ -696,7 +699,13 @@ do
        else
            action=yes
        fi
-       FIRSTLINE=$(sed 1q "$dotest/final-commit")
+
+       if test -f "$dotest/final-commit"
+       then
+               FIRSTLINE=$(sed 1q "$dotest/final-commit")
+       else
+               FIRSTLINE=""
+       fi
 
        if test $action = skip
        then
@@ -732,6 +741,8 @@ do
                resolved=
                git diff-index --quiet --cached HEAD -- && {
                        echo "No changes - did you forget to use 'git add'?"
+                       echo "If there is nothing left to stage, chances are that something else"
+                       echo "already introduced the same changes; you might want to skip this patch."
                        stop_here_user_resolve $this
                }
                unmerged=$(git ls-files -u)
index c0198dde4c2c6a61718228ca2ade463c22e0bec3..fe845ae639767dc8f56a9196a7faefb468737bba 100644 (file)
@@ -200,6 +200,7 @@ extern char *gitbasename(char *);
 #include "compat/bswap.h"
 
 /* General helper functions */
+extern void vreportf(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)));
@@ -224,7 +225,6 @@ static inline const char *skip_prefix(const char *str, const char *prefix)
 #define PROT_READ 1
 #define PROT_WRITE 2
 #define MAP_PRIVATE 1
-#define MAP_FAILED ((void*)-1)
 #endif
 
 #define mmap git_mmap
@@ -253,6 +253,10 @@ extern int git_munmap(void *start, size_t length);
 
 #endif /* NO_MMAP */
 
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
 #ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
 #define on_disk_bytes(st) ((st).st_size)
 #else
@@ -363,7 +367,8 @@ static inline void *gitmempcpy(void *dest, const void *src, size_t n)
 
 extern void release_pack_memory(size_t, int);
 
-extern void set_try_to_free_routine(void (*routine)(size_t));
+typedef void (*try_to_free_t)(size_t);
+extern try_to_free_t set_try_to_free_routine(try_to_free_t);
 
 extern char *xstrdup(const char *str);
 extern void *xmalloc(size_t size);
@@ -383,6 +388,8 @@ extern int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1);
 
 static inline size_t xsize_t(off_t len)
 {
+       if (len > (size_t) len)
+               die("Cannot handle files this big");
        return (size_t)len;
 }
 
index 13751db882dd2c40e2c78503eba0d3f941297644..e9f3037df351ceed0262a8995f19903464163af8 100755 (executable)
@@ -183,12 +183,58 @@ if ($state->{method} eq 'pserver') {
        exit 1;
     }
     $line = <STDIN>; chomp $line;
-    unless ($line eq 'anonymous') {
-       print "E Only anonymous user allowed via pserver\n";
-       print "I HATE YOU\n";
-       exit 1;
+    my $user = $line;
+    $line = <STDIN>; chomp $line;
+    my $password = $line;
+
+    if ($user eq 'anonymous') {
+        # "A" will be 1 byte, use length instead in case the
+        # encryption method ever changes (yeah, right!)
+        if (length($password) > 1 ) {
+            print "E Don't supply a password for the `anonymous' user\n";
+            print "I HATE YOU\n";
+            exit 1;
+        }
+
+        # Fall through to LOVE
+    } else {
+        # Trying to authenticate a user
+        if (not exists $cfg->{gitcvs}->{authdb}) {
+            print "E the repo config file needs a [gitcvs] section with an 'authdb' parameter set to the filename of the authentication database\n";
+            print "I HATE YOU\n";
+            exit 1;
+        }
+
+        my $authdb = $cfg->{gitcvs}->{authdb};
+
+        unless (-e $authdb) {
+            print "E The authentication database specified in [gitcvs.authdb] does not exist\n";
+            print "I HATE YOU\n";
+            exit 1;
+        }
+
+        my $auth_ok;
+        open my $passwd, "<", $authdb or die $!;
+        while (<$passwd>) {
+            if (m{^\Q$user\E:(.*)}) {
+                if (crypt($user, descramble($password)) eq $1) {
+                    $auth_ok = 1;
+                }
+            };
+        }
+        close $passwd;
+
+        unless ($auth_ok) {
+            print "I HATE YOU\n";
+            exit 1;
+        }
+
+        # Fall through to LOVE
     }
-    $line = <STDIN>; chomp $line;    # validate the password?
+
+    # For checking whether the user is anonymous on commit
+    $state->{user} = $user;
+
     $line = <STDIN>; chomp $line;
     unless ($line eq "END $request REQUEST") {
        die "E Do not understand $line -- expecting END $request REQUEST\n";
@@ -1271,9 +1317,9 @@ sub req_ci
 
     $log->info("req_ci : " . ( defined($data) ? $data : "[NULL]" ));
 
-    if ( $state->{method} eq 'pserver')
+    if ( $state->{method} eq 'pserver' and $state->{user} eq 'anonymous' )
     {
-        print "error 1 pserver access cannot commit\n";
+        print "error 1 anonymous user cannot commit via pserver\n";
         cleanupWorkTree();
         exit;
     }
@@ -2369,15 +2415,20 @@ sub kopts_from_path
     if ( defined ( $cfg->{gitcvs}{usecrlfattr} ) and
          $cfg->{gitcvs}{usecrlfattr} =~ /\s*(1|true|yes)\s*$/i )
     {
-        my ($val) = check_attr( "crlf", $path );
-        if ( $val eq "set" )
+        my ($val) = check_attr( "text", $path );
+        if ( $val eq "unspecified" )
         {
-            return "";
+            $val = check_attr( "crlf", $path );
         }
-        elsif ( $val eq "unset" )
+        if ( $val eq "unset" )
         {
             return "-kb"
         }
+        elsif ( check_attr( "eol", $path ) ne "unspecified" ||
+                $val eq "set" || $val eq "input" )
+        {
+            return "";
+        }
         else
         {
             $log->info("Unrecognized check_attr crlf $path : $val");
@@ -2586,6 +2637,43 @@ sub cvs_author
     $author;
 }
 
+
+sub descramble
+{
+    # This table is from src/scramble.c in the CVS source
+    my @SHIFTS = (
+        0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
+        16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+        114,120, 53, 79, 96,109, 72,108, 70, 64, 76, 67,116, 74, 68, 87,
+        111, 52, 75,119, 49, 34, 82, 81, 95, 65,112, 86,118,110,122,105,
+        41, 57, 83, 43, 46,102, 40, 89, 38,103, 45, 50, 42,123, 91, 35,
+        125, 55, 54, 66,124,126, 59, 47, 92, 71,115, 78, 88,107,106, 56,
+        36,121,117,104,101,100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48,
+        58,113, 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85,223,
+        225,216,187,166,229,189,222,188,141,249,148,200,184,136,248,190,
+        199,170,181,204,138,232,218,183,255,234,220,247,213,203,226,193,
+        174,172,228,252,217,201,131,230,197,211,145,238,161,179,160,212,
+        207,221,254,173,202,146,224,151,140,196,205,130,135,133,143,246,
+        192,159,244,239,185,168,215,144,139,165,180,157,147,186,214,176,
+        227,231,219,169,175,156,206,198,129,164,150,210,154,177,134,127,
+        182,128,158,208,162,132,167,209,149,241,153,251,237,236,171,195,
+        243,233,253,240,194,250,191,155,142,137,245,235,163,242,178,152
+    );
+    my ($str) = @_;
+
+    # This should never happen, the same password format (A) has been
+    # used by CVS since the beginning of time
+    {
+        my $fmt = substr($str, 0, 1);
+        die "invalid password format `$fmt'" unless $fmt eq 'A';
+    }
+
+    my @str = unpack "C*", substr($str, 1);
+    my $ret = join '', map { chr $SHIFTS[$_] } @str;
+    return $ret;
+}
+
+
 package GITCVS::log;
 
 ####
index 7d5451198cb109e1d3e30e3e33f1557bbd8b12c0..bb104895a94450a2ade7446c8fda52910bae0868 100755 (executable)
@@ -38,7 +38,7 @@ if {[catch {package require Tcl 8.4} err]
        tk_messageBox \
                -icon error \
                -type ok \
-               -title [mc "git-gui: fatal error"] \
+               -title "git-gui: fatal error" \
                -message $err
        exit 1
 }
@@ -269,6 +269,17 @@ proc is_config_true {name} {
        }
 }
 
+proc is_config_false {name} {
+       global repo_config
+       if {[catch {set v $repo_config($name)}]} {
+               return 0
+       } elseif {$v eq {false} || $v eq {0} || $v eq {no}} {
+               return 1
+       } else {
+               return 0
+       }
+}
+
 proc get_config {name} {
        global repo_config
        if {[catch {set v $repo_config($name)}]} {
@@ -323,6 +334,8 @@ proc _trace_exec {cmd} {
        puts stderr $d
 }
 
+#'"  fix poor old emacs font-lock mode
+
 proc _git_cmd {name} {
        global _git_cmd_path
 
@@ -416,6 +429,9 @@ proc _lappend_nice {cmd_var} {
 
        if {![info exists _nice]} {
                set _nice [_which nice]
+               if {[catch {exec $_nice git version}]} {
+                       set _nice {}
+               }
        }
        if {$_nice ne {}} {
                lappend cmd $_nice
@@ -634,6 +650,7 @@ proc rmsel_tag {text} {
        return $text
 }
 
+wm withdraw .
 set root_exists 0
 bind . <Visibility> {
        bind . <Visibility> {}
@@ -782,6 +799,7 @@ set default_config(user.email) {}
 
 set default_config(gui.encoding) [encoding system]
 set default_config(gui.matchtrackingbranch) false
+set default_config(gui.textconv) true
 set default_config(gui.pruneduringfetch) false
 set default_config(gui.trustmtime) false
 set default_config(gui.fastcopyblame) false
@@ -1155,6 +1173,9 @@ apply_config
 # try to set work tree from environment, falling back to core.worktree
 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
        set _gitworktree [get_config core.worktree]
+       if {$_gitworktree eq ""} {
+               set _gitworktree [file dirname [file normalize $_gitdir]]
+       }
 }
 if {$_prefix ne {}} {
        if {$_gitworktree eq {}} {
@@ -2098,7 +2119,7 @@ proc do_explore {} {
                # freedesktop.org-conforming system is our best shot
                set explorer "xdg-open"
        }
-       eval exec $explorer $_gitworktree &
+       eval exec $explorer [list [file nativename $_gitworktree]] &
 }
 
 set is_quitting 0
@@ -2901,6 +2922,7 @@ blame {
                set current_branch $head
        }
 
+       wm deiconify .
        switch -- $subcommand {
        browser {
                if {$jump_spec ne {}} usage
@@ -3405,6 +3427,19 @@ lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
 $ctxmsm add separator
 create_common_diff_popup $ctxmsm
 
+proc has_textconv {path} {
+       if {[is_config_false gui.textconv]} {
+               return 0
+       }
+       set filter [gitattr $path diff set]
+       set textconv [get_config [join [list diff $filter textconv] .]]
+       if {$filter ne {set} && $textconv ne {}} {
+               return 1
+       } else {
+               return 0
+       }
+}
+
 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
        global current_diff_path file_states
        set ::cursorX $x
@@ -3440,7 +3475,8 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
                        || {__} eq $state
                        || {_O} eq $state
                        || {_T} eq $state
-                       || {T_} eq $state} {
+                       || {T_} eq $state
+                       || [has_textconv $current_diff_path]} {
                        set s disabled
                } else {
                        set s normal
@@ -3460,29 +3496,44 @@ $main_status show [mc "Initializing..."]
 
 # -- Load geometry
 #
-catch {
-set gm $repo_config(gui.geometry)
-wm geometry . [lindex $gm 0]
-if {$use_ttk} {
-       .vpane sashpos 0 [lindex $gm 1]
-       .vpane.files sashpos 0 [lindex $gm 2]
-} else {
-       .vpane sash place 0 \
-               [lindex $gm 1] \
-               [lindex [.vpane sash coord 0] 1]
-       .vpane.files sash place 0 \
-               [lindex [.vpane.files sash coord 0] 0] \
-               [lindex $gm 2]
+proc on_ttk_pane_mapped {w pane pos} {
+       bind $w <Map> {}
+       after 0 [list after idle [list $w sashpos $pane $pos]]
+}
+proc on_tk_pane_mapped {w pane x y} {
+       bind $w <Map> {}
+       after 0 [list after idle [list $w sash place $pane $x $y]]
+}
+proc on_application_mapped {} {
+       global repo_config use_ttk
+       bind . <Map> {}
+       set gm $repo_config(gui.geometry)
+       if {$use_ttk} {
+               bind .vpane <Map> \
+                   [list on_ttk_pane_mapped %W 0 [lindex $gm 1]]
+               bind .vpane.files <Map> \
+                   [list on_ttk_pane_mapped %W 0 [lindex $gm 2]]
+       } else {
+               bind .vpane <Map> \
+                   [list on_tk_pane_mapped %W 0 \
+                        [lindex $gm 1] \
+                        [lindex [.vpane sash coord 0] 1]]
+               bind .vpane.files <Map> \
+                   [list on_tk_pane_mapped %W 0 \
+                        [lindex [.vpane.files sash coord 0] 0] \
+                        [lindex $gm 2]]
+       }
+       wm geometry . [lindex $gm 0]
 }
-unset gm
+if {[info exists repo_config(gui.geometry)]} {
+       bind . <Map> [list on_application_mapped]
+       wm geometry . [lindex $repo_config(gui.geometry) 0]
 }
 
 # -- Load window state
 #
-catch {
-set gws $repo_config(gui.wmstate)
-wm state . $gws
-unset gws
+if {[info exists repo_config(gui.wmstate)]} {
+       catch {wm state . $repo_config(gui.wmstate)}
 }
 
 # -- Key Bindings
index 786b50b8c2b6f877d1d1a3a86d27368281ec2ae8..2137ec9684d0acdb386e6b50e1b41aa7705c9746 100644 (file)
@@ -449,11 +449,28 @@ method _load {jump} {
 
        $status show [mc "Reading %s..." "$commit:[escape_path $path]"]
        $w_path conf -text [escape_path $path]
+
+       set do_textconv 0
+       if {![is_config_false gui.textconv] && [git-version >= 1.7.2]} {
+               set filter [gitattr $path diff set]
+               set textconv [get_config [join [list diff $filter textconv] .]]
+               if {$filter ne {set} && $textconv ne {}} {
+                       set do_textconv 1
+               }
+       }
        if {$commit eq {}} {
-               set fd [open $path r]
+               if {$do_textconv ne 0} {
+                       set fd [open |[list $textconv $path] r]
+               } else {
+                       set fd [open $path r]
+               }
                fconfigure $fd -eofchar {}
        } else {
-               set fd [git_read cat-file blob "$commit:$path"]
+               if {$do_textconv ne 0} {
+                       set fd [git_read cat-file --textconv "$commit:$path"]
+               } else {
+                       set fd [git_read cat-file blob "$commit:$path"]
+               }
        }
        fconfigure $fd \
                -blocking 0 \
index 64f06748b612721143e851824e30987575010be2..fae119286d3d4511d1b362fb05a8fab775e80a40 100644 (file)
@@ -100,12 +100,17 @@ constructor pick {} {
        $opts insert end [mc "Clone Existing Repository"] link_clone
        $opts insert end "\n"
        if {$m_repo ne {}} {
+               if {[tk windowingsystem] eq "win32"} {
+                       set key L
+               } else {
+                       set key C
+               }
                $m_repo add command \
                        -command [cb _next clone] \
-                       -accelerator $M1T-C \
+                       -accelerator $M1T-$key \
                        -label [mc "Clone..."]
-               bind $top <$M1B-c> [cb _next clone]
-               bind $top <$M1B-C> [cb _next clone]
+               bind $top <$M1B-[string tolower $key]> [cb _next clone]
+               bind $top <$M1B-[string toupper $key]> [cb _next clone]
        }
 
        $opts tag conf link_open -foreground blue -underline 1
index ec8c11eeb7912e2e49e48f467ffc27fd9fc5f919..c628750276303fca620c9292463c4c59690c764f 100644 (file)
@@ -55,7 +55,7 @@ proc handle_empty_diff {} {
 
        set path $current_diff_path
        set s $file_states($path)
-       if {[lindex $s 0] ne {_M}} return
+       if {[lindex $s 0] ne {_M} || [has_textconv $path]} return
 
        # Prevent infinite rescan loops
        incr diff_empty_count
@@ -280,6 +280,9 @@ proc start_show_diff {cont_info {add_opts {}}} {
                        lappend cmd diff-files
                }
        }
+       if {![is_config_false gui.textconv] && [git-version >= 1.6.1]} {
+               lappend cmd --textconv
+       }
 
        if {[string match {160000 *} [lindex $s 2]]
         || [string match {160000 *} [lindex $s 3]]} {
index d4c5e45c8a7ade900753cb7eb5caf977e6e4ae2a..3807c8d28324a277204db9191e99ddb856041c22 100644 (file)
@@ -148,6 +148,7 @@ proc do_options {} {
                {b gui.trustmtime  {mc "Trust File Modification Timestamps"}}
                {b gui.pruneduringfetch {mc "Prune Tracking Branches During Fetch"}}
                {b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
+               {b gui.textconv {mc "Use Textconv For Diffs and Blames"}}
                {b gui.fastcopyblame {mc "Blame Copy Only On Changed Files"}}
                {i-20..200 gui.copyblamethreshold {mc "Minimum Letters To Blame Copy On"}}
                {i-0..300 gui.blamehistoryctx {mc "Blame History Context Radius (days)"}}
index 79c1888e11d210eed962eebdf67793a7367dff5a..78878ef89d11210d614fc8b3d2957705611bdaa3 100644 (file)
@@ -16,7 +16,7 @@ proc do_windows_shortcut {} {
                                        [info nameofexecutable] \
                                        [file normalize $::argv0] \
                                        ] \
-                                       [file normalize [$_gitworktree]]
+                                       [file normalize $_gitworktree]
                        } err]} {
                        error_popup [strcat [mc "Cannot write shortcut:"] "\n\n$err"]
                }
@@ -57,7 +57,7 @@ proc do_cygwin_shortcut {} {
                                        $sh -c \
                                        "CHERE_INVOKING=1 source /etc/profile;[sq $me] &" \
                                        ] \
-                                       [file normalize [$_gitworktree]]
+                                       [file normalize $_gitworktree]
                        } err]} {
                        error_popup [strcat [mc "Cannot write shortcut:"] "\n\n$err"]
                }
index 5fe3aad382f43a30a099a106f7d51f136eda0652..95cb44991fc5b018805d6091c4f98ce7ae0ccf52 100644 (file)
@@ -39,6 +39,7 @@ method _oneline_pack {} {
 }
 
 constructor two_line {path} {
+       global NS
        set w $path
        set w_l $w.l
        set w_c $w.c
index d7f93d045d1a2b3a14d2fdb4907697622b5973a8..db91ab84a56d79be6a5497f885a9181f368b9cf2 100644 (file)
@@ -18,9 +18,9 @@ proc win32_create_lnk {lnk_path lnk_exec lnk_dir} {
        eval [list exec wscript.exe \
                /E:jscript \
                /nologo \
-               [file join $oguilib win32_shortcut.js] \
+               [file nativename [file join $oguilib win32_shortcut.js]] \
                $lnk_path \
-               [file join $oguilib git-gui.ico] \
+               [file nativename [file join $oguilib git-gui.ico]] \
                $lnk_dir \
                $lnk_exec] $lnk_args
 }
index 66bbb2f8faaf83bc87819a9e288a0592f400e147..b1845c505500a0f079b2299de07d481c6b2550c4 100644 (file)
@@ -13,10 +13,11 @@ if { $argc >=2 && [lindex $argv 0] == "--working-dir" } {
        incr argc -2
 }
 
-set bindir [file dirname \
+set basedir [file dirname \
             [file dirname \
              [file dirname [info script]]]]
-set bindir [file join $bindir bin]
+set bindir [file join $basedir bin]
+set bindir "$bindir;[file join $basedir mingw bin]"
 regsub -all ";" $bindir "\\;" bindir
 set env(PATH) "$bindir;$env(PATH)"
 unset bindir
index f6080149c22bad8b3434b874b9e4079ac508ca69..b7342e22c88993756e7beb6582a896087e52a034 100755 (executable)
@@ -24,6 +24,7 @@ restart        restart the web server
 fqgitdir="$GIT_DIR"
 local="$(git config --bool --get instaweb.local)"
 httpd="$(git config --get instaweb.httpd)"
+root="$(git config --get instaweb.gitwebdir)"
 port=$(git config --get instaweb.port)
 module_path="$(git config --get instaweb.modulepath)"
 
@@ -34,18 +35,28 @@ conf="$GIT_DIR/gitweb/httpd.conf"
 # if installed, it doesn't need further configuration (module_path)
 test -z "$httpd" && httpd='lighttpd -f'
 
+# Default is @@GITWEBDIR@@
+test -z "$root" && root='@@GITWEBDIR@@'
+
 # any untaken local port will do...
 test -z "$port" && port=1234
 
 resolve_full_httpd () {
        case "$httpd" in
-       *apache2*|*lighttpd*)
+       *apache2*|*lighttpd*|*httpd*)
+               # yes, *httpd* covers *lighttpd* above, but it is there for clarity
                # ensure that the apache2/lighttpd command ends with "-f"
                if ! echo "$httpd" | sane_grep -- '-f *$' >/dev/null 2>&1
                then
                        httpd="$httpd -f"
                fi
                ;;
+       *plackup*)
+               # server is started by running via generated gitweb.psgi in $fqgitdir/gitweb
+               full_httpd="$fqgitdir/gitweb/gitweb.psgi"
+               httpd_only="${httpd%% *}" # cut on first space
+               return
+               ;;
        esac
 
        httpd_only="$(echo $httpd | cut -f1 -d' ')"
@@ -57,7 +68,7 @@ resolve_full_httpd () {
                # these days and those are not in most users $PATHs
                # in addition, we may have generated a server script
                # in $fqgitdir/gitweb.
-               for i in /usr/local/sbin /usr/sbin "$fqgitdir/gitweb"
+               for i in /usr/local/sbin /usr/sbin "$root" "$fqgitdir/gitweb"
                do
                        if test -x "$i/$httpd_only"
                        then
@@ -83,8 +94,8 @@ start_httpd () {
 
        # don't quote $full_httpd, there can be arguments to it (-f)
        case "$httpd" in
-       *mongoose*)
-               #The mongoose server doesn't have a daemon mode so we'll have to fork it
+       *mongoose*|*plackup*)
+               #These servers don't have a daemon mode so we'll have to fork it
                $full_httpd "$fqgitdir/gitweb/httpd.conf" &
                #Save the pid before doing anything else (we'll print it later)
                pid=$!
@@ -110,6 +121,20 @@ EOF
 
 stop_httpd () {
        test -f "$fqgitdir/pid" && kill $(cat "$fqgitdir/pid")
+       rm -f "$fqgitdir/pid"
+}
+
+httpd_is_ready () {
+       "$PERL" -MIO::Socket::INET -e "
+local \$| = 1; # turn on autoflush
+exit if (IO::Socket::INET->new('127.0.0.1:$port'));
+print 'Waiting for \'$httpd\' to start ..';
+do {
+       print '.';
+       sleep(1);
+} until (IO::Socket::INET->new('127.0.0.1:$port'));
+print qq! (done)\n!;
+"
 }
 
 while test $# != 0
@@ -159,8 +184,8 @@ done
 mkdir -p "$GIT_DIR/gitweb/tmp"
 GIT_EXEC_PATH="$(git --exec-path)"
 GIT_DIR="$fqgitdir"
-export GIT_EXEC_PATH GIT_DIR
-
+GITWEB_CONFIG="$fqgitdir/gitweb/gitweb_config.perl"
+export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
 
 webrick_conf () {
        # generate a standalone server script in $fqgitdir/gitweb.
@@ -192,7 +217,7 @@ EOF
 
        cat >"$conf" <<EOF
 :Port: $port
-:DocumentRoot: "$fqgitdir/gitweb"
+:DocumentRoot: "$root"
 :DirectoryIndex: ["gitweb.cgi"]
 :PidFile: "$fqgitdir/pid"
 EOF
@@ -201,18 +226,18 @@ EOF
 
 lighttpd_conf () {
        cat > "$conf" <<EOF
-server.document-root = "$fqgitdir/gitweb"
+server.document-root = "$root"
 server.port = $port
 server.modules = ( "mod_setenv", "mod_cgi" )
 server.indexfiles = ( "gitweb.cgi" )
 server.pid-file = "$fqgitdir/pid"
-server.errorlog = "$fqgitdir/gitweb/error.log"
+server.errorlog = "$fqgitdir/gitweb/$httpd_only/error.log"
 
 # to enable, add "mod_access", "mod_accesslog" to server.modules
 # variable above and uncomment this
-#accesslog.filename = "$fqgitdir/gitweb/access.log"
+#accesslog.filename = "$fqgitdir/gitweb/$httpd_only/access.log"
 
-setenv.add-environment = ( "PATH" => env.PATH )
+setenv.add-environment = ( "PATH" => env.PATH, "GITWEB_CONFIG" => env.GITWEB_CONFIG )
 
 cgi.assign = ( ".cgi" => "" )
 
@@ -276,21 +301,30 @@ EOF
 }
 
 apache2_conf () {
-       test -z "$module_path" && module_path=/usr/lib/apache2/modules
-       mkdir -p "$GIT_DIR/gitweb/logs"
+       if test -z "$module_path"
+       then
+               test -d "/usr/lib/httpd/modules" &&
+                       module_path="/usr/lib/httpd/modules"
+               test -d "/usr/lib/apache2/modules" &&
+                       module_path="/usr/lib/apache2/modules"
+       fi
        bind=
        test x"$local" = xtrue && bind='127.0.0.1:'
        echo 'text/css css' > "$fqgitdir/mime.types"
        cat > "$conf" <<EOF
 ServerName "git-instaweb"
-ServerRoot "$fqgitdir/gitweb"
-DocumentRoot "$fqgitdir/gitweb"
+ServerRoot "$root"
+DocumentRoot "$root"
+ErrorLog "$fqgitdir/gitweb/$httpd_only/error.log"
+CustomLog "$fqgitdir/gitweb/$httpd_only/access.log" combined
 PidFile "$fqgitdir/pid"
 Listen $bind$port
 EOF
 
-       for mod in mime dir; do
-               if test -e $module_path/mod_${mod}.so; then
+       for mod in mime dir env log_config
+       do
+               if test -e $module_path/mod_${mod}.so
+               then
                        echo "LoadModule ${mod}_module " \
                             "$module_path/mod_${mod}.so" >> "$conf"
                fi
@@ -303,13 +337,14 @@ EOF
        # check to see if Dennis Stosberg's mod_perl compatibility patch
        # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
        if test -f "$module_path/mod_perl.so" &&
-          sane_grep 'MOD_PERL' "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null
+          sane_grep 'MOD_PERL' "$root/gitweb.cgi" >/dev/null
        then
                # favor mod_perl if available
                cat >> "$conf" <<EOF
 LoadModule perl_module $module_path/mod_perl.so
 PerlPassEnv GIT_DIR
-PerlPassEnv GIT_EXEC_DIR
+PerlPassEnv GIT_EXEC_PATH
+PerlPassEnv GITWEB_CONFIG
 <Location /gitweb.cgi>
        SetHandler perl-script
        PerlResponseHandler ModPerl::Registry
@@ -338,6 +373,9 @@ EOF
                        echo "ScriptSock logs/gitweb.sock" >> "$conf"
                fi
                cat >> "$conf" <<EOF
+PassEnv GIT_DIR
+PassEnv GIT_EXEC_PATH
+PassEnv GITWEB_CONFIG
 AddHandler cgi-script .cgi
 <Location /gitweb.cgi>
        Options +ExecCGI
@@ -353,15 +391,15 @@ mongoose_conf() {
 # For detailed description of every option, visit
 # http://code.google.com/p/mongoose/wiki/MongooseManual
 
-root           $fqgitdir/gitweb
+root           $root
 ports          $port
 index_files    gitweb.cgi
 #ssl_cert      $fqgitdir/gitweb/ssl_cert.pem
-error_log      $fqgitdir/gitweb/error.log
-access_log     $fqgitdir/gitweb/access.log
+error_log      $fqgitdir/gitweb/$httpd_only/error.log
+access_log     $fqgitdir/gitweb/$httpd_only/access.log
 
 #cgi setup
-cgi_env                PATH=$PATH,GIT_DIR=$GIT_DIR,GIT_EXEC_PATH=$GIT_EXEC_PATH
+cgi_env                PATH=$PATH,GIT_DIR=$GIT_DIR,GIT_EXEC_PATH=$GIT_EXEC_PATH,GITWEB_CONFIG=$GITWEB_CONFIG
 cgi_interp     $PERL
 cgi_ext                cgi,pl
 
@@ -370,47 +408,171 @@ mime_types       .gz=application/x-gzip,.tar.gz=application/x-tgz,.tgz=application/x-t
 EOF
 }
 
-
-script='
-s#^(my|our) \$projectroot =.*#$1 \$projectroot = "'$(dirname "$fqgitdir")'";#;
-s#(my|our) \$gitbin =.*#$1 \$gitbin = "'$GIT_EXEC_PATH'";#;
-s#(my|our) \$projects_list =.*#$1 \$projects_list = \$projectroot;#;
-s#(my|our) \$git_temp =.*#$1 \$git_temp = "'$fqgitdir/gitweb/tmp'";#;'
-
-gitweb_cgi () {
-       cat > "$1.tmp" <<\EOFGITWEB
-@@GITWEB_CGI@@
-EOFGITWEB
-       # Use the configured full path to perl to match the generated
-       # scripts' 'hashpling' line
-       "$PERL" -p -e "$script" "$1.tmp"  > "$1"
-       chmod +x "$1"
-       rm -f "$1.tmp"
+plackup_conf () {
+       # generate a standalone 'plackup' server script in $fqgitdir/gitweb
+       # with embedded configuration; it does not use "$conf" file
+       cat > "$fqgitdir/gitweb/gitweb.psgi" <<EOF
+#!$PERL
+
+# gitweb - simple web interface to track changes in git repositories
+#          PSGI wrapper and server starter (see http://plackperl.org)
+
+use strict;
+
+use IO::Handle;
+use Plack::MIME;
+use Plack::Builder;
+use Plack::App::WrapCGI;
+use CGI::Emulate::PSGI 0.07; # minimum version required to work with gitweb
+
+# mimetype mapping (from lighttpd_conf)
+Plack::MIME->add_type(
+       ".pdf"          =>      "application/pdf",
+       ".sig"          =>      "application/pgp-signature",
+       ".spl"          =>      "application/futuresplash",
+       ".class"        =>      "application/octet-stream",
+       ".ps"           =>      "application/postscript",
+       ".torrent"      =>      "application/x-bittorrent",
+       ".dvi"          =>      "application/x-dvi",
+       ".gz"           =>      "application/x-gzip",
+       ".pac"          =>      "application/x-ns-proxy-autoconfig",
+       ".swf"          =>      "application/x-shockwave-flash",
+       ".tar.gz"       =>      "application/x-tgz",
+       ".tgz"          =>      "application/x-tgz",
+       ".tar"          =>      "application/x-tar",
+       ".zip"          =>      "application/zip",
+       ".mp3"          =>      "audio/mpeg",
+       ".m3u"          =>      "audio/x-mpegurl",
+       ".wma"          =>      "audio/x-ms-wma",
+       ".wax"          =>      "audio/x-ms-wax",
+       ".ogg"          =>      "application/ogg",
+       ".wav"          =>      "audio/x-wav",
+       ".gif"          =>      "image/gif",
+       ".jpg"          =>      "image/jpeg",
+       ".jpeg"         =>      "image/jpeg",
+       ".png"          =>      "image/png",
+       ".xbm"          =>      "image/x-xbitmap",
+       ".xpm"          =>      "image/x-xpixmap",
+       ".xwd"          =>      "image/x-xwindowdump",
+       ".css"          =>      "text/css",
+       ".html"         =>      "text/html",
+       ".htm"          =>      "text/html",
+       ".js"           =>      "text/javascript",
+       ".asc"          =>      "text/plain",
+       ".c"            =>      "text/plain",
+       ".cpp"          =>      "text/plain",
+       ".log"          =>      "text/plain",
+       ".conf"         =>      "text/plain",
+       ".text"         =>      "text/plain",
+       ".txt"          =>      "text/plain",
+       ".dtd"          =>      "text/xml",
+       ".xml"          =>      "text/xml",
+       ".mpeg"         =>      "video/mpeg",
+       ".mpg"          =>      "video/mpeg",
+       ".mov"          =>      "video/quicktime",
+       ".qt"           =>      "video/quicktime",
+       ".avi"          =>      "video/x-msvideo",
+       ".asf"          =>      "video/x-ms-asf",
+       ".asx"          =>      "video/x-ms-asf",
+       ".wmv"          =>      "video/x-ms-wmv",
+       ".bz2"          =>      "application/x-bzip",
+       ".tbz"          =>      "application/x-bzip-compressed-tar",
+       ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
+       ""              =>      "text/plain"
+);
+
+my \$app = builder {
+       # to be able to override \$SIG{__WARN__} to log build time warnings
+       use CGI::Carp; # it sets \$SIG{__WARN__} itself
+
+       my \$logdir = "$fqgitdir/gitweb/$httpd_only";
+       open my \$access_log_fh, '>>', "\$logdir/access.log"
+               or die "Couldn't open access log '\$logdir/access.log': \$!";
+       open my \$error_log_fh,  '>>', "\$logdir/error.log"
+               or die "Couldn't open error log '\$logdir/error.log': \$!";
+
+       \$access_log_fh->autoflush(1);
+       \$error_log_fh->autoflush(1);
+
+       # redirect build time warnings to error.log
+       \$SIG{'__WARN__'} = sub {
+               my \$msg = shift;
+               # timestamp warning like in CGI::Carp::warn
+               my \$stamp = CGI::Carp::stamp();
+               \$msg =~ s/^/\$stamp/gm;
+               print \$error_log_fh \$msg;
+       };
+
+       # write errors to error.log, access to access.log
+       enable 'AccessLog',
+               format => "combined",
+               logger => sub { print \$access_log_fh @_; };
+       enable sub {
+               my \$app = shift;
+               sub {
+                       my \$env = shift;
+                       \$env->{'psgi.errors'} = \$error_log_fh;
+                       \$app->(\$env);
+               }
+       };
+       # gitweb currently doesn't work with $SIG{CHLD} set to 'IGNORE',
+       # because it uses 'close $fd or die...' on piped filehandle $fh
+       # (which causes the parent process to wait for child to finish).
+       enable_if { \$SIG{'CHLD'} eq 'IGNORE' } sub {
+               my \$app = shift;
+               sub {
+                       my \$env = shift;
+                       local \$SIG{'CHLD'} = 'DEFAULT';
+                       local \$SIG{'CLD'}  = 'DEFAULT';
+                       \$app->(\$env);
+               }
+       };
+       # serve static files, i.e. stylesheet, images, script
+       enable 'Static',
+               path => sub { m!\.(js|css|png)\$! && s!^/gitweb/!! },
+               root => "$root/",
+               encoding => 'utf-8'; # encoding for 'text/plain' files
+       # convert CGI application to PSGI app
+       Plack::App::WrapCGI->new(script => "$root/gitweb.cgi")->to_app;
+};
+
+# make it runnable as standalone app,
+# like it would be run via 'plackup' utility
+if (__FILE__ eq \$0) {
+       require Plack::Runner;
+
+       my \$runner = Plack::Runner->new();
+       \$runner->parse_options(qw(--env deployment --port $port),
+                              "$local" ? qw(--host 127.0.0.1) : ());
+       \$runner->run(\$app);
 }
+__END__
+EOF
 
-gitweb_css () {
-       cat > "$1" <<\EOFGITWEB
-@@GITWEB_CSS@@
-
-EOFGITWEB
+       chmod a+x "$fqgitdir/gitweb/gitweb.psgi"
+       # configuration is embedded in server script file, gitweb.psgi
+       rm -f "$conf"
 }
 
-gitweb_js () {
-       cat > "$1" <<\EOFGITWEB
-@@GITWEB_JS@@
-
-EOFGITWEB
+gitweb_conf() {
+       cat > "$fqgitdir/gitweb/gitweb_config.perl" <<EOF
+#!/usr/bin/perl
+our \$projectroot = "$(dirname "$fqgitdir")";
+our \$git_temp = "$fqgitdir/gitweb/tmp";
+our \$projects_list = \$projectroot;
+EOF
 }
 
-gitweb_cgi "$GIT_DIR/gitweb/gitweb.cgi"
-gitweb_css "$GIT_DIR/@@GITWEB_CSS_NAME@@"
-gitweb_js  "$GIT_DIR/@@GITWEB_JS_NAME@@"
+gitweb_conf
+
+resolve_full_httpd
+mkdir -p "$fqgitdir/gitweb/$httpd_only"
 
 case "$httpd" in
 *lighttpd*)
        lighttpd_conf
        ;;
-*apache2*)
+*apache2*|*httpd*)
        apache2_conf
        ;;
 webrick)
@@ -419,6 +581,9 @@ webrick)
 *mongoose*)
        mongoose_conf
        ;;
+*plackup*)
+       plackup_conf
+       ;;
 *)
        echo "Unknown httpd specified: $httpd"
        exit 1
@@ -429,7 +594,7 @@ start_httpd
 url=http://127.0.0.1:$port
 
 if test -n "$browser"; then
-       git web--browse -b "$browser" $url || echo $url
+       httpd_is_ready && git web--browse -b "$browser" $url || echo $url
 else
-       git web--browse -c "instaweb.browser" $url || echo $url
+       httpd_is_ready && git web--browse -c "instaweb.browser" $url || echo $url
 fi
index d067894bf45fd0a50513e196ea2a5e671d901681..b86402afa5d079df8d1cf6eebb15e5727cc8a5de 100755 (executable)
@@ -107,7 +107,7 @@ case "${1:-.}${2:-.}${3:-.}" in
                # remove lines that are unique to ours.
                orig=`git-unpack-file $2`
                sz0=`wc -c <"$orig"`
-               diff -u -La/$orig -Lb/$orig $orig $src2 | git apply --no-add
+               @@DIFF@@ -u -La/$orig -Lb/$orig $orig $src2 | git apply --no-add
                sz1=`wc -c <"$orig"`
 
                # If we do not have enough common material, it is not
index a09a44ec4ce3d82cebc5f972f09e94c7c35dc948..8eb74d45debe7ab2bd2cc9b5ed57b1ba49d94bdb 100755 (executable)
@@ -273,6 +273,15 @@ then
        exit
 fi
 
+if test true = "$rebase"
+then
+       o=$(git show-branch --merge-base $curr_branch $merge_head $oldremoteref)
+       if test "$oldremoteref" = "$o"
+       then
+               unset oldremoteref
+       fi
+fi
+
 merge_name=$(git fmt-merge-msg $log_arg <"$GIT_DIR/FETCH_HEAD") || exit
 case "$rebase" in
 true)
index 6b86abc64bfe0034caf23cf9530955128766de32..b94c2a03867ddcd1fa0c2051f81cf14547b550f0 100755 (executable)
@@ -119,7 +119,7 @@ run 'git rebase --continue'"
 export GIT_CHERRY_PICK_HELP
 
 warn () {
-       echo "$*" >&2
+       printf '%s\n' "$*" >&2
 }
 
 output () {
@@ -263,10 +263,10 @@ pick_one_preserving_merges () {
        then
                if test "$fast_forward" = t
                then
-                       cat "$DOTEST"/current-commit | while read current_commit
+                       while read current_commit
                        do
                                git rev-parse HEAD > "$REWRITTEN"/$current_commit
-                       done
+                       done <"$DOTEST"/current-commit
                        rm "$DOTEST"/current-commit ||
                        die "Cannot write current commit's replacement sha1"
                fi
@@ -440,9 +440,9 @@ record_in_rewritten() {
        echo "$oldsha1" >> "$REWRITTEN_PENDING"
 
        case "$(peek_next_command)" in
-           squash|s|fixup|f)
+       squash|s|fixup|f)
                ;;
-           *)
+       *)
                flush_rewritten_pending
                ;;
        esac
@@ -450,7 +450,7 @@ record_in_rewritten() {
 
 do_next () {
        rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit
-       read command sha1 rest < "$TODO"
+       read -r command sha1 rest < "$TODO"
        case "$command" in
        '#'*|''|noop)
                mark_action_done
@@ -591,7 +591,7 @@ do_rest () {
 # skip picking commits whose parents are unchanged
 skip_unnecessary_picks () {
        fd=3
-       while read command sha1 rest
+       while read -r command sha1 rest
        do
                # fd=3 means we skip the command
                case "$fd,$command,$(git rev-parse --verify --quiet $sha1^)" in
@@ -606,7 +606,7 @@ skip_unnecessary_picks () {
                        fd=1
                        ;;
                esac
-               echo "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd
+               printf '%s\n' "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd
        done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
        mv -f "$TODO".new "$TODO" &&
        case "$(peek_next_command)" in
@@ -644,17 +644,17 @@ rearrange_squash () {
        test -s "$1.sq" || return
 
        used=
-       while read pick sha1 message
+       while read -r pick sha1 message
        do
                case " $used" in
                *" $sha1 "*) continue ;;
                esac
-               echo "$pick $sha1 $message"
-               while read squash action msg
+               printf '%s\n' "$pick $sha1 $message"
+               while read -r squash action msg
                do
                        case "$message" in
                        "$msg"*)
-                               echo "$action $squash $action! $msg"
+                               printf '%s\n' "$action $squash $action! $msg"
                                used="$used$squash "
                                ;;
                        esac
@@ -890,11 +890,12 @@ first and then run 'git rebase --continue' again."
                git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
                        --abbrev=7 --reverse --left-right --topo-order \
                        $REVISIONS | \
-                       sed -n "s/^>//p" | while read shortsha1 rest
+                       sed -n "s/^>//p" |
+               while read -r shortsha1 rest
                do
                        if test t != "$PRESERVE_MERGES"
                        then
-                               echo "pick $shortsha1 $rest" >> "$TODO"
+                               printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
                        else
                                sha1=$(git rev-parse $shortsha1)
                                if test -z "$REBASE_ROOT"
@@ -913,7 +914,7 @@ first and then run 'git rebase --continue' again."
                                if test f = "$preserve"
                                then
                                        touch "$REWRITTEN"/$sha1
-                                       echo "pick $shortsha1 $rest" >> "$TODO"
+                                       printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
                                fi
                        fi
                done
index 44f5c65fdb5e81c4b660a666c2edd71aa75c5c1a..1b9ea48cd713d7f6b25e529d09743447635f6432 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright (c) 2005 Junio C Hamano.
 #
 
-USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]'
+USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] (<upstream>|--root) [<branch>] [--quiet | -q]'
 LONG_USAGE='git-rebase replaces <branch> with a new branch of the
 same name.  When the --onto option is provided the new branch starts
 out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
@@ -198,14 +198,6 @@ test -f "$GIT_DIR"/rebase-apply/applying &&
 
 is_interactive "$@" && exec git-rebase--interactive "$@"
 
-if test $# -eq 0
-then
-       test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || usage
-       test -d "$dotest" -o -f "$GIT_DIR"/rebase-apply/rebasing &&
-               die 'A rebase is in progress, try --continue, --skip or --abort.'
-       die "No arguments given and $GIT_DIR/rebase-apply already exists."
-fi
-
 while test $# != 0
 do
        case "$1" in
@@ -216,6 +208,7 @@ do
                test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
                        die "No rebase in progress?"
 
+               git update-index --ignore-submodules --refresh &&
                git diff-files --quiet --ignore-submodules || {
                        echo "You must edit all merge conflicts and then"
                        echo "mark them as resolved using git add"
@@ -353,7 +346,7 @@ do
        --root)
                rebase_root=t
                ;;
-       -f|--f|--fo|--for|--forc|force|--force-r|--force-re|--force-reb|--force-reba|--force-rebas|--force-rebase|--no-ff)
+       -f|--f|--fo|--for|--forc|--force|--force-r|--force-re|--force-reb|--force-reba|--force-rebas|--force-rebase|--no-ff)
                force_rebase=t
                ;;
        --rerere-autoupdate|--no-rerere-autoupdate)
@@ -370,6 +363,13 @@ do
 done
 test $# -gt 2 && usage
 
+if test $# -eq 0 && test -z "$rebase_root"
+then
+       test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || usage
+       test -d "$dotest" -o -f "$GIT_DIR"/rebase-apply/rebasing &&
+               die 'A rebase is in progress, try --continue, --skip or --abort.'
+fi
+
 # Make sure we do not have $GIT_DIR/rebase-apply
 if test -z "$do_merge"
 then
@@ -544,7 +544,7 @@ fi
 if test -z "$do_merge"
 then
        git format-patch -k --stdout --full-index --ignore-if-in-upstream \
-               $root_flag "$revisions" |
+               --no-renames $root_flag "$revisions" |
        git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
        move_to_original_branch
        ret=$?
diff --git a/git-remote-testgit.py b/git-remote-testgit.py
new file mode 100644 (file)
index 0000000..df9d512
--- /dev/null
@@ -0,0 +1,244 @@
+#!/usr/bin/env python
+
+# hashlib is only available in python >= 2.5
+try:
+    import hashlib
+    _digest = hashlib.sha1
+except ImportError:
+    import sha
+    _digest = sha.new
+import sys
+import os
+sys.path.insert(0, os.getenv("GITPYTHONLIB","."))
+
+from git_remote_helpers.util import die, debug, warn
+from git_remote_helpers.git.repo import GitRepo
+from git_remote_helpers.git.exporter import GitExporter
+from git_remote_helpers.git.importer import GitImporter
+from git_remote_helpers.git.non_local import NonLocalGit
+
+def get_repo(alias, url):
+    """Returns a git repository object initialized for usage.
+    """
+
+    repo = GitRepo(url)
+    repo.get_revs()
+    repo.get_head()
+
+    hasher = _digest()
+    hasher.update(repo.path)
+    repo.hash = hasher.hexdigest()
+
+    repo.get_base_path = lambda base: os.path.join(
+        base, 'info', 'fast-import', repo.hash)
+
+    prefix = 'refs/testgit/%s/' % alias
+    debug("prefix: '%s'", prefix)
+
+    repo.gitdir = ""
+    repo.alias = alias
+    repo.prefix = prefix
+
+    repo.exporter = GitExporter(repo)
+    repo.importer = GitImporter(repo)
+    repo.non_local = NonLocalGit(repo)
+
+    return repo
+
+
+def local_repo(repo, path):
+    """Returns a git repository object initalized for usage.
+    """
+
+    local = GitRepo(path)
+
+    local.non_local = None
+    local.gitdir = repo.gitdir
+    local.alias = repo.alias
+    local.prefix = repo.prefix
+    local.hash = repo.hash
+    local.get_base_path = repo.get_base_path
+    local.exporter = GitExporter(local)
+    local.importer = GitImporter(local)
+
+    return local
+
+
+def do_capabilities(repo, args):
+    """Prints the supported capabilities.
+    """
+
+    print "import"
+    print "export"
+    print "gitdir"
+    print "refspec refs/heads/*:%s*" % repo.prefix
+
+    print # end capabilities
+
+
+def do_list(repo, args):
+    """Lists all known references.
+
+    Bug: This will always set the remote head to master for non-local
+    repositories, since we have no way of determining what the remote
+    head is at clone time.
+    """
+
+    for ref in repo.revs:
+        debug("? refs/heads/%s", ref)
+        print "? refs/heads/%s" % ref
+
+    if repo.head:
+        debug("@refs/heads/%s HEAD" % repo.head)
+        print "@refs/heads/%s HEAD" % repo.head
+    else:
+        debug("@refs/heads/master HEAD")
+        print "@refs/heads/master HEAD"
+
+    print # end list
+
+
+def update_local_repo(repo):
+    """Updates (or clones) a local repo.
+    """
+
+    if repo.local:
+        return repo
+
+    path = repo.non_local.clone(repo.gitdir)
+    repo.non_local.update(repo.gitdir)
+    repo = local_repo(repo, path)
+    return repo
+
+
+def do_import(repo, args):
+    """Exports a fast-import stream from testgit for git to import.
+    """
+
+    if len(args) != 1:
+        die("Import needs exactly one ref")
+
+    if not repo.gitdir:
+        die("Need gitdir to import")
+
+    repo = update_local_repo(repo)
+    repo.exporter.export_repo(repo.gitdir)
+
+
+def do_export(repo, args):
+    """Imports a fast-import stream from git to testgit.
+    """
+
+    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.
+    """
+
+    if not args:
+        die("gitdir needs an argument")
+
+    repo.gitdir = ' '.join(args)
+
+
+COMMANDS = {
+    'capabilities': do_capabilities,
+    'list': do_list,
+    'import': do_import,
+    'export': do_export,
+    'gitdir': do_gitdir,
+}
+
+
+def sanitize(value):
+    """Cleans up the url.
+    """
+
+    if value.startswith('testgit::'):
+        value = value[9:]
+
+    return value
+
+
+def read_one_line(repo):
+    """Reads and processes one command.
+    """
+
+    line = sys.stdin.readline()
+
+    cmdline = line
+
+    if not cmdline:
+        warn("Unexpected EOF")
+        return False
+
+    cmdline = cmdline.strip().split()
+    if not cmdline:
+        # Blank line means we're about to quit
+        return False
+
+    cmd = cmdline.pop(0)
+    debug("Got command '%s' with args '%s'", cmd, ' '.join(cmdline))
+
+    if cmd not in COMMANDS:
+        die("Unknown command, %s", cmd)
+
+    func = COMMANDS[cmd]
+    func(repo, cmdline)
+    sys.stdout.flush()
+
+    return True
+
+
+def main(args):
+    """Starts a new remote helper for the specified repository.
+    """
+
+    if len(args) != 3:
+        die("Expecting exactly three arguments.")
+        sys.exit(1)
+
+    if os.getenv("GIT_DEBUG_TESTGIT"):
+        import git_remote_helpers.util
+        git_remote_helpers.util.DEBUG = True
+
+    alias = sanitize(args[1])
+    url = sanitize(args[2])
+
+    if not alias.isalnum():
+        warn("non-alnum alias '%s'", alias)
+        alias = "tmp"
+
+    args[1] = alias
+    args[2] = url
+
+    repo = get_repo(alias, url)
+
+    debug("Got arguments %s", args[1:])
+
+    more = True
+
+    while (more):
+        more = read_one_line(repo)
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
index 8fd15f6df4926a89812437e04735bd924ee7088b..6fdea397ddec3cfa4ff37cdf672e7cced840bb60 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh -e
+#!/bin/sh
 # Copyright 2005, Ryan Anderson <ryan@michonline.com>
 #
 # This file is licensed under the GPL v2, or a later version
@@ -8,6 +8,7 @@ USAGE='<start> <url> [<end>]'
 LONG_USAGE='Summarizes the changes between two commits to the standard output,
 and includes the given URL in the generated summary.'
 SUBDIRECTORY_OK='Yes'
+OPTIONS_KEEPDASHDASH=
 OPTIONS_SPEC='git request-pull [options] start url [end]
 --
 p    show patch text as well
@@ -69,10 +70,10 @@ git show -s --format='The following changes since commit %H:
 
   %s (%ci)
 
-are available in the git repository at:' $baserev
-echo "  $url $branch"
-echo
+are available in the git repository at:' $baserev &&
+echo "  $url $branch" &&
+echo &&
 
-git shortlog ^$baserev $headrev
-git diff -M --stat --summary $patch $merge_base..$headrev
+git shortlog ^$baserev $headrev &&
+git diff -M --stat --summary $patch $merge_base..$headrev || exit
 exit $status
index 0f858d334c756f9cd4028b4950a3912d0f6182dd..1d95447d03f342811dd77386f2e83d0814beabf2 100755 (executable)
@@ -57,7 +57,7 @@ create_stash () {
        # state of the base commit
        if b_commit=$(git rev-parse --verify HEAD)
        then
-               head=$(git log --no-color --abbrev-commit --pretty=oneline -n 1 HEAD --)
+               head=$(git rev-list --oneline -n 1 HEAD --)
        else
                die "You do not have the initial commit yet"
        fi
index 3319b836b217a26b4ac55ae5ced328ffafa0a015..9ebbab798d21147fc019b6183cad0c462c9dafca 100755 (executable)
@@ -5,7 +5,7 @@
 # Copyright (c) 2007 Lars Hjemli
 
 dashless=$(basename "$0" | sed -e 's/-/ /')
-USAGE="[--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]
+USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] init [--] [<path>...]
    or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
@@ -19,6 +19,7 @@ require_work_tree
 
 command=
 branch=
+force=
 reference=
 cached=
 recursive=
@@ -133,6 +134,9 @@ cmd_add()
                        branch=$2
                        shift
                        ;;
+               -f | --force)
+                       force=$1
+                       ;;
                -q|--quiet)
                        GIT_QUIET=1
                        ;;
@@ -201,6 +205,14 @@ cmd_add()
        git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
        die "'$path' already exists in the index"
 
+       if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
+       then
+               echo >&2 "The following path is ignored by one of your .gitignore files:" &&
+               echo >&2 $path &&
+               echo >&2 "Use -f if you really want to add it."
+               exit 1
+       fi
+
        # perhaps the path exists and is already a git repo, else clone it
        if test -e "$path"
        then
@@ -234,12 +246,12 @@ cmd_add()
                ) || die "Unable to checkout submodule '$path'"
        fi
 
-       git add "$path" ||
+       git add $force "$path" ||
        die "Failed to add submodule '$path'"
 
        git config -f .gitmodules submodule."$path".path "$path" &&
        git config -f .gitmodules submodule."$path".url "$repo" &&
-       git add .gitmodules ||
+       git add --force .gitmodules ||
        die "Failed to register submodule '$path'"
 }
 
@@ -271,6 +283,8 @@ cmd_foreach()
                shift
        done
 
+       toplevel=$(pwd)
+
        module_list |
        while read mode sha1 stage path
        do
@@ -578,7 +592,7 @@ cmd_summary() {
 
        cd_to_toplevel
        # Get modified modules cared by user
-       modules=$(git $diff_cmd $cached --raw $head -- "$@" |
+       modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" |
                sane_egrep '^:([0-7]* )?160000' |
                while read mod_src mod_dst sha1_src sha1_dst status name
                do
@@ -592,7 +606,7 @@ cmd_summary() {
 
        test -z "$modules" && return
 
-       git $diff_cmd $cached --raw $head -- $modules |
+       git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules |
        sane_egrep '^:([0-7]* )?160000' |
        cut -c2- |
        while read mod_src mod_dst sha1_src sha1_dst status name
@@ -650,7 +664,7 @@ cmd_summary() {
                                range=$sha1_dst
                        fi
                        GIT_DIR="$name/.git" \
-                       git log --pretty=oneline --first-parent $range | wc -l
+                       git rev-list --first-parent $range -- | wc -l
                        )
                        total_commits=" ($(($total_commits + 0)))"
                        ;;
@@ -758,7 +772,7 @@ cmd_status()
                        continue;
                fi
                set_name_rev "$path" "$sha1"
-               if git diff-files --quiet -- "$path"
+               if git diff-files --ignore-submodules=dirty --quiet -- "$path"
                then
                        say " $sha1 $displaypath$revname"
                else
@@ -825,10 +839,11 @@ cmd_sync()
                if test -e "$path"/.git
                then
                (
+                       say "Synchronizing submodule url for '$name'"
+                       git config submodule."$name".url "$url"
                        clear_local_git_env
                        cd "$path"
                        remote=$(get_default_remote)
-                       say "Synchronizing submodule url for '$name'"
                        git config remote."$remote".url "$url"
                )
                fi
index 2c86ea2e384e4b3ecf9f6c2a856c52a0203ce489..c4163584a93ba594141aa8af99948fc8929605d7 100755 (executable)
@@ -963,6 +963,7 @@ sub cmd_multi_init {
        }
        do_git_init_db();
        if (defined $_trunk) {
+               $_trunk =~ s#^/+##;
                my $trunk_ref = 'refs/remotes/' . $_prefix . 'trunk';
                # try both old-style and new-style lookups:
                my $gs_trunk = eval { Git::SVN->new($trunk_ref) };
@@ -1185,6 +1186,7 @@ sub cmd_reset {
                    "history\n";
        }
        my ($r, $c) = $gs->find_rev_before($target, not $_fetch_parent);
+       die "Cannot find SVN revision $target\n" unless defined($c);
        $gs->rev_map_set($r, $c, 'reset', $uuid);
        print "r$r = $c ($gs->{ref_id})\n";
 }
@@ -2053,6 +2055,9 @@ sub new {
                         "\":$ref_id\$\" in config\n";
                ($self->{path}, undef) = split(/\s*:\s*/, $fetch);
        }
+       $self->{path} =~ s{/+}{/}g;
+       $self->{path} =~ s{\A/}{};
+       $self->{path} =~ s{/\z}{};
        $self->{url} = command_oneline('config', '--get',
                                       "svn-remote.$repo_id.url") or
                   die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
@@ -2086,6 +2091,14 @@ sub refname {
        # .. becomes %2E%2E
        $refname =~ s{\.\.}{%2E%2E}g;
 
+       # trailing dots and .lock are not allowed
+       # .$ becomes %2E and .lock becomes %2Elock
+       $refname =~ s{\.(?=$|lock$)}{%2E};
+
+       # the sequence @{ is used to access the reflog
+       # @{ becomes %40{
+       $refname =~ s{\@\{}{%40\{}g;
+
        return $refname;
 }
 
@@ -2827,8 +2840,9 @@ sub mkemptydirs {
        foreach my $d (sort keys %empty_dirs) {
                $d = uri_decode($d);
                $d =~ s/$strip//;
+               next unless length($d);
                next if -d $d;
-               if (-e _) {
+               if (-e $d) {
                        warn "$d exists but is not a directory\n";
                } else {
                        print "creating empty directory: $d\n";
@@ -3155,6 +3169,22 @@ sub has_no_changes {
                        LIST_CACHE => 'FAULT',
                ;
        }
+
+       sub unmemoize_svn_mergeinfo_functions {
+               return if not $memoized;
+               $memoized = 0;
+
+               Memoize::unmemoize 'lookup_svn_merge';
+               Memoize::unmemoize 'check_cherry_pick';
+               Memoize::unmemoize 'has_no_changes';
+       }
+}
+
+END {
+       # Force cache writeout explicitly instead of waiting for
+       # global destruction to avoid segfault in Storable:
+       # http://rt.cpan.org/Public/Bug/Display.html?id=36087
+       unmemoize_svn_mergeinfo_functions();
 }
 
 sub parents_exclude {
@@ -3605,6 +3635,7 @@ sub mkfile {
 
 sub rev_map_set {
        my ($self, $rev, $commit, $update_ref, $uuid) = @_;
+       defined $commit or die "missing arg3\n";
        length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
        my $db = $self->map_path($uuid);
        my $db_lock = "$db.lock";
@@ -3998,7 +4029,6 @@ use vars qw/@ISA/;
 use strict;
 use warnings;
 use Carp qw/croak/;
-use File::Temp qw/tempfile/;
 use IO::File qw//;
 use vars qw/$_ignore_regex/;
 
index a578c3a73203fbf1bf4abfb024b1e83c45f2b2ce..3fc4166b25714911b6b1294c7439da1e237e4918 100755 (executable)
@@ -31,7 +31,7 @@ valid_custom_tool()
 
 valid_tool() {
        case "$1" in
-               firefox | iceweasel | konqueror | w3m | links | lynx | dillo | open | start)
+               firefox | iceweasel | chrome | google-chrome | chromium | konqueror | w3m | links | lynx | dillo | open | start)
                        ;; # happy
                *)
                        valid_custom_tool "$1" || return 1
@@ -103,7 +103,7 @@ fi
 
 if test -z "$browser" ; then
     if test -n "$DISPLAY"; then
-       browser_candidates="firefox iceweasel konqueror w3m links lynx dillo"
+       browser_candidates="firefox iceweasel google-chrome chrome chromium konqueror w3m links lynx dillo"
        if test "$KDE_FULL_SESSION" = "true"; then
            browser_candidates="konqueror $browser_candidates"
        fi
@@ -146,6 +146,11 @@ case "$browser" in
        test "$vers" -lt 2 && NEWTAB=''
        "$browser_path" $NEWTAB "$@" &
        ;;
+    google-chrome|chrome|chromium)
+       # Actual command for chromium is chromium-browser.
+       # No need to specify newTab. It's default in chromium
+       eval "$browser_path" "$@" &
+       ;;
     konqueror)
        case "$(basename "$browser_path")" in
            konqueror)
diff --git a/git.c b/git.c
index 6bae30545b85f19eb51c4b055f303f70909f0cf2..b83c1d17ab803ae0fa1d6c0dece43f2c0334f23d 100644 (file)
--- a/git.c
+++ b/git.c
@@ -8,7 +8,8 @@ const char git_usage_string[] =
        "git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n"
        "           [-p|--paginate|--no-pager] [--no-replace-objects]\n"
        "           [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\n"
-       "           [--help] COMMAND [ARGS]";
+       "           [-c name=value] [--help]\n"
+       "           COMMAND [ARGS]";
 
 const char git_more_info_string[] =
        "See 'git help COMMAND' for more information on a specific command.";
@@ -130,6 +131,14 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                        setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0);
                        if (envchanged)
                                *envchanged = 1;
+               } else if (!strcmp(cmd, "-c")) {
+                       if (*argc < 2) {
+                               fprintf(stderr, "-c expects a configuration string\n" );
+                               usage(git_usage_string);
+                       }
+                       git_config_parse_parameter((*argv)[1]);
+                       (*argv)++;
+                       (*argc)--;
                } else {
                        fprintf(stderr, "Unknown option: %s\n", cmd);
                        usage(git_usage_string);
@@ -158,6 +167,7 @@ static int handle_alias(int *argcp, const char ***argv)
        alias_string = alias_lookup(alias_command);
        if (alias_string) {
                if (alias_string[0] == '!') {
+                       commit_pager_choice();
                        if (*argcp > 1) {
                                struct strbuf buf;
 
@@ -320,13 +330,13 @@ static void handle_internal_command(int argc, const char **argv)
                { "fsck-objects", cmd_fsck, RUN_SETUP },
                { "gc", cmd_gc, RUN_SETUP },
                { "get-tar-commit-id", cmd_get_tar_commit_id },
-               { "grep", cmd_grep, USE_PAGER },
+               { "grep", cmd_grep },
                { "hash-object", cmd_hash_object },
                { "help", cmd_help },
                { "index-pack", cmd_index_pack },
                { "init", cmd_init_db },
                { "init-db", cmd_init_db },
-               { "log", cmd_log, RUN_SETUP | USE_PAGER },
+               { "log", cmd_log, RUN_SETUP },
                { "ls-files", cmd_ls_files, RUN_SETUP },
                { "ls-tree", cmd_ls_tree, RUN_SETUP },
                { "ls-remote", cmd_ls_remote },
@@ -370,7 +380,7 @@ static void handle_internal_command(int argc, const char **argv)
                { "send-pack", cmd_send_pack, RUN_SETUP },
                { "shortlog", cmd_shortlog, USE_PAGER },
                { "show-branch", cmd_show_branch, RUN_SETUP },
-               { "show", cmd_show, RUN_SETUP | USE_PAGER },
+               { "show", cmd_show, RUN_SETUP },
                { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
                { "stripspace", cmd_stripspace },
                { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
@@ -385,7 +395,7 @@ static void handle_internal_command(int argc, const char **argv)
                { "var", cmd_var },
                { "verify-tag", cmd_verify_tag, RUN_SETUP },
                { "version", cmd_version },
-               { "whatchanged", cmd_whatchanged, RUN_SETUP | USE_PAGER },
+               { "whatchanged", cmd_whatchanged, RUN_SETUP },
                { "write-tree", cmd_write_tree, RUN_SETUP },
                { "verify-pack", cmd_verify_pack },
                { "show-ref", cmd_show_ref, RUN_SETUP },
@@ -423,6 +433,8 @@ static void execv_dashed_external(const char **argv)
        const char *tmp;
        int status;
 
+       commit_pager_choice();
+
        strbuf_addf(&cmd, "git-%s", argv[0]);
 
        /*
@@ -502,12 +514,12 @@ int main(int argc, const char **argv)
        argv++;
        argc--;
        handle_options(&argv, &argc, NULL);
-       commit_pager_choice();
        if (argc > 0) {
                if (!prefixcmp(argv[0], "--"))
                        argv[0] += 2;
        } else {
                /* The user didn't specify a command; give them help */
+               commit_pager_choice();
                printf("usage: %s\n\n", git_usage_string);
                list_common_cmds_help();
                printf("\n%s\n", git_more_info_string);
index 9533147ff2e06282dc8d60aeb371afa715e22cc1..91c8462b7dae171247c40db7f7b5b36d2c0633a1 100644 (file)
@@ -35,6 +35,7 @@ Requires:     git-cvs = %{version}-%{release}
 Requires:      git-arch = %{version}-%{release}
 Requires:      git-email = %{version}-%{release}
 Requires:      gitk = %{version}-%{release}
+Requires:      gitweb = %{version}-%{release}
 Requires:      git-gui = %{version}-%{release}
 Obsoletes:     git <= 1.5.4.2
 
@@ -87,6 +88,13 @@ Requires:       git = %{version}-%{release}, tk >= 8.4
 %description -n gitk
 Git revision tree visualiser ('gitk')
 
+%package -n gitweb
+Summary:       Git web interface
+Group:          Development/Tools
+Requires:       git = %{version}-%{release}
+%description -n gitweb
+Browsing git repository on the web
+
 %package -n perl-Git
 Summary:        Perl interface to Git
 Group:          Development/Libraries
@@ -189,6 +197,10 @@ rm -rf $RPM_BUILD_ROOT
 %{!?_without_docs: %{_mandir}/man1/*gitk*.1*}
 %{!?_without_docs: %doc Documentation/*gitk*.html }
 
+%files -n gitweb
+%defattr(-,root,root)
+%{_datadir}/gitweb
+
 %files -n perl-Git -f perl-files
 %defattr(-,root,root)
 
@@ -196,6 +208,9 @@ rm -rf $RPM_BUILD_ROOT
 # No files for you!
 
 %changelog
+* Wed Jun 30 2010 Junio C Hamano <gitster@pobox.com>
+- Add 'gitweb' subpackage.
+
 * Fri Mar 26 2010 Ian Ward Comfort <icomfort@stanford.edu>
 - Ship bash completion support from contrib/ in the core package.
 
diff --git a/git_remote_helpers/git/exporter.py b/git_remote_helpers/git/exporter.py
new file mode 100644 (file)
index 0000000..f40f9d6
--- /dev/null
@@ -0,0 +1,53 @@
+import os
+import subprocess
+import sys
+
+
+class GitExporter(object):
+    """An exporter for testgit repositories.
+
+    The exporter simply delegates to git fast-export.
+    """
+
+    def __init__(self, repo):
+        """Creates a new exporter for the specified repo.
+        """
+
+        self.repo = repo
+
+    def export_repo(self, base):
+        """Exports a fast-export stream for the given directory.
+
+        Simply delegates to git fast-epxort and pipes it through sed
+        to make the refs show up under the prefix rather than the
+        default refs/heads. This is to demonstrate how the export
+        data can be stored under it's own ref (using the refspec
+        capability).
+        """
+
+        dirname = self.repo.get_base_path(base)
+        path = os.path.abspath(os.path.join(dirname, 'testgit.marks'))
+
+        if not os.path.exists(dirname):
+            os.makedirs(dirname)
+
+        print "feature relative-marks"
+        if os.path.exists(os.path.join(dirname, 'git.marks')):
+            print "feature import-marks=%s/git.marks" % self.repo.hash
+        print "feature export-marks=%s/git.marks" % self.repo.hash
+        sys.stdout.flush()
+
+        args = ["git", "--git-dir=" + self.repo.gitpath, "fast-export", "--export-marks=" + path]
+
+        if os.path.exists(path):
+            args.append("--import-marks=" + path)
+
+        args.append("HEAD")
+
+        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
diff --git a/git_remote_helpers/git/importer.py b/git_remote_helpers/git/importer.py
new file mode 100644 (file)
index 0000000..70a7127
--- /dev/null
@@ -0,0 +1,40 @@
+import os
+import subprocess
+
+
+class GitImporter(object):
+    """An importer for testgit repositories.
+
+    This importer simply delegates to git fast-import.
+    """
+
+    def __init__(self, repo):
+        """Creates a new importer for the specified repo.
+        """
+
+        self.repo = repo
+
+    def do_import(self, base):
+        """Imports a fast-import stream to the given directory.
+
+        Simply delegates to git fast-import.
+        """
+
+        dirname = self.repo.get_base_path(base)
+        if self.repo.local:
+            gitdir = self.repo.gitpath
+        else:
+            gitdir = os.path.abspath(os.path.join(dirname, '.git'))
+        path = os.path.abspath(os.path.join(dirname, 'git.marks'))
+
+        if not os.path.exists(dirname):
+            os.makedirs(dirname)
+
+        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
diff --git a/git_remote_helpers/git/non_local.py b/git_remote_helpers/git/non_local.py
new file mode 100644 (file)
index 0000000..f27389b
--- /dev/null
@@ -0,0 +1,69 @@
+import os
+import subprocess
+
+from git_remote_helpers.util import die, warn
+
+
+class NonLocalGit(object):
+    """Handler to interact with non-local repos.
+    """
+
+    def __init__(self, repo):
+        """Creates a new non-local handler for the specified repo.
+        """
+
+        self.repo = repo
+
+    def clone(self, base):
+        """Clones the non-local repo to base.
+
+        Does nothing if a clone already exists.
+        """
+
+        path = os.path.join(self.repo.get_base_path(base), '.git')
+
+        # already cloned
+        if os.path.exists(path):
+            return path
+
+        os.makedirs(path)
+        args = ["git", "clone", "--bare", "--quiet", self.repo.gitpath, path]
+
+        child = subprocess.Popen(args)
+        if child.wait() != 0:
+            raise CalledProcessError
+
+        return path
+
+    def update(self, base):
+        """Updates checkout of the non-local repo in base.
+        """
+
+        path = os.path.join(self.repo.get_base_path(base), '.git')
+
+        if not os.path.exists(path):
+            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
+
+        args = ["git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD"]
+        child = subprocess.Popen(args)
+        if child.wait() != 0:
+            raise CalledProcessError
+
+    def push(self, base):
+        """Pushes from the non-local repo to base.
+        """
+
+        path = os.path.join(self.repo.get_base_path(base), '.git')
+
+        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
diff --git a/git_remote_helpers/git/repo.py b/git_remote_helpers/git/repo.py
new file mode 100644 (file)
index 0000000..58e1cdb
--- /dev/null
@@ -0,0 +1,75 @@
+import os
+import subprocess
+
+def sanitize(rev, sep='\t'):
+    """Converts a for-each-ref line to a name/value pair.
+    """
+
+    splitrev = rev.split(sep)
+    branchval = splitrev[0]
+    branchname = splitrev[1].strip()
+    if branchname.startswith("refs/heads/"):
+        branchname = branchname[11:]
+
+    return branchname, branchval
+
+def is_remote(url):
+    """Checks whether the specified value is a remote url.
+    """
+
+    prefixes = ["http", "file", "git"]
+
+    for prefix in prefixes:
+        if url.startswith(prefix):
+            return True
+    return False
+
+class GitRepo(object):
+    """Repo object representing a repo.
+    """
+
+    def __init__(self, path):
+        """Initializes a new repo at the given path.
+        """
+
+        self.path = path
+        self.head = None
+        self.revmap = {}
+        self.local = not is_remote(self.path)
+
+        if(self.path.endswith('.git')):
+            self.gitpath = self.path
+        else:
+            self.gitpath = os.path.join(self.path, '.git')
+
+        if self.local and not os.path.exists(self.gitpath):
+            os.makedirs(self.gitpath)
+
+    def get_revs(self):
+        """Fetches all revs from the remote.
+        """
+
+        args = ["git", "ls-remote", self.gitpath]
+        path = ".cached_revs"
+        ofile = open(path, "w")
+
+        child = subprocess.Popen(args, stdout=ofile)
+        if child.wait() != 0:
+            raise CalledProcessError
+        output = open(path).readlines()
+        self.revmap = dict(sanitize(i) for i in output)
+        if "HEAD" in self.revmap:
+            del self.revmap["HEAD"]
+        self.revs = self.revmap.keys()
+        ofile.close()
+
+    def get_head(self):
+        """Determines the head of a local repo.
+        """
+
+        if not self.local:
+            return
+
+        path = os.path.join(self.gitpath, "HEAD")
+        head = open(path).readline()
+        self.head, _ = sanitize(head, ' ')
index cbdc1364700d79b9d8b41850790baee103f31ca1..823053173c92e4097dad54945db16f42b4b5d994 100644 (file)
@@ -2,12 +2,13 @@ GIT web Interface (gitweb) Installation
 =======================================
 
 First you have to generate gitweb.cgi from gitweb.perl using
-"make gitweb", then copy appropriate files (gitweb.cgi, gitweb.js,
-gitweb.css, git-logo.png and git-favicon.png) to their destination.
-For example if git was (or is) installed with /usr prefix, you can do
+"make gitweb", then "make install-gitweb" appropriate files
+(gitweb.cgi, gitweb.js, gitweb.css, git-logo.png and git-favicon.png)
+to their destination. For example if git was (or is) installed with
+/usr prefix and gitwebdir is /var/www/cgi-bin, you can do
 
-       $ make prefix=/usr gitweb             ;# as yourself
-       # cp gitweb/git* /var/www/cgi-bin/    ;# as root
+       $ make prefix=/usr gitweb                            ;# as yourself
+       # make gitwebdir=/var/www/cgi-bin install-gitweb     ;# as root
 
 Alternatively you can use autoconf generated ./configure script to
 set up path to git binaries (via config.mak.autogen), so you can write
@@ -16,7 +17,8 @@ instead
        $ make configure                     ;# as yourself
        $ ./configure --prefix=/usr          ;# as yourself
        $ make gitweb                        ;# as yourself
-       # cp gitweb/git* /var/www/cgi-bin/   ;# as root
+       # make gitwebdir=/var/www/cgi-bin \
+              install-gitweb                ;# as root
 
 The above example assumes that your web server is configured to run
 [executable] files in /var/www/cgi-bin/ as server scripts (as CGI
@@ -74,21 +76,20 @@ file for gitweb (in gitweb/README).
 Build example
 ~~~~~~~~~~~~~
 
-- To install gitweb to /var/www/cgi-bin/gitweb/ when git wrapper
-  is installed at /usr/local/bin/git and the repositories (projects)
-  we want to display are under /home/local/scm, you can do
+- To install gitweb to /var/www/cgi-bin/gitweb/, when git wrapper
+  is installed at /usr/local/bin/git, the repositories (projects)
+  we want to display are under /home/local/scm, and you do not use
+  minifiers, you can do
 
        make GITWEB_PROJECTROOT="/home/local/scm" \
-            GITWEB_JS="/gitweb/gitweb.js" \
-            GITWEB_CSS="/gitweb/gitweb.css" \
-            GITWEB_LOGO="/gitweb/git-logo.png" \
-            GITWEB_FAVICON="/gitweb/git-favicon.png" \
+            GITWEB_JS="gitweb/static/gitweb.js" \
+            GITWEB_CSS="gitweb/static/gitweb.css" \
+            GITWEB_LOGO="gitweb/static/git-logo.png" \
+            GITWEB_FAVICON="gitweb/static/git-favicon.png" \
             bindir=/usr/local/bin \
             gitweb
 
-       cp -fv ~/git/gitweb/gitweb.{cgi,js,css} \
-              ~/git/gitweb/git-{favicon,logo}.png \
-            /var/www/cgi-bin/gitweb/
+       make gitwebdir=/var/www/cgi-bin/gitweb install-gitweb
 
 
 Gitweb config file
index e7dd2527736ddc6e47f864916115f9cc5c9e7dd9..2fb7c2d77bbd5f2041341822859dce51ae504d83 100644 (file)
@@ -4,15 +4,18 @@ all::
 # Define V=1 to have a more verbose compile.
 #
 # Define JSMIN to point to JavaScript minifier that functions as
-# a filter to have gitweb.js minified.
+# a filter to have static/gitweb.js minified.
 #
 # Define CSSMIN to point to a CSS minifier in order to generate a minified
-# version of gitweb.css
+# version of static/gitweb.css
 #
 
 prefix ?= $(HOME)
 bindir ?= $(prefix)/bin
+gitwebdir ?= /var/www/cgi-bin
+
 RM ?= rm -f
+INSTALL ?= install
 
 # default configuration for gitweb
 GITWEB_CONFIG = gitweb_config.perl
@@ -26,10 +29,10 @@ GITWEB_STRICT_EXPORT =
 GITWEB_BASE_URL =
 GITWEB_LIST =
 GITWEB_HOMETEXT = indextext.html
-GITWEB_CSS = gitweb.css
-GITWEB_LOGO = git-logo.png
-GITWEB_FAVICON = git-favicon.png
-GITWEB_JS = gitweb.js
+GITWEB_CSS = static/gitweb.css
+GITWEB_LOGO = static/git-logo.png
+GITWEB_FAVICON = static/git-favicon.png
+GITWEB_JS = static/gitweb.js
 GITWEB_SITE_HEADER =
 GITWEB_SITE_FOOTER =
 
@@ -49,9 +52,12 @@ SHELL_PATH ?= $(SHELL)
 PERL_PATH  ?= /usr/bin/perl
 
 # Shell quote;
-bindir_SQ = $(subst ','\'',$(bindir))         #'
-SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) #'
-PERL_PATH_SQ  = $(subst ','\'',$(PERL_PATH))  #'
+bindir_SQ = $(subst ','\'',$(bindir))#'
+gitwebdir_SQ = $(subst ','\'',$(gitwebdir))#'
+gitwebstaticdir_SQ = $(subst ','\'',$(gitwebdir)/static)#'
+SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))#'
+PERL_PATH_SQ  = $(subst ','\'',$(PERL_PATH))#'
+DESTDIR_SQ    = $(subst ','\'',$(DESTDIR))#'
 
 # Quiet generation (unless V=1)
 QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
@@ -80,20 +86,30 @@ endif
 
 all:: gitweb.cgi
 
+GITWEB_PROGRAMS = gitweb.cgi
+
 ifdef JSMIN
-GITWEB_JS = gitweb.min.js
-all:: gitweb.min.js
-gitweb.min.js: gitweb.js GITWEB-BUILD-OPTIONS
+GITWEB_FILES += static/gitweb.min.js
+GITWEB_JS = static/gitweb.min.js
+all:: static/gitweb.min.js
+static/gitweb.min.js: static/gitweb.js GITWEB-BUILD-OPTIONS
        $(QUIET_GEN)$(JSMIN) <$< >$@
+else
+GITWEB_FILES += static/gitweb.js
 endif
 
 ifdef CSSMIN
-GITWEB_CSS = gitweb.min.css
-all:: gitweb.min.css
-gitweb.min.css: gitweb.css GITWEB-BUILD-OPTIONS
+GITWEB_FILES += static/gitweb.min.css
+GITWEB_CSS = static/gitweb.min.css
+all:: static/gitweb.min.css
+static/gitweb.min.css: static/gitweb.css GITWEB-BUILD-OPTIONS
        $(QUIET_GEN)$(CSSMIN) <$< >$@
+else
+GITWEB_FILES += static/gitweb.css
 endif
 
+GITWEB_FILES += static/git-logo.png static/git-favicon.png
+
 GITWEB_REPLACE = \
        -e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
        -e 's|++GIT_BINDIR++|$(bindir)|g' \
@@ -127,8 +143,18 @@ gitweb.cgi: gitweb.perl GITWEB-BUILD-OPTIONS
        chmod +x $@+ && \
        mv $@+ $@
 
+### Installation rules
+
+install: all
+       $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebdir_SQ)'
+       $(INSTALL) -m 755 $(GITWEB_PROGRAMS) '$(DESTDIR_SQ)$(gitwebdir_SQ)'
+       $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'
+       $(INSTALL) -m 644 $(GITWEB_FILES) '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'
+
+### Cleaning rules
+
 clean:
-       $(RM) gitweb.cgi gitweb.min.js gitweb.min.css GITWEB-BUILD-OPTIONS
+       $(RM) gitweb.cgi static/gitweb.min.js static/gitweb.min.css GITWEB-BUILD-OPTIONS
 
-.PHONY: all clean .FORCE-GIT-VERSION-FILE FORCE
+.PHONY: all clean install .FORCE-GIT-VERSION-FILE FORCE
 
index 71742b335dd786a24699b06b17519e264724ea5b..d4811987965e5a5036b7ed71e32d93578579073a 100644 (file)
@@ -80,24 +80,26 @@ You can specify the following configuration variables when building GIT:
    Points to the location where you put gitweb.css on your web server
    (or to be more generic, the URI of gitweb stylesheet).  Relative to the
    base URI of gitweb.  Note that you can setup multiple stylesheets from
-   the gitweb config file.  [Default: gitweb.css (or gitweb.min.css if the
-   CSSMIN variable is defined / CSS minifier is used)]
+   the gitweb config file.  [Default: static/gitweb.css (or
+   static/gitweb.min.css if the CSSMIN variable is defined / CSS minifier
+   is used)]
  * GITWEB_LOGO
    Points to the location where you put git-logo.png on your web server
    (or to be more generic URI of logo, 72x27 size, displayed in top right
    corner of each gitweb page, and used as logo for Atom feed).  Relative
-   to base URI of gitweb.  [Default: git-logo.png]
+   to base URI of gitweb.  [Default: static/git-logo.png]
  * GITWEB_FAVICON
    Points to the location where you put git-favicon.png on your web server
    (or to be more generic URI of favicon, assumed to be image/png type;
    web browsers that support favicons (website icons) may display them
    in the browser's URL bar and next to site name in bookmarks).  Relative
-   to base URI of gitweb.  [Default: git-favicon.png]
+   to base URI of gitweb.  [Default: static/git-favicon.png]
  * GITWEB_JS
-   Points to the localtion where you put gitweb.js on your web server
+   Points to the location where you put gitweb.js on your web server
    (or to be more generic URI of JavaScript code used by gitweb).
-   Relative to base URI of gitweb.  [Default: gitweb.js (or gitweb.min.js
-   if JSMIN build variable is defined / JavaScript minifier is used)]
+   Relative to base URI of gitweb.  [Default: static/gitweb.js (or
+   static/gitweb.min.js if JSMIN build variable is defined / JavaScript
+   minifier is used)]
  * GITWEB_CONFIG
    This Perl file will be loaded using 'do' and can be used to override any
    of the options above as well as some other options -- see the "Runtime
@@ -231,7 +233,7 @@ not include variables usually directly set during build):
    is false.
  * $maxload
    Used to set the maximum load that we will still respond to gitweb queries.
-   If server load exceed this value then return "503 Service Unavaliable" error.
+   If server load exceed this value then return "503 Service Unavailable" error.
    Server load is taken to be 0 if gitweb cannot determine its value.  Set it to
    undefined value to turn it off.  The default is 300.
 
index b51f5bfb2f3e1b440a1815ad6163441ba97c8c70..8b8ab2960793d591bcd8bf572e882339b9674a04 100755 (executable)
@@ -11,7 +11,7 @@ use strict;
 use warnings;
 use CGI qw(:standard :escapeHTML -nosticky);
 use CGI::Util qw(unescape);
-use CGI::Carp qw(fatalsToBrowser);
+use CGI::Carp qw(fatalsToBrowser set_message);
 use Encode;
 use Fcntl ':mode';
 use File::Find qw();
@@ -28,34 +28,42 @@ BEGIN {
        CGI->compile() if $ENV{'MOD_PERL'};
 }
 
-our $cgi = new CGI;
 our $version = "++GIT_VERSION++";
-our $my_url = $cgi->url();
-our $my_uri = $cgi->url(-absolute => 1);
 
-# Base URL for relative URLs in gitweb ($logo, $favicon, ...),
-# needed and used only for URLs with nonempty PATH_INFO
-our $base_url = $my_url;
+our ($my_url, $my_uri, $base_url, $path_info, $home_link);
+sub evaluate_uri {
+       our $cgi;
 
-# When the script is used as DirectoryIndex, the URL does not contain the name
-# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
-# have to do it ourselves. We make $path_info global because it's also used
-# later on.
-#
-# Another issue with the script being the DirectoryIndex is that the resulting
-# $my_url data is not the full script URL: this is good, because we want
-# generated links to keep implying the script name if it wasn't explicitly
-# indicated in the URL we're handling, but it means that $my_url cannot be used
-# as base URL.
-# Therefore, if we needed to strip PATH_INFO, then we know that we have
-# to build the base URL ourselves:
-our $path_info = $ENV{"PATH_INFO"};
-if ($path_info) {
-       if ($my_url =~ s,\Q$path_info\E$,, &&
-           $my_uri =~ s,\Q$path_info\E$,, &&
-           defined $ENV{'SCRIPT_NAME'}) {
-               $base_url = $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'};
+       our $my_url = $cgi->url();
+       our $my_uri = $cgi->url(-absolute => 1);
+
+       # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
+       # needed and used only for URLs with nonempty PATH_INFO
+       our $base_url = $my_url;
+
+       # When the script is used as DirectoryIndex, the URL does not contain the name
+       # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
+       # have to do it ourselves. We make $path_info global because it's also used
+       # later on.
+       #
+       # Another issue with the script being the DirectoryIndex is that the resulting
+       # $my_url data is not the full script URL: this is good, because we want
+       # generated links to keep implying the script name if it wasn't explicitly
+       # indicated in the URL we're handling, but it means that $my_url cannot be used
+       # as base URL.
+       # Therefore, if we needed to strip PATH_INFO, then we know that we have
+       # to build the base URL ourselves:
+       our $path_info = $ENV{"PATH_INFO"};
+       if ($path_info) {
+               if ($my_url =~ s,\Q$path_info\E$,, &&
+                   $my_uri =~ s,\Q$path_info\E$,, &&
+                   defined $ENV{'SCRIPT_NAME'}) {
+                       $base_url = $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'};
+               }
        }
+
+       # target of the home link on top of all pages
+       our $home_link = $my_uri || "/";
 }
 
 # core git executable to use
@@ -70,9 +78,6 @@ our $projectroot = "++GITWEB_PROJECTROOT++";
 # the number is relative to the projectroot
 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
 
-# target of the home link on top of all pages
-our $home_link = $my_uri || "/";
-
 # string of the home link on top of all pages
 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
 
@@ -240,7 +245,7 @@ our %feature = (
        # return value of feature-sub indicates if to enable specified feature
        #
        # if there is no 'sub' key (no feature-sub), then feature cannot be
-       # overriden
+       # overridden
        #
        # use gitweb_get_feature(<feature>) to retrieve the <feature> value
        # (an array) or gitweb_check_feature(<feature>) to check if <feature>
@@ -445,6 +450,19 @@ our %feature = (
        'javascript-actions' => {
                'override' => 0,
                'default' => [0]},
+
+       # Syntax highlighting support. This is based on Daniel Svensson's
+       # and Sham Chukoury's work in gitweb-xmms2.git.
+       # It requires the 'highlight' program present in $PATH,
+       # and therefore is disabled by default.
+
+       # To enable system wide have in $GITWEB_CONFIG
+       # $feature{'highlight'}{'default'} = [1];
+
+       'highlight' => {
+               'sub' => sub { feature_bool('highlight', @_) },
+               'override' => 0,
+               'default' => [0]},
 );
 
 sub gitweb_get_feature {
@@ -553,15 +571,18 @@ sub filter_snapshot_fmts {
                !$known_snapshot_formats{$_}{'disabled'}} @fmts;
 }
 
-our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
-our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
-# die if there are errors parsing config file
-if (-e $GITWEB_CONFIG) {
-       do $GITWEB_CONFIG;
-       die $@ if $@;
-} elsif (-e $GITWEB_CONFIG_SYSTEM) {
-       do $GITWEB_CONFIG_SYSTEM;
-       die $@ if $@;
+our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
+sub evaluate_gitweb_config {
+       our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
+       our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
+       # die if there are errors parsing config file
+       if (-e $GITWEB_CONFIG) {
+               do $GITWEB_CONFIG;
+               die $@ if $@;
+       } elsif (-e $GITWEB_CONFIG_SYSTEM) {
+               do $GITWEB_CONFIG_SYSTEM;
+               die $@ if $@;
+       }
 }
 
 # Get loadavg of system, to compare against $maxload.
@@ -587,13 +608,16 @@ sub get_loadavg {
 }
 
 # version of the core git binary
-our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
-$number_of_git_cmds++;
-
-$projects_list ||= $projectroot;
+our $git_version;
+sub evaluate_git_version {
+       our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
+       $number_of_git_cmds++;
+}
 
-if (defined $maxload && get_loadavg() > $maxload) {
-       die_error(503, "The load average on the server is too high");
+sub check_loadavg {
+       if (defined $maxload && get_loadavg() > $maxload) {
+               die_error(503, "The load average on the server is too high");
+       }
 }
 
 # ======================================================================
@@ -680,11 +704,15 @@ our %allowed_options = (
 # should be single values, but opt can be an array. We should probably
 # build an array of parameters that can be multi-valued, but since for the time
 # being it's only this one, we just single it out
-while (my ($name, $symbol) = each %cgi_param_mapping) {
-       if ($symbol eq 'opt') {
-               $input_params{$name} = [ $cgi->param($symbol) ];
-       } else {
-               $input_params{$name} = $cgi->param($symbol);
+sub evaluate_query_params {
+       our $cgi;
+
+       while (my ($name, $symbol) = each %cgi_param_mapping) {
+               if ($symbol eq 'opt') {
+                       $input_params{$name} = [ $cgi->param($symbol) ];
+               } else {
+                       $input_params{$name} = $cgi->param($symbol);
+               }
        }
 }
 
@@ -831,152 +859,277 @@ sub evaluate_path_info {
                }
        }
 }
-evaluate_path_info();
 
-our $action = $input_params{'action'};
-if (defined $action) {
-       if (!validate_action($action)) {
-               die_error(400, "Invalid action parameter");
+our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
+     $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
+     $searchtext, $search_regexp);
+sub evaluate_and_validate_params {
+       our $action = $input_params{'action'};
+       if (defined $action) {
+               if (!validate_action($action)) {
+                       die_error(400, "Invalid action parameter");
+               }
        }
-}
 
-# parameters which are pathnames
-our $project = $input_params{'project'};
-if (defined $project) {
-       if (!validate_project($project)) {
-               undef $project;
-               die_error(404, "No such project");
+       # parameters which are pathnames
+       our $project = $input_params{'project'};
+       if (defined $project) {
+               if (!validate_project($project)) {
+                       undef $project;
+                       die_error(404, "No such project");
+               }
        }
-}
 
-our $file_name = $input_params{'file_name'};
-if (defined $file_name) {
-       if (!validate_pathname($file_name)) {
-               die_error(400, "Invalid file parameter");
+       our $file_name = $input_params{'file_name'};
+       if (defined $file_name) {
+               if (!validate_pathname($file_name)) {
+                       die_error(400, "Invalid file parameter");
+               }
        }
-}
 
-our $file_parent = $input_params{'file_parent'};
-if (defined $file_parent) {
-       if (!validate_pathname($file_parent)) {
-               die_error(400, "Invalid file parent parameter");
+       our $file_parent = $input_params{'file_parent'};
+       if (defined $file_parent) {
+               if (!validate_pathname($file_parent)) {
+                       die_error(400, "Invalid file parent parameter");
+               }
        }
-}
 
-# parameters which are refnames
-our $hash = $input_params{'hash'};
-if (defined $hash) {
-       if (!validate_refname($hash)) {
-               die_error(400, "Invalid hash parameter");
+       # parameters which are refnames
+       our $hash = $input_params{'hash'};
+       if (defined $hash) {
+               if (!validate_refname($hash)) {
+                       die_error(400, "Invalid hash parameter");
+               }
        }
-}
 
-our $hash_parent = $input_params{'hash_parent'};
-if (defined $hash_parent) {
-       if (!validate_refname($hash_parent)) {
-               die_error(400, "Invalid hash parent parameter");
+       our $hash_parent = $input_params{'hash_parent'};
+       if (defined $hash_parent) {
+               if (!validate_refname($hash_parent)) {
+                       die_error(400, "Invalid hash parent parameter");
+               }
        }
-}
 
-our $hash_base = $input_params{'hash_base'};
-if (defined $hash_base) {
-       if (!validate_refname($hash_base)) {
-               die_error(400, "Invalid hash base parameter");
+       our $hash_base = $input_params{'hash_base'};
+       if (defined $hash_base) {
+               if (!validate_refname($hash_base)) {
+                       die_error(400, "Invalid hash base parameter");
+               }
        }
-}
 
-our @extra_options = @{$input_params{'extra_options'}};
-# @extra_options is always defined, since it can only be (currently) set from
-# CGI, and $cgi->param() returns the empty array in array context if the param
-# is not set
-foreach my $opt (@extra_options) {
-       if (not exists $allowed_options{$opt}) {
-               die_error(400, "Invalid option parameter");
-       }
-       if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
-               die_error(400, "Invalid option parameter for this action");
+       our @extra_options = @{$input_params{'extra_options'}};
+       # @extra_options is always defined, since it can only be (currently) set from
+       # CGI, and $cgi->param() returns the empty array in array context if the param
+       # is not set
+       foreach my $opt (@extra_options) {
+               if (not exists $allowed_options{$opt}) {
+                       die_error(400, "Invalid option parameter");
+               }
+               if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
+                       die_error(400, "Invalid option parameter for this action");
+               }
        }
-}
 
-our $hash_parent_base = $input_params{'hash_parent_base'};
-if (defined $hash_parent_base) {
-       if (!validate_refname($hash_parent_base)) {
-               die_error(400, "Invalid hash parent base parameter");
+       our $hash_parent_base = $input_params{'hash_parent_base'};
+       if (defined $hash_parent_base) {
+               if (!validate_refname($hash_parent_base)) {
+                       die_error(400, "Invalid hash parent base parameter");
+               }
        }
-}
 
-# other parameters
-our $page = $input_params{'page'};
-if (defined $page) {
-       if ($page =~ m/[^0-9]/) {
-               die_error(400, "Invalid page parameter");
+       # other parameters
+       our $page = $input_params{'page'};
+       if (defined $page) {
+               if ($page =~ m/[^0-9]/) {
+                       die_error(400, "Invalid page parameter");
+               }
        }
-}
 
-our $searchtype = $input_params{'searchtype'};
-if (defined $searchtype) {
-       if ($searchtype =~ m/[^a-z]/) {
-               die_error(400, "Invalid searchtype parameter");
+       our $searchtype = $input_params{'searchtype'};
+       if (defined $searchtype) {
+               if ($searchtype =~ m/[^a-z]/) {
+                       die_error(400, "Invalid searchtype parameter");
+               }
        }
-}
 
-our $search_use_regexp = $input_params{'search_use_regexp'};
+       our $search_use_regexp = $input_params{'search_use_regexp'};
 
-our $searchtext = $input_params{'searchtext'};
-our $search_regexp;
-if (defined $searchtext) {
-       if (length($searchtext) < 2) {
-               die_error(403, "At least two characters are required for search parameter");
+       our $searchtext = $input_params{'searchtext'};
+       our $search_regexp;
+       if (defined $searchtext) {
+               if (length($searchtext) < 2) {
+                       die_error(403, "At least two characters are required for search parameter");
+               }
+               $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
        }
-       $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
 }
 
 # path to the current git repository
 our $git_dir;
-$git_dir = "$projectroot/$project" if $project;
-
-# list of supported snapshot formats
-our @snapshot_fmts = gitweb_get_feature('snapshot');
-@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
-
-# check that the avatar feature is set to a known provider name,
-# and for each provider check if the dependencies are satisfied.
-# if the provider name is invalid or the dependencies are not met,
-# reset $git_avatar to the empty string.
-our ($git_avatar) = gitweb_get_feature('avatar');
-if ($git_avatar eq 'gravatar') {
-       $git_avatar = '' unless (eval { require Digest::MD5; 1; });
-} elsif ($git_avatar eq 'picon') {
-       # no dependencies
-} else {
-       $git_avatar = '';
+sub evaluate_git_dir {
+       our $git_dir = "$projectroot/$project" if $project;
 }
 
-# dispatch
-if (!defined $action) {
-       if (defined $hash) {
-               $action = git_get_type($hash);
-       } elsif (defined $hash_base && defined $file_name) {
-               $action = git_get_type("$hash_base:$file_name");
-       } elsif (defined $project) {
-               $action = 'summary';
+our (@snapshot_fmts, $git_avatar);
+sub configure_gitweb_features {
+       # list of supported snapshot formats
+       our @snapshot_fmts = gitweb_get_feature('snapshot');
+       @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
+
+       # check that the avatar feature is set to a known provider name,
+       # and for each provider check if the dependencies are satisfied.
+       # if the provider name is invalid or the dependencies are not met,
+       # reset $git_avatar to the empty string.
+       our ($git_avatar) = gitweb_get_feature('avatar');
+       if ($git_avatar eq 'gravatar') {
+               $git_avatar = '' unless (eval { require Digest::MD5; 1; });
+       } elsif ($git_avatar eq 'picon') {
+               # no dependencies
        } else {
-               $action = 'project_list';
+               $git_avatar = '';
        }
 }
-if (!defined($actions{$action})) {
-       die_error(400, "Unknown action");
+
+# custom error handler: 'die <message>' is Internal Server Error
+sub handle_errors_html {
+       my $msg = shift; # it is already HTML escaped
+
+       # to avoid infinite loop where error occurs in die_error,
+       # change handler to default handler, disabling handle_errors_html
+       set_message("Error occured when inside die_error:\n$msg");
+
+       # you cannot jump out of die_error when called as error handler;
+       # the subroutine set via CGI::Carp::set_message is called _after_
+       # HTTP headers are already written, so it cannot write them itself
+       die_error(undef, undef, $msg, -error_handler => 1, -no_http_header => 1);
 }
-if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
-    !$project) {
-       die_error(400, "Project needed");
+set_message(\&handle_errors_html);
+
+# dispatch
+sub dispatch {
+       if (!defined $action) {
+               if (defined $hash) {
+                       $action = git_get_type($hash);
+               } elsif (defined $hash_base && defined $file_name) {
+                       $action = git_get_type("$hash_base:$file_name");
+               } elsif (defined $project) {
+                       $action = 'summary';
+               } else {
+                       $action = 'project_list';
+               }
+       }
+       if (!defined($actions{$action})) {
+               die_error(400, "Unknown action");
+       }
+       if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
+           !$project) {
+               die_error(400, "Project needed");
+       }
+       $actions{$action}->();
+}
+
+sub reset_timer {
+       our $t0 = [Time::HiRes::gettimeofday()]
+               if defined $t0;
+       our $number_of_git_cmds = 0;
+}
+
+sub run_request {
+       reset_timer();
+
+       evaluate_uri();
+       check_loadavg();
+
+       evaluate_query_params();
+       evaluate_path_info();
+       evaluate_and_validate_params();
+       evaluate_git_dir();
+
+       configure_gitweb_features();
+
+       dispatch();
+}
+
+our $is_last_request = sub { 1 };
+our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
+our $CGI = 'CGI';
+our $cgi;
+sub configure_as_fcgi {
+       require CGI::Fast;
+       our $CGI = 'CGI::Fast';
+
+       my $request_number = 0;
+       # let each child service 100 requests
+       our $is_last_request = sub { ++$request_number > 100 };
+}
+sub evaluate_argv {
+       my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__;
+       configure_as_fcgi()
+               if $script_name =~ /\.fcgi$/;
+
+       return unless (@ARGV);
+
+       require Getopt::Long;
+       Getopt::Long::GetOptions(
+               'fastcgi|fcgi|f' => \&configure_as_fcgi,
+               'nproc|n=i' => sub {
+                       my ($arg, $val) = @_;
+                       return unless eval { require FCGI::ProcManager; 1; };
+                       my $proc_manager = FCGI::ProcManager->new({
+                               n_processes => $val,
+                       });
+                       our $pre_listen_hook    = sub { $proc_manager->pm_manage()        };
+                       our $pre_dispatch_hook  = sub { $proc_manager->pm_pre_dispatch()  };
+                       our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
+               },
+       );
+}
+
+sub run {
+       evaluate_argv();
+       evaluate_gitweb_config();
+       evaluate_git_version();
+
+       # $projectroot and $projects_list might be set in gitweb config file
+       $projects_list ||= $projectroot;
+
+       $pre_listen_hook->()
+               if $pre_listen_hook;
+
+ REQUEST:
+       while ($cgi = $CGI->new()) {
+               $pre_dispatch_hook->()
+                       if $pre_dispatch_hook;
+
+               run_request();
+
+               $pre_dispatch_hook->()
+                       if $post_dispatch_hook;
+
+               last REQUEST if ($is_last_request->());
+       }
+
+ DONE_GITWEB:
+       1;
+}
+
+run();
+
+if (defined caller) {
+       # wrapped in a subroutine processing requests,
+       # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
+       return;
+} else {
+       # pure CGI script, serving single request
+       exit;
 }
-$actions{$action}->();
-exit;
 
 ## ======================================================================
 ## action links
 
+# possible values of extra options
+# -full => 0|1      - use absolute/full URL ($my_uri/$my_url as base)
+# -replay => 1      - start from a current view (replay with modifications)
+# -path_info => 0|1 - don't use/use path_info URL (if possible)
 sub href {
        my %params = @_;
        # default is to use -absolute url() i.e. $my_uri
@@ -993,7 +1146,8 @@ sub href {
        }
 
        my $use_pathinfo = gitweb_check_feature('pathinfo');
-       if ($use_pathinfo and defined $params{'project'}) {
+       if (defined $params{'project'} &&
+           (exists $params{-path_info} ? $params{-path_info} : $use_pathinfo)) {
                # try to put as many parameters as possible in PATH_INFO:
                #   - project name
                #   - action
@@ -1169,7 +1323,7 @@ sub esc_param {
        return $str;
 }
 
-# quote unsafe chars in whole URL, so some charactrs cannot be quoted
+# quote unsafe chars in whole URL, so some characters cannot be quoted
 sub esc_url {
        my $str = shift;
        return undef unless defined $str;
@@ -2426,6 +2580,9 @@ sub git_get_projects_list {
                        follow_skip => 2, # ignore duplicates
                        dangling_symlinks => 0, # ignore dangling symlinks, silently
                        wanted => sub {
+                               # global variables
+                               our $project_maxdepth;
+                               our $projectroot;
                                # skip project-list toplevel, if we get it.
                                return if (m!^[/.]$!);
                                # only directories can be git repositories
@@ -3161,26 +3318,88 @@ sub blob_contenttype {
        return $type;
 }
 
+# guess file syntax for syntax highlighting; return undef if no highlighting
+# the name of syntax can (in the future) depend on syntax highlighter used
+sub guess_file_syntax {
+       my ($highlight, $mimetype, $file_name) = @_;
+       return undef unless ($highlight && defined $file_name);
+
+       # configuration for 'highlight' (http://www.andre-simon.de/)
+       # match by basename
+       my %highlight_basename = (
+               #'Program' => 'py',
+               #'Library' => 'py',
+               'SConstruct' => 'py', # SCons equivalent of Makefile
+               'Makefile' => 'make',
+       );
+       # match by extension
+       my %highlight_ext = (
+               # main extensions, defining name of syntax;
+               # see files in /usr/share/highlight/langDefs/ directory
+               map { $_ => $_ }
+                       qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
+               # alternate extensions, see /etc/highlight/filetypes.conf
+               'h' => 'c',
+               map { $_ => 'cpp' } qw(cxx c++ cc),
+               map { $_ => 'php' } qw(php3 php4),
+               map { $_ => 'pl'  } qw(perl pm), # perhaps also 'cgi'
+               'mak' => 'make',
+               map { $_ => 'xml' } qw(xhtml html htm),
+       );
+
+       my $basename = basename($file_name, '.in');
+       return $highlight_basename{$basename}
+               if exists $highlight_basename{$basename};
+
+       $basename =~ /\.([^.]*)$/;
+       my $ext = $1 or return undef;
+       return $highlight_ext{$ext}
+               if exists $highlight_ext{$ext};
+
+       return undef;
+}
+
+# run highlighter and return FD of its output,
+# or return original FD if no highlighting
+sub run_highlighter {
+       my ($fd, $highlight, $syntax) = @_;
+       return $fd unless ($highlight && defined $syntax);
+
+       close $fd
+               or die_error(404, "Reading blob failed");
+       open $fd, quote_command(git_cmd(), "cat-file", "blob", $hash)." | ".
+                 "highlight --xhtml --fragment --syntax $syntax |"
+               or die_error(500, "Couldn't open file or run syntax highlighter");
+       return $fd;
+}
+
 ## ======================================================================
 ## functions printing HTML: header, footer, error page
 
+sub get_page_title {
+       my $title = to_utf8($site_name);
+
+       return $title unless (defined $project);
+       $title .= " - " . to_utf8($project);
+
+       return $title unless (defined $action);
+       $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
+
+       return $title unless (defined $file_name);
+       $title .= " - " . esc_path($file_name);
+       if ($action eq "tree" && $file_name !~ m|/$|) {
+               $title .= "/";
+       }
+
+       return $title;
+}
+
 sub git_header_html {
        my $status = shift || "200 OK";
        my $expires = shift;
+       my %opts = @_;
 
-       my $title = "$site_name";
-       if (defined $project) {
-               $title .= " - " . to_utf8($project);
-               if (defined $action) {
-                       $title .= "/$action";
-                       if (defined $file_name) {
-                               $title .= " - " . esc_path($file_name);
-                               if ($action eq "tree" && $file_name !~ m|/$|) {
-                                       $title .= "/";
-                               }
-                       }
-               }
-       }
+       my $title = get_page_title();
        my $content_type;
        # require explicit support from the UA if we are to send the page as
        # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
@@ -3194,7 +3413,8 @@ sub git_header_html {
                $content_type = 'text/html';
        }
        print $cgi->header(-type=>$content_type, -charset => 'utf-8',
-                          -status=> $status, -expires => $expires);
+                          -status=> $status, -expires => $expires)
+               unless ($opts{'-no_http_header'});
        my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
        print <<EOF;
 <?xml version="1.0" encoding="utf-8"?>
@@ -3411,6 +3631,7 @@ sub die_error {
        my $status = shift || 500;
        my $error = esc_html(shift) || "Internal Server Error";
        my $extra = shift;
+       my %opts = @_;
 
        my %http_responses = (
                400 => '400 Bad Request',
@@ -3419,7 +3640,7 @@ sub die_error {
                500 => '500 Internal Server Error',
                503 => '503 Service Unavailable',
        );
-       git_header_html($http_responses{$status});
+       git_header_html($http_responses{$status}, undef, %opts);
        print <<EOF;
 <div class="page_body">
 <br /><br />
@@ -3433,7 +3654,8 @@ EOF
        print "</div>\n";
 
        git_footer_html();
-       exit;
+       goto DONE_GITWEB
+               unless ($opts{'-error_handler'});
 }
 
 ## ----------------------------------------------------------------------
@@ -3567,9 +3789,9 @@ sub git_print_authorship {
 }
 
 # Outputs table rows containing the full author or committer information,
-# in the format expected for 'commit' view (& similia).
+# in the format expected for 'commit' view (& similar).
 # Parameters are a commit hash reference, followed by the list of people
-# to output information for. If the list is empty it defalts to both
+# to output information for. If the list is empty it defaults to both
 # author and committer.
 sub git_print_authorship_rows {
        my $co = shift;
@@ -4298,8 +4520,8 @@ sub git_patchset_body {
                print "</div>\n"; # class="patch"
        }
 
-       # for compact combined (--cc) format, with chunk and patch simpliciaction
-       # patchset might be empty, but there might be unprocessed raw lines
+       # for compact combined (--cc) format, with chunk and patch simplification
+       # the patchset might be empty, but there might be unprocessed raw lines
        for (++$patch_idx if $patch_number > 0;
             $patch_idx < @$difftree;
             ++$patch_idx) {
@@ -5352,6 +5574,7 @@ sub git_blob {
        open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
                or die_error(500, "Couldn't cat $file_name, $hash");
        my $mimetype = blob_mimetype($fd, $file_name);
+       # use 'blob_plain' (aka 'raw') view for files that cannot be displayed
        if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) {
                close $fd;
                return git_blob_plain($mimetype);
@@ -5359,6 +5582,11 @@ sub git_blob {
        # we can have blame only for text/* mimetype
        $have_blame &&= ($mimetype =~ m!^text/!);
 
+       my $highlight = gitweb_check_feature('highlight');
+       my $syntax = guess_file_syntax($highlight, $mimetype, $file_name);
+       $fd = run_highlighter($fd, $highlight, $syntax)
+               if $syntax;
+
        git_header_html(undef, $expires);
        my $formats_nav = '';
        if (defined $hash_base && (my %co = parse_commit($hash_base))) {
@@ -5408,10 +5636,8 @@ sub git_blob {
                        chomp $line;
                        $nr++;
                        $line = untabify($line);
-                       printf "<div class=\"pre\"><a id=\"l%i\" href=\""
-                               . esc_attr(href(-replay => 1))
-                               . "#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
-                              $nr, $nr, $nr, esc_html($line, -nbsp=>1);
+                       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);
                }
        }
        close $fd
@@ -6124,8 +6350,8 @@ sub git_commitdiff {
                        }
                        push @commit_spec, '--root', $hash;
                }
-               open $fd, "-|", git_cmd(), "format-patch", '--encoding=utf8',
-                       '--stdout', @commit_spec
+               open $fd, "-|", git_cmd(), "format-patch", @diff_opts,
+                       '--encoding=utf8', '--stdout', @commit_spec
                        or die_error(500, "Open git-format-patch failed");
        } else {
                die_error(400, "Unknown commitdiff format");
@@ -6303,12 +6529,13 @@ sub git_search {
                        $paging_nav .= " &sdot; next";
                }
 
-               if ($#commitlist >= 100) {
-               }
-
                git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
                git_print_header_div('commit', esc_html($co{'title'}), $hash);
-               git_search_grep_body(\@commitlist, 0, 99, $next_link);
+               if ($page == 0 && !@commitlist) {
+                       print "<p>No match.</p>\n";
+               } else {
+                       git_search_grep_body(\@commitlist, 0, 99, $next_link);
+               }
        }
 
        if ($searchtype eq 'pickaxe') {
similarity index 93%
rename from gitweb/gitweb.css
rename to gitweb/static/gitweb.css
index 50067f2e0dea2c1e17a41e9a5e8b2a8f6240c13d..4132aabcdb4ef402ceb1a890b61778b3254fdf18 100644 (file)
@@ -572,3 +572,21 @@ span.match {
 div.binary {
        font-style: italic;
 }
+
+/* Style definition generated by highlight 2.4.5, http://www.andre-simon.de/ */
+
+/* Highlighting theme definition: */
+
+.num    { color:#2928ff; }
+.esc    { color:#ff00ff; }
+.str    { color:#ff0000; }
+.dstr   { color:#818100; }
+.slc    { color:#838183; font-style:italic; }
+.com    { color:#838183; font-style:italic; }
+.dir    { color:#008200; }
+.sym    { color:#000000; }
+.line   { color:#555555; }
+.kwa    { color:#000000; font-weight:bold; }
+.kwb    { color:#830000; }
+.kwc    { color:#000000; font-weight:bold; }
+.kwd    { color:#010181; }
similarity index 100%
rename from gitweb/gitweb.js
rename to gitweb/static/gitweb.js
diff --git a/graph.c b/graph.c
index e6bbcaa8c4655add3ecaca578e948355795e36ca..85ab150787bfcdd593ad13e7c00396a1c96c134d 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -211,6 +211,18 @@ struct git_graph {
        unsigned short default_column_color;
 };
 
+static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void *data)
+{
+       struct git_graph *graph = data;
+       static struct strbuf msgbuf = STRBUF_INIT;
+
+       assert(graph);
+
+       strbuf_reset(&msgbuf);
+       graph_padding_line(graph, &msgbuf);
+       return &msgbuf;
+}
+
 struct git_graph *graph_init(struct rev_info *opt)
 {
        struct git_graph *graph = xmalloc(sizeof(struct git_graph));
@@ -244,6 +256,13 @@ struct git_graph *graph_init(struct rev_info *opt)
        graph->mapping = xmalloc(sizeof(int) * 2 * graph->column_capacity);
        graph->new_mapping = xmalloc(sizeof(int) * 2 * graph->column_capacity);
 
+       /*
+        * The diff output prefix callback, with this we can make
+        * all the diff output to align with the graph lines.
+        */
+       opt->diffopt.output_prefix = diff_output_prefix_callback;
+       opt->diffopt.output_prefix_data = graph;
+
        return graph;
 }
 
@@ -420,7 +439,7 @@ static void graph_update_width(struct git_graph *graph,
                max_cols++;
 
        /*
-        * We added a column for the the current commit as part of
+        * We added a column for the current commit as part of
         * graph->num_parents.  If the current commit was already in
         * graph->columns, then we have double counted it.
         */
diff --git a/grep.c b/grep.c
index 543b1d53784c16020dea089f23c431c7f2608425..82fb349be6f6ef8211d4828101cd8e88bcbb304f 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -7,6 +7,7 @@ void append_header_grep_pattern(struct grep_opt *opt, enum grep_header_field fie
 {
        struct grep_pat *p = xcalloc(1, sizeof(*p));
        p->pattern = pat;
+       p->patternlen = strlen(pat);
        p->origin = "header";
        p->no = 0;
        p->token = GREP_PATTERN_HEAD;
@@ -18,9 +19,16 @@ void append_header_grep_pattern(struct grep_opt *opt, enum grep_header_field fie
 
 void append_grep_pattern(struct grep_opt *opt, const char *pat,
                         const char *origin, int no, enum grep_pat_token t)
+{
+       append_grep_pat(opt, pat, strlen(pat), origin, no, t);
+}
+
+void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen,
+                    const char *origin, int no, enum grep_pat_token t)
 {
        struct grep_pat *p = xcalloc(1, sizeof(*p));
        p->pattern = pat;
+       p->patternlen = patlen;
        p->origin = origin;
        p->no = no;
        p->token = t;
@@ -44,8 +52,8 @@ struct grep_opt *grep_opt_dup(const struct grep_opt *opt)
                        append_header_grep_pattern(ret, pat->field,
                                                   pat->pattern);
                else
-                       append_grep_pattern(ret, pat->pattern, pat->origin,
-                                           pat->no, pat->token);
+                       append_grep_pat(ret, pat->pattern, pat->patternlen,
+                                       pat->origin, pat->no, pat->token);
        }
 
        return ret;
@@ -329,14 +337,21 @@ static void show_name(struct grep_opt *opt, const char *name)
        opt->output(opt, opt->null_following_name ? "\0" : "\n", 1);
 }
 
-
-static int fixmatch(const char *pattern, char *line, int ignore_case, regmatch_t *match)
+static int fixmatch(struct grep_pat *p, char *line, char *eol,
+                   regmatch_t *match)
 {
        char *hit;
-       if (ignore_case)
-               hit = strcasestr(line, pattern);
-       else
-               hit = strstr(line, pattern);
+
+       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) {
                match->rm_so = match->rm_eo = -1;
@@ -344,11 +359,22 @@ static int fixmatch(const char *pattern, char *line, int ignore_case, regmatch_t
        }
        else {
                match->rm_so = hit - line;
-               match->rm_eo = match->rm_so + strlen(pattern);
+               match->rm_eo = match->rm_so + p->patternlen;
                return 0;
        }
 }
 
+static int regmatch(const regex_t *preg, char *line, char *eol,
+                   regmatch_t *match, int eflags)
+{
+#ifdef REG_STARTEND
+       match->rm_so = 0;
+       match->rm_eo = eol - line;
+       eflags |= REG_STARTEND;
+#endif
+       return regexec(preg, line, 1, match, eflags);
+}
+
 static int strip_timestamp(char *bol, char **eol_p)
 {
        char *eol = *eol_p;
@@ -399,9 +425,9 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
 
  again:
        if (p->fixed)
-               hit = !fixmatch(p->pattern, bol, p->ignore_case, pmatch);
+               hit = !fixmatch(p, bol, eol, pmatch);
        else
-               hit = !regexec(&p->regexp, bol, 1, pmatch, eflags);
+               hit = !regmatch(&p->regexp, bol, eol, pmatch, eflags);
 
        if (hit && p->word_regexp) {
                if ((pmatch[0].rm_so < 0) ||
@@ -726,16 +752,9 @@ static int look_ahead(struct grep_opt *opt,
                regmatch_t m;
 
                if (p->fixed)
-                       hit = !fixmatch(p->pattern, bol, p->ignore_case, &m);
-               else {
-#ifdef REG_STARTEND
-                       m.rm_so = 0;
-                       m.rm_eo = *left_p;
-                       hit = !regexec(&p->regexp, bol, 1, &m, REG_STARTEND);
-#else
-                       hit = !regexec(&p->regexp, bol, 1, &m, 0);
-#endif
-               }
+                       hit = !fixmatch(p, bol, bol + *left_p, &m);
+               else
+                       hit = !regmatch(&p->regexp, bol, bol + *left_p, &m, 0);
                if (!hit || m.rm_so < 0 || m.rm_eo < 0)
                        continue;
                if (earliest < 0 || m.rm_so < earliest)
@@ -800,17 +819,19 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
                opt->show_hunk_mark = 1;
        opt->last_shown = 0;
 
-       if (buffer_is_binary(buf, size)) {
-               switch (opt->binary) {
-               case GREP_BINARY_DEFAULT:
+       switch (opt->binary) {
+       case GREP_BINARY_DEFAULT:
+               if (buffer_is_binary(buf, size))
                        binary_match_only = 1;
-                       break;
-               case GREP_BINARY_NOMATCH:
+               break;
+       case GREP_BINARY_NOMATCH:
+               if (buffer_is_binary(buf, size))
                        return 0; /* Assume unmatch */
-                       break;
-               default:
-                       break;
-               }
+               break;
+       case GREP_BINARY_TEXT:
+               break;
+       default:
+               die("bug: unknown binary handling mode");
        }
 
        memset(&xecfg, 0, sizeof(xecfg));
@@ -871,6 +892,12 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
                        count++;
                        if (opt->status_only)
                                return 1;
+                       if (opt->name_only) {
+                               show_name(opt, name);
+                               return 1;
+                       }
+                       if (opt->count)
+                               goto next_line;
                        if (binary_match_only) {
                                opt->output(opt, "Binary file ", 12);
                                output_color(opt, name, strlen(name),
@@ -878,22 +905,14 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
                                opt->output(opt, " matches\n", 9);
                                return 1;
                        }
-                       if (opt->name_only) {
-                               show_name(opt, name);
-                               return 1;
-                       }
                        /* Hit at this line.  If we haven't shown the
                         * pre-context lines, we would need to show them.
-                        * When asked to do "count", this still show
-                        * the context which is nonsense, but the user
-                        * deserves to get that ;-).
                         */
                        if (opt->pre_context)
                                show_pre_context(opt, name, buf, bol, lno);
                        else if (opt->funcname)
                                show_funcname_line(opt, name, buf, bol, lno);
-                       if (!opt->count)
-                               show_line(opt, bol, eol, name, lno, ':');
+                       show_line(opt, bol, eol, name, lno, ':');
                        last_hit = lno;
                }
                else if (last_hit &&
@@ -937,6 +956,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
                output_sep(opt, ':');
                snprintf(buf, sizeof(buf), "%u\n", count);
                opt->output(opt, buf, strlen(buf));
+               return 1;
        }
        return !!last_hit;
 }
diff --git a/grep.h b/grep.h
index 89342e5b47f6d63dd546e738e4cbf023c447b382..efa8cff980af2b2c06dad080876637d16b5c4985 100644 (file)
--- a/grep.h
+++ b/grep.h
@@ -10,17 +10,17 @@ enum grep_pat_token {
        GREP_OPEN_PAREN,
        GREP_CLOSE_PAREN,
        GREP_NOT,
-       GREP_OR,
+       GREP_OR
 };
 
 enum grep_context {
        GREP_CONTEXT_HEAD,
-       GREP_CONTEXT_BODY,
+       GREP_CONTEXT_BODY
 };
 
 enum grep_header_field {
        GREP_HEADER_AUTHOR = 0,
-       GREP_HEADER_COMMITTER,
+       GREP_HEADER_COMMITTER
 };
 
 struct grep_pat {
@@ -29,6 +29,7 @@ struct grep_pat {
        int no;
        enum grep_pat_token token;
        const char *pattern;
+       size_t patternlen;
        enum grep_header_field field;
        regex_t regexp;
        unsigned fixed:1;
@@ -40,7 +41,7 @@ enum grep_expr_node {
        GREP_NODE_ATOM,
        GREP_NODE_NOT,
        GREP_NODE_AND,
-       GREP_NODE_OR,
+       GREP_NODE_OR
 };
 
 struct grep_expr {
@@ -104,6 +105,7 @@ struct grep_opt {
        void *output_priv;
 };
 
+extern void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
 extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
 extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
 extern void compile_grep_patterns(struct grep_opt *opt);
index d1e83d0906dbc9d677630cdf74615ec3f9dfc46d..14c90c2e84afd9997e1a6453f0065b3f59b32e57 100644 (file)
@@ -6,6 +6,7 @@
 #include "exec_cmd.h"
 #include "run-command.h"
 #include "string-list.h"
+#include "url.h"
 
 static const char content_type[] = "Content-Type";
 static const char content_length[] = "Content-Length";
@@ -25,60 +26,6 @@ static struct rpc_service rpc_service[] = {
        { "receive-pack", "receivepack", -1 },
 };
 
-static int decode_char(const char *q)
-{
-       int i;
-       unsigned char val = 0;
-       for (i = 0; i < 2; i++) {
-               unsigned char c = *q++;
-               val <<= 4;
-               if (c >= '0' && c <= '9')
-                       val += c - '0';
-               else if (c >= 'a' && c <= 'f')
-                       val += c - 'a' + 10;
-               else if (c >= 'A' && c <= 'F')
-                       val += c - 'A' + 10;
-               else
-                       return -1;
-       }
-       return val;
-}
-
-static char *decode_parameter(const char **query, int is_name)
-{
-       const char *q = *query;
-       struct strbuf out;
-
-       strbuf_init(&out, 16);
-       do {
-               unsigned char c = *q;
-
-               if (!c)
-                       break;
-               if (c == '&' || (is_name && c == '=')) {
-                       q++;
-                       break;
-               }
-
-               if (c == '%') {
-                       int val = decode_char(q + 1);
-                       if (0 <= val) {
-                               strbuf_addch(&out, val);
-                               q += 3;
-                               continue;
-                       }
-               }
-
-               if (c == '+')
-                       strbuf_addch(&out, ' ');
-               else
-                       strbuf_addch(&out, c);
-               q++;
-       } while (1);
-       *query = q;
-       return strbuf_detach(&out, NULL);
-}
-
 static struct string_list *get_parameters(void)
 {
        if (!query_params) {
@@ -86,13 +33,13 @@ static struct string_list *get_parameters(void)
 
                query_params = xcalloc(1, sizeof(*query_params));
                while (query && *query) {
-                       char *name = decode_parameter(&query, 1);
-                       char *value = decode_parameter(&query, 0);
+                       char *name = url_decode_parameter_name(&query);
+                       char *value = url_decode_parameter_value(&query);
                        struct string_list_item *i;
 
-                       i = string_list_lookup(name, query_params);
+                       i = string_list_lookup(query_params, name);
                        if (!i)
-                               i = string_list_insert(name, query_params);
+                               i = string_list_insert(query_params, name);
                        else
                                free(i->util);
                        i->util = value;
@@ -104,7 +51,7 @@ static struct string_list *get_parameters(void)
 static const char *get_parameter(const char *name)
 {
        struct string_list_item *i;
-       i = string_list_lookup(name, get_parameters());
+       i = string_list_lookup(get_parameters(), name);
        return i ? i->util : NULL;
 }
 
@@ -541,14 +488,12 @@ static NORETURN void die_webcgi(const char *err, va_list params)
        static int dead;
 
        if (!dead) {
-               char buffer[1000];
                dead = 1;
-
-               vsnprintf(buffer, sizeof(buffer), err, params);
-               fprintf(stderr, "fatal: %s\n", buffer);
                http_status(500, "Internal Server Error");
                hdr_nocache();
                end_headers();
+
+               vreportf("fatal: ", err, params);
        }
        exit(0); /* we successfully reported a failure ;-) */
 }
index 415b1ab0a7f0a98e3a16f82c39bbcc9b04f85ac2..c9bcd116975635cabf30eceb7909abfc7f341948 100644 (file)
@@ -105,7 +105,7 @@ enum transfer_state {
        RUN_PUT,
        RUN_MOVE,
        ABORTED,
-       COMPLETE,
+       COMPLETE
 };
 
 struct transfer_request
index 8ca76d0507bdc1d95283e1f5fee3f88180cdce26..18bd6504beb99ab68f360c4fa93011efae42fdfb 100644 (file)
@@ -15,7 +15,7 @@ enum object_request_state {
        WAITING,
        ABORTED,
        ACTIVE,
-       COMPLETE,
+       COMPLETE
 };
 
 struct object_request
diff --git a/http.h b/http.h
index a0b59015948c3b9736dd6c09fd9137f7ecd4f59a..173f74c8298c3fa3989f88b06e2085127fe96db8 100644 (file)
--- a/http.h
+++ b/http.h
 #endif
 
 #if LIBCURL_VERSION_NUM < 0x070704
-#define curl_global_cleanup() do { /* nothing */ } while(0)
+#define curl_global_cleanup() do { /* nothing */ } while (0)
 #endif
 #if LIBCURL_VERSION_NUM < 0x070800
-#define curl_global_init(a) do { /* nothing */ } while(0)
+#define curl_global_init(a) do { /* nothing */ } while (0)
 #endif
 
 #if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)
index 9d0097ca02960460ff3a104f1739982fee453987..71506a8dd3ed07fe44c487a644ce9a42b94a7578 100644 (file)
@@ -230,7 +230,7 @@ enum CAPABILITY {
        LITERALPLUS,
        NAMESPACE,
        STARTTLS,
-       AUTH_CRAM_MD5,
+       AUTH_CRAM_MD5
 };
 
 static const char *cap_list[] = {
@@ -543,9 +543,13 @@ static struct imap_cmd *v_issue_imap_cmd(struct imap_store *ctx,
        while (imap->literal_pending)
                get_cmd_result(ctx, NULL);
 
-       bufl = nfsnprintf(buf, sizeof(buf), cmd->cb.data ? CAP(LITERALPLUS) ?
-                          "%d %s{%d+}\r\n" : "%d %s{%d}\r\n" : "%d %s\r\n",
-                          cmd->tag, cmd->cmd, cmd->cb.dlen);
+       if (!cmd->cb.data)
+               bufl = nfsnprintf(buf, sizeof(buf), "%d %s\r\n", cmd->tag, cmd->cmd);
+       else
+               bufl = nfsnprintf(buf, sizeof(buf), "%d %s{%d%s}\r\n",
+                                 cmd->tag, cmd->cmd, cmd->cb.dlen,
+                                 CAP(LITERALPLUS) ? "+" : "");
+
        if (Verbose) {
                if (imap->num_in_progress)
                        printf("(%d in progress) ", imap->num_in_progress);
@@ -1086,7 +1090,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
                int gai;
                char portstr[6];
 
-               snprintf(portstr, sizeof(portstr), "%hu", srvc->port);
+               snprintf(portstr, sizeof(portstr), "%d", srvc->port);
 
                memset(&hints, 0, sizeof(hints));
                hints.ai_socktype = SOCK_STREAM;
index f9b3d854a921ab6fa3eed6f4dbf01af1a8657602..3764a1ab72354a3ce643c899c1e8cf5443d4e7cb 100644 (file)
@@ -139,17 +139,17 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
 {
        char temp[4][50];
        struct strbuf cmd = STRBUF_INIT;
-       struct strbuf_expand_dict_entry dict[] = {
-               { "O", temp[0] },
-               { "A", temp[1] },
-               { "B", temp[2] },
-               { "L", temp[3] },
-               { NULL }
-       };
+       struct strbuf_expand_dict_entry dict[5];
        const char *args[] = { NULL, NULL };
        int status, fd, i;
        struct stat st;
 
+       dict[0].placeholder = "O"; dict[0].value = temp[0];
+       dict[1].placeholder = "A"; dict[1].value = temp[1];
+       dict[2].placeholder = "B"; dict[2].value = temp[2];
+       dict[3].placeholder = "L"; dict[3].value = temp[3];
+       dict[4].placeholder = NULL; dict[4].value = NULL;
+
        if (fn->cmdline == NULL)
                die("custom merge driver %s lacks command line.", fn->name);
 
index d3ae969f608b50a469aa60b2e925558a6bb437e5..b46ed3baef7d9d9971a3886d700059217fbe974a 100644 (file)
 #include "reflog-walk.h"
 #include "refs.h"
 #include "string-list.h"
+#include "color.h"
 
 struct decoration name_decoration = { "object names" };
 
-static void add_name_decoration(const char *prefix, const char *name, struct object *obj)
+enum decoration_type {
+       DECORATION_NONE = 0,
+       DECORATION_REF_LOCAL,
+       DECORATION_REF_REMOTE,
+       DECORATION_REF_TAG,
+       DECORATION_REF_STASH,
+       DECORATION_REF_HEAD,
+};
+
+static char decoration_colors[][COLOR_MAXLEN] = {
+       GIT_COLOR_RESET,
+       GIT_COLOR_BOLD_GREEN,   /* REF_LOCAL */
+       GIT_COLOR_BOLD_RED,     /* REF_REMOTE */
+       GIT_COLOR_BOLD_YELLOW,  /* REF_TAG */
+       GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */
+       GIT_COLOR_BOLD_CYAN,    /* REF_HEAD */
+};
+
+static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
+{
+       if (decorate_use_color)
+               return decoration_colors[ix];
+       return "";
+}
+
+static int parse_decorate_color_slot(const char *slot)
+{
+       /*
+        * We're comparing with 'ignore-case' on
+        * (because config.c sets them all tolower),
+        * but let's match the letters in the literal
+        * string values here with how they are
+        * documented in Documentation/config.txt, for
+        * consistency.
+        *
+        * We love being consistent, don't we?
+        */
+       if (!strcasecmp(slot, "branch"))
+               return DECORATION_REF_LOCAL;
+       if (!strcasecmp(slot, "remoteBranch"))
+               return DECORATION_REF_REMOTE;
+       if (!strcasecmp(slot, "tag"))
+               return DECORATION_REF_TAG;
+       if (!strcasecmp(slot, "stash"))
+               return DECORATION_REF_STASH;
+       if (!strcasecmp(slot, "HEAD"))
+               return DECORATION_REF_HEAD;
+       return -1;
+}
+
+int parse_decorate_color_config(const char *var, const int ofs, const char *value)
+{
+       int slot = parse_decorate_color_slot(var + ofs);
+       if (slot < 0)
+               return 0;
+       if (!value)
+               return config_error_nonbool(var);
+       color_parse(value, var, decoration_colors[slot]);
+       return 0;
+}
+
+/*
+ * log-tree.c uses DIFF_OPT_TST for determining whether to use color
+ * 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)
+
+static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
 {
-       int plen = strlen(prefix);
        int nlen = strlen(name);
-       struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen);
-       memcpy(res->name, prefix, plen);
-       memcpy(res->name + plen, name, nlen + 1);
+       struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + nlen);
+       memcpy(res->name, name, nlen + 1);
+       res->type = type;
        res->next = add_decoration(&name_decoration, obj, res);
 }
 
 static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
 {
        struct object *obj = parse_object(sha1);
+       enum decoration_type type = DECORATION_NONE;
        if (!obj)
                return 0;
+
+       if (!prefixcmp(refname, "refs/heads"))
+               type = DECORATION_REF_LOCAL;
+       else if (!prefixcmp(refname, "refs/remotes"))
+               type = DECORATION_REF_REMOTE;
+       else if (!prefixcmp(refname, "refs/tags"))
+               type = DECORATION_REF_TAG;
+       else if (!prefixcmp(refname, "refs/stash"))
+               type = DECORATION_REF_STASH;
+       else if (!prefixcmp(refname, "HEAD"))
+               type = DECORATION_REF_HEAD;
+
        if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
                refname = prettify_refname(refname);
-       add_name_decoration("", refname, obj);
+       add_name_decoration(type, refname, obj);
        while (obj->type == OBJ_TAG) {
                obj = ((struct tag *)obj)->tagged;
                if (!obj)
                        break;
-               add_name_decoration("tag: ", refname, obj);
+               add_name_decoration(DECORATION_REF_TAG, refname, obj);
        }
        return 0;
 }
@@ -60,6 +141,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
 {
        const char *prefix;
        struct name_decoration *decoration;
+       const char *color_commit =
+               diff_get_color_opt(&opt->diffopt, DIFF_COMMIT);
+       const char *color_reset =
+               decorate_get_color_opt(&opt->diffopt, DECORATION_NONE);
 
        if (opt->show_source && commit->util)
                printf("\t%s", (char *) commit->util);
@@ -70,7 +155,14 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
                return;
        prefix = " (";
        while (decoration) {
-               printf("%s%s", prefix, decoration->name);
+               printf("%s", prefix);
+               fputs(decorate_get_color_opt(&opt->diffopt, decoration->type),
+                     stdout);
+               if (decoration->type == DECORATION_REF_TAG)
+                       fputs("tag: ", stdout);
+               printf("%s", decoration->name);
+               fputs(color_reset, stdout);
+               fputs(color_commit, stdout);
                prefix = ", ";
                decoration = decoration->next;
        }
@@ -469,6 +561,12 @@ int log_tree_diff_flush(struct rev_info *opt)
                        int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
                        if ((pch & opt->diffopt.output_format) == pch)
                                printf("---");
+                       if (opt->diffopt.output_prefix) {
+                               struct strbuf *msg = NULL;
+                               msg = opt->diffopt.output_prefix(&opt->diffopt,
+                                       opt->diffopt.output_prefix_data);
+                               fwrite(msg->buf, msg->len, 1, stdout);
+                       }
                        putchar('\n');
                }
        }
index 3f7b40027b7203985f018e43ab72a6cfc233e8d7..5c4cf7cac3327e2ef6000dff414680cd5c4c0e1e 100644 (file)
@@ -7,6 +7,7 @@ struct log_info {
        struct commit *commit, *parent;
 };
 
+int parse_decorate_color_config(const char *var, const int ofs, const char *value);
 void init_log_tree_opt(struct rev_info *);
 int log_tree_diff_flush(struct rev_info *);
 int log_tree_commit(struct rev_info *, struct commit *);
index b68c1fec9c2ca69f313bc3fa16461c6c9150c53d..f80b701292f0d852950735ab20a63dac13e92362 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -69,7 +69,7 @@ static void add_mapping(struct string_list *map,
                index = -1 - index;
        } else {
                /* create mailmap entry */
-               struct string_list_item *item = string_list_insert_at_index(index, old_email, map);
+               struct string_list_item *item = string_list_insert_at_index(map, index, old_email);
                item->util = xmalloc(sizeof(struct mailmap_entry));
                memset(item->util, 0, sizeof(struct mailmap_entry));
                ((struct mailmap_entry *)item->util)->namemap.strdup_strings = 1;
@@ -92,7 +92,7 @@ static void add_mapping(struct string_list *map,
                        mi->name = xstrdup(new_name);
                if (new_email)
                        mi->email = xstrdup(new_email);
-               string_list_insert(old_name, &me->namemap)->util = mi;
+               string_list_insert(&me->namemap, old_name)->util = mi;
        }
 
        debug_mm("mailmap:  '%s' <%s> -> '%s' <%s>\n",
@@ -214,13 +214,13 @@ int map_user(struct string_list *map,
        mailbuf[i] = 0;
 
        debug_mm("map_user: map '%s' <%s>\n", name, mailbuf);
-       item = string_list_lookup(mailbuf, map);
+       item = string_list_lookup(map, mailbuf);
        if (item != NULL) {
                me = (struct mailmap_entry *)item->util;
                if (me->namemap.nr) {
                        /* The item has multiple items, so we'll look up on name too */
                        /* If the name is not found, we choose the simple entry      */
-                       struct string_list_item *subitem = string_list_lookup(name, &me->namemap);
+                       struct string_list_item *subitem = string_list_lookup(&me->namemap, name);
                        if (subitem)
                                item = subitem;
                }
index 206c1036359ce7b1fc5a1f5734b2d0bc2a760d90..fb6aa4a551802de07be76bd838b6f22a236457ff 100644 (file)
@@ -238,9 +238,9 @@ static int save_files_dirs(const unsigned char *sha1,
        newpath[baselen + len] = '\0';
 
        if (S_ISDIR(mode))
-               string_list_insert(newpath, &o->current_directory_set);
+               string_list_insert(&o->current_directory_set, newpath);
        else
-               string_list_insert(newpath, &o->current_file_set);
+               string_list_insert(&o->current_file_set, newpath);
        free(newpath);
 
        return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
@@ -271,7 +271,7 @@ static struct stage_data *insert_stage_data(const char *path,
                        e->stages[2].sha, &e->stages[2].mode);
        get_tree_entry(b->object.sha1, path,
                        e->stages[3].sha, &e->stages[3].mode);
-       item = string_list_insert(path, entries);
+       item = string_list_insert(entries, path);
        item->util = e;
        return e;
 }
@@ -294,9 +294,9 @@ static struct string_list *get_unmerged(void)
                if (!ce_stage(ce))
                        continue;
 
-               item = string_list_lookup(ce->name, unmerged);
+               item = string_list_lookup(unmerged, ce->name);
                if (!item) {
-                       item = string_list_insert(ce->name, unmerged);
+                       item = string_list_insert(unmerged, ce->name);
                        item->util = xcalloc(1, sizeof(struct stage_data));
                }
                e = item->util;
@@ -356,20 +356,20 @@ static struct string_list *get_renames(struct merge_options *o,
                re = xmalloc(sizeof(*re));
                re->processed = 0;
                re->pair = pair;
-               item = string_list_lookup(re->pair->one->path, entries);
+               item = string_list_lookup(entries, re->pair->one->path);
                if (!item)
                        re->src_entry = insert_stage_data(re->pair->one->path,
                                        o_tree, a_tree, b_tree, entries);
                else
                        re->src_entry = item->util;
 
-               item = string_list_lookup(re->pair->two->path, entries);
+               item = string_list_lookup(entries, re->pair->two->path);
                if (!item)
                        re->dst_entry = insert_stage_data(re->pair->two->path,
                                        o_tree, a_tree, b_tree, entries);
                else
                        re->dst_entry = item->util;
-               item = string_list_insert(pair->one->path, renames);
+               item = string_list_insert(renames, pair->one->path);
                item->util = re;
        }
        opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -432,7 +432,7 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
               lstat(newpath, &st) == 0)
                sprintf(p, "_%d", suffix++);
 
-       string_list_insert(newpath, &o->current_file_set);
+       string_list_insert(&o->current_file_set, newpath);
        return newpath;
 }
 
@@ -811,12 +811,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(sre->pair->two->path, &a_by_dst)->util
+               string_list_insert(&a_by_dst, sre->pair->two->path)->util
                        = sre->dst_entry;
        }
        for (i = 0; i < b_renames->nr; i++) {
                sre = b_renames->items[i].util;
-               string_list_insert(sre->pair->two->path, &b_by_dst)->util
+               string_list_insert(&b_by_dst, sre->pair->two->path)->util
                        = sre->dst_entry;
        }
 
@@ -988,7 +988,7 @@ static int process_renames(struct merge_options *o,
                                        output(o, 1, "Adding as %s instead", new_path);
                                        update_file(o, 0, dst_other.sha1, dst_other.mode, new_path);
                                }
-                       } else if ((item = string_list_lookup(ren1_dst, renames2Dst))) {
+                       } else if ((item = string_list_lookup(renames2Dst, ren1_dst))) {
                                ren2 = item->util;
                                clean_merge = 0;
                                ren2->processed = 1;
@@ -1214,7 +1214,7 @@ int merge_trees(struct merge_options *o,
        }
 
        if (sha_eq(common->object.sha1, merge->object.sha1)) {
-               output(o, 0, "Already uptodate!");
+               output(o, 0, "Already up-to-date!");
                *result = head;
                return 1;
        }
index d1192f56d797a1664f5bfb5028d52ad679928e23..b831293b3865ae52584565039e4a893c3c6f45ff 100644 (file)
@@ -10,7 +10,7 @@ struct merge_options {
        enum {
                MERGE_RECURSIVE_NORMAL = 0,
                MERGE_RECURSIVE_OURS,
-               MERGE_RECURSIVE_THEIRS,
+               MERGE_RECURSIVE_THEIRS
        } recursive_variant;
        const char *subtree_shift;
        unsigned buffer_output : 1;
@@ -54,4 +54,7 @@ int merge_recursive_generic(struct merge_options *o,
 void init_merge_options(struct merge_options *o);
 struct tree *write_tree_from_memory(struct merge_options *o);
 
+/* builtin/merge.c */
+int try_merge_command(const char *strategy, struct commit_list *common, const char *head_arg, struct commit_list *remotes);
+
 #endif
diff --git a/notes-cache.c b/notes-cache.c
new file mode 100644 (file)
index 0000000..dee6d62
--- /dev/null
@@ -0,0 +1,94 @@
+#include "cache.h"
+#include "notes-cache.h"
+#include "commit.h"
+#include "refs.h"
+
+static int notes_cache_match_validity(const char *ref, const char *validity)
+{
+       unsigned char sha1[20];
+       struct commit *commit;
+       struct pretty_print_context pretty_ctx;
+       struct strbuf msg = STRBUF_INIT;
+       int ret;
+
+       if (read_ref(ref, sha1) < 0)
+               return 0;
+
+       commit = lookup_commit_reference_gently(sha1, 1);
+       if (!commit)
+               return 0;
+
+       memset(&pretty_ctx, 0, sizeof(pretty_ctx));
+       format_commit_message(commit, "%s", &msg, &pretty_ctx);
+       strbuf_trim(&msg);
+
+       ret = !strcmp(msg.buf, validity);
+       strbuf_release(&msg);
+
+       return ret;
+}
+
+void notes_cache_init(struct notes_cache *c, const char *name,
+                    const char *validity)
+{
+       struct strbuf ref = STRBUF_INIT;
+       int flags = 0;
+
+       memset(c, 0, sizeof(*c));
+       c->validity = xstrdup(validity);
+
+       strbuf_addf(&ref, "refs/notes/%s", name);
+       if (!notes_cache_match_validity(ref.buf, validity))
+               flags = NOTES_INIT_EMPTY;
+       init_notes(&c->tree, ref.buf, combine_notes_overwrite, flags);
+       strbuf_release(&ref);
+}
+
+int notes_cache_write(struct notes_cache *c)
+{
+       unsigned char tree_sha1[20];
+       unsigned char commit_sha1[20];
+
+       if (!c || !c->tree.initialized || !c->tree.ref || !*c->tree.ref)
+               return -1;
+       if (!c->tree.dirty)
+               return 0;
+
+       if (write_notes_tree(&c->tree, tree_sha1))
+               return -1;
+       if (commit_tree(c->validity, tree_sha1, NULL, commit_sha1, NULL) < 0)
+               return -1;
+       if (update_ref("update notes cache", c->tree.ref, commit_sha1, NULL,
+                      0, QUIET_ON_ERR) < 0)
+               return -1;
+
+       return 0;
+}
+
+char *notes_cache_get(struct notes_cache *c, unsigned char key_sha1[20],
+                     size_t *outsize)
+{
+       const unsigned char *value_sha1;
+       enum object_type type;
+       char *value;
+       unsigned long size;
+
+       value_sha1 = get_note(&c->tree, key_sha1);
+       if (!value_sha1)
+               return NULL;
+       value = read_sha1_file(value_sha1, &type, &size);
+
+       *outsize = size;
+       return value;
+}
+
+int notes_cache_put(struct notes_cache *c, unsigned char key_sha1[20],
+                   const char *data, size_t size)
+{
+       unsigned char value_sha1[20];
+
+       if (write_sha1_file(data, size, "blob", value_sha1) < 0)
+               return -1;
+       add_note(&c->tree, key_sha1, value_sha1, NULL);
+       return 0;
+}
diff --git a/notes-cache.h b/notes-cache.h
new file mode 100644 (file)
index 0000000..356f88f
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef NOTES_CACHE_H
+#define NOTES_CACHE_H
+
+#include "notes.h"
+
+struct notes_cache {
+       struct notes_tree tree;
+       char *validity;
+};
+
+void notes_cache_init(struct notes_cache *c, const char *name,
+                    const char *validity);
+int notes_cache_write(struct notes_cache *c);
+
+char *notes_cache_get(struct notes_cache *c, unsigned char sha1[20], size_t
+                     *outsize);
+int notes_cache_put(struct notes_cache *c, unsigned char sha1[20],
+                   const char *data, size_t size);
+
+#endif /* NOTES_CACHE_H */
diff --git a/notes.c b/notes.c
index cc92cf351a5d8abb7ad2890660d484644c359dfb..197824439826881fc0de3275353ec1b74d86cfa3 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -838,7 +838,7 @@ static int string_list_add_one_ref(const char *path, const unsigned char *sha1,
 {
        struct string_list *refs = cb;
        if (!unsorted_string_list_has_string(refs, path))
-               string_list_append(path, refs);
+               string_list_append(refs, path);
        return 0;
 }
 
@@ -851,7 +851,7 @@ void string_list_add_refs_by_glob(struct string_list *list, const char *glob)
                if (get_sha1(glob, sha1))
                        warning("notes ref %s is invalid", glob);
                if (!unsorted_string_list_has_string(list, glob))
-                       string_list_append(glob, list);
+                       string_list_append(list, glob);
        }
 }
 
@@ -969,7 +969,7 @@ struct notes_tree **load_notes_trees(struct string_list *refs)
        trees = xmalloc((refs->nr+1) * sizeof(struct notes_tree *));
        cb_data.counter = 0;
        cb_data.trees = trees;
-       for_each_string_list(load_one_display_note_ref, refs, &cb_data);
+       for_each_string_list(refs, load_one_display_note_ref, &cb_data);
        trees[cb_data.counter] = NULL;
        return trees;
 }
@@ -983,7 +983,7 @@ void init_display_notes(struct display_notes_opt *opt)
        assert(!display_notes_trees);
 
        if (!opt || !opt->suppress_default_notes) {
-               string_list_append(default_notes_ref(), &display_notes_refs);
+               string_list_append(&display_notes_refs, default_notes_ref());
                display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
                if (display_ref_env) {
                        string_list_add_refs_from_colon_sep(&display_notes_refs,
@@ -996,8 +996,8 @@ void init_display_notes(struct display_notes_opt *opt)
        git_config(notes_display_config, &load_config_refs);
 
        if (opt && opt->extra_notes_refs)
-               for_each_string_list(string_list_add_refs_from_list,
-                                    opt->extra_notes_refs,
+               for_each_string_list(opt->extra_notes_refs,
+                                    string_list_add_refs_from_list,
                                     &display_notes_refs);
 
        display_notes_trees = load_notes_trees(&display_notes_refs);
@@ -1083,7 +1083,7 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result)
        return ret;
 }
 
-void prune_notes(struct notes_tree *t)
+void prune_notes(struct notes_tree *t, int flags)
 {
        struct note_delete_list *l = NULL;
 
@@ -1094,7 +1094,10 @@ void prune_notes(struct notes_tree *t)
        for_each_note(t, 0, prune_notes_helper, &l);
 
        while (l) {
-               remove_note(t, l->sha1);
+               if (flags & NOTES_PRUNE_VERBOSE)
+                       printf("%s\n", sha1_to_hex(l->sha1));
+               if (!(flags & NOTES_PRUNE_DRYRUN))
+                       remove_note(t, l->sha1);
                l = l->next;
        }
 }
diff --git a/notes.h b/notes.h
index 109bc8f78236d8067568e524ffaf4ae21ee6c027..65fc3a66b2f575dd078cc390e7f5ea5cbebffc96 100644 (file)
--- a/notes.h
+++ b/notes.h
@@ -171,6 +171,9 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
  */
 int write_notes_tree(struct notes_tree *t, unsigned char *result);
 
+/* Flags controlling the operation of prune */
+#define NOTES_PRUNE_VERBOSE 1
+#define NOTES_PRUNE_DRYRUN 2
 /*
  * Remove all notes annotating non-existing objects from the given notes tree
  *
@@ -181,7 +184,7 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result);
  * structure are not persistent until a subsequent call to write_notes_tree()
  * returns zero.
  */
-void prune_notes(struct notes_tree *t);
+void prune_notes(struct notes_tree *t, int flags);
 
 /*
  * Free (and de-initialize) the given notes_tree structure
index 277b3ddba7dc5387cd97cb35c23d3358727898be..2eda53cc6144430f5fcf4b93e80fac9b9e147bfd 100644 (file)
--- a/object.c
+++ b/object.c
@@ -211,10 +211,10 @@ struct object_list *object_list_insert(struct object *item,
                                       struct object_list **list_p)
 {
        struct object_list *new_list = xmalloc(sizeof(struct object_list));
-        new_list->item = item;
-        new_list->next = *list_p;
-        *list_p = new_list;
-        return new_list;
+       new_list->item = item;
+       new_list->next = *list_p;
+       *list_p = new_list;
+       return new_list;
 }
 
 int object_list_contains(struct object_list *list, struct object *obj)
index 395fb9527a3bc6dd8ca648233911a1c35604440d..9d0cb9a114cb3e5b0a4a4a132b9289ef18d8ae21 100644 (file)
@@ -77,7 +77,7 @@ static int verify_packfile(struct packed_git *p,
                err = error("%s SHA1 checksum mismatch",
                            p->pack_name);
        if (hashcmp(index_base + index_size - 40, pack_sig))
-               err = error("%s SHA1 does not match its inddex",
+               err = error("%s SHA1 does not match its index",
                            p->pack_name);
        unuse_pack(w_curs);
 
index 7f43f8ac3398fb2dbe393f08811989b0a8d4e2dd..1290570260d184b9c94fdab62650d6e474b365b4 100644 (file)
@@ -60,6 +60,37 @@ static int handle_one_ref(const char *path, const unsigned char *sha1,
        return 0;
 }
 
+/*
+ * Remove empty parents, but spare refs/ and immediate subdirs.
+ * Note: munges *name.
+ */
+static void try_remove_empty_parents(char *name)
+{
+       char *p, *q;
+       int i;
+       p = name;
+       for (i = 0; i < 2; i++) { /* refs/{heads,tags,...}/ */
+               while (*p && *p != '/')
+                       p++;
+               /* tolerate duplicate slashes; see check_ref_format() */
+               while (*p == '/')
+                       p++;
+       }
+       for (q = p; *q; q++)
+               ;
+       while (1) {
+               while (q > p && *q != '/')
+                       q--;
+               while (q > p && *(q-1) == '/')
+                       q--;
+               if (q == p)
+                       break;
+               *q = '\0';
+               if (rmdir(git_path("%s", name)))
+                       break;
+       }
+}
+
 /* make sure nobody touched the ref, and unlink */
 static void prune_ref(struct ref_to_prune *r)
 {
@@ -68,6 +99,7 @@ static void prune_ref(struct ref_to_prune *r)
        if (lock) {
                unlink_or_warn(git_path("%s", r->name));
                unlock_ref(lock);
+               try_remove_empty_parents(r->name);
        }
 }
 
index 8546d8526f311e2a2703c258a4da3f02f8650df4..0fa79bc31d322e2aab8fce738ca6489a35a51ca4 100644 (file)
@@ -4,8 +4,9 @@
 #include "commit.h"
 #include "color.h"
 
-static int parse_options_usage(const char * const *usagestr,
-                              const struct option *opts);
+static int parse_options_usage(struct parse_opt_ctx_t *ctx,
+                              const char * const *usagestr,
+                              const struct option *opts, int err);
 
 #define OPT_SHORT 1
 #define OPT_UNSET 2
@@ -351,8 +352,9 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
                die("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together");
 }
 
-static int usage_with_options_internal(const char * const *,
-                                      const struct option *, int);
+static int usage_with_options_internal(struct parse_opt_ctx_t *,
+                                      const char * const *,
+                                      const struct option *, int, int);
 
 int parse_options_step(struct parse_opt_ctx_t *ctx,
                       const struct option *options,
@@ -380,10 +382,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
                if (arg[1] != '-') {
                        ctx->opt = arg + 1;
                        if (internal_help && *ctx->opt == 'h')
-                               return parse_options_usage(usagestr, options);
+                               return parse_options_usage(ctx, usagestr, options, 0);
                        switch (parse_short_opt(ctx, options)) {
                        case -1:
-                               return parse_options_usage(usagestr, options);
+                               return parse_options_usage(ctx, usagestr, options, 1);
                        case -2:
                                goto unknown;
                        }
@@ -391,10 +393,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
                                check_typos(arg + 1, options);
                        while (ctx->opt) {
                                if (internal_help && *ctx->opt == 'h')
-                                       return parse_options_usage(usagestr, options);
+                                       return parse_options_usage(ctx, usagestr, options, 0);
                                switch (parse_short_opt(ctx, options)) {
                                case -1:
-                                       return parse_options_usage(usagestr, options);
+                                       return parse_options_usage(ctx, usagestr, options, 1);
                                case -2:
                                        /* fake a short option thing to hide the fact that we may have
                                         * started to parse aggregated stuff
@@ -418,12 +420,12 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
                }
 
                if (internal_help && !strcmp(arg + 2, "help-all"))
-                       return usage_with_options_internal(usagestr, options, 1);
+                       return usage_with_options_internal(ctx, usagestr, options, 1, 0);
                if (internal_help && !strcmp(arg + 2, "help"))
-                       return parse_options_usage(usagestr, options);
+                       return parse_options_usage(ctx, usagestr, options, 0);
                switch (parse_long_opt(ctx, arg + 2, options)) {
                case -1:
-                       return parse_options_usage(usagestr, options);
+                       return parse_options_usage(ctx, usagestr, options, 1);
                case -2:
                        goto unknown;
                }
@@ -468,7 +470,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
        return parse_options_end(&ctx);
 }
 
-static int usage_argh(const struct option *opts)
+static int usage_argh(const struct option *opts, FILE *outfile)
 {
        const char *s;
        int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh;
@@ -479,72 +481,81 @@ static int usage_argh(const struct option *opts)
                        s = literal ? "[%s]" : "[<%s>]";
        else
                s = literal ? " %s" : " <%s>";
-       return fprintf(stderr, s, opts->argh ? opts->argh : "...");
+       return fprintf(outfile, s, opts->argh ? opts->argh : "...");
 }
 
 #define USAGE_OPTS_WIDTH 24
 #define USAGE_GAP         2
 
-static int usage_with_options_internal(const char * const *usagestr,
-                               const struct option *opts, int full)
+static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
+                                      const char * const *usagestr,
+                                      const struct option *opts, int full, int err)
 {
+       FILE *outfile = err ? stderr : stdout;
+
        if (!usagestr)
                return PARSE_OPT_HELP;
 
-       fprintf(stderr, "usage: %s\n", *usagestr++);
+       if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL)
+               fprintf(outfile, "cat <<\\EOF\n");
+
+       fprintf(outfile, "usage: %s\n", *usagestr++);
        while (*usagestr && **usagestr)
-               fprintf(stderr, "   or: %s\n", *usagestr++);
+               fprintf(outfile, "   or: %s\n", *usagestr++);
        while (*usagestr) {
-               fprintf(stderr, "%s%s\n",
+               fprintf(outfile, "%s%s\n",
                                **usagestr ? "    " : "",
                                *usagestr);
                usagestr++;
        }
 
        if (opts->type != OPTION_GROUP)
-               fputc('\n', stderr);
+               fputc('\n', outfile);
 
        for (; opts->type != OPTION_END; opts++) {
                size_t pos;
                int pad;
 
                if (opts->type == OPTION_GROUP) {
-                       fputc('\n', stderr);
+                       fputc('\n', outfile);
                        if (*opts->help)
-                               fprintf(stderr, "%s\n", opts->help);
+                               fprintf(outfile, "%s\n", opts->help);
                        continue;
                }
                if (!full && (opts->flags & PARSE_OPT_HIDDEN))
                        continue;
 
-               pos = fprintf(stderr, "    ");
+               pos = fprintf(outfile, "    ");
                if (opts->short_name && !(opts->flags & PARSE_OPT_NEGHELP)) {
                        if (opts->flags & PARSE_OPT_NODASH)
-                               pos += fprintf(stderr, "%c", opts->short_name);
+                               pos += fprintf(outfile, "%c", opts->short_name);
                        else
-                               pos += fprintf(stderr, "-%c", opts->short_name);
+                               pos += fprintf(outfile, "-%c", opts->short_name);
                }
                if (opts->long_name && opts->short_name)
-                       pos += fprintf(stderr, ", ");
+                       pos += fprintf(outfile, ", ");
                if (opts->long_name)
-                       pos += fprintf(stderr, "--%s%s",
+                       pos += fprintf(outfile, "--%s%s",
                                (opts->flags & PARSE_OPT_NEGHELP) ?  "no-" : "",
                                opts->long_name);
                if (opts->type == OPTION_NUMBER)
-                       pos += fprintf(stderr, "-NUM");
+                       pos += fprintf(outfile, "-NUM");
 
                if (!(opts->flags & PARSE_OPT_NOARG))
-                       pos += usage_argh(opts);
+                       pos += usage_argh(opts, outfile);
 
                if (pos <= USAGE_OPTS_WIDTH)
                        pad = USAGE_OPTS_WIDTH - pos;
                else {
-                       fputc('\n', stderr);
+                       fputc('\n', outfile);
                        pad = USAGE_OPTS_WIDTH;
                }
-               fprintf(stderr, "%*s%s\n", pad + USAGE_GAP, "", opts->help);
+               fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", opts->help);
        }
-       fputc('\n', stderr);
+       fputc('\n', outfile);
+
+       if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL)
+               fputs("EOF\n", outfile);
 
        return PARSE_OPT_HELP;
 }
@@ -552,7 +563,7 @@ static int usage_with_options_internal(const char * const *usagestr,
 void usage_with_options(const char * const *usagestr,
                        const struct option *opts)
 {
-       usage_with_options_internal(usagestr, opts, 0);
+       usage_with_options_internal(NULL, usagestr, opts, 0, 1);
        exit(129);
 }
 
@@ -564,10 +575,11 @@ void usage_msg_opt(const char *msg,
        usage_with_options(usagestr, options);
 }
 
-static int parse_options_usage(const char * const *usagestr,
-                              const struct option *opts)
+static int parse_options_usage(struct parse_opt_ctx_t *ctx,
+                              const char * const *usagestr,
+                              const struct option *opts, int err)
 {
-       return usage_with_options_internal(usagestr, opts, 0);
+       return usage_with_options_internal(ctx, usagestr, opts, 0, err);
 }
 
 
index 7581e931da13151473739036a89d9d19303eb18b..d982f0f1bf181f00f54861eb768504007490e95d 100644 (file)
@@ -25,7 +25,7 @@ enum parse_opt_flags {
        PARSE_OPT_STOP_AT_NON_OPTION = 2,
        PARSE_OPT_KEEP_ARGV0 = 4,
        PARSE_OPT_KEEP_UNKNOWN = 8,
-       PARSE_OPT_NO_INTERNAL_HELP = 16,
+       PARSE_OPT_NO_INTERNAL_HELP = 16
 };
 
 enum parse_opt_option_flags {
@@ -37,6 +37,7 @@ enum parse_opt_option_flags {
        PARSE_OPT_NODASH = 32,
        PARSE_OPT_LITERAL_ARGHELP = 64,
        PARSE_OPT_NEGHELP = 128,
+       PARSE_OPT_SHELL_EVAL = 256
 };
 
 struct option;
@@ -68,7 +69,7 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
  * `flags`::
  *   mask of parse_opt_option_flags.
  *   PARSE_OPT_OPTARG: says that the argument is optional (not for BOOLEANs)
- *   PARSE_OPT_NOARG: says that this option takes no argument
+ *   PARSE_OPT_NOARG: says that this option does not take an argument
  *   PARSE_OPT_NONEG: says that this option cannot be negated
  *   PARSE_OPT_HIDDEN: this option is skipped in the default usage, and
  *                     shown only in the full usage.
@@ -160,7 +161,7 @@ extern NORETURN void usage_msg_opt(const char *msg,
 enum {
        PARSE_OPT_HELP = -1,
        PARSE_OPT_DONE,
-       PARSE_OPT_UNKNOWN,
+       PARSE_OPT_UNKNOWN
 };
 
 /*
index 2777d30224618fb0ec823961c3c35ede1ac4e2e5..f85444b27d4815547f7cef542291b1f6616f77d5 100644 (file)
--- a/pretty.c
+++ b/pretty.c
 #include "reflog-walk.h"
 
 static char *user_format;
+static struct cmt_fmt_map {
+       const char *name;
+       enum cmit_fmt format;
+       int is_tformat;
+       int is_alias;
+       const char *user_format;
+} *commit_formats;
+static size_t builtin_formats_len;
+static size_t commit_formats_len;
+static size_t commit_formats_alloc;
+static struct cmt_fmt_map *find_commit_format(const char *sought);
 
 static void save_user_format(struct rev_info *rev, const char *cp, int is_tformat)
 {
@@ -21,22 +32,118 @@ static void save_user_format(struct rev_info *rev, const char *cp, int is_tforma
        rev->commit_format = CMIT_FMT_USERFORMAT;
 }
 
-void get_commit_format(const char *arg, struct rev_info *rev)
+static int git_pretty_formats_config(const char *var, const char *value, void *cb)
 {
+       struct cmt_fmt_map *commit_format = NULL;
+       const char *name;
+       const char *fmt;
        int i;
-       static struct cmt_fmt_map {
-               const char *n;
-               size_t cmp_len;
-               enum cmit_fmt v;
-       } cmt_fmts[] = {
-               { "raw",        1,      CMIT_FMT_RAW },
-               { "medium",     1,      CMIT_FMT_MEDIUM },
-               { "short",      1,      CMIT_FMT_SHORT },
-               { "email",      1,      CMIT_FMT_EMAIL },
-               { "full",       5,      CMIT_FMT_FULL },
-               { "fuller",     5,      CMIT_FMT_FULLER },
-               { "oneline",    1,      CMIT_FMT_ONELINE },
+
+       if (prefixcmp(var, "pretty."))
+               return 0;
+
+       name = var + strlen("pretty.");
+       for (i = 0; i < builtin_formats_len; i++) {
+               if (!strcmp(commit_formats[i].name, name))
+                       return 0;
+       }
+
+       for (i = builtin_formats_len; i < commit_formats_len; i++) {
+               if (!strcmp(commit_formats[i].name, name)) {
+                       commit_format = &commit_formats[i];
+                       break;
+               }
+       }
+
+       if (!commit_format) {
+               ALLOC_GROW(commit_formats, commit_formats_len+1,
+                          commit_formats_alloc);
+               commit_format = &commit_formats[commit_formats_len];
+               memset(commit_format, 0, sizeof(*commit_format));
+               commit_formats_len++;
+       }
+
+       commit_format->name = xstrdup(name);
+       commit_format->format = CMIT_FMT_USERFORMAT;
+       git_config_string(&fmt, var, value);
+       if (!prefixcmp(fmt, "format:") || !prefixcmp(fmt, "tformat:")) {
+               commit_format->is_tformat = fmt[0] == 't';
+               fmt = strchr(fmt, ':') + 1;
+       } else if (strchr(fmt, '%'))
+               commit_format->is_tformat = 1;
+       else
+               commit_format->is_alias = 1;
+       commit_format->user_format = fmt;
+
+       return 0;
+}
+
+static void setup_commit_formats(void)
+{
+       struct cmt_fmt_map builtin_formats[] = {
+               { "raw",        CMIT_FMT_RAW,           0 },
+               { "medium",     CMIT_FMT_MEDIUM,        0 },
+               { "short",      CMIT_FMT_SHORT,         0 },
+               { "email",      CMIT_FMT_EMAIL,         0 },
+               { "fuller",     CMIT_FMT_FULLER,        0 },
+               { "full",       CMIT_FMT_FULL,          0 },
+               { "oneline",    CMIT_FMT_ONELINE,       1 }
        };
+       commit_formats_len = ARRAY_SIZE(builtin_formats);
+       builtin_formats_len = commit_formats_len;
+       ALLOC_GROW(commit_formats, commit_formats_len, commit_formats_alloc);
+       memcpy(commit_formats, builtin_formats,
+              sizeof(*builtin_formats)*ARRAY_SIZE(builtin_formats));
+
+       git_config(git_pretty_formats_config, NULL);
+}
+
+static struct cmt_fmt_map *find_commit_format_recursive(const char *sought,
+                                                       const char *original,
+                                                       int num_redirections)
+{
+       struct cmt_fmt_map *found = NULL;
+       size_t found_match_len = 0;
+       int i;
+
+       if (num_redirections >= commit_formats_len)
+               die("invalid --pretty format: "
+                   "'%s' references an alias which points to itself",
+                   original);
+
+       for (i = 0; i < commit_formats_len; i++) {
+               size_t match_len;
+
+               if (prefixcmp(commit_formats[i].name, sought))
+                       continue;
+
+               match_len = strlen(commit_formats[i].name);
+               if (found == NULL || found_match_len > match_len) {
+                       found = &commit_formats[i];
+                       found_match_len = match_len;
+               }
+       }
+
+       if (found && found->is_alias) {
+               found = find_commit_format_recursive(found->user_format,
+                                                    original,
+                                                    num_redirections+1);
+       }
+
+       return found;
+}
+
+static struct cmt_fmt_map *find_commit_format(const char *sought)
+{
+       if (!commit_formats)
+               setup_commit_formats();
+
+       return find_commit_format_recursive(sought, sought, 0);
+}
+
+void get_commit_format(const char *arg, struct rev_info *rev)
+{
+       struct cmt_fmt_map *commit_format;
 
        rev->use_terminator = 0;
        if (!arg || !*arg) {
@@ -47,21 +154,22 @@ void get_commit_format(const char *arg, struct rev_info *rev)
                save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't');
                return;
        }
-       for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {
-               if (!strncmp(arg, cmt_fmts[i].n, cmt_fmts[i].cmp_len) &&
-                   !strncmp(arg, cmt_fmts[i].n, strlen(arg))) {
-                       if (cmt_fmts[i].v == CMIT_FMT_ONELINE)
-                               rev->use_terminator = 1;
-                       rev->commit_format = cmt_fmts[i].v;
-                       return;
-               }
-       }
+
        if (strchr(arg, '%')) {
                save_user_format(rev, arg, 1);
                return;
        }
 
-       die("invalid --pretty format: %s", arg);
+       commit_format = find_commit_format(arg);
+       if (!commit_format)
+               die("invalid --pretty format: %s", arg);
+
+       rev->commit_format = commit_format->format;
+       rev->use_terminator = commit_format->is_tformat;
+       if (commit_format->format == CMIT_FMT_USERFORMAT) {
+               save_user_format(rev, commit_format->user_format,
+                                commit_format->is_tformat);
+       }
 }
 
 /*
@@ -801,6 +909,10 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
        case 'e':       /* encoding */
                strbuf_add(sb, msg + c->encoding.off, c->encoding.len);
                return 1;
+       case 'B':       /* raw body */
+               /* message_off is always left at the initial newline */
+               strbuf_addstr(sb, msg + c->message_off + 1);
+               return 1;
        }
 
        /* Now we need to parse the commit message. */
@@ -830,6 +942,7 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
                NO_MAGIC,
                ADD_LF_BEFORE_NON_EMPTY,
                DEL_LF_BEFORE_EMPTY,
+               ADD_SP_BEFORE_NON_EMPTY
        } magic = NO_MAGIC;
 
        switch (placeholder[0]) {
@@ -839,6 +952,9 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
        case '+':
                magic = ADD_LF_BEFORE_NON_EMPTY;
                break;
+       case ' ':
+               magic = ADD_SP_BEFORE_NON_EMPTY;
+               break;
        default:
                break;
        }
@@ -853,8 +969,11 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
        if ((orig_len == sb->len) && magic == DEL_LF_BEFORE_EMPTY) {
                while (sb->len && sb->buf[sb->len - 1] == '\n')
                        strbuf_setlen(sb, sb->len - 1);
-       } else if ((orig_len != sb->len) && magic == ADD_LF_BEFORE_NON_EMPTY) {
-               strbuf_insert(sb, orig_len, "\n", 1);
+       } else if (orig_len != sb->len) {
+               if (magic == ADD_LF_BEFORE_NON_EMPTY)
+                       strbuf_insert(sb, orig_len, "\n", 1);
+               else if (magic == ADD_SP_BEFORE_NON_EMPTY)
+                       strbuf_insert(sb, orig_len, " ", 1);
        }
        return consumed + 1;
 }
@@ -864,7 +983,7 @@ static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
 {
        struct userformat_want *w = context;
 
-       if (*placeholder == '+' || *placeholder == '-')
+       if (*placeholder == '+' || *placeholder == '-' || *placeholder == ' ')
                placeholder++;
 
        switch (*placeholder) {
index f1f789b7b87643245f1772d15b3f1cb321af324c..1f42473e8070a05ada8c56b0d60537227a5223ec 100644 (file)
@@ -1516,6 +1516,7 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
        int size = ondisk_ce_size(ce);
        struct ondisk_cache_entry *ondisk = xcalloc(1, size);
        char *name;
+       int result;
 
        ondisk->ctime.sec = htonl(ce->ce_ctime.sec);
        ondisk->mtime.sec = htonl(ce->ce_mtime.sec);
@@ -1539,7 +1540,9 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
                name = ondisk->name;
        memcpy(name, ce->name, ce_namelen(ce));
 
-       return ce_write(c, fd, ondisk, size);
+       result = ce_write(c, fd, ondisk, size);
+       free(ondisk);
+       return result;
 }
 
 int write_index(struct index_state *istate, int newfd)
index caba4f743f2dcc1cf7046cec294f242b2af19052..4879615cad7527dc5346cd1a85bd56b9d11e052b 100644 (file)
@@ -162,7 +162,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
        } else
                recno = 0;
 
-       item = string_list_lookup(branch, &info->complete_reflogs);
+       item = string_list_lookup(&info->complete_reflogs, branch);
        if (item)
                reflogs = item->util;
        else {
@@ -190,7 +190,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
                }
                if (!reflogs || reflogs->nr == 0)
                        return -1;
-               string_list_insert(branch, &info->complete_reflogs)->util
+               string_list_insert(&info->complete_reflogs, branch)->util
                        = reflogs;
        }
 
diff --git a/refs.c b/refs.c
index d6307ae29c14d73654039bf8a92483302f4e3e15..b5400674d7a1fcf4cc16dd630b8671b2ad7b9f7b 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -314,7 +314,11 @@ static int warn_if_dangling_symref(const char *refname, const unsigned char *sha
 
 void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
 {
-       struct warn_if_dangling_data data = { fp, refname, msg_fmt };
+       struct warn_if_dangling_data data;
+
+       data.fp = fp;
+       data.refname = refname;
+       data.msg_fmt = msg_fmt;
        for_each_rawref(warn_if_dangling_symref, &data);
 }
 
@@ -1267,52 +1271,65 @@ static int copy_msg(char *buf, const char *msg)
        return cp - buf;
 }
 
-static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
-                        const unsigned char *new_sha1, const char *msg)
+int log_ref_setup(const char *ref_name, char *logfile, int bufsize)
 {
-       int logfd, written, oflags = O_APPEND | O_WRONLY;
-       unsigned maxlen, len;
-       int msglen;
-       char log_file[PATH_MAX];
-       char *logrec;
-       const char *committer;
-
-       if (log_all_ref_updates < 0)
-               log_all_ref_updates = !is_bare_repository();
-
-       git_snpath(log_file, sizeof(log_file), "logs/%s", ref_name);
+       int logfd, oflags = O_APPEND | O_WRONLY;
 
+       git_snpath(logfile, bufsize, "logs/%s", ref_name);
        if (log_all_ref_updates &&
            (!prefixcmp(ref_name, "refs/heads/") ||
             !prefixcmp(ref_name, "refs/remotes/") ||
             !prefixcmp(ref_name, "refs/notes/") ||
             !strcmp(ref_name, "HEAD"))) {
-               if (safe_create_leading_directories(log_file) < 0)
+               if (safe_create_leading_directories(logfile) < 0)
                        return error("unable to create directory for %s",
-                                    log_file);
+                                    logfile);
                oflags |= O_CREAT;
        }
 
-       logfd = open(log_file, oflags, 0666);
+       logfd = open(logfile, oflags, 0666);
        if (logfd < 0) {
                if (!(oflags & O_CREAT) && errno == ENOENT)
                        return 0;
 
                if ((oflags & O_CREAT) && errno == EISDIR) {
-                       if (remove_empty_directories(log_file)) {
+                       if (remove_empty_directories(logfile)) {
                                return error("There are still logs under '%s'",
-                                            log_file);
+                                            logfile);
                        }
-                       logfd = open(log_file, oflags, 0666);
+                       logfd = open(logfile, oflags, 0666);
                }
 
                if (logfd < 0)
                        return error("Unable to append to %s: %s",
-                                    log_file, strerror(errno));
+                                    logfile, strerror(errno));
        }
 
-       adjust_shared_perm(log_file);
+       adjust_shared_perm(logfile);
+       close(logfd);
+       return 0;
+}
+
+static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
+                        const unsigned char *new_sha1, const char *msg)
+{
+       int logfd, result, written, oflags = O_APPEND | O_WRONLY;
+       unsigned maxlen, len;
+       int msglen;
+       char log_file[PATH_MAX];
+       char *logrec;
+       const char *committer;
+
+       if (log_all_ref_updates < 0)
+               log_all_ref_updates = !is_bare_repository();
 
+       result = log_ref_setup(ref_name, log_file, sizeof(log_file));
+       if (result)
+               return result;
+
+       logfd = open(log_file, oflags);
+       if (logfd < 0)
+               return 0;
        msglen = msg ? strlen(msg) : 0;
        committer = git_committer_info(0);
        maxlen = strlen(committer) + msglen + 100;
diff --git a/refs.h b/refs.h
index 4a18b083f52a15e5216d583644e590d666cae097..762ce504b5eba3aacff204321a7c41db2b1e6053 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -68,6 +68,9 @@ extern void unlock_ref(struct ref_lock *lock);
 /** Writes sha1 into the ref specified by the lock. **/
 extern int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1, const char *msg);
 
+/** Setup reflog before using. **/
+int log_ref_setup(const char *ref_name, char *logfile, int bufsize);
+
 /** Reads log for the value of ref during at_time. **/
 extern int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
 
index 24fbb9a9b972c1078b3688b2d0683c9704e09ee6..04d4813e4183c675b54aba942cd078d8ff632053 100644 (file)
@@ -528,11 +528,12 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
                rpc->len = n;
                err |= post_rpc(rpc);
        }
-       strbuf_read(&rpc->result, client.out, 0);
 
        close(client.in);
-       close(client.out);
        client.in = -1;
+       strbuf_read(&rpc->result, client.out, 0);
+
+       close(client.out);
        client.out = -1;
 
        err |= finish_command(&client);
index 26ce56046dd14fec4ae59c7e7df3c2072178c51d..afbba47460c0204721d61800033ed0a9f93f92bc 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -443,6 +443,8 @@ static int handle_config(const char *key, const char *value, void *cb)
        } else if (!strcmp(subkey, ".tagopt")) {
                if (!strcmp(value, "--no-tags"))
                        remote->fetch_tags = -1;
+               else if (!strcmp(value, "--tags"))
+                       remote->fetch_tags = 2;
        } else if (!strcmp(subkey, ".proxy")) {
                return git_config_string((const char **)&remote->http_proxy,
                                         key, value);
@@ -657,10 +659,9 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
 
 int valid_fetch_refspec(const char *fetch_refspec_str)
 {
-       const char *fetch_refspec[] = { fetch_refspec_str };
        struct refspec *refspec;
 
-       refspec = parse_refspec_internal(1, fetch_refspec, 1, 1);
+       refspec = parse_refspec_internal(1, &fetch_refspec_str, 1, 1);
        free_refspecs(refspec, 1);
        return !!refspec;
 }
@@ -761,7 +762,7 @@ void ref_remove_duplicates(struct ref *ref_map)
                if (!ref_map->peer_ref)
                        continue;
 
-               item = string_list_lookup(ref_map->peer_ref->name, &refs);
+               item = string_list_lookup(&refs, ref_map->peer_ref->name);
                if (item) {
                        if (strcmp(((struct ref *)item->util)->name,
                                   ref_map->name))
@@ -776,7 +777,7 @@ void ref_remove_duplicates(struct ref *ref_map)
                        continue;
                }
 
-               item = string_list_insert(ref_map->peer_ref->name, &refs);
+               item = string_list_insert(&refs, ref_map->peer_ref->name);
                item->util = ref_map;
        }
        string_list_clear(&refs, 0);
@@ -1709,7 +1710,7 @@ struct ref *get_stale_heads(struct remote *remote, struct ref *fetch_map)
        info.ref_names = &ref_names;
        info.stale_refs_tail = &stale_refs;
        for (ref = fetch_map; ref; ref = ref->next)
-               string_list_append(ref->name, &ref_names);
+               string_list_append(&ref_names, ref->name);
        sort_string_list(&ref_names);
        for_each_ref(get_stale_heads_cb, &info);
        string_list_clear(&ref_names, 0);
index 6e13643cabb6fa9a5b619f53dd148345d9161ad4..888d7c15de2eacc56d869a96d4463aefca7a7a06 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -145,7 +145,7 @@ int branch_merge_matches(struct branch *, int n, const char *);
 enum match_refs_flags {
        MATCH_REFS_NONE         = 0,
        MATCH_REFS_ALL          = (1 << 0),
-       MATCH_REFS_MIRROR       = (1 << 1),
+       MATCH_REFS_MIRROR       = (1 << 1)
 };
 
 /* Reporting of tracking info */
index f221bed1e97a0f1b41d1845edac270a109e3a4dd..1d951617ee2f92676a6e3ff4b809b716481a7847 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -46,7 +46,7 @@ static void read_rr(struct string_list *rr)
                        ; /* do nothing */
                if (i == sizeof(buf))
                        die("filename too long");
-               string_list_insert(buf, rr)->util = name;
+               string_list_insert(rr, buf)->util = name;
        }
        fclose(in);
 }
@@ -153,7 +153,7 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz
        git_SHA_CTX ctx;
        int hunk_no = 0;
        enum {
-               RR_CONTEXT = 0, RR_SIDE_1, RR_SIDE_2, RR_ORIGINAL,
+               RR_CONTEXT = 0, RR_SIDE_1, RR_SIDE_2, RR_ORIGINAL
        } hunk = RR_CONTEXT;
        struct strbuf one = STRBUF_INIT, two = STRBUF_INIT;
        struct strbuf buf = STRBUF_INIT;
@@ -354,7 +354,7 @@ static int find_conflict(struct string_list *conflict)
                    ce_same_name(e2, e3) &&
                    S_ISREG(e2->ce_mode) &&
                    S_ISREG(e3->ce_mode)) {
-                       string_list_insert((const char *)e2->name, conflict);
+                       string_list_insert(conflict, (const char *)e2->name);
                        i++; /* skip over both #2 and #3 */
                }
        }
@@ -378,7 +378,13 @@ static int merge(const char *name, const char *path)
        }
        ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "", 0);
        if (!ret) {
-               FILE *f = fopen(path, "w");
+               FILE *f;
+
+               if (utime(rerere_path(name, "postimage"), NULL) < 0)
+                       warning("failed utime() on %s: %s",
+                                       rerere_path(name, "postimage"),
+                                       strerror(errno));
+               f = fopen(path, "w");
                if (!f)
                        return error("Could not open %s: %s", path,
                                     strerror(errno));
@@ -449,7 +455,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
                        if (ret < 1)
                                continue;
                        hex = xstrdup(sha1_to_hex(sha1));
-                       string_list_insert(path, rr)->util = hex;
+                       string_list_insert(rr, path)->util = hex;
                        if (mkdir(git_path("rr-cache/%s", hex), 0755))
                                continue;
                        handle_file(path, NULL, rerere_path(hex, "preimage"));
@@ -471,7 +477,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
                if (has_rerere_resolution(name)) {
                        if (!merge(name, path)) {
                                if (rerere_autoupdate)
-                                       string_list_insert(path, &update);
+                                       string_list_insert(&update, path);
                                fprintf(stderr,
                                        "%s '%s' using previous resolution.\n",
                                        rerere_autoupdate
@@ -577,7 +583,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
        fprintf(stderr, "Updated preimage for '%s'\n", path);
 
 
-       string_list_insert(path, rr)->util = hex;
+       string_list_insert(rr, path)->util = hex;
        fprintf(stderr, "Forgot resolution for %s\n", path);
        return 0;
 }
index 0f50ee0484776c545e632cde69b0646629a3b190..174ebec9e573b1942e379942037f38500bd19b97 100644 (file)
@@ -20,7 +20,7 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce)
                istate->resolve_undo = resolve_undo;
        }
        resolve_undo = istate->resolve_undo;
-       lost = string_list_insert(ce->name, resolve_undo);
+       lost = string_list_insert(resolve_undo, ce->name);
        if (!lost->util)
                lost->util = xcalloc(1, sizeof(*ui));
        ui = lost->util;
@@ -50,7 +50,7 @@ static int write_one(struct string_list_item *item, void *cbdata)
 
 void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo)
 {
-       for_each_string_list(write_one, resolve_undo, sb);
+   for_each_string_list(resolve_undo, write_one, sb);
 }
 
 struct string_list *resolve_undo_read(const char *data, unsigned long size)
@@ -70,7 +70,7 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
                len = strlen(data) + 1;
                if (size <= len)
                        goto error;
-               lost = string_list_insert(data, resolve_undo);
+               lost = string_list_insert(resolve_undo, data);
                if (!lost->util)
                        lost->util = xcalloc(1, sizeof(*ui));
                ui = lost->util;
@@ -135,7 +135,7 @@ int unmerge_index_entry_at(struct index_state *istate, int pos)
                        pos++;
                return pos - 1; /* return the last entry processed */
        }
-       item = string_list_lookup(ce->name, istate->resolve_undo);
+       item = string_list_lookup(istate->resolve_undo, ce->name);
        if (!item)
                return pos;
        ru = item->util;
index f4b8b383153b2330be1729fa29488bab1848e019..7e82efd9324e84582732485c53c6c25a24c29997 100644 (file)
@@ -646,6 +646,93 @@ static int still_interesting(struct commit_list *src, unsigned long date, int sl
        return slop-1;
 }
 
+/*
+ * "rev-list --ancestry-path A..B" computes commits that are ancestors
+ * of B but not ancestors of A but further limits the result to those
+ * that are descendants of A.  This takes the list of bottom commits and
+ * the result of "A..B" without --ancestry-path, and limits the latter
+ * further to the ones that can reach one of the commits in "bottom".
+ */
+static void limit_to_ancestry(struct commit_list *bottom, struct commit_list *list)
+{
+       struct commit_list *p;
+       struct commit_list *rlist = NULL;
+       int made_progress;
+
+       /*
+        * Reverse the list so that it will be likely that we would
+        * process parents before children.
+        */
+       for (p = list; p; p = p->next)
+               commit_list_insert(p->item, &rlist);
+
+       for (p = bottom; p; p = p->next)
+               p->item->object.flags |= TMP_MARK;
+
+       /*
+        * Mark the ones that can reach bottom commits in "list",
+        * in a bottom-up fashion.
+        */
+       do {
+               made_progress = 0;
+               for (p = rlist; p; p = p->next) {
+                       struct commit *c = p->item;
+                       struct commit_list *parents;
+                       if (c->object.flags & (TMP_MARK | UNINTERESTING))
+                               continue;
+                       for (parents = c->parents;
+                            parents;
+                            parents = parents->next) {
+                               if (!(parents->item->object.flags & TMP_MARK))
+                                       continue;
+                               c->object.flags |= TMP_MARK;
+                               made_progress = 1;
+                               break;
+                       }
+               }
+       } while (made_progress);
+
+       /*
+        * NEEDSWORK: decide if we want to remove parents that are
+        * not marked with TMP_MARK from commit->parents for commits
+        * in the resulting list.  We may not want to do that, though.
+        */
+
+       /*
+        * The ones that are not marked with TMP_MARK are uninteresting
+        */
+       for (p = list; p; p = p->next) {
+               struct commit *c = p->item;
+               if (c->object.flags & TMP_MARK)
+                       continue;
+               c->object.flags |= UNINTERESTING;
+       }
+
+       /* We are done with the TMP_MARK */
+       for (p = list; p; p = p->next)
+               p->item->object.flags &= ~TMP_MARK;
+       for (p = bottom; p; p = p->next)
+               p->item->object.flags &= ~TMP_MARK;
+       free_commit_list(rlist);
+}
+
+/*
+ * Before walking the history, keep the set of "negative" refs the
+ * caller has asked to exclude.
+ *
+ * This is used to compute "rev-list --ancestry-path A..B", as we need
+ * 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)
+{
+       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);
+       return bottom;
+}
+
 static int limit_list(struct rev_info *revs)
 {
        int slop = SLOP;
@@ -653,6 +740,13 @@ static int limit_list(struct rev_info *revs)
        struct commit_list *list = revs->commits;
        struct commit_list *newlist = NULL;
        struct commit_list **p = &newlist;
+       struct commit_list *bottom = NULL;
+
+       if (revs->ancestry_path) {
+               bottom = collect_bottom_commits(list);
+               if (!bottom)
+                       die("--ancestry-path given but there are no bottom commits");
+       }
 
        while (list) {
                struct commit_list *entry = list;
@@ -694,6 +788,11 @@ static int limit_list(struct rev_info *revs)
        if (revs->cherry_pick)
                cherry_pick_list(newlist, revs);
 
+       if (bottom) {
+               limit_to_ancestry(bottom, newlist);
+               free_commit_list(bottom);
+       }
+
        revs->commits = newlist;
        return 0;
 }
@@ -1063,18 +1162,22 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 
        if (!prefixcmp(arg, "--max-count=")) {
                revs->max_count = atoi(arg + 12);
+               revs->no_walk = 0;
        } else if (!prefixcmp(arg, "--skip=")) {
                revs->skip_count = atoi(arg + 7);
        } else if ((*arg == '-') && isdigit(arg[1])) {
        /* accept -<digit>, like traditional "head" */
                revs->max_count = atoi(arg + 1);
+               revs->no_walk = 0;
        } else if (!strcmp(arg, "-n")) {
                if (argc <= 1)
                        return error("-n requires an argument");
                revs->max_count = atoi(argv[1]);
+               revs->no_walk = 0;
                return 2;
        } else if (!prefixcmp(arg, "-n")) {
                revs->max_count = atoi(arg + 2);
+               revs->no_walk = 0;
        } else if (!prefixcmp(arg, "--max-age=")) {
                revs->max_age = atoi(arg + 10);
        } else if (!prefixcmp(arg, "--since=")) {
@@ -1089,6 +1192,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->min_age = approxidate(arg + 8);
        } else if (!strcmp(arg, "--first-parent")) {
                revs->first_parent_only = 1;
+       } else if (!strcmp(arg, "--ancestry-path")) {
+               revs->ancestry_path = 1;
+               revs->simplify_history = 0;
+               revs->limited = 1;
        } else if (!strcmp(arg, "-g") || !strcmp(arg, "--walk-reflogs")) {
                init_reflog_walk(&revs->reflog_info);
        } else if (!strcmp(arg, "--default")) {
@@ -1146,6 +1253,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->boundary = 1;
        } else if (!strcmp(arg, "--left-right")) {
                revs->left_right = 1;
+       } else if (!strcmp(arg, "--count")) {
+               revs->count = 1;
        } else if (!strcmp(arg, "--cherry-pick")) {
                revs->cherry_pick = 1;
                revs->limited = 1;
@@ -1205,8 +1314,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                else
                        strbuf_addstr(&buf, "refs/notes/");
                strbuf_addstr(&buf, arg+13);
-               string_list_append(strbuf_detach(&buf, NULL),
-                                  revs->notes_opt.extra_notes_refs);
+               string_list_append(revs->notes_opt.extra_notes_refs,
+                                  strbuf_detach(&buf, NULL));
        } else if (!strcmp(arg, "--no-notes")) {
                revs->show_notes = 0;
                revs->show_notes_given = 1;
@@ -1781,7 +1890,7 @@ int prepare_revision_walk(struct rev_info *revs)
 enum rewrite_result {
        rewrite_one_ok,
        rewrite_one_noparents,
-       rewrite_one_error,
+       rewrite_one_error
 };
 
 static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp)
index 568f1c98de844dbadcebf1d583bffc24e6daa677..36fdf22b299c4cc7e6f20d767d5c6a6c3f69d952 100644 (file)
@@ -57,6 +57,7 @@ struct rev_info {
                        limited:1,
                        unpacked:1,
                        boundary:2,
+                       count:1,
                        left_right:1,
                        rewrite_parents:1,
                        print_parents:1,
@@ -66,6 +67,7 @@ struct rev_info {
                        reverse_output_stage:1,
                        cherry_pick:1,
                        bisect:1,
+                       ancestry_path:1,
                        first_parent_only:1;
 
        /* Diff flags */
@@ -131,6 +133,10 @@ struct rev_info {
 
        /* notes-specific options: which refs to show */
        struct display_notes_opt notes_opt;
+
+       /* commit counts */
+       int count_left;
+       int count_right;
 };
 
 #define REV_TREE_SAME          0
index c7793f50fbe0a43495c2b2d36a47c0b5aac37483..2a1041ef6599c84fff6a8d9faf5dea23a2af3ab0 100644 (file)
@@ -84,6 +84,7 @@ static NORETURN void die_child(const char *err, va_list params)
        unused = write(child_err, "\n", 1);
        exit(128);
 }
+#endif
 
 static inline void set_cloexec(int fd)
 {
@@ -91,7 +92,6 @@ static inline void set_cloexec(int fd)
        if (flags >= 0)
                fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
 }
-#endif
 
 static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
 {
@@ -449,11 +449,35 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
        return run_command(&cmd);
 }
 
-#ifdef WIN32
-static unsigned __stdcall run_thread(void *data)
+#ifndef NO_PTHREADS
+static pthread_t main_thread;
+static int main_thread_set;
+static pthread_key_t async_key;
+
+static void *run_thread(void *data)
 {
        struct async *async = data;
-       return async->proc(async->proc_in, async->proc_out, async->data);
+       intptr_t ret;
+
+       pthread_setspecific(async_key, async);
+       ret = async->proc(async->proc_in, async->proc_out, async->data);
+       return (void *)ret;
+}
+
+static NORETURN void die_async(const char *err, va_list params)
+{
+       vreportf("fatal: ", err, params);
+
+       if (!pthread_equal(main_thread, pthread_self())) {
+               struct async *async = pthread_getspecific(async_key);
+               if (async->proc_in >= 0)
+                       close(async->proc_in);
+               if (async->proc_out >= 0)
+                       close(async->proc_out);
+               pthread_exit((void *)128);
+       }
+
+       exit(128);
 }
 #endif
 
@@ -499,7 +523,7 @@ int start_async(struct async *async)
        else
                proc_out = -1;
 
-#ifndef WIN32
+#ifdef NO_PTHREADS
        /* Flush stdio before fork() to avoid cloning buffers */
        fflush(NULL);
 
@@ -526,12 +550,29 @@ int start_async(struct async *async)
        else if (async->out)
                close(async->out);
 #else
+       if (!main_thread_set) {
+               /*
+                * We assume that the first time that start_async is called
+                * it is from the main thread.
+                */
+               main_thread_set = 1;
+               main_thread = pthread_self();
+               pthread_key_create(&async_key, NULL);
+               set_die_routine(die_async);
+       }
+
+       if (proc_in >= 0)
+               set_cloexec(proc_in);
+       if (proc_out >= 0)
+               set_cloexec(proc_out);
        async->proc_in = proc_in;
        async->proc_out = proc_out;
-       async->tid = (HANDLE) _beginthreadex(NULL, 0, run_thread, async, 0, NULL);
-       if (!async->tid) {
-               error("cannot create thread: %s", strerror(errno));
-               goto error;
+       {
+               int err = pthread_create(&async->tid, NULL, run_thread, async);
+               if (err) {
+                       error("cannot create thread: %s", strerror(err));
+                       goto error;
+               }
        }
 #endif
        return 0;
@@ -551,17 +592,15 @@ error:
 
 int finish_async(struct async *async)
 {
-#ifndef WIN32
-       int ret = wait_or_whine(async->pid, "child process", 0);
+#ifdef NO_PTHREADS
+       return wait_or_whine(async->pid, "child process", 0);
 #else
-       DWORD ret = 0;
-       if (WaitForSingleObject(async->tid, INFINITE) != WAIT_OBJECT_0)
-               ret = error("waiting for thread failed: %lu", GetLastError());
-       else if (!GetExitCodeThread(async->tid, &ret))
-               ret = error("cannot get thread exit code: %lu", GetLastError());
-       CloseHandle(async->tid);
+       void *ret = (void *)(intptr_t)(-1);
+
+       if (pthread_join(async->tid, &ret))
+               error("pthread_join failed");
+       return (int)(intptr_t)ret;
 #endif
-       return ret;
 }
 
 int run_hook(const char *index_file, const char *name, ...)
index 94619f52d95888b320664b7f19db3eeb7d6d8cca..56491b9f2344541c02bd0da2928a535f11193bd8 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef RUN_COMMAND_H
 #define RUN_COMMAND_H
 
+#ifndef NO_PTHREADS
+#include <pthread.h>
+#endif
+
 struct child_process {
        const char **argv;
        pid_t pid;
@@ -74,10 +78,10 @@ struct async {
        void *data;
        int in;         /* caller writes here and closes it */
        int out;        /* caller reads from here and closes it */
-#ifndef WIN32
+#ifdef NO_PTHREADS
        pid_t pid;
 #else
-       HANDLE tid;
+       pthread_t tid;
        int proc_in;
        int proc_out;
 #endif
diff --git a/setup.c b/setup.c
index 3bb046118cb612b16f35fa016032d1486c6e7190..276916052795c5ffa872b57a7e6723edc71dfdc4 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -325,6 +325,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
        const char *gitdirenv;
        const char *gitfile_dir;
        int len, offset, ceil_offset, root_len;
+       dev_t current_device = 0;
+       int one_filesystem = 1;
+       struct stat buf;
 
        /*
         * Let's assume that we are in a git repository.
@@ -392,6 +395,12 @@ const char *setup_git_directory_gently(int *nongit_ok)
         *   etc.
         */
        offset = len = strlen(cwd);
+       one_filesystem = !git_env_bool("GIT_DISCOVERY_ACROSS_FILESYSTEM", 0);
+       if (one_filesystem) {
+               if (stat(".", &buf))
+                       die_errno("failed to stat '.'");
+               current_device = buf.st_dev;
+       }
        for (;;) {
                gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
                if (gitfile_dir) {
@@ -424,8 +433,27 @@ const char *setup_git_directory_gently(int *nongit_ok)
                        }
                        die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT);
                }
-               if (chdir(".."))
+               if (one_filesystem) {
+                       if (stat("..", &buf)) {
+                               cwd[offset] = '\0';
+                               die_errno("failed to stat '%s/..'", cwd);
+                       }
+                       if (buf.st_dev != current_device) {
+                               if (nongit_ok) {
+                                       if (chdir(cwd))
+                                               die_errno("Cannot come back to cwd");
+                                       *nongit_ok = 1;
+                                       return NULL;
+                               }
+                               cwd[offset] = '\0';
+                               die("Not a git repository (or any parent up to mount parent %s)\n"
+                               "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).", cwd);
+                       }
+               }
+               if (chdir("..")) {
+                       cwd[offset] = '\0';
                        die_errno("Cannot change to '%s/..'", cwd);
+               }
        }
 
        inside_git_dir = 0;
index 72de38909ef6b05f0aa709b78fd803c632a02044..e42ef96d457f6aa12ab7d0057acf936db0335d40 100644 (file)
@@ -2525,3 +2525,13 @@ int read_pack_header(int fd, struct pack_header *header)
                return PH_ERROR_PROTOCOL;
        return 0;
 }
+
+void assert_sha1_type(const unsigned char *sha1, enum object_type expect)
+{
+       enum object_type type = sha1_object_info(sha1, NULL);
+       if (type < 0)
+               die("%s is not a valid object", sha1_to_hex(sha1));
+       if (type != expect)
+               die("%s is not a valid '%s' object", sha1_to_hex(sha1),
+                   typename(expect));
+}
index bf924178380c42a50b2fd7a02ff869dcc3ddff6a..4af94fa59806c570c177a68139b54d46772d68a5 100644 (file)
@@ -659,6 +659,16 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1)
        return get_short_sha1(name, len, sha1, 0);
 }
 
+/*
+ * This interprets names like ':/Initial revision of "git"' by searching
+ * through history and returning the first commit whose message starts
+ * the given regular expression.
+ *
+ * For future extension, ':/!' is reserved. If you want to match a message
+ * beginning with a '!', you have to repeat the exclamation mark.
+ */
+#define ONELINE_SEEN (1u<<20)
+
 static int handle_one_ref(const char *path,
                const unsigned char *sha1, int flag, void *cb_data)
 {
@@ -674,30 +684,26 @@ static int handle_one_ref(const char *path,
        if (object->type != OBJ_COMMIT)
                return 0;
        insert_by_date((struct commit *)object, list);
+       object->flags |= ONELINE_SEEN;
        return 0;
 }
 
-/*
- * This interprets names like ':/Initial revision of "git"' by searching
- * through history and returning the first commit whose message starts
- * with the given string.
- *
- * For future extension, ':/!' is reserved. If you want to match a message
- * beginning with a '!', you have to repeat the exclamation mark.
- */
-
-#define ONELINE_SEEN (1u<<20)
 static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 {
        struct commit_list *list = NULL, *backup = NULL, *l;
        int retval = -1;
        char *temp_commit_buffer = NULL;
+       regex_t regex;
 
        if (prefix[0] == '!') {
                if (prefix[1] != '!')
                        die ("Invalid search pattern: %s", prefix);
                prefix++;
        }
+
+       if (regcomp(&regex, prefix, REG_EXTENDED))
+               die("Invalid search pattern: %s", prefix);
+
        for_each_ref(handle_one_ref, &list);
        for (l = list; l; l = l->next)
                commit_list_insert(l->item, &backup);
@@ -721,12 +727,13 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
                }
                if (!(p = strstr(p, "\n\n")))
                        continue;
-               if (!prefixcmp(p + 2, prefix)) {
+               if (!regexec(&regex, p + 2, 0, NULL, 0)) {
                        hashcpy(sha1, commit->object.sha1);
                        retval = 0;
                        break;
                }
        }
+       regfree(&regex);
        free(temp_commit_buffer);
        free_commit_list(list);
        for (l = backup; l; l = l->next)
@@ -933,8 +940,8 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
  */
 int get_sha1(const char *name, unsigned char *sha1)
 {
-       unsigned unused;
-       return get_sha1_with_mode(name, sha1, &unused);
+       struct object_context unused;
+       return get_sha1_with_context(name, sha1, &unused);
 }
 
 /* Must be called only when object_name:filename doesn't exist. */
@@ -1031,12 +1038,24 @@ static void diagnose_invalid_index_path(int stage,
 
 
 int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode, int gently, const char *prefix)
+{
+       struct object_context oc;
+       int ret;
+       ret = get_sha1_with_context_1(name, sha1, &oc, gently, prefix);
+       *mode = oc.mode;
+       return ret;
+}
+
+int get_sha1_with_context_1(const char *name, unsigned char *sha1,
+                           struct object_context *oc,
+                           int gently, const char *prefix)
 {
        int ret, bracket_depth;
        int namelen = strlen(name);
        const char *cp;
 
-       *mode = S_IFINVALID;
+       memset(oc, 0, sizeof(*oc));
+       oc->mode = S_IFINVALID;
        ret = get_sha1_1(name, namelen, sha1);
        if (!ret)
                return ret;
@@ -1059,6 +1078,11 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
                        cp = name + 3;
                }
                namelen = namelen - (cp - name);
+
+               strncpy(oc->path, cp,
+                       sizeof(oc->path));
+               oc->path[sizeof(oc->path)-1] = '\0';
+
                if (!active_cache)
                        read_cache();
                pos = cache_name_pos(cp, namelen);
@@ -1071,7 +1095,6 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
                                break;
                        if (ce_stage(ce) == stage) {
                                hashcpy(sha1, ce->sha1);
-                               *mode = ce->ce_mode;
                                return 0;
                        }
                        pos++;
@@ -1098,12 +1121,17 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
                }
                if (!get_sha1_1(name, cp-name, tree_sha1)) {
                        const char *filename = cp+1;
-                       ret = get_tree_entry(tree_sha1, filename, sha1, mode);
+                       ret = get_tree_entry(tree_sha1, filename, sha1, &oc->mode);
                        if (!gently) {
                                diagnose_invalid_sha1_path(prefix, filename,
                                                           tree_sha1, object_name);
                                free(object_name);
                        }
+                       hashcpy(oc->tree, tree_sha1);
+                       strncpy(oc->path, filename,
+                               sizeof(oc->path));
+                       oc->path[sizeof(oc->path)-1] = '\0';
+
                        return ret;
                } else {
                        if (!gently)
index c9ad7fcd49669b0dff481d9ab857bf70d8a51bca..9b023a25841cb7a9c1faecc30c484eba0e16d6af 100644 (file)
@@ -51,13 +51,13 @@ static int add_entry(int insert_at, struct string_list *list, const char *string
        return index;
 }
 
-struct string_list_item *string_list_insert(const char *string, struct string_list *list)
+struct string_list_item *string_list_insert(struct string_list *list, const char *string)
 {
-       return string_list_insert_at_index(-1, string, list);
+       return string_list_insert_at_index(list, -1, string);
 }
 
-struct string_list_item *string_list_insert_at_index(int insert_at,
-                                                    const char *string, struct string_list *list)
+struct string_list_item *string_list_insert_at_index(struct string_list *list,
+                                                    int insert_at, const char *string)
 {
        int index = add_entry(insert_at, list, string);
 
@@ -84,7 +84,7 @@ int string_list_find_insert_index(const struct string_list *list, const char *st
        return index;
 }
 
-struct string_list_item *string_list_lookup(const char *string, struct string_list *list)
+struct string_list_item *string_list_lookup(struct string_list *list, const char *string)
 {
        int exact_match, i = get_entry_index(list, string, &exact_match);
        if (!exact_match)
@@ -92,8 +92,8 @@ struct string_list_item *string_list_lookup(const char *string, struct string_li
        return list->items + i;
 }
 
-int for_each_string_list(string_list_each_func_t fn,
-                        struct string_list *list, void *cb_data)
+int for_each_string_list(struct string_list *list,
+                        string_list_each_func_t fn, void *cb_data)
 {
        int i, ret = 0;
        for (i = 0; i < list->nr; i++)
@@ -139,7 +139,7 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c
 }
 
 
-void print_string_list(const char *text, const struct string_list *p)
+void print_string_list(const struct string_list *p, const char *text)
 {
        int i;
        if ( text )
@@ -148,7 +148,7 @@ void print_string_list(const char *text, const struct string_list *p)
                printf("%s:%p\n", p->items[i].string, p->items[i].util);
 }
 
-struct string_list_item *string_list_append(const char *string, struct string_list *list)
+struct string_list_item *string_list_append(struct string_list *list, const char *string)
 {
        ALLOC_GROW(list->items, list->nr + 1, list->alloc);
        list->items[list->nr].string =
index 63b69c8d75ee33120a65a23598ddf93e84831bdd..680d600d16c095eb167be2eca8c1a7cb94f962af 100644 (file)
@@ -12,7 +12,7 @@ struct string_list
        unsigned int strdup_strings:1;
 };
 
-void print_string_list(const char *text, const struct string_list *p);
+void print_string_list(const struct string_list *p, const char *text);
 void string_list_clear(struct string_list *list, int free_util);
 
 /* Use this function to call a custom clear function on each util pointer */
@@ -22,20 +22,20 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c
 
 /* Use this function to iterate over each item */
 typedef int (*string_list_each_func_t)(struct string_list_item *, void *);
-int for_each_string_list(string_list_each_func_t,
-                        struct string_list *list, void *cb_data);
+int for_each_string_list(struct string_list *list,
+                        string_list_each_func_t, void *cb_data);
 
 /* Use these functions only on sorted lists: */
 int string_list_has_string(const struct string_list *list, const char *string);
 int string_list_find_insert_index(const struct string_list *list, const char *string,
                                  int negative_existing_index);
-struct string_list_item *string_list_insert(const char *string, struct string_list *list);
-struct string_list_item *string_list_insert_at_index(int insert_at,
-                                                    const char *string, struct string_list *list);
-struct string_list_item *string_list_lookup(const char *string, struct string_list *list);
+struct string_list_item *string_list_insert(struct string_list *list, const char *string);
+struct string_list_item *string_list_insert_at_index(struct string_list *list,
+                                                    int insert_at, const char *string);
+struct string_list_item *string_list_lookup(struct string_list *list, const char *string);
 
 /* Use these functions only on unsorted lists: */
-struct string_list_item *string_list_append(const char *string, struct string_list *list);
+struct string_list_item *string_list_append(struct string_list *list, const char *string);
 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,
index 676d48fb33119f393befcaf8998ad38741366525..61cb6e21ddfc789ce59597c96204e7904cd9359e 100644 (file)
@@ -46,6 +46,19 @@ done:
        return ret;
 }
 
+void handle_ignore_submodules_arg(struct diff_options *diffopt,
+                                 const char *arg)
+{
+       if (!strcmp(arg, "all"))
+               DIFF_OPT_SET(diffopt, IGNORE_SUBMODULES);
+       else if (!strcmp(arg, "untracked"))
+               DIFF_OPT_SET(diffopt, IGNORE_UNTRACKED_IN_SUBMODULES);
+       else if (!strcmp(arg, "dirty"))
+               DIFF_OPT_SET(diffopt, IGNORE_DIRTY_SUBMODULES);
+       else
+               die("bad --ignore-submodules argument: %s", arg);
+}
+
 void show_submodule_summary(FILE *f, const char *path,
                unsigned char one[20], unsigned char two[20],
                unsigned dirty_submodule,
index dbda270873171c41f20c0f07b70773ce67c6a303..6fd3bb40702e5fb905eb4ae519d487e3c9f40073 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef SUBMODULE_H
 #define SUBMODULE_H
 
+struct diff_options;
+
+void handle_ignore_submodules_arg(struct diff_options *diffopt, const char *);
 void show_submodule_summary(FILE *f, const char *path,
                unsigned char one[20], unsigned char two[20],
                unsigned dirty_submodule,
index 25c559bb49d04586c69242cd7ef03713f0939e9d..cf5f9e2e1eb17c442220464d06374e6c529f8629 100644 (file)
@@ -3,6 +3,7 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
+-include ../config.mak.autogen
 -include ../config.mak
 
 #GIT_TEST_OPTS=--verbose --debug
@@ -35,7 +36,9 @@ aggregate-results-and-cleanup: $(T)
        $(MAKE) clean
 
 aggregate-results:
-       '$(SHELL_PATH_SQ)' ./aggregate-results.sh test-results/t*-*
+       for f in test-results/t*-*.counts; do \
+               echo "$$f"; \
+       done | '$(SHELL_PATH_SQ)' ./aggregate-results.sh
 
 # we can test NO_OPTIMIZE_COMMITS independently of LC_ALL
 full-svn-test:
index fecb76e599cee2643e4f6c05c44fa2585e807284..0d1183c3e69904e9e3543d757f14f10c629e199b 100644 (file)
--- a/t/README
+++ b/t/README
@@ -18,25 +18,48 @@ The easiest way to run tests is to say "make".  This runs all
 the tests.
 
     *** t0000-basic.sh ***
-    *   ok 1: .git/objects should be empty after git-init in an empty repo.
-    *   ok 2: .git/objects should have 256 subdirectories.
-    *   ok 3: git-update-index without --add should fail adding.
+    ok 1 - .git/objects should be empty after git init in an empty repo.
+    ok 2 - .git/objects should have 3 subdirectories.
+    ok 3 - success is reported like this
     ...
-    *   ok 23: no diff after checkout and git-update-index --refresh.
-    * passed all 23 test(s)
-    *** t0100-environment-names.sh ***
-    *   ok 1: using old names should issue warnings.
-    *   ok 2: using old names but having new names should not issue warnings.
-    ...
-
-Or you can run each test individually from command line, like
-this:
-
-    $ sh ./t3001-ls-files-killed.sh
-    *   ok 1: git-update-index --add to add various paths.
-    *   ok 2: git-ls-files -k to show killed files.
-    *   ok 3: validate git-ls-files -k output.
-    * passed all 3 test(s)
+    ok 43 - very long name in the index handled sanely
+    # fixed 1 known breakage(s)
+    # still have 1 known breakage(s)
+    # passed all remaining 42 test(s)
+    1..43
+    *** t0001-init.sh ***
+    ok 1 - plain
+    ok 2 - plain with GIT_WORK_TREE
+    ok 3 - plain bare
+
+Since the tests all output TAP (see http://testanything.org) they can
+be run with any TAP harness. Here's an example of parallel testing
+powered by a recent version of prove(1):
+
+    $ prove --timer --jobs 15 ./t[0-9]*.sh
+    [19:17:33] ./t0005-signals.sh ................................... ok       36 ms
+    [19:17:33] ./t0022-crlf-rename.sh ............................... ok       69 ms
+    [19:17:33] ./t0024-crlf-archive.sh .............................. ok      154 ms
+    [19:17:33] ./t0004-unwritable.sh ................................ ok      289 ms
+    [19:17:33] ./t0002-gitfile.sh ................................... ok      480 ms
+    ===(     102;0  25/?  6/?  5/?  16/?  1/?  4/?  2/?  1/?  3/?  1... )===
+
+prove and other harnesses come with a lot of useful options. The
+--state option in particular is very useful:
+
+    # Repeat until no more failures
+    $ prove -j 15 --state=failed,save ./t[0-9]*.sh
+
+You can also run each test individually from command line, like this:
+
+    $ sh ./t3010-ls-files-killed-modified.sh
+    ok 1 - git update-index --add to add various paths.
+    ok 2 - git ls-files -k to show killed files.
+    ok 3 - validate git ls-files -k output.
+    ok 4 - git ls-files -m to show modified files.
+    ok 5 - validate git ls-files -m output.
+    # passed all 5 test(s)
+    1..5
 
 You can pass --verbose (or -v), --debug (or -d), and --immediate
 (or -i) command line argument to the test, or by setting GIT_TEST_OPTS
@@ -198,15 +221,101 @@ This test harness library does the following things:
  - If the script is invoked with command line argument --help
    (or -h), it shows the test_description and exits.
 
- - Creates an empty test directory with an empty .git/objects
-   database and chdir(2) into it.  This directory is 't/trash directory'
-   if you must know, but I do not think you care.
+ - Creates an empty test directory with an empty .git/objects database
+   and chdir(2) into it.  This directory is 't/trash
+   directory.$test_name_without_dotsh', with t/ subject to change by
+   the --root option documented above.
 
  - Defines standard test helper functions for your scripts to
    use.  These functions are designed to make all scripts behave
    consistently when command line arguments --verbose (or -v),
    --debug (or -d), and --immediate (or -i) is given.
 
+Do's, don'ts & things to keep in mind
+-------------------------------------
+
+Here are a few examples of things you probably should and shouldn't do
+when writing tests.
+
+Do:
+
+ - Put all code inside test_expect_success and other assertions.
+
+   Even code that isn't a test per se, but merely some setup code
+   should be inside a test assertion.
+
+ - Chain your test assertions
+
+   Write test code like this:
+
+       git merge foo &&
+       git push bar &&
+       test ...
+
+   Instead of:
+
+       git merge hla
+       git push gh
+       test ...
+
+   That way all of the commands in your tests will succeed or fail. If
+   you must ignore the return value of something (e.g., the return
+   after unsetting a variable that was already unset is unportable) it's
+   best to indicate so explicitly with a semicolon:
+
+       unset HLAGH;
+       git merge hla &&
+       git push gh &&
+       test ...
+
+Don't:
+
+ - exit() within a <script> part.
+
+   The harness will catch this as a programming error of the test.
+   Use test_done instead if you need to stop the tests early (see
+   "Skipping tests" below).
+
+ - Break the TAP output
+
+   The raw output from your test may be interpreted by a TAP harness. TAP
+   harnesses will ignore everything they don't know about, but don't step
+   on their toes in these areas:
+
+   - Don't print lines like "$x..$y" where $x and $y are integers.
+
+   - Don't print lines that begin with "ok" or "not ok".
+
+   TAP harnesses expect a line that begins with either "ok" and "not
+   ok" to signal a test passed or failed (and our harness already
+   produces such lines), so your script shouldn't emit such lines to
+   their output.
+
+   You can glean some further possible issues from the TAP grammar
+   (see http://search.cpan.org/perldoc?TAP::Parser::Grammar#TAP_Grammar)
+   but the best indication is to just run the tests with prove(1),
+   it'll complain if anything is amiss.
+
+Keep in mind:
+
+ - Inside <script> part, the standard output and standard error
+   streams are discarded, and the test harness only reports "ok" or
+   "not ok" to the end user running the tests. Under --verbose, they
+   are shown to help debugging the tests.
+
+
+Skipping tests
+--------------
+
+If you need to skip all the remaining tests you should set skip_all
+and immediately call test_done. The string you give to skip_all will
+be used as an explanation for why the test was skipped. for instance:
+
+       if ! test_have_prereq PERL
+       then
+           skip_all='skipping perl interface tests, perl not available'
+           test_done
+       fi
 
 End with test_done
 ------------------
@@ -222,9 +331,9 @@ Test harness library
 There are a handful helper functions defined in the test harness
 library for your script to use.
 
- - test_expect_success <message> <script>
+ - test_expect_success [<prereq>] <message> <script>
 
-   This takes two strings as parameter, and evaluates the
+   Usually takes two strings as parameter, and evaluates the
    <script>.  If it yields success, test is considered
    successful.  <message> should state what it is testing.
 
@@ -234,7 +343,14 @@ library for your script to use.
            'git-write-tree should be able to write an empty tree.' \
            'tree=$(git-write-tree)'
 
- - test_expect_failure <message> <script>
+   If you supply three parameters the first will be taken to be a
+   prerequisite, see the test_set_prereq and test_have_prereq
+   documentation below:
+
+       test_expect_success TTY 'git --paginate rev-list uses a pager' \
+           ' ... '
+
+ - test_expect_failure [<prereq>] <message> <script>
 
    This is NOT the opposite of test_expect_success, but is used
    to mark a test that demonstrates a known breakage.  Unlike
@@ -243,6 +359,16 @@ library for your script to use.
    success and "still broken" on failure.  Failures from these
    tests won't cause -i (immediate) to stop.
 
+   Like test_expect_success this function can optionally use a three
+   argument invocation with a prerequisite as the first argument.
+
+ - test_expect_code [<prereq>] <code> <message> <script>
+
+   Analogous to test_expect_success, but pass the test if it exits
+   with a given exit <code>
+
+ test_expect_code 1 'Merge with d/f conflicts' 'git merge "merge msg" B master'
+
  - test_debug <script>
 
    This takes a single argument, <script>, and evaluates it only
@@ -275,6 +401,53 @@ library for your script to use.
    Merges the given rev using the given message.  Like test_commit,
    creates a tag and calls test_tick before committing.
 
+ - test_set_prereq SOME_PREREQ
+
+   Set a test prerequisite to be used later with test_have_prereq. The
+   test-lib will set some prerequisites for you, e.g. PERL and PYTHON
+   which are derived from ./GIT-BUILD-OPTIONS (grep test_set_prereq
+   test-lib.sh for more). Others you can set yourself and use later
+   with either test_have_prereq directly, or the three argument
+   invocation of test_expect_success and test_expect_failure.
+
+ - test_have_prereq SOME PREREQ
+
+   Check if we have a prerequisite previously set with
+   test_set_prereq. The most common use of this directly is to skip
+   all the tests if we don't have some essential prerequisite:
+
+       if ! test_have_prereq PERL
+       then
+           skip_all='skipping perl interface tests, perl not available'
+           test_done
+       fi
+
+ - test_external [<prereq>] <message> <external> <script>
+
+   Execute a <script> with an <external> interpreter (like perl). This
+   was added for tests like t9700-perl-git.sh which do most of their
+   work in an external test script.
+
+       test_external \
+           'GitwebCache::*FileCache*' \
+           "$PERL_PATH" "$TEST_DIRECTORY"/t9503/test_cache_interface.pl
+
+   If the test is outputting its own TAP you should set the
+   test_external_has_tap variable somewhere before calling the first
+   test_external* function. See t9700-perl-git.sh for an example.
+
+       # The external test will outputs its own plan
+       test_external_has_tap=1
+
+ - test_external_without_stderr [<prereq>] <message> <external> <script>
+
+   Like test_external but fail if there's any output on stderr,
+   instead of checking the exit code.
+
+       test_external_without_stderr \
+           'Perl API' \
+           "$PERL_PATH" "$TEST_DIRECTORY"/t9700/test.pl
+
  - test_must_fail <git-command>
 
    Run a git command and ensure it fails in a controlled way.  Use
@@ -283,6 +456,32 @@ library for your script to use.
    treats it as just another expected failure, which would let such a
    bug go unnoticed.
 
+ - test_might_fail <git-command>
+
+   Similar to test_must_fail, but tolerate success, too.  Use this
+   instead of "<git-command> || :" to catch failures due to segv.
+
+ - test_cmp <expected> <actual>
+
+   Check whether the content of the <actual> file matches the
+   <expected> file.  This behaves like "cmp" but produces more
+   helpful output when the test is run with "-v" option.
+
+ - test_when_finished <script>
+
+   Prepend <script> to a list of commands to run to clean up
+   at the end of the current test.  If some clean-up command
+   fails, the test will not pass.
+
+   Example:
+
+       test_expect_success 'branch pointing to non-commit' '
+               git rev-parse HEAD^{tree} >.git/refs/heads/invalid &&
+               test_when_finished "git update-ref -d refs/heads/invalid" &&
+               ...
+       '
+
+
 Tips for Writing Tests
 ----------------------
 
index d5bab75d7da49ebb53e368d67f6b867f5417a125..d206b7c4cfa4f7d61d151cebc35a0f296fbe4c6b 100755 (executable)
@@ -6,7 +6,7 @@ failed=0
 broken=0
 total=0
 
-for file
+while read file
 do
        while read type value
        do
index 5a734b1b7b2df4a5c5c35f5347c618f3735317ac..81ef2a0969d98f05ce22cd8a06fcb55a7af9aee8 100644 (file)
@@ -19,9 +19,9 @@ our \$site_name = '[localhost]';
 our \$site_header = '';
 our \$site_footer = '';
 our \$home_text = 'indextext.html';
-our @stylesheets = ('file:///$TEST_DIRECTORY/../gitweb/gitweb.css');
-our \$logo = 'file:///$TEST_DIRECTORY/../gitweb/git-logo.png';
-our \$favicon = 'file:///$TEST_DIRECTORY/../gitweb/git-favicon.png';
+our @stylesheets = ('file:///$TEST_DIRECTORY/../gitweb/static/gitweb.css');
+our \$logo = 'file:///$TEST_DIRECTORY/../gitweb/static/git-logo.png';
+our \$favicon = 'file:///$TEST_DIRECTORY/../gitweb/static/git-favicon.png';
 our \$projects_list = '';
 our \$export_ok = '';
 our \$strict_export = '';
@@ -76,12 +76,12 @@ gitweb_run () {
 . ./test-lib.sh
 
 if ! test_have_prereq PERL; then
-       say 'skipping gitweb tests, perl not available'
+       skip_all='skipping gitweb tests, perl not available'
        test_done
 fi
 
 perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
-    say 'skipping gitweb tests, perl version is too old'
+    skip_all='skipping gitweb tests, perl version is too old'
     test_done
 }
 
index 4b3b793730604e5b513c5017f39f4560b3083338..648d1619c86bb676faadf62bd831683cb46d6be2 100644 (file)
@@ -9,7 +9,7 @@ export HOME
 
 if ! type cvs >/dev/null 2>&1
 then
-       say 'skipping cvsimport tests, cvs not found'
+       skip_all='skipping cvsimport tests, cvs not found'
        test_done
 fi
 
@@ -21,11 +21,11 @@ case "$cvsps_version" in
 2.1 | 2.2*)
        ;;
 '')
-       say 'skipping cvsimport tests, cvsps not found'
+       skip_all='skipping cvsimport tests, cvsps not found'
        test_done
        ;;
 *)
-       say 'skipping cvsimport tests, unsupported cvsps version'
+       skip_all='skipping cvsimport tests, unsupported cvsps version'
        test_done
        ;;
 esac
index 0f7f35ccc9e1315d3ac8e5d37df51c106847d920..92d6d319428223de9205d4d162e3806aedee855b 100644 (file)
@@ -5,23 +5,22 @@ git_svn_id=git""-svn-id
 
 if test -n "$NO_SVN_TESTS"
 then
-       say 'skipping git svn tests, NO_SVN_TESTS defined'
+       skip_all='skipping git svn tests, NO_SVN_TESTS defined'
        test_done
 fi
 if ! test_have_prereq PERL; then
-       say 'skipping git svn tests, perl not available'
+       skip_all='skipping git svn tests, perl not available'
        test_done
 fi
 
 GIT_DIR=$PWD/.git
 GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
 SVN_TREE=$GIT_SVN_DIR/svn-tree
-PERL=${PERL:-perl}
 
 svn >/dev/null 2>&1
 if test $? -ne 1
 then
-    say 'skipping git svn tests, svn not found'
+    skip_all='skipping git svn tests, svn not found'
     test_done
 fi
 
@@ -30,7 +29,7 @@ export svnrepo
 svnconf=$PWD/svnconf
 export svnconf
 
-$PERL -w -e "
+"$PERL_PATH" -w -e "
 use SVN::Core;
 use SVN::Repos;
 \$SVN::Core::VERSION gt '1.1.0' or exit(42);
@@ -40,13 +39,12 @@ x=$?
 if test $x -ne 0
 then
        if test $x -eq 42; then
-               err='Perl SVN libraries must be >= 1.1.0'
+               skip_all='Perl SVN libraries must be >= 1.1.0'
        elif test $x -eq 41; then
-               err='svnadmin failed to create fsfs repository'
+               skip_all='svnadmin failed to create fsfs repository'
        else
-               err='Perl SVN libraries not found or unusable, skipping test'
+               skip_all='Perl SVN libraries not found or unusable'
        fi
-       say "$err"
        test_done
 fi
 
@@ -131,7 +129,7 @@ stop_httpd () {
 }
 
 convert_to_rev_db () {
-       $PERL -w -- - "$@" <<\EOF
+       "$PERL_PATH" -w -- - "$@" <<\EOF
 use strict;
 @ARGV == 2 or die "Usage: convert_to_rev_db <input> <output>";
 open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
@@ -159,7 +157,7 @@ EOF
 require_svnserve () {
     if test -z "$SVNSERVE_PORT"
     then
-        say 'skipping svnserve test. (set $SVNSERVE_PORT to enable)'
+       skip_all='skipping svnserve test. (set $SVNSERVE_PORT to enable)'
         test_done
     fi
 }
index da4b8d5a6fbf18adac103a5a6dd26ea3498c178f..e733f6516fdf98e48d5c7cd36ecc89d36166eea1 100644 (file)
@@ -5,8 +5,7 @@
 
 if test -z "$GIT_TEST_HTTPD"
 then
-       say "skipping test, network testing disabled by default"
-       say "(define GIT_TEST_HTTPD to enable)"
+       skip_all="Network testing disabled (define GIT_TEST_HTTPD to enable)"
        test_done
 fi
 
@@ -46,7 +45,7 @@ HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www
 
 if ! test -x "$LIB_HTTPD_PATH"
 then
-       say "skipping test, no web server found at '$LIB_HTTPD_PATH'"
+       skip_all="skipping test, no web server found at '$LIB_HTTPD_PATH'"
        test_done
 fi
 
@@ -59,12 +58,12 @@ then
        then
                if ! test $HTTPD_VERSION -ge 2
                then
-                       say "skipping test, at least Apache version 2 is required"
+                       skip_all="skipping test, at least Apache version 2 is required"
                        test_done
                fi
                if ! test -d "$DEFAULT_HTTPD_MODULE_PATH"
                then
-                       say "Apache module directory not found.  Skipping tests."
+                       skip_all="Apache module directory not found.  Skipping tests."
                        test_done
                fi
 
@@ -119,7 +118,7 @@ start_httpd() {
                >&3 2>&4
        if test $? -ne 0
        then
-               say "skipping test, web server setup failed"
+               skip_all="skipping test, web server setup failed"
                trap 'die' EXIT
                test_done
        fi
@@ -146,7 +145,7 @@ test_http_push_nonff() {
                echo "changed" > path2 &&
                git commit -a -m path2 --amend &&
 
-               !(git push -v origin >output 2>&1) &&
+               test_must_fail git push -v origin >output 2>&1 &&
                (cd "$REMOTE_REPO" &&
                 test $HEAD = $(git rev-parse --verify HEAD))
        '
diff --git a/t/lib-pager.sh b/t/lib-pager.sh
new file mode 100644 (file)
index 0000000..ba03eab
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+test_expect_success 'determine default pager' '
+       test_might_fail git config --unset core.pager &&
+       less=$(
+               unset PAGER GIT_PAGER;
+               git var GIT_PAGER
+       ) &&
+       test -n "$less"
+'
+
+if expr "$less" : '[a-z][a-z]*$' >/dev/null
+then
+       test_set_prereq SIMPLEPAGER
+fi
index ce36f34d0337d29f6ec8f274cd99ad201bd3965d..375e2486511656df4294f0a4b750fd8d3f16d273 100644 (file)
@@ -3,7 +3,7 @@
 . ./test-lib.sh
 
 if ! test_have_prereq PERL; then
-       say 'skipping --patch tests, perl not available'
+       skip_all='skipping --patch tests, perl not available'
        test_done
 fi
 
index 985d517a1ce4cf2f80eed3d54c25b5fc912d5c6b..ea25dd89e505525507c16c62d91fb07c092b064a 100644 (file)
@@ -91,7 +91,7 @@ check_output()
        shift 1
        if eval "$*" | entag > $_name.actual
        then
-               diff $_name.expected $_name.actual
+               test_cmp $_name.expected $_name.actual
        else
                return 1;
        fi
index 3ec9cbef2c88f65e5fb254d10cc551c6c4062c88..f2c73369a5b93544ee837229da965d7efbdc45bf 100755 (executable)
@@ -301,7 +301,7 @@ $expectfilter >expected <<\EOF
 EOF
 test_expect_success \
     'validate git diff-files output for a know cache/work tree state.' \
-    'git diff-files >current && diff >/dev/null -b current expected'
+    'git diff-files >current && test_cmp current expected >/dev/null'
 
 test_expect_success \
     'git update-index --refresh should succeed.' \
index 3ea4f9eff923c963aeb9635be6d77dce99f3bf4a..1d4d0a5c7d2549c67334a8d5dd3f462962db81f2 100755 (executable)
@@ -39,6 +39,7 @@ 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' '2008-02-14 20:30:45 -0500' EST5
 
 check_approxidate() {
        echo "$1 -> $2 +0000" >expect
index c3e7e322a8d62b988999b166d2abcf08930adbf7..234a94f3e6311c529b5bb476ee5a6a2ea705017f 100755 (executable)
@@ -453,5 +453,57 @@ test_expect_success 'invalid .gitattributes (must not crash)' '
        git diff
 
 '
+# Some more tests here to add new autocrlf functionality.
+# We want to have a known state here, so start a bit from scratch
+
+test_expect_success 'setting up for new autocrlf tests' '
+       git config core.autocrlf false &&
+       git config core.safecrlf false &&
+       rm -rf .????* * &&
+       for w in I am all LF; do echo $w; done >alllf &&
+       for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
+       for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
+       git add -A . &&
+       git commit -m "alllf, allcrlf and mixed only" &&
+       git tag -a -m "message" autocrlf-checkpoint
+'
+
+test_expect_success 'report no change after setting autocrlf' '
+       git config core.autocrlf true &&
+       touch * &&
+       git diff --exit-code
+'
+
+test_expect_success 'files are clean after checkout' '
+       rm * &&
+       git checkout -f &&
+       git diff --exit-code
+'
+
+cr_to_Q_no_NL () {
+    tr '\015' Q | tr -d '\012'
+}
+
+test_expect_success 'LF only file gets CRLF with autocrlf' '
+       test "$(cr_to_Q_no_NL < alllf)" = "IQamQallQLFQ"
+'
+
+test_expect_success 'Mixed file is still mixed with autocrlf' '
+       test "$(cr_to_Q_no_NL < mixed)" = "OhhereisCRLFQintext"
+'
+
+test_expect_success 'CRLF only file has CRLF with autocrlf' '
+       test "$(cr_to_Q_no_NL < allcrlf)" = "IQamQallQCRLFQ"
+'
+
+test_expect_success 'New CRLF file gets LF in repo' '
+       tr -d "\015" < alllf | append_cr > alllf2 &&
+       git add alllf2 &&
+       git commit -m "alllf2 added" &&
+       git config core.autocrlf false &&
+       rm * &&
+       git checkout -f &&
+       test_cmp alllf alllf2
+'
 
 test_done
index 6cb8d60ea2649495c0e3c8bbb8b7cc75c36799b7..828e35baf72d94908ad1f30dbd2e1aa6f9376e69 100755 (executable)
@@ -65,17 +65,21 @@ test_expect_success expanded_in_repo '
                echo "\$Id:NoSpaceAtFront \$"
                echo "\$Id:NoSpaceAtEitherEnd\$"
                echo "\$Id: NoTerminatingSymbol"
+               echo "\$Id: Foreign Commit With Spaces \$"
+               echo "\$Id: NoTerminatingSymbolAtEOF"
        } > expanded-keywords &&
 
        {
                echo "File with expanded keywords"
-               echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
-               echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
-               echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
-               echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
-               echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
-               echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
+               echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+               echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+               echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+               echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+               echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+               echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
                echo "\$Id: NoTerminatingSymbol"
+               echo "\$Id: Foreign Commit With Spaces \$"
+               echo "\$Id: NoTerminatingSymbolAtEOF"
        } > expected-output &&
 
        git add expanded-keywords &&
diff --git a/t/t0025-crlf-auto.sh b/t/t0025-crlf-auto.sh
new file mode 100755 (executable)
index 0000000..f5f67a6
--- /dev/null
@@ -0,0 +1,155 @@
+#!/bin/sh
+
+test_description='CRLF conversion'
+
+. ./test-lib.sh
+
+has_cr() {
+       tr '\015' Q <"$1" | grep Q >/dev/null
+}
+
+test_expect_success setup '
+
+       git config core.autocrlf false &&
+
+       for w in Hello world how are you; do echo $w; done >one &&
+       for w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >two &&
+       for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >three &&
+       git add . &&
+
+       git commit -m initial &&
+
+       one=`git rev-parse HEAD:one` &&
+       two=`git rev-parse HEAD:two` &&
+       three=`git rev-parse HEAD:three` &&
+
+       echo happy.
+'
+
+test_expect_success 'default settings cause no changes' '
+
+       rm -f .gitattributes tmp one two three &&
+       git read-tree --reset -u HEAD &&
+
+       ! has_cr one &&
+       has_cr two &&
+       onediff=`git diff one` &&
+       twodiff=`git diff two` &&
+       threediff=`git diff three` &&
+       test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
+'
+
+test_expect_success 'crlf=true causes a CRLF file to be normalized' '
+
+       # Backwards compatibility check
+       rm -f .gitattributes tmp one two three &&
+       echo "two crlf" > .gitattributes &&
+       git read-tree --reset -u HEAD &&
+
+       # Note, "normalized" means that git will normalize it if added
+       has_cr two &&
+       twodiff=`git diff two` &&
+       test -n "$twodiff"
+'
+
+test_expect_success 'text=true causes a CRLF file to be normalized' '
+
+       rm -f .gitattributes tmp one two three &&
+       echo "two text" > .gitattributes &&
+       git read-tree --reset -u HEAD &&
+
+       # Note, "normalized" means that git will normalize it if added
+       has_cr two &&
+       twodiff=`git diff two` &&
+       test -n "$twodiff"
+'
+
+test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
+
+       rm -f .gitattributes tmp one two three &&
+       git config core.autocrlf false &&
+       echo "one eol=crlf" > .gitattributes &&
+       git read-tree --reset -u HEAD &&
+
+       has_cr one &&
+       onediff=`git diff one` &&
+       test -z "$onediff"
+'
+
+test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
+
+       rm -f .gitattributes tmp one two three &&
+       git config core.autocrlf input &&
+       echo "one eol=crlf" > .gitattributes &&
+       git read-tree --reset -u HEAD &&
+
+       has_cr one &&
+       onediff=`git diff one` &&
+       test -z "$onediff"
+'
+
+test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' '
+
+       rm -f .gitattributes tmp one two three &&
+       git config core.autocrlf true &&
+       echo "one eol=lf" > .gitattributes &&
+       git read-tree --reset -u HEAD &&
+
+       ! has_cr one &&
+       onediff=`git diff one` &&
+       test -z "$onediff"
+'
+
+test_expect_success 'autocrlf=true does not normalize CRLF files' '
+
+       rm -f .gitattributes tmp one two three &&
+       git config core.autocrlf true &&
+       git read-tree --reset -u HEAD &&
+
+       has_cr one &&
+       has_cr two &&
+       onediff=`git diff one` &&
+       twodiff=`git diff two` &&
+       threediff=`git diff three` &&
+       test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
+'
+
+test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' '
+
+       rm -f .gitattributes tmp one two three &&
+       git config core.autocrlf true &&
+       echo "* text=auto" > .gitattributes &&
+       git read-tree --reset -u HEAD &&
+
+       has_cr one &&
+       has_cr two &&
+       onediff=`git diff one` &&
+       twodiff=`git diff two` &&
+       threediff=`git diff three` &&
+       test -z "$onediff" -a -n "$twodiff" -a -z "$threediff"
+'
+
+test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '
+
+       rm -f .gitattributes tmp one two three &&
+       git config core.autocrlf true &&
+       echo "* text=auto" > .gitattributes &&
+       git read-tree --reset -u HEAD &&
+
+       ! has_cr three &&
+       threediff=`git diff three` &&
+       test -z "$threediff"
+'
+
+test_expect_success 'eol=crlf _does_ normalize binary files' '
+
+       rm -f .gitattributes tmp one two three &&
+       echo "three eol=crlf" > .gitattributes &&
+       git read-tree --reset -u HEAD &&
+
+       has_cr three &&
+       threediff=`git diff three` &&
+       test -z "$threediff"
+'
+
+test_done
diff --git a/t/t0026-eol-config.sh b/t/t0026-eol-config.sh
new file mode 100755 (executable)
index 0000000..f37ac8f
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+test_description='CRLF conversion'
+
+. ./test-lib.sh
+
+has_cr() {
+       tr '\015' Q <"$1" | grep Q >/dev/null
+}
+
+test_expect_success setup '
+
+       git config core.autocrlf false &&
+
+       echo "one text" > .gitattributes
+
+       for w in Hello world how are you; do echo $w; done >one &&
+       for w in I am very very fine thank you; do echo $w; done >two &&
+       git add . &&
+
+       git commit -m initial &&
+
+       one=`git rev-parse HEAD:one` &&
+       two=`git rev-parse HEAD:two` &&
+
+       echo happy.
+'
+
+test_expect_success 'eol=lf puts LFs in normalized file' '
+
+       rm -f .gitattributes tmp one two &&
+       git config core.eol lf &&
+       git read-tree --reset -u HEAD &&
+
+       ! has_cr one &&
+       ! has_cr two &&
+       onediff=`git diff one` &&
+       twodiff=`git diff two` &&
+       test -z "$onediff" -a -z "$twodiff"
+'
+
+test_expect_success 'eol=crlf puts CRLFs in normalized file' '
+
+       rm -f .gitattributes tmp one two &&
+       git config core.eol crlf &&
+       git read-tree --reset -u HEAD &&
+
+       has_cr one &&
+       ! has_cr two &&
+       onediff=`git diff one` &&
+       twodiff=`git diff two` &&
+       test -z "$onediff" -a -z "$twodiff"
+'
+
+test_expect_success 'autocrlf=true overrides eol=lf' '
+
+       rm -f .gitattributes tmp one two &&
+       git config core.eol lf &&
+       git config core.autocrlf true &&
+       git read-tree --reset -u HEAD &&
+
+       has_cr one &&
+       has_cr two &&
+       onediff=`git diff one` &&
+       twodiff=`git diff two` &&
+       test -z "$onediff" -a -z "$twodiff"
+'
+
+test_expect_success 'autocrlf=true overrides unset eol' '
+
+       rm -f .gitattributes tmp one two &&
+       git config --unset-all core.eol &&
+       git config core.autocrlf true &&
+       git read-tree --reset -u HEAD &&
+
+       has_cr one &&
+       has_cr two &&
+       onediff=`git diff one` &&
+       twodiff=`git diff two` &&
+       test -z "$onediff" -a -z "$twodiff"
+'
+
+test_done
index 3d450ed379fcd1bf480fc75feb0e6ddb8f05e5be..20924506af886c8d0ce28f3fcb2742214d80020f 100755 (executable)
@@ -7,7 +7,7 @@ test_description='our own option parser'
 
 . ./test-lib.sh
 
-cat > expect.err << EOF
+cat > expect << EOF
 usage: test-parse-options <options>
 
     -b, --boolean         get a boolean
@@ -46,10 +46,12 @@ EOF
 
 test_expect_success 'test help' '
        test_must_fail test-parse-options -h > output 2> output.err &&
-       test ! -s output &&
-       test_cmp expect.err output.err
+       test ! -s output.err &&
+       test_cmp expect output
 '
 
+mv expect expect.err
+
 cat > expect << EOF
 boolean: 2
 integer: 1729
index 6327d205cb89b00e77502031e3b56b4b895cc32d..0c562bb820cb747a8f0d0df1eabb39da0b9eea21 100755 (executable)
@@ -390,4 +390,20 @@ test_expect_success \
      git ls-files --stage | tee >treeMcheck.out &&
      test_cmp treeM.out treeMcheck.out'
 
+test_expect_success '-m references the correct modified tree' '
+       echo >file-a &&
+       echo >file-b &&
+       git add file-a file-b &&
+       git commit -a -m "test for correct modified tree"
+       git branch initial-mod &&
+       echo b >file-b &&
+       git commit -a -m "B" &&
+       echo a >file-a &&
+       git add file-a &&
+       git ls-tree $(git write-tree) file-a >expect &&
+       git read-tree -m HEAD initial-mod &&
+       git ls-tree $(git write-tree) file-a >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 210e594f6f3c83cc1b0c423a0f692380ff57176b..56874996a6df278202c0bc476abec4bca3ce99c5 100755 (executable)
@@ -24,18 +24,18 @@ test_expect_success 'update-index and ls-files' '
        cd "$HERE" &&
        git update-index --add one &&
        case "`git ls-files`" in
-       one) echo ok one ;;
+       one) echo pass one ;;
        *) echo bad one; exit 1 ;;
        esac &&
        cd dir &&
        git update-index --add two &&
        case "`git ls-files`" in
-       two) echo ok two ;;
+       two) echo pass two ;;
        *) echo bad two; exit 1 ;;
        esac &&
        cd .. &&
        case "`git ls-files`" in
-       dir/two"$LF"one) echo ok both ;;
+       dir/two"$LF"one) echo pass both ;;
        *) echo bad; exit 1 ;;
        esac
 '
@@ -58,17 +58,17 @@ test_expect_success 'diff-files' '
        echo a >>one &&
        echo d >>dir/two &&
        case "`git diff-files --name-only`" in
-       dir/two"$LF"one) echo ok top ;;
+       dir/two"$LF"one) echo pass top ;;
        *) echo bad top; exit 1 ;;
        esac &&
        # diff should not omit leading paths
        cd dir &&
        case "`git diff-files --name-only`" in
-       dir/two"$LF"one) echo ok subdir ;;
+       dir/two"$LF"one) echo pass subdir ;;
        *) echo bad subdir; exit 1 ;;
        esac &&
        case "`git diff-files --name-only .`" in
-       dir/two) echo ok subdir limited ;;
+       dir/two) echo pass subdir limited ;;
        *) echo bad subdir limited; exit 1 ;;
        esac
 '
index 7ddab5fb76697442808e2818ec3bc5c635731830..074f2f2e3e57f76b01f16502998e95b493676711 100755 (executable)
@@ -846,4 +846,12 @@ test_expect_success 'check split_cmdline return' "
        test_must_fail git merge master
        "
 
+test_expect_success 'git -c "key=value" support' '
+       test "z$(git -c name=value config name)" = zvalue &&
+       test "z$(git -c core.name=value config core.name)" = zvalue &&
+       test "z$(git -c CamelCase=value config camelcase)" = zvalue &&
+       test "z$(git -c flag config --bool flag)" = ztrue &&
+       test_must_fail git -c core.name=value config name
+'
+
 test_done
index 055ad00f778eda1de02a418bbc602e580acdaca1..97ab02aceb8d9448ca5d4b13b94a8e3d7221375a 100755 (executable)
@@ -15,9 +15,12 @@ umask 077
 # is a good candidate: exists on all unices, and it has permission
 # anyway, so we don't create a security hole running the testsuite.
 
-if ! setfacl -m u:root:rwx .; then
-    say "Skipping ACL tests: unable to use setfacl"
-    test_done
+setfacl_out="$(setfacl -m u:root:rwx . 2>&1)"
+setfacl_ret=$?
+
+if [ $setfacl_ret != 0 ]; then
+       skip_all="Skipping ACL tests: unable to use setfacl (output: '$setfacl_out'; return code: '$setfacl_ret')"
+       test_done
 fi
 
 check_perms_and_acl () {
index eb45afb018f6e3849204b44cce06ae1a4e2e29aa..782e75d00091ebf1fda93ca5dc8e532289a15638 100755 (executable)
@@ -41,6 +41,23 @@ test_expect_success "check-ref-format --branch @{-1}" '
        refname2=$(git check-ref-format --branch @{-2}) &&
        test "$refname2" = master'
 
+test_expect_success 'check-ref-format --branch from subdir' '
+       mkdir subdir &&
+
+       T=$(git write-tree) &&
+       sha1=$(echo A | git commit-tree $T) &&
+       git update-ref refs/heads/master $sha1 &&
+       git update-ref refs/remotes/origin/master $sha1
+       git checkout master &&
+       git checkout origin/master &&
+       git checkout master &&
+       refname=$(
+               cd subdir &&
+               git check-ref-format --branch @{-1}
+       ) &&
+       test "$refname" = "$sha1"
+'
+
 valid_ref_normalized() {
        test_expect_success "ref name '$1' simplifies to '$2'" "
                refname=\$(git check-ref-format --print '$1') &&
index 49cae3ed524d70ae39114b35a95e7070f1a4e575..759cf12e16bcddc3dab9d6b3ad8abd5590245a94 100755 (executable)
@@ -5,7 +5,9 @@ test_description='git fsck random collection of tests'
 . ./test-lib.sh
 
 test_expect_success setup '
+       git config i18n.commitencoding ISO-8859-1 &&
        test_commit A fileA one &&
+       git config --unset i18n.commitencoding &&
        git checkout HEAD^0 &&
        test_commit B fileB two &&
        git tag -d A B &&
@@ -28,6 +30,12 @@ test_expect_success 'loose objects borrowed from alternate are not missing' '
        )
 '
 
+test_expect_success 'valid objects appear valid' '
+       { git fsck 2>out; true; } &&
+       ! grep error out &&
+       ! grep fatal out
+'
+
 # Corruption tests follow.  Make sure to remove all traces of the
 # specific corruption you test afterwards, lest a later test trip over
 # it.
@@ -57,6 +65,34 @@ test_expect_success 'branch pointing to non-commit' '
        git update-ref -d refs/heads/invalid
 '
 
+new=nothing
+test_expect_success 'email without @ is okay' '
+       git cat-file commit HEAD >basis &&
+       sed "s/@/AT/" basis >okay &&
+       new=$(git hash-object -t commit -w --stdin <okay) &&
+       echo "$new" &&
+       git update-ref refs/heads/bogus "$new" &&
+       git fsck 2>out &&
+       cat out &&
+       ! grep "error in commit $new" out
+'
+git update-ref -d refs/heads/bogus
+rm -f ".git/objects/$new"
+
+new=nothing
+test_expect_success 'email with embedded > is not okay' '
+       git cat-file commit HEAD >basis &&
+       sed "s/@[a-z]/&>/" basis >bad-email &&
+       new=$(git hash-object -t commit -w --stdin <bad-email) &&
+       echo "$new" &&
+       git update-ref refs/heads/bogus "$new" &&
+       git fsck 2>out &&
+       cat out &&
+       grep "error in commit $new" out
+'
+git update-ref -d refs/heads/bogus
+rm -f ".git/objects/$new"
+
 cat > invalid-tag <<EOF
 object ffffffffffffffffffffffffffffffffffffffff
 type commit
index 3b612c67bec5985b24016eff7916942ae0afb58b..b3195c47070b35d555f8cfae90497a2d00d10ca7 100755 (executable)
@@ -3,7 +3,8 @@
 test_description='test git rev-parse --parseopt'
 . ./test-lib.sh
 
-cat > expect.err <<EOF
+cat > expect <<\END_EXPECT
+cat <<\EOF
 usage: some-command [options] <args>...
 
     some-command does foo and bar!
@@ -19,6 +20,7 @@ Extras
     --extra1              line above used to cause a segfault but no longer does
 
 EOF
+END_EXPECT
 
 cat > optionspec << EOF
 some-command [options] <args>...
@@ -38,8 +40,8 @@ extra1    line above used to cause a segfault but no longer does
 EOF
 
 test_expect_success 'test --parseopt help output' '
-       git rev-parse --parseopt -- -h 2> output.err < optionspec
-       test_cmp expect.err output.err
+       git rev-parse --parseopt -- -h > output < optionspec
+       test_cmp expect output
 '
 
 cat > expect <<EOF
index 5322a3bf9703fab9f6b199dcd3f861b8e27c3ed3..7f60fd0b2e8904ec231975df3d65e66c9363ff45 100755 (executable)
@@ -99,17 +99,17 @@ test_foobar_foobar() {
 }
 
 if ! test_have_prereq POSIXPERM || ! [ -w / ]; then
-       say "Dangerous test skipped. Read this test if you want to execute it"
+       skip_all="Dangerous test skipped. Read this test if you want to execute it"
        test_done
 fi
 
 if [ "$IKNOWWHATIAMDOING" != "YES" ]; then
-       say "You must set env var IKNOWWHATIAMDOING=YES in order to run this test"
+       skip_all="You must set env var IKNOWWHATIAMDOING=YES in order to run this test"
        test_done
 fi
 
 if [ "$UID" = 0 ]; then
-       say "No you can't run this with root"
+       skip_all="No you can't run this with root"
        test_done
 fi
 
index 27e2127afeeb0dd462a686254e60be74e9dd9c28..05cc8fdd0168d33d0fe6f2ca54aa4162a0c6cdd0 100755 (executable)
@@ -8,7 +8,7 @@ test_description='git checkout to switch between branches with symlink<->dir'
 
 if ! test_have_prereq SYMLINKS
 then
-       say "symbolic links not supported - skipping tests"
+       skip_all="symbolic links not supported - skipping tests"
        test_done
 fi
 
diff --git a/t/t2017-checkout-orphan.sh b/t/t2017-checkout-orphan.sh
new file mode 100755 (executable)
index 0000000..2d2f63f
--- /dev/null
@@ -0,0 +1,119 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Erick Mattos
+#
+
+test_description='git checkout --orphan
+
+Main Tests for --orphan functionality.'
+
+. ./test-lib.sh
+
+TEST_FILE=foo
+
+test_expect_success 'Setup' '
+       echo "Initial" >"$TEST_FILE" &&
+       git add "$TEST_FILE" &&
+       git commit -m "First Commit"
+       test_tick &&
+       echo "State 1" >>"$TEST_FILE" &&
+       git add "$TEST_FILE" &&
+       test_tick &&
+       git commit -m "Second Commit"
+'
+
+test_expect_success '--orphan creates a new orphan branch from HEAD' '
+       git checkout --orphan alpha &&
+       test_must_fail git rev-parse --verify HEAD &&
+       test "refs/heads/alpha" = "$(git symbolic-ref HEAD)" &&
+       test_tick &&
+       git commit -m "Third Commit" &&
+       test_must_fail git rev-parse --verify HEAD^ &&
+       git diff-tree --quiet master alpha
+'
+
+test_expect_success '--orphan creates a new orphan branch from <start_point>' '
+       git checkout master &&
+       git checkout --orphan beta master^ &&
+       test_must_fail git rev-parse --verify HEAD &&
+       test "refs/heads/beta" = "$(git symbolic-ref HEAD)" &&
+       test_tick &&
+       git commit -m "Fourth Commit" &&
+       test_must_fail git rev-parse --verify HEAD^ &&
+       git diff-tree --quiet master^ beta
+'
+
+test_expect_success '--orphan must be rejected with -b' '
+       git checkout master &&
+       test_must_fail git checkout --orphan new -b newer &&
+       test refs/heads/master = "$(git symbolic-ref HEAD)"
+'
+
+test_expect_success '--orphan must be rejected with -t' '
+       git checkout master &&
+       test_must_fail git checkout --orphan new -t master &&
+       test refs/heads/master = "$(git symbolic-ref HEAD)"
+'
+
+test_expect_success '--orphan ignores branch.autosetupmerge' '
+       git checkout master &&
+       git config branch.autosetupmerge always &&
+       git checkout --orphan gamma &&
+       test -z "$(git config branch.gamma.merge)" &&
+       test refs/heads/gamma = "$(git symbolic-ref HEAD)" &&
+       test_must_fail git rev-parse --verify HEAD^
+'
+
+test_expect_success '--orphan makes reflog by default' '
+       git checkout master &&
+       git config --unset core.logAllRefUpdates &&
+       git checkout --orphan delta &&
+       test_must_fail git rev-parse --verify delta@{0} &&
+       git commit -m Delta &&
+       git rev-parse --verify delta@{0}
+'
+
+test_expect_success '--orphan does not make reflog when core.logAllRefUpdates = false' '
+       git checkout master &&
+       git config core.logAllRefUpdates false &&
+       git checkout --orphan epsilon &&
+       test_must_fail git rev-parse --verify epsilon@{0} &&
+       git commit -m Epsilon &&
+       test_must_fail git rev-parse --verify epsilon@{0}
+'
+
+test_expect_success '--orphan with -l makes reflog when core.logAllRefUpdates = false' '
+       git checkout master &&
+       git checkout -l --orphan zeta &&
+       test_must_fail git rev-parse --verify zeta@{0} &&
+       git commit -m Zeta &&
+       git rev-parse --verify zeta@{0}
+'
+
+test_expect_success 'giving up --orphan not committed when -l and core.logAllRefUpdates = false deletes reflog' '
+       git checkout master &&
+       git checkout -l --orphan eta &&
+       test_must_fail git rev-parse --verify eta@{0} &&
+       git checkout master &&
+       test_must_fail git rev-parse --verify eta@{0}
+'
+
+test_expect_success '--orphan is rejected with an existing name' '
+       git checkout master &&
+       test_must_fail git checkout --orphan master &&
+       test refs/heads/master = "$(git symbolic-ref HEAD)"
+'
+
+test_expect_success '--orphan refuses to switch if a merge is needed' '
+       git checkout master &&
+       git reset --hard &&
+       echo local >>"$TEST_FILE" &&
+       cat "$TEST_FILE" >"$TEST_FILE.saved" &&
+       test_must_fail git checkout --orphan new master^ &&
+       test refs/heads/master = "$(git symbolic-ref HEAD)" &&
+       test_cmp "$TEST_FILE" "$TEST_FILE.saved" &&
+       git diff-index --quiet --cached HEAD &&
+       git reset --hard
+'
+
+test_done
index 1ed44ee503f9ecfb5222a9bce3f42ff2aa8127bc..4d0d0a35156ee1a7604f0ea719e93d3f765a2f91 100755 (executable)
@@ -24,7 +24,7 @@ git update-index symlink'
 test_expect_success \
 'the index entry must still be a symbolic link' '
 case "`git ls-files --stage --cached symlink`" in
-120000" "*symlink) echo ok;;
+120000" "*symlink) echo pass;;
 *) echo fail; git ls-files --stage --cached symlink; (exit 1);;
 esac'
 
index 86291e839942e6842bf1d2b40f2d7f7c1d8d4a9f..2eec0118c4235c0aa9d85cb7112e1f72b49c5c5f 100755 (executable)
@@ -17,57 +17,52 @@ filesystem.
 '
 . ./test-lib.sh
 
-date >path0
-if test_have_prereq SYMLINKS
-then
-       ln -s xyzzy path1
-else
-       date > path1
-fi
-mkdir path2 path3 path4
-date >path2/file2
-date >path2-junk
-date >path3/file3
-date >path3-junk
-git update-index --add path3-junk path3/file3
-
-cat >expected1 <<EOF
-expected1
-expected2
-expected3
-output
-path0
-path1
-path2-junk
-path2/file2
-EOF
-sed -e 's|path2/file2|path2/|' <expected1 >expected2
-cat <expected2 >expected3
-echo path4/ >>expected2
-
-test_expect_success \
-    'git ls-files --others to show output.' \
-    'git ls-files --others >output'
-
-test_expect_success \
-    'git ls-files --others should pick up symlinks.' \
-    'test_cmp expected1 output'
+test_expect_success 'setup ' '
+       date >path0 &&
+       if test_have_prereq SYMLINKS
+       then
+               ln -s xyzzy path1
+       else
+               date >path1
+       fi &&
+       mkdir path2 path3 path4 &&
+       date >path2/file2 &&
+       date >path2-junk &&
+       date >path3/file3 &&
+       date >path3-junk &&
+       git update-index --add path3-junk path3/file3
+'
 
-test_expect_success \
-    'git ls-files --others --directory to show output.' \
-    'git ls-files --others --directory >output'
+test_expect_success 'setup: expected output' '
+       cat >expected1 <<-\EOF &&
+       expected1
+       expected2
+       expected3
+       output
+       path0
+       path1
+       path2-junk
+       path2/file2
+       EOF
 
+       sed -e "s|path2/file2|path2/|" <expected1 >expected2 &&
+       cp expected2 expected3 &&
+       echo path4/ >>expected2
+'
 
-test_expect_success \
-    'git ls-files --others --directory should not get confused.' \
-    'test_cmp expected2 output'
+test_expect_success 'ls-files --others' '
+       git ls-files --others >output &&
+       test_cmp expected1 output
+'
 
-test_expect_success \
-    'git ls-files --others --directory --no-empty-directory to show output.' \
-    'git ls-files --others --directory --no-empty-directory >output'
+test_expect_success 'ls-files --others --directory' '
+       git ls-files --others --directory >output &&
+       test_cmp expected2 output
+'
 
-test_expect_success \
-    '--no-empty-directory hides empty directory' \
-    'test_cmp expected3 output'
+test_expect_success '--no-empty-directory hides empty directory' '
+       git ls-files --others --directory --no-empty-directory >output &&
+       test_cmp expected3 output
+'
 
 test_done
index 9929f82021deeb20358016b487400b80e27b596f..d541544537d47587abad8d27565cf9197387cfd6 100755 (executable)
@@ -22,6 +22,7 @@ test_expect_success 'setup 1' '
        git branch df-2 &&
        git branch df-3 &&
        git branch remove &&
+       git branch submod &&
 
        echo hello >>a &&
        cp a d/e &&
@@ -236,6 +237,17 @@ test_expect_success 'setup 6' '
        test_cmp expected actual
 '
 
+test_expect_success 'setup 7' '
+
+       git checkout submod &&
+       git rm d/e &&
+       test_tick &&
+       git commit -m "remove d/e" &&
+       git update-index --add --cacheinfo 160000 $c1 d &&
+       test_tick &&
+       git commit -m "make d/ a submodule"
+'
+
 test_expect_success 'merge-recursive simple' '
 
        rm -fr [abcd] &&
@@ -551,4 +563,21 @@ test_expect_success 'merge removes empty directories' '
        test_must_fail test -d d
 '
 
+test_expect_failure 'merge-recursive simple w/submodule' '
+
+       git checkout submod &&
+       git merge remove
+'
+
+test_expect_failure 'merge-recursive simple w/submodule result' '
+
+       git ls-files -s >actual &&
+       (
+               echo "100644 $o5 0      a"
+               echo "100644 $o0 0      c"
+               echo "160000 $c1 0      d"
+       ) >expected &&
+       test_cmp expected actual
+'
+
 test_done
index 06654c6f82fb6cfe955b91bcbd4a5fa064c73e70..026f9f89d916fdd0547c58aed7bcba7f06850023 100755 (executable)
@@ -21,33 +21,32 @@ entries.  Also test odd filename and missing entries handling.
 '
 . ./test-lib.sh
 
-test_expect_success \
-    'setup' \
-    'echo 111 >1.txt &&
-     echo 222 >2.txt &&
-     mkdir path0 path0/a path0/a/b path0/a/b/c &&
-     echo 111 >path0/a/b/c/1.txt &&
-     mkdir path1 path1/b path1/b/c &&
-     echo 111 >path1/b/c/1.txt &&
-     mkdir path2 &&
-     echo 111 >path2/1.txt &&
-     mkdir path3 &&
-     echo 111 >path3/1.txt &&
-     echo 222 >path3/2.txt &&
-     find *.txt path* \( -type f -o -type l \) -print |
-     xargs git update-index --add &&
-     tree=`git write-tree` &&
-     echo $tree'
+test_expect_success 'setup' '
+       echo 111 >1.txt &&
+       echo 222 >2.txt &&
+       mkdir path0 path0/a path0/a/b path0/a/b/c &&
+       echo 111 >path0/a/b/c/1.txt &&
+       mkdir path1 path1/b path1/b/c &&
+       echo 111 >path1/b/c/1.txt &&
+       mkdir path2 &&
+       echo 111 >path2/1.txt &&
+       mkdir path3 &&
+       echo 111 >path3/1.txt &&
+       echo 222 >path3/2.txt &&
+       find *.txt path* \( -type f -o -type l \) -print |
+       xargs git update-index --add &&
+       tree=`git write-tree` &&
+       echo $tree
+'
 
 test_output () {
-    sed -e "s/ $_x40   / X     /" <current >check
-    test_cmp expected check
+       sed -e "s/ $_x40        / X     /" <current >check &&
+       test_cmp expected check
 }
 
-test_expect_success \
-    'ls-tree plain' \
-    'git ls-tree $tree >current &&
-     cat >expected <<\EOF &&
+test_expect_success 'ls-tree plain' '
+       git ls-tree $tree >current &&
+       cat >expected <<\EOF &&
 100644 blob X  1.txt
 100644 blob X  2.txt
 040000 tree X  path0
@@ -55,13 +54,13 @@ test_expect_success \
 040000 tree X  path2
 040000 tree X  path3
 EOF
-     test_output'
+       test_output
+'
 
 # Recursive does not show tree nodes anymore...
-test_expect_success \
-    'ls-tree recursive' \
-    'git ls-tree -r $tree >current &&
-     cat >expected <<\EOF &&
+test_expect_success 'ls-tree recursive' '
+       git ls-tree -r $tree >current &&
+       cat >expected <<\EOF &&
 100644 blob X  1.txt
 100644 blob X  2.txt
 100644 blob X  path0/a/b/c/1.txt
@@ -70,68 +69,71 @@ test_expect_success \
 100644 blob X  path3/1.txt
 100644 blob X  path3/2.txt
 EOF
-     test_output'
+       test_output
+'
 
-test_expect_success \
-    'ls-tree filter 1.txt' \
-    'git ls-tree $tree 1.txt >current &&
-     cat >expected <<\EOF &&
+test_expect_success 'ls-tree filter 1.txt' '
+       git ls-tree $tree 1.txt >current &&
+       cat >expected <<\EOF &&
 100644 blob X  1.txt
 EOF
-     test_output'
+       test_output
+'
 
-test_expect_success \
-    'ls-tree filter path1/b/c/1.txt' \
-    'git ls-tree $tree path1/b/c/1.txt >current &&
-     cat >expected <<\EOF &&
+test_expect_success 'ls-tree filter path1/b/c/1.txt' '
+       git ls-tree $tree path1/b/c/1.txt >current &&
+       cat >expected <<\EOF &&
 100644 blob X  path1/b/c/1.txt
 EOF
-     test_output'
+       test_output
+'
 
-test_expect_success \
-    'ls-tree filter all 1.txt files' \
-    'git ls-tree $tree 1.txt path0/a/b/c/1.txt path1/b/c/1.txt path2/1.txt path3/1.txt >current &&
-     cat >expected <<\EOF &&
+test_expect_success 'ls-tree filter all 1.txt files' '
+       git ls-tree $tree 1.txt path0/a/b/c/1.txt \
+               path1/b/c/1.txt path2/1.txt path3/1.txt >current &&
+       cat >expected <<\EOF &&
 100644 blob X  1.txt
 100644 blob X  path0/a/b/c/1.txt
 100644 blob X  path1/b/c/1.txt
 100644 blob X  path2/1.txt
 100644 blob X  path3/1.txt
 EOF
-     test_output'
+       test_output
+'
 
 # I am not so sure about this one after ls-tree doing pathspec match.
 # Having both path0/a and path0/a/b/c makes path0/a redundant, and
 # it behaves as if path0/a/b/c, path1/b/c, path2 and path3 are specified.
-test_expect_success \
-    'ls-tree filter directories' \
-    'git ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current &&
-     cat >expected <<\EOF &&
+test_expect_success 'ls-tree filter directories' '
+       git ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current &&
+       cat >expected <<\EOF &&
 040000 tree X  path0/a/b/c
 040000 tree X  path1/b/c
 040000 tree X  path2
 040000 tree X  path3
 EOF
-     test_output'
+       test_output
+'
 
 # Again, duplicates are filtered away so this is equivalent to
 # having 1.txt and path3
-test_expect_success \
-    'ls-tree filter odd names' \
-    'git ls-tree $tree 1.txt ./1.txt .//1.txt path3/1.txt path3/./1.txt path3 path3// >current &&
-     cat >expected <<\EOF &&
+test_expect_success 'ls-tree filter odd names' '
+       git ls-tree $tree 1.txt ./1.txt .//1.txt \
+               path3/1.txt path3/./1.txt path3 path3// >current &&
+       cat >expected <<\EOF &&
 100644 blob X  1.txt
 100644 blob X  path3/1.txt
 100644 blob X  path3/2.txt
 EOF
-     test_output'
+       test_output
+'
 
-test_expect_success \
-    'ls-tree filter missing files and extra slashes' \
-    'git ls-tree $tree 1.txt/ abc.txt path3//23.txt path3/2.txt/// >current &&
-     cat >expected <<\EOF &&
-EOF
-     test_output'
+test_expect_success 'ls-tree filter missing files and extra slashes' '
+       git ls-tree $tree 1.txt/ abc.txt \
+               path3//23.txt path3/2.txt/// >current &&
+       >expected &&
+       test_output
+'
 
 test_expect_success 'ls-tree filter is leading path match' '
        git ls-tree $tree pa path3/a >current &&
@@ -198,7 +200,7 @@ EOF
 '
 
 test_expect_success 'ls-tree --name-only' '
-       git ls-tree --name-only $tree >current
+       git ls-tree --name-only $tree >current &&
        cat >expected <<\EOF &&
 1.txt
 2.txt
@@ -211,7 +213,7 @@ EOF
 '
 
 test_expect_success 'ls-tree --name-only -r' '
-       git ls-tree --name-only -r $tree >current
+       git ls-tree --name-only -r $tree >current &&
        cat >expected <<\EOF &&
 1.txt
 2.txt
index e0b760513cfc065126cecd6e273180826c8f6bc9..f54a533456d74a3eb2f745dbc77c8ad5a5ae960f 100755 (executable)
@@ -43,7 +43,7 @@ test_expect_success \
      git branch -l d/e/f &&
         test -f .git/refs/heads/d/e/f &&
         test -f .git/logs/refs/heads/d/e/f &&
-        diff expect .git/logs/refs/heads/d/e/f'
+        test_cmp expect .git/logs/refs/heads/d/e/f'
 
 test_expect_success \
     'git branch -d d/e/f should delete a branch and a log' \
@@ -222,7 +222,28 @@ test_expect_success \
      git checkout -b g/h/i -l master &&
         test -f .git/refs/heads/g/h/i &&
         test -f .git/logs/refs/heads/g/h/i &&
-        diff expect .git/logs/refs/heads/g/h/i'
+        test_cmp expect .git/logs/refs/heads/g/h/i'
+
+test_expect_success 'checkout -b makes reflog by default' '
+       git checkout master &&
+       git config --unset core.logAllRefUpdates &&
+       git checkout -b alpha &&
+       git rev-parse --verify alpha@{0}
+'
+
+test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
+       git checkout master &&
+       git config core.logAllRefUpdates false &&
+       git checkout -b beta &&
+       test_must_fail git rev-parse --verify beta@{0}
+'
+
+test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
+       git checkout master &&
+       git checkout -lb gamma &&
+       git config --unset core.logAllRefUpdates &&
+       git rev-parse --verify gamma@{0}
+'
 
 test_expect_success 'avoid ambiguous track' '
        git config branch.autosetupmerge true &&
index 413019acafc98646a61e77960527f042a8f96ac6..cd04361df811d329e269ac1d5eb0b0f03baa74d8 100755 (executable)
@@ -28,7 +28,7 @@ test_expect_success \
      SHA1=`cat .git/refs/heads/a` &&
      echo "$SHA1 refs/heads/a" >expect &&
      git show-ref a >result &&
-     diff expect result'
+     test_cmp expect result'
 
 test_expect_success \
     'see if a branch still exists when packed' \
@@ -37,7 +37,7 @@ test_expect_success \
      rm -f .git/refs/heads/b &&
      echo "$SHA1 refs/heads/b" >expect &&
      git show-ref b >result &&
-     diff expect result'
+     test_cmp expect result'
 
 test_expect_success 'git branch c/d should barf if branch c exists' '
      git branch c &&
@@ -52,7 +52,7 @@ test_expect_success \
      git pack-refs --all --prune &&
      echo "$SHA1 refs/heads/e" >expect &&
      git show-ref e >result &&
-     diff expect result'
+     test_cmp expect result'
 
 test_expect_success 'see if git pack-refs --prune remove ref files' '
      git branch f &&
@@ -60,6 +60,12 @@ test_expect_success 'see if git pack-refs --prune remove ref files' '
      ! test -f .git/refs/heads/f
 '
 
+test_expect_success 'see if git pack-refs --prune removes empty dirs' '
+     git branch r/s/t &&
+     git pack-refs --all --prune &&
+     ! test -e .git/refs/heads/r
+'
+
 test_expect_success \
     'git branch g should work when git branch g/h has been deleted' \
     'git branch g/h &&
@@ -109,7 +115,7 @@ test_expect_success 'pack, prune and repack' '
        git show-ref >all-of-them &&
        git pack-refs &&
        git show-ref >again &&
-       diff all-of-them again
+       test_cmp all-of-them again
 '
 
 test_done
index db46d53e8271c0410a0dbf53a3560a8b635e2853..a99e4d8b923cd0d85e5f7e875af4182d2238c9fb 100755 (executable)
@@ -26,7 +26,7 @@ echo 'Foo Bar Baz' >"$p2"
 
 test -f "$p1" && cmp "$p0" "$p1" || {
        # since FAT/NTFS does not allow tabs in filenames, skip this test
-       say 'Your filesystem does not allow tabs in filenames, test skipped.'
+       skip_all='Your filesystem does not allow tabs in filenames, test skipped.'
        test_done
 }
 
index 2d67a40fc16385b8bee37968f4058b094a174a98..1d82f79ee07e8f9317bc23c49cdf941af36ce3ff 100755 (executable)
@@ -693,7 +693,11 @@ test_expect_success 'create note from non-existing note with "git notes add -c"
        git add a10 &&
        test_tick &&
        git commit -m 10th &&
-       test_must_fail MSG="yet another note" git notes add -c deadbeef &&
+       (
+               MSG="yet another note" &&
+               export MSG &&
+               test_must_fail git notes add -c deadbeef
+       ) &&
        test_must_fail git notes list HEAD
 '
 
index ee84fc4884676ef683e6b3d2b6ad718dc2817445..8ab333dbd949fe781b5c13b3deab665544763a88 100755 (executable)
@@ -8,7 +8,7 @@ test_description='Test commit notes index (expensive!)'
 . ./test-lib.sh
 
 test -z "$GIT_NOTES_TIMING_TESTS" && {
-       say Skipping timing tests
+       skip_all="Skipping timing tests"
        test_done
        exit
 }
@@ -98,7 +98,7 @@ time_notes () {
        for mode in no-notes notes
        do
                echo $mode
-               /usr/bin/time sh ../time_notes $mode $1
+               /usr/bin/time "$SHELL_PATH" ../time_notes $mode $1
        done
 }
 
index a0ed0353e69dd6dbc96f1a8e3c9251757b4f408f..b4554041b49d1ab7b56430f2e85b76a23d360fb4 100755 (executable)
@@ -60,7 +60,7 @@ test_expect_success 'verify commits and notes' '
 
 test_expect_success 'remove some commits' '
 
-       git reset --hard HEAD~2 &&
+       git reset --hard HEAD~1 &&
        git reflog expire --expire=now HEAD &&
        git gc --prune=now
 '
@@ -68,7 +68,7 @@ test_expect_success 'remove some commits' '
 test_expect_success 'verify that commits are gone' '
 
        ! git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
-       git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
+       git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
        git cat-file -p ab5f302035f2e7aaf04265f08b42034c23256e1f
 '
 
@@ -79,11 +79,55 @@ test_expect_success 'verify that notes are still present' '
        git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
 '
 
+test_expect_success 'prune -n does not remove notes' '
+
+       git notes list > expect &&
+       git notes prune -n &&
+       git notes list > actual &&
+       test_cmp expect actual
+'
+
+cat > expect <<EOF
+5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29
+EOF
+
+test_expect_success 'prune -n lists prunable notes' '
+
+
+       git notes prune -n > actual &&
+       test_cmp expect actual
+'
+
+
 test_expect_success 'prune notes' '
 
        git notes prune
 '
 
+test_expect_success 'verify that notes are gone' '
+
+       ! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
+       git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
+       git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
+'
+
+test_expect_success 'remove some commits' '
+
+       git reset --hard HEAD~1 &&
+       git reflog expire --expire=now HEAD &&
+       git gc --prune=now
+'
+
+cat > expect <<EOF
+08341ad9e94faa089d60fd3f523affb25c6da189
+EOF
+
+test_expect_success 'prune -v notes' '
+
+       git notes prune -v > actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'verify that notes are gone' '
 
        ! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
index c41bcc7d635687f938312d4a6fbbf786738bca93..a19aeb6441cb29dc20478cf898b5f7767d770c94 100755 (executable)
@@ -14,129 +14,164 @@ GIT_AUTHOR_NAME=author@name
 GIT_AUTHOR_EMAIL=bogus@email@address
 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
 
-test_expect_success \
-    'prepare repository with topic branches' \
-    'git config core.logAllRefUpdates true &&
-     echo First > A &&
-     git update-index --add A &&
-     git commit -m "Add A." &&
-     git checkout -b my-topic-branch &&
-     echo Second > B &&
-     git update-index --add B &&
-     git commit -m "Add B." &&
-     git checkout -f master &&
-     echo Third >> A &&
-     git update-index A &&
-     git commit -m "Modify A." &&
-     git checkout -b side my-topic-branch &&
-     echo Side >> C &&
-     git add C &&
-     git commit -m "Add C" &&
-     git checkout -b nonlinear my-topic-branch &&
-     echo Edit >> B &&
-     git add B &&
-     git commit -m "Modify B" &&
-     git merge side &&
-     git checkout -b upstream-merged-nonlinear &&
-     git merge master &&
-     git checkout -f my-topic-branch &&
-     git tag topic
+test_expect_success 'prepare repository with topic branches' '
+       git config core.logAllRefUpdates true &&
+       echo First >A &&
+       git update-index --add A &&
+       git commit -m "Add A." &&
+       git checkout -b force-3way &&
+       echo Dummy >Y &&
+       git update-index --add Y &&
+       git commit -m "Add Y." &&
+       git checkout -b filemove &&
+       git reset --soft master &&
+       mkdir D &&
+       git mv A D/A &&
+       git commit -m "Move A." &&
+       git checkout -b my-topic-branch master &&
+       echo Second >B &&
+       git update-index --add B &&
+       git commit -m "Add B." &&
+       git checkout -f master &&
+       echo Third >>A &&
+       git update-index A &&
+       git commit -m "Modify A." &&
+       git checkout -b side my-topic-branch &&
+       echo Side >>C &&
+       git add C &&
+       git commit -m "Add C" &&
+       git checkout -b nonlinear my-topic-branch &&
+       echo Edit >>B &&
+       git add B &&
+       git commit -m "Modify B" &&
+       git merge side &&
+       git checkout -b upstream-merged-nonlinear &&
+       git merge master &&
+       git checkout -f my-topic-branch &&
+       git tag topic
 '
 
 test_expect_success 'rebase on dirty worktree' '
-     echo dirty >> A &&
-     test_must_fail git rebase master'
+       echo dirty >>A &&
+       test_must_fail git rebase master
+'
 
 test_expect_success 'rebase on dirty cache' '
-     git add A &&
-     test_must_fail git rebase master'
+       git add A &&
+       test_must_fail git rebase master
+'
 
 test_expect_success 'rebase against master' '
-     git reset --hard HEAD &&
-     git rebase master'
+       git reset --hard HEAD &&
+       git rebase master
+'
 
 test_expect_success 'rebase against master twice' '
-     git rebase master >out &&
-     grep "Current branch my-topic-branch is up to date" out
+       git rebase master >out &&
+       grep "Current branch my-topic-branch is up to date" out
 '
 
 test_expect_success 'rebase against master twice with --force' '
-     git rebase --force-rebase master >out &&
-     grep "Current branch my-topic-branch is up to date, rebase forced" out
+       git rebase --force-rebase master >out &&
+       grep "Current branch my-topic-branch is up to date, rebase forced" out
 '
 
 test_expect_success 'rebase against master twice from another branch' '
-     git checkout my-topic-branch^ &&
-     git rebase master my-topic-branch >out &&
-     grep "Current branch my-topic-branch is up to date" out
+       git checkout my-topic-branch^ &&
+       git rebase master my-topic-branch >out &&
+       grep "Current branch my-topic-branch is up to date" out
 '
 
 test_expect_success 'rebase fast-forward to master' '
-     git checkout my-topic-branch^ &&
-     git rebase my-topic-branch >out &&
-     grep "Fast-forwarded HEAD to my-topic-branch" out
+       git checkout my-topic-branch^ &&
+       git rebase my-topic-branch >out &&
+       grep "Fast-forwarded HEAD to my-topic-branch" out
 '
 
-test_expect_success \
-    'the rebase operation should not have destroyed author information' \
-    '! (git log | grep "Author:" | grep "<>")'
+test_expect_success 'the rebase operation should not have destroyed author information' '
+       ! (git log | grep "Author:" | grep "<>")
+'
 
-test_expect_success \
-    'the rebase operation should not have destroyed author information (2)' \
-    "git log -1 | grep 'Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>'"
+test_expect_success 'the rebase operation should not have destroyed author information (2)' "
+       git log -1 |
+       grep 'Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>'
+"
 
 test_expect_success 'HEAD was detached during rebase' '
-     test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})
+       test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})
 '
 
 test_expect_success 'rebase after merge master' '
-     git reset --hard topic &&
-     git merge master &&
-     git rebase master &&
-     ! (git show | grep "^Merge:")
+       git reset --hard topic &&
+       git merge master &&
+       git rebase master &&
+       ! (git show | grep "^Merge:")
 '
 
 test_expect_success 'rebase of history with merges is linearized' '
-     git checkout nonlinear &&
-     test 4 = $(git rev-list master.. | wc -l) &&
-     git rebase master &&
-     test 3 = $(git rev-list master.. | wc -l)
+       git checkout nonlinear &&
+       test 4 = $(git rev-list master.. | wc -l) &&
+       git rebase master &&
+       test 3 = $(git rev-list master.. | wc -l)
 '
 
-test_expect_success \
-    'rebase of history with merges after upstream merge is linearized' '
-     git checkout upstream-merged-nonlinear &&
-     test 5 = $(git rev-list master.. | wc -l) &&
-     git rebase master &&
-     test 3 = $(git rev-list master.. | wc -l)
+test_expect_success 'rebase of history with merges after upstream merge is linearized' '
+       git checkout upstream-merged-nonlinear &&
+       test 5 = $(git rev-list master.. | wc -l) &&
+       git rebase master &&
+       test 3 = $(git rev-list master.. | wc -l)
 '
 
 test_expect_success 'rebase a single mode change' '
-     git checkout master &&
-     echo 1 > X &&
-     git add X &&
-     test_tick &&
-     git commit -m prepare &&
-     git checkout -b modechange HEAD^ &&
-     echo 1 > X &&
-     git add X &&
-     test_chmod +x A &&
-     test_tick &&
-     git commit -m modechange &&
-     GIT_TRACE=1 git rebase master
+       git checkout master &&
+       echo 1 >X &&
+       git add X &&
+       test_tick &&
+       git commit -m prepare &&
+       git checkout -b modechange HEAD^ &&
+       echo 1 >X &&
+       git add X &&
+       test_chmod +x A &&
+       test_tick &&
+       git commit -m modechange &&
+       GIT_TRACE=1 git rebase master
+'
+
+test_expect_success 'rebase is not broken by diff.renames' '
+       git config diff.renames copies &&
+       test_when_finished "git config --unset diff.renames" &&
+       git checkout filemove &&
+       GIT_TRACE=1 git rebase force-3way
+'
+
+test_expect_success 'setup: recover' '
+       test_might_fail git rebase --abort &&
+       git reset --hard &&
+       git checkout modechange
 '
 
 test_expect_success 'Show verbose error when HEAD could not be detached' '
-     : > B &&
-     test_must_fail git rebase topic 2> output.err > output.out &&
-     grep "Untracked working tree file .B. would be overwritten" output.err
+       >B &&
+       test_must_fail git rebase topic 2>output.err >output.out &&
+       grep "Untracked working tree file .B. would be overwritten" output.err
+'
+rm -f B
+
+test_expect_success 'dump usage when upstream arg is missing' '
+       git checkout -b usage topic &&
+       test_must_fail git rebase 2>error1 &&
+       grep "[Uu]sage" error1 &&
+       test_must_fail git rebase --abort 2>error2 &&
+       grep "No rebase in progress" error2 &&
+       test_must_fail git rebase --onto master 2>error3 &&
+       grep "[Uu]sage" error3 &&
+       ! grep "can.t shift" error3
 '
 
 test_expect_success 'rebase -q is quiet' '
-     rm B &&
-     git checkout -b quiet topic &&
-     git rebase -q master > output.out 2>&1 &&
-     test ! -s output.out
+       git checkout -b quiet topic &&
+       git rebase -q master >output.out 2>&1 &&
+       test ! -s output.out
 '
 
 test_expect_success 'Rebase a commit that sprinkles CRs in' '
index ee9a1b25e6a35adcb2350068d3b63b50bc9c24b3..9f03ce699e8f4c3c654065deae675d1a7b259c74 100755 (executable)
@@ -630,4 +630,28 @@ test_expect_success 'always cherry-pick with --no-ff' '
        test_cmp empty out
 '
 
+test_expect_success 'set up commits with funny messages' '
+       git checkout -b funny A &&
+       echo >>file1 &&
+       test_tick &&
+       git commit -a -m "end with slash\\" &&
+       echo >>file1 &&
+       test_tick &&
+       git commit -a -m "something (\000) that looks like octal" &&
+       echo >>file1 &&
+       test_tick &&
+       git commit -a -m "something (\n) that looks like a newline" &&
+       echo >>file1 &&
+       test_tick &&
+       git commit -a -m "another commit"
+'
+
+test_expect_success 'rebase-i history with funny messages' '
+       git rev-list A..funny >expect &&
+       test_tick &&
+       FAKE_LINES="1 2 3 4" git rebase -i A &&
+       git rev-list A.. >actual &&
+       test_cmp expect actual
+'
+
 test_done
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
new file mode 100755 (executable)
index 0000000..3b0d273
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+test_description='git rebase --continue tests'
+
+. ./test-lib.sh
+
+. "$TEST_DIRECTORY"/lib-rebase.sh
+
+set_fake_editor
+
+test_expect_success 'setup' '
+       test_commit "commit-new-file-F1" F1 1 &&
+       test_commit "commit-new-file-F2" F2 2 &&
+
+       git checkout -b topic HEAD^ &&
+       test_commit "commit-new-file-F2-on-topic-branch" F2 22 &&
+
+       git checkout master
+'
+
+test_expect_success 'interactive rebase --continue works with touched file' '
+       rm -fr .git/rebase-* &&
+       git reset --hard &&
+       git checkout master &&
+
+       FAKE_LINES="edit 1" git rebase -i HEAD^ &&
+       test-chmtime =-60 F1 &&
+       git rebase --continue
+'
+
+test_expect_success 'non-interactive rebase --continue works with touched file' '
+       rm -fr .git/rebase-* &&
+       git reset --hard &&
+       git checkout master &&
+
+       test_must_fail git rebase --onto master master topic &&
+       echo "Resolved" >F2 &&
+       git add F2 &&
+       test-chmtime =-60 F1 &&
+       git rebase --continue
+'
+
+test_done
index dadbbc2a9f9b70a4e33f5aa825b8f9fe14eec124..f038f34b7c03b419b9341770a6924767a0b8e8d7 100755 (executable)
@@ -17,17 +17,19 @@ test_expect_success \
     'prepare repository with topic branch, and check cherry finds the 2 patches from there' \
     'echo First > A &&
      git update-index --add A &&
+     test_tick &&
      git commit -m "Add A." &&
 
      git checkout -b my-topic-branch &&
 
      echo Second > B &&
      git update-index --add B &&
+     test_tick &&
      git commit -m "Add B." &&
 
-     sleep 2 &&
      echo AnotherSecond > C &&
      git update-index --add C &&
+     test_tick &&
      git commit -m "Add C." &&
 
      git checkout -f master &&
@@ -35,6 +37,7 @@ test_expect_success \
 
      echo Third >> A &&
      git update-index A &&
+     test_tick &&
      git commit -m "Modify A." &&
 
      expr "$(echo $(git cherry master my-topic-branch) )" : "+ [^ ]* + .*"
index e4fbf7a2107c680ee5c51f2ccf5297ed1fd4d868..bc7aedd0484ed5ad1115cac0f22943445d658f47 100755 (executable)
@@ -41,6 +41,24 @@ test_expect_success setup '
        git tag rename2
 '
 
+test_expect_success 'cherry-pick --nonsense' '
+
+       pos=$(git rev-parse HEAD) &&
+       git diff --exit-code HEAD &&
+       test_must_fail git cherry-pick --nonsense 2>msg &&
+       git diff --exit-code HEAD "$pos" &&
+       grep '[Uu]sage:' msg
+'
+
+test_expect_success 'revert --nonsense' '
+
+       pos=$(git rev-parse HEAD) &&
+       git diff --exit-code HEAD &&
+       test_must_fail git revert --nonsense 2>msg &&
+       git diff --exit-code HEAD "$pos" &&
+       grep '[Uu]sage:' msg
+'
+
 test_expect_success 'cherry-pick after renaming branch' '
 
        git checkout rename2 &&
diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh
new file mode 100755 (executable)
index 0000000..f90ed3d
--- /dev/null
@@ -0,0 +1,105 @@
+#!/bin/sh
+
+test_description='test cherry-picking many commits'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+       echo first > file1 &&
+       git add file1 &&
+       test_tick &&
+       git commit -m "first" &&
+       git tag first &&
+
+       git checkout -b other &&
+       for val in second third fourth
+       do
+               echo $val >> file1 &&
+               git add file1 &&
+               test_tick &&
+               git commit -m "$val" &&
+               git tag $val
+       done
+'
+
+test_expect_success 'cherry-pick first..fourth works' '
+       git checkout -f master &&
+       git reset --hard first &&
+       test_tick &&
+       git cherry-pick first..fourth &&
+       git diff --quiet other &&
+       git diff --quiet HEAD other &&
+       test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
+'
+
+test_expect_success 'cherry-pick --ff first..fourth works' '
+       git checkout -f master &&
+       git reset --hard first &&
+       test_tick &&
+       git cherry-pick --ff first..fourth &&
+       git diff --quiet other &&
+       git diff --quiet HEAD other &&
+       test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify fourth)"
+'
+
+test_expect_success 'cherry-pick -n first..fourth works' '
+       git checkout -f master &&
+       git reset --hard first &&
+       test_tick &&
+       git cherry-pick -n first..fourth &&
+       git diff --quiet other &&
+       git diff --cached --quiet other &&
+       git diff --quiet HEAD first
+'
+
+test_expect_success 'revert first..fourth works' '
+       git checkout -f master &&
+       git reset --hard fourth &&
+       test_tick &&
+       git revert first..fourth &&
+       git diff --quiet first &&
+       git diff --cached --quiet first &&
+       git diff --quiet HEAD first
+'
+
+test_expect_success 'revert ^first fourth works' '
+       git checkout -f master &&
+       git reset --hard fourth &&
+       test_tick &&
+       git revert ^first fourth &&
+       git diff --quiet first &&
+       git diff --cached --quiet first &&
+       git diff --quiet HEAD first
+'
+
+test_expect_success 'revert fourth fourth~1 fourth~2 works' '
+       git checkout -f master &&
+       git reset --hard fourth &&
+       test_tick &&
+       git revert fourth fourth~1 fourth~2 &&
+       git diff --quiet first &&
+       git diff --cached --quiet first &&
+       git diff --quiet HEAD first
+'
+
+test_expect_success 'cherry-pick -3 fourth works' '
+       git checkout -f master &&
+       git reset --hard first &&
+       test_tick &&
+       git cherry-pick -3 fourth &&
+       git diff --quiet other &&
+       git diff --quiet HEAD other &&
+       test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
+'
+
+test_expect_success 'cherry-pick --stdin works' '
+       git checkout -f master &&
+       git reset --hard first &&
+       test_tick &&
+       git rev-list --reverse first..fourth | git cherry-pick --stdin &&
+       git diff --quiet other &&
+       git diff --quiet HEAD other &&
+       test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
+'
+
+test_done
index 0aaf0ad84b05e1ee17e9789811ea06f2d2798556..b514cbb60665fef9d5cd67b8f7bcd8e8a3c2d0a5 100755 (executable)
@@ -39,7 +39,7 @@ if test -f test-file
 then
        test_set_prereq RO_DIR
 else
-       say 'skipping removal failure test (perhaps running as root?)'
+       skip_all='skipping removal failure test (perhaps running as root?)'
 fi
 chmod 775 .
 rm -f test-file
index 525c9a8fdfb4953612e6946994c8e555f676bfd2..7d7140db380225bfffd3b64c125e2599b6be77c2 100755 (executable)
@@ -26,7 +26,7 @@ test_expect_success \
         chmod 755 xfoo1 &&
         git add xfoo1 &&
         case "`git ls-files --stage xfoo1`" in
-        100644" "*xfoo1) echo ok;;
+        100644" "*xfoo1) echo pass;;
         *) echo fail; git ls-files --stage xfoo1; (exit 1);;
         esac'
 
@@ -35,7 +35,7 @@ test_expect_success SYMLINKS 'git add: filemode=0 should not get confused by sym
        ln -s foo xfoo1 &&
        git add xfoo1 &&
        case "`git ls-files --stage xfoo1`" in
-       120000" "*xfoo1) echo ok;;
+       120000" "*xfoo1) echo pass;;
        *) echo fail; git ls-files --stage xfoo1; (exit 1);;
        esac
 '
@@ -47,7 +47,7 @@ test_expect_success \
         chmod 755 xfoo2 &&
         git update-index --add xfoo2 &&
         case "`git ls-files --stage xfoo2`" in
-        100644" "*xfoo2) echo ok;;
+        100644" "*xfoo2) echo pass;;
         *) echo fail; git ls-files --stage xfoo2; (exit 1);;
         esac'
 
@@ -56,7 +56,7 @@ test_expect_success SYMLINKS 'git add: filemode=0 should not get confused by sym
        ln -s foo xfoo2 &&
        git update-index --add xfoo2 &&
        case "`git ls-files --stage xfoo2`" in
-       120000" "*xfoo2) echo ok;;
+       120000" "*xfoo2) echo pass;;
        *) echo fail; git ls-files --stage xfoo2; (exit 1);;
        esac
 '
@@ -67,7 +67,7 @@ test_expect_success SYMLINKS \
         ln -s xfoo2 xfoo3 &&
         git update-index --add xfoo3 &&
         case "`git ls-files --stage xfoo3`" in
-        120000" "*xfoo3) echo ok;;
+        120000" "*xfoo3) echo pass;;
         *) echo fail; git ls-files --stage xfoo3; (exit 1);;
         esac'
 
@@ -172,7 +172,7 @@ test_expect_success 'git add --refresh' '
        test -z "`git diff-index HEAD -- foo`" &&
        git read-tree HEAD &&
        case "`git diff-index HEAD -- foo`" in
-       :100644" "*"M   foo") echo ok;;
+       :100644" "*"M   foo") echo pass;;
        *) echo fail; (exit 1);;
        esac &&
        git add --refresh -- foo &&
@@ -260,4 +260,32 @@ test_expect_success '"add non-existent" should fail' '
        ! (git ls-files | grep "non-existent")
 '
 
+test_expect_success 'git add --dry-run of existing changed file' "
+       echo new >>track-this &&
+       git add --dry-run track-this >actual 2>&1 &&
+       echo \"add 'track-this'\" | test_cmp - actual
+"
+
+test_expect_success 'git add --dry-run of non-existing file' "
+       echo ignored-file >>.gitignore &&
+       test_must_fail git add --dry-run track-this ignored-file >actual 2>&1 &&
+       echo \"fatal: pathspec 'ignored-file' did not match any files\" | test_cmp - actual
+"
+
+cat >expect.err <<\EOF
+The following paths are ignored by one of your .gitignore files:
+ignored-file
+Use -f if you really want to add them.
+fatal: no files added
+EOF
+cat >expect.out <<\EOF
+add 'track-this'
+EOF
+
+test_expect_success 'git add --dry-run --ignore-missing of non-existing file' '
+       test_must_fail git add --dry-run --ignore-missing track-this ignored-file >actual.out 2>actual.err &&
+       test_cmp expect.out actual.out &&
+       test_cmp expect.err actual.err
+'
+
 test_done
index b6eba6a83904a00724b7b550a9bc3b1b35825bee..7ad8465f8f89656bf0ce57feb45e12bc9cea5d65 100755 (executable)
@@ -4,7 +4,7 @@ test_description='add -i basic tests'
 . ./test-lib.sh
 
 if ! test_have_prereq PERL; then
-       say 'skipping git add -i tests, perl not available'
+       skip_all='skipping git add -i tests, perl not available'
        test_done
 fi
 
@@ -154,7 +154,7 @@ rm -f .gitignore
 
 if test "$(git config --bool core.filemode)" = false
 then
-       say 'skipping filemode tests (filesystem does not properly support modes)'
+       say 'skipping filemode tests (filesystem does not properly support modes)'
 else
        test_set_prereq FILEMODE
 fi
index 29103f65dc60a81d071b9dd5600f416b3a31860f..147e634cd65b616ea6c8059897f191b761996c6f 100755 (executable)
@@ -17,7 +17,7 @@ DQ='"'
 echo foo 2>/dev/null > "Name and an${HT}HT"
 test -f "Name and an${HT}HT" || {
        # since FAT/NTFS does not allow tabs in filenames, skip this test
-       say 'Your filesystem does not allow tabs in filenames, test skipped.'
+       skip_all='Your filesystem does not allow tabs in filenames, test skipped.'
        test_done
 }
 
index 8fe14ccc5444df95960bee88e5b79eb68156572b..62e208aadd592ddaa5c519cf328e636d948221c0 100755 (executable)
@@ -81,7 +81,7 @@ test_expect_success 'drop top stash' '
        git stash &&
        git stash drop &&
        git stash list > stashlist2 &&
-       diff stashlist1 stashlist2 &&
+       test_cmp stashlist1 stashlist2 &&
        git stash apply &&
        test 3 = $(cat file) &&
        test 1 = $(git show :file) &&
index 18695ce8218a7b383258eeb0bad84b4d4bde45be..73441a516572dcf826582c04f3fe9d3ad0c1a88c 100755 (executable)
@@ -135,7 +135,7 @@ cmp_diff_files_output () {
     # filesystem.
     sed <"$2" >.test-tmp \
        -e '/^:000000 /d;s/'$x40'\( [MCRNDU][0-9]*\)    /'$z40'\1       /' &&
-    diff "$1" .test-tmp
+    test_cmp "$1" .test-tmp
 }
 
 test_expect_success \
index a4da1196a93a00502c8945a14e3aafd628efda53..1a09e8db403adc9c65859b0a369ce9d06e00e6f4 100755 (executable)
@@ -14,7 +14,7 @@ by an edit for them.
 
 if ! test_have_prereq SYMLINKS
 then
-       say 'Symbolic links not supported, skipping tests.'
+       skip_all='Symbolic links not supported, skipping tests.'
        test_done
 fi
 
index d7e327cc5bc5984546032fb085fb581de5755e11..918a21a2f41caf2e8ed6bb6120631ff0e4ccb0fc 100755 (executable)
@@ -11,7 +11,7 @@ test_description='Test diff of symlinks.
 
 if ! test_have_prereq SYMLINKS
 then
-       say 'Symbolic links not supported, skipping tests.'
+       skip_all='Symbolic links not supported, skipping tests.'
        test_done
 fi
 
@@ -54,7 +54,7 @@ EOF
 
 test_expect_success \
     'diff removed symlink' \
-    'rm frotz &&
+    'mv frotz frotz2 &&
     git diff-index -M -p $tree > current &&
     compare_diff_patch current expected'
 
@@ -64,8 +64,7 @@ EOF
 
 test_expect_success \
     'diff identical, but newly created symlink' \
-    'sleep 3 &&
-    ln -s xyzzy frotz &&
+    'ln -s xyzzy frotz &&
     git diff-index -M -p $tree > current &&
     compare_diff_patch current expected'
 
index 8dab4bf93ebd5f3e5ee6e899890d6e53af9ab967..1f0f9ad44b241e57e867c0676b73f37a1dc93d60 100644 (file)
@@ -18,6 +18,9 @@ A U Thor (2):
  create mode 100644 file1
  delete mode 100644 file2
 
+-- 
+g-i-t--v-e-r-s-i-o-n
+
 From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
 From: A U Thor <author@example.com>
 Date: Mon, 26 Jun 2006 00:01:00 +0000
index d21c37f3a20c42b05044e45c5e5af71294c8420c..f87434b9f8e0d520813389e6ea7c94f74222767b 100755 (executable)
@@ -613,4 +613,56 @@ test_expect_success 'format-patch --ignore-if-in-upstream HEAD' '
        git format-patch --ignore-if-in-upstream HEAD
 '
 
+test_expect_success 'format-patch --signature' '
+       git format-patch --stdout --signature="my sig" -1 >output &&
+       grep "my sig" output
+'
+
+test_expect_success 'format-patch with format.signature config' '
+       git config format.signature "config sig" &&
+       git format-patch --stdout -1 >output &&
+       grep "config sig" output
+'
+
+test_expect_success 'format-patch --signature overrides format.signature' '
+       git config format.signature "config sig" &&
+       git format-patch --stdout --signature="overrides" -1 >output &&
+       ! grep "config sig" output &&
+       grep "overrides" output
+'
+
+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 &&
+       ! grep "config sig" output &&
+       ! grep "my sig" output &&
+       ! grep "^-- \$" output
+'
+
+test_expect_success 'format-patch --signature --cover-letter' '
+       git config --unset-all format.signature &&
+       git format-patch --stdout --signature="my sig" --cover-letter \
+               -1 >output &&
+       grep "my sig" output &&
+       test 2 = $(grep "my sig" output | wc -l)
+'
+
+test_expect_success 'format.signature="" supresses signatures' '
+       git config format.signature "" &&
+       git format-patch --stdout -1 >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 &&
+       ! grep "^-- \$" output
+'
+
+test_expect_success 'format-patch --signature="" supresses signatures' '
+       git format-patch --signature="" -1 >output &&
+       ! grep "^-- \$" output
+'
+
 test_done
index 7e78851a113918f798d1b9e1b3f59e74e6406e78..935d101fe8d880ff426452ca6f611ce8d30b8bc1 100755 (executable)
@@ -352,6 +352,48 @@ test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab:
 
 '
 
+test_expect_success 'check tabs as indentation (tab-in-indent: off)' '
+
+       git config core.whitespace "-tab-in-indent" &&
+       echo "  foo ();" > x &&
+       git diff --check
+
+'
+
+test_expect_success 'check tabs as indentation (tab-in-indent: on)' '
+
+       git config core.whitespace "tab-in-indent" &&
+       echo "  foo ();" > x &&
+       test_must_fail git diff --check
+
+'
+
+test_expect_success 'check tabs and spaces as indentation (tab-in-indent: on)' '
+
+       git config core.whitespace "tab-in-indent" &&
+       echo "                  foo ();" > x &&
+       test_must_fail git diff --check
+
+'
+
+test_expect_success 'check tab-in-indent and indent-with-non-tab conflict' '
+
+       git config core.whitespace "tab-in-indent,indent-with-non-tab" &&
+       echo "foo ();" > x &&
+       test_must_fail git diff --check
+
+'
+
+test_expect_success 'check tab-in-indent excluded from wildcard whitespace attribute' '
+
+       git config --unset core.whitespace &&
+       echo "x whitespace" > .gitattributes &&
+       echo "    foo ();" > x &&
+       git diff --check &&
+       rm -f .gitattributes
+
+'
+
 test_expect_success 'line numbers in --check output are correct' '
 
        echo "" > x &&
index 55eb5f83f17c0ebfb537d390fd3913b7c89d65f4..34e5144eed8958a3f3341574ff8ecbcc6a4157a9 100755 (executable)
@@ -14,7 +14,7 @@ P2='pathname with SP'
 P3='pathname
 with LF'
 : 2>/dev/null >"$P1" && test -f "$P1" && rm -f "$P1" || {
-       say 'Your filesystem does not allow tabs in filenames, test skipped.'
+       skip_all='Your filesystem does not allow tabs in filenames, test skipped.'
        test_done
 }
 
index 9bdf6596d82878f709a375084095697124a97609..40a95a149e4e84924d961d43f03115f466a9acc1 100755 (executable)
@@ -6,7 +6,7 @@ test_description='typechange rename detection'
 
 if ! test_have_prereq SYMLINKS
 then
-       say 'Symbolic links not supported, skipping tests.'
+       skip_all='Symbolic links not supported, skipping tests.'
        test_done
 fi
 
index 83c19147717f2a5e6c634918c74b93e54376d725..1bd8e5ee3ac5ca4d101738048e6769ae798b23dc 100755 (executable)
@@ -103,7 +103,15 @@ test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)'
        git diff HEAD >actual &&
        sed -e "1,/^@@/d" actual >actual.body &&
        expect_from_to >expect.body $subprev $subprev-dirty &&
-       test_cmp expect.body actual.body
+       test_cmp expect.body actual.body &&
+       git diff --ignore-submodules HEAD >actual2 &&
+       ! test -s actual2 &&
+       git diff --ignore-submodules=untracked HEAD >actual3 &&
+       sed -e "1,/^@@/d" actual3 >actual3.body &&
+       expect_from_to >expect.body $subprev $subprev-dirty &&
+       test_cmp expect.body actual3.body &&
+       git diff --ignore-submodules=dirty HEAD >actual4 &&
+       ! test -s actual4
 '
 
 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
@@ -129,7 +137,13 @@ test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)'
        git diff HEAD >actual &&
        sed -e "1,/^@@/d" actual >actual.body &&
        expect_from_to >expect.body $subprev $subprev-dirty &&
-       test_cmp expect.body actual.body
+       test_cmp expect.body actual.body &&
+       git diff --ignore-submodules=all HEAD >actual2 &&
+       ! test -s actual2 &&
+       git diff --ignore-submodules=untracked HEAD >actual3 &&
+       ! test -s actual3 &&
+       git diff --ignore-submodules=dirty HEAD >actual4 &&
+       ! test -s actual4
 '
 
 test_expect_success 'git diff (empty submodule dir)' '
index 2e2e103b31332ea2f74de5d5e6e49c00b13dfa8a..6f7548c3a144ecada6642eccee6b0f687baafb2d 100755 (executable)
@@ -55,6 +55,93 @@ test_expect_success 'word diff with runs of whitespace' '
 
 '
 
+test_expect_success '--word-diff=color' '
+
+       word_diff --word-diff=color
+
+'
+
+test_expect_success '--color --word-diff=color' '
+
+       word_diff --color --word-diff=color
+
+'
+
+sed 's/#.*$//' > expect <<EOF
+diff --git a/pre b/post
+index 330b04f..5ed8eff 100644
+--- a/pre
++++ b/post
+@@ -1,3 +1,7 @@
+-h(4)
++h(4),hh[44]
+~
+ # significant space
+~
+ a = b + c
+~
+~
++aa = a
+~
+~
++aeff = aeff * ( aaa )
+~
+EOF
+
+test_expect_success '--word-diff=porcelain' '
+
+       word_diff --word-diff=porcelain
+
+'
+
+cat > expect <<EOF
+diff --git a/pre b/post
+index 330b04f..5ed8eff 100644
+--- a/pre
++++ b/post
+@@ -1,3 +1,7 @@
+[-h(4)-]{+h(4),hh[44]+}
+
+a = b + c
+
+{+aa = a+}
+
+{+aeff = aeff * ( aaa )+}
+EOF
+
+test_expect_success '--word-diff=plain' '
+
+       word_diff --word-diff=plain
+
+'
+
+test_expect_success '--word-diff=plain --no-color' '
+
+       word_diff --word-diff=plain --no-color
+
+'
+
+cat > expect <<EOF
+<WHITE>diff --git a/pre b/post<RESET>
+<WHITE>index 330b04f..5ed8eff 100644<RESET>
+<WHITE>--- a/pre<RESET>
+<WHITE>+++ b/post<RESET>
+<CYAN>@@ -1,3 +1,7 @@<RESET>
+<RED>[-h(4)-]<RESET><GREEN>{+h(4),hh[44]+}<RESET>
+
+a = b + c<RESET>
+
+<GREEN>{+aa = a+}<RESET>
+
+<GREEN>{+aeff = aeff * ( aaa )+}<RESET>
+EOF
+
+test_expect_success '--word-diff=plain --color' '
+
+       word_diff --word-diff=plain --color
+
+'
+
 cat > expect <<\EOF
 <WHITE>diff --git a/pre b/post<RESET>
 <WHITE>index 330b04f..5ed8eff 100644<RESET>
@@ -143,6 +230,25 @@ test_expect_success 'command-line overrides config' '
        word_diff --color-words="[a-z]+"
 '
 
+cat > expect <<\EOF
+<WHITE>diff --git a/pre b/post<RESET>
+<WHITE>index 330b04f..5ed8eff 100644<RESET>
+<WHITE>--- a/pre<RESET>
+<WHITE>+++ b/post<RESET>
+<CYAN>@@ -1,3 +1,7 @@<RESET>
+h(4),<GREEN>{+hh+}<RESET>[44]
+
+a = b + c<RESET>
+
+<GREEN>{+aa = a+}<RESET>
+
+<GREEN>{+aeff = aeff * ( aaa+}<RESET> )
+EOF
+
+test_expect_success 'command-line overrides config: --word-diff-regex' '
+       word_diff --color --word-diff-regex="[a-z]+"
+'
+
 cp expect.non-whitespace-is-word expect
 
 test_expect_success '.gitattributes override config' '
@@ -209,4 +315,20 @@ test_expect_success 'test when words are only removed at the end' '
 
 '
 
+cat > expect <<\EOF
+diff --git a/pre b/post
+index 289cb9d..2d06f37 100644
+--- a/pre
++++ b/post
+@@ -1 +1 @@
+-(:
++(
+EOF
+
+test_expect_success '--word-diff=none' '
+
+       word_diff --word-diff=plain --word-diff=none
+
+'
+
 test_done
similarity index 74%
rename from t/t4041-diff-submodule.sh
rename to t/t4041-diff-submodule-option.sh
index 019acb926d6765bf24e1dfe4bea2a9dba28ca797..8e391cf9a72c6518217526155cbea93d74b9e626 100755 (executable)
@@ -205,6 +205,21 @@ Submodule sm1 contains untracked content
 EOF
 "
 
+test_expect_success 'submodule contains untracked content (untracked ignored)' "
+       git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
+       ! test -s actual
+"
+
+test_expect_success 'submodule contains untracked content (dirty ignored)' "
+       git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
+       ! test -s actual
+"
+
+test_expect_success 'submodule contains untracked content (all ignored)' "
+       git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
+       ! test -s actual
+"
+
 test_expect_success 'submodule contains untracked and modifed content' "
        echo new > sm1/foo6 &&
        git diff-index -p --submodule=log HEAD >actual &&
@@ -214,6 +229,26 @@ Submodule sm1 contains modified content
 EOF
 "
 
+test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' "
+       echo new > sm1/foo6 &&
+       git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
+       diff actual - <<-EOF
+Submodule sm1 contains modified content
+EOF
+"
+
+test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' "
+       echo new > sm1/foo6 &&
+       git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
+       ! test -s actual
+"
+
+test_expect_success 'submodule contains untracked and modifed content (all ignored)' "
+       echo new > sm1/foo6 &&
+       git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
+       ! test -s actual
+"
+
 test_expect_success 'submodule contains modifed content' "
        rm -f sm1/new-file &&
        git diff-index -p --submodule=log HEAD >actual &&
@@ -242,6 +277,27 @@ Submodule sm1 $head6..$head8:
 EOF
 "
 
+test_expect_success 'modified submodule contains untracked content (untracked ignored)' "
+       git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
+       diff actual - <<-EOF
+Submodule sm1 $head6..$head8:
+  > change
+EOF
+"
+
+test_expect_success 'modified submodule contains untracked content (dirty ignored)' "
+       git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
+       diff actual - <<-EOF
+Submodule sm1 $head6..$head8:
+  > change
+EOF
+"
+
+test_expect_success 'modified submodule contains untracked content (all ignored)' "
+       git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
+       ! test -s actual
+"
+
 test_expect_success 'modified submodule contains untracked and modifed content' "
        echo modification >> sm1/foo6 &&
        git diff-index -p --submodule=log HEAD >actual &&
@@ -253,6 +309,31 @@ Submodule sm1 $head6..$head8:
 EOF
 "
 
+test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' "
+       echo modification >> sm1/foo6 &&
+       git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
+       diff actual - <<-EOF
+Submodule sm1 contains modified content
+Submodule sm1 $head6..$head8:
+  > change
+EOF
+"
+
+test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' "
+       echo modification >> sm1/foo6 &&
+       git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
+       diff actual - <<-EOF
+Submodule sm1 $head6..$head8:
+  > change
+EOF
+"
+
+test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' "
+       echo modification >> sm1/foo6 &&
+       git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
+       ! test -s actual
+"
+
 test_expect_success 'modified submodule contains modifed content' "
        rm -f sm1/new-file &&
        git diff-index -p --submodule=log HEAD >actual &&
diff --git a/t/t4042-diff-textconv-caching.sh b/t/t4042-diff-textconv-caching.sh
new file mode 100755 (executable)
index 0000000..91f8198
--- /dev/null
@@ -0,0 +1,109 @@
+#!/bin/sh
+
+test_description='test textconv caching'
+. ./test-lib.sh
+
+cat >helper <<'EOF'
+#!/bin/sh
+sed 's/^/converted: /' "$@" >helper.out
+cat helper.out
+EOF
+chmod +x helper
+
+test_expect_success 'setup' '
+       echo foo content 1 >foo.bin &&
+       echo bar content 1 >bar.bin &&
+       git add . &&
+       git commit -m one &&
+       echo foo content 2 >foo.bin &&
+       echo bar content 2 >bar.bin &&
+       git commit -a -m two &&
+       echo "*.bin diff=magic" >.gitattributes &&
+       git config diff.magic.textconv ./helper &&
+       git config diff.magic.cachetextconv true
+'
+
+cat >expect <<EOF
+diff --git a/bar.bin b/bar.bin
+index fcf9166..28283d5 100644
+--- a/bar.bin
++++ b/bar.bin
+@@ -1 +1 @@
+-converted: bar content 1
++converted: bar content 2
+diff --git a/foo.bin b/foo.bin
+index d5b9fe3..1345db2 100644
+--- a/foo.bin
++++ b/foo.bin
+@@ -1 +1 @@
+-converted: foo content 1
++converted: foo content 2
+EOF
+
+test_expect_success 'first textconv works' '
+       git diff HEAD^ HEAD >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cached textconv produces same output' '
+       git diff HEAD^ HEAD >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cached textconv does not run helper' '
+       rm -f helper.out &&
+       git diff HEAD^ HEAD >actual &&
+       test_cmp expect actual &&
+       ! test -r helper.out
+'
+
+cat >expect <<EOF
+diff --git a/bar.bin b/bar.bin
+index fcf9166..28283d5 100644
+--- a/bar.bin
++++ b/bar.bin
+@@ -1,2 +1,2 @@
+ converted: other
+-converted: bar content 1
++converted: bar content 2
+diff --git a/foo.bin b/foo.bin
+index d5b9fe3..1345db2 100644
+--- a/foo.bin
++++ b/foo.bin
+@@ -1,2 +1,2 @@
+ converted: other
+-converted: foo content 1
++converted: foo content 2
+EOF
+test_expect_success 'changing textconv invalidates cache' '
+       echo other >other &&
+       git config diff.magic.textconv "./helper other" &&
+       git diff HEAD^ HEAD >actual &&
+       test_cmp expect actual
+'
+
+cat >expect <<EOF
+diff --git a/bar.bin b/bar.bin
+index fcf9166..28283d5 100644
+--- a/bar.bin
++++ b/bar.bin
+@@ -1,2 +1,2 @@
+ converted: other
+-converted: bar content 1
++converted: bar content 2
+diff --git a/foo.bin b/foo.bin
+index d5b9fe3..1345db2 100644
+--- a/foo.bin
++++ b/foo.bin
+@@ -1 +1 @@
+-converted: foo content 1
++converted: foo content 2
+EOF
+test_expect_success 'switching diff driver produces correct results' '
+       git config diff.moremagic.textconv ./helper &&
+       echo foo.bin diff=moremagic >>.gitattributes &&
+       git diff HEAD^ HEAD >actual &&
+       test_cmp expect actual
+'
+
+test_done
diff --git a/t/t4044-diff-index-unique-abbrev.sh b/t/t4044-diff-index-unique-abbrev.sh
new file mode 100755 (executable)
index 0000000..d5ce72b
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+test_description='test unique sha1 abbreviation on "index from..to" line'
+. ./test-lib.sh
+
+cat >expect_initial <<EOF
+100644 blob 51d2738463ea4ca66f8691c91e33ce64b7d41bb1   foo
+EOF
+
+cat >expect_update <<EOF
+100644 blob 51d2738efb4ad8a1e40bed839ab8e116f0a15e47   foo
+EOF
+
+test_expect_success 'setup' '
+       echo 4827 > foo &&
+       git add foo &&
+       git commit -m "initial" &&
+       git cat-file -p HEAD: > actual &&
+       test_cmp expect_initial actual &&
+       echo 11742 > foo &&
+       git commit -a -m "update" &&
+       git cat-file -p HEAD: > actual &&
+       test_cmp expect_update actual
+'
+
+cat >expect <<EOF
+index 51d27384..51d2738e 100644
+EOF
+
+test_expect_success 'diff does not produce ambiguous index line' '
+       git diff HEAD^..HEAD | grep index > actual &&
+       test_cmp expect actual
+'
+
+test_done
diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh
new file mode 100755 (executable)
index 0000000..8a3c63b
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+test_description='diff --relative tests'
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       git commit --allow-empty -m empty &&
+       echo content >file1 &&
+       mkdir subdir &&
+       echo other content >subdir/file2 &&
+       git add . &&
+       git commit -m one
+'
+
+check_diff() {
+expect=$1; shift
+cat >expected <<EOF
+diff --git a/$expect b/$expect
+new file mode 100644
+index 0000000..25c05ef
+--- /dev/null
++++ b/$expect
+@@ -0,0 +1 @@
++other content
+EOF
+test_expect_success "-p $*" "
+       git diff -p $* HEAD^ >actual &&
+       test_cmp expected actual
+"
+}
+
+check_stat() {
+expect=$1; shift
+cat >expected <<EOF
+ $expect |    1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
+EOF
+test_expect_success "--stat $*" "
+       git diff --stat $* HEAD^ >actual &&
+       test_cmp expected actual
+"
+}
+
+check_raw() {
+expect=$1; shift
+cat >expected <<EOF
+:000000 100644 0000000000000000000000000000000000000000 25c05ef3639d2d270e7fe765a67668f098092bc5 A     $expect
+EOF
+test_expect_success "--raw $*" "
+       git diff --no-abbrev --raw $* HEAD^ >actual &&
+       test_cmp expected actual
+"
+}
+
+for type in diff stat raw; do
+       check_$type file2 --relative=subdir/
+       check_$type file2 --relative=subdir
+       check_$type dir/file2 --relative=sub
+done
+
+test_done
index 99ec13dd531c71299681acc3eb678b490ff68707..164d58c222088bd42becf07c044f51bf23eda8b6 100755 (executable)
@@ -11,7 +11,7 @@ test_description='git apply should not get confused with type changes.
 
 if ! test_have_prereq SYMLINKS
 then
-       say 'Symbolic links not supported, skipping tests.'
+       skip_all='Symbolic links not supported, skipping tests.'
        test_done
 fi
 
index b852e5898009bca0205c231033f8f72f48962b81..aff4348034b21644818fb8f938ef006001b0b099 100755 (executable)
@@ -11,7 +11,7 @@ test_description='git apply symlinks and partial files
 
 if ! test_have_prereq SYMLINKS
 then
-       say 'Symbolic links not supported, skipping tests.'
+       skip_all='Symbolic links not supported, skipping tests.'
        test_done
 fi
 
index 0d3c1d5dd5c0f35f9cc44eab4fcba5ba2e36ddd7..923fcab7f96a76ee7038bfcb20b1270565bc2230 100755 (executable)
@@ -5,7 +5,7 @@ test_description='apply to deeper directory without getting fooled with symlink'
 
 if ! test_have_prereq SYMLINKS
 then
-       say 'Symbolic links not supported, skipping tests.'
+       skip_all='Symbolic links not supported, skipping tests.'
        test_done
 fi
 
index 451d75e3fb2ea3efb17825f6af92fa3213c620aa..8a676a5dcd113418c2bd4ea4aa885fddd5951a3a 100755 (executable)
@@ -11,21 +11,22 @@ prepare_test_file () {
        #       !  trailing-space
        #       @  space-before-tab
        #       #  indent-with-non-tab
+       #       %  tab-in-indent
        sed -e "s/_/ /g" -e "s/>/       /" <<-\EOF
                An_SP in an ordinary line>and a HT.
-               >A HT.
-               _>A SP and a HT (@).
-               _>_A SP, a HT and a SP (@).
+               >A HT (%).
+               _>A SP and a HT (@%).
+               _>_A SP, a HT and a SP (@%).
                _______Seven SP.
                ________Eight SP (#).
-               _______>Seven SP and a HT (@).
-               ________>Eight SP and a HT (@#).
-               _______>_Seven SP, a HT and a SP (@).
-               ________>_Eight SP, a HT and a SP (@#).
+               _______>Seven SP and a HT (@%).
+               ________>Eight SP and a HT (@#%).
+               _______>_Seven SP, a HT and a SP (@%).
+               ________>_Eight SP, a HT and a SP (@#%).
                _______________Fifteen SP (#).
-               _______________>Fifteen SP and a HT (@#).
+               _______________>Fifteen SP and a HT (@#%).
                ________________Sixteen SP (#).
-               ________________>Sixteen SP and a HT (@#).
+               ________________>Sixteen SP and a HT (@#%).
                _____a__Five SP, a non WS, two SP.
                A line with a (!) trailing SP_
                A line with a (!) trailing HT>
@@ -39,12 +40,11 @@ apply_patch () {
 }
 
 test_fix () {
-
        # fix should not barf
        apply_patch --whitespace=fix || return 1
 
        # find touched lines
-       diff file target | sed -n -e "s/^> //p" >fixed
+       $DIFF file target | sed -n -e "s/^> //p" >fixed
 
        # the changed lines are all expeced to change
        fixed_cnt=$(wc -l <fixed)
@@ -85,14 +85,14 @@ test_expect_success setup '
 test_expect_success 'whitespace=nowarn, default rule' '
 
        apply_patch --whitespace=nowarn &&
-       diff file target
+       test_cmp file target
 
 '
 
 test_expect_success 'whitespace=warn, default rule' '
 
        apply_patch --whitespace=warn &&
-       diff file target
+       test_cmp file target
 
 '
 
@@ -108,7 +108,7 @@ test_expect_success 'whitespace=error-all, no rule' '
 
        git config core.whitespace -trailing,-space-before,-indent &&
        apply_patch --whitespace=error-all &&
-       diff file target
+       test_cmp file target
 
 '
 
@@ -117,7 +117,7 @@ test_expect_success 'whitespace=error-all, no rule (attribute)' '
        git config --unset core.whitespace &&
        echo "target -whitespace" >.gitattributes &&
        apply_patch --whitespace=error-all &&
-       diff file target
+       test_cmp file target
 
 '
 
@@ -130,20 +130,25 @@ do
                for i in - ''
                do
                        case "$i" in '') ti='#' ;; *) ti= ;; esac
-                       rule=${t}trailing,${s}space,${i}indent
-
-                       rm -f .gitattributes
-                       test_expect_success "rule=$rule" '
-                               git config core.whitespace "$rule" &&
-                               test_fix "$tt$ts$ti"
-                       '
-
-                       test_expect_success "rule=$rule (attributes)" '
-                               git config --unset core.whitespace &&
-                               echo "target whitespace=$rule" >.gitattributes &&
-                               test_fix "$tt$ts$ti"
-                       '
-
+                       for h in - ''
+                       do
+                               [ -z "$h$i" ] && continue
+                               case "$h" in '') th='%' ;; *) th= ;; esac
+                               rule=${t}trailing,${s}space,${i}indent,${h}tab
+
+                               rm -f .gitattributes
+                               test_expect_success "rule=$rule" '
+                                       git config core.whitespace "$rule" &&
+                                       test_fix "$tt$ts$ti$th"
+                               '
+
+                               test_expect_success "rule=$rule (attributes)" '
+                                       git config --unset core.whitespace &&
+                                       echo "target whitespace=$rule" >.gitattributes &&
+                                       test_fix "$tt$ts$ti$th"
+                               '
+
+                       done
                done
        done
 done
index 3a8202ea9311b1c90158ad0d115dda985060fdeb..77200c0b2d969d621623f3be8621a3f9925d50a5 100755 (executable)
@@ -27,7 +27,7 @@ test_expect_success 'apply same filename with independent changes' '
        cp same_fn same_fn2 &&
        git reset --hard &&
        git apply patch0 &&
-       diff same_fn same_fn2
+       test_cmp same_fn same_fn2
 '
 
 test_expect_success 'apply same filename with overlapping changes' '
@@ -40,7 +40,7 @@ test_expect_success 'apply same filename with overlapping changes' '
        cp same_fn same_fn2 &&
        git reset --hard &&
        git apply patch0 &&
-       diff same_fn same_fn2
+       test_cmp same_fn same_fn2
 '
 
 test_expect_success 'apply same new filename after rename' '
@@ -54,7 +54,7 @@ test_expect_success 'apply same new filename after rename' '
        cp new_fn new_fn2 &&
        git reset --hard &&
        git apply --index patch1 &&
-       diff new_fn new_fn2
+       test_cmp new_fn new_fn2
 '
 
 test_expect_success 'apply same old filename after rename -- should fail.' '
index 810b04b817c79d2b4c478f767843b4e7a42e0bed..1c3d8ed548e629689517661cd1fc6c21d98ccc80 100755 (executable)
@@ -4,66 +4,71 @@ test_description='git am running'
 
 . ./test-lib.sh
 
-cat >msg <<EOF
-second
-
-Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy
-eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
-voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
-kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
-ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
-tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
-vero eos et accusam et justo duo dolores et ea rebum.
-
-       Duis autem vel eum iriure dolor in hendrerit in vulputate velit
-       esse molestie consequat, vel illum dolore eu feugiat nulla facilisis
-       at vero eros et accumsan et iusto odio dignissim qui blandit
-       praesent luptatum zzril delenit augue duis dolore te feugait nulla
-       facilisi.
-
-
-Lorem ipsum dolor sit amet,
-consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
-laoreet dolore magna aliquam erat volutpat.
-
-  git
-  ---
-  +++
-
-Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
-lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
-dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
-dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
-dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
-feugait nulla facilisi.
-EOF
-
-cat >failmail <<EOF
-From foo@example.com Fri May 23 10:43:49 2008
-From:  foo@example.com
-To:    bar@example.com
-Subject: Re: [RFC/PATCH] git-foo.sh
-Date:  Fri, 23 May 2008 05:23:42 +0200
-
-Sometimes we have to find out that there's nothing left.
-
-EOF
-
-cat >pine <<EOF
-From MAILER-DAEMON Fri May 23 10:43:49 2008
-Date: 23 May 2008 05:23:42 +0200
-From: Mail System Internal Data <MAILER-DAEMON@example.com>
-Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
-Message-ID: <foo-0001@example.com>
-
-This text is part of the internal format of your mail folder, and is not
-a real message.  It is created automatically by the mail system software.
-If deleted, important folder data will be lost, and it will be re-created
-with the data reset to initial values.
-
-EOF
-
-echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected
+test_expect_success 'setup: messages' '
+       cat >msg <<-\EOF &&
+       second
+
+       Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy
+       eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
+       voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
+       kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
+       ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
+       tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
+       vero eos et accusam et justo duo dolores et ea rebum.
+
+       EOF
+       q_to_tab <<-\EOF >>msg &&
+       QDuis autem vel eum iriure dolor in hendrerit in vulputate velit
+       Qesse molestie consequat, vel illum dolore eu feugiat nulla facilisis
+       Qat vero eros et accumsan et iusto odio dignissim qui blandit
+       Qpraesent luptatum zzril delenit augue duis dolore te feugait nulla
+       Qfacilisi.
+       EOF
+       cat >>msg <<-\EOF &&
+
+       Lorem ipsum dolor sit amet,
+       consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
+       laoreet dolore magna aliquam erat volutpat.
+
+         git
+         ---
+         +++
+
+       Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
+       lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
+       dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
+       dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
+       dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
+       feugait nulla facilisi.
+       EOF
+
+       cat >failmail <<-\EOF &&
+       From foo@example.com Fri May 23 10:43:49 2008
+       From:   foo@example.com
+       To:     bar@example.com
+       Subject: Re: [RFC/PATCH] git-foo.sh
+       Date:   Fri, 23 May 2008 05:23:42 +0200
+
+       Sometimes we have to find out that there'\''s nothing left.
+
+       EOF
+
+       cat >pine <<-\EOF &&
+       From MAILER-DAEMON Fri May 23 10:43:49 2008
+       Date: 23 May 2008 05:23:42 +0200
+       From: Mail System Internal Data <MAILER-DAEMON@example.com>
+       Subject: DON'\''T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
+       Message-ID: <foo-0001@example.com>
+
+       This text is part of the internal format of your mail folder, and is not
+       a real message.  It is created automatically by the mail system software.
+       If deleted, important folder data will be lost, and it will be re-created
+       with the data reset to initial values.
+
+       EOF
+
+       signoff="Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
+'
 
 test_expect_success setup '
        echo hello >file &&
@@ -71,11 +76,13 @@ test_expect_success setup '
        test_tick &&
        git commit -m first &&
        git tag first &&
+
        echo world >>file &&
        git add file &&
        test_tick &&
        git commit -s -F msg &&
        git tag second &&
+
        git format-patch --stdout first >patch1 &&
        {
                echo "X-Fake-Field: Line One" &&
@@ -89,74 +96,101 @@ test_expect_success setup '
                echo "X-Fake-Field: Line Three" &&
                git format-patch --stdout first | sed -e "1d"
        } | append_cr >patch1-crlf.eml &&
+
        sed -n -e "3,\$p" msg >file &&
        git add file &&
        test_tick &&
        git commit -m third &&
+
        git format-patch --stdout first >patch2 &&
+
        git checkout -b lorem &&
        sed -n -e "11,\$p" msg >file &&
        head -n 9 msg >>file &&
        test_tick &&
        git commit -a -m "moved stuff" &&
+
        echo goodbye >another &&
        git add another &&
        test_tick &&
        git commit -m "added another file" &&
-       git format-patch --stdout master >lorem-move.patch
-'
 
-# reset time
-unset test_tick
-test_tick
+       git format-patch --stdout master >lorem-move.patch &&
+
+       git checkout -b rename &&
+       git mv file renamed &&
+       git commit -m "renamed a file" &&
+
+       git format-patch -M --stdout lorem >rename.patch &&
+
+       git reset --soft lorem^ &&
+       git commit -m "renamed a file and added another" &&
+
+       git format-patch -M --stdout lorem^ >rename-add.patch &&
+
+       # reset time
+       unset test_tick &&
+       test_tick
+'
 
 test_expect_success 'am applies patch correctly' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        test_tick &&
        git am <patch1 &&
        ! test -d .git/rebase-apply &&
-       test -z "$(git diff second)" &&
+       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 'am applies patch e-mail not in a mbox' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        git am patch1.eml &&
        ! test -d .git/rebase-apply &&
-       test -z "$(git diff second)" &&
+       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 'am applies patch e-mail not in a mbox with CRLF' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        git am patch1-crlf.eml &&
        ! test -d .git/rebase-apply &&
-       test -z "$(git diff second)" &&
+       git diff --exit-code second &&
        test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
        test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
 '
 
-GIT_AUTHOR_NAME="Another Thor"
-GIT_AUTHOR_EMAIL="a.thor@example.com"
-GIT_COMMITTER_NAME="Co M Miter"
-GIT_COMMITTER_EMAIL="c.miter@example.com"
-export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
+test_expect_success 'setup: new author and committer' '
+       GIT_AUTHOR_NAME="Another Thor" &&
+       GIT_AUTHOR_EMAIL="a.thor@example.com" &&
+       GIT_COMMITTER_NAME="Co M Miter" &&
+       GIT_COMMITTER_EMAIL="c.miter@example.com" &&
+       export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
+'
 
 compare () {
-       test "$(git cat-file commit "$2" | grep "^$1 ")" = \
-            "$(git cat-file commit "$3" | grep "^$1 ")"
+       a=$(git cat-file commit "$2" | grep "^$1 ") &&
+       b=$(git cat-file commit "$3" | grep "^$1 ") &&
+       test "$a" = "$b"
 }
 
 test_expect_success 'am changes committer and keeps author' '
        test_tick &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        git am patch2 &&
        ! test -d .git/rebase-apply &&
        test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
-       test -z "$(git diff master..HEAD)" &&
-       test -z "$(git diff master^..HEAD^)" &&
+       git diff --exit-code master..HEAD &&
+       git diff --exit-code master^..HEAD^ &&
        compare author master HEAD &&
        compare author master^ HEAD^ &&
        test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \
@@ -164,41 +198,55 @@ test_expect_success 'am changes committer and keeps author' '
 '
 
 test_expect_success 'am --signoff adds Signed-off-by: line' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout -b master2 first &&
        git am --signoff <patch2 &&
+       printf "%s\n" "$signoff" >expected &&
        echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected &&
        git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
-       test_cmp actual expected &&
+       test_cmp expected actual &&
        echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
        git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
-       test_cmp actual expected
+       test_cmp expected actual
 '
 
 test_expect_success 'am stays in branch' '
-       test "refs/heads/master2" = "$(git symbolic-ref HEAD)"
+       echo refs/heads/master2 >expected &&
+       git symbolic-ref HEAD >actual &&
+       test_cmp expected actual
 '
 
 test_expect_success 'am --signoff does not add Signed-off-by: line if already there' '
        git format-patch --stdout HEAD^ >patch3 &&
        sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout HEAD^ &&
        git am --signoff patch4 &&
-       test "$(git cat-file commit HEAD | grep -c "^Signed-off-by:")" -eq 1
+       git cat-file commit HEAD >actual &&
+       test $(grep -c "^Signed-off-by:" actual) -eq 1
 '
 
 test_expect_success 'am without --keep removes Re: and [PATCH] stuff' '
-       test "$(git rev-parse HEAD)" = "$(git rev-parse master2)"
+       git rev-parse HEAD >expected &&
+       git rev-parse master2 >actual &&
+       test_cmp expected actual
 '
 
 test_expect_success 'am --keep really keeps the subject' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout HEAD^ &&
        git am --keep patch4 &&
        ! test -d .git/rebase-apply &&
-       git cat-file commit HEAD |
-               fgrep "Re: Re: Re: [PATCH 1/5 v2] third"
+       git cat-file commit HEAD >actual &&
+       grep "Re: Re: Re: \[PATCH 1/5 v2\] third" actual
 '
 
 test_expect_success 'am -3 falls back to 3-way merge' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout -b lorem2 master2 &&
        sed -n -e "3,\$p" msg >file &&
        head -n 9 msg >>file &&
@@ -207,34 +255,75 @@ test_expect_success 'am -3 falls back to 3-way merge' '
        git commit -m "copied stuff" &&
        git am -3 lorem-move.patch &&
        ! test -d .git/rebase-apply &&
-       test -z "$(git diff lorem)"
+       git diff --exit-code lorem
+'
+
+test_expect_success 'am can rename a file' '
+       grep "^rename from" rename.patch &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout lorem^0 &&
+       git am rename.patch &&
+       ! test -d .git/rebase-apply &&
+       git update-index --refresh &&
+       git diff --exit-code rename
+'
+
+test_expect_success 'am -3 can rename a file' '
+       grep "^rename from" rename.patch &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout lorem^0 &&
+       git am -3 rename.patch &&
+       ! test -d .git/rebase-apply &&
+       git update-index --refresh &&
+       git diff --exit-code rename
+'
+
+test_expect_success 'am -3 can rename a file after falling back to 3-way merge' '
+       grep "^rename from" rename-add.patch &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout lorem^0 &&
+       git am -3 rename-add.patch &&
+       ! test -d .git/rebase-apply &&
+       git update-index --refresh &&
+       git diff --exit-code rename
 '
 
 test_expect_success 'am -3 -q is quiet' '
+       rm -fr .git/rebase-apply &&
+       git checkout -f lorem2 &&
        git reset master2 --hard &&
        sed -n -e "3,\$p" msg >file &&
        head -n 9 msg >>file &&
        git add file &&
        test_tick &&
        git commit -m "copied stuff" &&
-       git am -3 -q lorem-move.patch > output.out 2>&1 &&
+       git am -3 -q lorem-move.patch >output.out 2>&1 &&
        ! test -s output.out
 '
 
 test_expect_success 'am pauses on conflict' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout lorem2^^ &&
        test_must_fail git am lorem-move.patch &&
        test -d .git/rebase-apply
 '
 
 test_expect_success 'am --skip works' '
+       echo goodbye >expected &&
        git am --skip &&
        ! test -d .git/rebase-apply &&
-       test -z "$(git diff lorem2^^ -- file)" &&
-       test goodbye = "$(cat another)"
+       git diff --exit-code lorem2^^ -- file &&
+       test_cmp expected another
 '
 
 test_expect_success 'am --resolved works' '
+       echo goodbye >expected &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout lorem2^^ &&
        test_must_fail git am lorem-move.patch &&
        test -d .git/rebase-apply &&
@@ -242,22 +331,29 @@ test_expect_success 'am --resolved works' '
        git add file &&
        git am --resolved &&
        ! test -d .git/rebase-apply &&
-       test goodbye = "$(cat another)"
+       test_cmp expected another
 '
 
 test_expect_success 'am takes patches from a Pine mailbox' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        cat pine patch1 | git am &&
        ! test -d .git/rebase-apply &&
-       test -z "$(git diff master^..HEAD)"
+       git diff --exit-code master^..HEAD
 '
 
 test_expect_success 'am fails on mail without patch' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        test_must_fail git am <failmail &&
-       rm -r .git/rebase-apply/
+       git am --abort &&
+       ! test -d .git/rebase-apply
 '
 
 test_expect_success 'am fails on empty patch' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        echo "---" >>failmail &&
        test_must_fail git am <failmail &&
        git am --skip &&
@@ -266,28 +362,34 @@ test_expect_success 'am fails on empty patch' '
 
 test_expect_success 'am works from stdin in subdirectory' '
        rm -fr subdir &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        (
                mkdir -p subdir &&
                cd subdir &&
                git am <../patch1
        ) &&
-       test -z "$(git diff second)"
+       git diff --exit-code second
 '
 
 test_expect_success 'am works from file (relative path given) in subdirectory' '
        rm -fr subdir &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        (
                mkdir -p subdir &&
                cd subdir &&
                git am ../patch1
        ) &&
-       test -z "$(git diff second)"
+       git diff --exit-code second
 '
 
 test_expect_success 'am works from file (absolute path given) in subdirectory' '
        rm -fr subdir &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        P=$(pwd) &&
        (
@@ -295,27 +397,31 @@ test_expect_success 'am works from file (absolute path given) in subdirectory' '
                cd subdir &&
                git am "$P/patch1"
        ) &&
-       test -z "$(git diff second)"
+       git diff --exit-code second
 '
 
 test_expect_success 'am --committer-date-is-author-date' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        test_tick &&
        git am --committer-date-is-author-date patch1 &&
        git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
-       at=$(sed -ne "/^author /s/.*> //p" head1) &&
-       ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
-       test "$at" = "$ct"
+       sed -ne "/^author /s/.*> //p" head1 >at &&
+       sed -ne "/^committer /s/.*> //p" head1 >ct &&
+       test_cmp at ct
 '
 
 test_expect_success 'am without --committer-date-is-author-date' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        test_tick &&
        git am patch1 &&
        git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
-       at=$(sed -ne "/^author /s/.*> //p" head1) &&
-       ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
-       test "$at" != "$ct"
+       sed -ne "/^author /s/.*> //p" head1 >at &&
+       sed -ne "/^committer /s/.*> //p" head1 >ct &&
+       ! test_cmp at ct
 '
 
 # This checks for +0000 because TZ is set to UTC and that should
@@ -323,41 +429,51 @@ test_expect_success 'am without --committer-date-is-author-date' '
 # by test_tick that uses -0700 timezone; if this feature does not
 # work, we will see that instead of +0000.
 test_expect_success 'am --ignore-date' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        test_tick &&
        git am --ignore-date patch1 &&
        git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
-       at=$(sed -ne "/^author /s/.*> //p" head1) &&
-       echo "$at" | grep "+0000"
+       sed -ne "/^author /s/.*> //p" head1 >at &&
+       grep "+0000" at
 '
 
 test_expect_success 'am into an unborn branch' '
+       git rev-parse first^{tree} >expected &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        rm -fr subdir &&
-       mkdir -p subdir &&
+       mkdir subdir &&
        git format-patch --numbered-files -o subdir -1 first &&
        (
                cd subdir &&
                git init &&
                git am 1
        ) &&
-       result=$(
-               cd subdir && git rev-parse HEAD^{tree}
+       (
+               cd subdir &&
+               git rev-parse HEAD^{tree} >../actual
        ) &&
-       test "z$result" = "z$(git rev-parse first^{tree})"
+       test_cmp expected actual
 '
 
 test_expect_success 'am newline in subject' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        test_tick &&
-       sed -e "s/second/second \\\n foo/" patch1 > patchnl &&
-       git am < patchnl > output.out 2>&1 &&
+       sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
+       git am <patchnl >output.out 2>&1 &&
        grep "^Applying: second \\\n foo$" output.out
 '
 
 test_expect_success 'am -q is quiet' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
        git checkout first &&
        test_tick &&
-       git am -q < patch1 > output.out 2>&1 &&
+       git am -q <patch1 >output.out 2>&1 &&
        ! test -s output.out
 '
 
index 2b912d77283fbd3fc02a7d9d6bca660e4193b8c3..b55c4117884744db8eda17e42fe05e0e65216215 100755 (executable)
@@ -47,7 +47,7 @@ do
                test_must_fail git am$with3 --skip >output &&
                test "$(grep "^Applying" output)" = "Applying: 6" &&
                test_cmp file-2-expect file-2 &&
-               test ! -f .git/rr-cache/MERGE_RR
+               test ! -f .git/MERGE_RR
        '
 
        test_expect_success "am --abort goes back after failed am$with3" '
@@ -57,7 +57,7 @@ do
                test_cmp expect actual &&
                test_cmp file-2-expect file-2 &&
                git diff-index --exit-code --cached HEAD &&
-               test ! -f .git/rr-cache/MERGE_RR
+               test ! -f .git/MERGE_RR
        '
 
 done
index 70856d07ed113b731d149bde73fe7b4eb25a72f2..093b1389116250ada236b5949fab269fd567b643 100755 (executable)
@@ -132,6 +132,8 @@ test_expect_success 'commit succeeds' \
 
 test_expect_success 'recorded postimage' "test -f $rr/postimage"
 
+oldmtimepost=$(test-chmtime -v -60 $rr/postimage |cut -f 1)
+
 test_expect_success 'another conflicting merge' '
        git checkout -b third master &&
        git show second^:a1 | sed "s/To die: t/To die! T/" > a1 &&
@@ -144,6 +146,11 @@ test_expect_success 'rerere kicked in' "! grep ^=======$ a1"
 
 test_expect_success 'rerere prefers first change' 'test_cmp a1 expect'
 
+test_expect_success 'rerere updates postimage timestamp' '
+       newmtimepost=$(test-chmtime -v +0 $rr/postimage |cut -f 1) &&
+       test $oldmtimepost -lt $newmtimepost
+'
+
 rm $rr/postimage
 echo "$sha1    a1" | perl -pe 'y/\012/\000/' > .git/MERGE_RR
 
@@ -165,15 +172,16 @@ just_over_15_days_ago=$((-1-15*86400))
 almost_60_days_ago=$((60-60*86400))
 just_over_60_days_ago=$((-1-60*86400))
 
-test-chmtime =$almost_60_days_ago $rr/preimage
+test-chmtime =$just_over_60_days_ago $rr/preimage
+test-chmtime =$almost_60_days_ago $rr/postimage
 test-chmtime =$almost_15_days_ago $rr2/preimage
 
 test_expect_success 'garbage collection (part1)' 'git rerere gc'
 
-test_expect_success 'young records still live' \
+test_expect_success 'young or recently used records still live' \
        "test -f $rr/preimage && test -f $rr2/preimage"
 
-test-chmtime =$just_over_60_days_ago $rr/preimage
+test-chmtime =$just_over_60_days_ago $rr/postimage
 test-chmtime =$just_over_15_days_ago $rr2/preimage
 
 test_expect_success 'garbage collection (part2)' 'git rerere gc'
index 1dc224f6fbf074434728d326b8a36160e9032192..ead204e5cb77804ee1b54cc1b2f31d35312fa758 100755 (executable)
@@ -387,5 +387,66 @@ test_expect_success 'log --graph with merge' '
        test_cmp expect actual
 '
 
-test_done
+test_expect_success 'log.decorate configuration' '
+       git config --unset-all log.decorate || :
+
+       git log --oneline >expect.none &&
+       git log --oneline --decorate >expect.short &&
+       git log --oneline --decorate=full >expect.full &&
+
+       echo "[log] decorate" >>.git/config &&
+       git log --oneline >actual &&
+       test_cmp expect.short actual &&
+
+       git config --unset-all log.decorate &&
+       git config log.decorate true &&
+       git log --oneline >actual &&
+       test_cmp expect.short actual &&
+       git log --oneline --decorate=full >actual &&
+       test_cmp expect.full actual &&
+       git log --oneline --decorate=no >actual &&
+       test_cmp expect.none actual &&
+
+       git config --unset-all log.decorate &&
+       git config log.decorate no &&
+       git log --oneline >actual &&
+       test_cmp expect.none actual &&
+       git log --oneline --decorate >actual &&
+       test_cmp expect.short actual &&
+       git log --oneline --decorate=full >actual &&
+       test_cmp expect.full actual &&
+
+       git config --unset-all log.decorate &&
+       git config log.decorate short &&
+       git log --oneline >actual &&
+       test_cmp expect.short actual &&
+       git log --oneline --no-decorate >actual &&
+       test_cmp expect.none actual &&
+       git log --oneline --decorate=full >actual &&
+       test_cmp expect.full actual &&
+
+       git config --unset-all log.decorate &&
+       git config log.decorate full &&
+       git log --oneline >actual &&
+       test_cmp expect.full actual &&
+       git log --oneline --no-decorate >actual &&
+       test_cmp expect.none actual &&
+       git log --oneline --decorate >actual &&
+       test_cmp expect.short actual
+
+'
 
+test_expect_success 'show added path under "--follow -M"' '
+       # This tests for a regression introduced in v1.7.2-rc0~103^2~2
+       test_create_repo regression &&
+       (
+               cd regression &&
+               test_commit needs-another-commit &&
+               test_commit foo.bar &&
+               git log -M --follow -p foo.bar.t &&
+               git log -M --follow --stat foo.bar.t &&
+               git log -M --follow --name-only foo.bar.t
+       )
+'
+
+test_done
index 04f7bae8503f7605f1403f55d0bf4d9cd146913d..68e2652814c6a52265407b0fdfb70162eb634d53 100755 (executable)
@@ -18,6 +18,11 @@ test_expect_success 'patch-id output is well-formed' '
        grep "^[a-f0-9]\{40\} $(git rev-parse HEAD)$" output
 '
 
+calc_patch_id () {
+       git patch-id |
+               sed "s# .*##" > patch-id_"$1"
+}
+
 get_patch_id () {
        git log -p -1 "$1" | git patch-id |
                sed "s# .*##" > patch-id_"$1"
@@ -35,4 +40,27 @@ test_expect_success 'patch-id detects inequality' '
        ! test_cmp patch-id_master patch-id_notsame
 '
 
+test_expect_success 'patch-id supports git-format-patch output' '
+       get_patch_id master &&
+       git checkout same &&
+       git format-patch -1 --stdout | calc_patch_id same &&
+       test_cmp patch-id_master patch-id_same &&
+       set `git format-patch -1 --stdout | git patch-id` &&
+       test "$2" = `git rev-parse HEAD`
+'
+
+test_expect_success 'whitespace is irrelevant in footer' '
+       get_patch_id master &&
+       git checkout same &&
+       git format-patch -1 --stdout | sed "s/ \$//" | calc_patch_id same &&
+       test_cmp patch-id_master patch-id_same
+'
+
+test_expect_success 'patch-id supports git-format-patch MIME output' '
+       get_patch_id master &&
+       git checkout same &&
+       git format-patch -1 --attach --stdout | calc_patch_id same &&
+       test_cmp patch-id_master patch-id_same
+'
+
 test_done
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
new file mode 100755 (executable)
index 0000000..cb9f2bd
--- /dev/null
@@ -0,0 +1,74 @@
+#!/bin/sh
+#
+# Copyright (c) 2010, Will Palmer
+#
+
+test_description='Test pretty formats'
+. ./test-lib.sh
+
+test_expect_success 'set up basic repos' '
+       >foo &&
+       >bar &&
+       git add foo &&
+       test_tick &&
+       git commit -m initial &&
+       git add bar &&
+       test_tick &&
+       git commit -m "add bar"
+'
+
+test_expect_success 'alias builtin format' '
+       git log --pretty=oneline >expected &&
+       git config pretty.test-alias oneline &&
+       git log --pretty=test-alias >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'alias masking builtin format' '
+       git log --pretty=oneline >expected &&
+       git config pretty.oneline "%H" &&
+       git log --pretty=oneline >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'alias user-defined format' '
+       git log --pretty="format:%h" >expected &&
+       git config pretty.test-alias "format:%h" &&
+       git log --pretty=test-alias >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'alias user-defined tformat' '
+       git log --pretty="tformat:%h" >expected &&
+       git config pretty.test-alias "tformat:%h" &&
+       git log --pretty=test-alias >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'alias non-existant format' '
+       git config pretty.test-alias format-that-will-never-exist &&
+       test_must_fail git log --pretty=test-alias
+'
+
+test_expect_success 'alias of an alias' '
+       git log --pretty="tformat:%h" >expected &&
+       git config pretty.test-foo "tformat:%h" &&
+       git config pretty.test-bar test-foo &&
+       git log --pretty=test-bar >actual && test_cmp expected actual
+'
+
+test_expect_success 'alias masking an alias' '
+       git log --pretty=format:"Two %H" >expected &&
+       git config pretty.duplicate "format:One %H" &&
+       git config --add pretty.duplicate "format:Two %H" &&
+       git log --pretty=duplicate >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'alias loop' '
+       git config pretty.test-foo test-bar &&
+       git config pretty.test-bar test-foo &&
+       test_must_fail git log --pretty=test-foo
+'
+
+test_done
diff --git a/t/t4206-log-follow-harder-copies.sh b/t/t4206-log-follow-harder-copies.sh
new file mode 100755 (executable)
index 0000000..ad29e65
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Bo Yang
+#
+
+test_description='Test --follow should always find copies hard in git log.
+
+'
+. ./test-lib.sh
+. "$TEST_DIRECTORY"/diff-lib.sh
+
+echo >path0 'Line 1
+Line 2
+Line 3
+'
+
+test_expect_success \
+    'add a file path0 and commit.' \
+    'git add path0 &&
+     git commit -m "Add path0"'
+
+echo >path0 'New line 1
+New line 2
+New line 3
+'
+test_expect_success \
+    'Change path0.' \
+    'git add path0 &&
+     git commit -m "Change path0"'
+
+cat <path0 >path1
+test_expect_success \
+    'copy path0 to path1.' \
+    'git add path1 &&
+     git commit -m "Copy path1 from path0"'
+
+test_expect_success \
+    'find the copy path0 -> path1 harder' \
+    'git log --follow --name-status --pretty="format:%s"  path1 > current'
+
+cat >expected <<\EOF
+Copy path1 from path0
+C100   path0   path1
+
+Change path0
+M      path0
+
+Add path0
+A      path0
+EOF
+
+test_expect_success \
+    'validate the output.' \
+    'compare_diff_patch current expected'
+
+test_done
diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh
new file mode 100755 (executable)
index 0000000..bbde31b
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Nazri Ramliy
+#
+
+test_description='Test for "git log --decorate" colors'
+
+. ./test-lib.sh
+
+get_color ()
+{
+       git config --get-color no.such.slot "$1"
+}
+
+test_expect_success setup '
+       git config diff.color.commit yellow &&
+       git config color.decorate.branch green &&
+       git config color.decorate.remoteBranch red &&
+       git config color.decorate.tag "reverse bold yellow" &&
+       git config color.decorate.stash magenta &&
+       git config color.decorate.HEAD cyan &&
+
+       c_reset=$(get_color reset) &&
+
+       c_commit=$(get_color yellow) &&
+       c_branch=$(get_color green) &&
+       c_remoteBranch=$(get_color red) &&
+       c_tag=$(get_color "reverse bold yellow") &&
+       c_stash=$(get_color magenta) &&
+       c_HEAD=$(get_color cyan) &&
+
+       test_commit A &&
+       git clone . other &&
+       (
+               cd other &&
+               test_commit A1
+       ) &&
+
+       git remote add -f other ./other &&
+       test_commit B &&
+       git tag v1.0 &&
+       echo >>A.t &&
+       git stash save Changes to A.t
+'
+
+cat >expected <<EOF
+${c_commit}COMMIT_ID (${c_HEAD}HEAD${c_reset}${c_commit},\
+ ${c_tag}tag: v1.0${c_reset}${c_commit},\
+ ${c_tag}tag: B${c_reset}${c_commit},\
+ ${c_branch}master${c_reset}${c_commit})${c_reset} B
+${c_commit}COMMIT_ID (${c_tag}tag: A1${c_reset}${c_commit},\
+ ${c_remoteBranch}other/master${c_reset}${c_commit})${c_reset} A1
+${c_commit}COMMIT_ID (${c_stash}refs/stash${c_reset}${c_commit})${c_reset}\
+ On master: Changes to A.t
+${c_commit}COMMIT_ID (${c_tag}tag: A${c_reset}${c_commit})${c_reset} A
+EOF
+
+# We want log to show all, but the second parent to refs/stash is irrelevant
+# to this test since it does not contain any decoration, hence --first-parent
+test_expect_success 'Commit Decorations Colored Correctly' '
+       git log --first-parent --abbrev=10 --all --decorate --oneline --color=always |
+       sed "s/[0-9a-f]\{10,10\}/COMMIT_ID/" >out &&
+       test_cmp expected out
+'
+
+test_done
diff --git a/t/t4300-merge-tree.sh b/t/t4300-merge-tree.sh
new file mode 100755 (executable)
index 0000000..46c3fe7
--- /dev/null
@@ -0,0 +1,257 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Will Palmer
+#
+
+test_description='git merge-tree'
+. ./test-lib.sh
+
+test_expect_success setup '
+       test_commit "initial" "initial-file" "initial"
+'
+
+test_expect_success 'file add A, !B' '
+       cat >expected <<\EXPECTED &&
+added in remote
+  their  100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
+@@ -0,0 +1 @@
++AAA
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "add-a-not-b" "ONE" "AAA" &&
+       git merge-tree initial initial add-a-not-b >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file add !A, B' '
+       cat >expected <<\EXPECTED &&
+added in local
+  our    100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "add-not-a-b" "ONE" "AAA" &&
+       git merge-tree initial add-not-a-b initial >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file add A, B (same)' '
+       cat >expected <<\EXPECTED &&
+added in both
+  our    100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
+  their  100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "add-a-b-same-A" "ONE" "AAA" &&
+       git reset --hard initial &&
+       test_commit "add-a-b-same-B" "ONE" "AAA" &&
+       git merge-tree initial add-a-b-same-A add-a-b-same-B >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file add A, B (different)' '
+       cat >expected <<\EXPECTED &&
+added in both
+  our    100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
+  their  100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
+@@ -1 +1,5 @@
++<<<<<<< .our
+ AAA
++=======
++BBB
++>>>>>>> .their
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "add-a-b-diff-A" "ONE" "AAA" &&
+       git reset --hard initial &&
+       test_commit "add-a-b-diff-B" "ONE" "BBB" &&
+       git merge-tree initial add-a-b-diff-A add-a-b-diff-B >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file change A, !B' '
+       cat >expected <<\EXPECTED &&
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "change-a-not-b" "initial-file" "BBB" &&
+       git merge-tree initial change-a-not-b initial >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file change !A, B' '
+       cat >expected <<\EXPECTED &&
+merged
+  result 100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
+  our    100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
+@@ -1 +1 @@
+-initial
++BBB
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "change-not-a-b" "initial-file" "BBB" &&
+       git merge-tree initial initial change-not-a-b >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file change A, B (same)' '
+       cat >expected <<\EXPECTED &&
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "change-a-b-same-A" "initial-file" "AAA" &&
+       git reset --hard initial &&
+       test_commit "change-a-b-same-B" "initial-file" "AAA" &&
+       git merge-tree initial change-a-b-same-A change-a-b-same-B >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file change A, B (different)' '
+       cat >expected <<\EXPECTED &&
+changed in both
+  base   100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
+  our    100644 43d5a8ed6ef6c00ff775008633f95787d088285d initial-file
+  their  100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
+@@ -1 +1,5 @@
++<<<<<<< .our
+ AAA
++=======
++BBB
++>>>>>>> .their
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "change-a-b-diff-A" "initial-file" "AAA" &&
+       git reset --hard initial &&
+       test_commit "change-a-b-diff-B" "initial-file" "BBB" &&
+       git merge-tree initial change-a-b-diff-A change-a-b-diff-B >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file change A, B (mixed)' '
+       cat >expected <<\EXPECTED &&
+changed in both
+  base   100644 f4f1f998c7776568c4ff38f516d77fef9399b5a7 ONE
+  our    100644 af14c2c3475337c73759d561ef70b59e5c731176 ONE
+  their  100644 372d761493f524d44d59bd24700c3bdf914c973c ONE
+@@ -7,7 +7,11 @@
+ AAA
+ AAA
+ AAA
++<<<<<<< .our
+ BBB
++=======
++CCC
++>>>>>>> .their
+ AAA
+ AAA
+ AAA
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "change-a-b-mix-base" "ONE" "
+AAA
+AAA
+AAA
+AAA
+AAA
+AAA
+AAA
+AAA
+AAA
+AAA
+AAA
+AAA
+AAA
+AAA
+AAA" &&
+       test_commit "change-a-b-mix-A" "ONE" \
+               "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/BBB/;}" <ONE)" &&
+       git reset --hard change-a-b-mix-base &&
+       test_commit "change-a-b-mix-B" "ONE" \
+               "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/CCC/;}" <ONE)" &&
+       git merge-tree change-a-b-mix-base change-a-b-mix-A change-a-b-mix-B \
+               >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file remove A, !B' '
+       cat >expected <<\EXPECTED &&
+removed in local
+  base   100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
+  their  100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "rm-a-not-b-base" "ONE" "AAA" &&
+       git rm ONE &&
+       git commit -m "rm-a-not-b" &&
+       git tag "rm-a-not-b" &&
+       git merge-tree rm-a-not-b-base rm-a-not-b rm-a-not-b-base >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file remove !A, B' '
+       cat >expected <<\EXPECTED &&
+removed in remote
+  base   100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
+  our    100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
+@@ -1 +0,0 @@
+-AAA
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "rm-not-a-b-base" "ONE" "AAA" &&
+       git rm ONE &&
+       git commit -m "rm-not-a-b" &&
+       git tag "rm-not-a-b" &&
+       git merge-tree rm-a-not-b-base rm-a-not-b-base rm-a-not-b >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file change A, remove B' '
+       cat >expected <<\EXPECTED &&
+removed in remote
+  base   100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
+  our    100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
+@@ -1 +0,0 @@
+-BBB
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "change-a-rm-b-base" "ONE" "AAA" &&
+       test_commit "change-a-rm-b-A" "ONE" "BBB" &&
+       git reset --hard change-a-rm-b-base &&
+       git rm ONE &&
+       git commit -m "change-a-rm-b-B" &&
+       git tag "change-a-rm-b-B" &&
+       git merge-tree change-a-rm-b-base change-a-rm-b-A change-a-rm-b-B \
+               >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'file remove A, change B' '
+       cat >expected <<\EXPECTED &&
+removed in local
+  base   100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
+  their  100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
+EXPECTED
+
+       git reset --hard initial &&
+       test_commit "rm-a-change-b-base" "ONE" "AAA" &&
+
+       git rm ONE &&
+       git commit -m "rm-a-change-b-A" &&
+       git tag "rm-a-change-b-A" &&
+       git reset --hard rm-a-change-b-base &&
+       test_commit "rm-a-change-b-B" "ONE" "BBB" &&
+       git merge-tree rm-a-change-b-base rm-a-change-b-A rm-a-change-b-B \
+               >actual &&
+       test_cmp expected actual
+'
+
+test_done
index 426b319bd36257331f07d5aee1a20ed7e515408a..02d4d2284d8bcf9637dbd6a670e376b4ae9f7af1 100755 (executable)
@@ -4,7 +4,7 @@ test_description='git archive attribute tests'
 
 . ./test-lib.sh
 
-SUBSTFORMAT=%H%n
+SUBSTFORMAT='%H (%h)%n'
 
 test_expect_exists() {
        test_expect_success " $1 exists" "test -e $1"
diff --git a/t/t5150-request-pull.sh b/t/t5150-request-pull.sh
new file mode 100755 (executable)
index 0000000..9cc0a42
--- /dev/null
@@ -0,0 +1,228 @@
+#!/bin/sh
+
+test_description='Test workflows involving pull request.'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+
+       git init --bare upstream.git &&
+       git init --bare downstream.git &&
+       git clone upstream.git upstream-private &&
+       git clone downstream.git local &&
+
+       trash_url="file://$TRASH_DIRECTORY" &&
+       downstream_url="$trash_url/downstream.git/" &&
+       upstream_url="$trash_url/upstream.git/" &&
+
+       (
+               cd upstream-private &&
+               cat <<-\EOT >mnemonic.txt &&
+               Thirtey days hath November,
+               Aprile, June, and September:
+               EOT
+               git add mnemonic.txt &&
+               test_tick &&
+               git commit -m "\"Thirty days\", a reminder of month lengths" &&
+               git tag -m "version 1" -a initial &&
+               git push --tags origin master
+       ) &&
+       (
+               cd local &&
+               git remote add upstream "$trash_url/upstream.git" &&
+               git fetch upstream &&
+               git pull upstream master &&
+               cat <<-\EOT >>mnemonic.txt &&
+               Of twyecescore-eightt is but eine,
+               And all the remnante be thrycescore-eine.
+               O’course Leap yare comes an’pynes,
+               Ev’rie foure yares, gote it ryghth.
+               An’twyecescore-eight is but twyecescore-nyne.
+               EOT
+               git add mnemonic.txt &&
+               test_tick &&
+               git commit -m "More detail" &&
+               git tag -m "version 2" -a full &&
+               git checkout -b simplify HEAD^ &&
+               mv mnemonic.txt mnemonic.standard &&
+               cat <<-\EOT >mnemonic.clarified &&
+               Thirty days has September,
+               All the rest I can’t remember.
+               EOT
+               git add -N mnemonic.standard mnemonic.clarified &&
+               git commit -a -m "Adapt to use modern, simpler English
+
+But keep the old version, too, in case some people prefer it." &&
+               git checkout master
+       )
+
+'
+
+test_expect_success 'setup: two scripts for reading pull requests' '
+
+       downstream_url_for_sed=$(
+               printf "%s\n" "$downstream_url" |
+               sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\''
+       ) &&
+
+       cat <<-\EOT >read-request.sed &&
+       #!/bin/sed -nf
+       / in the git repository at:$/!d
+       n
+       /^$/ n
+       s/^[    ]*\(.*\) \([^ ]*\)/please pull\
+       \1\
+       \2/p
+       q
+       EOT
+
+       cat <<-EOT >fuzz.sed
+       #!/bin/sed -nf
+       s/$_x40/OBJECT_NAME/g
+       s/A U Thor/AUTHOR/g
+       s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
+       s/        [^ ].*/        SUBJECT/g
+       s/  [^ ].* (DATE)/  SUBJECT (DATE)/g
+       s/$downstream_url_for_sed/URL/g
+       s/for-upstream/BRANCH/g
+       s/mnemonic.txt/FILENAME/g
+       /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
+       /^AUTHOR ([0-9]*):\$/ b shortlog
+       p
+       b
+       : diffstat
+       n
+       / [0-9]* files changed/ {
+               a\\
+       DIFFSTAT
+               b
+       }
+       b diffstat
+       : shortlog
+       /^        [a-zA-Z]/ n
+       /^[a-zA-Z]* ([0-9]*):\$/ n
+       /^\$/ N
+       /^\n[a-zA-Z]* ([0-9]*):\$/!{
+               a\\
+       SHORTLOG
+               D
+       }
+       n
+       b shortlog
+       EOT
+
+'
+
+test_expect_success 'pull request when forgot to push' '
+
+       rm -fr downstream.git &&
+       git init --bare downstream.git &&
+       (
+               cd local &&
+               git checkout initial &&
+               git merge --ff-only master &&
+               test_must_fail git request-pull initial "$downstream_url" \
+                       2>../err
+       ) &&
+       grep "No branch of.*is at:\$" err &&
+       grep "Are you sure you pushed" err
+
+'
+
+test_expect_success 'pull request after push' '
+
+       rm -fr downstream.git &&
+       git init --bare downstream.git &&
+       (
+               cd local &&
+               git checkout initial &&
+               git merge --ff-only master &&
+               git push origin master:for-upstream &&
+               git request-pull initial origin >../request
+       ) &&
+       sed -nf read-request.sed <request >digest &&
+       cat digest &&
+       {
+               read task &&
+               read repository &&
+               read branch
+       } <digest &&
+       (
+               cd upstream-private &&
+               git checkout initial &&
+               git pull --ff-only "$repository" "$branch"
+       ) &&
+       test "$branch" = for-upstream &&
+       test_cmp local/mnemonic.txt upstream-private/mnemonic.txt
+
+'
+
+test_expect_success 'request names an appropriate branch' '
+
+       rm -fr downstream.git &&
+       git init --bare downstream.git &&
+       (
+               cd local &&
+               git checkout initial &&
+               git merge --ff-only master &&
+               git push --tags origin master simplify &&
+               git push origin master:for-upstream &&
+               git request-pull initial "$downstream_url" >../request
+       ) &&
+       sed -nf read-request.sed <request >digest &&
+       cat digest &&
+       {
+               read task &&
+               read repository &&
+               read branch
+       } <digest &&
+       {
+               test "$branch" = master ||
+               test "$branch" = for-upstream
+       }
+
+'
+
+test_expect_success 'pull request format' '
+
+       rm -fr downstream.git &&
+       git init --bare downstream.git &&
+       cat <<-\EOT >expect &&
+       The following changes since commit OBJECT_NAME:
+
+         SUBJECT (DATE)
+
+       are available in the git repository at:
+         URL BRANCH
+
+       SHORTLOG
+
+       DIFFSTAT
+       EOT
+       (
+               cd local &&
+               git checkout initial &&
+               git merge --ff-only master &&
+               git push origin master:for-upstream &&
+               git request-pull initial "$downstream_url" >../request
+       ) &&
+       <request sed -nf fuzz.sed >request.fuzzy &&
+       test_cmp expect request.fuzzy
+
+'
+
+test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
+
+       (
+               cd local &&
+               OPTIONS_KEEPDASHDASH=Yes &&
+               export OPTIONS_KEEPDASHDASH &&
+               git checkout initial &&
+               git merge --ff-only master &&
+               git push origin master:for-upstream &&
+               git request-pull -- initial "$downstream_url" >../request
+       )
+
+'
+
+test_done
index 7649b810b1469724ff738fb0bf8b23ea61b37bda..bbb9c1251d97bdaf5bca8f8260e481c3cac56dea 100755 (executable)
@@ -147,7 +147,7 @@ test_expect_success \
            git cat-file $t $object || return 1
         done <obj-list
     } >current &&
-    diff expect current'
+    test_cmp expect current'
 
 test_expect_success \
     'use packed deltified (REF_DELTA) objects' \
@@ -162,7 +162,7 @@ test_expect_success \
            git cat-file $t $object || return 1
         done <obj-list
     } >current &&
-    diff expect current'
+    test_cmp expect current'
 
 test_expect_success \
     'use packed deltified (OFS_DELTA) objects' \
@@ -177,7 +177,7 @@ test_expect_success \
            git cat-file $t $object || return 1
         done <obj-list
     } >current &&
-    diff expect current'
+    test_cmp expect current'
 
 unset GIT_OBJECT_DIRECTORY
 
index 4360e77d317bfdaf7b40795859b4a023a5b89c13..fb3a270822c9a4ac2e4f79bfa71c784291859d4f 100755 (executable)
@@ -74,7 +74,7 @@ if msg=$(git verify-pack -v "test-3-${pack3}.pack" 2>&1) ||
 then
        test_set_prereq OFF64_T
 else
-       say "skipping tests concerning 64-bit offsets"
+       say "skipping tests concerning 64-bit offsets"
 fi
 
 test_expect_success OFF64_T \
index d5db75d826c8584e1d7f0f5ef298021fecd6f055..bab1a536f562c63db67035712588d3e9a5222649 100755 (executable)
@@ -6,7 +6,7 @@ test_description='test automatic tag following'
 
 case $(uname -s) in
 *MINGW*)
-       say "GIT_DEBUG_SEND_PACK not supported - skipping tests"
+       skip_all="GIT_DEBUG_SEND_PACK not supported - skipping tests"
        test_done
 esac
 
index 230c0cd784b317856749609cf64a5067e35a6965..5d1c66ea7166b0b4d631b681f344e0eefb84d899 100755 (executable)
@@ -320,6 +320,69 @@ test_expect_success 'add alt && prune' '
         git rev-parse --verify refs/remotes/origin/side2)
 '
 
+cat >test/expect <<\EOF
+some-tag
+EOF
+
+test_expect_success 'add with reachable tags (default)' '
+       (cd one &&
+        >foobar &&
+        git add foobar &&
+        git commit -m "Foobar" &&
+        git tag -a -m "Foobar tag" foobar-tag &&
+        git reset --hard HEAD~1 &&
+        git tag -a -m "Some tag" some-tag) &&
+       (mkdir add-tags &&
+        cd add-tags &&
+        git init &&
+        git remote add -f origin ../one &&
+        git tag -l some-tag >../test/output &&
+        git tag -l foobar-tag >>../test/output &&
+        test_must_fail git config remote.origin.tagopt) &&
+       test_cmp test/expect test/output
+'
+
+cat >test/expect <<\EOF
+some-tag
+foobar-tag
+--tags
+EOF
+
+test_expect_success 'add --tags' '
+       (rm -rf add-tags &&
+        mkdir add-tags &&
+        cd add-tags &&
+        git init &&
+        git remote add -f --tags origin ../one &&
+        git tag -l some-tag >../test/output &&
+        git tag -l foobar-tag >>../test/output &&
+        git config remote.origin.tagopt >>../test/output) &&
+       test_cmp test/expect test/output
+'
+
+cat >test/expect <<\EOF
+--no-tags
+EOF
+
+test_expect_success 'add --no-tags' '
+       (rm -rf add-tags &&
+        mkdir add-no-tags &&
+        cd add-no-tags &&
+        git init &&
+        git remote add -f --no-tags origin ../one &&
+        git tag -l some-tag >../test/output &&
+        git tag -l foobar-tag >../test/output &&
+        git config remote.origin.tagopt >>../test/output) &&
+       (cd one &&
+        git tag -d some-tag foobar-tag) &&
+       test_cmp test/expect test/output
+'
+
+test_expect_success 'reject --no-no-tags' '
+       (cd add-no-tags &&
+        test_must_fail git remote add -f --no-no-tags neworigin ../one)
+'
+
 cat > one/expect << EOF
   apis/master
   apis/side
@@ -372,7 +435,7 @@ test_expect_success 'update --prune' '
         git branch -m side2 side3) &&
        (cd test &&
         git remote update --prune &&
-        (cd ../one && git branch -m side3 side2)
+        (cd ../one && git branch -m side3 side2) &&
         git rev-parse refs/remotes/origin/side3 &&
         test_must_fail git rev-parse refs/remotes/origin/side2)
 '
@@ -534,6 +597,94 @@ test_expect_success 'show empty remote' '
        )
 '
 
+test_expect_success 'remote set-branches requires a remote' '
+       test_must_fail git remote set-branches &&
+       test_must_fail git remote set-branches --add
+'
+
+test_expect_success 'remote set-branches' '
+       echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
+       sort <<-\EOF >expect.add &&
+       +refs/heads/*:refs/remotes/scratch/*
+       +refs/heads/other:refs/remotes/scratch/other
+       EOF
+       sort <<-\EOF >expect.replace &&
+       +refs/heads/maint:refs/remotes/scratch/maint
+       +refs/heads/master:refs/remotes/scratch/master
+       +refs/heads/next:refs/remotes/scratch/next
+       EOF
+       sort <<-\EOF >expect.add-two &&
+       +refs/heads/maint:refs/remotes/scratch/maint
+       +refs/heads/master:refs/remotes/scratch/master
+       +refs/heads/next:refs/remotes/scratch/next
+       +refs/heads/pu:refs/remotes/scratch/pu
+       +refs/heads/t/topic:refs/remotes/scratch/t/topic
+       EOF
+       sort <<-\EOF >expect.setup-ffonly &&
+       refs/heads/master:refs/remotes/scratch/master
+       +refs/heads/next:refs/remotes/scratch/next
+       EOF
+       sort <<-\EOF >expect.respect-ffonly &&
+       refs/heads/master:refs/remotes/scratch/master
+       +refs/heads/next:refs/remotes/scratch/next
+       +refs/heads/pu:refs/remotes/scratch/pu
+       EOF
+
+       git clone .git/ setbranches &&
+       (
+               cd setbranches &&
+               git remote rename origin scratch &&
+               git config --get-all remote.scratch.fetch >config-result &&
+               sort <config-result >../actual.initial &&
+
+               git remote set-branches scratch --add other &&
+               git config --get-all remote.scratch.fetch >config-result &&
+               sort <config-result >../actual.add &&
+
+               git remote set-branches scratch maint master next &&
+               git config --get-all remote.scratch.fetch >config-result &&
+               sort <config-result >../actual.replace &&
+
+               git remote set-branches --add scratch pu t/topic &&
+               git config --get-all remote.scratch.fetch >config-result &&
+               sort <config-result >../actual.add-two &&
+
+               git config --unset-all remote.scratch.fetch &&
+               git config remote.scratch.fetch \
+                       refs/heads/master:refs/remotes/scratch/master &&
+               git config --add remote.scratch.fetch \
+                       +refs/heads/next:refs/remotes/scratch/next &&
+               git config --get-all remote.scratch.fetch >config-result &&
+               sort <config-result >../actual.setup-ffonly &&
+
+               git remote set-branches --add scratch pu &&
+               git config --get-all remote.scratch.fetch >config-result &&
+               sort <config-result >../actual.respect-ffonly
+       ) &&
+       test_cmp expect.initial actual.initial &&
+       test_cmp expect.add actual.add &&
+       test_cmp expect.replace actual.replace &&
+       test_cmp expect.add-two actual.add-two &&
+       test_cmp expect.setup-ffonly actual.setup-ffonly &&
+       test_cmp expect.respect-ffonly actual.respect-ffonly
+'
+
+test_expect_success 'remote set-branches with --mirror' '
+       echo "+refs/*:refs/*" >expect.initial &&
+       echo "+refs/heads/master:refs/heads/master" >expect.replace &&
+       git clone --mirror .git/ setbranches-mirror &&
+       (
+               cd setbranches-mirror &&
+               git remote rename origin scratch &&
+               git config --get-all remote.scratch.fetch >../actual.initial &&
+
+               git remote set-branches scratch heads/master &&
+               git config --get-all remote.scratch.fetch >../actual.replace
+       ) &&
+       test_cmp expect.initial actual.initial &&
+       test_cmp expect.replace actual.replace
+'
+
 test_expect_success 'new remote' '
        git remote add someremote foo &&
        echo foo >expect &&
index 721821ec92e476ed9a16222bc49b72f2fd9b2c68..4eb10f602fdcba354c6d140ed6b910ee89641708 100755 (executable)
@@ -71,7 +71,7 @@ test_expect_success "fetch test for-merge" '
                echo "$one_in_two       "
        } >expected &&
        cut -f -2 .git/FETCH_HEAD >actual &&
-       diff expected actual'
+       test_cmp expected actual'
 
 test_expect_success 'fetch tags when there is no tags' '
 
index 1dd8eed5bb3cb0f320a8f0780452e52fa7d8da16..d1912351db7da4a7c457fd44895b5ea076c84e7e 100755 (executable)
@@ -49,4 +49,78 @@ test_expect_success 'ls-remote self' '
 
 '
 
+test_expect_success 'dies when no remote specified and no default remotes found' '
+
+       test_must_fail git ls-remote
+
+'
+
+test_expect_success 'use "origin" when no remote specified' '
+
+       URL="$(pwd)/.git" &&
+       echo "From $URL" >exp_err &&
+
+       git remote add origin "$URL" &&
+       git ls-remote 2>actual_err >actual &&
+
+       test_cmp exp_err actual_err &&
+       test_cmp expected.all actual
+
+'
+
+test_expect_success 'suppress "From <url>" with -q' '
+
+       git ls-remote -q 2>actual_err &&
+       test_must_fail test_cmp exp_err actual_err
+
+'
+
+test_expect_success 'use branch.<name>.remote if possible' '
+
+       #
+       # Test that we are indeed using branch.<name>.remote, not "origin", even
+       # though the "origin" remote has been set.
+       #
+
+       # setup a new remote to differentiate from "origin"
+       git clone . other.git &&
+       (
+               cd other.git &&
+               echo "$(git rev-parse HEAD)     HEAD"
+               git show-ref    | sed -e "s/ /  /"
+       ) >exp &&
+
+       URL="other.git" &&
+       echo "From $URL" >exp_err &&
+
+       git remote add other $URL &&
+       git config branch.master.remote other &&
+
+       git ls-remote 2>actual_err >actual &&
+       test_cmp exp_err actual_err &&
+       test_cmp exp actual
+
+'
+
+cat >exp <<EOF
+fatal: 'refs*master' does not appear to be a git repository
+fatal: The remote end hung up unexpectedly
+EOF
+test_expect_success 'confuses pattern as remote when no remote specified' '
+       #
+       # Do not expect "git ls-remote <pattern>" to work; ls-remote, correctly,
+       # confuses <pattern> for <remote>. Although ugly, this behaviour is akin
+       # to the confusion of refspecs for remotes by git-fetch and git-push,
+       # eg:
+       #
+       #   $ git fetch branch
+       #
+
+       # We could just as easily have used "master"; the "*" emphasizes its
+       # role as a pattern.
+       test_must_fail git ls-remote refs*master >actual 2>&1 &&
+       test_cmp exp actual
+
+'
+
 test_done
index b8f64e13865a0f5fe24d90e6864b58962e8d384c..b11da79c9cafebb5af572bd8e9f85dfc6f3c3f77 100755 (executable)
@@ -64,13 +64,13 @@ check_push_result () {
 
 test_expect_success setup '
 
-       >path1 &&
+       >path1 &&
        git add path1 &&
        test_tick &&
        git commit -a -m repo &&
        the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
 
-       >path2 &&
+       >path2 &&
        git add path2 &&
        test_tick &&
        git commit -a -m second &&
@@ -483,8 +483,10 @@ git config --remove-section remote.there
 test_expect_success 'push with dry-run' '
 
        mk_test heads/master &&
-       (cd testrepo &&
-        old_commit=$(git show-ref -s --verify refs/heads/master)) &&
+       (
+               cd testrepo &&
+               old_commit=$(git show-ref -s --verify refs/heads/master)
+       ) &&
        git push --dry-run testrepo &&
        check_push_result $old_commit heads/master
 '
@@ -493,10 +495,13 @@ test_expect_success 'push updates local refs' '
 
        mk_test heads/master &&
        mk_child child &&
-       (cd child &&
+       (
+               cd child &&
                git pull .. master &&
                git push &&
-       test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
+               test $(git rev-parse master) = \
+                       $(git rev-parse remotes/origin/master)
+       )
 
 '
 
@@ -506,10 +511,13 @@ test_expect_success 'push updates up-to-date local refs' '
        mk_child child1 &&
        mk_child child2 &&
        (cd child1 && git pull .. master && git push) &&
-       (cd child2 &&
+       (
+               cd child2 &&
                git pull ../child1 master &&
                git push &&
-       test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
+               test $(git rev-parse master) = \
+                       $(git rev-parse remotes/origin/master)
+       )
 
 '
 
@@ -517,9 +525,11 @@ test_expect_success 'push preserves up-to-date packed refs' '
 
        mk_test heads/master &&
        mk_child child &&
-       (cd child &&
+       (
+               cd child &&
                git push &&
-       ! test -f .git/refs/remotes/origin/master)
+               ! test -f .git/refs/remotes/origin/master
+       )
 
 '
 
@@ -530,11 +540,13 @@ test_expect_success 'push does not update local refs on failure' '
        mkdir testrepo/.git/hooks &&
        echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
        chmod +x testrepo/.git/hooks/pre-receive &&
-       (cd child &&
+       (
+               cd child &&
                git pull .. master
                test_must_fail git push &&
                test $(git rev-parse master) != \
-                       $(git rev-parse remotes/origin/master))
+                       $(git rev-parse remotes/origin/master)
+       )
 
 '
 
@@ -575,34 +587,41 @@ test_expect_success 'push --delete refuses src:dest refspecs' '
 
 test_expect_success 'warn on push to HEAD of non-bare repository' '
        mk_test heads/master
-       (cd testrepo &&
+       (
+               cd testrepo &&
                git checkout master &&
-               git config receive.denyCurrentBranch warn) &&
+               git config receive.denyCurrentBranch warn
+       ) &&
        git push testrepo master 2>stderr &&
        grep "warning: updating the current branch" stderr
 '
 
 test_expect_success 'deny push to HEAD of non-bare repository' '
        mk_test heads/master
-       (cd testrepo &&
+       (
+               cd testrepo &&
                git checkout master &&
-               git config receive.denyCurrentBranch true) &&
+               git config receive.denyCurrentBranch true
+       ) &&
        test_must_fail git push testrepo master
 '
 
 test_expect_success 'allow push to HEAD of bare repository (bare)' '
        mk_test heads/master
-       (cd testrepo &&
+       (
+               cd testrepo &&
                git checkout master &&
                git config receive.denyCurrentBranch true &&
-               git config core.bare true) &&
+               git config core.bare true
+       ) &&
        git push testrepo master 2>stderr &&
        ! grep "warning: updating the current branch" stderr
 '
 
 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
        mk_test heads/master
-       (cd testrepo &&
+       (
+               cd testrepo &&
                git checkout master &&
                git config receive.denyCurrentBranch false
        ) &&
@@ -615,7 +634,8 @@ test_expect_success 'fetch with branches' '
        git branch second $the_first_commit &&
        git checkout second &&
        echo ".." > testrepo/.git/branches/branch1 &&
-       (cd testrepo &&
+       (
+               cd testrepo &&
                git fetch branch1 &&
                r=$(git show-ref -s --verify refs/heads/branch1) &&
                test "z$r" = "z$the_commit" &&
@@ -627,7 +647,8 @@ test_expect_success 'fetch with branches' '
 test_expect_success 'fetch with branches containing #' '
        mk_empty &&
        echo "..#second" > testrepo/.git/branches/branch2 &&
-       (cd testrepo &&
+       (
+               cd testrepo &&
                git fetch branch2 &&
                r=$(git show-ref -s --verify refs/heads/branch2) &&
                test "z$r" = "z$the_first_commit" &&
@@ -641,7 +662,8 @@ test_expect_success 'push with branches' '
        git checkout second &&
        echo "testrepo" > .git/branches/branch1 &&
        git push branch1 &&
-       (cd testrepo &&
+       (
+               cd testrepo &&
                r=$(git show-ref -s --verify refs/heads/master) &&
                test "z$r" = "z$the_first_commit" &&
                test 1 = $(git for-each-ref refs/heads | wc -l)
@@ -652,7 +674,8 @@ test_expect_success 'push with branches containing #' '
        mk_empty &&
        echo "testrepo#branch3" > .git/branches/branch2 &&
        git push branch2 &&
-       (cd testrepo &&
+       (
+               cd testrepo &&
                r=$(git show-ref -s --verify refs/heads/branch3) &&
                test "z$r" = "z$the_first_commit" &&
                test 1 = $(git for-each-ref refs/heads | wc -l)
index dd2ee842e020c23b49ed4e2070c4e31cdb7ac055..0b489f5b1227268c050c1256d105d57d871f5698 100755 (executable)
@@ -4,6 +4,11 @@ test_description='pulling into void'
 
 . ./test-lib.sh
 
+modify () {
+       sed -e "$1" <"$2" >"$2.x" &&
+       mv "$2.x" "$2"
+}
+
 D=`pwd`
 
 test_expect_success setup '
@@ -26,7 +31,7 @@ cd "$D"
 test_expect_success 'checking the results' '
        test -f file &&
        test -f cloned/file &&
-       diff file cloned/file
+       test_cmp file cloned/file
 '
 
 test_expect_success 'pulling into void using master:master' '
@@ -160,4 +165,61 @@ test_expect_success 'pull --rebase works on branch yet to be born' '
        test_cmp expect actual
 '
 
+test_expect_success 'setup for detecting upstreamed changes' '
+       mkdir src &&
+       (cd src &&
+        git init &&
+        printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
+        git add stuff &&
+        git commit -m "Initial revision"
+       ) &&
+       git clone src dst &&
+       (cd src &&
+        modify s/5/43/ stuff &&
+        git commit -a -m "5->43" &&
+        modify s/6/42/ stuff &&
+        git commit -a -m "Make it bigger"
+       ) &&
+       (cd dst &&
+        modify s/5/43/ stuff &&
+        git commit -a -m "Independent discovery of 5->43"
+       )
+'
+
+test_expect_success 'git pull --rebase detects upstreamed changes' '
+       (cd dst &&
+        git pull --rebase &&
+        test -z "$(git ls-files -u)"
+       )
+'
+
+test_expect_success 'setup for avoiding reapplying old patches' '
+       (cd dst &&
+        test_might_fail git rebase --abort &&
+        git reset --hard origin/master
+       ) &&
+       git clone --bare src src-replace.git &&
+       rm -rf src &&
+       mv src-replace.git src &&
+       (cd dst &&
+        modify s/2/22/ stuff &&
+        git commit -a -m "Change 2" &&
+        modify s/3/33/ stuff &&
+        git commit -a -m "Change 3" &&
+        modify s/4/44/ stuff &&
+        git commit -a -m "Change 4" &&
+        git push &&
+
+        modify s/44/55/ stuff &&
+        git commit --amend -a -m "Modified Change 4"
+       )
+'
+
+test_expect_success 'git pull --rebase does not reapply old patches' '
+       (cd dst &&
+        test_must_fail git pull --rebase &&
+        test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+       )
+'
+
 test_done
index 7206817ca1c7a450b47f9a1d7d8a3af53452dac6..298200fa4cafc61b5f16f9337314a2b887593a36 100755 (executable)
@@ -6,7 +6,7 @@ test_description='pulling from symlinked subdir'
 
 if ! test_have_prereq SYMLINKS
 then
-       say 'Symbolic links not supported, skipping tests.'
+       skip_all='Symbolic links not supported, skipping tests.'
        test_done
 fi
 
diff --git a/t/t5525-fetch-tagopt.sh b/t/t5525-fetch-tagopt.sh
new file mode 100755 (executable)
index 0000000..4fbf7a1
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+test_description='tagopt variable affects "git fetch" and is overridden by commandline.'
+
+. ./test-lib.sh
+
+setup_clone () {
+       git clone --mirror . $1 &&
+       git remote add remote_$1 $1 &&
+       (cd $1 &&
+       git tag tag_$1)
+}
+
+test_expect_success setup '
+       test_commit test &&
+       setup_clone one &&
+       git config remote.remote_one.tagopt --no-tags &&
+       setup_clone two &&
+       git config remote.remote_two.tagopt --tags
+       '
+
+test_expect_success "fetch with tagopt=--no-tags does not get tag" '
+       git fetch remote_one &&
+       test_must_fail git show-ref tag_one
+       '
+
+test_expect_success "fetch --tags with tagopt=--no-tags gets tag" '
+       git fetch --tags remote_one &&
+       git show-ref tag_one
+       '
+
+test_expect_success "fetch --no-tags with tagopt=--tags does not get tag" '
+       git fetch --no-tags remote_two &&
+       test_must_fail git show-ref tag_two
+       '
+
+test_expect_success "fetch with tagopt=--tags gets tag" '
+       git fetch remote_two &&
+       git show-ref tag_two
+       '
+test_done
index a696b8791b7caa44ae2bd16d6970a791f3a28d3d..044603c26ed62e3ddf03ebb2542f783e4dd7d9ff 100755 (executable)
@@ -32,9 +32,9 @@ test_expect_success 'fsck fails' '
 
 test_expect_success 'upload-pack fails due to error in pack-objects packing' '
 
-       ! echo "0032want $(git rev-parse HEAD)
-00000009done
-0000" | git upload-pack . > /dev/null 2> output.err &&
+       printf "0032want %s\n00000009done\n0000" \
+               $(git rev-parse HEAD) >input &&
+       test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
        grep "unable to read" output.err &&
        grep "pack-objects died" output.err
 '
@@ -51,9 +51,9 @@ test_expect_success 'fsck fails' '
 '
 test_expect_success 'upload-pack fails due to error in rev-list' '
 
-       ! echo "0032want $(git rev-parse HEAD)
-0034shallow $(git rev-parse HEAD^)00000009done
-0000" | git upload-pack . > /dev/null 2> output.err &&
+       printf "0032want %s\n0034shallow %s00000009done\n0000" \
+               $(git rev-parse HEAD) $(git rev-parse HEAD^) >input &&
+       test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
        # pack-objects survived
        grep "Total.*, reused" output.err &&
        # but there was an error, which must have been in rev-list
@@ -62,9 +62,9 @@ test_expect_success 'upload-pack fails due to error in rev-list' '
 
 test_expect_success 'upload-pack fails due to error in pack-objects enumeration' '
 
-       ! echo "0032want $(git rev-parse HEAD)
-00000009done
-0000" | git upload-pack . > /dev/null 2> output.err &&
+       printf "0032want %s\n00000009done\n0000" \
+               $(git rev-parse HEAD) >input &&
+       test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
        grep "bad tree object" output.err &&
        grep "pack-objects died" output.err
 '
index 37fe87541127887742530a8f8859f1dd369d3f34..a266ca56361347fe751495e1531b5a26e4733493 100755 (executable)
@@ -11,7 +11,7 @@ This test runs various sanity checks on http-push.'
 
 if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
 then
-       say "skipping test, USE_CURL_MULTI is not defined"
+       skip_all="skipping test, USE_CURL_MULTI is not defined"
        test_done
 fi
 
index 17e1bdc5a81ce4802f5074ddb9c1996c68fc97be..b0c2a2c3aea811ec023423bdb486de5412fa79c5 100755 (executable)
@@ -7,7 +7,7 @@ test_description='test smart pushing over http via http-backend'
 . ./test-lib.sh
 
 if test -n "$NO_CURL"; then
-       say 'skipping test, git built without http support'
+       skip_all='skipping test, git built without http support'
        test_done
 fi
 
@@ -128,7 +128,7 @@ test_expect_success 'push fails for non-fast-forward refs unmatched by remote he
 
        # push master too; this ensures there is at least one '"'push'"' command to
        # the remote helper and triggers interaction with the helper.
-       !(git push -v origin +master master:retsam >output 2>&1) &&
+       test_must_fail git push -v origin +master master:retsam >output 2>&1 &&
 
        grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
        grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output &&
index fc675b50adfa945724cd7d17dbb6034df53426d3..2fb48d09edb47129d9cea8b9686e46a6d8f35615 100755 (executable)
@@ -4,7 +4,7 @@ test_description='test dumb fetching over http via static file'
 . ./test-lib.sh
 
 if test -n "$NO_CURL"; then
-       say 'skipping test, git built without http support'
+       skip_all='skipping test, git built without http support'
        test_done
 fi
 
index 7faa31a299f263b0628d4a23e4500d3e43e0fdda..fd19121372aecc0806e17e62d639855f391045d3 100755 (executable)
@@ -4,7 +4,7 @@ test_description='test smart fetching over http via http-backend'
 . ./test-lib.sh
 
 if test -n "$NO_CURL"; then
-       say 'skipping test, git built without http support'
+       skip_all='skipping test, git built without http support'
        test_done
 fi
 
index 8c6d0b2f20c803574af273b9d7c4ffd41870adcc..b5d7fbc3815aed53ec50bdf7f5dbf2c796fed1fe 100755 (executable)
@@ -4,7 +4,7 @@ test_description='test git-http-backend'
 . ./test-lib.sh
 
 if test -n "$NO_CURL"; then
-       say 'skipping test, git built without http support'
+       skip_all='skipping test, git built without http support'
        test_done
 fi
 
index 678cee502de54e5a9c18a43f114446d3392ec7f3..8abb71afcd4d7389260baa6f82ecb9b53bb9524c 100755 (executable)
@@ -176,4 +176,16 @@ test_expect_success 'clone respects global branch.autosetuprebase' '
        )
 '
 
+test_expect_success 'respect url-encoding of file://' '
+       git init x+y &&
+       test_must_fail git clone "file://$PWD/x+y" xy-url &&
+       git clone "file://$PWD/x%2By" xy-url
+'
+
+test_expect_success 'do not respect url-encoding of non-url path' '
+       git init x+y &&
+       test_must_fail git clone x%2By xy-regular &&
+       git clone x+y xy-regular
+'
+
 test_done
index 1c109160690d273451f7a089be42e45f36a3b5bb..895f5595aee9341276e79497b9c4a8736c78e5e7 100755 (executable)
@@ -48,7 +48,7 @@ test_expect_success 'that reference gets used' \
 'cd C &&
 echo "0 objects, 0 kilobytes" > expected &&
 git count-objects > current &&
-diff expected current'
+test_cmp expected current'
 
 cd "$base_dir"
 
@@ -75,7 +75,7 @@ cd "$base_dir"
 test_expect_success 'that reference gets used' \
 'cd D && echo "0 objects, 0 kilobytes" > expected &&
 git count-objects > current &&
-diff expected current'
+test_cmp expected current'
 
 cd "$base_dir"
 
@@ -100,7 +100,7 @@ test_expect_success 'that alternate to origin gets used' \
 'cd C &&
 echo "2 objects" > expected &&
 git count-objects | cut -d, -f1 > current &&
-diff expected current'
+test_cmp expected current'
 
 cd "$base_dir"
 
@@ -116,7 +116,7 @@ test_expect_success 'check objects expected to exist locally' \
 'cd D &&
 echo "5 objects" > expected &&
 git count-objects | cut -d, -f1 > current &&
-diff expected current'
+test_cmp expected current'
 
 cd "$base_dir"
 
index 8afbdd4de2146be763f7454af66a15986490fe60..e4d1b6a0fa39d82d048f4dde62155a059173c5b4 100755 (executable)
@@ -4,7 +4,7 @@ test_description='Test cloning a repository larger than 2 gigabyte'
 . ./test-lib.sh
 
 test -z "$GIT_TEST_CLONE_2GB" &&
-say "Skipping expensive 2GB clone test; enable it with GIT_TEST_CLONE_2GB=t" &&
+skip_all="Skipping expensive 2GB clone test; enable it with GIT_TEST_CLONE_2GB=t" &&
 test_done &&
 exit
 
diff --git a/t/t5800-remote-helpers.sh b/t/t5800-remote-helpers.sh
new file mode 100755 (executable)
index 0000000..637d8e9
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Sverre Rabbelier
+#
+
+test_description='Test remote-helper import and export commands'
+
+. ./test-lib.sh
+
+if test_have_prereq PYTHON && "$PYTHON_PATH" -c '
+import sys
+if sys.hexversion < 0x02040000:
+    sys.exit(1)
+'
+then
+       :
+else
+       skip_all='skipping git remote-testgit tests: requires Python 2.4 or newer'
+       test_done
+fi
+
+test_expect_success 'setup repository' '
+       git init --bare server/.git &&
+       git clone server public &&
+       (cd public &&
+        echo content >file &&
+        git add file &&
+        git commit -m one &&
+        git push origin master)
+'
+
+test_expect_success 'cloning from local repo' '
+       git clone "testgit::${PWD}/server" localclone &&
+       test_cmp public/file localclone/file
+'
+
+test_expect_success 'cloning from remote repo' '
+       git clone "testgit::file://${PWD}/server" clone &&
+       test_cmp public/file clone/file
+'
+
+test_expect_success 'create new commit on remote' '
+       (cd public &&
+        echo content >>file &&
+        git commit -a -m two &&
+        git push)
+'
+
+test_expect_success 'pulling from local repo' '
+       (cd localclone && git pull) &&
+       test_cmp public/file localclone/file
+'
+
+test_expect_success 'pulling from remote remote' '
+       (cd clone && git pull) &&
+       test_cmp public/file clone/file
+'
+
+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)
+'
+
+test_expect_success 'synch with changes from localclone' '
+       (cd clone &&
+        git pull)
+'
+
+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)
+'
+
+test_done
index b2131cdacd93e0b62f4ef8fdc62b6a81c6aef6fc..fc57e7d3fd69c60144ee3fb3f66b252a67369b42 100755 (executable)
@@ -84,7 +84,7 @@ check () {
                git rev-list --parents --pretty=raw $arg |
                sed -n -e 's/^commit //p' >test.actual
        fi
-       diff test.expect test.actual
+       test_cmp test.expect test.actual
 }
 
 for type in basic parents parents-raw
index e8fde5c19c16f3fa2305ed319edb3289f4f758b9..cccacd4add48524abd4a3021f8048a6c45c245ea 100755 (executable)
@@ -101,6 +101,15 @@ commit 131a310eb913d107dd3c09a65d1651175898735d
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
 EOF
 
+test_format raw-body %B <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+changed foo
+
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+added foo
+
+EOF
+
 test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
 commit 131a310eb913d107dd3c09a65d1651175898735d
 \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
@@ -191,6 +200,16 @@ test_expect_success 'add LF before non-empty (2)' '
        grep "^$" actual
 '
 
+test_expect_success 'add SP before non-empty (1)' '
+       git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual &&
+       test $(wc -w <actual) = 2
+'
+
+test_expect_success 'add SP before non-empty (2)' '
+       git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual &&
+       test $(wc -w <actual) = 4
+'
+
 test_expect_success '--abbrev' '
        echo SHORT SHORT SHORT >expect2 &&
        echo LONG LONG LONG >expect3 &&
index 4b8611ce2092f9062aeaeb62ce19a9121d5be537..b565638e92655c12c841c29a108516a8b13cf8d2 100755 (executable)
@@ -32,6 +32,23 @@ test_expect_success setup '
        git tag B
 '
 
+cat >expect <<EOF
+<tags/B
+>tags/C
+EOF
+
+test_expect_success '--left-right' '
+       git rev-list --left-right B...C > actual &&
+       git name-rev --stdin --name-only --refs="*tags/*" \
+               < actual > actual.named &&
+       test_cmp actual.named expect
+'
+
+test_expect_success '--count' '
+       git rev-list --count B...C > actual &&
+       test "$(cat actual)" = 2
+'
+
 test_expect_success '--cherry-pick foo comes up empty' '
        test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)"
 '
@@ -54,4 +71,16 @@ test_expect_success '--cherry-pick with independent, but identical branches' '
                HEAD...master -- foo)"
 '
 
+cat >expect <<EOF
+1      2
+EOF
+
+# Insert an extra commit to break the symmetry
+test_expect_success '--count --left-right' '
+       git checkout branch &&
+       test_commit D &&
+       git rev-list --count --left-right B...D > actual &&
+       test_cmp expect actual
+'
+
 test_done
index 8d3fa7d014c1e5a856f6c4c35cfb46eb8c44e684..58428d9f5c3d079b0e842b5851b100f9e895a239 100755 (executable)
@@ -34,7 +34,9 @@ test_expect_success 'setup' '
        git checkout master &&
        commit master2 &&
        git tag foo/bar master &&
-       git update-ref refs/remotes/foo/baz master
+       commit master3 &&
+       git update-ref refs/remotes/foo/baz master &&
+       commit master4
 '
 
 test_expect_success 'rev-parse --glob=refs/heads/subspace/*' '
@@ -162,6 +164,13 @@ test_expect_success 'rev-list --branches=subspace' '
        compare rev-list "subspace/one subspace/two" "--branches=subspace"
 
 '
+
+test_expect_success 'rev-list --branches' '
+
+       compare rev-list "master subspace-x someref other/three subspace/one subspace/two" "--branches"
+
+'
+
 test_expect_success 'rev-list --glob=heads/someref/* master' '
 
        compare rev-list "master" "--glob=heads/someref/* master"
@@ -186,6 +195,12 @@ test_expect_success 'rev-list --tags=foo' '
 
 '
 
+test_expect_success 'rev-list --tags' '
+
+       compare rev-list "foo/bar" "--tags"
+
+'
+
 test_expect_success 'rev-list --remotes=foo' '
 
        compare rev-list "foo/baz" "--remotes=foo"
diff --git a/t/t6019-rev-list-ancestry-path.sh b/t/t6019-rev-list-ancestry-path.sh
new file mode 100755 (executable)
index 0000000..7641029
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+test_description='--ancestry-path'
+
+#          D---E-------F
+#         /     \       \
+#    B---C---G---H---I---J
+#   /                     \
+#  A-------K---------------L--M
+#
+#  D..M                 == E F G H I J K L M
+#  --ancestry-path D..M == E F H I J L M
+#
+#  D..M -- M.t                 == M
+#  --ancestry-path D..M -- M.t == M
+
+. ./test-lib.sh
+
+test_merge () {
+       test_tick &&
+       git merge -s ours -m "$2" "$1" &&
+       git tag "$2"
+}
+
+test_expect_success setup '
+       test_commit A &&
+       test_commit B &&
+       test_commit C &&
+       test_commit D &&
+       test_commit E &&
+       test_commit F &&
+       git reset --hard C &&
+       test_commit G &&
+       test_merge E H &&
+       test_commit I &&
+       test_merge F J &&
+       git reset --hard A &&
+       test_commit K &&
+       test_merge J L &&
+       test_commit M
+'
+
+test_expect_success 'rev-list D..M' '
+       for c in E F G H I J K L M; do echo $c; done >expect &&
+       git rev-list --format=%s D..M |
+       sed -e "/^commit /d" |
+       sort >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'rev-list --ancestry-path D..M' '
+       for c in E F H I J L M; do echo $c; done >expect &&
+       git rev-list --ancestry-path --format=%s D..M |
+       sed -e "/^commit /d" |
+       sort >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'rev-list D..M -- M.t' '
+       echo M >expect &&
+       git rev-list --format=%s D..M -- M.t |
+       sed -e "/^commit /d" >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'rev-list --ancestry-patch D..M -- M.t' '
+       echo M >expect &&
+       git rev-list --ancestry-path --format=%s D..M -- M.t |
+       sed -e "/^commit /d" >actual &&
+       test_cmp expect actual
+'
+
+test_done
index e3f7ae8120aa2a46b25dd3830597cb863a5f5e20..b66544b76d545a396ef068438f3980b3f544efdd 100755 (executable)
@@ -280,7 +280,7 @@ test_expect_success 'updated working tree file should prevent the merge' '
                echo "BAD: should have complained"
                return 1
        }
-       diff M M.saved || {
+       test_cmp M M.saved || {
                echo "BAD: should have left M intact"
                return 1
        }
@@ -301,7 +301,7 @@ test_expect_success 'updated working tree file should prevent the merge' '
                echo "BAD: should have complained"
                return 1
        }
-       diff M M.saved || {
+       test_cmp M M.saved || {
                echo "BAD: should have left M intact"
                return 1
        }
index 3202e1de6d01bf3c36e82351c7f8426cc2bb44ab..cd3190c4a61f0404491b41a1b22f5143b63f4992 100755 (executable)
@@ -5,7 +5,7 @@ test_description='merging when a directory was replaced with a symlink'
 
 if ! test_have_prereq SYMLINKS
 then
-       say 'Symbolic links not supported, skipping tests.'
+       skip_all='Symbolic links not supported, skipping tests.'
        test_done
 fi
 
index 203ffdb17a914654d35416575b6797a2825ce4e6..4185b7ca1d3679b458d16753581fe78e3b68b376 100755 (executable)
@@ -219,6 +219,12 @@ test_expect_success 'bisect and replacements' '
      git bisect reset
 '
 
+test_expect_success 'index-pack and replacements' '
+       git --no-replace-objects rev-list --objects HEAD |
+       git --no-replace-objects pack-objects test- &&
+       git index-pack test-*.pack
+'
+
 #
 #
 test_done
index 8052c86ad3516505765ab214f4801940c8cc1684..7dc8a510c7f33d048cd3268424298fdda2f8c2bb 100755 (executable)
@@ -295,6 +295,15 @@ test_expect_success 'Check short upstream format' '
        test_cmp expected actual
 '
 
+cat >expected <<EOF
+67a36f1
+EOF
+
+test_expect_success 'Check short objectname format' '
+       git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'Check for invalid refname format' '
        test_must_fail git for-each-ref --format="%(refname:INVALID)"
 '
index 0da13a8d6b8f75ba041a353dfc6a356c1e8bbed0..2c55801ee8b88b2d97968a24706dcfdab824668b 100755 (executable)
@@ -143,11 +143,12 @@ test_expect_success 'more setup' '
 test_expect_success 'use index-filter to move into a subdirectory' '
        git branch directorymoved &&
        git filter-branch -f --index-filter \
-                "git ls-files -s | sed \"s-\\t-&newsubdir/-\" |
+                "git ls-files -s | sed \"s-    -&newsubdir/-\" |
                  GIT_INDEX_FILE=\$GIT_INDEX_FILE.new \
                        git update-index --index-info &&
                  mv \"\$GIT_INDEX_FILE.new\" \"\$GIT_INDEX_FILE\"" directorymoved &&
-       test -z "$(git diff HEAD directorymoved:newsubdir)"'
+       git diff --exit-code HEAD directorymoved:newsubdir
+'
 
 test_expect_success 'stops when msg filter fails' '
        old=$(git rev-parse HEAD) &&
index 73dbc4360b58c95ae135577031fb8e60b3f395f7..ac943f5eeecd17dd1edc5834265df9e16e5032f2 100755 (executable)
@@ -583,7 +583,7 @@ test_expect_success \
 # subsequent tests require gpg; check if it is available
 gpg --version >/dev/null 2>/dev/null
 if [ $? -eq 127 ]; then
-       say "gpg not found - skipping tag signing and verification tests"
+       say "gpg not found - skipping tag signing and verification tests"
 else
        # As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
        # the gpg version 1.0.6 didn't parse trust packets correctly, so for
index 6355698c6b5d133988270b5c5ded3b0209b1bf03..26ddf9d496f6eacddbec603659be7fca3dff294b 100755 (executable)
@@ -38,7 +38,7 @@ test_expect_success setup '
        test_commit "$msg" &&
        echo "$msg" >expect &&
        git show -s --format=%s > actual &&
-       diff actual expect
+       test_cmp actual expect
 
 '
 
@@ -85,7 +85,7 @@ do
                git --exec-path=. commit --amend &&
                git show -s --pretty=oneline |
                sed -e "s/^[0-9a-f]* //" >actual &&
-               diff actual expect
+               test_cmp actual expect
        '
 done
 
@@ -107,13 +107,13 @@ do
                git --exec-path=. commit --amend &&
                git show -s --pretty=oneline |
                sed -e "s/^[0-9a-f]* //" >actual &&
-               diff actual expect
+               test_cmp actual expect
        '
 done
 
 if ! echo 'echo space > "$1"' > "e space.sh"
 then
-       say "Skipping; FS does not support spaces in filenames"
+       skip_all="Skipping; FS does not support spaces in filenames"
        test_done
 fi
 
index 0f6b367832ed164a126abc6206e724a7a0e4feb0..71d3ceff8f06ad33aee5e48f85e97164df447a59 100755 (executable)
@@ -3,6 +3,7 @@
 test_description='Test automatic use of a pager.'
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-pager.sh
 
 cleanup_fail() {
        echo >&2 cleanup failed
@@ -36,11 +37,11 @@ then
        }
        test_set_prereq TTY
 else
-       say no usable terminal, so skipping some tests
+       say "# no usable terminal, so skipping some tests"
 fi
 
 test_expect_success 'setup' '
-       unset GIT_PAGER GIT_PAGER_IN_USE &&
+       unset GIT_PAGER GIT_PAGER_IN_USE;
        test_might_fail git config --unset core.pager &&
 
        PAGER="cat >paginated.out" &&
@@ -158,72 +159,214 @@ test_expect_success 'color when writing to a file intended for a pager' '
        colorful colorful.log
 '
 
-test_expect_success 'determine default pager' '
-       unset PAGER GIT_PAGER &&
-       test_might_fail git config --unset core.pager ||
-       cleanup_fail &&
-
-       less=$(git var GIT_PAGER) &&
-       test -n "$less"
-'
-
-if expr "$less" : '[a-z][a-z]*$' >/dev/null && test_have_prereq TTY
+if test_have_prereq SIMPLEPAGER && test_have_prereq TTY
 then
-       test_set_prereq SIMPLEPAGER
+       test_set_prereq SIMPLEPAGERTTY
 fi
 
-test_expect_success SIMPLEPAGER 'default pager is used by default' '
-       unset PAGER GIT_PAGER &&
-       test_might_fail git config --unset core.pager &&
-       rm -f default_pager_used ||
-       cleanup_fail &&
+# Use this helper to make it easy for the caller of your
+# terminal-using function to specify whether it should fail.
+# If you write
+#
+#      your_test() {
+#              parse_args "$@"
+#
+#              $test_expectation "$cmd - behaves well" "
+#                      ...
+#                      $full_command &&
+#                      ...
+#              "
+#      }
+#
+# then your test can be used like this:
+#
+#      your_test expect_(success|failure) [test_must_fail] 'git foo'
+#
+parse_args() {
+       test_expectation="test_$1"
+       shift
+       if test "$1" = test_must_fail
+       then
+               full_command="test_must_fail test_terminal "
+               shift
+       else
+               full_command="test_terminal "
+       fi
+       cmd=$1
+       full_command="$full_command $1"
+}
 
-       cat >$less <<-\EOF &&
-       #!/bin/sh
-       wc >default_pager_used
-       EOF
-       chmod +x $less &&
-       (
-               PATH=.:$PATH &&
-               export PATH &&
-               test_terminal git log
-       ) &&
-       test -e default_pager_used
-'
+test_default_pager() {
+       parse_args "$@"
+
+       $test_expectation SIMPLEPAGERTTY "$cmd - default pager is used by default" "
+               unset PAGER GIT_PAGER;
+               test_might_fail git config --unset core.pager &&
+               rm -f default_pager_used ||
+               cleanup_fail &&
+
+               cat >\$less <<-\EOF &&
+               #!/bin/sh
+               wc >default_pager_used
+               EOF
+               chmod +x \$less &&
+               (
+                       PATH=.:\$PATH &&
+                       export PATH &&
+                       $full_command
+               ) &&
+               test -e default_pager_used
+       "
+}
 
-test_expect_success TTY 'PAGER overrides default pager' '
-       unset GIT_PAGER &&
-       test_might_fail git config --unset core.pager &&
-       rm -f PAGER_used ||
-       cleanup_fail &&
+test_PAGER_overrides() {
+       parse_args "$@"
 
-       PAGER="wc >PAGER_used" &&
-       export PAGER &&
-       test_terminal git log &&
-       test -e PAGER_used
-'
+       $test_expectation TTY "$cmd - PAGER overrides default pager" "
+               unset GIT_PAGER;
+               test_might_fail git config --unset core.pager &&
+               rm -f PAGER_used ||
+               cleanup_fail &&
 
-test_expect_success TTY 'core.pager overrides PAGER' '
-       unset GIT_PAGER &&
-       rm -f core.pager_used ||
-       cleanup_fail &&
+               PAGER='wc >PAGER_used' &&
+               export PAGER &&
+               $full_command &&
+               test -e PAGER_used
+       "
+}
 
-       PAGER=wc &&
-       export PAGER &&
-       git config core.pager "wc >core.pager_used" &&
-       test_terminal git log &&
-       test -e core.pager_used
-'
+test_core_pager_overrides() {
+       if_local_config=
+       used_if_wanted='overrides PAGER'
+       test_core_pager "$@"
+}
 
-test_expect_success TTY 'GIT_PAGER overrides core.pager' '
-       rm -f GIT_PAGER_used ||
-       cleanup_fail &&
+test_local_config_ignored() {
+       if_local_config='! '
+       used_if_wanted='is not used'
+       test_core_pager "$@"
+}
 
-       git config core.pager wc &&
-       GIT_PAGER="wc >GIT_PAGER_used" &&
-       export GIT_PAGER &&
-       test_terminal git log &&
-       test -e GIT_PAGER_used
+test_core_pager() {
+       parse_args "$@"
+
+       $test_expectation TTY "$cmd - repository-local core.pager setting $used_if_wanted" "
+               unset GIT_PAGER;
+               rm -f core.pager_used ||
+               cleanup_fail &&
+
+               PAGER=wc &&
+               export PAGER &&
+               git config core.pager 'wc >core.pager_used' &&
+               $full_command &&
+               ${if_local_config}test -e core.pager_used
+       "
+}
+
+test_core_pager_subdir() {
+       if_local_config=
+       used_if_wanted='overrides PAGER'
+       test_pager_subdir_helper "$@"
+}
+
+test_no_local_config_subdir() {
+       if_local_config='! '
+       used_if_wanted='is not used'
+       test_pager_subdir_helper "$@"
+}
+
+test_pager_subdir_helper() {
+       parse_args "$@"
+
+       $test_expectation TTY "$cmd - core.pager $used_if_wanted from subdirectory" "
+               unset GIT_PAGER;
+               rm -f core.pager_used &&
+               rm -fr sub ||
+               cleanup_fail &&
+
+               PAGER=wc &&
+               stampname=\$(pwd)/core.pager_used &&
+               export PAGER stampname &&
+               git config core.pager 'wc >\"\$stampname\"' &&
+               mkdir sub &&
+               (
+                       cd sub &&
+                       $full_command
+               ) &&
+               ${if_local_config}test -e core.pager_used
+       "
+}
+
+test_GIT_PAGER_overrides() {
+       parse_args "$@"
+
+       $test_expectation TTY "$cmd - GIT_PAGER overrides core.pager" "
+               rm -f GIT_PAGER_used ||
+               cleanup_fail &&
+
+               git config core.pager wc &&
+               GIT_PAGER='wc >GIT_PAGER_used' &&
+               export GIT_PAGER &&
+               $full_command &&
+               test -e GIT_PAGER_used
+       "
+}
+
+test_doesnt_paginate() {
+       parse_args "$@"
+
+       $test_expectation TTY "no pager for '$cmd'" "
+               rm -f GIT_PAGER_used ||
+               cleanup_fail &&
+
+               GIT_PAGER='wc >GIT_PAGER_used' &&
+               export GIT_PAGER &&
+               $full_command &&
+               ! test -e GIT_PAGER_used
+       "
+}
+
+test_pager_choices() {
+       test_default_pager        expect_success "$@"
+       test_PAGER_overrides      expect_success "$@"
+       test_core_pager_overrides expect_success "$@"
+       test_core_pager_subdir    expect_success "$@"
+       test_GIT_PAGER_overrides  expect_success "$@"
+}
+
+test_expect_success 'setup: some aliases' '
+       git config alias.aliasedlog log &&
+       git config alias.true "!true"
 '
 
+test_pager_choices                       'git log'
+test_pager_choices                       'git -p log'
+test_pager_choices                       'git aliasedlog'
+
+test_default_pager        expect_success 'git -p aliasedlog'
+test_PAGER_overrides      expect_success 'git -p aliasedlog'
+test_core_pager_overrides expect_success 'git -p aliasedlog'
+test_core_pager_subdir    expect_failure 'git -p aliasedlog'
+test_GIT_PAGER_overrides  expect_success 'git -p aliasedlog'
+
+test_default_pager        expect_success 'git -p true'
+test_PAGER_overrides      expect_success 'git -p true'
+test_core_pager_overrides expect_success 'git -p true'
+test_core_pager_subdir    expect_failure 'git -p true'
+test_GIT_PAGER_overrides  expect_success 'git -p true'
+
+test_default_pager        expect_success test_must_fail 'git -p request-pull'
+test_PAGER_overrides      expect_success test_must_fail 'git -p request-pull'
+test_core_pager_overrides expect_success test_must_fail 'git -p request-pull'
+test_core_pager_subdir    expect_failure test_must_fail 'git -p request-pull'
+test_GIT_PAGER_overrides  expect_success test_must_fail 'git -p request-pull'
+
+test_default_pager        expect_success test_must_fail 'git -p'
+test_PAGER_overrides      expect_success test_must_fail 'git -p'
+test_local_config_ignored expect_failure test_must_fail 'git -p'
+test_no_local_config_subdir expect_success test_must_fail 'git -p'
+test_GIT_PAGER_overrides  expect_success test_must_fail 'git -p'
+
+test_doesnt_paginate      expect_failure test_must_fail 'git -p nonsense'
+
 test_done
diff --git a/t/t7008-grep-binary.sh b/t/t7008-grep-binary.sh
new file mode 100755 (executable)
index 0000000..eb8ca88
--- /dev/null
@@ -0,0 +1,102 @@
+#!/bin/sh
+
+test_description='git grep in binary files'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' "
+       printf 'binary\000file\n' >a &&
+       git add a &&
+       git commit -m.
+"
+
+test_expect_success 'git grep ina a' '
+       echo Binary file a matches >expect &&
+       git grep ina a >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'git grep -ah ina a' '
+       git grep -ah ina a >actual &&
+       test_cmp a actual
+'
+
+test_expect_success 'git grep -I ina a' '
+       : >expect &&
+       test_must_fail git grep -I ina a >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'git grep -c ina a' '
+       echo a:1 >expect &&
+       git grep -c ina a >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'git grep -l ina a' '
+       echo a >expect &&
+       git grep -l ina a >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'git grep -L bar a' '
+       echo a >expect &&
+       git grep -L bar a >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'git grep -q ina a' '
+       : >expect &&
+       git grep -q ina a >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'git grep -F ile a' '
+       git grep -F ile a
+'
+
+test_expect_success 'git grep -Fi iLE a' '
+       git grep -Fi iLE a
+'
+
+# This test actually passes on platforms where regexec() supports the
+# flag REG_STARTEND.
+test_expect_failure 'git grep ile a' '
+       git grep ile a
+'
+
+test_expect_failure 'git grep .fi a' '
+       git grep .fi a
+'
+
+test_expect_success 'git grep -F y<NUL>f a' "
+       printf 'y\000f' >f &&
+       git grep -f f -F a
+"
+
+test_expect_success 'git grep -F y<NUL>x a' "
+       printf 'y\000x' >f &&
+       test_must_fail git grep -f f -F a
+"
+
+test_expect_success 'git grep -Fi Y<NUL>f a' "
+       printf 'Y\000f' >f &&
+       git grep -f f -Fi a
+"
+
+test_expect_failure 'git grep -Fi Y<NUL>x a' "
+       printf 'Y\000x' >f &&
+       test_must_fail git grep -f f -Fi a
+"
+
+test_expect_success 'git grep y<NUL>f a' "
+       printf 'y\000f' >f &&
+       git grep -f f a
+"
+
+test_expect_failure 'git grep y<NUL>x a' "
+       printf 'y\000x' >f &&
+       test_must_fail git grep -f f a
+"
+
+test_done
index 1a4dc5f89353df7d7bda4bea539ee5bd7a3b9bae..9bda97058499ecab88dc6de7551d7909e1ad5a2e 100755 (executable)
@@ -11,226 +11,317 @@ subcommands of git submodule.
 
 . ./test-lib.sh
 
-#
-# Test setup:
-#  -create a repository in directory init
-#  -add a couple of files
-#  -add directory init to 'superproject', this creates a DIRLINK entry
-#  -add a couple of regular files to enable testing of submodule filtering
-#  -mv init subrepo
-#  -add an entry to .gitmodules for submodule 'example'
-#
-test_expect_success 'Prepare submodule testing' '
-       : > t &&
+test_expect_success 'setup - initial commit' '
+       >t &&
        git add t &&
        git commit -m "initial commit" &&
-       git branch initial HEAD &&
+       git branch initial
+'
+
+test_expect_success 'setup - repository in init subdirectory' '
        mkdir init &&
-       cd init &&
-       git init &&
-       echo a >a &&
-       git add a &&
-       git commit -m "submodule commit 1" &&
-       git tag -a -m "rev-1" rev-1 &&
-       rev1=$(git rev-parse HEAD) &&
-       if test -z "$rev1"
-       then
-               echo "[OOPS] submodule git rev-parse returned nothing"
-               false
-       fi &&
-       cd .. &&
+       (
+               cd init &&
+               git init &&
+               echo a >a &&
+               git add a &&
+               git commit -m "submodule commit 1" &&
+               git tag -a -m "rev-1" rev-1
+       )
+'
+
+test_expect_success 'setup - commit with gitlink' '
        echo a >a &&
        echo z >z &&
        git add a init z &&
-       git commit -m "super commit 1" &&
-       mv init .subrepo &&
-       GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git
+       git commit -m "super commit 1"
+'
+
+test_expect_success 'setup - hide init subdirectory' '
+       mv init .subrepo
+'
+
+test_expect_success 'setup - repository to add submodules to' '
+       git init addtest &&
+       git init addtest-ignore
 '
 
-test_expect_success 'Prepare submodule add testing' '
-       submodurl=$(pwd)
+# The 'submodule add' tests need some repository to add as a submodule.
+# The trash directory is a good one as any.
+submodurl=$TRASH_DIRECTORY
+
+listbranches() {
+       git for-each-ref --format='%(refname)' 'refs/heads/*'
+}
+
+inspect() {
+       dir=$1 &&
+       dotdot="${2:-..}" &&
+
        (
-               mkdir addtest &&
-               cd addtest &&
-               git init
+               cd "$dir" &&
+               listbranches >"$dotdot/heads" &&
+               { git symbolic-ref HEAD || :; } >"$dotdot/head" &&
+               git rev-parse HEAD >"$dotdot/head-sha1" &&
+               git update-index --refresh &&
+               git diff-files --exit-code &&
+               git clean -n -d -x >"$dotdot/untracked"
        )
-'
+}
 
 test_expect_success 'submodule add' '
+       echo "refs/heads/master" >expect &&
+       >empty &&
+
        (
                cd addtest &&
                git submodule add "$submodurl" submod &&
                git submodule init
+       ) &&
+
+       rm -f heads head untracked &&
+       inspect addtest/submod ../.. &&
+       test_cmp expect heads &&
+       test_cmp expect head &&
+       test_cmp empty untracked
+'
+
+test_expect_success 'submodule add to .gitignored path fails' '
+       (
+               cd addtest-ignore &&
+               cat <<-\EOF >expect &&
+               The following path is ignored by one of your .gitignore files:
+               submod
+               Use -f if you really want to add it.
+               EOF
+               # Does not use test_commit due to the ignore
+               echo "*" > .gitignore &&
+               git add --force .gitignore &&
+               git commit -m"Ignore everything" &&
+               ! git submodule add "$submodurl" submod >actual 2>&1 &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'submodule add to .gitignored path with --force' '
+       (
+               cd addtest-ignore &&
+               git submodule add --force "$submodurl" submod
        )
 '
 
 test_expect_success 'submodule add --branch' '
+       echo "refs/heads/initial" >expect-head &&
+       cat <<-\EOF >expect-heads &&
+       refs/heads/initial
+       refs/heads/master
+       EOF
+       >empty &&
+
        (
                cd addtest &&
                git submodule add -b initial "$submodurl" submod-branch &&
-               git submodule init &&
-               cd submod-branch &&
-               git branch | grep initial
-       )
+               git submodule init
+       ) &&
+
+       rm -f heads head untracked &&
+       inspect addtest/submod-branch ../.. &&
+       test_cmp expect-heads heads &&
+       test_cmp expect-head head &&
+       test_cmp empty untracked
 '
 
 test_expect_success 'submodule add with ./ in path' '
+       echo "refs/heads/master" >expect &&
+       >empty &&
+
        (
                cd addtest &&
                git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
                git submodule init
-       )
+       ) &&
+
+       rm -f heads head untracked &&
+       inspect addtest/dotsubmod/frotz ../../.. &&
+       test_cmp expect heads &&
+       test_cmp expect head &&
+       test_cmp empty untracked
 '
 
 test_expect_success 'submodule add with // in path' '
+       echo "refs/heads/master" >expect &&
+       >empty &&
+
        (
                cd addtest &&
                git submodule add "$submodurl" slashslashsubmod///frotz// &&
                git submodule init
-       )
+       ) &&
+
+       rm -f heads head untracked &&
+       inspect addtest/slashslashsubmod/frotz ../../.. &&
+       test_cmp expect heads &&
+       test_cmp expect head &&
+       test_cmp empty untracked
 '
 
 test_expect_success 'submodule add with /.. in path' '
+       echo "refs/heads/master" >expect &&
+       >empty &&
+
        (
                cd addtest &&
                git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
                git submodule init
-       )
+       ) &&
+
+       rm -f heads head untracked &&
+       inspect addtest/realsubmod ../.. &&
+       test_cmp expect heads &&
+       test_cmp expect head &&
+       test_cmp empty untracked
 '
 
 test_expect_success 'submodule add with ./, /.. and // in path' '
+       echo "refs/heads/master" >expect &&
+       >empty &&
+
        (
                cd addtest &&
                git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
                git submodule init
-       )
+       ) &&
+
+       rm -f heads head untracked &&
+       inspect addtest/realsubmod2 ../.. &&
+       test_cmp expect heads &&
+       test_cmp expect head &&
+       test_cmp empty untracked
+'
+
+test_expect_success 'setup - add an example entry to .gitmodules' '
+       GIT_CONFIG=.gitmodules \
+       git config submodule.example.url git://example.com/init.git
 '
 
 test_expect_success 'status should fail for unmapped paths' '
-       if git submodule status
-       then
-               echo "[OOPS] submodule status succeeded"
-               false
-       elif ! GIT_CONFIG=.gitmodules git config submodule.example.path init
-       then
-               echo "[OOPS] git config failed to update .gitmodules"
-               false
-       fi
+       test_must_fail git submodule status
+'
+
+test_expect_success 'setup - map path in .gitmodules' '
+       cat <<\EOF >expect &&
+[submodule "example"]
+       url = git://example.com/init.git
+       path = init
+EOF
+
+       GIT_CONFIG=.gitmodules git config submodule.example.path init &&
+
+       test_cmp expect .gitmodules
 '
 
 test_expect_success 'status should only print one line' '
-       lines=$(git submodule status | wc -l) &&
-       test $lines = 1
+       git submodule status >lines &&
+       test $(wc -l <lines) = 1
+'
+
+test_expect_success 'setup - fetch commit name from submodule' '
+       rev1=$(cd .subrepo && git rev-parse HEAD) &&
+       printf "rev1: %s\n" "$rev1" &&
+       test -n "$rev1"
 '
 
 test_expect_success 'status should initially be "missing"' '
-       git submodule status | grep "^-$rev1"
+       git submodule status >lines &&
+       grep "^-$rev1" lines
 '
 
 test_expect_success 'init should register submodule url in .git/config' '
+       echo git://example.com/init.git >expect &&
+
        git submodule init &&
-       url=$(git config submodule.example.url) &&
-       if test "$url" != "git://example.com/init.git"
-       then
-               echo "[OOPS] init succeeded but submodule url is wrong"
-               false
-       elif test_must_fail git config submodule.example.url ./.subrepo
-       then
-               echo "[OOPS] init succeeded but update of url failed"
-               false
-       fi
+       git config submodule.example.url >url &&
+       git config submodule.example.url ./.subrepo &&
+
+       test_cmp expect url
 '
 
 test_expect_success 'update should fail when path is used by a file' '
+       echo hello >expect &&
+
        echo "hello" >init &&
-       if git submodule update
-       then
-               echo "[OOPS] update should have failed"
-               false
-       elif test "$(cat init)" != "hello"
-       then
-               echo "[OOPS] update failed but init file was molested"
-               false
-       else
-               rm init
-       fi
+       test_must_fail git submodule update &&
+
+       test_cmp expect init
 '
 
 test_expect_success 'update should fail when path is used by a nonempty directory' '
+       echo hello >expect &&
+
+       rm -fr init &&
        mkdir init &&
        echo "hello" >init/a &&
-       if git submodule update
-       then
-               echo "[OOPS] update should have failed"
-               false
-       elif test "$(cat init/a)" != "hello"
-       then
-               echo "[OOPS] update failed but init/a was molested"
-               false
-       else
-               rm init/a
-       fi
+
+       test_must_fail git submodule update &&
+
+       test_cmp expect init/a
 '
 
 test_expect_success 'update should work when path is an empty dir' '
-       rm -rf init &&
+       rm -fr init &&
+       rm -f head-sha1 &&
+       echo "$rev1" >expect &&
+
        mkdir init &&
        git submodule update &&
-       head=$(cd init && git rev-parse HEAD) &&
-       if test -z "$head"
-       then
-               echo "[OOPS] Failed to obtain submodule head"
-               false
-       elif test "$head" != "$rev1"
-       then
-               echo "[OOPS] Submodule head is $head but should have been $rev1"
-               false
-       fi
+
+       inspect init &&
+       test_cmp expect head-sha1
 '
 
 test_expect_success 'status should be "up-to-date" after update' '
-       git submodule status | grep "^ $rev1"
+       git submodule status >list &&
+       grep "^ $rev1" list
 '
 
 test_expect_success 'status should be "modified" after submodule commit' '
-       cd init &&
-       echo b >b &&
-       git add b &&
-       git commit -m "submodule commit 2" &&
-       rev2=$(git rev-parse HEAD) &&
-       cd .. &&
-       if test -z "$rev2"
-       then
-               echo "[OOPS] submodule git rev-parse returned nothing"
-               false
-       fi &&
-       git submodule status | grep "^+$rev2"
+       (
+               cd init &&
+               echo b >b &&
+               git add b &&
+               git commit -m "submodule commit 2"
+       ) &&
+
+       rev2=$(cd init && git rev-parse HEAD) &&
+       test -n "$rev2" &&
+       git submodule status >list &&
+
+       grep "^+$rev2" list
 '
 
 test_expect_success 'the --cached sha1 should be rev1' '
-       git submodule --cached status | grep "^+$rev1"
+       git submodule --cached status >list &&
+       grep "^+$rev1" list
 '
 
 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
-       git diff | grep "^+Subproject commit $rev2"
+       git diff >diff &&
+       grep "^+Subproject commit $rev2" diff
 '
 
 test_expect_success 'update should checkout rev1' '
+       rm -f head-sha1 &&
+       echo "$rev1" >expect &&
+
        git submodule update init &&
-       head=$(cd init && git rev-parse HEAD) &&
-       if test -z "$head"
-       then
-               echo "[OOPS] submodule git rev-parse returned nothing"
-               false
-       elif test "$head" != "$rev1"
-       then
-               echo "[OOPS] init did not checkout correct head"
-               false
-       fi
+       inspect init &&
+
+       test_cmp expect head-sha1
 '
 
 test_expect_success 'status should be "up-to-date" after update' '
-       git submodule status | grep "^ $rev1"
+       git submodule status >list &&
+       grep "^ $rev1" list
 '
 
 test_expect_success 'checkout superproject with subproject already present' '
@@ -239,6 +330,8 @@ test_expect_success 'checkout superproject with subproject already present' '
 '
 
 test_expect_success 'apply submodule diff' '
+       >empty &&
+
        git branch second &&
        (
                cd init &&
@@ -251,21 +344,24 @@ test_expect_success 'apply submodule diff' '
        git format-patch -1 --stdout >P.diff &&
        git checkout second &&
        git apply --index P.diff &&
-       D=$(git diff --cached master) &&
-       test -z "$D"
+
+       git diff --cached master >staged &&
+       test_cmp empty staged
 '
 
 test_expect_success 'update --init' '
-
        mv init init2 &&
        git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
-       git config --remove-section submodule.example
+       git config --remove-section submodule.example &&
+       test_must_fail git config submodule.example.url &&
+
        git submodule update init > update.out &&
+       cat update.out &&
        grep "not initialized" update.out &&
-       test ! -d init/.git &&
+       ! test -d init/.git &&
+
        git submodule update --init init &&
        test -d init/.git
-
 '
 
 test_expect_success 'do not add files from a submodule' '
index 7538756487d9b9483143b338104cd6af13397a91..02522f9627eea8166b2d4709ef3519b23c8dd3d5 100755 (executable)
@@ -14,7 +14,7 @@ test_expect_success setup '
        echo file > file &&
        git add file &&
        test_tick &&
-       git commit -m upstream
+       git commit -m upstream &&
        git clone . super &&
        git clone super submodule &&
        (cd super &&
@@ -42,7 +42,7 @@ test_expect_success 'change submodule url' '
        ) &&
        mv submodule moved-submodule &&
        (cd super &&
-        git config -f .gitmodules submodule.submodule.url ../moved-submodule
+        git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
         test_tick &&
         git commit -a -m moved-submodule
        )
@@ -58,6 +58,9 @@ test_expect_success '"git submodule sync" should update submodule URLs' '
        (cd super-clone/submodule &&
         git checkout master &&
         git pull
+       ) &&
+       (cd super-clone &&
+        test -d "$(git config submodule.submodule.url)"
        )
 '
 
index 2a527750ce4a81bc168b8ad3d8b09174f487b142..db9365b6454b18eb07f5c0798e13e18d696498c6 100755 (executable)
@@ -59,11 +59,13 @@ test_expect_success 'setup a submodule tree' '
 sub1sha1=$(cd super/sub1 && git rev-parse HEAD)
 sub3sha1=$(cd super/sub3 && git rev-parse HEAD)
 
+pwd=$(pwd)
+
 cat > expect <<EOF
 Entering 'sub1'
-foo1-sub1-$sub1sha1
+$pwd/clone-foo1-sub1-$sub1sha1
 Entering 'sub3'
-foo3-sub3-$sub3sha1
+$pwd/clone-foo3-sub3-$sub3sha1
 EOF
 
 test_expect_success 'test basic "submodule foreach" usage' '
@@ -71,7 +73,9 @@ test_expect_success 'test basic "submodule foreach" usage' '
        (
                cd clone &&
                git submodule update --init -- sub1 sub3 &&
-               git submodule foreach "echo \$name-\$path-\$sha1" > ../actual
+               git submodule foreach "echo \$toplevel-\$name-\$path-\$sha1" > ../actual &&
+               git config foo.bar zar &&
+               git submodule foreach "git config --file \"\$toplevel/.git/config\" foo.bar"
        ) &&
        test_cmp expect actual
 '
index 9f5c3edb0392c321092e56e2bf46fd096f74cf75..aa9c577e9e306bce05cd0fe076c56017c1b97e41 100755 (executable)
@@ -193,4 +193,26 @@ test_expect_success 'commit -F overrides -t' '
        commit_msg_is "-F log"
 '
 
+test_expect_success 'Commit without message is allowed with --allow-empty-message' '
+       echo "more content" >>foo &&
+       git add foo &&
+       >empty &&
+       git commit --allow-empty-message <empty &&
+       commit_msg_is ""
+'
+
+test_expect_success 'Commit without message is no-no without --allow-empty-message' '
+       echo "more content" >>foo &&
+       git add foo &&
+       >empty &&
+       test_must_fail git commit <empty
+'
+
+test_expect_success 'Commit a message with --allow-empty-message' '
+       echo "even more content" >>foo &&
+       git add foo &&
+       git commit --allow-empty-message -m"hello there" &&
+       commit_msg_is "hello there"
+'
+
 test_done
index 008d5711b818a315136290c141c830cdf5af80a0..a72fe3ae640378350102a07124aee201fb1c637b 100755 (executable)
@@ -107,13 +107,32 @@ A  dir2/added
 ?? untracked
 EOF
 
-test_expect_success 'status -s (2)' '
+test_expect_success 'status -s' '
 
        git status -s >output &&
        test_cmp expect output
 
 '
 
+cat >expect <<\EOF
+## master
+ M dir1/modified
+A  dir2/added
+?? dir1/untracked
+?? dir2/modified
+?? dir2/untracked
+?? expect
+?? output
+?? untracked
+EOF
+
+test_expect_success 'status -s -b' '
+
+       git status -s -b >output &&
+       test_cmp expect output
+
+'
+
 cat >expect <<EOF
 # On branch master
 # Changes to be committed:
@@ -436,6 +455,25 @@ test_expect_success 'status -s with color.status' '
 
 '
 
+cat >expect <<\EOF
+## <GREEN>master<RESET>
+ <RED>M<RESET> dir1/modified
+<GREEN>A<RESET>  dir2/added
+<BLUE>??<RESET> dir1/untracked
+<BLUE>??<RESET> dir2/modified
+<BLUE>??<RESET> dir2/untracked
+<BLUE>??<RESET> expect
+<BLUE>??<RESET> output
+<BLUE>??<RESET> untracked
+EOF
+
+test_expect_success 'status -s -b with color.status' '
+
+       git status -s -b | test_decode_color >output &&
+       test_cmp expect output
+
+'
+
 cat >expect <<\EOF
  M dir1/modified
 A  dir2/added
@@ -469,6 +507,13 @@ test_expect_success 'status --porcelain ignores color.status' '
 git config --unset color.status
 git config --unset color.ui
 
+test_expect_success 'status --porcelain ignores -b' '
+
+       git status --porcelain -b >output &&
+       test_cmp expect output
+
+'
+
 cat >expect <<\EOF
 # On branch master
 # Changes to be committed:
@@ -763,4 +808,131 @@ test_expect_success POSIXPERM 'status succeeds in a read-only repository' '
        (exit $status)
 '
 
+cat > expect << EOF
+# On branch master
+# Changed but not updated:
+#   (use "git add <file>..." to update what will be committed)
+#   (use "git checkout -- <file>..." to discard changes in working directory)
+#
+#      modified:   dir1/modified
+#
+# Untracked files:
+#   (use "git add <file>..." to include in what will be committed)
+#
+#      dir1/untracked
+#      dir2/modified
+#      dir2/untracked
+#      expect
+#      output
+#      untracked
+no changes added to commit (use "git add" and/or "git commit -a")
+EOF
+
+test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
+       echo modified > sm/untracked &&
+       git status --ignore-submodules=untracked > output &&
+       test_cmp expect output
+'
+
+test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' '
+       git status --ignore-submodules=dirty > output &&
+       test_cmp expect output
+'
+
+test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' '
+       echo modified > sm/foo &&
+       git status --ignore-submodules=dirty > output &&
+       test_cmp expect output
+'
+
+cat > expect << EOF
+# On branch master
+# Changed but not updated:
+#   (use "git add <file>..." to update what will be committed)
+#   (use "git checkout -- <file>..." to discard changes in working directory)
+#   (commit or discard the untracked or modified content in submodules)
+#
+#      modified:   dir1/modified
+#      modified:   sm (modified content)
+#
+# Untracked files:
+#   (use "git add <file>..." to include in what will be committed)
+#
+#      dir1/untracked
+#      dir2/modified
+#      dir2/untracked
+#      expect
+#      output
+#      untracked
+no changes added to commit (use "git add" and/or "git commit -a")
+EOF
+
+test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
+       git status --ignore-submodules=untracked > output &&
+       test_cmp expect output
+'
+
+head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --verify HEAD)
+
+cat > expect << EOF
+# On branch master
+# Changed but not updated:
+#   (use "git add <file>..." to update what will be committed)
+#   (use "git checkout -- <file>..." to discard changes in working directory)
+#
+#      modified:   dir1/modified
+#      modified:   sm (new commits)
+#
+# Submodules changed but not updated:
+#
+# * sm $head...$head2 (1):
+#   > 2nd commit
+#
+# Untracked files:
+#   (use "git add <file>..." to include in what will be committed)
+#
+#      dir1/untracked
+#      dir2/modified
+#      dir2/untracked
+#      expect
+#      output
+#      untracked
+no changes added to commit (use "git add" and/or "git commit -a")
+EOF
+
+test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
+       git status --ignore-submodules=untracked > output &&
+       test_cmp expect output
+'
+
+test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" '
+       git status --ignore-submodules=dirty > output &&
+       test_cmp expect output
+'
+
+cat > expect << EOF
+# On branch master
+# Changed but not updated:
+#   (use "git add <file>..." to update what will be committed)
+#   (use "git checkout -- <file>..." to discard changes in working directory)
+#
+#      modified:   dir1/modified
+#
+# Untracked files:
+#   (use "git add <file>..." to include in what will be committed)
+#
+#      dir1/untracked
+#      dir2/modified
+#      dir2/untracked
+#      expect
+#      output
+#      untracked
+no changes added to commit (use "git add" and/or "git commit -a")
+EOF
+
+test_expect_success "--ignore-submodules=all suppresses submodule summary" '
+       git status --ignore-submodules=all > output &&
+       test_cmp expect output
+'
+
 test_done
index 57f6d2bae7c63f13ee18e11737dbdcc0c080ab10..cde8390c1b9df6e6537a3538d8da11511b6644ec 100755 (executable)
@@ -554,8 +554,7 @@ test_debug 'gitk --all'
 
 test_expect_success 'refresh the index before merging' '
        git reset --hard c1 &&
-       sleep 1 &&
-       touch file &&
+       cp file file.n && mv -f file.n file &&
        git merge c3
 '
 
index f4aa0547501a19fe570304e830504ff984f5a9a9..c2f66ff1703c35d5f5b92285e31e8df157e51642 100755 (executable)
@@ -8,6 +8,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
        echo content1 > file1 &&
        echo content2 > file2 &&
        git add . &&
+       test_tick &&
        git commit -m initial_commit &&
        # Create two packs
        # The first pack will contain all of the objects except one
@@ -40,6 +41,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
        echo content3 > file3 &&
        objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
        git add file3 &&
+       test_tick &&
        git commit -m commit_file3 &&
        git repack -a -d -l &&
        git prune-packed &&
@@ -73,6 +75,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
        rm -f .git/objects/pack/* &&
        echo new_content >> file1 &&
        git add file1 &&
+       test_tick &&
        git commit -m more_content &&
        git repack &&
        git repack -a -d &&
@@ -118,8 +121,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
        mv .git/objects/pack/* alt_objects/pack/ &&
        csha1=$(git rev-parse HEAD^{commit}) &&
        git reset --hard HEAD^ &&
-       sleep 1 &&
-       git reflog expire --expire=now --expire-unreachable=now --all &&
+       test_tick &&
+       git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
        # The pack-objects call on the next line is equivalent to
        # git repack -A -d without the call to prune-packed
        git pack-objects --honor-pack-keep --non-empty --all --reflog \
@@ -156,7 +159,7 @@ test_expect_success 'objects made unreachable by grafts only are kept' '
        H1=$(git rev-parse HEAD^) &&
        H2=$(git rev-parse HEAD^^) &&
        echo "$H0 $H2" > .git/info/grafts &&
-       git reflog expire --expire=now --expire-unreachable=now --all &&
+       git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
        git repack -a -d &&
        git cat-file -t $H1
        '
index 5babdf26e625933268b911cc6e81f6a448f7f78d..200ab61278643e8b9deb4f624a95378e7e4c5b67 100755 (executable)
@@ -11,17 +11,20 @@ tsha1=
 test_expect_success '-A with -d option leaves unreachable objects unpacked' '
        echo content > file1 &&
        git add . &&
+       test_tick &&
        git commit -m initial_commit &&
        # create a transient branch with unique content
        git checkout -b transient_branch &&
        echo more content >> file1 &&
        # record the objects created in the database for file, commit, tree
        fsha1=$(git hash-object file1) &&
+       test_tick &&
        git commit -a -m more_content &&
        csha1=$(git rev-parse HEAD^{commit}) &&
        tsha1=$(git rev-parse HEAD^{tree}) &&
        git checkout master &&
        echo even more content >> file1 &&
+       test_tick &&
        git commit -a -m even_more_content &&
        # delete the transient branch
        git branch -D transient_branch &&
@@ -34,9 +37,11 @@ test_expect_success '-A with -d option leaves unreachable objects unpacked' '
        git show $fsha1 &&
        git show $csha1 &&
        git show $tsha1 &&
-       # now expire the reflog
-       sleep 1 &&
-       git reflog expire --expire-unreachable=now --all &&
+       # now expire the reflog, while keeping reachable ones but expiring
+       # unreachables immediately
+       test_tick &&
+       sometimeago=$(( $test_tick - 10000 )) &&
+       git reflog expire --expire=$sometimeago --expire-unreachable=$test_tick --all &&
        # and repack
        git repack -A -d -l &&
        # verify objects are retained unpacked
@@ -71,7 +76,7 @@ test_expect_success '-A without -d option leaves unreachable objects packed' '
        test 1 = $(ls -1 .git/objects/pack/pack-*.pack | wc -l) &&
        packfile=$(ls .git/objects/pack/pack-*.pack) &&
        git branch -D transient_branch &&
-       sleep 1 &&
+       test_tick &&
        git repack -A -l &&
        test ! -f "$fsha1path" &&
        test ! -f "$csha1path" &&
index 1de83ef98fdcbfd63469e66ba4886c2477b983ff..196827e7eacf0584379630f528fb7a4400f2b865 100755 (executable)
@@ -11,7 +11,7 @@ Testing basic diff tool invocation
 . ./test-lib.sh
 
 if ! test_have_prereq PERL; then
-       say 'skipping difftool tests, perl not available'
+       skip_all='skipping difftool tests, perl not available'
        test_done
 fi
 
similarity index 98%
rename from t/t7002-grep.sh
rename to t/t7810-grep.sh
index e249c3ed4176b4934ae57541ab8b671801968eae..8a6322765c965bfc3a9158cc14312fdf03295090 100755 (executable)
@@ -60,7 +60,7 @@ do
                        echo ${HC}file:5:foo_mmap bar mmap baz
                } >expected &&
                git grep -n -w -e mmap $H >actual &&
-               diff expected actual
+               test_cmp expected actual
        '
 
        test_expect_success "grep -w $L (w)" '
@@ -74,7 +74,7 @@ do
                        echo ${HC}x:1:x x xx x
                } >expected &&
                git grep -n -w -e "x xx* x" $H >actual &&
-               diff expected actual
+               test_cmp expected actual
        '
 
        test_expect_success "grep -w $L (y-1)" '
@@ -82,7 +82,7 @@ do
                        echo ${HC}y:1:y yy
                } >expected &&
                git grep -n -w -e "^y" $H >actual &&
-               diff expected actual
+               test_cmp expected actual
        '
 
        test_expect_success "grep -w $L (y-2)" '
@@ -93,7 +93,7 @@ do
                        cat actual
                        false
                else
-                       diff expected actual
+                       test_cmp expected actual
                fi
        '
 
@@ -105,14 +105,14 @@ do
                        cat actual
                        false
                else
-                       diff expected actual
+                       test_cmp expected actual
                fi
        '
 
        test_expect_success "grep $L (t-1)" '
                echo "${HC}t/t:1:test" >expected &&
                git grep -n -e test $H >actual &&
-               diff expected actual
+               test_cmp expected actual
        '
 
        test_expect_success "grep $L (t-2)" '
@@ -121,7 +121,7 @@ do
                        cd t &&
                        git grep -n -e test $H
                ) >actual &&
-               diff expected actual
+               test_cmp expected actual
        '
 
        test_expect_success "grep $L (t-3)" '
@@ -130,7 +130,7 @@ do
                        cd t &&
                        git grep --full-name -n -e test $H
                ) >actual &&
-               diff expected actual
+               test_cmp expected actual
        '
 
        test_expect_success "grep -c $L (no /dev/null)" '
diff --git a/t/t7811-grep-open.sh b/t/t7811-grep-open.sh
new file mode 100755 (executable)
index 0000000..568a6f2
--- /dev/null
@@ -0,0 +1,168 @@
+#!/bin/sh
+
+test_description='git grep --open-files-in-pager
+'
+
+. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-pager.sh
+unset PAGER GIT_PAGER
+
+test_expect_success 'setup' '
+       test_commit initial grep.h "
+enum grep_pat_token {
+       GREP_PATTERN,
+       GREP_PATTERN_HEAD,
+       GREP_PATTERN_BODY,
+       GREP_AND,
+       GREP_OPEN_PAREN,
+       GREP_CLOSE_PAREN,
+       GREP_NOT,
+       GREP_OR,
+};" &&
+
+       test_commit add-user revision.c "
+       }
+       if (seen_dashdash)
+               read_pathspec_from_stdin(revs, &sb, prune);
+       strbuf_release(&sb);
+}
+
+static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
+{
+       append_grep_pattern(&revs->grep_filter, ptn, \"command line\", 0, what);
+" &&
+
+       mkdir subdir &&
+       test_commit subdir subdir/grep.c "enum grep_pat_token" &&
+
+       test_commit uninteresting unrelated "hello, world" &&
+
+       echo GREP_PATTERN >untracked
+'
+
+test_expect_success SIMPLEPAGER 'git grep -O' '
+       cat >$less <<-\EOF &&
+       #!/bin/sh
+       printf "%s\n" "$@" >pager-args
+       EOF
+       chmod +x $less &&
+       cat >expect.less <<-\EOF &&
+       +/*GREP_PATTERN
+       grep.h
+       EOF
+       echo grep.h >expect.notless &&
+       >empty &&
+
+       PATH=.:$PATH git grep -O GREP_PATTERN >out &&
+       {
+               test_cmp expect.less pager-args ||
+               test_cmp expect.notless pager-args
+       } &&
+       test_cmp empty out
+'
+
+test_expect_success 'git grep -O --cached' '
+       test_must_fail git grep --cached -O GREP_PATTERN >out 2>msg &&
+       grep open-files-in-pager msg
+'
+
+test_expect_success 'git grep -O --no-index' '
+       rm -f expect.less pager-args out &&
+       cat >expect <<-\EOF &&
+       grep.h
+       untracked
+       EOF
+       >empty &&
+
+       (
+               GIT_PAGER='\''printf "%s\n" >pager-args'\'' &&
+               export GIT_PAGER &&
+               git grep --no-index -O GREP_PATTERN >out
+       ) &&
+       test_cmp expect pager-args &&
+       test_cmp empty out
+'
+
+test_expect_success 'setup: fake "less"' '
+       cat >less <<-\EOF &&
+       #!/bin/sh
+       printf "%s\n" "$@" >actual
+       EOF
+       chmod +x less
+'
+
+test_expect_success 'git grep -O jumps to line in less' '
+       cat >expect <<-\EOF &&
+       +/*GREP_PATTERN
+       grep.h
+       EOF
+       >empty &&
+
+       GIT_PAGER=./less git grep -O GREP_PATTERN >out &&
+       test_cmp expect actual &&
+       test_cmp empty out &&
+
+       git grep -O./less GREP_PATTERN >out2 &&
+       test_cmp expect actual &&
+       test_cmp empty out2
+'
+
+test_expect_success 'modified file' '
+       rm -f actual &&
+       cat >expect <<-\EOF &&
+       +/*enum grep_pat_token
+       grep.h
+       revision.c
+       subdir/grep.c
+       unrelated
+       EOF
+       >empty &&
+
+       echo "enum grep_pat_token" >unrelated &&
+       test_when_finished "git checkout HEAD unrelated" &&
+       GIT_PAGER=./less git grep -F -O "enum grep_pat_token" >out &&
+       test_cmp expect actual &&
+       test_cmp empty out
+'
+
+test_config() {
+       git config "$1" "$2" &&
+       test_when_finished "git config --unset $1"
+}
+
+test_expect_success 'copes with color settings' '
+       rm -f actual &&
+       echo grep.h >expect &&
+       test_config color.grep always &&
+       test_config color.grep.filename yellow &&
+       test_config color.grep.separator green &&
+       git grep -O'\''printf "%s\n" >actual'\'' GREP_AND &&
+       test_cmp expect actual
+'
+
+test_expect_success 'run from subdir' '
+       rm -f actual &&
+       echo grep.c >expect &&
+       >empty &&
+
+       (
+               cd subdir &&
+               export GIT_PAGER &&
+               GIT_PAGER='\''printf "%s\n" >../args'\'' &&
+               git grep -O "enum grep_pat_token" >../out &&
+               git grep -O"pwd >../dir; :" "enum grep_pat_token" >../out2
+       ) &&
+       case $(cat dir) in
+       *subdir)
+               : good
+               ;;
+       *)
+               false
+               ;;
+       esac &&
+       test_cmp expect args &&
+       test_cmp empty out &&
+       test_cmp empty out2
+'
+
+test_done
diff --git a/t/t8006-blame-textconv.sh b/t/t8006-blame-textconv.sh
new file mode 100755 (executable)
index 0000000..9ad96d4
--- /dev/null
@@ -0,0 +1,80 @@
+#!/bin/sh
+
+test_description='git blame textconv support'
+. ./test-lib.sh
+
+find_blame() {
+       sed -e 's/^[^(]*//'
+}
+
+cat >helper <<'EOF'
+#!/bin/sh
+sed 's/^/converted: /' "$@"
+EOF
+chmod +x helper
+
+test_expect_success 'setup ' '
+       echo test 1 >one.bin &&
+       echo test number 2 >two.bin &&
+       git add . &&
+       GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
+       echo test 1 version 2 >one.bin &&
+       echo test number 2 version 2 >>two.bin &&
+       GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
+'
+
+cat >expected <<EOF
+(Number2 2010-01-01 20:00:00 +0000 1) test 1 version 2
+EOF
+
+test_expect_success 'no filter specified' '
+       git blame one.bin >blame &&
+       find_blame Number2 <blame >result &&
+       test_cmp expected result
+'
+
+test_expect_success 'setup textconv filters' '
+       echo "*.bin diff=test" >.gitattributes &&
+       git config diff.test.textconv ./helper &&
+       git config diff.test.cachetextconv false
+'
+
+test_expect_success 'blame with --no-textconv' '
+       git blame --no-textconv one.bin >blame &&
+       find_blame <blame> result &&
+       test_cmp expected result
+'
+
+cat >expected <<EOF
+(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
+EOF
+
+test_expect_success 'basic blame on last commit' '
+       git blame one.bin >blame &&
+       find_blame  <blame >result &&
+       test_cmp expected result
+'
+
+cat >expected <<EOF
+(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
+(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
+EOF
+
+test_expect_success 'blame --textconv going through revisions' '
+       git blame --textconv two.bin >blame &&
+       find_blame <blame >result &&
+       test_cmp expected result
+'
+
+test_expect_success 'make a new commit' '
+       echo "test number 2 version 3" >>two.bin &&
+       GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00"
+'
+
+test_expect_success 'blame from previous revision' '
+       git blame HEAD^ two.bin >blame &&
+       find_blame <blame >result &&
+       test_cmp expected result
+'
+
+test_done
diff --git a/t/t8007-cat-file-textconv.sh b/t/t8007-cat-file-textconv.sh
new file mode 100755 (executable)
index 0000000..38ac05e
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+test_description='git cat-file textconv support'
+. ./test-lib.sh
+
+cat >helper <<'EOF'
+#!/bin/sh
+sed 's/^/converted: /' "$@"
+EOF
+chmod +x helper
+
+test_expect_success 'setup ' '
+       echo test >one.bin &&
+       git add . &&
+       GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
+       echo test version 2 >one.bin &&
+       GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
+'
+
+cat >expected <<EOF
+fatal: git cat-file --textconv: unable to run textconv on :one.bin
+EOF
+
+test_expect_success 'no filter specified' '
+       git cat-file --textconv :one.bin 2>result
+       test_cmp expected result
+'
+
+test_expect_success 'setup textconv filters' '
+       echo "*.bin diff=test" >.gitattributes &&
+       git config diff.test.textconv ./helper &&
+       git config diff.test.cachetextconv false
+'
+
+cat >expected <<EOF
+test version 2
+EOF
+
+test_expect_success 'cat-file without --textconv' '
+       git cat-file blob :one.bin >result &&
+       test_cmp expected result
+'
+
+cat >expected <<EOF
+test
+EOF
+
+test_expect_success 'cat-file without --textconv on previous commit' '
+       git cat-file -p HEAD^:one.bin >result &&
+       test_cmp expected result
+'
+
+cat >expected <<EOF
+converted: test version 2
+EOF
+
+test_expect_success 'cat-file --textconv on last commit' '
+       git cat-file --textconv :one.bin >result &&
+       test_cmp expected result
+'
+
+cat >expected <<EOF
+converted: test
+EOF
+
+test_expect_success 'cat-file --textconv on previous commit' '
+       git cat-file --textconv HEAD^:one.bin >result &&
+       test_cmp expected result
+'
+test_done
index 382ab6c98a932925db838b29d452b36cfea0dba5..23597cc40751addd1473acd2edf7563e0a517c9e 100755 (executable)
@@ -4,7 +4,7 @@ test_description='git send-email'
 . ./test-lib.sh
 
 if ! test_have_prereq PERL; then
-       say 'skipping git send-email tests, perl not available'
+       skip_all='skipping git send-email tests, perl not available'
        test_done
 fi
 
@@ -58,7 +58,7 @@ test_no_confirm () {
 # Exit immediately to prevent hang if a no-confirm test fails
 check_no_confirm () {
        test -f no_confirm_okay || {
-               say 'No confirm test failed; skipping remaining tests to prevent hanging'
+               skip_all='confirm test failed; skipping remaining tests to prevent hanging'
                test_done
        }
 }
index 570e0359e4739e178b1836887c53ddd78e3c8ec0..13766ab160e48d2b2ecb6e95079077e4a0704c2c 100755 (executable)
@@ -15,7 +15,7 @@ case "$GIT_SVN_LC_ALL" in
        test_set_prereq UTF8
        ;;
 *)
-       say "UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)"
+       say "UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)"
        ;;
 esac
 
index ac52bff0ef540bce48e4ee02a53adbbec3662939..63fc982c8cdbd9c19eb06bba58ad5e86da5dd03e 100755 (executable)
@@ -21,34 +21,59 @@ test_expect_success 'setup svnrepo' '
                              "$svnrepo/pr ject/branches/more fun plugin!" &&
        svn_cmd cp -m "scary" "$svnrepo/pr ject/branches/fun plugin" \
                      "$svnrepo/pr ject/branches/$scary_uri" &&
+       svn_cmd cp -m "leading dot" "$svnrepo/pr ject/trunk" \
+                       "$svnrepo/pr ject/branches/.leading_dot" &&
+       svn_cmd cp -m "trailing dot" "$svnrepo/pr ject/trunk" \
+                       "$svnrepo/pr ject/branches/trailing_dot." &&
+       svn_cmd cp -m "trailing .lock" "$svnrepo/pr ject/trunk" \
+                       "$svnrepo/pr ject/branches/trailing_dotlock.lock" &&
+       svn_cmd cp -m "reflog" "$svnrepo/pr ject/trunk" \
+                       "$svnrepo/pr ject/branches/not-a%40{0}reflog" &&
        start_httpd
        '
 
 test_expect_success 'test clone with funky branch names' '
        git svn clone -s "$svnrepo/pr ject" project &&
-       cd project &&
+       (
+               cd project &&
                git rev-parse "refs/remotes/fun%20plugin" &&
                git rev-parse "refs/remotes/more%20fun%20plugin!" &&
                git rev-parse "refs/remotes/$scary_ref" &&
-       cd ..
+               git rev-parse "refs/remotes/%2Eleading_dot" &&
+               git rev-parse "refs/remotes/trailing_dot%2E" &&
+               git rev-parse "refs/remotes/trailing_dotlock%2Elock" &&
+               git rev-parse "refs/remotes/not-a%40{0}reflog"
+       )
        '
 
 test_expect_success 'test dcommit to funky branch' "
-       cd project &&
-       git reset --hard 'refs/remotes/more%20fun%20plugin!' &&
-       echo hello >> foo &&
-       git commit -m 'hello' -- foo &&
-       git svn dcommit &&
-       cd ..
+       (
+               cd project &&
+               git reset --hard 'refs/remotes/more%20fun%20plugin!' &&
+               echo hello >> foo &&
+               git commit -m 'hello' -- foo &&
+               git svn dcommit
+       )
        "
 
 test_expect_success 'test dcommit to scary branch' '
-       cd project &&
-       git reset --hard "refs/remotes/$scary_ref" &&
-       echo urls are scary >> foo &&
-       git commit -m "eep" -- foo &&
-       git svn dcommit &&
-       cd ..
+       (
+               cd project &&
+               git reset --hard "refs/remotes/$scary_ref" &&
+               echo urls are scary >> foo &&
+               git commit -m "eep" -- foo &&
+               git svn dcommit
+       )
+       '
+
+test_expect_success 'test dcommit to trailing_dotlock branch' '
+       (
+               cd project &&
+               git reset --hard "refs/remotes/trailing_dotlock%2Elock" &&
+               echo who names branches like this anyway? >> foo &&
+               git commit -m "bar" -- foo &&
+               git svn dcommit
+       )
        '
 
 stop_httpd
index a9a558d292231bd4b372552df0364c63ece25299..5fb94fb3d61c2e26dcd448ac5106ec0f9a3a2283 100755 (executable)
@@ -13,7 +13,7 @@ case $v in
 1.[456].*)
        ;;
 *)
-       say "skipping svn-info test (SVN version: $v not supported)"
+       skip_all="skipping svn-info test (SVN version: $v not supported)"
        test_done
        ;;
 esac
index 1e9a2eb12bee55474f9bc10a7e31f5c01d6403f8..8cfdfe790f1e0bb7cd0ddb72a72a55073368ec60 100755 (executable)
@@ -23,7 +23,7 @@ if test -n "$a_utf8_locale"
 then
        test_set_prereq UTF8
 else
-       say "UTF-8 locale not available, some tests are skipped"
+       say "UTF-8 locale not available, some tests are skipped"
 fi
 
 compare_svn_head_with () {
index 99f69c6a0b8c7d3eea5211db333d0be41f9f5fa4..337ea59711ac7aca78a27afb92693f88e98aed9d 100755 (executable)
@@ -43,7 +43,7 @@ then
                 gunzip .git/svn/refs/remotes/git-svn/unhandled.log.gz
                '
 else
-       say "Perl Compress::Zlib unavailable, skipping gunzip test"
+       say "Perl Compress::Zlib unavailable, skipping gunzip test"
 fi
 
 test_expect_success 'git svn gc does not change unhandled.log files' '
index fc3795dc98803bd98e2ebd6f38a249c331038d54..ee39b36d78a9d5602be5d48ae34b1e5ce4927c79 100755 (executable)
@@ -7,14 +7,14 @@ test_description='Test export of commits to CVS'
 . ./test-lib.sh
 
 if ! test_have_prereq PERL; then
-       say 'skipping git cvsexportcommit tests, perl not available'
+       skip_all='skipping git cvsexportcommit tests, perl not available'
        test_done
 fi
 
 cvs >/dev/null 2>&1
 if test $? -ne 1
 then
-    say 'skipping git cvsexportcommit tests, cvs not found'
+    skip_all='skipping git cvsexportcommit tests, cvs not found'
     test_done
 fi
 
@@ -63,10 +63,10 @@ test_expect_success \
      check_entries B "newfile2.txt/1.1/" &&
      check_entries C "newfile3.png/1.1/-kb" &&
      check_entries D "newfile4.png/1.1/-kb" &&
-     diff A/newfile1.txt ../A/newfile1.txt &&
-     diff B/newfile2.txt ../B/newfile2.txt &&
-     diff C/newfile3.png ../C/newfile3.png &&
-     diff D/newfile4.png ../D/newfile4.png
+     test_cmp A/newfile1.txt ../A/newfile1.txt &&
+     test_cmp B/newfile2.txt ../B/newfile2.txt &&
+     test_cmp C/newfile3.png ../C/newfile3.png &&
+     test_cmp D/newfile4.png ../D/newfile4.png
      )'
 
 test_expect_success \
@@ -89,10 +89,10 @@ test_expect_success \
      check_entries D "newfile4.png/1.2/-kb" &&
      check_entries E "newfile5.txt/1.1/" &&
      check_entries F "newfile6.png/1.1/-kb" &&
-     diff A/newfile1.txt ../A/newfile1.txt &&
-     diff D/newfile4.png ../D/newfile4.png &&
-     diff E/newfile5.txt ../E/newfile5.txt &&
-     diff F/newfile6.png ../F/newfile6.png
+     test_cmp A/newfile1.txt ../A/newfile1.txt &&
+     test_cmp D/newfile4.png ../D/newfile4.png &&
+     test_cmp E/newfile5.txt ../E/newfile5.txt &&
+     test_cmp F/newfile6.png ../F/newfile6.png
      )'
 
 # Should fail (but only on the git cvsexportcommit stage)
@@ -137,9 +137,9 @@ test_expect_success \
      check_entries D "" &&
      check_entries E "newfile5.txt/1.1/" &&
      check_entries F "newfile6.png/1.1/-kb" &&
-     diff A/newfile1.txt ../A/newfile1.txt &&
-     diff E/newfile5.txt ../E/newfile5.txt &&
-     diff F/newfile6.png ../F/newfile6.png
+     test_cmp A/newfile1.txt ../A/newfile1.txt &&
+     test_cmp E/newfile5.txt ../E/newfile5.txt &&
+     test_cmp F/newfile6.png ../F/newfile6.png
      )'
 
 test_expect_success \
@@ -155,8 +155,8 @@ test_expect_success \
      check_entries D "" &&
      check_entries E "newfile5.txt/1.1/" &&
      check_entries F "newfile6.png/1.1/-kb" &&
-     diff E/newfile5.txt ../E/newfile5.txt &&
-     diff F/newfile6.png ../F/newfile6.png
+     test_cmp E/newfile5.txt ../E/newfile5.txt &&
+     test_cmp F/newfile6.png ../F/newfile6.png
      )'
 
 test_expect_success \
index 131f03298809ad193cc75ab77deda6daaf713d1f..2aeed7bd0601a0587f99250377001be6287772e5 100755 (executable)
@@ -166,6 +166,63 @@ test_expect_success \
         test `git rev-parse --verify master:file2` \
            = `git rev-parse --verify verify--import-marks:copy-of-file2`'
 
+test_tick
+mt=$(git hash-object --stdin < /dev/null)
+: >input.blob
+: >marks.exp
+: >tree.exp
+
+cat >input.commit <<EOF
+commit refs/heads/verify--dump-marks
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+test the sparse array dumping routines with exponentially growing marks
+COMMIT
+EOF
+
+i=0
+l=4
+m=6
+n=7
+while test "$i" -lt 27; do
+    cat >>input.blob <<EOF
+blob
+mark :$l
+data 0
+blob
+mark :$m
+data 0
+blob
+mark :$n
+data 0
+EOF
+    echo "M 100644 :$l l$i" >>input.commit
+    echo "M 100644 :$m m$i" >>input.commit
+    echo "M 100644 :$n n$i" >>input.commit
+
+    echo ":$l $mt" >>marks.exp
+    echo ":$m $mt" >>marks.exp
+    echo ":$n $mt" >>marks.exp
+
+    printf "100644 blob $mt\tl$i\n" >>tree.exp
+    printf "100644 blob $mt\tm$i\n" >>tree.exp
+    printf "100644 blob $mt\tn$i\n" >>tree.exp
+
+    l=$(($l + $l))
+    m=$(($m + $m))
+    n=$(($l + $n))
+
+    i=$((1 + $i))
+done
+
+sort tree.exp > tree.exp_s
+
+test_expect_success 'A: export marks with large values' '
+       cat input.blob input.commit | git fast-import --export-marks=marks.large &&
+       git ls-tree refs/heads/verify--dump-marks >tree.out &&
+       test_cmp tree.exp_s tree.out &&
+       test_cmp marks.exp marks.large'
+
 ###
 ### series B
 ###
index daef2d6c230fb617395feeff6cf330b74ad57832..36c457e7f2312774223f853aab0e3b055659e916 100755 (executable)
@@ -11,17 +11,17 @@ cvs CLI client via git-cvsserver server'
 . ./test-lib.sh
 
 if ! test_have_prereq PERL; then
-       say 'skipping git cvsserver tests, perl not available'
+       skip_all='skipping git cvsserver tests, perl not available'
        test_done
 fi
 cvs >/dev/null 2>&1
 if test $? -ne 1
 then
-    say 'skipping git-cvsserver tests, cvs not found'
+    skip_all='skipping git-cvsserver tests, cvs not found'
     test_done
 fi
 "$PERL_PATH" -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
-    say 'skipping git-cvsserver tests, Perl SQLite interface unavailable'
+    skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable'
     test_done
 }
 
@@ -48,7 +48,9 @@ test_expect_success 'setup' '
   git pull secondroot master &&
   git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
   GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
-  GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
+  GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" &&
+  GIT_DIR="$SERVERDIR" git config gitcvs.authdb "$SERVERDIR/auth.db" &&
+  echo cvsuser:cvGVEarMLnhlA > "$SERVERDIR/auth.db"
 '
 
 # note that cvs doesn't accept absolute pathnames
@@ -94,6 +96,14 @@ git
 END VERIFICATION REQUEST
 EOF
 
+cat >login-git-ok <<EOF
+BEGIN VERIFICATION REQUEST
+$SERVERDIR
+cvsuser
+Ah<Z:yZZ30 e
+END VERIFICATION REQUEST
+EOF
+
 test_expect_success 'pserver authentication' \
   'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
    sed -ne \$p log | grep "^I LOVE YOU\$"'
@@ -107,6 +117,10 @@ test_expect_success 'pserver authentication failure (non-anonymous user)' \
    fi &&
    sed -ne \$p log | grep "^I HATE YOU\$"'
 
+test_expect_success 'pserver authentication success (non-anonymous user with password)' \
+  'cat login-git-ok | git-cvsserver pserver >log 2>&1 &&
+   sed -ne \$p log | grep "^I LOVE YOU\$"'
+
 test_expect_success 'pserver authentication (login)' \
   'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
    sed -ne \$p log | grep "^I LOVE YOU\$"'
@@ -435,7 +449,7 @@ test_expect_success 'cvs update (-p)' '
     rm -f failures &&
     for i in merge no-lf empty really-empty; do
         GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out
-        diff $i.out ../$i >>failures 2>&1
+       test_cmp $i.out ../$i >>failures 2>&1
     done &&
     test -z "$(cat failures)"
 '
index ed7b513f3e82706f6455bb32f4f19a5161bb0415..925bd0fbedf9865cef834460969c0a9fd2262437 100755 (executable)
@@ -41,16 +41,16 @@ not_present() {
 cvs >/dev/null 2>&1
 if test $? -ne 1
 then
-    say 'skipping git-cvsserver tests, cvs not found'
+    skip_all='skipping git-cvsserver tests, cvs not found'
     test_done
 fi
 if ! test_have_prereq PERL
 then
-    say 'skipping git-cvsserver tests, perl not available'
+    skip_all='skipping git-cvsserver tests, perl not available'
     test_done
 fi
 "$PERL_PATH" -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
-    say 'skipping git-cvsserver tests, Perl SQLite interface unavailable'
+    skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable'
     test_done
 }
 
index 63b6b060e64948771319294251838394264c84a9..4f2b9b062b08302aedab42dcdd0a33776559c05e 100755 (executable)
@@ -647,4 +647,33 @@ test_expect_success \
         gitweb_run "p=.git;a=summary"'
 test_debug 'cat gitweb.log'
 
+# ----------------------------------------------------------------------
+# syntax highlighting
+
+cat >>gitweb_config.perl <<\EOF
+$feature{'highlight'}{'override'} = 1;
+EOF
+
+highlight --version >/dev/null 2>&1
+if [ $? -eq 127 ]; then
+       say "Skipping syntax highlighting test, because 'highlight' was not found"
+else
+       test_set_prereq HIGHLIGHT
+fi
+
+test_expect_success HIGHLIGHT \
+       'syntax highlighting (no highlight)' \
+       'git config gitweb.highlight yes &&
+        gitweb_run "p=.git;a=blob;f=file"'
+test_debug 'cat gitweb.log'
+
+test_expect_success HIGHLIGHT \
+       'syntax highlighting (highlighted)' \
+       'git config gitweb.highlight yes &&
+        echo "#!/usr/bin/sh" > test.sh &&
+        git add test.sh &&
+        git commit -m "Add test.sh" &&
+        gitweb_run "p=.git;a=blob;f=test.sh"'
+test_debug 'cat gitweb.log'
+
 test_done
index b572ce3ab7f55e1258aa92b37e10a0d067c9d01d..2eff9cd68ce2f51618159df402bfb46382d44434 100755 (executable)
@@ -4,7 +4,7 @@ test_description='git cvsimport basic tests'
 . ./lib-cvs.sh
 
 if ! test_have_prereq PERL; then
-       say 'skipping git cvsimport tests, perl not available'
+       skip_all='skipping git cvsimport tests, perl not available'
        test_done
 fi
 
index 8686086dde9dba742bd805c31f3e28c658b03a9b..3787186703f51f75103824f562c3849483ceaae1 100755 (executable)
@@ -7,12 +7,12 @@ test_description='perl interface (Git.pm)'
 . ./test-lib.sh
 
 if ! test_have_prereq PERL; then
-       say 'skipping perl interface tests, perl not available'
+       skip_all='skipping perl interface tests, perl not available'
        test_done
 fi
 
 "$PERL_PATH" -MTest::More -e 0 2>/dev/null || {
-       say "Perl Test::More unavailable, skipping test"
+       skip_all="Perl Test::More unavailable, skipping test"
        test_done
 }
 
@@ -46,6 +46,9 @@ test_expect_success \
      git config --add test.int 2k
      '
 
+# The external test will outputs its own plan
+test_external_has_tap=1
+
 test_external_without_stderr \
     'Perl API' \
     "$PERL_PATH" "$TEST_DIRECTORY"/t9700/test.pl
index 666722d9bf1050522a687f4af95792a8e0ec5d64..671f38db2bb78c076b281602ca5b87f10fdf4d00 100755 (executable)
@@ -7,6 +7,13 @@ use strict;
 
 use Test::More qw(no_plan);
 
+BEGIN {
+       # t9700-perl-git.sh kicks off our testing, so we have to go from
+       # there.
+       Test::More->builder->current_test(1);
+       Test::More->builder->no_ending(1);
+}
+
 use Cwd;
 use File::Basename;
 
@@ -105,3 +112,8 @@ my $last_commit = $r2->command_oneline(qw(rev-parse --verify HEAD));
 like($last_commit, qr/^[0-9a-fA-F]{40}$/, 'rev-parse returned hash');
 my $dir_commit = $r2->command_oneline('log', '-n1', '--pretty=format:%H', '.');
 isnt($last_commit, $dir_commit, 'log . does not show last commit');
+
+printf "1..%d\n", Test::More->builder->current_test;
+
+my $is_passing = eval { Test::More->is_passing };
+exit($is_passing ? 0 : 1) unless $@ =~ /Can't locate object method/;
index 9bfa14be7f1c3935013d04318eeaecc68b4ef88c..29fd7209cf1aff851f0f1f95ccecd0d949b3da6c 100644 (file)
@@ -75,7 +75,6 @@ export GIT_MERGE_VERBOSITY
 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
 export EDITOR
-GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
 
 # Protect ourselves from common misconfiguration to export
 # CDPATH into the environment
@@ -128,14 +127,13 @@ do
        -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
                verbose=t; shift ;;
        -q|--q|--qu|--qui|--quie|--quiet)
-               quiet=t; shift ;;
+               # Ignore --quiet under a TAP::Harness. Saying how many tests
+               # passed without the ok/not ok details is always an error.
+               test -z "$HARNESS_ACTIVE" && quiet=t; shift ;;
        --with-dashes)
                with_dashes=t; shift ;;
        --no-color)
                color=; shift ;;
-       --no-python)
-               # noop now...
-               shift ;;
        --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
                valgrind=t; verbose=t; shift ;;
        --tee)
@@ -161,7 +159,7 @@ if test -n "$color"; then
                        *) test -n "$quiet" && return;;
                esac
                shift
-               printf "%s" "$*"
+               printf "%s" "$*"
                tput sgr0
                echo
                )
@@ -170,7 +168,7 @@ else
        say_color() {
                test -z "$1" && test -n "$quiet" && return
                shift
-               echo "$*"
+               echo "$*"
        }
 fi
 
@@ -207,6 +205,8 @@ test_fixed=0
 test_broken=0
 test_success=0
 
+test_external_has_tap=0
+
 die () {
        code=$?
        if test -n "$GIT_EXIT_OK"
@@ -256,6 +256,10 @@ q_to_cr () {
        tr Q '\015'
 }
 
+q_to_tab () {
+       tr Q '\011'
+}
+
 append_cr () {
        sed -e 's/$/Q/' | tr Q '\015'
 }
@@ -340,25 +344,25 @@ test_have_prereq () {
 
 test_ok_ () {
        test_success=$(($test_success + 1))
-       say_color "" "  ok $test_count: $@"
+       say_color "" "ok $test_count - $@"
 }
 
 test_failure_ () {
        test_failure=$(($test_failure + 1))
-       say_color error "FAIL $test_count: $1"
+       say_color error "not ok - $test_count $1"
        shift
-       echo "$@" | sed -e 's/^/        /'
+       echo "$@" | sed -e 's/^/#       /'
        test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
 }
 
 test_known_broken_ok_ () {
        test_fixed=$(($test_fixed+1))
-       say_color "" "  FIXED $test_count: $@"
+       say_color "" "ok $test_count - $@ # TODO known breakage"
 }
 
 test_known_broken_failure_ () {
        test_broken=$(($test_broken+1))
-       say_color skip "  still broken $test_count: $@"
+       say_color skip "not ok $test_count - $@ # TODO known breakage"
 }
 
 test_debug () {
@@ -370,6 +374,9 @@ test_run_ () {
        eval >&3 2>&4 "$1"
        eval_ret=$?
        eval >&3 2>&4 "$test_cleanup"
+       if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"; then
+               echo ""
+       fi
        return 0
 }
 
@@ -381,6 +388,7 @@ test_skip () {
                case $this_test.$test_count in
                $skp)
                        to_skip=t
+                       break
                esac
        done
        if test -z "$to_skip" && test -n "$prereq" &&
@@ -391,7 +399,7 @@ test_skip () {
        case "$to_skip" in
        t)
                say_color skip >&3 "skipping test: $@"
-               say_color skip "skip $test_count: $1"
+               say_color skip "ok $test_count # skip $1"
                : true
                ;;
        *)
@@ -457,7 +465,7 @@ test_expect_code () {
 # test_external runs external test scripts that provide continuous
 # test output about their progress, and succeeds/fails on
 # zero/non-zero exit code.  It outputs the test output on stdout even
-# in non-verbose mode, and announces the external script with "* run
+# in non-verbose mode, and announces the external script with "# run
 # <n>: ..." before running it.  When providing relative paths, keep in
 # mind that all scripts run in "trash directory".
 # Usage: test_external description command arguments...
@@ -472,16 +480,29 @@ test_external () {
        then
                # Announce the script to reduce confusion about the
                # test output that follows.
-               say_color "" " run $test_count: $descr ($*)"
+               say_color "" "# run $test_count: $descr ($*)"
+               # Export TEST_DIRECTORY, TRASH_DIRECTORY and GIT_TEST_LONG
+               # to be able to use them in script
+               export TEST_DIRECTORY TRASH_DIRECTORY GIT_TEST_LONG
                # Run command; redirect its stderr to &4 as in
                # test_run_, but keep its stdout on our stdout even in
                # non-verbose mode.
                "$@" 2>&4
                if [ "$?" = 0 ]
                then
-                       test_ok_ "$descr"
+                       if test $test_external_has_tap -eq 0; then
+                               test_ok_ "$descr"
+                       else
+                               say_color "" "# test_external test $descr was ok"
+                               test_success=$(($test_success + 1))
+                       fi
                else
-                       test_failure_ "$descr" "$@"
+                       if test $test_external_has_tap -eq 0; then
+                               test_failure_ "$descr" "$@"
+                       else
+                               say_color error "# test_external test $descr failed: $@"
+                               test_failure=$(($test_failure + 1))
+                       fi
                fi
        fi
 }
@@ -497,19 +518,30 @@ test_external_without_stderr () {
        [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
        descr="no stderr: $1"
        shift
-       say >&3 "expecting no stderr from previous command"
+       say >&3 "expecting no stderr from previous command"
        if [ ! -s "$stderr" ]; then
                rm "$stderr"
-               test_ok_ "$descr"
+
+               if test $test_external_has_tap -eq 0; then
+                       test_ok_ "$descr"
+               else
+                       say_color "" "# test_external_without_stderr test $descr was ok"
+                       test_success=$(($test_success + 1))
+               fi
        else
                if [ "$verbose" = t ]; then
-                       output=`echo; echo Stderr is:; cat "$stderr"`
+                       output=`echo; echo "# Stderr is:"; cat "$stderr"`
                else
                        output=
                fi
                # rm first in case test_failure exits.
                rm "$stderr"
-               test_failure_ "$descr" "$@" "$output"
+               if test $test_external_has_tap -eq 0; then
+                       test_failure_ "$descr" "$@" "$output"
+               else
+                       say_color error "# test_external_without_stderr test $descr failed: $@: $output"
+                       test_failure=$(($test_failure + 1))
+               fi
        fi
 }
 
@@ -607,7 +639,7 @@ test_done () {
        GIT_EXIT_OK=t
        test_results_dir="$TEST_DIRECTORY/test-results"
        mkdir -p "$test_results_dir"
-       test_results_path="$test_results_dir/${0%.sh}-$$"
+       test_results_path="$test_results_dir/${0%.sh}-$$.counts"
 
        echo "total $test_count" >> $test_results_path
        echo "success $test_success" >> $test_results_path
@@ -618,18 +650,24 @@ test_done () {
 
        if test "$test_fixed" != 0
        then
-               say_color pass "fixed $test_fixed known breakage(s)"
+               say_color pass "fixed $test_fixed known breakage(s)"
        fi
        if test "$test_broken" != 0
        then
-               say_color error "still have $test_broken known breakage(s)"
+               say_color error "still have $test_broken known breakage(s)"
                msg="remaining $(($test_count-$test_broken)) test(s)"
        else
                msg="$test_count test(s)"
        fi
        case "$test_failure" in
        0)
-               say_color pass "passed all $msg"
+               # Maybe print SKIP message
+               [ -z "$skip_all" ] || skip_all=" # SKIP $skip_all"
+
+               if test $test_external_has_tap -eq 0; then
+                       say_color pass "# passed all $msg"
+                       say "1..$test_count$skip_all"
+               fi
 
                test -d "$remove_trash" &&
                cd "$(dirname "$remove_trash")" &&
@@ -638,7 +676,11 @@ test_done () {
                exit 0 ;;
 
        *)
-               say_color error "failed $test_failure among $msg"
+               if test $test_external_has_tap -eq 0; then
+                       say_color error "# failed $test_failure among $msg"
+                       say "1..$test_count"
+               fi
+
                exit 1 ;;
 
        esac
@@ -737,6 +779,16 @@ export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOB
 
 . ../GIT-BUILD-OPTIONS
 
+if test -z "$GIT_TEST_CMP"
+then
+       if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"
+       then
+               GIT_TEST_CMP="$DIFF -c"
+       else
+               GIT_TEST_CMP="$DIFF -u"
+       fi
+fi
+
 GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git
 export GITPERLLIB
 test -d ../templates/blt || {
@@ -781,18 +833,10 @@ this_test=${0##*/}
 this_test=${this_test%%-*}
 for skp in $GIT_SKIP_TESTS
 do
-       to_skip=
-       for skp in $GIT_SKIP_TESTS
-       do
-               case "$this_test" in
-               $skp)
-                       to_skip=t
-               esac
-       done
-       case "$to_skip" in
-       t)
+       case "$this_test" in
+       $skp)
                say_color skip >&3 "skipping test $this_test altogether"
-               say_color skip "skip all tests in $this_test"
+               skip_all="skip all tests in $this_test"
                test_done
        esac
 done
diff --git a/tag.c b/tag.c
index 85607c219e25d63b0d1f3344649104c60f5b96e2..28641cf85a0d32357269129f0e8b92bb9e21f399 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -28,12 +28,12 @@ struct tag *lookup_tag(const unsigned char *sha1)
                return create_object(sha1, OBJ_TAG, alloc_tag_node());
        if (!obj->type)
                obj->type = OBJ_TAG;
-        if (obj->type != OBJ_TAG) {
-                error("Object %s is a %s, not a tag",
-                      sha1_to_hex(sha1), typename(obj->type));
-                return NULL;
-        }
-        return (struct tag *) obj;
+       if (obj->type != OBJ_TAG) {
+               error("Object %s is a %s, not a tag",
+                     sha1_to_hex(sha1), typename(obj->type));
+               return NULL;
+       }
+       return (struct tag *) obj;
 }
 
 static unsigned long parse_tag_date(const char *buf, const char *tail)
diff --git a/trace.c b/trace.c
index 4229ae1231d69aedd9f1aa8350989ddbe2bdb845..1e560cb0b977e19beeb095497c8e4f6280b7f0d6 100644 (file)
--- a/trace.c
+++ b/trace.c
 #include "cache.h"
 #include "quote.h"
 
+void do_nothing(size_t unused)
+{
+}
+
 /* Get a trace file descriptor from GIT_TRACE env variable. */
 static int get_trace_fd(int *need_close)
 {
@@ -72,6 +76,7 @@ void trace_printf(const char *fmt, ...)
        if (!fd)
                return;
 
+       set_try_to_free_routine(do_nothing);    /* is never reset */
        strbuf_init(&buf, 64);
        va_start(ap, fmt);
        len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);
@@ -103,6 +108,7 @@ void trace_argv_printf(const char **argv, const char *fmt, ...)
        if (!fd)
                return;
 
+       set_try_to_free_routine(do_nothing);    /* is never reset */
        strbuf_init(&buf, 64);
        va_start(ap, fmt);
        len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);
index 2638781c5b89024294f3c4c32861b275e339ad1d..191fbf798a5e5db1abeafc719e8ec0d986a1050c 100644 (file)
@@ -7,6 +7,7 @@
 #include "revision.h"
 #include "quote.h"
 #include "remote.h"
+#include "string-list.h"
 
 static int debug;
 
@@ -17,6 +18,7 @@ struct helper_data
        FILE *out;
        unsigned fetch : 1,
                import : 1,
+               export : 1,
                option : 1,
                push : 1,
                connect : 1,
@@ -163,6 +165,8 @@ static struct child_process *get_helper(struct transport *transport)
                        data->push = 1;
                else if (!strcmp(capname, "import"))
                        data->import = 1;
+               else if (!strcmp(capname, "export"))
+                       data->export = 1;
                else if (!data->refspecs && !prefixcmp(capname, "refspec ")) {
                        ALLOC_GROW(refspecs,
                                   refspec_nr + 1,
@@ -170,6 +174,11 @@ static struct child_process *get_helper(struct transport *transport)
                        refspecs[refspec_nr++] = strdup(buf.buf + 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 (mandatory) {
                        die("Unknown mandatory capability %s. This remote "
                            "helper probably needs newer version of Git.\n",
@@ -351,6 +360,33 @@ static int get_importer(struct transport *transport, struct child_process *fasti
        return start_command(fastimport);
 }
 
+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 child_process *helper = get_helper(transport);
+       int argc = 0, i;
+       memset(fastexport, 0, sizeof(*fastexport));
+
+       /* 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[argc++] = "fast-export";
+       if (export_marks)
+               fastexport->argv[argc++] = export_marks;
+       if (import_marks)
+               fastexport->argv[argc++] = import_marks;
+
+       for (i = 0; i < revlist_args->nr; i++)
+               fastexport->argv[argc++] = revlist_args->items[i].string;
+
+       fastexport->git_cmd = 1;
+       return start_command(fastexport);
+}
+
 static int fetch_with_import(struct transport *transport,
                             int nr_heads, struct ref **to_fetch)
 {
@@ -518,7 +554,7 @@ static int fetch(struct transport *transport,
        return -1;
 }
 
-static int push_refs(struct transport *transport,
+static int push_refs_with_push(struct transport *transport,
                struct ref *remote_refs, int flags)
 {
        int force_all = flags & TRANSPORT_PUSH_FORCE;
@@ -528,17 +564,6 @@ static int push_refs(struct transport *transport,
        struct child_process *helper;
        struct ref *ref;
 
-       if (process_connect(transport, 1)) {
-               do_take_over(transport);
-               return transport->push_refs(transport, remote_refs, flags);
-       }
-
-       if (!remote_refs) {
-               fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
-                       "Perhaps you should specify a branch such as 'master'.\n");
-               return 0;
-       }
-
        helper = get_helper(transport);
        if (!data->push)
                return 1;
@@ -657,6 +682,94 @@ static int push_refs(struct transport *transport,
        return 0;
 }
 
+static int push_refs_with_export(struct transport *transport,
+               struct ref *remote_refs, int flags)
+{
+       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 = { NULL, 0, 0 };
+       struct strbuf buf = STRBUF_INIT;
+
+       helper = get_helper(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) {
+               char *private;
+               unsigned char sha1[20];
+
+               if (!data->refspecs)
+                       continue;
+               private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
+               if (private && !get_sha1(private, sha1)) {
+                       strbuf_addf(&buf, "^%s", private);
+                       string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
+               }
+
+               string_list_append(&revlist_args, ref->name);
+
+       }
+
+       if (get_exporter(transport, &exporter,
+                        export_marks, import_marks, &revlist_args))
+               die("Couldn't run fast-export");
+
+       data->no_disconnect_req = 1;
+       finish_command(&exporter);
+       disconnect_helper(transport);
+       return 0;
+}
+
+static int push_refs(struct transport *transport,
+               struct ref *remote_refs, int flags)
+{
+       struct helper_data *data = transport->data;
+
+       if (process_connect(transport, 1)) {
+               do_take_over(transport);
+               return transport->push_refs(transport, remote_refs, flags);
+       }
+
+       if (!remote_refs) {
+               fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
+                       "Perhaps you should specify a branch such as 'master'.\n");
+               return 0;
+       }
+
+       if (data->push)
+               return push_refs_with_push(transport, remote_refs, flags);
+
+       if (data->export)
+               return push_refs_with_export(transport, remote_refs, flags);
+
+       return -1;
+}
+
+
 static int has_attribute(const char *attrs, const char *attr) {
        int len;
        if (!attrs)
index 8ce39364a1e58b338bc45a4eb524b637ce3a8881..4dba6f8815a80093a8ac9edc226d99bba1bb6394 100644 (file)
@@ -9,6 +9,7 @@
 #include "dir.h"
 #include "refs.h"
 #include "branch.h"
+#include "url.h"
 
 /* rsync support */
 
@@ -871,54 +872,6 @@ static int is_file(const char *url)
        return S_ISREG(buf.st_mode);
 }
 
-static int isurlschemechar(int first_flag, int ch)
-{
-       /*
-        * The set of valid URL schemes, as per STD66 (RFC3986) is
-        * '[A-Za-z][A-Za-z0-9+.-]*'. But use sightly looser check
-        * of '[A-Za-z0-9][A-Za-z0-9+.-]*' because earlier version
-        * of check used '[A-Za-z0-9]+' so not to break any remote
-        * helpers.
-        */
-       int alphanumeric, special;
-       alphanumeric = ch > 0 && isalnum(ch);
-       special = ch == '+' || ch == '-' || ch == '.';
-       return alphanumeric || (!first_flag && special);
-}
-
-static int is_url(const char *url)
-{
-       const char *url2, *first_slash;
-
-       if (!url)
-               return 0;
-       url2 = url;
-       first_slash = strchr(url, '/');
-
-       /* Input with no slash at all or slash first can't be URL. */
-       if (!first_slash || first_slash == url)
-               return 0;
-       /* Character before must be : and next must be /. */
-       if (first_slash[-1] != ':' || first_slash[1] != '/')
-               return 0;
-       /* There must be something before the :// */
-       if (first_slash == url + 1)
-               return 0;
-       /*
-        * Check all characters up to first slash - 1. Only alphanum
-        * is allowed.
-        */
-       url2 = url;
-       while (url2 < first_slash - 1) {
-               if (!isurlschemechar(url2 == url, (unsigned char)*url2))
-                       return 0;
-               url2++;
-       }
-
-       /* Valid enough. */
-       return 1;
-}
-
 static int external_specification_len(const char *url)
 {
        return strchr(url, ':') - url;
@@ -946,7 +899,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
        if (url) {
                const char *p = url;
 
-               while (isurlschemechar(p == url, *p))
+               while (is_urlschemechar(p == url, *p))
                        p++;
                if (!prefixcmp(p, "::"))
                        helper = xstrndup(url, p - url);
index fe9f52c4796512f40869e511b55a2d97fa84532e..cd659c6fe447b6fcdedee2843113feb358f23849 100644 (file)
@@ -346,7 +346,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
 
        diff_setup(&diff_opts);
        DIFF_OPT_SET(&diff_opts, RECURSIVE);
-       diff_opts.detect_rename = DIFF_DETECT_RENAME;
+       DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
        diff_opts.single_follow = opt->paths[0];
        diff_opts.break_opt = opt->break_opt;
@@ -359,6 +359,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
        diff_tree_release_paths(&diff_opts);
 
        /* Go through the new set of filepairing, and see if we find a more interesting one */
+       opt->found_follow = 0;
        for (i = 0; i < q->nr; i++) {
                struct diff_filepair *p = q->queue[i];
 
@@ -376,6 +377,16 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
                        diff_tree_release_paths(opt);
                        opt->paths[0] = xstrdup(p->one->path);
                        diff_tree_setup_paths(opt->paths, opt);
+
+                       /*
+                        * The caller expects us to return a set of vanilla
+                        * filepairs to let a later call to diffcore_std()
+                        * it makes to sort the renames out (among other
+                        * things), but we already have found renames
+                        * ourselves; signal diffcore_std() not to muck with
+                        * rename information.
+                        */
+                       opt->found_follow = 1;
                        break;
                }
        }
@@ -412,7 +423,7 @@ int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const cha
        init_tree_desc(&t1, tree1, size1);
        init_tree_desc(&t2, tree2, size2);
        retval = diff_tree(&t1, &t2, base, opt);
-       if (DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) {
+       if (!*base && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) {
                init_tree_desc(&t1, tree1, size1);
                init_tree_desc(&t2, tree2, size2);
                try_to_follow_renames(&t1, &t2, base, opt);
index 42110a465f9a8c91d1bc643dfae7a9b9c32e3719..f78361a676be002a36bed0f243217c4e0ae9c8d1 100644 (file)
@@ -28,7 +28,10 @@ static inline int tree_entry_len(const char *name, const unsigned char *sha1)
 void update_tree_entry(struct tree_desc *);
 void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
 
-/* Helper function that does both of the above and returns true for success */
+/*
+ * Helper function that does both tree_entry_extract() and update_tree_entry()
+ * and returns true for success
+ */
 int tree_entry(struct tree_desc *, struct name_entry *);
 
 void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1);
index e8f03f51541472ead12d55672ba4422f97a3c113..f561d88156b827b15bad7dd4e00f944718149bd9 100644 (file)
@@ -279,9 +279,11 @@ static void add_same_unmerged(struct cache_entry *ce,
 static int unpack_index_entry(struct cache_entry *ce,
                              struct unpack_trees_options *o)
 {
-       struct cache_entry *src[5] = { ce, NULL, };
+       struct cache_entry *src[5] = { NULL };
        int ret;
 
+       src[0] = ce;
+
        mark_ce_used(ce, o);
        if (ce_stage(ce)) {
                if (o->skip_unmerged) {
@@ -327,6 +329,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
 {
        int i, ret, bottom;
        struct tree_desc t[MAX_UNPACK_TREES];
+       void *buf[MAX_UNPACK_TREES];
        struct traverse_info newinfo;
        struct name_entry *p;
 
@@ -344,12 +347,16 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
                const unsigned char *sha1 = NULL;
                if (dirmask & 1)
                        sha1 = names[i].sha1;
-               fill_tree_descriptor(t+i, sha1);
+               buf[i] = fill_tree_descriptor(t+i, sha1);
        }
 
        bottom = switch_cache_bottom(&newinfo);
        ret = traverse_trees(n, t, &newinfo);
        restore_cache_bottom(&newinfo, bottom);
+
+       for (i = 0; i < n; i++)
+               free(buf[i]);
+
        return ret;
 }
 
diff --git a/url.c b/url.c
new file mode 100644 (file)
index 0000000..2306236
--- /dev/null
+++ b/url.c
@@ -0,0 +1,126 @@
+#include "cache.h"
+
+int is_urlschemechar(int first_flag, int ch)
+{
+       /*
+        * The set of valid URL schemes, as per STD66 (RFC3986) is
+        * '[A-Za-z][A-Za-z0-9+.-]*'. But use sightly looser check
+        * of '[A-Za-z0-9][A-Za-z0-9+.-]*' because earlier version
+        * of check used '[A-Za-z0-9]+' so not to break any remote
+        * helpers.
+        */
+       int alphanumeric, special;
+       alphanumeric = ch > 0 && isalnum(ch);
+       special = ch == '+' || ch == '-' || ch == '.';
+       return alphanumeric || (!first_flag && special);
+}
+
+int is_url(const char *url)
+{
+       const char *url2, *first_slash;
+
+       if (!url)
+               return 0;
+       url2 = url;
+       first_slash = strchr(url, '/');
+
+       /* Input with no slash at all or slash first can't be URL. */
+       if (!first_slash || first_slash == url)
+               return 0;
+       /* Character before must be : and next must be /. */
+       if (first_slash[-1] != ':' || first_slash[1] != '/')
+               return 0;
+       /* There must be something before the :// */
+       if (first_slash == url + 1)
+               return 0;
+       /*
+        * Check all characters up to first slash - 1. Only alphanum
+        * is allowed.
+        */
+       url2 = url;
+       while (url2 < first_slash - 1) {
+               if (!is_urlschemechar(url2 == url, (unsigned char)*url2))
+                       return 0;
+               url2++;
+       }
+
+       /* Valid enough. */
+       return 1;
+}
+
+static int url_decode_char(const char *q)
+{
+       int i;
+       unsigned char val = 0;
+       for (i = 0; i < 2; i++) {
+               unsigned char c = *q++;
+               val <<= 4;
+               if (c >= '0' && c <= '9')
+                       val += c - '0';
+               else if (c >= 'a' && c <= 'f')
+                       val += c - 'a' + 10;
+               else if (c >= 'A' && c <= 'F')
+                       val += c - 'A' + 10;
+               else
+                       return -1;
+       }
+       return val;
+}
+
+static char *url_decode_internal(const char **query, const char *stop_at, struct strbuf *out)
+{
+       const char *q = *query;
+
+       do {
+               unsigned char c = *q;
+
+               if (!c)
+                       break;
+               if (stop_at && strchr(stop_at, c)) {
+                       q++;
+                       break;
+               }
+
+               if (c == '%') {
+                       int val = url_decode_char(q + 1);
+                       if (0 <= val) {
+                               strbuf_addch(out, val);
+                               q += 3;
+                               continue;
+                       }
+               }
+
+               if (c == '+')
+                       strbuf_addch(out, ' ');
+               else
+                       strbuf_addch(out, c);
+               q++;
+       } while (1);
+       *query = q;
+       return strbuf_detach(out, NULL);
+}
+
+char *url_decode(const char *url)
+{
+       struct strbuf out = STRBUF_INIT;
+       const char *colon = strchr(url, ':');
+
+       /* Skip protocol part if present */
+       if (colon && url < colon) {
+               strbuf_add(&out, url, colon - url);
+               url = colon;
+       }
+       return url_decode_internal(&url, NULL, &out);
+}
+
+char *url_decode_parameter_name(const char **query)
+{
+       struct strbuf out = STRBUF_INIT;
+       return url_decode_internal(query, "&=", &out);
+}
+
+char *url_decode_parameter_value(const char **query)
+{
+       struct strbuf out = STRBUF_INIT;
+       return url_decode_internal(query, "&", &out);
+}
diff --git a/url.h b/url.h
new file mode 100644 (file)
index 0000000..15817f8
--- /dev/null
+++ b/url.h
@@ -0,0 +1,10 @@
+#ifndef URL_H
+#define URL_H
+
+extern int is_url(const char *url);
+extern int is_urlschemechar(int first_flag, int ch);
+extern char *url_decode(const char *url);
+extern char *url_decode_parameter_name(const char **query);
+extern char *url_decode_parameter_value(const char **query);
+
+#endif /* URL_H */
diff --git a/usage.c b/usage.c
index 79856a2b9f5bc4603252cb10b471a0815416a617..ec4cf53b6bf16f7f9b3528a430891d6c68ef64cc 100644 (file)
--- a/usage.c
+++ b/usage.c
@@ -5,7 +5,7 @@
  */
 #include "git-compat-util.h"
 
-static void report(const char *prefix, const char *err, va_list params)
+void vreportf(const char *prefix, const char *err, va_list params)
 {
        char msg[4096];
        vsnprintf(msg, sizeof(msg), err, params);
@@ -14,24 +14,24 @@ static void report(const char *prefix, const char *err, va_list params)
 
 static NORETURN void usage_builtin(const char *err, va_list params)
 {
-       report("usage: ", err, params);
+       vreportf("usage: ", err, params);
        exit(129);
 }
 
 static NORETURN void die_builtin(const char *err, va_list params)
 {
-       report("fatal: ", err, params);
+       vreportf("fatal: ", err, params);
        exit(128);
 }
 
 static void error_builtin(const char *err, va_list params)
 {
-       report("error: ", err, params);
+       vreportf("error: ", err, params);
 }
 
 static void warn_builtin(const char *warn, va_list params)
 {
-       report("warning: ", warn, params);
+       vreportf("warning: ", warn, params);
 }
 
 /* If we are in a dlopen()ed .so write to a global variable would segfault
index 38563daa3c7582ca87565886d74f16d11b292a57..c49cc1b67e1164c561fb20839272bd8b1f7dde6d 100644 (file)
@@ -1,3 +1,4 @@
+#include "cache.h"
 #include "userdiff.h"
 #include "cache.h"
 #include "attr.h"
@@ -169,6 +170,12 @@ static int parse_tristate(int *b, const char *k, const char *v)
        return 1;
 }
 
+static int parse_bool(int *b, const char *k, const char *v)
+{
+       *b = git_config_bool(k, v);
+       return 1;
+}
+
 int userdiff_config(const char *k, const char *v)
 {
        struct userdiff_driver *drv;
@@ -183,6 +190,8 @@ int userdiff_config(const char *k, const char *v)
                return parse_string(&drv->external, k, v);
        if ((drv = parse_driver(k, v, "textconv")))
                return parse_string(&drv->textconv, k, v);
+       if ((drv = parse_driver(k, v, "cachetextconv")))
+               return parse_bool(&drv->textconv_want_cache, k, v);
        if ((drv = parse_driver(k, v, "wordregex")))
                return parse_string(&drv->word_regex, k, v);
 
index c3151594f5c0643fead757accc27bf1093cf4a68..942d5949501027fb5d30e0d59629aab38fd2669a 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef USERDIFF_H
 #define USERDIFF_H
 
+#include "notes-cache.h"
+
 struct userdiff_funcname {
        const char *pattern;
        int cflags;
@@ -13,6 +15,8 @@ struct userdiff_driver {
        struct userdiff_funcname funcname;
        const char *word_regex;
        const char *textconv;
+       struct notes_cache *textconv_cache;
+       int textconv_want_cache;
 };
 
 int userdiff_config(const char *k, const char *v);
index 58201b6bcb8d362cffd1222bcb8cd77072c34cf5..fd8ead33ed72c37e690ee1fc5b8568f629c95145 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -10,9 +10,11 @@ static void try_to_free_builtin(size_t size)
 
 static void (*try_to_free_routine)(size_t size) = try_to_free_builtin;
 
-void set_try_to_free_routine(void (*routine)(size_t))
+try_to_free_t set_try_to_free_routine(try_to_free_t routine)
 {
-       try_to_free_routine = (routine) ? routine : try_to_free_builtin;
+       try_to_free_t old = try_to_free_routine;
+       try_to_free_routine = routine;
+       return old;
 }
 
 char *xstrdup(const char *str)
@@ -38,7 +40,8 @@ void *xmalloc(size_t size)
                if (!ret && !size)
                        ret = malloc(1);
                if (!ret)
-                       die("Out of memory, malloc failed");
+                       die("Out of memory, malloc failed (tried to allocate %lu bytes)",
+                           (unsigned long)size);
        }
 #ifdef XMALLOC_POISON
        memset(ret, 0xA5, size);
diff --git a/ws.c b/ws.c
index c0893386e6c8aa3af002e847d228dfc5ef64a9cf..d7b8c33f14195ba7ebe86bdbca2fea8f1b22ad37 100644 (file)
--- a/ws.c
+++ b/ws.c
@@ -10,7 +10,8 @@
 static struct whitespace_rule {
        const char *rule_name;
        unsigned rule_bits;
-       unsigned loosens_error;
+       unsigned loosens_error:1,
+               exclude_default:1;
 } whitespace_rule_names[] = {
        { "trailing-space", WS_TRAILING_SPACE, 0 },
        { "space-before-tab", WS_SPACE_BEFORE_TAB, 0 },
@@ -18,6 +19,7 @@ static struct whitespace_rule {
        { "cr-at-eol", WS_CR_AT_EOL, 1 },
        { "blank-at-eol", WS_BLANK_AT_EOL, 0 },
        { "blank-at-eof", WS_BLANK_AT_EOF, 0 },
+       { "tab-in-indent", WS_TAB_IN_INDENT, 0, 1 },
 };
 
 unsigned parse_whitespace_rule(const char *string)
@@ -56,6 +58,9 @@ unsigned parse_whitespace_rule(const char *string)
                }
                string = ep;
        }
+
+       if (rule & WS_TAB_IN_INDENT && rule & WS_INDENT_WITH_NON_TAB)
+               die("cannot enforce both tab-in-indent and indent-with-non-tab");
        return rule;
 }
 
@@ -82,7 +87,8 @@ unsigned whitespace_rule(const char *pathname)
                        unsigned all_rule = 0;
                        int i;
                        for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++)
-                               if (!whitespace_rule_names[i].loosens_error)
+                               if (!whitespace_rule_names[i].loosens_error &&
+                                   !whitespace_rule_names[i].exclude_default)
                                        all_rule |= whitespace_rule_names[i].rule_bits;
                        return all_rule;
                } else if (ATTR_FALSE(value)) {
@@ -125,6 +131,11 @@ char *whitespace_error_string(unsigned ws)
                        strbuf_addstr(&err, ", ");
                strbuf_addstr(&err, "indent with spaces");
        }
+       if (ws & WS_TAB_IN_INDENT) {
+               if (err.len)
+                       strbuf_addstr(&err, ", ");
+               strbuf_addstr(&err, "tab in indent");
+       }
        return strbuf_detach(&err, NULL);
 }
 
@@ -163,7 +174,7 @@ static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule,
                }
        }
 
-       /* Check for space before tab in initial indent. */
+       /* Check indentation */
        for (i = 0; i < len; i++) {
                if (line[i] == ' ')
                        continue;
@@ -175,11 +186,19 @@ static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule,
                                fputs(ws, stream);
                                fwrite(line + written, i - written, 1, stream);
                                fputs(reset, stream);
+                               fwrite(line + i, 1, 1, stream);
                        }
-               } else if (stream)
-                       fwrite(line + written, i - written, 1, stream);
-               if (stream)
-                       fwrite(line + i, 1, 1, stream);
+               } else if (ws_rule & WS_TAB_IN_INDENT) {
+                       result |= WS_TAB_IN_INDENT;
+                       if (stream) {
+                               fwrite(line + written, i - written, 1, stream);
+                               fputs(ws, stream);
+                               fwrite(line + i, 1, 1, stream);
+                               fputs(reset, stream);
+                       }
+               } else if (stream) {
+                       fwrite(line + written, i - written + 1, 1, stream);
+               }
                written = i + 1;
        }
 
@@ -252,8 +271,8 @@ int ws_blank_line(const char *line, int len, unsigned ws_rule)
        return 1;
 }
 
-/* Copy the line to the buffer while fixing whitespaces */
-int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *error_count)
+/* Copy the line onto the end of the strbuf while fixing whitespaces */
+void ws_fix_copy(struct strbuf *dst, const char *src, int len, unsigned ws_rule, int *error_count)
 {
        /*
         * len is number of bytes to be copied from src, starting
@@ -267,7 +286,6 @@ int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *erro
        int last_tab_in_indent = -1;
        int last_space_in_indent = -1;
        int need_fix_leading_space = 0;
-       char *buf;
 
        /*
         * Strip trailing whitespace
@@ -307,7 +325,6 @@ int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *erro
                        break;
        }
 
-       buf = dst;
        if (need_fix_leading_space) {
                /* Process indent ourselves */
                int consecutive_spaces = 0;
@@ -329,28 +346,41 @@ int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *erro
                        char ch = src[i];
                        if (ch != ' ') {
                                consecutive_spaces = 0;
-                               *dst++ = ch;
+                               strbuf_addch(dst, ch);
                        } else {
                                consecutive_spaces++;
                                if (consecutive_spaces == 8) {
-                                       *dst++ = '\t';
+                                       strbuf_addch(dst, '\t');
                                        consecutive_spaces = 0;
                                }
                        }
                }
                while (0 < consecutive_spaces--)
-                       *dst++ = ' ';
+                       strbuf_addch(dst, ' ');
+               len -= last;
+               src += last;
+               fixed = 1;
+       } else if ((ws_rule & WS_TAB_IN_INDENT) && last_tab_in_indent >= 0) {
+               /* Expand tabs into spaces */
+               int last = last_tab_in_indent + 1;
+               for (i = 0; i < last; i++) {
+                       if (src[i] == '\t')
+                               do {
+                                       strbuf_addch(dst, ' ');
+                               } while (dst->len % 8);
+                       else
+                               strbuf_addch(dst, src[i]);
+               }
                len -= last;
                src += last;
                fixed = 1;
        }
 
-       memcpy(dst, src, len);
+       strbuf_add(dst, src, len);
        if (add_cr_to_tail)
-               dst[len++] = '\r';
+               strbuf_addch(dst, '\r');
        if (add_nl_to_tail)
-               dst[len++] = '\n';
+               strbuf_addch(dst, '\n');
        if (fixed && error_count)
                (*error_count)++;
-       return dst + len - buf;
 }
index d44486c826ee46d258e88c5013d038243aad2756..2f9e33c8fa172b129fd956abc4f74a5bf5543ba7 100644 (file)
@@ -9,6 +9,8 @@
 #include "quote.h"
 #include "run-command.h"
 #include "remote.h"
+#include "refs.h"
+#include "submodule.h"
 
 static char default_wt_status_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -17,6 +19,8 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_RED,    /* WT_STATUS_UNTRACKED */
        GIT_COLOR_RED,    /* WT_STATUS_NOBRANCH */
        GIT_COLOR_RED,    /* WT_STATUS_UNMERGED */
+       GIT_COLOR_GREEN,  /* WT_STATUS_LOCAL_BRANCH */
+       GIT_COLOR_RED,    /* WT_STATUS_REMOTE_BRANCH */
 };
 
 static const char *color(int slot, struct wt_status *s)
@@ -42,6 +46,7 @@ void wt_status_prepare(struct wt_status *s)
        s->index_file = get_index_file();
        s->change.strdup_strings = 1;
        s->untracked.strdup_strings = 1;
+       s->ignored.strdup_strings = 1;
 }
 
 static void wt_status_print_unmerged_header(struct wt_status *s)
@@ -96,13 +101,15 @@ static void wt_status_print_dirty_header(struct wt_status *s,
        color_fprintf_ln(s->fp, c, "#");
 }
 
-static void wt_status_print_untracked_header(struct wt_status *s)
+static void wt_status_print_other_header(struct wt_status *s,
+                                        const char *what,
+                                        const char *how)
 {
        const char *c = color(WT_STATUS_HEADER, s);
-       color_fprintf_ln(s->fp, c, "# Untracked files:");
+       color_fprintf_ln(s->fp, c, "# %s files:", what);
        if (!advice_status_hints)
                return;
-       color_fprintf_ln(s->fp, c, "#   (use \"git add <file>...\" to include in what will be committed)");
+       color_fprintf_ln(s->fp, c, "#   (use \"git %s <file>...\" to include in what will be committed)", how);
        color_fprintf_ln(s->fp, c, "#");
 }
 
@@ -229,7 +236,7 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
                struct wt_status_change_data *d;
 
                p = q->queue[i];
-               it = string_list_insert(p->one->path, &s->change);
+               it = string_list_insert(&s->change, p->one->path);
                d = it->util;
                if (!d) {
                        d = xcalloc(1, sizeof(*d));
@@ -276,7 +283,7 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
                struct wt_status_change_data *d;
 
                p = q->queue[i];
-               it = string_list_insert(p->two->path, &s->change);
+               it = string_list_insert(&s->change, p->two->path);
                d = it->util;
                if (!d) {
                        d = xcalloc(1, sizeof(*d));
@@ -306,6 +313,8 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
        DIFF_OPT_SET(&rev.diffopt, DIRTY_SUBMODULES);
        if (!s->show_untracked_files)
                DIFF_OPT_SET(&rev.diffopt, IGNORE_UNTRACKED_IN_SUBMODULES);
+       if (s->ignore_submodule_arg)
+               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;
        rev.prune_data = s->pathspec;
@@ -322,6 +331,9 @@ static void wt_status_collect_changes_index(struct wt_status *s)
        opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference;
        setup_revisions(0, NULL, &rev, &opt);
 
+       if (s->ignore_submodule_arg)
+               handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg);
+
        rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
        rev.diffopt.format_callback = wt_status_collect_updated_cb;
        rev.diffopt.format_callback_data = s;
@@ -343,7 +355,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
 
                if (!ce_path_match(ce, s->pathspec))
                        continue;
-               it = string_list_insert(ce->name, &s->change);
+               it = string_list_insert(&s->change, ce->name);
                d = it->util;
                if (!d) {
                        d = xcalloc(1, sizeof(*d));
@@ -378,9 +390,26 @@ static void wt_status_collect_untracked(struct wt_status *s)
                        continue;
                if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
                        continue;
-               s->workdir_untracked = 1;
-               string_list_insert(ent->name, &s->untracked);
+               string_list_insert(&s->untracked, ent->name);
+               free(ent);
+       }
+
+       if (s->show_ignored_files) {
+               dir.nr = 0;
+               dir.flags = DIR_SHOW_IGNORED | DIR_SHOW_OTHER_DIRECTORIES;
+               fill_directory(&dir, s->pathspec);
+               for (i = 0; i < dir.nr; i++) {
+                       struct dir_entry *ent = dir.entries[i];
+                       if (!cache_name_is_other(ent->name, ent->len))
+                               continue;
+                       if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
+                               continue;
+                       string_list_insert(&s->ignored, ent->name);
+                       free(ent);
+               }
        }
+
+       free(dir.entries);
 }
 
 void wt_status_collect(struct wt_status *s)
@@ -498,17 +527,18 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
        struct child_process sm_summary;
        char summary_limit[64];
        char index[PATH_MAX];
-       const char *env[] = { index, NULL };
-       const char *argv[] = {
-               "submodule",
-               "summary",
-               uncommitted ? "--files" : "--cached",
-               "--for-status",
-               "--summary-limit",
-               summary_limit,
-               uncommitted ? NULL : (s->amend ? "HEAD^" : "HEAD"),
-               NULL
-       };
+       const char *env[] = { NULL, NULL };
+       const char *argv[8];
+
+       env[0] =        index;
+       argv[0] =       "submodule";
+       argv[1] =       "summary";
+       argv[2] =       uncommitted ? "--files" : "--cached";
+       argv[3] =       "--for-status";
+       argv[4] =       "--summary-limit";
+       argv[5] =       summary_limit;
+       argv[6] =       uncommitted ? NULL : (s->amend ? "HEAD^" : "HEAD");
+       argv[7] =       NULL;
 
        sprintf(summary_limit, "%d", s->submodule_summary);
        snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
@@ -523,7 +553,10 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
        run_command(&sm_summary);
 }
 
-static void wt_status_print_untracked(struct wt_status *s)
+static void wt_status_print_other(struct wt_status *s,
+                                 struct string_list *l,
+                                 const char *what,
+                                 const char *how)
 {
        int i;
        struct strbuf buf = STRBUF_INIT;
@@ -531,10 +564,11 @@ static void wt_status_print_untracked(struct wt_status *s)
        if (!s->untracked.nr)
                return;
 
-       wt_status_print_untracked_header(s);
-       for (i = 0; i < s->untracked.nr; i++) {
+       wt_status_print_other_header(s, what, how);
+
+       for (i = 0; i < l->nr; i++) {
                struct string_list_item *it;
-               it = &(s->untracked.items[i]);
+               it = &(l->items[i]);
                color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
                color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s",
                                 quote_path(it->string, strlen(it->string),
@@ -618,13 +652,17 @@ void wt_status_print(struct wt_status *s)
        wt_status_print_updated(s);
        wt_status_print_unmerged(s);
        wt_status_print_changed(s);
-       if (s->submodule_summary) {
+       if (s->submodule_summary &&
+           (!s->ignore_submodule_arg ||
+            strcmp(s->ignore_submodule_arg, "all"))) {
                wt_status_print_submodule_summary(s, 0);  /* staged */
                wt_status_print_submodule_summary(s, 1);  /* unstaged */
        }
-       if (s->show_untracked_files)
-               wt_status_print_untracked(s);
-       else if (s->commitable)
+       if (s->show_untracked_files) {
+               wt_status_print_other(s, &s->untracked, "Untracked", "add");
+               if (s->show_ignored_files)
+                       wt_status_print_other(s, &s->ignored, "Ignored", "add -f");
+       } else if (s->commitable)
                fprintf(s->fp, "# Untracked files not listed%s\n",
                        advice_status_hints
                        ? " (use -u option to show untracked files)" : "");
@@ -715,24 +753,84 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
        }
 }
 
-static void wt_shortstatus_untracked(int null_termination, struct string_list_item *it,
-                           struct wt_status *s)
+static void wt_shortstatus_other(int null_termination, struct string_list_item *it,
+                                struct wt_status *s, const char *sign)
 {
        if (null_termination) {
-               fprintf(stdout, "?? %s%c", it->string, 0);
+               fprintf(stdout, "%s %s%c", sign, it->string, 0);
        } else {
                struct strbuf onebuf = STRBUF_INIT;
                const char *one;
                one = quote_path(it->string, -1, &onebuf, s->prefix);
-               color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "??");
+               color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign);
                printf(" %s\n", one);
                strbuf_release(&onebuf);
        }
 }
 
-void wt_shortstatus_print(struct wt_status *s, int null_termination)
+static void wt_shortstatus_print_tracking(struct wt_status *s)
+{
+       struct branch *branch;
+       const char *header_color = color(WT_STATUS_HEADER, s);
+       const char *branch_color_local = color(WT_STATUS_LOCAL_BRANCH, s);
+       const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s);
+
+       const char *base;
+       const char *branch_name;
+       int num_ours, num_theirs;
+
+       color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## ");
+
+       if (!s->branch)
+               return;
+       branch_name = s->branch;
+
+       if (!prefixcmp(branch_name, "refs/heads/"))
+               branch_name += 11;
+       else if (!strcmp(branch_name, "HEAD")) {
+               branch_name = "HEAD (no branch)";
+               branch_color_local = color(WT_STATUS_NOBRANCH, s);
+       }
+
+       branch = branch_get(s->branch + 11);
+       if (s->is_initial)
+               color_fprintf(s->fp, header_color, "Initial commit on ");
+       if (!stat_tracking_info(branch, &num_ours, &num_theirs)) {
+               color_fprintf_ln(s->fp, branch_color_local,
+                       "%s", branch_name);
+               return;
+       }
+
+       base = branch->merge[0]->dst;
+       base = shorten_unambiguous_ref(base, 0);
+       color_fprintf(s->fp, branch_color_local, "%s", branch_name);
+       color_fprintf(s->fp, header_color, "...");
+       color_fprintf(s->fp, branch_color_remote, "%s", base);
+
+       color_fprintf(s->fp, header_color, " [");
+       if (!num_ours) {
+               color_fprintf(s->fp, header_color, "behind ");
+               color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
+       } else if (!num_theirs) {
+               color_fprintf(s->fp, header_color, "ahead ");
+               color_fprintf(s->fp, branch_color_local, "%d", num_ours);
+       } else {
+               color_fprintf(s->fp, header_color, "ahead ");
+               color_fprintf(s->fp, branch_color_local, "%d", num_ours);
+               color_fprintf(s->fp, header_color, ", behind ");
+               color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
+       }
+
+       color_fprintf_ln(s->fp, header_color, "]");
+}
+
+void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_branch)
 {
        int i;
+
+       if (show_branch)
+               wt_shortstatus_print_tracking(s);
+
        for (i = 0; i < s->change.nr; i++) {
                struct wt_status_change_data *d;
                struct string_list_item *it;
@@ -748,7 +846,13 @@ void wt_shortstatus_print(struct wt_status *s, int null_termination)
                struct string_list_item *it;
 
                it = &(s->untracked.items[i]);
-               wt_shortstatus_untracked(null_termination, it, s);
+               wt_shortstatus_other(null_termination, it, s, "??");
+       }
+       for (i = 0; i < s->ignored.nr; i++) {
+               struct string_list_item *it;
+
+               it = &(s->ignored.items[i]);
+               wt_shortstatus_other(null_termination, it, s, "!!");
        }
 }
 
@@ -757,5 +861,5 @@ void wt_porcelain_print(struct wt_status *s, int null_termination)
        s->use_color = 0;
        s->relative_paths = 0;
        s->prefix = NULL;
-       wt_shortstatus_print(s, null_termination);
+       wt_shortstatus_print(s, null_termination, 0);
 }
index 91206739f318233811dbd594d5ff37aa77c06eef..9df9c9fad2512d7c1d7d6456cdd645d641b5a089 100644 (file)
@@ -12,6 +12,8 @@ enum color_wt_status {
        WT_STATUS_UNTRACKED,
        WT_STATUS_NOBRANCH,
        WT_STATUS_UNMERGED,
+       WT_STATUS_LOCAL_BRANCH,
+       WT_STATUS_REMOTE_BRANCH
 };
 
 enum untracked_status_type {
@@ -41,25 +43,27 @@ struct wt_status {
        int use_color;
        int relative_paths;
        int submodule_summary;
+       int show_ignored_files;
        enum untracked_status_type show_untracked_files;
-       char color_palette[WT_STATUS_UNMERGED+1][COLOR_MAXLEN];
+       const char *ignore_submodule_arg;
+       char color_palette[WT_STATUS_REMOTE_BRANCH+1][COLOR_MAXLEN];
 
        /* These are computed during processing of the individual sections */
        int commitable;
        int workdir_dirty;
-       int workdir_untracked;
        const char *index_file;
        FILE *fp;
        const char *prefix;
        struct string_list change;
        struct string_list untracked;
+       struct string_list ignored;
 };
 
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
 
-void wt_shortstatus_print(struct wt_status *s, int null_termination);
+void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_branch);
 void wt_porcelain_print(struct wt_status *s, int null_termination);
 
 #endif /* STATUS_H */
index cd2285de1cb1faa9f7c6c97dd22210f20bb046a3..e1e054e4d982de30d8a9c8c4109c6d62448f62a9 100644 (file)
@@ -286,9 +286,8 @@ static long ff_regexp(const char *line, long len,
        result = pmatch[i].rm_eo - pmatch[i].rm_so;
        if (result > buffer_size)
                result = buffer_size;
-       else
-               while (result > 0 && (isspace(line[result - 1])))
-                       result--;
+       while (result > 0 && (isspace(line[result - 1])))
+               result--;
        memcpy(buffer, line, result);
  fail:
        free(line_buffer);