Merge branch 'js/chain-lint-attrfix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 20 Aug 2018 18:33:54 +0000 (11:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Aug 2018 18:33:54 +0000 (11:33 -0700)
Test fix.

* js/chain-lint-attrfix:
chainlint: fix for core.autocrlf=true

479 files changed:
.gitignore
.mailmap
Documentation/.gitignore
Documentation/RelNotes/2.19.0.txt
Documentation/SubmittingPatches
Documentation/config.txt
Documentation/diff-options.txt
Documentation/doc-diff [new file with mode: 0755]
Documentation/fetch-options.txt
Documentation/git-bisect-lk2009.txt
Documentation/git-branch.txt
Documentation/git-cat-file.txt
Documentation/git-checkout.txt
Documentation/git-commit-graph.txt
Documentation/git-for-each-ref.txt
Documentation/git-fsck.txt
Documentation/git-gc.txt
Documentation/git-grep.txt
Documentation/git-imap-send.txt
Documentation/git-interpret-trailers.txt
Documentation/git-merge.txt
Documentation/git-notes.txt
Documentation/git-p4.txt
Documentation/git-range-diff.txt [new file with mode: 0644]
Documentation/git-rebase.txt
Documentation/git-send-email.txt
Documentation/git-status.txt
Documentation/git-svn.txt
Documentation/git-tag.txt
Documentation/git-update-index.txt
Documentation/git-worktree.txt
Documentation/giteveryday.txt
Documentation/githooks.txt
Documentation/gitignore.txt
Documentation/gitsubmodules.txt
Documentation/glossary-content.txt
Documentation/pull-fetch-param.txt
Documentation/revisions.txt
Documentation/technical/api-directory-listing.txt
Documentation/technical/api-gitattributes.txt
Documentation/technical/commit-graph-format.txt
Documentation/technical/commit-graph.txt
Documentation/technical/directory-rename-detection.txt [new file with mode: 0644]
Documentation/technical/hash-function-transition.txt
Documentation/technical/http-protocol.txt
Documentation/technical/pack-protocol.txt
Documentation/technical/protocol-v2.txt
Makefile
advice.c
advice.h
apply.c
apply.h
archive-tar.c
archive-zip.c
archive.c
archive.h
attr.c
attr.h
banned.h [new file with mode: 0644]
bisect.c
blame.c
blame.h
blob.c
blob.h
branch.c
builtin.h
builtin/add.c
builtin/am.c
builtin/apply.c
builtin/archive.c
builtin/blame.c
builtin/branch.c
builtin/cat-file.c
builtin/check-attr.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clean.c
builtin/clone.c
builtin/commit-graph.c
builtin/commit-tree.c
builtin/commit.c
builtin/config.c
builtin/describe.c
builtin/diff-tree.c
builtin/diff.c
builtin/difftool.c
builtin/fast-export.c
builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/fsck.c
builtin/gc.c
builtin/grep.c
builtin/hash-object.c
builtin/index-pack.c
builtin/init-db.c
builtin/log.c
builtin/ls-files.c
builtin/ls-tree.c
builtin/merge-base.c
builtin/merge-recursive.c
builtin/merge-tree.c
builtin/merge.c
builtin/mktag.c
builtin/mktree.c
builtin/name-rev.c
builtin/notes.c
builtin/pack-objects.c
builtin/prune-packed.c
builtin/prune.c
builtin/pull.c
builtin/push.c
builtin/range-diff.c [new file with mode: 0644]
builtin/read-tree.c
builtin/receive-pack.c
builtin/reflog.c
builtin/remote.c
builtin/replace.c
builtin/reset.c
builtin/rev-list.c
builtin/rev-parse.c
builtin/rm.c
builtin/send-pack.c
builtin/shortlog.c
builtin/show-branch.c
builtin/show-ref.c
builtin/submodule--helper.c
builtin/tag.c
builtin/unpack-file.c
builtin/unpack-objects.c
builtin/update-index.c
builtin/upload-archive.c
builtin/upload-pack.c
builtin/verify-commit.c
builtin/worktree.c
builtin/write-tree.c
bulk-checkin.c
bundle.c
cache-tree.c
cache-tree.h
cache.h
checkout.c
checkout.h
ci/lib-travisci.sh
ci/print-test-failures.sh
ci/run-static-analysis.sh
ci/util/extract-trash-dirs.sh [new file with mode: 0755]
color.c
color.h
combine-diff.c
command-list.txt
commit-graph.c
commit-graph.h
commit-slab-impl.h
commit.c
commit.h
compat/mingw.c
compat/vcbuild/README
config.c
config.h
config.mak.dev
config.mak.uname
connect.c
connect.h
connected.c
connected.h
contrib/coccinelle/commit.cocci
contrib/completion/git-completion.bash
contrib/git-jump/README
contrib/git-jump/git-jump
contrib/mw-to-git/t/t9360-mw-to-git-clone.sh
contrib/subtree/t/t7900-subtree.sh
contrib/vscode/.gitattributes [new file with mode: 0644]
contrib/vscode/README.md [new file with mode: 0644]
contrib/vscode/init.sh [new file with mode: 0755]
convert.c
convert.h
diff-lib.c
diff.c
diff.h
diffcore-rename.c
diffcore.h
dir.c
dir.h
entry.c
environment.c
ewah/bitmap.c
ewah/ewah_bitmap.c
ewah/ewah_io.c
ewah/ewah_rlw.c
ewah/ewok.h
ewah/ewok_rlw.h
exec-cmd.c
fast-import.c
fetch-negotiator.c [new file with mode: 0644]
fetch-negotiator.h [new file with mode: 0644]
fetch-pack.c
fetch-pack.h
fsck.c
git-compat-util.h
git-filter-branch.sh
git-instaweb.sh
git-mergetool.sh
git-p4.py
git-rebase--merge.sh
git-rebase--preserve-merges.sh
git-rebase.sh
git-send-email.perl
git-submodule.sh
git.c
gpg-interface.c
gpg-interface.h
grep.c
grep.h
help.c
hex.c
http-backend.c
http-push.c
json-writer.c [new file with mode: 0644]
json-writer.h [new file with mode: 0644]
line-log.c
line-range.c
line-range.h
linear-assignment.c [new file with mode: 0644]
linear-assignment.h [new file with mode: 0644]
list-objects-filter.c
list-objects.c
ll-merge.c
log-tree.c
mailmap.c
match-trees.c
mem-pool.c
mem-pool.h
merge-blobs.c
merge-recursive.c
merge.c
negotiator/default.c [new file with mode: 0644]
negotiator/default.h [new file with mode: 0644]
negotiator/skipping.c [new file with mode: 0644]
negotiator/skipping.h [new file with mode: 0644]
notes-cache.c
notes-merge.c
notes-utils.c
notes.c
object-store.h
object.c
object.h
pack-bitmap-write.c
pack-bitmap.c
pack-bitmap.h
packfile.c
packfile.h
parse-options-cb.c
parse-options.c
path.c
path.h
pathspec.c
pkt-line.c
preload-index.c
pretty.c
range-diff.c [new file with mode: 0644]
range-diff.h [new file with mode: 0644]
reachable.c
read-cache.c
ref-filter.c
reflog-walk.c
refs.c
refs/files-backend.c
refs/refs-internal.h
refspec.c
remote-curl.c
remote-testsvn.c
remote.c
remote.h
replace-object.c
replace-object.h
repository.h
rerere.c
rerere.h
resolve-undo.c
revision.c
revision.h
send-pack.c
sequencer.c
server-info.c
sha1-file.c
sha1-name.c
sha1collisiondetection
sha1dc/sha1.c
shallow.c
split-index.c
strbuf.c
string-list.c
submodule-config.c
submodule-config.h
submodule.c
submodule.h
t/.gitattributes
t/annotate-tests.sh
t/chainlint.sed
t/chainlint/here-doc-close-subshell.expect [new file with mode: 0644]
t/chainlint/here-doc-close-subshell.test [new file with mode: 0644]
t/chainlint/here-doc-multi-line-command-subst.expect [new file with mode: 0644]
t/chainlint/here-doc-multi-line-command-subst.test [new file with mode: 0644]
t/chainlint/here-doc-multi-line-string.expect [new file with mode: 0644]
t/chainlint/here-doc-multi-line-string.test [new file with mode: 0644]
t/chainlint/here-doc.expect
t/chainlint/here-doc.test
t/chainlint/multi-line-nested-command-substitution.expect
t/chainlint/multi-line-nested-command-substitution.test
t/chainlint/multi-line-string.expect
t/chainlint/multi-line-string.test
t/chainlint/nested-here-doc.expect
t/chainlint/nested-here-doc.test
t/chainlint/subshell-here-doc.expect
t/chainlint/subshell-here-doc.test
t/chainlint/t7900-subtree.expect [new file with mode: 0644]
t/chainlint/t7900-subtree.test [new file with mode: 0644]
t/check-non-portable-shell.pl
t/helper/test-drop-caches.c
t/helper/test-json-writer.c [new file with mode: 0644]
t/helper/test-pkt-line.c
t/helper/test-repository.c [new file with mode: 0644]
t/helper/test-tool.c
t/helper/test-tool.h
t/lib-gpg.sh
t/lib-gpg/gpgsm-gen-key.in [new file with mode: 0644]
t/lib-gpg/gpgsm_cert.p12 [new file with mode: 0644]
t/lib-httpd.sh
t/lib-httpd/apache.conf
t/lib-httpd/apply-one-time-sed.sh [new file with mode: 0644]
t/lib-submodule-update.sh
t/t0008-ignores.sh
t/t0019-json-writer.sh [new file with mode: 0755]
t/t0019/parse_json.perl [new file with mode: 0644]
t/t0021-conversion.sh
t/t0030-stripspace.sh
t/t0300-credentials.sh
t/t1006-cat-file.sh
t/t1011-read-tree-sparse-checkout.sh
t/t1015-read-index-unmerged.sh [new file with mode: 0755]
t/t1305-config-include.sh
t/t1306-xdg-files.sh
t/t1308-config-set.sh
t/t1400-update-ref.sh
t/t1403-show-ref.sh
t/t1404-update-ref-errors.sh
t/t1410-reflog.sh
t/t1450-fsck.sh
t/t1507-rev-parse-upstream.sh
t/t2024-checkout-dwim.sh
t/t2025-worktree-add.sh
t/t2202-add-addremove.sh
t/t3001-ls-files-others-exclude.sh
t/t3005-ls-files-relative.sh
t/t3031-merge-criscross.sh
t/t3035-merge-sparse.sh [new file with mode: 0755]
t/t3070-wildmatch.sh
t/t3200-branch.sh
t/t3201-branch-contains.sh
t/t3206-range-diff.sh [new file with mode: 0755]
t/t3206/history.export [new file with mode: 0644]
t/t3210-pack-refs.sh
t/t3310-notes-merge-manual-resolve.sh
t/t3401-rebase-and-am-rename.sh [new file with mode: 0755]
t/t3404-rebase-interactive.sh
t/t3405-rebase-malformed.sh
t/t3418-rebase-continue.sh
t/t3422-rebase-incompatible-options.sh [new file with mode: 0755]
t/t3423-rebase-reword.sh [new file with mode: 0755]
t/t3430-rebase-merges.sh
t/t3507-cherry-pick-conflict.sh
t/t3510-cherry-pick-sequence.sh
t/t3700-add.sh
t/t3910-mac-os-precompose.sh
t/t4010-diff-pathspec.sh
t/t4014-format-patch.sh
t/t4015-diff-whitespace.sh
t/t4018/php-abstract-class [new file with mode: 0644]
t/t4018/php-class [new file with mode: 0644]
t/t4018/php-final-class [new file with mode: 0644]
t/t4018/php-function [new file with mode: 0644]
t/t4018/php-interface [new file with mode: 0644]
t/t4018/php-method [new file with mode: 0644]
t/t4018/php-trait [new file with mode: 0644]
t/t4039-diff-assume-unchanged.sh
t/t4150-am.sh
t/t4200-rerere.sh
t/t4202-log.sh
t/t4208-log-magic-pathspec.sh
t/t4210-log-i18n.sh
t/t4211-line-log.sh
t/t5310-pack-bitmaps.sh
t/t5313-pack-bounds-checks.sh
t/t5317-pack-objects-filter-objects.sh
t/t5318-commit-graph.sh
t/t5407-post-rewrite-hook.sh
t/t5500-fetch-pack.sh
t/t5504-fetch-receive-strict.sh
t/t5505-remote.sh
t/t5510-fetch.sh
t/t5512-ls-remote.sh
t/t5514-fetch-multiple.sh
t/t5516-fetch-push.sh
t/t5520-pull.sh
t/t5533-push-cas.sh
t/t5534-push-signed.sh
t/t5537-fetch-shallow.sh
t/t5541-http-push-smart.sh
t/t5551-http-fetch-smart.sh
t/t5552-skipping-fetch-negotiator.sh [new file with mode: 0755]
t/t5561-http-backend.sh
t/t5562-http-backend-content-length.sh [new file with mode: 0755]
t/t5562/invoke-with-content-length.pl [new file with mode: 0755]
t/t5570-git-daemon.sh
t/t5612-clone-refspec.sh
t/t5616-partial-clone.sh
t/t5702-protocol-v2.sh
t/t5703-upload-pack-ref-in-want.sh [new file with mode: 0755]
t/t5801-remote-helpers.sh
t/t6000-rev-list-misc.sh
t/t6009-rev-list-parent.sh
t/t6018-rev-list-glob.sh
t/t6019-rev-list-ancestry-path.sh
t/t6020-merge-df.sh
t/t6022-merge-rename.sh
t/t6029-merge-subtree.sh
t/t6036-recursive-corner-cases.sh
t/t6042-merge-rename-corner-cases.sh
t/t6044-merge-unrelated-index-changes.sh
t/t6046-merge-skip-unneeded-updates.sh
t/t6050-replace.sh
t/t6060-merge-index.sh
t/t6300-for-each-ref.sh
t/t7003-filter-branch.sh
t/t7004-tag.sh
t/t7006-pager.sh
t/t7030-verify-tag.sh
t/t7063-status-untracked-cache.sh
t/t7102-reset.sh
t/t7106-reset-unborn-branch.sh
t/t7400-submodule-basic.sh
t/t7401-submodule-summary.sh
t/t7405-submodule-merge.sh
t/t7406-submodule-update.sh
t/t7415-submodule-names.sh
t/t7502-commit.sh
t/t7504-commit-msg-hook.sh
t/t7510-signed-commit.sh
t/t7610-mergetool.sh
t/t7611-merge-abort.sh
t/t7810-grep.sh
t/t8003-blame-corner-cases.sh
t/t9001-send-email.sh
t/t9300-fast-import.sh
t/t9800-git-p4-basic.sh
t/t9833-errors.sh
t/test-lib-functions.sh
tag.c
tag.h
transport-helper.c
transport.c
transport.h
tree-walk.c
tree.c
tree.h
unicode-width.h
unpack-trees.c
unpack-trees.h
upload-pack.c
userdiff.c
utf8.c
utf8.h
walker.c
ws.c
wt-status.c
xdiff-interface.c
xdiff/xdiff.h
xdiff/xdiffi.c
xdiff/xhistogram.c
index 3284a1e9b1e80eae619024258ea96bb7e33bf943..ffceea7d59fd21d5c5deed2c8d14f507bdbf1666 100644 (file)
 /git-pull
 /git-push
 /git-quiltimport
+/git-range-diff
 /git-read-tree
 /git-rebase
 /git-rebase--am
 /config.mak.autogen
 /config.mak.append
 /configure
+/.vscode/
 /tags
 /TAGS
 /cscope*
index df7cf6313c7dd0c5c065e448fd7c725ff537a08b..f165222a7821e982174adc8e1c3678275ae80753 100644 (file)
--- a/.mailmap
+++ b/.mailmap
@@ -35,11 +35,13 @@ Chris Wright <chrisw@sous-sol.org> <chrisw@osdl.org>
 Cord Seele <cowose@gmail.com> <cowose@googlemail.com>
 Christian Couder <chriscool@tuxfamily.org> <christian.couder@gmail.com>
 Christian Stimming <stimming@tuhh.de> <chs@ckiste.goetheallee>
+Christopher Díaz Riveros <chrisadr@gentoo.org> Christopher Diaz Riveros
 Csaba Henk <csaba@gluster.com> <csaba@lowlife.hu>
 Dan Johnson <computerdruid@gmail.com>
 Dana L. How <danahow@gmail.com> <how@deathvalley.cswitch.com>
 Dana L. How <danahow@gmail.com> Dana How
 Daniel Barkalow <barkalow@iabervon.org>
+Daniel Knittl-Frank <knittl89@googlemail.com> knittl
 Daniel Trstenjak <daniel.trstenjak@gmail.com> <daniel.trstenjak@online.de>
 Daniel Trstenjak <daniel.trstenjak@gmail.com> <trsten@science-computing.de>
 David Brown <git@davidb.org> <davidb@quicinc.com>
@@ -57,6 +59,7 @@ Eric S. Raymond <esr@thyrsus.com>
 Eric Wong <e@80x24.org> <normalperson@yhbt.net>
 Erik Faye-Lund <kusmabite@gmail.com> <kusmabite@googlemail.com>
 Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com> <eyvind-git@orakel.ntnu.no>
+Fangyi Zhou <fangyi.zhou@yuriko.moe> Zhou Fangyi
 Florian Achleitner <florian.achleitner.2.6.31@gmail.com> <florian.achleitner2.6.31@gmail.com>
 Franck Bui-Huu <vagabon.xyz@gmail.com> <fbuihuu@gmail.com>
 Frank Lichtenheld <frank@lichtenheld.de> <djpig@debian.org>
@@ -86,6 +89,8 @@ Jason McMullan <mcmullan@netapp.com>
 Jason Riedy <ejr@eecs.berkeley.edu> <ejr@EECS.Berkeley.EDU>
 Jason Riedy <ejr@eecs.berkeley.edu> <ejr@cs.berkeley.edu>
 Jay Soffian <jaysoffian@gmail.com> <jaysoffian+git@gmail.com>
+Jean-Noël Avila <jn.avila@free.fr> Jean-Noel Avila
+Jean-Noël Avila <jn.avila@free.fr> Jean-Noël AVILA
 Jeff King <peff@peff.net> <peff@github.com>
 Jeff Muizelaar <jmuizelaar@mozilla.com> <jeff@infidigm.net>
 Jens Axboe <axboe@kernel.dk> <axboe@suse.de>
@@ -149,6 +154,7 @@ Matt Draisey <matt@draisey.ca> <mattdraisey@sympatico.ca>
 Matt Kraai <kraai@ftbfs.org> <matt.kraai@amo.abbott.com>
 Matt McCutchen <matt@mattmccutchen.net> <hashproduct@gmail.com>
 Matthias Kestenholz <matthias@spinlock.ch> <mk@spinlock.ch>
+Matthias Rüster <matthias.ruester@gmail.com> Matthias Ruester
 Matthias Urlichs <matthias@urlichs.de> <smurf@kiste.(none)>
 Matthias Urlichs <matthias@urlichs.de> <smurf@smurf.noris.de>
 Michael Coleman <tutufan@gmail.com>
@@ -213,6 +219,8 @@ Sean Estabrooks <seanlkml@sympatico.ca>
 Sebastian Schuberth <sschuberth@gmail.com> <sschuberth@visageimaging.com>
 Seth Falcon <seth@userprimary.net> <sfalcon@fhcrc.org>
 Shawn O. Pearce <spearce@spearce.org>
+Wei Shuyu <wsy@dogben.com> Shuyu Wei
+Sidhant Sharma <tigerkid001@gmail.com> Sidhant Sharma [:tk]
 Simon Hausmann <hausmann@kde.org> <simon@lst.de>
 Simon Hausmann <hausmann@kde.org> <shausman@trolltech.com>
 Stefan Beller <stefanbeller@gmail.com> <stefanbeller@googlemail.com>
@@ -253,7 +261,8 @@ Uwe Kleine-König <u.kleine-koenig@pengutronix.de> <ukleinek@informatik.uni-frei
 Uwe Kleine-König <u.kleine-koenig@pengutronix.de> <uzeisberger@io.fsforth.de>
 Uwe Kleine-König <u.kleine-koenig@pengutronix.de> <zeisberg@informatik.uni-freiburg.de>
 Ville Skyttä <ville.skytta@iki.fi> <scop@xemacs.org>
-Vitaly "_Vi" Shukela <public_vi@tut.by>
+Vitaly "_Vi" Shukela <vi0oss@gmail.com> <public_vi@tut.by>
+Vitaly "_Vi" Shukela <vi0oss@gmail.com> Vitaly _Vi Shukela
 W. Trevor King <wking@tremily.us> <wking@drexel.edu>
 William Pursell <bill.pursell@gmail.com>
 YONETANI Tomokazu <y0n3t4n1@gmail.com> <qhwt+git@les.ath.cx>
index c7096f11f1e03f5eae463fa23dc7802136097f99..3ef54e0adbad5fbfd4468581037a2dcb9a9a4681 100644 (file)
@@ -12,3 +12,4 @@ cmds-*.txt
 mergetools-*.txt
 manpage-base-url.xsl
 SubmittingPatches.txt
+tmp-doc-diff/
index 2b45b6ff5cb3bf2980ad911b8c84179f27d8d72c..8f8da9f9c84a91e746cdbe168eb4fa72a4fac780 100644 (file)
@@ -15,6 +15,64 @@ UI, Workflows & Features
    otherwise working-tree-only application of a patch will add new
    paths to the index marked with the "intent-to-add" bit.
 
+ * "git grep" learned the "--column" option that gives not just the
+   line number but the column number of the hit.
+
+ * The "-l" option in "git branch -l" is an unfortunate short-hand for
+   "--create-reflog", but many users, both old and new, somehow expect
+   it to be something else, perhaps "--list".  This step warns when "-l"
+   is used as a short-hand for "--create-reflog" and warns about the
+   future repurposing of the it when it is used.
+
+ * The userdiff pattern for .php has been updated.
+
+ * The content-transfer-encoding of the message "git send-email" sends
+   out by default was 8bit, which can cause trouble when there is an
+   overlong line to bust RFC 5322/2822 limit.  A new option 'auto' to
+   automatically switch to quoted-printable when there is such a line
+   in the payload has been introduced and is made the default.
+
+ * "git checkout" and "git worktree add" learned to honor
+   checkout.defaultRemote when auto-vivifying a local branch out of a
+   remote tracking branch in a repository with multiple remotes that
+   have tracking branches that share the same names.
+   (merge 8d7b558bae ab/checkout-default-remote later to maint).
+
+ * "git grep" learned the "--only-matching" option.
+
+ * "git rebase --rebase-merges" mode now handles octopus merges as
+   well.
+
+ * Add a server-side knob to skip commits in exponential/fibbonacci
+   stride in an attempt to cover wider swath of history with a smaller
+   number of iterations, potentially accepting a larger packfile
+   transfer, instead of going back one commit a time during common
+   ancestor discovery during the "git fetch" transaction.
+   (merge 42cc7485a2 jt/fetch-negotiator-skipping later to maint).
+
+ * A new configuration variable core.usereplacerefs has been added,
+   primarily to help server installations that want to ignore the
+   replace mechanism altogether.
+
+ * Teach "git tag -s" etc. a few configuration variables (gpg.format
+   that can be set to "openpgp" or "x509", and gpg.<format>.program
+   that is used to specify what program to use to deal with the format)
+   to allow x.509 certs with CMS via "gpgsm" to be used instead of
+   openpgp via "gnupg".
+
+ * Many more strings are prepared for l10n.
+
+ * "git p4 submit" learns to ask its own pre-submit hook if it should
+   continue with submitting.
+
+ * The test performed at the receiving end of "git push" to prevent
+   bad objects from entering repository can be customized via
+   receive.fsck.* configuration variables; we now have gained a
+   counterpart to do the same on the "git fetch" side, with
+   fetch.fsck.* configuration variables.
+
+ * "git pull --rebase=interactive" learned "i" as a short-hand for
+   "interactive".
 
 Performance, Internal Implementation, Development Support etc.
 
@@ -51,6 +109,117 @@ Performance, Internal Implementation, Development Support etc.
  * Build and test procedure for netrc credential helper (in contrib/)
    has been updated.
 
+ * The conversion to pass "the_repository" and then "a_repository"
+   throughout the object access API continues.
+
+ * Remove unused function definitions and declarations from ewah
+   bitmap subsystem.
+
+ * Code preparation to make "git p4" closer to be usable with Python 3.
+
+ * Tighten the API to make it harder to misuse in-tree .gitmodules
+   file, even though it shares the same syntax with configuration
+   files, to read random configuration items from it.
+
+ * "git fast-import" has been updated to avoid attempting to create
+   delta against a zero-byte-long string, which is pointless.
+
+ * The codebase has been updated to compile cleanly with -pedantic
+   option.
+   (merge 2b647a05d7 bb/pedantic later to maint).
+
+ * The character display width table has been updated to match the
+   latest Unicode standard.
+   (merge 570951eea2 bb/unicode-11-width later to maint).
+
+ * test-lint now looks for broken use of "VAR=VAL shell_func" in test
+   scripts.
+
+ * Conversion from uchar[40] to struct object_id continues.
+
+ * Recent "security fix" to pay attention to contents of ".gitmodules"
+   while accepting "git push" was a bit overly strict than necessary,
+   which has been adjusted.
+
+ * "git fsck" learns to make sure the optional commit-graph file is in
+   a sane state.
+
+ * "git diff --color-moved" feature has further been tweaked.
+
+ * Code restructuring and a small fix to transport protocol v2 during
+   fetching.
+
+ * Parsing of -L[<N>][,[<M>]] parameters "git blame" and "git log"
+   take has been tweaked.
+
+ * lookup_commit_reference() and friends have been updated to find
+   in-core object for a specific in-core repository instance.
+
+ * Various glitches in the heuristics of merge-recursive strategy have
+   been documented in new tests.
+
+ * "git fetch" learned a new option "--negotiation-tip" to limit the
+   set of commits it tells the other end as "have", to reduce wasted
+   bandwidth and cycles, which would be helpful when the receiving
+   repository has a lot of refs that have little to do with the
+   history at the remote it is fetching from.
+
+ * For a large tree, the index needs to hold many cache entries
+   allocated on heap.  These cache entries are now allocated out of a
+   dedicated memory pool to amortize malloc(3) overhead.
+
+ * Tests to cover various conflicting cases have been added for
+   merge-recursive.
+
+ * Tests to cover conflict cases that involve submodules have been
+   added for merge-recursive.
+
+ * Look for broken "&&" chains that are hidden in subshell, many of
+   which have been found and corrected.
+
+ * The singleton commit-graph in-core instance is made per in-core
+   repository instance.
+
+ * "make DEVELOPER=1 DEVOPTS=pedantic" allows developers to compile
+   with -pedantic option, which may catch more problematic program
+   constructs and potential bugs.
+
+ * Preparatory code to later add json output for telemetry data has
+   been added.
+
+ * Update the way we use Coccinelle to find out-of-style code that
+   need to be modernised.
+
+ * It is too easy to misuse system API functions such as strcat();
+   these selected functions are now forbidden in this codebase and
+   will cause a compilation failure.
+
+ * Add a script (in contrib/) to help users of VSCode work better with
+   our codebase.
+
+ * The Travis CI scripts were taught to ship back the test data from
+   failed tests.
+   (merge aea8879a6a sg/travis-retrieve-trash-upon-failure later to maint).
+
+ * The parse-options machinery learned to refrain from enclosing
+   placeholder string inside a "<bra" and "ket>" pair automatically
+   without PARSE_OPT_LITERAL_ARGHELP.  Existing help text for option
+   arguments that are not formatted correctly have been identified and
+   fixed.
+   (merge 5f0df44cd7 rs/parse-opt-lithelp later to maint).
+
+ * Noiseword "extern" has been removed from function decls in the
+   header files.
+
+ * A few atoms like %(objecttype) and %(objectsize) in the format
+   specifier of "for-each-ref --format=<format>" can be filled without
+   getting the full contents of the object, but just with the object
+   header.  These cases have been optimized by calling
+   oid_object_info() API (instead of reading and inspecting the data).
+
+ * The end result of documentation update has been made to be
+   inspected more easily to help developers.
+
 
 Fixes since v2.18
 -----------------
@@ -96,6 +265,223 @@ Fixes since v2.18
    to the submodule was changed in the range of commits in the
    superproject, sometimes showing "(null)".  This has been corrected.
 
- * Code cleanup.
+ * "git submodule" did not correctly adjust core.worktree setting that
+   indicates whether/where a submodule repository has its associated
+   working tree across various state transitions, which has been
+   corrected.
+   (merge 984cd77ddb sb/submodule-core-worktree later to maint).
+
+ * Bugfix for "rebase -i" corner case regression.
+   (merge a9279c6785 pw/rebase-i-keep-reword-after-conflict later to maint).
+
+ * Recently added "--base" option to "git format-patch" command did
+   not correctly generate prereq patch ids.
+   (merge 15b76c1fb3 xy/format-patch-prereq-patch-id-fix later to maint).
+
+ * POSIX portability fix in Makefile to fix a glitch introduced a few
+   releases ago.
+   (merge 6600054e9b dj/runtime-prefix later to maint).
+
+ * "git filter-branch" when used with the "--state-branch" option
+   still attempted to rewrite the commits whose filtered result is
+   known from the previous attempt (which is recorded on the state
+   branch); the command has been corrected not to waste cycles doing
+   so.
+   (merge 709cfe848a mb/filter-branch-optim later to maint).
+
+ * Clarify that setting core.ignoreCase to deviate from reality would
+   not turn a case-incapable filesystem into a case-capable one.
+   (merge 48294b512a ms/core-icase-doc later to maint).
+
+ * "fsck.skipList" did not prevent a blob object listed there from
+   being inspected for is contents (e.g. we recently started to
+   inspect the contents of ".gitmodules" for certain malicious
+   patterns), which has been corrected.
+   (merge fb16287719 rj/submodule-fsck-skip later to maint).
+
+ * "git checkout --recurse-submodules another-branch" did not report
+   in which submodule it failed to update the working tree, which
+   resulted in an unhelpful error message.
+   (merge ba95d4e4bd sb/submodule-move-head-error-msg later to maint).
+
+ * "git rebase" behaved slightly differently depending on which one of
+   the three backends gets used; this has been documented and an
+   effort to make them more uniform has begun.
+   (merge b00bf1c9a8 en/rebase-consistency later to maint).
+
+ * The "--ignore-case" option of "git for-each-ref" (and its friends)
+   did not work correctly, which has been fixed.
+   (merge e674eb2528 jk/for-each-ref-icase later to maint).
+
+ * "git fetch" failed to correctly validate the set of objects it
+   received when making a shallow history deeper, which has been
+   corrected.
+   (merge cf1e7c0770 jt/connectivity-check-after-unshallow later to maint).
+
+ * Partial clone support of "git clone" has been updated to correctly
+   validate the objects it receives from the other side.  The server
+   side has been corrected to send objects that are directly
+   requested, even if they may match the filtering criteria (e.g. when
+   doing a "lazy blob" partial clone).
+   (merge a7e67c11b8 jt/partial-clone-fsck-connectivity later to maint).
+
+ * Handling of an empty range by "git cherry-pick" was inconsistent
+   depending on how the range ended up to be empty, which has been
+   corrected.
+   (merge c5e358d073 jk/empty-pick-fix later to maint).
+
+ * "git reset --merge" (hence "git merge ---abort") and "git reset --hard"
+   had trouble working correctly in a sparsely checked out working
+   tree after a conflict, which has been corrected.
+   (merge b33fdfc34c mk/merge-in-sparse-checkout later to maint).
+
+ * Correct a broken use of "VAR=VAL shell_func" in a test.
+   (merge 650161a277 jc/t3404-one-shot-export-fix later to maint).
+
+ * "git rev-parse ':/substring'" did not consider the history leading
+   only to HEAD when looking for a commit with the given substring,
+   when the HEAD is detached.  This has been fixed.
+   (merge 6b3351e799 wc/find-commit-with-pattern-on-detached-head later to maint).
+
+ * Build doc update for Windows.
+   (merge ede8d89bb1 nd/command-list later to maint).
+
+ * core.commentchar is now honored when preparing the list of commits
+   to replay in "rebase -i".
+
+ * "git pull --rebase" on a corrupt HEAD caused a segfault.  In
+   general we substitute an empty tree object when running the in-core
+   equivalent of the diff-index command, and the codepath has been
+   corrected to do so as well to fix this issue.
+   (merge 3506dc9445 jk/has-uncommitted-changes-fix later to maint).
+
+ * httpd tests saw occasional breakage due to the way its access log
+   gets inspected by the tests, which has been updated to make them
+   less flaky.
+   (merge e8b3b2e275 sg/httpd-test-unflake later to maint).
+
+ * Tests to cover more D/F conflict cases have been added for
+   merge-recursive.
+
+ * "git gc --auto" opens file descriptors for the packfiles before
+   spawning "git repack/prune", which would upset Windows that does
+   not want a process to work on a file that is open by another
+   process.  The issue has been worked around.
+   (merge 12e73a3ce4 kg/gc-auto-windows-workaround later to maint).
+
+ * The recursive merge strategy did not properly ensure there was no
+   change between HEAD and the index before performing its operation,
+   which has been corrected.
+   (merge 55f39cf755 en/dirty-merge-fixes later to maint).
+
+ * "git rebase" started exporting GIT_DIR environment variable and
+   exposing it to hook scripts when part of it got rewritten in C.
+   Instead of matching the old scripted Porcelains' behaviour,
+   compensate by also exporting GIT_WORK_TREE environment as well to
+   lessen the damage.  This can harm existing hooks that want to
+   operate on different repository, but the current behaviour is
+   already broken for them anyway.
+   (merge ab5e67d751 bc/sequencer-export-work-tree-as-well later to maint).
+
+ * "git send-email" when using in a batched mode that limits the
+   number of messages sent in a single SMTP session lost the contents
+   of the variable used to choose between tls/ssl, unable to send the
+   second and later batches, which has been fixed.
+   (merge 636f3d7ac5 jm/send-email-tls-auth-on-batch later to maint).
+
+ * The lazy clone support had a few places where missing but promised
+   objects were not correctly tolerated, which have been fixed.
+
+ * One of the "diff --color-moved" mode "dimmed_zebra" that was named
+   in an unusual way has been deprecated and replaced by
+   "dimmed-zebra".
+   (merge e3f2f5f9cd es/diff-color-moved-fix later to maint).
+
+ * The wire-protocol v2 relies on the client to send "ref prefixes" to
+   limit the bandwidth spent on the initial ref advertisement.  "git
+   clone" when learned to speak v2 forgot to do so, which has been
+   corrected.
+   (merge 402c47d939 bw/clone-ref-prefixes later to maint).
+
+ * "git diff --histogram" had a bad memory usage pattern, which has
+   been rearranged to reduce the peak usage.
+   (merge 79cb2ebb92 sb/histogram-less-memory later to maint).
+
+ * Code clean-up to use size_t/ssize_t when they are the right type.
+   (merge 7726d360b5 jk/size-t later to maint).
+
+ * The wire-protocol v2 relies on the client to send "ref prefixes" to
+   limit the bandwidth spent on the initial ref advertisement.  "git
+   fetch $remote branch:branch" that asks tags that point into the
+   history leading to the "branch" automatically followed sent to
+   narrow prefix and broke the tag following, which has been fixed.
+   (merge 2b554353a5 jt/tag-following-with-proto-v2-fix later to maint).
+
+ * When the sparse checkout feature is in use, "git cherry-pick" and
+   other mergy operations lost the skip_worktree bit when a path that
+   is excluded from checkout requires content level merge, which is
+   resolved as the same as the HEAD version, without materializing the
+   merge result in the working tree, which made the path appear as
+   deleted.  This has been corrected by preserving the skip_worktree
+   bit (and not materializing the file in the working tree).
+   (merge 2b75fb601c en/merge-recursive-skip-fix later to maint).
+
+ * The "author-script" file "git rebase -i" creates got broken when
+   we started to move the command away from shell script, which is
+   getting fixed now.
+   (merge 5522bbac20 es/rebase-i-author-script-fix later to maint).
+
+ * The automatic tree-matching in "git merge -s subtree" was broken 5
+   years ago and nobody has noticed since then, which is now fixed.
+   (merge 2ec4150713 jk/merge-subtree-heuristics later to maint).
+
+ * "git fetch $there refs/heads/s" ought to fetch the tip of the
+   branch 's', but when "refs/heads/refs/heads/s", i.e. a branch whose
+   name is "refs/heads/s" exists at the same time, fetched that one
+   instead by mistake.  This has been corrected to honor the usual
+   disambiguation rules for abbreviated refnames.
+   (merge 60650a48c0 jt/refspec-dwim-precedence-fix later to maint).
+
+ * Futureproofing a helper function that can easily be misused.
+   (merge 65bb21e77e es/want-color-fd-defensive later to maint).
+
+ * The http-backend (used for smart-http transport) used to slurp the
+   whole input until EOF, without paying attention to CONTENT_LENGTH
+   that is supplied in the environment and instead expecting the Web
+   server to close the input stream.  This has been fixed.
+   (merge eebfe40962 mk/http-backend-content-length later to maint).
+
+ * "git merge --abort" etc. did not clean things up properly when
+   there were conflicted entries in the index in certain order that
+   are involved in D/F conflicts.  This has been corrected.
+   (merge ad3762042a en/abort-df-conflict-fixes later to maint).
+
+ * "git diff --indent-heuristic" had a bad corner case performance.
+   (merge 301ef85401 sb/indent-heuristic-optim later to maint).
+
+ * Code cleanup, docfix, build fix, etc.
    (merge aee9be2ebe sg/update-ref-stdin-cleanup later to maint).
    (merge 037714252f jc/clean-after-sanity-tests later to maint).
+   (merge 5b26c3c941 en/merge-recursive-cleanup later to maint).
+   (merge 0dcbc0392e bw/config-refer-to-gitsubmodules-doc later to maint).
+   (merge bb4d000e87 bw/protocol-v2 later to maint).
+   (merge 928f0ab4ba vs/typofixes later to maint).
+   (merge d7f590be84 en/rebase-i-microfixes later to maint).
+   (merge 81d395cc85 js/rebase-recreate-merge later to maint).
+   (merge 51d1863168 tz/exclude-doc-smallfixes later to maint).
+   (merge a9aa3c0927 ds/commit-graph later to maint).
+   (merge 5cf8e06474 js/enhanced-version-info later to maint).
+   (merge 6aaded5509 tb/config-default later to maint).
+   (merge 022d2ac1f3 sb/blame-color later to maint).
+   (merge 5a06a20e0c bp/test-drop-caches-for-windows later to maint).
+   (merge dd61cc1c2e jk/ui-color-always-to-auto later to maint).
+   (merge 1e83b9bfdd sb/trailers-docfix later to maint).
+   (merge ab29f1b329 sg/fast-import-dump-refs-on-checkpoint-fix later to maint).
+   (merge 6a8ad880f0 jn/subtree-test-fixes later to maint).
+   (merge ffbd51cc60 nd/pack-objects-threading-doc later to maint).
+   (merge e9dac7be60 es/mw-to-git-chain-fix later to maint).
+   (merge fe583c6c7a rs/remote-mv-leakfix later to maint).
+   (merge 69885ab015 en/t3031-title-fix later to maint).
+   (merge 8578037bed nd/config-blame-sort later to maint).
+   (merge 8ad169c4ba hn/config-in-code-comment later to maint).
+   (merge b7446fcfdf ar/t4150-am-scissors-test-fix later to maint).
index 24885444078b04cfe70cf9fd0b81c972f72b91bd..b44fd51f275b105b62a1f5c9d23ca616e2d87e7d 100644 (file)
@@ -298,7 +298,7 @@ smaller project it is a good discipline to follow it.
 
 The sign-off is a simple line at the end of the explanation for
 the patch, which certifies that you wrote it or otherwise have
-the right to pass it on as a open-source patch.  The rules are
+the right to pass it on as an open-source patch.  The rules are
 pretty simple: if you can certify the below D-C-O:
 
 [[dco]]
@@ -403,7 +403,7 @@ don't demand).  +git log -p {litdd} _$area_you_are_modifying_+ would
 help you find out who they are.
 
 . You get comments and suggestions for improvements.  You may
-  even get them in a "on top of your change" patch form.
+  even get them in an "on top of your change" patch form.
 
 . Polish, refine, and re-send to the list and the people who
   spend their time to improve your patch.  Go back to step (2).
index 1cc18a828ca63bc489726dc3f1489a5e5e5c8b2b..1c78df7b90468db379cbca8790f3cac9a6aef6b3 100644 (file)
@@ -344,6 +344,16 @@ advice.*::
                Advice shown when you used linkgit:git-checkout[1] to
                move to the detach HEAD state, to instruct how to create
                a local branch after the fact.
+       checkoutAmbiguousRemoteBranchName::
+               Advice shown when the argument to
+               linkgit:git-checkout[1] ambiguously resolves to a
+               remote tracking branch on more than one remote in
+               situations where an unambiguous argument would have
+               otherwise caused a remote-tracking branch to be
+               checked out. See the `checkout.defaultRemote`
+               configuration variable for how to set a given remote
+               to used by default in some situations where this
+               advice would be printed.
        amWorkDir::
                Advice that shows the location of the patch file when
                linkgit:git-am[1] fails to apply it.
@@ -354,7 +364,7 @@ advice.*::
                Advice on what to do when you've accidentally added one
                git repo inside of another.
        ignoredHook::
-               Advice shown if an hook is ignored because the hook is not
+               Advice shown if a hook is ignored because the hook is not
                set as executable.
        waitingForEditor::
                Print a message to the terminal whenever Git is waiting for
@@ -390,16 +400,19 @@ core.hideDotFiles::
        default mode is 'dotGitOnly'.
 
 core.ignoreCase::
-       If true, this option enables various workarounds to enable
+       Internal variable which enables various workarounds to enable
        Git to work better on filesystems that are not case sensitive,
-       like FAT. For example, if a directory listing finds
-       "makefile" when Git expects "Makefile", Git will assume
+       like APFS, HFS+, FAT, NTFS, etc. For example, if a directory listing
+       finds "makefile" when Git expects "Makefile", Git will assume
        it is really the same file, and continue to remember it as
        "Makefile".
 +
 The default is false, except linkgit:git-clone[1] or linkgit:git-init[1]
 will probe and set core.ignoreCase true if appropriate when the repository
 is created.
++
+Git relies on the proper configuration of this variable for your operating
+and file system. Modifying this value may result in unexpected behavior.
 
 core.precomposeUnicode::
        This option is only used by Mac OS implementation of Git.
@@ -904,9 +917,17 @@ core.notesRef::
 This setting defaults to "refs/notes/commits", and it can be overridden by
 the `GIT_NOTES_REF` environment variable.  See linkgit:git-notes[1].
 
-core.commitGraph::
-       Enable git commit graph feature. Allows reading from the
-       commit-graph file.
+gc.commitGraph::
+       If true, then gc will rewrite the commit-graph file when
+       linkgit:git-gc[1] is run. When using linkgit:git-gc[1]
+       '--auto' the commit-graph will be updated if housekeeping is
+       required. Default is false. See linkgit:git-commit-graph[1]
+       for details.
+
+core.useReplaceRefs::
+       If set to `false`, behave as if the `--no-replace-objects`
+       option was given on the command line. See linkgit:git[1] and
+       linkgit:git-replace[1] for more information.
 
 core.sparseCheckout::
        Enable "sparse checkout" feature. See section "Sparse checkout" in
@@ -974,23 +995,28 @@ apply.whitespace::
        Tells 'git apply' how to handle whitespaces, in the same way
        as the `--whitespace` option. See linkgit:git-apply[1].
 
-blame.showRoot::
-       Do not treat root commits as boundaries in linkgit:git-blame[1].
-       This option defaults to false.
-
 blame.blankBoundary::
        Show blank commit object name for boundary commits in
        linkgit:git-blame[1]. This option defaults to false.
 
-blame.showEmail::
-       Show the author email instead of author name in linkgit:git-blame[1].
-       This option defaults to false.
+blame.coloring::
+       This determines the coloring scheme to be applied to blame
+       output. It can be 'repeatedLines', 'highlightRecent',
+       or 'none' which is the default.
 
 blame.date::
        Specifies the format used to output dates in linkgit:git-blame[1].
        If unset the iso format is used. For supported values,
        see the discussion of the `--date` option at linkgit:git-log[1].
 
+blame.showEmail::
+       Show the author email instead of author name in linkgit:git-blame[1].
+       This option defaults to false.
+
+blame.showRoot::
+       Do not treat root commits as boundaries in linkgit:git-blame[1].
+       This option defaults to false.
+
 branch.autoSetupMerge::
        Tells 'git branch' and 'git checkout' to set up new branches
        so that linkgit:git-pull[1] will appropriately merge from the
@@ -1098,6 +1124,22 @@ browser.<tool>.path::
        browse HTML help (see `-w` option in linkgit:git-help[1]) or a
        working repository in gitweb (see linkgit:git-instaweb[1]).
 
+checkout.defaultRemote::
+       When you run 'git checkout <something>' and only have one
+       remote, it may implicitly fall back on checking out and
+       tracking e.g. 'origin/<something>'. This stops working as soon
+       as you have more than one remote with a '<something>'
+       reference. This setting allows for setting the name of a
+       preferred remote that should always win when it comes to
+       disambiguation. The typical use-case is to set this to
+       `origin`.
++
+Currently this is used by linkgit:git-checkout[1] when 'git checkout
+<something>' will checkout the '<something>' branch on another remote,
+and by linkgit:git-worktree[1] when 'git worktree add' refers to a
+remote branch. This setting might be used for other checkout-like
+commands or functionality in the future.
+
 clean.requireForce::
        A boolean to make git-clean do nothing unless given -f,
        -i or -n.   Defaults to true.
@@ -1112,6 +1154,28 @@ color.advice::
 color.advice.hint::
        Use customized color for hints.
 
+color.blame.highlightRecent::
+       This can be used to color the metadata of a blame line depending
+       on age of the line.
++
+This setting should be set to a comma-separated list of color and date settings,
+starting and ending with a color, the dates should be set from oldest to newest.
+The metadata will be colored given the colors if the the line was introduced
+before the given timestamp, overwriting older timestamped colors.
++
+Instead of an absolute timestamp relative timestamps work as well, e.g.
+2.weeks.ago is valid to address anything older than 2 weeks.
++
+It defaults to 'blue,12 month ago,white,1 month ago,red', which colors
+everything older than one year blue, recent changes between one month and
+one year old are kept white, and lines introduced within the last month are
+colored red.
+
+color.blame.repeatedLines::
+       Use the customized color for the part of git-blame output that
+       is repeated meta information per line (such as commit id,
+       author name, date and timezone). Defaults to cyan.
+
 color.branch::
        A boolean to enable/disable color in the output of
        linkgit:git-branch[1]. May be set to `always`,
@@ -1146,6 +1210,11 @@ diff.colorMoved::
        true the default color mode will be used. When set to false,
        moved lines are not colored.
 
+diff.colorMovedWS::
+       When moved lines are colored using e.g. the `diff.colorMoved` setting,
+       this option controls the `<mode>` how spaces are treated
+       for details of valid modes see '--color-moved-ws' in linkgit:git-diff[1].
+
 color.diff.<slot>::
        Use customized color for diff colorization.  `<slot>` specifies
        which part of the patch to use the specified color, and is one
@@ -1156,8 +1225,10 @@ color.diff.<slot>::
        (highlighting whitespace errors), `oldMoved` (deleted lines),
        `newMoved` (added lines), `oldMovedDimmed`, `oldMovedAlternative`,
        `oldMovedAlternativeDimmed`, `newMovedDimmed`, `newMovedAlternative`
-       and `newMovedAlternativeDimmed` (See the '<mode>'
-       setting of '--color-moved' in linkgit:git-diff[1] for details).
+       `newMovedAlternativeDimmed` (See the '<mode>'
+       setting of '--color-moved' in linkgit:git-diff[1] for details),
+       `contextDimmed`, `oldDimmed`, `newDimmed`, `contextBold`,
+       `oldBold`, and `newBold` (see linkgit:git-range-diff[1] for details).
 
 color.decorate.<slot>::
        Use customized color for 'git log --decorate' output.  `<slot>` is one
@@ -1182,8 +1253,10 @@ color.grep.<slot>::
        filename prefix (when not using `-h`)
 `function`;;
        function name lines (when using `-p`)
-`linenumber`;;
+`lineNumber`;;
        line number prefix (when using `-n`)
+`column`;;
+       column number prefix (when using `--column`)
 `match`;;
        matching text (same as setting `matchContext` and `matchSelected`)
 `matchContext`;;
@@ -1252,33 +1325,6 @@ color.status.<slot>::
        status short-format), or
        `unmerged` (files which have unmerged changes).
 
-color.blame.repeatedLines::
-       Use the customized color for the part of git-blame output that
-       is repeated meta information per line (such as commit id,
-       author name, date and timezone). Defaults to cyan.
-
-color.blame.highlightRecent::
-       This can be used to color the metadata of a blame line depending
-       on age of the line.
-+
-This setting should be set to a comma-separated list of color and date settings,
-starting and ending with a color, the dates should be set from oldest to newest.
-The metadata will be colored given the colors if the the line was introduced
-before the given timestamp, overwriting older timestamped colors.
-+
-Instead of an absolute timestamp relative timestamps work as well, e.g.
-2.weeks.ago is valid to address anything older than 2 weeks.
-+
-It defaults to 'blue,12 month ago,white,1 month ago,red', which colors
-everything older than one year blue, recent changes between one month and
-one year old are kept white, and lines introduced within the last month are
-colored red.
-
-blame.coloring::
-       This determines the coloring scheme to be applied to blame
-       output. It can be 'repeatedLines', 'highlightRecent',
-       or 'none' which is the default.
-
 color.transport::
        A boolean to enable/disable color when pushes are rejected. May be
        set to `always`, `false` (or `never`) or `auto` (or `true`), in which
@@ -1458,10 +1504,19 @@ fetch.recurseSubmodules::
 
 fetch.fsckObjects::
        If it is set to true, git-fetch-pack will check all fetched
-       objects. It will abort in the case of a malformed object or a
-       broken link. The result of an abort are only dangling objects.
-       Defaults to false. If not set, the value of `transfer.fsckObjects`
-       is used instead.
+       objects. See `transfer.fsckObjects` for what's
+       checked. Defaults to false. If not set, the value of
+       `transfer.fsckObjects` is used instead.
+
+fetch.fsck.<msg-id>::
+       Acts like `fsck.<msg-id>`, but is used by
+       linkgit:git-fetch-pack[1] instead of linkgit:git-fsck[1]. See
+       the `fsck.<msg-id>` documentation for details.
+
+fetch.fsck.skipList::
+       Acts like `fsck.skipList`, but is used by
+       linkgit:git-fetch-pack[1] instead of linkgit:git-fsck[1]. See
+       the `fsck.skipList` documentation for details.
 
 fetch.unpackLimit::
        If the number of objects fetched over the Git native
@@ -1492,6 +1547,18 @@ fetch.output::
        `full` and `compact`. Default value is `full`. See section
        OUTPUT in linkgit:git-fetch[1] for detail.
 
+fetch.negotiationAlgorithm::
+       Control how information about the commits in the local repository is
+       sent when negotiating the contents of the packfile to be sent by the
+       server. Set to "skipping" to use an algorithm that skips commits in an
+       effort to converge faster, but may result in a larger-than-necessary
+       packfile; The default is "default" which instructs Git to use the default algorithm
+       that never skips commits (unless the server has acknowledged it or one
+       of its descendants).
+       Unknown values will cause 'git fetch' to error out.
++
+See also the `--negotiation-tip` option for linkgit:git-fetch[1].
+
 format.attach::
        Enable multipart/mixed attachments as the default for
        'format-patch'.  The value can also be a double quoted string
@@ -1591,15 +1658,42 @@ filter.<driver>.smudge::
        linkgit:gitattributes[5] for details.
 
 fsck.<msg-id>::
-       Allows overriding the message type (error, warn or ignore) of a
-       specific message ID such as `missingEmail`.
-+
-For convenience, fsck prefixes the error/warning with the message ID,
-e.g.  "missingEmail: invalid author/committer line - missing email" means
-that setting `fsck.missingEmail = ignore` will hide that issue.
-+
-This feature is intended to support working with legacy repositories
-which cannot be repaired without disruptive changes.
+       During fsck git may find issues with legacy data which
+       wouldn't be generated by current versions of git, and which
+       wouldn't be sent over the wire if `transfer.fsckObjects` was
+       set. This feature is intended to support working with legacy
+       repositories containing such data.
++
+Setting `fsck.<msg-id>` will be picked up by linkgit:git-fsck[1], but
+to accept pushes of such data set `receive.fsck.<msg-id>` instead, or
+to clone or fetch it set `fetch.fsck.<msg-id>`.
++
+The rest of the documentation discusses `fsck.*` for brevity, but the
+same applies for the corresponding `receive.fsck.*` and
+`fetch.<msg-id>.*`. variables.
++
+Unlike variables like `color.ui` and `core.editor` the
+`receive.fsck.<msg-id>` and `fetch.fsck.<msg-id>` variables will not
+fall back on the `fsck.<msg-id>` configuration if they aren't set. To
+uniformly configure the same fsck settings in different circumstances
+all three of them they must all set to the same values.
++
+When `fsck.<msg-id>` is set, errors can be switched to warnings and
+vice versa by configuring the `fsck.<msg-id>` setting where the
+`<msg-id>` is the fsck message ID and the value is one of `error`,
+`warn` or `ignore`. For convenience, fsck prefixes the error/warning
+with the message ID, e.g. "missingEmail: invalid author/committer line
+- missing email" means that setting `fsck.missingEmail = ignore` will
+hide that issue.
++
+In general, it is better to enumerate existing objects with problems
+with `fsck.skipList`, instead of listing the kind of breakages these
+problematic objects share to be ignored, as doing the latter will
+allow new instances of the same breakages go unnoticed.
++
+Setting an unknown `fsck.<msg-id>` value will cause fsck to die, but
+doing the same for `receive.fsck.<msg-id>` and `fetch.fsck.<msg-id>`
+will only cause git to warn.
 
 fsck.skipList::
        The path to a sorted list of object names (i.e. one SHA-1 per
@@ -1608,6 +1702,15 @@ fsck.skipList::
        should be accepted despite early commits containing errors that
        can be safely ignored such as invalid committer email addresses.
        Note: corrupt objects cannot be skipped with this setting.
++
+Like `fsck.<msg-id>` this variable has corresponding
+`receive.fsck.skipList` and `fetch.fsck.skipList` variants.
++
+Unlike variables like `color.ui` and `core.editor` the
+`receive.fsck.skipList` and `fetch.fsck.skipList` variables will not
+fall back on the `fsck.skipList` configuration if they aren't set. To
+uniformly configure the same fsck settings in different circumstances
+all three of them they must all set to the same values.
 
 gc.aggressiveDepth::
        The depth parameter used in the delta compression
@@ -1798,6 +1901,9 @@ gitweb.snapshot::
 grep.lineNumber::
        If set to true, enable `-n` option by default.
 
+grep.column::
+       If set to true, enable the `--column` option by default.
+
 grep.patternType::
        Set the default matching behavior. Using a value of 'basic', 'extended',
        'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,
@@ -1828,6 +1934,16 @@ gpg.program::
        signed, and the program is expected to send the result to its
        standard output.
 
+gpg.format::
+       Specifies which key format to use when signing with `--gpg-sign`.
+       Default is "openpgp" and another possible value is "x509".
+
+gpg.<format>.program::
+       Use this to customize the program used for the signing format you
+       chose. (see `gpg.program` and `gpg.format`) `gpg.program` can still
+       be used as a legacy synonym for `gpg.openpgp.program`. The default
+       value for `gpg.x509.program` is "gpgsm".
+
 gui.commitMsgWidth::
        Defines how wide the commit message window is in the
        linkgit:git-gui[1]. "75" is the default.
@@ -2881,32 +2997,21 @@ receive.certNonceSlop::
 
 receive.fsckObjects::
        If it is set to true, git-receive-pack will check all received
-       objects. It will abort in the case of a malformed object or a
-       broken link. The result of an abort are only dangling objects.
-       Defaults to false. If not set, the value of `transfer.fsckObjects`
-       is used instead.
+       objects. See `transfer.fsckObjects` for what's checked.
+       Defaults to false. If not set, the value of
+       `transfer.fsckObjects` is used instead.
 
 receive.fsck.<msg-id>::
-       When `receive.fsckObjects` is set to true, errors can be switched
-       to warnings and vice versa by configuring the `receive.fsck.<msg-id>`
-       setting where the `<msg-id>` is the fsck message ID and the value
-       is one of `error`, `warn` or `ignore`. For convenience, fsck prefixes
-       the error/warning with the message ID, e.g. "missingEmail: invalid
-       author/committer line - missing email" means that setting
-       `receive.fsck.missingEmail = ignore` will hide that issue.
-+
-This feature is intended to support working with legacy repositories
-which would not pass pushing when `receive.fsckObjects = true`, allowing
-the host to accept repositories with certain known issues but still catch
-other issues.
+       Acts like `fsck.<msg-id>`, but is used by
+       linkgit:git-receive-pack[1] instead of
+       linkgit:git-fsck[1]. See the `fsck.<msg-id>` documentation for
+       details.
 
 receive.fsck.skipList::
-       The path to a sorted list of object names (i.e. one SHA-1 per
-       line) that are known to be broken in a non-fatal way and should
-       be ignored. This feature is useful when an established project
-       should be accepted despite early commits containing errors that
-       can be safely ignored such as invalid committer email addresses.
-       Note: corrupt objects cannot be skipped with this setting.
+       Acts like `fsck.skipList`, but is used by
+       linkgit:git-receive-pack[1] instead of
+       linkgit:git-fsck[1]. See the `fsck.skipList` documentation for
+       details.
 
 receive.keepAlive::
        After receiving the pack from the client, `receive-pack` may
@@ -3328,12 +3433,13 @@ submodule.<name>.ignore::
 submodule.<name>.active::
        Boolean value indicating if the submodule is of interest to git
        commands.  This config option takes precedence over the
-       submodule.active config option.
+       submodule.active config option. See linkgit:gitsubmodules[7] for
+       details.
 
 submodule.active::
        A repeated field which contains a pathspec used to match against a
        submodule's path to determine if the submodule is of interest to git
-       commands.
+       commands. See linkgit:gitsubmodules[7] for details.
 
 submodule.recurse::
        Specifies if commands recurse into submodules by default. This
@@ -3380,6 +3486,40 @@ transfer.fsckObjects::
        When `fetch.fsckObjects` or `receive.fsckObjects` are
        not set, the value of this variable is used instead.
        Defaults to false.
++
+When set, the fetch or receive will abort in the case of a malformed
+object or a link to a nonexistent object. In addition, various other
+issues are checked for, including legacy issues (see `fsck.<msg-id>`),
+and potential security issues like the existence of a `.GIT` directory
+or a malicious `.gitmodules` file (see the release notes for v2.2.1
+and v2.17.1 for details). Other sanity and security checks may be
+added in future releases.
++
+On the receiving side, failing fsckObjects will make those objects
+unreachable, see "QUARANTINE ENVIRONMENT" in
+linkgit:git-receive-pack[1]. On the fetch side, malformed objects will
+instead be left unreferenced in the repository.
++
+Due to the non-quarantine nature of the `fetch.fsckObjects`
+implementation it can not be relied upon to leave the object store
+clean like `receive.fsckObjects` can.
++
+As objects are unpacked they're written to the object store, so there
+can be cases where malicious objects get introduced even though the
+"fetch" failed, only to have a subsequent "fetch" succeed because only
+new incoming objects are checked, not those that have already been
+written to the object store. That difference in behavior should not be
+relied upon. In the future, such objects may be quarantined for
+"fetch" as well.
++
+For now, the paranoid need to find some way to emulate the quarantine
+environment if they'd like the same protection as "push". E.g. in the
+case of an internal mirror do the mirroring in two steps, one to fetch
+the untrusted objects, and then do a second "push" (which will use the
+quarantine) to another internal repo, and have internal clients
+consume this pushed-to repository, or embargo internal fetches and
+only allow them once a full "fsck" has run (and no new fetches have
+happened in the meantime).
 
 transfer.hideRefs::
        String(s) `receive-pack` and `upload-pack` use to decide which
@@ -3480,6 +3620,13 @@ Note that this configuration variable is ignored if it is seen in the
 repository-level config (this is a safety measure against fetching from
 untrusted repositories).
 
+uploadpack.allowRefInWant::
+       If this option is set, `upload-pack` will support the `ref-in-want`
+       feature of the protocol version 2 `fetch` command.  This feature
+       is intended for the benefit of load-balanced servers which may
+       not have the same view of what OIDs their refs point to due to
+       replication delay.
+
 url.<base>.insteadOf::
        Any URL that starts with this value will be rewritten to
        start, instead, with <base>. In cases where some site serves a
index 41064909ee42bca9a5decd375bc62ad658ae3c81..0378cd574eb01069baba14221d511f580565c0eb 100644 (file)
@@ -276,16 +276,46 @@ plain::
        that are added somewhere else in the diff. This mode picks up any
        moved line, but it is not very useful in a review to determine
        if a block of code was moved without permutation.
-zebra::
+blocks::
        Blocks of moved text of at least 20 alphanumeric characters
        are detected greedily. The detected blocks are
-       painted using either the 'color.diff.{old,new}Moved' color or
+       painted using either the 'color.diff.{old,new}Moved' color.
+       Adjacent blocks cannot be told apart.
+zebra::
+       Blocks of moved text are detected as in 'blocks' mode. The blocks
+       are painted using either the 'color.diff.{old,new}Moved' color or
        'color.diff.{old,new}MovedAlternative'. The change between
        the two colors indicates that a new block was detected.
-dimmed_zebra::
+dimmed-zebra::
        Similar to 'zebra', but additional dimming of uninteresting parts
        of moved code is performed. The bordering lines of two adjacent
        blocks are considered interesting, the rest is uninteresting.
+       `dimmed_zebra` is a deprecated synonym.
+--
+
+--color-moved-ws=<modes>::
+       This configures how white spaces are ignored when performing the
+       move detection for `--color-moved`.
+ifdef::git-diff[]
+       It can be set by the `diff.colorMovedWS` configuration setting.
+endif::git-diff[]
+       These modes can be given as a comma separated list:
++
+--
+ignore-space-at-eol::
+       Ignore changes in whitespace at EOL.
+ignore-space-change::
+       Ignore changes in amount of whitespace.  This ignores whitespace
+       at line end, and considers all other sequences of one or
+       more whitespace characters to be equivalent.
+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
+       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.
 --
 
 --word-diff[=<mode>]::
diff --git a/Documentation/doc-diff b/Documentation/doc-diff
new file mode 100755 (executable)
index 0000000..f483fe4
--- /dev/null
@@ -0,0 +1,109 @@
+#!/bin/sh
+
+OPTIONS_SPEC="\
+doc-diff [options] <from> <to> [-- <diff-options>]
+--
+j=n    parallel argument to pass to make
+f      force rebuild; do not rely on cached results
+"
+SUBDIRECTORY_OK=1
+. "$(git --exec-path)/git-sh-setup"
+
+parallel=
+force=
+while test $# -gt 0
+do
+       case "$1" in
+       -j)
+               parallel=$2; shift ;;
+       -f)
+               force=t ;;
+       --)
+               shift; break ;;
+       *)
+               usage ;;
+       esac
+       shift
+done
+
+if test -z "$parallel"
+then
+       parallel=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
+       if test $? != 0 || test -z "$parallel"
+       then
+               parallel=1
+       fi
+fi
+
+test $# -gt 1 || usage
+from=$1; shift
+to=$1; shift
+
+from_oid=$(git rev-parse --verify "$from") || exit 1
+to_oid=$(git rev-parse --verify "$to") || exit 1
+
+cd_to_toplevel
+tmp=Documentation/tmp-doc-diff
+
+if test -n "$force"
+then
+       rm -rf "$tmp"
+fi
+
+# We'll do both builds in a single worktree, which lets "make" reuse
+# results that don't differ between the two trees.
+if ! test -d "$tmp/worktree"
+then
+       git worktree add --detach "$tmp/worktree" "$from" &&
+       dots=$(echo "$tmp/worktree" | sed 's#[^/]*#..#g') &&
+       ln -s "$dots/config.mak" "$tmp/worktree/config.mak"
+fi
+
+# generate_render_makefile <srcdir> <dstdir>
+generate_render_makefile () {
+       find "$1" -type f |
+       while read src
+       do
+               dst=$2/${src#$1/}
+               printf 'all:: %s\n' "$dst"
+               printf '%s: %s\n' "$dst" "$src"
+               printf '\t@echo >&2 "  RENDER $(notdir $@)" && \\\n'
+               printf '\tmkdir -p $(dir $@) && \\\n'
+               printf '\tMANWIDTH=80 man -l $< >$@+ && \\\n'
+               printf '\tmv $@+ $@\n'
+       done
+}
+
+# render_tree <dirname> <committish>
+render_tree () {
+       # Skip install-man entirely if we already have an installed directory.
+       # We can't rely on make here, since "install-man" unconditionally
+       # copies the files (spending effort, but also updating timestamps that
+       # we then can't rely on during the render step). We use "mv" to make
+       # sure we don't get confused by a previous run that failed partway
+       # through.
+       if ! test -d "$tmp/installed/$1"
+       then
+               git -C "$tmp/worktree" checkout "$2" &&
+               make -j$parallel -C "$tmp/worktree" \
+                       GIT_VERSION=omitted \
+                       SOURCE_DATE_EPOCH=0 \
+                       DESTDIR="$PWD/$tmp/installed/$1+" \
+                       install-man &&
+               mv "$tmp/installed/$1+" "$tmp/installed/$1"
+       fi &&
+
+       # As with "installed" above, we skip the render if it's already been
+       # done.  So using make here is primarily just about running in
+       # parallel.
+       if ! test -d "$tmp/rendered/$1"
+       then
+               generate_render_makefile "$tmp/installed/$1" "$tmp/rendered/$1+" |
+               make -j$parallel -f - &&
+               mv "$tmp/rendered/$1+" "$tmp/rendered/$1"
+       fi
+}
+
+render_tree $from_oid "$from" &&
+render_tree $to_oid "$to" &&
+git -C $tmp/rendered diff --no-index "$@" $from_oid $to_oid
index 97d3217df9ac3f048073f62a0d5356c4546354ff..8bc36af4b1b10375c81c6f700ea300cee2295cc1 100644 (file)
@@ -42,6 +42,25 @@ the current repository has the same history as the source repository.
        .git/shallow. This option updates .git/shallow and accept such
        refs.
 
+--negotiation-tip=<commit|glob>::
+       By default, Git will report, to the server, commits reachable
+       from all local refs to find common commits in an attempt to
+       reduce the size of the to-be-received packfile. If specified,
+       Git will only report commits reachable from the given tips.
+       This is useful to speed up fetches when the user knows which
+       local ref is likely to have commits in common with the
+       upstream ref being fetched.
++
+This option may be specified more than once; if so, Git will report
+commits reachable from any of the given commits.
++
+The argument to this option may be a glob on ref names, a ref, or the (possibly
+abbreviated) SHA-1 of a commit. Specifying a glob is equivalent to specifying
+this option multiple times, one for each matching ref name.
++
+See also the `fetch.negotiationAlgorithm` configuration variable
+documented in linkgit:git-config[1].
+
 ifndef::git-pull[]
 --dry-run::
        Show what would be done, without making any changes.
index 78479b003eb3a340da99c533aece8ee9fc19360c..0f9ef2f25e039e2a9ce72988962377439e84590c 100644 (file)
@@ -1103,7 +1103,7 @@ _____________
 Combining test suites, git bisect and other systems together
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-We have seen that test suites an git bisect are very powerful when
+We have seen that test suites and git bisect are very powerful when
 used together. It can be even more powerful if you can combine them
 with other systems.
 
index 02eccbb931eb1ffe6e4c018927eebce8eb98f124..1072ca0eb61e45f5049fedfd24a7512ff81ee957 100644 (file)
@@ -91,7 +91,6 @@ OPTIONS
 -D::
        Shortcut for `--delete --force`.
 
--l::
 --create-reflog::
        Create the branch's reflog.  This activates recording of
        all changes made to the branch ref, enabling use of date
@@ -101,6 +100,8 @@ OPTIONS
        The negated form `--no-create-reflog` only overrides an earlier
        `--create-reflog`, but currently does not negate the setting of
        `core.logAllRefUpdates`.
++
+The `-l` option is a deprecated synonym for `--create-reflog`.
 
 -f::
 --force::
index f90f09b03fae578e867335d1be3ab85d83195f27..74013335a1ccd18228a53acbd8dd7f5fe1ab40ca 100644 (file)
@@ -104,6 +104,16 @@ OPTIONS
        buffering; this is much more efficient when invoking
        `--batch-check` on a large number of objects.
 
+--unordered::
+       When `--batch-all-objects` is in use, visit objects in an
+       order which may be more efficient for accessing the object
+       contents than hash order. The exact details of the order are
+       unspecified, but if you do not require a specific order, this
+       should generally result in faster output, especially with
+       `--batch`.  Note that `cat-file` will still show each object
+       only once, even if it is stored multiple times in the
+       repository.
+
 --allow-unknown-type::
        Allow -s or -t to query broken/corrupt objects of unknown type.
 
index ca5fc9c79887652e38e3d11dc86dba657fe585c0..9db02928c4634ea07c3950b1431bdf9981ec1ab9 100644 (file)
@@ -38,6 +38,15 @@ equivalent to
 $ git checkout -b <branch> --track <remote>/<branch>
 ------------
 +
+If the branch exists in multiple remotes and one of them is named by
+the `checkout.defaultRemote` configuration variable, we'll use that
+one for the purposes of disambiguation, even if the `<branch>` isn't
+unique across all remotes. Set it to
+e.g. `checkout.defaultRemote=origin` to always checkout remote
+branches from there if `<branch>` is ambiguous but exists on the
+'origin' remote. See also `checkout.defaultRemote` in
+linkgit:git-config[1].
++
 You could omit <branch>, in which case the command degenerates to
 "check out the current branch", which is a glorified no-op with
 rather expensive side-effects to show only the tracking information,
index 4c97b555cca5c1daa66c1f44c097ef6a640e0914..dececb79d772447e5ca0d3ea8253f20ea288ddf6 100644 (file)
@@ -10,6 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git commit-graph read' [--object-dir <dir>]
+'git commit-graph verify' [--object-dir <dir>]
 'git commit-graph write' <options> [--object-dir <dir>]
 
 
@@ -37,12 +38,16 @@ Write a commit graph file based on the commits found in packfiles.
 +
 With the `--stdin-packs` option, generate the new commit graph by
 walking objects only in the specified pack-indexes. (Cannot be combined
-with --stdin-commits.)
+with `--stdin-commits` or `--reachable`.)
 +
 With the `--stdin-commits` option, generate the new commit graph by
 walking commits starting at the commits specified in stdin as a list
 of OIDs in hex, one OID per line. (Cannot be combined with
---stdin-packs.)
+`--stdin-packs` or `--reachable`.)
++
+With the `--reachable` option, generate the new commit graph by walking
+commits starting at all refs. (Cannot be combined with `--stdin-commits`
+or `--stdin-packs`.)
 +
 With the `--append` option, include all commits that are present in the
 existing commit-graph file.
@@ -52,6 +57,11 @@ existing commit-graph file.
 Read a graph file given by the commit-graph file and output basic
 details about the graph file. Used for debugging purposes.
 
+'verify'::
+
+Read the commit-graph file and verify its contents against the object
+database. Used to check for corrupted data.
+
 
 EXAMPLES
 --------
index 085d177d976546a0b21891884e490c9ce7530913..901faef1bfdcea991fe1b0a32ab5ecd22771967f 100644 (file)
@@ -57,7 +57,7 @@ OPTIONS
        `xx`; for example `%00` interpolates to `\0` (NUL),
        `%09` to `\t` (TAB) and `%0a` to `\n` (LF).
 
---color[=<when>]:
+--color[=<when>]::
        Respect any colors specified in the `--format` option. The
        `<when>` field must be one of `always`, `never`, or `auto` (if
        `<when>` is absent, behave as if `always` was given).
index b9f060e3b207f981932957d8148dfcfcd912e33c..ab9a93fb9b8fb7291362cc419a7aca8b464d3d76 100644 (file)
@@ -110,6 +110,9 @@ Any corrupt objects you will have to find in backups or other archives
 (i.e., you can just remove them and do an 'rsync' with some other site in
 the hopes that somebody else has the object you have corrupted).
 
+If core.commitGraph is true, the commit-graph file will also be inspected
+using 'git commit-graph verify'. See linkgit:git-commit-graph[1].
+
 Extracted Diagnostics
 ---------------------
 
index 24b2dd44fe445a66121fa957f0af8e2209a85676..f5bc98ccb3673079fa2e1205b57bc87acb3c1e90 100644 (file)
@@ -136,6 +136,10 @@ The optional configuration variable `gc.packRefs` determines if
 it within all non-bare repos or it can be set to a boolean value.
 This defaults to true.
 
+The optional configuration variable `gc.commitGraph` determines if
+'git gc' should run 'git commit-graph write'. This can be set to a
+boolean value. This defaults to false.
+
 The optional configuration variable `gc.aggressiveWindow` controls how
 much time is spent optimizing the delta compression of the objects in
 the repository when the --aggressive option is specified.  The larger
index 312409a607231d66bd296c1d955bb62c47ecffcf..a3049af1a36c09325a88ad2cc822ae2891c8974b 100644 (file)
@@ -13,11 +13,11 @@ SYNOPSIS
           [-v | --invert-match] [-h|-H] [--full-name]
           [-E | --extended-regexp] [-G | --basic-regexp]
           [-P | --perl-regexp]
-          [-F | --fixed-strings] [-n | --line-number]
+          [-F | --fixed-strings] [-n | --line-number] [--column]
           [-l | --files-with-matches] [-L | --files-without-match]
           [(-O | --open-files-in-pager) [<pager>]]
           [-z | --null]
-          [-c | --count] [--all-match] [-q | --quiet]
+          [ -o | --only-matching ] [-c | --count] [--all-match] [-q | --quiet]
           [--max-depth <depth>]
           [--color[=<when>] | --no-color]
           [--break] [--heading] [-p | --show-function]
@@ -44,6 +44,9 @@ CONFIGURATION
 grep.lineNumber::
        If set to true, enable `-n` option by default.
 
+grep.column::
+       If set to true, enable the `--column` option by default.
+
 grep.patternType::
        Set the default matching behavior. Using a value of 'basic', 'extended',
        'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,
@@ -169,6 +172,10 @@ providing this option will cause it to die.
 --line-number::
        Prefix the line number to matching lines.
 
+--column::
+       Prefix the 1-indexed byte-offset of the first match from the start of the
+       matching line.
+
 -l::
 --files-with-matches::
 --name-only::
@@ -194,6 +201,11 @@ providing this option will cause it to die.
        Output \0 instead of the character that normally follows a
        file name.
 
+-o::
+--only-matching::
+       Print only the matched (non-empty) parts of a matching line, with each such
+       part on a separate output line.
+
 -c::
 --count::
        Instead of showing every matched line, show the number of
index 032613c420cf3cbcf75e82fc89abed6ec8d85355..7b157441eb3ee9e84e98f36f74a6083f071f36e1 100644 (file)
@@ -68,8 +68,8 @@ imap.tunnel::
        to the server. Required when imap.host is not set.
 
 imap.host::
-       A URL identifying the server. Use a `imap://` prefix for non-secure
-       connections and a `imaps://` prefix for secure connections.
+       A URL identifying the server. Use an `imap://` prefix for non-secure
+       connections and an `imaps://` prefix for secure connections.
        Ignored when imap.tunnel is set, but required otherwise.
 
 imap.user::
index 9111c47a1bf2c22466bb74d3b3bca540c4fb0eb2..b8fafb1e8bdd6c3e061b88b227e1ef264bbfbd07 100644 (file)
@@ -88,7 +88,8 @@ OPTIONS
        Specify where all new trailers will be added.  A setting
        provided with '--where' overrides all configuration variables
        and applies to all '--trailer' options until the next occurrence of
-       '--where' or '--no-where'.
+       '--where' or '--no-where'. Possible values are `after`, `before`,
+       `end` or `start`.
 
 --if-exists <action>::
 --no-if-exists::
@@ -96,7 +97,8 @@ OPTIONS
        least one trailer with the same <token> in the message.  A setting
        provided with '--if-exists' overrides all configuration variables
        and applies to all '--trailer' options until the next occurrence of
-       '--if-exists' or '--no-if-exists'.
+       '--if-exists' or '--no-if-exists'. Possible actions are `addIfDifferent`,
+       `addIfDifferentNeighbor`, `add`, `replace` and `doNothing`.
 
 --if-missing <action>::
 --no-if-missing::
@@ -104,7 +106,8 @@ OPTIONS
        trailer with the same <token> in the message.  A setting
        provided with '--if-missing' overrides all configuration variables
        and applies to all '--trailer' options until the next occurrence of
-       '--if-missing' or '--no-if-missing'.
+       '--if-missing' or '--no-if-missing'. Possible actions are `doNothing`
+       or `add`.
 
 --only-trailers::
        Output only the trailers, not any other parts of the input.
index 6a5c00e2c2b5b5201e42e12b74d8ae5128ce9c93..eb36837f86e21423e0a543eceb67313eed27d310 100644 (file)
@@ -12,7 +12,7 @@ SYNOPSIS
 'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
        [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
        [--[no-]allow-unrelated-histories]
-       [--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]
+       [--[no-]rerere-autoupdate] [-m <msg>] [-F <file>] [<commit>...]
 'git merge' --abort
 'git merge' --continue
 
@@ -75,6 +75,14 @@ The 'git fmt-merge-msg' command can be
 used to give a good default for automated 'git merge'
 invocations. The automated message can include the branch description.
 
+-F <file>::
+--file=<file>::
+       Read the commit message to be used for the merge commit (in
+       case one is created).
++
+If `--log` is specified, a shortlog of the commits being merged
+will be appended to the specified message.
+
 --[no-]rerere-autoupdate::
        Allow the rerere mechanism to update the index with the
        result of auto-conflict resolution if possible.
@@ -122,9 +130,9 @@ merge' may need to update.
 
 To avoid recording unrelated changes in the merge commit,
 'git pull' and 'git merge' will also abort if there are any changes
-registered in the index relative to the `HEAD` commit.  (One
-exception is when the changed index entries are in the state that
-would result from the merge already.)
+registered in the index relative to the `HEAD` commit.  (Special
+narrow exceptions to this rule may exist depending on which merge
+strategy is in use, but generally, the index must match HEAD.)
 
 If all named commits are already ancestors of `HEAD`, 'git merge'
 will exit early with the message "Already up to date."
index e8dec1b3c89a66dc2f9e78737fa7d243bee85d37..df2b64dbb618e3cf7c538798f5f18ebc41e7eff6 100644 (file)
@@ -199,7 +199,7 @@ OPTIONS
        .git/NOTES_MERGE_REF symref is updated to the resulting commit.
 
 --abort::
-       Abort/reset a in-progress 'git notes merge', i.e. a notes merge
+       Abort/reset an in-progress 'git notes merge', i.e. a notes merge
        with conflicts. This simply removes all files related to the
        notes merge.
 
index f0de3b891b297bb92ffb0323f5bfec5944b9c3aa..41780a5aa970fb46538373afbf6684a526803f63 100644 (file)
@@ -374,6 +374,14 @@ These options can be used to modify 'git p4 submit' behavior.
     been submitted. Implies --disable-rebase. Can also be set with
     git-p4.disableP4Sync. Sync with origin/master still goes ahead if possible.
 
+Hook for submit
+~~~~~~~~~~~~~~~
+The `p4-pre-submit` hook is executed if it exists and is executable.
+The hook takes no parameters and nothing from standard input. Exiting with
+non-zero status from this script prevents `git-p4 submit` from launching.
+
+One usage scenario is to run unit tests in the hook.
+
 Rebase options
 ~~~~~~~~~~~~~~
 These options can be used to modify 'git p4 rebase' behavior.
diff --git a/Documentation/git-range-diff.txt b/Documentation/git-range-diff.txt
new file mode 100644 (file)
index 0000000..f693930
--- /dev/null
@@ -0,0 +1,252 @@
+git-range-diff(1)
+=================
+
+NAME
+----
+git-range-diff - Compare two commit ranges (e.g. two versions of a branch)
+
+SYNOPSIS
+--------
+[verse]
+'git range-diff' [--color=[<when>]] [--no-color] [<diff-options>]
+       [--no-dual-color] [--creation-factor=<factor>]
+       ( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> )
+
+DESCRIPTION
+-----------
+
+This command shows the differences between two versions of a patch
+series, or more generally, two commit ranges (ignoring merge commits).
+
+To that end, it first finds pairs of commits from both commit ranges
+that correspond with each other. Two commits are said to correspond when
+the diff between their patches (i.e. the author information, the commit
+message and the commit diff) is reasonably small compared to the
+patches' size. See ``Algorithm`` below for details.
+
+Finally, the list of matching commits is shown in the order of the
+second commit range, with unmatched commits being inserted just after
+all of their ancestors have been shown.
+
+
+OPTIONS
+-------
+--no-dual-color::
+       When the commit diffs differ, `git range-diff` recreates the
+       original diffs' coloring, and adds outer -/+ diff markers with
+       the *background* being red/green to make it easier to see e.g.
+       when there was a change in what exact lines were added.
++
+Additionally, the commit diff lines that are only present in the first commit
+range are shown "dimmed" (this can be overridden using the `color.diff.<slot>`
+config setting where `<slot>` is one of `contextDimmed`, `oldDimmed` and
+`newDimmed`), and the commit diff lines that are only present in the second
+commit range are shown in bold (which can be overridden using the config
+settings `color.diff.<slot>` with `<slot>` being one of `contextBold`,
+`oldBold` or `newBold`).
++
+This is known to `range-diff` as "dual coloring". Use `--no-dual-color`
+to revert to color all lines according to the outer diff markers
+(and completely ignore the inner diff when it comes to color).
+
+--creation-factor=<percent>::
+       Set the creation/deletion cost fudge factor to `<percent>`.
+       Defaults to 60. Try a larger value if `git range-diff` erroneously
+       considers a large change a total rewrite (deletion of one commit
+       and addition of another), and a smaller one in the reverse case.
+       See the ``Algorithm`` section below for an explanation why this is
+       needed.
+
+<range1> <range2>::
+       Compare the commits specified by the two ranges, where
+       `<range1>` is considered an older version of `<range2>`.
+
+<rev1>...<rev2>::
+       Equivalent to passing `<rev2>..<rev1>` and `<rev1>..<rev2>`.
+
+<base> <rev1> <rev2>::
+       Equivalent to passing `<base>..<rev1>` and `<base>..<rev2>`.
+       Note that `<base>` does not need to be the exact branch point
+       of the branches. Example: after rebasing a branch `my-topic`,
+       `git range-diff my-topic@{u} my-topic@{1} my-topic` would
+       show the differences introduced by the rebase.
+
+`git range-diff` also accepts the regular diff options (see
+linkgit:git-diff[1]), most notably the `--color=[<when>]` and
+`--no-color` options. These options are used when generating the "diff
+between patches", i.e. to compare the author, commit message and diff of
+corresponding old/new commits. There is currently no means to tweak the
+diff options passed to `git log` when generating those patches.
+
+
+CONFIGURATION
+-------------
+This command uses the `diff.color.*` and `pager.range-diff` settings
+(the latter is on by default).
+See linkgit:git-config[1].
+
+
+EXAMPLES
+--------
+
+When a rebase required merge conflicts to be resolved, compare the changes
+introduced by the rebase directly afterwards using:
+
+------------
+$ git range-diff @{u} @{1} @
+------------
+
+
+A typical output of `git range-diff` would look like this:
+
+------------
+-:  ------- > 1:  0ddba11 Prepare for the inevitable!
+1:  c0debee = 2:  cab005e Add a helpful message at the start
+2:  f00dbal ! 3:  decafe1 Describe a bug
+    @@ -1,3 +1,3 @@
+     Author: A U Thor <author@example.com>
+
+    -TODO: Describe a bug
+    +Describe a bug
+    @@ -324,5 +324,6
+      This is expected.
+
+    -+What is unexpected is that it will also crash.
+    ++Unexpectedly, it also crashes. This is a bug, and the jury is
+    ++still out there how to fix it best. See ticket #314 for details.
+
+      Contact
+3:  bedead < -:  ------- TO-UNDO
+------------
+
+In this example, there are 3 old and 3 new commits, where the developer
+removed the 3rd, added a new one before the first two, and modified the
+commit message of the 2nd commit as well its diff.
+
+When the output goes to a terminal, it is color-coded by default, just
+like regular `git diff`'s output. In addition, the first line (adding a
+commit) is green, the last line (deleting a commit) is red, the second
+line (with a perfect match) is yellow like the commit header of `git
+show`'s output, and the third line colors the old commit red, the new
+one green and the rest like `git show`'s commit header.
+
+A naive color-coded diff of diffs is actually a bit hard to read,
+though, as it colors the entire lines red or green. The line that added
+"What is unexpected" in the old commit, for example, is completely red,
+even if the intent of the old commit was to add something.
+
+To help with that, `range` uses the `--dual-color` mode by default. In
+this mode, the diff of diffs will retain the original diff colors, and
+prefix the lines with -/+ markers that have their *background* red or
+green, to make it more obvious that they describe how the diff itself
+changed.
+
+
+Algorithm
+---------
+
+The general idea is this: we generate a cost matrix between the commits
+in both commit ranges, then solve the least-cost assignment.
+
+The cost matrix is populated thusly: for each pair of commits, both
+diffs are generated and the "diff of diffs" is generated, with 3 context
+lines, then the number of lines in that diff is used as cost.
+
+To avoid false positives (e.g. when a patch has been removed, and an
+unrelated patch has been added between two iterations of the same patch
+series), the cost matrix is extended to allow for that, by adding
+fixed-cost entries for wholesale deletes/adds.
+
+Example: Let commits `1--2` be the first iteration of a patch series and
+`A--C` the second iteration. Let's assume that `A` is a cherry-pick of
+`2,` and `C` is a cherry-pick of `1` but with a small modification (say,
+a fixed typo). Visualize the commits as a bipartite graph:
+
+------------
+    1            A
+
+    2            B
+
+                C
+------------
+
+We are looking for a "best" explanation of the new series in terms of
+the old one. We can represent an "explanation" as an edge in the graph:
+
+
+------------
+    1            A
+              /
+    2 --------'  B
+
+                C
+------------
+
+This explanation comes for "free" because there was no change. Similarly
+`C` could be explained using `1`, but that comes at some cost c>0
+because of the modification:
+
+------------
+    1 ----.      A
+         |    /
+    2 ----+---'  B
+         |
+         `----- C
+         c>0
+------------
+
+In mathematical terms, what we are looking for is some sort of a minimum
+cost bipartite matching; `1` is matched to `C` at some cost, etc. The
+underlying graph is in fact a complete bipartite graph; the cost we
+associate with every edge is the size of the diff between the two
+commits' patches. To explain also new commits, we introduce dummy nodes
+on both sides:
+
+------------
+    1 ----.      A
+         |    /
+    2 ----+---'  B
+         |
+    o     `----- C
+         c>0
+    o            o
+
+    o            o
+------------
+
+The cost of an edge `o--C` is the size of `C`'s diff, modified by a
+fudge factor that should be smaller than 100%. The cost of an edge
+`o--o` is free. The fudge factor is necessary because even if `1` and
+`C` have nothing in common, they may still share a few empty lines and
+such, possibly making the assignment `1--C`, `o--o` slightly cheaper
+than `1--o`, `o--C` even if `1` and `C` have nothing in common. With the
+fudge factor we require a much larger common part to consider patches as
+corresponding.
+
+The overall time needed to compute this algorithm is the time needed to
+compute n+m commit diffs and then n*m diffs of patches, plus the time
+needed to compute the least-cost assigment between n and m diffs. Git
+uses an implementation of the Jonker-Volgenant algorithm to solve the
+assignment problem, which has cubic runtime complexity. The matching
+found in this case will look like this:
+
+------------
+    1 ----.      A
+         |    /
+    2 ----+---'  B
+       .--+-----'
+    o -'  `----- C
+         c>0
+    o ---------- o
+
+    o ---------- o
+------------
+
+
+SEE ALSO
+--------
+linkgit:git-log[1]
+
+GIT
+---
+Part of the linkgit:git[1] suite
index 0e20a66e73cf420c83b156d1a0aaa8f60cd4702f..1fbc6ebcde0945fe6bc8cc85e5fd31247c4879e4 100644 (file)
@@ -243,11 +243,15 @@ leave out at most one of A and B, in which case it defaults to HEAD.
 --keep-empty::
        Keep the commits that do not change anything from its
        parents in the result.
++
+See also INCOMPATIBLE OPTIONS below.
 
 --allow-empty-message::
        By default, rebasing commits with an empty message will fail.
        This option overrides that behavior, allowing commits with empty
        messages to be rebased.
++
+See also INCOMPATIBLE OPTIONS below.
 
 --skip::
        Restart the rebasing process by skipping the current patch.
@@ -271,6 +275,8 @@ branch on top of the <upstream> branch.  Because of this, when a merge
 conflict happens, the side reported as 'ours' is the so-far rebased
 series, starting with <upstream>, and 'theirs' is the working branch.  In
 other words, the sides are swapped.
++
+See also INCOMPATIBLE OPTIONS below.
 
 -s <strategy>::
 --strategy=<strategy>::
@@ -280,8 +286,10 @@ other words, the sides are swapped.
 +
 Because 'git rebase' replays each commit from the working branch
 on top of the <upstream> branch using the given strategy, using
-the 'ours' strategy simply discards all patches from the <branch>,
+the 'ours' strategy simply empties all patches from the <branch>,
 which makes little sense.
++
+See also INCOMPATIBLE OPTIONS below.
 
 -X <strategy-option>::
 --strategy-option=<strategy-option>::
@@ -289,6 +297,8 @@ which makes little sense.
        This implies `--merge` and, if no strategy has been
        specified, `-s recursive`.  Note the reversal of 'ours' and
        'theirs' as noted above for the `-m` option.
++
+See also INCOMPATIBLE OPTIONS below.
 
 -S[<keyid>]::
 --gpg-sign[=<keyid>]::
@@ -324,17 +334,21 @@ which makes little sense.
        and after each change.  When fewer lines of surrounding
        context exist they all must match.  By default no context is
        ever ignored.
++
+See also INCOMPATIBLE OPTIONS below.
 
--f::
+--no-ff::
 --force-rebase::
-       Force a rebase even if the current branch is up to date and
-       the command without `--force` would return without doing anything.
+-f::
+       Individually replay all rebased commits instead of fast-forwarding
+       over the unchanged ones.  This ensures that the entire history of
+       the rebased branch is composed of new commits.
 +
-You may find this (or --no-ff with an interactive rebase) helpful after
-reverting a topic branch merge, as this option recreates the topic branch with
-fresh commits so it can be remerged successfully without needing to "revert
-the reversion" (see the
-link:howto/revert-a-faulty-merge.html[revert-a-faulty-merge How-To] for details).
+You may find this helpful after reverting a topic branch merge, as this option
+recreates the topic branch with fresh commits so it can be remerged
+successfully without needing to "revert the reversion" (see the
+link:howto/revert-a-faulty-merge.html[revert-a-faulty-merge How-To] for
+details).
 
 --fork-point::
 --no-fork-point::
@@ -355,19 +369,22 @@ default is `--no-fork-point`, otherwise the default is `--fork-point`.
 --whitespace=<option>::
        These flag are passed to the 'git apply' program
        (see linkgit:git-apply[1]) that applies the patch.
-       Incompatible with the --interactive option.
++
+See also INCOMPATIBLE OPTIONS below.
 
 --committer-date-is-author-date::
 --ignore-date::
        These flags are passed to 'git am' to easily change the dates
        of the rebased commits (see linkgit:git-am[1]).
-       Incompatible with the --interactive option.
++
+See also INCOMPATIBLE OPTIONS below.
 
 --signoff::
        Add a Signed-off-by: trailer to all the rebased commits. Note
        that if `--interactive` is given then only commits marked to be
-       picked, edited or reworded will have the trailer added. Incompatible
-       with the `--preserve-merges` option.
+       picked, edited or reworded will have the trailer added.
++
+See also INCOMPATIBLE OPTIONS below.
 
 -i::
 --interactive::
@@ -378,6 +395,8 @@ default is `--no-fork-point`, otherwise the default is `--fork-point`.
 The commit list format can be changed by setting the configuration option
 rebase.instructionFormat.  A customized instruction format will automatically
 have the long commit hash prepended to the format.
++
+See also INCOMPATIBLE OPTIONS below.
 
 -r::
 --rebase-merges[=(rebase-cousins|no-rebase-cousins)]::
@@ -404,7 +423,7 @@ It is currently only possible to recreate the merge commits using the
 `recursive` merge strategy; Different merge strategies can be used only via
 explicit `exec git merge -s <strategy> [...]` commands.
 +
-See also REBASING MERGES below.
+See also REBASING MERGES and INCOMPATIBLE OPTIONS below.
 
 -p::
 --preserve-merges::
@@ -415,6 +434,8 @@ See also REBASING MERGES below.
 This uses the `--interactive` machinery internally, but combining it
 with the `--interactive` option explicitly is generally not a good
 idea unless you know what you are doing (see BUGS below).
++
+See also INCOMPATIBLE OPTIONS below.
 
 -x <cmd>::
 --exec <cmd>::
@@ -437,6 +458,8 @@ squash/fixup series.
 +
 This uses the `--interactive` machinery internally, but it can be run
 without an explicit `--interactive`.
++
+See also INCOMPATIBLE OPTIONS below.
 
 --root::
        Rebase all commits reachable from <branch>, instead of
@@ -447,6 +470,8 @@ without an explicit `--interactive`.
        When used together with both --onto and --preserve-merges,
        'all' root commits will be rewritten to have <newbase> as parent
        instead.
++
+See also INCOMPATIBLE OPTIONS below.
 
 --autosquash::
 --no-autosquash::
@@ -461,11 +486,11 @@ without an explicit `--interactive`.
        too.  The recommended way to create fixup/squash commits is by using
        the `--fixup`/`--squash` options of linkgit:git-commit[1].
 +
-This option is only valid when the `--interactive` option is used.
-+
 If the `--autosquash` option is enabled by default using the
 configuration variable `rebase.autoSquash`, this option can be
 used to override and disable this setting.
++
+See also INCOMPATIBLE OPTIONS below.
 
 --autostash::
 --no-autostash::
@@ -475,17 +500,73 @@ used to override and disable this setting.
        with care: the final stash application after a successful
        rebase might result in non-trivial conflicts.
 
---no-ff::
-       With --interactive, cherry-pick all rebased commits instead of
-       fast-forwarding over the unchanged ones.  This ensures that the
-       entire history of the rebased branch is composed of new commits.
-+
-Without --interactive, this is a synonym for --force-rebase.
-+
-You may find this helpful after reverting a topic branch merge, as this option
-recreates the topic branch with fresh commits so it can be remerged
-successfully without needing to "revert the reversion" (see the
-link:howto/revert-a-faulty-merge.html[revert-a-faulty-merge How-To] for details).
+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:
+
+ * --committer-date-is-author-date
+ * --ignore-date
+ * --whitespace
+ * --ignore-whitespace
+ * -C
+
+Flags understood by both merge and interactive backends:
+
+ * --merge
+ * --strategy
+ * --strategy-option
+ * --allow-empty-message
+
+Flags only understood by the interactive backend:
+
+ * --[no-]autosquash
+ * --rebase-merges
+ * --preserve-merges
+ * --interactive
+ * --exec
+ * --keep-empty
+ * --autosquash
+ * --edit-todo
+ * --root when used in combination with --onto
+
+Other incompatible flag pairs:
+
+ * --preserve-merges and --interactive
+ * --preserve-merges and --signoff
+ * --preserve-merges and --rebase-merges
+ * --rebase-merges and --strategy
+ * --rebase-merges and --strategy-option
+
+BEHAVIORAL DIFFERENCES
+-----------------------
+
+ * empty commits:
+
+    am-based rebase will drop any "empty" commits, whether the
+    commit started empty (had no changes relative to its parent to
+    start with) or ended empty (all changes were already applied
+    upstream in other commits).
+
+    merge-based rebase does the same.
+
+    interactive-based rebase will by default drop commits that
+    started empty and halt if it hits a commit that ended up empty.
+    The `--keep-empty` option exists for interactive rebases to allow
+    it to keep commits that started empty.
+
+  * directory rename detection:
+
+    merge-based and interactive-based rebases work fine with
+    directory rename detection.  am-based rebases sometimes do not.
 
 include::merge-strategies.txt[]
 
@@ -804,7 +885,7 @@ The ripple effect of a "hard case" recovery is especially bad:
 case" recovery too!
 
 REBASING MERGES
------------------
+---------------
 
 The interactive rebase command was originally designed to handle
 individual patch series. As such, it makes sense to exclude merge
@@ -879,8 +960,8 @@ rescheduled immediately, with a helpful message how to edit the todo list
 (this typically happens when a `reset` command was inserted into the todo
 list manually and contains a typo).
 
-The `merge` command will merge the specified revision into whatever is
-HEAD at that time. With `-C <original-commit>`, the commit message of
+The `merge` command will merge the specified revision(s) into whatever
+is HEAD at that time. With `-C <original-commit>`, the commit message of
 the specified merge commit will be used. When the `-C` is changed to
 a lower-case `-c`, the message will be opened in an editor after a
 successful merge so that the user can edit the message.
@@ -889,7 +970,8 @@ If a `merge` command fails for any reason other than merge conflicts (i.e.
 when the merge operation did not even start), it is rescheduled immediately.
 
 At this time, the `merge` command will *always* use the `recursive`
-merge strategy, with no way to choose a different one. To work around
+merge strategy for regular merges, and `octopus` for octopus merges,
+strategy, with no way to choose a different one. To work around
 this, an `exec` command can be used to call `git merge` explicitly,
 using the fact that the labels are worktree-local refs (the ref
 `refs/rewritten/onto` would correspond to the label `onto`, for example).
index 4f3efde80cd8e4f0b1a5b6699ad3e569f19ca516..465a4ecbeddaa20189bce6e223df8bbfa0319b9a 100644 (file)
@@ -137,15 +137,17 @@ Note that no attempts whatsoever are made to validate the encoding.
        Specify encoding of compose message. Default is the value of the
        'sendemail.composeencoding'; if that is unspecified, UTF-8 is assumed.
 
---transfer-encoding=(7bit|8bit|quoted-printable|base64)::
+--transfer-encoding=(7bit|8bit|quoted-printable|base64|auto)::
        Specify the transfer encoding to be used to send the message over SMTP.
        7bit will fail upon encountering a non-ASCII message.  quoted-printable
        can be useful when the repository contains files that contain carriage
        returns, but makes the raw patch email file (as saved from a MUA) much
        harder to inspect manually.  base64 is even more fool proof, but also
-       even more opaque.  Default is the value of the `sendemail.transferEncoding`
-       configuration value; if that is unspecified, git will use 8bit and not
-       add a Content-Transfer-Encoding header.
+       even more opaque.  auto will use 8bit when possible, and quoted-printable
+       otherwise.
++
+Default is the value of the `sendemail.transferEncoding` configuration
+value; if that is unspecified, default to `auto`.
 
 --xmailer::
 --no-xmailer::
@@ -398,8 +400,11 @@ have been specified, in which case default to 'compose'.
 +
 --
                *       Invoke the sendemail-validate hook if present (see linkgit:githooks[5]).
-               *       Warn of patches that contain lines longer than 998 characters; this
-                       is due to SMTP limits as described by http://www.ietf.org/rfc/rfc2821.txt.
+               *       Warn of patches that contain lines longer than
+                       998 characters unless a suitable transfer encoding
+                       ('auto', 'base64', or 'quoted-printable') is used;
+                       this is due to SMTP limits as described by
+                       http://www.ietf.org/rfc/rfc5322.txt.
 --
 +
 Default is the value of `sendemail.validate`; if this is not set,
index c4467ffb98a95fa6bb5dc86a92dee3317be9c0ea..d9f422d5600af6b112eba692d5c5607cdb4169ef 100644 (file)
@@ -106,7 +106,7 @@ It is optional: it defaults to 'traditional'.
 The possible options are:
 +
        - 'traditional' - Shows ignored files and directories, unless
-                         --untracked-files=all is specifed, in which case
+                         --untracked-files=all is specified, in which case
                          individual files in ignored directories are
                          displayed.
        - 'no'          - Show no ignored files.
index 7ea24fc942c18c032048edc10dfe00b56bff991e..b99029520d9b17e76ab65b4333a79fe20ed22eff 100644 (file)
@@ -452,7 +452,7 @@ Any other arguments are passed directly to 'git log'
 
 'commit-diff'::
        Commits the diff of two tree-ish arguments from the
-       command-line.  This command does not rely on being inside an `git svn
+       command-line.  This command does not rely on being inside a `git svn
        init`-ed repository.  This command takes three arguments, (a) the
        original tree to diff against, (b) the new tree result, (c) the
        URL of the target Subversion repository.  The final argument
index 87c4288ffc47ddd73162c85a27fe22c161b4a441..92f9c12b873f92c9f66a460272ccc0d235a6cad9 100644 (file)
@@ -115,7 +115,7 @@ options for details.
        variable if it exists, or lexicographic order otherwise. See
        linkgit:git-config[1].
 
---color[=<when>]:
+--color[=<when>]::
        Respect any colors specified in the `--format` option. The
        `<when>` field must be one of `always`, `never`, or `auto` (if
        `<when>` is absent, behave as if `always` was given).
index 4e8e762e68690cab880460fbe1fef0077c8351e2..1c4d146a41ce091755b2e4baef0fa79f45a4b515 100644 (file)
@@ -245,10 +245,10 @@ USING --CACHEINFO OR --INFO-ONLY
 current working directory.  This is useful for minimum-checkout
 merging.
 
-To pretend you have a file with mode and sha1 at path, say:
+To pretend you have a file at path with mode and sha1, say:
 
 ----------------
-$ git update-index --cacheinfo <mode>,<sha1>,<path>
+$ git update-index --add --cacheinfo <mode>,<sha1>,<path>
 ----------------
 
 `--info-only` is used to register files without placing them in the object
@@ -268,23 +268,20 @@ USING --INDEX-INFO
 multiple entry definitions from the standard input, and designed
 specifically for scripts.  It can take inputs of three formats:
 
-    . mode         SP sha1          TAB path
-+
-The first format is what "git-apply --index-info"
-reports, and used to reconstruct a partial tree
-that is used for phony merge base tree when falling
-back on 3-way merge.
-
     . mode SP type SP sha1          TAB path
 +
-The second format is to stuff 'git ls-tree' output
-into the index file.
+This format is to stuff `git ls-tree` output into the index.
 
     . mode         SP sha1 SP stage TAB path
 +
 This format is to put higher order stages into the
 index file and matches 'git ls-files --stage' output.
 
+    . mode         SP sha1          TAB path
++
+This format is no longer produced by any Git command, but is
+and will continue to be supported by `update-index --index-info`.
+
 To place a higher stage entry to the index, the path should
 first be removed by feeding a mode=0 entry for the path, and
 then feeding necessary input lines in the third format.
index afc6576a14d56ea49e37d1251a5665bf77457f89..9c26be40f4412b5f0a9c478236b9d3c38fcb14ec 100644 (file)
@@ -60,6 +60,15 @@ with a matching name, treat as equivalent to:
 $ git worktree add --track -b <branch> <path> <remote>/<branch>
 ------------
 +
+If the branch exists in multiple remotes and one of them is named by
+the `checkout.defaultRemote` configuration variable, we'll use that
+one for the purposes of disambiguation, even if the `<branch>` isn't
+unique across all remotes. Set it to
+e.g. `checkout.defaultRemote=origin` to always checkout remote
+branches from there if `<branch>` is ambiguous but exists on the
+'origin' remote. See also `checkout.defaultRemote` in
+linkgit:git-config[1].
++
 If `<commit-ish>` is omitted and neither `-b` nor `-B` nor `--detach` used,
 then, as a convenience, the new worktree is associated with a branch
 (call it `<branch>`) named after `$(basename <path>)`.  If `<branch>`
index 10c8ff93c0b9f55ff19a8b54cdeed2fdad93b92b..9f2528fc8c81622c237f7bc80289137d8f4f750b 100644 (file)
@@ -244,7 +244,7 @@ commands in addition to the ones needed by participants.
 
 This section can also be used by those who respond to `git
 request-pull` or pull-request on GitHub (www.github.com) to
-integrate the work of others into their history. An sub-area
+integrate the work of others into their history. A sub-area
 lieutenant for a repository will act both as a participant and
 as an integrator.
 
index e3c283a174c46352f26e3e6a957e72b76bf82680..959044347e5ee0daf78b3503794e2bf3c51f0efb 100644 (file)
@@ -485,6 +485,13 @@ The exit status determines whether git will use the data from the
 hook to limit its search.  On error, it will fall back to verifying
 all files and folders.
 
+p4-pre-submit
+~~~~~~~~~~~~~
+
+This hook is invoked by `git-p4 submit`. It takes no parameters and nothing
+from standard input. Exiting with non-zero status from this script prevent
+`git-p4 submit` from launching. Run `git-p4 submit --help` for details.
+
 GIT
 ---
 Part of the linkgit:git[1] suite
index ff5d7f9ed6f089646807f93d59e35a10763e46c2..d107daaffd4e84921c47951cf743d1eace11c525 100644 (file)
@@ -7,7 +7,7 @@ gitignore - Specifies intentionally untracked files to ignore
 
 SYNOPSIS
 --------
-$HOME/.config/git/ignore, $GIT_DIR/info/exclude, .gitignore
+$XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, .gitignore
 
 DESCRIPTION
 -----------
index 3b9faabdbb9cbc45893dff67fd40b0ed7552f287..504c5f1a885dfb20c37a9f87bdbdbd452cd216bd 100644 (file)
@@ -194,7 +194,7 @@ In the above config only the submodule 'bar' and 'baz' are active,
 
 Note that (c) is a historical artefact and will be ignored if the
 (a) and (b) specify that the submodule is not active. In other words,
-if we have an `submodule.<name>.active` set to `false` or if the
+if we have a `submodule.<name>.active` set to `false` or if the
 submodule's path is excluded in the pathspec in `submodule.active`, the
 url doesn't matter whether it is present or not. This is illustrated in
 the example that follows.
index 6c2d23dc489474958d39d8053fc799b8616aafee..0d2aa48c63856aba78d559445186a9b9e6bddd7d 100644 (file)
@@ -334,7 +334,7 @@ The optional colon that terminates the "magic signature" can be
 omitted if the pattern begins with a character that does not belong to
 "magic signature" symbol set and is not a colon.
 +
-In the long form, the leading colon `:` is followed by a open
+In the long form, the leading colon `:` is followed by an open
 parenthesis `(`, a comma-separated list of zero or more "magic words",
 and a close parentheses `)`, and the remainder is the pattern to match
 against the path.
index c579793af5b41a01fecda884c514ff78bf25672a..f1fb08dc683778b2ebddd4a92c8d3d5d17ee4b7f 100644 (file)
@@ -33,7 +33,7 @@ name.
 it requests fetching everything up to the given tag.
 +
 The remote ref that matches <src>
-is fetched, and if <dst> is not empty string, the local
+is fetched, and if <dst> is not an empty string, the local
 ref that matches it is fast-forwarded using <src>.
 If the optional plus `+` is used, the local ref
 is updated even if it does not result in a fast-forward
index 7d1bd440944149bb8de03a9a202e46c85ec646f2..72daa20e76fa0a0c10feaf37f927797ad1445934 100644 (file)
@@ -184,7 +184,8 @@ existing tag object.
   A colon, followed by a slash, followed by a text, names
   a commit whose commit message matches the specified regular expression.
   This name returns the youngest matching commit which is
-  reachable from any ref. The regular expression can match any part of the
+  reachable from any ref, including HEAD.
+  The regular expression can match any part of the
   commit message. To match messages starting with a string, one can use
   e.g. ':/^foo'. The special sequence ':/!' is reserved for modifiers to what
   is matched. ':/!-foo' performs a negative match, while ':/!!foo' matches a
index 4f44ca24f6457e6acf208d7068dfcd02039cf41b..5abb8e8b1fdb37f9948ea2e09bae6380cb11041b 100644 (file)
@@ -54,7 +54,7 @@ The notable options are:
        this case, the contents are returned as individual entries.
 +
 If this is set, files and directories that explicitly match an ignore
-pattern are reported. Implicity ignored directories (directories that
+pattern are reported. Implicitly ignored directories (directories that
 do not match an ignore pattern, but whose contents are all ignored)
 are not reported, instead all of the contents are reported.
 
index e7cbb7c13adf2f7ea3b15279a17f1a06da859cbc..45f0df600fab616688154df39775cbbc0f91ebd3 100644 (file)
@@ -146,7 +146,7 @@ To get the values of all attributes associated with a file:
 
 * Iterate over the `attr_check.items[]` array to examine
   the attribute names and values.  The name of the attribute
-  described by a  `attr_check.items[]` object can be retrieved via
+  described by an `attr_check.items[]` object can be retrieved via
   `git_attr_name(check->items[i].attr)`.  (Please note that no items
   will be returned for unset attributes, so `ATTR_UNSET()` will return
   false for all returned `attr_check.items[]` objects.)
index ad6af8105cf68e9e607cf67032e445094e53daf9..cc0474ba3ee4b04153752340328233437d5c7b05 100644 (file)
@@ -18,9 +18,9 @@ metadata, including:
   the graph file.
 
 These positional references are stored as unsigned 32-bit integers
-corresponding to the array position withing the list of commit OIDs. We
-use the most-significant bit for special purposes, so we can store at most
-(1 << 31) - 1 (around 2 billion) commits.
+corresponding to the array position within the list of commit OIDs. Due
+to some special constants we use to track parents, we can store at most
+(1 << 30) + (1 << 29) + (1 << 28) - 1 (around 1.8 billion) commits.
 
 == Commit graph files have the following format:
 
@@ -70,10 +70,10 @@ CHUNK DATA:
   OID Lookup (ID: {'O', 'I', 'D', 'L'}) (N * H bytes)
       The OIDs for all commits in the graph, sorted in ascending order.
 
-  Commit Data (ID: {'C', 'G', 'E', 'T' }) (N * (H + 16) bytes)
+  Commit Data (ID: {'C', 'D', 'A', 'T' }) (N * (H + 16) bytes)
     * The first H bytes are for the OID of the root tree.
     * The next 8 bytes are for the positions of the first two parents
-      of the ith commit. Stores value 0xffffffff if no parent in that
+      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.
index e1a883eb462cd9bddbc192a315464282146ac433..c664acbd765d06f000b2feeef1d7e98f1616ff62 100644 (file)
@@ -118,9 +118,6 @@ Future Work
 - The commit graph feature currently does not honor commit grafts. This can
   be remedied by duplicating or refactoring the current graft logic.
 
-- The 'commit-graph' subcommand does not have a "verify" mode that is
-  necessary for integration with fsck.
-
 - After computing and storing generation numbers, we must make graph
   walks aware of generation numbers to gain the performance benefits they
   enable. This will mostly be accomplished by swapping a commit-date-ordered
@@ -130,25 +127,6 @@ Future Work
     - 'log --topo-order'
     - 'tag --merged'
 
-- Currently, parse_commit_gently() requires filling in the root tree
-  object for a commit. This passes through lookup_tree() and consequently
-  lookup_object(). Also, it calls lookup_commit() when loading the parents.
-  These method calls check the ODB for object existence, even if the
-  consumer does not need the content. For example, we do not need the
-  tree contents when computing merge bases. Now that commit parsing is
-  removed from the computation time, these lookup operations are the
-  slowest operations keeping graph walks from being fast. Consider
-  loading these objects without verifying their existence in the ODB and
-  only loading them fully when consumers need them. Consider a method
-  such as "ensure_tree_loaded(commit)" that fully loads a tree before
-  using commit->tree.
-
-- The current design uses the 'commit-graph' subcommand to generate the graph.
-  When this feature stabilizes enough to recommend to most users, we should
-  add automatic graph writes to common operations that create many commits.
-  For example, one could compute a graph on 'clone', 'fetch', or 'repack'
-  commands.
-
 - A server could provide a commit graph file as part of the network protocol
   to avoid extra calculations by clients. This feature is only of benefit if
   the user is willing to trust the file, because verifying the file is correct
diff --git a/Documentation/technical/directory-rename-detection.txt b/Documentation/technical/directory-rename-detection.txt
new file mode 100644 (file)
index 0000000..1c0086e
--- /dev/null
@@ -0,0 +1,115 @@
+Directory rename detection
+==========================
+
+Rename detection logic in diffcore-rename that checks for renames of
+individual files is aggregated and analyzed in merge-recursive for cases
+where combinations of renames indicate that a full directory has been
+renamed.
+
+Scope of abilities
+------------------
+
+It is perhaps easiest to start with an example:
+
+  * When all of x/a, x/b and x/c have moved to z/a, z/b and z/c, it is
+    likely that x/d added in the meantime would also want to move to z/d by
+    taking the hint that the entire directory 'x' moved to 'z'.
+
+More interesting possibilities exist, though, such as:
+
+  * one side of history renames x -> z, and the other renames some file to
+    x/e, causing the need for the merge to do a transitive rename.
+
+  * one side of history renames x -> z, but also renames all files within
+    x.  For example, x/a -> z/alpha, x/b -> z/bravo, etc.
+
+  * both 'x' and 'y' being merged into a single directory 'z', with a
+    directory rename being detected for both x->z and y->z.
+
+  * not all files in a directory being renamed to the same location;
+    i.e. perhaps most the files in 'x' are now found under 'z', but a few
+    are found under 'w'.
+
+  * a directory being renamed, which also contained a subdirectory that was
+    renamed to some entirely different location.  (And perhaps the inner
+    directory itself contained inner directories that were renamed to yet
+    other locations).
+
+  * combinations of the above; see t/t6043-merge-rename-directories.sh for
+    various interesting cases.
+
+Limitations -- applicability of directory renames
+-------------------------------------------------
+
+In order to prevent edge and corner cases resulting in either conflicts
+that cannot be represented in the index or which might be too complex for
+users to try to understand and resolve, a couple basic rules limit when
+directory rename detection applies:
+
+  1) If a given directory still exists on both sides of a merge, we do
+     not consider it to have been renamed.
+
+  2) If a subset of to-be-renamed files have a file or directory in the
+     way (or would be in the way of each other), "turn off" the directory
+     rename for those specific sub-paths and report the conflict to the
+     user.
+
+  3) If the other side of history did a directory rename to a path that
+     your side of history renamed away, then ignore that particular
+     rename from the other side of history for any implicit directory
+     renames (but warn the user).
+
+Limitations -- detailed rules and testcases
+-------------------------------------------
+
+t/t6043-merge-rename-directories.sh contains extensive tests and commentary
+which generate and explore the rules listed above.  It also lists a few
+additional rules:
+
+  a) If renames split a directory into two or more others, the directory
+     with the most renames, "wins".
+
+  b) Avoid directory-rename-detection for a path, if that path is the
+     source of a rename on either side of a merge.
+
+  c) Only apply implicit directory renames to directories if the other side
+     of history is the one doing the renaming.
+
+Limitations -- support in different commands
+--------------------------------------------
+
+Directory rename detection is supported by 'merge' and 'cherry-pick'.
+Other git commands which users might be surprised to see limited or no
+directory rename detection support in:
+
+  * diff
+
+    Folks have requested in the past that `git diff` detect directory
+    renames and somehow simplify its output.  It is not clear whether this
+    would be desirable or how the output should be simplified, so this was
+    simply not implemented.  Further, to implement this, directory rename
+    detection logic would need to move from merge-recursive to
+    diffcore-rename.
+
+  * am
+
+    git-am tries to avoid a full three way merge, instead calling
+    git-apply.  That prevents us from detecting renames at all, which may
+    defeat the directory rename detection.  There is a fallback, though; if
+    the initial git-apply fails and the user has specified the -3 option,
+    git-am will fall back to a three way merge.  However, git-am lacks the
+    necessary information to do a "real" three way merge.  Instead, it has
+    to use build_fake_ancestor() to get a merge base that is missing files
+    whose rename may have been important to detect for directory rename
+    detection to function.
+
+  * rebase
+
+    Since am-based rebases work by first generating a bunch of patches
+    (which no longer record what the original commits were and thus don't
+    have the necessary info from which we can find a real merge-base), and
+    then calling git-am, this implies that am-based rebases will not always
+    successfully detect directory renames either (see the 'am' section
+    above).  merged-based rebases (rebase -m) and cherry-pick-based rebases
+    (rebase -i) are not affected by this shortcoming, and fully support
+    directory rename detection.
index 4ab6cd1012abae711acf02e6a76ee93eae86a1ad..bc2ace2a6e0563f655fedb5681307b43c98cedc7 100644 (file)
@@ -59,14 +59,11 @@ that are believed to be cryptographically secure.
 
 Goals
 -----
-Where NewHash is a strong 256-bit hash function to replace SHA-1 (see
-"Selection of a New Hash", below):
-
-1. The transition to NewHash can be done one local repository at a time.
+1. The transition to SHA-256 can be done one local repository at a time.
    a. Requiring no action by any other party.
-   b. A NewHash repository can communicate with SHA-1 Git servers
+   b. A SHA-256 repository can communicate with SHA-1 Git servers
       (push/fetch).
-   c. Users can use SHA-1 and NewHash identifiers for objects
+   c. Users can use SHA-1 and SHA-256 identifiers for objects
       interchangeably (see "Object names on the command line", below).
    d. New signed objects make use of a stronger hash function than
       SHA-1 for their security guarantees.
@@ -79,7 +76,7 @@ Where NewHash is a strong 256-bit hash function to replace SHA-1 (see
 
 Non-Goals
 ---------
-1. Add NewHash support to Git protocol. This is valuable and the
+1. Add SHA-256 support to Git protocol. This is valuable and the
    logical next step but it is out of scope for this initial design.
 2. Transparently improving the security of existing SHA-1 signed
    objects.
@@ -87,26 +84,26 @@ Non-Goals
    repository.
 4. Taking the opportunity to fix other bugs in Git's formats and
    protocols.
-5. Shallow clones and fetches into a NewHash repository. (This will
-   change when we add NewHash support to Git protocol.)
-6. Skip fetching some submodules of a project into a NewHash
-   repository. (This also depends on NewHash support in Git
+5. Shallow clones and fetches into a SHA-256 repository. (This will
+   change when we add SHA-256 support to Git protocol.)
+6. Skip fetching some submodules of a project into a SHA-256
+   repository. (This also depends on SHA-256 support in Git
    protocol.)
 
 Overview
 --------
 We introduce a new repository format extension. Repositories with this
-extension enabled use NewHash instead of SHA-1 to name their objects.
+extension enabled use SHA-256 instead of SHA-1 to name their objects.
 This affects both object names and object content --- both the names
 of objects and all references to other objects within an object are
 switched to the new hash function.
 
-NewHash repositories cannot be read by older versions of Git.
+SHA-256 repositories cannot be read by older versions of Git.
 
-Alongside the packfile, a NewHash repository stores a bidirectional
-mapping between NewHash and SHA-1 object names. The mapping is generated
+Alongside the packfile, a SHA-256 repository stores a bidirectional
+mapping between SHA-256 and SHA-1 object names. The mapping is generated
 locally and can be verified using "git fsck". Object lookups use this
-mapping to allow naming objects using either their SHA-1 and NewHash names
+mapping to allow naming objects using either their SHA-1 and SHA-256 names
 interchangeably.
 
 "git cat-file" and "git hash-object" gain options to display an object
@@ -116,7 +113,7 @@ object database so that they can be named using the appropriate name
 (using the bidirectional hash mapping).
 
 Fetches from a SHA-1 based server convert the fetched objects into
-NewHash form and record the mapping in the bidirectional mapping table
+SHA-256 form and record the mapping in the bidirectional mapping table
 (see below for details). Pushes to a SHA-1 based server convert the
 objects being pushed into sha1 form so the server does not have to be
 aware of the hash function the client is using.
@@ -125,19 +122,19 @@ Detailed Design
 ---------------
 Repository format extension
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-A NewHash repository uses repository format version `1` (see
+A SHA-256 repository uses repository format version `1` (see
 Documentation/technical/repository-version.txt) with extensions
 `objectFormat` and `compatObjectFormat`:
 
        [core]
                repositoryFormatVersion = 1
        [extensions]
-               objectFormat = newhash
+               objectFormat = sha256
                compatObjectFormat = sha1
 
 The combination of setting `core.repositoryFormatVersion=1` and
 populating `extensions.*` ensures that all versions of Git later than
-`v0.99.9l` will die instead of trying to operate on the NewHash
+`v0.99.9l` will die instead of trying to operate on the SHA-256
 repository, instead producing an error message.
 
        # Between v0.99.9l and v2.7.0
@@ -155,36 +152,36 @@ repository extensions.
 Object names
 ~~~~~~~~~~~~
 Objects can be named by their 40 hexadecimal digit sha1-name or 64
-hexadecimal digit newhash-name, plus names derived from those (see
+hexadecimal digit sha256-name, plus names derived from those (see
 gitrevisions(7)).
 
 The sha1-name of an object is the SHA-1 of the concatenation of its
 type, length, a nul byte, and the object's sha1-content. This is the
 traditional <sha1> used in Git to name objects.
 
-The newhash-name of an object is the NewHash of the concatenation of its
-type, length, a nul byte, and the object's newhash-content.
+The sha256-name of an object is the SHA-256 of the concatenation of its
+type, length, a nul byte, and the object's sha256-content.
 
 Object format
 ~~~~~~~~~~~~~
 The content as a byte sequence of a tag, commit, or tree object named
-by sha1 and newhash differ because an object named by newhash-name refers to
-other objects by their newhash-names and an object named by sha1-name
+by sha1 and sha256 differ because an object named by sha256-name refers to
+other objects by their sha256-names and an object named by sha1-name
 refers to other objects by their sha1-names.
 
-The newhash-content of an object is the same as its sha1-content, except
-that objects referenced by the object are named using their newhash-names
+The sha256-content of an object is the same as its sha1-content, except
+that objects referenced by the object are named using their sha256-names
 instead of sha1-names. Because a blob object does not refer to any
-other object, its sha1-content and newhash-content are the same.
+other object, its sha1-content and sha256-content are the same.
 
-The format allows round-trip conversion between newhash-content and
+The format allows round-trip conversion between sha256-content and
 sha1-content.
 
 Object storage
 ~~~~~~~~~~~~~~
 Loose objects use zlib compression and packed objects use the packed
 format described in Documentation/technical/pack-format.txt, just like
-today. The content that is compressed and stored uses newhash-content
+today. The content that is compressed and stored uses sha256-content
 instead of sha1-content.
 
 Pack index
@@ -255,10 +252,10 @@ network byte order):
   up to and not including the table of CRC32 values.
 - Zero or more NUL bytes.
 - The trailer consists of the following:
-  - A copy of the 20-byte NewHash checksum at the end of the
+  - A copy of the 20-byte SHA-256 checksum at the end of the
     corresponding packfile.
 
-  - 20-byte NewHash checksum of all of the above.
+  - 20-byte SHA-256 checksum of all of the above.
 
 Loose object index
 ~~~~~~~~~~~~~~~~~~
@@ -266,7 +263,7 @@ A new file $GIT_OBJECT_DIR/loose-object-idx contains information about
 all loose objects. Its format is
 
   # loose-object-idx
-  (newhash-name SP sha1-name LF)*
+  (sha256-name SP sha1-name LF)*
 
 where the object names are in hexadecimal format. The file is not
 sorted.
@@ -292,8 +289,8 @@ To remove entries (e.g. in "git pack-refs" or "git-prune"):
 Translation table
 ~~~~~~~~~~~~~~~~~
 The index files support a bidirectional mapping between sha1-names
-and newhash-names. The lookup proceeds similarly to ordinary object
-lookups. For example, to convert a sha1-name to a newhash-name:
+and sha256-names. The lookup proceeds similarly to ordinary object
+lookups. For example, to convert a sha1-name to a sha256-name:
 
  1. Look for the object in idx files. If a match is present in the
     idx's sorted list of truncated sha1-names, then:
@@ -301,8 +298,8 @@ lookups. For example, to convert a sha1-name to a newhash-name:
        name order mapping.
     b. Read the corresponding entry in the full sha1-name table to
        verify we found the right object. If it is, then
-    c. Read the corresponding entry in the full newhash-name table.
-       That is the object's newhash-name.
+    c. Read the corresponding entry in the full sha256-name table.
+       That is the object's sha256-name.
  2. Check for a loose object. Read lines from loose-object-idx until
     we find a match.
 
@@ -318,25 +315,25 @@ for all objects in the object store.
 
 Reading an object's sha1-content
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The sha1-content of an object can be read by converting all newhash-names
-its newhash-content references to sha1-names using the translation table.
+The sha1-content of an object can be read by converting all sha256-names
+its sha256-content references to sha1-names using the translation table.
 
 Fetch
 ~~~~~
 Fetching from a SHA-1 based server requires translating between SHA-1
-and NewHash based representations on the fly.
+and SHA-256 based representations on the fly.
 
 SHA-1s named in the ref advertisement that are present on the client
-can be translated to NewHash and looked up as local objects using the
+can be translated to SHA-256 and looked up as local objects using the
 translation table.
 
 Negotiation proceeds as today. Any "have"s generated locally are
 converted to SHA-1 before being sent to the server, and SHA-1s
-mentioned by the server are converted to NewHash when looking them up
+mentioned by the server are converted to SHA-256 when looking them up
 locally.
 
 After negotiation, the server sends a packfile containing the
-requested objects. We convert the packfile to NewHash format using
+requested objects. We convert the packfile to SHA-256 format using
 the following steps:
 
 1. index-pack: inflate each object in the packfile and compute its
@@ -351,12 +348,12 @@ the following steps:
    (This list only contains objects reachable from the "wants". If the
    pack from the server contained additional extraneous objects, then
    they will be discarded.)
-3. convert to newhash: open a new (newhash) packfile. Read the topologically
+3. convert to sha256: open a new (sha256) packfile. Read the topologically
    sorted list just generated. For each object, inflate its
-   sha1-content, convert to newhash-content, and write it to the newhash
-   pack. Record the new sha1<->newhash mapping entry for use in the idx.
+   sha1-content, convert to sha256-content, and write it to the sha256
+   pack. Record the new sha1<->sha256 mapping entry for use in the idx.
 4. sort: reorder entries in the new pack to match the order of objects
-   in the pack the server generated and include blobs. Write a newhash idx
+   in the pack the server generated and include blobs. Write a sha256 idx
    file
 5. clean up: remove the SHA-1 based pack file, index, and
    topologically sorted list obtained from the server in steps 1
@@ -388,16 +385,16 @@ send-pack.
 
 Signed Commits
 ~~~~~~~~~~~~~~
-We add a new field "gpgsig-newhash" to the commit object format to allow
+We add a new field "gpgsig-sha256" to the commit object format to allow
 signing commits without relying on SHA-1. It is similar to the
-existing "gpgsig" field. Its signed payload is the newhash-content of the
-commit object with any "gpgsig" and "gpgsig-newhash" fields removed.
+existing "gpgsig" field. Its signed payload is the sha256-content of the
+commit object with any "gpgsig" and "gpgsig-sha256" fields removed.
 
 This means commits can be signed
 1. using SHA-1 only, as in existing signed commit objects
-2. using both SHA-1 and NewHash, by using both gpgsig-newhash and gpgsig
+2. using both SHA-1 and SHA-256, by using both gpgsig-sha256 and gpgsig
    fields.
-3. using only NewHash, by only using the gpgsig-newhash field.
+3. using only SHA-256, by only using the gpgsig-sha256 field.
 
 Old versions of "git verify-commit" can verify the gpgsig signature in
 cases (1) and (2) without modifications and view case (3) as an
@@ -405,24 +402,24 @@ ordinary unsigned commit.
 
 Signed Tags
 ~~~~~~~~~~~
-We add a new field "gpgsig-newhash" to the tag object format to allow
+We add a new field "gpgsig-sha256" to the tag object format to allow
 signing tags without relying on SHA-1. Its signed payload is the
-newhash-content of the tag with its gpgsig-newhash field and "-----BEGIN PGP
+sha256-content of the tag with its gpgsig-sha256 field and "-----BEGIN PGP
 SIGNATURE-----" delimited in-body signature removed.
 
 This means tags can be signed
 1. using SHA-1 only, as in existing signed tag objects
-2. using both SHA-1 and NewHash, by using gpgsig-newhash and an in-body
+2. using both SHA-1 and SHA-256, by using gpgsig-sha256 and an in-body
    signature.
-3. using only NewHash, by only using the gpgsig-newhash field.
+3. using only SHA-256, by only using the gpgsig-sha256 field.
 
 Mergetag embedding
 ~~~~~~~~~~~~~~~~~~
 The mergetag field in the sha1-content of a commit contains the
 sha1-content of a tag that was merged by that commit.
 
-The mergetag field in the newhash-content of the same commit contains the
-newhash-content of the same tag.
+The mergetag field in the sha256-content of the same commit contains the
+sha256-content of the same tag.
 
 Submodules
 ~~~~~~~~~~
@@ -497,7 +494,7 @@ Caveats
 -------
 Invalid objects
 ~~~~~~~~~~~~~~~
-The conversion from sha1-content to newhash-content retains any
+The conversion from sha1-content to sha256-content retains any
 brokenness in the original object (e.g., tree entry modes encoded with
 leading 0, tree objects whose paths are not sorted correctly, and
 commit objects without an author or committer). This is a deliberate
@@ -516,7 +513,7 @@ allow lifting this restriction.
 
 Alternates
 ~~~~~~~~~~
-For the same reason, a newhash repository cannot borrow objects from a
+For the same reason, a sha256 repository cannot borrow objects from a
 sha1 repository using objects/info/alternates or
 $GIT_ALTERNATE_OBJECT_REPOSITORIES.
 
@@ -524,20 +521,20 @@ git notes
 ~~~~~~~~~
 The "git notes" tool annotates objects using their sha1-name as key.
 This design does not describe a way to migrate notes trees to use
-newhash-names. That migration is expected to happen separately (for
+sha256-names. That migration is expected to happen separately (for
 example using a file at the root of the notes tree to describe which
 hash it uses).
 
 Server-side cost
 ~~~~~~~~~~~~~~~~
-Until Git protocol gains NewHash support, using NewHash based storage
+Until Git protocol gains SHA-256 support, using SHA-256 based storage
 on public-facing Git servers is strongly discouraged. Once Git
-protocol gains NewHash support, NewHash based servers are likely not
+protocol gains SHA-256 support, SHA-256 based servers are likely not
 to support SHA-1 compatibility, to avoid what may be a very expensive
 hash reencode during clone and to encourage peers to modernize.
 
 The design described here allows fetches by SHA-1 clients of a
-personal NewHash repository because it's not much more difficult than
+personal SHA-256 repository because it's not much more difficult than
 allowing pushes from that repository. This support needs to be guarded
 by a configuration option --- servers like git.kernel.org that serve a
 large number of clients would not be expected to bear that cost.
@@ -547,7 +544,7 @@ Meaning of signatures
 The signed payload for signed commits and tags does not explicitly
 name the hash used to identify objects. If some day Git adopts a new
 hash function with the same length as the current SHA-1 (40
-hexadecimal digit) or NewHash (64 hexadecimal digit) objects then the
+hexadecimal digit) or SHA-256 (64 hexadecimal digit) objects then the
 intent behind the PGP signed payload in an object signature is
 unclear:
 
@@ -562,7 +559,7 @@ Does this mean Git v2.12.0 is the commit with sha1-name
 e7e07d5a4fcc2a203d9873968ad3e6bd4d7419d7 or the commit with
 new-40-digit-hash-name e7e07d5a4fcc2a203d9873968ad3e6bd4d7419d7?
 
-Fortunately NewHash and SHA-1 have different lengths. If Git starts
+Fortunately SHA-256 and SHA-1 have different lengths. If Git starts
 using another hash with the same length to name objects, then it will
 need to change the format of signed payloads using that hash to
 address this issue.
@@ -574,24 +571,24 @@ supports four different modes of operation:
 
  1. ("dark launch") Treat object names input by the user as SHA-1 and
     convert any object names written to output to SHA-1, but store
-    objects using NewHash.  This allows users to test the code with no
+    objects using SHA-256.  This allows users to test the code with no
     visible behavior change except for performance.  This allows
     allows running even tests that assume the SHA-1 hash function, to
     sanity-check the behavior of the new mode.
 
- 2. ("early transition") Allow both SHA-1 and NewHash object names in
+ 2. ("early transition") Allow both SHA-1 and SHA-256 object names in
     input. Any object names written to output use SHA-1. This allows
     users to continue to make use of SHA-1 to communicate with peers
     (e.g. by email) that have not migrated yet and prepares for mode 3.
 
- 3. ("late transition") Allow both SHA-1 and NewHash object names in
-    input. Any object names written to output use NewHash. In this
+ 3. ("late transition") Allow both SHA-1 and SHA-256 object names in
+    input. Any object names written to output use SHA-256. In this
     mode, users are using a more secure object naming method by
     default.  The disruption is minimal as long as most of their peers
     are in mode 2 or mode 3.
 
  4. ("post-transition") Treat object names input by the user as
-    NewHash and write output using NewHash. This is safer than mode 3
+    SHA-256 and write output using SHA-256. This is safer than mode 3
     because there is less risk that input is incorrectly interpreted
     using the wrong hash function.
 
@@ -601,27 +598,31 @@ The user can also explicitly specify which format to use for a
 particular revision specifier and for output, overriding the mode. For
 example:
 
-git --output-format=sha1 log abac87a^{sha1}..f787cac^{newhash}
+git --output-format=sha1 log abac87a^{sha1}..f787cac^{sha256}
 
-Selection of a New Hash
------------------------
+Choice of Hash
+--------------
 In early 2005, around the time that Git was written,  Xiaoyun Wang,
 Yiqun Lisa Yin, and Hongbo Yu announced an attack finding SHA-1
 collisions in 2^69 operations. In August they published details.
 Luckily, no practical demonstrations of a collision in full SHA-1 were
 published until 10 years later, in 2017.
 
-The hash function NewHash to replace SHA-1 should be stronger than
-SHA-1 was: we would like it to be trustworthy and useful in practice
-for at least 10 years.
+Git v2.13.0 and later subsequently moved to a hardened SHA-1
+implementation by default that mitigates the SHAttered attack, but
+SHA-1 is still believed to be weak.
+
+The hash to replace this hardened SHA-1 should be stronger than SHA-1
+was: we would like it to be trustworthy and useful in practice for at
+least 10 years.
 
 Some other relevant properties:
 
 1. A 256-bit hash (long enough to match common security practice; not
    excessively long to hurt performance and disk usage).
 
-2. High quality implementations should be widely available (e.g. in
-   OpenSSL).
+2. High quality implementations should be widely available (e.g., in
+   OpenSSL and Apple CommonCrypto).
 
 3. The hash function's properties should match Git's needs (e.g. Git
    requires collision and 2nd preimage resistance and does not require
@@ -630,14 +631,13 @@ Some other relevant properties:
 4. As a tiebreaker, the hash should be fast to compute (fortunately
    many contenders are faster than SHA-1).
 
-Some hashes under consideration are SHA-256, SHA-512/256, SHA-256x16,
-K12, and BLAKE2bp-256.
+We choose SHA-256.
 
 Transition plan
 ---------------
 Some initial steps can be implemented independently of one another:
 - adding a hash function API (vtable)
-- teaching fsck to tolerate the gpgsig-newhash field
+- teaching fsck to tolerate the gpgsig-sha256 field
 - excluding gpgsig-* from the fields copied by "git commit --amend"
 - annotating tests that depend on SHA-1 values with a SHA1 test
   prerequisite
@@ -664,7 +664,7 @@ Next comes introduction of compatObjectFormat:
 - adding appropriate index entries when adding a new object to the
   object store
 - --output-format option
-- ^{sha1} and ^{newhash} revision notation
+- ^{sha1} and ^{sha256} revision notation
 - configuration to specify default input and output format (see
   "Object names on the command line" above)
 
@@ -672,7 +672,7 @@ The next step is supporting fetches and pushes to SHA-1 repositories:
 - allow pushes to a repository using the compat format
 - generate a topologically sorted list of the SHA-1 names of fetched
   objects
-- convert the fetched packfile to newhash format and generate an idx
+- convert the fetched packfile to sha256 format and generate an idx
   file
 - re-sort to match the order of objects in the fetched packfile
 
@@ -680,30 +680,30 @@ The infrastructure supporting fetch also allows converting an existing
 repository. In converted repositories and new clones, end users can
 gain support for the new hash function without any visible change in
 behavior (see "dark launch" in the "Object names on the command line"
-section). In particular this allows users to verify NewHash signatures
+section). In particular this allows users to verify SHA-256 signatures
 on objects in the repository, and it should ensure the transition code
 is stable in production in preparation for using it more widely.
 
 Over time projects would encourage their users to adopt the "early
 transition" and then "late transition" modes to take advantage of the
-new, more futureproof NewHash object names.
+new, more futureproof SHA-256 object names.
 
 When objectFormat and compatObjectFormat are both set, commands
-generating signatures would generate both SHA-1 and NewHash signatures
+generating signatures would generate both SHA-1 and SHA-256 signatures
 by default to support both new and old users.
 
-In projects using NewHash heavily, users could be encouraged to adopt
+In projects using SHA-256 heavily, users could be encouraged to adopt
 the "post-transition" mode to avoid accidentally making implicit use
 of SHA-1 object names.
 
 Once a critical mass of users have upgraded to a version of Git that
-can verify NewHash signatures and have converted their existing
+can verify SHA-256 signatures and have converted their existing
 repositories to support verifying them, we can add support for a
-setting to generate only NewHash signatures. This is expected to be at
+setting to generate only SHA-256 signatures. This is expected to be at
 least a year later.
 
 That is also a good moment to advertise the ability to convert
-repositories to use NewHash only, stripping out all SHA-1 related
+repositories to use SHA-256 only, stripping out all SHA-1 related
 metadata. This improves performance by eliminating translation
 overhead and security by avoiding the possibility of accidentally
 relying on the safety of SHA-1.
@@ -742,16 +742,16 @@ using the old hash function.
 
 Signed objects with multiple hashes
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Instead of introducing the gpgsig-newhash field in commit and tag objects
-for newhash-content based signatures, an earlier version of this design
-added "hash newhash <newhash-name>" fields to strengthen the existing
+Instead of introducing the gpgsig-sha256 field in commit and tag objects
+for sha256-content based signatures, an earlier version of this design
+added "hash sha256 <sha256-name>" fields to strengthen the existing
 sha1-content based signatures.
 
 In other words, a single signature was used to attest to the object
 content using both hash functions. This had some advantages:
 * Using one signature instead of two speeds up the signing process.
 * Having one signed payload with both hashes allows the signer to
-  attest to the sha1-name and newhash-name referring to the same object.
+  attest to the sha1-name and sha256-name referring to the same object.
 * All users consume the same signature. Broken signatures are likely
   to be detected quickly using current versions of git.
 
@@ -760,11 +760,11 @@ However, it also came with disadvantages:
   objects it references, even after the transition is complete and
   translation table is no longer needed for anything else. To support
   this, the design added fields such as "hash sha1 tree <sha1-name>"
-  and "hash sha1 parent <sha1-name>" to the newhash-content of a signed
+  and "hash sha1 parent <sha1-name>" to the sha256-content of a signed
   commit, complicating the conversion process.
 * Allowing signed objects without a sha1 (for after the transition is
   complete) complicated the design further, requiring a "nohash sha1"
-  field to suppress including "hash sha1" fields in the newhash-content
+  field to suppress including "hash sha1" fields in the sha256-content
   and signed payload.
 
 Lazily populated translation table
@@ -772,7 +772,7 @@ Lazily populated translation table
 Some of the work of building the translation table could be deferred to
 push time, but that would significantly complicate and slow down pushes.
 Calculating the sha1-name at object creation time at the same time it is
-being streamed to disk and having its newhash-name calculated should be
+being streamed to disk and having its sha256-name calculated should be
 an acceptable cost.
 
 Document History
@@ -814,6 +814,12 @@ Incorporated suggestions from jonathantanmy and sbeller:
 * avoid loose object overhead by packing more aggressively in
   "git gc --auto"
 
+Later history:
+
+ See the history of this file in git.git for the history of subsequent
+ edits. This document history is no longer being maintained as it
+ would now be superfluous to the commit log
+
 [1] http://public-inbox.org/git/CA+55aFzJtejiCjV0e43+9oR3QuJK2PiFiLQemytoLpyJWe6P9w@mail.gmail.com/
 [2] http://public-inbox.org/git/CA+55aFz+gkAsDZ24zmePQuEs1XPS9BP_s8O7Q4wQ7LV7X5-oDA@mail.gmail.com/
 [3] http://public-inbox.org/git/20170306084353.nrns455dvkdsfgo5@sigill.intra.peff.net/
index 64f49d0bbb7b0c28832562e59fc8b89e872c4f4b..9c5b6f0facbf41ce4ffa492dda6795bca229f170 100644 (file)
@@ -338,11 +338,11 @@ server advertises capability `allow-tip-sha1-in-want` or
                       request_end
   request_end       =  "0000" / "done"
 
-  want_list         =  PKT-LINE(want NUL cap_list LF)
+  want_list         =  PKT-LINE(want SP cap_list LF)
                       *(want_pkt)
   want_pkt          =  PKT-LINE(want LF)
   want              =  "want" SP id
-  cap_list          =  *(SP capability) SP
+  cap_list          =  capability *(SP capability)
 
   have_list         =  *PKT-LINE("have" SP id LF)
 
index 7fee6b780a869fcb9af979fb95a54587002b92f2..6ac774d5f665614848cdaba9e4c97d86a2453913 100644 (file)
@@ -50,7 +50,8 @@ Each Extra Parameter takes the form of `<key>=<value>` or `<key>`.
 
 Servers that receive any such Extra Parameters MUST ignore all
 unrecognized keys. Currently, the only Extra Parameter recognized is
-"version=1".
+"version" with a value of '1' or '2'.  See protocol-v2.txt for more
+information on protocol version 2.
 
 Git Transport
 -------------
@@ -284,7 +285,9 @@ information is sent back to the client in the next step.
 The client can optionally request that pack-objects omit various
 objects from the packfile 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.
+operations. An object that does not meet a filter-spec value is
+omitted unless explicitly requested in a 'want' line. See `rev-list`
+for possible filter-spec values.
 
 Once all the 'want's and 'shallow's (and optional 'deepen') are
 transferred, clients MUST send a flush-pkt, to tell the server side
index 49bda76d231d08173a48593d0910b3cbc934f01c..09e4e0273fd515254b41cf2d36e3b6083de1d4ee 100644 (file)
@@ -64,9 +64,8 @@ When using the http:// or https:// transport a client makes a "smart"
 info/refs request as described in `http-protocol.txt` and requests that
 v2 be used by supplying "version=2" in the `Git-Protocol` header.
 
-   C: Git-Protocol: version=2
-   C:
    C: GET $GIT_URL/info/refs?service=git-upload-pack HTTP/1.0
+   C: Git-Protocol: version=2
 
 A v2 server would reply:
 
@@ -299,12 +298,21 @@ included in the client's request:
        for use with partial clone and partial fetch operations. See
        `rev-list` for possible "filter-spec" values.
 
+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
+the 'wanted-refs' section in the server's response as explained below.
+
+    want-ref <ref>
+       Indicates to the server that the client wants to retrieve a
+       particular ref, where <ref> is the full name of a ref on the
+       server.
+
 The response of `fetch` is broken into a number of sections separated by
 delimiter packets (0001), with each section beginning with its section
 header.
 
     output = *section
-    section = (acknowledgments | shallow-info | packfile)
+    section = (acknowledgments | shallow-info | wanted-refs | packfile)
              (flush-pkt | delim-pkt)
 
     acknowledgments = PKT-LINE("acknowledgments" LF)
@@ -319,6 +327,10 @@ header.
     shallow = "shallow" SP obj-id
     unshallow = "unshallow" SP obj-id
 
+    wanted-refs = PKT-LINE("wanted-refs" LF)
+                 *PKT-LINE(wanted-ref LF)
+    wanted-ref = obj-id SP refname
+
     packfile = PKT-LINE("packfile" LF)
               *PKT-LINE(%x01-03 *%x00-ff)
 
@@ -379,6 +391,19 @@ header.
        * This section is only included if a packfile section is also
          included in the response.
 
+    wanted-refs section
+       * This section is only included if the client has requested a
+         ref using a 'want-ref' line and if a packfile section is also
+         included in the response.
+
+       * Always begins with the section header "wanted-refs".
+
+       * The server will send a ref listing ("<oid> <refname>") for
+         each reference requested using 'want-ref' lines.
+
+       * The server MUST NOT send any refs which were not requested
+         using 'want-ref' lines.
+
     packfile section
        * This section is only included if the client has sent 'want'
          lines in its request and either requested that no more
index 0cb6590f24acdaec89fa85815e7af584c48ed620..d03df31c2a61b29caa60928eb3b3f131562152d3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -484,6 +484,11 @@ all::
 #        The DEVELOPER mode enables -Wextra with a few exceptions. By
 #        setting this flag the exceptions are removed, and all of
 #        -Wextra is used.
+#
+#    pedantic:
+#
+#        Enable -pedantic compilation. This also disables
+#        USE_PARENS_AROUND_GETTEXT_N to produce only relevant warnings.
 
 GIT-VERSION-FILE: FORCE
        @$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -564,7 +569,7 @@ SPATCH = spatch
 export TCL_PATH TCLTK_PATH
 
 SPARSE_FLAGS =
-SPATCH_FLAGS = --all-includes
+SPATCH_FLAGS = --all-includes --patch .
 
 
 
@@ -709,6 +714,7 @@ TEST_BUILTINS_OBJS += test-example-decorate.o
 TEST_BUILTINS_OBJS += test-genrandom.o
 TEST_BUILTINS_OBJS += test-hashmap.o
 TEST_BUILTINS_OBJS += test-index-version.o
+TEST_BUILTINS_OBJS += test-json-writer.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-match-trees.o
 TEST_BUILTINS_OBJS += test-mergesort.o
@@ -719,6 +725,7 @@ TEST_BUILTINS_OBJS += test-prio-queue.o
 TEST_BUILTINS_OBJS += test-read-cache.o
 TEST_BUILTINS_OBJS += test-ref-store.o
 TEST_BUILTINS_OBJS += test-regex.o
+TEST_BUILTINS_OBJS += test-repository.o
 TEST_BUILTINS_OBJS += test-revision-walking.o
 TEST_BUILTINS_OBJS += test-run-command.o
 TEST_BUILTINS_OBJS += test-scrap-cache-tree.o
@@ -859,6 +866,7 @@ LIB_OBJS += ewah/ewah_bitmap.o
 LIB_OBJS += ewah/ewah_io.o
 LIB_OBJS += ewah/ewah_rlw.o
 LIB_OBJS += exec-cmd.o
+LIB_OBJS += fetch-negotiator.o
 LIB_OBJS += fetch-object.o
 LIB_OBJS += fetch-pack.o
 LIB_OBJS += fsck.o
@@ -868,9 +876,11 @@ LIB_OBJS += gpg-interface.o
 LIB_OBJS += graph.o
 LIB_OBJS += grep.o
 LIB_OBJS += hashmap.o
+LIB_OBJS += linear-assignment.o
 LIB_OBJS += help.o
 LIB_OBJS += hex.o
 LIB_OBJS += ident.o
+LIB_OBJS += json-writer.o
 LIB_OBJS += kwset.o
 LIB_OBJS += levenshtein.o
 LIB_OBJS += line-log.o
@@ -891,6 +901,8 @@ LIB_OBJS += merge-blobs.o
 LIB_OBJS += merge-recursive.o
 LIB_OBJS += mergesort.o
 LIB_OBJS += name-hash.o
+LIB_OBJS += negotiator/default.o
+LIB_OBJS += negotiator/skipping.o
 LIB_OBJS += notes.o
 LIB_OBJS += notes-cache.o
 LIB_OBJS += notes-merge.o
@@ -920,6 +932,7 @@ LIB_OBJS += progress.o
 LIB_OBJS += prompt.o
 LIB_OBJS += protocol.o
 LIB_OBJS += quote.o
+LIB_OBJS += range-diff.o
 LIB_OBJS += reachable.o
 LIB_OBJS += read-cache.o
 LIB_OBJS += reflog-walk.o
@@ -1058,6 +1071,7 @@ BUILTIN_OBJS += builtin/prune-packed.o
 BUILTIN_OBJS += builtin/prune.o
 BUILTIN_OBJS += builtin/pull.o
 BUILTIN_OBJS += builtin/push.o
+BUILTIN_OBJS += builtin/range-diff.o
 BUILTIN_OBJS += builtin/read-tree.o
 BUILTIN_OBJS += builtin/rebase--helper.o
 BUILTIN_OBJS += builtin/receive-pack.o
@@ -2021,8 +2035,9 @@ version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
 version.sp version.s version.o: EXTRA_CPPFLAGS = \
        '-DGIT_VERSION="$(GIT_VERSION)"' \
        '-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)' \
-       '-DGIT_BUILT_FROM_COMMIT="$(shell GIT_CEILING_DIRECTORIES=\"$(CURDIR)/..\" \
-               git rev-parse -q --verify HEAD || :)"'
+       '-DGIT_BUILT_FROM_COMMIT="$(shell \
+               GIT_CEILING_DIRECTORIES="$(CURDIR)/.." \
+               git rev-parse -q --verify HEAD 2>/dev/null)"'
 
 $(BUILT_INS): git$X
        $(QUIET_BUILT_IN)$(RM) $@ && \
@@ -2032,7 +2047,7 @@ $(BUILT_INS): git$X
 
 command-list.h: generate-cmdlist.sh command-list.txt
 
-command-list.h: $(wildcard Documentation/git*.txt)
+command-list.h: $(wildcard Documentation/git*.txt) Documentation/config.txt
        $(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@
 
 SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
@@ -2110,7 +2125,7 @@ $(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
        $(QUIET_GEN)$(RM) $@ $@+ && \
        sed -e '1{' \
            -e '        s|#!.*perl|#!$(PERL_PATH_SQ)|' \
-           -e '        rGIT-PERL-HEADER' \
+           -e '        r GIT-PERL-HEADER' \
            -e '        G' \
            -e '}' \
            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
@@ -2668,10 +2683,16 @@ check: command-list.h
        fi
 
 C_SOURCES = $(patsubst %.o,%.c,$(C_OBJ))
-%.cocci.patch: %.cocci $(C_SOURCES)
+ifdef DC_SHA1_SUBMODULE
+COCCI_SOURCES = $(filter-out sha1collisiondetection/%,$(C_SOURCES))
+else
+COCCI_SOURCES = $(filter-out sha1dc/%,$(C_SOURCES))
+endif
+
+%.cocci.patch: %.cocci $(COCCI_SOURCES)
        @echo '    ' SPATCH $<; \
        ret=0; \
-       for f in $(C_SOURCES); do \
+       for f in $(COCCI_SOURCES); do \
                $(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
                        { ret=$$?; break; }; \
        done >$@+ 2>$@.log; \
@@ -2685,7 +2706,9 @@ C_SOURCES = $(patsubst %.o,%.c,$(C_OBJ))
        then \
                echo '    ' SPATCH result: $@; \
        fi
-coccicheck: $(patsubst %.cocci,%.cocci.patch,$(wildcard contrib/coccinelle/*.cocci))
+coccicheck: $(addsuffix .patch,$(wildcard contrib/coccinelle/*.cocci))
+
+.PHONY: coccicheck
 
 ### Installation rules
 
@@ -2897,7 +2920,10 @@ profile-clean:
        $(RM) $(addsuffix *.gcda,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
        $(RM) $(addsuffix *.gcno,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
 
-clean: profile-clean coverage-clean
+cocciclean:
+       $(RM) contrib/coccinelle/*.cocci.patch*
+
+clean: profile-clean coverage-clean cocciclean
        $(RM) *.res
        $(RM) $(OBJECTS)
        $(RM) $(LIB_FILE) $(XDIFF_LIB) $(VCSSVN_LIB)
@@ -2909,7 +2935,6 @@ clean: profile-clean coverage-clean
        $(RM) -r $(GIT_TARNAME) .doc-tmp-dir
        $(RM) $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
        $(RM) $(htmldocs).tar.gz $(manpages).tar.gz
-       $(RM) contrib/coccinelle/*.cocci.patch*
        $(MAKE) -C Documentation/ clean
 ifndef NO_PERL
        $(MAKE) -C gitweb clean
@@ -2925,7 +2950,7 @@ endif
        $(RM) GIT-USER-AGENT GIT-PREFIX
        $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
 
-.PHONY: all install profile-clean clean strip
+.PHONY: all install profile-clean cocciclean clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
 .PHONY: FORCE cscope
 
index 52aa85bdfd9e9054c24445f259125bc4b81be038..3561cd64e9dab0a5b0c52d117253f37a5926f9c7 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -23,6 +23,7 @@ int advice_add_embedded_repo = 1;
 int advice_ignored_hook = 1;
 int advice_waiting_for_editor = 1;
 int advice_graft_file_deprecated = 1;
+int advice_checkout_ambiguous_remote_branch_name = 1;
 
 static int advice_use_color = -1;
 static char advice_colors[][COLOR_MAXLEN] = {
@@ -75,6 +76,7 @@ static struct {
        { "ignoredHook", &advice_ignored_hook },
        { "waitingForEditor", &advice_waiting_for_editor },
        { "graftFileDeprecated", &advice_graft_file_deprecated },
+       { "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name },
 
        /* make this an alias for backward compatibility */
        { "pushNonFastForward", &advice_push_update_rejected }
index 7e9377864f8fca1051ce3fd27f3def62b8d234eb..ab24df0fd0d0c739f6f58bb2650bb4162ef4c7f2 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -23,6 +23,7 @@ extern int advice_add_embedded_repo;
 extern int advice_ignored_hook;
 extern int advice_waiting_for_editor;
 extern int advice_graft_file_deprecated;
+extern int advice_checkout_ambiguous_remote_branch_name;
 
 int git_default_advice_config(const char *var, const char *value);
 __attribute__((format (printf, 1, 2)))
diff --git a/apply.c b/apply.c
index 959c45791008214cbc971493afaeb5f0e761f486..e485fbc6bc11efc6daefe78cbe949a65560ff4fa 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -9,6 +9,7 @@
 
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "blob.h"
 #include "delta.h"
 #include "diff.h"
@@ -75,10 +76,12 @@ static int parse_ignorewhitespace_option(struct apply_state *state,
 }
 
 int init_apply_state(struct apply_state *state,
+                    struct repository *repo,
                     const char *prefix)
 {
        memset(state, 0, sizeof(*state));
        state->prefix = prefix;
+       state->repo = repo;
        state->apply = 1;
        state->line_termination = '\n';
        state->p_value = 1;
@@ -3373,14 +3376,17 @@ static struct patch *previous_patch(struct apply_state *state,
        return previous;
 }
 
-static int verify_index_match(const struct cache_entry *ce, struct stat *st)
+static int verify_index_match(struct apply_state *state,
+                             const struct cache_entry *ce,
+                             struct stat *st)
 {
        if (S_ISGITLINK(ce->ce_mode)) {
                if (!S_ISDIR(st->st_mode))
                        return -1;
                return 0;
        }
-       return ce_match_stat(ce, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
+       return ie_match_stat(state->repo->index, ce, st,
+                            CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);
 }
 
 #define SUBMODULE_PATCH_WITHOUT_INDEX 1
@@ -3513,17 +3519,17 @@ static int load_current(struct apply_state *state,
        if (!patch->is_new)
                BUG("patch to %s is not a creation", patch->old_name);
 
-       pos = cache_name_pos(name, strlen(name));
+       pos = index_name_pos(state->repo->index, name, strlen(name));
        if (pos < 0)
                return error(_("%s: does not exist in index"), name);
-       ce = active_cache[pos];
+       ce = state->repo->index->cache[pos];
        if (lstat(name, &st)) {
                if (errno != ENOENT)
                        return error_errno("%s", name);
-               if (checkout_target(&the_index, ce, &st))
+               if (checkout_target(state->repo->index, ce, &st))
                        return -1;
        }
-       if (verify_index_match(ce, &st))
+       if (verify_index_match(state, ce, &st))
                return error(_("%s: does not match index"), name);
 
        status = load_patch_target(state, &buf, ce, &st, patch, name, mode);
@@ -3682,18 +3688,19 @@ static int check_preimage(struct apply_state *state,
        }
 
        if (state->check_index && !previous) {
-               int pos = cache_name_pos(old_name, strlen(old_name));
+               int pos = index_name_pos(state->repo->index, old_name,
+                                        strlen(old_name));
                if (pos < 0) {
                        if (patch->is_new < 0)
                                goto is_new;
                        return error(_("%s: does not exist in index"), old_name);
                }
-               *ce = active_cache[pos];
+               *ce = state->repo->index->cache[pos];
                if (stat_ret < 0) {
-                       if (checkout_target(&the_index, *ce, st))
+                       if (checkout_target(state->repo->index, *ce, st))
                                return -1;
                }
-               if (!state->cached && verify_index_match(*ce, st))
+               if (!state->cached && verify_index_match(state, *ce, st))
                        return error(_("%s: does not match index"), old_name);
                if (state->cached)
                        st_mode = (*ce)->ce_mode;
@@ -3737,7 +3744,7 @@ static int check_to_create(struct apply_state *state,
        struct stat nst;
 
        if (state->check_index &&
-           cache_name_pos(new_name, strlen(new_name)) >= 0 &&
+           index_name_pos(state->repo->index, new_name, strlen(new_name)) >= 0 &&
            !ok_if_exists)
                return EXISTS_IN_INDEX;
        if (state->cached)
@@ -3826,7 +3833,8 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *na
                if (state->check_index) {
                        struct cache_entry *ce;
 
-                       ce = cache_file_exists(name->buf, name->len, ignore_case);
+                       ce = index_file_exists(state->repo->index, name->buf,
+                                              name->len, ignore_case);
                        if (ce && S_ISLNK(ce->ce_mode))
                                return 1;
                } else {
@@ -4001,9 +4009,10 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)
 static int read_apply_cache(struct apply_state *state)
 {
        if (state->index_file)
-               return read_cache_from(state->index_file);
+               return read_index_from(state->repo->index, state->index_file,
+                                      get_git_dir());
        else
-               return read_cache();
+               return read_index(state->repo->index);
 }
 
 /* This function tries to read the object name from the current index */
@@ -4014,10 +4023,10 @@ static int get_current_oid(struct apply_state *state, const char *path,
 
        if (read_apply_cache(state) < 0)
                return -1;
-       pos = cache_name_pos(path, strlen(path));
+       pos = index_name_pos(state->repo->index, path, strlen(path));
        if (pos < 0)
                return -1;
-       oidcpy(oid, &active_cache[pos]->oid);
+       oidcpy(oid, &state->repo->index->cache[pos]->oid);
        return 0;
 }
 
@@ -4055,7 +4064,7 @@ static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid)
        return get_oid_hex(p->old_sha1_prefix, oid);
 }
 
-/* Build an index that contains the just the files needed for a 3way merge */
+/* Build an index that contains just the files needed for a 3way merge */
 static int build_fake_ancestor(struct apply_state *state, struct patch *list)
 {
        struct patch *patch;
@@ -4092,12 +4101,12 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
                        return error(_("sha1 information is lacking or useless "
                                       "(%s)."), name);
 
-               ce = make_cache_entry(patch->old_mode, oid.hash, name, 0, 0);
+               ce = make_cache_entry(&result, patch->old_mode, &oid, name, 0, 0);
                if (!ce)
                        return error(_("make_cache_entry failed for path '%s'"),
                                     name);
                if (add_index_entry(&result, ce, ADD_CACHE_OK_TO_ADD)) {
-                       free(ce);
+                       discard_cache_entry(ce);
                        return error(_("could not add %s to temporary index"),
                                     name);
                }
@@ -4245,7 +4254,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
 static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
 {
        if (state->update_index && !state->ita_only) {
-               if (remove_file_from_cache(patch->old_name) < 0)
+               if (remove_file_from_index(state->repo->index, patch->old_name) < 0)
                        return error(_("unable to remove %s from index"), patch->old_name);
        }
        if (!state->cached) {
@@ -4265,9 +4274,8 @@ static int add_index_file(struct apply_state *state,
        struct stat st;
        struct cache_entry *ce;
        int namelen = strlen(path);
-       unsigned ce_size = cache_entry_size(namelen);
 
-       ce = xcalloc(1, ce_size);
+       ce = make_empty_cache_entry(state->repo->index, namelen);
        memcpy(ce->name, path, namelen);
        ce->ce_mode = create_ce_mode(mode);
        ce->ce_flags = create_ce_flags(0);
@@ -4280,13 +4288,13 @@ static int add_index_file(struct apply_state *state,
 
                if (!skip_prefix(buf, "Subproject commit ", &s) ||
                    get_oid_hex(s, &ce->oid)) {
-                       free(ce);
-                      return error(_("corrupt patch for submodule %s"), path);
+                       discard_cache_entry(ce);
+                       return error(_("corrupt patch for submodule %s"), path);
                }
        } else {
                if (!state->cached) {
                        if (lstat(path, &st) < 0) {
-                               free(ce);
+                               discard_cache_entry(ce);
                                return error_errno(_("unable to stat newly "
                                                     "created file '%s'"),
                                                   path);
@@ -4294,13 +4302,13 @@ static int add_index_file(struct apply_state *state,
                        fill_stat_cache_info(ce, &st);
                }
                if (write_object_file(buf, size, blob_type, &ce->oid) < 0) {
-                       free(ce);
+                       discard_cache_entry(ce);
                        return error(_("unable to create backing store "
                                       "for newly created file %s"), path);
                }
        }
-       if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
-               free(ce);
+       if (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
+               discard_cache_entry(ce);
                return error(_("unable to add cache entry for %s"), path);
        }
 
@@ -4313,7 +4321,9 @@ static int add_index_file(struct apply_state *state,
  *   0 if everything went well
  *   1 if a recoverable error happened
  */
-static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
+static int try_create_file(struct apply_state *state, const char *path,
+                          unsigned int mode, const char *buf,
+                          unsigned long size)
 {
        int fd, res;
        struct strbuf nbuf = STRBUF_INIT;
@@ -4335,7 +4345,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
        if (fd < 0)
                return 1;
 
-       if (convert_to_working_tree(path, buf, size, &nbuf)) {
+       if (convert_to_working_tree(state->repo->index, path, buf, size, &nbuf)) {
                size = nbuf.len;
                buf  = nbuf.buf;
        }
@@ -4371,7 +4381,7 @@ static int create_one_file(struct apply_state *state,
        if (state->cached)
                return 0;
 
-       res = try_create_file(path, mode, buf, size);
+       res = try_create_file(state, path, mode, buf, size);
        if (res < 0)
                return -1;
        if (!res)
@@ -4380,7 +4390,7 @@ static int create_one_file(struct apply_state *state,
        if (errno == ENOENT) {
                if (safe_create_leading_directories(path))
                        return 0;
-               res = try_create_file(path, mode, buf, size);
+               res = try_create_file(state, path, mode, buf, size);
                if (res < 0)
                        return -1;
                if (!res)
@@ -4402,7 +4412,7 @@ static int create_one_file(struct apply_state *state,
                for (;;) {
                        char newpath[PATH_MAX];
                        mksnpath(newpath, sizeof(newpath), "%s~%u", path, nr);
-                       res = try_create_file(newpath, mode, buf, size);
+                       res = try_create_file(state, newpath, mode, buf, size);
                        if (res < 0)
                                return -1;
                        if (!res) {
@@ -4424,27 +4434,26 @@ static int add_conflicted_stages_file(struct apply_state *state,
                                       struct patch *patch)
 {
        int stage, namelen;
-       unsigned ce_size, mode;
+       unsigned mode;
        struct cache_entry *ce;
 
        if (!state->update_index)
                return 0;
        namelen = strlen(patch->new_name);
-       ce_size = cache_entry_size(namelen);
        mode = patch->new_mode ? patch->new_mode : (S_IFREG | 0644);
 
-       remove_file_from_cache(patch->new_name);
+       remove_file_from_index(state->repo->index, patch->new_name);
        for (stage = 1; stage < 4; stage++) {
                if (is_null_oid(&patch->threeway_stage[stage - 1]))
                        continue;
-               ce = xcalloc(1, ce_size);
+               ce = make_empty_cache_entry(state->repo->index, namelen);
                memcpy(ce->name, patch->new_name, namelen);
                ce->ce_mode = create_ce_mode(mode);
                ce->ce_flags = create_ce_flags(stage);
                ce->ce_namelen = namelen;
                oidcpy(&ce->oid, &patch->threeway_stage[stage - 1]);
-               if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
-                       free(ce);
+               if (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
+                       discard_cache_entry(ce);
                        return error(_("unable to add cache entry for %s"),
                                     patch->new_name);
                }
@@ -4892,7 +4901,7 @@ int apply_all_patches(struct apply_state *state,
        }
 
        if (state->update_index) {
-               res = write_locked_index(&the_index, &state->lock_file, COMMIT_LOCK);
+               res = write_locked_index(state->repo->index, &state->lock_file, COMMIT_LOCK);
                if (res) {
                        error(_("Unable to write new index file"));
                        res = -128;
diff --git a/apply.h b/apply.h
index b80d8ba73633c042989e52a00f7df8ee3afcd192..78c8bcfc3c4afe5ebd583f58c76eb3ca0e19a702 100644 (file)
--- a/apply.h
+++ b/apply.h
@@ -1,6 +1,8 @@
 #ifndef APPLY_H
 #define APPLY_H
 
+struct repository;
+
 enum apply_ws_error_action {
        nowarn_ws_error,
        warn_on_ws_error,
@@ -62,6 +64,7 @@ struct apply_state {
        int unsafe_paths;
 
        /* Other non boolean parameters */
+       struct repository *repo;
        const char *index_file;
        enum apply_verbosity apply_verbosity;
        const char *fake_ancestor;
@@ -111,14 +114,15 @@ struct apply_state {
        int applied_after_fixing_ws;
 };
 
-extern int apply_parse_options(int argc, const char **argv,
-                              struct apply_state *state,
-                              int *force_apply, int *options,
-                              const char * const *apply_usage);
-extern int init_apply_state(struct apply_state *state,
-                           const char *prefix);
-extern void clear_apply_state(struct apply_state *state);
-extern int check_apply_state(struct apply_state *state, int force_apply);
+int apply_parse_options(int argc, const char **argv,
+                       struct apply_state *state,
+                       int *force_apply, int *options,
+                       const char * const *apply_usage);
+int init_apply_state(struct apply_state *state,
+                    struct repository *repo,
+                    const char *prefix);
+void clear_apply_state(struct apply_state *state);
+int check_apply_state(struct apply_state *state, int force_apply);
 
 /*
  * Some aspects of the apply behavior are controlled by the following
@@ -127,9 +131,8 @@ extern int check_apply_state(struct apply_state *state, int force_apply);
 #define APPLY_OPT_INACCURATE_EOF       (1<<0) /* accept inaccurate eof */
 #define APPLY_OPT_RECOUNT              (1<<1) /* accept inaccurate line count */
 
-extern int apply_all_patches(struct apply_state *state,
-                            int argc,
-                            const char **argv,
-                            int options);
+int apply_all_patches(struct apply_state *state,
+                     int argc, const char **argv,
+                     int options);
 
 #endif
index b6f58ddf38767d86f866bd9413292e279c6cfa73..7a535cba24a2a0535b412f1cfb3531ddde155c1e 100644 (file)
@@ -5,6 +5,7 @@
 #include "config.h"
 #include "tar.h"
 #include "archive.h"
+#include "object-store.h"
 #include "streaming.h"
 #include "run-command.h"
 
@@ -121,7 +122,7 @@ static int stream_blocked(const struct object_id *oid)
 
        st = open_istream(oid, &type, &sz, NULL);
        if (!st)
-               return error("cannot stream blob %s", oid_to_hex(oid));
+               return error(_("cannot stream blob %s"), oid_to_hex(oid));
        for (;;) {
                readlen = read_istream(st, buf, sizeof(buf));
                if (readlen <= 0)
@@ -256,7 +257,7 @@ static int write_tar_entry(struct archiver_args *args,
                *header.typeflag = TYPEFLAG_REG;
                mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask;
        } else {
-               return error("unsupported file mode: 0%o (SHA1: %s)",
+               return error(_("unsupported file mode: 0%o (SHA1: %s)"),
                             mode, oid_to_hex(oid));
        }
        if (pathlen > sizeof(header.name)) {
@@ -276,14 +277,14 @@ static int write_tar_entry(struct archiver_args *args,
                memcpy(header.name, path, pathlen);
 
        if (S_ISREG(mode) && !args->convert &&
-           oid_object_info(the_repository, oid, &size) == OBJ_BLOB &&
+           oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
            size > big_file_threshold)
                buffer = NULL;
        else if (S_ISLNK(mode) || S_ISREG(mode)) {
                enum object_type type;
                buffer = object_file_to_archive(args, path, oid, old_mode, &type, &size);
                if (!buffer)
-                       return error("cannot read %s", oid_to_hex(oid));
+                       return error(_("cannot read %s"), oid_to_hex(oid));
        } else {
                buffer = NULL;
                size = 0;
@@ -454,17 +455,17 @@ static int write_tar_filter_archive(const struct archiver *ar,
        filter.in = -1;
 
        if (start_command(&filter) < 0)
-               die_errno("unable to start '%s' filter", argv[0]);
+               die_errno(_("unable to start '%s' filter"), argv[0]);
        close(1);
        if (dup2(filter.in, 1) < 0)
-               die_errno("unable to redirect descriptor");
+               die_errno(_("unable to redirect descriptor"));
        close(filter.in);
 
        r = write_tar_archive(ar, args);
 
        close(1);
        if (finish_command(&filter) != 0)
-               die("'%s' filter reported error", argv[0]);
+               die(_("'%s' filter reported error"), argv[0]);
 
        strbuf_release(&cmd);
        return r;
index 74f3fe9103420571c9f22273ae44ebb9d5715c78..5a62351ab1a46f6a0827a7d41e794c00a4839edc 100644 (file)
@@ -6,6 +6,7 @@
 #include "archive.h"
 #include "streaming.h"
 #include "utf8.h"
+#include "object-store.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
 
@@ -309,11 +310,11 @@ static int write_zip_entry(struct archiver_args *args,
                if (is_utf8(path))
                        flags |= ZIP_UTF8;
                else
-                       warning("Path is not valid UTF-8: %s", path);
+                       warning(_("path is not valid UTF-8: %s"), path);
        }
 
        if (pathlen > 0xffff) {
-               return error("path too long (%d chars, SHA1: %s): %s",
+               return error(_("path too long (%d chars, SHA1: %s): %s"),
                                (int)pathlen, oid_to_hex(oid), path);
        }
 
@@ -325,7 +326,7 @@ static int write_zip_entry(struct archiver_args *args,
                compressed_size = 0;
                buffer = NULL;
        } else if (S_ISREG(mode) || S_ISLNK(mode)) {
-               enum object_type type = oid_object_info(the_repository, oid,
+               enum object_type type = oid_object_info(args->repo, oid,
                                                        &size);
 
                method = 0;
@@ -340,7 +341,7 @@ static int write_zip_entry(struct archiver_args *args,
                    size > big_file_threshold) {
                        stream = open_istream(oid, &type, &size, NULL);
                        if (!stream)
-                               return error("cannot stream blob %s",
+                               return error(_("cannot stream blob %s"),
                                             oid_to_hex(oid));
                        flags |= ZIP_STREAM;
                        out = buffer = NULL;
@@ -348,7 +349,7 @@ static int write_zip_entry(struct archiver_args *args,
                        buffer = object_file_to_archive(args, path, oid, mode,
                                                        &type, &size);
                        if (!buffer)
-                               return error("cannot read %s",
+                               return error(_("cannot read %s"),
                                             oid_to_hex(oid));
                        crc = crc32(crc, buffer, size);
                        is_binary = entry_is_binary(path_without_prefix,
@@ -357,7 +358,7 @@ static int write_zip_entry(struct archiver_args *args,
                }
                compressed_size = (method == 0) ? size : 0;
        } else {
-               return error("unsupported file mode: 0%o (SHA1: %s)", mode,
+               return error(_("unsupported file mode: 0%o (SHA1: %s)"), mode,
                                oid_to_hex(oid));
        }
 
@@ -466,7 +467,7 @@ static int write_zip_entry(struct archiver_args *args,
                        zstream.avail_in = readlen;
                        result = git_deflate(&zstream, 0);
                        if (result != Z_OK)
-                               die("deflate error (%d)", result);
+                               die(_("deflate error (%d)"), result);
                        out_len = zstream.next_out - compressed;
 
                        if (out_len > 0) {
@@ -601,7 +602,7 @@ static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
        struct tm *t;
 
        if (date_overflows(*timestamp))
-               die("timestamp too large for this system: %"PRItime,
+               die(_("timestamp too large for this system: %"PRItime),
                    *timestamp);
        time = (time_t)*timestamp;
        t = localtime(&time);
index 4fe7bec60c12b3b1ab27c35b716b23f4535d170c..0a07b140fedd8fb1f14dd844dae9844641842c57 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "refs.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree-walk.h"
 #include "attr.h"
@@ -78,7 +79,7 @@ void *object_file_to_archive(const struct archiver_args *args,
                size_t size = 0;
 
                strbuf_attach(&buf, buffer, *sizep, *sizep + 1);
-               convert_to_working_tree(path, buf.buf, buf.len, &buf);
+               convert_to_working_tree(args->repo->index, path, buf.buf, buf.len, &buf);
                if (commit)
                        format_subst(commit, buf.buf, buf.len, &buf);
                buffer = strbuf_detach(&buf, &size);
@@ -103,12 +104,13 @@ struct archiver_context {
        struct directory *bottom;
 };
 
-static const struct attr_check *get_archive_attrs(const char *path)
+static const struct attr_check *get_archive_attrs(struct index_state *istate,
+                                                 const char *path)
 {
        static struct attr_check *check;
        if (!check)
                check = attr_check_initl("export-ignore", "export-subst", NULL);
-       return git_check_attr(path, check) ? NULL : check;
+       return git_check_attr(istate, path, check) ? NULL : check;
 }
 
 static int check_attr_export_ignore(const struct attr_check *check)
@@ -144,7 +146,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
 
        if (!S_ISDIR(mode)) {
                const struct attr_check *check;
-               check = get_archive_attrs(path_without_prefix);
+               check = get_archive_attrs(args->repo->index, path_without_prefix);
                if (check_attr_export_ignore(check))
                        return 0;
                args->convert = check_attr_export_subst(check);
@@ -219,7 +221,7 @@ static int queue_or_write_archive_entry(const struct object_id *oid,
                /* Borrow base, but restore its original value when done. */
                strbuf_addstr(base, filename);
                strbuf_addch(base, '/');
-               check = get_archive_attrs(base->buf);
+               check = get_archive_attrs(c->args->repo->index, base->buf);
                strbuf_setlen(base, baselen);
 
                if (check_attr_export_ignore(check))
@@ -267,13 +269,13 @@ int write_archive_entries(struct archiver_args *args,
                memset(&opts, 0, sizeof(opts));
                opts.index_only = 1;
                opts.head_idx = -1;
-               opts.src_index = &the_index;
-               opts.dst_index = &the_index;
+               opts.src_index = args->repo->index;
+               opts.dst_index = args->repo->index;
                opts.fn = oneway_merge;
                init_tree_desc(&t, args->tree->buffer, args->tree->size);
                if (unpack_trees(1, &t, &opts))
                        return -1;
-               git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
+               git_attr_set_direction(GIT_ATTR_INDEX);
        }
 
        err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
@@ -303,33 +305,43 @@ static const struct archiver *lookup_archiver(const char *name)
        return NULL;
 }
 
+struct path_exists_context {
+       struct pathspec pathspec;
+       struct archiver_args *args;
+};
+
 static int reject_entry(const struct object_id *oid, struct strbuf *base,
                        const char *filename, unsigned mode,
                        int stage, void *context)
 {
        int ret = -1;
+       struct path_exists_context *ctx = context;
+
        if (S_ISDIR(mode)) {
                struct strbuf sb = STRBUF_INIT;
                strbuf_addbuf(&sb, base);
                strbuf_addstr(&sb, filename);
-               if (!match_pathspec(context, sb.buf, sb.len, 0, NULL, 1))
+               if (!match_pathspec(ctx->args->repo->index,
+                                   &ctx->pathspec,
+                                   sb.buf, sb.len, 0, NULL, 1))
                        ret = READ_TREE_RECURSIVE;
                strbuf_release(&sb);
        }
        return ret;
 }
 
-static int path_exists(struct tree *tree, const char *path)
+static int path_exists(struct archiver_args *args, const char *path)
 {
        const char *paths[] = { path, NULL };
-       struct pathspec pathspec;
+       struct path_exists_context ctx;
        int ret;
 
-       parse_pathspec(&pathspec, 0, 0, "", paths);
-       pathspec.recursive = 1;
-       ret = read_tree_recursive(tree, "", 0, 0, &pathspec,
-                                 reject_entry, &pathspec);
-       clear_pathspec(&pathspec);
+       ctx.args = args;
+       parse_pathspec(&ctx.pathspec, 0, 0, "", paths);
+       ctx.pathspec.recursive = 1;
+       ret = read_tree_recursive(args->tree, "", 0, 0, &ctx.pathspec,
+                                 reject_entry, &ctx);
+       clear_pathspec(&ctx.pathspec);
        return ret != 0;
 }
 
@@ -347,7 +359,7 @@ static void parse_pathspec_arg(const char **pathspec,
        ar_args->pathspec.recursive = 1;
        if (pathspec) {
                while (*pathspec) {
-                       if (**pathspec && !path_exists(ar_args->tree, *pathspec))
+                       if (**pathspec && !path_exists(ar_args, *pathspec))
                                die(_("pathspec '%s' did not match any files"), *pathspec);
                        pathspec++;
                }
@@ -379,7 +391,7 @@ static void parse_treeish_arg(const char **argv,
        if (get_oid(name, &oid))
                die("Not a valid object name");
 
-       commit = lookup_commit_reference_gently(&oid, 1);
+       commit = lookup_commit_reference_gently(the_repository, &oid, 1);
        if (commit) {
                commit_sha1 = commit->object.oid.hash;
                archive_time = commit->date;
@@ -509,6 +521,7 @@ static int parse_archive_args(int argc, const char **argv,
 }
 
 int write_archive(int argc, const char **argv, const char *prefix,
+                 struct repository *repo,
                  const char *name_hint, int remote)
 {
        const struct archiver *ar = NULL;
@@ -520,6 +533,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
        init_tar_archiver();
        init_zip_archiver();
 
+       args.repo = repo;
        argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote);
        if (!startup_info->have_repository) {
                /*
index 1f9954f7cdc5a1ee8036321e439a65bdfb90e59f..75b9a86066b5f4e2977c9525b222c6595cef8b25 100644 (file)
--- a/archive.h
+++ b/archive.h
@@ -3,7 +3,10 @@
 
 #include "pathspec.h"
 
+struct repository;
+
 struct archiver_args {
+       struct repository *repo;
        const char *base;
        size_t baselen;
        struct tree *tree;
@@ -17,6 +20,16 @@ struct archiver_args {
        int compression_level;
 };
 
+/* main api */
+
+extern int write_archive(int argc, const char **argv, const char *prefix,
+                        struct repository *repo,
+                        const char *name_hint, int remote);
+
+const char *archive_format_from_filename(const char *filename);
+
+/* archive backend stuff */
+
 #define ARCHIVER_WANT_COMPRESSION_LEVELS 1
 #define ARCHIVER_REMOTE 2
 struct archiver {
@@ -36,9 +49,6 @@ typedef int (*write_archive_entry_fn_t)(struct archiver_args *args,
                                        unsigned int mode);
 
 extern int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
-extern int write_archive(int argc, const char **argv, const char *prefix, const char *name_hint, int remote);
-
-const char *archive_format_from_filename(const char *filename);
 extern void *object_file_to_archive(const struct archiver_args *args,
                                    const char *path, const struct object_id *oid,
                                    unsigned int mode, enum object_type *type,
diff --git a/attr.c b/attr.c
index 067fb9e0c08cefa2ba1a9b1d3444938c9bab6e3d..98e4953f6e87f5f5ff777ee57cedf705086e109e 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -708,10 +708,8 @@ static struct attr_stack *read_attr_from_array(const char **list)
  * another thread could potentially be calling into the attribute system.
  */
 static enum git_attr_direction direction;
-static struct index_state *use_index;
 
-void git_attr_set_direction(enum git_attr_direction new_direction,
-                           struct index_state *istate)
+void git_attr_set_direction(enum git_attr_direction new_direction)
 {
        if (is_bare_repository() && new_direction != GIT_ATTR_INDEX)
                BUG("non-INDEX attr direction in a bare repo");
@@ -720,7 +718,6 @@ void git_attr_set_direction(enum git_attr_direction new_direction,
                drop_all_attr_stacks();
 
        direction = new_direction;
-       use_index = istate;
 }
 
 static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
@@ -743,13 +740,18 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
        return res;
 }
 
-static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)
+static struct attr_stack *read_attr_from_index(const struct index_state *istate,
+                                              const char *path,
+                                              int macro_ok)
 {
        struct attr_stack *res;
        char *buf, *sp;
        int lineno = 0;
 
-       buf = read_blob_data_from_index(use_index ? use_index : &the_index, path, NULL);
+       if (!istate)
+               return NULL;
+
+       buf = read_blob_data_from_index(istate, path, NULL);
        if (!buf)
                return NULL;
 
@@ -768,15 +770,16 @@ static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)
        return res;
 }
 
-static struct attr_stack *read_attr(const char *path, int macro_ok)
+static struct attr_stack *read_attr(const struct index_state *istate,
+                                   const char *path, int macro_ok)
 {
        struct attr_stack *res = NULL;
 
        if (direction == GIT_ATTR_INDEX) {
-               res = read_attr_from_index(path, macro_ok);
+               res = read_attr_from_index(istate, path, macro_ok);
        } else if (!is_bare_repository()) {
                if (direction == GIT_ATTR_CHECKOUT) {
-                       res = read_attr_from_index(path, macro_ok);
+                       res = read_attr_from_index(istate, path, macro_ok);
                        if (!res)
                                res = read_attr_from_file(path, macro_ok);
                } else if (direction == GIT_ATTR_CHECKIN) {
@@ -788,7 +791,7 @@ static struct attr_stack *read_attr(const char *path, int macro_ok)
                                 * We allow operation in a sparsely checked out
                                 * work tree, so read from it.
                                 */
-                               res = read_attr_from_index(path, macro_ok);
+                               res = read_attr_from_index(istate, path, macro_ok);
                }
        }
 
@@ -859,7 +862,8 @@ static void push_stack(struct attr_stack **attr_stack_p,
        }
 }
 
-static void bootstrap_attr_stack(struct attr_stack **stack)
+static void bootstrap_attr_stack(const struct index_state *istate,
+                                struct attr_stack **stack)
 {
        struct attr_stack *e;
 
@@ -883,7 +887,7 @@ static void bootstrap_attr_stack(struct attr_stack **stack)
        }
 
        /* root directory */
-       e = read_attr(GITATTRIBUTES_FILE, 1);
+       e = read_attr(istate, GITATTRIBUTES_FILE, 1);
        push_stack(stack, e, xstrdup(""), 0);
 
        /* info frame */
@@ -896,7 +900,8 @@ static void bootstrap_attr_stack(struct attr_stack **stack)
        push_stack(stack, e, NULL, 0);
 }
 
-static void prepare_attr_stack(const char *path, int dirlen,
+static void prepare_attr_stack(const struct index_state *istate,
+                              const char *path, int dirlen,
                               struct attr_stack **stack)
 {
        struct attr_stack *info;
@@ -917,7 +922,7 @@ static void prepare_attr_stack(const char *path, int dirlen,
         * .gitattributes in deeper directories to shallower ones,
         * and finally use the built-in set as the default.
         */
-       bootstrap_attr_stack(stack);
+       bootstrap_attr_stack(istate, stack);
 
        /*
         * Pop the "info" one that is always at the top of the stack.
@@ -973,7 +978,7 @@ static void prepare_attr_stack(const char *path, int dirlen,
                strbuf_add(&pathbuf, path + pathbuf.len, (len - pathbuf.len));
                strbuf_addf(&pathbuf, "/%s", GITATTRIBUTES_FILE);
 
-               next = read_attr(pathbuf.buf, 0);
+               next = read_attr(istate, pathbuf.buf, 0);
 
                /* reset the pathbuf to not include "/.gitattributes" */
                strbuf_setlen(&pathbuf, len);
@@ -1095,7 +1100,9 @@ static void determine_macros(struct all_attrs_item *all_attrs,
  * If check->check_nr is non-zero, only attributes in check[] are collected.
  * Otherwise all attributes are collected.
  */
-static void collect_some_attrs(const char *path, struct attr_check *check)
+static void collect_some_attrs(const struct index_state *istate,
+                              const char *path,
+                              struct attr_check *check)
 {
        int i, pathlen, rem, dirlen;
        const char *cp, *last_slash = NULL;
@@ -1114,7 +1121,7 @@ static void collect_some_attrs(const char *path, struct attr_check *check)
                dirlen = 0;
        }
 
-       prepare_attr_stack(path, dirlen, &check->stack);
+       prepare_attr_stack(istate, path, dirlen, &check->stack);
        all_attrs_init(&g_attr_hashmap, check);
        determine_macros(check->all_attrs, check->stack);
 
@@ -1136,11 +1143,13 @@ static void collect_some_attrs(const char *path, struct attr_check *check)
        fill(path, pathlen, basename_offset, check->stack, check->all_attrs, rem);
 }
 
-int git_check_attr(const char *path, struct attr_check *check)
+int git_check_attr(const struct index_state *istate,
+                  const char *path,
+                  struct attr_check *check)
 {
        int i;
 
-       collect_some_attrs(path, check);
+       collect_some_attrs(istate, path, check);
 
        for (i = 0; i < check->nr; i++) {
                size_t n = check->items[i].attr->attr_nr;
@@ -1153,12 +1162,13 @@ int git_check_attr(const char *path, struct attr_check *check)
        return 0;
 }
 
-void git_all_attrs(const char *path, struct attr_check *check)
+void git_all_attrs(const struct index_state *istate,
+                  const char *path, struct attr_check *check)
 {
        int i;
 
        attr_check_reset(check);
-       collect_some_attrs(path, check);
+       collect_some_attrs(istate, path, check);
 
        for (i = 0; i < check->all_attrs_nr; i++) {
                const char *name = check->all_attrs[i].attr->name;
diff --git a/attr.h b/attr.h
index 442d464db6271da48a4ef133127c7d3a18c186cf..01dab4a1262bc5aefadca627012cbf59c7c9df16 100644 (file)
--- a/attr.h
+++ b/attr.h
@@ -1,6 +1,8 @@
 #ifndef ATTR_H
 #define ATTR_H
 
+struct index_state;
+
 /* An attribute is a pointer to this opaque structure */
 struct git_attr;
 
@@ -42,40 +44,41 @@ struct attr_check {
        struct attr_stack *stack;
 };
 
-extern struct attr_check *attr_check_alloc(void);
-extern struct attr_check *attr_check_initl(const char *, ...);
-extern struct attr_check *attr_check_dup(const struct attr_check *check);
+struct attr_check *attr_check_alloc(void);
+struct attr_check *attr_check_initl(const char *, ...);
+struct attr_check *attr_check_dup(const struct attr_check *check);
 
-extern struct attr_check_item *attr_check_append(struct attr_check *check,
-                                                const struct git_attr *attr);
+struct attr_check_item *attr_check_append(struct attr_check *check,
+                                         const struct git_attr *attr);
 
-extern void attr_check_reset(struct attr_check *check);
-extern void attr_check_clear(struct attr_check *check);
-extern void attr_check_free(struct attr_check *check);
+void attr_check_reset(struct attr_check *check);
+void attr_check_clear(struct attr_check *check);
+void attr_check_free(struct attr_check *check);
 
 /*
  * Return the name of the attribute represented by the argument.  The
  * return value is a pointer to a null-delimited string that is part
  * of the internal data structure; it should not be modified or freed.
  */
-extern const char *git_attr_name(const struct git_attr *);
+const char *git_attr_name(const struct git_attr *);
 
-extern int git_check_attr(const char *path, struct attr_check *check);
+int git_check_attr(const struct index_state *istate,
+                  const char *path, struct attr_check *check);
 
 /*
  * Retrieve all attributes that apply to the specified path.
  * check holds the attributes and their values.
  */
-extern void git_all_attrs(const char *path, struct attr_check *check);
+void git_all_attrs(const struct index_state *istate,
+                  const char *path, struct attr_check *check);
 
 enum git_attr_direction {
        GIT_ATTR_CHECKIN,
        GIT_ATTR_CHECKOUT,
        GIT_ATTR_INDEX
 };
-void git_attr_set_direction(enum git_attr_direction new_direction,
-                           struct index_state *istate);
+void git_attr_set_direction(enum git_attr_direction new_direction);
 
-extern void attr_start(void);
+void attr_start(void);
 
 #endif /* ATTR_H */
diff --git a/banned.h b/banned.h
new file mode 100644 (file)
index 0000000..28f5937
--- /dev/null
+++ b/banned.h
@@ -0,0 +1,30 @@
+#ifndef BANNED_H
+#define BANNED_H
+
+/*
+ * This header lists functions that have been banned from our code base,
+ * because they're too easy to misuse (and even if used correctly,
+ * complicate audits). Including this header turns them into compile-time
+ * errors.
+ */
+
+#define BANNED(func) sorry_##func##_is_a_banned_function
+
+#undef strcpy
+#define strcpy(x,y) BANNED(strcpy)
+#undef strcat
+#define strcat(x,y) BANNED(strcat)
+#undef strncpy
+#define strncpy(x,y,n) BANNED(strncpy)
+
+#undef sprintf
+#undef vsprintf
+#ifdef HAVE_VARIADIC_MACROS
+#define sprintf(...) BANNED(sprintf)
+#define vsprintf(...) BANNED(vsprintf)
+#else
+#define sprintf(buf,fmt,arg) BANNED(sprintf)
+#define vsprintf(buf,fmt,arg) BANNED(sprintf)
+#endif
+
+#endif /* BANNED_H */
index 6de1abd407ba3f8b7698133d469389913bfd92c3..e1275ba79e8e7368f5448043e321db2b9376aa71 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -724,7 +724,7 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
 
 static struct commit *get_commit_reference(const struct object_id *oid)
 {
-       struct commit *r = lookup_commit_reference(oid);
+       struct commit *r = lookup_commit_reference(the_repository, oid);
        if (!r)
                die(_("Not a valid commit name %s"), oid_to_hex(oid));
        return r;
diff --git a/blame.c b/blame.c
index a5c9bd78ab09ce1d1ce40f82ccf13fcc8d973eec..08c0c6cf73c349a2b7ad6fe129443852318a5044 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "refs.h"
+#include "object-store.h"
 #include "cache-tree.h"
 #include "mergesort.h"
 #include "diff.h"
@@ -89,7 +90,8 @@ static struct blame_origin *get_origin(struct commit *commit, const char *path)
 
 
 
-static void verify_working_tree_path(struct commit *work_tree, const char *path)
+static void verify_working_tree_path(struct repository *repo,
+                                    struct commit *work_tree, const char *path)
 {
        struct commit_list *parents;
        int pos;
@@ -100,15 +102,15 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
                unsigned mode;
 
                if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
-                   oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB)
+                   oid_object_info(repo, &blob_oid, NULL) == OBJ_BLOB)
                        return;
        }
 
-       pos = cache_name_pos(path, strlen(path));
+       pos = index_name_pos(repo->index, path, strlen(path));
        if (pos >= 0)
                ; /* path is in the index */
-       else if (-1 - pos < active_nr &&
-                !strcmp(active_cache[-1 - pos]->name, path))
+       else if (-1 - pos < repo->index->cache_nr &&
+                !strcmp(repo->index->cache[-1 - pos]->name, path))
                ; /* path is in the index, unmerged */
        else
                die("no such path '%s' in HEAD", path);
@@ -118,7 +120,7 @@ static struct commit_list **append_parent(struct commit_list **tail, const struc
 {
        struct commit *parent;
 
-       parent = lookup_commit_reference(oid);
+       parent = lookup_commit_reference(the_repository, oid);
        if (!parent)
                die("no such commit %s", oid_to_hex(oid));
        return &commit_list_insert(parent, tail)->next;
@@ -129,17 +131,19 @@ static void append_merge_parents(struct commit_list **tail)
        int merge_head;
        struct strbuf line = STRBUF_INIT;
 
-       merge_head = open(git_path_merge_head(), O_RDONLY);
+       merge_head = open(git_path_merge_head(the_repository), O_RDONLY);
        if (merge_head < 0) {
                if (errno == ENOENT)
                        return;
-               die("cannot open '%s' for reading", git_path_merge_head());
+               die("cannot open '%s' for reading",
+                   git_path_merge_head(the_repository));
        }
 
        while (!strbuf_getwholeline_fd(&line, merge_head, '\n')) {
                struct object_id oid;
                if (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))
-                       die("unknown line in '%s': %s", git_path_merge_head(), line.buf);
+                       die("unknown line in '%s': %s",
+                           git_path_merge_head(the_repository), line.buf);
                tail = append_parent(tail, &oid);
        }
        close(merge_head);
@@ -155,14 +159,15 @@ static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
 {
        size_t len;
        void *buf = strbuf_detach(sb, &len);
-       set_commit_buffer(c, buf, len);
+       set_commit_buffer(the_repository, c, buf, len);
 }
 
 /*
  * Prepare a dummy commit that represents the work tree (or staged) item.
  * Note that annotating work tree item never works in the reverse.
  */
-static struct commit *fake_working_tree_commit(struct diff_options *opt,
+static struct commit *fake_working_tree_commit(struct repository *repo,
+                                              struct diff_options *opt,
                                               const char *path,
                                               const char *contents_from)
 {
@@ -173,12 +178,12 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
        struct strbuf buf = STRBUF_INIT;
        const char *ident;
        time_t now;
-       int size, len;
+       int len;
        struct cache_entry *ce;
        unsigned mode;
        struct strbuf msg = STRBUF_INIT;
 
-       read_cache();
+       read_index(repo->index);
        time(&now);
        commit = alloc_commit_node(the_repository);
        commit->object.parsed = 1;
@@ -190,7 +195,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 
        parent_tail = append_parent(parent_tail, &head_oid);
        append_merge_parents(parent_tail);
-       verify_working_tree_path(commit, path);
+       verify_working_tree_path(repo, commit, path);
 
        origin = make_origin(commit, path);
 
@@ -248,7 +253,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
                if (strbuf_read(&buf, 0, 0) < 0)
                        die_errno("failed to read from stdin");
        }
-       convert_to_git(&the_index, path, buf.buf, buf.len, &buf, 0);
+       convert_to_git(repo->index, path, buf.buf, buf.len, &buf, 0);
        origin->file.ptr = buf.buf;
        origin->file.size = buf.len;
        pretend_object_file(buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
@@ -259,28 +264,28 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
         * bits; we are not going to write this index out -- we just
         * want to run "diff-index --cached".
         */
-       discard_cache();
-       read_cache();
+       discard_index(repo->index);
+       read_index(repo->index);
 
        len = strlen(path);
        if (!mode) {
-               int pos = cache_name_pos(path, len);
+               int pos = index_name_pos(repo->index, path, len);
                if (0 <= pos)
-                       mode = active_cache[pos]->ce_mode;
+                       mode = repo->index->cache[pos]->ce_mode;
                else
                        /* Let's not bother reading from HEAD tree */
                        mode = S_IFREG | 0644;
        }
-       size = cache_entry_size(len);
-       ce = xcalloc(1, size);
+       ce = make_empty_cache_entry(repo->index, len);
        oidcpy(&ce->oid, &origin->blob_oid);
        memcpy(ce->name, path, len);
        ce->ce_flags = create_ce_flags(0);
        ce->ce_namelen = len;
        ce->ce_mode = create_ce_mode(mode);
-       add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
+       add_index_entry(repo->index, ce,
+                       ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
 
-       cache_tree_invalidate_path(&the_index, path);
+       cache_tree_invalidate_path(repo->index, path);
 
        return commit;
 }
@@ -517,13 +522,14 @@ static void queue_blames(struct blame_scoreboard *sb, struct blame_origin *porig
  *
  * This also fills origin->mode for corresponding tree path.
  */
-static int fill_blob_sha1_and_mode(struct blame_origin *origin)
+static int fill_blob_sha1_and_mode(struct repository *repo,
+                                  struct blame_origin *origin)
 {
        if (!is_null_oid(&origin->blob_oid))
                return 0;
        if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
                goto error_out;
-       if (oid_object_info(the_repository, &origin->blob_oid, NULL) != OBJ_BLOB)
+       if (oid_object_info(repo, &origin->blob_oid, NULL) != OBJ_BLOB)
                goto error_out;
        return 0;
  error_out:
@@ -1671,7 +1677,7 @@ static struct commit *find_single_final(struct rev_info *revs,
                struct object *obj = revs->pending.objects[i].item;
                if (obj->flags & UNINTERESTING)
                        continue;
-               obj = deref_tag(obj, NULL, 0);
+               obj = deref_tag(the_repository, obj, NULL, 0);
                if (obj->type != OBJ_COMMIT)
                        die("Non commit %s?", revs->pending.objects[i].name);
                if (found)
@@ -1702,14 +1708,15 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
 
        /* Is that sole rev a committish? */
        obj = revs->pending.objects[0].item;
-       obj = deref_tag(obj, NULL, 0);
+       obj = deref_tag(the_repository, obj, NULL, 0);
        if (obj->type != OBJ_COMMIT)
                return NULL;
 
        /* Do we have HEAD? */
        if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
                return NULL;
-       head_commit = lookup_commit_reference_gently(&head_oid, 1);
+       head_commit = lookup_commit_reference_gently(the_repository,
+                                                    &head_oid, 1);
        if (!head_commit)
                return NULL;
 
@@ -1737,7 +1744,7 @@ static struct commit *find_single_initial(struct rev_info *revs,
                struct object *obj = revs->pending.objects[i].item;
                if (!(obj->flags & UNINTERESTING))
                        continue;
-               obj = deref_tag(obj, NULL, 0);
+               obj = deref_tag(the_repository, obj, NULL, 0);
                if (obj->type != OBJ_COMMIT)
                        die("Non commit %s?", revs->pending.objects[i].name);
                if (found)
@@ -1764,7 +1771,9 @@ void init_scoreboard(struct blame_scoreboard *sb)
        sb->copy_score = BLAME_DEFAULT_COPY_SCORE;
 }
 
-void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blame_origin **orig)
+void setup_scoreboard(struct blame_scoreboard *sb,
+                     const char *path,
+                     struct blame_origin **orig)
 {
        const char *final_commit_name = NULL;
        struct blame_origin *o;
@@ -1776,6 +1785,9 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
        if (sb->reverse && sb->contents_from)
                die(_("--contents and --reverse do not blend well."));
 
+       if (!sb->repo)
+               BUG("repo is NULL");
+
        if (!sb->reverse) {
                sb->final = find_single_final(sb->revs, &final_commit_name);
                sb->commits.compare = compare_commits_by_commit_date;
@@ -1797,7 +1809,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
                 * or "--contents".
                 */
                setup_work_tree();
-               sb->final = fake_working_tree_commit(&sb->revs->diffopt,
+               sb->final = fake_working_tree_commit(sb->repo,
+                                                    &sb->revs->diffopt,
                                                     path, sb->contents_from);
                add_pending_object(sb->revs, &(sb->final->object), ":");
        }
@@ -1842,7 +1855,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
        }
        else {
                o = get_origin(sb->final, path);
-               if (fill_blob_sha1_and_mode(o))
+               if (fill_blob_sha1_and_mode(sb->repo, o))
                        die(_("no such path %s in %s"), path, final_commit_name);
 
                if (sb->revs->diffopt.flags.allow_textconv &&
diff --git a/blame.h b/blame.h
index 2092f9529c108d40100ec2a8175098edc8e8e5dd..be3a895043e07a2508d407ac35e74d634acd7886 100644 (file)
--- a/blame.h
+++ b/blame.h
@@ -102,6 +102,7 @@ struct blame_scoreboard {
        struct commit *final;
        /* Priority queue for commits with unassigned blame records */
        struct prio_queue commits;
+       struct repository *repo;
        struct rev_info *revs;
        const char *path;
 
@@ -159,18 +160,22 @@ static inline struct blame_origin *blame_origin_incref(struct blame_origin *o)
                o->refcnt++;
        return o;
 }
-extern void blame_origin_decref(struct blame_origin *o);
-
-extern void blame_coalesce(struct blame_scoreboard *sb);
-extern void blame_sort_final(struct blame_scoreboard *sb);
-extern unsigned blame_entry_score(struct blame_scoreboard *sb, struct blame_entry *e);
-extern void assign_blame(struct blame_scoreboard *sb, int opt);
-extern const char *blame_nth_line(struct blame_scoreboard *sb, long lno);
-
-extern void init_scoreboard(struct blame_scoreboard *sb);
-extern void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blame_origin **orig);
-
-extern struct blame_entry *blame_entry_prepend(struct blame_entry *head, long start, long end, struct blame_origin *o);
+void blame_origin_decref(struct blame_origin *o);
+
+void blame_coalesce(struct blame_scoreboard *sb);
+void blame_sort_final(struct blame_scoreboard *sb);
+unsigned blame_entry_score(struct blame_scoreboard *sb, struct blame_entry *e);
+void assign_blame(struct blame_scoreboard *sb, int opt);
+const char *blame_nth_line(struct blame_scoreboard *sb, long lno);
+
+void init_scoreboard(struct blame_scoreboard *sb);
+void setup_scoreboard(struct blame_scoreboard *sb,
+                     const char *path,
+                     struct blame_origin **orig);
+
+struct blame_entry *blame_entry_prepend(struct blame_entry *head,
+                                       long start, long end,
+                                       struct blame_origin *o);
 
 extern struct blame_origin *get_blame_suspects(struct commit *commit);
 
diff --git a/blob.c b/blob.c
index 458dafa811edf74e01e10777cf580c696bf0b1a8..342bdbb1bbea78dced090b815cab5ff9bfed9cd9 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -5,13 +5,13 @@
 
 const char *blob_type = "blob";
 
-struct blob *lookup_blob(const struct object_id *oid)
+struct blob *lookup_blob(struct repository *r, const struct object_id *oid)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(r, oid->hash);
        if (!obj)
-               return create_object(the_repository, oid->hash,
-                                    alloc_blob_node(the_repository));
-       return object_as_type(obj, OBJ_BLOB, 0);
+               return create_object(r, oid->hash,
+                                    alloc_blob_node(r));
+       return object_as_type(r, obj, OBJ_BLOB, 0);
 }
 
 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
diff --git a/blob.h b/blob.h
index 446061683101d5578f8de2b8aa43e4b6c51d1d66..1664872055783557e1836dcc64bc2f51c20c5b4f 100644 (file)
--- a/blob.h
+++ b/blob.h
@@ -9,7 +9,7 @@ struct blob {
        struct object object;
 };
 
-struct blob *lookup_blob(const struct object_id *oid);
+struct blob *lookup_blob(struct repository *r, const struct object_id *oid);
 
 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size);
 
index f967c98f6324c49d9ab7f94f973230512af13707..ecd710d7308c9d2be85cd3bcde4fd9d38dec0edc 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -302,7 +302,7 @@ void create_branch(const char *name, const char *start_name,
                break;
        }
 
-       if ((commit = lookup_commit_reference(&oid)) == NULL)
+       if ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)
                die(_("Not a valid branch point: '%s'."), start_name);
        oidcpy(&oid, &commit->object.oid);
 
@@ -340,13 +340,13 @@ void create_branch(const char *name, const char *start_name,
 
 void remove_branch_state(void)
 {
-       unlink(git_path_cherry_pick_head());
-       unlink(git_path_revert_head());
-       unlink(git_path_merge_head());
-       unlink(git_path_merge_rr());
-       unlink(git_path_merge_msg());
-       unlink(git_path_merge_mode());
-       unlink(git_path_squash_msg());
+       unlink(git_path_cherry_pick_head(the_repository));
+       unlink(git_path_revert_head(the_repository));
+       unlink(git_path_merge_head(the_repository));
+       unlink(git_path_merge_rr(the_repository));
+       unlink(git_path_merge_msg(the_repository));
+       unlink(git_path_merge_mode(the_repository));
+       unlink(git_path_squash_msg(the_repository));
 }
 
 void die_if_checked_out(const char *branch, int ignore_current_worktree)
index 0362f1ce25fb64631e28f00eafa46f35bc94c7eb..99206df4bd43fc0c4ff8db538912dec1c600c397 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -201,6 +201,7 @@ extern int cmd_prune(int argc, const char **argv, const char *prefix);
 extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
 extern int cmd_pull(int argc, const char **argv, const char *prefix);
 extern int cmd_push(int argc, const char **argv, const char *prefix);
+extern int cmd_range_diff(int argc, const char **argv, const char *prefix);
 extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
 extern int cmd_rebase__helper(int argc, const char **argv, const char *prefix);
 extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
index 8a155dd41eccd8004a55b1302111293ae59ea542..9916498a29bbd8fa7c5c5d8e7bd32e1dc184909b 100644 (file)
@@ -40,7 +40,7 @@ static void chmod_pathspec(struct pathspec *pathspec, char flip)
        for (i = 0; i < active_nr; i++) {
                struct cache_entry *ce = active_cache[i];
 
-               if (pathspec && !ce_path_match(ce, pathspec, NULL))
+               if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
                        continue;
 
                if (chmod_cache_entry(ce, flip) < 0)
@@ -135,7 +135,7 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
                        continue; /* do not touch unmerged paths */
                if (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))
                        continue; /* do not touch non blobs */
-               if (pathspec && !ce_path_match(ce, pathspec, NULL))
+               if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
                        continue;
                retval |= add_file_to_cache(ce->name, flags | HASH_RENORMALIZE);
        }
@@ -155,7 +155,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
        i = dir->nr;
        while (--i >= 0) {
                struct dir_entry *entry = *src++;
-               if (dir_path_match(entry, pathspec, prefix, seen))
+               if (dir_path_match(&the_index, entry, pathspec, prefix, seen))
                        *dst++ = entry;
        }
        dir->nr = dst - dir->entries;
@@ -304,7 +304,8 @@ static struct option builtin_add_options[] = {
        OPT_BOOL( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")),
        OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
        OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
-       OPT_STRING( 0 , "chmod", &chmod_arg, N_("(+/-)x"), N_("override the executable bit of the listed files")),
+       OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
+                  N_("override the executable bit of the listed files")),
        OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
                        N_("warn when adding an embedded repository")),
        OPT_END(),
index 6273ea5195bb7f7f2296155753c5e7982d533d66..9f7ecf6ecb7711c35277fa827c4c2afc0dfba867 100644 (file)
@@ -32,6 +32,7 @@
 #include "apply.h"
 #include "string-list.h"
 #include "packfile.h"
+#include "repository.h"
 
 /**
  * Returns 1 if the file is empty or does not exist, 0 otherwise.
@@ -1400,9 +1401,10 @@ static void write_index_patch(const struct am_state *state)
        FILE *fp;
 
        if (!get_oid_tree("HEAD", &head))
-               tree = lookup_tree(&head);
+               tree = lookup_tree(the_repository, &head);
        else
-               tree = lookup_tree(the_hash_algo->empty_tree);
+               tree = lookup_tree(the_repository,
+                                  the_repository->hash_algo->empty_tree);
 
        fp = xfopen(am_path(state, "patch"), "w");
        init_revisions(&rev_info, NULL);
@@ -1462,7 +1464,7 @@ static int run_apply(const struct am_state *state, const char *index_file)
        int force_apply = 0;
        int options = 0;
 
-       if (init_apply_state(&apply_state, NULL))
+       if (init_apply_state(&apply_state, the_repository, NULL))
                BUG("init_apply_state() failed");
 
        argv_array_push(&apply_opts, "apply");
@@ -1631,7 +1633,8 @@ static void do_commit(const struct am_state *state)
 
        if (!get_oid_commit("HEAD", &parent)) {
                old_oid = &parent;
-               commit_list_insert(lookup_commit(&parent), &parents);
+               commit_list_insert(lookup_commit(the_repository, &parent),
+                                  &parents);
        } else {
                old_oid = NULL;
                say(state, stderr, _("applying to an empty history"));
@@ -1763,7 +1766,7 @@ static void am_run(struct am_state *state, int resume)
 
        refresh_and_write_cache();
 
-       if (index_has_changes(&sb)) {
+       if (index_has_changes(&the_index, NULL, &sb)) {
                write_state_bool(state, "dirtyindex", 1);
                die(_("Dirty index: cannot apply patches (dirty: %s)"), sb.buf);
        }
@@ -1820,7 +1823,8 @@ static void am_run(struct am_state *state, int resume)
                         * Applying the patch to an earlier tree and merging
                         * the result may have produced the same tree as ours.
                         */
-                       if (!apply_status && !index_has_changes(NULL)) {
+                       if (!apply_status &&
+                           !index_has_changes(&the_index, NULL, NULL)) {
                                say(state, stdout, _("No changes -- Patch already applied."));
                                goto next;
                        }
@@ -1874,7 +1878,7 @@ static void am_resolve(struct am_state *state)
 
        say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
 
-       if (!index_has_changes(NULL)) {
+       if (!index_has_changes(&the_index, 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."));
index 48d3989331d9b7deeb034642a027729bd1267e38..3f099b960565ff2944209ba514ea7274dad852f5 100644 (file)
@@ -16,7 +16,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
        int ret;
        struct apply_state state;
 
-       if (init_apply_state(&state, prefix))
+       if (init_apply_state(&state, the_repository, prefix))
                exit(128);
 
        argc = apply_parse_options(argc, argv,
index 73971d0dd20e7233d6cb1e6c16986ede25526939..e74f675390d975e3a8993037796aa6ef2f975cb7 100644 (file)
@@ -105,5 +105,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 
        setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
 
-       return write_archive(argc, argv, prefix, output, 0);
+       return write_archive(argc, argv, prefix, the_repository, output, 0);
 }
index 5a0388aaef580e8d3592e1b5b767618fe638ca0b..c2da673ac802b02609d54de3932fa8a2db221dbd 100644 (file)
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "color.h"
 #include "builtin.h"
+#include "repository.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
@@ -23,6 +24,7 @@
 #include "line-log.h"
 #include "dir.h"
 #include "progress.h"
+#include "object-store.h"
 #include "blame.h"
 #include "string-list.h"
 
@@ -408,7 +410,7 @@ static void parse_color_fields(const char *s)
        }
 
        if (next == EXPECT_COLOR)
-               die (_("must end with a color"));
+               die(_("must end with a color"));
 
        colorfield[colorfield_nr].hop = TIME_MAX;
        string_list_clear(&l, 0);
@@ -576,7 +578,7 @@ static int read_ancestry(const char *graft_file)
                /* The format is just "Commit Parent1 Parent2 ...\n" */
                struct commit_graft *graft = read_graft_line(&buf);
                if (graft)
-                       register_commit_graft(graft, 0);
+                       register_commit_graft(the_repository, graft, 0);
        }
        fclose(fp);
        strbuf_release(&buf);
@@ -986,6 +988,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        sb.revs = &revs;
        sb.contents_from = contents_from;
        sb.reverse = reverse;
+       sb.repo = the_repository;
        setup_scoreboard(&sb, path, &o);
        lno = sb.num_lines;
 
@@ -1000,13 +1003,13 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                                    nth_line_cb, &sb, lno, anchor,
                                    &bottom, &top, sb.path))
                        usage(blame_usage);
-               if (lno < top || ((lno || bottom) && lno < bottom))
+               if ((!lno && (top || bottom)) || lno < bottom)
                        die(Q_("file %s has only %lu line",
                               "file %s has only %lu lines",
                               lno), path, lno);
                if (bottom < 1)
                        bottom = 1;
-               if (top < 1)
+               if (top < 1 || lno < top)
                        top = lno;
                bottom--;
                range_set_append_unsafe(&ranges, bottom, top);
@@ -1069,7 +1072,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                find_alignment(&sb, &output_option);
                if (!*repeated_meta_color &&
                    (output_option & OUTPUT_COLOR_LINE))
-                       strcpy(repeated_meta_color, GIT_COLOR_CYAN);
+                       xsnprintf(repeated_meta_color,
+                                 sizeof(repeated_meta_color),
+                                 "%s", GIT_COLOR_CYAN);
        }
        if (output_option & OUTPUT_ANNOTATE_COMPAT)
                output_option &= ~(OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR);
index 1876ca9e7969019e1db1c97aedcf1064903b80a2..4fc55c3508c2fff3e92e6235ed35ba582caf4b15 100644 (file)
@@ -37,6 +37,7 @@ static const char * const builtin_branch_usage[] = {
 
 static const char *head;
 static struct object_id head_oid;
+static int used_deprecated_reflog_option;
 
 static int branch_use_color = -1;
 static char branch_colors[][COLOR_MAXLEN] = {
@@ -121,7 +122,8 @@ static int branch_merged(int kind, const char *name,
                    (reference_name = reference_name_to_free =
                     resolve_refdup(upstream, RESOLVE_REF_READING,
                                    &oid, NULL)) != NULL)
-                       reference_rev = lookup_commit_reference(&oid);
+                       reference_rev = lookup_commit_reference(the_repository,
+                                                               &oid);
        }
        if (!reference_rev)
                reference_rev = head_rev;
@@ -154,7 +156,7 @@ static int check_branch_commit(const char *branchname, const char *refname,
                               const struct object_id *oid, struct commit *head_rev,
                               int kinds, int force)
 {
-       struct commit *rev = lookup_commit_reference(oid);
+       struct commit *rev = lookup_commit_reference(the_repository, oid);
        if (!rev) {
                error(_("Couldn't look up commit object for '%s'"), refname);
                return -1;
@@ -208,7 +210,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
        }
 
        if (!force) {
-               head_rev = lookup_commit_reference(&head_oid);
+               head_rev = lookup_commit_reference(the_repository, &head_oid);
                if (!head_rev)
                        die(_("Couldn't look up commit object for HEAD"));
        }
@@ -568,6 +570,14 @@ static int edit_branch_description(const char *branch_name)
        return 0;
 }
 
+static int deprecated_reflog_option_cb(const struct option *opt,
+                                      const char *arg, int unset)
+{
+       used_deprecated_reflog_option = 1;
+       *(int *)opt->value = !unset;
+       return 0;
+}
+
 int cmd_branch(int argc, const char **argv, const char *prefix)
 {
        int delete = 0, rename = 0, copy = 0, force = 0, list = 0;
@@ -610,7 +620,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                OPT_BIT('c', "copy", &copy, N_("copy a branch and its reflog"), 1),
                OPT_BIT('C', NULL, &copy, N_("copy a branch, even if target exists"), 2),
                OPT_BOOL(0, "list", &list, N_("list branch names")),
-               OPT_BOOL('l', "create-reflog", &reflog, N_("create the branch's reflog")),
+               OPT_BOOL(0, "create-reflog", &reflog, N_("create the branch's reflog")),
+               {
+                       OPTION_CALLBACK, 'l', NULL, &reflog, NULL,
+                       N_("deprecated synonym for --create-reflog"),
+                       PARSE_OPT_NOARG | PARSE_OPT_HIDDEN,
+                       deprecated_reflog_option_cb
+               },
                OPT_BOOL(0, "edit-description", &edit_description,
                         N_("edit the description for the branch")),
                OPT__FORCE(&force, N_("force creation, move/rename, deletion"), PARSE_OPT_NOCOMPLETE),
@@ -683,6 +699,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
        if (list)
                setup_auto_pager("branch", 1);
 
+       if (used_deprecated_reflog_option && !list) {
+               warning("the '-l' alias for '--create-reflog' is deprecated;");
+               warning("it will be removed in a future version of Git");
+       }
+
        if (delete) {
                if (!argc)
                        die(_("branch name required"));
index 665b5819499b4d56a4f49996125cac919e477309..64ec1745ab2c20ef18a9292ef3b3c82efd46de17 100644 (file)
@@ -13,6 +13,7 @@
 #include "tree-walk.h"
 #include "sha1-array.h"
 #include "packfile.h"
+#include "object-store.h"
 
 struct batch_options {
        int enabled;
@@ -20,6 +21,7 @@ struct batch_options {
        int print_contents;
        int buffer_output;
        int all_objects;
+       int unordered;
        int cmdmode; /* may be 'w' or 'c' for --filters or --textconv */
        const char *format;
 };
@@ -38,7 +40,7 @@ static int filter_object(const char *path, unsigned mode,
                             oid_to_hex(oid), path);
        if ((type == OBJ_BLOB) && S_ISREG(mode)) {
                struct strbuf strbuf = STRBUF_INIT;
-               if (convert_to_working_tree(path, *buf, *size, &strbuf)) {
+               if (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf)) {
                        free(*buf);
                        *size = strbuf.len;
                        *buf = strbuf_detach(&strbuf, NULL);
@@ -336,11 +338,11 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
        }
 }
 
-static void batch_object_write(const char *obj_name, struct batch_options *opt,
+static void batch_object_write(const char *obj_name,
+                              struct strbuf *scratch,
+                              struct batch_options *opt,
                               struct expand_data *data)
 {
-       struct strbuf buf = STRBUF_INIT;
-
        if (!data->skip_object_info &&
            oid_object_info_extended(the_repository, &data->oid, &data->info,
                                     OBJECT_INFO_LOOKUP_REPLACE) < 0) {
@@ -350,10 +352,10 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
                return;
        }
 
-       strbuf_expand(&buf, opt->format, expand_format, data);
-       strbuf_addch(&buf, '\n');
-       batch_write(opt, buf.buf, buf.len);
-       strbuf_release(&buf);
+       strbuf_reset(scratch);
+       strbuf_expand(scratch, opt->format, expand_format, data);
+       strbuf_addch(scratch, '\n');
+       batch_write(opt, scratch->buf, scratch->len);
 
        if (opt->print_contents) {
                print_object_or_die(opt, data);
@@ -361,7 +363,9 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
        }
 }
 
-static void batch_one_object(const char *obj_name, struct batch_options *opt,
+static void batch_one_object(const char *obj_name,
+                            struct strbuf *scratch,
+                            struct batch_options *opt,
                             struct expand_data *data)
 {
        struct object_context ctx;
@@ -403,42 +407,70 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt,
                return;
        }
 
-       batch_object_write(obj_name, opt, data);
+       batch_object_write(obj_name, scratch, opt, data);
 }
 
 struct object_cb_data {
        struct batch_options *opt;
        struct expand_data *expand;
+       struct oidset *seen;
+       struct strbuf *scratch;
 };
 
 static int batch_object_cb(const struct object_id *oid, void *vdata)
 {
        struct object_cb_data *data = vdata;
        oidcpy(&data->expand->oid, oid);
-       batch_object_write(NULL, data->opt, data->expand);
+       batch_object_write(NULL, data->scratch, data->opt, data->expand);
        return 0;
 }
 
-static int batch_loose_object(const struct object_id *oid,
-                             const char *path,
-                             void *data)
+static int collect_loose_object(const struct object_id *oid,
+                               const char *path,
+                               void *data)
 {
        oid_array_append(data, oid);
        return 0;
 }
 
-static int batch_packed_object(const struct object_id *oid,
-                              struct packed_git *pack,
-                              uint32_t pos,
-                              void *data)
+static int collect_packed_object(const struct object_id *oid,
+                                struct packed_git *pack,
+                                uint32_t pos,
+                                void *data)
 {
        oid_array_append(data, oid);
        return 0;
 }
 
+static int batch_unordered_object(const struct object_id *oid, void *vdata)
+{
+       struct object_cb_data *data = vdata;
+
+       if (oidset_insert(data->seen, oid))
+               return 0;
+
+       return batch_object_cb(oid, data);
+}
+
+static int batch_unordered_loose(const struct object_id *oid,
+                                const char *path,
+                                void *data)
+{
+       return batch_unordered_object(oid, data);
+}
+
+static int batch_unordered_packed(const struct object_id *oid,
+                                 struct packed_git *pack,
+                                 uint32_t pos,
+                                 void *data)
+{
+       return batch_unordered_object(oid, data);
+}
+
 static int batch_objects(struct batch_options *opt)
 {
-       struct strbuf buf = STRBUF_INIT;
+       struct strbuf input = STRBUF_INIT;
+       struct strbuf output = STRBUF_INIT;
        struct expand_data data;
        int save_warning;
        int retval = 0;
@@ -453,8 +485,9 @@ static int batch_objects(struct batch_options *opt)
         */
        memset(&data, 0, sizeof(data));
        data.mark_query = 1;
-       strbuf_expand(&buf, opt->format, expand_format, &data);
+       strbuf_expand(&output, opt->format, expand_format, &data);
        data.mark_query = 0;
+       strbuf_release(&output);
        if (opt->cmdmode)
                data.split_on_whitespace = 1;
 
@@ -472,19 +505,37 @@ static int batch_objects(struct batch_options *opt)
                data.info.typep = &data.type;
 
        if (opt->all_objects) {
-               struct oid_array sa = OID_ARRAY_INIT;
                struct object_cb_data cb;
 
-               for_each_loose_object(batch_loose_object, &sa, 0);
-               for_each_packed_object(batch_packed_object, &sa, 0);
                if (repository_format_partial_clone)
                        warning("This repository has extensions.partialClone set. Some objects may not be loaded.");
 
                cb.opt = opt;
                cb.expand = &data;
-               oid_array_for_each_unique(&sa, batch_object_cb, &cb);
+               cb.scratch = &output;
+
+               if (opt->unordered) {
+                       struct oidset seen = OIDSET_INIT;
+
+                       cb.seen = &seen;
+
+                       for_each_loose_object(batch_unordered_loose, &cb, 0);
+                       for_each_packed_object(batch_unordered_packed, &cb,
+                                              FOR_EACH_OBJECT_PACK_ORDER);
+
+                       oidset_clear(&seen);
+               } else {
+                       struct oid_array sa = OID_ARRAY_INIT;
+
+                       for_each_loose_object(collect_loose_object, &sa, 0);
+                       for_each_packed_object(collect_packed_object, &sa, 0);
+
+                       oid_array_for_each_unique(&sa, batch_object_cb, &cb);
+
+                       oid_array_clear(&sa);
+               }
 
-               oid_array_clear(&sa);
+               strbuf_release(&output);
                return 0;
        }
 
@@ -498,14 +549,14 @@ static int batch_objects(struct batch_options *opt)
        save_warning = warn_on_object_refname_ambiguity;
        warn_on_object_refname_ambiguity = 0;
 
-       while (strbuf_getline(&buf, stdin) != EOF) {
+       while (strbuf_getline(&input, stdin) != EOF) {
                if (data.split_on_whitespace) {
                        /*
                         * Split at first whitespace, tying off the beginning
                         * of the string and saving the remainder (or NULL) in
                         * data.rest.
                         */
-                       char *p = strpbrk(buf.buf, " \t");
+                       char *p = strpbrk(input.buf, " \t");
                        if (p) {
                                while (*p && strchr(" \t", *p))
                                        *p++ = '\0';
@@ -513,10 +564,11 @@ static int batch_objects(struct batch_options *opt)
                        data.rest = p;
                }
 
-               batch_one_object(buf.buf, opt, &data);
+               batch_one_object(input.buf, &output, opt, &data);
        }
 
-       strbuf_release(&buf);
+       strbuf_release(&input);
+       strbuf_release(&output);
        warn_on_object_refname_ambiguity = save_warning;
        return retval;
 }
@@ -585,6 +637,8 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
                         N_("follow in-tree symlinks (used with --batch or --batch-check)")),
                OPT_BOOL(0, "batch-all-objects", &batch.all_objects,
                         N_("show all objects with --batch or --batch-check")),
+               OPT_BOOL(0, "unordered", &batch.unordered,
+                        N_("do not order --batch-all-objects output")),
                OPT_END()
        };
 
index 91444dc0448b32e854f1923fe1e57e28c87f5b35..c05573ff9cd091cbe3b5ff1980fa7fb4815f6ebd 100644 (file)
@@ -63,9 +63,9 @@ static void check_attr(const char *prefix,
                prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
 
        if (collect_all) {
-               git_all_attrs(full_path, check);
+               git_all_attrs(&the_index, full_path, check);
        } else {
-               if (git_check_attr(full_path, check))
+               if (git_check_attr(&the_index, full_path, check))
                        die("git_check_attr died");
        }
        output_attr(check, file);
@@ -120,7 +120,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
        }
 
        if (cached_attrs)
-               git_attr_set_direction(GIT_ATTR_INDEX, NULL);
+               git_attr_set_direction(GIT_ATTR_INDEX);
 
        doubledash = -1;
        for (i = 0; doubledash < 0 && i < argc; i++) {
index a730f6a1aa47a60d4c131ee47076411a129d8080..d92db62fbdf15c14ff3d85b767a069b22aa3897d 100644 (file)
@@ -190,6 +190,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
 
        argc = parse_options(argc, argv, prefix, builtin_checkout_index_options,
                        builtin_checkout_index_usage, 0);
+       state.istate = &the_index;
        state.force = force;
        state.quiet = quiet;
        state.not_new = not_new;
index 4c41d8b4c831937354fca62f454b83e311f79145..29ef50013dccbd118093af0b4dc08eb907953cc2 100644 (file)
@@ -4,6 +4,7 @@
 #include "lockfile.h"
 #include "parse-options.h"
 #include "refs.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "tree-walk.h"
@@ -22,6 +23,7 @@
 #include "resolve-undo.h"
 #include "submodule-config.h"
 #include "submodule.h"
+#include "advice.h"
 
 static const char * const checkout_usage[] = {
        N_("git checkout [<options>] <branch>"),
@@ -77,7 +79,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
                return READ_TREE_RECURSIVE;
 
        len = base->len + strlen(pathname);
-       ce = xcalloc(1, cache_entry_size(len));
+       ce = make_empty_cache_entry(&the_index, len);
        oidcpy(&ce->oid, oid);
        memcpy(ce->name, base->buf, base->len);
        memcpy(ce->name + base->len, pathname, len - base->len);
@@ -96,7 +98,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
                if (ce->ce_mode == old->ce_mode &&
                    !oidcmp(&ce->oid, &old->oid)) {
                        old->ce_flags |= CE_UPDATE;
-                       free(ce);
+                       discard_cache_entry(ce);
                        return 0;
                }
        }
@@ -230,11 +232,11 @@ static int checkout_merged(int pos, const struct checkout *state)
        if (write_object_file(result_buf.ptr, result_buf.size, blob_type, &oid))
                die(_("Unable to add merge result for '%s'"), path);
        free(result_buf.ptr);
-       ce = make_cache_entry(mode, oid.hash, path, 2, 0);
+       ce = make_transient_cache_entry(mode, &oid, path, 2);
        if (!ce)
                die(_("make_cache_entry failed for path '%s'"), path);
        status = checkout_entry(ce, state, NULL);
-       free(ce);
+       discard_cache_entry(ce);
        return status;
 }
 
@@ -316,7 +318,7 @@ static int checkout_paths(const struct checkout_opts *opts,
                 * match_pathspec() for _all_ entries when
                 * opts->source_tree != NULL.
                 */
-               if (ce_path_match(ce, &opts->pathspec, ps_matched))
+               if (ce_path_match(&the_index, ce, &opts->pathspec, ps_matched))
                        ce->ce_flags |= CE_MATCHED;
        }
 
@@ -378,7 +380,7 @@ static int checkout_paths(const struct checkout_opts *opts,
                die(_("unable to write new index file"));
 
        read_ref_full("HEAD", 0, &rev, NULL);
-       head = lookup_commit_reference_gently(&rev, 1);
+       head = lookup_commit_reference_gently(the_repository, &rev, 1);
 
        errs |= post_checkout_hook(head, head, 0);
        return errs;
@@ -829,7 +831,7 @@ static int switch_branches(const struct checkout_opts *opts,
        memset(&old_branch_info, 0, sizeof(old_branch_info));
        old_branch_info.path = path_to_free = resolve_refdup("HEAD", 0, &rev, &flag);
        if (old_branch_info.path)
-               old_branch_info.commit = lookup_commit_reference_gently(&rev, 1);
+               old_branch_info.commit = lookup_commit_reference_gently(the_repository, &rev, 1);
        if (!(flag & REF_ISSYMREF))
                old_branch_info.path = NULL;
 
@@ -878,7 +880,8 @@ static int parse_branchname_arg(int argc, const char **argv,
                                int dwim_new_local_branch_ok,
                                struct branch_info *new_branch_info,
                                struct checkout_opts *opts,
-                               struct object_id *rev)
+                               struct object_id *rev,
+                               int *dwim_remotes_matched)
 {
        struct tree **source_tree = &opts->source_tree;
        const char **new_branch = &opts->new_branch;
@@ -910,8 +913,10 @@ static int parse_branchname_arg(int argc, const char **argv,
         *   (b) If <something> is _not_ a commit, either "--" is present
         *       or <something> is not a path, no -t or -b was given, and
         *       and there is a tracking branch whose name is <something>
-        *       in one and only one remote, then this is a short-hand to
-        *       fork local <something> from that remote-tracking branch.
+        *       in one and only one remote (or if the branch exists on the
+        *       remote named in checkout.defaultRemote), then this is a
+        *       short-hand to fork local <something> from that
+        *       remote-tracking branch.
         *
         *   (c) Otherwise, if "--" is present, treat it like case (1).
         *
@@ -972,7 +977,8 @@ static int parse_branchname_arg(int argc, const char **argv,
                        recover_with_dwim = 0;
 
                if (recover_with_dwim) {
-                       const char *remote = unique_tracking_name(arg, rev);
+                       const char *remote = unique_tracking_name(arg, rev,
+                                                                 dwim_remotes_matched);
                        if (remote) {
                                *new_branch = arg;
                                arg = remote;
@@ -1003,7 +1009,7 @@ static int parse_branchname_arg(int argc, const char **argv,
        else
                new_branch_info->path = NULL; /* not an existing branch */
 
-       new_branch_info->commit = lookup_commit_reference_gently(rev, 1);
+       new_branch_info->commit = lookup_commit_reference_gently(the_repository, rev, 1);
        if (!new_branch_info->commit) {
                /* not a commit */
                *source_tree = parse_tree_indirect(rev);
@@ -1109,6 +1115,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        struct branch_info new_branch_info;
        char *conflict_style = NULL;
        int dwim_new_local_branch = 1;
+       int dwim_remotes_matched = 0;
        struct option options[] = {
                OPT__QUIET(&opts.quiet, N_("suppress progress reporting")),
                OPT_STRING('b', NULL, &opts.new_branch, N_("branch"),
@@ -1191,12 +1198,12 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        if (opts.track != BRANCH_TRACK_UNSPECIFIED && !opts.new_branch) {
                const char *argv0 = argv[0];
                if (!argc || !strcmp(argv0, "--"))
-                       die (_("--track needs a branch name"));
+                       die(_("--track needs a branch name"));
                skip_prefix(argv0, "refs/", &argv0);
                skip_prefix(argv0, "remotes/", &argv0);
                argv0 = strchr(argv0, '/');
                if (!argv0 || !argv0[1])
-                       die (_("Missing branch name; try -b"));
+                       die(_("missing branch name; try -b"));
                opts.new_branch = argv0 + 1;
        }
 
@@ -1221,7 +1228,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                        opts.track == BRANCH_TRACK_UNSPECIFIED &&
                        !opts.new_branch;
                int n = parse_branchname_arg(argc, argv, dwim_ok,
-                                            &new_branch_info, &opts, &rev);
+                                            &new_branch_info, &opts, &rev,
+                                            &dwim_remotes_matched);
                argv += n;
                argc -= n;
        }
@@ -1263,8 +1271,26 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        }
 
        UNLEAK(opts);
-       if (opts.patch_mode || opts.pathspec.nr)
-               return checkout_paths(&opts, new_branch_info.name);
-       else
+       if (opts.patch_mode || opts.pathspec.nr) {
+               int ret = checkout_paths(&opts, new_branch_info.name);
+               if (ret && dwim_remotes_matched > 1 &&
+                   advice_checkout_ambiguous_remote_branch_name)
+                       advise(_("'%s' matched more than one remote tracking branch.\n"
+                                "We found %d remotes with a reference that matched. So we fell back\n"
+                                "on trying to resolve the argument as a path, but failed there too!\n"
+                                "\n"
+                                "If you meant to check out a remote tracking branch on, e.g. 'origin',\n"
+                                "you can do so by fully qualifying the name with the --track option:\n"
+                                "\n"
+                                "    git checkout --track origin/<name>\n"
+                                "\n"
+                                "If you'd like to always have checkouts of an ambiguous <name> prefer\n"
+                                "one remote, e.g. the 'origin' remote, consider setting\n"
+                                "checkout.defaultRemote=origin in your config."),
+                              argv[0],
+                              dwim_remotes_matched);
+               return ret;
+       } else {
                return checkout_branch(&opts, &new_branch_info);
+       }
 }
index ab402c204cbcaea6190608753311605d37ca83d2..8d9a7dc20647079bc5f35b446bbbab5479abb32d 100644 (file)
@@ -976,7 +976,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
                        continue;
 
                if (pathspec.nr)
-                       matches = dir_path_match(ent, &pathspec, 0, NULL);
+                       matches = dir_path_match(&the_index, ent, &pathspec, 0, NULL);
 
                if (pathspec.nr && !matches)
                        continue;
index 74a804f2e814b726c95e8f572f91eba581c6ca4b..fd2c3ef090146058651af5e411dd304153ee114d 100644 (file)
@@ -15,6 +15,7 @@
 #include "fetch-pack.h"
 #include "refs.h"
 #include "refspec.h"
+#include "object-store.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "unpack-trees.h"
@@ -695,7 +696,8 @@ static void update_head(const struct ref *our, const struct ref *remote,
                        install_branch_config(0, head, option_origin, our->name);
                }
        } else if (our) {
-               struct commit *c = lookup_commit_reference(&our->old_oid);
+               struct commit *c = lookup_commit_reference(the_repository,
+                                                          &our->old_oid);
                /* --branch specifies a non-branch (i.e. tags), detach HEAD */
                update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NO_DEREF,
                           UPDATE_REFS_DIE_ON_ERR);
@@ -895,7 +897,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        int err = 0, complete_refs_before_fetch = 1;
        int submodule_progress;
 
-       struct refspec_item refspec;
+       struct refspec rs = REFSPEC_INIT_FETCH;
+       struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
 
        fetch_if_missing = 0;
 
@@ -1077,7 +1080,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        if (option_required_reference.nr || option_optional_reference.nr)
                setup_reference();
 
-       refspec_item_init_or_die(&refspec, value.buf, REFSPEC_FETCH);
+       refspec_append(&rs, value.buf);
 
        strbuf_reset(&value);
 
@@ -1134,10 +1137,18 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        if (transport->smart_options && !deepen && !filter_options.choice)
                transport->smart_options->check_self_contained_and_connected = 1;
 
-       refs = transport_get_remote_refs(transport, NULL);
+
+       argv_array_push(&ref_prefixes, "HEAD");
+       refspec_ref_prefixes(&rs, &ref_prefixes);
+       if (option_branch)
+               expand_ref_prefix(&ref_prefixes, option_branch);
+       if (!option_no_tags)
+               argv_array_push(&ref_prefixes, "refs/tags/");
+
+       refs = transport_get_remote_refs(transport, &ref_prefixes);
 
        if (refs) {
-               mapped_refs = wanted_peer_refs(refs, &refspec);
+               mapped_refs = wanted_peer_refs(refs, &rs.items[0]);
                /*
                 * transport_get_remote_refs() may return refs with null sha-1
                 * in mapped_refs (see struct transport->get_refs_list
@@ -1201,7 +1212,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
        update_remote_refs(refs, mapped_refs, remote_head_points_at,
                           branch_top.buf, reflog_msg.buf, transport,
-                          !is_local && !filter_options.choice);
+                          !is_local);
 
        update_head(our_head_points_at, remote_head, reflog_msg.buf);
 
@@ -1231,6 +1242,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        strbuf_release(&value);
        junk_mode = JUNK_LEAVE_ALL;
 
-       refspec_item_clear(&refspec);
+       refspec_clear(&rs);
+       argv_array_clear(&ref_prefixes);
        return err;
 }
index 37420ae0fde81ea2e957bedd4949a2eba0cd6ff9..0bf0c486575a8557b729658ce05be02d28a1a8b8 100644 (file)
@@ -3,12 +3,19 @@
 #include "dir.h"
 #include "lockfile.h"
 #include "parse-options.h"
+#include "repository.h"
 #include "commit-graph.h"
 
 static char const * const builtin_commit_graph_usage[] = {
        N_("git commit-graph [--object-dir <objdir>]"),
        N_("git commit-graph read [--object-dir <objdir>]"),
-       N_("git commit-graph write [--object-dir <objdir>] [--append] [--stdin-packs|--stdin-commits]"),
+       N_("git commit-graph verify [--object-dir <objdir>]"),
+       N_("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits]"),
+       NULL
+};
+
+static const char * const builtin_commit_graph_verify_usage[] = {
+       N_("git commit-graph verify [--object-dir <objdir>]"),
        NULL
 };
 
@@ -18,17 +25,48 @@ static const char * const builtin_commit_graph_read_usage[] = {
 };
 
 static const char * const builtin_commit_graph_write_usage[] = {
-       N_("git commit-graph write [--object-dir <objdir>] [--append] [--stdin-packs|--stdin-commits]"),
+       N_("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits]"),
        NULL
 };
 
 static struct opts_commit_graph {
        const char *obj_dir;
+       int reachable;
        int stdin_packs;
        int stdin_commits;
        int append;
 } opts;
 
+
+static int graph_verify(int argc, const char **argv)
+{
+       struct commit_graph *graph = NULL;
+       char *graph_name;
+
+       static struct option builtin_commit_graph_verify_options[] = {
+               OPT_STRING(0, "object-dir", &opts.obj_dir,
+                          N_("dir"),
+                          N_("The object directory to store the graph")),
+               OPT_END(),
+       };
+
+       argc = parse_options(argc, argv, NULL,
+                            builtin_commit_graph_verify_options,
+                            builtin_commit_graph_verify_usage, 0);
+
+       if (!opts.obj_dir)
+               opts.obj_dir = get_object_directory();
+
+       graph_name = get_commit_graph_filename(opts.obj_dir);
+       graph = load_commit_graph_one(graph_name);
+       FREE_AND_NULL(graph_name);
+
+       if (!graph)
+               return 0;
+
+       return verify_commit_graph(the_repository, graph);
+}
+
 static int graph_read(int argc, const char **argv)
 {
        struct commit_graph *graph = NULL;
@@ -51,8 +89,11 @@ static int graph_read(int argc, const char **argv)
        graph_name = get_commit_graph_filename(opts.obj_dir);
        graph = load_commit_graph_one(graph_name);
 
-       if (!graph)
+       if (!graph) {
+               UNLEAK(graph_name);
                die("graph file %s does not exist", graph_name);
+       }
+
        FREE_AND_NULL(graph_name);
 
        printf("header: %08x %d %d %d %d\n",
@@ -74,23 +115,23 @@ static int graph_read(int argc, const char **argv)
                printf(" large_edges");
        printf("\n");
 
+       free_commit_graph(graph);
+
        return 0;
 }
 
 static int graph_write(int argc, const char **argv)
 {
-       const char **pack_indexes = NULL;
-       int packs_nr = 0;
-       const char **commit_hex = NULL;
-       int commits_nr = 0;
-       const char **lines = NULL;
-       int lines_nr = 0;
-       int lines_alloc = 0;
+       struct string_list *pack_indexes = NULL;
+       struct string_list *commit_hex = NULL;
+       struct string_list lines;
 
        static struct option builtin_commit_graph_write_options[] = {
                OPT_STRING(0, "object-dir", &opts.obj_dir,
                        N_("dir"),
                        N_("The object directory to store the graph")),
+               OPT_BOOL(0, "reachable", &opts.reachable,
+                       N_("start walk at all refs")),
                OPT_BOOL(0, "stdin-packs", &opts.stdin_packs,
                        N_("scan pack-indexes listed by stdin for commits")),
                OPT_BOOL(0, "stdin-commits", &opts.stdin_commits,
@@ -104,39 +145,35 @@ static int graph_write(int argc, const char **argv)
                             builtin_commit_graph_write_options,
                             builtin_commit_graph_write_usage, 0);
 
-       if (opts.stdin_packs && opts.stdin_commits)
-               die(_("cannot use both --stdin-commits and --stdin-packs"));
+       if (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1)
+               die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs"));
        if (!opts.obj_dir)
                opts.obj_dir = get_object_directory();
 
+       if (opts.reachable) {
+               write_commit_graph_reachable(opts.obj_dir, opts.append);
+               return 0;
+       }
+
+       string_list_init(&lines, 0);
        if (opts.stdin_packs || opts.stdin_commits) {
                struct strbuf buf = STRBUF_INIT;
-               lines_nr = 0;
-               lines_alloc = 128;
-               ALLOC_ARRAY(lines, lines_alloc);
-
-               while (strbuf_getline(&buf, stdin) != EOF) {
-                       ALLOC_GROW(lines, lines_nr + 1, lines_alloc);
-                       lines[lines_nr++] = strbuf_detach(&buf, NULL);
-               }
-
-               if (opts.stdin_packs) {
-                       pack_indexes = lines;
-                       packs_nr = lines_nr;
-               }
-               if (opts.stdin_commits) {
-                       commit_hex = lines;
-                       commits_nr = lines_nr;
-               }
+
+               while (strbuf_getline(&buf, stdin) != EOF)
+                       string_list_append(&lines, strbuf_detach(&buf, NULL));
+
+               if (opts.stdin_packs)
+                       pack_indexes = &lines;
+               if (opts.stdin_commits)
+                       commit_hex = &lines;
        }
 
        write_commit_graph(opts.obj_dir,
                           pack_indexes,
-                          packs_nr,
                           commit_hex,
-                          commits_nr,
                           opts.append);
 
+       string_list_clear(&lines, 0);
        return 0;
 }
 
@@ -162,6 +199,8 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix)
        if (argc > 0) {
                if (!strcmp(argv[0], "read"))
                        return graph_read(argc, argv);
+               if (!strcmp(argv[0], "verify"))
+                       return graph_verify(argc, argv);
                if (!strcmp(argv[0], "write"))
                        return graph_write(argc, argv);
        }
index ecf42191da10cd2e87360f001d5493e792b9682e..9ec36a82b63c0216cca11a709310e12174726e91 100644 (file)
@@ -5,6 +5,8 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "tree.h"
 #include "builtin.h"
@@ -59,7 +61,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
                        if (get_oid_commit(argv[i], &oid))
                                die("Not a valid object name %s", argv[i]);
                        assert_oid_type(&oid, OBJ_COMMIT);
-                       new_parent(lookup_commit(&oid), &parents);
+                       new_parent(lookup_commit(the_repository, &oid),
+                                                &parents);
                        continue;
                }
 
index 9bcbb0c25cb44e6230a9d4c1c4564dd2c9eb5acc..0d9828e29ebe89f037e68761d5cd5b407339cd48 100644 (file)
@@ -168,9 +168,9 @@ static int opt_parse_rename_score(const struct option *opt, const char *arg, int
 
 static void determine_whence(struct wt_status *s)
 {
-       if (file_exists(git_path_merge_head()))
+       if (file_exists(git_path_merge_head(the_repository)))
                whence = FROM_MERGE;
-       else if (file_exists(git_path_cherry_pick_head())) {
+       else if (file_exists(git_path_cherry_pick_head(the_repository))) {
                whence = FROM_CHERRY_PICK;
                if (file_exists(git_path_seq_dir()))
                        sequencer_in_use = 1;
@@ -251,7 +251,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
 
                if (ce->ce_flags & CE_UPDATE)
                        continue;
-               if (!ce_path_match(ce, pattern, m))
+               if (!ce_path_match(&the_index, ce, pattern, m))
                        continue;
                item = string_list_insert(list, ce->name);
                if (ce_skip_worktree(ce))
@@ -718,21 +718,21 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                if (have_option_m)
                        strbuf_addbuf(&sb, &message);
                hook_arg1 = "message";
-       } else if (!stat(git_path_merge_msg(), &statbuf)) {
+       } else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {
                /*
                 * prepend SQUASH_MSG here if it exists and a
                 * "merge --squash" was originally performed
                 */
-               if (!stat(git_path_squash_msg(), &statbuf)) {
-                       if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
+               if (!stat(git_path_squash_msg(the_repository), &statbuf)) {
+                       if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)
                                die_errno(_("could not read SQUASH_MSG"));
                        hook_arg1 = "squash";
                } else
                        hook_arg1 = "merge";
-               if (strbuf_read_file(&sb, git_path_merge_msg(), 0) < 0)
+               if (strbuf_read_file(&sb, git_path_merge_msg(the_repository), 0) < 0)
                        die_errno(_("could not read MERGE_MSG"));
-       } else if (!stat(git_path_squash_msg(), &statbuf)) {
-               if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
+       } else if (!stat(git_path_squash_msg(the_repository), &statbuf)) {
+               if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)
                        die_errno(_("could not read SQUASH_MSG"));
                hook_arg1 = "squash";
        } else if (template_file) {
@@ -813,8 +813,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                                        "       %s\n"
                                        "and try again.\n"),
                                whence == FROM_MERGE ?
-                                       git_path_merge_head() :
-                                       git_path_cherry_pick_head());
+                                       git_path_merge_head(the_repository) :
+                                       git_path_cherry_pick_head(the_repository));
                }
 
                fprintf(s->fp, "\n");
@@ -1564,7 +1564,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                if (!reflog_msg)
                        reflog_msg = "commit (merge)";
                pptr = commit_list_append(current_head, pptr);
-               fp = xfopen(git_path_merge_head(), "r");
+               fp = xfopen(git_path_merge_head(the_repository), "r");
                while (strbuf_getline_lf(&m, fp) != EOF) {
                        struct commit *parent;
 
@@ -1575,8 +1575,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                }
                fclose(fp);
                strbuf_release(&m);
-               if (!stat(git_path_merge_mode(), &statbuf)) {
-                       if (strbuf_read_file(&sb, git_path_merge_mode(), 0) < 0)
+               if (!stat(git_path_merge_mode(the_repository), &statbuf)) {
+                       if (strbuf_read_file(&sb, git_path_merge_mode(the_repository), 0) < 0)
                                die_errno(_("could not read MERGE_MODE"));
                        if (!strcmp(sb.buf, "no-ff"))
                                allow_fast_forward = 0;
@@ -1639,17 +1639,17 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                die("%s", err.buf);
        }
 
-       unlink(git_path_cherry_pick_head());
-       unlink(git_path_revert_head());
-       unlink(git_path_merge_head());
-       unlink(git_path_merge_msg());
-       unlink(git_path_merge_mode());
-       unlink(git_path_squash_msg());
+       unlink(git_path_cherry_pick_head(the_repository));
+       unlink(git_path_revert_head(the_repository));
+       unlink(git_path_merge_head(the_repository));
+       unlink(git_path_merge_msg(the_repository));
+       unlink(git_path_merge_mode(the_repository));
+       unlink(git_path_squash_msg(the_repository));
 
        if (commit_index_files())
-               die (_("Repository has been updated, but unable to write\n"
-                    "new_index file. Check that disk is not full and quota is\n"
-                    "not exceeded, and then \"git reset HEAD\" to recover."));
+               die(_("repository has been updated, but unable to write\n"
+                     "new_index file. Check that disk is not full and quota is\n"
+                     "not exceeded, and then \"git reset HEAD\" to recover."));
 
        rerere(0);
        run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
index b29d26dede79b9a5c46bdc4f951b22e7b88310b3..97b58c4aeac4a390148192578d92191407ec7e13 100644 (file)
@@ -67,7 +67,7 @@ static int show_origin;
        { OPTION_CALLBACK, (s), (l), (v), NULL, (h), PARSE_OPT_NOARG | \
        PARSE_OPT_NONEG, option_parse_type, (i) }
 
-static struct option builtin_config_options[];
+static NORETURN void usage_builtin_config(void);
 
 static int option_parse_type(const struct option *opt, const char *arg,
                             int unset)
@@ -110,9 +110,8 @@ static int option_parse_type(const struct option *opt, const char *arg,
                 * --int' and '--type=bool
                 * --type=int'.
                 */
-               error("only one type at a time.");
-               usage_with_options(builtin_config_usage,
-                       builtin_config_options);
+               error(_("only one type at a time"));
+               usage_builtin_config();
        }
        *to_type = new_type;
 
@@ -157,11 +156,20 @@ static struct option builtin_config_options[] = {
        OPT_END(),
 };
 
+static NORETURN void usage_builtin_config(void)
+{
+       usage_with_options(builtin_config_usage, builtin_config_options);
+}
+
 static void check_argc(int argc, int min, int max) {
        if (argc >= min && argc <= max)
                return;
-       error("wrong number of arguments");
-       usage_with_options(builtin_config_usage, builtin_config_options);
+       if (min == max)
+               error(_("wrong number of arguments, should be %d"), min);
+       else
+               error(_("wrong number of arguments, should be from %d to %d"),
+                     min, max);
+       usage_builtin_config();
 }
 
 static void show_config_origin(struct strbuf *buf)
@@ -293,7 +301,7 @@ static int get_value(const char *key_, const char *regex_)
 
                key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
                if (regcomp(key_regexp, key, REG_EXTENDED)) {
-                       error("invalid key pattern: %s", key_);
+                       error(_("invalid key pattern: %s"), key_);
                        FREE_AND_NULL(key_regexp);
                        ret = CONFIG_INVALID_PATTERN;
                        goto free_strings;
@@ -313,7 +321,7 @@ static int get_value(const char *key_, const char *regex_)
 
                regexp = (regex_t*)xmalloc(sizeof(regex_t));
                if (regcomp(regexp, regex_, REG_EXTENDED)) {
-                       error("invalid pattern: %s", regex_);
+                       error(_("invalid pattern: %s"), regex_);
                        FREE_AND_NULL(regexp);
                        ret = CONFIG_INVALID_PATTERN;
                        goto free_strings;
@@ -386,7 +394,7 @@ static char *normalize_value(const char *key, const char *value)
        if (type == TYPE_COLOR) {
                char v[COLOR_MAXLEN];
                if (git_config_color(v, key, value))
-                       die("cannot parse color '%s'", value);
+                       die(_("cannot parse color '%s'"), value);
 
                /*
                 * The contents of `v` now contain an ANSI escape
@@ -481,13 +489,13 @@ static int get_colorbool(const char *var, int print)
 static void check_write(void)
 {
        if (!given_config_source.file && !startup_info->have_repository)
-               die("not in a git directory");
+               die(_("not in a git directory"));
 
        if (given_config_source.use_stdin)
-               die("writing to stdin is not supported");
+               die(_("writing to stdin is not supported"));
 
        if (given_config_source.blob)
-               die("writing config blobs is not supported");
+               die(_("writing config blobs is not supported"));
 }
 
 struct urlmatch_current_candidate_value {
@@ -595,8 +603,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 
        if (use_global_config + use_system_config + use_local_config +
            !!given_config_source.file + !!given_config_source.blob > 1) {
-               error("only one config file at a time.");
-               usage_with_options(builtin_config_usage, builtin_config_options);
+               error(_("only one config file at a time"));
+               usage_builtin_config();
        }
 
        if (use_local_config && nongit)
@@ -622,7 +630,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                         * location; error out even if XDG_CONFIG_HOME
                         * is set and points at a sane location.
                         */
-                       die("$HOME not set");
+                       die(_("$HOME not set"));
 
                if (access_or_warn(user_config, R_OK, 0) &&
                    xdg_config && !access_or_warn(xdg_config, R_OK, 0)) {
@@ -659,13 +667,13 @@ int cmd_config(int argc, const char **argv, const char *prefix)
        }
 
        if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && type) {
-               error("--get-color and variable type are incoherent");
-               usage_with_options(builtin_config_usage, builtin_config_options);
+               error(_("--get-color and variable type are incoherent"));
+               usage_builtin_config();
        }
 
        if (HAS_MULTI_BITS(actions)) {
-               error("only one action at a time.");
-               usage_with_options(builtin_config_usage, builtin_config_options);
+               error(_("only one action at a time"));
+               usage_builtin_config();
        }
        if (actions == 0)
                switch (argc) {
@@ -673,25 +681,24 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                case 2: actions = ACTION_SET; break;
                case 3: actions = ACTION_SET_ALL; break;
                default:
-                       usage_with_options(builtin_config_usage, builtin_config_options);
+                       usage_builtin_config();
                }
        if (omit_values &&
            !(actions == ACTION_LIST || actions == ACTION_GET_REGEXP)) {
-               error("--name-only is only applicable to --list or --get-regexp");
-               usage_with_options(builtin_config_usage, builtin_config_options);
+               error(_("--name-only is only applicable to --list or --get-regexp"));
+               usage_builtin_config();
        }
 
        if (show_origin && !(actions &
                (ACTION_GET|ACTION_GET_ALL|ACTION_GET_REGEXP|ACTION_LIST))) {
-               error("--show-origin is only applicable to --get, --get-all, "
-                         "--get-regexp, and --list.");
-               usage_with_options(builtin_config_usage, builtin_config_options);
+               error(_("--show-origin is only applicable to --get, --get-all, "
+                       "--get-regexp, and --list"));
+               usage_builtin_config();
        }
 
        if (default_value && !(actions & ACTION_GET)) {
-               error("--default is only applicable to --get");
-               usage_with_options(builtin_config_usage,
-                       builtin_config_options);
+               error(_("--default is only applicable to --get"));
+               usage_builtin_config();
        }
 
        if (actions & PAGING_ACTIONS)
@@ -703,10 +710,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                                        &given_config_source,
                                        &config_options) < 0) {
                        if (given_config_source.file)
-                               die_errno("unable to read config file '%s'",
+                               die_errno(_("unable to read config file '%s'"),
                                          given_config_source.file);
                        else
-                               die("error processing config file(s)");
+                               die(_("error processing config file(s)"));
                }
        }
        else if (actions == ACTION_EDIT) {
@@ -714,11 +721,11 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 
                check_argc(argc, 0, 0);
                if (!given_config_source.file && nongit)
-                       die("not in a git directory");
+                       die(_("not in a git directory"));
                if (given_config_source.use_stdin)
-                       die("editing stdin is not supported");
+                       die(_("editing stdin is not supported"));
                if (given_config_source.blob)
-                       die("editing blobs is not supported");
+                       die(_("editing blobs is not supported"));
                git_config(git_default_config, NULL);
                config_file = given_config_source.file ?
                                xstrdup(given_config_source.file) :
@@ -819,7 +826,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                if (ret < 0)
                        return ret;
                if (ret == 0)
-                       die("No such section!");
+                       die(_("no such section: %s"), argv[0]);
        }
        else if (actions == ACTION_REMOVE_SECTION) {
                int ret;
@@ -830,7 +837,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                if (ret < 0)
                        return ret;
                if (ret == 0)
-                       die("No such section!");
+                       die(_("no such section: %s"), argv[0]);
        }
        else if (actions == ACTION_GET_COLOR) {
                check_argc(argc, 1, 2);
index bec2513b66cea8e5b3c7bae5de2c2e0bd31aecc9..41606c8a90092bca3f782980baf37031744e0cd6 100644 (file)
@@ -13,6 +13,7 @@
 #include "hashmap.h"
 #include "argv-array.h"
 #include "run-command.h"
+#include "object-store.h"
 #include "revision.h"
 #include "list-objects.h"
 #include "commit-slab.h"
@@ -92,13 +93,13 @@ static int replace_name(struct commit_name *e,
                struct tag *t;
 
                if (!e->tag) {
-                       t = lookup_tag(&e->oid);
+                       t = lookup_tag(the_repository, &e->oid);
                        if (!t || parse_tag(t))
                                return 1;
                        e->tag = t;
                }
 
-               t = lookup_tag(oid);
+               t = lookup_tag(the_repository, oid);
                if (!t || parse_tag(t))
                        return 0;
                *tag = t;
@@ -266,7 +267,7 @@ static unsigned long finish_depth_computation(
 static void append_name(struct commit_name *n, struct strbuf *dst)
 {
        if (n->prio == 2 && !n->tag) {
-               n->tag = lookup_tag(&n->oid);
+               n->tag = lookup_tag(the_repository, &n->oid);
                if (!n->tag || parse_tag(n->tag))
                        die(_("annotated tag %s not available"), n->path);
        }
@@ -302,7 +303,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
        unsigned long seen_commits = 0;
        unsigned int unannotated_cnt = 0;
 
-       cmit = lookup_commit_reference(oid);
+       cmit = lookup_commit_reference(the_repository, oid);
 
        n = find_commit_name(&cmit->object.oid);
        if (n && (tags || all || n->prio == 2)) {
@@ -330,7 +331,8 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
                init_commit_names(&commit_names);
                n = hashmap_iter_first(&names, &iter);
                for (; n; n = hashmap_iter_next(&iter)) {
-                       c = lookup_commit_reference_gently(&n->peeled, 1);
+                       c = lookup_commit_reference_gently(the_repository,
+                                                          &n->peeled, 1);
                        if (c)
                                *commit_names_at(&commit_names, c) = n;
                }
@@ -508,7 +510,7 @@ static void describe(const char *arg, int last_one)
 
        if (get_oid(arg, &oid))
                die(_("Not a valid object name %s"), arg);
-       cmit = lookup_commit_reference_gently(&oid, 1);
+       cmit = lookup_commit_reference_gently(the_repository, &oid, 1);
 
        if (cmit)
                describe_commit(&oid, &sb);
index 473615117e0adbb301e6ddc0ab000accc513a9ee..d07bf2e4c4b5c2ec2f93930c0dd16897df32b25f 100644 (file)
@@ -5,12 +5,13 @@
 #include "log-tree.h"
 #include "builtin.h"
 #include "submodule.h"
+#include "repository.h"
 
 static struct rev_info log_tree_opt;
 
 static int diff_tree_commit_oid(const struct object_id *oid)
 {
-       struct commit *commit = lookup_commit_reference(oid);
+       struct commit *commit = lookup_commit_reference(the_repository, oid);
        if (!commit)
                return -1;
        return log_tree_commit(&log_tree_opt, commit);
@@ -24,7 +25,7 @@ static int stdin_diff_commit(struct commit *commit, const char *p)
 
        /* Graft the fake parents locally to the commit */
        while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) {
-               struct commit *parent = lookup_commit(&oid);
+               struct commit *parent = lookup_commit(the_repository, &oid);
                if (!pptr) {
                        /* Free the real parent list */
                        free_commit_list(commit->parents);
@@ -45,7 +46,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
        struct tree *tree2;
        if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
                return error("Need exactly two trees, separated by a space");
-       tree2 = lookup_tree(&oid);
+       tree2 = lookup_tree(the_repository, &oid);
        if (!tree2 || parse_tree(tree2))
                return -1;
        printf("%s %s\n", oid_to_hex(&tree1->object.oid),
@@ -68,7 +69,7 @@ static int diff_tree_stdin(char *line)
        line[len-1] = 0;
        if (parse_oid_hex(line, &oid, &p))
                return -1;
-       obj = parse_object(&oid);
+       obj = parse_object(the_repository, &oid);
        if (!obj)
                return -1;
        if (obj->type == OBJ_COMMIT)
@@ -162,9 +163,11 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
                int saved_nrl = 0;
                int saved_dcctc = 0;
 
-               if (opt->diffopt.detect_rename)
-                       opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
-                                              DIFF_SETUP_USE_CACHE);
+               if (opt->diffopt.detect_rename) {
+                       if (!the_index.cache)
+                               read_index(&the_index);
+                       opt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;
+               }
                while (fgets(line, sizeof(line), stdin)) {
                        struct object_id oid;
 
index b709b6e9842c68597b5bb7149db4054ef980fc53..361a3c3ed38769f798b83933755fed84724ce43c 100644 (file)
@@ -386,7 +386,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
                                add_head_to_pending(&rev);
                                if (!rev.pending.nr) {
                                        struct tree *tree;
-                                       tree = lookup_tree(the_hash_algo->empty_tree);
+                                       tree = lookup_tree(the_repository,
+                                                          the_repository->hash_algo->empty_tree);
                                        add_pending_object(&rev, &tree->object, "HEAD");
                                }
                                break;
@@ -400,8 +401,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
                const char *name = entry->name;
                int flags = (obj->flags & UNINTERESTING);
                if (!obj->parsed)
-                       obj = parse_object(&obj->oid);
-               obj = deref_tag(obj, NULL, 0);
+                       obj = parse_object(the_repository, &obj->oid);
+               obj = deref_tag(the_repository, obj, NULL, 0);
                if (!obj)
                        die(_("invalid object '%s' given."), name);
                if (obj->type == OBJ_COMMIT)
index bc97d4aef2db2d76e3ffddfc4759e52688f3974e..cdd585ca76d51f6d5dcca78a9e1dfa6f8102c476 100644 (file)
@@ -20,6 +20,7 @@
 #include "argv-array.h"
 #include "strbuf.h"
 #include "lockfile.h"
+#include "object-store.h"
 #include "dir.h"
 
 static char *diff_gui_tool;
@@ -321,10 +322,10 @@ static int checkout_path(unsigned mode, struct object_id *oid,
        struct cache_entry *ce;
        int ret;
 
-       ce = make_cache_entry(mode, oid->hash, path, 0, 0);
+       ce = make_transient_cache_entry(mode, oid, path, 0);
        ret = checkout_entry(ce, state, NULL);
 
-       free(ce);
+       discard_cache_entry(ce);
        return ret;
 }
 
@@ -488,7 +489,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
                                 * index.
                                 */
                                struct cache_entry *ce2 =
-                                       make_cache_entry(rmode, roid.hash,
+                                       make_cache_entry(&wtindex, rmode, &roid,
                                                         dst_path, 0, 0);
 
                                add_index_entry(&wtindex, ce2,
@@ -702,7 +703,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
                        1, PARSE_OPT_NONEG | PARSE_OPT_HIDDEN),
                OPT_BOOL(0, "symlinks", &symlinks,
                         N_("use symlinks in dir-diff mode")),
-               OPT_STRING('t', "tool", &difftool_cmd, N_("<tool>"),
+               OPT_STRING('t', "tool", &difftool_cmd, N_("tool"),
                           N_("use the specified diff tool")),
                OPT_BOOL(0, "tool-help", &tool_help,
                         N_("print a list of diff tools that may be used with "
@@ -710,7 +711,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
                OPT_BOOL(0, "trust-exit-code", &trust_exit_code,
                         N_("make 'git-difftool' exit when an invoked diff "
                            "tool returns a non - zero exit code")),
-               OPT_STRING('x', "extcmd", &extcmd, N_("<command>"),
+               OPT_STRING('x', "extcmd", &extcmd, N_("command"),
                           N_("specify a custom command for viewing diffs")),
                OPT_END()
        };
index 73d12c1020c4c13ff00210ad4eafc028bd33b322..9bd8a14b57b8e1b014503dffbcffa27e7242d67a 100644 (file)
@@ -8,6 +8,7 @@
 #include "config.h"
 #include "refs.h"
 #include "refspec.h"
+#include "object-store.h"
 #include "commit.h"
 #include "object.h"
 #include "tag.h"
@@ -229,21 +230,22 @@ static void export_blob(const struct object_id *oid)
        if (is_null_oid(oid))
                return;
 
-       object = lookup_object(oid->hash);
+       object = lookup_object(the_repository, oid->hash);
        if (object && object->flags & SHOWN)
                return;
 
        if (anonymize) {
                buf = anonymize_blob(&size);
-               object = (struct object *)lookup_blob(oid);
+               object = (struct object *)lookup_blob(the_repository, oid);
                eaten = 0;
        } else {
                buf = read_object_file(oid, &type, &size);
                if (!buf)
-                       die ("Could not read blob %s", oid_to_hex(oid));
+                       die("could not read blob %s", oid_to_hex(oid));
                if (check_object_signature(oid, buf, size, type_name(type)) < 0)
                        die("sha1 mismatch in blob %s", oid_to_hex(oid));
-               object = parse_object_buffer(oid, type, size, buf, &eaten);
+               object = parse_object_buffer(the_repository, oid, type,
+                                            size, buf, &eaten);
        }
 
        if (!object)
@@ -253,7 +255,7 @@ static void export_blob(const struct object_id *oid)
 
        printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size);
        if (size && fwrite(buf, size, 1, stdout) != 1)
-               die_errno ("Could not write blob '%s'", oid_to_hex(oid));
+               die_errno("could not write blob '%s'", oid_to_hex(oid));
        printf("\n");
 
        show_progress();
@@ -401,7 +403,8 @@ static void show_filemodify(struct diff_queue_struct *q,
                                                   anonymize_sha1(&spec->oid) :
                                                   spec->oid.hash));
                        else {
-                               struct object *object = lookup_object(spec->oid.hash);
+                               struct object *object = lookup_object(the_repository,
+                                                                     spec->oid.hash);
                                printf("M %06o :%d ", spec->mode,
                                       get_object_mark(object));
                        }
@@ -560,14 +563,14 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
        commit_buffer = get_commit_buffer(commit, NULL);
        author = strstr(commit_buffer, "\nauthor ");
        if (!author)
-               die ("Could not find author in commit %s",
-                    oid_to_hex(&commit->object.oid));
+               die("could not find author in commit %s",
+                   oid_to_hex(&commit->object.oid));
        author++;
        author_end = strchrnul(author, '\n');
        committer = strstr(author_end, "\ncommitter ");
        if (!committer)
-               die ("Could not find committer in commit %s",
-                    oid_to_hex(&commit->object.oid));
+               die("could not find committer in commit %s",
+                   oid_to_hex(&commit->object.oid));
        committer++;
        committer_end = strchrnul(committer, '\n');
        message = strstr(committer_end, "\n\n");
@@ -688,7 +691,7 @@ static void handle_tag(const char *name, struct tag *tag)
 
        buf = read_object_file(&tag->object.oid, &type, &size);
        if (!buf)
-               die ("Could not read tag %s", oid_to_hex(&tag->object.oid));
+               die("could not read tag %s", oid_to_hex(&tag->object.oid));
        message = memmem(buf, size, "\n\n", 2);
        if (message) {
                message += 2;
@@ -725,18 +728,18 @@ static void handle_tag(const char *name, struct tag *tag)
                if (signature)
                        switch(signed_tag_mode) {
                        case ABORT:
-                               die ("Encountered signed tag %s; use "
-                                    "--signed-tags=<mode> to handle it.",
-                                    oid_to_hex(&tag->object.oid));
+                               die("encountered signed tag %s; use "
+                                   "--signed-tags=<mode> to handle it",
+                                   oid_to_hex(&tag->object.oid));
                        case WARN:
-                               warning ("Exporting signed tag %s",
-                                        oid_to_hex(&tag->object.oid));
+                               warning("exporting signed tag %s",
+                                       oid_to_hex(&tag->object.oid));
                                /* fallthru */
                        case VERBATIM:
                                break;
                        case WARN_STRIP:
-                               warning ("Stripping signature from tag %s",
-                                        oid_to_hex(&tag->object.oid));
+                               warning("stripping signature from tag %s",
+                                       oid_to_hex(&tag->object.oid));
                                /* fallthru */
                        case STRIP:
                                message_size = signature + 1 - message;
@@ -750,18 +753,18 @@ static void handle_tag(const char *name, struct tag *tag)
        if (!tagged_mark) {
                switch(tag_of_filtered_mode) {
                case ABORT:
-                       die ("Tag %s tags unexported object; use "
-                            "--tag-of-filtered-object=<mode> to handle it.",
-                            oid_to_hex(&tag->object.oid));
+                       die("tag %s tags unexported object; use "
+                           "--tag-of-filtered-object=<mode> to handle it",
+                           oid_to_hex(&tag->object.oid));
                case DROP:
                        /* Ignore this tag altogether */
                        free(buf);
                        return;
                case REWRITE:
                        if (tagged->type != OBJ_COMMIT) {
-                               die ("Tag %s tags unexported %s!",
-                                    oid_to_hex(&tag->object.oid),
-                                    type_name(tagged->type));
+                               die("tag %s tags unexported %s!",
+                                   oid_to_hex(&tag->object.oid),
+                                   type_name(tagged->type));
                        }
                        p = (struct commit *)tagged;
                        for (;;) {
@@ -772,7 +775,7 @@ static void handle_tag(const char *name, struct tag *tag)
                                if (!(p->object.flags & TREESAME))
                                        break;
                                if (!p->parents)
-                                       die ("Can't find replacement commit for tag %s\n",
+                                       die("can't find replacement commit for tag %s",
                                             oid_to_hex(&tag->object.oid));
                                p = p->parents->item;
                        }
@@ -800,7 +803,7 @@ static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name)
 
                /* handle nested tags */
                while (tag && tag->object.type == OBJ_TAG) {
-                       parse_object(&tag->object.oid);
+                       parse_object(the_repository, &tag->object.oid);
                        string_list_append(&extra_refs, full_name)->util = tag;
                        tag = (struct tag *)tag->tagged;
                }
@@ -960,7 +963,7 @@ static void import_marks(char *input_file)
                        /* only commits */
                        continue;
 
-               commit = lookup_commit(&oid);
+               commit = lookup_commit(the_repository, &oid);
                if (!commit)
                        die("not a commit? can't happen: %s", oid_to_hex(&oid));
 
index ea5b9669ad1f40da56a8565cada56e5991d24206..61bec5d213d47141d14162bd1a2ca88861c22ef7 100644 (file)
@@ -6,6 +6,7 @@
 #include "repository.h"
 #include "refs.h"
 #include "refspec.h"
+#include "object-store.h"
 #include "commit.h"
 #include "builtin.h"
 #include "string-list.h"
@@ -63,6 +64,7 @@ static int shown_url = 0;
 static struct refspec refmap = REFSPEC_INIT_FETCH;
 static struct list_objects_filter_options filter_options;
 static struct string_list server_options = STRING_LIST_INIT_DUP;
+static struct string_list negotiation_tip = STRING_LIST_INIT_NODUP;
 
 static int git_fetch_config(const char *k, const char *v, void *cb)
 {
@@ -93,19 +95,6 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
        return git_default_config(k, v, cb);
 }
 
-static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
-{
-       if (!strcmp(var, "submodule.fetchjobs")) {
-               max_children = parse_submodule_fetchjobs(var, value);
-               return 0;
-       } else if (!strcmp(var, "fetch.recursesubmodules")) {
-               recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
-               return 0;
-       }
-
-       return 0;
-}
-
 static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
 {
        /*
@@ -174,6 +163,8 @@ static struct option builtin_fetch_options[] = {
                        TRANSPORT_FAMILY_IPV4),
        OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
                        TRANSPORT_FAMILY_IPV6),
+       OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
+                       N_("report that we have only objects reachable from this object")),
        OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
        OPT_END()
 };
@@ -254,9 +245,9 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
        return 0;
 }
 
-static void find_non_local_tags(struct transport *transport,
-                       struct ref **head,
-                       struct ref ***tail)
+static void find_non_local_tags(const struct ref *refs,
+                               struct ref **head,
+                               struct ref ***tail)
 {
        struct string_list existing_refs = STRING_LIST_INIT_DUP;
        struct string_list remote_refs = STRING_LIST_INIT_NODUP;
@@ -264,7 +255,7 @@ static void find_non_local_tags(struct transport *transport,
        struct string_list_item *item = NULL;
 
        for_each_ref(add_existing, &existing_refs);
-       for (ref = transport_get_remote_refs(transport, NULL); ref; ref = ref->next) {
+       for (ref = refs; ref; ref = ref->next) {
                if (!starts_with(ref->name, "refs/tags/"))
                        continue;
 
@@ -338,7 +329,8 @@ static void find_non_local_tags(struct transport *transport,
        string_list_clear(&remote_refs, 0);
 }
 
-static struct ref *get_ref_map(struct transport *transport,
+static struct ref *get_ref_map(struct remote *remote,
+                              const struct ref *remote_refs,
                               struct refspec *rs,
                               int tags, int *autotags)
 {
@@ -346,26 +338,11 @@ static struct ref *get_ref_map(struct transport *transport,
        struct ref *rm;
        struct ref *ref_map = NULL;
        struct ref **tail = &ref_map;
-       struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
 
        /* opportunistically-updated references: */
        struct ref *orefs = NULL, **oref_tail = &orefs;
 
-       const struct ref *remote_refs;
-
-       if (rs->nr)
-               refspec_ref_prefixes(rs, &ref_prefixes);
-       else if (transport->remote && transport->remote->fetch.nr)
-               refspec_ref_prefixes(&transport->remote->fetch, &ref_prefixes);
-
-       if (ref_prefixes.argc &&
-           (tags == TAGS_SET || (tags == TAGS_DEFAULT && !rs->nr))) {
-               argv_array_push(&ref_prefixes, "refs/tags/");
-       }
-
-       remote_refs = transport_get_remote_refs(transport, &ref_prefixes);
-
-       argv_array_clear(&ref_prefixes);
+       struct string_list existing_refs = STRING_LIST_INIT_DUP;
 
        if (rs->nr) {
                struct refspec *fetch_refspec;
@@ -402,7 +379,7 @@ static struct ref *get_ref_map(struct transport *transport,
                if (refmap.nr)
                        fetch_refspec = &refmap;
                else
-                       fetch_refspec = &transport->remote->fetch;
+                       fetch_refspec = &remote->fetch;
 
                for (i = 0; i < fetch_refspec->nr; i++)
                        get_fetch_map(ref_map, &fetch_refspec->items[i], &oref_tail, 1);
@@ -410,7 +387,6 @@ static struct ref *get_ref_map(struct transport *transport,
                die("--refmap option is only meaningful with command-line refspec(s).");
        } else {
                /* Use the defaults */
-               struct remote *remote = transport->remote;
                struct branch *branch = branch_get(NULL);
                int has_merge = branch_has_merge_config(branch);
                if (remote &&
@@ -449,7 +425,7 @@ static struct ref *get_ref_map(struct transport *transport,
                /* also fetch all tags */
                get_fetch_map(remote_refs, tag_refspec, &tail, 0);
        else if (tags == TAGS_DEFAULT && *autotags)
-               find_non_local_tags(transport, &ref_map, &tail);
+               find_non_local_tags(remote_refs, &ref_map, &tail);
 
        /* Now append any refs to be updated opportunistically: */
        *tail = orefs;
@@ -458,7 +434,23 @@ static struct ref *get_ref_map(struct transport *transport,
                tail = &rm->next;
        }
 
-       return ref_remove_duplicates(ref_map);
+       ref_map = ref_remove_duplicates(ref_map);
+
+       for_each_ref(add_existing, &existing_refs);
+       for (rm = ref_map; rm; rm = rm->next) {
+               if (rm->peer_ref) {
+                       struct string_list_item *peer_item =
+                               string_list_lookup(&existing_refs,
+                                                  rm->peer_ref->name);
+                       if (peer_item) {
+                               struct object_id *old_oid = peer_item->util;
+                               oidcpy(&rm->peer_ref->old_oid, old_oid);
+                       }
+               }
+       }
+       string_list_clear(&existing_refs, 1);
+
+       return ref_map;
 }
 
 #define STORE_REF_ERROR_OTHER 1
@@ -683,8 +675,10 @@ static int update_local_ref(struct ref *ref,
                return r;
        }
 
-       current = lookup_commit_reference_gently(&ref->old_oid, 1);
-       updated = lookup_commit_reference_gently(&ref->new_oid, 1);
+       current = lookup_commit_reference_gently(the_repository,
+                                                &ref->old_oid, 1);
+       updated = lookup_commit_reference_gently(the_repository,
+                                                &ref->new_oid, 1);
        if (!current || !updated) {
                const char *msg;
                const char *what;
@@ -768,7 +762,7 @@ static int iterate_ref_map(void *cb_data, struct object_id *oid)
 }
 
 static int store_updated_refs(const char *raw_url, const char *remote_name,
-               struct ref *ref_map)
+                             int connectivity_checked, struct ref *ref_map)
 {
        FILE *fp;
        struct commit *commit;
@@ -777,7 +771,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
        const char *what, *kind;
        struct ref *rm;
        char *url;
-       const char *filename = dry_run ? "/dev/null" : git_path_fetch_head();
+       const char *filename = dry_run ? "/dev/null" : git_path_fetch_head(the_repository);
        int want_status;
        int summary_width = transport_summary_width(ref_map);
 
@@ -790,10 +784,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
        else
                url = xstrdup("foreign");
 
-       rm = ref_map;
-       if (check_connected(iterate_ref_map, &rm, NULL)) {
-               rc = error(_("%s did not send all necessary objects\n"), url);
-               goto abort;
+       if (!connectivity_checked) {
+               rm = ref_map;
+               if (check_connected(iterate_ref_map, &rm, NULL)) {
+                       rc = error(_("%s did not send all necessary objects\n"), url);
+                       goto abort;
+               }
        }
 
        prepare_format_display(ref_map);
@@ -817,7 +813,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
                                continue;
                        }
 
-                       commit = lookup_commit_reference_gently(&rm->old_oid,
+                       commit = lookup_commit_reference_gently(the_repository,
+                                                               &rm->old_oid,
                                                                1);
                        if (!commit)
                                rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE;
@@ -951,9 +948,24 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
        if (ret)
                ret = transport_fetch_refs(transport, ref_map);
        if (!ret)
-               ret |= store_updated_refs(transport->url,
-                               transport->remote->name,
-                               ref_map);
+               /*
+                * Keep the new pack's ".keep" file around to allow the caller
+                * time to update refs to reference the new objects.
+                */
+               return 0;
+       transport_unlock_pack(transport);
+       return ret;
+}
+
+/* Update local refs based on the ref values fetched from a remote */
+static int consume_refs(struct transport *transport, struct ref *ref_map)
+{
+       int connectivity_checked = transport->smart_options
+               ? transport->smart_options->connectivity_checked : 0;
+       int ret = store_updated_refs(transport->url,
+                                    transport->remote->name,
+                                    connectivity_checked,
+                                    ref_map);
        transport_unlock_pack(transport);
        return ret;
 }
@@ -1029,7 +1041,7 @@ static void check_not_current_branch(struct ref *ref_map)
 
 static int truncate_fetch_head(void)
 {
-       const char *filename = git_path_fetch_head();
+       const char *filename = git_path_fetch_head(the_repository);
        FILE *fp = fopen_for_writing(filename);
 
        if (!fp)
@@ -1049,6 +1061,40 @@ static void set_option(struct transport *transport, const char *name, const char
                        name, transport->url);
 }
 
+
+static int add_oid(const char *refname, const struct object_id *oid, int flags,
+                  void *cb_data)
+{
+       struct oid_array *oids = cb_data;
+
+       oid_array_append(oids, oid);
+       return 0;
+}
+
+static void add_negotiation_tips(struct git_transport_options *smart_options)
+{
+       struct oid_array *oids = xcalloc(1, sizeof(*oids));
+       int i;
+
+       for (i = 0; i < negotiation_tip.nr; i++) {
+               const char *s = negotiation_tip.items[i].string;
+               int old_nr;
+               if (!has_glob_specials(s)) {
+                       struct object_id oid;
+                       if (get_oid(s, &oid))
+                               die("%s is not a valid object", s);
+                       oid_array_append(oids, &oid);
+                       continue;
+               }
+               old_nr = oids->nr;
+               for_each_glob_ref(add_oid, s, oids);
+               if (old_nr == oids->nr)
+                       warning("Ignoring --negotiation-tip=%s because it does not match any refs",
+                               s);
+       }
+       smart_options->negotiation_tips = oids;
+}
+
 static struct transport *prepare_transport(struct remote *remote, int deepen)
 {
        struct transport *transport;
@@ -1075,6 +1121,12 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
                           filter_options.filter_spec);
                set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
        }
+       if (negotiation_tip.nr) {
+               if (transport->smart_options)
+                       add_negotiation_tips(transport->smart_options);
+               else
+                       warning("Ignoring --negotiation-tip because the protocol does not support it.");
+       }
        return transport;
 }
 
@@ -1099,7 +1151,8 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map)
        transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
        transport_set_option(transport, TRANS_OPT_DEPTH, "0");
        transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
-       fetch_refs(transport, ref_map);
+       if (!fetch_refs(transport, ref_map))
+               consume_refs(transport, ref_map);
 
        if (gsecondary) {
                transport_disconnect(gsecondary);
@@ -1110,13 +1163,11 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map)
 static int do_fetch(struct transport *transport,
                    struct refspec *rs)
 {
-       struct string_list existing_refs = STRING_LIST_INIT_DUP;
        struct ref *ref_map;
-       struct ref *rm;
        int autotags = (transport->remote->fetch_tags == 1);
        int retcode = 0;
-
-       for_each_ref(add_existing, &existing_refs);
+       const struct ref *remote_refs;
+       struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
 
        if (tags == TAGS_DEFAULT) {
                if (transport->remote->fetch_tags == 2)
@@ -1132,22 +1183,24 @@ static int do_fetch(struct transport *transport,
                        goto cleanup;
        }
 
-       ref_map = get_ref_map(transport, rs, tags, &autotags);
-       if (!update_head_ok)
-               check_not_current_branch(ref_map);
+       if (rs->nr)
+               refspec_ref_prefixes(rs, &ref_prefixes);
+       else if (transport->remote && transport->remote->fetch.nr)
+               refspec_ref_prefixes(&transport->remote->fetch, &ref_prefixes);
 
-       for (rm = ref_map; rm; rm = rm->next) {
-               if (rm->peer_ref) {
-                       struct string_list_item *peer_item =
-                               string_list_lookup(&existing_refs,
-                                                  rm->peer_ref->name);
-                       if (peer_item) {
-                               struct object_id *old_oid = peer_item->util;
-                               oidcpy(&rm->peer_ref->old_oid, old_oid);
-                       }
-               }
+       if (ref_prefixes.argc &&
+           (tags == TAGS_SET || (tags == TAGS_DEFAULT))) {
+               argv_array_push(&ref_prefixes, "refs/tags/");
        }
 
+       remote_refs = transport_get_remote_refs(transport, &ref_prefixes);
+       argv_array_clear(&ref_prefixes);
+
+       ref_map = get_ref_map(transport->remote, remote_refs, rs,
+                             tags, &autotags);
+       if (!update_head_ok)
+               check_not_current_branch(ref_map);
+
        if (tags == TAGS_DEFAULT && autotags)
                transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
        if (prune) {
@@ -1164,7 +1217,7 @@ static int do_fetch(struct transport *transport,
                                   transport->url);
                }
        }
-       if (fetch_refs(transport, ref_map)) {
+       if (fetch_refs(transport, ref_map) || consume_refs(transport, ref_map)) {
                free_refs(ref_map);
                retcode = 1;
                goto cleanup;
@@ -1176,14 +1229,13 @@ static int do_fetch(struct transport *transport,
        if (tags == TAGS_DEFAULT && autotags) {
                struct ref **tail = &ref_map;
                ref_map = NULL;
-               find_non_local_tags(transport, &ref_map, &tail);
+               find_non_local_tags(remote_refs, &ref_map, &tail);
                if (ref_map)
                        backfill_tags(transport, ref_map);
                free_refs(ref_map);
        }
 
  cleanup:
-       string_list_clear(&existing_refs, 1);
        return retcode;
 }
 
@@ -1433,7 +1485,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
        for (i = 1; i < argc; i++)
                strbuf_addf(&default_rla, " %s", argv[i]);
 
-       config_from_gitmodules(gitmodules_fetch_config, NULL);
+       fetch_config_from_gitmodules(&max_children, &recurse_submodules);
        git_config(git_fetch_config, NULL);
 
        argc = parse_options(argc, argv, prefix,
@@ -1449,7 +1501,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
        if (unshallow) {
                if (depth)
                        die(_("--depth and --unshallow cannot be used together"));
-               else if (!is_repository_shallow())
+               else if (!is_repository_shallow(the_repository))
                        die(_("--unshallow on a complete repository does not make sense"));
                else
                        depth = xstrfmt("%d", INFINITE_DEPTH);
index bd680be6874da29cf776c84468a60888beea53fb..f35ff1612bb563c819b611e82f8e3a7730d32461 100644 (file)
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "refs.h"
+#include "object-store.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
@@ -10,6 +11,7 @@
 #include "branch.h"
 #include "fmt-merge-msg.h"
 #include "gpg-interface.h"
+#include "repository.h"
 
 static const char * const fmt_merge_msg_usage[] = {
        N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"),
@@ -108,14 +110,15 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
        struct string_list_item *item;
        int pulling_head = 0;
        struct object_id oid;
+       const unsigned hexsz = the_hash_algo->hexsz;
 
-       if (len < GIT_SHA1_HEXSZ + 3 || line[GIT_SHA1_HEXSZ] != '\t')
+       if (len < hexsz + 3 || line[hexsz] != '\t')
                return 1;
 
-       if (starts_with(line + GIT_SHA1_HEXSZ + 1, "not-for-merge"))
+       if (starts_with(line + hexsz + 1, "not-for-merge"))
                return 0;
 
-       if (line[GIT_SHA1_HEXSZ + 1] != '\t')
+       if (line[hexsz + 1] != '\t')
                return 2;
 
        i = get_oid_hex(line, &oid);
@@ -130,7 +133,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
 
        if (line[len - 1] == '\n')
                line[len - 1] = 0;
-       line += GIT_SHA1_HEXSZ + 2;
+       line += hexsz + 2;
 
        /*
         * At this point, line points at the beginning of comment e.g.
@@ -342,7 +345,9 @@ static void shortlog(const char *name,
        const struct object_id *oid = &origin_data->oid;
        int limit = opts->shortlog_len;
 
-       branch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ);
+       branch = deref_tag(the_repository, parse_object(the_repository, oid),
+                          oid_to_hex(oid),
+                          the_hash_algo->hexsz);
        if (!branch || branch->type != OBJ_COMMIT)
                return;
 
@@ -545,6 +550,7 @@ static void find_merge_parents(struct merge_parents *result,
                int len;
                char *p = in->buf + pos;
                char *newline = strchr(p, '\n');
+               const char *q;
                struct object_id oid;
                struct commit *parent;
                struct object *obj;
@@ -552,24 +558,23 @@ static void find_merge_parents(struct merge_parents *result,
                len = newline ? newline - p : strlen(p);
                pos += len + !!newline;
 
-               if (len < GIT_SHA1_HEXSZ + 3 ||
-                   get_oid_hex(p, &oid) ||
-                   p[GIT_SHA1_HEXSZ] != '\t' ||
-                   p[GIT_SHA1_HEXSZ + 1] != '\t')
+               if (parse_oid_hex(p, &oid, &q) ||
+                   q[0] != '\t' ||
+                   q[1] != '\t')
                        continue; /* skip not-for-merge */
                /*
                 * Do not use get_merge_parent() here; we do not have
                 * "name" here and we do not want to contaminate its
                 * util field yet.
                 */
-               obj = parse_object(&oid);
+               obj = parse_object(the_repository, &oid);
                parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT);
                if (!parent)
                        continue;
                commit_list_insert(parent, &parents);
                add_merge_parent(result, &obj->oid, &parent->object.oid);
        }
-       head_commit = lookup_commit(head);
+       head_commit = lookup_commit(the_repository, head);
        if (head_commit)
                commit_list_insert(head_commit, &parents);
        reduce_heads_replace(&parents);
@@ -623,7 +628,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
                i++;
                p[len] = 0;
                if (handle_line(p, &merge_parents))
-                       die ("Error in line %d: %.*s", i, len, p);
+                       die("error in line %d: %.*s", i, len, p);
        }
 
        if (opts->add_title && srcs.nr)
index 3ad4f160f9959a30262c81d5c3f85c36649d2895..250f5af1182ddc66ac0a729c1d39e94d8b19a878 100644 (file)
@@ -18,6 +18,7 @@
 #include "decorate.h"
 #include "packfile.h"
 #include "object-store.h"
+#include "run-command.h"
 
 #define REACHABLE 0x0001
 #define SEEN      0x0002
@@ -47,6 +48,7 @@ static int name_objects;
 #define ERROR_REACHABLE 02
 #define ERROR_PACK 04
 #define ERROR_REFS 010
+#define ERROR_COMMIT_GRAPH 020
 
 static const char *describe_object(struct object *obj)
 {
@@ -70,7 +72,7 @@ static const char *printable_type(struct object *obj)
                enum object_type type = oid_object_info(the_repository,
                                                        &obj->oid, NULL);
                if (type > 0)
-                       object_as_type(obj, type, 0);
+                       object_as_type(the_repository, obj, type, 0);
        }
 
        ret = type_name(obj->type);
@@ -392,7 +394,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
         * verify_packfile(), data_valid variable for details.
         */
        struct object *obj;
-       obj = parse_object_buffer(oid, type, size, buffer, eaten);
+       obj = parse_object_buffer(the_repository, oid, type, size, buffer,
+                                 eaten);
        if (!obj) {
                errors_found |= ERROR_OBJECT;
                return error("%s: object corrupt or missing", oid_to_hex(oid));
@@ -410,7 +413,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
        struct object *obj;
 
        if (!is_null_oid(oid)) {
-               obj = lookup_object(oid->hash);
+               obj = lookup_object(the_repository, oid->hash);
                if (obj && (obj->flags & HAS_OBJ)) {
                        if (timestamp && name_objects)
                                add_decoration(fsck_walk_options.object_names,
@@ -452,7 +455,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
 {
        struct object *obj;
 
-       obj = parse_object(oid);
+       obj = parse_object(the_repository, oid);
        if (!obj) {
                if (is_promisor_object(oid)) {
                        /*
@@ -525,7 +528,9 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
        if (!contents && type != OBJ_BLOB)
                BUG("read_loose_object streamed a non-blob");
 
-       obj = parse_object_buffer(oid, type, size, contents, &eaten);
+       obj = parse_object_buffer(the_repository, oid, type, size,
+                                 contents, &eaten);
+
        if (!obj) {
                errors_found |= ERROR_OBJECT;
                error("%s: object could not be parsed: %s",
@@ -614,7 +619,7 @@ static int fsck_cache_tree(struct cache_tree *it)
                fprintf(stderr, "Checking cache tree\n");
 
        if (0 <= it->entry_count) {
-               struct object *obj = parse_object(&it->oid);
+               struct object *obj = parse_object(the_repository, &it->oid);
                if (!obj) {
                        error("%s: invalid sha1 pointer in cache-tree",
                              oid_to_hex(&it->oid));
@@ -689,7 +694,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
        fetch_if_missing = 0;
 
        errors_found = 0;
-       check_replace_refs = 0;
+       read_replace_refs = 0;
 
        argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
 
@@ -763,7 +768,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                const char *arg = argv[i];
                struct object_id oid;
                if (!get_oid(arg, &oid)) {
-                       struct object *obj = lookup_object(oid.hash);
+                       struct object *obj = lookup_object(the_repository,
+                                                          oid.hash);
 
                        if (!obj || !(obj->flags & HAS_OBJ)) {
                                if (is_promisor_object(&oid))
@@ -806,7 +812,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                        mode = active_cache[i]->ce_mode;
                        if (S_ISGITLINK(mode))
                                continue;
-                       blob = lookup_blob(&active_cache[i]->oid);
+                       blob = lookup_blob(the_repository,
+                                          &active_cache[i]->oid);
                        if (!blob)
                                continue;
                        obj = &blob->object;
@@ -822,5 +829,24 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
        }
 
        check_connectivity();
+
+       if (!git_config_get_bool("core.commitgraph", &i) && i) {
+               struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
+               const char *verify_argv[] = { "commit-graph", "verify", NULL, NULL, NULL };
+
+               commit_graph_verify.argv = verify_argv;
+               commit_graph_verify.git_cmd = 1;
+               if (run_command(&commit_graph_verify))
+                       errors_found |= ERROR_COMMIT_GRAPH;
+
+               prepare_alt_odb(the_repository);
+               for (alt =  the_repository->objects->alt_odb_list; alt; alt = alt->next) {
+                       verify_argv[2] = "--object-dir";
+                       verify_argv[3] = alt->path;
+                       if (run_command(&commit_graph_verify))
+                               errors_found |= ERROR_COMMIT_GRAPH;
+               }
+       }
+
        return errors_found;
 }
index ccfb1ceaeb3eb9c6a8cbe9297bceac94fa54bcac..57069442b0dc1297366e29b1fbf0e6ee70377146 100644 (file)
@@ -20,6 +20,7 @@
 #include "sigchain.h"
 #include "argv-array.h"
 #include "commit.h"
+#include "commit-graph.h"
 #include "packfile.h"
 #include "object-store.h"
 #include "pack.h"
@@ -40,6 +41,7 @@ static int aggressive_depth = 50;
 static int aggressive_window = 250;
 static int gc_auto_threshold = 6700;
 static int gc_auto_pack_limit = 50;
+static int gc_write_commit_graph;
 static int detach_auto = 1;
 static timestamp_t gc_log_expire_time;
 static const char *gc_log_expire = "1.day.ago";
@@ -129,6 +131,7 @@ static void gc_config(void)
        git_config_get_int("gc.aggressivedepth", &aggressive_depth);
        git_config_get_int("gc.auto", &gc_auto_threshold);
        git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
+       git_config_get_bool("gc.writecommitgraph", &gc_write_commit_graph);
        git_config_get_bool("gc.autodetach", &detach_auto);
        git_config_get_expiry("gc.pruneexpire", &prune_expire);
        git_config_get_expiry("gc.worktreepruneexpire", &prune_worktrees_expire);
@@ -612,6 +615,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
                return -1;
 
        if (!repository_format_precious_objects) {
+               close_all_packs(the_repository->objects);
                if (run_command_v_opt(repack.argv, RUN_GIT_CMD))
                        return error(FAILED_RUN, repack.argv[0]);
 
@@ -641,6 +645,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
        if (pack_garbage.nr > 0)
                clean_pack_garbage();
 
+       if (gc_write_commit_graph)
+               write_commit_graph_reachable(get_object_directory(), 0);
+
        if (auto_gc && too_many_loose_objects())
                warning(_("There are too many unreachable loose objects; "
                        "run 'git prune' to remove them."));
index ee753a403eba0e9bc25b40a1efd200cafdf31e19..601f801158f097b302dcf6615016bb4cefbc0225 100644 (file)
@@ -489,7 +489,7 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
        }
 
        if (repo_read_index(repo) < 0)
-               die("index file corrupt");
+               die(_("index file corrupt"));
 
        for (nr = 0; nr < repo->index->cache_nr; nr++) {
                const struct cache_entry *ce = repo->index->cache[nr];
@@ -497,7 +497,7 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
                strbuf_addstr(&name, ce->name);
 
                if (S_ISREG(ce->ce_mode) &&
-                   match_pathspec(pathspec, name.buf, name.len, 0, NULL,
+                   match_pathspec(repo->index, pathspec, name.buf, name.len, 0, NULL,
                                   S_ISDIR(ce->ce_mode) ||
                                   S_ISGITLINK(ce->ce_mode))) {
                        /*
@@ -515,7 +515,7 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
                                hit |= grep_file(opt, name.buf);
                        }
                } else if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
-                          submodule_path_match(pathspec, name.buf, NULL)) {
+                          submodule_path_match(repo->index, pathspec, name.buf, NULL)) {
                        hit |= grep_submodule(opt, repo, pathspec, NULL, ce->name, ce->name);
                } else {
                        continue;
@@ -647,7 +647,8 @@ 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(list->objects[i].item, NULL, 0);
+               real_obj = deref_tag(the_repository, list->objects[i].item,
+                                    NULL, 0);
 
                /* load the gitmodules file for this rev */
                if (recurse_submodules) {
@@ -678,7 +679,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
 
        fill_directory(&dir, &the_index, pathspec);
        for (i = 0; i < dir.nr; i++) {
-               if (!dir_path_match(dir.entries[i], pathspec, 0, NULL))
+               if (!dir_path_match(&the_index, dir.entries[i], pathspec, 0, NULL))
                        continue;
                hit |= grep_file(opt, dir.entries[i]->name);
                if (hit && opt->status_only)
@@ -828,6 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                            GREP_PATTERN_TYPE_PCRE),
                OPT_GROUP(""),
                OPT_BOOL('n', "line-number", &opt.linenum, N_("show line numbers")),
+               OPT_BOOL(0, "column", &opt.columnnum, N_("show column number of first match")),
                OPT_NEGBIT('h', NULL, &opt.pathname, N_("don't show filenames"), 1),
                OPT_BIT('H', NULL, &opt.pathname, N_("show filenames"), 1),
                OPT_NEGBIT(0, "full-name", &opt.relative,
@@ -842,6 +844,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                OPT_BOOL_F('z', "null", &opt.null_following_name,
                           N_("print NUL after filenames"),
                           PARSE_OPT_NOCOMPLETE),
+               OPT_BOOL('o', "only-matching", &opt.only_matching,
+                       N_("show only matching parts of a line")),
                OPT_BOOL('c', "count", &opt.count,
                        N_("show the number of matches instead of matching lines")),
                OPT__COLOR(&opt.color, N_("highlight matches")),
@@ -959,7 +963,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
        }
 
        if (!opt.pattern_list)
-               die(_("no pattern given."));
+               die(_("no pattern given"));
+
+       /* --only-matching has no effect with --invert. */
+       if (opt.invert)
+               opt.only_matching = 0;
 
        /*
         * We have to find "--" in a separate pass, because its presence
@@ -1085,19 +1093,19 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
        }
 
        if (recurse_submodules && (!use_index || untracked))
-               die(_("option not supported with --recurse-submodules."));
+               die(_("option not supported with --recurse-submodules"));
 
        if (!show_in_pager && !opt.status_only)
                setup_pager();
 
        if (!use_index && (untracked || cached))
-               die(_("--cached or --untracked cannot be used with --no-index."));
+               die(_("--cached or --untracked cannot be used with --no-index"));
 
        if (!use_index || untracked) {
                int use_exclude = (opt_exclude < 0) ? use_index : !!opt_exclude;
                hit = grep_directory(&opt, &pathspec, use_exclude, use_index);
        } else if (0 <= opt_exclude) {
-               die(_("--[no-]exclude-standard cannot be used for tracked contents."));
+               die(_("--[no-]exclude-standard cannot be used for tracked contents"));
        } else if (!list.nr) {
                if (!cached)
                        setup_work_tree();
@@ -1105,7 +1113,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                hit = grep_cache(&opt, the_repository, &pathspec, cached);
        } else {
                if (cached)
-                       die(_("both --cached and trees are given."));
+                       die(_("both --cached and trees are given"));
 
                hit = grep_objects(&opt, &pathspec, &list);
        }
index a9a3a198c3b47197cb847ba32a33177f1a45f428..9ada4f4dfd8747d3888203749f057915f7c9ab46 100644 (file)
@@ -6,6 +6,7 @@
  */
 #include "builtin.h"
 #include "config.h"
+#include "object-store.h"
 #include "blob.h"
 #include "quote.h"
 #include "parse-options.h"
index 74fe2973e1256e092652fce28ba2036cc3203af9..9582ead9507ee27f88386fcc55c044eba233c770 100644 (file)
@@ -832,7 +832,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
        if (strict || do_fsck_object) {
                read_lock();
                if (type == OBJ_BLOB) {
-                       struct blob *blob = lookup_blob(oid);
+                       struct blob *blob = lookup_blob(the_repository, oid);
                        if (blob)
                                blob->object.flags |= FLAG_CHECKED;
                        else
@@ -851,7 +851,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
                         * we do not need to free the memory here, as the
                         * buf is deleted by the caller.
                         */
-                       obj = parse_object_buffer(oid, type, size, buf,
+                       obj = parse_object_buffer(the_repository, oid, type,
+                                                 size, buf,
                                                  &eaten);
                        if (!obj)
                                die(_("invalid %s"), type_name(type));
@@ -1679,7 +1680,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage(index_pack_usage);
 
-       check_replace_refs = 0;
+       read_replace_refs = 0;
        fsck_options.walk = mark_link;
 
        reset_pack_idx_option(&opts);
index 4ecf90936822e64998651e4d51d1be9c921dee60..12ddda7e7bac51f74b2f7ca8a2b64ffe90fd8683 100644 (file)
@@ -73,7 +73,8 @@ static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
                        continue;
                else if (S_ISLNK(st_template.st_mode)) {
                        struct strbuf lnk = STRBUF_INIT;
-                       if (strbuf_readlink(&lnk, template_path->buf, 0) < 0)
+                       if (strbuf_readlink(&lnk, template_path->buf,
+                                           st_template.st_size) < 0)
                                die_errno(_("cannot readlink '%s'"), template_path->buf);
                        if (symlink(lnk.buf, path->buf))
                                die_errno(_("cannot symlink '%s' '%s'"),
index 0583f7f383a481f353909dc5b406b38745549c63..e094560d9abca6e819c24b845dc7c04d384850c3 100644 (file)
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "config.h"
 #include "refs.h"
+#include "object-store.h"
 #include "color.h"
 #include "commit.h"
 #include "diff.h"
@@ -29,6 +30,7 @@
 #include "gpg-interface.h"
 #include "progress.h"
 #include "commit-slab.h"
+#include "repository.h"
 
 #define MAIL_DEFAULT_WRAP 72
 
@@ -618,7 +620,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
                        rev.shown_one = 1;
                        if (ret)
                                break;
-                       o = parse_object(&t->tagged->oid);
+                       o = parse_object(the_repository, &t->tagged->oid);
                        if (!o)
                                ret = error(_("Could not read object %s"),
                                            oid_to_hex(&t->tagged->oid));
@@ -905,8 +907,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
        o2 = rev->pending.objects[1].item;
        flags1 = o1->flags;
        flags2 = o2->flags;
-       c1 = lookup_commit_reference(&o1->oid);
-       c2 = lookup_commit_reference(&o2->oid);
+       c1 = lookup_commit_reference(the_repository, &o1->oid);
+       c2 = lookup_commit_reference(the_repository, &o2->oid);
 
        if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
                die(_("Not a range."));
@@ -1606,14 +1608,14 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                numbered = 0;
 
        if (numbered && keep_subject)
-               die (_("-n and -k are mutually exclusive."));
+               die(_("-n and -k are mutually exclusive"));
        if (keep_subject && subject_prefix)
-               die (_("--subject-prefix/--rfc and -k are mutually exclusive."));
+               die(_("--subject-prefix/--rfc and -k are mutually exclusive"));
        rev.preserve_subject = keep_subject;
 
        argc = setup_revisions(argc, argv, &rev, &s_r_opt);
        if (argc > 1)
-               die (_("unrecognized argument: %s"), argv[1]);
+               die(_("unrecognized argument: %s"), argv[1]);
 
        if (rev.diffopt.output_format & DIFF_FORMAT_NAME)
                die(_("--name-only does not make sense"));
@@ -1755,6 +1757,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        if (base_commit || base_auto) {
                struct commit *base = get_base_commit(base_commit, list, nr);
                reset_revision_walk();
+               clear_object_flags(UNINTERESTING);
                prepare_bases(&bases, base, list, nr);
        }
 
@@ -1862,7 +1865,8 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
 {
        struct object_id oid;
        if (get_oid(arg, &oid) == 0) {
-               struct commit *commit = lookup_commit_reference(&oid);
+               struct commit *commit = lookup_commit_reference(the_repository,
+                                                               &oid);
                if (commit) {
                        commit->object.flags |= flags;
                        add_pending_object(revs, &commit->object, arg);
index 88bb2019ad7a52a13373d4c88b127915b219e4a5..7f9919a36234f603ffe76d7324fafc7f5872d404 100644 (file)
@@ -63,7 +63,7 @@ static void write_eolinfo(const struct index_state *istate,
                struct stat st;
                const char *i_txt = "";
                const char *w_txt = "";
-               const char *a_txt = get_convert_attr_ascii(path);
+               const char *a_txt = get_convert_attr_ascii(istate, path);
                if (ce && S_ISREG(ce->ce_mode))
                        i_txt = get_cached_convert_stats_ascii(istate,
                                                               ce->name);
@@ -121,18 +121,19 @@ static void print_debug(const struct cache_entry *ce)
        }
 }
 
-static void show_dir_entry(const char *tag, struct dir_entry *ent)
+static void show_dir_entry(const struct index_state *istate,
+                          const char *tag, struct dir_entry *ent)
 {
        int len = max_prefix_len;
 
        if (len > ent->len)
                die("git ls-files: internal error - directory entry not superset of prefix");
 
-       if (!dir_path_match(ent, &pathspec, len, ps_matched))
+       if (!dir_path_match(istate, ent, &pathspec, len, ps_matched))
                return;
 
        fputs(tag, stdout);
-       write_eolinfo(NULL, NULL, ent->name);
+       write_eolinfo(istate, NULL, ent->name);
        write_name(ent->name);
 }
 
@@ -145,7 +146,7 @@ static void show_other_files(const struct index_state *istate,
                struct dir_entry *ent = dir->entries[i];
                if (!index_name_is_other(istate, ent->name, ent->len))
                        continue;
-               show_dir_entry(tag_other, ent);
+               show_dir_entry(istate, tag_other, ent);
        }
 }
 
@@ -196,7 +197,7 @@ static void show_killed_files(const struct index_state *istate,
                        }
                }
                if (killed)
-                       show_dir_entry(tag_killed, dir->entries[i]);
+                       show_dir_entry(istate, tag_killed, dir->entries[i]);
        }
 }
 
@@ -228,7 +229,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
        if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
            is_submodule_active(repo, ce->name)) {
                show_submodule(repo, dir, ce->name);
-       } else if (match_pathspec(&pathspec, fullname, strlen(fullname),
+       } else if (match_pathspec(repo->index, &pathspec, fullname, strlen(fullname),
                                  max_prefix_len, ps_matched,
                                  S_ISDIR(ce->ce_mode) ||
                                  S_ISGITLINK(ce->ce_mode))) {
@@ -264,7 +265,7 @@ static void show_ru_info(const struct index_state *istate)
                len = strlen(path);
                if (len < max_prefix_len)
                        continue; /* outside of the prefix */
-               if (!match_pathspec(&pathspec, path, len,
+               if (!match_pathspec(istate, &pathspec, path, len,
                                    max_prefix_len, ps_matched, 0))
                        continue; /* uninterested */
                for (i = 0; i < 3; i++) {
index 409da4e8351f6d8719671d3176f0ea34fe9b756c..fe3b952cb3007d12c2e94a08b10486ed301c4769 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
index 3b7600150b66c4bf814e21b74b2d931f44c83805..08d91b1f0c0172fef93f1a87bf0843a85f57ca37 100644 (file)
@@ -6,6 +6,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "parse-options.h"
+#include "repository.h"
 
 static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
 {
@@ -42,7 +43,7 @@ static struct commit *get_commit_reference(const char *arg)
 
        if (get_oid(arg, &revkey))
                die("Not a valid object name %s", arg);
-       r = lookup_commit_reference(&revkey);
+       r = lookup_commit_reference(the_repository, &revkey);
        if (!r)
                die("Not a valid commit name %s", arg);
 
@@ -123,7 +124,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
        if (is_null_oid(oid))
                return;
 
-       commit = lookup_commit(oid);
+       commit = lookup_commit(the_repository, oid);
        if (!commit ||
            (commit->object.flags & TMP_MARK) ||
            parse_commit(commit))
@@ -171,7 +172,7 @@ static int handle_fork_point(int argc, const char **argv)
        if (get_oid(commitname, &oid))
                die("Not a valid object name: '%s'", commitname);
 
-       derived = lookup_commit_reference(&oid);
+       derived = lookup_commit_reference(the_repository, &oid);
        memset(&revs, 0, sizeof(revs));
        revs.initial = 1;
        for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
index 0dd902195878aedef76559ad67ad6dc9384141b3..9b2f707c291cf903b9151c2f3673b6fe0e0ca6d5 100644 (file)
@@ -9,10 +9,10 @@ static const char builtin_merge_recursive_usage[] =
 
 static const char *better_branch_name(const char *branch)
 {
-       static char githead_env[8 + GIT_SHA1_HEXSZ + 1];
+       static char githead_env[8 + GIT_MAX_HEXSZ + 1];
        char *name;
 
-       if (strlen(branch) != GIT_SHA1_HEXSZ)
+       if (strlen(branch) != the_hash_algo->hexsz)
                return branch;
        xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
        name = getenv(githead_env);
index bf01e05808313da20ed73c37d0d150c4ddb45587..f8023bae1e2eceaa8ea086f5d990d8bc4c0e6121 100644 (file)
@@ -1,6 +1,8 @@
 #include "builtin.h"
 #include "tree-walk.h"
 #include "xdiff-interface.h"
+#include "object-store.h"
+#include "repository.h"
 #include "blob.h"
 #include "exec-cmd.h"
 #include "merge-blobs.h"
@@ -169,7 +171,7 @@ static struct merge_list *create_entry(unsigned stage, unsigned mode, const stru
        res->stage = stage;
        res->path = path;
        res->mode = mode;
-       res->blob = lookup_blob(oid);
+       res->blob = lookup_blob(the_repository, oid);
        return res;
 }
 
index 4a4c09496cfee08417c18cc010528464a3137488..8f4a5065c209b5b50e02271b48277fff90306338 100644 (file)
@@ -111,6 +111,35 @@ static int option_parse_message(const struct option *opt,
        return 0;
 }
 
+static int option_read_message(struct parse_opt_ctx_t *ctx,
+                              const struct option *opt, int unset)
+{
+       struct strbuf *buf = opt->value;
+       const char *arg;
+
+       if (unset)
+               BUG("-F cannot be negated");
+
+       if (ctx->opt) {
+               arg = ctx->opt;
+               ctx->opt = NULL;
+       } else if (ctx->argc > 1) {
+               ctx->argc--;
+               arg = *++ctx->argv;
+       } else
+               return opterror(opt, "requires a value", 0);
+
+       if (buf->len)
+               strbuf_addch(buf, '\n');
+       if (ctx->prefix && !is_absolute_path(arg))
+               arg = prefix_filename(ctx->prefix, arg);
+       if (strbuf_read_file(buf, arg, 0) < 0)
+               return error(_("could not read file '%s'"), arg);
+       have_message = 1;
+
+       return 0;
+}
+
 static struct strategy *get_strategy(const char *name)
 {
        int i;
@@ -228,6 +257,9 @@ static struct option builtin_merge_options[] = {
        OPT_CALLBACK('m', "message", &merge_msg, N_("message"),
                N_("merge commit message (for a non-fast-forward merge)"),
                option_parse_message),
+       { OPTION_LOWLEVEL_CALLBACK, 'F', "file", &merge_msg, N_("path"),
+               N_("read message from file"), PARSE_OPT_NONEG,
+               (parse_opt_cb *) option_read_message },
        OPT__VERBOSITY(&verbosity),
        OPT_BOOL(0, "abort", &abort_current_merge,
                N_("abort the current in-progress merge")),
@@ -247,9 +279,9 @@ static struct option builtin_merge_options[] = {
 /* Cleans up metadata that is uninteresting after a succeeded merge. */
 static void drop_save(void)
 {
-       unlink(git_path_merge_head());
-       unlink(git_path_merge_msg());
-       unlink(git_path_merge_mode());
+       unlink(git_path_merge_head(the_repository));
+       unlink(git_path_merge_msg(the_repository));
+       unlink(git_path_merge_mode(the_repository));
 }
 
 static int save_state(struct object_id *stash)
@@ -382,7 +414,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
                        oid_to_hex(&commit->object.oid));
                pretty_print_commit(&ctx, commit, &out);
        }
-       write_file_buf(git_path_squash_msg(), out.buf, out.len);
+       write_file_buf(git_path_squash_msg(the_repository), out.buf, out.len);
        strbuf_release(&out);
 }
 
@@ -693,7 +725,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
                        exit(128);
                if (write_locked_index(&the_index, &lock,
                                       COMMIT_LOCK | SKIP_IF_UNCHANGED))
-                       die (_("unable to write %s"), get_index_file());
+                       die(_("unable to write %s"), get_index_file());
                return clean ? 0 : 1;
        } else {
                return try_merge_command(strategy, xopts_nr, xopts,
@@ -741,7 +773,7 @@ static void add_strategies(const char *string, unsigned attr)
 
 static void read_merge_msg(struct strbuf *msg)
 {
-       const char *filename = git_path_merge_msg();
+       const char *filename = git_path_merge_msg(the_repository);
        strbuf_reset(msg);
        if (strbuf_read_file(msg, filename, 0) < 0)
                die_errno(_("Could not read from '%s'"), filename);
@@ -778,18 +810,18 @@ static void prepare_to_commit(struct commit_list *remoteheads)
        if (signoff)
                append_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0);
        write_merge_heads(remoteheads);
-       write_file_buf(git_path_merge_msg(), msg.buf, msg.len);
+       write_file_buf(git_path_merge_msg(the_repository), msg.buf, msg.len);
        if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg",
-                           git_path_merge_msg(), "merge", NULL))
+                           git_path_merge_msg(the_repository), "merge", NULL))
                abort_commit(remoteheads, NULL);
        if (0 < option_edit) {
-               if (launch_editor(git_path_merge_msg(), NULL, NULL))
+               if (launch_editor(git_path_merge_msg(the_repository), NULL, NULL))
                        abort_commit(remoteheads, NULL);
        }
 
        if (verify_msg && run_commit_hook(0 < option_edit, get_index_file(),
                                          "commit-msg",
-                                         git_path_merge_msg(), NULL))
+                                         git_path_merge_msg(the_repository), NULL))
                abort_commit(remoteheads, NULL);
 
        read_merge_msg(&msg);
@@ -859,7 +891,7 @@ static int suggest_conflicts(void)
        FILE *fp;
        struct strbuf msgbuf = STRBUF_INIT;
 
-       filename = git_path_merge_msg();
+       filename = git_path_merge_msg(the_repository);
        fp = xfopen(filename, "a");
 
        append_conflicts_hint(&msgbuf);
@@ -942,12 +974,12 @@ static void write_merge_heads(struct commit_list *remoteheads)
                }
                strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
        }
-       write_file_buf(git_path_merge_head(), buf.buf, buf.len);
+       write_file_buf(git_path_merge_head(the_repository), buf.buf, buf.len);
 
        strbuf_reset(&buf);
        if (fast_forward == FF_NO)
                strbuf_addstr(&buf, "no-ff");
-       write_file_buf(git_path_merge_mode(), buf.buf, buf.len);
+       write_file_buf(git_path_merge_mode(the_repository), buf.buf, buf.len);
        strbuf_release(&buf);
 }
 
@@ -955,7 +987,8 @@ static void write_merge_state(struct commit_list *remoteheads)
 {
        write_merge_heads(remoteheads);
        strbuf_addch(&merge_msg, '\n');
-       write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);
+       write_file_buf(git_path_merge_msg(the_repository), merge_msg.buf,
+                      merge_msg.len);
 }
 
 static int default_edit_option(void)
@@ -1034,11 +1067,12 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge
        const char *filename;
        int fd, pos, npos;
        struct strbuf fetch_head_file = STRBUF_INIT;
+       const unsigned hexsz = the_hash_algo->hexsz;
 
        if (!merge_names)
                merge_names = &fetch_head_file;
 
-       filename = git_path_fetch_head();
+       filename = git_path_fetch_head(the_repository);
        fd = open(filename, O_RDONLY);
        if (fd < 0)
                die_errno(_("could not open '%s' for reading"), filename);
@@ -1059,16 +1093,16 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge
                else
                        npos = merge_names->len;
 
-               if (npos - pos < GIT_SHA1_HEXSZ + 2 ||
+               if (npos - pos < hexsz + 2 ||
                    get_oid_hex(merge_names->buf + pos, &oid))
                        commit = NULL; /* bad */
-               else if (memcmp(merge_names->buf + pos + GIT_SHA1_HEXSZ, "\t\t", 2))
+               else if (memcmp(merge_names->buf + pos + hexsz, "\t\t", 2))
                        continue; /* not-for-merge */
                else {
-                       char saved = merge_names->buf[pos + GIT_SHA1_HEXSZ];
-                       merge_names->buf[pos + GIT_SHA1_HEXSZ] = '\0';
+                       char saved = merge_names->buf[pos + hexsz];
+                       merge_names->buf[pos + hexsz] = '\0';
                        commit = get_merge_parent(merge_names->buf + pos);
-                       merge_names->buf[pos + GIT_SHA1_HEXSZ] = saved;
+                       merge_names->buf[pos + hexsz] = saved;
                }
                if (!commit) {
                        if (ptr)
@@ -1213,7 +1247,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                        usage_msg_opt(_("--abort expects no arguments"),
                              builtin_merge_usage, builtin_merge_options);
 
-               if (!file_exists(git_path_merge_head()))
+               if (!file_exists(git_path_merge_head(the_repository)))
                        die(_("There is no merge to abort (MERGE_HEAD missing)."));
 
                /* Invoke 'git reset --merge' */
@@ -1229,7 +1263,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                        usage_msg_opt(_("--continue expects no arguments"),
                              builtin_merge_usage, builtin_merge_options);
 
-               if (!file_exists(git_path_merge_head()))
+               if (!file_exists(git_path_merge_head(the_repository)))
                        die(_("There is no merge in progress (MERGE_HEAD missing)."));
 
                /* Invoke 'git commit' */
@@ -1240,7 +1274,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        if (read_cache_unmerged())
                die_resolve_conflict("merge");
 
-       if (file_exists(git_path_merge_head())) {
+       if (file_exists(git_path_merge_head(the_repository))) {
                /*
                 * There is no unmerged entry, don't advise 'git
                 * add/rm <file>', just 'git commit'.
@@ -1251,7 +1285,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                else
                        die(_("You have not concluded your merge (MERGE_HEAD exists)."));
        }
-       if (file_exists(git_path_cherry_pick_head())) {
+       if (file_exists(git_path_cherry_pick_head(the_repository))) {
                if (advice_resolve_conflict)
                        die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
                            "Please, commit your changes before you merge."));
index 82a6e860775f872a9145e32ee9d8f315b70ad2ea..6fb7dc8578d68526c64179d7fc43aaa5a72445f6 100644 (file)
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "tag.h"
 #include "replace-object.h"
+#include "object-store.h"
 
 /*
  * A signature file has a very simple fixed format: four lines
index bb76b469fd1f57319f3d202c1e2658d77962d698..2dc4ad6ba8f227a6a8a46bac62048959220411ec 100644 (file)
@@ -7,6 +7,7 @@
 #include "quote.h"
 #include "tree.h"
 #include "parse-options.h"
+#include "object-store.h"
 
 static struct treeent {
        unsigned mode;
index 0eb440359dd40d51f2802979218bd20a2d3d732e..f1cb45c22746bbcfb76d8fb1fefd5061f582cf57 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "repository.h"
 #include "config.h"
 #include "commit.h"
 #include "tag.h"
@@ -203,7 +204,7 @@ static int tipcmp(const void *a_, const void *b_)
 
 static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data)
 {
-       struct object *o = parse_object(oid);
+       struct object *o = parse_object(the_repository, oid);
        struct name_ref_data *data = cb_data;
        int can_abbreviate_output = data->tags_only && data->name_only;
        int deref = 0;
@@ -261,7 +262,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
                struct tag *t = (struct tag *) o;
                if (!t->tagged)
                        break; /* broken repository */
-               o = parse_object(&t->tagged->oid);
+               o = parse_object(the_repository, &t->tagged->oid);
                deref = 1;
                taggerdate = t->date;
        }
@@ -378,7 +379,8 @@ static void name_rev_line(char *p, struct name_ref_data *data)
                        *(p+1) = 0;
                        if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {
                                struct object *o =
-                                       lookup_object(oid.hash);
+                                       lookup_object(the_repository,
+                                                     oid.hash);
                                if (o)
                                        name = get_rev_name(o, &buf);
                        }
@@ -451,9 +453,10 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
                }
 
                commit = NULL;
-               object = parse_object(&oid);
+               object = parse_object(the_repository, &oid);
                if (object) {
-                       struct object *peeled = deref_tag(object, *argv, 0);
+                       struct object *peeled = deref_tag(the_repository,
+                                                         object, *argv, 0);
                        if (peeled && peeled->type == OBJ_COMMIT)
                                commit = (struct commit *)peeled;
                }
index 6981e2d906f43b06cac5bd11cb0d627571be09d5..c05cd004abcbdcd1e4c3d140f3cf4251c416df36 100644 (file)
@@ -11,6 +11,8 @@
 #include "config.h"
 #include "builtin.h"
 #include "notes.h"
+#include "object-store.h"
+#include "repository.h"
 #include "blob.h"
 #include "pretty.h"
 #include "refs.h"
@@ -710,7 +712,7 @@ static int merge_commit(struct notes_merge_options *o)
 
        if (get_oid("NOTES_MERGE_PARTIAL", &oid))
                die(_("failed to read ref NOTES_MERGE_PARTIAL"));
-       else if (!(partial = lookup_commit_reference(&oid)))
+       else if (!(partial = lookup_commit_reference(the_repository, &oid)))
                die(_("could not find commit from NOTES_MERGE_PARTIAL."));
        else if (parse_commit(partial))
                die(_("could not parse commit from NOTES_MERGE_PARTIAL."));
index 71056d8294d7f4bcfdcbc9bb292a5d17faf49252..0d80dee2ba1ad82fd21622f73dac86b6010da4b6 100644 (file)
@@ -140,7 +140,7 @@ static void *get_delta(struct object_entry *entry)
 
        buf = read_object_file(&entry->idx.oid, &type, &size);
        if (!buf)
-               die("unable to read %s", oid_to_hex(&entry->idx.oid));
+               die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
        base_buf = read_object_file(&DELTA(entry)->idx.oid, &type,
                                    &base_size);
        if (!base_buf)
@@ -148,8 +148,13 @@ static void *get_delta(struct object_entry *entry)
                    oid_to_hex(&DELTA(entry)->idx.oid));
        delta_buf = diff_delta(base_buf, base_size,
                               buf, size, &delta_size, 0);
+       /*
+        * We succesfully computed this delta once but dropped it for
+        * memory reasons. Something is very wrong if this time we
+        * recompute and create a different delta.
+        */
        if (!delta_buf || delta_size != DELTA_SIZE(entry))
-               die("delta size changed");
+               BUG("delta size changed");
        free(buf);
        free(base_buf);
        return delta_buf;
@@ -406,7 +411,7 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
        datalen = revidx[1].offset - offset;
        if (!pack_to_stdout && p->index_version > 1 &&
            check_pack_crc(p, &w_curs, offset, datalen, revidx->nr)) {
-               error("bad packed object CRC for %s",
+               error(_("bad packed object CRC for %s"),
                      oid_to_hex(&entry->idx.oid));
                unuse_pack(&w_curs);
                return write_no_reuse_object(f, entry, limit, usable_delta);
@@ -417,7 +422,7 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
 
        if (!pack_to_stdout && p->index_version == 1 &&
            check_pack_inflate(p, &w_curs, offset, datalen, entry_size)) {
-               error("corrupt packed object for %s",
+               error(_("corrupt packed object for %s"),
                      oid_to_hex(&entry->idx.oid));
                unuse_pack(&w_curs);
                return write_no_reuse_object(f, entry, limit, usable_delta);
@@ -548,7 +553,7 @@ static enum write_one_status write_one(struct hashfile *f,
         */
        recursing = (e->idx.offset == 1);
        if (recursing) {
-               warning("recursive delta detected for object %s",
+               warning(_("recursive delta detected for object %s"),
                        oid_to_hex(&e->idx.oid));
                return WRITE_ONE_RECURSIVE;
        } else if (e->idx.offset || e->preferred_base) {
@@ -582,7 +587,7 @@ static enum write_one_status write_one(struct hashfile *f,
 
        /* make sure off_t is sufficiently large not to wrap */
        if (signed_add_overflows(*offset, size))
-               die("pack too large for current definition of off_t");
+               die(_("pack too large for current definition of off_t"));
        *offset += size;
        return WRITE_ONE_WRITTEN;
 }
@@ -748,7 +753,8 @@ static struct object_entry **compute_write_order(void)
        }
 
        if (wo_end != to_pack.nr_objects)
-               die("ordered %u objects, expected %"PRIu32, wo_end, to_pack.nr_objects);
+               die(_("ordered %u objects, expected %"PRIu32),
+                   wo_end, to_pack.nr_objects);
 
        return wo;
 }
@@ -760,15 +766,15 @@ static off_t write_reused_pack(struct hashfile *f)
        int fd;
 
        if (!is_pack_valid(reuse_packfile))
-               die("packfile is invalid: %s", reuse_packfile->pack_name);
+               die(_("packfile is invalid: %s"), reuse_packfile->pack_name);
 
        fd = git_open(reuse_packfile->pack_name);
        if (fd < 0)
-               die_errno("unable to open packfile for reuse: %s",
+               die_errno(_("unable to open packfile for reuse: %s"),
                          reuse_packfile->pack_name);
 
        if (lseek(fd, sizeof(struct pack_header), SEEK_SET) == -1)
-               die_errno("unable to seek in reused packfile");
+               die_errno(_("unable to seek in reused packfile"));
 
        if (reuse_packfile_offset < 0)
                reuse_packfile_offset = reuse_packfile->pack_size - the_hash_algo->rawsz;
@@ -779,7 +785,7 @@ static off_t write_reused_pack(struct hashfile *f)
                int read_pack = xread(fd, buffer, sizeof(buffer));
 
                if (read_pack <= 0)
-                       die_errno("unable to read from reused packfile");
+                       die_errno(_("unable to read from reused packfile"));
 
                if (read_pack > to_write)
                        read_pack = to_write;
@@ -882,7 +888,7 @@ static void write_pack_file(void)
                         * to preserve this property.
                         */
                        if (stat(pack_tmp_name, &st) < 0) {
-                               warning_errno("failed to stat %s", pack_tmp_name);
+                               warning_errno(_("failed to stat %s"), pack_tmp_name);
                        } else if (!last_mtime) {
                                last_mtime = st.st_mtime;
                        } else {
@@ -890,7 +896,7 @@ static void write_pack_file(void)
                                utb.actime = st.st_atime;
                                utb.modtime = --last_mtime;
                                if (utime(pack_tmp_name, &utb) < 0)
-                                       warning_errno("failed utime() on %s", pack_tmp_name);
+                                       warning_errno(_("failed utime() on %s"), pack_tmp_name);
                        }
 
                        strbuf_addf(&tmpname, "%s-", base_name);
@@ -935,8 +941,8 @@ static void write_pack_file(void)
        free(write_order);
        stop_progress(&progress_state);
        if (written != nr_result)
-               die("wrote %"PRIu32" objects while expecting %"PRIu32,
-                       written, nr_result);
+               die(_("wrote %"PRIu32" objects while expecting %"PRIu32),
+                   written, nr_result);
 }
 
 static int no_try_delta(const char *path)
@@ -945,7 +951,7 @@ static int no_try_delta(const char *path)
 
        if (!check)
                check = attr_check_initl("delta", NULL);
-       if (git_check_attr(path, check))
+       if (git_check_attr(&the_index, path, check))
                return 0;
        if (ATTR_FALSE(check->items[0].value))
                return 1;
@@ -1480,7 +1486,7 @@ static void check_object(struct object_entry *entry)
                        while (c & 128) {
                                ofs += 1;
                                if (!ofs || MSB(ofs, 7)) {
-                                       error("delta base offset overflow in pack for %s",
+                                       error(_("delta base offset overflow in pack for %s"),
                                              oid_to_hex(&entry->idx.oid));
                                        goto give_up;
                                }
@@ -1489,7 +1495,7 @@ static void check_object(struct object_entry *entry)
                        }
                        ofs = entry->in_pack_offset - ofs;
                        if (ofs <= 0 || ofs >= entry->in_pack_offset) {
-                               error("delta base offset out of bound for %s",
+                               error(_("delta base offset out of bound for %s"),
                                      oid_to_hex(&entry->idx.oid));
                                goto give_up;
                        }
@@ -1852,18 +1858,30 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
 
 #ifndef NO_PTHREADS
 
+/* 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)
 #define cache_unlock()         pthread_mutex_unlock(&cache_mutex)
 
+/*
+ * Protect object list partitioning (e.g. struct thread_param) and
+ * progress_state
+ */
 static pthread_mutex_t progress_mutex;
 #define progress_lock()                pthread_mutex_lock(&progress_mutex)
 #define progress_unlock()      pthread_mutex_unlock(&progress_mutex)
 
+/*
+ * Access to struct object_entry is unprotected since each thread owns
+ * a portion of the main object list. Just don't access object entries
+ * ahead in the list because they can be stolen and would need
+ * progress_mutex for protection.
+ */
 #else
 
 #define read_lock()            (void)0
@@ -1974,10 +1992,10 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
                trg->data = read_object_file(&trg_entry->idx.oid, &type, &sz);
                read_unlock();
                if (!trg->data)
-                       die("object %s cannot be read",
+                       die(_("object %s cannot be read"),
                            oid_to_hex(&trg_entry->idx.oid));
                if (sz != trg_size)
-                       die("object %s inconsistent object length (%lu vs %lu)",
+                       die(_("object %s inconsistent object length (%lu vs %lu)"),
                            oid_to_hex(&trg_entry->idx.oid), sz,
                            trg_size);
                *mem_usage += sz;
@@ -1990,7 +2008,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
                        if (src_entry->preferred_base) {
                                static int warned = 0;
                                if (!warned++)
-                                       warning("object %s cannot be read",
+                                       warning(_("object %s cannot be read"),
                                                oid_to_hex(&src_entry->idx.oid));
                                /*
                                 * Those objects are not included in the
@@ -2000,11 +2018,11 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
                                 */
                                return 0;
                        }
-                       die("object %s cannot be read",
+                       die(_("object %s cannot be read"),
                            oid_to_hex(&src_entry->idx.oid));
                }
                if (sz != src_size)
-                       die("object %s inconsistent object length (%lu vs %lu)",
+                       die(_("object %s inconsistent object length (%lu vs %lu)"),
                            oid_to_hex(&src_entry->idx.oid), sz,
                            src_size);
                *mem_usage += sz;
@@ -2014,7 +2032,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
                if (!src->index) {
                        static int warned = 0;
                        if (!warned++)
-                               warning("suboptimal pack - out of memory");
+                               warning(_("suboptimal pack - out of memory"));
                        return 0;
                }
                *mem_usage += sizeof_delta_index(src->index);
@@ -2245,12 +2263,19 @@ static void try_to_free_from_threads(size_t size)
 static try_to_free_t old_try_to_free_routine;
 
 /*
+ * The main object list is split into smaller lists, each is handed to
+ * one worker.
+ *
  * The main thread waits on the condition that (at least) one of the workers
  * has stopped working (which is indicated in the .working member of
  * struct thread_params).
+ *
  * When a work thread has completed its work, it sets .working to 0 and
  * signals the main thread and waits on the condition that .data_ready
  * becomes 1.
+ *
+ * The main thread steals half of the work from the worker that has
+ * most work left to hand it to the idle worker.
  */
 
 struct thread_params {
@@ -2341,8 +2366,8 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
                return;
        }
        if (progress > pack_to_stdout)
-               fprintf(stderr, "Delta compression using up to %d threads.\n",
-                               delta_search_threads);
+               fprintf_ln(stderr, _("Delta compression using up to %d threads"),
+                          delta_search_threads);
        p = xcalloc(delta_search_threads, sizeof(*p));
 
        /* Partition the work amongst work threads. */
@@ -2382,7 +2407,7 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
                ret = pthread_create(&p[i].thread, NULL,
                                     threaded_find_deltas, &p[i]);
                if (ret)
-                       die("unable to create thread: %s", strerror(ret));
+                       die(_("unable to create thread: %s"), strerror(ret));
                active_threads++;
        }
 
@@ -2474,10 +2499,10 @@ static void add_tag_chain(const struct object_id *oid)
        if (packlist_find(&to_pack, oid->hash, NULL))
                return;
 
-       tag = lookup_tag(oid);
+       tag = lookup_tag(the_repository, oid);
        while (1) {
                if (!tag || parse_tag(tag) || !tag->tagged)
-                       die("unable to pack objects reachable from tag %s",
+                       die(_("unable to pack objects reachable from tag %s"),
                            oid_to_hex(oid));
 
                add_object_entry(&tag->object.oid, OBJ_TAG, NULL, 0);
@@ -2543,7 +2568,7 @@ static void prepare_pack(int window, int depth)
                if (!entry->preferred_base) {
                        nr_deltas++;
                        if (oe_type(entry) < 0)
-                               die("unable to get type of object %s",
+                               die(_("unable to get type of object %s"),
                                    oid_to_hex(&entry->idx.oid));
                } else {
                        if (oe_type(entry) < 0) {
@@ -2567,7 +2592,7 @@ static void prepare_pack(int window, int depth)
                ll_find_deltas(delta_list, n, window+1, depth, &nr_done);
                stop_progress(&progress_state);
                if (nr_done != nr_deltas)
-                       die("inconsistency with delta count");
+                       die(_("inconsistency with delta count"));
        }
        free(delta_list);
 }
@@ -2607,11 +2632,11 @@ static int git_pack_config(const char *k, const char *v, void *cb)
        if (!strcmp(k, "pack.threads")) {
                delta_search_threads = git_config_int(k, v);
                if (delta_search_threads < 0)
-                       die("invalid number of threads specified (%d)",
+                       die(_("invalid number of threads specified (%d)"),
                            delta_search_threads);
 #ifdef NO_PTHREADS
                if (delta_search_threads != 1) {
-                       warning("no threads support, ignoring %s", k);
+                       warning(_("no threads support, ignoring %s"), k);
                        delta_search_threads = 0;
                }
 #endif
@@ -2620,7 +2645,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
        if (!strcmp(k, "pack.indexversion")) {
                pack_idx_opts.version = git_config_int(k, v);
                if (pack_idx_opts.version > 2)
-                       die("bad pack.indexversion=%"PRIu32,
+                       die(_("bad pack.indexversion=%"PRIu32),
                            pack_idx_opts.version);
                return 0;
        }
@@ -2638,7 +2663,7 @@ static void read_object_list_from_stdin(void)
                        if (feof(stdin))
                                break;
                        if (!ferror(stdin))
-                               die("fgets returned NULL, not EOF, not error!");
+                               die("BUG: fgets returned NULL, not EOF, not error!");
                        if (errno != EINTR)
                                die_errno("fgets");
                        clearerr(stdin);
@@ -2646,13 +2671,13 @@ static void read_object_list_from_stdin(void)
                }
                if (line[0] == '-') {
                        if (get_oid_hex(line+1, &oid))
-                               die("expected edge object ID, got garbage:\n %s",
+                               die(_("expected edge object ID, got garbage:\n %s"),
                                    line);
                        add_preferred_base(&oid);
                        continue;
                }
                if (parse_oid_hex(line, &oid, &p))
-                       die("expected object ID, got garbage:\n %s", line);
+                       die(_("expected object ID, got garbage:\n %s"), line);
 
                add_preferred_base_object(p + 1);
                add_object_entry(&oid, OBJ_NONE, p + 1, 0);
@@ -2791,7 +2816,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
                if (!p->pack_local || p->pack_keep || p->pack_keep_in_core)
                        continue;
                if (open_pack_index(p))
-                       die("cannot open pack index");
+                       die(_("cannot open pack index"));
 
                ALLOC_GROW(in_pack.array,
                           in_pack.nr + p->num_objects,
@@ -2822,7 +2847,7 @@ static int add_loose_object(const struct object_id *oid, const char *path,
        enum object_type type = oid_object_info(the_repository, oid, NULL);
 
        if (type < 0) {
-               warning("loose object at %s could not be examined", path);
+               warning(_("loose object at %s could not be examined"), path);
                return 0;
        }
 
@@ -2899,7 +2924,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
                        continue;
 
                if (open_pack_index(p))
-                       die("cannot open pack index");
+                       die(_("cannot open pack index"));
 
                for (i = 0; i < p->num_objects; i++) {
                        nth_packed_object_oid(&oid, p, i);
@@ -2907,7 +2932,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
                            !has_sha1_pack_kept_or_nonlocal(&oid) &&
                            !loosened_object_can_be_discarded(&oid, p->mtime))
                                if (force_object_loose(&oid, p->mtime))
-                                       die("unable to force loose object");
+                                       die(_("unable to force loose object"));
                }
        }
 }
@@ -2929,11 +2954,13 @@ static int pack_options_allow_reuse(void)
 
 static int get_object_list_from_bitmap(struct rev_info *revs)
 {
-       if (prepare_bitmap_walk(revs) < 0)
+       struct bitmap_index *bitmap_git;
+       if (!(bitmap_git = prepare_bitmap_walk(revs)))
                return -1;
 
        if (pack_options_allow_reuse() &&
            !reuse_partial_packfile_from_bitmap(
+                       bitmap_git,
                        &reuse_packfile,
                        &reuse_packfile_objects,
                        &reuse_packfile_offset)) {
@@ -2942,7 +2969,8 @@ static int get_object_list_from_bitmap(struct rev_info *revs)
                display_progress(progress_state, nr_result);
        }
 
-       traverse_bitmap_commit_list(&add_object_entry_from_bitmap);
+       traverse_bitmap_commit_list(bitmap_git, &add_object_entry_from_bitmap);
+       free_bitmap_index(bitmap_git);
        return 0;
 }
 
@@ -2969,7 +2997,7 @@ static void get_object_list(int ac, const char **av)
        setup_revisions(ac, av, &revs, NULL);
 
        /* make sure shallows are read */
-       is_repository_shallow();
+       is_repository_shallow(the_repository);
 
        while (fgets(line, sizeof(line), stdin) != NULL) {
                int len = strlen(line);
@@ -2987,21 +3015,21 @@ static void get_object_list(int ac, const char **av)
                                struct object_id oid;
                                if (get_oid_hex(line + 10, &oid))
                                        die("not an SHA-1 '%s'", line + 10);
-                               register_shallow(&oid);
+                               register_shallow(the_repository, &oid);
                                use_bitmap_index = 0;
                                continue;
                        }
-                       die("not a rev '%s'", line);
+                       die(_("not a rev '%s'"), line);
                }
                if (handle_revision_arg(line, &revs, flags, REVARG_CANNOT_BE_FILENAME))
-                       die("bad revision '%s'", line);
+                       die(_("bad revision '%s'"), line);
        }
 
        if (use_bitmap_index && !get_object_list_from_bitmap(&revs))
                return;
 
        if (prepare_revision_walk(&revs))
-               die("revision walk setup failed");
+               die(_("revision walk setup failed"));
        mark_edges_uninteresting(&revs, show_edge);
 
        if (!fn_show_object)
@@ -3014,9 +3042,9 @@ static void get_object_list(int ac, const char **av)
                revs.ignore_missing_links = 1;
                if (add_unseen_recent_objects_to_traversal(&revs,
                                unpack_unreachable_expiration))
-                       die("unable to add recent objects");
+                       die(_("unable to add recent objects"));
                if (prepare_revision_walk(&revs))
-                       die("revision walk setup failed");
+                       die(_("revision walk setup failed"));
                traverse_commit_list(&revs, record_recent_commit,
                                     record_recent_object, NULL);
        }
@@ -3107,7 +3135,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                OPT_BOOL(0, "all-progress-implied",
                         &all_progress_implied,
                         N_("similar to --all-progress when progress meter is shown")),
-               { OPTION_CALLBACK, 0, "index-version", NULL, N_("version[,offset]"),
+               { OPTION_CALLBACK, 0, "index-version", NULL, N_("<version>[,<offset>]"),
                  N_("write the pack index file in the specified idx format version"),
                  0, option_parse_index_version },
                OPT_MAGNITUDE(0, "max-pack-size", &pack_size_limit,
@@ -3185,7 +3213,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
        if (DFS_NUM_STATES > (1 << OE_DFS_STATE_BITS))
                BUG("too many dfs states, increase OE_DFS_STATE_BITS");
 
-       check_replace_refs = 0;
+       read_replace_refs = 0;
 
        reset_pack_idx_option(&pack_idx_opts);
        git_config(git_pack_config, NULL);
@@ -3251,35 +3279,35 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
        if (pack_compression_level == -1)
                pack_compression_level = Z_DEFAULT_COMPRESSION;
        else if (pack_compression_level < 0 || pack_compression_level > Z_BEST_COMPRESSION)
-               die("bad pack compression level %d", pack_compression_level);
+               die(_("bad pack compression level %d"), pack_compression_level);
 
        if (!delta_search_threads)      /* --threads=0 means autodetect */
                delta_search_threads = online_cpus();
 
 #ifdef NO_PTHREADS
        if (delta_search_threads != 1)
-               warning("no threads support, ignoring --threads");
+               warning(_("no threads support, ignoring --threads"));
 #endif
        if (!pack_to_stdout && !pack_size_limit)
                pack_size_limit = pack_size_limit_cfg;
        if (pack_to_stdout && pack_size_limit)
-               die("--max-pack-size cannot be used to build a pack for transfer.");
+               die(_("--max-pack-size cannot be used to build a pack for transfer"));
        if (pack_size_limit && pack_size_limit < 1024*1024) {
-               warning("minimum pack size limit is 1 MiB");
+               warning(_("minimum pack size limit is 1 MiB"));
                pack_size_limit = 1024*1024;
        }
 
        if (!pack_to_stdout && thin)
-               die("--thin cannot be used to build an indexable pack.");
+               die(_("--thin cannot be used to build an indexable pack"));
 
        if (keep_unreachable && unpack_unreachable)
-               die("--keep-unreachable and --unpack-unreachable are incompatible.");
+               die(_("--keep-unreachable and --unpack-unreachable are incompatible"));
        if (!rev_list_all || !rev_list_reflog || !rev_list_index)
                unpack_unreachable_expiration = 0;
 
        if (filter_options.choice) {
                if (!pack_to_stdout)
-                       die("cannot use --filter without --stdout.");
+                       die(_("cannot use --filter without --stdout"));
                use_bitmap_index = 0;
        }
 
@@ -3299,7 +3327,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                use_bitmap_index = use_bitmap_index_default;
 
        /* "hard" reasons not to use bitmaps; these just won't work at all */
-       if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow())
+       if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow(the_repository))
                use_bitmap_index = 0;
 
        if (pack_to_stdout || !rev_list_all)
@@ -3353,8 +3381,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                prepare_pack(window, depth);
        write_pack_file();
        if (progress)
-               fprintf(stderr, "Total %"PRIu32" (delta %"PRIu32"),"
-                       " reused %"PRIu32" (delta %"PRIu32")\n",
-                       written, written_delta, reused, reused_delta);
+               fprintf_ln(stderr,
+                          _("Total %"PRIu32" (delta %"PRIu32"),"
+                            " reused %"PRIu32" (delta %"PRIu32")"),
+                          written, written_delta, reused, reused_delta);
        return 0;
 }
index 4ff525e50fc701392e7ed276ae4bba4a82ddf8a1..a9e7b552b9d117c5f1078a0dd5864bbed724c6b6 100644 (file)
@@ -3,6 +3,7 @@
 #include "progress.h"
 #include "parse-options.h"
 #include "packfile.h"
+#include "object-store.h"
 
 static const char * const prune_packed_usage[] = {
        N_("git prune-packed [-n | --dry-run] [-q | --quiet]"),
index 518ffbea1397faa35102dc088a3830e40c9b13a6..4916a4daa264ee695dbfbde81dbd8ef0072ac9c4 100644 (file)
@@ -6,6 +6,7 @@
 #include "reachable.h"
 #include "parse-options.h"
 #include "progress.h"
+#include "object-store.h"
 
 static const char * const prune_usage[] = {
        N_("git prune [-n] [-v] [--progress] [--expire <time>] [--] [<head>...]"),
@@ -39,7 +40,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
         * Do we know about this object?
         * It must have been reachable
         */
-       if (lookup_object(oid->hash))
+       if (lookup_object(the_repository, oid->hash))
                return 0;
 
        if (lstat(fullpath, &st)) {
@@ -117,7 +118,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 
        expire = TIME_MAX;
        save_commit_buffer = 0;
-       check_replace_refs = 0;
+       read_replace_refs = 0;
        ref_paranoia = 1;
        init_revisions(&revs, prefix);
 
@@ -159,7 +160,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
        remove_temporary_files(s);
        free(s);
 
-       if (is_repository_shallow())
+       if (is_repository_shallow(the_repository))
                prune_shallow(show_only);
 
        return 0;
index fe002a72f8ac7f1020a951769641f5f4b39f23b3..53bc5facfdabd05934a351091f2040744b2575ca 100644 (file)
@@ -48,11 +48,11 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value,
                return REBASE_FALSE;
        else if (v > 0)
                return REBASE_TRUE;
-       else if (!strcmp(value, "preserve"))
+       else if (!strcmp(value, "preserve") || !strcmp(value, "p"))
                return REBASE_PRESERVE;
-       else if (!strcmp(value, "merges"))
+       else if (!strcmp(value, "merges") || !strcmp(value, "m"))
                return REBASE_MERGES;
-       else if (!strcmp(value, "interactive"))
+       else if (!strcmp(value, "interactive") || !strcmp(value, "i"))
                return REBASE_INTERACTIVE;
 
        if (fatal)
@@ -356,7 +356,7 @@ static int git_pull_config(const char *var, const char *value, void *cb)
  */
 static void get_merge_heads(struct oid_array *merge_heads)
 {
-       const char *filename = git_path_fetch_head();
+       const char *filename = git_path_fetch_head(the_repository);
        FILE *fp;
        struct strbuf sb = STRBUF_INIT;
        struct object_id oid;
@@ -765,10 +765,13 @@ static int get_octopus_merge_base(struct object_id *merge_base,
 {
        struct commit_list *revs = NULL, *result;
 
-       commit_list_insert(lookup_commit_reference(curr_head), &revs);
-       commit_list_insert(lookup_commit_reference(merge_head), &revs);
+       commit_list_insert(lookup_commit_reference(the_repository, curr_head),
+                          &revs);
+       commit_list_insert(lookup_commit_reference(the_repository, merge_head),
+                          &revs);
        if (!is_null_oid(fork_point))
-               commit_list_insert(lookup_commit_reference(fork_point), &revs);
+               commit_list_insert(lookup_commit_reference(the_repository, fork_point),
+                                  &revs);
 
        result = get_octopus_merge_bases(revs);
        free_commit_list(revs);
@@ -864,7 +867,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        if (read_cache_unmerged())
                die_resolve_conflict("pull");
 
-       if (file_exists(git_path_merge_head()))
+       if (file_exists(git_path_merge_head(the_repository)))
                die_conclude_merge();
 
        if (get_oid("HEAD", &orig_head))
@@ -944,9 +947,11 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                        struct commit_list *list = NULL;
                        struct commit *merge_head, *head;
 
-                       head = lookup_commit_reference(&orig_head);
+                       head = lookup_commit_reference(the_repository,
+                                                      &orig_head);
                        commit_list_insert(head, &list);
-                       merge_head = lookup_commit_reference(&merge_heads.oid[0]);
+                       merge_head = lookup_commit_reference(the_repository,
+                                                            &merge_heads.oid[0]);
                        if (is_descendant_of(merge_head, list)) {
                                /* we can fast-forward this without invoking rebase */
                                opt_ff = "--ff-only";
index 9cd8e8cd5631158e0904826567f2d3c02bca2bda..ef4c188895beab317a66523b23a9f1c87e634405 100644 (file)
@@ -558,9 +558,9 @@ int cmd_push(int argc, const char **argv, const char *prefix)
                OPT_BIT( 0,  "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
                OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
                { OPTION_CALLBACK,
-                 0, CAS_OPT_NAME, &cas, N_("refname>:<expect"),
+                 0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
                  N_("require old value of ref to be at this value"),
-                 PARSE_OPT_OPTARG, parseopt_push_cas_option },
+                 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option },
                { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, "check|on-demand|no",
                        N_("control recursive pushing of submodules"),
                        PARSE_OPT_OPTARG, option_parse_recurse_submodules },
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
new file mode 100644 (file)
index 0000000..f52d45d
--- /dev/null
@@ -0,0 +1,116 @@
+#include "cache.h"
+#include "builtin.h"
+#include "parse-options.h"
+#include "range-diff.h"
+#include "config.h"
+
+static const char * const builtin_range_diff_usage[] = {
+N_("git range-diff [<options>] <old-base>..<old-tip> <new-base>..<new-tip>"),
+N_("git range-diff [<options>] <old-tip>...<new-tip>"),
+N_("git range-diff [<options>] <base> <old-tip> <new-tip>"),
+NULL
+};
+
+static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data)
+{
+       return data;
+}
+
+int cmd_range_diff(int argc, const char **argv, const char *prefix)
+{
+       int creation_factor = 60;
+       struct diff_options diffopt = { NULL };
+       int simple_color = -1;
+       struct option options[] = {
+               OPT_INTEGER(0, "creation-factor", &creation_factor,
+                           N_("Percentage by which creation is weighted")),
+               OPT_BOOL(0, "no-dual-color", &simple_color,
+                           N_("color both diff and diff-between-diffs")),
+               OPT_END()
+       };
+       int i, j, res = 0;
+       struct strbuf four_spaces = STRBUF_INIT;
+       struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
+
+       git_config(git_diff_ui_config, NULL);
+
+       diff_setup(&diffopt);
+       diffopt.output_format = DIFF_FORMAT_PATCH;
+       diffopt.flags.suppress_diff_headers = 1;
+       diffopt.output_prefix = output_prefix_cb;
+       strbuf_addstr(&four_spaces, "    ");
+       diffopt.output_prefix_data = &four_spaces;
+
+       argc = parse_options(argc, argv, NULL, options,
+                            builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN |
+                            PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
+
+       for (i = j = 1; i < argc && strcmp("--", argv[i]); ) {
+               int c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix);
+
+               if (!c)
+                       argv[j++] = argv[i++];
+               else
+                       i += c;
+       }
+       while (i < argc)
+               argv[j++] = argv[i++];
+       argc = j;
+       diff_setup_done(&diffopt);
+
+       /* Make sure that there are no unparsed options */
+       argc = parse_options(argc, argv, NULL,
+                            options + ARRAY_SIZE(options) - 1, /* OPT_END */
+                            builtin_range_diff_usage, 0);
+
+       if (simple_color < 1) {
+               if (!simple_color)
+                       /* force color when --dual-color was used */
+                       diffopt.use_color = 1;
+               diffopt.flags.dual_color_diffed_diffs = 1;
+       }
+
+       if (argc == 2) {
+               if (!strstr(argv[0], ".."))
+                       die(_("no .. in range: '%s'"), argv[0]);
+               strbuf_addstr(&range1, argv[0]);
+
+               if (!strstr(argv[1], ".."))
+                       die(_("no .. in range: '%s'"), argv[1]);
+               strbuf_addstr(&range2, argv[1]);
+       } else if (argc == 3) {
+               strbuf_addf(&range1, "%s..%s", argv[0], argv[1]);
+               strbuf_addf(&range2, "%s..%s", argv[0], argv[2]);
+       } else if (argc == 1) {
+               const char *b = strstr(argv[0], "..."), *a = argv[0];
+               int a_len;
+
+               if (!b) {
+                       error(_("single arg format must be symmetric range"));
+                       usage_with_options(builtin_range_diff_usage, options);
+               }
+
+               a_len = (int)(b - a);
+               if (!a_len) {
+                       a = "HEAD";
+                       a_len = strlen(a);
+               }
+               b += 3;
+               if (!*b)
+                       b = "HEAD";
+               strbuf_addf(&range1, "%s..%.*s", b, a_len, a);
+               strbuf_addf(&range2, "%.*s..%s", a_len, a, b);
+       } else {
+               error(_("need two commit ranges"));
+               usage_with_options(builtin_range_diff_usage, options);
+       }
+
+       res = show_range_diff(range1.buf, range2.buf, creation_factor,
+                             &diffopt);
+
+       strbuf_release(&range1);
+       strbuf_release(&range2);
+       strbuf_release(&four_spaces);
+
+       return res;
+}
index ebc43eb8057dc9c85aad4c608250ed9a6c4d6cd1..fbbc98e5161f011a25743a528e6bb3f85e415f51 100644 (file)
@@ -133,7 +133,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
                         N_("same as -m, but discard unmerged entries")),
                { OPTION_STRING, 0, "prefix", &opts.prefix, N_("<subdirectory>/"),
                  N_("read the tree into the index under <subdirectory>/"),
-                 PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP },
+                 PARSE_OPT_NONEG },
                OPT_BOOL('u', NULL, &opts.update,
                         N_("update working tree with merge result")),
                { OPTION_CALLBACK, 0, "exclude-per-directory", &opts,
index 68d36e0a56c3c72ad76c07af293d20e8254377d1..c17ce94e12ee34c5b822b0e09fcd6d7264e759ad 100644 (file)
@@ -25,6 +25,7 @@
 #include "tmp-objdir.h"
 #include "oidset.h"
 #include "packfile.h"
+#include "object-store.h"
 #include "protocol.h"
 
 static const char * const receive_pack_usage[] = {
@@ -629,8 +630,6 @@ static void prepare_push_cert_sha1(struct child_process *proc)
                return;
 
        if (!already_done) {
-               struct strbuf gpg_output = STRBUF_INIT;
-               struct strbuf gpg_status = STRBUF_INIT;
                int bogs /* beginning_of_gpg_sig */;
 
                already_done = 1;
@@ -639,22 +638,11 @@ static void prepare_push_cert_sha1(struct child_process *proc)
                        oidclr(&push_cert_oid);
 
                memset(&sigcheck, '\0', sizeof(sigcheck));
-               sigcheck.result = 'N';
 
                bogs = parse_signature(push_cert.buf, push_cert.len);
-               if (verify_signed_buffer(push_cert.buf, bogs,
-                                        push_cert.buf + bogs, push_cert.len - bogs,
-                                        &gpg_output, &gpg_status) < 0) {
-                       ; /* error running gpg */
-               } else {
-                       sigcheck.payload = push_cert.buf;
-                       sigcheck.gpg_output = gpg_output.buf;
-                       sigcheck.gpg_status = gpg_status.buf;
-                       parse_gpg_output(&sigcheck);
-               }
+               check_signature(push_cert.buf, bogs, push_cert.buf + bogs,
+                               push_cert.len - bogs, &sigcheck);
 
-               strbuf_release(&gpg_output);
-               strbuf_release(&gpg_status);
                nonce_status = check_nonce(push_cert.buf, bogs);
        }
        if (!is_null_oid(&push_cert_oid)) {
@@ -905,7 +893,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
         * not lose these new roots..
         */
        for (i = 0; i < extra.nr; i++)
-               register_shallow(&extra.oid[i]);
+               register_shallow(the_repository, &extra.oid[i]);
 
        si->shallow_ref[cmd->index] = 0;
        oid_array_clear(&extra);
@@ -1107,8 +1095,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
                struct object *old_object, *new_object;
                struct commit *old_commit, *new_commit;
 
-               old_object = parse_object(old_oid);
-               new_object = parse_object(new_oid);
+               old_object = parse_object(the_repository, old_oid);
+               new_object = parse_object(the_repository, new_oid);
 
                if (!old_object || !new_object ||
                    old_object->type != OBJ_COMMIT ||
@@ -1131,7 +1119,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
 
        if (is_null_oid(new_oid)) {
                struct strbuf err = STRBUF_INIT;
-               if (!parse_object(old_oid)) {
+               if (!parse_object(the_repository, old_oid)) {
                        old_oid = NULL;
                        if (ref_exists(name)) {
                                rp_warning("Allowing deletion of corrupt ref.");
index a48984d37e4f5f9e1f07a840582f82e202bd09f0..3acef5a0abed400f543da673dbcaa2f648bd4bef 100644 (file)
@@ -1,6 +1,8 @@
 #include "builtin.h"
 #include "config.h"
 #include "lockfile.h"
+#include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "refs.h"
 #include "dir.h"
@@ -64,7 +66,7 @@ static int tree_is_complete(const struct object_id *oid)
        int complete;
        struct tree *tree;
 
-       tree = lookup_tree(oid);
+       tree = lookup_tree(the_repository, oid);
        if (!tree)
                return 0;
        if (tree->object.flags & SEEN)
@@ -128,7 +130,7 @@ static int commit_is_complete(struct commit *commit)
                struct commit_list *parent;
 
                c = (struct commit *)object_array_pop(&study);
-               if (!c->object.parsed && !parse_object(&c->object.oid))
+               if (!c->object.parsed && !parse_object(the_repository, &c->object.oid))
                        c->object.flags |= INCOMPLETE;
 
                if (c->object.flags & INCOMPLETE) {
@@ -194,7 +196,7 @@ static int keep_entry(struct commit **it, struct object_id *oid)
 
        if (is_null_oid(oid))
                return 1;
-       commit = lookup_commit_reference_gently(oid, 1);
+       commit = lookup_commit_reference_gently(the_repository, oid, 1);
        if (!commit)
                return 0;
 
@@ -263,7 +265,8 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit
                if (is_null_oid(oid))
                        return 0;
 
-               commit = lookup_commit_reference_gently(oid, 1);
+               commit = lookup_commit_reference_gently(the_repository, oid,
+                                                       1);
 
                /* Not a commit -- keep it */
                if (!commit)
@@ -320,7 +323,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid,
        struct commit *tip_commit;
        if (flags & REF_ISSYMREF)
                return 0;
-       tip_commit = lookup_commit_reference_gently(oid, 1);
+       tip_commit = lookup_commit_reference_gently(the_repository, oid, 1);
        if (!tip_commit)
                return 0;
        commit_list_insert(tip_commit, list);
@@ -337,7 +340,8 @@ static void reflog_expiry_prepare(const char *refname,
                cb->tip_commit = NULL;
                cb->unreachable_expire_kind = UE_HEAD;
        } else {
-               cb->tip_commit = lookup_commit_reference_gently(oid, 1);
+               cb->tip_commit = lookup_commit_reference_gently(the_repository,
+                                                               oid, 1);
                if (!cb->tip_commit)
                        cb->unreachable_expire_kind = UE_ALWAYS;
                else
index 1a82d850a22c3bfc3176eeda3f8b061b6feb7dc4..07bd51f8eb348036e7e1446d513e46e2877ec6a9 100644 (file)
@@ -8,6 +8,7 @@
 #include "run-command.h"
 #include "refs.h"
 #include "refspec.h"
+#include "object-store.h"
 #include "argv-array.h"
 
 static const char * const builtin_remote_usage[] = {
@@ -565,7 +566,7 @@ static int read_remote_branches(const char *refname,
 
        strbuf_addf(&buf, "refs/remotes/%s/", rename->old_name);
        if (starts_with(refname, buf.buf)) {
-               item = string_list_append(rename->remote_branches, xstrdup(refname));
+               item = string_list_append(rename->remote_branches, refname);
                symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
                                            NULL, &flag);
                if (symref && (flag & REF_ISSYMREF))
@@ -611,7 +612,7 @@ static int mv(int argc, const char **argv)
        struct remote *oldremote, *newremote;
        struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT,
                old_remote_context = STRBUF_INIT;
-       struct string_list remote_branches = STRING_LIST_INIT_NODUP;
+       struct string_list remote_branches = STRING_LIST_INIT_DUP;
        struct rename_info rename;
        int i, refspec_updated = 0;
 
@@ -733,6 +734,7 @@ static int mv(int argc, const char **argv)
                if (create_symref(buf.buf, buf2.buf, buf3.buf))
                        die(_("creating '%s' failed"), buf.buf);
        }
+       string_list_clear(&remote_branches, 1);
        return 0;
 }
 
index 6da2411e14b9f94f309671e14124ef32d89ef528..4f05791f3e895f78ba511dd6571bd09abab9269c 100644 (file)
@@ -54,7 +54,7 @@ static int show_reference(const char *refname, const struct object_id *oid,
                        enum object_type obj_type, repl_type;
 
                        if (get_oid(refname, &object))
-                               return error("Failed to resolve '%s' as a valid ref.", refname);
+                               return error(_("failed to resolve '%s' as a valid ref"), refname);
 
                        obj_type = oid_object_info(the_repository, &object,
                                                   NULL);
@@ -83,8 +83,8 @@ static int list_replace_refs(const char *pattern, const char *format)
        else if (!strcmp(format, "long"))
                data.format = REPLACE_FORMAT_LONG;
        else
-               return error("invalid replace format '%s'\n"
-                            "valid formats are 'short', 'medium' and 'long'\n",
+               return error(_("invalid replace format '%s'\n"
+                              "valid formats are 'short', 'medium' and 'long'"),
                             format);
 
        for_each_replace_ref(the_repository, show_reference, (void *)&data);
@@ -108,7 +108,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
 
        for (p = argv; *p; p++) {
                if (get_oid(*p, &oid)) {
-                       error("Failed to resolve '%s' as a valid ref.", *p);
+                       error("failed to resolve '%s' as a valid ref", *p);
                        had_error = 1;
                        continue;
                }
@@ -118,7 +118,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
                full_hex = ref.buf + base_len;
 
                if (read_ref(ref.buf, &oid)) {
-                       error("replace ref '%s' not found.", full_hex);
+                       error(_("replace ref '%s' not found"), full_hex);
                        had_error = 1;
                        continue;
                }
@@ -134,7 +134,7 @@ static int delete_replace_ref(const char *name, const char *ref,
 {
        if (delete_ref(NULL, ref, oid, 0))
                return 1;
-       printf("Deleted replace ref '%s'\n", name);
+       printf_ln(_("Deleted replace ref '%s'"), name);
        return 0;
 }
 
@@ -146,12 +146,12 @@ static int check_ref_valid(struct object_id *object,
        strbuf_reset(ref);
        strbuf_addf(ref, "%s%s", git_replace_ref_base, oid_to_hex(object));
        if (check_refname_format(ref->buf, 0))
-               return error("'%s' is not a valid ref name.", ref->buf);
+               return error(_("'%s' is not a valid ref name"), ref->buf);
 
        if (read_ref(ref->buf, prev))
                oidclr(prev);
        else if (!force)
-               return error("replace ref '%s' already exists", ref->buf);
+               return error(_("replace ref '%s' already exists"), ref->buf);
        return 0;
 }
 
@@ -171,10 +171,10 @@ static int replace_object_oid(const char *object_ref,
        obj_type = oid_object_info(the_repository, object, NULL);
        repl_type = oid_object_info(the_repository, repl, NULL);
        if (!force && obj_type != repl_type)
-               return error("Objects must be of the same type.\n"
-                            "'%s' points to a replaced object of type '%s'\n"
-                            "while '%s' points to a replacement object of "
-                            "type '%s'.",
+               return error(_("Objects must be of the same type.\n"
+                              "'%s' points to a replaced object of type '%s'\n"
+                              "while '%s' points to a replacement object of "
+                              "type '%s'."),
                             object_ref, type_name(obj_type),
                             replace_ref, type_name(repl_type));
 
@@ -200,10 +200,10 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f
        struct object_id object, repl;
 
        if (get_oid(object_ref, &object))
-               return error("Failed to resolve '%s' as a valid ref.",
+               return error(_("failed to resolve '%s' as a valid ref"),
                             object_ref);
        if (get_oid(replace_ref, &repl))
-               return error("Failed to resolve '%s' as a valid ref.",
+               return error(_("failed to resolve '%s' as a valid ref"),
                             replace_ref);
 
        return replace_object_oid(object_ref, &object, replace_ref, &repl, force);
@@ -222,7 +222,7 @@ static int export_object(const struct object_id *oid, enum object_type type,
 
        fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
        if (fd < 0)
-               return error_errno("unable to open %s for writing", filename);
+               return error_errno(_("unable to open %s for writing"), filename);
 
        argv_array_push(&cmd.args, "--no-replace-objects");
        argv_array_push(&cmd.args, "cat-file");
@@ -235,7 +235,7 @@ static int export_object(const struct object_id *oid, enum object_type type,
        cmd.out = fd;
 
        if (run_command(&cmd))
-               return error("cat-file reported failure");
+               return error(_("cat-file reported failure"));
        return 0;
 }
 
@@ -251,7 +251,7 @@ static int import_object(struct object_id *oid, enum object_type type,
 
        fd = open(filename, O_RDONLY);
        if (fd < 0)
-               return error_errno("unable to open %s for reading", filename);
+               return error_errno(_("unable to open %s for reading"), filename);
 
        if (!raw && type == OBJ_TREE) {
                const char *argv[] = { "mktree", NULL };
@@ -265,11 +265,11 @@ static int import_object(struct object_id *oid, enum object_type type,
 
                if (start_command(&cmd)) {
                        close(fd);
-                       return error("unable to spawn mktree");
+                       return error(_("unable to spawn mktree"));
                }
 
                if (strbuf_read(&result, cmd.out, 41) < 0) {
-                       error_errno("unable to read from mktree");
+                       error_errno(_("unable to read from mktree"));
                        close(fd);
                        close(cmd.out);
                        return -1;
@@ -278,11 +278,11 @@ static int import_object(struct object_id *oid, enum object_type type,
 
                if (finish_command(&cmd)) {
                        strbuf_release(&result);
-                       return error("mktree reported failure");
+                       return error(_("mktree reported failure"));
                }
                if (get_oid_hex(result.buf, oid) < 0) {
                        strbuf_release(&result);
-                       return error("mktree did not return an object name");
+                       return error(_("mktree did not return an object name"));
                }
 
                strbuf_release(&result);
@@ -291,12 +291,12 @@ static int import_object(struct object_id *oid, enum object_type type,
                int flags = HASH_FORMAT_CHECK | HASH_WRITE_OBJECT;
 
                if (fstat(fd, &st) < 0) {
-                       error_errno("unable to fstat %s", filename);
+                       error_errno(_("unable to fstat %s"), filename);
                        close(fd);
                        return -1;
                }
                if (index_fd(oid, fd, &st, type, NULL, flags) < 0)
-                       return error("unable to write object to database");
+                       return error(_("unable to write object to database"));
                /* index_fd close()s fd for us */
        }
 
@@ -315,11 +315,11 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
        struct strbuf ref = STRBUF_INIT;
 
        if (get_oid(object_ref, &old_oid) < 0)
-               return error("Not a valid object name: '%s'", object_ref);
+               return error(_("not a valid object name: '%s'"), object_ref);
 
        type = oid_object_info(the_repository, &old_oid, NULL);
        if (type < 0)
-               return error("unable to get object type for %s",
+               return error(_("unable to get object type for %s"),
                             oid_to_hex(&old_oid));
 
        if (check_ref_valid(&old_oid, &prev, &ref, force)) {
@@ -335,7 +335,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
        }
        if (launch_editor(tmpfile, NULL, NULL) < 0) {
                free(tmpfile);
-               return error("editing object file failed");
+               return error(_("editing object file failed"));
        }
        if (import_object(&new_oid, type, raw, tmpfile)) {
                free(tmpfile);
@@ -344,7 +344,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
        free(tmpfile);
 
        if (!oidcmp(&old_oid, &new_oid))
-               return error("new object is the same as the old one: '%s'", oid_to_hex(&old_oid));
+               return error(_("new object is the same as the old one: '%s'"), oid_to_hex(&old_oid));
 
        return replace_object_oid(object_ref, &old_oid, "replacement", &new_oid, force);
 }
@@ -368,10 +368,10 @@ static int replace_parents(struct strbuf *buf, int argc, const char **argv)
                struct object_id oid;
                if (get_oid(argv[i], &oid) < 0) {
                        strbuf_release(&new_parents);
-                       return error(_("Not a valid object name: '%s'"),
+                       return error(_("not a valid object name: '%s'"),
                                     argv[i]);
                }
-               if (!lookup_commit_reference(&oid)) {
+               if (!lookup_commit_reference(the_repository, &oid)) {
                        strbuf_release(&new_parents);
                        return error(_("could not parse %s"), argv[i]);
                }
@@ -402,17 +402,17 @@ static int check_one_mergetag(struct commit *commit,
        int i;
 
        hash_object_file(extra->value, extra->len, type_name(OBJ_TAG), &tag_oid);
-       tag = lookup_tag(&tag_oid);
+       tag = lookup_tag(the_repository, &tag_oid);
        if (!tag)
                return error(_("bad mergetag in commit '%s'"), ref);
-       if (parse_tag_buffer(tag, extra->value, extra->len))
+       if (parse_tag_buffer(the_repository, tag, extra->value, extra->len))
                return error(_("malformed mergetag in commit '%s'"), ref);
 
        /* iterate over new parents */
        for (i = 1; i < mergetag_data->argc; i++) {
                struct object_id oid;
                if (get_oid(mergetag_data->argv[i], &oid) < 0)
-                       return error(_("Not a valid object name: '%s'"),
+                       return error(_("not a valid object name: '%s'"),
                                     mergetag_data->argv[i]);
                if (!oidcmp(&tag->tagged->oid, &oid))
                        return 0; /* found */
@@ -442,8 +442,8 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
        unsigned long size;
 
        if (get_oid(old_ref, &old_oid) < 0)
-               return error(_("Not a valid object name: '%s'"), old_ref);
-       commit = lookup_commit_reference(&old_oid);
+               return error(_("not a valid object name: '%s'"), old_ref);
+       commit = lookup_commit_reference(the_repository, &old_oid);
        if (!commit)
                return error(_("could not parse %s"), old_ref);
 
@@ -457,7 +457,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
        }
 
        if (remove_signature(&buf)) {
-               warning(_("the original commit '%s' has a gpg signature."), old_ref);
+               warning(_("the original commit '%s' has a gpg signature"), old_ref);
                warning(_("the signature will be removed in the replacement commit!"));
        }
 
@@ -476,10 +476,10 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
 
        if (!oidcmp(&old_oid, &new_oid)) {
                if (gentle) {
-                       warning("graft for '%s' unnecessary", oid_to_hex(&old_oid));
+                       warning(_("graft for '%s' unnecessary"), oid_to_hex(&old_oid));
                        return 0;
                }
-               return error("new commit is the same as the old one: '%s'", oid_to_hex(&old_oid));
+               return error(_("new commit is the same as the old one: '%s'"), oid_to_hex(&old_oid));
        }
 
        return replace_object_oid(old_ref, &old_oid, "replacement", &new_oid, force);
@@ -487,7 +487,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
 
 static int convert_graft_file(int force)
 {
-       const char *graft_file = get_graft_file();
+       const char *graft_file = get_graft_file(the_repository);
        FILE *fp = fopen_or_warn(graft_file, "r");
        struct strbuf buf = STRBUF_INIT, err = STRBUF_INIT;
        struct argv_array args = ARGV_ARRAY_INIT;
@@ -544,7 +544,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
                OPT_END()
        };
 
-       check_replace_refs = 0;
+       read_replace_refs = 0;
        git_config(git_default_config, NULL);
 
        argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
@@ -553,7 +553,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
                cmdmode = argc ? MODE_REPLACE : MODE_LIST;
 
        if (format && cmdmode != MODE_LIST)
-               usage_msg_opt("--format cannot be used when not listing",
+               usage_msg_opt(_("--format cannot be used when not listing"),
                              git_replace_usage, options);
 
        if (force &&
@@ -561,47 +561,47 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
            cmdmode != MODE_EDIT &&
            cmdmode != MODE_GRAFT &&
            cmdmode != MODE_CONVERT_GRAFT_FILE)
-               usage_msg_opt("-f only makes sense when writing a replacement",
+               usage_msg_opt(_("-f only makes sense when writing a replacement"),
                              git_replace_usage, options);
 
        if (raw && cmdmode != MODE_EDIT)
-               usage_msg_opt("--raw only makes sense with --edit",
+               usage_msg_opt(_("--raw only makes sense with --edit"),
                              git_replace_usage, options);
 
        switch (cmdmode) {
        case MODE_DELETE:
                if (argc < 1)
-                       usage_msg_opt("-d needs at least one argument",
+                       usage_msg_opt(_("-d needs at least one argument"),
                                      git_replace_usage, options);
                return for_each_replace_name(argv, delete_replace_ref);
 
        case MODE_REPLACE:
                if (argc != 2)
-                       usage_msg_opt("bad number of arguments",
+                       usage_msg_opt(_("bad number of arguments"),
                                      git_replace_usage, options);
                return replace_object(argv[0], argv[1], force);
 
        case MODE_EDIT:
                if (argc != 1)
-                       usage_msg_opt("-e needs exactly one argument",
+                       usage_msg_opt(_("-e needs exactly one argument"),
                                      git_replace_usage, options);
                return edit_and_replace(argv[0], force, raw);
 
        case MODE_GRAFT:
                if (argc < 1)
-                       usage_msg_opt("-g needs at least one argument",
+                       usage_msg_opt(_("-g needs at least one argument"),
                                      git_replace_usage, options);
                return create_graft(argc, argv, force, 0);
 
        case MODE_CONVERT_GRAFT_FILE:
                if (argc != 0)
-                       usage_msg_opt("--convert-graft-file takes no argument",
+                       usage_msg_opt(_("--convert-graft-file takes no argument"),
                                      git_replace_usage, options);
                return !!convert_graft_file(force);
 
        case MODE_LIST:
                if (argc > 1)
-                       usage_msg_opt("only one pattern can be given with -l",
+                       usage_msg_opt(_("only one pattern can be given with -l"),
                                      git_replace_usage, options);
                return list_replace_refs(argv[0], format);
 
index a862c70fab99290b5faf3e700e88194589583329..11cd0dcb8cc73ac753b7ed746e194ba1458742ee 100644 (file)
@@ -39,7 +39,7 @@ static const char *reset_type_names[] = {
 
 static inline int is_merge(void)
 {
-       return !access(git_path_merge_head(), F_OK);
+       return !access(git_path_merge_head(the_repository), F_OK);
 }
 
 static int reset_index(const struct object_id *oid, int reset_type, int quiet)
@@ -134,7 +134,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
                        continue;
                }
 
-               ce = make_cache_entry(one->mode, one->oid.hash, one->path,
+               ce = make_cache_entry(&the_index, one->mode, &one->oid, one->path,
                                      0, 0);
                if (!ce)
                        die(_("make_cache_entry failed for path '%s'"),
@@ -319,7 +319,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                struct commit *commit;
                if (get_oid_committish(rev, &oid))
                        die(_("Failed to resolve '%s' as a valid revision."), rev);
-               commit = lookup_commit_reference(&oid);
+               commit = lookup_commit_reference(the_repository, &oid);
                if (!commit)
                        die(_("Could not parse object '%s'."), rev);
                oidcpy(&oid, &commit->object.oid);
@@ -396,7 +396,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                update_ref_status = reset_refs(rev, &oid);
 
                if (reset_type == HARD && !update_ref_status && !quiet)
-                       print_new_head_line(lookup_commit_reference(&oid));
+                       print_new_head_line(lookup_commit_reference(the_repository, &oid));
        }
        if (!pathspec.nr)
                remove_branch_state();
index fadd3ec14cbf0469c332a85278e5d1b4932ef788..5b07f3f4a2cf6cd5f73f20a930934ca2277c8391 100644 (file)
@@ -6,6 +6,7 @@
 #include "list-objects.h"
 #include "list-objects-filter.h"
 #include "list-objects-filter-options.h"
+#include "object-store.h"
 #include "pack.h"
 #include "pack-bitmap.h"
 #include "builtin.h"
@@ -16,6 +17,7 @@
 #include "reflog-walk.h"
 #include "oidset.h"
 #include "packfile.h"
+#include "object-store.h"
 
 static const char rev_list_usage[] =
 "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@ -238,7 +240,7 @@ static int finish_object(struct object *obj, const char *name, void *cb_data)
                return 1;
        }
        if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
-               parse_object(&obj->oid);
+               parse_object(the_repository, &obj->oid);
        return 0;
 }
 
@@ -514,17 +516,21 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
                if (revs.count && !revs.left_right && !revs.cherry_mark) {
                        uint32_t commit_count;
                        int max_count = revs.max_count;
-                       if (!prepare_bitmap_walk(&revs)) {
-                               count_bitmap_commit_list(&commit_count, NULL, NULL, NULL);
+                       struct bitmap_index *bitmap_git;
+                       if ((bitmap_git = prepare_bitmap_walk(&revs))) {
+                               count_bitmap_commit_list(bitmap_git, &commit_count, NULL, NULL, NULL);
                                if (max_count >= 0 && max_count < commit_count)
                                        commit_count = max_count;
                                printf("%d\n", commit_count);
+                               free_bitmap_index(bitmap_git);
                                return 0;
                        }
                } else if (revs.max_count < 0 &&
                           revs.tag_objects && revs.tree_objects && revs.blob_objects) {
-                       if (!prepare_bitmap_walk(&revs)) {
-                               traverse_bitmap_commit_list(&show_object_fast);
+                       struct bitmap_index *bitmap_git;
+                       if ((bitmap_git = prepare_bitmap_walk(&revs))) {
+                               traverse_bitmap_commit_list(bitmap_git, &show_object_fast);
+                               free_bitmap_index(bitmap_git);
                                return 0;
                        }
                }
index 4f49e96bfd0166aeb6f9875a688ff0dd83d631b5..0f09bbbf65a4bc8d6d064a985181ac547d9ee411 100644 (file)
@@ -280,8 +280,8 @@ static int try_difference(const char *arg)
                if (symmetric) {
                        struct commit_list *exclude;
                        struct commit *a, *b;
-                       a = lookup_commit_reference(&start_oid);
-                       b = lookup_commit_reference(&end_oid);
+                       a = lookup_commit_reference(the_repository, &start_oid);
+                       b = lookup_commit_reference(the_repository, &end_oid);
                        if (!a || !b) {
                                *dotdot = '.';
                                return 0;
@@ -333,7 +333,7 @@ static int try_parent_shorthands(const char *arg)
 
        *dotdot = 0;
        if (get_oid_committish(arg, &oid) ||
-           !(commit = lookup_commit_reference(&oid))) {
+           !(commit = lookup_commit_reference(the_repository, &oid))) {
                *dotdot = '^';
                return 0;
        }
@@ -883,7 +883,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                continue;
                        }
                        if (!strcmp(arg, "--is-shallow-repository")) {
-                               printf("%s\n", is_repository_shallow() ? "true"
+                               printf("%s\n",
+                                               is_repository_shallow(the_repository) ? "true"
                                                : "false");
                                continue;
                        }
index 65b448ef8ee91079194841762d4b7a2193eec9a9..2cbe89e0ae3b7a4801ac27d25fd37306813104ba 100644 (file)
@@ -278,14 +278,14 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 
        for (i = 0; i < active_nr; i++) {
                const struct cache_entry *ce = active_cache[i];
-               if (!ce_path_match(ce, &pathspec, seen))
+               if (!ce_path_match(&the_index, ce, &pathspec, seen))
                        continue;
                ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
                list.entry[list.nr].name = xstrdup(ce->name);
                list.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode);
                if (list.entry[list.nr++].is_submodule &&
                    !is_staging_gitmodules_ok(&the_index))
-                       die (_("Please stage your changes to .gitmodules or stash them to proceed"));
+                       die(_("please stage your changes to .gitmodules or stash them to proceed"));
        }
 
        if (pathspec.nr) {
index 42fd8d1a3528c3ea0b30007407b2ae38f240f4c7..724b4848508d67b3693edf458033e7e29a92b3d3 100644 (file)
@@ -178,7 +178,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
                OPT_BOOL(0, "stdin", &from_stdin, N_("read refs from stdin")),
                OPT_BOOL(0, "helper-status", &helper_status, N_("print status from remote helper")),
                { OPTION_CALLBACK,
-                 0, CAS_OPT_NAME, &cas, N_("refname>:<expect"),
+                 0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
                  N_("require old value of ref to be at this value"),
                  PARSE_OPT_OPTARG, parseopt_push_cas_option },
                OPT_END()
index 608d6ba77bdfb4673513444651053d0e8e789020..3898a2c9c428864caf43b0f8160a441488643e29 100644 (file)
@@ -268,8 +268,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
                         N_("Suppress commit descriptions, only provides commit count")),
                OPT_BOOL('e', "email", &log.email,
                         N_("Show the email address of each author")),
-               { OPTION_CALLBACK, 'w', NULL, &log, N_("w[,i1[,i2]]"),
-                       N_("Linewrap output"), PARSE_OPT_OPTARG, &parse_wrap_args },
+               { OPTION_CALLBACK, 'w', NULL, &log, N_("<w>[,<i1>[,<i2>]]"),
+                       N_("Linewrap output"), PARSE_OPT_OPTARG,
+                       &parse_wrap_args },
                OPT_END(),
        };
 
index f2e985c00abd2e6f7aa1eaa1c9368f4c3ada60ab..363cf8509af5bf640da60c36118b841da06918fe 100644 (file)
@@ -378,7 +378,8 @@ static void sort_ref_range(int bottom, int top)
 static int append_ref(const char *refname, const struct object_id *oid,
                      int allow_dups)
 {
-       struct commit *commit = lookup_commit_reference_gently(oid, 1);
+       struct commit *commit = lookup_commit_reference_gently(the_repository,
+                                                              oid, 1);
        int i;
 
        if (!commit)
@@ -673,7 +674,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                { OPTION_CALLBACK, 'g', "reflog", &reflog_base, N_("<n>[,<base>]"),
                            N_("show <n> most recent ref-log entries starting at "
                               "base"),
-                           PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP,
+                           PARSE_OPT_OPTARG,
                            parse_reflog_param },
                OPT_END()
        };
@@ -830,7 +831,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                               MAX_REVS), MAX_REVS);
                if (get_oid(ref_name[num_rev], &revkey))
                        die(_("'%s' is not a valid ref."), ref_name[num_rev]);
-               commit = lookup_commit_reference(&revkey);
+               commit = lookup_commit_reference(the_repository, &revkey);
                if (!commit)
                        die(_("cannot find commit %s (%s)"),
                            ref_name[num_rev], oid_to_hex(&revkey));
index f2eb1a7724058bb1db237a6199d16e5ff1ef495a..2f13f1316fadc2fc860fac75a161b47f7d11e391 100644 (file)
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "refs.h"
+#include "object-store.h"
 #include "object.h"
 #include "tag.h"
 #include "string-list.h"
index 20ae9191ca376841ca2540502d85a3dc150d3417..a4440a31094323581c696f4eb7b9048b02d3462e 100644 (file)
@@ -331,7 +331,7 @@ static int module_list_compute(int argc, const char **argv,
        for (i = 0; i < active_nr; i++) {
                const struct cache_entry *ce = active_cache[i];
 
-               if (!match_pathspec(pathspec, ce->name, ce_namelen(ce),
+               if (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),
                                    0, ps_matched, 1) ||
                    !S_ISGITLINK(ce->ce_mode))
                        continue;
@@ -1124,6 +1124,8 @@ static void deinit_submodule(const char *path, const char *prefix,
                if (!(flags & OPT_QUIET))
                        printf(format, displaypath);
 
+               submodule_unset_core_worktree(sub);
+
                strbuf_release(&sb_rm);
        }
 
@@ -1706,8 +1708,8 @@ static int update_clone_task_finished(int result,
        return 0;
 }
 
-static int gitmodules_update_clone_config(const char *var, const char *value,
-                                         void *cb)
+static int git_update_clone_config(const char *var, const char *value,
+                                  void *cb)
 {
        int *max_jobs = cb;
        if (!strcmp(var, "submodule.fetchjobs"))
@@ -1757,8 +1759,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
        };
        suc.prefix = prefix;
 
-       config_from_gitmodules(gitmodules_update_clone_config, &max_jobs);
-       git_config(gitmodules_update_clone_config, &max_jobs);
+       update_clone_config_from_gitmodules(&max_jobs);
+       git_config(git_update_clone_config, &max_jobs);
 
        argc = parse_options(argc, argv, prefix, module_update_clone_options,
                             git_submodule_helper_usage, 0);
@@ -2004,6 +2006,29 @@ static int check_name(int argc, const char **argv, const char *prefix)
        return 0;
 }
 
+static int connect_gitdir_workingtree(int argc, const char **argv, const char *prefix)
+{
+       struct strbuf sb = STRBUF_INIT;
+       const char *name, *path;
+       char *sm_gitdir;
+
+       if (argc != 3)
+               BUG("submodule--helper connect-gitdir-workingtree <name> <path>");
+
+       name = argv[1];
+       path = argv[2];
+
+       strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
+       sm_gitdir = absolute_pathdup(sb.buf);
+
+       connect_work_tree_and_git_dir(path, sm_gitdir, 0);
+
+       strbuf_release(&sb);
+       free(sm_gitdir);
+
+       return 0;
+}
+
 #define SUPPORT_SUPER_PREFIX (1<<0)
 
 struct cmd_struct {
@@ -2017,6 +2042,7 @@ static struct cmd_struct commands[] = {
        {"name", module_name, 0},
        {"clone", module_clone, 0},
        {"update-clone", update_clone, 0},
+       {"connect-gitdir-workingtree", connect_gitdir_workingtree, 0},
        {"relative-path", resolve_relative_path, 0},
        {"resolve-relative-url", resolve_relative_url, 0},
        {"resolve-relative-url-test", resolve_relative_url_test, 0},
index 5d0dd112408419a0090cbe179d69c0ea709f22a7..9a19ffb49f68d7c0318f650d34d0edbcd6db81d3 100644 (file)
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "refs.h"
+#include "object-store.h"
 #include "tag.h"
 #include "run-command.h"
 #include "parse-options.h"
@@ -312,7 +313,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
                }
                free(buf);
 
-               if ((c = lookup_commit_reference(oid)) != NULL)
+               if ((c = lookup_commit_reference(the_repository, oid)) != NULL)
                        strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT)));
                break;
        case OBJ_TREE:
index 300eb59657e29cace38798029a9170834cac7c9e..58652229f273bf93e55b0ff5eef1421096cfe719 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "object-store.h"
 
 static char *create_temp_file(struct object_id *oid)
 {
index 6e81ca8ca28a67ce3d7bc0d62556fd41eda2ba52..30d9413b4bfb95ad1ee774430b8f954699e46d74 100644 (file)
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "object.h"
 #include "delta.h"
 #include "pack.h"
@@ -253,7 +254,7 @@ static void write_object(unsigned nr, enum object_type type,
                added_object(nr, type, buf, size);
                free(buf);
 
-               blob = lookup_blob(&obj_list[nr].oid);
+               blob = lookup_blob(the_repository, &obj_list[nr].oid);
                if (blob)
                        blob->object.flags |= FLAG_WRITTEN;
                else
@@ -264,7 +265,8 @@ static void write_object(unsigned nr, enum object_type type,
                int eaten;
                hash_object_file(buf, size, type_name(type), &obj_list[nr].oid);
                added_object(nr, type, buf, size);
-               obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf,
+               obj = parse_object_buffer(the_repository, &obj_list[nr].oid,
+                                         type, size, buf,
                                          &eaten);
                if (!obj)
                        die("invalid %s", type_name(type));
@@ -330,7 +332,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,
 {
        struct object *obj;
        struct obj_buffer *obj_buffer;
-       obj = lookup_object(base->hash);
+       obj = lookup_object(the_repository, base->hash);
        if (!obj)
                return 0;
        obj_buffer = lookup_object_buffer(obj);
@@ -512,7 +514,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
        int i;
        struct object_id oid;
 
-       check_replace_refs = 0;
+       read_replace_refs = 0;
 
        git_config(git_default_config, NULL);
 
index a8709a26ec4b8bb79cbb20bfa4a7892e063c804d..fe84003b4fa05c377bb4ab1de04a7cd1c9ae4d5d 100644 (file)
@@ -268,15 +268,14 @@ static int process_lstat_error(const char *path, int err)
 
 static int add_one_path(const struct cache_entry *old, const char *path, int len, struct stat *st)
 {
-       int option, size;
+       int option;
        struct cache_entry *ce;
 
        /* Was the old index entry already up-to-date? */
        if (old && !ce_stage(old) && !ce_match_stat(old, st, 0))
                return 0;
 
-       size = cache_entry_size(len);
-       ce = xcalloc(1, size);
+       ce = make_empty_cache_entry(&the_index, len);
        memcpy(ce->name, path, len);
        ce->ce_flags = create_ce_flags(0);
        ce->ce_namelen = len;
@@ -285,13 +284,13 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
 
        if (index_path(&ce->oid, path, st,
                       info_only ? 0 : HASH_WRITE_OBJECT)) {
-               free(ce);
+               discard_cache_entry(ce);
                return -1;
        }
        option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
        option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
        if (add_cache_entry(ce, option)) {
-               free(ce);
+               discard_cache_entry(ce);
                return error("%s: cannot add to the index - missing --add option?", path);
        }
        return 0;
@@ -402,15 +401,14 @@ static int process_path(const char *path, struct stat *st, int stat_errno)
 static int add_cacheinfo(unsigned int mode, const struct object_id *oid,
                         const char *path, int stage)
 {
-       int size, len, option;
+       int len, option;
        struct cache_entry *ce;
 
        if (!verify_path(path, mode))
                return error("Invalid path '%s'", path);
 
        len = strlen(path);
-       size = cache_entry_size(len);
-       ce = xcalloc(1, size);
+       ce = make_empty_cache_entry(&the_index, len);
 
        oidcpy(&ce->oid, oid);
        memcpy(ce->name, path, len);
@@ -492,6 +490,7 @@ static void update_one(const char *path)
 
 static void read_index_info(int nul_term_line)
 {
+       const int hexsz = the_hash_algo->hexsz;
        struct strbuf buf = STRBUF_INIT;
        struct strbuf uq = STRBUF_INIT;
        strbuf_getline_fn getline_fn;
@@ -529,7 +528,7 @@ static void read_index_info(int nul_term_line)
                mode = ul;
 
                tab = strchr(ptr, '\t');
-               if (!tab || tab - ptr < GIT_SHA1_HEXSZ + 1)
+               if (!tab || tab - ptr < hexsz + 1)
                        goto bad_line;
 
                if (tab[-2] == ' ' && '0' <= tab[-1] && tab[-1] <= '3') {
@@ -542,8 +541,8 @@ static void read_index_info(int nul_term_line)
                        ptr = tab + 1; /* point at the head of path */
                }
 
-               if (get_oid_hex(tab - GIT_SHA1_HEXSZ, &oid) ||
-                       tab[-(GIT_SHA1_HEXSZ + 1)] != ' ')
+               if (get_oid_hex(tab - hexsz, &oid) ||
+                       tab[-(hexsz + 1)] != ' ')
                        goto bad_line;
 
                path_name = ptr;
@@ -571,7 +570,7 @@ static void read_index_info(int nul_term_line)
                         * ptr[-1] points at tab,
                         * ptr[-41] is at the beginning of sha1
                         */
-                       ptr[-(GIT_SHA1_HEXSZ + 2)] = ptr[-1] = 0;
+                       ptr[-(hexsz + 2)] = ptr[-1] = 0;
                        if (add_cacheinfo(mode, &oid, path_name, stage))
                                die("git update-index: unable to update %s",
                                    path_name);
@@ -599,7 +598,6 @@ static struct cache_entry *read_one_ent(const char *which,
 {
        unsigned mode;
        struct object_id oid;
-       int size;
        struct cache_entry *ce;
 
        if (get_tree_entry(ent, path, &oid, &mode)) {
@@ -612,8 +610,7 @@ static struct cache_entry *read_one_ent(const char *which,
                        error("%s: not a blob in %s branch.", path, which);
                return NULL;
        }
-       size = cache_entry_size(namelen);
-       ce = xcalloc(1, size);
+       ce = make_empty_cache_entry(&the_index, namelen);
 
        oidcpy(&ce->oid, &oid);
        memcpy(ce->name, path, namelen);
@@ -690,8 +687,8 @@ static int unresolve_one(const char *path)
        error("%s: cannot add their version to the index.", path);
        ret = -1;
  free_return:
-       free(ce_2);
-       free(ce_3);
+       discard_cache_entry(ce_2);
+       discard_cache_entry(ce_3);
        return ret;
 }
 
@@ -751,14 +748,14 @@ static int do_reupdate(int ac, const char **av,
                int save_nr;
                char *path;
 
-               if (ce_stage(ce) || !ce_path_match(ce, &pathspec, NULL))
+               if (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL))
                        continue;
                if (has_head)
                        old = read_one_ent(NULL, &head_oid,
                                           ce->name, ce_namelen(ce), 0);
                if (old && ce->ce_mode == old->ce_mode &&
                    !oidcmp(&ce->oid, &old->oid)) {
-                       free(old);
+                       discard_cache_entry(old);
                        continue; /* unchanged */
                }
                /* Be careful.  The working tree may not have the
@@ -769,7 +766,7 @@ static int do_reupdate(int ac, const char **av,
                path = xstrdup(ce->name);
                update_one(path);
                free(path);
-               free(old);
+               discard_cache_entry(old);
                if (save_nr != active_nr)
                        goto redo;
        }
@@ -826,6 +823,7 @@ static int parse_new_style_cacheinfo(const char *arg,
 {
        unsigned long ul;
        char *endp;
+       const char *p;
 
        if (!arg)
                return -1;
@@ -836,9 +834,9 @@ static int parse_new_style_cacheinfo(const char *arg,
                return -1; /* not a new-style cacheinfo */
        *mode = ul;
        endp++;
-       if (get_oid_hex(endp, oid) || endp[GIT_SHA1_HEXSZ] != ',')
+       if (parse_oid_hex(endp, oid, &p) || *p != ',')
                return -1;
-       *path = endp + GIT_SHA1_HEXSZ + 1;
+       *path = p + 1;
        return 0;
 }
 
@@ -971,9 +969,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                        PARSE_OPT_NOARG | /* disallow --cacheinfo=<mode> form */
                        PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
                        (parse_opt_cb *) cacheinfo_callback},
-               {OPTION_CALLBACK, 0, "chmod", &set_executable_bit, N_("(+/-)x"),
+               {OPTION_CALLBACK, 0, "chmod", &set_executable_bit, "(+|-)x",
                        N_("override the executable bit of the listed files"),
-                       PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
+                       PARSE_OPT_NONEG,
                        chmod_callback},
                {OPTION_SET_INT, 0, "assume-unchanged", &mark_valid_only, NULL,
                        N_("mark files as \"not changing\""),
index 84532ae9a93e7fb526a6fd28901875b3a10f3ffa..25d91163563614110d2c93802ce3fef6d5844325 100644 (file)
@@ -43,7 +43,8 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
        }
 
        /* parse all options sent by the client */
-       return write_archive(sent_argv.argc, sent_argv.argv, prefix, NULL, 1);
+       return write_archive(sent_argv.argc, sent_argv.argv, prefix,
+                            the_repository, NULL, 1);
 }
 
 __attribute__((format (printf, 1, 2)))
index decde5a3b1b70442e1550027359dab11f4704468..42dc4da5a1fc047baa9f71288670c3b981cb3b7e 100644 (file)
@@ -31,7 +31,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
        };
 
        packet_trace_identity("upload-pack");
-       check_replace_refs = 0;
+       read_replace_refs = 0;
 
        argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0);
 
index dcdaada111071c84b56022d9050ae06ffafbc25f..7772c07ed7a1e13e3b6ecabc4642cefd6d16b333 100644 (file)
@@ -8,6 +8,8 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "run-command.h"
 #include <signal.h>
@@ -26,7 +28,8 @@ static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned
 
        memset(&signature_check, 0, sizeof(signature_check));
 
-       ret = check_commit_signature(lookup_commit(oid), &signature_check);
+       ret = check_commit_signature(lookup_commit(the_repository, oid),
+                                    &signature_check);
        print_signature_buffer(&signature_check, flags);
 
        signature_check_clear(&signature_check);
index 5c7d2bb1807f942139b3ec41b426320e4b0cfc2a..a763dbdccb490ab6707c247d618203ffd37d4052 100644 (file)
@@ -412,7 +412,7 @@ static const char *dwim_branch(const char *path, const char **new_branch)
        if (guess_remote) {
                struct object_id oid;
                const char *remote =
-                       unique_tracking_name(*new_branch, &oid);
+                       unique_tracking_name(*new_branch, &oid, NULL);
                return remote;
        }
        return NULL;
@@ -484,7 +484,7 @@ static int add(int ac, const char **av, const char *prefix)
 
                commit = lookup_commit_reference_by_name(branch);
                if (!commit) {
-                       remote = unique_tracking_name(branch, &oid);
+                       remote = unique_tracking_name(branch, &oid, NULL);
                        if (remote) {
                                new_branch = branch;
                                branch = remote;
index c9d3c544e79f46bab9e5fd50079d1bb574b722f2..cdcbf8264e8c6e9b56977b99ad28160754d8fb7c 100644 (file)
@@ -24,9 +24,8 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
        struct option write_tree_options[] = {
                OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
                        WRITE_TREE_MISSING_OK),
-               { OPTION_STRING, 0, "prefix", &prefix, N_("<prefix>/"),
-                 N_("write tree object for a subdirectory <prefix>") ,
-                 PARSE_OPT_LITERAL_ARGHELP },
+               OPT_STRING(0, "prefix", &prefix, N_("<prefix>/"),
+                          N_("write tree object for a subdirectory <prefix>")),
                { OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
                  N_("only useful for debugging"),
                  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
index b7e131c47a62603069185d67e5d2758175bc543f..9f3b644811cd79b2c93ebf1dcebd711640c18419 100644 (file)
@@ -8,6 +8,7 @@
 #include "pack.h"
 #include "strbuf.h"
 #include "packfile.h"
+#include "object-store.h"
 
 static struct bulk_checkin_state {
        unsigned plugged:1;
index 160bbfdc64ec2876bdc685d253bf537d1c739c1f..24cbe409863a83e8bda453af637c2237504a531d 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -1,6 +1,8 @@
 #include "cache.h"
 #include "lockfile.h"
 #include "bundle.h"
+#include "object-store.h"
+#include "repository.h"
 #include "object.h"
 #include "commit.h"
 #include "diff.h"
@@ -141,7 +143,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
        init_revisions(&revs, NULL);
        for (i = 0; i < p->nr; i++) {
                struct ref_list_entry *e = p->list + i;
-               struct object *o = parse_object(&e->oid);
+               struct object *o = parse_object(the_repository, &e->oid);
                if (o) {
                        o->flags |= PREREQ_MARK;
                        add_pending_object(&revs, o, e->name);
@@ -166,7 +168,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
 
        for (i = 0; i < p->nr; i++) {
                struct ref_list_entry *e = p->list + i;
-               struct object *o = parse_object(&e->oid);
+               struct object *o = parse_object(the_repository, &e->oid);
                assert(o); /* otherwise we'd have returned early */
                if (o->flags & SHOWN)
                        continue;
@@ -178,7 +180,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
        /* Clean up objects used, as they will be reused. */
        for (i = 0; i < p->nr; i++) {
                struct ref_list_entry *e = p->list + i;
-               commit = lookup_commit_reference_gently(&e->oid, 1);
+               commit = lookup_commit_reference_gently(the_repository, &e->oid, 1);
                if (commit)
                        clear_commit_marks(commit, ALL_REV_FLAGS);
        }
@@ -373,7 +375,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
                         * in terms of a tag (e.g. v2.0 from the range
                         * "v1.0..v2.0")?
                         */
-                       struct commit *one = lookup_commit_reference(&oid);
+                       struct commit *one = lookup_commit_reference(the_repository,
+                                                                    &oid);
                        struct object *obj;
 
                        if (e->item == &(one->object)) {
index 25663825b553b4e4590e3b4aaad54b4f5950aef8..16ea022c46d3b281d04a3956f865d8a886a5b714 100644 (file)
@@ -3,6 +3,7 @@
 #include "tree.h"
 #include "tree-walk.h"
 #include "cache-tree.h"
+#include "object-store.h"
 
 #ifndef DEBUG
 #define DEBUG 0
@@ -651,11 +652,6 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state,
        return ret;
 }
 
-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);
-}
-
 static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
 {
        struct tree_desc desc;
@@ -670,7 +666,8 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
                        cnt++;
                else {
                        struct cache_tree_sub *sub;
-                       struct tree *subtree = lookup_tree(entry.oid);
+                       struct tree *subtree = lookup_tree(the_repository,
+                                                          entry.oid);
                        if (!subtree->object.parsed)
                                parse_tree(subtree);
                        sub = cache_tree_sub(it, entry.path);
@@ -721,10 +718,3 @@ int cache_tree_matches_traversal(struct cache_tree *root,
                return it->entry_count;
        return 0;
 }
-
-int update_main_cache_tree(int flags)
-{
-       if (!the_index.cache_tree)
-               the_index.cache_tree = cache_tree();
-       return cache_tree_update(&the_index, flags);
-}
index cfd5328cc93694e23037e15148241e17bd4f3a04..fc0c842e773f648d64858d1891f64d222633fc3a 100644 (file)
@@ -33,8 +33,6 @@ struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
 int cache_tree_fully_valid(struct cache_tree *);
 int cache_tree_update(struct index_state *, int);
 
-int update_main_cache_tree(int);
-
 /* bitmasks to write_cache_as_tree flags */
 #define WRITE_TREE_MISSING_OK 1
 #define WRITE_TREE_IGNORE_CACHE_TREE 2
@@ -48,9 +46,22 @@ int update_main_cache_tree(int);
 #define WRITE_TREE_PREFIX_ERROR (-3)
 
 int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix);
-int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix);
 void prime_cache_tree(struct index_state *, struct tree *);
 
-extern int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
+int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
+
+#ifndef NO_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);
+}
+
+static inline int update_main_cache_tree(int flags)
+{
+       if (!the_index.cache_tree)
+               the_index.cache_tree = cache_tree();
+       return cache_tree_update(&the_index, flags);
+}
+#endif
 
 #endif
diff --git a/cache.h b/cache.h
index d49092d94d1970cc7e07ade8064793fa64d8f362..66d3b91cdb1d14bbe2499f90a0e1f6d9785b4b37 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -15,6 +15,7 @@
 #include "path.h"
 #include "sha1-array.h"
 #include "repository.h"
+#include "mem-pool.h"
 
 #include <zlib.h>
 typedef struct git_zstream {
@@ -156,6 +157,7 @@ struct cache_entry {
        struct stat_data ce_stat_data;
        unsigned int ce_mode;
        unsigned int ce_flags;
+       unsigned int mem_pool_allocated;
        unsigned int ce_namelen;
        unsigned int index;     /* for link extension */
        struct object_id oid;
@@ -218,6 +220,7 @@ struct cache_entry {
 /* Forward structure decls */
 struct pathspec;
 struct child_process;
+struct tree;
 
 /*
  * Copy the sha1 and stat state of a cache entry from one to
@@ -227,6 +230,7 @@ static inline void copy_cache_entry(struct cache_entry *dst,
                                    const struct cache_entry *src)
 {
        unsigned int state = dst->ce_flags & CE_HASHED;
+       int mem_pool_allocated = dst->mem_pool_allocated;
 
        /* Don't copy hash chain and name */
        memcpy(&dst->ce_stat_data, &src->ce_stat_data,
@@ -235,6 +239,9 @@ static inline void copy_cache_entry(struct cache_entry *dst,
 
        /* Restore the hash state */
        dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state;
+
+       /* Restore the mem_pool_allocated flag */
+       dst->mem_pool_allocated = mem_pool_allocated;
 }
 
 static inline unsigned create_ce_flags(unsigned stage)
@@ -328,6 +335,7 @@ struct index_state {
        struct untracked_cache *untracked;
        uint64_t fsmonitor_last_update;
        struct ewah_bitmap *fsmonitor_dirty;
+       struct mem_pool *ce_mem_pool;
 };
 
 extern struct index_state the_index;
@@ -339,6 +347,60 @@ extern void remove_name_hash(struct index_state *istate, struct cache_entry *ce)
 extern void free_name_hash(struct index_state *istate);
 
 
+/* Cache entry creation and cleanup */
+
+/*
+ * Create cache_entry intended for use in the specified index. Caller
+ * is responsible for discarding the cache_entry with
+ * `discard_cache_entry`.
+ */
+struct cache_entry *make_cache_entry(struct index_state *istate,
+                                    unsigned int mode,
+                                    const struct object_id *oid,
+                                    const char *path,
+                                    int stage,
+                                    unsigned int refresh_options);
+
+struct cache_entry *make_empty_cache_entry(struct index_state *istate,
+                                          size_t name_len);
+
+/*
+ * Create a cache_entry that is not intended to be added to an index.
+ * Caller is responsible for discarding the cache_entry
+ * with `discard_cache_entry`.
+ */
+struct cache_entry *make_transient_cache_entry(unsigned int mode,
+                                              const struct object_id *oid,
+                                              const char *path,
+                                              int stage);
+
+struct cache_entry *make_empty_transient_cache_entry(size_t name_len);
+
+/*
+ * Discard cache entry.
+ */
+void discard_cache_entry(struct cache_entry *ce);
+
+/*
+ * Check configuration if we should perform extra validation on cache
+ * entries.
+ */
+int should_validate_cache_entries(void);
+
+/*
+ * Duplicate a cache_entry. Allocate memory for the new entry from a
+ * memory_pool. Takes into account cache_entry fields that are meant
+ * for managing the underlying memory allocation of the cache_entry.
+ */
+struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_state *istate);
+
+/*
+ * Validate the cache entries in the index.  This is an internal
+ * consistency check that the cache_entry structs are allocated from
+ * the expected memory pool.
+ */
+void validate_cache_entries(const struct index_state *istate);
+
 #ifndef NO_THE_INDEX_COMPATIBILITY_MACROS
 #define active_cache (the_index.cache)
 #define active_nr (the_index.cache_nr)
@@ -484,7 +546,7 @@ extern const char *get_git_dir(void);
 extern const char *get_git_common_dir(void);
 extern char *get_object_directory(void);
 extern char *get_index_file(void);
-extern char *get_graft_file(void);
+extern char *get_graft_file(struct repository *r);
 extern void set_git_dir(const char *path);
 extern int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
 extern int get_common_dir(struct strbuf *sb, const char *gitdir);
@@ -635,12 +697,15 @@ extern void move_index_extensions(struct index_state *dst, struct index_state *s
 extern int unmerged_index(const struct index_state *);
 
 /**
- * Returns 1 if the index differs from HEAD, 0 otherwise. When on an unborn
- * branch, returns 1 if there are entries in the index, 0 otherwise. If an
- * strbuf is provided, the space-separated list of files that differ will be
- * appended to it.
+ * Returns 1 if istate differs from tree, 0 otherwise.  If tree is NULL,
+ * compares istate to HEAD.  If tree is NULL and on an unborn branch,
+ * returns 1 if there are entries in istate, 0 otherwise.  If an strbuf is
+ * provided, the space-separated list of files that differ will be appended
+ * to it.
  */
-extern int index_has_changes(struct strbuf *sb);
+extern int index_has_changes(const struct index_state *istate,
+                            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);
@@ -698,7 +763,6 @@ extern int remove_file_from_index(struct index_state *, const char *path);
 extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
 extern int add_file_to_index(struct index_state *, const char *path, int flags);
 
-extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options);
 extern int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip);
 extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
 extern void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
@@ -751,7 +815,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
 #define REFRESH_IGNORE_SUBMODULES      0x0010  /* ignore submodules */
 #define REFRESH_IN_PORCELAIN   0x0020  /* user friendly output, not "needs update" */
 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 cache_entry *, unsigned int);
+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.
@@ -804,16 +868,13 @@ void reset_shared_repository(void);
  * Do replace refs need to be checked this run?  This variable is
  * initialized to true unless --no-replace-object is used or
  * $GIT_NO_REPLACE_OBJECTS is set, but is set to false by some
- * commands that do not want replace references to be active.  As an
- * optimization it is also set to false if replace references have
- * been sought but there were none.
+ * commands that do not want replace references to be active.
  */
-extern int check_replace_refs;
+extern int read_replace_refs;
 extern char *git_replace_ref_base;
 
 extern int fsync_object_files;
 extern int core_preload_index;
-extern int core_commit_graph;
 extern int core_apply_sparse_checkout;
 extern int precomposed_unicode;
 extern int protect_hfs;
@@ -972,7 +1033,7 @@ extern const struct object_id null_oid;
 
 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
 {
-       return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
+       return memcmp(sha1, sha2, the_hash_algo->rawsz);
 }
 
 static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
@@ -992,7 +1053,7 @@ static inline int is_null_oid(const struct object_id *oid)
 
 static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
 {
-       memcpy(sha_dst, sha_src, GIT_SHA1_RAWSZ);
+       memcpy(sha_dst, sha_src, the_hash_algo->rawsz);
 }
 
 static inline void oidcpy(struct object_id *dst, const struct object_id *src)
@@ -1009,7 +1070,7 @@ static inline struct object_id *oiddup(const struct object_id *src)
 
 static inline void hashclr(unsigned char *hash)
 {
-       memset(hash, 0, GIT_SHA1_RAWSZ);
+       memset(hash, 0, the_hash_algo->rawsz);
 }
 
 static inline void oidclr(struct object_id *oid)
@@ -1192,32 +1253,6 @@ extern char *xdg_config_home(const char *filename);
  */
 extern char *xdg_cache_home(const char *filename);
 
-extern void *read_object_file_extended(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)
-{
-       return read_object_file_extended(oid, type, size, 1);
-}
-
-/* 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 *);
-
-extern int hash_object_file(const void *buf, unsigned long len,
-                           const char *type, struct object_id *oid);
-
-extern int write_object_file(const void *buf, unsigned long len,
-                            const char *type, struct object_id *oid);
-
-extern int hash_object_file_literally(const void *buf, unsigned long len,
-                                     const char *type, struct object_id *oid,
-                                     unsigned flags);
-
-extern int pretend_object_file(void *, unsigned long, enum object_type,
-                              struct object_id *oid);
-
-extern int force_object_loose(const struct object_id *oid, time_t mtime);
-
 extern int git_open_cloexec(const char *name, int flags);
 #define git_open(name) git_open_cloexec(name, O_RDONLY)
 extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
@@ -1227,43 +1262,6 @@ extern int check_object_signature(const struct object_id *oid, void *buf, unsign
 
 extern int finalize_object_file(const char *tmpfile, const char *filename);
 
-/*
- * Open the loose object at path, check its hash, and return the contents,
- * type, and size. If the object is a blob, then "contents" may return NULL,
- * to allow streaming of large blobs.
- *
- * Returns 0 on success, negative on error (details may be written to stderr).
- */
-int read_loose_object(const char *path,
-                     const struct object_id *expected_oid,
-                     enum object_type *type,
-                     unsigned long *size,
-                     void **contents);
-
-/*
- * Convenience for sha1_object_info_extended() with a NULL struct
- * 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)
-{
-       return has_sha1_file_with_flags(sha1, 0);
-}
-
-/* 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);
-
-/*
- * Return true iff an alternate object database has a loose object
- * with the specified name.  This function does not respect replace
- * references.
- */
-extern int has_loose_object_nonlocal(const struct object_id *oid);
-
-extern void assert_oid_type(const struct object_id *oid, enum object_type expect);
-
 /* Helper to check and "touch" a file */
 extern int check_and_freshen_file(const char *fn, int freshen);
 
@@ -1425,18 +1423,20 @@ extern void *read_object_with_reference(const struct object_id *oid,
 extern struct object *peel_to_type(const char *name, int namelen,
                                   struct object *o, enum object_type);
 
+enum date_mode_type {
+       DATE_NORMAL = 0,
+       DATE_RELATIVE,
+       DATE_SHORT,
+       DATE_ISO8601,
+       DATE_ISO8601_STRICT,
+       DATE_RFC2822,
+       DATE_STRFTIME,
+       DATE_RAW,
+       DATE_UNIX
+};
+
 struct date_mode {
-       enum date_mode_type {
-               DATE_NORMAL = 0,
-               DATE_RELATIVE,
-               DATE_SHORT,
-               DATE_ISO8601,
-               DATE_ISO8601_STRICT,
-               DATE_RFC2822,
-               DATE_STRFTIME,
-               DATE_RAW,
-               DATE_UNIX
-       } type;
+       enum date_mode_type type;
        const char *strftime_fmt;
        int local;
 };
@@ -1575,116 +1575,6 @@ extern int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
  */
 extern int odb_pack_keep(const char *name);
 
-/*
- * Iterate over the files in the loose-object parts of the object
- * directory "path", triggering the following callbacks:
- *
- *  - loose_object is called for each loose object we find.
- *
- *  - loose_cruft is called for any files that do not appear to be
- *    loose objects. Note that we only look in the loose object
- *    directories "objects/[0-9a-f]{2}/", so we will not report
- *    "objects/foobar" as cruft.
- *
- *  - loose_subdir is called for each top-level hashed subdirectory
- *    of the object directory (e.g., "$OBJDIR/f0"). It is called
- *    after the objects in the directory are processed.
- *
- * Any callback that is NULL will be ignored. Callbacks returning non-zero
- * will end the iteration.
- *
- * In the "buf" variant, "path" is a strbuf which will also be used as a
- * scratch buffer, but restored to its original contents before
- * the function returns.
- */
-typedef int each_loose_object_fn(const struct object_id *oid,
-                                const char *path,
-                                void *data);
-typedef int each_loose_cruft_fn(const char *basename,
-                               const char *path,
-                               void *data);
-typedef int each_loose_subdir_fn(unsigned int nr,
-                                const char *path,
-                                void *data);
-int for_each_file_in_obj_subdir(unsigned int subdir_nr,
-                               struct strbuf *path,
-                               each_loose_object_fn obj_cb,
-                               each_loose_cruft_fn cruft_cb,
-                               each_loose_subdir_fn subdir_cb,
-                               void *data);
-int for_each_loose_file_in_objdir(const char *path,
-                                 each_loose_object_fn obj_cb,
-                                 each_loose_cruft_fn cruft_cb,
-                                 each_loose_subdir_fn subdir_cb,
-                                 void *data);
-int for_each_loose_file_in_objdir_buf(struct strbuf *path,
-                                     each_loose_object_fn obj_cb,
-                                     each_loose_cruft_fn cruft_cb,
-                                     each_loose_subdir_fn subdir_cb,
-                                     void *data);
-
-/*
- * Iterate over loose objects in both the local
- * repository and any alternates repositories (unless the
- * LOCAL_ONLY flag is set).
- */
-#define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
-extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);
-
-struct object_info {
-       /* Request */
-       enum object_type *typep;
-       unsigned long *sizep;
-       off_t *disk_sizep;
-       unsigned char *delta_base_sha1;
-       struct strbuf *type_name;
-       void **contentp;
-
-       /* Response */
-       enum {
-               OI_CACHED,
-               OI_LOOSE,
-               OI_PACKED,
-               OI_DBCACHED
-       } whence;
-       union {
-               /*
-                * struct {
-                *      ... Nothing to expose in this case
-                * } cached;
-                * struct {
-                *      ... Nothing to expose in this case
-                * } loose;
-                */
-               struct {
-                       struct packed_git *pack;
-                       off_t offset;
-                       unsigned int is_delta;
-               } packed;
-       } u;
-};
-
-/*
- * Initializer for a "struct object_info" that wants no items. You may
- * also memset() the memory to all-zeroes.
- */
-#define OBJECT_INFO_INIT {NULL}
-
-/* Invoke lookup_replace_object() on the given hash */
-#define OBJECT_INFO_LOOKUP_REPLACE 1
-/* Allow reading from a loose object file of unknown/bogus type */
-#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
-/* Do not check cached storage */
-#define OBJECT_INFO_SKIP_CACHED 4
-/* Do not retry packed storage after checking packed and loose storage */
-#define OBJECT_INFO_QUICK 8
-/* Do not check loose object */
-#define OBJECT_INFO_IGNORE_LOOSE 16
-
-int oid_object_info_extended(struct repository *r,
-                            const struct object_id *,
-                            struct object_info *, unsigned flags);
-
 /*
  * Set this to 0 to prevent sha1_object_info_extended() from fetching missing
  * blobs. This has a difference only if extensions.partialClone is set.
index bdefc888bae1516f0ddcf22264807d031af7c991..c72e9f9773e173c0dbcb5de88bde54d5434cf808 100644 (file)
@@ -2,14 +2,20 @@
 #include "remote.h"
 #include "refspec.h"
 #include "checkout.h"
+#include "config.h"
 
 struct tracking_name_data {
        /* const */ char *src_ref;
        char *dst_ref;
        struct object_id *dst_oid;
-       int unique;
+       int num_matches;
+       const char *default_remote;
+       char *default_dst_ref;
+       struct object_id *default_dst_oid;
 };
 
+#define TRACKING_NAME_DATA_INIT { NULL, NULL, NULL, 0, NULL, NULL, NULL }
+
 static int check_tracking_name(struct remote *remote, void *cb_data)
 {
        struct tracking_name_data *cb = cb_data;
@@ -21,24 +27,45 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
                free(query.dst);
                return 0;
        }
+       cb->num_matches++;
+       if (cb->default_remote && !strcmp(remote->name, cb->default_remote)) {
+               struct object_id *dst = xmalloc(sizeof(*cb->default_dst_oid));
+               cb->default_dst_ref = xstrdup(query.dst);
+               oidcpy(dst, cb->dst_oid);
+               cb->default_dst_oid = dst;
+       }
        if (cb->dst_ref) {
                free(query.dst);
-               cb->unique = 0;
                return 0;
        }
        cb->dst_ref = query.dst;
        return 0;
 }
 
-const char *unique_tracking_name(const char *name, struct object_id *oid)
+const char *unique_tracking_name(const char *name, struct object_id *oid,
+                                int *dwim_remotes_matched)
 {
-       struct tracking_name_data cb_data = { NULL, NULL, NULL, 1 };
+       struct tracking_name_data cb_data = TRACKING_NAME_DATA_INIT;
+       const char *default_remote = NULL;
+       if (!git_config_get_string_const("checkout.defaultremote", &default_remote))
+               cb_data.default_remote = default_remote;
        cb_data.src_ref = xstrfmt("refs/heads/%s", name);
        cb_data.dst_oid = oid;
        for_each_remote(check_tracking_name, &cb_data);
+       if (dwim_remotes_matched)
+               *dwim_remotes_matched = cb_data.num_matches;
        free(cb_data.src_ref);
-       if (cb_data.unique)
+       free((char *)default_remote);
+       if (cb_data.num_matches == 1) {
+               free(cb_data.default_dst_ref);
+               free(cb_data.default_dst_oid);
                return cb_data.dst_ref;
+       }
        free(cb_data.dst_ref);
+       if (cb_data.default_dst_ref) {
+               oidcpy(oid, cb_data.default_dst_oid);
+               free(cb_data.default_dst_oid);
+               return cb_data.default_dst_ref;
+       }
        return NULL;
 }
index 998071117952de27f2ec0c16d7b3d49abaa952bc..6b2073310c4a6a735a557ab0883c7bb045c2c458 100644 (file)
@@ -8,6 +8,8 @@
  * tracking branch.  Return the name of the remote if such a branch
  * exists, NULL otherwise.
  */
-extern const char *unique_tracking_name(const char *name, struct object_id *oid);
+extern const char *unique_tracking_name(const char *name,
+                                       struct object_id *oid,
+                                       int *dwim_remotes_matched);
 
 #endif /* CHECKOUT_H */
index ceecc889caf9fc3af038ffa4179056291e90b704..06970f72134fae6f6fd6df9afd93a7c7f064f495 100755 (executable)
@@ -97,7 +97,7 @@ fi
 export DEVELOPER=1
 export DEFAULT_TEST_TARGET=prove
 export GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save"
-export GIT_TEST_OPTS="--verbose-log -x"
+export GIT_TEST_OPTS="--verbose-log -x --immediate"
 export GIT_TEST_CLONE_2GB=YesPlease
 if [ "$jobname" = linux-gcc ]; then
        export CC=gcc-8
index 4f261ddc012fb162b7d414b065fe251ceff91bee..d55460a21287018aafe8a4133dc5238e50496a36 100755 (executable)
@@ -8,13 +8,24 @@
 # Tracing executed commands would produce too much noise in the loop below.
 set +x
 
-if ! ls t/test-results/*.exit >/dev/null 2>/dev/null
+cd t/
+
+if ! ls test-results/*.exit >/dev/null 2>/dev/null
 then
        echo "Build job failed before the tests could have been run"
        exit
 fi
 
-for TEST_EXIT in t/test-results/*.exit
+case "$jobname" in
+osx-clang|osx-gcc)
+       # base64 in OSX doesn't wrap its output at 76 columns by
+       # default, but prints a single, very long line.
+       base64_opts="-b 76"
+       ;;
+esac
+
+combined_trash_size=0
+for TEST_EXIT in test-results/*.exit
 do
        if [ "$(cat "$TEST_EXIT")" != "0" ]
        then
@@ -23,5 +34,45 @@ do
                echo "$(tput setaf 1)${TEST_OUT}...$(tput sgr0)"
                echo "------------------------------------------------------------------------"
                cat "${TEST_OUT}"
+
+               test_name="${TEST_EXIT%.exit}"
+               test_name="${test_name##*/}"
+               trash_dir="trash directory.$test_name"
+               trash_tgz_b64="trash.$test_name.base64"
+               if [ -d "$trash_dir" ]
+               then
+                       tar czp "$trash_dir" |base64 $base64_opts >"$trash_tgz_b64"
+
+                       trash_size=$(wc -c <"$trash_tgz_b64")
+                       if [ $trash_size -gt 1048576 ]
+                       then
+                               # larger than 1MB
+                               echo "$(tput setaf 1)Didn't include the trash directory of '$test_name' in the trace log, it's too big$(tput sgr0)"
+                               continue
+                       fi
+
+                       new_combined_trash_size=$(($combined_trash_size + $trash_size))
+                       if [ $new_combined_trash_size -gt 1048576 ]
+                       then
+                               echo "$(tput setaf 1)Didn't include the trash directory of '$test_name' in the trace log, there is plenty of trash in there already.$(tput sgr0)"
+                               continue
+                       fi
+                       combined_trash_size=$new_combined_trash_size
+
+                       # DO NOT modify these two 'echo'-ed strings below
+                       # without updating 'ci/util/extract-trash-dirs.sh'
+                       # as well.
+                       echo "$(tput setaf 1)Start of trash directory of '$test_name':$(tput sgr0)"
+                       cat "$trash_tgz_b64"
+                       echo "$(tput setaf 1)End of trash directory of '$test_name'$(tput sgr0)"
+               fi
        fi
 done
+
+if [ $combined_trash_size -gt 0 ]
+then
+       echo "------------------------------------------------------------------------"
+       echo "Trash directories embedded in this log can be extracted by running:"
+       echo
+       echo "  curl https://api.travis-ci.org/v3/job/$TRAVIS_JOB_ID/log.txt |./ci/util/extract-trash-dirs.sh"
+fi
index fe4ee4e06b1e33d3ee1cd9022df06c960dd8d75b..5688f261d0813d4b2b55baeb5e404fcfef80b5d7 100755 (executable)
@@ -5,6 +5,25 @@
 
 . ${0%/*}/lib-travisci.sh
 
-make coccicheck
+make --jobs=2 coccicheck
+
+set +x
+
+fail=
+for cocci_patch in contrib/coccinelle/*.patch
+do
+       if test -s "$cocci_patch"
+       then
+               echo "$(tput setaf 1)Coccinelle suggests the following changes in '$cocci_patch':$(tput sgr0)"
+               cat "$cocci_patch"
+               fail=UnfortunatelyYes
+       fi
+done
+
+if test -n "$fail"
+then
+       echo "$(tput setaf 1)error: Coccinelle suggested some changes$(tput sgr0)"
+       exit 1
+fi
 
 save_good_tree
diff --git a/ci/util/extract-trash-dirs.sh b/ci/util/extract-trash-dirs.sh
new file mode 100755 (executable)
index 0000000..8e67bec
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+error () {
+       echo >&2 "error: $@"
+       exit 1
+}
+
+find_embedded_trash () {
+       while read -r line
+       do
+               case "$line" in
+               *Start\ of\ trash\ directory\ of\ \'t[0-9][0-9][0-9][0-9]-*\':*)
+                       test_name="${line#*\'}"
+                       test_name="${test_name%\'*}"
+
+                       return 0
+               esac
+       done
+
+       return 1
+}
+
+extract_embedded_trash () {
+       while read -r line
+       do
+               case "$line" in
+               *End\ of\ trash\ directory\ of\ \'$test_name\'*)
+                       return
+                       ;;
+               *)
+                       printf '%s\n' "$line"
+                       ;;
+               esac
+       done
+
+       error "unexpected end of input"
+}
+
+# Raw logs from Linux build jobs have CRLF line endings, while OSX
+# build jobs mostly have CRCRLF, except an odd line every now and
+# then that has CRCRCRLF.  'base64 -d' from 'coreutils' doesn't like
+# CRs and complains about "invalid input", so remove all CRs at the
+# end of lines.
+sed -e 's/\r*$//' | \
+while find_embedded_trash
+do
+       echo "Extracting trash directory of '$test_name'"
+
+       extract_embedded_trash |base64 -d |tar xzp
+done
diff --git a/color.c b/color.c
index b1c24c69de652b0b8900e76ebd5b4e6cd24e5203..ebb222ec3323d45bdcd298208903dff9a90d5c3f 100644 (file)
--- a/color.c
+++ b/color.c
@@ -343,6 +343,9 @@ int want_color_fd(int fd, int var)
 
        static int want_auto[3] = { -1, -1, -1 };
 
+       if (fd < 1 || fd >= ARRAY_SIZE(want_auto))
+               BUG("file descriptor out of range: %d", fd);
+
        if (var < 0)
                var = git_use_color_default;
 
diff --git a/color.h b/color.h
index 5b744e1bc68617d196bdd864042e738cb4d75ebe..98894d6a17563d7005a2ba3a1fb6070c06cbcefc 100644 (file)
--- a/color.h
+++ b/color.h
@@ -36,6 +36,12 @@ struct strbuf;
 #define GIT_COLOR_BOLD_BLUE    "\033[1;34m"
 #define GIT_COLOR_BOLD_MAGENTA "\033[1;35m"
 #define GIT_COLOR_BOLD_CYAN    "\033[1;36m"
+#define GIT_COLOR_FAINT_RED    "\033[2;31m"
+#define GIT_COLOR_FAINT_GREEN  "\033[2;32m"
+#define GIT_COLOR_FAINT_YELLOW "\033[2;33m"
+#define GIT_COLOR_FAINT_BLUE   "\033[2;34m"
+#define GIT_COLOR_FAINT_MAGENTA        "\033[2;35m"
+#define GIT_COLOR_FAINT_CYAN   "\033[2;36m"
 #define GIT_COLOR_BG_RED       "\033[41m"
 #define GIT_COLOR_BG_GREEN     "\033[42m"
 #define GIT_COLOR_BG_YELLOW    "\033[43m"
@@ -44,6 +50,7 @@ struct strbuf;
 #define GIT_COLOR_BG_CYAN      "\033[46m"
 #define GIT_COLOR_FAINT                "\033[2m"
 #define GIT_COLOR_FAINT_ITALIC "\033[2;3m"
+#define GIT_COLOR_REVERSE      "\033[7m"
 
 /* A special value meaning "no color selected" */
 #define GIT_COLOR_NIL "NIL"
index 2ef495963fc1cf2e092778d35f1965912d7eaac0..de7695e72824f6f041e0979e29302ded6e50d611 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "commit.h"
 #include "blob.h"
 #include "diff.h"
index e1c26c1bb7e618f6f372d9a568e7cab75612d2db..a9dda3b8af6a754564f8f840f0ca63d93f6c88dc 100644 (file)
@@ -139,6 +139,7 @@ git-prune-packed                        plumbingmanipulators
 git-pull                                mainporcelain           remote
 git-push                                mainporcelain           remote
 git-quiltimport                         foreignscminterface
+git-range-diff                          mainporcelain
 git-read-tree                           plumbingmanipulators
 git-rebase                              mainporcelain           history
 git-receive-pack                        synchelpers
index b63a1fc85eaded844fcb1a2634067f9509b5937c..8a1bec7b8aa420dd3d4ecadc95dee31029533c07 100644 (file)
@@ -7,10 +7,12 @@
 #include "packfile.h"
 #include "commit.h"
 #include "object.h"
+#include "refs.h"
 #include "revision.h"
 #include "sha1-lookup.h"
 #include "commit-graph.h"
 #include "object-store.h"
+#include "alloc.h"
 
 #define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
 #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
 
 #define GRAPH_LAST_EDGE 0x80000000
 
+#define GRAPH_HEADER_SIZE 8
 #define GRAPH_FANOUT_SIZE (4 * 256)
 #define GRAPH_CHUNKLOOKUP_WIDTH 12
-#define GRAPH_MIN_SIZE (5 * GRAPH_CHUNKLOOKUP_WIDTH + GRAPH_FANOUT_SIZE + \
-                       GRAPH_OID_LEN + 8)
+#define GRAPH_MIN_SIZE (GRAPH_HEADER_SIZE + 4 * GRAPH_CHUNKLOOKUP_WIDTH \
+                       + GRAPH_FANOUT_SIZE + GRAPH_OID_LEN)
 
 char *get_commit_graph_filename(const char *obj_dir)
 {
@@ -77,28 +80,28 @@ struct commit_graph *load_commit_graph_one(const char *graph_file)
 
        if (graph_size < GRAPH_MIN_SIZE) {
                close(fd);
-               die("graph file %s is too small", graph_file);
+               die(_("graph file %s is too small"), graph_file);
        }
        graph_map = xmmap(NULL, graph_size, PROT_READ, MAP_PRIVATE, fd, 0);
        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",
+               error(_("graph signature %X does not match signature %X"),
                      graph_signature, GRAPH_SIGNATURE);
                goto cleanup_fail;
        }
 
        graph_version = *(unsigned char*)(data + 4);
        if (graph_version != GRAPH_VERSION) {
-               error("graph version %X does not match version %X",
+               error(_("graph version %X does not match version %X"),
                      graph_version, GRAPH_VERSION);
                goto cleanup_fail;
        }
 
        hash_version = *(unsigned char*)(data + 5);
        if (hash_version != GRAPH_OID_VERSION) {
-               error("hash version %X does not match version %X",
+               error(_("hash version %X does not match version %X"),
                      hash_version, GRAPH_OID_VERSION);
                goto cleanup_fail;
        }
@@ -122,7 +125,7 @@ struct commit_graph *load_commit_graph_one(const char *graph_file)
                chunk_lookup += GRAPH_CHUNKLOOKUP_WIDTH;
 
                if (chunk_offset > graph_size - GIT_MAX_RAWSZ) {
-                       error("improper chunk offset %08x%08x", (uint32_t)(chunk_offset >> 32),
+                       error(_("improper chunk offset %08x%08x"), (uint32_t)(chunk_offset >> 32),
                              (uint32_t)chunk_offset);
                        goto cleanup_fail;
                }
@@ -158,7 +161,7 @@ struct commit_graph *load_commit_graph_one(const char *graph_file)
                }
 
                if (chunk_repeated) {
-                       error("chunk id %08x appears multiple times", chunk_id);
+                       error(_("chunk id %08x appears multiple times"), chunk_id);
                        goto cleanup_fail;
                }
 
@@ -180,53 +183,60 @@ struct commit_graph *load_commit_graph_one(const char *graph_file)
        exit(1);
 }
 
-/* global storage */
-static struct commit_graph *commit_graph = NULL;
-
-static void prepare_commit_graph_one(const char *obj_dir)
+static void prepare_commit_graph_one(struct repository *r, const char *obj_dir)
 {
        char *graph_name;
 
-       if (commit_graph)
+       if (r->objects->commit_graph)
                return;
 
        graph_name = get_commit_graph_filename(obj_dir);
-       commit_graph = load_commit_graph_one(graph_name);
+       r->objects->commit_graph =
+               load_commit_graph_one(graph_name);
 
        FREE_AND_NULL(graph_name);
 }
 
-static int prepare_commit_graph_run_once = 0;
-static void prepare_commit_graph(void)
+/*
+ * Return 1 if commit_graph is non-NULL, and 0 otherwise.
+ *
+ * On the first invocation, this function attemps to load the commit
+ * graph if the_repository is configured to have one.
+ */
+static int prepare_commit_graph(struct repository *r)
 {
        struct alternate_object_database *alt;
        char *obj_dir;
+       int config_value;
+
+       if (r->objects->commit_graph_attempted)
+               return !!r->objects->commit_graph;
+       r->objects->commit_graph_attempted = 1;
+
+       if (repo_config_get_bool(r, "core.commitgraph", &config_value) ||
+           !config_value)
+               /*
+                * This repository is not configured to use commit graphs, so
+                * do not load one. (But report commit_graph_attempted anyway
+                * so that commit graph loading is not attempted again for this
+                * repository.)
+                */
+               return 0;
 
-       if (prepare_commit_graph_run_once)
-               return;
-       prepare_commit_graph_run_once = 1;
-
-       obj_dir = get_object_directory();
-       prepare_commit_graph_one(obj_dir);
-       prepare_alt_odb(the_repository);
-       for (alt = the_repository->objects->alt_odb_list;
-            !commit_graph && alt;
+       obj_dir = r->objects->objectdir;
+       prepare_commit_graph_one(r, obj_dir);
+       prepare_alt_odb(r);
+       for (alt = r->objects->alt_odb_list;
+            !r->objects->commit_graph && alt;
             alt = alt->next)
-               prepare_commit_graph_one(alt->path);
+               prepare_commit_graph_one(r, alt->path);
+       return !!r->objects->commit_graph;
 }
 
 static void close_commit_graph(void)
 {
-       if (!commit_graph)
-               return;
-
-       if (commit_graph->graph_fd >= 0) {
-               munmap((void *)commit_graph->data, commit_graph->data_len);
-               commit_graph->data = NULL;
-               close(commit_graph->graph_fd);
-       }
-
-       FREE_AND_NULL(commit_graph);
+       free_commit_graph(the_repository->objects->commit_graph);
+       the_repository->objects->commit_graph = NULL;
 }
 
 static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t *pos)
@@ -241,10 +251,14 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g,
 {
        struct commit *c;
        struct object_id oid;
+
+       if (pos >= g->num_commits)
+               die("invalid parent position %"PRIu64, pos);
+
        hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * pos);
-       c = lookup_commit(&oid);
+       c = lookup_commit(the_repository, &oid);
        if (!c)
-               die("could not find commit %s", oid_to_hex(&oid));
+               die(_("could not find commit %s"), oid_to_hex(&oid));
        c->graph_pos = pos;
        return &commit_list_insert(c, pptr)->next;
 }
@@ -313,28 +327,33 @@ static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uin
        }
 }
 
-int parse_commit_in_graph(struct commit *item)
+static int parse_commit_in_graph_one(struct commit_graph *g, struct commit *item)
 {
        uint32_t pos;
 
-       if (!core_commit_graph)
-               return 0;
        if (item->object.parsed)
                return 1;
-       prepare_commit_graph();
-       if (commit_graph && find_commit_in_graph(item, commit_graph, &pos))
-               return fill_commit_in_graph(item, commit_graph, pos);
+
+       if (find_commit_in_graph(item, g, &pos))
+               return fill_commit_in_graph(item, g, pos);
+
        return 0;
 }
 
-void load_commit_graph_info(struct commit *item)
+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);
+}
+
+void load_commit_graph_info(struct repository *r, struct commit *item)
 {
        uint32_t pos;
-       if (!core_commit_graph)
+       if (!prepare_commit_graph(r))
                return;
-       prepare_commit_graph();
-       if (commit_graph && find_commit_in_graph(item, commit_graph, &pos))
-               fill_commit_graph_info(item, commit_graph, pos);
+       if (find_commit_in_graph(item, r->objects->commit_graph, &pos))
+               fill_commit_graph_info(item, r->objects->commit_graph, pos);
 }
 
 static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit *c)
@@ -344,19 +363,25 @@ static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit *
                                           GRAPH_DATA_WIDTH * (c->graph_pos);
 
        hashcpy(oid.hash, commit_data);
-       c->maybe_tree = lookup_tree(&oid);
+       c->maybe_tree = lookup_tree(the_repository, &oid);
 
        return c->maybe_tree;
 }
 
-struct tree *get_commit_tree_in_graph(const struct commit *c)
+static struct tree *get_commit_tree_in_graph_one(struct commit_graph *g,
+                                                const struct commit *c)
 {
        if (c->maybe_tree)
                return c->maybe_tree;
        if (c->graph_pos == COMMIT_NOT_FROM_GRAPH)
-               BUG("get_commit_tree_in_graph called from non-commit-graph commit");
+               BUG("get_commit_tree_in_graph_one called from non-commit-graph commit");
 
-       return load_tree_for_commit(commit_graph, (struct commit *)c);
+       return load_tree_for_commit(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);
 }
 
 static void write_graph_chunk_fanout(struct hashfile *f,
@@ -537,7 +562,7 @@ static int add_packed_commits(const struct object_id *oid,
 
        oi.typep = &type;
        if (packed_object_info(the_repository, pack, offset, &oi) < 0)
-               die("unable to get type of object %s", oid_to_hex(oid));
+               die(_("unable to get type of object %s"), oid_to_hex(oid));
 
        if (type != OBJ_COMMIT)
                return 0;
@@ -568,7 +593,7 @@ static void close_reachable(struct packed_oid_list *oids)
        struct commit *commit;
 
        for (i = 0; i < oids->nr; i++) {
-               commit = lookup_commit(&oids->list[i]);
+               commit = lookup_commit(the_repository, &oids->list[i]);
                if (commit)
                        commit->object.flags |= UNINTERESTING;
        }
@@ -579,14 +604,14 @@ static void close_reachable(struct packed_oid_list *oids)
         * closure.
         */
        for (i = 0; i < oids->nr; i++) {
-               commit = lookup_commit(&oids->list[i]);
+               commit = lookup_commit(the_repository, &oids->list[i]);
 
                if (commit && !parse_commit(commit))
                        add_missing_parents(oids, commit);
        }
 
        for (i = 0; i < oids->nr; i++) {
-               commit = lookup_commit(&oids->list[i]);
+               commit = lookup_commit(the_repository, &oids->list[i]);
 
                if (commit)
                        commit->object.flags &= ~UNINTERESTING;
@@ -632,11 +657,28 @@ static void compute_generation_numbers(struct packed_commit_list* commits)
        }
 }
 
+static int add_ref_to_list(const char *refname,
+                          const struct object_id *oid,
+                          int flags, void *cb_data)
+{
+       struct string_list *list = (struct string_list *)cb_data;
+
+       string_list_append(list, oid_to_hex(oid));
+       return 0;
+}
+
+void write_commit_graph_reachable(const char *obj_dir, int append)
+{
+       struct string_list list;
+
+       string_list_init(&list, 1);
+       for_each_ref(add_ref_to_list, &list);
+       write_commit_graph(obj_dir, NULL, &list, append);
+}
+
 void write_commit_graph(const char *obj_dir,
-                       const char **pack_indexes,
-                       int nr_packs,
-                       const char **commit_hex,
-                       int nr_commits,
+                       struct string_list *pack_indexes,
+                       struct string_list *commit_hex,
                        int append)
 {
        struct packed_oid_list oids;
@@ -655,16 +697,18 @@ void write_commit_graph(const char *obj_dir,
        oids.alloc = approximate_object_count() / 4;
 
        if (append) {
-               prepare_commit_graph_one(obj_dir);
-               if (commit_graph)
-                       oids.alloc += commit_graph->num_commits;
+               prepare_commit_graph_one(the_repository, obj_dir);
+               if (the_repository->objects->commit_graph)
+                       oids.alloc += the_repository->objects->commit_graph->num_commits;
        }
 
        if (oids.alloc < 1024)
                oids.alloc = 1024;
        ALLOC_ARRAY(oids.list, oids.alloc);
 
-       if (append && commit_graph) {
+       if (append && the_repository->objects->commit_graph) {
+               struct commit_graph *commit_graph =
+                       the_repository->objects->commit_graph;
                for (i = 0; i < commit_graph->num_commits; i++) {
                        const unsigned char *hash = commit_graph->chunk_oid_lookup +
                                commit_graph->hash_len * i;
@@ -677,31 +721,32 @@ void write_commit_graph(const char *obj_dir,
                int dirlen;
                strbuf_addf(&packname, "%s/pack/", obj_dir);
                dirlen = packname.len;
-               for (i = 0; i < nr_packs; i++) {
+               for (i = 0; i < pack_indexes->nr; i++) {
                        struct packed_git *p;
                        strbuf_setlen(&packname, dirlen);
-                       strbuf_addstr(&packname, pack_indexes[i]);
+                       strbuf_addstr(&packname, pack_indexes->items[i].string);
                        p = add_packed_git(packname.buf, packname.len, 1);
                        if (!p)
-                               die("error adding pack %s", packname.buf);
+                               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);
+                               die(_("error opening index for %s"), packname.buf);
+                       for_each_object_in_pack(p, add_packed_commits, &oids, 0);
                        close_pack(p);
                }
                strbuf_release(&packname);
        }
 
        if (commit_hex) {
-               for (i = 0; i < nr_commits; i++) {
+               for (i = 0; i < commit_hex->nr; i++) {
                        const char *end;
                        struct object_id oid;
                        struct commit *result;
 
-                       if (commit_hex[i] && parse_oid_hex(commit_hex[i], &oid, &end))
+                       if (commit_hex->items[i].string &&
+                           parse_oid_hex(commit_hex->items[i].string, &oid, &end))
                                continue;
 
-                       result = lookup_commit_reference_gently(&oid, 1);
+                       result = lookup_commit_reference_gently(the_repository, &oid, 1);
 
                        if (result) {
                                ALLOC_GROW(oids.list, oids.nr + 1, oids.alloc);
@@ -737,7 +782,7 @@ void write_commit_graph(const char *obj_dir,
                if (i > 0 && !oidcmp(&oids.list[i-1], &oids.list[i]))
                        continue;
 
-               commits.list[commits.nr] = lookup_commit(&oids.list[i]);
+               commits.list[commits.nr] = lookup_commit(the_repository, &oids.list[i]);
                parse_commit(commits.list[commits.nr]);
 
                for (parent = commits.list[commits.nr]->parents;
@@ -808,3 +853,191 @@ void write_commit_graph(const char *obj_dir,
        oids.alloc = 0;
        oids.nr = 0;
 }
+
+#define VERIFY_COMMIT_GRAPH_ERROR_HASH 2
+static int verify_commit_graph_error;
+
+static void graph_report(const char *fmt, ...)
+{
+       va_list ap;
+
+       verify_commit_graph_error = 1;
+       va_start(ap, fmt);
+       vfprintf(stderr, fmt, ap);
+       fprintf(stderr, "\n");
+       va_end(ap);
+}
+
+#define GENERATION_ZERO_EXISTS 1
+#define GENERATION_NUMBER_EXISTS 2
+
+int verify_commit_graph(struct repository *r, struct commit_graph *g)
+{
+       uint32_t i, cur_fanout_pos = 0;
+       struct object_id prev_oid, cur_oid, checksum;
+       int generation_zero = 0;
+       struct hashfile *f;
+       int devnull;
+
+       if (!g) {
+               graph_report("no commit-graph file loaded");
+               return 1;
+       }
+
+       verify_commit_graph_error = 0;
+
+       if (!g->chunk_oid_fanout)
+               graph_report("commit-graph is missing the OID Fanout chunk");
+       if (!g->chunk_oid_lookup)
+               graph_report("commit-graph is missing the OID Lookup chunk");
+       if (!g->chunk_commit_data)
+               graph_report("commit-graph is missing the Commit Data chunk");
+
+       if (verify_commit_graph_error)
+               return verify_commit_graph_error;
+
+       devnull = open("/dev/null", O_WRONLY);
+       f = hashfd(devnull, NULL);
+       hashwrite(f, g->data, g->data_len - g->hash_len);
+       finalize_hashfile(f, checksum.hash, CSUM_CLOSE);
+       if (hashcmp(checksum.hash, g->data + g->data_len - g->hash_len)) {
+               graph_report(_("the commit-graph file has incorrect checksum and is likely corrupt"));
+               verify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH;
+       }
+
+       for (i = 0; i < g->num_commits; i++) {
+               struct commit *graph_commit;
+
+               hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
+
+               if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
+                       graph_report("commit-graph has incorrect OID order: %s then %s",
+                                    oid_to_hex(&prev_oid),
+                                    oid_to_hex(&cur_oid));
+
+               oidcpy(&prev_oid, &cur_oid);
+
+               while (cur_oid.hash[0] > cur_fanout_pos) {
+                       uint32_t fanout_value = get_be32(g->chunk_oid_fanout + cur_fanout_pos);
+
+                       if (i != fanout_value)
+                               graph_report("commit-graph has incorrect fanout value: fanout[%d] = %u != %u",
+                                            cur_fanout_pos, fanout_value, i);
+                       cur_fanout_pos++;
+               }
+
+               graph_commit = lookup_commit(r, &cur_oid);
+               if (!parse_commit_in_graph_one(g, graph_commit))
+                       graph_report("failed to parse %s from commit-graph",
+                                    oid_to_hex(&cur_oid));
+       }
+
+       while (cur_fanout_pos < 256) {
+               uint32_t fanout_value = get_be32(g->chunk_oid_fanout + cur_fanout_pos);
+
+               if (g->num_commits != fanout_value)
+                       graph_report("commit-graph has incorrect fanout value: fanout[%d] = %u != %u",
+                                    cur_fanout_pos, fanout_value, i);
+
+               cur_fanout_pos++;
+       }
+
+       if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH)
+               return verify_commit_graph_error;
+
+       for (i = 0; i < g->num_commits; i++) {
+               struct commit *graph_commit, *odb_commit;
+               struct commit_list *graph_parents, *odb_parents;
+               uint32_t max_generation = 0;
+
+               hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
+
+               graph_commit = lookup_commit(r, &cur_oid);
+               odb_commit = (struct commit *)create_object(r, cur_oid.hash, alloc_commit_node(r));
+               if (parse_commit_internal(odb_commit, 0, 0)) {
+                       graph_report("failed to parse %s from object database",
+                                    oid_to_hex(&cur_oid));
+                       continue;
+               }
+
+               if (oidcmp(&get_commit_tree_in_graph_one(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),
+                                    oid_to_hex(get_commit_tree_oid(graph_commit)),
+                                    oid_to_hex(get_commit_tree_oid(odb_commit)));
+
+               graph_parents = graph_commit->parents;
+               odb_parents = odb_commit->parents;
+
+               while (graph_parents) {
+                       if (odb_parents == NULL) {
+                               graph_report("commit-graph parent list for commit %s is too long",
+                                            oid_to_hex(&cur_oid));
+                               break;
+                       }
+
+                       if (oidcmp(&graph_parents->item->object.oid, &odb_parents->item->object.oid))
+                               graph_report("commit-graph parent for %s is %s != %s",
+                                            oid_to_hex(&cur_oid),
+                                            oid_to_hex(&graph_parents->item->object.oid),
+                                            oid_to_hex(&odb_parents->item->object.oid));
+
+                       if (graph_parents->item->generation > max_generation)
+                               max_generation = graph_parents->item->generation;
+
+                       graph_parents = graph_parents->next;
+                       odb_parents = odb_parents->next;
+               }
+
+               if (odb_parents != NULL)
+                       graph_report("commit-graph parent list for commit %s terminates early",
+                                    oid_to_hex(&cur_oid));
+
+               if (!graph_commit->generation) {
+                       if (generation_zero == GENERATION_NUMBER_EXISTS)
+                               graph_report("commit-graph has generation number zero for commit %s, but non-zero elsewhere",
+                                            oid_to_hex(&cur_oid));
+                       generation_zero = GENERATION_ZERO_EXISTS;
+               } else if (generation_zero == GENERATION_ZERO_EXISTS)
+                       graph_report("commit-graph has non-zero generation number for commit %s, but zero elsewhere",
+                                    oid_to_hex(&cur_oid));
+
+               if (generation_zero == GENERATION_ZERO_EXISTS)
+                       continue;
+
+               /*
+                * If one of our parents has generation GENERATION_NUMBER_MAX, then
+                * our generation is also GENERATION_NUMBER_MAX. Decrement to avoid
+                * extra logic in the following condition.
+                */
+               if (max_generation == GENERATION_NUMBER_MAX)
+                       max_generation--;
+
+               if (graph_commit->generation != max_generation + 1)
+                       graph_report("commit-graph generation for commit %s is %u != %u",
+                                    oid_to_hex(&cur_oid),
+                                    graph_commit->generation,
+                                    max_generation + 1);
+
+               if (graph_commit->date != odb_commit->date)
+                       graph_report("commit date for commit %s in commit-graph is %"PRItime" != %"PRItime,
+                                    oid_to_hex(&cur_oid),
+                                    graph_commit->date,
+                                    odb_commit->date);
+       }
+
+       return verify_commit_graph_error;
+}
+
+void free_commit_graph(struct commit_graph *g)
+{
+       if (!g)
+               return;
+       if (g->graph_fd >= 0) {
+               munmap((void *)g->data, g->data_len);
+               g->data = NULL;
+               close(g->graph_fd);
+       }
+       free(g);
+}
index 96cccb10f3d53a6da77f4ad06a971dbaa152f70c..76e098934a7f6740b52a479baa5c68fe605d1ea6 100644 (file)
@@ -2,6 +2,10 @@
 #define COMMIT_GRAPH_H
 
 #include "git-compat-util.h"
+#include "repository.h"
+#include "string-list.h"
+
+struct commit;
 
 char *get_commit_graph_filename(const char *obj_dir);
 
@@ -15,7 +19,7 @@ char *get_commit_graph_filename(const char *obj_dir);
  *
  * See parse_commit_buffer() for the fallback after this call.
  */
-int parse_commit_in_graph(struct commit *item);
+int parse_commit_in_graph(struct repository *r, struct commit *item);
 
 /*
  * It is possible that we loaded commit contents from the commit buffer,
@@ -23,9 +27,10 @@ int parse_commit_in_graph(struct commit *item);
  * checked and filled. Fill the graph_pos and generation members of
  * the given commit.
  */
-void load_commit_graph_info(struct commit *item);
+void load_commit_graph_info(struct repository *r, struct commit *item);
 
-struct tree *get_commit_tree_in_graph(const struct commit *c);
+struct tree *get_commit_tree_in_graph(struct repository *r,
+                                     const struct commit *c);
 
 struct commit_graph {
        int graph_fd;
@@ -46,11 +51,14 @@ struct commit_graph {
 
 struct commit_graph *load_commit_graph_one(const char *graph_file);
 
+void write_commit_graph_reachable(const char *obj_dir, int append);
 void write_commit_graph(const char *obj_dir,
-                       const char **pack_indexes,
-                       int nr_packs,
-                       const char **commit_hex,
-                       int nr_commits,
+                       struct string_list *pack_indexes,
+                       struct string_list *commit_hex,
                        int append);
 
+int verify_commit_graph(struct repository *r, struct commit_graph *g);
+
+void free_commit_graph(struct commit_graph *);
+
 #endif
index 87a9cadfcca3f58045e2d7b2c3a143c8c4501f8d..ac1e6d409ad6cf1109f1e439944bd2fb1ab9e58e 100644 (file)
@@ -11,8 +11,6 @@
 
 #define implement_commit_slab(slabname, elemtype, scope)               \
                                                                        \
-static int stat_ ##slabname## realloc;                                 \
-                                                                       \
 scope void init_ ##slabname## _with_stride(struct slabname *s,         \
                                                   unsigned stride)     \
 {                                                                      \
@@ -54,7 +52,6 @@ scope elemtype *slabname## _at_peek(struct slabname *s,                       \
                if (!add_if_missing)                                    \
                        return NULL;                                    \
                REALLOC_ARRAY(s->slab, nth_slab + 1);                   \
-               stat_ ##slabname## realloc++;                           \
                for (i = s->slab_count; i <= nth_slab; i++)             \
                        s->slab[i] = NULL;                              \
                s->slab_count = nth_slab + 1;                           \
index 0c3b75aeffea75956adf2190e763b0d753c848c5..30d1af2b20660de99bed06486c11d1aef3763849 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -2,6 +2,8 @@
 #include "tag.h"
 #include "commit.h"
 #include "commit-graph.h"
+#include "repository.h"
+#include "object-store.h"
 #include "pkt-line.h"
 #include "utf8.h"
 #include "diff.h"
@@ -22,24 +24,26 @@ int save_commit_buffer = 1;
 
 const char *commit_type = "commit";
 
-struct commit *lookup_commit_reference_gently(const struct object_id *oid,
-                                             int quiet)
+struct commit *lookup_commit_reference_gently(struct repository *r,
+               const struct object_id *oid, int quiet)
 {
-       struct object *obj = deref_tag(parse_object(oid), NULL, 0);
+       struct object *obj = deref_tag(r,
+                                      parse_object(r, oid),
+                                      NULL, 0);
 
        if (!obj)
                return NULL;
-       return object_as_type(obj, OBJ_COMMIT, quiet);
+       return object_as_type(r, obj, OBJ_COMMIT, quiet);
 }
 
-struct commit *lookup_commit_reference(const struct object_id *oid)
+struct commit *lookup_commit_reference(struct repository *r, const struct object_id *oid)
 {
-       return lookup_commit_reference_gently(oid, 0);
+       return lookup_commit_reference_gently(r, oid, 0);
 }
 
 struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)
 {
-       struct commit *c = lookup_commit_reference(oid);
+       struct commit *c = lookup_commit_reference(the_repository, oid);
        if (!c)
                die(_("could not parse %s"), ref_name);
        if (oidcmp(oid, &c->object.oid)) {
@@ -49,13 +53,13 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
        return c;
 }
 
-struct commit *lookup_commit(const struct object_id *oid)
+struct commit *lookup_commit(struct repository *r, const struct object_id *oid)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(r, oid->hash);
        if (!obj)
-               return create_object(the_repository, oid->hash,
-                                    alloc_commit_node(the_repository));
-       return object_as_type(obj, OBJ_COMMIT, 0);
+               return create_object(r, oid->hash,
+                                    alloc_commit_node(r));
+       return object_as_type(r, obj, OBJ_COMMIT, 0);
 }
 
 struct commit *lookup_commit_reference_by_name(const char *name)
@@ -65,7 +69,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
 
        if (get_oid_committish(name, &oid))
                return NULL;
-       commit = lookup_commit_reference(&oid);
+       commit = lookup_commit_reference(the_repository, &oid);
        if (parse_commit(commit))
                return NULL;
        return commit;
@@ -98,41 +102,44 @@ static timestamp_t parse_commit_date(const char *buf, const char *tail)
        return parse_timestamp(dateptr, NULL, 10);
 }
 
-static struct commit_graft **commit_graft;
-static int commit_graft_alloc, commit_graft_nr;
-
 static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
 {
        struct commit_graft **commit_graft_table = table;
        return commit_graft_table[index]->oid.hash;
 }
 
-static int commit_graft_pos(const unsigned char *sha1)
+static int commit_graft_pos(struct repository *r, const unsigned char *sha1)
 {
-       return sha1_pos(sha1, commit_graft, commit_graft_nr,
+       return sha1_pos(sha1, r->parsed_objects->grafts,
+                       r->parsed_objects->grafts_nr,
                        commit_graft_sha1_access);
 }
 
-int register_commit_graft(struct commit_graft *graft, int ignore_dups)
+int register_commit_graft(struct repository *r, struct commit_graft *graft,
+                         int ignore_dups)
 {
-       int pos = commit_graft_pos(graft->oid.hash);
+       int pos = commit_graft_pos(r, graft->oid.hash);
 
        if (0 <= pos) {
                if (ignore_dups)
                        free(graft);
                else {
-                       free(commit_graft[pos]);
-                       commit_graft[pos] = graft;
+                       free(r->parsed_objects->grafts[pos]);
+                       r->parsed_objects->grafts[pos] = graft;
                }
                return 1;
        }
        pos = -pos - 1;
-       ALLOC_GROW(commit_graft, commit_graft_nr + 1, commit_graft_alloc);
-       commit_graft_nr++;
-       if (pos < commit_graft_nr)
-               MOVE_ARRAY(commit_graft + pos + 1, commit_graft + pos,
-                          commit_graft_nr - pos - 1);
-       commit_graft[pos] = graft;
+       ALLOC_GROW(r->parsed_objects->grafts,
+                  r->parsed_objects->grafts_nr + 1,
+                  r->parsed_objects->grafts_alloc);
+       r->parsed_objects->grafts_nr++;
+       if (pos < r->parsed_objects->grafts_nr)
+               memmove(r->parsed_objects->grafts + pos + 1,
+                       r->parsed_objects->grafts + pos,
+                       (r->parsed_objects->grafts_nr - pos - 1) *
+                       sizeof(*r->parsed_objects->grafts));
+       r->parsed_objects->grafts[pos] = graft;
        return 0;
 }
 
@@ -174,7 +181,7 @@ struct commit_graft *read_graft_line(struct strbuf *line)
        return NULL;
 }
 
-static int read_graft_file(const char *graft_file)
+static int read_graft_file(struct repository *r, const char *graft_file)
 {
        FILE *fp = fopen_or_warn(graft_file, "r");
        struct strbuf buf = STRBUF_INIT;
@@ -194,7 +201,7 @@ static int read_graft_file(const char *graft_file)
                struct commit_graft *graft = read_graft_line(&buf);
                if (!graft)
                        continue;
-               if (register_commit_graft(graft, 1))
+               if (register_commit_graft(r, graft, 1))
                        error("duplicate graft data: %s", buf.buf);
        }
        fclose(fp);
@@ -202,50 +209,50 @@ static int read_graft_file(const char *graft_file)
        return 0;
 }
 
-static void prepare_commit_graft(void)
+static void prepare_commit_graft(struct repository *r)
 {
-       static int commit_graft_prepared;
        char *graft_file;
 
-       if (commit_graft_prepared)
+       if (r->parsed_objects->commit_graft_prepared)
                return;
        if (!startup_info->have_repository)
                return;
 
-       graft_file = get_graft_file();
-       read_graft_file(graft_file);
+       graft_file = get_graft_file(r);
+       read_graft_file(r, graft_file);
        /* make sure shallows are read */
-       is_repository_shallow();
-       commit_graft_prepared = 1;
+       is_repository_shallow(r);
+       r->parsed_objects->commit_graft_prepared = 1;
 }
 
-struct commit_graft *lookup_commit_graft(const struct object_id *oid)
+struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid)
 {
        int pos;
-       prepare_commit_graft();
-       pos = commit_graft_pos(oid->hash);
+       prepare_commit_graft(r);
+       pos = commit_graft_pos(r, oid->hash);
        if (pos < 0)
                return NULL;
-       return commit_graft[pos];
+       return r->parsed_objects->grafts[pos];
 }
 
 int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
 {
        int i, ret;
-       for (i = ret = 0; i < commit_graft_nr && !ret; i++)
-               ret = fn(commit_graft[i], cb_data);
+       for (i = ret = 0; i < the_repository->parsed_objects->grafts_nr && !ret; i++)
+               ret = fn(the_repository->parsed_objects->grafts[i], cb_data);
        return ret;
 }
 
 int unregister_shallow(const struct object_id *oid)
 {
-       int pos = commit_graft_pos(oid->hash);
+       int pos = commit_graft_pos(the_repository, oid->hash);
        if (pos < 0)
                return -1;
-       if (pos + 1 < commit_graft_nr)
-               MOVE_ARRAY(commit_graft + pos, commit_graft + pos + 1,
-                          commit_graft_nr - pos - 1);
-       commit_graft_nr--;
+       if (pos + 1 < the_repository->parsed_objects->grafts_nr)
+               MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
+                          the_repository->parsed_objects->grafts + pos + 1,
+                          the_repository->parsed_objects->grafts_nr - pos - 1);
+       the_repository->parsed_objects->grafts_nr--;
        return 0;
 }
 
@@ -254,18 +261,32 @@ struct commit_buffer {
        unsigned long size;
 };
 define_commit_slab(buffer_slab, struct commit_buffer);
-static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);
 
-void set_commit_buffer(struct commit *commit, void *buffer, unsigned long size)
+struct buffer_slab *allocate_commit_buffer_slab(void)
+{
+       struct buffer_slab *bs = xmalloc(sizeof(*bs));
+       init_buffer_slab(bs);
+       return bs;
+}
+
+void free_commit_buffer_slab(struct buffer_slab *bs)
+{
+       clear_buffer_slab(bs);
+       free(bs);
+}
+
+void set_commit_buffer(struct repository *r, struct commit *commit, void *buffer, unsigned long size)
 {
-       struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_at(
+               r->parsed_objects->buffer_slab, commit);
        v->buffer = buffer;
        v->size = size;
 }
 
-const void *get_cached_commit_buffer(const struct commit *commit, unsigned long *sizep)
+const void *get_cached_commit_buffer(struct repository *r, const struct commit *commit, unsigned long *sizep)
 {
-       struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               r->parsed_objects->buffer_slab, commit);
        if (!v) {
                if (sizep)
                        *sizep = 0;
@@ -278,7 +299,7 @@ const void *get_cached_commit_buffer(const struct commit *commit, unsigned long
 
 const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
 {
-       const void *ret = get_cached_commit_buffer(commit, sizep);
+       const void *ret = get_cached_commit_buffer(the_repository, commit, sizep);
        if (!ret) {
                enum object_type type;
                unsigned long size;
@@ -297,14 +318,16 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
 
 void unuse_commit_buffer(const struct commit *commit, const void *buffer)
 {
-       struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               the_repository->parsed_objects->buffer_slab, commit);
        if (!(v && v->buffer == buffer))
                free((void *)buffer);
 }
 
 void free_commit_buffer(struct commit *commit)
 {
-       struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               the_repository->parsed_objects->buffer_slab, commit);
        if (v) {
                FREE_AND_NULL(v->buffer);
                v->size = 0;
@@ -319,7 +342,7 @@ struct tree *get_commit_tree(const struct commit *commit)
        if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
                BUG("commit has NULL tree, but was not loaded from commit-graph");
 
-       return get_commit_tree_in_graph(commit);
+       return get_commit_tree_in_graph(the_repository, commit);
 }
 
 struct object_id *get_commit_tree_oid(const struct commit *commit)
@@ -340,7 +363,8 @@ void release_commit_memory(struct commit *c)
 
 const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
 {
-       struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               the_repository->parsed_objects->buffer_slab, commit);
        void *ret;
 
        if (!v) {
@@ -357,15 +381,15 @@ const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
        return ret;
 }
 
-int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size, int check_graph)
+int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size, int check_graph)
 {
        const char *tail = buffer;
        const char *bufptr = buffer;
        struct object_id parent;
        struct commit_list **pptr;
        struct commit_graft *graft;
-       const int tree_entry_len = GIT_SHA1_HEXSZ + 5;
-       const int parent_entry_len = GIT_SHA1_HEXSZ + 7;
+       const int tree_entry_len = the_hash_algo->hexsz + 5;
+       const int parent_entry_len = the_hash_algo->hexsz + 7;
 
        if (item->object.parsed)
                return 0;
@@ -377,11 +401,11 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
        if (get_oid_hex(bufptr + 5, &parent) < 0)
                return error("bad tree pointer in commit %s",
                             oid_to_hex(&item->object.oid));
-       item->maybe_tree = lookup_tree(&parent);
+       item->maybe_tree = lookup_tree(r, &parent);
        bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
        pptr = &item->parents;
 
-       graft = lookup_commit_graft(&item->object.oid);
+       graft = lookup_commit_graft(r, &item->object.oid);
        while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) {
                struct commit *new_parent;
 
@@ -396,7 +420,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
                 */
                if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
                        continue;
-               new_parent = lookup_commit(&parent);
+               new_parent = lookup_commit(r, &parent);
                if (new_parent)
                        pptr = &commit_list_insert(new_parent, pptr)->next;
        }
@@ -404,7 +428,8 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
                int i;
                struct commit *new_parent;
                for (i = 0; i < graft->nr_parent; i++) {
-                       new_parent = lookup_commit(&graft->parent[i]);
+                       new_parent = lookup_commit(r,
+                                                  &graft->parent[i]);
                        if (!new_parent)
                                continue;
                        pptr = &commit_list_insert(new_parent, pptr)->next;
@@ -413,12 +438,12 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
        item->date = parse_commit_date(bufptr, tail);
 
        if (check_graph)
-               load_commit_graph_info(item);
+               load_commit_graph_info(the_repository, item);
 
        return 0;
 }
 
-int parse_commit_gently(struct commit *item, int quiet_on_missing)
+int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_commit_graph)
 {
        enum object_type type;
        void *buffer;
@@ -429,7 +454,7 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)
                return -1;
        if (item->object.parsed)
                return 0;
-       if (parse_commit_in_graph(item))
+       if (use_commit_graph && parse_commit_in_graph(the_repository, item))
                return 0;
        buffer = read_object_file(&item->object.oid, &type, &size);
        if (!buffer)
@@ -441,15 +466,21 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)
                return error("Object %s not a commit",
                             oid_to_hex(&item->object.oid));
        }
-       ret = parse_commit_buffer(item, buffer, size, 0);
+
+       ret = parse_commit_buffer(the_repository, item, buffer, size, 0);
        if (save_commit_buffer && !ret) {
-               set_commit_buffer(item, buffer, size);
+               set_commit_buffer(the_repository, item, buffer, size);
                return 0;
        }
        free(buffer);
        return ret;
 }
 
+int parse_commit_gently(struct commit *item, int quiet_on_missing)
+{
+       return parse_commit_internal(item, quiet_on_missing, 1);
+}
+
 void parse_commit_or_die(struct commit *item)
 {
        if (parse_commit(item))
@@ -1687,7 +1718,7 @@ struct commit *get_merge_parent(const char *name)
        struct object_id oid;
        if (get_oid(name, &oid))
                return NULL;
-       obj = parse_object(&oid);
+       obj = parse_object(the_repository, &oid);
        commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
        if (commit && !merge_remote_util(commit))
                set_merge_remote_desc(commit, name, obj);
index 3ad07c2e3d092a97e3bc20091566f4b967b6bc8c..da0db36eba2bf16277dbb7aadcb3384e29191ecc 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -63,9 +63,11 @@ enum decoration_type {
 void add_name_decoration(enum decoration_type type, const char *name, struct object *obj);
 const struct name_decoration *get_name_decoration(const struct object *obj);
 
-struct commit *lookup_commit(const struct object_id *oid);
-struct commit *lookup_commit_reference(const struct object_id *oid);
-struct commit *lookup_commit_reference_gently(const struct object_id *oid,
+struct commit *lookup_commit(struct repository *r, const struct object_id *oid);
+struct commit *lookup_commit_reference(struct repository *r,
+                                      const struct object_id *oid);
+struct commit *lookup_commit_reference_gently(struct repository *r,
+                                             const struct object_id *oid,
                                              int quiet);
 struct commit *lookup_commit_reference_by_name(const char *name);
 
@@ -76,7 +78,8 @@ 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 commit *item, const void *buffer, unsigned long size, int check_graph);
+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)
 {
@@ -84,17 +87,21 @@ static inline int parse_commit(struct commit *item)
 }
 void parse_commit_or_die(struct commit *item);
 
+struct buffer_slab;
+struct buffer_slab *allocate_commit_buffer_slab(void);
+void free_commit_buffer_slab(struct buffer_slab *bs);
+
 /*
  * Associate an object buffer with the commit. The ownership of the
  * memory is handed over to the commit, and must be free()-able.
  */
-void set_commit_buffer(struct commit *, void *buffer, unsigned long size);
+void set_commit_buffer(struct repository *r, struct commit *, void *buffer, unsigned long size);
 
 /*
  * Get any cached object buffer associated with the commit. Returns NULL
  * if none. The resulting memory should not be freed.
  */
-const void *get_cached_commit_buffer(const struct commit *, unsigned long *size);
+const void *get_cached_commit_buffer(struct repository *, const struct commit *, unsigned long *size);
 
 /*
  * Get the commit's object contents, either from cache or by reading the object
@@ -194,8 +201,8 @@ struct commit_graft {
 typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
 
 struct commit_graft *read_graft_line(struct strbuf *line);
-int register_commit_graft(struct commit_graft *, int);
-struct commit_graft *lookup_commit_graft(const struct object_id *oid);
+int register_commit_graft(struct repository *r, struct commit_graft *, int);
+struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);
 
 extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);
 extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);
@@ -209,15 +216,15 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,
 
 struct oid_array;
 struct ref;
-extern int register_shallow(const struct object_id *oid);
+extern int register_shallow(struct repository *r, const struct object_id *oid);
 extern int unregister_shallow(const struct object_id *oid);
 extern int for_each_commit_graft(each_commit_graft_fn, void *);
-extern int is_repository_shallow(void);
+extern int is_repository_shallow(struct repository *r);
 extern struct commit_list *get_shallow_commits(struct object_array *heads,
                int depth, int shallow_flag, int not_shallow_flag);
 extern struct commit_list *get_shallow_commits_by_rev_list(
                int ac, const char **av, int shallow_flag, int not_shallow_flag);
-extern void set_alternate_shallow_file(const char *path, int override);
+extern void set_alternate_shallow_file(struct repository *r, const char *path, int override);
 extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
                                 const struct oid_array *extra);
 extern void setup_alternate_shallow(struct lock_file *shallow_lock,
index 6ded1c859f1b5ae1ffe035ac228c0f8a5298097a..858ca14a57351062d2bba147c72ed460fb0aa533 100644 (file)
@@ -341,12 +341,44 @@ int mingw_mkdir(const char *path, int mode)
        return ret;
 }
 
+static int mingw_open_append(wchar_t const *wfilename, int oflags, ...)
+{
+       HANDLE handle;
+       int fd;
+       DWORD create = (oflags & O_CREAT) ? OPEN_ALWAYS : OPEN_EXISTING;
+
+       /* only these flags are supported */
+       if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND))
+               return errno = ENOSYS, -1;
+
+       /*
+        * FILE_SHARE_WRITE is required to permit child processes
+        * to append to the file.
+        */
+       handle = CreateFileW(wfilename, FILE_APPEND_DATA,
+                       FILE_SHARE_WRITE | FILE_SHARE_READ,
+                       NULL, create, FILE_ATTRIBUTE_NORMAL, NULL);
+       if (handle == INVALID_HANDLE_VALUE)
+               return errno = err_win_to_posix(GetLastError()), -1;
+       /*
+        * No O_APPEND here, because the CRT uses it only to reset the
+        * file pointer to EOF on write(); but that is not necessary
+        * for a file created with FILE_APPEND_DATA.
+        */
+       fd = _open_osfhandle((intptr_t)handle, O_BINARY);
+       if (fd < 0)
+               CloseHandle(handle);
+       return fd;
+}
+
 int mingw_open (const char *filename, int oflags, ...)
 {
+       typedef int (*open_fn_t)(wchar_t const *wfilename, int oflags, ...);
        va_list args;
        unsigned mode;
        int fd;
        wchar_t wfilename[MAX_PATH];
+       open_fn_t open_fn;
 
        va_start(args, oflags);
        mode = va_arg(args, int);
@@ -355,9 +387,14 @@ int mingw_open (const char *filename, int oflags, ...)
        if (filename && !strcmp(filename, "/dev/null"))
                filename = "nul";
 
+       if (oflags & O_APPEND)
+               open_fn = mingw_open_append;
+       else
+               open_fn = _wopen;
+
        if (xutftowcs_path(wfilename, filename) < 0)
                return -1;
-       fd = _wopen(wfilename, oflags, mode);
+       fd = open_fn(wfilename, oflags, mode);
 
        if (fd < 0 && (oflags & O_ACCMODE) != O_RDONLY && errno == EACCES) {
                DWORD attrs = GetFileAttributesW(wfilename);
@@ -375,7 +412,7 @@ int mingw_open (const char *filename, int oflags, ...)
                 * CREATE_ALWAYS flag of CreateFile()).
                 */
                if (fd < 0 && errno == EACCES)
-                       fd = _wopen(wfilename, oflags & ~O_CREAT, mode);
+                       fd = open_fn(wfilename, oflags & ~O_CREAT, mode);
                if (fd >= 0 && set_hidden_flag(wfilename, 1))
                        warning("could not mark '%s' as hidden.", filename);
        }
index df8a6574c9ac24722aec9baf046dab785d210cc4..60fd873fe801da608cdef1ac2bafd371a0855db0 100644 (file)
@@ -30,8 +30,8 @@ The Steps of Build Git with VS2008
    the git operations.
 
 3. Inside Git's directory run the command:
-       make common-cmds.h
-   to generate the common-cmds.h file needed to compile git.
+       make command-list.h
+   to generate the command-list.h file needed to compile git.
 
 4. Then either build Git with the GNU Make Makefile in the Git projects
    root
index f4a208a16607c2f3eb10c02d067808d46399b7a3..4446909229a0f7b14d7428ad9860c9a655c77df8 100644 (file)
--- a/config.c
+++ b/config.c
@@ -14,6 +14,7 @@
 #include "quote.h"
 #include "hashmap.h"
 #include "string-list.h"
+#include "object-store.h"
 #include "utf8.h"
 #include "dir.h"
 #include "color.h"
@@ -31,7 +32,7 @@ struct config_source {
        enum config_origin_type origin_type;
        const char *name;
        const char *path;
-       int die_on_error;
+       enum config_error_action default_error_action;
        int linenr;
        int eof;
        struct strbuf value;
@@ -116,12 +117,12 @@ static long config_buf_ftell(struct config_source *conf)
 }
 
 #define MAX_INCLUDE_DEPTH 10
-static const char include_depth_advice[] =
+static const char include_depth_advice[] = N_(
 "exceeded maximum include depth (%d) while including\n"
 "      %s\n"
 "from\n"
 "      %s\n"
-"Do you have circular includes?";
+"Do you have circular includes?");
 static int handle_path_include(const char *path, struct config_include_data *inc)
 {
        int ret = 0;
@@ -133,7 +134,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
 
        expanded = expand_user_path(path, 0);
        if (!expanded)
-               return error("could not expand include path '%s'", path);
+               return error(_("could not expand include path '%s'"), path);
        path = expanded;
 
        /*
@@ -144,7 +145,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
                char *slash;
 
                if (!cf || !cf->path)
-                       return error("relative config includes must come from files");
+                       return error(_("relative config includes must come from files"));
 
                slash = find_last_dir_sep(cf->path);
                if (slash)
@@ -155,7 +156,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
 
        if (!access_or_die(path, R_OK, 0)) {
                if (++inc->depth > MAX_INCLUDE_DEPTH)
-                       die(include_depth_advice, MAX_INCLUDE_DEPTH, path,
+                       die(_(include_depth_advice), MAX_INCLUDE_DEPTH, path,
                            !cf ? "<unknown>" :
                            cf->name ? cf->name :
                            "the command line");
@@ -342,13 +343,13 @@ static int git_config_parse_key_1(const char *key, char **store_key, int *basele
 
        if (last_dot == NULL || last_dot == key) {
                if (!quiet)
-                       error("key does not contain a section: %s", key);
+                       error(_("key does not contain a section: %s"), key);
                return -CONFIG_NO_SECTION_OR_NAME;
        }
 
        if (!last_dot[1]) {
                if (!quiet)
-                       error("key does not contain variable name: %s", key);
+                       error(_("key does not contain variable name: %s"), key);
                return -CONFIG_NO_SECTION_OR_NAME;
        }
 
@@ -372,13 +373,13 @@ static int git_config_parse_key_1(const char *key, char **store_key, int *basele
                        if (!iskeychar(c) ||
                            (i == baselen + 1 && !isalpha(c))) {
                                if (!quiet)
-                                       error("invalid key: %s", key);
+                                       error(_("invalid key: %s"), key);
                                goto out_free_ret_1;
                        }
                        c = tolower(c);
                } else if (c == '\n') {
                        if (!quiet)
-                               error("invalid key (newline): %s", key);
+                               error(_("invalid key (newline): %s"), key);
                        goto out_free_ret_1;
                }
                if (store_key)
@@ -414,7 +415,7 @@ int git_config_parse_parameter(const char *text,
 
        pair = strbuf_split_str(text, '=', 2);
        if (!pair[0])
-               return error("bogus config parameter: %s", text);
+               return error(_("bogus config parameter: %s"), text);
 
        if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=') {
                strbuf_setlen(pair[0], pair[0]->len - 1);
@@ -426,7 +427,7 @@ int git_config_parse_parameter(const char *text,
        strbuf_trim(pair[0]);
        if (!pair[0]->len) {
                strbuf_list_free(pair);
-               return error("bogus config parameter: %s", text);
+               return error(_("bogus config parameter: %s"), text);
        }
 
        if (git_config_parse_key(pair[0]->buf, &canonical_name, NULL)) {
@@ -461,7 +462,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
        envw = xstrdup(env);
 
        if (sq_dequote_to_argv(envw, &argv, &nr, &alloc) < 0) {
-               ret = error("bogus format in " CONFIG_DATA_ENVIRONMENT);
+               ret = error(_("bogus format in %s"), CONFIG_DATA_ENVIRONMENT);
                goto out;
        }
 
@@ -809,10 +810,21 @@ static int git_parse_source(config_fn_t fn, void *data,
                                      cf->linenr, cf->name);
        }
 
-       if (cf->die_on_error)
+       switch (opts && opts->error_action ?
+               opts->error_action :
+               cf->default_error_action) {
+       case CONFIG_ERROR_DIE:
                die("%s", error_msg);
-       else
+               break;
+       case CONFIG_ERROR_ERROR:
                error_return = error("%s", error_msg);
+               break;
+       case CONFIG_ERROR_SILENT:
+               error_return = -1;
+               break;
+       case CONFIG_ERROR_UNSET:
+               BUG("config error action unset");
+       }
 
        free(error_msg);
        return error_return;
@@ -921,7 +933,7 @@ int git_parse_ulong(const char *value, unsigned long *ret)
        return 1;
 }
 
-static int git_parse_ssize_t(const char *value, ssize_t *ret)
+int git_parse_ssize_t(const char *value, ssize_t *ret)
 {
        intmax_t tmp;
        if (!git_parse_signed(value, &tmp, maximum_signed_value_of_type(ssize_t)))
@@ -1154,7 +1166,7 @@ static int git_default_core_config(const char *var, const char *value)
                else {
                        int abbrev = git_config_int(var, value);
                        if (abbrev < minimum_abbrev || abbrev > 40)
-                               return error("abbrev length out of range: %d", abbrev);
+                               return error(_("abbrev length out of range: %d"), abbrev);
                        default_abbrev = abbrev;
                }
                return 0;
@@ -1271,7 +1283,7 @@ static int git_default_core_config(const char *var, const char *value)
                        comment_line_char = value[0];
                        auto_comment_line_char = 0;
                } else
-                       return error("core.commentChar should only be one character");
+                       return error(_("core.commentChar should only be one character"));
                return 0;
        }
 
@@ -1308,11 +1320,6 @@ static int git_default_core_config(const char *var, const char *value)
                return 0;
        }
 
-       if (!strcmp(var, "core.commitgraph")) {
-               core_commit_graph = git_config_bool(var, value);
-               return 0;
-       }
-
        if (!strcmp(var, "core.sparsecheckout")) {
                core_apply_sparse_checkout = git_config_bool(var, value);
                return 0;
@@ -1346,6 +1353,11 @@ static int git_default_core_config(const char *var, const char *value)
                                         var, value);
        }
 
+       if (!strcmp(var, "core.usereplacerefs")) {
+               read_replace_refs = git_config_bool(var, value);
+               return 0;
+       }
+
        /* Add other config variables here and to Documentation/config.txt. */
        return 0;
 }
@@ -1384,7 +1396,7 @@ static int git_default_branch_config(const char *var, const char *value)
                else if (!strcmp(value, "always"))
                        autorebase = AUTOREBASE_ALWAYS;
                else
-                       return error("malformed value for %s", var);
+                       return error(_("malformed value for %s"), var);
                return 0;
        }
 
@@ -1410,9 +1422,9 @@ static int git_default_push_config(const char *var, const char *value)
                else if (!strcmp(value, "current"))
                        push_default = PUSH_DEFAULT_CURRENT;
                else {
-                       error("malformed value for %s: %s", var, value);
-                       return error("Must be one of nothing, matching, simple, "
-                                    "upstream or current.");
+                       error(_("malformed value for %s: %s"), var, value);
+                       return error(_("must be one of nothing, matching, simple, "
+                                      "upstream or current"));
                }
                return 0;
        }
@@ -1520,7 +1532,7 @@ static int do_config_from_file(config_fn_t fn,
        top.origin_type = origin_type;
        top.name = name;
        top.path = path;
-       top.die_on_error = 1;
+       top.default_error_action = CONFIG_ERROR_DIE;
        top.do_fgetc = config_file_fgetc;
        top.do_ungetc = config_file_ungetc;
        top.do_ftell = config_file_ftell;
@@ -1558,8 +1570,10 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
        return git_config_from_file_with_options(fn, filename, data, NULL);
 }
 
-int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_type,
-                       const char *name, const char *buf, size_t len, void *data)
+int git_config_from_mem(config_fn_t fn,
+                       const enum config_origin_type origin_type,
+                       const char *name, const char *buf, size_t len,
+                       void *data, const struct config_options *opts)
 {
        struct config_source top;
 
@@ -1569,12 +1583,12 @@ int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_typ
        top.origin_type = origin_type;
        top.name = name;
        top.path = NULL;
-       top.die_on_error = 0;
+       top.default_error_action = CONFIG_ERROR_ERROR;
        top.do_fgetc = config_buf_fgetc;
        top.do_ungetc = config_buf_ungetc;
        top.do_ftell = config_buf_ftell;
 
-       return do_config_from(&top, fn, data, NULL);
+       return do_config_from(&top, fn, data, opts);
 }
 
 int git_config_from_blob_oid(config_fn_t fn,
@@ -1589,13 +1603,14 @@ int git_config_from_blob_oid(config_fn_t fn,
 
        buf = read_object_file(oid, &type, &size);
        if (!buf)
-               return error("unable to load config blob object '%s'", name);
+               return error(_("unable to load config blob object '%s'"), name);
        if (type != OBJ_BLOB) {
                free(buf);
-               return error("reference '%s' does not point to a blob", name);
+               return error(_("reference '%s' does not point to a blob"), name);
        }
 
-       ret = git_config_from_mem(fn, CONFIG_ORIGIN_BLOB, name, buf, size, data);
+       ret = git_config_from_mem(fn, CONFIG_ORIGIN_BLOB, name, buf, size,
+                                 data, NULL);
        free(buf);
 
        return ret;
@@ -1608,7 +1623,7 @@ static int git_config_from_blob_ref(config_fn_t fn,
        struct object_id oid;
 
        if (get_oid(name, &oid) < 0)
-               return error("unable to resolve config blob '%s'", name);
+               return error(_("unable to resolve config blob '%s'"), name);
        return git_config_from_blob_oid(fn, name, &oid, data);
 }
 
@@ -1638,7 +1653,7 @@ unsigned long git_env_ulong(const char *k, unsigned long val)
 {
        const char *v = getenv(k);
        if (v && !git_parse_ulong(v, &val))
-               die("failed to parse %s", k);
+               die(_("failed to parse %s"), k);
        return val;
 }
 
@@ -2172,23 +2187,6 @@ int git_config_get_pathname(const char *key, const char **dest)
        return repo_config_get_pathname(the_repository, key, dest);
 }
 
-/*
- * Note: This function exists solely to maintain backward compatibility with
- * 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should
- * NOT be used anywhere else.
- *
- * Runs the provided config function on the '.gitmodules' file found in the
- * working directory.
- */
-void config_from_gitmodules(config_fn_t fn, void *data)
-{
-       if (the_repository->worktree) {
-               char *file = repo_worktree_path(the_repository, GITMODULES_FILE);
-               git_config_from_file(fn, file, data);
-               free(file);
-       }
-}
-
 int git_config_get_expiry(const char *key, const char **output)
 {
        int ret = git_config_get_string_const(key, output);
@@ -2372,7 +2370,7 @@ static int store_aux_event(enum config_event_t type,
 
        if (type == CONFIG_EVENT_SECTION) {
                if (cf->var.len < 2 || cf->var.buf[cf->var.len - 1] != '.')
-                       return error("invalid section name '%s'", cf->var.buf);
+                       return error(_("invalid section name '%s'"), cf->var.buf);
 
                /* Is this the section we were looking for? */
                store->is_keys_section =
@@ -2428,7 +2426,7 @@ static int store_aux(const char *key, const char *value, void *cb)
 
 static int write_error(const char *filename)
 {
-       error("failed to write new configuration file %s", filename);
+       error(_("failed to write new configuration file %s"), filename);
 
        /* Same error code as "failed to rename". */
        return 4;
@@ -2679,7 +2677,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
         */
        fd = hold_lock_file_for_update(&lock, config_filename, 0);
        if (fd < 0) {
-               error_errno("could not lock config file %s", config_filename);
+               error_errno(_("could not lock config file %s"), config_filename);
                ret = CONFIG_NO_LOCK;
                goto out_free;
        }
@@ -2690,7 +2688,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
        in_fd = open(config_filename, O_RDONLY);
        if ( in_fd < 0 ) {
                if ( ENOENT != errno ) {
-                       error_errno("opening %s", config_filename);
+                       error_errno(_("opening %s"), config_filename);
                        ret = CONFIG_INVALID_FILE; /* same as "invalid config file" */
                        goto out_free;
                }
@@ -2725,7 +2723,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
                        store.value_regex = (regex_t*)xmalloc(sizeof(regex_t));
                        if (regcomp(store.value_regex, value_regex,
                                        REG_EXTENDED)) {
-                               error("invalid pattern: %s", value_regex);
+                               error(_("invalid pattern: %s"), value_regex);
                                FREE_AND_NULL(store.value_regex);
                                ret = CONFIG_INVALID_PATTERN;
                                goto out_free;
@@ -2750,7 +2748,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
                if (git_config_from_file_with_options(store_aux,
                                                      config_filename,
                                                      &store, &opts)) {
-                       error("invalid config file %s", config_filename);
+                       error(_("invalid config file %s"), config_filename);
                        ret = CONFIG_INVALID_FILE;
                        goto out_free;
                }
@@ -2774,7 +2772,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
                if (contents == MAP_FAILED) {
                        if (errno == ENODEV && S_ISDIR(st.st_mode))
                                errno = EISDIR;
-                       error_errno("unable to mmap '%s'", config_filename);
+                       error_errno(_("unable to mmap '%s'"), config_filename);
                        ret = CONFIG_INVALID_FILE;
                        contents = NULL;
                        goto out_free;
@@ -2783,7 +2781,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
                in_fd = -1;
 
                if (chmod(get_lock_file_path(&lock), st.st_mode & 07777) < 0) {
-                       error_errno("chmod on %s failed", get_lock_file_path(&lock));
+                       error_errno(_("chmod on %s failed"), get_lock_file_path(&lock));
                        ret = CONFIG_NO_WRITE;
                        goto out_free;
                }
@@ -2868,7 +2866,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
        }
 
        if (commit_lock_file(&lock) < 0) {
-               error_errno("could not write config file %s", config_filename);
+               error_errno(_("could not write config file %s"), config_filename);
                ret = CONFIG_NO_WRITE;
                goto out_free;
        }
@@ -2994,7 +2992,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
        memset(&store, 0, sizeof(store));
 
        if (new_name && !section_name_is_ok(new_name)) {
-               ret = error("invalid section name: %s", new_name);
+               ret = error(_("invalid section name: %s"), new_name);
                goto out_no_rollback;
        }
 
@@ -3003,7 +3001,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
 
        out_fd = hold_lock_file_for_update(&lock, config_filename, 0);
        if (out_fd < 0) {
-               ret = error("could not lock config file %s", config_filename);
+               ret = error(_("could not lock config file %s"), config_filename);
                goto out;
        }
 
@@ -3021,7 +3019,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
        }
 
        if (chmod(get_lock_file_path(&lock), st.st_mode & 07777) < 0) {
-               ret = error_errno("chmod on %s failed",
+               ret = error_errno(_("chmod on %s failed"),
                                  get_lock_file_path(&lock));
                goto out;
        }
@@ -3118,7 +3116,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
        config_file = NULL;
 commit_and_out:
        if (commit_lock_file(&lock) < 0)
-               ret = error_errno("could not write config file %s",
+               ret = error_errno(_("could not write config file %s"),
                                  config_filename);
 out:
        if (config_file)
@@ -3161,7 +3159,7 @@ int git_config_copy_section(const char *old_name, const char *new_name)
 #undef config_error_nonbool
 int config_error_nonbool(const char *var)
 {
-       return error("missing value for '%s'", var);
+       return error(_("missing value for '%s'"), var);
 }
 
 int parse_config_key(const char *var,
index 626d4654bd6f98771be903cca208fdb368920bf4..2d5c18b05f85e1a6a7f954442f5d7565e9769212 100644 (file)
--- a/config.h
+++ b/config.h
@@ -54,6 +54,12 @@ struct config_options {
        const char *git_dir;
        config_parser_event_fn_t event_fn;
        void *event_fn_data;
+       enum config_error_action {
+               CONFIG_ERROR_UNSET = 0, /* use source-specific default */
+               CONFIG_ERROR_DIE, /* die() on error */
+               CONFIG_ERROR_ERROR, /* error() on error, return -1 */
+               CONFIG_ERROR_SILENT, /* return -1 */
+       } error_action;
 };
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
@@ -62,8 +68,11 @@ extern int git_config_from_file(config_fn_t fn, const char *, void *);
 extern int git_config_from_file_with_options(config_fn_t fn, const char *,
                                             void *,
                                             const struct config_options *);
-extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
-                                       const char *name, const char *buf, size_t len, void *data);
+extern int git_config_from_mem(config_fn_t fn,
+                              const enum config_origin_type,
+                              const char *name,
+                              const char *buf, size_t len,
+                              void *data, const struct config_options *opts);
 extern int git_config_from_blob_oid(config_fn_t fn, const char *name,
                                    const struct object_id *oid, void *data);
 extern void git_config_push_parameter(const char *text);
@@ -73,6 +82,7 @@ extern void git_config(config_fn_t fn, void *);
 extern int config_with_options(config_fn_t fn, void *,
                               struct git_config_source *config_source,
                               const struct config_options *opts);
+extern int git_parse_ssize_t(const char *, ssize_t *);
 extern int git_parse_ulong(const char *, unsigned long *);
 extern int git_parse_maybe_bool(const char *);
 extern int git_config_int(const char *, const char *);
@@ -179,9 +189,14 @@ struct config_set {
 
 extern void git_configset_init(struct config_set *cs);
 extern int git_configset_add_file(struct config_set *cs, const char *filename);
-extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value);
 extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key);
 extern void git_configset_clear(struct config_set *cs);
+
+/*
+ * These functions return 1 if not found, and 0 if found, leaving the found
+ * value in the 'dest' pointer.
+ */
+extern int git_configset_get_value(struct config_set *cs, const char *key, const char **dest);
 extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest);
 extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
 extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest);
@@ -215,16 +230,6 @@ extern int repo_config_get_maybe_bool(struct repository *repo,
 extern int repo_config_get_pathname(struct repository *repo,
                                    const char *key, const char **dest);
 
-/*
- * Note: This function exists solely to maintain backward compatibility with
- * 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should
- * NOT be used anywhere else.
- *
- * Runs the provided config function on the '.gitmodules' file found in the
- * working directory.
- */
-extern void config_from_gitmodules(config_fn_t fn, void *data);
-
 extern int git_config_get_value(const char *key, const char **value);
 extern const struct string_list *git_config_get_value_multi(const char *key);
 extern void git_config_clear(void);
index 2d244ca470d8d99f54034b1494127db25c5161ad..9a998149d99a8eeebf311d5e84d43f146ed0f90d 100644 (file)
@@ -1,6 +1,11 @@
 ifeq ($(filter no-error,$(DEVOPTS)),)
 CFLAGS += -Werror
 endif
+ifneq ($(filter pedantic,$(DEVOPTS)),)
+CFLAGS += -pedantic
+# don't warn for each N_ use
+CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0
+endif
 CFLAGS += -Wdeclaration-after-statement
 CFLAGS += -Wno-format-zero-length
 CFLAGS += -Wold-style-definition
index 684fc5bf02677bbaddd214f78b14fa55df7025c2..2be2f19811394360601db5cf1aff0208fe740ae1 100644 (file)
@@ -528,7 +528,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
        COMPAT_OBJS += compat/mingw.o compat/winansi.o \
                compat/win32/pthread.o compat/win32/syslog.o \
                compat/win32/dirent.o
-       BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
+       BASIC_CFLAGS += -DWIN32 -DPROTECT_NTFS_DEFAULT=1
        EXTLIBS += -lws2_32
        GITLIBS += git.res
        PTHREAD_LIBS =
index 968e91b18c09e5ac814328e0f833e2d4aa91cf2c..94547e5056b008d9cd9d00680a795d833e1f0528 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -58,7 +58,7 @@ static NORETURN void die_initial_contact(int unexpected)
         * response does not necessarily mean an ACL problem, though.
         */
        if (unexpected)
-               die(_("The remote end hung up upon initial contact"));
+               die(_("the remote end hung up upon initial contact"));
        else
                die(_("Could not read from remote repository.\n\n"
                      "Please make sure you have the correct access rights\n"
@@ -78,7 +78,7 @@ int server_supports_v2(const char *c, int die_on_error)
        }
 
        if (die_on_error)
-               die("server doesn't support '%s'", c);
+               die(_("server doesn't support '%s'"), c);
 
        return 0;
 }
@@ -100,7 +100,7 @@ int server_supports_feature(const char *c, const char *feature,
        }
 
        if (die_on_error)
-               die("server doesn't support feature '%s'", feature);
+               die(_("server doesn't support feature '%s'"), feature);
 
        return 0;
 }
@@ -111,7 +111,7 @@ static void process_capabilities_v2(struct packet_reader *reader)
                argv_array_push(&server_capabilities_v2, reader->line);
 
        if (reader->status != PACKET_READ_FLUSH)
-               die("expected flush after capabilities");
+               die(_("expected flush after capabilities"));
 }
 
 enum protocol_version discover_version(struct packet_reader *reader)
@@ -230,7 +230,7 @@ static int process_dummy_ref(const char *line)
 static void check_no_capabilities(const char *line, int len)
 {
        if (strlen(line) != len)
-               warning("Ignoring capabilities after first line '%s'",
+               warning(_("ignoring capabilities after first line '%s'"),
                        line + strlen(line));
 }
 
@@ -249,7 +249,7 @@ static int process_ref(const char *line, int len, struct ref ***list,
        if (extra_have && !strcmp(name, ".have")) {
                oid_array_append(extra_have, &old_oid);
        } else if (!strcmp(name, "capabilities^{}")) {
-               die("protocol error: unexpected capabilities^{}");
+               die(_("protocol error: unexpected capabilities^{}"));
        } else if (check_ref(name, flags)) {
                struct ref *ref = alloc_ref(name);
                oidcpy(&ref->old_oid, &old_oid);
@@ -270,9 +270,9 @@ static int process_shallow(const char *line, int len,
                return 0;
 
        if (get_oid_hex(arg, &old_oid))
-               die("protocol error: expected shallow sha-1, got '%s'", arg);
+               die(_("protocol error: expected shallow sha-1, got '%s'"), arg);
        if (!shallow_points)
-               die("repository on the other end cannot be shallow");
+               die(_("repository on the other end cannot be shallow"));
        oid_array_append(shallow_points, &old_oid);
        check_no_capabilities(line, len);
        return 1;
@@ -307,13 +307,13 @@ struct ref **get_remote_heads(struct packet_reader *reader,
                case PACKET_READ_NORMAL:
                        len = reader->pktlen;
                        if (len > 4 && skip_prefix(reader->line, "ERR ", &arg))
-                               die("remote error: %s", arg);
+                               die(_("remote error: %s"), arg);
                        break;
                case PACKET_READ_FLUSH:
                        state = EXPECTING_DONE;
                        break;
                case PACKET_READ_DELIM:
-                       die("invalid packet");
+                       die(_("invalid packet"));
                }
 
                switch (state) {
@@ -333,7 +333,7 @@ struct ref **get_remote_heads(struct packet_reader *reader,
                case EXPECTING_SHALLOW:
                        if (process_shallow(reader->line, len, shallow_points))
                                break;
-                       die("protocol error: unexpected '%s'", reader->line);
+                       die(_("protocol error: unexpected '%s'"), reader->line);
                case EXPECTING_DONE:
                        break;
                }
@@ -441,11 +441,11 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
        /* Process response from server */
        while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
                if (!process_ref_v2(reader->line, &list))
-                       die("invalid ls-refs response: %s", reader->line);
+                       die(_("invalid ls-refs response: %s"), reader->line);
        }
 
        if (reader->status != PACKET_READ_FLUSH)
-               die("expected flush after ref listing");
+               die(_("expected flush after ref listing"));
 
        return list;
 }
@@ -544,7 +544,7 @@ static enum protocol get_protocol(const char *name)
                return PROTO_SSH;
        if (!strcmp(name, "file"))
                return PROTO_FILE;
-       die("I don't handle protocol '%s'", name);
+       die(_("protocol '%s' is not supported"), name);
 }
 
 static char *host_end(char **hoststart, int removebrackets)
@@ -595,8 +595,7 @@ static void enable_keepalive(int sockfd)
        int ka = 1;
 
        if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &ka, sizeof(ka)) < 0)
-               fprintf(stderr, "unable to set SO_KEEPALIVE on socket: %s\n",
-                       strerror(errno));
+               error_errno(_("unable to set SO_KEEPALIVE on socket"));
 }
 
 #ifndef NO_IPV6
@@ -636,14 +635,15 @@ static int git_tcp_connect_sock(char *host, int flags)
        hints.ai_protocol = IPPROTO_TCP;
 
        if (flags & CONNECT_VERBOSE)
-               fprintf(stderr, "Looking up %s ... ", host);
+               fprintf(stderr, _("Looking up %s ... "), host);
 
        gai = getaddrinfo(host, port, &hints, &ai);
        if (gai)
-               die("Unable to look up %s (port %s) (%s)", host, port, gai_strerror(gai));
+               die(_("unable to look up %s (port %s) (%s)"), host, port, gai_strerror(gai));
 
        if (flags & CONNECT_VERBOSE)
-               fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port);
+               /* TRANSLATORS: this is the end of "Looking up %s ... " */
+               fprintf(stderr, _("done.\nConnecting to %s (port %s) ... "), host, port);
 
        for (ai0 = ai; ai; ai = ai->ai_next, cnt++) {
                sockfd = socket(ai->ai_family,
@@ -665,12 +665,13 @@ static int git_tcp_connect_sock(char *host, int flags)
        freeaddrinfo(ai0);
 
        if (sockfd < 0)
-               die("unable to connect to %s:\n%s", host, error_message.buf);
+               die(_("unable to connect to %s:\n%s"), host, error_message.buf);
 
        enable_keepalive(sockfd);
 
        if (flags & CONNECT_VERBOSE)
-               fprintf(stderr, "done.\n");
+               /* TRANSLATORS: this is the end of "Connecting to %s (port %s) ... " */
+               fprintf_ln(stderr, _("done."));
 
        strbuf_release(&error_message);
 
@@ -697,22 +698,23 @@ static int git_tcp_connect_sock(char *host, int flags)
        get_host_and_port(&host, &port);
 
        if (flags & CONNECT_VERBOSE)
-               fprintf(stderr, "Looking up %s ... ", host);
+               fprintf(stderr, _("Looking up %s ... "), host);
 
        he = gethostbyname(host);
        if (!he)
-               die("Unable to look up %s (%s)", host, hstrerror(h_errno));
+               die(_("unable to look up %s (%s)"), host, hstrerror(h_errno));
        nport = strtoul(port, &ep, 10);
        if ( ep == port || *ep ) {
                /* Not numeric */
                struct servent *se = getservbyname(port,"tcp");
                if ( !se )
-                       die("Unknown port %s", port);
+                       die(_("unknown port %s"), port);
                nport = se->s_port;
        }
 
        if (flags & CONNECT_VERBOSE)
-               fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port);
+               /* TRANSLATORS: this is the end of "Looking up %s ... " */
+               fprintf(stderr, _("done.\nConnecting to %s (port %s) ... "), host, port);
 
        for (cnt = 0, ap = he->h_addr_list; *ap; ap++, cnt++) {
                memset(&sa, 0, sizeof sa);
@@ -740,12 +742,13 @@ static int git_tcp_connect_sock(char *host, int flags)
        }
 
        if (sockfd < 0)
-               die("unable to connect to %s:\n%s", host, error_message.buf);
+               die(_("unable to connect to %s:\n%s"), host, error_message.buf);
 
        enable_keepalive(sockfd);
 
        if (flags & CONNECT_VERBOSE)
-               fprintf(stderr, "done.\n");
+               /* TRANSLATORS: this is the end of "Connecting to %s (port %s) ... " */
+               fprintf_ln(stderr, _("done."));
 
        return sockfd;
 }
@@ -842,9 +845,9 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
        get_host_and_port(&host, &port);
 
        if (looks_like_command_line_option(host))
-               die("strange hostname '%s' blocked", host);
+               die(_("strange hostname '%s' blocked"), host);
        if (looks_like_command_line_option(port))
-               die("strange port '%s' blocked", port);
+               die(_("strange port '%s' blocked"), port);
 
        proxy = xmalloc(sizeof(*proxy));
        child_process_init(proxy);
@@ -854,7 +857,7 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
        proxy->in = -1;
        proxy->out = -1;
        if (start_command(proxy))
-               die("cannot start proxy %s", git_proxy_command);
+               die(_("cannot start proxy %s"), git_proxy_command);
        fd[0] = proxy->out; /* read from proxy stdout */
        fd[1] = proxy->in;  /* write to proxy stdin */
        return proxy;
@@ -921,7 +924,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
                path = strchr(end, separator);
 
        if (!path || !*path)
-               die("No path specified. See 'man git-pull' for valid url syntax");
+               die(_("no path specified; see 'git help pull' for valid url syntax"));
 
        /*
         * null-terminate hostname and point path to ~ for URL's like this:
@@ -1116,7 +1119,7 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
                case VARIANT_AUTO:
                        BUG("VARIANT_AUTO passed to push_ssh_options");
                case VARIANT_SIMPLE:
-                       die("ssh variant 'simple' does not support -4");
+                       die(_("ssh variant 'simple' does not support -4"));
                case VARIANT_SSH:
                case VARIANT_PLINK:
                case VARIANT_PUTTY:
@@ -1128,7 +1131,7 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
                case VARIANT_AUTO:
                        BUG("VARIANT_AUTO passed to push_ssh_options");
                case VARIANT_SIMPLE:
-                       die("ssh variant 'simple' does not support -6");
+                       die(_("ssh variant 'simple' does not support -6"));
                case VARIANT_SSH:
                case VARIANT_PLINK:
                case VARIANT_PUTTY:
@@ -1145,7 +1148,7 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
                case VARIANT_AUTO:
                        BUG("VARIANT_AUTO passed to push_ssh_options");
                case VARIANT_SIMPLE:
-                       die("ssh variant 'simple' does not support setting port");
+                       die(_("ssh variant 'simple' does not support setting port"));
                case VARIANT_SSH:
                        argv_array_push(args, "-p");
                        break;
@@ -1168,7 +1171,7 @@ static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
        enum ssh_variant variant;
 
        if (looks_like_command_line_option(ssh_host))
-               die("strange hostname '%s' blocked", ssh_host);
+               die(_("strange hostname '%s' blocked"), ssh_host);
 
        ssh = get_ssh_command();
        if (ssh) {
@@ -1256,7 +1259,7 @@ struct child_process *git_connect(int fd[2], const char *url,
                child_process_init(conn);
 
                if (looks_like_command_line_option(path))
-                       die("strange pathname '%s' blocked", path);
+                       die(_("strange pathname '%s' blocked"), path);
 
                strbuf_addstr(&cmd, prog);
                strbuf_addch(&cmd, ' ');
@@ -1301,7 +1304,7 @@ struct child_process *git_connect(int fd[2], const char *url,
                argv_array_push(&conn->args, cmd.buf);
 
                if (start_command(conn))
-                       die("unable to fork");
+                       die(_("unable to fork"));
 
                fd[0] = conn->out; /* read from child's stdout */
                fd[1] = conn->in;  /* write to child's stdin */
index 0e69c6709c9fdb83b4888443f490d79ef504c8a3..32aff60979512b7f1382482435a26c51882b9f16 100644 (file)
--- a/connect.h
+++ b/connect.h
@@ -1,6 +1,8 @@
 #ifndef CONNECT_H
 #define CONNECT_H
 
+#include "protocol.h"
+
 #define CONNECT_VERBOSE       (1u << 0)
 #define CONNECT_DIAG_URL      (1u << 1)
 #define CONNECT_IPV4          (1u << 2)
index 91feb7881545f4143f45b9eb3393de65739cfa92..1bba888eff90a23e586807fd02b274b8e7fac097 100644 (file)
@@ -58,8 +58,10 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
        argv_array_push(&rev_list.args, "--stdin");
        if (repository_format_partial_clone)
                argv_array_push(&rev_list.args, "--exclude-promisor-objects");
-       argv_array_push(&rev_list.args, "--not");
-       argv_array_push(&rev_list.args, "--all");
+       if (!opt->is_deepening_fetch) {
+               argv_array_push(&rev_list.args, "--not");
+               argv_array_push(&rev_list.args, "--all");
+       }
        argv_array_push(&rev_list.args, "--quiet");
        if (opt->progress)
                argv_array_pushf(&rev_list.args, "--progress=%s",
index a53f03a61aca4871be5ab75db9bf63ee895668e1..322dc7637263630712e5ab3e875720c5e39eda22 100644 (file)
@@ -38,6 +38,13 @@ struct check_connected_options {
         * Insert these variables into the environment of the child process.
         */
        const char **env;
+
+       /*
+        * If non-zero, check the ancestry chain completely, not stopping at
+        * any existing ref. This is necessary when deepening existing refs
+        * during a fetch.
+        */
+       unsigned is_deepening_fetch : 1;
 };
 
 #define CHECK_CONNECTED_INIT { 0 }
index a7e9215ffc370d945ba2ac28b7eff9e8cb1d0679..aec3345adb4f0fb83b511335e0727f1097f97e29 100644 (file)
@@ -12,7 +12,7 @@ expression c;
 
 // These excluded functions must access c->maybe_tree direcly.
 @@
-identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph|load_tree_for_commit)$";
+identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
 expression c;
 @@
   f(...) {...
index 94c95516ebec7f32787cc5a2fb45cae83c7e28e3..d63d2dffd4e12186e734adb0cc2ae7c1db7a6374 100644 (file)
@@ -1976,6 +1976,20 @@ _git_push ()
        __git_complete_remote_or_refspec
 }
 
+_git_range_diff ()
+{
+       case "$cur" in
+       --*)
+               __gitcomp "
+                       --creation-factor= --no-dual-color
+                       $__git_diff_common_options
+               "
+               return
+               ;;
+       esac
+       __git_complete_revlist
+}
+
 _git_rebase ()
 {
        __git_find_repo_path
index 4484bda41065af6f6e23c667a7bab59a8a1a61cc..2f618a7f978822a0453114df0ed0045d2cf8ace5 100644 (file)
@@ -25,6 +25,13 @@ git-jump will feed this to the editor:
 foo.c:2: printf("hello word!\n");
 -----------------------------------
 
+Or, when running 'git jump grep', column numbers will also be emitted,
+e.g. `git jump grep "hello"` would return:
+
+-----------------------------------
+foo.c:2:9: printf("hello word!\n");
+-----------------------------------
+
 Obviously this trivial case isn't that interesting; you could just open
 `foo.c` yourself. But when you have many changes scattered across a
 project, you can use the editor's support to "jump" from point to point.
@@ -35,7 +42,8 @@ Git-jump can generate four types of interesting lists:
 
   2. The beginning of any merge conflict markers.
 
-  3. Any grep matches.
+  3. Any grep matches, including the column of the first match on a
+     line.
 
   4. Any whitespace errors detected by `git diff --check`.
 
@@ -82,7 +90,7 @@ which does something similar to `git jump grep`. However, it is limited
 to positioning the cursor to the correct line in only the first file,
 leaving you to locate subsequent hits in that file or other files using
 the editor or pager. By contrast, git-jump provides the editor with a
-complete list of files and line numbers for each match.
+complete list of files, lines, and a column number for each match.
 
 
 Limitations
index 80ab0590bc92221e2b2f8f35b76f5a0cbb970f8b..931b0fe3a9483ea7394d6b30d36f92ebade09110 100755 (executable)
@@ -52,7 +52,7 @@ mode_merge() {
 # editor shows them to us in the status bar.
 mode_grep() {
        cmd=$(git config jump.grepCmd)
-       test -n "$cmd" || cmd="git grep -n"
+       test -n "$cmd" || cmd="git grep -n --column"
        $cmd "$@" |
        perl -pe '
        s/[ \t]+/ /g;
index 22f069db4896efcf0fd2a1a8912e72d9db3569ae..cfbfe7ddf622c46559c626360970df303a9eb8d1 100755 (executable)
@@ -247,7 +247,7 @@ test_expect_success 'Test of resistance to modification of category on wiki for
        wiki_editpage Notconsidered "this page will not appear on local" false &&
        wiki_editpage Othercategory "this page will not appear on local" false -c=Cattwo &&
        wiki_editpage Tobeedited "this page have been modified" true -c=Catone &&
-       wiki_delete_page Tobedeleted
+       wiki_delete_page Tobedeleted &&
        git clone -c remote.origin.categories="Catone" \
                mediawiki::'"$WIKI_URL"' mw_dir_14 &&
        wiki_getallpage ref_page_14 Catone &&
index d05c613c9718697f64bc2334dc9ae85bf473f13e..57ff4b25c17e5479e9dc058fd723d44faa23877b 100755 (executable)
@@ -540,26 +540,10 @@ test_expect_success 'make sure exactly the right set of files ends up in the sub
                git fetch .. subproj-br &&
                git merge FETCH_HEAD &&
 
-               chks="sub1
-sub2
-sub3
-sub4" &&
-               chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
-$chks
-TXT
-) &&
-               chkms="main-sub1
-main-sub2
-main-sub3
-main-sub4" &&
-               chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
-$chkms
-TXT
-) &&
-
-               subfiles=$(git ls-files) &&
-               check_equal "$subfiles" "$chkms
-$chks"
+               test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
+                       sub1 sub2 sub3 sub4 >expect &&
+               git ls-files >actual &&
+               test_cmp expect actual
        )
 '
 
@@ -606,25 +590,11 @@ test_expect_success 'make sure the subproj *only* contains commits that affect t
                git fetch .. subproj-br &&
                git merge FETCH_HEAD &&
 
-               chks="sub1
-sub2
-sub3
-sub4" &&
-               chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
-$chks
-TXT
-) &&
-               chkms="main-sub1
-main-sub2
-main-sub3
-main-sub4" &&
-               chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
-$chkms
-TXT
-) &&
-               allchanges=$(git log --name-only --pretty=format:"" | sort | sed "/^$/d") &&
-               check_equal "$allchanges" "$chkms
-$chks"
+               test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
+                       sub1 sub2 sub3 sub4 >expect &&
+               git log --name-only --pretty=format:"" >log &&
+               sort <log | sed "/^\$/ d" >actual &&
+               test_cmp expect actual
        )
 '
 
@@ -675,29 +645,16 @@ test_expect_success 'make sure exactly the right set of files ends up in the mai
                cd "$subtree_test_count" &&
                git subtree pull --prefix="sub dir" ./"sub proj" master &&
 
-               chkm="main1
-main2" &&
-               chks="sub1
-sub2
-sub3
-sub4" &&
-               chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
-$chks
-TXT
-) &&
-               chkms="main-sub1
-main-sub2
-main-sub3
-main-sub4" &&
-               chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
-$chkms
-TXT
-) &&
-               mainfiles=$(git ls-files) &&
-               check_equal "$mainfiles" "$chkm
-$chkms_sub
-$chks_sub"
-)
+               test_write_lines main1 main2 >chkm &&
+               test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
+               sed "s,^,sub dir/," chkms >chkms_sub &&
+               test_write_lines sub1 sub2 sub3 sub4 >chks &&
+               sed "s,^,sub dir/," chks >chks_sub &&
+
+               cat chkm chkms_sub chks_sub >expect &&
+               git ls-files >actual &&
+               test_cmp expect actual
+       )
 '
 
 next_test
@@ -708,7 +665,7 @@ test_expect_success 'make sure each filename changed exactly once in the entire
        test_create_commit "$subtree_test_count/sub proj" sub1 &&
        (
                cd "$subtree_test_count" &&
-               git config log.date relative
+               git config log.date relative &&
                git fetch ./"sub proj" master &&
                git subtree add --prefix="sub dir" FETCH_HEAD
        ) &&
@@ -748,37 +705,21 @@ test_expect_success 'make sure each filename changed exactly once in the entire
                cd "$subtree_test_count" &&
                git subtree pull --prefix="sub dir" ./"sub proj" master &&
 
-               chkm="main1
-main2" &&
-               chks="sub1
-sub2
-sub3
-sub4" &&
-               chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
-$chks
-TXT
-) &&
-               chkms="main-sub1
-main-sub2
-main-sub3
-main-sub4" &&
-               chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
-$chkms
-TXT
-) &&
+               test_write_lines main1 main2 >chkm &&
+               test_write_lines sub1 sub2 sub3 sub4 >chks &&
+               test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
+               sed "s,^,sub dir/," chkms >chkms_sub &&
 
                # main-sub?? and /"sub dir"/main-sub?? both change, because those are the
                # changes that were split into their own history.  And "sub dir"/sub?? never
                # change, since they were *only* changed in the subtree branch.
-               allchanges=$(git log --name-only --pretty=format:"" | sort | sed "/^$/d") &&
-               expected=''"$(cat <<TXT | sort
-$chkms
-$chkm
-$chks
-$chkms_sub
-TXT
-)"'' &&
-               check_equal "$allchanges" "$expected"
+               git log --name-only --pretty=format:"" >log &&
+               sort <log >sorted-log &&
+               sed "/^$/ d" sorted-log >actual &&
+
+               cat chkms chkm chks chkms_sub >expect-unsorted &&
+               sort expect-unsorted >expect &&
+               test_cmp expect actual
        )
 '
 
diff --git a/contrib/vscode/.gitattributes b/contrib/vscode/.gitattributes
new file mode 100644 (file)
index 0000000..e89f223
--- /dev/null
@@ -0,0 +1 @@
+init.sh whitespace=-indent-with-non-tab
diff --git a/contrib/vscode/README.md b/contrib/vscode/README.md
new file mode 100644 (file)
index 0000000..8202d62
--- /dev/null
@@ -0,0 +1,14 @@
+Configuration for VS Code
+=========================
+
+[VS Code](https://code.visualstudio.com/) is a lightweight but powerful source
+code editor which runs on your desktop and is available for
+[Windows](https://code.visualstudio.com/docs/setup/windows),
+[macOS](https://code.visualstudio.com/docs/setup/mac) and
+[Linux](https://code.visualstudio.com/docs/setup/linux). Among other languages,
+it has [support for C/C++ via an extension](https://github.com/Microsoft/vscode-cpptools).
+
+To start developing Git with VS Code, simply run the Unix shell script called
+`init.sh` in this directory, which creates the configuration files in
+`.vscode/` that VS Code consumes. `init.sh` needs access to `make` and `gcc`,
+so run the script in a Git SDK shell if you are using Windows.
diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh
new file mode 100755 (executable)
index 0000000..27de949
--- /dev/null
@@ -0,0 +1,375 @@
+#!/bin/sh
+
+die () {
+       echo "$*" >&2
+       exit 1
+}
+
+cd "$(dirname "$0")"/../.. ||
+die "Could not cd to top-level directory"
+
+mkdir -p .vscode ||
+die "Could not create .vscode/"
+
+# General settings
+
+cat >.vscode/settings.json.new <<\EOF ||
+{
+    "C_Cpp.intelliSenseEngine": "Default",
+    "C_Cpp.intelliSenseEngineFallback": "Disabled",
+    "[git-commit]": {
+        "editor.wordWrap": "wordWrapColumn",
+        "editor.wordWrapColumn": 72
+    },
+    "[c]": {
+        "editor.detectIndentation": false,
+        "editor.insertSpaces": false,
+        "editor.tabSize": 8,
+        "editor.wordWrap": "wordWrapColumn",
+        "editor.wordWrapColumn": 80,
+        "files.trimTrailingWhitespace": true
+    },
+    "files.associations": {
+        "*.h": "c",
+        "*.c": "c"
+    },
+    "cSpell.ignorePaths": [
+    ],
+    "cSpell.words": [
+        "DATAW",
+        "DBCACHED",
+        "DFCHECK",
+        "DTYPE",
+        "Hamano",
+        "HCAST",
+        "HEXSZ",
+        "HKEY",
+        "HKLM",
+        "IFGITLINK",
+        "IFINVALID",
+        "ISBROKEN",
+        "ISGITLINK",
+        "ISSYMREF",
+        "Junio",
+        "LPDWORD",
+        "LPPROC",
+        "LPWSTR",
+        "MSVCRT",
+        "NOARG",
+        "NOCOMPLETE",
+        "NOINHERIT",
+        "RENORMALIZE",
+        "STARTF",
+        "STARTUPINFOEXW",
+        "Schindelin",
+        "UCRT",
+        "YESNO",
+        "argcp",
+        "beginthreadex",
+        "committish",
+        "contentp",
+        "cpath",
+        "cpidx",
+        "ctim",
+        "dequote",
+        "envw",
+        "ewah",
+        "fdata",
+        "fherr",
+        "fhin",
+        "fhout",
+        "fragp",
+        "fsmonitor",
+        "hnsec",
+        "idents",
+        "includeif",
+        "interpr",
+        "iprog",
+        "isexe",
+        "iskeychar",
+        "kompare",
+        "mksnpath",
+        "mktag",
+        "mktree",
+        "mmblob",
+        "mmbuffer",
+        "mmfile",
+        "noenv",
+        "nparents",
+        "ntpath",
+        "ondisk",
+        "ooid",
+        "oplen",
+        "osdl",
+        "pnew",
+        "pold",
+        "ppinfo",
+        "pushf",
+        "pushv",
+        "rawsz",
+        "rebasing",
+        "reencode",
+        "repo",
+        "rerere",
+        "scld",
+        "sharedrepo",
+        "spawnv",
+        "spawnve",
+        "spawnvpe",
+        "strdup'ing",
+        "submodule",
+        "submodules",
+        "topath",
+        "topo",
+        "tpatch",
+        "unexecutable",
+        "unhide",
+        "unkc",
+        "unkv",
+        "unmark",
+        "unmatch",
+        "unsets",
+        "unshown",
+        "untracked",
+        "untrackedcache",
+        "unuse",
+        "upos",
+        "uval",
+        "vreportf",
+        "wargs",
+        "wargv",
+        "wbuffer",
+        "wcmd",
+        "wcsnicmp",
+        "wcstoutfdup",
+        "wdeltaenv",
+        "wdir",
+        "wenv",
+        "wenvblk",
+        "wenvcmp",
+        "wenviron",
+        "wenvpos",
+        "wenvsz",
+        "wfile",
+        "wfilename",
+        "wfopen",
+        "wfreopen",
+        "wfullpath",
+        "which'll",
+        "wlink",
+        "wmain",
+        "wmkdir",
+        "wmktemp",
+        "wnewpath",
+        "wotype",
+        "wpath",
+        "wpathname",
+        "wpgmptr",
+        "wpnew",
+        "wpointer",
+        "wpold",
+        "wpos",
+        "wputenv",
+        "wrmdir",
+        "wship",
+        "wtarget",
+        "wtemplate",
+        "wunlink",
+        "xcalloc",
+        "xgetcwd",
+        "xmallocz",
+        "xmemdupz",
+        "xmmap",
+        "xopts",
+        "xrealloc",
+        "xsnprintf",
+        "xutftowcs",
+        "xutftowcsn",
+        "xwcstoutf"
+    ],
+    "cSpell.ignoreRegExpList": [
+        "\\\"(DIRC|FSMN|REUC|UNTR)\\\"",
+        "\\\\u[0-9a-fA-Fx]{4}\\b",
+        "\\b(filfre|frotz|xyzzy)\\b",
+        "\\bCMIT_FMT_DEFAULT\\b",
+        "\\bde-munge\\b",
+        "\\bGET_OID_DISAMBIGUATORS\\b",
+        "\\bHASH_RENORMALIZE\\b",
+        "\\bTREESAMEness\\b",
+        "\\bUSE_STDEV\\b",
+        "\\Wchar *\\*\\W*utfs\\W",
+        "cURL's",
+        "nedmalloc'ed",
+        "ntifs\\.h",
+    ],
+}
+EOF
+die "Could not write settings.json"
+
+# Infer some setup-specific locations/names
+
+GCCPATH="$(which gcc)"
+GDBPATH="$(which gdb)"
+MAKECOMMAND="make -j5 DEVELOPER=1"
+OSNAME=
+X=
+case "$(uname -s)" in
+MINGW*)
+       GCCPATH="$(cygpath -am "$GCCPATH")"
+       GDBPATH="$(cygpath -am "$GDBPATH")"
+       MAKE_BASH="$(cygpath -am /git-cmd.exe) --command=usr\\\\bin\\\\bash.exe"
+       MAKECOMMAND="$MAKE_BASH -lc \\\"$MAKECOMMAND\\\""
+       OSNAME=Win32
+       X=.exe
+       ;;
+Linux)
+       OSNAME=Linux
+       ;;
+Darwin)
+       OSNAME=macOS
+       ;;
+esac
+
+# Default build task
+
+cat >.vscode/tasks.json.new <<EOF ||
+{
+    // See https://go.microsoft.com/fwlink/?LinkId=733558
+    // for the documentation about the tasks.json format
+    "version": "2.0.0",
+    "tasks": [
+        {
+            "label": "make",
+            "type": "shell",
+            "command": "$MAKECOMMAND",
+            "group": {
+                "kind": "build",
+                "isDefault": true
+            }
+        }
+    ]
+}
+EOF
+die "Could not install default build task"
+
+# Debugger settings
+
+cat >.vscode/launch.json.new <<EOF ||
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit:
+    // https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "(gdb) Launch",
+            "type": "cppdbg",
+            "request": "launch",
+            "program": "\${workspaceFolder}/git$X",
+            "args": [],
+            "stopAtEntry": false,
+            "cwd": "\${workspaceFolder}",
+            "environment": [],
+            "externalConsole": true,
+            "MIMode": "gdb",
+            "miDebuggerPath": "$GDBPATH",
+            "setupCommands": [
+                {
+                    "description": "Enable pretty-printing for gdb",
+                    "text": "-enable-pretty-printing",
+                    "ignoreFailures": true
+                }
+            ]
+        }
+    ]
+}
+EOF
+die "Could not write launch configuration"
+
+# C/C++ extension settings
+
+make -f - OSNAME=$OSNAME GCCPATH="$GCCPATH" vscode-init \
+       >.vscode/c_cpp_properties.json <<\EOF ||
+include Makefile
+
+vscode-init:
+       @mkdir -p .vscode && \
+       incs= && defs= && \
+       for e in $(ALL_CFLAGS) \
+                       '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
+                       '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
+                       '-DBINDIR="$(bindir_relative_SQ)"' \
+                       '-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"' \
+                       '-DDEFAULT_GIT_TEMPLATE_DIR="$(template_dir_SQ)"' \
+                       '-DETC_GITCONFIG="$(ETC_GITCONFIG_SQ)"' \
+                       '-DETC_GITATTRIBUTES="$(ETC_GITATTRIBUTES_SQ)"' \
+                       '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
+                       '-DCURL_DISABLE_TYPECHECK', \
+                       '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
+                       '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
+                       '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'; do \
+               case "$$e" in \
+               -I.) \
+                       incs="$$(printf '% 16s"$${workspaceRoot}",\n%s' \
+                               "" "$$incs")" \
+                       ;; \
+               -I/*) \
+                       incs="$$(printf '% 16s"%s",\n%s' \
+                               "" "$${e#-I}" "$$incs")" \
+                       ;; \
+               -I*) \
+                       incs="$$(printf '% 16s"$${workspaceRoot}/%s",\n%s' \
+                               "" "$${e#-I}" "$$incs")" \
+                       ;; \
+               -D*) \
+                       defs="$$(printf '% 16s"%s",\n%s' \
+                               "" "$$(echo "$${e#-D}" | sed 's/"/\\&/g')" \
+                               "$$defs")" \
+                       ;; \
+               esac; \
+       done && \
+       echo '{' && \
+       echo '    "configurations": [' && \
+       echo '        {' && \
+       echo '            "name": "$(OSNAME)",' && \
+       echo '            "intelliSenseMode": "clang-x64",' && \
+       echo '            "includePath": [' && \
+       echo "$$incs" | sort | sed '$$s/,$$//' && \
+       echo '            ],' && \
+       echo '            "defines": [' && \
+       echo "$$defs" | sort | sed '$$s/,$$//' && \
+       echo '            ],' && \
+       echo '            "browse": {' && \
+       echo '                "limitSymbolsToIncludedHeaders": true,' && \
+       echo '                "databaseFilename": "",' && \
+       echo '                "path": [' && \
+       echo '                    "$${workspaceRoot}"' && \
+       echo '                ]' && \
+       echo '            },' && \
+       echo '            "cStandard": "c11",' && \
+       echo '            "cppStandard": "c++17",' && \
+       echo '            "compilerPath": "$(GCCPATH)"' && \
+       echo '        }' && \
+       echo '    ],' && \
+       echo '    "version": 4' && \
+       echo '}'
+EOF
+die "Could not write settings for the C/C++ extension"
+
+for file in .vscode/settings.json .vscode/tasks.json .vscode/launch.json
+do
+       if test -f $file
+       then
+               if git diff --no-index --quiet --exit-code $file $file.new
+               then
+                       rm $file.new
+               else
+                       printf "The file $file.new has these changes:\n\n"
+                       git --no-pager diff --no-index $file $file.new
+                       printf "\n\nMaybe \`mv $file.new $file\`?\n\n"
+               fi
+       else
+               mv $file.new $file
+       fi
+done
index 64d0d30e08de4acd496bf955d9ce64afa0ff5b8b..6057f1f58015ad7cae9792309dd635a1e7933586 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -1,6 +1,7 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
@@ -190,7 +191,7 @@ static enum eol output_eol(enum crlf_action crlf_action)
                /* fall through */
                return text_eol_is_crlf() ? EOL_CRLF : EOL_LF;
        }
-       warning("Illegal crlf_action %d\n", (int)crlf_action);
+       warning(_("illegal crlf_action %d"), (int)crlf_action);
        return core_eol;
 }
 
@@ -203,11 +204,11 @@ static void check_global_conv_flags_eol(const char *path, enum crlf_action crlf_
                 * CRLFs would not be restored by checkout
                 */
                if (conv_flags & CONV_EOL_RNDTRP_DIE)
-                       die(_("CRLF would be replaced by LF in %s."), path);
+                       die(_("CRLF would be replaced by LF in %s"), path);
                else if (conv_flags & CONV_EOL_RNDTRP_WARN)
                        warning(_("CRLF will be replaced by LF in %s.\n"
                                  "The file will have its original line"
-                                 " endings in your working directory."), path);
+                                 " endings in your working directory"), path);
        } else if (old_stats->lonelf && !new_stats->lonelf ) {
                /*
                 * CRLFs would be added by checkout
@@ -217,7 +218,7 @@ static void check_global_conv_flags_eol(const char *path, enum crlf_action crlf_
                else if (conv_flags & CONV_EOL_RNDTRP_WARN)
                        warning(_("LF will be replaced by CRLF in %s.\n"
                                  "The file will have its original line"
-                                 " endings in your working directory."), path);
+                                 " endings in your working directory"), path);
        }
 }
 
@@ -334,7 +335,7 @@ static void trace_encoding(const char *context, const char *path,
        strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding);
        for (i = 0; i < len && buf; ++i) {
                strbuf_addf(
-                       &trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c",
+                       &trace, "| \033[2m%2i:\033[0m %2x \033[2m%c\033[0m%c",
                        i,
                        (unsigned char) buf[i],
                        (buf[i] > 32 && buf[i] < 127 ? buf[i] : ' '),
@@ -389,7 +390,7 @@ static int encode_to_git(const char *path, const char *src, size_t src_len,
                         struct strbuf *buf, const char *enc, int conv_flags)
 {
        char *dst;
-       int dst_len;
+       size_t dst_len;
        int die_on_error = conv_flags & CONV_WRITE_OBJECT;
 
        /*
@@ -452,7 +453,7 @@ static int encode_to_git(const char *path, const char *src, size_t src_len,
         */
        if (die_on_error && check_roundtrip(enc)) {
                char *re_src;
-               int re_src_len;
+               size_t re_src_len;
 
                re_src = reencode_string_len(dst, dst_len,
                                             enc, default_encoding,
@@ -480,7 +481,7 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len,
                              struct strbuf *buf, const char *enc)
 {
        char *dst;
-       int dst_len;
+       size_t dst_len;
 
        /*
         * No encoding is specified or there is nothing to encode.
@@ -492,8 +493,8 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len,
        dst = reencode_string_len(src, src_len, enc, default_encoding,
                                  &dst_len);
        if (!dst) {
-               error("failed to encode '%s' from %s to %s",
-                       path, default_encoding, enc);
+               error(_("failed to encode '%s' from %s to %s"),
+                     path, default_encoding, enc);
                return 0;
        }
 
@@ -670,7 +671,8 @@ static int filter_buffer_or_fd(int in, int out, void *data)
 
        if (start_command(&child_process)) {
                strbuf_release(&cmd);
-               return error("cannot fork to run external filter '%s'", params->cmd);
+               return error(_("cannot fork to run external filter '%s'"),
+                            params->cmd);
        }
 
        sigchain_push(SIGPIPE, SIG_IGN);
@@ -689,13 +691,14 @@ static int filter_buffer_or_fd(int in, int out, void *data)
        if (close(child_process.in))
                write_err = 1;
        if (write_err)
-               error("cannot feed the input to external filter '%s'", params->cmd);
+               error(_("cannot feed the input to external filter '%s'"),
+                     params->cmd);
 
        sigchain_pop(SIGPIPE);
 
        status = finish_command(&child_process);
        if (status)
-               error("external filter '%s' failed %d", params->cmd, status);
+               error(_("external filter '%s' failed %d"), params->cmd, status);
 
        strbuf_release(&cmd);
        return (write_err || status);
@@ -730,13 +733,13 @@ static int apply_single_file_filter(const char *path, const char *src, size_t le
                return 0;       /* error was already reported */
 
        if (strbuf_read(&nbuf, async.out, len) < 0) {
-               err = error("read from external filter '%s' failed", cmd);
+               err = error(_("read from external filter '%s' failed"), cmd);
        }
        if (close(async.out)) {
-               err = error("read from external filter '%s' failed", cmd);
+               err = error(_("read from external filter '%s' failed"), cmd);
        }
        if (finish_async(&async)) {
-               err = error("external filter '%s' failed", cmd);
+               err = error(_("external filter '%s' failed"), cmd);
        }
 
        if (!err) {
@@ -790,7 +793,7 @@ static void handle_filter_error(const struct strbuf *filter_status,
                 * Something went wrong with the protocol filter.
                 * Force shutdown and restart if another blob requires filtering.
                 */
-               error("external filter '%s' failed", entry->subprocess.cmd);
+               error(_("external filter '%s' failed"), entry->subprocess.cmd);
                subprocess_stop(&subprocess_map, &entry->subprocess);
                free(entry);
        }
@@ -838,7 +841,7 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
        else if (wanted_capability & CAP_SMUDGE)
                filter_type = "smudge";
        else
-               die("unexpected filter type");
+               die(_("unexpected filter type"));
 
        sigchain_push(SIGPIPE, SIG_IGN);
 
@@ -849,7 +852,7 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
 
        err = strlen(path) > LARGE_PACKET_DATA_MAX - strlen("pathname=\n");
        if (err) {
-               error("path name too long for external filter");
+               error(_("path name too long for external filter"));
                goto done;
        }
 
@@ -923,8 +926,8 @@ int async_query_available_blobs(const char *cmd, struct string_list *available_p
        assert(subprocess_map_initialized);
        entry = (struct cmd2process *)subprocess_find_entry(&subprocess_map, cmd);
        if (!entry) {
-               error("external filter '%s' is not available anymore although "
-                     "not all paths have been filtered", cmd);
+               error(_("external filter '%s' is not available anymore although "
+                       "not all paths have been filtered"), cmd);
                return 0;
        }
        process = &entry->subprocess.process;
@@ -1290,7 +1293,8 @@ struct conv_attrs {
        const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */
 };
 
-static void convert_attrs(struct conv_attrs *ca, const char *path)
+static void convert_attrs(const struct index_state *istate,
+                         struct conv_attrs *ca, const char *path)
 {
        static struct attr_check *check;
 
@@ -1302,7 +1306,7 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
                git_config(read_convert_config, NULL);
        }
 
-       if (!git_check_attr(path, check)) {
+       if (!git_check_attr(istate, path, check)) {
                struct attr_check_item *ccheck = check->items;
                ca->crlf_action = git_path_check_crlf(ccheck + 4);
                if (ca->crlf_action == CRLF_UNDEFINED)
@@ -1339,11 +1343,11 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
                ca->crlf_action = CRLF_AUTO_INPUT;
 }
 
-int would_convert_to_git_filter_fd(const char *path)
+int would_convert_to_git_filter_fd(const struct index_state *istate, const char *path)
 {
        struct conv_attrs ca;
 
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
        if (!ca.drv)
                return 0;
 
@@ -1358,11 +1362,11 @@ int would_convert_to_git_filter_fd(const char *path)
        return apply_filter(path, NULL, 0, -1, NULL, ca.drv, CAP_CLEAN, NULL);
 }
 
-const char *get_convert_attr_ascii(const char *path)
+const char *get_convert_attr_ascii(const struct index_state *istate, const char *path)
 {
        struct conv_attrs ca;
 
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
        switch (ca.attr_action) {
        case CRLF_UNDEFINED:
                return "";
@@ -1391,11 +1395,11 @@ int convert_to_git(const struct index_state *istate,
        int ret = 0;
        struct conv_attrs ca;
 
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
 
        ret |= apply_filter(path, src, len, -1, dst, ca.drv, CAP_CLEAN, NULL);
        if (!ret && ca.drv && ca.drv->required)
-               die("%s: clean filter '%s' failed", path, ca.drv->name);
+               die(_("%s: clean filter '%s' failed"), path, ca.drv->name);
 
        if (ret && dst) {
                src = dst->buf;
@@ -1423,27 +1427,28 @@ void convert_to_git_filter_fd(const struct index_state *istate,
                              int conv_flags)
 {
        struct conv_attrs ca;
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
 
        assert(ca.drv);
        assert(ca.drv->clean || ca.drv->process);
 
        if (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN, NULL))
-               die("%s: clean filter '%s' failed", path, ca.drv->name);
+               die(_("%s: clean filter '%s' failed"), path, ca.drv->name);
 
        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);
 }
 
-static int convert_to_working_tree_internal(const char *path, const char *src,
+static int convert_to_working_tree_internal(const struct index_state *istate,
+                                           const char *path, const char *src,
                                            size_t len, struct strbuf *dst,
                                            int normalizing, struct delayed_checkout *dco)
 {
        int ret = 0, ret_filter = 0;
        struct conv_attrs ca;
 
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
 
        ret |= ident_to_worktree(path, src, len, dst, ca.ident);
        if (ret) {
@@ -1472,27 +1477,30 @@ static int convert_to_working_tree_internal(const char *path, const char *src,
        ret_filter = apply_filter(
                path, src, len, -1, dst, ca.drv, CAP_SMUDGE, dco);
        if (!ret_filter && ca.drv && ca.drv->required)
-               die("%s: smudge filter %s failed", path, ca.drv->name);
+               die(_("%s: smudge filter %s failed"), path, ca.drv->name);
 
        return ret | ret_filter;
 }
 
-int async_convert_to_working_tree(const char *path, const char *src,
+int async_convert_to_working_tree(const struct index_state *istate,
+                                 const char *path, const char *src,
                                  size_t len, struct strbuf *dst,
                                  void *dco)
 {
-       return convert_to_working_tree_internal(path, src, len, dst, 0, dco);
+       return convert_to_working_tree_internal(istate, path, src, len, dst, 0, dco);
 }
 
-int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)
+int convert_to_working_tree(const struct index_state *istate,
+                           const char *path, const char *src,
+                           size_t len, struct strbuf *dst)
 {
-       return convert_to_working_tree_internal(path, src, len, dst, 0, NULL);
+       return convert_to_working_tree_internal(istate, path, src, len, dst, 0, NULL);
 }
 
 int renormalize_buffer(const struct index_state *istate, const char *path,
                       const char *src, size_t len, struct strbuf *dst)
 {
-       int ret = convert_to_working_tree_internal(path, src, len, dst, 1, NULL);
+       int ret = convert_to_working_tree_internal(istate, path, src, len, dst, 1, NULL);
        if (ret) {
                src = dst->buf;
                len = dst->len;
@@ -1926,12 +1934,14 @@ static struct stream_filter *ident_filter(const struct object_id *oid)
  * Note that you would be crazy to set CRLF, smuge/clean or ident to a
  * large binary blob you would want us not to slurp into the memory!
  */
-struct stream_filter *get_stream_filter(const char *path, const struct object_id *oid)
+struct stream_filter *get_stream_filter(const struct index_state *istate,
+                                       const char *path,
+                                       const struct object_id *oid)
 {
        struct conv_attrs ca;
        struct stream_filter *filter = NULL;
 
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
        if (ca.drv && (ca.drv->process || ca.drv->smudge || ca.drv->clean))
                return NULL;
 
index 01385d92886223ab7b1d951d12c5de9b07612401..6d0ee887ed710b3ea3dadf315a4dd3bfb807e39e 100644 (file)
--- a/convert.h
+++ b/convert.h
@@ -57,35 +57,40 @@ struct delayed_checkout {
 
 extern enum eol core_eol;
 extern char *check_roundtrip_encoding;
-extern const char *get_cached_convert_stats_ascii(const struct index_state *istate,
-                                                 const char *path);
-extern const char *get_wt_convert_stats_ascii(const char *path);
-extern const char *get_convert_attr_ascii(const char *path);
+const char *get_cached_convert_stats_ascii(const struct index_state *istate,
+                                          const char *path);
+const char *get_wt_convert_stats_ascii(const char *path);
+const char *get_convert_attr_ascii(const struct index_state *istate,
+                                  const char *path);
 
 /* returns 1 if *dst was used */
-extern int convert_to_git(const struct index_state *istate,
-                         const char *path, const char *src, size_t len,
-                         struct strbuf *dst, int conv_flags);
-extern int convert_to_working_tree(const char *path, const char *src,
-                                  size_t len, struct strbuf *dst);
-extern int async_convert_to_working_tree(const char *path, const char *src,
-                                        size_t len, struct strbuf *dst,
-                                        void *dco);
-extern int async_query_available_blobs(const char *cmd, struct string_list *available_paths);
-extern int renormalize_buffer(const struct index_state *istate,
-                             const char *path, const char *src, size_t len,
-                             struct strbuf *dst);
+int convert_to_git(const struct index_state *istate,
+                  const char *path, const char *src, size_t len,
+                  struct strbuf *dst, int conv_flags);
+int convert_to_working_tree(const struct index_state *istate,
+                           const char *path, const char *src,
+                           size_t len, struct strbuf *dst);
+int async_convert_to_working_tree(const struct index_state *istate,
+                                 const char *path, const char *src,
+                                 size_t len, struct strbuf *dst,
+                                 void *dco);
+int async_query_available_blobs(const char *cmd,
+                               struct string_list *available_paths);
+int renormalize_buffer(const struct index_state *istate,
+                      const char *path, const char *src, size_t len,
+                      struct strbuf *dst);
 static inline int would_convert_to_git(const struct index_state *istate,
                                       const char *path)
 {
        return convert_to_git(istate, path, NULL, 0, NULL, 0);
 }
 /* Precondition: would_convert_to_git_filter_fd(path) == true */
-extern void convert_to_git_filter_fd(const struct index_state *istate,
-                                    const char *path, int fd,
-                                    struct strbuf *dst,
-                                    int conv_flags);
-extern int would_convert_to_git_filter_fd(const char *path);
+void convert_to_git_filter_fd(const struct index_state *istate,
+                             const char *path, int fd,
+                             struct strbuf *dst,
+                             int conv_flags);
+int would_convert_to_git_filter_fd(const struct index_state *istate,
+                                  const char *path);
 
 /*****************************************************************
  *
@@ -95,9 +100,11 @@ extern int would_convert_to_git_filter_fd(const char *path);
 
 struct stream_filter; /* opaque */
 
-extern struct stream_filter *get_stream_filter(const char *path, const struct object_id *);
-extern void free_stream_filter(struct stream_filter *);
-extern int is_null_stream_filter(struct stream_filter *);
+struct stream_filter *get_stream_filter(const struct index_state *istate,
+                                       const char *path,
+                                       const struct object_id *);
+void free_stream_filter(struct stream_filter *);
+int is_null_stream_filter(struct stream_filter *);
 
 /*
  * Use as much input up to *isize_p and fill output up to *osize_p;
@@ -111,8 +118,8 @@ extern int is_null_stream_filter(struct stream_filter *);
  * such filters know there is no more input coming and it is time for
  * them to produce the remaining output based on the buffered input.
  */
-extern int stream_filter(struct stream_filter *,
-                        const char *input, size_t *isize_p,
-                        char *output, size_t *osize_p);
+int stream_filter(struct stream_filter *,
+                 const char *input, size_t *isize_p,
+                 char *output, size_t *osize_p);
 
 #endif /* CONVERT_H */
index a9f38eb5a3e0e17d111301b581d06876ce5fd510..88a98b1c06e8792136eced81a7da5f9aacb8542f 100644 (file)
@@ -109,7 +109,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                if (diff_can_quit_early(&revs->diffopt))
                        break;
 
-               if (!ce_path_match(ce, &revs->prune_data, NULL))
+               if (!ce_path_match(&the_index, ce, &revs->prune_data, NULL))
                        continue;
 
                if (ce_stage(ce)) {
@@ -474,7 +474,7 @@ static int oneway_diff(const struct cache_entry * const *src,
        if (tree == o->df_conflict_entry)
                tree = NULL;
 
-       if (ce_path_match(idx ? idx : tree, &revs->prune_data, NULL)) {
+       if (ce_path_match(&the_index, idx ? idx : tree, &revs->prune_data, NULL)) {
                do_oneway_diff(o, idx, tree);
                if (diff_can_quit_early(&revs->diffopt)) {
                        o->exiting_early = 1;
@@ -520,6 +520,9 @@ int run_diff_index(struct rev_info *revs, int cached)
        struct object_array_entry *ent;
        uint64_t start = getnanotime();
 
+       if (revs->pending.nr != 1)
+               BUG("run_diff_index must be passed exactly one tree");
+
        ent = revs->pending.objects;
        if (diff_cache(revs, &ent->item->oid, ent->name, cached))
                exit(128);
diff --git a/diff.c b/diff.c
index 639eb646b9fa0f07eaeb20a1f0734c177092806d..145cfbae5929c69224f9f9e5bc473f2a221603de 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -13,6 +13,7 @@
 #include "attr.h"
 #include "run-command.h"
 #include "utf8.h"
+#include "object-store.h"
 #include "userdiff.h"
 #include "submodule-config.h"
 #include "submodule.h"
@@ -36,6 +37,7 @@ static int diff_rename_limit_default = 400;
 static int diff_suppress_blank_empty;
 static int diff_use_color_default = -1;
 static int diff_color_moved_default;
+static int diff_color_moved_ws_default;
 static int diff_context_default = 3;
 static int diff_interhunk_context_default;
 static const char *diff_word_regex_cfg;
@@ -68,6 +70,12 @@ static char diff_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_BOLD_YELLOW,  /* NEW_MOVED ALTERNATIVE */
        GIT_COLOR_FAINT,        /* NEW_MOVED_DIM */
        GIT_COLOR_FAINT_ITALIC, /* NEW_MOVED_ALTERNATIVE_DIM */
+       GIT_COLOR_FAINT,        /* CONTEXT_DIM */
+       GIT_COLOR_FAINT_RED,    /* OLD_DIM */
+       GIT_COLOR_FAINT_GREEN,  /* NEW_DIM */
+       GIT_COLOR_BOLD,         /* CONTEXT_BOLD */
+       GIT_COLOR_BOLD_RED,     /* OLD_BOLD */
+       GIT_COLOR_BOLD_GREEN,   /* NEW_BOLD */
 };
 
 static const char *color_diff_slots[] = {
@@ -87,6 +95,12 @@ static const char *color_diff_slots[] = {
        [DIFF_FILE_NEW_MOVED_ALT]     = "newMovedAlternative",
        [DIFF_FILE_NEW_MOVED_DIM]     = "newMovedDimmed",
        [DIFF_FILE_NEW_MOVED_ALT_DIM] = "newMovedAlternativeDimmed",
+       [DIFF_CONTEXT_DIM]            = "contextDimmed",
+       [DIFF_FILE_OLD_DIM]           = "oldDimmed",
+       [DIFF_FILE_NEW_DIM]           = "newDimmed",
+       [DIFF_CONTEXT_BOLD]           = "contextBold",
+       [DIFF_FILE_OLD_BOLD]          = "oldBold",
+       [DIFF_FILE_NEW_BOLD]          = "newBold",
 };
 
 static NORETURN void die_want_option(const char *option_name)
@@ -263,14 +277,54 @@ static int parse_color_moved(const char *arg)
                return COLOR_MOVED_NO;
        else if (!strcmp(arg, "plain"))
                return COLOR_MOVED_PLAIN;
+       else if (!strcmp(arg, "blocks"))
+               return COLOR_MOVED_BLOCKS;
        else if (!strcmp(arg, "zebra"))
                return COLOR_MOVED_ZEBRA;
        else if (!strcmp(arg, "default"))
                return COLOR_MOVED_DEFAULT;
+       else if (!strcmp(arg, "dimmed-zebra"))
+               return COLOR_MOVED_ZEBRA_DIM;
        else if (!strcmp(arg, "dimmed_zebra"))
                return COLOR_MOVED_ZEBRA_DIM;
        else
-               return error(_("color moved setting must be one of 'no', 'default', 'zebra', 'dimmed_zebra', 'plain'"));
+               return error(_("color moved setting must be one of 'no', 'default', 'blocks', 'zebra', 'dimmed-zebra', 'plain'"));
+}
+
+static int parse_color_moved_ws(const char *arg)
+{
+       int ret = 0;
+       struct string_list l = STRING_LIST_INIT_DUP;
+       struct string_list_item *i;
+
+       string_list_split(&l, arg, ',', -1);
+
+       for_each_string_list_item(i, &l) {
+               struct strbuf sb = STRBUF_INIT;
+               strbuf_addstr(&sb, i->string);
+               strbuf_trim(&sb);
+
+               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;
+               else if (!strcmp(sb.buf, "ignore-all-space"))
+                       ret |= XDF_IGNORE_WHITESPACE;
+               else if (!strcmp(sb.buf, "allow-indentation-change"))
+                       ret |= COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE;
+               else
+                       error(_("ignoring unknown color-moved-ws mode '%s'"), sb.buf);
+
+               strbuf_release(&sb);
+       }
+
+       if ((ret & COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) &&
+           (ret & XDF_WHITESPACE_FLAGS))
+               die(_("color-moved-ws: allow-indentation-change cannot be combined with other white space modes"));
+
+       string_list_clear(&l, 0);
+
+       return ret;
 }
 
 int git_diff_ui_config(const char *var, const char *value, void *cb)
@@ -286,6 +340,13 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
                diff_color_moved_default = cm;
                return 0;
        }
+       if (!strcmp(var, "diff.colormovedws")) {
+               int cm = parse_color_moved_ws(value);
+               if (cm < 0)
+                       return -1;
+               diff_color_moved_ws_default = cm;
+               return 0;
+       }
        if (!strcmp(var, "diff.context")) {
                diff_context_default = git_config_int(var, value);
                if (diff_context_default < 0)
@@ -562,14 +623,18 @@ static void check_blank_at_eof(mmfile_t *mf1, mmfile_t *mf2,
        ecbdata->blank_at_eof_in_postimage = (at - l2) + 1;
 }
 
-static void emit_line_0(struct diff_options *o, const char *set, const char *reset,
+static void emit_line_0(struct diff_options *o,
+                       const char *set, unsigned reverse, const char *reset,
                        int first, const char *line, int len)
 {
        int has_trailing_newline, has_trailing_carriage_return;
        int nofirst;
        FILE *file = o->file;
 
-       fputs(diff_line_prefix(o), file);
+       if (first)
+               fputs(diff_line_prefix(o), file);
+       else if (!len)
+               return;
 
        if (len == 0) {
                has_trailing_newline = (first == '\n');
@@ -587,8 +652,10 @@ static void emit_line_0(struct diff_options *o, const char *set, const char *res
        }
 
        if (len || !nofirst) {
+               if (reverse && want_color(o->use_color))
+                       fputs(GIT_COLOR_REVERSE, file);
                fputs(set, file);
-               if (!nofirst)
+               if (first && !nofirst)
                        fputc(first, file);
                fwrite(line, len, 1, file);
                fputs(reset, file);
@@ -602,7 +669,7 @@ static void emit_line_0(struct diff_options *o, const char *set, const char *res
 static void emit_line(struct diff_options *o, const char *set, const char *reset,
                      const char *line, int len)
 {
-       emit_line_0(o, set, reset, line[0], line+1, len-1);
+       emit_line_0(o, set, 0, reset, line[0], line+1, len-1);
 }
 
 enum diff_symbol {
@@ -697,16 +764,116 @@ struct moved_entry {
        struct hashmap_entry ent;
        const struct emitted_diff_symbol *es;
        struct moved_entry *next_line;
+       struct ws_delta *wsd;
+};
+
+/**
+ * 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 }
+
+static int compute_ws_delta(const struct emitted_diff_symbol *a,
+                            const struct emitted_diff_symbol *b,
+                            struct ws_delta *out)
+{
+       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;
+
+       out->string = xmemdupz(longer->line, d);
+       out->current_longer = (a == longer);
+
+       return !strncmp(longer->line + d, shorter->line, shorter->len);
+}
+
+static int cmp_in_block_with_wsd(const struct diff_options *o,
+                                const struct moved_entry *cur,
+                                const struct moved_entry *match,
+                                struct moved_entry *pmb,
+                                int n)
+{
+       struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
+       int al = cur->es->len, cl = l->len;
+       const char *a = cur->es->line,
+                  *b = match->es->line,
+                  *c = l->line;
+
+       int wslen;
+
+       /*
+        * 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.
+        */
+       if (strcmp(a, b))
+               return 1;
+
+       if (!pmb->wsd)
+               /*
+                * No white space delta was carried forward? This can happen
+                * when we exit early in this function and do not carry
+                * forward ws.
+                */
+               return 1;
+
+       /*
+        * The indent changes of the block are known and carried forward 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.
+        */
+
+       wslen = strlen(pmb->wsd->string);
+       if (pmb->wsd->current_longer) {
+               c += wslen;
+               cl -= wslen;
+       } else {
+               a += wslen;
+               al -= wslen;
+       }
 
-static int moved_entry_cmp(const struct diff_options *diffopt,
-                          const struct moved_entry *a,
-                          const struct moved_entry *b,
+       if (strcmp(a, c))
+               return 1;
+
+       return 0;
+}
+
+static int moved_entry_cmp(const void *hashmap_cmp_fn_data,
+                          const void *entry,
+                          const void *entry_or_key,
                           const void *keydata)
 {
+       const struct diff_options *diffopt = hashmap_cmp_fn_data;
+       const struct moved_entry *a = entry;
+       const struct moved_entry *b = entry_or_key;
+       unsigned flags = diffopt->color_moved_ws_handling
+                        & XDF_WHITESPACE_FLAGS;
+
+       if (diffopt->color_moved_ws_handling &
+           COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
+               /*
+                * As there is not specific white space config given,
+                * we'd need to check for a new block, so ignore all
+                * white space. The setup of the white space
+                * configuration for the next block is done else where
+                */
+               flags |= XDF_IGNORE_WHITESPACE;
+
        return !xdiff_compare_lines(a->es->line, a->es->len,
                                    b->es->line, b->es->len,
-                                   diffopt->xdl_opts);
+                                   flags);
 }
 
 static struct moved_entry *prepare_entry(struct diff_options *o,
@@ -714,10 +881,12 @@ static struct moved_entry *prepare_entry(struct diff_options *o,
 {
        struct moved_entry *ret = xmalloc(sizeof(*ret));
        struct emitted_diff_symbol *l = &o->emitted_symbols->buf[line_no];
+       unsigned flags = o->color_moved_ws_handling & XDF_WHITESPACE_FLAGS;
 
-       ret->ent.hash = xdiff_hash_string(l->line, l->len, o->xdl_opts);
+       ret->ent.hash = xdiff_hash_string(l->line, l->len, flags);
        ret->es = l;
        ret->next_line = NULL;
+       ret->wsd = NULL;
 
        return ret;
 }
@@ -754,6 +923,56 @@ static void add_lines_to_move_detection(struct diff_options *o,
        }
 }
 
+static void pmb_advance_or_null(struct diff_options *o,
+                               struct moved_entry *match,
+                               struct hashmap *hm,
+                               struct moved_entry **pmb,
+                               int pmb_nr)
+{
+       int i;
+       for (i = 0; i < pmb_nr; i++) {
+               struct moved_entry *prev = pmb[i];
+               struct moved_entry *cur = (prev && prev->next_line) ?
+                               prev->next_line : NULL;
+               if (cur && !hm->cmpfn(o, cur, match, NULL)) {
+                       pmb[i] = cur;
+               } else {
+                       pmb[i] = NULL;
+               }
+       }
+}
+
+static void pmb_advance_or_null_multi_match(struct diff_options *o,
+                                           struct moved_entry *match,
+                                           struct hashmap *hm,
+                                           struct moved_entry **pmb,
+                                           int pmb_nr, int n)
+{
+       int i;
+       char *got_match = xcalloc(1, pmb_nr);
+
+       for (; match; match = hashmap_get_next(hm, match)) {
+               for (i = 0; i < pmb_nr; i++) {
+                       struct moved_entry *prev = pmb[i];
+                       struct moved_entry *cur = (prev && prev->next_line) ?
+                                       prev->next_line : NULL;
+                       if (!cur)
+                               continue;
+                       if (!cmp_in_block_with_wsd(o, cur, match, pmb[i], n))
+                               got_match[i] |= 1;
+               }
+       }
+
+       for (i = 0; i < pmb_nr; i++) {
+               if (got_match[i]) {
+                       /* Carry the white space delta forward */
+                       pmb[i]->next_line->wsd = pmb[i]->wsd;
+                       pmb[i] = pmb[i]->next_line;
+               } else
+                       pmb[i] = NULL;
+       }
+}
+
 static int shrink_potential_moved_blocks(struct moved_entry **pmb,
                                         int pmb_nr)
 {
@@ -771,6 +990,10 @@ static int shrink_potential_moved_blocks(struct moved_entry **pmb,
 
                if (lp < pmb_nr && rp > -1 && lp < rp) {
                        pmb[lp] = pmb[rp];
+                       if (pmb[rp]->wsd) {
+                               free(pmb[rp]->wsd->string);
+                               FREE_AND_NULL(pmb[rp]->wsd);
+                       }
                        pmb[rp] = NULL;
                        rp--;
                        lp++;
@@ -828,19 +1051,18 @@ 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];
-               int i;
 
                switch (l->s) {
                case DIFF_SYMBOL_PLUS:
                        hm = del_lines;
                        key = prepare_entry(o, n);
-                       match = hashmap_get(hm, key, o);
+                       match = hashmap_get(hm, key, NULL);
                        free(key);
                        break;
                case DIFF_SYMBOL_MINUS:
                        hm = add_lines;
                        key = prepare_entry(o, n);
-                       match = hashmap_get(hm, key, o);
+                       match = hashmap_get(hm, key, NULL);
                        free(key);
                        break;
                default:
@@ -859,17 +1081,11 @@ static void mark_color_as_moved(struct diff_options *o,
                if (o->color_moved == COLOR_MOVED_PLAIN)
                        continue;
 
-               /* Check any potential block runs, advance each or nullify */
-               for (i = 0; i < pmb_nr; i++) {
-                       struct moved_entry *p = pmb[i];
-                       struct moved_entry *pnext = (p && p->next_line) ?
-                                       p->next_line : NULL;
-                       if (pnext && !hm->cmpfn(o, pnext, match, NULL)) {
-                               pmb[i] = p->next_line;
-                       } else {
-                               pmb[i] = NULL;
-                       }
-               }
+               if (o->color_moved_ws_handling &
+                   COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
+                       pmb_advance_or_null_multi_match(o, match, hm, pmb, pmb_nr, n);
+               else
+                       pmb_advance_or_null(o, match, hm, pmb, pmb_nr);
 
                pmb_nr = shrink_potential_moved_blocks(pmb, pmb_nr);
 
@@ -880,7 +1096,17 @@ static void mark_color_as_moved(struct diff_options *o,
                         */
                        for (; match; match = hashmap_get_next(hm, match)) {
                                ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc);
-                               pmb[pmb_nr++] = match;
+                               if (o->color_moved_ws_handling &
+                                   COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) {
+                                       struct ws_delta *wsd = xmalloc(sizeof(*match->wsd));
+                                       if (compute_ws_delta(l, match->es, wsd)) {
+                                               match->wsd = wsd;
+                                               pmb[pmb_nr++] = match;
+                                       } else
+                                               free(wsd);
+                               } else {
+                                       pmb[pmb_nr++] = match;
+                               }
                        }
 
                        flipped_block = (flipped_block + 1) % 2;
@@ -891,7 +1117,7 @@ static void mark_color_as_moved(struct diff_options *o,
 
                block_length++;
 
-               if (flipped_block)
+               if (flipped_block && o->color_moved != COLOR_MOVED_BLOCKS)
                        l->flags |= DIFF_SYMBOL_MOVED_LINE_ALT;
        }
        adjust_last_block(o, n, block_length);
@@ -962,7 +1188,8 @@ static void dim_moved_lines(struct diff_options *o)
 
 static void emit_line_ws_markup(struct diff_options *o,
                                const char *set, const char *reset,
-                               const char *line, int len, char sign,
+                               const char *line, int len,
+                               const char *set_sign, char sign,
                                unsigned ws_rule, int blank_at_eof)
 {
        const char *ws = NULL;
@@ -973,14 +1200,20 @@ static void emit_line_ws_markup(struct diff_options *o,
                        ws = NULL;
        }
 
-       if (!ws)
-               emit_line_0(o, set, reset, sign, line, len);
-       else if (blank_at_eof)
+       if (!ws && !set_sign)
+               emit_line_0(o, set, 0, reset, sign, line, len);
+       else if (!ws) {
+               /* Emit just the prefix, then the rest. */
+               emit_line_0(o, set_sign ? set_sign : set, !!set_sign, reset,
+                           sign, "", 0);
+               emit_line_0(o, set, 0, reset, 0, line, len);
+       } else if (blank_at_eof)
                /* Blank line at EOF - paint '+' as well */
-               emit_line_0(o, ws, reset, sign, line, len);
+               emit_line_0(o, ws, 0, reset, sign, line, len);
        else {
                /* Emit just the prefix, then the rest. */
-               emit_line_0(o, set, reset, sign, "", 0);
+               emit_line_0(o, set_sign ? set_sign : set, !!set_sign, reset,
+                           sign, "", 0);
                ws_check_emit(line, len, ws_rule,
                              o->file, set, reset, ws);
        }
@@ -990,7 +1223,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
                                         struct emitted_diff_symbol *eds)
 {
        static const char *nneof = " No newline at end of file\n";
-       const char *context, *reset, *set, *meta, *fraginfo;
+       const char *context, *reset, *set, *set_sign, *meta, *fraginfo;
        struct strbuf sb = STRBUF_INIT;
 
        enum diff_symbol s = eds->s;
@@ -1003,7 +1236,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
                context = diff_get_color_opt(o, DIFF_CONTEXT);
                reset = diff_get_color_opt(o, DIFF_RESET);
                putc('\n', o->file);
-               emit_line_0(o, context, reset, '\\',
+               emit_line_0(o, context, 0, reset, '\\',
                            nneof, strlen(nneof));
                break;
        case DIFF_SYMBOL_SUBMODULE_HEADER:
@@ -1030,7 +1263,18 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
        case DIFF_SYMBOL_CONTEXT:
                set = diff_get_color_opt(o, DIFF_CONTEXT);
                reset = diff_get_color_opt(o, DIFF_RESET);
-               emit_line_ws_markup(o, set, reset, line, len, ' ',
+               set_sign = NULL;
+               if (o->flags.dual_color_diffed_diffs) {
+                       char c = !len ? 0 : line[0];
+
+                       if (c == '+')
+                               set = diff_get_color_opt(o, DIFF_FILE_NEW);
+                       else if (c == '@')
+                               set = diff_get_color_opt(o, DIFF_FRAGINFO);
+                       else if (c == '-')
+                               set = diff_get_color_opt(o, DIFF_FILE_OLD);
+               }
+               emit_line_ws_markup(o, set, reset, line, len, set_sign, ' ',
                                    flags & (DIFF_SYMBOL_CONTENT_WS_MASK), 0);
                break;
        case DIFF_SYMBOL_PLUS:
@@ -1057,7 +1301,23 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
                        set = diff_get_color_opt(o, DIFF_FILE_NEW);
                }
                reset = diff_get_color_opt(o, DIFF_RESET);
-               emit_line_ws_markup(o, set, reset, line, len, '+',
+               if (!o->flags.dual_color_diffed_diffs)
+                       set_sign = NULL;
+               else {
+                       char c = !len ? 0 : line[0];
+
+                       set_sign = set;
+                       if (c == '-')
+                               set = diff_get_color_opt(o, DIFF_FILE_OLD_BOLD);
+                       else if (c == '@')
+                               set = diff_get_color_opt(o, DIFF_FRAGINFO);
+                       else if (c == '+')
+                               set = diff_get_color_opt(o, DIFF_FILE_NEW_BOLD);
+                       else
+                               set = diff_get_color_opt(o, DIFF_CONTEXT_BOLD);
+                       flags &= ~DIFF_SYMBOL_CONTENT_WS_MASK;
+               }
+               emit_line_ws_markup(o, set, reset, line, len, set_sign, '+',
                                    flags & DIFF_SYMBOL_CONTENT_WS_MASK,
                                    flags & DIFF_SYMBOL_CONTENT_BLANK_LINE_EOF);
                break;
@@ -1085,7 +1345,22 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
                        set = diff_get_color_opt(o, DIFF_FILE_OLD);
                }
                reset = diff_get_color_opt(o, DIFF_RESET);
-               emit_line_ws_markup(o, set, reset, line, len, '-',
+               if (!o->flags.dual_color_diffed_diffs)
+                       set_sign = NULL;
+               else {
+                       char c = !len ? 0 : line[0];
+
+                       set_sign = set;
+                       if (c == '+')
+                               set = diff_get_color_opt(o, DIFF_FILE_NEW_DIM);
+                       else if (c == '@')
+                               set = diff_get_color_opt(o, DIFF_FRAGINFO);
+                       else if (c == '-')
+                               set = diff_get_color_opt(o, DIFF_FILE_OLD_DIM);
+                       else
+                               set = diff_get_color_opt(o, DIFF_CONTEXT_DIM);
+               }
+               emit_line_ws_markup(o, set, reset, line, len, set_sign, '-',
                                    flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
                break;
        case DIFF_SYMBOL_WORDS_PORCELAIN:
@@ -1276,6 +1551,7 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
        const char *frag = diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO);
        const char *func = diff_get_color(ecbdata->color_diff, DIFF_FUNCINFO);
        const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
+       const char *reverse = ecbdata->color_diff ? GIT_COLOR_REVERSE : "";
        static const char atat[2] = { '@', '@' };
        const char *cp, *ep;
        struct strbuf msgbuf = STRBUF_INIT;
@@ -1296,6 +1572,8 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
        ep += 2; /* skip over @@ */
 
        /* The hunk header in fraginfo color */
+       if (ecbdata->opt->flags.dual_color_diffed_diffs)
+               strbuf_addstr(&msgbuf, reverse);
        strbuf_addstr(&msgbuf, frag);
        strbuf_add(&msgbuf, line, ep - line);
        strbuf_addstr(&msgbuf, reset);
@@ -1863,8 +2141,8 @@ static void init_diff_words_data(struct emit_callback *ecbdata,
                if (regcomp(ecbdata->diff_words->word_regex,
                            o->word_regex,
                            REG_EXTENDED | REG_NEWLINE))
-                       die ("Invalid regular expression: %s",
-                            o->word_regex);
+                       die("invalid regular expression: %s",
+                           o->word_regex);
        }
        for (i = 0; i < ARRAY_SIZE(diff_words_styles); i++) {
                if (o->word_diff == diff_words_styles[i].type) {
@@ -3189,13 +3467,16 @@ static void builtin_diff(const char *name_a,
                memset(&xpp, 0, sizeof(xpp));
                memset(&xecfg, 0, sizeof(xecfg));
                memset(&ecbdata, 0, sizeof(ecbdata));
+               if (o->flags.suppress_diff_headers)
+                       lbl[0] = NULL;
                ecbdata.label_path = lbl;
                ecbdata.color_diff = want_color(o->use_color);
                ecbdata.ws_rule = whitespace_rule(name_b);
                if (ecbdata.ws_rule & WS_BLANK_AT_EOF)
                        check_blank_at_eof(&mf1, &mf2, &ecbdata);
                ecbdata.opt = o;
-               ecbdata.header = header.len ? &header : NULL;
+               if (header.len && !o->flags.suppress_diff_headers)
+                       ecbdata.header = &header;
                xpp.flags = o->xdl_opts;
                xpp.anchors = o->anchors;
                xpp.anchors_nr = o->anchors_nr;
@@ -3687,7 +3968,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
        temp->tempfile = mks_tempfile_ts(tempfile.buf, strlen(base) + 1);
        if (!temp->tempfile)
                die_errno("unable to create temp-file");
-       if (convert_to_working_tree(path,
+       if (convert_to_working_tree(&the_index, path,
                        (const char *)blob, (size_t)size, &buf)) {
                blob = buf.buf;
                size = buf.len;
@@ -3832,7 +4113,7 @@ static const char *diff_abbrev_oid(const struct object_id *oid, int abbrev)
                char *hex = oid_to_hex(oid);
                if (abbrev < 0)
                        abbrev = FALLBACK_DEFAULT_ABBREV;
-               if (abbrev > GIT_SHA1_HEXSZ)
+               if (abbrev > the_hash_algo->hexsz)
                        BUG("oid abbreviation out of range: %d", abbrev);
                if (abbrev)
                        hex[abbrev] = '\0';
@@ -4124,6 +4405,7 @@ void diff_setup(struct diff_options *options)
        }
 
        options->color_moved = diff_color_moved_default;
+       options->color_moved_ws_handling = diff_color_moved_ws_default;
 }
 
 void diff_setup_done(struct diff_options *options)
@@ -4207,16 +4489,6 @@ void diff_setup_done(struct diff_options *options)
 
        if (options->detect_rename && options->rename_limit < 0)
                options->rename_limit = diff_rename_limit_default;
-       if (options->setup & DIFF_SETUP_USE_CACHE) {
-               if (!active_cache)
-                       /* read-cache does not die even when it fails
-                        * so it is safe for us to do this here.  Also
-                        * it does not smudge active_cache or active_nr
-                        * when it fails, so we do not have to worry about
-                        * cleaning it up ourselves either.
-                        */
-                       read_cache();
-       }
        if (hexsz < options->abbrev)
                options->abbrev = hexsz; /* full */
 
@@ -4703,6 +4975,8 @@ int diff_opt_parse(struct diff_options *options,
                if (cm < 0)
                        die("bad --color-moved argument: %s", arg);
                options->color_moved = cm;
+       } else if (skip_prefix(arg, "--color-moved-ws=", &arg)) {
+               options->color_moved_ws_handling = parse_color_moved_ws(arg);
        } else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
                options->use_color = 1;
                options->word_diff = DIFF_WORDS_COLOR;
@@ -4947,7 +5221,7 @@ const char *diff_aligned_abbrev(const struct object_id *oid, int len)
        const char *abbrev;
 
        /* Do we want all 40 hex characters? */
-       if (len == GIT_SHA1_HEXSZ)
+       if (len == the_hash_algo->hexsz)
                return oid_to_hex(oid);
 
        /* An abbreviated value is fine, possibly followed by an ellipsis. */
@@ -4977,7 +5251,7 @@ const char *diff_aligned_abbrev(const struct object_id *oid, int len)
         * the automatic sizing is supposed to give abblen that ensures
         * uniqueness across all objects (statistically speaking).
         */
-       if (abblen < GIT_SHA1_HEXSZ - 3) {
+       if (abblen < the_hash_algo->hexsz - 3) {
                static char hex[GIT_MAX_HEXSZ + 1];
                if (len < abblen && abblen <= len + 2)
                        xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, len+3-abblen, "..");
@@ -5533,10 +5807,12 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o)
                if (o->color_moved) {
                        struct hashmap add_lines, del_lines;
 
-                       hashmap_init(&del_lines,
-                                    (hashmap_cmp_fn)moved_entry_cmp, o, 0);
-                       hashmap_init(&add_lines,
-                                    (hashmap_cmp_fn)moved_entry_cmp, o, 0);
+                       if (o->color_moved_ws_handling &
+                           COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
+                               o->color_moved_ws_handling |= XDF_IGNORE_WHITESPACE;
+
+                       hashmap_init(&del_lines, moved_entry_cmp, o, 0);
+                       hashmap_init(&add_lines, moved_entry_cmp, o, 0);
 
                        add_lines_to_move_detection(o, &add_lines, &del_lines);
                        mark_color_as_moved(o, &add_lines, &del_lines);
diff --git a/diff.h b/diff.h
index dedac472ca5959bb5ff17888a54042ac75678631..89544e64bc5797fe40f069e84657d85589f0252a 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -94,6 +94,8 @@ struct diff_flags {
        unsigned funccontext:1;
        unsigned default_follow_renames:1;
        unsigned stat_with_summary:1;
+       unsigned suppress_diff_headers:1;
+       unsigned dual_color_diffed_diffs:1;
 };
 
 static inline void diff_flags_or(struct diff_flags *a,
@@ -208,11 +210,16 @@ struct diff_options {
        enum {
                COLOR_MOVED_NO = 0,
                COLOR_MOVED_PLAIN = 1,
-               COLOR_MOVED_ZEBRA = 2,
-               COLOR_MOVED_ZEBRA_DIM = 3,
+               COLOR_MOVED_BLOCKS = 2,
+               COLOR_MOVED_ZEBRA = 3,
+               COLOR_MOVED_ZEBRA_DIM = 4,
        } color_moved;
        #define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
        #define COLOR_MOVED_MIN_ALNUM_COUNT 20
+
+       /* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
+       #define COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE (1<<5)
+       int color_moved_ws_handling;
 };
 
 void diff_emit_submodule_del(struct diff_options *o, const char *line);
@@ -241,7 +248,13 @@ enum color_diff {
        DIFF_FILE_NEW_MOVED = 13,
        DIFF_FILE_NEW_MOVED_ALT = 14,
        DIFF_FILE_NEW_MOVED_DIM = 15,
-       DIFF_FILE_NEW_MOVED_ALT_DIM = 16
+       DIFF_FILE_NEW_MOVED_ALT_DIM = 16,
+       DIFF_CONTEXT_DIM = 17,
+       DIFF_FILE_OLD_DIM = 18,
+       DIFF_FILE_NEW_DIM = 19,
+       DIFF_CONTEXT_BOLD = 20,
+       DIFF_FILE_OLD_BOLD = 21,
+       DIFF_FILE_NEW_BOLD = 22,
 };
 const char *diff_get_color(int diff_use_color, enum color_diff ix);
 #define diff_get_color_opt(o, ix) \
@@ -253,15 +266,15 @@ const char *diff_line_prefix(struct diff_options *);
 
 extern const char mime_boundary_leader[];
 
-extern struct combine_diff_path *diff_tree_paths(
+struct combine_diff_path *diff_tree_paths(
        struct combine_diff_path *p, const struct object_id *oid,
        const struct object_id **parents_oid, int nparent,
        struct strbuf *base, struct diff_options *opt);
-extern int diff_tree_oid(const struct object_id *old_oid,
-                        const struct object_id *new_oid,
-                        const char *base, struct diff_options *opt);
-extern int diff_root_tree_oid(const struct object_id *new_oid, const char *base,
-                             struct diff_options *opt);
+int diff_tree_oid(const struct object_id *old_oid,
+                 const struct object_id *new_oid,
+                 const char *base, struct diff_options *opt);
+int diff_root_tree_oid(const struct object_id *new_oid, const char *base,
+                      struct diff_options *opt);
 
 struct combine_diff_path {
        struct combine_diff_path *next;
@@ -278,53 +291,52 @@ struct combine_diff_path {
        st_add4(sizeof(struct combine_diff_path), (l), 1, \
                st_mult(sizeof(struct combine_diff_parent), (n)))
 
-extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
-                             int dense, struct rev_info *);
+void show_combined_diff(struct combine_diff_path *elem, int num_parent,
+                       int dense, struct rev_info *);
 
-extern void diff_tree_combined(const struct object_id *oid, const struct oid_array *parents, int dense, struct rev_info *rev);
+void diff_tree_combined(const struct object_id *oid, const struct oid_array *parents, int dense, struct rev_info *rev);
 
-extern void diff_tree_combined_merge(const struct commit *commit, int dense, struct rev_info *rev);
+void diff_tree_combined_merge(const struct commit *commit, int dense, struct rev_info *rev);
 
 void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
 
-extern int diff_can_quit_early(struct diff_options *);
+int diff_can_quit_early(struct diff_options *);
 
-extern void diff_addremove(struct diff_options *,
-                          int addremove,
-                          unsigned mode,
-                          const struct object_id *oid,
-                          int oid_valid,
-                          const char *fullpath, unsigned dirty_submodule);
+void diff_addremove(struct diff_options *,
+                   int addremove,
+                   unsigned mode,
+                   const struct object_id *oid,
+                   int oid_valid,
+                   const char *fullpath, unsigned dirty_submodule);
 
-extern void diff_change(struct diff_options *,
-                       unsigned mode1, unsigned mode2,
-                       const struct object_id *old_oid,
-                       const struct object_id *new_oid,
-                       int old_oid_valid, int new_oid_valid,
-                       const char *fullpath,
-                       unsigned dirty_submodule1, unsigned dirty_submodule2);
+void diff_change(struct diff_options *,
+                unsigned mode1, unsigned mode2,
+                const struct object_id *old_oid,
+                const struct object_id *new_oid,
+                int old_oid_valid, int new_oid_valid,
+                const char *fullpath,
+                unsigned dirty_submodule1, unsigned dirty_submodule2);
 
-extern struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
+struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
 
 #define DIFF_SETUP_REVERSE             1
-#define DIFF_SETUP_USE_CACHE           2
 #define DIFF_SETUP_USE_SIZE_CACHE      4
 
 /*
  * Poor man's alternative to parse-option, to allow both stuck form
  * (--option=value) and separate form (--option value).
  */
-extern int parse_long_opt(const char *opt, const char **argv,
-                        const char **optarg);
-
-extern int git_diff_basic_config(const char *var, const char *value, void *cb);
-extern int git_diff_heuristic_config(const char *var, const char *value, void *cb);
-extern void init_diff_ui_defaults(void);
-extern int git_diff_ui_config(const char *var, const char *value, void *cb);
-extern void diff_setup(struct diff_options *);
-extern int diff_opt_parse(struct diff_options *, const char **, int, const char *);
-extern void diff_setup_done(struct diff_options *);
-extern int git_config_rename(const char *var, const char *value);
+int parse_long_opt(const char *opt, const char **argv,
+                  const char **optarg);
+
+int git_diff_basic_config(const char *var, const char *value, void *cb);
+int git_diff_heuristic_config(const char *var, const char *value, void *cb);
+void init_diff_ui_defaults(void);
+int git_diff_ui_config(const char *var, const char *value, void *cb);
+void diff_setup(struct diff_options *);
+int diff_opt_parse(struct diff_options *, const char **, int, const char *);
+void diff_setup_done(struct diff_options *);
+int git_config_rename(const char *var, const char *value);
 
 #define DIFF_DETECT_RENAME     1
 #define DIFF_DETECT_COPY       2
@@ -342,8 +354,8 @@ extern int git_config_rename(const char *var, const char *value);
 
 #define DIFF_PICKAXE_IGNORE_CASE       32
 
-extern void diffcore_std(struct diff_options *);
-extern void diffcore_fix_diff_index(struct diff_options *);
+void diffcore_std(struct diff_options *);
+void diffcore_fix_diff_index(struct diff_options *);
 
 #define COMMON_DIFF_OPTIONS_HELP \
 "\ncommon diff options:\n" \
@@ -373,9 +385,9 @@ extern void diffcore_fix_diff_index(struct diff_options *);
 "                show all files diff when -S is used and hit is found.\n" \
 "  -a  --text    treat all files as text.\n"
 
-extern int diff_queue_is_empty(void);
-extern void diff_flush(struct diff_options*);
-extern void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc);
+int diff_queue_is_empty(void);
+void diff_flush(struct diff_options*);
+void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc);
 
 /* diff-raw status letters */
 #define DIFF_STATUS_ADDED              'A'
@@ -397,24 +409,24 @@ extern void diff_warn_rename_limit(const char *varname, int needed, int degraded
  * This is different from find_unique_abbrev() in that
  * it stuffs the result with dots for alignment.
  */
-extern const char *diff_aligned_abbrev(const struct object_id *sha1, int);
+const char *diff_aligned_abbrev(const struct object_id *sha1, int);
 
 /* do not report anything on removed paths */
 #define DIFF_SILENT_ON_REMOVED 01
 /* report racily-clean paths as modified */
 #define DIFF_RACY_IS_MODIFIED 02
-extern int run_diff_files(struct rev_info *revs, unsigned int option);
-extern int run_diff_index(struct rev_info *revs, int cached);
+int run_diff_files(struct rev_info *revs, unsigned int option);
+int run_diff_index(struct rev_info *revs, int cached);
 
-extern int do_diff_cache(const struct object_id *, struct diff_options *);
-extern int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
+int do_diff_cache(const struct object_id *, struct diff_options *);
+int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
 
-extern int diff_result_code(struct diff_options *, int);
+int diff_result_code(struct diff_options *, int);
 
-extern void diff_no_index(struct rev_info *, int, const char **);
+void diff_no_index(struct rev_info *, int, const char **);
 
-extern int index_differs_from(const char *def, const struct diff_flags *flags,
-                             int ita_invisible_in_index);
+int index_differs_from(const char *def, const struct diff_flags *flags,
+                      int ita_invisible_in_index);
 
 /*
  * Fill the contents of the filespec "df", respecting any textconv defined by
@@ -427,30 +439,30 @@ extern int index_differs_from(const char *def, const struct diff_flags *flags,
  * struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
  * that should be freed by the caller.
  */
-extern size_t fill_textconv(struct userdiff_driver *driver,
-                           struct diff_filespec *df,
-                           char **outbuf);
+size_t fill_textconv(struct userdiff_driver *driver,
+                    struct diff_filespec *df,
+                    char **outbuf);
 
 /*
  * Look up the userdiff driver for the given filespec, and return it if
  * and only if it has textconv enabled (otherwise return NULL). The result
  * can be passed to fill_textconv().
  */
-extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
+struct userdiff_driver *get_textconv(struct diff_filespec *one);
 
 /*
  * Prepare diff_filespec and convert it using diff textconv API
  * if the textconv driver exists.
  * Return 1 if the conversion succeeds, 0 otherwise.
  */
-extern int textconv_object(const char *path, unsigned mode, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size);
+int textconv_object(const char *path, unsigned mode, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size);
 
-extern int parse_rename_score(const char **cp_p);
+int parse_rename_score(const char **cp_p);
 
-extern long parse_algorithm_value(const char *value);
+long parse_algorithm_value(const char *value);
 
-extern void print_stat_summary(FILE *fp, int files,
-                              int insertions, int deletions);
-extern void setup_diff_pager(struct diff_options *);
+void print_stat_summary(FILE *fp, int files,
+                       int insertions, int deletions);
+void setup_diff_pager(struct diff_options *);
 
 #endif /* DIFF_H */
index 0b7e4989a87214faa22e4f8ec75a719d3fd857ae..d775183c2fd1bed06a97facb56c4721e4e5df2f6 100644 (file)
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "object-store.h"
 #include "hashmap.h"
 #include "progress.h"
 
index a30da161dafcf0d3951e3208000c54388803c8f0..81281a398b4f218f22d1d9ed50df99589832fe83 100644 (file)
@@ -50,17 +50,17 @@ struct diff_filespec {
        struct userdiff_driver *driver;
 };
 
-extern struct diff_filespec *alloc_filespec(const char *);
-extern void free_filespec(struct diff_filespec *);
-extern void fill_filespec(struct diff_filespec *, const struct object_id *,
-                         int, unsigned short);
+struct diff_filespec *alloc_filespec(const char *);
+void free_filespec(struct diff_filespec *);
+void fill_filespec(struct diff_filespec *, const struct object_id *,
+                  int, unsigned short);
 
 #define CHECK_SIZE_ONLY 1
 #define CHECK_BINARY    2
-extern int diff_populate_filespec(struct diff_filespec *, unsigned int);
-extern void diff_free_filespec_data(struct diff_filespec *);
-extern void diff_free_filespec_blob(struct diff_filespec *);
-extern int diff_filespec_is_binary(struct diff_filespec *);
+int diff_populate_filespec(struct diff_filespec *, unsigned int);
+void diff_free_filespec_data(struct diff_filespec *);
+void diff_free_filespec_blob(struct diff_filespec *);
+int diff_filespec_is_binary(struct diff_filespec *);
 
 struct diff_filepair {
        struct diff_filespec *one;
@@ -86,9 +86,9 @@ struct diff_filepair {
 
 #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
 
-extern void diff_free_filepair(struct diff_filepair *);
+void diff_free_filepair(struct diff_filepair *);
 
-extern int diff_unmodified_pair(struct diff_filepair *);
+int diff_unmodified_pair(struct diff_filepair *);
 
 struct diff_queue_struct {
        struct diff_filepair **queue;
@@ -102,16 +102,16 @@ struct diff_queue_struct {
        } while (0)
 
 extern struct diff_queue_struct diff_queued_diff;
-extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
-                                       struct diff_filespec *,
-                                       struct diff_filespec *);
-extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
+struct diff_filepair *diff_queue(struct diff_queue_struct *,
+                                struct diff_filespec *,
+                                struct diff_filespec *);
+void diff_q(struct diff_queue_struct *, struct diff_filepair *);
 
-extern void diffcore_break(int);
-extern void diffcore_rename(struct diff_options *);
-extern void diffcore_merge_broken(void);
-extern void diffcore_pickaxe(struct diff_options *);
-extern void diffcore_order(const char *orderfile);
+void diffcore_break(int);
+void diffcore_rename(struct diff_options *);
+void diffcore_merge_broken(void);
+void diffcore_pickaxe(struct diff_options *);
+void diffcore_order(const char *orderfile);
 
 /* low-level interface to diffcore_order */
 struct obj_order {
@@ -138,11 +138,11 @@ void diff_debug_queue(const char *, struct diff_queue_struct *);
 #define diff_debug_queue(a,b) do { /* nothing */ } while (0)
 #endif
 
-extern int diffcore_count_changes(struct diff_filespec *src,
-                                 struct diff_filespec *dst,
-                                 void **src_count_p,
-                                 void **dst_count_p,
-                                 unsigned long *src_copied,
-                                 unsigned long *literal_added);
+int diffcore_count_changes(struct diff_filespec *src,
+                          struct diff_filespec *dst,
+                          void **src_count_p,
+                          void **dst_count_p,
+                          unsigned long *src_copied,
+                          unsigned long *literal_added);
 
 #endif
diff --git a/dir.c b/dir.c
index fe9bf58e4c72790dca5492de4bd98df06798d27a..aceb0d48692b7d727cfd2645ae88b0d45d660c09 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -11,6 +11,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "object-store.h"
 #include "attr.h"
 #include "refs.h"
 #include "wildmatch.h"
@@ -275,12 +276,13 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
 #define DO_MATCH_DIRECTORY (1<<1)
 #define DO_MATCH_SUBMODULE (1<<2)
 
-static int match_attrs(const char *name, int namelen,
+static int match_attrs(const struct index_state *istate,
+                      const char *name, int namelen,
                       const struct pathspec_item *item)
 {
        int i;
 
-       git_check_attr(name, item->attr_check);
+       git_check_attr(istate, name, item->attr_check);
        for (i = 0; i < item->attr_match_nr; i++) {
                const char *value;
                int matched;
@@ -317,7 +319,8 @@ static int match_attrs(const char *name, int namelen,
  *
  * It returns 0 when there is no match.
  */
-static int match_pathspec_item(const struct pathspec_item *item, int prefix,
+static int match_pathspec_item(const struct index_state *istate,
+                              const struct pathspec_item *item, int prefix,
                               const char *name, int namelen, unsigned flags)
 {
        /* name/namelen has prefix cut off by caller */
@@ -357,7 +360,7 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,
            strncmp(item->match, name - prefix, item->prefix))
                return 0;
 
-       if (item->attr_match_nr && !match_attrs(name, namelen, item))
+       if (item->attr_match_nr && !match_attrs(istate, name, namelen, item))
                return 0;
 
        /* If the match was just the prefix, we matched */
@@ -425,7 +428,8 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,
  * pathspec did not match any names, which could indicate that the
  * user mistyped the nth pathspec.
  */
-static int do_match_pathspec(const struct pathspec *ps,
+static int do_match_pathspec(const struct index_state *istate,
+                            const struct pathspec *ps,
                             const char *name, int namelen,
                             int prefix, char *seen,
                             unsigned flags)
@@ -471,7 +475,7 @@ static int do_match_pathspec(const struct pathspec *ps,
                 */
                if (seen && ps->items[i].magic & PATHSPEC_EXCLUDE)
                        seen[i] = MATCHED_FNMATCH;
-               how = match_pathspec_item(ps->items+i, prefix, name,
+               how = match_pathspec_item(istate, ps->items+i, prefix, name,
                                          namelen, flags);
                if (ps->recursive &&
                    (ps->magic & PATHSPEC_MAXDEPTH) &&
@@ -495,17 +499,18 @@ static int do_match_pathspec(const struct pathspec *ps,
        return retval;
 }
 
-int match_pathspec(const struct pathspec *ps,
+int match_pathspec(const struct index_state *istate,
+                  const struct pathspec *ps,
                   const char *name, int namelen,
                   int prefix, char *seen, int is_dir)
 {
        int positive, negative;
        unsigned flags = is_dir ? DO_MATCH_DIRECTORY : 0;
-       positive = do_match_pathspec(ps, name, namelen,
+       positive = do_match_pathspec(istate, ps, name, namelen,
                                     prefix, seen, flags);
        if (!(ps->magic & PATHSPEC_EXCLUDE) || !positive)
                return positive;
-       negative = do_match_pathspec(ps, name, namelen,
+       negative = do_match_pathspec(istate, ps, name, namelen,
                                     prefix, seen,
                                     flags | DO_MATCH_EXCLUDE);
        return negative ? 0 : positive;
@@ -514,11 +519,12 @@ int match_pathspec(const struct pathspec *ps,
 /**
  * Check if a submodule is a superset of the pathspec
  */
-int submodule_path_match(const struct pathspec *ps,
+int submodule_path_match(const struct index_state *istate,
+                        const struct pathspec *ps,
                         const char *submodule_name,
                         char *seen)
 {
-       int matched = do_match_pathspec(ps, submodule_name,
+       int matched = do_match_pathspec(istate, ps, submodule_name,
                                        strlen(submodule_name),
                                        0, seen,
                                        DO_MATCH_DIRECTORY |
@@ -560,7 +566,7 @@ int report_path_error(const char *ps_matched,
                if (found_dup)
                        continue;
 
-               error("pathspec '%s' did not match any file(s) known to git.",
+               error(_("pathspec '%s' did not match any file(s) known to git"),
                      pathspec->items[num].original);
                errors++;
        }
@@ -949,7 +955,7 @@ static void add_excludes_from_file_1(struct dir_struct *dir, const char *fname,
                dir->unmanaged_exclude_files++;
        el = add_exclude_list(dir, EXC_FILE, fname);
        if (add_excludes(fname, "", 0, el, NULL, oid_stat) < 0)
-               die("cannot use %s as an exclude file", fname);
+               die(_("cannot use %s as an exclude file"), fname);
 }
 
 void add_excludes_from_file(struct dir_struct *dir, const char *fname)
@@ -2230,7 +2236,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
                return NULL;
 
        if (!ident_in_untracked(dir->untracked)) {
-               warning(_("Untracked cache is disabled on this system or location."));
+               warning(_("untracked cache is disabled on this system or location"));
                return NULL;
        }
 
@@ -2497,7 +2503,7 @@ void setup_standard_excludes(struct dir_struct *dir)
 {
        dir->exclude_per_dir = ".gitignore";
 
-       /* core.excludefile defaulting to $XDG_HOME/git/ignore */
+       /* core.excludesfile defaulting to $XDG_CONFIG_HOME/git/ignore */
        if (!excludes_file)
                excludes_file = xdg_config_home("ignore");
        if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
@@ -3028,7 +3034,7 @@ static void connect_wt_gitdir_in_nested(const char *sub_worktree,
                return;
 
        if (repo_read_index(&subrepo) < 0)
-               die("index file corrupt in repo %s", subrepo.gitdir);
+               die(_("index file corrupt in repo %s"), subrepo.gitdir);
 
        for (i = 0; i < subrepo.index->cache_nr; i++) {
                const struct cache_entry *ce = subrepo.index->cache[i];
diff --git a/dir.h b/dir.h
index f5fdedbab2520547f8de2e7c827f5f9c85c932ac..e3ec26143db26f3b8c300627a3c9557b08a17edb 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -216,7 +216,8 @@ extern int count_slashes(const char *s);
 extern int simple_length(const char *match);
 extern int no_wildcard(const char *string);
 extern char *common_prefix(const struct pathspec *pathspec);
-extern int match_pathspec(const struct pathspec *pathspec,
+extern int match_pathspec(const struct index_state *istate,
+                         const struct pathspec *pathspec,
                          const char *name, int namelen,
                          int prefix, char *seen, int is_dir);
 extern int report_path_error(const char *ps_matched, const struct pathspec *pathspec, const char *prefix);
@@ -326,25 +327,28 @@ extern int git_fnmatch(const struct pathspec_item *item,
                       const char *pattern, const char *string,
                       int prefix);
 
-extern int submodule_path_match(const struct pathspec *ps,
+extern int submodule_path_match(const struct index_state *istate,
+                               const struct pathspec *ps,
                                const char *submodule_name,
                                char *seen);
 
-static inline int ce_path_match(const struct cache_entry *ce,
+static inline int ce_path_match(const struct index_state *istate,
+                               const struct cache_entry *ce,
                                const struct pathspec *pathspec,
                                char *seen)
 {
-       return match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen,
+       return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
                              S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
 }
 
-static inline int dir_path_match(const struct dir_entry *ent,
+static inline int dir_path_match(const struct index_state *istate,
+                                const struct dir_entry *ent,
                                 const struct pathspec *pathspec,
                                 int prefix, char *seen)
 {
        int has_trailing_dir = ent->len && ent->name[ent->len - 1] == '/';
        int len = has_trailing_dir ? ent->len - 1 : ent->len;
-       return match_pathspec(pathspec, ent->name, len, prefix, seen,
+       return match_pathspec(istate, pathspec, ent->name, len, prefix, seen,
                              has_trailing_dir);
 }
 
diff --git a/entry.c b/entry.c
index 2101201a111785f449a65e785e9ed5b57b7aa196..2a2ab6c839490aba1b9d2723b8e05837855f5b39 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "blob.h"
+#include "object-store.h"
 #include "dir.h"
 #include "streaming.h"
 #include "submodule.h"
@@ -265,7 +266,7 @@ static int write_entry(struct cache_entry *ce,
        const struct submodule *sub;
 
        if (ce_mode_s_ifmt == S_IFREG) {
-               struct stream_filter *filter = get_stream_filter(ce->name,
+               struct stream_filter *filter = get_stream_filter(state->istate, ce->name,
                                                                 &ce->oid);
                if (filter &&
                    !streaming_write_entry(ce, path, filter,
@@ -313,14 +314,14 @@ static int write_entry(struct cache_entry *ce,
                 * Convert from git internal format to working tree format
                 */
                if (dco && dco->state != CE_NO_DELAY) {
-                       ret = async_convert_to_working_tree(ce->name, new_blob,
+                       ret = async_convert_to_working_tree(state->istate, ce->name, new_blob,
                                                            size, &buf, dco);
                        if (ret && string_list_has_string(&dco->paths, ce->name)) {
                                free(new_blob);
                                goto delayed;
                        }
                } else
-                       ret = convert_to_working_tree(ce->name, new_blob, size, &buf);
+                       ret = convert_to_working_tree(state->istate, ce->name, new_blob, size, &buf);
 
                if (ret) {
                        free(new_blob);
@@ -421,7 +422,8 @@ int checkout_entry(struct cache_entry *ce,
 
        if (!check_path(path.buf, path.len, &st, state->base_dir_len)) {
                const struct submodule *sub;
-               unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
+               unsigned changed = ie_match_stat(state->istate, ce, &st,
+                                                CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);
                /*
                 * Needs to be checked before !changed returns early,
                 * as the possibly empty directory was not changed
index 2a6de2330bc024d19ab0c1d8cc594f146ca6da11..68523b6b0ecd3bf924b075bd47bf0cd3426795f3 100644 (file)
@@ -51,7 +51,7 @@ const char *editor_program;
 const char *askpass_program;
 const char *excludes_file;
 enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
-int check_replace_refs = 1; /* NEEDSWORK: rename to read_replace_refs */
+int read_replace_refs = 1;
 char *git_replace_ref_base;
 enum eol core_eol = EOL_UNSET;
 int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
@@ -66,7 +66,6 @@ enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
 enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
 char *notes_ref_name;
 int grafts_replace_parents = 1;
-int core_commit_graph;
 int core_apply_sparse_checkout;
 int merge_log_config = -1;
 int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
@@ -147,7 +146,7 @@ static char *expand_namespace(const char *raw_namespace)
                        strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf);
        strbuf_list_free(components);
        if (check_refname_format(buf.buf, 0))
-               die("bad git namespace path \"%s\"", raw_namespace);
+               die(_("bad git namespace path \"%s\""), raw_namespace);
        strbuf_addch(&buf, '/');
        return strbuf_detach(&buf, NULL);
 }
@@ -183,7 +182,7 @@ void setup_git_env(const char *git_dir)
        argv_array_clear(&to_free);
 
        if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
-               check_replace_refs = 0;
+               read_replace_refs = 0;
        replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
        free(git_replace_ref_base);
        git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
@@ -192,7 +191,7 @@ void setup_git_env(const char *git_dir)
        git_namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
        shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
        if (shallow_file)
-               set_alternate_shallow_file(shallow_file, 0);
+               set_alternate_shallow_file(the_repository, shallow_file, 0);
 }
 
 int is_bare_repository(void)
@@ -319,17 +318,17 @@ char *get_index_file(void)
        return the_repository->index_file;
 }
 
-char *get_graft_file(void)
+char *get_graft_file(struct repository *r)
 {
-       if (!the_repository->graft_file)
+       if (!r->graft_file)
                BUG("git environment hasn't been setup");
-       return the_repository->graft_file;
+       return r->graft_file;
 }
 
 static void set_git_dir_1(const char *path)
 {
        if (setenv(GIT_DIR_ENVIRONMENT, path, 1))
-               die("could not set GIT_DIR to '%s'", path);
+               die(_("could not set GIT_DIR to '%s'"), path);
        setup_git_env(path);
 }
 
index 756bdd050e6df9e90bb08edc73617351d1c1f9b1..52f1178db4ce35103545a3e1ee00a3000b08eb90 100644 (file)
@@ -45,14 +45,6 @@ void bitmap_set(struct bitmap *self, size_t pos)
        self->words[block] |= EWAH_MASK(pos);
 }
 
-void bitmap_clear(struct bitmap *self, size_t pos)
-{
-       size_t block = EWAH_BLOCK(pos);
-
-       if (block < self->word_alloc)
-               self->words[block] &= ~EWAH_MASK(pos);
-}
-
 int bitmap_get(struct bitmap *self, size_t pos)
 {
        size_t block = EWAH_BLOCK(pos);
@@ -137,30 +129,6 @@ void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other)
                self->words[i++] |= word;
 }
 
-void bitmap_each_bit(struct bitmap *self, ewah_callback callback, void *data)
-{
-       size_t pos = 0, i;
-
-       for (i = 0; i < self->word_alloc; ++i) {
-               eword_t word = self->words[i];
-               uint32_t offset;
-
-               if (word == (eword_t)~0) {
-                       for (offset = 0; offset < BITS_IN_EWORD; ++offset)
-                               callback(pos++, data);
-               } else {
-                       for (offset = 0; offset < BITS_IN_EWORD; ++offset) {
-                               if ((word >> offset) == 0)
-                                       break;
-
-                               offset += ewah_bit_ctz64(word >> offset);
-                               callback(pos + offset, data);
-                       }
-                       pos += BITS_IN_EWORD;
-               }
-       }
-}
-
 size_t bitmap_popcount(struct bitmap *self)
 {
        size_t i, count = 0;
index b9fdda1d3d2e033ddcfa7c1b31730d4188c75306..d59b1afe3d6a83b89dc30e19e61f8a3e9b1cc0aa 100644 (file)
@@ -276,6 +276,18 @@ void ewah_each_bit(struct ewah_bitmap *self, void (*callback)(size_t, void*), vo
        }
 }
 
+/**
+ * Clear all the bits in the bitmap. Does not free or resize
+ * memory.
+ */
+static void ewah_clear(struct ewah_bitmap *self)
+{
+       self->buffer_size = 1;
+       self->buffer[0] = 0;
+       self->bit_size = 0;
+       self->rlw = self->buffer;
+}
+
 struct ewah_bitmap *ewah_new(void)
 {
        struct ewah_bitmap *self;
@@ -288,14 +300,6 @@ struct ewah_bitmap *ewah_new(void)
        return self;
 }
 
-void ewah_clear(struct ewah_bitmap *self)
-{
-       self->buffer_size = 1;
-       self->buffer[0] = 0;
-       self->bit_size = 0;
-       self->rlw = self->buffer;
-}
-
 void ewah_free(struct ewah_bitmap *self)
 {
        if (!self)
@@ -376,25 +380,6 @@ void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent)
                read_new_rlw(it);
 }
 
-void ewah_not(struct ewah_bitmap *self)
-{
-       size_t pointer = 0;
-
-       while (pointer < self->buffer_size) {
-               eword_t *word = &self->buffer[pointer];
-               size_t literals, k;
-
-               rlw_xor_run_bit(word);
-               ++pointer;
-
-               literals = rlw_get_literal_words(word);
-               for (k = 0; k < literals; ++k) {
-                       self->buffer[pointer] = ~self->buffer[pointer];
-                       ++pointer;
-               }
-       }
-}
-
 void ewah_xor(
        struct ewah_bitmap *ewah_i,
        struct ewah_bitmap *ewah_j,
@@ -459,216 +444,6 @@ void ewah_xor(
        out->bit_size = max_size(ewah_i->bit_size, ewah_j->bit_size);
 }
 
-void ewah_and(
-       struct ewah_bitmap *ewah_i,
-       struct ewah_bitmap *ewah_j,
-       struct ewah_bitmap *out)
-{
-       struct rlw_iterator rlw_i;
-       struct rlw_iterator rlw_j;
-       size_t literals;
-
-       rlwit_init(&rlw_i, ewah_i);
-       rlwit_init(&rlw_j, ewah_j);
-
-       while (rlwit_word_size(&rlw_i) > 0 && rlwit_word_size(&rlw_j) > 0) {
-               while (rlw_i.rlw.running_len > 0 || rlw_j.rlw.running_len > 0) {
-                       struct rlw_iterator *prey, *predator;
-
-                       if (rlw_i.rlw.running_len < rlw_j.rlw.running_len) {
-                               prey = &rlw_i;
-                               predator = &rlw_j;
-                       } else {
-                               prey = &rlw_j;
-                               predator = &rlw_i;
-                       }
-
-                       if (predator->rlw.running_bit == 0) {
-                               ewah_add_empty_words(out, 0,
-                                       predator->rlw.running_len);
-                               rlwit_discard_first_words(prey,
-                                       predator->rlw.running_len);
-                               rlwit_discard_first_words(predator,
-                                       predator->rlw.running_len);
-                       } else {
-                               size_t index = rlwit_discharge(prey, out,
-                                       predator->rlw.running_len, 0);
-                               ewah_add_empty_words(out, 0,
-                                       predator->rlw.running_len - index);
-                               rlwit_discard_first_words(predator,
-                                       predator->rlw.running_len);
-                       }
-               }
-
-               literals = min_size(
-                       rlw_i.rlw.literal_words,
-                       rlw_j.rlw.literal_words);
-
-               if (literals) {
-                       size_t k;
-
-                       for (k = 0; k < literals; ++k) {
-                               ewah_add(out,
-                                       rlw_i.buffer[rlw_i.literal_word_start + k] &
-                                       rlw_j.buffer[rlw_j.literal_word_start + k]
-                               );
-                       }
-
-                       rlwit_discard_first_words(&rlw_i, literals);
-                       rlwit_discard_first_words(&rlw_j, literals);
-               }
-       }
-
-       if (rlwit_word_size(&rlw_i) > 0)
-               rlwit_discharge_empty(&rlw_i, out);
-       else
-               rlwit_discharge_empty(&rlw_j, out);
-
-       out->bit_size = max_size(ewah_i->bit_size, ewah_j->bit_size);
-}
-
-void ewah_and_not(
-       struct ewah_bitmap *ewah_i,
-       struct ewah_bitmap *ewah_j,
-       struct ewah_bitmap *out)
-{
-       struct rlw_iterator rlw_i;
-       struct rlw_iterator rlw_j;
-       size_t literals;
-
-       rlwit_init(&rlw_i, ewah_i);
-       rlwit_init(&rlw_j, ewah_j);
-
-       while (rlwit_word_size(&rlw_i) > 0 && rlwit_word_size(&rlw_j) > 0) {
-               while (rlw_i.rlw.running_len > 0 || rlw_j.rlw.running_len > 0) {
-                       struct rlw_iterator *prey, *predator;
-
-                       if (rlw_i.rlw.running_len < rlw_j.rlw.running_len) {
-                               prey = &rlw_i;
-                               predator = &rlw_j;
-                       } else {
-                               prey = &rlw_j;
-                               predator = &rlw_i;
-                       }
-
-                       if ((predator->rlw.running_bit && prey == &rlw_i) ||
-                               (!predator->rlw.running_bit && prey != &rlw_i)) {
-                               ewah_add_empty_words(out, 0,
-                                       predator->rlw.running_len);
-                               rlwit_discard_first_words(prey,
-                                       predator->rlw.running_len);
-                               rlwit_discard_first_words(predator,
-                                       predator->rlw.running_len);
-                       } else {
-                               size_t index;
-                               int negate_words;
-
-                               negate_words = (&rlw_i != prey);
-                               index = rlwit_discharge(prey, out,
-                                       predator->rlw.running_len, negate_words);
-                               ewah_add_empty_words(out, negate_words,
-                                       predator->rlw.running_len - index);
-                               rlwit_discard_first_words(predator,
-                                       predator->rlw.running_len);
-                       }
-               }
-
-               literals = min_size(
-                       rlw_i.rlw.literal_words,
-                       rlw_j.rlw.literal_words);
-
-               if (literals) {
-                       size_t k;
-
-                       for (k = 0; k < literals; ++k) {
-                               ewah_add(out,
-                                       rlw_i.buffer[rlw_i.literal_word_start + k] &
-                                       ~(rlw_j.buffer[rlw_j.literal_word_start + k])
-                               );
-                       }
-
-                       rlwit_discard_first_words(&rlw_i, literals);
-                       rlwit_discard_first_words(&rlw_j, literals);
-               }
-       }
-
-       if (rlwit_word_size(&rlw_i) > 0)
-               rlwit_discharge(&rlw_i, out, ~0, 0);
-       else
-               rlwit_discharge_empty(&rlw_j, out);
-
-       out->bit_size = max_size(ewah_i->bit_size, ewah_j->bit_size);
-}
-
-void ewah_or(
-       struct ewah_bitmap *ewah_i,
-       struct ewah_bitmap *ewah_j,
-       struct ewah_bitmap *out)
-{
-       struct rlw_iterator rlw_i;
-       struct rlw_iterator rlw_j;
-       size_t literals;
-
-       rlwit_init(&rlw_i, ewah_i);
-       rlwit_init(&rlw_j, ewah_j);
-
-       while (rlwit_word_size(&rlw_i) > 0 && rlwit_word_size(&rlw_j) > 0) {
-               while (rlw_i.rlw.running_len > 0 || rlw_j.rlw.running_len > 0) {
-                       struct rlw_iterator *prey, *predator;
-
-                       if (rlw_i.rlw.running_len < rlw_j.rlw.running_len) {
-                               prey = &rlw_i;
-                               predator = &rlw_j;
-                       } else {
-                               prey = &rlw_j;
-                               predator = &rlw_i;
-                       }
-
-                       if (predator->rlw.running_bit) {
-                               ewah_add_empty_words(out, 0,
-                                       predator->rlw.running_len);
-                               rlwit_discard_first_words(prey,
-                                       predator->rlw.running_len);
-                               rlwit_discard_first_words(predator,
-                                       predator->rlw.running_len);
-                       } else {
-                               size_t index = rlwit_discharge(prey, out,
-                                       predator->rlw.running_len, 0);
-                               ewah_add_empty_words(out, 0,
-                                       predator->rlw.running_len - index);
-                               rlwit_discard_first_words(predator,
-                                       predator->rlw.running_len);
-                       }
-               }
-
-               literals = min_size(
-                       rlw_i.rlw.literal_words,
-                       rlw_j.rlw.literal_words);
-
-               if (literals) {
-                       size_t k;
-
-                       for (k = 0; k < literals; ++k) {
-                               ewah_add(out,
-                                       rlw_i.buffer[rlw_i.literal_word_start + k] |
-                                       rlw_j.buffer[rlw_j.literal_word_start + k]
-                               );
-                       }
-
-                       rlwit_discard_first_words(&rlw_i, literals);
-                       rlwit_discard_first_words(&rlw_j, literals);
-               }
-       }
-
-       if (rlwit_word_size(&rlw_i) > 0)
-               rlwit_discharge(&rlw_i, out, ~0, 0);
-       else
-               rlwit_discharge(&rlw_j, out, ~0, 0);
-
-       out->bit_size = max_size(ewah_i->bit_size, ewah_j->bit_size);
-}
-
-
 #define BITMAP_POOL_MAX 16
 static struct ewah_bitmap *bitmap_pool[BITMAP_POOL_MAX];
 static size_t bitmap_pool_size;
index 33c08c40f896f32d9a1c251c1456755e949d91bd..9035ee65ea8db67c373492fcb1755f8b1499679e 100644 (file)
 #include "ewok.h"
 #include "strbuf.h"
 
-int ewah_serialize_native(struct ewah_bitmap *self, int fd)
-{
-       uint32_t write32;
-       size_t to_write = self->buffer_size * 8;
-
-       /* 32 bit -- bit size for the map */
-       write32 = (uint32_t)self->bit_size;
-       if (write(fd, &write32, 4) != 4)
-               return -1;
-
-       /** 32 bit -- number of compressed 64-bit words */
-       write32 = (uint32_t)self->buffer_size;
-       if (write(fd, &write32, 4) != 4)
-               return -1;
-
-       if (write(fd, self->buffer, to_write) != to_write)
-               return -1;
-
-       /** 32 bit -- position for the RLW */
-       write32 = self->rlw - self->buffer;
-       if (write(fd, &write32, 4) != 4)
-               return -1;
-
-       return (3 * 4) + to_write;
-}
-
 int ewah_serialize_to(struct ewah_bitmap *self,
                      int (*write_fun)(void *, const void *, size_t),
                      void *data)
@@ -100,16 +74,6 @@ int ewah_serialize_to(struct ewah_bitmap *self,
        return (3 * 4) + (self->buffer_size * 8);
 }
 
-static int write_helper(void *fd, const void *buf, size_t len)
-{
-       return write((intptr_t)fd, buf, len);
-}
-
-int ewah_serialize(struct ewah_bitmap *self, int fd)
-{
-       return ewah_serialize_to(self, write_helper, (void *)(intptr_t)fd);
-}
-
 static int write_strbuf(void *user_data, const void *data, size_t len)
 {
        struct strbuf *sb = user_data;
@@ -168,58 +132,3 @@ ssize_t ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len)
 
        return ptr - (const uint8_t *)map;
 }
-
-int ewah_deserialize(struct ewah_bitmap *self, int fd)
-{
-       size_t i;
-       eword_t dump[2048];
-       const size_t words_per_dump = sizeof(dump) / sizeof(eword_t);
-       uint32_t bitsize, word_count, rlw_pos;
-
-       eword_t *buffer = NULL;
-       size_t words_left;
-
-       ewah_clear(self);
-
-       /* 32 bit -- bit size for the map */
-       if (read(fd, &bitsize, 4) != 4)
-               return -1;
-
-       self->bit_size = (size_t)ntohl(bitsize);
-
-       /** 32 bit -- number of compressed 64-bit words */
-       if (read(fd, &word_count, 4) != 4)
-               return -1;
-
-       self->buffer_size = self->alloc_size = (size_t)ntohl(word_count);
-       REALLOC_ARRAY(self->buffer, self->alloc_size);
-
-       /** 64 bit x N -- compressed words */
-       buffer = self->buffer;
-       words_left = self->buffer_size;
-
-       while (words_left >= words_per_dump) {
-               if (read(fd, dump, sizeof(dump)) != sizeof(dump))
-                       return -1;
-
-               for (i = 0; i < words_per_dump; ++i, ++buffer)
-                       *buffer = ntohll(dump[i]);
-
-               words_left -= words_per_dump;
-       }
-
-       if (words_left) {
-               if (read(fd, dump, words_left * 8) != words_left * 8)
-                       return -1;
-
-               for (i = 0; i < words_left; ++i, ++buffer)
-                       *buffer = ntohll(dump[i]);
-       }
-
-       /** 32 bit -- position for the RLW */
-       if (read(fd, &rlw_pos, 4) != 4)
-               return -1;
-
-       self->rlw = self->buffer + ntohl(rlw_pos);
-       return 0;
-}
index b9643b7d0f4420b0ebbd7315a3308407bdfafa53..5093d43e2f00e2bec4290c1fe918d8a0593e2e8c 100644 (file)
@@ -104,11 +104,3 @@ size_t rlwit_discharge(
 
        return index;
 }
-
-void rlwit_discharge_empty(struct rlw_iterator *it, struct ewah_bitmap *out)
-{
-       while (rlwit_word_size(it) > 0) {
-               ewah_add_empty_words(out, 0, rlwit_word_size(it));
-               rlwit_discard_first_words(it, rlwit_word_size(it));
-       }
-}
index 357fd93c84edbe79f9bcb10e2947ed935ac9f0df..84b2a29faa0c57410168ad5afb2dbaa7a49ddd60 100644 (file)
@@ -72,12 +72,6 @@ void ewah_pool_free(struct ewah_bitmap *self);
  */
 struct ewah_bitmap *ewah_new(void);
 
-/**
- * Clear all the bits in the bitmap. Does not free or resize
- * memory.
- */
-void ewah_clear(struct ewah_bitmap *self);
-
 /**
  * Free all the memory of the bitmap
  */
@@ -86,22 +80,12 @@ void ewah_free(struct ewah_bitmap *self);
 int ewah_serialize_to(struct ewah_bitmap *self,
                      int (*write_fun)(void *out, const void *buf, size_t len),
                      void *out);
-int ewah_serialize(struct ewah_bitmap *self, int fd);
-int ewah_serialize_native(struct ewah_bitmap *self, int fd);
 int ewah_serialize_strbuf(struct ewah_bitmap *self, struct strbuf *);
 
-int ewah_deserialize(struct ewah_bitmap *self, int fd);
 ssize_t ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len);
 
 uint32_t ewah_checksum(struct ewah_bitmap *self);
 
-/**
- * Logical not (bitwise negation) in-place on the bitmap
- *
- * This operation is linear time based on the size of the bitmap.
- */
-void ewah_not(struct ewah_bitmap *self);
-
 /**
  * Call the given callback with the position of every single bit
  * that has been set on the bitmap.
@@ -164,26 +148,11 @@ void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent);
  */
 int ewah_iterator_next(eword_t *next, struct ewah_iterator *it);
 
-void ewah_or(
-       struct ewah_bitmap *ewah_i,
-       struct ewah_bitmap *ewah_j,
-       struct ewah_bitmap *out);
-
-void ewah_and_not(
-       struct ewah_bitmap *ewah_i,
-       struct ewah_bitmap *ewah_j,
-       struct ewah_bitmap *out);
-
 void ewah_xor(
        struct ewah_bitmap *ewah_i,
        struct ewah_bitmap *ewah_j,
        struct ewah_bitmap *out);
 
-void ewah_and(
-       struct ewah_bitmap *ewah_i,
-       struct ewah_bitmap *ewah_j,
-       struct ewah_bitmap *out);
-
 /**
  * Direct word access
  */
@@ -204,7 +173,6 @@ struct bitmap {
 
 struct bitmap *bitmap_new(void);
 void bitmap_set(struct bitmap *self, size_t pos);
-void bitmap_clear(struct bitmap *self, size_t pos);
 int bitmap_get(struct bitmap *self, size_t pos);
 void bitmap_reset(struct bitmap *self);
 void bitmap_free(struct bitmap *self);
@@ -218,7 +186,6 @@ void bitmap_and_not(struct bitmap *self, struct bitmap *other);
 void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other);
 void bitmap_or(struct bitmap *self, const struct bitmap *other);
 
-void bitmap_each_bit(struct bitmap *self, ewah_callback callback, void *data);
 size_t bitmap_popcount(struct bitmap *self);
 
 #endif
index bb3c6ff7e05c0e3cb51a2ae5a065baa372e1d7f4..7cdfdd0c020e37abbc30624b2ea1bcf4ef0ddfee 100644 (file)
@@ -98,7 +98,6 @@ void rlwit_init(struct rlw_iterator *it, struct ewah_bitmap *bitmap);
 void rlwit_discard_first_words(struct rlw_iterator *it, size_t x);
 size_t rlwit_discharge(
        struct rlw_iterator *it, struct ewah_bitmap *out, size_t max, int negate);
-void rlwit_discharge_empty(struct rlw_iterator *it, struct ewah_bitmap *out);
 
 static inline size_t rlwit_word_size(struct rlw_iterator *it)
 {
index 02d31ee89711da7a4d5a483c6339909c05a15e08..4f81f443105f071e488a0436b7fe0579e22bc816 100644 (file)
@@ -358,7 +358,7 @@ int execl_git_cmd(const char *cmd, ...)
        }
        va_end(param);
        if (MAX_ARGS <= argc)
-               return error("too many args to run %s", cmd);
+               return error(_("too many args to run %s"), cmd);
 
        argv[argc] = NULL;
        return execv_git_cmd(argv);
index 4d55910ab9a0634a553c01643035ef9afe6034c7..89bb0c9db3de9b380aad53709d882cb04f7d054a 100644 (file)
@@ -1076,7 +1076,7 @@ static int store_object(
                return 1;
        }
 
-       if (last && last->data.buf && last->depth < max_depth
+       if (last && last->data.len && last->data.buf && last->depth < max_depth
                && dat->len > the_hash_algo->rawsz) {
 
                delta_count_attempts_by_type[type]++;
@@ -1724,8 +1724,10 @@ static int update_branch(struct branch *b)
        if (!force_update && !is_null_oid(&old_oid)) {
                struct commit *old_cmit, *new_cmit;
 
-               old_cmit = lookup_commit_reference_gently(&old_oid, 0);
-               new_cmit = lookup_commit_reference_gently(&b->oid, 0);
+               old_cmit = lookup_commit_reference_gently(the_repository,
+                                                         &old_oid, 0);
+               new_cmit = lookup_commit_reference_gently(the_repository,
+                                                         &b->oid, 0);
                if (!old_cmit || !new_cmit)
                        return error("Branch %s is missing commits.", b->name);
 
diff --git a/fetch-negotiator.c b/fetch-negotiator.c
new file mode 100644 (file)
index 0000000..d6d685c
--- /dev/null
@@ -0,0 +1,20 @@
+#include "git-compat-util.h"
+#include "fetch-negotiator.h"
+#include "negotiator/default.h"
+#include "negotiator/skipping.h"
+
+void fetch_negotiator_init(struct fetch_negotiator *negotiator,
+                          const char *algorithm)
+{
+       if (algorithm) {
+               if (!strcmp(algorithm, "skipping")) {
+                       skipping_negotiator_init(negotiator);
+                       return;
+               } else if (!strcmp(algorithm, "default")) {
+                       /* Fall through to default initialization */
+               } else {
+                       die("unknown fetch negotiation algorithm '%s'", algorithm);
+               }
+       }
+       default_negotiator_init(negotiator);
+}
diff --git a/fetch-negotiator.h b/fetch-negotiator.h
new file mode 100644 (file)
index 0000000..ddb44a2
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef FETCH_NEGOTIATOR
+#define FETCH_NEGOTIATOR
+
+struct commit;
+
+/*
+ * An object that supplies the information needed to negotiate the contents of
+ * the to-be-sent packfile during a fetch.
+ *
+ * To set up the negotiator, call fetch_negotiator_init(), then known_common()
+ * (0 or more times), then add_tip() (0 or more times).
+ *
+ * Then, when "have" lines are required, call next(). Call ack() to report what
+ * the server tells us.
+ *
+ * Once negotiation is done, call release(). The negotiator then cannot be used
+ * (unless reinitialized with fetch_negotiator_init()).
+ */
+struct fetch_negotiator {
+       /*
+        * Before negotiation starts, indicate that the server is known to have
+        * this commit.
+        */
+       void (*known_common)(struct fetch_negotiator *, struct commit *);
+
+       /*
+        * Once this function is invoked, known_common() cannot be invoked any
+        * more.
+        *
+        * Indicate that this commit and all its ancestors are to be checked
+        * for commonality with the server.
+        */
+       void (*add_tip)(struct fetch_negotiator *, struct commit *);
+
+       /*
+        * Once this function is invoked, known_common() and add_tip() cannot
+        * be invoked any more.
+        *
+        * Return the next commit that the client should send as a "have" line.
+        */
+       const struct object_id *(*next)(struct fetch_negotiator *);
+
+       /*
+        * Inform the negotiator that the server has the given commit. This
+        * method must only be called on commits returned by next().
+        */
+       int (*ack)(struct fetch_negotiator *, struct commit *);
+
+       void (*release)(struct fetch_negotiator *);
+
+       /* internal use */
+       void *data;
+};
+
+void fetch_negotiator_init(struct fetch_negotiator *negotiator,
+                          const char *algorithm);
+
+#endif
index cc7a42fee9fad161e37caacf87a15b2c1e33ec94..88a078e9befd281cf5f03e9e64615b14ca768a35 100644 (file)
 #include "connect.h"
 #include "transport.h"
 #include "version.h"
-#include "prio-queue.h"
 #include "sha1-array.h"
 #include "oidset.h"
 #include "packfile.h"
+#include "object-store.h"
+#include "connected.h"
+#include "fetch-negotiator.h"
+#include "fsck.h"
 
 static int transfer_unpack_limit = -1;
 static int fetch_unpack_limit = -1;
@@ -33,16 +36,12 @@ static int agent_supported;
 static int server_supports_filtering;
 static struct lock_file shallow_lock;
 static const char *alternate_shallow_file;
+static char *negotiation_algorithm;
+static struct strbuf fsck_msg_types = STRBUF_INIT;
 
 /* Remember to update object flag allocation in object.h */
 #define COMPLETE       (1U << 0)
-#define COMMON         (1U << 1)
-#define COMMON_REF     (1U << 2)
-#define SEEN           (1U << 3)
-#define POPPED         (1U << 4)
-#define ALTERNATE      (1U << 5)
-
-static int marked;
+#define ALTERNATE      (1U << 1)
 
 /*
  * After sending this many "have"s if we do not get any new ACK , we
@@ -50,8 +49,7 @@ static int marked;
  */
 #define MAX_IN_VAIN 256
 
-static struct prio_queue rev_list = { compare_commits_by_commit_date };
-static int non_common_revs, multi_ack, use_sideband;
+static int multi_ack, use_sideband;
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1 01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -83,7 +81,7 @@ static void cache_one_alternate(const char *refname,
                                void *vcache)
 {
        struct alternate_object_cache *cache = vcache;
-       struct object *obj = parse_object(oid);
+       struct object *obj = parse_object(the_repository, oid);
 
        if (!obj || (obj->flags & ALTERNATE))
                return;
@@ -93,7 +91,9 @@ static void cache_one_alternate(const char *refname,
        cache->items[cache->nr++] = obj;
 }
 
-static void for_each_cached_alternate(void (*cb)(struct object *))
+static void for_each_cached_alternate(struct fetch_negotiator *negotiator,
+                                     void (*cb)(struct fetch_negotiator *,
+                                                struct object *))
 {
        static int initialized;
        static struct alternate_object_cache cache;
@@ -105,30 +105,19 @@ static void for_each_cached_alternate(void (*cb)(struct object *))
        }
 
        for (i = 0; i < cache.nr; i++)
-               cb(cache.items[i]);
+               cb(negotiator, cache.items[i]);
 }
 
-static void rev_list_push(struct commit *commit, int mark)
+static int rev_list_insert_ref(struct fetch_negotiator *negotiator,
+                              const char *refname,
+                              const struct object_id *oid)
 {
-       if (!(commit->object.flags & mark)) {
-               commit->object.flags |= mark;
-
-               if (parse_commit(commit))
-                       return;
-
-               prio_queue_put(&rev_list, commit);
-
-               if (!(commit->object.flags & COMMON))
-                       non_common_revs++;
-       }
-}
-
-static int rev_list_insert_ref(const char *refname, const struct object_id *oid)
-{
-       struct object *o = deref_tag(parse_object(oid), refname, 0);
+       struct object *o = deref_tag(the_repository,
+                                    parse_object(the_repository, oid),
+                                    refname, 0);
 
        if (o && o->type == OBJ_COMMIT)
-               rev_list_push((struct commit *)o, SEEN);
+               negotiator->add_tip(negotiator, (struct commit *)o);
 
        return 0;
 }
@@ -136,98 +125,7 @@ static int rev_list_insert_ref(const char *refname, const struct object_id *oid)
 static int rev_list_insert_ref_oid(const char *refname, const struct object_id *oid,
                                   int flag, void *cb_data)
 {
-       return rev_list_insert_ref(refname, oid);
-}
-
-static int clear_marks(const char *refname, const struct object_id *oid,
-                      int flag, void *cb_data)
-{
-       struct object *o = deref_tag(parse_object(oid), refname, 0);
-
-       if (o && o->type == OBJ_COMMIT)
-               clear_commit_marks((struct commit *)o,
-                                  COMMON | COMMON_REF | SEEN | POPPED);
-       return 0;
-}
-
-/*
-   This function marks a rev and its ancestors as common.
-   In some cases, it is desirable to mark only the ancestors (for example
-   when only the server does not yet know that they are common).
-*/
-
-static void mark_common(struct commit *commit,
-               int ancestors_only, int dont_parse)
-{
-       if (commit != NULL && !(commit->object.flags & COMMON)) {
-               struct object *o = (struct object *)commit;
-
-               if (!ancestors_only)
-                       o->flags |= COMMON;
-
-               if (!(o->flags & SEEN))
-                       rev_list_push(commit, SEEN);
-               else {
-                       struct commit_list *parents;
-
-                       if (!ancestors_only && !(o->flags & POPPED))
-                               non_common_revs--;
-                       if (!o->parsed && !dont_parse)
-                               if (parse_commit(commit))
-                                       return;
-
-                       for (parents = commit->parents;
-                                       parents;
-                                       parents = parents->next)
-                               mark_common(parents->item, 0, dont_parse);
-               }
-       }
-}
-
-/*
-  Get the next rev to send, ignoring the common.
-*/
-
-static const struct object_id *get_rev(void)
-{
-       struct commit *commit = NULL;
-
-       while (commit == NULL) {
-               unsigned int mark;
-               struct commit_list *parents;
-
-               if (rev_list.nr == 0 || non_common_revs == 0)
-                       return NULL;
-
-               commit = prio_queue_get(&rev_list);
-               parse_commit(commit);
-               parents = commit->parents;
-
-               commit->object.flags |= POPPED;
-               if (!(commit->object.flags & COMMON))
-                       non_common_revs--;
-
-               if (commit->object.flags & COMMON) {
-                       /* do not send "have", and ignore ancestors */
-                       commit = NULL;
-                       mark = COMMON | SEEN;
-               } else if (commit->object.flags & COMMON_REF)
-                       /* send "have", and ignore ancestors */
-                       mark = COMMON | SEEN;
-               else
-                       /* send "have", also for its ancestors */
-                       mark = SEEN;
-
-               while (parents) {
-                       if (!(parents->item->object.flags & SEEN))
-                               rev_list_push(parents->item, mark);
-                       if (mark & COMMON)
-                               mark_common(parents->item, 1, 0);
-                       parents = parents->next;
-               }
-       }
-
-       return &commit->object.oid;
+       return rev_list_insert_ref(cb_data, refname, oid);
 }
 
 enum ack_type {
@@ -296,9 +194,10 @@ static void send_request(struct fetch_pack_args *args,
                write_or_die(fd, buf->buf, buf->len);
 }
 
-static void insert_one_alternate_object(struct object *obj)
+static void insert_one_alternate_object(struct fetch_negotiator *negotiator,
+                                       struct object *obj)
 {
-       rev_list_insert_ref(NULL, &obj->oid);
+       rev_list_insert_ref(negotiator, NULL, &obj->oid);
 }
 
 #define INITIAL_FLUSH 16
@@ -321,7 +220,24 @@ static int next_flush(int stateless_rpc, int count)
        return count;
 }
 
-static int find_common(struct fetch_pack_args *args,
+static void mark_tips(struct fetch_negotiator *negotiator,
+                     const struct oid_array *negotiation_tips)
+{
+       int i;
+
+       if (!negotiation_tips) {
+               for_each_ref(rev_list_insert_ref_oid, negotiator);
+               return;
+       }
+
+       for (i = 0; i < negotiation_tips->nr; i++)
+               rev_list_insert_ref(negotiator, NULL,
+                                   &negotiation_tips->oid[i]);
+       return;
+}
+
+static int find_common(struct fetch_negotiator *negotiator,
+                      struct fetch_pack_args *args,
                       int fd[2], struct object_id *result_oid,
                       struct ref *refs)
 {
@@ -336,12 +252,9 @@ static int find_common(struct fetch_pack_args *args,
 
        if (args->stateless_rpc && multi_ack == 1)
                die(_("--stateless-rpc requires multi_ack_detailed"));
-       if (marked)
-               for_each_ref(clear_marks, NULL);
-       marked = 1;
 
-       for_each_ref(rev_list_insert_ref_oid, NULL);
-       for_each_cached_alternate(insert_one_alternate_object);
+       mark_tips(negotiator, args->negotiation_tips);
+       for_each_cached_alternate(negotiator, insert_one_alternate_object);
 
        fetching = 0;
        for ( ; refs ; refs = refs->next) {
@@ -359,7 +272,7 @@ static int find_common(struct fetch_pack_args *args,
                 * interested in the case we *know* the object is
                 * reachable and we have already scanned it.
                 */
-               if (((o = lookup_object(remote->hash)) != NULL) &&
+               if (((o = lookup_object(the_repository, remote->hash)) != NULL) &&
                                (o->flags & COMPLETE)) {
                        continue;
                }
@@ -396,7 +309,7 @@ static int find_common(struct fetch_pack_args *args,
                return 1;
        }
 
-       if (is_repository_shallow())
+       if (is_repository_shallow(the_repository))
                write_shallow_commits(&req_buf, 1, NULL);
        if (args->depth > 0)
                packet_buf_write(&req_buf, "deepen %d", args->depth);
@@ -427,16 +340,16 @@ static int find_common(struct fetch_pack_args *args,
                        if (skip_prefix(line, "shallow ", &arg)) {
                                if (get_oid_hex(arg, &oid))
                                        die(_("invalid shallow line: %s"), line);
-                               register_shallow(&oid);
+                               register_shallow(the_repository, &oid);
                                continue;
                        }
                        if (skip_prefix(line, "unshallow ", &arg)) {
                                if (get_oid_hex(arg, &oid))
                                        die(_("invalid unshallow line: %s"), line);
-                               if (!lookup_object(oid.hash))
+                               if (!lookup_object(the_repository, oid.hash))
                                        die(_("object not found: %s"), line);
                                /* make sure that it is parsed as shallow */
-                               if (!parse_object(&oid))
+                               if (!parse_object(the_repository, &oid))
                                        die(_("error in object: %s"), line);
                                if (unregister_shallow(&oid))
                                        die(_("no shallow found: %s"), line);
@@ -459,7 +372,7 @@ static int find_common(struct fetch_pack_args *args,
        retval = -1;
        if (args->no_dependents)
                goto done;
-       while ((oid = get_rev())) {
+       while ((oid = negotiator->next(negotiator))) {
                packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid));
                print_verbose(args, "have %s", oid_to_hex(oid));
                in_vain++;
@@ -495,12 +408,16 @@ static int find_common(struct fetch_pack_args *args,
                                case ACK_ready:
                                case ACK_continue: {
                                        struct commit *commit =
-                                               lookup_commit(result_oid);
+                                               lookup_commit(the_repository,
+                                                             result_oid);
+                                       int was_common;
+
                                        if (!commit)
                                                die(_("invalid commit %s"), oid_to_hex(result_oid));
+                                       was_common = negotiator->ack(negotiator, commit);
                                        if (args->stateless_rpc
                                         && ack == ACK_common
-                                        && !(commit->object.flags & COMMON)) {
+                                        && !was_common) {
                                                /* We need to replay the have for this object
                                                 * on the next RPC request so the peer knows
                                                 * it is in common with us.
@@ -517,13 +434,10 @@ static int find_common(struct fetch_pack_args *args,
                                        } else if (!args->stateless_rpc
                                                   || ack != ACK_common)
                                                in_vain = 0;
-                                       mark_common(commit, 0, 1);
                                        retval = 0;
                                        got_continue = 1;
-                                       if (ack == ACK_ready) {
-                                               clear_prio_queue(&rev_list);
+                                       if (ack == ACK_ready)
                                                got_ready = 1;
-                                       }
                                        break;
                                        }
                                }
@@ -533,6 +447,8 @@ static int find_common(struct fetch_pack_args *args,
                                print_verbose(args, _("giving up"));
                                break; /* give up */
                        }
+                       if (got_ready)
+                               break;
                }
        }
 done:
@@ -569,14 +485,14 @@ static struct commit_list *complete;
 
 static int mark_complete(const struct object_id *oid)
 {
-       struct object *o = parse_object(oid);
+       struct object *o = parse_object(the_repository, oid);
 
        while (o && o->type == OBJ_TAG) {
                struct tag *t = (struct tag *) o;
                if (!t->tagged)
                        break; /* broken repository */
                o->flags |= COMPLETE;
-               o = parse_object(&t->tagged->oid);
+               o = parse_object(the_repository, &t->tagged->oid);
        }
        if (o && o->type == OBJ_COMMIT) {
                struct commit *commit = (struct commit *)o;
@@ -707,7 +623,8 @@ static void filter_refs(struct fetch_pack_args *args,
        *refs = newlist;
 }
 
-static void mark_alternate_complete(struct object *obj)
+static void mark_alternate_complete(struct fetch_negotiator *unused,
+                                   struct object *obj)
 {
        mark_complete(&obj->oid);
 }
@@ -734,12 +651,21 @@ static int add_loose_objects_to_set(const struct object_id *oid,
        return 0;
 }
 
-static int everything_local(struct fetch_pack_args *args,
-                           struct ref **refs,
-                           struct ref **sought, int nr_sought)
+/*
+ * Mark recent commits available locally and reachable from a local ref as
+ * COMPLETE. If args->no_dependents is false, also mark COMPLETE remote refs as
+ * COMMON_REF (otherwise, we are not planning to participate in negotiation, and
+ * thus do not need COMMON_REF marks).
+ *
+ * The cutoff time for recency is determined by this heuristic: it is the
+ * earliest commit time of the objects in refs that are commits and that we know
+ * the commit time of.
+ */
+static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
+                                        struct fetch_pack_args *args,
+                                        struct ref **refs)
 {
        struct ref *ref;
-       int retval;
        int old_save_commit_buffer = save_commit_buffer;
        timestamp_t cutoff = 0;
        struct oidset loose_oid_set = OIDSET_INIT;
@@ -767,7 +693,7 @@ static int everything_local(struct fetch_pack_args *args,
 
                if (!has_object_file_with_flags(&ref->old_oid, flags))
                        continue;
-               o = parse_object(&ref->old_oid);
+               o = parse_object(the_repository, &ref->old_oid);
                if (!o)
                        continue;
 
@@ -787,7 +713,7 @@ static int everything_local(struct fetch_pack_args *args,
        if (!args->no_dependents) {
                if (!args->deepen) {
                        for_each_ref(mark_complete_oid, NULL);
-                       for_each_cached_alternate(mark_alternate_complete);
+                       for_each_cached_alternate(NULL, mark_alternate_complete);
                        commit_list_sort_by_date(&complete);
                        if (cutoff)
                                mark_recent_complete_commits(args, cutoff);
@@ -798,27 +724,37 @@ static int everything_local(struct fetch_pack_args *args,
                 * Don't mark them common yet; the server has to be told so first.
                 */
                for (ref = *refs; ref; ref = ref->next) {
-                       struct object *o = deref_tag(lookup_object(ref->old_oid.hash),
+                       struct object *o = deref_tag(the_repository,
+                                                    lookup_object(the_repository,
+                                                    ref->old_oid.hash),
                                                     NULL, 0);
 
                        if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
                                continue;
 
-                       if (!(o->flags & SEEN)) {
-                               rev_list_push((struct commit *)o, COMMON_REF | SEEN);
-
-                               mark_common((struct commit *)o, 1, 1);
-                       }
+                       negotiator->known_common(negotiator,
+                                                (struct commit *)o);
                }
        }
 
-       filter_refs(args, refs, sought, nr_sought);
+       save_commit_buffer = old_save_commit_buffer;
+}
+
+/*
+ * Returns 1 if every object pointed to by the given remote refs is available
+ * locally and reachable from a local ref, and 0 otherwise.
+ */
+static int everything_local(struct fetch_pack_args *args,
+                           struct ref **refs)
+{
+       struct ref *ref;
+       int retval;
 
        for (retval = 1, ref = *refs; ref ; ref = ref->next) {
                const struct object_id *remote = &ref->old_oid;
                struct object *o;
 
-               o = lookup_object(remote->hash);
+               o = lookup_object(the_repository, remote->hash);
                if (!o || !(o->flags & COMPLETE)) {
                        retval = 0;
                        print_verbose(args, "want %s (%s)", oid_to_hex(remote),
@@ -829,8 +765,6 @@ static int everything_local(struct fetch_pack_args *args,
                              ref->name);
        }
 
-       save_commit_buffer = old_save_commit_buffer;
-
        return retval;
 }
 
@@ -935,7 +869,8 @@ static int get_pack(struct fetch_pack_args *args,
                         */
                        argv_array_push(&cmd.args, "--fsck-objects");
                else
-                       argv_array_push(&cmd.args, "--strict");
+                       argv_array_pushf(&cmd.args, "--strict%s",
+                                        fsck_msg_types.buf);
        }
 
        cmd.in = demux.out;
@@ -981,11 +916,13 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
        struct object_id oid;
        const char *agent_feature;
        int agent_len;
+       struct fetch_negotiator negotiator;
+       fetch_negotiator_init(&negotiator, negotiation_algorithm);
 
        sort_ref_list(&ref, ref_compare_name);
        QSORT(sought, nr_sought, cmp_ref_by_name);
 
-       if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
+       if ((args->depth > 0 || is_repository_shallow(the_repository)) && !server_supports("shallow"))
                die(_("Server does not support shallow clients"));
        if (args->depth > 0 || args->deepen_since || args->deepen_not)
                args->deepen = 1;
@@ -1053,11 +990,13 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
        if (!server_supports("deepen-relative") && args->deepen_relative)
                die(_("Server does not support --deepen"));
 
-       if (everything_local(args, &ref, sought, nr_sought)) {
+       mark_complete_and_common_ref(&negotiator, args, &ref);
+       filter_refs(args, &ref, sought, nr_sought);
+       if (everything_local(args, &ref)) {
                packet_flush(fd[1]);
                goto all_done;
        }
-       if (find_common(args, fd, &oid, ref) < 0)
+       if (find_common(&negotiator, args, fd, &oid, ref) < 0)
                if (!args->keep_pack)
                        /* When cloning, it is not unusual to have
                         * no common commit.
@@ -1077,13 +1016,14 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
                die(_("git fetch-pack: fetch failed."));
 
  all_done:
+       negotiator.release(&negotiator);
        return ref;
 }
 
 static void add_shallow_requests(struct strbuf *req_buf,
                                 const struct fetch_pack_args *args)
 {
-       if (is_repository_shallow())
+       if (is_repository_shallow(the_repository))
                write_shallow_commits(req_buf, 1, NULL);
        if (args->depth > 0)
                packet_buf_write(req_buf, "deepen %d", args->depth);
@@ -1102,9 +1042,10 @@ static void add_shallow_requests(struct strbuf *req_buf,
 
 static void add_wants(const struct ref *wants, struct strbuf *req_buf)
 {
+       int use_ref_in_want = server_supports_feature("fetch", "ref-in-want", 0);
+
        for ( ; wants ; wants = wants->next) {
                const struct object_id *remote = &wants->old_oid;
-               const char *remote_hex;
                struct object *o;
 
                /*
@@ -1117,13 +1058,15 @@ static void add_wants(const struct ref *wants, struct strbuf *req_buf)
                 * interested in the case we *know* the object is
                 * reachable and we have already scanned it.
                 */
-               if (((o = lookup_object(remote->hash)) != NULL) &&
+               if (((o = lookup_object(the_repository, remote->hash)) != NULL) &&
                    (o->flags & COMPLETE)) {
                        continue;
                }
 
-               remote_hex = oid_to_hex(remote);
-               packet_buf_write(req_buf, "want %s\n", remote_hex);
+               if (!use_ref_in_want || wants->exact_oid)
+                       packet_buf_write(req_buf, "want %s\n", oid_to_hex(remote));
+               else
+                       packet_buf_write(req_buf, "want-ref %s\n", wants->name);
        }
 }
 
@@ -1138,13 +1081,15 @@ static void add_common(struct strbuf *req_buf, struct oidset *common)
        }
 }
 
-static int add_haves(struct strbuf *req_buf, int *haves_to_send, int *in_vain)
+static int add_haves(struct fetch_negotiator *negotiator,
+                    struct strbuf *req_buf,
+                    int *haves_to_send, int *in_vain)
 {
        int ret = 0;
        int haves_added = 0;
        const struct object_id *oid;
 
-       while ((oid = get_rev())) {
+       while ((oid = negotiator->next(negotiator))) {
                packet_buf_write(req_buf, "have %s\n", oid_to_hex(oid));
                if (++haves_added >= *haves_to_send)
                        break;
@@ -1163,7 +1108,8 @@ static int add_haves(struct strbuf *req_buf, int *haves_to_send, int *in_vain)
        return ret;
 }
 
-static int send_fetch_request(int fd_out, const struct fetch_pack_args *args,
+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)
 {
@@ -1195,7 +1141,7 @@ static int send_fetch_request(int fd_out, const struct fetch_pack_args *args,
        /* Add shallow-info and deepen request */
        if (server_supports_feature("fetch", "shallow", 0))
                add_shallow_requests(&req_buf, args);
-       else if (is_repository_shallow() || args->deepen)
+       else if (is_repository_shallow(the_repository) || args->deepen)
                die(_("Server does not support shallow requests"));
 
        /* Add filter */
@@ -1219,7 +1165,7 @@ static int send_fetch_request(int fd_out, const struct fetch_pack_args *args,
                add_common(&req_buf, common);
 
                /* Add initial haves */
-               ret = add_haves(&req_buf, haves_to_send, in_vain);
+               ret = add_haves(negotiator, &req_buf, haves_to_send, in_vain);
        }
 
        /* Send request */
@@ -1242,13 +1188,13 @@ static int process_section_header(struct packet_reader *reader,
        int ret;
 
        if (packet_reader_peek(reader) != PACKET_READ_NORMAL)
-               die("error reading section header '%s'", section);
+               die(_("error reading section header '%s'"), section);
 
        ret = !strcmp(reader->line, section);
 
        if (!peek) {
                if (!ret)
-                       die("expected '%s', received '%s'",
+                       die(_("expected '%s', received '%s'"),
                            section, reader->line);
                packet_reader_read(reader);
        }
@@ -1256,7 +1202,9 @@ static int process_section_header(struct packet_reader *reader,
        return ret;
 }
 
-static int process_acks(struct packet_reader *reader, struct oidset *common)
+static int process_acks(struct fetch_negotiator *negotiator,
+                       struct packet_reader *reader,
+                       struct oidset *common)
 {
        /* received */
        int received_ready = 0;
@@ -1274,24 +1222,23 @@ static int process_acks(struct packet_reader *reader, struct oidset *common)
                        if (!get_oid_hex(arg, &oid)) {
                                struct commit *commit;
                                oidset_insert(common, &oid);
-                               commit = lookup_commit(&oid);
-                               mark_common(commit, 0, 1);
+                               commit = lookup_commit(the_repository, &oid);
+                               negotiator->ack(negotiator, commit);
                        }
                        continue;
                }
 
                if (!strcmp(reader->line, "ready")) {
-                       clear_prio_queue(&rev_list);
                        received_ready = 1;
                        continue;
                }
 
-               die("unexpected acknowledgment line: '%s'", reader->line);
+               die(_("unexpected acknowledgment line: '%s'"), reader->line);
        }
 
        if (reader->status != PACKET_READ_FLUSH &&
            reader->status != PACKET_READ_DELIM)
-               die("error processing acks: %d", reader->status);
+               die(_("error processing acks: %d"), reader->status);
 
        /* return 0 if no common, 1 if there are common, or 2 if ready */
        return received_ready ? 2 : (received_ack ? 1 : 0);
@@ -1308,16 +1255,16 @@ static void receive_shallow_info(struct fetch_pack_args *args,
                if (skip_prefix(reader->line, "shallow ", &arg)) {
                        if (get_oid_hex(arg, &oid))
                                die(_("invalid shallow line: %s"), reader->line);
-                       register_shallow(&oid);
+                       register_shallow(the_repository, &oid);
                        continue;
                }
                if (skip_prefix(reader->line, "unshallow ", &arg)) {
                        if (get_oid_hex(arg, &oid))
                                die(_("invalid unshallow line: %s"), reader->line);
-                       if (!lookup_object(oid.hash))
+                       if (!lookup_object(the_repository, oid.hash))
                                die(_("object not found: %s"), reader->line);
                        /* make sure that it is parsed as shallow */
-                       if (!parse_object(&oid))
+                       if (!parse_object(the_repository, &oid))
                                die(_("error in object: %s"), reader->line);
                        if (unregister_shallow(&oid))
                                die(_("no shallow found: %s"), reader->line);
@@ -1328,12 +1275,39 @@ static void receive_shallow_info(struct fetch_pack_args *args,
 
        if (reader->status != PACKET_READ_FLUSH &&
            reader->status != PACKET_READ_DELIM)
-               die("error processing shallow info: %d", reader->status);
+               die(_("error processing shallow info: %d"), reader->status);
 
        setup_alternate_shallow(&shallow_lock, &alternate_shallow_file, NULL);
        args->deepen = 1;
 }
 
+static void receive_wanted_refs(struct packet_reader *reader,
+                               struct ref **sought, int nr_sought)
+{
+       process_section_header(reader, "wanted-refs", 0);
+       while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
+               struct object_id oid;
+               const char *end;
+               int i;
+
+               if (parse_oid_hex(reader->line, &oid, &end) || *end++ != ' ')
+                       die(_("expected wanted-ref, got '%s'"), reader->line);
+
+               for (i = 0; i < nr_sought; i++) {
+                       if (!strcmp(end, sought[i]->name)) {
+                               oidcpy(&sought[i]->old_oid, &oid);
+                               break;
+                       }
+               }
+
+               if (i == nr_sought)
+                       die(_("unexpected wanted-ref: '%s'"), reader->line);
+       }
+
+       if (reader->status != PACKET_READ_DELIM)
+               die(_("error processing wanted refs: %d"), reader->status);
+}
+
 enum fetch_state {
        FETCH_CHECK_LOCAL = 0,
        FETCH_SEND_REQUEST,
@@ -1354,6 +1328,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
        struct packet_reader reader;
        int in_vain = 0;
        int haves_to_send = INITIAL_FLUSH;
+       struct fetch_negotiator negotiator;
+       fetch_negotiator_init(&negotiator, negotiation_algorithm);
        packet_reader_init(&reader, fd[0], NULL, 0,
                           PACKET_READ_CHOMP_NEWLINE);
 
@@ -1369,21 +1345,21 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
                        if (args->depth > 0 || args->deepen_since || args->deepen_not)
                                args->deepen = 1;
 
-                       if (marked)
-                               for_each_ref(clear_marks, NULL);
-                       marked = 1;
-
-                       for_each_ref(rev_list_insert_ref_oid, NULL);
-                       for_each_cached_alternate(insert_one_alternate_object);
-
                        /* Filter 'ref' by 'sought' and those that aren't local */
-                       if (everything_local(args, &ref, sought, nr_sought))
+                       mark_complete_and_common_ref(&negotiator, args, &ref);
+                       filter_refs(args, &ref, sought, nr_sought);
+                       if (everything_local(args, &ref))
                                state = FETCH_DONE;
                        else
                                state = FETCH_SEND_REQUEST;
+
+                       mark_tips(&negotiator, args->negotiation_tips);
+                       for_each_cached_alternate(&negotiator,
+                                                 insert_one_alternate_object);
                        break;
                case FETCH_SEND_REQUEST:
-                       if (send_fetch_request(fd[1], args, ref, &common,
+                       if (send_fetch_request(&negotiator, fd[1], args, ref,
+                                              &common,
                                               &haves_to_send, &in_vain))
                                state = FETCH_GET_PACK;
                        else
@@ -1391,7 +1367,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
                        break;
                case FETCH_PROCESS_ACKS:
                        /* Process ACKs/NAKs */
-                       switch (process_acks(&reader, &common)) {
+                       switch (process_acks(&negotiator, &reader, &common)) {
                        case 2:
                                state = FETCH_GET_PACK;
                                break;
@@ -1408,6 +1384,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
                        if (process_section_header(&reader, "shallow-info", 1))
                                receive_shallow_info(args, &reader);
 
+                       if (process_section_header(&reader, "wanted-refs", 1))
+                               receive_wanted_refs(&reader, sought, nr_sought);
+
                        /* get the pack */
                        process_section_header(&reader, "packfile", 0);
                        if (get_pack(args, fd, pack_lockfile))
@@ -1420,10 +1399,36 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
                }
        }
 
+       negotiator.release(&negotiator);
        oidset_clear(&common);
        return ref;
 }
 
+static int fetch_pack_config_cb(const char *var, const char *value, void *cb)
+{
+       if (strcmp(var, "fetch.fsck.skiplist") == 0) {
+               const char *path;
+
+               if (git_config_pathname(&path, var, value))
+                       return 1;
+               strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
+                       fsck_msg_types.len ? ',' : '=', path);
+               free((char *)path);
+               return 0;
+       }
+
+       if (skip_prefix(var, "fetch.fsck.", &var)) {
+               if (is_valid_msg_type(var, value))
+                       strbuf_addf(&fsck_msg_types, "%c%s=%s",
+                               fsck_msg_types.len ? ',' : '=', var, value);
+               else
+                       warning("Skipping unknown msg id '%s'", var);
+               return 0;
+       }
+
+       return git_default_config(var, value, cb);
+}
+
 static void fetch_pack_config(void)
 {
        git_config_get_int("fetch.unpacklimit", &fetch_unpack_limit);
@@ -1431,8 +1436,10 @@ static void fetch_pack_config(void)
        git_config_get_bool("repack.usedeltabaseoffset", &prefer_ofs_delta);
        git_config_get_bool("fetch.fsckobjects", &fetch_fsck_objects);
        git_config_get_bool("transfer.fsckobjects", &transfer_fsck_objects);
+       git_config_get_string("fetch.negotiationalgorithm",
+                             &negotiation_algorithm);
 
-       git_config(git_default_config, NULL);
+       git_config(fetch_pack_config_cb, NULL);
 }
 
 static void fetch_pack_setup(void)
@@ -1479,7 +1486,7 @@ static void update_shallow(struct fetch_pack_args *args,
 
        if (args->deepen && alternate_shallow_file) {
                if (*alternate_shallow_file == '\0') { /* --unshallow */
-                       unlink_or_warn(git_path_shallow());
+                       unlink_or_warn(git_path_shallow(the_repository));
                        rollback_lock_file(&shallow_lock);
                } else
                        commit_lock_file(&shallow_lock);
@@ -1563,6 +1570,18 @@ static void update_shallow(struct fetch_pack_args *args,
        oid_array_clear(&ref);
 }
 
+static int iterate_ref_map(void *cb_data, struct object_id *oid)
+{
+       struct ref **rm = cb_data;
+       struct ref *ref = *rm;
+
+       if (!ref)
+               return -1; /* end of the list */
+       *rm = ref->next;
+       oidcpy(oid, &ref->old_oid);
+       return 0;
+}
+
 struct ref *fetch_pack(struct fetch_pack_args *args,
                       int fd[], struct child_process *conn,
                       const struct ref *ref,
@@ -1591,7 +1610,25 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
                ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,
                                        &si, pack_lockfile);
        reprepare_packed_git(the_repository);
+
+       if (!args->cloning && args->deepen) {
+               struct check_connected_options opt = CHECK_CONNECTED_INIT;
+               struct ref *iterator = ref_cpy;
+               opt.shallow_file = alternate_shallow_file;
+               if (args->deepen)
+                       opt.is_deepening_fetch = 1;
+               if (check_connected(iterate_ref_map, &iterator, &opt)) {
+                       error(_("remote did not send all necessary objects"));
+                       free_refs(ref_cpy);
+                       ref_cpy = NULL;
+                       rollback_lock_file(&shallow_lock);
+                       goto cleanup;
+               }
+               args->connectivity_checked = 1;
+       }
+
        update_shallow(args, sought, nr_sought, &si);
+cleanup:
        clear_shallow_info(&si);
        return ref_cpy;
 }
index bb45a366a82a4a7dae2524e0845ac33128076c57..5b6e868802b53ca5fa59eb864199274ac538c242 100644 (file)
@@ -16,6 +16,13 @@ struct fetch_pack_args {
        const struct string_list *deepen_not;
        struct list_objects_filter_options filter_options;
        const struct string_list *server_options;
+
+       /*
+        * If not NULL, during packfile negotiation, fetch-pack will send "have"
+        * lines only with these tips and their ancestors.
+        */
+       const struct oid_array *negotiation_tips;
+
        unsigned deepen_relative:1;
        unsigned quiet:1;
        unsigned keep_pack:1;
@@ -41,6 +48,21 @@ struct fetch_pack_args {
         * regardless of which object flags it uses (if any).
         */
        unsigned no_dependents:1;
+
+       /*
+        * Because fetch_pack() overwrites the shallow file upon a
+        * successful deepening non-clone fetch, if this struct
+        * specifies such a fetch, fetch_pack() needs to perform a
+        * connectivity check before deciding if a fetch is successful
+        * (and overwriting the shallow file). fetch_pack() sets this
+        * field to 1 if such a connectivity check was performed.
+        *
+        * This is different from check_self_contained_and_connected
+        * in that the former allows existing objects in the
+        * repository to satisfy connectivity needs, whereas the
+        * latter doesn't.
+        */
+       unsigned connectivity_checked:1;
 };
 
 /*
diff --git a/fsck.c b/fsck.c
index 0b8b20b6c464cdfbbb8afd9685f45e3e2e67adfa..a0cee0be590020e4ff4b42da86c322ba4d0010ae 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -1,4 +1,6 @@
 #include "cache.h"
+#include "object-store.h"
+#include "repository.h"
 #include "object.h"
 #include "blob.h"
 #include "tree.h"
@@ -62,7 +64,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;
        FUNC(ZERO_PADDED_DATE, ERROR) \
        FUNC(GITMODULES_MISSING, ERROR) \
        FUNC(GITMODULES_BLOB, ERROR) \
-       FUNC(GITMODULES_PARSE, ERROR) \
+       FUNC(GITMODULES_LARGE, ERROR) \
        FUNC(GITMODULES_NAME, ERROR) \
        FUNC(GITMODULES_SYMLINK, ERROR) \
        /* warnings */ \
@@ -76,6 +78,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;
        FUNC(ZERO_PADDED_FILEMODE, WARN) \
        FUNC(NUL_IN_COMMIT, WARN) \
        /* infos (reported as warnings, but ignored by default) */ \
+       FUNC(GITMODULES_PARSE, INFO) \
        FUNC(BAD_TAG_NAME, INFO) \
        FUNC(MISSING_TAGGER_ENTRY, INFO)
 
@@ -315,6 +318,13 @@ static void append_msg_id(struct strbuf *sb, const char *msg_id)
        strbuf_addstr(sb, ": ");
 }
 
+static int object_on_skiplist(struct fsck_options *opts, struct object *obj)
+{
+       if (opts && opts->skiplist && obj)
+               return oid_array_lookup(opts->skiplist, &obj->oid) >= 0;
+       return 0;
+}
+
 __attribute__((format (printf, 4, 5)))
 static int report(struct fsck_options *options, struct object *object,
        enum fsck_msg_id id, const char *fmt, ...)
@@ -326,8 +336,7 @@ static int report(struct fsck_options *options, struct object *object,
        if (msg_type == FSCK_IGNORE)
                return 0;
 
-       if (options->skiplist && object &&
-                       oid_array_lookup(options->skiplist, &object->oid) >= 0)
+       if (object_on_skiplist(options, object))
                return 0;
 
        if (msg_type == FSCK_FATAL)
@@ -405,14 +414,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(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(entry.oid);
+                       obj = (struct object *)lookup_blob(the_repository, entry.oid);
                        if (name && obj)
                                put_object_name(options, obj, "%s%s", name,
                                        entry.path);
@@ -510,7 +519,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
                return -1;
 
        if (obj->type == OBJ_NONE)
-               parse_object(&obj->oid);
+               parse_object(the_repository, &obj->oid);
 
        switch (obj->type) {
        case OBJ_BLOB:
@@ -795,7 +804,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
                buffer = p + 1;
                parent_line_count++;
        }
-       graft = lookup_commit_graft(&commit->object.oid);
+       graft = lookup_commit_graft(the_repository, &commit->object.oid);
        parent_count = commit_list_count(commit->parents);
        if (graft) {
                if (graft->nr_parent == -1 && !parent_count)
@@ -992,11 +1001,15 @@ static int fsck_blob(struct blob *blob, const char *buf,
                     unsigned long size, struct fsck_options *options)
 {
        struct fsck_gitmodules_data data;
+       struct config_options config_opts = { 0 };
 
        if (!oidset_contains(&gitmodules_found, &blob->object.oid))
                return 0;
        oidset_insert(&gitmodules_done, &blob->object.oid);
 
+       if (object_on_skiplist(options, &blob->object))
+               return 0;
+
        if (!buf) {
                /*
                 * A missing buffer here is a sign that the caller found the
@@ -1004,15 +1017,16 @@ static int fsck_blob(struct blob *blob, const char *buf,
                 * that an error.
                 */
                return report(options, &blob->object,
-                             FSCK_MSG_GITMODULES_PARSE,
+                             FSCK_MSG_GITMODULES_LARGE,
                              ".gitmodules too large to parse");
        }
 
        data.obj = &blob->object;
        data.options = options;
        data.ret = 0;
+       config_opts.error_action = CONFIG_ERROR_SILENT;
        if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB,
-                               ".gitmodules", buf, size, &data))
+                               ".gitmodules", buf, size, &data, &config_opts))
                data.ret |= report(options, &blob->object,
                                   FSCK_MSG_GITMODULES_PARSE,
                                   "could not parse gitmodules blob");
@@ -1068,7 +1082,7 @@ int fsck_finish(struct fsck_options *options)
                if (oidset_contains(&gitmodules_done, oid))
                        continue;
 
-               blob = lookup_blob(oid);
+               blob = lookup_blob(the_repository, oid);
                if (!blob) {
                        struct object *obj = lookup_unknown_object(oid->hash);
                        ret |= report(options, obj,
index 9a64998b24b1de277772f1ac97a989aae3133898..5f2e90932f9990419d75d803d9552acf2f14adef 100644 (file)
 #endif
 #ifdef NO_INTPTR_T
 /*
- * On I16LP32, ILP32 and LP64 "long" is the save bet, however
+ * On I16LP32, ILP32 and LP64 "long" is the safe bet, however
  * on LLP86, IL33LLP64 and P64 it needs to be "long long",
  * while on IP16 and IP16L32 it is "int" (resp. "short")
  * Size needs to match (or exceed) 'sizeof(void *)'.
@@ -1239,4 +1239,10 @@ extern void unleak_memory(const void *ptr, size_t len);
 #define UNLEAK(var) do {} while (0)
 #endif
 
+/*
+ * This include must come after system headers, since it introduces macros that
+ * replace system names.
+ */
+#include "banned.h"
+
 #endif
index ccceaf19a74373bb23b2a2b1aa71b7f0bb909d54..5c5afa2b985e2e524601518bbb8fb8d3c8efda61 100755 (executable)
@@ -372,6 +372,7 @@ while read commit parents; do
        git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
 
        report_progress
+       test -f "$workdir"/../map/$commit && continue
 
        case "$filter_subdir" in
        "")
index 47e38f34c3a871349630660e6e3387d554c29d36..eec264e6303684c5886804361c630e1572c1fe09 100755 (executable)
@@ -326,13 +326,17 @@ EOF
 }
 
 apache2_conf () {
-       if test -z "$module_path"
-       then
-               test -d "/usr/lib/httpd/modules" &&
-                       module_path="/usr/lib/httpd/modules"
-               test -d "/usr/lib/apache2/modules" &&
-                       module_path="/usr/lib/apache2/modules"
-       fi
+       for candidate in \
+               /etc/httpd \
+               /usr/lib/apache2 \
+               /usr/lib/httpd ;
+       do
+               if test -d "$candidate/modules"
+               then
+                       module_path="$candidate/modules"
+                       break
+               fi
+       done
        bind=
        test x"$local" = xtrue && bind='127.0.0.1:'
        echo 'text/css css' > "$fqgitdir/mime.types"
@@ -356,7 +360,7 @@ EOF
                        break
                fi
        done
-       for mod in mime dir env log_config authz_core
+       for mod in mime dir env log_config authz_core unixd
        do
                if test -e $module_path/mod_${mod}.so
                then
index c062e3de3a503bd01203f2a6aef63eea63cae5c5..d07c7f387cf478bbd93d1dada1afa1de80db0fbf 100755 (executable)
@@ -491,14 +491,16 @@ main () {
        printf "%s\n" "$files"
 
        rc=0
-       for i in $files
+       set -- $files
+       while test $# -ne 0
        do
                printf "\n"
-               if ! merge_file "$i"
+               if ! merge_file "$1"
                then
                        rc=1
-                       prompt_after_failed_merge || exit 1
+                       test $# -ne 1 && prompt_after_failed_merge || exit 1
                fi
+               shift
        done
 
        exit $rc
index 0354d4df5cadd5145245d755a8868608b849719f..7fab255584e5bca70aef305f6ead73330694a88b 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
 import ctypes
 import errno
 
+# support basestring in python3
+try:
+    unicode = unicode
+except NameError:
+    # 'unicode' is undefined, must be Python 3
+    str = str
+    unicode = str
+    bytes = bytes
+    basestring = (str,bytes)
+else:
+    # 'unicode' exists, must be Python 2
+    str = str
+    unicode = unicode
+    bytes = str
+    basestring = basestring
+
 try:
     from subprocess import CalledProcessError
 except ImportError:
@@ -767,7 +783,7 @@ def gitDeleteRef(ref):
 _gitConfig = {}
 
 def gitConfig(key, typeSpecifier=None):
-    if not _gitConfig.has_key(key):
+    if key not in _gitConfig:
         cmd = [ "git", "config" ]
         if typeSpecifier:
             cmd += [ typeSpecifier ]
@@ -781,12 +797,12 @@ def gitConfigBool(key):
        variable is set to true, and False if set to false or not present
        in the config."""
 
-    if not _gitConfig.has_key(key):
+    if key not in _gitConfig:
         _gitConfig[key] = gitConfig(key, '--bool') == "true"
     return _gitConfig[key]
 
 def gitConfigInt(key):
-    if not _gitConfig.has_key(key):
+    if key not in _gitConfig:
         cmd = [ "git", "config", "--int", key ]
         s = read_pipe(cmd, ignore_error=True)
         v = s.strip()
@@ -797,7 +813,7 @@ def gitConfigInt(key):
     return _gitConfig[key]
 
 def gitConfigList(key):
-    if not _gitConfig.has_key(key):
+    if key not in _gitConfig:
         s = read_pipe(["git", "config", "--get-all", key], ignore_error=True)
         _gitConfig[key] = s.strip().splitlines()
         if _gitConfig[key] == ['']:
@@ -855,7 +871,7 @@ def findUpstreamBranchPoint(head = "HEAD"):
         tip = branches[branch]
         log = extractLogMessageFromGitCommit(tip)
         settings = extractSettingsGitLog(log)
-        if settings.has_key("depot-paths"):
+        if "depot-paths" in settings:
             paths = ",".join(settings["depot-paths"])
             branchByDepotPath[paths] = "remotes/p4/" + branch
 
@@ -865,9 +881,9 @@ def findUpstreamBranchPoint(head = "HEAD"):
         commit = head + "~%s" % parent
         log = extractLogMessageFromGitCommit(commit)
         settings = extractSettingsGitLog(log)
-        if settings.has_key("depot-paths"):
+        if "depot-paths" in settings:
             paths = ",".join(settings["depot-paths"])
-            if branchByDepotPath.has_key(paths):
+            if paths in branchByDepotPath:
                 return [branchByDepotPath[paths], settings]
 
         parent = parent + 1
@@ -876,7 +892,7 @@ def findUpstreamBranchPoint(head = "HEAD"):
 
 def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent=True):
     if not silent:
-        print ("Creating/updating branch(es) in %s based on origin branch(es)"
+        print("Creating/updating branch(es) in %s based on origin branch(es)"
                % localRefPrefix)
 
     originPrefix = "origin/p4/"
@@ -891,29 +907,29 @@ def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent
         originHead = line
 
         original = extractSettingsGitLog(extractLogMessageFromGitCommit(originHead))
-        if (not original.has_key('depot-paths')
-            or not original.has_key('change')):
+        if ('depot-paths' not in original
+            or 'change' not in original):
             continue
 
         update = False
         if not gitBranchExists(remoteHead):
             if verbose:
-                print "creating %s" % remoteHead
+                print("creating %s" % remoteHead)
             update = True
         else:
             settings = extractSettingsGitLog(extractLogMessageFromGitCommit(remoteHead))
-            if settings.has_key('change') > 0:
+            if 'change' in settings:
                 if settings['depot-paths'] == original['depot-paths']:
                     originP4Change = int(original['change'])
                     p4Change = int(settings['change'])
                     if originP4Change > p4Change:
-                        print ("%s (%s) is newer than %s (%s). "
+                        print("%s (%s) is newer than %s (%s). "
                                "Updating p4 branch from origin."
                                % (originHead, originP4Change,
                                   remoteHead, p4Change))
                         update = True
                 else:
-                    print ("Ignoring: %s was imported from %s while "
+                    print("Ignoring: %s was imported from %s while "
                            "%s was imported from %s"
                            % (originHead, ','.join(original['depot-paths']),
                               remoteHead, ','.join(settings['depot-paths'])))
@@ -1002,7 +1018,7 @@ def p4ChangesForPaths(depotPaths, changeRange, requestedBlockSize):
 
         # Insert changes in chronological order
         for entry in reversed(result):
-            if not entry.has_key('change'):
+            if 'change' not in entry:
                 continue
             changes.add(int(entry['change']))
 
@@ -1312,7 +1328,7 @@ def p4UserId(self):
 
         results = p4CmdList("user -o")
         for r in results:
-            if r.has_key('User'):
+            if 'User' in r:
                 self.myP4UserId = r['User']
                 return r['User']
         die("Could not find your p4 user id")
@@ -1336,7 +1352,7 @@ def getUserMapFromPerforceServer(self):
         self.emails = {}
 
         for output in p4CmdList("users"):
-            if not output.has_key("User"):
+            if "User" not in output:
                 continue
             self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
             self.emails[output["Email"]] = output["User"]
@@ -1381,9 +1397,9 @@ def __init__(self):
     def run(self, args):
         j = 0
         for output in p4CmdList(args):
-            print 'Element: %d' % j
+            print('Element: %d' % j)
             j += 1
-            print output
+            print(output)
         return True
 
 class P4RollBack(Command):
@@ -1424,14 +1440,14 @@ def run(self, args):
 
                 if len(p4Cmd("changes -m 1 "  + ' '.join (['%s...@%s' % (p, maxChange)
                                                            for p in depotPaths]))) == 0:
-                    print "Branch %s did not exist at change %s, deleting." % (ref, maxChange)
+                    print("Branch %s did not exist at change %s, deleting." % (ref, maxChange))
                     system("git update-ref -d %s `git rev-parse %s`" % (ref, ref))
                     continue
 
                 while change and int(change) > maxChange:
                     changed = True
                     if self.verbose:
-                        print "%s is at %s ; rewinding towards %s" % (ref, change, maxChange)
+                        print("%s is at %s ; rewinding towards %s" % (ref, change, maxChange))
                     system("git update-ref %s \"%s^\"" % (ref, ref))
                     log = extractLogMessageFromGitCommit(ref)
                     settings =  extractSettingsGitLog(log)
@@ -1441,7 +1457,7 @@ def run(self, args):
                     change = settings['change']
 
                 if changed:
-                    print "%s rewound to %s" % (ref, change)
+                    print("%s rewound to %s" % (ref, change))
 
         return True
 
@@ -1478,7 +1494,13 @@ def __init__(self):
                 optparse.make_option("--disable-p4sync", dest="disable_p4sync", action="store_true",
                                      help="Skip Perforce sync of p4/master after submit or shelve"),
         ]
-        self.description = "Submit changes from git to the perforce depot."
+        self.description = """Submit changes from git to the perforce depot.\n
+    The `p4-pre-submit` hook is executed if it exists and is executable.
+    The hook takes no parameters and nothing from standard input. Exiting with
+    non-zero status from this script prevents `git-p4 submit` from launching.
+
+    One usage scenario is to run unit tests in the hook."""
+
         self.usage += " [name of git branch to submit into perforce depot]"
         self.origin = ""
         self.detectRenames = False
@@ -1577,10 +1599,10 @@ def patchRCSKeywords(self, file, pattern):
         except:
             # cleanup our temporary file
             os.unlink(outFileName)
-            print "Failed to strip RCS keywords in %s" % file
+            print("Failed to strip RCS keywords in %s" % file)
             raise
 
-        print "Patched up RCS keywords in %s" % file
+        print("Patched up RCS keywords in %s" % file)
 
     def p4UserForCommit(self,id):
         # Return the tuple (perforce user,git email) for a given git commit id
@@ -1588,7 +1610,7 @@ def p4UserForCommit(self,id):
         gitEmail = read_pipe(["git", "log", "--max-count=1",
                               "--format=%ae", id])
         gitEmail = gitEmail.strip()
-        if not self.emails.has_key(gitEmail):
+        if gitEmail not in self.emails:
             return (None,gitEmail)
         else:
             return (self.emails[gitEmail],gitEmail)
@@ -1600,7 +1622,7 @@ def checkValidP4Users(self,commits):
             if not user:
                 msg = "Cannot find p4 user for email %s in commit %s." % (email, id)
                 if gitConfigBool("git-p4.allowMissingP4Users"):
-                    print "%s" % msg
+                    print("%s" % msg)
                 else:
                     die("Error: %s\nSet git-p4.allowMissingP4Users to true to allow this." % msg)
 
@@ -1612,14 +1634,14 @@ def lastP4Changelist(self):
         results = p4CmdList("client -o")        # find the current client
         client = None
         for r in results:
-            if r.has_key('Client'):
+            if 'Client' in r:
                 client = r['Client']
                 break
         if not client:
             die("could not get client spec")
         results = p4CmdList(["changes", "-c", client, "-m", "1"])
         for r in results:
-            if r.has_key('change'):
+            if 'change' in r:
                 return r['change']
         die("Could not get changelist number for last submit - cannot patch up user details")
 
@@ -1637,10 +1659,10 @@ def modifyChangelistUser(self, changelist, newUser):
 
         result = p4CmdList("change -f -i", stdin=input)
         for r in result:
-            if r.has_key('code'):
+            if 'code' in r:
                 if r['code'] == 'error':
                     die("Could not modify user field of changelist %s to %s:%s" % (changelist, newUser, r['data']))
-            if r.has_key('data'):
+            if 'data' in r:
                 print("Updated user field for changelist %s to %s" % (changelist, newUser))
                 return
         die("Could not modify user field of changelist %s to %s" % (changelist, newUser))
@@ -1650,7 +1672,7 @@ def canChangeChangelists(self):
         # which are required to modify changelists.
         results = p4CmdList(["protects", self.depotPath])
         for r in results:
-            if r.has_key('perm'):
+            if 'perm' in r:
                 if r['perm'] == 'admin':
                     return 1
                 if r['perm'] == 'super':
@@ -1690,7 +1712,7 @@ def prepareSubmitTemplate(self, changelist=None):
         if changelist:
             args.append(str(changelist))
         for entry in p4CmdList(args):
-            if not entry.has_key('code'):
+            if 'code' not in entry:
                 continue
             if entry['code'] == 'stat':
                 change_entry = entry
@@ -1699,7 +1721,7 @@ def prepareSubmitTemplate(self, changelist=None):
             die('Failed to decode output of p4 change -o')
         for key, value in change_entry.iteritems():
             if key.startswith('File'):
-                if settings.has_key('depot-paths'):
+                if 'depot-paths' in settings:
                     if not [p for p in settings['depot-paths']
                             if p4PathStartsWith(value, p)]:
                         continue
@@ -1710,7 +1732,7 @@ def prepareSubmitTemplate(self, changelist=None):
                 continue
         # Output in the order expected by prepareLogMessage
         for key in ['Change', 'Client', 'User', 'Status', 'Description', 'Jobs']:
-            if not change_entry.has_key(key):
+            if key not in change_entry:
                 continue
             template += '\n'
             template += key + ':'
@@ -1738,7 +1760,7 @@ def edit_template(self, template_file):
         mtime = os.stat(template_file).st_mtime
 
         # invoke the editor
-        if os.environ.has_key("P4EDITOR") and (os.environ.get("P4EDITOR") != ""):
+        if "P4EDITOR" in os.environ and (os.environ.get("P4EDITOR") != ""):
             editor = os.environ.get("P4EDITOR")
         else:
             editor = read_pipe("git var GIT_EDITOR").strip()
@@ -1762,7 +1784,7 @@ def edit_template(self, template_file):
 
     def get_diff_description(self, editedFiles, filesToAdd, symlinks):
         # diff
-        if os.environ.has_key("P4DIFF"):
+        if "P4DIFF" in os.environ:
             del(os.environ["P4DIFF"])
         diff = ""
         for editedFile in editedFiles:
@@ -1792,8 +1814,8 @@ def get_diff_description(self, editedFiles, filesToAdd, symlinks):
     def applyCommit(self, id):
         """Apply one commit, return True if it succeeded."""
 
-        print "Applying", read_pipe(["git", "show", "-s",
-                                     "--format=format:%h %s", id])
+        print("Applying", read_pipe(["git", "show", "-s",
+                                     "--format=format:%h %s", id]))
 
         (p4User, gitEmail) = self.p4UserForCommit(id)
 
@@ -1825,7 +1847,7 @@ def applyCommit(self, id):
                     filesToDelete.remove(path)
 
                 dst_mode = int(diff['dst_mode'], 8)
-                if dst_mode == 0120000:
+                if dst_mode == 0o120000:
                     symlinks.add(path)
 
             elif modifier == "D":
@@ -1883,7 +1905,7 @@ def applyCommit(self, id):
         if os.system(tryPatchCmd) != 0:
             fixed_rcs_keywords = False
             patch_succeeded = False
-            print "Unfortunately applying the change failed!"
+            print("Unfortunately applying the change failed!")
 
             # Patch failed, maybe it's just RCS keyword woes. Look through
             # the patch to see if that's possible.
@@ -1901,13 +1923,13 @@ def applyCommit(self, id):
                         for line in read_pipe_lines(["git", "diff", "%s^..%s" % (id, id), file]):
                             if regexp.search(line):
                                 if verbose:
-                                    print "got keyword match on %s in %s in %s" % (pattern, line, file)
+                                    print("got keyword match on %s in %s in %s" % (pattern, line, file))
                                 kwfiles[file] = pattern
                                 break
 
                 for file in kwfiles:
                     if verbose:
-                        print "zapping %s with %s" % (line,pattern)
+                        print("zapping %s with %s" % (line,pattern))
                     # File is being deleted, so not open in p4.  Must
                     # disable the read-only bit on windows.
                     if self.isWindows and file not in editedFiles:
@@ -1916,7 +1938,7 @@ def applyCommit(self, id):
                     fixed_rcs_keywords = True
 
             if fixed_rcs_keywords:
-                print "Retrying the patch with RCS keywords cleaned up"
+                print("Retrying the patch with RCS keywords cleaned up")
                 if os.system(tryPatchCmd) == 0:
                     patch_succeeded = True
 
@@ -1984,34 +2006,34 @@ def applyCommit(self, id):
             # Leave the p4 tree prepared, and the submit template around
             # and let the user decide what to do next
             #
-            print
-            print "P4 workspace prepared for submission."
-            print "To submit or revert, go to client workspace"
-            print "  " + self.clientPath
-            print
-            print "To submit, use \"p4 submit\" to write a new description,"
-            print "or \"p4 submit -i <%s\" to use the one prepared by" \
-                  " \"git p4\"." % fileName
-            print "You can delete the file \"%s\" when finished." % fileName
+            print()
+            print("P4 workspace prepared for submission.")
+            print("To submit or revert, go to client workspace")
+            print("  " + self.clientPath)
+            print()
+            print("To submit, use \"p4 submit\" to write a new description,")
+            print("or \"p4 submit -i <%s\" to use the one prepared by" \
+                  " \"git p4\"." % fileName)
+            print("You can delete the file \"%s\" when finished." % fileName)
 
             if self.preserveUser and p4User and not self.p4UserIsMe(p4User):
-                print "To preserve change ownership by user %s, you must\n" \
+                print("To preserve change ownership by user %s, you must\n" \
                       "do \"p4 change -f <change>\" after submitting and\n" \
-                      "edit the User field."
+                      "edit the User field.")
             if pureRenameCopy:
-                print "After submitting, renamed files must be re-synced."
-                print "Invoke \"p4 sync -f\" on each of these files:"
+                print("After submitting, renamed files must be re-synced.")
+                print("Invoke \"p4 sync -f\" on each of these files:")
                 for f in pureRenameCopy:
-                    print "  " + f
+                    print("  " + f)
 
-            print
-            print "To revert the changes, use \"p4 revert ...\", and delete"
-            print "the submit template file \"%s\"" % fileName
+            print()
+            print("To revert the changes, use \"p4 revert ...\", and delete")
+            print("the submit template file \"%s\"" % fileName)
             if filesToAdd:
-                print "Since the commit adds new files, they must be deleted:"
+                print("Since the commit adds new files, they must be deleted:")
                 for f in filesToAdd:
-                    print "  " + f
-            print
+                    print("  " + f)
+            print()
             return True
 
         #
@@ -2078,17 +2100,17 @@ def exportGitTags(self, gitTags):
 
             if not m.match(name):
                 if verbose:
-                    print "tag %s does not match regexp %s" % (name, validLabelRegexp)
+                    print("tag %s does not match regexp %s" % (name, validLabelRegexp))
                 continue
 
             # Get the p4 commit this corresponds to
             logMessage = extractLogMessageFromGitCommit(name)
             values = extractSettingsGitLog(logMessage)
 
-            if not values.has_key('change'):
+            if 'change' not in values:
                 # a tag pointing to something not sent to p4; ignore
                 if verbose:
-                    print "git tag %s does not give a p4 commit" % name
+                    print("git tag %s does not give a p4 commit" % name)
                 continue
             else:
                 changelist = values['change']
@@ -2123,10 +2145,10 @@ def exportGitTags(self, gitTags):
                 labelTemplate += "\t%s\n" % depot_side
 
             if self.dry_run:
-                print "Would create p4 label %s for tag" % name
+                print("Would create p4 label %s for tag" % name)
             elif self.prepare_p4_only:
-                print "Not creating p4 label %s for tag due to option" \
-                      " --prepare-p4-only" % name
+                print("Not creating p4 label %s for tag due to option" \
+                      " --prepare-p4-only" % name)
             else:
                 p4_write_pipe(["label", "-i"], labelTemplate)
 
@@ -2135,7 +2157,7 @@ def exportGitTags(self, gitTags):
                           ["%s@%s" % (depot_side, changelist) for depot_side in clientSpec.mappings])
 
                 if verbose:
-                    print "created p4 label for tag %s" % name
+                    print("created p4 label for tag %s" % name)
 
     def run(self, args):
         if len(args) == 0:
@@ -2179,10 +2201,10 @@ def run(self, args):
             self.conflict_behavior = val
 
         if self.verbose:
-            print "Origin branch is " + self.origin
+            print("Origin branch is " + self.origin)
 
         if len(self.depotPath) == 0:
-            print "Internal error: cannot locate perforce depot path from existing branches"
+            print("Internal error: cannot locate perforce depot path from existing branches")
             sys.exit(128)
 
         self.useClientSpec = False
@@ -2203,7 +2225,7 @@ def run(self, args):
         if self.clientPath == "":
             die("Error: Cannot locate perforce checkout of %s in client view" % self.depotPath)
 
-        print "Perforce checkout for depot path %s located at %s" % (self.depotPath, self.clientPath)
+        print("Perforce checkout for depot path %s located at %s" % (self.depotPath, self.clientPath))
         self.oldWorkingDirectory = os.getcwd()
 
         # ensure the clientPath exists
@@ -2214,9 +2236,9 @@ def run(self, args):
 
         chdir(self.clientPath, is_client_path=True)
         if self.dry_run:
-            print "Would synchronize p4 checkout in %s" % self.clientPath
+            print("Would synchronize p4 checkout in %s" % self.clientPath)
         else:
-            print "Synchronizing p4 checkout..."
+            print("Synchronizing p4 checkout...")
             if new_client_dir:
                 # old one was destroyed, and maybe nobody told p4
                 p4_sync("...", "-f")
@@ -2287,18 +2309,26 @@ def run(self, args):
             sys.exit("number of commits (%d) must match number of shelved changelist (%d)" %
                      (len(commits), num_shelves))
 
+        hooks_path = gitConfig("core.hooksPath")
+        if len(hooks_path) <= 0:
+            hooks_path = os.path.join(os.environ.get("GIT_DIR", ".git"), "hooks")
+
+        hook_file = os.path.join(hooks_path, "p4-pre-submit")
+        if os.path.isfile(hook_file) and os.access(hook_file, os.X_OK) and subprocess.call([hook_file]) != 0:
+            sys.exit(1)
+
         #
         # Apply the commits, one at a time.  On failure, ask if should
         # continue to try the rest of the patches, or quit.
         #
         if self.dry_run:
-            print "Would apply"
+            print("Would apply")
         applied = []
         last = len(commits) - 1
         for i, commit in enumerate(commits):
             if self.dry_run:
-                print " ", read_pipe(["git", "show", "-s",
-                                      "--format=format:%h %s", commit])
+                print(" ", read_pipe(["git", "show", "-s",
+                                      "--format=format:%h %s", commit]))
                 ok = True
             else:
                 ok = self.applyCommit(commit)
@@ -2306,15 +2336,15 @@ def run(self, args):
                 applied.append(commit)
             else:
                 if self.prepare_p4_only and i < last:
-                    print "Processing only the first commit due to option" \
-                          " --prepare-p4-only"
+                    print("Processing only the first commit due to option" \
+                          " --prepare-p4-only")
                     break
                 if i < last:
                     quit = False
                     while True:
                         # prompt for what to do, or use the option/variable
                         if self.conflict_behavior == "ask":
-                            print "What do you want to do?"
+                            print("What do you want to do?")
                             response = raw_input("[s]kip this commit but apply"
                                                  " the rest, or [q]uit? ")
                             if not response:
@@ -2328,10 +2358,10 @@ def run(self, args):
                                 self.conflict_behavior)
 
                         if response[0] == "s":
-                            print "Skipping this commit, but applying the rest"
+                            print("Skipping this commit, but applying the rest")
                             break
                         if response[0] == "q":
-                            print "Quitting"
+                            print("Quitting")
                             quit = True
                             break
                     if quit:
@@ -2344,7 +2374,7 @@ def run(self, args):
         elif self.prepare_p4_only:
             pass
         elif len(commits) == len(applied):
-            print ("All commits {0}!".format(shelved_applied))
+            print("All commits {0}!".format(shelved_applied))
 
             sync = P4Sync()
             if self.branch:
@@ -2360,17 +2390,17 @@ def run(self, args):
 
         else:
             if len(applied) == 0:
-                print ("No commits {0}.".format(shelved_applied))
+                print("No commits {0}.".format(shelved_applied))
             else:
-                print ("{0} only the commits marked with '*':".format(shelved_applied.capitalize()))
+                print("{0} only the commits marked with '*':".format(shelved_applied.capitalize()))
                 for c in commits:
                     if c in applied:
                         star = "*"
                     else:
                         star = " "
-                    print star, read_pipe(["git", "show", "-s",
-                                           "--format=format:%h %s",  c])
-                print "You will have to do 'git p4 sync' and rebase."
+                    print(star, read_pipe(["git", "show", "-s",
+                                           "--format=format:%h %s",  c]))
+                print("You will have to do 'git p4 sync' and rebase.")
 
         if gitConfigBool("git-p4.exportLabels"):
             self.exportLabels = True
@@ -2580,7 +2610,7 @@ def checkpoint(self):
         self.gitStream.write("progress checkpoint\n\n")
         out = self.gitOutput.readline()
         if self.verbose:
-            print "checkpoint finished: " + out
+            print("checkpoint finished: " + out)
 
     def cmp_shelved(self, path, filerev, revision):
         """ Determine if a path at revision #filerev is the same as the file
@@ -2600,7 +2630,7 @@ def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0, origin_r
                              for path in self.cloneExclude]
         files = []
         fnum = 0
-        while commit.has_key("depotFile%s" % fnum):
+        while "depotFile%s" % fnum in commit:
             path =  commit["depotFile%s" % fnum]
 
             if [p for p in self.cloneExclude
@@ -2638,7 +2668,7 @@ def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0, origin_r
     def extractJobsFromCommit(self, commit):
         jobs = []
         jnum = 0
-        while commit.has_key("job%s" % jnum):
+        while "job%s" % jnum in commit:
             job = commit["job%s" % jnum]
             jobs.append(job)
             jnum = jnum + 1
@@ -2686,7 +2716,7 @@ def splitFilesIntoBranches(self, commit):
 
         branches = {}
         fnum = 0
-        while commit.has_key("depotFile%s" % fnum):
+        while "depotFile%s" % fnum in commit:
             path =  commit["depotFile%s" % fnum]
             found = [p for p in self.depotPaths
                      if p4PathStartsWith(path, p)]
@@ -2735,7 +2765,7 @@ def encodeWithUTF8(self, path):
                 encoding = gitConfig('git-p4.pathEncoding')
             path = path.decode(encoding, 'replace').encode('utf8', 'replace')
             if self.verbose:
-                print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, path)
+                print('Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, path))
         return path
 
     # output one file from the P4 stream
@@ -2764,7 +2794,7 @@ def streamOneP4File(self, file, contents):
                 # to nothing.  This causes p4 errors when checking out such
                 # a change, and errors here too.  Work around it by ignoring
                 # the bad symlink; hopefully a future change fixes it.
-                print "\nIgnoring empty symlink in %s" % file['depotFile']
+                print("\nIgnoring empty symlink in %s" % file['depotFile'])
                 return
             elif data[-1] == '\n':
                 contents = [data[:-1]]
@@ -2804,7 +2834,7 @@ def streamOneP4File(self, file, contents):
             # Ideally, someday, this script can learn how to generate
             # appledouble files directly and import those to git, but
             # non-mac machines can never find a use for apple filetype.
-            print "\nIgnoring apple filetype file %s" % file['depotFile']
+            print("\nIgnoring apple filetype file %s" % file['depotFile'])
             return
 
         # Note that we do not try to de-mangle keywords on utf16 files,
@@ -2866,7 +2896,7 @@ def streamP4FilesCb(self, marshalled):
             else:
                 die("Error from p4 print: %s" % err)
 
-        if marshalled.has_key('depotFile') and self.stream_have_file_info:
+        if 'depotFile' in marshalled and self.stream_have_file_info:
             # start of a new file - output the old one first
             self.streamOneP4File(self.stream_file, self.stream_contents)
             self.stream_file = {}
@@ -2938,7 +2968,7 @@ def streamP4FilesCbSelf(entry):
                       cb=streamP4FilesCbSelf)
 
             # do the last chunk
-            if self.stream_file.has_key('depotFile'):
+            if 'depotFile' in self.stream_file:
                 self.streamOneP4File(self.stream_file, self.stream_contents)
 
     def make_email(self, userid):
@@ -2953,11 +2983,11 @@ def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
         """
 
         if verbose:
-            print "writing tag %s for commit %s" % (labelName, commit)
+            print("writing tag %s for commit %s" % (labelName, commit))
         gitStream.write("tag %s\n" % labelName)
         gitStream.write("from %s\n" % commit)
 
-        if labelDetails.has_key('Owner'):
+        if 'Owner' in labelDetails:
             owner = labelDetails["Owner"]
         else:
             owner = None
@@ -2972,8 +3002,8 @@ def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
 
         gitStream.write("tagger %s\n" % tagger)
 
-        print "labelDetails=",labelDetails
-        if labelDetails.has_key('Description'):
+        print("labelDetails=",labelDetails)
+        if 'Description' in labelDetails:
             description = labelDetails['Description']
         else:
             description = 'Label from git p4'
@@ -3044,7 +3074,7 @@ def commit(self, details, files, branch, parent = ""):
 
         if len(parent) > 0:
             if self.verbose:
-                print "parent %s" % parent
+                print("parent %s" % parent)
             self.gitStream.write("from %s\n" % parent)
 
         self.streamP4Files(files)
@@ -3052,12 +3082,12 @@ def commit(self, details, files, branch, parent = ""):
 
         change = int(details["change"])
 
-        if self.labels.has_key(change):
+        if change in self.labels:
             label = self.labels[change]
             labelDetails = label[0]
             labelRevisions = label[1]
             if self.verbose:
-                print "Change %s is labelled %s" % (change, labelDetails)
+                print("Change %s is labelled %s" % (change, labelDetails))
 
             files = p4CmdList(["files"] + ["%s...@%s" % (p, change)
                                                 for p in self.branchPrefixes])
@@ -3075,12 +3105,12 @@ def commit(self, details, files, branch, parent = ""):
 
                 else:
                     if not self.silent:
-                        print ("Tag %s does not match with change %s: files do not match."
+                        print("Tag %s does not match with change %s: files do not match."
                                % (labelDetails["label"], change))
 
             else:
                 if not self.silent:
-                    print ("Tag %s does not match with change %s: file count is different."
+                    print("Tag %s does not match with change %s: file count is different."
                            % (labelDetails["label"], change))
 
     # Build a dictionary of changelists and labels, for "detect-labels" option.
@@ -3089,14 +3119,14 @@ def getLabels(self):
 
         l = p4CmdList(["labels"] + ["%s..." % p for p in self.depotPaths])
         if len(l) > 0 and not self.silent:
-            print "Finding files belonging to labels in %s" % `self.depotPaths`
+            print("Finding files belonging to labels in %s" % self.depotPaths)
 
         for output in l:
             label = output["label"]
             revisions = {}
             newestChange = 0
             if self.verbose:
-                print "Querying files for label %s" % label
+                print("Querying files for label %s" % label)
             for file in p4CmdList(["files"] +
                                       ["%s...@%s" % (p, label)
                                           for p in self.depotPaths]):
@@ -3108,7 +3138,7 @@ def getLabels(self):
             self.labels[newestChange] = [output, revisions]
 
         if self.verbose:
-            print "Label changes: %s" % self.labels.keys()
+            print("Label changes: %s" % self.labels.keys())
 
     # Import p4 labels as git tags. A direct mapping does not
     # exist, so assume that if all the files are at the same revision
@@ -3116,7 +3146,7 @@ def getLabels(self):
     # just ignore.
     def importP4Labels(self, stream, p4Labels):
         if verbose:
-            print "import p4 labels: " + ' '.join(p4Labels)
+            print("import p4 labels: " + ' '.join(p4Labels))
 
         ignoredP4Labels = gitConfigList("git-p4.ignoredP4Labels")
         validLabelRegexp = gitConfig("git-p4.labelImportRegexp")
@@ -3129,7 +3159,7 @@ def importP4Labels(self, stream, p4Labels):
 
             if not m.match(name):
                 if verbose:
-                    print "label %s does not match regexp %s" % (name,validLabelRegexp)
+                    print("label %s does not match regexp %s" % (name,validLabelRegexp))
                 continue
 
             if name in ignoredP4Labels:
@@ -3141,7 +3171,7 @@ def importP4Labels(self, stream, p4Labels):
             change = p4Cmd(["changes", "-m", "1"] + ["%s...@%s" % (p, name)
                                 for p in self.depotPaths])
 
-            if change.has_key('change'):
+            if 'change' in change:
                 # find the corresponding git commit; take the oldest commit
                 changelist = int(change['change'])
                 if changelist in self.committedChanges:
@@ -3151,7 +3181,7 @@ def importP4Labels(self, stream, p4Labels):
                     gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
                         "--reverse", ":/\[git-p4:.*change = %d\]" % changelist], ignore_error=True)
                     if len(gitCommit) == 0:
-                        print "importing label %s: could not find git commit for changelist %d" % (name, changelist)
+                        print("importing label %s: could not find git commit for changelist %d" % (name, changelist))
                     else:
                         commitFound = True
                         gitCommit = gitCommit.strip()
@@ -3161,16 +3191,16 @@ def importP4Labels(self, stream, p4Labels):
                     try:
                         tmwhen = time.strptime(labelDetails['Update'], "%Y/%m/%d %H:%M:%S")
                     except ValueError:
-                        print "Could not convert label time %s" % labelDetails['Update']
+                        print("Could not convert label time %s" % labelDetails['Update'])
                         tmwhen = 1
 
                     when = int(time.mktime(tmwhen))
                     self.streamTag(stream, name, labelDetails, gitCommit, when)
                     if verbose:
-                        print "p4 label %s mapped to git commit %s" % (name, gitCommit)
+                        print("p4 label %s mapped to git commit %s" % (name, gitCommit))
             else:
                 if verbose:
-                    print "Label %s has no changelists - possibly deleted?" % name
+                    print("Label %s has no changelists - possibly deleted?" % name)
 
             if not commitFound:
                 # We can't import this label; don't try again as it will get very
@@ -3200,7 +3230,7 @@ def getBranchMapping(self):
         for info in p4CmdList(command):
             details = p4Cmd(["branch", "-o", info["branch"]])
             viewIdx = 0
-            while details.has_key("View%s" % viewIdx):
+            while "View%s" % viewIdx in details:
                 paths = details["View%s" % viewIdx].split(" ")
                 viewIdx = viewIdx + 1
                 # require standard //depot/foo/... //depot/bar/... mapping
@@ -3215,8 +3245,8 @@ def getBranchMapping(self):
 
                     if destination in self.knownBranches:
                         if not self.silent:
-                            print "p4 branch %s defines a mapping from %s to %s" % (info["branch"], source, destination)
-                            print "but there exists another mapping from %s to %s already!" % (self.knownBranches[destination], destination)
+                            print("p4 branch %s defines a mapping from %s to %s" % (info["branch"], source, destination))
+                            print("but there exists another mapping from %s to %s already!" % (self.knownBranches[destination], destination))
                         continue
 
                     self.knownBranches[destination] = source
@@ -3266,7 +3296,7 @@ def updateOptionDict(self, d):
         d["options"] = ' '.join(sorted(option_keys.keys()))
 
     def readOptions(self, d):
-        self.keepRepoPath = (d.has_key('options')
+        self.keepRepoPath = ('options' in d
                              and ('keepRepoPath' in d['options']))
 
     def gitRefForBranch(self, branch):
@@ -3280,28 +3310,28 @@ def gitRefForBranch(self, branch):
 
     def gitCommitByP4Change(self, ref, change):
         if self.verbose:
-            print "looking in ref " + ref + " for change %s using bisect..." % change
+            print("looking in ref " + ref + " for change %s using bisect..." % change)
 
         earliestCommit = ""
         latestCommit = parseRevision(ref)
 
         while True:
             if self.verbose:
-                print "trying: earliest %s latest %s" % (earliestCommit, latestCommit)
+                print("trying: earliest %s latest %s" % (earliestCommit, latestCommit))
             next = read_pipe("git rev-list --bisect %s %s" % (latestCommit, earliestCommit)).strip()
             if len(next) == 0:
                 if self.verbose:
-                    print "argh"
+                    print("argh")
                 return ""
             log = extractLogMessageFromGitCommit(next)
             settings = extractSettingsGitLog(log)
             currentChange = int(settings['change'])
             if self.verbose:
-                print "current change %s" % currentChange
+                print("current change %s" % currentChange)
 
             if currentChange == change:
                 if self.verbose:
-                    print "found %s" % next
+                    print("found %s" % next)
                 return next
 
             if currentChange < change:
@@ -3347,7 +3377,7 @@ def searchParent(self, parent, branch, target):
             if len(read_pipe(["git", "diff-tree", blob, target])) == 0:
                 parentFound = True
                 if self.verbose:
-                    print "Found parent of %s in commit %s" % (branch, blob)
+                    print("Found parent of %s in commit %s" % (branch, blob))
                 break
         if parentFound:
             return blob
@@ -3378,7 +3408,7 @@ def importChanges(self, changes, shelved=False, origin_revision=0):
                         filesForCommit = branches[branch]
 
                         if self.verbose:
-                            print "branch is %s" % branch
+                            print("branch is %s" % branch)
 
                         self.updatedBranches.add(branch)
 
@@ -3399,13 +3429,13 @@ def importChanges(self, changes, shelved=False, origin_revision=0):
                                         print("\n    Resuming with change %s" % change);
 
                                 if self.verbose:
-                                    print "parent determined through known branches: %s" % parent
+                                    print("parent determined through known branches: %s" % parent)
 
                         branch = self.gitRefForBranch(branch)
                         parent = self.gitRefForBranch(parent)
 
                         if self.verbose:
-                            print "looking for initial parent for %s; current parent is %s" % (branch, parent)
+                            print("looking for initial parent for %s; current parent is %s" % (branch, parent))
 
                         if len(parent) == 0 and branch in self.initialParents:
                             parent = self.initialParents[branch]
@@ -3415,7 +3445,7 @@ def importChanges(self, changes, shelved=False, origin_revision=0):
                         if len(parent) > 0:
                             tempBranch = "%s/%d" % (self.tempBranchLocation, change)
                             if self.verbose:
-                                print "Creating temporary branch: " + tempBranch
+                                print("Creating temporary branch: " + tempBranch)
                             self.commit(description, filesForCommit, tempBranch)
                             self.tempBranches.append(tempBranch)
                             self.checkpoint()
@@ -3424,7 +3454,7 @@ def importChanges(self, changes, shelved=False, origin_revision=0):
                             self.commit(description, filesForCommit, branch, blob)
                         else:
                             if self.verbose:
-                                print "Parent of %s not found. Committing into head of %s" % (branch, parent)
+                                print("Parent of %s not found. Committing into head of %s" % (branch, parent))
                             self.commit(description, filesForCommit, branch, parent)
                 else:
                     files = self.extractFilesFromCommit(description, shelved, change, origin_revision)
@@ -3433,7 +3463,7 @@ def importChanges(self, changes, shelved=False, origin_revision=0):
                     # only needed once, to connect to the previous commit
                     self.initialParent = ""
             except IOError:
-                print self.gitError.read()
+                print(self.gitError.read())
                 sys.exit(1)
 
     def sync_origin_only(self):
@@ -3441,11 +3471,11 @@ def sync_origin_only(self):
             self.hasOrigin = originP4BranchesExist()
             if self.hasOrigin:
                 if not self.silent:
-                    print 'Syncing with origin first, using "git fetch origin"'
+                    print('Syncing with origin first, using "git fetch origin"')
                 system("git fetch origin")
 
     def importHeadRevision(self, revision):
-        print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch)
+        print("Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch))
 
         details = {}
         details["user"] = "git perforce import user"
@@ -3497,8 +3527,8 @@ def importHeadRevision(self, revision):
         try:
             self.commit(details, self.extractFilesFromCommit(details), self.branch)
         except IOError:
-            print "IO error with git fast-import. Is your git version recent enough?"
-            print self.gitError.read()
+            print("IO error with git fast-import. Is your git version recent enough?")
+            print(self.gitError.read())
 
     def openStreams(self):
         self.importProcess = subprocess.Popen(["git", "fast-import"],
@@ -3560,14 +3590,14 @@ def run(self, args):
 
             if len(self.p4BranchesInGit) > 1:
                 if not self.silent:
-                    print "Importing from/into multiple branches"
+                    print("Importing from/into multiple branches")
                 self.detectBranches = True
                 for branch in branches.keys():
                     self.initialParents[self.refPrefix + branch] = \
                         branches[branch]
 
             if self.verbose:
-                print "branches: %s" % self.p4BranchesInGit
+                print("branches: %s" % self.p4BranchesInGit)
 
             p4Change = 0
             for branch in self.p4BranchesInGit:
@@ -3576,8 +3606,8 @@ def run(self, args):
                 settings = extractSettingsGitLog(logMsg)
 
                 self.readOptions(settings)
-                if (settings.has_key('depot-paths')
-                    and settings.has_key ('change')):
+                if ('depot-paths' in settings
+                    and 'change' in settings):
                     change = int(settings['change']) + 1
                     p4Change = max(p4Change, change)
 
@@ -3590,7 +3620,7 @@ def run(self, args):
                             prev_list = prev.split("/")
                             cur_list = cur.split("/")
                             for i in range(0, min(len(cur_list), len(prev_list))):
-                                if cur_list[i] <> prev_list[i]:
+                                if cur_list[i] != prev_list[i]:
                                     i = i - 1
                                     break
 
@@ -3602,7 +3632,7 @@ def run(self, args):
                 self.depotPaths = sorted(self.previousDepotPaths)
                 self.changeRange = "@%s,#head" % p4Change
                 if not self.silent and not self.detectBranches:
-                    print "Performing incremental import into %s git branch" % self.branch
+                    print("Performing incremental import into %s git branch" % self.branch)
 
         # accept multiple ref name abbreviations:
         #    refs/foo/bar/branch -> use it exactly
@@ -3619,10 +3649,10 @@ def run(self, args):
 
         if len(args) == 0 and self.depotPaths:
             if not self.silent:
-                print "Depot paths: %s" % ' '.join(self.depotPaths)
+                print("Depot paths: %s" % ' '.join(self.depotPaths))
         else:
             if self.depotPaths and self.depotPaths != args:
-                print ("previous import used depot path %s and now %s was specified. "
+                print("previous import used depot path %s and now %s was specified. "
                        "This doesn't work!" % (' '.join (self.depotPaths),
                                                ' '.join (args)))
                 sys.exit(1)
@@ -3689,8 +3719,8 @@ def run(self, args):
             else:
                 self.getBranchMapping()
             if self.verbose:
-                print "p4-git branches: %s" % self.p4BranchesInGit
-                print "initial parents: %s" % self.initialParents
+                print("p4-git branches: %s" % self.p4BranchesInGit)
+                print("initial parents: %s" % self.initialParents)
             for b in self.p4BranchesInGit:
                 if b != "master":
 
@@ -3734,8 +3764,8 @@ def run(self, args):
                                     self.branch)
 
                 if self.verbose:
-                    print "Getting p4 changes for %s...%s" % (', '.join(self.depotPaths),
-                                                              self.changeRange)
+                    print("Getting p4 changes for %s...%s" % (', '.join(self.depotPaths),
+                                                              self.changeRange))
                 changes = p4ChangesForPaths(self.depotPaths, self.changeRange, self.changes_block_size)
 
                 if len(self.maxChanges) > 0:
@@ -3743,10 +3773,10 @@ def run(self, args):
 
             if len(changes) == 0:
                 if not self.silent:
-                    print "No changes to import!"
+                    print("No changes to import!")
             else:
                 if not self.silent and not self.detectBranches:
-                    print "Import destination: %s" % self.branch
+                    print("Import destination: %s" % self.branch)
 
                 self.updatedBranches = set()
 
@@ -3761,7 +3791,7 @@ def run(self, args):
                 self.importChanges(changes)
 
                 if not self.silent:
-                    print ""
+                    print("")
                     if len(self.updatedBranches) > 0:
                         sys.stdout.write("Updated branches: ")
                         for b in self.updatedBranches:
@@ -3825,7 +3855,7 @@ def rebase(self):
         # the branchpoint may be p4/foo~3, so strip off the parent
         upstream = re.sub("~[0-9]+$", "", upstream)
 
-        print "Rebasing the current branch onto %s" % upstream
+        print("Rebasing the current branch onto %s" % upstream)
         oldHead = read_pipe("git rev-parse HEAD").strip()
         system("git rebase %s" % upstream)
         system("git diff-tree --stat --summary -M %s HEAD --" % oldHead)
@@ -3879,7 +3909,7 @@ def run(self, args):
         if not self.cloneDestination:
             self.cloneDestination = self.defaultDestination(args)
 
-        print "Importing from %s into %s" % (', '.join(depotPaths), self.cloneDestination)
+        print("Importing from %s into %s" % (', '.join(depotPaths), self.cloneDestination))
 
         if not os.path.exists(self.cloneDestination):
             os.makedirs(self.cloneDestination)
@@ -3901,8 +3931,8 @@ def run(self, args):
             if not self.cloneBare:
                 system([ "git", "checkout", "-f" ])
         else:
-            print 'Not checking out any branch, use ' \
-                  '"git checkout -q -b master <branch>"'
+            print('Not checking out any branch, use ' \
+                  '"git checkout -q -b master <branch>"')
 
         # auto-set this variable if invoked with --use-client-spec
         if self.useClientSpec_from_options:
@@ -3950,7 +3980,7 @@ def findLastP4Revision(self, starting_point):
         for parent in (range(65535)):
             log = extractLogMessageFromGitCommit("{0}^{1}".format(starting_point, parent))
             settings = extractSettingsGitLog(log)
-            if settings.has_key('change'):
+            if 'change' in settings:
                 return settings
 
         sys.exit("could not find git-p4 commits in {0}".format(self.origin))
@@ -4018,7 +4048,7 @@ def run(self, args):
             log = extractLogMessageFromGitCommit("refs/remotes/%s" % branch)
             settings = extractSettingsGitLog(log)
 
-            print "%s <= %s (%s)" % (branch, ",".join(settings["depot-paths"]), settings["change"])
+            print("%s <= %s (%s)" % (branch, ",".join(settings["depot-paths"]), settings["change"]))
         return True
 
 class HelpFormatter(optparse.IndentedHelpFormatter):
@@ -4032,12 +4062,12 @@ def format_description(self, description):
             return ""
 
 def printUsage(commands):
-    print "usage: %s <command> [options]" % sys.argv[0]
-    print ""
-    print "valid commands: %s" % ", ".join(commands)
-    print ""
-    print "Try %s <command> --help for command specific help." % sys.argv[0]
-    print ""
+    print("usage: %s <command> [options]" % sys.argv[0])
+    print("")
+    print("valid commands: %s" % ", ".join(commands))
+    print("")
+    print("Try %s <command> --help for command specific help." % sys.argv[0])
+    print("")
 
 commands = {
     "debug" : P4Debug,
@@ -4062,8 +4092,8 @@ def main():
         klass = commands[cmdName]
         cmd = klass()
     except KeyError:
-        print "unknown command %s" % cmdName
-        print ""
+        print("unknown command %s" % cmdName)
+        print("")
         printUsage(commands.keys())
         sys.exit(2)
 
index cf4c0422148935906ad939c5351652a1531e5f0d..aa2f2f08728edbbfd4beb28a882b744170b426ba 100644 (file)
@@ -71,7 +71,7 @@ call_merge () {
        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"'
+       eval 'git merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"'
        rv=$?
        case "$rv" in
        0)
@@ -88,7 +88,7 @@ call_merge () {
                ;;
        *)
                die "Unknown exit code ($rv) from command:" \
-                       "git-merge-$strategy $cmt^ -- HEAD $cmt"
+                       "git merge-$strategy $cmt^ -- HEAD $cmt"
                ;;
        esac
 }
index c51c7828e7b331710006ac9a15f3d7443dcf3816..c214c5e4d6ce21996f16031ec14dd624b75a9939 100644 (file)
@@ -891,9 +891,9 @@ $comment_char $(eval_ngettext \
 EOF
        append_todo_help
        gettext "
-       However, if you remove everything, the rebase will be aborted.
+However, if you remove everything, the rebase will be aborted.
 
-       " | git stripspace --comment-lines >>"$todo"
+" | git stripspace --comment-lines >>"$todo"
 
        if test -z "$keep_empty"
        then
index 19bdebb48025e236c596d554768012951d348632..797344764510e0a2b09bf91af08c528411a9025b 100755 (executable)
@@ -20,23 +20,23 @@ onto=!             rebase onto given branch instead of upstream
 r,rebase-merges?   try to rebase merges instead of skipping them
 p,preserve-merges! try to recreate merges instead of ignoring them
 s,strategy=!       use the given merge strategy
+X,strategy-option=! pass the argument through to the merge strategy
 no-ff!             cherry-pick all commits, even if unchanged
+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
 k,keep-empty      preserve empty commits during rebase
 allow-empty-message allow rebasing commits with empty messages
-f,force-rebase!    force rebase even if branch is up to date
-X,strategy-option=! pass the argument through to the merge strategy
 stat!              display a diffstat of what changed upstream
 n,no-stat!         do not show diffstat of what changed upstream
 verify             allow pre-rebase hook to run
 rerere-autoupdate  allow rerere to update index with resolved conflicts
 root!              rebase all reachable commits up to the root(s)
 autosquash         move commits that begin with squash!/fixup! under -i
+signoff            add a Signed-off-by: line to each commit
 committer-date-is-author-date! passed to 'git am'
 ignore-date!       passed to 'git am'
-signoff            passed to 'git am'
 whitespace=!       passed to 'git apply'
 ignore-whitespace! passed to 'git apply'
 C=!                passed to 'git apply'
@@ -95,7 +95,7 @@ rebase_cousins=
 preserve_merges=
 autosquash=
 keep_empty=
-allow_empty_message=
+allow_empty_message=--allow-empty-message
 signoff=
 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 case "$(git config --bool commit.gpgsign)" in
@@ -328,7 +328,7 @@ do
                do_merge=t
                ;;
        --strategy-option=*)
-               strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--${1#--strategy-option=}")"
+               strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--${1#--strategy-option=}" | sed -e s/^.//)"
                do_merge=t
                test -z "$strategy" && strategy=recursive
                ;;
@@ -521,6 +521,24 @@ 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"
+       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
+       fi
+fi
+
 if test -n "$signoff"
 then
        test -n "$preserve_merges" &&
@@ -529,6 +547,23 @@ then
        force_rebase=t
 fi
 
+if test -n "$preserve_merges"
+then
+       # 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"
+       test -n "$rebase_merges" &&
+               die "$(gettext "error: cannot combine '--preserve_merges' with '--rebase-merges'")"
+fi
+
+if test -n "$rebase_merges"
+then
+       test -n "$strategy_opts" &&
+               die "$(gettext "error: cannot combine '--rebase_merges' with '--strategy-option'")"
+       test -n "$strategy" &&
+               die "$(gettext "error: cannot combine '--rebase_merges' with '--strategy'")"
+fi
+
 if test -z "$rebase_root"
 then
        case "$#" in
index 8ec70e58ed5c4caace7701549038b63f9a3e9aad..2be5dac337a0e2f4a0ea1538c7873aa43382cb04 100755 (executable)
@@ -231,7 +231,7 @@ sub do_edit {
 my (@suppress_cc);
 my ($auto_8bit_encoding);
 my ($compose_encoding);
-my ($target_xfer_encoding);
+my $target_xfer_encoding = 'auto';
 
 my ($debug_net_smtp) = 0;              # Net::SMTP, see send_message()
 
@@ -645,7 +645,7 @@ sub is_format_patch_arg {
 if ($validate) {
        foreach my $f (@files) {
                unless (-p $f) {
-                       my $error = validate_patch($f);
+                       my $error = validate_patch($f, $target_xfer_encoding);
                        $error and die sprintf(__("fatal: %s: %s\nwarning: no patches were sent\n"),
                                                  $f, $error);
                }
@@ -1479,7 +1479,7 @@ sub send_message {
                                                         SSL => 1);
                        }
                }
-               else {
+               elsif (!$smtp) {
                        $smtp_server_port ||= 25;
                        $smtp ||= Net::SMTP->new($smtp_server,
                                                 Hello => $smtp_domain,
@@ -1501,7 +1501,6 @@ sub send_message {
                                        $smtp->starttls(ssl_verify_params())
                                                or die sprintf(__("STARTTLS failed! %s"), IO::Socket::SSL::errstr());
                                }
-                               $smtp_encryption = '';
                                # Send EHLO again to receive fresh
                                # supported commands
                                $smtp->hello($smtp_domain);
@@ -1737,18 +1736,11 @@ sub process_file {
                        }
                }
        }
-       if (defined $target_xfer_encoding) {
-               $xfer_encoding = '8bit' if not defined $xfer_encoding;
-               $message = apply_transfer_encoding(
-                       $message, $xfer_encoding, $target_xfer_encoding);
-               $xfer_encoding = $target_xfer_encoding;
-       }
-       if (defined $xfer_encoding) {
-               push @xh, "Content-Transfer-Encoding: $xfer_encoding";
-       }
-       if (defined $xfer_encoding or $has_content_type) {
-               unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
-       }
+       $xfer_encoding = '8bit' if not defined $xfer_encoding;
+       ($message, $xfer_encoding) = apply_transfer_encoding(
+               $message, $xfer_encoding, $target_xfer_encoding);
+       push @xh, "Content-Transfer-Encoding: $xfer_encoding";
+       unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
 
        $needs_confirm = (
                $confirm eq "always" or
@@ -1852,13 +1844,16 @@ sub apply_transfer_encoding {
        $message = MIME::Base64::decode($message)
                if ($from eq 'base64');
 
+       $to = ($message =~ /.{999,}/) ? 'quoted-printable' : '8bit'
+               if $to eq 'auto';
+
        die __("cannot send message as 7bit")
                if ($to eq '7bit' and $message =~ /[^[:ascii:]]/);
-       return $message
+       return ($message, $to)
                if ($to eq '7bit' or $to eq '8bit');
-       return MIME::QuotedPrint::encode($message, "\n", 0)
+       return (MIME::QuotedPrint::encode($message, "\n", 0), $to)
                if ($to eq 'quoted-printable');
-       return MIME::Base64::encode($message, "\n")
+       return (MIME::Base64::encode($message, "\n"), $to)
                if ($to eq 'base64');
        die __("invalid transfer encoding");
 }
@@ -1877,7 +1872,7 @@ sub unique_email_list {
 }
 
 sub validate_patch {
-       my $fn = shift;
+       my ($fn, $xfer_encoding) = @_;
 
        if ($repo) {
                my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
@@ -1897,11 +1892,15 @@ sub validate_patch {
                return $hook_error if $hook_error;
        }
 
-       open(my $fh, '<', $fn)
-               or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
-       while (my $line = <$fh>) {
-               if (length($line) > 998) {
-                       return sprintf(__("%s: patch contains a line longer than 998 characters"), $.);
+       # Any long lines will be automatically fixed if we use a suitable transfer
+       # encoding.
+       unless ($xfer_encoding =~ /^(?:auto|quoted-printable|base64)$/) {
+               open(my $fh, '<', $fn)
+                       or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
+               while (my $line = <$fh>) {
+                       if (length($line) > 998) {
+                               return sprintf(__("%s: patch contains a line longer than 998 characters"), $.);
+                       }
                }
        }
        return;
index 5f9d9f6ea3713be458c006501c503d8d660e9ddf..f7fd80345cd991df4b17c6598d7dd7bd462424c7 100755 (executable)
@@ -438,6 +438,9 @@ cmd_update()
                -q|--quiet)
                        GIT_QUIET=1
                        ;;
+               -v)
+                       GIT_QUIET=0
+                       ;;
                --progress)
                        progress=1
                        ;;
@@ -577,6 +580,11 @@ cmd_update()
                        die "$(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")"
                fi
 
+               if ! $(git config -f "$(git rev-parse --git-common-dir)/modules/$name/config" core.worktree) 2>/dev/null
+               then
+                       git submodule--helper connect-gitdir-workingtree "$name" "$sm_path"
+               fi
+
                if test "$subsha1" != "$sha1" || test -n "$force"
                then
                        subforce=$force
diff --git a/git.c b/git.c
index 9dbe6ffaa7f04ceba22b215a221b9a389d0cad97..c27c38738b2a9d9d61460b150d5ab4d36bb9cf5b 100644 (file)
--- a/git.c
+++ b/git.c
@@ -164,7 +164,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                        if (envchanged)
                                *envchanged = 1;
                } else if (!strcmp(cmd, "--no-replace-objects")) {
-                       check_replace_refs = 0;
+                       read_replace_refs = 0;
                        setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
                        if (envchanged)
                                *envchanged = 1;
@@ -267,7 +267,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                } else if (!strcmp(cmd, "--shallow-file")) {
                        (*argv)++;
                        (*argc)--;
-                       set_alternate_shallow_file((*argv)[0], 1);
+                       set_alternate_shallow_file(the_repository, (*argv)[0], 1);
                        if (envchanged)
                                *envchanged = 1;
                } else if (!strcmp(cmd, "-C")) {
@@ -414,7 +414,10 @@ 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);
        status = p->fn(argc, argv, prefix);
+       validate_cache_entries(&the_index);
+
        if (status)
                return status;
 
@@ -517,6 +520,7 @@ static struct cmd_struct commands[] = {
        { "prune-packed", cmd_prune_packed, RUN_SETUP },
        { "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
        { "push", cmd_push, RUN_SETUP },
+       { "range-diff", cmd_range_diff, RUN_SETUP | USE_PAGER },
        { "read-tree", cmd_read_tree, RUN_SETUP | SUPPORT_SUPER_PREFIX},
        { "rebase--helper", cmd_rebase__helper, RUN_SETUP | NEED_WORK_TREE },
        { "receive-pack", cmd_receive_pack },
index 0647bd6348cdedd0e32f30ed23934d390eae4122..db17d65f8ac977ddc5204130cb0af6a7565ae04b 100644 (file)
@@ -7,10 +7,64 @@
 #include "tempfile.h"
 
 static char *configured_signing_key;
-static const char *gpg_program = "gpg";
+struct gpg_format {
+       const char *name;
+       const char *program;
+       const char **verify_args;
+       const char **sigs;
+};
+
+static const char *openpgp_verify_args[] = {
+       "--keyid-format=long",
+       NULL
+};
+static const char *openpgp_sigs[] = {
+       "-----BEGIN PGP SIGNATURE-----",
+       "-----BEGIN PGP MESSAGE-----",
+       NULL
+};
+
+static const char *x509_verify_args[] = {
+       NULL
+};
+static const char *x509_sigs[] = {
+       "-----BEGIN SIGNED MESSAGE-----",
+       NULL
+};
 
-#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
-#define PGP_MESSAGE "-----BEGIN PGP MESSAGE-----"
+static struct gpg_format gpg_format[] = {
+       { .name = "openpgp", .program = "gpg",
+         .verify_args = openpgp_verify_args,
+         .sigs = openpgp_sigs
+       },
+       { .name = "x509", .program = "gpgsm",
+         .verify_args = x509_verify_args,
+         .sigs = x509_sigs
+       },
+};
+
+static struct gpg_format *use_format = &gpg_format[0];
+
+static struct gpg_format *get_format_by_name(const char *str)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(gpg_format); i++)
+               if (!strcmp(gpg_format[i].name, str))
+                       return gpg_format + i;
+       return NULL;
+}
+
+static struct gpg_format *get_format_by_sig(const char *sig)
+{
+       int i, j;
+
+       for (i = 0; i < ARRAY_SIZE(gpg_format); i++)
+               for (j = 0; gpg_format[i].sigs[j]; j++)
+                       if (starts_with(sig, gpg_format[i].sigs[j]))
+                               return gpg_format + i;
+       return NULL;
+}
 
 void signature_check_clear(struct signature_check *sigc)
 {
@@ -35,7 +89,7 @@ static struct {
        { 'R', "\n[GNUPG:] REVKEYSIG "},
 };
 
-void parse_gpg_output(struct signature_check *sigc)
+static void parse_gpg_output(struct signature_check *sigc)
 {
        const char *buf = sigc->gpg_status;
        int i;
@@ -53,10 +107,11 @@ void parse_gpg_output(struct signature_check *sigc)
                sigc->result = sigcheck_gpg_status[i].result;
                /* The trust messages are not followed by key/signer information */
                if (sigc->result != 'U') {
-                       sigc->key = xmemdupz(found, 16);
+                       next = strchrnul(found, ' ');
+                       sigc->key = xmemdupz(found, next - found);
                        /* The ERRSIG message is not followed by signer information */
-                       if (sigc-> result != 'E') {
-                               found += 17;
+                       if (*next && sigc-> result != 'E') {
+                               found = next + 1;
                                next = strchrnul(found, '\n');
                                sigc->signer = xmemdupz(found, next - found);
                        }
@@ -81,12 +136,13 @@ int check_signature(const char *payload, size_t plen, const char *signature,
        sigc->gpg_output = strbuf_detach(&gpg_output, NULL);
        sigc->gpg_status = strbuf_detach(&gpg_status, NULL);
        parse_gpg_output(sigc);
+       status |= sigc->result != 'G' && sigc->result != 'U';
 
  out:
        strbuf_release(&gpg_status);
        strbuf_release(&gpg_output);
 
-       return sigc->result != 'G' && sigc->result != 'U';
+       return !!status;
 }
 
 void print_signature_buffer(const struct signature_check *sigc, unsigned flags)
@@ -101,12 +157,6 @@ void print_signature_buffer(const struct signature_check *sigc, unsigned flags)
                fputs(output, stderr);
 }
 
-static int is_gpg_start(const char *line)
-{
-       return starts_with(line, PGP_SIGNATURE) ||
-               starts_with(line, PGP_MESSAGE);
-}
-
 size_t parse_signature(const char *buf, size_t size)
 {
        size_t len = 0;
@@ -114,7 +164,7 @@ size_t parse_signature(const char *buf, size_t size)
        while (len < size) {
                const char *eol;
 
-               if (is_gpg_start(buf + len))
+               if (get_format_by_sig(buf + len))
                        match = len;
 
                eol = memchr(buf + len, '\n', size - len);
@@ -131,6 +181,9 @@ void set_signing_key(const char *key)
 
 int git_gpg_config(const char *var, const char *value, void *cb)
 {
+       struct gpg_format *fmt = NULL;
+       char *fmtname = NULL;
+
        if (!strcmp(var, "user.signingkey")) {
                if (!value)
                        return config_error_nonbool(var);
@@ -138,13 +191,28 @@ int git_gpg_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
-       if (!strcmp(var, "gpg.program")) {
+       if (!strcmp(var, "gpg.format")) {
                if (!value)
                        return config_error_nonbool(var);
-               gpg_program = xstrdup(value);
+               fmt = get_format_by_name(value);
+               if (!fmt)
+                       return error("unsupported value for %s: %s",
+                                    var, value);
+               use_format = fmt;
                return 0;
        }
 
+       if (!strcmp(var, "gpg.program") || !strcmp(var, "gpg.openpgp.program"))
+               fmtname = "openpgp";
+
+       if (!strcmp(var, "gpg.x509.program"))
+               fmtname = "x509";
+
+       if (fmtname) {
+               fmt = get_format_by_name(fmtname);
+               return git_config_string(&fmt->program, var, value);
+       }
+
        return 0;
 }
 
@@ -163,7 +231,7 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *sig
        struct strbuf gpg_status = STRBUF_INIT;
 
        argv_array_pushl(&gpg.args,
-                        gpg_program,
+                        use_format->program,
                         "--status-fd=2",
                         "-bsau", signing_key,
                         NULL);
@@ -201,6 +269,7 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
                         struct strbuf *gpg_output, struct strbuf *gpg_status)
 {
        struct child_process gpg = CHILD_PROCESS_INIT;
+       struct gpg_format *fmt;
        struct tempfile *temp;
        int ret;
        struct strbuf buf = STRBUF_INIT;
@@ -216,10 +285,14 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
                return -1;
        }
 
+       fmt = get_format_by_sig(signature);
+       if (!fmt)
+               BUG("bad signature '%s'", signature);
+
+       argv_array_push(&gpg.args, fmt->program);
+       argv_array_pushv(&gpg.args, fmt->verify_args);
        argv_array_pushl(&gpg.args,
-                        gpg_program,
                         "--status-fd=1",
-                        "--keyid-format=long",
                         "--verify", temp->filename.buf, "-",
                         NULL);
 
index a5e6517ae67ea5fa3f79265517381d58d99fba18..5ecff4aa0c062d8a33290d39456e24c073fd48e4 100644 (file)
@@ -33,8 +33,6 @@ void signature_check_clear(struct signature_check *sigc);
  */
 size_t parse_signature(const char *buf, size_t size);
 
-void parse_gpg_output(struct signature_check *);
-
 /*
  * Create a detached signature for the contents of "buffer" and append
  * it after "signature"; "buffer" and "signature" can be the same
diff --git a/grep.c b/grep.c
index 7c1b8e2e8ba38f27ee4fe16e39cfe319ab89265f..2b26cee08d559ceba6dd5a83ae90aaa0155ebca8 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "grep.h"
+#include "object-store.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
 #include "diff.h"
@@ -19,6 +20,7 @@ static const char *color_grep_slots[] = {
        [GREP_COLOR_FILENAME]       = "filename",
        [GREP_COLOR_FUNCTION]       = "function",
        [GREP_COLOR_LINENO]         = "lineNumber",
+       [GREP_COLOR_COLUMNNO]       = "column",
        [GREP_COLOR_MATCH_CONTEXT]  = "matchContext",
        [GREP_COLOR_MATCH_SELECTED] = "matchSelected",
        [GREP_COLOR_SELECTED]       = "selected",
@@ -58,10 +60,12 @@ void init_grep_defaults(void)
        color_set(opt->colors[GREP_COLOR_FILENAME], "");
        color_set(opt->colors[GREP_COLOR_FUNCTION], "");
        color_set(opt->colors[GREP_COLOR_LINENO], "");
+       color_set(opt->colors[GREP_COLOR_COLUMNNO], "");
        color_set(opt->colors[GREP_COLOR_MATCH_CONTEXT], GIT_COLOR_BOLD_RED);
        color_set(opt->colors[GREP_COLOR_MATCH_SELECTED], GIT_COLOR_BOLD_RED);
        color_set(opt->colors[GREP_COLOR_SELECTED], "");
        color_set(opt->colors[GREP_COLOR_SEP], GIT_COLOR_CYAN);
+       opt->only_matching = 0;
        opt->color = -1;
        opt->output = std_output;
 }
@@ -109,6 +113,10 @@ int grep_config(const char *var, const char *value, void *cb)
                opt->linenum = git_config_bool(var, value);
                return 0;
        }
+       if (!strcmp(var, "grep.column")) {
+               opt->columnnum = git_config_bool(var, value);
+               return 0;
+       }
 
        if (!strcmp(var, "grep.fullname")) {
                opt->relative = !git_config_bool(var, value);
@@ -152,10 +160,12 @@ void grep_init(struct grep_opt *opt, const char *prefix)
        opt->pattern_tail = &opt->pattern_list;
        opt->header_tail = &opt->header_list;
 
+       opt->only_matching = def->only_matching;
        opt->color = def->color;
        opt->extended_regexp_option = def->extended_regexp_option;
        opt->pattern_type_option = def->pattern_type_option;
        opt->linenum = def->linenum;
+       opt->columnnum = def->columnnum;
        opt->max_depth = def->max_depth;
        opt->pathname = def->pathname;
        opt->relative = def->relative;
@@ -1243,11 +1253,11 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
        return hit;
 }
 
-static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
-                          enum grep_context ctx, int collect_hits)
+static int match_expr_eval(struct grep_opt *opt, struct grep_expr *x, char *bol,
+                          char *eol, enum grep_context ctx, ssize_t *col,
+                          ssize_t *icol, int collect_hits)
 {
        int h = 0;
-       regmatch_t match;
 
        if (!x)
                die("Not a valid grep expression");
@@ -1256,25 +1266,52 @@ static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
                h = 1;
                break;
        case GREP_NODE_ATOM:
-               h = match_one_pattern(x->u.atom, bol, eol, ctx, &match, 0);
+               {
+                       regmatch_t tmp;
+                       h = match_one_pattern(x->u.atom, bol, eol, ctx,
+                                             &tmp, 0);
+                       if (h && (*col < 0 || tmp.rm_so < *col))
+                               *col = tmp.rm_so;
+               }
                break;
        case GREP_NODE_NOT:
-               h = !match_expr_eval(x->u.unary, bol, eol, ctx, 0);
+               /*
+                * Upon visiting a GREP_NODE_NOT, col and icol become swapped.
+                */
+               h = !match_expr_eval(opt, x->u.unary, bol, eol, ctx, icol, col,
+                                    0);
                break;
        case GREP_NODE_AND:
-               if (!match_expr_eval(x->u.binary.left, bol, eol, ctx, 0))
-                       return 0;
-               h = match_expr_eval(x->u.binary.right, bol, eol, ctx, 0);
+               h = match_expr_eval(opt, x->u.binary.left, bol, eol, ctx, col,
+                                   icol, 0);
+               if (h || opt->columnnum) {
+                       /*
+                        * Don't short-circuit AND when given --column, since a
+                        * NOT earlier in the tree may turn this into an OR. In
+                        * this case, see the below comment.
+                        */
+                       h &= match_expr_eval(opt, x->u.binary.right, bol, eol,
+                                            ctx, col, icol, 0);
+               }
                break;
        case GREP_NODE_OR:
-               if (!collect_hits)
-                       return (match_expr_eval(x->u.binary.left,
-                                               bol, eol, ctx, 0) ||
-                               match_expr_eval(x->u.binary.right,
-                                               bol, eol, ctx, 0));
-               h = match_expr_eval(x->u.binary.left, bol, eol, ctx, 0);
-               x->u.binary.left->hit |= h;
-               h |= match_expr_eval(x->u.binary.right, bol, eol, ctx, 1);
+               if (!(collect_hits || opt->columnnum)) {
+                       /*
+                        * Don't short-circuit OR when given --column (or
+                        * collecting hits) to ensure we don't skip a later
+                        * child that would produce an earlier match.
+                        */
+                       return (match_expr_eval(opt, x->u.binary.left, bol, eol,
+                                               ctx, col, icol, 0) ||
+                               match_expr_eval(opt, x->u.binary.right, bol,
+                                               eol, ctx, col, icol, 0));
+               }
+               h = match_expr_eval(opt, x->u.binary.left, bol, eol, ctx, col,
+                                   icol, 0);
+               if (collect_hits)
+                       x->u.binary.left->hit |= h;
+               h |= match_expr_eval(opt, x->u.binary.right, bol, eol, ctx, col,
+                                    icol, collect_hits);
                break;
        default:
                die("Unexpected node type (internal error) %d", x->node);
@@ -1285,27 +1322,43 @@ static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
 }
 
 static int match_expr(struct grep_opt *opt, char *bol, char *eol,
-                     enum grep_context ctx, int collect_hits)
+                     enum grep_context ctx, ssize_t *col,
+                     ssize_t *icol, int collect_hits)
 {
        struct grep_expr *x = opt->pattern_expression;
-       return match_expr_eval(x, bol, eol, ctx, collect_hits);
+       return match_expr_eval(opt, x, bol, eol, ctx, col, icol, collect_hits);
 }
 
 static int match_line(struct grep_opt *opt, char *bol, char *eol,
+                     ssize_t *col, ssize_t *icol,
                      enum grep_context ctx, int collect_hits)
 {
        struct grep_pat *p;
-       regmatch_t match;
+       int hit = 0;
 
        if (opt->extended)
-               return match_expr(opt, bol, eol, ctx, collect_hits);
+               return match_expr(opt, bol, eol, ctx, col, icol,
+                                 collect_hits);
 
        /* we do not call with collect_hits without being extended */
        for (p = opt->pattern_list; p; p = p->next) {
-               if (match_one_pattern(p, bol, eol, ctx, &match, 0))
-                       return 1;
+               regmatch_t tmp;
+               if (match_one_pattern(p, bol, eol, ctx, &tmp, 0)) {
+                       hit |= 1;
+                       if (!opt->columnnum) {
+                               /*
+                                * Without --column, any single match on a line
+                                * is enough to know that it needs to be
+                                * printed. With --column, scan _all_ patterns
+                                * to find the earliest.
+                                */
+                               break;
+                       }
+                       if (*col < 0 || tmp.rm_so < *col)
+                               *col = tmp.rm_so;
+               }
        }
-       return 0;
+       return hit;
 }
 
 static int match_next_pattern(struct grep_pat *p, char *bol, char *eol,
@@ -1353,11 +1406,44 @@ static int next_match(struct grep_opt *opt, char *bol, char *eol,
        return hit;
 }
 
+static void show_line_header(struct grep_opt *opt, const char *name,
+                            unsigned lno, ssize_t cno, char sign)
+{
+       if (opt->heading && opt->last_shown == 0) {
+               output_color(opt, name, strlen(name), opt->colors[GREP_COLOR_FILENAME]);
+               opt->output(opt, "\n", 1);
+       }
+       opt->last_shown = lno;
+
+       if (!opt->heading && opt->pathname) {
+               output_color(opt, name, strlen(name), opt->colors[GREP_COLOR_FILENAME]);
+               output_sep(opt, sign);
+       }
+       if (opt->linenum) {
+               char buf[32];
+               xsnprintf(buf, sizeof(buf), "%d", lno);
+               output_color(opt, buf, strlen(buf), opt->colors[GREP_COLOR_LINENO]);
+               output_sep(opt, sign);
+       }
+       /*
+        * Treat 'cno' as the 1-indexed offset from the start of a non-context
+        * line to its first match. Otherwise, 'cno' is 0 indicating that we are
+        * being called with a context line.
+        */
+       if (opt->columnnum && cno) {
+               char buf[32];
+               xsnprintf(buf, sizeof(buf), "%"PRIuMAX, (uintmax_t)cno);
+               output_color(opt, buf, strlen(buf), opt->colors[GREP_COLOR_COLUMNNO]);
+               output_sep(opt, sign);
+       }
+}
+
 static void show_line(struct grep_opt *opt, char *bol, char *eol,
-                     const char *name, unsigned lno, char sign)
+                     const char *name, unsigned lno, ssize_t cno, char sign)
 {
        int rest = eol - bol;
-       const char *match_color, *line_color = NULL;
+       const char *match_color = NULL;
+       const char *line_color = NULL;
 
        if (opt->file_break && opt->last_shown == 0) {
                if (opt->show_hunk_mark)
@@ -1373,54 +1459,55 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
                        opt->output(opt, "\n", 1);
                }
        }
-       if (opt->heading && opt->last_shown == 0) {
-               output_color(opt, name, strlen(name), opt->colors[GREP_COLOR_FILENAME]);
-               opt->output(opt, "\n", 1);
-       }
-       opt->last_shown = lno;
-
-       if (!opt->heading && opt->pathname) {
-               output_color(opt, name, strlen(name), opt->colors[GREP_COLOR_FILENAME]);
-               output_sep(opt, sign);
-       }
-       if (opt->linenum) {
-               char buf[32];
-               xsnprintf(buf, sizeof(buf), "%d", lno);
-               output_color(opt, buf, strlen(buf), opt->colors[GREP_COLOR_LINENO]);
-               output_sep(opt, sign);
+       if (!opt->only_matching) {
+               /*
+                * In case the line we're being called with contains more than
+                * one match, leave printing each header to the loop below.
+                */
+               show_line_header(opt, name, lno, cno, sign);
        }
-       if (opt->color) {
+       if (opt->color || opt->only_matching) {
                regmatch_t match;
                enum grep_context ctx = GREP_CONTEXT_BODY;
                int ch = *eol;
                int eflags = 0;
 
-               if (sign == ':')
-                       match_color = opt->colors[GREP_COLOR_MATCH_SELECTED];
-               else
-                       match_color = opt->colors[GREP_COLOR_MATCH_CONTEXT];
-               if (sign == ':')
-                       line_color = opt->colors[GREP_COLOR_SELECTED];
-               else if (sign == '-')
-                       line_color = opt->colors[GREP_COLOR_CONTEXT];
-               else if (sign == '=')
-                       line_color = opt->colors[GREP_COLOR_FUNCTION];
+               if (opt->color) {
+                       if (sign == ':')
+                               match_color = opt->colors[GREP_COLOR_MATCH_SELECTED];
+                       else
+                               match_color = opt->colors[GREP_COLOR_MATCH_CONTEXT];
+                       if (sign == ':')
+                               line_color = opt->colors[GREP_COLOR_SELECTED];
+                       else if (sign == '-')
+                               line_color = opt->colors[GREP_COLOR_CONTEXT];
+                       else if (sign == '=')
+                               line_color = opt->colors[GREP_COLOR_FUNCTION];
+               }
                *eol = '\0';
                while (next_match(opt, bol, eol, ctx, &match, eflags)) {
                        if (match.rm_so == match.rm_eo)
                                break;
 
-                       output_color(opt, bol, match.rm_so, line_color);
+                       if (opt->only_matching)
+                               show_line_header(opt, name, lno, cno, sign);
+                       else
+                               output_color(opt, bol, match.rm_so, line_color);
                        output_color(opt, bol + match.rm_so,
                                     match.rm_eo - match.rm_so, match_color);
+                       if (opt->only_matching)
+                               opt->output(opt, "\n", 1);
                        bol += match.rm_eo;
+                       cno += match.rm_eo;
                        rest -= match.rm_eo;
                        eflags = REG_NOTBOL;
                }
                *eol = ch;
        }
-       output_color(opt, bol, rest, line_color);
-       opt->output(opt, "\n", 1);
+       if (!opt->only_matching) {
+               output_color(opt, bol, rest, line_color);
+               opt->output(opt, "\n", 1);
+       }
 }
 
 #ifndef NO_PTHREADS
@@ -1494,7 +1581,7 @@ static void show_funcname_line(struct grep_opt *opt, struct grep_source *gs,
                        break;
 
                if (match_funcname(opt, gs, bol, eol)) {
-                       show_line(opt, bol, eol, gs->name, lno, '=');
+                       show_line(opt, bol, eol, gs->name, lno, 0, '=');
                        break;
                }
        }
@@ -1559,7 +1646,7 @@ static void show_pre_context(struct grep_opt *opt, struct grep_source *gs,
 
                while (*eol != '\n')
                        eol++;
-               show_line(opt, bol, eol, gs->name, cur, sign);
+               show_line(opt, bol, eol, gs->name, cur, 0, sign);
                bol = eol + 1;
                cur++;
        }
@@ -1758,6 +1845,8 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
        while (left) {
                char *eol, ch;
                int hit;
+               ssize_t cno;
+               ssize_t col = -1, icol = -1;
 
                /*
                 * look_ahead() skips quickly to the line that possibly
@@ -1781,7 +1870,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
                if ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))
                        ctx = GREP_CONTEXT_BODY;
 
-               hit = match_line(opt, bol, eol, ctx, collect_hits);
+               hit = match_line(opt, bol, eol, &col, &icol, ctx, collect_hits);
                *eol = ch;
 
                if (collect_hits)
@@ -1822,7 +1911,18 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
                                show_pre_context(opt, gs, bol, eol, lno);
                        else if (opt->funcname)
                                show_funcname_line(opt, gs, bol, lno);
-                       show_line(opt, bol, eol, gs->name, lno, ':');
+                       cno = opt->invert ? icol : col;
+                       if (cno < 0) {
+                               /*
+                                * A negative cno indicates that there was no
+                                * match on the line. We are thus inverted and
+                                * being asked to show all lines that _don't_
+                                * match a given expression. Therefore, set cno
+                                * to 0 to suggest the whole line matches.
+                                */
+                               cno = 0;
+                       }
+                       show_line(opt, bol, eol, gs->name, lno, cno + 1, ':');
                        last_hit = lno;
                        if (opt->funcbody)
                                show_function = 1;
@@ -1851,7 +1951,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
                        /* If the last hit is within the post context,
                         * we need to show this line.
                         */
-                       show_line(opt, bol, eol, gs->name, lno, '-');
+                       show_line(opt, bol, eol, gs->name, lno, col + 1, '-');
                }
 
        next_line:
diff --git a/grep.h b/grep.h
index ed25be271b5b6a002fdb582fd5c11a499a4f0c94..0ba62a11c5cc2767b15b52aca20a0ea5b00870b8 100644 (file)
--- a/grep.h
+++ b/grep.h
@@ -67,6 +67,7 @@ enum grep_color {
        GREP_COLOR_FILENAME,
        GREP_COLOR_FUNCTION,
        GREP_COLOR_LINENO,
+       GREP_COLOR_COLUMNNO,
        GREP_COLOR_MATCH_CONTEXT,
        GREP_COLOR_MATCH_SELECTED,
        GREP_COLOR_SELECTED,
@@ -139,6 +140,7 @@ struct grep_opt {
        int prefix_length;
        regex_t regexp;
        int linenum;
+       int columnnum;
        int invert;
        int ignore_case;
        int status_only;
@@ -161,6 +163,7 @@ struct grep_opt {
        int relative;
        int pathname;
        int null_following_name;
+       int only_matching;
        int color;
        int max_depth;
        int funcname;
diff --git a/help.c b/help.c
index 3ebf0568dba1f20039b6e4d02c18c652078ad2cb..9c0b5a8de974727e98efc1ad28fd49655290ffd8 100644 (file)
--- a/help.c
+++ b/help.c
@@ -693,6 +693,7 @@ int cmd_version(int argc, const char **argv, const char *prefix)
                else
                        printf("no commit associated with this build\n");
                printf("sizeof-long: %d\n", (int)sizeof(long));
+               printf("sizeof-size_t: %d\n", (int)sizeof(size_t));
                /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
        }
        return 0;
diff --git a/hex.c b/hex.c
index 8df2d63728f0405a9b1dc70aa404954dd921b6bc..10af1a29e80f903fb95cbeb71be00e5fdd705e66 100644 (file)
--- a/hex.c
+++ b/hex.c
@@ -50,7 +50,7 @@ int hex_to_bytes(unsigned char *binary, const char *hex, size_t len)
 int get_sha1_hex(const char *hex, unsigned char *sha1)
 {
        int i;
-       for (i = 0; i < GIT_SHA1_RAWSZ; i++) {
+       for (i = 0; i < the_hash_algo->rawsz; i++) {
                int val = hex2chr(hex);
                if (val < 0)
                        return -1;
@@ -69,7 +69,7 @@ int parse_oid_hex(const char *hex, struct object_id *oid, const char **end)
 {
        int ret = get_oid_hex(hex, oid);
        if (!ret)
-               *end = hex + GIT_SHA1_HEXSZ;
+               *end = hex + the_hash_algo->hexsz;
        return ret;
 }
 
@@ -79,7 +79,7 @@ char *sha1_to_hex_r(char *buffer, const unsigned char *sha1)
        char *buf = buffer;
        int i;
 
-       for (i = 0; i < GIT_SHA1_RAWSZ; i++) {
+       for (i = 0; i < the_hash_algo->rawsz; i++) {
                unsigned int val = *sha1++;
                *buf++ = hex[val >> 4];
                *buf++ = hex[val & 0xf];
index adaef16fadfd03f34b8ac5bb496bd51aab292b20..88c38c834ba479447be8eb64f3bc5331cdb9ed49 100644 (file)
@@ -279,12 +279,18 @@ static struct rpc_service *select_service(struct strbuf *hdr, const char *name)
        return svc;
 }
 
+static void write_to_child(int out, const unsigned char *buf, ssize_t len, const char *prog_name)
+{
+       if (write_in_full(out, buf, len) < 0)
+               die("unable to write to '%s'", prog_name);
+}
+
 /*
  * This is basically strbuf_read(), except that if we
  * hit max_request_buffer we die (we'd rather reject a
  * maliciously large request than chew up infinite memory).
  */
-static ssize_t read_request(int fd, unsigned char **out)
+static ssize_t read_request_eof(int fd, unsigned char **out)
 {
        size_t len = 0, alloc = 8192;
        unsigned char *buf = xmalloc(alloc);
@@ -321,13 +327,54 @@ static ssize_t read_request(int fd, unsigned char **out)
        }
 }
 
-static void inflate_request(const char *prog_name, int out, int buffer_input)
+static ssize_t read_request_fixed_len(int fd, ssize_t req_len, unsigned char **out)
+{
+       unsigned char *buf = NULL;
+       ssize_t cnt = 0;
+
+       if (max_request_buffer < req_len) {
+               die("request was larger than our maximum size (%lu): "
+                   "%" PRIuMAX "; try setting GIT_HTTP_MAX_REQUEST_BUFFER",
+                   max_request_buffer, (uintmax_t)req_len);
+       }
+
+       buf = xmalloc(req_len);
+       cnt = read_in_full(fd, buf, req_len);
+       if (cnt < 0) {
+               free(buf);
+               return -1;
+       }
+       *out = buf;
+       return cnt;
+}
+
+static ssize_t get_content_length(void)
+{
+       ssize_t val = -1;
+       const char *str = getenv("CONTENT_LENGTH");
+
+       if (str && !git_parse_ssize_t(str, &val))
+               die("failed to parse CONTENT_LENGTH: %s", str);
+       return val;
+}
+
+static ssize_t read_request(int fd, unsigned char **out, ssize_t req_len)
+{
+       if (req_len < 0)
+               return read_request_eof(fd, out);
+       else
+               return read_request_fixed_len(fd, req_len, out);
+}
+
+static void inflate_request(const char *prog_name, int out, int buffer_input, ssize_t req_len)
 {
        git_zstream stream;
        unsigned char *full_request = NULL;
        unsigned char in_buf[8192];
        unsigned char out_buf[8192];
        unsigned long cnt = 0;
+       int req_len_defined = req_len >= 0;
+       size_t req_remaining_len = req_len;
 
        memset(&stream, 0, sizeof(stream));
        git_inflate_init_gzip_only(&stream);
@@ -339,11 +386,18 @@ static void inflate_request(const char *prog_name, int out, int buffer_input)
                        if (full_request)
                                n = 0; /* nothing left to read */
                        else
-                               n = read_request(0, &full_request);
+                               n = read_request(0, &full_request, req_len);
                        stream.next_in = full_request;
                } else {
-                       n = xread(0, in_buf, sizeof(in_buf));
+                       ssize_t buffer_len;
+                       if (req_len_defined && req_remaining_len <= sizeof(in_buf))
+                               buffer_len = req_remaining_len;
+                       else
+                               buffer_len = sizeof(in_buf);
+                       n = xread(0, in_buf, buffer_len);
                        stream.next_in = in_buf;
+                       if (req_len_defined && n > 0)
+                               req_remaining_len -= n;
                }
 
                if (n <= 0)
@@ -361,9 +415,8 @@ static void inflate_request(const char *prog_name, int out, int buffer_input)
                                die("zlib error inflating request, result %d", ret);
 
                        n = stream.total_out - cnt;
-                       if (write_in_full(out, out_buf, n) < 0)
-                               die("%s aborted reading request", prog_name);
-                       cnt += n;
+                       write_to_child(out, out_buf, stream.total_out - cnt, prog_name);
+                       cnt = stream.total_out;
 
                        if (ret == Z_STREAM_END)
                                goto done;
@@ -376,18 +429,34 @@ static void inflate_request(const char *prog_name, int out, int buffer_input)
        free(full_request);
 }
 
-static void copy_request(const char *prog_name, int out)
+static void copy_request(const char *prog_name, int out, ssize_t req_len)
 {
        unsigned char *buf;
-       ssize_t n = read_request(0, &buf);
+       ssize_t n = read_request(0, &buf, req_len);
        if (n < 0)
                die_errno("error reading request body");
-       if (write_in_full(out, buf, n) < 0)
-               die("%s aborted reading request", prog_name);
+       write_to_child(out, buf, n, prog_name);
        close(out);
        free(buf);
 }
 
+static void pipe_fixed_length(const char *prog_name, int out, size_t req_len)
+{
+       unsigned char buf[8192];
+       size_t remaining_len = req_len;
+
+       while (remaining_len > 0) {
+               size_t chunk_length = remaining_len > sizeof(buf) ? sizeof(buf) : remaining_len;
+               ssize_t n = xread(0, buf, chunk_length);
+               if (n < 0)
+                       die_errno("Reading request failed");
+               write_to_child(out, buf, n, prog_name);
+               remaining_len -= n;
+       }
+
+       close(out);
+}
+
 static void run_service(const char **argv, int buffer_input)
 {
        const char *encoding = getenv("HTTP_CONTENT_ENCODING");
@@ -395,6 +464,7 @@ static void run_service(const char **argv, int buffer_input)
        const char *host = getenv("REMOTE_ADDR");
        int gzipped_request = 0;
        struct child_process cld = CHILD_PROCESS_INIT;
+       ssize_t req_len = get_content_length();
 
        if (encoding && !strcmp(encoding, "gzip"))
                gzipped_request = 1;
@@ -413,7 +483,7 @@ static void run_service(const char **argv, int buffer_input)
                                 "GIT_COMMITTER_EMAIL=%s@http.%s", user, host);
 
        cld.argv = argv;
-       if (buffer_input || gzipped_request)
+       if (buffer_input || gzipped_request || req_len >= 0)
                cld.in = -1;
        cld.git_cmd = 1;
        if (start_command(&cld))
@@ -421,9 +491,11 @@ static void run_service(const char **argv, int buffer_input)
 
        close(1);
        if (gzipped_request)
-               inflate_request(argv[0], cld.in, buffer_input);
+               inflate_request(argv[0], cld.in, buffer_input, req_len);
        else if (buffer_input)
-               copy_request(argv[0], cld.in);
+               copy_request(argv[0], cld.in, req_len);
+       else if (req_len >= 0)
+               pipe_fixed_length(argv[0], cld.in, req_len);
        else
                close(0);
 
@@ -436,13 +508,13 @@ static int show_text_ref(const char *name, const struct object_id *oid,
 {
        const char *name_nons = strip_namespace(name);
        struct strbuf *buf = cb_data;
-       struct object *o = parse_object(oid);
+       struct object *o = parse_object(the_repository, oid);
        if (!o)
                return 0;
 
        strbuf_addf(buf, "%s\t%s\n", oid_to_hex(oid), name_nons);
        if (o->type == OBJ_TAG) {
-               o = deref_tag(o, name, 0);
+               o = deref_tag(the_repository, o, name, 0);
                if (!o)
                        return 0;
                strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid),
index 7e38522098bf91c144adaee7f9f5476f8bc72cd2..5eaf551b51e7aaf87219d4af0ca19873484c90ca 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "repository.h"
 #include "commit.h"
 #include "tag.h"
 #include "blob.h"
@@ -14,6 +15,7 @@
 #include "packfile.h"
 #include "object-store.h"
 
+
 #ifdef EXPAT_NEEDS_XMLPARSE_H
 #include <xmlparse.h>
 #else
@@ -720,9 +722,9 @@ static void one_remote_object(const struct object_id *oid)
 {
        struct object *obj;
 
-       obj = lookup_object(oid->hash);
+       obj = lookup_object(the_repository, oid->hash);
        if (!obj)
-               obj = parse_object(oid);
+               obj = parse_object(the_repository, oid);
 
        /* Ignore remote objects that don't exist locally */
        if (!obj)
@@ -1309,10 +1311,12 @@ 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(entry.oid), p);
+                       p = process_tree(lookup_tree(the_repository, entry.oid),
+                                        p);
                        break;
                case OBJ_BLOB:
-                       p = process_blob(lookup_blob(entry.oid), p);
+                       p = process_blob(lookup_blob(the_repository, entry.oid),
+                                        p);
                        break;
                default:
                        /* Subproject commit - not in this repository */
@@ -1459,7 +1463,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
                return;
        }
 
-       o = parse_object(&ref->old_oid);
+       o = parse_object(the_repository, &ref->old_oid);
        if (!o) {
                fprintf(stderr,
                        "Unable to parse object %s for remote ref %s\n",
@@ -1473,7 +1477,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
                    oid_to_hex(&ref->old_oid), ls->dentry_name);
 
        if (o->type == OBJ_TAG) {
-               o = deref_tag(o, ls->dentry_name, 0);
+               o = deref_tag(the_repository, o, ls->dentry_name, 0);
                if (o)
                        strbuf_addf(buf, "%s\t%s^{}\n",
                                    oid_to_hex(&o->oid), ls->dentry_name);
diff --git a/json-writer.c b/json-writer.c
new file mode 100644 (file)
index 0000000..aadb9db
--- /dev/null
@@ -0,0 +1,414 @@
+#include "cache.h"
+#include "json-writer.h"
+
+void jw_init(struct json_writer *jw)
+{
+       strbuf_init(&jw->json, 0);
+       strbuf_init(&jw->open_stack, 0);
+       jw->need_comma = 0;
+       jw->pretty = 0;
+}
+
+void jw_release(struct json_writer *jw)
+{
+       strbuf_release(&jw->json);
+       strbuf_release(&jw->open_stack);
+}
+
+/*
+ * Append JSON-quoted version of the given string to 'out'.
+ */
+static void append_quoted_string(struct strbuf *out, const char *in)
+{
+       unsigned char c;
+
+       strbuf_addch(out, '"');
+       while ((c = *in++) != '\0') {
+               if (c == '"')
+                       strbuf_addstr(out, "\\\"");
+               else if (c == '\\')
+                       strbuf_addstr(out, "\\\\");
+               else if (c == '\n')
+                       strbuf_addstr(out, "\\n");
+               else if (c == '\r')
+                       strbuf_addstr(out, "\\r");
+               else if (c == '\t')
+                       strbuf_addstr(out, "\\t");
+               else if (c == '\f')
+                       strbuf_addstr(out, "\\f");
+               else if (c == '\b')
+                       strbuf_addstr(out, "\\b");
+               else if (c < 0x20)
+                       strbuf_addf(out, "\\u%04x", c);
+               else
+                       strbuf_addch(out, c);
+       }
+       strbuf_addch(out, '"');
+}
+
+static void indent_pretty(struct json_writer *jw)
+{
+       int k;
+
+       for (k = 0; k < jw->open_stack.len; k++)
+               strbuf_addstr(&jw->json, "  ");
+}
+
+/*
+ * Begin an object or array (either top-level or nested within the currently
+ * open object or array).
+ */
+static void begin(struct json_writer *jw, char ch_open, int pretty)
+{
+       jw->pretty = pretty;
+
+       strbuf_addch(&jw->json, ch_open);
+
+       strbuf_addch(&jw->open_stack, ch_open);
+       jw->need_comma = 0;
+}
+
+/*
+ * Assert that the top of the open-stack is an object.
+ */
+static void assert_in_object(const struct json_writer *jw, const char *key)
+{
+       if (!jw->open_stack.len)
+               BUG("json-writer: object: missing jw_object_begin(): '%s'", key);
+       if (jw->open_stack.buf[jw->open_stack.len - 1] != '{')
+               BUG("json-writer: object: not in object: '%s'", key);
+}
+
+/*
+ * Assert that the top of the open-stack is an array.
+ */
+static void assert_in_array(const struct json_writer *jw)
+{
+       if (!jw->open_stack.len)
+               BUG("json-writer: array: missing jw_array_begin()");
+       if (jw->open_stack.buf[jw->open_stack.len - 1] != '[')
+               BUG("json-writer: array: not in array");
+}
+
+/*
+ * Add comma if we have already seen a member at this level.
+ */
+static void maybe_add_comma(struct json_writer *jw)
+{
+       if (jw->need_comma)
+               strbuf_addch(&jw->json, ',');
+       else
+               jw->need_comma = 1;
+}
+
+static void fmt_double(struct json_writer *jw, int precision,
+                             double value)
+{
+       if (precision < 0) {
+               strbuf_addf(&jw->json, "%f", value);
+       } else {
+               struct strbuf fmt = STRBUF_INIT;
+               strbuf_addf(&fmt, "%%.%df", precision);
+               strbuf_addf(&jw->json, fmt.buf, value);
+               strbuf_release(&fmt);
+       }
+}
+
+static void object_common(struct json_writer *jw, const char *key)
+{
+       assert_in_object(jw, key);
+       maybe_add_comma(jw);
+
+       if (jw->pretty) {
+               strbuf_addch(&jw->json, '\n');
+               indent_pretty(jw);
+       }
+
+       append_quoted_string(&jw->json, key);
+       strbuf_addch(&jw->json, ':');
+       if (jw->pretty)
+               strbuf_addch(&jw->json, ' ');
+}
+
+static void array_common(struct json_writer *jw)
+{
+       assert_in_array(jw);
+       maybe_add_comma(jw);
+
+       if (jw->pretty) {
+               strbuf_addch(&jw->json, '\n');
+               indent_pretty(jw);
+       }
+}
+
+/*
+ * Assert that the given JSON object or JSON array has been properly
+ * terminated.  (Has closing bracket.)
+ */
+static void assert_is_terminated(const struct json_writer *jw)
+{
+       if (jw->open_stack.len)
+               BUG("json-writer: object: missing jw_end(): '%s'",
+                   jw->json.buf);
+}
+
+void jw_object_begin(struct json_writer *jw, int pretty)
+{
+       begin(jw, '{', pretty);
+}
+
+void jw_object_string(struct json_writer *jw, const char *key, const char *value)
+{
+       object_common(jw, key);
+       append_quoted_string(&jw->json, value);
+}
+
+void jw_object_intmax(struct json_writer *jw, const char *key, intmax_t value)
+{
+       object_common(jw, key);
+       strbuf_addf(&jw->json, "%"PRIdMAX, value);
+}
+
+void jw_object_double(struct json_writer *jw, const char *key, int precision,
+                     double value)
+{
+       object_common(jw, key);
+       fmt_double(jw, precision, value);
+}
+
+void jw_object_true(struct json_writer *jw, const char *key)
+{
+       object_common(jw, key);
+       strbuf_addstr(&jw->json, "true");
+}
+
+void jw_object_false(struct json_writer *jw, const char *key)
+{
+       object_common(jw, key);
+       strbuf_addstr(&jw->json, "false");
+}
+
+void jw_object_bool(struct json_writer *jw, const char *key, int value)
+{
+       if (value)
+               jw_object_true(jw, key);
+       else
+               jw_object_false(jw, key);
+}
+
+void jw_object_null(struct json_writer *jw, const char *key)
+{
+       object_common(jw, key);
+       strbuf_addstr(&jw->json, "null");
+}
+
+static void increase_indent(struct strbuf *sb,
+                           const struct json_writer *jw,
+                           int indent)
+{
+       int k;
+
+       strbuf_reset(sb);
+       for (k = 0; k < jw->json.len; k++) {
+               char ch = jw->json.buf[k];
+               strbuf_addch(sb, ch);
+               if (ch == '\n')
+                       strbuf_addchars(sb, ' ', indent);
+       }
+}
+
+static void kill_indent(struct strbuf *sb,
+                       const struct json_writer *jw)
+{
+       int k;
+       int eat_it = 0;
+
+       strbuf_reset(sb);
+       for (k = 0; k < jw->json.len; k++) {
+               char ch = jw->json.buf[k];
+               if (eat_it && ch == ' ')
+                       continue;
+               if (ch == '\n') {
+                       eat_it = 1;
+                       continue;
+               }
+               eat_it = 0;
+               strbuf_addch(sb, ch);
+       }
+}
+
+static void append_sub_jw(struct json_writer *jw,
+                         const struct json_writer *value)
+{
+       /*
+        * If both are pretty, increase the indentation of the sub_jw
+        * to better fit under the super.
+        *
+        * If the super is pretty, but the sub_jw is compact, leave the
+        * sub_jw compact.  (We don't want to parse and rebuild the sub_jw
+        * for this debug-ish feature.)
+        *
+        * If the super is compact, and the sub_jw is pretty, convert
+        * the sub_jw to compact.
+        *
+        * If both are compact, keep the sub_jw compact.
+        */
+       if (jw->pretty && jw->open_stack.len && value->pretty) {
+               struct strbuf sb = STRBUF_INIT;
+               increase_indent(&sb, value, jw->open_stack.len * 2);
+               strbuf_addbuf(&jw->json, &sb);
+               strbuf_release(&sb);
+               return;
+       }
+       if (!jw->pretty && value->pretty) {
+               struct strbuf sb = STRBUF_INIT;
+               kill_indent(&sb, value);
+               strbuf_addbuf(&jw->json, &sb);
+               strbuf_release(&sb);
+               return;
+       }
+
+       strbuf_addbuf(&jw->json, &value->json);
+}
+
+/*
+ * Append existing (properly terminated) JSON sub-data (object or array)
+ * as-is onto the given JSON data.
+ */
+void jw_object_sub_jw(struct json_writer *jw, const char *key,
+                     const struct json_writer *value)
+{
+       assert_is_terminated(value);
+
+       object_common(jw, key);
+       append_sub_jw(jw, value);
+}
+
+void jw_object_inline_begin_object(struct json_writer *jw, const char *key)
+{
+       object_common(jw, key);
+
+       jw_object_begin(jw, jw->pretty);
+}
+
+void jw_object_inline_begin_array(struct json_writer *jw, const char *key)
+{
+       object_common(jw, key);
+
+       jw_array_begin(jw, jw->pretty);
+}
+
+void jw_array_begin(struct json_writer *jw, int pretty)
+{
+       begin(jw, '[', pretty);
+}
+
+void jw_array_string(struct json_writer *jw, const char *value)
+{
+       array_common(jw);
+       append_quoted_string(&jw->json, value);
+}
+
+void jw_array_intmax(struct json_writer *jw, intmax_t value)
+{
+       array_common(jw);
+       strbuf_addf(&jw->json, "%"PRIdMAX, value);
+}
+
+void jw_array_double(struct json_writer *jw, int precision, double value)
+{
+       array_common(jw);
+       fmt_double(jw, precision, value);
+}
+
+void jw_array_true(struct json_writer *jw)
+{
+       array_common(jw);
+       strbuf_addstr(&jw->json, "true");
+}
+
+void jw_array_false(struct json_writer *jw)
+{
+       array_common(jw);
+       strbuf_addstr(&jw->json, "false");
+}
+
+void jw_array_bool(struct json_writer *jw, int value)
+{
+       if (value)
+               jw_array_true(jw);
+       else
+               jw_array_false(jw);
+}
+
+void jw_array_null(struct json_writer *jw)
+{
+       array_common(jw);
+       strbuf_addstr(&jw->json, "null");
+}
+
+void jw_array_sub_jw(struct json_writer *jw, const struct json_writer *value)
+{
+       assert_is_terminated(value);
+
+       array_common(jw);
+       append_sub_jw(jw, value);
+}
+
+void jw_array_argc_argv(struct json_writer *jw, int argc, const char **argv)
+{
+       int k;
+
+       for (k = 0; k < argc; k++)
+               jw_array_string(jw, argv[k]);
+}
+
+void jw_array_argv(struct json_writer *jw, const char **argv)
+{
+       while (*argv)
+               jw_array_string(jw, *argv++);
+}
+
+void jw_array_inline_begin_object(struct json_writer *jw)
+{
+       array_common(jw);
+
+       jw_object_begin(jw, jw->pretty);
+}
+
+void jw_array_inline_begin_array(struct json_writer *jw)
+{
+       array_common(jw);
+
+       jw_array_begin(jw, jw->pretty);
+}
+
+int jw_is_terminated(const struct json_writer *jw)
+{
+       return !jw->open_stack.len;
+}
+
+void jw_end(struct json_writer *jw)
+{
+       char ch_open;
+       int len;
+
+       if (!jw->open_stack.len)
+               BUG("json-writer: too many jw_end(): '%s'", jw->json.buf);
+
+       len = jw->open_stack.len - 1;
+       ch_open = jw->open_stack.buf[len];
+
+       strbuf_setlen(&jw->open_stack, len);
+       jw->need_comma = 1;
+
+       if (jw->pretty) {
+               strbuf_addch(&jw->json, '\n');
+               indent_pretty(jw);
+       }
+
+       if (ch_open == '{')
+               strbuf_addch(&jw->json, '}');
+       else
+               strbuf_addch(&jw->json, ']');
+}
diff --git a/json-writer.h b/json-writer.h
new file mode 100644 (file)
index 0000000..fc18acc
--- /dev/null
@@ -0,0 +1,105 @@
+#ifndef JSON_WRITER_H
+#define JSON_WRITER_H
+
+/*
+ * JSON data structures are defined at:
+ * [1] http://www.ietf.org/rfc/rfc7159.txt
+ * [2] http://json.org/
+ *
+ * The JSON-writer API allows one to build JSON data structures using a
+ * simple wrapper around a "struct strbuf" buffer.  It is intended as a
+ * simple API to build output strings; it is not intended to be a general
+ * object model for JSON data.  In particular, it does not re-order keys
+ * in an object (dictionary), it does not de-dup keys in an object, and
+ * it does not allow lookup or parsing of JSON data.
+ *
+ * All string values (both keys and string r-values) are properly quoted
+ * and escaped if they contain special characters.
+ *
+ * These routines create compact JSON data (with no unnecessary whitespace,
+ * newlines, or indenting).  If you get an unexpected response, verify
+ * that you're not expecting a pretty JSON string.
+ *
+ * Both "JSON objects" (aka sets of k/v pairs) and "JSON array" can be
+ * constructed using a 'begin append* end' model.
+ *
+ * Nested objects and arrays can either be constructed bottom up (by
+ * creating sub object/arrays first and appending them to the super
+ * object/array) -or- by building them inline in one pass.  This is a
+ * personal style and/or data shape choice.
+ *
+ * See t/helper/test-json-writer.c for various usage examples.
+ *
+ * LIMITATIONS:
+ * ============
+ *
+ * The JSON specification [1,2] defines string values as Unicode data
+ * and probably UTF-8 encoded.  The current json-writer API does not
+ * enforce this and will write any string as received.  However, it will
+ * properly quote and backslash-escape them as necessary.  It is up to
+ * the caller to UTF-8 encode their strings *before* passing them to this
+ * API.  This layer should not have to try to guess the encoding or locale
+ * of the given strings.
+ */
+
+struct json_writer
+{
+       /*
+        * Buffer of the in-progress JSON currently being composed.
+        */
+       struct strbuf json;
+
+       /*
+        * Simple stack of the currently open array and object forms.
+        * This is a string of '{' and '[' characters indicating the
+        * currently unterminated forms.  This is used to ensure the
+        * properly closing character is used when popping a level and
+        * to know when the JSON is completely closed.
+        */
+       struct strbuf open_stack;
+
+       unsigned int need_comma:1;
+       unsigned int pretty:1;
+};
+
+#define JSON_WRITER_INIT { STRBUF_INIT, STRBUF_INIT, 0, 0 }
+
+void jw_init(struct json_writer *jw);
+void jw_release(struct json_writer *jw);
+
+void jw_object_begin(struct json_writer *jw, int pretty);
+void jw_array_begin(struct json_writer *jw, int pretty);
+
+void jw_object_string(struct json_writer *jw, const char *key,
+                     const char *value);
+void jw_object_intmax(struct json_writer *jw, const char *key, intmax_t value);
+void jw_object_double(struct json_writer *jw, const char *key, int precision,
+                     double value);
+void jw_object_true(struct json_writer *jw, const char *key);
+void jw_object_false(struct json_writer *jw, const char *key);
+void jw_object_bool(struct json_writer *jw, const char *key, int value);
+void jw_object_null(struct json_writer *jw, const char *key);
+void jw_object_sub_jw(struct json_writer *jw, const char *key,
+                     const struct json_writer *value);
+
+void jw_object_inline_begin_object(struct json_writer *jw, const char *key);
+void jw_object_inline_begin_array(struct json_writer *jw, const char *key);
+
+void jw_array_string(struct json_writer *jw, const char *value);
+void jw_array_intmax(struct json_writer *jw, intmax_t value);
+void jw_array_double(struct json_writer *jw, int precision, double value);
+void jw_array_true(struct json_writer *jw);
+void jw_array_false(struct json_writer *jw);
+void jw_array_bool(struct json_writer *jw, int value);
+void jw_array_null(struct json_writer *jw);
+void jw_array_sub_jw(struct json_writer *jw, const struct json_writer *value);
+void jw_array_argc_argv(struct json_writer *jw, int argc, const char **argv);
+void jw_array_argv(struct json_writer *jw, const char **argv);
+
+void jw_array_inline_begin_object(struct json_writer *jw);
+void jw_array_inline_begin_array(struct json_writer *jw);
+
+int jw_is_terminated(const struct json_writer *jw);
+void jw_end(struct json_writer *jw);
+
+#endif /* JSON_WRITER_H */
index fa9cfd5bdbb5dfe4a1ca5c7f7711435caf091805..72a5fed661ca0a0f0eb1fe726e91acc8cd47512a 100644 (file)
@@ -479,7 +479,7 @@ static struct commit *check_single_commit(struct rev_info *revs)
                struct object *obj = revs->pending.objects[i].item;
                if (obj->flags & UNINTERESTING)
                        continue;
-               obj = deref_tag(obj, NULL, 0);
+               obj = deref_tag(the_repository, obj, NULL, 0);
                if (obj->type != OBJ_COMMIT)
                        die("Non commit %s?", revs->pending.objects[i].name);
                if (commit)
@@ -598,11 +598,11 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
                                    lines, anchor, &begin, &end,
                                    full_name))
                        die("malformed -L argument '%s'", range_part);
-               if (lines < end || ((lines || begin) && lines < begin))
+               if ((!lines && (begin || end)) || lines < begin)
                        die("file %s has only %lu lines", name_part, lines);
                if (begin < 1)
                        begin = 1;
-               if (end < 1)
+               if (end < 1 || lines < end)
                        end = lines;
                begin--;
                line_log_data_insert(&ranges, full_name, begin, end);
index 323399d16cfa828adce913c9ff994e860ce2e7a5..232c3909ec27d3079e9228d0fcf561ce6a349754 100644 (file)
@@ -47,7 +47,7 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,
                        else if (!num)
                                *ret = begin;
                        else
-                               *ret = begin + num;
+                               *ret = begin + num > 0 ? begin + num : 1;
                        return term;
                }
                return spec;
index 83ba3c25e88a4601dc17ce01dc57dfbc33c05b2e..d3c54e45aa8a8e488778bbc7db1c6a5c0f602ab2 100644 (file)
 
 typedef const char *(*nth_line_fn_t)(void *data, long lno);
 
-extern int parse_range_arg(const char *arg,
-                          nth_line_fn_t nth_line_cb,
-                          void *cb_data, long lines, long anchor,
-                          long *begin, long *end,
-                          const char *path);
+int parse_range_arg(const char *arg,
+                   nth_line_fn_t nth_line_cb,
+                   void *cb_data, long lines, long anchor,
+                   long *begin, long *end,
+                   const char *path);
 
 /*
  * Scan past a range argument that could be parsed by
@@ -34,6 +34,6 @@ extern int parse_range_arg(const char *arg,
  * NULL in case the argument is obviously malformed.
  */
 
-extern const char *skip_range_arg(const char *arg);
+const char *skip_range_arg(const char *arg);
 
 #endif /* LINE_RANGE_H */
diff --git a/linear-assignment.c b/linear-assignment.c
new file mode 100644 (file)
index 0000000..9b3e56e
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * Based on: Jonker, R., & Volgenant, A. (1987). <i>A shortest augmenting path
+ * algorithm for dense and sparse linear assignment problems</i>. Computing,
+ * 38(4), 325-340.
+ */
+#include "cache.h"
+#include "linear-assignment.h"
+
+#define COST(column, row) cost[(column) + column_count * (row)]
+
+/*
+ * The parameter `cost` is the cost matrix: the cost to assign column j to row
+ * i is `cost[j + column_count * i].
+ */
+void compute_assignment(int column_count, int row_count, int *cost,
+                       int *column2row, int *row2column)
+{
+       int *v, *d;
+       int *free_row, free_count = 0, saved_free_count, *pred, *col;
+       int i, j, phase;
+
+       memset(column2row, -1, sizeof(int) * column_count);
+       memset(row2column, -1, sizeof(int) * row_count);
+       ALLOC_ARRAY(v, column_count);
+
+       /* column reduction */
+       for (j = column_count - 1; j >= 0; j--) {
+               int i1 = 0;
+
+               for (i = 1; i < row_count; i++)
+                       if (COST(j, i1) > COST(j, i))
+                               i1 = i;
+               v[j] = COST(j, i1);
+               if (row2column[i1] == -1) {
+                       /* row i1 unassigned */
+                       row2column[i1] = j;
+                       column2row[j] = i1;
+               } else {
+                       if (row2column[i1] >= 0)
+                               row2column[i1] = -2 - row2column[i1];
+                       column2row[j] = -1;
+               }
+       }
+
+       /* reduction transfer */
+       ALLOC_ARRAY(free_row, row_count);
+       for (i = 0; i < row_count; i++) {
+               int j1 = row2column[i];
+               if (j1 == -1)
+                       free_row[free_count++] = i;
+               else if (j1 < -1)
+                       row2column[i] = -2 - j1;
+               else {
+                       int min = COST(!j1, i) - v[!j1];
+                       for (j = 1; j < column_count; j++)
+                               if (j != j1 && min > COST(j, i) - v[j])
+                                       min = COST(j, i) - v[j];
+                       v[j1] -= min;
+               }
+       }
+
+       if (free_count ==
+           (column_count < row_count ? row_count - column_count : 0)) {
+               free(v);
+               free(free_row);
+               return;
+       }
+
+       /* augmenting row reduction */
+       for (phase = 0; phase < 2; phase++) {
+               int k = 0;
+
+               saved_free_count = free_count;
+               free_count = 0;
+               while (k < saved_free_count) {
+                       int u1, u2;
+                       int j1 = 0, j2, i0;
+
+                       i = free_row[k++];
+                       u1 = COST(j1, i) - v[j1];
+                       j2 = -1;
+                       u2 = INT_MAX;
+                       for (j = 1; j < column_count; j++) {
+                               int c = COST(j, i) - v[j];
+                               if (u2 > c) {
+                                       if (u1 < c) {
+                                               u2 = c;
+                                               j2 = j;
+                                       } else {
+                                               u2 = u1;
+                                               u1 = c;
+                                               j2 = j1;
+                                               j1 = j;
+                                       }
+                               }
+                       }
+                       if (j2 < 0) {
+                               j2 = j1;
+                               u2 = u1;
+                       }
+
+                       i0 = column2row[j1];
+                       if (u1 < u2)
+                               v[j1] -= u2 - u1;
+                       else if (i0 >= 0) {
+                               j1 = j2;
+                               i0 = column2row[j1];
+                       }
+
+                       if (i0 >= 0) {
+                               if (u1 < u2)
+                                       free_row[--k] = i0;
+                               else
+                                       free_row[free_count++] = i0;
+                       }
+                       row2column[i] = j1;
+                       column2row[j1] = i;
+               }
+       }
+
+       /* augmentation */
+       saved_free_count = free_count;
+       ALLOC_ARRAY(d, column_count);
+       ALLOC_ARRAY(pred, column_count);
+       ALLOC_ARRAY(col, column_count);
+       for (free_count = 0; free_count < saved_free_count; free_count++) {
+               int i1 = free_row[free_count], low = 0, up = 0, last, k;
+               int min, c, u1;
+
+               for (j = 0; j < column_count; j++) {
+                       d[j] = COST(j, i1) - v[j];
+                       pred[j] = i1;
+                       col[j] = j;
+               }
+
+               j = -1;
+               do {
+                       last = low;
+                       min = d[col[up++]];
+                       for (k = up; k < column_count; k++) {
+                               j = col[k];
+                               c = d[j];
+                               if (c <= min) {
+                                       if (c < min) {
+                                               up = low;
+                                               min = c;
+                                       }
+                                       col[k] = col[up];
+                                       col[up++] = j;
+                               }
+                       }
+                       for (k = low; k < up; k++)
+                               if (column2row[col[k]] == -1)
+                                       goto update;
+
+                       /* scan a row */
+                       do {
+                               int j1 = col[low++];
+
+                               i = column2row[j1];
+                               u1 = COST(j1, i) - v[j1] - min;
+                               for (k = up; k < column_count; k++) {
+                                       j = col[k];
+                                       c = COST(j, i) - v[j] - u1;
+                                       if (c < d[j]) {
+                                               d[j] = c;
+                                               pred[j] = i;
+                                               if (c == min) {
+                                                       if (column2row[j] == -1)
+                                                               goto update;
+                                                       col[k] = col[up];
+                                                       col[up++] = j;
+                                               }
+                                       }
+                               }
+                       } while (low != up);
+               } while (low == up);
+
+update:
+               /* updating of the column pieces */
+               for (k = 0; k < last; k++) {
+                       int j1 = col[k];
+                       v[j1] += d[j1] - min;
+               }
+
+               /* augmentation */
+               do {
+                       if (j < 0)
+                               BUG("negative j: %d", j);
+                       i = pred[j];
+                       column2row[j] = i;
+                       SWAP(j, row2column[i]);
+               } while (i1 != i);
+       }
+
+       free(col);
+       free(pred);
+       free(d);
+       free(v);
+       free(free_row);
+}
diff --git a/linear-assignment.h b/linear-assignment.h
new file mode 100644 (file)
index 0000000..1dfea76
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef LINEAR_ASSIGNMENT_H
+#define LINEAR_ASSIGNMENT_H
+
+/*
+ * Compute an assignment of columns -> rows (and vice versa) such that every
+ * column is assigned to at most one row (and vice versa) minimizing the
+ * overall cost.
+ *
+ * The parameter `cost` is the cost matrix: the cost to assign column j to row
+ * i is `cost[j + column_count * i].
+ *
+ * The arrays column2row and row2column will be populated with the respective
+ * assignments (-1 for unassigned, which can happen only if column_count !=
+ * row_count).
+ */
+void compute_assignment(int column_count, int row_count, int *cost,
+                       int *column2row, int *row2column);
+
+/* The maximal cost in the cost matrix (to prevent integer overflows). */
+#define COST_MAX (1<<16)
+
+#endif
index 5b14d2711ad3791169f5d8cbc03836b4254bd55c..a0ba78b20cc99bfcd2c41abd4f312b5649a2b9cd 100644 (file)
@@ -11,6 +11,7 @@
 #include "list-objects-filter.h"
 #include "list-objects-filter-options.h"
 #include "oidset.h"
+#include "object-store.h"
 
 /* Remember to update object flag allocation in object.h */
 /*
index 3eec510357337f5e33eea08a05faa22373d98c07..c99c47ac181612db5122a313557090e1957fea4f 100644 (file)
@@ -10,6 +10,7 @@
 #include "list-objects-filter.h"
 #include "list-objects-filter-options.h"
 #include "packfile.h"
+#include "object-store.h"
 
 static void process_blob(struct rev_info *revs,
                         struct blob *blob,
@@ -47,7 +48,7 @@ static void process_blob(struct rev_info *revs,
 
        pathlen = path->len;
        strbuf_addstr(path, name);
-       if (filter_fn)
+       if (!(obj->flags & USER_GIVEN) && filter_fn)
                r = filter_fn(LOFS_BLOB, obj,
                              path->buf, &path->buf[pathlen],
                              filter_data);
@@ -132,7 +133,7 @@ static void process_tree(struct rev_info *revs,
        }
 
        strbuf_addstr(base, name);
-       if (filter_fn)
+       if (!(obj->flags & USER_GIVEN) && filter_fn)
                r = filter_fn(LOFS_BEGIN_TREE, obj,
                              base->buf, &base->buf[baselen],
                              filter_data);
@@ -157,7 +158,7 @@ static void process_tree(struct rev_info *revs,
 
                if (S_ISDIR(entry.mode))
                        process_tree(revs,
-                                    lookup_tree(entry.oid),
+                                    lookup_tree(the_repository, entry.oid),
                                     show, base, entry.path,
                                     cb_data, filter_fn, filter_data);
                else if (S_ISGITLINK(entry.mode))
@@ -166,12 +167,12 @@ static void process_tree(struct rev_info *revs,
                                        cb_data);
                else
                        process_blob(revs,
-                                    lookup_blob(entry.oid),
+                                    lookup_blob(the_repository, entry.oid),
                                     show, base, entry.path,
                                     cb_data, filter_fn, filter_data);
        }
 
-       if (filter_fn) {
+       if (!(obj->flags & USER_GIVEN) && filter_fn) {
                r = filter_fn(LOFS_END_TREE, obj,
                              base->buf, &base->buf[baselen],
                              filter_data);
index a6ad2ec12dc9c1ece81f120196c81fd259e40eb6..0e2800f7bb46bdf9e1713d210a5dc1c02fbbaa26 100644 (file)
@@ -371,7 +371,7 @@ int ll_merge(mmbuffer_t *result_buf,
        if (!check)
                check = attr_check_initl("merge", "conflict-marker-size", NULL);
 
-       if (!git_check_attr(path, check)) {
+       if (!git_check_attr(&the_index, path, check)) {
                ll_driver_name = check->items[0].value;
                if (check->items[1].value) {
                        marker_size = atoi(check->items[1].value);
@@ -398,7 +398,7 @@ int ll_merge_marker_size(const char *path)
 
        if (!check)
                check = attr_check_initl("conflict-marker-size", NULL);
-       if (!git_check_attr(path, check) && check->items[0].value) {
+       if (!git_check_attr(&the_index, path, check) && check->items[0].value) {
                marker_size = atoi(check->items[0].value);
                if (marker_size <= 0)
                        marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
index d3a43e29cd50e0afb015f1a5efdb82fd195d9c93..7443e5fcc74b7964c478327c6557d53eb4f6b425 100644 (file)
@@ -1,6 +1,8 @@
 #include "cache.h"
 #include "config.h"
 #include "diff.h"
+#include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "tag.h"
 #include "graph.h"
@@ -90,20 +92,20 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
 
        if (starts_with(refname, git_replace_ref_base)) {
                struct object_id original_oid;
-               if (!check_replace_refs)
+               if (!read_replace_refs)
                        return 0;
                if (get_oid_hex(refname + strlen(git_replace_ref_base),
                                &original_oid)) {
                        warning("invalid replace ref %s", refname);
                        return 0;
                }
-               obj = parse_object(&original_oid);
+               obj = parse_object(the_repository, &original_oid);
                if (obj)
                        add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
                return 0;
        }
 
-       obj = parse_object(oid);
+       obj = parse_object(the_repository, oid);
        if (!obj)
                return 0;
 
@@ -124,7 +126,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
                if (!obj)
                        break;
                if (!obj->parsed)
-                       parse_object(&obj->oid);
+                       parse_object(the_repository, &obj->oid);
                add_name_decoration(DECORATION_REF_TAG, refname, obj);
        }
        return 0;
@@ -132,7 +134,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
 
 static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
 {
-       struct commit *commit = lookup_commit(&graft->oid);
+       struct commit *commit = lookup_commit(the_repository, &graft->oid);
        if (!commit)
                return 0;
        add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
@@ -496,12 +498,12 @@ static int show_one_mergetag(struct commit *commit,
        size_t payload_size, gpg_message_offset;
 
        hash_object_file(extra->value, extra->len, type_name(OBJ_TAG), &oid);
-       tag = lookup_tag(&oid);
+       tag = lookup_tag(the_repository, &oid);
        if (!tag)
                return -1; /* error message already given */
 
        strbuf_init(&verify_message, 256);
-       if (parse_tag_buffer(tag, extra->value, extra->len))
+       if (parse_tag_buffer(the_repository, tag, extra->value, extra->len))
                strbuf_addstr(&verify_message, "malformed mergetag\n");
        else if (is_common_merge(commit) &&
                 !oidcmp(&tag->tagged->oid,
@@ -545,7 +547,7 @@ void show_log(struct rev_info *opt)
        struct strbuf msgbuf = STRBUF_INIT;
        struct log_info *log = opt->loginfo;
        struct commit *commit = log->commit, *parent = log->parent;
-       int abbrev_commit = opt->abbrev_commit ? opt->abbrev : GIT_SHA1_HEXSZ;
+       int abbrev_commit = opt->abbrev_commit ? opt->abbrev : the_hash_algo->hexsz;
        const char *extra_headers = opt->extra_headers;
        struct pretty_print_context ctx = {0};
 
index 13f0d2884e25edef3fde5bdf72b89a770111e472..962fd86d6d7067e84bc0dbf499cc0c47b6ad3c11 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "string-list.h"
 #include "mailmap.h"
+#include "object-store.h"
 
 #define DEBUG_MAILMAP 0
 #if DEBUG_MAILMAP
index 72cc2baa3f96b2cbfa296335c7f0ff1094b6e96c..37653308d3601e56191d2f83f967cc77ad1517af 100644 (file)
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "tree.h"
 #include "tree-walk.h"
+#include "object-store.h"
 
 static int score_missing(unsigned mode, const char *path)
 {
@@ -82,34 +83,43 @@ static int score_trees(const struct object_id *hash1, const struct object_id *ha
        int score = 0;
 
        for (;;) {
-               struct name_entry e1, e2;
-               int got_entry_from_one = tree_entry(&one, &e1);
-               int got_entry_from_two = tree_entry(&two, &e2);
                int cmp;
 
-               if (got_entry_from_one && got_entry_from_two)
-                       cmp = base_name_entries_compare(&e1, &e2);
-               else if (got_entry_from_one)
+               if (one.size && two.size)
+                       cmp = base_name_entries_compare(&one.entry, &two.entry);
+               else if (one.size)
                        /* two lacks this entry */
                        cmp = -1;
-               else if (got_entry_from_two)
+               else if (two.size)
                        /* two has more entries */
                        cmp = 1;
                else
                        break;
 
-               if (cmp < 0)
+               if (cmp < 0) {
                        /* path1 does not appear in two */
-                       score += score_missing(e1.mode, e1.path);
-               else if (cmp > 0)
+                       score += score_missing(one.entry.mode, one.entry.path);
+                       update_tree_entry(&one);
+               } else if (cmp > 0) {
                        /* path2 does not appear in one */
-                       score += score_missing(e2.mode, e2.path);
-               else if (oidcmp(e1.oid, e2.oid))
-                       /* they are different */
-                       score += score_differs(e1.mode, e2.mode, e1.path);
-               else
-                       /* same subtree or blob */
-                       score += score_matches(e1.mode, e2.mode, e1.path);
+                       score += score_missing(two.entry.mode, two.entry.path);
+                       update_tree_entry(&two);
+               } else {
+                       /* path appears in both */
+                       if (oidcmp(one.entry.oid, two.entry.oid)) {
+                               /* they are different */
+                               score += score_differs(one.entry.mode,
+                                                      two.entry.mode,
+                                                      one.entry.path);
+                       } else {
+                               /* same subtree or blob */
+                               score += score_matches(one.entry.mode,
+                                                      two.entry.mode,
+                                                      one.entry.path);
+                       }
+                       update_tree_entry(&one);
+                       update_tree_entry(&two);
+               }
        }
        free(one_buf);
        free(two_buf);
index 389d7af447036ef58e64d2041a8c6743a862817a..a2841a4a9ad7e4871282031f1b18fd62f18e9638 100644 (file)
@@ -5,40 +5,88 @@
 #include "cache.h"
 #include "mem-pool.h"
 
-static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_pool, size_t block_alloc)
+#define BLOCK_GROWTH_SIZE 1024*1024 - sizeof(struct mp_block);
+
+/*
+ * Allocate a new mp_block and insert it after the block specified in
+ * `insert_after`. If `insert_after` is NULL, then insert block at the
+ * head of the linked list.
+ */
+static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_pool, size_t block_alloc, struct mp_block *insert_after)
 {
        struct mp_block *p;
 
        mem_pool->pool_alloc += sizeof(struct mp_block) + block_alloc;
        p = xmalloc(st_add(sizeof(struct mp_block), block_alloc));
-       p->next_block = mem_pool->mp_block;
+
        p->next_free = (char *)p->space;
        p->end = p->next_free + block_alloc;
-       mem_pool->mp_block = p;
+
+       if (insert_after) {
+               p->next_block = insert_after->next_block;
+               insert_after->next_block = p;
+       } else {
+               p->next_block = mem_pool->mp_block;
+               mem_pool->mp_block = p;
+       }
 
        return p;
 }
 
+void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size)
+{
+       struct mem_pool *pool;
+
+       if (*mem_pool)
+               return;
+
+       pool = xcalloc(1, sizeof(*pool));
+
+       pool->block_alloc = BLOCK_GROWTH_SIZE;
+
+       if (initial_size > 0)
+               mem_pool_alloc_block(pool, initial_size, NULL);
+
+       *mem_pool = pool;
+}
+
+void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)
+{
+       struct mp_block *block, *block_to_free;
+
+       block = mem_pool->mp_block;
+       while (block)
+       {
+               block_to_free = block;
+               block = block->next_block;
+
+               if (invalidate_memory)
+                       memset(block_to_free->space, 0xDD, ((char *)block_to_free->end) - ((char *)block_to_free->space));
+
+               free(block_to_free);
+       }
+
+       free(mem_pool);
+}
+
 void *mem_pool_alloc(struct mem_pool *mem_pool, size_t len)
 {
-       struct mp_block *p;
+       struct mp_block *p = NULL;
        void *r;
 
        /* round up to a 'uintmax_t' alignment */
        if (len & (sizeof(uintmax_t) - 1))
                len += sizeof(uintmax_t) - (len & (sizeof(uintmax_t) - 1));
 
-       for (p = mem_pool->mp_block; p; p = p->next_block)
-               if (p->end - p->next_free >= len)
-                       break;
+       if (mem_pool->mp_block &&
+           mem_pool->mp_block->end - mem_pool->mp_block->next_free >= len)
+               p = mem_pool->mp_block;
 
        if (!p) {
-               if (len >= (mem_pool->block_alloc / 2)) {
-                       mem_pool->pool_alloc += len;
-                       return xmalloc(len);
-               }
+               if (len >= (mem_pool->block_alloc / 2))
+                       return mem_pool_alloc_block(mem_pool, len, mem_pool->mp_block);
 
-               p = mem_pool_alloc_block(mem_pool, mem_pool->block_alloc);
+               p = mem_pool_alloc_block(mem_pool, mem_pool->block_alloc, NULL);
        }
 
        r = p->next_free;
@@ -53,3 +101,45 @@ void *mem_pool_calloc(struct mem_pool *mem_pool, size_t count, size_t size)
        memset(r, 0, len);
        return r;
 }
+
+int mem_pool_contains(struct mem_pool *mem_pool, void *mem)
+{
+       struct mp_block *p;
+
+       /* Check if memory is allocated in a block */
+       for (p = mem_pool->mp_block; p; p = p->next_block)
+               if ((mem >= ((void *)p->space)) &&
+                   (mem < ((void *)p->end)))
+                       return 1;
+
+       return 0;
+}
+
+void mem_pool_combine(struct mem_pool *dst, struct mem_pool *src)
+{
+       struct mp_block *p;
+
+       /* Append the blocks from src to dst */
+       if (dst->mp_block && src->mp_block) {
+               /*
+                * src and dst have blocks, append
+                * blocks from src to dst.
+                */
+               p = dst->mp_block;
+               while (p->next_block)
+                       p = p->next_block;
+
+               p->next_block = src->mp_block;
+       } else if (src->mp_block) {
+               /*
+                * src has blocks, dst is empty.
+                */
+               dst->mp_block = src->mp_block;
+       } else {
+               /* src is empty, nothing to do. */
+       }
+
+       dst->pool_alloc += src->pool_alloc;
+       src->pool_alloc = 0;
+       src->mp_block = NULL;
+}
index 829ad58ecfc48ce7ebbd707e833e933c87eb0d44..999d3c3a52cc49b6dec896fc1e6b31ea8ac078d5 100644 (file)
@@ -21,6 +21,16 @@ struct mem_pool {
        size_t pool_alloc;
 };
 
+/*
+ * Initialize mem_pool with specified initial size.
+ */
+void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size);
+
+/*
+ * Discard a memory pool and free all the memory it is responsible for.
+ */
+void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory);
+
 /*
  * Alloc memory from the mem_pool.
  */
@@ -31,4 +41,17 @@ void *mem_pool_alloc(struct mem_pool *pool, size_t len);
  */
 void *mem_pool_calloc(struct mem_pool *pool, size_t count, size_t size);
 
+/*
+ * Move the memory associated with the 'src' pool to the 'dst' pool. The 'src'
+ * pool will be empty and not contain any memory. It still needs to be free'd
+ * with a call to `mem_pool_discard`.
+ */
+void mem_pool_combine(struct mem_pool *dst, struct mem_pool *src);
+
+/*
+ * Check if a memory pointed at by 'mem' is part of the range of
+ * memory managed by the specified mem_pool.
+ */
+int mem_pool_contains(struct mem_pool *mem_pool, void *mem);
+
 #endif
index fa49c17287f4120b4bbb75acc6b92b3d339710cd..fabb8c19ce983962b45c415f66c11236fa906bfe 100644 (file)
@@ -4,6 +4,7 @@
 #include "ll-merge.h"
 #include "blob.h"
 #include "merge-blobs.h"
+#include "object-store.h"
 
 static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
 {
index bed4a5be02404ef512ba5cfcd9bb33ac04a4ca47..dcdc93019cec870f196191caf3055611faae4ede 100644 (file)
@@ -8,6 +8,8 @@
 #include "advice.h"
 #include "lockfile.h"
 #include "cache-tree.h"
+#include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "blob.h"
 #include "builtin.h"
@@ -156,7 +158,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
        }
        if (!oidcmp(&two->object.oid, &shifted))
                return two;
-       return lookup_tree(&shifted);
+       return lookup_tree(the_repository, &shifted);
 }
 
 static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
@@ -182,7 +184,7 @@ static int oid_eq(const struct object_id *a, const struct object_id *b)
 
 enum rename_type {
        RENAME_NORMAL = 0,
-       RENAME_DIR,
+       RENAME_VIA_DIR,
        RENAME_DELETE,
        RENAME_ONE_FILE_TO_ONE,
        RENAME_ONE_FILE_TO_TWO,
@@ -312,13 +314,13 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
 }
 
 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)
+                        unsigned int mode, const struct object_id *oid,
+                        const char *path, int stage, int refresh, int options)
 {
        struct cache_entry *ce;
        int ret;
 
-       ce = make_cache_entry(mode, oid ? oid->hash : null_sha1, path, stage, 0);
+       ce = make_cache_entry(&the_index, mode, oid ? oid : &null_oid, path, stage, 0);
        if (!ce)
                return err(o, _("add_cacheinfo failed for path '%s'; merge aborting."), path);
 
@@ -326,7 +328,7 @@ static int add_cacheinfo(struct merge_options *o,
        if (refresh) {
                struct cache_entry *nce;
 
-               nce = refresh_cache_entry(ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);
+               nce = refresh_cache_entry(&the_index, 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)
@@ -414,14 +416,14 @@ struct tree *write_tree_from_memory(struct merge_options *o)
                return NULL;
        }
 
-       result = lookup_tree(&active_cache_tree->oid);
+       result = lookup_tree(the_repository, &active_cache_tree->oid);
 
        return result;
 }
 
 static int save_files_dirs(const struct object_id *oid,
-               struct strbuf *base, const char *path,
-               unsigned int mode, int stage, void *context)
+                          struct strbuf *base, const char *path,
+                          unsigned int mode, int stage, void *context)
 {
        struct path_hashmap_entry *entry;
        int baselen = base->len;
@@ -542,7 +544,7 @@ static void record_df_conflict_files(struct merge_options *o,
                                     struct string_list *entries)
 {
        /* If there is a D/F conflict and the file for such a conflict
-        * currently exist in the working tree, we want to allow it to be
+        * currently exists in the working tree, we want to allow it to be
         * removed to make room for the corresponding directory if needed.
         * The files underneath the directories of such D/F conflicts will
         * be processed before the corresponding file involved in the D/F
@@ -916,7 +918,7 @@ static int make_room_for_path(struct merge_options *o, const char *path)
         */
        if (would_lose_untracked(path))
                return err(o, _("refusing to lose untracked file at '%s'"),
-                            path);
+                          path);
 
        /* Successful unlink is good.. */
        if (!unlink(path))
@@ -964,7 +966,7 @@ static int update_file_flags(struct merge_options *o,
                }
                if (S_ISREG(mode)) {
                        struct strbuf strbuf = STRBUF_INIT;
-                       if (convert_to_working_tree(path, buf, size, &strbuf)) {
+                       if (convert_to_working_tree(&the_index, path, buf, size, &strbuf)) {
                                free(buf);
                                size = strbuf.len;
                                buf = strbuf_detach(&strbuf, NULL);
@@ -995,16 +997,16 @@ static int update_file_flags(struct merge_options *o,
                        unlink(path);
                        if (symlink(lnk, path))
                                ret = err(o, _("failed to symlink '%s': %s"),
-                                       path, strerror(errno));
+                                         path, strerror(errno));
                        free(lnk);
                } else
                        ret = err(o,
                                  _("do not know what to do with %06o %s '%s'"),
                                  mode, oid_to_hex(oid), path);
- free_buf:
      free_buf:
                free(buf);
        }
- update_index:
+update_index:
        if (!ret && update_cache)
                if (add_cacheinfo(o, mode, oid, path, 0, update_wd,
                                  ADD_CACHE_OK_TO_ADD))
@@ -1093,7 +1095,7 @@ static int merge_3way(struct merge_options *o,
 }
 
 static int find_first_merges(struct object_array *result, const char *path,
-               struct commit *a, struct commit *b)
+                            struct commit *a, struct commit *b)
 {
        int i, j;
        struct object_array merges = OBJECT_ARRAY_INIT;
@@ -1111,7 +1113,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));
+                 oid_to_hex(&a->object.oid));
        init_revisions(&revs, NULL);
        rev_opts.submodule = path;
        /* FIXME: can't handle linked worktrees in submodules yet */
@@ -1190,9 +1192,9 @@ static int merge_submodule(struct merge_options *o,
                return 0;
        }
 
-       if (!(commit_base = lookup_commit_reference(base)) ||
-           !(commit_a = lookup_commit_reference(a)) ||
-           !(commit_b = lookup_commit_reference(b))) {
+       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))) {
                output(o, 1, _("Failed to merge submodule %s (commits not present)"), path);
                return 0;
        }
@@ -1253,12 +1255,12 @@ static int merge_submodule(struct merge_options *o,
                output(o, 2, _("Found a possible merge resolution for the submodule:\n"));
                print_commit((struct commit *) merges.objects[0].item);
                output(o, 2, _(
-                       "If this is correct simply add it to the index "
-                       "for example\n"
-                       "by using:\n\n"
-                       "  git update-index --cacheinfo 160000 %s \"%s\"\n\n"
-                       "which will accept this suggestion.\n"),
-                       oid_to_hex(&merges.objects[0].item->oid), path);
+                      "If this is correct simply add it to the index "
+                      "for example\n"
+                      "by using:\n\n"
+                      "  git update-index --cacheinfo 160000 %s \"%s\"\n\n"
+                      "which will accept this suggestion.\n"),
+                      oid_to_hex(&merges.objects[0].item->oid), path);
                break;
 
        default:
@@ -1335,10 +1337,10 @@ static int merge_file_1(struct merge_options *o,
                        result->clean = (merge_status == 0);
                } else if (S_ISGITLINK(a->mode)) {
                        result->clean = merge_submodule(o, &result->oid,
-                                                      one->path,
-                                                      &one->oid,
-                                                      &a->oid,
-                                                      &b->oid);
+                                                       one->path,
+                                                       &one->oid,
+                                                       &a->oid,
+                                                       &b->oid);
                } else if (S_ISLNK(a->mode)) {
                        switch (o->recursive_variant) {
                        case MERGE_RECURSIVE_NORMAL:
@@ -1413,11 +1415,17 @@ static int merge_file_one(struct merge_options *o,
        return merge_file_1(o, &one, &a, &b, path, branch1, branch2, mfi);
 }
 
-static int conflict_rename_dir(struct merge_options *o,
-                              struct diff_filepair *pair,
-                              const char *rename_branch,
-                              const char *other_branch)
+static int handle_rename_via_dir(struct merge_options *o,
+                                struct diff_filepair *pair,
+                                const char *rename_branch,
+                                const char *other_branch)
 {
+       /*
+        * Handle file adds that need to be renamed due to directory rename
+        * detection.  This differs from handle_rename_normal, because
+        * there is no content merge to do; just move the file into the
+        * desired final location.
+        */
        const struct diff_filespec *dest = pair->two;
 
        if (!o->call_depth && would_lose_untracked(dest->path)) {
@@ -1446,13 +1454,13 @@ static int conflict_rename_dir(struct merge_options *o,
 }
 
 static int handle_change_delete(struct merge_options *o,
-                                const char *path, const char *old_path,
-                                const struct object_id *o_oid, int o_mode,
-                                const struct object_id *changed_oid,
-                                int changed_mode,
-                                const char *change_branch,
-                                const char *delete_branch,
-                                const char *change, const char *change_past)
+                               const char *path, const char *old_path,
+                               const struct object_id *o_oid, int o_mode,
+                               const struct object_id *changed_oid,
+                               int changed_mode,
+                               const char *change_branch,
+                               const char *delete_branch,
+                               const char *change, const char *change_past)
 {
        char *alt_path = NULL;
        const char *update_path = path;
@@ -1473,6 +1481,21 @@ static int handle_change_delete(struct merge_options *o,
                if (!ret)
                        ret = update_file(o, 0, o_oid, o_mode, update_path);
        } else {
+               /*
+                * Despite the four nearly duplicate messages and argument
+                * lists below and the ugliness of the nested if-statements,
+                * having complete messages makes the job easier for
+                * translators.
+                *
+                * The slight variance among the cases is due to the fact
+                * that:
+                *   1) directory/file conflicts (in effect if
+                *      !alt_path) could cause us to need to write the
+                *      file to a different path.
+                *   2) renames (in effect if !old_path) could mean that
+                *      there are two names for the path that the user
+                *      may know the file by.
+                */
                if (!alt_path) {
                        if (!old_path) {
                                output(o, 1, _("CONFLICT (%s/delete): %s deleted in %s "
@@ -1512,10 +1535,10 @@ static int handle_change_delete(struct merge_options *o,
        return ret;
 }
 
-static int conflict_rename_delete(struct merge_options *o,
-                                  struct diff_filepair *pair,
-                                  const char *rename_branch,
-                                  const char *delete_branch)
+static int handle_rename_delete(struct merge_options *o,
+                               struct diff_filepair *pair,
+                               const char *rename_branch,
+                               const char *delete_branch)
 {
        const struct diff_filespec *orig = pair->one;
        const struct diff_filespec *dest = pair->two;
@@ -1617,8 +1640,8 @@ static int handle_file(struct merge_options *o,
        return ret;
 }
 
-static int conflict_rename_rename_1to2(struct merge_options *o,
-                                       struct rename_conflict_info *ci)
+static int handle_rename_rename_1to2(struct merge_options *o,
+                                    struct rename_conflict_info *ci)
 {
        /* One file was renamed in both branches, but to different names. */
        struct diff_filespec *one = ci->pair1->one;
@@ -1679,8 +1702,8 @@ static int conflict_rename_rename_1to2(struct merge_options *o,
        return 0;
 }
 
-static int conflict_rename_rename_2to1(struct merge_options *o,
-                                       struct rename_conflict_info *ci)
+static int handle_rename_rename_2to1(struct merge_options *o,
+                                    struct rename_conflict_info *ci)
 {
        /* Two files, a & b, were renamed to the same thing, c. */
        struct diff_filespec *a = ci->pair1->one;
@@ -2422,7 +2445,7 @@ static void apply_directory_rename_modifications(struct merge_options *o,
         * "NOTE" in update_stages(), doing so will modify the current
         * in-memory index which will break calls to would_lose_untracked()
         * that we need to make.  Instead, we need to just make sure that
-        * the various conflict_rename_*() functions update the index
+        * the various handle_rename_*() functions update the index
         * explicitly rather than relying on unpack_trees() to have done it.
         */
        get_tree_entry(&tree->object.oid,
@@ -2695,7 +2718,7 @@ static int process_renames(struct merge_options *o,
 
                        if (oid_eq(&src_other.oid, &null_oid) &&
                            ren1->add_turned_into_rename) {
-                               setup_rename_conflict_info(RENAME_DIR,
+                               setup_rename_conflict_info(RENAME_VIA_DIR,
                                                           ren1->pair,
                                                           NULL,
                                                           branch1,
@@ -2826,12 +2849,12 @@ static void initial_cleanup_rename(struct diff_queue_struct *pairs,
        free(pairs);
 }
 
-static int handle_renames(struct merge_options *o,
-                         struct tree *common,
-                         struct tree *head,
-                         struct tree *merge,
-                         struct string_list *entries,
-                         struct rename_info *ri)
+static int detect_and_process_renames(struct merge_options *o,
+                                     struct tree *common,
+                                     struct tree *head,
+                                     struct tree *merge,
+                                     struct string_list *entries,
+                                     struct rename_info *ri)
 {
        struct diff_queue_struct *head_pairs, *merge_pairs;
        struct hashmap *dir_re_head, *dir_re_merge;
@@ -2907,7 +2930,8 @@ static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)
 }
 
 static int read_oid_strbuf(struct merge_options *o,
-       const struct object_id *oid, struct strbuf *dst)
+                          const struct object_id *oid,
+                          struct strbuf *dst)
 {
        void *buf;
        enum object_type type;
@@ -2960,10 +2984,10 @@ static int blob_unchanged(struct merge_options *opt,
 }
 
 static int handle_modify_delete(struct merge_options *o,
-                                const char *path,
-                                struct object_id *o_oid, int o_mode,
-                                struct object_id *a_oid, int a_mode,
-                                struct object_id *b_oid, int b_mode)
+                               const char *path,
+                               struct object_id *o_oid, int o_mode,
+                               struct object_id *a_oid, int a_mode,
+                               struct object_id *b_oid, int b_mode)
 {
        const char *modify_branch, *delete_branch;
        struct object_id *changed_oid;
@@ -3046,10 +3070,26 @@ static int merge_content(struct merge_options *o,
        if (mfi.clean &&
            was_tracked_and_matches(o, path, &mfi.oid, mfi.mode) &&
            !df_conflict_remains) {
+               int pos;
+               struct cache_entry *ce;
+
                output(o, 3, _("Skipped %s (merged same as existing)"), path);
                if (add_cacheinfo(o, mfi.mode, &mfi.oid, path,
                                  0, (!o->call_depth && !is_dirty), 0))
                        return -1;
+               /*
+                * However, add_cacheinfo() will delete the old cache entry
+                * and add a new one.  We need to copy over any skip_worktree
+                * flag to avoid making the file appear as if it were
+                * deleted by the user.
+                */
+               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];
+                       ce->ce_flags |= CE_SKIP_WORKTREE;
+               }
                return mfi.clean;
        }
 
@@ -3101,12 +3141,12 @@ static int merge_content(struct merge_options *o,
        return !is_dirty && mfi.clean;
 }
 
-static int conflict_rename_normal(struct merge_options *o,
-                                 const char *path,
-                                 struct object_id *o_oid, unsigned int o_mode,
-                                 struct object_id *a_oid, unsigned int a_mode,
-                                 struct object_id *b_oid, unsigned int b_mode,
-                                 struct rename_conflict_info *ci)
+static int handle_rename_normal(struct merge_options *o,
+                               const char *path,
+                               struct object_id *o_oid, unsigned int o_mode,
+                               struct object_id *a_oid, unsigned int a_mode,
+                               struct object_id *b_oid, unsigned int b_mode,
+                               struct rename_conflict_info *ci)
 {
        /* Merge the content and write it out */
        return merge_content(o, path, was_dirty(o, path),
@@ -3133,37 +3173,37 @@ static int process_entry(struct merge_options *o,
                switch (conflict_info->rename_type) {
                case RENAME_NORMAL:
                case RENAME_ONE_FILE_TO_ONE:
-                       clean_merge = conflict_rename_normal(o,
-                                                            path,
-                                                            o_oid, o_mode,
-                                                            a_oid, a_mode,
-                                                            b_oid, b_mode,
-                                                            conflict_info);
+                       clean_merge = handle_rename_normal(o,
+                                                          path,
+                                                          o_oid, o_mode,
+                                                          a_oid, a_mode,
+                                                          b_oid, b_mode,
+                                                          conflict_info);
                        break;
-               case RENAME_DIR:
+               case RENAME_VIA_DIR:
                        clean_merge = 1;
-                       if (conflict_rename_dir(o,
-                                               conflict_info->pair1,
-                                               conflict_info->branch1,
-                                               conflict_info->branch2))
+                       if (handle_rename_via_dir(o,
+                                                 conflict_info->pair1,
+                                                 conflict_info->branch1,
+                                                 conflict_info->branch2))
                                clean_merge = -1;
                        break;
                case RENAME_DELETE:
                        clean_merge = 0;
-                       if (conflict_rename_delete(o,
-                                                  conflict_info->pair1,
-                                                  conflict_info->branch1,
-                                                  conflict_info->branch2))
+                       if (handle_rename_delete(o,
+                                                conflict_info->pair1,
+                                                conflict_info->branch1,
+                                                conflict_info->branch2))
                                clean_merge = -1;
                        break;
                case RENAME_ONE_FILE_TO_TWO:
                        clean_merge = 0;
-                       if (conflict_rename_rename_1to2(o, conflict_info))
+                       if (handle_rename_rename_1to2(o, conflict_info))
                                clean_merge = -1;
                        break;
                case RENAME_TWO_FILES_TO_ONE:
                        clean_merge = 0;
-                       if (conflict_rename_rename_2to1(o, conflict_info))
+                       if (handle_rename_rename_2to1(o, conflict_info))
                                clean_merge = -1;
                        break;
                default:
@@ -3257,6 +3297,13 @@ int merge_trees(struct merge_options *o,
                struct tree **result)
 {
        int code, clean;
+       struct strbuf sb = STRBUF_INIT;
+
+       if (!o->call_depth && index_has_changes(&the_index, 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);
@@ -3264,13 +3311,6 @@ int merge_trees(struct merge_options *o,
        }
 
        if (oid_eq(&common->object.oid, &merge->object.oid)) {
-               struct strbuf sb = STRBUF_INIT;
-
-               if (!o->call_depth && index_has_changes(&sb)) {
-                       err(o, _("Dirty index: cannot merge (dirty: %s)"),
-                           sb.buf);
-                       return 0;
-               }
                output(o, 0, _("Already up to date!"));
                *result = head;
                return 1;
@@ -3303,8 +3343,8 @@ int merge_trees(struct merge_options *o,
                get_files_dirs(o, merge);
 
                entries = get_unmerged();
-               clean = handle_renames(o, common, head, merge, entries,
-                                      &re_info);
+               clean = detect_and_process_renames(o, common, head, merge,
+                                                  entries, &re_info);
                record_df_conflict_files(o, entries);
                if (clean < 0)
                        goto cleanup;
@@ -3328,7 +3368,7 @@ int merge_trees(struct merge_options *o,
                                    entries->items[i].string);
                }
 
-cleanup:
+       cleanup:
                final_cleanup_renames(&re_info);
 
                string_list_clear(entries, 1);
@@ -3403,7 +3443,7 @@ int merge_recursive(struct merge_options *o,
                /* if there is no common ancestor, use an empty tree */
                struct tree *tree;
 
-               tree = lookup_tree(the_hash_algo->empty_tree);
+               tree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
                merged_common_ancestors = make_virtual_commit(tree, "ancestor");
        }
 
@@ -3465,7 +3505,9 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)
 {
        struct object *object;
 
-       object = deref_tag(parse_object(oid), name, strlen(name));
+       object = deref_tag(the_repository, parse_object(the_repository, oid),
+                          name,
+                          strlen(name));
        if (!object)
                return NULL;
        if (object->type == OBJ_TREE)
@@ -3496,14 +3538,14 @@ int merge_recursive_generic(struct merge_options *o,
                        struct commit *base;
                        if (!(base = get_ref(base_list[i], oid_to_hex(base_list[i]))))
                                return err(o, _("Could not parse object '%s'"),
-                                       oid_to_hex(base_list[i]));
+                                          oid_to_hex(base_list[i]));
                        commit_list_insert(base, &ca);
                }
        }
 
        hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
        clean = merge_recursive(o, head_commit, next_commit, ca,
-                       result);
+                               result);
        if (clean < 0) {
                rollback_lock_file(&lock);
                return clean;
diff --git a/merge.c b/merge.c
index 0783858739f84028df6eef85d3673c944fabb912..e30e03fb84a7677520d208a5688bb7170c22bf8e 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -14,37 +14,6 @@ static const char *merge_argument(struct commit *commit)
        return oid_to_hex(commit ? &commit->object.oid : the_hash_algo->empty_tree);
 }
 
-int index_has_changes(struct strbuf *sb)
-{
-       struct object_id head;
-       int i;
-
-       if (!get_oid_tree("HEAD", &head)) {
-               struct diff_options opt;
-
-               diff_setup(&opt);
-               opt.flags.exit_with_status = 1;
-               if (!sb)
-                       opt.flags.quick = 1;
-               do_diff_cache(&head, &opt);
-               diffcore_std(&opt);
-               for (i = 0; sb && i < diff_queued_diff.nr; i++) {
-                       if (i)
-                               strbuf_addch(sb, ' ');
-                       strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
-               }
-               diff_flush(&opt);
-               return opt.flags.has_changes != 0;
-       } else {
-               for (i = 0; sb && i < active_nr; i++) {
-                       if (i)
-                               strbuf_addch(sb, ' ');
-                       strbuf_addstr(sb, active_cache[i]->name);
-               }
-               return !!active_nr;
-       }
-}
-
 int try_merge_command(const char *strategy, size_t xopts_nr,
                      const char **xopts, struct commit_list *common,
                      const char *head_arg, struct commit_list *remotes)
diff --git a/negotiator/default.c b/negotiator/default.c
new file mode 100644 (file)
index 0000000..4b78f6b
--- /dev/null
@@ -0,0 +1,176 @@
+#include "cache.h"
+#include "default.h"
+#include "../commit.h"
+#include "../fetch-negotiator.h"
+#include "../prio-queue.h"
+#include "../refs.h"
+#include "../tag.h"
+
+/* Remember to update object flag allocation in object.h */
+#define COMMON         (1U << 2)
+#define COMMON_REF     (1U << 3)
+#define SEEN           (1U << 4)
+#define POPPED         (1U << 5)
+
+static int marked;
+
+struct negotiation_state {
+       struct prio_queue rev_list;
+       int non_common_revs;
+};
+
+static void rev_list_push(struct negotiation_state *ns,
+                         struct commit *commit, int mark)
+{
+       if (!(commit->object.flags & mark)) {
+               commit->object.flags |= mark;
+
+               if (parse_commit(commit))
+                       return;
+
+               prio_queue_put(&ns->rev_list, commit);
+
+               if (!(commit->object.flags & COMMON))
+                       ns->non_common_revs++;
+       }
+}
+
+static int clear_marks(const char *refname, const struct object_id *oid,
+                      int flag, void *cb_data)
+{
+       struct object *o = deref_tag(the_repository, parse_object(the_repository, oid), refname, 0);
+
+       if (o && o->type == OBJ_COMMIT)
+               clear_commit_marks((struct commit *)o,
+                                  COMMON | COMMON_REF | SEEN | POPPED);
+       return 0;
+}
+
+/*
+ * This function marks a rev and its ancestors as common.
+ * In some cases, it is desirable to mark only the ancestors (for example
+ * when only the server does not yet know that they are common).
+ */
+static void mark_common(struct negotiation_state *ns, struct commit *commit,
+               int ancestors_only, int dont_parse)
+{
+       if (commit != NULL && !(commit->object.flags & COMMON)) {
+               struct object *o = (struct object *)commit;
+
+               if (!ancestors_only)
+                       o->flags |= COMMON;
+
+               if (!(o->flags & SEEN))
+                       rev_list_push(ns, commit, SEEN);
+               else {
+                       struct commit_list *parents;
+
+                       if (!ancestors_only && !(o->flags & POPPED))
+                               ns->non_common_revs--;
+                       if (!o->parsed && !dont_parse)
+                               if (parse_commit(commit))
+                                       return;
+
+                       for (parents = commit->parents;
+                                       parents;
+                                       parents = parents->next)
+                               mark_common(ns, parents->item, 0,
+                                           dont_parse);
+               }
+       }
+}
+
+/*
+ * Get the next rev to send, ignoring the common.
+ */
+static const struct object_id *get_rev(struct negotiation_state *ns)
+{
+       struct commit *commit = NULL;
+
+       while (commit == NULL) {
+               unsigned int mark;
+               struct commit_list *parents;
+
+               if (ns->rev_list.nr == 0 || ns->non_common_revs == 0)
+                       return NULL;
+
+               commit = prio_queue_get(&ns->rev_list);
+               parse_commit(commit);
+               parents = commit->parents;
+
+               commit->object.flags |= POPPED;
+               if (!(commit->object.flags & COMMON))
+                       ns->non_common_revs--;
+
+               if (commit->object.flags & COMMON) {
+                       /* do not send "have", and ignore ancestors */
+                       commit = NULL;
+                       mark = COMMON | SEEN;
+               } else if (commit->object.flags & COMMON_REF)
+                       /* send "have", and ignore ancestors */
+                       mark = COMMON | SEEN;
+               else
+                       /* send "have", also for its ancestors */
+                       mark = SEEN;
+
+               while (parents) {
+                       if (!(parents->item->object.flags & SEEN))
+                               rev_list_push(ns, parents->item, mark);
+                       if (mark & COMMON)
+                               mark_common(ns, parents->item, 1, 0);
+                       parents = parents->next;
+               }
+       }
+
+       return &commit->object.oid;
+}
+
+static void known_common(struct fetch_negotiator *n, struct commit *c)
+{
+       if (!(c->object.flags & SEEN)) {
+               rev_list_push(n->data, c, COMMON_REF | SEEN);
+               mark_common(n->data, c, 1, 1);
+       }
+}
+
+static void add_tip(struct fetch_negotiator *n, struct commit *c)
+{
+       n->known_common = NULL;
+       rev_list_push(n->data, c, SEEN);
+}
+
+static const struct object_id *next(struct fetch_negotiator *n)
+{
+       n->known_common = NULL;
+       n->add_tip = NULL;
+       return get_rev(n->data);
+}
+
+static int ack(struct fetch_negotiator *n, struct commit *c)
+{
+       int known_to_be_common = !!(c->object.flags & COMMON);
+       mark_common(n->data, c, 0, 1);
+       return known_to_be_common;
+}
+
+static void release(struct fetch_negotiator *n)
+{
+       clear_prio_queue(&((struct negotiation_state *)n->data)->rev_list);
+       FREE_AND_NULL(n->data);
+}
+
+void default_negotiator_init(struct fetch_negotiator *negotiator)
+{
+       struct negotiation_state *ns;
+       negotiator->known_common = known_common;
+       negotiator->add_tip = add_tip;
+       negotiator->next = next;
+       negotiator->ack = ack;
+       negotiator->release = release;
+       negotiator->data = ns = xcalloc(1, sizeof(*ns));
+       ns->rev_list.compare = compare_commits_by_commit_date;
+
+       if (marked)
+               for_each_ref(clear_marks, NULL);
+       marked = 1;
+}
diff --git a/negotiator/default.h b/negotiator/default.h
new file mode 100644 (file)
index 0000000..d23a8f2
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef NEGOTIATOR_DEFAULT_H
+#define NEGOTIATOR_DEFAULT_H
+
+struct fetch_negotiator;
+
+void default_negotiator_init(struct fetch_negotiator *negotiator);
+
+#endif
diff --git a/negotiator/skipping.c b/negotiator/skipping.c
new file mode 100644 (file)
index 0000000..dffbc76
--- /dev/null
@@ -0,0 +1,250 @@
+#include "cache.h"
+#include "skipping.h"
+#include "../commit.h"
+#include "../fetch-negotiator.h"
+#include "../prio-queue.h"
+#include "../refs.h"
+#include "../tag.h"
+
+/* Remember to update object flag allocation in object.h */
+/*
+ * Both us and the server know that both parties have this object.
+ */
+#define COMMON         (1U << 2)
+/*
+ * The server has told us that it has this object. We still need to tell the
+ * server that we have this object (or one of its descendants), but since we are
+ * going to do that, we do not need to tell the server about its ancestors.
+ */
+#define ADVERTISED     (1U << 3)
+/*
+ * This commit has entered the priority queue.
+ */
+#define SEEN           (1U << 4)
+/*
+ * This commit has left the priority queue.
+ */
+#define POPPED         (1U << 5)
+
+static int marked;
+
+/*
+ * An entry in the priority queue.
+ */
+struct entry {
+       struct commit *commit;
+
+       /*
+        * Used only if commit is not COMMON.
+        */
+       uint16_t original_ttl;
+       uint16_t ttl;
+};
+
+struct data {
+       struct prio_queue rev_list;
+
+       /*
+        * The number of non-COMMON commits in rev_list.
+        */
+       int non_common_revs;
+};
+
+static int compare(const void *a_, const void *b_, void *unused)
+{
+       const struct entry *a = a_;
+       const struct entry *b = b_;
+       return compare_commits_by_commit_date(a->commit, b->commit, NULL);
+}
+
+static struct entry *rev_list_push(struct data *data, struct commit *commit, int mark)
+{
+       struct entry *entry;
+       commit->object.flags |= mark | SEEN;
+
+       entry = xcalloc(1, sizeof(*entry));
+       entry->commit = commit;
+       prio_queue_put(&data->rev_list, entry);
+
+       if (!(mark & COMMON))
+               data->non_common_revs++;
+       return entry;
+}
+
+static int clear_marks(const char *refname, const struct object_id *oid,
+                      int flag, void *cb_data)
+{
+       struct object *o = deref_tag(the_repository, parse_object(the_repository, oid), refname, 0);
+
+       if (o && o->type == OBJ_COMMIT)
+               clear_commit_marks((struct commit *)o,
+                                  COMMON | ADVERTISED | SEEN | POPPED);
+       return 0;
+}
+
+/*
+ * Mark this SEEN commit and all its SEEN ancestors as COMMON.
+ */
+static void mark_common(struct data *data, struct commit *c)
+{
+       struct commit_list *p;
+
+       if (c->object.flags & COMMON)
+               return;
+       c->object.flags |= COMMON;
+       if (!(c->object.flags & POPPED))
+               data->non_common_revs--;
+
+       if (!c->object.parsed)
+               return;
+       for (p = c->parents; p; p = p->next) {
+               if (p->item->object.flags & SEEN)
+                       mark_common(data, p->item);
+       }
+}
+
+/*
+ * Ensure that the priority queue has an entry for to_push, and ensure that the
+ * entry has the correct flags and ttl.
+ *
+ * This function returns 1 if an entry was found or created, and 0 otherwise
+ * (because the entry for this commit had already been popped).
+ */
+static int push_parent(struct data *data, struct entry *entry,
+                      struct commit *to_push)
+{
+       struct entry *parent_entry;
+
+       if (to_push->object.flags & SEEN) {
+               int i;
+               if (to_push->object.flags & POPPED)
+                       /*
+                        * The entry for this commit has already been popped,
+                        * due to clock skew. Pretend that this parent does not
+                        * exist.
+                        */
+                       return 0;
+               /*
+                * Find the existing entry and use it.
+                */
+               for (i = 0; i < data->rev_list.nr; i++) {
+                       parent_entry = data->rev_list.array[i].data;
+                       if (parent_entry->commit == to_push)
+                               goto parent_found;
+               }
+               BUG("missing parent in priority queue");
+parent_found:
+               ;
+       } else {
+               parent_entry = rev_list_push(data, to_push, 0);
+       }
+
+       if (entry->commit->object.flags & (COMMON | ADVERTISED)) {
+               mark_common(data, to_push);
+       } else {
+               uint16_t new_original_ttl = entry->ttl
+                       ? entry->original_ttl : entry->original_ttl * 3 / 2 + 1;
+               uint16_t new_ttl = entry->ttl
+                       ? entry->ttl - 1 : new_original_ttl;
+               if (parent_entry->original_ttl < new_original_ttl) {
+                       parent_entry->original_ttl = new_original_ttl;
+                       parent_entry->ttl = new_ttl;
+               }
+       }
+
+       return 1;
+}
+
+static const struct object_id *get_rev(struct data *data)
+{
+       struct commit *to_send = NULL;
+
+       while (to_send == NULL) {
+               struct entry *entry;
+               struct commit *commit;
+               struct commit_list *p;
+               int parent_pushed = 0;
+
+               if (data->rev_list.nr == 0 || data->non_common_revs == 0)
+                       return NULL;
+
+               entry = prio_queue_get(&data->rev_list);
+               commit = entry->commit;
+               commit->object.flags |= POPPED;
+               if (!(commit->object.flags & COMMON))
+                       data->non_common_revs--;
+
+               if (!(commit->object.flags & COMMON) && !entry->ttl)
+                       to_send = commit;
+
+               parse_commit(commit);
+               for (p = commit->parents; p; p = p->next)
+                       parent_pushed |= push_parent(data, entry, p->item);
+
+               if (!(commit->object.flags & COMMON) && !parent_pushed)
+                       /*
+                        * This commit has no parents, or all of its parents
+                        * have already been popped (due to clock skew), so send
+                        * it anyway.
+                        */
+                       to_send = commit;
+
+               free(entry);
+       }
+
+       return &to_send->object.oid;
+}
+
+static void known_common(struct fetch_negotiator *n, struct commit *c)
+{
+       if (c->object.flags & SEEN)
+               return;
+       rev_list_push(n->data, c, ADVERTISED);
+}
+
+static void add_tip(struct fetch_negotiator *n, struct commit *c)
+{
+       n->known_common = NULL;
+       if (c->object.flags & SEEN)
+               return;
+       rev_list_push(n->data, c, 0);
+}
+
+static const struct object_id *next(struct fetch_negotiator *n)
+{
+       n->known_common = NULL;
+       n->add_tip = NULL;
+       return get_rev(n->data);
+}
+
+static int ack(struct fetch_negotiator *n, struct commit *c)
+{
+       int known_to_be_common = !!(c->object.flags & COMMON);
+       if (!(c->object.flags & SEEN))
+               die("received ack for commit %s not sent as 'have'\n",
+                   oid_to_hex(&c->object.oid));
+       mark_common(n->data, c);
+       return known_to_be_common;
+}
+
+static void release(struct fetch_negotiator *n)
+{
+       clear_prio_queue(&((struct data *)n->data)->rev_list);
+       FREE_AND_NULL(n->data);
+}
+
+void skipping_negotiator_init(struct fetch_negotiator *negotiator)
+{
+       struct data *data;
+       negotiator->known_common = known_common;
+       negotiator->add_tip = add_tip;
+       negotiator->next = next;
+       negotiator->ack = ack;
+       negotiator->release = release;
+       negotiator->data = data = xcalloc(1, sizeof(*data));
+       data->rev_list.compare = compare;
+
+       if (marked)
+               for_each_ref(clear_marks, NULL);
+       marked = 1;
+}
diff --git a/negotiator/skipping.h b/negotiator/skipping.h
new file mode 100644 (file)
index 0000000..d7dfa6c
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef NEGOTIATOR_SKIPPING_H
+#define NEGOTIATOR_SKIPPING_H
+
+struct fetch_negotiator;
+
+void skipping_negotiator_init(struct fetch_negotiator *negotiator);
+
+#endif
index e61988e503b0b2097afeb6716123d88429c0717d..d87e7ca91cdecb158ca93659fb58968e92b18b31 100644 (file)
@@ -1,5 +1,7 @@
 #include "cache.h"
 #include "notes-cache.h"
+#include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "refs.h"
 
@@ -14,7 +16,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
        if (read_ref(ref, &oid) < 0)
                return 0;
 
-       commit = lookup_commit_reference_gently(&oid, 1);
+       commit = lookup_commit_reference_gently(the_repository, &oid, 1);
        if (!commit)
                return 0;
 
index d613e06574aec31e0ecaf083b489b0465e5c27f1..76ab19e702423aeb511bfc1e939a7998c61fab61 100644 (file)
@@ -1,6 +1,8 @@
 #include "cache.h"
 #include "commit.h"
 #include "refs.h"
+#include "object-store.h"
+#include "repository.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "xdiff-interface.h"
@@ -552,7 +554,7 @@ int notes_merge(struct notes_merge_options *o,
        else if (!check_refname_format(o->local_ref, 0) &&
                is_null_oid(&local_oid))
                local = NULL; /* local_oid == null_oid indicates unborn ref */
-       else if (!(local = lookup_commit_reference(&local_oid)))
+       else if (!(local = lookup_commit_reference(the_repository, &local_oid)))
                die("Could not parse local commit %s (%s)",
                    oid_to_hex(&local_oid), o->local_ref);
        trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid));
@@ -570,7 +572,7 @@ int notes_merge(struct notes_merge_options *o,
                        die("Failed to resolve remote notes ref '%s'",
                            o->remote_ref);
                }
-       } else if (!(remote = lookup_commit_reference(&remote_oid))) {
+       } else if (!(remote = lookup_commit_reference(the_repository, &remote_oid))) {
                die("Could not parse remote commit %s (%s)",
                    oid_to_hex(&remote_oid), o->remote_ref);
        }
index 02407fe2a7327947dda6bf755405d2778ae450ae..14ea03178e9c44c8c8a05fb70ab038df5ad1b5f8 100644 (file)
@@ -3,6 +3,7 @@
 #include "commit.h"
 #include "refs.h"
 #include "notes-utils.h"
+#include "repository.h"
 
 void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
                         const char *msg, size_t msg_len,
@@ -19,7 +20,8 @@ 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(&parent_oid);
+                       struct commit *parent = lookup_commit(the_repository,
+                                                             &parent_oid);
                        if (parse_commit(parent))
                                die("Failed to find/parse commit %s", t->ref);
                        commit_list_insert(parent, &parents);
diff --git a/notes.c b/notes.c
index a386d450c4c812ef30d0fc661fe2c03e1d062a83..32d3dbcc1e74ce344da89b9aa2b9ca09f6e62d2b 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "notes.h"
+#include "object-store.h"
 #include "blob.h"
 #include "tree.h"
 #include "utf8.h"
index d683112fd7bbab5df7e8cd5656b497cb8fd2bda1..162156f5dc66d491eaf010136caa9c3ebc02483e 100644 (file)
@@ -2,6 +2,9 @@
 #define OBJECT_STORE_H
 
 #include "oidmap.h"
+#include "list.h"
+#include "sha1-array.h"
+#include "strbuf.h"
 
 struct alternate_object_database {
        struct alternate_object_database *next;
@@ -103,6 +106,9 @@ struct raw_object_store {
         */
        struct oidmap *replace_map;
 
+       struct commit_graph *commit_graph;
+       unsigned commit_graph_attempted : 1; /* if loading has been attempted */
+
        /*
         * private data
         *
@@ -139,4 +145,211 @@ void sha1_file_name(struct repository *r, struct strbuf *buf, const unsigned cha
 
 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,
+                                      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)
+{
+       return read_object_file_extended(oid, type, size, 1);
+}
+
+/* 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 *);
+
+extern int hash_object_file(const void *buf, unsigned long len,
+                           const char *type, struct object_id *oid);
+
+extern int write_object_file(const void *buf, unsigned long len,
+                            const char *type, struct object_id *oid);
+
+extern int hash_object_file_literally(const void *buf, unsigned long len,
+                                     const char *type, struct object_id *oid,
+                                     unsigned flags);
+
+extern int pretend_object_file(void *, unsigned long, enum object_type,
+                              struct object_id *oid);
+
+extern int force_object_loose(const struct object_id *oid, time_t mtime);
+
+/*
+ * Open the loose object at path, check its hash, and return the contents,
+ * type, and size. If the object is a blob, then "contents" may return NULL,
+ * to allow streaming of large blobs.
+ *
+ * Returns 0 on success, negative on error (details may be written to stderr).
+ */
+int read_loose_object(const char *path,
+                     const struct object_id *expected_oid,
+                     enum object_type *type,
+                     unsigned long *size,
+                     void **contents);
+
+/*
+ * Convenience for sha1_object_info_extended() with a NULL struct
+ * 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)
+{
+       return has_sha1_file_with_flags(sha1, 0);
+}
+
+/* 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);
+
+/*
+ * Return true iff an alternate object database has a loose object
+ * with the specified name.  This function does not respect replace
+ * references.
+ */
+extern int has_loose_object_nonlocal(const struct object_id *);
+
+extern void assert_oid_type(const struct object_id *oid, enum object_type expect);
+
+struct object_info {
+       /* Request */
+       enum object_type *typep;
+       unsigned long *sizep;
+       off_t *disk_sizep;
+       unsigned char *delta_base_sha1;
+       struct strbuf *type_name;
+       void **contentp;
+
+       /* Response */
+       enum {
+               OI_CACHED,
+               OI_LOOSE,
+               OI_PACKED,
+               OI_DBCACHED
+       } whence;
+       union {
+               /*
+                * struct {
+                *      ... Nothing to expose in this case
+                * } cached;
+                * struct {
+                *      ... Nothing to expose in this case
+                * } loose;
+                */
+               struct {
+                       struct packed_git *pack;
+                       off_t offset;
+                       unsigned int is_delta;
+               } packed;
+       } u;
+};
+
+/*
+ * Initializer for a "struct object_info" that wants no items. You may
+ * also memset() the memory to all-zeroes.
+ */
+#define OBJECT_INFO_INIT {NULL}
+
+/* Invoke lookup_replace_object() on the given hash */
+#define OBJECT_INFO_LOOKUP_REPLACE 1
+/* Allow reading from a loose object file of unknown/bogus type */
+#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
+/* Do not check cached storage */
+#define OBJECT_INFO_SKIP_CACHED 4
+/* Do not retry packed storage after checking packed and loose storage */
+#define OBJECT_INFO_QUICK 8
+/* Do not check loose object */
+#define OBJECT_INFO_IGNORE_LOOSE 16
+
+int oid_object_info_extended(struct repository *r,
+                            const struct object_id *,
+                            struct object_info *, unsigned flags);
+
+/*
+ * Iterate over the files in the loose-object parts of the object
+ * directory "path", triggering the following callbacks:
+ *
+ *  - loose_object is called for each loose object we find.
+ *
+ *  - loose_cruft is called for any files that do not appear to be
+ *    loose objects. Note that we only look in the loose object
+ *    directories "objects/[0-9a-f]{2}/", so we will not report
+ *    "objects/foobar" as cruft.
+ *
+ *  - loose_subdir is called for each top-level hashed subdirectory
+ *    of the object directory (e.g., "$OBJDIR/f0"). It is called
+ *    after the objects in the directory are processed.
+ *
+ * Any callback that is NULL will be ignored. Callbacks returning non-zero
+ * will end the iteration.
+ *
+ * In the "buf" variant, "path" is a strbuf which will also be used as a
+ * scratch buffer, but restored to its original contents before
+ * the function returns.
+ */
+typedef int each_loose_object_fn(const struct object_id *oid,
+                                const char *path,
+                                void *data);
+typedef int each_loose_cruft_fn(const char *basename,
+                               const char *path,
+                               void *data);
+typedef int each_loose_subdir_fn(unsigned int nr,
+                                const char *path,
+                                void *data);
+int for_each_file_in_obj_subdir(unsigned int subdir_nr,
+                               struct strbuf *path,
+                               each_loose_object_fn obj_cb,
+                               each_loose_cruft_fn cruft_cb,
+                               each_loose_subdir_fn subdir_cb,
+                               void *data);
+int for_each_loose_file_in_objdir(const char *path,
+                                 each_loose_object_fn obj_cb,
+                                 each_loose_cruft_fn cruft_cb,
+                                 each_loose_subdir_fn subdir_cb,
+                                 void *data);
+int for_each_loose_file_in_objdir_buf(struct strbuf *path,
+                                     each_loose_object_fn obj_cb,
+                                     each_loose_cruft_fn cruft_cb,
+                                     each_loose_subdir_fn subdir_cb,
+                                     void *data);
+
+/* Flags for for_each_*_object() below. */
+enum for_each_object_flags {
+       /* Iterate only over local objects, not alternates. */
+       FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
+
+       /* Only iterate over packs obtained from the promisor remote. */
+       FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
+
+       /*
+        * Visit objects within a pack in packfile order rather than .idx order
+        */
+       FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
+};
+
+/*
+ * Iterate over all accessible loose objects without respect to
+ * reachability. By default, this includes both local and alternate objects.
+ * The order in which objects are visited is unspecified.
+ *
+ * Any flags specific to packs are ignored.
+ */
+int for_each_loose_object(each_loose_object_fn, void *,
+                         enum for_each_object_flags flags);
+
+/*
+ * Iterate over all accessible packed objects without respect to reachability.
+ * By default, this includes both local and alternate packs.
+ *
+ * Note that some objects may appear twice if they are found in multiple packs.
+ * Each pack is visited in an unspecified order. By default, objects within a
+ * pack are visited in pack-idx order (i.e., sorted by oid).
+ */
+typedef int each_packed_object_fn(const struct object_id *oid,
+                                 struct packed_git *pack,
+                                 uint32_t pos,
+                                 void *data);
+int for_each_object_in_pack(struct packed_git *p,
+                           each_packed_object_fn, void *data,
+                           enum for_each_object_flags flags);
+int for_each_packed_object(each_packed_object_fn, void *,
+                          enum for_each_object_flags flags);
+
 #endif /* OBJECT_STORE_H */
index 10d167825ea8d8048640001f28750dd0834aa169..51c45945156c421ada403139faefdf145918f4f7 100644 (file)
--- a/object.c
+++ b/object.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "object.h"
 #include "replace-object.h"
+#include "object-store.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
@@ -8,6 +9,7 @@
 #include "alloc.h"
 #include "object-store.h"
 #include "packfile.h"
+#include "commit-graph.h"
 
 unsigned int get_max_object_index(void)
 {
@@ -49,7 +51,7 @@ int type_from_string_gently(const char *str, ssize_t len, int gentle)
        if (gentle)
                return -1;
 
-       die("invalid object type \"%s\"", str);
+       die(_("invalid object type \"%s\""), str);
 }
 
 /*
@@ -83,21 +85,20 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
  * Look up the record for the given sha1 in the hash map stored in
  * obj_hash.  Return NULL if it was not found.
  */
-struct object *lookup_object(const unsigned char *sha1)
+struct object *lookup_object(struct repository *r, const unsigned char *sha1)
 {
        unsigned int i, first;
        struct object *obj;
 
-       if (!the_repository->parsed_objects->obj_hash)
+       if (!r->parsed_objects->obj_hash)
                return NULL;
 
-       first = i = hash_obj(sha1,
-                            the_repository->parsed_objects->obj_hash_size);
-       while ((obj = the_repository->parsed_objects->obj_hash[i]) != NULL) {
+       first = i = hash_obj(sha1, r->parsed_objects->obj_hash_size);
+       while ((obj = r->parsed_objects->obj_hash[i]) != NULL) {
                if (!hashcmp(sha1, obj->oid.hash))
                        break;
                i++;
-               if (i == the_repository->parsed_objects->obj_hash_size)
+               if (i == r->parsed_objects->obj_hash_size)
                        i = 0;
        }
        if (obj && i != first) {
@@ -106,8 +107,8 @@ struct object *lookup_object(const unsigned char *sha1)
                 * that we do not need to walk the hash table the next
                 * time we look for it.
                 */
-               SWAP(the_repository->parsed_objects->obj_hash[i],
-                    the_repository->parsed_objects->obj_hash[first]);
+               SWAP(r->parsed_objects->obj_hash[i],
+                    r->parsed_objects->obj_hash[first]);
        }
        return obj;
 }
@@ -157,19 +158,19 @@ void *create_object(struct repository *r, const unsigned char *sha1, void *o)
        return obj;
 }
 
-void *object_as_type(struct object *obj, enum object_type type, int quiet)
+void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet)
 {
        if (obj->type == type)
                return obj;
        else if (obj->type == OBJ_NONE) {
                if (type == OBJ_COMMIT)
-                       ((struct commit *)obj)->index = alloc_commit_index(the_repository);
+                       ((struct commit *)obj)->index = alloc_commit_index(r);
                obj->type = type;
                return obj;
        }
        else {
                if (!quiet)
-                       error("object %s is a %s, not a %s",
+                       error(_("object %s is a %s, not a %s"),
                              oid_to_hex(&obj->oid),
                              type_name(obj->type), type_name(type));
                return NULL;
@@ -178,28 +179,28 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
 
 struct object *lookup_unknown_object(const unsigned char *sha1)
 {
-       struct object *obj = lookup_object(sha1);
+       struct object *obj = lookup_object(the_repository, sha1);
        if (!obj)
                obj = create_object(the_repository, sha1,
                                    alloc_object_node(the_repository));
        return obj;
 }
 
-struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
+struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
 {
        struct object *obj;
        *eaten_p = 0;
 
        obj = NULL;
        if (type == OBJ_BLOB) {
-               struct blob *blob = lookup_blob(oid);
+               struct blob *blob = lookup_blob(r, oid);
                if (blob) {
                        if (parse_blob_buffer(blob, buffer, size))
                                return NULL;
                        obj = &blob->object;
                }
        } else if (type == OBJ_TREE) {
-               struct tree *tree = lookup_tree(oid);
+               struct tree *tree = lookup_tree(r, oid);
                if (tree) {
                        obj = &tree->object;
                        if (!tree->buffer)
@@ -211,25 +212,25 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type
                        }
                }
        } else if (type == OBJ_COMMIT) {
-               struct commit *commit = lookup_commit(oid);
+               struct commit *commit = lookup_commit(r, oid);
                if (commit) {
-                       if (parse_commit_buffer(commit, buffer, size, 1))
+                       if (parse_commit_buffer(r, commit, buffer, size, 1))
                                return NULL;
-                       if (!get_cached_commit_buffer(commit, NULL)) {
-                               set_commit_buffer(commit, buffer, size);
+                       if (!get_cached_commit_buffer(r, commit, NULL)) {
+                               set_commit_buffer(r, commit, buffer, size);
                                *eaten_p = 1;
                        }
                        obj = &commit->object;
                }
        } else if (type == OBJ_TAG) {
-               struct tag *tag = lookup_tag(oid);
+               struct tag *tag = lookup_tag(r, oid);
                if (tag) {
-                       if (parse_tag_buffer(tag, buffer, size))
+                       if (parse_tag_buffer(r, tag, buffer, size))
                               return NULL;
                        obj = &tag->object;
                }
        } else {
-               warning("object %s has unknown type id %d", oid_to_hex(oid), type);
+               warning(_("object %s has unknown type id %d"), oid_to_hex(oid), type);
                obj = NULL;
        }
        return obj;
@@ -238,46 +239,47 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type
 struct object *parse_object_or_die(const struct object_id *oid,
                                   const char *name)
 {
-       struct object *o = parse_object(oid);
+       struct object *o = parse_object(the_repository, oid);
        if (o)
                return o;
 
        die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid));
 }
 
-struct object *parse_object(const struct object_id *oid)
+struct object *parse_object(struct repository *r, const struct object_id *oid)
 {
        unsigned long size;
        enum object_type type;
        int eaten;
-       const struct object_id *repl = lookup_replace_object(the_repository, oid);
+       const struct object_id *repl = lookup_replace_object(r, oid);
        void *buffer;
        struct object *obj;
 
-       obj = lookup_object(oid->hash);
+       obj = lookup_object(r, oid->hash);
        if (obj && obj->parsed)
                return obj;
 
        if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
            (!obj && has_object_file(oid) &&
-            oid_object_info(the_repository, oid, NULL) == OBJ_BLOB)) {
+            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));
+                       error(_("sha1 mismatch %s"), oid_to_hex(oid));
                        return NULL;
                }
-               parse_blob_buffer(lookup_blob(oid), NULL, 0);
-               return lookup_object(oid->hash);
+               parse_blob_buffer(lookup_blob(r, oid), NULL, 0);
+               return lookup_object(r, oid->hash);
        }
 
        buffer = read_object_file(oid, &type, &size);
        if (buffer) {
                if (check_object_signature(repl, buffer, size, type_name(type)) < 0) {
                        free(buffer);
-                       error("sha1 mismatch %s", oid_to_hex(repl));
+                       error(_("sha1 mismatch %s"), oid_to_hex(repl));
                        return NULL;
                }
 
-               obj = parse_object_buffer(oid, type, size, buffer, &eaten);
+               obj = parse_object_buffer(r, oid, type, size,
+                                         buffer, &eaten);
                if (!eaten)
                        free(buffer);
                return obj;
@@ -463,6 +465,11 @@ struct parsed_object_pool *parsed_object_pool_new(void)
        o->tag_state = allocate_alloc_state();
        o->object_state = allocate_alloc_state();
 
+       o->is_shallow = -1;
+       o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
+
+       o->buffer_slab = allocate_commit_buffer_slab();
+
        return o;
 }
 
@@ -501,6 +508,10 @@ void raw_object_store_clear(struct raw_object_store *o)
        oidmap_free(o->replace_map, 1);
        FREE_AND_NULL(o->replace_map);
 
+       free_commit_graph(o->commit_graph);
+       o->commit_graph = NULL;
+       o->commit_graph_attempted = 0;
+
        free_alt_odbs(o);
        o->alt_odb_tail = NULL;
 
@@ -537,6 +548,9 @@ void parsed_object_pool_clear(struct parsed_object_pool *o)
        FREE_AND_NULL(o->obj_hash);
        o->obj_hash_size = 0;
 
+       free_commit_buffer_slab(o->buffer_slab);
+       o->buffer_slab = NULL;
+
        clear_alloc_state(o->blob_state);
        clear_alloc_state(o->tree_state);
        clear_alloc_state(o->commit_state);
index 47d1b4902263c4059d8b27e17c7d7fc042dc6771..177b1a4571fb60f75d523124c09c133c2f5c84e6 100644 (file)
--- a/object.h
+++ b/object.h
@@ -1,6 +1,8 @@
 #ifndef OBJECT_H
 #define OBJECT_H
 
+struct buffer_slab;
+
 struct parsed_object_pool {
        struct object **obj_hash;
        int nr_objs, obj_hash_size;
@@ -12,6 +14,18 @@ struct parsed_object_pool {
        struct alloc_state *tag_state;
        struct alloc_state *object_state;
        unsigned commit_count;
+
+       /* parent substitutions from .git/info/grafts and .git/shallow */
+       struct commit_graft **grafts;
+       int grafts_alloc, grafts_nr;
+
+       int is_shallow;
+       struct stat_validity *shallow_stat;
+       char *alternate_shallow_file;
+
+       int commit_graft_prepared;
+
+       struct buffer_slab *buffer_slab;
 };
 
 struct parsed_object_pool *parsed_object_pool_new(void);
@@ -43,8 +57,9 @@ struct object_array {
 
 /*
  * object flag allocation:
- * revision.h:               0---------10                                26
- * fetch-pack.c:             0----5
+ * revision.h:               0---------10                              2526
+ * fetch-pack.c:             01
+ * negotiator/default.c:       2--5
  * walker.c:                 0-2
  * upload-pack.c:                4       11----------------19
  * builtin/blame.c:                        12-13
@@ -99,18 +114,18 @@ extern struct object *get_indexed_object(unsigned int);
  * half-initialised objects, the caller is expected to initialize them
  * by calling parse_object() on them.
  */
-struct object *lookup_object(const unsigned char *sha1);
+struct object *lookup_object(struct repository *r, const unsigned char *sha1);
 
 extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
 
-void *object_as_type(struct object *obj, enum object_type type, int quiet);
+void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet);
 
 /*
  * Returns the object, having parsed it to find out what it is.
  *
  * Returns NULL if the object is missing or corrupt.
  */
-struct object *parse_object(const struct object_id *oid);
+struct object *parse_object(struct repository *r, const struct object_id *oid);
 
 /*
  * Like parse_object, but will die() instead of returning NULL. If the
@@ -123,7 +138,7 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name
  * parsing it.  eaten_p indicates if the object has a borrowed copy
  * of buffer and the caller should not free() it.
  */
-struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
+struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
 
 /** Returns the object, with potentially excess memory allocated. **/
 struct object *lookup_unknown_object(const unsigned  char *sha1);
index 7b2dc3e7dc768a2d2405a9ae3b1d13f86069a93d..d977e9bacb19ed766dd0a501b6fbcae800bb4ae0 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tag.h"
 #include "diff.h"
@@ -360,11 +361,17 @@ static int date_compare(const void *_a, const void *_b)
 
 void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack)
 {
-       if (prepare_bitmap_git() < 0)
+       struct bitmap_index *bitmap_git;
+       if (!(bitmap_git = prepare_bitmap_git()))
                return;
 
        writer.reused = kh_init_sha1();
-       rebuild_existing_bitmaps(to_pack, writer.reused, writer.show_progress);
+       rebuild_existing_bitmaps(bitmap_git, to_pack, writer.reused,
+                                writer.show_progress);
+       /*
+        * NEEDSWORK: rebuild_existing_bitmaps() makes writer.reused reference
+        * some bitmaps in bitmap_git, so we can't free the latter.
+        */
 }
 
 static struct ewah_bitmap *find_reused_bitmap(const unsigned char *sha1)
index 18f8b22aeb422bb81999e1e564006daf8b64f637..f0a1937a1cc5fbb13fc705df8d193a43a0648198 100644 (file)
@@ -25,14 +25,14 @@ struct stored_bitmap {
 };
 
 /*
- * The currently active bitmap index. By design, repositories only have
+ * The active bitmap index for a repository. By design, repositories only have
  * a single bitmap index available (the index for the biggest packfile in
  * the repository), since bitmap indexes need full closure.
  *
  * If there is more than one bitmap index available (e.g. because of alternates),
  * the active bitmap index is the largest one.
  */
-static struct bitmap_index {
+struct bitmap_index {
        /* Packfile to which this bitmap index belongs to */
        struct packed_git *pack;
 
@@ -66,7 +66,7 @@ static struct bitmap_index {
        /* Number of bitmapped commits */
        uint32_t entry_count;
 
-       /* Name-hash cache (or NULL if not present). */
+       /* If not NULL, this is a name-hash cache pointing into map. */
        uint32_t *hashes;
 
        /*
@@ -90,8 +90,7 @@ static struct bitmap_index {
        unsigned int version;
 
        unsigned loaded : 1;
-
-} bitmap_git;
+};
 
 static struct ewah_bitmap *lookup_stored_bitmap(struct stored_bitmap *st)
 {
@@ -259,7 +258,7 @@ static char *pack_bitmap_filename(struct packed_git *p)
        return xstrfmt("%.*s.bitmap", (int)len, p->pack_name);
 }
 
-static int open_pack_bitmap_1(struct packed_git *packfile)
+static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git *packfile)
 {
        int fd;
        struct stat st;
@@ -280,117 +279,122 @@ static int open_pack_bitmap_1(struct packed_git *packfile)
                return -1;
        }
 
-       if (bitmap_git.pack) {
+       if (bitmap_git->pack) {
                warning("ignoring extra bitmap file: %s", packfile->pack_name);
                close(fd);
                return -1;
        }
 
-       bitmap_git.pack = packfile;
-       bitmap_git.map_size = xsize_t(st.st_size);
-       bitmap_git.map = xmmap(NULL, bitmap_git.map_size, PROT_READ, MAP_PRIVATE, fd, 0);
-       bitmap_git.map_pos = 0;
+       bitmap_git->pack = packfile;
+       bitmap_git->map_size = xsize_t(st.st_size);
+       bitmap_git->map = xmmap(NULL, bitmap_git->map_size, PROT_READ, MAP_PRIVATE, fd, 0);
+       bitmap_git->map_pos = 0;
        close(fd);
 
-       if (load_bitmap_header(&bitmap_git) < 0) {
-               munmap(bitmap_git.map, bitmap_git.map_size);
-               bitmap_git.map = NULL;
-               bitmap_git.map_size = 0;
+       if (load_bitmap_header(bitmap_git) < 0) {
+               munmap(bitmap_git->map, bitmap_git->map_size);
+               bitmap_git->map = NULL;
+               bitmap_git->map_size = 0;
                return -1;
        }
 
        return 0;
 }
 
-static int load_pack_bitmap(void)
+static int load_pack_bitmap(struct bitmap_index *bitmap_git)
 {
-       assert(bitmap_git.map && !bitmap_git.loaded);
+       assert(bitmap_git->map && !bitmap_git->loaded);
 
-       bitmap_git.bitmaps = kh_init_sha1();
-       bitmap_git.ext_index.positions = kh_init_sha1_pos();
-       load_pack_revindex(bitmap_git.pack);
+       bitmap_git->bitmaps = kh_init_sha1();
+       bitmap_git->ext_index.positions = kh_init_sha1_pos();
+       load_pack_revindex(bitmap_git->pack);
 
-       if (!(bitmap_git.commits = read_bitmap_1(&bitmap_git)) ||
-               !(bitmap_git.trees = read_bitmap_1(&bitmap_git)) ||
-               !(bitmap_git.blobs = read_bitmap_1(&bitmap_git)) ||
-               !(bitmap_git.tags = read_bitmap_1(&bitmap_git)))
+       if (!(bitmap_git->commits = read_bitmap_1(bitmap_git)) ||
+               !(bitmap_git->trees = read_bitmap_1(bitmap_git)) ||
+               !(bitmap_git->blobs = read_bitmap_1(bitmap_git)) ||
+               !(bitmap_git->tags = read_bitmap_1(bitmap_git)))
                goto failed;
 
-       if (load_bitmap_entries_v1(&bitmap_git) < 0)
+       if (load_bitmap_entries_v1(bitmap_git) < 0)
                goto failed;
 
-       bitmap_git.loaded = 1;
+       bitmap_git->loaded = 1;
        return 0;
 
 failed:
-       munmap(bitmap_git.map, bitmap_git.map_size);
-       bitmap_git.map = NULL;
-       bitmap_git.map_size = 0;
+       munmap(bitmap_git->map, bitmap_git->map_size);
+       bitmap_git->map = NULL;
+       bitmap_git->map_size = 0;
        return -1;
 }
 
-static int open_pack_bitmap(void)
+static int open_pack_bitmap(struct bitmap_index *bitmap_git)
 {
        struct packed_git *p;
        int ret = -1;
 
-       assert(!bitmap_git.map && !bitmap_git.loaded);
+       assert(!bitmap_git->map && !bitmap_git->loaded);
 
        for (p = get_packed_git(the_repository); p; p = p->next) {
-               if (open_pack_bitmap_1(p) == 0)
+               if (open_pack_bitmap_1(bitmap_git, p) == 0)
                        ret = 0;
        }
 
        return ret;
 }
 
-int prepare_bitmap_git(void)
+struct bitmap_index *prepare_bitmap_git(void)
 {
-       if (bitmap_git.loaded)
-               return 0;
+       struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
 
-       if (!open_pack_bitmap())
-               return load_pack_bitmap();
+       if (!open_pack_bitmap(bitmap_git) && !load_pack_bitmap(bitmap_git))
+               return bitmap_git;
 
-       return -1;
+       free_bitmap_index(bitmap_git);
+       return NULL;
 }
 
 struct include_data {
+       struct bitmap_index *bitmap_git;
        struct bitmap *base;
        struct bitmap *seen;
 };
 
-static inline int bitmap_position_extended(const unsigned char *sha1)
+static inline int bitmap_position_extended(struct bitmap_index *bitmap_git,
+                                          const unsigned char *sha1)
 {
-       khash_sha1_pos *positions = bitmap_git.ext_index.positions;
+       khash_sha1_pos *positions = bitmap_git->ext_index.positions;
        khiter_t pos = kh_get_sha1_pos(positions, sha1);
 
        if (pos < kh_end(positions)) {
                int bitmap_pos = kh_value(positions, pos);
-               return bitmap_pos + bitmap_git.pack->num_objects;
+               return bitmap_pos + bitmap_git->pack->num_objects;
        }
 
        return -1;
 }
 
-static inline int bitmap_position_packfile(const unsigned char *sha1)
+static inline int bitmap_position_packfile(struct bitmap_index *bitmap_git,
+                                          const unsigned char *sha1)
 {
-       off_t offset = find_pack_entry_one(sha1, bitmap_git.pack);
+       off_t offset = find_pack_entry_one(sha1, bitmap_git->pack);
        if (!offset)
                return -1;
 
-       return find_revindex_position(bitmap_git.pack, offset);
+       return find_revindex_position(bitmap_git->pack, offset);
 }
 
-static int bitmap_position(const unsigned char *sha1)
+static int bitmap_position(struct bitmap_index *bitmap_git,
+                          const unsigned char *sha1)
 {
-       int pos = bitmap_position_packfile(sha1);
-       return (pos >= 0) ? pos : bitmap_position_extended(sha1);
+       int pos = bitmap_position_packfile(bitmap_git, sha1);
+       return (pos >= 0) ? pos : bitmap_position_extended(bitmap_git, sha1);
 }
 
-static int ext_index_add_object(struct object *object, const char *name)
+static int ext_index_add_object(struct bitmap_index *bitmap_git,
+                               struct object *object, const char *name)
 {
-       struct eindex *eindex = &bitmap_git.ext_index;
+       struct eindex *eindex = &bitmap_git->ext_index;
 
        khiter_t hash_pos;
        int hash_ret;
@@ -413,27 +417,34 @@ static int ext_index_add_object(struct object *object, const char *name)
                bitmap_pos = kh_value(eindex->positions, hash_pos);
        }
 
-       return bitmap_pos + bitmap_git.pack->num_objects;
+       return bitmap_pos + bitmap_git->pack->num_objects;
 }
 
-static void show_object(struct object *object, const char *name, void *data)
+struct bitmap_show_data {
+       struct bitmap_index *bitmap_git;
+       struct bitmap *base;
+};
+
+static void show_object(struct object *object, const char *name, void *data_)
 {
-       struct bitmap *base = data;
+       struct bitmap_show_data *data = data_;
        int bitmap_pos;
 
-       bitmap_pos = bitmap_position(object->oid.hash);
+       bitmap_pos = bitmap_position(data->bitmap_git, object->oid.hash);
 
        if (bitmap_pos < 0)
-               bitmap_pos = ext_index_add_object(object, name);
+               bitmap_pos = ext_index_add_object(data->bitmap_git, object,
+                                                 name);
 
-       bitmap_set(base, bitmap_pos);
+       bitmap_set(data->base, bitmap_pos);
 }
 
 static void show_commit(struct commit *commit, void *data)
 {
 }
 
-static int add_to_include_set(struct include_data *data,
+static int add_to_include_set(struct bitmap_index *bitmap_git,
+                             struct include_data *data,
                              const unsigned char *sha1,
                              int bitmap_pos)
 {
@@ -445,9 +456,9 @@ static int add_to_include_set(struct include_data *data,
        if (bitmap_get(data->base, bitmap_pos))
                return 0;
 
-       hash_pos = kh_get_sha1(bitmap_git.bitmaps, sha1);
-       if (hash_pos < kh_end(bitmap_git.bitmaps)) {
-               struct stored_bitmap *st = kh_value(bitmap_git.bitmaps, hash_pos);
+       hash_pos = kh_get_sha1(bitmap_git->bitmaps, sha1);
+       if (hash_pos < kh_end(bitmap_git->bitmaps)) {
+               struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, hash_pos);
                bitmap_or_ewah(data->base, lookup_stored_bitmap(st));
                return 0;
        }
@@ -461,11 +472,14 @@ static int should_include(struct commit *commit, void *_data)
        struct include_data *data = _data;
        int bitmap_pos;
 
-       bitmap_pos = bitmap_position(commit->object.oid.hash);
+       bitmap_pos = bitmap_position(data->bitmap_git, commit->object.oid.hash);
        if (bitmap_pos < 0)
-               bitmap_pos = ext_index_add_object((struct object *)commit, NULL);
+               bitmap_pos = ext_index_add_object(data->bitmap_git,
+                                                 (struct object *)commit,
+                                                 NULL);
 
-       if (!add_to_include_set(data, commit->object.oid.hash, bitmap_pos)) {
+       if (!add_to_include_set(data->bitmap_git, data, commit->object.oid.hash,
+                               bitmap_pos)) {
                struct commit_list *parent = commit->parents;
 
                while (parent) {
@@ -479,7 +493,8 @@ static int should_include(struct commit *commit, void *_data)
        return 1;
 }
 
-static struct bitmap *find_objects(struct rev_info *revs,
+static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
+                                  struct rev_info *revs,
                                   struct object_list *roots,
                                   struct bitmap *seen)
 {
@@ -501,10 +516,10 @@ static struct bitmap *find_objects(struct rev_info *revs,
                roots = roots->next;
 
                if (object->type == OBJ_COMMIT) {
-                       khiter_t pos = kh_get_sha1(bitmap_git.bitmaps, object->oid.hash);
+                       khiter_t pos = kh_get_sha1(bitmap_git->bitmaps, object->oid.hash);
 
-                       if (pos < kh_end(bitmap_git.bitmaps)) {
-                               struct stored_bitmap *st = kh_value(bitmap_git.bitmaps, pos);
+                       if (pos < kh_end(bitmap_git->bitmaps)) {
+                               struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, pos);
                                struct ewah_bitmap *or_with = lookup_stored_bitmap(st);
 
                                if (base == NULL)
@@ -543,7 +558,7 @@ static struct bitmap *find_objects(struct rev_info *revs,
                int pos;
 
                roots = roots->next;
-               pos = bitmap_position(object->oid.hash);
+               pos = bitmap_position(bitmap_git, object->oid.hash);
 
                if (pos < 0 || base == NULL || !bitmap_get(base, pos)) {
                        object->flags &= ~UNINTERESTING;
@@ -556,10 +571,12 @@ static struct bitmap *find_objects(struct rev_info *revs,
 
        if (needs_walk) {
                struct include_data incdata;
+               struct bitmap_show_data show_data;
 
                if (base == NULL)
                        base = bitmap_new();
 
+               incdata.bitmap_git = bitmap_git;
                incdata.base = base;
                incdata.seen = seen;
 
@@ -569,22 +586,27 @@ static struct bitmap *find_objects(struct rev_info *revs,
                if (prepare_revision_walk(revs))
                        die("revision walk setup failed");
 
-               traverse_commit_list(revs, show_commit, show_object, base);
+               show_data.bitmap_git = bitmap_git;
+               show_data.base = base;
+
+               traverse_commit_list(revs, show_commit, show_object,
+                                    &show_data);
        }
 
        return base;
 }
 
-static void show_extended_objects(struct bitmap *objects,
+static void show_extended_objects(struct bitmap_index *bitmap_git,
                                  show_reachable_fn show_reach)
 {
-       struct eindex *eindex = &bitmap_git.ext_index;
+       struct bitmap *objects = bitmap_git->result;
+       struct eindex *eindex = &bitmap_git->ext_index;
        uint32_t i;
 
        for (i = 0; i < eindex->count; ++i) {
                struct object *obj;
 
-               if (!bitmap_get(objects, bitmap_git.pack->num_objects + i))
+               if (!bitmap_get(objects, bitmap_git->pack->num_objects + i))
                        continue;
 
                obj = eindex->objects[i];
@@ -593,7 +615,7 @@ static void show_extended_objects(struct bitmap *objects,
 }
 
 static void show_objects_for_type(
-       struct bitmap *objects,
+       struct bitmap_index *bitmap_git,
        struct ewah_bitmap *type_filter,
        enum object_type object_type,
        show_reachable_fn show_reach)
@@ -604,7 +626,9 @@ static void show_objects_for_type(
        struct ewah_iterator it;
        eword_t filter;
 
-       if (bitmap_git.reuse_objects == bitmap_git.pack->num_objects)
+       struct bitmap *objects = bitmap_git->result;
+
+       if (bitmap_git->reuse_objects == bitmap_git->pack->num_objects)
                return;
 
        ewah_iterator_init(&it, type_filter);
@@ -622,16 +646,16 @@ static void show_objects_for_type(
 
                        offset += ewah_bit_ctz64(word >> offset);
 
-                       if (pos + offset < bitmap_git.reuse_objects)
+                       if (pos + offset < bitmap_git->reuse_objects)
                                continue;
 
-                       entry = &bitmap_git.pack->revindex[pos + offset];
-                       nth_packed_object_oid(&oid, bitmap_git.pack, entry->nr);
+                       entry = &bitmap_git->pack->revindex[pos + offset];
+                       nth_packed_object_oid(&oid, bitmap_git->pack, entry->nr);
 
-                       if (bitmap_git.hashes)
-                               hash = get_be32(bitmap_git.hashes + entry->nr);
+                       if (bitmap_git->hashes)
+                               hash = get_be32(bitmap_git->hashes + entry->nr);
 
-                       show_reach(&oid, object_type, 0, hash, bitmap_git.pack, entry->offset);
+                       show_reach(&oid, object_type, 0, hash, bitmap_git->pack, entry->offset);
                }
 
                pos += BITS_IN_EWORD;
@@ -639,20 +663,21 @@ static void show_objects_for_type(
        }
 }
 
-static int in_bitmapped_pack(struct object_list *roots)
+static int in_bitmapped_pack(struct bitmap_index *bitmap_git,
+                            struct object_list *roots)
 {
        while (roots) {
                struct object *object = roots->item;
                roots = roots->next;
 
-               if (find_pack_entry_one(object->oid.hash, bitmap_git.pack) > 0)
+               if (find_pack_entry_one(object->oid.hash, bitmap_git->pack) > 0)
                        return 1;
        }
 
        return 0;
 }
 
-int prepare_bitmap_walk(struct rev_info *revs)
+struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
 {
        unsigned int i;
 
@@ -662,12 +687,11 @@ int prepare_bitmap_walk(struct rev_info *revs)
        struct bitmap *wants_bitmap = NULL;
        struct bitmap *haves_bitmap = NULL;
 
-       if (!bitmap_git.loaded) {
-               /* try to open a bitmapped pack, but don't parse it yet
-                * because we may not need to use it */
-               if (open_pack_bitmap() < 0)
-                       return -1;
-       }
+       struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
+       /* try to open a bitmapped pack, but don't parse it yet
+        * because we may not need to use it */
+       if (open_pack_bitmap(bitmap_git) < 0)
+               goto cleanup;
 
        for (i = 0; i < revs->pending.nr; ++i) {
                struct object *object = revs->pending.objects[i].item;
@@ -699,26 +723,26 @@ int prepare_bitmap_walk(struct rev_info *revs)
         * in the packfile that has a bitmap, we don't have anything to
         * optimize here
         */
-       if (haves && !in_bitmapped_pack(haves))
-               return -1;
+       if (haves && !in_bitmapped_pack(bitmap_git, haves))
+               goto cleanup;
 
        /* if we don't want anything, we're done here */
        if (!wants)
-               return -1;
+               goto cleanup;
 
        /*
         * now we're going to use bitmaps, so load the actual bitmap entries
         * from disk. this is the point of no return; after this the rev_list
         * becomes invalidated and we must perform the revwalk through bitmaps
         */
-       if (!bitmap_git.loaded && load_pack_bitmap() < 0)
-               return -1;
+       if (!bitmap_git->loaded && load_pack_bitmap(bitmap_git) < 0)
+               goto cleanup;
 
        object_array_clear(&revs->pending);
 
        if (haves) {
                revs->ignore_missing_links = 1;
-               haves_bitmap = find_objects(revs, haves, NULL);
+               haves_bitmap = find_objects(bitmap_git, revs, haves, NULL);
                reset_revision_walk();
                revs->ignore_missing_links = 0;
 
@@ -726,7 +750,7 @@ int prepare_bitmap_walk(struct rev_info *revs)
                        BUG("failed to perform bitmap walk");
        }
 
-       wants_bitmap = find_objects(revs, wants, haves_bitmap);
+       wants_bitmap = find_objects(bitmap_git, revs, wants, haves_bitmap);
 
        if (!wants_bitmap)
                BUG("failed to perform bitmap walk");
@@ -734,13 +758,18 @@ int prepare_bitmap_walk(struct rev_info *revs)
        if (haves_bitmap)
                bitmap_and_not(wants_bitmap, haves_bitmap);
 
-       bitmap_git.result = wants_bitmap;
+       bitmap_git->result = wants_bitmap;
 
        bitmap_free(haves_bitmap);
-       return 0;
+       return bitmap_git;
+
+cleanup:
+       free_bitmap_index(bitmap_git);
+       return NULL;
 }
 
-int reuse_partial_packfile_from_bitmap(struct packed_git **packfile,
+int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
+                                      struct packed_git **packfile,
                                       uint32_t *entries,
                                       off_t *up_to)
 {
@@ -750,7 +779,7 @@ int reuse_partial_packfile_from_bitmap(struct packed_git **packfile,
         */
        static const double REUSE_PERCENT = 0.9;
 
-       struct bitmap *result = bitmap_git.result;
+       struct bitmap *result = bitmap_git->result;
        uint32_t reuse_threshold;
        uint32_t i, reuse_objects = 0;
 
@@ -770,8 +799,8 @@ int reuse_partial_packfile_from_bitmap(struct packed_git **packfile,
                const unsigned char *sha1;
                struct revindex_entry *entry;
 
-               entry = &bitmap_git.reverse_index->revindex[reuse_objects];
-               sha1 = nth_packed_object_sha1(bitmap_git.pack, entry->nr);
+               entry = &bitmap_git->reverse_index->revindex[reuse_objects];
+               sha1 = nth_packed_object_sha1(bitmap_git->pack, entry->nr);
 
                fprintf(stderr, "Failed to reuse at %d (%016llx)\n",
                        reuse_objects, result->words[i]);
@@ -782,48 +811,50 @@ int reuse_partial_packfile_from_bitmap(struct packed_git **packfile,
        if (!reuse_objects)
                return -1;
 
-       if (reuse_objects >= bitmap_git.pack->num_objects) {
-               bitmap_git.reuse_objects = *entries = bitmap_git.pack->num_objects;
+       if (reuse_objects >= bitmap_git->pack->num_objects) {
+               bitmap_git->reuse_objects = *entries = bitmap_git->pack->num_objects;
                *up_to = -1; /* reuse the full pack */
-               *packfile = bitmap_git.pack;
+               *packfile = bitmap_git->pack;
                return 0;
        }
 
-       reuse_threshold = bitmap_popcount(bitmap_git.result) * REUSE_PERCENT;
+       reuse_threshold = bitmap_popcount(bitmap_git->result) * REUSE_PERCENT;
 
        if (reuse_objects < reuse_threshold)
                return -1;
 
-       bitmap_git.reuse_objects = *entries = reuse_objects;
-       *up_to = bitmap_git.pack->revindex[reuse_objects].offset;
-       *packfile = bitmap_git.pack;
+       bitmap_git->reuse_objects = *entries = reuse_objects;
+       *up_to = bitmap_git->pack->revindex[reuse_objects].offset;
+       *packfile = bitmap_git->pack;
 
        return 0;
 }
 
-void traverse_bitmap_commit_list(show_reachable_fn show_reachable)
+void traverse_bitmap_commit_list(struct bitmap_index *bitmap_git,
+                                show_reachable_fn show_reachable)
 {
-       assert(bitmap_git.result);
+       assert(bitmap_git->result);
 
-       show_objects_for_type(bitmap_git.result, bitmap_git.commits,
+       show_objects_for_type(bitmap_git, bitmap_git->commits,
                OBJ_COMMIT, show_reachable);
-       show_objects_for_type(bitmap_git.result, bitmap_git.trees,
+       show_objects_for_type(bitmap_git, bitmap_git->trees,
                OBJ_TREE, show_reachable);
-       show_objects_for_type(bitmap_git.result, bitmap_git.blobs,
+       show_objects_for_type(bitmap_git, bitmap_git->blobs,
                OBJ_BLOB, show_reachable);
-       show_objects_for_type(bitmap_git.result, bitmap_git.tags,
+       show_objects_for_type(bitmap_git, bitmap_git->tags,
                OBJ_TAG, show_reachable);
 
-       show_extended_objects(bitmap_git.result, show_reachable);
+       show_extended_objects(bitmap_git, show_reachable);
 
-       bitmap_free(bitmap_git.result);
-       bitmap_git.result = NULL;
+       bitmap_free(bitmap_git->result);
+       bitmap_git->result = NULL;
 }
 
-static uint32_t count_object_type(struct bitmap *objects,
+static uint32_t count_object_type(struct bitmap_index *bitmap_git,
                                  enum object_type type)
 {
-       struct eindex *eindex = &bitmap_git.ext_index;
+       struct bitmap *objects = bitmap_git->result;
+       struct eindex *eindex = &bitmap_git->ext_index;
 
        uint32_t i = 0, count = 0;
        struct ewah_iterator it;
@@ -831,19 +862,19 @@ static uint32_t count_object_type(struct bitmap *objects,
 
        switch (type) {
        case OBJ_COMMIT:
-               ewah_iterator_init(&it, bitmap_git.commits);
+               ewah_iterator_init(&it, bitmap_git->commits);
                break;
 
        case OBJ_TREE:
-               ewah_iterator_init(&it, bitmap_git.trees);
+               ewah_iterator_init(&it, bitmap_git->trees);
                break;
 
        case OBJ_BLOB:
-               ewah_iterator_init(&it, bitmap_git.blobs);
+               ewah_iterator_init(&it, bitmap_git->blobs);
                break;
 
        case OBJ_TAG:
-               ewah_iterator_init(&it, bitmap_git.tags);
+               ewah_iterator_init(&it, bitmap_git->tags);
                break;
 
        default:
@@ -857,32 +888,34 @@ static uint32_t count_object_type(struct bitmap *objects,
 
        for (i = 0; i < eindex->count; ++i) {
                if (eindex->objects[i]->type == type &&
-                       bitmap_get(objects, bitmap_git.pack->num_objects + i))
+                       bitmap_get(objects, bitmap_git->pack->num_objects + i))
                        count++;
        }
 
        return count;
 }
 
-void count_bitmap_commit_list(uint32_t *commits, uint32_t *trees,
+void count_bitmap_commit_list(struct bitmap_index *bitmap_git,
+                             uint32_t *commits, uint32_t *trees,
                              uint32_t *blobs, uint32_t *tags)
 {
-       assert(bitmap_git.result);
+       assert(bitmap_git->result);
 
        if (commits)
-               *commits = count_object_type(bitmap_git.result, OBJ_COMMIT);
+               *commits = count_object_type(bitmap_git, OBJ_COMMIT);
 
        if (trees)
-               *trees = count_object_type(bitmap_git.result, OBJ_TREE);
+               *trees = count_object_type(bitmap_git, OBJ_TREE);
 
        if (blobs)
-               *blobs = count_object_type(bitmap_git.result, OBJ_BLOB);
+               *blobs = count_object_type(bitmap_git, OBJ_BLOB);
 
        if (tags)
-               *tags = count_object_type(bitmap_git.result, OBJ_TAG);
+               *tags = count_object_type(bitmap_git, OBJ_TAG);
 }
 
 struct bitmap_test_data {
+       struct bitmap_index *bitmap_git;
        struct bitmap *base;
        struct progress *prg;
        size_t seen;
@@ -894,7 +927,7 @@ static void test_show_object(struct object *object, const char *name,
        struct bitmap_test_data *tdata = data;
        int bitmap_pos;
 
-       bitmap_pos = bitmap_position(object->oid.hash);
+       bitmap_pos = bitmap_position(tdata->bitmap_git, object->oid.hash);
        if (bitmap_pos < 0)
                die("Object not in bitmap: %s\n", oid_to_hex(&object->oid));
 
@@ -907,7 +940,8 @@ static void test_show_commit(struct commit *commit, void *data)
        struct bitmap_test_data *tdata = data;
        int bitmap_pos;
 
-       bitmap_pos = bitmap_position(commit->object.oid.hash);
+       bitmap_pos = bitmap_position(tdata->bitmap_git,
+                                    commit->object.oid.hash);
        if (bitmap_pos < 0)
                die("Object not in bitmap: %s\n", oid_to_hex(&commit->object.oid));
 
@@ -922,21 +956,22 @@ void test_bitmap_walk(struct rev_info *revs)
        khiter_t pos;
        size_t result_popcnt;
        struct bitmap_test_data tdata;
+       struct bitmap_index *bitmap_git;
 
-       if (prepare_bitmap_git())
+       if (!(bitmap_git = prepare_bitmap_git()))
                die("failed to load bitmap indexes");
 
        if (revs->pending.nr != 1)
                die("you must specify exactly one commit to test");
 
        fprintf(stderr, "Bitmap v%d test (%d entries loaded)\n",
-               bitmap_git.version, bitmap_git.entry_count);
+               bitmap_git->version, bitmap_git->entry_count);
 
        root = revs->pending.objects[0].item;
-       pos = kh_get_sha1(bitmap_git.bitmaps, root->oid.hash);
+       pos = kh_get_sha1(bitmap_git->bitmaps, root->oid.hash);
 
-       if (pos < kh_end(bitmap_git.bitmaps)) {
-               struct stored_bitmap *st = kh_value(bitmap_git.bitmaps, pos);
+       if (pos < kh_end(bitmap_git->bitmaps)) {
+               struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, pos);
                struct ewah_bitmap *bm = lookup_stored_bitmap(st);
 
                fprintf(stderr, "Found bitmap for %s. %d bits / %08x checksum\n",
@@ -957,6 +992,7 @@ void test_bitmap_walk(struct rev_info *revs)
        if (prepare_revision_walk(revs))
                die("revision walk setup failed");
 
+       tdata.bitmap_git = bitmap_git;
        tdata.base = bitmap_new();
        tdata.prg = start_progress("Verifying bitmap entries", result_popcnt);
        tdata.seen = 0;
@@ -970,7 +1006,7 @@ void test_bitmap_walk(struct rev_info *revs)
        else
                fprintf(stderr, "Mismatch!\n");
 
-       bitmap_free(result);
+       free_bitmap_index(bitmap_git);
 }
 
 static int rebuild_bitmap(uint32_t *reposition,
@@ -1004,7 +1040,8 @@ static int rebuild_bitmap(uint32_t *reposition,
        return 0;
 }
 
-int rebuild_existing_bitmaps(struct packing_data *mapping,
+int rebuild_existing_bitmaps(struct bitmap_index *bitmap_git,
+                            struct packing_data *mapping,
                             khash_sha1 *reused_bitmaps,
                             int show_progress)
 {
@@ -1017,10 +1054,7 @@ int rebuild_existing_bitmaps(struct packing_data *mapping,
        khiter_t hash_pos;
        int hash_ret;
 
-       if (prepare_bitmap_git() < 0)
-               return -1;
-
-       num_objects = bitmap_git.pack->num_objects;
+       num_objects = bitmap_git->pack->num_objects;
        reposition = xcalloc(num_objects, sizeof(uint32_t));
 
        for (i = 0; i < num_objects; ++i) {
@@ -1028,8 +1062,8 @@ int rebuild_existing_bitmaps(struct packing_data *mapping,
                struct revindex_entry *entry;
                struct object_entry *oe;
 
-               entry = &bitmap_git.pack->revindex[i];
-               sha1 = nth_packed_object_sha1(bitmap_git.pack, entry->nr);
+               entry = &bitmap_git->pack->revindex[i];
+               sha1 = nth_packed_object_sha1(bitmap_git->pack, entry->nr);
                oe = packlist_find(mapping, sha1, NULL);
 
                if (oe)
@@ -1042,7 +1076,7 @@ int rebuild_existing_bitmaps(struct packing_data *mapping,
        if (show_progress)
                progress = start_progress("Reusing bitmaps", 0);
 
-       kh_foreach_value(bitmap_git.bitmaps, stored, {
+       kh_foreach_value(bitmap_git->bitmaps, stored, {
                if (stored->flags & BITMAP_FLAG_REUSE) {
                        if (!rebuild_bitmap(reposition,
                                            lookup_stored_bitmap(stored),
@@ -1064,3 +1098,21 @@ int rebuild_existing_bitmaps(struct packing_data *mapping,
        bitmap_free(rebuild);
        return 0;
 }
+
+void free_bitmap_index(struct bitmap_index *b)
+{
+       if (!b)
+               return;
+
+       if (b->map)
+               munmap(b->map, b->map_size);
+       ewah_pool_free(b->commits);
+       ewah_pool_free(b->trees);
+       ewah_pool_free(b->blobs);
+       ewah_pool_free(b->tags);
+       kh_destroy_sha1(b->bitmaps);
+       free(b->ext_index.objects);
+       free(b->ext_index.hashes);
+       bitmap_free(b->result);
+       free(b);
+}
index 5ded2f139a6ccdab725ed5e568b1100906f4b736..4555907dee99fbf731b739c584837adbbe8270f1 100644 (file)
@@ -34,13 +34,21 @@ typedef int (*show_reachable_fn)(
        struct packed_git *found_pack,
        off_t found_offset);
 
-int prepare_bitmap_git(void);
-void count_bitmap_commit_list(uint32_t *commits, uint32_t *trees, uint32_t *blobs, uint32_t *tags);
-void traverse_bitmap_commit_list(show_reachable_fn show_reachable);
+struct bitmap_index;
+
+struct bitmap_index *prepare_bitmap_git(void);
+void count_bitmap_commit_list(struct bitmap_index *, uint32_t *commits,
+                             uint32_t *trees, uint32_t *blobs, uint32_t *tags);
+void traverse_bitmap_commit_list(struct bitmap_index *,
+                                show_reachable_fn show_reachable);
 void test_bitmap_walk(struct rev_info *revs);
-int prepare_bitmap_walk(struct rev_info *revs);
-int reuse_partial_packfile_from_bitmap(struct packed_git **packfile, uint32_t *entries, off_t *up_to);
-int rebuild_existing_bitmaps(struct packing_data *mapping, khash_sha1 *reused_bitmaps, int show_progress);
+struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs);
+int reuse_partial_packfile_from_bitmap(struct bitmap_index *,
+                                      struct packed_git **packfile,
+                                      uint32_t *entries, off_t *up_to);
+int rebuild_existing_bitmaps(struct bitmap_index *, struct packing_data *mapping,
+                            khash_sha1 *reused_bitmaps, int show_progress);
+void free_bitmap_index(struct bitmap_index *);
 
 void bitmap_writer_show_progress(int show);
 void bitmap_writer_set_checksum(unsigned char *sha1);
index 7cd45aa4b2a0e098d597e4dea633d9b097b9b94c..ebcb5742ec748d730f8d730ad8b0744e9094d121 100644 (file)
@@ -1885,26 +1885,38 @@ int has_pack_index(const unsigned char *sha1)
        return 1;
 }
 
-int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn cb, void *data)
+int for_each_object_in_pack(struct packed_git *p,
+                           each_packed_object_fn cb, void *data,
+                           enum for_each_object_flags flags)
 {
        uint32_t i;
        int r = 0;
 
+       if (flags & FOR_EACH_OBJECT_PACK_ORDER)
+               load_pack_revindex(p);
+
        for (i = 0; i < p->num_objects; i++) {
+               uint32_t pos;
                struct object_id oid;
 
-               if (!nth_packed_object_oid(&oid, p, i))
+               if (flags & FOR_EACH_OBJECT_PACK_ORDER)
+                       pos = p->revindex[i].nr;
+               else
+                       pos = i;
+
+               if (!nth_packed_object_oid(&oid, p, pos))
                        return error("unable to get sha1 of object %u in %s",
-                                    i, p->pack_name);
+                                    pos, p->pack_name);
 
-               r = cb(&oid, p, i, data);
+               r = cb(&oid, p, pos, data);
                if (r)
                        break;
        }
        return r;
 }
 
-int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)
+int for_each_packed_object(each_packed_object_fn cb, void *data,
+                          enum for_each_object_flags flags)
 {
        struct packed_git *p;
        int r = 0;
@@ -1921,7 +1933,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)
                        pack_errors = 1;
                        continue;
                }
-               r = for_each_object_in_pack(p, cb, data);
+               r = for_each_object_in_pack(p, cb, data, flags);
                if (r)
                        break;
        }
@@ -1934,7 +1946,7 @@ static int add_promisor_object(const struct object_id *oid,
                               void *set_)
 {
        struct oidset *set = set_;
-       struct object *obj = parse_object(oid);
+       struct object *obj = parse_object(the_repository, oid);
        if (!obj)
                return 1;
 
index e0a38aba9321deae1d64aea7cd87067fde240b10..630f35cf31ef74975c04d17820314a85bba675af 100644 (file)
@@ -1,8 +1,13 @@
 #ifndef PACKFILE_H
 #define PACKFILE_H
 
+#include "cache.h"
 #include "oidset.h"
 
+/* in object-store.h */
+struct packed_git;
+struct object_info;
+
 /*
  * Generate the filename to be used for a pack file with checksum "sha1" and
  * extension "ext". The result is written into the strbuf "buf", overwriting
@@ -143,23 +148,6 @@ extern int has_object_pack(const struct object_id *oid);
 
 extern int has_pack_index(const unsigned char *sha1);
 
-/*
- * Only iterate over packs obtained from the promisor remote.
- */
-#define FOR_EACH_OBJECT_PROMISOR_ONLY 2
-
-/*
- * Iterate over packed objects in both the local
- * repository and any alternates repositories (unless the
- * FOR_EACH_OBJECT_LOCAL_ONLY flag, defined in cache.h, is set).
- */
-typedef int each_packed_object_fn(const struct object_id *oid,
-                                 struct packed_git *pack,
-                                 uint32_t pos,
-                                 void *data);
-extern int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn, void *data);
-extern int for_each_packed_object(each_packed_object_fn, void *, unsigned flags);
-
 /*
  * Return 1 if an object in a promisor packfile is or refers to the given
  * object, 0 otherwise.
index 0f9f311a7a93350a584125c90da643fce96c34e7..e8236534ac8aa00fde2a5a9ae27e85c72d062f3a 100644 (file)
@@ -91,7 +91,7 @@ int parse_opt_commits(const struct option *opt, const char *arg, int unset)
                return -1;
        if (get_oid(arg, &oid))
                return error("malformed object name %s", arg);
-       commit = lookup_commit_reference(&oid);
+       commit = lookup_commit_reference(the_repository, &oid);
        if (!commit)
                return error("no such commit %s", arg);
        commit_list_insert(commit, opt->value);
index 7db84227ab34cb33849f4327af58acd925f782c8..3b874a83a0c897845deeec37c1a3b85e0b625050 100644 (file)
@@ -660,7 +660,8 @@ int parse_options(int argc, const char **argv, const char *prefix,
 static int usage_argh(const struct option *opts, FILE *outfile)
 {
        const char *s;
-       int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh;
+       int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) ||
+               !opts->argh || !!strpbrk(opts->argh, "()<>[]|");
        if (opts->flags & PARSE_OPT_OPTARG)
                if (opts->long_name)
                        s = literal ? "[=%s]" : "[=<%s>]";
diff --git a/path.c b/path.c
index 7f109f661816039768e4d8050bdb3c12384f9f85..34f0f98349a6eccd462614cdf143bb031ca348c8 100644 (file)
--- a/path.c
+++ b/path.c
@@ -1442,12 +1442,12 @@ char *xdg_cache_home(const char *filename)
        return NULL;
 }
 
-GIT_PATH_FUNC(git_path_cherry_pick_head, "CHERRY_PICK_HEAD")
-GIT_PATH_FUNC(git_path_revert_head, "REVERT_HEAD")
-GIT_PATH_FUNC(git_path_squash_msg, "SQUASH_MSG")
-GIT_PATH_FUNC(git_path_merge_msg, "MERGE_MSG")
-GIT_PATH_FUNC(git_path_merge_rr, "MERGE_RR")
-GIT_PATH_FUNC(git_path_merge_mode, "MERGE_MODE")
-GIT_PATH_FUNC(git_path_merge_head, "MERGE_HEAD")
-GIT_PATH_FUNC(git_path_fetch_head, "FETCH_HEAD")
-GIT_PATH_FUNC(git_path_shallow, "shallow")
+REPO_GIT_PATH_FUNC(cherry_pick_head, "CHERRY_PICK_HEAD")
+REPO_GIT_PATH_FUNC(revert_head, "REVERT_HEAD")
+REPO_GIT_PATH_FUNC(squash_msg, "SQUASH_MSG")
+REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG")
+REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR")
+REPO_GIT_PATH_FUNC(merge_mode, "MERGE_MODE")
+REPO_GIT_PATH_FUNC(merge_head, "MERGE_HEAD")
+REPO_GIT_PATH_FUNC(fetch_head, "FETCH_HEAD")
+REPO_GIT_PATH_FUNC(shallow, "shallow")
diff --git a/path.h b/path.h
index 1ccd0373c9db8460c7ad7a3f9c5465f84408fd56..ed6732e5a22ca8fbceff68437c9df616bb819cc9 100644 (file)
--- a/path.h
+++ b/path.h
@@ -147,7 +147,7 @@ extern void report_linked_checkout_garbage(void);
 /*
  * You can define a static memoized git path like:
  *
- *    static GIT_PATH_FUNC(git_path_foo, "FOO");
+ *    static GIT_PATH_FUNC(git_path_foo, "FOO")
  *
  * or use one of the global ones below.
  */
@@ -160,14 +160,36 @@ extern void report_linked_checkout_garbage(void);
                return ret; \
        }
 
-const char *git_path_cherry_pick_head(void);
-const char *git_path_revert_head(void);
-const char *git_path_squash_msg(void);
-const char *git_path_merge_msg(void);
-const char *git_path_merge_rr(void);
-const char *git_path_merge_mode(void);
-const char *git_path_merge_head(void);
-const char *git_path_fetch_head(void);
-const char *git_path_shallow(void);
+#define REPO_GIT_PATH_FUNC(var, filename) \
+       const char *git_path_##var(struct repository *r) \
+       { \
+               if (!r->cached_paths.var) \
+                       r->cached_paths.var = git_pathdup(filename); \
+               return r->cached_paths.var; \
+       }
+
+struct path_cache {
+       const char *cherry_pick_head;
+       const char *revert_head;
+       const char *squash_msg;
+       const char *merge_msg;
+       const char *merge_rr;
+       const char *merge_mode;
+       const char *merge_head;
+       const char *fetch_head;
+       const char *shallow;
+};
+
+#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
+
+const char *git_path_cherry_pick_head(struct repository *r);
+const char *git_path_revert_head(struct repository *r);
+const char *git_path_squash_msg(struct repository *r);
+const char *git_path_merge_msg(struct repository *r);
+const char *git_path_merge_rr(struct repository *r);
+const char *git_path_merge_mode(struct repository *r);
+const char *git_path_merge_head(struct repository *r);
+const char *git_path_fetch_head(struct repository *r);
+const char *git_path_shallow(struct repository *r);
 
 #endif /* PATH_H */
index 27cd6067860d4fdb0b48b6bcf7c84d5903efd71b..6f005996fdc8f3e412b0faafc12e65aed359be3b 100644 (file)
@@ -37,7 +37,7 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
                return;
        for (i = 0; i < istate->cache_nr; i++) {
                const struct cache_entry *ce = istate->cache[i];
-               ce_path_match(ce, pathspec, seen);
+               ce_path_match(istate, ce, pathspec, seen);
        }
 }
 
index a593c08aad814ca015198936158219f44cbd0226..04d10bbd037b393574f8453cbd00f94e0b2e7e99 100644 (file)
@@ -101,7 +101,7 @@ int packet_flush_gently(int fd)
 {
        packet_trace("0000", 4, 1);
        if (write_in_full(fd, "0000", 4) < 0)
-               return error("flush packet write failed");
+               return error(_("flush packet write failed"));
        return 0;
 }
 
@@ -139,7 +139,7 @@ static void format_packet(struct strbuf *out, const char *fmt, va_list args)
        n = out->len - orig_len;
 
        if (n > LARGE_PACKET_MAX)
-               die("protocol error: impossibly long line");
+               die(_("protocol error: impossibly long line"));
 
        set_packet_header(&out->buf[orig_len], n);
        packet_trace(out->buf + orig_len + 4, n - 4, 1);
@@ -155,9 +155,9 @@ static int packet_write_fmt_1(int fd, int gently,
        if (write_in_full(fd, buf.buf, buf.len) < 0) {
                if (!gently) {
                        check_pipe(errno);
-                       die_errno("packet write with format failed");
+                       die_errno(_("packet write with format failed"));
                }
-               return error("packet write with format failed");
+               return error(_("packet write with format failed"));
        }
 
        return 0;
@@ -189,21 +189,21 @@ static int packet_write_gently(const int fd_out, const char *buf, size_t size)
        size_t packet_size;
 
        if (size > sizeof(packet_write_buffer) - 4)
-               return error("packet write failed - data exceeds max packet size");
+               return error(_("packet write failed - data exceeds max packet size"));
 
        packet_trace(buf, size, 1);
        packet_size = size + 4;
        set_packet_header(packet_write_buffer, packet_size);
        memcpy(packet_write_buffer + 4, buf, size);
        if (write_in_full(fd_out, packet_write_buffer, packet_size) < 0)
-               return error("packet write failed");
+               return error(_("packet write failed"));
        return 0;
 }
 
 void packet_write(int fd_out, const char *buf, size_t size)
 {
        if (packet_write_gently(fd_out, buf, size))
-               die_errno("packet write failed");
+               die_errno(_("packet write failed"));
 }
 
 void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
@@ -225,7 +225,7 @@ void packet_buf_write_len(struct strbuf *buf, const char *data, size_t len)
        n = buf->len - orig_len;
 
        if (n > LARGE_PACKET_MAX)
-               die("protocol error: impossibly long line");
+               die(_("protocol error: impossibly long line"));
 
        set_packet_header(&buf->buf[orig_len], n);
        packet_trace(data, len, 1);
@@ -288,7 +288,7 @@ static int get_packet_data(int fd, char **src_buf, size_t *src_size,
        } else {
                ret = read_in_full(fd, dst, size);
                if (ret < 0)
-                       die_errno("read error");
+                       die_errno(_("read error"));
        }
 
        /* And complain if we didn't get enough bytes to satisfy the read. */
@@ -296,7 +296,7 @@ static int get_packet_data(int fd, char **src_buf, size_t *src_size,
                if (options & PACKET_READ_GENTLE_ON_EOF)
                        return -1;
 
-               die("The remote end hung up unexpectedly");
+               die(_("the remote end hung up unexpectedly"));
        }
 
        return ret;
@@ -324,7 +324,7 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
        len = packet_length(linelen);
 
        if (len < 0) {
-               die("protocol error: bad line length character: %.4s", linelen);
+               die(_("protocol error: bad line length character: %.4s"), linelen);
        } else if (!len) {
                packet_trace("0000", 4, 0);
                *pktlen = 0;
@@ -334,12 +334,12 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
                *pktlen = 0;
                return PACKET_READ_DELIM;
        } else if (len < 4) {
-               die("protocol error: bad line length %d", len);
+               die(_("protocol error: bad line length %d"), len);
        }
 
        len -= 4;
        if ((unsigned)len >= size)
-               die("protocol error: bad line length %d", len);
+               die(_("protocol error: bad line length %d"), len);
 
        if (get_packet_data(fd, src_buffer, src_len, buffer, len, options) < 0) {
                *pktlen = -1;
index 4d08d4487460f839f39f667c714f1bb85fa1e144..71cd2437a3b33b343696bf96067603e8dc9e4464 100644 (file)
@@ -58,7 +58,7 @@ static void *preload_thread(void *_data)
                        continue;
                if (ce->ce_flags & CE_FSMONITOR_VALID)
                        continue;
-               if (!ce_path_match(ce, &p->pathspec, NULL))
+               if (!ce_path_match(index, ce, &p->pathspec, NULL))
                        continue;
                if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
                        continue;
index 703fa6ff7bf297e9d0dd91586f951f715032e06a..98cf5228f9e30fe5622bdfb4c54d996cb3153808 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -630,7 +630,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(commit, NULL))
+               if (msg == get_cached_commit_buffer(the_repository, commit, NULL))
                        out = xstrdup(msg);
                else
                        out = (char *)msg;
@@ -1146,7 +1146,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
 
        /* these depend on the commit */
        if (!commit->object.parsed)
-               parse_object(&commit->object.oid);
+               parse_object(the_repository, &commit->object.oid);
 
        switch (placeholder[0]) {
        case 'H':               /* commit hash */
@@ -1538,7 +1538,7 @@ void format_commit_message(const struct commit *commit,
        }
 
        if (output_enc) {
-               int outsz;
+               size_t outsz;
                char *out = reencode_string_len(sb->buf, sb->len,
                                                output_enc, utf8, &outsz);
                if (out)
@@ -1575,7 +1575,7 @@ static void pp_header(struct pretty_print_context *pp,
                }
 
                if (starts_with(line, "parent ")) {
-                       if (linelen != 48)
+                       if (linelen != the_hash_algo->hexsz + 8)
                                die("bad parent line in commit");
                        continue;
                }
@@ -1583,7 +1583,7 @@ static void pp_header(struct pretty_print_context *pp,
                if (!parents_shown) {
                        unsigned num = commit_list_count(commit->parents);
                        /* with enough slop */
-                       strbuf_grow(sb, num * 50 + 20);
+                       strbuf_grow(sb, num * (GIT_MAX_HEXSZ + 10) + 20);
                        add_merge_info(pp, sb, commit);
                        parents_shown = 1;
                }
diff --git a/range-diff.c b/range-diff.c
new file mode 100644 (file)
index 0000000..b6b9aba
--- /dev/null
@@ -0,0 +1,435 @@
+#include "cache.h"
+#include "range-diff.h"
+#include "string-list.h"
+#include "run-command.h"
+#include "argv-array.h"
+#include "hashmap.h"
+#include "xdiff-interface.h"
+#include "linear-assignment.h"
+#include "diffcore.h"
+#include "commit.h"
+#include "pretty.h"
+#include "userdiff.h"
+
+struct patch_util {
+       /* For the search for an exact match */
+       struct hashmap_entry e;
+       const char *diff, *patch;
+
+       int i, shown;
+       int diffsize;
+       size_t diff_offset;
+       /* the index of the matching item in the other branch, or -1 */
+       int matching;
+       struct object_id oid;
+};
+
+/*
+ * Reads the patches into a string list, with the `util` field being populated
+ * as struct object_id (will need to be free()d).
+ */
+static int read_patches(const char *range, struct string_list *list)
+{
+       struct child_process cp = CHILD_PROCESS_INIT;
+       FILE *in;
+       struct strbuf buf = STRBUF_INIT, line = STRBUF_INIT;
+       struct patch_util *util = NULL;
+       int in_header = 1;
+
+       argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
+                       "--reverse", "--date-order", "--decorate=no",
+                       "--no-abbrev-commit", range,
+                       NULL);
+       cp.out = -1;
+       cp.no_stdin = 1;
+       cp.git_cmd = 1;
+
+       if (start_command(&cp))
+               return error_errno(_("could not start `log`"));
+       in = fdopen(cp.out, "r");
+       if (!in) {
+               error_errno(_("could not read `log` output"));
+               finish_command(&cp);
+               return -1;
+       }
+
+       while (strbuf_getline(&line, in) != EOF) {
+               const char *p;
+
+               if (skip_prefix(line.buf, "commit ", &p)) {
+                       if (util) {
+                               string_list_append(list, buf.buf)->util = util;
+                               strbuf_reset(&buf);
+                       }
+                       util = xcalloc(sizeof(*util), 1);
+                       if (get_oid(p, &util->oid)) {
+                               error(_("could not parse commit '%s'"), p);
+                               free(util);
+                               string_list_clear(list, 1);
+                               strbuf_release(&buf);
+                               strbuf_release(&line);
+                               fclose(in);
+                               finish_command(&cp);
+                               return -1;
+                       }
+                       util->matching = -1;
+                       in_header = 1;
+                       continue;
+               }
+
+               if (starts_with(line.buf, "diff --git")) {
+                       in_header = 0;
+                       strbuf_addch(&buf, '\n');
+                       if (!util->diff_offset)
+                               util->diff_offset = buf.len;
+                       strbuf_addbuf(&buf, &line);
+               } else if (in_header) {
+                       if (starts_with(line.buf, "Author: ")) {
+                               strbuf_addbuf(&buf, &line);
+                               strbuf_addstr(&buf, "\n\n");
+                       } else if (starts_with(line.buf, "    ")) {
+                               strbuf_rtrim(&line);
+                               strbuf_addbuf(&buf, &line);
+                               strbuf_addch(&buf, '\n');
+                       }
+                       continue;
+               } else if (starts_with(line.buf, "@@ "))
+                       strbuf_addstr(&buf, "@@");
+               else if (!line.buf[0] || starts_with(line.buf, "index "))
+                       /*
+                        * A completely blank (not ' \n', which is context)
+                        * line is not valid in a diff.  We skip it
+                        * silently, because this neatly handles the blank
+                        * separator line between commits in git-log
+                        * output.
+                        *
+                        * We also want to ignore the diff's `index` lines
+                        * because they contain exact blob hashes in which
+                        * we are not interested.
+                        */
+                       continue;
+               else
+                       strbuf_addbuf(&buf, &line);
+
+               strbuf_addch(&buf, '\n');
+               util->diffsize++;
+       }
+       fclose(in);
+       strbuf_release(&line);
+
+       if (util)
+               string_list_append(list, buf.buf)->util = util;
+       strbuf_release(&buf);
+
+       if (finish_command(&cp))
+               return -1;
+
+       return 0;
+}
+
+static int patch_util_cmp(const void *dummy, const struct patch_util *a,
+                    const struct patch_util *b, const char *keydata)
+{
+       return strcmp(a->diff, keydata ? keydata : b->diff);
+}
+
+static void find_exact_matches(struct string_list *a, struct string_list *b)
+{
+       struct hashmap map;
+       int i;
+
+       hashmap_init(&map, (hashmap_cmp_fn)patch_util_cmp, NULL, 0);
+
+       /* First, add the patches of a to a hash map */
+       for (i = 0; i < a->nr; i++) {
+               struct patch_util *util = a->items[i].util;
+
+               util->i = i;
+               util->patch = a->items[i].string;
+               util->diff = util->patch + util->diff_offset;
+               hashmap_entry_init(util, strhash(util->diff));
+               hashmap_add(&map, util);
+       }
+
+       /* Now try to find exact matches in b */
+       for (i = 0; i < b->nr; i++) {
+               struct patch_util *util = b->items[i].util, *other;
+
+               util->i = i;
+               util->patch = b->items[i].string;
+               util->diff = util->patch + util->diff_offset;
+               hashmap_entry_init(util, strhash(util->diff));
+               other = hashmap_remove(&map, util, NULL);
+               if (other) {
+                       if (other->matching >= 0)
+                               BUG("already assigned!");
+
+                       other->matching = i;
+                       util->matching = other->i;
+               }
+       }
+
+       hashmap_free(&map, 0);
+}
+
+static void diffsize_consume(void *data, char *line, unsigned long len)
+{
+       (*(int *)data)++;
+}
+
+static int diffsize(const char *a, const char *b)
+{
+       xpparam_t pp = { 0 };
+       xdemitconf_t cfg = { 0 };
+       mmfile_t mf1, mf2;
+       int count = 0;
+
+       mf1.ptr = (char *)a;
+       mf1.size = strlen(a);
+       mf2.ptr = (char *)b;
+       mf2.size = strlen(b);
+
+       cfg.ctxlen = 3;
+       if (!xdi_diff_outf(&mf1, &mf2, diffsize_consume, &count, &pp, &cfg))
+               return count;
+
+       error(_("failed to generate diff"));
+       return COST_MAX;
+}
+
+static void get_correspondences(struct string_list *a, struct string_list *b,
+                               int creation_factor)
+{
+       int n = a->nr + b->nr;
+       int *cost, c, *a2b, *b2a;
+       int i, j;
+
+       ALLOC_ARRAY(cost, st_mult(n, n));
+       ALLOC_ARRAY(a2b, n);
+       ALLOC_ARRAY(b2a, n);
+
+       for (i = 0; i < a->nr; i++) {
+               struct patch_util *a_util = a->items[i].util;
+
+               for (j = 0; j < b->nr; j++) {
+                       struct patch_util *b_util = b->items[j].util;
+
+                       if (a_util->matching == j)
+                               c = 0;
+                       else if (a_util->matching < 0 && b_util->matching < 0)
+                               c = diffsize(a_util->diff, b_util->diff);
+                       else
+                               c = COST_MAX;
+                       cost[i + n * j] = c;
+               }
+
+               c = a_util->matching < 0 ?
+                       a_util->diffsize * creation_factor / 100 : COST_MAX;
+               for (j = b->nr; j < n; j++)
+                       cost[i + n * j] = c;
+       }
+
+       for (j = 0; j < b->nr; j++) {
+               struct patch_util *util = b->items[j].util;
+
+               c = util->matching < 0 ?
+                       util->diffsize * creation_factor / 100 : COST_MAX;
+               for (i = a->nr; i < n; i++)
+                       cost[i + n * j] = c;
+       }
+
+       for (i = a->nr; i < n; i++)
+               for (j = b->nr; j < n; j++)
+                       cost[i + n * j] = 0;
+
+       compute_assignment(n, n, cost, a2b, b2a);
+
+       for (i = 0; i < a->nr; i++)
+               if (a2b[i] >= 0 && a2b[i] < b->nr) {
+                       struct patch_util *a_util = a->items[i].util;
+                       struct patch_util *b_util = b->items[a2b[i]].util;
+
+                       a_util->matching = a2b[i];
+                       b_util->matching = i;
+               }
+
+       free(cost);
+       free(a2b);
+       free(b2a);
+}
+
+static void output_pair_header(struct diff_options *diffopt,
+                              int patch_no_width,
+                              struct strbuf *buf,
+                              struct strbuf *dashes,
+                              struct patch_util *a_util,
+                              struct patch_util *b_util)
+{
+       struct object_id *oid = a_util ? &a_util->oid : &b_util->oid;
+       struct commit *commit;
+       char status;
+       const char *color_reset = diff_get_color_opt(diffopt, DIFF_RESET);
+       const char *color_old = diff_get_color_opt(diffopt, DIFF_FILE_OLD);
+       const char *color_new = diff_get_color_opt(diffopt, DIFF_FILE_NEW);
+       const char *color_commit = diff_get_color_opt(diffopt, DIFF_COMMIT);
+       const char *color;
+
+       if (!dashes->len)
+               strbuf_addchars(dashes, '-',
+                               strlen(find_unique_abbrev(oid,
+                                                         DEFAULT_ABBREV)));
+
+       if (!b_util) {
+               color = color_old;
+               status = '<';
+       } else if (!a_util) {
+               color = color_new;
+               status = '>';
+       } else if (strcmp(a_util->patch, b_util->patch)) {
+               color = color_commit;
+               status = '!';
+       } else {
+               color = color_commit;
+               status = '=';
+       }
+
+       strbuf_reset(buf);
+       strbuf_addstr(buf, status == '!' ? color_old : color);
+       if (!a_util)
+               strbuf_addf(buf, "%*s:  %s ", patch_no_width, "-", dashes->buf);
+       else
+               strbuf_addf(buf, "%*d:  %s ", patch_no_width, a_util->i + 1,
+                           find_unique_abbrev(&a_util->oid, DEFAULT_ABBREV));
+
+       if (status == '!')
+               strbuf_addf(buf, "%s%s", color_reset, color);
+       strbuf_addch(buf, status);
+       if (status == '!')
+               strbuf_addf(buf, "%s%s", color_reset, color_new);
+
+       if (!b_util)
+               strbuf_addf(buf, " %*s:  %s", patch_no_width, "-", dashes->buf);
+       else
+               strbuf_addf(buf, " %*d:  %s", patch_no_width, b_util->i + 1,
+                           find_unique_abbrev(&b_util->oid, DEFAULT_ABBREV));
+
+       commit = lookup_commit_reference(the_repository, oid);
+       if (commit) {
+               if (status == '!')
+                       strbuf_addf(buf, "%s%s", color_reset, color);
+
+               strbuf_addch(buf, ' ');
+               pp_commit_easy(CMIT_FMT_ONELINE, commit, buf);
+       }
+       strbuf_addf(buf, "%s\n", color_reset);
+
+       fwrite(buf->buf, buf->len, 1, stdout);
+}
+
+static struct userdiff_driver no_func_name = {
+       .funcname = { "$^", 0 }
+};
+
+static struct diff_filespec *get_filespec(const char *name, const char *p)
+{
+       struct diff_filespec *spec = alloc_filespec(name);
+
+       fill_filespec(spec, &null_oid, 0, 0644);
+       spec->data = (char *)p;
+       spec->size = strlen(p);
+       spec->should_munmap = 0;
+       spec->is_stdin = 1;
+       spec->driver = &no_func_name;
+
+       return spec;
+}
+
+static void patch_diff(const char *a, const char *b,
+                             struct diff_options *diffopt)
+{
+       diff_queue(&diff_queued_diff,
+                  get_filespec("a", a), get_filespec("b", b));
+
+       diffcore_std(diffopt);
+       diff_flush(diffopt);
+}
+
+static void output(struct string_list *a, struct string_list *b,
+                  struct diff_options *diffopt)
+{
+       struct strbuf buf = STRBUF_INIT, dashes = STRBUF_INIT;
+       int patch_no_width = decimal_width(1 + (a->nr > b->nr ? a->nr : b->nr));
+       int i = 0, j = 0;
+
+       /*
+        * We assume the user is really more interested in the second argument
+        * ("newer" version). To that end, we print the output in the order of
+        * the RHS (the `b` parameter). To put the LHS (the `a` parameter)
+        * commits that are no longer in the RHS into a good place, we place
+        * them once we have shown all of their predecessors in the LHS.
+        */
+
+       while (i < a->nr || j < b->nr) {
+               struct patch_util *a_util, *b_util;
+               a_util = i < a->nr ? a->items[i].util : NULL;
+               b_util = j < b->nr ? b->items[j].util : NULL;
+
+               /* Skip all the already-shown commits from the LHS. */
+               while (i < a->nr && a_util->shown)
+                       a_util = ++i < a->nr ? a->items[i].util : NULL;
+
+               /* Show unmatched LHS commit whose predecessors were shown. */
+               if (i < a->nr && a_util->matching < 0) {
+                       output_pair_header(diffopt, patch_no_width,
+                                          &buf, &dashes, a_util, NULL);
+                       i++;
+                       continue;
+               }
+
+               /* Show unmatched RHS commits. */
+               while (j < b->nr && b_util->matching < 0) {
+                       output_pair_header(diffopt, patch_no_width,
+                                          &buf, &dashes, NULL, b_util);
+                       b_util = ++j < b->nr ? b->items[j].util : NULL;
+               }
+
+               /* Show matching LHS/RHS pair. */
+               if (j < b->nr) {
+                       a_util = a->items[b_util->matching].util;
+                       output_pair_header(diffopt, patch_no_width,
+                                          &buf, &dashes, a_util, b_util);
+                       if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT))
+                               patch_diff(a->items[b_util->matching].string,
+                                          b->items[j].string, diffopt);
+                       a_util->shown = 1;
+                       j++;
+               }
+       }
+       strbuf_release(&buf);
+       strbuf_release(&dashes);
+}
+
+int show_range_diff(const char *range1, const char *range2,
+                   int creation_factor, struct diff_options *diffopt)
+{
+       int res = 0;
+
+       struct string_list branch1 = STRING_LIST_INIT_DUP;
+       struct string_list branch2 = STRING_LIST_INIT_DUP;
+
+       if (read_patches(range1, &branch1))
+               res = error(_("could not parse log for '%s'"), range1);
+       if (!res && read_patches(range2, &branch2))
+               res = error(_("could not parse log for '%s'"), range2);
+
+       if (!res) {
+               find_exact_matches(&branch1, &branch2);
+               get_correspondences(&branch1, &branch2, creation_factor);
+               output(&branch1, &branch2, diffopt);
+       }
+
+       string_list_clear(&branch1, 1);
+       string_list_clear(&branch2, 1);
+
+       return res;
+}
diff --git a/range-diff.h b/range-diff.h
new file mode 100644 (file)
index 0000000..2407d46
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef RANGE_DIFF_H
+#define RANGE_DIFF_H
+
+#include "diff.h"
+
+int show_range_diff(const char *range1, const char *range2,
+                   int creation_factor, struct diff_options *diffopt);
+
+#endif
index ffb976c33c6936a7b178c7c478bcf4cd2840d472..6e9b810d2a5e03dc613fe1e58938086f1ed9b684 100644 (file)
@@ -88,10 +88,10 @@ static void add_recent_object(const struct object_id *oid,
                obj = parse_object_or_die(oid, NULL);
                break;
        case OBJ_TREE:
-               obj = (struct object *)lookup_tree(oid);
+               obj = (struct object *)lookup_tree(the_repository, oid);
                break;
        case OBJ_BLOB:
-               obj = (struct object *)lookup_blob(oid);
+               obj = (struct object *)lookup_blob(the_repository, oid);
                break;
        default:
                die("unknown object type for %s: %s",
@@ -108,7 +108,7 @@ static int add_recent_loose(const struct object_id *oid,
                            const char *path, void *data)
 {
        struct stat st;
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(the_repository, oid->hash);
 
        if (obj && obj->flags & SEEN)
                return 0;
@@ -133,7 +133,7 @@ static int add_recent_packed(const struct object_id *oid,
                             struct packed_git *p, uint32_t pos,
                             void *data)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(the_repository, oid->hash);
 
        if (obj && obj->flags & SEEN)
                return 0;
index 372588260ea00f48ea4d031095901a575ac0e620..7b1354d7590a70ecbd6e508bdd95eafd4793efcc 100644 (file)
@@ -6,11 +6,14 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
+#include "diff.h"
+#include "diffcore.h"
 #include "tempfile.h"
 #include "lockfile.h"
 #include "cache-tree.h"
 #include "refs.h"
 #include "dir.h"
+#include "object-store.h"
 #include "tree.h"
 #include "commit.h"
 #include "blob.h"
                 CE_ENTRY_ADDED | CE_ENTRY_REMOVED | CE_ENTRY_CHANGED | \
                 SPLIT_INDEX_ORDERED | UNTRACKED_CHANGED | FSMONITOR_CHANGED)
 
+
+/*
+ * This is an estimate of the pathname length in the index.  We use
+ * this for V4 index files to guess the un-deltafied size of the index
+ * in memory because of pathname deltafication.  This is not required
+ * for V2/V3 index formats because their pathnames are not compressed.
+ * If the initial amount of memory set aside is not sufficient, the
+ * mem pool will allocate extra memory.
+ */
+#define CACHE_ENTRY_PATH_LENGTH 80
+
+static inline struct cache_entry *mem_pool__ce_alloc(struct mem_pool *mem_pool, size_t len)
+{
+       struct cache_entry *ce;
+       ce = mem_pool_alloc(mem_pool, cache_entry_size(len));
+       ce->mem_pool_allocated = 1;
+       return ce;
+}
+
+static inline struct cache_entry *mem_pool__ce_calloc(struct mem_pool *mem_pool, size_t len)
+{
+       struct cache_entry * ce;
+       ce = mem_pool_calloc(mem_pool, 1, cache_entry_size(len));
+       ce->mem_pool_allocated = 1;
+       return ce;
+}
+
+static struct mem_pool *find_mem_pool(struct index_state *istate)
+{
+       struct mem_pool **pool_ptr;
+
+       if (istate->split_index && istate->split_index->base)
+               pool_ptr = &istate->split_index->base->ce_mem_pool;
+       else
+               pool_ptr = &istate->ce_mem_pool;
+
+       if (!*pool_ptr)
+               mem_pool_init(pool_ptr, 0);
+
+       return *pool_ptr;
+}
+
 struct index_state the_index;
 static const char *alternate_index_output;
 
@@ -61,7 +106,7 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache
 
        replace_index_entry_in_base(istate, old, ce);
        remove_name_hash(istate, old);
-       free(old);
+       discard_cache_entry(old);
        ce->ce_flags &= ~CE_HASHED;
        set_index_entry(istate, nr, ce);
        ce->ce_flags |= CE_UPDATE_IN_BASE;
@@ -74,7 +119,7 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
        struct cache_entry *old_entry = istate->cache[nr], *new_entry;
        int namelen = strlen(new_name);
 
-       new_entry = xmalloc(cache_entry_size(namelen));
+       new_entry = make_empty_cache_entry(istate, namelen);
        copy_cache_entry(new_entry, old_entry);
        new_entry->ce_flags &= ~CE_HASHED;
        new_entry->ce_namelen = namelen;
@@ -623,7 +668,7 @@ static struct cache_entry *create_alias_ce(struct index_state *istate,
 
        /* Ok, create the new entry using the name of the existing alias */
        len = ce_namelen(alias);
-       new_entry = xcalloc(1, cache_entry_size(len));
+       new_entry = make_empty_cache_entry(istate, len);
        memcpy(new_entry->name, alias->name, len);
        copy_cache_entry(new_entry, ce);
        save_or_free_index_entry(istate, ce);
@@ -640,7 +685,7 @@ void set_object_name_for_intent_to_add_entry(struct cache_entry *ce)
 
 int add_to_index(struct index_state *istate, const char *path, struct stat *st, int flags)
 {
-       int size, namelen, was_same;
+       int namelen, was_same;
        mode_t st_mode = st->st_mode;
        struct cache_entry *ce, *alias = NULL;
        unsigned ce_option = CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE|CE_MATCH_RACY_IS_DIRTY;
@@ -662,8 +707,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
                while (namelen && path[namelen-1] == '/')
                        namelen--;
        }
-       size = cache_entry_size(namelen);
-       ce = xcalloc(1, size);
+       ce = make_empty_cache_entry(istate, namelen);
        memcpy(ce->name, path, namelen);
        ce->ce_namelen = namelen;
        if (!intent_only)
@@ -704,13 +748,13 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
                                ce_mark_uptodate(alias);
                        alias->ce_flags |= CE_ADDED;
 
-                       free(ce);
+                       discard_cache_entry(ce);
                        return 0;
                }
        }
        if (!intent_only) {
                if (index_path(&ce->oid, path, st, newflags)) {
-                       free(ce);
+                       discard_cache_entry(ce);
                        return error("unable to index file %s", path);
                }
        } else
@@ -727,9 +771,9 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
                    ce->ce_mode == alias->ce_mode);
 
        if (pretend)
-               free(ce);
+               discard_cache_entry(ce);
        else if (add_index_entry(istate, ce, add_option)) {
-               free(ce);
+               discard_cache_entry(ce);
                return error("unable to add %s to index", path);
        }
        if (verbose && !was_same)
@@ -745,12 +789,25 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)
        return add_to_index(istate, path, &st, flags);
 }
 
-struct cache_entry *make_cache_entry(unsigned int mode,
-               const unsigned char *sha1, const char *path, int stage,
-               unsigned int refresh_options)
+struct cache_entry *make_empty_cache_entry(struct index_state *istate, size_t len)
+{
+       return mem_pool__ce_calloc(find_mem_pool(istate), len);
+}
+
+struct cache_entry *make_empty_transient_cache_entry(size_t len)
+{
+       return xcalloc(1, cache_entry_size(len));
+}
+
+struct cache_entry *make_cache_entry(struct index_state *istate,
+                                    unsigned int mode,
+                                    const struct object_id *oid,
+                                    const char *path,
+                                    int stage,
+                                    unsigned int refresh_options)
 {
-       int size, len;
        struct cache_entry *ce, *ret;
+       int len;
 
        if (!verify_path(path, mode)) {
                error("Invalid path '%s'", path);
@@ -758,21 +815,43 @@ struct cache_entry *make_cache_entry(unsigned int mode,
        }
 
        len = strlen(path);
-       size = cache_entry_size(len);
-       ce = xcalloc(1, size);
+       ce = make_empty_cache_entry(istate, len);
 
-       hashcpy(ce->oid.hash, sha1);
+       oidcpy(&ce->oid, oid);
        memcpy(ce->name, path, len);
        ce->ce_flags = create_ce_flags(stage);
        ce->ce_namelen = len;
        ce->ce_mode = create_ce_mode(mode);
 
-       ret = refresh_cache_entry(ce, refresh_options);
+       ret = refresh_cache_entry(&the_index, ce, refresh_options);
        if (ret != ce)
-               free(ce);
+               discard_cache_entry(ce);
        return ret;
 }
 
+struct cache_entry *make_transient_cache_entry(unsigned int mode, const struct object_id *oid,
+                                              const char *path, int stage)
+{
+       struct cache_entry *ce;
+       int len;
+
+       if (!verify_path(path, mode)) {
+               error("Invalid path '%s'", path);
+               return NULL;
+       }
+
+       len = strlen(path);
+       ce = make_empty_transient_cache_entry(len);
+
+       oidcpy(&ce->oid, oid);
+       memcpy(ce->name, path, len);
+       ce->ce_flags = create_ce_flags(stage);
+       ce->ce_namelen = len;
+       ce->ce_mode = create_ce_mode(mode);
+
+       return ce;
+}
+
 /*
  * Chmod an index entry with either +x or -x.
  *
@@ -1268,7 +1347,7 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
 {
        struct stat st;
        struct cache_entry *updated;
-       int changed, size;
+       int changed;
        int refresh = options & CE_MATCH_REFRESH;
        int ignore_valid = options & CE_MATCH_IGNORE_VALID;
        int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
@@ -1348,8 +1427,7 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
                return NULL;
        }
 
-       size = ce_size(ce);
-       updated = xmalloc(size);
+       updated = make_empty_cache_entry(istate, ce_namelen(ce));
        copy_cache_entry(updated, ce);
        memcpy(updated->name, ce->name, ce->ce_namelen + 1);
        fill_stat_cache_info(updated, &st);
@@ -1415,7 +1493,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
                if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
                        continue;
 
-               if (pathspec && !ce_path_match(ce, pathspec, seen))
+               if (pathspec && !ce_path_match(&the_index, ce, pathspec, seen))
                        filtered = 1;
 
                if (ce_stage(ce)) {
@@ -1473,10 +1551,11 @@ int refresh_index(struct index_state *istate, unsigned int flags,
        return has_errors;
 }
 
-struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
-                                              unsigned int options)
+struct cache_entry *refresh_cache_entry(struct index_state *istate,
+                                       struct cache_entry *ce,
+                                       unsigned int options)
 {
-       return refresh_cache_ent(&the_index, ce, options, NULL, NULL);
+       return refresh_cache_ent(istate, ce, options, NULL, NULL);
 }
 
 
@@ -1634,12 +1713,13 @@ int read_index(struct index_state *istate)
        return read_index_from(istate, get_index_file(), get_git_dir());
 }
 
-static struct cache_entry *cache_entry_from_ondisk(struct ondisk_cache_entry *ondisk,
+static struct cache_entry *cache_entry_from_ondisk(struct mem_pool *mem_pool,
+                                                  struct ondisk_cache_entry *ondisk,
                                                   unsigned int flags,
                                                   const char *name,
                                                   size_t len)
 {
-       struct cache_entry *ce = xmalloc(cache_entry_size(len));
+       struct cache_entry *ce = mem_pool__ce_alloc(mem_pool, len);
 
        ce->ce_stat_data.sd_ctime.sec = get_be32(&ondisk->ctime.sec);
        ce->ce_stat_data.sd_mtime.sec = get_be32(&ondisk->mtime.sec);
@@ -1681,7 +1761,8 @@ static unsigned long expand_name_field(struct strbuf *name, const char *cp_)
        return (const char *)ep + 1 - cp_;
 }
 
-static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
+static struct cache_entry *create_from_disk(struct mem_pool *mem_pool,
+                                           struct ondisk_cache_entry *ondisk,
                                            unsigned long *ent_size,
                                            struct strbuf *previous_name)
 {
@@ -1712,13 +1793,13 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
                /* v3 and earlier */
                if (len == CE_NAMEMASK)
                        len = strlen(name);
-               ce = cache_entry_from_ondisk(ondisk, flags, name, len);
+               ce = cache_entry_from_ondisk(mem_pool, ondisk, flags, name, len);
 
                *ent_size = ondisk_ce_size(ce);
        } else {
                unsigned long consumed;
                consumed = expand_name_field(previous_name, name);
-               ce = cache_entry_from_ondisk(ondisk, flags,
+               ce = cache_entry_from_ondisk(mem_pool, ondisk, flags,
                                             previous_name->buf,
                                             previous_name->len);
 
@@ -1792,6 +1873,22 @@ static void post_read_index_from(struct index_state *istate)
        tweak_fsmonitor(istate);
 }
 
+static size_t estimate_cache_size_from_compressed(unsigned int entries)
+{
+       return entries * (sizeof(struct cache_entry) + CACHE_ENTRY_PATH_LENGTH);
+}
+
+static size_t estimate_cache_size(size_t ondisk_size, unsigned int entries)
+{
+       long per_entry = sizeof(struct cache_entry) - sizeof(struct ondisk_cache_entry);
+
+       /*
+        * Account for potential alignment differences.
+        */
+       per_entry += align_padding_size(sizeof(struct cache_entry), -sizeof(struct ondisk_cache_entry));
+       return ondisk_size + entries * per_entry;
+}
+
 /* remember to discard_cache() before reading a different cache! */
 int do_read_index(struct index_state *istate, const char *path, int must_exist)
 {
@@ -1838,10 +1935,15 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
        istate->cache = xcalloc(istate->cache_alloc, sizeof(*istate->cache));
        istate->initialized = 1;
 
-       if (istate->version == 4)
+       if (istate->version == 4) {
                previous_name = &previous_name_buf;
-       else
+               mem_pool_init(&istate->ce_mem_pool,
+                             estimate_cache_size_from_compressed(istate->cache_nr));
+       } else {
                previous_name = NULL;
+               mem_pool_init(&istate->ce_mem_pool,
+                             estimate_cache_size(mmap_size, istate->cache_nr));
+       }
 
        src_offset = sizeof(*hdr);
        for (i = 0; i < istate->cache_nr; i++) {
@@ -1850,7 +1952,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
                unsigned long consumed;
 
                disk_ce = (struct ondisk_cache_entry *)((char *)mmap + src_offset);
-               ce = create_from_disk(disk_ce, &consumed, previous_name);
+               ce = create_from_disk(istate->ce_mem_pool, disk_ce, &consumed, previous_name);
                set_index_entry(istate, i, ce);
 
                src_offset += consumed;
@@ -1947,17 +2049,15 @@ int is_index_unborn(struct index_state *istate)
 
 int discard_index(struct index_state *istate)
 {
-       int i;
+       /*
+        * Cache entries in istate->cache[] should have been allocated
+        * from the memory pool associated with this index, or from an
+        * associated split_index. There is no need to free individual
+        * cache entries. validate_cache_entries can detect when this
+        * assertion does not hold.
+        */
+       validate_cache_entries(istate);
 
-       for (i = 0; i < istate->cache_nr; i++) {
-               if (istate->cache[i]->index &&
-                   istate->split_index &&
-                   istate->split_index->base &&
-                   istate->cache[i]->index <= istate->split_index->base->cache_nr &&
-                   istate->cache[i] == istate->split_index->base->cache[istate->cache[i]->index - 1])
-                       continue;
-               free(istate->cache[i]);
-       }
        resolve_undo_clear_index(istate);
        istate->cache_nr = 0;
        istate->cache_changed = 0;
@@ -1971,9 +2071,47 @@ int discard_index(struct index_state *istate)
        discard_split_index(istate);
        free_untracked_cache(istate->untracked);
        istate->untracked = NULL;
+
+       if (istate->ce_mem_pool) {
+               mem_pool_discard(istate->ce_mem_pool, should_validate_cache_entries());
+               istate->ce_mem_pool = NULL;
+       }
+
        return 0;
 }
 
+/*
+ * Validate the cache entries of this index.
+ * All cache entries associated with this index
+ * should have been allocated by the memory pool
+ * associated with this index, or by a referenced
+ * split index.
+ */
+void validate_cache_entries(const struct index_state *istate)
+{
+       int i;
+
+       if (!should_validate_cache_entries() ||!istate || !istate->initialized)
+               return;
+
+       for (i = 0; i < istate->cache_nr; i++) {
+               if (!istate) {
+                       die("internal error: cache entry is not allocated from expected memory pool");
+               } else if (!istate->ce_mem_pool ||
+                       !mem_pool_contains(istate->ce_mem_pool, istate->cache[i])) {
+                       if (!istate->split_index ||
+                               !istate->split_index->base ||
+                               !istate->split_index->base->ce_mem_pool ||
+                               !mem_pool_contains(istate->split_index->base->ce_mem_pool, istate->cache[i])) {
+                               die("internal error: cache entry is not allocated from expected memory pool");
+                       }
+               }
+       }
+
+       if (istate->split_index)
+               validate_cache_entries(istate->split_index->base);
+}
+
 int unmerged_index(const struct index_state *istate)
 {
        int i;
@@ -1984,6 +2122,44 @@ int unmerged_index(const struct index_state *istate)
        return 0;
 }
 
+int index_has_changes(const struct index_state *istate,
+                     struct tree *tree,
+                     struct strbuf *sb)
+{
+       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;
+
+               diff_setup(&opt);
+               opt.flags.exit_with_status = 1;
+               if (!sb)
+                       opt.flags.quick = 1;
+               do_diff_cache(&cmp, &opt);
+               diffcore_std(&opt);
+               for (i = 0; sb && i < diff_queued_diff.nr; i++) {
+                       if (i)
+                               strbuf_addch(sb, ' ');
+                       strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
+               }
+               diff_flush(&opt);
+               return opt.flags.has_changes != 0;
+       } else {
+               for (i = 0; sb && i < istate->cache_nr; i++) {
+                       if (i)
+                               strbuf_addch(sb, ' ');
+                       strbuf_addstr(sb, istate->cache[i]->name);
+               }
+               return !!istate->cache_nr;
+       }
+}
+
 #define WRITE_BUFFER_SIZE 8192
 static unsigned char write_buffer[WRITE_BUFFER_SIZE];
 static unsigned long write_buffer_len;
@@ -2632,10 +2808,13 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
 
 /*
  * Read the index file that is potentially unmerged into given
- * index_state, dropping any unmerged entries.  Returns true if
- * the index is unmerged.  Callers who want to refuse to work
- * from an unmerged state can call this and check its return value,
- * instead of calling read_cache().
+ * index_state, dropping any unmerged entries to stage #0 (potentially
+ * resulting in a path appearing as both a file and a directory in the
+ * index; the caller is responsible to clear out the extra entries
+ * before writing the index to a tree).  Returns true if the index is
+ * unmerged.  Callers who want to refuse to work from an unmerged
+ * state can call this and check its return value, instead of calling
+ * read_cache().
  */
 int read_index_unmerged(struct index_state *istate)
 {
@@ -2646,19 +2825,18 @@ int read_index_unmerged(struct index_state *istate)
        for (i = 0; i < istate->cache_nr; i++) {
                struct cache_entry *ce = istate->cache[i];
                struct cache_entry *new_ce;
-               int size, len;
+               int len;
 
                if (!ce_stage(ce))
                        continue;
                unmerged = 1;
                len = ce_namelen(ce);
-               size = cache_entry_size(len);
-               new_ce = xcalloc(1, size);
+               new_ce = make_empty_cache_entry(istate, len);
                memcpy(new_ce->name, ce->name, len);
                new_ce->ce_flags = create_ce_flags(0) | CE_CONFLICTED;
                new_ce->ce_namelen = len;
                new_ce->ce_mode = ce->ce_mode;
-               if (add_index_entry(istate, new_ce, 0))
+               if (add_index_entry(istate, new_ce, ADD_CACHE_SKIP_DFCHECK))
                        return error("%s: cannot drop to stage #0",
                                     new_ce->name);
        }
@@ -2762,3 +2940,41 @@ void move_index_extensions(struct index_state *dst, struct index_state *src)
        dst->untracked = src->untracked;
        src->untracked = NULL;
 }
+
+struct cache_entry *dup_cache_entry(const struct cache_entry *ce,
+                                   struct index_state *istate)
+{
+       unsigned int size = ce_size(ce);
+       int mem_pool_allocated;
+       struct cache_entry *new_entry = make_empty_cache_entry(istate, ce_namelen(ce));
+       mem_pool_allocated = new_entry->mem_pool_allocated;
+
+       memcpy(new_entry, ce, size);
+       new_entry->mem_pool_allocated = mem_pool_allocated;
+       return new_entry;
+}
+
+void discard_cache_entry(struct cache_entry *ce)
+{
+       if (ce && should_validate_cache_entries())
+               memset(ce, 0xCD, cache_entry_size(ce->ce_namelen));
+
+       if (ce && ce->mem_pool_allocated)
+               return;
+
+       free(ce);
+}
+
+int should_validate_cache_entries(void)
+{
+       static int validate_index_cache_entries = -1;
+
+       if (validate_index_cache_entries < 0) {
+               if (getenv("GIT_TEST_VALIDATE_INDEX_CACHE_ENTRIES"))
+                       validate_index_cache_entries = 1;
+               else
+                       validate_index_cache_entries = 0;
+       }
+
+       return validate_index_cache_entries;
+}
index fa3685d91f0464a28ef13102a1672215d4ec5177..0bccfceff2ae31200019838d9f2b67e13e32ef6f 100644 (file)
@@ -3,6 +3,8 @@
 #include "parse-options.h"
 #include "refs.h"
 #include "wildmatch.h"
+#include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "remote.h"
 #include "color.h"
@@ -41,6 +43,7 @@ void setup_ref_filter_porcelain_msg(void)
 
 typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
 typedef enum { COMPARE_EQUAL, COMPARE_UNEQUAL, COMPARE_NONE } cmp_status;
+typedef enum { SOURCE_NONE = 0, SOURCE_OBJ, SOURCE_OTHER } info_source;
 
 struct align {
        align_type position;
@@ -60,6 +63,17 @@ struct refname_atom {
        int lstrip, rstrip;
 };
 
+static struct expand_data {
+       struct object_id oid;
+       enum object_type type;
+       unsigned long size;
+       off_t disk_size;
+       struct object_id delta_base_oid;
+       void *content;
+
+       struct object_info info;
+} oi, oi_deref;
+
 /*
  * An atom is a valid field atom listed below, possibly prefixed with
  * a "*" to denote deref_tag().
@@ -73,6 +87,7 @@ struct refname_atom {
 static struct used_atom {
        const char *name;
        cmp_type type;
+       info_source source;
        union {
                char color[COLOR_MAXLEN];
                struct align align;
@@ -200,6 +215,30 @@ static int remote_ref_atom_parser(const struct ref_format *format, struct used_a
        return 0;
 }
 
+static int objecttype_atom_parser(const struct ref_format *format, struct used_atom *atom,
+                                 const char *arg, struct strbuf *err)
+{
+       if (arg)
+               return strbuf_addf_ret(err, -1, _("%%(objecttype) does not take arguments"));
+       if (*atom->name == '*')
+               oi_deref.info.typep = &oi_deref.type;
+       else
+               oi.info.typep = &oi.type;
+       return 0;
+}
+
+static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom,
+                                 const char *arg, struct strbuf *err)
+{
+       if (arg)
+               return strbuf_addf_ret(err, -1, _("%%(objectsize) does not take arguments"));
+       if (*atom->name == '*')
+               oi_deref.info.sizep = &oi_deref.size;
+       else
+               oi.info.sizep = &oi.size;
+       return 0;
+}
+
 static int body_atom_parser(const struct ref_format *format, struct used_atom *atom,
                            const char *arg, struct strbuf *err)
 {
@@ -380,49 +419,50 @@ static int head_atom_parser(const struct ref_format *format, struct used_atom *a
 
 static struct {
        const char *name;
+       info_source source;
        cmp_type cmp_type;
        int (*parser)(const struct ref_format *format, struct used_atom *atom,
                      const char *arg, struct strbuf *err);
 } valid_atom[] = {
-       { "refname" , FIELD_STR, refname_atom_parser },
-       { "objecttype" },
-       { "objectsize", FIELD_ULONG },
-       { "objectname", FIELD_STR, objectname_atom_parser },
-       { "tree" },
-       { "parent" },
-       { "numparent", FIELD_ULONG },
-       { "object" },
-       { "type" },
-       { "tag" },
-       { "author" },
-       { "authorname" },
-       { "authoremail" },
-       { "authordate", FIELD_TIME },
-       { "committer" },
-       { "committername" },
-       { "committeremail" },
-       { "committerdate", FIELD_TIME },
-       { "tagger" },
-       { "taggername" },
-       { "taggeremail" },
-       { "taggerdate", FIELD_TIME },
-       { "creator" },
-       { "creatordate", FIELD_TIME },
-       { "subject", FIELD_STR, subject_atom_parser },
-       { "body", FIELD_STR, body_atom_parser },
-       { "trailers", FIELD_STR, trailers_atom_parser },
-       { "contents", FIELD_STR, contents_atom_parser },
-       { "upstream", FIELD_STR, remote_ref_atom_parser },
-       { "push", FIELD_STR, remote_ref_atom_parser },
-       { "symref", FIELD_STR, refname_atom_parser },
-       { "flag" },
-       { "HEAD", FIELD_STR, head_atom_parser },
-       { "color", FIELD_STR, color_atom_parser },
-       { "align", FIELD_STR, align_atom_parser },
-       { "end" },
-       { "if", FIELD_STR, if_atom_parser },
-       { "then" },
-       { "else" },
+       { "refname", SOURCE_NONE, FIELD_STR, refname_atom_parser },
+       { "objecttype", SOURCE_OTHER, FIELD_STR, objecttype_atom_parser },
+       { "objectsize", SOURCE_OTHER, FIELD_ULONG, objectsize_atom_parser },
+       { "objectname", SOURCE_OTHER, FIELD_STR, objectname_atom_parser },
+       { "tree", SOURCE_OBJ },
+       { "parent", SOURCE_OBJ },
+       { "numparent", SOURCE_OBJ, FIELD_ULONG },
+       { "object", SOURCE_OBJ },
+       { "type", SOURCE_OBJ },
+       { "tag", SOURCE_OBJ },
+       { "author", SOURCE_OBJ },
+       { "authorname", SOURCE_OBJ },
+       { "authoremail", SOURCE_OBJ },
+       { "authordate", SOURCE_OBJ, FIELD_TIME },
+       { "committer", SOURCE_OBJ },
+       { "committername", SOURCE_OBJ },
+       { "committeremail", SOURCE_OBJ },
+       { "committerdate", SOURCE_OBJ, FIELD_TIME },
+       { "tagger", SOURCE_OBJ },
+       { "taggername", SOURCE_OBJ },
+       { "taggeremail", SOURCE_OBJ },
+       { "taggerdate", SOURCE_OBJ, FIELD_TIME },
+       { "creator", SOURCE_OBJ },
+       { "creatordate", SOURCE_OBJ, FIELD_TIME },
+       { "subject", SOURCE_OBJ, FIELD_STR, subject_atom_parser },
+       { "body", SOURCE_OBJ, FIELD_STR, body_atom_parser },
+       { "trailers", SOURCE_OBJ, FIELD_STR, trailers_atom_parser },
+       { "contents", SOURCE_OBJ, FIELD_STR, contents_atom_parser },
+       { "upstream", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
+       { "push", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
+       { "symref", SOURCE_NONE, FIELD_STR, refname_atom_parser },
+       { "flag", SOURCE_NONE },
+       { "HEAD", SOURCE_NONE, FIELD_STR, head_atom_parser },
+       { "color", SOURCE_NONE, FIELD_STR, color_atom_parser },
+       { "align", SOURCE_NONE, FIELD_STR, align_atom_parser },
+       { "end", SOURCE_NONE },
+       { "if", SOURCE_NONE, FIELD_STR, if_atom_parser },
+       { "then", SOURCE_NONE },
+       { "else", SOURCE_NONE },
 };
 
 #define REF_FORMATTING_STATE_INIT  { 0, NULL }
@@ -498,6 +538,13 @@ static int parse_ref_filter_atom(const struct ref_format *format,
        REALLOC_ARRAY(used_atom, used_atom_cnt);
        used_atom[at].name = xmemdupz(atom, ep - atom);
        used_atom[at].type = valid_atom[i].cmp_type;
+       used_atom[at].source = valid_atom[i].source;
+       if (used_atom[at].source == SOURCE_OBJ) {
+               if (*atom == '*')
+                       oi_deref.info.contentp = &oi_deref.content;
+               else
+                       oi.info.contentp = &oi.content;
+       }
        if (arg) {
                arg = used_atom[at].name + (arg - atom) + 1;
                if (!*arg) {
@@ -793,24 +840,6 @@ int verify_ref_format(struct ref_format *format)
        return 0;
 }
 
-/*
- * Given an object name, read the object data and size, and return a
- * "struct object".  If the object data we are returning is also borrowed
- * by the "struct object" representation, set *eaten as well---it is a
- * signal from parse_object_buffer to us not to free the buffer.
- */
-static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten)
-{
-       enum object_type type;
-       void *buf = read_object_file(oid, &type, sz);
-
-       if (buf)
-               *obj = parse_object_buffer(oid, type, *sz, buf, eaten);
-       else
-               *obj = NULL;
-       return buf;
-}
-
 static int grab_objectname(const char *name, const struct object_id *oid,
                           struct atom_value *v, struct used_atom *atom)
 {
@@ -831,7 +860,7 @@ static int grab_objectname(const char *name, const struct object_id *oid,
 }
 
 /* See grab_values */
-static void grab_common_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
+static void grab_common_values(struct atom_value *val, int deref, struct expand_data *oi)
 {
        int i;
 
@@ -843,13 +872,13 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
                if (deref)
                        name++;
                if (!strcmp(name, "objecttype"))
-                       v->s = type_name(obj->type);
+                       v->s = type_name(oi->type);
                else if (!strcmp(name, "objectsize")) {
-                       v->value = sz;
-                       v->s = xstrfmt("%lu", sz);
+                       v->value = oi->size;
+                       v->s = xstrfmt("%lu", oi->size);
                }
                else if (deref)
-                       grab_objectname(name, &obj->oid, v, &used_atom[i]);
+                       grab_objectname(name, &oi->oid, v, &used_atom[i]);
        }
 }
 
@@ -1208,7 +1237,6 @@ static void fill_missing_values(struct atom_value *val)
  */
 static void grab_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
 {
-       grab_common_values(val, deref, obj, buf, sz);
        switch (obj->type) {
        case OBJ_TAG:
                grab_tag_values(val, deref, obj, buf, sz);
@@ -1432,24 +1460,36 @@ static const char *get_refname(struct used_atom *atom, struct ref_array_item *re
        return show_ref(&atom->u.refname, ref->refname);
 }
 
-static int get_object(struct ref_array_item *ref, const struct object_id *oid,
-                      int deref, struct object **obj, struct strbuf *err)
+static int get_object(struct ref_array_item *ref, int deref, struct object **obj,
+                     struct expand_data *oi, struct strbuf *err)
 {
-       int eaten;
-       int ret = 0;
-       unsigned long size;
-       void *buf = get_obj(oid, obj, &size, &eaten);
-       if (!buf)
-               ret = strbuf_addf_ret(err, -1, _("missing object %s for %s"),
-                                     oid_to_hex(oid), ref->refname);
-       else if (!*obj)
-               ret = strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"),
-                                     oid_to_hex(oid), ref->refname);
-       else
-               grab_values(ref->value, deref, *obj, buf, size);
+       /* parse_object_buffer() will set eaten to 0 if free() will be needed */
+       int eaten = 1;
+       if (oi->info.contentp) {
+               /* We need to know that to use parse_object_buffer properly */
+               oi->info.sizep = &oi->size;
+               oi->info.typep = &oi->type;
+       }
+       if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
+                                    OBJECT_INFO_LOOKUP_REPLACE))
+               return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
+                                      oid_to_hex(&oi->oid), ref->refname);
+
+       if (oi->info.contentp) {
+               *obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten);
+               if (!obj) {
+                       if (!eaten)
+                               free(oi->content);
+                       return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"),
+                                              oid_to_hex(&oi->oid), ref->refname);
+               }
+               grab_values(ref->value, deref, *obj, oi->content, oi->size);
+       }
+
+       grab_common_values(ref->value, deref, oi);
        if (!eaten)
-               free(buf);
-       return ret;
+               free(oi->content);
+       return 0;
 }
 
 /*
@@ -1459,7 +1499,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
 {
        struct object *obj;
        int i;
-       const struct object_id *tagged;
+       struct object_info empty = OBJECT_INFO_INIT;
 
        ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));
 
@@ -1493,6 +1533,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
                        refname = get_symref(atom, ref);
                else if (starts_with(name, "upstream")) {
                        const char *branch_name;
+                       v->s = "";
                        /* only local branches may have an upstream */
                        if (!skip_prefix(ref->refname, "refs/heads/",
                                         &branch_name))
@@ -1505,6 +1546,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
                        continue;
                } else if (atom->u.remote_ref.push) {
                        const char *branch_name;
+                       v->s = "";
                        if (!skip_prefix(ref->refname, "refs/heads/",
                                         &branch_name))
                                continue;
@@ -1545,22 +1587,26 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
                        continue;
                } else if (starts_with(name, "align")) {
                        v->handler = align_atom_handler;
+                       v->s = "";
                        continue;
                } else if (!strcmp(name, "end")) {
                        v->handler = end_atom_handler;
+                       v->s = "";
                        continue;
                } else if (starts_with(name, "if")) {
                        const char *s;
-
+                       v->s = "";
                        if (skip_prefix(name, "if:", &s))
                                v->s = xstrdup(s);
                        v->handler = if_atom_handler;
                        continue;
                } else if (!strcmp(name, "then")) {
                        v->handler = then_atom_handler;
+                       v->s = "";
                        continue;
                } else if (!strcmp(name, "else")) {
                        v->handler = else_atom_handler;
+                       v->s = "";
                        continue;
                } else
                        continue;
@@ -1573,13 +1619,20 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
 
        for (i = 0; i < used_atom_cnt; i++) {
                struct atom_value *v = &ref->value[i];
-               if (v->s == NULL)
-                       break;
+               if (v->s == NULL && used_atom[i].source == SOURCE_NONE)
+                       return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
+                                              oid_to_hex(&ref->objectname), ref->refname);
        }
-       if (used_atom_cnt <= i)
+
+       if (need_tagged)
+               oi.info.contentp = &oi.content;
+       if (!memcmp(&oi.info, &empty, sizeof(empty)) &&
+           !memcmp(&oi_deref.info, &empty, sizeof(empty)))
                return 0;
 
-       if (get_object(ref, &ref->objectname, 0, &obj, err))
+
+       oi.oid = ref->objectname;
+       if (get_object(ref, 0, &obj, &oi, err))
                return -1;
 
        /*
@@ -1593,7 +1646,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
         * If it is a tag object, see if we use a value that derefs
         * the object, and if we do grab the object it refers to.
         */
-       tagged = &((struct tag *)obj)->tagged->oid;
+       oi_deref.oid = ((struct tag *)obj)->tagged->oid;
 
        /*
         * NEEDSWORK: This derefs tag only once, which
@@ -1601,7 +1654,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
         * is not consistent with what deref_tag() does
         * which peels the onion to the core.
         */
-       return get_object(ref, tagged, 1, &obj, err);
+       return get_object(ref, 1, &obj, &oi_deref, err);
 }
 
 /*
@@ -1710,7 +1763,7 @@ static enum contains_result contains_tag_algo(struct commit *candidate,
 
        for (p = want; p; p = p->next) {
                struct commit *c = p->item;
-               load_commit_graph_info(c);
+               load_commit_graph_info(the_repository, c);
                if (c->generation < cutoff)
                        cutoff = c->generation;
        }
@@ -1813,7 +1866,7 @@ static int match_name_as_path(const struct ref_filter *filter, const char *refna
                     refname[plen] == '/' ||
                     p[plen-1] == '/'))
                        return 1;
-               if (!wildmatch(p, refname, WM_PATHNAME))
+               if (!wildmatch(p, refname, flags))
                        return 1;
        }
        return 0;
@@ -1868,6 +1921,15 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
                return for_each_fullref_in("", cb, cb_data, broken);
        }
 
+       if (filter->ignore_case) {
+               /*
+                * we can't handle case-insensitive comparisons,
+                * so just return everything and let the caller
+                * sort it out.
+                */
+               return for_each_fullref_in("", cb, cb_data, broken);
+       }
+
        if (!filter->name_patterns[0]) {
                /* no patterns; we have to look at everything */
                return for_each_fullref_in("", cb, cb_data, broken);
@@ -1913,7 +1975,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 
        if (oid_array_lookup(points_at, oid) >= 0)
                return oid;
-       obj = parse_object(oid);
+       obj = parse_object(the_repository, oid);
        if (!obj)
                die(_("malformed object at '%s'"), refname);
        if (obj->type == OBJ_TAG)
@@ -2023,7 +2085,8 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
         * non-commits early. The actual filtering is done later.
         */
        if (filter->merge_commit || filter->with_commit || filter->no_commit || filter->verbose) {
-               commit = lookup_commit_reference_gently(oid, 1);
+               commit = lookup_commit_reference_gently(the_repository, oid,
+                                                       1);
                if (!commit)
                        return 0;
                /* We perform the filtering for the '--contains' option... */
@@ -2380,7 +2443,8 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
        if (get_oid(arg, &oid))
                die(_("malformed object name %s"), arg);
 
-       rf->merge_commit = lookup_commit_reference_gently(&oid, 0);
+       rf->merge_commit = lookup_commit_reference_gently(the_repository,
+                                                         &oid, 0);
        if (!rf->merge_commit)
                return opterror(opt, "must point to a commit", 0);
 
index 5008bbf6ada3707009722e3a3ca5b37437fbfb24..3a25b27d8f8dbd49b4c33c81cb6af3c92f59759d 100644 (file)
@@ -128,7 +128,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
        enum selector_type selector = SELECTOR_NONE;
 
        if (commit->object.flags & UNINTERESTING)
-               die ("Cannot walk reflogs for %s", name);
+               die("cannot walk reflogs for %s", name);
 
        branch = xstrdup(name);
        if (at && at[1] == '{') {
@@ -153,7 +153,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
                        free(branch);
                        branch = resolve_refdup("HEAD", 0, NULL, NULL);
                        if (!branch)
-                               die ("No current branch");
+                               die("no current branch");
 
                }
                reflogs = read_complete_reflog(branch);
@@ -305,7 +305,8 @@ static struct commit *next_reflog_commit(struct commit_reflog *log)
 {
        for (; log->recno >= 0; log->recno--) {
                struct reflog_info *entry = &log->reflogs->items[log->recno];
-               struct object *obj = parse_object(&entry->noid);
+               struct object *obj = parse_object(the_repository,
+                                                 &entry->noid);
 
                if (obj && obj->type == OBJ_COMMIT)
                        return (struct commit *)obj;
diff --git a/refs.c b/refs.c
index 0eb379f9312fd9f167fea2e0f148c85c47cd2ff0..de81c7be7ca8d3ca033b34a61f33b0bff069932f 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -9,6 +9,7 @@
 #include "iterator.h"
 #include "refs.h"
 #include "refs/refs-internal.h"
+#include "object-store.h"
 #include "object.h"
 #include "tag.h"
 #include "submodule.h"
@@ -188,7 +189,7 @@ int ref_resolves_to_object(const char *refname,
        if (flags & REF_ISBROKEN)
                return 0;
        if (!has_sha1_file(oid->hash)) {
-               error("%s does not point to a valid object!", refname);
+               error(_("%s does not point to a valid object!"), refname);
                return 0;
        }
        return 1;
@@ -304,7 +305,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid
 
        if (o->type == OBJ_NONE) {
                int type = oid_object_info(the_repository, name, NULL);
-               if (type < 0 || !object_as_type(o, type, 0))
+               if (type < 0 || !object_as_type(the_repository, o, type, 0))
                        return PEEL_INVALID;
        }
 
@@ -489,16 +490,24 @@ static const char *ref_rev_parse_rules[] = {
        NULL
 };
 
+#define NUM_REV_PARSE_RULES (ARRAY_SIZE(ref_rev_parse_rules) - 1)
+
+/*
+ * Is it possible that the caller meant full_name with abbrev_name?
+ * If so return a non-zero value to signal "yes"; the magnitude of
+ * the returned value gives the precedence used for disambiguation.
+ *
+ * If abbrev_name cannot mean full_name, return 0.
+ */
 int refname_match(const char *abbrev_name, const char *full_name)
 {
        const char **p;
        const int abbrev_name_len = strlen(abbrev_name);
+       const int num_rules = NUM_REV_PARSE_RULES;
 
-       for (p = ref_rev_parse_rules; *p; p++) {
-               if (!strcmp(full_name, mkpath(*p, abbrev_name_len, abbrev_name))) {
-                       return 1;
-               }
-       }
+       for (p = ref_rev_parse_rules; *p; p++)
+               if (!strcmp(full_name, mkpath(*p, abbrev_name_len, abbrev_name)))
+                       return &ref_rev_parse_rules[num_rules] - p;
 
        return 0;
 }
@@ -567,9 +576,9 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
                        if (!warn_ambiguous_refs)
                                break;
                } else if ((flag & REF_ISSYMREF) && strcmp(fullref.buf, "HEAD")) {
-                       warning("ignoring dangling symref %s.", fullref.buf);
+                       warning(_("ignoring dangling symref %s"), fullref.buf);
                } else if ((flag & REF_ISBROKEN) && strchr(fullref.buf, '/')) {
-                       warning("ignoring broken ref %s.", fullref.buf);
+                       warning(_("ignoring broken ref %s"), fullref.buf);
                }
        }
        strbuf_release(&fullref);
@@ -673,7 +682,7 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
        fd = hold_lock_file_for_update_timeout(&lock, filename, 0,
                                               get_files_ref_lock_timeout_ms());
        if (fd < 0) {
-               strbuf_addf(err, "could not open '%s' for writing: %s",
+               strbuf_addf(err, _("could not open '%s' for writing: %s"),
                            filename, strerror(errno));
                goto done;
        }
@@ -683,18 +692,18 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
 
                if (read_ref(pseudoref, &actual_old_oid)) {
                        if (!is_null_oid(old_oid)) {
-                               strbuf_addf(err, "could not read ref '%s'",
+                               strbuf_addf(err, _("could not read ref '%s'"),
                                            pseudoref);
                                rollback_lock_file(&lock);
                                goto done;
                        }
                } else if (is_null_oid(old_oid)) {
-                       strbuf_addf(err, "ref '%s' already exists",
+                       strbuf_addf(err, _("ref '%s' already exists"),
                                    pseudoref);
                        rollback_lock_file(&lock);
                        goto done;
                } else if (oidcmp(&actual_old_oid, old_oid)) {
-                       strbuf_addf(err, "unexpected object ID when writing '%s'",
+                       strbuf_addf(err, _("unexpected object ID when writing '%s'"),
                                    pseudoref);
                        rollback_lock_file(&lock);
                        goto done;
@@ -702,7 +711,7 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
        }
 
        if (write_in_full(fd, buf.buf, buf.len) < 0) {
-               strbuf_addf(err, "could not write to '%s'", filename);
+               strbuf_addf(err, _("could not write to '%s'"), filename);
                rollback_lock_file(&lock);
                goto done;
        }
@@ -734,9 +743,9 @@ static int delete_pseudoref(const char *pseudoref, const struct object_id *old_o
                        return -1;
                }
                if (read_ref(pseudoref, &actual_old_oid))
-                       die("could not read ref '%s'", pseudoref);
+                       die(_("could not read ref '%s'"), pseudoref);
                if (oidcmp(&actual_old_oid, old_oid)) {
-                       error("unexpected object ID when deleting '%s'",
+                       error(_("unexpected object ID when deleting '%s'"),
                              pseudoref);
                        rollback_lock_file(&lock);
                        return -1;
@@ -786,25 +795,21 @@ int delete_ref(const char *msg, const char *refname,
                               old_oid, flags);
 }
 
-int copy_reflog_msg(char *buf, const char *msg)
+void copy_reflog_msg(struct strbuf *sb, const char *msg)
 {
-       char *cp = buf;
        char c;
        int wasspace = 1;
 
-       *cp++ = '\t';
+       strbuf_addch(sb, '\t');
        while ((c = *msg++)) {
                if (wasspace && isspace(c))
                        continue;
                wasspace = isspace(c);
                if (wasspace)
                        c = ' ';
-               *cp++ = c;
+               strbuf_addch(sb, c);
        }
-       while (buf < cp && isspace(cp[-1]))
-               cp--;
-       *cp++ = '\n';
-       return cp - buf;
+       strbuf_rtrim(sb);
 }
 
 int should_autocreate_reflog(const char *refname)
@@ -871,13 +876,13 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
                if (!is_null_oid(&cb->ooid)) {
                        oidcpy(cb->oid, noid);
                        if (oidcmp(&cb->ooid, noid))
-                               warning("Log for ref %s has gap after %s.",
+                               warning(_("log for ref %s has gap after %s"),
                                        cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
                }
                else if (cb->date == cb->at_time)
                        oidcpy(cb->oid, noid);
                else if (oidcmp(noid, cb->oid))
-                       warning("Log for ref %s unexpectedly ended on %s.",
+                       warning(_("log for ref %s unexpectedly ended on %s"),
                                cb->refname, show_date(cb->date, cb->tz,
                                                       DATE_MODE(RFC2822)));
                oidcpy(&cb->ooid, ooid);
@@ -935,7 +940,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
                if (flags & GET_OID_QUIETLY)
                        exit(128);
                else
-                       die("Log for %s is empty.", refname);
+                       die(_("log for %s is empty"), refname);
        }
        if (cb.found_it)
                return 0;
@@ -1027,7 +1032,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
        if ((new_oid && !is_null_oid(new_oid)) ?
            check_refname_format(refname, REFNAME_ALLOW_ONELEVEL) :
            !refname_is_safe(refname)) {
-               strbuf_addf(err, "refusing to update ref with bad name '%s'",
+               strbuf_addf(err, _("refusing to update ref with bad name '%s'"),
                            refname);
                return -1;
        }
@@ -1103,7 +1108,7 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
                }
        }
        if (ret) {
-               const char *str = "update_ref failed for ref '%s': %s";
+               const char *str = _("update_ref failed for ref '%s': %s");
 
                switch (onerr) {
                case UPDATE_REFS_MSG_ON_ERR:
@@ -1845,7 +1850,7 @@ int ref_update_reject_duplicates(struct string_list *refnames,
 
                if (!cmp) {
                        strbuf_addf(err,
-                                   "multiple updates for ref '%s' not allowed.",
+                                   _("multiple updates for ref '%s' not allowed"),
                                    refnames->items[i].string);
                        return 1;
                } else if (cmp > 0) {
@@ -1973,13 +1978,13 @@ int refs_verify_refname_available(struct ref_store *refs,
                        continue;
 
                if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent, &type)) {
-                       strbuf_addf(err, "'%s' exists; cannot create '%s'",
+                       strbuf_addf(err, _("'%s' exists; cannot create '%s'"),
                                    dirname.buf, refname);
                        goto cleanup;
                }
 
                if (extras && string_list_has_string(extras, dirname.buf)) {
-                       strbuf_addf(err, "cannot process '%s' and '%s' at the same time",
+                       strbuf_addf(err, _("cannot process '%s' and '%s' at the same time"),
                                    refname, dirname.buf);
                        goto cleanup;
                }
@@ -2003,7 +2008,7 @@ int refs_verify_refname_available(struct ref_store *refs,
                    string_list_has_string(skip, iter->refname))
                        continue;
 
-               strbuf_addf(err, "'%s' exists; cannot create '%s'",
+               strbuf_addf(err, _("'%s' exists; cannot create '%s'"),
                            iter->refname, refname);
                ref_iterator_abort(iter);
                goto cleanup;
@@ -2014,7 +2019,7 @@ int refs_verify_refname_available(struct ref_store *refs,
 
        extra_refname = find_descendant_ref(dirname.buf, extras, skip);
        if (extra_refname)
-               strbuf_addf(err, "cannot process '%s' and '%s' at the same time",
+               strbuf_addf(err, _("cannot process '%s' and '%s' at the same time"),
                            refname, extra_refname);
        else
                ret = 0;
index a9a066dcfb60d83a10e27d1c0d1131faf2ae97a4..1f1a98e4cb0610039e66f24dab59205377d90144 100644 (file)
@@ -363,7 +363,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
        /* Follow "normalized" - ie "refs/.." symlinks by hand */
        if (S_ISLNK(st.st_mode)) {
                strbuf_reset(&sb_contents);
-               if (strbuf_readlink(&sb_contents, path, 0) < 0) {
+               if (strbuf_readlink(&sb_contents, path, st.st_size) < 0) {
                        if (errno == ENOENT || errno == EINVAL)
                                /* inconsistent with lstat; retry */
                                goto stat_ref;
@@ -1582,26 +1582,17 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,
                            const struct object_id *new_oid,
                            const char *committer, const char *msg)
 {
-       int msglen, written;
-       unsigned maxlen, len;
-       char *logrec;
-
-       msglen = msg ? strlen(msg) : 0;
-       maxlen = strlen(committer) + msglen + 100;
-       logrec = xmalloc(maxlen);
-       len = xsnprintf(logrec, maxlen, "%s %s %s\n",
-                       oid_to_hex(old_oid),
-                       oid_to_hex(new_oid),
-                       committer);
-       if (msglen)
-               len += copy_reflog_msg(logrec + len - 1, msg) - 1;
-
-       written = len <= maxlen ? write_in_full(fd, logrec, len) : -1;
-       free(logrec);
-       if (written < 0)
-               return -1;
+       struct strbuf sb = STRBUF_INIT;
+       int ret = 0;
 
-       return 0;
+       strbuf_addf(&sb, "%s %s %s", oid_to_hex(old_oid), oid_to_hex(new_oid), committer);
+       if (msg && *msg)
+               copy_reflog_msg(&sb, msg);
+       strbuf_addch(&sb, '\n');
+       if (write_in_full(fd, sb.buf, sb.len) < 0)
+               ret = -1;
+       strbuf_release(&sb);
+       return ret;
 }
 
 static int files_log_ref_write(struct files_ref_store *refs,
@@ -1660,7 +1651,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
        struct object *o;
        int fd;
 
-       o = parse_object(oid);
+       o = parse_object(the_repository, oid);
        if (!o) {
                strbuf_addf(err,
                            "trying to write ref '%s' with nonexistent object %s",
@@ -1676,7 +1667,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
                return -1;
        }
        fd = get_lock_file_fd(&lock->lk);
-       if (write_in_full(fd, oid_to_hex(oid), GIT_SHA1_HEXSZ) < 0 ||
+       if (write_in_full(fd, oid_to_hex(oid), the_hash_algo->hexsz) < 0 ||
            write_in_full(fd, &term, 1) < 0 ||
            close_ref_gently(lock) < 0) {
                strbuf_addf(err,
@@ -3070,7 +3061,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
                        rollback_lock_file(&reflog_lock);
                } else if (update &&
                           (write_in_full(get_lock_file_fd(&lock->lk),
-                               oid_to_hex(&cb.last_kept_oid), GIT_SHA1_HEXSZ) < 0 ||
+                               oid_to_hex(&cb.last_kept_oid), the_hash_algo->hexsz) < 0 ||
                            write_str_in_full(get_lock_file_fd(&lock->lk), "\n") < 0 ||
                            close_ref_gently(lock) < 0)) {
                        status |= error("couldn't write %s",
index dd834314bd8d5af0315dab19af50f3300a73ad90..04425d6d1e45e2401454e7b89b0ed4b3959926de 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef REFS_REFS_INTERNAL_H
 #define REFS_REFS_INTERNAL_H
 
+#include "iterator.h"
+
 /*
  * Data structures and functions for the internal use of the refs
  * module. Code outside of the refs module should use only the public
@@ -91,11 +93,10 @@ enum peel_status {
 enum peel_status peel_object(const struct object_id *name, struct object_id *oid);
 
 /*
- * Copy the reflog message msg to buf, which has been allocated sufficiently
- * large, while cleaning up the whitespaces.  Especially, convert LF to space,
- * because reflog file is one line per entry.
+ * Copy the reflog message msg to sb while cleaning up the whitespaces.
+ * Especially, convert LF to space, because reflog file is one line per entry.
  */
-int copy_reflog_msg(char *buf, const char *msg);
+void copy_reflog_msg(struct strbuf *sb, const char *msg);
 
 /**
  * Information needed for a single ref update. Set new_oid to the new
index e8010dce0ce27472c2b3269e13b9c1de6a69f3cc..f529092fd6d9ba0474fd21b31d72c117794e640d 100644 (file)
--- a/refspec.c
+++ b/refspec.c
@@ -134,7 +134,7 @@ void refspec_item_init_or_die(struct refspec_item *item, const char *refspec,
                              int fetch)
 {
        if (!refspec_item_init(item, refspec, fetch))
-               die("Invalid refspec '%s'", refspec);
+               die(_("invalid refspec '%s'"), refspec);
 }
 
 void refspec_item_clear(struct refspec_item *item)
index 99b0bedc6ddc670cad6e74083dc33dc0aa4b595a..fb28309e850518018667dc746c630acc1f497981 100644 (file)
@@ -714,7 +714,7 @@ static int post_rpc(struct rpc_state *rpc)
 
        } else if (use_gzip && 1024 < rpc->len) {
                /* The client backend isn't giving us compressed data so
-                * we can try to deflate it ourselves, this may save on.
+                * we can try to deflate it ourselves, this may save on
                 * the transfer time.
                 */
                git_zstream stream;
index 444d98059f681e21beeb3e66fe8539887cfb74d1..3af708c5b671920cff3d1888eb9c8ae724e0d648 100644 (file)
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "refs.h"
 #include "remote.h"
+#include "object-store.h"
 #include "strbuf.h"
 #include "url.h"
 #include "exec-cmd.h"
index abe80c13972c718bd5d738063a2f526f2d12ee87..7f6277a1451d147fc5af4ae2910e7c40dd330aec 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -3,6 +3,7 @@
 #include "remote.h"
 #include "refs.h"
 #include "refspec.h"
+#include "object-store.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
@@ -1148,7 +1149,7 @@ static void add_to_tips(struct tips *tips, const struct object_id *oid)
 
        if (is_null_oid(oid))
                return;
-       commit = lookup_commit_reference_gently(oid, 1);
+       commit = lookup_commit_reference_gently(the_repository, oid, 1);
        if (!commit || (commit->object.flags & TMP_MARK))
                return;
        commit->object.flags |= TMP_MARK;
@@ -1210,7 +1211,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 
                        if (is_null_oid(&ref->new_oid))
                                continue;
-                       commit = lookup_commit_reference_gently(&ref->new_oid,
+                       commit = lookup_commit_reference_gently(the_repository,
+                                                               &ref->new_oid,
                                                                1);
                        if (!commit)
                                /* not pushing a commit, which is not an error */
@@ -1434,8 +1436,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
                                reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
                        else if (!has_object_file(&ref->old_oid))
                                reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
-                       else if (!lookup_commit_reference_gently(&ref->old_oid, 1) ||
-                                !lookup_commit_reference_gently(&ref->new_oid, 1))
+                       else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) ||
+                                !lookup_commit_reference_gently(the_repository, &ref->new_oid, 1))
                                reject_reason = REF_STATUS_REJECT_NEEDS_FORCE;
                        else if (!ref_newer(&ref->new_oid, &ref->old_oid))
                                reject_reason = REF_STATUS_REJECT_NONFASTFORWARD;
@@ -1687,11 +1689,18 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
 static const struct ref *find_ref_by_name_abbrev(const struct ref *refs, const char *name)
 {
        const struct ref *ref;
+       const struct ref *best_match = NULL;
+       int best_score = 0;
+
        for (ref = refs; ref; ref = ref->next) {
-               if (refname_match(name, ref->name))
-                       return ref;
+               int score = refname_match(name, ref->name);
+
+               if (best_score < score) {
+                       best_match = ref;
+                       best_score = score;
+               }
        }
-       return NULL;
+       return best_match;
 }
 
 struct ref *get_remote_ref(const struct ref *remote_refs, const char *name)
@@ -1735,6 +1744,7 @@ int get_fetch_map(const struct ref *remote_refs,
                if (refspec->exact_sha1) {
                        ref_map = alloc_ref(name);
                        get_oid_hex(name, &ref_map->old_oid);
+                       ref_map->exact_oid = 1;
                } else {
                        ref_map = get_remote_ref(remote_refs, name);
                }
@@ -1800,12 +1810,14 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
         * Both new_commit and old_commit must be commit-ish and new_commit is descendant of
         * old_commit.  Otherwise we require --force.
         */
-       o = deref_tag(parse_object(old_oid), NULL, 0);
+       o = deref_tag(the_repository, parse_object(the_repository, old_oid),
+                     NULL, 0);
        if (!o || o->type != OBJ_COMMIT)
                return 0;
        old_commit = (struct commit *) o;
 
-       o = deref_tag(parse_object(new_oid), NULL, 0);
+       o = deref_tag(the_repository, parse_object(the_repository, new_oid),
+                     NULL, 0);
        if (!o || o->type != OBJ_COMMIT)
                return 0;
        new_commit = (struct commit *) o;
@@ -1863,13 +1875,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
        /* Cannot stat if what we used to build on no longer exists */
        if (read_ref(base, &oid))
                return -1;
-       theirs = lookup_commit_reference(&oid);
+       theirs = lookup_commit_reference(the_repository, &oid);
        if (!theirs)
                return -1;
 
        if (read_ref(branch->refname, &oid))
                return -1;
-       ours = lookup_commit_reference(&oid);
+       ours = lookup_commit_reference(the_repository, &oid);
        if (!ours)
                return -1;
 
index 45ecc6cefafdea435d0fee39691f7458b940b877..976292152c020127e6c88d54e5448ef21e0eb4e8 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -73,6 +73,7 @@ struct ref {
                force:1,
                forced_update:1,
                expect_old_sha1:1,
+               exact_oid:1,
                deletion:1;
 
        enum {
index 801b5c16789f5ac7d87a4409d8218311a52db0aa..4ec77ce41848311a912256046bd2bf8dc9ee63c0 100644 (file)
@@ -17,7 +17,7 @@ static int register_replace_ref(const char *refname,
 
        if (get_oid_hex(hash, &repl_obj->original.oid)) {
                free(repl_obj);
-               warning("bad replace ref name: %s", refname);
+               warning(_("bad replace ref name: %s"), refname);
                return 0;
        }
 
@@ -26,7 +26,7 @@ static int register_replace_ref(const char *refname,
 
        /* Register new object */
        if (oidmap_put(the_repository->objects->replace_map, repl_obj))
-               die("duplicate replace ref: %s", refname);
+               die(_("duplicate replace ref: %s"), refname);
 
        return 0;
 }
@@ -51,7 +51,7 @@ static void prepare_replace_object(struct repository *r)
  * replacement object's name (replaced recursively, if necessary).
  * The return value is either oid or a pointer to a
  * permanently-allocated value.  This function always respects replace
- * references, regardless of the value of check_replace_refs.
+ * references, regardless of the value of read_replace_refs.
  */
 const struct object_id *do_lookup_replace_object(struct repository *r,
                                                 const struct object_id *oid)
@@ -69,5 +69,5 @@ const struct object_id *do_lookup_replace_object(struct repository *r,
                        return cur;
                cur = &repl_obj->replacement;
        }
-       die("replace depth too high for object %s", oid_to_hex(oid));
+       die(_("replace depth too high for object %s"), oid_to_hex(oid));
 }
index f996de3d62c6aaa9d30792e5347613ff1f63fbe0..9345e105ddcaa38cf9e856df70d960245a3b696c 100644 (file)
@@ -26,7 +26,7 @@ extern const struct object_id *do_lookup_replace_object(struct repository *r,
 static inline const struct object_id *lookup_replace_object(struct repository *r,
                                                            const struct object_id *oid)
 {
-       if (!check_replace_refs ||
+       if (!read_replace_refs ||
            (r->objects->replace_map &&
             r->objects->replace_map->map.tablesize == 0))
                return oid;
index dba3ddbfdd2d48068d60100425d1a22025cd25b0..58961037c4acbe825b0a8b257e9601da8bd29b37 100644 (file)
@@ -38,6 +38,11 @@ struct repository {
        /* The store in which the refs are held. */
        struct ref_store *refs;
 
+       /*
+        * Contains path to often used file names.
+        */
+       struct path_cache cached_paths;
+
        /*
         * Path to the repository's graft file.
         * Cannot be NULL after initialization.
@@ -103,19 +108,16 @@ struct set_gitdir_args {
        const char *alternate_db;
 };
 
-extern void repo_set_gitdir(struct repository *repo,
-                           const char *root,
-                           const struct set_gitdir_args *extra_args);
-extern void repo_set_worktree(struct repository *repo, const char *path);
-extern void repo_set_hash_algo(struct repository *repo, int algo);
-extern void initialize_the_repository(void);
-extern int repo_init(struct repository *r,
-                    const char *gitdir,
-                    const char *worktree);
-extern int repo_submodule_init(struct repository *submodule,
-                              struct repository *superproject,
-                              const char *path);
-extern void repo_clear(struct repository *repo);
+void repo_set_gitdir(struct repository *repo, const char *root,
+                    const struct set_gitdir_args *extra_args);
+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,
+                       struct repository *superproject,
+                       const char *path);
+void repo_clear(struct repository *repo);
 
 /*
  * Populates the repository's index from its index_file, an index struct will
@@ -125,6 +127,6 @@ extern void repo_clear(struct repository *repo);
  * than zero if an error occured.  If the repository's index has already been
  * populated then the number of entries will simply be returned.
  */
-extern int repo_read_index(struct repository *repo);
+int repo_read_index(struct repository *repo);
 
 #endif /* REPOSITORY_H */
index e0862e27786244b1a98723d09475223cc001dd62..c7787aa07f80f00589e3c4f4e4e3cc825c43044e 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -9,6 +9,7 @@
 #include "ll-merge.h"
 #include "attr.h"
 #include "pathspec.h"
+#include "object-store.h"
 #include "sha1-lookup.h"
 
 #define RESOLVED 0
@@ -200,7 +201,7 @@ static struct rerere_id *new_rerere_id(unsigned char *sha1)
 static void read_rr(struct string_list *rr)
 {
        struct strbuf buf = STRBUF_INIT;
-       FILE *in = fopen_or_warn(git_path_merge_rr(), "r");
+       FILE *in = fopen_or_warn(git_path_merge_rr(the_repository), "r");
 
        if (!in)
                return;
@@ -895,7 +896,8 @@ int setup_rerere(struct string_list *merge_rr, int flags)
        if (flags & RERERE_READONLY)
                fd = 0;
        else
-               fd = hold_lock_file_for_update(&write_lock, git_path_merge_rr(),
+               fd = hold_lock_file_for_update(&write_lock,
+                                              git_path_merge_rr(the_repository),
                                               LOCK_DIE_ON_ERROR);
        read_rr(merge_rr);
        return fd;
@@ -1118,7 +1120,7 @@ int rerere_forget(struct pathspec *pathspec)
        find_conflict(&conflict);
        for (i = 0; i < conflict.nr; i++) {
                struct string_list_item *it = &conflict.items[i];
-               if (!match_pathspec(pathspec, it->string,
+               if (!match_pathspec(&the_index, pathspec, it->string,
                                    strlen(it->string), 0, NULL, 0))
                        continue;
                rerere_forget_one_path(it->string, &merge_rr);
@@ -1245,6 +1247,6 @@ void rerere_clear(struct string_list *merge_rr)
                        rmdir(rerere_path(id, NULL));
                }
        }
-       unlink_or_warn(git_path_merge_rr());
+       unlink_or_warn(git_path_merge_rr(the_repository));
        rollback_lock_file(&write_lock);
 }
index c2961feaaa8a8297d59fb13b120c1a57c8a2868a..cd948f28f494286c8e5750908eb7e35cf4293af3 100644 (file)
--- a/rerere.h
+++ b/rerere.h
@@ -22,19 +22,19 @@ struct rerere_id {
        int variant;
 };
 
-extern int setup_rerere(struct string_list *, int);
-extern int rerere(int);
+int setup_rerere(struct string_list *, int);
+int rerere(int);
 /*
  * Given the conflict ID and the name of a "file" used for replaying
  * the recorded resolution (e.g. "preimage", "postimage"), return the
  * path to that filesystem entity.  With "file" specified with NULL,
  * return the path to the directory that houses these files.
  */
-extern const char *rerere_path(const struct rerere_id *, const char *file);
-extern int rerere_forget(struct pathspec *);
-extern int rerere_remaining(struct string_list *);
-extern void rerere_clear(struct string_list *);
-extern void rerere_gc(struct string_list *);
+const char *rerere_path(const struct rerere_id *, const char *file);
+int rerere_forget(struct pathspec *);
+int rerere_remaining(struct string_list *);
+void rerere_clear(struct string_list *);
+void rerere_gc(struct string_list *);
 
 #define OPT_RERERE_AUTOUPDATE(v) OPT_UYN(0, "rerere-autoupdate", (v), \
        N_("update the index with reused conflict resolution if possible"))
index fc5b3b83d9a08e9deed55ee15520387f147da626..236320f179cbf60a312f882ee57e1f843398e907 100644 (file)
@@ -146,7 +146,9 @@ int unmerge_index_entry_at(struct index_state *istate, int pos)
                struct cache_entry *nce;
                if (!ru->mode[i])
                        continue;
-               nce = make_cache_entry(ru->mode[i], ru->oid[i].hash,
+               nce = make_cache_entry(istate,
+                                      ru->mode[i],
+                                      &ru->oid[i],
                                       name, i + 1, 0);
                if (matched)
                        nce->ce_flags |= CE_MATCHED;
@@ -186,7 +188,7 @@ void unmerge_index(struct index_state *istate, const struct pathspec *pathspec)
 
        for (i = 0; i < istate->cache_nr; i++) {
                const struct cache_entry *ce = istate->cache[i];
-               if (!ce_path_match(ce, pathspec, NULL))
+               if (!ce_path_match(istate, ce, pathspec, NULL))
                        continue;
                i = unmerge_index_entry_at(istate, i);
        }
index 0afae4744a12b9b1bfd484c12440db82e19c8c9f..de4dce600d00282655907e9014228791a352f813 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "tag.h"
 #include "blob.h"
 #include "tree.h"
@@ -62,10 +63,10 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
        while (tree_entry(&desc, &entry)) {
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
-                       mark_tree_uninteresting(lookup_tree(entry.oid));
+                       mark_tree_uninteresting(lookup_tree(the_repository, entry.oid));
                        break;
                case OBJ_BLOB:
-                       mark_blob_uninteresting(lookup_blob(entry.oid));
+                       mark_blob_uninteresting(lookup_blob(the_repository, entry.oid));
                        break;
                default:
                        /* Subproject commit - not in this repository */
@@ -174,6 +175,7 @@ static void add_pending_object_with_path(struct rev_info *revs,
                strbuf_release(&buf);
                return; /* do not add the commit itself */
        }
+       obj->flags |= USER_GIVEN;
        add_object_array_with_path(obj, name, &revs->pending, mode, path);
 }
 
@@ -196,7 +198,7 @@ void add_head_to_pending(struct rev_info *revs)
        struct object *obj;
        if (get_oid("HEAD", &oid))
                return;
-       obj = parse_object(&oid);
+       obj = parse_object(the_repository, &oid);
        if (!obj)
                return;
        add_pending_object(revs, obj, "HEAD");
@@ -208,7 +210,7 @@ static struct object *get_reference(struct rev_info *revs, const char *name,
 {
        struct object *object;
 
-       object = parse_object(oid);
+       object = parse_object(the_repository, oid);
        if (!object) {
                if (revs->ignore_missing)
                        return object;
@@ -245,10 +247,13 @@ static struct commit *handle_commit(struct rev_info *revs,
                        add_pending_object(revs, object, tag->tag);
                if (!tag->tagged)
                        die("bad tag");
-               object = parse_object(&tag->tagged->oid);
+               object = parse_object(the_repository, &tag->tagged->oid);
                if (!object) {
                        if (revs->ignore_missing_links || (flags & UNINTERESTING))
                                return NULL;
+                       if (revs->exclude_promisor_objects &&
+                           is_promisor_object(&tag->tagged->oid))
+                               return NULL;
                        die("bad object %s", oid_to_hex(&tag->tagged->oid));
                }
                object->flags |= flags;
@@ -1248,7 +1253,7 @@ static void handle_one_reflog_commit(struct object_id *oid, void *cb_data)
 {
        struct all_refs_cb *cb = cb_data;
        if (!is_null_oid(oid)) {
-               struct object *o = parse_object(oid);
+               struct object *o = parse_object(the_repository, oid);
                if (o) {
                        o->flags |= cb->all_flags;
                        /* ??? CMDLINEFLAGS ??? */
@@ -1321,7 +1326,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
        int i;
 
        if (it->entry_count >= 0) {
-               struct tree *tree = lookup_tree(&it->oid);
+               struct tree *tree = lookup_tree(the_repository, &it->oid);
                add_pending_object_with_path(revs, &tree->object, "",
                                             040000, path->buf);
        }
@@ -1347,7 +1352,7 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
                if (S_ISGITLINK(ce->ce_mode))
                        continue;
 
-               blob = lookup_blob(&ce->oid);
+               blob = lookup_blob(the_repository, &ce->oid);
                if (!blob)
                        die("unable to add index blob to traversal");
                add_pending_object_with_path(revs, &blob->object, "",
@@ -1512,7 +1517,7 @@ static void prepare_show_merge(struct rev_info *revs)
                const struct cache_entry *ce = active_cache[i];
                if (!ce_stage(ce))
                        continue;
-               if (ce_path_match(ce, &revs->prune_data, NULL)) {
+               if (ce_path_match(&the_index, ce, &revs->prune_data, NULL)) {
                        prune_num++;
                        REALLOC_ARRAY(prune, prune_num);
                        prune[prune_num-2] = ce->name;
@@ -1576,8 +1581,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
                *dotdot = '\0';
        }
 
-       a_obj = parse_object(&a_oid);
-       b_obj = parse_object(&b_oid);
+       a_obj = parse_object(the_repository, &a_oid);
+       b_obj = parse_object(the_repository, &b_oid);
        if (!a_obj || !b_obj)
                return dotdot_missing(arg, dotdot, revs, symmetric);
 
@@ -1590,8 +1595,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
                struct commit *a, *b;
                struct commit_list *exclude;
 
-               a = lookup_commit_reference(&a_obj->oid);
-               b = lookup_commit_reference(&b_obj->oid);
+               a = lookup_commit_reference(the_repository, &a_obj->oid);
+               b = lookup_commit_reference(the_repository, &b_obj->oid);
                if (!a || !b)
                        return dotdot_missing(arg, dotdot, revs, symmetric);
 
@@ -2882,7 +2887,7 @@ static int mark_uninteresting(const struct object_id *oid,
                              uint32_t pos,
                              void *unused)
 {
-       struct object *o = parse_object(oid);
+       struct object *o = parse_object(the_repository, oid);
        o->flags |= UNINTERESTING | SEEN;
        return 0;
 }
index bf2239f87689d9486c4b888bed5cba6affa21953..51bb57d889b316aaf90c416446ea995d5e2e9e25 100644 (file)
@@ -20,8 +20,9 @@
 #define SYMMETRIC_LEFT (1u<<8)
 #define PATCHSAME      (1u<<9)
 #define BOTTOM         (1u<<10)
+#define USER_GIVEN     (1u<<25) /* given directly by the user */
 #define TRACK_LINEAR   (1u<<26)
-#define ALL_REV_FLAGS  (((1u<<11)-1) | TRACK_LINEAR)
+#define ALL_REV_FLAGS  (((1u<<11)-1) | USER_GIVEN | TRACK_LINEAR)
 
 #define DECORATE_SHORT_REFS    1
 #define DECORATE_FULL_REFS     2
@@ -229,7 +230,7 @@ struct rev_info {
        struct revision_sources *sources;
 };
 
-extern int ref_excluded(struct string_list *, const char *path);
+int ref_excluded(struct string_list *, const char *path);
 void clear_ref_exclusion(struct string_list **);
 void add_ref_exclusion(struct string_list **, const char *exclude);
 
@@ -251,39 +252,39 @@ struct setup_revision_opt {
        unsigned revarg_opt;
 };
 
-extern void init_revisions(struct rev_info *revs, const char *prefix);
-extern int setup_revisions(int argc, const char **argv, struct rev_info *revs,
-                          struct setup_revision_opt *);
-extern void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
-                              const struct option *options,
-                              const char * const usagestr[]);
+void init_revisions(struct rev_info *revs, const char *prefix);
+int setup_revisions(int argc, const char **argv, struct rev_info *revs,
+                   struct setup_revision_opt *);
+void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
+                       const struct option *options,
+                       const char * const usagestr[]);
 #define REVARG_CANNOT_BE_FILENAME 01
 #define REVARG_COMMITTISH 02
-extern int handle_revision_arg(const char *arg, struct rev_info *revs,
-                              int flags, unsigned revarg_opt);
+int handle_revision_arg(const char *arg, struct rev_info *revs,
+                       int flags, unsigned revarg_opt);
 
-extern void reset_revision_walk(void);
-extern int prepare_revision_walk(struct rev_info *revs);
-extern struct commit *get_revision(struct rev_info *revs);
-extern char *get_revision_mark(const struct rev_info *revs,
-                              const struct commit *commit);
-extern void put_revision_mark(const struct rev_info *revs,
-                             const struct commit *commit);
+void reset_revision_walk(void);
+int prepare_revision_walk(struct rev_info *revs);
+struct commit *get_revision(struct rev_info *revs);
+char *get_revision_mark(const struct rev_info *revs,
+                       const struct commit *commit);
+void put_revision_mark(const struct rev_info *revs,
+                      const struct commit *commit);
 
-extern void mark_parents_uninteresting(struct commit *commit);
-extern void mark_tree_uninteresting(struct tree *tree);
+void mark_parents_uninteresting(struct commit *commit);
+void mark_tree_uninteresting(struct tree *tree);
 
-extern void show_object_with_name(FILE *, struct object *, const char *);
+void show_object_with_name(FILE *, struct object *, const char *);
 
-extern void add_pending_object(struct rev_info *revs,
-                              struct object *obj, const char *name);
-extern void add_pending_oid(struct rev_info *revs,
-                           const char *name, const struct object_id *oid,
-                           unsigned int flags);
+void add_pending_object(struct rev_info *revs,
+                       struct object *obj, const char *name);
+void add_pending_oid(struct rev_info *revs,
+                    const char *name, const struct object_id *oid,
+                    unsigned int flags);
 
-extern void add_head_to_pending(struct rev_info *);
-extern void add_reflogs_to_pending(struct rev_info *, unsigned int flags);
-extern void add_index_objects_to_pending(struct rev_info *, unsigned int flags);
+void add_head_to_pending(struct rev_info *);
+void add_reflogs_to_pending(struct rev_info *, unsigned int flags);
+void add_index_objects_to_pending(struct rev_info *, unsigned int flags);
 
 enum commit_action {
        commit_ignore,
@@ -291,10 +292,10 @@ enum commit_action {
        commit_error
 };
 
-extern enum commit_action get_commit_action(struct rev_info *revs,
-                                           struct commit *commit);
-extern enum commit_action simplify_commit(struct rev_info *revs,
-                                         struct commit *commit);
+enum commit_action get_commit_action(struct rev_info *revs,
+                                    struct commit *commit);
+enum commit_action simplify_commit(struct rev_info *revs,
+                                  struct commit *commit);
 
 enum rewrite_result {
        rewrite_one_ok,
@@ -304,8 +305,9 @@ enum rewrite_result {
 
 typedef enum rewrite_result (*rewrite_parent_fn_t)(struct rev_info *revs, struct commit **pp);
 
-extern int rewrite_parents(struct rev_info *revs, struct commit *commit,
-       rewrite_parent_fn_t rewrite_parent);
+int rewrite_parents(struct rev_info *revs,
+                   struct commit *commit,
+                   rewrite_parent_fn_t rewrite_parent);
 
 /*
  * The log machinery saves the original parent list so that
@@ -316,6 +318,6 @@ extern int rewrite_parents(struct rev_info *revs, struct commit *commit,
  * get_saved_parents() will transparently return commit->parents if
  * history simplification is off.
  */
-extern struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit);
+struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit);
 
 #endif
index 19025a7aca82a7066b9a2d40d4d50406a9749a5f..e920ca57df4dd0b65d6694ed2532dead8ae83fb6 100644 (file)
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "commit.h"
 #include "refs.h"
+#include "object-store.h"
 #include "pkt-line.h"
 #include "sideband.h"
 #include "run-command.h"
@@ -75,7 +76,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
                argv_array_push(&po.args, "-q");
        if (args->progress)
                argv_array_push(&po.args, "--progress");
-       if (is_repository_shallow())
+       if (is_repository_shallow(the_repository))
                argv_array_push(&po.args, "--shallow");
        po.in = -1;
        po.out = args->stateless_rpc ? -1 : fd;
@@ -220,7 +221,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
 
 static void advertise_shallow_grafts_buf(struct strbuf *sb)
 {
-       if (!is_repository_shallow())
+       if (!is_repository_shallow(the_repository))
                return;
        for_each_commit_graft(advertise_shallow_grafts_cb, sb);
 }
@@ -537,7 +538,7 @@ int send_pack(struct send_pack_args *args,
        }
 
        if (args->stateless_rpc) {
-               if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
+               if (!args->dry_run && (cmds_sent || is_repository_shallow(the_repository))) {
                        packet_buf_flush(&req_buf);
                        send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
                }
index 5354d4d51e62a31d5254334851bce1b5bb5558a9..c00eedd8568519433462b7d94dd5ef4d46fef96f 100644 (file)
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "lockfile.h"
 #include "dir.h"
+#include "object-store.h"
 #include "object.h"
 #include "commit.h"
 #include "sequencer.h"
@@ -62,12 +63,12 @@ static GIT_PATH_FUNC(rebase_path_done, "rebase-merge/done")
  * The file to keep track of how many commands were already processed (e.g.
  * for the prompt).
  */
-static GIT_PATH_FUNC(rebase_path_msgnum, "rebase-merge/msgnum");
+static GIT_PATH_FUNC(rebase_path_msgnum, "rebase-merge/msgnum")
 /*
  * The file to keep track of how many commands are to be processed in total
  * (e.g. for the prompt).
  */
-static GIT_PATH_FUNC(rebase_path_msgtotal, "rebase-merge/end");
+static GIT_PATH_FUNC(rebase_path_msgtotal, "rebase-merge/end")
 /*
  * The commit message that is planned to be used for any changes that
  * need to be committed following a user interaction.
@@ -306,7 +307,7 @@ static const char *action_name(const struct replay_opts *opts)
        case REPLAY_INTERACTIVE_REBASE:
                return N_("rebase -i");
        }
-       die(_("Unknown action: %d"), opts->action);
+       die(_("unknown action: %d"), opts->action);
 }
 
 struct commit_message {
@@ -357,7 +358,7 @@ static void print_advice(int show_hint, struct replay_opts *opts)
                 * (typically rebase --interactive) wants to take care
                 * of the commit itself so remove CHERRY_PICK_HEAD
                 */
-               unlink(git_path_cherry_pick_head());
+               unlink(git_path_cherry_pick_head(the_repository));
                return;
        }
 
@@ -432,7 +433,7 @@ static int read_oneliner(struct strbuf *buf,
 
 static struct tree *empty_tree(void)
 {
-       return lookup_tree(the_hash_algo->empty_tree);
+       return lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
 }
 
 static int error_dirty_index(struct replay_opts *opts)
@@ -593,7 +594,7 @@ static int is_index_unchanged(void)
        if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
                return error(_("could not resolve HEAD commit"));
 
-       head_commit = lookup_commit(&head_oid);
+       head_commit = lookup_commit(the_repository, &head_oid);
 
        /*
         * If head_commit is NULL, check_commit, called from
@@ -653,6 +654,7 @@ static int write_author_script(const char *message)
                        strbuf_addch(&buf, *(message++));
                else
                        strbuf_addf(&buf, "'\\\\%c'", *(message++));
+       strbuf_addch(&buf, '\'');
        res = write_message(buf.buf, buf.len, rebase_path_author_script(), 1);
        strbuf_release(&buf);
        return res;
@@ -707,43 +709,51 @@ static const char *read_author_ident(struct strbuf *buf)
        const char *keys[] = {
                "GIT_AUTHOR_NAME=", "GIT_AUTHOR_EMAIL=", "GIT_AUTHOR_DATE="
        };
-       char *in, *out, *eol;
-       int i = 0, len;
+       struct strbuf out = STRBUF_INIT;
+       char *in, *eol;
+       const char *val[3];
+       int i = 0;
 
        if (strbuf_read_file(buf, rebase_path_author_script(), 256) <= 0)
                return NULL;
 
        /* dequote values and construct ident line in-place */
-       for (in = out = buf->buf; i < 3 && in - buf->buf < buf->len; i++) {
+       for (in = buf->buf; i < 3 && in - buf->buf < buf->len; i++) {
                if (!skip_prefix(in, keys[i], (const char **)&in)) {
-                       warning("could not parse '%s' (looking for '%s'",
+                       warning(_("could not parse '%s' (looking for '%s'"),
                                rebase_path_author_script(), keys[i]);
                        return NULL;
                }
 
                eol = strchrnul(in, '\n');
                *eol = '\0';
-               sq_dequote(in);
-               len = strlen(in);
-
-               if (i > 0) /* separate values by spaces */
-                       *(out++) = ' ';
-               if (i == 1) /* email needs to be surrounded by <...> */
-                       *(out++) = '<';
-               memmove(out, in, len);
-               out += len;
-               if (i == 1) /* email needs to be surrounded by <...> */
-                       *(out++) = '>';
+               if (!sq_dequote(in)) {
+                       warning(_("bad quoting on %s value in '%s'"),
+                               keys[i], rebase_path_author_script());
+                       return NULL;
+               }
+               val[i] = in;
                in = eol + 1;
        }
 
        if (i < 3) {
-               warning("could not parse '%s' (looking for '%s')",
+               warning(_("could not parse '%s' (looking for '%s')"),
                        rebase_path_author_script(), keys[i]);
                return NULL;
        }
 
-       buf->len = out - buf->buf;
+       /* validate date since fmt_ident() will die() on bad value */
+       if (parse_date(val[2], &out)){
+               warning(_("invalid date format '%s' in '%s'"),
+                       val[2], rebase_path_author_script());
+               strbuf_release(&out);
+               return NULL;
+       }
+
+       strbuf_reset(&out);
+       strbuf_addstr(&out, fmt_ident(val[0], val[1], val[2], 0));
+       strbuf_swap(buf, &out);
+       strbuf_release(&out);
        return buf->buf;
 }
 
@@ -1100,7 +1110,7 @@ void print_commit_summary(const char *prefix, const struct object_id *oid,
        struct strbuf author_ident = STRBUF_INIT;
        struct strbuf committer_ident = STRBUF_INIT;
 
-       commit = lookup_commit(oid);
+       commit = lookup_commit(the_repository, oid);
        if (!commit)
                die(_("couldn't look up newly created commit"));
        if (parse_commit(commit))
@@ -1175,7 +1185,7 @@ static int parse_head(struct commit **head)
        if (get_oid("HEAD", &oid)) {
                current_head = NULL;
        } else {
-               current_head = lookup_commit_reference(&oid);
+               current_head = lookup_commit_reference(the_repository, &oid);
                if (!current_head)
                        return error(_("could not parse HEAD"));
                if (oidcmp(&oid, &current_head->object.oid)) {
@@ -1243,7 +1253,7 @@ static int try_to_commit(struct strbuf *msg, const char *author,
                commit_list_insert(current_head, &parents);
        }
 
-       if (write_cache_as_tree(&tree, 0, NULL)) {
+       if (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL)) {
                res = error(_("git write-tree failed to write a tree"));
                goto out;
        }
@@ -1324,8 +1334,8 @@ static int do_commit(const char *msg_file, const char *author,
                                    &oid);
                strbuf_release(&sb);
                if (!res) {
-                       unlink(git_path_cherry_pick_head());
-                       unlink(git_path_merge_msg());
+                       unlink(git_path_cherry_pick_head(the_repository));
+                       unlink(git_path_merge_msg(the_repository));
                        if (!is_rebase_i(opts))
                                print_commit_summary(NULL, &oid,
                                                SUMMARY_SHOW_AUTHOR_DATE);
@@ -1444,7 +1454,7 @@ static const char *command_to_string(const enum todo_command command)
 {
        if (command < TODO_COMMENT)
                return todo_command_info[command].str;
-       die("Unknown command: %d", command);
+       die(_("unknown command: %d"), command);
 }
 
 static char command_to_char(const enum todo_command command)
@@ -1510,7 +1520,7 @@ static int update_squash_messages(enum todo_command command,
 
                if (get_oid("HEAD", &head))
                        return error(_("need a HEAD to fixup"));
-               if (!(head_commit = lookup_commit_reference(&head)))
+               if (!(head_commit = lookup_commit_reference(the_repository, &head)))
                        return error(_("could not read HEAD"));
                if (!(head_message = get_commit_buffer(head_commit, NULL)))
                        return error(_("could not read HEAD's commit message"));
@@ -1613,7 +1623,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                struct replay_opts *opts, int final_fixup)
 {
        unsigned int flags = opts->edit ? EDIT_MSG : 0;
-       const char *msg_file = opts->edit ? NULL : git_path_merge_msg();
+       const char *msg_file = opts->edit ? NULL : git_path_merge_msg(the_repository);
        struct object_id head;
        struct commit *base, *next, *parent;
        const char *base_label, *next_label;
@@ -1629,7 +1639,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                 * that represents the "current" state for merge-recursive
                 * to work on.
                 */
-               if (write_cache_as_tree(&head, 0, NULL))
+               if (write_index_as_tree(&head, &the_index, get_index_file(), 0, NULL))
                        return error(_("your index file is unmerged."));
        } else {
                unborn = get_oid("HEAD", &head);
@@ -1755,12 +1765,12 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                        flags |= CLEANUP_MSG;
                        msg_file = rebase_path_fixup_msg();
                } else {
-                       const char *dest = git_path_squash_msg();
+                       const char *dest = git_path_squash_msg(the_repository);
                        unlink(dest);
                        if (copy_file(dest, rebase_path_squash_msg(), 0666))
                                return error(_("could not rename '%s' to '%s'"),
                                             rebase_path_squash_msg(), dest);
-                       unlink(git_path_merge_msg());
+                       unlink(git_path_merge_msg(the_repository));
                        msg_file = dest;
                        flags |= EDIT_MSG;
                }
@@ -1778,13 +1788,13 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                        goto leave;
 
                res |= write_message(msgbuf.buf, msgbuf.len,
-                                    git_path_merge_msg(), 0);
+                                    git_path_merge_msg(the_repository), 0);
        } else {
                struct commit_list *common = NULL;
                struct commit_list *remotes = NULL;
 
                res = write_message(msgbuf.buf, msgbuf.len,
-                                   git_path_merge_msg(), 0);
+                                   git_path_merge_msg(the_repository), 0);
 
                commit_list_insert(base, &common);
                commit_list_insert(next, &remotes);
@@ -1863,8 +1873,6 @@ static int prepare_revs(struct replay_opts *opts)
        if (prepare_revision_walk(opts->revs))
                return error(_("revision walk setup failed"));
 
-       if (!opts->revs->commits)
-               return error(_("empty commit set passed"));
        return 0;
 }
 
@@ -2008,7 +2016,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
        if (status < 0)
                return -1;
 
-       item->commit = lookup_commit_reference(&commit_oid);
+       item->commit = lookup_commit_reference(the_repository, &commit_oid);
        return !item->commit;
 }
 
@@ -2206,6 +2214,7 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
 static void read_strategy_opts(struct replay_opts *opts, struct strbuf *buf)
 {
        int i;
+       char *strategy_opts_string;
 
        strbuf_reset(buf);
        if (!read_oneliner(buf, rebase_path_strategy(), 0))
@@ -2214,7 +2223,11 @@ static void read_strategy_opts(struct replay_opts *opts, struct strbuf *buf)
        if (!read_oneliner(buf, rebase_path_strategy_opts(), 0))
                return;
 
-       opts->xopts_nr = split_cmdline(buf->buf, (const char ***)&opts->xopts);
+       strategy_opts_string = buf->buf;
+       if (*strategy_opts_string == ' ')
+               strategy_opts_string++;
+       opts->xopts_nr = split_cmdline(strategy_opts_string,
+                                      (const char ***)&opts->xopts);
        for (i = 0; i < opts->xopts_nr; i++) {
                const char *arg = opts->xopts[i];
 
@@ -2317,6 +2330,10 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
                        short_commit_name(commit), subject_len, subject);
                unuse_commit_buffer(commit, commit_buffer);
        }
+
+       if (!todo_list->nr)
+               return error(_("empty commit set passed"));
+
        return 0;
 }
 
@@ -2394,8 +2411,8 @@ static int rollback_single_pick(void)
 {
        struct object_id head_oid;
 
-       if (!file_exists(git_path_cherry_pick_head()) &&
-           !file_exists(git_path_revert_head()))
+       if (!file_exists(git_path_cherry_pick_head(the_repository)) &&
+           !file_exists(git_path_revert_head(the_repository)))
                return error(_("no cherry-pick or revert in progress"));
        if (read_ref_full("HEAD", 0, &head_oid, NULL))
                return error(_("cannot resolve HEAD"));
@@ -2600,15 +2617,17 @@ static int error_with_patch(struct commit *commit,
                if (intend_to_amend())
                        return -1;
 
-               fprintf(stderr, "You can amend the commit now, with\n"
-                       "\n"
-                       "  git commit --amend %s\n"
-                       "\n"
-                       "Once you are satisfied with your changes, run\n"
-                       "\n"
-                       "  git rebase --continue\n", gpg_sign_opt_quoted(opts));
+               fprintf(stderr,
+                       _("You can amend the commit now, with\n"
+                         "\n"
+                         "  git commit --amend %s\n"
+                         "\n"
+                         "Once you are satisfied with your changes, run\n"
+                         "\n"
+                         "  git rebase --continue\n"),
+                       gpg_sign_opt_quoted(opts));
        } else if (exit_code)
-               fprintf(stderr, "Could not apply %s... %.*s\n",
+               fprintf_ln(stderr, _("Could not apply %s... %.*s"),
                        short_commit_name(commit), subject_len, subject);
 
        return exit_code;
@@ -2620,10 +2639,11 @@ static int error_failed_squash(struct commit *commit,
        if (copy_file(rebase_path_message(), rebase_path_squash_msg(), 0666))
                return error(_("could not copy '%s' to '%s'"),
                        rebase_path_squash_msg(), rebase_path_message());
-       unlink(git_path_merge_msg());
-       if (copy_file(git_path_merge_msg(), rebase_path_message(), 0666))
+       unlink(git_path_merge_msg(the_repository));
+       if (copy_file(git_path_merge_msg(the_repository), rebase_path_message(), 0666))
                return error(_("could not copy '%s' to '%s'"),
-                            rebase_path_message(), git_path_merge_msg());
+                            rebase_path_message(),
+                            git_path_merge_msg(the_repository));
        return error_with_patch(commit, subject, subject_len, opts, 1, 0);
 }
 
@@ -2636,6 +2656,8 @@ static int do_exec(const char *command_line)
        fprintf(stderr, "Executing: %s\n", command_line);
        child_argv[0] = command_line;
        argv_array_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir()));
+       argv_array_pushf(&child_env, "GIT_WORK_TREE=%s",
+                        absolute_path(get_git_work_tree()));
        status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL,
                                          child_env.argv);
 
@@ -2719,7 +2741,7 @@ static int do_label(const char *name, int len)
        struct object_id head_oid;
 
        if (len == 1 && *name == '#')
-               return error("Illegal label name: '%.*s'", len, name);
+               return error(_("illegal label name: '%.*s'"), len, name);
 
        strbuf_addf(&ref_name, "refs/rewritten/%.*s", len, name);
        strbuf_addf(&msg, "rebase -i (label) '%.*s'", len, name);
@@ -2841,6 +2863,26 @@ static int do_reset(const char *name, int len, struct replay_opts *opts)
        return ret;
 }
 
+static struct commit *lookup_label(const char *label, int len,
+                                  struct strbuf *buf)
+{
+       struct commit *commit;
+
+       strbuf_reset(buf);
+       strbuf_addf(buf, "refs/rewritten/%.*s", len, label);
+       commit = lookup_commit_reference_by_name(buf->buf);
+       if (!commit) {
+               /* fall back to non-rewritten ref or commit */
+               strbuf_splice(buf, 0, strlen("refs/rewritten/"), "", 0);
+               commit = lookup_commit_reference_by_name(buf->buf);
+       }
+
+       if (!commit)
+               error(_("could not resolve '%s'"), buf->buf);
+
+       return commit;
+}
+
 static int do_merge(struct commit *commit, const char *arg, int arg_len,
                    int flags, struct replay_opts *opts)
 {
@@ -2849,8 +2891,9 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
        struct strbuf ref_name = STRBUF_INIT;
        struct commit *head_commit, *merge_commit, *i;
        struct commit_list *bases, *j, *reversed = NULL;
+       struct commit_list *to_merge = NULL, **tail = &to_merge;
        struct merge_options o;
-       int merge_arg_len, oneline_offset, can_fast_forward, ret;
+       int merge_arg_len, oneline_offset, can_fast_forward, ret, k;
        static struct lock_file lock;
        const char *p;
 
@@ -2865,26 +2908,34 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
                goto leave_merge;
        }
 
-       oneline_offset = arg_len;
-       merge_arg_len = strcspn(arg, " \t\n");
-       p = arg + merge_arg_len;
-       p += strspn(p, " \t\n");
-       if (*p == '#' && (!p[1] || isspace(p[1]))) {
-               p += 1 + strspn(p + 1, " \t\n");
-               oneline_offset = p - arg;
-       } else if (p - arg < arg_len)
-               BUG("octopus merges are not supported yet: '%s'", p);
-
-       strbuf_addf(&ref_name, "refs/rewritten/%.*s", merge_arg_len, arg);
-       merge_commit = lookup_commit_reference_by_name(ref_name.buf);
-       if (!merge_commit) {
-               /* fall back to non-rewritten ref or commit */
-               strbuf_splice(&ref_name, 0, strlen("refs/rewritten/"), "", 0);
-               merge_commit = lookup_commit_reference_by_name(ref_name.buf);
+       /*
+        * For octopus merges, the arg starts with the list of revisions to be
+        * merged. The list is optionally followed by '#' and the oneline.
+        */
+       merge_arg_len = oneline_offset = arg_len;
+       for (p = arg; p - arg < arg_len; p += strspn(p, " \t\n")) {
+               if (!*p)
+                       break;
+               if (*p == '#' && (!p[1] || isspace(p[1]))) {
+                       p += 1 + strspn(p + 1, " \t\n");
+                       oneline_offset = p - arg;
+                       break;
+               }
+               k = strcspn(p, " \t\n");
+               if (!k)
+                       continue;
+               merge_commit = lookup_label(p, k, &ref_name);
+               if (!merge_commit) {
+                       ret = error(_("unable to parse '%.*s'"), k, p);
+                       goto leave_merge;
+               }
+               tail = &commit_list_insert(merge_commit, tail)->next;
+               p += k;
+               merge_arg_len = p - arg;
        }
 
-       if (!merge_commit) {
-               ret = error(_("could not resolve '%s'"), ref_name.buf);
+       if (!to_merge) {
+               ret = error(_("nothing to merge: '%.*s'"), arg_len, arg);
                goto leave_merge;
        }
 
@@ -2895,8 +2946,13 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
                 * "[new root]", let's simply fast-forward to the merge head.
                 */
                rollback_lock_file(&lock);
-               ret = fast_forward_to(&merge_commit->object.oid,
-                                      &head_commit->object.oid, 0, opts);
+               if (to_merge->next)
+                       ret = error(_("octopus merge cannot be executed on "
+                                     "top of a [new root]"));
+               else
+                       ret = fast_forward_to(&to_merge->item->object.oid,
+                                             &head_commit->object.oid, 0,
+                                             opts);
                goto leave_merge;
        }
 
@@ -2913,11 +2969,11 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
                write_author_script(message);
                find_commit_subject(message, &body);
                len = strlen(body);
-               ret = write_message(body, len, git_path_merge_msg(), 0);
+               ret = write_message(body, len, git_path_merge_msg(the_repository), 0);
                unuse_commit_buffer(commit, message);
                if (ret) {
                        error_errno(_("could not write '%s'"),
-                                   git_path_merge_msg());
+                                   git_path_merge_msg(the_repository));
                        goto leave_merge;
                }
        } else {
@@ -2932,17 +2988,18 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
                        p = arg + oneline_offset;
                        len = arg_len - oneline_offset;
                } else {
-                       strbuf_addf(&buf, "Merge branch '%.*s'",
+                       strbuf_addf(&buf, "Merge %s '%.*s'",
+                                   to_merge->next ? "branches" : "branch",
                                    merge_arg_len, arg);
                        p = buf.buf;
                        len = buf.len;
                }
 
-               ret = write_message(p, len, git_path_merge_msg(), 0);
+               ret = write_message(p, len, git_path_merge_msg(the_repository), 0);
                strbuf_release(&buf);
                if (ret) {
                        error_errno(_("could not write '%s'"),
-                                   git_path_merge_msg());
+                                   git_path_merge_msg(the_repository));
                        goto leave_merge;
                }
        }
@@ -2956,31 +3013,79 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
                        &head_commit->object.oid);
 
        /*
-        * If the merge head is different from the original one, we cannot
+        * If any merge head is different from the original one, we cannot
         * fast-forward.
         */
        if (can_fast_forward) {
-               struct commit_list *second_parent = commit->parents->next;
+               struct commit_list *p = commit->parents->next;
 
-               if (second_parent && !second_parent->next &&
-                   oidcmp(&merge_commit->object.oid,
-                          &second_parent->item->object.oid))
+               for (j = to_merge; j && p; j = j->next, p = p->next)
+                       if (oidcmp(&j->item->object.oid,
+                                  &p->item->object.oid)) {
+                               can_fast_forward = 0;
+                               break;
+                       }
+               /*
+                * If the number of merge heads differs from the original merge
+                * commit, we cannot fast-forward.
+                */
+               if (j || p)
                        can_fast_forward = 0;
        }
 
-       if (can_fast_forward && commit->parents->next &&
-           !commit->parents->next->next &&
-           !oidcmp(&commit->parents->next->item->object.oid,
-                   &merge_commit->object.oid)) {
+       if (can_fast_forward) {
                rollback_lock_file(&lock);
                ret = fast_forward_to(&commit->object.oid,
                                      &head_commit->object.oid, 0, opts);
                goto leave_merge;
        }
 
+       if (to_merge->next) {
+               /* Octopus merge */
+               struct child_process cmd = CHILD_PROCESS_INIT;
+
+               if (read_env_script(&cmd.env_array)) {
+                       const char *gpg_opt = gpg_sign_opt_quoted(opts);
+
+                       ret = error(_(staged_changes_advice), gpg_opt, gpg_opt);
+                       goto leave_merge;
+               }
+
+               cmd.git_cmd = 1;
+               argv_array_push(&cmd.args, "merge");
+               argv_array_push(&cmd.args, "-s");
+               argv_array_push(&cmd.args, "octopus");
+               argv_array_push(&cmd.args, "--no-edit");
+               argv_array_push(&cmd.args, "--no-ff");
+               argv_array_push(&cmd.args, "--no-log");
+               argv_array_push(&cmd.args, "--no-stat");
+               argv_array_push(&cmd.args, "-F");
+               argv_array_push(&cmd.args, git_path_merge_msg(the_repository));
+               if (opts->gpg_sign)
+                       argv_array_push(&cmd.args, opts->gpg_sign);
+
+               /* Add the tips to be merged */
+               for (j = to_merge; j; j = j->next)
+                       argv_array_push(&cmd.args,
+                                       oid_to_hex(&j->item->object.oid));
+
+               strbuf_release(&ref_name);
+               unlink(git_path_cherry_pick_head(the_repository));
+               rollback_lock_file(&lock);
+
+               rollback_lock_file(&lock);
+               ret = run_command(&cmd);
+
+               /* force re-reading of the cache */
+               if (!ret && (discard_cache() < 0 || read_cache() < 0))
+                       ret = error(_("could not read index"));
+               goto leave_merge;
+       }
+
+       merge_commit = to_merge->item;
        write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
-                     git_path_merge_head(), 0);
-       write_message("no-ff", 5, git_path_merge_mode(), 0);
+                     git_path_merge_head(the_repository), 0);
+       write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
 
        bases = get_merge_bases(head_commit, merge_commit);
        if (bases && !oidcmp(&merge_commit->object.oid,
@@ -3034,12 +3139,13 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
                 * value (a negative one would indicate that the `merge`
                 * command needs to be rescheduled).
                 */
-               ret = !!run_git_commit(git_path_merge_msg(), opts,
+               ret = !!run_git_commit(git_path_merge_msg(the_repository), opts,
                                     run_commit_flags);
 
 leave_merge:
        strbuf_release(&ref_name);
        rollback_lock_file(&lock);
+       free_commit_list(to_merge);
        return ret;
 }
 
@@ -3217,10 +3323,27 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                                        intend_to_amend();
                                return error_failed_squash(item->commit, opts,
                                        item->arg_len, item->arg);
-                       } else if (res && is_rebase_i(opts) && item->commit)
+                       } else if (res && is_rebase_i(opts) && item->commit) {
+                               int to_amend = 0;
+                               struct object_id oid;
+
+                               /*
+                                * If we are rewording and have either
+                                * fast-forwarded already, or are about to
+                                * create a new root commit, we want to amend,
+                                * otherwise we do not.
+                                */
+                               if (item->command == TODO_REWORD &&
+                                   !get_oid("HEAD", &oid) &&
+                                   (!oidcmp(&item->commit->object.oid, &oid) ||
+                                    (opts->have_squash_onto &&
+                                     !oidcmp(&opts->squash_onto, &oid))))
+                                       to_amend = 1;
+
                                return res | error_with_patch(item->commit,
-                                       item->arg, item->arg_len, opts, res,
-                                       item->command == TODO_REWORD);
+                                               item->arg, item->arg_len, opts,
+                                               res, to_amend);
+                       }
                } else if (item->command == TODO_EXEC) {
                        char *end_of_arg = (char *)(item->arg + item->arg_len);
                        int saved = *end_of_arg;
@@ -3401,8 +3524,8 @@ static int continue_single_pick(void)
 {
        const char *argv[] = { "commit", NULL };
 
-       if (!file_exists(git_path_cherry_pick_head()) &&
-           !file_exists(git_path_revert_head()))
+       if (!file_exists(git_path_cherry_pick_head(the_repository)) &&
+           !file_exists(git_path_revert_head(the_repository)))
                return error(_("no cherry-pick or revert in progress"));
        return run_command_v_opt(argv, RUN_GIT_CMD);
 }
@@ -3505,7 +3628,7 @@ static int commit_staged_changes(struct replay_opts *opts,
        }
 
        if (is_clean) {
-               const char *cherry_pick_head = git_path_cherry_pick_head();
+               const char *cherry_pick_head = git_path_cherry_pick_head(the_repository);
 
                if (file_exists(cherry_pick_head) && unlink(cherry_pick_head))
                        return error(_("could not remove CHERRY_PICK_HEAD"));
@@ -3555,8 +3678,8 @@ int sequencer_continue(struct replay_opts *opts)
 
        if (!is_rebase_i(opts)) {
                /* Verify that the conflict has been resolved */
-               if (file_exists(git_path_cherry_pick_head()) ||
-                   file_exists(git_path_revert_head())) {
+               if (file_exists(git_path_cherry_pick_head(the_repository)) ||
+                   file_exists(git_path_revert_head(the_repository))) {
                        res = continue_single_pick();
                        if (res)
                                goto release_todo_list;
@@ -3608,7 +3731,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
                        continue;
 
                if (!get_oid(name, &oid)) {
-                       if (!lookup_commit_reference_gently(&oid, 1)) {
+                       if (!lookup_commit_reference_gently(the_repository, &oid, 1)) {
                                enum object_type type = oid_object_info(the_repository,
                                                                        &oid,
                                                                        NULL);
@@ -3634,8 +3757,10 @@ int sequencer_pick_revisions(struct replay_opts *opts)
                if (prepare_revision_walk(opts->revs))
                        return error(_("revision walk setup failed"));
                cmit = get_revision(opts->revs);
-               if (!cmit || get_revision(opts->revs))
-                       return error("BUG: expected exactly one commit from walk");
+               if (!cmit)
+                       return error(_("empty commit set passed"));
+               if (get_revision(opts->revs))
+                       BUG("unexpected extra commit from walk");
                return single_pick(cmit, opts);
        }
 
@@ -3877,7 +4002,6 @@ static int make_script_with_merges(struct pretty_print_context *pp,
         */
        while ((commit = get_revision(revs))) {
                struct commit_list *to_merge;
-               int is_octopus;
                const char *p1, *p2;
                struct object_id *oid;
                int is_empty;
@@ -3909,11 +4033,6 @@ static int make_script_with_merges(struct pretty_print_context *pp,
                        continue;
                }
 
-               is_octopus = to_merge && to_merge->next;
-
-               if (is_octopus)
-                       BUG("Octopus merges not yet supported");
-
                /* Create a label */
                strbuf_reset(&label);
                if (skip_prefix(oneline.buf, "Merge ", &p1) &&
@@ -3935,13 +4054,17 @@ static int make_script_with_merges(struct pretty_print_context *pp,
                strbuf_addf(&buf, "%s -C %s",
                            cmd_merge, oid_to_hex(&commit->object.oid));
 
-               /* label the tip of merged branch */
-               oid = &to_merge->item->object.oid;
-               strbuf_addch(&buf, ' ');
+               /* label the tips of merged branches */
+               for (; to_merge; to_merge = to_merge->next) {
+                       oid = &to_merge->item->object.oid;
+                       strbuf_addch(&buf, ' ');
+
+                       if (!oidset_contains(&interesting, oid)) {
+                               strbuf_addstr(&buf, label_oid(oid, NULL,
+                                                             &state));
+                               continue;
+                       }
 
-               if (!oidset_contains(&interesting, oid))
-                       strbuf_addstr(&buf, label_oid(oid, NULL, &state));
-               else {
                        tips_tail = &commit_list_insert(to_merge->item,
                                                        tips_tail)->next;
 
@@ -3994,7 +4117,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,
                entry = oidmap_get(&state.commit2label, &commit->object.oid);
 
                if (entry)
-                       fprintf(out, "\n# Branch %s\n", entry->string);
+                       fprintf(out, "\n%c Branch %s\n", comment_line_char, entry->string);
                else
                        fprintf(out, "\n");
 
@@ -4132,10 +4255,9 @@ int sequencer_add_exec_commands(const char *commands)
 {
        const char *todo_file = rebase_path_todo();
        struct todo_list todo_list = TODO_LIST_INIT;
-       struct todo_item *item;
        struct strbuf *buf = &todo_list.buf;
        size_t offset = 0, commands_len = strlen(commands);
-       int i, first;
+       int i, insert;
 
        if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
                return error(_("could not read '%s'."), todo_file);
@@ -4145,19 +4267,40 @@ int sequencer_add_exec_commands(const char *commands)
                return error(_("unusable todo list: '%s'"), todo_file);
        }
 
-       first = 1;
-       /* insert <commands> before every pick except the first one */
-       for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) {
-               if (item->command == TODO_PICK && !first) {
-                       strbuf_insert(buf, item->offset_in_buf + offset,
-                                     commands, commands_len);
+       /*
+        * Insert <commands> after every pick. Here, fixup/squash chains
+        * are considered part of the pick, so we insert the commands *after*
+        * those chains if there are any.
+        */
+       insert = -1;
+       for (i = 0; i < todo_list.nr; i++) {
+               enum todo_command command = todo_list.items[i].command;
+
+               if (insert >= 0) {
+                       /* skip fixup/squash chains */
+                       if (command == TODO_COMMENT)
+                               continue;
+                       else if (is_fixup(command)) {
+                               insert = i + 1;
+                               continue;
+                       }
+                       strbuf_insert(buf,
+                                     todo_list.items[insert].offset_in_buf +
+                                     offset, commands, commands_len);
                        offset += commands_len;
+                       insert = -1;
                }
-               first = 0;
+
+               if (command == TODO_PICK || command == TODO_MERGE)
+                       insert = i + 1;
        }
 
-       /* append final <commands> */
-       strbuf_add(buf, commands, commands_len);
+       /* insert or append final <commands> */
+       if (insert >= 0 && insert < todo_list.nr)
+               strbuf_insert(buf, todo_list.items[insert].offset_in_buf +
+                             offset, commands, commands_len);
+       else if (insert >= 0 || !offset)
+               strbuf_add(buf, commands, commands_len);
 
        i = write_message(buf->buf, buf->len, todo_file, 0);
        todo_list_release(&todo_list);
index 7ce6dcd67b7bef92f79bc24c319b2e46150980a3..41050c2449b1adaaeddda30529f9eb1d62981396 100644 (file)
@@ -56,7 +56,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,
                        int flag, void *cb_data)
 {
        FILE *fp = cb_data;
-       struct object *o = parse_object(oid);
+       struct object *o = parse_object(the_repository, oid);
        if (!o)
                return -1;
 
@@ -64,7 +64,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,
                return -1;
 
        if (o->type == OBJ_TAG) {
-               o = deref_tag(o, path, 0);
+               o = deref_tag(the_repository, o, path, 0);
                if (o)
                        if (fprintf(fp, "%s     %s^{}\n",
                                oid_to_hex(&o->oid), path) < 0)
index de4839e634c02cb7497f05a3a4597b9fa5123e32..97b74238483e00c3f07bd5ab0879eb84bf5c8dfa 100644 (file)
@@ -71,17 +71,17 @@ static void git_hash_sha1_final(unsigned char *hash, git_hash_ctx *ctx)
 
 static void git_hash_unknown_init(git_hash_ctx *ctx)
 {
-       die("trying to init unknown hash");
+       BUG("trying to init unknown hash");
 }
 
 static void git_hash_unknown_update(git_hash_ctx *ctx, const void *data, size_t len)
 {
-       die("trying to update unknown hash");
+       BUG("trying to update unknown hash");
 }
 
 static void git_hash_unknown_final(unsigned char *hash, git_hash_ctx *ctx)
 {
-       die("trying to finalize unknown hash");
+       BUG("trying to finalize unknown hash");
 }
 
 const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
@@ -336,7 +336,7 @@ int raceproof_create_file(const char *path, create_file_fn fn, void *cb)
 static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)
 {
        int i;
-       for (i = 0; i < 20; i++) {
+       for (i = 0; i < the_hash_algo->rawsz; i++) {
                static char hex[] = "0123456789abcdef";
                unsigned int val = sha1[i];
                strbuf_addch(buf, hex[val >> 4]);
@@ -378,8 +378,8 @@ static int alt_odb_usable(struct raw_object_store *o,
 
        /* Detect cases where alternate disappeared */
        if (!is_directory(path->buf)) {
-               error("object directory %s does not exist; "
-                     "check .git/objects/info/alternates.",
+               error(_("object directory %s does not exist; "
+                       "check .git/objects/info/alternates"),
                      path->buf);
                return 0;
        }
@@ -429,7 +429,7 @@ static int link_alt_odb_entry(struct repository *r, const char *entry,
        strbuf_addstr(&pathbuf, entry);
 
        if (strbuf_normalize_path(&pathbuf) < 0 && relative_base) {
-               error("unable to normalize alternate object path: %s",
+               error(_("unable to normalize alternate object path: %s"),
                      pathbuf.buf);
                strbuf_release(&pathbuf);
                return -1;
@@ -500,14 +500,14 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
                return;
 
        if (depth > 5) {
-               error("%s: ignoring alternate object stores, nesting too deep.",
+               error(_("%s: ignoring alternate object stores, nesting too deep"),
                                relative_base);
                return;
        }
 
        strbuf_add_absolute_path(&objdirbuf, r->objects->objectdir);
        if (strbuf_normalize_path(&objdirbuf) < 0)
-               die("unable to normalize object directory: %s",
+               die(_("unable to normalize object directory: %s"),
                    objdirbuf.buf);
 
        while (*alt) {
@@ -562,7 +562,7 @@ void add_to_alternates_file(const char *reference)
        hold_lock_file_for_update(&lock, alts, LOCK_DIE_ON_ERROR);
        out = fdopen_lock_file(&lock, "w");
        if (!out)
-               die_errno("unable to fdopen alternates lockfile");
+               die_errno(_("unable to fdopen alternates lockfile"));
 
        in = fopen(alts, "r");
        if (in) {
@@ -580,14 +580,14 @@ void add_to_alternates_file(const char *reference)
                fclose(in);
        }
        else if (errno != ENOENT)
-               die_errno("unable to read alternates file");
+               die_errno(_("unable to read alternates file"));
 
        if (found) {
                rollback_lock_file(&lock);
        } else {
                fprintf_or_die(out, "%s\n", reference);
                if (commit_lock_file(&lock))
-                       die_errno("unable to move new alternates file into place");
+                       die_errno(_("unable to move new alternates file into place"));
                if (the_repository->objects->alt_odb_tail)
                        link_alt_odb_entries(the_repository, reference,
                                             '\n', NULL, 0);
@@ -778,7 +778,7 @@ static void mmap_limit_check(size_t length)
                        limit = SIZE_MAX;
        }
        if (length > limit)
-               die("attempting to mmap %"PRIuMAX" over limit %"PRIuMAX,
+               die(_("attempting to mmap %"PRIuMAX" over limit %"PRIuMAX),
                    (uintmax_t)length, (uintmax_t)limit);
 }
 
@@ -803,7 +803,7 @@ void *xmmap(void *start, size_t length,
 {
        void *ret = xmmap_gently(start, length, prot, flags, fd, offset);
        if (ret == MAP_FAILED)
-               die_errno("mmap failed");
+               die_errno(_("mmap failed"));
        return ret;
 }
 
@@ -970,7 +970,7 @@ static void *map_sha1_file_1(struct repository *r, const char *path,
                        *size = xsize_t(st.st_size);
                        if (!*size) {
                                /* mmap() is forbidden on empty files */
-                               error("object file %s is empty", path);
+                               error(_("object file %s is empty"), path);
                                return NULL;
                        }
                        map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0);
@@ -1090,9 +1090,9 @@ static void *unpack_sha1_rest(git_zstream *stream, void *buffer, unsigned long s
        }
 
        if (status < 0)
-               error("corrupt loose object '%s'", sha1_to_hex(sha1));
+               error(_("corrupt loose object '%s'"), sha1_to_hex(sha1));
        else if (stream->avail_in)
-               error("garbage at end of loose object '%s'",
+               error(_("garbage at end of loose object '%s'"),
                      sha1_to_hex(sha1));
        free(buf);
        return NULL;
@@ -1134,7 +1134,7 @@ static int parse_sha1_header_extended(const char *hdr, struct object_info *oi,
        if ((flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE) && (type < 0))
                type = 0;
        else if (type < 0)
-               die("invalid object type");
+               die(_("invalid object type"));
        if (oi->typep)
                *oi->typep = type;
 
@@ -1216,19 +1216,19 @@ static int sha1_loose_object_info(struct repository *r,
                *oi->disk_sizep = mapsize;
        if ((flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE)) {
                if (unpack_sha1_header_to_strbuf(&stream, map, mapsize, hdr, sizeof(hdr), &hdrbuf) < 0)
-                       status = error("unable to unpack %s header with --allow-unknown-type",
+                       status = error(_("unable to unpack %s header with --allow-unknown-type"),
                                       sha1_to_hex(sha1));
        } else if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
-               status = error("unable to unpack %s header",
+               status = error(_("unable to unpack %s header"),
                               sha1_to_hex(sha1));
        if (status < 0)
                ; /* Do nothing */
        else if (hdrbuf.len) {
                if ((status = parse_sha1_header_extended(hdrbuf.buf, oi, flags)) < 0)
-                       status = error("unable to parse %s header with --allow-unknown-type",
+                       status = error(_("unable to parse %s header with --allow-unknown-type"),
                                       sha1_to_hex(sha1));
        } else if ((status = parse_sha1_header_extended(hdr, oi, flags)) < 0)
-               status = error("unable to parse %s header", sha1_to_hex(sha1));
+               status = error(_("unable to parse %s header"), sha1_to_hex(sha1));
 
        if (status >= 0 && oi->contentp) {
                *oi->contentp = unpack_sha1_rest(&stream, hdr,
@@ -1419,19 +1419,19 @@ void *read_object_file_extended(const struct object_id *oid,
                return data;
 
        if (errno && errno != ENOENT)
-               die_errno("failed to read object %s", oid_to_hex(oid));
+               die_errno(_("failed to read object %s"), oid_to_hex(oid));
 
        /* die if we replaced an object with one that does not exist */
        if (repl != oid)
-               die("replacement %s not found for %s",
+               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))
-               die("loose object %s (stored in %s) is corrupt",
+               die(_("loose object %s (stored in %s) is corrupt"),
                    oid_to_hex(repl), path);
 
        if ((p = has_packed_and_bad(repl->hash)) != NULL)
-               die("packed object %s (stored in %s) is corrupt",
+               die(_("packed object %s (stored in %s) is corrupt"),
                    oid_to_hex(repl), p->pack_name);
 
        return NULL;
@@ -1473,7 +1473,7 @@ void *read_object_with_reference(const struct object_id *oid,
                }
                ref_length = strlen(ref_type);
 
-               if (ref_length + GIT_SHA1_HEXSZ > isize ||
+               if (ref_length + the_hash_algo->hexsz > isize ||
                    memcmp(buffer, ref_type, ref_length) ||
                    get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
                        free(buffer);
@@ -1533,21 +1533,21 @@ int finalize_object_file(const char *tmpfile, const char *filename)
        unlink_or_warn(tmpfile);
        if (ret) {
                if (ret != EEXIST) {
-                       return error_errno("unable to write sha1 filename %s", filename);
+                       return error_errno(_("unable to write sha1 filename %s"), filename);
                }
                /* FIXME!!! Collision check here ? */
        }
 
 out:
        if (adjust_shared_perm(filename))
-               return error("unable to set permission to '%s'", filename);
+               return error(_("unable to set permission to '%s'"), filename);
        return 0;
 }
 
 static int write_buffer(int fd, const void *buf, size_t len)
 {
        if (write_in_full(fd, buf, len) < 0)
-               return error_errno("file write error");
+               return error_errno(_("file write error"));
        return 0;
 }
 
@@ -1566,7 +1566,7 @@ static void close_sha1_file(int fd)
        if (fsync_object_files)
                fsync_or_die(fd, "sha1 file");
        if (close(fd) != 0)
-               die_errno("error when closing sha1 file");
+               die_errno(_("error when closing sha1 file"));
 }
 
 /* Size of directory component, including the ending '/' */
@@ -1632,9 +1632,9 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
        fd = create_tmpfile(&tmp_file, filename.buf);
        if (fd < 0) {
                if (errno == EACCES)
-                       return error("insufficient permission for adding an object to repository database %s", get_object_directory());
+                       return error(_("insufficient permission for adding an object to repository database %s"), get_object_directory());
                else
-                       return error_errno("unable to create temporary file");
+                       return error_errno(_("unable to create temporary file"));
        }
 
        /* Set it up */
@@ -1658,21 +1658,21 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
                ret = git_deflate(&stream, Z_FINISH);
                the_hash_algo->update_fn(&c, in0, stream.next_in - in0);
                if (write_buffer(fd, compressed, stream.next_out - compressed) < 0)
-                       die("unable to write sha1 file");
+                       die(_("unable to write sha1 file"));
                stream.next_out = compressed;
                stream.avail_out = sizeof(compressed);
        } while (ret == Z_OK);
 
        if (ret != Z_STREAM_END)
-               die("unable to deflate new object %s (%d)", oid_to_hex(oid),
+               die(_("unable to deflate new object %s (%d)"), oid_to_hex(oid),
                    ret);
        ret = git_deflate_end_gently(&stream);
        if (ret != Z_OK)
-               die("deflateEnd on object %s failed (%d)", oid_to_hex(oid),
+               die(_("deflateEnd on object %s failed (%d)"), oid_to_hex(oid),
                    ret);
        the_hash_algo->final_fn(parano_oid.hash, &c);
        if (oidcmp(oid, &parano_oid) != 0)
-               die("confused by unstable object source data for %s",
+               die(_("confused by unstable object source data for %s"),
                    oid_to_hex(oid));
 
        close_sha1_file(fd);
@@ -1682,7 +1682,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
                utb.actime = mtime;
                utb.modtime = mtime;
                if (utime(tmp_file.buf, &utb) < 0)
-                       warning_errno("failed utime() on %s", tmp_file.buf);
+                       warning_errno(_("failed utime() on %s"), tmp_file.buf);
        }
 
        return finalize_object_file(tmp_file.buf, filename.buf);
@@ -1757,7 +1757,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
                return 0;
        buf = read_object(oid->hash, &type, &len);
        if (!buf)
-               return error("cannot read sha1_file for %s", oid_to_hex(oid));
+               return error(_("cannot read sha1_file for %s"), oid_to_hex(oid));
        hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
        ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime);
        free(buf);
@@ -1801,16 +1801,16 @@ static void check_commit(const void *buf, size_t size)
 {
        struct commit c;
        memset(&c, 0, sizeof(c));
-       if (parse_commit_buffer(&c, buf, size, 0))
-               die("corrupt commit");
+       if (parse_commit_buffer(the_repository, &c, buf, size, 0))
+               die(_("corrupt commit"));
 }
 
 static void check_tag(const void *buf, size_t size)
 {
        struct tag t;
        memset(&t, 0, sizeof(t));
-       if (parse_tag_buffer(&t, buf, size))
-               die("corrupt tag");
+       if (parse_tag_buffer(the_repository, &t, buf, size))
+               die(_("corrupt tag"));
 }
 
 static int index_mem(struct object_id *oid, void *buf, size_t size,
@@ -1860,7 +1860,7 @@ static int index_stream_convert_blob(struct object_id *oid, int fd,
        struct strbuf sbuf = STRBUF_INIT;
 
        assert(path);
-       assert(would_convert_to_git_filter_fd(path));
+       assert(would_convert_to_git_filter_fd(&the_index, path));
 
        convert_to_git_filter_fd(&the_index, path, fd, &sbuf,
                                 get_conv_flags(flags));
@@ -1903,10 +1903,10 @@ static int index_core(struct object_id *oid, int fd, size_t size,
                char *buf = xmalloc(size);
                ssize_t read_result = read_in_full(fd, buf, size);
                if (read_result < 0)
-                       ret = error_errno("read error while indexing %s",
+                       ret = error_errno(_("read error while indexing %s"),
                                          path ? path : "<unknown>");
                else if (read_result != size)
-                       ret = error("short read while indexing %s",
+                       ret = error(_("short read while indexing %s"),
                                    path ? path : "<unknown>");
                else
                        ret = index_mem(oid, buf, size, type, path, flags);
@@ -1950,7 +1950,7 @@ int index_fd(struct object_id *oid, int fd, struct stat *st,
         * Call xsize_t() only when needed to avoid potentially unnecessary
         * die() for large files.
         */
-       if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(path))
+       if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(&the_index, path))
                ret = index_stream_convert_blob(oid, fd, path, flags);
        else if (!S_ISREG(st->st_mode))
                ret = index_pipe(oid, fd, type, path, flags);
@@ -1977,7 +1977,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
                if (fd < 0)
                        return error_errno("open(\"%s\")", path);
                if (index_fd(oid, fd, st, OBJ_BLOB, path, flags) < 0)
-                       return error("%s: failed to insert into database",
+                       return error(_("%s: failed to insert into database"),
                                     path);
                break;
        case S_IFLNK:
@@ -1986,13 +1986,13 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
                if (!(flags & HASH_WRITE_OBJECT))
                        hash_object_file(sb.buf, sb.len, blob_type, oid);
                else if (write_object_file(sb.buf, sb.len, blob_type, oid))
-                       rc = error("%s: failed to insert into database", path);
+                       rc = error(_("%s: failed to insert into database"), path);
                strbuf_release(&sb);
                break;
        case S_IFDIR:
                return resolve_gitlink_ref(path, "HEAD", oid);
        default:
-               return error("%s: unsupported file type", path);
+               return error(_("%s: unsupported file type"), path);
        }
        return rc;
 }
@@ -2016,9 +2016,9 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
 {
        enum object_type type = oid_object_info(the_repository, oid, NULL);
        if (type < 0)
-               die("%s is not a valid object", oid_to_hex(oid));
+               die(_("%s is not a valid object"), oid_to_hex(oid));
        if (type != expect)
-               die("%s is not a valid '%s' object", oid_to_hex(oid),
+               die(_("%s is not a valid '%s' object"), oid_to_hex(oid),
                    type_name(expect));
 }
 
@@ -2045,7 +2045,7 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
        dir = opendir(path->buf);
        if (!dir) {
                if (errno != ENOENT)
-                       r = error_errno("unable to open %s", path->buf);
+                       r = error_errno(_("unable to open %s"), path->buf);
                strbuf_setlen(path, origlen);
                return r;
        }
@@ -2062,9 +2062,9 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
                namelen = strlen(de->d_name);
                strbuf_setlen(path, baselen);
                strbuf_add(path, de->d_name, namelen);
-               if (namelen == GIT_SHA1_HEXSZ - 2 &&
+               if (namelen == the_hash_algo->hexsz - 2 &&
                    !hex_to_bytes(oid.hash + 1, de->d_name,
-                                 GIT_SHA1_RAWSZ - 1)) {
+                                 the_hash_algo->rawsz - 1)) {
                        if (obj_cb) {
                                r = obj_cb(&oid, path->buf, data);
                                if (r)
@@ -2146,7 +2146,8 @@ static int loose_from_alt_odb(struct alternate_object_database *alt,
        return r;
 }
 
-int for_each_loose_object(each_loose_object_fn cb, void *data, unsigned flags)
+int for_each_loose_object(each_loose_object_fn cb, void *data,
+                         enum for_each_object_flags flags)
 {
        struct loose_alt_odb_data alt;
        int r;
@@ -2202,18 +2203,18 @@ static int check_stream_sha1(git_zstream *stream,
        git_inflate_end(stream);
 
        if (status != Z_STREAM_END) {
-               error("corrupt loose object '%s'", sha1_to_hex(expected_sha1));
+               error(_("corrupt loose object '%s'"), sha1_to_hex(expected_sha1));
                return -1;
        }
        if (stream->avail_in) {
-               error("garbage at end of loose object '%s'",
+               error(_("garbage at end of loose object '%s'"),
                      sha1_to_hex(expected_sha1));
                return -1;
        }
 
        the_hash_algo->final_fn(real_sha1, &c);
        if (hashcmp(expected_sha1, real_sha1)) {
-               error("sha1 mismatch for %s (expected %s)", path,
+               error(_("sha1 mismatch for %s (expected %s)"), path,
                      sha1_to_hex(expected_sha1));
                return -1;
        }
@@ -2237,18 +2238,18 @@ int read_loose_object(const char *path,
 
        map = map_sha1_file_1(the_repository, path, NULL, &mapsize);
        if (!map) {
-               error_errno("unable to mmap %s", path);
+               error_errno(_("unable to mmap %s"), path);
                goto out;
        }
 
        if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0) {
-               error("unable to unpack header of %s", path);
+               error(_("unable to unpack header of %s"), path);
                goto out;
        }
 
        *type = parse_sha1_header(hdr, size);
        if (*type < 0) {
-               error("unable to parse header of %s", path);
+               error(_("unable to parse header of %s"), path);
                git_inflate_end(&stream);
                goto out;
        }
@@ -2259,13 +2260,13 @@ int read_loose_object(const char *path,
        } else {
                *contents = unpack_sha1_rest(&stream, hdr, *size, expected_oid->hash);
                if (!*contents) {
-                       error("unable to unpack contents of %s", path);
+                       error(_("unable to unpack contents of %s"), path);
                        git_inflate_end(&stream);
                        goto out;
                }
                if (check_object_signature(expected_oid, *contents,
                                         *size, type_name(*type))) {
-                       error("sha1 mismatch for %s (expected %s)", path,
+                       error(_("sha1 mismatch for %s (expected %s)"), path,
                              oid_to_hex(expected_oid));
                        free(*contents);
                        goto out;
index 60d9ef3c7e7108c859647656972c171cce4e7d7f..c9cc1318b7394e86704bda95651c9a4db3015b9a 100644 (file)
@@ -239,7 +239,8 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
                return 0;
 
        /* We need to do this the hard way... */
-       obj = deref_tag(parse_object(oid), NULL, 0);
+       obj = deref_tag(the_repository, parse_object(the_repository, oid),
+                       NULL, 0);
        if (obj && obj->type == OBJ_COMMIT)
                return 1;
        return 0;
@@ -263,7 +264,8 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
                return 0;
 
        /* We need to do this the hard way... */
-       obj = deref_tag(parse_object(oid), NULL, 0);
+       obj = deref_tag(the_repository, parse_object(the_repository, oid),
+                       NULL, 0);
        if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
                return 1;
        return 0;
@@ -310,7 +312,7 @@ static int init_object_disambiguation(const char *name, int len,
 {
        int i;
 
-       if (len < MINIMUM_ABBREV || len > GIT_SHA1_HEXSZ)
+       if (len < MINIMUM_ABBREV || len > the_hash_algo->hexsz)
                return -1;
 
        memset(ds, 0, sizeof(*ds));
@@ -351,14 +353,14 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
 
        type = oid_object_info(the_repository, oid, NULL);
        if (type == OBJ_COMMIT) {
-               struct commit *commit = lookup_commit(oid);
+               struct commit *commit = lookup_commit(the_repository, oid);
                if (commit) {
                        struct pretty_print_context pp = {0};
                        pp.date_mode.type = DATE_SHORT;
                        format_commit_message(commit, " %ad - %s", &desc, &pp);
                }
        } else if (type == OBJ_TAG) {
-               struct tag *tag = lookup_tag(oid);
+               struct tag *tag = lookup_tag(the_repository, oid);
                if (!parse_tag(tag) && tag->tag)
                        strbuf_addf(&desc, " %s", tag->tag);
        }
@@ -576,6 +578,8 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
        struct disambiguate_state ds;
        struct min_abbrev_data mad;
        struct object_id oid_ret;
+       const unsigned hexsz = the_hash_algo->hexsz;
+
        if (len < 0) {
                unsigned long count = approximate_object_count();
                /*
@@ -599,8 +603,8 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
        }
 
        oid_to_hex_r(hex, oid);
-       if (len == GIT_SHA1_HEXSZ || !len)
-               return GIT_SHA1_HEXSZ;
+       if (len == hexsz || !len)
+               return hexsz;
 
        mad.init_len = len;
        mad.cur_len = len;
@@ -706,7 +710,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
        int refs_found = 0;
        int at, reflog_len, nth_prior = 0;
 
-       if (len == GIT_SHA1_HEXSZ && !get_oid_hex(str, oid)) {
+       if (len == the_hash_algo->hexsz && !get_oid_hex(str, oid)) {
                if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
                        refs_found = dwim_ref(str, len, &tmp_oid, &real_ref);
                        if (refs_found > 0) {
@@ -750,7 +754,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
                int detached;
 
                if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
-                       detached = (buf.len == GIT_SHA1_HEXSZ && !get_oid_hex(buf.buf, oid));
+                       detached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
                        strbuf_release(&buf);
                        if (detached)
                                return 0;
@@ -844,7 +848,7 @@ static int get_parent(const char *name, int len,
 
        if (ret)
                return ret;
-       commit = lookup_commit_reference(&oid);
+       commit = lookup_commit_reference(the_repository, &oid);
        if (parse_commit(commit))
                return -1;
        if (!idx) {
@@ -872,7 +876,7 @@ static int get_nth_ancestor(const char *name, int len,
        ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
        if (ret)
                return ret;
-       commit = lookup_commit_reference(&oid);
+       commit = lookup_commit_reference(the_repository, &oid);
        if (!commit)
                return -1;
 
@@ -891,7 +895,7 @@ struct object *peel_to_type(const char *name, int namelen,
        if (name && !namelen)
                namelen = strlen(name);
        while (1) {
-               if (!o || (!o->parsed && !parse_object(&o->oid)))
+               if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
                        return NULL;
                if (expected_type == OBJ_ANY || o->type == expected_type)
                        return o;
@@ -964,12 +968,12 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
        if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
                return -1;
 
-       o = parse_object(&outer);
+       o = parse_object(the_repository, &outer);
        if (!o)
                return -1;
        if (!expected_type) {
-               o = deref_tag(o, name, sp - name - 2);
-               if (!o || (!o->parsed && !parse_object(&o->oid)))
+               o = deref_tag(the_repository, o, name, sp - name - 2);
+               if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
                        return -1;
                oidcpy(oid, &o->oid);
                return 0;
@@ -1096,11 +1100,12 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
                          int flag, void *cb_data)
 {
        struct commit_list **list = cb_data;
-       struct object *object = parse_object(oid);
+       struct object *object = parse_object(the_repository, oid);
        if (!object)
                return 0;
        if (object->type == OBJ_TAG) {
-               object = deref_tag(object, path, strlen(path));
+               object = deref_tag(the_repository, object, path,
+                                  strlen(path));
                if (!object)
                        return 0;
        }
@@ -1142,7 +1147,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,
                int matches;
 
                commit = pop_most_recent_commit(&list, ONELINE_SEEN);
-               if (!parse_object(&commit->object.oid))
+               if (!parse_object(the_repository, &commit->object.oid))
                        continue;
                buf = get_commit_buffer(commit, NULL);
                p = strstr(buf, "\n\n");
@@ -1251,13 +1256,13 @@ int get_oid_mb(const char *name, struct object_id *oid)
        }
        if (st)
                return st;
-       one = lookup_commit_reference_gently(&oid_tmp, 0);
+       one = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
        if (!one)
                return -1;
 
        if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
                return -1;
-       two = lookup_commit_reference_gently(&oid_tmp, 0);
+       two = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
        if (!two)
                return -1;
        mbs = get_merge_bases(one, two);
@@ -1650,6 +1655,7 @@ static int get_oid_with_context_1(const char *name,
                        struct commit_list *list = NULL;
 
                        for_each_ref(handle_one_ref, &list);
+                       head_ref(handle_one_ref, &list);
                        commit_list_sort_by_date(&list);
                        return get_oid_oneline(name + 2, oid, list);
                }
index 19d97bf5af05312267c2e874ee6bcf584d9e9681..232357eb2ea0397388254a4b188333a227bf5b10 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 19d97bf5af05312267c2e874ee6bcf584d9e9681
+Subproject commit 232357eb2ea0397388254a4b188333a227bf5b10
index 25eded1399a8c3ae1532074ccdd388b24e660071..df0630bc6d607749f80955bc9ffaa5b0bbc506a5 100644 (file)
 #define SHA1DC_BIGENDIAN
 
 /* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist> */
+#elif (defined(_AIX))
+
+/*
+ * Defines Big Endian on a whitelist of OSs that are known to be Big
+ * Endian-only. See
+ * https://public-inbox.org/git/93056823-2740-d072-1ebd-46b440b33d7e@felt.demon.nl/
+ */
+#define SHA1DC_BIGENDIAN
+
+/* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist> or <os whitelist> */
 #elif defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR)
 /*
  * As a last resort before we do anything else we're not 100% sure
  * about below, we blacklist specific processors here. We could add
  * more, see e.g. https://wiki.debian.org/ArchitectureSpecificsMemo
  */
-#else /* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist>  or <processor blacklist> */
+#else /* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist> or <os whitelist> or <processor blacklist> */
 
 /* We do nothing more here for now */
 /*#error "Uncomment this to see if you fall through all the detection"*/
index 79439a818f52d5c783fbf003a7b9fa90bb0d1993..dbe8a2a2906abf9b393eeca1cdad8c9425c3e4bb 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -1,6 +1,8 @@
 #include "cache.h"
+#include "repository.h"
 #include "tempfile.h"
 #include "lockfile.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tag.h"
 #include "pkt-line.h"
 #include "revision.h"
 #include "list-objects.h"
 #include "commit-slab.h"
+#include "repository.h"
 
-static int is_shallow = -1;
-static struct stat_validity shallow_stat;
-static char *alternate_shallow_file;
-
-void set_alternate_shallow_file(const char *path, int override)
+void set_alternate_shallow_file(struct repository *r, const char *path, int override)
 {
-       if (is_shallow != -1)
+       if (r->parsed_objects->is_shallow != -1)
                BUG("is_repository_shallow must not be called before set_alternate_shallow_file");
-       if (alternate_shallow_file && !override)
+       if (r->parsed_objects->alternate_shallow_file && !override)
                return;
-       free(alternate_shallow_file);
-       alternate_shallow_file = xstrdup_or_null(path);
+       free(r->parsed_objects->alternate_shallow_file);
+       r->parsed_objects->alternate_shallow_file = xstrdup_or_null(path);
 }
 
-int register_shallow(const struct object_id *oid)
+int register_shallow(struct repository *r, const struct object_id *oid)
 {
        struct commit_graft *graft =
                xmalloc(sizeof(struct commit_graft));
-       struct commit *commit = lookup_commit(oid);
+       struct commit *commit = lookup_commit(the_repository, oid);
 
        oidcpy(&graft->oid, oid);
        graft->nr_parent = -1;
        if (commit && commit->object.parsed)
                commit->parents = NULL;
-       return register_commit_graft(graft, 0);
+       return register_commit_graft(r, graft, 0);
 }
 
-int is_repository_shallow(void)
+int is_repository_shallow(struct repository *r)
 {
        FILE *fp;
        char buf[1024];
-       const char *path = alternate_shallow_file;
+       const char *path = r->parsed_objects->alternate_shallow_file;
 
-       if (is_shallow >= 0)
-               return is_shallow;
+       if (r->parsed_objects->is_shallow >= 0)
+               return r->parsed_objects->is_shallow;
 
        if (!path)
-               path = git_path_shallow();
+               path = git_path_shallow(r);
        /*
         * fetch-pack sets '--shallow-file ""' as an indicator that no
         * shallow file should be used. We could just open it and it
         * will likely fail. But let's do an explicit check instead.
         */
        if (!*path || (fp = fopen(path, "r")) == NULL) {
-               stat_validity_clear(&shallow_stat);
-               is_shallow = 0;
-               return is_shallow;
+               stat_validity_clear(r->parsed_objects->shallow_stat);
+               r->parsed_objects->is_shallow = 0;
+               return r->parsed_objects->is_shallow;
        }
-       stat_validity_update(&shallow_stat, fileno(fp));
-       is_shallow = 1;
+       stat_validity_update(r->parsed_objects->shallow_stat, fileno(fp));
+       r->parsed_objects->is_shallow = 1;
 
        while (fgets(buf, sizeof(buf), fp)) {
                struct object_id oid;
                if (get_oid_hex(buf, &oid))
                        die("bad shallow line: %s", buf);
-               register_shallow(&oid);
+               register_shallow(r, &oid);
        }
        fclose(fp);
-       return is_shallow;
+       return r->parsed_objects->is_shallow;
 }
 
 /*
@@ -97,7 +96,9 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
                        if (i < heads->nr) {
                                int **depth_slot;
                                commit = (struct commit *)
-                                       deref_tag(heads->objects[i++].item, NULL, 0);
+                                       deref_tag(the_repository,
+                                                 heads->objects[i++].item,
+                                                 NULL, 0);
                                if (!commit || commit->object.type != OBJ_COMMIT) {
                                        commit = NULL;
                                        continue;
@@ -116,8 +117,8 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
                parse_commit_or_die(commit);
                cur_depth++;
                if ((depth != INFINITE_DEPTH && cur_depth >= depth) ||
-                   (is_repository_shallow() && !commit->parents &&
-                    (graft = lookup_commit_graft(&commit->object.oid)) != NULL &&
+                   (is_repository_shallow(the_repository) && !commit->parents &&
+                    (graft = lookup_commit_graft(the_repository, &commit->object.oid)) != NULL &&
                     graft->nr_parent < 0)) {
                        commit_list_insert(commit, &result);
                        commit->object.flags |= shallow_flag;
@@ -181,7 +182,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
         */
        clear_object_flags(both_flags);
 
-       is_repository_shallow(); /* make sure shallows are read */
+       is_repository_shallow(the_repository); /* make sure shallows are read */
 
        init_revisions(&revs, NULL);
        save_commit_buffer = 0;
@@ -234,12 +235,12 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
        return result;
 }
 
-static void check_shallow_file_for_update(void)
+static void check_shallow_file_for_update(struct repository *r)
 {
-       if (is_shallow == -1)
+       if (r->parsed_objects->is_shallow == -1)
                BUG("shallow must be initialized by now");
 
-       if (!stat_validity_check(&shallow_stat, git_path_shallow()))
+       if (!stat_validity_check(r->parsed_objects->shallow_stat, git_path_shallow(the_repository)))
                die("shallow file has changed since we read it");
 }
 
@@ -260,7 +261,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
        if (graft->nr_parent != -1)
                return 0;
        if (data->flags & SEEN_ONLY) {
-               struct commit *c = lookup_commit(&graft->oid);
+               struct commit *c = lookup_commit(the_repository, &graft->oid);
                if (!c || !(c->object.flags & SEEN)) {
                        if (data->flags & VERBOSE)
                                printf("Removing %s from .git/shallow\n",
@@ -334,9 +335,10 @@ void setup_alternate_shallow(struct lock_file *shallow_lock,
        struct strbuf sb = STRBUF_INIT;
        int fd;
 
-       fd = hold_lock_file_for_update(shallow_lock, git_path_shallow(),
+       fd = hold_lock_file_for_update(shallow_lock,
+                                      git_path_shallow(the_repository),
                                       LOCK_DIE_ON_ERROR);
-       check_shallow_file_for_update();
+       check_shallow_file_for_update(the_repository);
        if (write_shallow_commits(&sb, 0, extra)) {
                if (write_in_full(fd, sb.buf, sb.len) < 0)
                        die_errno("failed to write to %s",
@@ -361,7 +363,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
 
 void advertise_shallow_grafts(int fd)
 {
-       if (!is_repository_shallow())
+       if (!is_repository_shallow(the_repository))
                return;
        for_each_commit_graft(advertise_shallow_grafts_cb, &fd);
 }
@@ -381,16 +383,17 @@ void prune_shallow(int show_only)
                strbuf_release(&sb);
                return;
        }
-       fd = hold_lock_file_for_update(&shallow_lock, git_path_shallow(),
+       fd = hold_lock_file_for_update(&shallow_lock,
+                                      git_path_shallow(the_repository),
                                       LOCK_DIE_ON_ERROR);
-       check_shallow_file_for_update();
+       check_shallow_file_for_update(the_repository);
        if (write_shallow_commits_1(&sb, 0, NULL, SEEN_ONLY)) {
                if (write_in_full(fd, sb.buf, sb.len) < 0)
                        die_errno("failed to write to %s",
                                  get_lock_file_path(&shallow_lock));
                commit_lock_file(&shallow_lock);
        } else {
-               unlink(git_path_shallow());
+               unlink(git_path_shallow(the_repository));
                rollback_lock_file(&shallow_lock);
        }
        strbuf_release(&sb);
@@ -415,7 +418,8 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
        for (i = 0; i < sa->nr; i++) {
                if (has_object_file(sa->oid + i)) {
                        struct commit_graft *graft;
-                       graft = lookup_commit_graft(&sa->oid[i]);
+                       graft = lookup_commit_graft(the_repository,
+                                                   &sa->oid[i]);
                        if (graft && graft->nr_parent < 0)
                                continue;
                        info->ours[info->nr_ours++] = i;
@@ -490,7 +494,8 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
        struct commit_list *head = NULL;
        int bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32);
        size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
-       struct commit *c = lookup_commit_reference_gently(oid, 1);
+       struct commit *c = lookup_commit_reference_gently(the_repository, oid,
+                                                         1);
        uint32_t *tmp; /* to be freed before return */
        uint32_t *bitmap;
 
@@ -552,7 +557,8 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
 static int mark_uninteresting(const char *refname, const struct object_id *oid,
                              int flags, void *cb_data)
 {
-       struct commit *commit = lookup_commit_reference_gently(oid, 1);
+       struct commit *commit = lookup_commit_reference_gently(the_repository,
+                                                              oid, 1);
        if (!commit)
                return 0;
        commit->object.flags |= UNINTERESTING;
@@ -620,7 +626,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
 
        /* Mark potential bottoms so we won't go out of bound */
        for (i = 0; i < nr_shallow; i++) {
-               struct commit *c = lookup_commit(&oid[shallow[i]]);
+               struct commit *c = lookup_commit(the_repository,
+                                                &oid[shallow[i]]);
                c->object.flags |= BOTTOM;
        }
 
@@ -631,7 +638,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
                int bitmap_size = DIV_ROUND_UP(pi.nr_bits, 32) * sizeof(uint32_t);
                memset(used, 0, sizeof(*used) * info->shallow->nr);
                for (i = 0; i < nr_shallow; i++) {
-                       const struct commit *c = lookup_commit(&oid[shallow[i]]);
+                       const struct commit *c = lookup_commit(the_repository,
+                                                              &oid[shallow[i]]);
                        uint32_t **map = ref_bitmap_at(&pi.ref_bitmap, c);
                        if (*map)
                                used[shallow[i]] = xmemdupz(*map, bitmap_size);
@@ -662,7 +670,8 @@ static int add_ref(const char *refname, const struct object_id *oid,
 {
        struct commit_array *ca = cb_data;
        ALLOC_GROW(ca->commits, ca->nr + 1, ca->alloc);
-       ca->commits[ca->nr] = lookup_commit_reference_gently(oid, 1);
+       ca->commits[ca->nr] = lookup_commit_reference_gently(the_repository,
+                                                            oid, 1);
        if (ca->commits[ca->nr])
                ca->nr++;
        return 0;
@@ -700,7 +709,7 @@ static void post_assign_shallow(struct shallow_info *info,
        for (i = dst = 0; i < info->nr_theirs; i++) {
                if (i != dst)
                        info->theirs[dst] = info->theirs[i];
-               c = lookup_commit(&oid[info->theirs[i]]);
+               c = lookup_commit(the_repository, &oid[info->theirs[i]]);
                bitmap = ref_bitmap_at(ref_bitmap, c);
                if (!*bitmap)
                        continue;
@@ -721,7 +730,7 @@ static void post_assign_shallow(struct shallow_info *info,
        for (i = dst = 0; i < info->nr_ours; i++) {
                if (i != dst)
                        info->ours[dst] = info->ours[i];
-               c = lookup_commit(&oid[info->ours[i]]);
+               c = lookup_commit(the_repository, &oid[info->ours[i]]);
                bitmap = ref_bitmap_at(ref_bitmap, c);
                if (!*bitmap)
                        continue;
@@ -743,7 +752,8 @@ static void post_assign_shallow(struct shallow_info *info,
 int delayed_reachability_test(struct shallow_info *si, int c)
 {
        if (si->need_reachability_test[c]) {
-               struct commit *commit = lookup_commit(&si->shallow->oid[c]);
+               struct commit *commit = lookup_commit(the_repository,
+                                                     &si->shallow->oid[c]);
 
                if (!si->commits) {
                        struct commit_array ca;
index 660c75f31fb970af06af3aad48b4ecc57e8cc136..84f067e10d2cec1d77ec1a51f0f38cc5a29dd89f 100644 (file)
@@ -73,16 +73,31 @@ void move_cache_to_base_index(struct index_state *istate)
        int i;
 
        /*
-        * do not delete old si->base, its index entries may be shared
-        * with istate->cache[]. Accept a bit of leaking here because
-        * this code is only used by short-lived update-index.
+        * If there was a previous base index, then transfer ownership of allocated
+        * entries to the parent index.
         */
+       if (si->base &&
+               si->base->ce_mem_pool) {
+
+               if (!istate->ce_mem_pool)
+                       mem_pool_init(&istate->ce_mem_pool, 0);
+
+               mem_pool_combine(istate->ce_mem_pool, istate->split_index->base->ce_mem_pool);
+       }
+
        si->base = xcalloc(1, sizeof(*si->base));
        si->base->version = istate->version;
        /* zero timestamp disables racy test in ce_write_index() */
        si->base->timestamp = istate->timestamp;
        ALLOC_GROW(si->base->cache, istate->cache_nr, si->base->cache_alloc);
        si->base->cache_nr = istate->cache_nr;
+
+       /*
+        * The mem_pool needs to move with the allocated entries.
+        */
+       si->base->ce_mem_pool = istate->ce_mem_pool;
+       istate->ce_mem_pool = NULL;
+
        COPY_ARRAY(si->base->cache, istate->cache, istate->cache_nr);
        mark_base_index_entries(si->base);
        for (i = 0; i < si->base->cache_nr; i++)
@@ -123,7 +138,7 @@ static void replace_entry(size_t pos, void *data)
        src->ce_flags |= CE_UPDATE_IN_BASE;
        src->ce_namelen = dst->ce_namelen;
        copy_cache_entry(dst, src);
-       free(src);
+       discard_cache_entry(src);
        si->nr_replacements++;
 }
 
@@ -224,7 +239,7 @@ void prepare_to_write_split_index(struct index_state *istate)
                        base->ce_flags = base_flags;
                        if (ret)
                                ce->ce_flags |= CE_UPDATE_IN_BASE;
-                       free(base);
+                       discard_cache_entry(base);
                        si->base->cache[ce->index - 1] = ce;
                }
                for (i = 0; i < si->base->cache_nr; i++) {
@@ -301,7 +316,7 @@ void save_or_free_index_entry(struct index_state *istate, struct cache_entry *ce
            ce == istate->split_index->base->cache[ce->index - 1])
                ce->ce_flags |= CE_REMOVE;
        else
-               free(ce);
+               discard_cache_entry(ce);
 }
 
 void replace_index_entry_in_base(struct index_state *istate,
@@ -314,7 +329,7 @@ void replace_index_entry_in_base(struct index_state *istate,
            old_entry->index <= istate->split_index->base->cache_nr) {
                new_entry->index = old_entry->index;
                if (old_entry != istate->split_index->base->cache[new_entry->index - 1])
-                       free(istate->split_index->base->cache[new_entry->index - 1]);
+                       discard_cache_entry(istate->split_index->base->cache[new_entry->index - 1]);
                istate->split_index->base->cache[new_entry->index - 1] = new_entry;
        }
 }
@@ -331,12 +346,31 @@ void remove_split_index(struct index_state *istate)
 {
        if (istate->split_index) {
                /*
-                * can't discard_split_index(&the_index); because that
-                * will destroy split_index->base->cache[], which may
-                * be shared with the_index.cache[]. So yeah we're
-                * leaking a bit here.
+                * When removing the split index, we need to move
+                * ownership of the mem_pool associated with the
+                * base index to the main index. There may be cache entries
+                * allocated from the base's memory pool that are shared with
+                * the_index.cache[].
                 */
-               istate->split_index = NULL;
+               mem_pool_combine(istate->ce_mem_pool, istate->split_index->base->ce_mem_pool);
+
+               /*
+                * The split index no longer owns the mem_pool backing
+                * its cache array. As we are discarding this index,
+                * mark the index as having no cache entries, so it
+                * will not attempt to clean up the cache entries or
+                * validate them.
+                */
+               if (istate->split_index->base)
+                       istate->split_index->base->cache_nr = 0;
+
+               /*
+                * We can discard the split index because its
+                * memory pool has been incorporated into the
+                * memory pool associated with the the_index.
+                */
+               discard_split_index(istate);
+
                istate->cache_changed |= SOMETHING_CHANGED;
        }
 }
index b0716ac585285a971c04952254c34a00aab9f0ef..64041c3c249b158478ecc6db7257519bc3fc5c19 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -134,7 +134,7 @@ void strbuf_ltrim(struct strbuf *sb)
 int strbuf_reencode(struct strbuf *sb, const char *from, const char *to)
 {
        char *out;
-       int len;
+       size_t len;
 
        if (same_encoding(from, to))
                return 0;
@@ -209,7 +209,7 @@ void strbuf_list_free(struct strbuf **sbs)
 
 int strbuf_cmp(const struct strbuf *a, const struct strbuf *b)
 {
-       int len = a->len < b->len ? a->len: b->len;
+       size_t len = a->len < b->len ? a->len: b->len;
        int cmp = memcmp(a->buf, b->buf, len);
        if (cmp)
                return cmp;
@@ -389,7 +389,7 @@ size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder,
 
 void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src)
 {
-       int i, len = src->len;
+       size_t i, len = src->len;
 
        for (i = 0; i < len; i++) {
                if (src->buf[i] == '%')
@@ -469,7 +469,7 @@ int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint)
                hint = 32;
 
        while (hint < STRBUF_MAXLINK) {
-               int len;
+               ssize_t len;
 
                strbuf_grow(sb, hint);
                len = readlink(path, sb->buf, hint);
@@ -734,18 +734,18 @@ void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)
 {
        if (bytes > 1 << 30) {
                strbuf_addf(buf, "%u.%2.2u GiB",
-                           (int)(bytes >> 30),
-                           (int)(bytes & ((1 << 30) - 1)) / 10737419);
+                           (unsigned)(bytes >> 30),
+                           (unsigned)(bytes & ((1 << 30) - 1)) / 10737419);
        } else if (bytes > 1 << 20) {
-               int x = bytes + 5243;  /* for rounding */
+               unsigned x = bytes + 5243;  /* for rounding */
                strbuf_addf(buf, "%u.%2.2u MiB",
                            x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
        } else if (bytes > 1 << 10) {
-               int x = bytes + 5;  /* for rounding */
+               unsigned x = bytes + 5;  /* for rounding */
                strbuf_addf(buf, "%u.%2.2u KiB",
                            x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
        } else {
-               strbuf_addf(buf, "%u bytes", (int)bytes);
+               strbuf_addf(buf, "%u bytes", (unsigned)bytes);
        }
 }
 
@@ -921,7 +921,7 @@ void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
                              int abbrev_len)
 {
        int r;
-       strbuf_grow(sb, GIT_SHA1_HEXSZ + 1);
+       strbuf_grow(sb, GIT_MAX_HEXSZ + 1);
        r = find_unique_abbrev_r(sb->buf + sb->len, oid, abbrev_len);
        strbuf_setlen(sb, sb->len + r);
 }
@@ -960,7 +960,7 @@ static size_t cleanup(char *line, size_t len)
  */
 void strbuf_stripspace(struct strbuf *sb, int skip_comments)
 {
-       int empties = 0;
+       size_t empties = 0;
        size_t i, j, len, newlen;
        char *eol;
 
index a0cf0cfe88ee38f35ec33662778ec1bd7036a127..771c4550980e24eb8bf9db14e27c49f983c1ed4b 100644 (file)
@@ -224,18 +224,28 @@ struct string_list_item *string_list_append(struct string_list *list,
                        list->strdup_strings ? xstrdup(string) : (char *)string);
 }
 
+/*
+ * Encapsulate the compare function pointer because ISO C99 forbids
+ * casting from void * to a function pointer and vice versa.
+ */
+struct string_list_sort_ctx
+{
+       compare_strings_fn cmp;
+};
+
 static int cmp_items(const void *a, const void *b, void *ctx)
 {
-       compare_strings_fn cmp = ctx;
+       struct string_list_sort_ctx *sort_ctx = ctx;
        const struct string_list_item *one = a;
        const struct string_list_item *two = b;
-       return cmp(one->string, two->string);
+       return sort_ctx->cmp(one->string, two->string);
 }
 
 void string_list_sort(struct string_list *list)
 {
-       QSORT_S(list->items, list->nr, cmp_items,
-               list->cmp ? list->cmp : strcmp);
+       struct string_list_sort_ctx sort_ctx = {list->cmp ? list->cmp : strcmp};
+
+       QSORT_S(list->items, list->nr, cmp_items, &sort_ctx);
 }
 
 struct string_list_item *unsorted_string_list_lookup(struct string_list *list,
index 388ef1f892bdd63a485d9c93810a945fc3eab46f..fc2c41b947cb471deef42323c83f8b28f42780d6 100644 (file)
@@ -4,6 +4,7 @@
 #include "submodule-config.h"
 #include "submodule.h"
 #include "strbuf.h"
+#include "object-store.h"
 #include "parse-options.h"
 
 /*
@@ -561,7 +562,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
        parameter.gitmodules_oid = &oid;
        parameter.overwrite = 0;
        git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf,
-                       config, config_size, &parameter);
+                       config, config_size, &parameter, NULL);
        strbuf_release(&rev);
        free(config);
 
@@ -591,6 +592,23 @@ static void submodule_cache_check_init(struct repository *repo)
        submodule_cache_init(repo->submodule_cache);
 }
 
+/*
+ * Note: This function is private for a reason, the '.gitmodules' file should
+ * not be used as as a mechanism to retrieve arbitrary configuration stored in
+ * the repository.
+ *
+ * Runs the provided config function on the '.gitmodules' file found in the
+ * working directory.
+ */
+static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void *data)
+{
+       if (repo->worktree) {
+               char *file = repo_worktree_path(repo, GITMODULES_FILE);
+               git_config_from_file(fn, file, data);
+               free(file);
+       }
+}
+
 static int gitmodules_cb(const char *var, const char *value, void *data)
 {
        struct repository *repo = data;
@@ -608,19 +626,11 @@ void repo_read_gitmodules(struct repository *repo)
 {
        submodule_cache_check_init(repo);
 
-       if (repo->worktree) {
-               char *gitmodules;
-
-               if (repo_read_index(repo) < 0)
-                       return;
-
-               gitmodules = repo_worktree_path(repo, GITMODULES_FILE);
-
-               if (!is_gitmodules_unmerged(repo->index))
-                       git_config_from_file(gitmodules_cb, gitmodules, repo);
+       if (repo_read_index(repo) < 0)
+               return;
 
-               free(gitmodules);
-       }
+       if (!is_gitmodules_unmerged(repo->index))
+               config_from_gitmodules(gitmodules_cb, repo, repo);
 
        repo->submodule_cache->gitmodules_read = 1;
 }
@@ -671,3 +681,45 @@ void submodule_free(struct repository *r)
        if (r->submodule_cache)
                submodule_cache_clear(r->submodule_cache);
 }
+
+struct fetch_config {
+       int *max_children;
+       int *recurse_submodules;
+};
+
+static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
+{
+       struct fetch_config *config = cb;
+       if (!strcmp(var, "submodule.fetchjobs")) {
+               *(config->max_children) = parse_submodule_fetchjobs(var, value);
+               return 0;
+       } else if (!strcmp(var, "fetch.recursesubmodules")) {
+               *(config->recurse_submodules) = parse_fetch_recurse_submodules_arg(var, value);
+               return 0;
+       }
+
+       return 0;
+}
+
+void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules)
+{
+       struct fetch_config config = {
+               .max_children = max_children,
+               .recurse_submodules = recurse_submodules
+       };
+       config_from_gitmodules(gitmodules_fetch_config, the_repository, &config);
+}
+
+static int gitmodules_update_clone_config(const char *var, const char *value,
+                                         void *cb)
+{
+       int *max_jobs = cb;
+       if (!strcmp(var, "submodule.fetchjobs"))
+               *max_jobs = parse_submodule_fetchjobs(var, value);
+       return 0;
+}
+
+void update_clone_config_from_gitmodules(int *max_jobs)
+{
+       config_from_gitmodules(gitmodules_update_clone_config, the_repository, &max_jobs);
+}
index ca1f94e2d2ed90f9ef4c588e27c0d8e15e1724ab..dc7278eea45deedc33635af50b016e9ee28df7d2 100644 (file)
@@ -2,6 +2,7 @@
 #define SUBMODULE_CONFIG_CACHE_H
 
 #include "cache.h"
+#include "config.h"
 #include "hashmap.h"
 #include "submodule.h"
 #include "strbuf.h"
@@ -55,4 +56,15 @@ void submodule_free(struct repository *r);
  */
 int check_submodule_name(const char *name);
 
+/*
+ * Note: these helper functions exist solely to maintain backward
+ * compatibility with 'fetch' and 'update_clone' storing configuration in
+ * '.gitmodules'.
+ *
+ * New helpers to retrieve arbitrary configuration from the '.gitmodules' file
+ * should NOT be added.
+ */
+extern void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules);
+extern void update_clone_config_from_gitmodules(int *max_jobs);
+
 #endif /* SUBMODULE_CONFIG_H */
index 0998ea2345800449c08bca12fbedd236f6b55eb6..50cbf5f13ed84c5da081b4130bbd50b7b97e3121 100644 (file)
@@ -93,7 +93,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
        if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
                return -1;
 
-       if (is_gitmodules_unmerged(&the_index))
+       if (is_gitmodules_unmerged(the_repository->index))
                die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
 
        submodule = submodule_from_path(the_repository, &null_oid, oldpath);
@@ -127,7 +127,7 @@ int remove_path_from_gitmodules(const char *path)
        if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
                return -1;
 
-       if (is_gitmodules_unmerged(&the_index))
+       if (is_gitmodules_unmerged(the_repository->index))
                die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
 
        submodule = submodule_from_path(the_repository, &null_oid, path);
@@ -188,7 +188,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 
                if (ignore)
                        handle_ignore_submodules_arg(diffopt, ignore);
-               else if (is_gitmodules_unmerged(&the_index))
+               else if (is_gitmodules_unmerged(the_repository->index))
                        diffopt->flags.ignore_submodules = 1;
        }
 }
@@ -258,7 +258,7 @@ int is_submodule_active(struct repository *repo, const char *path)
                }
 
                parse_pathspec(&ps, 0, 0, NULL, args.argv);
-               ret = match_pathspec(&ps, path, strlen(path), 0, NULL, 1);
+               ret = match_pathspec(repo->index, &ps, path, strlen(path), 0, NULL, 1);
 
                argv_array_clear(&args);
                clear_pathspec(&ps);
@@ -517,8 +517,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(one);
-       *right = lookup_commit_reference(two);
+       *left = lookup_commit_reference(the_repository, one);
+       *right = lookup_commit_reference(the_repository, two);
 
        /*
         * Warn about missing commits in the submodule project, but only if
@@ -1534,6 +1534,18 @@ int bad_to_remove_submodule(const char *path, unsigned flags)
        return ret;
 }
 
+void submodule_unset_core_worktree(const struct submodule *sub)
+{
+       char *config_path = xstrfmt("%s/modules/%s/config",
+                                   get_git_common_dir(), sub->name);
+
+       if (git_config_set_in_file_gently(config_path, "core.worktree", NULL))
+               warning(_("Could not unset core.worktree setting in submodule '%s'"),
+                         sub->path);
+
+       free(config_path);
+}
+
 static const char *get_super_prefix_or_empty(void)
 {
        const char *s = get_super_prefix();
@@ -1670,7 +1682,7 @@ int submodule_move_head(const char *path,
        argv_array_push(&cp.args, new_head ? new_head : empty_tree_oid_hex());
 
        if (run_command(&cp)) {
-               ret = -1;
+               ret = error(_("Submodule '%s' could not be updated."), path);
                goto out;
        }
 
@@ -1699,6 +1711,8 @@ int submodule_move_head(const char *path,
 
                        if (is_empty_dir(path))
                                rmdir_or_warn(path);
+
+                       submodule_unset_core_worktree(sub);
                }
        }
 out:
index 7856b8a0b3d676cde20095f69a4d000d8cf38615..c98cd983e1e13d15605bb0a30d2a558fa08226bf 100644 (file)
@@ -33,62 +33,62 @@ struct submodule_update_strategy {
 };
 #define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
 
-extern int is_gitmodules_unmerged(const struct index_state *istate);
-extern int is_staging_gitmodules_ok(struct index_state *istate);
-extern int update_path_in_gitmodules(const char *oldpath, const char *newpath);
-extern int remove_path_from_gitmodules(const char *path);
-extern void stage_updated_gitmodules(struct index_state *istate);
-extern void set_diffopt_flags_from_submodule_config(struct diff_options *,
-               const char *path);
-extern int git_default_submodule_config(const char *var, const char *value, void *cb);
+int is_gitmodules_unmerged(const struct index_state *istate);
+int is_staging_gitmodules_ok(struct index_state *istate);
+int update_path_in_gitmodules(const char *oldpath, const char *newpath);
+int remove_path_from_gitmodules(const char *path);
+void stage_updated_gitmodules(struct index_state *istate);
+void set_diffopt_flags_from_submodule_config(struct diff_options *,
+                                            const char *path);
+int git_default_submodule_config(const char *var, const char *value, void *cb);
 
 struct option;
 int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
                                                     const char *arg, int unset);
-extern int is_submodule_active(struct repository *repo, const char *path);
+int is_submodule_active(struct repository *repo, const char *path);
 /*
  * Determine if a submodule has been populated at a given 'path' by checking if
  * the <path>/.git resolves to a valid git repository.
  * If return_error_code is NULL, die on error.
  * Otherwise the return error code is the same as of resolve_gitdir_gently.
  */
-extern int is_submodule_populated_gently(const char *path, int *return_error_code);
-extern void die_in_unpopulated_submodule(const struct index_state *istate,
-                                        const char *prefix);
-extern void die_path_inside_submodule(const struct index_state *istate,
-                                     const struct pathspec *ps);
-extern enum submodule_update_type parse_submodule_update_type(const char *value);
-extern int parse_submodule_update_strategy(const char *value,
-               struct submodule_update_strategy *dst);
-extern const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);
-extern void handle_ignore_submodules_arg(struct diff_options *, const char *);
-extern void show_submodule_summary(struct diff_options *o, const char *path,
-               struct object_id *one, struct object_id *two,
-               unsigned dirty_submodule);
-extern void show_submodule_inline_diff(struct diff_options *o, const char *path,
-               struct object_id *one, struct object_id *two,
-               unsigned dirty_submodule);
+int is_submodule_populated_gently(const char *path, int *return_error_code);
+void die_in_unpopulated_submodule(const struct index_state *istate,
+                                 const char *prefix);
+void die_path_inside_submodule(const struct index_state *istate,
+                              const struct pathspec *ps);
+enum submodule_update_type parse_submodule_update_type(const char *value);
+int parse_submodule_update_strategy(const char *value,
+                                   struct submodule_update_strategy *dst);
+const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);
+void handle_ignore_submodules_arg(struct diff_options *, const char *);
+void show_submodule_summary(struct diff_options *o, const char *path,
+                           struct object_id *one, struct object_id *two,
+                           unsigned dirty_submodule);
+void show_submodule_inline_diff(struct diff_options *o, const char *path,
+                               struct object_id *one, struct object_id *two,
+                               unsigned dirty_submodule);
 /* Check if we want to update any submodule.*/
-extern int should_update_submodules(void);
+int should_update_submodules(void);
 /*
  * Returns the submodule struct if the given ce entry is a submodule
  * and it should be updated. Returns NULL otherwise.
  */
-extern const struct submodule *submodule_from_ce(const struct cache_entry *ce);
-extern void check_for_new_submodule_commits(struct object_id *oid);
-extern int fetch_populated_submodules(struct repository *r,
-                                     const struct argv_array *options,
-                                     const char *prefix,
-                                     int command_line_option,
-                                     int default_option,
-                                     int quiet, int max_parallel_jobs);
-extern unsigned is_submodule_modified(const char *path, int ignore_untracked);
-extern int submodule_uses_gitfile(const char *path);
+const struct submodule *submodule_from_ce(const struct cache_entry *ce);
+void check_for_new_submodule_commits(struct object_id *oid);
+int fetch_populated_submodules(struct repository *r,
+                              const struct argv_array *options,
+                              const char *prefix,
+                              int command_line_option,
+                              int default_option,
+                              int quiet, int max_parallel_jobs);
+unsigned is_submodule_modified(const char *path, int ignore_untracked);
+int submodule_uses_gitfile(const char *path);
 
 #define SUBMODULE_REMOVAL_DIE_ON_ERROR (1<<0)
 #define SUBMODULE_REMOVAL_IGNORE_UNTRACKED (1<<1)
 #define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
-extern int bad_to_remove_submodule(const char *path, unsigned flags);
+int bad_to_remove_submodule(const char *path, unsigned flags);
 
 int add_submodule_odb(const char *path);
 
@@ -96,17 +96,17 @@ int add_submodule_odb(const char *path);
  * Checks if there are submodule changes in a..b. If a is the null OID,
  * checks b and all its ancestors instead.
  */
-extern int submodule_touches_in_range(struct object_id *a,
-                                     struct object_id *b);
-extern int find_unpushed_submodules(struct oid_array *commits,
-                                   const char *remotes_name,
-                                   struct string_list *needs_pushing);
+int submodule_touches_in_range(struct object_id *a,
+                              struct object_id *b);
+int find_unpushed_submodules(struct oid_array *commits,
+                            const char *remotes_name,
+                            struct string_list *needs_pushing);
 struct refspec;
-extern int push_unpushed_submodules(struct oid_array *commits,
-                                   const struct remote *remote,
-                                   const struct refspec *rs,
-                                   const struct string_list *push_options,
-                                   int dry_run);
+int push_unpushed_submodules(struct oid_array *commits,
+                            const struct remote *remote,
+                            const struct refspec *rs,
+                            const struct string_list *push_options,
+                            int dry_run);
 /*
  * Given a submodule path (as in the index), return the repository
  * path of that submodule in 'buf'. Return -1 on error or when the
@@ -116,28 +116,30 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule);
 
 #define SUBMODULE_MOVE_HEAD_DRY_RUN (1<<0)
 #define SUBMODULE_MOVE_HEAD_FORCE   (1<<1)
-extern int submodule_move_head(const char *path,
-                              const char *old,
-                              const char *new_head,
-                              unsigned flags);
+int submodule_move_head(const char *path,
+                       const char *old,
+                       const char *new_head,
+                       unsigned flags);
+
+void submodule_unset_core_worktree(const struct submodule *sub);
 
 /*
  * Prepare the "env_array" parameter of a "struct child_process" for executing
  * a submodule by clearing any repo-specific environment variables, but
  * retaining any config in the environment.
  */
-extern void prepare_submodule_repo_env(struct argv_array *out);
+void prepare_submodule_repo_env(struct argv_array *out);
 
 #define ABSORB_GITDIR_RECURSE_SUBMODULES (1<<0)
-extern void absorb_git_dir_into_superproject(const char *prefix,
-                                            const char *path,
-                                            unsigned flags);
+void absorb_git_dir_into_superproject(const char *prefix,
+                                     const char *path,
+                                     unsigned flags);
 
 /*
  * Return the absolute path of the working tree of the superproject, which this
  * project is a submodule of. If this repository is not a submodule of
  * another repository, return NULL.
  */
-extern const char *get_superproject_working_tree(void);
+const char *get_superproject_working_tree(void);
 
 #endif
index 9d09df5a60d8d751f68436d28776f82dbc38e036..e7acedabe17f033d4205613c9af50152e5cec126 100644 (file)
@@ -2,6 +2,7 @@ t[0-9][0-9][0-9][0-9]/* -whitespace
 /chainlint/*.expect eol=lf
 /diff-lib/* eol=lf
 /t0110/url-* binary
+/t3206/* eol=lf
 /t3900/*.txt eol=lf
 /t3901/*.txt eol=lf
 /t4034/*/* eol=lf
index 093832fef1541906b735d162a76c8ffa773d236c..6da48a2e0a461e35f31fdd05712ee5c2bb9fda31 100644 (file)
@@ -320,11 +320,11 @@ test_expect_success 'blame -L ,Y (Y == nlines)' '
 
 test_expect_success 'blame -L ,Y (Y == nlines + 1)' '
        n=$(expr $(wc -l <file) + 2) &&
-       test_must_fail $PROG -L,$n file
+       check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
 '
 
 test_expect_success 'blame -L ,Y (Y > nlines)' '
-       test_must_fail $PROG -L,12345 file
+       check_count -L,12345 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
 '
 
 test_expect_success 'blame -L multiple (disjoint)' '
index 5f0882cb3810114dfdbbe244799af0c676bf7126..8544df38dfc0c557120a8a250529147edbc3d2a4 100644 (file)
 # "else", and "fi" in if-then-else likewise must not end with "&&", thus
 # receives similar treatment.
 #
+# Swallowing here-docs with arbitrary tags requires a bit of finesse. When a
+# line such as "cat <<EOF >out" is seen, the here-doc tag is moved to the front
+# of the line enclosed in angle brackets as a sentinel, giving "<EOF>cat >out".
+# As each subsequent line is read, it is appended to the target line and a
+# (whitespace-loose) back-reference match /^<(.*)>\n\1$/ is attempted to see if
+# the content inside "<...>" matches the entirety of the newly-read line. For
+# instance, if the next line read is "some data", when concatenated with the
+# target line, it becomes "<EOF>cat >out\nsome data", and a match is attempted
+# to see if "EOF" matches "some data". Since it doesn't, the next line is
+# attempted. When a line consisting of only "EOF" (and possible whitespace) is
+# encountered, it is appended to the target line giving "<EOF>cat >out\nEOF",
+# in which case the "EOF" inside "<...>" does match the text following the
+# newline, thus the closing here-doc tag has been found. The closing tag line
+# and the "<...>" prefix on the target line are then discarded, leaving just
+# the target line "cat >out".
+#
 # To facilitate regression testing (and manual debugging), a ">" annotation is
 # applied to the line containing ")" which closes a subshell, ">>" to a line
 # closing a nested subshell, and ">>>" to a line closing both at once. This
 
 # here-doc -- swallow it to avoid false hits within its body (but keep the
 # command to which it was attached)
-/<<[   ]*[-\\]*EOF[    ]*/ {
-       s/[     ]*<<[   ]*[-\\]*EOF//
-       h
+/<<[   ]*[-\\']*[A-Za-z0-9_]/ {
+       s/^\(.*\)<<[    ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
+       s/[     ]*<<//
        :hereslurp
        N
-       s/.*\n//
-       /^[     ]*EOF[  ]*$/!bhereslurp
-       x
+       /^<\([^>]*\)>.*\n[      ]*\1[   ]*$/!{
+               s/\n.*$//
+               bhereslurp
+       }
+       s/^<[^>]*>//
+       s/\n.*$//
 }
 
 # one-liner "(...) &&"
@@ -132,16 +151,15 @@ s/.*\n//
 :slurp
 # incomplete line "...\"
 /\\$/bincomplete
-# multi-line quoted string "...\n..."
-/^[^"]*"[^"]*$/bdqstring
-# multi-line quoted string '...\n...' (but not contraction in string "it's so")
-/^[^']*'[^']*$/{
+# multi-line quoted string "...\n..."?
+/"/bdqstring
+# multi-line quoted string '...\n...'? (but not contraction in string "it's")
+/'/{
        /"[^'"]*'[^'"]*"/!bsqstring
 }
+:folded
 # here-doc -- swallow it
-/<<[   ]*[-\\]*EOF/bheredoc
-/<<[   ]*[-\\]*EOT/bheredoc
-/<<[   ]*[-\\]*INPUT_END/bheredoc
+/<<[   ]*[-\\']*[A-Za-z0-9_]/bheredoc
 # comment or empty line -- discard since final non-comment, non-empty line
 # before closing ")", "done", "elsif", "else", or "fi" will need to be
 # re-visited to drop "suspect" marking since final line of those constructs
@@ -199,7 +217,7 @@ s/.*\n//
 # "$(...)" -- command substitution; not closing ")"
 /\$([^)][^)]*)[^)]*$/bcheckchain
 # multi-line "$(...\n...)" -- command substitution; treat as nested subshell
-/\$([  ]*$/bnest
+/\$([^)]*$/bnest
 # "=(...)" -- Bash array assignment; not closing ")"
 /=(/bcheckchain
 # closing "...) &&"
@@ -232,42 +250,48 @@ N
 s/\\\n//
 bslurp
 
-# found multi-line double-quoted string "...\n..." -- slurp until end of string
+# check for multi-line double-quoted string "...\n..." -- fold to one line
 :dqstring
-s/"//g
+# remove all quote pairs
+s/"\([^"]*\)"/@!\1@!/g
+# done if no dangling quote
+/"/!bdqdone
+# otherwise, slurp next line and try again
 N
 s/\n//
-/"/!bdqstring
-bcheckchain
+bdqstring
+:dqdone
+s/@!/"/g
+bfolded
 
-# found multi-line single-quoted string '...\n...' -- slurp until end of string
+# check for multi-line single-quoted string '...\n...' -- fold to one line
 :sqstring
-s/'//g
+# remove all quote pairs
+s/'\([^']*\)'/@!\1@!/g
+# done if no dangling quote
+/'/!bsqdone
+# otherwise, slurp next line and try again
 N
 s/\n//
-/'/!bsqstring
-bcheckchain
+bsqstring
+:sqdone
+s/@!/'/g
+bfolded
 
 # found here-doc -- swallow it to avoid false hits within its body (but keep
-# the command to which it was attached); take care to handle here-docs nested
-# within here-docs by only recognizing closing tag matching outer here-doc
-# opening tag
+# the command to which it was attached)
 :heredoc
-/EOF/{ s/[     ]*<<[   ]*[-\\]*EOF//; s/^/EOF/; }
-/EOT/{ s/[     ]*<<[   ]*[-\\]*EOT//; s/^/EOT/; }
-/INPUT_END/{ s/[       ]*<<[   ]*[-\\]*INPUT_END//; s/^/INPUT_END/; }
+s/^\(.*\)<<[   ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
+s/[    ]*<<//
 :hereslurpsub
 N
-/^EOF.*\n[     ]*EOF[  ]*$/bhereclose
-/^EOT.*\n[     ]*EOT[  ]*$/bhereclose
-/^INPUT_END.*\n[       ]*INPUT_END[    ]*$/bhereclose
-bhereslurpsub
-:hereclose
-s/^EOF//
-s/^EOT//
-s/^INPUT_END//
+/^<\([^>]*\)>.*\n[     ]*\1[   ]*$/!{
+       s/\n.*$//
+       bhereslurpsub
+}
+s/^<[^>]*>//
 s/\n.*$//
-bcheckchain
+bfolded
 
 # found "case ... in" -- pass through untouched
 :case
diff --git a/t/chainlint/here-doc-close-subshell.expect b/t/chainlint/here-doc-close-subshell.expect
new file mode 100644 (file)
index 0000000..f011e33
--- /dev/null
@@ -0,0 +1,2 @@
+(
+>      cat)
diff --git a/t/chainlint/here-doc-close-subshell.test b/t/chainlint/here-doc-close-subshell.test
new file mode 100644 (file)
index 0000000..b857ff5
--- /dev/null
@@ -0,0 +1,5 @@
+(
+# LINT: line contains here-doc and closes nested subshell
+       cat <<-\INPUT)
+       fizz
+       INPUT
diff --git a/t/chainlint/here-doc-multi-line-command-subst.expect b/t/chainlint/here-doc-multi-line-command-subst.expect
new file mode 100644 (file)
index 0000000..e5fb752
--- /dev/null
@@ -0,0 +1,5 @@
+(
+       x=$(bobble &&
+?!AMP?!>>              wiffle)
+       echo $x
+>)
diff --git a/t/chainlint/here-doc-multi-line-command-subst.test b/t/chainlint/here-doc-multi-line-command-subst.test
new file mode 100644 (file)
index 0000000..899bc5d
--- /dev/null
@@ -0,0 +1,9 @@
+(
+# LINT: line contains here-doc and opens multi-line $(...)
+       x=$(bobble <<-\END &&
+               fossil
+               vegetable
+               END
+               wiffle)
+       echo $x
+)
diff --git a/t/chainlint/here-doc-multi-line-string.expect b/t/chainlint/here-doc-multi-line-string.expect
new file mode 100644 (file)
index 0000000..32038a0
--- /dev/null
@@ -0,0 +1,4 @@
+(
+?!AMP?!        cat && echo "multi-line string"
+       bap
+>)
diff --git a/t/chainlint/here-doc-multi-line-string.test b/t/chainlint/here-doc-multi-line-string.test
new file mode 100644 (file)
index 0000000..a53edbc
--- /dev/null
@@ -0,0 +1,8 @@
+(
+# LINT: line contains here-doc and opens multi-line string
+       cat <<-\TXT && echo "multi-line
+       string"
+       fizzle
+       TXT
+       bap
+)
index 2328fe7753908b455ec8034b6724acc7f21e891d..aff65687168ec7e8e38cb4db79ada69b199da1ea 100644 (file)
@@ -1,3 +1,7 @@
 boodle wobba        gorgo snoot        wafta snurb &&
 
+cat >foo &&
+
+cat >bar &&
+
 horticulture
index bd36f6e1d35f6a423acc6630ef8b24004f322dcf..f2bb14b693a4bf2a8c371bef82cb6d3aea453528 100644 (file)
@@ -7,6 +7,20 @@ quoth the raven,
 nevermore...
 EOF
 
+# LINT: swallow here-doc with arbitrary tag
+cat <<-Arbitrary_Tag_42 >foo &&
+snoz
+boz
+woz
+Arbitrary_Tag_42
+
+# LINT: swallow 'quoted' here-doc
+cat <<'FUMP' >bar &&
+snoz
+boz
+woz
+FUMP
+
 # LINT: swallow here-doc (EOF is last line of test)
 horticulture <<\EOF
 gomez
index 19c023b1c871daa34df20735ca848a454bf647bc..59b6c8b850a16d087e5d322c8ee25dcbeb553fa5 100644 (file)
@@ -6,4 +6,13 @@
 >>     ) &&
        echo ok
 >) |
-sort
+sort &&
+(
+       bar &&
+       x=$(echo bar |
+               cat
+>>     ) &&
+       y=$(echo baz |
+>>             fip) &&
+       echo fail
+>)
index ca0620ab6b14b6bed39226565eb3d2d120f6f36e..300058341b6f303dce9d8e8105b6f16fa25f2ebf 100644 (file)
@@ -6,4 +6,13 @@
        ) &&
        echo ok
 ) |
-sort
+sort &&
+(
+       bar &&
+       x=$(echo bar |
+               cat
+       ) &&
+       y=$(echo baz |
+               fip) &&
+       echo fail
+)
index 8334c4cc8e08d3e8f296de90bfd6ab3dd1983629..170cb5999322ea7798bceafb2222274c4112adde 100644 (file)
@@ -1,9 +1,15 @@
 (
-       x=line 1                line 2          line 3" &&
-?!AMP?!        y=line 1                line2'
+       x="line 1               line 2          line 3" &&
+?!AMP?!        y='line 1               line2'
        foobar
 >) &&
 (
        echo "there's nothing to see here" &&
        exit
+>) &&
+(
+       echo "xyz" "abc         def             ghi" &&
+       echo 'xyz' 'abc         def             ghi' &&
+       echo 'xyz' "abc         def             ghi" &&
+       barfoo
 >)
index 14cb44d51cbdaebc7ab16fa39d921b391e96ec5c..287ab897054874972076ec6913bf8c8144196296 100644 (file)
 # LINT: starting multi-line single-quoted string
        echo "there's nothing to see here" &&
        exit
+) &&
+(
+       echo "xyz" "abc
+               def
+               ghi" &&
+       echo 'xyz' 'abc
+               def
+               ghi' &&
+       echo 'xyz' "abc
+               def
+               ghi" &&
+       barfoo
 )
index 559301e005e1f16e748f728b4da6fdf7c59496a1..0c9ef1cfc6959e1b4093200769b2401467e927ad 100644 (file)
@@ -1,3 +1,5 @@
+cat >foop &&
+
 (
        cat &&
 ?!AMP?!        cat
index 027e0bb3ff1af3e2acf76abe5bbcf21eff8a2389..f35404bf0f9313f33040d49b685d087d4f11b29b 100644 (file)
@@ -1,3 +1,13 @@
+# LINT: inner "EOF" not misintrepreted as closing ARBITRARY here-doc
+cat <<ARBITRARY >foop &&
+naddle
+fub <<EOF
+       nozzle
+       noodle
+EOF
+formp
+ARBITRARY
+
 (
 # LINT: inner "EOF" not misintrepreted as closing INPUT_END here-doc
        cat <<-\INPUT_END &&
index 19d5aff233f30c15645fe9c700e7f70506a84272..7663ea7fc4adba607279a3f36c57200e9e56a800 100644 (file)
@@ -2,4 +2,9 @@
        echo wobba             gorgo snoot             wafta snurb &&
 ?!AMP?!        cat >bip
        echo >bop
+>) &&
+(
+       cat >bup &&
+       cat >bup2 &&
+       meep
 >)
index 9c3564c247e0d15e96a13e1092f848d301a828a5..b6b5a9b33aac57156df37da5b3bc420baab78796 100644 (file)
        wednesday
        pugsly
        EOF
+) &&
+(
+# LINT: swallow here-doc with arbitrary tag
+       cat <<-\ARBITRARY >bup &&
+       glink
+       FIZZ
+       ARBITRARY
+       cat <<-'ARBITRARY2' >bup2 &&
+       glink
+       FIZZ
+       ARBITRARY2
+       meep
 )
diff --git a/t/chainlint/t7900-subtree.expect b/t/chainlint/t7900-subtree.expect
new file mode 100644 (file)
index 0000000..c991342
--- /dev/null
@@ -0,0 +1,10 @@
+(
+       chks="sub1sub2sub3sub4" &&
+       chks_sub=$(cat | sed 's,^,sub dir/,'
+>>) &&
+       chkms="main-sub1main-sub2main-sub3main-sub4" &&
+       chkms_sub=$(cat | sed 's,^,sub dir/,'
+>>) &&
+       subfiles=$(git ls-files) &&
+       check_equal "$subfiles" "$chkms$chks"
+>)
diff --git a/t/chainlint/t7900-subtree.test b/t/chainlint/t7900-subtree.test
new file mode 100644 (file)
index 0000000..277d835
--- /dev/null
@@ -0,0 +1,22 @@
+(
+       chks="sub1
+sub2
+sub3
+sub4" &&
+       chks_sub=$(cat <<TXT | sed 's,^,sub dir/,'
+$chks
+TXT
+) &&
+       chkms="main-sub1
+main-sub2
+main-sub3
+main-sub4" &&
+       chkms_sub=$(cat <<TXT | sed 's,^,sub dir/,'
+$chkms
+TXT
+) &&
+
+       subfiles=$(git ls-files) &&
+       check_equal "$subfiles" "$chkms
+$chks"
+)
index e07f0284372ec25c91fd62f0d136c31d80263a0d..d5823f71d8d57ec92404d5cceabd86d5ab86af53 100755 (executable)
@@ -7,22 +7,43 @@
 use warnings;
 
 my $exit_code=0;
+my %func;
 
 sub err {
        my $msg = shift;
+       s/^\s+//;
+       s/\s+$//;
+       s/\s+/ /g;
        print "$ARGV:$.: error: $msg: $_\n";
        $exit_code = 1;
 }
 
+# glean names of shell functions
+for my $i (@ARGV) {
+       open(my $f, '<', $i) or die "$0: $i: $!\n";
+       while (<$f>) {
+               $func{$1} = 1 if /^\s*(\w+)\s*\(\)\s*{\s*$/;
+       }
+       close $f;
+}
+
 while (<>) {
        chomp;
+       # stitch together incomplete lines (those ending with "\")
+       while (s/\\$//) {
+               $_ .= readline;
+               chomp;
+       }
+
        /\bsed\s+-i/ and err 'sed -i is not portable';
-       /\becho\s+-[neE]/ and err 'echo with option is not portable (please use printf)';
+       /\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 (please use type)';
-       /\btest\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
-       /\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (please use test_line_count)';
-       /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';
+       /^\s*[^#]\s*which\s/ and err 'which is not portable (use type)';
+       /\btest\s+[^=]*==/ and err '"test a == b" is not portable (use =)';
+       /\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (use test_line_count)';
+       /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (use FOO=bar && export FOO)';
+       /^\s*([A-Z0-9_]+=(\w+|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and
+               err '"FOO=bar shell_func" assignment extends beyond "shell_func"';
        # this resets our $. for each file
        close ARGV if eof;
 }
index d6bcfddf13352b92d6be4d9d5b8e7d7f05cc06ee..f65e301f9ddc13f395b88a4b8cf994506beee292 100644 (file)
@@ -16,8 +16,8 @@ static int cmd_sync(void)
        if ((0 == dwRet) || (dwRet > MAX_PATH))
                return error("Error getting current directory");
 
-       if ((Buffer[0] < 'A') || (Buffer[0] > 'Z'))
-               return error("Invalid drive letter '%c'", Buffer[0]);
+       if (!has_dos_drive_prefix(Buffer))
+               return error("'%s': invalid drive letter", Buffer);
 
        szVolumeAccessPath[4] = Buffer[0];
        hVolWrite = CreateFile(szVolumeAccessPath, GENERIC_READ | GENERIC_WRITE,
diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c
new file mode 100644 (file)
index 0000000..37c4525
--- /dev/null
@@ -0,0 +1,565 @@
+#include "test-tool.h"
+#include "cache.h"
+#include "json-writer.h"
+
+static const char *expect_obj1 = "{\"a\":\"abc\",\"b\":42,\"c\":true}";
+static const char *expect_obj2 = "{\"a\":-1,\"b\":2147483647,\"c\":0}";
+static const char *expect_obj3 = "{\"a\":0,\"b\":4294967295,\"c\":9223372036854775807}";
+static const char *expect_obj4 = "{\"t\":true,\"f\":false,\"n\":null}";
+static const char *expect_obj5 = "{\"abc\\tdef\":\"abc\\\\def\"}";
+static const char *expect_obj6 = "{\"a\":3.14}";
+
+static const char *pretty_obj1 = ("{\n"
+                                 "  \"a\": \"abc\",\n"
+                                 "  \"b\": 42,\n"
+                                 "  \"c\": true\n"
+                                 "}");
+static const char *pretty_obj2 = ("{\n"
+                                 "  \"a\": -1,\n"
+                                 "  \"b\": 2147483647,\n"
+                                 "  \"c\": 0\n"
+                                 "}");
+static const char *pretty_obj3 = ("{\n"
+                                 "  \"a\": 0,\n"
+                                 "  \"b\": 4294967295,\n"
+                                 "  \"c\": 9223372036854775807\n"
+                                 "}");
+static const char *pretty_obj4 = ("{\n"
+                                 "  \"t\": true,\n"
+                                 "  \"f\": false,\n"
+                                 "  \"n\": null\n"
+                                 "}");
+
+static struct json_writer obj1 = JSON_WRITER_INIT;
+static struct json_writer obj2 = JSON_WRITER_INIT;
+static struct json_writer obj3 = JSON_WRITER_INIT;
+static struct json_writer obj4 = JSON_WRITER_INIT;
+static struct json_writer obj5 = JSON_WRITER_INIT;
+static struct json_writer obj6 = JSON_WRITER_INIT;
+
+static void make_obj1(int pretty)
+{
+       jw_object_begin(&obj1, pretty);
+       {
+               jw_object_string(&obj1, "a", "abc");
+               jw_object_intmax(&obj1, "b", 42);
+               jw_object_true(&obj1, "c");
+       }
+       jw_end(&obj1);
+}
+
+static void make_obj2(int pretty)
+{
+       jw_object_begin(&obj2, pretty);
+       {
+               jw_object_intmax(&obj2, "a", -1);
+               jw_object_intmax(&obj2, "b", 0x7fffffff);
+               jw_object_intmax(&obj2, "c", 0);
+       }
+       jw_end(&obj2);
+}
+
+static void make_obj3(int pretty)
+{
+       jw_object_begin(&obj3, pretty);
+       {
+               jw_object_intmax(&obj3, "a", 0);
+               jw_object_intmax(&obj3, "b", 0xffffffff);
+               jw_object_intmax(&obj3, "c", 0x7fffffffffffffffULL);
+       }
+       jw_end(&obj3);
+}
+
+static void make_obj4(int pretty)
+{
+       jw_object_begin(&obj4, pretty);
+       {
+               jw_object_true(&obj4, "t");
+               jw_object_false(&obj4, "f");
+               jw_object_null(&obj4, "n");
+       }
+       jw_end(&obj4);
+}
+
+static void make_obj5(int pretty)
+{
+       jw_object_begin(&obj5, pretty);
+       {
+               jw_object_string(&obj5, "abc" "\x09" "def", "abc" "\\" "def");
+       }
+       jw_end(&obj5);
+}
+
+static void make_obj6(int pretty)
+{
+       jw_object_begin(&obj6, pretty);
+       {
+               jw_object_double(&obj6, "a", 2, 3.14159);
+       }
+       jw_end(&obj6);
+}
+
+static const char *expect_arr1 = "[\"abc\",42,true]";
+static const char *expect_arr2 = "[-1,2147483647,0]";
+static const char *expect_arr3 = "[0,4294967295,9223372036854775807]";
+static const char *expect_arr4 = "[true,false,null]";
+
+static const char *pretty_arr1 = ("[\n"
+                                 "  \"abc\",\n"
+                                 "  42,\n"
+                                 "  true\n"
+                                 "]");
+static const char *pretty_arr2 = ("[\n"
+                                 "  -1,\n"
+                                 "  2147483647,\n"
+                                 "  0\n"
+                                 "]");
+static const char *pretty_arr3 = ("[\n"
+                                 "  0,\n"
+                                 "  4294967295,\n"
+                                 "  9223372036854775807\n"
+                                 "]");
+static const char *pretty_arr4 = ("[\n"
+                                 "  true,\n"
+                                 "  false,\n"
+                                 "  null\n"
+                                 "]");
+
+static struct json_writer arr1 = JSON_WRITER_INIT;
+static struct json_writer arr2 = JSON_WRITER_INIT;
+static struct json_writer arr3 = JSON_WRITER_INIT;
+static struct json_writer arr4 = JSON_WRITER_INIT;
+
+static void make_arr1(int pretty)
+{
+       jw_array_begin(&arr1, pretty);
+       {
+               jw_array_string(&arr1, "abc");
+               jw_array_intmax(&arr1, 42);
+               jw_array_true(&arr1);
+       }
+       jw_end(&arr1);
+}
+
+static void make_arr2(int pretty)
+{
+       jw_array_begin(&arr2, pretty);
+       {
+               jw_array_intmax(&arr2, -1);
+               jw_array_intmax(&arr2, 0x7fffffff);
+               jw_array_intmax(&arr2, 0);
+       }
+       jw_end(&arr2);
+}
+
+static void make_arr3(int pretty)
+{
+       jw_array_begin(&arr3, pretty);
+       {
+               jw_array_intmax(&arr3, 0);
+               jw_array_intmax(&arr3, 0xffffffff);
+               jw_array_intmax(&arr3, 0x7fffffffffffffffULL);
+       }
+       jw_end(&arr3);
+}
+
+static void make_arr4(int pretty)
+{
+       jw_array_begin(&arr4, pretty);
+       {
+               jw_array_true(&arr4);
+               jw_array_false(&arr4);
+               jw_array_null(&arr4);
+       }
+       jw_end(&arr4);
+}
+
+static char *expect_nest1 =
+       "{\"obj1\":{\"a\":\"abc\",\"b\":42,\"c\":true},\"arr1\":[\"abc\",42,true]}";
+
+static struct json_writer nest1 = JSON_WRITER_INIT;
+
+static void make_nest1(int pretty)
+{
+       jw_object_begin(&nest1, pretty);
+       {
+               jw_object_sub_jw(&nest1, "obj1", &obj1);
+               jw_object_sub_jw(&nest1, "arr1", &arr1);
+       }
+       jw_end(&nest1);
+}
+
+static char *expect_inline1 =
+       "{\"obj1\":{\"a\":\"abc\",\"b\":42,\"c\":true},\"arr1\":[\"abc\",42,true]}";
+
+static char *pretty_inline1 =
+       ("{\n"
+        "  \"obj1\": {\n"
+        "    \"a\": \"abc\",\n"
+        "    \"b\": 42,\n"
+        "    \"c\": true\n"
+        "  },\n"
+        "  \"arr1\": [\n"
+        "    \"abc\",\n"
+        "    42,\n"
+        "    true\n"
+        "  ]\n"
+        "}");
+
+static struct json_writer inline1 = JSON_WRITER_INIT;
+
+static void make_inline1(int pretty)
+{
+       jw_object_begin(&inline1, pretty);
+       {
+               jw_object_inline_begin_object(&inline1, "obj1");
+               {
+                       jw_object_string(&inline1, "a", "abc");
+                       jw_object_intmax(&inline1, "b", 42);
+                       jw_object_true(&inline1, "c");
+               }
+               jw_end(&inline1);
+               jw_object_inline_begin_array(&inline1, "arr1");
+               {
+                       jw_array_string(&inline1, "abc");
+                       jw_array_intmax(&inline1, 42);
+                       jw_array_true(&inline1);
+               }
+               jw_end(&inline1);
+       }
+       jw_end(&inline1);
+}
+
+static char *expect_inline2 =
+       "[[1,2],[3,4],{\"a\":\"abc\"}]";
+
+static char *pretty_inline2 =
+       ("[\n"
+        "  [\n"
+        "    1,\n"
+        "    2\n"
+        "  ],\n"
+        "  [\n"
+        "    3,\n"
+        "    4\n"
+        "  ],\n"
+        "  {\n"
+        "    \"a\": \"abc\"\n"
+        "  }\n"
+        "]");
+
+static struct json_writer inline2 = JSON_WRITER_INIT;
+
+static void make_inline2(int pretty)
+{
+       jw_array_begin(&inline2, pretty);
+       {
+               jw_array_inline_begin_array(&inline2);
+               {
+                       jw_array_intmax(&inline2, 1);
+                       jw_array_intmax(&inline2, 2);
+               }
+               jw_end(&inline2);
+               jw_array_inline_begin_array(&inline2);
+               {
+                       jw_array_intmax(&inline2, 3);
+                       jw_array_intmax(&inline2, 4);
+               }
+               jw_end(&inline2);
+               jw_array_inline_begin_object(&inline2);
+               {
+                       jw_object_string(&inline2, "a", "abc");
+               }
+               jw_end(&inline2);
+       }
+       jw_end(&inline2);
+}
+
+/*
+ * When super is compact, we expect subs to be compacted (even if originally
+ * pretty).
+ */
+static const char *expect_mixed1 =
+       ("{\"obj1\":{\"a\":\"abc\",\"b\":42,\"c\":true},"
+        "\"arr1\":[\"abc\",42,true]}");
+
+/*
+ * When super is pretty, a compact sub (obj1) is kept compact and a pretty
+ * sub (arr1) is re-indented.
+ */
+static const char *pretty_mixed1 =
+       ("{\n"
+        "  \"obj1\": {\"a\":\"abc\",\"b\":42,\"c\":true},\n"
+        "  \"arr1\": [\n"
+        "    \"abc\",\n"
+        "    42,\n"
+        "    true\n"
+        "  ]\n"
+        "}");
+
+static struct json_writer mixed1 = JSON_WRITER_INIT;
+
+static void make_mixed1(int pretty)
+{
+       jw_init(&obj1);
+       jw_init(&arr1);
+
+       make_obj1(0); /* obj1 is compact */
+       make_arr1(1); /* arr1 is pretty */
+
+       jw_object_begin(&mixed1, pretty);
+       {
+               jw_object_sub_jw(&mixed1, "obj1", &obj1);
+               jw_object_sub_jw(&mixed1, "arr1", &arr1);
+       }
+       jw_end(&mixed1);
+}
+
+static void cmp(const char *test, const struct json_writer *jw, const char *exp)
+{
+       if (!strcmp(jw->json.buf, exp))
+               return;
+
+       printf("error[%s]: observed '%s' expected '%s'\n",
+              test, jw->json.buf, exp);
+       exit(1);
+}
+
+#define t(v) do { make_##v(0); cmp(#v, &v, expect_##v); } while (0)
+#define p(v) do { make_##v(1); cmp(#v, &v, pretty_##v); } while (0)
+
+/*
+ * Run some basic regression tests with some known patterns.
+ * These tests also demonstrate how to use the jw_ API.
+ */
+static int unit_tests(void)
+{
+       /* comptact (canonical) forms */
+       t(obj1);
+       t(obj2);
+       t(obj3);
+       t(obj4);
+       t(obj5);
+       t(obj6);
+
+       t(arr1);
+       t(arr2);
+       t(arr3);
+       t(arr4);
+
+       t(nest1);
+
+       t(inline1);
+       t(inline2);
+
+       jw_init(&obj1);
+       jw_init(&obj2);
+       jw_init(&obj3);
+       jw_init(&obj4);
+
+       jw_init(&arr1);
+       jw_init(&arr2);
+       jw_init(&arr3);
+       jw_init(&arr4);
+
+       jw_init(&inline1);
+       jw_init(&inline2);
+
+       /* pretty forms */
+       p(obj1);
+       p(obj2);
+       p(obj3);
+       p(obj4);
+
+       p(arr1);
+       p(arr2);
+       p(arr3);
+       p(arr4);
+
+       p(inline1);
+       p(inline2);
+
+       /* mixed forms */
+       t(mixed1);
+       jw_init(&mixed1);
+       p(mixed1);
+
+       return 0;
+}
+
+static void get_s(int line_nr, char **s_in)
+{
+       *s_in = strtok(NULL, " ");
+       if (!*s_in)
+               die("line[%d]: expected: <s>", line_nr);
+}
+
+static void get_i(int line_nr, intmax_t *s_in)
+{
+       char *s;
+       char *endptr;
+
+       get_s(line_nr, &s);
+
+       *s_in = strtol(s, &endptr, 10);
+       if (*endptr || errno == ERANGE)
+               die("line[%d]: invalid integer value", line_nr);
+}
+
+static void get_d(int line_nr, double *s_in)
+{
+       char *s;
+       char *endptr;
+
+       get_s(line_nr, &s);
+
+       *s_in = strtod(s, &endptr);
+       if (*endptr || errno == ERANGE)
+               die("line[%d]: invalid float value", line_nr);
+}
+
+static int pretty;
+
+#define MAX_LINE_LENGTH (64 * 1024)
+
+static char *get_trimmed_line(char *buf, int buf_size)
+{
+       int len;
+
+       if (!fgets(buf, buf_size, stdin))
+               return NULL;
+
+       len = strlen(buf);
+       while (len > 0) {
+               char c = buf[len - 1];
+               if (c == '\n' || c == '\r' || c == ' ' || c == '\t')
+                       buf[--len] = 0;
+               else
+                       break;
+       }
+
+       while (*buf == ' ' || *buf == '\t')
+               buf++;
+
+       return buf;
+}
+
+static int scripted(void)
+{
+       struct json_writer jw = JSON_WRITER_INIT;
+       char buf[MAX_LINE_LENGTH];
+       char *line;
+       int line_nr = 0;
+
+       line = get_trimmed_line(buf, MAX_LINE_LENGTH);
+       if (!line)
+               return 0;
+
+       if (!strcmp(line, "object"))
+               jw_object_begin(&jw, pretty);
+       else if (!strcmp(line, "array"))
+               jw_array_begin(&jw, pretty);
+       else
+               die("expected first line to be 'object' or 'array'");
+
+       while ((line = get_trimmed_line(buf, MAX_LINE_LENGTH)) != NULL) {
+               char *verb;
+               char *key;
+               char *s_value;
+               intmax_t i_value;
+               double d_value;
+
+               line_nr++;
+
+               verb = strtok(line, " ");
+
+               if (!strcmp(verb, "end")) {
+                       jw_end(&jw);
+               }
+               else if (!strcmp(verb, "object-string")) {
+                       get_s(line_nr, &key);
+                       get_s(line_nr, &s_value);
+                       jw_object_string(&jw, key, s_value);
+               }
+               else if (!strcmp(verb, "object-int")) {
+                       get_s(line_nr, &key);
+                       get_i(line_nr, &i_value);
+                       jw_object_intmax(&jw, key, i_value);
+               }
+               else if (!strcmp(verb, "object-double")) {
+                       get_s(line_nr, &key);
+                       get_i(line_nr, &i_value);
+                       get_d(line_nr, &d_value);
+                       jw_object_double(&jw, key, i_value, d_value);
+               }
+               else if (!strcmp(verb, "object-true")) {
+                       get_s(line_nr, &key);
+                       jw_object_true(&jw, key);
+               }
+               else if (!strcmp(verb, "object-false")) {
+                       get_s(line_nr, &key);
+                       jw_object_false(&jw, key);
+               }
+               else if (!strcmp(verb, "object-null")) {
+                       get_s(line_nr, &key);
+                       jw_object_null(&jw, key);
+               }
+               else if (!strcmp(verb, "object-object")) {
+                       get_s(line_nr, &key);
+                       jw_object_inline_begin_object(&jw, key);
+               }
+               else if (!strcmp(verb, "object-array")) {
+                       get_s(line_nr, &key);
+                       jw_object_inline_begin_array(&jw, key);
+               }
+               else if (!strcmp(verb, "array-string")) {
+                       get_s(line_nr, &s_value);
+                       jw_array_string(&jw, s_value);
+               }
+               else if (!strcmp(verb, "array-int")) {
+                       get_i(line_nr, &i_value);
+                       jw_array_intmax(&jw, i_value);
+               }
+               else if (!strcmp(verb, "array-double")) {
+                       get_i(line_nr, &i_value);
+                       get_d(line_nr, &d_value);
+                       jw_array_double(&jw, i_value, d_value);
+               }
+               else if (!strcmp(verb, "array-true"))
+                       jw_array_true(&jw);
+               else if (!strcmp(verb, "array-false"))
+                       jw_array_false(&jw);
+               else if (!strcmp(verb, "array-null"))
+                       jw_array_null(&jw);
+               else if (!strcmp(verb, "array-object"))
+                       jw_array_inline_begin_object(&jw);
+               else if (!strcmp(verb, "array-array"))
+                       jw_array_inline_begin_array(&jw);
+               else
+                       die("unrecognized token: '%s'", verb);
+       }
+
+       if (!jw_is_terminated(&jw))
+               die("json not terminated: '%s'", jw.json.buf);
+
+       printf("%s\n", jw.json.buf);
+
+       strbuf_release(&jw.json);
+       return 0;
+}
+
+int cmd__json_writer(int argc, const char **argv)
+{
+       argc--; /* skip over "json-writer" arg */
+       argv++;
+
+       if (argc > 0 && argv[0][0] == '-') {
+               if (!strcmp(argv[0], "-u") || !strcmp(argv[0], "--unit"))
+                       return unit_tests();
+
+               if (!strcmp(argv[0], "-p") || !strcmp(argv[0], "--pretty"))
+                       pretty = 1;
+       }
+
+       return scripted();
+}
index 0f19e53c75bf28fc075e7a220cf8fa78507def7f..30775f986f8067323808f6ccd064067f6c27489b 100644 (file)
@@ -1,3 +1,4 @@
+#include "cache.h"
 #include "pkt-line.h"
 
 static void pack_line(const char *line)
@@ -48,6 +49,36 @@ static void unpack(void)
        }
 }
 
+static void unpack_sideband(void)
+{
+       struct packet_reader reader;
+       packet_reader_init(&reader, 0, NULL, 0,
+                          PACKET_READ_GENTLE_ON_EOF |
+                          PACKET_READ_CHOMP_NEWLINE);
+
+       while (packet_reader_read(&reader) != PACKET_READ_EOF) {
+               int band;
+               int fd;
+
+               switch (reader.status) {
+               case PACKET_READ_EOF:
+                       break;
+               case PACKET_READ_NORMAL:
+                       band = reader.line[0] & 0xff;
+                       if (band < 1 || band > 2)
+                               die("unexpected side band %d", band);
+                       fd = band;
+
+                       write_or_die(fd, reader.line + 1, reader.pktlen - 1);
+                       break;
+               case PACKET_READ_FLUSH:
+                       return;
+               case PACKET_READ_DELIM:
+                       break;
+               }
+       }
+}
+
 int cmd_main(int argc, const char **argv)
 {
        if (argc < 2)
@@ -57,6 +88,8 @@ int cmd_main(int argc, const char **argv)
                pack(argc - 2, argv + 2);
        else if (!strcmp(argv[1], "unpack"))
                unpack();
+       else if (!strcmp(argv[1], "unpack-sideband"))
+               unpack_sideband();
        else
                die("invalid argument '%s'", argv[1]);
 
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
new file mode 100644 (file)
index 0000000..2762ca6
--- /dev/null
@@ -0,0 +1,82 @@
+#include "test-tool.h"
+#include "cache.h"
+#include "commit-graph.h"
+#include "commit.h"
+#include "config.h"
+#include "object-store.h"
+#include "object.h"
+#include "repository.h"
+#include "tree.h"
+
+static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
+                                      const struct object_id *commit_oid)
+{
+       struct repository r;
+       struct commit *c;
+       struct commit_list *parent;
+
+       repo_init(&r, gitdir, worktree);
+
+       c = lookup_commit(&r, commit_oid);
+
+       if (!parse_commit_in_graph(&r, c))
+               die("Couldn't parse commit");
+
+       printf("%"PRItime, c->date);
+       for (parent = c->parents; parent; parent = parent->next)
+               printf(" %s", oid_to_hex(&parent->item->object.oid));
+       printf("\n");
+
+       repo_clear(&r);
+}
+
+static void test_get_commit_tree_in_graph(const char *gitdir,
+                                         const char *worktree,
+                                         const struct object_id *commit_oid)
+{
+       struct repository r;
+       struct commit *c;
+       struct tree *tree;
+
+       repo_init(&r, gitdir, worktree);
+
+       c = lookup_commit(&r, commit_oid);
+
+       /*
+        * get_commit_tree_in_graph does not automatically parse the commit, so
+        * parse it first.
+        */
+       if (!parse_commit_in_graph(&r, c))
+               die("Couldn't parse commit");
+       tree = get_commit_tree_in_graph(&r, c);
+       if (!tree)
+               die("Couldn't get commit tree");
+
+       printf("%s\n", oid_to_hex(&tree->object.oid));
+
+       repo_clear(&r);
+}
+
+int cmd__repository(int argc, const char **argv)
+{
+       if (argc < 2)
+               die("must have at least 2 arguments");
+       if (!strcmp(argv[1], "parse_commit_in_graph")) {
+               struct object_id oid;
+               if (argc < 5)
+                       die("not enough arguments");
+               if (parse_oid_hex(argv[4], &oid, &argv[4]))
+                       die("cannot parse oid '%s'", argv[4]);
+               test_parse_commit_in_graph(argv[2], argv[3], &oid);
+       } else if (!strcmp(argv[1], "get_commit_tree_in_graph")) {
+               struct object_id oid;
+               if (argc < 5)
+                       die("not enough arguments");
+               if (parse_oid_hex(argv[4], &oid, &argv[4]))
+                       die("cannot parse oid '%s'", argv[4]);
+               test_get_commit_tree_in_graph(argv[2], argv[3], &oid);
+       } else {
+               die("unrecognized '%s'", argv[1]);
+       }
+       return 0;
+}
index 805a45de9c877d9e5fecb6aa543e6ac985443d5b..0edafcfd65db7586bc1521d2e1afa99fbde50292 100644 (file)
@@ -19,6 +19,7 @@ static struct test_cmd cmds[] = {
        { "genrandom", cmd__genrandom },
        { "hashmap", cmd__hashmap },
        { "index-version", cmd__index_version },
+       { "json-writer", cmd__json_writer },
        { "lazy-init-name-hash", cmd__lazy_init_name_hash },
        { "match-trees", cmd__match_trees },
        { "mergesort", cmd__mergesort },
@@ -29,6 +30,7 @@ static struct test_cmd cmds[] = {
        { "read-cache", cmd__read_cache },
        { "ref-store", cmd__ref_store },
        { "regex", cmd__regex },
+       { "repository", cmd__repository },
        { "revision-walking", cmd__revision_walking },
        { "run-command", cmd__run_command },
        { "scrap-cache-tree", cmd__scrap_cache_tree },
index 7116ddfb94398da98063b7efed77240058c6961f..e926c416ea48bc25412097944d454ebd922e624a 100644 (file)
@@ -13,6 +13,7 @@ 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__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);
 int cmd__match_trees(int argc, const char **argv);
 int cmd__mergesort(int argc, const char **argv);
@@ -23,6 +24,7 @@ int cmd__prio_queue(int argc, const char **argv);
 int cmd__read_cache(int argc, const char **argv);
 int cmd__ref_store(int argc, const char **argv);
 int cmd__regex(int argc, const char **argv);
+int cmd__repository(int argc, const char **argv);
 int cmd__revision_walking(int argc, const char **argv);
 int cmd__run_command(int argc, const char **argv);
 int cmd__scrap_cache_tree(int argc, const char **argv);
index a5d3b2cbaad4edd078b8d58160dc4252ce8adec9..3fe02876c1fc7e4f7488c1534a4745f5760f1ca0 100755 (executable)
@@ -38,7 +38,33 @@ then
                        "$TEST_DIRECTORY"/lib-gpg/ownertrust &&
                gpg --homedir "${GNUPGHOME}" </dev/null >/dev/null 2>&1 \
                        --sign -u committer@example.com &&
-               test_set_prereq GPG
+               test_set_prereq GPG &&
+               # Available key info:
+               # * see t/lib-gpg/gpgsm-gen-key.in
+               # To generate new certificate:
+               #  * no passphrase
+               #       gpgsm --homedir /tmp/gpghome/ \
+               #               -o /tmp/gpgsm.crt.user \
+               #               --generate-key \
+               #               --batch t/lib-gpg/gpgsm-gen-key.in
+               # To import certificate:
+               #       gpgsm --homedir /tmp/gpghome/ \
+               #               --import /tmp/gpgsm.crt.user
+               # To export into a .p12 we can later import:
+               #       gpgsm --homedir /tmp/gpghome/ \
+               #               -o t/lib-gpg/gpgsm_cert.p12 \
+               #               --export-secret-key-p12 "committer@example.com"
+               echo | gpgsm --homedir "${GNUPGHOME}" 2>/dev/null \
+                       --passphrase-fd 0 --pinentry-mode loopback \
+                       --import "$TEST_DIRECTORY"/lib-gpg/gpgsm_cert.p12 &&
+               gpgsm --homedir "${GNUPGHOME}" 2>/dev/null -K \
+                       | grep fingerprint: | cut -d" " -f4 | tr -d '\n' > \
+                       ${GNUPGHOME}/trustlist.txt &&
+               echo " S relax" >> ${GNUPGHOME}/trustlist.txt &&
+               (gpgconf --kill gpg-agent >/dev/null 2>&1 || : ) &&
+               echo hello | gpgsm --homedir "${GNUPGHOME}" >/dev/null \
+                       -u committer@example.com -o /dev/null --sign - 2>&1 &&
+               test_set_prereq GPGSM
                ;;
        esac
 fi
diff --git a/t/lib-gpg/gpgsm-gen-key.in b/t/lib-gpg/gpgsm-gen-key.in
new file mode 100644 (file)
index 0000000..a7fd87c
--- /dev/null
@@ -0,0 +1,8 @@
+Key-Type: RSA
+Key-Length: 2048
+Key-Usage: sign
+Serial: random
+Name-DN: CN=C O Mitter, O=Example, SN=C O, GN=Mitter
+Name-Email: committer@example.com
+Not-Before: 1970-01-01 00:00:00
+Not-After: 3000-01-01 00:00:00
diff --git a/t/lib-gpg/gpgsm_cert.p12 b/t/lib-gpg/gpgsm_cert.p12
new file mode 100644 (file)
index 0000000..94ffad0
Binary files /dev/null and b/t/lib-gpg/gpgsm_cert.p12 differ
index 435a37465a702c35a5d53d8809f0ef700ae9ff83..a8729f82325ee7fb9350c42553e11205e6720928 100644 (file)
@@ -132,6 +132,7 @@ prepare_httpd() {
        cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH"
        install_script broken-smart-http.sh
        install_script error.sh
+       install_script apply-one-time-sed.sh
 
        ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
 
@@ -287,3 +288,24 @@ expect_askpass() {
        test_cmp "$TRASH_DIRECTORY/askpass-expect" \
                 "$TRASH_DIRECTORY/askpass-query"
 }
+
+strip_access_log() {
+       sed -e "
+               s/^.* \"//
+               s/\"//
+               s/ [1-9][0-9]*\$//
+               s/^GET /GET  /
+       " "$HTTPD_ROOT_PATH"/access.log
+}
+
+# Requires one argument: the name of a file containing the expected stripped
+# access log entries.
+check_access_log() {
+       sort "$1" >"$1".sorted &&
+       strip_access_log >access.log.stripped &&
+       sort access.log.stripped >access.log.sorted &&
+       if ! test_cmp "$1".sorted access.log.sorted
+       then
+               test_cmp "$1" access.log.stripped
+       fi
+}
index 724d9ae462b78af95298786a1fe26f375023ad55..581c010d8fc4c1184ba17b63b940aaac30d0b0f4 100644 (file)
@@ -111,9 +111,14 @@ Alias /auth/dumb/ www/auth/dumb/
        SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
        SetEnv GIT_HTTP_EXPORT_ALL
 </LocationMatch>
+<LocationMatch /one_time_sed/>
+       SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
+       SetEnv GIT_HTTP_EXPORT_ALL
+</LocationMatch>
 ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1
 ScriptAlias /broken_smart/ broken-smart-http.sh/
 ScriptAlias /error/ error.sh/
+ScriptAliasMatch /one_time_sed/(.*) apply-one-time-sed.sh/$1
 <Directory ${GIT_EXEC_PATH}>
        Options FollowSymlinks
 </Directory>
@@ -123,6 +128,9 @@ ScriptAlias /error/ error.sh/
 <Files error.sh>
   Options ExecCGI
 </Files>
+<Files apply-one-time-sed.sh>
+       Options ExecCGI
+</Files>
 <Files ${GIT_EXEC_PATH}/git-http-backend>
        Options ExecCGI
 </Files>
diff --git a/t/lib-httpd/apply-one-time-sed.sh b/t/lib-httpd/apply-one-time-sed.sh
new file mode 100644 (file)
index 0000000..fcef728
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# If "one-time-sed" exists in $HTTPD_ROOT_PATH, run sed on the HTTP response,
+# using the contents of "one-time-sed" as the sed command to be run. If the
+# response was modified as a result, delete "one-time-sed" so that subsequent
+# HTTP responses are no longer modified.
+#
+# This can be used to simulate the effects of the repository changing in
+# between HTTP request-response pairs.
+if [ -e one-time-sed ]; then
+       "$GIT_EXEC_PATH/git-http-backend" >out
+       sed "$(cat one-time-sed)" <out >out_modified
+
+       if diff out out_modified >/dev/null; then
+               cat out
+       else
+               cat out_modified
+               rm one-time-sed
+       fi
+else
+       "$GIT_EXEC_PATH/git-http-backend"
+fi
index e90ec7908771788d0d7723d2dd729b6defb4bb7f..5b56b23166bb3dea2e89cea38a19eb5698dfff53 100755 (executable)
@@ -235,7 +235,7 @@ reset_work_tree_to_interested () {
        then
                mkdir -p submodule_update/.git/modules/sub1/modules &&
                cp -r submodule_update_repo/.git/modules/sub1/modules/sub2 submodule_update/.git/modules/sub1/modules/sub2
-               GIT_WORK_TREE=. git -C submodule_update/.git/modules/sub1/modules/sub2 config --unset core.worktree
+               # core.worktree is unset for sub2 as it is not checked out
        fi &&
        # indicate we are interested in the submodule:
        git -C submodule_update config submodule.sub1.url "bogus" &&
@@ -709,7 +709,8 @@ test_submodule_recursing_with_args_common() {
                        git branch -t remove_sub1 origin/remove_sub1 &&
                        $command remove_sub1 &&
                        test_superproject_content origin/remove_sub1 &&
-                       ! test -e sub1
+                       ! test -e sub1 &&
+                       test_must_fail git config -f .git/modules/sub1/config core.worktree
                )
        '
        # ... absorbing a .git directory along the way.
@@ -781,7 +782,8 @@ test_submodule_recursing_with_args_common() {
                (
                        cd submodule_update &&
                        git branch -t invalid_sub1 origin/invalid_sub1 &&
-                       test_must_fail $command invalid_sub1 &&
+                       test_must_fail $command invalid_sub1 2>err &&
+                       test_i18ngrep sub1 err &&
                        test_superproject_content origin/add_sub1 &&
                        test_submodule_content sub1 origin/add_sub1
                )
index c03f155a357446338fa831e061dc58d8e5f4c657..1744cee5e996fe4e03149de3a0fb8065d2aa6d67 100755 (executable)
@@ -807,10 +807,9 @@ test_expect_success 'trailing whitespace is ignored' '
        cat >expect <<EOF &&
 whitespace/untracked
 EOF
-       : >err.expect &&
        git ls-files -o -X ignore whitespace >actual 2>err &&
        test_cmp expect actual &&
-       test_cmp err.expect err
+       test_must_be_empty err
 '
 
 test_expect_success !MINGW 'quoting allows trailing whitespace' '
@@ -820,10 +819,9 @@ test_expect_success !MINGW 'quoting allows trailing whitespace' '
        >whitespace/untracked &&
        echo "whitespace/trailing\\ \\ " >ignore &&
        echo whitespace/untracked >expect &&
-       : >err.expect &&
        git ls-files -o -X ignore whitespace >actual 2>err &&
        test_cmp expect actual &&
-       test_cmp err.expect err
+       test_must_be_empty err
 '
 
 test_expect_success !MINGW,!CYGWIN 'correct handling of backslashes' '
@@ -845,10 +843,9 @@ test_expect_success !MINGW,!CYGWIN 'correct handling of backslashes' '
        whitespace/trailing 6 \\a\\Z
        EOF
        echo whitespace/untracked >expect &&
-       >err.expect &&
        git ls-files -o -X ignore whitespace >actual 2>err &&
        test_cmp expect actual &&
-       test_cmp err.expect err
+       test_must_be_empty err
 '
 
 test_expect_success 'info/exclude trumps core.excludesfile' '
diff --git a/t/t0019-json-writer.sh b/t/t0019-json-writer.sh
new file mode 100755 (executable)
index 0000000..3b0c336
--- /dev/null
@@ -0,0 +1,331 @@
+#!/bin/sh
+
+test_description='test json-writer JSON generation'
+. ./test-lib.sh
+
+test_expect_success 'unit test of json-writer routines' '
+       test-tool json-writer -u
+'
+
+test_expect_success 'trivial object' '
+       cat >expect <<-\EOF &&
+       {}
+       EOF
+       cat >input <<-\EOF &&
+       object
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'trivial array' '
+       cat >expect <<-\EOF &&
+       []
+       EOF
+       cat >input <<-\EOF &&
+       array
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'simple object' '
+       cat >expect <<-\EOF &&
+       {"a":"abc","b":42,"c":3.14,"d":true,"e":false,"f":null}
+       EOF
+       cat >input <<-\EOF &&
+       object
+               object-string a abc
+               object-int b 42
+               object-double c 2 3.140
+               object-true d
+               object-false e
+               object-null f
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'simple array' '
+       cat >expect <<-\EOF &&
+       ["abc",42,3.14,true,false,null]
+       EOF
+       cat >input <<-\EOF &&
+       array
+               array-string abc
+               array-int 42
+               array-double 2 3.140
+               array-true
+               array-false
+               array-null
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'escape quoting string' '
+       cat >expect <<-\EOF &&
+       {"a":"abc\\def"}
+       EOF
+       cat >input <<-\EOF &&
+       object
+               object-string a abc\def
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'escape quoting string 2' '
+       cat >expect <<-\EOF &&
+       {"a":"abc\"def"}
+       EOF
+       cat >input <<-\EOF &&
+       object
+               object-string a abc"def
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'nested inline object' '
+       cat >expect <<-\EOF &&
+       {"a":"abc","b":42,"sub1":{"c":3.14,"d":true,"sub2":{"e":false,"f":null}}}
+       EOF
+       cat >input <<-\EOF &&
+       object
+               object-string a abc
+               object-int b 42
+               object-object sub1
+                       object-double c 2 3.140
+                       object-true d
+                       object-object sub2
+                               object-false e
+                               object-null f
+                       end
+               end
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'nested inline array' '
+       cat >expect <<-\EOF &&
+       ["abc",42,[3.14,true,[false,null]]]
+       EOF
+       cat >input <<-\EOF &&
+       array
+               array-string abc
+               array-int 42
+               array-array
+                       array-double 2 3.140
+                       array-true
+                       array-array
+                               array-false
+                               array-null
+                       end
+               end
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'nested inline object and array' '
+       cat >expect <<-\EOF &&
+       {"a":"abc","b":42,"sub1":{"c":3.14,"d":true,"sub2":[false,null]}}
+       EOF
+       cat >input <<-\EOF &&
+       object
+               object-string a abc
+               object-int b 42
+               object-object sub1
+                       object-double c 2 3.140
+                       object-true d
+                       object-array sub2
+                               array-false
+                               array-null
+                       end
+               end
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'nested inline object and array 2' '
+       cat >expect <<-\EOF &&
+       {"a":"abc","b":42,"sub1":{"c":3.14,"d":true,"sub2":[false,{"g":0,"h":1},null]}}
+       EOF
+       cat >input <<-\EOF &&
+       object
+               object-string a abc
+               object-int b 42
+               object-object sub1
+                       object-double c 2 3.140
+                       object-true d
+                       object-array sub2
+                               array-false
+                               array-object
+                                       object-int g 0
+                                       object-int h 1
+                               end
+                               array-null
+                       end
+               end
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'pretty nested inline object and array 2' '
+       sed -e "s/^|//" >expect <<-\EOF &&
+       |{
+       |  "a": "abc",
+       |  "b": 42,
+       |  "sub1": {
+       |    "c": 3.14,
+       |    "d": true,
+       |    "sub2": [
+       |      false,
+       |      {
+       |        "g": 0,
+       |        "h": 1
+       |      },
+       |      null
+       |    ]
+       |  }
+       |}
+       EOF
+       cat >input <<-\EOF &&
+       object
+               object-string a abc
+               object-int b 42
+               object-object sub1
+                       object-double c 2 3.140
+                       object-true d
+                       object-array sub2
+                               array-false
+                               array-object
+                                       object-int g 0
+                                       object-int h 1
+                               end
+                               array-null
+                       end
+               end
+       end
+       EOF
+       test-tool json-writer -p <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'inline object with no members' '
+       cat >expect <<-\EOF &&
+       {"a":"abc","empty":{},"b":42}
+       EOF
+       cat >input <<-\EOF &&
+       object
+               object-string a abc
+               object-object empty
+               end
+               object-int b 42
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'inline array with no members' '
+       cat >expect <<-\EOF &&
+       {"a":"abc","empty":[],"b":42}
+       EOF
+       cat >input <<-\EOF &&
+       object
+               object-string a abc
+               object-array empty
+               end
+               object-int b 42
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'larger empty example' '
+       cat >expect <<-\EOF &&
+       {"a":"abc","empty":[{},{},{},[],{}],"b":42}
+       EOF
+       cat >input <<-\EOF &&
+       object
+               object-string a abc
+               object-array empty
+                       array-object
+                       end
+                       array-object
+                       end
+                       array-object
+                       end
+                       array-array
+                       end
+                       array-object
+                       end
+               end
+               object-int b 42
+       end
+       EOF
+       test-tool json-writer <input >actual &&
+       test_cmp expect actual
+'
+
+test_lazy_prereq PERLJSON '
+       perl -MJSON -e "exit 0"
+'
+
+# As a sanity check, ask Perl to parse our generated JSON and recursively
+# dump the resulting data in sorted order.  Confirm that that matches our
+# expectations.
+test_expect_success PERLJSON 'parse JSON using Perl' '
+       cat >expect <<-\EOF &&
+       row[0].a abc
+       row[0].b 42
+       row[0].sub1 hash
+       row[0].sub1.c 3.14
+       row[0].sub1.d 1
+       row[0].sub1.sub2 array
+       row[0].sub1.sub2[0] 0
+       row[0].sub1.sub2[1] hash
+       row[0].sub1.sub2[1].g 0
+       row[0].sub1.sub2[1].h 1
+       row[0].sub1.sub2[2] null
+       EOF
+       cat >input <<-\EOF &&
+       object
+               object-string a abc
+               object-int b 42
+               object-object sub1
+                       object-double c 2 3.140
+                       object-true d
+                       object-array sub2
+                               array-false
+                               array-object
+                                       object-int g 0
+                                       object-int h 1
+                               end
+                               array-null
+                       end
+               end
+       end
+       EOF
+       test-tool json-writer <input >output.json &&
+       perl "$TEST_DIRECTORY"/t0019/parse_json.perl <output.json >actual &&
+       test_cmp expect actual
+'
+
+test_done
diff --git a/t/t0019/parse_json.perl b/t/t0019/parse_json.perl
new file mode 100644 (file)
index 0000000..ca4e5bf
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use JSON;
+
+sub dump_array {
+    my ($label_in, $ary_ref) = @_;
+    my @ary = @$ary_ref;
+
+    for ( my $i = 0; $i <= $#{ $ary_ref }; $i++ )
+    {
+       my $label = "$label_in\[$i\]";
+       dump_item($label, $ary[$i]);
+    }
+}
+
+sub dump_hash {
+    my ($label_in, $obj_ref) = @_;
+    my %obj = %$obj_ref;
+
+    foreach my $k (sort keys %obj) {
+       my $label = (length($label_in) > 0) ? "$label_in.$k" : "$k";
+       my $value = $obj{$k};
+
+       dump_item($label, $value);
+    }
+}
+
+sub dump_item {
+    my ($label_in, $value) = @_;
+    if (ref($value) eq 'ARRAY') {
+       print "$label_in array\n";
+       dump_array($label_in, $value);
+    } elsif (ref($value) eq 'HASH') {
+       print "$label_in hash\n";
+       dump_hash($label_in, $value);
+    } elsif (defined $value) {
+       print "$label_in $value\n";
+    } else {
+       print "$label_in null\n";
+    }
+}
+
+my $row = 0;
+while (<>) {
+    my $data = decode_json( $_ );
+    my $label = "row[$row]";
+
+    dump_hash($label, $data);
+    $row++;
+}
+
index 6a213608cc10fc29691f8bf293b0a34ce1f93c5e..308cd28f3bd7304a63628e8a64014e8d20faa82f 100755 (executable)
@@ -583,7 +583,7 @@ test_expect_success PERL 'process filter should restart after unexpected write f
                git checkout --quiet --no-progress . 2>git-stderr.log &&
 
                grep "smudge write error at" git-stderr.log &&
-               grep "error: external filter" git-stderr.log &&
+               test_i18ngrep "error: external filter" git-stderr.log &&
 
                cat >expected.log <<-EOF &&
                        START
index bbf3e39e3d229fbda5b7e40e9caca3aba2e1f52b..b77948c618ecdd3ac654500ae2143863eccf4f9f 100755 (executable)
@@ -110,31 +110,30 @@ test_expect_success \
 
 test_expect_success \
     'only consecutive blank lines should be completely removed' '
-    > expect &&
 
     printf "\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "\n\n\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "$sss\n$sss\n$sss\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "$sss$sss\n$sss\n\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "\n$sss\n$sss$sss\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "$sss$sss$sss$sss\n\n\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "\n$sss$sss$sss$sss\n\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "\n\n$sss$sss$sss$sss\n" | git stripspace >actual &&
-    test_cmp expect actual
+    test_must_be_empty actual
 '
 
 test_expect_success \
index 03bd31e9f22a1964551cb07d76c45ce90a3cd17e..82eaaea0f4954d22861a4733b80aebcc361aca9a 100755 (executable)
@@ -294,8 +294,7 @@ test_expect_success 'helpers can abort the process' '
                -c credential.helper="!f() { echo quit=1; }; f" \
                -c credential.helper="verbatim foo bar" \
                credential fill >stdout &&
-       >expect &&
-       test_cmp expect stdout
+       test_must_be_empty stdout
 '
 
 test_expect_success 'empty helper spec resets helper list' '
index 13dd510b2ed8c4ce3b48666557bf68ad2aa03953..7f19d591f250bd61f7d25a5e5e0fae2ca1d8f118 100755 (executable)
@@ -550,8 +550,8 @@ test_expect_success 'git cat-file --batch --follow-symlink returns correct sha a
 test_expect_success 'cat-file --batch-all-objects shows all objects' '
        # make new repos so we know the full set of objects; we will
        # also make sure that there are some packed and some loose
-       # objects, some referenced and some not, and that there are
-       # some available only via alternates.
+       # objects, some referenced and some not, some duplicates, and that
+       # there are some available only via alternates.
        git init all-one &&
        (
                cd all-one &&
@@ -567,10 +567,23 @@ test_expect_success 'cat-file --batch-all-objects shows all objects' '
                cd all-two &&
                echo local-unref | git hash-object -w --stdin
        ) >>expect.unsorted &&
+       git -C all-two rev-parse HEAD:file |
+               git -C all-two pack-objects .git/objects/pack/pack &&
        sort <expect.unsorted >expect &&
        git -C all-two cat-file --batch-all-objects \
                                --batch-check="%(objectname)" >actual &&
        test_cmp expect actual
 '
 
+# The only user-visible difference is that the objects are no longer sorted,
+# and the resulting sort order is undefined. So we can only check that it
+# produces the same objects as the ordered case, but that at least exercises
+# the code.
+test_expect_success 'cat-file --unordered works' '
+       git -C all-two cat-file --batch-all-objects --unordered \
+                               --batch-check="%(objectname)" >actual.unsorted &&
+       sort <actual.unsorted >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 0c6f48f3024c81de765a8acb489e2d5e3ec42a56..ba71b159ba8ce1aae9c13d470bdceb7963da58da 100755 (executable)
@@ -227,12 +227,11 @@ test_expect_success 'index removal and worktree narrowing at the same time' '
 '
 
 test_expect_success 'read-tree --reset removes outside worktree' '
-       >empty &&
        echo init.t >.git/info/sparse-checkout &&
        git checkout -f top &&
        git reset --hard removed &&
        git ls-files sub/added >result &&
-       test_cmp empty result
+       test_must_be_empty result
 '
 
 test_expect_success 'print errors when failed to update worktree' '
diff --git a/t/t1015-read-index-unmerged.sh b/t/t1015-read-index-unmerged.sh
new file mode 100755 (executable)
index 0000000..55d22da
--- /dev/null
@@ -0,0 +1,123 @@
+#!/bin/sh
+
+test_description='Test various callers of read_index_unmerged'
+. ./test-lib.sh
+
+test_expect_success 'setup modify/delete + directory/file conflict' '
+       test_create_repo df_plus_modify_delete &&
+       (
+               cd df_plus_modify_delete &&
+
+               test_write_lines a b c d e f g h >letters &&
+               git add letters &&
+               git commit -m initial &&
+
+               git checkout -b modify &&
+               # Throw in letters.txt for sorting order fun
+               # ("letters.txt" sorts between "letters" and "letters/file")
+               echo i >>letters &&
+               echo "version 2" >letters.txt &&
+               git add letters letters.txt &&
+               git commit -m modified &&
+
+               git checkout -b delete HEAD^ &&
+               git rm letters &&
+               mkdir letters &&
+               >letters/file &&
+               echo "version 1" >letters.txt &&
+               git add letters letters.txt &&
+               git commit -m deleted
+       )
+'
+
+test_expect_success 'read-tree --reset cleans unmerged entries' '
+       test_when_finished "git -C df_plus_modify_delete clean -f" &&
+       test_when_finished "git -C df_plus_modify_delete reset --hard" &&
+       (
+               cd df_plus_modify_delete &&
+
+               git checkout delete^0 &&
+               test_must_fail git merge modify &&
+
+               git read-tree --reset HEAD &&
+               git ls-files -u >conflicts &&
+               test_must_be_empty conflicts
+       )
+'
+
+test_expect_success 'One reset --hard cleans unmerged entries' '
+       test_when_finished "git -C df_plus_modify_delete clean -f" &&
+       test_when_finished "git -C df_plus_modify_delete reset --hard" &&
+       (
+               cd df_plus_modify_delete &&
+
+               git checkout delete^0 &&
+               test_must_fail git merge modify &&
+
+               git reset --hard &&
+               test_path_is_missing .git/MERGE_HEAD &&
+               git ls-files -u >conflicts &&
+               test_must_be_empty conflicts
+       )
+'
+
+test_expect_success 'setup directory/file conflict + simple edit/edit' '
+       test_create_repo df_plus_edit_edit &&
+       (
+               cd df_plus_edit_edit &&
+
+               test_seq 1 10 >numbers &&
+               git add numbers &&
+               git commit -m initial &&
+
+               git checkout -b d-edit &&
+               mkdir foo &&
+               echo content >foo/bar &&
+               git add foo &&
+               echo 11 >>numbers &&
+               git add numbers &&
+               git commit -m "directory and edit" &&
+
+               git checkout -b f-edit d-edit^1 &&
+               echo content >foo &&
+               git add foo &&
+               echo eleven >>numbers &&
+               git add numbers &&
+               git commit -m "file and edit"
+       )
+'
+
+test_expect_success 'git merge --abort succeeds despite D/F conflict' '
+       test_when_finished "git -C df_plus_edit_edit clean -f" &&
+       test_when_finished "git -C df_plus_edit_edit reset --hard" &&
+       (
+               cd df_plus_edit_edit &&
+
+               git checkout f-edit^0 &&
+               test_must_fail git merge d-edit^0 &&
+
+               git merge --abort &&
+               test_path_is_missing .git/MERGE_HEAD &&
+               git ls-files -u >conflicts &&
+               test_must_be_empty conflicts
+       )
+'
+
+test_expect_success 'git am --skip succeeds despite D/F conflict' '
+       test_when_finished "git -C df_plus_edit_edit clean -f" &&
+       test_when_finished "git -C df_plus_edit_edit reset --hard" &&
+       (
+               cd df_plus_edit_edit &&
+
+               git checkout f-edit^0 &&
+               git format-patch -1 d-edit &&
+               test_must_fail git am -3 0001*.patch &&
+
+               git am --skip &&
+               test_path_is_missing .git/rebase-apply &&
+               git ls-files -u >conflicts &&
+               test_must_be_empty conflicts
+       )
+'
+
+test_done
index f035ee40a313ae25a13bdb6a838eed3b34fd5f9d..635918505d122f822dcaee54e16ee9669c81693c 100755 (executable)
@@ -310,7 +310,7 @@ test_expect_success 'include cycles are detected' '
        cycle
        EOF
        test_must_fail git config --get-all test.value 2>stderr &&
-       grep "exceeded maximum include depth" stderr
+       test_i18ngrep "exceeded maximum include depth" stderr
 '
 
 test_done
index 8b14ab187c5e01a27bbc4964e3ac9d89e2eb8934..21e139a313bed1d91121044f64a5e7ce5078002c 100755 (executable)
@@ -114,11 +114,10 @@ test_expect_success 'Exclusion in a non-XDG global ignore file' '
 '
 
 test_expect_success 'Checking XDG ignore file when HOME is unset' '
-       >expected &&
        (sane_unset HOME &&
         git config --unset core.excludesfile &&
         git ls-files --exclude-standard --ignored >actual) &&
-       test_cmp expected actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'Checking attributes in the XDG attributes file' '
@@ -132,10 +131,9 @@ test_expect_success 'Checking attributes in the XDG attributes file' '
 '
 
 test_expect_success 'Checking XDG attributes when HOME is unset' '
-       >expected &&
        (sane_unset HOME &&
         git check-attr -a f >actual) &&
-       test_cmp expected actual
+       test_must_be_empty actual
 '
 
 test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/attributes' '
index 3e00d1af01fb771bd3fd26dcb265a3d80da37934..d0a2727b850a6a5fa855a5787a221ce1078f2c7c 100755 (executable)
@@ -233,7 +233,7 @@ test_expect_success 'check line errors for malformed values' '
 
 test_expect_success 'error on modifying repo config without repo' '
        nongit test_must_fail git config a.b c 2>err &&
-       grep "not in a git directory" err
+       test_i18ngrep "not in a git directory" err
 '
 
 cmdline_config="'foo.bar=from-cmdline'"
index e1fd0f0ca8b5d731d79ccca1d6e6140683a3665f..7c8df2095574f66f6d434f7717228f6f76a2a908 100755 (executable)
@@ -390,7 +390,7 @@ test_expect_success 'Query "master@{2005-05-26 23:33:01}" (middle of history wit
        test_when_finished "rm -f o e" &&
        git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
        test $B = $(cat o) &&
-       test "warning: Log for ref $m has gap after $gd." = "$(cat e)"
+       test_i18ngrep -F "warning: log for ref $m has gap after $gd" e
 '
 test_expect_success 'Query "master@{2005-05-26 23:38:00}" (middle of history)' '
        test_when_finished "rm -f o e" &&
@@ -408,7 +408,7 @@ test_expect_success 'Query "master@{2005-05-28}" (past end of history)' '
        test_when_finished "rm -f o e" &&
        git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
        test $D = $(cat o) &&
-       test "warning: Log for ref $m unexpectedly ended on $ld." = "$(cat e)"
+       test_i18ngrep -F "warning: log for ref $m unexpectedly ended on $ld" e
 '
 
 rm -f .git/$m .git/logs/$m expect
@@ -462,7 +462,7 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER
 test_expect_success 'given old value for missing pseudoref, do not create' '
        test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
        test_path_is_missing .git/PSEUDOREF &&
-       grep "could not read ref" err
+       test_i18ngrep "could not read ref" err
 '
 
 test_expect_success 'create pseudoref' '
@@ -483,7 +483,7 @@ test_expect_success 'overwrite pseudoref with correct old value' '
 test_expect_success 'do not overwrite pseudoref with wrong old value' '
        test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
        test $C = $(cat .git/PSEUDOREF) &&
-       grep "unexpected object ID" err
+       test_i18ngrep "unexpected object ID" err
 '
 
 test_expect_success 'delete pseudoref' '
@@ -495,7 +495,7 @@ test_expect_success 'do not delete pseudoref with wrong old value' '
        git update-ref PSEUDOREF $A &&
        test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
        test $A = $(cat .git/PSEUDOREF) &&
-       grep "unexpected object ID" err
+       test_i18ngrep "unexpected object ID" err
 '
 
 test_expect_success 'delete pseudoref with correct old value' '
@@ -512,7 +512,7 @@ test_expect_success 'do not overwrite pseudoref with old OID zero' '
        test_when_finished git update-ref -d PSEUDOREF &&
        test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
        test $A = $(cat .git/PSEUDOREF) &&
-       grep "already exists" err
+       test_i18ngrep "already exists" err
 '
 
 # Test --stdin
@@ -650,7 +650,7 @@ test_expect_success 'stdin fails with duplicate refs' '
        create $a $m
        EOF
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed." err
+       test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
 '
 
 test_expect_success 'stdin create ref works' '
@@ -1052,7 +1052,7 @@ test_expect_success 'stdin -z fails option with unknown name' '
 test_expect_success 'stdin -z fails with duplicate refs' '
        printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed." err
+       test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
 '
 
 test_expect_success 'stdin -z create ref works' '
@@ -1283,7 +1283,7 @@ test_expect_success 'fails with duplicate HEAD update' '
        update HEAD $B
        EOF
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
+       test_i18ngrep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
        echo "refs/heads/target1" >expect &&
        git symbolic-ref HEAD >actual &&
        test_cmp expect actual &&
@@ -1300,7 +1300,7 @@ test_expect_success 'fails with duplicate ref update via symref' '
        update refs/heads/symref2 $B
        EOF
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
+       test_i18ngrep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
        echo "refs/heads/target2" >expect &&
        git symbolic-ref refs/heads/symref2 >actual &&
        test_cmp expect actual &&
index 30354fd26c0cf6b6e2a6c01bc2bcbef48168e562..5d955c3bff2ce9c276acd363f7c906565333da79 100755 (executable)
@@ -26,26 +26,22 @@ test_expect_success 'show-ref' '
        git show-ref refs/tags/A >actual &&
        test_cmp expect actual &&
 
-       >expect &&
-
        test_must_fail git show-ref D >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show-ref -q' '
-       >expect &&
-
        git show-ref -q A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        git show-ref -q tags/A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        git show-ref -q refs/tags/A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref -q D >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show-ref --verify' '
@@ -54,32 +50,28 @@ test_expect_success 'show-ref --verify' '
        git show-ref --verify refs/tags/A >actual &&
        test_cmp expect actual &&
 
-       >expect &&
-
        test_must_fail git show-ref --verify A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify tags/A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify D >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show-ref --verify -q' '
-       >expect &&
-
        git show-ref --verify -q refs/tags/A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify -q A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify -q tags/A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify -q D >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show-ref -d' '
@@ -113,19 +105,17 @@ test_expect_success 'show-ref -d' '
        git show-ref -d --verify refs/heads/master >actual &&
        test_cmp expect actual &&
 
-       >expect &&
-
        test_must_fail git show-ref -d --verify master >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref -d --verify heads/master >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify -d A C >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify -d tags/A tags/C >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
@@ -178,10 +168,8 @@ test_expect_success 'show-ref --verify HEAD' '
        git show-ref --verify HEAD >actual &&
        test_cmp expect actual &&
 
-       >expect &&
-
        git show-ref --verify -q HEAD >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show-ref --verify with dangling ref' '
index 3a887b511340b50a0cadcf1968a8c0986d67d66c..2a42a589a42cb9c086561be2df5540fa72af2ddf 100755 (executable)
@@ -27,7 +27,7 @@ test_update_rejected () {
        fi &&
        printf "create $prefix/%s $C\n" $create >input &&
        test_must_fail git update-ref --stdin <input 2>output.err &&
-       grep -F "$error" output.err &&
+       test_i18ngrep -F "$error" output.err &&
        git for-each-ref $prefix >actual &&
        test_cmp unchanged actual
 }
@@ -103,7 +103,7 @@ df_test() {
                printf "%s\n" "delete $delname" "create $addname $D"
        fi >commands &&
        test_must_fail git update-ref --stdin <commands 2>output.err &&
-       test_cmp expected-err output.err &&
+       test_i18ncmp expected-err output.err &&
        printf "%s\n" "$C $delref" >expected-refs &&
        git for-each-ref --format="%(objectname) %(refname)" $prefix/r >actual-refs &&
        test_cmp expected-refs actual-refs
index 553e26d9ceb83fc6529beb95ff71ffa0a899a166..8293131001ee0e816406df858dc47bc2fb9be3ce 100755 (executable)
@@ -339,8 +339,8 @@ test_expect_failure 'reflog with non-commit entries displays all entries' '
 '
 
 test_expect_success 'reflog expire operates on symref not referrent' '
-       git branch -l the_symref &&
-       git branch -l referrent &&
+       git branch --create-reflog the_symref &&
+       git branch --create-reflog referrent &&
        git update-ref referrent HEAD &&
        git symbolic-ref refs/heads/the_symref refs/heads/referrent &&
        test_when_finished "rm -f .git/refs/heads/referrent.lock" &&
index 91fd71444dbe40400b6608b56d51ae72e8ceafbc..7b7602ddb453de7104ae3c64a08c96e74b465aa4 100755 (executable)
@@ -372,7 +372,7 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
 
        test_might_fail git rev-list --verify-objects refs/heads/bogus >/dev/null 2>out &&
        cat out &&
-       grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out
+       test_i18ngrep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out
 '
 
 test_expect_success 'force fsck to ignore double author' '
index 349f6e10af9ea64a0e874b863f784feab4d12386..fa3e4996418d6d78afa31e9be19b6c77b22cd819 100755 (executable)
@@ -138,8 +138,7 @@ test_expect_success 'branch -d other@{u}' '
        git checkout -t -b other master &&
        git branch -d @{u} &&
        git for-each-ref refs/heads/master >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'checkout other@{u}' '
index 3e5ac81bd29bf6aded0d0fa643dca448a281d481..f79dfbbdd693b3fd7443d3c839e86e627663eb4b 100755 (executable)
@@ -23,6 +23,11 @@ test_branch_upstream () {
        test_cmp expect.upstream actual.upstream
 }
 
+status_uno_is_clean () {
+       git status -uno --porcelain >status.actual &&
+       test_must_be_empty status.actual
+}
+
 test_expect_success 'setup' '
        test_commit my_master &&
        git init repo_a &&
@@ -55,6 +60,7 @@ test_expect_success 'checkout of non-existing branch fails' '
        test_might_fail git branch -D xyzzy &&
 
        test_must_fail git checkout xyzzy &&
+       status_uno_is_clean &&
        test_must_fail git rev-parse --verify refs/heads/xyzzy &&
        test_branch master
 '
@@ -64,15 +70,47 @@ test_expect_success 'checkout of branch from multiple remotes fails #1' '
        test_might_fail git branch -D foo &&
 
        test_must_fail git checkout foo &&
+       status_uno_is_clean &&
        test_must_fail git rev-parse --verify refs/heads/foo &&
        test_branch master
 '
 
+test_expect_success 'checkout of branch from multiple remotes fails with advice' '
+       git checkout -B master &&
+       test_might_fail git branch -D foo &&
+       test_must_fail git checkout foo 2>stderr &&
+       test_branch master &&
+       status_uno_is_clean &&
+       test_i18ngrep "^hint: " stderr &&
+       test_must_fail git -c advice.checkoutAmbiguousRemoteBranchName=false \
+               checkout foo 2>stderr &&
+       test_branch master &&
+       status_uno_is_clean &&
+       test_i18ngrep ! "^hint: " stderr &&
+       # Make sure the likes of checkout -p do not print this hint
+       git checkout -p foo 2>stderr &&
+       test_i18ngrep ! "^hint: " stderr &&
+       status_uno_is_clean
+'
+
+test_expect_success 'checkout of branch from multiple remotes succeeds with checkout.defaultRemote #1' '
+       git checkout -B master &&
+       status_uno_is_clean &&
+       test_might_fail git branch -D foo &&
+
+       git -c checkout.defaultRemote=repo_a checkout foo &&
+       status_uno_is_clean &&
+       test_branch foo &&
+       test_cmp_rev remotes/repo_a/foo HEAD &&
+       test_branch_upstream foo repo_a foo
+'
+
 test_expect_success 'checkout of branch from a single remote succeeds #1' '
        git checkout -B master &&
        test_might_fail git branch -D bar &&
 
        git checkout bar &&
+       status_uno_is_clean &&
        test_branch bar &&
        test_cmp_rev remotes/repo_a/bar HEAD &&
        test_branch_upstream bar repo_a bar
@@ -83,6 +121,7 @@ test_expect_success 'checkout of branch from a single remote succeeds #2' '
        test_might_fail git branch -D baz &&
 
        git checkout baz &&
+       status_uno_is_clean &&
        test_branch baz &&
        test_cmp_rev remotes/other_b/baz HEAD &&
        test_branch_upstream baz repo_b baz
@@ -90,6 +129,7 @@ test_expect_success 'checkout of branch from a single remote succeeds #2' '
 
 test_expect_success '--no-guess suppresses branch auto-vivification' '
        git checkout -B master &&
+       status_uno_is_clean &&
        test_might_fail git branch -D bar &&
 
        test_must_fail git checkout --no-guess bar &&
@@ -99,6 +139,7 @@ test_expect_success '--no-guess suppresses branch auto-vivification' '
 
 test_expect_success 'setup more remotes with unconventional refspecs' '
        git checkout -B master &&
+       status_uno_is_clean &&
        git init repo_c &&
        (
                cd repo_c &&
@@ -128,27 +169,33 @@ test_expect_success 'setup more remotes with unconventional refspecs' '
 
 test_expect_success 'checkout of branch from multiple remotes fails #2' '
        git checkout -B master &&
+       status_uno_is_clean &&
        test_might_fail git branch -D bar &&
 
        test_must_fail git checkout bar &&
+       status_uno_is_clean &&
        test_must_fail git rev-parse --verify refs/heads/bar &&
        test_branch master
 '
 
 test_expect_success 'checkout of branch from multiple remotes fails #3' '
        git checkout -B master &&
+       status_uno_is_clean &&
        test_might_fail git branch -D baz &&
 
        test_must_fail git checkout baz &&
+       status_uno_is_clean &&
        test_must_fail git rev-parse --verify refs/heads/baz &&
        test_branch master
 '
 
 test_expect_success 'checkout of branch from a single remote succeeds #3' '
        git checkout -B master &&
+       status_uno_is_clean &&
        test_might_fail git branch -D spam &&
 
        git checkout spam &&
+       status_uno_is_clean &&
        test_branch spam &&
        test_cmp_rev refs/remotes/extra_dir/repo_c/extra_dir/spam HEAD &&
        test_branch_upstream spam repo_c spam
@@ -156,9 +203,11 @@ test_expect_success 'checkout of branch from a single remote succeeds #3' '
 
 test_expect_success 'checkout of branch from a single remote succeeds #4' '
        git checkout -B master &&
+       status_uno_is_clean &&
        test_might_fail git branch -D eggs &&
 
        git checkout eggs &&
+       status_uno_is_clean &&
        test_branch eggs &&
        test_cmp_rev refs/repo_d/eggs HEAD &&
        test_branch_upstream eggs repo_d eggs
@@ -166,32 +215,38 @@ test_expect_success 'checkout of branch from a single remote succeeds #4' '
 
 test_expect_success 'checkout of branch with a file having the same name fails' '
        git checkout -B master &&
+       status_uno_is_clean &&
        test_might_fail git branch -D spam &&
 
        >spam &&
        test_must_fail git checkout spam &&
+       status_uno_is_clean &&
        test_must_fail git rev-parse --verify refs/heads/spam &&
        test_branch master
 '
 
 test_expect_success 'checkout of branch with a file in subdir having the same name fails' '
        git checkout -B master &&
+       status_uno_is_clean &&
        test_might_fail git branch -D spam &&
 
        >spam &&
        mkdir sub &&
        mv spam sub/spam &&
        test_must_fail git -C sub checkout spam &&
+       status_uno_is_clean &&
        test_must_fail git rev-parse --verify refs/heads/spam &&
        test_branch master
 '
 
 test_expect_success 'checkout <branch> -- succeeds, even if a file with the same name exists' '
        git checkout -B master &&
+       status_uno_is_clean &&
        test_might_fail git branch -D spam &&
 
        >spam &&
        git checkout spam -- &&
+       status_uno_is_clean &&
        test_branch spam &&
        test_cmp_rev refs/remotes/extra_dir/repo_c/extra_dir/spam HEAD &&
        test_branch_upstream spam repo_c spam
@@ -200,6 +255,7 @@ test_expect_success 'checkout <branch> -- succeeds, even if a file with the same
 test_expect_success 'loosely defined local base branch is reported correctly' '
 
        git checkout master &&
+       status_uno_is_clean &&
        git branch strict &&
        git branch loose &&
        git commit --allow-empty -m "a bit more" &&
@@ -210,7 +266,9 @@ test_expect_success 'loosely defined local base branch is reported correctly' '
        test_config branch.loose.merge master &&
 
        git checkout strict | sed -e "s/strict/BRANCHNAME/g" >expect &&
+       status_uno_is_clean &&
        git checkout loose | sed -e "s/loose/BRANCHNAME/g" >actual &&
+       status_uno_is_clean &&
 
        test_cmp expect actual
 '
index d2e49f763263333e8e269051686d3b8b2cae44ba..166942c1bd2943b778b7df66e21d2e84861ef958 100755 (executable)
@@ -402,6 +402,26 @@ test_expect_success '"add" <path> <branch> dwims' '
        )
 '
 
+test_expect_success '"add" <path> <branch> dwims with checkout.defaultRemote' '
+       test_when_finished rm -rf repo_upstream repo_dwim foo &&
+       setup_remote_repo repo_upstream repo_dwim &&
+       git init repo_dwim &&
+       (
+               cd repo_dwim &&
+               git remote add repo_upstream2 ../repo_upstream &&
+               git fetch repo_upstream2 &&
+               test_must_fail git worktree add ../foo foo &&
+               git -c checkout.defaultRemote=repo_upstream worktree add ../foo foo &&
+               git status -uno --porcelain >status.actual &&
+               test_must_be_empty status.actual
+       ) &&
+       (
+               cd foo &&
+               test_branch_upstream foo repo_upstream foo &&
+               test_cmp_rev refs/remotes/repo_upstream/foo refs/heads/foo
+       )
+'
+
 test_expect_success 'git worktree add does not match remote' '
        test_when_finished rm -rf repo_a repo_b foo &&
        setup_remote_repo repo_a repo_b &&
index 17744e8c57b8adbe976e9abe5a8c8350429e4c19..9ee659098c45fbc18dfb5ccc2292f978320c1ebb 100755 (executable)
@@ -48,8 +48,7 @@ test_expect_success 'Just "git add" is a no-op' '
        >will-not-be-added &&
        git add &&
        git diff-index --name-status --cached HEAD >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_done
index 3fc484e8c3f8d910f02e409baf7bf1d5682b4f2f..3b47647ed56aa88b35227ef295e6a3432e5ab8f1 100755 (executable)
@@ -210,8 +210,7 @@ test_expect_success 'subdirectory ignore (toplevel)' '
                cd top &&
                git ls-files -o --exclude-standard
        ) >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'subdirectory ignore (l1/l2)' '
@@ -219,8 +218,7 @@ test_expect_success 'subdirectory ignore (l1/l2)' '
                cd top/l1/l2 &&
                git ls-files -o --exclude-standard
        ) >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'subdirectory ignore (l1)' '
@@ -228,8 +226,7 @@ test_expect_success 'subdirectory ignore (l1)' '
                cd top/l1 &&
                git ls-files -o --exclude-standard
        ) >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show/hide empty ignored directory (setup)' '
@@ -251,8 +248,7 @@ test_expect_success 'hide empty ignored directory with --no-empty-directory' '
                cd top &&
                git ls-files -o -i --exclude l1 --directory --no-empty-directory
        ) >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show/hide empty ignored sub-directory (setup)' '
@@ -277,8 +273,7 @@ test_expect_success 'hide empty ignored sub-directory with --no-empty-directory'
                cd top &&
                git ls-files -o -i --exclude l1 --directory --no-empty-directory
        ) >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'pattern matches prefix completely' '
index 377869432e9d0227c51836cedca8893394bb63e9..209b4c7cd8c6739d0bee566c7058419021ed1a45 100755 (executable)
@@ -44,13 +44,13 @@ test_expect_success 'ls-files -c' '
                cd top/sub &&
                for f in ../y*
                do
-                       echo "error: pathspec $sq$f$sq did not match any file(s) known to git."
+                       echo "error: pathspec $sq$f$sq did not match any file(s) known to git"
                done >expect.err &&
                echo "Did you forget to ${sq}git add${sq}?" >>expect.err &&
                ls ../x* >expect.out &&
                test_must_fail git ls-files -c --error-unmatch ../[xy]* >actual.out 2>actual.err &&
                test_cmp expect.out actual.out &&
-               test_cmp expect.err actual.err
+               test_i18ncmp expect.err actual.err
        )
 '
 
@@ -59,13 +59,13 @@ test_expect_success 'ls-files -o' '
                cd top/sub &&
                for f in ../x*
                do
-                       echo "error: pathspec $sq$f$sq did not match any file(s) known to git."
+                       echo "error: pathspec $sq$f$sq did not match any file(s) known to git"
                done >expect.err &&
                echo "Did you forget to ${sq}git add${sq}?" >>expect.err &&
                ls ../y* >expect.out &&
                test_must_fail git ls-files -o --error-unmatch ../[xy]* >actual.out 2>actual.err &&
                test_cmp expect.out actual.out &&
-               test_cmp expect.err actual.err
+               test_i18ncmp expect.err actual.err
        )
 '
 
index e59b0a32d67ec86074059eee7a64c4b7bae6c145..3824756a02ec31c228e2eeda92fc13a33b1e4b75 100755 (executable)
@@ -88,7 +88,7 @@ test_expect_success 'setup repo with criss-cross history' '
        git branch G
 '
 
-test_expect_success 'recursive merge between F and G, causes segfault' '
+test_expect_success 'recursive merge between F and G does not cause segfault' '
        git merge F
 '
 
diff --git a/t/t3035-merge-sparse.sh b/t/t3035-merge-sparse.sh
new file mode 100755 (executable)
index 0000000..0c0b433
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+test_description='merge with sparse files'
+
+. ./test-lib.sh
+
+# test_file $filename $content
+test_file () {
+       echo "$2" > "$1" &&
+       git add "$1"
+}
+
+# test_commit_this $message_and_tag
+test_commit_this () {
+       git commit -m "$1" &&
+       git tag "$1"
+}
+
+test_expect_success 'setup' '
+       : >empty &&
+       test_file checked-out init &&
+       test_file modify_delete modify_delete_init &&
+       test_commit_this init &&
+       test_file modify_delete modify_delete_theirs &&
+       test_commit_this theirs &&
+       git reset --hard init &&
+       git rm modify_delete &&
+       test_commit_this ours &&
+       git config core.sparseCheckout true &&
+       echo "/checked-out" >.git/info/sparse-checkout &&
+       git reset --hard &&
+       ! git merge theirs
+'
+
+test_expect_success 'reset --hard works after the conflict' '
+       git reset --hard
+'
+
+test_expect_success 'is reset properly' '
+       git status --porcelain -- modify_delete >out &&
+       test_cmp empty out &&
+       test_path_is_missing modify_delete
+'
+
+test_expect_success 'setup: conflict back' '
+       ! git merge theirs
+'
+
+test_expect_success 'Merge abort works after the conflict' '
+       git merge --abort
+'
+
+test_expect_success 'is aborted properly' '
+       git status --porcelain -- modify_delete >out &&
+       test_cmp empty out &&
+       test_path_is_missing modify_delete
+'
+
+test_done
index dce102130fb77ddda7cdc9aa9211507d9c2f2e09..46aca0af102e863f8c46f160d3f2022aee5ba29e 100755 (executable)
@@ -101,8 +101,7 @@ match_with_ls_files() {
 
        match_stdout_stderr_cmp="
                tr -d '\0' <actual.raw >actual &&
-               >expect.err &&
-               test_cmp expect.err actual.err &&
+               test_must_be_empty actual.err &&
                test_cmp expect actual"
 
        if test "$match_expect" = 'E'
index 08467982f61fd81f0614711b52b9806f2497f3eb..dbca665da41908e7e3014564dc8ddb901030715b 100755 (executable)
@@ -49,9 +49,9 @@ test_expect_success 'git branch HEAD should fail' '
 cat >expect <<EOF
 $ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000    branch: Created from master
 EOF
-test_expect_success 'git branch -l d/e/f should create a branch and a log' '
+test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
        GIT_COMMITTER_DATE="2005-05-26 23:30" \
-       git branch -l d/e/f &&
+       git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
        test_path_is_file .git/refs/heads/d/e/f &&
        test_path_is_file .git/logs/refs/heads/d/e/f &&
        test_cmp expect .git/logs/refs/heads/d/e/f
@@ -82,7 +82,7 @@ test_expect_success 'git branch -m dumps usage' '
 
 test_expect_success 'git branch -m m broken_symref should work' '
        test_when_finished "git branch -D broken_symref" &&
-       git branch -l m &&
+       git branch --create-reflog m &&
        git symbolic-ref refs/heads/broken_symref refs/heads/i_am_broken &&
        git branch -m m broken_symref &&
        git reflog exists refs/heads/broken_symref &&
@@ -90,13 +90,13 @@ test_expect_success 'git branch -m m broken_symref should work' '
 '
 
 test_expect_success 'git branch -m m m/m should work' '
-       git branch -l m &&
+       git branch --create-reflog m &&
        git branch -m m m/m &&
        git reflog exists refs/heads/m/m
 '
 
 test_expect_success 'git branch -m n/n n should work' '
-       git branch -l n/n &&
+       git branch --create-reflog n/n &&
        git branch -m n/n n &&
        git reflog exists refs/heads/n
 '
@@ -378,9 +378,9 @@ mv .git/config-saved .git/config
 git config branch.s/s.dummy Hello
 
 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
-       git branch -l s/s &&
+       git branch --create-reflog s/s &&
        git reflog exists refs/heads/s/s &&
-       git branch -l s/t &&
+       git branch --create-reflog s/t &&
        git reflog exists refs/heads/s/t &&
        git branch -d s/t &&
        git branch -m s/s s &&
@@ -444,7 +444,7 @@ test_expect_success 'git branch --copy dumps usage' '
 '
 
 test_expect_success 'git branch -c d e should work' '
-       git branch -l d &&
+       git branch --create-reflog d &&
        git reflog exists refs/heads/d &&
        git config branch.d.dummy Hello &&
        git branch -c d e &&
@@ -459,7 +459,7 @@ test_expect_success 'git branch -c d e should work' '
 '
 
 test_expect_success 'git branch --copy is a synonym for -c' '
-       git branch -l copy &&
+       git branch --create-reflog copy &&
        git reflog exists refs/heads/copy &&
        git config branch.copy.dummy Hello &&
        git branch --copy copy copy-to &&
@@ -486,7 +486,7 @@ test_expect_success 'git branch -c ee ef should copy ee to create branch ef' '
 '
 
 test_expect_success 'git branch -c f/f g/g should work' '
-       git branch -l f/f &&
+       git branch --create-reflog f/f &&
        git reflog exists refs/heads/f/f &&
        git config branch.f/f.dummy Hello &&
        git branch -c f/f g/g &&
@@ -497,7 +497,7 @@ test_expect_success 'git branch -c f/f g/g should work' '
 '
 
 test_expect_success 'git branch -c m2 m2 should work' '
-       git branch -l m2 &&
+       git branch --create-reflog m2 &&
        git reflog exists refs/heads/m2 &&
        git config branch.m2.dummy Hello &&
        git branch -c m2 m2 &&
@@ -506,18 +506,18 @@ test_expect_success 'git branch -c m2 m2 should work' '
 '
 
 test_expect_success 'git branch -c zz zz/zz should fail' '
-       git branch -l zz &&
+       git branch --create-reflog zz &&
        git reflog exists refs/heads/zz &&
        test_must_fail git branch -c zz zz/zz
 '
 
 test_expect_success 'git branch -c b/b b should fail' '
-       git branch -l b/b &&
+       git branch --create-reflog b/b &&
        test_must_fail git branch -c b/b b
 '
 
 test_expect_success 'git branch -C o/q o/p should work when o/p exists' '
-       git branch -l o/q &&
+       git branch --create-reflog o/q &&
        git reflog exists refs/heads/o/q &&
        git reflog exists refs/heads/o/p &&
        git branch -C o/q o/p
@@ -570,10 +570,10 @@ test_expect_success 'git branch -C master5 master5 should work when master is ch
 '
 
 test_expect_success 'git branch -C ab cd should overwrite existing config for cd' '
-       git branch -l cd &&
+       git branch --create-reflog cd &&
        git reflog exists refs/heads/cd &&
        git config branch.cd.dummy CD &&
-       git branch -l ab &&
+       git branch --create-reflog ab &&
        git reflog exists refs/heads/ab &&
        git config branch.ab.dummy AB &&
        git branch -C ab cd &&
@@ -685,7 +685,7 @@ test_expect_success 'renaming a symref is not allowed' '
 '
 
 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
-       git branch -l u &&
+       git branch --create-reflog u &&
        mv .git/logs/refs/heads/u real-u &&
        ln -s real-u .git/logs/refs/heads/u &&
        test_must_fail git branch -m u v
index 0ef1b6fdcc420d6fac2cbe0abd5f1ec6ebec90c6..0ea4fc46949daf8d9522ff9ae52d8583ca5e9754 100755 (executable)
@@ -48,16 +48,14 @@ test_expect_success 'branch --contains master' '
 test_expect_success 'branch --no-contains=master' '
 
        git branch --no-contains=master >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
 test_expect_success 'branch --no-contains master' '
 
        git branch --no-contains master >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
@@ -94,8 +92,7 @@ test_expect_success 'branch --contains with pattern implies --list' '
 test_expect_success 'branch --no-contains with pattern implies --list' '
 
        git branch --no-contains=master master >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
@@ -123,8 +120,7 @@ test_expect_success 'branch --merged with pattern implies --list' '
 test_expect_success 'side: branch --no-merged' '
 
        git branch --no-merged >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
@@ -152,8 +148,7 @@ test_expect_success 'master: branch --no-merged' '
 test_expect_success 'branch --no-merged with pattern implies --list' '
 
        git branch --no-merged=master master >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh
new file mode 100755 (executable)
index 0000000..2237c7f
--- /dev/null
@@ -0,0 +1,145 @@
+#!/bin/sh
+
+test_description='range-diff tests'
+
+. ./test-lib.sh
+
+# Note that because of the range-diff's heuristics, test_commit does more
+# harm than good.  We need some real history.
+
+test_expect_success 'setup' '
+       git fast-import < "$TEST_DIRECTORY"/t3206/history.export
+'
+
+test_expect_success 'simple A..B A..C (unmodified)' '
+       git range-diff --no-color master..topic master..unmodified \
+               >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  35b9b25 s/5/A/
+       2:  fccce22 = 2:  de345ab s/4/A/
+       3:  147e64e = 3:  9af6654 s/11/B/
+       4:  a63e992 = 4:  2901f77 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'simple B...C (unmodified)' '
+       git range-diff --no-color topic...unmodified >actual &&
+       # same "expected" as above
+       test_cmp expected actual
+'
+
+test_expect_success 'simple A B C (unmodified)' '
+       git range-diff --no-color master topic unmodified >actual &&
+       # same "expected" as above
+       test_cmp expected actual
+'
+
+test_expect_success 'trivial reordering' '
+       git range-diff --no-color master topic reordered >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  aca177a s/5/A/
+       3:  147e64e = 2:  14ad629 s/11/B/
+       4:  a63e992 = 3:  ee58208 s/12/B/
+       2:  fccce22 = 4:  307b27a s/4/A/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'removed a commit' '
+       git range-diff --no-color master topic removed >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  7657159 s/5/A/
+       2:  fccce22 < -:  ------- s/4/A/
+       3:  147e64e = 2:  43d84d3 s/11/B/
+       4:  a63e992 = 3:  a740396 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'added a commit' '
+       git range-diff --no-color master topic added >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  2716022 s/5/A/
+       2:  fccce22 = 2:  b62accd s/4/A/
+       -:  ------- > 3:  df46cfa s/6/A/
+       3:  147e64e = 4:  3e64548 s/11/B/
+       4:  a63e992 = 5:  12b4063 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'new base, A B C' '
+       git range-diff --no-color master topic rebased >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  cc9c443 s/5/A/
+       2:  fccce22 = 2:  c5d9641 s/4/A/
+       3:  147e64e = 3:  28cc2b6 s/11/B/
+       4:  a63e992 = 4:  5628ab7 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'new base, B...C' '
+       # this syntax includes the commits from master!
+       git range-diff --no-color topic...rebased >actual &&
+       cat >expected <<-EOF &&
+       -:  ------- > 1:  a31b12e unrelated
+       1:  4de457d = 2:  cc9c443 s/5/A/
+       2:  fccce22 = 3:  c5d9641 s/4/A/
+       3:  147e64e = 4:  28cc2b6 s/11/B/
+       4:  a63e992 = 5:  5628ab7 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'changed commit' '
+       git range-diff --no-color topic...changed >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  a4b3333 s/5/A/
+       2:  fccce22 = 2:  f51d370 s/4/A/
+       3:  147e64e ! 3:  0559556 s/11/B/
+           @@ -10,7 +10,7 @@
+             9
+             10
+            -11
+           -+B
+           ++BB
+             12
+             13
+             14
+       4:  a63e992 ! 4:  d966c5c s/12/B/
+           @@ -8,7 +8,7 @@
+            @@
+             9
+             10
+           - B
+           + BB
+            -12
+            +B
+             13
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'changed message' '
+       git range-diff --no-color topic...changed-message >actual &&
+       sed s/Z/\ /g >expected <<-EOF &&
+       1:  4de457d = 1:  f686024 s/5/A/
+       2:  fccce22 ! 2:  4ab067d s/4/A/
+           @@ -2,6 +2,8 @@
+           Z
+           Z    s/4/A/
+           Z
+           +    Also a silly comment here!
+           +
+           Zdiff --git a/file b/file
+           Z--- a/file
+           Z+++ b/file
+       3:  147e64e = 3:  b9cb956 s/11/B/
+       4:  a63e992 = 4:  8add5f1 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_done
diff --git a/t/t3206/history.export b/t/t3206/history.export
new file mode 100644 (file)
index 0000000..b8ffff0
--- /dev/null
@@ -0,0 +1,604 @@
+blob
+mark :1
+data 51
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+reset refs/heads/removed
+commit refs/heads/removed
+mark :2
+author Thomas Rast <trast@inf.ethz.ch> 1374424921 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374484724 +0200
+data 8
+initial
+M 100644 :1 file
+
+blob
+mark :3
+data 51
+1
+2
+3
+4
+A
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/topic
+mark :4
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+blob
+mark :5
+data 51
+1
+2
+3
+A
+A
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/topic
+mark :6
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+data 7
+s/4/A/
+from :4
+M 100644 :5 file
+
+blob
+mark :7
+data 50
+1
+2
+3
+A
+A
+6
+7
+8
+9
+10
+B
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/topic
+mark :8
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+data 8
+s/11/B/
+from :6
+M 100644 :7 file
+
+blob
+mark :9
+data 49
+1
+2
+3
+A
+A
+6
+7
+8
+9
+10
+B
+B
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/topic
+mark :10
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+data 8
+s/12/B/
+from :8
+M 100644 :9 file
+
+blob
+mark :11
+data 10
+unrelated
+
+commit refs/heads/master
+mark :12
+author Thomas Rast <trast@inf.ethz.ch> 1374485127 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485127 +0200
+data 10
+unrelated
+from :2
+M 100644 :11 otherfile
+
+commit refs/heads/rebased
+mark :13
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485137 +0200
+data 7
+s/5/A/
+from :12
+M 100644 :3 file
+
+commit refs/heads/rebased
+mark :14
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485138 +0200
+data 7
+s/4/A/
+from :13
+M 100644 :5 file
+
+commit refs/heads/rebased
+mark :15
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485138 +0200
+data 8
+s/11/B/
+from :14
+M 100644 :7 file
+
+commit refs/heads/rebased
+mark :16
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485138 +0200
+data 8
+s/12/B/
+from :15
+M 100644 :9 file
+
+commit refs/heads/added
+mark :17
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+commit refs/heads/added
+mark :18
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
+data 7
+s/4/A/
+from :17
+M 100644 :5 file
+
+blob
+mark :19
+data 51
+1
+2
+3
+A
+A
+A
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/added
+mark :20
+author Thomas Rast <trast@inf.ethz.ch> 1374485186 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
+data 7
+s/6/A/
+from :18
+M 100644 :19 file
+
+blob
+mark :21
+data 50
+1
+2
+3
+A
+A
+A
+7
+8
+9
+10
+B
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/added
+mark :22
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
+data 8
+s/11/B/
+from :20
+M 100644 :21 file
+
+blob
+mark :23
+data 49
+1
+2
+3
+A
+A
+A
+7
+8
+9
+10
+B
+B
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/added
+mark :24
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
+data 8
+s/12/B/
+from :22
+M 100644 :23 file
+
+commit refs/heads/reordered
+mark :25
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+blob
+mark :26
+data 50
+1
+2
+3
+4
+A
+6
+7
+8
+9
+10
+B
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/reordered
+mark :27
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
+data 8
+s/11/B/
+from :25
+M 100644 :26 file
+
+blob
+mark :28
+data 49
+1
+2
+3
+4
+A
+6
+7
+8
+9
+10
+B
+B
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/reordered
+mark :29
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
+data 8
+s/12/B/
+from :27
+M 100644 :28 file
+
+commit refs/heads/reordered
+mark :30
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
+data 7
+s/4/A/
+from :29
+M 100644 :9 file
+
+commit refs/heads/changed
+mark :31
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+commit refs/heads/changed
+mark :32
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
+data 7
+s/4/A/
+from :31
+M 100644 :5 file
+
+blob
+mark :33
+data 51
+1
+2
+3
+A
+A
+6
+7
+8
+9
+10
+BB
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/changed
+mark :34
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
+data 8
+s/11/B/
+from :32
+M 100644 :33 file
+
+blob
+mark :35
+data 50
+1
+2
+3
+A
+A
+6
+7
+8
+9
+10
+BB
+B
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/changed
+mark :36
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
+data 8
+s/12/B/
+from :34
+M 100644 :35 file
+
+commit refs/heads/changed-message
+mark :37
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485530 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+commit refs/heads/changed-message
+mark :38
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485530 +0200
+data 35
+s/4/A/
+
+Also a silly comment here!
+from :37
+M 100644 :5 file
+
+commit refs/heads/changed-message
+mark :39
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485536 +0200
+data 8
+s/11/B/
+from :38
+M 100644 :7 file
+
+commit refs/heads/changed-message
+mark :40
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485536 +0200
+data 8
+s/12/B/
+from :39
+M 100644 :9 file
+
+commit refs/heads/unmodified
+mark :41
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485631 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+commit refs/heads/unmodified
+mark :42
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485631 +0200
+data 7
+s/4/A/
+from :41
+M 100644 :5 file
+
+commit refs/heads/unmodified
+mark :43
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485632 +0200
+data 8
+s/11/B/
+from :42
+M 100644 :7 file
+
+commit refs/heads/unmodified
+mark :44
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485632 +0200
+data 8
+s/12/B/
+from :43
+M 100644 :9 file
+
+commit refs/heads/removed
+mark :45
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374486061 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+commit refs/heads/removed
+mark :46
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374486061 +0200
+data 8
+s/11/B/
+from :45
+M 100644 :26 file
+
+commit refs/heads/removed
+mark :47
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374486061 +0200
+data 8
+s/12/B/
+from :46
+M 100644 :28 file
+
+reset refs/heads/removed
+from :47
+
index 724b4b9bc037a229ec4fae9d6e49e0cf47188070..7333d7d5459179ab306d29fc04e7d088d75412af 100755 (executable)
@@ -186,7 +186,7 @@ test_expect_success 'notice d/f conflict with existing directory' '
 
 test_expect_success 'existing directory reports concrete ref' '
        test_must_fail git branch foo 2>stderr &&
-       grep refs/heads/foo/bar/baz stderr
+       test_i18ngrep refs/heads/foo/bar/baz stderr
 '
 
 test_expect_success 'notice d/f conflict with existing ref' '
index 9c1bf6eb3d46f31c0e1816508dcc8fee4699f823..68436eed82101cdfcc7f93fea0681083b546cf2a 100755 (executable)
@@ -541,9 +541,9 @@ EOF
        test "$(git rev-parse refs/notes/y)" = "$(git rev-parse NOTES_MERGE_PARTIAL^1)" &&
        test "$(git rev-parse refs/notes/m)" != "$(git rev-parse NOTES_MERGE_PARTIAL^1)" &&
        # Mention refs/notes/m, and its current and expected value in output
-       grep -q "refs/notes/m" output &&
-       grep -q "$(git rev-parse refs/notes/m)" output &&
-       grep -q "$(git rev-parse NOTES_MERGE_PARTIAL^1)" output &&
+       test_i18ngrep -q "refs/notes/m" output &&
+       test_i18ngrep -q "$(git rev-parse refs/notes/m)" output &&
+       test_i18ngrep -q "$(git rev-parse NOTES_MERGE_PARTIAL^1)" output &&
        # Verify that other notes refs has not changed (w, x, y and z)
        verify_notes w &&
        verify_notes x &&
diff --git a/t/t3401-rebase-and-am-rename.sh b/t/t3401-rebase-and-am-rename.sh
new file mode 100755 (executable)
index 0000000..8f83295
--- /dev/null
@@ -0,0 +1,105 @@
+#!/bin/sh
+
+test_description='git rebase + directory rename tests'
+
+. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-rebase.sh
+
+test_expect_success 'setup testcase' '
+       test_create_repo dir-rename &&
+       (
+               cd dir-rename &&
+
+               mkdir x &&
+               test_seq  1 10 >x/a &&
+               test_seq 11 20 >x/b &&
+               test_seq 21 30 >x/c &&
+               test_write_lines a b c d e f g h i >l &&
+               git add x l &&
+               git commit -m "Initial" &&
+
+               git branch O &&
+               git branch A &&
+               git branch B &&
+
+               git checkout A &&
+               git mv x y &&
+               git mv l letters &&
+               git commit -m "Rename x to y, l to letters" &&
+
+               git checkout B &&
+               echo j >>l &&
+               test_seq 31 40 >x/d &&
+               git add l x/d &&
+               git commit -m "Modify l, add x/d"
+       )
+'
+
+test_expect_success 'rebase --interactive: directory rename detected' '
+       (
+               cd dir-rename &&
+
+               git checkout B^0 &&
+
+               set_fake_editor &&
+               FAKE_LINES="1" git rebase --interactive A &&
+
+               git ls-files -s >out &&
+               test_line_count = 5 out &&
+
+               test_path_is_file y/d &&
+               test_path_is_missing x/d
+       )
+'
+
+test_expect_failure 'rebase (am): directory rename detected' '
+       (
+               cd dir-rename &&
+
+               git checkout B^0 &&
+
+               git rebase A &&
+
+               git ls-files -s >out &&
+               test_line_count = 5 out &&
+
+               test_path_is_file y/d &&
+               test_path_is_missing x/d
+       )
+'
+
+test_expect_success 'rebase --merge: directory rename detected' '
+       (
+               cd dir-rename &&
+
+               git checkout B^0 &&
+
+               git rebase --merge A &&
+
+               git ls-files -s >out &&
+               test_line_count = 5 out &&
+
+               test_path_is_file y/d &&
+               test_path_is_missing x/d
+       )
+'
+
+test_expect_failure 'am: directory rename detected' '
+       (
+               cd dir-rename &&
+
+               git checkout A^0 &&
+
+               git format-patch -1 B &&
+
+               git am --3way 0001*.patch &&
+
+               git ls-files -s >out &&
+               test_line_count = 5 out &&
+
+               test_path_is_file y/d &&
+               test_path_is_missing x/d
+       )
+'
+
+test_done
index 85e99aac1342b4b6a7b0458354f6b721ce7f1b6c..4c7b1ea3563274c7c3551e417c819b70200e90e9 100755 (executable)
@@ -119,6 +119,15 @@ test_expect_success 'rebase -i with exec allows git commands in subdirs' '
        )
 '
 
+test_expect_success 'rebase -i sets work tree properly' '
+       test_when_finished "rm -rf subdir" &&
+       test_when_finished "test_might_fail git rebase --abort" &&
+       mkdir subdir &&
+       git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \
+               >actual &&
+       ! grep "/subdir$" actual
+'
+
 test_expect_success 'rebase -i with the exec command checks tree cleanness' '
        git checkout master &&
        set_fake_editor &&
@@ -264,11 +273,18 @@ test_expect_success 'retain authorship' '
 '
 
 test_expect_success 'retain authorship w/ conflicts' '
+       oGIT_AUTHOR_NAME=$GIT_AUTHOR_NAME &&
+       test_when_finished "GIT_AUTHOR_NAME=\$oGIT_AUTHOR_NAME" &&
+
        git reset --hard twerp &&
        test_commit a conflict a conflict-a &&
        git reset --hard twerp &&
-       GIT_AUTHOR_NAME=AttributeMe \
+
+       GIT_AUTHOR_NAME=AttributeMe &&
+       export GIT_AUTHOR_NAME &&
        test_commit b conflict b conflict-b &&
+       GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME &&
+
        set_fake_editor &&
        test_must_fail git rebase -i conflict-a &&
        echo resolved >conflict &&
@@ -553,15 +569,16 @@ test_expect_success '--continue tries to commit, even for "edit"' '
 '
 
 test_expect_success 'aborted --continue does not squash commits after "edit"' '
+       test_when_finished "git rebase --abort" &&
        old=$(git rev-parse HEAD) &&
        test_tick &&
        set_fake_editor &&
        FAKE_LINES="edit 1" git rebase -i HEAD^ &&
        echo "edited again" > file7 &&
        git add file7 &&
-       test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue &&
-       test $old = $(git rev-parse HEAD) &&
-       git rebase --abort
+       echo all the things >>conflict &&
+       test_must_fail git rebase --continue &&
+       test $old = $(git rev-parse HEAD)
 '
 
 test_expect_success 'auto-amend only edited commits after "edit"' '
@@ -981,7 +998,35 @@ test_expect_success 'rebase -i --root reword root commit' '
        test -z "$(git show -s --format=%p HEAD^)"
 '
 
+test_expect_success 'rebase -i --root when root has untracked file confilct' '
+       test_when_finished "reset_rebase" &&
+       git checkout -b failing-root-pick A &&
+       echo x >file2 &&
+       git rm file1 &&
+       git commit -m "remove file 1 add file 2" &&
+       echo z >file1 &&
+       set_fake_editor &&
+       test_must_fail env FAKE_LINES="1 2" git rebase -i --root &&
+       rm file1 &&
+       git rebase --continue &&
+       test "$(git log -1 --format=%B)" = "remove file 1 add file 2" &&
+       test "$(git rev-list --count HEAD)" = 2
+'
+
+test_expect_success 'rebase -i --root reword root when root has untracked file conflict' '
+       test_when_finished "reset_rebase" &&
+       echo z>file1 &&
+       set_fake_editor &&
+       test_must_fail env FAKE_LINES="reword 1 2" \
+               FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root &&
+       rm file1 &&
+       FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue &&
+       test "$(git log -1 --format=%B HEAD^)" = "Reworded A" &&
+       test "$(git rev-list --count HEAD)" = 2
+'
+
 test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' '
+       git checkout reword-root-branch &&
        git reset --hard &&
        git checkout conflict-branch &&
        set_fake_editor &&
@@ -1202,7 +1247,7 @@ rebase_setup_and_clean () {
                test_might_fail git branch -D $1 &&
                test_might_fail git rebase --abort
        " &&
-       git checkout -b $1 master
+       git checkout -b $1 ${2:-master}
 }
 
 test_expect_success 'drop' '
@@ -1379,4 +1424,12 @@ test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
        test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
 '
 
+test_expect_success 'valid author header after --root swap' '
+       rebase_setup_and_clean author-header no-conflict-branch &&
+       set_fake_editor &&
+       FAKE_LINES="2 1" git rebase -i --root &&
+       git cat-file commit HEAD^ >out &&
+       grep "^author ..*> [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$" out
+'
+
 test_done
index cb7c6de84abf88bf90ac9716bb24ac91b8f64bf9..da94dddc86d78830664d3a4b910ab157c2db2f0f 100755 (executable)
@@ -77,19 +77,14 @@ test_expect_success 'rebase commit with diff in message' '
 '
 
 test_expect_success 'rebase -m commit with empty message' '
-       test_must_fail git rebase -m master empty-message-merge &&
-       git rebase --abort &&
-       git rebase -m --allow-empty-message master empty-message-merge
+       git rebase -m master empty-message-merge
 '
 
 test_expect_success 'rebase -i commit with empty message' '
        git checkout diff-in-message &&
        set_fake_editor &&
-       test_must_fail env FAKE_COMMIT_MESSAGE=" " FAKE_LINES="reword 1" \
-               git rebase -i HEAD^ &&
-       git rebase --abort &&
-       FAKE_COMMIT_MESSAGE=" " FAKE_LINES="reword 1" \
-               git rebase -i --allow-empty-message HEAD^
+       env FAKE_COMMIT_MESSAGE=" " FAKE_LINES="reword 1" \
+               git rebase -i HEAD^
 '
 
 test_done
index 853e015839fce0cb2cb50eb6b08aef0dcb24adb3..65ed7db1592d97ae7120e028bc6023446e973a4a 100755 (executable)
@@ -74,6 +74,38 @@ test_expect_success 'rebase --continue remembers merge strategy and options' '
        test -f funny.was.run
 '
 
+test_expect_success 'rebase -i --continue handles merge strategy and options' '
+       rm -fr .git/rebase-* &&
+       git reset --hard commit-new-file-F2-on-topic-branch &&
+       test_commit "commit-new-file-F3-on-topic-branch-for-dash-i" F3 32 &&
+       test_when_finished "rm -fr test-bin funny.was.run funny.args" &&
+       mkdir test-bin &&
+       cat >test-bin/git-merge-funny <<-EOF &&
+       #!$SHELL_PATH
+       echo "\$@" >>funny.args
+       case "\$1" in --opt) ;; *) exit 2 ;; esac
+       case "\$2" in --foo) ;; *) exit 2 ;; esac
+       case "\$4" in --) ;; *) exit 2 ;; esac
+       shift 2 &&
+       >funny.was.run &&
+       exec git merge-recursive "\$@"
+       EOF
+       chmod +x test-bin/git-merge-funny &&
+       (
+               PATH=./test-bin:$PATH &&
+               test_must_fail git rebase -i -s funny -Xopt -Xfoo master topic
+       ) &&
+       test -f funny.was.run &&
+       rm funny.was.run &&
+       echo "Resolved" >F2 &&
+       git add F2 &&
+       (
+               PATH=./test-bin:$PATH &&
+               git rebase --continue
+       ) &&
+       test -f funny.was.run
+'
+
 test_expect_success 'rebase passes merge strategy options correctly' '
        rm -fr .git/rebase-* &&
        git reset --hard commit-new-file-F3-on-topic-branch &&
diff --git a/t/t3422-rebase-incompatible-options.sh b/t/t3422-rebase-incompatible-options.sh
new file mode 100755 (executable)
index 0000000..bb78a6e
--- /dev/null
@@ -0,0 +1,88 @@
+#!/bin/sh
+
+test_description='test if rebase detects and aborts on incompatible options'
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       test_seq 2 9 >foo &&
+       git add foo &&
+       git commit -m orig &&
+
+       git branch A &&
+       git branch B &&
+
+       git checkout A &&
+       test_seq 1 9 >foo &&
+       git add foo &&
+       git commit -m A &&
+
+       git checkout B &&
+       echo "q qfoo();" | q_to_tab >>foo &&
+       git add foo &&
+       git commit -m B
+'
+
+#
+# Rebase has lots of useful options like --whitepsace=fix, which are
+# actually all built in terms of flags to git-am.  Since neither
+# --merge nor --interactive (nor any options that imply those two) use
+# git-am, using them together will result in flags like --whitespace=fix
+# being ignored.  Make sure rebase warns the user and aborts instead.
+#
+
+test_rebase_am_only () {
+       opt=$1
+       shift
+       test_expect_success "$opt incompatible with --merge" "
+               git checkout B^0 &&
+               test_must_fail git rebase $opt --merge A
+       "
+
+       test_expect_success "$opt incompatible with --strategy=ours" "
+               git checkout B^0 &&
+               test_must_fail git rebase $opt --strategy=ours A
+       "
+
+       test_expect_success "$opt incompatible with --strategy-option=ours" "
+               git checkout B^0 &&
+               test_must_fail git rebase $opt --strategy-option=ours A
+       "
+
+       test_expect_success "$opt incompatible with --interactive" "
+               git checkout B^0 &&
+               test_must_fail git rebase $opt --interactive A
+       "
+
+       test_expect_success "$opt incompatible with --exec" "
+               git checkout B^0 &&
+               test_must_fail git rebase $opt --exec 'true' A
+       "
+
+}
+
+test_rebase_am_only --whitespace=fix
+test_rebase_am_only --ignore-whitespace
+test_rebase_am_only --committer-date-is-author-date
+test_rebase_am_only -C4
+
+test_expect_success '--preserve-merges incompatible with --signoff' '
+       git checkout B^0 &&
+       test_must_fail git rebase --preserve-merges --signoff A
+'
+
+test_expect_success '--preserve-merges incompatible with --rebase-merges' '
+       git checkout B^0 &&
+       test_must_fail git rebase --preserve-merges --rebase-merges A
+'
+
+test_expect_success '--rebase-merges incompatible with --strategy' '
+       git checkout B^0 &&
+       test_must_fail git rebase --rebase-merges -s resolve A
+'
+
+test_expect_success '--rebase-merges incompatible with --strategy-option' '
+       git checkout B^0 &&
+       test_must_fail git rebase --rebase-merges -Xignore-space-change A
+'
+
+test_done
diff --git a/t/t3423-rebase-reword.sh b/t/t3423-rebase-reword.sh
new file mode 100755 (executable)
index 0000000..6963750
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+test_description='git rebase interactive with rewording'
+
+. ./test-lib.sh
+
+. "$TEST_DIRECTORY"/lib-rebase.sh
+
+test_expect_success 'setup' '
+       test_commit master file-1 test &&
+
+       git checkout -b stuff &&
+
+       test_commit feature_a file-2 aaa &&
+       test_commit feature_b file-2 ddd
+'
+
+test_expect_success 'reword without issues functions as intended' '
+       test_when_finished "reset_rebase" &&
+
+       git checkout stuff^0 &&
+
+       set_fake_editor &&
+       FAKE_LINES="pick 1 reword 2" FAKE_COMMIT_MESSAGE="feature_b_reworded" \
+               git rebase -i -v master &&
+
+       test "$(git log -1 --format=%B)" = "feature_b_reworded" &&
+       test $(git rev-list --count HEAD) = 3
+'
+
+test_expect_success 'reword after a conflict preserves commit' '
+       test_when_finished "reset_rebase" &&
+
+       git checkout stuff^0 &&
+
+       set_fake_editor &&
+       test_must_fail env FAKE_LINES="reword 2" \
+               git rebase -i -v master &&
+
+       git checkout --theirs file-2 &&
+       git add file-2 &&
+       FAKE_COMMIT_MESSAGE="feature_b_reworded" git rebase --continue &&
+
+       test "$(git log -1 --format=%B)" = "feature_b_reworded" &&
+       test $(git rev-list --count HEAD) = 2
+'
+
+test_done
index 78f7c9958030bee8d8040eda0380ba5af16d0441..90ae613e23fb5bbbde638c25dd052d398169fba6 100755 (executable)
@@ -329,4 +329,55 @@ test_expect_success 'labels that are object IDs are rewritten' '
        ! grep "^label $third$" .git/ORIGINAL-TODO
 '
 
+test_expect_success 'octopus merges' '
+       git checkout -b three &&
+       test_commit before-octopus &&
+       test_commit three &&
+       git checkout -b two HEAD^ &&
+       test_commit two &&
+       git checkout -b one HEAD^ &&
+       test_commit one &&
+       test_tick &&
+       (GIT_AUTHOR_NAME="Hank" GIT_AUTHOR_EMAIL="hank@sea.world" \
+        git merge -m "Tüntenfüsch" two three) &&
+
+       : fast forward if possible &&
+       before="$(git rev-parse --verify HEAD)" &&
+       test_tick &&
+       git rebase -i -r HEAD^^ &&
+       test_cmp_rev HEAD $before &&
+
+       test_tick &&
+       git rebase -i --force -r HEAD^^ &&
+       test "Hank" = "$(git show -s --format=%an HEAD)" &&
+       test "$before" != $(git rev-parse HEAD) &&
+       test_cmp_graph HEAD^^.. <<-\EOF
+       *-.   Tüntenfüsch
+       |\ \
+       | | * three
+       | * | two
+       | |/
+       * | one
+       |/
+       o before-octopus
+       EOF
+'
+
+test_expect_success 'with --autosquash and --exec' '
+       git checkout -b with-exec H &&
+       echo Booh >B.t &&
+       test_tick &&
+       git commit --fixup B B.t &&
+       write_script show.sh <<-\EOF &&
+       subject="$(git show -s --format=%s HEAD)"
+       content="$(git diff HEAD^! | tail -n 1)"
+       echo "$subject: $content"
+       EOF
+       test_tick &&
+       git rebase -ir --autosquash --exec ./show.sh A >actual &&
+       grep "B: +Booh" actual &&
+       grep "E: +Booh" actual &&
+       grep "G: +G" actual
+'
+
 test_done
index 7c5ad086264e3d1c140da7fd996f27c1352a26a9..0db166152ab9eafee7a34421c1100029bda485eb 100755 (executable)
@@ -392,4 +392,17 @@ test_expect_success 'commit --amend -s places the sign-off at the right place' '
        test_cmp expect actual
 '
 
+test_expect_success 'cherry-pick preserves sparse-checkout' '
+       pristine_detach initial &&
+       test_config core.sparseCheckout true &&
+       test_when_finished "
+               echo \"/*\" >.git/info/sparse-checkout
+               git read-tree --reset -u HEAD
+               rm .git/info/sparse-checkout" &&
+       echo /unrelated >.git/info/sparse-checkout &&
+       git read-tree --reset -u HEAD &&
+       test_must_fail git cherry-pick -Xours picked>actual &&
+       test_i18ngrep ! "Changes not staged for commit:" actual
+'
+
 test_done
index b42cd66d3a574138148a311b34472506b433c286..3505b6aa14e630a98062558ed30270c98e5a920f 100755 (executable)
@@ -480,11 +480,16 @@ test_expect_success 'malformed instruction sheet 2' '
        test_expect_code 128 git cherry-pick --continue
 '
 
-test_expect_success 'empty commit set' '
+test_expect_success 'empty commit set (no commits to walk)' '
        pristine_detach initial &&
        test_expect_code 128 git cherry-pick base..base
 '
 
+test_expect_success 'empty commit set (culled during walk)' '
+       pristine_detach initial &&
+       test_expect_code 128 git cherry-pick -2 --author=no.such.author base
+'
+
 test_expect_success 'malformed instruction sheet 3' '
        pristine_detach initial &&
        test_expect_code 1 git cherry-pick base..anotherpick &&
index 618750167aed8d99a57b2642713d12406cd2e5f6..37729ba2582119047d559d22df8c522f9c0ab0f1 100755 (executable)
@@ -188,9 +188,8 @@ test_expect_success 'git add --refresh with pathspec' '
        git add foo bar baz && H=$(git rev-parse :foo) && git rm -f foo &&
        echo "100644 $H 3       foo" | git update-index --index-info &&
        test-tool chmtime -60 bar baz &&
-       >expect &&
        git add --refresh bar >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        git diff-files --name-only >actual &&
        ! grep bar actual&&
index 26dd5b7f78a7f7e65ddda24c4686d2ae26fc30de..54ce19e353d924de08d4242f519fef7a44ce4787 100755 (executable)
@@ -187,9 +187,8 @@ test_expect_failure 'handle existing decomposed filenames' '
        echo content >"verbatim.$Adiarnfd" &&
        git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" &&
        git commit -m "existing decomposed file" &&
-       >expect &&
        git ls-files --exclude-standard -o "verbatim*" >untracked &&
-       test_cmp expect untracked
+       test_must_be_empty untracked
 '
 
 # Test if the global core.precomposeunicode stops autosensing
index b7f25071cfb24408f43634d016ac785bba282614..281f8fad0c71687aecec7479328ce8609cda5c83 100755 (executable)
@@ -74,8 +74,7 @@ test_expect_success 'diff-tree pathspec' '
        tree2=$(git write-tree) &&
        echo "$tree2" &&
        git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
-       >expected &&
-       test_cmp expected current
+       test_must_be_empty current
 '
 
 test_expect_success 'diff-tree with wildcard shows dir also matches' '
index 028d5507a6b684208ba82292379ec74bc6628574..53880da7bbe85521112ced3ff94ead05587c7e81 100755 (executable)
@@ -1554,13 +1554,15 @@ test_expect_success 'format-patch -o overrides format.outputDirectory' '
 
 test_expect_success 'format-patch --base' '
        git checkout side &&
-       git format-patch --stdout --base=HEAD~3 -1 | tail -n 7 >actual &&
+       git format-patch --stdout --base=HEAD~3 -1 | tail -n 7 >actual1 &&
+       git format-patch --stdout --base=HEAD~3 HEAD~.. | tail -n 7 >actual2 &&
        echo >expected &&
        echo "base-commit: $(git rev-parse HEAD~3)" >>expected &&
        echo "prerequisite-patch-id: $(git show --patch HEAD~2 | git patch-id --stable | awk "{print \$1}")" >>expected &&
        echo "prerequisite-patch-id: $(git show --patch HEAD~1 | git patch-id --stable | awk "{print \$1}")" >>expected &&
        signature >> expected &&
-       test_cmp expected actual
+       test_cmp expected actual1 &&
+       test_cmp expected actual2
 '
 
 test_expect_success 'format-patch --base errors out when base commit is in revision list' '
index 17df491a3abe84fca63bb899d1162832d13e1847..35fc8b5c2aa559a40000588f9a1e2b86215cb6ef 100755 (executable)
@@ -93,21 +93,20 @@ test_expect_success 'another test, without options' '
        git diff >out &&
        test_cmp expect out &&
 
-       >expect &&
        git diff -w >out &&
-       test_cmp expect out &&
+       test_must_be_empty out &&
 
        git diff -w -b >out &&
-       test_cmp expect out &&
+       test_must_be_empty out &&
 
        git diff -w --ignore-space-at-eol >out &&
-       test_cmp expect out &&
+       test_must_be_empty out &&
 
        git diff -w -b --ignore-space-at-eol >out &&
-       test_cmp expect out &&
+       test_must_be_empty out &&
 
        git diff -w --ignore-cr-at-eol >out &&
-       test_cmp expect out &&
+       test_must_be_empty out &&
 
        tr "Q_" "\015 " <<-\EOF >expect &&
        diff --git a/x b/x
@@ -182,8 +181,7 @@ test_expect_success 'ignore-blank-lines: only new lines' '
        test_seq 5 | sed "/3/i\\
 " >x &&
        git diff --ignore-blank-lines >out &&
-       >expect &&
-       test_cmp expect out
+       test_must_be_empty out
 '
 
 test_expect_success 'ignore-blank-lines: only new lines with space' '
@@ -192,8 +190,7 @@ test_expect_success 'ignore-blank-lines: only new lines with space' '
        test_seq 5 | sed "/3/i\\
  " >x &&
        git diff -w --ignore-blank-lines >out &&
-       >expect &&
-       test_cmp expect out
+       test_must_be_empty out
 '
 
 test_expect_success 'ignore-blank-lines: after change' '
@@ -1223,7 +1220,7 @@ test_expect_success 'plain moved code, inside file' '
        test_cmp expected actual
 '
 
-test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
+test_expect_success 'detect blocks of moved code' '
        git reset --hard &&
        cat <<-\EOF >lines.txt &&
                long line 1
@@ -1271,9 +1268,52 @@ test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
        test_config color.diff.newMovedDimmed "normal cyan" &&
        test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
        test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
-       git diff HEAD --no-renames --color-moved=dimmed_zebra --color |
-               grep -v "index" |
-               test_decode_color >actual &&
+       git diff HEAD --no-renames --color-moved=blocks --color >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
+       cat <<-\EOF >expected &&
+       <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
+       <BOLD>--- a/lines.txt<RESET>
+       <BOLD>+++ b/lines.txt<RESET>
+       <CYAN>@@ -1,16 +1,16 @@<RESET>
+       <MAGENTA>-long line 1<RESET>
+       <MAGENTA>-long line 2<RESET>
+       <MAGENTA>-long line 3<RESET>
+        line 4<RESET>
+        line 5<RESET>
+        line 6<RESET>
+        line 7<RESET>
+        line 8<RESET>
+        line 9<RESET>
+       <CYAN>+<RESET><CYAN>long line 1<RESET>
+       <CYAN>+<RESET><CYAN>long line 2<RESET>
+       <CYAN>+<RESET><CYAN>long line 3<RESET>
+       <CYAN>+<RESET><CYAN>long line 14<RESET>
+       <CYAN>+<RESET><CYAN>long line 15<RESET>
+       <CYAN>+<RESET><CYAN>long line 16<RESET>
+        line 10<RESET>
+        line 11<RESET>
+        line 12<RESET>
+        line 13<RESET>
+       <MAGENTA>-long line 14<RESET>
+       <MAGENTA>-long line 15<RESET>
+       <MAGENTA>-long line 16<RESET>
+       EOF
+       test_cmp expected actual
+
+'
+
+test_expect_success 'detect permutations inside moved code -- dimmed-zebra' '
+       # reuse setup from test before!
+       test_config color.diff.oldMoved "magenta" &&
+       test_config color.diff.newMoved "cyan" &&
+       test_config color.diff.oldMovedAlternative "blue" &&
+       test_config color.diff.newMovedAlternative "yellow" &&
+       test_config color.diff.oldMovedDimmed "normal magenta" &&
+       test_config color.diff.newMovedDimmed "normal cyan" &&
+       test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
+       test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
+       git diff HEAD --no-renames --color-moved=dimmed-zebra --color >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@ -1315,9 +1355,8 @@ test_expect_success 'cmd option assumes configured colored-moved' '
        test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
        test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
        test_config diff.colorMoved zebra &&
-       git diff HEAD --no-renames --color-moved --color |
-               grep -v "index" |
-               test_decode_color >actual &&
+       git diff HEAD --no-renames --color-moved --color >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@ -1395,9 +1434,8 @@ test_expect_success 'move detection ignoring whitespace ' '
        line 4
        line 5
        EOF
-       git diff HEAD --no-renames --color-moved --color |
-               grep -v "index" |
-               test_decode_color >actual &&
+       git diff HEAD --no-renames --color-moved --color >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@ -1419,9 +1457,9 @@ test_expect_success 'move detection ignoring whitespace ' '
        EOF
        test_cmp expected actual &&
 
-       git diff HEAD --no-renames -w --color-moved --color |
-               grep -v "index" |
-               test_decode_color >actual &&
+       git diff HEAD --no-renames --color-moved --color \
+               --color-moved-ws=ignore-all-space >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@ -1459,9 +1497,8 @@ test_expect_success 'move detection ignoring whitespace changes' '
        line 5
        EOF
 
-       git diff HEAD --no-renames --color-moved --color |
-               grep -v "index" |
-               test_decode_color >actual &&
+       git diff HEAD --no-renames --color-moved --color >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@ -1483,9 +1520,9 @@ test_expect_success 'move detection ignoring whitespace changes' '
        EOF
        test_cmp expected actual &&
 
-       git diff HEAD --no-renames -b --color-moved --color |
-               grep -v "index" |
-               test_decode_color >actual &&
+       git diff HEAD --no-renames --color-moved --color \
+               --color-moved-ws=ignore-space-change >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@ -1526,9 +1563,8 @@ test_expect_success 'move detection ignoring whitespace at eol' '
        # avoid cluttering the output with complaints about our eol whitespace
        test_config core.whitespace -blank-at-eol &&
 
-       git diff HEAD --no-renames --color-moved --color |
-               grep -v "index" |
-               test_decode_color >actual &&
+       git diff HEAD --no-renames --color-moved --color >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@ -1550,9 +1586,9 @@ test_expect_success 'move detection ignoring whitespace at eol' '
        EOF
        test_cmp expected actual &&
 
-       git diff HEAD --no-renames --ignore-space-at-eol --color-moved --color |
-               grep -v "index" |
-               test_decode_color >actual &&
+       git diff HEAD --no-renames --color-moved --color \
+               --color-moved-ws=ignore-space-at-eol >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@ -1597,9 +1633,8 @@ test_expect_success '--color-moved block at end of diff output respects MIN_ALNU
        irrelevant_line
        EOF
 
-       git diff HEAD --color-moved=zebra --color --no-renames |
-               grep -v "index" |
-               test_decode_color >actual &&
+       git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
        cat >expected <<-\EOF &&
        <BOLD>diff --git a/bar b/bar<RESET>
        <BOLD>--- a/bar<RESET>
@@ -1636,9 +1671,8 @@ test_expect_success '--color-moved respects MIN_ALNUM_COUNT' '
        nineteen chars 456789
        EOF
 
-       git diff HEAD --color-moved=zebra --color --no-renames |
-               grep -v "index" |
-               test_decode_color >actual &&
+       git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
        cat >expected <<-\EOF &&
        <BOLD>diff --git a/bar b/bar<RESET>
        <BOLD>--- a/bar<RESET>
@@ -1679,7 +1713,8 @@ test_expect_success '--color-moved treats adjacent blocks as separate for MIN_AL
        7charsA
        EOF
 
-       git diff HEAD --color-moved=zebra --color --no-renames | grep -v "index" | test_decode_color >actual &&
+       git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
        cat >expected <<-\EOF &&
        <BOLD>diff --git a/bar b/bar<RESET>
        <BOLD>--- a/bar<RESET>
@@ -1722,7 +1757,146 @@ test_expect_success 'move detection with submodules' '
 
        # nor did we mess with it another way
        git diff --submodule=diff --color | test_decode_color >expect &&
-       test_cmp expect decoded_actual
+       test_cmp expect decoded_actual &&
+       rm -rf bananas &&
+       git submodule deinit bananas
+'
+
+test_expect_success 'only move detection ignores white spaces' '
+       git reset --hard &&
+       q_to_tab <<-\EOF >text.txt &&
+               a long line to exceed per-line minimum
+               another long line to exceed per-line minimum
+               original file
+       EOF
+       git add text.txt &&
+       git commit -m "add text" &&
+       q_to_tab <<-\EOF >text.txt &&
+               Qa long line to exceed per-line minimum
+               Qanother long line to exceed per-line minimum
+               new file
+       EOF
+
+       # Make sure we get a different diff using -w
+       git diff --color --color-moved -w >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
+       q_to_tab <<-\EOF >expected &&
+       <BOLD>diff --git a/text.txt b/text.txt<RESET>
+       <BOLD>--- a/text.txt<RESET>
+       <BOLD>+++ b/text.txt<RESET>
+       <CYAN>@@ -1,3 +1,3 @@<RESET>
+        Qa long line to exceed per-line minimum<RESET>
+        Qanother long line to exceed per-line minimum<RESET>
+       <RED>-original file<RESET>
+       <GREEN>+<RESET><GREEN>new file<RESET>
+       EOF
+       test_cmp expected actual &&
+
+       # And now ignoring white space only in the move detection
+       git diff --color --color-moved \
+               --color-moved-ws=ignore-all-space,ignore-space-change,ignore-space-at-eol >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
+       q_to_tab <<-\EOF >expected &&
+       <BOLD>diff --git a/text.txt b/text.txt<RESET>
+       <BOLD>--- a/text.txt<RESET>
+       <BOLD>+++ b/text.txt<RESET>
+       <CYAN>@@ -1,3 +1,3 @@<RESET>
+       <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>
+       <GREEN>+<RESET><GREEN>new file<RESET>
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'compare whitespace delta across moved blocks' '
+
+       git reset --hard &&
+       q_to_tab <<-\EOF >text.txt &&
+       QIndented
+       QText across
+       Qsome lines
+       QBut! <- this stands out
+       QAdjusting with
+       QQdifferent starting
+       Qwhite spaces
+       QAnother outlier
+       QQQIndented
+       QQQText across
+       QQQfive lines
+       QQQthat has similar lines
+       QQQto previous blocks, but with different indent
+       QQQYetQAnotherQoutlierQ
+       EOF
+
+       git add text.txt &&
+       git commit -m "add text.txt" &&
+
+       q_to_tab <<-\EOF >text.txt &&
+       QQIndented
+       QQText across
+       QQsome lines
+       QQQBut! <- this stands out
+       Adjusting with
+       Qdifferent starting
+       white spaces
+       AnotherQoutlier
+       QQIndented
+       QQText across
+       QQfive lines
+       QQthat has similar lines
+       QQto previous blocks, but with different indent
+       QQYetQAnotherQoutlier
+       EOF
+
+       git diff --color --color-moved --color-moved-ws=allow-indentation-change >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
+
+       q_to_tab <<-\EOF >expected &&
+               <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>
+               <BOLD;MAGENTA>-QIndented<RESET>
+               <BOLD;MAGENTA>-QText across<RESET>
+               <BOLD;MAGENTA>-Qsome lines<RESET>
+               <RED>-QBut! <- this stands out<RESET>
+               <BOLD;MAGENTA>-QAdjusting with<RESET>
+               <BOLD;MAGENTA>-QQdifferent starting<RESET>
+               <BOLD;MAGENTA>-Qwhite spaces<RESET>
+               <RED>-QAnother outlier<RESET>
+               <BOLD;MAGENTA>-QQQIndented<RESET>
+               <BOLD;MAGENTA>-QQQText across<RESET>
+               <BOLD;MAGENTA>-QQQfive lines<RESET>
+               <BOLD;MAGENTA>-QQQthat has similar lines<RESET>
+               <BOLD;MAGENTA>-QQQto previous blocks, but with different indent<RESET>
+               <RED>-QQQYetQAnotherQoutlierQ<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>
+               <GREEN>+<RESET>QQQ<GREEN>But! <- this stands out<RESET>
+               <BOLD;CYAN>+<RESET><BOLD;CYAN>Adjusting with<RESET>
+               <BOLD;CYAN>+<RESET>Q<BOLD;CYAN>different starting<RESET>
+               <BOLD;CYAN>+<RESET><BOLD;CYAN>white spaces<RESET>
+               <GREEN>+<RESET><GREEN>AnotherQoutlier<RESET>
+               <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Indented<RESET>
+               <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Text across<RESET>
+               <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>five lines<RESET>
+               <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>
+       EOF
+
+       test_cmp expected actual
+'
+
+test_expect_success 'compare whitespace delta incompatible with other space options' '
+       test_must_fail git diff \
+               --color-moved-ws=allow-indentation-change,ignore-all-space \
+               2>err &&
+       test_i18ngrep allow-indentation-change err
 '
 
 test_done
diff --git a/t/t4018/php-abstract-class b/t/t4018/php-abstract-class
new file mode 100644 (file)
index 0000000..5213e12
--- /dev/null
@@ -0,0 +1,4 @@
+abstract class RIGHT
+{
+    const FOO = 'ChangeMe';
+}
diff --git a/t/t4018/php-class b/t/t4018/php-class
new file mode 100644 (file)
index 0000000..7785b63
--- /dev/null
@@ -0,0 +1,4 @@
+class RIGHT
+{
+    const FOO = 'ChangeMe';
+}
diff --git a/t/t4018/php-final-class b/t/t4018/php-final-class
new file mode 100644 (file)
index 0000000..69f5710
--- /dev/null
@@ -0,0 +1,4 @@
+final class RIGHT
+{
+    const FOO = 'ChangeMe';
+}
diff --git a/t/t4018/php-function b/t/t4018/php-function
new file mode 100644 (file)
index 0000000..35717c5
--- /dev/null
@@ -0,0 +1,4 @@
+function RIGHT()
+{
+    return 'ChangeMe';
+}
diff --git a/t/t4018/php-interface b/t/t4018/php-interface
new file mode 100644 (file)
index 0000000..86b49ad
--- /dev/null
@@ -0,0 +1,4 @@
+interface RIGHT
+{
+    public function foo($ChangeMe);
+}
diff --git a/t/t4018/php-method b/t/t4018/php-method
new file mode 100644 (file)
index 0000000..03af1a6
--- /dev/null
@@ -0,0 +1,7 @@
+class Klass
+{
+    public static function RIGHT()
+    {
+        return 'ChangeMe';
+    }
+}
diff --git a/t/t4018/php-trait b/t/t4018/php-trait
new file mode 100644 (file)
index 0000000..65b8c82
--- /dev/null
@@ -0,0 +1,7 @@
+trait RIGHT
+{
+    public function foo($ChangeMe)
+    {
+        return 'foo';
+    }
+}
index 23c0e357a765f00d807938fccf81a250c371ec4f..53ac44b0f0036803b48979c3c5f343ca02b1b80a 100755 (executable)
@@ -34,9 +34,8 @@ test_expect_success POSIXPERM 'find-copies-harder is not confused by mode bits'
        git add exec &&
        git commit -m exec &&
        git update-index --assume-unchanged exec &&
-       >expect &&
        git diff-files --find-copies-harder -- exec >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_done
index 1ebc587f8fc0010713f52196206462fa915cbca5..01867a989885e1272e998df54375b74438a8059e 100755 (executable)
@@ -69,13 +69,15 @@ test_expect_success 'setup: messages' '
 
        EOF
 
-       cat >scissors-msg <<-\EOF &&
-       Test git-am with scissors line
+       cat >msg-without-scissors-line <<-\EOF &&
+       Test that git-am --scissors cuts at the scissors line
 
        This line should be included in the commit message.
        EOF
 
-       cat - scissors-msg >no-scissors-msg <<-\EOF &&
+       printf "Subject: " >subject-prefix &&
+
+       cat - subject-prefix msg-without-scissors-line >msg-with-scissors-line <<-\EOF &&
        This line should not be included in the commit message with --scissors enabled.
 
         - - >8 - - remove everything above this line - - >8 - -
@@ -148,18 +150,17 @@ test_expect_success setup '
        } >patch1-hg.eml &&
 
 
-       echo scissors-file >scissors-file &&
-       git add scissors-file &&
-       git commit -F scissors-msg &&
-       git tag scissors &&
-       git format-patch --stdout scissors^ >scissors-patch.eml &&
+       echo file >file &&
+       git add file &&
+       git commit -F msg-without-scissors-line &&
+       git tag expected-for-scissors &&
        git reset --hard HEAD^ &&
 
-       echo no-scissors-file >no-scissors-file &&
-       git add no-scissors-file &&
-       git commit -F no-scissors-msg &&
-       git tag no-scissors &&
-       git format-patch --stdout no-scissors^ >no-scissors-patch.eml &&
+       echo file >file &&
+       git add file &&
+       git commit -F msg-with-scissors-line &&
+       git tag expected-for-no-scissors &&
+       git format-patch --stdout expected-for-no-scissors^ >patch-with-scissors-line.eml &&
        git reset --hard HEAD^ &&
 
        sed -n -e "3,\$p" msg >file &&
@@ -416,10 +417,10 @@ test_expect_success 'am --scissors cuts the message at the scissors line' '
        rm -fr .git/rebase-apply &&
        git reset --hard &&
        git checkout second &&
-       git am --scissors scissors-patch.eml &&
+       git am --scissors patch-with-scissors-line.eml &&
        test_path_is_missing .git/rebase-apply &&
-       git diff --exit-code scissors &&
-       test_cmp_rev scissors HEAD
+       git diff --exit-code expected-for-scissors &&
+       test_cmp_rev expected-for-scissors HEAD
 '
 
 test_expect_success 'am --no-scissors overrides mailinfo.scissors' '
@@ -427,10 +428,10 @@ test_expect_success 'am --no-scissors overrides mailinfo.scissors' '
        git reset --hard &&
        git checkout second &&
        test_config mailinfo.scissors true &&
-       git am --no-scissors no-scissors-patch.eml &&
+       git am --no-scissors patch-with-scissors-line.eml &&
        test_path_is_missing .git/rebase-apply &&
-       git diff --exit-code no-scissors &&
-       test_cmp_rev no-scissors HEAD
+       git diff --exit-code expected-for-no-scissors &&
+       test_cmp_rev expected-for-no-scissors HEAD
 '
 
 test_expect_success 'setup: new author and committer' '
index 8417e5a4b105a54a8de23af8bae2bdaf28c257cb..65da74c76683c0ccd109fdec63766ab6bdfb08f0 100755 (executable)
@@ -267,8 +267,7 @@ rerere_gc_custom_expiry_test () {
                git -c "gc.rerereresolved=$right_now" \
                    -c "gc.rerereunresolved=$right_now" rerere gc &&
                find .git/rr-cache -type f | sort >actual &&
-               >expect &&
-               test_cmp expect actual
+               test_must_be_empty actual
        '
 }
 
@@ -536,9 +535,8 @@ test_expect_success 'multiple identical conflicts' '
 
        # We resolved file1 and file2
        git rerere &&
-       >expect &&
        git rerere remaining >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        # We must have recorded both of them
        count_pre_post 2 2 &&
@@ -548,9 +546,8 @@ test_expect_success 'multiple identical conflicts' '
        test_must_fail git merge six.1 &&
        git rerere &&
 
-       >expect &&
        git rerere remaining >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        concat_insert short 6.1 6.2 >file1.expect &&
        concat_insert long 6.1 6.2 >file2.expect &&
index 25b1f8cc73bc35bedaaffeacbb75a1329d725c3b..153a506151e2afe3f1e047cd5a00270f1378ce14 100755 (executable)
@@ -340,10 +340,9 @@ test_expect_success PCRE 'log -F -E --perl-regexp --grep=<pcre> uses PCRE' '
 '
 
 test_expect_success 'log with grep.patternType configuration' '
-       >expect &&
        git -c grep.patterntype=fixed \
        log -1 --pretty=tformat:%s --grep=s.c.nd >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'log with grep.patternType configuration and command line' '
@@ -1556,12 +1555,28 @@ test_expect_success GPG 'setup signed branch' '
        git commit -S -m signed_commit
 '
 
+test_expect_success GPGSM 'setup signed branch x509' '
+       test_when_finished "git reset --hard && git checkout master" &&
+       git checkout -b signed-x509 master &&
+       echo foo >foo &&
+       git add foo &&
+       test_config gpg.format x509 &&
+       test_config user.signingkey $GIT_COMMITTER_EMAIL &&
+       git commit -S -m signed_commit
+'
+
 test_expect_success GPG 'log --graph --show-signature' '
        git log --graph --show-signature -n1 signed >actual &&
        grep "^| gpg: Signature made" actual &&
        grep "^| gpg: Good signature" actual
 '
 
+test_expect_success GPGSM 'log --graph --show-signature x509' '
+       git log --graph --show-signature -n1 signed-x509 >actual &&
+       grep "^| gpgsm: Signature made" actual &&
+       grep "^| gpgsm: Good signature" actual
+'
+
 test_expect_success GPG 'log --graph --show-signature for merged tag' '
        test_when_finished "git reset --hard && git checkout master" &&
        git checkout -b plain master &&
@@ -1581,6 +1596,27 @@ test_expect_success GPG 'log --graph --show-signature for merged tag' '
        grep "^| | gpg: Good signature" actual
 '
 
+test_expect_success GPGSM 'log --graph --show-signature for merged tag x509' '
+       test_when_finished "git reset --hard && git checkout master" &&
+       test_config gpg.format x509 &&
+       test_config user.signingkey $GIT_COMMITTER_EMAIL &&
+       git checkout -b plain-x509 master &&
+       echo aaa >bar &&
+       git add bar &&
+       git commit -m bar_commit &&
+       git checkout -b tagged-x509 master &&
+       echo bbb >baz &&
+       git add baz &&
+       git commit -m baz_commit &&
+       git tag -s -m signed_tag_msg signed_tag_x509 &&
+       git checkout plain-x509 &&
+       git merge --no-ff -m msg signed_tag_x509 &&
+       git log --graph --show-signature -n1 plain-x509 >actual &&
+       grep "^|\\\  merged tag" actual &&
+       grep "^| | gpgsm: Signature made" actual &&
+       grep "^| | gpgsm: Good signature" actual
+'
+
 test_expect_success GPG '--no-show-signature overrides --show-signature' '
        git log -1 --show-signature --no-show-signature signed >actual &&
        ! grep "^gpg:" actual
@@ -1625,9 +1661,8 @@ test_expect_success 'log diagnoses bogus HEAD' '
 '
 
 test_expect_success 'log does not default to HEAD when rev input is given' '
-       >expect &&
        git log --branches=does-not-exist >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'set up --source tests' '
index 62f335b2d9fe7268f8f6cd878067de8528b5cb75..4c8f3b8e1bdd084a6407d76ff26cff0048e90bdf 100755 (executable)
@@ -25,6 +25,32 @@ test_expect_success '"git log :/a -- " should not be ambiguous' '
        git log :/a --
 '
 
+test_expect_success '"git log :/detached -- " should find a commit only in HEAD' '
+       test_when_finished "git checkout master" &&
+       git checkout --detach &&
+       # Must manually call `test_tick` instead of using `test_commit`,
+       # because the latter additionally creates a tag, which would make
+       # the commit reachable not only via HEAD.
+       test_tick &&
+       git commit --allow-empty -m detached &&
+       test_tick &&
+       git commit --allow-empty -m something-else &&
+       git log :/detached --
+'
+
+test_expect_success '"git log :/detached -- " should not find an orphaned commit' '
+       test_must_fail git log :/detached --
+'
+
+test_expect_success '"git log :/detached -- " should find HEAD only of own worktree' '
+       git worktree add other-tree HEAD &&
+       git -C other-tree checkout --detach &&
+       test_tick &&
+       git -C other-tree commit --allow-empty -m other-detached &&
+       git -C other-tree log :/other-detached -- &&
+       test_must_fail git log :/other-detached --
+'
+
 test_expect_success '"git log -- :/a" should not be ambiguous' '
        git log -- :/a
 '
index e585fe6129b7af264427d8af46de21cb08efad7f..7c519436ef3d2ed4843d173948c8fcac1069cffe 100755 (executable)
@@ -44,15 +44,13 @@ test_expect_success !MINGW 'log --grep searches in log output encoding (latin1)'
 '
 
 test_expect_success !MINGW 'log --grep does not find non-reencoded values (utf8)' '
-       >expect &&
        git log --encoding=utf8 --format=%s --grep=$latin1_e >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'log --grep does not find non-reencoded values (latin1)' '
-       >expect &&
        git log --encoding=ISO-8859-1 --format=%s --grep=$utf8_e >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_done
index d0377fae5c832bcd4df37f3bc2ab4a8708f70251..436b13ad21d06351ef9f9a027689a7e23ca97ba5 100755 (executable)
@@ -60,7 +60,6 @@ test_bad_opts "-L 1:nonexistent" "There is no path"
 test_bad_opts "-L 1:simple" "There is no path"
 test_bad_opts "-L '/foo:b.c'" "argument not .start,end:file"
 test_bad_opts "-L 1000:b.c" "has only.*lines"
-test_bad_opts "-L 1,1000:b.c" "has only.*lines"
 test_bad_opts "-L :b.c" "argument not .start,end:file"
 test_bad_opts "-L :foo:b.c" "no match"
 
@@ -86,12 +85,12 @@ test_expect_success '-L ,Y (Y == nlines)' '
 
 test_expect_success '-L ,Y (Y == nlines + 1)' '
        n=$(expr $(wc -l <b.c) + 1) &&
-       test_must_fail git log -L ,$n:b.c
+       git log -L ,$n:b.c
 '
 
 test_expect_success '-L ,Y (Y == nlines + 2)' '
        n=$(expr $(wc -l <b.c) + 2) &&
-       test_must_fail git log -L ,$n:b.c
+       git log -L ,$n:b.c
 '
 
 test_expect_success '-L with --first-parent and a merge' '
index 2d22a17c4a7f9dcc402e89e73ce01c97ebd4ba48..557bd0d0c09e370515acb7fc75391f0a7d62d73e 100755 (executable)
@@ -9,7 +9,8 @@ objpath () {
 
 # show objects present in pack ($1 should be associated *.idx)
 list_packed_objects () {
-       git show-index <"$1" | cut -d' ' -f2
+       git show-index <"$1" >object-list &&
+       cut -d' ' -f2 object-list
 }
 
 # has_any pattern-file content-file
@@ -204,8 +205,8 @@ test_expect_success 'pack-objects to file can use bitmap' '
        # verify equivalent packs are generated with/without using bitmap index
        packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
        packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
-       list_packed_objects <packa-$packasha1.idx >packa.objects &&
-       list_packed_objects <packb-$packbsha1.idx >packb.objects &&
+       list_packed_objects packa-$packasha1.idx >packa.objects &&
+       list_packed_objects packb-$packbsha1.idx >packb.objects &&
        test_cmp packa.objects packb.objects
 '
 
@@ -309,9 +310,8 @@ test_expect_success 'pack reuse respects --honor-pack-keep' '
        done &&
        reusable_pack --honor-pack-keep >empty.pack &&
        git index-pack empty.pack &&
-       >expect &&
        git show-index <empty.idx >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'pack reuse respects --local' '
@@ -319,17 +319,15 @@ test_expect_success 'pack reuse respects --local' '
        test_when_finished "mv alt.git/objects/pack/* .git/objects/pack/" &&
        reusable_pack --local >empty.pack &&
        git index-pack empty.pack &&
-       >expect &&
        git show-index <empty.idx >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'pack reuse respects --incremental' '
        reusable_pack --incremental >empty.pack &&
        git index-pack empty.pack &&
-       >expect &&
        git show-index <empty.idx >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'truncated bitmap fails gracefully' '
index 4fe4ad9d6166d9a82cb944fadfc0317b5052b973..f1708d415e55c25be441ae47f865fbe7f5973c93 100755 (executable)
@@ -90,9 +90,8 @@ test_expect_success 'matched bogus object count' '
 
        # Unlike above, we should notice early that the .idx is totally
        # bogus, and not even enumerate its contents.
-       >expect &&
        git cat-file --batch-all-objects --batch-check >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        # But as before, we can do the same object-access checks.
        test_must_fail git cat-file blob $object &&
index 1b0acc383bb216a3f420cd19ff066275a5b4706e..6710c8bc8c4699035bec418258fcaec8a634855c 100755 (executable)
@@ -160,6 +160,22 @@ test_expect_success 'verify blob:limit=1k' '
        test_cmp observed expected
 '
 
+test_expect_success 'verify explicitly specifying oversized blob in input' '
+       git -C r2 ls-files -s large.1000 large.10000 \
+               | awk -f print_2.awk \
+               | sort >expected &&
+       git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
+       HEAD
+       $(git -C r2 rev-parse HEAD:large.10000)
+       EOF
+       git -C r2 index-pack ../filter.pack &&
+       git -C r2 verify-pack -v ../filter.pack \
+               | grep blob \
+               | awk -f print_1.awk \
+               | sort >observed &&
+       test_cmp observed expected
+'
+
 test_expect_success 'verify blob:limit=1m' '
        git -C r2 ls-files -s large.1000 large.10000 \
                | awk -f print_2.awk \
index 77d85aefe7da18a0d7cc2db2baaedacead6b2e97..3c1ffad49144d177a56f2f6a0b26612899e25adb 100755 (executable)
@@ -11,6 +11,11 @@ test_expect_success 'setup full repo' '
        objdir=".git/objects"
 '
 
+test_expect_success 'verify graph with no graph file' '
+       cd "$TRASH_DIRECTORY/full" &&
+       git commit-graph verify
+'
+
 test_expect_success 'write graph with no packs' '
        cd "$TRASH_DIRECTORY/full" &&
        git commit-graph write --object-dir . &&
@@ -28,8 +33,8 @@ test_expect_success 'create commits and repack' '
 '
 
 graph_git_two_modes() {
-       git -c core.graph=true $1 >output
-       git -c core.graph=false $1 >expect
+       git -c core.commitGraph=true $1 >output
+       git -c core.commitGraph=false $1 >expect
        test_cmp output expect
 }
 
@@ -200,6 +205,16 @@ test_expect_success 'build graph from commits with append' '
 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
 
+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_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
+graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
+
 test_expect_success 'setup bare repo' '
        cd "$TRASH_DIRECTORY" &&
        git clone --bare --no-local full bare &&
@@ -230,4 +245,227 @@ test_expect_success 'perform fast-forward merge in full repo' '
        test_cmp expect output
 '
 
+test_expect_success 'check that gc computes commit-graph' '
+       cd "$TRASH_DIRECTORY/full" &&
+       git commit --allow-empty -m "blank" &&
+       git commit-graph write --reachable &&
+       cp $objdir/info/commit-graph commit-graph-before-gc &&
+       git reset --hard HEAD~1 &&
+       git config gc.writeCommitGraph true &&
+       git gc &&
+       cp $objdir/info/commit-graph commit-graph-after-gc &&
+       ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
+       git commit-graph write --reachable &&
+       test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
+'
+
+# the verify tests below expect the commit-graph to contain
+# exactly the commits reachable from the commits/8 branch.
+# If the file changes the set of commits in the list, then the
+# offsets into the binary file will result in different edits
+# and the tests will likely break.
+
+test_expect_success 'git commit-graph verify' '
+       cd "$TRASH_DIRECTORY/full" &&
+       git rev-parse commits/8 | git commit-graph write --stdin-commits &&
+       git commit-graph verify >output
+'
+
+NUM_COMMITS=9
+NUM_OCTOPUS_EDGES=2
+HASH_LEN=20
+GRAPH_BYTE_VERSION=4
+GRAPH_BYTE_HASH=5
+GRAPH_BYTE_CHUNK_COUNT=6
+GRAPH_CHUNK_LOOKUP_OFFSET=8
+GRAPH_CHUNK_LOOKUP_WIDTH=12
+GRAPH_CHUNK_LOOKUP_ROWS=5
+GRAPH_BYTE_OID_FANOUT_ID=$GRAPH_CHUNK_LOOKUP_OFFSET
+GRAPH_BYTE_OID_LOOKUP_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
+                           1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
+GRAPH_BYTE_COMMIT_DATA_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
+                            2 * $GRAPH_CHUNK_LOOKUP_WIDTH))
+GRAPH_FANOUT_OFFSET=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
+                      $GRAPH_CHUNK_LOOKUP_WIDTH * $GRAPH_CHUNK_LOOKUP_ROWS))
+GRAPH_BYTE_FANOUT1=$(($GRAPH_FANOUT_OFFSET + 4 * 4))
+GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255))
+GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256))
+GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
+GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
+GRAPH_COMMIT_DATA_OFFSET=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
+GRAPH_BYTE_COMMIT_TREE=$GRAPH_COMMIT_DATA_OFFSET
+GRAPH_BYTE_COMMIT_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN))
+GRAPH_BYTE_COMMIT_EXTRA_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4))
+GRAPH_BYTE_COMMIT_WRONG_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3))
+GRAPH_BYTE_COMMIT_GENERATION=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11))
+GRAPH_BYTE_COMMIT_DATE=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12))
+GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
+GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
+                            $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
+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>
+# Manipulates the commit-graph file at the position
+# by inserting the data, then runs 'git commit-graph verify'
+# and places the output in the file 'err'. Test 'err' for
+# the given string.
+corrupt_graph_and_verify() {
+       pos=$1
+       data="${2:-\0}"
+       grepstr=$3
+       cd "$TRASH_DIRECTORY/full" &&
+       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 &&
+       test_must_fail git commit-graph verify 2>test_err &&
+       grep -v "^+" test_err >err
+       test_i18ngrep "$grepstr" err
+}
+
+test_expect_success 'detect bad signature' '
+       corrupt_graph_and_verify 0 "\0" \
+               "graph signature"
+'
+
+test_expect_success 'detect bad version' '
+       corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \
+               "graph version"
+'
+
+test_expect_success 'detect bad hash version' '
+       corrupt_graph_and_verify $GRAPH_BYTE_HASH "\02" \
+               "hash version"
+'
+
+test_expect_success 'detect low chunk count' '
+       corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\02" \
+               "missing the .* chunk"
+'
+
+test_expect_success 'detect missing OID fanout chunk' '
+       corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \
+               "missing the OID Fanout chunk"
+'
+
+test_expect_success 'detect missing OID lookup chunk' '
+       corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \
+               "missing the OID Lookup chunk"
+'
+
+test_expect_success 'detect missing commit data chunk' '
+       corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \
+               "missing the Commit Data chunk"
+'
+
+test_expect_success 'detect incorrect fanout' '
+       corrupt_graph_and_verify $GRAPH_BYTE_FANOUT1 "\01" \
+               "fanout value"
+'
+
+test_expect_success 'detect incorrect fanout final value' '
+       corrupt_graph_and_verify $GRAPH_BYTE_FANOUT2 "\01" \
+               "fanout value"
+'
+
+test_expect_success 'detect incorrect OID order' '
+       corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ORDER "\01" \
+               "incorrect OID order"
+'
+
+test_expect_success 'detect OID not in object database' '
+       corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_MISSING "\01" \
+               "from object database"
+'
+
+test_expect_success 'detect incorrect tree OID' '
+       corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_TREE "\01" \
+               "root tree OID for commit"
+'
+
+test_expect_success 'detect incorrect parent int-id' '
+       corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_PARENT "\01" \
+               "invalid parent"
+'
+
+test_expect_success 'detect extra parent int-id' '
+       corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_EXTRA_PARENT "\00" \
+               "is too long"
+'
+
+test_expect_success 'detect wrong parent' '
+       corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_WRONG_PARENT "\01" \
+               "commit-graph parent for"
+'
+
+test_expect_success 'detect incorrect generation number' '
+       corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\070" \
+               "generation for commit"
+'
+
+test_expect_success 'detect incorrect generation number' '
+       corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
+               "non-zero generation number"
+'
+
+test_expect_success 'detect incorrect commit date' '
+       corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \
+               "commit date"
+'
+
+test_expect_success 'detect incorrect parent for octopus merge' '
+       corrupt_graph_and_verify $GRAPH_BYTE_OCTOPUS "\01" \
+               "invalid parent"
+'
+
+test_expect_success 'detect invalid checksum hash' '
+       corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
+               "incorrect checksum"
+'
+
+test_expect_success 'git fsck (checks commit-graph)' '
+       cd "$TRASH_DIRECTORY/full" &&
+       git fsck &&
+       corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
+               "incorrect checksum" &&
+       test_must_fail git fsck
+'
+
+test_expect_success 'setup non-the_repository tests' '
+       rm -rf repo &&
+       git init repo &&
+       test_commit -C repo one &&
+       test_commit -C repo two &&
+       git -C repo config core.commitGraph true &&
+       git -C repo rev-parse two | \
+               git -C repo commit-graph write --stdin-commits
+'
+
+test_expect_success 'parse_commit_in_graph works for non-the_repository' '
+       test-tool repository parse_commit_in_graph \
+               repo/.git repo "$(git -C repo rev-parse two)" >actual &&
+       {
+               git -C repo log --pretty=format:"%ct " -1 &&
+               git -C repo rev-parse one
+       } >expect &&
+       test_cmp expect actual &&
+
+       test-tool repository parse_commit_in_graph \
+               repo/.git repo "$(git -C repo rev-parse one)" >actual &&
+       git -C repo log --pretty="%ct" -1 one >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'get_commit_tree_in_graph works for non-the_repository' '
+       test-tool repository get_commit_tree_in_graph \
+               repo/.git repo "$(git -C repo rev-parse two)" >actual &&
+       git -C repo rev-parse two^{tree} >expect &&
+       test_cmp expect actual &&
+
+       test-tool repository get_commit_tree_in_graph \
+               repo/.git repo "$(git -C repo rev-parse one)" >actual &&
+       git -C repo rev-parse one^{tree} >expect &&
+       test_cmp expect actual
+'
+
 test_done
index 7a48236e87695d947c7c3f166e1d291cd3b7a05b..9b2a274c71f40ace060069212055a29f9a3c4203 100755 (executable)
@@ -113,7 +113,7 @@ test_expect_success 'git rebase -m' '
 test_expect_success 'git rebase -m --skip' '
        git reset --hard D &&
        clear_hook_input &&
-       test_must_fail git rebase --onto A B &&
+       test_must_fail git rebase -m --onto A B &&
        test_must_fail git rebase --skip &&
        echo D > foo &&
        git add foo &&
index ebbbbfe05424dd805640180f9dfa41068c1d2d4e..8f945235e3a94156de4dadaff5e944751f056372 100755 (executable)
@@ -403,7 +403,7 @@ test_expect_success 'fetch creating new shallow root' '
                git fetch --depth=1 --progress 2>actual &&
                # This should fetch only the empty commit, no tree or
                # blob objects
-               grep "remote: Total 1" actual
+               test_i18ngrep "remote: Total 1" actual
        )
 '
 
@@ -533,19 +533,26 @@ test_expect_success 'test --all wrt tag to non-commits' '
        # are reachable only via created tag references.
        blob=$(echo "hello blob" | git hash-object -t blob -w --stdin) &&
        git tag -a -m "tag -> blob" tag-to-blob $blob &&
- \
+
        tree=$(printf "100644 blob $blob\tfile" | git mktree) &&
        git tag -a -m "tag -> tree" tag-to-tree $tree &&
- \
+
        tree2=$(printf "100644 blob $blob\tfile2" | git mktree) &&
        commit=$(git commit-tree -m "hello commit" $tree) &&
        git tag -a -m "tag -> commit" tag-to-commit $commit &&
- \
+
        blob2=$(echo "hello blob2" | git hash-object -t blob -w --stdin) &&
-       tag=$(printf "object $blob2\ntype blob\ntag tag-to-blob2\n\
-tagger author A U Thor <author@example.com> 0 +0000\n\nhello tag" | git mktag) &&
+       tag=$(git mktag <<-EOF
+               object $blob2
+               type blob
+               tag tag-to-blob2
+               tagger author A U Thor <author@example.com> 0 +0000
+
+               hello tag
+       EOF
+       ) &&
        git tag -a -m "tag -> tag" tag-to-tag $tag &&
- \
+
        # `fetch-pack --all` should succeed fetching all those objects.
        mkdir fetchall &&
        (
@@ -807,6 +814,39 @@ test_expect_success 'fetching deepen' '
        )
 '
 
+test_expect_success 'use ref advertisement to prune "have" lines sent' '
+       rm -rf server client &&
+       git init server &&
+       test_commit -C server both_have_1 &&
+       git -C server tag -d both_have_1 &&
+       test_commit -C server both_have_2 &&
+
+       git clone server client &&
+       test_commit -C server server_has &&
+       test_commit -C client client_has &&
+
+       # In both protocol v0 and v2, ensure that the parent of both_have_2 is
+       # not sent as a "have" line. The client should know that the server has
+       # both_have_2, so it only needs to inform the server that it has
+       # both_have_2, and the server can infer the rest.
+
+       rm -f trace &&
+       cp -r client clientv0 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C clientv0 \
+               fetch origin server_has both_have_2 &&
+       grep "have $(git -C client rev-parse client_has)" trace &&
+       grep "have $(git -C client rev-parse both_have_2)" trace &&
+       ! grep "have $(git -C client rev-parse both_have_2^)" trace &&
+
+       rm -f trace &&
+       cp -r client clientv2 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C clientv2 -c protocol.version=2 \
+               fetch origin server_has both_have_2 &&
+       grep "have $(git -C client rev-parse client_has)" trace &&
+       grep "have $(git -C client rev-parse both_have_2)" trace &&
+       ! grep "have $(git -C client rev-parse both_have_2^)" trace
+'
+
 test_expect_success 'filtering by size' '
        rm -rf server client &&
        test_create_repo server &&
index 49d3621a926786dfbfd71b205dfcb5dd3fa2d889..62f35698912d0655e44d53d50c7197b8200d2710 100755 (executable)
@@ -3,13 +3,16 @@
 test_description='fetch/receive strict mode'
 . ./test-lib.sh
 
-test_expect_success setup '
+test_expect_success 'setup and inject "corrupt or missing" object' '
        echo hello >greetings &&
        git add greetings &&
        git commit -m greetings &&
 
        S=$(git rev-parse :greetings | sed -e "s|^..|&/|") &&
        X=$(echo bye | git hash-object -w --stdin | sed -e "s|^..|&/|") &&
+       echo $S >S &&
+       echo $X >X &&
+       cp .git/objects/$S .git/objects/$S.back &&
        mv -f .git/objects/$X .git/objects/$S &&
 
        test_must_fail git fsck
@@ -115,6 +118,13 @@ test_expect_success 'push with transfer.fsckobjects' '
        test_cmp exp act
 '
 
+test_expect_success 'repair the "corrupt or missing" object' '
+       mv -f .git/objects/$(cat S) .git/objects/$(cat X) &&
+       mv .git/objects/$(cat S).back .git/objects/$(cat S) &&
+       rm -rf .git/objects/$(cat X) &&
+       git fsck
+'
+
 cat >bogus-commit <<EOF
 tree $EMPTY_TREE
 author Bugs Bunny 1234567890 +0000
@@ -123,6 +133,14 @@ committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
 This commit object intentionally broken
 EOF
 
+test_expect_success 'fsck with invalid or bogus skipList input' '
+       git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
+       test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err &&
+       test_i18ngrep "Could not open skip list: does-not-exist" err &&
+       test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
+       test_i18ngrep "Invalid SHA-1: \[core\]" err
+'
+
 test_expect_success 'push with receive.fsck.skipList' '
        commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
        git push . $commit:refs/heads/bogus &&
@@ -130,11 +148,61 @@ test_expect_success 'push with receive.fsck.skipList' '
        git init dst &&
        git --git-dir=dst/.git config receive.fsckObjects true &&
        test_must_fail git push --porcelain dst bogus &&
-       git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
        echo $commit >dst/.git/SKIP &&
+
+       # receive.fsck.* does not fall back on fsck.*
+       git --git-dir=dst/.git config fsck.skipList SKIP &&
+       test_must_fail git push --porcelain dst bogus &&
+
+       # Invalid and/or bogus skipList input
+       git --git-dir=dst/.git config receive.fsck.skipList /dev/null &&
+       test_must_fail git push --porcelain dst bogus &&
+       git --git-dir=dst/.git config receive.fsck.skipList does-not-exist &&
+       test_must_fail git push --porcelain dst bogus 2>err &&
+       test_i18ngrep "Could not open skip list: does-not-exist" err &&
+       git --git-dir=dst/.git config receive.fsck.skipList config &&
+       test_must_fail git push --porcelain dst bogus 2>err &&
+       test_i18ngrep "Invalid SHA-1: \[core\]" err &&
+
+       git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
        git push --porcelain dst bogus
 '
 
+test_expect_success 'fetch with fetch.fsck.skipList' '
+       commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
+       refspec=refs/heads/bogus:refs/heads/bogus &&
+       git push . $commit:refs/heads/bogus &&
+       rm -rf dst &&
+       git init dst &&
+       git --git-dir=dst/.git config fetch.fsckObjects true &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+       git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+       echo $commit >dst/.git/SKIP &&
+
+       # fetch.fsck.* does not fall back on fsck.*
+       git --git-dir=dst/.git config fsck.skipList dst/.git/SKIP &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+
+       # Invalid and/or bogus skipList input
+       git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+       git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
+       test_i18ngrep "Could not open skip list: does-not-exist" err &&
+       git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
+       test_i18ngrep "Invalid SHA-1: \[core\]" err &&
+
+       git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
+       git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
+'
+
+test_expect_success 'fsck.<unknownmsg-id> dies' '
+       test_must_fail git -c fsck.whatEver=ignore fsck 2>err &&
+       test_i18ngrep "Unhandled message id: whatever" err
+'
+
 test_expect_success 'push with receive.fsck.missingEmail=warn' '
        commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
        git push . $commit:refs/heads/bogus &&
@@ -142,19 +210,58 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
        git init dst &&
        git --git-dir=dst/.git config receive.fsckobjects true &&
        test_must_fail git push --porcelain dst bogus &&
+
+       # receive.fsck.<msg-id> does not fall back on fsck.<msg-id>
+       git --git-dir=dst/.git config fsck.missingEmail warn &&
+       test_must_fail git push --porcelain dst bogus &&
+
+       # receive.fsck.<unknownmsg-id> warns
+       git --git-dir=dst/.git config \
+               receive.fsck.whatEver error &&
+
        git --git-dir=dst/.git config \
                receive.fsck.missingEmail warn &&
        git push --porcelain dst bogus >act 2>&1 &&
        grep "missingEmail" act &&
+       test_i18ngrep "Skipping unknown msg id.*whatever" act &&
        git --git-dir=dst/.git branch -D bogus &&
        git --git-dir=dst/.git config --add \
                receive.fsck.missingEmail ignore &&
-       git --git-dir=dst/.git config --add \
-               receive.fsck.badDate warn &&
        git push --porcelain dst bogus >act 2>&1 &&
        ! grep "missingEmail" act
 '
 
+test_expect_success 'fetch with fetch.fsck.missingEmail=warn' '
+       commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
+       refspec=refs/heads/bogus:refs/heads/bogus &&
+       git push . $commit:refs/heads/bogus &&
+       rm -rf dst &&
+       git init dst &&
+       git --git-dir=dst/.git config fetch.fsckobjects true &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+
+       # fetch.fsck.<msg-id> does not fall back on fsck.<msg-id>
+       git --git-dir=dst/.git config fsck.missingEmail warn &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+
+       # receive.fsck.<unknownmsg-id> warns
+       git --git-dir=dst/.git config \
+               fetch.fsck.whatEver error &&
+
+       git --git-dir=dst/.git config \
+               fetch.fsck.missingEmail warn &&
+       git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
+       grep "missingEmail" act &&
+       test_i18ngrep "Skipping unknown msg id.*whatever" act &&
+       rm -rf dst &&
+       git init dst &&
+       git --git-dir=dst/.git config fetch.fsckobjects true &&
+       git --git-dir=dst/.git config \
+               fetch.fsck.missingEmail ignore &&
+       git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
+       ! grep "missingEmail" act
+'
+
 test_expect_success \
        'receive.fsck.unterminatedHeader=warn triggers error' '
        rm -rf dst &&
@@ -166,4 +273,15 @@ test_expect_success \
        grep "Cannot demote unterminatedheader" act
 '
 
+test_expect_success \
+       'fetch.fsck.unterminatedHeader=warn triggers error' '
+       rm -rf dst &&
+       git init dst &&
+       git --git-dir=dst/.git config fetch.fsckobjects true &&
+       git --git-dir=dst/.git config \
+               fetch.fsck.unterminatedheader warn &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" HEAD &&
+       grep "Cannot demote unterminatedheader" act
+'
+
 test_done
index 11e14a1e0fd591c053e3cb50a1a40e49b2b93e09..241e6a319df4cefa612b6744c79e72e5cf929462 100755 (executable)
@@ -74,8 +74,7 @@ test_expect_success 'add another remote' '
                git for-each-ref "--format=%(refname)" refs/remotes |
                sed -e "/^refs\/remotes\/origin\//d" \
                    -e "/^refs\/remotes\/second\//d" >actual &&
-               >expect &&
-               test_cmp expect actual
+               test_must_be_empty actual
        )
 '
 
@@ -112,8 +111,7 @@ test_expect_success C_LOCALE_OUTPUT 'remove remote' '
                check_remote_track origin master side &&
                git for-each-ref "--format=%(refname)" refs/remotes |
                sed -e "/^refs\/remotes\/origin\//d" >actual &&
-               >expect &&
-               test_cmp expect actual
+               test_must_be_empty actual
        )
 '
 
@@ -872,7 +870,7 @@ test_expect_success 'remote prune to cause a dangling symref' '
                cd eight &&
                test_must_fail git branch nomore origin
        ) 2>err &&
-       grep "dangling symref" err
+       test_i18ngrep "dangling symref" err
 '
 
 test_expect_success 'show empty remote' '
index e402aee6a22e64306c9f093ad1b529b3923fd65e..3b7b30568cddd5d9ea1a8979e5366a262f81bf09 100755 (executable)
@@ -535,6 +535,41 @@ test_expect_success "should be able to fetch with duplicate refspecs" '
        )
 '
 
+test_expect_success 'LHS of refspec follows ref disambiguation rules' '
+       mkdir lhs-ambiguous &&
+       (
+               cd lhs-ambiguous &&
+               git init server &&
+               test_commit -C server unwanted &&
+               test_commit -C server wanted &&
+
+               git init client &&
+
+               # Check a name coming after "refs" alphabetically ...
+               git -C server update-ref refs/heads/s wanted &&
+               git -C server update-ref refs/heads/refs/heads/s unwanted &&
+               git -C client fetch ../server +refs/heads/s:refs/heads/checkthis &&
+               git -C server rev-parse wanted >expect &&
+               git -C client rev-parse checkthis >actual &&
+               test_cmp expect actual &&
+
+               # ... and one before.
+               git -C server update-ref refs/heads/q wanted &&
+               git -C server update-ref refs/heads/refs/heads/q unwanted &&
+               git -C client fetch ../server +refs/heads/q:refs/heads/checkthis &&
+               git -C server rev-parse wanted >expect &&
+               git -C client rev-parse checkthis >actual &&
+               test_cmp expect actual &&
+
+               # Tags are preferred over branches like refs/{heads,tags}/*
+               git -C server update-ref refs/tags/t wanted &&
+               git -C server update-ref refs/heads/t unwanted &&
+               git -C client fetch ../server +t:refs/heads/checkthis &&
+               git -C server rev-parse wanted >expect &&
+               git -C client rev-parse checkthis >actual
+       )
+'
+
 # configured prune tests
 
 set_config_tristate () {
@@ -613,7 +648,7 @@ test_configured_prune_type () {
                        git rev-parse --verify refs/tags/newtag
                ) &&
 
-               # now remove it
+               # now remove them
                git branch -d newbranch &&
                git tag -d newtag &&
 
@@ -828,9 +863,11 @@ test_expect_success 'fetching with auto-gc does not lock up' '
        test_commit test2 &&
        (
                cd auto-gc &&
+               git config fetch.unpackLimit 1 &&
                git config gc.autoPackLimit 1 &&
                git config gc.autoDetach false &&
                GIT_ASK_YESNO="$D/askyesno" git fetch >fetch.out 2>&1 &&
+               test_i18ngrep "Auto packing the repository" fetch.out &&
                ! grep "Should I try again" fetch.out
        )
 '
@@ -865,4 +902,82 @@ test_expect_success C_LOCALE_OUTPUT 'fetch compact output' '
        test_cmp expect actual
 '
 
+setup_negotiation_tip () {
+       SERVER="$1"
+       URL="$2"
+       USE_PROTOCOL_V2="$3"
+
+       rm -rf "$SERVER" client trace &&
+       git init "$SERVER" &&
+       test_commit -C "$SERVER" alpha_1 &&
+       test_commit -C "$SERVER" alpha_2 &&
+       git -C "$SERVER" checkout --orphan beta &&
+       test_commit -C "$SERVER" beta_1 &&
+       test_commit -C "$SERVER" beta_2 &&
+
+       git clone "$URL" client &&
+
+       if test "$USE_PROTOCOL_V2" -eq 1
+       then
+               git -C "$SERVER" config protocol.version 2 &&
+               git -C client config protocol.version 2
+       fi &&
+
+       test_commit -C "$SERVER" beta_s &&
+       git -C "$SERVER" checkout master &&
+       test_commit -C "$SERVER" alpha_s &&
+       git -C "$SERVER" tag -d alpha_1 alpha_2 beta_1 beta_2
+}
+
+check_negotiation_tip () {
+       # Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2
+       ALPHA_1=$(git -C client rev-parse alpha_1) &&
+       grep "fetch> have $ALPHA_1" trace &&
+       BETA_1=$(git -C client rev-parse beta_1) &&
+       grep "fetch> have $BETA_1" trace &&
+       ALPHA_2=$(git -C client rev-parse alpha_2) &&
+       ! grep "fetch> have $ALPHA_2" trace &&
+       BETA_2=$(git -C client rev-parse beta_2) &&
+       ! grep "fetch> have $BETA_2" trace
+}
+
+test_expect_success '--negotiation-tip limits "have" lines sent' '
+       setup_negotiation_tip server server 0 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
+               --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
+               origin alpha_s beta_s &&
+       check_negotiation_tip
+'
+
+test_expect_success '--negotiation-tip understands globs' '
+       setup_negotiation_tip server server 0 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
+               --negotiation-tip=*_1 \
+               origin alpha_s beta_s &&
+       check_negotiation_tip
+'
+
+test_expect_success '--negotiation-tip understands abbreviated SHA-1' '
+       setup_negotiation_tip server server 0 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
+               --negotiation-tip=$(git -C client rev-parse --short alpha_1) \
+               --negotiation-tip=$(git -C client rev-parse --short beta_1) \
+               origin alpha_s beta_s &&
+       check_negotiation_tip
+'
+
+. "$TEST_DIRECTORY"/lib-httpd.sh
+start_httpd
+
+test_expect_success '--negotiation-tip limits "have" lines sent with HTTP protocol v2' '
+       setup_negotiation_tip "$HTTPD_DOCUMENT_ROOT_PATH/server" \
+               "$HTTPD_URL/smart/server" 1 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
+               --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
+               origin alpha_s beta_s &&
+       check_negotiation_tip
+'
+
+stop_httpd
+
 test_done
index ea020040e858de0c65759e299ce9cf646573fc63..bc5703ff9ba166b928199abf3085ff55a8fc09f1 100755 (executable)
@@ -155,14 +155,12 @@ test_expect_success 'die with non-2 for wrong repository even with --exit-code'
 
 test_expect_success 'Report success even when nothing matches' '
        git ls-remote other.git "refs/nsn/*" >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'Report no-match with --exit-code' '
        test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'Report match with --exit-code' '
index 4b4b6673b8fe25d96044cdc5d1196b191a7ae0e9..0030c92e1afa2a83066944272fcf3925f821bc54 100755 (executable)
@@ -152,7 +152,6 @@ test_expect_success 'git fetch --multiple (ignoring skipFetchAll)' '
 '
 
 test_expect_success 'git fetch --all --no-tags' '
-       >expect &&
        git clone one test5 &&
        git clone test5 test6 &&
        (cd test5 && git tag test-tag) &&
@@ -161,7 +160,7 @@ test_expect_success 'git fetch --all --no-tags' '
                git fetch --all --no-tags &&
                git tag >output
        ) &&
-       test_cmp expect test6/output
+       test_must_be_empty test6/output
 '
 
 test_expect_success 'git fetch --all --tags' '
index bd8f23e4300218fba33a5bea5effa167a2e9155a..539c25aadafdcf6aa9fbcce0988631702d3fb02d 100755 (executable)
@@ -965,26 +965,51 @@ test_expect_success 'push into aliased refs (inconsistent)' '
        )
 '
 
-test_expect_success 'push requires --force to update lightweight tag' '
-       mk_test testrepo heads/master &&
-       mk_child testrepo child1 &&
-       mk_child testrepo child2 &&
-       (
-               cd child1 &&
-               git tag Tag &&
-               git push ../child2 Tag &&
-               git push ../child2 Tag &&
-               >file1 &&
-               git add file1 &&
-               git commit -m "file1" &&
-               git tag -f Tag &&
-               test_must_fail git push ../child2 Tag &&
-               git push --force ../child2 Tag &&
-               git tag -f Tag &&
-               test_must_fail git push ../child2 Tag HEAD~ &&
-               git push --force ../child2 Tag
-       )
-'
+test_force_push_tag () {
+       tag_type_description=$1
+       tag_args=$2
+
+       test_expect_success 'force pushing required to update lightweight tag' "
+               mk_test testrepo heads/master &&
+               mk_child testrepo child1 &&
+               mk_child testrepo child2 &&
+               (
+                       cd child1 &&
+                       git tag testTag &&
+                       git push ../child2 testTag &&
+                       >file1 &&
+                       git add file1 &&
+                       git commit -m 'file1' &&
+                       git tag $tag_args testTag &&
+                       test_must_fail git push ../child2 testTag &&
+                       git push --force ../child2 testTag &&
+                       git tag $tag_args testTag HEAD~ &&
+                       test_must_fail git push ../child2 testTag &&
+                       git push --force ../child2 testTag &&
+
+                       # Clobbering without + in refspec needs --force
+                       git tag -f testTag &&
+                       test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' &&
+                       git push --force ../child2 'refs/tags/*:refs/tags/*' &&
+
+                       # Clobbering with + in refspec does not need --force
+                       git tag -f testTag HEAD~ &&
+                       git push ../child2 '+refs/tags/*:refs/tags/*' &&
+
+                       # Clobbering with --no-force still obeys + in refspec
+                       git tag -f testTag &&
+                       git push --no-force ../child2 '+refs/tags/*:refs/tags/*' &&
+
+                       # Clobbering with/without --force and 'tag <name>' format
+                       git tag -f testTag HEAD~ &&
+                       test_must_fail git push ../child2 tag testTag &&
+                       git push --force ../child2 tag testTag
+               )
+       "
+}
+
+test_force_push_tag "lightweight tag" "-f"
+test_force_push_tag "annotated tag" "-f -a -m'msg'"
 
 test_expect_success 'push --porcelain' '
        mk_empty testrepo &&
index 59c4b778d3a455b6ef4575a4b07b860d1e84720d..5e501c8b08868b17478b8baa91db2cd129cd1c67 100755 (executable)
@@ -475,10 +475,22 @@ test_expect_success 'pull.rebase=interactive' '
        false
        EOF
        test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
+       test_when_finished "test_might_fail git rebase --abort" &&
        test_must_fail git pull --rebase=interactive . copy &&
        test "I was here" = "$(cat fake.out)"
 '
 
+test_expect_success 'pull --rebase=i' '
+       write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
+       echo I was here, too >fake.out &&
+       false
+       EOF
+       test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
+       test_when_finished "test_might_fail git rebase --abort" &&
+       test_must_fail git pull --rebase=i . copy &&
+       test "I was here, too" = "$(cat fake.out)"
+'
+
 test_expect_success 'pull.rebase=invalid fails' '
        git reset --hard before-preserve-rebase &&
        test_config pull.rebase invalid &&
@@ -618,6 +630,18 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
        )
 '
 
+test_expect_success 'pull --rebase fails on corrupt HEAD' '
+       test_when_finished "rm -rf corrupt" &&
+       git init corrupt &&
+       (
+               cd corrupt &&
+               test_commit one &&
+               obj=$(git rev-parse --verify HEAD | sed "s#^..#&/#") &&
+               rm -f .git/objects/$obj &&
+               test_must_fail git pull --rebase
+       )
+'
+
 test_expect_success 'setup for detecting upstreamed changes' '
        mkdir src &&
        (cd src &&
index d38ecee2172a6e5599cfbeb18e472816e98e553c..0b0eb1d0259f314261c131db8e089e6859a7f3ba 100755 (executable)
@@ -142,9 +142,8 @@ test_expect_success 'push to delete (protected, forced)' '
                cd dst &&
                git push --force --force-with-lease=master:master^ origin :master
        ) &&
-       >expect &&
        git ls-remote src refs/heads/master >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'push to delete (allowed)' '
@@ -154,9 +153,8 @@ test_expect_success 'push to delete (allowed)' '
                git push --force-with-lease=master origin :master 2>err &&
                grep deleted err
        ) &&
-       >expect &&
        git ls-remote src refs/heads/master >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'cover everything with default force-with-lease (protected)' '
index 1cea758f789edef35a61ce1a9bc11d9fda7bd7ac..030331f1c51fc2a962fffd04c84d8f31d096311c 100755 (executable)
@@ -194,10 +194,12 @@ test_expect_success GPG 'fail without key and heed user.signingkey' '
 
        EOF
 
-       unset GIT_COMMITTER_EMAIL &&
-       git config user.email hasnokey@nowhere.com &&
-       test_must_fail git push --signed dst noop ff +noff &&
-       git config user.signingkey committer@example.com &&
+       test_config user.email hasnokey@nowhere.com &&
+       (
+               sane_unset GIT_COMMITTER_EMAIL &&
+               test_must_fail git push --signed dst noop ff +noff
+       ) &&
+       test_config user.signingkey $GIT_COMMITTER_EMAIL &&
        git push --signed dst noop ff +noff &&
 
        (
@@ -218,4 +220,57 @@ test_expect_success GPG 'fail without key and heed user.signingkey' '
        test_cmp expect dst/push-cert-status
 '
 
+test_expect_success GPGSM 'fail without key and heed user.signingkey x509' '
+       test_config gpg.format x509 &&
+       prepare_dst &&
+       mkdir -p dst/.git/hooks &&
+       git -C dst config receive.certnonceseed sekrit &&
+       write_script dst/.git/hooks/post-receive <<-\EOF &&
+       # discard the update list
+       cat >/dev/null
+       # record the push certificate
+       if test -n "${GIT_PUSH_CERT-}"
+       then
+               git cat-file blob $GIT_PUSH_CERT >../push-cert
+       fi &&
+
+       cat >../push-cert-status <<E_O_F
+       SIGNER=${GIT_PUSH_CERT_SIGNER-nobody}
+       KEY=${GIT_PUSH_CERT_KEY-nokey}
+       STATUS=${GIT_PUSH_CERT_STATUS-nostatus}
+       NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus}
+       NONCE=${GIT_PUSH_CERT_NONCE-nononce}
+       E_O_F
+
+       EOF
+
+       test_config user.email hasnokey@nowhere.com &&
+       test_config user.signingkey "" &&
+       (
+               sane_unset GIT_COMMITTER_EMAIL &&
+               test_must_fail git push --signed dst noop ff +noff
+       ) &&
+       test_config user.signingkey $GIT_COMMITTER_EMAIL &&
+       git push --signed dst noop ff +noff &&
+
+       (
+               cat <<-\EOF &&
+               SIGNER=/CN=C O Mitter/O=Example/SN=C O/GN=Mitter
+               KEY=
+               STATUS=G
+               NONCE_STATUS=OK
+               EOF
+               sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" dst/push-cert
+       ) >expect.in &&
+       key=$(cat "${GNUPGHOME}/trustlist.txt" | cut -d" " -f1 | tr -d ":") &&
+       sed -e "s/^KEY=/KEY=${key}/" expect.in >expect &&
+
+       noop=$(git rev-parse noop) &&
+       ff=$(git rev-parse ff) &&
+       noff=$(git rev-parse noff) &&
+       grep "$noop $ff refs/heads/ff" dst/push-cert &&
+       grep "$noop $noff refs/heads/noff" dst/push-cert &&
+       test_cmp expect dst/push-cert-status
+'
+
 test_done
index 943231af9638d14641811ea8196f8afdafdf6871..7045685e2d3942161084ecd04a116faa83f35a44 100755 (executable)
@@ -186,4 +186,47 @@ EOF
        test_cmp expect actual
 '
 
+. "$TEST_DIRECTORY"/lib-httpd.sh
+start_httpd
+
+REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
+
+test_expect_success 'shallow fetches check connectivity before writing shallow file' '
+       rm -rf "$REPO" client &&
+
+       git init "$REPO" &&
+       test_commit -C "$REPO" one &&
+       test_commit -C "$REPO" two &&
+       test_commit -C "$REPO" three &&
+
+       git init client &&
+
+       # Use protocol v2 to ensure that shallow information is sent exactly
+       # once by the server, since we are planning to manipulate it.
+       git -C "$REPO" config protocol.version 2 &&
+       git -C client config protocol.version 2 &&
+
+       git -C client fetch --depth=2 "$HTTPD_URL/one_time_sed/repo" master:a_branch &&
+
+       # Craft a situation in which the server sends back an unshallow request
+       # with an empty packfile. This is done by refetching with a shorter
+       # depth (to ensure that the packfile is empty), and overwriting the
+       # shallow line in the response with the unshallow line we want.
+       printf "s/0034shallow %s/0036unshallow %s/" \
+              "$(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" \
+               master:a_branch &&
+
+       # Ensure that the one-time-sed script was used.
+       ! test -e "$HTTPD_ROOT_PATH/one-time-sed" &&
+
+       # Ensure that the resulting repo is consistent, despite our failure to
+       # fetch.
+       git -C client fsck
+'
+
+stop_httpd
+
 test_done
index a2af693068fa455838c97df1fefe38bd630ceb2e..a0fc4005e059723dbafb26606548a074554bc961 100755 (executable)
@@ -38,25 +38,16 @@ GET  /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
 EOF
 test_expect_success 'no empty path components' '
+       # Clear the log, so that it does not affect the "used receive-pack
+       # service" test which reads the log too.
+       test_when_finished ">\"\$HTTPD_ROOT_PATH\"/access.log" &&
+
        # In the URL, add a trailing slash, and see if git appends yet another
        # slash.
        cd "$ROOT_PATH" &&
        git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
 
-       sed -e "
-               s/^.* \"//
-               s/\"//
-               s/ [1-9][0-9]*\$//
-               s/^GET /GET  /
-       " >act <"$HTTPD_ROOT_PATH"/access.log &&
-
-       # Clear the log, so that it does not affect the "used receive-pack
-       # service" test which reads the log too.
-       #
-       # We do this before the actual comparison to ensure the log is cleared.
-       echo > "$HTTPD_ROOT_PATH"/access.log &&
-
-       test_cmp exp act
+       check_access_log exp
 '
 
 test_expect_success 'clone remote repository' '
@@ -124,7 +115,6 @@ test_expect_success 'rejected update prints status' '
 rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
 
 cat >exp <<EOF
-
 GET  /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
 GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
@@ -138,13 +128,7 @@ GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
 EOF
 test_expect_success 'used receive-pack service' '
-       sed -e "
-               s/^.* \"//
-               s/\"//
-               s/ [1-9][0-9]*\$//
-               s/^GET /GET  /
-       " >act <"$HTTPD_ROOT_PATH"/access.log &&
-       test_cmp exp act
+       check_access_log exp
 '
 
 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
index 913089b14452976144878415c05a9a2c743d22bf..771f36f9ff473d31507af374f1c96fac03192048 100755 (executable)
@@ -103,13 +103,7 @@ GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
 EOF
 test_expect_success 'used upload-pack service' '
-       sed -e "
-               s/^.* \"//
-               s/\"//
-               s/ [1-9][0-9]*\$//
-               s/^GET /GET  /
-       " >act <"$HTTPD_ROOT_PATH"/access.log &&
-       test_cmp exp act
+       check_access_log exp
 '
 
 test_expect_success 'follow redirects (301)' '
@@ -369,6 +363,24 @@ test_expect_success 'custom http headers' '
                submodule update sub
 '
 
+test_expect_success 'using fetch command in remote-curl updates refs' '
+       SERVER="$HTTPD_DOCUMENT_ROOT_PATH/twobranch" &&
+       rm -rf "$SERVER" client &&
+
+       git init "$SERVER" &&
+       test_commit -C "$SERVER" foo &&
+       git -C "$SERVER" update-ref refs/heads/anotherbranch foo &&
+
+       git clone $HTTPD_URL/smart/twobranch client &&
+
+       test_commit -C "$SERVER" bar &&
+       git -C client -c protocol.version=0 fetch &&
+
+       git -C "$SERVER" rev-parse master >expect &&
+       git -C client rev-parse origin/master >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'GIT_REDACT_COOKIES redacts cookies' '
        rm -rf clone &&
        echo "Set-Cookie: Foo=1" >cookies &&
diff --git a/t/t5552-skipping-fetch-negotiator.sh b/t/t5552-skipping-fetch-negotiator.sh
new file mode 100755 (executable)
index 0000000..5ad5bec
--- /dev/null
@@ -0,0 +1,215 @@
+#!/bin/sh
+
+test_description='test skipping fetch negotiator'
+. ./test-lib.sh
+
+have_sent () {
+       while test "$#" -ne 0
+       do
+               grep "fetch> have $(git -C client rev-parse $1)" trace
+               if test $? -ne 0
+               then
+                       echo "No have $(git -C client rev-parse $1) ($1)"
+                       return 1
+               fi
+               shift
+       done
+}
+
+have_not_sent () {
+       while test "$#" -ne 0
+       do
+               grep "fetch> have $(git -C client rev-parse $1)" trace
+               if test $? -eq 0
+               then
+                       return 1
+               fi
+               shift
+       done
+}
+
+# trace_fetch <client_dir> <server_dir> [args]
+#
+# Trace the packet output of fetch, but make sure we disable the variable
+# in the child upload-pack, so we don't combine the results in the same file.
+trace_fetch () {
+       client=$1; shift
+       server=$1; shift
+       GIT_TRACE_PACKET="$(pwd)/trace" \
+       git -C "$client" fetch \
+         --upload-pack 'unset GIT_TRACE_PACKET; git-upload-pack' \
+         "$server" "$@"
+}
+
+test_expect_success 'commits with no parents are sent regardless of skip distance' '
+       git init server &&
+       test_commit -C server to_fetch &&
+
+       git init client &&
+       for i in $(seq 7)
+       do
+               test_commit -C client c$i
+       done &&
+
+       # We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since
+       # "c1" has no parent, it is still sent as "have" even though it would
+       # normally be skipped.
+       test_config -C client fetch.negotiationalgorithm skipping &&
+       trace_fetch client "$(pwd)/server" &&
+       have_sent c7 c5 c2 c1 &&
+       have_not_sent c6 c4 c3
+'
+
+test_expect_success 'unknown fetch.negotiationAlgorithm values error out' '
+       rm -rf server client trace &&
+       git init server &&
+       test_commit -C server to_fetch &&
+
+       git init client &&
+       test_commit -C client on_client &&
+       git -C client checkout on_client &&
+
+       test_config -C client fetch.negotiationAlgorithm invalid &&
+       test_must_fail git -C client fetch "$(pwd)/server" 2>err &&
+       test_i18ngrep "unknown fetch negotiation algorithm" err &&
+
+       # Explicit "default" value
+       test_config -C client fetch.negotiationAlgorithm default &&
+       git -C client -c fetch.negotiationAlgorithm=default fetch "$(pwd)/server" &&
+
+       # Implementation detail: If there is nothing to fetch, we will not error out
+       test_config -C client fetch.negotiationAlgorithm invalid &&
+       git -C client fetch "$(pwd)/server" 2>err &&
+       test_i18ngrep ! "unknown fetch negotiation algorithm" err
+'
+
+test_expect_success 'when two skips collide, favor the larger one' '
+       rm -rf server client trace &&
+       git init server &&
+       test_commit -C server to_fetch &&
+
+       git init client &&
+       for i in $(seq 11)
+       do
+               test_commit -C client c$i
+       done &&
+       git -C client checkout c5 &&
+       test_commit -C client c5side &&
+
+       # Before reaching c5, we send "c5side" (skip 1) and "c11" (skip 1) "c9"
+       # (skip 2) "c6" (skip 4). The larger skip (skip 4) takes precedence, so
+       # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
+       # (from "c5side" skip 1).
+       test_config -C client fetch.negotiationalgorithm skipping &&
+       trace_fetch client "$(pwd)/server" &&
+       have_sent c5side c11 c9 c6 c1 &&
+       have_not_sent c10 c8 c7 c5 c4 c3 c2
+'
+
+test_expect_success 'use ref advertisement to filter out commits' '
+       rm -rf server client trace &&
+       git init server &&
+       test_commit -C server c1 &&
+       test_commit -C server c2 &&
+       test_commit -C server c3 &&
+       git -C server tag -d c1 c2 c3 &&
+
+       git clone server client &&
+       test_commit -C client c4 &&
+       test_commit -C client c5 &&
+       git -C client checkout c4^^ &&
+       test_commit -C client c2side &&
+
+       git -C server checkout --orphan anotherbranch &&
+       test_commit -C server to_fetch &&
+
+       # The server advertising "c3" (as "refs/heads/master") means that we do
+       # not need to send any ancestors of "c3", but we still need to send "c3"
+       # itself.
+       test_config -C client fetch.negotiationalgorithm skipping &&
+       trace_fetch client origin to_fetch &&
+       have_sent c5 c4^ c2side &&
+       have_not_sent c4 c4^^ c4^^^
+'
+
+test_expect_success 'handle clock skew' '
+       rm -rf server client trace &&
+       git init server &&
+       test_commit -C server to_fetch &&
+
+       git init client &&
+
+       # 2 regular commits
+       test_tick=2000000000 &&
+       test_commit -C client c1 &&
+       test_commit -C client c2 &&
+
+       # 4 old commits
+       test_tick=1000000000 &&
+       git -C client checkout c1 &&
+       test_commit -C client old1 &&
+       test_commit -C client old2 &&
+       test_commit -C client old3 &&
+       test_commit -C client old4 &&
+
+       # "c2" and "c1" are popped first, then "old4" to "old1". "old1" would
+       # normally be skipped, but is treated as a commit without a parent here
+       # and sent, because (due to clock skew) its only parent has already been
+       # popped off the priority queue.
+       test_config -C client fetch.negotiationalgorithm skipping &&
+       trace_fetch client "$(pwd)/server" &&
+       have_sent c2 c1 old4 old2 old1 &&
+       have_not_sent old3
+'
+
+test_expect_success 'do not send "have" with ancestors of commits that server ACKed' '
+       rm -rf server client trace &&
+       git init server &&
+       test_commit -C server to_fetch &&
+
+       git init client &&
+       for i in $(seq 8)
+       do
+               git -C client checkout --orphan b$i &&
+               test_commit -C client b$i.c0
+       done &&
+       for j in $(seq 19)
+       do
+               for i in $(seq 8)
+               do
+                       git -C client checkout b$i &&
+                       test_commit -C client b$i.c$j
+               done
+       done &&
+
+       # Copy this branch over to the server and add a commit on it so that it
+       # is reachable but not advertised.
+       git -C server fetch --no-tags "$(pwd)/client" b1:refs/heads/b1 &&
+       git -C server checkout b1 &&
+       test_commit -C server commit-on-b1 &&
+
+       test_config -C client fetch.negotiationalgorithm skipping &&
+       trace_fetch client "$(pwd)/server" to_fetch &&
+       grep "  fetch" trace &&
+
+       # fetch-pack sends 2 requests each containing 16 "have" lines before
+       # processing the first response. In these 2 requests, 4 commits from
+       # each branch are sent. Just check the first branch.
+       have_sent b1.c19 b1.c17 b1.c14 b1.c9 &&
+       have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 &&
+
+       # While fetch-pack is processing the first response, it should read that
+       # the server ACKs b1.c19 and b1.c17.
+       grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace &&
+       grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace &&
+
+       # fetch-pack should thus not send any more commits in the b1 branch, but
+       # should still send the others (in this test, just check b2).
+       for i in $(seq 0 8)
+       do
+               have_not_sent b1.c$i
+       done &&
+       have_sent b2.c1 b2.c0
+'
+
+test_done
index 84a955770a017e68d0cc1e928929e5a043d64e86..1c49054595c23564cf762ac01ea0a1667a59f2f9 100755 (executable)
@@ -129,13 +129,7 @@ GET  /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -
 POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
 EOF
 test_expect_success 'server request log matches test results' '
-       sed -e "
-               s/^.* \"//
-               s/\"//
-               s/ [1-9][0-9]*\$//
-               s/^GET /GET  /
-       " >act <"$HTTPD_ROOT_PATH"/access.log &&
-       test_cmp exp act
+       check_access_log exp
 '
 
 stop_httpd
diff --git a/t/t5562-http-backend-content-length.sh b/t/t5562-http-backend-content-length.sh
new file mode 100755 (executable)
index 0000000..43570ce
--- /dev/null
@@ -0,0 +1,156 @@
+#!/bin/sh
+
+test_description='test git-http-backend respects CONTENT_LENGTH'
+. ./test-lib.sh
+
+test_lazy_prereq GZIP 'gzip --version'
+
+verify_http_result() {
+       # some fatal errors still produce status 200
+       # so check if there is the error message
+       if grep 'fatal:' act.err
+       then
+               return 1
+       fi
+
+       if ! grep "Status" act.out >act
+       then
+               printf "Status: 200 OK\r\n" >act
+       fi
+       printf "Status: $1\r\n" >exp &&
+       test_cmp exp act
+}
+
+test_http_env() {
+       handler_type="$1"
+       request_body="$2"
+       shift
+       env \
+               CONTENT_TYPE="application/x-git-$handler_type-pack-request" \
+               QUERY_STRING="/repo.git/git-$handler_type-pack" \
+               PATH_TRANSLATED="$PWD/.git/git-$handler_type-pack" \
+               GIT_HTTP_EXPORT_ALL=TRUE \
+               REQUEST_METHOD=POST \
+               "$TEST_DIRECTORY"/t5562/invoke-with-content-length.pl \
+                   "$request_body" git http-backend >act.out 2>act.err
+}
+
+ssize_b100dots() {
+       # hardcoded ((size_t) SSIZE_MAX) + 1
+       case "$(build_option sizeof-size_t)" in
+       8) echo 9223372036854775808;;
+       4) echo 2147483648;;
+       *) die "Unexpected ssize_t size: $(build_option sizeof-size_t)";;
+       esac
+}
+
+test_expect_success 'setup' '
+       HTTP_CONTENT_ENCODING="identity" &&
+       export HTTP_CONTENT_ENCODING &&
+       git config http.receivepack true &&
+       test_commit c0 &&
+       test_commit c1 &&
+       hash_head=$(git rev-parse HEAD) &&
+       hash_prev=$(git rev-parse HEAD~1) &&
+       printf "want %s" "$hash_head" | packetize >fetch_body &&
+       printf 0000 >>fetch_body &&
+       printf "have %s" "$hash_prev" | packetize >>fetch_body &&
+       printf done | packetize >>fetch_body &&
+       test_copy_bytes 10 <fetch_body >fetch_body.trunc &&
+       hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) &&
+       printf "%s %s refs/heads/newbranch\\0report-status\\n" "$_z40" "$hash_next" | packetize >push_body &&
+       printf 0000 >>push_body &&
+       echo "$hash_next" | git pack-objects --stdout >>push_body &&
+       test_copy_bytes 10 <push_body >push_body.trunc &&
+       : >empty_body
+'
+
+test_expect_success GZIP 'setup, compression related' '
+       gzip -c fetch_body >fetch_body.gz &&
+       test_copy_bytes 10 <fetch_body.gz >fetch_body.gz.trunc &&
+       gzip -c push_body >push_body.gz &&
+       test_copy_bytes 10 <push_body.gz >push_body.gz.trunc
+'
+
+test_expect_success 'fetch plain' '
+       test_http_env upload fetch_body &&
+       verify_http_result "200 OK"
+'
+
+test_expect_success 'fetch plain truncated' '
+       test_http_env upload fetch_body.trunc &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success 'fetch plain empty' '
+       test_http_env upload empty_body &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'fetch gzipped' '
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload fetch_body.gz &&
+       verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'fetch gzipped truncated' '
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload fetch_body.gz.trunc &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'fetch gzipped empty' '
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload empty_body &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'push plain' '
+       test_when_finished "git branch -D newbranch" &&
+       test_http_env receive push_body &&
+       verify_http_result "200 OK" &&
+       git rev-parse newbranch >act.head &&
+       echo "$hash_next" >exp.head &&
+       test_cmp act.head exp.head
+'
+
+test_expect_success 'push plain truncated' '
+       test_http_env receive push_body.trunc &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success 'push plain empty' '
+       test_http_env receive empty_body &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'push gzipped' '
+       test_when_finished "git branch -D newbranch" &&
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive push_body.gz &&
+       verify_http_result "200 OK" &&
+       git rev-parse newbranch >act.head &&
+       echo "$hash_next" >exp.head &&
+       test_cmp act.head exp.head
+'
+
+test_expect_success GZIP 'push gzipped truncated' '
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive push_body.gz.trunc &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'push gzipped empty' '
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive empty_body &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success 'CONTENT_LENGTH overflow ssite_t' '
+       NOT_FIT_IN_SSIZE=$(ssize_b100dots) &&
+       env \
+               CONTENT_TYPE=application/x-git-upload-pack-request \
+               QUERY_STRING=/repo.git/git-upload-pack \
+               PATH_TRANSLATED="$PWD"/.git/git-upload-pack \
+               GIT_HTTP_EXPORT_ALL=TRUE \
+               REQUEST_METHOD=POST \
+               CONTENT_LENGTH="$NOT_FIT_IN_SSIZE" \
+               git http-backend </dev/zero >/dev/null 2>err &&
+       grep "fatal:.*CONTENT_LENGTH" err
+'
+
+test_done
diff --git a/t/t5562/invoke-with-content-length.pl b/t/t5562/invoke-with-content-length.pl
new file mode 100755 (executable)
index 0000000..6c2aae7
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+use 5.008;
+use strict;
+use warnings;
+
+my $body_filename = $ARGV[0];
+my @command = @ARGV[1 .. $#ARGV];
+
+# read data
+my $body_size = -s $body_filename;
+$ENV{"CONTENT_LENGTH"} = $body_size;
+open(my $body_fh, "<", $body_filename) or die "Cannot open $body_filename: $!";
+my $body_data;
+defined read($body_fh, $body_data, $body_size) or die "Cannot read $body_filename: $!";
+close($body_fh);
+
+my $exited = 0;
+$SIG{"CHLD"} = sub {
+        $exited = 1;
+};
+
+# write data
+my $pid = open(my $out, "|-", @command);
+{
+        # disable buffering at $out
+        my $old_selected = select;
+        select $out;
+        $| = 1;
+        select $old_selected;
+}
+print $out $body_data or die "Cannot write data: $!";
+
+sleep 60; # is interrupted by SIGCHLD
+if (!$exited) {
+        close($out);
+        die "Command did not exit after reading whole body";
+}
index 0d4c52016b2b3651fa638fcc416f22d236c87fc2..a571f22bfdd52293d0fcce16d30870119f72e88f 100755 (executable)
@@ -7,9 +7,9 @@ test_description='test fetching over git protocol'
 start_git_daemon
 
 check_verbose_connect () {
-       grep -F "Looking up 127.0.0.1 ..." stderr &&
-       grep -F "Connecting to 127.0.0.1 (port " stderr &&
-       grep -F "done." stderr
+       test_i18ngrep -F "Looking up 127.0.0.1 ..." stderr &&
+       test_i18ngrep -F "Connecting to 127.0.0.1 (port " stderr &&
+       test_i18ngrep -F "done." stderr
 }
 
 test_expect_success 'setup repository' '
index fac5a738519fe4aec0c3b2328c410db693c11f63..5582b3d5fd7118398bad00e43864d9e73c055f01 100755 (executable)
@@ -97,8 +97,7 @@ test_expect_success 'clone with --no-tags' '
                git fetch &&
                git for-each-ref refs/tags >../actual
        ) &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success '--single-branch while HEAD pointing at master' '
@@ -140,8 +139,7 @@ test_expect_success '--single-branch while HEAD pointing at master and --no-tags
                git fetch &&
                git for-each-ref refs/tags >../actual
        ) &&
-       >expect &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
        test_line_count = 0 actual &&
        # get tags with --tags overrides tagOpt
        (
@@ -230,8 +228,7 @@ test_expect_success '--single-branch with detached' '
                    -e "s|/remotes/origin/|/heads/|" >../actual
        ) &&
        # nothing
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_done
index cee556536757128861e166ea8e2cab7f975282c6..bbbe7537dfd315a567c6dc5583804325e6f10235 100755 (executable)
@@ -154,4 +154,112 @@ test_expect_success 'partial clone with transfer.fsckobjects=1 uses index-pack -
        grep "git index-pack.*--fsck-objects" trace
 '
 
+test_expect_success 'partial clone fetches blobs pointed to by refs even if normally filtered out' '
+       rm -rf src dst &&
+       git init src &&
+       test_commit -C src x &&
+       test_config -C src uploadpack.allowfilter 1 &&
+       test_config -C src uploadpack.allowanysha1inwant 1 &&
+
+       # Create a tag pointing to a blob.
+       BLOB=$(echo blob-contents | git -C src hash-object --stdin -w) &&
+       git -C src tag myblob "$BLOB" &&
+
+       git clone --filter="blob:none" "file://$(pwd)/src" dst 2>err &&
+       ! grep "does not point to a valid object" err &&
+       git -C dst fsck
+'
+
+. "$TEST_DIRECTORY"/lib-httpd.sh
+start_httpd
+
+# Converts bytes into a form suitable for inclusion in a sed command. For
+# example, "printf 'ab\r\n' | hex_unpack" results in '\x61\x62\x0d\x0a'.
+sed_escape () {
+       perl -e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)' |
+               sed 's/\(..\)/\\x\1/g'
+}
+
+test_expect_success 'upon cloning, check that all refs point to objects' '
+       SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
+       rm -rf "$SERVER" repo &&
+       test_create_repo "$SERVER" &&
+       test_commit -C "$SERVER" foo &&
+       test_config -C "$SERVER" uploadpack.allowfilter 1 &&
+       test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
+
+       # Create a tag pointing to a blob.
+       BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
+       git -C "$SERVER" tag myblob "$BLOB" &&
+
+       # Craft a packfile not including that blob.
+       git -C "$SERVER" rev-parse HEAD |
+               git -C "$SERVER" pack-objects --stdout >incomplete.pack &&
+
+       # Replace the existing packfile with the crafted one. The protocol
+       # requires that the packfile be sent in sideband 1, hence the extra
+       # \x01 byte at the beginning.
+       printf "1,/packfile/!c %04x\\\\x01%s0000" \
+               "$(($(wc -c <incomplete.pack) + 5))" \
+               "$(sed_escape <incomplete.pack)" \
+               >"$HTTPD_ROOT_PATH/one-time-sed" &&
+
+       # Use protocol v2 because the sed command looks for the "packfile"
+       # section header.
+       test_config -C "$SERVER" protocol.version 2 &&
+       test_must_fail git -c protocol.version=2 clone \
+               --filter=blob:none $HTTPD_URL/one_time_sed/server repo 2>err &&
+
+       grep "did not send all necessary objects" err &&
+
+       # Ensure that the one-time-sed script was used.
+       ! test -e "$HTTPD_ROOT_PATH/one-time-sed"
+'
+
+test_expect_success 'when partial cloning, tolerate server not sending target of tag' '
+       SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
+       rm -rf "$SERVER" repo &&
+       test_create_repo "$SERVER" &&
+       test_commit -C "$SERVER" foo &&
+       test_config -C "$SERVER" uploadpack.allowfilter 1 &&
+       test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
+
+       # Create an annotated tag pointing to a blob.
+       BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
+       git -C "$SERVER" tag -m message -a myblob "$BLOB" &&
+
+       # Craft a packfile including the tag, but not the blob it points to.
+       # Also, omit objects referenced from HEAD in order to force a second
+       # fetch (to fetch missing objects) upon the automatic checkout that
+       # happens after a clone.
+       printf "%s\n%s\n--not\n%s\n%s\n" \
+               $(git -C "$SERVER" rev-parse HEAD) \
+               $(git -C "$SERVER" rev-parse myblob) \
+               $(git -C "$SERVER" rev-parse HEAD^{tree}) \
+               $(git -C "$SERVER" rev-parse myblob^{blob}) |
+               git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
+
+       # Replace the existing packfile with the crafted one. The protocol
+       # requires that the packfile be sent in sideband 1, hence the extra
+       # \x01 byte at the beginning.
+       printf "1,/packfile/!c %04x\\\\x01%s0000" \
+               "$(($(wc -c <incomplete.pack) + 5))" \
+               "$(sed_escape <incomplete.pack)" \
+               >"$HTTPD_ROOT_PATH/one-time-sed" &&
+
+       # Use protocol v2 because the sed command looks for the "packfile"
+       # section header.
+       test_config -C "$SERVER" protocol.version 2 &&
+
+       # Exercise to make sure it works.
+       git -c protocol.version=2 clone \
+               --filter=blob:none $HTTPD_URL/one_time_sed/server repo 2> err &&
+       ! grep "missing object referenced by" err &&
+
+       # Ensure that the one-time-sed script was used.
+       ! test -e "$HTTPD_ROOT_PATH/one-time-sed"
+'
+
+stop_httpd
+
 test_done
index a4fe6508bdd73784758b2ea80ab81752e15c01b3..3beeed4546cee6c7793de94ba2735b0e6d63b073 100755 (executable)
@@ -181,7 +181,12 @@ test_expect_success 'clone with file:// using protocol v2' '
        test_cmp expect actual &&
 
        # Server responded using protocol v2
-       grep "clone< version 2" log
+       grep "clone< version 2" log &&
+
+       # Client sent ref-prefixes to filter the ref-advertisement
+       grep "ref-prefix HEAD" log &&
+       grep "ref-prefix refs/heads/" log &&
+       grep "ref-prefix refs/tags/" log
 '
 
 test_expect_success 'fetch with file:// using protocol v2' '
@@ -204,6 +209,7 @@ test_expect_success 'ref advertisment is filtered during fetch using protocol v2
        test_when_finished "rm -f log" &&
 
        test_commit -C file_parent three &&
+       git -C file_parent branch unwanted-branch three &&
 
        GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
                fetch origin master &&
@@ -212,9 +218,8 @@ test_expect_success 'ref advertisment is filtered during fetch using protocol v2
        git -C file_parent log -1 --format=%s >expect &&
        test_cmp expect actual &&
 
-       ! grep "refs/tags/one" log &&
-       ! grep "refs/tags/two" log &&
-       ! grep "refs/tags/three" log
+       grep "refs/heads/master" log &&
+       ! grep "refs/heads/unwanted-branch" log
 '
 
 test_expect_success 'server-options are sent when fetching' '
@@ -359,6 +364,71 @@ test_expect_success 'default refspec is used to filter ref when fetchcing' '
        grep "ref-prefix refs/tags/" log
 '
 
+test_expect_success 'fetch supports various ways of have lines' '
+       rm -rf server client trace &&
+       git init server &&
+       test_commit -C server dwim &&
+       TREE=$(git -C server rev-parse HEAD^{tree}) &&
+       git -C server tag exact \
+               $(git -C server commit-tree -m a "$TREE") &&
+       git -C server tag dwim-unwanted \
+               $(git -C server commit-tree -m b "$TREE") &&
+       git -C server tag exact-unwanted \
+               $(git -C server commit-tree -m c "$TREE") &&
+       git -C server tag prefix1 \
+               $(git -C server commit-tree -m d "$TREE") &&
+       git -C server tag prefix2 \
+               $(git -C server commit-tree -m e "$TREE") &&
+       git -C server tag fetch-by-sha1 \
+               $(git -C server commit-tree -m f "$TREE") &&
+       git -C server tag completely-unrelated \
+               $(git -C server commit-tree -m g "$TREE") &&
+
+       git init client &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
+               fetch "file://$(pwd)/server" \
+               dwim \
+               refs/tags/exact \
+               refs/tags/prefix*:refs/tags/prefix* \
+               "$(git -C server rev-parse fetch-by-sha1)" &&
+
+       # Ensure that the appropriate prefixes are sent (using a sample)
+       grep "fetch> ref-prefix dwim" trace &&
+       grep "fetch> ref-prefix refs/heads/dwim" trace &&
+       grep "fetch> ref-prefix refs/tags/prefix" trace &&
+
+       # Ensure that the correct objects are returned
+       git -C client cat-file -e $(git -C server rev-parse dwim) &&
+       git -C client cat-file -e $(git -C server rev-parse exact) &&
+       git -C client cat-file -e $(git -C server rev-parse prefix1) &&
+       git -C client cat-file -e $(git -C server rev-parse prefix2) &&
+       git -C client cat-file -e $(git -C server rev-parse fetch-by-sha1) &&
+       test_must_fail git -C client cat-file -e \
+               $(git -C server rev-parse dwim-unwanted) &&
+       test_must_fail git -C client cat-file -e \
+               $(git -C server rev-parse exact-unwanted) &&
+       test_must_fail git -C client cat-file -e \
+               $(git -C server rev-parse completely-unrelated)
+'
+
+test_expect_success 'fetch supports include-tag and tag following' '
+       rm -rf server client trace &&
+       git init server &&
+
+       test_commit -C server to_fetch &&
+       git -C server tag -a annotated_tag -m message &&
+
+       git init client &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
+               fetch "$(pwd)/server" to_fetch:to_fetch &&
+
+       grep "fetch> ref-prefix to_fetch" trace &&
+       grep "fetch> ref-prefix refs/tags/" trace &&
+       grep "fetch> include-tag" trace &&
+
+       git -C client cat-file -e $(git -C client rev-parse annotated_tag)
+'
+
 # Test protocol v2 with 'http://' transport
 #
 . "$TEST_DIRECTORY"/lib-httpd.sh
diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
new file mode 100755 (executable)
index 0000000..a73c55a
--- /dev/null
@@ -0,0 +1,377 @@
+#!/bin/sh
+
+test_description='upload-pack ref-in-want'
+
+. ./test-lib.sh
+
+get_actual_refs () {
+       sed -n -e '/wanted-refs/,/0001/{
+               /wanted-refs/d
+               /0001/d
+               p
+               }' <out | test-pkt-line unpack >actual_refs
+}
+
+get_actual_commits () {
+       sed -n -e '/packfile/,/0000/{
+               /packfile/d
+               p
+               }' <out | test-pkt-line unpack-sideband >o.pack &&
+       git index-pack o.pack &&
+       git verify-pack -v o.idx | grep commit | cut -c-40 | sort >actual_commits
+}
+
+check_output () {
+       get_actual_refs &&
+       test_cmp expected_refs actual_refs &&
+       get_actual_commits &&
+       test_cmp expected_commits actual_commits
+}
+
+# c(o/foo) d(o/bar)
+#        \ /
+#         b   e(baz)  f(master)
+#          \__  |  __/
+#             \ | /
+#               a
+test_expect_success 'setup repository' '
+       test_commit a &&
+       git checkout -b o/foo &&
+       test_commit b &&
+       test_commit c &&
+       git checkout -b o/bar b &&
+       test_commit d &&
+       git checkout -b baz a &&
+       test_commit e &&
+       git checkout master &&
+       test_commit f
+'
+
+test_expect_success 'config controls ref-in-want advertisement' '
+       git serve --advertise-capabilities >out &&
+       ! grep -a ref-in-want out &&
+
+       git config uploadpack.allowRefInWant false &&
+       git serve --advertise-capabilities >out &&
+       ! grep -a ref-in-want out &&
+
+       git config uploadpack.allowRefInWant true &&
+       git serve --advertise-capabilities >out &&
+       grep -a ref-in-want out
+'
+
+test_expect_success 'invalid want-ref line' '
+       test-pkt-line pack >in <<-EOF &&
+       command=fetch
+       0001
+       no-progress
+       want-ref refs/heads/non-existent
+       done
+       0000
+       EOF
+
+       test_must_fail git serve --stateless-rpc 2>out <in &&
+       grep "unknown ref" out
+'
+
+test_expect_success 'basic want-ref' '
+       cat >expected_refs <<-EOF &&
+       $(git rev-parse f) refs/heads/master
+       EOF
+       git rev-parse f | sort >expected_commits &&
+
+       test-pkt-line pack >in <<-EOF &&
+       command=fetch
+       0001
+       no-progress
+       want-ref refs/heads/master
+       have $(git rev-parse a)
+       done
+       0000
+       EOF
+
+       git serve --stateless-rpc >out <in &&
+       check_output
+'
+
+test_expect_success 'multiple want-ref lines' '
+       cat >expected_refs <<-EOF &&
+       $(git rev-parse c) refs/heads/o/foo
+       $(git rev-parse d) refs/heads/o/bar
+       EOF
+       git rev-parse c d | sort >expected_commits &&
+
+       test-pkt-line pack >in <<-EOF &&
+       command=fetch
+       0001
+       no-progress
+       want-ref refs/heads/o/foo
+       want-ref refs/heads/o/bar
+       have $(git rev-parse b)
+       done
+       0000
+       EOF
+
+       git serve --stateless-rpc >out <in &&
+       check_output
+'
+
+test_expect_success 'mix want and want-ref' '
+       cat >expected_refs <<-EOF &&
+       $(git rev-parse f) refs/heads/master
+       EOF
+       git rev-parse e f | sort >expected_commits &&
+
+       test-pkt-line pack >in <<-EOF &&
+       command=fetch
+       0001
+       no-progress
+       want-ref refs/heads/master
+       want $(git rev-parse e)
+       have $(git rev-parse a)
+       done
+       0000
+       EOF
+
+       git serve --stateless-rpc >out <in &&
+       check_output
+'
+
+test_expect_success 'want-ref with ref we already have commit for' '
+       cat >expected_refs <<-EOF &&
+       $(git rev-parse c) refs/heads/o/foo
+       EOF
+       >expected_commits &&
+
+       test-pkt-line pack >in <<-EOF &&
+       command=fetch
+       0001
+       no-progress
+       want-ref refs/heads/o/foo
+       have $(git rev-parse c)
+       done
+       0000
+       EOF
+
+       git serve --stateless-rpc >out <in &&
+       check_output
+'
+
+. "$TEST_DIRECTORY"/lib-httpd.sh
+start_httpd
+
+REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
+LOCAL_PRISTINE="$(pwd)/local_pristine"
+
+test_expect_success 'setup repos for change-while-negotiating test' '
+       (
+               git init "$REPO" &&
+               cd "$REPO" &&
+               >.git/git-daemon-export-ok &&
+               test_commit m1 &&
+               git tag -d m1 &&
+
+               # Local repo with many commits (so that negotiation will take
+               # more than 1 request/response pair)
+               git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
+               cd "$LOCAL_PRISTINE" &&
+               git checkout -b side &&
+               for i in $(seq 1 33); do test_commit s$i; done &&
+
+               # Add novel commits to upstream
+               git checkout master &&
+               cd "$REPO" &&
+               test_commit m2 &&
+               test_commit m3 &&
+               git tag -d m2 m3
+       ) &&
+       git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_sed/repo" &&
+       git -C "$LOCAL_PRISTINE" config protocol.version 2
+'
+
+inconsistency () {
+       # Simulate that the server initially reports $2 as the ref
+       # corresponding to $1, and after that, $1 as the ref corresponding to
+       # $1. This corresponds to the real-life situation where the server's
+       # repository appears to change during negotiation, for example, when
+       # different servers in a load-balancing arrangement serve (stateless)
+       # RPCs during a single negotiation.
+       printf "s/%s/%s/" \
+              $(git -C "$REPO" rev-parse $1 | tr -d "\n") \
+              $(git -C "$REPO" rev-parse $2 | tr -d "\n") \
+              >"$HTTPD_ROOT_PATH/one-time-sed"
+}
+
+test_expect_success 'server is initially ahead - no ref in want' '
+       git -C "$REPO" config uploadpack.allowRefInWant false &&
+       rm -rf local &&
+       cp -r "$LOCAL_PRISTINE" local &&
+       inconsistency master 1234567890123456789012345678901234567890 &&
+       test_must_fail git -C local fetch 2>err &&
+       grep "ERR upload-pack: not our ref" err
+'
+
+test_expect_success 'server is initially ahead - ref in want' '
+       git -C "$REPO" config uploadpack.allowRefInWant true &&
+       rm -rf local &&
+       cp -r "$LOCAL_PRISTINE" local &&
+       inconsistency master 1234567890123456789012345678901234567890 &&
+       git -C local fetch &&
+
+       git -C "$REPO" rev-parse --verify master >expected &&
+       git -C local rev-parse --verify refs/remotes/origin/master >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'server is initially behind - no ref in want' '
+       git -C "$REPO" config uploadpack.allowRefInWant false &&
+       rm -rf local &&
+       cp -r "$LOCAL_PRISTINE" local &&
+       inconsistency master "master^" &&
+       git -C local fetch &&
+
+       git -C "$REPO" rev-parse --verify "master^" >expected &&
+       git -C local rev-parse --verify refs/remotes/origin/master >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'server is initially behind - ref in want' '
+       git -C "$REPO" config uploadpack.allowRefInWant true &&
+       rm -rf local &&
+       cp -r "$LOCAL_PRISTINE" local &&
+       inconsistency master "master^" &&
+       git -C local fetch &&
+
+       git -C "$REPO" rev-parse --verify "master" >expected &&
+       git -C local rev-parse --verify refs/remotes/origin/master >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'server loses a ref - ref in want' '
+       git -C "$REPO" config uploadpack.allowRefInWant true &&
+       rm -rf local &&
+       cp -r "$LOCAL_PRISTINE" local &&
+       echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-sed" &&
+       test_must_fail git -C local fetch 2>err &&
+
+       grep "ERR unknown ref refs/heads/raster" err
+'
+
+stop_httpd
+
+REPO="$(pwd)/repo"
+LOCAL_PRISTINE="$(pwd)/local_pristine"
+
+# $REPO
+# c(o/foo) d(o/bar)
+#        \ /
+#         b   e(baz)  f(master)
+#          \__  |  __/
+#             \ | /
+#               a
+#
+# $LOCAL_PRISTINE
+#              s32(side)
+#              |
+#              .
+#              .
+#              |
+#              a(master)
+test_expect_success 'setup repos for fetching with ref-in-want tests' '
+       (
+               git init "$REPO" &&
+               cd "$REPO" &&
+               test_commit a &&
+
+               # Local repo with many commits (so that negotiation will take
+               # more than 1 request/response pair)
+               rm -rf "$LOCAL_PRISTINE" &&
+               git clone "file://$REPO" "$LOCAL_PRISTINE" &&
+               cd "$LOCAL_PRISTINE" &&
+               git checkout -b side &&
+               for i in $(seq 1 33); do test_commit s$i; done &&
+
+               # Add novel commits to upstream
+               git checkout master &&
+               cd "$REPO" &&
+               git checkout -b o/foo &&
+               test_commit b &&
+               test_commit c &&
+               git checkout -b o/bar b &&
+               test_commit d &&
+               git checkout -b baz a &&
+               test_commit e &&
+               git checkout master &&
+               test_commit f
+       ) &&
+       git -C "$REPO" config uploadpack.allowRefInWant true &&
+       git -C "$LOCAL_PRISTINE" config protocol.version 2
+'
+
+test_expect_success 'fetching with exact OID' '
+       test_when_finished "rm -f log" &&
+
+       rm -rf local &&
+       cp -r "$LOCAL_PRISTINE" local &&
+       GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
+               $(git -C "$REPO" rev-parse d):refs/heads/actual &&
+
+       git -C "$REPO" rev-parse "d" >expected &&
+       git -C local rev-parse refs/heads/actual >actual &&
+       test_cmp expected actual &&
+       grep "want $(git -C "$REPO" rev-parse d)" log
+'
+
+test_expect_success 'fetching multiple refs' '
+       test_when_finished "rm -f log" &&
+
+       rm -rf local &&
+       cp -r "$LOCAL_PRISTINE" local &&
+       GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin master baz &&
+
+       git -C "$REPO" rev-parse "master" "baz" >expected &&
+       git -C local rev-parse refs/remotes/origin/master refs/remotes/origin/baz >actual &&
+       test_cmp expected actual &&
+       grep "want-ref refs/heads/master" log &&
+       grep "want-ref refs/heads/baz" log
+'
+
+test_expect_success 'fetching ref and exact OID' '
+       test_when_finished "rm -f log" &&
+
+       rm -rf local &&
+       cp -r "$LOCAL_PRISTINE" local &&
+       GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
+               master $(git -C "$REPO" rev-parse b):refs/heads/actual &&
+
+       git -C "$REPO" rev-parse "master" "b" >expected &&
+       git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
+       test_cmp expected actual &&
+       grep "want $(git -C "$REPO" rev-parse b)" log &&
+       grep "want-ref refs/heads/master" log
+'
+
+test_expect_success 'fetching with wildcard that does not match any refs' '
+       test_when_finished "rm -f log" &&
+
+       rm -rf local &&
+       cp -r "$LOCAL_PRISTINE" local &&
+       git -C local fetch origin refs/heads/none*:refs/heads/* >out &&
+       test_must_be_empty out
+'
+
+test_expect_success 'fetching with wildcard that matches multiple refs' '
+       test_when_finished "rm -f log" &&
+
+       rm -rf local &&
+       cp -r "$LOCAL_PRISTINE" local &&
+       GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin refs/heads/o*:refs/heads/o* &&
+
+       git -C "$REPO" rev-parse "o/foo" "o/bar" >expected &&
+       git -C local rev-parse "o/foo" "o/bar" >actual &&
+       test_cmp expected actual &&
+       grep "want-ref refs/heads/o/foo" log &&
+       grep "want-ref refs/heads/o/bar" log
+'
+
+test_done
index ee5757966f597637a3f9f1602a9ef4bd7ffd908d..aaaa722ccab016cc5847d5b6bbc5a3879a0b3fbc 100755 (executable)
@@ -126,7 +126,7 @@ test_expect_success 'forced push' '
 test_expect_success 'cloning without refspec' '
        GIT_REMOTE_TESTGIT_REFSPEC="" \
        git clone "testgit::${PWD}/server" local2 2>error &&
-       grep "This remote helper should implement refspec capability" error &&
+       test_i18ngrep "this remote helper should implement refspec capability" error &&
        compare_refs local2 HEAD server HEAD
 '
 
@@ -134,7 +134,7 @@ test_expect_success 'pulling without refspecs' '
        (cd local2 &&
        git reset --hard &&
        GIT_REMOTE_TESTGIT_REFSPEC="" git pull 2>../error) &&
-       grep "This remote helper should implement refspec capability" error &&
+       test_i18ngrep "this remote helper should implement refspec capability" error &&
        compare_refs local2 HEAD server HEAD
 '
 
@@ -146,7 +146,7 @@ test_expect_success 'pushing without refspecs' '
        GIT_REMOTE_TESTGIT_REFSPEC="" &&
        export GIT_REMOTE_TESTGIT_REFSPEC &&
        test_must_fail git push 2>../error) &&
-       grep "remote-helper doesn.t support push; refspec needed" error
+       test_i18ngrep "remote-helper doesn.t support push; refspec needed" error
 '
 
 test_expect_success 'pulling without marks' '
@@ -246,7 +246,7 @@ test_expect_success 'proper failure checks for fetching' '
        (cd local &&
        test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
        cat error &&
-       grep -q "Error while running fast-import" error
+       test_i18ngrep -q "error while running fast-import" error
        )
 '
 
index 969e4e9e5261640dc690806ed06f8e58e760633f..fb4d295aa0f17c6aa967555ed92b4bc02884a9b3 100755 (executable)
@@ -58,8 +58,7 @@ test_expect_success 'rev-list A..B and rev-list ^A B are the same' '
 
 test_expect_success 'propagate uninteresting flag down correctly' '
        git rev-list --objects ^HEAD^{tree} HEAD^{tree} >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'symleft flag bit is propagated down from tag' '
index 20e3e2554a132552b5e398a2c449cedbef6ccb1e..916d9692bc05fdc87b28b7dbd4afdb173dd1d244 100755 (executable)
@@ -31,8 +31,7 @@ test_expect_success setup '
 test_expect_success 'one is ancestor of others and should not be shown' '
 
        git rev-list one --not four >result &&
-       >expect &&
-       test_cmp expect result
+       test_must_be_empty result
 
 '
 
@@ -144,8 +143,7 @@ test_expect_success 'ancestors with the same commit time' '
                test_commit t$i
        done &&
        git rev-list t1^! --not t$i >result &&
-       >expect &&
-       test_cmp expect result
+       test_must_be_empty result
 '
 
 test_done
index d3453c583c1921a10409c16b5e2cf949edde6cd2..02936c2f24aeaa3961bc11c623b7fd25d3280c43 100755 (executable)
@@ -256,31 +256,27 @@ test_expect_success 'rev-list accumulates multiple --exclude' '
 '
 
 test_expect_failure 'rev-list should succeed with empty output on empty stdin' '
-       >expect &&
        git rev-list --stdin <expect >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'rev-list should succeed with empty output with all refs excluded' '
-       >expect &&
        git rev-list --exclude=* --all >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'rev-list should succeed with empty output with empty --all' '
        (
                test_create_repo empty &&
                cd empty &&
-               >expect &&
                git rev-list --all >actual &&
-               test_cmp expect actual
+               test_must_be_empty actual
        )
 '
 
 test_expect_success 'rev-list should succeed with empty output with empty glob' '
-       >expect &&
        git rev-list --glob=does-not-match-anything >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
index dabebaee0b7b474387d4bc9b466b969624822d6d..beadaf6cca054bc2d821be19b4358286c6107165 100755 (executable)
@@ -95,10 +95,9 @@ test_expect_success 'rev-list --ancestry-path F...I' '
 
 # G.t is dropped in an "-s ours" merge
 test_expect_success 'rev-list G..M -- G.t' '
-       >expect &&
        git rev-list --format=%s G..M -- G.t |
        sed -e "/^commit /d" >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'rev-list --ancestry-path G..M -- G.t' '
index 2af1beec5f6f330072b3739e3c8b855f988173a9..46b506b3b7b6f6308994082abda2fcaddaaadf0e 100755 (executable)
@@ -89,9 +89,6 @@ test_expect_success 'modify/delete + directory/file conflict' '
 '
 
 test_expect_success 'modify/delete + directory/file conflict; other way' '
-       # Yes, we really need the double reset since "letters" appears as
-       # both a file and a directory.
-       git reset --hard &&
        git reset --hard &&
        git clean -f &&
        git checkout modify^0 &&
index b760c223c6a56609b7dace5353671aec8243b85d..53cc9b2ffbdbc551c358c8d5d1d4185ef63f0c0b 100755 (executable)
@@ -893,8 +893,7 @@ test_expect_success 'do not follow renames for empty files' '
        git mv empty1 empty2 &&
        git commit -m rename &&
        test_must_fail git merge empty-base &&
-       >expect &&
-       test_cmp expect empty2
+       test_must_be_empty empty2
 '
 
 test_done
index 7d5bc784721411a3abe475a8ed9f291204072b7d..793f0c8bf38aba350542c0710f509a1c69b33a9b 100755 (executable)
@@ -29,6 +29,34 @@ test_expect_success 'subtree available and works like recursive' '
 
 '
 
+test_expect_success 'setup branch sub' '
+       git checkout --orphan sub &&
+       git rm -rf . &&
+       test_commit foo
+'
+
+test_expect_success 'setup branch main' '
+       git checkout -b main master &&
+       git merge -s ours --no-commit --allow-unrelated-histories sub &&
+       git read-tree --prefix=dir/ -u sub &&
+       git commit -m "initial merge of sub into main" &&
+       test_path_is_file dir/foo.t &&
+       test_path_is_file hello
+'
+
+test_expect_success 'update branch sub' '
+       git checkout sub &&
+       test_commit bar
+'
+
+test_expect_success 'update branch main' '
+       git checkout main &&
+       git merge -s subtree sub -m "second merge of sub into main" &&
+       test_path_is_file dir/bar.t &&
+       test_path_is_file dir/foo.t &&
+       test_path_is_file hello
+'
+
 test_expect_success 'setup' '
        mkdir git-gui &&
        cd git-gui &&
index 892cf08743007aec0424edd6d7428489109ead59..59e52c5a09eebfabe932c5c33a842236f68ffdfb 100755 (executable)
@@ -345,40 +345,97 @@ test_expect_success 'git detects conflict merging criss-cross+modify/delete, rev
        )
 '
 
+#      SORRY FOR THE SUPER LONG DESCRIPTION, BUT THIS NEXT ONE IS HAIRY
 #
 # criss-cross + d/f conflict via add/add:
 #   Commit A: Neither file 'a' nor directory 'a/' exists.
 #   Commit B: Introduce 'a'
 #   Commit C: Introduce 'a/file'
-#   Commit D: Merge B & C, keeping 'a' and deleting 'a/'
-#
-# Two different later cases:
+#   Commit D1: Merge B & C, keeping 'a'    and deleting 'a/'
 #   Commit E1: Merge B & C, deleting 'a' but keeping 'a/file'
-#   Commit E2: Merge B & C, deleting 'a' but keeping a slightly modified 'a/file'
 #
-#      B   D
+#      B   D1 or D2
 #      o---o
 #     / \ / \
 #  A o   X   ? F
 #     \ / \ /
 #      o---o
-#      C   E1 or E2
+#      C   E1 or E2 or E3
+#
+# I'll describe D2, E2, & E3 (which are alternatives for D1 & E1) more below...
+#
+# Merging D1 & E1 requires we first create a virtual merge base X from
+# merging A & B in memory.  There are several possibilities for the merge-base:
+#   1: Keep both 'a' and 'a/file' (assuming crazy filesystem allowing a tree
+#      with a directory and file at same path): results in merge of D1 & E1
+#      being clean with both files deleted.  Bad (no conflict detected).
+#   2: Keep 'a' but not 'a/file': Merging D1 & E1 is clean and matches E1.  Bad.
+#   3: Keep 'a/file' but not 'a': Merging D1 & E1 is clean and matches D1.  Bad.
+#   4: Keep neither file: Merging D1 & E1 reports the D/F add/add conflict.
+#
+# So 4 sounds good for this case, but if we were to merge D1 & E3, where E3
+# is defined as:
+#   Commit E3: Merge B & C, keeping modified a, and deleting a/
+# then we'd get an add/add conflict for 'a', which seems suboptimal.  A little
+# creativity leads us to an alternate choice:
+#   5: Keep 'a' as 'a~$UNIQUE' and a/file; results:
+#        Merge D1 & E1: rename/delete conflict for 'a'; a/file silently deleted
+#        Merge D1 & E3 is clean, as expected.
+#
+# So choice 5 at least provides some kind of conflict for the original case,
+# and can merge cleanly as expected with D1 and E3.  It also made things just
+# slightly funny for merging D1 and e$, where E4 is defined as:
+#   Commit E4: Merge B & C, modifying 'a' and renaming to 'a2', and deleting 'a/'
+# in this case, we'll get a rename/rename(1to2) conflict because a~$UNIQUE
+# gets renamed to 'a' in D1 and to 'a2' in E4.  But that's better than having
+# two files (both 'a' and 'a2') sitting around without the user being notified
+# that we could detect they were related and need to be merged.  Also, choice
+# 5 makes the handling of 'a/file' seem suboptimal.  What if we were to merge
+# D2 and E4, where D2 is:
+#   Commit D2: Merge B & C, renaming 'a'->'a2', keeping 'a/file'
+# This would result in a clean merge with 'a2' having three-way merged
+# contents (good), and deleting 'a/' (bad) -- it doesn't detect the
+# conflict in how the different sides treated a/file differently.
+# Continuing down the creative route:
+#   6: Keep 'a' as 'a~$UNIQUE1' and keep 'a/' as 'a~$UNIQUE2/'; results:
+#        Merge D1 & E1: rename/delete conflict for 'a' and each path under 'a/'.
+#        Merge D1 & E3: clean, as expected.
+#        Merge D1 & E4: rename/rename(1to2) conflict on 'a' vs 'a2'.
+#        Merge D2 & E4: clean for 'a2', rename/delete for a/file
 #
-# Merging D & E1 requires we first create a virtual merge base X from
-# merging A & B in memory.  Now, if X could keep both 'a' and 'a/file' in
-# the index, then the merge of D & E1 could be resolved cleanly with both
-# 'a' and 'a/file' removed.  Since git does not currently allow creating
-# such a tree, the best we can do is have X contain both 'a~<unique>' and
-# 'a/file' resulting in the merge of D and E1 having a rename/delete
-# conflict for 'a'.  (Although this merge appears to be unsolvable with git
-# currently, git could do a lot better than it currently does with these
-# d/f conflicts, which is the purpose of this test.)
+# Choice 6 could cause rename detection to take longer (providing more targets
+# that need to be searched).  Also, the conflict message for each path under
+# 'a/' might be annoying unless we can detect it at the directory level, print
+# it once, and then suppress it for individual filepaths underneath.
 #
-# Merge of D & E2 has similar issues for path 'a', but should always result
-# in a modify/delete conflict for path 'a/file'.
 #
-# We run each merge in both directions, to check for directional issues
-# with D/F conflict handling.
+# As of time of writing, git uses choice 5.  Directory rename detection and
+# rename detection performance improvements might make choice 6 a desirable
+# improvement.  But we can at least document where we fall short for now...
+#
+#
+# Historically, this testcase also used:
+#   Commit E2: Merge B & C, deleting 'a' but keeping slightly modified 'a/file'
+# The merge of D1 & E2 is very similar to D1 & E1 -- it has similar issues for
+# path 'a', but should always result in a modify/delete conflict for path
+# 'a/file'.  These tests ran the two merges
+#   D1 & E1
+#   D1 & E2
+# in both directions, to check for directional issues with D/F conflict
+# handling. Later we added
+#   D1 & E3
+#   D1 & E4
+#   D2 & E4
+# for good measure, though we only ran those one way because we had pretty
+# good confidence in merge-recursive's directional handling of D/F issues.
+#
+# Just to summarize all the intermediate merge commits:
+#   Commit D1: Merge B & C, keeping a    and deleting a/
+#   Commit D2: Merge B & C, renaming a->a2, keeping a/file
+#   Commit E1: Merge B & C, deleting a but keeping a/file
+#   Commit E2: Merge B & C, deleting a but keeping slightly modified a/file
+#   Commit E3: Merge B & C, keeping modified a, and deleting a/
+#   Commit E4: Merge B & C, modifying 'a' and renaming to 'a2', and deleting 'a/'
 #
 
 test_expect_success 'setup differently handled merges of directory/file conflict' '
@@ -395,56 +452,70 @@ test_expect_success 'setup differently handled merges of directory/file conflict
                git branch B &&
                git checkout -b C &&
                mkdir a &&
-               echo 10 >a/file &&
+               test_write_lines a b c d e f g >a/file &&
                git add a/file &&
                test_tick &&
                git commit -m C &&
 
                git checkout B &&
-               echo 5 >a &&
+               test_write_lines 1 2 3 4 5 6 7 >a &&
                git add a &&
                test_tick &&
                git commit -m B &&
 
                git checkout B^0 &&
-               test_must_fail git merge C &&
-               git clean -f &&
-               rm -rf a/ &&
-               echo 5 >a &&
-               git add a &&
-               test_tick &&
-               git commit -m D &&
-               git tag D &&
+               git merge -s ours -m D1 C^0 &&
+               git tag D1 &&
+
+               git checkout B^0 &&
+               test_must_fail git merge C^0 &&
+               git clean -fd &&
+               git rm -rf a/ &&
+               git rm a &&
+               git cat-file -p B:a >a2 &&
+               git add a2 &&
+               git commit -m D2 &&
+               git tag D2 &&
 
                git checkout C^0 &&
-               test_must_fail git merge B &&
-               git clean -f &&
-               git rm --cached a &&
-               echo 10 >a/file &&
-               git add a/file &&
-               test_tick &&
-               git commit -m E1 &&
+               git merge -s ours -m E1 B^0 &&
                git tag E1 &&
 
                git checkout C^0 &&
-               test_must_fail git merge B &&
-               git clean -f &&
-               git rm --cached a &&
-               printf "10\n11\n" >a/file &&
+               git merge -s ours -m E2 B^0 &&
+               test_write_lines a b c d e f g h >a/file &&
                git add a/file &&
-               test_tick &&
-               git commit -m E2 &&
-               git tag E2
+               git commit --amend -C HEAD &&
+               git tag E2 &&
+
+               git checkout C^0 &&
+               test_must_fail git merge B^0 &&
+               git clean -fd &&
+               git rm -rf a/ &&
+               test_write_lines 1 2 3 4 5 6 7 8 >a &&
+               git add a &&
+               git commit -m E3 &&
+               git tag E3 &&
+
+               git checkout C^0 &&
+               test_must_fail git merge B^0 &&
+               git clean -fd &&
+               git rm -rf a/ &&
+               git rm a &&
+               test_write_lines 1 2 3 4 5 6 7 8 >a2 &&
+               git add a2 &&
+               git commit -m E4 &&
+               git tag E4
        )
 '
 
-test_expect_success 'merge of D & E1 fails but has appropriate contents' '
+test_expect_success 'merge of D1 & E1 fails but has appropriate contents' '
        test_when_finished "git -C directory-file reset --hard" &&
        test_when_finished "git -C directory-file clean -fdqx" &&
        (
                cd directory-file &&
 
-               git checkout D^0 &&
+               git checkout D1^0 &&
 
                test_must_fail git merge -s recursive E1^0 &&
 
@@ -463,7 +534,7 @@ test_expect_success 'merge of D & E1 fails but has appropriate contents' '
        )
 '
 
-test_expect_success 'merge of E1 & D fails but has appropriate contents' '
+test_expect_success 'merge of E1 & D1 fails but has appropriate contents' '
        test_when_finished "git -C directory-file reset --hard" &&
        test_when_finished "git -C directory-file clean -fdqx" &&
        (
@@ -471,7 +542,7 @@ test_expect_success 'merge of E1 & D fails but has appropriate contents' '
 
                git checkout E1^0 &&
 
-               test_must_fail git merge -s recursive D^0 &&
+               test_must_fail git merge -s recursive D1^0 &&
 
                git ls-files -s >out &&
                test_line_count = 2 out &&
@@ -488,13 +559,13 @@ test_expect_success 'merge of E1 & D fails but has appropriate contents' '
        )
 '
 
-test_expect_success 'merge of D & E2 fails but has appropriate contents' '
+test_expect_success 'merge of D1 & E2 fails but has appropriate contents' '
        test_when_finished "git -C directory-file reset --hard" &&
        test_when_finished "git -C directory-file clean -fdqx" &&
        (
                cd directory-file &&
 
-               git checkout D^0 &&
+               git checkout D1^0 &&
 
                test_must_fail git merge -s recursive E2^0 &&
 
@@ -515,7 +586,7 @@ test_expect_success 'merge of D & E2 fails but has appropriate contents' '
        )
 '
 
-test_expect_success 'merge of E2 & D fails but has appropriate contents' '
+test_expect_success 'merge of E2 & D1 fails but has appropriate contents' '
        test_when_finished "git -C directory-file reset --hard" &&
        test_when_finished "git -C directory-file clean -fdqx" &&
        (
@@ -523,7 +594,7 @@ test_expect_success 'merge of E2 & D fails but has appropriate contents' '
 
                git checkout E2^0 &&
 
-               test_must_fail git merge -s recursive D^0 &&
+               test_must_fail git merge -s recursive D1^0 &&
 
                git ls-files -s >out &&
                test_line_count = 4 out &&
@@ -538,7 +609,82 @@ test_expect_success 'merge of E2 & D fails but has appropriate contents' '
                        :3:a  :2:a/file  :1:a/file  :0:ignore-me &&
                test_cmp expect actual &&
 
-               test_path_is_file a~D^0
+               test_path_is_file a~D1^0
+       )
+'
+
+test_expect_success 'merge of D1 & E3 succeeds' '
+       test_when_finished "git -C directory-file reset --hard" &&
+       test_when_finished "git -C directory-file clean -fdqx" &&
+       (
+               cd directory-file &&
+
+               git checkout D1^0 &&
+
+               git merge -s recursive E3^0 &&
+
+               git ls-files -s >out &&
+               test_line_count = 2 out &&
+               git ls-files -u >out &&
+               test_line_count = 0 out &&
+               git ls-files -o >out &&
+               test_line_count = 1 out &&
+
+               git rev-parse >expect    \
+                       A:ignore-me  E3:a &&
+               git rev-parse   >actual   \
+                       :0:ignore-me :0:a &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'merge of D1 & E4 notifies user a and a2 are related' '
+       test_when_finished "git -C directory-file reset --hard" &&
+       test_when_finished "git -C directory-file clean -fdqx" &&
+       (
+               cd directory-file &&
+
+               git checkout D1^0 &&
+
+               test_must_fail git merge -s recursive E4^0 &&
+
+               git ls-files -s >out &&
+               test_line_count = 4 out &&
+               git ls-files -u >out &&
+               test_line_count = 3 out &&
+               git ls-files -o >out &&
+               test_line_count = 1 out &&
+
+               git rev-parse >expect                  \
+                       A:ignore-me  B:a   D1:a  E4:a2 &&
+               git rev-parse   >actual                \
+                       :0:ignore-me :1:a~Temporary\ merge\ branch\ 2  :2:a  :3:a2 &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_failure 'merge of D2 & E4 merges a2s & reports conflict for a/file' '
+       test_when_finished "git -C directory-file reset --hard" &&
+       test_when_finished "git -C directory-file clean -fdqx" &&
+       (
+               cd directory-file &&
+
+               git checkout D2^0 &&
+
+               test_must_fail git merge -s recursive E4^0 &&
+
+               git ls-files -s >out &&
+               test_line_count = 3 out &&
+               git ls-files -u >out &&
+               test_line_count = 1 out &&
+               git ls-files -o >out &&
+               test_line_count = 1 out &&
+
+               git rev-parse >expect                 \
+                       A:ignore-me  E4:a2  D2:a/file &&
+               git rev-parse   >actual               \
+                       :0:ignore-me :0:a2  :2:a/file &&
+               test_cmp expect actual
        )
 '
 
@@ -805,4 +951,455 @@ test_expect_success 'virtual merge base handles rename/rename(1to2)/add-dest' '
        )
 '
 
+#
+# criss-cross with modify/modify on a symlink:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: simple simlink fickle->lagoon
+#   Commit B: redirect fickle->disneyland
+#   Commit C: redirect fickle->home
+#   Commit D: merge B&C, resolving in favor of B
+#   Commit E: merge B&C, resolving in favor of C
+#
+# This is an obvious modify/modify conflict for the symlink 'fickle'.  Can
+# git detect it?
+
+test_expect_success 'setup symlink modify/modify' '
+       test_create_repo symlink-modify-modify &&
+       (
+               cd symlink-modify-modify &&
+
+               test_ln_s_add lagoon fickle &&
+               git commit -m A &&
+               git tag A &&
+
+               git checkout -b B A &&
+               git rm fickle &&
+               test_ln_s_add disneyland fickle &&
+               git commit -m B &&
+
+               git checkout -b C A &&
+               git rm fickle &&
+               test_ln_s_add home fickle &&
+               git add fickle &&
+               git commit -m C &&
+
+               git checkout -q B^0 &&
+               git merge -s ours -m D C^0 &&
+               git tag D &&
+
+               git checkout -q C^0 &&
+               git merge -s ours -m E B^0 &&
+               git tag E
+       )
+'
+
+test_expect_failure 'check symlink modify/modify' '
+       (
+               cd symlink-modify-modify &&
+
+               git checkout D^0 &&
+
+               test_must_fail git merge -s recursive E^0 &&
+
+               git ls-files -s >out &&
+               test_line_count = 3 out &&
+               git ls-files -u >out &&
+               test_line_count = 3 out &&
+               git ls-files -o >out &&
+               test_line_count = 1 out
+       )
+'
+
+#
+# criss-cross with add/add of a symlink:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: No symlink or path exists yet
+#   Commit B: set up symlink: fickle->disneyland
+#   Commit C: set up symlink: fickle->home
+#   Commit D: merge B&C, resolving in favor of B
+#   Commit E: merge B&C, resolving in favor of C
+#
+# This is an obvious add/add conflict for the symlink 'fickle'.  Can
+# git detect it?
+
+test_expect_success 'setup symlink add/add' '
+       test_create_repo symlink-add-add &&
+       (
+               cd symlink-add-add &&
+
+               touch ignoreme &&
+               git add ignoreme &&
+               git commit -m A &&
+               git tag A &&
+
+               git checkout -b B A &&
+               test_ln_s_add disneyland fickle &&
+               git commit -m B &&
+
+               git checkout -b C A &&
+               test_ln_s_add home fickle &&
+               git add fickle &&
+               git commit -m C &&
+
+               git checkout -q B^0 &&
+               git merge -s ours -m D C^0 &&
+               git tag D &&
+
+               git checkout -q C^0 &&
+               git merge -s ours -m E B^0 &&
+               git tag E
+       )
+'
+
+test_expect_failure 'check symlink add/add' '
+       (
+               cd symlink-add-add &&
+
+               git checkout D^0 &&
+
+               test_must_fail git merge -s recursive E^0 &&
+
+               git ls-files -s >out &&
+               test_line_count = 2 out &&
+               git ls-files -u >out &&
+               test_line_count = 2 out &&
+               git ls-files -o >out &&
+               test_line_count = 1 out
+       )
+'
+
+#
+# criss-cross with modify/modify on a submodule:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: simple submodule repo
+#   Commit B: update repo
+#   Commit C: update repo differently
+#   Commit D: merge B&C, resolving in favor of B
+#   Commit E: merge B&C, resolving in favor of C
+#
+# This is an obvious modify/modify conflict for the submodule 'repo'.  Can
+# git detect it?
+
+test_expect_success 'setup submodule modify/modify' '
+       test_create_repo submodule-modify-modify &&
+       (
+               cd submodule-modify-modify &&
+
+               test_create_repo submod &&
+               (
+                       cd submod &&
+                       touch file-A &&
+                       git add file-A &&
+                       git commit -m A &&
+                       git tag A &&
+
+                       git checkout -b B A &&
+                       touch file-B &&
+                       git add file-B &&
+                       git commit -m B &&
+                       git tag B &&
+
+                       git checkout -b C A &&
+                       touch file-C &&
+                       git add file-C &&
+                       git commit -m C &&
+                       git tag C
+               ) &&
+
+               git -C submod reset --hard A &&
+               git add submod &&
+               git commit -m A &&
+               git tag A &&
+
+               git checkout -b B A &&
+               git -C submod reset --hard B &&
+               git add submod &&
+               git commit -m B &&
+
+               git checkout -b C A &&
+               git -C submod reset --hard C &&
+               git add submod &&
+               git commit -m C &&
+
+               git checkout -q B^0 &&
+               git merge -s ours -m D C^0 &&
+               git tag D &&
+
+               git checkout -q C^0 &&
+               git merge -s ours -m E B^0 &&
+               git tag E
+       )
+'
+
+test_expect_failure 'check submodule modify/modify' '
+       (
+               cd submodule-modify-modify &&
+
+               git checkout D^0 &&
+
+               test_must_fail git merge -s recursive E^0 &&
+
+               git ls-files -s >out &&
+               test_line_count = 3 out &&
+               git ls-files -u >out &&
+               test_line_count = 3 out &&
+               git ls-files -o >out &&
+               test_line_count = 1 out
+       )
+'
+
+#
+# criss-cross with add/add on a submodule:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: nothing of note
+#   Commit B: introduce submodule repo
+#   Commit C: introduce submodule repo at different commit
+#   Commit D: merge B&C, resolving in favor of B
+#   Commit E: merge B&C, resolving in favor of C
+#
+# This is an obvious add/add conflict for the submodule 'repo'.  Can
+# git detect it?
+
+test_expect_success 'setup submodule add/add' '
+       test_create_repo submodule-add-add &&
+       (
+               cd submodule-add-add &&
+
+               test_create_repo submod &&
+               (
+                       cd submod &&
+                       touch file-A &&
+                       git add file-A &&
+                       git commit -m A &&
+                       git tag A &&
+
+                       git checkout -b B A &&
+                       touch file-B &&
+                       git add file-B &&
+                       git commit -m B &&
+                       git tag B &&
+
+                       git checkout -b C A &&
+                       touch file-C &&
+                       git add file-C &&
+                       git commit -m C &&
+                       git tag C
+               ) &&
+
+               touch irrelevant-file &&
+               git add irrelevant-file &&
+               git commit -m A &&
+               git tag A &&
+
+               git checkout -b B A &&
+               git -C submod reset --hard B &&
+               git add submod &&
+               git commit -m B &&
+
+               git checkout -b C A &&
+               git -C submod reset --hard C &&
+               git add submod &&
+               git commit -m C &&
+
+               git checkout -q B^0 &&
+               git merge -s ours -m D C^0 &&
+               git tag D &&
+
+               git checkout -q C^0 &&
+               git merge -s ours -m E B^0 &&
+               git tag E
+       )
+'
+
+test_expect_failure 'check submodule add/add' '
+       (
+               cd submodule-add-add &&
+
+               git checkout D^0 &&
+
+               test_must_fail git merge -s recursive E^0 &&
+
+               git ls-files -s >out &&
+               test_line_count = 3 out &&
+               git ls-files -u >out &&
+               test_line_count = 2 out &&
+               git ls-files -o >out &&
+               test_line_count = 1 out
+       )
+'
+
+#
+# criss-cross with conflicting entry types:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: nothing of note
+#   Commit B: introduce submodule 'path'
+#   Commit C: introduce symlink 'path'
+#   Commit D: merge B&C, resolving in favor of B
+#   Commit E: merge B&C, resolving in favor of C
+#
+# This is an obvious add/add conflict for 'path'.  Can git detect it?
+
+test_expect_success 'setup conflicting entry types (submodule vs symlink)' '
+       test_create_repo submodule-symlink-add-add &&
+       (
+               cd submodule-symlink-add-add &&
+
+               test_create_repo path &&
+               (
+                       cd path &&
+                       touch file-B &&
+                       git add file-B &&
+                       git commit -m B &&
+                       git tag B
+               ) &&
+
+               touch irrelevant-file &&
+               git add irrelevant-file &&
+               git commit -m A &&
+               git tag A &&
+
+               git checkout -b B A &&
+               git -C path reset --hard B &&
+               git add path &&
+               git commit -m B &&
+
+               git checkout -b C A &&
+               rm -rf path/ &&
+               test_ln_s_add irrelevant-file path &&
+               git commit -m C &&
+
+               git checkout -q B^0 &&
+               git merge -s ours -m D C^0 &&
+               git tag D &&
+
+               git checkout -q C^0 &&
+               git merge -s ours -m E B^0 &&
+               git tag E
+       )
+'
+
+test_expect_failure 'check conflicting entry types (submodule vs symlink)' '
+       (
+               cd submodule-symlink-add-add &&
+
+               git checkout D^0 &&
+
+               test_must_fail git merge -s recursive E^0 &&
+
+               git ls-files -s >out &&
+               test_line_count = 3 out &&
+               git ls-files -u >out &&
+               test_line_count = 2 out &&
+               git ls-files -o >out &&
+               test_line_count = 1 out
+       )
+'
+
+#
+# criss-cross with regular files that have conflicting modes:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: nothing of note
+#   Commit B: introduce file source_me.bash, not executable
+#   Commit C: introduce file source_me.bash, executable
+#   Commit D: merge B&C, resolving in favor of B
+#   Commit E: merge B&C, resolving in favor of C
+#
+# This is an obvious add/add mode conflict.  Can git detect it?
+
+test_expect_success 'setup conflicting modes for regular file' '
+       test_create_repo regular-file-mode-conflict &&
+       (
+               cd regular-file-mode-conflict &&
+
+               touch irrelevant-file &&
+               git add irrelevant-file &&
+               git commit -m A &&
+               git tag A &&
+
+               git checkout -b B A &&
+               echo "command_to_run" >source_me.bash &&
+               git add source_me.bash &&
+               git commit -m B &&
+
+               git checkout -b C A &&
+               echo "command_to_run" >source_me.bash &&
+               git add source_me.bash &&
+               test_chmod +x source_me.bash &&
+               git commit -m C &&
+
+               git checkout -q B^0 &&
+               git merge -s ours -m D C^0 &&
+               git tag D &&
+
+               git checkout -q C^0 &&
+               git merge -s ours -m E B^0 &&
+               git tag E
+       )
+'
+
+test_expect_failure 'check conflicting modes for regular file' '
+       (
+               cd regular-file-mode-conflict &&
+
+               git checkout D^0 &&
+
+               test_must_fail git merge -s recursive E^0 &&
+
+               git ls-files -s >out &&
+               test_line_count = 3 out &&
+               git ls-files -u >out &&
+               test_line_count = 2 out &&
+               git ls-files -o >out &&
+               test_line_count = 1 out
+       )
+'
+
 test_done
index 661b633478fae7ceeb50736a4c675e7b95f5042a..b97aca7fa263f79520013b14d90fa0b49031484b 100755 (executable)
@@ -323,7 +323,6 @@ test_expect_success 'rename/directory conflict + content merge conflict' '
        (
                cd rename-directory-1 &&
 
-               git reset --hard &&
                git reset --hard &&
                git clean -fdqx &&
 
@@ -693,4 +692,249 @@ test_expect_success 'rename/rename/add-dest merge still knows about conflicting
        )
 '
 
+# Testcase rad, rename/add/delete
+#   Commit O: foo
+#   Commit A: rm foo, add different bar
+#   Commit B: rename foo->bar
+#   Expected: CONFLICT (rename/add/delete), two-way merged bar
+
+test_expect_success 'rad-setup: rename/add/delete conflict' '
+       test_create_repo rad &&
+       (
+               cd rad &&
+               echo "original file" >foo &&
+               git add foo &&
+               git commit -m "original" &&
+
+               git branch O &&
+               git branch A &&
+               git branch B &&
+
+               git checkout A &&
+               git rm foo &&
+               echo "different file" >bar &&
+               git add bar &&
+               git commit -m "Remove foo, add bar" &&
+
+               git checkout B &&
+               git mv foo bar &&
+               git commit -m "rename foo to bar"
+       )
+'
+
+test_expect_failure 'rad-check: rename/add/delete conflict' '
+       (
+               cd rad &&
+
+               git checkout B^0 &&
+               test_must_fail git merge -s recursive A^0 >out 2>err &&
+
+               # Not sure whether the output should contain just one
+               # "CONFLICT (rename/add/delete)" line, or if it should break
+               # it into a pair of "CONFLICT (rename/delete)" and
+               # "CONFLICT (rename/add)"; allow for either.
+               test_i18ngrep "CONFLICT (rename.*add)" out &&
+               test_i18ngrep "CONFLICT (rename.*delete)" out &&
+               test_must_be_empty err &&
+
+               git ls-files -s >file_count &&
+               test_line_count = 2 file_count &&
+               git ls-files -u >file_count &&
+               test_line_count = 2 file_count &&
+               git ls-files -o >file_count &&
+               test_line_count = 2 file_count &&
+
+               git rev-parse >actual \
+                       :2:bar :3:bar &&
+               git rev-parse >expect \
+                       B:bar  A:bar  &&
+
+               test_cmp file_is_missing foo &&
+               # bar should have two-way merged contents of the different
+               # versions of bar; check that content from both sides is
+               # present.
+               grep original bar &&
+               grep different bar
+       )
+'
+
+# Testcase rrdd, rename/rename(2to1)/delete/delete
+#   Commit O: foo, bar
+#   Commit A: rename foo->baz, rm bar
+#   Commit B: rename bar->baz, rm foo
+#   Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz
+
+test_expect_success 'rrdd-setup: rename/rename(2to1)/delete/delete conflict' '
+       test_create_repo rrdd &&
+       (
+               cd rrdd &&
+               echo foo >foo &&
+               echo bar >bar &&
+               git add foo bar &&
+               git commit -m O &&
+
+               git branch O &&
+               git branch A &&
+               git branch B &&
+
+               git checkout A &&
+               git mv foo baz &&
+               git rm bar &&
+               git commit -m "Rename foo, remove bar" &&
+
+               git checkout B &&
+               git mv bar baz &&
+               git rm foo &&
+               git commit -m "Rename bar, remove foo"
+       )
+'
+
+test_expect_failure 'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
+       (
+               cd rrdd &&
+
+               git checkout A^0 &&
+               test_must_fail git merge -s recursive B^0 >out 2>err &&
+
+               # Not sure whether the output should contain just one
+               # "CONFLICT (rename/rename/delete/delete)" line, or if it
+               # should break it into three: "CONFLICT (rename/rename)" and
+               # two "CONFLICT (rename/delete)" lines; allow for either.
+               test_i18ngrep "CONFLICT (rename/rename)" out &&
+               test_i18ngrep "CONFLICT (rename.*delete)" out &&
+               test_must_be_empty err &&
+
+               git ls-files -s >file_count &&
+               test_line_count = 2 file_count &&
+               git ls-files -u >file_count &&
+               test_line_count = 2 file_count &&
+               git ls-files -o >file_count &&
+               test_line_count = 2 file_count &&
+
+               git rev-parse >actual \
+                       :2:baz :3:baz &&
+               git rev-parse >expect \
+                       O:foo  O:bar  &&
+
+               test_cmp file_is_missing foo &&
+               test_cmp file_is_missing bar &&
+               # baz should have two-way merged contents of the original
+               # contents of foo and bar; check that content from both sides
+               # is present.
+               grep foo baz &&
+               grep bar baz
+       )
+'
+
+# Testcase mod6, chains of rename/rename(1to2) and rename/rename(2to1)
+#   Commit O: one,      three,       five
+#   Commit A: one->two, three->four, five->six
+#   Commit B: one->six, three->two,  five->four
+#   Expected: six CONFLICT(rename/rename) messages, each path in two of the
+#             multi-way merged contents found in two, four, six
+
+test_expect_success 'mod6-setup: chains of rename/rename(1to2) and rename/rename(2to1)' '
+       test_create_repo mod6 &&
+       (
+               cd mod6 &&
+               test_seq 11 19 >one &&
+               test_seq 31 39 >three &&
+               test_seq 51 59 >five &&
+               git add . &&
+               test_tick &&
+               git commit -m "O" &&
+
+               git branch O &&
+               git branch A &&
+               git branch B &&
+
+               git checkout A &&
+               test_seq 10 19 >one &&
+               echo 40        >>three &&
+               git add one three &&
+               git mv  one   two  &&
+               git mv  three four &&
+               git mv  five  six  &&
+               test_tick &&
+               git commit -m "A" &&
+
+               git checkout B &&
+               echo 20    >>one       &&
+               echo forty >>three     &&
+               echo 60    >>five      &&
+               git add one three five &&
+               git mv  one   six  &&
+               git mv  three two  &&
+               git mv  five  four &&
+               test_tick &&
+               git commit -m "B"
+       )
+'
+
+test_expect_failure 'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
+       (
+               cd mod6 &&
+
+               git checkout A^0 &&
+
+               test_must_fail git merge -s recursive B^0 >out 2>err &&
+
+               test_i18ngrep "CONFLICT (rename/rename)" out &&
+               test_must_be_empty err &&
+
+               git ls-files -s >file_count &&
+               test_line_count = 6 file_count &&
+               git ls-files -u >file_count &&
+               test_line_count = 6 file_count &&
+               git ls-files -o >file_count &&
+               test_line_count = 3 file_count &&
+
+               test_seq 10 20 >merged-one &&
+               test_seq 51 60 >merged-five &&
+               # Determine what the merge of three would give us.
+               test_seq 30 40 >three-side-A &&
+               test_seq 31 39 >three-side-B &&
+               echo forty >three-side-B &&
+               >empty &&
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "B^0" \
+                       three-side-A empty three-side-B &&
+               sed -e "s/^\([<=>]\)/\1\1\1/" three-side-A >merged-three &&
+
+               # Verify the index is as expected
+               git rev-parse >actual         \
+                       :2:two       :3:two   \
+                       :2:four      :3:four  \
+                       :2:six       :3:six   &&
+               git hash-object >expect           \
+                       merged-one   merged-three \
+                       merged-three merged-five  \
+                       merged-five  merged-one   &&
+               test_cmp expect actual &&
+
+               git cat-file -p :2:two >expect &&
+               git cat-file -p :3:two >other &&
+               test_must_fail git merge-file    \
+                       -L "HEAD"  -L ""  -L "B^0" \
+                       expect     empty  other &&
+               test_cmp expect two &&
+
+               git cat-file -p :2:four >expect &&
+               git cat-file -p :3:four >other &&
+               test_must_fail git merge-file    \
+                       -L "HEAD"  -L ""  -L "B^0" \
+                       expect     empty  other &&
+               test_cmp expect four &&
+
+               git cat-file -p :2:six >expect &&
+               git cat-file -p :3:six >other &&
+               test_must_fail git merge-file    \
+                       -L "HEAD"  -L ""  -L "B^0" \
+                       expect     empty  other &&
+               test_cmp expect six
+       )
+'
+
 test_done
index 23b86fb9778980ab813d5e252065ebe34fe4736d..5e3779ebc9310bfb25d0c6579f234ecf4fabd12e 100755 (executable)
@@ -82,7 +82,8 @@ test_expect_success 'ff update, important file modified' '
        touch subdir/e &&
        git add subdir/e &&
 
-       test_must_fail git merge E^0
+       test_must_fail git merge E^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'resolve, trivial' '
@@ -91,7 +92,8 @@ test_expect_success 'resolve, trivial' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge -s resolve C^0
+       test_must_fail git merge -s resolve C^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'resolve, non-trivial' '
@@ -100,7 +102,8 @@ test_expect_success 'resolve, non-trivial' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge -s resolve D^0
+       test_must_fail git merge -s resolve D^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'recursive' '
@@ -109,7 +112,8 @@ test_expect_success 'recursive' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge -s recursive C^0
+       test_must_fail git merge -s recursive C^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'recursive, when merge branch matches merge base' '
@@ -118,7 +122,45 @@ test_expect_success 'recursive, when merge branch matches merge base' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge -s recursive F^0
+       test_must_fail git merge -s recursive F^0 &&
+       test_path_is_missing .git/MERGE_HEAD
+'
+
+test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
+       git reset --hard &&
+       git checkout C^0 &&
+
+       # Make index match B
+       git diff C B -- | git apply --cached &&
+       # Merge B & F, with B as "head"
+       git merge-recursive A -- B F > out &&
+       test_i18ngrep "Already up to date" out
+'
+
+test_expect_success 'recursive, when file has staged changes not matching HEAD nor what a merge would give' '
+       git reset --hard &&
+       git checkout B^0 &&
+
+       mkdir subdir &&
+       test_seq 1 10 >subdir/a &&
+       git add subdir/a &&
+
+       # We have staged changes; merge should error out
+       test_must_fail git merge -s recursive E^0 2>err &&
+       test_i18ngrep "changes to the following files would be overwritten" err
+'
+
+test_expect_success 'recursive, when file has staged changes matching what a merge would give' '
+       git reset --hard &&
+       git checkout B^0 &&
+
+       mkdir subdir &&
+       test_seq 1 11 >subdir/a &&
+       git add subdir/a &&
+
+       # We have staged changes; merge should error out
+       test_must_fail git merge -s recursive E^0 2>err &&
+       test_i18ngrep "changes to the following files would be overwritten" err
 '
 
 test_expect_success 'octopus, unrelated file touched' '
@@ -127,7 +169,8 @@ test_expect_success 'octopus, unrelated file touched' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge C^0 D^0
+       test_must_fail git merge C^0 D^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'octopus, related file removed' '
@@ -136,7 +179,8 @@ test_expect_success 'octopus, related file removed' '
 
        git rm b &&
 
-       test_must_fail git merge C^0 D^0
+       test_must_fail git merge C^0 D^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'octopus, related file modified' '
@@ -145,7 +189,8 @@ test_expect_success 'octopus, related file modified' '
 
        echo 12 >>a && git add a &&
 
-       test_must_fail git merge C^0 D^0
+       test_must_fail git merge C^0 D^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'ours' '
@@ -154,7 +199,8 @@ test_expect_success 'ours' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge -s ours C^0
+       test_must_fail git merge -s ours C^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'subtree' '
@@ -163,7 +209,8 @@ test_expect_success 'subtree' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge -s subtree E^0
+       test_must_fail git merge -s subtree E^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_done
index fcefffcaece290f4070aceb9ddf6b5579447f104..38e24f787cffb5e645a5b31c8bfa30fb5106bea7 100755 (executable)
@@ -366,7 +366,9 @@ test_expect_success '2c-check: Modify b & add c VS rename b->c' '
 
                git checkout A^0 &&
 
-               GIT_MERGE_VERBOSITY=3 test_must_fail git merge -s recursive B^0 >out 2>err &&
+               GIT_MERGE_VERBOSITY=3 &&
+               export GIT_MERGE_VERBOSITY &&
+               test_must_fail git merge -s recursive B^0 >out 2>err &&
 
                test_i18ngrep "CONFLICT (rename/add): Rename b->c" out &&
                test_i18ngrep ! "Skipped c" out &&
index aa3e24963967ba4be2394ceeab26f8317fb31b4b..86374a9c52c0bd26a8ba7223526c9e1f128f468a 100755 (executable)
@@ -113,6 +113,12 @@ test_expect_success 'test GIT_NO_REPLACE_OBJECTS env variable' '
      GIT_NO_REPLACE_OBJECTS=1 git show $HASH2 | grep "A U Thor"
 '
 
+test_expect_success 'test core.usereplacerefs config option' '
+       test_config core.usereplacerefs false &&
+       git cat-file commit $HASH2 | grep "author A U Thor" &&
+       git show $HASH2 | grep "A U Thor"
+'
+
 cat >tag.sig <<EOF
 object $HASH2
 type commit
index debadbd299c02630097a3f476729719d4d71a10c..ddf34f0115b08b401a8981099459d10e1b1c4a02 100755 (executable)
@@ -44,8 +44,7 @@ test_expect_success 'read-tree does not resolve content merge' '
 test_expect_success 'git merge-index git-merge-one-file resolves' '
        git merge-index git-merge-one-file -a &&
        git diff-files --name-only --diff-filter=U >unmerged &&
-       >expect &&
-       test_cmp expect unmerged &&
+       test_must_be_empty unmerged &&
        test_cmp expect-merged file &&
        git cat-file blob :file >file-index &&
        test_cmp expect-merged file-index
index 48379aa0ee874b0250e2348d47eded09713a0a79..024f8c06f7c58a424204d6fca69021ace2de3cbf 100755 (executable)
@@ -795,4 +795,14 @@ test_expect_success ':remotename and :remoteref' '
        )
 '
 
+test_expect_success 'for-each-ref --ignore-case ignores case' '
+       git for-each-ref --format="%(refname)" refs/heads/MASTER >actual &&
+       test_must_be_empty actual &&
+
+       echo refs/heads/master >expect &&
+       git for-each-ref --format="%(refname)" --ignore-case \
+               refs/heads/MASTER >actual &&
+       test_cmp expect actual
+'
+
 test_done
index ec4b160ddb9f966044e729f35cc1edfcc79eed14..e23de7d0b5a4da29effb1e59426f857fed0e91e0 100755 (executable)
@@ -107,6 +107,21 @@ test_expect_success 'test that the directory was renamed' '
        test dir/D = "$(cat diroh/D.t)"
 '
 
+V=$(git rev-parse HEAD)
+
+test_expect_success 'populate --state-branch' '
+       git filter-branch --state-branch state -f --tree-filter "touch file || :" HEAD
+'
+
+W=$(git rev-parse HEAD)
+
+test_expect_success 'using --state-branch to skip already rewritten commits' '
+       test_when_finished git reset --hard $V &&
+       git reset --hard $V &&
+       git filter-branch --state-branch state -f --tree-filter "touch file || :" HEAD &&
+       test_cmp_rev $W HEAD
+'
+
 git tag oldD HEAD~4
 test_expect_success 'rewrite one branch, keeping a side branch' '
        git branch modD oldD &&
index d7b319e919c83ca677737840f70075c173364209..465eb4ea3f973943367b1c8b2e560d1b16b3c31b 100755 (executable)
@@ -693,9 +693,8 @@ test_expect_success \
 '
 
 test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
-       >expect &&
        git tag -n 100 >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        git tag -m "A msg" 100 &&
        echo "100             A msg" >expect &&
@@ -974,9 +973,8 @@ test_expect_success GPG 'verifying a proper tag with --format pass and format ac
 '
 
 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
-       >expect &&
        test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 # blank and empty messages for signed tags:
@@ -1354,6 +1352,19 @@ test_expect_success GPG \
        'test_config gpg.program echo &&
         test_must_fail git tag -s -m tail tag-gpg-failure'
 
+# try to sign with bad user.signingkey
+test_expect_success GPGSM \
+       'git tag -s fails if gpgsm is misconfigured (bad key)' \
+       'test_config user.signingkey BobTheMouse &&
+        test_config gpg.format x509 &&
+        test_must_fail git tag -s -m tail tag-gpg-failure'
+
+# try to produce invalid signature
+test_expect_success GPGSM \
+       'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
+       'test_config gpg.x509.program echo &&
+        test_config gpg.format x509 &&
+        test_must_fail git tag -s -m tail tag-gpg-failure'
 
 # try to verify without gpg:
 
@@ -1382,9 +1393,8 @@ test_expect_success 'message in editor has initial comment: first line' '
 test_expect_success \
        'message in editor has initial comment: remainder' '
        # remove commented lines from the remainder -- should be empty
-       >rest.expect &&
        sed -e 1d -e "/^#/d" <actual >rest.actual &&
-       test_cmp rest.expect rest.actual
+       test_must_be_empty rest.actual
 '
 
 get_tag_header reuse $commit commit $time >expect
@@ -1466,19 +1476,18 @@ test_expect_success 'checking that first commit is in all tags (relative)' "
 
 # All the --contains tests above, but with --no-contains
 test_expect_success 'checking that first commit is not listed in any tag with --no-contains  (hash)' "
-       >expected &&
        git tag -l --no-contains $hash1 v* >actual &&
-       test_cmp expected actual
+       test_must_be_empty actual
 "
 
 test_expect_success 'checking that first commit is in all tags (tag)' "
        git tag -l --no-contains v1.0 v* >actual &&
-       test_cmp expected actual
+       test_must_be_empty actual
 "
 
 test_expect_success 'checking that first commit is in all tags (relative)' "
        git tag -l --no-contains HEAD~2 v* >actual &&
-       test_cmp expected actual
+       test_must_be_empty actual
 "
 
 cat > expected <<EOF
@@ -1606,9 +1615,8 @@ test_expect_success 'checking that --contains can be used in non-list mode' '
 '
 
 test_expect_success 'checking that initial commit is in all tags with --no-contains' "
-       >expected &&
        git tag -l --no-contains $hash1 v* >actual &&
-       test_cmp expected actual
+       test_must_be_empty actual
 "
 
 # mixing modes and options:
@@ -1905,7 +1913,6 @@ test_expect_success 'version sort with very long prerelease suffix' '
 '
 
 test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
-       >expect &&
        i=1 &&
        while test $i -lt 8000
        do
@@ -1920,7 +1927,7 @@ EOF"
        git checkout master &&
        git tag far-far-away HEAD^ &&
        run_with_limited_stack git tag --contains HEAD >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
        run_with_limited_stack git tag --no-contains HEAD >actual &&
        test_line_count "-gt" 10 actual
 '
index 7541ba5edbcae1f1555c367b7f8bfc795913ff60..00e09a375c2e6e3bfce2c2f8ce93493513082b2d 100755 (executable)
@@ -626,12 +626,11 @@ test_expect_success TTY 'sub-commands of externals use their own pager' '
 
 test_expect_success TTY 'external command pagers override sub-commands' '
        sane_unset PAGER GIT_PAGER &&
-       >expect &&
        >actual &&
        test_config pager.external false &&
        test_config pager.log "sed s/^/log:/ >actual" &&
        test_terminal git --exec-path=. external log --format=%s -1 &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'command with underscores does not complain' '
index 291a1e2b07417559d3f3defd6a60043b505eb3c7..041e319e79aacb74ea9ec8fc20a38cc222961b6e 100755 (executable)
@@ -41,6 +41,13 @@ test_expect_success GPG 'create signed tags' '
        git tag -uB7227189 -m eighth eighth-signed-alt
 '
 
+test_expect_success GPGSM 'create signed tags x509 ' '
+       test_config gpg.format x509 &&
+       test_config user.signingkey $GIT_COMMITTER_EMAIL &&
+       echo 9 >file && test_tick && git commit -a -m "nineth gpgsm-signed" &&
+       git tag -s -m nineth nineth-signed-x509
+'
+
 test_expect_success GPG 'verify and show signatures' '
        (
                for tag in initial second merge fourth-signed sixth-signed seventh-signed
@@ -72,6 +79,13 @@ test_expect_success GPG 'verify and show signatures' '
        )
 '
 
+test_expect_success GPGSM 'verify and show signatures x509' '
+       git verify-tag nineth-signed-x509 2>actual &&
+       grep "Good signature from" actual &&
+       ! grep "BAD signature from" actual &&
+       echo nineth-signed-x509 OK
+'
+
 test_expect_success GPG 'detect fudged signature' '
        git cat-file tag seventh-signed >raw &&
        sed -e "/^tag / s/seventh/7th forged/" raw >forged1 &&
@@ -112,6 +126,13 @@ test_expect_success GPG 'verify signatures with --raw' '
        )
 '
 
+test_expect_success GPGSM 'verify signatures with --raw x509' '
+       git verify-tag --raw nineth-signed-x509 2>actual &&
+       grep "GOODSIG" actual &&
+       ! grep "BADSIG" actual &&
+       echo nineth-signed-x509 OK
+'
+
 test_expect_success GPG 'verify multiple tags' '
        tags="fourth-signed sixth-signed seventh-signed" &&
        for i in $tags
@@ -125,6 +146,19 @@ test_expect_success GPG 'verify multiple tags' '
        test_cmp expect.stderr actual.stderr
 '
 
+test_expect_success GPGSM 'verify multiple tags x509' '
+       tags="seventh-signed nineth-signed-x509" &&
+       for i in $tags
+       do
+               git verify-tag -v --raw $i || return 1
+       done >expect.stdout 2>expect.stderr.1 &&
+       grep "^.GNUPG:." <expect.stderr.1 >expect.stderr &&
+       git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 &&
+       grep "^.GNUPG:." <actual.stderr.1 >actual.stderr &&
+       test_cmp expect.stdout actual.stdout &&
+       test_cmp expect.stderr actual.stderr
+'
+
 test_expect_success GPG 'verifying tag with --format' '
        cat >expect <<-\EOF &&
        tagname : fourth-signed
@@ -134,9 +168,8 @@ test_expect_success GPG 'verifying tag with --format' '
 '
 
 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
-       >expect &&
        test_must_fail git verify-tag --format="tagname : %(tag)" $(cat forged1.tag) >actual-forged &&
-       test_cmp expect actual-forged
+       test_must_be_empty actual-forged
 '
 
 test_done
index c61e304e97376b09de51299a797dfb388335a365..2da57fce7b12bd9a2cfac38ba4d98fc9c4af1a4c 100755 (executable)
@@ -26,9 +26,8 @@ avoid_racy() {
 }
 
 status_is_clean() {
-       >../status.expect &&
        git status --porcelain >../status.actual &&
-       test_cmp ../status.expect ../status.actual
+       test_must_be_empty ../status.actual
 }
 
 test_lazy_prereq UNTRACKED_CACHE '
@@ -666,7 +665,7 @@ test_expect_success 'test ident field is working' '
        mkdir ../other_worktree &&
        cp -R done dthree dtwo four three ../other_worktree &&
        GIT_WORK_TREE=../other_worktree git status 2>../err &&
-       echo "warning: Untracked cache is disabled on this system or location." >../expect &&
+       echo "warning: untracked cache is disabled on this system or location" >../expect &&
        test_i18ncmp ../expect ../err
 '
 
index 95653a08cade25fb6edd7dcc479fb102d800f534..97be0d968dbcedba226b39862faddd23da39d863 100755 (executable)
@@ -549,8 +549,7 @@ test_expect_success 'reset -N keeps removed files as intent-to-add' '
 
        tree=$(git write-tree) &&
        git ls-tree $tree new-file >actual &&
-       >expect &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        git diff --name-only >actual &&
        echo new-file >expect &&
@@ -563,9 +562,8 @@ test_expect_success 'reset --mixed sets up work tree' '
                cd mixed_worktree &&
                test_commit dummy
        ) &&
-       : >expect &&
        git --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_done
index 0f95f004777ac3db191264fc5760c17bc1bdf77b..ecb85c3b823275efc68fb64643a4304a3cbf28b2 100755 (executable)
@@ -12,9 +12,8 @@ test_expect_success 'reset' '
        git add a b &&
        git reset &&
 
-       >expect &&
        git ls-files >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'reset HEAD' '
@@ -39,9 +38,8 @@ test_expect_success PERL 'reset -p' '
        echo y >yes &&
        git reset -p <yes >output &&
 
-       >expect &&
        git ls-files >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
        test_i18ngrep "Unstage" output
 '
 
@@ -61,9 +59,8 @@ test_expect_success 'reset --hard' '
        test_when_finished "echo a >a" &&
        git reset --hard &&
 
-       >expect &&
        git ls-files >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
        test_path_is_missing a
 '
 
index bfb09dd56615580fd82f8f3d680f45ecd12f9f0e..2b71e62ec2c26e6b1bbbcf71e69c5e5b784dc2ba 100755 (executable)
@@ -378,7 +378,7 @@ test_expect_success 'init should register submodule url in .git/config' '
 
 test_failure_with_unknown_submodule () {
        test_must_fail git submodule $1 no-such-submodule 2>output.err &&
-       grep "^error: .*no-such-submodule" output.err
+       test_i18ngrep "^error: .*no-such-submodule" output.err
 }
 
 test_expect_success 'init should fail with unknown submodule' '
@@ -994,6 +994,11 @@ test_expect_success 'submodule deinit should remove the whole submodule section
        rmdir init
 '
 
+test_expect_success 'submodule deinit should unset core.worktree' '
+       test_path_is_file .git/modules/example/config &&
+       test_must_fail git config -f .git/modules/example/config core.worktree
+'
+
 test_expect_success 'submodule deinit from subdirectory' '
        git submodule update --init &&
        git config submodule.example.foo bar &&
index 4e4c45550262ca75b36d15e80aa1f4bffc45465f..1cd12b38c53c7fdfedb937151d961527aa990dbd 100755 (executable)
@@ -64,8 +64,7 @@ test_expect_success 'added submodule (subdirectory only)' "
                cd sub &&
                git submodule summary . >../actual
        ) &&
-       >expected &&
-       test_cmp expected actual
+       test_must_be_empty actual
 "
 
 test_expect_success 'added submodule (subdirectory with explicit path)' "
index 7bfb2f498d3579d6e0aed2056a996f5c2829e8e4..7855bd8648f84b074e8a028a50aef49495c75431 100755 (executable)
@@ -279,4 +279,177 @@ test_expect_success 'recursive merge with submodule' '
         grep "$(cat expect3)" actual > /dev/null)
 '
 
+# File/submodule conflict
+#   Commit O: <empty>
+#   Commit A: path (submodule)
+#   Commit B: path
+#   Expected: path/ is submodule and file contents for B's path are somewhere
+
+test_expect_success 'setup file/submodule conflict' '
+       test_create_repo file-submodule &&
+       (
+               cd file-submodule &&
+
+               git commit --allow-empty -m O &&
+
+               git branch A &&
+               git branch B &&
+
+               git checkout B &&
+               echo content >path &&
+               git add path &&
+               git commit -m B &&
+
+               git checkout A &&
+               test_create_repo path &&
+               test_commit -C path world &&
+               git submodule add ./path &&
+               git commit -m A
+       )
+'
+
+test_expect_failure 'file/submodule conflict' '
+       test_when_finished "git -C file-submodule reset --hard" &&
+       (
+               cd file-submodule &&
+
+               git checkout A^0 &&
+               test_must_fail git merge B^0 &&
+
+               git ls-files -s >out &&
+               test_line_count = 3 out &&
+               git ls-files -u >out &&
+               test_line_count = 2 out &&
+
+               # path/ is still a submodule
+               test_path_is_dir path/.git &&
+
+               # There is a submodule at "path", so B:path cannot be written
+               # there.  We expect it to be written somewhere in the same
+               # directory, though, so just grep for its content in all
+               # files, and ignore "grep: path: Is a directory" message
+               echo Checking if contents from B:path showed up anywhere &&
+               grep -q content * 2>/dev/null
+       )
+'
+
+test_expect_success 'file/submodule conflict; merge --abort works afterward' '
+       test_when_finished "git -C file-submodule reset --hard" &&
+       (
+               cd file-submodule &&
+
+               git checkout A^0 &&
+               test_must_fail git merge B^0 >out 2>err &&
+
+               test_path_is_file .git/MERGE_HEAD &&
+               git merge --abort
+       )
+'
+
+# Directory/submodule conflict
+#   Commit O: <empty>
+#   Commit A: path (submodule), with sole tracked file named 'world'
+#   Commit B1: path/file
+#   Commit B2: path/world
+#
+#   Expected from merge of A & B1:
+#     Contents under path/ from commit B1 are renamed elsewhere; we do not
+#     want to write files from one of our tracked directories into a submodule
+#
+#   Expected from merge of A & B2:
+#     Similar to last merge, but with a slight twist: we don't want paths
+#     under the submodule to be treated as untracked or in the way.
+
+test_expect_success 'setup directory/submodule conflict' '
+       test_create_repo directory-submodule &&
+       (
+               cd directory-submodule &&
+
+               git commit --allow-empty -m O &&
+
+               git branch A &&
+               git branch B1 &&
+               git branch B2 &&
+
+               git checkout B1 &&
+               mkdir path &&
+               echo contents >path/file &&
+               git add path/file &&
+               git commit -m B1 &&
+
+               git checkout B2 &&
+               mkdir path &&
+               echo contents >path/world &&
+               git add path/world &&
+               git commit -m B2 &&
+
+               git checkout A &&
+               test_create_repo path &&
+               test_commit -C path hello world &&
+               git submodule add ./path &&
+               git commit -m A
+       )
+'
+
+test_expect_failure 'directory/submodule conflict; keep submodule clean' '
+       test_when_finished "git -C directory-submodule reset --hard" &&
+       (
+               cd directory-submodule &&
+
+               git checkout A^0 &&
+               test_must_fail git merge B1^0 &&
+
+               git ls-files -s >out &&
+               test_line_count = 3 out &&
+               git ls-files -u >out &&
+               test_line_count = 1 out &&
+
+               # path/ is still a submodule
+               test_path_is_dir path/.git &&
+
+               echo Checking if contents from B1:path/file showed up &&
+               # Would rather use grep -r, but that is GNU extension...
+               git ls-files -co | xargs grep -q contents 2>/dev/null &&
+
+               # However, B1:path/file should NOT have shown up at path/file,
+               # because we should not write into the submodule
+               test_path_is_missing path/file
+       )
+'
+
+test_expect_failure 'directory/submodule conflict; should not treat submodule files as untracked or in the way' '
+       test_when_finished "git -C directory-submodule/path reset --hard" &&
+       test_when_finished "git -C directory-submodule reset --hard" &&
+       (
+               cd directory-submodule &&
+
+               git checkout A^0 &&
+               test_must_fail git merge B2^0 >out 2>err &&
+
+               # We do not want files within the submodule to prevent the
+               # merge from starting; we should not be writing to such paths
+               # anyway.
+               test_i18ngrep ! "refusing to lose untracked file at" err
+       )
+'
+
+test_expect_failure 'directory/submodule conflict; merge --abort works afterward' '
+       test_when_finished "git -C directory-submodule/path reset --hard" &&
+       test_when_finished "git -C directory-submodule reset --hard" &&
+       (
+               cd directory-submodule &&
+
+               git checkout A^0 &&
+               test_must_fail git merge B2^0 &&
+               test_path_is_file .git/MERGE_HEAD &&
+
+               # merge --abort should succeed, should clear .git/MERGE_HEAD,
+               # and should not leave behind any conflicted files
+               git merge --abort &&
+               test_path_is_missing .git/MERGE_HEAD &&
+               git ls-files -u >conflicts &&
+               test_must_be_empty conflicts
+       )
+'
+
 test_done
index f604ef7a7294b893b4e342d086ac67c760582177..10dc91620a69870ab5dac213d032ae5d9938128c 100755 (executable)
@@ -115,17 +115,17 @@ Submodule path '../super/submodule': checked out '$submodulesha1'
 EOF
 
 cat <<EOF >expect2
+Cloning into '$pwd/recursivesuper/super/merging'...
+Cloning into '$pwd/recursivesuper/super/none'...
+Cloning into '$pwd/recursivesuper/super/rebasing'...
+Cloning into '$pwd/recursivesuper/super/submodule'...
 Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
 Submodule 'none' ($pwd/none) registered for path '../super/none'
 Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
 Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
-Cloning into '$pwd/recursivesuper/super/merging'...
 done.
-Cloning into '$pwd/recursivesuper/super/none'...
 done.
-Cloning into '$pwd/recursivesuper/super/rebasing'...
 done.
-Cloning into '$pwd/recursivesuper/super/submodule'...
 done.
 EOF
 
@@ -137,7 +137,8 @@ test_expect_success 'submodule update --init --recursive from subdirectory' '
         git submodule update --init --recursive ../super >../../actual 2>../../actual2
        ) &&
        test_i18ncmp expect actual &&
-       test_i18ncmp expect2 actual2
+       sort actual2 >actual2.sorted &&
+       test_i18ncmp expect2 actual2.sorted
 '
 
 cat <<EOF >expect2
@@ -174,7 +175,7 @@ test_expect_success 'submodule update does not fetch already present commits' '
          git submodule update > ../actual 2> ../actual.err
        ) &&
        test_i18ncmp expected actual &&
-       ! test -s actual.err
+       test_must_be_empty actual.err
 '
 
 test_expect_success 'submodule update should fail due to local changes' '
@@ -481,7 +482,8 @@ test_expect_success 'recursive submodule update - command in .git/config catches
 
 test_expect_success 'submodule init does not copy command into .git/config' '
        (cd super &&
-        H=$(git ls-files -s submodule | cut -d" " -f2) &&
+        git ls-files -s submodule >out &&
+        H=$(cut -d" " -f2 out) &&
         mkdir submodule1 &&
         git update-index --add --cacheinfo 160000 $H submodule1 &&
         git config -f .gitmodules submodule.submodule1.path submodule1 &&
@@ -579,9 +581,11 @@ test_expect_success 'submodule update - update=none in .git/config' '
          git checkout master &&
          compare_head
         ) &&
-        git diff --raw | grep "        submodule" &&
+        git diff --name-only >out &&
+        grep ^submodule$ out &&
         git submodule update &&
-        git diff --raw | grep "        submodule" &&
+        git diff --name-only >out &&
+        grep ^submodule$ out &&
         (cd submodule &&
          compare_head
         ) &&
@@ -597,11 +601,13 @@ test_expect_success 'submodule update - update=none in .git/config but --checkou
          git checkout master &&
          compare_head
         ) &&
-        git diff --raw | grep "        submodule" &&
+        git diff --name-only >out &&
+        grep ^submodule$ out &&
         git submodule update --checkout &&
-        test_must_fail git diff --raw \| grep "        submodule" &&
+        git diff --name-only >out &&
+        ! grep ^submodule$ out &&
         (cd submodule &&
-         test_must_fail compare_head
+         ! compare_head
         ) &&
         git config --unset submodule.submodule.update
        )
@@ -615,8 +621,8 @@ test_expect_success 'submodule update --init skips submodule with update=none' '
        git clone super cloned &&
        (cd cloned &&
         git submodule update --init &&
-        test -e submodule/.git &&
-        test_must_fail test -e none/.git
+        test_path_exists submodule/.git &&
+        test_path_is_missing none/.git
        )
 '
 
@@ -885,7 +891,8 @@ test_expect_success 'submodule update properly revives a moved submodule' '
         H=$(git rev-parse --short HEAD) &&
         git commit -am "pre move" &&
         H2=$(git rev-parse --short HEAD) &&
-        git status | sed "s/$H/XXX/" >expect &&
+        git status >out &&
+        sed "s/$H/XXX/" out >expect &&
         H=$(cd submodule2 && git rev-parse HEAD) &&
         git rm --cached submodule2 &&
         rm -rf submodule2 &&
@@ -894,7 +901,8 @@ test_expect_success 'submodule update properly revives a moved submodule' '
         git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
         git commit -am "post move" &&
         git submodule update &&
-        git status | sed "s/$H2/XXX/" >actual &&
+        git status > out &&
+        sed "s/$H2/XXX/" out >actual &&
         test_cmp expect actual
        )
 '
@@ -912,7 +920,7 @@ test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd'
 
 test_expect_success 'submodule update clone shallow submodule' '
        test_when_finished "rm -rf super3" &&
-       first=$(git -C cloned submodule status submodule |cut -c2-41) &&
+       first=$(git -C cloned rev-parse HEAD:submodule) &&
        second=$(git -C submodule rev-parse HEAD) &&
        commit_count=$(git -C submodule rev-list --count $first^..$second) &&
        git clone cloned super3 &&
@@ -922,7 +930,8 @@ test_expect_success 'submodule update clone shallow submodule' '
                sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
                mv -f .gitmodules.tmp .gitmodules &&
                git submodule update --init --depth=$commit_count &&
-               test 1 = $(git -C submodule log --oneline | wc -l)
+               git -C submodule log --oneline >out &&
+               test_line_count = 1 out
        )
 '
 
@@ -938,7 +947,8 @@ test_expect_success 'submodule update clone shallow submodule outside of depth'
                test_i18ngrep "Direct fetching of that commit failed." actual &&
                git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
                git submodule update --init --depth=1 >actual &&
-               test 1 = $(git -C submodule log --oneline | wc -l)
+               git -C submodule log --oneline >out &&
+               test_line_count = 1 out
        )
 '
 
index b68c5f5e8510ddbf4e10f6cb608d9e789bef09b4..293e2e1963962e49afa10882439b5106607439a1 100755 (executable)
@@ -176,4 +176,19 @@ test_expect_success 'fsck detects non-blob .gitmodules' '
        )
 '
 
+test_expect_success 'fsck detects corrupt .gitmodules' '
+       git init corrupt &&
+       (
+               cd corrupt &&
+
+               echo "[broken" >.gitmodules &&
+               git add .gitmodules &&
+               git commit -m "broken gitmodules" &&
+
+               git fsck 2>output &&
+               grep gitmodulesParse output &&
+               test_i18ngrep ! "bad config" output
+       )
+'
+
 test_done
index d33a3cb331b6c022343aff0bb7091cf8219b40df..ca4a740da0258b5522f29051c3d18632d1bafa1b 100755 (executable)
@@ -393,7 +393,6 @@ EOF
 
 test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '
        >.git/result &&
-       >expect &&
 
        echo >>negative &&
        (
@@ -403,7 +402,7 @@ test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '
                export GIT_EDITOR &&
                test_must_fail git commit -e -m sample -a
        ) &&
-       test_cmp expect .git/result
+       test_must_be_empty .git/result
 '
 
 test_expect_success 'do not fire editor if -m <msg> was given' '
index 302a3a2082a9da593ace637a2c32d8f4cf992cb3..31b9c6a2c1d3c30aa7d6d8a2eb836e7b67831d0c 100755 (executable)
@@ -157,6 +157,7 @@ test_expect_success 'merge bypasses failing hook with --no-verify' '
        test_when_finished "git branch -D newbranch" &&
        test_when_finished "git checkout -f master" &&
        git checkout --orphan newbranch &&
+       git rm -f file &&
        : >file2 &&
        git add file2 &&
        git commit --no-verify file2 -m in-side-branch &&
@@ -168,7 +169,7 @@ test_expect_success 'merge bypasses failing hook with --no-verify' '
 chmod -x "$HOOK"
 test_expect_success POSIXPERM 'with non-executable hook' '
 
-       echo "content" >file &&
+       echo "content" >file &&
        git add file &&
        git commit -m "content"
 
@@ -249,6 +250,7 @@ test_expect_success 'hook called in git-merge picks up commit message' '
        test_when_finished "git branch -D newbranch" &&
        test_when_finished "git checkout -f master" &&
        git checkout --orphan newbranch &&
+       git rm -f file &&
        : >file2 &&
        git add file2 &&
        git commit --no-verify file2 -m in-side-branch &&
index 6e2015ed9a199d6c6240a5fee850e72fd2fa65c3..4e37ff8f169615a893ee5d0594ff056b0284b724 100755 (executable)
@@ -227,4 +227,11 @@ test_expect_success GPG 'log.showsignature behaves like --show-signature' '
        grep "gpg: Good signature" actual
 '
 
+test_expect_success GPG 'check config gpg.format values' '
+       test_config gpg.format openpgp &&
+       git commit -S --amend -m "success" &&
+       test_config gpg.format OpEnPgP &&
+       test_must_fail git commit -S --amend -m "fail"
+'
+
 test_done
index 047156e9d51141a97ad71687c6da036b5ce76548..b18503de8158aa6583423f923675d415ab408e76 100755 (executable)
@@ -620,8 +620,7 @@ test_expect_success 'file with no base' '
        git checkout -b test$test_count branch1 &&
        test_must_fail git merge master &&
        git mergetool --no-prompt --tool mybase -- both &&
-       >expected &&
-       test_cmp expected both
+       test_must_be_empty both
 '
 
 test_expect_success 'custom commands override built-ins' '
index 7b4798e8e4791c78e94da1354ef7279fa456983d..7c84a518aa398cef2f7f39e23e02a9160323d968 100755 (executable)
@@ -187,31 +187,6 @@ test_expect_success 'Fail clean merge with matching dirty worktree' '
        test_cmp expect actual
 '
 
-test_expect_success 'Abort clean merge with matching dirty index' '
-       git add bar &&
-       git diff --staged > expect &&
-       git merge --no-commit clean_branch &&
-       test -f .git/MERGE_HEAD &&
-       ### When aborting the merge, git will discard all staged changes,
-       ### including those that were staged pre-merge. In other words,
-       ### --abort will LOSE any staged changes (the staged changes that
-       ### are lost must match the merge result, or the merge would not
-       ### have been allowed to start). Change expectations accordingly:
-       rm expect &&
-       touch expect &&
-       # Abort merge
-       git merge --abort &&
-       test ! -f .git/MERGE_HEAD &&
-       test "$pre_merge_head" = "$(git rev-parse HEAD)" &&
-       git diff --staged > actual &&
-       test_cmp expect actual &&
-       test -z "$(git diff)"
-'
-
-test_expect_success 'Reset worktree changes' '
-       git reset --hard "$pre_merge_head"
-'
-
 test_expect_success 'Fail conflicting merge with matching dirty worktree' '
        echo barf > bar &&
        git diff > expect &&
@@ -223,97 +198,4 @@ test_expect_success 'Fail conflicting merge with matching dirty worktree' '
        test_cmp expect actual
 '
 
-test_expect_success 'Abort conflicting merge with matching dirty index' '
-       git add bar &&
-       git diff --staged > expect &&
-       test_must_fail git merge conflict_branch &&
-       test -f .git/MERGE_HEAD &&
-       ### When aborting the merge, git will discard all staged changes,
-       ### including those that were staged pre-merge. In other words,
-       ### --abort will LOSE any staged changes (the staged changes that
-       ### are lost must match the merge result, or the merge would not
-       ### have been allowed to start). Change expectations accordingly:
-       rm expect &&
-       touch expect &&
-       # Abort merge
-       git merge --abort &&
-       test ! -f .git/MERGE_HEAD &&
-       test "$pre_merge_head" = "$(git rev-parse HEAD)" &&
-       git diff --staged > actual &&
-       test_cmp expect actual &&
-       test -z "$(git diff)"
-'
-
-test_expect_success 'Reset worktree changes' '
-       git reset --hard "$pre_merge_head"
-'
-
-test_expect_success 'Abort merge with pre- and post-merge worktree changes' '
-       # Pre-merge worktree changes
-       echo xyzzy > foo &&
-       echo barf > bar &&
-       git add bar &&
-       git diff > expect &&
-       git diff --staged > expect-staged &&
-       # Perform merge
-       test_must_fail git merge conflict_branch &&
-       test -f .git/MERGE_HEAD &&
-       # Post-merge worktree changes
-       echo yzxxz > foo &&
-       echo blech > baz &&
-       ### When aborting the merge, git will discard staged changes (bar)
-       ### and unmerged changes (baz). Other changes that are neither
-       ### staged nor marked as unmerged (foo), will be preserved. For
-       ### these changed, git cannot tell pre-merge changes apart from
-       ### post-merge changes, so the post-merge changes will be
-       ### preserved. Change expectations accordingly:
-       git diff -- foo > expect &&
-       rm expect-staged &&
-       touch expect-staged &&
-       # Abort merge
-       git merge --abort &&
-       test ! -f .git/MERGE_HEAD &&
-       test "$pre_merge_head" = "$(git rev-parse HEAD)" &&
-       git diff > actual &&
-       test_cmp expect actual &&
-       git diff --staged > actual-staged &&
-       test_cmp expect-staged actual-staged
-'
-
-test_expect_success 'Reset worktree changes' '
-       git reset --hard "$pre_merge_head"
-'
-
-test_expect_success 'Abort merge with pre- and post-merge index changes' '
-       # Pre-merge worktree changes
-       echo xyzzy > foo &&
-       echo barf > bar &&
-       git add bar &&
-       git diff > expect &&
-       git diff --staged > expect-staged &&
-       # Perform merge
-       test_must_fail git merge conflict_branch &&
-       test -f .git/MERGE_HEAD &&
-       # Post-merge worktree changes
-       echo yzxxz > foo &&
-       echo blech > baz &&
-       git add foo bar &&
-       ### When aborting the merge, git will discard all staged changes
-       ### (foo, bar and baz), and no changes will be preserved. Whether
-       ### the changes were staged pre- or post-merge does not matter
-       ### (except for not preventing starting the merge).
-       ### Change expectations accordingly:
-       rm expect expect-staged &&
-       touch expect &&
-       touch expect-staged &&
-       # Abort merge
-       git merge --abort &&
-       test ! -f .git/MERGE_HEAD &&
-       test "$pre_merge_head" = "$(git rev-parse HEAD)" &&
-       git diff > actual &&
-       test_cmp expect actual &&
-       git diff --staged > actual-staged &&
-       test_cmp expect-staged actual-staged
-'
-
 test_done
index fecee602c1de3e46676b3c8cd77dcab97a862dcf..d826e24b45118d4b87a2723f540c742ac6300f44 100755 (executable)
@@ -99,6 +99,101 @@ do
                test_cmp expected actual
        '
 
+       test_expect_success "grep -w $L (with --column)" '
+               {
+                       echo ${HC}file:5:foo mmap bar
+                       echo ${HC}file:14:foo_mmap bar mmap
+                       echo ${HC}file:5:foo mmap bar_mmap
+                       echo ${HC}file:14:foo_mmap bar mmap baz
+               } >expected &&
+               git grep --column -w -e mmap $H >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep -w $L (with --column, extended OR)" '
+               {
+                       echo ${HC}file:14:foo_mmap bar mmap
+                       echo ${HC}file:19:foo_mmap bar mmap baz
+               } >expected &&
+               git grep --column -w -e mmap$ --or -e baz $H >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep -w $L (with --column, --invert)" '
+               {
+                       echo ${HC}file:1:foo mmap bar
+                       echo ${HC}file:1:foo_mmap bar
+                       echo ${HC}file:1:foo_mmap bar mmap
+                       echo ${HC}file:1:foo mmap bar_mmap
+               } >expected &&
+               git grep --column --invert -w -e baz $H -- file >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep $L (with --column, --invert, extended OR)" '
+               {
+                       echo ${HC}hello_world:6:HeLLo_world
+               } >expected &&
+               git grep --column --invert -e ll --or --not -e _ $H -- hello_world \
+                       >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep $L (with --column, --invert, extended AND)" '
+               {
+                       echo ${HC}hello_world:3:Hello world
+                       echo ${HC}hello_world:3:Hello_world
+                       echo ${HC}hello_world:6:HeLLo_world
+               } >expected &&
+               git grep --column --invert --not -e _ --and --not -e ll $H -- hello_world \
+                       >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep $L (with --column, double-negation)" '
+               {
+                       echo ${HC}file:1:foo_mmap bar mmap baz
+               } >expected &&
+               git grep --column --not \( --not -e foo --or --not -e baz \) $H -- file \
+                       >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep -w $L (with --column, -C)" '
+               {
+                       echo ${HC}file:5:foo mmap bar
+                       echo ${HC}file-foo_mmap bar
+                       echo ${HC}file:14:foo_mmap bar mmap
+                       echo ${HC}file:5:foo mmap bar_mmap
+                       echo ${HC}file:14:foo_mmap bar mmap baz
+               } >expected &&
+               git grep --column -w -C1 -e mmap $H >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep -w $L (with --line-number, --column)" '
+               {
+                       echo ${HC}file:1:5:foo mmap bar
+                       echo ${HC}file:3:14:foo_mmap bar mmap
+                       echo ${HC}file:4:5:foo mmap bar_mmap
+                       echo ${HC}file:5:14:foo_mmap bar mmap baz
+               } >expected &&
+               git grep -n --column -w -e mmap $H >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep -w $L (with non-extended patterns, --column)" '
+               {
+                       echo ${HC}file:5:foo mmap bar
+                       echo ${HC}file:10:foo_mmap bar
+                       echo ${HC}file:10:foo_mmap bar mmap
+                       echo ${HC}file:5:foo mmap bar_mmap
+                       echo ${HC}file:10:foo_mmap bar mmap baz
+               } >expected &&
+               git grep --column -w -e bar -e mmap $H >actual &&
+               test_cmp expected actual
+       '
+
        test_expect_success "grep -w $L" '
                {
                        echo ${HC}file:1:foo mmap bar
@@ -167,6 +262,21 @@ do
                fi
        '
 
+       test_expect_success "grep $L (with --column, --only-matching)" '
+               {
+                       echo ${HC}file:1:5:mmap
+                       echo ${HC}file:2:5:mmap
+                       echo ${HC}file:3:5:mmap
+                       echo ${HC}file:3:13:mmap
+                       echo ${HC}file:4:5:mmap
+                       echo ${HC}file:4:13:mmap
+                       echo ${HC}file:5:5:mmap
+                       echo ${HC}file:5:13:mmap
+               } >expected &&
+               git grep --column -n -o -e mmap $H >actual &&
+               test_cmp expected actual
+       '
+
        test_expect_success "grep $L (t-1)" '
                echo "${HC}t/t:1:test" >expected &&
                git grep -n -e test $H >actual &&
@@ -581,8 +691,7 @@ test_expect_success 'log grep (5)' '
 
 test_expect_success 'log grep (6)' '
        git log --author=-0700  --pretty=tformat:%s >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'log grep (7)' '
index 661f9d430d28834b8a006fa0bcc958f52c95258b..c92a47b6d5b11ab537ce9892ca21feddc19db7d9 100755 (executable)
@@ -216,14 +216,18 @@ test_expect_success 'blame -L with invalid start' '
 '
 
 test_expect_success 'blame -L with invalid end' '
-       test_must_fail git blame -L1,5 tres 2>errors &&
-       test_i18ngrep "has only 2 lines" errors
+       git blame -L1,5 tres >out &&
+       test_line_count = 2 out
 '
 
 test_expect_success 'blame parses <end> part of -L' '
        git blame -L1,1 tres >out &&
-       cat out &&
-       test $(wc -l < out) -eq 1
+       test_line_count = 1 out
+'
+
+test_expect_success 'blame -Ln,-(n+1)' '
+       git blame -L3,-4 nine_lines >out &&
+       test_line_count = 3 out
 '
 
 test_expect_success 'indent of line numbers, nine lines' '
index 53314ff54e4e186bfef99877ac1f5aa082c8eab6..1ef1a19003db5c9be94197e9d6cb25110591705b 100755 (executable)
@@ -225,6 +225,8 @@ X-Mailer: X-MAILER-STRING
 In-Reply-To: <unique-message-id@example.com>
 References: <unique-message-id@example.com>
 Reply-To: Reply <reply@example.com>
+MIME-Version: 1.0
+Content-Transfer-Encoding: 8bit
 
 Result: OK
 EOF
@@ -251,10 +253,9 @@ test_suppress_self () {
 
        mv msgtxt1 msgtxt1-$3 &&
        sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
-       >"expected-no-cc-$3" &&
 
        (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
-        test_cmp expected-no-cc-$3 actual-no-cc-$3)
+        test_must_be_empty actual-no-cc-$3)
 }
 
 test_suppress_self_unquoted () {
@@ -415,6 +416,7 @@ test_expect_success $PREREQ 'reject long lines' '
                --from="Example <nobody@example.com>" \
                --to=nobody@example.com \
                --smtp-server="$(pwd)/fake.sendmail" \
+               --transfer-encoding=8bit \
                $patches longline.patch \
                2>errors &&
        grep longline.patch errors
@@ -456,6 +458,42 @@ test_expect_success $PREREQ 'allow long lines with --no-validate' '
                2>errors
 '
 
+test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
+       clean_fake_sendmail &&
+       git send-email \
+               --from="A <author@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               --transfer-encoding=auto \
+               $patches &&
+       grep "Content-Transfer-Encoding: 8bit" msgtxt1
+'
+
+test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
+       clean_fake_sendmail &&
+       git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               --transfer-encoding=auto \
+               --no-validate \
+               longline.patch &&
+       grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
+'
+
+for enc in auto quoted-printable base64
+do
+       test_expect_success $PREREQ "--validate passes with encoding $enc" '
+               git send-email \
+                       --from="Example <nobody@example.com>" \
+                       --to=nobody@example.com \
+                       --smtp-server="$(pwd)/fake.sendmail" \
+                       --transfer-encoding=$enc \
+                       --validate \
+                       $patches longline.patch
+       '
+done
+
 test_expect_success $PREREQ 'Invalid In-Reply-To' '
        clean_fake_sendmail &&
        git send-email \
@@ -573,6 +611,8 @@ Subject: [PATCH 1/1] Second.
 Date: DATE-STRING
 Message-Id: MESSAGE-ID-STRING
 X-Mailer: X-MAILER-STRING
+MIME-Version: 1.0
+Content-Transfer-Encoding: 8bit
 
 Result: OK
 EOF
@@ -617,6 +657,8 @@ Subject: [PATCH 1/1] Second.
 Date: DATE-STRING
 Message-Id: MESSAGE-ID-STRING
 X-Mailer: X-MAILER-STRING
+MIME-Version: 1.0
+Content-Transfer-Encoding: 8bit
 
 Result: OK
 EOF
@@ -652,6 +694,8 @@ Subject: [PATCH 1/1] Second.
 Date: DATE-STRING
 Message-Id: MESSAGE-ID-STRING
 X-Mailer: X-MAILER-STRING
+MIME-Version: 1.0
+Content-Transfer-Encoding: 8bit
 
 Result: OK
 EOF
@@ -678,6 +722,8 @@ Subject: [PATCH 1/1] Second.
 Date: DATE-STRING
 Message-Id: MESSAGE-ID-STRING
 X-Mailer: X-MAILER-STRING
+MIME-Version: 1.0
+Content-Transfer-Encoding: 8bit
 
 Result: OK
 EOF
@@ -712,6 +758,8 @@ Subject: [PATCH 1/1] Second.
 Date: DATE-STRING
 Message-Id: MESSAGE-ID-STRING
 X-Mailer: X-MAILER-STRING
+MIME-Version: 1.0
+Content-Transfer-Encoding: 8bit
 
 Result: OK
 EOF
@@ -743,6 +791,8 @@ Subject: [PATCH 1/1] Second.
 Date: DATE-STRING
 Message-Id: MESSAGE-ID-STRING
 X-Mailer: X-MAILER-STRING
+MIME-Version: 1.0
+Content-Transfer-Encoding: 8bit
 
 Result: OK
 EOF
@@ -774,6 +824,8 @@ Subject: [PATCH 1/1] Second.
 Date: DATE-STRING
 Message-Id: MESSAGE-ID-STRING
 X-Mailer: X-MAILER-STRING
+MIME-Version: 1.0
+Content-Transfer-Encoding: 8bit
 
 Result: OK
 EOF
@@ -809,6 +861,8 @@ Subject: [PATCH 1/1] Second.
 Date: DATE-STRING
 Message-Id: MESSAGE-ID-STRING
 X-Mailer: X-MAILER-STRING
+MIME-Version: 1.0
+Content-Transfer-Encoding: 8bit
 
 Result: OK
 EOF
@@ -837,6 +891,8 @@ Subject: [PATCH 1/1] Second.
 Date: DATE-STRING
 Message-Id: MESSAGE-ID-STRING
 X-Mailer: X-MAILER-STRING
+MIME-Version: 1.0
+Content-Transfer-Encoding: 8bit
 
 Result: OK
 EOF
index 9e7f96223dc2222c48b172711b4b469ff08190c8..40fe7e49767ac4e0bbe5686413ff2b667171747a 100755 (executable)
@@ -2191,12 +2191,11 @@ test_expect_success 'R: --import-marks-if-exists' '
 
 test_expect_success 'R: feature import-marks-if-exists' '
        rm -f io.marks &&
-       >expect &&
 
        git fast-import --export-marks=io.marks <<-\EOF &&
        feature import-marks-if-exists=not_io.marks
        EOF
-       test_cmp expect io.marks &&
+       test_must_be_empty io.marks &&
 
        blob=$(echo hi | git hash-object --stdin) &&
 
@@ -2227,13 +2226,11 @@ test_expect_success 'R: feature import-marks-if-exists' '
        EOF
        test_cmp expect io.marks &&
 
-       >expect &&
-
        git fast-import --import-marks-if-exists=not_io.marks \
                        --export-marks=io.marks <<-\EOF &&
        feature import-marks-if-exists=io.marks
        EOF
-       test_cmp expect io.marks
+       test_must_be_empty io.marks
 '
 
 test_expect_success 'R: import to output marks works without any content' '
@@ -3147,7 +3144,10 @@ background_import_then_checkpoint () {
        echo $! >V.pid
        # We don't mind if fast-import has already died by the time the test
        # ends.
-       test_when_finished "exec 8>&-; exec 9>&-; kill $(cat V.pid) || true"
+       test_when_finished "
+               exec 8>&-; exec 9>&-;
+               kill $(cat V.pid) && wait $(cat V.pid)
+               true"
 
        # Start in the background to ensure we adhere strictly to (blocking)
        # pipes writing sequence. We want to assume that the write below could
index 4849edc4ef6733b8cf42950b3cd5fe809a80cdde..729cd25770177aa52bade1100bb4ddae1456d269 100755 (executable)
@@ -261,6 +261,35 @@ test_expect_success 'unresolvable host in P4PORT should display error' '
        )
 '
 
+# Test following scenarios:
+#   - Without ".git/hooks/p4-pre-submit" , submit should continue
+#   - With the hook returning 0, submit should continue
+#   - With the hook returning 1, submit should abort
+test_expect_success 'run hook p4-pre-submit before submit' '
+       test_when_finished cleanup_git &&
+       git p4 clone --dest="$git" //depot &&
+       (
+               cd "$git" &&
+               echo "hello world" >hello.txt &&
+               git add hello.txt &&
+               git commit -m "add hello.txt" &&
+               git config git-p4.skipSubmitEdit true &&
+               git p4 submit --dry-run >out &&
+               grep "Would apply" out &&
+               mkdir -p .git/hooks &&
+               write_script .git/hooks/p4-pre-submit <<-\EOF &&
+               exit 0
+               EOF
+               git p4 submit --dry-run >out &&
+               grep "Would apply" out &&
+               write_script .git/hooks/p4-pre-submit <<-\EOF &&
+               exit 1
+               EOF
+               test_must_fail git p4 submit --dry-run >errs 2>&1 &&
+               ! grep "Would apply" errs
+       )
+'
+
 test_expect_success 'submit from detached head' '
        test_when_finished cleanup_git &&
        git p4 clone --dest="$git" //depot &&
index 9ba892de7abff30a81125521cb5e9084cad1b75f..277d34701201af03d0efbcfe05336b6cfec5483b 100755 (executable)
@@ -26,7 +26,9 @@ test_expect_success 'error handling' '
        ) &&
        p4 passwd -P newpassword &&
        (
-               P4PASSWD=badpassword test_must_fail git p4 clone //depot/foo 2>errmsg &&
+               P4PASSWD=badpassword &&
+               export P4PASSWD &&
+               test_must_fail git p4 clone //depot/foo 2>errmsg &&
                grep -q "failure accessing depot.*P4PASSWD" errmsg
        )
 '
index 2b2181dca09089ed36d10ee8f6f67eedda8cf352..4207af40777c69365dc395e800a7e4214beab076 100644 (file)
@@ -565,6 +565,14 @@ test_path_is_dir () {
        fi
 }
 
+test_path_exists () {
+       if ! test -e "$1"
+       then
+               echo "Path $1 doesn't exist. $2"
+               false
+       fi
+}
+
 # Check if the directory exists and is empty as expected, barf otherwise.
 test_dir_is_empty () {
        test_path_is_dir "$1" &&
diff --git a/tag.c b/tag.c
index 7c12426b4eaba595b9b652fa47952c961306e44f..1db663d71623a493286c90b13532c7d1cf73f517 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -1,10 +1,12 @@
 #include "cache.h"
 #include "tag.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
 #include "alloc.h"
 #include "gpg-interface.h"
+#include "packfile.h"
 
 const char *tag_type = "tag";
 
@@ -63,14 +65,20 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
        return ret;
 }
 
-struct object *deref_tag(struct object *o, const char *warn, int warnlen)
+struct object *deref_tag(struct repository *r, struct object *o, const char *warn, int warnlen)
 {
+       struct object_id *last_oid = NULL;
        while (o && o->type == OBJ_TAG)
-               if (((struct tag *)o)->tagged)
-                       o = parse_object(&((struct tag *)o)->tagged->oid);
-               else
+               if (((struct tag *)o)->tagged) {
+                       last_oid = &((struct tag *)o)->tagged->oid;
+                       o = parse_object(r, last_oid);
+               } else {
+                       last_oid = NULL;
                        o = NULL;
+               }
        if (!o && warn) {
+               if (last_oid && is_promisor_object(last_oid))
+                       return NULL;
                if (!warnlen)
                        warnlen = strlen(warn);
                error("missing object referenced by '%.*s'", warnlen, warn);
@@ -81,7 +89,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
 struct object *deref_tag_noverify(struct object *o)
 {
        while (o && o->type == OBJ_TAG) {
-               o = parse_object(&o->oid);
+               o = parse_object(the_repository, &o->oid);
                if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged)
                        o = ((struct tag *)o)->tagged;
                else
@@ -90,13 +98,13 @@ struct object *deref_tag_noverify(struct object *o)
        return o;
 }
 
-struct tag *lookup_tag(const struct object_id *oid)
+struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(r, oid->hash);
        if (!obj)
-               return create_object(the_repository, oid->hash,
-                                    alloc_tag_node(the_repository));
-       return object_as_type(obj, OBJ_TAG, 0);
+               return create_object(r, oid->hash,
+                                    alloc_tag_node(r));
+       return object_as_type(r, obj, OBJ_TAG, 0);
 }
 
 static timestamp_t parse_tag_date(const char *buf, const char *tail)
@@ -124,7 +132,7 @@ void release_tag_memory(struct tag *t)
        t->date = 0;
 }
 
-int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
+int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size)
 {
        struct object_id oid;
        char type[20];
@@ -152,13 +160,13 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
        bufptr = nl + 1;
 
        if (!strcmp(type, blob_type)) {
-               item->tagged = (struct object *)lookup_blob(&oid);
+               item->tagged = (struct object *)lookup_blob(r, &oid);
        } else if (!strcmp(type, tree_type)) {
-               item->tagged = (struct object *)lookup_tree(&oid);
+               item->tagged = (struct object *)lookup_tree(r, &oid);
        } else if (!strcmp(type, commit_type)) {
-               item->tagged = (struct object *)lookup_commit(&oid);
+               item->tagged = (struct object *)lookup_commit(r, &oid);
        } else if (!strcmp(type, tag_type)) {
-               item->tagged = (struct object *)lookup_tag(&oid);
+               item->tagged = (struct object *)lookup_tag(r, &oid);
        } else {
                error("Unknown type %s", type);
                item->tagged = NULL;
@@ -201,7 +209,7 @@ int parse_tag(struct tag *item)
                return error("Object %s not a tag",
                             oid_to_hex(&item->object.oid));
        }
-       ret = parse_tag_buffer(item, data, size);
+       ret = parse_tag_buffer(the_repository, item, data, size);
        free(data);
        return ret;
 }
diff --git a/tag.h b/tag.h
index 9057d76a50639d65aae1340b752d2daa7dc67aa9..e669c3e497a95bdeb08c4b45dec37a7d80b52ac4 100644 (file)
--- a/tag.h
+++ b/tag.h
@@ -11,12 +11,11 @@ struct tag {
        char *tag;
        timestamp_t date;
 };
-
-extern struct tag *lookup_tag(const struct object_id *oid);
-extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long size);
+extern struct tag *lookup_tag(struct repository *r, const struct object_id *oid);
+extern int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size);
 extern int parse_tag(struct tag *item);
 extern void release_tag_memory(struct tag *t);
-extern struct object *deref_tag(struct object *, const char *, int);
+extern struct object *deref_tag(struct repository *r, struct object *, const char *, int);
 extern struct object *deref_tag_noverify(struct object *);
 extern int gpg_verify_tag(const struct object_id *oid,
                const char *name_to_report, unsigned flags);
index 1f8ff7e9424e5d780578a6ab00623f814d8f836a..143ca008c8f20384c8c4636e5372817946e66e14 100644 (file)
@@ -48,7 +48,7 @@ static void sendline(struct helper_data *helper, struct strbuf *buffer)
        if (debug)
                fprintf(stderr, "Debug: Remote helper: -> %s", buffer->buf);
        if (write_in_full(helper->helper->in, buffer->buf, buffer->len) < 0)
-               die_errno("Full write to remote helper failed");
+               die_errno(_("full write to remote helper failed"));
 }
 
 static int recvline_fh(FILE *helper, struct strbuf *buffer)
@@ -77,7 +77,7 @@ static void write_constant(int fd, const char *str)
        if (debug)
                fprintf(stderr, "Debug: Remote helper: -> %s", str);
        if (write_in_full(fd, str, strlen(str)) < 0)
-               die_errno("Full write to remote helper failed");
+               die_errno(_("full write to remote helper failed"));
 }
 
 static const char *remove_ext_force(const char *url)
@@ -129,7 +129,7 @@ static struct child_process *get_helper(struct transport *transport)
 
        code = start_command(helper);
        if (code < 0 && errno == ENOENT)
-               die("Unable to find remote helper for '%s'", data->name);
+               die(_("unable to find remote helper for '%s'"), data->name);
        else if (code != 0)
                exit(code);
 
@@ -145,7 +145,7 @@ static struct child_process *get_helper(struct transport *transport)
         */
        duped = dup(helper->out);
        if (duped < 0)
-               die_errno("Can't dup helper output fd");
+               die_errno(_("can't dup helper output fd"));
        data->out = xfdopen(duped, "r");
 
        write_constant(helper->in, "capabilities\n");
@@ -196,13 +196,13 @@ static struct child_process *get_helper(struct transport *transport)
                } else if (starts_with(capname, "no-private-update")) {
                        data->no_private_update = 1;
                } else if (mandatory) {
-                       die("Unknown mandatory capability %s. This remote "
-                           "helper probably needs newer version of Git.",
+                       die(_("unknown mandatory capability %s; this remote "
+                             "helper probably needs newer version of Git"),
                            capname);
                }
        }
        if (!data->rs.nr && (data->import || data->bidi_import || data->export)) {
-               warning("This remote helper should implement refspec capability.");
+               warning(_("this remote helper should implement refspec capability"));
        }
        strbuf_release(&buf);
        if (debug)
@@ -269,7 +269,7 @@ static int strbuf_set_helper_option(struct helper_data *data,
        else if (!strcmp(buf->buf, "unsupported"))
                ret = 1;
        else {
-               warning("%s unexpectedly said: '%s'", data->name, buf->buf);
+               warning(_("%s unexpectedly said: '%s'"), data->name, buf->buf);
                ret = 1;
        }
        return ret;
@@ -398,7 +398,7 @@ static int fetch_with_fetch(struct transport *transport,
                if (starts_with(buf.buf, "lock ")) {
                        const char *name = buf.buf + 5;
                        if (transport->pack_lockfile)
-                               warning("%s also locked %s", data->name, name);
+                               warning(_("%s also locked %s"), data->name, name);
                        else
                                transport->pack_lockfile = xstrdup(name);
                }
@@ -409,7 +409,7 @@ static int fetch_with_fetch(struct transport *transport,
                else if (!buf.len)
                        break;
                else
-                       warning("%s unexpectedly said: '%s'", data->name, buf.buf);
+                       warning(_("%s unexpectedly said: '%s'"), data->name, buf.buf);
        }
        strbuf_release(&buf);
        return 0;
@@ -476,7 +476,7 @@ static int fetch_with_import(struct transport *transport,
        get_helper(transport);
 
        if (get_importer(transport, &fastimport))
-               die("Couldn't run fast-import");
+               die(_("couldn't run fast-import"));
 
        for (i = 0; i < nr_heads; i++) {
                posn = to_fetch[i];
@@ -499,7 +499,7 @@ static int fetch_with_import(struct transport *transport,
         */
 
        if (finish_command(&fastimport))
-               die("Error while running fast-import");
+               die(_("error while running fast-import"));
 
        /*
         * The fast-import stream of a remote helper that advertises
@@ -528,7 +528,7 @@ static int fetch_with_import(struct transport *transport,
                        private = xstrdup(name);
                if (private) {
                        if (read_ref(private, &posn->old_oid) < 0)
-                               die("Could not read ref %s", private);
+                               die(_("could not read ref %s"), private);
                        free(private);
                }
        }
@@ -554,7 +554,7 @@ static int run_connect(struct transport *transport, struct strbuf *cmdbuf)
         */
        duped = dup(helper->out);
        if (duped < 0)
-               die_errno("Can't dup helper output fd");
+               die_errno(_("can't dup helper output fd"));
        input = xfdopen(duped, "r");
        setvbuf(input, NULL, _IONBF, 0);
 
@@ -573,8 +573,8 @@ static int run_connect(struct transport *transport, struct strbuf *cmdbuf)
                        fprintf(stderr, "Debug: Falling back to dumb "
                                "transport.\n");
        } else {
-               die("Unknown response to connect: %s",
-                       cmdbuf->buf);
+               die(_(_("unknown response to connect: %s")),
+                   cmdbuf->buf);
        }
 
        fclose(input);
@@ -595,9 +595,9 @@ static int process_connect_service(struct transport *transport,
        if (strcmp(name, exec)) {
                int r = set_helper_option(transport, "servpath", exec);
                if (r > 0)
-                       warning("Setting remote service path not supported by protocol.");
+                       warning(_("setting remote service path not supported by protocol"));
                else if (r < 0)
-                       warning("Invalid remote service path.");
+                       warning(_("invalid remote service path"));
        }
 
        if (data->connect) {
@@ -640,10 +640,10 @@ static int connect_helper(struct transport *transport, const char *name,
        /* Get_helper so connect is inited. */
        get_helper(transport);
        if (!data->connect)
-               die("Operation not supported by protocol.");
+               die(_("operation not supported by protocol"));
 
        if (!process_connect_service(transport, name, exec))
-               die("Can't connect to subservice %s.", name);
+               die(_("can't connect to subservice %s"), name);
 
        fd[0] = data->helper->out;
        fd[1] = data->helper->in;
@@ -684,6 +684,9 @@ static int fetch(struct transport *transport,
                        transport, "filter",
                        data->transport_options.filter_options.filter_spec);
 
+       if (data->transport_options.negotiation_tips)
+               warning("Ignoring --negotiation-tip because the protocol does not support it.");
+
        if (data->fetch)
                return fetch_with_fetch(transport, nr_heads, to_fetch);
 
@@ -707,7 +710,7 @@ static int push_update_ref_status(struct strbuf *buf,
                status = REF_STATUS_REMOTE_REJECT;
                refname = buf->buf + 6;
        } else
-               die("expected ok/error, helper said '%s'", buf->buf);
+               die(_("expected ok/error, helper said '%s'"), buf->buf);
 
        msg = strchr(refname, ' ');
        if (msg) {
@@ -760,7 +763,7 @@ static int push_update_ref_status(struct strbuf *buf,
        if (!*ref)
                *ref = find_ref_by_name(remote_refs, refname);
        if (!*ref) {
-               warning("helper reported unexpected status of %s", refname);
+               warning(_("helper reported unexpected status of %s"), refname);
                return 1;
        }
 
@@ -821,20 +824,20 @@ static void set_common_push_options(struct transport *transport,
 {
        if (flags & TRANSPORT_PUSH_DRY_RUN) {
                if (set_helper_option(transport, "dry-run", "true") != 0)
-                       die("helper %s does not support dry-run", name);
+                       die(_("helper %s does not support dry-run"), name);
        } else if (flags & TRANSPORT_PUSH_CERT_ALWAYS) {
                if (set_helper_option(transport, TRANS_OPT_PUSH_CERT, "true") != 0)
-                       die("helper %s does not support --signed", name);
+                       die(_("helper %s does not support --signed"), name);
        } else if (flags & TRANSPORT_PUSH_CERT_IF_ASKED) {
                if (set_helper_option(transport, TRANS_OPT_PUSH_CERT, "if-asked") != 0)
-                       die("helper %s does not support --signed=if-asked", name);
+                       die(_("helper %s does not support --signed=if-asked"), name);
        }
 
        if (flags & TRANSPORT_PUSH_OPTIONS) {
                struct string_list_item *item;
                for_each_string_list_item(item, transport->push_options)
                        if (set_helper_option(transport, "push-option", item->string) != 0)
-                               die("helper %s does not support 'push-option'", name);
+                               die(_("helper %s does not support 'push-option'"), name);
        }
 }
 
@@ -926,12 +929,12 @@ static int push_refs_with_export(struct transport *transport,
        struct strbuf buf = STRBUF_INIT;
 
        if (!data->rs.nr)
-               die("remote-helper doesn't support push; refspec needed");
+               die(_("remote-helper doesn't support push; refspec needed"));
 
        set_common_push_options(transport, data->name, flags);
        if (flags & TRANSPORT_PUSH_FORCE) {
                if (set_helper_option(transport, "force", "true") != 0)
-                       warning("helper %s does not support 'force'", data->name);
+                       warning(_("helper %s does not support 'force'"), data->name);
        }
 
        helper = get_helper(transport);
@@ -978,12 +981,12 @@ static int push_refs_with_export(struct transport *transport,
        }
 
        if (get_exporter(transport, &exporter, &revlist_args))
-               die("Couldn't run fast-export");
+               die(_("couldn't run fast-export"));
 
        string_list_clear(&revlist_args, 1);
 
        if (finish_command(&exporter))
-               die("Error while running fast-export");
+               die(_("error while running fast-export"));
        if (push_update_refs_status(data, remote_refs, flags))
                return 1;
 
@@ -1007,8 +1010,9 @@ static int push_refs(struct transport *transport,
        }
 
        if (!remote_refs) {
-               fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
-                       "Perhaps you should specify a branch such as 'master'.\n");
+               fprintf(stderr,
+                       _("No refs in common and none specified; doing nothing.\n"
+                         "Perhaps you should specify a branch such as 'master'.\n"));
                return 0;
        }
 
@@ -1070,7 +1074,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
 
                eov = strchr(buf.buf, ' ');
                if (!eov)
-                       die("Malformed response in ref list: %s", buf.buf);
+                       die(_("malformed response in ref list: %s"), buf.buf);
                eon = strchr(eov + 1, ' ');
                *eov = '\0';
                if (eon)
@@ -1084,7 +1088,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
                        if (has_attribute(eon + 1, "unchanged")) {
                                (*tail)->status |= REF_STATUS_UPTODATE;
                                if (read_ref((*tail)->name, &(*tail)->old_oid) < 0)
-                                       die(_("Could not read ref %s"),
+                                       die(_("could not read ref %s"),
                                            (*tail)->name);
                        }
                }
@@ -1223,7 +1227,7 @@ static int udt_do_read(struct unidirectional_transfer *t)
        bytes = read(t->src, t->buf + t->bufuse, BUFFERSIZE - t->bufuse);
        if (bytes < 0 && errno != EWOULDBLOCK && errno != EAGAIN &&
                errno != EINTR) {
-               error_errno("read(%s) failed", t->src_name);
+               error_errno(_("read(%s) failed"), t->src_name);
                return -1;
        } else if (bytes == 0) {
                transfer_debug("%s EOF (with %i bytes in buffer)",
@@ -1250,7 +1254,7 @@ static int udt_do_write(struct unidirectional_transfer *t)
        transfer_debug("%s is writable", t->dest_name);
        bytes = xwrite(t->dest, t->buf, t->bufuse);
        if (bytes < 0 && errno != EWOULDBLOCK) {
-               error_errno("write(%s) failed", t->dest_name);
+               error_errno(_("write(%s) failed"), t->dest_name);
                return -1;
        } else if (bytes > 0) {
                t->bufuse -= bytes;
@@ -1299,11 +1303,11 @@ static int tloop_join(pthread_t thread, const char *name)
        void *tret;
        err = pthread_join(thread, &tret);
        if (!tret) {
-               error("%s thread failed", name);
+               error(_("%s thread failed"), name);
                return 1;
        }
        if (err) {
-               error("%s thread failed to join: %s", name, strerror(err));
+               error(_("%s thread failed to join: %s"), name, strerror(err));
                return 1;
        }
        return 0;
@@ -1322,11 +1326,11 @@ static int tloop_spawnwait_tasks(struct bidirectional_transfer_state *s)
        err = pthread_create(&gtp_thread, NULL, udt_copy_task_routine,
                &s->gtp);
        if (err)
-               die("Can't start thread for copying data: %s", strerror(err));
+               die(_("can't start thread for copying data: %s"), strerror(err));
        err = pthread_create(&ptg_thread, NULL, udt_copy_task_routine,
                &s->ptg);
        if (err)
-               die("Can't start thread for copying data: %s", strerror(err));
+               die(_("can't start thread for copying data: %s"), strerror(err));
 
        ret |= tloop_join(gtp_thread, "Git to program copy");
        ret |= tloop_join(ptg_thread, "Program to git copy");
@@ -1363,11 +1367,11 @@ static int tloop_join(pid_t pid, const char *name)
 {
        int tret;
        if (waitpid(pid, &tret, 0) < 0) {
-               error_errno("%s process failed to wait", name);
+               error_errno(_("%s process failed to wait"), name);
                return 1;
        }
        if (!WIFEXITED(tret) || WEXITSTATUS(tret)) {
-               error("%s process failed", name);
+               error(_("%s process failed"), name);
                return 1;
        }
        return 0;
@@ -1385,7 +1389,7 @@ static int tloop_spawnwait_tasks(struct bidirectional_transfer_state *s)
        /* Fork thread #1: git to program. */
        pid1 = fork();
        if (pid1 < 0)
-               die_errno("Can't start thread for copying data");
+               die_errno(_("can't start thread for copying data"));
        else if (pid1 == 0) {
                udt_kill_transfer(&s->ptg);
                exit(udt_copy_task_routine(&s->gtp) ? 0 : 1);
@@ -1394,7 +1398,7 @@ static int tloop_spawnwait_tasks(struct bidirectional_transfer_state *s)
        /* Fork thread #2: program to git. */
        pid2 = fork();
        if (pid2 < 0)
-               die_errno("Can't start thread for copying data");
+               die_errno(_("can't start thread for copying data"));
        else if (pid2 == 0) {
                udt_kill_transfer(&s->gtp);
                exit(udt_copy_task_routine(&s->ptg) ? 0 : 1);
index a32da30dee6f4e38433b68d7c9f7e9404aa58858..06ffea277460d68694aa4700b269601b56dd46ce 100644 (file)
@@ -139,7 +139,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
                close(data->fd);
        data->fd = read_bundle_header(transport->url, &data->header);
        if (data->fd < 0)
-               die ("Could not read bundle '%s'.", transport->url);
+               die(_("could not read bundle '%s'"), transport->url);
        for (i = 0; i < data->header.references.nr; i++) {
                struct ref_list_entry *e = data->header.references.list + i;
                struct ref *ref = alloc_ref(e->name);
@@ -318,6 +318,7 @@ static int fetch_refs_via_pack(struct transport *transport,
        args.filter_options = data->options.filter_options;
        args.stateless_rpc = transport->stateless_rpc;
        args.server_options = transport->server_options;
+       args.negotiation_tips = data->options.negotiation_tips;
 
        if (!data->got_remote_heads)
                refs_tmp = get_refs_via_connect(transport, 0, NULL);
@@ -348,6 +349,7 @@ static int fetch_refs_via_pack(struct transport *transport,
        data->got_remote_heads = 0;
        data->options.self_contained_and_connected =
                args.self_contained_and_connected;
+       data->options.connectivity_checked = args.connectivity_checked;
 
        if (refs == NULL)
                ret = -1;
@@ -654,7 +656,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
 
        switch (data->version) {
        case protocol_v2:
-               die("support for protocol v2 not implemented yet");
+               die(_("support for protocol v2 not implemented yet"));
                break;
        case protocol_v1:
        case protocol_v0:
@@ -780,7 +782,7 @@ static enum protocol_allow_config parse_protocol_config(const char *key,
        else if (!strcasecmp(value, "user"))
                return PROTOCOL_ALLOW_USER_ONLY;
 
-       die("unknown value for config '%s': %s", key, value);
+       die(_("unknown value for config '%s': %s"), key, value);
 }
 
 static enum protocol_allow_config get_protocol_config(const char *type)
@@ -846,7 +848,7 @@ int is_transport_allowed(const char *type, int from_user)
 void transport_check_allowed(const char *type)
 {
        if (!is_transport_allowed(type, -1))
-               die("transport '%s' not allowed", type);
+               die(_("transport '%s' not allowed"), type);
 }
 
 static struct transport_vtable bundle_vtable = {
@@ -875,7 +877,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
        ret->progress = isatty(2);
 
        if (!remote)
-               die("No remote provided to transport_get()");
+               BUG("No remote provided to transport_get()");
 
        ret->got_remote_refs = 0;
        ret->remote = remote;
@@ -898,7 +900,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
        if (helper) {
                transport_helper_init(ret, helper);
        } else if (starts_with(url, "rsync:")) {
-               die("git-over-rsync is no longer supported");
+               die(_("git-over-rsync is no longer supported"));
        } else if (url_is_local_not_ssh(url) && is_file(url) && is_bundle(url, 1)) {
                struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
                transport_check_allowed("file");
@@ -1143,7 +1145,7 @@ int transport_push(struct transport *transport,
                                                      transport->push_options,
                                                      pretend)) {
                                oid_array_clear(&commits);
-                               die("Failed to push all needed submodules!");
+                               die(_("failed to push all needed submodules"));
                        }
                        oid_array_clear(&commits);
                }
@@ -1265,7 +1267,7 @@ int transport_connect(struct transport *transport, const char *name,
        if (transport->vtable->connect)
                return transport->vtable->connect(transport, name, exec, fd);
        else
-               die("Operation not supported by protocol");
+               die(_("operation not supported by protocol"));
 }
 
 int transport_disconnect(struct transport *transport)
@@ -1347,7 +1349,7 @@ static void read_alternate_refs(const char *path,
 
                if (get_oid_hex(line.buf, &oid) ||
                    line.buf[GIT_SHA1_HEXSZ] != ' ') {
-                       warning("invalid line while parsing alternate refs: %s",
+                       warning(_("invalid line while parsing alternate refs: %s"),
                                line.buf);
                        break;
                }
index 7792b08582c132e18b495a21b700d9113727c7eb..01e717c29ee6e0f0724b5757ebc7538a72e7e807 100644 (file)
@@ -18,6 +18,17 @@ struct git_transport_options {
        unsigned deepen_relative : 1;
        unsigned from_promisor : 1;
        unsigned no_dependents : 1;
+
+       /*
+        * If this transport supports connect or stateless-connect,
+        * the corresponding field in struct fetch_pack_args is copied
+        * here after fetching.
+        *
+        * See the definition of connectivity_checked in struct
+        * fetch_pack_args for more information.
+        */
+       unsigned connectivity_checked:1;
+
        int depth;
        const char *deepen_since;
        const struct string_list *deepen_not;
@@ -25,6 +36,16 @@ struct git_transport_options {
        const char *receivepack;
        struct push_cas_option *cas;
        struct list_objects_filter_options filter_options;
+
+       /*
+        * This is only used during fetch. See the documentation of
+        * negotiation_tips in struct fetch_pack_args.
+        *
+        * This field is only supported by transports that support connect or
+        * stateless_connect. Set this field directly instead of using
+        * transport_set_option().
+        */
+       struct oid_array *negotiation_tips;
 };
 
 enum transport_family {
index 8f5090862b5193db135f18854974b21e75eb8ae4..77b37f36fa1bc8fae48231d35514b88d51902488 100644 (file)
@@ -2,6 +2,7 @@
 #include "tree-walk.h"
 #include "unpack-trees.h"
 #include "dir.h"
+#include "object-store.h"
 #include "tree.h"
 #include "pathspec.h"
 
@@ -26,8 +27,9 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l
 {
        const char *path;
        unsigned int mode, len;
+       const unsigned hashsz = the_hash_algo->rawsz;
 
-       if (size < 23 || buf[size - 21]) {
+       if (size < hashsz + 3 || buf[size - (hashsz + 1)]) {
                strbuf_addstr(err, _("too-short tree object"));
                return -1;
        }
diff --git a/tree.c b/tree.c
index 2c9c49725ca0eb311a4e82081a6748db7c8e1fcd..215d3fdc7c4af2ef2faca1cf5d5d0b5de52b84a8 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -2,11 +2,13 @@
 #include "cache.h"
 #include "cache-tree.h"
 #include "tree.h"
+#include "object-store.h"
 #include "blob.h"
 #include "commit.h"
 #include "tag.h"
 #include "alloc.h"
 #include "tree-walk.h"
+#include "repository.h"
 
 const char *tree_type = "tree";
 
@@ -17,15 +19,13 @@ static int read_one_entry_opt(struct index_state *istate,
                              unsigned mode, int stage, int opt)
 {
        int len;
-       unsigned int size;
        struct cache_entry *ce;
 
        if (S_ISDIR(mode))
                return READ_TREE_RECURSIVE;
 
        len = strlen(pathname);
-       size = cache_entry_size(baselen + len);
-       ce = xcalloc(1, size);
+       ce = make_empty_cache_entry(istate, baselen + len);
 
        ce->ce_mode = create_ce_mode(mode);
        ce->ce_flags = create_ce_flags(stage);
@@ -99,7 +99,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
                else if (S_ISGITLINK(entry.mode)) {
                        struct commit *commit;
 
-                       commit = lookup_commit(entry.oid);
+                       commit = lookup_commit(the_repository, entry.oid);
                        if (!commit)
                                die("Commit %s in submodule path %s%s not found",
                                    oid_to_hex(entry.oid),
@@ -118,7 +118,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
                len = tree_entry_len(&entry);
                strbuf_add(base, entry.path, len);
                strbuf_addch(base, '/');
-               retval = read_tree_1(lookup_tree(&oid),
+               retval = read_tree_1(lookup_tree(the_repository, &oid),
                                     base, stage, pathspec,
                                     fn, context);
                strbuf_setlen(base, oldlen);
@@ -193,13 +193,13 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
        return 0;
 }
 
-struct tree *lookup_tree(const struct object_id *oid)
+struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(r, oid->hash);
        if (!obj)
-               return create_object(the_repository, oid->hash,
-                                    alloc_tree_node(the_repository));
-       return object_as_type(obj, OBJ_TREE, 0);
+               return create_object(r, oid->hash,
+                                    alloc_tree_node(r));
+       return object_as_type(r, obj, OBJ_TREE, 0);
 }
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
@@ -243,7 +243,7 @@ void free_tree_buffer(struct tree *tree)
 
 struct tree *parse_tree_indirect(const struct object_id *oid)
 {
-       struct object *obj = parse_object(oid);
+       struct object *obj = parse_object(the_repository, oid);
        do {
                if (!obj)
                        return NULL;
@@ -256,6 +256,6 @@ struct tree *parse_tree_indirect(const struct object_id *oid)
                else
                        return NULL;
                if (!obj->parsed)
-                       parse_object(&obj->oid);
+                       parse_object(the_repository, &obj->oid);
        } while (1);
 }
diff --git a/tree.h b/tree.h
index e2a80be4ef87e35d895e8591a0f8a75df347d347..d4807dc805827e6fe07fd01721a8a4680af3403f 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -12,7 +12,7 @@ struct tree {
        unsigned long size;
 };
 
-struct tree *lookup_tree(const struct object_id *oid);
+struct tree *lookup_tree(struct repository *r, const struct object_id *oid);
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
 
index 6dee2c77cebdd93dbc357ab3427175ec291c2310..7c643760f81abb9efd1208e9a6e885e5d6ffd4ea 100644 (file)
@@ -20,12 +20,13 @@ static const struct interval zero_width[] = {
 { 0x0730, 0x074A },
 { 0x07A6, 0x07B0 },
 { 0x07EB, 0x07F3 },
+{ 0x07FD, 0x07FD },
 { 0x0816, 0x0819 },
 { 0x081B, 0x0823 },
 { 0x0825, 0x0827 },
 { 0x0829, 0x082D },
 { 0x0859, 0x085B },
-{ 0x08D4, 0x0902 },
+{ 0x08D3, 0x0902 },
 { 0x093A, 0x093A },
 { 0x093C, 0x093C },
 { 0x0941, 0x0948 },
@@ -37,6 +38,7 @@ static const struct interval zero_width[] = {
 { 0x09C1, 0x09C4 },
 { 0x09CD, 0x09CD },
 { 0x09E2, 0x09E3 },
+{ 0x09FE, 0x09FE },
 { 0x0A01, 0x0A02 },
 { 0x0A3C, 0x0A3C },
 { 0x0A41, 0x0A42 },
@@ -63,6 +65,7 @@ static const struct interval zero_width[] = {
 { 0x0BC0, 0x0BC0 },
 { 0x0BCD, 0x0BCD },
 { 0x0C00, 0x0C00 },
+{ 0x0C04, 0x0C04 },
 { 0x0C3E, 0x0C40 },
 { 0x0C46, 0x0C48 },
 { 0x0C4A, 0x0C4D },
@@ -182,6 +185,7 @@ static const struct interval zero_width[] = {
 { 0xA825, 0xA826 },
 { 0xA8C4, 0xA8C5 },
 { 0xA8E0, 0xA8F1 },
+{ 0xA8FF, 0xA8FF },
 { 0xA926, 0xA92D },
 { 0xA947, 0xA951 },
 { 0xA980, 0xA982 },
@@ -219,19 +223,22 @@ static const struct interval zero_width[] = {
 { 0x10A38, 0x10A3A },
 { 0x10A3F, 0x10A3F },
 { 0x10AE5, 0x10AE6 },
+{ 0x10D24, 0x10D27 },
+{ 0x10F46, 0x10F50 },
 { 0x11001, 0x11001 },
 { 0x11038, 0x11046 },
 { 0x1107F, 0x11081 },
 { 0x110B3, 0x110B6 },
 { 0x110B9, 0x110BA },
 { 0x110BD, 0x110BD },
+{ 0x110CD, 0x110CD },
 { 0x11100, 0x11102 },
 { 0x11127, 0x1112B },
 { 0x1112D, 0x11134 },
 { 0x11173, 0x11173 },
 { 0x11180, 0x11181 },
 { 0x111B6, 0x111BE },
-{ 0x111CA, 0x111CC },
+{ 0x111C9, 0x111CC },
 { 0x1122F, 0x11231 },
 { 0x11234, 0x11234 },
 { 0x11236, 0x11237 },
@@ -239,13 +246,14 @@ static const struct interval zero_width[] = {
 { 0x112DF, 0x112DF },
 { 0x112E3, 0x112EA },
 { 0x11300, 0x11301 },
-{ 0x1133C, 0x1133C },
+{ 0x1133B, 0x1133C },
 { 0x11340, 0x11340 },
 { 0x11366, 0x1136C },
 { 0x11370, 0x11374 },
 { 0x11438, 0x1143F },
 { 0x11442, 0x11444 },
 { 0x11446, 0x11446 },
+{ 0x1145E, 0x1145E },
 { 0x114B3, 0x114B8 },
 { 0x114BA, 0x114BA },
 { 0x114BF, 0x114C0 },
@@ -264,8 +272,9 @@ static const struct interval zero_width[] = {
 { 0x1171D, 0x1171F },
 { 0x11722, 0x11725 },
 { 0x11727, 0x1172B },
-{ 0x11A01, 0x11A06 },
-{ 0x11A09, 0x11A0A },
+{ 0x1182F, 0x11837 },
+{ 0x11839, 0x1183A },
+{ 0x11A01, 0x11A0A },
 { 0x11A33, 0x11A38 },
 { 0x11A3B, 0x11A3E },
 { 0x11A47, 0x11A47 },
@@ -285,6 +294,10 @@ static const struct interval zero_width[] = {
 { 0x11D3C, 0x11D3D },
 { 0x11D3F, 0x11D45 },
 { 0x11D47, 0x11D47 },
+{ 0x11D90, 0x11D91 },
+{ 0x11D95, 0x11D95 },
+{ 0x11D97, 0x11D97 },
+{ 0x11EF3, 0x11EF4 },
 { 0x16AF0, 0x16AF4 },
 { 0x16B30, 0x16B36 },
 { 0x16F8F, 0x16F92 },
@@ -355,7 +368,7 @@ static const struct interval double_width[] = {
 { 0x3000, 0x303E },
 { 0x3041, 0x3096 },
 { 0x3099, 0x30FF },
-{ 0x3105, 0x312E },
+{ 0x3105, 0x312F },
 { 0x3131, 0x318E },
 { 0x3190, 0x31BA },
 { 0x31C0, 0x31E3 },
@@ -375,7 +388,7 @@ static const struct interval double_width[] = {
 { 0xFF01, 0xFF60 },
 { 0xFFE0, 0xFFE6 },
 { 0x16FE0, 0x16FE1 },
-{ 0x17000, 0x187EC },
+{ 0x17000, 0x187F1 },
 { 0x18800, 0x18AF2 },
 { 0x1B000, 0x1B11E },
 { 0x1B170, 0x1B2FB },
@@ -410,13 +423,15 @@ static const struct interval double_width[] = {
 { 0x1F6CC, 0x1F6CC },
 { 0x1F6D0, 0x1F6D2 },
 { 0x1F6EB, 0x1F6EC },
-{ 0x1F6F4, 0x1F6F8 },
+{ 0x1F6F4, 0x1F6F9 },
 { 0x1F910, 0x1F93E },
-{ 0x1F940, 0x1F94C },
-{ 0x1F950, 0x1F96B },
-{ 0x1F980, 0x1F997 },
-{ 0x1F9C0, 0x1F9C0 },
-{ 0x1F9D0, 0x1F9E6 },
+{ 0x1F940, 0x1F970 },
+{ 0x1F973, 0x1F976 },
+{ 0x1F97A, 0x1F97A },
+{ 0x1F97C, 0x1F9A2 },
+{ 0x1F9B0, 0x1F9B9 },
+{ 0x1F9C0, 0x1F9C2 },
+{ 0x1F9D0, 0x1F9FF },
 { 0x20000, 0x2FFFD },
 { 0x30000, 0x3FFFD }
 };
index 3a85a02a7733aeeee86da1a324319d026c32d787..f25089b878a8b0842a9d6407cb6b1821867a737c 100644 (file)
@@ -16,6 +16,7 @@
 #include "submodule.h"
 #include "submodule-config.h"
 #include "fsmonitor.h"
+#include "object-store.h"
 #include "fetch-object.h"
 
 /*
@@ -203,20 +204,11 @@ static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
                               ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
 }
 
-static struct cache_entry *dup_entry(const struct cache_entry *ce)
-{
-       unsigned int size = ce_size(ce);
-       struct cache_entry *new_entry = xmalloc(size);
-
-       memcpy(new_entry, ce, size);
-       return new_entry;
-}
-
 static void add_entry(struct unpack_trees_options *o,
                      const struct cache_entry *ce,
                      unsigned int set, unsigned int clear)
 {
-       do_add_entry(o, dup_entry(ce), set, clear);
+       do_add_entry(o, dup_cache_entry(ce, &o->result), set, clear);
 }
 
 /*
@@ -361,7 +353,7 @@ static int check_updates(struct unpack_trees_options *o)
        progress = get_progress(o);
 
        if (o->update)
-               git_attr_set_direction(GIT_ATTR_CHECKOUT, index);
+               git_attr_set_direction(GIT_ATTR_CHECKOUT);
 
        if (should_update_submodules() && o->update && !o->dry_run)
                load_gitmodules_file(index, NULL);
@@ -421,7 +413,7 @@ static int check_updates(struct unpack_trees_options *o)
        stop_progress(&progress);
        errs |= finish_delayed_checkout(&state);
        if (o->update)
-               git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);
+               git_attr_set_direction(GIT_ATTR_CHECKIN);
        return errs != 0;
 }
 
@@ -797,10 +789,17 @@ static int ce_in_traverse_path(const struct cache_entry *ce,
        return (info->pathlen < ce_namelen(ce));
 }
 
-static struct cache_entry *create_ce_entry(const struct traverse_info *info, const struct name_entry *n, int stage)
+static struct cache_entry *create_ce_entry(const struct traverse_info *info,
+       const struct name_entry *n,
+       int stage,
+       struct index_state *istate,
+       int is_transient)
 {
        int len = traverse_path_len(info, n);
-       struct cache_entry *ce = xcalloc(1, cache_entry_size(len));
+       struct cache_entry *ce =
+               is_transient ?
+               make_empty_transient_cache_entry(len) :
+               make_empty_cache_entry(istate, len);
 
        ce->ce_mode = create_ce_mode(n->mode);
        ce->ce_flags = create_ce_flags(stage);
@@ -846,7 +845,15 @@ static int unpack_nondirectories(int n, unsigned long mask,
                        stage = 3;
                else
                        stage = 2;
-               src[i + o->merge] = create_ce_entry(info, names + i, stage);
+
+               /*
+                * If the merge bit is set, then the cache entries are
+                * discarded in the following block.  In this case,
+                * construct "transient" cache_entries, as they are
+                * not stored in the index.  otherwise construct the
+                * cache entry from the index aware logic.
+                */
+               src[i + o->merge] = create_ce_entry(info, names + i, stage, &o->result, o->merge);
        }
 
        if (o->merge) {
@@ -855,7 +862,7 @@ static int unpack_nondirectories(int n, unsigned long mask,
                for (i = 0; i < n; i++) {
                        struct cache_entry *ce = src[i + o->merge];
                        if (ce != o->df_conflict_entry)
-                               free(ce);
+                               discard_cache_entry(ce);
                }
                return rc;
        }
@@ -1085,13 +1092,15 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
        return mask;
 }
 
-static int clear_ce_flags_1(struct cache_entry **cache, int nr,
+static int clear_ce_flags_1(struct index_state *istate,
+                           struct cache_entry **cache, int nr,
                            struct strbuf *prefix,
                            int select_mask, int clear_mask,
                            struct exclude_list *el, int defval);
 
 /* Whole directory matching */
-static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
+static int clear_ce_flags_dir(struct index_state *istate,
+                             struct cache_entry **cache, int nr,
                              struct strbuf *prefix,
                              char *basename,
                              int select_mask, int clear_mask,
@@ -1100,7 +1109,7 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
        struct cache_entry **cache_end;
        int dtype = DT_DIR;
        int ret = is_excluded_from_list(prefix->buf, prefix->len,
-                                       basename, &dtype, el, &the_index);
+                                       basename, &dtype, el, istate);
        int rc;
 
        strbuf_addch(prefix, '/');
@@ -1122,7 +1131,7 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
         * calling clear_ce_flags_1(). That function will call
         * the expensive is_excluded_from_list() on every entry.
         */
-       rc = clear_ce_flags_1(cache, cache_end - cache,
+       rc = clear_ce_flags_1(istate, cache, cache_end - cache,
                              prefix,
                              select_mask, clear_mask,
                              el, ret);
@@ -1145,7 +1154,8 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
  *   cache[0]->name[0..(prefix_len-1)]
  * Top level path has prefix_len zero.
  */
-static int clear_ce_flags_1(struct cache_entry **cache, int nr,
+static int clear_ce_flags_1(struct index_state *istate,
+                           struct cache_entry **cache, int nr,
                            struct strbuf *prefix,
                            int select_mask, int clear_mask,
                            struct exclude_list *el, int defval)
@@ -1179,7 +1189,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
                        len = slash - name;
                        strbuf_add(prefix, name, len);
 
-                       processed = clear_ce_flags_dir(cache, cache_end - cache,
+                       processed = clear_ce_flags_dir(istate, cache, cache_end - cache,
                                                       prefix,
                                                       prefix->buf + prefix->len - len,
                                                       select_mask, clear_mask,
@@ -1193,7 +1203,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
                        }
 
                        strbuf_addch(prefix, '/');
-                       cache += clear_ce_flags_1(cache, cache_end - cache,
+                       cache += clear_ce_flags_1(istate, cache, cache_end - cache,
                                                  prefix,
                                                  select_mask, clear_mask, el, defval);
                        strbuf_setlen(prefix, prefix->len - len - 1);
@@ -1203,7 +1213,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
                /* Non-directory */
                dtype = ce_to_dtype(ce);
                ret = is_excluded_from_list(ce->name, ce_namelen(ce),
-                                           name, &dtype, el, &the_index);
+                                           name, &dtype, el, istate);
                if (ret < 0)
                        ret = defval;
                if (ret > 0)
@@ -1213,15 +1223,17 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
        return nr - (cache_end - cache);
 }
 
-static int clear_ce_flags(struct cache_entry **cache, int nr,
-                           int select_mask, int clear_mask,
-                           struct exclude_list *el)
+static int clear_ce_flags(struct index_state *istate,
+                         int select_mask, int clear_mask,
+                         struct exclude_list *el)
 {
        static struct strbuf prefix = STRBUF_INIT;
 
        strbuf_reset(&prefix);
 
-       return clear_ce_flags_1(cache, nr,
+       return clear_ce_flags_1(istate,
+                               istate->cache,
+                               istate->cache_nr,
                                &prefix,
                                select_mask, clear_mask,
                                el, 0);
@@ -1231,7 +1243,7 @@ static int clear_ce_flags(struct cache_entry **cache, int nr,
  * Set/Clear CE_NEW_SKIP_WORKTREE according to $GIT_DIR/info/sparse-checkout
  */
 static void mark_new_skip_worktree(struct exclude_list *el,
-                                  struct index_state *the_index,
+                                  struct index_state *istate,
                                   int select_flag, int skip_wt_flag)
 {
        int i;
@@ -1240,13 +1252,13 @@ static void mark_new_skip_worktree(struct exclude_list *el,
         * 1. Pretend the narrowest worktree: only unmerged entries
         * are checked out
         */
-       for (i = 0; i < the_index->cache_nr; i++) {
-               struct cache_entry *ce = the_index->cache[i];
+       for (i = 0; i < istate->cache_nr; i++) {
+               struct cache_entry *ce = istate->cache[i];
 
                if (select_flag && !(ce->ce_flags & select_flag))
                        continue;
 
-               if (!ce_stage(ce))
+               if (!ce_stage(ce) && !(ce->ce_flags & CE_CONFLICTED))
                        ce->ce_flags |= skip_wt_flag;
                else
                        ce->ce_flags &= ~skip_wt_flag;
@@ -1256,8 +1268,7 @@ static void mark_new_skip_worktree(struct exclude_list *el,
         * 2. Widen worktree according to sparse-checkout file.
         * Matched entries will have skip_wt_flag cleared (i.e. "in")
         */
-       clear_ce_flags(the_index->cache, the_index->cache_nr,
-                      select_flag, skip_wt_flag, el);
+       clear_ce_flags(istate, select_flag, skip_wt_flag, el);
 }
 
 static int verify_absent(const struct cache_entry *,
@@ -1545,6 +1556,17 @@ static int verify_uptodate_sparse(const struct cache_entry *ce,
        return verify_uptodate_1(ce, o, ERROR_SPARSE_NOT_UPTODATE_FILE);
 }
 
+/*
+ * TODO: We should actually invalidate o->result, not src_index [1].
+ * But since cache tree and untracked cache both are not copied to
+ * o->result until unpacking is complete, we invalidate them on
+ * src_index instead with the assumption that they will be copied to
+ * dst_index at the end.
+ *
+ * [1] src_index->cache_tree is also used in unpack_callback() so if
+ * we invalidate o->result, we need to update it to use
+ * o->result.cache_tree as well.
+ */
 static void invalidate_ce_path(const struct cache_entry *ce,
                               struct unpack_trees_options *o)
 {
@@ -1636,7 +1658,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
        memset(&d, 0, sizeof(d));
        if (o->dir)
                d.exclude_per_dir = o->dir->exclude_per_dir;
-       i = read_directory(&d, &the_index, pathbuf, namelen+1, NULL);
+       i = read_directory(&d, o->src_index, pathbuf, namelen+1, NULL);
        if (i)
                return o->gently ? -1 :
                        add_rejected_path(o, ERROR_NOT_UPTODATE_DIR, ce->name);
@@ -1678,7 +1700,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
                return 0;
 
        if (o->dir &&
-           is_excluded(o->dir, &the_index, name, &dtype))
+           is_excluded(o->dir, o->src_index, name, &dtype))
                /*
                 * ce->name is explicitly excluded, so it is Ok to
                 * overwrite it.
@@ -1787,7 +1809,7 @@ static int merged_entry(const struct cache_entry *ce,
                        struct unpack_trees_options *o)
 {
        int update = CE_UPDATE;
-       struct cache_entry *merge = dup_entry(ce);
+       struct cache_entry *merge = dup_cache_entry(ce, &o->result);
 
        if (!old) {
                /*
@@ -1807,7 +1829,7 @@ static int merged_entry(const struct cache_entry *ce,
 
                if (verify_absent(merge,
                                  ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) {
-                       free(merge);
+                       discard_cache_entry(merge);
                        return -1;
                }
                invalidate_ce_path(merge, o);
@@ -1833,7 +1855,7 @@ static int merged_entry(const struct cache_entry *ce,
                        update = 0;
                } else {
                        if (verify_uptodate(old, o)) {
-                               free(merge);
+                               discard_cache_entry(merge);
                                return -1;
                        }
                        /* Migrate old flags over */
index c2b434c60648fb0e287c100a32d9346a765ab74f..534358fcc5603e0996ed1b07ddd7c7de9dce4331 100644 (file)
@@ -82,8 +82,8 @@ struct unpack_trees_options {
        struct exclude_list *el; /* for internal use */
 };
 
-extern int unpack_trees(unsigned n, struct tree_desc *t,
-               struct unpack_trees_options *options);
+int unpack_trees(unsigned n, struct tree_desc *t,
+                struct unpack_trees_options *options);
 
 int verify_uptodate(const struct cache_entry *ce,
                    struct unpack_trees_options *o);
index 87c6722ea58207a9b369e75f7cf7ac16a705330b..82b393ec31917c0c2bcd904668a60b5aaef00633 100644 (file)
@@ -3,6 +3,8 @@
 #include "refs.h"
 #include "pkt-line.h"
 #include "sideband.h"
+#include "repository.h"
+#include "object-store.h"
 #include "tag.h"
 #include "object.h"
 #include "commit.h"
@@ -64,6 +66,7 @@ static const char *pack_objects_hook;
 
 static int filter_capability_requested;
 static int allow_filter;
+static int allow_ref_in_want;
 static struct list_objects_filter_options filter_options;
 
 static void reset_timeout(void)
@@ -310,7 +313,7 @@ static int got_oid(const char *hex, struct object_id *oid)
        if (!has_object_file(oid))
                return -1;
 
-       o = parse_object(oid);
+       o = parse_object(the_repository, oid);
        if (!o)
                die("oops (%s)", oid_to_hex(oid));
        if (o->type == OBJ_COMMIT) {
@@ -348,7 +351,7 @@ static int reachable(struct commit *want)
                        break;
                }
                if (!commit->object.parsed)
-                       parse_object(&commit->object.oid);
+                       parse_object(the_repository, &commit->object.oid);
                if (commit->object.flags & REACHABLE)
                        continue;
                commit->object.flags |= REACHABLE;
@@ -378,7 +381,7 @@ static int ok_to_give_up(void)
 
                if (want->flags & COMMON_KNOWN)
                        continue;
-               want = deref_tag(want, "a want line", 0);
+               want = deref_tag(the_repository, want, "a want line", 0);
                if (!want || want->type != OBJ_COMMIT) {
                        /* no way to tell if this is reachable by
                         * looking at the ancestry chain alone, so
@@ -568,7 +571,7 @@ static int get_reachable_list(struct object_array *src,
                if (parse_oid_hex(namebuf, &sha1, &p) || *p != '\n')
                        break;
 
-               o = lookup_object(sha1.hash);
+               o = lookup_object(the_repository, sha1.hash);
                if (o && o->type == OBJ_COMMIT) {
                        o->flags &= ~TMP_MARK;
                }
@@ -658,7 +661,7 @@ static void send_shallow(struct commit_list *result)
                if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
                        packet_write_fmt(1, "shallow %s",
                                         oid_to_hex(&object->oid));
-                       register_shallow(&object->oid);
+                       register_shallow(the_repository, &object->oid);
                        shallow_nr++;
                }
                result = result->next;
@@ -695,14 +698,14 @@ static void send_unshallow(const struct object_array *shallows)
                        add_object_array(object, NULL, &extra_edge_obj);
                }
                /* make sure commit traversal conforms to client */
-               register_shallow(&object->oid);
+               register_shallow(the_repository, &object->oid);
        }
 }
 
 static void deepen(int depth, int deepen_relative,
                   struct object_array *shallows)
 {
-       if (depth == INFINITE_DEPTH && !is_repository_shallow()) {
+       if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) {
                int i;
 
                for (i = 0; i < shallows->nr; i++) {
@@ -782,7 +785,8 @@ static int send_shallow_list(int depth, int deepen_rev_list,
                if (shallows->nr > 0) {
                        int i;
                        for (i = 0; i < shallows->nr; i++)
-                               register_shallow(&shallows->objects[i].item->oid);
+                               register_shallow(the_repository,
+                                                &shallows->objects[i].item->oid);
                }
        }
 
@@ -798,7 +802,7 @@ static int process_shallow(const char *line, struct object_array *shallows)
                struct object *object;
                if (get_oid_hex(arg, &oid))
                        die("invalid shallow line: %s", line);
-               object = parse_object(&oid);
+               object = parse_object(the_repository, &oid);
                if (!object)
                        return 1;
                if (object->type != OBJ_COMMIT)
@@ -924,7 +928,7 @@ static void receive_needs(void)
                if (allow_filter && parse_feature_request(features, "filter"))
                        filter_capability_requested = 1;
 
-               o = parse_object(&oid_buf);
+               o = parse_object(the_repository, &oid_buf);
                if (!o) {
                        packet_write_fmt(1,
                                         "ERR upload-pack: not our ref %s",
@@ -1075,6 +1079,8 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
                        return git_config_string(&pack_objects_hook, var, value);
        } else if (!strcmp("uploadpack.allowfilter", var)) {
                allow_filter = git_config_bool(var, value);
+       } else if (!strcmp("uploadpack.allowrefinwant", var)) {
+               allow_ref_in_want = git_config_bool(var, value);
        }
        return parse_hide_refs_config(var, value, "uploadpack");
 }
@@ -1114,6 +1120,7 @@ void upload_pack(struct upload_pack_options *options)
 
 struct upload_pack_data {
        struct object_array wants;
+       struct string_list wanted_refs;
        struct oid_array haves;
 
        struct object_array shallows;
@@ -1135,12 +1142,14 @@ struct upload_pack_data {
 static void upload_pack_data_init(struct upload_pack_data *data)
 {
        struct object_array wants = OBJECT_ARRAY_INIT;
+       struct string_list wanted_refs = STRING_LIST_INIT_DUP;
        struct oid_array haves = OID_ARRAY_INIT;
        struct object_array shallows = OBJECT_ARRAY_INIT;
        struct string_list deepen_not = STRING_LIST_INIT_DUP;
 
        memset(data, 0, sizeof(*data));
        data->wants = wants;
+       data->wanted_refs = wanted_refs;
        data->haves = haves;
        data->shallows = shallows;
        data->deepen_not = deepen_not;
@@ -1149,6 +1158,7 @@ static void upload_pack_data_init(struct upload_pack_data *data)
 static void upload_pack_data_clear(struct upload_pack_data *data)
 {
        object_array_clear(&data->wants);
+       string_list_clear(&data->wanted_refs, 1);
        oid_array_clear(&data->haves);
        object_array_clear(&data->shallows);
        string_list_clear(&data->deepen_not, 0);
@@ -1165,7 +1175,7 @@ static int parse_want(const char *line)
                        die("git upload-pack: protocol error, "
                            "expected to get oid, not '%s'", line);
 
-               o = parse_object(&oid);
+               o = parse_object(the_repository, &oid);
                if (!o) {
                        packet_write_fmt(1,
                                         "ERR upload-pack: not our ref %s",
@@ -1185,6 +1195,34 @@ static int parse_want(const char *line)
        return 0;
 }
 
+static int parse_want_ref(const char *line, struct string_list *wanted_refs)
+{
+       const char *arg;
+       if (skip_prefix(line, "want-ref ", &arg)) {
+               struct object_id oid;
+               struct string_list_item *item;
+               struct object *o;
+
+               if (read_ref(arg, &oid)) {
+                       packet_write_fmt(1, "ERR unknown ref %s", arg);
+                       die("unknown ref %s", arg);
+               }
+
+               item = string_list_append(wanted_refs, arg);
+               item->util = oiddup(&oid);
+
+               o = parse_object_or_die(&oid, arg);
+               if (!(o->flags & WANTED)) {
+                       o->flags |= WANTED;
+                       add_object_array(o, NULL, &want_obj);
+               }
+
+               return 1;
+       }
+
+       return 0;
+}
+
 static int parse_have(const char *line, struct oid_array *haves)
 {
        const char *arg;
@@ -1210,6 +1248,8 @@ static void process_args(struct packet_reader *request,
                /* process want */
                if (parse_want(arg))
                        continue;
+               if (allow_ref_in_want && parse_want_ref(arg, &data->wanted_refs))
+                       continue;
                /* process have line */
                if (parse_have(arg, &data->haves))
                        continue;
@@ -1277,7 +1317,7 @@ static int process_haves(struct oid_array *haves, struct oid_array *common)
 
                oid_array_append(common, oid);
 
-               o = parse_object(oid);
+               o = parse_object(the_repository, oid);
                if (!o)
                        die("oops (%s)", oid_to_hex(oid));
                if (o->type == OBJ_COMMIT) {
@@ -1352,18 +1392,37 @@ static int process_haves_and_send_acks(struct upload_pack_data *data)
        return ret;
 }
 
+static void send_wanted_ref_info(struct upload_pack_data *data)
+{
+       const struct string_list_item *item;
+
+       if (!data->wanted_refs.nr)
+               return;
+
+       packet_write_fmt(1, "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_delim(1);
+}
+
 static void send_shallow_info(struct upload_pack_data *data)
 {
        /* No shallow info needs to be sent */
        if (!data->depth && !data->deepen_rev_list && !data->shallows.nr &&
-           !is_repository_shallow())
+           !is_repository_shallow(the_repository))
                return;
 
        packet_write_fmt(1, "shallow-info\n");
 
        if (!send_shallow_list(data->depth, data->deepen_rev_list,
                               data->deepen_since, &data->deepen_not,
-                              &data->shallows) && is_repository_shallow())
+                              &data->shallows) &&
+           is_repository_shallow(the_repository))
                deepen(INFINITE_DEPTH, data->deepen_relative, &data->shallows);
 
        packet_delim(1);
@@ -1418,6 +1477,7 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
                                state = FETCH_DONE;
                        break;
                case FETCH_SEND_PACK:
+                       send_wanted_ref_info(&data);
                        send_shallow_info(&data);
 
                        packet_write_fmt(1, "packfile\n");
@@ -1438,12 +1498,22 @@ int upload_pack_advertise(struct repository *r,
 {
        if (value) {
                int allow_filter_value;
+               int allow_ref_in_want;
+
                strbuf_addstr(value, "shallow");
+
                if (!repo_config_get_bool(the_repository,
                                         "uploadpack.allowfilter",
                                         &allow_filter_value) &&
                    allow_filter_value)
                        strbuf_addstr(value, " filter");
+
+               if (!repo_config_get_bool(the_repository,
+                                        "uploadpack.allowrefinwant",
+                                        &allow_ref_in_want) &&
+                   allow_ref_in_want)
+                       strbuf_addstr(value, " ref-in-want");
        }
+
        return 1;
 }
index a69241b25ddaff5b61380aa8b451a6fcb833502c..f3f4be579c9810d0fcf94badd4bf21770b99c91b 100644 (file)
@@ -114,7 +114,7 @@ PATTERNS("perl",
         "|<<|<>|<=>|>>"),
 PATTERNS("php",
         "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
-        "^[\t ]*(class.*)$",
+        "^[\t ]*((((final|abstract)[\t ]+)?class|interface|trait).*)$",
         /* -- */
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
@@ -278,7 +278,7 @@ struct userdiff_driver *userdiff_find_by_path(const char *path)
                check = attr_check_initl("diff", NULL);
        if (!path)
                return NULL;
-       if (git_check_attr(path, check))
+       if (git_check_attr(&the_index, path, check))
                return NULL;
 
        if (ATTR_TRUE(check->items[0].value))
diff --git a/utf8.c b/utf8.c
index d55e20c6415cb53ef66e1edd0a5e7dc470e18052..eb785875042920b84e56abbd235ef9eb7ef22ac4 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -470,14 +470,14 @@ 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, int *outsz_p)
+char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv, size_t *outsz_p)
 {
        size_t outsz, outalloc;
        char *out, *outpos;
        iconv_ibp cp;
 
        outsz = insz;
-       outalloc = outsz + 1; /* for terminating NUL */
+       outalloc = st_add(outsz, 1); /* for terminating NUL */
        out = xmalloc(outalloc);
        outpos = out;
        cp = (iconv_ibp)in;
@@ -497,7 +497,7 @@ char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv, int *outs
                         * converting the rest.
                         */
                        sofar = outpos - out;
-                       outalloc = sofar + insz * 2 + 32;
+                       outalloc = st_add3(sofar, st_mult(insz, 2), 32);
                        out = xrealloc(out, outalloc);
                        outpos = out + sofar;
                        outsz = outalloc - sofar - 1;
@@ -534,9 +534,9 @@ static const char *fallback_encoding(const char *name)
        return name;
 }
 
-char *reencode_string_len(const char *in, int insz,
+char *reencode_string_len(const char *in, size_t insz,
                          const char *out_encoding, const char *in_encoding,
-                         int *outsz)
+                         size_t *outsz)
 {
        iconv_t conv;
        char *out;
@@ -566,10 +566,10 @@ 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[] = {0xFE, 0xFF};
-static const char utf16_le_bom[] = {0xFF, 0xFE};
-static const char utf32_be_bom[] = {0x00, 0x00, 0xFE, 0xFF};
-static const char utf32_le_bom[] = {0xFF, 0xFE, 0x00, 0x00};
+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)
 {
diff --git a/utf8.h b/utf8.h
index db73a2d8d374e7570471627693ecddc87d998f10..ce1c2696e069782807354a846f2cfe075e1dfd5c 100644 (file)
--- a/utf8.h
+++ b/utf8.h
@@ -25,14 +25,14 @@ 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, int *outsz);
-char *reencode_string_len(const char *in, int insz,
+                           iconv_t conv, size_t *outsz);
+char *reencode_string_len(const char *in, size_t insz,
                          const char *out_encoding,
                          const char *in_encoding,
-                         int *outsz);
+                         size_t *outsz);
 #else
-static inline char *reencode_string_len(const char *a, int b,
-                                       const char *c, const char *d, int *e)
+static inline char *reencode_string_len(const char *a, size_t b,
+                                       const char *c, const char *d, size_t *e)
 { if (e) *e = 0; return NULL; }
 #endif
 
index 0b162a09b95a3eadeef47f3e6d314d386215cc9f..96990d84dabfdd34e169c8e9fcfd656633e4f31e 100644 (file)
--- a/walker.c
+++ b/walker.c
@@ -1,5 +1,7 @@
 #include "cache.h"
 #include "walker.h"
+#include "repository.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "tree-walk.h"
@@ -47,12 +49,14 @@ static int process_tree(struct walker *walker, struct tree *tree)
                if (S_ISGITLINK(entry.mode))
                        continue;
                if (S_ISDIR(entry.mode)) {
-                       struct tree *tree = lookup_tree(entry.oid);
+                       struct tree *tree = lookup_tree(the_repository,
+                                                       entry.oid);
                        if (tree)
                                obj = &tree->object;
                }
                else {
-                       struct blob *blob = lookup_blob(entry.oid);
+                       struct blob *blob = lookup_blob(the_repository,
+                                                       entry.oid);
                        if (blob)
                                obj = &blob->object;
                }
@@ -177,7 +181,7 @@ static int loop(struct walker *walker)
                        }
                }
                if (!obj->type)
-                       parse_object(&obj->oid);
+                       parse_object(the_repository, &obj->oid);
                if (process_object(walker, obj))
                        return -1;
        }
@@ -203,7 +207,8 @@ static int interpret_target(struct walker *walker, char *target, struct object_i
 static int mark_complete(const char *path, const struct object_id *oid,
                         int flag, void *cb_data)
 {
-       struct commit *commit = lookup_commit_reference_gently(oid, 1);
+       struct commit *commit = lookup_commit_reference_gently(the_repository,
+                                                              oid, 1);
 
        if (commit) {
                commit->object.flags |= COMPLETE;
diff --git a/ws.c b/ws.c
index a07caedd5a565bbf29e4f9b3036ac60e6e9f716e..5b67b426e7b41d92f9b11bd82fd7e9bd09c89d79 100644 (file)
--- a/ws.c
+++ b/ws.c
@@ -78,7 +78,7 @@ unsigned whitespace_rule(const char *pathname)
        if (!attr_whitespace_rule)
                attr_whitespace_rule = attr_check_initl("whitespace", NULL);
 
-       if (!git_check_attr(pathname, attr_whitespace_rule)) {
+       if (!git_check_attr(&the_index, pathname, attr_whitespace_rule)) {
                const char *value;
 
                value = attr_whitespace_rule->items[0].value;
index d1c05145a4bded06a7fccc60543193d2f5181953..5ffab61015da908ed36b7ca6455f53fd42f1e292 100644 (file)
@@ -647,7 +647,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
                struct wt_status_change_data *d;
                const struct cache_entry *ce = active_cache[i];
 
-               if (!ce_path_match(ce, &s->pathspec, NULL))
+               if (!ce_path_match(&the_index, ce, &s->pathspec, NULL))
                        continue;
                if (ce_intent_to_add(ce))
                        continue;
@@ -703,7 +703,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
        for (i = 0; i < dir.nr; i++) {
                struct dir_entry *ent = dir.entries[i];
                if (cache_name_is_other(ent->name, ent->len) &&
-                   dir_path_match(ent, &s->pathspec, 0, NULL))
+                   dir_path_match(&the_index, ent, &s->pathspec, 0, NULL))
                        string_list_insert(&s->untracked, ent->name);
                free(ent);
        }
@@ -711,7 +711,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
        for (i = 0; i < dir.ignored_nr; i++) {
                struct dir_entry *ent = dir.ignored[i];
                if (cache_name_is_other(ent->name, ent->len) &&
-                   dir_path_match(ent, &s->pathspec, 0, NULL))
+                   dir_path_match(&the_index, ent, &s->pathspec, 0, NULL))
                        string_list_insert(&s->ignored, ent->name);
                free(ent);
        }
@@ -1317,7 +1317,7 @@ static void show_rebase_in_progress(struct wt_status *s,
                        status_printf_ln(s, color,
                                _("  (use \"git rebase --abort\" to check out the original branch)"));
                }
-       } else if (state->rebase_in_progress || !stat(git_path_merge_msg(), &st)) {
+       } else if (state->rebase_in_progress || !stat(git_path_merge_msg(the_repository), &st)) {
                print_rebase_state(s, state, color);
                if (s->hints)
                        status_printf_ln(s, color,
@@ -1489,7 +1489,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
            /* sha1 is a commit? match without further lookup */
            (!oidcmp(&cb.noid, &oid) ||
             /* perhaps sha1 is a tag, try to dereference to a commit */
-            ((commit = lookup_commit_reference_gently(&oid, 1)) != NULL &&
+            ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&
              !oidcmp(&cb.noid, &commit->object.oid)))) {
                const char *from = ref;
                if (!skip_prefix(from, "refs/tags/", &from))
@@ -1552,17 +1552,17 @@ void wt_status_get_state(struct wt_status_state *state,
        struct stat st;
        struct object_id oid;
 
-       if (!stat(git_path_merge_head(), &st)) {
+       if (!stat(git_path_merge_head(the_repository), &st)) {
                state->merge_in_progress = 1;
        } else if (wt_status_check_rebase(NULL, state)) {
                ;               /* all set */
-       } else if (!stat(git_path_cherry_pick_head(), &st) &&
+       } else if (!stat(git_path_cherry_pick_head(the_repository), &st) &&
                        !get_oid("CHERRY_PICK_HEAD", &oid)) {
                state->cherry_pick_in_progress = 1;
                oidcpy(&state->cherry_pick_head_oid, &oid);
        }
        wt_status_check_bisect(NULL, state);
-       if (!stat(git_path_revert_head(), &st) &&
+       if (!stat(git_path_revert_head(the_repository), &st) &&
            !get_oid("REVERT_HEAD", &oid)) {
                state->revert_in_progress = 1;
                oidcpy(&state->revert_head_oid, &oid);
@@ -2340,7 +2340,17 @@ int has_uncommitted_changes(int ignore_submodules)
        if (ignore_submodules)
                rev_info.diffopt.flags.ignore_submodules = 1;
        rev_info.diffopt.flags.quick = 1;
+
        add_head_to_pending(&rev_info);
+       if (!rev_info.pending.nr) {
+               /*
+                * We have no head (or it's corrupt); use the empty tree,
+                * which will complain if the index is non-empty.
+                */
+               struct tree *tree = lookup_tree(the_repository, the_hash_algo->empty_tree);
+               add_pending_object(&rev_info, &tree->object, "");
+       }
+
        diff_setup_done(&rev_info.diffopt);
        result = run_diff_index(&rev_info, 1);
        return diff_result_code(&rev_info.diffopt, result);
index 9315bc0ede11ba0377e27d711e37b6a0ae555c43..ec6e574e4aa07414b9a17bb99ddee26fd44497de 100644 (file)
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "xdiff-interface.h"
 #include "xdiff/xtypes.h"
 #include "xdiff/xdiffi.h"
index c1937a291126ca5e451763ccdf22bf8cccd0bd42..2356da5f784fbe5670b3f9e8bbc6d6419b4fa9d3 100644 (file)
@@ -52,14 +52,6 @@ extern "C" {
 #define XDL_EMIT_FUNCNAMES (1 << 0)
 #define XDL_EMIT_FUNCCONTEXT (1 << 2)
 
-#define XDL_MMB_READONLY (1 << 0)
-
-#define XDL_MMF_ATOMIC (1 << 0)
-
-#define XDL_BDOP_INS 1
-#define XDL_BDOP_CPY 2
-#define XDL_BDOP_INSB 3
-
 /* merge simplification levels */
 #define XDL_MERGE_MINIMAL 0
 #define XDL_MERGE_EAGER 1
index 0de1ef463bf71b2021ae142a80ac5f87a03a43fc..1f1f4a3c7808435f73b0ffd1c35d5b0572516b6c 100644 (file)
 
 #include "xinclude.h"
 
-
-
 #define XDL_MAX_COST_MIN 256
 #define XDL_HEUR_MIN_COST 256
 #define XDL_LINE_MAX (long)((1UL << (CHAR_BIT * sizeof(long) - 1)) - 1)
 #define XDL_SNAKE_CNT 20
 #define XDL_K_HEUR 4
 
-
-
 typedef struct s_xdpsplit {
        long i1, i2;
        int min_lo, min_hi;
 } xdpsplit_t;
 
-
-
-
-static long xdl_split(unsigned long const *ha1, long off1, long lim1,
-                     unsigned long const *ha2, long off2, long lim2,
-                     long *kvdf, long *kvdb, int need_min, xdpsplit_t *spl,
-                     xdalgoenv_t *xenv);
-static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1, long chg2);
-
-
-
-
-
 /*
  * See "An O(ND) Difference Algorithm and its Variations", by Eugene Myers.
  * Basically considers a "box" (off1, off2, lim1, lim2) and scan from both
@@ -591,6 +574,11 @@ static void measure_split(const xdfile_t *xdf, long split,
  */
 #define INDENT_WEIGHT 60
 
+/*
+ * How far do we slide a hunk at most?
+ */
+#define INDENT_HEURISTIC_MAX_SLIDING 100
+
 /*
  * Compute a badness score for the hypothetical split whose measurements are
  * stored in m. The weight factors were determined empirically using the tools and
@@ -903,7 +891,12 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
                        long shift, best_shift = -1;
                        struct split_score best_score;
 
-                       for (shift = earliest_end; shift <= g.end; shift++) {
+                       shift = earliest_end;
+                       if (g.end - groupsize - 1 > shift)
+                               shift = g.end - groupsize - 1;
+                       if (g.end - INDENT_HEURISTIC_MAX_SLIDING > shift)
+                               shift = g.end - INDENT_HEURISTIC_MAX_SLIDING;
+                       for (; shift <= g.end; shift++) {
                                struct split_measurement m;
                                struct split_score score = {0, 0};
 
index 73210cb6f3fb5d1cb90b1c5959a5a90e058ea1f2..ec85f5992bd2c5148382eaba73b6c4c51c74dbf2 100644 (file)
@@ -233,54 +233,31 @@ static int try_lcs(struct histindex *index, struct region *lcs, int b_ptr,
        return b_next;
 }
 
-static int find_lcs(struct histindex *index, struct region *lcs,
-       int line1, int count1, int line2, int count2) {
-       int b_ptr;
-
-       if (scanA(index, line1, count1))
-               return -1;
-
-       index->cnt = index->max_chain_length + 1;
-
-       for (b_ptr = line2; b_ptr <= LINE_END(2); )
-               b_ptr = try_lcs(index, lcs, b_ptr, line1, count1, line2, count2);
-
-       return index->has_common && index->max_chain_length < index->cnt;
-}
-
-static int fall_back_to_classic_diff(struct histindex *index,
+static int fall_back_to_classic_diff(xpparam_t const *xpp, xdfenv_t *env,
                int line1, int count1, int line2, int count2)
 {
-       xpparam_t xpp;
-       xpp.flags = index->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK;
+       xpparam_t xpparam;
+       xpparam.flags = xpp->flags & ~XDF_DIFF_ALGORITHM_MASK;
 
-       return xdl_fall_back_diff(index->env, &xpp,
+       return xdl_fall_back_diff(env, &xpparam,
                                  line1, count1, line2, count2);
 }
 
-static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
-       int line1, int count1, int line2, int count2)
+static inline void free_index(struct histindex *index)
 {
-       struct histindex index;
-       struct region lcs;
-       int sz;
-       int result = -1;
-
-       if (count1 <= 0 && count2 <= 0)
-               return 0;
-
-       if (LINE_END(1) >= MAX_PTR)
-               return -1;
+       xdl_free(index->records);
+       xdl_free(index->line_map);
+       xdl_free(index->next_ptrs);
+       xdl_cha_free(&index->rcha);
+}
 
-       if (!count1) {
-               while(count2--)
-                       env->xdf2.rchg[line2++ - 1] = 1;
-               return 0;
-       } else if (!count2) {
-               while(count1--)
-                       env->xdf1.rchg[line1++ - 1] = 1;
-               return 0;
-       }
+static int find_lcs(xpparam_t const *xpp, xdfenv_t *env,
+                   struct region *lcs,
+                   int line1, int count1, int line2, int count2)
+{
+       int b_ptr;
+       int sz, ret = -1;
+       struct histindex index;
 
        memset(&index, 0, sizeof(index));
 
@@ -318,9 +295,55 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
        index.ptr_shift = line1;
        index.max_chain_length = 64;
 
+       if (scanA(&index, line1, count1))
+               goto cleanup;
+
+       index.cnt = index.max_chain_length + 1;
+
+       for (b_ptr = line2; b_ptr <= LINE_END(2); )
+               b_ptr = try_lcs(&index, lcs, b_ptr, line1, count1, line2, count2);
+
+       if (index.has_common && index.max_chain_length < index.cnt)
+               ret = 1;
+       else
+               ret = 0;
+
+cleanup:
+       free_index(&index);
+       return ret;
+}
+
+static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
+       int line1, int count1, int line2, int count2)
+{
+       struct region lcs;
+       int lcs_found;
+       int result;
+redo:
+       result = -1;
+
+       if (count1 <= 0 && count2 <= 0)
+               return 0;
+
+       if (LINE_END(1) >= MAX_PTR)
+               return -1;
+
+       if (!count1) {
+               while(count2--)
+                       env->xdf2.rchg[line2++ - 1] = 1;
+               return 0;
+       } else if (!count2) {
+               while(count1--)
+                       env->xdf1.rchg[line1++ - 1] = 1;
+               return 0;
+       }
+
        memset(&lcs, 0, sizeof(lcs));
-       if (find_lcs(&index, &lcs, line1, count1, line2, count2))
-               result = fall_back_to_classic_diff(&index, line1, count1, line2, count2);
+       lcs_found = find_lcs(xpp, env, &lcs, line1, count1, line2, count2);
+       if (lcs_found < 0)
+               goto out;
+       else if (lcs_found)
+               result = fall_back_to_classic_diff(xpp, env, line1, count1, line2, count2);
        else {
                if (lcs.begin1 == 0 && lcs.begin2 == 0) {
                        while (count1--)
@@ -333,21 +356,21 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
                                                line1, lcs.begin1 - line1,
                                                line2, lcs.begin2 - line2);
                        if (result)
-                               goto cleanup;
-                       result = histogram_diff(xpp, env,
-                                               lcs.end1 + 1, LINE_END(1) - lcs.end1,
-                                               lcs.end2 + 1, LINE_END(2) - lcs.end2);
-                       if (result)
-                               goto cleanup;
+                               goto out;
+                       /*
+                        * result = histogram_diff(xpp, env,
+                        *            lcs.end1 + 1, LINE_END(1) - lcs.end1,
+                        *            lcs.end2 + 1, LINE_END(2) - lcs.end2);
+                        * but let's optimize tail recursion ourself:
+                       */
+                       count1 = LINE_END(1) - lcs.end1;
+                       line1 = lcs.end1 + 1;
+                       count2 = LINE_END(2) - lcs.end2;
+                       line2 = lcs.end2 + 1;
+                       goto redo;
                }
        }
-
-cleanup:
-       xdl_free(index.records);
-       xdl_free(index.line_map);
-       xdl_free(index.next_ptrs);
-       xdl_cha_free(&index.rcha);
-
+out:
        return result;
 }