Merge branch 'br/commit-tree-fully-spelled-gpg-sign-option'
authorJunio C Hamano <gitster@pobox.com>
Thu, 7 Feb 2019 06:05:25 +0000 (22:05 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Feb 2019 06:05:25 +0000 (22:05 -0800)
The documentation of "git commit-tree" said that the command
understands "--gpg-sign" in addition to "-S", but the command line
parser did not know about the longhand, which has been corrected.

* br/commit-tree-fully-spelled-gpg-sign-option:
commit-tree: add missing --gpg-sign flag
t7510: invoke git as part of &&-chain

271 files changed:
.gitignore
.travis.yml
Documentation/Makefile
Documentation/RelNotes/2.21.0.txt
Documentation/config/core.txt
Documentation/config/pack.txt
Documentation/config/rebase.txt
Documentation/diff-options.txt
Documentation/git-add.txt
Documentation/git-branch.txt
Documentation/git-cat-file.txt
Documentation/git-checkout.txt
Documentation/git-cherry-pick.txt
Documentation/git-diff.txt
Documentation/git-fetch.txt
Documentation/git-format-patch.txt
Documentation/git-help.txt
Documentation/git-init.txt
Documentation/git-instaweb.txt
Documentation/git-log.txt
Documentation/git-p4.txt
Documentation/git-pack-objects.txt
Documentation/git-rebase.txt
Documentation/git-reset.txt
Documentation/git-send-email.txt
Documentation/git-tag.txt
Documentation/git-upload-pack.txt
Documentation/gitattributes.txt
Documentation/pretty-formats.txt
Documentation/rev-list-options.txt
Documentation/technical/api-oid-array.txt
Documentation/technical/commit-graph-format.txt
Documentation/technical/pack-protocol.txt
Documentation/technical/partial-clone.txt
Documentation/technical/protocol-v2.txt
Makefile
alloc.c
alloc.h
apply.c
attr.c
bisect.c
blame.c
builtin/add.c
builtin/am.c
builtin/archive.c
builtin/bisect--helper.c
builtin/blame.c
builtin/bundle.c
builtin/cat-file.c
builtin/check-attr.c
builtin/check-ignore.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clean.c
builtin/clone.c
builtin/commit-graph.c
builtin/commit.c
builtin/config.c
builtin/describe.c
builtin/diff-files.c
builtin/diff-index.c
builtin/diff-tree.c
builtin/diff.c
builtin/difftool.c
builtin/fetch-pack.c
builtin/fetch.c
builtin/fsck.c
builtin/grep.c
builtin/hash-object.c
builtin/init-db.c
builtin/log.c
builtin/ls-files.c
builtin/merge-index.c
builtin/merge-ours.c
builtin/merge-recursive.c
builtin/merge-tree.c
builtin/merge.c
builtin/mv.c
builtin/notes.c
builtin/pack-objects.c
builtin/pull.c
builtin/read-tree.c
builtin/rebase--interactive.c
builtin/rebase.c
builtin/receive-pack.c
builtin/reflog.c
builtin/replace.c
builtin/reset.c
builtin/rev-list.c
builtin/rev-parse.c
builtin/rm.c
builtin/send-pack.c
builtin/submodule--helper.c
builtin/update-index.c
builtin/write-tree.c
bundle.c
bundle.h
cache-tree.c
cache-tree.h
cache.h
ci/install-dependencies.sh
ci/lib-travisci.sh
ci/run-build-and-tests.sh
ci/run-linux32-build.sh
column.c
combine-diff.c
commit-graph.c
commit-graph.h
commit-reach.c
commit-reach.h
commit.c
commit.h
compat/mingw.c
compat/obstack.c
compat/obstack.h
compat/precompose_utf8.c
config.c
connect.c
contrib/coccinelle/object_id.cocci
contrib/coccinelle/strbuf.cocci
contrib/coccinelle/the_repository.pending.cocci [new file with mode: 0644]
convert.c
date.c
delta-islands.c
diff.c
dir.c
environment.c
fetch-pack.c
fsck.c
fuzz-commit-graph.c [new file with mode: 0644]
git-bisect.sh
git-instaweb.sh
git-legacy-rebase.sh
git-p4.py
git-rebase--am.sh
git-rebase--common.sh
git-rebase--merge.sh [deleted file]
git-submodule.sh
git.c
hash.h
hex.c
http-push.c
http.c
http.h
list-objects-filter-options.c
list-objects-filter-options.h
list-objects-filter.c
list-objects.c
list-objects.h
log-tree.c
ls-refs.c
match-trees.c
merge-recursive.c
merge-recursive.h
merge.c
name-hash.c
notes-merge.c
notes-utils.c
notes-utils.h
notes.c
object-store.h
object.c
pack-objects.c
pack-objects.h
packfile.c
packfile.h
path.h
pathspec.c
pkt-line.c
pkt-line.h
preload-index.c
pretty.c
pretty.h
read-cache.c
remote-curl.c
remote.c
repository.c
repository.h
rerere.c
revision.c
revision.h
send-pack.c
sequencer.c
sequencer.h
serve.c
setup.c
sha1-array.c
sha1-array.h
sha1-file.c
sha1-name.c
sha256/block/sha256.c [new file with mode: 0644]
sha256/block/sha256.h [new file with mode: 0644]
sha256/gcrypt.h [new file with mode: 0644]
shallow.c
sideband.c
sideband.h
streaming.c
submodule.c
t/README
t/check-non-portable-shell.pl
t/helper/test-date.c
t/helper/test-dump-fsmonitor.c
t/helper/test-dump-untracked-cache.c
t/helper/test-hash-speed.c [new file with mode: 0644]
t/helper/test-hash.c [new file with mode: 0644]
t/helper/test-ref-store.c
t/helper/test-repository.c
t/helper/test-sha1.c
t/helper/test-sha256.c [new file with mode: 0644]
t/helper/test-submodule-nested-repo-config.c
t/helper/test-tool.c
t/helper/test-tool.h
t/lib-httpd/apache.conf
t/t0003-attributes.sh
t/t0006-date.sh
t/t0015-hash.sh [new file with mode: 0755]
t/t0025-crlf-renormalize.sh
t/t0028-working-tree-encoding.sh
t/t0061-run-command.sh
t/t1512-rev-parse-disambiguation.sh
t/t2018-checkout-branch.sh
t/t3404-rebase-interactive.sh
t/t3406-rebase-message.sh
t/t3418-rebase-continue.sh
t/t3420-rebase-autostash.sh
t/t3421-rebase-topology-linear.sh
t/t3425-rebase-topology-merges.sh
t/t3430-rebase-merges.sh
t/t3700-add.sh
t/t4006-diff-mode.sh
t/t4013-diff-various.sh
t/t4013/diff.diff-tree_--cc_--shortstat_master [new file with mode: 0644]
t/t4013/diff.diff-tree_--cc_--summary_REVERSE [new file with mode: 0644]
t/t4013/diff.diff_--dirstat_--cc_master~1_master [new file with mode: 0644]
t/t4015-diff-whitespace.sh
t/t4066-diff-emit-delay.sh [new file with mode: 0755]
t/t4205-log-pretty-formats.sh
t/t5318-commit-graph.sh
t/t5322-pack-objects-sparse.sh [new file with mode: 0755]
t/t5403-post-checkout-hook.sh
t/t5407-post-rewrite-hook.sh
t/t5500-fetch-pack.sh
t/t5512-ls-remote.sh
t/t5526-fetch-submodules.sh
t/t5537-fetch-shallow.sh
t/t5580-clone-push-unc.sh
t/t5581-http-curl-verbose.sh [new file with mode: 0755]
t/t5701-git-serve.sh
t/t5702-protocol-v2.sh
t/t5703-upload-pack-ref-in-want.sh
t/t6006-rev-list-format.sh
t/t6030-bisect-porcelain.sh
t/t6042-merge-rename-corner-cases.sh
t/t6112-rev-list-filters-objects.sh
t/t7505-prepare-commit-msg-hook.sh
t/t9807-git-p4-submit.sh
t/t9903-bash-prompt.sh
t/test-lib.sh
transport-helper.c
transport.c
tree-diff.c
tree-walk.c
tree-walk.h
tree.c
unpack-trees.c
upload-pack.c
utf8.c
utf8.h
walker.c
wrapper.c
wt-status.c
index 0d77ea5894274c43c4b348c8b52b8e665a1a339e..7374587f9df901cba0a6990ad48fac17f8a5be57 100644 (file)
@@ -1,3 +1,4 @@
+/fuzz-commit-graph
 /fuzz_corpora
 /fuzz-pack-headers
 /fuzz-pack-idx
 /git-rebase--am
 /git-rebase--common
 /git-rebase--interactive
-/git-rebase--merge
 /git-rebase--preserve-merges
 /git-receive-pack
 /git-reflog
 *.pdb
 /Debug/
 /Release/
+*.dSYM
index 03c8e4c613015476fffe3f1e071c0c9d6609df0e..36cbdea7f4f37e7eb4d5172daa4431cffcb4b46c 100644 (file)
@@ -8,6 +8,8 @@ os:
   - linux
   - osx
 
+osx_image: xcode10.1
+
 compiler:
   - clang
   - gcc
index d5d936e6a7a3dd8839901a0dd606cdc813249c1c..26a2342beaf0132241980dbbcaf8592fd4d183dc 100644 (file)
@@ -36,14 +36,19 @@ MAN7_TXT += gittutorial-2.txt
 MAN7_TXT += gittutorial.txt
 MAN7_TXT += gitworkflows.txt
 
+ifdef MAN_FILTER
+MAN_TXT = $(filter $(MAN_FILTER),$(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT))
+else
 MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT)
+MAN_FILTER = $(MAN_TXT)
+endif
+
 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
-DOC_HTML = $(MAN_HTML) $(OBSOLETE_HTML)
 
 ARTICLES += howto-index
 ARTICLES += git-tools
@@ -89,11 +94,13 @@ TECH_DOCS += technical/trivial-merge
 SP_ARTICLES += $(TECH_DOCS)
 SP_ARTICLES += technical/api-index
 
-DOC_HTML += $(patsubst %,%.html,$(ARTICLES) $(SP_ARTICLES))
+ARTICLES_HTML += $(patsubst %,%.html,$(ARTICLES) $(SP_ARTICLES))
+HTML_FILTER ?= $(ARTICLES_HTML) $(OBSOLETE_HTML)
+DOC_HTML = $(MAN_HTML) $(filter $(HTML_FILTER),$(ARTICLES_HTML) $(OBSOLETE_HTML))
 
-DOC_MAN1 = $(patsubst %.txt,%.1,$(MAN1_TXT))
-DOC_MAN5 = $(patsubst %.txt,%.5,$(MAN5_TXT))
-DOC_MAN7 = $(patsubst %.txt,%.7,$(MAN7_TXT))
+DOC_MAN1 = $(patsubst %.txt,%.1,$(filter $(MAN_FILTER),$(MAN1_TXT)))
+DOC_MAN5 = $(patsubst %.txt,%.5,$(filter $(MAN_FILTER),$(MAN5_TXT)))
+DOC_MAN7 = $(patsubst %.txt,%.7,$(filter $(MAN_FILTER),$(MAN7_TXT)))
 
 prefix ?= $(HOME)
 bindir ?= $(prefix)/bin
@@ -457,4 +464,9 @@ print-man1:
 lint-docs::
        $(QUIET_LINT)$(PERL_PATH) lint-gitlink.perl
 
+ifeq ($(wildcard po/Makefile),po/Makefile)
+doc-l10n install-l10n::
+       $(MAKE) -C po $@
+endif
+
 .PHONY: FORCE
index ea78e22a245cad0dd14b7d251050e98e40b49726..5ad2233c9950b1b3d0c3b558ac9c81bb3b7cf2f0 100644 (file)
@@ -51,6 +51,17 @@ UI, Workflows & Features
    learned to show a few more traits of objects that can be learned by
    the object_info API.
 
+ * "git rebase -i" learned to re-execute a command given with 'exec'
+   to run after it failed the last time.
+
+ * "git diff --color-moved-ws" updates.
+
+ * Custom userformat "log --format" learned %S atom that stands for
+   the tip the traversal reached the commit from, i.e. --source.
+
+ * "git instaweb" learned to drive http.server that comes with
+   "batteries included" Python installation (both Python2 & 3).
+
 
 Performance, Internal Implementation, Development Support etc.
 
@@ -77,6 +88,42 @@ Performance, Internal Implementation, Development Support etc.
    "--stress" option.
    (merge fb7d1e3ac8 sg/stress-test later to maint).
 
+ * Documentation/Makefile is getting prepared for manpage
+   localization.
+
+ * "git fetch-pack" now can talk the version 2 protocol.
+
+ * sha-256 hash has been added and plumbed through the code to allow
+   building Git with the "NewHash".
+
+ * Debugging help for http transport.
+
+ * "git fetch --deepen=<more>" has been corrected to work over v2
+   protocol.
+
+ * The code to walk tree objects has been taught that we may be
+   working with object names that are not computed with SHA-1.
+
+ * The in-core repository instances are passed through more codepaths.
+
+ * Update the protocol message specification to allow only the limited
+   use of scaled quantities.  This is ensure potential compatibility
+   issues will not go out of hand.
+
+ * Micro-optimize the code that prepares commit objects to be walked
+   by "git rev-list" when the commit-graph is available.
+
+ * "git fetch" and "git upload-pack" learned to send all exchange over
+   the sideband channel while talking the v2 protocol.
+
+ * The codepath to write out commit-graph has been optimized by
+   following the usual pattern of visiting objects in in-pack order.
+
+ * The codepath to show progress meter while writing out commit-graph
+   file has been improved.
+
+ * Cocci rules have been updated to encourage use of strbuf_addbuf().
+
 
 Fixes since v2.20
 -----------------
@@ -170,6 +217,98 @@ Fixes since v2.20
    corrected.
    (merge 5bdece0d70 js/gc-repack-close-before-remove later to maint).
 
+ * The code to drive GIT_EXTERNAL_DIFF command relied on the string
+   returned from getenv() to be non-volatile, which is not true, that
+   has been corrected.
+   (merge 6776a84dae kg/external-diff-save-env later to maint).
+
+ * There were many places the code relied on the string returned from
+   getenv() to be non-volatile, which is not true, that have been
+   corrected.
+   (merge 0da0e9268b jk/save-getenv-result later to maint).
+
+ * The v2 upload-pack protocol implementation failed to honor
+   hidden-ref configuration, which has been corrected.
+   (merge e20b4192a3 jk/proto-v2-hidden-refs-fix later to maint).
+
+ * "git fetch --recurse-submodules" may not fetch the necessary commit
+   that is bound to the superproject, which is getting corrected.
+   (merge be76c21282 sb/submodule-recursive-fetch-gets-the-tip later to maint).
+
+ * "git rebase" internally runs "checkout" to switch between branches,
+   and the command used to call the post-checkout hook, but the
+   reimplementation stopped doing so, which is getting fixed.
+
+ * "git add -e" got confused when the change it wants to let the user
+   edit is smaller than the previous change that was left over in a
+   temporary file.
+   (merge fa6f225e01 js/add-e-clear-patch-before-stating later to maint).
+
+ * "git p4" failed to update a shelved change when there were moved
+   files, which has been corrected.
+   (merge 7a10946ab9 ld/git-p4-shelve-update-fix later to maint).
+
+ * The codepath to read from the commit-graph file attempted to read
+   past the end of it when the file's table-of-contents was corrupt.
+
+ * The compat/obstack code had casts that -Wcast-function-type
+   compilation option found questionable.
+   (merge 764473d257 sg/obstack-cast-function-type-fix later to maint).
+
+ * An obvious typo in an assertion error message has been fixed.
+   (merge 3c27e2e059 cc/test-ref-store-typofix later to maint).
+
+ * In Git for Windows, "git clone \\server\share\path" etc. that uses
+   UNC paths from command line had bad interaction with its shell
+   emulation.
+
+ * "git add --ignore-errors" did not work as advertised and instead
+   worked as an unintended synonym for "git add --renormalize", which
+   has been fixed.
+   (merge 9e5da3d055 jk/add-ignore-errors-bit-assignment-fix later to maint).
+
+ * On a case-insensitive filesystem, we failed to compare the part of
+   the path that is above the worktree directory in an absolute
+   pathname, which has been corrected.
+
+ * Asking "git check-attr" about a macro (e.g. "binary") on a specific
+   path did not work correctly, even though "git check-attr -a" listed
+   such a macro correctly.  This has been corrected.
+   (merge 7b95849be4 jk/attr-macro-fix later to maint).
+
+ * "git pack-objects" incorrectly used uninitialized mutex, which has
+   been corrected.
+   (merge edb673cf10 ph/pack-objects-mutex-fix later to maint).
+
+ * "git checkout -b <new> [HEAD]" to create a new branch from the
+   current commit and check it out ought to be a no-op in the index
+   and the working tree in normal cases, but there are corner cases
+   that do require updates to the index and the working tree.  Running
+   it immediately after "git clone --no-checkout" is one of these
+   cases that an earlier optimization kicked in incorrectly, which has
+   been fixed.
+   (merge 8424bfd45b bp/checkout-new-branch-optim later to maint).
+
+ * "git diff --color-moved --cc --stat -p" did not work well due to
+   funny interaction between a bug in color-moved and the rest, which
+   has been fixed.
+   (merge dac03b5518 jk/diff-cc-stat-fixes later to maint).
+
+ * When GIT_SEQUENCE_EDITOR is set, the command was incorrectly
+   started when modes of "git rebase" that implicitly uses the
+   machinery for the interactive rebase are run, which has been
+   corrected.
+   (merge 891d4a0313 pw/no-editor-in-rebase-i-implicit later to maint).
+
+ * The commit-graph facility did not work when in-core objects that
+   are promoted from unknown type to commit (e.g. a commit that is
+   accessed via a tag that refers to it) were involved, which has been
+   corrected.
+   (merge 4468d4435c sg/object-as-type-commit-graph-fix later to maint).
+
+ * "git fetch" output cleanup.
+   (merge dc40b24df4 nd/fetch-compact-update later to maint).
+
  * Code cleanup, docfix, build fix, etc.
    (merge 89ba9a79ae hb/t0061-dot-in-path-fix later to maint).
    (merge d173e799ea sb/diff-color-moved-config-option-fixup later to maint).
@@ -186,3 +325,8 @@ Fixes since v2.20
    (merge 0650614982 cy/completion-typofix later to maint).
    (merge 6881925ef5 rs/sha1-file-close-mapped-file-on-error later to maint).
    (merge bd8d6f0def en/show-ref-doc-fix later to maint).
+   (merge 1747125e2c cc/parial-clone-doc-typofix later to maint).
+   (merge e01378753d cc/fetch-error-message-fix later to maint).
+   (merge 54e8c11215 jk/remote-insteadof-cleanup later to maint).
+   (merge d609615f48 js/test-git-installed later to maint).
+   (merge ba170517be ja/doc-style-fix later to maint).
index d0e6635fe0b56b87826240bc80cfef40b722bef4..7e9b6c8f4c2d36116be6699c0dc822222393dae6 100644 (file)
@@ -121,11 +121,14 @@ core.quotePath::
 
 core.eol::
        Sets the line ending type to use in the working directory for
-       files that have the `text` property set when core.autocrlf is false.
+       files that are marked as text (either by having the `text`
+       attribute set, or by having `text=auto` and Git auto-detecting
+       the contents as text).
        Alternatives are 'lf', 'crlf' and 'native', which uses the platform's
        native line ending.  The default value is `native`.  See
        linkgit:gitattributes[5] for more information on end-of-line
-       conversion.
+       conversion. Note that this value is ignored if `core.autocrlf`
+       is set to `true` or `input`.
 
 core.safecrlf::
        If true, makes Git check if converting `CRLF` is reversible when
index edac75c83f471bee7e9f560b1ec2defc13e0482e..425c73aa521a67f87941bd8fc11c69b52432cb00 100644 (file)
@@ -105,6 +105,15 @@ pack.useBitmaps::
        true. You should not generally need to turn this off unless
        you are debugging pack bitmaps.
 
+pack.useSparse::
+       When true, git will default to using the '--sparse' option in
+       'git pack-objects' when the '--revs' option is present. This
+       algorithm only walks trees that appear in paths that introduce new
+       objects. This can have significant performance benefits when
+       computing a pack to send a small change. However, it is possible
+       that extra objects are added to the pack-file if the included
+       commits contain certain types of direct renames.
+
 pack.writeBitmaps (deprecated)::
        This is a deprecated synonym for `repack.writeBitmaps`.
 
index f079bf6b7e5d88e012074a223a785f8de5949f78..331d250e0468df8ec51bdb3348d6a30274da26ed 100644 (file)
@@ -64,3 +64,8 @@ instead of:
 -------------------------------------------
 +
 Defaults to false.
+
+rebase.rescheduleFailedExec::
+       Automatically reschedule `exec` commands that failed. This only makes
+       sense in interactive mode (or when an `--exec` option was provided).
+       This is the same as specifying the `--reschedule-failed-exec` option.
index b94d332f71b0ff58fb12527f8ba13788b8aa6eeb..554a34080d7081da917cd54cd34eceb7bf4cd95c 100644 (file)
@@ -293,8 +293,12 @@ dimmed-zebra::
        `dimmed_zebra` is a deprecated synonym.
 --
 
+--no-color-moved::
+       Turn off move detection. This can be used to override configuration
+       settings. It is the same as `--color-moved=no`.
+
 --color-moved-ws=<modes>::
-       This configures how white spaces are ignored when performing the
+       This configures how whitespace is ignored when performing the
        move detection for `--color-moved`.
 ifdef::git-diff[]
        It can be set by the `diff.colorMovedWS` configuration setting.
@@ -302,6 +306,8 @@ endif::git-diff[]
        These modes can be given as a comma separated list:
 +
 --
+no::
+       Do not ignore whitespace when performing move detection.
 ignore-space-at-eol::
        Ignore changes in whitespace at EOL.
 ignore-space-change::
@@ -312,12 +318,17 @@ ignore-all-space::
        Ignore whitespace when comparing lines. This ignores differences
        even if one line has whitespace where the other line has none.
 allow-indentation-change::
-       Initially ignore any white spaces in the move detection, then
+       Initially ignore any whitespace in the move detection, then
        group the moved code blocks only into a block if the change in
        whitespace is the same per line. This is incompatible with the
        other modes.
 --
 
+--no-color-moved-ws::
+       Do not ignore whitespace when performing move detection. This can be
+       used to override configuration settings. It is the same as
+       `--color-moved-ws=no`.
+
 --word-diff[=<mode>]::
        Show a word diff, using the <mode> to delimit changed words.
        By default, words are delimited by whitespace; see
index 45652fe4a6a51c251f773776576956745701d677..37bcab94d5e435849c22ddd0473be5cfb1c56140 100644 (file)
@@ -58,9 +58,9 @@ OPTIONS
        specifying `dir` will record not just a file `dir/file1`
        modified in the working tree, a file `dir/file2` added to
        the working tree, but also a file `dir/file3` removed from
-       the working tree Note that older versions of Git used
+       the working tree). Note that older versions of Git used
        to ignore removed files; use `--no-all` option if you want
-       to add modified or new files but ignore removed ones.
+       to add modified or new files but ignore removed ones.
 +
 For more details about the <pathspec> syntax, see the 'pathspec' entry
 in linkgit:gitglossary[7].
@@ -124,7 +124,7 @@ subdirectories).
 --no-ignore-removal::
        Update the index not only where the working tree has a file
        matching <pathspec> but also where the index already has an
-       entry.  This adds, modifies, and removes index entries to
+       entry. This adds, modifies, and removes index entries to
        match the working tree.
 +
 If no <pathspec> is given when `-A` option is used, all
@@ -206,7 +206,7 @@ EXAMPLES
 --------
 
 * Adds content from all `*.txt` files under `Documentation` directory
-and its subdirectories:
+  and its subdirectories:
 +
 ------------
 $ git add Documentation/\*.txt
index bf5316ffa929a88aa98f5b3c7a892ee43638a098..3bd83a7cbdd9d62c9b10057bd4bf3f03d57b1085 100644 (file)
@@ -297,7 +297,7 @@ $ git checkout my2.6.14
 ------------
 +
 <1> This step and the next one could be combined into a single step with
-"checkout -b my2.6.14 v2.6.14".
+    "checkout -b my2.6.14 v2.6.14".
 
 Delete an unneeded branch::
 +
@@ -309,10 +309,10 @@ $ git branch -D test                                    <2>
 ------------
 +
 <1> Delete the remote-tracking branches "todo", "html" and "man". The next
-'fetch' or 'pull' will create them again unless you configure them not to.
-See linkgit:git-fetch[1].
+    'fetch' or 'pull' will create them again unless you configure them not to.
+    See linkgit:git-fetch[1].
 <2> Delete the "test" branch even if the "master" branch (or whichever branch
-is currently checked out) does not have all commits from the test branch.
+    is currently checked out) does not have all commits from the test branch.
 
 
 NOTES
index 74013335a1ccd18228a53acbd8dd7f5fe1ab40ca..8eca671b8278cfe02692605b80a9121bc5717567 100644 (file)
@@ -23,8 +23,8 @@ In the second form, a list of objects (separated by linefeeds) is provided on
 stdin, and the SHA-1, type, and size of each object is printed on stdout. The
 output format can be overridden using the optional `<format>` argument. If
 either `--textconv` or `--filters` was specified, the input is expected to
-list the object names followed by the path name, separated by a single white
-space, so that the appropriate drivers can be determined.
+list the object names followed by the path name, separated by a single
+whitespace, so that the appropriate drivers can be determined.
 
 OPTIONS
 -------
@@ -79,7 +79,7 @@ OPTIONS
        Print object information and contents for each object provided
        on stdin.  May not be combined with any other options or arguments
        except `--textconv` or `--filters`, in which case the input lines
-       also need to specify the path, separated by white space.  See the
+       also need to specify the path, separated by whitespace.  See the
        section `BATCH OUTPUT` below for details.
 
 --batch-check::
@@ -87,7 +87,7 @@ OPTIONS
        Print object information for each object provided on stdin.  May
        not be combined with any other options or arguments except
        `--textconv` or `--filters`, in which case the input lines also
-       need to specify the path, separated by white space.  See the
+       need to specify the path, separated by whitespace.  See the
        section `BATCH OUTPUT` below for details.
 
 --batch-all-objects::
@@ -252,6 +252,12 @@ the repository, then `cat-file` will ignore any custom format and print:
 <object> SP missing LF
 ------------
 
+If a name is specified that might refer to more than one object (an ambiguous short sha), then `cat-file` will ignore any custom format and print:
+
+------------
+<object> SP ambiguous LF
+------------
+
 If --follow-symlinks is used, and a symlink in the repository points
 outside the repository, then `cat-file` will ignore any custom format
 and print:
index 6acc3d98e7422be7f313b0a203a61565fae212c5..9a396498d106e1f3ff581d465c072d90686f8c21 100644 (file)
@@ -424,14 +424,14 @@ $ git tag foo           <3>
 ------------
 
 <1> creates a new branch 'foo', which refers to commit 'f', and then
-updates HEAD to refer to branch 'foo'. In other words, we'll no longer
-be in detached HEAD state after this command.
+    updates HEAD to refer to branch 'foo'. In other words, we'll no longer
+    be in detached HEAD state after this command.
 
 <2> similarly creates a new branch 'foo', which refers to commit 'f',
-but leaves HEAD detached.
+    but leaves HEAD detached.
 
 <3> creates a new tag 'foo', which refers to commit 'f',
-leaving HEAD detached.
+    leaving HEAD detached.
 
 If we have moved away from commit 'f', then we must first recover its object
 name (typically by using git reflog), and then we can create a reference to
@@ -459,8 +459,8 @@ EXAMPLES
 --------
 
 . The following sequence checks out the `master` branch, reverts
-the `Makefile` to two revisions back, deletes hello.c by
-mistake, and gets it back from the index.
+  the `Makefile` to two revisions back, deletes hello.c by
+  mistake, and gets it back from the index.
 +
 ------------
 $ git checkout master             <1>
@@ -494,7 +494,7 @@ $ git checkout -- hello.c
 ------------
 
 . After working in the wrong branch, switching to the correct
-branch would be done using:
+  branch would be done using:
 +
 ------------
 $ git checkout mytopic
@@ -522,7 +522,7 @@ registered in your index file, so `git diff` would show you what
 changes you made since the tip of the new branch.
 
 . When a merge conflict happens during switching branches with
-the `-m` option, you would see something like this:
+  the `-m` option, you would see something like this:
 +
 ------------
 $ git checkout -m mytopic
index d35d771fc8172e12958b4a9521c51a5f65cddebe..b8cfeec67e5fbdcfe1705a3b249f97b284932e79 100644 (file)
@@ -213,16 +213,16 @@ $ git reset --merge ORIG_HEAD        <3>
 $ git cherry-pick -Xpatience topic^  <4>
 ------------
 <1> apply the change that would be shown by `git show topic^`.
-In this example, the patch does not apply cleanly, so
-information about the conflict is written to the index and
-working tree and no new commit results.
+    In this example, the patch does not apply cleanly, so
+    information about the conflict is written to the index and
+    working tree and no new commit results.
 <2> summarize changes to be reconciled
 <3> cancel the cherry-pick.  In other words, return to the
-pre-cherry-pick state, preserving any local modifications you had in
-the working tree.
+    pre-cherry-pick state, preserving any local modifications
+    you had in the working tree.
 <4> try to apply the change introduced by `topic^` again,
-spending extra time to avoid mistakes based on incorrectly matching
-context lines.
+    spending extra time to avoid mistakes based on incorrectly
+    matching context lines.
 
 SEE ALSO
 --------
index 030f162f301608c329fecae04953620eb78f0b14..72179d993cb9b68766e2d9093f323cb3720e38f4 100644 (file)
@@ -132,9 +132,9 @@ $ git diff HEAD       <3>
 +
 <1> Changes in the working tree not yet staged for the next commit.
 <2> Changes between the index and your last commit; what you
-would be committing if you run "git commit" without "-a" option.
+    would be committing if you run "git commit" without "-a" option.
 <3> Changes in the working tree since your last commit; what you
-would be committing if you run "git commit -a"
+    would be committing if you run "git commit -a"
 
 Comparing with arbitrary commits::
 +
@@ -145,10 +145,10 @@ $ git diff HEAD^ HEAD      <3>
 ------------
 +
 <1> Instead of using the tip of the current branch, compare with the
-tip of "test" branch.
+    tip of "test" branch.
 <2> Instead of comparing with the tip of "test" branch, compare with
-the tip of the current branch, but limit the comparison to the
-file "test".
+    the tip of the current branch, but limit the comparison to the
+    file "test".
 <3> Compare the version before the last commit and the last commit.
 
 Comparing branches::
@@ -162,7 +162,7 @@ $ git diff topic...master  <3>
 <1> Changes between the tips of the topic and the master branches.
 <2> Same as above.
 <3> Changes that occurred on the master branch since when the topic
-branch was started off it.
+    branch was started off it.
 
 Limiting the diff output::
 +
@@ -173,9 +173,9 @@ $ git diff arch/i386 include/asm-i386   <3>
 ------------
 +
 <1> Show only modification, rename, and copy, but not addition
-or deletion.
+    or deletion.
 <2> Show only names and the nature of change, but not actual
-diff output.
+    diff output.
 <3> Limit diff output to named subtrees.
 
 Munging the diff output::
@@ -186,7 +186,7 @@ $ git diff -R                          <2>
 ------------
 +
 <1> Spend extra cycles to find renames, copies and complete
-rewrites (very expensive).
+    rewrites (very expensive).
 <2> Output diff in reverse.
 
 SEE ALSO
index e3199355978880b21668bc1aff0e42f610c02bd6..266d63cf111c8a73420c5fa945543384e9825b55 100644 (file)
@@ -266,7 +266,7 @@ The `pu` branch will be updated even if it is does not fast-forward,
 because it is prefixed with a plus sign; `tmp` will not be.
 
 * Peek at a remote's branch, without configuring the remote in your local
-repository:
+  repository:
 +
 ------------------------------------------------
 $ git fetch git://git.kernel.org/pub/scm/git/git.git maint
index 27304428a12ce9d0ee46e10e3c63069b4677838a..1af85d404f5191c18a8c587df06e7c0620066236 100644 (file)
@@ -504,9 +504,9 @@ Toggle it to make sure it is set to `false`. Also, search for
 "mailnews.wraplength" and set the value to 0.
 
 3. Disable the use of format=flowed:
-Edit..Preferences..Advanced..Config Editor.  Search for
-"mailnews.send_plaintext_flowed".
-Toggle it to make sure it is set to `false`.
+   Edit..Preferences..Advanced..Config Editor.  Search for
+   "mailnews.send_plaintext_flowed".
+   Toggle it to make sure it is set to `false`.
 
 After that is done, you should be able to compose email as you
 otherwise would (cut + paste, 'git format-patch' | 'git imap-send', etc),
@@ -629,14 +629,14 @@ EXAMPLES
 --------
 
 * Extract commits between revisions R1 and R2, and apply them on top of
-the current branch using 'git am' to cherry-pick them:
+  the current branch using 'git am' to cherry-pick them:
 +
 ------------
 $ git format-patch -k --stdout R1..R2 | git am -3 -k
 ------------
 
 * Extract all commits which are in the current branch but not in the
-origin branch:
+  origin branch:
 +
 ------------
 $ git format-patch origin
@@ -645,7 +645,7 @@ $ git format-patch origin
 For each commit a separate file is created in the current directory.
 
 * Extract all commits that lead to 'origin' since the inception of the
-project:
+  project:
 +
 ------------
 $ git format-patch --root origin
@@ -664,7 +664,7 @@ Note that non-Git "patch" programs won't understand renaming patches, so
 use it only when you know the recipient uses Git to apply your patch.
 
 * Extract three topmost commits from the current branch and format them
-as e-mailable patches:
+  as e-mailable patches:
 +
 ------------
 $ git format-patch -3
index aab5453bbbb239931ee2006095135c8db9f0f9ea..c318bf87e174f18798a2fcb0530bec05a34c4c92 100644 (file)
@@ -118,9 +118,9 @@ format is chosen. The following values are currently supported:
 
 * "man": use the 'man' program as usual,
 * "woman": use 'emacsclient' to launch the "woman" mode in emacs
-(this only works starting with emacsclient versions 22),
+  (this only works starting with emacsclient versions 22),
 * "konqueror": use 'kfmclient' to open the man page in a new konqueror
-tab (see 'Note about konqueror' below).
+  tab (see 'Note about konqueror' below).
 
 Values for other tools can be used if there is a corresponding
 `man.<tool>.cmd` configuration entry (see below).
index 057076ca38eecfc6d25caeb90110efc4c30e83a1..32880aafb0c55ce29f35490fd734587c38095066 100644 (file)
@@ -128,7 +128,7 @@ The template directory will be one of the following (in order):
 The default template directory includes some directory structure, suggested
 "exclude patterns" (see linkgit:gitignore[5]), and sample hook files.
 
-The sample hooks are all disabled by default, To enable one of the
+The sample hooks are all disabled by default. To enable one of the
 sample hooks rename it by removing its `.sample` suffix.
 
 See linkgit:githooks[5] for more general info on hook execution.
index e8ecdbf927ba5e7af79d3852a9a939c10052e45f..a54fe4401bd1a21c6bd133745ab8864882ca73d4 100644 (file)
@@ -29,7 +29,8 @@ OPTIONS
        The HTTP daemon command-line that will be executed.
        Command-line options may be specified here, and the
        configuration file will be added at the end of the command-line.
-       Currently apache2, lighttpd, mongoose, plackup and webrick are supported.
+       Currently apache2, lighttpd, mongoose, plackup, python and
+       webrick are supported.
        (Default: lighttpd)
 
 -m::
index 90761f169444c165f0e94ebc3b7731cd8d85d3f0..b02e922dc33d248493df4bf6e1bb42f342e38daa 100644 (file)
@@ -192,6 +192,10 @@ log.date::
        Default format for human-readable dates.  (Compare the
        `--date` option.)  Defaults to "default", which means to write
        dates like `Sat May 8 19:35:34 2010 -0500`.
++
+If the format is set to "auto:foo" and the pager is in use, format
+"foo" will be the used for the date format. Otherwise "default" will
+be used.
 
 log.follow::
        If `true`, `git log` will act as if the `--follow` option was used when
index f0a0280954f18532a1f12d4e5e6cae094c778784..3494a1db3ebf4991ed05011a8f4035807db7a9f6 100644 (file)
@@ -71,12 +71,12 @@ $ git p4 clone //depot/path/project
 ------------
 This:
 
-1.   Creates an empty Git repository in a subdirectory called 'project'.
+1. Creates an empty Git repository in a subdirectory called 'project'.
 +
-2.   Imports the full contents of the head revision from the given p4
-depot path into a single commit in the Git branch 'refs/remotes/p4/master'.
+2. Imports the full contents of the head revision from the given p4
+   depot path into a single commit in the Git branch 'refs/remotes/p4/master'.
 +
-3.   Creates a local branch, 'master' from this remote and checks it out.
+3. Creates a local branch, 'master' from this remote and checks it out.
 
 To reproduce the entire p4 history in Git, use the '@all' modifier on
 the depot path:
index 40c825c38197f4e335ebfb162415cdcc52bbdf1e..e45f3e680d3632c8122db01b2a51cc3971c27922 100644 (file)
@@ -14,7 +14,7 @@ SYNOPSIS
        [--local] [--incremental] [--window=<n>] [--depth=<n>]
        [--revs [--unpacked | --all]] [--keep-pack=<pack-name>]
        [--stdout [--filter=<filter-spec>] | base-name]
-       [--shallow] [--keep-true-parents] < object-list
+       [--shallow] [--keep-true-parents] [--sparse] < object-list
 
 
 DESCRIPTION
@@ -196,6 +196,15 @@ depth is 4095.
        Add --no-reuse-object if you want to force a uniform compression
        level on all data no matter the source.
 
+--sparse::
+       Use the "sparse" algorithm to determine which objects to include in
+       the pack, when combined with the "--revs" option. This algorithm
+       only walks trees that appear in paths that introduce new objects.
+       This can have significant performance benefits when computing
+       a pack to send a small change. However, it is possible that extra
+       objects are added to the pack-file if the included commits contain
+       certain types of direct renames.
+
 --thin::
        Create a "thin" pack by omitting the common objects between a
        sender and a receiver in order to reduce network transfer. This
index d284155cf33dfb9460d4af487eef680585959017..7e695b30e455245d8c187b7be0402e35bb83362c 100644 (file)
@@ -462,6 +462,12 @@ without an explicit `--interactive`.
 +
 See also INCOMPATIBLE OPTIONS below.
 
+-y <cmd>::
+       This is the same as passing `--reschedule-failed-exec` before
+       `-x <cmd>`, i.e. it appends the specified `exec` command and
+       turns on the mode where failed `exec` commands are automatically
+       rescheduled.
+
 --root::
        Rebase all commits reachable from <branch>, instead of
        limiting them with an <upstream>.  This allows you to rebase
@@ -501,18 +507,15 @@ See also INCOMPATIBLE OPTIONS below.
        with care: the final stash application after a successful
        rebase might result in non-trivial conflicts.
 
+--reschedule-failed-exec::
+--no-reschedule-failed-exec::
+       Automatically reschedule `exec` commands that failed. This only makes
+       sense in interactive mode (or when an `--exec` option was provided).
+
 INCOMPATIBLE OPTIONS
 --------------------
 
-git-rebase has many flags that are incompatible with each other,
-predominantly due to the fact that it has three different underlying
-implementations:
-
- * one based on linkgit:git-am[1] (the default)
- * one based on git-merge-recursive (merge backend)
- * one based on linkgit:git-cherry-pick[1] (interactive backend)
-
-Flags only understood by the am backend:
+The following options:
 
  * --committer-date-is-author-date
  * --ignore-date
@@ -520,15 +523,12 @@ Flags only understood by the am backend:
  * --ignore-whitespace
  * -C
 
-Flags understood by both merge and interactive backends:
+are incompatible with the following options:
 
  * --merge
  * --strategy
  * --strategy-option
  * --allow-empty-message
-
-Flags only understood by the interactive backend:
-
  * --[no-]autosquash
  * --rebase-merges
  * --preserve-merges
@@ -539,7 +539,7 @@ Flags only understood by the interactive backend:
  * --edit-todo
  * --root when used in combination with --onto
 
-Other incompatible flag pairs:
+In addition, the following pairs of options are incompatible:
 
  * --preserve-merges and --interactive
  * --preserve-merges and --signoff
index 9f69ae8b693a15184f26f65a44e552fb31a0bd32..132f8e55f67b2e2a40f0058888f4f8260c51f270 100644 (file)
@@ -115,17 +115,17 @@ $ git pull git://info.example.com/ nitfol  <4>
 ------------
 +
 <1> You are happily working on something, and find the changes
-in these files are in good order.  You do not want to see them
-when you run `git diff`, because you plan to work on other files
-and changes with these files are distracting.
+    in these files are in good order.  You do not want to see them
+    when you run `git diff`, because you plan to work on other files
+    and changes with these files are distracting.
 <2> Somebody asks you to pull, and the changes sound worthy of merging.
 <3> However, you already dirtied the index (i.e. your index does
-not match the `HEAD` commit).  But you know the pull you are going
-to make does not affect `frotz.c` or `filfre.c`, so you revert the
-index changes for these two files.  Your changes in working tree
-remain there.
+    not match the `HEAD` commit).  But you know the pull you are going
+    to make does not affect `frotz.c` or `filfre.c`, so you revert the
+    index changes for these two files.  Your changes in working tree
+    remain there.
 <4> Then you can pull and merge, leaving `frotz.c` and `filfre.c`
-changes still in the working tree.
+    changes still in the working tree.
 
 Undo a commit and redo::
 +
@@ -137,12 +137,12 @@ $ git commit -a -c ORIG_HEAD  <3>
 ------------
 +
 <1> This is most often done when you remembered what you
-just committed is incomplete, or you misspelled your commit
-message, or both.  Leaves working tree as it was before "reset".
+    just committed is incomplete, or you misspelled your commit
+    message, or both.  Leaves working tree as it was before "reset".
 <2> Make corrections to working tree files.
 <3> "reset" copies the old head to `.git/ORIG_HEAD`; redo the
-commit by starting with its log message.  If you do not need to
-edit the message further, you can give `-C` option instead.
+    commit by starting with its log message.  If you do not need to
+    edit the message further, you can give `-C` option instead.
 +
 See also the `--amend` option to linkgit:git-commit[1].
 
@@ -155,9 +155,9 @@ $ git checkout topic/wip   <3>
 ------------
 +
 <1> You have made some commits, but realize they were premature
-to be in the `master` branch.  You want to continue polishing
-them in a topic branch, so create `topic/wip` branch off of the
-current `HEAD`.
+    to be in the `master` branch.  You want to continue polishing
+    them in a topic branch, so create `topic/wip` branch off of the
+    current `HEAD`.
 <2> Rewind the master branch to get rid of those three commits.
 <3> Switch to `topic/wip` branch and keep working.
 
@@ -169,10 +169,10 @@ $ git reset --hard HEAD~3   <1>
 ------------
 +
 <1> The last three commits (`HEAD`, `HEAD^`, and `HEAD~2`) were bad
-and you do not want to ever see them again.  Do *not* do this if
-you have already given these commits to somebody else.  (See the
-"RECOVERING FROM UPSTREAM REBASE" section in linkgit:git-rebase[1] for
-the implications of doing so.)
+    and you do not want to ever see them again.  Do *not* do this if
+    you have already given these commits to somebody else.  (See the
+    "RECOVERING FROM UPSTREAM REBASE" section in linkgit:git-rebase[1]
+    for the implications of doing so.)
 
 Undo a merge or pull::
 +
@@ -189,18 +189,18 @@ $ git reset --hard ORIG_HEAD       <4>
 ------------
 +
 <1> Try to update from the upstream resulted in a lot of
-conflicts; you were not ready to spend a lot of time merging
-right now, so you decide to do that later.
+    conflicts; you were not ready to spend a lot of time merging
+    right now, so you decide to do that later.
 <2> "pull" has not made merge commit, so `git reset --hard`
-which is a synonym for `git reset --hard HEAD` clears the mess
-from the index file and the working tree.
+    which is a synonym for `git reset --hard HEAD` clears the mess
+    from the index file and the working tree.
 <3> Merge a topic branch into the current branch, which resulted
-in a fast-forward.
+    in a fast-forward.
 <4> But you decided that the topic branch is not ready for public
-consumption yet.  "pull" or "merge" always leaves the original
-tip of the current branch in `ORIG_HEAD`, so resetting hard to it
-brings your index file and the working tree back to that state,
-and resets the tip of the branch to that commit.
+    consumption yet.  "pull" or "merge" always leaves the original
+    tip of the current branch in `ORIG_HEAD`, so resetting hard to it
+    brings your index file and the working tree back to that state,
+    and resets the tip of the branch to that commit.
 
 Undo a merge or pull inside a dirty working tree::
 +
@@ -214,14 +214,14 @@ $ git reset --merge ORIG_HEAD      <2>
 ------------
 +
 <1> Even if you may have local modifications in your
-working tree, you can safely say `git pull` when you know
-that the change in the other branch does not overlap with
-them.
+    working tree, you can safely say `git pull` when you know
+    that the change in the other branch does not overlap with
+    them.
 <2> After inspecting the result of the merge, you may find
-that the change in the other branch is unsatisfactory.  Running
-`git reset --hard ORIG_HEAD` will let you go back to where you
-were, but it will discard your local changes, which you do not
-want.  `git reset --merge` keeps your local changes.
+    that the change in the other branch is unsatisfactory.  Running
+    `git reset --hard ORIG_HEAD` will let you go back to where you
+    were, but it will discard your local changes, which you do not
+    want.  `git reset --merge` keeps your local changes.
 
 
 Interrupted workflow::
index 62c6c76f2736e0ee2dd61d3ac25a4962a9db0fc7..1afe9fc858ea7dcd05ae5f77c994af8f17f5bf52 100644 (file)
@@ -33,7 +33,7 @@ This is what linkgit:git-format-patch[1] generates.  Most headers and MIME
 formatting are ignored.
 
 2. The original format used by Greg Kroah-Hartman's 'send_lots_of_email.pl'
-script
+   script
 +
 This format expects the first line of the file to contain the "Cc:" value
 and the "Subject:" of the message as the second line.
index f2d644e3af1849d842567bfb7a2c38083984545d..a74e7b926d030f6f385e49be68714133f6e3c06e 100644 (file)
@@ -237,16 +237,16 @@ your repository directly), then others will have already seen
 the old tag. In that case you can do one of two things:
 
 . The sane thing.
-Just admit you screwed up, and use a different name. Others have
-already seen one tag-name, and if you keep the same name, you
-may be in the situation that two people both have "version X",
-but they actually have 'different' "X"'s.  So just call it "X.1"
-and be done with it.
+  Just admit you screwed up, and use a different name. Others have
+  already seen one tag-name, and if you keep the same name, you
+  may be in the situation that two people both have "version X",
+  but they actually have 'different' "X"'s.  So just call it "X.1"
+  and be done with it.
 
 . The insane thing.
-You really want to call the new version "X" too, 'even though'
-others have already seen the old one. So just use 'git tag -f'
-again, as if you hadn't already published the old one.
+  You really want to call the new version "X" too, 'even though'
+  others have already seen the old one. So just use 'git tag -f'
+  again, as if you hadn't already published the old one.
 
 However, Git does *not* (and it should not) change tags behind
 users back. So if somebody already got the old tag, doing a
index 998f52d3df71e29d4178251de375d70cd570a1d8..9822c1eb1add168cdb30426bab04d925504d0205 100644 (file)
@@ -22,7 +22,6 @@ The UI for the protocol is on the 'git fetch-pack' side, and the
 program pair is meant to be used to pull updates from a remote
 repository.  For push operations, see 'git send-pack'.
 
-
 OPTIONS
 -------
 
index b8392fc3300cfa7d7c37e37dd069246f20ceadb1..9b41f81c06ef9fd2386b0e424d4d62cb27195ae3 100644 (file)
@@ -124,7 +124,9 @@ text file is normalized, its line endings are converted to LF in the
 repository.  To control what line ending style is used in the working
 directory, use the `eol` attribute for a single file and the
 `core.eol` configuration variable for all text files.
-Note that `core.autocrlf` overrides `core.eol`
+Note that setting `core.autocrlf` to `true` or `input` overrides
+`core.eol` (see the definitions of those options in
+linkgit:git-config[1]).
 
 Set::
 
@@ -344,7 +346,9 @@ automatic line ending conversion based on your platform.
 
 Use the following attributes if your '*.ps1' files are UTF-16 little
 endian encoded without BOM and you want Git to use Windows line endings
-in the working directory. Please note, it is highly recommended to
+in the working directory (use `UTF-16-LE-BOM` instead of `UTF-16LE` if
+you want UTF-16 little endian with BOM).
+Please note, it is highly recommended to
 explicitly define the line endings with `eol` if the `working-tree-encoding`
 attribute is used to avoid ambiguity.
 
index 417b638cd803e6cf3b106f3bd7333ba4f72d800a..de6953108cbc5324b9f6e9dacf23482aa698f45a 100644 (file)
@@ -134,6 +134,8 @@ The placeholders are:
 - '%cI': committer date, strict ISO 8601 format
 - '%d': ref names, like the --decorate option of linkgit:git-log[1]
 - '%D': ref names without the " (", ")" wrapping.
+- '%S': ref name given on the command line by which the commit was reached
+  (like `git log --source`), only works with `git log`
 - '%e': encoding
 - '%s': subject
 - '%f': sanitized subject line, suitable for a filename
index 98b538bc779635fcf59afd1a8cb366e9e57ed7ae..cad711ce0ac060d9356e49599ffc13d130fc593c 100644 (file)
@@ -270,13 +270,13 @@ depending on a few rules:
 +
 --
 1. If the starting point is specified as `ref@{Nth}`, show the index
-format.
+   format.
 +
 2. If the starting point was specified as `ref@{now}`, show the
-timestamp format.
+   timestamp format.
 +
 3. If neither was used, but `--date` was given on the command line, show
-the timestamp in the format requested by `--date`.
+   the timestamp in the format requested by `--date`.
 +
 4. Otherwise, show the index format.
 --
@@ -730,8 +730,13 @@ specification contained in <path>.
 +
 The form '--filter=tree:<depth>' omits all blobs and trees whose depth
 from the root tree is >= <depth> (minimum depth if an object is located
-at multiple depths in the commits traversed). Currently, only <depth>=0
-is supported, which omits all blobs and trees.
+at multiple depths in the commits traversed). <depth>=0 will not include
+any trees or blobs unless included explicitly in the command-line (or
+standard input when --stdin is used). <depth>=1 will include only the
+tree and blobs which are referenced directly by a commit reachable from
+<commit> or an explicitly-given object. <depth>=2 is like <depth>=1
+while also including trees and blobs one more level removed from an
+explicitly-given commit or tree.
 
 --no-filter::
        Turn off any previous `--filter=` argument.
@@ -831,6 +836,13 @@ Note that the `-local` option does not affect the seconds-since-epoch
 value (which is always measured in UTC), but does switch the accompanying
 timezone value.
 +
+`--date=human` shows the timezone if the timezone does not match the
+current time-zone, and doesn't print the whole date if that matches
+(ie skip printing year for dates that are "this year", but also skip
+the whole date itself if it's in the last few days and we can just say
+what weekday it was).  For older dates the hour and minute is also
+omitted.
++
 `--date=unix` shows the date as a Unix epoch timestamp (seconds since
 1970).  As with `--raw`, this is always in UTC and therefore `-local`
 has no effect.
index 9febfb1d528b2764d6d603ea25eae0ac6b048f68..c97428c2c3495e3f575ed944027740e882128482 100644 (file)
@@ -48,6 +48,11 @@ Functions
        is not sorted, this function has the side effect of sorting
        it.
 
+`oid_array_filter`::
+       Apply the callback function `want` to each entry in the array,
+       retaining only the entries for which the function returns true.
+       Preserve the order of the entries that are retained.
+
 Examples
 --------
 
index cc0474ba3ee4b04153752340328233437d5c7b05..16452a0504c8fa5b9b1b62cb907b96315db43942 100644 (file)
@@ -76,7 +76,7 @@ CHUNK DATA:
       of the ith commit. Stores value 0x7000000 if no parent in that
       position. If there are more than two parents, the second value
       has its most-significant bit on and the other bits store an array
-      position into the Large Edge List chunk.
+      position into the Extra Edge List chunk.
     * The next 8 bytes store the generation number of the commit and
       the commit time in seconds since EPOCH. The generation number
       uses the higher 30 bits of the first 4 bytes, while the commit
@@ -84,7 +84,7 @@ CHUNK DATA:
       2 bits of the lowest byte, storing the 33rd and 34th bit of the
       commit time.
 
-  Large Edge List (ID: {'E', 'D', 'G', 'E'}) [Optional]
+  Extra Edge List (ID: {'E', 'D', 'G', 'E'}) [Optional]
       This list of 4-byte values store the second through nth parents for
       all octopus merges. The second parent value in the commit data stores
       an array position within this list along with the most-significant bit
index 6ac774d5f665614848cdaba9e4c97d86a2453913..7a2375a55d074514c5ebd851fe55ff27541c207c 100644 (file)
@@ -22,6 +22,16 @@ protocol-common.txt. When the grammar indicate `PKT-LINE(...)`, unless
 otherwise noted the usual pkt-line LF rules apply: the sender SHOULD
 include a LF, but the receiver MUST NOT complain if it is not present.
 
+An error packet is a special pkt-line that contains an error string.
+
+----
+  error-line     =  PKT-LINE("ERR" SP explanation-text)
+----
+
+Throughout the protocol, where `PKT-LINE(...)` is expected, an error packet MAY
+be sent. Once this packet is sent by a client or a server, the data transfer
+process defined in this protocol is terminated.
+
 Transports
 ----------
 There are three transports over which the packfile protocol is
@@ -89,13 +99,6 @@ process on the server side over the Git protocol is this:
      "0039git-upload-pack /schacon/gitbook.git\0host=example.com\0" |
      nc -v example.com 9418
 
-If the server refuses the request for some reasons, it could abort
-gracefully with an error message.
-
-----
-  error-line     =  PKT-LINE("ERR" SP explanation-text)
-----
-
 
 SSH Transport
 -------------
@@ -398,12 +401,11 @@ from the client).
 Then the server will start sending its packfile data.
 
 ----
-  server-response = *ack_multi ack / nak / error-line
+  server-response = *ack_multi ack / nak
   ack_multi       = PKT-LINE("ACK" SP obj-id ack_status)
   ack_status      = "continue" / "common" / "ready"
   ack             = PKT-LINE("ACK" SP obj-id)
   nak             = PKT-LINE("NAK")
-  error-line     =  PKT-LINE("ERR" SP explanation-text)
 ----
 
 A simple clone may look like this (with no 'have' lines):
index 1ef66bd788a0997f73ec736c806a5aadad63ee39..896c7b3878869de8d3564b42abcef9d4ea5dedec 100644 (file)
@@ -114,7 +114,7 @@ their "<name>.pack" and "<name>.idx" files.
   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
+When Git encounters a missing object, Git can see if it is 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
index 09e4e0273fd515254b41cf2d36e3b6083de1d4ee..ead85ce35cf2342335af69221e4b4e956b9f66fd 100644 (file)
@@ -296,7 +296,13 @@ included in the client's request:
        Request that various objects from the packfile be omitted
        using one of several filtering techniques. These are intended
        for use with partial clone and partial fetch operations. See
-       `rev-list` for possible "filter-spec" values.
+       `rev-list` for possible "filter-spec" values. When communicating
+       with other processes, senders SHOULD translate scaled integers
+       (e.g. "1k") into a fully-expanded form (e.g. "1024") to aid
+       interoperability with older receivers that may not understand
+       newly-invented scaling suffixes. However, receivers SHOULD
+       accept the following suffixes: 'k', 'm', and 'g' for 1024,
+       1048576, and 1073741824, respectively.
 
 If the 'ref-in-want' feature is advertised, the following argument can
 be included in the client's request as well as the potential addition of
@@ -307,6 +313,16 @@ the 'wanted-refs' section in the server's response as explained below.
        particular ref, where <ref> is the full name of a ref on the
        server.
 
+If the 'sideband-all' feature is advertised, the following argument can be
+included in the client's request:
+
+    sideband-all
+       Instruct the server to send the whole response multiplexed, not just
+       the packfile section. All non-flush and non-delim PKT-LINE in the
+       response (not only in the packfile section) will then start with a byte
+       indicating its sideband (1, 2, or 3), and the server may send "0005\2"
+       (a PKT-LINE of sideband 2 with no payload) as a keepalive packet.
+
 The response of `fetch` is broken into a number of sections separated by
 delimiter packets (0001), with each section beginning with its section
 header.
index 1a44c811aa56330327172cf693c61f9a221e4e16..afa411d727532f95278438851a5ad09292fb7f48 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -186,6 +186,12 @@ all::
 # in one call to the platform's SHA1_Update(). e.g. APPLE_COMMON_CRYPTO
 # wants 'SHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L' defined.
 #
+# Define BLK_SHA256 to use the built-in SHA-256 routines.
+#
+# Define GCRYPT_SHA256 to use the SHA-256 routines in libgcrypt.
+#
+# Define OPENSSL_SHA256 to use the SHA-256 routines in OpenSSL.
+#
 # Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin).
 #
 # Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin).
@@ -628,7 +634,6 @@ SCRIPT_LIB += git-parse-remote
 SCRIPT_LIB += git-rebase--am
 SCRIPT_LIB += git-rebase--common
 SCRIPT_LIB += git-rebase--preserve-merges
-SCRIPT_LIB += git-rebase--merge
 SCRIPT_LIB += git-sh-setup
 SCRIPT_LIB += git-sh-i18n
 
@@ -684,6 +689,7 @@ SCRIPTS = $(SCRIPT_SH_INS) \
 
 ETAGS_TARGET = TAGS
 
+FUZZ_OBJS += fuzz-commit-graph.o
 FUZZ_OBJS += fuzz-pack-headers.o
 FUZZ_OBJS += fuzz-pack-idx.o
 
@@ -724,7 +730,9 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o
 TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
 TEST_BUILTINS_OBJS += test-example-decorate.o
 TEST_BUILTINS_OBJS += test-genrandom.o
+TEST_BUILTINS_OBJS += test-hash.o
 TEST_BUILTINS_OBJS += test-hashmap.o
+TEST_BUILTINS_OBJS += test-hash-speed.o
 TEST_BUILTINS_OBJS += test-index-version.o
 TEST_BUILTINS_OBJS += test-json-writer.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
@@ -747,6 +755,7 @@ TEST_BUILTINS_OBJS += test-run-command.o
 TEST_BUILTINS_OBJS += test-scrap-cache-tree.o
 TEST_BUILTINS_OBJS += test-sha1.o
 TEST_BUILTINS_OBJS += test-sha1-array.o
+TEST_BUILTINS_OBJS += test-sha256.o
 TEST_BUILTINS_OBJS += test-sigchain.o
 TEST_BUILTINS_OBJS += test-strcmp-offset.o
 TEST_BUILTINS_OBJS += test-string-list.o
@@ -1646,6 +1655,19 @@ endif
 endif
 endif
 
+ifdef OPENSSL_SHA256
+       EXTLIBS += $(LIB_4_CRYPTO)
+       BASIC_CFLAGS += -DSHA256_OPENSSL
+else
+ifdef GCRYPT_SHA256
+       BASIC_CFLAGS += -DSHA256_GCRYPT
+       EXTLIBS += -lgcrypt
+else
+       LIB_OBJS += sha256/block/sha256.o
+       BASIC_CFLAGS += -DSHA256_BLK
+endif
+endif
+
 ifdef SHA1_MAX_BLOCK_SIZE
        LIB_OBJS += compat/sha1-chunked.o
        BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)"
@@ -3103,7 +3125,7 @@ cover_db_html: cover_db
 # An example command to build against libFuzzer from LLVM 4.0.0:
 #
 # make CC=clang CXX=clang++ \
-#      FUZZ_CXXFLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address" \
+#      CFLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address" \
 #      LIB_FUZZING_ENGINE=/usr/lib/llvm-4.0/lib/libFuzzer.a \
 #      fuzz-all
 #
diff --git a/alloc.c b/alloc.c
index e7aa81b7aa48c14f2a98894eb6e8c2e28998945e..1c64c4dd1629c63a8bb2fff6e580ee0c648a0730 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -99,18 +99,23 @@ void *alloc_object_node(struct repository *r)
        return obj;
 }
 
-unsigned int alloc_commit_index(struct repository *r)
+static unsigned int alloc_commit_index(struct repository *r)
 {
        return r->parsed_objects->commit_count++;
 }
 
-void *alloc_commit_node(struct repository *r)
+void init_commit_node(struct repository *r, struct commit *c)
 {
-       struct commit *c = alloc_node(r->parsed_objects->commit_state, sizeof(struct commit));
        c->object.type = OBJ_COMMIT;
        c->index = alloc_commit_index(r);
        c->graph_pos = COMMIT_NOT_FROM_GRAPH;
        c->generation = GENERATION_NUMBER_INFINITY;
+}
+
+void *alloc_commit_node(struct repository *r)
+{
+       struct commit *c = alloc_node(r->parsed_objects->commit_state, sizeof(struct commit));
+       init_commit_node(r, c);
        return c;
 }
 
diff --git a/alloc.h b/alloc.h
index ba356ed8478d13f05f49efd5bacccaac3e69dfd7..ed1071c11ea3a6d0f7d55da46df4acf524a32565 100644 (file)
--- a/alloc.h
+++ b/alloc.h
@@ -9,11 +9,11 @@ struct repository;
 
 void *alloc_blob_node(struct repository *r);
 void *alloc_tree_node(struct repository *r);
+void init_commit_node(struct repository *r, struct commit *c);
 void *alloc_commit_node(struct repository *r);
 void *alloc_tag_node(struct repository *r);
 void *alloc_object_node(struct repository *r);
 void alloc_report(struct repository *r);
-unsigned int alloc_commit_index(struct repository *r);
 
 struct alloc_state *allocate_alloc_state(void);
 void clear_alloc_state(struct alloc_state *s);
diff --git a/apply.c b/apply.c
index 3703bfc8d03deb3be3a3fa9a45a2dd64b0a8eafd..beed3091d2a347116a11cb4b593a70b2c90406f8 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -467,7 +467,6 @@ static char *squash_slash(char *name)
 
 static char *find_name_gnu(struct apply_state *state,
                           const char *line,
-                          const char *def,
                           int p_value)
 {
        struct strbuf name = STRBUF_INIT;
@@ -714,7 +713,7 @@ static char *find_name(struct apply_state *state,
                       int terminate)
 {
        if (*line == '"') {
-               char *name = find_name_gnu(state, line, def, p_value);
+               char *name = find_name_gnu(state, line, p_value);
                if (name)
                        return name;
        }
@@ -731,7 +730,7 @@ static char *find_name_traditional(struct apply_state *state,
        size_t date_len;
 
        if (*line == '"') {
-               char *name = find_name_gnu(state, line, def, p_value);
+               char *name = find_name_gnu(state, line, p_value);
                if (name)
                        return name;
        }
@@ -4020,7 +4019,7 @@ static int read_apply_cache(struct apply_state *state)
                return read_index_from(state->repo->index, state->index_file,
                                       get_git_dir());
        else
-               return read_index(state->repo->index);
+               return repo_read_index(state->repo);
 }
 
 /* This function tries to read the object name from the current index */
@@ -4713,7 +4712,8 @@ static int apply_patch(struct apply_state *state,
                                                  state->index_file,
                                                  LOCK_DIE_ON_ERROR);
                else
-                       hold_locked_index(&state->lock_file, LOCK_DIE_ON_ERROR);
+                       repo_hold_locked_index(state->repo, &state->lock_file,
+                                              LOCK_DIE_ON_ERROR);
        }
 
        if (state->check_index && read_apply_cache(state) < 0) {
diff --git a/attr.c b/attr.c
index b63fe0fc0e99caa07dc2e6da816e1ac8d5942df6..fdd110bec55cb3bc5c8ebbb8cffbc33cced530b2 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -7,7 +7,6 @@
  * an insanely large number of attributes.
  */
 
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "exec-cmd.h"
@@ -1092,7 +1091,7 @@ static void collect_some_attrs(const struct index_state *istate,
                               const char *path,
                               struct attr_check *check)
 {
-       int i, pathlen, rem, dirlen;
+       int pathlen, rem, dirlen;
        const char *cp, *last_slash = NULL;
        int basename_offset;
 
@@ -1113,20 +1112,6 @@ static void collect_some_attrs(const struct index_state *istate,
        all_attrs_init(&g_attr_hashmap, check);
        determine_macros(check->all_attrs, check->stack);
 
-       if (check->nr) {
-               rem = 0;
-               for (i = 0; i < check->nr; i++) {
-                       int n = check->items[i].attr->attr_nr;
-                       struct all_attrs_item *item = &check->all_attrs[n];
-                       if (item->macro) {
-                               item->value = ATTR__UNSET;
-                               rem++;
-                       }
-               }
-               if (rem == check->nr)
-                       return;
-       }
-
        rem = check->all_attrs_nr;
        fill(path, pathlen, basename_offset, check->stack, check->all_attrs, rem);
 }
index 6bf521138a590496a7b3fa7c2515ac53f815a1e3..3af955c4bc4e1c7cd155a5f2e460cee38af732cd 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -658,7 +658,7 @@ static void bisect_common(struct rev_info *revs)
        if (prepare_revision_walk(revs))
                die("revision walk setup failed");
        if (revs->tree_objects)
-               mark_edges_uninteresting(revs, NULL);
+               mark_edges_uninteresting(revs, NULL, 0);
 }
 
 static void exit_if_skipped_commits(struct commit_list *tried,
diff --git a/blame.c b/blame.c
index 43861437f749849e85d448eba692b42488ec459d..da57233cbbd98d41bdfeba46e861b1f5f61dfbe2 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -188,7 +188,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
        unsigned mode;
        struct strbuf msg = STRBUF_INIT;
 
-       read_index(r->index);
+       repo_read_index(r);
        time(&now);
        commit = alloc_commit_node(r);
        commit->object.parsed = 1;
@@ -270,7 +270,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
         * want to run "diff-index --cached".
         */
        discard_index(r->index);
-       read_index(r->index);
+       repo_read_index(r);
 
        len = strlen(path);
        if (!mode) {
index 12247b48fd42d4a4b6955ff997fdf51a8785f9ae..db2dfa43502d0059219189f01731e143982345ab 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2006 Linus Torvalds
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
@@ -137,7 +138,7 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
                        continue; /* do not touch non blobs */
                if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
                        continue;
-               retval |= add_file_to_cache(ce->name, flags | HASH_RENORMALIZE);
+               retval |= add_file_to_cache(ce->name, flags | ADD_CACHE_RENORMALIZE);
        }
 
        return retval;
@@ -239,7 +240,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
        rev.diffopt.output_format = DIFF_FORMAT_PATCH;
        rev.diffopt.use_color = 0;
        rev.diffopt.flags.ignore_dirty_submodules = 1;
-       out = open(file, O_CREAT | O_WRONLY, 0666);
+       out = open(file, O_CREAT | O_WRONLY | O_TRUNC, 0666);
        if (out < 0)
                die(_("Could not open '%s' for writing."), file);
        rev.diffopt.file = xfdopen(out, "w");
index 95370313b66daad8cabcc3b855136e29afb3133f..58a2aef28bbcd715660422dc37042e79d4d350c1 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Based on git-am.sh by Junio C Hamano.
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
 #include "packfile.h"
 #include "repository.h"
 
-/**
- * Returns 1 if the file is empty or does not exist, 0 otherwise.
- */
-static int is_empty_file(const char *filename)
-{
-       struct stat st;
-
-       if (stat(filename, &st) < 0) {
-               if (errno == ENOENT)
-                       return 1;
-               die_errno(_("could not stat %s"), filename);
-       }
-
-       return !st.st_size;
-}
-
 /**
  * Returns the length of the first line of msg.
  */
@@ -527,7 +512,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
        }
 
 finish:
-       finish_copy_notes_for_rewrite(c, msg);
+       finish_copy_notes_for_rewrite(the_repository, c, msg);
        fclose(fp);
        strbuf_release(&sb);
        return ret;
@@ -1220,7 +1205,7 @@ static int parse_mail(struct am_state *state, const char *mail)
                goto finish;
        }
 
-       if (is_empty_file(am_path(state, "patch"))) {
+       if (is_empty_or_missing_file(am_path(state, "patch"))) {
                printf_ln(_("Patch is empty."));
                die_user_resolve(state);
        }
@@ -1545,7 +1530,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
         * changes.
         */
 
-       init_merge_options(&o);
+       init_merge_options(&o, the_repository);
 
        o.branch1 = "HEAD";
        their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
@@ -1719,7 +1704,7 @@ static void am_run(struct am_state *state, int resume)
 
        refresh_and_write_cache();
 
-       if (index_has_changes(&the_index, NULL, &sb)) {
+       if (repo_index_has_changes(the_repository, NULL, &sb)) {
                write_state_bool(state, "dirtyindex", 1);
                die(_("Dirty index: cannot apply patches (dirty: %s)"), sb.buf);
        }
@@ -1777,7 +1762,7 @@ static void am_run(struct am_state *state, int resume)
                         * the result may have produced the same tree as ours.
                         */
                        if (!apply_status &&
-                           !index_has_changes(&the_index, NULL, NULL)) {
+                           !repo_index_has_changes(the_repository, NULL, NULL)) {
                                say(state, stdout, _("No changes -- Patch already applied."));
                                goto next;
                        }
@@ -1803,7 +1788,7 @@ static void am_run(struct am_state *state, int resume)
                resume = 0;
        }
 
-       if (!is_empty_file(am_path(state, "rewritten"))) {
+       if (!is_empty_or_missing_file(am_path(state, "rewritten"))) {
                assert(state->rebasing);
                copy_notes_for_rebase(state);
                run_post_rewrite_hook(state);
@@ -1831,7 +1816,7 @@ static void am_resolve(struct am_state *state)
 
        say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
 
-       if (!index_has_changes(&the_index, NULL, NULL)) {
+       if (!repo_index_has_changes(the_repository, NULL, NULL)) {
                printf_ln(_("No changes - did you forget to use 'git add'?\n"
                        "If there is nothing left to stage, chances are that something else\n"
                        "already introduced the same changes; you might want to skip this patch."));
@@ -2000,6 +1985,15 @@ static void am_skip(struct am_state *state)
        if (clean_index(&head, &head))
                die(_("failed to clean index"));
 
+       if (state->rebasing) {
+               FILE *fp = xfopen(am_path(state, "rewritten"), "a");
+
+               assert(!is_null_oid(&state->orig_commit));
+               fprintf(fp, "%s ", oid_to_hex(&state->orig_commit));
+               fprintf(fp, "%s\n", oid_to_hex(&head));
+               fclose(fp);
+       }
+
        am_next(state);
        am_load(state);
        am_run(state, 0);
@@ -2278,7 +2272,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
        /* Ensure a valid committer ident can be constructed */
        git_committer_info(IDENT_STRICT);
 
-       if (read_index_preload(&the_index, NULL, 0) < 0)
+       if (repo_read_index_preload(the_repository, NULL, 0) < 0)
                die(_("failed to read the index"));
 
        if (in_progress) {
index d2455237ce04d68de624ed60157dc90a4ee4e477..45d11669aae459caf95bb6b4737558297debae89 100644 (file)
@@ -27,10 +27,10 @@ static int run_remote_archiver(int argc, const char **argv,
                               const char *remote, const char *exec,
                               const char *name_hint)
 {
-       char *buf;
        int fd[2], i, rv;
        struct transport *transport;
        struct remote *_remote;
+       struct packet_reader reader;
 
        _remote = remote_get(remote);
        if (!_remote->url[0])
@@ -53,18 +53,19 @@ static int run_remote_archiver(int argc, const char **argv,
                packet_write_fmt(fd[1], "argument %s\n", argv[i]);
        packet_flush(fd[1]);
 
-       buf = packet_read_line(fd[0], NULL);
-       if (!buf)
+       packet_reader_init(&reader, fd[0], NULL, 0,
+                          PACKET_READ_CHOMP_NEWLINE |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
+
+       if (packet_reader_read(&reader) != PACKET_READ_NORMAL)
                die(_("git archive: expected ACK/NAK, got a flush packet"));
-       if (strcmp(buf, "ACK")) {
-               if (starts_with(buf, "NACK "))
-                       die(_("git archive: NACK %s"), buf + 5);
-               if (starts_with(buf, "ERR "))
-                       die(_("remote error: %s"), buf + 4);
+       if (strcmp(reader.line, "ACK")) {
+               if (starts_with(reader.line, "NACK "))
+                       die(_("git archive: NACK %s"), reader.line + 5);
                die(_("git archive: protocol error"));
        }
 
-       if (packet_read_line(fd[0], NULL))
+       if (packet_reader_read(&reader) != PACKET_READ_FLUSH)
                die(_("git archive: expected a flush"));
 
        /* Now, start reading from fd[0] and spit it out to stdout */
index 417d141c09ad2698c17cf4738ad6ce7177456088..c1cff3266114323f466133b98050f5aec71c5f91 100644 (file)
@@ -3,18 +3,58 @@
 #include "parse-options.h"
 #include "bisect.h"
 #include "refs.h"
+#include "dir.h"
+#include "argv-array.h"
+#include "run-command.h"
+#include "prompt.h"
+#include "quote.h"
 
 static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
 static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
 static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
+static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
+static GIT_PATH_FUNC(git_path_bisect_head, "BISECT_HEAD")
+static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
+static GIT_PATH_FUNC(git_path_head_name, "head-name")
+static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
 
 static const char * const git_bisect_helper_usage[] = {
        N_("git bisect--helper --next-all [--no-checkout]"),
        N_("git bisect--helper --write-terms <bad_term> <good_term>"),
        N_("git bisect--helper --bisect-clean-state"),
+       N_("git bisect--helper --bisect-reset [<commit>]"),
+       N_("git bisect--helper --bisect-write [--no-log] <state> <revision> <good_term> <bad_term>"),
+       N_("git bisect--helper --bisect-check-and-set-terms <command> <good_term> <bad_term>"),
+       N_("git bisect--helper --bisect-next-check <good_term> <bad_term> [<term>]"),
+       N_("git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]"),
+       N_("git bisect--helper --bisect-start [--term-{old,good}=<term> --term-{new,bad}=<term>]"
+                                            "[--no-checkout] [<bad> [<good>...]] [--] [<paths>...]"),
        NULL
 };
 
+struct bisect_terms {
+       char *term_good;
+       char *term_bad;
+};
+
+static void free_terms(struct bisect_terms *terms)
+{
+       FREE_AND_NULL(terms->term_good);
+       FREE_AND_NULL(terms->term_bad);
+}
+
+static void set_terms(struct bisect_terms *terms, const char *bad,
+                     const char *good)
+{
+       free((void *)terms->term_good);
+       terms->term_good = xstrdup(good);
+       free((void *)terms->term_bad);
+       terms->term_bad = xstrdup(bad);
+}
+
+static const char *vocab_bad = "bad|new";
+static const char *vocab_good = "good|old";
+
 /*
  * Check whether the string `term` belongs to the set of strings
  * included in the variable arguments.
@@ -106,15 +146,482 @@ static void check_expected_revs(const char **revs, int rev_nr)
        }
 }
 
+static int bisect_reset(const char *commit)
+{
+       struct strbuf branch = STRBUF_INIT;
+
+       if (!commit) {
+               if (strbuf_read_file(&branch, git_path_bisect_start(), 0) < 1) {
+                       printf(_("We are not bisecting.\n"));
+                       return 0;
+               }
+               strbuf_rtrim(&branch);
+       } else {
+               struct object_id oid;
+
+               if (get_oid_commit(commit, &oid))
+                       return error(_("'%s' is not a valid commit"), commit);
+               strbuf_addstr(&branch, commit);
+       }
+
+       if (!file_exists(git_path_bisect_head())) {
+               struct argv_array argv = ARGV_ARRAY_INIT;
+
+               argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL);
+               if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) {
+                       strbuf_release(&branch);
+                       argv_array_clear(&argv);
+                       return error(_("could not check out original"
+                                      " HEAD '%s'. Try 'git bisect"
+                                      "reset <commit>'."), branch.buf);
+               }
+               argv_array_clear(&argv);
+       }
+
+       strbuf_release(&branch);
+       return bisect_clean_state();
+}
+
+static void log_commit(FILE *fp, char *fmt, const char *state,
+                      struct commit *commit)
+{
+       struct pretty_print_context pp = {0};
+       struct strbuf commit_msg = STRBUF_INIT;
+       char *label = xstrfmt(fmt, state);
+
+       format_commit_message(commit, "%s", &commit_msg, &pp);
+
+       fprintf(fp, "# %s: [%s] %s\n", label, oid_to_hex(&commit->object.oid),
+               commit_msg.buf);
+
+       strbuf_release(&commit_msg);
+       free(label);
+}
+
+static int bisect_write(const char *state, const char *rev,
+                       const struct bisect_terms *terms, int nolog)
+{
+       struct strbuf tag = STRBUF_INIT;
+       struct object_id oid;
+       struct commit *commit;
+       FILE *fp = NULL;
+       int retval = 0;
+
+       if (!strcmp(state, terms->term_bad)) {
+               strbuf_addf(&tag, "refs/bisect/%s", state);
+       } else if (one_of(state, terms->term_good, "skip", NULL)) {
+               strbuf_addf(&tag, "refs/bisect/%s-%s", state, rev);
+       } else {
+               retval = error(_("Bad bisect_write argument: %s"), state);
+               goto finish;
+       }
+
+       if (get_oid(rev, &oid)) {
+               retval = error(_("couldn't get the oid of the rev '%s'"), rev);
+               goto finish;
+       }
+
+       if (update_ref(NULL, tag.buf, &oid, NULL, 0,
+                      UPDATE_REFS_MSG_ON_ERR)) {
+               retval = -1;
+               goto finish;
+       }
+
+       fp = fopen(git_path_bisect_log(), "a");
+       if (!fp) {
+               retval = error_errno(_("couldn't open the file '%s'"), git_path_bisect_log());
+               goto finish;
+       }
+
+       commit = lookup_commit_reference(the_repository, &oid);
+       log_commit(fp, "%s", state, commit);
+
+       if (!nolog)
+               fprintf(fp, "git bisect %s %s\n", state, rev);
+
+finish:
+       if (fp)
+               fclose(fp);
+       strbuf_release(&tag);
+       return retval;
+}
+
+static int check_and_set_terms(struct bisect_terms *terms, const char *cmd)
+{
+       int has_term_file = !is_empty_or_missing_file(git_path_bisect_terms());
+
+       if (one_of(cmd, "skip", "start", "terms", NULL))
+               return 0;
+
+       if (has_term_file && strcmp(cmd, terms->term_bad) &&
+           strcmp(cmd, terms->term_good))
+               return error(_("Invalid command: you're currently in a "
+                               "%s/%s bisect"), terms->term_bad,
+                               terms->term_good);
+
+       if (!has_term_file) {
+               if (one_of(cmd, "bad", "good", NULL)) {
+                       set_terms(terms, "bad", "good");
+                       return write_terms(terms->term_bad, terms->term_good);
+               }
+               if (one_of(cmd, "new", "old", NULL)) {
+                       set_terms(terms, "new", "old");
+                       return write_terms(terms->term_bad, terms->term_good);
+               }
+       }
+
+       return 0;
+}
+
+static int mark_good(const char *refname, const struct object_id *oid,
+                    int flag, void *cb_data)
+{
+       int *m_good = (int *)cb_data;
+       *m_good = 0;
+       return 1;
+}
+
+static const char *need_bad_and_good_revision_warning =
+       N_("You need to give me at least one %s and %s revision.\n"
+          "You can use \"git bisect %s\" and \"git bisect %s\" for that.");
+
+static const char *need_bisect_start_warning =
+       N_("You need to start by \"git bisect start\".\n"
+          "You then need to give me at least one %s and %s revision.\n"
+          "You can use \"git bisect %s\" and \"git bisect %s\" for that.");
+
+static int bisect_next_check(const struct bisect_terms *terms,
+                            const char *current_term)
+{
+       int missing_good = 1, missing_bad = 1, retval = 0;
+       const char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad);
+       const char *good_glob = xstrfmt("%s-*", terms->term_good);
+
+       if (ref_exists(bad_ref))
+               missing_bad = 0;
+
+       for_each_glob_ref_in(mark_good, good_glob, "refs/bisect/",
+                            (void *) &missing_good);
+
+       if (!missing_good && !missing_bad)
+               goto finish;
+
+       if (!current_term) {
+               retval = -1;
+               goto finish;
+       }
+
+       if (missing_good && !missing_bad &&
+           !strcmp(current_term, terms->term_good)) {
+               char *yesno;
+               /*
+                * have bad (or new) but not good (or old). We could bisect
+                * although this is less optimum.
+                */
+               warning(_("bisecting only with a %s commit"), terms->term_bad);
+               if (!isatty(0))
+                       goto finish;
+               /*
+                * TRANSLATORS: Make sure to include [Y] and [n] in your
+                * translation. The program will only accept English input
+                * at this point.
+                */
+               yesno = git_prompt(_("Are you sure [Y/n]? "), PROMPT_ECHO);
+               if (starts_with(yesno, "N") || starts_with(yesno, "n"))
+                       retval = -1;
+               goto finish;
+       }
+       if (!is_empty_or_missing_file(git_path_bisect_start())) {
+               retval = error(_(need_bad_and_good_revision_warning),
+                              vocab_bad, vocab_good, vocab_bad, vocab_good);
+       } else {
+               retval = error(_(need_bisect_start_warning),
+                              vocab_good, vocab_bad, vocab_good, vocab_bad);
+       }
+
+finish:
+       free((void *) good_glob);
+       free((void *) bad_ref);
+       return retval;
+}
+
+static int get_terms(struct bisect_terms *terms)
+{
+       struct strbuf str = STRBUF_INIT;
+       FILE *fp = NULL;
+       int res = 0;
+
+       fp = fopen(git_path_bisect_terms(), "r");
+       if (!fp) {
+               res = -1;
+               goto finish;
+       }
+
+       free_terms(terms);
+       strbuf_getline_lf(&str, fp);
+       terms->term_bad = strbuf_detach(&str, NULL);
+       strbuf_getline_lf(&str, fp);
+       terms->term_good = strbuf_detach(&str, NULL);
+
+finish:
+       if (fp)
+               fclose(fp);
+       strbuf_release(&str);
+       return res;
+}
+
+static int bisect_terms(struct bisect_terms *terms, const char *option)
+{
+       if (get_terms(terms))
+               return error(_("no terms defined"));
+
+       if (option == NULL) {
+               printf(_("Your current terms are %s for the old state\n"
+                        "and %s for the new state.\n"),
+                      terms->term_good, terms->term_bad);
+               return 0;
+       }
+       if (one_of(option, "--term-good", "--term-old", NULL))
+               printf("%s\n", terms->term_good);
+       else if (one_of(option, "--term-bad", "--term-new", NULL))
+               printf("%s\n", terms->term_bad);
+       else
+               return error(_("invalid argument %s for 'git bisect terms'.\n"
+                              "Supported options are: "
+                              "--term-good|--term-old and "
+                              "--term-bad|--term-new."), option);
+
+       return 0;
+}
+
+static int bisect_append_log_quoted(const char **argv)
+{
+       int retval = 0;
+       FILE *fp = fopen(git_path_bisect_log(), "a");
+       struct strbuf orig_args = STRBUF_INIT;
+
+       if (!fp)
+               return -1;
+
+       if (fprintf(fp, "git bisect start") < 1) {
+               retval = -1;
+               goto finish;
+       }
+
+       sq_quote_argv(&orig_args, argv);
+       if (fprintf(fp, "%s\n", orig_args.buf) < 1)
+               retval = -1;
+
+finish:
+       fclose(fp);
+       strbuf_release(&orig_args);
+       return retval;
+}
+
+static int bisect_start(struct bisect_terms *terms, int no_checkout,
+                       const char **argv, int argc)
+{
+       int i, has_double_dash = 0, must_write_terms = 0, bad_seen = 0;
+       int flags, pathspec_pos, retval = 0;
+       struct string_list revs = STRING_LIST_INIT_DUP;
+       struct string_list states = STRING_LIST_INIT_DUP;
+       struct strbuf start_head = STRBUF_INIT;
+       struct strbuf bisect_names = STRBUF_INIT;
+       struct object_id head_oid;
+       struct object_id oid;
+       const char *head;
+
+       if (is_bare_repository())
+               no_checkout = 1;
+
+       /*
+        * Check for one bad and then some good revisions
+        */
+       for (i = 0; i < argc; i++) {
+               if (!strcmp(argv[i], "--")) {
+                       has_double_dash = 1;
+                       break;
+               }
+       }
+
+       for (i = 0; i < argc; i++) {
+               const char *arg = argv[i];
+               if (!strcmp(argv[i], "--")) {
+                       break;
+               } else if (!strcmp(arg, "--no-checkout")) {
+                       no_checkout = 1;
+               } else if (!strcmp(arg, "--term-good") ||
+                        !strcmp(arg, "--term-old")) {
+                       must_write_terms = 1;
+                       free((void *) terms->term_good);
+                       terms->term_good = xstrdup(argv[++i]);
+               } else if (skip_prefix(arg, "--term-good=", &arg) ||
+                          skip_prefix(arg, "--term-old=", &arg)) {
+                       must_write_terms = 1;
+                       free((void *) terms->term_good);
+                       terms->term_good = xstrdup(arg);
+               } else if (!strcmp(arg, "--term-bad") ||
+                        !strcmp(arg, "--term-new")) {
+                       must_write_terms = 1;
+                       free((void *) terms->term_bad);
+                       terms->term_bad = xstrdup(argv[++i]);
+               } else if (skip_prefix(arg, "--term-bad=", &arg) ||
+                          skip_prefix(arg, "--term-new=", &arg)) {
+                       must_write_terms = 1;
+                       free((void *) terms->term_bad);
+                       terms->term_bad = xstrdup(arg);
+               } else if (starts_with(arg, "--") &&
+                        !one_of(arg, "--term-good", "--term-bad", NULL)) {
+                       return error(_("unrecognized option: '%s'"), arg);
+               } else {
+                       char *commit_id = xstrfmt("%s^{commit}", arg);
+                       if (get_oid(commit_id, &oid) && has_double_dash)
+                               die(_("'%s' does not appear to be a valid "
+                                     "revision"), arg);
+
+                       string_list_append(&revs, oid_to_hex(&oid));
+                       free(commit_id);
+               }
+       }
+       pathspec_pos = i;
+
+       /*
+        * The user ran "git bisect start <sha1> <sha1>", hence did not
+        * explicitly specify the terms, but we are already starting to
+        * set references named with the default terms, and won't be able
+        * to change afterwards.
+        */
+       if (revs.nr)
+               must_write_terms = 1;
+       for (i = 0; i < revs.nr; i++) {
+               if (bad_seen) {
+                       string_list_append(&states, terms->term_good);
+               } else {
+                       bad_seen = 1;
+                       string_list_append(&states, terms->term_bad);
+               }
+       }
+
+       /*
+        * Verify HEAD
+        */
+       head = resolve_ref_unsafe("HEAD", 0, &head_oid, &flags);
+       if (!head)
+               if (get_oid("HEAD", &head_oid))
+                       return error(_("bad HEAD - I need a HEAD"));
+
+       /*
+        * Check if we are bisecting
+        */
+       if (!is_empty_or_missing_file(git_path_bisect_start())) {
+               /* Reset to the rev from where we started */
+               strbuf_read_file(&start_head, git_path_bisect_start(), 0);
+               strbuf_trim(&start_head);
+               if (!no_checkout) {
+                       struct argv_array argv = ARGV_ARRAY_INIT;
+
+                       argv_array_pushl(&argv, "checkout", start_head.buf,
+                                        "--", NULL);
+                       if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) {
+                               retval = error(_("checking out '%s' failed."
+                                                " Try 'git bisect start "
+                                                "<valid-branch>'."),
+                                              start_head.buf);
+                               goto finish;
+                       }
+               }
+       } else {
+               /* Get the rev from where we start. */
+               if (!get_oid(head, &head_oid) &&
+                   !starts_with(head, "refs/heads/")) {
+                       strbuf_reset(&start_head);
+                       strbuf_addstr(&start_head, oid_to_hex(&head_oid));
+               } else if (!get_oid(head, &head_oid) &&
+                          skip_prefix(head, "refs/heads/", &head)) {
+                       /*
+                        * This error message should only be triggered by
+                        * cogito usage, and cogito users should understand
+                        * it relates to cg-seek.
+                        */
+                       if (!is_empty_or_missing_file(git_path_head_name()))
+                               return error(_("won't bisect on cg-seek'ed tree"));
+                       strbuf_addstr(&start_head, head);
+               } else {
+                       return error(_("bad HEAD - strange symbolic ref"));
+               }
+       }
+
+       /*
+        * Get rid of any old bisect state.
+        */
+       if (bisect_clean_state())
+               return -1;
+
+       /*
+        * In case of mistaken revs or checkout error, or signals received,
+        * "bisect_auto_next" below may exit or misbehave.
+        * We have to trap this to be able to clean up using
+        * "bisect_clean_state".
+        */
+
+       /*
+        * Write new start state
+        */
+       write_file(git_path_bisect_start(), "%s\n", start_head.buf);
+
+       if (no_checkout) {
+               get_oid(start_head.buf, &oid);
+               if (update_ref(NULL, "BISECT_HEAD", &oid, NULL, 0,
+                              UPDATE_REFS_MSG_ON_ERR)) {
+                       retval = -1;
+                       goto finish;
+               }
+       }
+
+       if (pathspec_pos < argc - 1)
+               sq_quote_argv(&bisect_names, argv + pathspec_pos);
+       write_file(git_path_bisect_names(), "%s\n", bisect_names.buf);
+
+       for (i = 0; i < states.nr; i++)
+               if (bisect_write(states.items[i].string,
+                                revs.items[i].string, terms, 1)) {
+                       retval = -1;
+                       goto finish;
+               }
+
+       if (must_write_terms && write_terms(terms->term_bad,
+                                           terms->term_good)) {
+               retval = -1;
+               goto finish;
+       }
+
+       retval = bisect_append_log_quoted(argv);
+       if (retval)
+               retval = -1;
+
+finish:
+       string_list_clear(&revs, 0);
+       string_list_clear(&states, 0);
+       strbuf_release(&start_head);
+       strbuf_release(&bisect_names);
+       return retval;
+}
+
 int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
 {
        enum {
                NEXT_ALL = 1,
                WRITE_TERMS,
                BISECT_CLEAN_STATE,
-               CHECK_EXPECTED_REVS
+               CHECK_EXPECTED_REVS,
+               BISECT_RESET,
+               BISECT_WRITE,
+               CHECK_AND_SET_TERMS,
+               BISECT_NEXT_CHECK,
+               BISECT_TERMS,
+               BISECT_START
        } cmdmode = 0;
-       int no_checkout = 0;
+       int no_checkout = 0, res = 0, nolog = 0;
        struct option options[] = {
                OPT_CMDMODE(0, "next-all", &cmdmode,
                         N_("perform 'git bisect next'"), NEXT_ALL),
@@ -124,13 +631,29 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
                         N_("cleanup the bisection state"), BISECT_CLEAN_STATE),
                OPT_CMDMODE(0, "check-expected-revs", &cmdmode,
                         N_("check for expected revs"), CHECK_EXPECTED_REVS),
+               OPT_CMDMODE(0, "bisect-reset", &cmdmode,
+                        N_("reset the bisection state"), BISECT_RESET),
+               OPT_CMDMODE(0, "bisect-write", &cmdmode,
+                        N_("write out the bisection state in BISECT_LOG"), BISECT_WRITE),
+               OPT_CMDMODE(0, "check-and-set-terms", &cmdmode,
+                        N_("check and set terms in a bisection state"), CHECK_AND_SET_TERMS),
+               OPT_CMDMODE(0, "bisect-next-check", &cmdmode,
+                        N_("check whether bad or good terms exist"), BISECT_NEXT_CHECK),
+               OPT_CMDMODE(0, "bisect-terms", &cmdmode,
+                        N_("print out the bisect terms"), BISECT_TERMS),
+               OPT_CMDMODE(0, "bisect-start", &cmdmode,
+                        N_("start the bisect session"), BISECT_START),
                OPT_BOOL(0, "no-checkout", &no_checkout,
                         N_("update BISECT_HEAD instead of checking out the current commit")),
+               OPT_BOOL(0, "no-log", &nolog,
+                        N_("no log for BISECT_WRITE ")),
                OPT_END()
        };
+       struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL };
 
        argc = parse_options(argc, argv, prefix, options,
-                            git_bisect_helper_usage, 0);
+                            git_bisect_helper_usage,
+                            PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN);
 
        if (!cmdmode)
                usage_with_options(git_bisect_helper_usage, options);
@@ -149,8 +672,40 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
        case CHECK_EXPECTED_REVS:
                check_expected_revs(argv, argc);
                return 0;
+       case BISECT_RESET:
+               if (argc > 1)
+                       return error(_("--bisect-reset requires either no argument or a commit"));
+               return !!bisect_reset(argc ? argv[0] : NULL);
+       case BISECT_WRITE:
+               if (argc != 4 && argc != 5)
+                       return error(_("--bisect-write requires either 4 or 5 arguments"));
+               set_terms(&terms, argv[3], argv[2]);
+               res = bisect_write(argv[0], argv[1], &terms, nolog);
+               break;
+       case CHECK_AND_SET_TERMS:
+               if (argc != 3)
+                       return error(_("--check-and-set-terms requires 3 arguments"));
+               set_terms(&terms, argv[2], argv[1]);
+               res = check_and_set_terms(&terms, argv[0]);
+               break;
+       case BISECT_NEXT_CHECK:
+               if (argc != 2 && argc != 3)
+                       return error(_("--bisect-next-check requires 2 or 3 arguments"));
+               set_terms(&terms, argv[1], argv[0]);
+               res = bisect_next_check(&terms, argc == 3 ? argv[2] : NULL);
+               break;
+       case BISECT_TERMS:
+               if (argc > 1)
+                       return error(_("--bisect-terms requires 0 or 1 argument"));
+               res = bisect_terms(&terms, argc == 1 ? argv[0] : NULL);
+               break;
+       case BISECT_START:
+               set_terms(&terms, "bad", "good");
+               res = bisect_start(&terms, no_checkout, argv, argc);
+               break;
        default:
                return error("BUG: unknown subcommand '%d'", cmdmode);
        }
-       return 0;
+       free_terms(&terms);
+       return !!res;
 }
index 6d798f99392e54b4392713846652111d457787bb..581de0d8322681ef11026b3e36a81c7baf0fda38 100644 (file)
@@ -925,6 +925,10 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                 */
                blame_date_width = utf8_strwidth(_("4 years, 11 months ago")) + 1; /* add the null */
                break;
+       case DATE_HUMAN:
+               /* If the year is shown, no time is shown */
+               blame_date_width = sizeof("Thu Oct 19 16:00");
+               break;
        case DATE_NORMAL:
                blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
                break;
@@ -1007,7 +1011,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                long bottom, top;
                if (parse_range_arg(range_list.items[range_i].string,
                                    nth_line_cb, &sb, lno, anchor,
-                                   &bottom, &top, sb.path, &the_index))
+                                   &bottom, &top, sb.path,
+                                   the_repository->index))
                        usage(blame_usage);
                if ((!lno && (top || bottom)) || lno < bottom)
                        die(Q_("file %s has only %lu line",
index 9e9c65d9c698cae2ab735463edf378d5dd3a9815..1ea4bfdfc19868d9cb89bb7014c138f145f7dd67 100644 (file)
@@ -56,8 +56,7 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
                }
                if (!startup_info->have_repository)
                        die(_("Need a repository to create a bundle."));
-               return !!create_bundle(the_repository, &header,
-                                      bundle_file, argc, argv);
+               return !!create_bundle(the_repository, bundle_file, argc, argv);
        } else if (!strcmp(cmd, "unbundle")) {
                if (!startup_info->have_repository)
                        die(_("Need a repository to unbundle."));
index 2ca56fd086bf6bef7595ad008d9eda2c64901cf5..8487cd7dba0681087a5700039c234084f071333c 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
@@ -73,7 +74,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
        if (unknown_type)
                flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
 
-       if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
+       if (get_oid_with_context(the_repository, obj_name,
+                                GET_OID_RECORD_PATH,
                                 &oid, &obj_context))
                die("Not a valid object name %s", obj_name);
 
@@ -380,14 +382,18 @@ static void batch_one_object(const char *obj_name,
 {
        struct object_context ctx;
        int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
-       enum follow_symlinks_result result;
+       enum get_oid_result result;
 
-       result = get_oid_with_context(obj_name, flags, &data->oid, &ctx);
+       result = get_oid_with_context(the_repository, obj_name,
+                                     flags, &data->oid, &ctx);
        if (result != FOUND) {
                switch (result) {
                case MISSING_OBJECT:
                        printf("%s missing\n", obj_name);
                        break;
+               case SHORT_NAME_AMBIGUOUS:
+                       printf("%s ambiguous\n", obj_name);
+                       break;
                case DANGLING_SYMLINK:
                        printf("dangling %"PRIuMAX"\n%s\n",
                               (uintmax_t)strlen(obj_name), obj_name);
index 30a2f84274d32977769f778d5704accb599cf0e7..dd833977864d79a3abde9fc66042d7bda56b8e82 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
index ec9a959e08d0e3dfa0d2b08529cacbe8d2e04c6e..599097304b77fa5a3f464b8831e71d6a3f56077a 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
index a2a726ad8d8fa65d2fbcd1b111d71bad61c5cee8..1ac1cc290ed7db86d3ae42b7df2246dad1c507e3 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) 2005 Linus Torvalds
  *
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "config.h"
 #include "lockfile.h"
index 6fadf412e830ba4aeaa8d2940fd9a7aab9bd8fa5..ece4eb14bf1e92742b9fc0723a150e595883d8c6 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "config.h"
 #include "checkout.h"
@@ -288,7 +289,7 @@ static int checkout_paths(const struct checkout_opts *opts,
                return run_add_interactive(revision, "--patch=checkout",
                                           &opts->pathspec);
 
-       hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
+       repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
        if (read_cache_preload(&opts->pathspec) < 0)
                return error(_("index file corrupt"));
 
@@ -592,6 +593,14 @@ static int skip_merge_working_tree(const struct checkout_opts *opts,
         * Remaining variables are not checkout options but used to track state
         */
 
+        /*
+         * Do the merge if this is the initial checkout. We cannot use
+         * is_cache_unborn() here because the index hasn't been loaded yet
+         * so cache_nr and timestamp.sec are always zero.
+         */
+       if (!file_exists(get_index_file()))
+               return 0;
+
        return 1;
 }
 
@@ -693,7 +702,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
                         * a pain; plumb in an option to set
                         * o.renormalize?
                         */
-                       init_merge_options(&o);
+                       init_merge_options(&o, the_repository);
                        o.verbosity = 0;
                        work = write_tree_from_memory(&o);
 
index bbcdeb2d9e7f275309609a2a21a5dd4baf1cf1bd..aaba4af3c26de2150ad655a0b162fc85a69a466d 100644 (file)
@@ -6,6 +6,7 @@
  * Based on git-clean.sh by Pavel Roskin
  */
 
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
index 7c7f98c72c80cfcb12f3d3f61a13f46b19967a8f..50bde9961809b1d55c74fb6d3cbfbf5a86ddf5c7 100644 (file)
@@ -8,6 +8,7 @@
  * Clone a repository into a different directory that does not yet exist.
  */
 
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "config.h"
 #include "lockfile.h"
@@ -1136,9 +1137,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                                     option_upload_pack);
 
        if (filter_options.choice) {
+               struct strbuf expanded_filter_spec = STRBUF_INIT;
+               expand_list_objects_filter_spec(&filter_options,
+                                               &expanded_filter_spec);
                transport_set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER,
-                                    filter_options.filter_spec);
+                                    expanded_filter_spec.buf);
                transport_set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
+               strbuf_release(&expanded_filter_spec);
        }
 
        if (transport->smart_options && !deepen && !filter_options.choice)
index c02a3f1221d625ad6407317199cc35c7a56a09ba..4ae502754c292d0e743ed8fbfdf9d5dda00d1dba 100644 (file)
@@ -110,8 +110,8 @@ static int graph_read(int argc, const char **argv)
                printf(" oid_lookup");
        if (graph->chunk_commit_data)
                printf(" commit_metadata");
-       if (graph->chunk_large_edges)
-               printf(" large_edges");
+       if (graph->chunk_extra_edges)
+               printf(" extra_edges");
        printf("\n");
 
        UNLEAK(graph);
index 004b816635bf1628bfe7697f737a22cbcd27622b..2986553d5ffb97f0798e4d4eb921073439fb9a92 100644 (file)
@@ -5,6 +5,7 @@
  * Based on git-commit.sh by Junio C Hamano and Linus Torvalds
  */
 
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "lockfile.h"
@@ -351,7 +352,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
                if (write_locked_index(&the_index, &index_lock, 0))
                        die(_("unable to create temporary index"));
 
-               old_index_env = getenv(INDEX_ENVIRONMENT);
+               old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
                setenv(INDEX_ENVIRONMENT, get_lock_file_path(&index_lock), 1);
 
                if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
@@ -361,6 +362,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
                        setenv(INDEX_ENVIRONMENT, old_index_env, 1);
                else
                        unsetenv(INDEX_ENVIRONMENT);
+               FREE_AND_NULL(old_index_env);
 
                discard_cache();
                read_cache_from(get_lock_file_path(&index_lock));
@@ -1367,7 +1369,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
        if (status_format != STATUS_FORMAT_PORCELAIN &&
            status_format != STATUS_FORMAT_PORCELAIN_V2)
                progress_flag = REFRESH_PROGRESS;
-       read_index(&the_index);
+       repo_read_index(the_repository);
        refresh_index(&the_index,
                      REFRESH_QUIET|REFRESH_UNMERGED|progress_flag,
                      &s.pathspec, NULL, NULL);
@@ -1396,7 +1398,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
        wt_status_collect(&s);
 
        if (0 <= fd)
-               update_index_if_able(&the_index, &index_lock);
+               repo_update_index_if_able(the_repository, &index_lock);
 
        if (s.relative_paths)
                s.prefix = prefix;
@@ -1674,7 +1676,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
        run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
        if (amend && !no_post_rewrite) {
-               commit_post_rewrite(current_head, &oid);
+               commit_post_rewrite(the_repository, current_head, &oid);
        }
        if (!quiet) {
                unsigned int flags = 0;
index 99bc7ef64ec6f7f0ab0e6dc1d0dc3fd149969a16..98d65bc0ad4fd4bee8bd2755b9d7444d9862eae8 100644 (file)
@@ -599,7 +599,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
        int nongit = !startup_info->have_repository;
        char *value;
 
-       given_config_source.file = getenv(CONFIG_ENVIRONMENT);
+       given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT));
 
        argc = parse_options(argc, argv, prefix, builtin_config_options,
                             builtin_config_usage,
index cc118448ee00d2c4336422afbad1799babfb5783..02ec56417a197b7e252625561fa462a215499a4d 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "lockfile.h"
@@ -634,7 +635,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                                      NULL, NULL, NULL);
                        fd = hold_locked_index(&index_lock, 0);
                        if (0 <= fd)
-                               update_index_if_able(&the_index, &index_lock);
+                               repo_update_index_if_able(the_repository, &index_lock);
 
                        repo_init_revisions(the_repository, &revs, prefix);
                        argv_array_pushv(&args, diff_index_args);
index 48cfcb935d0413fcf3850e0c28ec237b642b38a2..86ae474fbfb410f026d42ce9f36e9805a98cfc82 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "diff.h"
index fcccd1f10dc95cd47a994b5139226af438049f87..93ec6424234c65f486dcfca724c77a48e5e91f91 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "diff.h"
index ef996126d7b521ea1de2c837e4ed97fdcb6f1e71..a90681bcbafcba04af3b669f0758c78ccecdd11f 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "diff.h"
@@ -165,7 +166,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
 
                if (opt->diffopt.detect_rename) {
                        if (!the_index.cache)
-                               read_index(&the_index);
+                               repo_read_index(the_repository);
                        opt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;
                }
                while (fgets(line, sizeof(line), stdin)) {
index f0393bba23a7d95c67470508a6b63e4e41e8d46b..74351a5757d399ddf251369a5be67bedbe2dfad7 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "lockfile.h"
@@ -212,7 +213,7 @@ static void refresh_index_quietly(void)
        discard_cache();
        read_cache();
        refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);
-       update_index_if_able(&the_index, &lock_file);
+       repo_update_index_if_able(the_repository, &lock_file);
 }
 
 static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv)
index 71318c26e177e8aa4176201e4f23e6f43b63b630..a3ea60ea71428ee59ab20a67f6e9ccf76c841f85 100644 (file)
@@ -11,6 +11,7 @@
  *
  * Copyright (C) 2016 Johannes Schindelin
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
index 63e69a58011a4d3c774cd3c81ae9f10e3a96efe6..153a2bd282cac47ba72c101eaf0ca1b867d3f2cd 100644 (file)
@@ -55,6 +55,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
        struct oid_array shallow = OID_ARRAY_INIT;
        struct string_list deepen_not = STRING_LIST_INIT_DUP;
        struct packet_reader reader;
+       enum protocol_version version;
 
        fetch_if_missing = 0;
 
@@ -217,11 +218,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
 
        packet_reader_init(&reader, fd[0], NULL, 0,
                           PACKET_READ_CHOMP_NEWLINE |
-                          PACKET_READ_GENTLE_ON_EOF);
+                          PACKET_READ_GENTLE_ON_EOF |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
 
-       switch (discover_version(&reader)) {
+       version = discover_version(&reader);
+       switch (version) {
        case protocol_v2:
-               die("support for protocol v2 not implemented yet");
+               get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL);
+               break;
        case protocol_v1:
        case protocol_v0:
                get_remote_heads(&reader, &ref, 0, NULL, &shallow);
@@ -231,7 +235,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
        }
 
        ref = fetch_pack(&args, fd, conn, ref, dest, sought, nr_sought,
-                        &shallow, pack_lockfile_ptr, protocol_v0);
+                        &shallow, pack_lockfile_ptr, version);
        if (pack_lockfile) {
                printf("lock %s\n", pack_lockfile);
                fflush(stdout);
index e0140327aab23654c69e7388c23a07b98b8ff913..39c42106109f35f49550133580bf34b6eb60aa26 100644 (file)
@@ -629,9 +629,14 @@ static int find_and_replace(struct strbuf *haystack,
                            const char *needle,
                            const char *placeholder)
 {
-       const char *p = strstr(haystack->buf, needle);
+       const char *p = NULL;
        int plen, nlen;
 
+       nlen = strlen(needle);
+       if (ends_with(haystack->buf, needle))
+               p = haystack->buf + haystack->len - nlen;
+       else
+               p = strstr(haystack->buf, needle);
        if (!p)
                return 0;
 
@@ -639,7 +644,6 @@ static int find_and_replace(struct strbuf *haystack,
                return 0;
 
        plen = strlen(p);
-       nlen = strlen(needle);
        if (plen > nlen && p[nlen] != '/')
                return 0;
 
@@ -763,9 +767,6 @@ static int update_local_ref(struct ref *ref,
                        what = _("[new ref]");
                }
 
-               if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
-                   (recurse_submodules != RECURSE_SUBMODULES_ON))
-                       check_for_new_submodule_commits(&ref->new_oid);
                r = s_update_ref(msg, ref, 0);
                format_display(display, r ? '!' : '*', what,
                               r ? _("unable to update local ref") : NULL,
@@ -779,9 +780,6 @@ static int update_local_ref(struct ref *ref,
                strbuf_add_unique_abbrev(&quickref, &current->object.oid, DEFAULT_ABBREV);
                strbuf_addstr(&quickref, "..");
                strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV);
-               if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
-                   (recurse_submodules != RECURSE_SUBMODULES_ON))
-                       check_for_new_submodule_commits(&ref->new_oid);
                r = s_update_ref("fast-forward", ref, 1);
                format_display(display, r ? '!' : ' ', quickref.buf,
                               r ? _("unable to update local ref") : NULL,
@@ -794,9 +792,6 @@ static int update_local_ref(struct ref *ref,
                strbuf_add_unique_abbrev(&quickref, &current->object.oid, DEFAULT_ABBREV);
                strbuf_addstr(&quickref, "...");
                strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV);
-               if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
-                   (recurse_submodules != RECURSE_SUBMODULES_ON))
-                       check_for_new_submodule_commits(&ref->new_oid);
                r = s_update_ref("forced-update", ref, 1);
                format_display(display, r ? '!' : '+', quickref.buf,
                               r ? _("unable to update local ref") : _("forced update"),
@@ -892,6 +887,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
                                ref->force = rm->peer_ref->force;
                        }
 
+                       if (recurse_submodules != RECURSE_SUBMODULES_OFF)
+                               check_for_new_submodule_commits(&rm->old_oid);
 
                        if (!strcmp(rm->name, "HEAD")) {
                                kind = "";
@@ -1172,6 +1169,7 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
 static struct transport *prepare_transport(struct remote *remote, int deepen)
 {
        struct transport *transport;
+
        transport = transport_get(remote, NULL);
        transport_set_verbosity(transport, verbosity, progress);
        transport->family = family;
@@ -1191,9 +1189,13 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
        if (update_shallow)
                set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes");
        if (filter_options.choice) {
+               struct strbuf expanded_filter_spec = STRBUF_INIT;
+               expand_list_objects_filter_spec(&filter_options,
+                                               &expanded_filter_spec);
                set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER,
-                          filter_options.filter_spec);
+                          expanded_filter_spec.buf);
                set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
+               strbuf_release(&expanded_filter_spec);
        }
        if (negotiation_tip.nr) {
                if (transport->smart_options)
@@ -1478,7 +1480,8 @@ static inline void fetch_one_setup_partial(struct remote *remote)
         */
        if (strcmp(remote->name, repository_format_partial_clone)) {
                if (filter_options.choice)
-                       die(_("--filter can only be used with the remote configured in core.partialClone"));
+                       die(_("--filter can only be used with the remote "
+                             "configured in extensions.partialclone"));
                return;
        }
 
@@ -1646,7 +1649,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
                result = fetch_one(remote, argc, argv, prune_tags_ok);
        } else {
                if (filter_options.choice)
-                       die(_("--filter can only be used with the remote configured in core.partialClone"));
+                       die(_("--filter can only be used with the remote "
+                             "configured in extensions.partialclone"));
                /* TODO should this also die if we have a previous partial-clone? */
                result = fetch_multiple(&list);
        }
index bf5ddff43f74e0dba77d05e04bc14c0c59884287..bb4227bebc606dfac8337d7aa3e78705113a79b5 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "cache.h"
 #include "repository.h"
@@ -401,7 +402,8 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
        if (obj->type == OBJ_TREE)
                free_tree_buffer((struct tree *)obj);
        if (obj->type == OBJ_COMMIT)
-               free_commit_buffer((struct commit *)obj);
+               free_commit_buffer(the_repository->parsed_objects,
+                                  (struct commit *)obj);
        return err;
 }
 
index 4748195ae173786924f75dab9e865ce05b434930..580fd38f41704b6d534c04f2dee1bf85eee67c3c 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "repository.h"
 #include "config.h"
@@ -393,18 +394,22 @@ static void run_pager(struct grep_opt *opt, const char *prefix)
                exit(status);
 }
 
-static int grep_cache(struct grep_opt *opt, struct repository *repo,
+static int grep_cache(struct grep_opt *opt,
                      const struct pathspec *pathspec, int cached);
 static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
                     struct tree_desc *tree, struct strbuf *base, int tn_len,
-                    int check_attr, struct repository *repo);
+                    int check_attr);
 
-static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
+static int grep_submodule(struct grep_opt *opt,
                          const struct pathspec *pathspec,
                          const struct object_id *oid,
                          const char *filename, const char *path)
 {
-       struct repository submodule;
+       struct repository subrepo;
+       struct repository *superproject = opt->repo;
+       const struct submodule *sub = submodule_from_path(superproject,
+                                                         &null_oid, path);
+       struct grep_opt subopt;
        int hit;
 
        /*
@@ -420,12 +425,12 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
                return 0;
        }
 
-       if (repo_submodule_init(&submodule, superproject, path)) {
+       if (repo_submodule_init(&subrepo, superproject, sub)) {
                grep_read_unlock();
                return 0;
        }
 
-       repo_read_gitmodules(&submodule);
+       repo_read_gitmodules(&subrepo);
 
        /*
         * NEEDSWORK: This adds the submodule's object directory to the list of
@@ -437,9 +442,12 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
         * store is no longer global and instead is a member of the repository
         * object.
         */
-       add_to_alternates_memory(submodule.objects->odb->path);
+       add_to_alternates_memory(subrepo.objects->odb->path);
        grep_read_unlock();
 
+       memcpy(&subopt, opt, sizeof(subopt));
+       subopt.repo = &subrepo;
+
        if (oid) {
                struct object *object;
                struct tree_desc tree;
@@ -461,21 +469,22 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
                strbuf_addch(&base, '/');
 
                init_tree_desc(&tree, data, size);
-               hit = grep_tree(opt, pathspec, &tree, &base, base.len,
-                               object->type == OBJ_COMMIT, &submodule);
+               hit = grep_tree(&subopt, pathspec, &tree, &base, base.len,
+                               object->type == OBJ_COMMIT);
                strbuf_release(&base);
                free(data);
        } else {
-               hit = grep_cache(opt, &submodule, pathspec, 1);
+               hit = grep_cache(&subopt, pathspec, 1);
        }
 
-       repo_clear(&submodule);
+       repo_clear(&subrepo);
        return hit;
 }
 
-static int grep_cache(struct grep_opt *opt, struct repository *repo,
+static int grep_cache(struct grep_opt *opt,
                      const struct pathspec *pathspec, int cached)
 {
+       struct repository *repo = opt->repo;
        int hit = 0;
        int nr;
        struct strbuf name = STRBUF_INIT;
@@ -513,7 +522,7 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
                        }
                } else if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
                           submodule_path_match(repo->index, pathspec, name.buf, NULL)) {
-                       hit |= grep_submodule(opt, repo, pathspec, NULL, ce->name, ce->name);
+                       hit |= grep_submodule(opt, pathspec, NULL, ce->name, ce->name);
                } else {
                        continue;
                }
@@ -535,8 +544,9 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
 
 static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
                     struct tree_desc *tree, struct strbuf *base, int tn_len,
-                    int check_attr, struct repository *repo)
+                    int check_attr)
 {
+       struct repository *repo = opt->repo;
        int hit = 0;
        enum interesting match = entry_not_interesting;
        struct name_entry entry;
@@ -567,7 +577,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
                strbuf_add(base, entry.path, te_len);
 
                if (S_ISREG(entry.mode)) {
-                       hit |= grep_oid(opt, entry.oid, base->buf, tn_len,
+                       hit |= grep_oid(opt, &entry.oid, base->buf, tn_len,
                                         check_attr ? base->buf + tn_len : NULL);
                } else if (S_ISDIR(entry.mode)) {
                        enum object_type type;
@@ -575,18 +585,18 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
                        void *data;
                        unsigned long size;
 
-                       data = lock_and_read_oid_file(entry.oid, &type, &size);
+                       data = lock_and_read_oid_file(&entry.oid, &type, &size);
                        if (!data)
                                die(_("unable to read tree (%s)"),
-                                   oid_to_hex(entry.oid));
+                                   oid_to_hex(&entry.oid));
 
                        strbuf_addch(base, '/');
                        init_tree_desc(&sub, data, size);
                        hit |= grep_tree(opt, pathspec, &sub, base, tn_len,
-                                        check_attr, repo);
+                                        check_attr);
                        free(data);
                } else if (recurse_submodules && S_ISGITLINK(entry.mode)) {
-                       hit |= grep_submodule(opt, repo, pathspec, entry.oid,
+                       hit |= grep_submodule(opt, pathspec, &entry.oid,
                                              base->buf, base->buf + tn_len);
                }
 
@@ -628,7 +638,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
                }
                init_tree_desc(&tree, data, size);
                hit = grep_tree(opt, pathspec, &tree, &base, base.len,
-                               obj->type == OBJ_COMMIT, the_repository);
+                               obj->type == OBJ_COMMIT);
                strbuf_release(&base);
                free(data);
                return hit;
@@ -645,12 +655,12 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
 
        for (i = 0; i < nr; i++) {
                struct object *real_obj;
-               real_obj = deref_tag(the_repository, list->objects[i].item,
+               real_obj = deref_tag(opt->repo, list->objects[i].item,
                                     NULL, 0);
 
                /* load the gitmodules file for this rev */
                if (recurse_submodules) {
-                       submodule_free(the_repository);
+                       submodule_free(opt->repo);
                        gitmodules_config_oid(&real_obj->oid);
                }
                if (grep_object(opt, pathspec, real_obj, list->objects[i].name,
@@ -675,9 +685,9 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
        if (exc_std)
                setup_standard_excludes(&dir);
 
-       fill_directory(&dir, &the_index, pathspec);
+       fill_directory(&dir, opt->repo->index, pathspec);
        for (i = 0; i < dir.nr; i++) {
-               if (!dir_path_match(&the_index, dir.entries[i], pathspec, 0, NULL))
+               if (!dir_path_match(opt->repo->index, dir.entries[i], pathspec, 0, NULL))
                        continue;
                hit |= grep_file(opt, dir.entries[i]->name);
                if (hit && opt->status_only)
@@ -1015,7 +1025,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                        break;
                }
 
-               if (get_oid_with_context(arg, GET_OID_RECORD_PATH,
+               if (get_oid_with_context(the_repository, arg,
+                                        GET_OID_RECORD_PATH,
                                         &oid, &oc)) {
                        if (seen_dashdash)
                                die(_("unable to resolve revision: %s"), arg);
@@ -1118,7 +1129,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                if (!cached)
                        setup_work_tree();
 
-               hit = grep_cache(&opt, the_repository, &pathspec, cached);
+               hit = grep_cache(&opt, &pathspec, cached);
        } else {
                if (cached)
                        die(_("both --cached and trees are given"));
index d6f06ea32f51272efa5ccb3fdd396b5916e98e45..e055c1110310bc3b6ccef4fa83dae84316fcc75f 100644 (file)
@@ -40,7 +40,8 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
        if (fstat(fd, &st) < 0 ||
            (literally
             ? hash_literally(&oid, fd, type, flags)
-            : index_fd(&the_index, &oid, fd, &st, type_from_string(type), path, flags)))
+            : index_fd(the_repository->index, &oid, fd, &st,
+                       type_from_string(type), path, flags)))
                die((flags & HASH_WRITE_OBJECT)
                    ? "Unable to add %s to database"
                    : "Unable to hash %s", path);
index 41faffd28db8850fb97daa52c6d481375b380504..93eff7618cf1b98e3c69a7f1f159063e9e73dbe3 100644 (file)
@@ -542,8 +542,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
         * GIT_WORK_TREE makes sense only in conjunction with GIT_DIR
         * without --bare.  Catch the error early.
         */
-       git_dir = getenv(GIT_DIR_ENVIRONMENT);
-       work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
+       git_dir = xstrdup_or_null(getenv(GIT_DIR_ENVIRONMENT));
+       work_tree = xstrdup_or_null(getenv(GIT_WORK_TREE_ENVIRONMENT));
        if ((!git_dir || is_bare_repository_cfg == 1) && work_tree)
                die(_("%s (or --work-tree=<directory>) not allowed without "
                          "specifying %s (or --git-dir=<directory>)"),
@@ -582,6 +582,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
        }
 
        UNLEAK(real_git_dir);
+       UNLEAK(git_dir);
+       UNLEAK(work_tree);
 
        flags |= INIT_DB_EXIST_OK;
        return init_db(git_dir, real_git_dir, template_dir, flags);
index 3e145fe5023638bc50c05f9d9dedfd6d11ae536d..57869267d8d75e06a1a34e4dea104102aac21a65 100644 (file)
@@ -4,6 +4,7 @@
  * (C) Copyright 2006 Linus Torvalds
  *              2006 Junio Hamano
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "refs.h"
@@ -203,7 +204,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
            rev->diffopt.filter || rev->diffopt.flags.follow_renames)
                rev->always_show_header = 0;
 
-       if (source) {
+       if (source || w.source) {
                init_revision_sources(&revision_sources);
                rev->sources = &revision_sources;
        }
@@ -397,7 +398,8 @@ static int cmd_log_walk(struct rev_info *rev)
                         * We may show a given commit multiple times when
                         * walking the reflogs.
                         */
-                       free_commit_buffer(commit);
+                       free_commit_buffer(the_repository->parsed_objects,
+                                          commit);
                        free_commit_list(commit->parents);
                        commit->parents = NULL;
                }
@@ -508,7 +510,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
            !rev->diffopt.flags.allow_textconv)
                return stream_blob_to_fd(1, oid, NULL, 0);
 
-       if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
+       if (get_oid_with_context(the_repository, obj_name,
+                                GET_OID_RECORD_PATH,
                                 &oidc, &obj_context))
                die(_("Not a valid object name %s"), obj_name);
        if (!obj_context.path ||
@@ -1940,7 +1943,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                    open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
                        die(_("Failed to create output files"));
                shown = log_tree_commit(&rev, commit);
-               free_commit_buffer(commit);
+               free_commit_buffer(the_repository->parsed_objects,
+                                  commit);
 
                /* We put one extra blank line between formatted
                 * patches and this flag is used by log-tree code
index 7e0dcaa3599da68c62d05655e488467b7756409b..29a8762d46eb7aa9a9b456e2564062fdbdb48a06 100644 (file)
@@ -5,7 +5,6 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "repository.h"
 #include "config.h"
@@ -206,17 +205,19 @@ static void show_files(struct repository *repo, struct dir_struct *dir);
 static void show_submodule(struct repository *superproject,
                           struct dir_struct *dir, const char *path)
 {
-       struct repository submodule;
+       struct repository subrepo;
+       const struct submodule *sub = submodule_from_path(superproject,
+                                                         &null_oid, path);
 
-       if (repo_submodule_init(&submodule, superproject, path))
+       if (repo_submodule_init(&subrepo, superproject, sub))
                return;
 
-       if (repo_read_index(&submodule) < 0)
+       if (repo_read_index(&subrepo) < 0)
                die("index file corrupt");
 
-       show_files(&submodule, dir);
+       show_files(&subrepo, dir);
 
-       repo_clear(&submodule);
+       repo_clear(&subrepo);
 }
 
 static void show_ce(struct repository *repo, struct dir_struct *dir,
index c99443b095bd8abbe02d4ea87a452d916681c53f..38ea6ad6ca25d5a969afdbfc5b3510ba44e49a33 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "run-command.h"
 
index 0b07263415785e11c7fc5b1a6da40a25e969b73c..4594507420533262a7b6611386a340cfdb96b25f 100644 (file)
@@ -7,6 +7,7 @@
  *
  * Pretend we resolved the heads, but declare our tree trumps everybody else.
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "git-compat-util.h"
 #include "builtin.h"
 #include "diff.h"
index 9b2f707c291cf903b9151c2f3673b6fe0e0ca6d5..5b910e351e4dede4527d23a04a8294e17ebd371c 100644 (file)
@@ -7,16 +7,16 @@
 static const char builtin_merge_recursive_usage[] =
        "git %s <base>... -- <head> <remote> ...";
 
-static const char *better_branch_name(const char *branch)
+static char *better_branch_name(const char *branch)
 {
        static char githead_env[8 + GIT_MAX_HEXSZ + 1];
        char *name;
 
        if (strlen(branch) != the_hash_algo->hexsz)
-               return branch;
+               return xstrdup(branch);
        xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
        name = getenv(githead_env);
-       return name ? name : branch;
+       return xstrdup(name ? name : branch);
 }
 
 int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
@@ -26,9 +26,10 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
        int i, failed;
        struct object_id h1, h2;
        struct merge_options o;
+       char *better1, *better2;
        struct commit *result;
 
-       init_merge_options(&o);
+       init_merge_options(&o, the_repository);
        if (argv[0] && ends_with(argv[0], "-subtree"))
                o.subtree_shift = "";
 
@@ -70,13 +71,17 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
        if (get_oid(o.branch2, &h2))
                die(_("could not resolve ref '%s'"), o.branch2);
 
-       o.branch1 = better_branch_name(o.branch1);
-       o.branch2 = better_branch_name(o.branch2);
+       o.branch1 = better1 = better_branch_name(o.branch1);
+       o.branch2 = better2 = better_branch_name(o.branch2);
 
        if (o.verbosity >= 3)
                printf(_("Merging %s with %s\n"), o.branch1, o.branch2);
 
        failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);
+
+       free(better1);
+       free(better2);
+
        if (failed < 0)
                return 128; /* die() error code */
        return failed;
index 4984b7e12e90aab356606e6e7d3e6526f31c8c73..34ca0258b12ae4e4a04c495c244fb9c18268e7d8 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "tree-walk.h"
 #include "xdiff-interface.h"
@@ -76,7 +77,8 @@ static void *result(struct merge_list *entry, unsigned long *size)
        their = NULL;
        if (entry)
                their = entry->blob;
-       return merge_blobs(&the_index, path, base, our, their, size);
+       return merge_blobs(the_repository->index, path,
+                          base, our, their, size);
 }
 
 static void *origin(struct merge_list *entry, unsigned long *size)
@@ -154,15 +156,15 @@ static void show_result(void)
 /* An empty entry never compares same, not even to another empty entry */
 static int same_entry(struct name_entry *a, struct name_entry *b)
 {
-       return  a->oid &&
-               b->oid &&
-               oideq(a->oid, b->oid) &&
+       return  !is_null_oid(&a->oid) &&
+               !is_null_oid(&b->oid) &&
+               oideq(&a->oid, &b->oid) &&
                a->mode == b->mode;
 }
 
 static int both_empty(struct name_entry *a, struct name_entry *b)
 {
-       return !(a->oid || b->oid);
+       return is_null_oid(&a->oid) && is_null_oid(&b->oid);
 }
 
 static struct merge_list *create_entry(unsigned stage, unsigned mode, const struct object_id *oid, const char *path)
@@ -178,7 +180,7 @@ static struct merge_list *create_entry(unsigned stage, unsigned mode, const stru
 
 static char *traverse_path(const struct traverse_info *info, const struct name_entry *n)
 {
-       char *path = xmallocz(traverse_path_len(info, n));
+       char *path = xmallocz(traverse_path_len(info, n) + the_hash_algo->rawsz);
        return make_traverse_path(path, info, n);
 }
 
@@ -192,8 +194,8 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s
                return;
 
        path = traverse_path(info, result);
-       orig = create_entry(2, ours->mode, ours->oid, path);
-       final = create_entry(0, result->mode, result->oid, path);
+       orig = create_entry(2, ours->mode, &ours->oid, path);
+       final = create_entry(0, result->mode, &result->oid, path);
 
        final->link = orig;
 
@@ -217,7 +219,7 @@ static void unresolved_directory(const struct traverse_info *info,
 
        newbase = traverse_path(info, p);
 
-#define ENTRY_OID(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid : NULL)
+#define ENTRY_OID(e) (((e)->mode && S_ISDIR((e)->mode)) ? &(e)->oid : NULL)
        buf0 = fill_tree_descriptor(t + 0, ENTRY_OID(n + 0));
        buf1 = fill_tree_descriptor(t + 1, ENTRY_OID(n + 1));
        buf2 = fill_tree_descriptor(t + 2, ENTRY_OID(n + 2));
@@ -243,7 +245,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info
                path = entry->path;
        else
                path = traverse_path(info, n);
-       link = create_entry(stage, n->mode, n->oid, path);
+       link = create_entry(stage, n->mode, &n->oid, path);
        link->link = entry;
        return link;
 }
@@ -318,7 +320,7 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s
        }
 
        if (same_entry(entry+0, entry+1)) {
-               if (entry[2].oid && !S_ISDIR(entry[2].mode)) {
+               if (!is_null_oid(&entry[2].oid) && !S_ISDIR(entry[2].mode)) {
                        /* We did not touch, they modified -- take theirs */
                        resolve(info, entry+1, entry+2);
                        return mask;
index dc0b7cc521c26f4c0ef1c6440d17c0f35ac1c983..e47d77baeebe888cfb67f8e03804ffc3ee3715c0 100644 (file)
@@ -6,6 +6,7 @@
  * Based on git-merge.sh by Junio C Hamano.
  */
 
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "parse-options.h"
@@ -702,7 +703,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
                        return 2;
                }
 
-               init_merge_options(&o);
+               init_merge_options(&o, the_repository);
                if (!strcmp(strategy, "subtree"))
                        o.subtree_shift = "";
 
index 80bb967a63f154eb44ebc1a6dd7f833d01dce83e..be15ba7044e0eeeee216a9e6c4615214cd7cdc1e 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2006 Johannes Schindelin
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "config.h"
 #include "pathspec.h"
index 4996a670f71333de09e1a0311fde85d6985c9c91..02e97f55c5a01be452bb3eaa97ec396f58e2ed99 100644 (file)
@@ -330,10 +330,10 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
        }
 
        if (!rewrite_cmd) {
-               commit_notes(t, msg);
+               commit_notes(the_repository, t, msg);
                free_notes(t);
        } else {
-               finish_copy_notes_for_rewrite(c, msg);
+               finish_copy_notes_for_rewrite(the_repository, c, msg);
        }
        strbuf_release(&buf);
        return ret;
@@ -469,12 +469,14 @@ static int add(int argc, const char **argv, const char *prefix)
                write_note_data(&d, &new_note);
                if (add_note(t, &object, &new_note, combine_notes_overwrite))
                        BUG("combine_notes_overwrite failed");
-               commit_notes(t, "Notes added by 'git notes add'");
+               commit_notes(the_repository, t,
+                            "Notes added by 'git notes add'");
        } else {
                fprintf(stderr, _("Removing note for object %s\n"),
                        oid_to_hex(&object));
                remove_note(t, object.hash);
-               commit_notes(t, "Notes removed by 'git notes add'");
+               commit_notes(the_repository, t,
+                            "Notes removed by 'git notes add'");
        }
 
        free_note_data(&d);
@@ -552,7 +554,8 @@ static int copy(int argc, const char **argv, const char *prefix)
 
        if (add_note(t, &object, from_note, combine_notes_overwrite))
                BUG("combine_notes_overwrite failed");
-       commit_notes(t, "Notes added by 'git notes copy'");
+       commit_notes(the_repository, t,
+                    "Notes added by 'git notes copy'");
 out:
        free_notes(t);
        return retval;
@@ -636,7 +639,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
                remove_note(t, object.hash);
                logmsg = xstrfmt("Notes removed by 'git notes %s'", argv[0]);
        }
-       commit_notes(t, logmsg);
+       commit_notes(the_repository, t, logmsg);
 
        free(logmsg);
        free_note_data(&d);
@@ -937,7 +940,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
                strbuf_release(&sb);
        }
        if (!retval)
-               commit_notes(t, "Notes removed by 'git notes remove'");
+               commit_notes(the_repository, t,
+                            "Notes removed by 'git notes remove'");
        free_notes(t);
        return retval;
 }
@@ -965,7 +969,8 @@ static int prune(int argc, const char **argv, const char *prefix)
        prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
                (show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );
        if (!show_only)
-               commit_notes(t, "Notes removed by 'git notes prune'");
+               commit_notes(the_repository, t,
+                            "Notes removed by 'git notes prune'");
        free_notes(t);
        return 0;
 }
index 889df2c755176b60fc5c22b0ae553ced23629dc2..bd67491c1633602a7fab3c48e86bde4421f92c4e 100644 (file)
@@ -84,6 +84,7 @@ static unsigned long pack_size_limit;
 static int depth = 50;
 static int delta_search_threads;
 static int pack_to_stdout;
+static int sparse;
 static int thin;
 static int num_preferred_base;
 static struct progress *progress_state;
@@ -970,7 +971,7 @@ static int no_try_delta(const char *path)
 
        if (!check)
                check = attr_check_initl("delta", NULL);
-       git_check_attr(&the_index, path, check);
+       git_check_attr(the_repository->index, path, check);
        if (ATTR_FALSE(check->items[0].value))
                return 1;
        return 0;
@@ -1334,7 +1335,7 @@ static void add_pbase_object(struct tree_desc *tree,
                if (cmp < 0)
                        return;
                if (name[cmplen] != '/') {
-                       add_object_entry(entry.oid,
+                       add_object_entry(&entry.oid,
                                         object_type(entry.mode),
                                         fullname, 1);
                        return;
@@ -1345,7 +1346,7 @@ static void add_pbase_object(struct tree_desc *tree,
                        const char *down = name+cmplen+1;
                        int downlen = name_cmp_len(down);
 
-                       tree = pbase_tree_get(entry.oid);
+                       tree = pbase_tree_get(&entry.oid);
                        if (!tree)
                                return;
                        init_tree_desc(&sub, tree->tree_data, tree->tree_size);
@@ -1953,11 +1954,6 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
        return 0;
 }
 
-/* Protect access to object database */
-static pthread_mutex_t read_mutex;
-#define read_lock()            pthread_mutex_lock(&read_mutex)
-#define read_unlock()          pthread_mutex_unlock(&read_mutex)
-
 /* Protect delta_cache_size */
 static pthread_mutex_t cache_mutex;
 #define cache_lock()           pthread_mutex_lock(&cache_mutex)
@@ -1993,11 +1989,11 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
        unsigned long used, avail, size;
 
        if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
-               read_lock();
+               packing_data_lock(&to_pack);
                if (oid_object_info(the_repository, &e->idx.oid, &size) < 0)
                        die(_("unable to get size of %s"),
                            oid_to_hex(&e->idx.oid));
-               read_unlock();
+               packing_data_unlock(&to_pack);
                return size;
        }
 
@@ -2005,7 +2001,7 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
        if (!p)
                BUG("when e->type is a delta, it must belong to a pack");
 
-       read_lock();
+       packing_data_lock(&to_pack);
        w_curs = NULL;
        buf = use_pack(p, &w_curs, e->in_pack_offset, &avail);
        used = unpack_object_header_buffer(buf, avail, &type, &size);
@@ -2014,7 +2010,7 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
                    oid_to_hex(&e->idx.oid));
 
        unuse_pack(&w_curs);
-       read_unlock();
+       packing_data_unlock(&to_pack);
        return size;
 }
 
@@ -2076,9 +2072,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
 
        /* Load data if not already done */
        if (!trg->data) {
-               read_lock();
+               packing_data_lock(&to_pack);
                trg->data = read_object_file(&trg_entry->idx.oid, &type, &sz);
-               read_unlock();
+               packing_data_unlock(&to_pack);
                if (!trg->data)
                        die(_("object %s cannot be read"),
                            oid_to_hex(&trg_entry->idx.oid));
@@ -2089,9 +2085,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
                *mem_usage += sz;
        }
        if (!src->data) {
-               read_lock();
+               packing_data_lock(&to_pack);
                src->data = read_object_file(&src_entry->idx.oid, &type, &sz);
-               read_unlock();
+               packing_data_unlock(&to_pack);
                if (!src->data) {
                        if (src_entry->preferred_base) {
                                static int warned = 0;
@@ -2337,9 +2333,9 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
 
 static void try_to_free_from_threads(size_t size)
 {
-       read_lock();
+       packing_data_lock(&to_pack);
        release_pack_memory(size);
-       read_unlock();
+       packing_data_unlock(&to_pack);
 }
 
 static try_to_free_t old_try_to_free_routine;
@@ -2381,7 +2377,6 @@ static pthread_cond_t progress_cond;
  */
 static void init_threaded_search(void)
 {
-       init_recursive_mutex(&read_mutex);
        pthread_mutex_init(&cache_mutex, NULL);
        pthread_mutex_init(&progress_mutex, NULL);
        pthread_cond_init(&progress_cond, NULL);
@@ -2392,7 +2387,6 @@ static void cleanup_threaded_search(void)
 {
        set_try_to_free_routine(old_try_to_free_routine);
        pthread_cond_destroy(&progress_cond);
-       pthread_mutex_destroy(&read_mutex);
        pthread_mutex_destroy(&cache_mutex);
        pthread_mutex_destroy(&progress_mutex);
 }
@@ -2710,6 +2704,10 @@ static int git_pack_config(const char *k, const char *v, void *cb)
                use_bitmap_index_default = git_config_bool(k, v);
                return 0;
        }
+       if (!strcmp(k, "pack.usesparse")) {
+               sparse = git_config_bool(k, v);
+               return 0;
+       }
        if (!strcmp(k, "pack.threads")) {
                delta_search_threads = git_config_int(k, v);
                if (delta_search_threads < 0)
@@ -3137,7 +3135,7 @@ 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);
+       mark_edges_uninteresting(&revs, show_edge, sparse);
 
        if (!fn_show_object)
                fn_show_object = show_object;
@@ -3294,6 +3292,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                { OPTION_CALLBACK, 0, "unpack-unreachable", NULL, N_("time"),
                  N_("unpack unreachable objects newer than <time>"),
                  PARSE_OPT_OPTARG, option_parse_unpack_unreachable },
+               OPT_BOOL(0, "sparse", &sparse,
+                        N_("use the sparse reachability algorithm")),
                OPT_BOOL(0, "thin", &thin,
                         N_("create thin packs")),
                OPT_BOOL(0, "shallow", &shallow,
@@ -3326,6 +3326,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 
        read_replace_refs = 0;
 
+       sparse = git_env_bool("GIT_TEST_PACK_SPARSE", 0);
        reset_pack_idx_option(&pack_idx_opts);
        git_config(git_pack_config, NULL);
 
index 74808b94554a78e720128a721f21dc0d20dd839e..701d1473dc59e018247f337d37f00fe04f83cb98 100644 (file)
@@ -5,6 +5,7 @@
  *
  * Fetch one or more remote refs and merge it/them into the current HEAD.
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
index ac255ad2c243192a9afd3b4578a2a501eb250aff..9083dcfa28a38f7f804c1fdcaa56fb4260b4e6f0 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "lockfile.h"
index dd2a55ab1d956ef0937cfdb0e4e3fb026ac2ff81..888390f9114321a489f8210659487ef2d2897fae 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
@@ -193,6 +194,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
                OPT_STRING(0, "onto-name", &onto_name, N_("onto-name"), N_("onto name")),
                OPT_STRING(0, "cmd", &cmd, N_("cmd"), N_("the command to run")),
                OPT_RERERE_AUTOUPDATE(&opts.allow_rerere_auto),
+               OPT_BOOL(0, "reschedule-failed-exec", &opts.reschedule_failed_exec,
+                        N_("automatically re-schedule any `exec` that fails")),
                OPT_END()
        };
 
index 00de70365ed41167c18e3233106e89d082370b6a..0b039319e134d0c33df842666eddc820dc6c410c 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (c) 2018 Pratik Karki
  */
 
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "run-command.h"
 #include "exec-cmd.h"
@@ -104,6 +105,7 @@ struct rebase_options {
        int rebase_merges, rebase_cousins;
        char *strategy, *strategy_opts;
        struct strbuf git_format_patch_opt;
+       int reschedule_failed_exec;
 };
 
 static int is_interactive(struct rebase_options *opts)
@@ -122,7 +124,7 @@ static void imply_interactive(struct rebase_options *opts, const char *option)
        case REBASE_PRESERVE_MERGES:
                break;
        case REBASE_MERGE:
-               /* we silently *upgrade* --merge to --interactive if needed */
+               /* we now implement --merge via --interactive */
        default:
                opts->type = REBASE_INTERACTIVE; /* implied */
                break;
@@ -185,10 +187,7 @@ static int read_basic_state(struct rebase_options *opts)
        if (get_oid(buf.buf, &opts->orig_head))
                return error(_("invalid orig-head: '%s'"), buf.buf);
 
-       strbuf_reset(&buf);
-       if (read_one(state_dir_path("quiet", opts), &buf))
-               return -1;
-       if (buf.len)
+       if (file_exists(state_dir_path("quiet", opts)))
                opts->flags &= ~REBASE_NO_QUIET;
        else
                opts->flags |= REBASE_NO_QUIET;
@@ -246,6 +245,37 @@ static int read_basic_state(struct rebase_options *opts)
        return 0;
 }
 
+static int write_basic_state(struct rebase_options *opts)
+{
+       write_file(state_dir_path("head-name", opts), "%s",
+                  opts->head_name ? opts->head_name : "detached HEAD");
+       write_file(state_dir_path("onto", opts), "%s",
+                  opts->onto ? oid_to_hex(&opts->onto->object.oid) : "");
+       write_file(state_dir_path("orig-head", opts), "%s",
+                  oid_to_hex(&opts->orig_head));
+       write_file(state_dir_path("quiet", opts), "%s",
+                  opts->flags & REBASE_NO_QUIET ? "" : "t");
+       if (opts->flags & REBASE_VERBOSE)
+               write_file(state_dir_path("verbose", opts), "%s", "");
+       if (opts->strategy)
+               write_file(state_dir_path("strategy", opts), "%s",
+                          opts->strategy);
+       if (opts->strategy_opts)
+               write_file(state_dir_path("strategy_opts", opts), "%s",
+                          opts->strategy_opts);
+       if (opts->allow_rerere_autoupdate >= 0)
+               write_file(state_dir_path("allow_rerere_autoupdate", opts),
+                          "-%s-rerere-autoupdate",
+                          opts->allow_rerere_autoupdate ? "" : "-no");
+       if (opts->gpg_sign_opt)
+               write_file(state_dir_path("gpg_sign_opt", opts), "%s",
+                          opts->gpg_sign_opt);
+       if (opts->signoff)
+               write_file(state_dir_path("strategy", opts), "--signoff");
+
+       return 0;
+}
+
 static int apply_autostash(struct rebase_options *opts)
 {
        const char *path = state_dir_path("autostash", opts);
@@ -333,6 +363,161 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
        }
 }
 
+#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
+
+#define RESET_HEAD_DETACH (1<<0)
+#define RESET_HEAD_HARD (1<<1)
+#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2)
+#define RESET_HEAD_REFS_ONLY (1<<3)
+
+static int reset_head(struct object_id *oid, const char *action,
+                     const char *switch_to_branch, unsigned flags,
+                     const char *reflog_orig_head, const char *reflog_head)
+{
+       unsigned detach_head = flags & RESET_HEAD_DETACH;
+       unsigned reset_hard = flags & RESET_HEAD_HARD;
+       unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
+       unsigned refs_only = flags & RESET_HEAD_REFS_ONLY;
+       struct object_id head_oid;
+       struct tree_desc desc[2] = { { NULL }, { NULL } };
+       struct lock_file lock = LOCK_INIT;
+       struct unpack_trees_options unpack_tree_opts;
+       struct tree *tree;
+       const char *reflog_action;
+       struct strbuf msg = STRBUF_INIT;
+       size_t prefix_len;
+       struct object_id *orig = NULL, oid_orig,
+               *old_orig = NULL, oid_old_orig;
+       int ret = 0, nr = 0;
+
+       if (switch_to_branch && !starts_with(switch_to_branch, "refs/"))
+               BUG("Not a fully qualified branch: '%s'", switch_to_branch);
+
+       if (!refs_only && hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
+               ret = -1;
+               goto leave_reset_head;
+       }
+
+       if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) {
+               ret = error(_("could not determine HEAD revision"));
+               goto leave_reset_head;
+       }
+
+       if (!oid)
+               oid = &head_oid;
+
+       if (refs_only)
+               goto reset_head_refs;
+
+       memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
+       setup_unpack_trees_porcelain(&unpack_tree_opts, action);
+       unpack_tree_opts.head_idx = 1;
+       unpack_tree_opts.src_index = the_repository->index;
+       unpack_tree_opts.dst_index = the_repository->index;
+       unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge;
+       unpack_tree_opts.update = 1;
+       unpack_tree_opts.merge = 1;
+       if (!detach_head)
+               unpack_tree_opts.reset = 1;
+
+       if (repo_read_index_unmerged(the_repository) < 0) {
+               ret = error(_("could not read index"));
+               goto leave_reset_head;
+       }
+
+       if (!reset_hard && !fill_tree_descriptor(&desc[nr++], &head_oid)) {
+               ret = error(_("failed to find tree of %s"),
+                           oid_to_hex(&head_oid));
+               goto leave_reset_head;
+       }
+
+       if (!fill_tree_descriptor(&desc[nr++], oid)) {
+               ret = error(_("failed to find tree of %s"), oid_to_hex(oid));
+               goto leave_reset_head;
+       }
+
+       if (unpack_trees(nr, desc, &unpack_tree_opts)) {
+               ret = -1;
+               goto leave_reset_head;
+       }
+
+       tree = parse_tree_indirect(oid);
+       prime_cache_tree(the_repository, the_repository->index, tree);
+
+       if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0) {
+               ret = error(_("could not write index"));
+               goto leave_reset_head;
+       }
+
+reset_head_refs:
+       reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
+       strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
+       prefix_len = msg.len;
+
+       if (!get_oid("ORIG_HEAD", &oid_old_orig))
+               old_orig = &oid_old_orig;
+       if (!get_oid("HEAD", &oid_orig)) {
+               orig = &oid_orig;
+               if (!reflog_orig_head) {
+                       strbuf_addstr(&msg, "updating ORIG_HEAD");
+                       reflog_orig_head = msg.buf;
+               }
+               update_ref(reflog_orig_head, "ORIG_HEAD", orig, old_orig, 0,
+                          UPDATE_REFS_MSG_ON_ERR);
+       } else if (old_orig)
+               delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
+       if (!reflog_head) {
+               strbuf_setlen(&msg, prefix_len);
+               strbuf_addstr(&msg, "updating HEAD");
+               reflog_head = msg.buf;
+       }
+       if (!switch_to_branch)
+               ret = update_ref(reflog_head, "HEAD", oid, orig,
+                                detach_head ? REF_NO_DEREF : 0,
+                                UPDATE_REFS_MSG_ON_ERR);
+       else {
+               ret = update_ref(reflog_orig_head, switch_to_branch, oid,
+                                NULL, 0, UPDATE_REFS_MSG_ON_ERR);
+               if (!ret)
+                       ret = create_symref("HEAD", switch_to_branch,
+                                           reflog_head);
+       }
+       if (run_hook)
+               run_hook_le(NULL, "post-checkout",
+                           oid_to_hex(orig ? orig : &null_oid),
+                           oid_to_hex(oid), "1", NULL);
+
+leave_reset_head:
+       strbuf_release(&msg);
+       rollback_lock_file(&lock);
+       while (nr)
+               free((void *)desc[--nr].buffer);
+       return ret;
+}
+
+static int move_to_original_branch(struct rebase_options *opts)
+{
+       struct strbuf orig_head_reflog = STRBUF_INIT, head_reflog = STRBUF_INIT;
+       int ret;
+
+       if (!opts->head_name)
+               return 0; /* nothing to move back to */
+
+       if (!opts->onto)
+               BUG("move_to_original_branch without onto");
+
+       strbuf_addf(&orig_head_reflog, "rebase finished: %s onto %s",
+                   opts->head_name, oid_to_hex(&opts->onto->object.oid));
+       strbuf_addf(&head_reflog, "rebase finished: returning to %s",
+                   opts->head_name);
+       ret = reset_head(NULL, "", opts->head_name, RESET_HEAD_REFS_ONLY,
+                        orig_head_reflog.buf, head_reflog.buf);
+
+       strbuf_release(&orig_head_reflog);
+       strbuf_release(&head_reflog);
+       return ret;
+}
+
 static const char *resolvemsg =
 N_("Resolve all conflicts manually, mark them as resolved with\n"
 "\"git add/rm <conflicted_files>\", then run \"git rebase --continue\".\n"
@@ -340,6 +525,126 @@ N_("Resolve all conflicts manually, mark them as resolved with\n"
 "To abort and get back to the state before \"git rebase\", run "
 "\"git rebase --abort\".");
 
+static int run_am(struct rebase_options *opts)
+{
+       struct child_process am = CHILD_PROCESS_INIT;
+       struct child_process format_patch = CHILD_PROCESS_INIT;
+       struct strbuf revisions = STRBUF_INIT;
+       int status;
+       char *rebased_patches;
+
+       am.git_cmd = 1;
+       argv_array_push(&am.args, "am");
+
+       if (opts->action && !strcmp("continue", opts->action)) {
+               argv_array_push(&am.args, "--resolved");
+               argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
+               if (opts->gpg_sign_opt)
+                       argv_array_push(&am.args, opts->gpg_sign_opt);
+               status = run_command(&am);
+               if (status)
+                       return status;
+
+               return move_to_original_branch(opts);
+       }
+       if (opts->action && !strcmp("skip", opts->action)) {
+               argv_array_push(&am.args, "--skip");
+               argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
+               status = run_command(&am);
+               if (status)
+                       return status;
+
+               return move_to_original_branch(opts);
+       }
+       if (opts->action && !strcmp("show-current-patch", opts->action)) {
+               argv_array_push(&am.args, "--show-current-patch");
+               return run_command(&am);
+       }
+
+       strbuf_addf(&revisions, "%s...%s",
+                   oid_to_hex(opts->root ?
+                              /* this is now equivalent to !opts->upstream */
+                              &opts->onto->object.oid :
+                              &opts->upstream->object.oid),
+                   oid_to_hex(&opts->orig_head));
+
+       rebased_patches = xstrdup(git_path("rebased-patches"));
+       format_patch.out = open(rebased_patches,
+                               O_WRONLY | O_CREAT | O_TRUNC, 0666);
+       if (format_patch.out < 0) {
+               status = error_errno(_("could not open '%s' for writing"),
+                                    rebased_patches);
+               free(rebased_patches);
+               argv_array_clear(&am.args);
+               return status;
+       }
+
+       format_patch.git_cmd = 1;
+       argv_array_pushl(&format_patch.args, "format-patch", "-k", "--stdout",
+                        "--full-index", "--cherry-pick", "--right-only",
+                        "--src-prefix=a/", "--dst-prefix=b/", "--no-renames",
+                        "--no-cover-letter", "--pretty=mboxrd", "--topo-order", NULL);
+       if (opts->git_format_patch_opt.len)
+               argv_array_split(&format_patch.args,
+                                opts->git_format_patch_opt.buf);
+       argv_array_push(&format_patch.args, revisions.buf);
+       if (opts->restrict_revision)
+               argv_array_pushf(&format_patch.args, "^%s",
+                                oid_to_hex(&opts->restrict_revision->object.oid));
+
+       status = run_command(&format_patch);
+       if (status) {
+               unlink(rebased_patches);
+               free(rebased_patches);
+               argv_array_clear(&am.args);
+
+               reset_head(&opts->orig_head, "checkout", opts->head_name, 0,
+                          "HEAD", NULL);
+               error(_("\ngit encountered an error while preparing the "
+                       "patches to replay\n"
+                       "these revisions:\n"
+                       "\n    %s\n\n"
+                       "As a result, git cannot rebase them."),
+                     opts->revisions);
+
+               strbuf_release(&revisions);
+               return status;
+       }
+       strbuf_release(&revisions);
+
+       am.in = open(rebased_patches, O_RDONLY);
+       if (am.in < 0) {
+               status = error_errno(_("could not open '%s' for reading"),
+                                    rebased_patches);
+               free(rebased_patches);
+               argv_array_clear(&am.args);
+               return status;
+       }
+
+       argv_array_pushv(&am.args, opts->git_am_opts.argv);
+       argv_array_push(&am.args, "--rebasing");
+       argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
+       argv_array_push(&am.args, "--patch-format=mboxrd");
+       if (opts->allow_rerere_autoupdate > 0)
+               argv_array_push(&am.args, "--rerere-autoupdate");
+       else if (opts->allow_rerere_autoupdate == 0)
+               argv_array_push(&am.args, "--no-rerere-autoupdate");
+       if (opts->gpg_sign_opt)
+               argv_array_push(&am.args, opts->gpg_sign_opt);
+       status = run_command(&am);
+       unlink(rebased_patches);
+       free(rebased_patches);
+
+       if (!status) {
+               return move_to_original_branch(opts);
+       }
+
+       if (is_directory(opts->state_dir))
+               write_basic_state(opts);
+
+       return status;
+}
+
 static int run_specific_rebase(struct rebase_options *opts)
 {
        const char *argv[] = { NULL, NULL };
@@ -354,7 +659,8 @@ static int run_specific_rebase(struct rebase_options *opts)
                argv_array_pushf(&child.env_array, "GIT_CHERRY_PICK_HELP=%s",
                                 resolvemsg);
                if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
-                       argv_array_push(&child.env_array, "GIT_EDITOR=:");
+                       argv_array_push(&child.env_array,
+                                       "GIT_SEQUENCE_EDITOR=:");
                        opts->autosquash = 0;
                }
 
@@ -415,11 +721,18 @@ static int run_specific_rebase(struct rebase_options *opts)
                        argv_array_push(&child.args, opts->gpg_sign_opt);
                if (opts->signoff)
                        argv_array_push(&child.args, "--signoff");
+               if (opts->reschedule_failed_exec)
+                       argv_array_push(&child.args, "--reschedule-failed-exec");
 
                status = run_command(&child);
                goto finished_rebase;
        }
 
+       if (opts->type == REBASE_AM) {
+               status = run_am(opts);
+               goto finished_rebase;
+       }
+
        add_var(&script_snippet, "GIT_DIR", absolute_path(get_git_dir()));
        add_var(&script_snippet, "state_dir", opts->state_dir);
 
@@ -475,7 +788,7 @@ static int run_specific_rebase(struct rebase_options *opts)
        if (is_interactive(opts) &&
            !(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
                strbuf_addstr(&script_snippet,
-                             "GIT_EDITOR=:; export GIT_EDITOR; ");
+                             "GIT_SEQUENCE_EDITOR=:; export GIT_SEQUENCE_EDITOR; ");
                opts->autosquash = 0;
        }
 
@@ -484,10 +797,6 @@ static int run_specific_rebase(struct rebase_options *opts)
                backend = "git-rebase--am";
                backend_func = "git_rebase__am";
                break;
-       case REBASE_MERGE:
-               backend = "git-rebase--merge";
-               backend_func = "git_rebase__merge";
-               break;
        case REBASE_PRESERVE_MERGES:
                backend = "git-rebase--preserve-merges";
                backend_func = "git_rebase__preserve_merges";
@@ -526,125 +835,6 @@ static int run_specific_rebase(struct rebase_options *opts)
        return status ? -1 : 0;
 }
 
-#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
-
-#define RESET_HEAD_DETACH (1<<0)
-#define RESET_HEAD_HARD (1<<1)
-
-static int reset_head(struct object_id *oid, const char *action,
-                     const char *switch_to_branch, unsigned flags,
-                     const char *reflog_orig_head, const char *reflog_head)
-{
-       unsigned detach_head = flags & RESET_HEAD_DETACH;
-       unsigned reset_hard = flags & RESET_HEAD_HARD;
-       struct object_id head_oid;
-       struct tree_desc desc[2] = { { NULL }, { NULL } };
-       struct lock_file lock = LOCK_INIT;
-       struct unpack_trees_options unpack_tree_opts;
-       struct tree *tree;
-       const char *reflog_action;
-       struct strbuf msg = STRBUF_INIT;
-       size_t prefix_len;
-       struct object_id *orig = NULL, oid_orig,
-               *old_orig = NULL, oid_old_orig;
-       int ret = 0, nr = 0;
-
-       if (switch_to_branch && !starts_with(switch_to_branch, "refs/"))
-               BUG("Not a fully qualified branch: '%s'", switch_to_branch);
-
-       if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
-               ret = -1;
-               goto leave_reset_head;
-       }
-
-       if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) {
-               ret = error(_("could not determine HEAD revision"));
-               goto leave_reset_head;
-       }
-
-       if (!oid)
-               oid = &head_oid;
-
-       memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
-       setup_unpack_trees_porcelain(&unpack_tree_opts, action);
-       unpack_tree_opts.head_idx = 1;
-       unpack_tree_opts.src_index = the_repository->index;
-       unpack_tree_opts.dst_index = the_repository->index;
-       unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge;
-       unpack_tree_opts.update = 1;
-       unpack_tree_opts.merge = 1;
-       if (!detach_head)
-               unpack_tree_opts.reset = 1;
-
-       if (read_index_unmerged(the_repository->index) < 0) {
-               ret = error(_("could not read index"));
-               goto leave_reset_head;
-       }
-
-       if (!reset_hard && !fill_tree_descriptor(&desc[nr++], &head_oid)) {
-               ret = error(_("failed to find tree of %s"),
-                           oid_to_hex(&head_oid));
-               goto leave_reset_head;
-       }
-
-       if (!fill_tree_descriptor(&desc[nr++], oid)) {
-               ret = error(_("failed to find tree of %s"), oid_to_hex(oid));
-               goto leave_reset_head;
-       }
-
-       if (unpack_trees(nr, desc, &unpack_tree_opts)) {
-               ret = -1;
-               goto leave_reset_head;
-       }
-
-       tree = parse_tree_indirect(oid);
-       prime_cache_tree(the_repository, the_repository->index, tree);
-
-       if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0) {
-               ret = error(_("could not write index"));
-               goto leave_reset_head;
-       }
-
-       reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
-       strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
-       prefix_len = msg.len;
-
-       if (!get_oid("ORIG_HEAD", &oid_old_orig))
-               old_orig = &oid_old_orig;
-       if (!get_oid("HEAD", &oid_orig)) {
-               orig = &oid_orig;
-               if (!reflog_orig_head) {
-                       strbuf_addstr(&msg, "updating ORIG_HEAD");
-                       reflog_orig_head = msg.buf;
-               }
-               update_ref(reflog_orig_head, "ORIG_HEAD", orig, old_orig, 0,
-                          UPDATE_REFS_MSG_ON_ERR);
-       } else if (old_orig)
-               delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
-       if (!reflog_head) {
-               strbuf_setlen(&msg, prefix_len);
-               strbuf_addstr(&msg, "updating HEAD");
-               reflog_head = msg.buf;
-       }
-       if (!switch_to_branch)
-               ret = update_ref(reflog_head, "HEAD", oid, orig,
-                                detach_head ? REF_NO_DEREF : 0,
-                                UPDATE_REFS_MSG_ON_ERR);
-       else {
-               ret = create_symref("HEAD", switch_to_branch, msg.buf);
-               if (!ret)
-                       ret = update_ref(reflog_head, "HEAD", oid, NULL, 0,
-                                        UPDATE_REFS_MSG_ON_ERR);
-       }
-
-leave_reset_head:
-       strbuf_release(&msg);
-       rollback_lock_file(&lock);
-       while (nr)
-               free((void *)desc[--nr].buffer);
-       return ret;
-}
-
 static int rebase_config(const char *var, const char *value, void *data)
 {
        struct rebase_options *opts = data;
@@ -674,6 +864,11 @@ static int rebase_config(const char *var, const char *value, void *data)
                return 0;
        }
 
+       if (!strcmp(var, "rebase.reschedulefailedexec")) {
+               opts->reschedule_failed_exec = git_config_bool(var, value);
+               return 0;
+       }
+
        return git_default_config(var, value, data);
 }
 
@@ -746,6 +941,23 @@ static int parse_opt_interactive(const struct option *opt, const char *arg,
        return 0;
 }
 
+struct opt_y {
+       struct string_list *list;
+       struct rebase_options *options;
+};
+
+static int parse_opt_y(const struct option *opt, const char *arg, int unset)
+{
+       struct opt_y *o = opt->value;
+
+       if (unset || !arg)
+               return -1;
+
+       o->options->reschedule_failed_exec = 1;
+       string_list_append(o->list, arg);
+       return 0;
+}
+
 static void NORETURN error_on_missing_default_upstream(void)
 {
        struct branch *current_branch = branch_get(NULL);
@@ -826,6 +1038,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
        struct string_list strategy_options = STRING_LIST_INIT_NODUP;
        struct object_id squash_onto;
        char *squash_onto_name = NULL;
+       struct opt_y opt_y = { .list = &exec, .options = &options };
        struct option builtin_rebase_options[] = {
                OPT_STRING(0, "onto", &options.onto_name,
                           N_("revision"),
@@ -903,6 +1116,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                OPT_STRING_LIST('x', "exec", &exec, N_("exec"),
                                N_("add exec lines after each commit of the "
                                   "editable list")),
+               { OPTION_CALLBACK, 'y', NULL, &opt_y, N_("<cmd>"),
+                       N_("same as --reschedule-failed-exec -x <cmd>"),
+                       PARSE_OPT_NONEG, parse_opt_y },
                OPT_BOOL(0, "allow-empty-message",
                         &options.allow_empty_message,
                         N_("allow rebasing commits with empty messages")),
@@ -920,6 +1136,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                                   "strategy")),
                OPT_BOOL(0, "root", &options.root,
                         N_("rebase all reachable commits up to the root(s)")),
+               OPT_BOOL(0, "reschedule-failed-exec",
+                        &options.reschedule_failed_exec,
+                        N_("automatically re-schedule any `exec` that fails")),
                OPT_END(),
        };
        int i;
@@ -1015,13 +1234,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                        die(_("Cannot read HEAD"));
 
                fd = hold_locked_index(&lock_file, 0);
-               if (read_index(the_repository->index) < 0)
+               if (repo_read_index(the_repository) < 0)
                        die(_("could not read index"));
                refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,
                              NULL);
                if (0 <= fd)
-                       update_index_if_able(the_repository->index,
-                                            &lock_file);
+                       repo_update_index_if_able(the_repository, &lock_file);
                rollback_lock_file(&lock_file);
 
                if (has_unstaged_changes(the_repository, 1)) {
@@ -1194,6 +1412,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                }
        }
 
+       if (options.type == REBASE_MERGE)
+               imply_interactive(&options, "--merge");
+
        if (options.root && !options.onto_name)
                imply_interactive(&options, "--root without --onto");
 
@@ -1216,6 +1437,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                break;
        }
 
+       if (options.reschedule_failed_exec && !is_interactive(&options))
+               die(_("--reschedule-failed-exec requires an interactive rebase"));
+
        if (options.git_am_opts.argc) {
                /* all am options except -q are compatible only with --am */
                for (i = options.git_am_opts.argc - 1; i >= 0; i--)
@@ -1223,14 +1447,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                                break;
 
                if (is_interactive(&options) && i >= 0)
-                       die(_("error: cannot combine interactive options "
-                             "(--interactive, --exec, --rebase-merges, "
-                             "--preserve-merges, --keep-empty, --root + "
-                             "--onto) with am options (%s)"), buf.buf);
-               if (options.type == REBASE_MERGE && i >= 0)
-                       die(_("error: cannot combine merge options (--merge, "
-                             "--strategy, --strategy-option) with am options "
-                             "(%s)"), buf.buf);
+                       die(_("cannot combine am options with either "
+                             "interactive or merge options"));
        }
 
        if (options.signoff) {
@@ -1241,22 +1459,27 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                options.flags |= REBASE_FORCE;
        }
 
-       if (options.type == REBASE_PRESERVE_MERGES)
+       if (options.type == REBASE_PRESERVE_MERGES) {
                /*
                 * Note: incompatibility with --signoff handled in signoff block above
                 * Note: incompatibility with --interactive is just a strong warning;
                 *       git-rebase.txt caveats with "unless you know what you are doing"
                 */
                if (options.rebase_merges)
-                       die(_("error: cannot combine '--preserve-merges' with "
+                       die(_("cannot combine '--preserve-merges' with "
                              "'--rebase-merges'"));
 
+               if (options.reschedule_failed_exec)
+                       die(_("error: cannot combine '--preserve-merges' with "
+                             "'--reschedule-failed-exec'"));
+       }
+
        if (options.rebase_merges) {
                if (strategy_options.nr)
-                       die(_("error: cannot combine '--rebase-merges' with "
+                       die(_("cannot combine '--rebase-merges' with "
                              "'--strategy-option'"));
                if (options.strategy)
-                       die(_("error: cannot combine '--rebase-merges' with "
+                       die(_("cannot combine '--rebase-merges' with "
                              "'--strategy'"));
        }
 
@@ -1368,7 +1591,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                        get_fork_point(options.upstream_name, head);
        }
 
-       if (read_index(the_repository->index) < 0)
+       if (repo_read_index(the_repository) < 0)
                die(_("could not read index"));
 
        if (options.autostash) {
@@ -1378,7 +1601,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                fd = hold_locked_index(&lock_file, 0);
                refresh_cache(REFRESH_QUIET);
                if (0 <= fd)
-                       update_index_if_able(&the_index, &lock_file);
+                       repo_update_index_if_able(the_repository, &lock_file);
                rollback_lock_file(&lock_file);
 
                if (has_unstaged_changes(the_repository, 1) ||
@@ -1423,7 +1646,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                        putchar('\n');
 
                        if (discard_index(the_repository->index) < 0 ||
-                               read_index(the_repository->index) < 0)
+                               repo_read_index(the_repository) < 0)
                                die(_("could not read index"));
                }
        }
@@ -1466,7 +1689,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                                            getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
                                            options.switch_to);
                                if (reset_head(&oid, "checkout",
-                                              options.head_name, 0,
+                                              options.head_name,
+                                              RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
                                               NULL, buf.buf) < 0) {
                                        ret = !!error(_("could not switch to "
                                                        "%s"),
@@ -1540,7 +1764,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
        strbuf_addf(&msg, "%s: checkout %s",
                    getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
        if (reset_head(&options.onto->object.oid, "checkout", NULL,
-                      RESET_HEAD_DETACH, NULL, msg.buf))
+                      RESET_HEAD_DETACH | RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
+                      NULL, msg.buf))
                die(_("Could not detach HEAD"));
        strbuf_release(&msg);
 
index 33187bd8e90252c283b7154bc7026e01d4e754ef..d58b7750b6b46565ca4ebb8299e5260943aa364e 100644 (file)
@@ -1569,30 +1569,29 @@ static void queue_commands_from_cert(struct command **tail,
        }
 }
 
-static struct command *read_head_info(struct oid_array *shallow)
+static struct command *read_head_info(struct packet_reader *reader,
+                                     struct oid_array *shallow)
 {
        struct command *commands = NULL;
        struct command **p = &commands;
        for (;;) {
-               char *line;
-               int len, linelen;
+               int linelen;
 
-               line = packet_read_line(0, &len);
-               if (!line)
+               if (packet_reader_read(reader) != PACKET_READ_NORMAL)
                        break;
 
-               if (len > 8 && starts_with(line, "shallow ")) {
+               if (reader->pktlen > 8 && starts_with(reader->line, "shallow ")) {
                        struct object_id oid;
-                       if (get_oid_hex(line + 8, &oid))
+                       if (get_oid_hex(reader->line + 8, &oid))
                                die("protocol error: expected shallow sha, got '%s'",
-                                   line + 8);
+                                   reader->line + 8);
                        oid_array_append(shallow, &oid);
                        continue;
                }
 
-               linelen = strlen(line);
-               if (linelen < len) {
-                       const char *feature_list = line + linelen + 1;
+               linelen = strlen(reader->line);
+               if (linelen < reader->pktlen) {
+                       const char *feature_list = reader->line + linelen + 1;
                        if (parse_feature_request(feature_list, "report-status"))
                                report_status = 1;
                        if (parse_feature_request(feature_list, "side-band-64k"))
@@ -1607,28 +1606,32 @@ static struct command *read_head_info(struct oid_array *shallow)
                                use_push_options = 1;
                }
 
-               if (!strcmp(line, "push-cert")) {
+               if (!strcmp(reader->line, "push-cert")) {
                        int true_flush = 0;
-                       char certbuf[1024];
+                       int saved_options = reader->options;
+                       reader->options &= ~PACKET_READ_CHOMP_NEWLINE;
 
                        for (;;) {
-                               len = packet_read(0, NULL, NULL,
-                                                 certbuf, sizeof(certbuf), 0);
-                               if (!len) {
+                               packet_reader_read(reader);
+                               if (reader->status == PACKET_READ_FLUSH) {
                                        true_flush = 1;
                                        break;
                                }
-                               if (!strcmp(certbuf, "push-cert-end\n"))
+                               if (reader->status != PACKET_READ_NORMAL) {
+                                       die("protocol error: got an unexpected packet");
+                               }
+                               if (!strcmp(reader->line, "push-cert-end\n"))
                                        break; /* end of cert */
-                               strbuf_addstr(&push_cert, certbuf);
+                               strbuf_addstr(&push_cert, reader->line);
                        }
+                       reader->options = saved_options;
 
                        if (true_flush)
                                break;
                        continue;
                }
 
-               p = queue_command(p, line, linelen);
+               p = queue_command(p, reader->line, linelen);
        }
 
        if (push_cert.len)
@@ -1637,18 +1640,14 @@ static struct command *read_head_info(struct oid_array *shallow)
        return commands;
 }
 
-static void read_push_options(struct string_list *options)
+static void read_push_options(struct packet_reader *reader,
+                             struct string_list *options)
 {
        while (1) {
-               char *line;
-               int len;
-
-               line = packet_read_line(0, &len);
-
-               if (!line)
+               if (packet_reader_read(reader) != PACKET_READ_NORMAL)
                        break;
 
-               string_list_append(options, line);
+               string_list_append(options, reader->line);
        }
 }
 
@@ -1924,6 +1923,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
        struct oid_array shallow = OID_ARRAY_INIT;
        struct oid_array ref = OID_ARRAY_INIT;
        struct shallow_info si;
+       struct packet_reader reader;
 
        struct option options[] = {
                OPT__QUIET(&quiet, N_("quiet")),
@@ -1986,12 +1986,16 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
        if (advertise_refs)
                return 0;
 
-       if ((commands = read_head_info(&shallow)) != NULL) {
+       packet_reader_init(&reader, 0, NULL, 0,
+                          PACKET_READ_CHOMP_NEWLINE |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
+
+       if ((commands = read_head_info(&reader, &shallow)) != NULL) {
                const char *unpack_status = NULL;
                struct string_list push_options = STRING_LIST_INIT_DUP;
 
                if (use_push_options)
-                       read_push_options(&push_options);
+                       read_push_options(&reader, &push_options);
                if (!check_cert_push_options(&push_options)) {
                        struct command *cmd;
                        for (cmd = commands; cmd; cmd = cmd->next)
index 64a8df4f252f598ff835c39ce8a3d3d417e8a31e..1f1010e2d9aec2b95487007ec30509fcbda605d6 100644 (file)
@@ -94,8 +94,8 @@ static int tree_is_complete(const struct object_id *oid)
        init_tree_desc(&desc, tree->buffer, tree->size);
        complete = 1;
        while (tree_entry(&desc, &entry)) {
-               if (!has_sha1_file(entry.oid->hash) ||
-                   (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid))) {
+               if (!has_sha1_file(entry.oid.hash) ||
+                   (S_ISDIR(entry.mode) && !tree_is_complete(&entry.oid))) {
                        tree->object.flags |= INCOMPLETE;
                        complete = 0;
                }
index affcdfb4169899c2affee51593f0453d5d9b9add..5b80b7f21141d6f85d8444d669dffe289f3a60f5 100644 (file)
@@ -295,7 +295,7 @@ static int import_object(struct object_id *oid, enum object_type type,
                        close(fd);
                        return -1;
                }
-               if (index_fd(&the_index, oid, fd, &st, type, NULL, flags) < 0)
+               if (index_fd(the_repository->index, oid, fd, &st, type, NULL, flags) < 0)
                        return error(_("unable to write object to database"));
                /* index_fd close()s fd for us */
        }
index 59898c972eee5e8065c2a68b7c937cc3af11f513..4d18a461fab631dd752adec3b95197a3a2657a62 100644 (file)
@@ -7,6 +7,7 @@
  *
  * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "config.h"
 #include "lockfile.h"
index 51e9e1267e848b345ff7c78fe036e7e66bb6f055..5b5b6dbb1c9b6f9893f3d0420c99655eb19501a8 100644 (file)
@@ -197,7 +197,8 @@ static void finish_commit(struct commit *commit, void *data)
                free_commit_list(commit->parents);
                commit->parents = NULL;
        }
-       free_commit_buffer(commit);
+       free_commit_buffer(the_repository->parsed_objects,
+                          commit);
 }
 
 static inline void finish_object__ma(struct object *obj)
@@ -545,7 +546,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
        if (prepare_revision_walk(&revs))
                die("revision walk setup failed");
        if (revs.tree_objects)
-               mark_edges_uninteresting(&revs, show_edge);
+               mark_edges_uninteresting(&revs, show_edge, 0);
 
        if (bisect_list) {
                int reaches, all;
index 10d4dab894e25a73d6a761205ce53c88019a4a8b..f8bbe6d47ec397f55bec62d6a71bc6db8f08b54b 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "commit.h"
@@ -933,7 +934,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                        name++;
                        type = REVERSED;
                }
-               if (!get_oid_with_context(name, flags, &oid, &unused)) {
+               if (!get_oid_with_context(the_repository, name,
+                                         flags, &oid, &unused)) {
                        if (verify)
                                revs_count++;
                        else
index 17086d3d97c536522720c589ea8f35d366536ea8..db85b339823cc0aa5ab5d03220335d4e4240d656 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds 2006
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "config.h"
 #include "lockfile.h"
index 8e3c7490f70df79497ee064ab13c0164de11fe9e..098ebf22d0d65a6f98606c7ea567467641976f6b 100644 (file)
@@ -250,7 +250,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
 
        packet_reader_init(&reader, fd[0], NULL, 0,
                           PACKET_READ_CHOMP_NEWLINE |
-                          PACKET_READ_GENTLE_ON_EOF);
+                          PACKET_READ_GENTLE_ON_EOF |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
 
        switch (discover_version(&reader)) {
        case protocol_v2:
index 6881b6a9cb0fa1cd44118663cd8d7c8eaef1c95a..b80fc4ba3d88b56436fa3f6b9a132bfe9e82b79b 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "repository.h"
 #include "cache.h"
@@ -2056,7 +2057,7 @@ static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
        if (!sub)
                BUG("We could get the submodule handle before?");
 
-       if (repo_submodule_init(&subrepo, the_repository, path))
+       if (repo_submodule_init(&subrepo, the_repository, sub))
                die(_("could not get a repository handle for submodule '%s'"), path);
 
        if (!repo_config_get_string(&subrepo, "core.worktree", &cw)) {
index e19da77edcaa024cc2bffc6fa8818c2b1cf0d4b6..02ace602b9ae23d6ab74abac016948410b30fcde 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "lockfile.h"
index cdcbf8264e8c6e9b56977b99ad28160754d8fb7c..3d46d22ee5261d2cf1233913b7b544e812c26122 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
index 37b1daa6918bafb6b21faba47d25fcc6433698ba..b45666c49b1c19a63d816527a761d0177d9633ce 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -424,8 +424,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
        return ref_count;
 }
 
-int create_bundle(struct repository *r, struct bundle_header *header,
-                 const char *path, int argc, const char **argv)
+int create_bundle(struct repository *r, const char *path,
+                 int argc, const char **argv)
 {
        struct lock_file lock = LOCK_INIT;
        int bundle_fd = -1;
index 781e6f5c3a837ac65e6911ec5e0ae458b8b6a5c7..37c37d7f653c68ab6752fab8203b59783e2f5c40 100644 (file)
--- a/bundle.h
+++ b/bundle.h
@@ -18,8 +18,8 @@ struct bundle_header {
 
 int is_bundle(const char *path, int quiet);
 int read_bundle_header(const char *path, struct bundle_header *header);
-int create_bundle(struct repository *r, struct bundle_header *header,
-                 const char *path, int argc, const char **argv);
+int create_bundle(struct repository *r, const char *path,
+                 int argc, const char **argv);
 int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
 #define BUNDLE_VERBOSE 1
 int unbundle(struct repository *r, struct bundle_header *header,
index eabb8fb6546cbb5e418f30a4e9329d635520d601..c4b8a1fa16d4e1376c1df3f2784db32c20001314 100644 (file)
@@ -675,7 +675,7 @@ static void prime_cache_tree_rec(struct repository *r,
                        cnt++;
                else {
                        struct cache_tree_sub *sub;
-                       struct tree *subtree = lookup_tree(r, entry.oid);
+                       struct tree *subtree = lookup_tree(r, &entry.oid);
                        if (!subtree->object.parsed)
                                parse_tree(subtree);
                        sub = cache_tree_sub(it, entry.path);
@@ -724,7 +724,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,
 
        it = find_cache_tree_from_traversal(root, info);
        it = cache_tree_find(it, ent->path);
-       if (it && it->entry_count > 0 && oideq(ent->oid, &it->oid))
+       if (it && it->entry_count > 0 && oideq(&ent->oid, &it->oid))
                return it->entry_count;
        return 0;
 }
index 326209198b60fa8a6fdbd171c46132b8a5062e04..757bbc48bca155fe539d07a268087b96ae7aa7f6 100644 (file)
@@ -51,7 +51,7 @@ void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
 
 int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
 
-#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS
+#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
 static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)
 {
        return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);
diff --git a/cache.h b/cache.h
index 49713cc5a5a61bf0749e596b94474f00286dc652..ef9f3c4eaf2956c416b3b698ce965acb9c58ca98 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -45,10 +45,20 @@ unsigned long git_deflate_bound(git_zstream *, unsigned long);
 /* The length in bytes and in hex digits of an object name (SHA-1 value). */
 #define GIT_SHA1_RAWSZ 20
 #define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
+/* The block size of SHA-1. */
+#define GIT_SHA1_BLKSZ 64
+
+/* The length in bytes and in hex digits of an object name (SHA-256 value). */
+#define GIT_SHA256_RAWSZ 32
+#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
+/* The block size of SHA-256. */
+#define GIT_SHA256_BLKSZ 64
 
 /* The length in byte and in hex digits of the largest possible hash value. */
-#define GIT_MAX_RAWSZ GIT_SHA1_RAWSZ
-#define GIT_MAX_HEXSZ GIT_SHA1_HEXSZ
+#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
+#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
+/* The largest possible block size for any supported hash. */
+#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
 
 struct object_id {
        unsigned char hash[GIT_MAX_RAWSZ];
@@ -338,8 +348,6 @@ struct index_state {
        struct mem_pool *ce_mem_pool;
 };
 
-extern struct index_state the_index;
-
 /* Name hashing */
 extern int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
 extern void add_name_hash(struct index_state *istate, struct cache_entry *ce);
@@ -401,18 +409,20 @@ struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_s
  */
 void validate_cache_entries(const struct index_state *istate);
 
-#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS
+#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
+extern struct index_state the_index;
+
 #define active_cache (the_index.cache)
 #define active_nr (the_index.cache_nr)
 #define active_alloc (the_index.cache_alloc)
 #define active_cache_changed (the_index.cache_changed)
 #define active_cache_tree (the_index.cache_tree)
 
-#define read_cache() read_index(&the_index)
+#define read_cache() repo_read_index(the_repository)
 #define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))
-#define read_cache_preload(pathspec) read_index_preload(&the_index, (pathspec), 0)
+#define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)
 #define is_cache_unborn() is_index_unborn(&the_index)
-#define read_cache_unmerged() read_index_unmerged(&the_index)
+#define read_cache_unmerged() repo_read_index_unmerged(the_repository)
 #define discard_cache() discard_index(&the_index)
 #define unmerged_cache() unmerged_index(&the_index)
 #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))
@@ -433,6 +443,7 @@ void validate_cache_entries(const struct index_state *istate);
 #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)
 #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)
 #define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))
+#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))
 #endif
 
 #define TYPE_BITS 3
@@ -660,19 +671,14 @@ extern int daemonize(void);
 
 /* Initialize and use the cache information */
 struct lock_file;
-extern int read_index(struct index_state *);
 extern void preload_index(struct index_state *index,
                          const struct pathspec *pathspec,
                          unsigned int refresh_flags);
-extern int read_index_preload(struct index_state *,
-                             const struct pathspec *pathspec,
-                             unsigned int refresh_flags);
 extern int do_read_index(struct index_state *istate, const char *path,
                         int must_exist); /* for testting only! */
 extern int read_index_from(struct index_state *, const char *path,
                           const char *gitdir);
 extern int is_index_unborn(struct index_state *);
-extern int read_index_unmerged(struct index_state *);
 
 /* For use with `write_locked_index()`. */
 #define COMMIT_LOCK            (1 << 0)
@@ -710,9 +716,9 @@ extern int unmerged_index(const struct index_state *);
  * provided, the space-separated list of files that differ will be appended
  * to it.
  */
-extern int index_has_changes(struct index_state *istate,
-                            struct tree *tree,
-                            struct strbuf *sb);
+extern int repo_index_has_changes(struct repository *repo,
+                                 struct tree *tree,
+                                 struct strbuf *sb);
 
 extern int verify_path(const char *path, unsigned mode);
 extern int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
@@ -745,6 +751,7 @@ extern int index_name_pos(const struct index_state *, const char *name, int name
 #define ADD_CACHE_JUST_APPEND 8                /* Append only; tree.c::read_tree() */
 #define ADD_CACHE_NEW_ONLY 16          /* Do not replace existing ones */
 #define ADD_CACHE_KEEP_CACHE_TREE 32   /* Do not invalidate cache-tree */
+#define ADD_CACHE_RENORMALIZE 64        /* Pass along HASH_RENORMALIZE */
 extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
 extern void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
 
@@ -827,13 +834,6 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
 extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
 extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);
 
-/*
- * Opportunistically update the index but do not complain if we can't.
- * The lockfile is always committed or rolled back.
- */
-extern void update_index_if_able(struct index_state *, struct lock_file *);
-
-extern int hold_locked_index(struct lock_file *, int);
 extern void set_alternate_index_output(const char *);
 
 extern int verify_index_checksum;
@@ -1028,16 +1028,12 @@ extern const struct object_id null_oid;
 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
 {
        /*
-        * This is a temporary optimization hack. By asserting the size here,
-        * we let the compiler know that it's always going to be 20, which lets
-        * it turn this fixed-size memcmp into a few inline instructions.
-        *
-        * This will need to be extended or ripped out when we learn about
-        * hashes of different sizes.
+        * Teach the compiler that there are only two possibilities of hash size
+        * here, so that it can optimize for this case as much as possible.
         */
-       if (the_hash_algo->rawsz != 20)
-               BUG("hash size not yet supported by hashcmp");
-       return memcmp(sha1, sha2, the_hash_algo->rawsz);
+       if (the_hash_algo->rawsz == GIT_MAX_RAWSZ)
+               return memcmp(sha1, sha2, GIT_MAX_RAWSZ);
+       return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
 }
 
 static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
@@ -1047,7 +1043,13 @@ static inline int oidcmp(const struct object_id *oid1, const struct object_id *o
 
 static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)
 {
-       return !hashcmp(sha1, sha2);
+       /*
+        * We write this here instead of deferring to hashcmp so that the
+        * compiler can properly inline it and avoid calling memcmp.
+        */
+       if (the_hash_algo->rawsz == GIT_MAX_RAWSZ)
+               return !memcmp(sha1, sha2, GIT_MAX_RAWSZ);
+       return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
 }
 
 static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
@@ -1072,7 +1074,7 @@ static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
 
 static inline void oidcpy(struct object_id *dst, const struct object_id *src)
 {
-       hashcpy(dst->hash, src->hash);
+       memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
 }
 
 static inline struct object_id *oiddup(const struct object_id *src)
@@ -1332,6 +1334,24 @@ struct object_context {
        GET_OID_TREE | GET_OID_TREEISH | \
        GET_OID_BLOB)
 
+enum get_oid_result {
+       FOUND = 0,
+       MISSING_OBJECT = -1, /* The requested object is missing */
+       SHORT_NAME_AMBIGUOUS = -2,
+       /* The following only apply when symlinks are followed */
+       DANGLING_SYMLINK = -4, /*
+                               * The initial symlink is there, but
+                               * (transitively) points to a missing
+                               * in-tree file
+                               */
+       SYMLINK_LOOP = -5,
+       NOT_DIR = -6, /*
+                      * Somewhere along the symlink chain, a path is
+                      * requested which contains a file as a
+                      * non-final element.
+                      */
+};
+
 extern int get_oid(const char *str, struct object_id *oid);
 extern int get_oid_commit(const char *str, struct object_id *oid);
 extern int get_oid_committish(const char *str, struct object_id *oid);
@@ -1339,8 +1359,9 @@ extern int get_oid_tree(const char *str, struct object_id *oid);
 extern int get_oid_treeish(const char *str, struct object_id *oid);
 extern int get_oid_blob(const char *str, struct object_id *oid);
 extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
-extern int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc);
-
+extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,
+                               unsigned flags, struct object_id *oid,
+                               struct object_context *oc);
 
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
 extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
@@ -1365,9 +1386,9 @@ extern int get_oid_hex(const char *hex, struct object_id *sha1);
 extern int hex_to_bytes(unsigned char *binary, const char *hex, size_t len);
 
 /*
- * Convert a binary sha1 to its hex equivalent. The `_r` variant is reentrant,
+ * Convert a binary hash to its hex equivalent. The `_r` variant is reentrant,
  * and writes the NUL-terminated output to the buffer `out`, which must be at
- * least `GIT_SHA1_HEXSZ + 1` bytes, and returns a pointer to out for
+ * least `GIT_MAX_HEXSZ + 1` bytes, and returns a pointer to out for
  * convenience.
  *
  * The non-`_r` variant returns a static buffer, but uses a ring of 4
@@ -1375,10 +1396,13 @@ extern int hex_to_bytes(unsigned char *binary, const char *hex, size_t len);
  *
  *   printf("%s -> %s", sha1_to_hex(one), sha1_to_hex(two));
  */
-extern char *sha1_to_hex_r(char *out, const unsigned char *sha1);
-extern char *oid_to_hex_r(char *out, const struct object_id *oid);
-extern char *sha1_to_hex(const unsigned char *sha1);   /* static buffer result! */
-extern char *oid_to_hex(const struct object_id *oid);  /* same static buffer as sha1_to_hex */
+char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash, const struct git_hash_algo *);
+char *sha1_to_hex_r(char *out, const unsigned char *sha1);
+char *oid_to_hex_r(char *out, const struct object_id *oid);
+char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *);      /* static buffer result! */
+char *sha1_to_hex(const unsigned char *sha1);                                          /* same static buffer */
+char *hash_to_hex(const unsigned char *hash);                                          /* same static buffer */
+char *oid_to_hex(const struct object_id *oid);                                         /* same static buffer */
 
 /*
  * Parse a 40-character hexadecimal object ID starting from hex, updating the
@@ -1439,6 +1463,7 @@ extern struct object *peel_to_type(const char *name, int namelen,
 
 enum date_mode_type {
        DATE_NORMAL = 0,
+       DATE_HUMAN,
        DATE_RELATIVE,
        DATE_SHORT,
        DATE_ISO8601,
@@ -1464,7 +1489,9 @@ struct date_mode {
 struct date_mode *date_mode_from_type(enum date_mode_type type);
 
 const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode);
-void show_date_relative(timestamp_t time, int tz, const struct timeval *now,
+void show_date_relative(timestamp_t time, const struct timeval *now,
+                       struct strbuf *timebuf);
+void show_date_human(timestamp_t time, int tz, const struct timeval *now,
                        struct strbuf *timebuf);
 int parse_date(const char *date, struct strbuf *out);
 int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset);
@@ -1788,4 +1815,7 @@ void safe_create_dir(const char *dir, int share);
  */
 extern int print_sha1_ellipsis(void);
 
+/* Return 1 if the file is empty or does not exists, 0 otherwise. */
+extern int is_empty_or_missing_file(const char *filename);
+
 #endif /* CACHE_H */
index 06c3546e1ed4e1a78cea4d7a1801145066a895d8..dc719876bb12309c086952d275085d8d3d0690e6 100755 (executable)
@@ -40,6 +40,11 @@ osx-clang|osx-gcc)
        brew install git-lfs gettext
        brew link --force gettext
        brew install caskroom/cask/perforce
+       case "$jobname" in
+       osx-gcc)
+               brew link gcc@8
+               ;;
+       esac
        ;;
 StaticAnalysis)
        sudo apt-get -q update
index 69dff4d1ecb4b21c32f8127d78a87a925e9390c5..a479613a5748858774994f67fdcd29600b95d1ba 100755 (executable)
@@ -99,12 +99,14 @@ export DEFAULT_TEST_TARGET=prove
 export GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save"
 export GIT_TEST_OPTS="--verbose-log -x --immediate"
 export GIT_TEST_CLONE_2GB=YesPlease
-if [ "$jobname" = linux-gcc ]; then
-       export CC=gcc-8
-fi
 
 case "$jobname" in
 linux-clang|linux-gcc)
+       if [ "$jobname" = linux-gcc ]
+       then
+               export CC=gcc-8
+       fi
+
        export GIT_TEST_HTTPD=YesPlease
 
        # The Linux build installs the defined dependency versions below.
@@ -118,6 +120,11 @@ linux-clang|linux-gcc)
        export PATH="$GIT_LFS_PATH:$P4_PATH:$PATH"
        ;;
 osx-clang|osx-gcc)
+       if [ "$jobname" = osx-gcc ]
+       then
+               export CC=gcc-8
+       fi
+
        # t9810 occasionally fails on Travis CI OS X
        # t9816 occasionally fails with "TAP out of sequence errors" on
        # Travis CI OS X
@@ -127,3 +134,5 @@ GIT_TEST_GETTEXT_POISON)
        export GIT_TEST_GETTEXT_POISON=YesPlease
        ;;
 esac
+
+export MAKEFLAGS="CC=${CC:-cc}"
index cda170d5c27bab7c511d6fe70fc9852b21cc0180..84431c097eb8dffa1b540ee61d6c047239afd18a 100755 (executable)
@@ -8,7 +8,7 @@
 ln -s "$cache_dir/.prove" t/.prove
 
 make --jobs=2
-make --quiet test
+make test
 if test "$jobname" = "linux-gcc"
 then
        export GIT_TEST_SPLIT_INDEX=yes
@@ -17,7 +17,7 @@ then
        export GIT_TEST_OE_DELTA_SIZE=5
        export GIT_TEST_COMMIT_GRAPH=1
        export GIT_TEST_MULTI_PACK_INDEX=1
-       make --quiet test
+       make test
 fi
 
 check_unignored_build_artifacts
index 2c60d2e70ae56b59b1ff8046a21b9bc4bf87e3e6..26c168a0165522655e4e80988ba553b314b333f5 100755 (executable)
@@ -56,5 +56,5 @@ linux32 --32bit i386 su -m -l $CI_USER -c '
        cd /usr/src/git
        test -n "$cache_dir" && ln -s "$cache_dir/.prove" t/.prove
        make --jobs=2
-       make --quiet test
+       make test
 '
index 2165297608ec92c3f5a9cc9abfba072f9d43be1f..7a17c14b822faac1a00b62412611825f0952a935 100644 (file)
--- a/column.c
+++ b/column.c
@@ -21,7 +21,7 @@ struct column_data {
 };
 
 /* return length of 's' in letters, ANSI escapes stripped */
-static int item_length(unsigned int colopts, const char *s)
+static int item_length(const char *s)
 {
        int len, i = 0;
        struct strbuf str = STRBUF_INIT;
@@ -167,7 +167,7 @@ static void display_table(const struct string_list *list,
 
        ALLOC_ARRAY(data.len, list->nr);
        for (i = 0; i < list->nr; i++)
-               data.len[i] = item_length(colopts, list->items[i].string);
+               data.len[i] = item_length(list->items[i].string);
 
        layout(&data, &initial_width);
 
index a143c006341170fad8c42604eca8f9bbf3226de8..23d8fabe75d9d80b2811acfc20f62d210ec6bba8 100644 (file)
@@ -1321,6 +1321,14 @@ static const char *path_path(void *obj)
        return path->path;
 }
 
+/*
+ * Diff stat formats which we always compute solely against the first parent.
+ */
+#define STAT_FORMAT_MASK (DIFF_FORMAT_NUMSTAT \
+                         | DIFF_FORMAT_SHORTSTAT \
+                         | DIFF_FORMAT_SUMMARY \
+                         | DIFF_FORMAT_DIRSTAT \
+                         | DIFF_FORMAT_DIFFSTAT)
 
 /* find set of paths that every parent touches */
 static struct combine_diff_path *find_paths_generic(const struct object_id *oid,
@@ -1342,8 +1350,7 @@ static struct combine_diff_path *find_paths_generic(const struct object_id *oid,
                 * show stat against the first parent even when doing
                 * combined diff.
                 */
-               int stat_opt = (output_format &
-                               (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT));
+               int stat_opt = output_format & STAT_FORMAT_MASK;
                if (i == 0 && stat_opt)
                        opt->output_format = stat_opt;
                else
@@ -1470,8 +1477,7 @@ void diff_tree_combined(const struct object_id *oid,
                 * show stat against the first parent even
                 * when doing combined diff.
                 */
-               stat_opt = (opt->output_format &
-                               (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT));
+               stat_opt = opt->output_format & STAT_FORMAT_MASK;
                if (stat_opt) {
                        diffopts.output_format = stat_opt;
 
@@ -1515,8 +1521,7 @@ void diff_tree_combined(const struct object_id *oid,
                                show_raw_diff(p, num_parent, rev);
                        needsep = 1;
                }
-               else if (opt->output_format &
-                        (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT))
+               else if (opt->output_format & STAT_FORMAT_MASK)
                        needsep = 1;
                else if (opt->output_format & DIFF_FORMAT_CALLBACK)
                        handle_combined_callback(opt, paths, num_parent, num_paths);
index 0d6ba6da2d76fa3a5d43dae74fc1bb7b652c6df0..47e9be0a3aad883c17221b11c972b8376a70a555 100644 (file)
 #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
 #define GRAPH_CHUNKID_OIDLOOKUP 0x4f49444c /* "OIDL" */
 #define GRAPH_CHUNKID_DATA 0x43444154 /* "CDAT" */
-#define GRAPH_CHUNKID_LARGEEDGES 0x45444745 /* "EDGE" */
+#define GRAPH_CHUNKID_EXTRAEDGES 0x45444745 /* "EDGE" */
 
-#define GRAPH_DATA_WIDTH 36
+#define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
 
 #define GRAPH_VERSION_1 0x1
 #define GRAPH_VERSION GRAPH_VERSION_1
 
-#define GRAPH_OID_VERSION_SHA1 1
-#define GRAPH_OID_LEN_SHA1 GIT_SHA1_RAWSZ
-#define GRAPH_OID_VERSION GRAPH_OID_VERSION_SHA1
-#define GRAPH_OID_LEN GRAPH_OID_LEN_SHA1
-
-#define GRAPH_OCTOPUS_EDGES_NEEDED 0x80000000
+#define GRAPH_EXTRA_EDGES_NEEDED 0x80000000
 #define GRAPH_EDGE_LAST_MASK 0x7fffffff
 #define GRAPH_PARENT_NONE 0x70000000
 
 #define GRAPH_FANOUT_SIZE (4 * 256)
 #define GRAPH_CHUNKLOOKUP_WIDTH 12
 #define GRAPH_MIN_SIZE (GRAPH_HEADER_SIZE + 4 * GRAPH_CHUNKLOOKUP_WIDTH \
-                       + GRAPH_FANOUT_SIZE + GRAPH_OID_LEN)
+                       + GRAPH_FANOUT_SIZE + the_hash_algo->rawsz)
 
 char *get_commit_graph_filename(const char *obj_dir)
 {
        return xstrfmt("%s/info/commit-graph", obj_dir);
 }
 
+static uint8_t oid_version(void)
+{
+       return 1;
+}
+
 static struct commit_graph *alloc_commit_graph(void)
 {
        struct commit_graph *g = xcalloc(1, sizeof(*g));
@@ -83,16 +83,10 @@ static int commit_graph_compatible(struct repository *r)
 struct commit_graph *load_commit_graph_one(const char *graph_file)
 {
        void *graph_map;
-       const unsigned char *data, *chunk_lookup;
        size_t graph_size;
        struct stat st;
-       uint32_t i;
-       struct commit_graph *graph;
+       struct commit_graph *ret;
        int fd = git_open(graph_file);
-       uint64_t last_chunk_offset;
-       uint32_t last_chunk_id;
-       uint32_t graph_signature;
-       unsigned char graph_version, hash_version;
 
        if (fd < 0)
                return NULL;
@@ -107,32 +101,60 @@ struct commit_graph *load_commit_graph_one(const char *graph_file)
                die(_("graph file %s is too small"), graph_file);
        }
        graph_map = xmmap(NULL, graph_size, PROT_READ, MAP_PRIVATE, fd, 0);
+       ret = parse_commit_graph(graph_map, fd, graph_size);
+
+       if (!ret) {
+               munmap(graph_map, graph_size);
+               close(fd);
+               exit(1);
+       }
+
+       return ret;
+}
+
+struct commit_graph *parse_commit_graph(void *graph_map, int fd,
+                                       size_t graph_size)
+{
+       const unsigned char *data, *chunk_lookup;
+       uint32_t i;
+       struct commit_graph *graph;
+       uint64_t last_chunk_offset;
+       uint32_t last_chunk_id;
+       uint32_t graph_signature;
+       unsigned char graph_version, hash_version;
+
+       if (!graph_map)
+               return NULL;
+
+       if (graph_size < GRAPH_MIN_SIZE)
+               return NULL;
+
        data = (const unsigned char *)graph_map;
 
        graph_signature = get_be32(data);
        if (graph_signature != GRAPH_SIGNATURE) {
                error(_("graph signature %X does not match signature %X"),
                      graph_signature, GRAPH_SIGNATURE);
-               goto cleanup_fail;
+               return NULL;
        }
 
        graph_version = *(unsigned char*)(data + 4);
        if (graph_version != GRAPH_VERSION) {
                error(_("graph version %X does not match version %X"),
                      graph_version, GRAPH_VERSION);
-               goto cleanup_fail;
+               return NULL;
        }
 
        hash_version = *(unsigned char*)(data + 5);
-       if (hash_version != GRAPH_OID_VERSION) {
+       if (hash_version != oid_version()) {
                error(_("hash version %X does not match version %X"),
-                     hash_version, GRAPH_OID_VERSION);
-               goto cleanup_fail;
+                     hash_version, oid_version());
+               return NULL;
        }
 
        graph = alloc_commit_graph();
 
-       graph->hash_len = GRAPH_OID_LEN;
+       graph->hash_len = the_hash_algo->rawsz;
        graph->num_chunks = *(unsigned char*)(data + 6);
        graph->graph_fd = fd;
        graph->data = graph_map;
@@ -142,16 +164,27 @@ struct commit_graph *load_commit_graph_one(const char *graph_file)
        last_chunk_offset = 8;
        chunk_lookup = data + 8;
        for (i = 0; i < graph->num_chunks; i++) {
-               uint32_t chunk_id = get_be32(chunk_lookup + 0);
-               uint64_t chunk_offset = get_be64(chunk_lookup + 4);
+               uint32_t chunk_id;
+               uint64_t chunk_offset;
                int chunk_repeated = 0;
 
+               if (data + graph_size - chunk_lookup <
+                   GRAPH_CHUNKLOOKUP_WIDTH) {
+                       error(_("chunk lookup table entry missing; graph file may be incomplete"));
+                       free(graph);
+                       return NULL;
+               }
+
+               chunk_id = get_be32(chunk_lookup + 0);
+               chunk_offset = get_be64(chunk_lookup + 4);
+
                chunk_lookup += GRAPH_CHUNKLOOKUP_WIDTH;
 
-               if (chunk_offset > graph_size - GIT_MAX_RAWSZ) {
+               if (chunk_offset > graph_size - the_hash_algo->rawsz) {
                        error(_("improper chunk offset %08x%08x"), (uint32_t)(chunk_offset >> 32),
                              (uint32_t)chunk_offset);
-                       goto cleanup_fail;
+                       free(graph);
+                       return NULL;
                }
 
                switch (chunk_id) {
@@ -176,17 +209,18 @@ struct commit_graph *load_commit_graph_one(const char *graph_file)
                                graph->chunk_commit_data = data + chunk_offset;
                        break;
 
-               case GRAPH_CHUNKID_LARGEEDGES:
-                       if (graph->chunk_large_edges)
+               case GRAPH_CHUNKID_EXTRAEDGES:
+                       if (graph->chunk_extra_edges)
                                chunk_repeated = 1;
                        else
-                               graph->chunk_large_edges = data + chunk_offset;
+                               graph->chunk_extra_edges = data + chunk_offset;
                        break;
                }
 
                if (chunk_repeated) {
                        error(_("chunk id %08x appears multiple times"), chunk_id);
-                       goto cleanup_fail;
+                       free(graph);
+                       return NULL;
                }
 
                if (last_chunk_id == GRAPH_CHUNKID_OIDLOOKUP)
@@ -200,11 +234,6 @@ struct commit_graph *load_commit_graph_one(const char *graph_file)
        }
 
        return graph;
-
-cleanup_fail:
-       munmap(graph_map, graph_size);
-       close(fd);
-       exit(1);
 }
 
 static void prepare_commit_graph_one(struct repository *r, const char *obj_dir)
@@ -288,7 +317,8 @@ static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t
                            g->chunk_oid_lookup, g->hash_len, pos);
 }
 
-static struct commit_list **insert_parent_or_die(struct commit_graph *g,
+static struct commit_list **insert_parent_or_die(struct repository *r,
+                                                struct commit_graph *g,
                                                 uint64_t pos,
                                                 struct commit_list **pptr)
 {
@@ -299,7 +329,7 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g,
                die("invalid parent position %"PRIu64, pos);
 
        hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * pos);
-       c = lookup_commit(the_repository, &oid);
+       c = lookup_commit(r, &oid);
        if (!c)
                die(_("could not find commit %s"), oid_to_hex(&oid));
        c->graph_pos = pos;
@@ -313,7 +343,9 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
        item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
 }
 
-static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t pos)
+static int fill_commit_in_graph(struct repository *r,
+                               struct commit *item,
+                               struct commit_graph *g, uint32_t pos)
 {
        uint32_t edge_value;
        uint32_t *parent_data_ptr;
@@ -337,21 +369,21 @@ static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uin
        edge_value = get_be32(commit_data + g->hash_len);
        if (edge_value == GRAPH_PARENT_NONE)
                return 1;
-       pptr = insert_parent_or_die(g, edge_value, pptr);
+       pptr = insert_parent_or_die(r, g, edge_value, pptr);
 
        edge_value = get_be32(commit_data + g->hash_len + 4);
        if (edge_value == GRAPH_PARENT_NONE)
                return 1;
-       if (!(edge_value & GRAPH_OCTOPUS_EDGES_NEEDED)) {
-               pptr = insert_parent_or_die(g, edge_value, pptr);
+       if (!(edge_value & GRAPH_EXTRA_EDGES_NEEDED)) {
+               pptr = insert_parent_or_die(r, g, edge_value, pptr);
                return 1;
        }
 
-       parent_data_ptr = (uint32_t*)(g->chunk_large_edges +
+       parent_data_ptr = (uint32_t*)(g->chunk_extra_edges +
                          4 * (uint64_t)(edge_value & GRAPH_EDGE_LAST_MASK));
        do {
                edge_value = get_be32(parent_data_ptr);
-               pptr = insert_parent_or_die(g,
+               pptr = insert_parent_or_die(r, g,
                                            edge_value & GRAPH_EDGE_LAST_MASK,
                                            pptr);
                parent_data_ptr++;
@@ -370,7 +402,9 @@ static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uin
        }
 }
 
-static int parse_commit_in_graph_one(struct commit_graph *g, struct commit *item)
+static int parse_commit_in_graph_one(struct repository *r,
+                                    struct commit_graph *g,
+                                    struct commit *item)
 {
        uint32_t pos;
 
@@ -378,7 +412,7 @@ static int parse_commit_in_graph_one(struct commit_graph *g, struct commit *item
                return 1;
 
        if (find_commit_in_graph(item, g, &pos))
-               return fill_commit_in_graph(item, g, pos);
+               return fill_commit_in_graph(r, item, g, pos);
 
        return 0;
 }
@@ -387,7 +421,7 @@ int parse_commit_in_graph(struct repository *r, struct commit *item)
 {
        if (!prepare_commit_graph(r))
                return 0;
-       return parse_commit_in_graph_one(r->objects->commit_graph, item);
+       return parse_commit_in_graph_one(r, r->objects->commit_graph, item);
 }
 
 void load_commit_graph_info(struct repository *r, struct commit *item)
@@ -399,19 +433,22 @@ void load_commit_graph_info(struct repository *r, struct commit *item)
                fill_commit_graph_info(item, r->objects->commit_graph, pos);
 }
 
-static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit *c)
+static struct tree *load_tree_for_commit(struct repository *r,
+                                        struct commit_graph *g,
+                                        struct commit *c)
 {
        struct object_id oid;
        const unsigned char *commit_data = g->chunk_commit_data +
                                           GRAPH_DATA_WIDTH * (c->graph_pos);
 
        hashcpy(oid.hash, commit_data);
-       c->maybe_tree = lookup_tree(the_repository, &oid);
+       c->maybe_tree = lookup_tree(r, &oid);
 
        return c->maybe_tree;
 }
 
-static struct tree *get_commit_tree_in_graph_one(struct commit_graph *g,
+static struct tree *get_commit_tree_in_graph_one(struct repository *r,
+                                                struct commit_graph *g,
                                                 const struct commit *c)
 {
        if (c->maybe_tree)
@@ -419,17 +456,19 @@ static struct tree *get_commit_tree_in_graph_one(struct commit_graph *g,
        if (c->graph_pos == COMMIT_NOT_FROM_GRAPH)
                BUG("get_commit_tree_in_graph_one called from non-commit-graph commit");
 
-       return load_tree_for_commit(g, (struct commit *)c);
+       return load_tree_for_commit(r, g, (struct commit *)c);
 }
 
 struct tree *get_commit_tree_in_graph(struct repository *r, const struct commit *c)
 {
-       return get_commit_tree_in_graph_one(r->objects->commit_graph, c);
+       return get_commit_tree_in_graph_one(r, r->objects->commit_graph, c);
 }
 
 static void write_graph_chunk_fanout(struct hashfile *f,
                                     struct commit **commits,
-                                    int nr_commits)
+                                    int nr_commits,
+                                    struct progress *progress,
+                                    uint64_t *progress_cnt)
 {
        int i, count = 0;
        struct commit **list = commits;
@@ -443,6 +482,7 @@ static void write_graph_chunk_fanout(struct hashfile *f,
                while (count < nr_commits) {
                        if ((*list)->object.oid.hash[0] != i)
                                break;
+                       display_progress(progress, ++*progress_cnt);
                        count++;
                        list++;
                }
@@ -452,12 +492,16 @@ static void write_graph_chunk_fanout(struct hashfile *f,
 }
 
 static void write_graph_chunk_oids(struct hashfile *f, int hash_len,
-                                  struct commit **commits, int nr_commits)
+                                  struct commit **commits, int nr_commits,
+                                  struct progress *progress,
+                                  uint64_t *progress_cnt)
 {
        struct commit **list = commits;
        int count;
-       for (count = 0; count < nr_commits; count++, list++)
+       for (count = 0; count < nr_commits; count++, list++) {
+               display_progress(progress, ++*progress_cnt);
                hashwrite(f, (*list)->object.oid.hash, (int)hash_len);
+       }
 }
 
 static const unsigned char *commit_to_sha1(size_t index, void *table)
@@ -467,7 +511,9 @@ static const unsigned char *commit_to_sha1(size_t index, void *table)
 }
 
 static void write_graph_chunk_data(struct hashfile *f, int hash_len,
-                                  struct commit **commits, int nr_commits)
+                                  struct commit **commits, int nr_commits,
+                                  struct progress *progress,
+                                  uint64_t *progress_cnt)
 {
        struct commit **list = commits;
        struct commit **last = commits + nr_commits;
@@ -477,6 +523,7 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
                struct commit_list *parent;
                int edge_value;
                uint32_t packedDate[2];
+               display_progress(progress, ++*progress_cnt);
 
                parse_commit(*list);
                hashwrite(f, get_commit_tree_oid(*list)->hash, hash_len);
@@ -505,7 +552,7 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
                if (!parent)
                        edge_value = GRAPH_PARENT_NONE;
                else if (parent->next)
-                       edge_value = GRAPH_OCTOPUS_EDGES_NEEDED | num_extra_edges;
+                       edge_value = GRAPH_EXTRA_EDGES_NEEDED | num_extra_edges;
                else {
                        edge_value = sha1_pos(parent->item->object.oid.hash,
                                              commits,
@@ -519,7 +566,7 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
 
                hashwrite_be32(f, edge_value);
 
-               if (edge_value & GRAPH_OCTOPUS_EDGES_NEEDED) {
+               if (edge_value & GRAPH_EXTRA_EDGES_NEEDED) {
                        do {
                                num_extra_edges++;
                                parent = parent->next;
@@ -540,9 +587,11 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
        }
 }
 
-static void write_graph_chunk_large_edges(struct hashfile *f,
+static void write_graph_chunk_extra_edges(struct hashfile *f,
                                          struct commit **commits,
-                                         int nr_commits)
+                                         int nr_commits,
+                                         struct progress *progress,
+                                         uint64_t *progress_cnt)
 {
        struct commit **list = commits;
        struct commit **last = commits + nr_commits;
@@ -550,6 +599,9 @@ static void write_graph_chunk_large_edges(struct hashfile *f,
 
        while (list < last) {
                int num_parents = 0;
+
+               display_progress(progress, ++*progress_cnt);
+
                for (parent = (*list)->parents; num_parents < 3 && parent;
                     parent = parent->next)
                        num_parents++;
@@ -643,15 +695,15 @@ static void add_missing_parents(struct packed_oid_list *oids, struct commit *com
 
 static void close_reachable(struct packed_oid_list *oids, int report_progress)
 {
-       int i, j;
+       int i;
        struct commit *commit;
        struct progress *progress = NULL;
 
        if (report_progress)
                progress = start_delayed_progress(
-                       _("Loading known commits in commit graph"), j = 0);
+                       _("Loading known commits in commit graph"), oids->nr);
        for (i = 0; i < oids->nr; i++) {
-               display_progress(progress, ++j);
+               display_progress(progress, i + 1);
                commit = lookup_commit(the_repository, &oids->list[i]);
                if (commit)
                        commit->object.flags |= UNINTERESTING;
@@ -665,9 +717,9 @@ static void close_reachable(struct packed_oid_list *oids, int report_progress)
         */
        if (report_progress)
                progress = start_delayed_progress(
-                       _("Expanding reachable commits in commit graph"), j = 0);
+                       _("Expanding reachable commits in commit graph"), oids->nr);
        for (i = 0; i < oids->nr; i++) {
-               display_progress(progress, ++j);
+               display_progress(progress, i + 1);
                commit = lookup_commit(the_repository, &oids->list[i]);
 
                if (commit && !parse_commit(commit))
@@ -677,9 +729,9 @@ static void close_reachable(struct packed_oid_list *oids, int report_progress)
 
        if (report_progress)
                progress = start_delayed_progress(
-                       _("Clearing commit marks in commit graph"), j = 0);
+                       _("Clearing commit marks in commit graph"), oids->nr);
        for (i = 0; i < oids->nr; i++) {
-               display_progress(progress, ++j);
+               display_progress(progress, i + 1);
                commit = lookup_commit(the_repository, &oids->list[i]);
 
                if (commit)
@@ -773,12 +825,17 @@ void write_commit_graph(const char *obj_dir,
        int num_extra_edges;
        struct commit_list *parent;
        struct progress *progress = NULL;
+       const unsigned hashsz = the_hash_algo->rawsz;
+       uint64_t progress_cnt = 0;
+       struct strbuf progress_title = STRBUF_INIT;
+       unsigned long approx_nr_objects;
 
        if (!commit_graph_compatible(the_repository))
                return;
 
        oids.nr = 0;
-       oids.alloc = approximate_object_count() / 32;
+       approx_nr_objects = approximate_object_count();
+       oids.alloc = approx_nr_objects / 32;
        oids.progress = NULL;
        oids.progress_done = 0;
 
@@ -808,8 +865,12 @@ void write_commit_graph(const char *obj_dir,
                strbuf_addf(&packname, "%s/pack/", obj_dir);
                dirlen = packname.len;
                if (report_progress) {
-                       oids.progress = start_delayed_progress(
-                               _("Finding commits for commit graph"), 0);
+                       strbuf_addf(&progress_title,
+                                   Q_("Finding commits for commit graph in %d pack",
+                                      "Finding commits for commit graph in %d packs",
+                                      pack_indexes->nr),
+                                   pack_indexes->nr);
+                       oids.progress = start_delayed_progress(progress_title.buf, 0);
                        oids.progress_done = 0;
                }
                for (i = 0; i < pack_indexes->nr; i++) {
@@ -821,19 +882,26 @@ void write_commit_graph(const char *obj_dir,
                                die(_("error adding pack %s"), packname.buf);
                        if (open_pack_index(p))
                                die(_("error opening index for %s"), packname.buf);
-                       for_each_object_in_pack(p, add_packed_commits, &oids, 0);
+                       for_each_object_in_pack(p, add_packed_commits, &oids,
+                                               FOR_EACH_OBJECT_PACK_ORDER);
                        close_pack(p);
                        free(p);
                }
                stop_progress(&oids.progress);
+               strbuf_reset(&progress_title);
                strbuf_release(&packname);
        }
 
        if (commit_hex) {
-               if (report_progress)
-                       progress = start_delayed_progress(
-                               _("Finding commits for commit graph"),
-                               commit_hex->nr);
+               if (report_progress) {
+                       strbuf_addf(&progress_title,
+                                   Q_("Finding commits for commit graph from %d ref",
+                                      "Finding commits for commit graph from %d refs",
+                                      commit_hex->nr),
+                                   commit_hex->nr);
+                       progress = start_delayed_progress(progress_title.buf,
+                                                         commit_hex->nr);
+               }
                for (i = 0; i < commit_hex->nr; i++) {
                        const char *end;
                        struct object_id oid;
@@ -853,25 +921,36 @@ void write_commit_graph(const char *obj_dir,
                        }
                }
                stop_progress(&progress);
+               strbuf_reset(&progress_title);
        }
 
        if (!pack_indexes && !commit_hex) {
                if (report_progress)
                        oids.progress = start_delayed_progress(
-                               _("Finding commits for commit graph"), 0);
-               for_each_packed_object(add_packed_commits, &oids, 0);
+                               _("Finding commits for commit graph among packed objects"),
+                               approx_nr_objects);
+               for_each_packed_object(add_packed_commits, &oids,
+                                      FOR_EACH_OBJECT_PACK_ORDER);
+               if (oids.progress_done < approx_nr_objects)
+                       display_progress(oids.progress, approx_nr_objects);
                stop_progress(&oids.progress);
        }
 
        close_reachable(&oids, report_progress);
 
+       if (report_progress)
+               progress = start_delayed_progress(
+                       _("Counting distinct commits in commit graph"),
+                       oids.nr);
+       display_progress(progress, 0); /* TODO: Measure QSORT() progress */
        QSORT(oids.list, oids.nr, commit_compare);
-
        count_distinct = 1;
        for (i = 1; i < oids.nr; i++) {
+               display_progress(progress, i + 1);
                if (!oideq(&oids.list[i - 1], &oids.list[i]))
                        count_distinct++;
        }
+       stop_progress(&progress);
 
        if (count_distinct >= GRAPH_EDGE_LAST_MASK)
                die(_("the commit graph format cannot write %d commits"), count_distinct);
@@ -881,8 +960,13 @@ void write_commit_graph(const char *obj_dir,
        ALLOC_ARRAY(commits.list, commits.alloc);
 
        num_extra_edges = 0;
+       if (report_progress)
+               progress = start_delayed_progress(
+                       _("Finding extra edges in commit graph"),
+                       oids.nr);
        for (i = 0; i < oids.nr; i++) {
                int num_parents = 0;
+               display_progress(progress, i + 1);
                if (i > 0 && oideq(&oids.list[i - 1], &oids.list[i]))
                        continue;
 
@@ -899,6 +983,7 @@ void write_commit_graph(const char *obj_dir,
                commits.nr++;
        }
        num_chunks = num_extra_edges ? 4 : 3;
+       stop_progress(&progress);
 
        if (commits.nr >= GRAPH_EDGE_LAST_MASK)
                die(_("too many commits to write graph"));
@@ -918,7 +1003,7 @@ void write_commit_graph(const char *obj_dir,
        hashwrite_be32(f, GRAPH_SIGNATURE);
 
        hashwrite_u8(f, GRAPH_VERSION);
-       hashwrite_u8(f, GRAPH_OID_VERSION);
+       hashwrite_u8(f, oid_version());
        hashwrite_u8(f, num_chunks);
        hashwrite_u8(f, 0); /* unused padding byte */
 
@@ -926,15 +1011,15 @@ void write_commit_graph(const char *obj_dir,
        chunk_ids[1] = GRAPH_CHUNKID_OIDLOOKUP;
        chunk_ids[2] = GRAPH_CHUNKID_DATA;
        if (num_extra_edges)
-               chunk_ids[3] = GRAPH_CHUNKID_LARGEEDGES;
+               chunk_ids[3] = GRAPH_CHUNKID_EXTRAEDGES;
        else
                chunk_ids[3] = 0;
        chunk_ids[4] = 0;
 
        chunk_offsets[0] = 8 + (num_chunks + 1) * GRAPH_CHUNKLOOKUP_WIDTH;
        chunk_offsets[1] = chunk_offsets[0] + GRAPH_FANOUT_SIZE;
-       chunk_offsets[2] = chunk_offsets[1] + GRAPH_OID_LEN * commits.nr;
-       chunk_offsets[3] = chunk_offsets[2] + (GRAPH_OID_LEN + 16) * commits.nr;
+       chunk_offsets[2] = chunk_offsets[1] + hashsz * commits.nr;
+       chunk_offsets[3] = chunk_offsets[2] + (hashsz + 16) * commits.nr;
        chunk_offsets[4] = chunk_offsets[3] + 4 * num_extra_edges;
 
        for (i = 0; i <= num_chunks; i++) {
@@ -946,10 +1031,23 @@ void write_commit_graph(const char *obj_dir,
                hashwrite(f, chunk_write, 12);
        }
 
-       write_graph_chunk_fanout(f, commits.list, commits.nr);
-       write_graph_chunk_oids(f, GRAPH_OID_LEN, commits.list, commits.nr);
-       write_graph_chunk_data(f, GRAPH_OID_LEN, commits.list, commits.nr);
-       write_graph_chunk_large_edges(f, commits.list, commits.nr);
+       if (report_progress) {
+               strbuf_addf(&progress_title,
+                           Q_("Writing out commit graph in %d pass",
+                              "Writing out commit graph in %d passes",
+                              num_chunks),
+                           num_chunks);
+               progress = start_delayed_progress(
+                       progress_title.buf,
+                       num_chunks * commits.nr);
+       }
+       write_graph_chunk_fanout(f, commits.list, commits.nr, progress, &progress_cnt);
+       write_graph_chunk_oids(f, hashsz, commits.list, commits.nr, progress, &progress_cnt);
+       write_graph_chunk_data(f, hashsz, commits.list, commits.nr, progress, &progress_cnt);
+       if (num_extra_edges)
+               write_graph_chunk_extra_edges(f, commits.list, commits.nr, progress, &progress_cnt);
+       stop_progress(&progress);
+       strbuf_release(&progress_title);
 
        close_commit_graph(the_repository);
        finalize_hashfile(f, NULL, CSUM_HASH_IN_STREAM | CSUM_FSYNC);
@@ -1034,7 +1132,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
                }
 
                graph_commit = lookup_commit(r, &cur_oid);
-               if (!parse_commit_in_graph_one(g, graph_commit))
+               if (!parse_commit_in_graph_one(r, g, graph_commit))
                        graph_report("failed to parse %s from commit-graph",
                                     oid_to_hex(&cur_oid));
        }
@@ -1070,7 +1168,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
                        continue;
                }
 
-               if (!oideq(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid,
+               if (!oideq(&get_commit_tree_in_graph_one(r, g, graph_commit)->object.oid,
                           get_commit_tree_oid(odb_commit)))
                        graph_report("root tree OID for commit %s in commit-graph is %s != %s",
                                     oid_to_hex(&cur_oid),
index 9db40b4d3aadb75b4dcea5027d07d373bdf169e1..096d8bac340514916c852268ef37c7b97190799a 100644 (file)
@@ -49,11 +49,14 @@ struct commit_graph {
        const uint32_t *chunk_oid_fanout;
        const unsigned char *chunk_oid_lookup;
        const unsigned char *chunk_commit_data;
-       const unsigned char *chunk_large_edges;
+       const unsigned char *chunk_extra_edges;
 };
 
 struct commit_graph *load_commit_graph_one(const char *graph_file);
 
+struct commit_graph *parse_commit_graph(void *graph_map, int fd,
+                                       size_t graph_size);
+
 /*
  * Return 1 if and only if the repository has a commit-graph
  * file and generation numbers are computed in that file.
index d5a39defd3d5144f83d4f48e43e54e1f7f49ab29..3ea174788a4f0229460bad65373e974cc3f87c64 100644 (file)
@@ -30,7 +30,8 @@ static int queue_has_nonstale(struct prio_queue *queue)
 }
 
 /* all input commits in one and twos[] must have been parsed! */
-static struct commit_list *paint_down_to_common(struct commit *one, int n,
+static struct commit_list *paint_down_to_common(struct repository *r,
+                                               struct commit *one, int n,
                                                struct commit **twos,
                                                int min_generation)
 {
@@ -83,7 +84,7 @@ static struct commit_list *paint_down_to_common(struct commit *one, int n,
                        parents = parents->next;
                        if ((p->object.flags & flags) == flags)
                                continue;
-                       if (parse_commit(p))
+                       if (repo_parse_commit(r, p))
                                return NULL;
                        p->object.flags |= flags;
                        prio_queue_put(&queue, p);
@@ -94,7 +95,9 @@ static struct commit_list *paint_down_to_common(struct commit *one, int n,
        return result;
 }
 
-static struct commit_list *merge_bases_many(struct commit *one, int n, struct commit **twos)
+static struct commit_list *merge_bases_many(struct repository *r,
+                                           struct commit *one, int n,
+                                           struct commit **twos)
 {
        struct commit_list *list = NULL;
        struct commit_list *result = NULL;
@@ -109,14 +112,14 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co
                        return commit_list_insert(one, &result);
        }
 
-       if (parse_commit(one))
+       if (repo_parse_commit(r, one))
                return NULL;
        for (i = 0; i < n; i++) {
-               if (parse_commit(twos[i]))
+               if (repo_parse_commit(r, twos[i]))
                        return NULL;
        }
 
-       list = paint_down_to_common(one, n, twos, 0);
+       list = paint_down_to_common(r, one, n, twos, 0);
 
        while (list) {
                struct commit *commit = pop_commit(&list);
@@ -153,7 +156,7 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
        return ret;
 }
 
-static int remove_redundant(struct commit **array, int cnt)
+static int remove_redundant(struct repository *r, struct commit **array, int cnt)
 {
        /*
         * Some commit in the array may be an ancestor of
@@ -171,7 +174,7 @@ static int remove_redundant(struct commit **array, int cnt)
        ALLOC_ARRAY(filled_index, cnt - 1);
 
        for (i = 0; i < cnt; i++)
-               parse_commit(array[i]);
+               repo_parse_commit(r, array[i]);
        for (i = 0; i < cnt; i++) {
                struct commit_list *common;
                uint32_t min_generation = array[i]->generation;
@@ -187,8 +190,8 @@ static int remove_redundant(struct commit **array, int cnt)
                        if (array[j]->generation < min_generation)
                                min_generation = array[j]->generation;
                }
-               common = paint_down_to_common(array[i], filled, work,
-                                             min_generation);
+               common = paint_down_to_common(r, array[i], filled,
+                                             work, min_generation);
                if (array[i]->object.flags & PARENT2)
                        redundant[i] = 1;
                for (j = 0; j < filled; j++)
@@ -213,7 +216,8 @@ static int remove_redundant(struct commit **array, int cnt)
        return filled;
 }
 
-static struct commit_list *get_merge_bases_many_0(struct commit *one,
+static struct commit_list *get_merge_bases_many_0(struct repository *r,
+                                                 struct commit *one,
                                                  int n,
                                                  struct commit **twos,
                                                  int cleanup)
@@ -223,7 +227,7 @@ static struct commit_list *get_merge_bases_many_0(struct commit *one,
        struct commit_list *result;
        int cnt, i;
 
-       result = merge_bases_many(one, n, twos);
+       result = merge_bases_many(r, one, n, twos);
        for (i = 0; i < n; i++) {
                if (one == twos[i])
                        return result;
@@ -246,7 +250,7 @@ static struct commit_list *get_merge_bases_many_0(struct commit *one,
        clear_commit_marks(one, all_flags);
        clear_commit_marks_many(n, twos, all_flags);
 
-       cnt = remove_redundant(rslt, cnt);
+       cnt = remove_redundant(r, rslt, cnt);
        result = NULL;
        for (i = 0; i < cnt; i++)
                commit_list_insert_by_date(rslt[i], &result);
@@ -254,23 +258,27 @@ static struct commit_list *get_merge_bases_many_0(struct commit *one,
        return result;
 }
 
-struct commit_list *get_merge_bases_many(struct commit *one,
-                                        int n,
-                                        struct commit **twos)
+struct commit_list *repo_get_merge_bases_many(struct repository *r,
+                                             struct commit *one,
+                                             int n,
+                                             struct commit **twos)
 {
-       return get_merge_bases_many_0(one, n, twos, 1);
+       return get_merge_bases_many_0(r, one, n, twos, 1);
 }
 
-struct commit_list *get_merge_bases_many_dirty(struct commit *one,
-                                              int n,
-                                              struct commit **twos)
+struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
+                                                   struct commit *one,
+                                                   int n,
+                                                   struct commit **twos)
 {
-       return get_merge_bases_many_0(one, n, twos, 0);
+       return get_merge_bases_many_0(r, one, n, twos, 0);
 }
 
-struct commit_list *get_merge_bases(struct commit *one, struct commit *two)
+struct commit_list *repo_get_merge_bases(struct repository *r,
+                                        struct commit *one,
+                                        struct commit *two)
 {
-       return get_merge_bases_many_0(one, 1, &two, 1);
+       return get_merge_bases_many_0(r, one, 1, &two, 1);
 }
 
 /*
@@ -304,16 +312,17 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
 /*
  * Is "commit" an ancestor of one of the "references"?
  */
-int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference)
+int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
+                            int nr_reference, struct commit **reference)
 {
        struct commit_list *bases;
        int ret = 0, i;
        uint32_t min_generation = GENERATION_NUMBER_INFINITY;
 
-       if (parse_commit(commit))
+       if (repo_parse_commit(r, commit))
                return ret;
        for (i = 0; i < nr_reference; i++) {
-               if (parse_commit(reference[i]))
+               if (repo_parse_commit(r, reference[i]))
                        return ret;
                if (reference[i]->generation < min_generation)
                        min_generation = reference[i]->generation;
@@ -322,7 +331,9 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
        if (commit->generation > min_generation)
                return ret;
 
-       bases = paint_down_to_common(commit, nr_reference, reference, commit->generation);
+       bases = paint_down_to_common(r, commit,
+                                    nr_reference, reference,
+                                    commit->generation);
        if (commit->object.flags & PARENT2)
                ret = 1;
        clear_commit_marks(commit, all_flags);
@@ -334,9 +345,11 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
 /*
  * Is "commit" an ancestor of (i.e. reachable from) the "reference"?
  */
-int in_merge_bases(struct commit *commit, struct commit *reference)
+int repo_in_merge_bases(struct repository *r,
+                       struct commit *commit,
+                       struct commit *reference)
 {
-       return in_merge_bases_many(commit, 1, &reference);
+       return repo_in_merge_bases_many(r, commit, 1, &reference);
 }
 
 struct commit_list *reduce_heads(struct commit_list *heads)
@@ -365,7 +378,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)
                        p->item->object.flags &= ~STALE;
                }
        }
-       num_head = remove_redundant(array, num_head);
+       num_head = remove_redundant(the_repository, array, num_head);
        for (i = 0; i < num_head; i++)
                tail = &commit_list_insert(array[i], tail)->next;
        free(array);
index fb8082a2ece94a94cf2f9a55ba95950caa41a914..99a43e8b64fc803d7b7f4d09d11c2ec31fdb0a76 100644 (file)
@@ -9,21 +9,35 @@ struct ref_filter;
 struct object_id;
 struct object_array;
 
-struct commit_list *get_merge_bases_many(struct commit *one,
-                                        int n,
-                                        struct commit **twos);
-struct commit_list *get_merge_bases_many_dirty(struct commit *one,
-                                              int n,
-                                              struct commit **twos);
-struct commit_list *get_merge_bases(struct commit *one, struct commit *two);
-struct commit_list *get_octopus_merge_bases(struct commit_list *in);
-
+struct commit_list *repo_get_merge_bases(struct repository *r,
+                                        struct commit *rev1,
+                                        struct commit *rev2);
+struct commit_list *repo_get_merge_bases_many(struct repository *r,
+                                             struct commit *one, int n,
+                                             struct commit **twos);
 /* To be used only when object flags after this call no longer matter */
-struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n, struct commit **twos);
+struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
+                                                   struct commit *one, int n,
+                                                   struct commit **twos);
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define get_merge_bases(r1, r2)           repo_get_merge_bases(the_repository, r1, r2)
+#define get_merge_bases_many(one, n, two) repo_get_merge_bases_many(the_repository, one, n, two)
+#define get_merge_bases_many_dirty(one, n, twos) repo_get_merge_bases_many_dirty(the_repository, one, n, twos)
+#endif
+
+struct commit_list *get_octopus_merge_bases(struct commit_list *in);
 
 int is_descendant_of(struct commit *commit, struct commit_list *with_commit);
-int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference);
-int in_merge_bases(struct commit *commit, struct commit *reference);
+int repo_in_merge_bases(struct repository *r,
+                       struct commit *commit,
+                       struct commit *reference);
+int repo_in_merge_bases_many(struct repository *r,
+                            struct commit *commit,
+                            int nr_reference, struct commit **reference);
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define in_merge_bases(c1, c2) repo_in_merge_bases(the_repository, c1, c2)
+#define in_merge_bases_many(c1, n, cs) repo_in_merge_bases_many(the_repository, c1, n, cs)
+#endif
 
 /*
  * Takes a list of commits and returns a new list where those
index d13a7bc3746406bdaf0bda0975c25b40111afe47..a5333c7ac6c373a13f9298b36be5ff94a90a3e3f 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -299,13 +299,15 @@ const void *get_cached_commit_buffer(struct repository *r, const struct commit *
        return v->buffer;
 }
 
-const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
+const void *repo_get_commit_buffer(struct repository *r,
+                                  const struct commit *commit,
+                                  unsigned long *sizep)
 {
-       const void *ret = get_cached_commit_buffer(the_repository, commit, sizep);
+       const void *ret = get_cached_commit_buffer(r, commit, sizep);
        if (!ret) {
                enum object_type type;
                unsigned long size;
-               ret = read_object_file(&commit->object.oid, &type, &size);
+               ret = repo_read_object_file(r, &commit->object.oid, &type, &size);
                if (!ret)
                        die("cannot read commit object %s",
                            oid_to_hex(&commit->object.oid));
@@ -318,18 +320,20 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
        return ret;
 }
 
-void unuse_commit_buffer(const struct commit *commit, const void *buffer)
+void repo_unuse_commit_buffer(struct repository *r,
+                             const struct commit *commit,
+                             const void *buffer)
 {
        struct commit_buffer *v = buffer_slab_peek(
-               the_repository->parsed_objects->buffer_slab, commit);
+               r->parsed_objects->buffer_slab, commit);
        if (!(v && v->buffer == buffer))
                free((void *)buffer);
 }
 
-void free_commit_buffer(struct commit *commit)
+void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
 {
        struct commit_buffer *v = buffer_slab_peek(
-               the_repository->parsed_objects->buffer_slab, commit);
+               pool->buffer_slab, commit);
        if (v) {
                FREE_AND_NULL(v->buffer);
                v->size = 0;
@@ -352,13 +356,12 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)
        return &get_commit_tree(commit)->object.oid;
 }
 
-void release_commit_memory(struct commit *c)
+void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)
 {
        c->maybe_tree = NULL;
        c->index = 0;
-       free_commit_buffer(c);
+       free_commit_buffer(pool, c);
        free_commit_list(c->parents);
-       /* TODO: what about commit->util? */
 
        c->object.parsed = 0;
 }
@@ -445,7 +448,10 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
        return 0;
 }
 
-int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_commit_graph)
+int repo_parse_commit_internal(struct repository *r,
+                              struct commit *item,
+                              int quiet_on_missing,
+                              int use_commit_graph)
 {
        enum object_type type;
        void *buffer;
@@ -456,9 +462,9 @@ int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_com
                return -1;
        if (item->object.parsed)
                return 0;
-       if (use_commit_graph && parse_commit_in_graph(the_repository, item))
+       if (use_commit_graph && parse_commit_in_graph(r, item))
                return 0;
-       buffer = read_object_file(&item->object.oid, &type, &size);
+       buffer = repo_read_object_file(r, &item->object.oid, &type, &size);
        if (!buffer)
                return quiet_on_missing ? -1 :
                        error("Could not read %s",
@@ -469,18 +475,19 @@ int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_com
                             oid_to_hex(&item->object.oid));
        }
 
-       ret = parse_commit_buffer(the_repository, item, buffer, size, 0);
+       ret = parse_commit_buffer(r, item, buffer, size, 0);
        if (save_commit_buffer && !ret) {
-               set_commit_buffer(the_repository, item, buffer, size);
+               set_commit_buffer(r, item, buffer, size);
                return 0;
        }
        free(buffer);
        return ret;
 }
 
-int parse_commit_gently(struct commit *item, int quiet_on_missing)
+int repo_parse_commit_gently(struct repository *r,
+                            struct commit *item, int quiet_on_missing)
 {
-       return parse_commit_internal(item, quiet_on_missing, 1);
+       return repo_parse_commit_internal(r, item, quiet_on_missing, 1);
 }
 
 void parse_commit_or_die(struct commit *item)
index 98664536cb82c65f04a1742c3e5c1e269afc9493..42728c2906608a9f4f1724e02b16d913b74b8728 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -80,12 +80,21 @@ struct commit *lookup_commit_reference_by_name(const char *name);
 struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name);
 
 int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size, int check_graph);
-int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_commit_graph);
-int parse_commit_gently(struct commit *item, int quiet_on_missing);
-static inline int parse_commit(struct commit *item)
+int repo_parse_commit_internal(struct repository *r, struct commit *item,
+                              int quiet_on_missing, int use_commit_graph);
+int repo_parse_commit_gently(struct repository *r,
+                            struct commit *item,
+                            int quiet_on_missing);
+static inline int repo_parse_commit(struct repository *r, struct commit *item)
 {
-       return parse_commit_gently(item, 0);
+       return repo_parse_commit_gently(r, item, 0);
 }
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define parse_commit_internal(item, quiet, use) repo_parse_commit_internal(the_repository, item, quiet, use)
+#define parse_commit_gently(item, quiet) repo_parse_commit_gently(the_repository, item, quiet)
+#define parse_commit(item) repo_parse_commit(the_repository, item)
+#endif
+
 void parse_commit_or_die(struct commit *item);
 
 struct buffer_slab;
@@ -109,7 +118,12 @@ const void *get_cached_commit_buffer(struct repository *, const struct commit *,
  * from disk. The resulting memory should not be modified, and must be given
  * to unuse_commit_buffer when the caller is done.
  */
-const void *get_commit_buffer(const struct commit *, unsigned long *size);
+const void *repo_get_commit_buffer(struct repository *r,
+                                  const struct commit *,
+                                  unsigned long *size);
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define get_commit_buffer(c, s) repo_get_commit_buffer(the_repository, c, s)
+#endif
 
 /*
  * Tell the commit subsytem that we are done with a particular commit buffer.
@@ -117,12 +131,17 @@ const void *get_commit_buffer(const struct commit *, unsigned long *size);
  * from an earlier call to get_commit_buffer.  The buffer may or may not be
  * freed by this call; callers should not access the memory afterwards.
  */
-void unuse_commit_buffer(const struct commit *, const void *buffer);
+void repo_unuse_commit_buffer(struct repository *r,
+                             const struct commit *,
+                             const void *buffer);
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define unuse_commit_buffer(c, b) repo_unuse_commit_buffer(the_repository, c, b)
+#endif
 
 /*
  * Free any cached object buffer associated with the commit.
  */
-void free_commit_buffer(struct commit *);
+void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
 
 struct tree *get_commit_tree(const struct commit *);
 struct object_id *get_commit_tree_oid(const struct commit *);
@@ -131,7 +150,7 @@ struct object_id *get_commit_tree_oid(const struct commit *);
  * Release memory related to a commit, including the parent list and
  * any cached object buffer.
  */
-void release_commit_memory(struct commit *c);
+void release_commit_memory(struct parsed_object_pool *pool, struct commit *c);
 
 /*
  * Disassociate any cached object buffer from the commit, but do not free it.
@@ -162,6 +181,14 @@ extern int has_non_ascii(const char *text);
 extern const char *logmsg_reencode(const struct commit *commit,
                                   char **commit_encoding,
                                   const char *output_encoding);
+const char *repo_logmsg_reencode(struct repository *r,
+                                const struct commit *commit,
+                                char **commit_encoding,
+                                const char *output_encoding);
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define logmsg_reencode(c, enc, out) repo_logmsg_reencode(the_repository, c, enc, out)
+#endif
+
 extern const char *skip_blank_lines(const char *msg);
 
 /** Removes the first commit from a list sorted by date, and adds all
index b459e1a291ab0fe906c9a53a0fbcc61ad2c7e153..0af86840197deb3b0b9d442e3e5236170c31a4de 100644 (file)
@@ -7,6 +7,7 @@
 #include "../cache.h"
 #include "win32/lazyload.h"
 #include "../config.h"
+#include "dir.h"
 
 #define HCAST(type, handle) ((type)(intptr_t)handle)
 
@@ -1031,7 +1032,7 @@ char *mingw_getcwd(char *pointer, int len)
  * See "Parsing C++ Command-Line Arguments" at Microsoft's Docs:
  * https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments
  */
-static const char *quote_arg(const char *arg)
+static const char *quote_arg_msvc(const char *arg)
 {
        /* count chars to quote */
        int len = 0, n = 0;
@@ -1086,6 +1087,37 @@ static const char *quote_arg(const char *arg)
        return q;
 }
 
+#include "quote.h"
+
+static const char *quote_arg_msys2(const char *arg)
+{
+       struct strbuf buf = STRBUF_INIT;
+       const char *p2 = arg, *p;
+
+       for (p = arg; *p; p++) {
+               int ws = isspace(*p);
+               if (!ws && *p != '\\' && *p != '"' && *p != '{')
+                       continue;
+               if (!buf.len)
+                       strbuf_addch(&buf, '"');
+               if (p != p2)
+                       strbuf_add(&buf, p2, p - p2);
+               if (!ws && *p != '{')
+                       strbuf_addch(&buf, '\\');
+               p2 = p;
+       }
+
+       if (p == arg)
+               strbuf_addch(&buf, '"');
+       else if (!buf.len)
+               return arg;
+       else
+               strbuf_add(&buf, p2, p - p2),
+
+       strbuf_addch(&buf, '"');
+       return strbuf_detach(&buf, 0);
+}
+
 static const char *parse_interpreter(const char *cmd)
 {
        static char buf[100];
@@ -1317,6 +1349,47 @@ struct pinfo_t {
 static struct pinfo_t *pinfo = NULL;
 CRITICAL_SECTION pinfo_cs;
 
+/* Used to match and chomp off path components */
+static inline int match_last_path_component(const char *path, size_t *len,
+                                           const char *component)
+{
+       size_t component_len = strlen(component);
+       if (*len < component_len + 1 ||
+           !is_dir_sep(path[*len - component_len - 1]) ||
+           fspathncmp(path + *len - component_len, component, component_len))
+               return 0;
+       *len -= component_len + 1;
+       /* chomp off repeated dir separators */
+       while (*len > 0 && is_dir_sep(path[*len - 1]))
+               (*len)--;
+       return 1;
+}
+
+static int is_msys2_sh(const char *cmd)
+{
+       if (cmd && !strcmp(cmd, "sh")) {
+               static int ret = -1;
+               char *p;
+
+               if (ret >= 0)
+                       return ret;
+
+               p = path_lookup(cmd, 0);
+               if (!p)
+                       ret = 0;
+               else {
+                       size_t len = strlen(p);
+
+                       ret = match_last_path_component(p, &len, "sh.exe") &&
+                               match_last_path_component(p, &len, "bin") &&
+                               match_last_path_component(p, &len, "usr");
+                       free(p);
+               }
+               return ret;
+       }
+       return 0;
+}
+
 static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
                              const char *dir,
                              int prepend_cmd, int fhin, int fhout, int fherr)
@@ -1328,6 +1401,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
        unsigned flags = CREATE_UNICODE_ENVIRONMENT;
        BOOL ret;
        HANDLE cons;
+       const char *(*quote_arg)(const char *arg) =
+               is_msys2_sh(*argv) ? quote_arg_msys2 : quote_arg_msvc;
 
        do_unset_environment_variables();
 
index 4d1d95beeb509b3bb159b4eaadf20deeb498e73a..27cd5c1ea1f9b3885740b25a161d152b515b43b6 100644 (file)
@@ -112,15 +112,15 @@ compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0);
 
 # define CALL_CHUNKFUN(h, size) \
   (((h) -> use_extra_arg) \
-   ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
-   : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size)))
+   ? (*(h)->chunkfun.extra) ((h)->extra_arg, (size)) \
+   : (*(h)->chunkfun.plain) ((size)))
 
 # define CALL_FREEFUN(h, old_chunk) \
   do { \
     if ((h) -> use_extra_arg) \
-      (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
+      (*(h)->freefun.extra) ((h)->extra_arg, (old_chunk)); \
     else \
-      (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
+      (*(h)->freefun.plain) ((old_chunk)); \
   } while (0)
 
 \f
@@ -159,8 +159,8 @@ _obstack_begin (struct obstack *h,
       size = 4096 - extra;
     }
 
-  h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun;
-  h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
+  h->chunkfun.plain = chunkfun;
+  h->freefun.plain = freefun;
   h->chunk_size = size;
   h->alignment_mask = alignment - 1;
   h->use_extra_arg = 0;
@@ -206,8 +206,9 @@ _obstack_begin_1 (struct obstack *h, int size, int alignment,
       size = 4096 - extra;
     }
 
-  h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
-  h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
+  h->chunkfun.extra = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
+  h->freefun.extra = (void (*) (void *, struct _obstack_chunk *)) freefun;
+
   h->chunk_size = size;
   h->alignment_mask = alignment - 1;
   h->extra_arg = arg;
index 6bc24b76445686b2ef55fe5461273e4c5b2cd4f7..ced94d01180a66b2f2d471c1ebaef4eec07e6c49 100644 (file)
@@ -160,11 +160,15 @@ struct obstack            /* control current object in current chunk */
     void *tempptr;
   } temp;                      /* Temporary for some macros.  */
   int   alignment_mask;                /* Mask of alignment for each object. */
-  /* These prototypes vary based on `use_extra_arg', and we use
-     casts to the prototypeless function type in all assignments,
-     but having prototypes here quiets -Wstrict-prototypes.  */
-  struct _obstack_chunk *(*chunkfun) (void *, long);
-  void (*freefun) (void *, struct _obstack_chunk *);
+  /* These prototypes vary based on `use_extra_arg'. */
+  union {
+    void *(*plain) (long);
+    struct _obstack_chunk *(*extra) (void *, long);
+  } chunkfun;
+  union {
+    void (*plain) (void *);
+    void (*extra) (void *, struct _obstack_chunk *);
+  } freefun;
   void *extra_arg;             /* first arg for chunk alloc/dealloc funcs */
   unsigned use_extra_arg:1;    /* chunk alloc/dealloc funcs take extra arg */
   unsigned maybe_empty_object:1;/* There is a possibility that the current
@@ -235,10 +239,10 @@ extern void (*obstack_alloc_failed_handler) (void);
                    (void (*) (void *, void *)) (freefun), (arg))
 
 #define obstack_chunkfun(h, newchunkfun) \
-  ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))
+  ((h)->chunkfun.extra = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))
 
 #define obstack_freefun(h, newfreefun) \
-  ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
+  ((h)->freefun.extra = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
 
 #define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar))
 
index de61c15d3483fc4a9e8e163bd7cfa5280996c61a..136250fbf6c4f7e707c25dba936e2effebd847f2 100644 (file)
@@ -79,7 +79,7 @@ void precompose_argv(int argc, const char **argv)
                size_t namelen;
                oldarg = argv[i];
                if (has_non_ascii(oldarg, (size_t)-1, &namelen)) {
-                       newarg = reencode_string_iconv(oldarg, namelen, ic_precompose, NULL);
+                       newarg = reencode_string_iconv(oldarg, namelen, ic_precompose, 0, NULL);
                        if (newarg)
                                argv[i] = newarg;
                }
index ff521eb27ad243b27c7bd95f3ad7a1b777a4ae00..24ad1a985400168e33778781d01d6e9e6c6ededf 100644 (file)
--- a/config.c
+++ b/config.c
@@ -2565,7 +2565,6 @@ static ssize_t write_pair(int fd, const char *key, const char *value,
  * entry (which all are to be removed).
  */
 static void maybe_remove_section(struct config_store_data *store,
-                                const char *contents,
                                 size_t *begin_offset, size_t *end_offset,
                                 int *seen_ptr)
 {
@@ -2850,7 +2849,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
                                replace_end = store.parsed[j].end;
                                copy_end = store.parsed[j].begin;
                                if (!value)
-                                       maybe_remove_section(&store, contents,
+                                       maybe_remove_section(&store,
                                                             &copy_end,
                                                             &replace_end, &i);
                                /*
index 24281b608284ee74b262237c467ff054874d8a8e..4813f005ab05279a72ef2894cfae8887965d9640 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -296,7 +296,6 @@ struct ref **get_remote_heads(struct packet_reader *reader,
        struct ref **orig_list = list;
        int len = 0;
        enum get_remote_heads_state state = EXPECTING_FIRST_REF;
-       const char *arg;
 
        *list = NULL;
 
@@ -306,8 +305,6 @@ struct ref **get_remote_heads(struct packet_reader *reader,
                        die_initial_contact(1);
                case PACKET_READ_NORMAL:
                        len = reader->pktlen;
-                       if (len > 4 && skip_prefix(reader->line, "ERR ", &arg))
-                               die(_("remote error: %s"), arg);
                        break;
                case PACKET_READ_FLUSH:
                        state = EXPECTING_DONE;
index 6a7cf3e02da832b3a2829178b968b57f3b80d081..3e536a9834b62353f984f04e0051e20aa5378f48 100644 (file)
@@ -86,36 +86,6 @@ struct object_id OID;
 - hashcmp(OID.hash, OIDPTR->hash)
 + oidcmp(&OID, OIDPTR)
 
-@@
-struct object_id OID1, OID2;
-@@
-- hashcpy(OID1.hash, OID2.hash)
-+ oidcpy(&OID1, &OID2)
-
-@@
-identifier f != oidcpy;
-struct object_id *OIDPTR1;
-struct object_id *OIDPTR2;
-@@
-  f(...) {<...
-- hashcpy(OIDPTR1->hash, OIDPTR2->hash)
-+ oidcpy(OIDPTR1, OIDPTR2)
-  ...>}
-
-@@
-struct object_id *OIDPTR;
-struct object_id OID;
-@@
-- hashcpy(OIDPTR->hash, OID.hash)
-+ oidcpy(OIDPTR, &OID)
-
-@@
-struct object_id *OIDPTR;
-struct object_id OID;
-@@
-- hashcpy(OID.hash, OIDPTR->hash)
-+ oidcpy(&OID, OIDPTR)
-
 @@
 struct object_id *OIDPTR1;
 struct object_id *OIDPTR2;
index e34eada1ad52933230c7fcace595677747f9e1d6..d9ada69b4323f2e9611aa6add5b21a77e622a7c8 100644 (file)
@@ -12,6 +12,36 @@ constant fmt !~ "%";
 )
   );
 
+@@
+expression E;
+struct strbuf SB;
+format F =~ "s";
+@@
+- strbuf_addf(E, "%@F@", SB.buf);
++ strbuf_addbuf(E, &SB);
+
+@@
+expression E;
+struct strbuf *SBP;
+format F =~ "s";
+@@
+- strbuf_addf(E, "%@F@", SBP->buf);
++ strbuf_addbuf(E, SBP);
+
+@@
+expression E;
+struct strbuf SB;
+@@
+- strbuf_addstr(E, SB.buf);
++ strbuf_addbuf(E, &SB);
+
+@@
+expression E;
+struct strbuf *SBP;
+@@
+- strbuf_addstr(E, SBP->buf);
++ strbuf_addbuf(E, SBP);
+
 @@
 expression E1, E2;
 format F =~ "s";
diff --git a/contrib/coccinelle/the_repository.pending.cocci b/contrib/coccinelle/the_repository.pending.cocci
new file mode 100644 (file)
index 0000000..2ee702e
--- /dev/null
@@ -0,0 +1,144 @@
+// This file is used for the ongoing refactoring of
+// bringing the index or repository struct in all of
+// our code base.
+
+@@
+expression E;
+expression F;
+expression G;
+@@
+- read_object_file(
++ repo_read_object_file(the_repository,
+  E, F, G)
+
+@@
+expression E;
+@@
+- has_sha1_file(
++ repo_has_sha1_file(the_repository,
+  E)
+
+@@
+expression E;
+expression F;
+@@
+- has_sha1_file_with_flags(
++ repo_has_sha1_file_with_flags(the_repository,
+  E)
+
+@@
+expression E;
+@@
+- has_object_file(
++ repo_has_object_file(the_repository,
+  E)
+
+@@
+expression E;
+expression F;
+@@
+- has_object_file_with_flags(
++ repo_has_object_file_with_flags(the_repository,
+  E)
+
+@@
+expression E;
+expression F;
+expression G;
+@@
+- parse_commit_internal(
++ repo_parse_commit_internal(the_repository,
+  E, F, G)
+
+@@
+expression E;
+expression F;
+@@
+- parse_commit_gently(
++ repo_parse_commit_gently(the_repository,
+  E, F)
+
+@@
+expression E;
+@@
+- parse_commit(
++ repo_parse_commit(the_repository,
+  E)
+
+@@
+expression E;
+expression F;
+@@
+- get_merge_bases(
++ repo_get_merge_bases(the_repository,
+  E, F);
+
+@@
+expression E;
+expression F;
+expression G;
+@@
+- get_merge_bases_many(
++ repo_get_merge_bases_many(the_repository,
+  E, F, G);
+
+@@
+expression E;
+expression F;
+expression G;
+@@
+- get_merge_bases_many_dirty(
++ repo_get_merge_bases_many_dirty(the_repository,
+  E, F, G);
+
+@@
+expression E;
+expression F;
+@@
+- in_merge_bases(
++ repo_in_merge_bases(the_repository,
+  E, F);
+
+@@
+expression E;
+expression F;
+expression G;
+@@
+- in_merge_bases_many(
++ repo_in_merge_bases_many(the_repository,
+  E, F, G);
+
+@@
+expression E;
+expression F;
+@@
+- get_commit_buffer(
++ repo_get_commit_buffer(the_repository,
+  E, F);
+
+@@
+expression E;
+expression F;
+@@
+- unuse_commit_buffer(
++ repo_unuse_commit_buffer(the_repository,
+  E, F);
+
+@@
+expression E;
+expression F;
+expression G;
+@@
+- logmsg_reencode(
++ repo_logmsg_reencode(the_repository,
+  E, F, G);
+
+@@
+expression E;
+expression F;
+expression G;
+expression H;
+@@
+- format_commit_message(
++ repo_format_commit_message(the_repository,
+  E, F, G, H);
index 0d89ae7c2302a4bff3a6fdcb4a7015a81eeb8025..5d0307fc1004f215c48a6f653e21da41bee71baa 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "object-store.h"
@@ -92,7 +91,7 @@ static void gather_stats(const char *buf, unsigned long size, struct text_stat *
  * The same heuristics as diff.c::mmfile_is_binary()
  * We treat files with bare CR as binary
  */
-static int convert_is_binary(unsigned long size, const struct text_stat *stats)
+static int convert_is_binary(const struct text_stat *stats)
 {
        if (stats->lonecr)
                return 1;
@@ -110,7 +109,7 @@ static unsigned int gather_convert_stats(const char *data, unsigned long size)
        if (!data || !size)
                return 0;
        gather_stats(data, size, &stats);
-       if (convert_is_binary(size, &stats))
+       if (convert_is_binary(&stats))
                ret |= CONVERT_STAT_BITS_BIN;
        if (stats.crlf)
                ret |= CONVERT_STAT_BITS_TXT_CRLF;
@@ -245,7 +244,7 @@ static int has_crlf_in_index(const struct index_state *istate, const char *path)
        return has_crlf;
 }
 
-static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats,
+static int will_convert_lf_to_crlf(struct text_stat *stats,
                                   enum crlf_action crlf_action)
 {
        if (output_eol(crlf_action) != EOL_CRLF)
@@ -260,7 +259,7 @@ static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats,
                if (stats->lonecr || stats->crlf)
                        return 0;
 
-               if (convert_is_binary(len, stats))
+               if (convert_is_binary(stats))
                        return 0;
        }
        return 1;
@@ -527,7 +526,7 @@ static int crlf_to_git(const struct index_state *istate,
        convert_crlf_into_lf = !!stats.crlf;
 
        if (crlf_action == CRLF_AUTO || crlf_action == CRLF_AUTO_INPUT || crlf_action == CRLF_AUTO_CRLF) {
-               if (convert_is_binary(len, &stats))
+               if (convert_is_binary(&stats))
                        return 0;
                /*
                 * If the file in the index has any CR in it, do not
@@ -549,7 +548,7 @@ static int crlf_to_git(const struct index_state *istate,
                        new_stats.crlf = 0;
                }
                /* simulate "git checkout" */
-               if (will_convert_lf_to_crlf(len, &new_stats, crlf_action)) {
+               if (will_convert_lf_to_crlf(&new_stats, crlf_action)) {
                        new_stats.crlf += new_stats.lonelf;
                        new_stats.lonelf = 0;
                }
@@ -591,7 +590,7 @@ static int crlf_to_git(const struct index_state *istate,
        return 1;
 }
 
-static int crlf_to_worktree(const char *path, const char *src, size_t len,
+static int crlf_to_worktree(const char *src, size_t len,
                            struct strbuf *buf, enum crlf_action crlf_action)
 {
        char *to_free = NULL;
@@ -601,7 +600,7 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,
                return 0;
 
        gather_stats(src, len, &stats);
-       if (!will_convert_lf_to_crlf(len, &stats, crlf_action))
+       if (!will_convert_lf_to_crlf(&stats, crlf_action))
                return 0;
 
        /* are we "faking" in place editing ? */
@@ -1091,7 +1090,7 @@ static int count_ident(const char *cp, unsigned long size)
        return cnt;
 }
 
-static int ident_to_git(const char *path, const char *src, size_t len,
+static int ident_to_git(const char *src, size_t len,
                        struct strbuf *buf, int ident)
 {
        char *dst, *dollar;
@@ -1135,7 +1134,7 @@ static int ident_to_git(const char *path, const char *src, size_t len,
        return 1;
 }
 
-static int ident_to_worktree(const char *path, const char *src, size_t len,
+static int ident_to_worktree(const char *src, size_t len,
                             struct strbuf *buf, int ident)
 {
        struct object_id oid;
@@ -1416,7 +1415,7 @@ int convert_to_git(const struct index_state *istate,
                        len = dst->len;
                }
        }
-       return ret | ident_to_git(path, src, len, dst, ca.ident);
+       return ret | ident_to_git(src, len, dst, ca.ident);
 }
 
 void convert_to_git_filter_fd(const struct index_state *istate,
@@ -1434,7 +1433,7 @@ void convert_to_git_filter_fd(const struct index_state *istate,
 
        encode_to_git(path, dst->buf, dst->len, dst, ca.working_tree_encoding, conv_flags);
        crlf_to_git(istate, path, dst->buf, dst->len, dst, ca.crlf_action, conv_flags);
-       ident_to_git(path, dst->buf, dst->len, dst, ca.ident);
+       ident_to_git(dst->buf, dst->len, dst, ca.ident);
 }
 
 static int convert_to_working_tree_internal(const struct index_state *istate,
@@ -1447,7 +1446,7 @@ static int convert_to_working_tree_internal(const struct index_state *istate,
 
        convert_attrs(istate, &ca, path);
 
-       ret |= ident_to_worktree(path, src, len, dst, ca.ident);
+       ret |= ident_to_worktree(src, len, dst, ca.ident);
        if (ret) {
                src = dst->buf;
                len = dst->len;
@@ -1458,7 +1457,7 @@ static int convert_to_working_tree_internal(const struct index_state *istate,
         * support smudge).  The filters might expect CRLFs.
         */
        if ((ca.drv && (ca.drv->smudge || ca.drv->process)) || !normalizing) {
-               ret |= crlf_to_worktree(path, src, len, dst, ca.crlf_action);
+               ret |= crlf_to_worktree(src, len, dst, ca.crlf_action);
                if (ret) {
                        src = dst->buf;
                        len = dst->len;
diff --git a/date.c b/date.c
index 9bc15df6f9dfa635fe91760914473d953b7c970b..9c5870e102951ed25f5def2103dab15bf8ed5c99 100644 (file)
--- a/date.c
+++ b/date.c
@@ -77,22 +77,16 @@ static struct tm *time_to_tm_local(timestamp_t time)
 }
 
 /*
- * What value of "tz" was in effect back then at "time" in the
- * local timezone?
+ * Fill in the localtime 'struct tm' for the supplied time,
+ * and return the local tz.
  */
-static int local_tzoffset(timestamp_t time)
+static int local_time_tzoffset(time_t t, struct tm *tm)
 {
-       time_t t, t_local;
-       struct tm tm;
+       time_t t_local;
        int offset, eastwest;
 
-       if (date_overflows(time))
-               die("Timestamp too large for this system: %"PRItime, time);
-
-       t = (time_t)time;
-       localtime_r(&t, &tm);
-       t_local = tm_to_time_t(&tm);
-
+       localtime_r(&t, tm);
+       t_local = tm_to_time_t(tm);
        if (t_local == -1)
                return 0; /* error; just use +0000 */
        if (t_local < t) {
@@ -107,9 +101,36 @@ static int local_tzoffset(timestamp_t time)
        return offset * eastwest;
 }
 
-void show_date_relative(timestamp_t time, int tz,
-                              const struct timeval *now,
-                              struct strbuf *timebuf)
+/*
+ * What value of "tz" was in effect back then at "time" in the
+ * local timezone?
+ */
+static int local_tzoffset(timestamp_t time)
+{
+       struct tm tm;
+
+       if (date_overflows(time))
+               die("Timestamp too large for this system: %"PRItime, time);
+
+       return local_time_tzoffset((time_t)time, &tm);
+}
+
+static void get_time(struct timeval *now)
+{
+       const char *x;
+
+       x = getenv("GIT_TEST_DATE_NOW");
+       if (x) {
+               now->tv_sec = atoi(x);
+               now->tv_usec = 0;
+       }
+       else
+               gettimeofday(now, NULL);
+}
+
+void show_date_relative(timestamp_t time,
+                       const struct timeval *now,
+                       struct strbuf *timebuf)
 {
        timestamp_t diff;
        if (now->tv_sec < time) {
@@ -191,9 +212,80 @@ struct date_mode *date_mode_from_type(enum date_mode_type type)
        return &mode;
 }
 
+static void show_date_normal(struct strbuf *buf, timestamp_t time, struct tm *tm, int tz, struct tm *human_tm, int human_tz, int local)
+{
+       struct {
+               unsigned int    year:1,
+                               date:1,
+                               wday:1,
+                               time:1,
+                               seconds:1,
+                               tz:1;
+       } hide = { 0 };
+
+       hide.tz = local || tz == human_tz;
+       hide.year = tm->tm_year == human_tm->tm_year;
+       if (hide.year) {
+               if (tm->tm_mon == human_tm->tm_mon) {
+                       if (tm->tm_mday > human_tm->tm_mday) {
+                               /* Future date: think timezones */
+                       } else if (tm->tm_mday == human_tm->tm_mday) {
+                               hide.date = hide.wday = 1;
+                       } else if (tm->tm_mday + 5 > human_tm->tm_mday) {
+                               /* Leave just weekday if it was a few days ago */
+                               hide.date = 1;
+                       }
+               }
+       }
+
+       /* Show "today" times as just relative times */
+       if (hide.wday) {
+               struct timeval now;
+               get_time(&now);
+               show_date_relative(time, &now, buf);
+               return;
+       }
+
+       /*
+        * Always hide seconds for human-readable.
+        * Hide timezone if showing date.
+        * Hide weekday and time if showing year.
+        *
+        * The logic here is two-fold:
+        *  (a) only show details when recent enough to matter
+        *  (b) keep the maximum length "similar", and in check
+        */
+       if (human_tm->tm_year) {
+               hide.seconds = 1;
+               hide.tz |= !hide.date;
+               hide.wday = hide.time = !hide.year;
+       }
+
+       if (!hide.wday)
+               strbuf_addf(buf, "%.3s ", weekday_names[tm->tm_wday]);
+       if (!hide.date)
+               strbuf_addf(buf, "%.3s %d ", month_names[tm->tm_mon], tm->tm_mday);
+
+       /* Do we want AM/PM depending on locale? */
+       if (!hide.time) {
+               strbuf_addf(buf, "%02d:%02d", tm->tm_hour, tm->tm_min);
+               if (!hide.seconds)
+                       strbuf_addf(buf, ":%02d", tm->tm_sec);
+       } else
+               strbuf_rtrim(buf);
+
+       if (!hide.year)
+               strbuf_addf(buf, " %d", tm->tm_year + 1900);
+
+       if (!hide.tz)
+               strbuf_addf(buf, " %+05d", tz);
+}
+
 const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
 {
        struct tm *tm;
+       struct tm human_tm = { 0 };
+       int human_tz = -1;
        static struct strbuf timebuf = STRBUF_INIT;
 
        if (mode->type == DATE_UNIX) {
@@ -202,6 +294,15 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
                return timebuf.buf;
        }
 
+       if (mode->type == DATE_HUMAN) {
+               struct timeval now;
+
+               get_time(&now);
+
+               /* Fill in the data for "current time" in human_tz and human_tm */
+               human_tz = local_time_tzoffset(now.tv_sec, &human_tm);
+       }
+
        if (mode->local)
                tz = local_tzoffset(time);
 
@@ -215,8 +316,8 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
                struct timeval now;
 
                strbuf_reset(&timebuf);
-               gettimeofday(&now, NULL);
-               show_date_relative(time, tz, &now, &timebuf);
+               get_time(&now);
+               show_date_relative(time, &now, &timebuf);
                return timebuf.buf;
        }
 
@@ -258,14 +359,7 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
                strbuf_addftime(&timebuf, mode->strftime_fmt, tm, tz,
                                !mode->local);
        else
-               strbuf_addf(&timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
-                               weekday_names[tm->tm_wday],
-                               month_names[tm->tm_mon],
-                               tm->tm_mday,
-                               tm->tm_hour, tm->tm_min, tm->tm_sec,
-                               tm->tm_year + 1900,
-                               mode->local ? 0 : ' ',
-                               tz);
+               show_date_normal(&timebuf, time, tm, tz, &human_tm, human_tz, mode->local);
        return timebuf.buf;
 }
 
@@ -819,6 +913,8 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)
                return DATE_SHORT;
        if (skip_prefix(format, "default", end))
                return DATE_NORMAL;
+       if (skip_prefix(format, "human", end))
+               return DATE_HUMAN;
        if (skip_prefix(format, "raw", end))
                return DATE_RAW;
        if (skip_prefix(format, "unix", end))
@@ -833,6 +929,14 @@ void parse_date_format(const char *format, struct date_mode *mode)
 {
        const char *p;
 
+       /* "auto:foo" is "if tty/pager, then foo, otherwise normal" */
+       if (skip_prefix(format, "auto:", &p)) {
+               if (isatty(1) || pager_in_use())
+                       format = p;
+               else
+                       format = "default";
+       }
+
        /* historical alias */
        if (!strcmp(format, "local"))
                format = "default-local";
@@ -1205,7 +1309,7 @@ timestamp_t approxidate_careful(const char *date, int *error_ret)
                return timestamp;
        }
 
-       gettimeofday(&tv, NULL);
+       get_time(&tv);
        return approxidate_str(date, &tv, error_ret);
 }
 
index 191a930705480e044e816c2ba62afe039036eaf3..2186bd0738ed2fcbe216cf24a6c99ed4dc4ccd9b 100644 (file)
@@ -296,7 +296,7 @@ void resolve_tree_islands(struct repository *r,
                        if (S_ISGITLINK(entry.mode))
                                continue;
 
-                       obj = lookup_object(r, entry.oid->hash);
+                       obj = lookup_object(r, entry.oid.hash);
                        if (!obj)
                                continue;
 
diff --git a/diff.c b/diff.c
index 1b5f27636061feb0ecf273f257c5e080c5ff7481..5306c48652db59e84c26383d68cf4a7d896647d4 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -304,7 +304,9 @@ static unsigned parse_color_moved_ws(const char *arg)
                strbuf_addstr(&sb, i->string);
                strbuf_trim(&sb);
 
-               if (!strcmp(sb.buf, "ignore-space-change"))
+               if (!strcmp(sb.buf, "no"))
+                       ret = 0;
+               else if (!strcmp(sb.buf, "ignore-space-change"))
                        ret |= XDF_IGNORE_WHITESPACE_CHANGE;
                else if (!strcmp(sb.buf, "ignore-space-at-eol"))
                        ret |= XDF_IGNORE_WHITESPACE_AT_EOL;
@@ -322,7 +324,7 @@ static unsigned parse_color_moved_ws(const char *arg)
 
        if ((ret & COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) &&
            (ret & XDF_WHITESPACE_FLAGS)) {
-               error(_("color-moved-ws: allow-indentation-change cannot be combined with other white space modes"));
+               error(_("color-moved-ws: allow-indentation-change cannot be combined with other whitespace modes"));
                ret |= COLOR_MOVED_WS_ERROR;
        }
 
@@ -493,7 +495,7 @@ static const char *external_diff(void)
 
        if (done_preparing)
                return external_diff_cmd;
-       external_diff_cmd = getenv("GIT_EXTERNAL_DIFF");
+       external_diff_cmd = xstrdup_or_null(getenv("GIT_EXTERNAL_DIFF"));
        if (!external_diff_cmd)
                external_diff_cmd = external_diff_cmd_cfg;
        done_preparing = 1;
@@ -754,6 +756,8 @@ struct emitted_diff_symbol {
        const char *line;
        int len;
        int flags;
+       int indent_off;   /* Offset to first non-whitespace character */
+       int indent_width; /* The visual width of the indentation */
        enum diff_symbol s;
 };
 #define EMITTED_DIFF_SYMBOL_INIT {NULL}
@@ -784,44 +788,85 @@ struct moved_entry {
        struct moved_entry *next_line;
 };
 
-/**
- * The struct ws_delta holds white space differences between moved lines, i.e.
- * between '+' and '-' lines that have been detected to be a move.
- * The string contains the difference in leading white spaces, before the
- * rest of the line is compared using the white space config for move
- * coloring. The current_longer indicates if the first string in the
- * comparision is longer than the second.
- */
-struct ws_delta {
-       char *string;
-       unsigned int current_longer : 1;
-};
-#define WS_DELTA_INIT { NULL, 0 }
-
 struct moved_block {
        struct moved_entry *match;
-       struct ws_delta wsd;
+       int wsd; /* The whitespace delta of this block */
 };
 
 static void moved_block_clear(struct moved_block *b)
 {
-       FREE_AND_NULL(b->wsd.string);
-       b->match = NULL;
+       memset(b, 0, sizeof(*b));
 }
 
-static int compute_ws_delta(const struct emitted_diff_symbol *a,
-                            const struct emitted_diff_symbol *b,
-                            struct ws_delta *out)
+#define INDENT_BLANKLINE INT_MIN
+
+static void fill_es_indent_data(struct emitted_diff_symbol *es)
 {
-       const struct emitted_diff_symbol *longer =  a->len > b->len ? a : b;
-       const struct emitted_diff_symbol *shorter = a->len > b->len ? b : a;
-       int d = longer->len - shorter->len;
+       unsigned int off = 0, i;
+       int width = 0, tab_width = es->flags & WS_TAB_WIDTH_MASK;
+       const char *s = es->line;
+       const int len = es->len;
+
+       /* skip any \v \f \r at start of indentation */
+       while (s[off] == '\f' || s[off] == '\v' ||
+              (s[off] == '\r' && off < len - 1))
+               off++;
+
+       /* calculate the visual width of indentation */
+       while(1) {
+               if (s[off] == ' ') {
+                       width++;
+                       off++;
+               } else if (s[off] == '\t') {
+                       width += tab_width - (width % tab_width);
+                       while (s[++off] == '\t')
+                               width += tab_width;
+               } else {
+                       break;
+               }
+       }
+
+       /* check if this line is blank */
+       for (i = off; i < len; i++)
+               if (!isspace(s[i]))
+                   break;
+
+       if (i == len) {
+               es->indent_width = INDENT_BLANKLINE;
+               es->indent_off = len;
+       } else {
+               es->indent_off = off;
+               es->indent_width = width;
+       }
+}
+
+static int compute_ws_delta(const struct emitted_diff_symbol *a,
+                           const struct emitted_diff_symbol *b,
+                           int *out)
+{
+       int a_len = a->len,
+           b_len = b->len,
+           a_off = a->indent_off,
+           a_width = a->indent_width,
+           b_off = b->indent_off,
+           b_width = b->indent_width;
+       int delta;
+
+       if (a_width == INDENT_BLANKLINE && b_width == INDENT_BLANKLINE) {
+               *out = INDENT_BLANKLINE;
+               return 1;
+       }
 
-       if (strncmp(longer->line + d, shorter->line, shorter->len))
+       if (a->s == DIFF_SYMBOL_PLUS)
+               delta = a_width - b_width;
+       else
+               delta = b_width - a_width;
+
+       if (a_len - a_off != b_len - b_off ||
+           memcmp(a->line + a_off, b->line + b_off, a_len - a_off))
                return 0;
 
-       out->string = xmemdupz(longer->line, d);
-       out->current_longer = (a == longer);
+       *out = delta;
 
        return 1;
 }
@@ -833,51 +878,53 @@ static int cmp_in_block_with_wsd(const struct diff_options *o,
                                 int n)
 {
        struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
-       int al = cur->es->len, cl = l->len;
+       int al = cur->es->len, bl = match->es->len, cl = l->len;
        const char *a = cur->es->line,
                   *b = match->es->line,
                   *c = l->line;
-
-       int wslen;
+       int a_off = cur->es->indent_off,
+           a_width = cur->es->indent_width,
+           c_off = l->indent_off,
+           c_width = l->indent_width;
+       int delta;
 
        /*
-        * We need to check if 'cur' is equal to 'match'.
-        * As those are from the same (+/-) side, we do not need to adjust for
-        * indent changes. However these were found using fuzzy matching
-        * so we do have to check if they are equal.
+        * We need to check if 'cur' is equal to 'match'.  As those
+        * are from the same (+/-) side, we do not need to adjust for
+        * indent changes. However these were found using fuzzy
+        * matching so we do have to check if they are equal. Here we
+        * just check the lengths. We delay calling memcmp() to check
+        * the contents until later as if the length comparison for a
+        * and c fails we can avoid the call all together.
         */
-       if (strcmp(a, b))
+       if (al != bl)
                return 1;
 
-       if (!pmb->wsd.string)
-               /*
-                * The white space delta is not active? This can happen
-                * when we exit early in this function.
-                */
-               return 1;
+       /* If 'l' and 'cur' are both blank then they match. */
+       if (a_width == INDENT_BLANKLINE && c_width == INDENT_BLANKLINE)
+               return 0;
 
        /*
-        * The indent changes of the block are known and stored in
-        * pmb->wsd; however we need to check if the indent changes of the
-        * current line are still the same as before.
-        *
-        * To do so we need to compare 'l' to 'cur', adjusting the
-        * one of them for the white spaces, depending which was longer.
+        * The indent changes of the block are known and stored in pmb->wsd;
+        * however we need to check if the indent changes of the current line
+        * match those of the current block and that the text of 'l' and 'cur'
+        * after the indentation match.
         */
+       if (cur->es->s == DIFF_SYMBOL_PLUS)
+               delta = a_width - c_width;
+       else
+               delta = c_width - a_width;
 
-       wslen = strlen(pmb->wsd.string);
-       if (pmb->wsd.current_longer) {
-               c += wslen;
-               cl -= wslen;
-       } else {
-               a += wslen;
-               al -= wslen;
-       }
-
-       if (al != cl || memcmp(a, c, al))
-               return 1;
+       /*
+        * If the previous lines of this block were all blank then set its
+        * whitespace delta.
+        */
+       if (pmb->wsd == INDENT_BLANKLINE)
+               pmb->wsd = delta;
 
-       return 0;
+       return !(delta == pmb->wsd && al - a_off == cl - c_off &&
+                !memcmp(a, b, al) && !
+                memcmp(a + a_off, c + c_off, al - a_off));
 }
 
 static int moved_entry_cmp(const void *hashmap_cmp_fn_data,
@@ -943,6 +990,9 @@ static void add_lines_to_move_detection(struct diff_options *o,
                        continue;
                }
 
+               if (o->color_moved_ws_handling &
+                   COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
+                       fill_es_indent_data(&o->emitted_symbols->buf[n]);
                key = prepare_entry(o, n);
                if (prev_line && prev_line->es->s == o->emitted_symbols->buf[n].s)
                        prev_line->next_line = key;
@@ -1021,8 +1071,7 @@ static int shrink_potential_moved_blocks(struct moved_block *pmb,
 
                if (lp < pmb_nr && rp > -1 && lp < rp) {
                        pmb[lp] = pmb[rp];
-                       pmb[rp].match = NULL;
-                       pmb[rp].wsd.string = NULL;
+                       memset(&pmb[rp], 0, sizeof(pmb[rp]));
                        rp--;
                        lp++;
                }
@@ -1042,14 +1091,17 @@ static int shrink_potential_moved_blocks(struct moved_block *pmb,
  * The last block consists of the (n - block_length)'th line up to but not
  * including the nth line.
  *
+ * Returns 0 if the last block is empty or is unset by this function, non zero
+ * otherwise.
+ *
  * NEEDSWORK: This uses the same heuristic as blame_entry_score() in blame.c.
  * Think of a way to unify them.
  */
-static void adjust_last_block(struct diff_options *o, int n, int block_length)
+static int adjust_last_block(struct diff_options *o, int n, int block_length)
 {
        int i, alnum_count = 0;
        if (o->color_moved == COLOR_MOVED_PLAIN)
-               return;
+               return block_length;
        for (i = 1; i < block_length + 1; i++) {
                const char *c = o->emitted_symbols->buf[n - i].line;
                for (; *c; c++) {
@@ -1057,11 +1109,12 @@ static void adjust_last_block(struct diff_options *o, int n, int block_length)
                                continue;
                        alnum_count++;
                        if (alnum_count >= COLOR_MOVED_MIN_ALNUM_COUNT)
-                               return;
+                               return 1;
                }
        }
        for (i = 1; i < block_length + 1; i++)
                o->emitted_symbols->buf[n - i].flags &= ~DIFF_SYMBOL_MOVED_LINE;
+       return 0;
 }
 
 /* Find blocks of moved code, delegate actual coloring decision to helper */
@@ -1071,7 +1124,7 @@ static void mark_color_as_moved(struct diff_options *o,
 {
        struct moved_block *pmb = NULL; /* potentially moved blocks */
        int pmb_nr = 0, pmb_alloc = 0;
-       int n, flipped_block = 1, block_length = 0;
+       int n, flipped_block = 0, block_length = 0;
 
 
        for (n = 0; n < o->emitted_symbols->nr; n++) {
@@ -1079,6 +1132,7 @@ static void mark_color_as_moved(struct diff_options *o,
                struct moved_entry *key;
                struct moved_entry *match = NULL;
                struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
+               enum diff_symbol last_symbol = 0;
 
                switch (l->s) {
                case DIFF_SYMBOL_PLUS:
@@ -1094,7 +1148,7 @@ static void mark_color_as_moved(struct diff_options *o,
                        free(key);
                        break;
                default:
-                       flipped_block = 1;
+                       flipped_block = 0;
                }
 
                if (!match) {
@@ -1105,13 +1159,16 @@ static void mark_color_as_moved(struct diff_options *o,
                                moved_block_clear(&pmb[i]);
                        pmb_nr = 0;
                        block_length = 0;
+                       flipped_block = 0;
+                       last_symbol = l->s;
                        continue;
                }
 
-               l->flags |= DIFF_SYMBOL_MOVED_LINE;
-
-               if (o->color_moved == COLOR_MOVED_PLAIN)
+               if (o->color_moved == COLOR_MOVED_PLAIN) {
+                       last_symbol = l->s;
+                       l->flags |= DIFF_SYMBOL_MOVED_LINE;
                        continue;
+               }
 
                if (o->color_moved_ws_handling &
                    COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
@@ -1134,21 +1191,27 @@ static void mark_color_as_moved(struct diff_options *o,
                                                             &pmb[pmb_nr].wsd))
                                                pmb[pmb_nr++].match = match;
                                } else {
-                                       pmb[pmb_nr].wsd.string = NULL;
+                                       pmb[pmb_nr].wsd = 0;
                                        pmb[pmb_nr++].match = match;
                                }
                        }
 
-                       flipped_block = (flipped_block + 1) % 2;
+                       if (adjust_last_block(o, n, block_length) &&
+                           pmb_nr && last_symbol != l->s)
+                               flipped_block = (flipped_block + 1) % 2;
+                       else
+                               flipped_block = 0;
 
-                       adjust_last_block(o, n, block_length);
                        block_length = 0;
                }
 
-               block_length++;
-
-               if (flipped_block && o->color_moved != COLOR_MOVED_BLOCKS)
-                       l->flags |= DIFF_SYMBOL_MOVED_LINE_ALT;
+               if (pmb_nr) {
+                       block_length++;
+                       l->flags |= DIFF_SYMBOL_MOVED_LINE;
+                       if (flipped_block && o->color_moved != COLOR_MOVED_BLOCKS)
+                               l->flags |= DIFF_SYMBOL_MOVED_LINE_ALT;
+               }
+               last_symbol = l->s;
        }
        adjust_last_block(o, n, block_length);
 
@@ -1492,7 +1555,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
 static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
                             const char *line, int len, unsigned flags)
 {
-       struct emitted_diff_symbol e = {line, len, flags, s};
+       struct emitted_diff_symbol e = {line, len, flags, 0, 0, s};
 
        if (o->emitted_symbols)
                append_emitted_diff_symbol(o, &e);
@@ -3481,7 +3544,7 @@ static void builtin_diff(const char *name_a,
                o->found_changes = 1;
        } else {
                /* Crazy xdl interfaces.. */
-               const char *diffopts = getenv("GIT_DIFF_OPTS");
+               const char *diffopts;
                const char *v;
                xpparam_t xpp;
                xdemitconf_t xecfg;
@@ -3524,12 +3587,15 @@ static void builtin_diff(const char *name_a,
                        xecfg.flags |= XDL_EMIT_FUNCCONTEXT;
                if (pe)
                        xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
+
+               diffopts = getenv("GIT_DIFF_OPTS");
                if (!diffopts)
                        ;
                else if (skip_prefix(diffopts, "--unified=", &v))
                        xecfg.ctxlen = strtoul(v, NULL, 10);
                else if (skip_prefix(diffopts, "-u", &v))
                        xecfg.ctxlen = strtoul(v, NULL, 10);
+
                if (o->word_diff)
                        init_diff_words_data(&ecbdata, o, one, two);
                if (xdi_diff_outf(&mf1, &mf2, NULL, fn_out_consume,
@@ -5042,6 +5108,8 @@ int diff_opt_parse(struct diff_options *options,
                if (cm < 0)
                        return error("bad --color-moved argument: %s", arg);
                options->color_moved = cm;
+       } else if (!strcmp(arg, "--no-color-moved-ws")) {
+               options->color_moved_ws_handling = 0;
        } else if (skip_prefix(arg, "--color-moved-ws=", &arg)) {
                unsigned cm = parse_color_moved_ws(arg);
                if (cm & COLOR_MOVED_WS_ERROR)
@@ -5894,8 +5962,10 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o)
 
                for (i = 0; i < esm.nr; i++)
                        free((void *)esm.buf[i].line);
+               esm.nr = 0;
+
+               o->emitted_symbols = NULL;
        }
-       esm.nr = 0;
 }
 
 void diff_flush(struct diff_options *options)
diff --git a/dir.c b/dir.c
index 21284482198147687fb03892265f97ac5ed58d18..b2cabadf2503b22cc10b3e47c548a5904d77158e 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -7,7 +7,6 @@
  * Copyright (C) Linus Torvalds, 2005-2006
  *              Junio Hamano, 2005-2006
  */
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
index 0e37741d838256d196b2ec9f3ca4e54395c66d31..89af47cb8504903b90460d5faa91be9f61bd2fc3 100644 (file)
@@ -107,7 +107,7 @@ char *git_work_tree_cfg;
 
 static char *git_namespace;
 
-static const char *super_prefix;
+static char *super_prefix;
 
 /*
  * Repository-local GIT_* environment variables; see cache.h for details.
@@ -240,7 +240,7 @@ const char *get_super_prefix(void)
 {
        static int initialized;
        if (!initialized) {
-               super_prefix = getenv(GIT_SUPER_PREFIX_ENVIRONMENT);
+               super_prefix = xstrdup_or_null(getenv(GIT_SUPER_PREFIX_ENVIRONMENT));
                initialized = 1;
        }
        return super_prefix;
index dd6700bda9240f2278e663f9147df1c0808d2efc..08b3b356faeabdeeff90918142f7225ce5460e8c 100644 (file)
@@ -135,38 +135,42 @@ enum ack_type {
        ACK_ready
 };
 
-static void consume_shallow_list(struct fetch_pack_args *args, int fd)
+static void consume_shallow_list(struct fetch_pack_args *args,
+                                struct packet_reader *reader)
 {
        if (args->stateless_rpc && args->deepen) {
                /* If we sent a depth we will get back "duplicate"
                 * shallow and unshallow commands every time there
                 * is a block of have lines exchanged.
                 */
-               char *line;
-               while ((line = packet_read_line(fd, NULL))) {
-                       if (starts_with(line, "shallow "))
+               while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
+                       if (starts_with(reader->line, "shallow "))
                                continue;
-                       if (starts_with(line, "unshallow "))
+                       if (starts_with(reader->line, "unshallow "))
                                continue;
                        die(_("git fetch-pack: expected shallow list"));
                }
+               if (reader->status != PACKET_READ_FLUSH)
+                       die(_("git fetch-pack: expected a flush packet after shallow list"));
        }
 }
 
-static enum ack_type get_ack(int fd, struct object_id *result_oid)
+static enum ack_type get_ack(struct packet_reader *reader,
+                            struct object_id *result_oid)
 {
        int len;
-       char *line = packet_read_line(fd, &len);
        const char *arg;
 
-       if (!line)
+       if (packet_reader_read(reader) != PACKET_READ_NORMAL)
                die(_("git fetch-pack: expected ACK/NAK, got a flush packet"));
-       if (!strcmp(line, "NAK"))
+       len = reader->pktlen;
+
+       if (!strcmp(reader->line, "NAK"))
                return NAK;
-       if (skip_prefix(line, "ACK ", &arg)) {
+       if (skip_prefix(reader->line, "ACK ", &arg)) {
                if (!get_oid_hex(arg, result_oid)) {
                        arg += 40;
-                       len -= arg - line;
+                       len -= arg - reader->line;
                        if (len < 1)
                                return ACK;
                        if (strstr(arg, "continue"))
@@ -178,9 +182,7 @@ static enum ack_type get_ack(int fd, struct object_id *result_oid)
                        return ACK;
                }
        }
-       if (skip_prefix(line, "ERR ", &arg))
-               die(_("remote error: %s"), arg);
-       die(_("git fetch-pack: expected ACK/NAK, got '%s'"), line);
+       die(_("git fetch-pack: expected ACK/NAK, got '%s'"), reader->line);
 }
 
 static void send_request(struct fetch_pack_args *args,
@@ -248,10 +250,15 @@ static int find_common(struct fetch_negotiator *negotiator,
        int got_ready = 0;
        struct strbuf req_buf = STRBUF_INIT;
        size_t state_len = 0;
+       struct packet_reader reader;
 
        if (args->stateless_rpc && multi_ack == 1)
                die(_("--stateless-rpc requires multi_ack_detailed"));
 
+       packet_reader_init(&reader, fd[0], NULL, 0,
+                          PACKET_READ_CHOMP_NEWLINE |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
+
        if (!args->no_dependents) {
                mark_tips(negotiator, args->negotiation_tips);
                for_each_cached_alternate(negotiator, insert_one_alternate_object);
@@ -329,38 +336,42 @@ static int find_common(struct fetch_negotiator *negotiator,
                        packet_buf_write(&req_buf, "deepen-not %s", s->string);
                }
        }
-       if (server_supports_filtering && args->filter_options.choice)
+       if (server_supports_filtering && args->filter_options.choice) {
+               struct strbuf expanded_filter_spec = STRBUF_INIT;
+               expand_list_objects_filter_spec(&args->filter_options,
+                                               &expanded_filter_spec);
                packet_buf_write(&req_buf, "filter %s",
-                                args->filter_options.filter_spec);
+                                expanded_filter_spec.buf);
+               strbuf_release(&expanded_filter_spec);
+       }
        packet_buf_flush(&req_buf);
        state_len = req_buf.len;
 
        if (args->deepen) {
-               char *line;
                const char *arg;
                struct object_id oid;
 
                send_request(args, fd[1], &req_buf);
-               while ((line = packet_read_line(fd[0], NULL))) {
-                       if (skip_prefix(line, "shallow ", &arg)) {
+               while (packet_reader_read(&reader) == PACKET_READ_NORMAL) {
+                       if (skip_prefix(reader.line, "shallow ", &arg)) {
                                if (get_oid_hex(arg, &oid))
-                                       die(_("invalid shallow line: %s"), line);
+                                       die(_("invalid shallow line: %s"), reader.line);
                                register_shallow(the_repository, &oid);
                                continue;
                        }
-                       if (skip_prefix(line, "unshallow ", &arg)) {
+                       if (skip_prefix(reader.line, "unshallow ", &arg)) {
                                if (get_oid_hex(arg, &oid))
-                                       die(_("invalid unshallow line: %s"), line);
+                                       die(_("invalid unshallow line: %s"), reader.line);
                                if (!lookup_object(the_repository, oid.hash))
-                                       die(_("object not found: %s"), line);
+                                       die(_("object not found: %s"), reader.line);
                                /* make sure that it is parsed as shallow */
                                if (!parse_object(the_repository, &oid))
-                                       die(_("error in object: %s"), line);
+                                       die(_("error in object: %s"), reader.line);
                                if (unregister_shallow(&oid))
-                                       die(_("no shallow found: %s"), line);
+                                       die(_("no shallow found: %s"), reader.line);
                                continue;
                        }
-                       die(_("expected shallow/unshallow, got %s"), line);
+                       die(_("expected shallow/unshallow, got %s"), reader.line);
                }
        } else if (!args->stateless_rpc)
                send_request(args, fd[1], &req_buf);
@@ -397,9 +408,9 @@ static int find_common(struct fetch_negotiator *negotiator,
                        if (!args->stateless_rpc && count == INITIAL_FLUSH)
                                continue;
 
-                       consume_shallow_list(args, fd[0]);
+                       consume_shallow_list(args, &reader);
                        do {
-                               ack = get_ack(fd[0], result_oid);
+                               ack = get_ack(&reader, result_oid);
                                if (ack)
                                        print_verbose(args, _("got %s %d %s"), "ack",
                                                      ack, oid_to_hex(result_oid));
@@ -469,9 +480,9 @@ static int find_common(struct fetch_negotiator *negotiator,
        strbuf_release(&req_buf);
 
        if (!got_ready || !no_done)
-               consume_shallow_list(args, fd[0]);
+               consume_shallow_list(args, &reader);
        while (flushes || multi_ack) {
-               int ack = get_ack(fd[0], result_oid);
+               int ack = get_ack(&reader, result_oid);
                if (ack) {
                        print_verbose(args, _("got %s (%d) %s"), "ack",
                                      ack, oid_to_hex(result_oid));
@@ -1007,6 +1018,8 @@ static void add_shallow_requests(struct strbuf *req_buf,
                        packet_buf_write(req_buf, "deepen-not %s", s->string);
                }
        }
+       if (args->deepen_relative)
+               packet_buf_write(req_buf, "deepen-relative\n");
 }
 
 static void add_wants(int no_dependents, const struct ref *wants, struct strbuf *req_buf)
@@ -1084,7 +1097,8 @@ static int add_haves(struct fetch_negotiator *negotiator,
 static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
                              const struct fetch_pack_args *args,
                              const struct ref *wants, struct oidset *common,
-                             int *haves_to_send, int *in_vain)
+                             int *haves_to_send, int *in_vain,
+                             int sideband_all)
 {
        int ret = 0;
        struct strbuf req_buf = STRBUF_INIT;
@@ -1110,6 +1124,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
                packet_buf_write(&req_buf, "include-tag");
        if (prefer_ofs_delta)
                packet_buf_write(&req_buf, "ofs-delta");
+       if (sideband_all)
+               packet_buf_write(&req_buf, "sideband-all");
 
        /* Add shallow-info and deepen request */
        if (server_supports_feature("fetch", "shallow", 0))
@@ -1120,9 +1136,13 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
        /* Add filter */
        if (server_supports_feature("fetch", "filter", 0) &&
            args->filter_options.choice) {
+               struct strbuf expanded_filter_spec = STRBUF_INIT;
                print_verbose(args, _("Server supports filter"));
+               expand_list_objects_filter_spec(&args->filter_options,
+                                               &expanded_filter_spec);
                packet_buf_write(&req_buf, "filter %s",
-                                args->filter_options.filter_spec);
+                                expanded_filter_spec.buf);
+               strbuf_release(&expanded_filter_spec);
        } else if (args->filter_options.choice) {
                warning("filtering not recognized by server, ignoring");
        }
@@ -1232,6 +1252,8 @@ static int process_acks(struct fetch_negotiator *negotiator,
 static void receive_shallow_info(struct fetch_pack_args *args,
                                 struct packet_reader *reader)
 {
+       int line_received = 0;
+
        process_section_header(reader, "shallow-info", 0);
        while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
                const char *arg;
@@ -1241,6 +1263,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
                        if (get_oid_hex(arg, &oid))
                                die(_("invalid shallow line: %s"), reader->line);
                        register_shallow(the_repository, &oid);
+                       line_received = 1;
                        continue;
                }
                if (skip_prefix(reader->line, "unshallow ", &arg)) {
@@ -1253,6 +1276,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
                                die(_("error in object: %s"), reader->line);
                        if (unregister_shallow(&oid))
                                die(_("no shallow found: %s"), reader->line);
+                       line_received = 1;
                        continue;
                }
                die(_("expected shallow/unshallow, got %s"), reader->line);
@@ -1262,8 +1286,11 @@ static void receive_shallow_info(struct fetch_pack_args *args,
            reader->status != PACKET_READ_DELIM)
                die(_("error processing shallow info: %d"), reader->status);
 
-       setup_alternate_shallow(&shallow_lock, &alternate_shallow_file, NULL);
-       args->deepen = 1;
+       if (line_received) {
+               setup_alternate_shallow(&shallow_lock, &alternate_shallow_file,
+                                       NULL);
+               args->deepen = 1;
+       }
 }
 
 static void receive_wanted_refs(struct packet_reader *reader,
@@ -1316,7 +1343,13 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
        struct fetch_negotiator negotiator;
        fetch_negotiator_init(&negotiator, negotiation_algorithm);
        packet_reader_init(&reader, fd[0], NULL, 0,
-                          PACKET_READ_CHOMP_NEWLINE);
+                          PACKET_READ_CHOMP_NEWLINE |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
+       if (git_env_bool("GIT_TEST_SIDEBAND_ALL", 1) &&
+           server_supports_feature("fetch", "sideband-all", 0)) {
+               reader.use_sideband = 1;
+               reader.me = "fetch-pack";
+       }
 
        while (state != FETCH_DONE) {
                switch (state) {
@@ -1350,7 +1383,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
                case FETCH_SEND_REQUEST:
                        if (send_fetch_request(&negotiator, fd[1], args, ref,
                                               &common,
-                                              &haves_to_send, &in_vain))
+                                              &haves_to_send, &in_vain,
+                                              reader.use_sideband))
                                state = FETCH_GET_PACK;
                        else
                                state = FETCH_PROCESS_ACKS;
diff --git a/fsck.c b/fsck.c
index 68502ce85b11bf0ef4445f2b1688b3834301ba53..2260adb71e7a9f1091d14bb635a4f082592b9512 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -410,14 +410,14 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
                        continue;
 
                if (S_ISDIR(entry.mode)) {
-                       obj = (struct object *)lookup_tree(the_repository, entry.oid);
+                       obj = (struct object *)lookup_tree(the_repository, &entry.oid);
                        if (name && obj)
                                put_object_name(options, obj, "%s%s/", name,
                                        entry.path);
                        result = options->walk(obj, OBJ_TREE, data, options);
                }
                else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
-                       obj = (struct object *)lookup_blob(the_repository, entry.oid);
+                       obj = (struct object *)lookup_blob(the_repository, &entry.oid);
                        if (name && obj)
                                put_object_name(options, obj, "%s%s", name,
                                        entry.path);
diff --git a/fuzz-commit-graph.c b/fuzz-commit-graph.c
new file mode 100644 (file)
index 0000000..cf790c9
--- /dev/null
@@ -0,0 +1,16 @@
+#include "commit-graph.h"
+
+struct commit_graph *parse_commit_graph(void *graph_map, int fd,
+                                       size_t graph_size);
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+       struct commit_graph *g;
+
+       g = parse_commit_graph((void *)data, -1, size);
+       free(g);
+
+       return 0;
+}
index 54cbfecc5ab0531513ff9e069be55d74339ad427..efee12b8b1e6d53d3cd5275683ebb0a4198b4b95 100755 (executable)
@@ -71,122 +71,7 @@ bisect_autostart() {
 }
 
 bisect_start() {
-       #
-       # Check for one bad and then some good revisions.
-       #
-       has_double_dash=0
-       for arg; do
-               case "$arg" in --) has_double_dash=1; break ;; esac
-       done
-       orig_args=$(git rev-parse --sq-quote "$@")
-       bad_seen=0
-       eval=''
-       must_write_terms=0
-       revs=''
-       if test "z$(git rev-parse --is-bare-repository)" != zfalse
-       then
-               mode=--no-checkout
-       else
-               mode=''
-       fi
-       while [ $# -gt 0 ]; do
-               arg="$1"
-               case "$arg" in
-               --)
-                       shift
-                       break
-               ;;
-               --no-checkout)
-                       mode=--no-checkout
-                       shift ;;
-               --term-good|--term-old)
-                       shift
-                       must_write_terms=1
-                       TERM_GOOD=$1
-                       shift ;;
-               --term-good=*|--term-old=*)
-                       must_write_terms=1
-                       TERM_GOOD=${1#*=}
-                       shift ;;
-               --term-bad|--term-new)
-                       shift
-                       must_write_terms=1
-                       TERM_BAD=$1
-                       shift ;;
-               --term-bad=*|--term-new=*)
-                       must_write_terms=1
-                       TERM_BAD=${1#*=}
-                       shift ;;
-               --*)
-                       die "$(eval_gettext "unrecognised option: '\$arg'")" ;;
-               *)
-                       rev=$(git rev-parse -q --verify "$arg^{commit}") || {
-                               test $has_double_dash -eq 1 &&
-                               die "$(eval_gettext "'\$arg' does not appear to be a valid revision")"
-                               break
-                       }
-                       revs="$revs $rev"
-                       shift
-                       ;;
-               esac
-       done
-
-       for rev in $revs
-       do
-               # The user ran "git bisect start <sha1>
-               # <sha1>", hence did not explicitly specify
-               # the terms, but we are already starting to
-               # set references named with the default terms,
-               # and won't be able to change afterwards.
-               must_write_terms=1
-
-               case $bad_seen in
-               0) state=$TERM_BAD ; bad_seen=1 ;;
-               *) state=$TERM_GOOD ;;
-               esac
-               eval="$eval bisect_write '$state' '$rev' 'nolog' &&"
-       done
-       #
-       # Verify HEAD.
-       #
-       head=$(GIT_DIR="$GIT_DIR" git symbolic-ref -q HEAD) ||
-       head=$(GIT_DIR="$GIT_DIR" git rev-parse --verify HEAD) ||
-       die "$(gettext "Bad HEAD - I need a HEAD")"
-
-       #
-       # Check if we are bisecting.
-       #
-       start_head=''
-       if test -s "$GIT_DIR/BISECT_START"
-       then
-               # Reset to the rev from where we started.
-               start_head=$(cat "$GIT_DIR/BISECT_START")
-               if test "z$mode" != "z--no-checkout"
-               then
-                       git checkout "$start_head" -- ||
-                       die "$(eval_gettext "Checking out '\$start_head' failed. Try 'git bisect reset <valid-branch>'.")"
-               fi
-       else
-               # Get rev from where we start.
-               case "$head" in
-               refs/heads/*|$_x40)
-                       # This error message should only be triggered by
-                       # cogito usage, and cogito users should understand
-                       # it relates to cg-seek.
-                       [ -s "$GIT_DIR/head-name" ] &&
-                               die "$(gettext "won't bisect on cg-seek'ed tree")"
-                       start_head="${head#refs/heads/}"
-                       ;;
-               *)
-                       die "$(gettext "Bad HEAD - strange symbolic ref")"
-                       ;;
-               esac
-       fi
-
-       #
-       # Get rid of any old bisect state.
-       #
-       git bisect--helper --bisect-clean-state || exit
+       git bisect--helper --bisect-start $@ || exit
 
        #
        # Change state.
@@ -198,45 +83,15 @@ bisect_start() {
        trap 'git bisect--helper --bisect-clean-state' 0
        trap 'exit 255' 1 2 3 15
 
-       #
-       # Write new start state.
-       #
-       echo "$start_head" >"$GIT_DIR/BISECT_START" && {
-               test "z$mode" != "z--no-checkout" ||
-               git update-ref --no-deref BISECT_HEAD "$start_head"
-       } &&
-       git rev-parse --sq-quote "$@" >"$GIT_DIR/BISECT_NAMES" &&
-       eval "$eval true" &&
-       if test $must_write_terms -eq 1
-       then
-               git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
-       fi &&
-       echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
        #
        # Check if we can proceed to the next bisect state.
        #
+       get_terms
        bisect_auto_next
 
        trap '-' 0
 }
 
-bisect_write() {
-       state="$1"
-       rev="$2"
-       nolog="$3"
-       case "$state" in
-               "$TERM_BAD")
-                       tag="$state" ;;
-               "$TERM_GOOD"|skip)
-                       tag="$state"-"$rev" ;;
-               *)
-                       die "$(eval_gettext "Bad bisect_write argument: \$state")" ;;
-       esac
-       git update-ref "refs/bisect/$tag" "$rev" || exit
-       echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
-       test -n "$nolog" || echo "git bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
-}
-
 bisect_skip() {
        all=''
        for arg in "$@"
@@ -255,7 +110,8 @@ bisect_skip() {
 bisect_state() {
        bisect_autostart
        state=$1
-       check_and_set_terms $state
+       git bisect--helper --check-and-set-terms $state $TERM_GOOD $TERM_BAD || exit
+       get_terms
        case "$#,$state" in
        0,*)
                die "Please call 'bisect_state' with at least one argument." ;;
@@ -263,7 +119,7 @@ bisect_state() {
                bisected_head=$(bisect_head)
                rev=$(git rev-parse --verify "$bisected_head") ||
                        die "$(eval_gettext "Bad rev input: \$bisected_head")"
-               bisect_write "$state" "$rev"
+               git bisect--helper --bisect-write "$state" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit
                git bisect--helper --check-expected-revs "$rev" ;;
        2,"$TERM_BAD"|*,"$TERM_GOOD"|*,skip)
                shift
@@ -276,7 +132,7 @@ bisect_state() {
                done
                for rev in $hash_list
                do
-                       bisect_write "$state" "$rev"
+                       git bisect--helper --bisect-write "$state" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit
                done
                git bisect--helper --check-expected-revs $hash_list ;;
        *,"$TERM_BAD")
@@ -287,59 +143,14 @@ bisect_state() {
        bisect_auto_next
 }
 
-bisect_next_check() {
-       missing_good= missing_bad=
-       git show-ref -q --verify refs/bisect/$TERM_BAD || missing_bad=t
-       test -n "$(git for-each-ref "refs/bisect/$TERM_GOOD-*")" || missing_good=t
-
-       case "$missing_good,$missing_bad,$1" in
-       ,,*)
-               : have both $TERM_GOOD and $TERM_BAD - ok
-               ;;
-       *,)
-               # do not have both but not asked to fail - just report.
-               false
-               ;;
-       t,,"$TERM_GOOD")
-               # have bad (or new) but not good (or old).  we could bisect although
-               # this is less optimum.
-               eval_gettextln "Warning: bisecting only with a \$TERM_BAD commit." >&2
-               if test -t 0
-               then
-                       # TRANSLATORS: Make sure to include [Y] and [n] in your
-                       # translation. The program will only accept English input
-                       # at this point.
-                       gettext "Are you sure [Y/n]? " >&2
-                       read yesno
-                       case "$yesno" in [Nn]*) exit 1 ;; esac
-               fi
-               : bisect without $TERM_GOOD...
-               ;;
-       *)
-               bad_syn=$(bisect_voc bad)
-               good_syn=$(bisect_voc good)
-               if test -s "$GIT_DIR/BISECT_START"
-               then
-
-                       eval_gettextln "You need to give me at least one \$bad_syn and one \$good_syn revision.
-(You can use \"git bisect \$bad_syn\" and \"git bisect \$good_syn\" for that.)" >&2
-               else
-                       eval_gettextln "You need to start by \"git bisect start\".
-You then need to give me at least one \$good_syn and one \$bad_syn revision.
-(You can use \"git bisect \$bad_syn\" and \"git bisect \$good_syn\" for that.)" >&2
-               fi
-               exit 1 ;;
-       esac
-}
-
 bisect_auto_next() {
-       bisect_next_check && bisect_next || :
+       git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD && bisect_next || :
 }
 
 bisect_next() {
        case "$#" in 0) ;; *) usage ;; esac
        bisect_autostart
-       bisect_next_check $TERM_GOOD
+       git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit
 
        # Perform all bisection computation, display and checkout
        git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout)
@@ -371,7 +182,7 @@ bisect_next() {
 }
 
 bisect_visualize() {
-       bisect_next_check fail
+       git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit
 
        if test $# = 0
        then
@@ -393,35 +204,11 @@ bisect_visualize() {
        eval '"$@"' --bisect -- $(cat "$GIT_DIR/BISECT_NAMES")
 }
 
-bisect_reset() {
-       test -s "$GIT_DIR/BISECT_START" || {
-               gettextln "We are not bisecting."
-               return
-       }
-       case "$#" in
-       0) branch=$(cat "$GIT_DIR/BISECT_START") ;;
-       1) git rev-parse --quiet --verify "$1^{commit}" >/dev/null || {
-                       invalid="$1"
-                       die "$(eval_gettext "'\$invalid' is not a valid commit")"
-               }
-               branch="$1" ;;
-       *)
-               usage ;;
-       esac
-
-       if ! test -f "$GIT_DIR/BISECT_HEAD" && ! git checkout "$branch" --
-       then
-               die "$(eval_gettext "Could not check out original HEAD '\$branch'.
-Try 'git bisect reset <commit>'.")"
-       fi
-       git bisect--helper --bisect-clean-state || exit
-}
-
 bisect_replay () {
        file="$1"
        test "$#" -eq 1 || die "$(gettext "No logfile given")"
        test -r "$file" || die "$(eval_gettext "cannot read \$file for replaying")"
-       bisect_reset
+       git bisect--helper --bisect-reset || exit
        while read git bisect command rev
        do
                test "$git $bisect" = "git bisect" || test "$git" = "git-bisect" || continue
@@ -431,15 +218,16 @@ bisect_replay () {
                        command="$bisect"
                fi
                get_terms
-               check_and_set_terms "$command"
+               git bisect--helper --check-and-set-terms "$command" "$TERM_GOOD" "$TERM_BAD" || exit
+               get_terms
                case "$command" in
                start)
                        cmd="bisect_start $rev"
                        eval "$cmd" ;;
                "$TERM_GOOD"|"$TERM_BAD"|skip)
-                       bisect_write "$command" "$rev" ;;
+                       git bisect--helper --bisect-write "$command" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit;;
                terms)
-                       bisect_terms $rev ;;
+                       git bisect--helper --bisect-terms $rev || exit;;
                *)
                        die "$(gettext "?? what are you talking about?")" ;;
                esac
@@ -448,7 +236,7 @@ bisect_replay () {
 }
 
 bisect_run () {
-       bisect_next_check fail
+       git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit
 
        test -n "$*" || die "$(gettext "bisect run failed: no command provided.")"
 
@@ -523,74 +311,6 @@ get_terms () {
        fi
 }
 
-check_and_set_terms () {
-       cmd="$1"
-       case "$cmd" in
-       skip|start|terms) ;;
-       *)
-               if test -s "$GIT_DIR/BISECT_TERMS" && test "$cmd" != "$TERM_BAD" && test "$cmd" != "$TERM_GOOD"
-               then
-                       die "$(eval_gettext "Invalid command: you're currently in a \$TERM_BAD/\$TERM_GOOD bisect.")"
-               fi
-               case "$cmd" in
-               bad|good)
-                       if ! test -s "$GIT_DIR/BISECT_TERMS"
-                       then
-                               TERM_BAD=bad
-                               TERM_GOOD=good
-                               git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
-                       fi
-                       ;;
-               new|old)
-                       if ! test -s "$GIT_DIR/BISECT_TERMS"
-                       then
-                               TERM_BAD=new
-                               TERM_GOOD=old
-                               git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
-                       fi
-                       ;;
-               esac ;;
-       esac
-}
-
-bisect_voc () {
-       case "$1" in
-       bad) echo "bad|new" ;;
-       good) echo "good|old" ;;
-       esac
-}
-
-bisect_terms () {
-       get_terms
-       if ! test -s "$GIT_DIR/BISECT_TERMS"
-       then
-               die "$(gettext "no terms defined")"
-       fi
-       case "$#" in
-       0)
-               gettextln "Your current terms are $TERM_GOOD for the old state
-and $TERM_BAD for the new state."
-               ;;
-       1)
-               arg=$1
-               case "$arg" in
-                       --term-good|--term-old)
-                               printf '%s\n' "$TERM_GOOD"
-                               ;;
-                       --term-bad|--term-new)
-                               printf '%s\n' "$TERM_BAD"
-                               ;;
-                       *)
-                               die "$(eval_gettext "invalid argument \$arg for 'git bisect terms'.
-Supported options are: --term-good|--term-old and --term-bad|--term-new.")"
-                               ;;
-               esac
-               ;;
-       *)
-               usage ;;
-       esac
-}
-
 case "$#" in
 0)
        usage ;;
@@ -613,7 +333,7 @@ case "$#" in
        visualize|view)
                bisect_visualize "$@" ;;
        reset)
-               bisect_reset "$@" ;;
+               git bisect--helper --bisect-reset "$@" ;;
        replay)
                bisect_replay "$@" ;;
        log)
@@ -621,7 +341,7 @@ case "$#" in
        run)
                bisect_run "$@" ;;
        terms)
-               bisect_terms "$@" ;;
+               git bisect--helper --bisect-terms "$@" || exit;;
        *)
                usage ;;
        esac
index eec264e6303684c5886804361c630e1572c1fe09..7c55229773e2bdb0f138b1180ab22d05c74ff904 100755 (executable)
@@ -67,6 +67,13 @@ resolve_full_httpd () {
                httpd_only="${httpd%% *}" # cut on first space
                return
                ;;
+       *python*)
+               # server is started by running via generated gitweb.py in
+               # $fqgitdir/gitweb
+               full_httpd="$fqgitdir/gitweb/gitweb.py"
+               httpd_only="${httpd%% *}" # cut on first space
+               return
+               ;;
        esac
 
        httpd_only="$(echo $httpd | cut -f1 -d' ')"
@@ -110,7 +117,7 @@ start_httpd () {
 
        # don't quote $full_httpd, there can be arguments to it (-f)
        case "$httpd" in
-       *mongoose*|*plackup*)
+       *mongoose*|*plackup*|*python*)
                #These servers don't have a daemon mode so we'll have to fork it
                $full_httpd "$conf" &
                #Save the pid before doing anything else (we'll print it later)
@@ -595,6 +602,121 @@ EOF
        rm -f "$conf"
 }
 
+python_conf() {
+       # Python's builtin http.server and its CGI support is very limited.
+       # CGI handler is capable of running CGI script only from inside a directory.
+       # Trying to set cgi_directories=["/"] will add double slash to SCRIPT_NAME
+       # and that in turn breaks gitweb's relative link generation.
+
+       # create a simple web root where $fqgitdir/gitweb/$httpd_only is our root
+       mkdir -p "$fqgitdir/gitweb/$httpd_only/cgi-bin"
+       # Python http.server follows the symlinks
+       ln -sf "$root/gitweb.cgi" "$fqgitdir/gitweb/$httpd_only/cgi-bin/gitweb.cgi"
+       ln -sf "$root/static" "$fqgitdir/gitweb/$httpd_only/"
+
+       # generate a standalone 'python http.server' script in $fqgitdir/gitweb
+       # This asumes that python is in user's $PATH
+       # This script is Python 2 and 3 compatible
+       cat > "$fqgitdir/gitweb/gitweb.py" <<EOF
+#!/usr/bin/env python
+import os
+import sys
+
+# Open log file in line buffering mode
+accesslogfile = open("$fqgitdir/gitweb/access.log", 'a', buffering=1)
+errorlogfile = open("$fqgitdir/gitweb/error.log", 'a', buffering=1)
+
+# and replace our stdout and stderr with log files
+# also do a lowlevel duplicate of the logfile file descriptors so that
+# our CGI child process writes any stderr warning also to the log file
+_orig_stdout_fd = sys.stdout.fileno()
+sys.stdout.close()
+os.dup2(accesslogfile.fileno(), _orig_stdout_fd)
+sys.stdout = accesslogfile
+
+_orig_stderr_fd = sys.stderr.fileno()
+sys.stderr.close()
+os.dup2(errorlogfile.fileno(), _orig_stderr_fd)
+sys.stderr = errorlogfile
+
+from functools import partial
+
+if sys.version_info < (3, 0):  # Python 2
+       from CGIHTTPServer import CGIHTTPRequestHandler
+       from BaseHTTPServer import HTTPServer as ServerClass
+else:  # Python 3
+       from http.server import CGIHTTPRequestHandler
+       from http.server import HTTPServer as ServerClass
+
+
+# Those environment variables will be passed to the cgi script
+os.environ.update({
+       "GIT_EXEC_PATH": "$GIT_EXEC_PATH",
+       "GIT_DIR": "$GIT_DIR",
+       "GITWEB_CONFIG": "$GITWEB_CONFIG"
+})
+
+
+class GitWebRequestHandler(CGIHTTPRequestHandler):
+
+       def log_message(self, format, *args):
+               # Write access logs to stdout
+               sys.stdout.write("%s - - [%s] %s\n" %
+                               (self.address_string(),
+                               self.log_date_time_string(),
+                               format%args))
+
+       def do_HEAD(self):
+               self.redirect_path()
+               CGIHTTPRequestHandler.do_HEAD(self)
+
+       def do_GET(self):
+               if self.path == "/":
+                       self.send_response(303, "See Other")
+                       self.send_header("Location", "/cgi-bin/gitweb.cgi")
+                       self.end_headers()
+                       return
+               self.redirect_path()
+               CGIHTTPRequestHandler.do_GET(self)
+
+       def do_POST(self):
+               self.redirect_path()
+               CGIHTTPRequestHandler.do_POST(self)
+
+       # rewrite path of every request that is not gitweb.cgi to out of cgi-bin
+       def redirect_path(self):
+               if not self.path.startswith("/cgi-bin/gitweb.cgi"):
+                       self.path = self.path.replace("/cgi-bin/", "/")
+
+       # gitweb.cgi is the only thing that is ever going to be run here.
+       # Ignore everything else
+       def is_cgi(self):
+               result = False
+               if self.path.startswith('/cgi-bin/gitweb.cgi'):
+                       result = CGIHTTPRequestHandler.is_cgi(self)
+               return result
+
+
+bind = "127.0.0.1"
+if "$local" == "true":
+       bind = "0.0.0.0"
+
+# Set our http root directory
+# This is a work around for a missing directory argument in older Python versions
+# as this was added to SimpleHTTPRequestHandler in Python 3.7
+os.chdir("$fqgitdir/gitweb/$httpd_only/")
+
+GitWebRequestHandler.protocol_version = "HTTP/1.0"
+httpd = ServerClass((bind, $port), GitWebRequestHandler)
+
+sa = httpd.socket.getsockname()
+print("Serving HTTP on", sa[0], "port", sa[1], "...")
+httpd.serve_forever()
+EOF
+
+       chmod a+x "$fqgitdir/gitweb/gitweb.py"
+}
+
 gitweb_conf() {
        cat > "$fqgitdir/gitweb/gitweb_config.perl" <<EOF
 #!@@PERL@@
@@ -623,6 +745,9 @@ configure_httpd() {
        *plackup*)
                plackup_conf
                ;;
+       *python*)
+               python_conf
+               ;;
        *)
                echo "Unknown httpd specified: $httpd"
                exit 1
index b4c7dbfa575d3b5c664677c22b8613284d2e33fb..8d6c9aca6584f76689246604abe047a85504671e 100755 (executable)
@@ -26,6 +26,7 @@ f,force-rebase!    cherry-pick all commits, even if unchanged
 m,merge!           use merging strategies to rebase
 i,interactive!     let the user edit the list of commits to rebase
 x,exec=!           add exec lines after each commit of the editable list
+y=!                same as --reschedule-failed-exec -x
 k,keep-empty      preserve empty commits during rebase
 allow-empty-message allow rebasing commits with empty messages
 stat!              display a diffstat of what changed upstream
@@ -48,6 +49,7 @@ skip!              skip current patch and continue
 edit-todo!         edit the todo list during an interactive rebase
 quit!              abort but keep HEAD where it is
 show-current-patch! show the patch file being applied or merged
+reschedule-failed-exec automatically reschedule failed exec commands
 "
 . git-sh-setup
 set_reflog_action rebase
@@ -92,11 +94,14 @@ autosquash=
 keep_empty=
 allow_empty_message=--allow-empty-message
 signoff=
+reschedule_failed_exec=
 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 case "$(git config --bool commit.gpgsign)" in
 true)  gpg_sign_opt=-S ;;
 *)     gpg_sign_opt= ;;
 esac
+test "$(git config --bool rebase.reschedulefailedexec)" = "true" &&
+reschedule_failed_exec=--reschedule-failed-exec
 . git-rebase--common
 
 read_basic_state () {
@@ -113,7 +118,7 @@ read_basic_state () {
        else
                orig_head=$(cat "$state_dir"/head)
        fi &&
-       GIT_QUIET=$(cat "$state_dir"/quiet) &&
+       test -f "$state_dir"/quiet && GIT_QUIET=t
        test -f "$state_dir"/verbose && verbose=t
        test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
        test -f "$state_dir"/strategy_opts &&
@@ -126,6 +131,8 @@ read_basic_state () {
                signoff="$(cat "$state_dir"/signoff)"
                force_rebase=t
        }
+       test -f "$state_dir"/reschedule-failed-exec &&
+               reschedule_failed_exec=t
 }
 
 finish_rebase () {
@@ -163,13 +170,14 @@ run_interactive () {
                "$allow_empty_message" "$autosquash" "$verbose" \
                "$force_rebase" "$onto_name" "$head_name" "$strategy" \
                "$strategy_opts" "$cmd" "$switch_to" \
-               "$allow_rerere_autoupdate" "$gpg_sign_opt" "$signoff"
+               "$allow_rerere_autoupdate" "$gpg_sign_opt" "$signoff" \
+               "$reschedule_failed_exec"
 }
 
 run_specific_rebase () {
        if [ "$interactive_rebase" = implied ]; then
-               GIT_EDITOR=:
-               export GIT_EDITOR
+               GIT_SEQUENCE_EDITOR=:
+               export GIT_SEQUENCE_EDITOR
                autosquash=
        fi
 
@@ -218,6 +226,7 @@ then
        state_dir="$apply_dir"
 elif test -d "$merge_dir"
 then
+       type=interactive
        if test -d "$merge_dir"/rewritten
        then
                type=preserve-merges
@@ -225,10 +234,7 @@ then
                preserve_merges=t
        elif test -f "$merge_dir"/interactive
        then
-               type=interactive
                interactive_rebase=explicit
-       else
-               type=merge
        fi
        state_dir="$merge_dir"
 fi
@@ -255,6 +261,11 @@ do
                cmd="${cmd}exec ${1#--exec=}${LF}"
                test -z "$interactive_rebase" && interactive_rebase=implied
                ;;
+       -y*)
+               reschedule_failed_exec=--reschedule-failed-exec
+               cmd="${cmd}exec ${1#-y}${LF}"
+               test -z "$interactive_rebase" && interactive_rebase=implied
+               ;;
        --interactive)
                interactive_rebase=explicit
                ;;
@@ -378,6 +389,12 @@ do
        --gpg-sign=*)
                gpg_sign_opt="-S${1#--gpg-sign=}"
                ;;
+       --reschedule-failed-exec)
+               reschedule_failed_exec=--reschedule-failed-exec
+               ;;
+       --no-reschedule-failed-exec)
+               reschedule_failed_exec=
+               ;;
        --)
                shift
                break
@@ -477,6 +494,7 @@ then
        test -z "$interactive_rebase" && interactive_rebase=implied
 fi
 
+actually_interactive=
 if test -n "$interactive_rebase"
 then
        if test -z "$preserve_merges"
@@ -485,11 +503,12 @@ then
        else
                type=preserve-merges
        fi
-
+       actually_interactive=t
        state_dir="$merge_dir"
 elif test -n "$do_merge"
 then
-       type=merge
+       interactive_rebase=implied
+       type=interactive
        state_dir="$merge_dir"
 else
        type=am
@@ -501,28 +520,20 @@ then
        git_format_patch_opt="$git_format_patch_opt --progress"
 fi
 
-if test -n "$git_am_opt"; then
-       incompatible_opts=$(echo " $git_am_opt " | \
-                           sed -e 's/ -q / /g' -e 's/^ \(.*\) $/\1/')
-       if test -n "$interactive_rebase"
+incompatible_opts=$(echo " $git_am_opt " | \
+                   sed -e 's/ -q / /g' -e 's/^ \(.*\) $/\1/')
+if test -n "$incompatible_opts"
+then
+       if test -n "$actually_interactive" || test "$do_merge"
        then
-               if test -n "$incompatible_opts"
-               then
-                       die "$(gettext "error: cannot combine interactive options (--interactive, --exec, --rebase-merges, --preserve-merges, --keep-empty, --root + --onto) with am options ($incompatible_opts)")"
-               fi
-       fi
-       if test -n "$do_merge"; then
-               if test -n "$incompatible_opts"
-               then
-                       die "$(gettext "error: cannot combine merge options (--merge, --strategy, --strategy-option) with am options ($incompatible_opts)")"
-               fi
+               die "$(gettext "fatal: cannot combine am options with either interactive or merge options")"
        fi
 fi
 
 if test -n "$signoff"
 then
        test -n "$preserve_merges" &&
-               die "$(gettext "error: cannot combine '--signoff' with '--preserve-merges'")"
+               die "$(gettext "fatal: cannot combine '--signoff' with '--preserve-merges'")"
        git_am_opt="$git_am_opt $signoff"
        force_rebase=t
 fi
@@ -533,15 +544,18 @@ then
        # Note: incompatibility with --interactive is just a strong warning;
        #       git-rebase.txt caveats with "unless you know what you are doing"
        test -n "$rebase_merges" &&
-               die "$(gettext "error: cannot combine '--preserve-merges' with '--rebase-merges'")"
+               die "$(gettext "fatal: cannot combine '--preserve-merges' with '--rebase-merges'")"
+
+       test -n "$reschedule_failed_exec" &&
+               die "$(gettext "error: cannot combine '--preserve-merges' with '--reschedule-failed-exec'")"
 fi
 
 if test -n "$rebase_merges"
 then
        test -n "$strategy_opts" &&
-               die "$(gettext "error: cannot combine '--rebase-merges' with '--strategy-option'")"
+               die "$(gettext "fatal: cannot combine '--rebase-merges' with '--strategy-option'")"
        test -n "$strategy" &&
-               die "$(gettext "error: cannot combine '--rebase-merges' with '--strategy'")"
+               die "$(gettext "fatal: cannot combine '--rebase-merges' with '--strategy'")"
 fi
 
 if test -z "$rebase_root"
@@ -680,7 +694,7 @@ require_clean_work_tree "rebase" "$(gettext "Please commit or stash them.")"
 # but this should be done only when upstream and onto are the same
 # and if this is not an interactive rebase.
 mb=$(git merge-base "$onto" "$orig_head")
-if test -z "$interactive_rebase" && test "$upstream" = "$onto" &&
+if test -z "$actually_interactive" && test "$upstream" = "$onto" &&
        test "$mb" = "$onto" && test -z "$restrict_revision" &&
        # linear history?
        ! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
@@ -730,6 +744,19 @@ then
        GIT_PAGER='' git diff --stat --summary "$mb_tree" "$onto"
 fi
 
+if test -z "$actually_interactive" && test "$mb" = "$orig_head"
+then
+       say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")"
+       GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" \
+               git checkout -q "$onto^0" || die "could not detach HEAD"
+       # If the $onto is a proper descendant of the tip of the branch, then
+       # we just fast-forwarded.
+       git update-ref ORIG_HEAD $orig_head
+       move_to_original_branch
+       finish_rebase
+       exit 0
+fi
+
 test -n "$interactive_rebase" && run_specific_rebase
 
 # Detach HEAD and reset the tree
@@ -739,16 +766,6 @@ GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" \
        git checkout -q "$onto^0" || die "could not detach HEAD"
 git update-ref ORIG_HEAD $orig_head
 
-# If the $onto is a proper descendant of the tip of the branch, then
-# we just fast-forwarded.
-if test "$mb" = "$orig_head"
-then
-       say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")"
-       move_to_original_branch
-       finish_rebase
-       exit 0
-fi
-
 if test -n "$rebase_root"
 then
        revisions="$onto..$orig_head"
index 3e12774f96bb185bb6860290ad187c986ec7fa76..5b79920f46a972437ff05966d042a84d44f050d9 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -1861,6 +1861,7 @@ def applyCommit(self, id):
                     filesToAdd.remove(path)
             elif modifier == "C":
                 src, dest = diff['src'], diff['dst']
+                all_files.append(dest)
                 p4_integrate(src, dest)
                 pureRenameCopy.add(dest)
                 if diff['src_sha1'] != diff['dst_sha1']:
@@ -1877,6 +1878,7 @@ def applyCommit(self, id):
                 editedFiles.add(dest)
             elif modifier == "R":
                 src, dest = diff['src'], diff['dst']
+                all_files.append(dest)
                 if self.p4HasMoveCommand:
                     p4_edit(src)        # src must be open before move
                     p4_move(src, dest)  # opens for (move/delete, move/add)
index 99b8c177875a7f26ae6c7f70be42c9d97231f7b9..6416716ee620cfac7803f9f00cef309a41b08f31 100644 (file)
@@ -36,7 +36,7 @@ rm -f "$GIT_DIR/rebased-patches"
 
 git format-patch -k --stdout --full-index --cherry-pick --right-only \
        --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \
-       --pretty=mboxrd \
+       --pretty=mboxrd --topo-order \
        $git_format_patch_opt \
        "$revisions" ${restrict_revision+^$restrict_revision} \
        >"$GIT_DIR/rebased-patches"
index 7e39d228717899228dfd735b22196de973e7add3..f00e13e5d04df09558dba65afd4fe1ed44375fa9 100644 (file)
@@ -10,7 +10,7 @@ write_basic_state () {
        echo "$head_name" > "$state_dir"/head-name &&
        echo "$onto" > "$state_dir"/onto &&
        echo "$orig_head" > "$state_dir"/orig-head &&
-       echo "$GIT_QUIET" > "$state_dir"/quiet &&
+       test t = "$GIT_QUIET" && : > "$state_dir"/quiet
        test t = "$verbose" && : > "$state_dir"/verbose
        test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
        test -n "$strategy_opts" && echo "$strategy_opts" > \
@@ -19,6 +19,7 @@ write_basic_state () {
                "$state_dir"/allow_rerere_autoupdate
        test -n "$gpg_sign_opt" && echo "$gpg_sign_opt" > "$state_dir"/gpg_sign_opt
        test -n "$signoff" && echo "$signoff" >"$state_dir"/signoff
+       test -n "$reschedule_failed_exec" && : > "$state_dir"/reschedule-failed-exec
 }
 
 apply_autostash () {
diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
deleted file mode 100644 (file)
index aa2f2f0..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-# This shell script fragment is sourced by git-rebase to implement
-# its merge-based non-interactive mode that copes well with renamed
-# files.
-#
-# Copyright (c) 2010 Junio C Hamano.
-#
-
-prec=4
-
-read_state () {
-       onto_name=$(cat "$state_dir"/onto_name) &&
-       end=$(cat "$state_dir"/end) &&
-       msgnum=$(cat "$state_dir"/msgnum)
-}
-
-continue_merge () {
-       test -d "$state_dir" || die "$state_dir directory does not exist"
-
-       unmerged=$(git ls-files -u)
-       if test -n "$unmerged"
-       then
-               echo "You still have unmerged paths in your index"
-               echo "did you forget to use git add?"
-               die "$resolvemsg"
-       fi
-
-       cmt=$(cat "$state_dir/current")
-       if ! git diff-index --quiet --ignore-submodules HEAD --
-       then
-               if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} $signoff $allow_empty_message \
-                       --no-verify -C "$cmt"
-               then
-                       echo "Commit failed, please do not call \"git commit\""
-                       echo "directly, but instead do one of the following: "
-                       die "$resolvemsg"
-               fi
-               if test -z "$GIT_QUIET"
-               then
-                       printf "Committed: %0${prec}d " $msgnum
-               fi
-               echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
-       else
-               if test -z "$GIT_QUIET"
-               then
-                       printf "Already applied: %0${prec}d " $msgnum
-               fi
-       fi
-       test -z "$GIT_QUIET" &&
-       GIT_PAGER='' git log --format=%s -1 "$cmt"
-
-       # onto the next patch:
-       msgnum=$(($msgnum + 1))
-       echo "$msgnum" >"$state_dir/msgnum"
-}
-
-call_merge () {
-       msgnum="$1"
-       echo "$msgnum" >"$state_dir/msgnum"
-       cmt="$(cat "$state_dir/cmt.$msgnum")"
-       echo "$cmt" > "$state_dir/current"
-       git update-ref REBASE_HEAD "$cmt"
-       hd=$(git rev-parse --verify HEAD)
-       cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
-       eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
-       eval GITHEAD_$hd='$onto_name'
-       export GITHEAD_$cmt GITHEAD_$hd
-       if test -n "$GIT_QUIET"
-       then
-               GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
-       fi
-       test -z "$strategy" && strategy=recursive
-       # If cmt doesn't have a parent, don't include it as a base
-       base=$(git rev-parse --verify --quiet $cmt^)
-       eval 'git merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"'
-       rv=$?
-       case "$rv" in
-       0)
-               unset GITHEAD_$cmt GITHEAD_$hd
-               return
-               ;;
-       1)
-               git rerere $allow_rerere_autoupdate
-               die "$resolvemsg"
-               ;;
-       2)
-               echo "Strategy: $strategy failed, try another" 1>&2
-               die "$resolvemsg"
-               ;;
-       *)
-               die "Unknown exit code ($rv) from command:" \
-                       "git merge-$strategy $cmt^ -- HEAD $cmt"
-               ;;
-       esac
-}
-
-finish_rb_merge () {
-       move_to_original_branch
-       if test -s "$state_dir"/rewritten
-       then
-               git notes copy --for-rewrite=rebase <"$state_dir"/rewritten
-               hook="$(git rev-parse --git-path hooks/post-rewrite)"
-               test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten
-       fi
-       say All done.
-}
-
-git_rebase__merge () {
-
-case "$action" in
-continue)
-       read_state
-       continue_merge
-       while test "$msgnum" -le "$end"
-       do
-               call_merge "$msgnum"
-               continue_merge
-       done
-       finish_rb_merge
-       return
-       ;;
-skip)
-       read_state
-       git rerere clear
-       msgnum=$(($msgnum + 1))
-       while test "$msgnum" -le "$end"
-       do
-               call_merge "$msgnum"
-               continue_merge
-       done
-       finish_rb_merge
-       return
-       ;;
-show-current-patch)
-       exec git show REBASE_HEAD --
-       ;;
-esac
-
-mkdir -p "$state_dir"
-echo "$onto_name" > "$state_dir/onto_name"
-write_basic_state
-rm -f "$(git rev-parse --git-path REBASE_HEAD)"
-
-msgnum=0
-for cmt in $(git rev-list --reverse --no-merges "$revisions")
-do
-       msgnum=$(($msgnum + 1))
-       echo "$cmt" > "$state_dir/cmt.$msgnum"
-done
-
-echo 1 >"$state_dir/msgnum"
-echo $msgnum >"$state_dir/end"
-
-end=$msgnum
-msgnum=1
-
-while test "$msgnum" -le "$end"
-do
-       call_merge "$msgnum"
-       continue_merge
-done
-
-finish_rb_merge
-
-}
index 5e608f8bad305fea40e9063b854bf1be24ebd448..02a0d728174a0201c966abd73299d03c198d03b4 100755 (executable)
@@ -548,7 +548,7 @@ cmd_update()
        do
                die_if_unmatched "$quickabort" "$sha1"
 
-               git submodule--helper ensure-core-worktree "$sm_path"
+               git submodule--helper ensure-core-worktree "$sm_path" || exit 1
 
                update_module=$(git submodule--helper update-module-mode $just_cloned "$sm_path" $update)
 
diff --git a/git.c b/git.c
index 0ce0e13f0f4879ae4608bd61d3a6a1f55ef7892e..2dd588674f621e2df2af1a3833c2cb3fa8417de4 100644 (file)
--- a/git.c
+++ b/git.c
@@ -418,9 +418,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 
        trace_argv_printf(argv, "trace: built-in: git");
 
-       validate_cache_entries(&the_index);
+       validate_cache_entries(the_repository->index);
        status = p->fn(argc, argv, prefix);
-       validate_cache_entries(&the_index);
+       validate_cache_entries(the_repository->index);
 
        if (status)
                return status;
diff --git a/hash.h b/hash.h
index 7c8238bc2ebfded778351b58c16a3854617082c6..adde708cf26d90ffd7ae10e6cdb8bfd7c08b1db5 100644 (file)
--- a/hash.h
+++ b/hash.h
 #include "block-sha1/sha1.h"
 #endif
 
+#if defined(SHA256_GCRYPT)
+#include "sha256/gcrypt.h"
+#elif defined(SHA256_OPENSSL)
+#include <openssl/sha.h>
+#else
+#include "sha256/block/sha256.h"
+#endif
+
 #ifndef platform_SHA_CTX
 /*
  * platform's underlying implementation of SHA-1; could be OpenSSL,
 #define git_SHA1_Update                platform_SHA1_Update
 #define git_SHA1_Final         platform_SHA1_Final
 
+#ifndef platform_SHA256_CTX
+#define platform_SHA256_CTX    SHA256_CTX
+#define platform_SHA256_Init   SHA256_Init
+#define platform_SHA256_Update SHA256_Update
+#define platform_SHA256_Final  SHA256_Final
+#endif
+
+#define git_SHA256_CTX         platform_SHA256_CTX
+#define git_SHA256_Init                platform_SHA256_Init
+#define git_SHA256_Update      platform_SHA256_Update
+#define git_SHA256_Final       platform_SHA256_Final
+
 #ifdef SHA1_MAX_BLOCK_SIZE
 #include "compat/sha1-chunked.h"
 #undef git_SHA1_Update
 #define GIT_HASH_UNKNOWN 0
 /* SHA-1 */
 #define GIT_HASH_SHA1 1
+/* SHA-256  */
+#define GIT_HASH_SHA256 2
 /* Number of algorithms supported (including unknown). */
-#define GIT_HASH_NALGOS (GIT_HASH_SHA1 + 1)
+#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
 
 /* A suitably aligned type for stack allocations of hash contexts. */
 union git_hash_ctx {
        git_SHA_CTX sha1;
+       git_SHA256_CTX sha256;
 };
 typedef union git_hash_ctx git_hash_ctx;
 
@@ -81,6 +104,9 @@ struct git_hash_algo {
        /* The length of the hash in hex characters. */
        size_t hexsz;
 
+       /* The block size of the hash. */
+       size_t blksz;
+
        /* The hash initialization function. */
        git_hash_init_fn init_fn;
 
@@ -98,4 +124,17 @@ struct git_hash_algo {
 };
 extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
 
+/*
+ * Return a GIT_HASH_* constant based on the name.  Returns GIT_HASH_UNKNOWN if
+ * the name doesn't match a known algorithm.
+ */
+int hash_algo_by_name(const char *name);
+/* Identical, except based on the format ID. */
+int hash_algo_by_id(uint32_t format_id);
+/* Identical, except for a pointer to struct git_hash_algo. */
+static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
+{
+       return p - hash_algos;
+}
+
 #endif
diff --git a/hex.c b/hex.c
index 10af1a29e80f903fb95cbeb71be00e5fdd705e66..7850a8879d5e0a00c0e89e197427cafa23d8e865 100644 (file)
--- a/hex.c
+++ b/hex.c
@@ -73,14 +73,15 @@ int parse_oid_hex(const char *hex, struct object_id *oid, const char **end)
        return ret;
 }
 
-char *sha1_to_hex_r(char *buffer, const unsigned char *sha1)
+char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash,
+                         const struct git_hash_algo *algop)
 {
        static const char hex[] = "0123456789abcdef";
        char *buf = buffer;
        int i;
 
-       for (i = 0; i < the_hash_algo->rawsz; i++) {
-               unsigned int val = *sha1++;
+       for (i = 0; i < algop->rawsz; i++) {
+               unsigned int val = *hash++;
                *buf++ = hex[val >> 4];
                *buf++ = hex[val & 0xf];
        }
@@ -89,20 +90,35 @@ char *sha1_to_hex_r(char *buffer, const unsigned char *sha1)
        return buffer;
 }
 
+char *sha1_to_hex_r(char *buffer, const unsigned char *sha1)
+{
+       return hash_to_hex_algop_r(buffer, sha1, &hash_algos[GIT_HASH_SHA1]);
+}
+
 char *oid_to_hex_r(char *buffer, const struct object_id *oid)
 {
-       return sha1_to_hex_r(buffer, oid->hash);
+       return hash_to_hex_algop_r(buffer, oid->hash, the_hash_algo);
 }
 
-char *sha1_to_hex(const unsigned char *sha1)
+char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *algop)
 {
        static int bufno;
        static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
        bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
-       return sha1_to_hex_r(hexbuffer[bufno], sha1);
+       return hash_to_hex_algop_r(hexbuffer[bufno], hash, algop);
+}
+
+char *sha1_to_hex(const unsigned char *sha1)
+{
+       return hash_to_hex_algop(sha1, &hash_algos[GIT_HASH_SHA1]);
+}
+
+char *hash_to_hex(const unsigned char *hash)
+{
+       return hash_to_hex_algop(hash, the_hash_algo);
 }
 
 char *oid_to_hex(const struct object_id *oid)
 {
-       return sha1_to_hex(oid->hash);
+       return hash_to_hex_algop(oid->hash, the_hash_algo);
 }
index cd485909127a79afcbb58ef18cd28977b65efb79..77e2e22852d769a04dc0275498964eff86e362d8 100644 (file)
@@ -1311,11 +1311,11 @@ static struct object_list **process_tree(struct tree *tree,
        while (tree_entry(&desc, &entry))
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
-                       p = process_tree(lookup_tree(the_repository, entry.oid),
+                       p = process_tree(lookup_tree(the_repository, &entry.oid),
                                         p);
                        break;
                case OBJ_BLOB:
-                       p = process_blob(lookup_blob(the_repository, entry.oid),
+                       p = process_blob(lookup_blob(the_repository, &entry.oid),
                                         p);
                        break;
                default:
@@ -1933,7 +1933,7 @@ int cmd_main(int argc, const char **argv)
                pushing = 0;
                if (prepare_revision_walk(&revs))
                        die("revision walk setup failed");
-               mark_edges_uninteresting(&revs, NULL);
+               mark_edges_uninteresting(&revs, NULL, 0);
                objects_to_send = get_delta(&revs, ref_lock);
                finish_all_active_slots();
 
diff --git a/http.c b/http.c
index 0b6807cef9aa0994be486581ecf18f7829ee4e19..954bebf6842510ea3fb83334ffe2684ade072f05 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1876,8 +1876,6 @@ static int http_request(const char *url,
        strbuf_addstr(&buf, "Pragma:");
        if (options && options->no_cache)
                strbuf_addstr(&buf, " no-cache");
-       if (options && options->keep_error)
-               curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0);
        if (options && options->initial_request &&
            http_follow_config == HTTP_FOLLOW_INITIAL)
                curl_easy_setopt(slot->curl, CURLOPT_FOLLOWLOCATION, 1);
@@ -1895,6 +1893,7 @@ static int http_request(const char *url,
        curl_easy_setopt(slot->curl, CURLOPT_URL, url);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
        curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
+       curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0);
 
        ret = run_one_slot(slot, &results);
 
@@ -1989,19 +1988,26 @@ static int http_request_reauth(const char *url,
                return ret;
 
        /*
-        * If we are using KEEP_ERROR, the previous request may have
-        * put cruft into our output stream; we should clear it out before
-        * making our next request. We only know how to do this for
-        * the strbuf case, but that is enough to satisfy current callers.
+        * The previous request may have put cruft into our output stream; we
+        * should clear it out before making our next request.
         */
-       if (options && options->keep_error) {
-               switch (target) {
-               case HTTP_REQUEST_STRBUF:
-                       strbuf_reset(result);
-                       break;
-               default:
-                       BUG("HTTP_KEEP_ERROR is only supported with strbufs");
+       switch (target) {
+       case HTTP_REQUEST_STRBUF:
+               strbuf_reset(result);
+               break;
+       case HTTP_REQUEST_FILE:
+               if (fflush(result)) {
+                       error_errno("unable to flush a file");
+                       return HTTP_START_FAILED;
                }
+               rewind(result);
+               if (ftruncate(fileno(result), 0) < 0) {
+                       error_errno("unable to truncate a file");
+                       return HTTP_START_FAILED;
+               }
+               break;
+       default:
+               BUG("Unknown http_request target");
        }
 
        credential_fill(&http_auth);
diff --git a/http.h b/http.h
index d305ca1dc7a3f931a81353c56060e98f4039c692..eebf40688cf6f695d12f9fe78e8e6b99bb44a8c4 100644 (file)
--- a/http.h
+++ b/http.h
@@ -146,7 +146,6 @@ extern char *get_remote_object_url(const char *url, const char *hex,
 /* Options for http_get_*() */
 struct http_get_options {
        unsigned no_cache:1,
-                keep_error:1,
                 initial_request:1;
 
        /* If non-NULL, returns the content-type of the response. */
index e8da2e8581b2df956411f19e796ceb94adcef903..b71bd1fb65bc6b9d6c6889b7dcf8d210d57f1e53 100644 (file)
@@ -18,8 +18,9 @@
  * 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.
+ * subordinate commands when necessary (although it's better to pass it through
+ * expand_list_objects_filter_spec() first).  We also "intern" the arg for the
+ * convenience of the current command.
  */
 static int gently_parse_list_objects_filter(
        struct list_objects_filter_options *filter_options,
@@ -50,16 +51,15 @@ static int gently_parse_list_objects_filter(
                }
 
        } else if (skip_prefix(arg, "tree:", &v0)) {
-               unsigned long depth;
-               if (!git_parse_ulong(v0, &depth) || depth != 0) {
+               if (!git_parse_ulong(v0, &filter_options->tree_exclude_depth)) {
                        if (errbuf) {
                                strbuf_addstr(
                                        errbuf,
-                                       _("only 'tree:0' is supported"));
+                                       _("expected 'tree:<depth>'"));
                        }
                        return 1;
                }
-               filter_options->choice = LOFC_TREE_NONE;
+               filter_options->choice = LOFC_TREE_DEPTH;
                return 0;
 
        } else if (skip_prefix(arg, "sparse:oid=", &v0)) {
@@ -71,7 +71,7 @@ static int gently_parse_list_objects_filter(
                 * command, but DO NOT complain if we don't have the blob or
                 * ref locally.
                 */
-               if (!get_oid_with_context(v0, GET_OID_BLOB,
+               if (!get_oid_with_context(the_repository, v0, GET_OID_BLOB,
                                          &sparse_oid, &oc))
                        filter_options->sparse_oid_value = oiddup(&sparse_oid);
                filter_options->choice = LOFC_SPARSE_OID;
@@ -112,6 +112,21 @@ int opt_parse_list_objects_filter(const struct option *opt,
        return parse_list_objects_filter(filter_options, arg);
 }
 
+void expand_list_objects_filter_spec(
+       const struct list_objects_filter_options *filter,
+       struct strbuf *expanded_spec)
+{
+       strbuf_init(expanded_spec, strlen(filter->filter_spec));
+       if (filter->choice == LOFC_BLOB_LIMIT)
+               strbuf_addf(expanded_spec, "blob:limit=%lu",
+                           filter->blob_limit_value);
+       else if (filter->choice == LOFC_TREE_DEPTH)
+               strbuf_addf(expanded_spec, "tree:%lu",
+                           filter->tree_exclude_depth);
+       else
+               strbuf_addstr(expanded_spec, filter->filter_spec);
+}
+
 void list_objects_filter_release(
        struct list_objects_filter_options *filter_options)
 {
index af64e5c66fc4a242f9cc534380a9b3e8f1e67d00..e3adc78ebf74717d3b4e544c5bbb5215d9402a92 100644 (file)
@@ -2,6 +2,7 @@
 #define LIST_OBJECTS_FILTER_OPTIONS_H
 
 #include "parse-options.h"
+#include "strbuf.h"
 
 /*
  * The list of defined filters for list-objects.
@@ -10,7 +11,7 @@ enum list_objects_filter_choice {
        LOFC_DISABLED = 0,
        LOFC_BLOB_NONE,
        LOFC_BLOB_LIMIT,
-       LOFC_TREE_NONE,
+       LOFC_TREE_DEPTH,
        LOFC_SPARSE_OID,
        LOFC_SPARSE_PATH,
        LOFC__COUNT /* must be last */
@@ -20,8 +21,9 @@ 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.
+        * commands that launch filtering sub-processes, or for communication
+        * over the network, don't use this value; use the result of
+        * expand_list_objects_filter_spec() instead.
         */
        char *filter_spec;
 
@@ -44,6 +46,7 @@ struct list_objects_filter_options {
        struct object_id *sparse_oid_value;
        char *sparse_path_value;
        unsigned long blob_limit_value;
+       unsigned long tree_exclude_depth;
 };
 
 /* Normalized command line arguments */
@@ -61,6 +64,17 @@ int opt_parse_list_objects_filter(const struct option *opt,
          N_("object filtering"), 0, \
          opt_parse_list_objects_filter }
 
+/*
+ * Translates abbreviated numbers in the filter's filter_spec into their
+ * fully-expanded forms (e.g., "limit:blob=1k" becomes "limit:blob=1024").
+ *
+ * This form should be used instead of the raw filter_spec field when
+ * communicating with a remote process or subprocess.
+ */
+void expand_list_objects_filter_spec(
+       const struct list_objects_filter_options *filter,
+       struct strbuf *expanded_spec);
+
 void list_objects_filter_release(
        struct list_objects_filter_options *filter_options);
 
index a62624a1ced704156395b3e30312f264aa46b862..ee449de3f77e2b8663d1ae2d43da049f15269249 100644 (file)
@@ -10,6 +10,7 @@
 #include "list-objects.h"
 #include "list-objects-filter.h"
 #include "list-objects-filter-options.h"
+#include "oidmap.h"
 #include "oidset.h"
 #include "object-store.h"
 
@@ -84,11 +85,44 @@ static void *filter_blobs_none__init(
  * A filter for list-objects to omit ALL trees and blobs from the traversal.
  * Can OPTIONALLY collect a list of the omitted OIDs.
  */
-struct filter_trees_none_data {
+struct filter_trees_depth_data {
        struct oidset *omits;
+
+       /*
+        * Maps trees to the minimum depth at which they were seen. It is not
+        * necessary to re-traverse a tree at deeper or equal depths than it has
+        * already been traversed.
+        *
+        * We can't use LOFR_MARK_SEEN for tree objects since this will prevent
+        * it from being traversed at shallower depths.
+        */
+       struct oidmap seen_at_depth;
+
+       unsigned long exclude_depth;
+       unsigned long current_depth;
 };
 
-static enum list_objects_filter_result filter_trees_none(
+struct seen_map_entry {
+       struct oidmap_entry base;
+       size_t depth;
+};
+
+/* Returns 1 if the oid was in the omits set before it was invoked. */
+static int filter_trees_update_omits(
+       struct object *obj,
+       struct filter_trees_depth_data *filter_data,
+       int include_it)
+{
+       if (!filter_data->omits)
+               return 0;
+
+       if (include_it)
+               return oidset_remove(filter_data->omits, &obj->oid);
+       else
+               return oidset_insert(filter_data->omits, &obj->oid);
+}
+
+static enum list_objects_filter_result filter_trees_depth(
        struct repository *r,
        enum list_objects_filter_situation filter_situation,
        struct object *obj,
@@ -96,43 +130,91 @@ static enum list_objects_filter_result filter_trees_none(
        const char *filename,
        void *filter_data_)
 {
-       struct filter_trees_none_data *filter_data = filter_data_;
+       struct filter_trees_depth_data *filter_data = filter_data_;
+       struct seen_map_entry *seen_info;
+       int include_it = filter_data->current_depth <
+               filter_data->exclude_depth;
+       int filter_res;
+       int already_seen;
+
+       /*
+        * Note that we do not use _MARK_SEEN in order to allow re-traversal in
+        * case we encounter a tree or blob again at a shallower depth.
+        */
 
        switch (filter_situation) {
        default:
                BUG("unknown filter_situation: %d", filter_situation);
 
-       case LOFS_BEGIN_TREE:
+       case LOFS_END_TREE:
+               assert(obj->type == OBJ_TREE);
+               filter_data->current_depth--;
+               return LOFR_ZERO;
+
        case LOFS_BLOB:
-               if (filter_data->omits) {
-                       oidset_insert(filter_data->omits, &obj->oid);
-                       /* _MARK_SEEN but not _DO_SHOW (hard omit) */
-                       return LOFR_MARK_SEEN;
+               filter_trees_update_omits(obj, filter_data, include_it);
+               return include_it ? LOFR_MARK_SEEN | LOFR_DO_SHOW : LOFR_ZERO;
+
+       case LOFS_BEGIN_TREE:
+               seen_info = oidmap_get(
+                       &filter_data->seen_at_depth, &obj->oid);
+               if (!seen_info) {
+                       seen_info = xcalloc(1, sizeof(*seen_info));
+                       oidcpy(&seen_info->base.oid, &obj->oid);
+                       seen_info->depth = filter_data->current_depth;
+                       oidmap_put(&filter_data->seen_at_depth, seen_info);
+                       already_seen = 0;
                } else {
-                       /*
-                        * Not collecting omits so no need to to traverse tree.
-                        */
-                       return LOFR_SKIP_TREE | LOFR_MARK_SEEN;
+                       already_seen =
+                               filter_data->current_depth >= seen_info->depth;
                }
 
-       case LOFS_END_TREE:
-               assert(obj->type == OBJ_TREE);
-               return LOFR_ZERO;
+               if (already_seen) {
+                       filter_res = LOFR_SKIP_TREE;
+               } else {
+                       int been_omitted = filter_trees_update_omits(
+                               obj, filter_data, include_it);
+                       seen_info->depth = filter_data->current_depth;
+
+                       if (include_it)
+                               filter_res = LOFR_DO_SHOW;
+                       else if (filter_data->omits && !been_omitted)
+                               /*
+                                * Must update omit information of children
+                                * recursively; they have not been omitted yet.
+                                */
+                               filter_res = LOFR_ZERO;
+                       else
+                               filter_res = LOFR_SKIP_TREE;
+               }
 
+               filter_data->current_depth++;
+               return filter_res;
        }
 }
 
-static void* filter_trees_none__init(
+static void filter_trees_free(void *filter_data) {
+       struct filter_trees_depth_data *d = filter_data;
+       if (!d)
+               return;
+       oidmap_free(&d->seen_at_depth, 1);
+       free(d);
+}
+
+static void *filter_trees_depth__init(
        struct oidset *omitted,
        struct list_objects_filter_options *filter_options,
        filter_object_fn *filter_fn,
        filter_free_fn *filter_free_fn)
 {
-       struct filter_trees_none_data *d = xcalloc(1, sizeof(*d));
+       struct filter_trees_depth_data *d = xcalloc(1, sizeof(*d));
        d->omits = omitted;
+       oidmap_init(&d->seen_at_depth, 0);
+       d->exclude_depth = filter_options->tree_exclude_depth;
+       d->current_depth = 0;
 
-       *filter_fn = filter_trees_none;
-       *filter_free_fn = free;
+       *filter_fn = filter_trees_depth;
+       *filter_free_fn = filter_trees_free;
        return d;
 }
 
@@ -430,7 +512,7 @@ static filter_init_fn s_filters[] = {
        NULL,
        filter_blobs_none__init,
        filter_blobs_limit__init,
-       filter_trees_none__init,
+       filter_trees_depth__init,
        filter_sparse_oid__init,
        filter_sparse_path__init,
 };
index 4e2789768d21ccb47a8fe2d5de62b6be58ea9bb7..dc77361e11d02a4eaa994f4351310a0d54d33ef6 100644 (file)
@@ -124,15 +124,15 @@ static void process_tree_contents(struct traversal_context *ctx,
                }
 
                if (S_ISDIR(entry.mode)) {
-                       struct tree *t = lookup_tree(ctx->revs->repo, entry.oid);
+                       struct tree *t = lookup_tree(ctx->revs->repo, &entry.oid);
                        t->object.flags |= NOT_USER_GIVEN;
                        process_tree(ctx, t, base, entry.path);
                }
                else if (S_ISGITLINK(entry.mode))
-                       process_gitlink(ctx, entry.oid->hash,
+                       process_gitlink(ctx, entry.oid.hash,
                                        base, entry.path);
                else {
-                       struct blob *b = lookup_blob(ctx->revs->repo, entry.oid);
+                       struct blob *b = lookup_blob(ctx->revs->repo, &entry.oid);
                        b->object.flags |= NOT_USER_GIVEN;
                        process_blob(ctx, b, base, entry.path);
                }
@@ -226,25 +226,73 @@ static void mark_edge_parents_uninteresting(struct commit *commit,
        }
 }
 
-void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
+static void add_edge_parents(struct commit *commit,
+                            struct rev_info *revs,
+                            show_edge_fn show_edge,
+                            struct oidset *set)
+{
+       struct commit_list *parents;
+
+       for (parents = commit->parents; parents; parents = parents->next) {
+               struct commit *parent = parents->item;
+               struct tree *tree = get_commit_tree(parent);
+
+               if (!tree)
+                       continue;
+
+               oidset_insert(set, &tree->object.oid);
+
+               if (!(parent->object.flags & UNINTERESTING))
+                       continue;
+               tree->object.flags |= UNINTERESTING;
+
+               if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
+                       parent->object.flags |= SHOWN;
+                       show_edge(parent);
+               }
+       }
+}
+
+void mark_edges_uninteresting(struct rev_info *revs,
+                             show_edge_fn show_edge,
+                             int sparse)
 {
        struct commit_list *list;
        int i;
 
-       for (list = revs->commits; list; list = list->next) {
-               struct commit *commit = list->item;
+       if (sparse) {
+               struct oidset set;
+               oidset_init(&set, 16);
 
-               if (commit->object.flags & UNINTERESTING) {
-                       mark_tree_uninteresting(revs->repo,
-                                               get_commit_tree(commit));
-                       if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
-                               commit->object.flags |= SHOWN;
-                               show_edge(commit);
+               for (list = revs->commits; list; list = list->next) {
+                       struct commit *commit = list->item;
+                       struct tree *tree = get_commit_tree(commit);
+
+                       if (commit->object.flags & UNINTERESTING)
+                               tree->object.flags |= UNINTERESTING;
+
+                       oidset_insert(&set, &tree->object.oid);
+                       add_edge_parents(commit, revs, show_edge, &set);
+               }
+
+               mark_trees_uninteresting_sparse(revs->repo, &set);
+               oidset_clear(&set);
+       } else {
+               for (list = revs->commits; list; list = list->next) {
+                       struct commit *commit = list->item;
+                       if (commit->object.flags & UNINTERESTING) {
+                               mark_tree_uninteresting(revs->repo,
+                                                       get_commit_tree(commit));
+                               if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
+                                       commit->object.flags |= SHOWN;
+                                       show_edge(commit);
+                               }
+                               continue;
                        }
-                       continue;
+                       mark_edge_parents_uninteresting(commit, revs, show_edge);
                }
-               mark_edge_parents_uninteresting(commit, revs, show_edge);
        }
+
        if (revs->edge_hint_aggressive) {
                for (i = 0; i < revs->cmdline.nr; i++) {
                        struct object *obj = revs->cmdline.rev[i].item;
index ad407629269a7e7c77953390beccf036fd2452f6..a952680e46671db2543bc4abff78a2d898cd1408 100644 (file)
@@ -10,7 +10,9 @@ typedef void (*show_object_fn)(struct object *, const char *, void *);
 void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, void *);
 
 typedef void (*show_edge_fn)(struct commit *);
-void mark_edges_uninteresting(struct rev_info *, show_edge_fn);
+void mark_edges_uninteresting(struct rev_info *revs,
+                             show_edge_fn show_edge,
+                             int sparse);
 
 struct oidset;
 struct list_objects_filter_options;
index 10680c139eeb530bc0e70e0c1713767b6ca5be21..3cb14256ec5b7a2712e23b8feb12b1a91328bc34 100644 (file)
@@ -700,6 +700,7 @@ void show_log(struct rev_info *opt)
        ctx.color = opt->diffopt.use_color;
        ctx.expand_tabs_in_log = opt->expand_tabs_in_log;
        ctx.output_encoding = get_log_output_encoding();
+       ctx.rev = opt;
        if (opt->from_ident.mail_begin && opt->from_ident.name_begin)
                ctx.from_ident = &opt->from_ident;
        if (opt->graph)
index a06f12eca8d6f9816c481f1f445791388d53039c..0a7dbc6442fad37fd9e2ce72866b04b134818181 100644 (file)
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -5,6 +5,7 @@
 #include "argv-array.h"
 #include "ls-refs.h"
 #include "pkt-line.h"
+#include "config.h"
 
 /*
  * Check if one of the prefixes is a prefix of the ref.
@@ -40,7 +41,10 @@ static int send_ref(const char *refname, const struct object_id *oid,
        const char *refname_nons = strip_namespace(refname);
        struct strbuf refline = STRBUF_INIT;
 
-       if (!ref_match(&data->prefixes, refname))
+       if (ref_is_hidden(refname_nons, refname))
+               return 0;
+
+       if (!ref_match(&data->prefixes, refname_nons))
                return 0;
 
        strbuf_addf(&refline, "%s %s", oid_to_hex(oid), refname_nons);
@@ -69,6 +73,16 @@ static int send_ref(const char *refname, const struct object_id *oid,
        return 0;
 }
 
+static int ls_refs_config(const char *var, const char *value, void *data)
+{
+       /*
+        * We only serve fetches over v2 for now, so respect only "uploadpack"
+        * config. This may need to eventually be expanded to "receive", but we
+        * don't yet know how that information will be passed to ls-refs.
+        */
+       return parse_hide_refs_config(var, value, "uploadpack");
+}
+
 int ls_refs(struct repository *r, struct argv_array *keys,
            struct packet_reader *request)
 {
@@ -76,6 +90,8 @@ int ls_refs(struct repository *r, struct argv_array *keys,
 
        memset(&data, 0, sizeof(data));
 
+       git_config(ls_refs_config, NULL);
+
        while (packet_reader_read(request) != PACKET_READ_FLUSH) {
                const char *arg = request->line;
                const char *out;
index 2b6d31ef9d35d9422e7ef90792651dcb7a2f9189..ddc4d398456363cede9f3f5d4fa602efb402b5bd 100644 (file)
@@ -3,7 +3,7 @@
 #include "tree-walk.h"
 #include "object-store.h"
 
-static int score_missing(unsigned mode, const char *path)
+static int score_missing(unsigned mode)
 {
        int score;
 
@@ -16,7 +16,7 @@ static int score_missing(unsigned mode, const char *path)
        return score;
 }
 
-static int score_differs(unsigned mode1, unsigned mode2, const char *path)
+static int score_differs(unsigned mode1, unsigned mode2)
 {
        int score;
 
@@ -29,7 +29,7 @@ static int score_differs(unsigned mode1, unsigned mode2, const char *path)
        return score;
 }
 
-static int score_matches(unsigned mode1, unsigned mode2, const char *path)
+static int score_matches(unsigned mode1, unsigned mode2)
 {
        int score;
 
@@ -98,24 +98,22 @@ static int score_trees(const struct object_id *hash1, const struct object_id *ha
 
                if (cmp < 0) {
                        /* path1 does not appear in two */
-                       score += score_missing(one.entry.mode, one.entry.path);
+                       score += score_missing(one.entry.mode);
                        update_tree_entry(&one);
                } else if (cmp > 0) {
                        /* path2 does not appear in one */
-                       score += score_missing(two.entry.mode, two.entry.path);
+                       score += score_missing(two.entry.mode);
                        update_tree_entry(&two);
                } else {
                        /* path appears in both */
-                       if (!oideq(one.entry.oid, two.entry.oid)) {
+                       if (!oideq(&one.entry.oid, &two.entry.oid)) {
                                /* they are different */
                                score += score_differs(one.entry.mode,
-                                                      two.entry.mode,
-                                                      one.entry.path);
+                                                      two.entry.mode);
                        } else {
                                /* same subtree or blob */
                                score += score_matches(one.entry.mode,
-                                                      two.entry.mode,
-                                                      one.entry.path);
+                                                      two.entry.mode);
                        }
                        update_tree_entry(&one);
                        update_tree_entry(&two);
@@ -179,7 +177,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
        char *buf;
        unsigned long sz;
        struct tree_desc desc;
-       struct object_id *rewrite_here;
+       unsigned char *rewrite_here;
        const struct object_id *rewrite_with;
        struct object_id subtree;
        enum object_type type;
@@ -199,15 +197,26 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
        while (desc.size) {
                const char *name;
                unsigned mode;
-               const struct object_id *oid;
 
-               oid = tree_entry_extract(&desc, &name, &mode);
+               tree_entry_extract(&desc, &name, &mode);
                if (strlen(name) == toplen &&
                    !memcmp(name, prefix, toplen)) {
                        if (!S_ISDIR(mode))
                                die("entry %s in tree %s is not a tree", name,
                                    oid_to_hex(oid1));
-                       rewrite_here = (struct object_id *)oid;
+
+                       /*
+                        * We cast here for two reasons:
+                        *
+                        *   - to flip the "char *" (for the path) to "unsigned
+                        *     char *" (for the hash stored after it)
+                        *
+                        *   - to discard the "const"; this is OK because we
+                        *     know it points into our non-const "buf"
+                        */
+                       rewrite_here = (unsigned char *)(desc.entry.path +
+                                                        strlen(desc.entry.path) +
+                                                        1);
                        break;
                }
                update_tree_entry(&desc);
@@ -216,14 +225,16 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
                die("entry %.*s not found in tree %s", toplen, prefix,
                    oid_to_hex(oid1));
        if (*subpath) {
-               status = splice_tree(rewrite_here, subpath, oid2, &subtree);
+               struct object_id tree_oid;
+               hashcpy(tree_oid.hash, rewrite_here);
+               status = splice_tree(&tree_oid, subpath, oid2, &subtree);
                if (status)
                        return status;
                rewrite_with = &subtree;
        } else {
                rewrite_with = oid2;
        }
-       oidcpy(rewrite_here, rewrite_with);
+       hashcpy(rewrite_here, rewrite_with->hash);
        status = write_object_file(buf, sz, tree_type, result);
        free(buf);
        return status;
index 59ba4b4a1a083b07050c5e6eba8306cb63736a3e..4851825aebf29d129aa4b82d860adcbb2697a300 100644 (file)
@@ -146,7 +146,8 @@ static int err(struct merge_options *o, const char *err, ...)
        return -1;
 }
 
-static struct tree *shift_tree_object(struct tree *one, struct tree *two,
+static struct tree *shift_tree_object(struct repository *repo,
+                                     struct tree *one, struct tree *two,
                                      const char *subtree_shift)
 {
        struct object_id shifted;
@@ -159,12 +160,14 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
        }
        if (oideq(&two->object.oid, &shifted))
                return two;
-       return lookup_tree(the_repository, &shifted);
+       return lookup_tree(repo, &shifted);
 }
 
-static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
+static struct commit *make_virtual_commit(struct repository *repo,
+                                         struct tree *tree,
+                                         const char *comment)
 {
-       struct commit *commit = alloc_commit_node(the_repository);
+       struct commit *commit = alloc_commit_node(repo);
 
        set_merge_remote_desc(commit, comment, (struct object *)commit);
        commit->maybe_tree = tree;
@@ -343,22 +346,24 @@ static int add_cacheinfo(struct merge_options *o,
                         unsigned int mode, const struct object_id *oid,
                         const char *path, int stage, int refresh, int options)
 {
+       struct index_state *istate = o->repo->index;
        struct cache_entry *ce;
        int ret;
 
-       ce = make_cache_entry(&the_index, mode, oid ? oid : &null_oid, path, stage, 0);
+       ce = make_cache_entry(istate, mode, oid ? oid : &null_oid, path, stage, 0);
        if (!ce)
                return err(o, _("add_cacheinfo failed for path '%s'; merge aborting."), path);
 
-       ret = add_cache_entry(ce, options);
+       ret = add_index_entry(istate, ce, options);
        if (refresh) {
                struct cache_entry *nce;
 
-               nce = refresh_cache_entry(&the_index, ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);
+               nce = refresh_cache_entry(istate, ce,
+                                         CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);
                if (!nce)
                        return err(o, _("add_cacheinfo failed to refresh for path '%s'; merge aborting."), path);
                if (nce != ce)
-                       ret = add_cache_entry(nce, options);
+                       ret = add_index_entry(istate, nce, options);
        }
        return ret;
 }
@@ -386,7 +391,7 @@ static int unpack_trees_start(struct merge_options *o,
        o->unpack_opts.merge = 1;
        o->unpack_opts.head_idx = 2;
        o->unpack_opts.fn = threeway_merge;
-       o->unpack_opts.src_index = &the_index;
+       o->unpack_opts.src_index = o->repo->index;
        o->unpack_opts.dst_index = &tmp_index;
        o->unpack_opts.aggressive = !merge_detect_rename(o);
        setup_unpack_trees_porcelain(&o->unpack_opts, "merge");
@@ -396,16 +401,16 @@ static int unpack_trees_start(struct merge_options *o,
        init_tree_desc_from_tree(t+2, merge);
 
        rc = unpack_trees(3, t, &o->unpack_opts);
-       cache_tree_free(&active_cache_tree);
+       cache_tree_free(&o->repo->index->cache_tree);
 
        /*
-        * Update the_index to match the new results, AFTER saving a copy
+        * Update o->repo->index to match the new results, AFTER saving a copy
         * in o->orig_index.  Update src_index to point to the saved copy.
         * (verify_uptodate() checks src_index, and the original index is
         * the one that had the necessary modification timestamps.)
         */
-       o->orig_index = the_index;
-       the_index = tmp_index;
+       o->orig_index = *o->repo->index;
+       *o->repo->index = tmp_index;
        o->unpack_opts.src_index = &o->orig_index;
 
        return rc;
@@ -420,12 +425,13 @@ static void unpack_trees_finish(struct merge_options *o)
 struct tree *write_tree_from_memory(struct merge_options *o)
 {
        struct tree *result = NULL;
+       struct index_state *istate = o->repo->index;
 
-       if (unmerged_cache()) {
+       if (unmerged_index(istate)) {
                int i;
                fprintf(stderr, "BUG: There are unmerged index entries:\n");
-               for (i = 0; i < active_nr; i++) {
-                       const struct cache_entry *ce = active_cache[i];
+               for (i = 0; i < istate->cache_nr; i++) {
+                       const struct cache_entry *ce = istate->cache[i];
                        if (ce_stage(ce))
                                fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce),
                                        (int)ce_namelen(ce), ce->name);
@@ -433,16 +439,16 @@ struct tree *write_tree_from_memory(struct merge_options *o)
                BUG("unmerged index entries in merge-recursive.c");
        }
 
-       if (!active_cache_tree)
-               active_cache_tree = cache_tree();
+       if (!istate->cache_tree)
+               istate->cache_tree = cache_tree();
 
-       if (!cache_tree_fully_valid(active_cache_tree) &&
-           cache_tree_update(&the_index, 0) < 0) {
+       if (!cache_tree_fully_valid(istate->cache_tree) &&
+           cache_tree_update(istate, 0) < 0) {
                err(o, _("error building trees"));
                return NULL;
        }
 
-       result = lookup_tree(the_repository, &active_cache_tree->oid);
+       result = lookup_tree(o->repo, &istate->cache_tree->oid);
 
        return result;
 }
@@ -513,17 +519,17 @@ static struct stage_data *insert_stage_data(const char *path,
  * Create a dictionary mapping file names to stage_data objects. The
  * dictionary contains one entry for every path with a non-zero stage entry.
  */
-static struct string_list *get_unmerged(void)
+static struct string_list *get_unmerged(struct index_state *istate)
 {
        struct string_list *unmerged = xcalloc(1, sizeof(struct string_list));
        int i;
 
        unmerged->strdup_strings = 1;
 
-       for (i = 0; i < active_nr; i++) {
+       for (i = 0; i < istate->cache_nr; i++) {
                struct string_list_item *item;
                struct stage_data *e;
-               const struct cache_entry *ce = active_cache[i];
+               const struct cache_entry *ce = istate->cache[i];
                if (!ce_stage(ce))
                        continue;
 
@@ -683,7 +689,7 @@ static int update_stages(struct merge_options *opt, const char *path,
        int clear = 1;
        int options = ADD_CACHE_OK_TO_ADD | ADD_CACHE_SKIP_DFCHECK;
        if (clear)
-               if (remove_file_from_cache(path))
+               if (remove_file_from_index(opt->repo->index, path))
                        return -1;
        if (o)
                if (add_cacheinfo(opt, o->mode, &o->oid, path, 1, 0, options))
@@ -718,13 +724,14 @@ static int remove_file(struct merge_options *o, int clean,
        int update_working_directory = !o->call_depth && !no_wd;
 
        if (update_cache) {
-               if (remove_file_from_cache(path))
+               if (remove_file_from_index(o->repo->index, path))
                        return -1;
        }
        if (update_working_directory) {
                if (ignore_case) {
                        struct cache_entry *ce;
-                       ce = cache_file_exists(path, strlen(path), ignore_case);
+                       ce = index_file_exists(o->repo->index, path, strlen(path),
+                                              ignore_case);
                        if (ce && ce_stage(ce) == 0 && strcmp(path, ce->name))
                                return 0;
                }
@@ -774,7 +781,8 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
  * check the working directory.  If empty_ok is non-zero, also return
  * 0 in the case where the working-tree dir exists but is empty.
  */
-static int dir_in_way(const char *path, int check_working_copy, int empty_ok)
+static int dir_in_way(struct index_state *istate, const char *path,
+                     int check_working_copy, int empty_ok)
 {
        int pos;
        struct strbuf dirpath = STRBUF_INIT;
@@ -783,12 +791,12 @@ static int dir_in_way(const char *path, int check_working_copy, int empty_ok)
        strbuf_addstr(&dirpath, path);
        strbuf_addch(&dirpath, '/');
 
-       pos = cache_name_pos(dirpath.buf, dirpath.len);
+       pos = index_name_pos(istate, dirpath.buf, dirpath.len);
 
        if (pos < 0)
                pos = -1 - pos;
-       if (pos < active_nr &&
-           !strncmp(dirpath.buf, active_cache[pos]->name, dirpath.len)) {
+       if (pos < istate->cache_nr &&
+           !strncmp(dirpath.buf, istate->cache[pos]->name, dirpath.len)) {
                strbuf_release(&dirpath);
                return 1;
        }
@@ -831,8 +839,10 @@ static int was_tracked(struct merge_options *o, const char *path)
        return 0;
 }
 
-static int would_lose_untracked(const char *path)
+static int would_lose_untracked(struct merge_options *o, const char *path)
 {
+       struct index_state *istate = o->repo->index;
+
        /*
         * This may look like it can be simplified to:
         *   return !was_tracked(o, path) && file_exists(path)
@@ -850,19 +860,19 @@ static int would_lose_untracked(const char *path)
         * update_file()/would_lose_untracked(); see every comment in this
         * file which mentions "update_stages".
         */
-       int pos = cache_name_pos(path, strlen(path));
+       int pos = index_name_pos(istate, path, strlen(path));
 
        if (pos < 0)
                pos = -1 - pos;
-       while (pos < active_nr &&
-              !strcmp(path, active_cache[pos]->name)) {
+       while (pos < istate->cache_nr &&
+              !strcmp(path, istate->cache[pos]->name)) {
                /*
                 * If stage #0, it is definitely tracked.
                 * If it has stage #2 then it was tracked
                 * before this merge started.  All other
                 * cases the path was not tracked.
                 */
-               switch (ce_stage(active_cache[pos])) {
+               switch (ce_stage(istate->cache[pos])) {
                case 0:
                case 2:
                        return 0;
@@ -922,7 +932,7 @@ static int make_room_for_path(struct merge_options *o, const char *path)
         * Do not unlink a file in the work tree if we are not
         * tracking it.
         */
-       if (would_lose_untracked(path))
+       if (would_lose_untracked(o, path))
                return err(o, _("refusing to lose untracked file at '%s'"),
                           path);
 
@@ -972,7 +982,7 @@ static int update_file_flags(struct merge_options *o,
                }
                if (S_ISREG(mode)) {
                        struct strbuf strbuf = STRBUF_INIT;
-                       if (convert_to_working_tree(&the_index, path, buf, size, &strbuf)) {
+                       if (convert_to_working_tree(o->repo->index, path, buf, size, &strbuf)) {
                                free(buf);
                                size = strbuf.len;
                                buf = strbuf_detach(&strbuf, NULL);
@@ -1092,7 +1102,7 @@ static int merge_3way(struct merge_options *o,
 
        merge_status = ll_merge(result_buf, a->path, &orig, base_name,
                                &src1, name1, &src2, name2,
-                               &the_index, &ll_opts);
+                               o->repo->index, &ll_opts);
 
        free(base_name);
        free(name1);
@@ -1103,7 +1113,8 @@ static int merge_3way(struct merge_options *o,
        return merge_status;
 }
 
-static int find_first_merges(struct object_array *result, const char *path,
+static int find_first_merges(struct repository *repo,
+                            struct object_array *result, const char *path,
                             struct commit *a, struct commit *b)
 {
        int i, j;
@@ -1123,7 +1134,7 @@ static int find_first_merges(struct object_array *result, const char *path,
        /* get all revisions that merge commit a */
        xsnprintf(merged_revision, sizeof(merged_revision), "^%s",
                  oid_to_hex(&a->object.oid));
-       repo_init_revisions(the_repository, &revs, NULL);
+       repo_init_revisions(repo, &revs, NULL);
        rev_opts.submodule = path;
        /* FIXME: can't handle linked worktrees in submodules yet */
        revs.single_worktree = path != NULL;
@@ -1201,9 +1212,9 @@ static int merge_submodule(struct merge_options *o,
                return 0;
        }
 
-       if (!(commit_base = lookup_commit_reference(the_repository, base)) ||
-           !(commit_a = lookup_commit_reference(the_repository, a)) ||
-           !(commit_b = lookup_commit_reference(the_repository, b))) {
+       if (!(commit_base = lookup_commit_reference(o->repo, base)) ||
+           !(commit_a = lookup_commit_reference(o->repo, a)) ||
+           !(commit_b = lookup_commit_reference(o->repo, b))) {
                output(o, 1, _("Failed to merge submodule %s (commits not present)"), path);
                return 0;
        }
@@ -1253,7 +1264,8 @@ static int merge_submodule(struct merge_options *o,
                return 0;
 
        /* find commit which merges them */
-       parent_count = find_first_merges(&merges, path, commit_a, commit_b);
+       parent_count = find_first_merges(o->repo, &merges, path,
+                                        commit_a, commit_b);
        switch (parent_count) {
        case 0:
                output(o, 1, _("Failed to merge submodule %s (merge following commits not found)"), path);
@@ -1401,7 +1413,7 @@ static int handle_rename_via_dir(struct merge_options *o,
         */
        const struct diff_filespec *dest = pair->two;
 
-       if (!o->call_depth && would_lose_untracked(dest->path)) {
+       if (!o->call_depth && would_lose_untracked(o, dest->path)) {
                char *alt_path = unique_path(o, dest->path, rename_branch);
 
                output(o, 1, _("Error: Refusing to lose untracked file at %s; "
@@ -1439,8 +1451,8 @@ static int handle_change_delete(struct merge_options *o,
        const char *update_path = path;
        int ret = 0;
 
-       if (dir_in_way(path, !o->call_depth, 0) ||
-           (!o->call_depth && would_lose_untracked(path))) {
+       if (dir_in_way(o->repo->index, path, !o->call_depth, 0) ||
+           (!o->call_depth && would_lose_untracked(o, path))) {
                update_path = alt_path = unique_path(o, path, change_branch);
        }
 
@@ -1450,7 +1462,7 @@ static int handle_change_delete(struct merge_options *o,
                 * correct; since there is no true "middle point" between
                 * them, simply reuse the base version for virtual merge base.
                 */
-               ret = remove_file_from_cache(path);
+               ret = remove_file_from_index(o->repo->index, path);
                if (!ret)
                        ret = update_file(o, 0, o_oid, o_mode, update_path);
        } else {
@@ -1526,7 +1538,7 @@ static int handle_rename_delete(struct merge_options *o,
                return -1;
 
        if (o->call_depth)
-               return remove_file_from_cache(dest->path);
+               return remove_file_from_index(o->repo->index, dest->path);
        else
                return update_stages(o, dest->path, NULL,
                                     rename_branch == o->branch1 ? dest : NULL,
@@ -1607,10 +1619,10 @@ static int handle_file_collision(struct merge_options *o,
        /* Remove rename sources if rename/add or rename/rename(2to1) */
        if (prev_path1)
                remove_file(o, 1, prev_path1,
-                           o->call_depth || would_lose_untracked(prev_path1));
+                           o->call_depth || would_lose_untracked(o, prev_path1));
        if (prev_path2)
                remove_file(o, 1, prev_path2,
-                           o->call_depth || would_lose_untracked(prev_path2));
+                           o->call_depth || would_lose_untracked(o, prev_path2));
 
        /*
         * Remove the collision path, if it wouldn't cause dirty contents
@@ -1621,7 +1633,7 @@ static int handle_file_collision(struct merge_options *o,
                output(o, 1, _("Refusing to lose dirty file at %s"),
                       collide_path);
                update_path = alt_path = unique_path(o, collide_path, "merged");
-       } else if (would_lose_untracked(collide_path)) {
+       } else if (would_lose_untracked(o, collide_path)) {
                /*
                 * Only way we get here is if both renames were from
                 * a directory rename AND user had an untracked file
@@ -1717,12 +1729,12 @@ static char *find_path_for_conflict(struct merge_options *o,
                                    const char *branch2)
 {
        char *new_path = NULL;
-       if (dir_in_way(path, !o->call_depth, 0)) {
+       if (dir_in_way(o->repo->index, path, !o->call_depth, 0)) {
                new_path = unique_path(o, path, branch1);
                output(o, 1, _("%s is a directory in %s adding "
                               "as %s instead"),
                       path, branch2, new_path);
-       } else if (would_lose_untracked(path)) {
+       } else if (would_lose_untracked(o, path)) {
                new_path = unique_path(o, path, branch1);
                output(o, 1, _("Refusing to lose untracked file"
                               " at %s; adding as %s instead"),
@@ -1783,14 +1795,14 @@ static int handle_rename_rename_1to2(struct merge_options *o,
                                return -1;
                }
                else
-                       remove_file_from_cache(a->path);
+                       remove_file_from_index(o->repo->index, a->path);
                add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);
                if (add) {
                        if (update_file(o, 0, &add->oid, add->mode, b->path))
                                return -1;
                }
                else
-                       remove_file_from_cache(b->path);
+                       remove_file_from_index(o->repo->index, b->path);
        } else {
                /*
                 * For each destination path, we need to see if there is a
@@ -1887,7 +1899,7 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *o,
        struct diff_queue_struct *ret;
        struct diff_options opts;
 
-       repo_diff_setup(the_repository, &opts);
+       repo_diff_setup(o->repo, &opts);
        opts.flags.recursive = 1;
        opts.flags.rename_empty = 0;
        opts.detect_rename = merge_detect_rename(o);
@@ -3042,8 +3054,8 @@ static int blob_unchanged(struct merge_options *opt,
         * performed.  Comparison can be skipped if both files are
         * unchanged since their sha1s have already been compared.
         */
-       if (renormalize_buffer(&the_index, path, o.buf, o.len, &o) |
-           renormalize_buffer(&the_index, path, a.buf, a.len, &a))
+       if (renormalize_buffer(opt->repo->index, path, o.buf, o.len, &o) |
+           renormalize_buffer(opt->repo->index, path, a.buf, a.len, &a))
                ret = (o.len == a.len && !memcmp(o.buf, a.buf, o.len));
 
 error_return:
@@ -3124,7 +3136,7 @@ static int handle_content_merge(struct merge_options *o,
                a.path = (char *)path1;
                b.path = (char *)path2;
 
-               if (dir_in_way(path, !o->call_depth,
+               if (dir_in_way(o->repo->index, path, !o->call_depth,
                               S_ISGITLINK(pair1->two->mode)))
                        df_conflict_remains = 1;
        }
@@ -3158,8 +3170,8 @@ static int handle_content_merge(struct merge_options *o,
                pos = index_name_pos(&o->orig_index, path, strlen(path));
                ce = o->orig_index.cache[pos];
                if (ce_skip_worktree(ce)) {
-                       pos = index_name_pos(&the_index, path, strlen(path));
-                       ce = the_index.cache[pos];
+                       pos = index_name_pos(o->repo->index, path, strlen(path));
+                       ce = o->repo->index->cache[pos];
                        ce->ce_flags |= CE_SKIP_WORKTREE;
                }
                return mfi.clean;
@@ -3178,7 +3190,7 @@ static int handle_content_merge(struct merge_options *o,
        if (df_conflict_remains || is_dirty) {
                char *new_path;
                if (o->call_depth) {
-                       remove_file_from_cache(path);
+                       remove_file_from_index(o->repo->index, path);
                } else {
                        if (!mfi.clean) {
                                if (update_stages(o, path, &one, &a, &b))
@@ -3338,7 +3350,7 @@ static int process_entry(struct merge_options *o,
                        oid = b_oid;
                        conf = _("directory/file");
                }
-               if (dir_in_way(path,
+               if (dir_in_way(o->repo->index, path,
                               !o->call_depth && !S_ISGITLINK(a_mode),
                               0)) {
                        char *new_path = unique_path(o, path, add_branch);
@@ -3349,7 +3361,7 @@ static int process_entry(struct merge_options *o,
                        if (update_file(o, 0, oid, mode, new_path))
                                clean_merge = -1;
                        else if (o->call_depth)
-                               remove_file_from_cache(path);
+                               remove_file_from_index(o->repo->index, path);
                        free(new_path);
                } else {
                        output(o, 2, _("Adding %s"), path);
@@ -3397,18 +3409,19 @@ int merge_trees(struct merge_options *o,
                struct tree *common,
                struct tree **result)
 {
+       struct index_state *istate = o->repo->index;
        int code, clean;
        struct strbuf sb = STRBUF_INIT;
 
-       if (!o->call_depth && index_has_changes(&the_index, head, &sb)) {
+       if (!o->call_depth && repo_index_has_changes(o->repo, head, &sb)) {
                err(o, _("Your local changes to the following files would be overwritten by merge:\n  %s"),
                    sb.buf);
                return -1;
        }
 
        if (o->subtree_shift) {
-               merge = shift_tree_object(head, merge, o->subtree_shift);
-               common = shift_tree_object(head, common, o->subtree_shift);
+               merge = shift_tree_object(o->repo, head, merge, o->subtree_shift);
+               common = shift_tree_object(o->repo, head, common, o->subtree_shift);
        }
 
        if (oid_eq(&common->object.oid, &merge->object.oid)) {
@@ -3428,7 +3441,7 @@ int merge_trees(struct merge_options *o,
                return -1;
        }
 
-       if (unmerged_cache()) {
+       if (unmerged_index(istate)) {
                struct string_list *entries;
                struct rename_info re_info;
                int i;
@@ -3443,7 +3456,7 @@ int merge_trees(struct merge_options *o,
                get_files_dirs(o, head);
                get_files_dirs(o, merge);
 
-               entries = get_unmerged();
+               entries = get_unmerged(o->repo->index);
                clean = detect_and_process_renames(o, common, head, merge,
                                                   entries, &re_info);
                record_df_conflict_files(o, entries);
@@ -3544,8 +3557,8 @@ int merge_recursive(struct merge_options *o,
                /* if there is no common ancestor, use an empty tree */
                struct tree *tree;
 
-               tree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
-               merged_common_ancestors = make_virtual_commit(tree, "ancestor");
+               tree = lookup_tree(o->repo, o->repo->hash_algo->empty_tree);
+               merged_common_ancestors = make_virtual_commit(o->repo, tree, "ancestor");
        }
 
        for (iter = ca; iter; iter = iter->next) {
@@ -3559,7 +3572,7 @@ int merge_recursive(struct merge_options *o,
                 * overwritten it: the committed "conflicts" were
                 * already resolved.
                 */
-               discard_cache();
+               discard_index(o->repo->index);
                saved_b1 = o->branch1;
                saved_b2 = o->branch2;
                o->branch1 = "Temporary merge branch 1";
@@ -3575,9 +3588,9 @@ int merge_recursive(struct merge_options *o,
                        return err(o, _("merge returned no commit"));
        }
 
-       discard_cache();
+       discard_index(o->repo->index);
        if (!o->call_depth)
-               read_cache();
+               repo_read_index(o->repo);
 
        o->ancestor = "merged common ancestors";
        clean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),
@@ -3589,7 +3602,7 @@ int merge_recursive(struct merge_options *o,
        }
 
        if (o->call_depth) {
-               *result = make_virtual_commit(mrtree, "merged tree");
+               *result = make_virtual_commit(o->repo, mrtree, "merged tree");
                commit_list_insert(h1, &(*result)->parents);
                commit_list_insert(h2, &(*result)->parents->next);
        }
@@ -3602,17 +3615,17 @@ int merge_recursive(struct merge_options *o,
        return clean;
 }
 
-static struct commit *get_ref(const struct object_id *oid, const char *name)
+static struct commit *get_ref(struct repository *repo, const struct object_id *oid,
+                             const char *name)
 {
        struct object *object;
 
-       object = deref_tag(the_repository, parse_object(the_repository, oid),
-                          name,
-                          strlen(name));
+       object = deref_tag(repo, parse_object(repo, oid),
+                          name, strlen(name));
        if (!object)
                return NULL;
        if (object->type == OBJ_TREE)
-               return make_virtual_commit((struct tree*)object, name);
+               return make_virtual_commit(repo, (struct tree*)object, name);
        if (object->type != OBJ_COMMIT)
                return NULL;
        if (parse_commit((struct commit *)object))
@@ -3629,22 +3642,22 @@ int merge_recursive_generic(struct merge_options *o,
 {
        int clean;
        struct lock_file lock = LOCK_INIT;
-       struct commit *head_commit = get_ref(head, o->branch1);
-       struct commit *next_commit = get_ref(merge, o->branch2);
+       struct commit *head_commit = get_ref(o->repo, head, o->branch1);
+       struct commit *next_commit = get_ref(o->repo, merge, o->branch2);
        struct commit_list *ca = NULL;
 
        if (base_list) {
                int i;
                for (i = 0; i < num_base_list; ++i) {
                        struct commit *base;
-                       if (!(base = get_ref(base_list[i], oid_to_hex(base_list[i]))))
+                       if (!(base = get_ref(o->repo, base_list[i], oid_to_hex(base_list[i]))))
                                return err(o, _("Could not parse object '%s'"),
                                           oid_to_hex(base_list[i]));
                        commit_list_insert(base, &ca);
                }
        }
 
-       hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
+       repo_hold_locked_index(o->repo, &lock, LOCK_DIE_ON_ERROR);
        clean = merge_recursive(o, head_commit, next_commit, ca,
                                result);
        if (clean < 0) {
@@ -3652,7 +3665,7 @@ int merge_recursive_generic(struct merge_options *o,
                return clean;
        }
 
-       if (write_locked_index(&the_index, &lock,
+       if (write_locked_index(o->repo->index, &lock,
                               COMMIT_LOCK | SKIP_IF_UNCHANGED))
                return err(o, _("Unable to write index."));
 
@@ -3676,10 +3689,12 @@ static void merge_recursive_config(struct merge_options *o)
        git_config(git_xmerge_config, NULL);
 }
 
-void init_merge_options(struct merge_options *o)
+void init_merge_options(struct merge_options *o,
+                       struct repository *repo)
 {
        const char *merge_verbosity;
        memset(o, 0, sizeof(struct merge_options));
+       o->repo = repo;
        o->verbosity = 2;
        o->buffer_output = 1;
        o->diff_rename_limit = -1;
index e6a0828ecacd81d820feb8caa07c90707e97f8b4..c2b7bb65c62ff51af1b89087bbf6692060b5962e 100644 (file)
@@ -6,6 +6,8 @@
 
 struct commit;
 
+struct repository;
+
 struct merge_options {
        const char *ancestor;
        const char *branch1;
@@ -34,6 +36,7 @@ struct merge_options {
        struct string_list df_conflict_file_set;
        struct unpack_trees_options unpack_opts;
        struct index_state orig_index;
+       struct repository *repo;
 };
 
 /*
@@ -92,7 +95,8 @@ int merge_recursive_generic(struct merge_options *o,
                            const struct object_id **ca,
                            struct commit **result);
 
-void init_merge_options(struct merge_options *o);
+void init_merge_options(struct merge_options *o,
+                       struct repository *repo);
 struct tree *write_tree_from_memory(struct merge_options *o);
 
 int parse_merge_opt(struct merge_options *out, const char *s);
diff --git a/merge.c b/merge.c
index 91008f760223e4f6c65a5d344bb6403dd5885d28..7c1d756c3fad6f9570b31c2c36f96e9f90df39f4 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -37,7 +37,7 @@ int try_merge_command(struct repository *r,
        argv_array_clear(&args);
 
        discard_index(r->index);
-       if (read_index(r->index) < 0)
+       if (repo_read_index(r) < 0)
                die(_("failed to read the cache"));
        resolve_undo_clear_index(r->index);
 
@@ -58,7 +58,7 @@ int checkout_fast_forward(struct repository *r,
 
        refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
 
-       if (hold_locked_index(&lock_file, LOCK_REPORT_ON_ERROR) < 0)
+       if (repo_hold_locked_index(r, &lock_file, LOCK_REPORT_ON_ERROR) < 0)
                return -1;
 
        memset(&trees, 0, sizeof(trees));
index 623ca6923a9ec78b9bb7d7cc899af72057d101d3..b4861bc7b02a93bd5f3659098764f535bb1f51c1 100644 (file)
@@ -5,7 +5,6 @@
  *
  * Copyright (C) 2008 Linus Torvalds
  */
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "thread-utils.h"
 
index 72688d301b7dd41ed1aa8ab5d3e5e61a6f4054c5..280aa8e6c1b04136d4718b970adca19a1a9eb9cf 100644 (file)
@@ -649,7 +649,7 @@ int notes_merge(struct notes_merge_options *o,
                struct commit_list *parents = NULL;
                commit_list_insert(remote, &parents); /* LIFO order */
                commit_list_insert(local, &parents);
-               create_notes_commit(local_tree, parents, o->commit_msg.buf,
+               create_notes_commit(o->repo, local_tree, parents, o->commit_msg.buf,
                                    o->commit_msg.len, result_oid);
        }
 
@@ -724,7 +724,7 @@ int notes_merge_commit(struct notes_merge_options *o,
                strbuf_setlen(&path, baselen);
        }
 
-       create_notes_commit(partial_tree, partial_commit->parents, msg,
+       create_notes_commit(o->repo, partial_tree, partial_commit->parents, msg,
                            strlen(msg), result_oid);
        unuse_commit_buffer(partial_commit, buffer);
        if (o->verbosity >= 4)
index 14ea03178e9c44c8c8a05fb70ab038df5ad1b5f8..a8194106987388a590b10e246327f49fd550f448 100644 (file)
@@ -5,7 +5,9 @@
 #include "notes-utils.h"
 #include "repository.h"
 
-void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
+void create_notes_commit(struct repository *r,
+                        struct notes_tree *t,
+                        struct commit_list *parents,
                         const char *msg, size_t msg_len,
                         struct object_id *result_oid)
 {
@@ -20,8 +22,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
                /* Deduce parent commit from t->ref */
                struct object_id parent_oid;
                if (!read_ref(t->ref, &parent_oid)) {
-                       struct commit *parent = lookup_commit(the_repository,
-                                                             &parent_oid);
+                       struct commit *parent = lookup_commit(r, &parent_oid);
                        if (parse_commit(parent))
                                die("Failed to find/parse commit %s", t->ref);
                        commit_list_insert(parent, &parents);
@@ -34,7 +35,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
                die("Failed to commit notes tree to database");
 }
 
-void commit_notes(struct notes_tree *t, const char *msg)
+void commit_notes(struct repository *r, struct notes_tree *t, const char *msg)
 {
        struct strbuf buf = STRBUF_INIT;
        struct object_id commit_oid;
@@ -50,7 +51,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
        strbuf_addstr(&buf, msg);
        strbuf_complete_line(&buf);
 
-       create_notes_commit(t, NULL, buf.buf, buf.len, &commit_oid);
+       create_notes_commit(r, t, NULL, buf.buf, buf.len, &commit_oid);
        strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
        update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
                   UPDATE_REFS_DIE_ON_ERR);
@@ -171,11 +172,13 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
        return ret;
 }
 
-void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char *msg)
+void finish_copy_notes_for_rewrite(struct repository *r,
+                                  struct notes_rewrite_cfg *c,
+                                  const char *msg)
 {
        int i;
        for (i = 0; c->trees[i]; i++) {
-               commit_notes(c->trees[i], msg);
+               commit_notes(r, c->trees[i], msg);
                free_notes(c->trees[i]);
        }
        free(c->trees);
index 54083065283f681d8354af633b805a4896c8b036..d9b3c09eaf09819f9444cfcf68ca5443aa918b78 100644 (file)
@@ -5,6 +5,7 @@
 
 struct commit_list;
 struct object_id;
+struct repository;
 
 /*
  * Create new notes commit from the given notes tree
@@ -17,11 +18,13 @@ struct object_id;
  *
  * The resulting commit SHA1 is stored in result_sha1.
  */
-void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
+void create_notes_commit(struct repository *r,
+                        struct notes_tree *t,
+                        struct commit_list *parents,
                         const char *msg, size_t msg_len,
                         struct object_id *result_oid);
 
-void commit_notes(struct notes_tree *t, const char *msg);
+void commit_notes(struct repository *r, struct notes_tree *t, const char *msg);
 
 enum notes_merge_strategy {
                NOTES_MERGE_RESOLVE_MANUAL = 0,
@@ -45,6 +48,8 @@ int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);
 struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
 int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
                          const struct object_id *from_obj, const struct object_id *to_obj);
-void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char *msg);
+void finish_copy_notes_for_rewrite(struct repository *r,
+                                  struct notes_rewrite_cfg *c,
+                                  const char *msg);
 
 #endif
diff --git a/notes.c b/notes.c
index 25cdce28b71a3ff15da424c8d1b1a89e28356dd5..7f7cc4d5112cd8f5098477d03034e8c8886dcb84 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -450,7 +450,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 
                l = xcalloc(1, sizeof(*l));
                oidcpy(&l->key_oid, &object_oid);
-               oidcpy(&l->val_oid, entry.oid);
+               oidcpy(&l->val_oid, &entry.oid);
                if (note_tree_insert(t, node, n, l, type,
                                     combine_notes_concatenate))
                        die("Failed to load %s %s into notes tree "
@@ -481,7 +481,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
                        }
                        strbuf_addstr(&non_note_path, entry.path);
                        add_non_note(t, strbuf_detach(&non_note_path, NULL),
-                                    entry.mode, entry.oid->hash);
+                                    entry.mode, entry.oid.hash);
                }
        }
        free(buf);
index e16aa38caebe69ae9bb3ace066f8103a60457407..ba57630677fac412c6f8a771ed64eccf6000e833 100644 (file)
@@ -160,13 +160,20 @@ const char *loose_object_path(struct repository *r, struct strbuf *buf, const un
 
 void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
 
-extern void *read_object_file_extended(const struct object_id *oid,
+extern void *read_object_file_extended(struct repository *r,
+                                      const struct object_id *oid,
                                       enum object_type *type,
                                       unsigned long *size, int lookup_replace);
-static inline void *read_object_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
+static inline void *repo_read_object_file(struct repository *r,
+                                         const struct object_id *oid,
+                                         enum object_type *type,
+                                         unsigned long *size)
 {
-       return read_object_file_extended(oid, type, size, 1);
+       return read_object_file_extended(r, oid, type, size, 1);
 }
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define read_object_file(oid, type, size) repo_read_object_file(the_repository, oid, type, size)
+#endif
 
 /* Read and unpack an object file into memory, write memory to an object file */
 int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
@@ -204,15 +211,27 @@ int read_loose_object(const char *path,
  * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
  * nonzero flags to also set other flags.
  */
-extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);
-static inline int has_sha1_file(const unsigned char *sha1)
+int repo_has_sha1_file_with_flags(struct repository *r,
+                                 const unsigned char *sha1, int flags);
+static inline int repo_has_sha1_file(struct repository *r,
+                                    const unsigned char *sha1)
 {
-       return has_sha1_file_with_flags(sha1, 0);
+       return repo_has_sha1_file_with_flags(r, sha1, 0);
 }
 
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define has_sha1_file_with_flags(sha1, flags) repo_has_sha1_file_with_flags(the_repository, sha1, flags)
+#define has_sha1_file(sha1) repo_has_sha1_file(the_repository, sha1)
+#endif
+
 /* Same as the above, except for struct object_id. */
-extern int has_object_file(const struct object_id *oid);
-extern int has_object_file_with_flags(const struct object_id *oid, int flags);
+int repo_has_object_file(struct repository *r, const struct object_id *oid);
+int repo_has_object_file_with_flags(struct repository *r,
+                                   const struct object_id *oid, int flags);
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define has_object_file(oid) repo_has_object_file(the_repository, oid)
+#define has_object_file_with_flags(oid, flags) repo_has_object_file_with_flags(the_repository, oid, flags)
+#endif
 
 /*
  * Return true iff an alternate object database has a loose object
index a5c5cf830fc52d03adb4283cafd097218e1117a0..5dc5eec367354ae4817b813b181423e096179a8a 100644 (file)
--- a/object.c
+++ b/object.c
@@ -164,8 +164,9 @@ void *object_as_type(struct repository *r, struct object *obj, enum object_type
                return obj;
        else if (obj->type == OBJ_NONE) {
                if (type == OBJ_COMMIT)
-                       ((struct commit *)obj)->index = alloc_commit_index(r);
-               obj->type = type;
+                       init_commit_node(r, (struct commit *) obj);
+               else
+                       obj->type = type;
                return obj;
        }
        else {
@@ -259,8 +260,8 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
        if (obj && obj->parsed)
                return obj;
 
-       if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
-           (!obj && has_object_file(oid) &&
+       if ((obj && obj->type == OBJ_BLOB && repo_has_object_file(r, oid)) ||
+           (!obj && repo_has_object_file(r, oid) &&
             oid_object_info(r, oid, NULL) == OBJ_BLOB)) {
                if (check_object_signature(repl, NULL, 0, NULL) < 0) {
                        error(_("sha1 mismatch %s"), oid_to_hex(oid));
@@ -270,7 +271,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
                return lookup_object(r, oid->hash);
        }
 
-       buffer = read_object_file(oid, &type, &size);
+       buffer = repo_read_object_file(r, oid, &type, &size);
        if (buffer) {
                if (check_object_signature(repl, buffer, size, type_name(type)) < 0) {
                        free(buffer);
@@ -540,7 +541,7 @@ void parsed_object_pool_clear(struct parsed_object_pool *o)
                if (obj->type == OBJ_TREE)
                        free_tree_buffer((struct tree*)obj);
                else if (obj->type == OBJ_COMMIT)
-                       release_commit_memory((struct commit*)obj);
+                       release_commit_memory(o, (struct commit*)obj);
                else if (obj->type == OBJ_TAG)
                        release_tag_memory((struct tag*)obj);
        }
index 9c45842df389270baf73f4aa5b65df2004c9ba4d..e7cd337bee53cb02282a14c8aa88f2342edd2eb2 100644 (file)
@@ -150,9 +150,7 @@ void prepare_packing_data(struct repository *r, struct packing_data *pdata)
                                             1U << OE_SIZE_BITS);
        pdata->oe_delta_size_limit = git_env_ulong("GIT_TEST_OE_DELTA_SIZE",
                                                   1UL << OE_DELTA_SIZE_BITS);
-#ifndef NO_PTHREADS
-       pthread_mutex_init(&pdata->lock, NULL);
-#endif
+       init_recursive_mutex(&pdata->odb_lock);
 }
 
 struct object_entry *packlist_alloc(struct packing_data *pdata,
index 3cd8d1f00a95978a5a8c86805506b9927aefcd0e..6bfacc7d2cedd7f399d7807b7746b6ed66737eed 100644 (file)
@@ -148,7 +148,11 @@ struct packing_data {
        struct packed_git **in_pack_by_idx;
        struct packed_git **in_pack;
 
-       pthread_mutex_t lock;
+       /*
+        * During packing with multiple threads, protect the in-core
+        * object database from concurrent accesses.
+        */
+       pthread_mutex_t odb_lock;
 
        /*
         * This list contains entries for bases which we know the other side
@@ -168,13 +172,14 @@ struct packing_data {
 
 void prepare_packing_data(struct repository *r, struct packing_data *pdata);
 
+/* Protect access to object database */
 static inline void packing_data_lock(struct packing_data *pdata)
 {
-       pthread_mutex_lock(&pdata->lock);
+       pthread_mutex_lock(&pdata->odb_lock);
 }
 static inline void packing_data_unlock(struct packing_data *pdata)
 {
-       pthread_mutex_unlock(&pdata->lock);
+       pthread_mutex_unlock(&pdata->odb_lock);
 }
 
 struct object_entry *packlist_alloc(struct packing_data *pdata,
index 0fe9c21bf108965867ca691c245c3be0124a9102..16bcb75262d918fc7b88cc5141213e951be145cc 100644 (file)
@@ -1148,12 +1148,13 @@ void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)
        p->num_bad_objects++;
 }
 
-const struct packed_git *has_packed_and_bad(const unsigned char *sha1)
+const struct packed_git *has_packed_and_bad(struct repository *r,
+                                           const unsigned char *sha1)
 {
        struct packed_git *p;
        unsigned i;
 
-       for (p = the_repository->objects->packed_git; p; p = p->next)
+       for (p = r->objects->packed_git; p; p = p->next)
                for (i = 0; i < p->num_bad_objects; i++)
                        if (hasheq(sha1,
                                   p->bad_object_sha1 + the_hash_algo->rawsz * i))
@@ -2097,7 +2098,7 @@ static int add_promisor_object(const struct object_id *oid,
                         */
                        return 0;
                while (tree_entry_gently(&desc, &entry))
-                       oidset_insert(set, entry.oid);
+                       oidset_insert(set, &entry.oid);
        } else if (obj->type == OBJ_COMMIT) {
                struct commit *commit = (struct commit *) obj;
                struct commit_list *parents = commit->parents;
index 6c4037605d0dfee59a084c440506f1af11708d63..d70c6d9afb94c77c285fe8ee3237f7a40867157a 100644 (file)
@@ -146,7 +146,7 @@ extern int packed_object_info(struct repository *r,
                              off_t offset, struct object_info *);
 
 extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
-extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
+extern const struct packed_git *has_packed_and_bad(struct repository *r, const unsigned char *sha1);
 
 /*
  * Iff a pack file in the given repository contains the object named by sha1,
diff --git a/path.h b/path.h
index b654ea8ff5f2e701239ec17b8d1fc81cebfc25dd..651e6157fc480264e3495bd508a88d0835de1379 100644 (file)
--- a/path.h
+++ b/path.h
@@ -165,7 +165,7 @@ extern void report_linked_checkout_garbage(void);
        const char *git_path_##var(struct repository *r) \
        { \
                if (!r->cached_paths.var) \
-                       r->cached_paths.var = git_pathdup(filename); \
+                       r->cached_paths.var = repo_git_path(r, filename); \
                return r->cached_paths.var; \
        }
 
index e85298f68cfeee14494466b0604e572a5c345810..12c2b322b30a59d2091d2c87df1bed88246d5950 100644 (file)
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
index 04d10bbd037b393574f8453cbd00f94e0b2e7e99..d4b71d3e82b0e54ef4105748fdfdc15b438badfb 100644 (file)
@@ -129,12 +129,14 @@ static void set_packet_header(char *buf, const int size)
        #undef hex
 }
 
-static void format_packet(struct strbuf *out, const char *fmt, va_list args)
+static void format_packet(struct strbuf *out, const char *prefix,
+                         const char *fmt, va_list args)
 {
        size_t orig_len, n;
 
        orig_len = out->len;
        strbuf_addstr(out, "0000");
+       strbuf_addstr(out, prefix);
        strbuf_vaddf(out, fmt, args);
        n = out->len - orig_len;
 
@@ -145,13 +147,13 @@ static void format_packet(struct strbuf *out, const char *fmt, va_list args)
        packet_trace(out->buf + orig_len + 4, n - 4, 1);
 }
 
-static int packet_write_fmt_1(int fd, int gently,
+static int packet_write_fmt_1(int fd, int gently, const char *prefix,
                              const char *fmt, va_list args)
 {
        static struct strbuf buf = STRBUF_INIT;
 
        strbuf_reset(&buf);
-       format_packet(&buf, fmt, args);
+       format_packet(&buf, prefix, fmt, args);
        if (write_in_full(fd, buf.buf, buf.len) < 0) {
                if (!gently) {
                        check_pipe(errno);
@@ -168,7 +170,7 @@ void packet_write_fmt(int fd, const char *fmt, ...)
        va_list args;
 
        va_start(args, fmt);
-       packet_write_fmt_1(fd, 0, fmt, args);
+       packet_write_fmt_1(fd, 0, "", fmt, args);
        va_end(args);
 }
 
@@ -178,7 +180,7 @@ int packet_write_fmt_gently(int fd, const char *fmt, ...)
        va_list args;
 
        va_start(args, fmt);
-       status = packet_write_fmt_1(fd, 1, fmt, args);
+       status = packet_write_fmt_1(fd, 1, "", fmt, args);
        va_end(args);
        return status;
 }
@@ -211,7 +213,7 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
        va_list args;
 
        va_start(args, fmt);
-       format_packet(buf, fmt, args);
+       format_packet(buf, "", fmt, args);
        va_end(args);
 }
 
@@ -346,6 +348,10 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
                return PACKET_READ_EOF;
        }
 
+       if ((options & PACKET_READ_DIE_ON_ERR_PACKET) &&
+           starts_with(buffer, "ERR "))
+               die(_("remote error: %s"), buffer + 4);
+
        if ((options & PACKET_READ_CHOMP_NEWLINE) &&
            len && buffer[len-1] == '\n')
                len--;
@@ -433,6 +439,29 @@ ssize_t read_packetized_to_strbuf(int fd_in, struct strbuf *sb_out)
        return sb_out->len - orig_len;
 }
 
+int recv_sideband(const char *me, int in_stream, int out)
+{
+       char buf[LARGE_PACKET_MAX + 1];
+       int len;
+       struct strbuf scratch = STRBUF_INIT;
+       enum sideband_type sideband_type;
+
+       while (1) {
+               len = packet_read(in_stream, NULL, NULL, buf, LARGE_PACKET_MAX,
+                                 0);
+               if (!demultiplex_sideband(me, buf, len, 0, &scratch,
+                                         &sideband_type))
+                       continue;
+               switch (sideband_type) {
+               case SIDEBAND_PRIMARY:
+                       write_or_die(out, buf + 1, len - 1);
+                       break;
+               default: /* errors: message already written */
+                       return sideband_type;
+               }
+       }
+}
+
 /* Packet Reader Functions */
 void packet_reader_init(struct packet_reader *reader, int fd,
                        char *src_buffer, size_t src_len,
@@ -446,25 +475,43 @@ void packet_reader_init(struct packet_reader *reader, int fd,
        reader->buffer = packet_buffer;
        reader->buffer_size = sizeof(packet_buffer);
        reader->options = options;
+       reader->me = "git";
 }
 
 enum packet_read_status packet_reader_read(struct packet_reader *reader)
 {
+       struct strbuf scratch = STRBUF_INIT;
+
        if (reader->line_peeked) {
                reader->line_peeked = 0;
                return reader->status;
        }
 
-       reader->status = packet_read_with_status(reader->fd,
-                                                &reader->src_buffer,
-                                                &reader->src_len,
-                                                reader->buffer,
-                                                reader->buffer_size,
-                                                &reader->pktlen,
-                                                reader->options);
+       /*
+        * Consume all progress packets until a primary payload packet is
+        * received
+        */
+       while (1) {
+               enum sideband_type sideband_type;
+               reader->status = packet_read_with_status(reader->fd,
+                                                        &reader->src_buffer,
+                                                        &reader->src_len,
+                                                        reader->buffer,
+                                                        reader->buffer_size,
+                                                        &reader->pktlen,
+                                                        reader->options);
+               if (!reader->use_sideband)
+                       break;
+               if (demultiplex_sideband(reader->me, reader->buffer,
+                                        reader->pktlen, 1, &scratch,
+                                        &sideband_type))
+                       break;
+       }
 
        if (reader->status == PACKET_READ_NORMAL)
-               reader->line = reader->buffer;
+               /* Skip the sideband designator if sideband is used */
+               reader->line = reader->use_sideband ?
+                       reader->buffer + 1 : reader->buffer;
        else
                reader->line = NULL;
 
@@ -482,3 +529,39 @@ enum packet_read_status packet_reader_peek(struct packet_reader *reader)
        reader->line_peeked = 1;
        return reader->status;
 }
+
+void packet_writer_init(struct packet_writer *writer, int dest_fd)
+{
+       writer->dest_fd = dest_fd;
+       writer->use_sideband = 0;
+}
+
+void packet_writer_write(struct packet_writer *writer, const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       packet_write_fmt_1(writer->dest_fd, 0,
+                          writer->use_sideband ? "\001" : "", fmt, args);
+       va_end(args);
+}
+
+void packet_writer_error(struct packet_writer *writer, const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       packet_write_fmt_1(writer->dest_fd, 0,
+                          writer->use_sideband ? "\003" : "ERR ", fmt, args);
+       va_end(args);
+}
+
+void packet_writer_delim(struct packet_writer *writer)
+{
+       packet_delim(writer->dest_fd);
+}
+
+void packet_writer_flush(struct packet_writer *writer)
+{
+       packet_flush(writer->dest_fd);
+}
index 5b28d43472db41a59f0a44845953f163748593b0..ad9a4a2cd7c332cb1c4d1f26268f1ef45f2d7639 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "git-compat-util.h"
 #include "strbuf.h"
+#include "sideband.h"
 
 /*
  * Write a packetized stream, where each line is preceded by
@@ -62,9 +63,13 @@ int write_packetized_from_buf(const char *src_in, size_t len, int fd_out);
  *
  * If options contains PACKET_READ_CHOMP_NEWLINE, a trailing newline (if
  * present) is removed from the buffer before returning.
+ *
+ * If options contains PACKET_READ_DIE_ON_ERR_PACKET, it dies when it sees an
+ * ERR packet.
  */
-#define PACKET_READ_GENTLE_ON_EOF (1u<<0)
-#define PACKET_READ_CHOMP_NEWLINE (1u<<1)
+#define PACKET_READ_GENTLE_ON_EOF     (1u<<0)
+#define PACKET_READ_CHOMP_NEWLINE     (1u<<1)
+#define PACKET_READ_DIE_ON_ERR_PACKET (1u<<2)
 int packet_read(int fd, char **src_buffer, size_t *src_len, char
                *buffer, unsigned size, int options);
 
@@ -116,6 +121,21 @@ char *packet_read_line_buf(char **src_buf, size_t *src_len, int *size);
  */
 ssize_t read_packetized_to_strbuf(int fd_in, struct strbuf *sb_out);
 
+/*
+ * Receive multiplexed output stream over git native protocol.
+ * in_stream is the input stream from the remote, which carries data
+ * in pkt_line format with band designator.  Demultiplex it into out
+ * and err and return error appropriately.  Band #1 carries the
+ * primary payload.  Things coming over band #2 is not necessarily
+ * error; they are usually informative message on the standard error
+ * stream, aka "verbose").  A message over band #3 is a signal that
+ * the remote died unexpectedly.  A flush() concludes the stream.
+ *
+ * Returns SIDEBAND_FLUSH upon a normal conclusion, and SIDEBAND_PROTOCOL_ERROR
+ * or SIDEBAND_REMOTE_ERROR if an error occurred.
+ */
+int recv_sideband(const char *me, int in_stream, int out);
+
 struct packet_reader {
        /* source file descriptor */
        int fd;
@@ -142,6 +162,9 @@ struct packet_reader {
 
        /* indicates if a line has been peeked */
        int line_peeked;
+
+       unsigned use_sideband : 1;
+       const char *me;
 };
 
 /*
@@ -179,4 +202,19 @@ extern enum packet_read_status packet_reader_peek(struct packet_reader *reader);
 #define LARGE_PACKET_DATA_MAX (LARGE_PACKET_MAX - 4)
 extern char packet_buffer[LARGE_PACKET_MAX];
 
+struct packet_writer {
+       int dest_fd;
+       unsigned use_sideband : 1;
+};
+
+void packet_writer_init(struct packet_writer *writer, int dest_fd);
+
+/* These functions die upon failure. */
+__attribute__((format (printf, 2, 3)))
+void packet_writer_write(struct packet_writer *writer, const char *fmt, ...);
+__attribute__((format (printf, 2, 3)))
+void packet_writer_error(struct packet_writer *writer, const char *fmt, ...);
+void packet_writer_delim(struct packet_writer *writer);
+void packet_writer_flush(struct packet_writer *writer);
+
 #endif
index c7dc3f2b9f62a762efd7f590d6e8959fc1707479..e73600ee7841a299e060369ca9eecf46d5a7fb0f 100644 (file)
@@ -8,6 +8,7 @@
 #include "config.h"
 #include "progress.h"
 #include "thread-utils.h"
+#include "repository.h"
 
 /*
  * Mostly randomly chosen maximum thread counts: we
@@ -146,12 +147,12 @@ void preload_index(struct index_state *index,
        trace_performance_leave("preload index");
 }
 
-int read_index_preload(struct index_state *index,
-                      const struct pathspec *pathspec,
-                      unsigned int refresh_flags)
+int repo_read_index_preload(struct repository *repo,
+                           const struct pathspec *pathspec,
+                           unsigned int refresh_flags)
 {
-       int retval = read_index(index);
+       int retval = repo_read_index(repo);
 
-       preload_index(index, pathspec, refresh_flags);
+       preload_index(repo->index, pathspec, refresh_flags);
        return retval;
 }
index b83a3ecd2331af7f2e7e03bd76336cde3c2a6dfc..0ab45d10d702373e212fb36e4fa66feb26669ee7 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -595,14 +595,15 @@ static char *replace_encoding_header(char *buf, const char *encoding)
        return strbuf_detach(&tmp, NULL);
 }
 
-const char *logmsg_reencode(const struct commit *commit,
-                           char **commit_encoding,
-                           const char *output_encoding)
+const char *repo_logmsg_reencode(struct repository *r,
+                                const struct commit *commit,
+                                char **commit_encoding,
+                                const char *output_encoding)
 {
        static const char *utf8 = "UTF-8";
        const char *use_encoding;
        char *encoding;
-       const char *msg = get_commit_buffer(commit, NULL);
+       const char *msg = repo_get_commit_buffer(r, commit, NULL);
        char *out;
 
        if (!output_encoding || !*output_encoding) {
@@ -630,7 +631,7 @@ const char *logmsg_reencode(const struct commit *commit,
                 * the cached copy from get_commit_buffer, we need to duplicate it
                 * to avoid munging the cached copy.
                 */
-               if (msg == get_cached_commit_buffer(the_repository, commit, NULL))
+               if (msg == get_cached_commit_buffer(r, commit, NULL))
                        out = xstrdup(msg);
                else
                        out = (char *)msg;
@@ -644,7 +645,7 @@ const char *logmsg_reencode(const struct commit *commit,
                 */
                out = reencode_string(msg, output_encoding, use_encoding);
                if (out)
-                       unuse_commit_buffer(commit, msg);
+                       repo_unuse_commit_buffer(r, commit, msg);
        }
 
        /*
@@ -1084,6 +1085,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
        struct commit_list *p;
        const char *arg;
        int ch;
+       char **slot;
 
        /* these are independent of the commit */
        switch (placeholder[0]) {
@@ -1194,6 +1196,14 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
                load_ref_decorations(NULL, DECORATE_SHORT_REFS);
                format_decorations_extended(sb, commit, c->auto_color, "", ", ", "");
                return 1;
+       case 'S':               /* tag/branch like --source */
+               if (!(c->pretty_ctx->rev && c->pretty_ctx->rev->sources))
+                       return 0;
+               slot = revision_sources_at(c->pretty_ctx->rev->sources, commit);
+               if (!(slot && *slot))
+                       return 0;
+               strbuf_addstr(sb, *slot);
+               return 1;
        case 'g':               /* reflog info */
                switch(placeholder[1]) {
                case 'd':       /* reflog selector */
@@ -1498,6 +1508,9 @@ static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
        case 'N':
                w->notes = 1;
                break;
+       case 'S':
+               w->source = 1;
+               break;
        }
        return 0;
 }
@@ -1515,9 +1528,10 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)
        strbuf_release(&dummy);
 }
 
-void format_commit_message(const struct commit *commit,
-                          const char *format, struct strbuf *sb,
-                          const struct pretty_print_context *pretty_ctx)
+void repo_format_commit_message(struct repository *r,
+                               const struct commit *commit,
+                               const char *format, struct strbuf *sb,
+                               const struct pretty_print_context *pretty_ctx)
 {
        struct format_commit_context context;
        const char *output_enc = pretty_ctx->output_encoding;
@@ -1531,9 +1545,9 @@ void format_commit_message(const struct commit *commit,
         * convert a commit message to UTF-8 first
         * as far as 'format_commit_item' assumes it in UTF-8
         */
-       context.message = logmsg_reencode(commit,
-                                         &context.commit_encoding,
-                                         utf8);
+       context.message = repo_logmsg_reencode(r, commit,
+                                              &context.commit_encoding,
+                                              utf8);
 
        strbuf_expand(sb, format, format_commit_item, &context);
        rewrap_message_tail(sb, &context, 0, 0, 0);
@@ -1557,7 +1571,7 @@ void format_commit_message(const struct commit *commit,
        }
 
        free(context.commit_encoding);
-       unuse_commit_buffer(commit, context.message);
+       repo_unuse_commit_buffer(r, commit, context.message);
 }
 
 static void pp_header(struct pretty_print_context *pp,
index 7359d318a92c167e0f36eabf73fdd1142f0e9031..4ad1fc31ff33408881abf2ea5e28ab813d6c1f85 100644 (file)
--- a/pretty.h
+++ b/pretty.h
@@ -60,6 +60,7 @@ static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
 
 struct userformat_want {
        unsigned notes:1;
+       unsigned source:1;
 };
 
 /* Set the flag "w->notes" if there is placeholder %N in "fmt". */
@@ -103,9 +104,14 @@ void pp_remainder(struct pretty_print_context *pp, const char **msg_p,
  * Put the result to "sb".
  * Please use this function for custom formats.
  */
-void format_commit_message(const struct commit *commit,
+void repo_format_commit_message(struct repository *r,
+                       const struct commit *commit,
                        const char *format, struct strbuf *sb,
                        const struct pretty_print_context *context);
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define format_commit_message(c, f, s, con) \
+       repo_format_commit_message(the_repository, c, f, s, con)
+#endif
 
 /*
  * Parse given arguments from "arg", check it for correctness and
index bfff271a3db92cfaaa93d23c5bf52297dda0419e..a66c87bc7a8346d1df529cae5154c8f35ba9d1ca 100644 (file)
@@ -3,7 +3,6 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "diff.h"
@@ -95,7 +94,6 @@ static struct mem_pool *find_mem_pool(struct index_state *istate)
        return *pool_ptr;
 }
 
-struct index_state the_index;
 static const char *alternate_index_output;
 
 static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
@@ -703,10 +701,10 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
        int intent_only = flags & ADD_CACHE_INTENT;
        int add_option = (ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE|
                          (intent_only ? ADD_CACHE_NEW_ONLY : 0));
-       int newflags = HASH_WRITE_OBJECT;
+       int hash_flags = HASH_WRITE_OBJECT;
 
-       if (flags & HASH_RENORMALIZE)
-               newflags |= HASH_RENORMALIZE;
+       if (flags & ADD_CACHE_RENORMALIZE)
+               hash_flags |= HASH_RENORMALIZE;
 
        if (!S_ISREG(st_mode) && !S_ISLNK(st_mode) && !S_ISDIR(st_mode))
                return error(_("%s: can only add regular files, symbolic links or git-directories"), path);
@@ -762,7 +760,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
                }
        }
        if (!intent_only) {
-               if (index_path(istate, &ce->oid, path, st, newflags)) {
+               if (index_path(istate, &ce->oid, path, st, hash_flags)) {
                        discard_cache_entry(ce);
                        return error(_("unable to index file '%s'"), path);
                }
@@ -1733,16 +1731,6 @@ static int read_index_extension(struct index_state *istate,
        return 0;
 }
 
-int hold_locked_index(struct lock_file *lk, int lock_flags)
-{
-       return hold_lock_file_for_update(lk, get_index_file(), lock_flags);
-}
-
-int read_index(struct index_state *istate)
-{
-       return read_index_from(istate, get_index_file(), get_git_dir());
-}
-
 static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
                                            unsigned int version,
                                            struct ondisk_cache_entry *ondisk,
@@ -2375,22 +2363,20 @@ int unmerged_index(const struct index_state *istate)
        return 0;
 }
 
-int index_has_changes(struct index_state *istate,
-                     struct tree *tree,
-                     struct strbuf *sb)
+int repo_index_has_changes(struct repository *repo,
+                          struct tree *tree,
+                          struct strbuf *sb)
 {
+       struct index_state *istate = repo->index;
        struct object_id cmp;
        int i;
 
-       if (istate != &the_index) {
-               BUG("index_has_changes cannot yet accept istate != &the_index; do_diff_cache needs updating first.");
-       }
        if (tree)
                cmp = tree->object.oid;
        if (tree || !get_oid_tree("HEAD", &cmp)) {
                struct diff_options opt;
 
-               repo_diff_setup(the_repository, &opt);
+               repo_diff_setup(repo, &opt);
                opt.flags.exit_with_status = 1;
                if (!sb)
                        opt.flags.quick = 1;
@@ -2664,9 +2650,9 @@ static int verify_index_from(const struct index_state *istate, const char *path)
        return 0;
 }
 
-static int verify_index(const struct index_state *istate)
+static int repo_verify_index(struct repository *repo)
 {
-       return verify_index_from(istate, get_index_file());
+       return verify_index_from(repo->index, repo->index_file);
 }
 
 static int has_racy_timestamp(struct index_state *istate)
@@ -2682,11 +2668,13 @@ static int has_racy_timestamp(struct index_state *istate)
        return 0;
 }
 
-void update_index_if_able(struct index_state *istate, struct lock_file *lockfile)
+void repo_update_index_if_able(struct repository *repo,
+                              struct lock_file *lockfile)
 {
-       if ((istate->cache_changed || has_racy_timestamp(istate)) &&
-           verify_index(istate))
-               write_locked_index(istate, lockfile, COMMIT_LOCK);
+       if ((repo->index->cache_changed ||
+            has_racy_timestamp(repo->index)) &&
+           repo_verify_index(repo))
+               write_locked_index(repo->index, lockfile, COMMIT_LOCK);
        else
                rollback_lock_file(lockfile);
 }
@@ -3223,12 +3211,14 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
  * state can call this and check its return value, instead of calling
  * read_cache().
  */
-int read_index_unmerged(struct index_state *istate)
+int repo_read_index_unmerged(struct repository *repo)
 {
+       struct index_state *istate;
        int i;
        int unmerged = 0;
 
-       read_index(istate);
+       repo_read_index(repo);
+       istate = repo->index;
        for (i = 0; i < istate->cache_nr; i++) {
                struct cache_entry *ce = istate->cache[i];
                struct cache_entry *new_ce;
index 90d565c8c5421eee7f929059e8e465ddfbe78dc2..2e04d53ac8e79c9f5a3839a7ab97fd67f2588021 100644 (file)
@@ -204,7 +204,8 @@ static struct ref *parse_git_refs(struct discovery *heads, int for_push)
 
        packet_reader_init(&reader, -1, heads->buf, heads->len,
                           PACKET_READ_CHOMP_NEWLINE |
-                          PACKET_READ_GENTLE_ON_EOF);
+                          PACKET_READ_GENTLE_ON_EOF |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
 
        heads->version = discover_version(&reader);
        switch (heads->version) {
@@ -380,7 +381,6 @@ static struct discovery *discover_refs(const char *service, int for_push)
        http_options.extra_headers = &extra_headers;
        http_options.initial_request = 1;
        http_options.no_cache = 1;
-       http_options.keep_error = 1;
 
        http_ret = http_get_strbuf(refs_url.buf, &buffer, &http_options);
        switch (http_ret) {
@@ -409,28 +409,37 @@ static struct discovery *discover_refs(const char *service, int for_push)
        if (maybe_smart &&
            (5 <= last->len && last->buf[4] == '#') &&
            !strbuf_cmp(&exp, &type)) {
-               char *line;
+               struct packet_reader reader;
+               packet_reader_init(&reader, -1, last->buf, last->len,
+                                  PACKET_READ_CHOMP_NEWLINE |
+                                  PACKET_READ_DIE_ON_ERR_PACKET);
 
                /*
                 * smart HTTP response; validate that the service
                 * pkt-line matches our request.
                 */
-               line = packet_read_line_buf(&last->buf, &last->len, NULL);
-               if (!line)
+               if (packet_reader_read(&reader) != PACKET_READ_NORMAL)
                        die("invalid server response; expected service, got flush packet");
 
                strbuf_reset(&exp);
                strbuf_addf(&exp, "# service=%s", service);
-               if (strcmp(line, exp.buf))
-                       die("invalid server response; got '%s'", line);
+               if (strcmp(reader.line, exp.buf))
+                       die("invalid server response; got '%s'", reader.line);
                strbuf_release(&exp);
 
                /* The header can include additional metadata lines, up
                 * until a packet flush marker.  Ignore these now, but
                 * in the future we might start to scan them.
                 */
-               while (packet_read_line_buf(&last->buf, &last->len, NULL))
-                       ;
+               for (;;) {
+                       packet_reader_read(&reader);
+                       if (reader.pktlen <= 0) {
+                               break;
+                       }
+               }
+
+               last->buf = reader.src_buffer;
+               last->len = reader.src_len;
 
                last->proto_git = 1;
        } else if (maybe_smart &&
@@ -546,14 +555,30 @@ static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)
 }
 #endif
 
+struct rpc_in_data {
+       struct rpc_state *rpc;
+       struct active_request_slot *slot;
+};
+
+/*
+ * A callback for CURLOPT_WRITEFUNCTION. The return value is the bytes consumed
+ * from ptr.
+ */
 static size_t rpc_in(char *ptr, size_t eltsize,
                size_t nmemb, void *buffer_)
 {
        size_t size = eltsize * nmemb;
-       struct rpc_state *rpc = buffer_;
+       struct rpc_in_data *data = buffer_;
+       long response_code;
+
+       if (curl_easy_getinfo(data->slot->curl, CURLINFO_RESPONSE_CODE,
+                             &response_code) != CURLE_OK)
+               return size;
+       if (response_code >= 300)
+               return size;
        if (size)
-               rpc->any_written = 1;
-       write_or_die(rpc->in, ptr, size);
+               data->rpc->any_written = 1;
+       write_or_die(data->rpc->in, ptr, size);
        return size;
 }
 
@@ -634,6 +659,7 @@ static int post_rpc(struct rpc_state *rpc)
        size_t gzip_size = 0;
        int err, large_request = 0;
        int needs_100_continue = 0;
+       struct rpc_in_data rpc_in_data;
 
        /* Try to load the entire request, if we can fit it into the
         * allocated buffer space we can use HTTP/1.0 and avoid the
@@ -766,7 +792,10 @@ static int post_rpc(struct rpc_state *rpc)
 
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
        curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
-       curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
+       rpc_in_data.rpc = rpc;
+       rpc_in_data.slot = slot;
+       curl_easy_setopt(slot->curl, CURLOPT_FILE, &rpc_in_data);
+       curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0);
 
 
        rpc->any_written = 0;
@@ -1175,7 +1204,8 @@ static void proxy_state_init(struct proxy_state *p, const char *service_name,
                p->headers = curl_slist_append(p->headers, buf.buf);
 
        packet_reader_init(&p->reader, p->in, NULL, 0,
-                          PACKET_READ_GENTLE_ON_EOF);
+                          PACKET_READ_GENTLE_ON_EOF |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
 
        strbuf_release(&buf);
 }
index 670dd448130d20325f5f9f1de8afd0f011535db2..9cc3b07d214a63271849243c5f823b8f87ad631b 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -337,14 +337,14 @@ static int handle_config(const char *key, const char *value, void *cb)
                if (!name)
                        return 0;
                if (!strcmp(subkey, "insteadof")) {
-                       rewrite = make_rewrite(&rewrites, name, namelen);
                        if (!value)
                                return config_error_nonbool(key);
+                       rewrite = make_rewrite(&rewrites, name, namelen);
                        add_instead_of(rewrite, xstrdup(value));
                } else if (!strcmp(subkey, "pushinsteadof")) {
-                       rewrite = make_rewrite(&rewrites_push, name, namelen);
                        if (!value)
                                return config_error_nonbool(key);
+                       rewrite = make_rewrite(&rewrites_push, name, namelen);
                        add_instead_of(rewrite, xstrdup(value));
                }
        }
index 7b02e1dffac077d0c21ecaef915f4ea33abc57bc..65e6f8b8fdfcf89e5c86cbee9590aa555f7b0b47 100644 (file)
@@ -1,13 +1,20 @@
+/*
+ * not really _using_ the compat macros, just make sure the_index
+ * declaration matches the definition in this file.
+ */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "repository.h"
 #include "object-store.h"
 #include "config.h"
 #include "object.h"
+#include "lockfile.h"
 #include "submodule-config.h"
 
 /* The main repository */
 static struct repository the_repo;
 struct repository *the_repository;
+struct index_state the_index;
 
 void initialize_the_repository(void)
 {
@@ -172,30 +179,23 @@ int repo_init(struct repository *repo,
        return -1;
 }
 
-/*
- * Initialize 'submodule' as the submodule given by 'path' in parent repository
- * 'superproject'.
- * Return 0 upon success and a non-zero value upon failure.
- */
-int repo_submodule_init(struct repository *submodule,
+int repo_submodule_init(struct repository *subrepo,
                        struct repository *superproject,
-                       const char *path)
+                       const struct submodule *sub)
 {
-       const struct submodule *sub;
        struct strbuf gitdir = STRBUF_INIT;
        struct strbuf worktree = STRBUF_INIT;
        int ret = 0;
 
-       sub = submodule_from_path(superproject, &null_oid, path);
        if (!sub) {
                ret = -1;
                goto out;
        }
 
-       strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", path);
-       strbuf_repo_worktree_path(&worktree, superproject, "%s", path);
+       strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", sub->path);
+       strbuf_repo_worktree_path(&worktree, superproject, "%s", sub->path);
 
-       if (repo_init(submodule, gitdir.buf, worktree.buf)) {
+       if (repo_init(subrepo, gitdir.buf, worktree.buf)) {
                /*
                 * If initilization fails then it may be due to the submodule
                 * not being populated in the superproject's worktree.  Instead
@@ -207,16 +207,16 @@ int repo_submodule_init(struct repository *submodule,
                strbuf_repo_git_path(&gitdir, superproject,
                                     "modules/%s", sub->name);
 
-               if (repo_init(submodule, gitdir.buf, NULL)) {
+               if (repo_init(subrepo, gitdir.buf, NULL)) {
                        ret = -1;
                        goto out;
                }
        }
 
-       submodule->submodule_prefix = xstrfmt("%s%s/",
-                                             superproject->submodule_prefix ?
-                                             superproject->submodule_prefix :
-                                             "", path);
+       subrepo->submodule_prefix = xstrfmt("%s%s/",
+                                           superproject->submodule_prefix ?
+                                           superproject->submodule_prefix :
+                                           "", sub->path);
 
 out:
        strbuf_release(&gitdir);
@@ -263,3 +263,12 @@ int repo_read_index(struct repository *repo)
 
        return read_index_from(repo->index, repo->index_file, repo->gitdir);
 }
+
+int repo_hold_locked_index(struct repository *repo,
+                          struct lock_file *lf,
+                          int flags)
+{
+       if (!repo->index_file)
+               BUG("the repo hasn't been setup");
+       return hold_lock_file_for_update(lf, repo->index_file, flags);
+}
index 9f16c42c1ed04af3bf2e7767c4fd6c05b28ccf9c..8981649d43736ee283fcd23cd3185288252d5357 100644 (file)
@@ -6,6 +6,8 @@
 struct config_set;
 struct git_hash_algo;
 struct index_state;
+struct lock_file;
+struct pathspec;
 struct raw_object_store;
 struct submodule_cache;
 
@@ -116,9 +118,17 @@ void repo_set_worktree(struct repository *repo, const char *path);
 void repo_set_hash_algo(struct repository *repo, int algo);
 void initialize_the_repository(void);
 int repo_init(struct repository *r, const char *gitdir, const char *worktree);
-int repo_submodule_init(struct repository *submodule,
+
+/*
+ * Initialize the repository 'subrepo' as the submodule given by the
+ * struct submodule 'sub' in parent repository 'superproject'.
+ * Return 0 upon success and a non-zero value upon failure, which may happen
+ * if the submodule is not found, or 'sub' is NULL.
+ */
+struct submodule;
+int repo_submodule_init(struct repository *subrepo,
                        struct repository *superproject,
-                       const char *path);
+                       const struct submodule *sub);
 void repo_clear(struct repository *repo);
 
 /*
@@ -130,5 +140,19 @@ void repo_clear(struct repository *repo);
  * populated then the number of entries will simply be returned.
  */
 int repo_read_index(struct repository *repo);
+int repo_hold_locked_index(struct repository *repo,
+                          struct lock_file *lf,
+                          int flags);
+
+int repo_read_index_preload(struct repository *,
+                           const struct pathspec *pathspec,
+                           unsigned refresh_flags);
+int repo_read_index_unmerged(struct repository *);
+/*
+ * Opportunistically update the index but do not complain if we can't.
+ * The lockfile is always committed or rolled back.
+ */
+void repo_update_index_if_able(struct repository *, struct lock_file *);
+
 
 #endif /* REPOSITORY_H */
index 13624038e66c2084c478711599ed9f005cf2e53d..17abb47321f14ada67f8ffc6cbfb2ce0d527fa82 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -561,7 +561,7 @@ static int find_conflict(struct repository *r, struct string_list *conflict)
 {
        int i;
 
-       if (read_index(r->index) < 0)
+       if (repo_read_index(r) < 0)
                return error(_("index file corrupt"));
 
        for (i = 0; i < r->index->cache_nr;) {
@@ -595,7 +595,7 @@ int rerere_remaining(struct repository *r, struct string_list *merge_rr)
 
        if (setup_rerere(r, merge_rr, RERERE_READONLY))
                return 0;
-       if (read_index(r->index) < 0)
+       if (repo_read_index(r) < 0)
                return error(_("index file corrupt"));
 
        for (i = 0; i < r->index->cache_nr;) {
@@ -705,7 +705,7 @@ static void update_paths(struct repository *r, struct string_list *update)
        struct lock_file index_lock = LOCK_INIT;
        int i;
 
-       hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
+       repo_hold_locked_index(r, &index_lock, LOCK_DIE_ON_ERROR);
 
        for (i = 0; i < update->nr; i++) {
                struct string_list_item *item = &update->items[i];
@@ -1107,7 +1107,7 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec)
        struct string_list conflict = STRING_LIST_INIT_DUP;
        struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-       if (read_index(r->index) < 0)
+       if (repo_read_index(r) < 0)
                return error(_("index file corrupt"));
 
        fd = setup_rerere(r, &merge_rr, RERERE_NOAUTOUPDATE);
index 13cfb59b388d1503adbaef424ea1dcecc410b673..162d511d4686bc43f2032a57fa95e3601eb3d6b2 100644 (file)
@@ -27,6 +27,7 @@
 #include "commit-reach.h"
 #include "commit-graph.h"
 #include "prio-queue.h"
+#include "hashmap.h"
 
 volatile show_early_output_fn_t show_early_output;
 
@@ -67,10 +68,10 @@ static void mark_tree_contents_uninteresting(struct repository *r,
        while (tree_entry(&desc, &entry)) {
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
-                       mark_tree_uninteresting(r, lookup_tree(r, entry.oid));
+                       mark_tree_uninteresting(r, lookup_tree(r, &entry.oid));
                        break;
                case OBJ_BLOB:
-                       mark_blob_uninteresting(lookup_blob(r, entry.oid));
+                       mark_blob_uninteresting(lookup_blob(r, &entry.oid));
                        break;
                default:
                        /* Subproject commit - not in this repository */
@@ -99,6 +100,148 @@ void mark_tree_uninteresting(struct repository *r, struct tree *tree)
        mark_tree_contents_uninteresting(r, tree);
 }
 
+struct path_and_oids_entry {
+       struct hashmap_entry ent;
+       char *path;
+       struct oidset trees;
+};
+
+static int path_and_oids_cmp(const void *hashmap_cmp_fn_data,
+                            const struct path_and_oids_entry *e1,
+                            const struct path_and_oids_entry *e2,
+                            const void *keydata)
+{
+       return strcmp(e1->path, e2->path);
+}
+
+static void paths_and_oids_init(struct hashmap *map)
+{
+       hashmap_init(map, (hashmap_cmp_fn) path_and_oids_cmp, NULL, 0);
+}
+
+static void paths_and_oids_clear(struct hashmap *map)
+{
+       struct hashmap_iter iter;
+       struct path_and_oids_entry *entry;
+       hashmap_iter_init(map, &iter);
+
+       while ((entry = (struct path_and_oids_entry *)hashmap_iter_next(&iter))) {
+               oidset_clear(&entry->trees);
+               free(entry->path);
+       }
+
+       hashmap_free(map, 1);
+}
+
+static void paths_and_oids_insert(struct hashmap *map,
+                                 const char *path,
+                                 const struct object_id *oid)
+{
+       int hash = strhash(path);
+       struct path_and_oids_entry key;
+       struct path_and_oids_entry *entry;
+
+       hashmap_entry_init(&key, hash);
+
+       /* use a shallow copy for the lookup */
+       key.path = (char *)path;
+       oidset_init(&key.trees, 0);
+
+       if (!(entry = (struct path_and_oids_entry *)hashmap_get(map, &key, NULL))) {
+               entry = xcalloc(1, sizeof(struct path_and_oids_entry));
+               hashmap_entry_init(entry, hash);
+               entry->path = xstrdup(key.path);
+               oidset_init(&entry->trees, 16);
+               hashmap_put(map, entry);
+       }
+
+       oidset_insert(&entry->trees, oid);
+}
+
+static void add_children_by_path(struct repository *r,
+                                struct tree *tree,
+                                struct hashmap *map)
+{
+       struct tree_desc desc;
+       struct name_entry entry;
+
+       if (!tree)
+               return;
+
+       if (parse_tree_gently(tree, 1) < 0)
+               return;
+
+       init_tree_desc(&desc, tree->buffer, tree->size);
+       while (tree_entry(&desc, &entry)) {
+               switch (object_type(entry.mode)) {
+               case OBJ_TREE:
+                       paths_and_oids_insert(map, entry.path, &entry.oid);
+
+                       if (tree->object.flags & UNINTERESTING) {
+                               struct tree *child = lookup_tree(r, &entry.oid);
+                               if (child)
+                                       child->object.flags |= UNINTERESTING;
+                       }
+                       break;
+               case OBJ_BLOB:
+                       if (tree->object.flags & UNINTERESTING) {
+                               struct blob *child = lookup_blob(r, &entry.oid);
+                               if (child)
+                                       child->object.flags |= UNINTERESTING;
+                       }
+                       break;
+               default:
+                       /* Subproject commit - not in this repository */
+                       break;
+               }
+       }
+
+       free_tree_buffer(tree);
+}
+
+void mark_trees_uninteresting_sparse(struct repository *r,
+                                    struct oidset *trees)
+{
+       unsigned has_interesting = 0, has_uninteresting = 0;
+       struct hashmap map;
+       struct hashmap_iter map_iter;
+       struct path_and_oids_entry *entry;
+       struct object_id *oid;
+       struct oidset_iter iter;
+
+       oidset_iter_init(trees, &iter);
+       while ((!has_interesting || !has_uninteresting) &&
+              (oid = oidset_iter_next(&iter))) {
+               struct tree *tree = lookup_tree(r, oid);
+
+               if (!tree)
+                       continue;
+
+               if (tree->object.flags & UNINTERESTING)
+                       has_uninteresting = 1;
+               else
+                       has_interesting = 1;
+       }
+
+       /* Do not walk unless we have both types of trees. */
+       if (!has_uninteresting || !has_interesting)
+               return;
+
+       paths_and_oids_init(&map);
+
+       oidset_iter_init(trees, &iter);
+       while ((oid = oidset_iter_next(&iter))) {
+               struct tree *tree = lookup_tree(r, oid);
+               add_children_by_path(r, tree, &map);
+       }
+
+       hashmap_iter_init(&map, &map_iter);
+       while ((entry = hashmap_iter_next(&map_iter)))
+               mark_trees_uninteresting_sparse(r, &entry->trees);
+
+       paths_and_oids_clear(&map);
+}
+
 struct commit_stack {
        struct commit **items;
        size_t nr, alloc;
@@ -213,7 +356,20 @@ static struct object *get_reference(struct rev_info *revs, const char *name,
 {
        struct object *object;
 
-       object = parse_object(revs->repo, oid);
+       /*
+        * If the repository has commit graphs, repo_parse_commit() avoids
+        * reading the object buffer, so use it whenever possible.
+        */
+       if (oid_object_info(revs->repo, oid, NULL) == OBJ_COMMIT) {
+               struct commit *c = lookup_commit(revs->repo, oid);
+               if (!repo_parse_commit(revs->repo, c))
+                       object = (struct object *) c;
+               else
+                       object = NULL;
+       } else {
+               object = parse_object(revs->repo, oid);
+       }
+
        if (!object) {
                if (revs->ignore_missing)
                        return object;
@@ -1384,7 +1540,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
 {
        struct worktree **worktrees, **p;
 
-       read_index(revs->repo->index);
+       repo_read_index(revs->repo);
        do_add_index_objects_to_pending(revs, revs->repo->index, flags);
 
        if (revs->single_worktree)
@@ -1531,7 +1687,7 @@ static void prepare_show_merge(struct rev_info *revs)
        head->object.flags |= SYMMETRIC_LEFT;
 
        if (!istate->cache_nr)
-               read_index(istate);
+               repo_read_index(revs->repo);
        for (i = 0; i < istate->cache_nr; i++) {
                const struct cache_entry *ce = istate->cache[i];
                if (!ce_stage(ce))
@@ -1590,8 +1746,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
        if (!*b_name)
                b_name = "HEAD";
 
-       if (get_oid_with_context(a_name, oc_flags, &a_oid, a_oc) ||
-           get_oid_with_context(b_name, oc_flags, &b_oid, b_oc))
+       if (get_oid_with_context(revs->repo, a_name, oc_flags, &a_oid, a_oc) ||
+           get_oid_with_context(revs->repo, b_name, oc_flags, &b_oid, b_oc))
                return -1;
 
        if (!cant_be_filename) {
@@ -1725,7 +1881,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
        if (revarg_opt & REVARG_COMMITTISH)
                get_sha1_flags |= GET_OID_COMMITTISH;
 
-       if (get_oid_with_context(arg, get_sha1_flags, &oid, &oc))
+       if (get_oid_with_context(revs->repo, arg, get_sha1_flags, &oid, &oc))
                return revs->ignore_missing ? 0 : -1;
        if (!cant_be_filename)
                verify_non_filename(revs->prefix, arg);
@@ -2458,7 +2614,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
                struct object_id oid;
                struct object *object;
                struct object_context oc;
-               if (get_oid_with_context(revs->def, 0, &oid, &oc))
+               if (get_oid_with_context(revs->repo, revs->def, 0, &oid, &oc))
                        diagnose_missing_default(revs->def);
                object = get_reference(revs, revs->def, &oid, 0);
                add_pending_object_with_mode(revs, object, revs->def, oc.mode);
index 52e5a88ff5725862dced5c72fbc2aa6435b94e3b..d32d62abc6a7e65ba04a9f25c5024d6f5bbb5f49 100644 (file)
@@ -67,6 +67,7 @@ struct rev_cmdline_info {
 #define REVISION_WALK_NO_WALK_SORTED 1
 #define REVISION_WALK_NO_WALK_UNSORTED 2
 
+struct oidset;
 struct topo_walk_info;
 
 struct rev_info {
@@ -327,6 +328,7 @@ void put_revision_mark(const struct rev_info *revs,
 
 void mark_parents_uninteresting(struct commit *commit);
 void mark_tree_uninteresting(struct repository *r, struct tree *tree);
+void mark_trees_uninteresting_sparse(struct repository *r, struct oidset *trees);
 
 void show_object_with_name(FILE *, struct object *, const char *);
 
index f692686770f69b49d44bf6dbabdb17886d85ea1a..7b9829f165e7aff7abe804fb780cf7c9d88aaf73 100644 (file)
@@ -135,38 +135,36 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
        return 0;
 }
 
-static int receive_unpack_status(int in)
+static int receive_unpack_status(struct packet_reader *reader)
 {
-       const char *line = packet_read_line(in, NULL);
-       if (!line)
+       if (packet_reader_read(reader) != PACKET_READ_NORMAL)
                return error(_("unexpected flush packet while reading remote unpack status"));
-       if (!skip_prefix(line, "unpack ", &line))
-               return error(_("unable to parse remote unpack status: %s"), line);
-       if (strcmp(line, "ok"))
-               return error(_("remote unpack failed: %s"), line);
+       if (!skip_prefix(reader->line, "unpack ", &reader->line))
+               return error(_("unable to parse remote unpack status: %s"), reader->line);
+       if (strcmp(reader->line, "ok"))
+               return error(_("remote unpack failed: %s"), reader->line);
        return 0;
 }
 
-static int receive_status(int in, struct ref *refs)
+static int receive_status(struct packet_reader *reader, struct ref *refs)
 {
        struct ref *hint;
        int ret;
 
        hint = NULL;
-       ret = receive_unpack_status(in);
+       ret = receive_unpack_status(reader);
        while (1) {
-               char *refname;
+               const char *refname;
                char *msg;
-               char *line = packet_read_line(in, NULL);
-               if (!line)
+               if (packet_reader_read(reader) != PACKET_READ_NORMAL)
                        break;
-               if (!starts_with(line, "ok ") && !starts_with(line, "ng ")) {
-                       error("invalid ref status from remote: %s", line);
+               if (!starts_with(reader->line, "ok ") && !starts_with(reader->line, "ng ")) {
+                       error("invalid ref status from remote: %s", reader->line);
                        ret = -1;
                        break;
                }
 
-               refname = line + 3;
+               refname = reader->line + 3;
                msg = strchr(refname, ' ');
                if (msg)
                        *msg++ = '\0';
@@ -187,7 +185,7 @@ static int receive_status(int in, struct ref *refs)
                        continue;
                }
 
-               if (line[0] == 'o' && line[1] == 'k')
+               if (reader->line[0] == 'o' && reader->line[1] == 'k')
                        hint->status = REF_STATUS_OK;
                else {
                        hint->status = REF_STATUS_REMOTE_REJECT;
@@ -390,6 +388,7 @@ int send_pack(struct send_pack_args *args,
        int ret;
        struct async demux;
        const char *push_cert_nonce = NULL;
+       struct packet_reader reader;
 
        /* Does the other end support the reporting? */
        if (server_supports("report-status"))
@@ -559,6 +558,10 @@ int send_pack(struct send_pack_args *args,
                in = demux.out;
        }
 
+       packet_reader_init(&reader, in, NULL, 0,
+                          PACKET_READ_CHOMP_NEWLINE |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
+
        if (need_pack_data && cmds_sent) {
                if (pack_objects(out, remote_refs, extra_have, args) < 0) {
                        for (ref = remote_refs; ref; ref = ref->next)
@@ -573,7 +576,7 @@ int send_pack(struct send_pack_args *args,
                         * are failing, and just want the error() side effects.
                         */
                        if (status_report)
-                               receive_unpack_status(in);
+                               receive_unpack_status(&reader);
 
                        if (use_sideband) {
                                close(demux.out);
@@ -590,7 +593,7 @@ int send_pack(struct send_pack_args *args,
                packet_flush(out);
 
        if (status_report && cmds_sent)
-               ret = receive_status(in, remote_refs);
+               ret = receive_status(&reader, remote_refs);
        else
                ret = 0;
        if (args->stateless_rpc)
index f5370f49659a3da10c8092c0b1682da08a1fab07..972402e8c0a09de5ec9069826cbb7ecae1ac9803 100644 (file)
@@ -150,6 +150,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
 static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt")
 static GIT_PATH_FUNC(rebase_path_orig_head, "rebase-merge/orig-head")
 static GIT_PATH_FUNC(rebase_path_verbose, "rebase-merge/verbose")
+static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet")
 static GIT_PATH_FUNC(rebase_path_signoff, "rebase-merge/signoff")
 static GIT_PATH_FUNC(rebase_path_head_name, "rebase-merge/head-name")
 static GIT_PATH_FUNC(rebase_path_onto, "rebase-merge/onto")
@@ -157,7 +158,7 @@ static GIT_PATH_FUNC(rebase_path_autostash, "rebase-merge/autostash")
 static GIT_PATH_FUNC(rebase_path_strategy, "rebase-merge/strategy")
 static GIT_PATH_FUNC(rebase_path_strategy_opts, "rebase-merge/strategy_opts")
 static GIT_PATH_FUNC(rebase_path_allow_rerere_autoupdate, "rebase-merge/allow_rerere_autoupdate")
-static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet")
+static GIT_PATH_FUNC(rebase_path_reschedule_failed_exec, "rebase-merge/reschedule-failed-exec")
 
 static int git_sequencer_config(const char *k, const char *v, void *cb)
 {
@@ -446,9 +447,9 @@ static struct tree *empty_tree(struct repository *r)
        return lookup_tree(r, the_hash_algo->empty_tree);
 }
 
-static int error_dirty_index(struct index_state *istate, struct replay_opts *opts)
+static int error_dirty_index(struct repository *repo, struct replay_opts *opts)
 {
-       if (read_index_unmerged(istate))
+       if (repo_read_index_unmerged(repo))
                return error_resolve_conflict(_(action_name(opts)));
 
        error(_("your local changes would be overwritten by %s."),
@@ -483,7 +484,7 @@ static int fast_forward_to(struct repository *r,
        struct strbuf sb = STRBUF_INIT;
        struct strbuf err = STRBUF_INIT;
 
-       read_index(r->index);
+       repo_read_index(r);
        if (checkout_fast_forward(r, from, to, 1))
                return -1; /* the callee should have complained already */
 
@@ -540,12 +541,12 @@ static int do_recursive_merge(struct repository *r,
        char **xopt;
        struct lock_file index_lock = LOCK_INIT;
 
-       if (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0)
+       if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0)
                return -1;
 
-       read_index(r->index);
+       repo_read_index(r);
 
-       init_merge_options(&o);
+       init_merge_options(&o, r);
        o.ancestor = base ? base_label : "(empty tree)";
        o.branch1 = "HEAD";
        o.branch2 = next ? next_label : "(empty tree)";
@@ -1115,7 +1116,8 @@ static int run_rewrite_hook(const struct object_id *oldoid,
        return finish_command(&proc);
 }
 
-void commit_post_rewrite(const struct commit *old_head,
+void commit_post_rewrite(struct repository *r,
+                        const struct commit *old_head,
                         const struct object_id *new_head)
 {
        struct notes_rewrite_cfg *cfg;
@@ -1124,7 +1126,7 @@ void commit_post_rewrite(const struct commit *old_head,
        if (cfg) {
                /* we are amending, so old_head is not NULL */
                copy_note_for_rewrite(cfg, &old_head->object.oid, new_head);
-               finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'");
+               finish_copy_notes_for_rewrite(r, cfg, "Notes added by 'git commit --amend'");
        }
        run_rewrite_hook(&old_head->object.oid, new_head);
 }
@@ -1405,7 +1407,7 @@ static int try_to_commit(struct repository *r,
        }
 
        if (flags & AMEND_MSG)
-               commit_post_rewrite(current_head, oid);
+               commit_post_rewrite(r, current_head, oid);
 
 out:
        free_commit_extra_headers(extra);
@@ -1767,7 +1769,7 @@ static int do_pick_commit(struct repository *r,
                        oidcpy(&head, the_hash_algo->empty_tree);
                if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
                                       NULL, 0))
-                       return error_dirty_index(r->index, opts);
+                       return error_dirty_index(r, opts);
        }
        discard_index(r->index);
 
@@ -1997,8 +1999,8 @@ static int read_and_refresh_cache(struct repository *r,
                                  struct replay_opts *opts)
 {
        struct lock_file index_lock = LOCK_INIT;
-       int index_fd = hold_locked_index(&index_lock, 0);
-       if (read_index(r->index) < 0) {
+       int index_fd = repo_hold_locked_index(r, &index_lock, 0);
+       if (repo_read_index(r) < 0) {
                rollback_lock_file(&index_lock);
                return error(_("git %s: failed to read the index"),
                        _(action_name(opts)));
@@ -2389,11 +2391,17 @@ static int read_populate_opts(struct replay_opts *opts)
                if (file_exists(rebase_path_verbose()))
                        opts->verbose = 1;
 
+               if (file_exists(rebase_path_quiet()))
+                       opts->quiet = 1;
+
                if (file_exists(rebase_path_signoff())) {
                        opts->allow_ff = 0;
                        opts->signoff = 1;
                }
 
+               if (file_exists(rebase_path_reschedule_failed_exec()))
+                       opts->reschedule_failed_exec = 1;
+
                read_strategy_opts(opts, &buf);
                strbuf_release(&buf);
 
@@ -2456,9 +2464,6 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
 
        if (quiet)
                write_file(rebase_path_quiet(), "%s\n", quiet);
-       else
-               write_file(rebase_path_quiet(), "\n");
-
        if (opts->verbose)
                write_file(rebase_path_verbose(), "%s", "");
        if (opts->strategy)
@@ -2475,6 +2480,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
                write_file(rebase_path_gpg_sign_opt(), "-S%s\n", opts->gpg_sign);
        if (opts->signoff)
                write_file(rebase_path_signoff(), "--signoff\n");
+       if (opts->reschedule_failed_exec)
+               write_file(rebase_path_reschedule_failed_exec(), "%s", "");
 
        return 0;
 }
@@ -2859,7 +2866,7 @@ static int do_exec(struct repository *r, const char *command_line)
                                          child_env.argv);
 
        /* force re-reading of the cache */
-       if (discard_index(r->index) < 0 || read_index(r->index) < 0)
+       if (discard_index(r->index) < 0 || repo_read_index(r) < 0)
                return error(_("could not read index"));
 
        dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1);
@@ -2983,7 +2990,7 @@ static int do_reset(struct repository *r,
        struct unpack_trees_options unpack_tree_opts;
        int ret = 0;
 
-       if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0)
+       if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0)
                return -1;
 
        if (len == 10 && !strncmp("[new root]", name, len)) {
@@ -3028,7 +3035,7 @@ static int do_reset(struct repository *r,
        unpack_tree_opts.merge = 1;
        unpack_tree_opts.update = 1;
 
-       if (read_index_unmerged(r->index)) {
+       if (repo_read_index_unmerged(r)) {
                rollback_lock_file(&lock);
                strbuf_release(&ref_name);
                return error_resolve_conflict(_(action_name(opts)));
@@ -3101,7 +3108,7 @@ static int do_merge(struct repository *r,
        static struct lock_file lock;
        const char *p;
 
-       if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
+       if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) {
                ret = -1;
                goto leave_merge;
        }
@@ -3282,7 +3289,7 @@ static int do_merge(struct repository *r,
 
                /* force re-reading of the cache */
                if (!ret && (discard_index(r->index) < 0 ||
-                            read_index(r->index) < 0))
+                            repo_read_index(r) < 0))
                        ret = error(_("could not read index"));
                goto leave_merge;
        }
@@ -3304,8 +3311,8 @@ static int do_merge(struct repository *r,
                commit_list_insert(j->item, &reversed);
        free_commit_list(bases);
 
-       read_index(r->index);
-       init_merge_options(&o);
+       repo_read_index(r);
+       init_merge_options(&o, r);
        o.branch1 = "HEAD";
        o.branch2 = ref_name.buf;
        o.buffer_output = 2;
@@ -3549,10 +3556,11 @@ static int pick_commits(struct repository *r,
                                        fprintf(f, "%d\n", todo_list->done_nr);
                                        fclose(f);
                                }
-                               fprintf(stderr, "Rebasing (%d/%d)%s",
-                                       todo_list->done_nr,
-                                       todo_list->total_nr,
-                                       opts->verbose ? "\n" : "\r");
+                               if (!opts->quiet)
+                                       fprintf(stderr, "Rebasing (%d/%d)%s",
+                                               todo_list->done_nr,
+                                               todo_list->total_nr,
+                                               opts->verbose ? "\n" : "\r");
                        }
                        unlink(rebase_path_message());
                        unlink(rebase_path_author_script());
@@ -3632,9 +3640,10 @@ static int pick_commits(struct repository *r,
                        *end_of_arg = saved;
 
                        /* Reread the todo file if it has changed. */
-                       if (res)
-                               ; /* fall through */
-                       else if (stat(get_todo_path(opts), &st))
+                       if (res) {
+                               if (opts->reschedule_failed_exec)
+                                       reschedule = 1;
+                       } else if (stat(get_todo_path(opts), &st))
                                res = error_errno(_("could not stat '%s'"),
                                                  get_todo_path(opts));
                        else if (match_stat_data(&todo_list->stat, &st)) {
@@ -3785,8 +3794,10 @@ static int pick_commits(struct repository *r,
                }
                apply_autostash(opts);
 
-               fprintf(stderr, "Successfully rebased and updated %s.\n",
-                       head_ref.buf);
+               if (!opts->quiet)
+                       fprintf(stderr,
+                               "Successfully rebased and updated %s.\n",
+                               head_ref.buf);
 
                strbuf_release(&buf);
                strbuf_release(&head_ref);
@@ -3977,7 +3988,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
                                goto release_todo_list;
                }
                if (index_differs_from(r, "HEAD", NULL, 0)) {
-                       res = error_dirty_index(r->index, opts);
+                       res = error_dirty_index(r, opts);
                        goto release_todo_list;
                }
                todo_list.current++;
index 9d83f0f3e90313be990439972845e9d4f2bc1804..93e891309bb7982c283c77e8950ba8848fdd7d2b 100644 (file)
@@ -40,6 +40,8 @@ struct replay_opts {
        int allow_empty_message;
        int keep_redundant_commits;
        int verbose;
+       int quiet;
+       int reschedule_failed_exec;
 
        int mainline;
 
@@ -124,7 +126,8 @@ int update_head_with_reflog(const struct commit *old_head,
                            const struct object_id *new_head,
                            const char *action, const struct strbuf *msg,
                            struct strbuf *err);
-void commit_post_rewrite(const struct commit *current_head,
+void commit_post_rewrite(struct repository *r,
+                        const struct commit *current_head,
                         const struct object_id *new_head);
 
 int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit);
diff --git a/serve.c b/serve.c
index bda085f09c8e10314c2c497dbca978fd9241e7b5..317256c1a493c4b2cc730a6212add4d1ef5696d4 100644 (file)
--- a/serve.c
+++ b/serve.c
@@ -167,7 +167,8 @@ static int process_request(void)
 
        packet_reader_init(&reader, 0, NULL, 0,
                           PACKET_READ_CHOMP_NEWLINE |
-                          PACKET_READ_GENTLE_ON_EOF);
+                          PACKET_READ_GENTLE_ON_EOF |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
 
        /*
         * Check to see if the client closed their end before sending another
@@ -175,7 +176,7 @@ static int process_request(void)
         */
        if (packet_reader_peek(&reader) == PACKET_READ_EOF)
                return 1;
-       reader.options = PACKET_READ_CHOMP_NEWLINE;
+       reader.options &= ~PACKET_READ_GENTLE_ON_EOF;
 
        while (state != PROCESS_REQUEST_DONE) {
                switch (packet_reader_peek(&reader)) {
diff --git a/setup.c b/setup.c
index 12bf25a0ebad33a8d8db9b8f9a44b0e6e04977d4..ca9e8a949ed869183f16c57520f19fb361100a02 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -39,7 +39,7 @@ static int abspath_part_inside_repo(char *path)
        off = offset_1st_component(path);
 
        /* check if work tree is already the prefix */
-       if (wtlen <= len && !strncmp(path, work_tree, wtlen)) {
+       if (wtlen <= len && !fspathncmp(path, work_tree, wtlen)) {
                if (path[wtlen] == '/') {
                        memmove(path, path + wtlen + 1, len - wtlen);
                        return 0;
@@ -59,7 +59,7 @@ static int abspath_part_inside_repo(char *path)
                path++;
                if (*path == '/') {
                        *path = '\0';
-                       if (strcmp(real_path(path0), work_tree) == 0) {
+                       if (fspathcmp(real_path(path0), work_tree) == 0) {
                                memmove(path0, path + 1, len - (path - path0));
                                return 0;
                        }
@@ -68,7 +68,7 @@ static int abspath_part_inside_repo(char *path)
        }
 
        /* check whole path */
-       if (strcmp(real_path(path0), work_tree) == 0) {
+       if (fspathcmp(real_path(path0), work_tree) == 0) {
                *path0 = '\0';
                return 0;
        }
index b94e0ec0f5e45fa56e1748bbb611a904ab81de67..d922e94e3fc58488402ac0095075bf5ef0e4d17b 100644 (file)
@@ -77,3 +77,20 @@ int oid_array_for_each_unique(struct oid_array *array,
        }
        return 0;
 }
+
+void oid_array_filter(struct oid_array *array,
+                     for_each_oid_fn want,
+                     void *cb_data)
+{
+       unsigned nr = array->nr, src, dst;
+       struct object_id *oids = array->oid;
+
+       for (src = dst = 0; src < nr; src++) {
+               if (want(&oids[src], cb_data)) {
+                       if (src != dst)
+                               oidcpy(&oids[dst], &oids[src]);
+                       dst++;
+               }
+       }
+       array->nr = dst;
+}
index 232bf9501729696846f514e13ce5f23c425d9d27..55d016c4bf7bf56936f034b7550996d1b7ca6473 100644 (file)
@@ -22,5 +22,8 @@ int oid_array_for_each(struct oid_array *array,
 int oid_array_for_each_unique(struct oid_array *array,
                              for_each_oid_fn fn,
                              void *data);
+void oid_array_filter(struct oid_array *array,
+                     for_each_oid_fn want,
+                     void *cbdata);
 
 #endif /* SHA1_ARRAY_H */
index 386b96e1d76622e4650c1bbab90092fef7dd7303..c8da9f34752c4d8f6518c8ed8c42164368e973a3 100644 (file)
 #define EMPTY_TREE_SHA1_BIN_LITERAL \
         "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
         "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
+#define EMPTY_TREE_SHA256_BIN_LITERAL \
+       "\x6e\xf1\x9b\x41\x22\x5c\x53\x69\xf1\xc1" \
+       "\x04\xd4\x5d\x8d\x85\xef\xa9\xb0\x57\xb5" \
+       "\x3b\x14\xb4\xb9\xb9\x39\xdd\x74\xde\xcc" \
+       "\x53\x21"
 
 #define EMPTY_BLOB_SHA1_BIN_LITERAL \
        "\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" \
        "\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91"
+#define EMPTY_BLOB_SHA256_BIN_LITERAL \
+       "\x47\x3a\x0f\x4c\x3b\xe8\xa9\x36\x81\xa2" \
+       "\x67\xe3\xb1\xe9\xa7\xdc\xda\x11\x85\x43" \
+       "\x6f\xe1\x41\xf7\x74\x91\x20\xa3\x03\x72" \
+       "\x18\x13"
 
 const unsigned char null_sha1[GIT_MAX_RAWSZ];
 const struct object_id null_oid;
@@ -53,6 +63,12 @@ static const struct object_id empty_tree_oid = {
 static const struct object_id empty_blob_oid = {
        EMPTY_BLOB_SHA1_BIN_LITERAL
 };
+static const struct object_id empty_tree_oid_sha256 = {
+       EMPTY_TREE_SHA256_BIN_LITERAL
+};
+static const struct object_id empty_blob_oid_sha256 = {
+       EMPTY_BLOB_SHA256_BIN_LITERAL
+};
 
 static void git_hash_sha1_init(git_hash_ctx *ctx)
 {
@@ -69,6 +85,22 @@ static void git_hash_sha1_final(unsigned char *hash, git_hash_ctx *ctx)
        git_SHA1_Final(hash, &ctx->sha1);
 }
 
+
+static void git_hash_sha256_init(git_hash_ctx *ctx)
+{
+       git_SHA256_Init(&ctx->sha256);
+}
+
+static void git_hash_sha256_update(git_hash_ctx *ctx, const void *data, size_t len)
+{
+       git_SHA256_Update(&ctx->sha256, data, len);
+}
+
+static void git_hash_sha256_final(unsigned char *hash, git_hash_ctx *ctx)
+{
+       git_SHA256_Final(hash, &ctx->sha256);
+}
+
 static void git_hash_unknown_init(git_hash_ctx *ctx)
 {
        BUG("trying to init unknown hash");
@@ -90,6 +122,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
                0x00000000,
                0,
                0,
+               0,
                git_hash_unknown_init,
                git_hash_unknown_update,
                git_hash_unknown_final,
@@ -97,17 +130,31 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
                NULL,
        },
        {
-               "sha-1",
+               "sha1",
                /* "sha1", big-endian */
                0x73686131,
                GIT_SHA1_RAWSZ,
                GIT_SHA1_HEXSZ,
+               GIT_SHA1_BLKSZ,
                git_hash_sha1_init,
                git_hash_sha1_update,
                git_hash_sha1_final,
                &empty_tree_oid,
                &empty_blob_oid,
        },
+       {
+               "sha256",
+               /* "s256", big-endian */
+               0x73323536,
+               GIT_SHA256_RAWSZ,
+               GIT_SHA256_HEXSZ,
+               GIT_SHA256_BLKSZ,
+               git_hash_sha256_init,
+               git_hash_sha256_update,
+               git_hash_sha256_final,
+               &empty_tree_oid_sha256,
+               &empty_blob_oid_sha256,
+       }
 };
 
 const char *empty_tree_oid_hex(void)
@@ -122,6 +169,27 @@ const char *empty_blob_oid_hex(void)
        return oid_to_hex_r(buf, the_hash_algo->empty_blob);
 }
 
+int hash_algo_by_name(const char *name)
+{
+       int i;
+       if (!name)
+               return GIT_HASH_UNKNOWN;
+       for (i = 1; i < GIT_HASH_NALGOS; i++)
+               if (!strcmp(name, hash_algos[i].name))
+                       return i;
+       return GIT_HASH_UNKNOWN;
+}
+
+int hash_algo_by_id(uint32_t format_id)
+{
+       int i;
+       for (i = 1; i < GIT_HASH_NALGOS; i++)
+               if (format_id == hash_algos[i].format_id)
+                       return i;
+       return GIT_HASH_UNKNOWN;
+}
+
+
 /*
  * This is meant to hold a *small* number of objects that you would
  * want read_sha1_file() to be able to return, but yet you do not want
@@ -1353,7 +1421,9 @@ int oid_object_info(struct repository *r,
        return type;
 }
 
-static void *read_object(const unsigned char *sha1, enum object_type *type,
+static void *read_object(struct repository *r,
+                        const unsigned char *sha1,
+                        enum object_type *type,
                         unsigned long *size)
 {
        struct object_id oid;
@@ -1365,7 +1435,7 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
 
        hashcpy(oid.hash, sha1);
 
-       if (oid_object_info_extended(the_repository, &oid, &oi, 0) < 0)
+       if (oid_object_info_extended(r, &oid, &oi, 0) < 0)
                return NULL;
        return content;
 }
@@ -1393,7 +1463,8 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
  * deal with them should arrange to call read_object() and give error
  * messages themselves.
  */
-void *read_object_file_extended(const struct object_id *oid,
+void *read_object_file_extended(struct repository *r,
+                               const struct object_id *oid,
                                enum object_type *type,
                                unsigned long *size,
                                int lookup_replace)
@@ -1403,10 +1474,10 @@ void *read_object_file_extended(const struct object_id *oid,
        const char *path;
        struct stat st;
        const struct object_id *repl = lookup_replace ?
-               lookup_replace_object(the_repository, oid) : oid;
+               lookup_replace_object(r, oid) : oid;
 
        errno = 0;
-       data = read_object(repl->hash, type, size);
+       data = read_object(r, repl->hash, type, size);
        if (data)
                return data;
 
@@ -1418,11 +1489,11 @@ void *read_object_file_extended(const struct object_id *oid,
                die(_("replacement %s not found for %s"),
                    oid_to_hex(repl), oid_to_hex(oid));
 
-       if (!stat_sha1_file(the_repository, repl->hash, &st, &path))
+       if (!stat_sha1_file(r, repl->hash, &st, &path))
                die(_("loose object %s (stored in %s) is corrupt"),
                    oid_to_hex(repl), path);
 
-       if ((p = has_packed_and_bad(repl->hash)) != NULL)
+       if ((p = has_packed_and_bad(r, repl->hash)) != NULL)
                die(_("packed object %s (stored in %s) is corrupt"),
                    oid_to_hex(repl), p->pack_name);
 
@@ -1746,7 +1817,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
 
        if (has_loose_object(oid))
                return 0;
-       buf = read_object(oid->hash, &type, &len);
+       buf = read_object(the_repository, oid->hash, &type, &len);
        if (!buf)
                return error(_("cannot read sha1_file for %s"), oid_to_hex(oid));
        hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(type), (uintmax_t)len) + 1;
@@ -1756,24 +1827,27 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
        return ret;
 }
 
-int has_sha1_file_with_flags(const unsigned char *sha1, int flags)
+int repo_has_sha1_file_with_flags(struct repository *r,
+                                 const unsigned char *sha1, int flags)
 {
        struct object_id oid;
        if (!startup_info->have_repository)
                return 0;
        hashcpy(oid.hash, sha1);
-       return oid_object_info_extended(the_repository, &oid, NULL,
+       return oid_object_info_extended(r, &oid, NULL,
                                        flags | OBJECT_INFO_SKIP_CACHED) >= 0;
 }
 
-int has_object_file(const struct object_id *oid)
+int repo_has_object_file(struct repository *r,
+                        const struct object_id *oid)
 {
-       return has_sha1_file(oid->hash);
+       return repo_has_sha1_file(r, oid->hash);
 }
 
-int has_object_file_with_flags(const struct object_id *oid, int flags)
+int repo_has_object_file_with_flags(struct repository *r,
+                                   const struct object_id *oid, int flags)
 {
-       return has_sha1_file_with_flags(oid->hash, flags);
+       return repo_has_sha1_file_with_flags(r, oid->hash, flags);
 }
 
 static void check_tree(const void *buf, size_t size)
index a656481c6aa9fbfe3eeff2367232690208ab8566..d1cc77c124c11ffd49be472b1368baeda3afbe17 100644 (file)
@@ -190,9 +190,6 @@ static void find_short_packed_object(struct disambiguate_state *ds)
                unique_in_pack(p, ds);
 }
 
-#define SHORT_NAME_NOT_FOUND (-1)
-#define SHORT_NAME_AMBIGUOUS (-2)
-
 static int finish_object_disambiguation(struct disambiguate_state *ds,
                                        struct object_id *oid)
 {
@@ -200,7 +197,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
                return SHORT_NAME_AMBIGUOUS;
 
        if (!ds->candidate_exists)
-               return SHORT_NAME_NOT_FOUND;
+               return MISSING_OBJECT;
 
        if (!ds->candidate_checked)
                /*
@@ -414,8 +411,9 @@ static int sort_ambiguous(const void *a, const void *b)
        return a_type_sort > b_type_sort ? 1 : -1;
 }
 
-static int get_short_oid(const char *name, int len, struct object_id *oid,
-                         unsigned flags)
+static enum get_oid_result get_short_oid(const char *name, int len,
+                                        struct object_id *oid,
+                                        unsigned flags)
 {
        int status;
        struct disambiguate_state ds;
@@ -733,7 +731,7 @@ static inline int push_mark(const char *string, int len)
        return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
 }
 
-static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
+static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
 
 static int get_oid_basic(const char *str, int len, struct object_id *oid,
@@ -883,11 +881,12 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
        return 0;
 }
 
-static int get_parent(const char *name, int len,
-                     struct object_id *result, int idx)
+static enum get_oid_result get_parent(const char *name, int len,
+                                     struct object_id *result, int idx)
 {
        struct object_id oid;
-       int ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
+       enum get_oid_result ret = get_oid_1(name, len, &oid,
+                                           GET_OID_COMMITTISH);
        struct commit *commit;
        struct commit_list *p;
 
@@ -895,24 +894,25 @@ static int get_parent(const char *name, int len,
                return ret;
        commit = lookup_commit_reference(the_repository, &oid);
        if (parse_commit(commit))
-               return -1;
+               return MISSING_OBJECT;
        if (!idx) {
                oidcpy(result, &commit->object.oid);
-               return 0;
+               return FOUND;
        }
        p = commit->parents;
        while (p) {
                if (!--idx) {
                        oidcpy(result, &p->item->object.oid);
-                       return 0;
+                       return FOUND;
                }
                p = p->next;
        }
-       return -1;
+       return MISSING_OBJECT;
 }
 
-static int get_nth_ancestor(const char *name, int len,
-                           struct object_id *result, int generation)
+static enum get_oid_result get_nth_ancestor(const char *name, int len,
+                                           struct object_id *result,
+                                           int generation)
 {
        struct object_id oid;
        struct commit *commit;
@@ -923,15 +923,15 @@ static int get_nth_ancestor(const char *name, int len,
                return ret;
        commit = lookup_commit_reference(the_repository, &oid);
        if (!commit)
-               return -1;
+               return MISSING_OBJECT;
 
        while (generation--) {
                if (parse_commit(commit) || !commit->parents)
-                       return -1;
+                       return MISSING_OBJECT;
                commit = commit->parents->item;
        }
        oidcpy(result, &commit->object.oid);
-       return 0;
+       return FOUND;
 }
 
 struct object *peel_to_type(const char *name, int namelen,
@@ -1077,7 +1077,9 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)
        return -1;
 }
 
-static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags)
+static enum get_oid_result get_oid_1(const char *name, int len,
+                                    struct object_id *oid,
+                                    unsigned lookup_flags)
 {
        int ret, has_suffix;
        const char *cp;
@@ -1111,16 +1113,16 @@ static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned
 
        ret = peel_onion(name, len, oid, lookup_flags);
        if (!ret)
-               return 0;
+               return FOUND;
 
        ret = get_oid_basic(name, len, oid, lookup_flags);
        if (!ret)
-               return 0;
+               return FOUND;
 
        /* It could be describe output that is "SOMETHING-gXXXX" */
        ret = get_describe_name(name, len, oid);
        if (!ret)
-               return 0;
+               return FOUND;
 
        return get_short_oid(name, len, oid, lookup_flags);
 }
@@ -1513,7 +1515,7 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
 int get_oid(const char *name, struct object_id *oid)
 {
        struct object_context unused;
-       return get_oid_with_context(name, 0, oid, &unused);
+       return get_oid_with_context(the_repository, name, 0, oid, &unused);
 }
 
 
@@ -1530,35 +1532,40 @@ int get_oid(const char *name, struct object_id *oid)
 int get_oid_committish(const char *name, struct object_id *oid)
 {
        struct object_context unused;
-       return get_oid_with_context(name, GET_OID_COMMITTISH,
+       return get_oid_with_context(the_repository,
+                                   name, GET_OID_COMMITTISH,
                                    oid, &unused);
 }
 
 int get_oid_treeish(const char *name, struct object_id *oid)
 {
        struct object_context unused;
-       return get_oid_with_context(name, GET_OID_TREEISH,
+       return get_oid_with_context(the_repository,
+                                   name, GET_OID_TREEISH,
                                    oid, &unused);
 }
 
 int get_oid_commit(const char *name, struct object_id *oid)
 {
        struct object_context unused;
-       return get_oid_with_context(name, GET_OID_COMMIT,
+       return get_oid_with_context(the_repository,
+                                   name, GET_OID_COMMIT,
                                    oid, &unused);
 }
 
 int get_oid_tree(const char *name, struct object_id *oid)
 {
        struct object_context unused;
-       return get_oid_with_context(name, GET_OID_TREE,
+       return get_oid_with_context(the_repository,
+                                   name, GET_OID_TREE,
                                    oid, &unused);
 }
 
 int get_oid_blob(const char *name, struct object_id *oid)
 {
        struct object_context unused;
-       return get_oid_with_context(name, GET_OID_BLOB,
+       return get_oid_with_context(the_repository,
+                                   name, GET_OID_BLOB,
                                    oid, &unused);
 }
 
@@ -1597,7 +1604,8 @@ static void diagnose_invalid_oid_path(const char *prefix,
 }
 
 /* Must be called only when :stage:filename doesn't exist. */
-static void diagnose_invalid_index_path(int stage,
+static void diagnose_invalid_index_path(struct index_state *istate,
+                                       int stage,
                                        const char *prefix,
                                        const char *filename)
 {
@@ -1610,11 +1618,11 @@ static void diagnose_invalid_index_path(int stage,
                prefix = "";
 
        /* Wrong stage number? */
-       pos = cache_name_pos(filename, namelen);
+       pos = index_name_pos(istate, filename, namelen);
        if (pos < 0)
                pos = -pos - 1;
-       if (pos < active_nr) {
-               ce = active_cache[pos];
+       if (pos < istate->cache_nr) {
+               ce = istate->cache[pos];
                if (ce_namelen(ce) == namelen &&
                    !memcmp(ce->name, filename, namelen))
                        die("Path '%s' is in the index, but not at stage %d.\n"
@@ -1626,11 +1634,11 @@ static void diagnose_invalid_index_path(int stage,
        /* Confusion between relative and absolute filenames? */
        strbuf_addstr(&fullname, prefix);
        strbuf_addstr(&fullname, filename);
-       pos = cache_name_pos(fullname.buf, fullname.len);
+       pos = index_name_pos(istate, fullname.buf, fullname.len);
        if (pos < 0)
                pos = -pos - 1;
-       if (pos < active_nr) {
-               ce = active_cache[pos];
+       if (pos < istate->cache_nr) {
+               ce = istate->cache[pos];
                if (ce_namelen(ce) == fullname.len &&
                    !memcmp(ce->name, fullname.buf, fullname.len))
                        die("Path '%s' is in the index, but not '%s'.\n"
@@ -1664,7 +1672,8 @@ static char *resolve_relative_path(const char *rel)
                           rel);
 }
 
-static int get_oid_with_context_1(const char *name,
+static enum get_oid_result get_oid_with_context_1(struct repository *repo,
+                                 const char *name,
                                  unsigned flags,
                                  const char *prefix,
                                  struct object_id *oid,
@@ -1723,13 +1732,13 @@ static int get_oid_with_context_1(const char *name,
                if (flags & GET_OID_RECORD_PATH)
                        oc->path = xstrdup(cp);
 
-               if (!active_cache)
-                       read_cache();
-               pos = cache_name_pos(cp, namelen);
+               if (!repo->index->cache)
+                       repo_read_index(the_repository);
+               pos = index_name_pos(repo->index, cp, namelen);
                if (pos < 0)
                        pos = -pos - 1;
-               while (pos < active_nr) {
-                       ce = active_cache[pos];
+               while (pos < repo->index->cache_nr) {
+                       ce = repo->index->cache[pos];
                        if (ce_namelen(ce) != namelen ||
                            memcmp(ce->name, cp, namelen))
                                break;
@@ -1742,7 +1751,7 @@ static int get_oid_with_context_1(const char *name,
                        pos++;
                }
                if (only_to_die && name[1] && name[1] != '/')
-                       diagnose_invalid_index_path(stage, prefix, cp);
+                       diagnose_invalid_index_path(repo->index, stage, prefix, cp);
                free(new_path);
                return -1;
        }
@@ -1807,12 +1816,15 @@ void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
 {
        struct object_context oc;
        struct object_id oid;
-       get_oid_with_context_1(name, GET_OID_ONLY_TO_DIE, prefix, &oid, &oc);
+       get_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,
+                              prefix, &oid, &oc);
 }
 
-int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc)
+int get_oid_with_context(struct repository *repo, const char *str,
+                        unsigned flags, struct object_id *oid,
+                        struct object_context *oc)
 {
        if (flags & GET_OID_FOLLOW_SYMLINKS && flags & GET_OID_ONLY_TO_DIE)
                BUG("incompatible flags for get_sha1_with_context");
-       return get_oid_with_context_1(str, flags, NULL, oid, oc);
+       return get_oid_with_context_1(repo, str, flags, NULL, oid, oc);
 }
diff --git a/sha256/block/sha256.c b/sha256/block/sha256.c
new file mode 100644 (file)
index 0000000..37850b4
--- /dev/null
@@ -0,0 +1,196 @@
+#include "git-compat-util.h"
+#include "./sha256.h"
+
+#undef RND
+#undef BLKSIZE
+
+#define BLKSIZE blk_SHA256_BLKSIZE
+
+void blk_SHA256_Init(blk_SHA256_CTX *ctx)
+{
+       ctx->offset = 0;
+       ctx->size = 0;
+       ctx->state[0] = 0x6a09e667ul;
+       ctx->state[1] = 0xbb67ae85ul;
+       ctx->state[2] = 0x3c6ef372ul;
+       ctx->state[3] = 0xa54ff53aul;
+       ctx->state[4] = 0x510e527ful;
+       ctx->state[5] = 0x9b05688cul;
+       ctx->state[6] = 0x1f83d9abul;
+       ctx->state[7] = 0x5be0cd19ul;
+}
+
+static inline uint32_t ror(uint32_t x, unsigned n)
+{
+       return (x >> n) | (x << (32 - n));
+}
+
+static inline uint32_t ch(uint32_t x, uint32_t y, uint32_t z)
+{
+       return z ^ (x & (y ^ z));
+}
+
+static inline uint32_t maj(uint32_t x, uint32_t y, uint32_t z)
+{
+       return ((x | y) & z) | (x & y);
+}
+
+static inline uint32_t sigma0(uint32_t x)
+{
+       return ror(x, 2) ^ ror(x, 13) ^ ror(x, 22);
+}
+
+static inline uint32_t sigma1(uint32_t x)
+{
+       return ror(x, 6) ^ ror(x, 11) ^ ror(x, 25);
+}
+
+static inline uint32_t gamma0(uint32_t x)
+{
+       return ror(x, 7) ^ ror(x, 18) ^ (x >> 3);
+}
+
+static inline uint32_t gamma1(uint32_t x)
+{
+       return ror(x, 17) ^ ror(x, 19) ^ (x >> 10);
+}
+
+static void blk_SHA256_Transform(blk_SHA256_CTX *ctx, const unsigned char *buf)
+{
+
+       uint32_t S[8], W[64], t0, t1;
+       int i;
+
+       /* copy state into S */
+       for (i = 0; i < 8; i++)
+               S[i] = ctx->state[i];
+
+       /* copy the state into 512-bits into W[0..15] */
+       for (i = 0; i < 16; i++, buf += sizeof(uint32_t))
+               W[i] = get_be32(buf);
+
+       /* fill W[16..63] */
+       for (i = 16; i < 64; i++)
+               W[i] = gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16];
+
+#define RND(a,b,c,d,e,f,g,h,i,ki)                    \
+       t0 = h + sigma1(e) + ch(e, f, g) + ki + W[i];   \
+       t1 = sigma0(a) + maj(a, b, c);                  \
+       d += t0;                                        \
+       h  = t0 + t1;
+
+       RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],0,0x428a2f98);
+       RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],1,0x71374491);
+       RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],2,0xb5c0fbcf);
+       RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],3,0xe9b5dba5);
+       RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],4,0x3956c25b);
+       RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],5,0x59f111f1);
+       RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],6,0x923f82a4);
+       RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],7,0xab1c5ed5);
+       RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],8,0xd807aa98);
+       RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],9,0x12835b01);
+       RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],10,0x243185be);
+       RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],11,0x550c7dc3);
+       RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],12,0x72be5d74);
+       RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],13,0x80deb1fe);
+       RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],14,0x9bdc06a7);
+       RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],15,0xc19bf174);
+       RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],16,0xe49b69c1);
+       RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],17,0xefbe4786);
+       RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],18,0x0fc19dc6);
+       RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],19,0x240ca1cc);
+       RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],20,0x2de92c6f);
+       RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],21,0x4a7484aa);
+       RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],22,0x5cb0a9dc);
+       RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],23,0x76f988da);
+       RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],24,0x983e5152);
+       RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],25,0xa831c66d);
+       RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],26,0xb00327c8);
+       RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],27,0xbf597fc7);
+       RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],28,0xc6e00bf3);
+       RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],29,0xd5a79147);
+       RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],30,0x06ca6351);
+       RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],31,0x14292967);
+       RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],32,0x27b70a85);
+       RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],33,0x2e1b2138);
+       RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],34,0x4d2c6dfc);
+       RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],35,0x53380d13);
+       RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],36,0x650a7354);
+       RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],37,0x766a0abb);
+       RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],38,0x81c2c92e);
+       RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],39,0x92722c85);
+       RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],40,0xa2bfe8a1);
+       RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],41,0xa81a664b);
+       RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],42,0xc24b8b70);
+       RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],43,0xc76c51a3);
+       RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],44,0xd192e819);
+       RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],45,0xd6990624);
+       RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],46,0xf40e3585);
+       RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],47,0x106aa070);
+       RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],48,0x19a4c116);
+       RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],49,0x1e376c08);
+       RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],50,0x2748774c);
+       RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],51,0x34b0bcb5);
+       RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],52,0x391c0cb3);
+       RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],53,0x4ed8aa4a);
+       RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],54,0x5b9cca4f);
+       RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],55,0x682e6ff3);
+       RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],56,0x748f82ee);
+       RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],57,0x78a5636f);
+       RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],58,0x84c87814);
+       RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],59,0x8cc70208);
+       RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],60,0x90befffa);
+       RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],61,0xa4506ceb);
+       RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],62,0xbef9a3f7);
+       RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],63,0xc67178f2);
+
+       for (i = 0; i < 8; i++)
+               ctx->state[i] += S[i];
+}
+
+void blk_SHA256_Update(blk_SHA256_CTX *ctx, const void *data, size_t len)
+{
+       unsigned int len_buf = ctx->size & 63;
+
+       ctx->size += len;
+
+       /* Read the data into buf and process blocks as they get full */
+       if (len_buf) {
+               unsigned int left = 64 - len_buf;
+               if (len < left)
+                       left = len;
+               memcpy(len_buf + ctx->buf, data, left);
+               len_buf = (len_buf + left) & 63;
+               len -= left;
+               data = ((const char *)data + left);
+               if (len_buf)
+                       return;
+               blk_SHA256_Transform(ctx, ctx->buf);
+       }
+       while (len >= 64) {
+               blk_SHA256_Transform(ctx, data);
+               data = ((const char *)data + 64);
+               len -= 64;
+       }
+       if (len)
+               memcpy(ctx->buf, data, len);
+}
+
+void blk_SHA256_Final(unsigned char *digest, blk_SHA256_CTX *ctx)
+{
+       static const unsigned char pad[64] = { 0x80 };
+       unsigned int padlen[2];
+       int i;
+
+       /* Pad with a binary 1 (ie 0x80), then zeroes, then length */
+       padlen[0] = htonl((uint32_t)(ctx->size >> 29));
+       padlen[1] = htonl((uint32_t)(ctx->size << 3));
+
+       i = ctx->size & 63;
+       blk_SHA256_Update(ctx, pad, 1 + (63 & (55 - i)));
+       blk_SHA256_Update(ctx, padlen, 8);
+
+       /* copy output */
+       for (i = 0; i < 8; i++, digest += sizeof(uint32_t))
+               put_be32(digest, ctx->state[i]);
+}
diff --git a/sha256/block/sha256.h b/sha256/block/sha256.h
new file mode 100644 (file)
index 0000000..5099d64
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef SHA256_BLOCK_SHA256_H
+#define SHA256_BLOCK_SHA256_H
+
+#define blk_SHA256_BLKSIZE 64
+
+struct blk_SHA256_CTX {
+       uint32_t state[8];
+       uint64_t size;
+       uint32_t offset;
+       uint8_t buf[blk_SHA256_BLKSIZE];
+};
+
+typedef struct blk_SHA256_CTX blk_SHA256_CTX;
+
+void blk_SHA256_Init(blk_SHA256_CTX *ctx);
+void blk_SHA256_Update(blk_SHA256_CTX *ctx, const void *data, size_t len);
+void blk_SHA256_Final(unsigned char *digest, blk_SHA256_CTX *ctx);
+
+#define platform_SHA256_CTX blk_SHA256_CTX
+#define platform_SHA256_Init blk_SHA256_Init
+#define platform_SHA256_Update blk_SHA256_Update
+#define platform_SHA256_Final blk_SHA256_Final
+
+#endif
diff --git a/sha256/gcrypt.h b/sha256/gcrypt.h
new file mode 100644 (file)
index 0000000..09bd8bb
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef SHA256_GCRYPT_H
+#define SHA256_GCRYPT_H
+
+#include <gcrypt.h>
+
+#define SHA256_DIGEST_SIZE 32
+
+typedef gcry_md_hd_t gcrypt_SHA256_CTX;
+
+inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)
+{
+       gcry_md_open(ctx, GCRY_MD_SHA256, 0);
+}
+
+inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)
+{
+       gcry_md_write(*ctx, data, len);
+}
+
+inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)
+{
+       memcpy(digest, gcry_md_read(*ctx, GCRY_MD_SHA256), SHA256_DIGEST_SIZE);
+}
+
+#define platform_SHA256_CTX gcrypt_SHA256_CTX
+#define platform_SHA256_Init gcrypt_SHA256_Init
+#define platform_SHA256_Update gcrypt_SHA256_Update
+#define platform_SHA256_Final gcrypt_SHA256_Final
+
+#endif
index 02fdbfc554c462c1eecdf1ddc6d17edbc1d8d853..ce45297940d417e3454b08d3f0c29f5cc6d93658 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -43,6 +43,13 @@ int register_shallow(struct repository *r, const struct object_id *oid)
 
 int is_repository_shallow(struct repository *r)
 {
+       /*
+        * NEEDSWORK: This function updates
+        * r->parsed_objects->{is_shallow,shallow_stat} as a side effect but
+        * there is no corresponding function to clear them when the shallow
+        * file is updated.
+        */
+
        FILE *fp;
        char buf[1024];
        const char *path = r->parsed_objects->alternate_shallow_file;
index 7c3d33d3f87965fc96720ad47674a81a804f43dd..ef851113c44ee91e594734bf68567110b7ac8c6b 100644 (file)
@@ -1,7 +1,6 @@
 #include "cache.h"
 #include "color.h"
 #include "config.h"
-#include "pkt-line.h"
 #include "sideband.h"
 #include "help.h"
 
@@ -110,109 +109,104 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
 }
 
 
-/*
- * Receive multiplexed output stream over git native protocol.
- * in_stream is the input stream from the remote, which carries data
- * in pkt_line format with band designator.  Demultiplex it into out
- * and err and return error appropriately.  Band #1 carries the
- * primary payload.  Things coming over band #2 is not necessarily
- * error; they are usually informative message on the standard error
- * stream, aka "verbose").  A message over band #3 is a signal that
- * the remote died unexpectedly.  A flush() concludes the stream.
- */
-
 #define DISPLAY_PREFIX "remote: "
 
 #define ANSI_SUFFIX "\033[K"
 #define DUMB_SUFFIX "        "
 
-int recv_sideband(const char *me, int in_stream, int out)
+int demultiplex_sideband(const char *me, char *buf, int len,
+                        int die_on_error,
+                        struct strbuf *scratch,
+                        enum sideband_type *sideband_type)
 {
-       const char *suffix;
-       char buf[LARGE_PACKET_MAX + 1];
-       struct strbuf outbuf = STRBUF_INIT;
-       int retval = 0;
-
-       if (isatty(2) && !is_terminal_dumb())
-               suffix = ANSI_SUFFIX;
-       else
-               suffix = DUMB_SUFFIX;
-
-       while (!retval) {
-               const char *b, *brk;
-               int band, len;
-               len = packet_read(in_stream, NULL, NULL, buf, LARGE_PACKET_MAX, 0);
-               if (len == 0)
-                       break;
-               if (len < 1) {
-                       strbuf_addf(&outbuf,
-                                   "%s%s: protocol error: no band designator",
-                                   outbuf.len ? "\n" : "", me);
-                       retval = SIDEBAND_PROTOCOL_ERROR;
-                       break;
-               }
-               band = buf[0] & 0xff;
-               buf[len] = '\0';
-               len--;
-               switch (band) {
-               case 3:
-                       strbuf_addf(&outbuf, "%s%s", outbuf.len ? "\n" : "",
-                                   DISPLAY_PREFIX);
-                       maybe_colorize_sideband(&outbuf, buf + 1, len);
-
-                       retval = SIDEBAND_REMOTE_ERROR;
-                       break;
-               case 2:
-                       b = buf + 1;
-
-                       /*
-                        * Append a suffix to each nonempty line to clear the
-                        * end of the screen line.
-                        *
-                        * The output is accumulated in a buffer and
-                        * each line is printed to stderr using
-                        * write(2) to ensure inter-process atomicity.
-                        */
-                       while ((brk = strpbrk(b, "\n\r"))) {
-                               int linelen = brk - b;
-
-                               if (!outbuf.len)
-                                       strbuf_addstr(&outbuf, DISPLAY_PREFIX);
-                               if (linelen > 0) {
-                                       maybe_colorize_sideband(&outbuf, b, linelen);
-                                       strbuf_addstr(&outbuf, suffix);
-                               }
-
-                               strbuf_addch(&outbuf, *brk);
-                               xwrite(2, outbuf.buf, outbuf.len);
-                               strbuf_reset(&outbuf);
-
-                               b = brk + 1;
-                       }
+       static const char *suffix;
+       const char *b, *brk;
+       int band;
+
+       if (!suffix) {
+               if (isatty(2) && !is_terminal_dumb())
+                       suffix = ANSI_SUFFIX;
+               else
+                       suffix = DUMB_SUFFIX;
+       }
 
-                       if (*b) {
-                               strbuf_addstr(&outbuf, outbuf.len ?
-                                           "" : DISPLAY_PREFIX);
-                               maybe_colorize_sideband(&outbuf, b, strlen(b));
+       if (len == 0) {
+               *sideband_type = SIDEBAND_FLUSH;
+               goto cleanup;
+       }
+       if (len < 1) {
+               strbuf_addf(scratch,
+                           "%s%s: protocol error: no band designator",
+                           scratch->len ? "\n" : "", me);
+               *sideband_type = SIDEBAND_PROTOCOL_ERROR;
+               goto cleanup;
+       }
+       band = buf[0] & 0xff;
+       buf[len] = '\0';
+       len--;
+       switch (band) {
+       case 3:
+               if (die_on_error)
+                       die("remote error: %s", buf + 1);
+               strbuf_addf(scratch, "%s%s", scratch->len ? "\n" : "",
+                           DISPLAY_PREFIX);
+               maybe_colorize_sideband(scratch, buf + 1, len);
+
+               *sideband_type = SIDEBAND_REMOTE_ERROR;
+               break;
+       case 2:
+               b = buf + 1;
+
+               /*
+                * Append a suffix to each nonempty line to clear the
+                * end of the screen line.
+                *
+                * The output is accumulated in a buffer and
+                * each line is printed to stderr using
+                * write(2) to ensure inter-process atomicity.
+                */
+               while ((brk = strpbrk(b, "\n\r"))) {
+                       int linelen = brk - b;
+
+                       if (!scratch->len)
+                               strbuf_addstr(scratch, DISPLAY_PREFIX);
+                       if (linelen > 0) {
+                               maybe_colorize_sideband(scratch, b, linelen);
+                               strbuf_addstr(scratch, suffix);
                        }
-                       break;
-               case 1:
-                       write_or_die(out, buf + 1, len);
-                       break;
-               default:
-                       strbuf_addf(&outbuf, "%s%s: protocol error: bad band #%d",
-                                   outbuf.len ? "\n" : "", me, band);
-                       retval = SIDEBAND_PROTOCOL_ERROR;
-                       break;
+
+                       strbuf_addch(scratch, *brk);
+                       xwrite(2, scratch->buf, scratch->len);
+                       strbuf_reset(scratch);
+
+                       b = brk + 1;
+               }
+
+               if (*b) {
+                       strbuf_addstr(scratch, scratch->len ?
+                                   "" : DISPLAY_PREFIX);
+                       maybe_colorize_sideband(scratch, b, strlen(b));
                }
+               return 0;
+       case 1:
+               *sideband_type = SIDEBAND_PRIMARY;
+               break;
+       default:
+               strbuf_addf(scratch, "%s%s: protocol error: bad band #%d",
+                           scratch->len ? "\n" : "", me, band);
+               *sideband_type = SIDEBAND_PROTOCOL_ERROR;
+               break;
        }
 
-       if (outbuf.len) {
-               strbuf_addch(&outbuf, '\n');
-               xwrite(2, outbuf.buf, outbuf.len);
+cleanup:
+       if (die_on_error && *sideband_type == SIDEBAND_PROTOCOL_ERROR)
+               die("%s", scratch->buf);
+       if (scratch->len) {
+               strbuf_addch(scratch, '\n');
+               xwrite(2, scratch->buf, scratch->len);
        }
-       strbuf_release(&outbuf);
-       return retval;
+       strbuf_release(scratch);
+       return 1;
 }
 
 /*
index 7a8146f161b7b460d29baea82230c0b6c11c5322..227740a58e58bd25c4625bc1963106542bd99779 100644 (file)
@@ -1,10 +1,29 @@
 #ifndef SIDEBAND_H
 #define SIDEBAND_H
 
-#define SIDEBAND_PROTOCOL_ERROR -2
-#define SIDEBAND_REMOTE_ERROR -1
+enum sideband_type {
+       SIDEBAND_PROTOCOL_ERROR = -2,
+       SIDEBAND_REMOTE_ERROR = -1,
+       SIDEBAND_FLUSH = 0,
+       SIDEBAND_PRIMARY = 1
+};
+
+/*
+ * Inspects a multiplexed packet read from the remote. If this packet is a
+ * progress packet and thus should not be processed by the caller, returns 0.
+ * Otherwise, returns 1, releases scratch, and sets sideband_type.
+ *
+ * If this packet is SIDEBAND_PROTOCOL_ERROR, SIDEBAND_REMOTE_ERROR, or a
+ * progress packet, also prints a message to stderr.
+ *
+ * scratch must be a struct strbuf allocated by the caller. It is used to store
+ * progress messages split across multiple packets.
+ */
+int demultiplex_sideband(const char *me, char *buf, int len,
+                        int die_on_error,
+                        struct strbuf *scratch,
+                        enum sideband_type *sideband_type);
 
-int recv_sideband(const char *me, int in_stream, int out);
 void send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max);
 
 #endif
index ac7c7a22f90b7320a235f23db9387fd91ba5b2cd..891f82f51a753d065ce67b111bce86e790801599 100644 (file)
@@ -499,7 +499,7 @@ static struct stream_vtbl incore_vtbl = {
 
 static open_method_decl(incore)
 {
-       st->u.incore.buf = read_object_file_extended(oid, type, &st->size, 0);
+       st->u.incore.buf = read_object_file_extended(the_repository, oid, type, &st->size, 0);
        st->u.incore.read_ptr = 0;
        st->vtbl = &incore_vtbl;
 
index d393e947e699bb1d5764f42e94919218496a138d..934ecfa2943bcb5ee87e7ac431b5332a5f3adcde 100644 (file)
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 
 #include "cache.h"
 #include "repository.h"
@@ -25,7 +24,6 @@
 #include "commit-reach.h"
 
 static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
-static struct string_list changed_submodule_names = STRING_LIST_INIT_DUP;
 static int initialized_fetch_ref_tips;
 static struct oid_array ref_tips_before_fetch;
 static struct oid_array ref_tips_after_fetch;
@@ -457,7 +455,7 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,
        return prepare_revision_walk(rev);
 }
 
-static void print_submodule_summary(struct rev_info *rev, struct diff_options *o)
+static void print_submodule_summary(struct repository *r, struct rev_info *rev, struct diff_options *o)
 {
        static const char format[] = "  %m %s";
        struct strbuf sb = STRBUF_INIT;
@@ -468,7 +466,8 @@ static void print_submodule_summary(struct rev_info *rev, struct diff_options *o
                ctx.date_mode = rev->date_mode;
                ctx.output_encoding = get_log_output_encoding();
                strbuf_setlen(&sb, 0);
-               format_commit_message(commit, format, &sb, &ctx);
+               repo_format_commit_message(r, commit, format, &sb,
+                                     &ctx);
                strbuf_addch(&sb, '\n');
                if (commit->object.flags & SYMMETRIC_LEFT)
                        diff_emit_submodule_del(o, sb.buf);
@@ -495,14 +494,52 @@ void prepare_submodule_repo_env(struct argv_array *out)
                         DEFAULT_GIT_DIR_ENVIRONMENT);
 }
 
-/* Helper function to display the submodule header line prior to the full
- * summary output. If it can locate the submodule objects directory it will
- * attempt to lookup both the left and right commits and put them into the
- * left and right pointers.
+static void prepare_submodule_repo_env_in_gitdir(struct argv_array *out)
+{
+       prepare_submodule_repo_env_no_git_dir(out);
+       argv_array_pushf(out, "%s=.", GIT_DIR_ENVIRONMENT);
+}
+
+/*
+ * Initialize a repository struct for a submodule based on the provided 'path'.
+ *
+ * Unlike repo_submodule_init, this tolerates submodules not present
+ * in .gitmodules. This function exists only to preserve historical behavior,
+ *
+ * Returns the repository struct on success,
+ * NULL when the submodule is not present.
  */
-static void show_submodule_header(struct diff_options *o, const char *path,
+static struct repository *open_submodule(const char *path)
+{
+       struct strbuf sb = STRBUF_INIT;
+       struct repository *out = xmalloc(sizeof(*out));
+
+       if (submodule_to_gitdir(&sb, path) || repo_init(out, sb.buf, NULL)) {
+               strbuf_release(&sb);
+               free(out);
+               return NULL;
+       }
+
+       /* Mark it as a submodule */
+       out->submodule_prefix = xstrdup(path);
+
+       strbuf_release(&sb);
+       return out;
+}
+
+/*
+ * Helper function to display the submodule header line prior to the full
+ * summary output.
+ *
+ * If it can locate the submodule git directory it will create a repository
+ * handle for the submodule and lookup both the left and right commits and
+ * put them into the left and right pointers.
+ */
+static void show_submodule_header(struct diff_options *o,
+               const char *path,
                struct object_id *one, struct object_id *two,
                unsigned dirty_submodule,
+               struct repository *sub,
                struct commit **left, struct commit **right,
                struct commit_list **merge_bases)
 {
@@ -521,7 +558,7 @@ static void show_submodule_header(struct diff_options *o, const char *path,
        else if (is_null_oid(two))
                message = "(submodule deleted)";
 
-       if (add_submodule_odb(path)) {
+       if (!sub) {
                if (!message)
                        message = "(commits not present)";
                goto output_header;
@@ -531,8 +568,8 @@ static void show_submodule_header(struct diff_options *o, const char *path,
         * Attempt to lookup the commit references, and determine if this is
         * a fast forward or fast backwards update.
         */
-       *left = lookup_commit_reference(the_repository, one);
-       *right = lookup_commit_reference(the_repository, two);
+       *left = lookup_commit_reference(sub, one);
+       *right = lookup_commit_reference(sub, two);
 
        /*
         * Warn about missing commits in the submodule project, but only if
@@ -542,7 +579,7 @@ static void show_submodule_header(struct diff_options *o, const char *path,
             (!is_null_oid(two) && !*right))
                message = "(commits not present)";
 
-       *merge_bases = get_merge_bases(*left, *right);
+       *merge_bases = repo_get_merge_bases(sub, *left, *right);
        if (*merge_bases) {
                if ((*merge_bases)->item == *left)
                        fast_forward = 1;
@@ -576,16 +613,18 @@ void show_submodule_summary(struct diff_options *o, const char *path,
        struct rev_info rev;
        struct commit *left = NULL, *right = NULL;
        struct commit_list *merge_bases = NULL;
+       struct repository *sub;
 
+       sub = open_submodule(path);
        show_submodule_header(o, path, one, two, dirty_submodule,
-                             &left, &right, &merge_bases);
+                             sub, &left, &right, &merge_bases);
 
        /*
         * If we don't have both a left and a right pointer, there is no
         * reason to try and display a summary. The header line should contain
         * all the information the user needs.
         */
-       if (!left || !right)
+       if (!left || !right || !sub)
                goto out;
 
        /* Treat revision walker failure the same as missing commits */
@@ -594,13 +633,17 @@ void show_submodule_summary(struct diff_options *o, const char *path,
                goto out;
        }
 
-       print_submodule_summary(&rev, o);
+       print_submodule_summary(sub, &rev, o);
 
 out:
        if (merge_bases)
                free_commit_list(merge_bases);
        clear_commit_marks(left, ~0);
        clear_commit_marks(right, ~0);
+       if (sub) {
+               repo_clear(sub);
+               free(sub);
+       }
 }
 
 void show_submodule_inline_diff(struct diff_options *o, const char *path,
@@ -612,9 +655,11 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
        struct commit_list *merge_bases = NULL;
        struct child_process cp = CHILD_PROCESS_INIT;
        struct strbuf sb = STRBUF_INIT;
+       struct repository *sub;
 
+       sub = open_submodule(path);
        show_submodule_header(o, path, one, two, dirty_submodule,
-                             &left, &right, &merge_bases);
+                             sub, &left, &right, &merge_bases);
 
        /* We need a valid left and right commit to display a difference */
        if (!(left || is_null_oid(one)) ||
@@ -675,6 +720,10 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
                clear_commit_marks(left, ~0);
        if (right)
                clear_commit_marks(right, ~0);
+       if (sub) {
+               repo_clear(sub);
+               free(sub);
+       }
 }
 
 int should_update_submodules(void)
@@ -999,9 +1048,6 @@ static int push_submodule(const char *path,
                          const struct string_list *push_options,
                          int dry_run)
 {
-       if (add_submodule_odb(path))
-               return 1;
-
        if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {
                struct child_process cp = CHILD_PROCESS_INIT;
                argv_array_push(&cp.args, "push");
@@ -1136,11 +1182,11 @@ void check_for_new_submodule_commits(struct object_id *oid)
        oid_array_append(&ref_tips_after_fetch, oid);
 }
 
-static void calculate_changed_submodule_paths(struct repository *r)
+static void calculate_changed_submodule_paths(struct repository *r,
+               struct string_list *changed_submodule_names)
 {
        struct argv_array argv = ARGV_ARRAY_INIT;
-       struct string_list changed_submodules = STRING_LIST_INIT_DUP;
-       const struct string_list_item *name;
+       struct string_list_item *name;
 
        /* No need to check if there are no submodules configured */
        if (!submodule_from_path(r, NULL, NULL))
@@ -1157,9 +1203,9 @@ static void calculate_changed_submodule_paths(struct repository *r)
         * Collect all submodules (whether checked out or not) for which new
         * commits have been recorded upstream in "changed_submodule_names".
         */
-       collect_changed_submodules(r, &changed_submodules, &argv);
+       collect_changed_submodules(r, changed_submodule_names, &argv);
 
-       for_each_string_list_item(name, &changed_submodules) {
+       for_each_string_list_item(name, changed_submodule_names) {
                struct oid_array *commits = name->util;
                const struct submodule *submodule;
                const char *path = NULL;
@@ -1173,11 +1219,14 @@ static void calculate_changed_submodule_paths(struct repository *r)
                if (!path)
                        continue;
 
-               if (!submodule_has_commits(r, path, commits))
-                       string_list_append(&changed_submodule_names, name->string);
+               if (submodule_has_commits(r, path, commits)) {
+                       oid_array_clear(commits);
+                       *name->string = '\0';
+               }
        }
 
-       free_submodules_oids(&changed_submodules);
+       string_list_remove_empty_items(changed_submodule_names, 1);
+
        argv_array_clear(&argv);
        oid_array_clear(&ref_tips_before_fetch);
        oid_array_clear(&ref_tips_after_fetch);
@@ -1221,8 +1270,16 @@ struct submodule_parallel_fetch {
        int default_option;
        int quiet;
        int result;
+
+       struct string_list changed_submodule_names;
+
+       /* Pending fetches by OIDs */
+       struct fetch_task **oid_fetch_tasks;
+       int oid_fetch_tasks_nr, oid_fetch_tasks_alloc;
 };
-#define SPF_INIT {0, ARGV_ARRAY_INIT, NULL, NULL, 0, 0, 0, 0}
+#define SPF_INIT {0, ARGV_ARRAY_INIT, NULL, NULL, 0, 0, 0, 0, \
+                 STRING_LIST_INIT_DUP, \
+                 NULL, 0, 0}
 
 static int get_fetch_recurse_config(const struct submodule *submodule,
                                    struct submodule_parallel_fetch *spf)
@@ -1249,40 +1306,126 @@ static int get_fetch_recurse_config(const struct submodule *submodule,
        return spf->default_option;
 }
 
+/*
+ * Fetch in progress (if callback data) or
+ * pending (if in oid_fetch_tasks in struct submodule_parallel_fetch)
+ */
+struct fetch_task {
+       struct repository *repo;
+       const struct submodule *sub;
+       unsigned free_sub : 1; /* Do we need to free the submodule? */
+
+       struct oid_array *commits; /* Ensure these commits are fetched */
+};
+
+/**
+ * When a submodule is not defined in .gitmodules, we cannot access it
+ * via the regular submodule-config. Create a fake submodule, which we can
+ * work on.
+ */
+static const struct submodule *get_non_gitmodules_submodule(const char *path)
+{
+       struct submodule *ret = NULL;
+       const char *name = default_name_or_path(path);
+
+       if (!name)
+               return NULL;
+
+       ret = xmalloc(sizeof(*ret));
+       memset(ret, 0, sizeof(*ret));
+       ret->path = name;
+       ret->name = name;
+
+       return (const struct submodule *) ret;
+}
+
+static struct fetch_task *fetch_task_create(struct repository *r,
+                                           const char *path)
+{
+       struct fetch_task *task = xmalloc(sizeof(*task));
+       memset(task, 0, sizeof(*task));
+
+       task->sub = submodule_from_path(r, &null_oid, path);
+       if (!task->sub) {
+               /*
+                * No entry in .gitmodules? Technically not a submodule,
+                * but historically we supported repositories that happen to be
+                * in-place where a gitlink is. Keep supporting them.
+                */
+               task->sub = get_non_gitmodules_submodule(path);
+               if (!task->sub) {
+                       free(task);
+                       return NULL;
+               }
+
+               task->free_sub = 1;
+       }
+
+       return task;
+}
+
+static void fetch_task_release(struct fetch_task *p)
+{
+       if (p->free_sub)
+               free((void*)p->sub);
+       p->free_sub = 0;
+       p->sub = NULL;
+
+       if (p->repo)
+               repo_clear(p->repo);
+       FREE_AND_NULL(p->repo);
+}
+
+static struct repository *get_submodule_repo_for(struct repository *r,
+                                                const struct submodule *sub)
+{
+       struct repository *ret = xmalloc(sizeof(*ret));
+
+       if (repo_submodule_init(ret, r, sub)) {
+               /*
+                * No entry in .gitmodules? Technically not a submodule,
+                * but historically we supported repositories that happen to be
+                * in-place where a gitlink is. Keep supporting them.
+                */
+               struct strbuf gitdir = STRBUF_INIT;
+               strbuf_repo_worktree_path(&gitdir, r, "%s/.git", sub->path);
+               if (repo_init(ret, gitdir.buf, NULL)) {
+                       strbuf_release(&gitdir);
+                       free(ret);
+                       return NULL;
+               }
+               strbuf_release(&gitdir);
+       }
+
+       return ret;
+}
+
 static int get_next_submodule(struct child_process *cp,
                              struct strbuf *err, void *data, void **task_cb)
 {
-       int ret = 0;
        struct submodule_parallel_fetch *spf = data;
 
        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 = spf->r->index->cache[spf->count];
-               const char *git_dir, *default_argv;
-               const struct submodule *submodule;
-               struct submodule default_submodule = SUBMODULE_INIT;
+               const char *default_argv;
+               struct fetch_task *task;
 
                if (!S_ISGITLINK(ce->ce_mode))
                        continue;
 
-               submodule = submodule_from_path(spf->r, &null_oid, ce->name);
-               if (!submodule) {
-                       const char *name = default_name_or_path(ce->name);
-                       if (name) {
-                               default_submodule.path = default_submodule.name = name;
-                               submodule = &default_submodule;
-                       }
-               }
+               task = fetch_task_create(spf->r, ce->name);
+               if (!task)
+                       continue;
 
-               switch (get_fetch_recurse_config(submodule, spf))
+               switch (get_fetch_recurse_config(task->sub, spf))
                {
                default:
                case RECURSE_SUBMODULES_DEFAULT:
                case RECURSE_SUBMODULES_ON_DEMAND:
-                       if (!submodule || !unsorted_string_list_lookup(&changed_submodule_names,
-                                                        submodule->name))
+                       if (!task->sub ||
+                           !string_list_lookup(
+                                       &spf->changed_submodule_names,
+                                       task->sub->name))
                                continue;
                        default_argv = "on-demand";
                        break;
@@ -1293,16 +1436,12 @@ static int get_next_submodule(struct child_process *cp,
                        continue;
                }
 
-               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);
-               if (!git_dir)
-                       git_dir = submodule_git_dir.buf;
-               if (is_directory(git_dir)) {
+               task->repo = get_submodule_repo_for(spf->r, task->sub);
+               if (task->repo) {
+                       struct strbuf submodule_prefix = STRBUF_INIT;
                        child_process_init(cp);
-                       cp->dir = strbuf_detach(&submodule_path, NULL);
-                       prepare_submodule_repo_env(&cp->env_array);
+                       cp->dir = task->repo->gitdir;
+                       prepare_submodule_repo_env_in_gitdir(&cp->env_array);
                        cp->git_cmd = 1;
                        if (!spf->quiet)
                                strbuf_addf(err, "Fetching submodule %s%s\n",
@@ -1311,17 +1450,66 @@ static int get_next_submodule(struct child_process *cp,
                        argv_array_pushv(&cp->args, spf->args.argv);
                        argv_array_push(&cp->args, default_argv);
                        argv_array_push(&cp->args, "--submodule-prefix");
+
+                       strbuf_addf(&submodule_prefix, "%s%s/",
+                                                      spf->prefix,
+                                                      task->sub->path);
                        argv_array_push(&cp->args, submodule_prefix.buf);
-                       ret = 1;
-               }
-               strbuf_release(&submodule_path);
-               strbuf_release(&submodule_git_dir);
-               strbuf_release(&submodule_prefix);
-               if (ret) {
+
                        spf->count++;
+                       *task_cb = task;
+
+                       strbuf_release(&submodule_prefix);
                        return 1;
+               } else {
+
+                       fetch_task_release(task);
+                       free(task);
+
+                       /*
+                        * An empty directory is normal,
+                        * the submodule is not initialized
+                        */
+                       if (S_ISGITLINK(ce->ce_mode) &&
+                           !is_empty_dir(ce->name)) {
+                               spf->result = 1;
+                               strbuf_addf(err,
+                                           _("Could not access submodule '%s'"),
+                                           ce->name);
+                       }
                }
        }
+
+       if (spf->oid_fetch_tasks_nr) {
+               struct fetch_task *task =
+                       spf->oid_fetch_tasks[spf->oid_fetch_tasks_nr - 1];
+               struct strbuf submodule_prefix = STRBUF_INIT;
+               spf->oid_fetch_tasks_nr--;
+
+               strbuf_addf(&submodule_prefix, "%s%s/",
+                           spf->prefix, task->sub->path);
+
+               child_process_init(cp);
+               prepare_submodule_repo_env_in_gitdir(&cp->env_array);
+               cp->git_cmd = 1;
+               cp->dir = task->repo->gitdir;
+
+               argv_array_init(&cp->args);
+               argv_array_pushv(&cp->args, spf->args.argv);
+               argv_array_push(&cp->args, "on-demand");
+               argv_array_push(&cp->args, "--submodule-prefix");
+               argv_array_push(&cp->args, submodule_prefix.buf);
+
+               /* NEEDSWORK: have get_default_remote from submodule--helper */
+               argv_array_push(&cp->args, "origin");
+               oid_array_for_each_unique(task->commits,
+                                         append_oid_to_argv, &cp->args);
+
+               *task_cb = task;
+               strbuf_release(&submodule_prefix);
+               return 1;
+       }
+
        return 0;
 }
 
@@ -1329,20 +1517,66 @@ static int fetch_start_failure(struct strbuf *err,
                               void *cb, void *task_cb)
 {
        struct submodule_parallel_fetch *spf = cb;
+       struct fetch_task *task = task_cb;
 
        spf->result = 1;
 
+       fetch_task_release(task);
        return 0;
 }
 
+static int commit_missing_in_sub(const struct object_id *oid, void *data)
+{
+       struct repository *subrepo = data;
+
+       enum object_type type = oid_object_info(subrepo, oid, NULL);
+
+       return type != OBJ_COMMIT;
+}
+
 static int fetch_finish(int retvalue, struct strbuf *err,
                        void *cb, void *task_cb)
 {
        struct submodule_parallel_fetch *spf = cb;
+       struct fetch_task *task = task_cb;
+
+       struct string_list_item *it;
+       struct oid_array *commits;
 
        if (retvalue)
                spf->result = 1;
 
+       if (!task || !task->sub)
+               BUG("callback cookie bogus");
+
+       /* Is this the second time we process this submodule? */
+       if (task->commits)
+               goto out;
+
+       it = string_list_lookup(&spf->changed_submodule_names, task->sub->name);
+       if (!it)
+               /* Could be an unchanged submodule, not contained in the list */
+               goto out;
+
+       commits = it->util;
+       oid_array_filter(commits,
+                        commit_missing_in_sub,
+                        task->repo);
+
+       /* Are there commits we want, but do not exist? */
+       if (commits->nr) {
+               task->commits = commits;
+               ALLOC_GROW(spf->oid_fetch_tasks,
+                          spf->oid_fetch_tasks_nr + 1,
+                          spf->oid_fetch_tasks_alloc);
+               spf->oid_fetch_tasks[spf->oid_fetch_tasks_nr] = task;
+               spf->oid_fetch_tasks_nr++;
+               return 0;
+       }
+
+out:
+       fetch_task_release(task);
+
        return 0;
 }
 
@@ -1373,7 +1607,8 @@ int fetch_populated_submodules(struct repository *r,
        argv_array_push(&spf.args, "--recurse-submodules-default");
        /* default value, "--submodule-prefix" and its value are added later */
 
-       calculate_changed_submodule_paths(r);
+       calculate_changed_submodule_paths(r, &spf.changed_submodule_names);
+       string_list_sort(&spf.changed_submodule_names);
        run_processes_parallel(max_parallel_jobs,
                               get_next_submodule,
                               fetch_start_failure,
@@ -1382,7 +1617,7 @@ int fetch_populated_submodules(struct repository *r,
 
        argv_array_clear(&spf.args);
 out:
-       string_list_clear(&changed_submodule_names, 1);
+       free_submodules_oids(&spf.changed_submodule_names);
        return spf.result;
 }
 
index 11ce7675e32e7042f0ae5ddee1b65a0f6516f175..6140b8c45bc7890c9166d44b852782364fa675ca 100644 (file)
--- a/t/README
+++ b/t/README
@@ -358,6 +358,10 @@ GIT_TEST_INDEX_VERSION=<n> exercises the index read/write code path
 for the index version specified.  Can be set to any valid version
 (currently 2, 3, or 4).
 
+GIT_TEST_PACK_SPARSE=<boolean> if enabled will default the pack-objects
+builtin to use the sparse object walk. This can still be overridden by
+the --no-sparse command-line argument.
+
 GIT_TEST_PRELOAD_INDEX=<boolean> exercises the preload-index code path
 by overriding the minimum number of cache entries required per thread.
 
@@ -374,6 +378,11 @@ GIT_TEST_MULTI_PACK_INDEX=<boolean>, when true, forces the multi-pack-
 index to be written after every 'git repack' command, and overrides the
 'core.multiPackIndex' setting to true.
 
+GIT_TEST_SIDEBAND_ALL=<boolean>, when true, overrides the
+'uploadpack.allowSidebandAll' setting to true, and when false, forces
+fetch-pack to not request sideband-all (even if the server advertises
+sideband-all).
+
 Naming Tests
 ------------
 
index 8037eef7777b4f65af44b3c8cc3e4b46d48259ae..166d64d4a2f05e76f3966080f188b864bf6bf4bb 100755 (executable)
@@ -36,7 +36,7 @@ sub err {
        }
 
        /\bcp\s+-a/ and err 'cp -a is not portable';
-       /\bsed\s+-i/ and err 'sed -i is not portable';
+       /\bsed\s+-[^efn]\s+/ and err 'sed option not portable (use only -n, -e, -f)';
        /\becho\s+-[neE]/ and err 'echo with option is not portable (use printf)';
        /^\s*declare\s+/ and err 'arrays/declare not portable';
        /^\s*[^#]\s*which\s/ and err 'which is not portable (use type)';
index a0837371aba17956331ddcdb04847c6c9edeefd2..a47bfa3003ba72d9ccac56981bf2ed89302af802 100644 (file)
@@ -3,6 +3,7 @@
 
 static const char *usage_msg = "\n"
 "  test-tool date relative [time_t]...\n"
+"  test-tool date human [time_t]...\n"
 "  test-tool date show:<format> [time_t]...\n"
 "  test-tool date parse [date]...\n"
 "  test-tool date approxidate [date]...\n"
@@ -16,12 +17,20 @@ static void show_relative_dates(const char **argv, struct timeval *now)
 
        for (; *argv; argv++) {
                time_t t = atoi(*argv);
-               show_date_relative(t, 0, now, &buf);
+               show_date_relative(t, now, &buf);
                printf("%s -> %s\n", *argv, buf.buf);
        }
        strbuf_release(&buf);
 }
 
+static void show_human_dates(const char **argv)
+{
+       for (; *argv; argv++) {
+               time_t t = atoi(*argv);
+               printf("%s -> %s\n", *argv, show_date(t, 0, DATE_MODE(HUMAN)));
+       }
+}
+
 static void show_dates(const char **argv, const char *format)
 {
        struct date_mode mode;
@@ -87,7 +96,7 @@ int cmd__date(int argc, const char **argv)
        struct timeval now;
        const char *x;
 
-       x = getenv("TEST_DATE_NOW");
+       x = getenv("GIT_TEST_DATE_NOW");
        if (x) {
                now.tv_sec = atoi(x);
                now.tv_usec = 0;
@@ -100,6 +109,8 @@ int cmd__date(int argc, const char **argv)
                usage(usage_msg);
        if (!strcmp(*argv, "relative"))
                show_relative_dates(argv+1, &now);
+       else if (!strcmp(*argv, "human"))
+               show_human_dates(argv+1);
        else if (skip_prefix(*argv, "show:", &x))
                show_dates(argv+1, x);
        else if (!strcmp(*argv, "parse"))
index 08e3684aff223670fb0786d80426d18bb8800a44..2786f47088e975608c839f193527e1e70e84cee9 100644 (file)
@@ -3,11 +3,11 @@
 
 int cmd__dump_fsmonitor(int ac, const char **av)
 {
-       struct index_state *istate = &the_index;
+       struct index_state *istate = the_repository->index;
        int i;
 
        setup_git_directory();
-       if (do_read_index(istate, get_index_file(), 0) < 0)
+       if (do_read_index(istate, the_repository->index_file, 0) < 0)
                die("unable to read index file");
        if (!istate->fsmonitor_last_update) {
                printf("no fsmonitor\n");
index 52870ebbb3ea7b2d69aecb1bb429dbbaf6388b51..cf0f2c7228e8293c5982168f21b004bc7daa2ff0 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "test-tool.h"
 #include "cache.h"
 #include "dir.h"
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
new file mode 100644 (file)
index 0000000..432233c
--- /dev/null
@@ -0,0 +1,61 @@
+#include "test-tool.h"
+#include "cache.h"
+
+#define NUM_SECONDS 3
+
+static inline void compute_hash(const struct git_hash_algo *algo, git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len)
+{
+       algo->init_fn(ctx);
+       algo->update_fn(ctx, p, len);
+       algo->final_fn(final, ctx);
+}
+
+int cmd__hash_speed(int ac, const char **av)
+{
+       git_hash_ctx ctx;
+       unsigned char hash[GIT_MAX_RAWSZ];
+       clock_t initial, start, end;
+       unsigned bufsizes[] = { 64, 256, 1024, 8192, 16384 };
+       int i;
+       void *p;
+       const struct git_hash_algo *algo = NULL;
+
+       if (ac == 2) {
+               for (i = 1; i < GIT_HASH_NALGOS; i++) {
+                       if (!strcmp(av[1], hash_algos[i].name)) {
+                               algo = &hash_algos[i];
+                               break;
+                       }
+               }
+       }
+       if (!algo)
+               die("usage: test-tool hash-speed algo_name");
+
+       /* Use this as an offset to make overflow less likely. */
+       initial = clock();
+
+       printf("algo: %s\n", algo->name);
+
+       for (i = 0; i < ARRAY_SIZE(bufsizes); i++) {
+               unsigned long j, kb;
+               double kb_per_sec;
+               p = xcalloc(1, bufsizes[i]);
+               start = end = clock() - initial;
+               for (j = 0; ((end - start) / CLOCKS_PER_SEC) < NUM_SECONDS; j++) {
+                       compute_hash(algo, &ctx, hash, p, bufsizes[i]);
+
+                       /*
+                        * Only check elapsed time every 128 iterations to avoid
+                        * dominating the runtime with system calls.
+                        */
+                       if (!(j & 127))
+                               end = clock() - initial;
+               }
+               kb = j * bufsizes[i];
+               kb_per_sec = kb / (1024 * ((double)end - start) / CLOCKS_PER_SEC);
+               printf("size %u: %lu iters; %lu KiB; %0.2f KiB/s\n", bufsizes[i], j, kb, kb_per_sec);
+               free(p);
+       }
+
+       exit(0);
+}
diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c
new file mode 100644 (file)
index 0000000..0a31de6
--- /dev/null
@@ -0,0 +1,58 @@
+#include "test-tool.h"
+#include "cache.h"
+
+int cmd_hash_impl(int ac, const char **av, int algo)
+{
+       git_hash_ctx ctx;
+       unsigned char hash[GIT_MAX_HEXSZ];
+       unsigned bufsz = 8192;
+       int binary = 0;
+       char *buffer;
+       const struct git_hash_algo *algop = &hash_algos[algo];
+
+       if (ac == 2) {
+               if (!strcmp(av[1], "-b"))
+                       binary = 1;
+               else
+                       bufsz = strtoul(av[1], NULL, 10) * 1024 * 1024;
+       }
+
+       if (!bufsz)
+               bufsz = 8192;
+
+       while ((buffer = malloc(bufsz)) == NULL) {
+               fprintf(stderr, "bufsz %u is too big, halving...\n", bufsz);
+               bufsz /= 2;
+               if (bufsz < 1024)
+                       die("OOPS");
+       }
+
+       algop->init_fn(&ctx);
+
+       while (1) {
+               ssize_t sz, this_sz;
+               char *cp = buffer;
+               unsigned room = bufsz;
+               this_sz = 0;
+               while (room) {
+                       sz = xread(0, cp, room);
+                       if (sz == 0)
+                               break;
+                       if (sz < 0)
+                               die_errno("test-hash");
+                       this_sz += sz;
+                       cp += sz;
+                       room -= sz;
+               }
+               if (this_sz == 0)
+                       break;
+               algop->update_fn(&ctx, buffer, this_sz);
+       }
+       algop->final_fn(hash, &ctx);
+
+       if (binary)
+               fwrite(hash, 1, algop->rawsz, stdout);
+       else
+               puts(hash_to_hex_algop(hash, algop));
+       exit(0);
+}
index e9e0541276c50d1739b6d39f2c01ba8ecb782adc..799fc00aa15b1e4cfe9fe8a6d32ebc2063003cb4 100644 (file)
@@ -233,7 +233,7 @@ static int cmd_update_ref(struct ref_store *refs, const char **argv)
 {
        const char *msg = notnull(*argv++, "msg");
        const char *refname = notnull(*argv++, "refname");
-       const char *new_sha1_buf = notnull(*argv++, "old-sha1");
+       const char *new_sha1_buf = notnull(*argv++, "new-sha1");
        const char *old_sha1_buf = notnull(*argv++, "old-sha1");
        unsigned int flags = arg_flags(*argv++, "flags");
        struct object_id old_oid;
index 6a84a53efbf6919c83d3f1fd73786acd92ee7abf..f7f861844560e0578eda989e39c4bd0572dcd5d6 100644 (file)
@@ -17,6 +17,11 @@ static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
 
        setup_git_env(gitdir);
 
+       memset(the_repository, 0, sizeof(*the_repository));
+
+       /* TODO: Needed for temporary hack in hashcmp, see 183a638b7da. */
+       repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+
        if (repo_init(&r, gitdir, worktree))
                die("Couldn't init repo");
 
@@ -43,6 +48,11 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
 
        setup_git_env(gitdir);
 
+       memset(the_repository, 0, sizeof(*the_repository));
+
+       /* TODO: Needed for temporary hack in hashcmp, see 183a638b7da. */
+       repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+
        if (repo_init(&r, gitdir, worktree))
                die("Couldn't init repo");
 
index 1ba0675c75f0d2dab281d054b577272cd45c39f9..d860c387c3846d69b7bd63a144ede2f93da60886 100644 (file)
@@ -3,55 +3,5 @@
 
 int cmd__sha1(int ac, const char **av)
 {
-       git_SHA_CTX ctx;
-       unsigned char sha1[20];
-       unsigned bufsz = 8192;
-       int binary = 0;
-       char *buffer;
-
-       if (ac == 2) {
-               if (!strcmp(av[1], "-b"))
-                       binary = 1;
-               else
-                       bufsz = strtoul(av[1], NULL, 10) * 1024 * 1024;
-       }
-
-       if (!bufsz)
-               bufsz = 8192;
-
-       while ((buffer = malloc(bufsz)) == NULL) {
-               fprintf(stderr, "bufsz %u is too big, halving...\n", bufsz);
-               bufsz /= 2;
-               if (bufsz < 1024)
-                       die("OOPS");
-       }
-
-       git_SHA1_Init(&ctx);
-
-       while (1) {
-               ssize_t sz, this_sz;
-               char *cp = buffer;
-               unsigned room = bufsz;
-               this_sz = 0;
-               while (room) {
-                       sz = xread(0, cp, room);
-                       if (sz == 0)
-                               break;
-                       if (sz < 0)
-                               die_errno("test-sha1");
-                       this_sz += sz;
-                       cp += sz;
-                       room -= sz;
-               }
-               if (this_sz == 0)
-                       break;
-               git_SHA1_Update(&ctx, buffer, this_sz);
-       }
-       git_SHA1_Final(sha1, &ctx);
-
-       if (binary)
-               fwrite(sha1, 1, 20, stdout);
-       else
-               puts(sha1_to_hex(sha1));
-       exit(0);
+       return cmd_hash_impl(ac, av, GIT_HASH_SHA1);
 }
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
new file mode 100644 (file)
index 0000000..0ac6a99
--- /dev/null
@@ -0,0 +1,7 @@
+#include "test-tool.h"
+#include "cache.h"
+
+int cmd__sha256(int ac, const char **av)
+{
+       return cmd_hash_impl(ac, av, GIT_HASH_SHA256);
+}
index a31e2a9bea60a8699cbe4b335a84113cc531f7ed..bc97929bbc3a9f03c069ea556575de4ef4397d23 100644 (file)
@@ -10,19 +10,21 @@ static void die_usage(int argc, const char **argv, const char *msg)
 
 int cmd__submodule_nested_repo_config(int argc, const char **argv)
 {
-       struct repository submodule;
+       struct repository subrepo;
+       const struct submodule *sub;
 
        if (argc < 3)
                die_usage(argc, argv, "Wrong number of arguments.");
 
        setup_git_directory();
 
-       if (repo_submodule_init(&submodule, the_repository, argv[1])) {
+       sub = submodule_from_path(the_repository, &null_oid, argv[1]);
+       if (repo_submodule_init(&subrepo, the_repository, sub)) {
                die_usage(argc, argv, "Submodule not found.");
        }
 
        /* Read the config of _child_ submodules. */
-       print_config_from_gitmodules(&submodule, argv[2]);
+       print_config_from_gitmodules(&subrepo, argv[2]);
 
        submodule_free(the_repository);
 
index bfb195b1a828a34988912e66f9e07f493588d5b4..5b137874e1d21166c92d00f540f6ecd68c18780a 100644 (file)
@@ -20,6 +20,7 @@ static struct test_cmd cmds[] = {
        { "example-decorate", cmd__example_decorate },
        { "genrandom", cmd__genrandom },
        { "hashmap", cmd__hashmap },
+       { "hash-speed", cmd__hash_speed },
        { "index-version", cmd__index_version },
        { "json-writer", cmd__json_writer },
        { "lazy-init-name-hash", cmd__lazy_init_name_hash },
@@ -42,6 +43,7 @@ static struct test_cmd cmds[] = {
        { "scrap-cache-tree", cmd__scrap_cache_tree },
        { "sha1", cmd__sha1 },
        { "sha1-array", cmd__sha1_array },
+       { "sha256", cmd__sha256 },
        { "sigchain", cmd__sigchain },
        { "strcmp-offset", cmd__strcmp_offset },
        { "string-list", cmd__string_list },
index 042f12464b2a17afeb37e01d90bf49ba33ce879a..a396c10947e86bb88e47a8e4df4fef2de64024e8 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef TEST_TOOL_H
 #define TEST_TOOL_H
 
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "git-compat-util.h"
 
 int cmd__chmtime(int argc, const char **argv);
@@ -16,6 +17,7 @@ int cmd__dump_untracked_cache(int argc, const char **argv);
 int cmd__example_decorate(int argc, const char **argv);
 int cmd__genrandom(int argc, const char **argv);
 int cmd__hashmap(int argc, const char **argv);
+int cmd__hash_speed(int argc, const char **argv);
 int cmd__index_version(int argc, const char **argv);
 int cmd__json_writer(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
@@ -38,6 +40,7 @@ int cmd__run_command(int argc, const char **argv);
 int cmd__scrap_cache_tree(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 int cmd__sha1_array(int argc, const char **argv);
+int cmd__sha256(int argc, const char **argv);
 int cmd__sigchain(int argc, const char **argv);
 int cmd__strcmp_offset(int argc, const char **argv);
 int cmd__string_list(int argc, const char **argv);
@@ -51,4 +54,6 @@ int cmd__windows_named_pipe(int argc, const char **argv);
 #endif
 int cmd__write_cache(int argc, const char **argv);
 
+int cmd_hash_impl(int ac, const char **av, int algo);
+
 #endif
index 581c010d8fc4c1184ba17b63b940aaac30d0b0f4..5d63ed90c51cf215dd24bf634f47413c2fa27368 100644 (file)
@@ -78,6 +78,7 @@ PassEnv GNUPGHOME
 PassEnv ASAN_OPTIONS
 PassEnv GIT_TRACE
 PassEnv GIT_CONFIG_NOSYSTEM
+PassEnv GIT_TEST_SIDEBAND_ALL
 
 SetEnvIf Git-Protocol ".*" GIT_PROTOCOL=$0
 
@@ -115,6 +116,7 @@ Alias /auth/dumb/ www/auth/dumb/
        SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
        SetEnv GIT_HTTP_EXPORT_ALL
 </LocationMatch>
+ScriptAliasMatch /error_git_upload_pack/(.*)/git-upload-pack error.sh/
 ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1
 ScriptAlias /broken_smart/ broken-smart-http.sh/
 ScriptAlias /error/ error.sh/
index 22499bce5f50637e574961f744b567b974a4d3d0..71e63d8b509d34fa4b860bac9ba1531e674799d7 100755 (executable)
@@ -322,4 +322,24 @@ test_expect_success 'bare repository: test info/attributes' '
        )
 '
 
+test_expect_success 'binary macro expanded by -a' '
+       echo "file binary" >.gitattributes &&
+       cat >expect <<-\EOF &&
+       file: binary: set
+       file: diff: unset
+       file: merge: unset
+       file: text: unset
+       EOF
+       git check-attr -a file >actual &&
+       test_cmp expect actual
+'
+
+
+test_expect_success 'query binary macro directly' '
+       echo "file binary" >.gitattributes &&
+       echo file: binary: set >expect &&
+       git check-attr binary file >actual &&
+       test_cmp expect actual
+'
+
 test_done
index ffb2975e4875287bd510503a3becfd90fd7d325b..d9fcc829a9e6cb10088e6503841928cf85d1d697 100755 (executable)
@@ -4,10 +4,10 @@ test_description='test date parsing and printing'
 . ./test-lib.sh
 
 # arbitrary reference time: 2009-08-30 19:20:00
-TEST_DATE_NOW=1251660000; export TEST_DATE_NOW
+GIT_TEST_DATE_NOW=1251660000; export GIT_TEST_DATE_NOW
 
 check_relative() {
-       t=$(($TEST_DATE_NOW - $1))
+       t=$(($GIT_TEST_DATE_NOW - $1))
        echo "$t -> $2" >expect
        test_expect_${3:-success} "relative date ($2)" "
        test-tool date relative $t >actual &&
@@ -128,4 +128,22 @@ check_approxidate '6AM, June 7, 2009' '2009-06-07 06:00:00'
 check_approxidate '2008-12-01' '2008-12-01 19:20:00'
 check_approxidate '2009-12-01' '2009-12-01 19:20:00'
 
+check_date_format_human() {
+       t=$(($GIT_TEST_DATE_NOW - $1))
+       echo "$t -> $2" >expect
+       test_expect_success "human date $t" '
+               test-tool date human $t >actual &&
+               test_i18ncmp expect actual
+'
+}
+
+check_date_format_human 18000 "5 hours ago" # 5 hours ago
+check_date_format_human 432000 "Tue Aug 25 19:20" # 5 days ago
+check_date_format_human 1728000 "Mon Aug 10 19:20" # 3 weeks ago
+check_date_format_human 13000000 "Thu Apr 2 08:13" # 5 months ago
+check_date_format_human 31449600 "Aug 31 2008" # 12 months ago
+check_date_format_human 37500000 "Jun 22 2008" # 1 year, 2 months ago
+check_date_format_human 55188000 "Dec 1 2007" # 1 year, 9 months ago
+check_date_format_human 630000000 "Sep 13 1989" # 20 years ago
+
 test_done
diff --git a/t/t0015-hash.sh b/t/t0015-hash.sh
new file mode 100755 (executable)
index 0000000..291e906
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+test_description='test basic hash implementation'
+. ./test-lib.sh
+
+
+test_expect_success 'test basic SHA-1 hash values' '
+       test-tool sha1 </dev/null >actual &&
+       grep da39a3ee5e6b4b0d3255bfef95601890afd80709 actual &&
+       printf "a" | test-tool sha1 >actual &&
+       grep 86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 actual &&
+       printf "abc" | test-tool sha1 >actual &&
+       grep a9993e364706816aba3e25717850c26c9cd0d89d actual &&
+       printf "message digest" | test-tool sha1 >actual &&
+       grep c12252ceda8be8994d5fa0290a47231c1d16aae3 actual &&
+       printf "abcdefghijklmnopqrstuvwxyz" | test-tool sha1 >actual &&
+       grep 32d10c7b8cf96570ca04ce37f2a19d84240d3a89 actual &&
+       perl -e "$| = 1; print q{aaaaaaaaaa} for 1..100000;" | \
+               test-tool sha1 >actual &&
+       grep 34aa973cd4c4daa4f61eeb2bdbad27316534016f actual &&
+       printf "blob 0\0" | test-tool sha1 >actual &&
+       grep e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 actual &&
+       printf "blob 3\0abc" | test-tool sha1 >actual &&
+       grep f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f actual &&
+       printf "tree 0\0" | test-tool sha1 >actual &&
+       grep 4b825dc642cb6eb9a060e54bf8d69288fbee4904 actual
+'
+
+test_expect_success 'test basic SHA-256 hash values' '
+       test-tool sha256 </dev/null >actual &&
+       grep e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 actual &&
+       printf "a" | test-tool sha256 >actual &&
+       grep ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb actual &&
+       printf "abc" | test-tool sha256 >actual &&
+       grep ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad actual &&
+       printf "message digest" | test-tool sha256 >actual &&
+       grep f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650 actual &&
+       printf "abcdefghijklmnopqrstuvwxyz" | test-tool sha256 >actual &&
+       grep 71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73 actual &&
+       # Try to exercise the chunking code by turning autoflush on.
+       perl -e "$| = 1; print q{aaaaaaaaaa} for 1..100000;" | \
+               test-tool sha256 >actual &&
+       grep cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0 actual &&
+       perl -e "$| = 1; print q{abcdefghijklmnopqrstuvwxyz} for 1..100000;" | \
+               test-tool sha256 >actual &&
+       grep e406ba321ca712ad35a698bf0af8d61fc4dc40eca6bdcea4697962724ccbde35 actual &&
+       printf "blob 0\0" | test-tool sha256 >actual &&
+       grep 473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 actual &&
+       printf "blob 3\0abc" | test-tool sha256 >actual &&
+       grep c1cf6e465077930e88dc5136641d402f72a229ddd996f627d60e9639eaba35a6 actual &&
+       printf "tree 0\0" | test-tool sha256 >actual &&
+       grep 6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321 actual
+'
+
+test_done
index 9d9e02a21112197a2a57a2877db24951d41a2996..e13363ade5cf500e6f57677eb961c5ca01197a12 100755 (executable)
@@ -27,4 +27,13 @@ test_expect_success 'renormalize CRLF in repo' '
        test_cmp expect actual
 '
 
+test_expect_success 'ignore-errors not mistaken for renormalize' '
+       git reset --hard &&
+       echo "*.txt text=auto" >.gitattributes &&
+       git ls-files --eol >expect &&
+       git add --ignore-errors "*.txt" &&
+       git ls-files --eol >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 7e87b5a200a3f6483ea2e243fa0c497205ce4e61..e58ecbfc44037fa1d38707b30545e803e1401b4f 100755 (executable)
@@ -11,9 +11,12 @@ test_expect_success 'setup test files' '
 
        text="hallo there!\ncan you read me?" &&
        echo "*.utf16 text working-tree-encoding=utf-16" >.gitattributes &&
+       echo "*.utf16lebom text working-tree-encoding=UTF-16LE-BOM" >>.gitattributes &&
        printf "$text" >test.utf8.raw &&
        printf "$text" | iconv -f UTF-8 -t UTF-16 >test.utf16.raw &&
        printf "$text" | iconv -f UTF-8 -t UTF-32 >test.utf32.raw &&
+       printf "\377\376"                         >test.utf16lebom.raw &&
+       printf "$text" | iconv -f UTF-8 -t UTF-32LE >>test.utf16lebom.raw &&
 
        # Line ending tests
        printf "one\ntwo\nthree\n" >lf.utf8.raw &&
@@ -32,7 +35,8 @@ test_expect_success 'setup test files' '
        # Add only UTF-16 file, we will add the UTF-32 file later
        cp test.utf16.raw test.utf16 &&
        cp test.utf32.raw test.utf32 &&
-       git add .gitattributes test.utf16 &&
+       cp test.utf16lebom.raw test.utf16lebom &&
+       git add .gitattributes test.utf16 test.utf16lebom &&
        git commit -m initial
 '
 
@@ -51,6 +55,12 @@ test_expect_success 're-encode to UTF-16 on checkout' '
        test_cmp_bin test.utf16.raw test.utf16
 '
 
+test_expect_success 're-encode to UTF-16-LE-BOM on checkout' '
+       rm test.utf16lebom &&
+       git checkout test.utf16lebom &&
+       test_cmp_bin test.utf16lebom.raw test.utf16lebom
+'
+
 test_expect_success 'check $GIT_DIR/info/attributes support' '
        test_when_finished "rm -f test.utf32.git" &&
        test_when_finished "git reset --hard HEAD" &&
index 99a614bc7c45ca792c7bbce7d16f793ab6107896..9c7604dcabec86776c3bb25598e39dac79118765 100755 (executable)
@@ -199,4 +199,14 @@ test_expect_success 'GIT_TRACE with environment variables' '
        )
 '
 
+test_expect_success MINGW 'verify curlies are quoted properly' '
+       : force the rev-parse through the MSYS2 Bash &&
+       git -c alias.r="!git rev-parse" r -- a{b}c >actual &&
+       cat >expect <<-\EOF &&
+       --
+       a{b}c
+       EOF
+       test_cmp expect actual
+'
+
 test_done
index e4d5b56014822ff760d3eab6d7c798f8d932ca45..c19fb500cb225273fce730c656fea00a3ada624d 100755 (executable)
@@ -388,4 +388,14 @@ test_expect_success C_LOCALE_OUTPUT 'ambiguous commits are printed by type first
        done
 '
 
+test_expect_success 'cat-file --batch and --batch-check show ambiguous' '
+       echo "0000 ambiguous" >expect &&
+       echo 0000 | git cat-file --batch-check >actual 2>err &&
+       test_cmp expect actual &&
+       test_i18ngrep hint: err &&
+       echo 0000 | git cat-file --batch >actual 2>err &&
+       test_cmp expect actual &&
+       test_i18ngrep hint: err
+'
+
 test_done
index 2131fb2a5682c50faf64e6066f03080702168b94..c5014ad9a63f2451f84db5076f902a0132d318c1 100755 (executable)
@@ -198,4 +198,13 @@ test_expect_success 'checkout -B to the current branch works' '
        test_dirty_mergeable
 '
 
+test_expect_success 'checkout -b after clone --no-checkout does a checkout of HEAD' '
+       git init src &&
+       test_commit -C src a &&
+       rev="$(git -C src rev-parse HEAD)" &&
+       git clone --no-checkout src dest &&
+       git -C dest checkout "$rev" -b branch &&
+       test_path_is_file dest/a.t
+'
+
 test_done
index 7a440e08d8257487ae2f47b159d11e37a5166df8..2b961745cc0aa302d3ac8ea72c4ad919de2e8bbf 100755 (executable)
@@ -156,6 +156,11 @@ test_expect_success 'rebase -i with exec of inexistent command' '
        ! grep "Maybe git-rebase is broken" actual
 '
 
+test_expect_success 'implicit interactive rebase does not invoke sequence editor' '
+       test_when_finished "git rebase --abort ||:" &&
+       GIT_SEQUENCE_EDITOR="echo bad >" git rebase -x"echo one" @^
+'
+
 test_expect_success 'no changes are a nop' '
        git checkout branch2 &&
        set_fake_editor &&
index f64b130cb805bbca8475f3c262693fa0faa2cafe..b393e1e9fee88bb9b3df6ecc8544dfa370086e41 100755 (executable)
@@ -17,14 +17,9 @@ test_expect_success 'setup' '
        git tag start
 '
 
-cat >expect <<\EOF
-Already applied: 0001 A
-Already applied: 0002 B
-Committed: 0003 Z
-EOF
-
 test_expect_success 'rebase -m' '
        git rebase -m master >report &&
+       >expect &&
        sed -n -e "/^Already applied: /p" \
                -e "/^Committed: /p" report >actual &&
        test_cmp expect actual
index 0210b2ac6f0709cce4bf7b656b3c61a751330e61..25aaacacfc6b7beb1e29b73678777a76c6af9f71 100755 (executable)
@@ -254,4 +254,18 @@ test_expect_success 'the todo command "break" works' '
        test_path_is_file execed
 '
 
+test_expect_success '--reschedule-failed-exec' '
+       test_when_finished "git rebase --abort" &&
+       test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
+       grep "^exec false" .git/rebase-merge/git-rebase-todo &&
+       git rebase --abort &&
+       test_must_fail git -c rebase.rescheduleFailedExec=true \
+               rebase -x false HEAD^ 2>err &&
+       grep "^exec false" .git/rebase-merge/git-rebase-todo &&
+       test_i18ngrep "has been rescheduled" err &&
+       git rebase --abort &&
+       test_must_fail git rebase -y false HEAD^ 2>err &&
+       test_i18ngrep "has been rescheduled" err
+'
+
 test_done
index 4c7494cc8f77a3ff92373cb130974825c4418ada..2d1094e4831a88205133558d2ca6ac5ac07209d1 100755 (executable)
@@ -53,41 +53,6 @@ create_expected_success_interactive () {
        EOF
 }
 
-create_expected_success_merge () {
-       cat >expected <<-EOF
-       $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
-       HEAD is now at $(git rev-parse --short feature-branch) third commit
-       First, rewinding head to replay your work on top of it...
-       Merging unrelated-onto-branch with HEAD~1
-       Merging:
-       $(git rev-parse --short unrelated-onto-branch) unrelated commit
-       $(git rev-parse --short feature-branch^) second commit
-       found 1 common ancestor:
-       $(git rev-parse --short feature-branch~2) initial commit
-       [detached HEAD $(git rev-parse --short rebased-feature-branch~1)] second commit
-        Author: A U Thor <author@example.com>
-        Date: Thu Apr 7 15:14:13 2005 -0700
-        2 files changed, 2 insertions(+)
-        create mode 100644 file1
-        create mode 100644 file2
-       Committed: 0001 second commit
-       Merging unrelated-onto-branch with HEAD~0
-       Merging:
-       $(git rev-parse --short rebased-feature-branch~1) second commit
-       $(git rev-parse --short feature-branch) third commit
-       found 1 common ancestor:
-       $(git rev-parse --short feature-branch~1) second commit
-       [detached HEAD $(git rev-parse --short rebased-feature-branch)] third commit
-        Author: A U Thor <author@example.com>
-        Date: Thu Apr 7 15:15:13 2005 -0700
-        1 file changed, 1 insertion(+)
-        create mode 100644 file3
-       Committed: 0002 third commit
-       All done.
-       Applied autostash.
-       EOF
-}
-
 create_expected_failure_am () {
        cat >expected <<-EOF
        $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
@@ -112,43 +77,6 @@ create_expected_failure_interactive () {
        EOF
 }
 
-create_expected_failure_merge () {
-       cat >expected <<-EOF
-       $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
-       HEAD is now at $(git rev-parse --short feature-branch) third commit
-       First, rewinding head to replay your work on top of it...
-       Merging unrelated-onto-branch with HEAD~1
-       Merging:
-       $(git rev-parse --short unrelated-onto-branch) unrelated commit
-       $(git rev-parse --short feature-branch^) second commit
-       found 1 common ancestor:
-       $(git rev-parse --short feature-branch~2) initial commit
-       [detached HEAD $(git rev-parse --short rebased-feature-branch~1)] second commit
-        Author: A U Thor <author@example.com>
-        Date: Thu Apr 7 15:14:13 2005 -0700
-        2 files changed, 2 insertions(+)
-        create mode 100644 file1
-        create mode 100644 file2
-       Committed: 0001 second commit
-       Merging unrelated-onto-branch with HEAD~0
-       Merging:
-       $(git rev-parse --short rebased-feature-branch~1) second commit
-       $(git rev-parse --short feature-branch) third commit
-       found 1 common ancestor:
-       $(git rev-parse --short feature-branch~1) second commit
-       [detached HEAD $(git rev-parse --short rebased-feature-branch)] third commit
-        Author: A U Thor <author@example.com>
-        Date: Thu Apr 7 15:15:13 2005 -0700
-        1 file changed, 1 insertion(+)
-        create mode 100644 file3
-       Committed: 0002 third commit
-       All done.
-       Applying autostash resulted in conflicts.
-       Your changes are safe in the stash.
-       You can run "git stash pop" or "git stash drop" at any time.
-       EOF
-}
-
 testrebase () {
        type=$1
        dotest=$2
@@ -177,6 +105,9 @@ testrebase () {
        test_expect_success "rebase$type --autostash: check output" '
                test_when_finished git branch -D rebased-feature-branch &&
                suffix=${type#\ --} && suffix=${suffix:-am} &&
+               if test ${suffix} = "merge"; then
+                       suffix=interactive
+               fi &&
                create_expected_success_$suffix &&
                test_i18ncmp expected actual
        '
@@ -274,6 +205,9 @@ testrebase () {
        test_expect_success "rebase$type: check output with conflicting stash" '
                test_when_finished git branch -D rebased-feature-branch &&
                suffix=${type#\ --} && suffix=${suffix:-am} &&
+               if test ${suffix} = "merge"; then
+                       suffix=interactive
+               fi &&
                create_expected_failure_$suffix &&
                test_i18ncmp expected actual
        '
index 23ad4cff35a74c9ffb8656f61e777d633459cb77..7274dca40b1ccf0d32aeb98e7b0acec59daaa14d 100755 (executable)
@@ -111,7 +111,7 @@ test_run_rebase () {
        "
 }
 test_run_rebase success ''
-test_run_rebase failure -m
+test_run_rebase success -m
 test_run_rebase success -i
 test_have_prereq !REBASE_P || test_run_rebase success -p
 
@@ -126,7 +126,7 @@ test_run_rebase () {
        "
 }
 test_run_rebase success ''
-test_run_rebase failure -m
+test_run_rebase success -m
 test_run_rebase success -i
 test_have_prereq !REBASE_P || test_run_rebase success -p
 
@@ -141,7 +141,7 @@ test_run_rebase () {
        "
 }
 test_run_rebase success ''
-test_run_rebase failure -m
+test_run_rebase success -m
 test_run_rebase success -i
 test_have_prereq !REBASE_P || test_run_rebase success -p
 
@@ -284,7 +284,7 @@ test_run_rebase () {
        "
 }
 test_run_rebase success ''
-test_run_rebase failure -m
+test_run_rebase success -m
 test_run_rebase success -i
 test_have_prereq !REBASE_P || test_run_rebase success -p
 
@@ -315,7 +315,7 @@ test_run_rebase () {
        "
 }
 test_run_rebase success ''
-test_run_rebase failure -m
+test_run_rebase success -m
 test_run_rebase success -i
 test_have_prereq !REBASE_P || test_run_rebase failure -p
 
index 5f892e33d7e53e8871df256b3344ebd0476712ee..fd8efe84fe8f74d062d73f27fb63d95cc5bed4c8 100755 (executable)
@@ -70,9 +70,8 @@ test_run_rebase () {
                test_linear_range "\'"$expected"\'" d..
        "
 }
-#TODO: make order consistent across all flavors of rebase
-test_run_rebase success 'e n o' ''
-test_run_rebase success 'e n o' -m
+test_run_rebase success 'n o e' ''
+test_run_rebase success 'n o e' -m
 test_run_rebase success 'n o e' -i
 
 test_run_rebase () {
@@ -87,9 +86,8 @@ test_run_rebase () {
                test_linear_range "\'"$expected"\'" c..
        "
 }
-#TODO: make order consistent across all flavors of rebase
-test_run_rebase success 'd e n o' ''
-test_run_rebase success 'd e n o' -m
+test_run_rebase success 'd n o e' ''
+test_run_rebase success 'd n o e' -m
 test_run_rebase success 'd n o e' -i
 
 test_run_rebase () {
@@ -104,9 +102,8 @@ test_run_rebase () {
                test_linear_range "\'"$expected"\'" c..
        "
 }
-#TODO: make order consistent across all flavors of rebase
-test_run_rebase success 'd e n o' ''
-test_run_rebase success 'd e n o' -m
+test_run_rebase success 'd n o e' ''
+test_run_rebase success 'd n o e' -m
 test_run_rebase success 'd n o e' -i
 
 if ! test_have_prereq REBASE_P; then
index cc5646836fce1aaaa01556450a9b017c7a853088..4c69255ee6b14bdd52b6f840e2e528c182cb23ec 100755 (executable)
@@ -125,7 +125,7 @@ test_expect_success '`reset` refuses to overwrite untracked files' '
        : >dont-overwrite-untracked.t &&
        echo "reset refs/tags/dont-overwrite-untracked" >script-from-scratch &&
        test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
-       test_must_fail git rebase -r HEAD &&
+       test_must_fail git rebase -ir HEAD &&
        git rebase --abort
 '
 
index 37729ba2582119047d559d22df8c522f9c0ab0f1..be582a513b1b99a71c10279aacc72cb36bd4bf7b 100755 (executable)
@@ -402,4 +402,11 @@ test_expect_success 'all statuses changed in folder if . is given' '
        test $(git ls-files --stage | grep ^100755 | wc -l) -eq 0
 '
 
+test_expect_success CASE_INSENSITIVE_FS 'path is case-insensitive' '
+       path="$(pwd)/BLUB" &&
+       touch "$path" &&
+       downcased="$(echo "$path" | tr A-Z a-z)" &&
+       git add "$downcased"
+'
+
 test_done
index a8e01eccd158131118019ca7c9b05d08a65d07e3..03489aff14ea72921f66605eeac3ccddd694e923 100755 (executable)
@@ -32,28 +32,37 @@ test_expect_success 'prepare binary file' '
        git commit -m binbin
 '
 
-# test_expect_success '--stat output after text chmod' '
-#      test_chmod -x rezrov &&
-#      echo " 0 files changed" >expect &&
-#      git diff HEAD --stat >actual &&
-#      test_i18ncmp expect actual
-# '
-#
-# test_expect_success '--shortstat output after text chmod' '
-#      git diff HEAD --shortstat >actual &&
-#      test_i18ncmp expect actual
-# '
-#
-# test_expect_success '--stat output after binary chmod' '
-#      test_chmod +x binbin &&
-#      echo " 0 files changed" >expect &&
-#      git diff HEAD --stat >actual &&
-#      test_i18ncmp expect actual
-# '
-#
-# test_expect_success '--shortstat output after binary chmod' '
-#      git diff HEAD --shortstat >actual &&
-#      test_i18ncmp expect actual
-# '
+test_expect_success '--stat output after text chmod' '
+       test_chmod -x rezrov &&
+       cat >expect <<-\EOF &&
+        rezrov | 0
+        1 file changed, 0 insertions(+), 0 deletions(-)
+       EOF
+       git diff HEAD --stat >actual &&
+       test_i18ncmp expect actual
+'
+
+test_expect_success '--shortstat output after text chmod' '
+       tail -n 1 <expect >expect.short &&
+       git diff HEAD --shortstat >actual &&
+       test_i18ncmp expect.short actual
+'
+
+test_expect_success '--stat output after binary chmod' '
+       test_chmod +x binbin &&
+       cat >expect <<-EOF &&
+        binbin | Bin
+        rezrov |   0
+        2 files changed, 0 insertions(+), 0 deletions(-)
+       EOF
+       git diff HEAD --stat >actual &&
+       test_i18ncmp expect actual
+'
+
+test_expect_success '--shortstat output after binary chmod' '
+       tail -n 1 <expect >expect.short &&
+       git diff HEAD --shortstat >actual &&
+       test_i18ncmp expect.short actual
+'
 
 test_done
index 7d985ff6b1bff3c73e4309cde675f67c813d93da..9f8f0e84ad4f35b72da73ef8ddfee0a3cddfbe1a 100755 (executable)
@@ -98,6 +98,12 @@ test_expect_success setup '
        git commit -m "update mode" &&
        git checkout -f master &&
 
+       # Same merge as master, but with parents reversed. Hide it in a
+       # pseudo-ref to avoid impacting tests with --all.
+       commit=$(echo reverse |
+                git commit-tree -p master^2 -p master^1 master^{tree}) &&
+       git update-ref REVERSE $commit &&
+
        git config diff.renames false &&
 
        git show-branch
@@ -239,6 +245,8 @@ diff-tree --cc --stat --summary master
 # stat summary should show the diffstat and summary with the first parent
 diff-tree -c --stat --summary side
 diff-tree --cc --stat --summary side
+diff-tree --cc --shortstat master
+diff-tree --cc --summary REVERSE
 # improved by Timo's patch
 diff-tree --cc --patch-with-stat master
 # improved by Timo's patch
@@ -350,6 +358,7 @@ diff --line-prefix=abc master master^ side
 diff --dirstat master~1 master~2
 diff --dirstat initial rearrange
 diff --dirstat-by-file initial rearrange
+diff --dirstat --cc master~1 master
 # No-index --abbrev and --no-abbrev
 diff --raw initial
 :noellipses diff --raw initial
diff --git a/t/t4013/diff.diff-tree_--cc_--shortstat_master b/t/t4013/diff.diff-tree_--cc_--shortstat_master
new file mode 100644 (file)
index 0000000..a4ca42d
--- /dev/null
@@ -0,0 +1,4 @@
+$ git diff-tree --cc --shortstat master
+59d314ad6f356dd08601a4cd5e530381da3e3c64
+ 2 files changed, 5 insertions(+)
+$
diff --git a/t/t4013/diff.diff-tree_--cc_--summary_REVERSE b/t/t4013/diff.diff-tree_--cc_--summary_REVERSE
new file mode 100644 (file)
index 0000000..e208dd5
--- /dev/null
@@ -0,0 +1,6 @@
+$ git diff-tree --cc --summary REVERSE
+2562325a7ee916efb2481da93073b82cec801cbc
+ create mode 100644 file1
+ delete mode 100644 file2
+ delete mode 100644 file3
+$
diff --git a/t/t4013/diff.diff_--dirstat_--cc_master~1_master b/t/t4013/diff.diff_--dirstat_--cc_master~1_master
new file mode 100644 (file)
index 0000000..fba4e34
--- /dev/null
@@ -0,0 +1,3 @@
+$ git diff --dirstat --cc master~1 master
+  40.0% dir/
+$
index 9a3e4fdfecef4fa00d12b6ff32fc5b0beaff089e..ab4670d23653eca46292b13ef1559584aae5c3a6 100755 (executable)
@@ -1802,8 +1802,8 @@ test_expect_success 'only move detection ignores white spaces' '
        <BOLD;MAGENTA>-a long line to exceed per-line minimum<RESET>
        <BOLD;MAGENTA>-another long line to exceed per-line minimum<RESET>
        <RED>-original file<RESET>
-       <BOLD;YELLOW>+<RESET>Q<BOLD;YELLOW>a long line to exceed per-line minimum<RESET>
-       <BOLD;YELLOW>+<RESET>Q<BOLD;YELLOW>another long line to exceed per-line minimum<RESET>
+       <BOLD;CYAN>+<RESET>Q<BOLD;CYAN>a long line to exceed per-line minimum<RESET>
+       <BOLD;CYAN>+<RESET>Q<BOLD;CYAN>another long line to exceed per-line minimum<RESET>
        <GREEN>+<RESET><GREEN>new file<RESET>
        EOF
        test_cmp expected actual
@@ -1827,6 +1827,7 @@ test_expect_success 'compare whitespace delta across moved blocks' '
        QQQthat has similar lines
        QQQto previous blocks, but with different indent
        QQQYetQAnotherQoutlierQ
+       QLine with internal w h i t e s p a c e change
        EOF
 
        git add text.txt &&
@@ -1847,6 +1848,7 @@ test_expect_success 'compare whitespace delta across moved blocks' '
        QQthat has similar lines
        QQto previous blocks, but with different indent
        QQYetQAnotherQoutlier
+       QLine with internal whitespace change
        EOF
 
        git diff --color --color-moved --color-moved-ws=allow-indentation-change >actual.raw &&
@@ -1856,7 +1858,7 @@ test_expect_success 'compare whitespace delta across moved blocks' '
                <BOLD>diff --git a/text.txt b/text.txt<RESET>
                <BOLD>--- a/text.txt<RESET>
                <BOLD>+++ b/text.txt<RESET>
-               <CYAN>@@ -1,14 +1,14 @@<RESET>
+               <CYAN>@@ -1,15 +1,15 @@<RESET>
                <BOLD;MAGENTA>-QIndented<RESET>
                <BOLD;MAGENTA>-QText across<RESET>
                <BOLD;MAGENTA>-Qsome lines<RESET>
@@ -1871,6 +1873,7 @@ test_expect_success 'compare whitespace delta across moved blocks' '
                <BOLD;MAGENTA>-QQQthat has similar lines<RESET>
                <BOLD;MAGENTA>-QQQto previous blocks, but with different indent<RESET>
                <RED>-QQQYetQAnotherQoutlierQ<RESET>
+               <RED>-QLine with internal w h i t e s p a c e change<RESET>
                <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Indented<RESET>
                <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Text across<RESET>
                <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>some lines<RESET>
@@ -1885,6 +1888,7 @@ test_expect_success 'compare whitespace delta across moved blocks' '
                <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>that has similar lines<RESET>
                <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>to previous blocks, but with different indent<RESET>
                <GREEN>+<RESET>QQ<GREEN>YetQAnotherQoutlier<RESET>
+               <GREEN>+<RESET>Q<GREEN>Line with internal whitespace change<RESET>
        EOF
 
        test_cmp expected actual
@@ -1915,4 +1919,93 @@ test_expect_success 'compare whitespace delta incompatible with other space opti
        test_i18ngrep allow-indentation-change err
 '
 
+EMPTY=''
+test_expect_success 'compare mixed whitespace delta across moved blocks' '
+
+       git reset --hard &&
+       tr Q_ "\t " <<-EOF >text.txt &&
+       ${EMPTY}
+       ____too short without
+       ${EMPTY}
+       ___being grouped across blank line
+       ${EMPTY}
+       context
+       lines
+       to
+       anchor
+       ____Indented text to
+       _Q____be further indented by four spaces across
+       ____Qseveral lines
+       QQ____These two lines have had their
+       ____indentation reduced by four spaces
+       Qdifferent indentation change
+       ____too short
+       EOF
+
+       git add text.txt &&
+       git commit -m "add text.txt" &&
+
+       tr Q_ "\t " <<-EOF >text.txt &&
+       context
+       lines
+       to
+       anchor
+       QIndented text to
+       QQbe further indented by four spaces across
+       Q____several lines
+       ${EMPTY}
+       QQtoo short without
+       ${EMPTY}
+       Q_______being grouped across blank line
+       ${EMPTY}
+       Q_QThese two lines have had their
+       indentation reduced by four spaces
+       QQdifferent indentation change
+       __Qtoo short
+       EOF
+
+       git -c color.diff.whitespace="normal red" \
+               -c core.whitespace=space-before-tab \
+               diff --color --color-moved --ws-error-highlight=all \
+               --color-moved-ws=allow-indentation-change >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
+
+       cat <<-\EOF >expected &&
+       <BOLD>diff --git a/text.txt b/text.txt<RESET>
+       <BOLD>--- a/text.txt<RESET>
+       <BOLD>+++ b/text.txt<RESET>
+       <CYAN>@@ -1,16 +1,16 @@<RESET>
+       <BOLD;MAGENTA>-<RESET>
+       <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>    too short without<RESET>
+       <BOLD;MAGENTA>-<RESET>
+       <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>   being grouped across blank line<RESET>
+       <BOLD;MAGENTA>-<RESET>
+        <RESET>context<RESET>
+        <RESET>lines<RESET>
+        <RESET>to<RESET>
+        <RESET>anchor<RESET>
+       <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>    Indented text to<RESET>
+       <BOLD;MAGENTA>-<RESET><BRED> <RESET>    <BOLD;MAGENTA>    be further indented by four spaces across<RESET>
+       <BOLD;MAGENTA>-<RESET><BRED>    <RESET> <BOLD;MAGENTA>several lines<RESET>
+       <BOLD;BLUE>-<RESET>             <BOLD;BLUE>    These two lines have had their<RESET>
+       <BOLD;BLUE>-<RESET><BOLD;BLUE>    indentation reduced by four spaces<RESET>
+       <BOLD;MAGENTA>-<RESET>  <BOLD;MAGENTA>different indentation change<RESET>
+       <RED>-<RESET><RED>    too short<RESET>
+       <BOLD;CYAN>+<RESET>     <BOLD;CYAN>Indented text to<RESET>
+       <BOLD;CYAN>+<RESET>             <BOLD;CYAN>be further indented by four spaces across<RESET>
+       <BOLD;CYAN>+<RESET>     <BOLD;CYAN>    several lines<RESET>
+       <BOLD;YELLOW>+<RESET>
+       <BOLD;YELLOW>+<RESET>           <BOLD;YELLOW>too short without<RESET>
+       <BOLD;YELLOW>+<RESET>
+       <BOLD;YELLOW>+<RESET>   <BOLD;YELLOW>       being grouped across blank line<RESET>
+       <BOLD;YELLOW>+<RESET>
+       <BOLD;CYAN>+<RESET>     <BRED> <RESET>  <BOLD;CYAN>These two lines have had their<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>indentation reduced by four spaces<RESET>
+       <BOLD;YELLOW>+<RESET>           <BOLD;YELLOW>different indentation change<RESET>
+       <GREEN>+<RESET><BRED>  <RESET>  <GREEN>too short<RESET>
+       EOF
+
+       test_cmp expected actual
+'
+
 test_done
diff --git a/t/t4066-diff-emit-delay.sh b/t/t4066-diff-emit-delay.sh
new file mode 100755 (executable)
index 0000000..5df6b5e
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/sh
+
+test_description='test combined/stat/moved interaction'
+. ./test-lib.sh
+
+# This test covers a weird 3-way interaction between "--cc -p", which will run
+# the combined diff code, along with "--stat", which will be computed as a
+# first-parent stat during the combined diff, and "--color-moved", which
+# enables the emitted_symbols list to store the diff in memory.
+
+test_expect_success 'set up history with a merge' '
+       test_commit A &&
+       test_commit B &&
+       git checkout -b side HEAD^ &&
+       test_commit C &&
+       git merge -m M master &&
+       test_commit D
+'
+
+test_expect_success 'log --cc -p --stat --color-moved' '
+       cat >expect <<-\EOF &&
+       commit D
+       ---
+        D.t | 1 +
+        1 file changed, 1 insertion(+)
+
+       diff --git a/D.t b/D.t
+       new file mode 100644
+       index 0000000..1784810
+       --- /dev/null
+       +++ b/D.t
+       @@ -0,0 +1 @@
+       +D
+       commit M
+
+        B.t | 1 +
+        1 file changed, 1 insertion(+)
+       commit C
+       ---
+        C.t | 1 +
+        1 file changed, 1 insertion(+)
+
+       diff --git a/C.t b/C.t
+       new file mode 100644
+       index 0000000..3cc58df
+       --- /dev/null
+       +++ b/C.t
+       @@ -0,0 +1 @@
+       +C
+       commit B
+       ---
+        B.t | 1 +
+        1 file changed, 1 insertion(+)
+
+       diff --git a/B.t b/B.t
+       new file mode 100644
+       index 0000000..223b783
+       --- /dev/null
+       +++ b/B.t
+       @@ -0,0 +1 @@
+       +B
+       commit A
+       ---
+        A.t | 1 +
+        1 file changed, 1 insertion(+)
+
+       diff --git a/A.t b/A.t
+       new file mode 100644
+       index 0000000..f70f10e
+       --- /dev/null
+       +++ b/A.t
+       @@ -0,0 +1 @@
+       +A
+       EOF
+       git log --format="commit %s" --cc -p --stat --color-moved >actual &&
+       test_cmp expect actual
+'
+
+test_done
index 978a8a66ff05055ad1967b5cc25f36880230a5e4..7df8c3d4ec04ef86e12277e5debfeb8f8f825521 100755 (executable)
@@ -621,4 +621,54 @@ test_expect_success 'trailer parsing not fooled by --- line' '
        test_cmp expect actual
 '
 
+test_expect_success 'set up %S tests' '
+       git checkout --orphan source-a &&
+       test_commit one &&
+       test_commit two &&
+       git checkout -b source-b HEAD^ &&
+       test_commit three
+'
+
+test_expect_success 'log --format=%S paints branch names' '
+       cat >expect <<-\EOF &&
+       source-b
+       source-a
+       source-b
+       EOF
+       git log --format=%S source-a source-b >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'log --format=%S paints tag names' '
+       git tag -m tagged source-tag &&
+       cat >expect <<-\EOF &&
+       source-tag
+       source-a
+       source-tag
+       EOF
+       git log --format=%S source-tag source-a >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'log --format=%S paints symmetric ranges' '
+       cat >expect <<-\EOF &&
+       source-b
+       source-a
+       EOF
+       git log --format=%S source-a...source-b >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '%S in git log --format works with other placeholders (part 1)' '
+       git log --format="source-b %h" source-b >expect &&
+       git log --format="%S %h" source-b >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '%S in git log --format works with other placeholders (part 2)' '
+       git log --format="%h source-b" source-b >expect &&
+       git log --format="%h %S" source-b >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 5fe21db99f43aa79dc36ab36bf6d40ca2f47264d..16d10ebce82fa1fc2e4396f8d30911541b96d7b6 100755 (executable)
@@ -122,7 +122,7 @@ test_expect_success 'write graph with merges' '
        cd "$TRASH_DIRECTORY/full" &&
        git commit-graph write &&
        test_path_is_file $objdir/info/commit-graph &&
-       graph_read_expect "10" "large_edges"
+       graph_read_expect "10" "extra_edges"
 '
 
 graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2
@@ -157,7 +157,7 @@ test_expect_success 'write graph with new commit' '
        cd "$TRASH_DIRECTORY/full" &&
        git commit-graph write &&
        test_path_is_file $objdir/info/commit-graph &&
-       graph_read_expect "11" "large_edges"
+       graph_read_expect "11" "extra_edges"
 '
 
 graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1
@@ -167,7 +167,7 @@ test_expect_success 'write graph with nothing new' '
        cd "$TRASH_DIRECTORY/full" &&
        git commit-graph write &&
        test_path_is_file $objdir/info/commit-graph &&
-       graph_read_expect "11" "large_edges"
+       graph_read_expect "11" "extra_edges"
 '
 
 graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1
@@ -177,7 +177,7 @@ test_expect_success 'build graph from latest pack with closure' '
        cd "$TRASH_DIRECTORY/full" &&
        cat new-idx | git commit-graph write --stdin-packs &&
        test_path_is_file $objdir/info/commit-graph &&
-       graph_read_expect "9" "large_edges"
+       graph_read_expect "9" "extra_edges"
 '
 
 graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1
@@ -200,7 +200,7 @@ test_expect_success 'build graph from commits with append' '
        cd "$TRASH_DIRECTORY/full" &&
        git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
        test_path_is_file $objdir/info/commit-graph &&
-       graph_read_expect "10" "large_edges"
+       graph_read_expect "10" "extra_edges"
 '
 
 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
@@ -210,7 +210,7 @@ test_expect_success 'build graph using --reachable' '
        cd "$TRASH_DIRECTORY/full" &&
        git commit-graph write --reachable &&
        test_path_is_file $objdir/info/commit-graph &&
-       graph_read_expect "11" "large_edges"
+       graph_read_expect "11" "extra_edges"
 '
 
 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
@@ -231,7 +231,7 @@ test_expect_success 'write graph in bare repo' '
        cd "$TRASH_DIRECTORY/bare" &&
        git commit-graph write &&
        test_path_is_file $baredir/info/commit-graph &&
-       graph_read_expect "11" "large_edges"
+       graph_read_expect "11" "extra_edges"
 '
 
 graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
@@ -366,9 +366,10 @@ GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
 GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
 GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
 
-# usage: corrupt_graph_and_verify <position> <data> <string>
+# usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
 # Manipulates the commit-graph file at the position
-# by inserting the data, then runs 'git commit-graph verify'
+# by inserting the data, optionally zeroing the file
+# starting at <zero_pos>, then runs 'git commit-graph verify'
 # and places the output in the file 'err'. Test 'err' for
 # the given string.
 corrupt_graph_and_verify() {
@@ -376,11 +377,15 @@ corrupt_graph_and_verify() {
        data="${2:-\0}"
        grepstr=$3
        cd "$TRASH_DIRECTORY/full" &&
+       orig_size=$(wc -c < $objdir/info/commit-graph) &&
+       zero_pos=${4:-${orig_size}} &&
        test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
        cp $objdir/info/commit-graph commit-graph-backup &&
        printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
+       dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" count=0 &&
+       dd if=/dev/zero of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" count=$(($orig_size - $zero_pos)) &&
        test_must_fail git commit-graph verify 2>test_err &&
-       grep -v "^+" test_err >err
+       grep -v "^+" test_err >err &&
        test_i18ngrep "$grepstr" err
 }
 
@@ -484,6 +489,11 @@ test_expect_success 'detect invalid checksum hash' '
                "incorrect checksum"
 '
 
+test_expect_success 'detect incorrect chunk count' '
+       corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\377" \
+               "chunk lookup table entry missing" $GRAPH_CHUNK_LOOKUP_OFFSET
+'
+
 test_expect_success 'git fsck (checks commit-graph)' '
        cd "$TRASH_DIRECTORY/full" &&
        git fsck &&
diff --git a/t/t5322-pack-objects-sparse.sh b/t/t5322-pack-objects-sparse.sh
new file mode 100755 (executable)
index 0000000..7124b55
--- /dev/null
@@ -0,0 +1,136 @@
+#!/bin/sh
+
+test_description='pack-objects object selection using sparse algorithm'
+. ./test-lib.sh
+
+test_expect_success 'setup repo' '
+       test_commit initial &&
+       for i in $(test_seq 1 3)
+       do
+               mkdir f$i &&
+               for j in $(test_seq 1 3)
+               do
+                       mkdir f$i/f$j &&
+                       echo $j >f$i/f$j/data.txt
+               done
+       done &&
+       git add . &&
+       git commit -m "Initialized trees" &&
+       for i in $(test_seq 1 3)
+       do
+               git checkout -b topic$i master &&
+               echo change-$i >f$i/f$i/data.txt &&
+               git commit -a -m "Changed f$i/f$i/data.txt"
+       done &&
+       cat >packinput.txt <<-EOF &&
+       topic1
+       ^topic2
+       ^topic3
+       EOF
+       git rev-parse                   \
+               topic1                  \
+               topic1^{tree}           \
+               topic1:f1               \
+               topic1:f1/f1            \
+               topic1:f1/f1/data.txt | sort >expect_objects.txt
+'
+
+test_expect_success 'non-sparse pack-objects' '
+       git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
+       git index-pack -o nonsparse.idx nonsparse.pack &&
+       git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
+       test_cmp expect_objects.txt nonsparse_objects.txt
+'
+
+test_expect_success 'sparse pack-objects' '
+       git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
+       git index-pack -o sparse.idx sparse.pack &&
+       git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
+       test_cmp expect_objects.txt sparse_objects.txt
+'
+
+test_expect_success 'duplicate a folder from f3 and commit to topic1' '
+       git checkout topic1 &&
+       echo change-3 >f3/f3/data.txt &&
+       git commit -a -m "Changed f3/f3/data.txt" &&
+       git rev-parse                   \
+               topic1~1                \
+               topic1~1^{tree}         \
+               topic1^{tree}           \
+               topic1                  \
+               topic1:f1               \
+               topic1:f1/f1            \
+               topic1:f1/f1/data.txt | sort >required_objects.txt
+'
+
+test_expect_success 'non-sparse pack-objects' '
+       git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
+       git index-pack -o nonsparse.idx nonsparse.pack &&
+       git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
+       comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
+       test_cmp required_objects.txt nonsparse_required_objects.txt
+'
+
+test_expect_success 'sparse pack-objects' '
+       git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
+       git index-pack -o sparse.idx sparse.pack &&
+       git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
+       comm -1 -2 required_objects.txt sparse_objects.txt >sparse_required_objects.txt &&
+       test_cmp required_objects.txt sparse_required_objects.txt
+'
+
+# Demonstrate that the algorithms differ when we copy a tree wholesale
+# from one folder to another.
+
+test_expect_success 'duplicate a folder from f1 into f3' '
+       mkdir f3/f4 &&
+       cp -r f1/f1/* f3/f4 &&
+       git add f3/f4 &&
+       git commit -m "Copied f1/f1 to f3/f4" &&
+       cat >packinput.txt <<-EOF &&
+       topic1
+       ^topic1~1
+       EOF
+       git rev-parse           \
+               topic1          \
+               topic1^{tree}   \
+               topic1:f3 | sort >required_objects.txt
+'
+
+test_expect_success 'non-sparse pack-objects' '
+       git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
+       git index-pack -o nonsparse.idx nonsparse.pack &&
+       git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
+       comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
+       test_cmp required_objects.txt nonsparse_required_objects.txt
+'
+
+test_expect_success 'sparse pack-objects' '
+       git rev-parse                   \
+               topic1                  \
+               topic1^{tree}           \
+               topic1:f3               \
+               topic1:f3/f4            \
+               topic1:f3/f4/data.txt | sort >expect_sparse_objects.txt &&
+       git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
+       git index-pack -o sparse.idx sparse.pack &&
+       git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
+       test_cmp expect_sparse_objects.txt sparse_objects.txt
+'
+
+test_expect_success 'pack.useSparse enables algorithm' '
+       git config pack.useSparse true &&
+       git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
+       git index-pack -o sparse.idx sparse.pack &&
+       git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
+       test_cmp expect_sparse_objects.txt sparse_objects.txt
+'
+
+test_expect_success 'pack.useSparse overridden' '
+       git pack-objects --stdout --revs --no-sparse <packinput.txt >sparse.pack &&
+       git index-pack -o sparse.idx sparse.pack &&
+       git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
+       test_cmp required_objects.txt sparse_objects.txt
+'
+
+test_done
index fc898c9eac704c934cfbef47fc1463f27dd50c6f..a539ffc0803a746c70d458a95f27144c9039afff 100755 (executable)
@@ -7,82 +7,70 @@ test_description='Test the post-checkout hook.'
 . ./test-lib.sh
 
 test_expect_success setup '
-       echo Data for commit0. >a &&
-       echo Data for commit0. >b &&
-       git update-index --add a &&
-       git update-index --add b &&
-       tree0=$(git write-tree) &&
-       commit0=$(echo setup | git commit-tree $tree0) &&
-       git update-ref refs/heads/master $commit0 &&
-       git clone ./. clone1 &&
-       git clone ./. clone2 &&
-       GIT_DIR=clone2/.git git branch new2 &&
-       echo Data for commit1. >clone2/b &&
-       GIT_DIR=clone2/.git git add clone2/b &&
-       GIT_DIR=clone2/.git git commit -m new2
-'
-
-for clone in 1 2; do
-    cat >clone${clone}/.git/hooks/post-checkout <<'EOF'
-#!/bin/sh
-echo $@ > $GIT_DIR/post-checkout.args
-EOF
-    chmod u+x clone${clone}/.git/hooks/post-checkout
-done
-
-test_expect_success 'post-checkout runs as expected ' '
-       GIT_DIR=clone1/.git git checkout master &&
-       test -e clone1/.git/post-checkout.args
+       mkdir -p .git/hooks &&
+       write_script .git/hooks/post-checkout <<-\EOF &&
+       echo "$@" >.git/post-checkout.args
+       EOF
+       test_commit one &&
+       test_commit two &&
+       test_commit rebase-on-me &&
+       git reset --hard HEAD^ &&
+       test_commit three
 '
 
 test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '
-       old=$(awk "{print \$1}" clone1/.git/post-checkout.args) &&
-       new=$(awk "{print \$2}" clone1/.git/post-checkout.args) &&
-       flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) &&
+       test_when_finished "rm -f .git/post-checkout.args" &&
+       git checkout master &&
+       read old new flag <.git/post-checkout.args &&
        test $old = $new && test $flag = 1
 '
 
-test_expect_success 'post-checkout runs as expected ' '
-       GIT_DIR=clone1/.git git checkout master &&
-       test -e clone1/.git/post-checkout.args
-'
-
 test_expect_success 'post-checkout args are correct with git checkout -b ' '
-       GIT_DIR=clone1/.git git checkout -b new1 &&
-       old=$(awk "{print \$1}" clone1/.git/post-checkout.args) &&
-       new=$(awk "{print \$2}" clone1/.git/post-checkout.args) &&
-       flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) &&
+       test_when_finished "rm -f .git/post-checkout.args" &&
+       git checkout -b new1 &&
+       read old new flag <.git/post-checkout.args &&
        test $old = $new && test $flag = 1
 '
 
 test_expect_success 'post-checkout receives the right args with HEAD changed ' '
-       GIT_DIR=clone2/.git git checkout new2 &&
-       old=$(awk "{print \$1}" clone2/.git/post-checkout.args) &&
-       new=$(awk "{print \$2}" clone2/.git/post-checkout.args) &&
-       flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) &&
+       test_when_finished "rm -f .git/post-checkout.args" &&
+       git checkout two &&
+       read old new flag <.git/post-checkout.args &&
        test $old != $new && test $flag = 1
 '
 
 test_expect_success 'post-checkout receives the right args when not switching branches ' '
-       GIT_DIR=clone2/.git git checkout master b &&
-       old=$(awk "{print \$1}" clone2/.git/post-checkout.args) &&
-       new=$(awk "{print \$2}" clone2/.git/post-checkout.args) &&
-       flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) &&
+       test_when_finished "rm -f .git/post-checkout.args" &&
+       git checkout master -- three.t &&
+       read old new flag <.git/post-checkout.args &&
        test $old = $new && test $flag = 0
 '
 
-if test "$(git config --bool core.filemode)" = true; then
-mkdir -p templates/hooks
-cat >templates/hooks/post-checkout <<'EOF'
-#!/bin/sh
-echo $@ > $GIT_DIR/post-checkout.args
-EOF
-chmod +x templates/hooks/post-checkout
+test_expect_success 'post-checkout is triggered on rebase' '
+       test_when_finished "rm -f .git/post-checkout.args" &&
+       git checkout -b rebase-test master &&
+       rm -f .git/post-checkout.args &&
+       git rebase rebase-on-me &&
+       read old new flag <.git/post-checkout.args &&
+       test $old != $new && test $flag = 1
+'
+
+test_expect_success 'post-checkout is triggered on rebase with fast-forward' '
+       test_when_finished "rm -f .git/post-checkout.args" &&
+       git checkout -b ff-rebase-test rebase-on-me^ &&
+       rm -f .git/post-checkout.args &&
+       git rebase rebase-on-me &&
+       read old new flag <.git/post-checkout.args &&
+       test $old != $new && test $flag = 1
+'
 
 test_expect_success 'post-checkout hook is triggered by clone' '
+       mkdir -p templates/hooks &&
+       write_script templates/hooks/post-checkout <<-\EOF &&
+       echo "$@" >$GIT_DIR/post-checkout.args
+       EOF
        git clone --template=templates . clone3 &&
        test -f clone3/.git/post-checkout.args
 '
-fi
 
 test_done
index 9b2a274c71f40ace060069212055a29f9a3c4203..a4a5903cbaee5c2a67963d8746d0252ba59bf163 100755 (executable)
@@ -78,6 +78,7 @@ test_expect_success 'git rebase --skip' '
        git rebase --continue &&
        echo rebase >expected.args &&
        cat >expected.data <<-EOF &&
+       $(git rev-parse C) $(git rev-parse HEAD^)
        $(git rev-parse D) $(git rev-parse HEAD)
        EOF
        verify_hook_input
@@ -91,6 +92,7 @@ test_expect_success 'git rebase --skip the last one' '
        echo rebase >expected.args &&
        cat >expected.data <<-EOF &&
        $(git rev-parse E) $(git rev-parse HEAD)
+       $(git rev-parse F) $(git rev-parse HEAD)
        EOF
        verify_hook_input
 '
@@ -120,6 +122,38 @@ test_expect_success 'git rebase -m --skip' '
        git rebase --continue &&
        echo rebase >expected.args &&
        cat >expected.data <<-EOF &&
+       $(git rev-parse C) $(git rev-parse HEAD^)
+       $(git rev-parse D) $(git rev-parse HEAD)
+       EOF
+       verify_hook_input
+'
+
+test_expect_success 'git rebase with implicit use of interactive backend' '
+       git reset --hard D &&
+       clear_hook_input &&
+       test_must_fail git rebase --keep --onto A B &&
+       echo C > foo &&
+       git add foo &&
+       git rebase --continue &&
+       echo rebase >expected.args &&
+       cat >expected.data <<-EOF &&
+       $(git rev-parse C) $(git rev-parse HEAD^)
+       $(git rev-parse D) $(git rev-parse HEAD)
+       EOF
+       verify_hook_input
+'
+
+test_expect_success 'git rebase --skip with implicit use of interactive backend' '
+       git reset --hard D &&
+       clear_hook_input &&
+       test_must_fail git rebase --keep --onto A B &&
+       test_must_fail git rebase --skip &&
+       echo D > foo &&
+       git add foo &&
+       git rebase --continue &&
+       echo rebase >expected.args &&
+       cat >expected.data <<-EOF &&
+       $(git rev-parse C) $(git rev-parse HEAD^)
        $(git rev-parse D) $(git rev-parse HEAD)
        EOF
        verify_hook_input
index 086f2c40f68ffaf666a09d88b86709133559fc91..49c540b1e1dbd5fc7d9a7baa36ee93a2ed3fc3c3 100755 (executable)
@@ -439,15 +439,23 @@ test_expect_success 'setup tests for the --stdin parameter' '
        ) >input.dup
 '
 
-test_expect_success 'fetch refs from cmdline' '
-       (
-               cd client &&
-               git fetch-pack --no-progress .. $(cat ../input)
-       ) >output &&
-       cut -d " " -f 2 <output | sort >actual &&
-       test_cmp expect actual
+test_expect_success 'setup fetch refs from cmdline v[12]' '
+       cp -r client client1 &&
+       cp -r client client2
 '
 
+for version in '' 1 2
+do
+       test_expect_success "protocol.version=$version fetch refs from cmdline" "
+               (
+                       cd client$version &&
+                       GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. \$(cat ../input)
+               ) >output &&
+               cut -d ' ' -f 2 <output | sort >actual &&
+               test_cmp expect actual
+       "
+done
+
 test_expect_success 'fetch refs from stdin' '
        (
                cd client &&
index cd9e60632d09e5fd21255261be5de457dc7f409b..ced15ae1224247355125fcbad7ad2184f9861cbe 100755 (executable)
@@ -204,6 +204,12 @@ test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs'
        grep refs/tags/magic actual
 '
 
+test_expect_success 'protocol v2 supports hiderefs' '
+       test_config uploadpack.hiderefs refs/tags &&
+       git -c protocol.version=2 ls-remote . >actual &&
+       ! grep refs/tags actual
+'
+
 test_expect_success 'ls-remote --symref' '
        git fetch origin &&
        cat >expect <<-EOF &&
index a0317556c690262e26ed99cd902ec30c8adda733..63205dfdf962dc31c9db5ba038674e12760a9909 100755 (executable)
@@ -602,4 +602,121 @@ test_expect_success "fetch new commits when submodule got renamed" '
        test_cmp expect actual
 '
 
+test_expect_success "fetch new submodule commits on-demand outside standard refspec" '
+       # add a second submodule and ensure it is around in downstream first
+       git clone submodule sub1 &&
+       git submodule add ./sub1 &&
+       git commit -m "adding a second submodule" &&
+       git -C downstream pull &&
+       git -C downstream submodule update --init --recursive &&
+
+       git checkout --detach &&
+
+       C=$(git -C submodule commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
+       git -C submodule update-ref refs/changes/1 $C &&
+       git update-index --cacheinfo 160000 $C submodule &&
+       test_tick &&
+
+       D=$(git -C sub1 commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
+       git -C sub1 update-ref refs/changes/2 $D &&
+       git update-index --cacheinfo 160000 $D sub1 &&
+
+       git commit -m "updated submodules outside of refs/heads" &&
+       E=$(git rev-parse HEAD) &&
+       git update-ref refs/changes/3 $E &&
+       (
+               cd downstream &&
+               git fetch --recurse-submodules origin refs/changes/3:refs/heads/my_branch &&
+               git -C submodule cat-file -t $C &&
+               git -C sub1 cat-file -t $D &&
+               git checkout --recurse-submodules FETCH_HEAD
+       )
+'
+
+test_expect_success 'fetch new submodule commit on-demand in FETCH_HEAD' '
+       # depends on the previous test for setup
+
+       C=$(git -C submodule commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
+       git -C submodule update-ref refs/changes/4 $C &&
+       git update-index --cacheinfo 160000 $C submodule &&
+       test_tick &&
+
+       D=$(git -C sub1 commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
+       git -C sub1 update-ref refs/changes/5 $D &&
+       git update-index --cacheinfo 160000 $D sub1 &&
+
+       git commit -m "updated submodules outside of refs/heads" &&
+       E=$(git rev-parse HEAD) &&
+       git update-ref refs/changes/6 $E &&
+       (
+               cd downstream &&
+               git fetch --recurse-submodules origin refs/changes/6 &&
+               git -C submodule cat-file -t $C &&
+               git -C sub1 cat-file -t $D &&
+               git checkout --recurse-submodules FETCH_HEAD
+       )
+'
+
+test_expect_success 'fetch new submodule commits on-demand without .gitmodules entry' '
+       # depends on the previous test for setup
+
+       git config -f .gitmodules --remove-section submodule.sub1 &&
+       git add .gitmodules &&
+       git commit -m "delete gitmodules file" &&
+       git checkout -B master &&
+       git -C downstream fetch &&
+       git -C downstream checkout origin/master &&
+
+       C=$(git -C submodule commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
+       git -C submodule update-ref refs/changes/7 $C &&
+       git update-index --cacheinfo 160000 $C submodule &&
+       test_tick &&
+
+       D=$(git -C sub1 commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
+       git -C sub1 update-ref refs/changes/8 $D &&
+       git update-index --cacheinfo 160000 $D sub1 &&
+
+       git commit -m "updated submodules outside of refs/heads" &&
+       E=$(git rev-parse HEAD) &&
+       git update-ref refs/changes/9 $E &&
+       (
+               cd downstream &&
+               git fetch --recurse-submodules origin refs/changes/9 &&
+               git -C submodule cat-file -t $C &&
+               git -C sub1 cat-file -t $D &&
+               git checkout --recurse-submodules FETCH_HEAD
+       )
+'
+
+test_expect_success 'fetch new submodule commit intermittently referenced by superproject' '
+       # depends on the previous test for setup
+
+       D=$(git -C sub1 commit-tree -m "change 10 outside refs/heads" HEAD^{tree}) &&
+       E=$(git -C sub1 commit-tree -m "change 11 outside refs/heads" HEAD^{tree}) &&
+       F=$(git -C sub1 commit-tree -m "change 12 outside refs/heads" HEAD^{tree}) &&
+
+       git -C sub1 update-ref refs/changes/10 $D &&
+       git update-index --cacheinfo 160000 $D sub1 &&
+       git commit -m "updated submodules outside of refs/heads" &&
+
+       git -C sub1 update-ref refs/changes/11 $E &&
+       git update-index --cacheinfo 160000 $E sub1 &&
+       git commit -m "updated submodules outside of refs/heads" &&
+
+       git -C sub1 update-ref refs/changes/12 $F &&
+       git update-index --cacheinfo 160000 $F sub1 &&
+       git commit -m "updated submodules outside of refs/heads" &&
+
+       G=$(git rev-parse HEAD) &&
+       git update-ref refs/changes/13 $G &&
+       (
+               cd downstream &&
+               git fetch --recurse-submodules origin refs/changes/13 &&
+
+               git -C sub1 cat-file -t $D &&
+               git -C sub1 cat-file -t $E &&
+               git -C sub1 cat-file -t $F
+       )
+'
+
 test_done
index 6faf17e17a133f31245f89fd0fe9bad1687ac5fa..6caf628efaaa400473ddfb46fdef0b847b4edd39 100755 (executable)
@@ -243,7 +243,8 @@ test_expect_success 'shallow fetches check connectivity before writing shallow f
               "$(git -C "$REPO" rev-parse HEAD)" \
               "$(git -C "$REPO" rev-parse HEAD^)" \
               >"$HTTPD_ROOT_PATH/one-time-sed" &&
-       test_must_fail git -C client fetch --depth=1 "$HTTPD_URL/one_time_sed/repo" \
+       test_must_fail env GIT_TEST_SIDEBAND_ALL=0 git -C client \
+               fetch --depth=1 "$HTTPD_URL/one_time_sed/repo" \
                master:a_branch &&
 
        # Ensure that the one-time-sed script was used.
index ba548df4a918243ee1b2bcedab525e6ec7eff7d6..217adf3a632b49e9322de1db78c3e1a588c3b7bd 100755 (executable)
@@ -40,6 +40,11 @@ test_expect_success clone '
        git clone "file://$UNCPATH" clone
 '
 
+test_expect_success 'clone with backslashed path' '
+       BACKSLASHED="$(echo "$UNCPATH" | tr / \\\\)" &&
+       git clone "$BACKSLASHED" backslashed
+'
+
 test_expect_success push '
        (
                cd clone &&
diff --git a/t/t5581-http-curl-verbose.sh b/t/t5581-http-curl-verbose.sh
new file mode 100755 (executable)
index 0000000..cd9283e
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+test_description='test GIT_CURL_VERBOSE'
+. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-httpd.sh
+start_httpd
+
+test_expect_success 'setup repository' '
+       mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+       git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" --bare init &&
+       git config push.default matching &&
+       echo content >file &&
+       git add file &&
+       git commit -m one &&
+       git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+       git push public master:master
+'
+
+test_expect_success 'failure in git-upload-pack is shown' '
+       test_might_fail env GIT_CURL_VERBOSE=1 \
+               git clone "$HTTPD_URL/error_git_upload_pack/smart/repo.git" \
+               2>curl_log &&
+       grep "< HTTP/1.1 500 Intentional Breakage" curl_log
+'
+
+stop_httpd
+
+test_done
index ae79c6bbc0d66e9a7a184b2d1726a316a0affbbe..fe45bf828d09cd9d95a66742ef938837d35141a3 100755 (executable)
@@ -14,7 +14,7 @@ test_expect_success 'test capability advertisement' '
        0000
        EOF
 
-       git serve --advertise-capabilities >out &&
+       GIT_TEST_SIDEBAND_ALL=0 git serve --advertise-capabilities >out &&
        test-tool pkt-line unpack <out >actual &&
        test_cmp expect actual
 '
index 0f2b09ebb8d6625b527ccc771c4725d2a314d4ee..db4ae09f2f81ff77b9c29b99c21363e66c81f222 100755 (executable)
@@ -471,6 +471,53 @@ test_expect_success 'upload-pack respects client shallows' '
        grep "fetch< version 2" trace
 '
 
+test_expect_success 'ensure that multiple fetches in same process from a shallow repo works' '
+       rm -rf server client trace &&
+
+       test_create_repo server &&
+       test_commit -C server one &&
+       test_commit -C server two &&
+       test_commit -C server three &&
+       git clone --shallow-exclude two "file://$(pwd)/server" client &&
+
+       git -C server tag -a -m "an annotated tag" twotag two &&
+
+       # Triggers tag following (thus, 2 fetches in one process)
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
+               fetch --shallow-exclude one origin &&
+       # Ensure that protocol v2 is used
+       grep "fetch< version 2" trace
+'
+
+test_expect_success 'deepen-relative' '
+       rm -rf server client trace &&
+
+       test_create_repo server &&
+       test_commit -C server one &&
+       test_commit -C server two &&
+       test_commit -C server three &&
+       git clone --depth 1 "file://$(pwd)/server" client &&
+       test_commit -C server four &&
+
+       # Sanity check that only "three" is downloaded
+       git -C client log --pretty=tformat:%s master >actual &&
+       echo three >expected &&
+       test_cmp expected actual &&
+
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
+               fetch --deepen=1 origin &&
+       # Ensure that protocol v2 is used
+       grep "fetch< version 2" trace &&
+
+       git -C client log --pretty=tformat:%s origin/master >actual &&
+       cat >expected <<-\EOF &&
+       four
+       three
+       two
+       EOF
+       test_cmp expected actual
+'
+
 # Test protocol v2 with 'http://' transport
 #
 . "$TEST_DIRECTORY"/lib-httpd.sh
@@ -514,6 +561,27 @@ test_expect_success 'fetch with http:// using protocol v2' '
        grep "git< version 2" log
 '
 
+test_expect_success 'fetch from namespaced repo respects namespaces' '
+       test_when_finished "rm -f log" &&
+
+       git init "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" &&
+       test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" one &&
+       test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" two &&
+       git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" \
+               update-ref refs/namespaces/ns/refs/heads/master one &&
+
+       GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
+               fetch "$HTTPD_URL/smart_namespace/nsrepo" \
+               refs/heads/master:refs/heads/theirs &&
+
+       # Server responded using protocol v2
+       grep "fetch< version 2" log &&
+
+       git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" rev-parse one >expect &&
+       git -C http_child rev-parse theirs >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'push with http:// and a config of v2 does not request v2' '
        test_when_finished "rm -f log" &&
        # Till v2 for push is designed, make sure that if a client has
@@ -583,8 +651,8 @@ test_expect_success 'when server does not send "ready", expect FLUSH' '
        test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" git -C http_child \
                -c protocol.version=2 \
                fetch "$HTTPD_URL/one_time_sed/http_parent" 2> err &&
-       grep "fetch< acknowledgments" log &&
-       ! grep "fetch< ready" log &&
+       grep "fetch< .*acknowledgments" log &&
+       ! grep "fetch< .*ready" log &&
        test_i18ngrep "expected no other sections to be sent after no .ready." err
 '
 
index 7053899cb5a0cbd5cca10cb4029b70df866dbff8..f87b2f6df329975e243ab9c00b510ee4cc588d0b 100755 (executable)
@@ -208,7 +208,7 @@ test_expect_success 'server is initially ahead - no ref in want' '
        cp -r "$LOCAL_PRISTINE" local &&
        inconsistency master 1234567890123456789012345678901234567890 &&
        test_must_fail git -C local fetch 2>err &&
-       test_i18ngrep "ERR upload-pack: not our ref" err
+       test_i18ngrep "fatal: remote error: upload-pack: not our ref" err
 '
 
 test_expect_success 'server is initially ahead - ref in want' '
@@ -254,7 +254,7 @@ test_expect_success 'server loses a ref - ref in want' '
        echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-sed" &&
        test_must_fail git -C local fetch 2>err &&
 
-       test_i18ngrep "ERR unknown ref refs/heads/raster" err
+       test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err
 '
 
 stop_httpd
index ec42c2f7797c38f39bb3420402d975a94217d1f4..da113d975b160f3c34a4acda3d82a26d65f5268e 100755 (executable)
@@ -185,6 +185,10 @@ test_expect_success 'basic colors' '
        test_cmp expect actual
 '
 
+test_expect_success '%S is not a placeholder for rev-list yet' '
+       git rev-list --format="%S" -1 master | grep "%S"
+'
+
 test_expect_success 'advanced colors' '
        cat >expect <<-EOF &&
        commit $head2
index f84ff941c3624be821fd87a67922ad1d2ca00b34..55835ee4a47158e1f7aeaa9aeb393f1f3d619791 100755 (executable)
@@ -802,7 +802,7 @@ test_expect_success 'bisect terms needs 0 or 1 argument' '
        test_must_fail git bisect terms only-one &&
        test_must_fail git bisect terms 1 2 &&
        test_must_fail git bisect terms 2>actual &&
-       echo "no terms defined" >expected &&
+       echo "error: no terms defined" >expected &&
        test_i18ncmp expected actual
 '
 
index 7cc34e75797b406096407ba1799a1ca54e48333c..09dfa8bd92b51e7a90fcd01f07c62a6fdf65a528 100755 (executable)
@@ -1175,7 +1175,7 @@ test_expect_success 'setup nested conflicts from rename/rename(2to1)' '
 
                # Handle the left side
                git checkout L &&
-               git mv one three &&
+               git rm one two &&
                mv -f file_v2 three &&
                mv -f file_v5 two &&
                git add two three &&
@@ -1183,7 +1183,7 @@ test_expect_success 'setup nested conflicts from rename/rename(2to1)' '
 
                # Handle the right side
                git checkout R &&
-               git mv two three &&
+               git rm one two &&
                mv -f file_v3 one &&
                mv -f file_v6 three &&
                git add one three &&
index eb32505a6ef8804f4f7762ce0332f00beeacbe99..9c114277196e5c231869dbfe51f88760c40ae0b8 100755 (executable)
@@ -283,7 +283,7 @@ test_expect_success 'verify tree:0 includes trees in "filtered" output' '
 
 # Make sure tree:0 does not iterate through any trees.
 
-test_expect_success 'filter a GIANT tree through tree:0' '
+test_expect_success 'verify skipping tree iteration when not collecting omits' '
        GIT_TRACE=1 git -C r3 rev-list \
                --objects --filter=tree:0 HEAD 2>filter_trace &&
        grep "Skipping contents of tree [.][.][.]" filter_trace >actual &&
@@ -294,6 +294,126 @@ test_expect_success 'filter a GIANT tree through tree:0' '
        ! grep "Skipping contents of tree [^.]" filter_trace
 '
 
+# Test tree:# filters.
+
+expect_has () {
+       commit=$1 &&
+       name=$2 &&
+
+       hash=$(git -C r3 rev-parse $commit:$name) &&
+       grep "^$hash $name$" actual
+}
+
+test_expect_success 'verify tree:1 includes root trees' '
+       git -C r3 rev-list --objects --filter=tree:1 HEAD >actual &&
+
+       # We should get two root directories and two commits.
+       expect_has HEAD "" &&
+       expect_has HEAD~1 ""  &&
+       test_line_count = 4 actual
+'
+
+test_expect_success 'verify tree:2 includes root trees and immediate children' '
+       git -C r3 rev-list --objects --filter=tree:2 HEAD >actual &&
+
+       expect_has HEAD "" &&
+       expect_has HEAD~1 "" &&
+       expect_has HEAD dir1 &&
+       expect_has HEAD pattern &&
+       expect_has HEAD sparse1 &&
+       expect_has HEAD sparse2 &&
+
+       # There are also 2 commit objects
+       test_line_count = 8 actual
+'
+
+test_expect_success 'verify tree:3 includes everything expected' '
+       git -C r3 rev-list --objects --filter=tree:3 HEAD >actual &&
+
+       expect_has HEAD "" &&
+       expect_has HEAD~1 "" &&
+       expect_has HEAD dir1 &&
+       expect_has HEAD dir1/sparse1 &&
+       expect_has HEAD dir1/sparse2 &&
+       expect_has HEAD pattern &&
+       expect_has HEAD sparse1 &&
+       expect_has HEAD sparse2 &&
+
+       # There are also 2 commit objects
+       test_line_count = 10 actual
+'
+
+# Test provisional omit collection logic with a repo that has objects appearing
+# at multiple depths - first deeper than the filter's threshold, then shallow.
+
+test_expect_success 'setup r4' '
+       git init r4 &&
+
+       echo foo > r4/foo &&
+       mkdir r4/subdir &&
+       echo bar > r4/subdir/bar &&
+
+       mkdir r4/filt &&
+       cp -r r4/foo r4/subdir r4/filt &&
+
+       git -C r4 add foo subdir filt &&
+       git -C r4 commit -m "commit msg"
+'
+
+expect_has_with_different_name () {
+       repo=$1 &&
+       name=$2 &&
+
+       hash=$(git -C $repo rev-parse HEAD:$name) &&
+       ! grep "^$hash $name$" actual &&
+       grep "^$hash " actual &&
+       ! grep "~$hash" actual
+}
+
+test_expect_success 'test tree:# filter provisional omit for blob and tree' '
+       git -C r4 rev-list --objects --filter-print-omitted --filter=tree:2 \
+               HEAD >actual &&
+       expect_has_with_different_name r4 filt/foo &&
+       expect_has_with_different_name r4 filt/subdir
+'
+
+test_expect_success 'verify skipping tree iteration when collecting omits' '
+       GIT_TRACE=1 git -C r4 rev-list --filter-print-omitted \
+               --objects --filter=tree:0 HEAD 2>filter_trace &&
+       grep "^Skipping contents of tree " filter_trace >actual &&
+
+       echo "Skipping contents of tree subdir/..." >expect &&
+       test_cmp expect actual
+'
+
+# Test tree:<depth> where a tree is iterated to twice - once where a subentry is
+# too deep to be included, and again where the blob inside it is shallow enough
+# to be included. This makes sure we don't use LOFR_MARK_SEEN incorrectly (we
+# can't use it because a tree can be iterated over again at a lower depth).
+
+test_expect_success 'tree:<depth> where we iterate over tree at two levels' '
+       git init r5 &&
+
+       mkdir -p r5/a/subdir/b &&
+       echo foo > r5/a/subdir/b/foo &&
+
+       mkdir -p r5/subdir/b &&
+       echo foo > r5/subdir/b/foo &&
+
+       git -C r5 add a subdir &&
+       git -C r5 commit -m "commit msg" &&
+
+       git -C r5 rev-list --objects --filter=tree:4 HEAD >actual &&
+       expect_has_with_different_name r5 a/subdir/b/foo
+'
+
+test_expect_success 'tree:<depth> which filters out blob but given as arg' '
+       blob_hash=$(git -C r4 rev-parse HEAD:subdir/bar) &&
+
+       git -C r4 rev-list --objects --filter=tree:1 HEAD $blob_hash >actual &&
+       grep ^$blob_hash actual
+'
+
 # Delete some loose objects and use rev-list, but WITHOUT any filtering.
 # This models previously omitted objects that we did not receive.
 
@@ -324,4 +444,21 @@ test_expect_success 'rev-list W/ missing=allow-any' '
        git -C r1 rev-list --quiet --missing=allow-any --objects HEAD
 '
 
+# Test expansion of filter specs.
+
+test_expect_success 'expand blob limit in protocol' '
+       git -C r2 config --local uploadpack.allowfilter 1 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 clone \
+               --filter=blob:limit=1k "file://$(pwd)/r2" limit &&
+       ! grep "blob:limit=1k" trace &&
+       grep "blob:limit=1024" trace
+'
+
+test_expect_success 'expand tree depth limit in protocol' '
+       GIT_TRACE_PACKET="$(pwd)/tree_trace" git -c protocol.version=2 clone \
+               --filter=tree:0k "file://$(pwd)/r2" tree &&
+       ! grep "tree:0k" tree_trace &&
+       grep "tree:0" tree_trace
+'
+
 test_done
index ebfcad9c4c7d3c6766907d76c5e0c794a0720e1c..ba8bd1b51497df1aedf2280210a98b389f12b9e7 100755 (executable)
@@ -215,7 +215,7 @@ test_expect_success 'with hook and editor (merge)' '
 test_rebase () {
        expect=$1 &&
        mode=$2 &&
-       test_expect_$expect C_LOCALE_OUTPUT "with hook (rebase $mode)" '
+       test_expect_$expect C_LOCALE_OUTPUT "with hook (rebase ${mode:--i})" '
                test_when_finished "\
                        git rebase --abort
                        git checkout -f master
@@ -225,7 +225,7 @@ test_rebase () {
                GIT_EDITOR="\"$FAKE_EDITOR\"" &&
                (
                        export GIT_SEQUENCE_EDITOR GIT_EDITOR &&
-                       test_must_fail git rebase $mode b &&
+                       test_must_fail git rebase -i $mode b &&
                        echo x >a &&
                        git add a &&
                        test_must_fail git rebase --continue &&
@@ -241,18 +241,18 @@ test_rebase () {
                        git add b &&
                        git rebase --continue
                ) &&
-               if test $mode = -p # reword amended after pick
+               if test "$mode" = -p # reword amended after pick
                then
                        n=18
                else
                        n=17
                fi &&
                git log --pretty=%s -g -n$n HEAD@{1} >actual &&
-               test_cmp "$TEST_DIRECTORY/t7505/expected-rebase$mode" actual
+               test_cmp "$TEST_DIRECTORY/t7505/expected-rebase${mode:--i}" actual
        '
 }
 
-test_rebase success -i
+test_rebase success
 test_have_prereq !REBASE_P || test_rebase success -p
 
 test_expect_success 'with hook (cherry-pick)' '
index 2325599ee60f5bf9b179f4a33ccbe866458c0740..850d97911966fe78f22035dab78ac0556a82fd99 100755 (executable)
@@ -500,6 +500,10 @@ test_expect_success 'submit --shelve' '
        )
 '
 
+last_shelve () {
+       p4 -G changes -s shelved -m 1 //depot/... | marshal_dump change
+}
+
 make_shelved_cl() {
        test_commit "$1" >/dev/null &&
        git p4 submit --origin HEAD^ --shelve >/dev/null &&
@@ -533,12 +537,59 @@ test_expect_success 'submit --update-shelve' '
        ) &&
        (
                cd "$cli" &&
-               change=$(p4 -G changes -s shelved -m 1 //depot/... | \
-                        marshal_dump change) &&
+               change=$(last_shelve) &&
                p4 unshelve -c $change -s $change &&
                grep -q updated-line shelf.t &&
                p4 describe -S $change | grep added-file.t &&
-               test_path_is_missing shelved-change-1.t
+               test_path_is_missing shelved-change-1.t &&
+               p4 revert ...
+       )
+'
+
+test_expect_success 'update a shelve involving moved and copied files' '
+       test_when_finished cleanup_git &&
+       (
+               cd "$cli" &&
+               : >file_to_move &&
+               p4 add file_to_move &&
+               p4 submit -d "change1" &&
+               p4 edit file_to_move &&
+               echo change >>file_to_move &&
+               p4 submit -d "change2" &&
+               p4 opened
+       ) &&
+       git p4 clone --dest="$git" //depot &&
+       (
+               cd "$git" &&
+               git config git-p4.detectCopies true &&
+               git config git-p4.detectRenames true &&
+               git config git-p4.skipSubmitEdit true &&
+               mkdir moved &&
+               cp file_to_move copy_of_file &&
+               git add copy_of_file &&
+               git mv file_to_move moved/ &&
+               git commit -m "rename a file" &&
+               git p4 submit -M --shelve --origin HEAD^ &&
+               : >new_file &&
+               git add new_file &&
+               git commit --amend &&
+               git show --stat HEAD &&
+               change=$(last_shelve) &&
+               git p4 submit -M --update-shelve $change --commit HEAD
+       ) &&
+       (
+               cd "$cli" &&
+               change=$(last_shelve) &&
+               echo change=$change &&
+               p4 unshelve -s $change &&
+               p4 submit -d "Testing update-shelve" &&
+               test_path_is_file copy_of_file &&
+               test_path_is_file moved/file_to_move &&
+               test_path_is_missing file_to_move &&
+               test_path_is_file new_file &&
+               echo "unshelved and submitted change $change" &&
+               p4 changes moved/file_to_move | grep "Testing update-shelve" &&
+               p4 changes copy_of_file | grep "Testing update-shelve"
        )
 '
 
index 81a5179e28bf529bc2f0a8bc197108fcb69fba72..5cadedb2a9bc6eb66b9ead3ccae037e62a655f2c 100755 (executable)
@@ -180,7 +180,7 @@ test_expect_success 'prompt - interactive rebase' '
 '
 
 test_expect_success 'prompt - rebase merge' '
-       printf " (b2|REBASE-m 1/3)" >expected &&
+       printf " (b2|REBASE-i 1/3)" >expected &&
        git checkout b2 &&
        test_when_finished "git checkout master" &&
        test_must_fail git rebase --merge b1 b2 &&
index a1abb1177a15c85ef7c75f0b9b056a59ff9843e9..9876b4bab0044c73bca5eaccdfa5f6611f3f59b7 100644 (file)
@@ -1154,7 +1154,7 @@ test -d "$GIT_BUILD_DIR"/templates/blt || {
        error "You haven't built things yet, have you?"
 }
 
-if ! test -x "$GIT_BUILD_DIR"/t/helper/test-tool
+if ! test -x "$GIT_BUILD_DIR"/t/helper/test-tool$X
 then
        echo >&2 'You need to build test-tool:'
        echo >&2 'Run "make t/helper/test-tool" in the source (toplevel) directory'
index 6cf3bb324e149c0180d332497edf2b2c15a6b71c..1f52c95fd87b1a02968727bde71dcc1eddc50410 100644 (file)
@@ -679,10 +679,15 @@ static int fetch(struct transport *transport,
        if (data->transport_options.update_shallow)
                set_helper_option(transport, "update-shallow", "true");
 
-       if (data->transport_options.filter_options.choice)
-               set_helper_option(
-                       transport, "filter",
-                       data->transport_options.filter_options.filter_spec);
+       if (data->transport_options.filter_options.choice) {
+               struct strbuf expanded_filter_spec = STRBUF_INIT;
+               expand_list_objects_filter_spec(
+                       &data->transport_options.filter_options,
+                       &expanded_filter_spec);
+               set_helper_option(transport, "filter",
+                                 expanded_filter_spec.buf);
+               strbuf_release(&expanded_filter_spec);
+       }
 
        if (data->transport_options.negotiation_tips)
                warning("Ignoring --negotiation-tip because the protocol does not support it.");
index 99678153c13a3ca442088595273fbcd6caacda29..e078812897eddefcd5a55a7d474dd4a7a89434fc 100644 (file)
@@ -273,7 +273,8 @@ static struct ref *handshake(struct transport *transport, int for_push,
 
        packet_reader_init(&reader, data->fd[0], NULL, 0,
                           PACKET_READ_CHOMP_NEWLINE |
-                          PACKET_READ_GENTLE_ON_EOF);
+                          PACKET_READ_GENTLE_ON_EOF |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
 
        data->version = discover_version(&reader);
        switch (data->version) {
index 34ee3b13b8f8369de4315f71f0d9ab99b1d42f22..e6d306f69f940edd9613de0b38ffe2d9993f91ab 100644 (file)
@@ -239,7 +239,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
                                                DIFF_STATUS_ADDED;
 
                        if (tpi_valid) {
-                               oid_i = tp[i].entry.oid;
+                               oid_i = &tp[i].entry.oid;
                                mode_i = tp[i].entry.mode;
                        }
                        else {
@@ -280,7 +280,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
                        /* same rule as in emitthis */
                        int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);
 
-                       parents_oid[i] = tpi_valid ? tp[i].entry.oid : NULL;
+                       parents_oid[i] = tpi_valid ? &tp[i].entry.oid : NULL;
                }
 
                strbuf_add(base, path, pathlen);
@@ -492,7 +492,7 @@ static struct combine_diff_path *ll_diff_tree_paths(
                                                continue;
 
                                        /* diff(t,pi) != Ã¸ */
-                                       if (!oideq(t.entry.oid, tp[i].entry.oid) ||
+                                       if (!oideq(&t.entry.oid, &tp[i].entry.oid) ||
                                            (t.entry.mode != tp[i].entry.mode))
                                                continue;
 
index 08210a4109c70364e630290a24478333aeee449a..1e4bbc8a0e48c6afe61dc8aab76488356d7e1cbc 100644 (file)
@@ -48,7 +48,8 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l
        /* Initialize the descriptor entry */
        desc->entry.path = path;
        desc->entry.mode = canon_mode(mode);
-       desc->entry.oid  = (const struct object_id *)(path + len);
+       desc->entry.pathlen = len - 1;
+       hashcpy(desc->entry.oid.hash, (const unsigned char *)path + len);
 
        return 0;
 }
@@ -107,7 +108,7 @@ static void entry_extract(struct tree_desc *t, struct name_entry *a)
 static int update_tree_entry_internal(struct tree_desc *desc, struct strbuf *err)
 {
        const void *buf = desc->buffer;
-       const unsigned char *end = desc->entry.oid->hash + the_hash_algo->rawsz;
+       const unsigned char *end = (const unsigned char *)desc->entry.path + desc->entry.pathlen + 1 + the_hash_algo->rawsz;
        unsigned long size = desc->size;
        unsigned long len = end - (const unsigned char *)buf;
 
@@ -175,9 +176,11 @@ void setup_traverse_info(struct traverse_info *info, const char *base)
                pathlen--;
        info->pathlen = pathlen ? pathlen + 1 : 0;
        info->name.path = base;
-       info->name.oid = (void *)(base + pathlen + 1);
-       if (pathlen)
+       info->name.pathlen = pathlen;
+       if (pathlen) {
+               hashcpy(info->name.oid.hash, (const unsigned char *)base + pathlen + 1);
                info->prev = &dummy;
+       }
 }
 
 char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n)
@@ -502,10 +505,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, struct object_
        int namelen = strlen(name);
        while (t->size) {
                const char *entry;
-               const struct object_id *oid;
+               struct object_id oid;
                int entrylen, cmp;
 
-               oid = tree_entry_extract(t, &entry, mode);
+               oidcpy(&oid, tree_entry_extract(t, &entry, mode));
                entrylen = tree_entry_len(&t->entry);
                update_tree_entry(t);
                if (entrylen > namelen)
@@ -516,7 +519,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, struct object_
                if (cmp < 0)
                        break;
                if (entrylen == namelen) {
-                       oidcpy(result, oid);
+                       oidcpy(result, &oid);
                        return 0;
                }
                if (name[entrylen] != '/')
@@ -524,10 +527,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, struct object_
                if (!S_ISDIR(*mode))
                        break;
                if (++entrylen == namelen) {
-                       oidcpy(result, oid);
+                       oidcpy(result, &oid);
                        return 0;
                }
-               return get_tree_entry(oid, name + entrylen, result, mode);
+               return get_tree_entry(&oid, name + entrylen, result, mode);
        }
        return -1;
 }
@@ -579,10 +582,10 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob
  * with the sha1 of the found object, and *mode will hold the mode of
  * the object.
  *
- * See the code for enum follow_symlink_result for a description of
+ * See the code for enum get_oid_result for a description of
  * the return values.
  */
-enum follow_symlinks_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned *mode)
+enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned *mode)
 {
        int retval = MISSING_OBJECT;
        struct dir_state *parents = NULL;
index eefd26bb6214916f7c451d97710b5ee443e52088..82251718666eb5dceb33d6140e86de5a627baab1 100644 (file)
@@ -1,12 +1,12 @@
 #ifndef TREE_WALK_H
 #define TREE_WALK_H
 
-struct index_state;
-struct strbuf;
+#include "cache.h"
 
 struct name_entry {
-       const struct object_id *oid;
+       struct object_id oid;
        const char *path;
+       int pathlen;
        unsigned int mode;
 };
 
@@ -20,12 +20,12 @@ static inline const struct object_id *tree_entry_extract(struct tree_desc *desc,
 {
        *pathp = desc->entry.path;
        *modep = desc->entry.mode;
-       return desc->entry.oid;
+       return &desc->entry.oid;
 }
 
 static inline int tree_entry_len(const struct name_entry *ne)
 {
-       return (const char *)ne->oid - ne->path - 1;
+       return ne->pathlen;
 }
 
 /*
@@ -51,23 +51,7 @@ struct traverse_info;
 typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
 int traverse_trees(struct index_state *istate, int n, struct tree_desc *t, struct traverse_info *info);
 
-enum follow_symlinks_result {
-       FOUND = 0, /* This includes out-of-tree links */
-       MISSING_OBJECT = -1, /* The initial symlink is missing */
-       DANGLING_SYMLINK = -2, /*
-                               * The initial symlink is there, but
-                               * (transitively) points to a missing
-                               * in-tree file
-                               */
-       SYMLINK_LOOP = -3,
-       NOT_DIR = -4, /*
-                      * Somewhere along the symlink chain, a path is
-                      * requested which contains a file as a
-                      * non-final element.
-                      */
-};
-
-enum follow_symlinks_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned *mode);
+enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned *mode);
 
 struct traverse_info {
        const char *traverse_path;
diff --git a/tree.c b/tree.c
index 0b5c84d0d79ff6e598d50c829df47c4dcce7d32c..f416afc57d784f8f63ba66ec8c7424ef1e4fcaa1 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "cache-tree.h"
 #include "tree.h"
@@ -86,7 +85,7 @@ static int read_tree_1(struct repository *r,
                                continue;
                }
 
-               switch (fn(entry.oid, base,
+               switch (fn(&entry.oid, base,
                           entry.path, entry.mode, stage, context)) {
                case 0:
                        continue;
@@ -97,19 +96,19 @@ static int read_tree_1(struct repository *r,
                }
 
                if (S_ISDIR(entry.mode))
-                       oidcpy(&oid, entry.oid);
+                       oidcpy(&oid, &entry.oid);
                else if (S_ISGITLINK(entry.mode)) {
                        struct commit *commit;
 
-                       commit = lookup_commit(r, entry.oid);
+                       commit = lookup_commit(r, &entry.oid);
                        if (!commit)
                                die("Commit %s in submodule path %s%s not found",
-                                   oid_to_hex(entry.oid),
+                                   oid_to_hex(&entry.oid),
                                    base->buf, entry.path);
 
                        if (parse_commit(commit))
                                die("Invalid commit %s in submodule path %s%s",
-                                   oid_to_hex(entry.oid),
+                                   oid_to_hex(&entry.oid),
                                    base->buf, entry.path);
 
                        oidcpy(&oid, get_commit_tree_oid(commit));
index 94265a7df0fe78e49b720b7514d0457645f9ff05..3563daae1aa6bceb4f7a4715ee574e1359622239 100644 (file)
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "argv-array.h"
 #include "repository.h"
@@ -679,7 +678,7 @@ static int switch_cache_bottom(struct traverse_info *info)
 
 static inline int are_same_oid(struct name_entry *name_j, struct name_entry *name_k)
 {
-       return name_j->oid && name_k->oid && oideq(name_j->oid, name_k->oid);
+       return !is_null_oid(&name_j->oid) && !is_null_oid(&name_k->oid) && oideq(&name_j->oid, &name_k->oid);
 }
 
 static int all_trees_same_as_cache_tree(int n, unsigned long dirmask,
@@ -857,7 +856,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
                else {
                        const struct object_id *oid = NULL;
                        if (dirmask & 1)
-                               oid = names[i].oid;
+                               oid = &names[i].oid;
                        buf[nr_buf++] = fill_tree_descriptor(t + i, oid);
                }
        }
@@ -981,7 +980,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info,
        ce->ce_mode = create_ce_mode(n->mode);
        ce->ce_flags = create_ce_flags(stage);
        ce->ce_namelen = len;
-       oidcpy(&ce->oid, n->oid);
+       oidcpy(&ce->oid, &n->oid);
        make_traverse_path(ce->name, info, n);
 
        return ce;
index 5e81f1ff24f141fc5357522cb0745c7ff0aeb189..d098ef598289d16956309cb73d4518a92c1206af 100644 (file)
@@ -43,7 +43,6 @@
 
 static timestamp_t oldest_have;
 
-static int deepen_relative;
 static int multi_ack;
 static int no_done;
 static int use_thin_pack, use_ofs_delta, use_include_tag;
@@ -71,6 +70,8 @@ static int allow_filter;
 static int allow_ref_in_want;
 static struct list_objects_filter_options filter_options;
 
+static int allow_sideband_all;
+
 static void reset_timeout(void)
 {
        alarm(timeout);
@@ -140,14 +141,17 @@ static void create_pack_file(const struct object_array *have_obj,
        if (use_include_tag)
                argv_array_push(&pack_objects.args, "--include-tag");
        if (filter_options.filter_spec) {
+               struct strbuf expanded_filter_spec = STRBUF_INIT;
+               expand_list_objects_filter_spec(&filter_options,
+                                               &expanded_filter_spec);
                if (pack_objects.use_shell) {
                        struct strbuf buf = STRBUF_INIT;
-                       sq_quote_buf(&buf, filter_options.filter_spec);
+                       sq_quote_buf(&buf, expanded_filter_spec.buf);
                        argv_array_pushf(&pack_objects.args, "--filter=%s", buf.buf);
                        strbuf_release(&buf);
                } else {
                        argv_array_pushf(&pack_objects.args, "--filter=%s",
-                                        filter_options.filter_spec);
+                                        expanded_filter_spec.buf);
                }
        }
 
@@ -354,7 +358,8 @@ static int ok_to_give_up(const struct object_array *have_obj,
                                            min_generation);
 }
 
-static int get_common_commits(struct object_array *have_obj,
+static int get_common_commits(struct packet_reader *reader,
+                             struct object_array *have_obj,
                              struct object_array *want_obj)
 {
        struct object_id oid;
@@ -366,12 +371,11 @@ static int get_common_commits(struct object_array *have_obj,
        save_commit_buffer = 0;
 
        for (;;) {
-               char *line = packet_read_line(0, NULL);
                const char *arg;
 
                reset_timeout();
 
-               if (!line) {
+               if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
                        if (multi_ack == 2 && got_common
                            && !got_other && ok_to_give_up(have_obj, want_obj)) {
                                sent_ready = 1;
@@ -390,7 +394,7 @@ static int get_common_commits(struct object_array *have_obj,
                        got_other = 0;
                        continue;
                }
-               if (skip_prefix(line, "have ", &arg)) {
+               if (skip_prefix(reader->line, "have ", &arg)) {
                        switch (got_oid(arg, &oid, have_obj)) {
                        case -1: /* they have what we do not */
                                got_other = 1;
@@ -416,7 +420,7 @@ static int get_common_commits(struct object_array *have_obj,
                        }
                        continue;
                }
-               if (!strcmp(line, "done")) {
+               if (!strcmp(reader->line, "done")) {
                        if (have_obj->nr > 0) {
                                if (multi_ack)
                                        packet_write_fmt(1, "ACK %s\n", last_hex);
@@ -425,7 +429,7 @@ static int get_common_commits(struct object_array *have_obj,
                        packet_write_fmt(1, "NAK\n");
                        return -1;
                }
-               die("git upload-pack: expected SHA1 list, got '%s'", line);
+               die("git upload-pack: expected SHA1 list, got '%s'", reader->line);
        }
 }
 
@@ -613,13 +617,14 @@ static void check_non_tip(struct object_array *want_obj)
        }
 }
 
-static void send_shallow(struct commit_list *result)
+static void send_shallow(struct packet_writer *writer,
+                        struct commit_list *result)
 {
        while (result) {
                struct object *object = &result->item->object;
                if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
-                       packet_write_fmt(1, "shallow %s",
-                                        oid_to_hex(&object->oid));
+                       packet_writer_write(writer, "shallow %s",
+                                           oid_to_hex(&object->oid));
                        register_shallow(the_repository, &object->oid);
                        shallow_nr++;
                }
@@ -627,7 +632,8 @@ static void send_shallow(struct commit_list *result)
        }
 }
 
-static void send_unshallow(const struct object_array *shallows,
+static void send_unshallow(struct packet_writer *writer,
+                          const struct object_array *shallows,
                           struct object_array *want_obj)
 {
        int i;
@@ -636,8 +642,8 @@ static void send_unshallow(const struct object_array *shallows,
                struct object *object = shallows->objects[i].item;
                if (object->flags & NOT_SHALLOW) {
                        struct commit_list *parents;
-                       packet_write_fmt(1, "unshallow %s",
-                                        oid_to_hex(&object->oid));
+                       packet_writer_write(writer, "unshallow %s",
+                                           oid_to_hex(&object->oid));
                        object->flags &= ~CLIENT_SHALLOW;
                        /*
                         * We want to _register_ "object" as shallow, but we
@@ -662,7 +668,9 @@ static void send_unshallow(const struct object_array *shallows,
        }
 }
 
-static void deepen(int depth, int deepen_relative,
+static int check_ref(const char *refname_full, const struct object_id *oid,
+                    int flag, void *cb_data);
+static void deepen(struct packet_writer *writer, int depth, int deepen_relative,
                   struct object_array *shallows, struct object_array *want_obj)
 {
        if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) {
@@ -676,11 +684,18 @@ static void deepen(int depth, int deepen_relative,
                struct object_array reachable_shallows = OBJECT_ARRAY_INIT;
                struct commit_list *result;
 
+               /*
+                * Checking for reachable shallows requires that our refs be
+                * marked with OUR_REF.
+                */
+               head_ref_namespaced(check_ref, NULL);
+               for_each_namespaced_ref(check_ref, NULL);
+
                get_reachable_list(shallows, &reachable_shallows);
                result = get_shallow_commits(&reachable_shallows,
                                             depth + 1,
                                             SHALLOW, NOT_SHALLOW);
-               send_shallow(result);
+               send_shallow(writer, result);
                free_commit_list(result);
                object_array_clear(&reachable_shallows);
        } else {
@@ -688,14 +703,15 @@ static void deepen(int depth, int deepen_relative,
 
                result = get_shallow_commits(want_obj, depth,
                                             SHALLOW, NOT_SHALLOW);
-               send_shallow(result);
+               send_shallow(writer, result);
                free_commit_list(result);
        }
 
-       send_unshallow(shallows, want_obj);
+       send_unshallow(writer, shallows, want_obj);
 }
 
-static void deepen_by_rev_list(int ac, const char **av,
+static void deepen_by_rev_list(struct packet_writer *writer, int ac,
+                              const char **av,
                               struct object_array *shallows,
                               struct object_array *want_obj)
 {
@@ -703,15 +719,17 @@ static void deepen_by_rev_list(int ac, const char **av,
 
        close_commit_graph(the_repository);
        result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
-       send_shallow(result);
+       send_shallow(writer, result);
        free_commit_list(result);
-       send_unshallow(shallows, want_obj);
+       send_unshallow(writer, shallows, want_obj);
 }
 
 /* Returns 1 if a shallow list is sent or 0 otherwise */
-static int send_shallow_list(int depth, int deepen_rev_list,
+static int send_shallow_list(struct packet_writer *writer,
+                            int depth, int deepen_rev_list,
                             timestamp_t deepen_since,
                             struct string_list *deepen_not,
+                            int deepen_relative,
                             struct object_array *shallows,
                             struct object_array *want_obj)
 {
@@ -720,7 +738,7 @@ static int send_shallow_list(int depth, int deepen_rev_list,
        if (depth > 0 && deepen_rev_list)
                die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together");
        if (depth > 0) {
-               deepen(depth, deepen_relative, shallows, want_obj);
+               deepen(writer, depth, deepen_relative, shallows, want_obj);
                ret = 1;
        } else if (deepen_rev_list) {
                struct argv_array av = ARGV_ARRAY_INIT;
@@ -741,7 +759,7 @@ static int send_shallow_list(int depth, int deepen_rev_list,
                        struct object *o = want_obj->objects[i].item;
                        argv_array_push(&av, oid_to_hex(&o->oid));
                }
-               deepen_by_rev_list(av.argc, av.argv, shallows, want_obj);
+               deepen_by_rev_list(writer, av.argc, av.argv, shallows, want_obj);
                argv_array_clear(&av);
                ret = 1;
        } else {
@@ -826,7 +844,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
        return 0;
 }
 
-static void receive_needs(struct object_array *want_obj)
+static void receive_needs(struct packet_reader *reader, struct object_array *want_obj)
 {
        struct object_array shallows = OBJECT_ARRAY_INIT;
        struct string_list deepen_not = STRING_LIST_INIT_DUP;
@@ -834,39 +852,41 @@ static void receive_needs(struct object_array *want_obj)
        int has_non_tip = 0;
        timestamp_t deepen_since = 0;
        int deepen_rev_list = 0;
+       int deepen_relative = 0;
+       struct packet_writer writer;
 
        shallow_nr = 0;
+       packet_writer_init(&writer, 1);
        for (;;) {
                struct object *o;
                const char *features;
                struct object_id oid_buf;
-               char *line = packet_read_line(0, NULL);
                const char *arg;
 
                reset_timeout();
-               if (!line)
+               if (packet_reader_read(reader) != PACKET_READ_NORMAL)
                        break;
 
-               if (process_shallow(line, &shallows))
+               if (process_shallow(reader->line, &shallows))
                        continue;
-               if (process_deepen(line, &depth))
+               if (process_deepen(reader->line, &depth))
                        continue;
-               if (process_deepen_since(line, &deepen_since, &deepen_rev_list))
+               if (process_deepen_since(reader->line, &deepen_since, &deepen_rev_list))
                        continue;
-               if (process_deepen_not(line, &deepen_not, &deepen_rev_list))
+               if (process_deepen_not(reader->line, &deepen_not, &deepen_rev_list))
                        continue;
 
-               if (skip_prefix(line, "filter ", &arg)) {
+               if (skip_prefix(reader->line, "filter ", &arg)) {
                        if (!filter_capability_requested)
                                die("git upload-pack: filtering capability not negotiated");
                        parse_list_objects_filter(&filter_options, arg);
                        continue;
                }
 
-               if (!skip_prefix(line, "want ", &arg) ||
+               if (!skip_prefix(reader->line, "want ", &arg) ||
                    parse_oid_hex(arg, &oid_buf, &features))
                        die("git upload-pack: protocol error, "
-                           "expected to get object ID, not '%s'", line);
+                           "expected to get object ID, not '%s'", reader->line);
 
                if (parse_feature_request(features, "deepen-relative"))
                        deepen_relative = 1;
@@ -893,9 +913,9 @@ static void receive_needs(struct object_array *want_obj)
 
                o = parse_object(the_repository, &oid_buf);
                if (!o) {
-                       packet_write_fmt(1,
-                                        "ERR upload-pack: not our ref %s",
-                                        oid_to_hex(&oid_buf));
+                       packet_writer_error(&writer,
+                                           "upload-pack: not our ref %s",
+                                           oid_to_hex(&oid_buf));
                        die("git upload-pack: not our ref %s",
                            oid_to_hex(&oid_buf));
                }
@@ -924,8 +944,9 @@ static void receive_needs(struct object_array *want_obj)
        if (depth == 0 && !deepen_rev_list && shallows.nr == 0)
                return;
 
-       if (send_shallow_list(depth, deepen_rev_list, deepen_since,
-                             &deepen_not, &shallows, want_obj))
+       if (send_shallow_list(&writer, depth, deepen_rev_list, deepen_since,
+                             &deepen_not, deepen_relative, &shallows,
+                             want_obj))
                packet_flush(1);
        object_array_clear(&shallows);
 }
@@ -1041,6 +1062,8 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
                allow_filter = git_config_bool(var, value);
        } else if (!strcmp("uploadpack.allowrefinwant", var)) {
                allow_ref_in_want = git_config_bool(var, value);
+       } else if (!strcmp("uploadpack.allowsidebandall", var)) {
+               allow_sideband_all = git_config_bool(var, value);
        }
 
        if (current_config_scope() != CONFIG_SCOPE_REPO) {
@@ -1055,6 +1078,7 @@ void upload_pack(struct upload_pack_options *options)
 {
        struct string_list symref = STRING_LIST_INIT_DUP;
        struct object_array want_obj = OBJECT_ARRAY_INIT;
+       struct packet_reader reader;
 
        stateless_rpc = options->stateless_rpc;
        timeout = options->timeout;
@@ -1078,10 +1102,14 @@ void upload_pack(struct upload_pack_options *options)
        if (options->advertise_refs)
                return;
 
-       receive_needs(&want_obj);
+       packet_reader_init(&reader, 0, NULL, 0,
+                          PACKET_READ_CHOMP_NEWLINE |
+                          PACKET_READ_DIE_ON_ERR_PACKET);
+
+       receive_needs(&reader, &want_obj);
        if (want_obj.nr) {
                struct object_array have_obj = OBJECT_ARRAY_INIT;
-               get_common_commits(&have_obj, &want_obj);
+               get_common_commits(&reader, &have_obj, &want_obj);
                create_pack_file(&have_obj, &want_obj);
        }
 }
@@ -1098,6 +1126,8 @@ struct upload_pack_data {
        int deepen_rev_list;
        int deepen_relative;
 
+       struct packet_writer writer;
+
        unsigned stateless_rpc : 1;
 
        unsigned use_thin_pack : 1;
@@ -1121,6 +1151,7 @@ static void upload_pack_data_init(struct upload_pack_data *data)
        data->haves = haves;
        data->shallows = shallows;
        data->deepen_not = deepen_not;
+       packet_writer_init(&data->writer, 1);
 }
 
 static void upload_pack_data_clear(struct upload_pack_data *data)
@@ -1132,7 +1163,8 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
        string_list_clear(&data->deepen_not, 0);
 }
 
-static int parse_want(const char *line, struct object_array *want_obj)
+static int parse_want(struct packet_writer *writer, const char *line,
+                     struct object_array *want_obj)
 {
        const char *arg;
        if (skip_prefix(line, "want ", &arg)) {
@@ -1145,9 +1177,9 @@ static int parse_want(const char *line, struct object_array *want_obj)
 
                o = parse_object(the_repository, &oid);
                if (!o) {
-                       packet_write_fmt(1,
-                                        "ERR upload-pack: not our ref %s",
-                                        oid_to_hex(&oid));
+                       packet_writer_error(writer,
+                                           "upload-pack: not our ref %s",
+                                           oid_to_hex(&oid));
                        die("git upload-pack: not our ref %s",
                            oid_to_hex(&oid));
                }
@@ -1163,7 +1195,8 @@ static int parse_want(const char *line, struct object_array *want_obj)
        return 0;
 }
 
-static int parse_want_ref(const char *line, struct string_list *wanted_refs,
+static int parse_want_ref(struct packet_writer *writer, const char *line,
+                         struct string_list *wanted_refs,
                          struct object_array *want_obj)
 {
        const char *arg;
@@ -1173,7 +1206,7 @@ static int parse_want_ref(const char *line, struct string_list *wanted_refs,
                struct object *o;
 
                if (read_ref(arg, &oid)) {
-                       packet_write_fmt(1, "ERR unknown ref %s", arg);
+                       packet_writer_error(writer, "unknown ref %s", arg);
                        die("unknown ref %s", arg);
                }
 
@@ -1216,10 +1249,11 @@ static void process_args(struct packet_reader *request,
                const char *p;
 
                /* process want */
-               if (parse_want(arg, want_obj))
+               if (parse_want(&data->writer, arg, want_obj))
                        continue;
                if (allow_ref_in_want &&
-                   parse_want_ref(arg, &data->wanted_refs, want_obj))
+                   parse_want_ref(&data->writer, arg, &data->wanted_refs,
+                                  want_obj))
                        continue;
                /* process have line */
                if (parse_have(arg, &data->haves))
@@ -1268,6 +1302,13 @@ static void process_args(struct packet_reader *request,
                        continue;
                }
 
+               if ((git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
+                    allow_sideband_all) &&
+                   !strcmp(arg, "sideband-all")) {
+                       data->writer.use_sideband = 1;
+                       continue;
+               }
+
                /* ignore unknown lines maybe? */
                die("unexpected line: '%s'", arg);
        }
@@ -1313,26 +1354,26 @@ static int process_haves(struct oid_array *haves, struct oid_array *common,
        return 0;
 }
 
-static int send_acks(struct oid_array *acks, struct strbuf *response,
+static int send_acks(struct packet_writer *writer, struct oid_array *acks,
                     const struct object_array *have_obj,
                     struct object_array *want_obj)
 {
        int i;
 
-       packet_buf_write(response, "acknowledgments\n");
+       packet_writer_write(writer, "acknowledgments\n");
 
        /* Send Acks */
        if (!acks->nr)
-               packet_buf_write(response, "NAK\n");
+               packet_writer_write(writer, "NAK\n");
 
        for (i = 0; i < acks->nr; i++) {
-               packet_buf_write(response, "ACK %s\n",
-                                oid_to_hex(&acks->oid[i]));
+               packet_writer_write(writer, "ACK %s\n",
+                                   oid_to_hex(&acks->oid[i]));
        }
 
        if (ok_to_give_up(have_obj, want_obj)) {
                /* Send Ready */
-               packet_buf_write(response, "ready\n");
+               packet_writer_write(writer, "ready\n");
                return 1;
        }
 
@@ -1344,25 +1385,20 @@ static int process_haves_and_send_acks(struct upload_pack_data *data,
                                       struct object_array *want_obj)
 {
        struct oid_array common = OID_ARRAY_INIT;
-       struct strbuf response = STRBUF_INIT;
        int ret = 0;
 
        process_haves(&data->haves, &common, have_obj);
        if (data->done) {
                ret = 1;
-       } else if (send_acks(&common, &response, have_obj, want_obj)) {
-               packet_buf_delim(&response);
+       } else if (send_acks(&data->writer, &common, have_obj, want_obj)) {
+               packet_writer_delim(&data->writer);
                ret = 1;
        } else {
                /* Add Flush */
-               packet_buf_flush(&response);
+               packet_writer_flush(&data->writer);
                ret = 0;
        }
 
-       /* Send response */
-       write_or_die(1, response.buf, response.len);
-       strbuf_release(&response);
-
        oid_array_clear(&data->haves);
        oid_array_clear(&common);
        return ret;
@@ -1375,15 +1411,15 @@ static void send_wanted_ref_info(struct upload_pack_data *data)
        if (!data->wanted_refs.nr)
                return;
 
-       packet_write_fmt(1, "wanted-refs\n");
+       packet_writer_write(&data->writer, "wanted-refs\n");
 
        for_each_string_list_item(item, &data->wanted_refs) {
-               packet_write_fmt(1, "%s %s\n",
-                                oid_to_hex(item->util),
-                                item->string);
+               packet_writer_write(&data->writer, "%s %s\n",
+                                   oid_to_hex(item->util),
+                                   item->string);
        }
 
-       packet_delim(1);
+       packet_writer_delim(&data->writer);
 }
 
 static void send_shallow_info(struct upload_pack_data *data,
@@ -1394,14 +1430,16 @@ static void send_shallow_info(struct upload_pack_data *data,
            !is_repository_shallow(the_repository))
                return;
 
-       packet_write_fmt(1, "shallow-info\n");
+       packet_writer_write(&data->writer, "shallow-info\n");
 
-       if (!send_shallow_list(data->depth, data->deepen_rev_list,
+       if (!send_shallow_list(&data->writer, data->depth,
+                              data->deepen_rev_list,
                               data->deepen_since, &data->deepen_not,
+                              data->deepen_relative,
                               &data->shallows, want_obj) &&
            is_repository_shallow(the_repository))
-               deepen(INFINITE_DEPTH, data->deepen_relative, &data->shallows,
-                      want_obj);
+               deepen(&data->writer, INFINITE_DEPTH, data->deepen_relative,
+                      &data->shallows, want_obj);
 
        packet_delim(1);
 }
@@ -1463,7 +1501,7 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
                        send_wanted_ref_info(&data);
                        send_shallow_info(&data, &want_obj);
 
-                       packet_write_fmt(1, "packfile\n");
+                       packet_writer_write(&data.writer, "packfile\n");
                        create_pack_file(&have_obj, &want_obj);
                        state = FETCH_DONE;
                        break;
@@ -1484,6 +1522,7 @@ int upload_pack_advertise(struct repository *r,
        if (value) {
                int allow_filter_value;
                int allow_ref_in_want;
+               int allow_sideband_all_value;
 
                strbuf_addstr(value, "shallow");
 
@@ -1498,6 +1537,13 @@ int upload_pack_advertise(struct repository *r,
                                         &allow_ref_in_want) &&
                    allow_ref_in_want)
                        strbuf_addstr(value, " ref-in-want");
+
+               if (git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
+                   (!repo_config_get_bool(the_repository,
+                                          "uploadpack.allowsidebandall",
+                                          &allow_sideband_all_value) &&
+                    allow_sideband_all_value))
+                       strbuf_addstr(value, " sideband-all");
        }
 
        return 1;
diff --git a/utf8.c b/utf8.c
index eb785875042920b84e56abbd235ef9eb7ef22ac4..83824dc2f4ab151a19418c61c46e0c1ffbb0e42c 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -4,6 +4,11 @@
 
 /* This code is originally from http://www.cl.cam.ac.uk/~mgk25/ucs/ */
 
+static const char utf16_be_bom[] = {'\xFE', '\xFF'};
+static const char utf16_le_bom[] = {'\xFF', '\xFE'};
+static const char utf32_be_bom[] = {'\0', '\0', '\xFE', '\xFF'};
+static const char utf32_le_bom[] = {'\xFF', '\xFE', '\0', '\0'};
+
 struct interval {
        ucs_char_t first;
        ucs_char_t last;
@@ -470,16 +475,17 @@ int utf8_fprintf(FILE *stream, const char *format, ...)
 #else
        typedef char * iconv_ibp;
 #endif
-char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv, size_t *outsz_p)
+char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv,
+                           size_t bom_len, size_t *outsz_p)
 {
        size_t outsz, outalloc;
        char *out, *outpos;
        iconv_ibp cp;
 
        outsz = insz;
-       outalloc = st_add(outsz, 1); /* for terminating NUL */
+       outalloc = st_add(outsz, 1 + bom_len); /* for terminating NUL */
        out = xmalloc(outalloc);
-       outpos = out;
+       outpos = out + bom_len;
        cp = (iconv_ibp)in;
 
        while (1) {
@@ -540,10 +546,30 @@ char *reencode_string_len(const char *in, size_t insz,
 {
        iconv_t conv;
        char *out;
+       const char *bom_str = NULL;
+       size_t bom_len = 0;
 
        if (!in_encoding)
                return NULL;
 
+       /* UTF-16LE-BOM is the same as UTF-16 for reading */
+       if (same_utf_encoding("UTF-16LE-BOM", in_encoding))
+               in_encoding = "UTF-16";
+
+       /*
+        * For writing, UTF-16 iconv typically creates "UTF-16BE-BOM"
+        * Some users under Windows want the little endian version
+        */
+       if (same_utf_encoding("UTF-16LE-BOM", out_encoding)) {
+               bom_str = utf16_le_bom;
+               bom_len = sizeof(utf16_le_bom);
+               out_encoding = "UTF-16LE";
+       } else if (same_utf_encoding("UTF-16BE-BOM", out_encoding)) {
+               bom_str = utf16_be_bom;
+               bom_len = sizeof(utf16_be_bom);
+               out_encoding = "UTF-16BE";
+       }
+
        conv = iconv_open(out_encoding, in_encoding);
        if (conv == (iconv_t) -1) {
                in_encoding = fallback_encoding(in_encoding);
@@ -553,9 +579,10 @@ char *reencode_string_len(const char *in, size_t insz,
                if (conv == (iconv_t) -1)
                        return NULL;
        }
-
-       out = reencode_string_iconv(in, insz, conv, outsz);
+       out = reencode_string_iconv(in, insz, conv, bom_len, outsz);
        iconv_close(conv);
+       if (out && bom_str && bom_len)
+               memcpy(out, bom_str, bom_len);
        return out;
 }
 #endif
@@ -566,11 +593,6 @@ static int has_bom_prefix(const char *data, size_t len,
        return data && bom && (len >= bom_len) && !memcmp(data, bom, bom_len);
 }
 
-static const char utf16_be_bom[] = {'\xFE', '\xFF'};
-static const char utf16_le_bom[] = {'\xFF', '\xFE'};
-static const char utf32_be_bom[] = {'\0', '\0', '\xFE', '\xFF'};
-static const char utf32_le_bom[] = {'\xFF', '\xFE', '\0', '\0'};
-
 int has_prohibited_utf_bom(const char *enc, const char *data, size_t len)
 {
        return (
diff --git a/utf8.h b/utf8.h
index edea55e093a4713dcd0056da9a31b63f0cb51272..84efbfcb1fa163b5b799add81b4464ff6eb88611 100644 (file)
--- a/utf8.h
+++ b/utf8.h
@@ -27,7 +27,7 @@ void strbuf_utf8_replace(struct strbuf *sb, int pos, int width,
 
 #ifndef NO_ICONV
 char *reencode_string_iconv(const char *in, size_t insz,
-                           iconv_t conv, size_t *outsz);
+                           iconv_t conv, size_t bom_len, size_t *outsz);
 char *reencode_string_len(const char *in, size_t insz,
                          const char *out_encoding,
                          const char *in_encoding,
index 96990d84dabfdd34e169c8e9fcfd656633e4f31e..d74ae59c77fb3626be0af291c6ee6fbb9c52dbb1 100644 (file)
--- a/walker.c
+++ b/walker.c
@@ -50,13 +50,13 @@ static int process_tree(struct walker *walker, struct tree *tree)
                        continue;
                if (S_ISDIR(entry.mode)) {
                        struct tree *tree = lookup_tree(the_repository,
-                                                       entry.oid);
+                                                       &entry.oid);
                        if (tree)
                                obj = &tree->object;
                }
                else {
                        struct blob *blob = lookup_blob(the_repository,
-                                                       entry.oid);
+                                                       &entry.oid);
                        if (blob)
                                obj = &blob->object;
                }
index e4fa9d84cd076770306114ff4f284155a5cdd2a1..ea3cf64d4c399ae84c156b850002459a8ffde72c 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -690,3 +690,16 @@ int xgethostname(char *buf, size_t len)
                buf[len - 1] = 0;
        return ret;
 }
+
+int is_empty_or_missing_file(const char *filename)
+{
+       struct stat st;
+
+       if (stat(filename, &st) < 0) {
+               if (errno == ENOENT)
+                       return 1;
+               die_errno(_("could not stat %s"), filename);
+       }
+
+       return !st.st_size;
+}
index 0fe3bcd4cd057b72a61cfc6d46e892ac890f0634..1f564b12d259956fa71fb0dce78c6e4c3c006897 100644 (file)
@@ -2375,10 +2375,10 @@ int require_clean_work_tree(struct repository *r,
        struct lock_file lock_file = LOCK_INIT;
        int err = 0, fd;
 
-       fd = hold_locked_index(&lock_file, 0);
+       fd = repo_hold_locked_index(r, &lock_file, 0);
        refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
        if (0 <= fd)
-               update_index_if_able(r->index, &lock_file);
+               repo_update_index_if_able(r, &lock_file);
        rollback_lock_file(&lock_file);
 
        if (has_unstaged_changes(r, ignore_submodules)) {