summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml26
-rw-r--r--Documentation/Makefile5
-rw-r--r--Documentation/RelNotes/2.16.0.txt72
-rw-r--r--Documentation/config.txt47
-rw-r--r--Documentation/git-check-ref-format.txt19
-rw-r--r--Documentation/git-describe.txt18
-rw-r--r--Documentation/git-pack-objects.txt22
-rw-r--r--Documentation/git-rebase.txt19
-rw-r--r--Documentation/git-rev-list.txt4
-rw-r--r--Documentation/githooks.txt3
-rw-r--r--Documentation/gitworkflows.txt4
-rwxr-xr-xDocumentation/install-doc-quick.sh9
-rw-r--r--Documentation/merge-config.txt4
-rw-r--r--Documentation/pretty-formats.txt12
-rw-r--r--Documentation/rebase-config.txt52
-rw-r--r--Documentation/rev-list-options.txt46
-rw-r--r--Documentation/technical/api-decorate.txt6
-rw-r--r--Documentation/technical/partial-clone.txt324
-rwxr-xr-xGIT-VERSION-GEN2
-rw-r--r--Makefile24
-rw-r--r--branch.c4
-rw-r--r--branch.h10
-rw-r--r--builtin/am.c10
-rw-r--r--builtin/branch.c19
-rw-r--r--builtin/checkout.c2
-rw-r--r--builtin/clone.c6
-rw-r--r--builtin/describe.c121
-rw-r--r--builtin/fast-export.c2
-rw-r--r--builtin/fetch.c7
-rw-r--r--builtin/fmt-merge-msg.c3
-rw-r--r--builtin/index-pack.c11
-rw-r--r--builtin/merge.c2
-rw-r--r--builtin/mv.c2
-rw-r--r--builtin/notes.c2
-rw-r--r--builtin/pack-objects.c64
-rw-r--r--builtin/rebase--helper.c29
-rw-r--r--builtin/reset.c2
-rw-r--r--builtin/rev-list.c112
-rw-r--r--builtin/rm.c2
-rw-r--r--builtin/show-branch.c2
-rw-r--r--builtin/worktree.c22
-rwxr-xr-xci/install-dependencies.sh8
-rwxr-xr-xci/lib-travisci.sh34
-rw-r--r--commit.h81
-rw-r--r--contrib/completion/git-prompt.sh7
-rw-r--r--convert.c19
-rw-r--r--decorate.c28
-rw-r--r--decorate.h49
-rw-r--r--diff.c50
-rw-r--r--dir.c132
-rw-r--r--dir.h3
-rw-r--r--git-compat-util.h23
-rwxr-xr-xgit-cvsimport.perl2
-rw-r--r--git-rebase--interactive.sh23
-rwxr-xr-xgit-rebase.sh35
-rwxr-xr-xgit-svn.perl1
-rw-r--r--help.c6
-rw-r--r--http.c5
-rw-r--r--imap-send.c8
-rw-r--r--list-objects-filter-options.c92
-rw-r--r--list-objects-filter-options.h61
-rw-r--r--list-objects-filter.c401
-rw-r--r--list-objects-filter.h77
-rw-r--r--list-objects.c144
-rw-r--r--list-objects.h13
-rw-r--r--object.h1
-rw-r--r--oidmap.h22
-rw-r--r--oidset.c10
-rw-r--r--oidset.h36
-rw-r--r--path.h133
-rw-r--r--pretty.h131
-rw-r--r--revision.c2
-rw-r--r--revision.h5
-rw-r--r--sequencer.c126
-rw-r--r--sequencer.h10
-rw-r--r--strbuf.c25
-rw-r--r--submodule.c32
-rw-r--r--submodule.h14
-rw-r--r--t/Makefile6
-rw-r--r--t/helper/.gitignore45
-rw-r--r--t/helper/test-example-decorate.c74
-rw-r--r--t/lib-git-svn.sh24
-rwxr-xr-xt/perf/p7519-fsmonitor.sh3
-rwxr-xr-xt/t0027-auto-crlf.sh77
-rwxr-xr-xt/t2025-worktree-add.sh35
-rwxr-xr-xt/t3404-rebase-interactive.sh22
-rwxr-xr-xt/t4045-diff-relative.sh110
-rwxr-xr-xt/t5317-pack-objects-filter-objects.sh375
-rwxr-xr-xt/t5573-pull-verify-signatures.sh81
-rwxr-xr-xt/t5615-alternate-env.sh6
-rwxr-xr-xt/t6100-rev-list-in-order.sh77
-rwxr-xr-xt/t6112-rev-list-filters-objects.sh225
-rwxr-xr-xt/t6120-describe.sh36
-rwxr-xr-xt/t7612-merge-verify-signatures.sh45
-rwxr-xr-xt/t9004-example.sh10
-rwxr-xr-xt/t9169-git-svn-dcommit-crlf.sh27
-rw-r--r--t/test-lib.sh46
-rw-r--r--transport-helper.c30
-rw-r--r--transport-internal.h61
-rw-r--r--transport.c76
-rw-r--r--transport.h55
-rw-r--r--version.c1
-rw-r--r--version.h1
103 files changed, 3804 insertions, 745 deletions
diff --git a/.travis.yml b/.travis.yml
index 281f101f31..7c9aa0557e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,30 +21,14 @@ addons:
- git-svn
- apache2
-env:
- global:
- - DEVELOPER=1
- # The Linux build installs the defined dependency versions below.
- # The OS X build installs the latest available versions. Keep that
- # in mind when you encounter a broken OS X build!
- - LINUX_P4_VERSION="16.2"
- - LINUX_GIT_LFS_VERSION="1.5.2"
- - DEFAULT_TEST_TARGET=prove
- - GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save"
- - GIT_TEST_OPTS="--verbose-log"
- - GIT_TEST_CLONE_2GB=YesPlease
- # t9810 occasionally fails on Travis CI OS X
- # t9816 occasionally fails with "TAP out of sequence errors" on Travis CI OS X
- - GIT_SKIP_TESTS="t9810 t9816"
-
matrix:
include:
- - env: GETTEXT_POISON=YesPlease
+ - env: jobname=GETTEXT_POISON
os: linux
compiler:
addons:
before_install:
- - env: Windows
+ - env: jobname=Windows
os: linux
compiler:
addons:
@@ -55,7 +39,7 @@ matrix:
test "$TRAVIS_REPO_SLUG" != "git/git" ||
ci/run-windows-build.sh $TRAVIS_BRANCH $(git rev-parse HEAD)
after_failure:
- - env: Linux32
+ - env: jobname=Linux32
os: linux
compiler:
services:
@@ -63,7 +47,7 @@ matrix:
before_install:
before_script:
script: ci/run-linux32-docker.sh
- - env: Static Analysis
+ - env: jobname=StaticAnalysis
os: linux
compiler:
addons:
@@ -74,7 +58,7 @@ matrix:
before_script:
script: ci/run-static-analysis.sh
after_failure:
- - env: Documentation
+ - env: jobname=Documentation
os: linux
compiler:
addons:
diff --git a/Documentation/Makefile b/Documentation/Makefile
index 2ab65561af..4ae9ba5c86 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -39,6 +39,7 @@ MAN7_TXT += gitworkflows.txt
MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT)
MAN_XML = $(patsubst %.txt,%.xml,$(MAN_TXT))
MAN_HTML = $(patsubst %.txt,%.html,$(MAN_TXT))
+GIT_MAN_REF = master
OBSOLETE_HTML += everyday.html
OBSOLETE_HTML += git-remote-helpers.html
@@ -437,14 +438,14 @@ require-manrepo::
then echo "git-manpages repository must exist at $(MAN_REPO)"; exit 1; fi
quick-install-man: require-manrepo
- '$(SHELL_PATH_SQ)' ./install-doc-quick.sh $(MAN_REPO) $(DESTDIR)$(mandir)
+ '$(SHELL_PATH_SQ)' ./install-doc-quick.sh $(MAN_REPO) $(DESTDIR)$(mandir) $(GIT_MAN_REF)
require-htmlrepo::
@if test ! -d $(HTML_REPO); \
then echo "git-htmldocs repository must exist at $(HTML_REPO)"; exit 1; fi
quick-install-html: require-htmlrepo
- '$(SHELL_PATH_SQ)' ./install-doc-quick.sh $(HTML_REPO) $(DESTDIR)$(htmldir)
+ '$(SHELL_PATH_SQ)' ./install-doc-quick.sh $(HTML_REPO) $(DESTDIR)$(htmldir) $(GIT_MAN_REF)
print-man1:
@for i in $(MAN1_TXT); do echo $$i; done
diff --git a/Documentation/RelNotes/2.16.0.txt b/Documentation/RelNotes/2.16.0.txt
index 073a126a9c..8f0461eefd 100644
--- a/Documentation/RelNotes/2.16.0.txt
+++ b/Documentation/RelNotes/2.16.0.txt
@@ -120,6 +120,31 @@ UI, Workflows & Features
who are used to seeing abbreviated object names and find them
confusing with the range syntax.
+ * With a configuration variable rebase.abbreviateCommands set,
+ "git rebase -i" produces the todo list with a single-letter
+ command names.
+
+ * "git worktree add" learned to run the post-checkout hook, just like
+ "git checkout" does, after the initial checkout.
+
+ * "git svn" has been updated to strip CRs in the commit messages, as
+ recent versions of Subversion rejects them.
+
+ * "git imap-send" did not correctly quote the folder name when
+ making a request to the server, which has been corrected.
+
+ * Error messages from "git rebase" have been somewhat cleaned up.
+
+ * Git has been taught to support an https:// URL used for http.proxy
+ when using recent versions of libcurl.
+
+ * "git merge" learned to pay attention to merge.verifySignatures
+ configuration variable and pretend as if '--verify-signatures'
+ option was given from the command line.
+
+ * "git describe" was taught to dig trees deeper to find a
+ <commit-ish>:<path> that refers to a given blob object.
+
Performance, Internal Implementation, Development Support etc.
@@ -183,6 +208,23 @@ Performance, Internal Implementation, Development Support etc.
* The tracing infrastructure has been optimized for cases where no
tracing is requested.
+ * In preparation for implementing narrow/partial clone, the object
+ walking machinery has been taught a way to tell it to "filter" some
+ objects from enumeration.
+
+ * A few structures and variables that are implementation details of
+ the decorate API have been renamed and then the API got documented
+ better.
+
+ * Assorted updates for TravisCI integration.
+ (merge 4f26366679 sg/travis-fixes later to maint).
+
+ * Introduce a helper to simplify code to parse a common pattern that
+ expects either "--key" or "--key=<something>".
+
+ * "git version --build-options" learned to report the host CPU and
+ the exact commit object name the binary was built from.
+
Also contains various documentation updates and code clean-ups.
@@ -374,6 +416,23 @@ Fixes since v2.15
lost.
(merge abfb04d0c7 ls/editor-waiting-message later to maint).
+ * The "safe crlf" check incorrectly triggered for contents that does
+ not use CRLF as line endings, which has been corrected.
+ (merge 649f1f0948 tb/check-crlf-for-safe-crlf later to maint).
+
+ * "git clone --shared" to borrow from a (secondary) worktree did not
+ work, even though "git clone --local" did. Both are now accepted.
+ (merge b3b05971c1 es/clone-shared-worktree later to maint).
+
+ * The build procedure now allows not just the repositories but also
+ the refs to be used to take pre-formatted manpages and html
+ documents to install.
+ (merge 65289e9dcd rb/quick-install-doc later to maint).
+
+ * Update the shell prompt script (in contrib/) to strip trailing CR
+ from strings read from various "state" files.
+ (merge 041fe8fc83 ra/prompt-eread-fix later to maint).
+
* Other minor doc, test and build updates and code cleanups.
(merge 1a1fc2d5b5 rd/man-prune-progress later to maint).
(merge 0ba014035a rd/man-reflog-add-n later to maint).
@@ -384,3 +443,16 @@ Fixes since v2.15
(merge 5e83cca0b8 jk/no-optional-locks later to maint).
(merge 826c778f7c js/hashmap-update-sample later to maint).
(merge 176b2d328c sg/setup-doc-update later to maint).
+ (merge 1b09073514 rs/am-builtin-leakfix later to maint).
+ (merge addcf6cfde rs/fmt-merge-msg-string-leak-fix later to maint).
+ (merge c3ff8f6c14 rs/strbuf-read-once-reset-length later to maint).
+ (merge 6b0eb884f9 db/doc-workflows-neuter-the-maintainer later to maint).
+ (merge 8c87bdfb21 jk/cvsimport-quoting later to maint).
+ (merge 176cb979fe rs/fmt-merge-msg-leakfix later to maint).
+ (merge 5a03360e73 tb/delimit-pretty-trailers-args-with-comma later to maint).
+ (merge d0e6326026 ot/pretty later to maint).
+ (merge 44103f4197 sb/test-helper-excludes later to maint).
+ (merge 170078693f jt/transport-no-more-rsync later to maint).
+ (merge c07b3adff1 bw/path-doc later to maint).
+ (merge bf9d7df950 tz/lib-git-svn-svnserve-tests later to maint).
+ (merge dec366c9a8 sr/http-sslverify-config-doc later to maint).
diff --git a/Documentation/config.txt b/Documentation/config.txt
index b18c0f97fe..0e25b2c92b 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -41,11 +41,13 @@ in the section header, like in the example below:
--------
Subsection names are case sensitive and can contain any characters except
-newline (doublequote `"` and backslash can be included by escaping them
-as `\"` and `\\`, respectively). Section headers cannot span multiple
-lines. Variables may belong directly to a section or to a given subsection.
-You can have `[section]` if you have `[section "subsection"]`, but you
-don't need to.
+newline and the null byte. Doublequote `"` and backslash can be included
+by escaping them as `\"` and `\\`, respectively. Backslashes preceding
+other characters are dropped when reading; for example, `\t` is read as
+`t` and `\0` is read as `0` Section headers cannot span multiple lines.
+Variables may belong directly to a section or to a given subsection. You
+can have `[section]` if you have `[section "subsection"]`, but you don't
+need to.
There is also a deprecated `[section.subsection]` syntax. With this
syntax, the subsection name is converted to lower-case and is also
@@ -1968,8 +1970,8 @@ empty string.
http.sslVerify::
Whether to verify the SSL certificate when fetching or pushing
- over HTTPS. Can be overridden by the `GIT_SSL_NO_VERIFY` environment
- variable.
+ over HTTPS. Defaults to true. Can be overridden by the
+ `GIT_SSL_NO_VERIFY` environment variable.
http.sslCert::
File containing the SSL certificate when fetching or pushing
@@ -2736,36 +2738,7 @@ push.recurseSubmodules::
is retained. You may override this configuration at time of push by
specifying '--recurse-submodules=check|on-demand|no'.
-rebase.stat::
- Whether to show a diffstat of what changed upstream since the last
- rebase. False by default.
-
-rebase.autoSquash::
- If set to true enable `--autosquash` option by default.
-
-rebase.autoStash::
- When set to true, automatically create a temporary stash entry
- before the operation begins, and apply it after the operation
- ends. This means that you can run rebase on a dirty worktree.
- However, use with care: the final stash application after a
- successful rebase might result in non-trivial conflicts.
- Defaults to false.
-
-rebase.missingCommitsCheck::
- If set to "warn", git rebase -i will print a warning if some
- commits are removed (e.g. a line was deleted), however the
- rebase will still proceed. If set to "error", it will print
- the previous warning and stop the rebase, 'git rebase
- --edit-todo' can then be used to correct the error. If set to
- "ignore", no checking is done.
- To drop a commit without warning or error, use the `drop`
- command in the todo-list.
- Defaults to "ignore".
-
-rebase.instructionFormat::
- A format string, as specified in linkgit:git-log[1], to be used for
- the instruction list during an interactive rebase. The format will automatically
- have the long commit hash prepended to the format.
+include::rebase-config.txt[]
receive.advertiseAtomic::
By default, git-receive-pack will advertise the atomic push
diff --git a/Documentation/git-check-ref-format.txt b/Documentation/git-check-ref-format.txt
index cf0a0b7df2..d9de992585 100644
--- a/Documentation/git-check-ref-format.txt
+++ b/Documentation/git-check-ref-format.txt
@@ -79,16 +79,21 @@ reference name expressions (see linkgit:gitrevisions[7]):
With the `--branch` option, the command takes a name and checks if
it can be used as a valid branch name (e.g. when creating a new
-branch). The rule `git check-ref-format --branch $name` implements
+branch). But be cautious when using the
+previous checkout syntax that may refer to a detached HEAD state.
+The rule `git check-ref-format --branch $name` implements
may be stricter than what `git check-ref-format refs/heads/$name`
says (e.g. a dash may appear at the beginning of a ref component,
but it is explicitly forbidden at the beginning of a branch name).
When run with `--branch` option in a repository, the input is first
-expanded for the ``previous branch syntax''
-`@{-n}`. For example, `@{-1}` is a way to refer the last branch you
-were on. This option should be used by porcelains to accept this
-syntax anywhere a branch name is expected, so they can act as if you
-typed the branch name.
+expanded for the ``previous checkout syntax''
+`@{-n}`. For example, `@{-1}` is a way to refer the last thing that
+was checked out using "git checkout" operation. This option should be
+used by porcelains to accept this syntax anywhere a branch name is
+expected, so they can act as if you typed the branch name. As an
+exception note that, the ``previous checkout operation'' might result
+in a commit object name when the N-th last thing checked out was not
+a branch.
OPTIONS
-------
@@ -116,7 +121,7 @@ OPTIONS
EXAMPLES
--------
-* Print the name of the previous branch:
+* Print the name of the previous thing checked out:
+
------------
$ git check-ref-format --branch @{-1}
diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
index c924c945ba..e027fb8c4b 100644
--- a/Documentation/git-describe.txt
+++ b/Documentation/git-describe.txt
@@ -3,14 +3,14 @@ git-describe(1)
NAME
----
-git-describe - Describe a commit using the most recent tag reachable from it
-
+git-describe - Give an object a human readable name based on an available ref
SYNOPSIS
--------
[verse]
'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] [<commit-ish>...]
'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] --dirty[=<mark>]
+'git describe' <blob>
DESCRIPTION
-----------
@@ -24,6 +24,12 @@ By default (without --all or --tags) `git describe` only shows
annotated tags. For more information about creating annotated tags
see the -a and -s options to linkgit:git-tag[1].
+If the given object refers to a blob, it will be described
+as `<commit-ish>:<path>`, such that the blob can be found
+at `<path>` in the `<commit-ish>`, which itself describes the
+first commit in which this blob occurs in a reverse revision walk
+from HEAD.
+
OPTIONS
-------
<commit-ish>...::
@@ -186,6 +192,14 @@ selected and output. Here fewest commits different is defined as
the number of commits which would be shown by `git log tag..input`
will be the smallest number of commits possible.
+BUGS
+----
+
+Tree objects as well as tag objects not pointing at commits, cannot be described.
+When describing blobs, the lightweight tags pointing at blobs are ignored,
+but the blob is still described as <committ-ish>:<path> despite the lightweight
+tag being favorable.
+
GIT
---
Part of the linkgit:git[1] suite
diff --git a/Documentation/git-pack-objects.txt b/Documentation/git-pack-objects.txt
index 473a16135a..aa403d02f3 100644
--- a/Documentation/git-pack-objects.txt
+++ b/Documentation/git-pack-objects.txt
@@ -12,7 +12,8 @@ SYNOPSIS
'git pack-objects' [-q | --progress | --all-progress] [--all-progress-implied]
[--no-reuse-delta] [--delta-base-offset] [--non-empty]
[--local] [--incremental] [--window=<n>] [--depth=<n>]
- [--revs [--unpacked | --all]] [--stdout | base-name]
+ [--revs [--unpacked | --all]]
+ [--stdout [--filter=<filter-spec>] | base-name]
[--shallow] [--keep-true-parents] < object-list
@@ -236,6 +237,25 @@ So does `git bundle` (see linkgit:git-bundle[1]) when it creates a bundle.
With this option, parents that are hidden by grafts are packed
nevertheless.
+--filter=<filter-spec>::
+ Requires `--stdout`. Omits certain objects (usually blobs) from
+ the resulting packfile. See linkgit:git-rev-list[1] for valid
+ `<filter-spec>` forms.
+
+--no-filter::
+ Turns off any previous `--filter=` argument.
+
+--missing=<missing-action>::
+ A debug option to help with future "partial clone" development.
+ This option specifies how missing objects are handled.
++
+The form '--missing=error' requests that pack-objects stop with an error if
+a missing object is encountered. This is the default action.
++
+The form '--missing=allow-any' will allow object traversal to continue
+if a missing object is encountered. Missing objects will silently be
+omitted from the results.
+
SEE ALSO
--------
linkgit:git-rev-list[1]
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 3cedfb0fd2..8a861c1e0d 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -203,24 +203,7 @@ Alternatively, you can undo the 'git rebase' with
CONFIGURATION
-------------
-rebase.stat::
- Whether to show a diffstat of what changed upstream since the last
- rebase. False by default.
-
-rebase.autoSquash::
- If set to true enable `--autosquash` option by default.
-
-rebase.autoStash::
- If set to true enable `--autostash` option by default.
-
-rebase.missingCommitsCheck::
- If set to "warn", print warnings about removed commits in
- interactive mode. If set to "error", print the warnings and
- stop the rebase. If set to "ignore", no checking is
- done. "ignore" by default.
-
-rebase.instructionFormat::
- Custom commit list format to use during an `--interactive` rebase.
+include::rebase-config.txt[]
OPTIONS
-------
diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
index ef22f1775b..88609ff435 100644
--- a/Documentation/git-rev-list.txt
+++ b/Documentation/git-rev-list.txt
@@ -47,7 +47,9 @@ SYNOPSIS
[ --fixed-strings | -F ]
[ --date=<format>]
[ [ --objects | --objects-edge | --objects-edge-aggressive ]
- [ --unpacked ] ]
+ [ --unpacked ]
+ [ --filter=<filter-spec> [ --filter-print-omitted ] ] ]
+ [ --missing=<missing-action> ]
[ --pretty | --header ]
[ --bisect ]
[ --bisect-vars ]
diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index b63f2ea860..f877f7b7cd 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -170,7 +170,8 @@ This hook cannot affect the outcome of 'git checkout'.
It is also run after 'git clone', unless the --no-checkout (-n) option is
used. The first parameter given to the hook is the null-ref, the second the
-ref of the new HEAD and the flag is always 1.
+ref of the new HEAD and the flag is always 1. Likewise for 'git worktree add'
+unless --no-checkout is used.
This hook can be used to perform repository validity checks, auto-display
differences from the previous HEAD if different, or set working dir metadata
diff --git a/Documentation/gitworkflows.txt b/Documentation/gitworkflows.txt
index 02569d0614..926e044d09 100644
--- a/Documentation/gitworkflows.txt
+++ b/Documentation/gitworkflows.txt
@@ -407,8 +407,8 @@ follows.
`git pull <url> <branch>`
=====================================
-Occasionally, the maintainer may get merge conflicts when he tries to
-pull changes from downstream. In this case, he can ask downstream to
+Occasionally, the maintainer may get merge conflicts when they try to
+pull changes from downstream. In this case, they can ask downstream to
do the merge and resolve the conflicts themselves (perhaps they will
know better how to resolve them). It is one of the rare cases where
downstream 'should' merge from upstream.
diff --git a/Documentation/install-doc-quick.sh b/Documentation/install-doc-quick.sh
index 327f69bcf5..17231d8e59 100755
--- a/Documentation/install-doc-quick.sh
+++ b/Documentation/install-doc-quick.sh
@@ -3,11 +3,12 @@
repository=${1?repository}
destdir=${2?destination}
+GIT_MAN_REF=${3?master}
-head=master GIT_DIR=
+GIT_DIR=
for d in "$repository/.git" "$repository"
do
- if GIT_DIR="$d" git rev-parse refs/heads/master >/dev/null 2>&1
+ if GIT_DIR="$d" git rev-parse "$GIT_MAN_REF" >/dev/null 2>&1
then
GIT_DIR="$d"
export GIT_DIR
@@ -27,12 +28,12 @@ export GIT_INDEX_FILE GIT_WORK_TREE
rm -f "$GIT_INDEX_FILE"
trap 'rm -f "$GIT_INDEX_FILE"' 0
-git read-tree $head
+git read-tree "$GIT_MAN_REF"
git checkout-index -a -f --prefix="$destdir"/
if test -n "$GZ"
then
- git ls-tree -r --name-only $head |
+ git ls-tree -r --name-only "$GIT_MAN_REF" |
xargs printf "$destdir/%s\n" |
xargs gzip -f
fi
diff --git a/Documentation/merge-config.txt b/Documentation/merge-config.txt
index df3ea3779b..12b6bbf591 100644
--- a/Documentation/merge-config.txt
+++ b/Documentation/merge-config.txt
@@ -26,6 +26,10 @@ merge.ff::
allowed (equivalent to giving the `--ff-only` option from the
command line).
+merge.verifySignatures::
+ If true, this is equivalent to the --verify-signatures command
+ line option. See linkgit:git-merge[1] for details.
+
include::fmt-merge-msg-config.txt[]
merge.renameLimit::
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index d433d50f81..e664c088a5 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -204,11 +204,13 @@ endif::git-rev-list[]
than given and there are spaces on its left, use those spaces
- '%><(<N>)', '%><|(<N>)': similar to '% <(<N>)', '%<|(<N>)'
respectively, but padding both sides (i.e. the text is centered)
-- %(trailers): display the trailers of the body as interpreted by
- linkgit:git-interpret-trailers[1]. If the `:only` option is given,
- omit non-trailer lines from the trailer block. If the `:unfold`
- option is given, behave as if interpret-trailer's `--unfold` option
- was given. E.g., `%(trailers:only:unfold)` to do both.
+- %(trailers[:options]): display the trailers of the body as interpreted
+ by linkgit:git-interpret-trailers[1]. The `trailers` string may be
+ followed by a colon and zero or more comma-separated options. If the
+ `only` option is given, omit non-trailer lines from the trailer block.
+ If the `unfold` option is given, behave as if interpret-trailer's
+ `--unfold` option was given. E.g., `%(trailers:only,unfold)` to do
+ both.
NOTE: Some placeholders may depend on other options given to the
revision traversal engine. For example, the `%g*` reflog options will
diff --git a/Documentation/rebase-config.txt b/Documentation/rebase-config.txt
new file mode 100644
index 0000000000..42e1ba7575
--- /dev/null
+++ b/Documentation/rebase-config.txt
@@ -0,0 +1,52 @@
+rebase.stat::
+ Whether to show a diffstat of what changed upstream since the last
+ rebase. False by default.
+
+rebase.autoSquash::
+ If set to true enable `--autosquash` option by default.
+
+rebase.autoStash::
+ When set to true, automatically create a temporary stash entry
+ before the operation begins, and apply it after the operation
+ ends. This means that you can run rebase on a dirty worktree.
+ However, use with care: the final stash application after a
+ successful rebase might result in non-trivial conflicts.
+ This option can be overridden by the `--no-autostash` and
+ `--autostash` options of linkgit:git-rebase[1].
+ Defaults to false.
+
+rebase.missingCommitsCheck::
+ If set to "warn", git rebase -i will print a warning if some
+ commits are removed (e.g. a line was deleted), however the
+ rebase will still proceed. If set to "error", it will print
+ the previous warning and stop the rebase, 'git rebase
+ --edit-todo' can then be used to correct the error. If set to
+ "ignore", no checking is done.
+ To drop a commit without warning or error, use the `drop`
+ command in the todo list.
+ Defaults to "ignore".
+
+rebase.instructionFormat::
+ A format string, as specified in linkgit:git-log[1], to be used for the
+ todo list during an interactive rebase. The format will
+ automatically have the long commit hash prepended to the format.
+
+rebase.abbreviateCommands::
+ If set to true, `git rebase` will use abbreviated command names in the
+ todo list resulting in something like this:
++
+-------------------------------------------
+ p deadbee The oneline of the commit
+ p fa1afe1 The oneline of the next commit
+ ...
+-------------------------------------------
++
+instead of:
++
+-------------------------------------------
+ pick deadbee The oneline of the commit
+ pick fa1afe1 The oneline of the next commit
+ ...
+-------------------------------------------
++
+Defaults to false.
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 13501e1556..22f5c9b43d 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -686,6 +686,11 @@ ifdef::git-rev-list[]
all object IDs which I need to download if I have the commit
object _bar_ but not _foo_''.
+--in-commit-order::
+ Print tree and blob ids in order of the commits. The tree
+ and blob ids are printed after they are first referenced
+ by a commit.
+
--objects-edge::
Similar to `--objects`, but also print the IDs of excluded
commits prefixed with a ``-'' character. This is used by
@@ -706,6 +711,47 @@ ifdef::git-rev-list[]
--unpacked::
Only useful with `--objects`; print the object IDs that are not
in packs.
+
+--filter=<filter-spec>::
+ Only useful with one of the `--objects*`; omits objects (usually
+ blobs) from the list of printed objects. The '<filter-spec>'
+ may be one of the following:
++
+The form '--filter=blob:none' omits all blobs.
++
+The form '--filter=blob:limit=<n>[kmg]' omits blobs larger than n bytes
+or units. n may be zero. The suffixes k, m, and g can be used to name
+units in KiB, MiB, or GiB. For example, 'blob:limit=1k' is the same
+as 'blob:limit=1024'.
++
+The form '--filter=sparse:oid=<blob-ish>' uses a sparse-checkout
+specification contained in the blob (or blob-expression) '<blob-ish>'
+to omit blobs that would not be not required for a sparse checkout on
+the requested refs.
++
+The form '--filter=sparse:path=<path>' similarly uses a sparse-checkout
+specification contained in <path>.
+
+--no-filter::
+ Turn off any previous `--filter=` argument.
+
+--filter-print-omitted::
+ Only useful with `--filter=`; prints a list of the objects omitted
+ by the filter. Object IDs are prefixed with a ``~'' character.
+
+--missing=<missing-action>::
+ A debug option to help with future "partial clone" development.
+ This option specifies how missing objects are handled.
++
+The form '--missing=error' requests that rev-list stop with an error if
+a missing object is encountered. This is the default action.
++
+The form '--missing=allow-any' will allow object traversal to continue
+if a missing object is encountered. Missing objects will silently be
+omitted from the results.
++
+The form '--missing=print' is like 'allow-any', but will also print a
+list of the missing objects. Object IDs are prefixed with a ``?'' character.
endif::git-rev-list[]
--no-walk[=(sorted|unsorted)]::
diff --git a/Documentation/technical/api-decorate.txt b/Documentation/technical/api-decorate.txt
deleted file mode 100644
index 1d52a6ce14..0000000000
--- a/Documentation/technical/api-decorate.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-decorate API
-============
-
-Talk about <decorate.h>
-
-(Linus)
diff --git a/Documentation/technical/partial-clone.txt b/Documentation/technical/partial-clone.txt
new file mode 100644
index 0000000000..0bed2472c8
--- /dev/null
+++ b/Documentation/technical/partial-clone.txt
@@ -0,0 +1,324 @@
+Partial Clone Design Notes
+==========================
+
+The "Partial Clone" feature is a performance optimization for Git that
+allows Git to function without having a complete copy of the repository.
+The goal of this work is to allow Git better handle extremely large
+repositories.
+
+During clone and fetch operations, Git downloads the complete contents
+and history of the repository. This includes all commits, trees, and
+blobs for the complete life of the repository. For extremely large
+repositories, clones can take hours (or days) and consume 100+GiB of disk
+space.
+
+Often in these repositories there are many blobs and trees that the user
+does not need such as:
+
+ 1. files outside of the user's work area in the tree. For example, in
+ a repository with 500K directories and 3.5M files in every commit,
+ we can avoid downloading many objects if the user only needs a
+ narrow "cone" of the source tree.
+
+ 2. large binary assets. For example, in a repository where large build
+ artifacts are checked into the tree, we can avoid downloading all
+ previous versions of these non-mergeable binary assets and only
+ download versions that are actually referenced.
+
+Partial clone allows us to avoid downloading such unneeded objects *in
+advance* during clone and fetch operations and thereby reduce download
+times and disk usage. Missing objects can later be "demand fetched"
+if/when needed.
+
+Use of partial clone requires that the user be online and the origin
+remote be available for on-demand fetching of missing objects. This may
+or may not be problematic for the user. For example, if the user can
+stay within the pre-selected subset of the source tree, they may not
+encounter any missing objects. Alternatively, the user could try to
+pre-fetch various objects if they know that they are going offline.
+
+
+Non-Goals
+---------
+
+Partial clone is a mechanism to limit the number of blobs and trees downloaded
+*within* a given range of commits -- and is therefore independent of and not
+intended to conflict with existing DAG-level mechanisms to limit the set of
+requested commits (i.e. shallow clone, single branch, or fetch '<refspec>').
+
+
+Design Overview
+---------------
+
+Partial clone logically consists of the following parts:
+
+- A mechanism for the client to describe unneeded or unwanted objects to
+ the server.
+
+- A mechanism for the server to omit such unwanted objects from packfiles
+ sent to the client.
+
+- A mechanism for the client to gracefully handle missing objects (that
+ were previously omitted by the server).
+
+- A mechanism for the client to backfill missing objects as needed.
+
+
+Design Details
+--------------
+
+- A new pack-protocol capability "filter" is added to the fetch-pack and
+ upload-pack negotiation.
+
+ This uses the existing capability discovery mechanism.
+ See "filter" in Documentation/technical/pack-protocol.txt.
+
+- Clients pass a "filter-spec" to clone and fetch which is passed to the
+ server to request filtering during packfile construction.
+
+ There are various filters available to accommodate different situations.
+ See "--filter=<filter-spec>" in Documentation/rev-list-options.txt.
+
+- On the server pack-objects applies the requested filter-spec as it
+ creates "filtered" packfiles for the client.
+
+ These filtered packfiles are *incomplete* in the traditional sense because
+ they may contain objects that reference objects not contained in the
+ packfile and that the client doesn't already have. For example, the
+ filtered packfile may contain trees or tags that reference missing blobs
+ or commits that reference missing trees.
+
+- On the client these incomplete packfiles are marked as "promisor packfiles"
+ and treated differently by various commands.
+
+- On the client a repository extension is added to the local config to
+ prevent older versions of git from failing mid-operation because of
+ missing objects that they cannot handle.
+ See "extensions.partialClone" in Documentation/technical/repository-version.txt"
+
+
+Handling Missing Objects
+------------------------
+
+- An object may be missing due to a partial clone or fetch, or missing due
+ to repository corruption. To differentiate these cases, the local
+ repository specially indicates such filtered packfiles obtained from the
+ promisor remote as "promisor packfiles".
+
+ These promisor packfiles consist of a "<name>.promisor" file with
+ arbitrary contents (like the "<name>.keep" files), in addition to
+ their "<name>.pack" and "<name>.idx" files.
+
+- The local repository considers a "promisor object" to be an object that
+ it knows (to the best of its ability) that the promisor remote has promised
+ that it has, either because the local repository has that object in one of
+ its promisor packfiles, or because another promisor object refers to it.
+
+ When Git encounters a missing object, Git can see if it a promisor object
+ and handle it appropriately. If not, Git can report a corruption.
+
+ This means that there is no need for the client to explicitly maintain an
+ expensive-to-modify list of missing objects.[a]
+
+- Since almost all Git code currently expects any referenced object to be
+ present locally and because we do not want to force every command to do
+ a dry-run first, a fallback mechanism is added to allow Git to attempt
+ to dynamically fetch missing objects from the promisor remote.
+
+ When the normal object lookup fails to find an object, Git invokes
+ fetch-object to try to get the object from the server and then retry
+ the object lookup. This allows objects to be "faulted in" without
+ complicated prediction algorithms.
+
+ For efficiency reasons, no check as to whether the missing object is
+ actually a promisor object is performed.
+
+ Dynamic object fetching tends to be slow as objects are fetched one at
+ a time.
+
+- `checkout` (and any other command using `unpack-trees`) has been taught
+ to bulk pre-fetch all required missing blobs in a single batch.
+
+- `rev-list` has been taught to print missing objects.
+
+ This can be used by other commands to bulk prefetch objects.
+ For example, a "git log -p A..B" may internally want to first do
+ something like "git rev-list --objects --quiet --missing=print A..B"
+ and prefetch those objects in bulk.
+
+- `fsck` has been updated to be fully aware of promisor objects.
+
+- `repack` in GC has been updated to not touch promisor packfiles at all,
+ and to only repack other objects.
+
+- The global variable "fetch_if_missing" is used to control whether an
+ object lookup will attempt to dynamically fetch a missing object or
+ report an error.
+
+ We are not happy with this global variable and would like to remove it,
+ but that requires significant refactoring of the object code to pass an
+ additional flag. We hope that concurrent efforts to add an ODB API can
+ encompass this.
+
+
+Fetching Missing Objects
+------------------------
+
+- Fetching of objects is done using the existing transport mechanism using
+ transport_fetch_refs(), setting a new transport option
+ TRANS_OPT_NO_DEPENDENTS to indicate that only the objects themselves are
+ desired, not any object that they refer to.
+
+ Because some transports invoke fetch_pack() in the same process, fetch_pack()
+ has been updated to not use any object flags when the corresponding argument
+ (no_dependents) is set.
+
+- The local repository sends a request with the hashes of all requested
+ objects as "want" lines, and does not perform any packfile negotiation.
+ It then receives a packfile.
+
+- Because we are reusing the existing fetch-pack mechanism, fetching
+ currently fetches all objects referred to by the requested objects, even
+ though they are not necessary.
+
+
+Current Limitations
+-------------------
+
+- The remote used for a partial clone (or the first partial fetch
+ following a regular clone) is marked as the "promisor remote".
+
+ We are currently limited to a single promisor remote and only that
+ remote may be used for subsequent partial fetches.
+
+ We accept this limitation because we believe initial users of this
+ feature will be using it on repositories with a strong single central
+ server.
+
+- Dynamic object fetching will only ask the promisor remote for missing
+ objects. We assume that the promisor remote has a complete view of the
+ repository and can satisfy all such requests.
+
+- Repack essentially treats promisor and non-promisor packfiles as 2
+ distinct partitions and does not mix them. Repack currently only works
+ on non-promisor packfiles and loose objects.
+
+- Dynamic object fetching invokes fetch-pack once *for each item*
+ because most algorithms stumble upon a missing object and need to have
+ it resolved before continuing their work. This may incur significant
+ overhead -- and multiple authentication requests -- if many objects are
+ needed.
+
+- Dynamic object fetching currently uses the existing pack protocol V0
+ which means that each object is requested via fetch-pack. The server
+ will send a full set of info/refs when the connection is established.
+ If there are large number of refs, this may incur significant overhead.
+
+
+Future Work
+-----------
+
+- Allow more than one promisor remote and define a strategy for fetching
+ missing objects from specific promisor remotes or of iterating over the
+ set of promisor remotes until a missing object is found.
+
+ A user might want to have multiple geographically-close cache servers
+ for fetching missing blobs while continuing to do filtered `git-fetch`
+ commands from the central server, for example.
+
+ Or the user might want to work in a triangular work flow with multiple
+ promisor remotes that each have an incomplete view of the repository.
+
+- Allow repack to work on promisor packfiles (while keeping them distinct
+ from non-promisor packfiles).
+
+- Allow non-pathname-based filters to make use of packfile bitmaps (when
+ present). This was just an omission during the initial implementation.
+
+- Investigate use of a long-running process to dynamically fetch a series
+ of objects, such as proposed in [5,6] to reduce process startup and
+ overhead costs.
+
+ It would be nice if pack protocol V2 could allow that long-running
+ process to make a series of requests over a single long-running
+ connection.
+
+- Investigate pack protocol V2 to avoid the info/refs broadcast on
+ each connection with the server to dynamically fetch missing objects.
+
+- Investigate the need to handle loose promisor objects.
+
+ Objects in promisor packfiles are allowed to reference missing objects
+ that can be dynamically fetched from the server. An assumption was
+ made that loose objects are only created locally and therefore should
+ not reference a missing object. We may need to revisit that assumption
+ if, for example, we dynamically fetch a missing tree and store it as a
+ loose object rather than a single object packfile.
+
+ This does not necessarily mean we need to mark loose objects as promisor;
+ it may be sufficient to relax the object lookup or is-promisor functions.
+
+
+Non-Tasks
+---------
+
+- Every time the subject of "demand loading blobs" comes up it seems
+ that someone suggests that the server be allowed to "guess" and send
+ additional objects that may be related to the requested objects.
+
+ No work has gone into actually doing that; we're just documenting that
+ it is a common suggestion. We're not sure how it would work and have
+ no plans to work on it.
+
+ It is valid for the server to send more objects than requested (even
+ for a dynamic object fetch), but we are not building on that.
+
+
+Footnotes
+---------
+
+[a] expensive-to-modify list of missing objects: Earlier in the design of
+ partial clone we discussed the need for a single list of missing objects.
+ This would essentially be a sorted linear list of OIDs that the were
+ omitted by the server during a clone or subsequent fetches.
+
+ This file would need to be loaded into memory on every object lookup.
+ It would need to be read, updated, and re-written (like the .git/index)
+ on every explicit "git fetch" command *and* on any dynamic object fetch.
+
+ The cost to read, update, and write this file could add significant
+ overhead to every command if there are many missing objects. For example,
+ if there are 100M missing blobs, this file would be at least 2GiB on disk.
+
+ With the "promisor" concept, we *infer* a missing object based upon the
+ type of packfile that references it.
+
+
+Related Links
+-------------
+[0] https://bugs.chromium.org/p/git/issues/detail?id=2
+ Chromium work item for: Partial Clone
+
+[1] https://public-inbox.org/git/20170113155253.1644-1-benpeart@microsoft.com/
+ Subject: [RFC] Add support for downloading blobs on demand
+ Date: Fri, 13 Jan 2017 10:52:53 -0500
+
+[2] https://public-inbox.org/git/cover.1506714999.git.jonathantanmy@google.com/
+ Subject: [PATCH 00/18] Partial clone (from clone to lazy fetch in 18 patches)
+ Date: Fri, 29 Sep 2017 13:11:36 -0700
+
+[3] https://public-inbox.org/git/20170426221346.25337-1-jonathantanmy@google.com/
+ Subject: Proposal for missing blob support in Git repos
+ Date: Wed, 26 Apr 2017 15:13:46 -0700
+
+[4] https://public-inbox.org/git/1488999039-37631-1-git-send-email-git@jeffhostetler.com/
+ Subject: [PATCH 00/10] RFC Partial Clone and Fetch
+ Date: Wed, 8 Mar 2017 18:50:29 +0000
+
+[5] https://public-inbox.org/git/20170505152802.6724-1-benpeart@microsoft.com/
+ Subject: [PATCH v7 00/10] refactor the filter process code into a reusable module
+ Date: Fri, 5 May 2017 11:27:52 -0400
+
+[6] https://public-inbox.org/git/20170714132651.170708-1-benpeart@microsoft.com/
+ Subject: [RFC/PATCH v2 0/1] Add support for downloading blobs on demand
+ Date: Fri, 14 Jul 2017 09:26:50 -0400
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index c1906f0fd1..4eba7701a0 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,7 +1,7 @@
#!/bin/sh
GVF=GIT-VERSION-FILE
-DEF_VER=v2.15.GIT
+DEF_VER=v2.16.0-rc0
LF='
'
diff --git a/Makefile b/Makefile
index 9dc5a588e2..bb5b7cdfb6 100644
--- a/Makefile
+++ b/Makefile
@@ -425,6 +425,13 @@ all::
#
# to say "export LESS=FRX (and LV=-c) if the environment variable
# LESS (and LV) is not set, respectively".
+#
+# Define TEST_SHELL_PATH if you want to use a shell besides SHELL_PATH for
+# running the test scripts (e.g., bash has better support for "set -x"
+# tracing).
+#
+# When cross-compiling, define HOST_CPU as the canonical name of the CPU on
+# which the built Git will run (for instance "x86_64").
GIT-VERSION-FILE: FORCE
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -651,6 +658,7 @@ TEST_PROGRAMS_NEED_X += test-dump-cache-tree
TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
TEST_PROGRAMS_NEED_X += test-dump-split-index
TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
+TEST_PROGRAMS_NEED_X += test-example-decorate
TEST_PROGRAMS_NEED_X += test-fake-ssh
TEST_PROGRAMS_NEED_X += test-genrandom
TEST_PROGRAMS_NEED_X += test-hashmap
@@ -729,6 +737,8 @@ endif
export PERL_PATH
export PYTHON_PATH
+TEST_SHELL_PATH = $(SHELL_PATH)
+
LIB_FILE = libgit.a
XDIFF_LIB = xdiff/lib.a
VCSSVN_LIB = vcs-svn/lib.a
@@ -811,6 +821,8 @@ LIB_OBJS += levenshtein.o
LIB_OBJS += line-log.o
LIB_OBJS += line-range.o
LIB_OBJS += list-objects.o
+LIB_OBJS += list-objects-filter.o
+LIB_OBJS += list-objects-filter-options.o
LIB_OBJS += ll-merge.o
LIB_OBJS += lockfile.o
LIB_OBJS += log-tree.o
@@ -1096,6 +1108,12 @@ else
BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
endif
+ifeq (,$(HOST_CPU))
+ BASIC_CFLAGS += -DGIT_HOST_CPU="\"$(firstword $(subst -, ,$(uname_M)))\""
+else
+ BASIC_CFLAGS += -DGIT_HOST_CPU="\"$(HOST_CPU)\""
+endif
+
ifneq (,$(INLINE))
BASIC_CFLAGS += -Dinline=$(INLINE)
endif
@@ -1726,6 +1744,7 @@ prefix_SQ = $(subst ','\'',$(prefix))
gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
+TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
@@ -1894,7 +1913,9 @@ builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
version.sp version.s version.o: EXTRA_CPPFLAGS = \
'-DGIT_VERSION="$(GIT_VERSION)"' \
- '-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)'
+ '-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)' \
+ '-DGIT_BUILT_FROM_COMMIT="$(shell GIT_CEILING_DIRECTORIES=\"$(CURDIR)/..\" \
+ git rev-parse -q --verify HEAD || :)"'
$(BUILT_INS): git$X
$(QUIET_BUILT_IN)$(RM) $@ && \
@@ -2356,6 +2377,7 @@ GIT-LDFLAGS: FORCE
# and the first level quoting from the shell that runs "echo".
GIT-BUILD-OPTIONS: FORCE
@echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@+
+ @echo TEST_SHELL_PATH=\''$(subst ','\'',$(TEST_SHELL_PATH_SQ))'\' >>$@+
@echo PERL_PATH=\''$(subst ','\'',$(PERL_PATH_SQ))'\' >>$@+
@echo DIFF=\''$(subst ','\'',$(subst ','\'',$(DIFF)))'\' >>$@+
@echo PYTHON_PATH=\''$(subst ','\'',$(PYTHON_PATH_SQ))'\' >>$@+
diff --git a/branch.c b/branch.c
index fe1e1c3676..2672054f0b 100644
--- a/branch.c
+++ b/branch.c
@@ -244,7 +244,7 @@ N_("\n"
"\"git push -u\" to set the upstream config as you push.");
void create_branch(const char *name, const char *start_name,
- int force, int reflog, int clobber_head,
+ int force, int clobber_head_ok, int reflog,
int quiet, enum branch_track track)
{
struct commit *commit;
@@ -258,7 +258,7 @@ void create_branch(const char *name, const char *start_name,
if (track == BRANCH_TRACK_EXPLICIT || track == BRANCH_TRACK_OVERRIDE)
explicit_tracking = 1;
- if ((track == BRANCH_TRACK_OVERRIDE || clobber_head)
+ if ((track == BRANCH_TRACK_OVERRIDE || clobber_head_ok)
? validate_branchname(name, &ref)
: validate_new_branchname(name, &ref, force)) {
if (!force)
diff --git a/branch.h b/branch.h
index be5e5d1308..473d0a93e9 100644
--- a/branch.h
+++ b/branch.h
@@ -13,14 +13,20 @@
*
* - force enables overwriting an existing (non-head) branch
*
+ * - clobber_head_ok allows the currently checked out (hence existing)
+ * branch to be overwritten; without 'force', it has no effect.
+ *
* - reflog creates a reflog for the branch
*
+ * - quiet suppresses tracking information
+ *
* - track causes the new branch to be configured to merge the remote branch
* that start_name is a tracking branch for (if any).
+ *
*/
void create_branch(const char *name, const char *start_name,
- int force, int reflog,
- int clobber_head, int quiet, enum branch_track track);
+ int force, int clobber_head_ok,
+ int reflog, int quiet, enum branch_track track);
/*
* Check if 'name' can be a valid name for a branch; die otherwise.
diff --git a/builtin/am.c b/builtin/am.c
index a02d5186cb..acfe9d3c8c 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -708,6 +708,7 @@ static int split_mail_mbox(struct am_state *state, const char **paths,
{
struct child_process cp = CHILD_PROCESS_INIT;
struct strbuf last = STRBUF_INIT;
+ int ret;
cp.git_cmd = 1;
argv_array_push(&cp.args, "mailsplit");
@@ -721,13 +722,16 @@ static int split_mail_mbox(struct am_state *state, const char **paths,
argv_array_push(&cp.args, "--");
argv_array_pushv(&cp.args, paths);
- if (capture_command(&cp, &last, 8))
- return -1;
+ ret = capture_command(&cp, &last, 8);
+ if (ret)
+ goto exit;
state->cur = 1;
state->last = strtol(last.buf, NULL, 10);
- return 0;
+exit:
+ strbuf_release(&last);
+ return ret ? -1 : 0;
}
/**
diff --git a/builtin/branch.c b/builtin/branch.c
index af95ad2192..8dcc2ed058 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -462,6 +462,8 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
{
struct strbuf oldref = STRBUF_INIT, newref = STRBUF_INIT, logmsg = STRBUF_INIT;
struct strbuf oldsection = STRBUF_INIT, newsection = STRBUF_INIT;
+ const char *interpreted_oldname = NULL;
+ const char *interpreted_newname = NULL;
int recovery = 0;
if (!oldname) {
@@ -493,6 +495,11 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
reject_rebase_or_bisect_branch(oldref.buf);
+ if (!skip_prefix(oldref.buf, "refs/heads/", &interpreted_oldname) ||
+ !skip_prefix(newref.buf, "refs/heads/", &interpreted_newname)) {
+ die("BUG: expected prefix missing for refs");
+ }
+
if (copy)
strbuf_addf(&logmsg, "Branch: copied %s to %s",
oldref.buf, newref.buf);
@@ -507,11 +514,11 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
if (recovery) {
if (copy)
- warning(_("Copied a misnamed branch '%s' away"),
- oldref.buf + 11);
+ warning(_("Created a copy of a misnamed branch '%s'"),
+ interpreted_oldname);
else
warning(_("Renamed a misnamed branch '%s' away"),
- oldref.buf + 11);
+ interpreted_oldname);
}
if (!copy &&
@@ -520,9 +527,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
strbuf_release(&logmsg);
- strbuf_addf(&oldsection, "branch.%s", oldref.buf + 11);
+ strbuf_addf(&oldsection, "branch.%s", interpreted_oldname);
strbuf_release(&oldref);
- strbuf_addf(&newsection, "branch.%s", newref.buf + 11);
+ strbuf_addf(&newsection, "branch.%s", interpreted_newname);
strbuf_release(&newref);
if (!copy && git_config_rename_section(oldsection.buf, newsection.buf) < 0)
die(_("Branch is renamed, but update of config-file failed"));
@@ -806,7 +813,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead."));
create_branch(argv[0], (argc == 2) ? argv[1] : head,
- force, reflog, 0, quiet, track);
+ force, 0, reflog, quiet, track);
} else
usage_with_options(builtin_branch_usage, options);
diff --git a/builtin/checkout.c b/builtin/checkout.c
index f9f3797e11..8bdc927d3f 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -647,8 +647,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
else
create_branch(opts->new_branch, new->name,
opts->new_branch_force ? 1 : 0,
- opts->new_branch_log,
opts->new_branch_force ? 1 : 0,
+ opts->new_branch_log,
opts->quiet,
opts->track);
new->name = opts->new_branch;
diff --git a/builtin/clone.c b/builtin/clone.c
index b22845738a..2da71db107 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -452,7 +452,8 @@ static void clone_local(const char *src_repo, const char *dest_repo)
{
if (option_shared) {
struct strbuf alt = STRBUF_INIT;
- strbuf_addf(&alt, "%s/objects", src_repo);
+ get_common_dir(&alt, src_repo);
+ strbuf_addstr(&alt, "/objects");
add_to_alternates_file(alt.buf);
strbuf_release(&alt);
} else {
@@ -1082,9 +1083,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
warning(_("--local is ignored"));
transport->cloning = 1;
- if (!transport->get_refs_list || (!is_local && !transport->fetch))
- die(_("Don't know how to clone %s"), transport->url);
-
transport_set_option(transport, TRANS_OPT_KEEP, "yes");
if (option_depth)
diff --git a/builtin/describe.c b/builtin/describe.c
index e14e162ef6..3b0b204b1e 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -3,6 +3,7 @@
#include "lockfile.h"
#include "commit.h"
#include "tag.h"
+#include "blob.h"
#include "refs.h"
#include "builtin.h"
#include "exec_cmd.h"
@@ -12,6 +13,8 @@
#include "hashmap.h"
#include "argv-array.h"
#include "run-command.h"
+#include "revision.h"
+#include "list-objects.h"
#define MAX_TAGS (FLAG_BITS - 1)
@@ -256,7 +259,7 @@ static unsigned long finish_depth_computation(
return seen_commits;
}
-static void display_name(struct commit_name *n)
+static void append_name(struct commit_name *n, struct strbuf *dst)
{
if (n->prio == 2 && !n->tag) {
n->tag = lookup_tag(&n->oid);
@@ -272,19 +275,18 @@ static void display_name(struct commit_name *n)
}
if (n->tag)
- printf("%s", n->tag->tag);
+ strbuf_addstr(dst, n->tag->tag);
else
- printf("%s", n->path);
+ strbuf_addstr(dst, n->path);
}
-static void show_suffix(int depth, const struct object_id *oid)
+static void append_suffix(int depth, const struct object_id *oid, struct strbuf *dst)
{
- printf("-%d-g%s", depth, find_unique_abbrev(oid->hash, abbrev));
+ strbuf_addf(dst, "-%d-g%s", depth, find_unique_abbrev(oid->hash, abbrev));
}
-static void describe(const char *arg, int last_one)
+static void describe_commit(struct object_id *oid, struct strbuf *dst)
{
- struct object_id oid;
struct commit *cmit, *gave_up_on = NULL;
struct commit_list *list;
struct commit_name *n;
@@ -293,30 +295,25 @@ static void describe(const char *arg, int last_one)
unsigned long seen_commits = 0;
unsigned int unannotated_cnt = 0;
- if (get_oid(arg, &oid))
- die(_("Not a valid object name %s"), arg);
- cmit = lookup_commit_reference(&oid);
- if (!cmit)
- die(_("%s is not a valid '%s' object"), arg, commit_type);
+ cmit = lookup_commit_reference(oid);
n = find_commit_name(&cmit->object.oid);
if (n && (tags || all || n->prio == 2)) {
/*
* Exact match to an existing ref.
*/
- display_name(n);
+ append_name(n, dst);
if (longformat)
- show_suffix(0, n->tag ? &n->tag->tagged->oid : &oid);
+ append_suffix(0, n->tag ? &n->tag->tagged->oid : oid, dst);
if (suffix)
- printf("%s", suffix);
- printf("\n");
+ strbuf_addstr(dst, suffix);
return;
}
if (!max_candidates)
die(_("no tag exactly matches '%s'"), oid_to_hex(&cmit->object.oid));
if (debug)
- fprintf(stderr, _("searching to describe %s\n"), arg);
+ fprintf(stderr, _("No exact match on refs or tags, searching to describe\n"));
if (!have_util) {
struct hashmap_iter iter;
@@ -381,22 +378,21 @@ static void describe(const char *arg, int last_one)
}
if (!match_cnt) {
- struct object_id *oid = &cmit->object.oid;
+ struct object_id *cmit_oid = &cmit->object.oid;
if (always) {
- printf("%s", find_unique_abbrev(oid->hash, abbrev));
+ strbuf_addstr(dst, find_unique_abbrev(cmit_oid->hash, abbrev));
if (suffix)
- printf("%s", suffix);
- printf("\n");
+ strbuf_addstr(dst, suffix);
return;
}
if (unannotated_cnt)
die(_("No annotated tags can describe '%s'.\n"
"However, there were unannotated tags: try --tags."),
- oid_to_hex(oid));
+ oid_to_hex(cmit_oid));
else
die(_("No tags can describe '%s'.\n"
"Try --always, or create some tags."),
- oid_to_hex(oid));
+ oid_to_hex(cmit_oid));
}
QSORT(all_matches, match_cnt, compare_pt);
@@ -434,15 +430,86 @@ static void describe(const char *arg, int last_one)
}
}
- display_name(all_matches[0].name);
+ append_name(all_matches[0].name, dst);
if (abbrev)
- show_suffix(all_matches[0].depth, &cmit->object.oid);
+ append_suffix(all_matches[0].depth, &cmit->object.oid, dst);
if (suffix)
- printf("%s", suffix);
- printf("\n");
+ strbuf_addstr(dst, suffix);
+}
+
+struct process_commit_data {
+ struct object_id current_commit;
+ struct object_id looking_for;
+ struct strbuf *dst;
+ struct rev_info *revs;
+};
+
+static void process_commit(struct commit *commit, void *data)
+{
+ struct process_commit_data *pcd = data;
+ pcd->current_commit = commit->object.oid;
+}
+
+static void process_object(struct object *obj, const char *path, void *data)
+{
+ struct process_commit_data *pcd = data;
+
+ if (!oidcmp(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {
+ reset_revision_walk();
+ describe_commit(&pcd->current_commit, pcd->dst);
+ strbuf_addf(pcd->dst, ":%s", path);
+ free_commit_list(pcd->revs->commits);
+ pcd->revs->commits = NULL;
+ }
+}
+
+static void describe_blob(struct object_id oid, struct strbuf *dst)
+{
+ struct rev_info revs;
+ struct argv_array args = ARGV_ARRAY_INIT;
+ struct process_commit_data pcd = { null_oid, oid, dst, &revs};
+
+ argv_array_pushl(&args, "internal: The first arg is not parsed",
+ "--objects", "--in-commit-order", "--reverse", "HEAD",
+ NULL);
+
+ init_revisions(&revs, NULL);
+ if (setup_revisions(args.argc, args.argv, &revs, NULL) > 1)
+ BUG("setup_revisions could not handle all args?");
+
+ if (prepare_revision_walk(&revs))
+ die("revision walk setup failed");
+
+ traverse_commit_list(&revs, process_commit, process_object, &pcd);
+ reset_revision_walk();
+}
+
+static void describe(const char *arg, int last_one)
+{
+ struct object_id oid;
+ struct commit *cmit;
+ struct strbuf sb = STRBUF_INIT;
+
+ if (debug)
+ fprintf(stderr, _("describe %s\n"), arg);
+
+ if (get_oid(arg, &oid))
+ die(_("Not a valid object name %s"), arg);
+ cmit = lookup_commit_reference_gently(&oid, 1);
+
+ if (cmit)
+ describe_commit(&oid, &sb);
+ else if (lookup_blob(&oid))
+ describe_blob(oid, &sb);
+ else
+ die(_("%s is neither a commit nor blob"), arg);
+
+ puts(sb.buf);
if (!last_one)
clear_commit_marks(cmit, -1);
+
+ strbuf_release(&sb);
}
int cmd_describe(int argc, const char **argv, const char *prefix)
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index f8fe04ca53..796d0cd66c 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -895,7 +895,7 @@ static void export_marks(char *file)
{
unsigned int i;
uint32_t mark;
- struct object_decoration *deco = idnums.hash;
+ struct decoration_entry *deco = idnums.entries;
FILE *f;
int e = 0;
diff --git a/builtin/fetch.c b/builtin/fetch.c
index e705237fa9..7bbcd26faf 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -3,6 +3,7 @@
*/
#include "cache.h"
#include "config.h"
+#include "repository.h"
#include "refs.h"
#include "commit.h"
#include "builtin.h"
@@ -1094,9 +1095,6 @@ static int do_fetch(struct transport *transport,
tags = TAGS_UNSET;
}
- if (!transport->get_refs_list || !transport->fetch)
- die(_("Don't know how to fetch from %s"), transport->url);
-
/* if not appending, truncate FETCH_HEAD */
if (!append && !dry_run) {
retcode = truncate_fetch_head();
@@ -1397,7 +1395,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
struct argv_array options = ARGV_ARRAY_INIT;
add_options_to_argv(&options);
- result = fetch_populated_submodules(&options,
+ result = fetch_populated_submodules(the_repository,
+ &options,
submodule_prefix,
recurse_submodules,
recurse_submodules_default,
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 22034f87e7..8e8a15ea4a 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -377,7 +377,8 @@ static void shortlog(const char *name,
string_list_append(&subjects,
oid_to_hex(&commit->object.oid));
else
- string_list_append(&subjects, strbuf_detach(&sb, NULL));
+ string_list_append_nodup(&subjects,
+ strbuf_detach(&sb, NULL));
}
if (opts->credit_people)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 8ec459f522..4c51aec81f 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1660,10 +1660,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
from_stdin = 1;
} else if (!strcmp(arg, "--fix-thin")) {
fix_thin_pack = 1;
- } else if (!strcmp(arg, "--strict")) {
- strict = 1;
- do_fsck_object = 1;
- } else if (skip_prefix(arg, "--strict=", &arg)) {
+ } else if (skip_to_optional_arg(arg, "--strict", &arg)) {
strict = 1;
do_fsck_object = 1;
fsck_set_msg_types(&fsck_options, arg);
@@ -1679,10 +1676,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
verify = 1;
show_stat = 1;
stat_only = 1;
- } else if (!strcmp(arg, "--keep")) {
- keep_msg = "";
- } else if (starts_with(arg, "--keep=")) {
- keep_msg = arg + 7;
+ } else if (skip_to_optional_arg(arg, "--keep", &keep_msg)) {
+ ; /* nothing to do */
} else if (starts_with(arg, "--threads=")) {
char *end;
nr_threads = strtoul(arg+10, &end, 0);
diff --git a/builtin/merge.c b/builtin/merge.c
index 612dd7bfb6..30264cfd7c 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -567,6 +567,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
show_diffstat = git_config_bool(k, v);
+ else if (!strcmp(k, "merge.verifysignatures"))
+ verify_signatures = git_config_bool(k, v);
else if (!strcmp(k, "pull.twohead"))
return git_config_string(&pull_twohead, k, v);
else if (!strcmp(k, "pull.octopus"))
diff --git a/builtin/mv.c b/builtin/mv.c
index ffdd5f01a1..cf3684d907 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -291,7 +291,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
}
if (gitmodules_modified)
- stage_updated_gitmodules();
+ stage_updated_gitmodules(&the_index);
if (active_cache_changed &&
write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
diff --git a/builtin/notes.c b/builtin/notes.c
index 1a2c7d92ad..7c81761645 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -12,7 +12,7 @@
#include "builtin.h"
#include "notes.h"
#include "blob.h"
-#include "commit.h"
+#include "pretty.h"
#include "refs.h"
#include "exec_cmd.h"
#include "run-command.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 631de28761..6b9cfc289d 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -15,6 +15,8 @@
#include "diff.h"
#include "revision.h"
#include "list-objects.h"
+#include "list-objects-filter.h"
+#include "list-objects-filter-options.h"
#include "pack-objects.h"
#include "progress.h"
#include "refs.h"
@@ -79,6 +81,15 @@ static unsigned long cache_max_small_delta_size = 1000;
static unsigned long window_memory_limit = 0;
+static struct list_objects_filter_options filter_options;
+
+enum missing_action {
+ MA_ERROR = 0, /* fail if any missing objects are encountered */
+ MA_ALLOW_ANY, /* silently allow ALL missing objects */
+};
+static enum missing_action arg_missing_action;
+static show_object_fn fn_show_object;
+
/*
* stats
*/
@@ -2553,6 +2564,42 @@ static void show_object(struct object *obj, const char *name, void *data)
obj->flags |= OBJECT_ADDED;
}
+static void show_object__ma_allow_any(struct object *obj, const char *name, void *data)
+{
+ assert(arg_missing_action == MA_ALLOW_ANY);
+
+ /*
+ * Quietly ignore ALL missing objects. This avoids problems with
+ * staging them now and getting an odd error later.
+ */
+ if (!has_object_file(&obj->oid))
+ return;
+
+ show_object(obj, name, data);
+}
+
+static int option_parse_missing_action(const struct option *opt,
+ const char *arg, int unset)
+{
+ assert(arg);
+ assert(!unset);
+
+ if (!strcmp(arg, "error")) {
+ arg_missing_action = MA_ERROR;
+ fn_show_object = show_object;
+ return 0;
+ }
+
+ if (!strcmp(arg, "allow-any")) {
+ arg_missing_action = MA_ALLOW_ANY;
+ fn_show_object = show_object__ma_allow_any;
+ return 0;
+ }
+
+ die(_("invalid value for --missing"));
+ return 0;
+}
+
static void show_edge(struct commit *commit)
{
add_preferred_base(&commit->object.oid);
@@ -2817,7 +2864,12 @@ static void get_object_list(int ac, const char **av)
if (prepare_revision_walk(&revs))
die("revision walk setup failed");
mark_edges_uninteresting(&revs, show_edge);
- traverse_commit_list(&revs, show_commit, show_object, NULL);
+
+ if (!fn_show_object)
+ fn_show_object = show_object;
+ traverse_commit_list_filtered(&filter_options, &revs,
+ show_commit, fn_show_object, NULL,
+ NULL);
if (unpack_unreachable_expiration) {
revs.ignore_missing_links = 1;
@@ -2953,6 +3005,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
N_("use a bitmap index if available to speed up counting objects")),
OPT_BOOL(0, "write-bitmap-index", &write_bitmap_index,
N_("write a bitmap index together with the pack index")),
+ OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
+ { OPTION_CALLBACK, 0, "missing", NULL, N_("action"),
+ N_("handling for missing objects"), PARSE_OPT_NONEG,
+ option_parse_missing_action },
OPT_END(),
};
@@ -3029,6 +3085,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
if (!rev_list_all || !rev_list_reflog || !rev_list_index)
unpack_unreachable_expiration = 0;
+ if (filter_options.choice) {
+ if (!pack_to_stdout)
+ die("cannot use --filter without --stdout.");
+ use_bitmap_index = 0;
+ }
+
/*
* "soft" reasons not to use bitmaps - for on-disk repack by default we want
*
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c
index f8519363a3..7daee544b7 100644
--- a/builtin/rebase--helper.c
+++ b/builtin/rebase--helper.c
@@ -12,10 +12,12 @@ static const char * const builtin_rebase_helper_usage[] = {
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
{
struct replay_opts opts = REPLAY_OPTS_INIT;
- int keep_empty = 0;
+ unsigned flags = 0, keep_empty = 0;
+ int abbreviate_commands = 0;
enum {
- CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_SHA1S, EXPAND_SHA1S,
- CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH
+ CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
+ CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
+ ADD_EXEC
} command = 0;
struct option options[] = {
OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
@@ -27,19 +29,22 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
OPT_CMDMODE(0, "make-script", &command,
N_("make rebase script"), MAKE_SCRIPT),
OPT_CMDMODE(0, "shorten-ids", &command,
- N_("shorten SHA-1s in the todo list"), SHORTEN_SHA1S),
+ N_("shorten commit ids in the todo list"), SHORTEN_OIDS),
OPT_CMDMODE(0, "expand-ids", &command,
- N_("expand SHA-1s in the todo list"), EXPAND_SHA1S),
+ N_("expand commit ids in the todo list"), EXPAND_OIDS),
OPT_CMDMODE(0, "check-todo-list", &command,
N_("check the todo list"), CHECK_TODO_LIST),
OPT_CMDMODE(0, "skip-unnecessary-picks", &command,
N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS),
OPT_CMDMODE(0, "rearrange-squash", &command,
N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
+ OPT_CMDMODE(0, "add-exec-commands", &command,
+ N_("insert exec commands in todo list"), ADD_EXEC),
OPT_END()
};
git_config(git_default_config, NULL);
+ git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands);
opts.action = REPLAY_INTERACTIVE_REBASE;
opts.allow_ff = 1;
@@ -48,21 +53,25 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, NULL, options,
builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
+ flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
+ flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
+ flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
+
if (command == CONTINUE && argc == 1)
return !!sequencer_continue(&opts);
if (command == ABORT && argc == 1)
return !!sequencer_remove_state(&opts);
if (command == MAKE_SCRIPT && argc > 1)
- return !!sequencer_make_script(keep_empty, stdout, argc, argv);
- if (command == SHORTEN_SHA1S && argc == 1)
- return !!transform_todo_ids(1);
- if (command == EXPAND_SHA1S && argc == 1)
- return !!transform_todo_ids(0);
+ return !!sequencer_make_script(stdout, argc, argv, flags);
+ if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)
+ return !!transform_todos(flags);
if (command == CHECK_TODO_LIST && argc == 1)
return !!check_todo_list();
if (command == SKIP_UNNECESSARY_PICKS && argc == 1)
return !!skip_unnecessary_picks();
if (command == REARRANGE_SQUASH && argc == 1)
return !!rearrange_squash();
+ if (command == ADD_EXEC && argc == 2)
+ return !!sequencer_add_exec_commands(argv[1]);
usage_with_options(builtin_rebase_helper_usage, options);
}
diff --git a/builtin/reset.c b/builtin/reset.c
index 906e541658..e15f595799 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -12,7 +12,7 @@
#include "lockfile.h"
#include "tag.h"
#include "object.h"
-#include "commit.h"
+#include "pretty.h"
#include "run-command.h"
#include "refs.h"
#include "diff.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 4032eb3811..d5345b6a2e 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -4,6 +4,8 @@
#include "diff.h"
#include "revision.h"
#include "list-objects.h"
+#include "list-objects-filter.h"
+#include "list-objects-filter-options.h"
#include "pack.h"
#include "pack-bitmap.h"
#include "builtin.h"
@@ -12,6 +14,7 @@
#include "bisect.h"
#include "progress.h"
#include "reflog-walk.h"
+#include "oidset.h"
static const char rev_list_usage[] =
"git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@ -55,6 +58,20 @@ static const char rev_list_usage[] =
static struct progress *progress;
static unsigned progress_counter;
+static struct list_objects_filter_options filter_options;
+static struct oidset omitted_objects;
+static int arg_print_omitted; /* print objects omitted by filter */
+
+static struct oidset missing_objects;
+enum missing_action {
+ MA_ERROR = 0, /* fail if any missing objects are encountered */
+ MA_ALLOW_ANY, /* silently allow ALL missing objects */
+ MA_PRINT, /* print ALL missing objects in special section */
+};
+static enum missing_action arg_missing_action;
+
+#define DEFAULT_OIDSET_SIZE (16*1024)
+
static void finish_commit(struct commit *commit, void *data);
static void show_commit(struct commit *commit, void *data)
{
@@ -178,11 +195,31 @@ static void finish_commit(struct commit *commit, void *data)
free_commit_buffer(commit);
}
+static inline void finish_object__ma(struct object *obj)
+{
+ switch (arg_missing_action) {
+ case MA_ERROR:
+ die("missing blob object '%s'", oid_to_hex(&obj->oid));
+ return;
+
+ case MA_ALLOW_ANY:
+ return;
+
+ case MA_PRINT:
+ oidset_insert(&missing_objects, &obj->oid);
+ return;
+
+ default:
+ BUG("unhandled missing_action");
+ return;
+ }
+}
+
static void finish_object(struct object *obj, const char *name, void *cb_data)
{
struct rev_list_info *info = cb_data;
if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid))
- die("missing blob object '%s'", oid_to_hex(&obj->oid));
+ finish_object__ma(obj);
if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
parse_object(&obj->oid);
}
@@ -269,6 +306,26 @@ static int show_object_fast(
return 1;
}
+static inline int parse_missing_action_value(const char *value)
+{
+ if (!strcmp(value, "error")) {
+ arg_missing_action = MA_ERROR;
+ return 1;
+ }
+
+ if (!strcmp(value, "allow-any")) {
+ arg_missing_action = MA_ALLOW_ANY;
+ return 1;
+ }
+
+ if (!strcmp(value, "print")) {
+ arg_missing_action = MA_PRINT;
+ return 1;
+ }
+
+ return 0;
+}
+
int cmd_rev_list(int argc, const char **argv, const char *prefix)
{
struct rev_info revs;
@@ -335,6 +392,30 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
show_progress = arg;
continue;
}
+
+ if (skip_prefix(arg, ("--" CL_ARG__FILTER "="), &arg)) {
+ parse_list_objects_filter(&filter_options, arg);
+ if (filter_options.choice && !revs.blob_objects)
+ die(_("object filtering requires --objects"));
+ if (filter_options.choice == LOFC_SPARSE_OID &&
+ !filter_options.sparse_oid_value)
+ die(_("invalid sparse value '%s'"),
+ filter_options.filter_spec);
+ continue;
+ }
+ if (!strcmp(arg, ("--no-" CL_ARG__FILTER))) {
+ list_objects_filter_release(&filter_options);
+ continue;
+ }
+ if (!strcmp(arg, "--filter-print-omitted")) {
+ arg_print_omitted = 1;
+ continue;
+ }
+
+ if (skip_prefix(arg, "--missing=", &arg) &&
+ parse_missing_action_value(arg))
+ continue;
+
usage(rev_list_usage);
}
@@ -360,6 +441,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
if (revs.show_notes)
die(_("rev-list does not support display of notes"));
+ if (filter_options.choice && use_bitmap_index)
+ die(_("cannot combine --use-bitmap-index with object filtering"));
+
save_commit_buffer = (revs.verbose_header ||
revs.grep_filter.pattern_list ||
revs.grep_filter.header_list);
@@ -403,7 +487,31 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
return show_bisect_vars(&info, reaches, all);
}
- traverse_commit_list(&revs, show_commit, show_object, &info);
+ if (arg_print_omitted)
+ oidset_init(&omitted_objects, DEFAULT_OIDSET_SIZE);
+ if (arg_missing_action == MA_PRINT)
+ oidset_init(&missing_objects, DEFAULT_OIDSET_SIZE);
+
+ traverse_commit_list_filtered(
+ &filter_options, &revs, show_commit, show_object, &info,
+ (arg_print_omitted ? &omitted_objects : NULL));
+
+ if (arg_print_omitted) {
+ struct oidset_iter iter;
+ struct object_id *oid;
+ oidset_iter_init(&omitted_objects, &iter);
+ while ((oid = oidset_iter_next(&iter)))
+ printf("~%s\n", oid_to_hex(oid));
+ oidset_clear(&omitted_objects);
+ }
+ if (arg_missing_action == MA_PRINT) {
+ struct oidset_iter iter;
+ struct object_id *oid;
+ oidset_iter_init(&missing_objects, &iter);
+ while ((oid = oidset_iter_next(&iter)))
+ printf("?%s\n", oid_to_hex(oid));
+ oidset_clear(&missing_objects);
+ }
stop_progress(&progress);
diff --git a/builtin/rm.c b/builtin/rm.c
index d91451fea1..4a2fcca27b 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -382,7 +382,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
}
strbuf_release(&buf);
if (gitmodules_modified)
- stage_updated_gitmodules();
+ stage_updated_gitmodules(&the_index);
}
if (active_cache_changed) {
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 2e24b5c330..e8a4aa40cb 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,6 +1,6 @@
#include "cache.h"
#include "config.h"
-#include "commit.h"
+#include "pretty.h"
#include "refs.h"
#include "builtin.h"
#include "color.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 002a569a11..7cef5b120b 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -230,20 +230,21 @@ static int add_worktree(const char *path, const char *refname,
int counter = 0, len, ret;
struct strbuf symref = STRBUF_INIT;
struct commit *commit = NULL;
+ int is_branch = 0;
if (file_exists(path) && !is_empty_dir(path))
die(_("'%s' already exists"), path);
/* is 'refname' a branch or commit? */
if (!opts->detach && !strbuf_check_branch_ref(&symref, refname) &&
- ref_exists(symref.buf)) { /* it's a branch */
+ ref_exists(symref.buf)) {
+ is_branch = 1;
if (!opts->force)
die_if_checked_out(symref.buf, 0);
- } else { /* must be a commit */
- commit = lookup_commit_reference_by_name(refname);
- if (!commit)
- die(_("invalid reference: %s"), refname);
}
+ commit = lookup_commit_reference_by_name(refname);
+ if (!commit)
+ die(_("invalid reference: %s"), refname);
name = worktree_basename(path, &len);
git_path_buf(&sb_repo, "worktrees/%.*s", (int)(path + len - name), name);
@@ -308,7 +309,7 @@ static int add_worktree(const char *path, const char *refname,
argv_array_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path);
cp.git_cmd = 1;
- if (commit)
+ if (!is_branch)
argv_array_pushl(&cp.args, "update-ref", "HEAD",
oid_to_hex(&commit->object.oid), NULL);
else
@@ -339,6 +340,15 @@ done:
strbuf_addf(&sb, "%s/locked", sb_repo.buf);
unlink_or_warn(sb.buf);
}
+
+ /*
+ * Hook failure does not warrant worktree deletion, so run hook after
+ * is_junk is cleared, but do return appropriate code when hook fails.
+ */
+ if (!ret && opts->checkout)
+ ret = run_hook_le(NULL, "post-checkout", oid_to_hex(&null_oid),
+ oid_to_hex(&commit->object.oid), "1", NULL);
+
argv_array_clear(&child_env);
strbuf_release(&sb);
strbuf_release(&symref);
diff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh
index 5bd06fe900..75a9fd2475 100755
--- a/ci/install-dependencies.sh
+++ b/ci/install-dependencies.sh
@@ -8,10 +8,8 @@
P4WHENCE=http://filehost.perforce.com/perforce/r$LINUX_P4_VERSION
LFSWHENCE=https://github.com/github/git-lfs/releases/download/v$LINUX_GIT_LFS_VERSION
-case "${TRAVIS_OS_NAME:-linux}" in
-linux)
- export GIT_TEST_HTTPD=YesPlease
-
+case "$jobname" in
+linux-clang|linux-gcc)
mkdir --parents "$P4_PATH"
pushd "$P4_PATH"
wget --quiet "$P4WHENCE/bin.linux26x86_64/p4d"
@@ -26,7 +24,7 @@ linux)
cp git-lfs-$LINUX_GIT_LFS_VERSION/git-lfs .
popd
;;
-osx)
+osx-clang|osx-gcc)
brew update --quiet
# Uncomment this if you want to run perf tests:
# brew install gnu-time
diff --git a/ci/lib-travisci.sh b/ci/lib-travisci.sh
index ac05f1f469..331d3eb3a6 100755
--- a/ci/lib-travisci.sh
+++ b/ci/lib-travisci.sh
@@ -23,14 +23,42 @@ skip_branch_tip_with_tag () {
# Set 'exit on error' for all CI scripts to let the caller know that
# something went wrong
-set -e
+set -ex
skip_branch_tip_with_tag
-case "${TRAVIS_OS_NAME:-linux}" in
-linux)
+if test -z "$jobname"
+then
+ jobname="$TRAVIS_OS_NAME-$CC"
+fi
+
+export DEVELOPER=1
+export DEFAULT_TEST_TARGET=prove
+export GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save"
+export GIT_TEST_OPTS="--verbose-log"
+export GIT_TEST_CLONE_2GB=YesPlease
+
+case "$jobname" in
+linux-clang|linux-gcc)
+ export GIT_TEST_HTTPD=YesPlease
+
+ # The Linux build installs the defined dependency versions below.
+ # The OS X build installs the latest available versions. Keep that
+ # in mind when you encounter a broken OS X build!
+ export LINUX_P4_VERSION="16.2"
+ export LINUX_GIT_LFS_VERSION="1.5.2"
+
P4_PATH="$(pwd)/custom/p4"
GIT_LFS_PATH="$(pwd)/custom/git-lfs"
export PATH="$GIT_LFS_PATH:$P4_PATH:$PATH"
;;
+osx-clang|osx-gcc)
+ # t9810 occasionally fails on Travis CI OS X
+ # t9816 occasionally fails with "TAP out of sequence errors" on
+ # Travis CI OS X
+ export GIT_SKIP_TESTS="t9810 t9816"
+ ;;
+GETTEXT_POISON)
+ export GETTEXT_POISON=YesPlease
+ ;;
esac
diff --git a/commit.h b/commit.h
index 99a3fea68d..8c68ca1a5a 100644
--- a/commit.h
+++ b/commit.h
@@ -7,6 +7,7 @@
#include "decorate.h"
#include "gpg-interface.h"
#include "string-list.h"
+#include "pretty.h"
struct commit_list {
struct commit *item;
@@ -121,93 +122,13 @@ struct commit_list *copy_commit_list(struct commit_list *list);
void free_commit_list(struct commit_list *list);
-/* Commit formats */
-enum cmit_fmt {
- CMIT_FMT_RAW,
- CMIT_FMT_MEDIUM,
- CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
- CMIT_FMT_SHORT,
- CMIT_FMT_FULL,
- CMIT_FMT_FULLER,
- CMIT_FMT_ONELINE,
- CMIT_FMT_EMAIL,
- CMIT_FMT_MBOXRD,
- CMIT_FMT_USERFORMAT,
-
- CMIT_FMT_UNSPECIFIED
-};
-
-static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
-{
- return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD);
-}
-
struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
-struct pretty_print_context {
- /*
- * Callers should tweak these to change the behavior of pp_* functions.
- */
- enum cmit_fmt fmt;
- int abbrev;
- const char *after_subject;
- int preserve_subject;
- struct date_mode date_mode;
- unsigned date_mode_explicit:1;
- int print_email_subject;
- int expand_tabs_in_log;
- int need_8bit_cte;
- char *notes_message;
- struct reflog_walk_info *reflog_info;
- struct rev_info *rev;
- const char *output_encoding;
- struct string_list *mailmap;
- int color;
- struct ident_split *from_ident;
-
- /*
- * Fields below here are manipulated internally by pp_* functions and
- * should not be counted on by callers.
- */
- struct string_list in_body_headers;
- int graph_width;
-};
-
-struct userformat_want {
- unsigned notes:1;
-};
-
extern int has_non_ascii(const char *text);
extern const char *logmsg_reencode(const struct commit *commit,
char **commit_encoding,
const char *output_encoding);
-extern void get_commit_format(const char *arg, struct rev_info *);
-extern const char *format_subject(struct strbuf *sb, const char *msg,
- const char *line_separator);
-extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
-extern int commit_format_is_empty(enum cmit_fmt);
extern const char *skip_blank_lines(const char *msg);
-extern void format_commit_message(const struct commit *commit,
- const char *format, struct strbuf *sb,
- const struct pretty_print_context *context);
-extern void pretty_print_commit(struct pretty_print_context *pp,
- const struct commit *commit,
- struct strbuf *sb);
-extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
- struct strbuf *sb);
-void pp_user_info(struct pretty_print_context *pp,
- const char *what, struct strbuf *sb,
- const char *line, const char *encoding);
-void pp_title_line(struct pretty_print_context *pp,
- const char **msg_p,
- struct strbuf *sb,
- const char *encoding,
- int need_8bit_cte);
-void pp_remainder(struct pretty_print_context *pp,
- const char **msg_p,
- struct strbuf *sb,
- int indent);
-
/** Removes the first commit from a list sorted by date, and adds all
* of its parents.
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index c6cbef38c2..983e419d2b 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -278,11 +278,12 @@ __git_ps1_colorize_gitstring ()
r="$c_clear$r"
}
+# Helper function to read the first line of a file into a variable.
+# __git_eread requires 2 arguments, the file path and the name of the
+# variable, in that order.
__git_eread ()
{
- local f="$1"
- shift
- test -r "$f" && read "$@" <"$f"
+ test -r "$1" && IFS=$'\r\n' read "$2" <"$1"
}
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
diff --git a/convert.c b/convert.c
index 20d7ab67bd..1a41a48e15 100644
--- a/convert.c
+++ b/convert.c
@@ -220,18 +220,27 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,
}
}
-static int has_cr_in_index(const struct index_state *istate, const char *path)
+static int has_crlf_in_index(const struct index_state *istate, const char *path)
{
unsigned long sz;
void *data;
- int has_cr;
+ const char *crp;
+ int has_crlf = 0;
data = read_blob_data_from_index(istate, path, &sz);
if (!data)
return 0;
- has_cr = memchr(data, '\r', sz) != NULL;
+
+ crp = memchr(data, '\r', sz);
+ if (crp) {
+ unsigned int ret_stats;
+ ret_stats = gather_convert_stats(data, sz);
+ if (!(ret_stats & CONVERT_STAT_BITS_BIN) &&
+ (ret_stats & CONVERT_STAT_BITS_TXT_CRLF))
+ has_crlf = 1;
+ }
free(data);
- return has_cr;
+ return has_crlf;
}
static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats,
@@ -290,7 +299,7 @@ static int crlf_to_git(const struct index_state *istate,
* cherry-pick.
*/
if ((checksafe != SAFE_CRLF_RENORMALIZE) &&
- has_cr_in_index(istate, path))
+ has_crlf_in_index(istate, path))
convert_crlf_into_lf = 0;
}
if ((checksafe == SAFE_CRLF_WARN ||
diff --git a/decorate.c b/decorate.c
index 270eb25197..de31331fa4 100644
--- a/decorate.c
+++ b/decorate.c
@@ -14,20 +14,20 @@ static unsigned int hash_obj(const struct object *obj, unsigned int n)
static void *insert_decoration(struct decoration *n, const struct object *base, void *decoration)
{
int size = n->size;
- struct object_decoration *hash = n->hash;
+ struct decoration_entry *entries = n->entries;
unsigned int j = hash_obj(base, size);
- while (hash[j].base) {
- if (hash[j].base == base) {
- void *old = hash[j].decoration;
- hash[j].decoration = decoration;
+ while (entries[j].base) {
+ if (entries[j].base == base) {
+ void *old = entries[j].decoration;
+ entries[j].decoration = decoration;
return old;
}
if (++j >= size)
j = 0;
}
- hash[j].base = base;
- hash[j].decoration = decoration;
+ entries[j].base = base;
+ entries[j].decoration = decoration;
n->nr++;
return NULL;
}
@@ -36,24 +36,23 @@ static void grow_decoration(struct decoration *n)
{
int i;
int old_size = n->size;
- struct object_decoration *old_hash = n->hash;
+ struct decoration_entry *old_entries = n->entries;
n->size = (old_size + 1000) * 3 / 2;
- n->hash = xcalloc(n->size, sizeof(struct object_decoration));
+ n->entries = xcalloc(n->size, sizeof(struct decoration_entry));
n->nr = 0;
for (i = 0; i < old_size; i++) {
- const struct object *base = old_hash[i].base;
- void *decoration = old_hash[i].decoration;
+ const struct object *base = old_entries[i].base;
+ void *decoration = old_entries[i].decoration;
if (!decoration)
continue;
insert_decoration(n, base, decoration);
}
- free(old_hash);
+ free(old_entries);
}
-/* Add a decoration pointer, return any old one */
void *add_decoration(struct decoration *n, const struct object *obj,
void *decoration)
{
@@ -64,7 +63,6 @@ void *add_decoration(struct decoration *n, const struct object *obj,
return insert_decoration(n, obj, decoration);
}
-/* Lookup a decoration pointer */
void *lookup_decoration(struct decoration *n, const struct object *obj)
{
unsigned int j;
@@ -74,7 +72,7 @@ void *lookup_decoration(struct decoration *n, const struct object *obj)
return NULL;
j = hash_obj(obj, n->size);
for (;;) {
- struct object_decoration *ref = n->hash + j;
+ struct decoration_entry *ref = n->entries + j;
if (ref->base == obj)
return ref->decoration;
if (!ref->base)
diff --git a/decorate.h b/decorate.h
index e7328044ff..9014c1e996 100644
--- a/decorate.h
+++ b/decorate.h
@@ -1,18 +1,61 @@
#ifndef DECORATE_H
#define DECORATE_H
-struct object_decoration {
+/*
+ * A data structure that associates Git objects to void pointers. See
+ * t/helper/test-example-decorate.c for a demonstration of how to use these
+ * functions.
+ */
+
+/*
+ * An entry in the data structure.
+ */
+struct decoration_entry {
const struct object *base;
void *decoration;
};
+/*
+ * The data structure.
+ *
+ * This data structure must be zero-initialized.
+ */
struct decoration {
+ /*
+ * Not used by the decoration mechanism. Clients may use this for
+ * whatever they want.
+ */
const char *name;
- unsigned int size, nr;
- struct object_decoration *hash;
+
+ /*
+ * The capacity of "entries".
+ */
+ unsigned int size;
+
+ /*
+ * The number of real Git objects (that is, entries with non-NULL
+ * "base").
+ */
+ unsigned int nr;
+
+ /*
+ * The entries. This is an array of size "size", containing nr entries
+ * with non-NULL "base" and (size - nr) entries with NULL "base".
+ */
+ struct decoration_entry *entries;
};
+/*
+ * Add an association from the given object to the given pointer (which may be
+ * NULL), returning the previously associated pointer. If there is no previous
+ * association, this function returns NULL.
+ */
extern void *add_decoration(struct decoration *n, const struct object *obj, void *decoration);
+
+/*
+ * Return the pointer associated to the given object. If there is no
+ * association, this function returns NULL.
+ */
extern void *lookup_decoration(struct decoration *n, const struct object *obj);
#endif
diff --git a/diff.c b/diff.c
index 3fb445a54d..fb22b19f09 100644
--- a/diff.c
+++ b/diff.c
@@ -4512,17 +4512,12 @@ int diff_opt_parse(struct diff_options *options,
options->output_format |= DIFF_FORMAT_NUMSTAT;
else if (!strcmp(arg, "--shortstat"))
options->output_format |= DIFF_FORMAT_SHORTSTAT;
- else if (!strcmp(arg, "-X") || !strcmp(arg, "--dirstat"))
- return parse_dirstat_opt(options, "");
- else if (skip_prefix(arg, "-X", &arg))
- return parse_dirstat_opt(options, arg);
- else if (skip_prefix(arg, "--dirstat=", &arg))
+ else if (skip_prefix(arg, "-X", &arg) ||
+ skip_to_optional_arg(arg, "--dirstat", &arg))
return parse_dirstat_opt(options, arg);
else if (!strcmp(arg, "--cumulative"))
return parse_dirstat_opt(options, "cumulative");
- else if (!strcmp(arg, "--dirstat-by-file"))
- return parse_dirstat_opt(options, "files");
- else if (skip_prefix(arg, "--dirstat-by-file=", &arg)) {
+ else if (skip_to_optional_arg(arg, "--dirstat-by-file", &arg)) {
parse_dirstat_opt(options, "files");
return parse_dirstat_opt(options, arg);
}
@@ -4544,13 +4539,13 @@ int diff_opt_parse(struct diff_options *options,
return stat_opt(options, av);
/* renames options */
- else if (starts_with(arg, "-B") || starts_with(arg, "--break-rewrites=") ||
- !strcmp(arg, "--break-rewrites")) {
+ else if (starts_with(arg, "-B") ||
+ skip_to_optional_arg(arg, "--break-rewrites", NULL)) {
if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
return error("invalid argument to -B: %s", arg+2);
}
- else if (starts_with(arg, "-M") || starts_with(arg, "--find-renames=") ||
- !strcmp(arg, "--find-renames")) {
+ else if (starts_with(arg, "-M") ||
+ skip_to_optional_arg(arg, "--find-renames", NULL)) {
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
return error("invalid argument to -M: %s", arg+2);
options->detect_rename = DIFF_DETECT_RENAME;
@@ -4558,8 +4553,8 @@ int diff_opt_parse(struct diff_options *options,
else if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
options->irreversible_delete = 1;
}
- else if (starts_with(arg, "-C") || starts_with(arg, "--find-copies=") ||
- !strcmp(arg, "--find-copies")) {
+ else if (starts_with(arg, "-C") ||
+ skip_to_optional_arg(arg, "--find-copies", NULL)) {
if (options->detect_rename == DIFF_DETECT_COPY)
options->flags.find_copies_harder = 1;
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
@@ -4572,11 +4567,10 @@ int diff_opt_parse(struct diff_options *options,
options->flags.rename_empty = 1;
else if (!strcmp(arg, "--no-rename-empty"))
options->flags.rename_empty = 0;
- else if (!strcmp(arg, "--relative"))
- options->flags.relative_name = 1;
- else if (skip_prefix(arg, "--relative=", &arg)) {
+ else if (skip_to_optional_arg_default(arg, "--relative", &arg, NULL)) {
options->flags.relative_name = 1;
- options->prefix = arg;
+ if (arg)
+ options->prefix = arg;
}
/* xdiff options */
@@ -4646,9 +4640,7 @@ int diff_opt_parse(struct diff_options *options,
else if (!strcmp(arg, "--no-follow")) {
options->flags.follow_renames = 0;
options->flags.default_follow_renames = 0;
- } else if (!strcmp(arg, "--color"))
- options->use_color = 1;
- else if (skip_prefix(arg, "--color=", &arg)) {
+ } else if (skip_to_optional_arg_default(arg, "--color", &arg, "always")) {
int value = git_config_colorbool(NULL, arg);
if (value < 0)
return error("option `color' expects \"always\", \"auto\", or \"never\"");
@@ -4668,14 +4660,9 @@ int diff_opt_parse(struct diff_options *options,
if (cm < 0)
die("bad --color-moved argument: %s", arg);
options->color_moved = cm;
- } else if (!strcmp(arg, "--color-words")) {
- options->use_color = 1;
- options->word_diff = DIFF_WORDS_COLOR;
- }
- else if (skip_prefix(arg, "--color-words=", &arg)) {
+ } else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
options->use_color = 1;
options->word_diff = DIFF_WORDS_COLOR;
- options->word_regex = arg;
}
else if (!strcmp(arg, "--word-diff")) {
if (options->word_diff == DIFF_WORDS_NONE)
@@ -4714,15 +4701,10 @@ int diff_opt_parse(struct diff_options *options,
options->flags.textconv_set_via_cmdline = 1;
} else if (!strcmp(arg, "--no-textconv"))
options->flags.allow_textconv = 0;
- else if (!strcmp(arg, "--ignore-submodules")) {
- options->flags.override_submodule_config = 1;
- handle_ignore_submodules_arg(options, "all");
- } else if (skip_prefix(arg, "--ignore-submodules=", &arg)) {
+ else if (skip_to_optional_arg_default(arg, "--ignore-submodules", &arg, "all")) {
options->flags.override_submodule_config = 1;
handle_ignore_submodules_arg(options, arg);
- } else if (!strcmp(arg, "--submodule"))
- options->submodule_format = DIFF_SUBMODULE_LOG;
- else if (skip_prefix(arg, "--submodule=", &arg))
+ } else if (skip_to_optional_arg_default(arg, "--submodule", &arg, "log"))
return parse_submodule_opt(options, arg);
else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
return parse_ws_error_highlight_opt(options, arg);
diff --git a/dir.c b/dir.c
index 3c54366a17..7c4b45e30e 100644
--- a/dir.c
+++ b/dir.c
@@ -221,6 +221,57 @@ int within_depth(const char *name, int namelen,
return 1;
}
+/*
+ * Read the contents of the blob with the given OID into a buffer.
+ * Append a trailing LF to the end if the last line doesn't have one.
+ *
+ * Returns:
+ * -1 when the OID is invalid or unknown or does not refer to a blob.
+ * 0 when the blob is empty.
+ * 1 along with { data, size } of the (possibly augmented) buffer
+ * when successful.
+ *
+ * Optionally updates the given sha1_stat with the given OID (when valid).
+ */
+static int do_read_blob(const struct object_id *oid,
+ struct sha1_stat *sha1_stat,
+ size_t *size_out,
+ char **data_out)
+{
+ enum object_type type;
+ unsigned long sz;
+ char *data;
+
+ *size_out = 0;
+ *data_out = NULL;
+
+ data = read_sha1_file(oid->hash, &type, &sz);
+ if (!data || type != OBJ_BLOB) {
+ free(data);
+ return -1;
+ }
+
+ if (sha1_stat) {
+ memset(&sha1_stat->stat, 0, sizeof(sha1_stat->stat));
+ hashcpy(sha1_stat->sha1, oid->hash);
+ }
+
+ if (sz == 0) {
+ free(data);
+ return 0;
+ }
+
+ if (data[sz - 1] != '\n') {
+ data = xrealloc(data, st_add(sz, 1));
+ data[sz++] = '\n';
+ }
+
+ *size_out = xsize_t(sz);
+ *data_out = data;
+
+ return 1;
+}
+
#define DO_MATCH_EXCLUDE (1<<0)
#define DO_MATCH_DIRECTORY (1<<1)
#define DO_MATCH_SUBMODULE (1<<2)
@@ -601,32 +652,22 @@ void add_exclude(const char *string, const char *base,
x->el = el;
}
-static void *read_skip_worktree_file_from_index(const struct index_state *istate,
- const char *path, size_t *size,
- struct sha1_stat *sha1_stat)
+static int read_skip_worktree_file_from_index(const struct index_state *istate,
+ const char *path,
+ size_t *size_out,
+ char **data_out,
+ struct sha1_stat *sha1_stat)
{
int pos, len;
- unsigned long sz;
- enum object_type type;
- void *data;
len = strlen(path);
pos = index_name_pos(istate, path, len);
if (pos < 0)
- return NULL;
+ return -1;
if (!ce_skip_worktree(istate->cache[pos]))
- return NULL;
- data = read_sha1_file(istate->cache[pos]->oid.hash, &type, &sz);
- if (!data || type != OBJ_BLOB) {
- free(data);
- return NULL;
- }
- *size = xsize_t(sz);
- if (sha1_stat) {
- memset(&sha1_stat->stat, 0, sizeof(sha1_stat->stat));
- hashcpy(sha1_stat->sha1, istate->cache[pos]->oid.hash);
- }
- return data;
+ return -1;
+
+ return do_read_blob(&istate->cache[pos]->oid, sha1_stat, size_out, data_out);
}
/*
@@ -740,6 +781,10 @@ static void invalidate_directory(struct untracked_cache *uc,
dir->dirs[i]->recurse = 0;
}
+static int add_excludes_from_buffer(char *buf, size_t size,
+ const char *base, int baselen,
+ struct exclude_list *el);
+
/*
* Given a file with name "fname", read it (either from disk, or from
* an index if 'istate' is non-null), parse it and store the
@@ -755,9 +800,10 @@ static int add_excludes(const char *fname, const char *base, int baselen,
struct sha1_stat *sha1_stat)
{
struct stat st;
- int fd, i, lineno = 1;
+ int r;
+ int fd;
size_t size = 0;
- char *buf, *entry;
+ char *buf;
fd = open(fname, O_RDONLY);
if (fd < 0 || fstat(fd, &st) < 0) {
@@ -765,17 +811,13 @@ static int add_excludes(const char *fname, const char *base, int baselen,
warn_on_fopen_errors(fname);
else
close(fd);
- if (!istate ||
- (buf = read_skip_worktree_file_from_index(istate, fname, &size, sha1_stat)) == NULL)
+ if (!istate)
return -1;
- if (size == 0) {
- free(buf);
- return 0;
- }
- if (buf[size-1] != '\n') {
- buf = xrealloc(buf, st_add(size, 1));
- buf[size++] = '\n';
- }
+ r = read_skip_worktree_file_from_index(istate, fname,
+ &size, &buf,
+ sha1_stat);
+ if (r != 1)
+ return r;
} else {
size = xsize_t(st.st_size);
if (size == 0) {
@@ -814,6 +856,17 @@ static int add_excludes(const char *fname, const char *base, int baselen,
}
}
+ add_excludes_from_buffer(buf, size, base, baselen, el);
+ return 0;
+}
+
+static int add_excludes_from_buffer(char *buf, size_t size,
+ const char *base, int baselen,
+ struct exclude_list *el)
+{
+ int i, lineno = 1;
+ char *entry;
+
el->filebuf = buf;
if (skip_utf8_bom(&buf, size))
@@ -842,6 +895,23 @@ int add_excludes_from_file_to_list(const char *fname, const char *base,
return add_excludes(fname, base, baselen, el, istate, NULL);
}
+int add_excludes_from_blob_to_list(
+ struct object_id *oid,
+ const char *base, int baselen,
+ struct exclude_list *el)
+{
+ char *buf;
+ size_t size;
+ int r;
+
+ r = do_read_blob(oid, NULL, &size, &buf);
+ if (r != 1)
+ return r;
+
+ add_excludes_from_buffer(buf, size, base, baselen, el);
+ return 0;
+}
+
struct exclude_list *add_exclude_list(struct dir_struct *dir,
int group_type, const char *src)
{
diff --git a/dir.h b/dir.h
index 233a2eb36b..11a047ba48 100644
--- a/dir.h
+++ b/dir.h
@@ -259,6 +259,9 @@ extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
extern int add_excludes_from_file_to_list(const char *fname, const char *base, int baselen,
struct exclude_list *el, struct index_state *istate);
extern void add_excludes_from_file(struct dir_struct *, const char *fname);
+extern int add_excludes_from_blob_to_list(struct object_id *oid,
+ const char *base, int baselen,
+ struct exclude_list *el);
extern void parse_exclude_pattern(const char **string, int *patternlen, unsigned *flags, int *nowildcardlen);
extern void add_exclude(const char *string, const char *base,
int baselen, struct exclude_list *el, int srcpos);
diff --git a/git-compat-util.h b/git-compat-util.h
index cedad4d581..68b2ad531e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -485,6 +485,29 @@ static inline int skip_prefix(const char *str, const char *prefix,
}
/*
+ * If the string "str" is the same as the string in "prefix", then the "arg"
+ * parameter is set to the "def" parameter and 1 is returned.
+ * If the string "str" begins with the string found in "prefix" and then a
+ * "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1"
+ * (i.e., to the point in the string right after the prefix and the "=" sign),
+ * and 1 is returned.
+ *
+ * Otherwise, return 0 and leave "arg" untouched.
+ *
+ * When we accept both a "--key" and a "--key=<val>" option, this function
+ * can be used instead of !strcmp(arg, "--key") and then
+ * skip_prefix(arg, "--key=", &arg) to parse such an option.
+ */
+int skip_to_optional_arg_default(const char *str, const char *prefix,
+ const char **arg, const char *def);
+
+static inline int skip_to_optional_arg(const char *str, const char *prefix,
+ const char **arg)
+{
+ return skip_to_optional_arg_default(str, prefix, arg, "");
+}
+
+/*
* Like skip_prefix, but promises never to read past "len" bytes of the input
* buffer, and returns the remaining number of bytes in "out" via "outlen".
*/
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 36929921ea..2d8df83172 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -642,7 +642,7 @@ sub is_sha1 {
sub get_headref ($) {
my $name = shift;
- $name =~ s/'/'\\''/;
+ $name =~ s/'/'\\''/g;
my $r = `git rev-parse --verify '$name' 2>/dev/null`;
return undef unless $? == 0;
chomp $r;
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 437815669f..e3f5a0abf3 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -722,27 +722,6 @@ collapse_todo_ids() {
git rebase--helper --shorten-ids
}
-# Add commands after a pick or after a squash/fixup series
-# in the todo list.
-add_exec_commands () {
- {
- first=t
- while read -r insn rest
- do
- case $insn in
- pick)
- test -n "$first" ||
- printf "%s" "$cmd"
- ;;
- esac
- printf "%s %s\n" "$insn" "$rest"
- first=
- done
- printf "%s" "$cmd"
- } <"$1" >"$1.new" &&
- mv "$1.new" "$1"
-}
-
# Switch to the branch in $into and notify it in the reflog
checkout_onto () {
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
@@ -982,7 +961,7 @@ fi
test -s "$todo" || echo noop >> "$todo"
test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
-test -n "$cmd" && add_exec_commands "$todo"
+test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
todocount=${todocount##* }
diff --git a/git-rebase.sh b/git-rebase.sh
index 60b70f3def..fd72a35c65 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -477,7 +477,7 @@ then
;;
esac
upstream=$(peel_committish "${upstream_name}") ||
- die "$(eval_gettext "invalid upstream \$upstream_name")"
+ die "$(eval_gettext "invalid upstream '\$upstream_name'")"
upstream_arg="$upstream_name"
else
if test -z "$onto"
@@ -518,7 +518,7 @@ case "$onto_name" in
esac
# If the branch to rebase is given, that is the branch we will rebase
-# $branch_name -- branch being rebased, or HEAD (already detached)
+# $branch_name -- branch/commit being rebased, or HEAD (already detached)
# $orig_head -- commit object name of tip of the branch before rebasing
# $head_name -- refs/heads/<that-branch> or "detached HEAD"
switch_to=
@@ -528,15 +528,18 @@ case "$#" in
branch_name="$1"
switch_to="$1"
- if git show-ref --verify --quiet -- "refs/heads/$1" &&
- orig_head=$(git rev-parse -q --verify "refs/heads/$1")
+ # Is it a local branch?
+ if git show-ref --verify --quiet -- "refs/heads/$branch_name" &&
+ orig_head=$(git rev-parse -q --verify "refs/heads/$branch_name")
then
- head_name="refs/heads/$1"
- elif orig_head=$(git rev-parse -q --verify "$1")
+ head_name="refs/heads/$branch_name"
+ # If not is it a valid ref (branch or commit)?
+ elif orig_head=$(git rev-parse -q --verify "$branch_name")
then
head_name="detached HEAD"
+
else
- die "$(eval_gettext "fatal: no such branch: \$branch_name")"
+ die "$(eval_gettext "fatal: no such branch/commit '\$branch_name'")"
fi
;;
0)
@@ -547,7 +550,7 @@ case "$#" in
branch_name=$(expr "z$branch_name" : 'zrefs/heads/\(.*\)')
else
head_name="detached HEAD"
- branch_name=HEAD ;# detached
+ branch_name=HEAD
fi
orig_head=$(git rev-parse --verify HEAD) || exit
;;
@@ -598,11 +601,23 @@ then
test -z "$switch_to" ||
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" \
git checkout -q "$switch_to" --
- say "$(eval_gettext "Current branch \$branch_name is up to date.")"
+ if test "$branch_name" = "HEAD" &&
+ ! git symbolic-ref -q HEAD
+ then
+ say "$(eval_gettext "HEAD is up to date.")"
+ else
+ say "$(eval_gettext "Current branch \$branch_name is up to date.")"
+ fi
finish_rebase
exit 0
else
- say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")"
+ if test "$branch_name" = "HEAD" &&
+ ! git symbolic-ref -q HEAD
+ then
+ say "$(eval_gettext "HEAD is up to date, rebase forced.")"
+ else
+ say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")"
+ fi
fi
fi
diff --git a/git-svn.perl b/git-svn.perl
index d2404184ba..aa242d4f4f 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -1865,6 +1865,7 @@ sub get_commit_entry {
}
}
$msgbuf =~ s/\s+$//s;
+ $msgbuf =~ s/\r\n/\n/sg; # SVN 1.6+ disallows CRLF
if ($Git::SVN::_add_author_from && defined($author)
&& !$saw_from) {
$msgbuf .= "\n\nFrom: $author";
diff --git a/help.c b/help.c
index 88a3aeaeb9..60071a9bea 100644
--- a/help.c
+++ b/help.c
@@ -412,6 +412,12 @@ int cmd_version(int argc, const char **argv, const char *prefix)
printf("git version %s\n", git_version_string);
if (build_options) {
+ printf("cpu: %s\n", GIT_HOST_CPU);
+ if (git_built_from_commit_string[0])
+ printf("built from commit: %s\n",
+ git_built_from_commit_string);
+ else
+ printf("no commit associated with this build\n");
printf("sizeof-long: %d\n", (int)sizeof(long));
/* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
}
diff --git a/http.c b/http.c
index 215bebef1b..32d33261c9 100644
--- a/http.c
+++ b/http.c
@@ -866,6 +866,11 @@ static CURL *get_curl_handle(void)
curl_easy_setopt(result,
CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
#endif
+#if LIBCURL_VERSION_NUM >= 0x073400
+ else if (starts_with(curl_http_proxy, "https"))
+ curl_easy_setopt(result,
+ CURLOPT_PROXYTYPE, CURLPROXY_HTTPS);
+#endif
if (strstr(curl_http_proxy, "://"))
credential_from_url(&proxy_auth, curl_http_proxy);
else {
diff --git a/imap-send.c b/imap-send.c
index 54e6a80fd6..36c7c1b4f6 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1412,6 +1412,7 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
{
CURL *curl;
struct strbuf path = STRBUF_INIT;
+ char *uri_encoded_folder;
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK)
die("curl_global_init failed");
@@ -1429,7 +1430,12 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
strbuf_addstr(&path, server.host);
if (!path.len || path.buf[path.len - 1] != '/')
strbuf_addch(&path, '/');
- strbuf_addstr(&path, server.folder);
+
+ uri_encoded_folder = curl_easy_escape(curl, server.folder, 0);
+ if (!uri_encoded_folder)
+ die("failed to encode server folder");
+ strbuf_addstr(&path, uri_encoded_folder);
+ curl_free(uri_encoded_folder);
curl_easy_setopt(curl, CURLOPT_URL, path.buf);
strbuf_release(&path);
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
new file mode 100644
index 0000000000..4c5b34e949
--- /dev/null
+++ b/list-objects-filter-options.c
@@ -0,0 +1,92 @@
+#include "cache.h"
+#include "commit.h"
+#include "config.h"
+#include "revision.h"
+#include "argv-array.h"
+#include "list-objects.h"
+#include "list-objects-filter.h"
+#include "list-objects-filter-options.h"
+
+/*
+ * Parse value of the argument to the "filter" keyword.
+ * On the command line this looks like:
+ * --filter=<arg>
+ * and in the pack protocol as:
+ * "filter" SP <arg>
+ *
+ * The filter keyword will be used by many commands.
+ * See Documentation/rev-list-options.txt for allowed values for <arg>.
+ *
+ * Capture the given arg as the "filter_spec". This can be forwarded to
+ * subordinate commands when necessary. We also "intern" the arg for
+ * the convenience of the current command.
+ */
+int parse_list_objects_filter(struct list_objects_filter_options *filter_options,
+ const char *arg)
+{
+ const char *v0;
+
+ if (filter_options->choice)
+ die(_("multiple object filter types cannot be combined"));
+
+ filter_options->filter_spec = strdup(arg);
+
+ if (!strcmp(arg, "blob:none")) {
+ filter_options->choice = LOFC_BLOB_NONE;
+ return 0;
+ }
+
+ if (skip_prefix(arg, "blob:limit=", &v0)) {
+ if (!git_parse_ulong(v0, &filter_options->blob_limit_value))
+ die(_("invalid filter-spec expression '%s'"), arg);
+ filter_options->choice = LOFC_BLOB_LIMIT;
+ return 0;
+ }
+
+ if (skip_prefix(arg, "sparse:oid=", &v0)) {
+ struct object_context oc;
+ struct object_id sparse_oid;
+
+ /*
+ * Try to parse <oid-expression> into an OID for the current
+ * command, but DO NOT complain if we don't have the blob or
+ * ref locally.
+ */
+ if (!get_oid_with_context(v0, GET_OID_BLOB,
+ &sparse_oid, &oc))
+ filter_options->sparse_oid_value = oiddup(&sparse_oid);
+ filter_options->choice = LOFC_SPARSE_OID;
+ return 0;
+ }
+
+ if (skip_prefix(arg, "sparse:path=", &v0)) {
+ filter_options->choice = LOFC_SPARSE_PATH;
+ filter_options->sparse_path_value = strdup(v0);
+ return 0;
+ }
+
+ die(_("invalid filter-spec expression '%s'"), arg);
+ return 0;
+}
+
+int opt_parse_list_objects_filter(const struct option *opt,
+ const char *arg, int unset)
+{
+ struct list_objects_filter_options *filter_options = opt->value;
+
+ if (unset || !arg) {
+ list_objects_filter_release(filter_options);
+ return 0;
+ }
+
+ return parse_list_objects_filter(filter_options, arg);
+}
+
+void list_objects_filter_release(
+ struct list_objects_filter_options *filter_options)
+{
+ free(filter_options->filter_spec);
+ free(filter_options->sparse_oid_value);
+ free(filter_options->sparse_path_value);
+ memset(filter_options, 0, sizeof(*filter_options));
+}
diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h
new file mode 100644
index 0000000000..eea44a1a51
--- /dev/null
+++ b/list-objects-filter-options.h
@@ -0,0 +1,61 @@
+#ifndef LIST_OBJECTS_FILTER_OPTIONS_H
+#define LIST_OBJECTS_FILTER_OPTIONS_H
+
+#include "parse-options.h"
+
+/*
+ * The list of defined filters for list-objects.
+ */
+enum list_objects_filter_choice {
+ LOFC_DISABLED = 0,
+ LOFC_BLOB_NONE,
+ LOFC_BLOB_LIMIT,
+ LOFC_SPARSE_OID,
+ LOFC_SPARSE_PATH,
+ LOFC__COUNT /* must be last */
+};
+
+struct list_objects_filter_options {
+ /*
+ * 'filter_spec' is the raw argument value given on the command line
+ * or protocol request. (The part after the "--keyword=".) For
+ * commands that launch filtering sub-processes, this value should be
+ * passed to them as received by the current process.
+ */
+ char *filter_spec;
+
+ /*
+ * 'choice' is determined by parsing the filter-spec. This indicates
+ * the filtering algorithm to use.
+ */
+ enum list_objects_filter_choice choice;
+
+ /*
+ * Parsed values (fields) from within the filter-spec. These are
+ * choice-specific; not all values will be defined for any given
+ * choice.
+ */
+ struct object_id *sparse_oid_value;
+ char *sparse_path_value;
+ unsigned long blob_limit_value;
+};
+
+/* Normalized command line arguments */
+#define CL_ARG__FILTER "filter"
+
+int parse_list_objects_filter(
+ struct list_objects_filter_options *filter_options,
+ const char *arg);
+
+int opt_parse_list_objects_filter(const struct option *opt,
+ const char *arg, int unset);
+
+#define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \
+ { OPTION_CALLBACK, 0, CL_ARG__FILTER, fo, N_("args"), \
+ N_("object filtering"), 0, \
+ opt_parse_list_objects_filter }
+
+void list_objects_filter_release(
+ struct list_objects_filter_options *filter_options);
+
+#endif /* LIST_OBJECTS_FILTER_OPTIONS_H */
diff --git a/list-objects-filter.c b/list-objects-filter.c
new file mode 100644
index 0000000000..4356c45368
--- /dev/null
+++ b/list-objects-filter.c
@@ -0,0 +1,401 @@
+#include "cache.h"
+#include "dir.h"
+#include "tag.h"
+#include "commit.h"
+#include "tree.h"
+#include "blob.h"
+#include "diff.h"
+#include "tree-walk.h"
+#include "revision.h"
+#include "list-objects.h"
+#include "list-objects-filter.h"
+#include "list-objects-filter-options.h"
+#include "oidset.h"
+
+/* Remember to update object flag allocation in object.h */
+/*
+ * FILTER_SHOWN_BUT_REVISIT -- we set this bit on tree objects
+ * that have been shown, but should be revisited if they appear
+ * in the traversal (until we mark it SEEN). This is a way to
+ * let us silently de-dup calls to show() in the caller. This
+ * is subtly different from the "revision.h:SHOWN" and the
+ * "sha1_name.c:ONELINE_SEEN" bits. And also different from
+ * the non-de-dup usage in pack-bitmap.c
+ */
+#define FILTER_SHOWN_BUT_REVISIT (1<<21)
+
+/*
+ * A filter for list-objects to omit ALL blobs from the traversal.
+ * And to OPTIONALLY collect a list of the omitted OIDs.
+ */
+struct filter_blobs_none_data {
+ struct oidset *omits;
+};
+
+static enum list_objects_filter_result filter_blobs_none(
+ enum list_objects_filter_situation filter_situation,
+ struct object *obj,
+ const char *pathname,
+ const char *filename,
+ void *filter_data_)
+{
+ struct filter_blobs_none_data *filter_data = filter_data_;
+
+ switch (filter_situation) {
+ default:
+ die("unknown filter_situation");
+ return LOFR_ZERO;
+
+ case LOFS_BEGIN_TREE:
+ assert(obj->type == OBJ_TREE);
+ /* always include all tree objects */
+ return LOFR_MARK_SEEN | LOFR_DO_SHOW;
+
+ case LOFS_END_TREE:
+ assert(obj->type == OBJ_TREE);
+ return LOFR_ZERO;
+
+ case LOFS_BLOB:
+ assert(obj->type == OBJ_BLOB);
+ assert((obj->flags & SEEN) == 0);
+
+ if (filter_data->omits)
+ oidset_insert(filter_data->omits, &obj->oid);
+ return LOFR_MARK_SEEN; /* but not LOFR_DO_SHOW (hard omit) */
+ }
+}
+
+static void *filter_blobs_none__init(
+ struct oidset *omitted,
+ struct list_objects_filter_options *filter_options,
+ filter_object_fn *filter_fn,
+ filter_free_fn *filter_free_fn)
+{
+ struct filter_blobs_none_data *d = xcalloc(1, sizeof(*d));
+ d->omits = omitted;
+
+ *filter_fn = filter_blobs_none;
+ *filter_free_fn = free;
+ return d;
+}
+
+/*
+ * A filter for list-objects to omit large blobs.
+ * And to OPTIONALLY collect a list of the omitted OIDs.
+ */
+struct filter_blobs_limit_data {
+ struct oidset *omits;
+ unsigned long max_bytes;
+};
+
+static enum list_objects_filter_result filter_blobs_limit(
+ enum list_objects_filter_situation filter_situation,
+ struct object *obj,
+ const char *pathname,
+ const char *filename,
+ void *filter_data_)
+{
+ struct filter_blobs_limit_data *filter_data = filter_data_;
+ unsigned long object_length;
+ enum object_type t;
+
+ switch (filter_situation) {
+ default:
+ die("unknown filter_situation");
+ return LOFR_ZERO;
+
+ case LOFS_BEGIN_TREE:
+ assert(obj->type == OBJ_TREE);
+ /* always include all tree objects */
+ return LOFR_MARK_SEEN | LOFR_DO_SHOW;
+
+ case LOFS_END_TREE:
+ assert(obj->type == OBJ_TREE);
+ return LOFR_ZERO;
+
+ case LOFS_BLOB:
+ assert(obj->type == OBJ_BLOB);
+ assert((obj->flags & SEEN) == 0);
+
+ t = sha1_object_info(obj->oid.hash, &object_length);
+ if (t != OBJ_BLOB) { /* probably OBJ_NONE */
+ /*
+ * We DO NOT have the blob locally, so we cannot
+ * apply the size filter criteria. Be conservative
+ * and force show it (and let the caller deal with
+ * the ambiguity).
+ */
+ goto include_it;
+ }
+
+ if (object_length < filter_data->max_bytes)
+ goto include_it;
+
+ if (filter_data->omits)
+ oidset_insert(filter_data->omits, &obj->oid);
+ return LOFR_MARK_SEEN; /* but not LOFR_DO_SHOW (hard omit) */
+ }
+
+include_it:
+ if (filter_data->omits)
+ oidset_remove(filter_data->omits, &obj->oid);
+ return LOFR_MARK_SEEN | LOFR_DO_SHOW;
+}
+
+static void *filter_blobs_limit__init(
+ struct oidset *omitted,
+ struct list_objects_filter_options *filter_options,
+ filter_object_fn *filter_fn,
+ filter_free_fn *filter_free_fn)
+{
+ struct filter_blobs_limit_data *d = xcalloc(1, sizeof(*d));
+ d->omits = omitted;
+ d->max_bytes = filter_options->blob_limit_value;
+
+ *filter_fn = filter_blobs_limit;
+ *filter_free_fn = free;
+ return d;
+}
+
+/*
+ * A filter driven by a sparse-checkout specification to only
+ * include blobs that a sparse checkout would populate.
+ *
+ * The sparse-checkout spec can be loaded from a blob with the
+ * given OID or from a local pathname. We allow an OID because
+ * the repo may be bare or we may be doing the filtering on the
+ * server.
+ */
+struct frame {
+ /*
+ * defval is the usual default include/exclude value that
+ * should be inherited as we recurse into directories based
+ * upon pattern matching of the directory itself or of a
+ * containing directory.
+ */
+ int defval;
+
+ /*
+ * 1 if the directory (recursively) contains any provisionally
+ * omitted objects.
+ *
+ * 0 if everything (recursively) contained in this directory
+ * has been explicitly included (SHOWN) in the result and
+ * the directory may be short-cut later in the traversal.
+ */
+ unsigned child_prov_omit : 1;
+};
+
+struct filter_sparse_data {
+ struct oidset *omits;
+ struct exclude_list el;
+
+ size_t nr, alloc;
+ struct frame *array_frame;
+};
+
+static enum list_objects_filter_result filter_sparse(
+ enum list_objects_filter_situation filter_situation,
+ struct object *obj,
+ const char *pathname,
+ const char *filename,
+ void *filter_data_)
+{
+ struct filter_sparse_data *filter_data = filter_data_;
+ int val, dtype;
+ struct frame *frame;
+
+ switch (filter_situation) {
+ default:
+ die("unknown filter_situation");
+ return LOFR_ZERO;
+
+ case LOFS_BEGIN_TREE:
+ assert(obj->type == OBJ_TREE);
+ dtype = DT_DIR;
+ val = is_excluded_from_list(pathname, strlen(pathname),
+ filename, &dtype, &filter_data->el,
+ &the_index);
+ if (val < 0)
+ val = filter_data->array_frame[filter_data->nr].defval;
+
+ ALLOC_GROW(filter_data->array_frame, filter_data->nr + 1,
+ filter_data->alloc);
+ filter_data->nr++;
+ filter_data->array_frame[filter_data->nr].defval = val;
+ filter_data->array_frame[filter_data->nr].child_prov_omit = 0;
+
+ /*
+ * A directory with this tree OID may appear in multiple
+ * places in the tree. (Think of a directory move or copy,
+ * with no other changes, so the OID is the same, but the
+ * full pathnames of objects within this directory are new
+ * and may match is_excluded() patterns differently.)
+ * So we cannot mark this directory as SEEN (yet), since
+ * that will prevent process_tree() from revisiting this
+ * tree object with other pathname prefixes.
+ *
+ * Only _DO_SHOW the tree object the first time we visit
+ * this tree object.
+ *
+ * We always show all tree objects. A future optimization
+ * may want to attempt to narrow this.
+ */
+ if (obj->flags & FILTER_SHOWN_BUT_REVISIT)
+ return LOFR_ZERO;
+ obj->flags |= FILTER_SHOWN_BUT_REVISIT;
+ return LOFR_DO_SHOW;
+
+ case LOFS_END_TREE:
+ assert(obj->type == OBJ_TREE);
+ assert(filter_data->nr > 0);
+
+ frame = &filter_data->array_frame[filter_data->nr];
+ filter_data->nr--;
+
+ /*
+ * Tell our parent directory if any of our children were
+ * provisionally omitted.
+ */
+ filter_data->array_frame[filter_data->nr].child_prov_omit |=
+ frame->child_prov_omit;
+
+ /*
+ * If there are NO provisionally omitted child objects (ALL child
+ * objects in this folder were INCLUDED), then we can mark the
+ * folder as SEEN (so we will not have to revisit it again).
+ */
+ if (!frame->child_prov_omit)
+ return LOFR_MARK_SEEN;
+ return LOFR_ZERO;
+
+ case LOFS_BLOB:
+ assert(obj->type == OBJ_BLOB);
+ assert((obj->flags & SEEN) == 0);
+
+ frame = &filter_data->array_frame[filter_data->nr];
+
+ dtype = DT_REG;
+ val = is_excluded_from_list(pathname, strlen(pathname),
+ filename, &dtype, &filter_data->el,
+ &the_index);
+ if (val < 0)
+ val = frame->defval;
+ if (val > 0) {
+ if (filter_data->omits)
+ oidset_remove(filter_data->omits, &obj->oid);
+ return LOFR_MARK_SEEN | LOFR_DO_SHOW;
+ }
+
+ /*
+ * Provisionally omit it. We've already established that
+ * this pathname is not in the sparse-checkout specification
+ * with the CURRENT pathname, so we *WANT* to omit this blob.
+ *
+ * However, a pathname elsewhere in the tree may also
+ * reference this same blob, so we cannot reject it yet.
+ * Leave the LOFR_ bits unset so that if the blob appears
+ * again in the traversal, we will be asked again.
+ */
+ if (filter_data->omits)
+ oidset_insert(filter_data->omits, &obj->oid);
+
+ /*
+ * Remember that at least 1 blob in this tree was
+ * provisionally omitted. This prevents us from short
+ * cutting the tree in future iterations.
+ */
+ frame->child_prov_omit = 1;
+ return LOFR_ZERO;
+ }
+}
+
+
+static void filter_sparse_free(void *filter_data)
+{
+ struct filter_sparse_data *d = filter_data;
+ /* TODO free contents of 'd' */
+ free(d);
+}
+
+static void *filter_sparse_oid__init(
+ struct oidset *omitted,
+ struct list_objects_filter_options *filter_options,
+ filter_object_fn *filter_fn,
+ filter_free_fn *filter_free_fn)
+{
+ struct filter_sparse_data *d = xcalloc(1, sizeof(*d));
+ d->omits = omitted;
+ if (add_excludes_from_blob_to_list(filter_options->sparse_oid_value,
+ NULL, 0, &d->el) < 0)
+ die("could not load filter specification");
+
+ ALLOC_GROW(d->array_frame, d->nr + 1, d->alloc);
+ d->array_frame[d->nr].defval = 0; /* default to include */
+ d->array_frame[d->nr].child_prov_omit = 0;
+
+ *filter_fn = filter_sparse;
+ *filter_free_fn = filter_sparse_free;
+ return d;
+}
+
+static void *filter_sparse_path__init(
+ struct oidset *omitted,
+ struct list_objects_filter_options *filter_options,
+ filter_object_fn *filter_fn,
+ filter_free_fn *filter_free_fn)
+{
+ struct filter_sparse_data *d = xcalloc(1, sizeof(*d));
+ d->omits = omitted;
+ if (add_excludes_from_file_to_list(filter_options->sparse_path_value,
+ NULL, 0, &d->el, NULL) < 0)
+ die("could not load filter specification");
+
+ ALLOC_GROW(d->array_frame, d->nr + 1, d->alloc);
+ d->array_frame[d->nr].defval = 0; /* default to include */
+ d->array_frame[d->nr].child_prov_omit = 0;
+
+ *filter_fn = filter_sparse;
+ *filter_free_fn = filter_sparse_free;
+ return d;
+}
+
+typedef void *(*filter_init_fn)(
+ struct oidset *omitted,
+ struct list_objects_filter_options *filter_options,
+ filter_object_fn *filter_fn,
+ filter_free_fn *filter_free_fn);
+
+/*
+ * Must match "enum list_objects_filter_choice".
+ */
+static filter_init_fn s_filters[] = {
+ NULL,
+ filter_blobs_none__init,
+ filter_blobs_limit__init,
+ filter_sparse_oid__init,
+ filter_sparse_path__init,
+};
+
+void *list_objects_filter__init(
+ struct oidset *omitted,
+ struct list_objects_filter_options *filter_options,
+ filter_object_fn *filter_fn,
+ filter_free_fn *filter_free_fn)
+{
+ filter_init_fn init_fn;
+
+ assert((sizeof(s_filters) / sizeof(s_filters[0])) == LOFC__COUNT);
+
+ if (filter_options->choice >= LOFC__COUNT)
+ die("invalid list-objects filter choice: %d",
+ filter_options->choice);
+
+ init_fn = s_filters[filter_options->choice];
+ if (init_fn)
+ return init_fn(omitted, filter_options,
+ filter_fn, filter_free_fn);
+ *filter_fn = NULL;
+ *filter_free_fn = NULL;
+ return NULL;
+}
diff --git a/list-objects-filter.h b/list-objects-filter.h
new file mode 100644
index 0000000000..a963d0274c
--- /dev/null
+++ b/list-objects-filter.h
@@ -0,0 +1,77 @@
+#ifndef LIST_OBJECTS_FILTER_H
+#define LIST_OBJECTS_FILTER_H
+
+/*
+ * During list-object traversal we allow certain objects to be
+ * filtered (omitted) from the result. The active filter uses
+ * these result values to guide list-objects.
+ *
+ * _ZERO : Do nothing with the object at this time. It may
+ * be revisited if it appears in another place in
+ * the tree or in another commit during the overall
+ * traversal.
+ *
+ * _MARK_SEEN : Mark this object as "SEEN" in the object flags.
+ * This will prevent it from being revisited during
+ * the remainder of the traversal. This DOES NOT
+ * imply that it will be included in the results.
+ *
+ * _DO_SHOW : Show this object in the results (call show() on it).
+ * In general, objects should only be shown once, but
+ * this result DOES NOT imply that we mark it SEEN.
+ *
+ * Most of the time, you want the combination (_MARK_SEEN | _DO_SHOW)
+ * but they can be used independently, such as when sparse-checkout
+ * pattern matching is being applied.
+ *
+ * A _MARK_SEEN without _DO_SHOW can be called a hard-omit -- the
+ * object is not shown and will never be reconsidered (unless a
+ * previous iteration has already shown it).
+ *
+ * A _DO_SHOW without _MARK_SEEN can be used, for example, to
+ * include a directory, but then revisit it to selectively include
+ * or omit objects within it.
+ *
+ * A _ZERO can be called a provisional-omit -- the object is NOT shown,
+ * but *may* be revisited (if the object appears again in the traversal).
+ * Therefore, it will be omitted from the results *unless* a later
+ * iteration causes it to be shown.
+ */
+enum list_objects_filter_result {
+ LOFR_ZERO = 0,
+ LOFR_MARK_SEEN = 1<<0,
+ LOFR_DO_SHOW = 1<<1,
+};
+
+enum list_objects_filter_situation {
+ LOFS_BEGIN_TREE,
+ LOFS_END_TREE,
+ LOFS_BLOB
+};
+
+typedef enum list_objects_filter_result (*filter_object_fn)(
+ enum list_objects_filter_situation filter_situation,
+ struct object *obj,
+ const char *pathname,
+ const char *filename,
+ void *filter_data);
+
+typedef void (*filter_free_fn)(void *filter_data);
+
+/*
+ * Constructor for the set of defined list-objects filters.
+ * Returns a generic "void *filter_data".
+ *
+ * The returned "filter_fn" will be used by traverse_commit_list()
+ * to filter the results.
+ *
+ * The returned "filter_free_fn" is a destructor for the
+ * filter_data.
+ */
+void *list_objects_filter__init(
+ struct oidset *omitted,
+ struct list_objects_filter_options *filter_options,
+ filter_object_fn *filter_fn,
+ filter_free_fn *filter_free_fn);
+
+#endif /* LIST_OBJECTS_FILTER_H */
diff --git a/list-objects.c b/list-objects.c
index b3931fa434..0966cdc9fa 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -7,16 +7,21 @@
#include "tree-walk.h"
#include "revision.h"
#include "list-objects.h"
+#include "list-objects-filter.h"
+#include "list-objects-filter-options.h"
static void process_blob(struct rev_info *revs,
struct blob *blob,
show_object_fn show,
struct strbuf *path,
const char *name,
- void *cb_data)
+ void *cb_data,
+ filter_object_fn filter_fn,
+ void *filter_data)
{
struct object *obj = &blob->object;
size_t pathlen;
+ enum list_objects_filter_result r = LOFR_MARK_SEEN | LOFR_DO_SHOW;
if (!revs->blob_objects)
return;
@@ -24,11 +29,17 @@ static void process_blob(struct rev_info *revs,
die("bad blob object");
if (obj->flags & (UNINTERESTING | SEEN))
return;
- obj->flags |= SEEN;
pathlen = path->len;
strbuf_addstr(path, name);
- show(obj, path->buf, cb_data);
+ if (filter_fn)
+ r = filter_fn(LOFS_BLOB, obj,
+ path->buf, &path->buf[pathlen],
+ filter_data);
+ if (r & LOFR_MARK_SEEN)
+ obj->flags |= SEEN;
+ if (r & LOFR_DO_SHOW)
+ show(obj, path->buf, cb_data);
strbuf_setlen(path, pathlen);
}
@@ -69,7 +80,9 @@ static void process_tree(struct rev_info *revs,
show_object_fn show,
struct strbuf *base,
const char *name,
- void *cb_data)
+ void *cb_data,
+ filter_object_fn filter_fn,
+ void *filter_data)
{
struct object *obj = &tree->object;
struct tree_desc desc;
@@ -77,6 +90,7 @@ static void process_tree(struct rev_info *revs,
enum interesting match = revs->diffopt.pathspec.nr == 0 ?
all_entries_interesting: entry_not_interesting;
int baselen = base->len;
+ enum list_objects_filter_result r = LOFR_MARK_SEEN | LOFR_DO_SHOW;
if (!revs->tree_objects)
return;
@@ -90,9 +104,15 @@ static void process_tree(struct rev_info *revs,
die("bad tree object %s", oid_to_hex(&obj->oid));
}
- obj->flags |= SEEN;
strbuf_addstr(base, name);
- show(obj, base->buf, cb_data);
+ if (filter_fn)
+ r = filter_fn(LOFS_BEGIN_TREE, obj,
+ base->buf, &base->buf[baselen],
+ filter_data);
+ if (r & LOFR_MARK_SEEN)
+ obj->flags |= SEEN;
+ if (r & LOFR_DO_SHOW)
+ show(obj, base->buf, cb_data);
if (base->len)
strbuf_addch(base, '/');
@@ -112,7 +132,7 @@ static void process_tree(struct rev_info *revs,
process_tree(revs,
lookup_tree(entry.oid),
show, base, entry.path,
- cb_data);
+ cb_data, filter_fn, filter_data);
else if (S_ISGITLINK(entry.mode))
process_gitlink(revs, entry.oid->hash,
show, base, entry.path,
@@ -121,8 +141,19 @@ static void process_tree(struct rev_info *revs,
process_blob(revs,
lookup_blob(entry.oid),
show, base, entry.path,
- cb_data);
+ cb_data, filter_fn, filter_data);
}
+
+ if (filter_fn) {
+ r = filter_fn(LOFS_END_TREE, obj,
+ base->buf, &base->buf[baselen],
+ filter_data);
+ if (r & LOFR_MARK_SEEN)
+ obj->flags |= SEEN;
+ if (r & LOFR_DO_SHOW)
+ show(obj, base->buf, cb_data);
+ }
+
strbuf_setlen(base, baselen);
free_tree_buffer(tree);
}
@@ -183,25 +214,17 @@ static void add_pending_tree(struct rev_info *revs, struct tree *tree)
add_pending_object(revs, &tree->object, "");
}
-void traverse_commit_list(struct rev_info *revs,
- show_commit_fn show_commit,
- show_object_fn show_object,
- void *data)
+static void traverse_trees_and_blobs(struct rev_info *revs,
+ struct strbuf *base,
+ show_object_fn show_object,
+ void *show_data,
+ filter_object_fn filter_fn,
+ void *filter_data)
{
int i;
- struct commit *commit;
- struct strbuf base;
- strbuf_init(&base, PATH_MAX);
- while ((commit = get_revision(revs)) != NULL) {
- /*
- * an uninteresting boundary commit may not have its tree
- * parsed yet, but we are not going to show them anyway
- */
- if (commit->tree)
- add_pending_tree(revs, commit->tree);
- show_commit(commit, data);
- }
+ assert(base->len == 0);
+
for (i = 0; i < revs->pending.nr; i++) {
struct object_array_entry *pending = revs->pending.objects + i;
struct object *obj = pending->item;
@@ -211,24 +234,89 @@ void traverse_commit_list(struct rev_info *revs,
continue;
if (obj->type == OBJ_TAG) {
obj->flags |= SEEN;
- show_object(obj, name, data);
+ show_object(obj, name, show_data);
continue;
}
if (!path)
path = "";
if (obj->type == OBJ_TREE) {
process_tree(revs, (struct tree *)obj, show_object,
- &base, path, data);
+ base, path, show_data,
+ filter_fn, filter_data);
continue;
}
if (obj->type == OBJ_BLOB) {
process_blob(revs, (struct blob *)obj, show_object,
- &base, path, data);
+ base, path, show_data,
+ filter_fn, filter_data);
continue;
}
die("unknown pending object %s (%s)",
oid_to_hex(&obj->oid), name);
}
object_array_clear(&revs->pending);
- strbuf_release(&base);
+}
+
+static void do_traverse(struct rev_info *revs,
+ show_commit_fn show_commit,
+ show_object_fn show_object,
+ void *show_data,
+ filter_object_fn filter_fn,
+ void *filter_data)
+{
+ struct commit *commit;
+ struct strbuf csp; /* callee's scratch pad */
+ strbuf_init(&csp, PATH_MAX);
+
+ while ((commit = get_revision(revs)) != NULL) {
+ /*
+ * an uninteresting boundary commit may not have its tree
+ * parsed yet, but we are not going to show them anyway
+ */
+ if (commit->tree)
+ add_pending_tree(revs, commit->tree);
+ show_commit(commit, show_data);
+
+ if (revs->tree_blobs_in_commit_order)
+ /*
+ * NEEDSWORK: Adding the tree and then flushing it here
+ * needs a reallocation for each commit. Can we pass the
+ * tree directory without allocation churn?
+ */
+ traverse_trees_and_blobs(revs, &csp,
+ show_object, show_data,
+ filter_fn, filter_data);
+ }
+ traverse_trees_and_blobs(revs, &csp,
+ show_object, show_data,
+ filter_fn, filter_data);
+ strbuf_release(&csp);
+}
+
+void traverse_commit_list(struct rev_info *revs,
+ show_commit_fn show_commit,
+ show_object_fn show_object,
+ void *show_data)
+{
+ do_traverse(revs, show_commit, show_object, show_data, NULL, NULL);
+}
+
+void traverse_commit_list_filtered(
+ struct list_objects_filter_options *filter_options,
+ struct rev_info *revs,
+ show_commit_fn show_commit,
+ show_object_fn show_object,
+ void *show_data,
+ struct oidset *omitted)
+{
+ filter_object_fn filter_fn = NULL;
+ filter_free_fn filter_free_fn = NULL;
+ void *filter_data = NULL;
+
+ filter_data = list_objects_filter__init(omitted, filter_options,
+ &filter_fn, &filter_free_fn);
+ do_traverse(revs, show_commit, show_object, show_data,
+ filter_fn, filter_data);
+ if (filter_data && filter_free_fn)
+ filter_free_fn(filter_data);
}
diff --git a/list-objects.h b/list-objects.h
index 0cebf8585c..aa618d7f45 100644
--- a/list-objects.h
+++ b/list-objects.h
@@ -8,4 +8,15 @@ void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, voi
typedef void (*show_edge_fn)(struct commit *);
void mark_edges_uninteresting(struct rev_info *, show_edge_fn);
-#endif
+struct oidset;
+struct list_objects_filter_options;
+
+void traverse_commit_list_filtered(
+ struct list_objects_filter_options *filter_options,
+ struct rev_info *revs,
+ show_commit_fn show_commit,
+ show_object_fn show_object,
+ void *show_data,
+ struct oidset *omitted);
+
+#endif /* LIST_OBJECTS_H */
diff --git a/object.h b/object.h
index df8abe96f7..f34461d4af 100644
--- a/object.h
+++ b/object.h
@@ -38,6 +38,7 @@ struct object_array {
* http-push.c: 16-----19
* commit.c: 16-----19
* sha1_name.c: 20
+ * list-objects-filter.c: 21
* builtin/fsck.c: 0--3
*/
#define FLAG_BITS 27
diff --git a/oidmap.h b/oidmap.h
index 18f54cde14..d3cd2bb590 100644
--- a/oidmap.h
+++ b/oidmap.h
@@ -65,4 +65,26 @@ extern void *oidmap_put(struct oidmap *map, void *entry);
*/
extern void *oidmap_remove(struct oidmap *map, const struct object_id *key);
+
+struct oidmap_iter {
+ struct hashmap_iter h_iter;
+};
+
+static inline void oidmap_iter_init(struct oidmap *map, struct oidmap_iter *iter)
+{
+ hashmap_iter_init(&map->map, &iter->h_iter);
+}
+
+static inline void *oidmap_iter_next(struct oidmap_iter *iter)
+{
+ return hashmap_iter_next(&iter->h_iter);
+}
+
+static inline void *oidmap_iter_first(struct oidmap *map,
+ struct oidmap_iter *iter)
+{
+ oidmap_iter_init(map, iter);
+ return oidmap_iter_next(iter);
+}
+
#endif
diff --git a/oidset.c b/oidset.c
index f1f874aaad..454c54f933 100644
--- a/oidset.c
+++ b/oidset.c
@@ -24,6 +24,16 @@ int oidset_insert(struct oidset *set, const struct object_id *oid)
return 0;
}
+int oidset_remove(struct oidset *set, const struct object_id *oid)
+{
+ struct oidmap_entry *entry;
+
+ entry = oidmap_remove(&set->map, oid);
+ free(entry);
+
+ return (entry != NULL);
+}
+
void oidset_clear(struct oidset *set)
{
oidmap_free(&set->map, 1);
diff --git a/oidset.h b/oidset.h
index f4c9e0f9c0..783abceccd 100644
--- a/oidset.h
+++ b/oidset.h
@@ -24,6 +24,12 @@ struct oidset {
#define OIDSET_INIT { OIDMAP_INIT }
+
+static inline void oidset_init(struct oidset *set, size_t initial_size)
+{
+ return oidmap_init(&set->map, initial_size);
+}
+
/**
* Returns true iff `set` contains `oid`.
*/
@@ -39,9 +45,39 @@ int oidset_contains(const struct oidset *set, const struct object_id *oid);
int oidset_insert(struct oidset *set, const struct object_id *oid);
/**
+ * Remove the oid from the set.
+ *
+ * Returns 1 if the oid was present in the set, 0 otherwise.
+ */
+int oidset_remove(struct oidset *set, const struct object_id *oid);
+
+/**
* Remove all entries from the oidset, freeing any resources associated with
* it.
*/
void oidset_clear(struct oidset *set);
+struct oidset_iter {
+ struct oidmap_iter m_iter;
+};
+
+static inline void oidset_iter_init(struct oidset *set,
+ struct oidset_iter *iter)
+{
+ oidmap_iter_init(&set->map, &iter->m_iter);
+}
+
+static inline struct object_id *oidset_iter_next(struct oidset_iter *iter)
+{
+ struct oidmap_entry *e = oidmap_iter_next(&iter->m_iter);
+ return e ? &e->oid : NULL;
+}
+
+static inline struct object_id *oidset_iter_first(struct oidset *set,
+ struct oidset_iter *iter)
+{
+ oidset_iter_init(set, iter);
+ return oidset_iter_next(iter);
+}
+
#endif /* OIDSET_H */
diff --git a/path.h b/path.h
index 9541620c79..1ccd0373c9 100644
--- a/path.h
+++ b/path.h
@@ -4,53 +4,144 @@
struct repository;
/*
- * Return a statically allocated filename, either generically (mkpath), in
- * the repository directory (git_path), or in a submodule's repository
- * directory (git_path_submodule). In all cases, note that the result
- * may be overwritten by another call to _any_ of the functions. Consider
- * using the safer "dup" or "strbuf" formats below (in some cases, the
- * unsafe versions have already been removed).
+ * The result to all functions which return statically allocated memory may be
+ * overwritten by another call to _any_ one of these functions. Consider using
+ * the safer variants which operate on strbufs or return allocated memory.
*/
-extern const char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
-extern const char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
-extern const char *git_common_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
+/*
+ * Return a statically allocated path.
+ */
+extern const char *mkpath(const char *fmt, ...)
+ __attribute__((format (printf, 1, 2)));
+
+/*
+ * Return a path.
+ */
+extern char *mkpathdup(const char *fmt, ...)
+ __attribute__((format (printf, 1, 2)));
+
+/*
+ * Construct a path and place the result in the provided buffer `buf`.
+ */
extern char *mksnpath(char *buf, size_t n, const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
-extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
- __attribute__((format (printf, 2, 3)));
+
+/*
+ * The `git_common_path` family of functions will construct a path into a
+ * repository's common git directory, which is shared by all worktrees.
+ */
+
+/*
+ * Constructs a path into the common git directory of repository `repo` and
+ * append it in the provided buffer `sb`.
+ */
extern void strbuf_git_common_path(struct strbuf *sb,
const struct repository *repo,
const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
-extern char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
- __attribute__((format (printf, 2, 3)));
-extern int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
- const char *fmt, ...)
- __attribute__((format (printf, 3, 4)));
-extern char *git_pathdup(const char *fmt, ...)
- __attribute__((format (printf, 1, 2)));
-extern char *mkpathdup(const char *fmt, ...)
+
+/*
+ * Return a statically allocated path into the main repository's
+ * (the_repository) common git directory.
+ */
+extern const char *git_common_path(const char *fmt, ...)
__attribute__((format (printf, 1, 2)));
-extern char *git_pathdup_submodule(const char *path, const char *fmt, ...)
- __attribute__((format (printf, 2, 3)));
+
+/*
+ * The `git_path` family of functions will construct a path into a repository's
+ * git directory.
+ *
+ * These functions will perform adjustments to the resultant path to account
+ * for special paths which are either considered common among worktrees (e.g.
+ * paths into the object directory) or have been explicitly set via an
+ * environment variable or config (e.g. path to the index file).
+ *
+ * For an exhaustive list of the adjustments made look at `common_list` and
+ * `adjust_git_path` in path.c.
+ */
+
+/*
+ * Return a path into the git directory of repository `repo`.
+ */
extern char *repo_git_path(const struct repository *repo,
const char *fmt, ...)
__attribute__((format (printf, 2, 3)));
+
+/*
+ * Construct a path into the git directory of repository `repo` and append it
+ * to the provided buffer `sb`.
+ */
extern void strbuf_repo_git_path(struct strbuf *sb,
const struct repository *repo,
const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
+/*
+ * Return a statically allocated path into the main repository's
+ * (the_repository) git directory.
+ */
+extern const char *git_path(const char *fmt, ...)
+ __attribute__((format (printf, 1, 2)));
+
+/*
+ * Return a path into the main repository's (the_repository) git directory.
+ */
+extern char *git_pathdup(const char *fmt, ...)
+ __attribute__((format (printf, 1, 2)));
+
+/*
+ * Construct a path into the main repository's (the_repository) git directory
+ * and place it in the provided buffer `buf`, the contents of the buffer will
+ * be overridden.
+ */
+extern char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
+ __attribute__((format (printf, 2, 3)));
+
+/*
+ * Construct a path into the main repository's (the_repository) git directory
+ * and append it to the provided buffer `sb`.
+ */
+extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
+ __attribute__((format (printf, 2, 3)));
+
+/*
+ * Return a path into the worktree of repository `repo`.
+ *
+ * If the repository doesn't have a worktree NULL is returned.
+ */
extern char *repo_worktree_path(const struct repository *repo,
const char *fmt, ...)
__attribute__((format (printf, 2, 3)));
+
+/*
+ * Construct a path into the worktree of repository `repo` and append it
+ * to the provided buffer `sb`.
+ *
+ * If the repository doesn't have a worktree nothing will be appended to `sb`.
+ */
extern void strbuf_repo_worktree_path(struct strbuf *sb,
const struct repository *repo,
const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
+/*
+ * Return a path into a submodule's git directory located at `path`. `path`
+ * must only reference a submodule of the main repository (the_repository).
+ */
+extern char *git_pathdup_submodule(const char *path, const char *fmt, ...)
+ __attribute__((format (printf, 2, 3)));
+
+/*
+ * Construct a path into a submodule's git directory located at `path` and
+ * append it to the provided buffer `sb`. `path` must only reference a
+ * submodule of the main repository (the_repository).
+ */
+extern int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
+ const char *fmt, ...)
+ __attribute__((format (printf, 3, 4)));
+
extern void report_linked_checkout_garbage(void);
/*
diff --git a/pretty.h b/pretty.h
new file mode 100644
index 0000000000..5c85d94e33
--- /dev/null
+++ b/pretty.h
@@ -0,0 +1,131 @@
+#ifndef PRETTY_H
+#define PRETTY_H
+
+struct commit;
+
+/* Commit formats */
+enum cmit_fmt {
+ CMIT_FMT_RAW,
+ CMIT_FMT_MEDIUM,
+ CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
+ CMIT_FMT_SHORT,
+ CMIT_FMT_FULL,
+ CMIT_FMT_FULLER,
+ CMIT_FMT_ONELINE,
+ CMIT_FMT_EMAIL,
+ CMIT_FMT_MBOXRD,
+ CMIT_FMT_USERFORMAT,
+
+ CMIT_FMT_UNSPECIFIED
+};
+
+struct pretty_print_context {
+ /*
+ * Callers should tweak these to change the behavior of pp_* functions.
+ */
+ enum cmit_fmt fmt;
+ int abbrev;
+ const char *after_subject;
+ int preserve_subject;
+ struct date_mode date_mode;
+ unsigned date_mode_explicit:1;
+ int print_email_subject;
+ int expand_tabs_in_log;
+ int need_8bit_cte;
+ char *notes_message;
+ struct reflog_walk_info *reflog_info;
+ struct rev_info *rev;
+ const char *output_encoding;
+ struct string_list *mailmap;
+ int color;
+ struct ident_split *from_ident;
+
+ /*
+ * Fields below here are manipulated internally by pp_* functions and
+ * should not be counted on by callers.
+ */
+ struct string_list in_body_headers;
+ int graph_width;
+};
+
+/* Check whether commit format is mail. */
+static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
+{
+ return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD);
+}
+
+struct userformat_want {
+ unsigned notes:1;
+};
+
+/* Set the flag "w->notes" if there is placeholder %N in "fmt". */
+void userformat_find_requirements(const char *fmt, struct userformat_want *w);
+
+/*
+ * Shortcut for invoking pretty_print_commit if we do not have any context.
+ * Context would be set empty except "fmt".
+ */
+void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
+ struct strbuf *sb);
+
+/*
+ * Get information about user and date from "line", format it and
+ * put it into "sb".
+ * Format of "line" must be readable for split_ident_line function.
+ * The resulting format is "what: name <email> date".
+ */
+void pp_user_info(struct pretty_print_context *pp, const char *what,
+ struct strbuf *sb, const char *line,
+ const char *encoding);
+
+/*
+ * Format title line of commit message taken from "msg_p" and
+ * put it into "sb".
+ * First line of "msg_p" is also affected.
+ */
+void pp_title_line(struct pretty_print_context *pp, const char **msg_p,
+ struct strbuf *sb, const char *encoding,
+ int need_8bit_cte);
+
+/*
+ * Get current state of commit message from "msg_p" and continue formatting
+ * by adding indentation and '>' signs. Put result into "sb".
+ */
+void pp_remainder(struct pretty_print_context *pp, const char **msg_p,
+ struct strbuf *sb, int indent);
+
+/*
+ * Create a text message about commit using given "format" and "context".
+ * Put the result to "sb".
+ * Please use this function for custom formats.
+ */
+void format_commit_message(const struct commit *commit,
+ const char *format, struct strbuf *sb,
+ const struct pretty_print_context *context);
+
+/*
+ * Parse given arguments from "arg", check it for correctness and
+ * fill struct rev_info.
+ */
+void get_commit_format(const char *arg, struct rev_info *);
+
+/*
+ * Make a commit message with all rules from given "pp"
+ * and put it into "sb".
+ * Please use this function if you have a context (candidate for "pp").
+ */
+void pretty_print_commit(struct pretty_print_context *pp,
+ const struct commit *commit,
+ struct strbuf *sb);
+
+/*
+ * Change line breaks in "msg" to "line_separator" and put it into "sb".
+ * Return "msg" itself.
+ */
+const char *format_subject(struct strbuf *sb, const char *msg,
+ const char *line_separator);
+
+/* Check if "cmit_fmt" will produce an empty output. */
+int commit_format_is_empty(enum cmit_fmt);
+
+#endif /* PRETTY_H */
diff --git a/revision.c b/revision.c
index f6a3da5cd9..72f2b4572e 100644
--- a/revision.c
+++ b/revision.c
@@ -1855,6 +1855,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->dense = 0;
} else if (!strcmp(arg, "--show-all")) {
revs->show_all = 1;
+ } else if (!strcmp(arg, "--in-commit-order")) {
+ revs->tree_blobs_in_commit_order = 1;
} else if (!strcmp(arg, "--remove-empty")) {
revs->remove_empty_trees = 1;
} else if (!strcmp(arg, "--merges")) {
diff --git a/revision.h b/revision.h
index 54761200ad..19dc9bdddb 100644
--- a/revision.h
+++ b/revision.h
@@ -4,7 +4,7 @@
#include "parse-options.h"
#include "grep.h"
#include "notes.h"
-#include "commit.h"
+#include "pretty.h"
#include "diff.h"
/* Remember to update object flag allocation in object.h */
@@ -121,7 +121,8 @@ struct rev_info {
bisect:1,
ancestry_path:1,
first_parent_only:1,
- line_level_traverse:1;
+ line_level_traverse:1,
+ tree_blobs_in_commit_order:1;
/* Diff flags */
unsigned int diff:1,
diff --git a/sequencer.c b/sequencer.c
index c8cb20c1eb..894d12ad72 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -797,6 +797,13 @@ static const char *command_to_string(const enum todo_command command)
die("Unknown command: %d", command);
}
+static char command_to_char(const enum todo_command command)
+{
+ if (command < TODO_COMMENT && todo_command_info[command].c)
+ return todo_command_info[command].c;
+ return comment_line_char;
+}
+
static int is_noop(const enum todo_command command)
{
return TODO_NOOP <= command;
@@ -1270,6 +1277,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
bol += padding;
if (item->command == TODO_EXEC) {
+ item->commit = NULL;
item->arg = bol;
item->arg_len = (int)(eol - bol);
return 0;
@@ -2445,14 +2453,16 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
strbuf_release(&sob);
}
-int sequencer_make_script(int keep_empty, FILE *out,
- int argc, const char **argv)
+int sequencer_make_script(FILE *out, int argc, const char **argv,
+ unsigned flags)
{
char *format = NULL;
struct pretty_print_context pp = {0};
struct strbuf buf = STRBUF_INIT;
struct rev_info revs;
struct commit *commit;
+ int keep_empty = flags & TODO_LIST_KEEP_EMPTY;
+ const char *insn = flags & TODO_LIST_ABBREVIATE_CMDS ? "p" : "pick";
init_revisions(&revs, NULL);
revs.verbose_header = 1;
@@ -2485,7 +2495,8 @@ int sequencer_make_script(int keep_empty, FILE *out,
strbuf_reset(&buf);
if (!keep_empty && is_original_commit_empty(commit))
strbuf_addf(&buf, "%c ", comment_line_char);
- strbuf_addf(&buf, "pick %s ", oid_to_hex(&commit->object.oid));
+ strbuf_addf(&buf, "%s %s ", insn,
+ oid_to_hex(&commit->object.oid));
pretty_print_commit(&pp, commit, &buf);
strbuf_addch(&buf, '\n');
fputs(buf.buf, out);
@@ -2494,61 +2505,90 @@ int sequencer_make_script(int keep_empty, FILE *out,
return 0;
}
-
-int transform_todo_ids(int shorten_ids)
+/*
+ * Add commands after pick and (series of) squash/fixup commands
+ * in the todo list.
+ */
+int sequencer_add_exec_commands(const char *commands)
{
const char *todo_file = rebase_path_todo();
struct todo_list todo_list = TODO_LIST_INIT;
- int fd, res, i;
- FILE *out;
+ struct todo_item *item;
+ struct strbuf *buf = &todo_list.buf;
+ size_t offset = 0, commands_len = strlen(commands);
+ int i, first;
- strbuf_reset(&todo_list.buf);
- fd = open(todo_file, O_RDONLY);
- if (fd < 0)
- return error_errno(_("could not open '%s'"), todo_file);
- if (strbuf_read(&todo_list.buf, fd, 0) < 0) {
- close(fd);
+ if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
return error(_("could not read '%s'."), todo_file);
- }
- close(fd);
- res = parse_insn_buffer(todo_list.buf.buf, &todo_list);
- if (res) {
+ if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) {
todo_list_release(&todo_list);
return error(_("unusable todo list: '%s'"), todo_file);
}
- out = fopen(todo_file, "w");
- if (!out) {
+ first = 1;
+ /* insert <commands> before every pick except the first one */
+ for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) {
+ if (item->command == TODO_PICK && !first) {
+ strbuf_insert(buf, item->offset_in_buf + offset,
+ commands, commands_len);
+ offset += commands_len;
+ }
+ first = 0;
+ }
+
+ /* append final <commands> */
+ strbuf_add(buf, commands, commands_len);
+
+ i = write_message(buf->buf, buf->len, todo_file, 0);
+ todo_list_release(&todo_list);
+ return i;
+}
+
+int transform_todos(unsigned flags)
+{
+ const char *todo_file = rebase_path_todo();
+ struct todo_list todo_list = TODO_LIST_INIT;
+ struct strbuf buf = STRBUF_INIT;
+ struct todo_item *item;
+ int i;
+
+ if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
+ return error(_("could not read '%s'."), todo_file);
+
+ if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) {
todo_list_release(&todo_list);
- return error(_("unable to open '%s' for writing"), todo_file);
+ return error(_("unusable todo list: '%s'"), todo_file);
}
- for (i = 0; i < todo_list.nr; i++) {
- struct todo_item *item = todo_list.items + i;
- int bol = item->offset_in_buf;
- const char *p = todo_list.buf.buf + bol;
- int eol = i + 1 < todo_list.nr ?
- todo_list.items[i + 1].offset_in_buf :
- todo_list.buf.len;
-
- if (item->command >= TODO_EXEC && item->command != TODO_DROP)
- fwrite(p, eol - bol, 1, out);
- else {
- const char *id = shorten_ids ?
- short_commit_name(item->commit) :
- oid_to_hex(&item->commit->object.oid);
- int len;
-
- p += strspn(p, " \t"); /* left-trim command */
- len = strcspn(p, " \t"); /* length of command */
-
- fprintf(out, "%.*s %s %.*s\n",
- len, p, id, item->arg_len, item->arg);
+
+ for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) {
+ /* if the item is not a command write it and continue */
+ if (item->command >= TODO_COMMENT) {
+ strbuf_addf(&buf, "%.*s\n", item->arg_len, item->arg);
+ continue;
}
+
+ /* add command to the buffer */
+ if (flags & TODO_LIST_ABBREVIATE_CMDS)
+ strbuf_addch(&buf, command_to_char(item->command));
+ else
+ strbuf_addstr(&buf, command_to_string(item->command));
+
+ /* add commit id */
+ if (item->commit) {
+ const char *oid = flags & TODO_LIST_SHORTEN_IDS ?
+ short_commit_name(item->commit) :
+ oid_to_hex(&item->commit->object.oid);
+
+ strbuf_addf(&buf, " %s", oid);
+ }
+ /* add all the rest */
+ strbuf_addf(&buf, " %.*s\n", item->arg_len, item->arg);
}
- fclose(out);
+
+ i = write_message(buf.buf, buf.len, todo_file, 0);
todo_list_release(&todo_list);
- return 0;
+ return i;
}
enum check_level {
diff --git a/sequencer.h b/sequencer.h
index 6f3d3df82c..81f6d7d393 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -45,10 +45,14 @@ int sequencer_continue(struct replay_opts *opts);
int sequencer_rollback(struct replay_opts *opts);
int sequencer_remove_state(struct replay_opts *opts);
-int sequencer_make_script(int keep_empty, FILE *out,
- int argc, const char **argv);
+#define TODO_LIST_KEEP_EMPTY (1U << 0)
+#define TODO_LIST_SHORTEN_IDS (1U << 1)
+#define TODO_LIST_ABBREVIATE_CMDS (1U << 2)
+int sequencer_make_script(FILE *out, int argc, const char **argv,
+ unsigned flags);
-int transform_todo_ids(int shorten_ids);
+int sequencer_add_exec_commands(const char *command);
+int transform_todos(unsigned flags);
int check_todo_list(void);
int skip_unnecessary_picks(void);
int rearrange_squash(void);
diff --git a/strbuf.c b/strbuf.c
index 323c49ceb3..8007be8fba 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -11,6 +11,28 @@ int starts_with(const char *str, const char *prefix)
return 0;
}
+int skip_to_optional_arg_default(const char *str, const char *prefix,
+ const char **arg, const char *def)
+{
+ const char *p;
+
+ if (!skip_prefix(str, prefix, &p))
+ return 0;
+
+ if (!*p) {
+ if (arg)
+ *arg = def;
+ return 1;
+ }
+
+ if (*p != '=')
+ return 0;
+
+ if (arg)
+ *arg = p + 1;
+ return 1;
+}
+
/*
* Used as the default ->buf value, so that people can always assume
* buf is non NULL and ->buf is NUL terminated even for a freshly
@@ -386,12 +408,15 @@ ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint)
ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
{
+ size_t oldalloc = sb->alloc;
ssize_t cnt;
strbuf_grow(sb, hint ? hint : 8192);
cnt = xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
if (cnt > 0)
strbuf_setlen(sb, sb->len + cnt);
+ else if (oldalloc == 0)
+ strbuf_release(sb);
return cnt;
}
diff --git a/submodule.c b/submodule.c
index fa25888783..2967704317 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,3 +1,5 @@
+#define NO_THE_INDEX_COMPATIBILITY_MACROS
+
#include "cache.h"
#include "repository.h"
#include "config.h"
@@ -55,14 +57,15 @@ int is_gitmodules_unmerged(const struct index_state *istate)
* future version when we learn to stage the changes we do ourselves without
* staging any previous modifications.
*/
-int is_staging_gitmodules_ok(const struct index_state *istate)
+int is_staging_gitmodules_ok(struct index_state *istate)
{
int pos = index_name_pos(istate, GITMODULES_FILE, strlen(GITMODULES_FILE));
if ((pos >= 0) && (pos < istate->cache_nr)) {
struct stat st;
if (lstat(GITMODULES_FILE, &st) == 0 &&
- ce_match_stat(istate->cache[pos], &st, CE_MATCH_IGNORE_FSMONITOR) & DATA_CHANGED)
+ ie_match_stat(istate, istate->cache[pos], &st,
+ CE_MATCH_IGNORE_FSMONITOR) & DATA_CHANGED)
return 0;
}
@@ -143,9 +146,9 @@ int remove_path_from_gitmodules(const char *path)
return 0;
}
-void stage_updated_gitmodules(void)
+void stage_updated_gitmodules(struct index_state *istate)
{
- if (add_file_to_cache(GITMODULES_FILE, 0))
+ if (add_file_to_index(istate, GITMODULES_FILE, 0))
die(_("staging updated .gitmodules failed"));
}
@@ -1178,7 +1181,7 @@ int submodule_touches_in_range(struct object_id *excl_oid,
struct submodule_parallel_fetch {
int count;
struct argv_array args;
- const char *work_tree;
+ struct repository *r;
const char *prefix;
int command_line_option;
int default_option;
@@ -1199,7 +1202,7 @@ static int get_fetch_recurse_config(const struct submodule *submodule,
int fetch_recurse = submodule->fetch_recurse;
key = xstrfmt("submodule.%s.fetchRecurseSubmodules", submodule->name);
- if (!repo_config_get_string_const(the_repository, key, &value)) {
+ if (!repo_config_get_string_const(spf->r, key, &value)) {
fetch_recurse = parse_fetch_recurse_submodules_arg(key, value);
}
free(key);
@@ -1218,11 +1221,11 @@ static int get_next_submodule(struct child_process *cp,
int ret = 0;
struct submodule_parallel_fetch *spf = data;
- for (; spf->count < active_nr; spf->count++) {
+ for (; spf->count < spf->r->index->cache_nr; spf->count++) {
struct strbuf submodule_path = STRBUF_INIT;
struct strbuf submodule_git_dir = STRBUF_INIT;
struct strbuf submodule_prefix = STRBUF_INIT;
- const struct cache_entry *ce = active_cache[spf->count];
+ const struct cache_entry *ce = spf->r->index->cache[spf->count];
const char *git_dir, *default_argv;
const struct submodule *submodule;
struct submodule default_submodule = SUBMODULE_INIT;
@@ -1230,7 +1233,7 @@ static int get_next_submodule(struct child_process *cp,
if (!S_ISGITLINK(ce->ce_mode))
continue;
- submodule = submodule_from_path(&null_oid, ce->name);
+ submodule = submodule_from_cache(spf->r, &null_oid, ce->name);
if (!submodule) {
const char *name = default_name_or_path(ce->name);
if (name) {
@@ -1256,7 +1259,7 @@ static int get_next_submodule(struct child_process *cp,
continue;
}
- strbuf_addf(&submodule_path, "%s/%s", spf->work_tree, ce->name);
+ strbuf_repo_worktree_path(&submodule_path, spf->r, "%s", ce->name);
strbuf_addf(&submodule_git_dir, "%s/.git", submodule_path.buf);
strbuf_addf(&submodule_prefix, "%s%s/", spf->prefix, ce->name);
git_dir = read_gitfile(submodule_git_dir.buf);
@@ -1309,7 +1312,8 @@ static int fetch_finish(int retvalue, struct strbuf *err,
return 0;
}
-int fetch_populated_submodules(const struct argv_array *options,
+int fetch_populated_submodules(struct repository *r,
+ const struct argv_array *options,
const char *prefix, int command_line_option,
int default_option,
int quiet, int max_parallel_jobs)
@@ -1317,16 +1321,16 @@ int fetch_populated_submodules(const struct argv_array *options,
int i;
struct submodule_parallel_fetch spf = SPF_INIT;
- spf.work_tree = get_git_work_tree();
+ spf.r = r;
spf.command_line_option = command_line_option;
spf.default_option = default_option;
spf.quiet = quiet;
spf.prefix = prefix;
- if (!spf.work_tree)
+ if (!r->worktree)
goto out;
- if (read_cache() < 0)
+ if (repo_read_index(r) < 0)
die("index file corrupt");
argv_array_push(&spf.args, "fetch");
diff --git a/submodule.h b/submodule.h
index f0da0277a4..b9b7ef0030 100644
--- a/submodule.h
+++ b/submodule.h
@@ -34,10 +34,10 @@ struct submodule_update_strategy {
#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
extern int is_gitmodules_unmerged(const struct index_state *istate);
-extern int is_staging_gitmodules_ok(const struct index_state *istate);
+extern int is_staging_gitmodules_ok(struct index_state *istate);
extern int update_path_in_gitmodules(const char *oldpath, const char *newpath);
extern int remove_path_from_gitmodules(const char *path);
-extern void stage_updated_gitmodules(void);
+extern void stage_updated_gitmodules(struct index_state *istate);
extern void set_diffopt_flags_from_submodule_config(struct diff_options *,
const char *path);
extern int git_default_submodule_config(const char *var, const char *value, void *cb);
@@ -76,10 +76,12 @@ extern int should_update_submodules(void);
*/
extern const struct submodule *submodule_from_ce(const struct cache_entry *ce);
extern void check_for_new_submodule_commits(struct object_id *oid);
-extern int fetch_populated_submodules(const struct argv_array *options,
- const char *prefix, int command_line_option,
- int default_option,
- int quiet, int max_parallel_jobs);
+extern int fetch_populated_submodules(struct repository *r,
+ const struct argv_array *options,
+ const char *prefix,
+ int command_line_option,
+ int default_option,
+ int quiet, int max_parallel_jobs);
extern unsigned is_submodule_modified(const char *path, int ignore_untracked);
extern int submodule_uses_gitfile(const char *path);
diff --git a/t/Makefile b/t/Makefile
index 1bb06c36f2..96317a35f4 100644
--- a/t/Makefile
+++ b/t/Makefile
@@ -8,6 +8,7 @@
#GIT_TEST_OPTS = --verbose --debug
SHELL_PATH ?= $(SHELL)
+TEST_SHELL_PATH ?= $(SHELL_PATH)
PERL_PATH ?= /usr/bin/perl
TAR ?= $(TAR)
RM ?= rm -f
@@ -23,6 +24,7 @@ endif
# Shell quote;
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
+TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
@@ -42,11 +44,11 @@ failed:
test -z "$$failed" || $(MAKE) $$failed
prove: pre-clean $(TEST_LINT)
- @echo "*** prove ***"; $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
+ @echo "*** prove ***"; $(PROVE) --exec '$(TEST_SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
$(MAKE) clean-except-prove-cache
$(T):
- @echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
+ @echo "*** $@ ***"; '$(TEST_SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
pre-clean:
$(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
diff --git a/t/helper/.gitignore b/t/helper/.gitignore
index d02f9b39ac..2bad28af92 100644
--- a/t/helper/.gitignore
+++ b/t/helper/.gitignore
@@ -1,40 +1,5 @@
-/test-chmtime
-/test-ctype
-/test-config
-/test-date
-/test-delta
-/test-drop-caches
-/test-dump-cache-tree
-/test-dump-fsmonitor
-/test-dump-split-index
-/test-dump-untracked-cache
-/test-fake-ssh
-/test-scrap-cache-tree
-/test-genrandom
-/test-hashmap
-/test-index-version
-/test-lazy-init-name-hash
-/test-line-buffer
-/test-match-trees
-/test-mergesort
-/test-mktemp
-/test-online-cpus
-/test-parse-options
-/test-path-utils
-/test-prio-queue
-/test-read-cache
-/test-ref-store
-/test-regex
-/test-revision-walking
-/test-run-command
-/test-sha1
-/test-sha1-array
-/test-sigchain
-/test-strcmp-offset
-/test-string-list
-/test-submodule-config
-/test-subprocess
-/test-svn-fe
-/test-urlmatch-normalization
-/test-wildmatch
-/test-write-cache
+*
+!*.sh
+!*.[ch]
+!*.gitignore
+
diff --git a/t/helper/test-example-decorate.c b/t/helper/test-example-decorate.c
new file mode 100644
index 0000000000..90dc97a9d0
--- /dev/null
+++ b/t/helper/test-example-decorate.c
@@ -0,0 +1,74 @@
+#include "cache.h"
+#include "object.h"
+#include "decorate.h"
+
+int cmd_main(int argc, const char **argv)
+{
+ struct decoration n;
+ struct object_id one_oid = { {1} };
+ struct object_id two_oid = { {2} };
+ struct object_id three_oid = { {3} };
+ struct object *one, *two, *three;
+
+ int decoration_a, decoration_b;
+
+ void *ret;
+
+ int i, objects_noticed = 0;
+
+ /*
+ * The struct must be zero-initialized.
+ */
+ memset(&n, 0, sizeof(n));
+
+ /*
+ * Add 2 objects, one with a non-NULL decoration and one with a NULL
+ * decoration.
+ */
+ one = lookup_unknown_object(one_oid.hash);
+ two = lookup_unknown_object(two_oid.hash);
+ ret = add_decoration(&n, one, &decoration_a);
+ if (ret)
+ die("BUG: when adding a brand-new object, NULL should be returned");
+ ret = add_decoration(&n, two, NULL);
+ if (ret)
+ die("BUG: when adding a brand-new object, NULL should be returned");
+
+ /*
+ * When re-adding an already existing object, the old decoration is
+ * returned.
+ */
+ ret = add_decoration(&n, one, NULL);
+ if (ret != &decoration_a)
+ die("BUG: when readding an already existing object, existing decoration should be returned");
+ ret = add_decoration(&n, two, &decoration_b);
+ if (ret)
+ die("BUG: when readding an already existing object, existing decoration should be returned");
+
+ /*
+ * Lookup returns the added declarations, or NULL if the object was
+ * never added.
+ */
+ ret = lookup_decoration(&n, one);
+ if (ret)
+ die("BUG: lookup should return added declaration");
+ ret = lookup_decoration(&n, two);
+ if (ret != &decoration_b)
+ die("BUG: lookup should return added declaration");
+ three = lookup_unknown_object(three_oid.hash);
+ ret = lookup_decoration(&n, three);
+ if (ret)
+ die("BUG: lookup for unknown object should return NULL");
+
+ /*
+ * The user can also loop through all entries.
+ */
+ for (i = 0; i < n.size; i++) {
+ if (n.entries[i].base)
+ objects_noticed++;
+ }
+ if (objects_noticed != 2)
+ die("BUG: should have 2 objects");
+
+ return 0;
+}
diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh
index 688313ed5c..4c1f81f167 100644
--- a/t/lib-git-svn.sh
+++ b/t/lib-git-svn.sh
@@ -17,8 +17,8 @@ SVN_TREE=$GIT_SVN_DIR/svn-tree
svn >/dev/null 2>&1
if test $? -ne 1
then
- skip_all='skipping git svn tests, svn not found'
- test_done
+ skip_all='skipping git svn tests, svn not found'
+ test_done
fi
svnrepo=$PWD/svnrepo
@@ -110,18 +110,20 @@ EOF
}
require_svnserve () {
- if test -z "$SVNSERVE_PORT"
- then
- skip_all='skipping svnserve test. (set $SVNSERVE_PORT to enable)'
- test_done
- fi
+ test_tristate GIT_TEST_SVNSERVE
+ if ! test "$GIT_TEST_SVNSERVE" = true
+ then
+ skip_all='skipping svnserve test. (set $GIT_TEST_SVNSERVE to enable)'
+ test_done
+ fi
}
start_svnserve () {
- svnserve --listen-port $SVNSERVE_PORT \
- --root "$rawsvnrepo" \
- --listen-once \
- --listen-host 127.0.0.1 &
+ SVNSERVE_PORT=${SVNSERVE_PORT-${this_test#t}}
+ svnserve --listen-port $SVNSERVE_PORT \
+ --root "$rawsvnrepo" \
+ --listen-once \
+ --listen-host 127.0.0.1 &
}
prepare_a_utf8_locale () {
diff --git a/t/perf/p7519-fsmonitor.sh b/t/perf/p7519-fsmonitor.sh
index 16d1bf72e5..65e145c02d 100755
--- a/t/perf/p7519-fsmonitor.sh
+++ b/t/perf/p7519-fsmonitor.sh
@@ -40,8 +40,7 @@ test_lazy_prereq UNTRACKED_CACHE '
'
test_lazy_prereq WATCHMAN '
- { command -v watchman >/dev/null 2>&1; ret=$?; } &&
- test $ret -ne 1
+ command -v watchman
'
if test_have_prereq WATCHMAN
diff --git a/t/t0027-auto-crlf.sh b/t/t0027-auto-crlf.sh
index 68108d956a..beb5927f77 100755
--- a/t/t0027-auto-crlf.sh
+++ b/t/t0027-auto-crlf.sh
@@ -43,19 +43,31 @@ create_gitattributes () {
} >.gitattributes
}
-create_NNO_files () {
+# Create 2 sets of files:
+# The NNO files are "Not NOrmalized in the repo. We use CRLF_mix_LF and store
+# it under different names for the different test cases, see ${pfx}
+# Depending on .gitattributes they are normalized at the next commit (or not)
+# The MIX files have different contents in the repo.
+# Depending on its contents, the "new safer autocrlf" may kick in.
+create_NNO_MIX_files () {
for crlf in false true input
do
for attr in "" auto text -text
do
for aeol in "" lf crlf
do
- pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf}
+ pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} &&
cp CRLF_mix_LF ${pfx}_LF.txt &&
cp CRLF_mix_LF ${pfx}_CRLF.txt &&
cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt &&
cp CRLF_mix_LF ${pfx}_LF_mix_CR.txt &&
- cp CRLF_mix_LF ${pfx}_CRLF_nul.txt
+ cp CRLF_mix_LF ${pfx}_CRLF_nul.txt &&
+ pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf} &&
+ cp LF ${pfx}_LF.txt &&
+ cp CRLF ${pfx}_CRLF.txt &&
+ cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt &&
+ cp LF_mix_CR ${pfx}_LF_mix_CR.txt &&
+ cp CRLF_nul ${pfx}_CRLF_nul.txt
done
done
done
@@ -136,6 +148,49 @@ commit_chk_wrnNNO () {
'
}
+# Commit a file with mixed line endings on top of different files
+# in the index. Check for warnings
+commit_MIX_chkwrn () {
+ attr=$1 ; shift
+ aeol=$1 ; shift
+ crlf=$1 ; shift
+ lfwarn=$1 ; shift
+ crlfwarn=$1 ; shift
+ lfmixcrlf=$1 ; shift
+ lfmixcr=$1 ; shift
+ crlfnul=$1 ; shift
+ pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf}
+ #Commit file with CLRF_mix_LF on top of existing file
+ create_gitattributes "$attr" $aeol &&
+ for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
+ do
+ fname=${pfx}_$f.txt &&
+ cp CRLF_mix_LF $fname &&
+ printf Z >>"$fname" &&
+ git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err"
+ done
+
+ test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" '
+ check_warning "$lfwarn" ${pfx}_LF.err
+ '
+ test_expect_success "commit file with mixed EOL onto CLRF attr=$attr aeol=$aeol crlf=$crlf" '
+ check_warning "$crlfwarn" ${pfx}_CRLF.err
+ '
+
+ test_expect_success "commit file with mixed EOL onto CRLF_mix_LF attr=$attr aeol=$aeol crlf=$crlf" '
+ check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err
+ '
+
+ test_expect_success "commit file with mixed EOL onto LF_mix_cr attr=$attr aeol=$aeol crlf=$crlf " '
+ check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err
+ '
+
+ test_expect_success "commit file with mixed EOL onto CRLF_nul attr=$attr aeol=$aeol crlf=$crlf" '
+ check_warning "$crlfnul" ${pfx}_CRLF_nul.err
+ '
+}
+
+
stats_ascii () {
case "$1" in
LF)
@@ -323,8 +378,8 @@ test_expect_success 'setup master' '
printf "\$Id: 0000000000000000000000000000000000000000 \$\r\nLINEONE\r\nLINETWO\rLINETHREE" >CRLF_mix_CR &&
printf "\$Id: 0000000000000000000000000000000000000000 \$\r\nLINEONEQ\r\nLINETWO\r\nLINETHREE" | q_to_nul >CRLF_nul &&
printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONEQ\nLINETWO\nLINETHREE" | q_to_nul >LF_nul &&
- create_NNO_files CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF &&
- git -c core.autocrlf=false add NNO_*.txt &&
+ create_NNO_MIX_files &&
+ git -c core.autocrlf=false add NNO_*.txt MIX_*.txt &&
git commit -m "mixed line endings" &&
test_tick
'
@@ -385,6 +440,18 @@ test_expect_success 'commit files attr=crlf' '
commit_check_warn input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" ""
'
+# Commit "CRLFmixLF" on top of these files already in the repo:
+# mixed mixed mixed mixed mixed
+# onto onto onto onto onto
+# attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL
+commit_MIX_chkwrn "" "" false "" "" "" "" ""
+commit_MIX_chkwrn "" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF"
+commit_MIX_chkwrn "" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF"
+
+commit_MIX_chkwrn "auto" "" false "$WAMIX" "" "" "$WAMIX" "$WAMIX"
+commit_MIX_chkwrn "auto" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF"
+commit_MIX_chkwrn "auto" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF"
+
# attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL
commit_chk_wrnNNO "" "" false "" "" "" "" ""
commit_chk_wrnNNO "" "" true LF_CRLF "" "" "" ""
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
index 6ce9b9c070..2b95944973 100755
--- a/t/t2025-worktree-add.sh
+++ b/t/t2025-worktree-add.sh
@@ -245,6 +245,12 @@ test_expect_success 'local clone from linked checkout' '
( cd here-clone && git fsck )
'
+test_expect_success 'local clone --shared from linked checkout' '
+ git -C bare worktree add --detach ../baretree &&
+ git clone --local --shared baretree bare-clone &&
+ grep /bare/ bare-clone/.git/objects/info/alternates
+'
+
test_expect_success '"add" worktree with --no-checkout' '
git worktree add --no-checkout -b swamp swamp &&
! test -e swamp/init.t &&
@@ -444,4 +450,33 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' '
)
'
+post_checkout_hook () {
+ test_when_finished "rm -f .git/hooks/post-checkout" &&
+ mkdir -p .git/hooks &&
+ write_script .git/hooks/post-checkout <<-\EOF
+ echo $* >hook.actual
+ EOF
+}
+
+test_expect_success '"add" invokes post-checkout hook (branch)' '
+ post_checkout_hook &&
+ printf "%s %s 1\n" $_z40 $(git rev-parse HEAD) >hook.expect &&
+ git worktree add gumby &&
+ test_cmp hook.expect hook.actual
+'
+
+test_expect_success '"add" invokes post-checkout hook (detached)' '
+ post_checkout_hook &&
+ printf "%s %s 1\n" $_z40 $(git rev-parse HEAD) >hook.expect &&
+ git worktree add --detach grumpy &&
+ test_cmp hook.expect hook.actual
+'
+
+test_expect_success '"add --no-checkout" suppresses post-checkout hook' '
+ post_checkout_hook &&
+ rm -f hook.actual &&
+ git worktree add --no-checkout gloopy &&
+ test_path_is_missing hook.actual
+'
+
test_done
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 6a82d1ed87..481a350090 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1260,6 +1260,28 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
test B = $(git cat-file commit HEAD^ | sed -ne \$p)
'
+test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
+ rebase_setup_and_clean abbrevcmd &&
+ test_commit "first" file1.txt "first line" first &&
+ test_commit "second" file1.txt "another line" second &&
+ test_commit "fixup! first" file2.txt "first line again" first_fixup &&
+ test_commit "squash! second" file1.txt "another line here" second_squash &&
+ cat >expected <<-EOF &&
+ p $(git rev-list --abbrev-commit -1 first) first
+ f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
+ x git show HEAD
+ p $(git rev-list --abbrev-commit -1 second) second
+ s $(git rev-list --abbrev-commit -1 second_squash) squash! second
+ x git show HEAD
+ EOF
+ git checkout abbrevcmd &&
+ set_cat_todo_editor &&
+ test_config rebase.abbreviateCommands true &&
+ test_must_fail git rebase -i --exec "git show HEAD" \
+ --autosquash master >actual &&
+ test_cmp expected actual
+'
+
test_expect_success 'static check of bad command' '
rebase_setup_and_clean bad-cmd &&
set_fake_editor &&
diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh
index 3950f5034d..6471a68701 100755
--- a/t/t4045-diff-relative.sh
+++ b/t/t4045-diff-relative.sh
@@ -12,62 +12,76 @@ test_expect_success 'setup' '
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_diff () {
+ dir=$1
+ shift
+ 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 -C '$dir' diff -p $* HEAD^ >actual &&
+ test_cmp expected actual
+ "
}
-check_numstat() {
-expect=$1; shift
-cat >expected <<EOF
-1 0 $expect
-EOF
-test_expect_success "--numstat $*" "
- echo '1 0 $expect' >expected &&
- git diff --numstat $* HEAD^ >actual &&
- test_cmp expected actual
-"
+check_numstat () {
+ dir=$1
+ shift
+ expect=$1
+ shift
+ cat >expected <<-EOF
+ 1 0 $expect
+ EOF
+ test_expect_success "--numstat $*" "
+ echo '1 0 $expect' >expected &&
+ git -C '$dir' diff --numstat $* HEAD^ >actual &&
+ test_cmp expected actual
+ "
}
-check_stat() {
-expect=$1; shift
-cat >expected <<EOF
- $expect | 1 +
- 1 file changed, 1 insertion(+)
-EOF
-test_expect_success "--stat $*" "
- git diff --stat $* HEAD^ >actual &&
- test_i18ncmp expected actual
-"
+check_stat () {
+ dir=$1
+ shift
+ expect=$1
+ shift
+ cat >expected <<-EOF
+ $expect | 1 +
+ 1 file changed, 1 insertion(+)
+ EOF
+ test_expect_success "--stat $*" "
+ git -C '$dir' diff --stat $* HEAD^ >actual &&
+ test_i18ncmp 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
-"
+check_raw () {
+ dir=$1
+ shift
+ expect=$1
+ shift
+ cat >expected <<-EOF
+ :000000 100644 0000000000000000000000000000000000000000 25c05ef3639d2d270e7fe765a67668f098092bc5 A $expect
+ EOF
+ test_expect_success "--raw $*" "
+ git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&
+ test_cmp expected actual
+ "
}
-for type in diff numstat stat raw; do
- check_$type file2 --relative=subdir/
- check_$type file2 --relative=subdir
- check_$type dir/file2 --relative=sub
+for type in diff numstat stat raw
+do
+ check_$type . file2 --relative=subdir/
+ check_$type . file2 --relative=subdir
+ check_$type subdir file2 --relative
+ check_$type . dir/file2 --relative=sub
done
test_done
diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh
new file mode 100755
index 0000000000..1b0acc383b
--- /dev/null
+++ b/t/t5317-pack-objects-filter-objects.sh
@@ -0,0 +1,375 @@
+#!/bin/sh
+
+test_description='git pack-objects using object filtering'
+
+. ./test-lib.sh
+
+# Test blob:none filter.
+
+test_expect_success 'setup r1' '
+ echo "{print \$1}" >print_1.awk &&
+ echo "{print \$2}" >print_2.awk &&
+
+ git init r1 &&
+ for n in 1 2 3 4 5
+ do
+ echo "This is file: $n" > r1/file.$n
+ git -C r1 add file.$n
+ git -C r1 commit -m "$n"
+ done
+'
+
+test_expect_success 'verify blob count in normal packfile' '
+ git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r1 pack-objects --rev --stdout >all.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r1 index-pack ../all.pack &&
+ git -C r1 verify-pack -v ../all.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify blob:none packfile has no blobs' '
+ git -C r1 pack-objects --rev --stdout --filter=blob:none >filter.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r1 index-pack ../filter.pack &&
+ git -C r1 verify-pack -v ../filter.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ nr=$(wc -l <observed) &&
+ test 0 -eq $nr
+'
+
+test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
+ git -C r1 verify-pack -v ../all.pack \
+ | grep -E "commit|tree" \
+ | awk -f print_1.awk \
+ | sort >expected &&
+ git -C r1 verify-pack -v ../filter.pack \
+ | grep -E "commit|tree" \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+# Test blob:limit=<n>[kmg] filter.
+# We boundary test around the size parameter. The filter is strictly less than
+# the value, so size 500 and 1000 should have the same results, but 1001 should
+# filter more.
+
+test_expect_success 'setup r2' '
+ git init r2 &&
+ for n in 1000 10000
+ do
+ printf "%"$n"s" X > r2/large.$n
+ git -C r2 add large.$n
+ git -C r2 commit -m "$n"
+ done
+'
+
+test_expect_success 'verify blob count in normal packfile' '
+ git -C r2 ls-files -s large.1000 large.10000 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r2 pack-objects --rev --stdout >all.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r2 index-pack ../all.pack &&
+ git -C r2 verify-pack -v ../all.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify blob:limit=500 omits all blobs' '
+ git -C r2 pack-objects --rev --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r2 index-pack ../filter.pack &&
+ git -C r2 verify-pack -v ../filter.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ nr=$(wc -l <observed) &&
+ test 0 -eq $nr
+'
+
+test_expect_success 'verify blob:limit=1000' '
+ git -C r2 pack-objects --rev --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r2 index-pack ../filter.pack &&
+ git -C r2 verify-pack -v ../filter.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ nr=$(wc -l <observed) &&
+ test 0 -eq $nr
+'
+
+test_expect_success 'verify blob:limit=1001' '
+ git -C r2 ls-files -s large.1000 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r2 pack-objects --rev --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r2 index-pack ../filter.pack &&
+ git -C r2 verify-pack -v ../filter.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify blob:limit=10001' '
+ git -C r2 ls-files -s large.1000 large.10000 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r2 pack-objects --rev --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r2 index-pack ../filter.pack &&
+ git -C r2 verify-pack -v ../filter.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify blob:limit=1k' '
+ git -C r2 ls-files -s large.1000 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r2 index-pack ../filter.pack &&
+ git -C r2 verify-pack -v ../filter.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify blob:limit=1m' '
+ git -C r2 ls-files -s large.1000 large.10000 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r2 pack-objects --rev --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r2 index-pack ../filter.pack &&
+ git -C r2 verify-pack -v ../filter.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify normal and blob:limit packfiles have same commits/trees' '
+ git -C r2 verify-pack -v ../all.pack \
+ | grep -E "commit|tree" \
+ | awk -f print_1.awk \
+ | sort >expected &&
+ git -C r2 verify-pack -v ../filter.pack \
+ | grep -E "commit|tree" \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+# Test sparse:path=<path> filter.
+# Use a local file containing a sparse-checkout specification to filter
+# out blobs not required for the corresponding sparse-checkout. We do not
+# require sparse-checkout to actually be enabled.
+
+test_expect_success 'setup r3' '
+ git init r3 &&
+ mkdir r3/dir1 &&
+ for n in sparse1 sparse2
+ do
+ echo "This is file: $n" > r3/$n
+ git -C r3 add $n
+ echo "This is file: dir1/$n" > r3/dir1/$n
+ git -C r3 add dir1/$n
+ done &&
+ git -C r3 commit -m "sparse" &&
+ echo dir1/ >pattern1 &&
+ echo sparse1 >pattern2
+'
+
+test_expect_success 'verify blob count in normal packfile' '
+ git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r3 pack-objects --rev --stdout >all.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r3 index-pack ../all.pack &&
+ git -C r3 verify-pack -v ../all.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify sparse:path=pattern1' '
+ git -C r3 ls-files -s dir1/sparse1 dir1/sparse2 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r3 index-pack ../filter.pack &&
+ git -C r3 verify-pack -v ../filter.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify normal and sparse:path=pattern1 packfiles have same commits/trees' '
+ git -C r3 verify-pack -v ../all.pack \
+ | grep -E "commit|tree" \
+ | awk -f print_1.awk \
+ | sort >expected &&
+ git -C r3 verify-pack -v ../filter.pack \
+ | grep -E "commit|tree" \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify sparse:path=pattern2' '
+ git -C r3 ls-files -s sparse1 dir1/sparse1 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r3 index-pack ../filter.pack &&
+ git -C r3 verify-pack -v ../filter.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify normal and sparse:path=pattern2 packfiles have same commits/trees' '
+ git -C r3 verify-pack -v ../all.pack \
+ | grep -E "commit|tree" \
+ | awk -f print_1.awk \
+ | sort >expected &&
+ git -C r3 verify-pack -v ../filter.pack \
+ | grep -E "commit|tree" \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+# Test sparse:oid=<oid-ish> filter.
+# Like sparse:path, but we get the sparse-checkout specification from
+# a blob rather than a file on disk.
+
+test_expect_success 'setup r4' '
+ git init r4 &&
+ mkdir r4/dir1 &&
+ for n in sparse1 sparse2
+ do
+ echo "This is file: $n" > r4/$n
+ git -C r4 add $n
+ echo "This is file: dir1/$n" > r4/dir1/$n
+ git -C r4 add dir1/$n
+ done &&
+ echo dir1/ >r4/pattern &&
+ git -C r4 add pattern &&
+ git -C r4 commit -m "pattern"
+'
+
+test_expect_success 'verify blob count in normal packfile' '
+ git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r4 pack-objects --rev --stdout >all.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r4 index-pack ../all.pack &&
+ git -C r4 verify-pack -v ../all.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify sparse:oid=OID' '
+ git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
+ git -C r4 pack-objects --rev --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r4 index-pack ../filter.pack &&
+ git -C r4 verify-pack -v ../filter.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify sparse:oid=oid-ish' '
+ git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r4 pack-objects --rev --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
+ HEAD
+ EOF
+ git -C r4 index-pack ../filter.pack &&
+ git -C r4 verify-pack -v ../filter.pack \
+ | grep blob \
+ | awk -f print_1.awk \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+# Delete some loose objects and use pack-objects, but WITHOUT any filtering.
+# This models previously omitted objects that we did not receive.
+
+test_expect_success 'setup r1 - delete loose blobs' '
+ git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ for id in `cat expected | sed "s|..|&/|"`
+ do
+ rm r1/.git/objects/$id
+ done
+'
+
+test_expect_success 'verify pack-objects fails w/ missing objects' '
+ test_must_fail git -C r1 pack-objects --rev --stdout >miss.pack <<-EOF
+ HEAD
+ EOF
+'
+
+test_expect_success 'verify pack-objects fails w/ --missing=error' '
+ test_must_fail git -C r1 pack-objects --rev --stdout --missing=error >miss.pack <<-EOF
+ HEAD
+ EOF
+'
+
+test_expect_success 'verify pack-objects w/ --missing=allow-any' '
+ git -C r1 pack-objects --rev --stdout --missing=allow-any >miss.pack <<-EOF
+ HEAD
+ EOF
+'
+
+test_done
diff --git a/t/t5573-pull-verify-signatures.sh b/t/t5573-pull-verify-signatures.sh
new file mode 100755
index 0000000000..9594e891f4
--- /dev/null
+++ b/t/t5573-pull-verify-signatures.sh
@@ -0,0 +1,81 @@
+#!/bin/sh
+
+test_description='pull signature verification tests'
+. ./test-lib.sh
+. "$TEST_DIRECTORY/lib-gpg.sh"
+
+test_expect_success GPG 'create repositories with signed commits' '
+ echo 1 >a && git add a &&
+ test_tick && git commit -m initial &&
+ git tag initial &&
+
+ git clone . signed &&
+ (
+ cd signed &&
+ echo 2 >b && git add b &&
+ test_tick && git commit -S -m "signed"
+ ) &&
+
+ git clone . unsigned &&
+ (
+ cd unsigned &&
+ echo 3 >c && git add c &&
+ test_tick && git commit -m "unsigned"
+ ) &&
+
+ git clone . bad &&
+ (
+ cd bad &&
+ echo 4 >d && git add d &&
+ test_tick && git commit -S -m "bad" &&
+ git cat-file commit HEAD >raw &&
+ sed -e "s/bad/forged bad/" raw >forged &&
+ git hash-object -w -t commit forged >forged.commit &&
+ git checkout $(cat forged.commit)
+ ) &&
+
+ git clone . untrusted &&
+ (
+ cd untrusted &&
+ echo 5 >e && git add e &&
+ test_tick && git commit -SB7227189 -m "untrusted"
+ )
+'
+
+test_expect_success GPG 'pull unsigned commit with --verify-signatures' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ test_must_fail git pull --ff-only --verify-signatures unsigned 2>pullerror &&
+ test_i18ngrep "does not have a GPG signature" pullerror
+'
+
+test_expect_success GPG 'pull commit with bad signature with --verify-signatures' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ test_must_fail git pull --ff-only --verify-signatures bad 2>pullerror &&
+ test_i18ngrep "has a bad GPG signature" pullerror
+'
+
+test_expect_success GPG 'pull commit with untrusted signature with --verify-signatures' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ test_must_fail git pull --ff-only --verify-signatures untrusted 2>pullerror &&
+ test_i18ngrep "has an untrusted GPG signature" pullerror
+'
+
+test_expect_success GPG 'pull signed commit with --verify-signatures' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ git pull --verify-signatures signed >pulloutput &&
+ test_i18ngrep "has a good GPG signature" pulloutput
+'
+
+test_expect_success GPG 'pull commit with bad signature without verification' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ git pull --ff-only bad 2>pullerror
+'
+
+test_expect_success GPG 'pull commit with bad signature with --no-verify-signatures' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ test_config merge.verifySignatures true &&
+ test_config pull.verifySignatures true &&
+ git pull --ff-only --no-verify-signatures bad 2>pullerror
+'
+
+test_done
diff --git a/t/t5615-alternate-env.sh b/t/t5615-alternate-env.sh
index d2d883f3a1..b4905b822c 100755
--- a/t/t5615-alternate-env.sh
+++ b/t/t5615-alternate-env.sh
@@ -7,9 +7,9 @@ check_obj () {
alt=$1; shift
while read obj expect
do
- echo "$obj" >&3 &&
- echo "$obj $expect" >&4
- done 3>input 4>expect &&
+ echo "$obj" >&5 &&
+ echo "$obj $expect" >&6
+ done 5>input 6>expect &&
GIT_ALTERNATE_OBJECT_DIRECTORIES=$alt \
git "$@" cat-file --batch-check='%(objectname) %(objecttype)' \
<input >actual &&
diff --git a/t/t6100-rev-list-in-order.sh b/t/t6100-rev-list-in-order.sh
new file mode 100755
index 0000000000..b2bb0a7f61
--- /dev/null
+++ b/t/t6100-rev-list-in-order.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+test_description='rev-list testing in-commit-order'
+
+. ./test-lib.sh
+
+test_expect_success 'setup a commit history with trees, blobs' '
+ for x in one two three four
+ do
+ echo $x >$x &&
+ git add $x &&
+ git commit -m "add file $x" ||
+ return 1
+ done &&
+ for x in four three
+ do
+ git rm $x &&
+ git commit -m "remove $x" ||
+ return 1
+ done
+'
+
+test_expect_success 'rev-list --in-commit-order' '
+ git rev-list --in-commit-order --objects HEAD >actual.raw &&
+ cut -c 1-40 >actual <actual.raw &&
+
+ git cat-file --batch-check="%(objectname)" >expect.raw <<-\EOF &&
+ HEAD^{commit}
+ HEAD^{tree}
+ HEAD^{tree}:one
+ HEAD^{tree}:two
+ HEAD~1^{commit}
+ HEAD~1^{tree}
+ HEAD~1^{tree}:three
+ HEAD~2^{commit}
+ HEAD~2^{tree}
+ HEAD~2^{tree}:four
+ HEAD~3^{commit}
+ # HEAD~3^{tree} skipped, same as HEAD~1^{tree}
+ HEAD~4^{commit}
+ # HEAD~4^{tree} skipped, same as HEAD^{tree}
+ HEAD~5^{commit}
+ HEAD~5^{tree}
+ EOF
+ grep -v "#" >expect <expect.raw &&
+
+ test_cmp expect actual
+'
+
+test_expect_success 'rev-list lists blobs and trees after commits' '
+ git rev-list --objects HEAD >actual.raw &&
+ cut -c 1-40 >actual <actual.raw &&
+
+ git cat-file --batch-check="%(objectname)" >expect.raw <<-\EOF &&
+ HEAD^{commit}
+ HEAD~1^{commit}
+ HEAD~2^{commit}
+ HEAD~3^{commit}
+ HEAD~4^{commit}
+ HEAD~5^{commit}
+ HEAD^{tree}
+ HEAD^{tree}:one
+ HEAD^{tree}:two
+ HEAD~1^{tree}
+ HEAD~1^{tree}:three
+ HEAD~2^{tree}
+ HEAD~2^{tree}:four
+ # HEAD~3^{tree} skipped, same as HEAD~1^{tree}
+ # HEAD~4^{tree} skipped, same as HEAD^{tree}
+ HEAD~5^{tree}
+ EOF
+ grep -v "#" >expect <expect.raw &&
+
+ test_cmp expect actual
+'
+
+test_done
diff --git a/t/t6112-rev-list-filters-objects.sh b/t/t6112-rev-list-filters-objects.sh
new file mode 100755
index 0000000000..0a37dd5f97
--- /dev/null
+++ b/t/t6112-rev-list-filters-objects.sh
@@ -0,0 +1,225 @@
+#!/bin/sh
+
+test_description='git rev-list using object filtering'
+
+. ./test-lib.sh
+
+# Test the blob:none filter.
+
+test_expect_success 'setup r1' '
+ echo "{print \$1}" >print_1.awk &&
+ echo "{print \$2}" >print_2.awk &&
+
+ git init r1 &&
+ for n in 1 2 3 4 5
+ do
+ echo "This is file: $n" > r1/file.$n
+ git -C r1 add file.$n
+ git -C r1 commit -m "$n"
+ done
+'
+
+test_expect_success 'verify blob:none omits all 5 blobs' '
+ git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r1 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:none \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify emitted+omitted == all' '
+ git -C r1 rev-list HEAD --objects \
+ | awk -f print_1.awk \
+ | sort >expected &&
+ git -C r1 rev-list HEAD --objects --filter-print-omitted --filter=blob:none \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+
+# Test blob:limit=<n>[kmg] filter.
+# We boundary test around the size parameter. The filter is strictly less than
+# the value, so size 500 and 1000 should have the same results, but 1001 should
+# filter more.
+
+test_expect_success 'setup r2' '
+ git init r2 &&
+ for n in 1000 10000
+ do
+ printf "%"$n"s" X > r2/large.$n
+ git -C r2 add large.$n
+ git -C r2 commit -m "$n"
+ done
+'
+
+test_expect_success 'verify blob:limit=500 omits all blobs' '
+ git -C r2 ls-files -s large.1000 large.10000 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=500 \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify emitted+omitted == all' '
+ git -C r2 rev-list HEAD --objects \
+ | awk -f print_1.awk \
+ | sort >expected &&
+ git -C r2 rev-list HEAD --objects --filter-print-omitted --filter=blob:limit=500 \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify blob:limit=1000' '
+ git -C r2 ls-files -s large.1000 large.10000 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1000 \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify blob:limit=1001' '
+ git -C r2 ls-files -s large.10000 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1001 \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify blob:limit=1k' '
+ git -C r2 ls-files -s large.10000 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1k \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify blob:limit=1m' '
+ cat </dev/null >expected &&
+ git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1m \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+# Test sparse:path=<path> filter.
+# Use a local file containing a sparse-checkout specification to filter
+# out blobs not required for the corresponding sparse-checkout. We do not
+# require sparse-checkout to actually be enabled.
+
+test_expect_success 'setup r3' '
+ git init r3 &&
+ mkdir r3/dir1 &&
+ for n in sparse1 sparse2
+ do
+ echo "This is file: $n" > r3/$n
+ git -C r3 add $n
+ echo "This is file: dir1/$n" > r3/dir1/$n
+ git -C r3 add dir1/$n
+ done &&
+ git -C r3 commit -m "sparse" &&
+ echo dir1/ >pattern1 &&
+ echo sparse1 >pattern2
+'
+
+test_expect_success 'verify sparse:path=pattern1 omits top-level files' '
+ git -C r3 ls-files -s sparse1 sparse2 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern1 \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify sparse:path=pattern2 omits both sparse2 files' '
+ git -C r3 ls-files -s sparse2 dir1/sparse2 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern2 \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+# Test sparse:oid=<oid-ish> filter.
+# Like sparse:path, but we get the sparse-checkout specification from
+# a blob rather than a file on disk.
+
+test_expect_success 'setup r3 part 2' '
+ echo dir1/ >r3/pattern &&
+ git -C r3 add pattern &&
+ git -C r3 commit -m "pattern"
+'
+
+test_expect_success 'verify sparse:oid=OID omits top-level files' '
+ git -C r3 ls-files -s pattern sparse1 sparse2 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) &&
+ git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=$oid \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'verify sparse:oid=oid-ish omits top-level files' '
+ git -C r3 ls-files -s pattern sparse1 sparse2 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=master:pattern \
+ | awk -f print_1.awk \
+ | sed "s/~//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+# Delete some loose objects and use rev-list, but WITHOUT any filtering.
+# This models previously omitted objects that we did not receive.
+
+test_expect_success 'rev-list W/ --missing=print' '
+ git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
+ | awk -f print_2.awk \
+ | sort >expected &&
+ for id in `cat expected | sed "s|..|&/|"`
+ do
+ rm r1/.git/objects/$id
+ done &&
+ git -C r1 rev-list --quiet HEAD --missing=print --objects \
+ | awk -f print_1.awk \
+ | sed "s/?//" \
+ | sort >observed &&
+ test_cmp observed expected
+'
+
+test_expect_success 'rev-list W/O --missing fails' '
+ test_must_fail git -C r1 rev-list --quiet --objects HEAD
+'
+
+test_expect_success 'rev-list W/ missing=allow-any' '
+ git -C r1 rev-list --quiet --missing=allow-any --objects HEAD
+'
+
+test_done
diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index 1c0e8659d9..3e3fb462a0 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -304,12 +304,46 @@ test_expect_success 'describe chokes on severely broken submodules' '
mv .git/modules/sub1/ .git/modules/sub_moved &&
test_must_fail git describe --dirty
'
-test_expect_success 'describe ignoring a borken submodule' '
+test_expect_success 'describe ignoring a broken submodule' '
git describe --broken >out &&
test_when_finished "mv .git/modules/sub_moved .git/modules/sub1" &&
grep broken out
'
+test_expect_success 'describe a blob at a directly tagged commit' '
+ echo "make it a unique blob" >file &&
+ git add file && git commit -m "content in file" &&
+ git tag -a -m "latest annotated tag" unique-file &&
+ git describe HEAD:file >actual &&
+ echo "unique-file:file" >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'describe a blob with its first introduction' '
+ git commit --allow-empty -m "empty commit" &&
+ git rm file &&
+ git commit -m "delete blob" &&
+ git revert HEAD &&
+ git commit --allow-empty -m "empty commit" &&
+ git describe HEAD:file >actual &&
+ echo "unique-file:file" >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'describe directly tagged blob' '
+ git tag test-blob unique-file:file &&
+ git describe test-blob >actual &&
+ echo "unique-file:file" >expect &&
+ # suboptimal: we rather want to see "test-blob"
+ test_cmp expect actual
+'
+
+test_expect_success 'describe tag object' '
+ git tag test-blob-1 -a -m msg unique-file:file &&
+ test_must_fail git describe test-blob-1 2>actual &&
+ test_i18ngrep "fatal: test-blob-1 is neither a commit nor blob" actual
+'
+
test_expect_failure ULIMIT_STACK_SIZE 'name-rev works in a deep repo' '
i=1 &&
while test $i -lt 8000
diff --git a/t/t7612-merge-verify-signatures.sh b/t/t7612-merge-verify-signatures.sh
index 8ae69a61c3..e797c74112 100755
--- a/t/t7612-merge-verify-signatures.sh
+++ b/t/t7612-merge-verify-signatures.sh
@@ -35,27 +35,72 @@ test_expect_success GPG 'create signed commits' '
'
test_expect_success GPG 'merge unsigned commit with verification' '
+ test_when_finished "git reset --hard && git checkout initial" &&
test_must_fail git merge --ff-only --verify-signatures side-unsigned 2>mergeerror &&
test_i18ngrep "does not have a GPG signature" mergeerror
'
+test_expect_success GPG 'merge unsigned commit with merge.verifySignatures=true' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ test_config merge.verifySignatures true &&
+ test_must_fail git merge --ff-only side-unsigned 2>mergeerror &&
+ test_i18ngrep "does not have a GPG signature" mergeerror
+'
+
test_expect_success GPG 'merge commit with bad signature with verification' '
+ test_when_finished "git reset --hard && git checkout initial" &&
test_must_fail git merge --ff-only --verify-signatures $(cat forged.commit) 2>mergeerror &&
test_i18ngrep "has a bad GPG signature" mergeerror
'
+test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=true' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ test_config merge.verifySignatures true &&
+ test_must_fail git merge --ff-only $(cat forged.commit) 2>mergeerror &&
+ test_i18ngrep "has a bad GPG signature" mergeerror
+'
+
test_expect_success GPG 'merge commit with untrusted signature with verification' '
+ test_when_finished "git reset --hard && git checkout initial" &&
test_must_fail git merge --ff-only --verify-signatures side-untrusted 2>mergeerror &&
test_i18ngrep "has an untrusted GPG signature" mergeerror
'
+test_expect_success GPG 'merge commit with untrusted signature with merge.verifySignatures=true' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ test_config merge.verifySignatures true &&
+ test_must_fail git merge --ff-only side-untrusted 2>mergeerror &&
+ test_i18ngrep "has an untrusted GPG signature" mergeerror
+'
+
test_expect_success GPG 'merge signed commit with verification' '
+ test_when_finished "git reset --hard && git checkout initial" &&
git merge --verbose --ff-only --verify-signatures side-signed >mergeoutput &&
test_i18ngrep "has a good GPG signature" mergeoutput
'
+test_expect_success GPG 'merge signed commit with merge.verifySignatures=true' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ test_config merge.verifySignatures true &&
+ git merge --verbose --ff-only side-signed >mergeoutput &&
+ test_i18ngrep "has a good GPG signature" mergeoutput
+'
+
test_expect_success GPG 'merge commit with bad signature without verification' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ git merge $(cat forged.commit)
+'
+
+test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=false' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ test_config merge.verifySignatures false &&
git merge $(cat forged.commit)
'
+test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=true and --no-verify-signatures' '
+ test_when_finished "git reset --hard && git checkout initial" &&
+ test_config merge.verifySignatures true &&
+ git merge --no-verify-signatures $(cat forged.commit)
+'
+
test_done
diff --git a/t/t9004-example.sh b/t/t9004-example.sh
new file mode 100755
index 0000000000..b28a028f55
--- /dev/null
+++ b/t/t9004-example.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+test_description='check that example code compiles and runs'
+. ./test-lib.sh
+
+test_expect_success 'decorate' '
+ test-example-decorate
+'
+
+test_done
diff --git a/t/t9169-git-svn-dcommit-crlf.sh b/t/t9169-git-svn-dcommit-crlf.sh
new file mode 100755
index 0000000000..54b1f61a2a
--- /dev/null
+++ b/t/t9169-git-svn-dcommit-crlf.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+test_description='git svn dcommit CRLF'
+. ./lib-git-svn.sh
+
+test_expect_success 'setup commit repository' '
+ svn_cmd mkdir -m "$test_description" "$svnrepo/dir" &&
+ git svn clone "$svnrepo" work &&
+ (
+ cd work &&
+ echo foo >>foo &&
+ git update-index --add foo &&
+ printf "a\\r\\n\\r\\nb\\r\\nc\\r\\n" >cmt &&
+ p=$(git rev-parse HEAD) &&
+ t=$(git write-tree) &&
+ cmt=$(git commit-tree -p $p $t <cmt) &&
+ git update-ref refs/heads/master $cmt &&
+ git cat-file commit HEAD | tail -n4 >out &&
+ test_cmp cmt out &&
+ git svn dcommit &&
+ printf "a\\n\\nb\\nc\\n" >exp &&
+ git cat-file commit HEAD | sed -ne 6,9p >out &&
+ test_cmp exp out
+ )
+'
+
+test_done
diff --git a/t/test-lib.sh b/t/test-lib.sh
index e7065df2bb..9a0a21f49a 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -80,7 +80,7 @@ done,*)
# from any previous runs.
>"$GIT_TEST_TEE_OUTPUT_FILE"
- (GIT_TEST_TEE_STARTED=done ${SHELL_PATH} "$0" "$@" 2>&1;
+ (GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
echo $? >"$BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
test "$(cat "$BASE.exit")" = 0
exit
@@ -264,7 +264,6 @@ do
shift ;;
-x)
trace=t
- verbose=t
shift ;;
--verbose-log)
verbose_log=t
@@ -283,6 +282,11 @@ then
test -z "$verbose_log" && verbose=t
fi
+if test -n "$trace" && test -z "$verbose_log"
+then
+ verbose=t
+fi
+
if test -n "$color"
then
# Save the color control sequences now rather than run tput
@@ -586,7 +590,9 @@ maybe_setup_valgrind () {
}
want_trace () {
- test "$trace" = t && test "$verbose" = t
+ test "$trace" = t && {
+ test "$verbose" = t || test "$verbose_log" = t
+ }
}
# This is a separate function because some tests use
@@ -601,26 +607,40 @@ test_eval_inner_ () {
}
test_eval_ () {
- # We run this block with stderr redirected to avoid extra cruft
- # during a "-x" trace. Once in "set -x" mode, we cannot prevent
+ # If "-x" tracing is in effect, then we want to avoid polluting stderr
+ # with non-test commands. But once in "set -x" mode, we cannot prevent
# the shell from printing the "set +x" to turn it off (nor the saving
# of $? before that). But we can make sure that the output goes to
# /dev/null.
#
- # The test itself is run with stderr put back to &4 (so either to
- # /dev/null, or to the original stderr if --verbose was used).
+ # There are a few subtleties here:
+ #
+ # - we have to redirect descriptor 4 in addition to 2, to cover
+ # BASH_XTRACEFD
+ #
+ # - the actual eval has to come before the redirection block (since
+ # it needs to see descriptor 4 to set up its stderr)
+ #
+ # - likewise, any error message we print must be outside the block to
+ # access descriptor 4
+ #
+ # - checking $? has to come immediately after the eval, but it must
+ # be _inside_ the block to avoid polluting the "set -x" output
+ #
+
+ test_eval_inner_ "$@" </dev/null >&3 2>&4
{
- test_eval_inner_ "$@" </dev/null >&3 2>&4
test_eval_ret_=$?
if want_trace
then
set +x
- if test "$test_eval_ret_" != 0
- then
- say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
- fi
fi
- } 2>/dev/null
+ } 2>/dev/null 4>&2
+
+ if test "$test_eval_ret_" != 0 && want_trace
+ then
+ say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
+ fi
return $test_eval_ret_
}
diff --git a/transport-helper.c b/transport-helper.c
index bf05a2dcf1..5080150231 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -11,6 +11,7 @@
#include "sigchain.h"
#include "argv-array.h"
#include "refs.h"
+#include "transport-internal.h"
static int debug;
@@ -650,7 +651,7 @@ static int fetch(struct transport *transport,
if (process_connect(transport, 0)) {
do_take_over(transport);
- return transport->fetch(transport, nr_heads, to_fetch);
+ return transport->vtable->fetch(transport, nr_heads, to_fetch);
}
count = 0;
@@ -882,7 +883,8 @@ static int push_refs_with_push(struct transport *transport,
struct strbuf cas = STRBUF_INIT;
strbuf_addf(&cas, "%s:%s",
ref->name, oid_to_hex(&ref->old_oid_expect));
- string_list_append(&cas_options, strbuf_detach(&cas, NULL));
+ string_list_append_nodup(&cas_options,
+ strbuf_detach(&cas, NULL));
}
}
if (buf.len == 0) {
@@ -897,6 +899,7 @@ static int push_refs_with_push(struct transport *transport,
strbuf_addch(&buf, '\n');
sendline(data, &buf);
strbuf_release(&buf);
+ string_list_clear(&cas_options, 0);
return push_update_refs_status(data, remote_refs, flags);
}
@@ -930,7 +933,8 @@ static int push_refs_with_export(struct transport *transport,
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
if (private && !get_oid(private, &oid)) {
strbuf_addf(&buf, "^%s", private);
- string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
+ string_list_append_nodup(&revlist_args,
+ strbuf_detach(&buf, NULL));
oidcpy(&ref->old_oid, &oid);
}
free(private);
@@ -987,7 +991,7 @@ static int push_refs(struct transport *transport,
if (process_connect(transport, 1)) {
do_take_over(transport);
- return transport->push_refs(transport, remote_refs, flags);
+ return transport->vtable->push_refs(transport, remote_refs, flags);
}
if (!remote_refs) {
@@ -1035,7 +1039,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
if (process_connect(transport, for_push)) {
do_take_over(transport);
- return transport->get_refs_list(transport, for_push);
+ return transport->vtable->get_refs_list(transport, for_push);
}
if (data->push && for_push)
@@ -1083,6 +1087,15 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
return ret;
}
+static struct transport_vtable vtable = {
+ set_helper_option,
+ get_refs_list,
+ fetch,
+ push_refs,
+ connect_helper,
+ release_helper
+};
+
int transport_helper_init(struct transport *transport, const char *name)
{
struct helper_data *data = xcalloc(1, sizeof(*data));
@@ -1094,12 +1107,7 @@ int transport_helper_init(struct transport *transport, const char *name)
debug = 1;
transport->data = data;
- transport->set_option = set_helper_option;
- transport->get_refs_list = get_refs_list;
- transport->fetch = fetch;
- transport->push_refs = push_refs;
- transport->disconnect = release_helper;
- transport->connect = connect_helper;
+ transport->vtable = &vtable;
transport->smart_options = &(data->transport_options);
return 0;
}
diff --git a/transport-internal.h b/transport-internal.h
new file mode 100644
index 0000000000..3c1a29d727
--- /dev/null
+++ b/transport-internal.h
@@ -0,0 +1,61 @@
+#ifndef TRANSPORT_INTERNAL_H
+#define TRANSPORT_INTERNAL_H
+
+struct ref;
+struct transport;
+
+struct transport_vtable {
+ /**
+ * Returns 0 if successful, positive if the option is not
+ * recognized or is inapplicable, and negative if the option
+ * is applicable but the value is invalid.
+ **/
+ int (*set_option)(struct transport *connection, const char *name,
+ const char *value);
+ /**
+ * Returns a list of the remote side's refs. In order to allow
+ * the transport to try to share connections, for_push is a
+ * hint as to whether the ultimate operation is a push or a fetch.
+ *
+ * If the transport is able to determine the remote hash for
+ * the ref without a huge amount of effort, it should store it
+ * in the ref's old_sha1 field; otherwise it should be all 0.
+ **/
+ struct ref *(*get_refs_list)(struct transport *transport, int for_push);
+
+ /**
+ * Fetch the objects for the given refs. Note that this gets
+ * an array, and should ignore the list structure.
+ *
+ * If the transport did not get hashes for refs in
+ * get_refs_list(), it should set the old_sha1 fields in the
+ * provided refs now.
+ **/
+ int (*fetch)(struct transport *transport, int refs_nr, struct ref **refs);
+
+ /**
+ * Push the objects and refs. Send the necessary objects, and
+ * then, for any refs where peer_ref is set and
+ * peer_ref->new_oid is different from old_oid, tell the
+ * remote side to update each ref in the list from old_oid to
+ * peer_ref->new_oid.
+ *
+ * Where possible, set the status for each ref appropriately.
+ *
+ * The transport must modify new_sha1 in the ref to the new
+ * value if the remote accepted the change. Note that this
+ * could be a different value from peer_ref->new_oid if the
+ * process involved generating new commits.
+ **/
+ int (*push_refs)(struct transport *transport, struct ref *refs, int flags);
+ int (*connect)(struct transport *connection, const char *name,
+ const char *executable, int fd[2]);
+
+ /** get_refs_list(), fetch(), and push_refs() can keep
+ * resources (such as a connection) reserved for further
+ * use. disconnect() releases these resources.
+ **/
+ int (*disconnect)(struct transport *connection);
+};
+
+#endif
diff --git a/transport.c b/transport.c
index 7231d1b1b0..fc802260f6 100644
--- a/transport.c
+++ b/transport.c
@@ -17,6 +17,7 @@
#include "string-list.h"
#include "sha1-array.h"
#include "sigchain.h"
+#include "transport-internal.h"
static void set_upstreams(struct transport *transport, struct ref *refs,
int pretend)
@@ -607,6 +608,15 @@ static int disconnect_git(struct transport *transport)
return 0;
}
+static struct transport_vtable taken_over_vtable = {
+ NULL,
+ get_refs_via_connect,
+ fetch_refs_via_pack,
+ git_transport_push,
+ NULL,
+ disconnect_git
+};
+
void transport_take_over(struct transport *transport,
struct child_process *child)
{
@@ -624,12 +634,7 @@ void transport_take_over(struct transport *transport,
data->got_remote_heads = 0;
transport->data = data;
- transport->set_option = NULL;
- transport->get_refs_list = get_refs_via_connect;
- transport->fetch = fetch_refs_via_pack;
- transport->push = NULL;
- transport->push_refs = git_transport_push;
- transport->disconnect = disconnect_git;
+ transport->vtable = &taken_over_vtable;
transport->smart_options = &(data->options);
transport->cannot_reuse = 1;
@@ -752,6 +757,24 @@ void transport_check_allowed(const char *type)
die("transport '%s' not allowed", type);
}
+static struct transport_vtable bundle_vtable = {
+ NULL,
+ get_refs_from_bundle,
+ fetch_refs_from_bundle,
+ NULL,
+ NULL,
+ close_bundle
+};
+
+static struct transport_vtable builtin_smart_vtable = {
+ NULL,
+ get_refs_via_connect,
+ fetch_refs_via_pack,
+ git_transport_push,
+ connect_git,
+ disconnect_git
+};
+
struct transport *transport_get(struct remote *remote, const char *url)
{
const char *helper;
@@ -788,9 +811,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
transport_check_allowed("file");
ret->data = data;
- ret->get_refs_list = get_refs_from_bundle;
- ret->fetch = fetch_refs_from_bundle;
- ret->disconnect = close_bundle;
+ ret->vtable = &bundle_vtable;
ret->smart_options = NULL;
} else if (!is_url(url)
|| starts_with(url, "file://")
@@ -805,12 +826,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
*/
struct git_transport_data *data = xcalloc(1, sizeof(*data));
ret->data = data;
- ret->set_option = NULL;
- ret->get_refs_list = get_refs_via_connect;
- ret->fetch = fetch_refs_via_pack;
- ret->push_refs = git_transport_push;
- ret->connect = connect_git;
- ret->disconnect = disconnect_git;
+ ret->vtable = &builtin_smart_vtable;
ret->smart_options = &(data->options);
data->conn = NULL;
@@ -844,9 +860,9 @@ int transport_set_option(struct transport *transport,
git_reports = set_git_option(transport->smart_options,
name, value);
- if (transport->set_option)
- protocol_reports = transport->set_option(transport, name,
- value);
+ if (transport->vtable->set_option)
+ protocol_reports = transport->vtable->set_option(transport,
+ name, value);
/* If either report is 0, report 0 (success). */
if (!git_reports || !protocol_reports)
@@ -969,13 +985,7 @@ int transport_push(struct transport *transport,
*reject_reasons = 0;
transport_verify_remote_names(refspec_nr, refspec);
- if (transport->push) {
- /* Maybe FIXME. But no important transport uses this case. */
- if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
- die("This transport does not support using --set-upstream");
-
- return transport->push(transport, refspec_nr, refspec, flags);
- } else if (transport->push_refs) {
+ if (transport->vtable->push_refs) {
struct ref *remote_refs;
struct ref *local_refs = get_local_heads();
int match_flags = MATCH_REFS_NONE;
@@ -988,7 +998,7 @@ int transport_push(struct transport *transport,
if (check_push_refs(local_refs, refspec_nr, refspec) < 0)
return -1;
- remote_refs = transport->get_refs_list(transport, 1);
+ remote_refs = transport->vtable->get_refs_list(transport, 1);
if (flags & TRANSPORT_PUSH_ALL)
match_flags |= MATCH_REFS_ALL;
@@ -1063,7 +1073,7 @@ int transport_push(struct transport *transport,
}
if (!(flags & TRANSPORT_RECURSE_SUBMODULES_ONLY))
- push_ret = transport->push_refs(transport, remote_refs, flags);
+ push_ret = transport->vtable->push_refs(transport, remote_refs, flags);
else
push_ret = 0;
err = push_had_errors(remote_refs);
@@ -1097,7 +1107,7 @@ int transport_push(struct transport *transport,
const struct ref *transport_get_remote_refs(struct transport *transport)
{
if (!transport->got_remote_refs) {
- transport->remote_refs = transport->get_refs_list(transport, 0);
+ transport->remote_refs = transport->vtable->get_refs_list(transport, 0);
transport->got_remote_refs = 1;
}
@@ -1134,7 +1144,7 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
heads[nr_heads++] = rm;
}
- rc = transport->fetch(transport, nr_heads, heads);
+ rc = transport->vtable->fetch(transport, nr_heads, heads);
free(heads);
return rc;
@@ -1151,8 +1161,8 @@ void transport_unlock_pack(struct transport *transport)
int transport_connect(struct transport *transport, const char *name,
const char *exec, int fd[2])
{
- if (transport->connect)
- return transport->connect(transport, name, exec, fd);
+ if (transport->vtable->connect)
+ return transport->vtable->connect(transport, name, exec, fd);
else
die("Operation not supported by protocol");
}
@@ -1160,8 +1170,8 @@ int transport_connect(struct transport *transport, const char *name,
int transport_disconnect(struct transport *transport)
{
int ret = 0;
- if (transport->disconnect)
- ret = transport->disconnect(transport);
+ if (transport->vtable->disconnect)
+ ret = transport->vtable->disconnect(transport);
free(transport);
return ret;
}
diff --git a/transport.h b/transport.h
index bc5571574b..731c78b679 100644
--- a/transport.h
+++ b/transport.h
@@ -30,6 +30,8 @@ enum transport_family {
};
struct transport {
+ const struct transport_vtable *vtable;
+
struct remote *remote;
const char *url;
void *data;
@@ -59,59 +61,6 @@ struct transport {
*/
const struct string_list *push_options;
- /**
- * Returns 0 if successful, positive if the option is not
- * recognized or is inapplicable, and negative if the option
- * is applicable but the value is invalid.
- **/
- int (*set_option)(struct transport *connection, const char *name,
- const char *value);
-
- /**
- * Returns a list of the remote side's refs. In order to allow
- * the transport to try to share connections, for_push is a
- * hint as to whether the ultimate operation is a push or a fetch.
- *
- * If the transport is able to determine the remote hash for
- * the ref without a huge amount of effort, it should store it
- * in the ref's old_sha1 field; otherwise it should be all 0.
- **/
- struct ref *(*get_refs_list)(struct transport *transport, int for_push);
-
- /**
- * Fetch the objects for the given refs. Note that this gets
- * an array, and should ignore the list structure.
- *
- * If the transport did not get hashes for refs in
- * get_refs_list(), it should set the old_sha1 fields in the
- * provided refs now.
- **/
- int (*fetch)(struct transport *transport, int refs_nr, struct ref **refs);
-
- /**
- * Push the objects and refs. Send the necessary objects, and
- * then, for any refs where peer_ref is set and
- * peer_ref->new_oid is different from old_oid, tell the
- * remote side to update each ref in the list from old_oid to
- * peer_ref->new_oid.
- *
- * Where possible, set the status for each ref appropriately.
- *
- * The transport must modify new_sha1 in the ref to the new
- * value if the remote accepted the change. Note that this
- * could be a different value from peer_ref->new_oid if the
- * process involved generating new commits.
- **/
- int (*push_refs)(struct transport *transport, struct ref *refs, int flags);
- int (*push)(struct transport *connection, int refspec_nr, const char **refspec, int flags);
- int (*connect)(struct transport *connection, const char *name,
- const char *executable, int fd[2]);
-
- /** get_refs_list(), fetch(), and push_refs() can keep
- * resources (such as a connection) reserved for further
- * use. disconnect() releases these resources.
- **/
- int (*disconnect)(struct transport *connection);
char *pack_lockfile;
signed verbose : 3;
/**
diff --git a/version.c b/version.c
index 6106a8098c..41b718c29e 100644
--- a/version.c
+++ b/version.c
@@ -3,6 +3,7 @@
#include "strbuf.h"
const char git_version_string[] = GIT_VERSION;
+const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT;
const char *git_user_agent(void)
{
diff --git a/version.h b/version.h
index 6911a4f155..7c62e80577 100644
--- a/version.h
+++ b/version.h
@@ -2,6 +2,7 @@
#define VERSION_H
extern const char git_version_string[];
+extern const char git_built_from_commit_string[];
const char *git_user_agent(void);
const char *git_user_agent_sanitized(void);