Merge branch 'sg/stress-test'
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2019 21:49:56 +0000 (13:49 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2019 21:49:56 +0000 (13:49 -0800)
Flaky tests can now be repeatedly run under load with the
"--stress" option.

* sg/stress-test:
test-lib: add the '--stress' option to run a test repeatedly under load
test-lib-functions: introduce the 'test_set_port' helper function
test-lib: set $TRASH_DIRECTORY earlier
test-lib: consolidate naming of test-results paths
test-lib: parse command line options earlier
test-lib: parse options in a for loop to keep $@ intact
test-lib: extract Bash version check for '-x' tracing
test-lib: translate SIGTERM and SIGHUP to an exit

237 files changed:
.gitattributes
.mailmap
Documentation/RelNotes/2.20.1.txt [new file with mode: 0644]
Documentation/RelNotes/2.21.0.txt [new file with mode: 0644]
Documentation/config/advice.txt
Documentation/config/http.txt
Documentation/config/worktree.txt
Documentation/diff-options.txt
Documentation/git-checkout.txt
Documentation/git-clone.txt
Documentation/git-column.txt
Documentation/git-fast-export.txt
Documentation/git-fast-import.txt
Documentation/git-gc.txt
Documentation/git-init.txt
Documentation/git-push.txt
Documentation/git-quiltimport.txt
Documentation/git-rebase.txt
Documentation/git-status.txt
Documentation/gitdiffcore.txt
Documentation/gitweb.conf.txt
Documentation/glossary-content.txt
Documentation/rev-list-options.txt
GIT-VERSION-GEN
RelNotes
advice.c
advice.h
alias.c
apply.c
archive-tar.c
archive.c
attr.c
banned.h
bisect.c
bisect.h
blame.c
branch.c
branch.h
builtin/add.c
builtin/am.c
builtin/bisect--helper.c
builtin/blame.c
builtin/branch.c
builtin/bundle.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clone.c
builtin/commit.c
builtin/config.c
builtin/count-objects.c
builtin/difftool.c
builtin/fast-export.c
builtin/fsck.c
builtin/gc.c
builtin/grep.c
builtin/log.c
builtin/ls-files.c
builtin/ls-tree.c
builtin/merge-ours.c
builtin/merge-tree.c
builtin/merge.c
builtin/notes.c
builtin/pack-objects.c
builtin/prune.c
builtin/pull.c
builtin/push.c
builtin/read-tree.c
builtin/rebase--interactive.c
builtin/rebase.c
builtin/reflog.c
builtin/repack.c
builtin/rerere.c
builtin/reset.c
builtin/rev-list.c
builtin/revert.c
builtin/shortlog.c
builtin/stripspace.c
builtin/submodule--helper.c
builtin/update-index.c
builtin/worktree.c
bundle.c
bundle.h
cache-tree.c
cache-tree.h
cache.h
combine-diff.c
commit-graph.c
compat/cygwin.c [deleted file]
compat/cygwin.h [deleted file]
compat/mingw.c
compat/mingw.h
compat/regex/regcomp.c
compat/win32/path-utils.c [new file with mode: 0644]
compat/win32/path-utils.h [new file with mode: 0644]
config.mak.dev
config.mak.uname
contrib/completion/git-completion.bash
contrib/completion/git-completion.zsh
contrib/hooks/multimail/CHANGES
contrib/hooks/multimail/CONTRIBUTING.rst
contrib/hooks/multimail/README [deleted file]
contrib/hooks/multimail/README.Git
contrib/hooks/multimail/README.rst [new file with mode: 0644]
contrib/hooks/multimail/doc/gitolite.rst
contrib/hooks/multimail/git_multimail.py
contrib/hooks/multimail/migrate-mailhook-config
contrib/hooks/multimail/post-receive.example
convert.c
credential-cache--daemon.c
delta-islands.c
delta-islands.h
diff-lib.c
diff.c
diff.h
diffcore-pickaxe.c
dir.c
entry.c
environment.c
fast-import.c
fetch-pack.c
git-compat-util.h
git-p4.py
git-quiltimport.sh
git-stash.sh
git.c
grep.c
help.c
help.h
http-backend.c
http-walker.c
http.c
imap-send.c
line-log.c
list-objects-filter.c
list-objects-filter.h
list-objects.c
ll-merge.c
ll-merge.h
merge-recursive.c
midx.c
notes-cache.c
notes-cache.h
notes-merge.c
notes-merge.h
object-store.h
object.c
pack-bitmap-write.c
pack-bitmap.c
pack-bitmap.h
pack-check.c
pack-objects.c
pack-objects.h
pack.h
packfile.c
parse-options-cb.c
parse-options.c
parse-options.h
path.c
pathspec.c
pathspec.h
quote.c
read-cache.c
rebase-interactive.c
rebase-interactive.h
ref-filter.c
remote-curl.c
remote.c
repository.c
rerere.c
rerere.h
revision.c
revision.h
run-command.c
sequencer.c
sequencer.h
setup.c
sha1-file.c
sha1-name.c
sideband.c
string-list.c
submodule.c
submodule.h
symlinks.c
t/.gitattributes
t/check-non-portable-shell.pl
t/helper/test-sigchain.c
t/lib-git-daemon.sh
t/lib-submodule-update.sh
t/t0027-auto-crlf.sh
t/t0030-stripspace.sh
t/t0040-parse-options.sh
t/t0061-run-command.sh
t/t0410-partial-clone.sh
t/t1410-reflog.sh
t/t1450-fsck.sh
t/t2024-checkout-dwim.sh
t/t2028-worktree-move.sh
t/t3502-cherry-pick-merge.sh
t/t3506-cherry-pick-ff.sh
t/t3510-cherry-pick-sequence.sh
t/t3903-stash.sh
t/t4015-diff-whitespace.sh
t/t4209-log-pickaxe.sh
t/t4211-line-log.sh
t/t5004-archive-corner-cases.sh
t/t5409-colorize-remote-messages.sh
t/t5505-remote.sh
t/t5526-fetch-submodules.sh
t/t5570-git-daemon.sh
t/t5601-clone.sh
t/t5611-clone-config.sh
t/t5616-partial-clone.sh
t/t5703-upload-pack-ref-in-want.sh
t/t6036-recursive-corner-cases.sh
t/t6042-merge-rename-corner-cases.sh
t/t6043-merge-rename-directories.sh
t/t6050-replace.sh
t/t6135-pathspec-with-attrs.sh
t/t7400-submodule-basic.sh
t/t7412-submodule-absorbgitdirs.sh
t/t7415-submodule-names.sh
t/t9350-fast-export.sh
t/t9902-completion.sh
transport-helper.c
transport.c
transport.h
tree-diff.c
tree-walk.c
tree-walk.h
tree.c
tree.h
unpack-trees.c
url.c
userdiff.c
userdiff.h
wt-status.c
wt-status.h
index acf853e0299463a12212e9ed5f35d7f4a9d289af..9fa72ad4503031528e24e7c69f24ca92bcc99914 100644 (file)
@@ -9,6 +9,7 @@
 /command-list.txt eol=lf
 /GIT-VERSION-GEN eol=lf
 /mergetools/* eol=lf
+/t/oid-info/* eol=lf
 /Documentation/git-merge.txt conflict-marker-size=32
 /Documentation/gitk.txt conflict-marker-size=32
 /Documentation/user-manual.txt conflict-marker-size=32
index eb7b5fc7b97f33999eced124943728854bc2e983..247a3deb7e1418f0fdcfd9719cb7f609775d2804 100644 (file)
--- a/.mailmap
+++ b/.mailmap
@@ -27,6 +27,7 @@ Ben Walton <bdwalton@gmail.com> <bwalton@artsci.utoronto.ca>
 Benoit Sigoure <tsunanet@gmail.com> <tsuna@lrde.epita.fr>
 Bernt Hansen <bernt@norang.ca> <bernt@alumni.uwaterloo.ca>
 Brandon Casey <drafnel@gmail.com> <casey@nrlssc.navy.mil>
+Brandon Williams <bwilliams.eng@gmail.com> <bmwill@google.com>
 brian m. carlson <sandals@crustytoothpaste.net>
 brian m. carlson <sandals@crustytoothpaste.net> <sandals@crustytoothpaste.ath.cx>
 Bryan Larsen <bryan@larsen.st> <bryan.larsen@gmail.com>
diff --git a/Documentation/RelNotes/2.20.1.txt b/Documentation/RelNotes/2.20.1.txt
new file mode 100644 (file)
index 0000000..dcba888
--- /dev/null
@@ -0,0 +1,20 @@
+Git v2.20.1 Release Notes
+=========================
+
+This release is primarily to fix brown-paper-bag breakages in the
+2.20.0 release.
+
+Fixes since v2.20
+-----------------
+
+ * A few newly added tests were not portable and caused minority
+   platforms to report false breakages, which have been fixed.
+
+ * Portability fix for a recent update to parse-options API.
+
+ * "git help -a" did not work well when an overly long alias is
+   defined, which has been corrected.
+
+ * A recent update accidentally squelched an error message when the
+   run_command API failed to run a missing command, which has been
+   corrected.
diff --git a/Documentation/RelNotes/2.21.0.txt b/Documentation/RelNotes/2.21.0.txt
new file mode 100644 (file)
index 0000000..71e437a
--- /dev/null
@@ -0,0 +1,108 @@
+Git 2.21 Release Notes
+======================
+
+Backward Compatibility Notes
+----------------------------
+
+
+Updates since v2.20
+-------------------
+
+UI, Workflows & Features
+
+ * The "http.version" configuration variable can be used with recent
+   enough cURL library to force the version of HTTP used to talk when
+   fetching and pushing.
+
+ * Small fixes and features for fast-export and fast-import, mostly on
+   the fast-export side.
+
+ * "git push $there $src:$dst" rejects when $dst is not a fully
+   qualified refname and not clear what the end user meant.  The
+   codepath has been taught to give a clearer error message, and also
+   guess where the push should go by taking the type of the pushed
+   object into account (e.g. a tag object would want to go under
+   refs/tags/).
+
+ * "git checkout [<tree-ish>] path..." learned to report the number of
+   paths that have been checked out of the index or the tree-ish,
+   which gives it the same degree of noisy-ness as the case in which
+   the command checks out a branch.
+
+
+Performance, Internal Implementation, Development Support etc.
+
+ * Code clean-up with optimization for the codepath that checks
+   (non-)existence of loose objects.
+
+ * More codepaths become aware of working with in-core repository
+   instance other than the default "the_repository".
+
+
+Fixes since v2.20
+-----------------
+
+ * Updates for corner cases in merge-recursive.
+   (merge cc4cb0902c en/merge-path-collision later to maint).
+
+ * "git checkout frotz" (without any double-dash) avoids ambiguity by
+   making sure 'frotz' cannot be interpreted as a revision and as a
+   path at the same time.  This safety has been updated to check also
+   a unique remote-tracking branch 'frotz' in a remote, when dwimming
+   to create a local branch 'frotz' out of a remote-tracking branch
+   'frotz' from a remote.
+   (merge be4908f103 nd/checkout-dwim-fix later to maint).
+
+ * Refspecs configured with "git -c var=val clone" did not propagate
+   to the resulting repository, which has been corrected.
+   (merge 7eae4a3ac4 sg/clone-initial-fetch-configuration later to maint).
+
+ * A properly configured username/email is required under
+   user.useConfigOnly in order to create commits; now "git stash"
+   (even though it creates commit objects to represent stash entries)
+   command is exempt from the requirement.
+   (merge 3bc2111fc2 sd/stash-wo-user-name later to maint).
+
+ * The http-backend CGI process did not correctly clean up the child
+   processes it spawns to run upload-pack etc. when it dies itself,
+   which has been corrected.
+   (merge 02818a98d7 mk/http-backend-kill-children-before-exit later to maint).
+
+ * "git rev-list --exclude-promisor-objects" had to take an object
+   that does not exist locally (and is lazily available) from the
+   command line without barfing, but the code dereferenced NULL.
+   (merge 4cf67869b2 md/list-lazy-objects-fix later to maint).
+
+ * The traversal over tree objects has learned to honor
+   ":(attr:label)" pathspec match, which has been implemented only for
+   enumerating paths on the filesystem.
+   (merge 5a0b97b34c nd/attr-pathspec-in-tree-walk later to maint).
+
+ * BSD port updates.
+   (merge 4e3ecbd439 cb/openbsd-allows-reading-directory later to maint).
+   (merge b6bdc2a0f5 cb/t5004-empty-tar-archive-fix later to maint).
+   (merge 82cbc8cde2 cb/test-lint-cp-a later to maint).
+
+ * Lines that begin with a certain keyword that come over the wire, as
+   well as lines that consist only of one of these keywords, ought to
+   be painted in color for easier eyeballing, but the latter was
+   broken ever since the feature was introduced in 2.19, which has
+   been corrected.
+   (merge 1f67290450 hn/highlight-sideband-keywords later to maint).
+
+ * "git log -G<regex>" looked for a hunk in the "git log -p" patch
+   output that contained a string that matches the given pattern.
+   Optimize this code to ignore binary files, which by default will
+   not show any hunk that would match any pattern (unless textconv or
+   the --text option is in effect, that is).
+   (merge e0e7cb8080 tb/log-G-binary later to maint).
+
+ * Code cleanup, docfix, build fix, etc.
+   (merge 89ba9a79ae hb/t0061-dot-in-path-fix later to maint).
+   (merge d173e799ea sb/diff-color-moved-config-option-fixup later to maint).
+   (merge a8f5a59067 en/directory-renames-nothanks-doc-update later to maint).
+   (merge ec36c42a63 nd/indentation-fix later to maint).
+   (merge f116ee21cd do/gitweb-strict-export-conf-doc later to maint).
+   (merge 112ea42663 fd/gitweb-snapshot-conf-doc-fix later to maint).
+   (merge 1cadad6f65 tb/use-common-win32-pathfuncs-on-cygwin later to maint).
+   (merge 57e9dcaa65 km/rebase-doc-typofix later to maint).
index 57fcd4c8622fc6e996308a1412a27100419a16be..88620429eacf857c7ba7941314c9b443b35b58ce 100644 (file)
@@ -30,6 +30,13 @@ advice.*::
                tries to overwrite a remote ref that points at an
                object that is not a commit-ish, or make the remote
                ref point at an object that is not a commit-ish.
+       pushUnqualifiedRefname::
+               Shown when linkgit:git-push[1] gives up trying to
+               guess based on the source and destination refs what
+               remote ref namespace the source belongs in, but where
+               we can still suggest that the user push to either
+               refs/heads/* or refs/tags/* based on the type of the
+               source object.
        statusHints::
                Show directions on how to proceed from the current
                state in the output of linkgit:git-status[1], in
index a56d848bc0ff87e4fed52081bd7d92952c319c68..5a32f5b0a5a9c312bb414d0405cab0f97e826a01 100644 (file)
@@ -68,6 +68,15 @@ http.saveCookies::
        If set, store cookies received during requests to the file specified by
        http.cookieFile. Has no effect if http.cookieFile is unset.
 
+http.version::
+       Use the specified HTTP protocol version when communicating with a server.
+       If you want to force the default. The available and default version depend
+       on libcurl. Actually the possible values of
+       this option are:
+
+       - HTTP/2
+       - HTTP/1.1
+
 http.sslVersion::
        The SSL version to use when negotiating an SSL connection, if you
        want to force the default.  The available and default version
index b853798fc2b159b13923be63f4068064f04579ce..048e349482df6c892055720eb53cdcd6c327b6ed 100644 (file)
@@ -1,6 +1,6 @@
 worktree.guessRemote::
-       With `add`, if no branch argument, and neither of `-b` nor
-       `-B` nor `--detach` are given, the command defaults to
+       If no branch is specified and neither `-b` nor `-B` nor
+       `--detach` is used, then `git worktree add` defaults to
        creating a new branch from HEAD.  If `worktree.guessRemote` is
        set to true, `worktree add` tries to find a remote-tracking
        branch whose name uniquely matches the new branch name.  If
index 0378cd574eb01069baba14221d511f580565c0eb..b94d332f71b0ff58fb12527f8ba13788b8aa6eeb 100644 (file)
@@ -524,6 +524,8 @@ struct), and want to know the history of that block since it first
 came into being: use the feature iteratively to feed the interesting
 block in the preimage back into `-S`, and keep going until you get the
 very first version of the block.
++
+Binary files are searched as well.
 
 -G<regex>::
        Look for differences whose patch text contains added/removed
@@ -543,6 +545,9 @@ While `git log -G"regexec\(regexp"` will show this commit, `git log
 -S"regexec\(regexp" --pickaxe-regex` will not (because the number of
 occurrences of that string did not change).
 +
+Unless `--text` is supplied patches of binary files without a textconv
+filter will be ignored.
++
 See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more
 information.
 
index 801de2f7645bf0b1fc506da58d469519abca8863..6acc3d98e7422be7f313b0a203a61565fae212c5 100644 (file)
@@ -276,6 +276,10 @@ section of linkgit:git-add[1] to learn how to operate the `--patch` mode.
        Just like linkgit:git-submodule[1], this will detach the
        submodules HEAD.
 
+--no-guess::
+       Do not attempt to create a branch if a remote tracking branch
+       of the same name exists.
+
 <branch>::
        Branch to checkout; if it refers to a branch (i.e., a name that,
        when prepended with "refs/heads/", is a valid ref), then that
index a55536f0bfb2dfa3774e1b952ac4dee1eea6e505..2fd12524f95afef9c688d3402cd2a8b6d2d98c2e 100644 (file)
@@ -189,6 +189,12 @@ objects from the source repository into a pack in the cloned repository.
        values are given for the same key, each value will be written to
        the config file. This makes it safe, for example, to add
        additional fetch refspecs to the origin remote.
++
+Due to limitations of the current implementation, some configuration
+variables do not take effect until after the initial fetch and checkout.
+Configuration variables known to not take effect are:
+`remote.<name>.mirror` and `remote.<name>.tagOpt`.  Use the
+corresponding `--mirror` and `--no-tags` options instead.
 
 --depth <depth>::
        Create a 'shallow' clone with a history truncated to the
index 763afabb6dc7487009ab49f5bb258f9181f0da78..f58e9c43e60cec3b56fb84f54859f3d01d1a963a 100644 (file)
@@ -47,7 +47,7 @@ OPTIONS
        The number of spaces between columns. One space by default.
 
 EXAMPLES
-------
+--------
 
 Format data by columns:
 ------------
index ce954be5321384b55687791acb32562850a5a6fa..64c01ba91884df1ec8e49ddc8fe852f1fb2a9425 100644 (file)
@@ -110,6 +110,25 @@ marks the same across runs.
        the shape of the history and stored tree.  See the section on
        `ANONYMIZING` below.
 
+--reference-excluded-parents::
+       By default, running a command such as `git fast-export
+       master~5..master` will not include the commit master{tilde}5
+       and will make master{tilde}4 no longer have master{tilde}5 as
+       a parent (though both the old master{tilde}4 and new
+       master{tilde}4 will have all the same files).  Use
+       --reference-excluded-parents to instead have the the stream
+       refer to commits in the excluded range of history by their
+       sha1sum.  Note that the resulting stream can only be used by a
+       repository which already contains the necessary parent
+       commits.
+
+--show-original-ids::
+       Add an extra directive to the output for commits and blobs,
+       `original-oid <SHA1SUM>`.  While such directives will likely be
+       ignored by importers such as git-fast-import, it may be useful
+       for intermediary filters (e.g. for rewriting commit messages
+       which refer to older commits, or for stripping blobs by id).
+
 --refspec::
        Apply the specified refspec to each ref exported. Multiple of them can
        be specified.
@@ -119,7 +138,9 @@ marks the same across runs.
        'git rev-list', that specifies the specific objects and references
        to export.  For example, `master~10..master` causes the
        current master reference to be exported along with all objects
-       added since its 10th ancestor commit.
+       added since its 10th ancestor commit and (unless the
+       --reference-excluded-parents option is specified) all files
+       common to master{tilde}9 and master{tilde}10.
 
 EXAMPLES
 --------
index e81117d27f477591b92480352731fb0c4faf3410..43ab3b1637b50462ff62aa9c33c87184ef8ebc47 100644 (file)
@@ -40,9 +40,10 @@ OPTIONS
        not contain the old commit).
 
 --quiet::
-       Disable all non-fatal output, making fast-import silent when it
-       is successful.  This option disables the output shown by
-       --stats.
+       Disable the output shown by --stats, making fast-import usually
+       be silent when it is successful.  However, if the import stream
+       has directives intended to show user output (e.g. `progress`
+       directives), the corresponding messages will still be shown.
 
 --stats::
        Display some basic statistics about the objects fast-import has
@@ -384,6 +385,7 @@ change to the project.
 ....
        'commit' SP <ref> LF
        mark?
+       original-oid?
        ('author' (SP <name>)? SP LT <email> GT SP <when> LF)?
        'committer' (SP <name>)? SP LT <email> GT SP <when> LF
        data
@@ -740,6 +742,19 @@ New marks are created automatically.  Existing marks can be moved
 to another object simply by reusing the same `<idnum>` in another
 `mark` command.
 
+`original-oid`
+~~~~~~~~~~~~~~
+Provides the name of the object in the original source control system.
+fast-import will simply ignore this directive, but filter processes
+which operate on and modify the stream before feeding to fast-import
+may have uses for this information
+
+....
+       'original-oid' SP <object-identifier> LF
+....
+
+where `<object-identifer>` is any string not containing LF.
+
 `tag`
 ~~~~~
 Creates an annotated tag referring to a specific commit.  To create
@@ -748,6 +763,7 @@ lightweight (non-annotated) tags see the `reset` command below.
 ....
        'tag' SP <name> LF
        'from' SP <commit-ish> LF
+       original-oid?
        'tagger' (SP <name>)? SP LT <email> GT SP <when> LF
        data
 ....
@@ -822,6 +838,7 @@ assigned mark.
 ....
        'blob' LF
        mark?
+       original-oid?
        data
 ....
 
index c20ee6c7892518de4ba915e473e7ed736f68fe6b..a7442499f6d3985fa2ca57fa827d454b11479705 100644 (file)
@@ -137,7 +137,7 @@ 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
+The optional configuration variable `gc.writeCommitGraph` determines if
 'git gc' should run 'git commit-graph write'. This can be set to a
 boolean value. This defaults to false.
 
index 3c5a67fb9671f8c65e0830222c63bb5035a05c30..057076ca38eecfc6d25caeb90110efc4c30e83a1 100644 (file)
@@ -38,8 +38,6 @@ the repository to another place if --separate-git-dir is given).
 OPTIONS
 -------
 
---
-
 -q::
 --quiet::
 
@@ -111,8 +109,6 @@ into it.
 If you provide a 'directory', the command is run inside it. If this directory
 does not exist, it will be created.
 
---
-
 TEMPLATE DIRECTORY
 ------------------
 
index a5fc54aeabccbeac32c73a610dbee45bfb5b0746..6a8a0d958bc63db19bfa4786e85e9e14061f1661 100644 (file)
@@ -73,6 +73,26 @@ be omitted--such a push will update a ref that `<src>` normally updates
 without any `<refspec>` on the command line.  Otherwise, missing
 `:<dst>` means to update the same ref as the `<src>`.
 +
+If <dst> doesn't start with `refs/` (e.g. `refs/heads/master`) we will
+try to infer where in `refs/*` on the destination <repository> it
+belongs based on the the type of <src> being pushed and whether <dst>
+is ambiguous.
++
+--
+* If <dst> unambiguously refers to a ref on the <repository> remote,
+  then push to that ref.
+
+* If <src> resolves to a ref starting with refs/heads/ or refs/tags/,
+  then prepend that to <dst>.
+
+* Other ambiguity resolutions might be added in the future, but for
+  now any other cases will error out with an error indicating what we
+  tried, and depending on the `advice.pushUnqualifiedRefname`
+  configuration (see linkgit:git-config[1]) suggest what refs/
+  namespace you may have wanted to push to.
+
+--
++
 The object referenced by <src> is used to update the <dst> reference
 on the remote side. Whether this is allowed depends on where in
 `refs/*` the <dst> reference lives as described in detail below, in
@@ -591,6 +611,9 @@ the ones in the examples below) can be configured as the default for
        `refs/remotes/satellite/master`) in the `mothership` repository;
        do the same for `dev` and `satellite/dev`.
 +
+See the section describing `<refspec>...` above for a discussion of
+the matching semantics.
++
 This is to emulate `git fetch` run on the `mothership` using `git
 push` that is run in the opposite direction in order to integrate
 the work done on `satellite`, and is often necessary when you can
index 8cf952b4de669ea3e7275c5d10087005548574eb..70562dc4c0235d53501bab56ff98af6169b8f968 100644 (file)
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git quiltimport' [--dry-run | -n] [--author <author>] [--patches <dir>]
-               [--series <file>]
+               [--series <file>] [--keep-non-patch]
 
 
 DESCRIPTION
@@ -56,6 +56,9 @@ The default for the series file is <patches>/series
 or the value of the `$QUILT_SERIES` environment
 variable.
 
+--keep-non-patch::
+       Pass `-b` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]).
+
 GIT
 ---
 Part of the linkgit:git[1] suite
index dff17b31788fec085b91314b3b3328c689050628..d284155cf33dfb9460d4af487eef680585959017 100644 (file)
@@ -570,8 +570,9 @@ it to keep commits that started empty.
 Directory rename detection
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-The merge and interactive backends work fine with
-directory rename detection.  The am backend sometimes does not.
+Directory rename heuristics are enabled in the merge and interactive
+backends.  Due to the lack of accurate tree information, directory
+rename detection is disabled in the am backend.
 
 include::merge-strategies.txt[]
 
@@ -979,7 +980,7 @@ 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 for regular merges, and `octopus` for octopus merges,
-strategy, with no way to choose a different one. To work around
+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 d9f422d5600af6b112eba692d5c5607cdb4169ef..861d821d7f26ec88818008f4c6825bfcad2590ce 100644 (file)
@@ -197,31 +197,33 @@ codes can be interpreted as follows:
 Ignored files are not listed, unless `--ignored` option is in effect,
 in which case `XY` are `!!`.
 
-    X          Y     Meaning
-    -------------------------------------------------
-            [AMD]   not updated
-    M        [ MD]   updated in index
-    A        [ MD]   added to index
-    D                deleted from index
-    R        [ MD]   renamed in index
-    C        [ MD]   copied in index
-    [MARC]           index and work tree matches
-    [ MARC]     M    work tree changed since index
-    [ MARC]     D    deleted in work tree
-    [ D]        R    renamed in work tree
-    [ D]        C    copied in work tree
-    -------------------------------------------------
-    D           D    unmerged, both deleted
-    A           U    unmerged, added by us
-    U           D    unmerged, deleted by them
-    U           A    unmerged, added by them
-    D           U    unmerged, deleted by us
-    A           A    unmerged, both added
-    U           U    unmerged, both modified
-    -------------------------------------------------
-    ?           ?    untracked
-    !           !    ignored
-    -------------------------------------------------
+....
+X          Y     Meaning
+-------------------------------------------------
+        [AMD]   not updated
+M        [ MD]   updated in index
+A        [ MD]   added to index
+D                deleted from index
+R        [ MD]   renamed in index
+C        [ MD]   copied in index
+[MARC]           index and work tree matches
+[ MARC]     M    work tree changed since index
+[ MARC]     D    deleted in work tree
+[ D]        R    renamed in work tree
+[ D]        C    copied in work tree
+-------------------------------------------------
+D           D    unmerged, both deleted
+A           U    unmerged, added by us
+U           D    unmerged, deleted by them
+U           A    unmerged, added by them
+D           U    unmerged, deleted by us
+A           A    unmerged, both added
+U           U    unmerged, both modified
+-------------------------------------------------
+?           ?    untracked
+!           !    ignored
+-------------------------------------------------
+....
 
 Submodules have more state and instead report
                M    the submodule has a different HEAD than
@@ -281,14 +283,16 @@ don't recognize.
 If `--branch` is given, a series of header lines are printed with
 information about the current branch.
 
-    Line                                     Notes
-    ------------------------------------------------------------
-    # branch.oid <commit> | (initial)        Current commit.
-    # branch.head <branch> | (detached)      Current branch.
-    # branch.upstream <upstream_branch>      If upstream is set.
-    # branch.ab +<ahead> -<behind>           If upstream is set and
-                                            the commit is present.
-    ------------------------------------------------------------
+....
+Line                                     Notes
+------------------------------------------------------------
+# branch.oid <commit> | (initial)        Current commit.
+# branch.head <branch> | (detached)      Current branch.
+# branch.upstream <upstream_branch>      If upstream is set.
+# branch.ab +<ahead> -<behind>           If upstream is set and
+                                        the commit is present.
+------------------------------------------------------------
+....
 
 ### Changed Tracked Entries
 
@@ -306,56 +310,60 @@ Renamed or copied entries have the following format:
 
     2 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <X><score> <path><sep><origPath>
 
-    Field       Meaning
-    --------------------------------------------------------
-    <XY>        A 2 character field containing the staged and
-               unstaged XY values described in the short format,
-               with unchanged indicated by a "." rather than
-               a space.
-    <sub>       A 4 character field describing the submodule state.
-               "N..." when the entry is not a submodule.
-               "S<c><m><u>" when the entry is a submodule.
-               <c> is "C" if the commit changed; otherwise ".".
-               <m> is "M" if it has tracked changes; otherwise ".".
-               <u> is "U" if there are untracked changes; otherwise ".".
-    <mH>        The octal file mode in HEAD.
-    <mI>        The octal file mode in the index.
-    <mW>        The octal file mode in the worktree.
-    <hH>        The object name in HEAD.
-    <hI>        The object name in the index.
-    <X><score>  The rename or copy score (denoting the percentage
-               of similarity between the source and target of the
-               move or copy). For example "R100" or "C75".
-    <path>      The pathname.  In a renamed/copied entry, this
-               is the target path.
-    <sep>       When the `-z` option is used, the 2 pathnames are separated
-               with a NUL (ASCII 0x00) byte; otherwise, a tab (ASCII 0x09)
-               byte separates them.
-    <origPath>  The pathname in the commit at HEAD or in the index.
-               This is only present in a renamed/copied entry, and
-               tells where the renamed/copied contents came from.
-    --------------------------------------------------------
+....
+Field       Meaning
+--------------------------------------------------------
+<XY>        A 2 character field containing the staged and
+           unstaged XY values described in the short format,
+           with unchanged indicated by a "." rather than
+           a space.
+<sub>       A 4 character field describing the submodule state.
+           "N..." when the entry is not a submodule.
+           "S<c><m><u>" when the entry is a submodule.
+           <c> is "C" if the commit changed; otherwise ".".
+           <m> is "M" if it has tracked changes; otherwise ".".
+           <u> is "U" if there are untracked changes; otherwise ".".
+<mH>        The octal file mode in HEAD.
+<mI>        The octal file mode in the index.
+<mW>        The octal file mode in the worktree.
+<hH>        The object name in HEAD.
+<hI>        The object name in the index.
+<X><score>  The rename or copy score (denoting the percentage
+           of similarity between the source and target of the
+           move or copy). For example "R100" or "C75".
+<path>      The pathname.  In a renamed/copied entry, this
+           is the target path.
+<sep>       When the `-z` option is used, the 2 pathnames are separated
+           with a NUL (ASCII 0x00) byte; otherwise, a tab (ASCII 0x09)
+           byte separates them.
+<origPath>  The pathname in the commit at HEAD or in the index.
+           This is only present in a renamed/copied entry, and
+           tells where the renamed/copied contents came from.
+--------------------------------------------------------
+....
 
 Unmerged entries have the following format; the first character is
 a "u" to distinguish from ordinary changed entries.
 
     u <xy> <sub> <m1> <m2> <m3> <mW> <h1> <h2> <h3> <path>
 
-    Field       Meaning
-    --------------------------------------------------------
-    <XY>        A 2 character field describing the conflict type
-               as described in the short format.
-    <sub>       A 4 character field describing the submodule state
-               as described above.
-    <m1>        The octal file mode in stage 1.
-    <m2>        The octal file mode in stage 2.
-    <m3>        The octal file mode in stage 3.
-    <mW>        The octal file mode in the worktree.
-    <h1>        The object name in stage 1.
-    <h2>        The object name in stage 2.
-    <h3>        The object name in stage 3.
-    <path>      The pathname.
-    --------------------------------------------------------
+....
+Field       Meaning
+--------------------------------------------------------
+<XY>        A 2 character field describing the conflict type
+           as described in the short format.
+<sub>       A 4 character field describing the submodule state
+           as described above.
+<m1>        The octal file mode in stage 1.
+<m2>        The octal file mode in stage 2.
+<m3>        The octal file mode in stage 3.
+<mW>        The octal file mode in the worktree.
+<h1>        The object name in stage 1.
+<h2>        The object name in stage 2.
+<h3>        The object name in stage 3.
+<path>      The pathname.
+--------------------------------------------------------
+....
 
 ### Other Items
 
index c0a60f315811c788f3431b5757c38ffcea487386..c970d9fe438a091dc19900a4de1973ac4bcc4434 100644 (file)
@@ -242,7 +242,8 @@ textual diff has an added or a deleted line that matches the given
 regular expression.  This means that it will detect in-file (or what
 rename-detection considers the same file) moves, which is noise.  The
 implementation runs diff twice and greps, and this can be quite
-expensive.
+expensive.  To speed things up binary files without textconv filters
+will be ignored.
 
 When `-S` or `-G` are used without `--pickaxe-all`, only filepairs
 that match their respective criterion are kept in the output.  When
index c0a326e3883c321f6a5b0c545d9aee9cdd1a5d8a..92535dbac53ac49d89ef6d8ce62dd2920c83c445 100644 (file)
@@ -207,8 +207,8 @@ subsection on linkgit:gitweb[1] manpage.
 
 $strict_export::
        Only allow viewing of repositories also shown on the overview page.
-       This for example makes `$gitweb_export_ok` file decide if repository is
-       available and not only if it is shown.  If `$gitweb_list` points to
+       This for example makes `$export_ok` file decide if repository is
+       available and not only if it is shown.  If `$projects_list` points to
        file with list of project, only those repositories listed would be
        available for gitweb.  Can be set during building gitweb via
        `GITWEB_STRICT_EXPORT`.  By default this variable is not set, which
@@ -684,7 +684,7 @@ compressed tar archive) and "zip"; please consult gitweb sources for
 a definitive list.  By default only "tgz" is offered.
 +
 This feature can be configured on a per-repository basis via
-repository's `gitweb.blame` configuration variable, which contains
+repository's `gitweb.snapshot` configuration variable, which contains
 a comma separated list of formats or "none" to disable snapshots.
 Unknown values are ignored.
 
index 0d2aa48c63856aba78d559445186a9b9e6bddd7d..023ca95e7c39d88fcac832d73a7454e9fb71e5a1 100644 (file)
@@ -404,6 +404,8 @@ these forms:
 - "`!ATTR`" requires that the attribute `ATTR` be
   unspecified.
 +
+Note that when matching against a tree object, attributes are still
+obtained from working tree, not from the given tree object.
 
 exclude;;
        After a path matches any non-exclude pathspec, it will be run
index bab5f50b1724913c7607180897b7f92d1517dda9..98b538bc779635fcf59afd1a8cb366e9e57ed7ae 100644 (file)
@@ -13,8 +13,6 @@ has a line that matches `<pattern>`), unless otherwise noted.
 Note that these are applied before commit
 ordering and formatting options, such as `--reverse`.
 
---
-
 -<number>::
 -n <number>::
 --max-count=<number>::
@@ -308,8 +306,6 @@ ifdef::git-rev-list[]
        `<header>` text will be printed with each progress update.
 endif::git-rev-list[]
 
---
-
 History Simplification
 ~~~~~~~~~~~~~~~~~~~~~~
 
index 216beefc50d54d132991636d5f049ea0916f1696..0a3ccac70ad0c14e805b33f372e6162dd84db7ec 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v2.20.0
+DEF_VER=v2.20.GIT
 
 LF='
 '
index 8d0b1654d25536f72abe885634c36412ae8b3246..31e21359a89066faf934359889ac76924dd86893 120000 (symlink)
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/2.20.0.txt
\ No newline at end of file
+Documentation/RelNotes/2.21.0.txt
\ No newline at end of file
index 5f35656409b1d51abf111efa5bbcc7f5d570aaf0..567209aa79afee0443dd0d7049343e1a004ae784 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -9,6 +9,7 @@ int advice_push_non_ff_matching = 1;
 int advice_push_already_exists = 1;
 int advice_push_fetch_first = 1;
 int advice_push_needs_force = 1;
+int advice_push_unqualified_ref_name = 1;
 int advice_status_hints = 1;
 int advice_status_u_option = 1;
 int advice_commit_before_merge = 1;
@@ -63,6 +64,7 @@ static struct {
        { "pushAlreadyExists", &advice_push_already_exists },
        { "pushFetchFirst", &advice_push_fetch_first },
        { "pushNeedsForce", &advice_push_needs_force },
+       { "pushUnqualifiedRefName", &advice_push_unqualified_ref_name },
        { "statusHints", &advice_status_hints },
        { "statusUoption", &advice_status_u_option },
        { "commitBeforeMerge", &advice_commit_before_merge },
index 696bf0e7d29ee107c5faf10a59985c0f49612495..f875f8cd8da5fdb6e570770ecc7ab4461745f827 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -9,6 +9,7 @@ extern int advice_push_non_ff_matching;
 extern int advice_push_already_exists;
 extern int advice_push_fetch_first;
 extern int advice_push_needs_force;
+extern int advice_push_unqualified_ref_name;
 extern int advice_status_hints;
 extern int advice_status_u_option;
 extern int advice_commit_before_merge;
diff --git a/alias.c b/alias.c
index a7e4e57130d46188a4a0ee93871375218041344c..c4715380205b5f8dd032b16ade846842fa3c23b9 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -47,8 +47,8 @@ void list_aliases(struct string_list *list)
 #define SPLIT_CMDLINE_BAD_ENDING 1
 #define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
 static const char *split_cmdline_errors[] = {
-       "cmdline ends with \\",
-       "unclosed quote"
+       N_("cmdline ends with \\"),
+       N_("unclosed quote")
 };
 
 int split_cmdline(char *cmdline, const char ***argv)
diff --git a/apply.c b/apply.c
index 01793d612620246b14fa57f6ce3ed6c33df65d0f..3703bfc8d03deb3be3a3fa9a45a2dd64b0a8eafd 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -3352,7 +3352,8 @@ static int checkout_target(struct index_state *istate,
 
        costate.refresh_cache = 1;
        costate.istate = istate;
-       if (checkout_entry(ce, &costate, NULL) || lstat(ce->name, st))
+       if (checkout_entry(ce, &costate, NULL, NULL) ||
+           lstat(ce->name, st))
                return error(_("cannot checkout %s"), ce->name);
        return 0;
 }
index a58e1a8ebf874afc856b03f2203ee32d79183b31..4aabd566fbb8af7065ebe8fa62afe8e8e70abe04 100644 (file)
@@ -142,7 +142,7 @@ static int stream_blocked(const struct object_id *oid)
  * string and appends it to a struct strbuf.
  */
 static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
-                                     const char *value, unsigned int valuelen)
+                                    const char *value, unsigned int valuelen)
 {
        int len, tmp;
 
index fd556c28e420732bbe625b68663f9099a5316f96..1f98324a930e39aa1a7c41e78b4fcd6450899c66 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -36,8 +36,8 @@ void init_archivers(void)
 }
 
 static void format_subst(const struct commit *commit,
-                         const char *src, size_t len,
-                         struct strbuf *buf)
+                        const char *src, size_t len,
+                        struct strbuf *buf)
 {
        char *to_free = NULL;
        struct strbuf fmt = STRBUF_INIT;
@@ -285,7 +285,8 @@ int write_archive_entries(struct archiver_args *args,
                git_attr_set_direction(GIT_ATTR_INDEX);
        }
 
-       err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
+       err = read_tree_recursive(args->repo, args->tree, "",
+                                 0, 0, &args->pathspec,
                                  queue_or_write_archive_entry,
                                  &context);
        if (err == READ_TREE_RECURSIVE)
@@ -346,7 +347,8 @@ static int path_exists(struct archiver_args *args, const char *path)
        ctx.args = args;
        parse_pathspec(&ctx.pathspec, 0, 0, "", paths);
        ctx.pathspec.recursive = 1;
-       ret = read_tree_recursive(args->tree, "", 0, 0, &ctx.pathspec,
+       ret = read_tree_recursive(args->repo, args->tree, "",
+                                 0, 0, &ctx.pathspec,
                                  reject_entry, &ctx);
        clear_pathspec(&ctx.pathspec);
        return ret != 0;
@@ -391,12 +393,12 @@ static void parse_treeish_arg(const char **argv,
                int refnamelen = colon - name;
 
                if (!dwim_ref(name, refnamelen, &oid, &ref))
-                       die("no such ref: %.*s", refnamelen, name);
+                       die(_("no such ref: %.*s"), refnamelen, name);
                free(ref);
        }
 
        if (get_oid(name, &oid))
-               die("Not a valid object name");
+               die(_("not a valid object name: %s"), name);
 
        commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1);
        if (commit) {
@@ -409,7 +411,7 @@ static void parse_treeish_arg(const char **argv,
 
        tree = parse_tree_indirect(&oid);
        if (tree == NULL)
-               die("not a tree object");
+               die(_("not a tree object: %s"), oid_to_hex(&oid));
 
        if (prefix) {
                struct object_id tree_oid;
@@ -419,7 +421,7 @@ static void parse_treeish_arg(const char **argv,
                err = get_tree_entry(&tree->object.oid, prefix, &tree_oid,
                                     &mode);
                if (err || !S_ISDIR(mode))
-                       die("current working directory is untracked");
+                       die(_("current working directory is untracked"));
 
                tree = parse_tree_indirect(&tree_oid);
        }
diff --git a/attr.c b/attr.c
index eaece6658d64b2129332ffab39e30485730f3306..b63fe0fc0e99caa07dc2e6da816e1ac8d5942df6 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -366,8 +366,8 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
        if (strlen(ATTRIBUTE_MACRO_PREFIX) < namelen &&
            starts_with(name, ATTRIBUTE_MACRO_PREFIX)) {
                if (!macro_ok) {
-                       fprintf(stderr, "%s not allowed: %s:%d\n",
-                               name, src, lineno);
+                       fprintf_ln(stderr, _("%s not allowed: %s:%d"),
+                                  name, src, lineno);
                        goto fail_return;
                }
                is_macro = 1;
index 28f5937035b762ad9fb091ea8fb7cc96f38fc92d..447af24807f49f5df4eace6435acba721745fc2c 100644 (file)
--- a/banned.h
+++ b/banned.h
@@ -16,6 +16,8 @@
 #define strcat(x,y) BANNED(strcat)
 #undef strncpy
 #define strncpy(x,y,n) BANNED(strncpy)
+#undef strncat
+#define strncat(x,y,n) BANNED(strncat)
 
 #undef sprintf
 #undef vsprintf
index 487675c67249a3164294aae71c1c2a650f3c4947..6bf521138a590496a7b3fa7c2515ac53f815a1e3 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -558,7 +558,8 @@ struct commit_list *filter_skipped(struct commit_list *list,
  * is increased by one between each call, but that should not matter
  * for this application.
  */
-static unsigned get_prn(unsigned count) {
+static unsigned get_prn(unsigned count)
+{
        count = count * 1103515245 + 12345;
        return (count/65536) % PRN_MODULO;
 }
@@ -626,14 +627,15 @@ static struct commit_list *managed_skipped(struct commit_list *list,
        return skip_away(list, count);
 }
 
-static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
+static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
+                            const char *prefix,
                             const char *bad_format, const char *good_format,
                             int read_paths)
 {
        struct argv_array rev_argv = ARGV_ARRAY_INIT;
        int i;
 
-       repo_init_revisions(the_repository, revs, prefix);
+       repo_init_revisions(r, revs, prefix);
        revs->abbrev = 0;
        revs->commit_format = CMIT_FMT_UNSPECIFIED;
 
@@ -723,23 +725,25 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
        return run_command_v_opt(argv_show_branch, RUN_GIT_CMD);
 }
 
-static struct commit *get_commit_reference(const struct object_id *oid)
+static struct commit *get_commit_reference(struct repository *r,
+                                          const struct object_id *oid)
 {
-       struct commit *r = lookup_commit_reference(the_repository, oid);
-       if (!r)
+       struct commit *c = lookup_commit_reference(r, oid);
+       if (!c)
                die(_("Not a valid commit name %s"), oid_to_hex(oid));
-       return r;
+       return c;
 }
 
-static struct commit **get_bad_and_good_commits(int *rev_nr)
+static struct commit **get_bad_and_good_commits(struct repository *r,
+                                               int *rev_nr)
 {
        struct commit **rev;
        int i, n = 0;
 
        ALLOC_ARRAY(rev, 1 + good_revs.nr);
-       rev[n++] = get_commit_reference(current_bad_oid);
+       rev[n++] = get_commit_reference(r, current_bad_oid);
        for (i = 0; i < good_revs.nr; i++)
-               rev[n++] = get_commit_reference(good_revs.oid + i);
+               rev[n++] = get_commit_reference(r, good_revs.oid + i);
        *rev_nr = n;
 
        return rev;
@@ -823,12 +827,13 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
        free_commit_list(result);
 }
 
-static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)
+static int check_ancestors(struct repository *r, int rev_nr,
+                          struct commit **rev, const char *prefix)
 {
        struct rev_info revs;
        int res;
 
-       bisect_rev_setup(&revs, prefix, "^%s", "%s", 0);
+       bisect_rev_setup(r, &revs, prefix, "^%s", "%s", 0);
 
        bisect_common(&revs);
        res = (revs.commits != NULL);
@@ -847,7 +852,9 @@ static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)
  * If a merge base must be tested by the user, its source code will be
  * checked out to be tested by the user and we will exit.
  */
-static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
+static void check_good_are_ancestors_of_bad(struct repository *r,
+                                           const char *prefix,
+                                           int no_checkout)
 {
        char *filename = git_pathdup("BISECT_ANCESTORS_OK");
        struct stat st;
@@ -866,8 +873,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
                goto done;
 
        /* Check if all good revs are ancestor of the bad rev. */
-       rev = get_bad_and_good_commits(&rev_nr);
-       if (check_ancestors(rev_nr, rev, prefix))
+       rev = get_bad_and_good_commits(r, &rev_nr);
+       if (check_ancestors(r, rev_nr, rev, prefix))
                check_merge_bases(rev_nr, rev, no_checkout);
        free(rev);
 
@@ -885,12 +892,14 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
 /*
  * This does "git diff-tree --pretty COMMIT" without one fork+exec.
  */
-static void show_diff_tree(const char *prefix, struct commit *commit)
+static void show_diff_tree(struct repository *r,
+                          const char *prefix,
+                          struct commit *commit)
 {
        struct rev_info opt;
 
        /* diff-tree init */
-       repo_init_revisions(the_repository, &opt, prefix);
+       repo_init_revisions(r, &opt, prefix);
        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
        opt.abbrev = 0;
        opt.diff = 1;
@@ -945,7 +954,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
  * If no_checkout is non-zero, the bisection process does not
  * checkout the trial commit but instead simply updates BISECT_HEAD.
  */
-int bisect_next_all(const char *prefix, int no_checkout)
+int bisect_next_all(struct repository *r, const char *prefix, int no_checkout)
 {
        struct rev_info revs;
        struct commit_list *tried;
@@ -957,9 +966,9 @@ int bisect_next_all(const char *prefix, int no_checkout)
        if (read_bisect_refs())
                die(_("reading bisect refs failed"));
 
-       check_good_are_ancestors_of_bad(prefix, no_checkout);
+       check_good_are_ancestors_of_bad(r, prefix, no_checkout);
 
-       bisect_rev_setup(&revs, prefix, "%s", "^%s", 1);
+       bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
        revs.limited = 1;
 
        bisect_common(&revs);
@@ -993,7 +1002,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
                exit_if_skipped_commits(tried, current_bad_oid);
                printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
                        term_bad);
-               show_diff_tree(prefix, revs.commits->item);
+               show_diff_tree(r, prefix, revs.commits->item);
                /* This means the bisection process succeeded. */
                exit(10);
        }
index 34df20935123065b4b253288ea0e22b1721af0e9..821d16e4ddad71d177190a0e05012c5a509fa17b 100644 (file)
--- a/bisect.h
+++ b/bisect.h
@@ -2,6 +2,7 @@
 #define BISECT_H
 
 struct commit_list;
+struct repository;
 
 /*
  * Find bisection. If something is found, `reaches` will be the number of
@@ -30,7 +31,9 @@ struct rev_list_info {
        const char *header_prefix;
 };
 
-extern int bisect_next_all(const char *prefix, int no_checkout);
+extern int bisect_next_all(struct repository *r,
+                          const char *prefix,
+                          int no_checkout);
 
 extern int estimate_bisect_steps(int all);
 
diff --git a/blame.c b/blame.c
index d84c937780801f51b8eb98b7e367c8017701ba5c..43861437f749849e85d448eba692b42488ec459d 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -116,35 +116,38 @@ static void verify_working_tree_path(struct repository *r,
                die("no such path '%s' in HEAD", path);
 }
 
-static struct commit_list **append_parent(struct commit_list **tail, const struct object_id *oid)
+static struct commit_list **append_parent(struct repository *r,
+                                         struct commit_list **tail,
+                                         const struct object_id *oid)
 {
        struct commit *parent;
 
-       parent = lookup_commit_reference(the_repository, oid);
+       parent = lookup_commit_reference(r, oid);
        if (!parent)
                die("no such commit %s", oid_to_hex(oid));
        return &commit_list_insert(parent, tail)->next;
 }
 
-static void append_merge_parents(struct commit_list **tail)
+static void append_merge_parents(struct repository *r,
+                                struct commit_list **tail)
 {
        int merge_head;
        struct strbuf line = STRBUF_INIT;
 
-       merge_head = open(git_path_merge_head(the_repository), O_RDONLY);
+       merge_head = open(git_path_merge_head(r), O_RDONLY);
        if (merge_head < 0) {
                if (errno == ENOENT)
                        return;
                die("cannot open '%s' for reading",
-                   git_path_merge_head(the_repository));
+                   git_path_merge_head(r));
        }
 
        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(the_repository), line.buf);
-               tail = append_parent(tail, &oid);
+                           git_path_merge_head(r), line.buf);
+               tail = append_parent(r, tail, &oid);
        }
        close(merge_head);
        strbuf_release(&line);
@@ -155,11 +158,13 @@ static void append_merge_parents(struct commit_list **tail)
  * want to transfer ownership of the buffer to the commit (so we
  * must use detach).
  */
-static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
+static void set_commit_buffer_from_strbuf(struct repository *r,
+                                         struct commit *c,
+                                         struct strbuf *sb)
 {
        size_t len;
        void *buf = strbuf_detach(sb, &len);
-       set_commit_buffer(the_repository, c, buf, len);
+       set_commit_buffer(r, c, buf, len);
 }
 
 /*
@@ -185,7 +190,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
 
        read_index(r->index);
        time(&now);
-       commit = alloc_commit_node(the_repository);
+       commit = alloc_commit_node(r);
        commit->object.parsed = 1;
        commit->date = now;
        parent_tail = &commit->parents;
@@ -193,8 +198,8 @@ static struct commit *fake_working_tree_commit(struct repository *r,
        if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
                die("no such ref: HEAD");
 
-       parent_tail = append_parent(parent_tail, &head_oid);
-       append_merge_parents(parent_tail);
+       parent_tail = append_parent(r, parent_tail, &head_oid);
+       append_merge_parents(r, parent_tail);
        verify_working_tree_path(r, commit, path);
 
        origin = make_origin(commit, path);
@@ -211,7 +216,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
                    ident, ident, path,
                    (!contents_from ? path :
                     (!strcmp(contents_from, "-") ? "standard input" : contents_from)));
-       set_commit_buffer_from_strbuf(commit, &msg);
+       set_commit_buffer_from_strbuf(r, commit, &msg);
 
        if (!contents_from || strcmp("-", contents_from)) {
                struct stat st;
@@ -1678,7 +1683,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(the_repository, obj, NULL, 0);
+               obj = deref_tag(revs->repo, obj, NULL, 0);
                if (obj->type != OBJ_COMMIT)
                        die("Non commit %s?", revs->pending.objects[i].name);
                if (found)
@@ -1709,14 +1714,14 @@ 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(the_repository, obj, NULL, 0);
+       obj = deref_tag(revs->repo, 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(the_repository,
+       head_commit = lookup_commit_reference_gently(revs->repo,
                                                     &head_oid, 1);
        if (!head_commit)
                return NULL;
@@ -1745,7 +1750,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(the_repository, obj, NULL, 0);
+               obj = deref_tag(revs->repo, obj, NULL, 0);
                if (obj->type != OBJ_COMMIT)
                        die("Non commit %s?", revs->pending.objects[i].name);
                if (found)
index 776f55fc66fb7d782f30b05ca9bdff4a55028f49..28b81a7e0256b2923c0fe296d9618d130821cdc4 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -242,7 +242,8 @@ N_("\n"
 "will track its remote counterpart, you may want to use\n"
 "\"git push -u\" to set the upstream config as you push.");
 
-void create_branch(const char *name, const char *start_name,
+void create_branch(struct repository *r,
+                  const char *name, const char *start_name,
                   int force, int clobber_head_ok, int reflog,
                   int quiet, enum branch_track track)
 {
@@ -300,7 +301,7 @@ void create_branch(const char *name, const char *start_name,
                break;
        }
 
-       if ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)
+       if ((commit = lookup_commit_reference(r, &oid)) == NULL)
                die(_("Not a valid branch point: '%s'."), start_name);
        oidcpy(&oid, &commit->object.oid);
 
@@ -336,15 +337,15 @@ void create_branch(const char *name, const char *start_name,
        free(real_ref);
 }
 
-void remove_branch_state(void)
+void remove_branch_state(struct repository *r)
 {
-       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));
+       unlink(git_path_cherry_pick_head(r));
+       unlink(git_path_revert_head(r));
+       unlink(git_path_merge_head(r));
+       unlink(git_path_merge_rr(r));
+       unlink(git_path_merge_msg(r));
+       unlink(git_path_merge_mode(r));
+       unlink(git_path_squash_msg(r));
 }
 
 void die_if_checked_out(const char *branch, int ignore_current_worktree)
index 5cace4581fe43aa5fdc20b4315cee6eff1034003..29c1afa4d0ce5d1639b81d3d652d5b16085218e9 100644 (file)
--- a/branch.h
+++ b/branch.h
@@ -1,6 +1,7 @@
 #ifndef BRANCH_H
 #define BRANCH_H
 
+struct repository;
 struct strbuf;
 
 enum branch_track {
@@ -19,6 +20,8 @@ extern enum branch_track git_branch_track;
 /*
  * Creates a new branch, where:
  *
+ *   - r is the repository to add a branch to
+ *
  *   - name is the new branch name
  *
  *   - start_name is the name of the existing branch that the new branch should
@@ -37,7 +40,8 @@ extern enum branch_track git_branch_track;
  *     that start_name is a tracking branch for (if any).
  *
  */
-void create_branch(const char *name, const char *start_name,
+void create_branch(struct repository *r,
+                  const char *name, const char *start_name,
                   int force, int clobber_head_ok,
                   int reflog, int quiet, enum branch_track track);
 
@@ -60,7 +64,7 @@ extern int validate_new_branchname(const char *name, struct strbuf *ref, int for
  * Remove information about the state of working on the current
  * branch. (E.g., MERGE_HEAD)
  */
-void remove_branch_state(void);
+void remove_branch_state(struct repository *r);
 
 /*
  * Configure local branch "local" as downstream to branch "remote"
index f65c1722993b62e93feb85e506dffbc77b7ce921..12247b48fd42d4a4b6955ff997fdf51a8785f9ae 100644 (file)
@@ -176,7 +176,7 @@ static void refresh(int verbose, const struct pathspec *pathspec)
                        die(_("pathspec '%s' did not match any files"),
                            pathspec->items[i].match);
        }
-        free(seen);
+       free(seen);
 }
 
 int run_add_interactive(const char *revision, const char *patch_mode,
index 8f27f3375b1e92f2ef026e0a1530ca8b6b3235bf..95370313b66daad8cabcc3b855136e29afb3133f 100644 (file)
@@ -1970,7 +1970,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
        if (merge_tree(remote_tree))
                return -1;
 
-       remove_branch_state();
+       remove_branch_state(the_repository);
 
        return 0;
 }
@@ -1981,7 +1981,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
 static void am_rerere_clear(void)
 {
        struct string_list merge_rr = STRING_LIST_INIT_DUP;
-       rerere_clear(&merge_rr);
+       rerere_clear(the_repository, &merge_rr);
        string_list_clear(&merge_rr, 1);
 }
 
index 4b5fadcbe1ae6a1b10fe88e80a5fcffd3296cfa7..417d141c09ad2698c17cf4738ad6ce7177456088 100644 (file)
@@ -137,7 +137,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
 
        switch (cmdmode) {
        case NEXT_ALL:
-               return bisect_next_all(prefix, no_checkout);
+               return bisect_next_all(the_repository, prefix, no_checkout);
        case WRITE_TERMS:
                if (argc != 2)
                        return error(_("--write-terms requires two arguments"));
index 06a7163ffe269cd43dc783c81ca6ac71b91b3614..6d798f99392e54b4392713846652111d457787bb 100644 (file)
@@ -850,6 +850,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                case PARSE_OPT_HELP:
                case PARSE_OPT_ERROR:
                        exit(129);
+               case PARSE_OPT_COMPLETE:
+                       exit(0);
                case PARSE_OPT_DONE:
                        if (ctx.argv[0])
                                dashdash_pos = ctx.cpidx;
index 0c55f7f065d6ceb34d27a165160192fabe9f22d1..1be727209b7ceaead46d0bc5e4b9666fbe7ef7a1 100644 (file)
@@ -783,7 +783,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                 * create_branch takes care of setting up the tracking
                 * info and making sure new_upstream is correct
                 */
-               create_branch(branch->name, new_upstream, 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
+               create_branch(the_repository, branch->name, new_upstream,
+                             0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
        } else if (unset_upstream) {
                struct branch *branch = branch_get(argv[0]);
                struct strbuf buf = STRBUF_INIT;
@@ -814,7 +815,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                if (track == BRANCH_TRACK_OVERRIDE)
                        die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead."));
 
-               create_branch(argv[0], (argc == 2) ? argv[1] : head,
+               create_branch(the_repository,
+                             argv[0], (argc == 2) ? argv[1] : head,
                              force, 0, reflog, quiet, track);
 
        } else
index d0de59b94ff23eebe03984dc670babf793bdd5ff..9e9c65d9c698cae2ab735463edf378d5dd3a9815 100644 (file)
@@ -40,7 +40,7 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
                        usage(builtin_bundle_usage);
                        return 1;
                }
-               if (verify_bundle(&header, 1))
+               if (verify_bundle(the_repository, &header, 1))
                        return 1;
                fprintf(stderr, _("%s is okay\n"), bundle_file);
                return 0;
@@ -56,11 +56,12 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
                }
                if (!startup_info->have_repository)
                        die(_("Need a repository to create a bundle."));
-               return !!create_bundle(&header, bundle_file, argc, argv);
+               return !!create_bundle(the_repository, &header,
+                                      bundle_file, argc, argv);
        } else if (!strcmp(cmd, "unbundle")) {
                if (!startup_info->have_repository)
                        die(_("Need a repository to unbundle."));
-               return !!unbundle(&header, bundle_fd, 0) ||
+               return !!unbundle(the_repository, &header, bundle_fd, 0) ||
                        list_bundle_refs(&header, argc, argv);
        } else
                usage(builtin_bundle_usage);
index eb74774cbc9d6bd6acf1b7fe2f31b8e80e461a12..a2a726ad8d8fa65d2fbcd1b111d71bad61c5cee8 100644 (file)
@@ -67,7 +67,8 @@ static int checkout_file(const char *name, const char *prefix)
                        continue;
                did_checkout = 1;
                if (checkout_entry(ce, &state,
-                   to_tempfile ? topath[ce_stage(ce)] : NULL) < 0)
+                                  to_tempfile ? topath[ce_stage(ce)] : NULL,
+                                  NULL) < 0)
                        errs++;
        }
 
@@ -111,7 +112,8 @@ static void checkout_all(const char *prefix, int prefix_length)
                                write_tempfile_record(last_ce->name, prefix);
                }
                if (checkout_entry(ce, &state,
-                   to_tempfile ? topath[ce_stage(ce)] : NULL) < 0)
+                                  to_tempfile ? topath[ce_stage(ce)] : NULL,
+                                  NULL) < 0)
                        errs++;
                last_ce = ce;
        }
index acdafc6e4c4d104aadcbe7492a8045e16e83ba50..6fadf412e830ba4aeaa8d2940fd9a7aab9bd8fa5 100644 (file)
@@ -44,6 +44,7 @@ struct checkout_opts {
        int ignore_skipworktree;
        int ignore_other_worktrees;
        int show_progress;
+       int count_checkout_paths;
        /*
         * If new checkout options are added, skip_merge_working_tree
         * should be updated accordingly.
@@ -115,7 +116,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
 
 static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)
 {
-       read_tree_recursive(tree, "", 0, 0, pathspec, update_some, NULL);
+       read_tree_recursive(the_repository, tree, "", 0, 0,
+                           pathspec, update_some, NULL);
 
        /* update the index with the given tree's info
         * for all args, expanding wildcards, and exit
@@ -165,12 +167,13 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)
 }
 
 static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
-                         const struct checkout *state)
+                         const struct checkout *state, int *nr_checkouts)
 {
        while (pos < active_nr &&
               !strcmp(active_cache[pos]->name, ce->name)) {
                if (ce_stage(active_cache[pos]) == stage)
-                       return checkout_entry(active_cache[pos], state, NULL);
+                       return checkout_entry(active_cache[pos], state,
+                                             NULL, nr_checkouts);
                pos++;
        }
        if (stage == 2)
@@ -179,7 +182,7 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
                return error(_("path '%s' does not have their version"), ce->name);
 }
 
-static int checkout_merged(int pos, const struct checkout *state)
+static int checkout_merged(int pos, const struct checkout *state, int *nr_checkouts)
 {
        struct cache_entry *ce = active_cache[pos];
        const char *path = ce->name;
@@ -242,7 +245,7 @@ static int checkout_merged(int pos, const struct checkout *state)
        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);
+       status = checkout_entry(ce, state, NULL, nr_checkouts);
        discard_cache_entry(ce);
        return status;
 }
@@ -257,6 +260,7 @@ static int checkout_paths(const struct checkout_opts *opts,
        struct commit *head;
        int errs = 0;
        struct lock_file lock_file = LOCK_INIT;
+       int nr_checkouts = 0;
 
        if (opts->track != BRANCH_TRACK_UNSPECIFIED)
                die(_("'%s' cannot be used with updating paths"), "--track");
@@ -371,17 +375,36 @@ static int checkout_paths(const struct checkout_opts *opts,
                struct cache_entry *ce = active_cache[pos];
                if (ce->ce_flags & CE_MATCHED) {
                        if (!ce_stage(ce)) {
-                               errs |= checkout_entry(ce, &state, NULL);
+                               errs |= checkout_entry(ce, &state,
+                                                      NULL, &nr_checkouts);
                                continue;
                        }
                        if (opts->writeout_stage)
-                               errs |= checkout_stage(opts->writeout_stage, ce, pos, &state);
+                               errs |= checkout_stage(opts->writeout_stage,
+                                                      ce, pos,
+                                                      &state, &nr_checkouts);
                        else if (opts->merge)
-                               errs |= checkout_merged(pos, &state);
+                               errs |= checkout_merged(pos, &state,
+                                                       &nr_checkouts);
                        pos = skip_same_name(ce, pos) - 1;
                }
        }
-       errs |= finish_delayed_checkout(&state);
+       errs |= finish_delayed_checkout(&state, &nr_checkouts);
+
+       if (opts->count_checkout_paths) {
+               if (opts->source_tree)
+                       fprintf_ln(stderr, Q_("Checked out %d path out of %s",
+                                             "Checked out %d paths out of %s",
+                                             nr_checkouts),
+                                  nr_checkouts,
+                                  find_unique_abbrev(&opts->source_tree->object.oid,
+                                                     DEFAULT_ABBREV));
+               else
+                       fprintf_ln(stderr, Q_("Checked out %d path out of the index",
+                                             "Checked out %d paths out of the index",
+                                             nr_checkouts),
+                                  nr_checkouts);
+       }
 
        if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
@@ -753,7 +776,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
                        free(refname);
                }
                else
-                       create_branch(opts->new_branch, new_branch_info->name,
+                       create_branch(the_repository,
+                                     opts->new_branch, new_branch_info->name,
                                      opts->new_branch_force ? 1 : 0,
                                      opts->new_branch_force ? 1 : 0,
                                      opts->new_branch_log,
@@ -811,7 +835,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
                                delete_reflog(old_branch_info->path);
                }
        }
-       remove_branch_state();
+       remove_branch_state(the_repository);
        strbuf_release(&msg);
        if (!opts->quiet &&
            (new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name, "HEAD"))))
@@ -1064,6 +1088,7 @@ static int parse_branchname_arg(int argc, const char **argv,
                has_dash_dash = 1; /* case (3) or (1) */
        else if (dash_dash_pos >= 2)
                die(_("only one reference expected, %d given."), dash_dash_pos);
+       opts->count_checkout_paths = !opts->quiet && !has_dash_dash;
 
        if (!strcmp(arg, "-"))
                arg = "@{-1}";
@@ -1079,9 +1104,12 @@ static int parse_branchname_arg(int argc, const char **argv,
                 */
                int recover_with_dwim = dwim_new_local_branch_ok;
 
-               if (!has_dash_dash &&
-                   (check_filename(opts->prefix, arg) || !no_wildcard(arg)))
+               int could_be_checkout_paths = !has_dash_dash &&
+                       check_filename(opts->prefix, arg);
+
+               if (!has_dash_dash && !no_wildcard(arg))
                        recover_with_dwim = 0;
+
                /*
                 * Accept "git checkout foo" and "git checkout foo --"
                 * as candidates for dwim.
@@ -1094,6 +1122,10 @@ static int parse_branchname_arg(int argc, const char **argv,
                        const char *remote = unique_tracking_name(arg, rev,
                                                                  dwim_remotes_matched);
                        if (remote) {
+                               if (could_be_checkout_paths)
+                                       die(_("'%s' could be both a local file and a tracking branch.\n"
+                                             "Please use -- (and optionally --no-guess) to disambiguate"),
+                                           arg);
                                *new_branch = arg;
                                arg = remote;
                                /* DWIMmed to create local branch, case (3).(b) */
@@ -1228,7 +1260,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        struct checkout_opts opts;
        struct branch_info new_branch_info;
        char *conflict_style = NULL;
-       int dwim_new_local_branch = 1;
+       int dwim_new_local_branch, no_dwim_new_local_branch = 0;
        int dwim_remotes_matched = 0;
        struct option options[] = {
                OPT__QUIET(&opts.quiet, N_("suppress progress reporting")),
@@ -1258,8 +1290,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                OPT_BOOL('p', "patch", &opts.patch_mode, N_("select hunks interactively")),
                OPT_BOOL(0, "ignore-skip-worktree-bits", &opts.ignore_skipworktree,
                         N_("do not limit pathspecs to sparse entries only")),
-               OPT_HIDDEN_BOOL(0, "guess", &dwim_new_local_branch,
-                               N_("second guess 'git checkout <no-such-branch>'")),
+               OPT_BOOL(0, "no-guess", &no_dwim_new_local_branch,
+                        N_("do not second guess 'git checkout <no-such-branch>'")),
                OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
                         N_("do not check if another worktree is holding the given ref")),
                { OPTION_CALLBACK, 0, "recurse-submodules", NULL,
@@ -1282,6 +1314,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, options, checkout_usage,
                             PARSE_OPT_KEEP_DASHDASH);
 
+       dwim_new_local_branch = !no_dwim_new_local_branch;
        if (opts.show_progress < 0) {
                if (opts.quiet)
                        opts.show_progress = 0;
index 15b142d64640e29c10e62d565ac21adbaaeebca4..7c7f98c72c80cfcb12f3d3f61a13f46b19967a8f 100644 (file)
@@ -548,7 +548,7 @@ static struct ref *find_remote_branch(const struct ref *refs, const char *branch
 }
 
 static struct ref *wanted_peer_refs(const struct ref *refs,
-               struct refspec_item *refspec)
+               struct refspec *refspec)
 {
        struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
        struct ref *local_refs = head;
@@ -569,13 +569,19 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
                        warning(_("Could not find remote branch %s to clone."),
                                option_branch);
                else {
-                       get_fetch_map(remote_head, refspec, &tail, 0);
+                       int i;
+                       for (i = 0; i < refspec->nr; i++)
+                               get_fetch_map(remote_head, &refspec->items[i],
+                                             &tail, 0);
 
                        /* if --branch=tag, pull the requested tag explicitly */
                        get_fetch_map(remote_head, tag_refspec, &tail, 0);
                }
-       } else
-               get_fetch_map(refs, refspec, &tail, 0);
+       } else {
+               int i;
+               for (i = 0; i < refspec->nr; i++)
+                       get_fetch_map(refs, &refspec->items[i], &tail, 0);
+       }
 
        if (!option_mirror && !option_single_branch && !option_no_tags)
                get_fetch_map(refs, tag_refspec, &tail, 0);
@@ -890,7 +896,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        const struct ref *our_head_points_at;
        struct ref *mapped_refs;
        const struct ref *ref;
-       struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
+       struct strbuf key = STRBUF_INIT;
+       struct strbuf default_refspec = STRBUF_INIT;
        struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
        struct transport *transport = NULL;
        const char *src_ref_prefix = "refs/heads/";
@@ -898,7 +905,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        int err = 0, complete_refs_before_fetch = 1;
        int submodule_progress;
 
-       struct refspec rs = REFSPEC_INIT_FETCH;
        struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
 
        fetch_if_missing = 0;
@@ -1067,7 +1073,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
        }
 
-       strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
        strbuf_addf(&key, "remote.%s.url", option_origin);
        git_config_set(key.buf, repo);
        strbuf_reset(&key);
@@ -1081,11 +1086,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        if (option_required_reference.nr || option_optional_reference.nr)
                setup_reference();
 
-       refspec_append(&rs, value.buf);
+       remote = remote_get(option_origin);
 
-       strbuf_reset(&value);
+       strbuf_addf(&default_refspec, "+%s*:%s*", src_ref_prefix,
+                   branch_top.buf);
+       refspec_append(&remote->fetch, default_refspec.buf);
 
-       remote = remote_get(option_origin);
        transport = transport_get(remote, remote->url[0]);
        transport_set_verbosity(transport, option_verbosity, option_progress);
        transport->family = family;
@@ -1140,7 +1146,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 
        argv_array_push(&ref_prefixes, "HEAD");
-       refspec_ref_prefixes(&rs, &ref_prefixes);
+       refspec_ref_prefixes(&remote->fetch, &ref_prefixes);
        if (option_branch)
                expand_ref_prefix(&ref_prefixes, option_branch);
        if (!option_no_tags)
@@ -1149,7 +1155,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        refs = transport_get_remote_refs(transport, &ref_prefixes);
 
        if (refs) {
-               mapped_refs = wanted_peer_refs(refs, &rs.items[0]);
+               mapped_refs = wanted_peer_refs(refs, &remote->fetch);
                /*
                 * transport_get_remote_refs() may return refs with null sha-1
                 * in mapped_refs (see struct transport->get_refs_list
@@ -1240,10 +1246,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        strbuf_release(&reflog_msg);
        strbuf_release(&branch_top);
        strbuf_release(&key);
-       strbuf_release(&value);
+       strbuf_release(&default_refspec);
        junk_mode = JUNK_LEAVE_ALL;
 
-       refspec_clear(&rs);
        argv_array_clear(&ref_prefixes);
        return err;
 }
index c021b119bb9df106ab7a860e032ea5dd35529401..004b816635bf1628bfe7697f737a22cbcd27622b 100644 (file)
@@ -188,7 +188,7 @@ static void determine_whence(struct wt_status *s)
 
 static void status_init_config(struct wt_status *s, config_fn_t fn)
 {
-       wt_status_prepare(s);
+       wt_status_prepare(the_repository, s);
        init_diff_ui_defaults();
        git_config(fn, s);
        determine_whence(s);
@@ -911,7 +911,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                        if (ignore_submodule_arg &&
                            !strcmp(ignore_submodule_arg, "all"))
                                flags.ignore_submodules = 1;
-                       committable = index_differs_from(parent, &flags, 1);
+                       committable = index_differs_from(the_repository,
+                                                        parent, &flags, 1);
                }
        }
        strbuf_release(&committer_ident);
@@ -1682,7 +1683,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                        flags |= SUMMARY_INITIAL_COMMIT;
                if (author_date_is_interesting())
                        flags |= SUMMARY_SHOW_AUTHOR_DATE;
-               print_commit_summary(prefix, &oid, flags);
+               print_commit_summary(the_repository, prefix,
+                                    &oid, flags);
        }
 
        UNLEAK(err);
index 84385ef165195e7c65be54e9463cb49578bec2bb..99bc7ef64ec6f7f0ab0e6dc1d0dc3fd149969a16 100644 (file)
@@ -164,7 +164,8 @@ 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) {
+static void check_argc(int argc, int min, int max)
+{
        if (argc >= min && argc <= max)
                return;
        if (min == max)
index a7cad052c615807b819f32c999c161f0f905c1bc..3fae474f6f1f4fb78911ab4a26a160f04527d292 100644 (file)
@@ -78,10 +78,10 @@ static int count_cruft(const char *basename, const char *path, void *data)
        return 0;
 }
 
-static int print_alternate(struct alternate_object_database *alt, void *data)
+static int print_alternate(struct object_directory *odb, void *data)
 {
        printf("alternate: ");
-       quote_c_style(alt->path, NULL, stdout, 0);
+       quote_c_style(odb->path, NULL, stdout, 0);
        putchar('\n');
        return 0;
 }
index 544b0e86397cb98ddfdad3cffdd983905ee36029..71318c26e177e8aa4176201e4f23e6f43b63b630 100644 (file)
@@ -323,7 +323,7 @@ static int checkout_path(unsigned mode, struct object_id *oid,
        int ret;
 
        ce = make_transient_cache_entry(mode, oid, path, 0);
-       ret = checkout_entry(ce, state, NULL);
+       ret = checkout_entry(ce, state, NULL, NULL);
 
        discard_cache_entry(ce);
        return ret;
index 5790f0d554b0aed2ea36a38c289cc6ce2c3c0faf..9e283482efcfa6de0376cc9306061cea149b12df 100644 (file)
@@ -31,13 +31,16 @@ static const char *fast_export_usage[] = {
 };
 
 static int progress;
-static enum { ABORT, VERBATIM, WARN, WARN_STRIP, STRIP } signed_tag_mode = ABORT;
-static enum { ERROR, DROP, REWRITE } tag_of_filtered_mode = ERROR;
+static enum { SIGNED_TAG_ABORT, VERBATIM, WARN, WARN_STRIP, STRIP } signed_tag_mode = SIGNED_TAG_ABORT;
+static enum { TAG_FILTERING_ABORT, DROP, REWRITE } tag_of_filtered_mode = TAG_FILTERING_ABORT;
 static int fake_missing_tagger;
 static int use_done_feature;
 static int no_data;
 static int full_tree;
+static int reference_excluded_commits;
+static int show_original_ids;
 static struct string_list extra_refs = STRING_LIST_INIT_NODUP;
+static struct string_list tag_refs = STRING_LIST_INIT_NODUP;
 static struct refspec refspecs = REFSPEC_INIT_FETCH;
 static int anonymize;
 static struct revision_sources revision_sources;
@@ -46,7 +49,7 @@ static int parse_opt_signed_tag_mode(const struct option *opt,
                                     const char *arg, int unset)
 {
        if (unset || !strcmp(arg, "abort"))
-               signed_tag_mode = ABORT;
+               signed_tag_mode = SIGNED_TAG_ABORT;
        else if (!strcmp(arg, "verbatim") || !strcmp(arg, "ignore"))
                signed_tag_mode = VERBATIM;
        else if (!strcmp(arg, "warn"))
@@ -64,7 +67,7 @@ static int parse_opt_tag_of_filtered_mode(const struct option *opt,
                                          const char *arg, int unset)
 {
        if (unset || !strcmp(arg, "abort"))
-               tag_of_filtered_mode = ERROR;
+               tag_of_filtered_mode = TAG_FILTERING_ABORT;
        else if (!strcmp(arg, "drop"))
                tag_of_filtered_mode = DROP;
        else if (!strcmp(arg, "rewrite"))
@@ -187,6 +190,22 @@ static int get_object_mark(struct object *object)
        return ptr_to_mark(decoration);
 }
 
+static struct commit *rewrite_commit(struct commit *p)
+{
+       for (;;) {
+               if (p->parents && p->parents->next)
+                       break;
+               if (p->object.flags & UNINTERESTING)
+                       break;
+               if (!(p->object.flags & TREESAME))
+                       break;
+               if (!p->parents)
+                       return NULL;
+               p = p->parents->item;
+       }
+       return p;
+}
+
 static void show_progress(void)
 {
        static int counter = 0;
@@ -243,7 +262,7 @@ static void export_blob(const struct object_id *oid)
                if (!buf)
                        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));
+                       die("oid mismatch in blob %s", oid_to_hex(oid));
                object = parse_object_buffer(the_repository, oid, type,
                                             size, buf, &eaten);
        }
@@ -253,7 +272,10 @@ static void export_blob(const struct object_id *oid)
 
        mark_next_object(object);
 
-       printf("blob\nmark :%"PRIu32"\ndata %"PRIuMAX"\n", last_idnum, (uintmax_t)size);
+       printf("blob\nmark :%"PRIu32"\n", last_idnum);
+       if (show_original_ids)
+               printf("original-oid %s\n", oid_to_hex(oid));
+       printf("data %"PRIuMAX"\n", (uintmax_t)size);
        if (size && fwrite(buf, size, 1, stdout) != 1)
                die_errno("could not write blob '%s'", oid_to_hex(oid));
        printf("\n");
@@ -330,17 +352,18 @@ static void print_path(const char *path)
 
 static void *generate_fake_oid(const void *old, size_t *len)
 {
-       static uint32_t counter = 1; /* avoid null sha1 */
-       unsigned char *out = xcalloc(GIT_SHA1_RAWSZ, 1);
-       put_be32(out + GIT_SHA1_RAWSZ - 4, counter++);
+       static uint32_t counter = 1; /* avoid null oid */
+       const unsigned hashsz = the_hash_algo->rawsz;
+       unsigned char *out = xcalloc(hashsz, 1);
+       put_be32(out + hashsz - 4, counter++);
        return out;
 }
 
-static const unsigned char *anonymize_sha1(const struct object_id *oid)
+static const struct object_id *anonymize_oid(const struct object_id *oid)
 {
-       static struct hashmap sha1s;
-       size_t len = GIT_SHA1_RAWSZ;
-       return anonymize_mem(&sha1s, generate_fake_oid, oid, &len);
+       static struct hashmap objs;
+       size_t len = the_hash_algo->rawsz;
+       return anonymize_mem(&objs, generate_fake_oid, oid, &len);
 }
 
 static void show_filemodify(struct diff_queue_struct *q,
@@ -399,9 +422,9 @@ static void show_filemodify(struct diff_queue_struct *q,
                         */
                        if (no_data || S_ISGITLINK(spec->mode))
                                printf("M %06o %s ", spec->mode,
-                                      sha1_to_hex(anonymize ?
-                                                  anonymize_sha1(&spec->oid) :
-                                                  spec->oid.hash));
+                                      oid_to_hex(anonymize ?
+                                                 anonymize_oid(&spec->oid) :
+                                                 &spec->oid));
                        else {
                                struct object *object = lookup_object(the_repository,
                                                                      spec->oid.hash);
@@ -579,7 +602,8 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
                message += 2;
 
        if (commit->parents &&
-           get_object_mark(&commit->parents->item->object) != 0 &&
+           (get_object_mark(&commit->parents->item->object) != 0 ||
+            reference_excluded_commits) &&
            !full_tree) {
                parse_commit_or_die(commit->parents->item);
                diff_tree_oid(get_commit_tree_oid(commit->parents->item),
@@ -595,6 +619,13 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
                        export_blob(&diff_queued_diff.queue[i]->two->oid);
 
        refname = *revision_sources_at(&revision_sources, commit);
+       /*
+        * FIXME: string_list_remove() below for each ref is overall
+        * O(N^2).  Compared to a history walk and diffing trees, this is
+        * just lost in the noise in practice.  However, theoretically a
+        * repo may have enough refs for this to become slow.
+        */
+       string_list_remove(&extra_refs, refname, 0);
        if (anonymize) {
                refname = anonymize_refname(refname);
                anonymize_ident_line(&committer, &committer_end);
@@ -608,8 +639,10 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
                reencoded = reencode_string(message, "UTF-8", encoding);
        if (!commit->parents)
                printf("reset %s\n", refname);
-       printf("commit %s\nmark :%"PRIu32"\n%.*s\n%.*s\ndata %u\n%s",
-              refname, last_idnum,
+       printf("commit %s\nmark :%"PRIu32"\n", refname, last_idnum);
+       if (show_original_ids)
+               printf("original-oid %s\n", oid_to_hex(&commit->object.oid));
+       printf("%.*s\n%.*s\ndata %u\n%s",
               (int)(author_end - author), author,
               (int)(committer_end - committer), committer,
               (unsigned)(reencoded
@@ -620,13 +653,21 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
        unuse_commit_buffer(commit, commit_buffer);
 
        for (i = 0, p = commit->parents; p; p = p->next) {
-               int mark = get_object_mark(&p->item->object);
-               if (!mark)
+               struct object *obj = &p->item->object;
+               int mark = get_object_mark(obj);
+
+               if (!mark && !reference_excluded_commits)
                        continue;
                if (i == 0)
-                       printf("from :%d\n", mark);
+                       printf("from ");
+               else
+                       printf("merge ");
+               if (mark)
+                       printf(":%d\n", mark);
                else
-                       printf("merge :%d\n", mark);
+                       printf("%s\n", oid_to_hex(anonymize ?
+                                                 anonymize_oid(&obj->oid) :
+                                                 &obj->oid));
                i++;
        }
 
@@ -727,7 +768,7 @@ static void handle_tag(const char *name, struct tag *tag)
                                               "\n-----BEGIN PGP SIGNATURE-----\n");
                if (signature)
                        switch(signed_tag_mode) {
-                       case ABORT:
+                       case SIGNED_TAG_ABORT:
                                die("encountered signed tag %s; use "
                                    "--signed-tags=<mode> to handle it",
                                    oid_to_hex(&tag->object.oid));
@@ -752,7 +793,7 @@ static void handle_tag(const char *name, struct tag *tag)
        tagged_mark = get_object_mark(tagged);
        if (!tagged_mark) {
                switch(tag_of_filtered_mode) {
-               case ABORT:
+               case TAG_FILTERING_ABORT:
                        die("tag %s tags unexported object; use "
                            "--tag-of-filtered-object=<mode> to handle it",
                            oid_to_hex(&tag->object.oid));
@@ -766,18 +807,12 @@ static void handle_tag(const char *name, struct tag *tag)
                                    oid_to_hex(&tag->object.oid),
                                    type_name(tagged->type));
                        }
-                       p = (struct commit *)tagged;
-                       for (;;) {
-                               if (p->parents && p->parents->next)
-                                       break;
-                               if (p->object.flags & UNINTERESTING)
-                                       break;
-                               if (!(p->object.flags & TREESAME))
-                                       break;
-                               if (!p->parents)
-                                       die("can't find replacement commit for tag %s",
-                                            oid_to_hex(&tag->object.oid));
-                               p = p->parents->item;
+                       p = rewrite_commit((struct commit *)tagged);
+                       if (!p) {
+                               printf("reset %s\nfrom %s\n\n",
+                                      name, oid_to_hex(&null_oid));
+                               free(buf);
+                               return;
                        }
                        tagged_mark = get_object_mark(&p->object);
                }
@@ -785,8 +820,10 @@ static void handle_tag(const char *name, struct tag *tag)
 
        if (starts_with(name, "refs/tags/"))
                name += 10;
-       printf("tag %s\nfrom :%d\n%.*s%sdata %d\n%.*s\n",
-              name, tagged_mark,
+       printf("tag %s\nfrom :%d\n", name, tagged_mark);
+       if (show_original_ids)
+               printf("original-oid %s\n", oid_to_hex(&tag->object.oid));
+       printf("%.*s%sdata %d\n%.*s\n",
               (int)(tagger_end - tagger), tagger,
               tagger == tagger_end ? "" : "\n",
               (int)message_size, (int)message_size, message ? message : "");
@@ -804,7 +841,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(the_repository, &tag->object.oid);
-                       string_list_append(&extra_refs, full_name)->util = tag;
+                       string_list_append(&tag_refs, full_name)->util = tag;
                        tag = (struct tag *)tag->tagged;
                }
                if (!tag)
@@ -863,25 +900,30 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
                }
 
                /*
-                * This ref will not be updated through a commit, lets make
-                * sure it gets properly updated eventually.
+                * Make sure this ref gets properly updated eventually, whether
+                * through a commit or manually at the end.
                 */
-               if (*revision_sources_at(&revision_sources, commit) ||
-                   commit->object.flags & SHOWN)
+               if (e->item->type != OBJ_TAG)
                        string_list_append(&extra_refs, full_name)->util = commit;
+
                if (!*revision_sources_at(&revision_sources, commit))
                        *revision_sources_at(&revision_sources, commit) = full_name;
        }
+
+       string_list_sort(&extra_refs);
+       string_list_remove_duplicates(&extra_refs, 0);
 }
 
-static void handle_tags_and_duplicates(void)
+static void handle_tags_and_duplicates(struct string_list *extras)
 {
        struct commit *commit;
        int i;
 
-       for (i = extra_refs.nr - 1; i >= 0; i--) {
-               const char *name = extra_refs.items[i].string;
-               struct object *object = extra_refs.items[i].util;
+       for (i = extras->nr - 1; i >= 0; i--) {
+               const char *name = extras->items[i].string;
+               struct object *object = extras->items[i].util;
+               int mark;
+
                switch (object->type) {
                case OBJ_TAG:
                        handle_tag(name, (struct tag *)object);
@@ -890,9 +932,45 @@ static void handle_tags_and_duplicates(void)
                        if (anonymize)
                                name = anonymize_refname(name);
                        /* create refs pointing to already seen commits */
-                       commit = (struct commit *)object;
-                       printf("reset %s\nfrom :%d\n\n", name,
-                              get_object_mark(&commit->object));
+                       commit = rewrite_commit((struct commit *)object);
+                       if (!commit) {
+                               /*
+                                * Neither this object nor any of its
+                                * ancestors touch any relevant paths, so
+                                * it has been filtered to nothing.  Delete
+                                * it.
+                                */
+                               printf("reset %s\nfrom %s\n\n",
+                                      name, oid_to_hex(&null_oid));
+                               continue;
+                       }
+
+                       mark = get_object_mark(&commit->object);
+                       if (!mark) {
+                               /*
+                                * Getting here means we have a commit which
+                                * was excluded by a negative refspec (e.g.
+                                * fast-export ^master master).  If we are
+                                * referencing excluded commits, set the ref
+                                * to the exact commit.  Otherwise, the user
+                                * wants the branch exported but every commit
+                                * in its history to be deleted, which basically
+                                * just means deletion of the ref.
+                                */
+                               if (!reference_excluded_commits) {
+                                       /* delete the ref */
+                                       printf("reset %s\nfrom %s\n\n",
+                                              name, oid_to_hex(&null_oid));
+                                       continue;
+                               }
+                               /* set ref to commit using oid, not mark */
+                               printf("reset %s\nfrom %s\n\n", name,
+                                      oid_to_hex(&commit->object.oid));
+                               continue;
+                       }
+
+                       printf("reset %s\nfrom :%d\n\n", name, mark
+                              );
                        show_progress();
                        break;
                }
@@ -988,7 +1066,7 @@ static void handle_deletes(void)
                        continue;
 
                printf("reset %s\nfrom %s\n\n",
-                               refspec->dst, sha1_to_hex(null_sha1));
+                               refspec->dst, oid_to_hex(&null_oid));
        }
 }
 
@@ -1024,6 +1102,11 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
                OPT_STRING_LIST(0, "refspec", &refspecs_list, N_("refspec"),
                             N_("Apply refspec to exported refs")),
                OPT_BOOL(0, "anonymize", &anonymize, N_("anonymize output")),
+               OPT_BOOL(0, "reference-excluded-parents",
+                        &reference_excluded_commits, N_("Reference parents which are not in fast-export stream by object id")),
+               OPT_BOOL(0, "show-original-ids", &show_original_ids,
+                           N_("Show original object ids of blobs/commits")),
+
                OPT_END()
        };
 
@@ -1080,7 +1163,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
                }
        }
 
-       handle_tags_and_duplicates();
+       handle_tags_and_duplicates(&extra_refs);
+       handle_tags_and_duplicates(&tag_refs);
        handle_deletes();
 
        if (export_filename && lastimportid != last_idnum)
index 3c3e0f06e78009ee3ee2d54333dfc4740b8792a9..bf5ddff43f74e0dba77d05e04bc14c0c59884287 100644 (file)
@@ -51,16 +51,24 @@ static int name_objects;
 
 static const char *describe_object(struct object *obj)
 {
-       static struct strbuf buf = STRBUF_INIT;
-       char *name = name_objects ?
-               lookup_decoration(fsck_walk_options.object_names, obj) : NULL;
+       static struct strbuf bufs[] = {
+               STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
+       };
+       static int b = 0;
+       struct strbuf *buf;
+       char *name = NULL;
 
-       strbuf_reset(&buf);
-       strbuf_addstr(&buf, oid_to_hex(&obj->oid));
+       if (name_objects)
+               name = lookup_decoration(fsck_walk_options.object_names, obj);
+
+       buf = bufs + b;
+       b = (b + 1) % ARRAY_SIZE(bufs);
+       strbuf_reset(buf);
+       strbuf_addstr(buf, oid_to_hex(&obj->oid));
        if (name)
-               strbuf_addf(&buf, " (%s)", name);
+               strbuf_addf(buf, " (%s)", name);
 
-       return buf.buf;
+       return buf->buf;
 }
 
 static const char *printable_type(struct object *obj)
@@ -76,7 +84,7 @@ static const char *printable_type(struct object *obj)
 
        ret = type_name(obj->type);
        if (!ret)
-               ret = "unknown";
+               ret = _("unknown");
 
        return ret;
 }
@@ -104,25 +112,32 @@ static int fsck_config(const char *var, const char *value, void *cb)
        return git_default_config(var, value, cb);
 }
 
-static void objreport(struct object *obj, const char *msg_type,
-                       const char *err)
-{
-       fprintf(stderr, "%s in %s %s: %s\n",
-               msg_type, printable_type(obj), describe_object(obj), err);
-}
-
 static int objerror(struct object *obj, const char *err)
 {
        errors_found |= ERROR_OBJECT;
-       objreport(obj, "error", err);
+       /* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
+       fprintf_ln(stderr, _("error in %s %s: %s"),
+                  printable_type(obj), describe_object(obj), err);
        return -1;
 }
 
 static int fsck_error_func(struct fsck_options *o,
        struct object *obj, int type, const char *message)
 {
-       objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message);
-       return (type == FSCK_WARN) ? 0 : 1;
+       switch (type) {
+       case FSCK_WARN:
+               /* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */
+               fprintf_ln(stderr, _("warning in %s %s: %s"),
+                          printable_type(obj), describe_object(obj), message);
+               return 0;
+       case FSCK_ERROR:
+               /* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
+               fprintf_ln(stderr, _("error in %s %s: %s"),
+                          printable_type(obj), describe_object(obj), message);
+               return 1;
+       default:
+               BUG("%d (FSCK_IGNORE?) should never trigger this callback", type);
+       }
 }
 
 static struct object_array pending;
@@ -138,17 +153,18 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
         */
        if (!obj) {
                /* ... these references to parent->fld are safe here */
-               printf("broken link from %7s %s\n",
-                          printable_type(parent), describe_object(parent));
-               printf("broken link from %7s %s\n",
-                          (type == OBJ_ANY ? "unknown" : type_name(type)), "unknown");
+               printf_ln(_("broken link from %7s %s"),
+                         printable_type(parent), describe_object(parent));
+               printf_ln(_("broken link from %7s %s"),
+                         (type == OBJ_ANY ? _("unknown") : type_name(type)),
+                         _("unknown"));
                errors_found |= ERROR_REACHABLE;
                return 1;
        }
 
        if (type != OBJ_ANY && obj->type != type)
                /* ... and the reference to parent is safe here */
-               objerror(parent, "wrong object type in link");
+               objerror(parent, _("wrong object type in link"));
 
        if (obj->flags & REACHABLE)
                return 0;
@@ -164,10 +180,12 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
 
        if (!(obj->flags & HAS_OBJ)) {
                if (parent && !has_object_file(&obj->oid)) {
-                       printf("broken link from %7s %s\n",
-                                printable_type(parent), describe_object(parent));
-                       printf("              to %7s %s\n",
-                                printable_type(obj), describe_object(obj));
+                       printf_ln(_("broken link from %7s %s\n"
+                                   "              to %7s %s"),
+                                 printable_type(parent),
+                                 describe_object(parent),
+                                 printable_type(obj),
+                                 describe_object(obj));
                        errors_found |= ERROR_REACHABLE;
                }
                return 1;
@@ -231,8 +249,8 @@ static void check_reachable_object(struct object *obj)
                        return;
                if (has_object_pack(&obj->oid))
                        return; /* it is in pack - forget about it */
-               printf("missing %s %s\n", printable_type(obj),
-                       describe_object(obj));
+               printf_ln(_("missing %s %s"), printable_type(obj),
+                         describe_object(obj));
                errors_found |= ERROR_REACHABLE;
                return;
        }
@@ -257,8 +275,8 @@ static void check_unreachable_object(struct object *obj)
         * since this is something that is prunable.
         */
        if (show_unreachable) {
-               printf("unreachable %s %s\n", printable_type(obj),
-                       describe_object(obj));
+               printf_ln(_("unreachable %s %s"), printable_type(obj),
+                         describe_object(obj));
                return;
        }
 
@@ -276,8 +294,8 @@ static void check_unreachable_object(struct object *obj)
         */
        if (!(obj->flags & USED)) {
                if (show_dangling)
-                       printf("dangling %s %s\n", printable_type(obj),
-                              describe_object(obj));
+                       printf_ln(_("dangling %s %s"), printable_type(obj),
+                                 describe_object(obj));
                if (write_lost_and_found) {
                        char *filename = git_pathdup("lost-found/%s/%s",
                                obj->type == OBJ_COMMIT ? "commit" : "other",
@@ -285,18 +303,18 @@ static void check_unreachable_object(struct object *obj)
                        FILE *f;
 
                        if (safe_create_leading_directories_const(filename)) {
-                               error("Could not create lost-found");
+                               error(_("could not create lost-found"));
                                free(filename);
                                return;
                        }
                        f = xfopen(filename, "w");
                        if (obj->type == OBJ_BLOB) {
                                if (stream_blob_to_fd(fileno(f), &obj->oid, NULL, 1))
-                                       die_errno("Could not write '%s'", filename);
+                                       die_errno(_("could not write '%s'"), filename);
                        } else
                                fprintf(f, "%s\n", describe_object(obj));
                        if (fclose(f))
-                               die_errno("Could not finish '%s'",
+                               die_errno(_("could not finish '%s'"),
                                          filename);
                        free(filename);
                }
@@ -313,7 +331,7 @@ static void check_unreachable_object(struct object *obj)
 static void check_object(struct object *obj)
 {
        if (verbose)
-               fprintf(stderr, "Checking %s\n", describe_object(obj));
+               fprintf_ln(stderr, _("Checking %s"), describe_object(obj));
 
        if (obj->flags & REACHABLE)
                check_reachable_object(obj);
@@ -331,7 +349,7 @@ static void check_connectivity(void)
        /* Look up all the requirements, warn about missing objects.. */
        max = get_max_object_index();
        if (verbose)
-               fprintf(stderr, "Checking connectivity (%d objects)\n", max);
+               fprintf_ln(stderr, _("Checking connectivity (%d objects)"), max);
 
        for (i = 0; i < max; i++) {
                struct object *obj = get_indexed_object(i);
@@ -350,11 +368,11 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
        obj->flags |= SEEN;
 
        if (verbose)
-               fprintf(stderr, "Checking %s %s\n",
-                       printable_type(obj), describe_object(obj));
+               fprintf_ln(stderr, _("Checking %s %s"),
+                          printable_type(obj), describe_object(obj));
 
        if (fsck_walk(obj, NULL, &fsck_obj_options))
-               objerror(obj, "broken links");
+               objerror(obj, _("broken links"));
        err = fsck_object(obj, buffer, size, &fsck_obj_options);
        if (err)
                goto out;
@@ -363,17 +381,19 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
                struct commit *commit = (struct commit *) obj;
 
                if (!commit->parents && show_root)
-                       printf("root %s\n", describe_object(&commit->object));
+                       printf_ln(_("root %s"),
+                                 describe_object(&commit->object));
        }
 
        if (obj->type == OBJ_TAG) {
                struct tag *tag = (struct tag *) obj;
 
                if (show_tags && tag->tagged) {
-                       printf("tagged %s %s", printable_type(tag->tagged),
-                               describe_object(tag->tagged));
-                       printf(" (%s) in %s\n", tag->tag,
-                               describe_object(&tag->object));
+                       printf_ln(_("tagged %s %s (%s) in %s"),
+                                 printable_type(tag->tagged),
+                                 describe_object(tag->tagged),
+                                 tag->tag,
+                                 describe_object(&tag->object));
                }
        }
 
@@ -397,7 +417,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
                                  eaten);
        if (!obj) {
                errors_found |= ERROR_OBJECT;
-               return error("%s: object corrupt or missing", oid_to_hex(oid));
+               return error(_("%s: object corrupt or missing"),
+                            oid_to_hex(oid));
        }
        obj->flags &= ~(REACHABLE | SEEN);
        obj->flags |= HAS_OBJ;
@@ -421,7 +442,8 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
                        obj->flags |= USED;
                        mark_object_reachable(obj);
                } else if (!is_promisor_object(oid)) {
-                       error("%s: invalid reflog entry %s", refname, oid_to_hex(oid));
+                       error(_("%s: invalid reflog entry %s"),
+                             refname, oid_to_hex(oid));
                        errors_found |= ERROR_REACHABLE;
                }
        }
@@ -434,8 +456,8 @@ static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noid
        const char *refname = cb_data;
 
        if (verbose)
-               fprintf(stderr, "Checking reflog %s->%s\n",
-                       oid_to_hex(ooid), oid_to_hex(noid));
+               fprintf_ln(stderr, _("Checking reflog %s->%s"),
+                          oid_to_hex(ooid), oid_to_hex(noid));
 
        fsck_handle_reflog_oid(refname, ooid, 0);
        fsck_handle_reflog_oid(refname, noid, timestamp);
@@ -468,13 +490,14 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
                         default_refs++;
                         return 0;
                }
-               error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
+               error(_("%s: invalid sha1 pointer %s"),
+                     refname, oid_to_hex(oid));
                errors_found |= ERROR_REACHABLE;
                /* We'll continue with the rest despite the error.. */
                return 0;
        }
        if (obj->type != OBJ_COMMIT && is_branch(refname)) {
-               error("%s: not a commit", refname);
+               error(_("%s: not a commit"), refname);
                errors_found |= ERROR_REFS;
        }
        default_refs++;
@@ -529,7 +552,7 @@ static void get_default_heads(void)
         * "show_unreachable" flag.
         */
        if (!default_refs) {
-               fprintf(stderr, "notice: No default references\n");
+               fprintf_ln(stderr, _("notice: No default references"));
                show_unreachable = 0;
        }
 }
@@ -544,7 +567,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
 
        if (read_loose_object(path, oid, &type, &size, &contents) < 0) {
                errors_found |= ERROR_OBJECT;
-               error("%s: object corrupt or missing: %s",
+               error(_("%s: object corrupt or missing: %s"),
                      oid_to_hex(oid), path);
                return 0; /* keep checking other objects */
        }
@@ -557,7 +580,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
 
        if (!obj) {
                errors_found |= ERROR_OBJECT;
-               error("%s: object could not be parsed: %s",
+               error(_("%s: object could not be parsed: %s"),
                      oid_to_hex(oid), path);
                if (!eaten)
                        free(contents);
@@ -577,7 +600,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
 static int fsck_cruft(const char *basename, const char *path, void *data)
 {
        if (!starts_with(basename, "tmp_obj_"))
-               fprintf(stderr, "bad sha1 file: %s\n", path);
+               fprintf_ln(stderr, _("bad sha1 file: %s"), path);
        return 0;
 }
 
@@ -592,7 +615,7 @@ static void fsck_object_dir(const char *path)
        struct progress *progress = NULL;
 
        if (verbose)
-               fprintf(stderr, "Checking object directory\n");
+               fprintf_ln(stderr, _("Checking object directory"));
 
        if (show_progress)
                progress = start_progress(_("Checking object directories"), 256);
@@ -610,29 +633,30 @@ static int fsck_head_link(const char *head_ref_name,
        int null_is_error = 0;
 
        if (verbose)
-               fprintf(stderr, "Checking %s link\n", head_ref_name);
+               fprintf_ln(stderr, _("Checking %s link"), head_ref_name);
 
        *head_points_at = resolve_ref_unsafe(head_ref_name, 0, head_oid, NULL);
        if (!*head_points_at) {
                errors_found |= ERROR_REFS;
-               return error("Invalid %s", head_ref_name);
+               return error(_("invalid %s"), head_ref_name);
        }
        if (!strcmp(*head_points_at, head_ref_name))
                /* detached HEAD */
                null_is_error = 1;
        else if (!starts_with(*head_points_at, "refs/heads/")) {
                errors_found |= ERROR_REFS;
-               return error("%s points to something strange (%s)",
+               return error(_("%s points to something strange (%s)"),
                             head_ref_name, *head_points_at);
        }
        if (is_null_oid(head_oid)) {
                if (null_is_error) {
                        errors_found |= ERROR_REFS;
-                       return error("%s: detached HEAD points at nothing",
+                       return error(_("%s: detached HEAD points at nothing"),
                                     head_ref_name);
                }
-               fprintf(stderr, "notice: %s points to an unborn branch (%s)\n",
-                       head_ref_name, *head_points_at + 11);
+               fprintf_ln(stderr,
+                          _("notice: %s points to an unborn branch (%s)"),
+                          head_ref_name, *head_points_at + 11);
        }
        return 0;
 }
@@ -643,12 +667,12 @@ static int fsck_cache_tree(struct cache_tree *it)
        int err = 0;
 
        if (verbose)
-               fprintf(stderr, "Checking cache tree\n");
+               fprintf_ln(stderr, _("Checking cache tree"));
 
        if (0 <= it->entry_count) {
                struct object *obj = parse_object(the_repository, &it->oid);
                if (!obj) {
-                       error("%s: invalid sha1 pointer in cache-tree",
+                       error(_("%s: invalid sha1 pointer in cache-tree"),
                              oid_to_hex(&it->oid));
                        errors_found |= ERROR_REFS;
                        return 1;
@@ -659,7 +683,7 @@ static int fsck_cache_tree(struct cache_tree *it)
                                obj, xstrdup(":"));
                mark_object_reachable(obj);
                if (obj->type != OBJ_TREE)
-                       err |= objerror(obj, "non-tree in cache-tree");
+                       err |= objerror(obj, _("non-tree in cache-tree"));
        }
        for (i = 0; i < it->subtree_nr; i++)
                err |= fsck_cache_tree(it->down[i]->cache_tree);
@@ -715,7 +739,7 @@ static struct option fsck_opts[] = {
 int cmd_fsck(int argc, const char **argv, const char *prefix)
 {
        int i;
-       struct alternate_object_database *alt;
+       struct object_directory *odb;
 
        /* fsck knows how to handle missing promisor objects */
        fetch_if_missing = 0;
@@ -751,14 +775,9 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
                for_each_packed_object(mark_packed_for_connectivity, NULL, 0);
        } else {
-               struct alternate_object_database *alt_odb_list;
-
-               fsck_object_dir(get_object_directory());
-
                prepare_alt_odb(the_repository);
-               alt_odb_list = the_repository->objects->alt_odb_list;
-               for (alt = alt_odb_list; alt; alt = alt->next)
-                       fsck_object_dir(alt->path);
+               for (odb = the_repository->objects->odb; odb; odb = odb->next)
+                       fsck_object_dir(odb->path);
 
                if (check_full) {
                        struct packed_git *p;
@@ -778,7 +797,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                        for (p = get_all_packs(the_repository); p;
                             p = p->next) {
                                /* verify gives error messages itself */
-                               if (verify_pack(p, fsck_obj_buffer,
+                               if (verify_pack(the_repository,
+                                               p, fsck_obj_buffer,
                                                progress, count))
                                        errors_found |= ERROR_PACK;
                                count += p->num_objects;
@@ -800,7 +820,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                        if (!obj || !(obj->flags & HAS_OBJ)) {
                                if (is_promisor_object(&oid))
                                        continue;
-                               error("%s: object missing", oid_to_hex(&oid));
+                               error(_("%s: object missing"), oid_to_hex(&oid));
                                errors_found |= ERROR_OBJECT;
                                continue;
                        }
@@ -812,7 +832,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                        mark_object_reachable(obj);
                        continue;
                }
-               error("invalid parameter: expected sha1, got '%s'", arg);
+               error(_("invalid parameter: expected sha1, got '%s'"), arg);
                errors_found |= ERROR_OBJECT;
        }
 
@@ -860,15 +880,13 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                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) {
+               for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+                       child_process_init(&commit_graph_verify);
+                       commit_graph_verify.argv = verify_argv;
+                       commit_graph_verify.git_cmd = 1;
                        verify_argv[2] = "--object-dir";
-                       verify_argv[3] = alt->path;
+                       verify_argv[3] = odb->path;
                        if (run_command(&commit_graph_verify))
                                errors_found |= ERROR_COMMIT_GRAPH;
                }
@@ -878,15 +896,13 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                struct child_process midx_verify = CHILD_PROCESS_INIT;
                const char *midx_argv[] = { "multi-pack-index", "verify", NULL, NULL, NULL };
 
-               midx_verify.argv = midx_argv;
-               midx_verify.git_cmd = 1;
-               if (run_command(&midx_verify))
-                       errors_found |= ERROR_COMMIT_GRAPH;
-
                prepare_alt_odb(the_repository);
-               for (alt =  the_repository->objects->alt_odb_list; alt; alt = alt->next) {
+               for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+                       child_process_init(&midx_verify);
+                       midx_verify.argv = midx_argv;
+                       midx_verify.git_cmd = 1;
                        midx_argv[2] = "--object-dir";
-                       midx_argv[3] = alt->path;
+                       midx_argv[3] = odb->path;
                        if (run_command(&midx_verify))
                                errors_found |= ERROR_COMMIT_GRAPH;
                }
index 871a56f1c5a5804db9363b117ae3891ea832bc5f..7696017cd4152eb191972d2d662c592030ac811e 100644 (file)
@@ -317,7 +317,7 @@ static void add_repack_all_option(struct string_list *keep_pack)
 
 static void add_repack_incremental_option(void)
 {
-       argv_array_push(&repack, "--no-write-bitmap-index");
+       argv_array_push(&repack, "--no-write-bitmap-index");
 }
 
 static int need_to_gc(void)
index 71df52a333cbc756b057e93bf3d2affca8157860..4748195ae173786924f75dab9e865ce05b434930 100644 (file)
@@ -437,7 +437,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
         * store is no longer global and instead is a member of the repository
         * object.
         */
-       add_to_alternates_memory(submodule.objects->objectdir);
+       add_to_alternates_memory(submodule.objects->odb->path);
        grep_read_unlock();
 
        if (oid) {
@@ -553,7 +553,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
 
                if (match != all_entries_interesting) {
                        strbuf_addstr(&name, base->buf + tn_len);
-                       match = tree_entry_interesting(&entry, &name,
+                       match = tree_entry_interesting(repo->index,
+                                                      &entry, &name,
                                                       0, pathspec);
                        strbuf_setlen(&name, name_base_len);
 
index e8e51068bd903c01e12207637d59d80ea940bf2d..3e145fe5023638bc50c05f9d9dedfd6d11ae536d 100644 (file)
@@ -641,8 +641,9 @@ int cmd_show(int argc, const char **argv, const char *prefix)
                                        diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
                                        name,
                                        diff_get_color_opt(&rev.diffopt, DIFF_RESET));
-                       read_tree_recursive((struct tree *)o, "", 0, 0, &match_all,
-                                       show_tree_object, rev.diffopt.file);
+                       read_tree_recursive(the_repository, (struct tree *)o, "",
+                                           0, 0, &match_all, show_tree_object,
+                                           rev.diffopt.file);
                        rev.shown_one = 1;
                        break;
                case OBJ_COMMIT:
index c70a9c71588a76b2ef04689fc6cd805cee4ae0b8..7e0dcaa3599da68c62d05655e488467b7756409b 100644 (file)
@@ -441,7 +441,7 @@ void overlay_tree_on_index(struct index_state *istate,
                               PATHSPEC_PREFER_CWD, prefix, matchbuf);
        } else
                memset(&pathspec, 0, sizeof(pathspec));
-       if (read_tree(tree, 1, &pathspec, istate))
+       if (read_tree(the_repository, tree, 1, &pathspec, istate))
                die("unable to read tree entries %s", tree_name);
 
        for (i = 0; i < istate->cache_nr; i++) {
index 7d581d6463dc534606d27b1998c27991a800d6f1..7cad3f24ebd084fe653061f4f5899816853fc4f0 100644 (file)
@@ -185,5 +185,6 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
        tree = parse_tree_indirect(&oid);
        if (!tree)
                die("not a tree object");
-       return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
+       return !!read_tree_recursive(the_repository, tree, "", 0, 0,
+                                    &pathspec, show_tree, NULL);
 }
index c84c6e05e922f09692b9b133cd391b850c7951df..0b07263415785e11c7fc5b1a6da40a25e969b73c 100644 (file)
@@ -26,7 +26,7 @@ int cmd_merge_ours(int argc, const char **argv, const char *prefix)
         */
        if (read_cache() < 0)
                die_errno("read_cache failed");
-       if (index_differs_from("HEAD", NULL, 0))
+       if (index_differs_from(the_repository, "HEAD", NULL, 0))
                exit(2);
        exit(0);
 }
index 70f6fc916765c5a5ca67c2dfe72e0480128182e3..4984b7e12e90aab356606e6e7d3e6526f31c8c73 100644 (file)
@@ -346,7 +346,7 @@ static void merge_trees(struct tree_desc t[3], const char *base)
 
        setup_traverse_info(&info, base);
        info.fn = threeway_callback;
-       traverse_trees(3, t, &info);
+       traverse_trees(&the_index, 3, t, &info);
 }
 
 static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
index c3c976d471ce78268e673a5135a4c37ebc6d0f6d..dc0b7cc521c26f4c0ef1c6440d17c0f35ac1c983 100644 (file)
@@ -128,7 +128,7 @@ static int option_read_message(struct parse_opt_ctx_t *ctx,
                ctx->argc--;
                arg = *++ctx->argv;
        } else
-               return opterror(opt, "requires a value", 0);
+               return error(_("option `%s' requires a value"), opt->long_name);
 
        if (buf->len)
                strbuf_addch(buf, '\n');
@@ -578,7 +578,7 @@ static void parse_branch_merge_options(char *bmo)
        argc = split_cmdline(bmo, &argv);
        if (argc < 0)
                die(_("Bad branch.%s.mergeoptions string: %s"), branch,
-                   split_cmdline_strerror(argc));
+                   _(split_cmdline_strerror(argc)));
        REALLOC_ARRAY(argv, argc + 2);
        MOVE_ARRAY(argv + 1, argv, argc + 1);
        argc++;
@@ -897,7 +897,7 @@ static int suggest_conflicts(void)
        filename = git_path_merge_msg(the_repository);
        fp = xfopen(filename, "a");
 
-       append_conflicts_hint(&msgbuf);
+       append_conflicts_hint(&the_index, &msgbuf);
        fputs(msgbuf.buf, fp);
        strbuf_release(&msgbuf);
        fclose(fp);
index c78b7a0c5b7fbea81320ae9873553c437d82e73e..4996a670f71333de09e1a0311fde85d6985c9c91 100644 (file)
@@ -813,7 +813,7 @@ static int merge(int argc, const char **argv, const char *prefix)
                usage_with_options(git_notes_merge_usage, options);
        }
 
-       init_notes_merge_options(&o);
+       init_notes_merge_options(the_repository, &o);
        o.verbosity = verbosity + NOTES_MERGE_VERBOSITY_DEFAULT;
 
        if (do_abort)
index 411aefd6875b2d35ee4a12d1a043ba50027021b3..889df2c755176b60fc5c22b0ae553ced23629dc2 100644 (file)
@@ -2610,7 +2610,7 @@ static void prepare_pack(int window, int depth)
        unsigned n;
 
        if (use_delta_islands)
-               resolve_tree_islands(progress, &to_pack);
+               resolve_tree_islands(the_repository, progress, &to_pack);
 
        get_object_details();
 
@@ -3084,14 +3084,16 @@ static void record_recent_commit(struct commit *commit, void *data)
 static void get_object_list(int ac, const char **av)
 {
        struct rev_info revs;
+       struct setup_revision_opt s_r_opt = {
+               .allow_exclude_promisor_objects = 1,
+       };
        char line[1000];
        int flags = 0;
        int save_warning;
 
        repo_init_revisions(the_repository, &revs, NULL);
        save_commit_buffer = 0;
-       revs.allow_exclude_promisor_objects_opt = 1;
-       setup_revisions(ac, av, &revs, NULL);
+       setup_revisions(ac, av, &revs, &s_r_opt);
 
        /* make sure shallows are read */
        is_repository_shallow(the_repository);
@@ -3131,7 +3133,7 @@ static void get_object_list(int ac, const char **av)
                return;
 
        if (use_delta_islands)
-               load_delta_islands();
+               load_delta_islands(the_repository);
 
        if (prepare_revision_walk(&revs))
                die(_("revision walk setup failed"));
@@ -3470,7 +3472,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                }
        }
 
-       prepare_packing_data(&to_pack);
+       prepare_packing_data(the_repository, &to_pack);
 
        if (progress)
                progress_state = start_progress(_("Enumerating objects"), 0);
index e42653b99cffe2f42f2fb853999a41465878ce02..1ec9ddd751df6644d2c39ace41a1494800082638 100644 (file)
@@ -120,7 +120,6 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
        save_commit_buffer = 0;
        read_replace_refs = 0;
        ref_paranoia = 1;
-       revs.allow_exclude_promisor_objects_opt = 1;
        repo_init_revisions(the_repository, &revs, prefix);
 
        argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
index 1b90622b1311187612ef8b33995c92a6802eb343..74808b94554a78e720128a721f21dc0d20dd839e 100644 (file)
@@ -899,7 +899,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                        die(_("Updating an unborn branch with changes added to the index."));
 
                if (!autostash)
-                       require_clean_work_tree(N_("pull with rebase"),
+                       require_clean_work_tree(the_repository,
+                               N_("pull with rebase"),
                                _("please commit or stash them."), 1, 0);
 
                if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))
index 8bb8a0849ba90aff5d295acc3894b2034cbbdef2..021dd3b1e48979086de68a434d4eddbbeb074df3 100644 (file)
@@ -143,7 +143,9 @@ static int push_url_of_remote(struct remote *remote, const char ***url_p)
        return remote->url_nr;
 }
 
-static NORETURN int die_push_simple(struct branch *branch, struct remote *remote) {
+static NORETURN int die_push_simple(struct branch *branch,
+                                   struct remote *remote)
+{
        /*
         * There's no point in using shorten_unambiguous_ref here,
         * as the ambiguity would be on the remote side, not what
@@ -355,7 +357,8 @@ static int push_with_options(struct transport *transport, struct refspec *rs,
 
        if (verbosity > 0)
                fprintf(stderr, _("Pushing to %s\n"), transport->url);
-       err = transport_push(transport, rs, flags, &reject_reasons);
+       err = transport_push(the_repository, transport,
+                            rs, flags, &reject_reasons);
        if (err != 0) {
                fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
                error(_("failed to push some refs to '%s'"), transport->url);
index 183ee8c1e5d4de53d10e9ed00c624f615baf3fc9..ac255ad2c243192a9afd3b4578a2a501eb250aff 100644 (file)
@@ -258,7 +258,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
         * what came from the tree.
         */
        if (nr_trees == 1 && !opts.prefix)
-               prime_cache_tree(&the_index, trees[0]);
+               prime_cache_tree(the_repository,
+                                the_repository->index,
+                                trees[0]);
 
        if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                die("unable to write new index file");
index a2ab68ed063224be123a3f5e8831afdc3ed649a0..dd2a55ab1d956ef0937cfdb0e4e3fb026ac2ff81 100644 (file)
@@ -105,7 +105,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
        if (restrict_revision)
                argv_array_push(&make_script_args, restrict_revision);
 
-       ret = sequencer_make_script(todo_list,
+       ret = sequencer_make_script(the_repository, todo_list,
                                    make_script_args.argc, make_script_args.argv,
                                    flags);
        fclose(todo_list);
@@ -114,7 +114,8 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
                error(_("could not generate todo list"));
        else {
                discard_cache();
-               ret = complete_action(opts, flags, shortrevisions, onto_name, onto,
+               ret = complete_action(the_repository, opts, flags,
+                                     shortrevisions, onto_name, onto,
                                      head_hash, cmd, autosquash);
        }
 
@@ -232,14 +233,14 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
        case SKIP: {
                struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-               rerere_clear(&merge_rr);
+               rerere_clear(the_repository, &merge_rr);
                /* fallthrough */
        case CONTINUE:
-               ret = sequencer_continue(&opts);
+               ret = sequencer_continue(the_repository, &opts);
                break;
        }
        case EDIT_TODO:
-               ret = edit_todo_list(flags);
+               ret = edit_todo_list(the_repository, flags);
                break;
        case SHOW_CURRENT_PATCH: {
                struct child_process cmd = CHILD_PROCESS_INIT;
@@ -252,16 +253,16 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
        }
        case SHORTEN_OIDS:
        case EXPAND_OIDS:
-               ret = transform_todos(flags);
+               ret = transform_todos(the_repository, flags);
                break;
        case CHECK_TODO_LIST:
-               ret = check_todo_list();
+               ret = check_todo_list(the_repository);
                break;
        case REARRANGE_SQUASH:
-               ret = rearrange_squash();
+               ret = rearrange_squash(the_repository);
                break;
        case ADD_EXEC:
-               ret = sequencer_add_exec_commands(cmd);
+               ret = sequencer_add_exec_commands(the_repository, cmd);
                break;
        default:
                BUG("invalid command '%d'", command);
index b5c99ec10c200a5fccb293c0acadae80642f2808..00de70365ed41167c18e3233106e89d082370b6a 100644 (file)
@@ -598,7 +598,7 @@ static int reset_head(struct object_id *oid, const char *action,
        }
 
        tree = parse_tree_indirect(oid);
-       prime_cache_tree(the_repository->index, tree);
+       prime_cache_tree(the_repository, the_repository->index, tree);
 
        if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0) {
                ret = error(_("could not write index"));
@@ -1024,7 +1024,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                                             &lock_file);
                rollback_lock_file(&lock_file);
 
-               if (has_unstaged_changes(1)) {
+               if (has_unstaged_changes(the_repository, 1)) {
                        puts(_("You must edit all merge conflicts and then\n"
                               "mark them as resolved using git add"));
                        exit(1);
@@ -1039,13 +1039,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                options.action = "skip";
                set_reflog_action(&options);
 
-               rerere_clear(&merge_rr);
+               rerere_clear(the_repository, &merge_rr);
                string_list_clear(&merge_rr, 1);
 
                if (reset_head(NULL, "reset", NULL, RESET_HEAD_HARD,
                               NULL, NULL) < 0)
                        die(_("could not discard worktree changes"));
-               remove_branch_state();
+               remove_branch_state(the_repository);
                if (read_basic_state(&options))
                        exit(1);
                goto run_rebase;
@@ -1055,7 +1055,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                options.action = "abort";
                set_reflog_action(&options);
 
-               rerere_clear(&merge_rr);
+               rerere_clear(the_repository, &merge_rr);
                string_list_clear(&merge_rr, 1);
 
                if (read_basic_state(&options))
@@ -1065,7 +1065,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                               NULL, NULL) < 0)
                        die(_("could not move back to %s"),
                            oid_to_hex(&options.orig_head));
-               remove_branch_state();
+               remove_branch_state(the_repository);
                ret = finish_rebase(&options);
                goto cleanup;
        }
@@ -1381,7 +1381,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                        update_index_if_able(&the_index, &lock_file);
                rollback_lock_file(&lock_file);
 
-               if (has_unstaged_changes(1) || has_uncommitted_changes(1)) {
+               if (has_unstaged_changes(the_repository, 1) ||
+                   has_uncommitted_changes(the_repository, 1)) {
                        const char *autostash =
                                state_dir_path("autostash", &options);
                        struct child_process stash = CHILD_PROCESS_INIT;
@@ -1427,7 +1428,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                }
        }
 
-       if (require_clean_work_tree("rebase",
+       if (require_clean_work_tree(the_repository, "rebase",
                                    _("Please commit or stash them."), 1, 1)) {
                ret = 1;
                goto cleanup;
index 7a85e4b1640b12d4c8f7958cb59b66e037fd2ce2..64a8df4f252f598ff835c39ce8a3d3d417e8a31e 100644 (file)
 
 /* NEEDSWORK: switch to using parse_options */
 static const char reflog_expire_usage[] =
-"git reflog expire [--expire=<time>] [--expire-unreachable=<time>] [--rewrite] [--updateref] [--stale-fix] [--dry-run | -n] [--verbose] [--all] <refs>...";
+N_("git reflog expire [--expire=<time>] "
+   "[--expire-unreachable=<time>] "
+   "[--rewrite] [--updateref] [--stale-fix] [--dry-run | -n] "
+   "[--verbose] [--all] <refs>...");
 static const char reflog_delete_usage[] =
-"git reflog delete [--rewrite] [--updateref] [--dry-run | -n] [--verbose] <refs>...";
+N_("git reflog delete [--rewrite] [--updateref] "
+   "[--dry-run | -n] [--verbose] <refs>...");
 static const char reflog_exists_usage[] =
-"git reflog exists <ref>";
+N_("git reflog exists <ref>");
 
 static timestamp_t default_reflog_expire;
 static timestamp_t default_reflog_expire_unreachable;
@@ -585,7 +589,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
                        break;
                }
                else if (arg[0] == '-')
-                       usage(reflog_expire_usage);
+                       usage(_(reflog_expire_usage));
                else
                        break;
        }
@@ -598,7 +602,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
        if (cb.cmd.stalefix) {
                repo_init_revisions(the_repository, &cb.cmd.revs, prefix);
                if (flags & EXPIRE_REFLOGS_VERBOSE)
-                       printf("Marking reachable objects...");
+                       printf(_("Marking reachable objects..."));
                mark_reachable_objects(&cb.cmd.revs, 0, 0, NULL);
                if (flags & EXPIRE_REFLOGS_VERBOSE)
                        putchar('\n');
@@ -636,7 +640,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
                char *ref;
                struct object_id oid;
                if (!dwim_log(argv[i], strlen(argv[i]), &oid, &ref)) {
-                       status |= error("%s points nowhere!", argv[i]);
+                       status |= error(_("%s points nowhere!"), argv[i]);
                        continue;
                }
                set_reflog_expiry_param(&cb.cmd, explicit_expiry, ref);
@@ -682,13 +686,13 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
                        break;
                }
                else if (arg[0] == '-')
-                       usage(reflog_delete_usage);
+                       usage(_(reflog_delete_usage));
                else
                        break;
        }
 
        if (argc - i < 1)
-               return error("Nothing to delete?");
+               return error(_("no reflog specified to delete"));
 
        for ( ; i < argc; i++) {
                const char *spec = strstr(argv[i], "@{");
@@ -697,12 +701,12 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
                int recno;
 
                if (!spec) {
-                       status |= error("Not a reflog: %s", argv[i]);
+                       status |= error(_("not a reflog: %s"), argv[i]);
                        continue;
                }
 
                if (!dwim_log(argv[i], spec - argv[i], &oid, &ref)) {
-                       status |= error("no reflog for '%s'", argv[i]);
+                       status |= error(_("no reflog for '%s'"), argv[i]);
                        continue;
                }
 
@@ -737,7 +741,7 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)
                        break;
                }
                else if (arg[0] == '-')
-                       usage(reflog_exists_usage);
+                       usage(_(reflog_exists_usage));
                else
                        break;
        }
@@ -745,10 +749,10 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)
        start = i;
 
        if (argc - start != 1)
-               usage(reflog_exists_usage);
+               usage(_(reflog_exists_usage));
 
        if (check_refname_format(argv[start], REFNAME_ALLOW_ONELEVEL))
-               die("invalid ref format: %s", argv[start]);
+               die(_("invalid ref format: %s"), argv[start]);
        return !reflog_exists(argv[start]);
 }
 
@@ -757,12 +761,12 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)
  */
 
 static const char reflog_usage[] =
-"git reflog [ show | expire | delete | exists ]";
+N_("git reflog [ show | expire | delete | exists ]");
 
 int cmd_reflog(int argc, const char **argv, const char *prefix)
 {
        if (argc > 1 && !strcmp(argv[1], "-h"))
-               usage(reflog_usage);
+               usage(_(reflog_usage));
 
        /* With no command, we default to showing it. */
        if (argc < 2 || *argv[1] == '-')
index 45583683eef4d59d1c8b957a8d9a8c0834db0e48..2a1c7b21c5d9cb52c328105b470366d1c7ef7c76 100644 (file)
@@ -197,7 +197,7 @@ static int write_oid(const struct object_id *oid, struct packed_git *pack,
 
        if (cmd->in == -1) {
                if (start_command(cmd))
-                       die("Could not start pack-objects to repack promisor objects");
+                       die(_("could not start pack-objects to repack promisor objects"));
        }
 
        xwrite(cmd->in, oid_to_hex(oid), GIT_SHA1_HEXSZ);
@@ -236,7 +236,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
                char *promisor_name;
                int fd;
                if (line.len != the_hash_algo->hexsz)
-                       die("repack: Expecting full hex object ID lines only from pack-objects.");
+                       die(_("repack: Expecting full hex object ID lines only from pack-objects."));
                string_list_append(names, line.buf);
 
                /*
@@ -247,13 +247,13 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
                                          line.buf);
                fd = open(promisor_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
                if (fd < 0)
-                       die_errno("unable to create '%s'", promisor_name);
+                       die_errno(_("unable to create '%s'"), promisor_name);
                close(fd);
                free(promisor_name);
        }
        fclose(out);
        if (finish_command(&cmd))
-               die("Could not finish pack-objects to repack promisor objects");
+               die(_("could not finish pack-objects to repack promisor objects"));
 }
 
 #define ALL_INTO_ONE 1
@@ -408,7 +408,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        out = xfdopen(cmd.out, "r");
        while (strbuf_getline_lf(&line, out) != EOF) {
                if (line.len != the_hash_algo->hexsz)
-                       die("repack: Expecting full hex object ID lines only from pack-objects.");
+                       die(_("repack: Expecting full hex object ID lines only from pack-objects."));
                string_list_append(&names, line.buf);
        }
        fclose(out);
@@ -417,7 +417,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                return ret;
 
        if (!names.nr && !po_args.quiet)
-               printf("Nothing new to pack.\n");
+               printf_ln(_("Nothing new to pack."));
 
        /*
         * Ok we have prepared all new packfiles.
@@ -476,13 +476,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                if (rollback_failure.nr) {
                        int i;
                        fprintf(stderr,
-                               "WARNING: Some packs in use have been renamed by\n"
-                               "WARNING: prefixing old- to their name, in order to\n"
-                               "WARNING: replace them with the new version of the\n"
-                               "WARNING: file.  But the operation failed, and the\n"
-                               "WARNING: attempt to rename them back to their\n"
-                               "WARNING: original names also failed.\n"
-                               "WARNING: Please rename them in %s manually:\n", packdir);
+                               _("WARNING: Some packs in use have been renamed by\n"
+                                 "WARNING: prefixing old- to their name, in order to\n"
+                                 "WARNING: replace them with the new version of the\n"
+                                 "WARNING: file.  But the operation failed, and the\n"
+                                 "WARNING: attempt to rename them back to their\n"
+                                 "WARNING: original names also failed.\n"
+                                 "WARNING: Please rename them in %s manually:\n"), packdir);
                        for (i = 0; i < rollback_failure.nr; i++)
                                fprintf(stderr, "WARNING:   old-%s -> %s\n",
                                        rollback_failure.items[i].string,
index d78eeaed329e5c647e5474b6a4205194b539f4b4..fd3be17b976c7d2f413b4e760236c2274f1e7639 100644 (file)
@@ -83,11 +83,12 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
        }
 
        if (!strcmp(argv[0], "clear")) {
-               rerere_clear(&merge_rr);
+               rerere_clear(the_repository, &merge_rr);
        } else if (!strcmp(argv[0], "gc"))
-               rerere_gc(&merge_rr);
+               rerere_gc(the_repository, &merge_rr);
        else if (!strcmp(argv[0], "status")) {
-               if (setup_rerere(&merge_rr, flags | RERERE_READONLY) < 0)
+               if (setup_rerere(the_repository, &merge_rr,
+                                flags | RERERE_READONLY) < 0)
                        return 0;
                for (i = 0; i < merge_rr.nr; i++)
                        printf("%s\n", merge_rr.items[i].string);
@@ -102,7 +103,8 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
                                merge_rr.items[i].util = NULL;
                }
        } else if (!strcmp(argv[0], "diff")) {
-               if (setup_rerere(&merge_rr, flags | RERERE_READONLY) < 0)
+               if (setup_rerere(the_repository, &merge_rr,
+                                flags | RERERE_READONLY) < 0)
                        return 0;
                for (i = 0; i < merge_rr.nr; i++) {
                        const char *path = merge_rr.items[i].string;
index 58166964f84ce1b78f703bb10f92f713b2cce6b4..59898c972eee5e8065c2a68b7c937cc3af11f513 100644 (file)
@@ -95,7 +95,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
 
        if (reset_type == MIXED || reset_type == HARD) {
                tree = parse_tree_indirect(oid);
-               prime_cache_tree(&the_index, tree);
+               prime_cache_tree(the_repository, the_repository->index, tree);
        }
 
        ret = 0;
@@ -413,7 +413,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                        print_new_head_line(lookup_commit_reference(the_repository, &oid));
        }
        if (!pathspec.nr)
-               remove_branch_state();
+               remove_branch_state(the_repository);
 
        return update_ref_status;
 }
index 2880ed37e3f97193d2374657346b4de52bc44954..51e9e1267e848b345ff7c78fe036e7e66bb6f055 100644 (file)
@@ -361,6 +361,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 {
        struct rev_info revs;
        struct rev_list_info info;
+       struct setup_revision_opt s_r_opt = {
+               .allow_exclude_promisor_objects = 1,
+       };
        int i;
        int bisect_list = 0;
        int bisect_show_vars = 0;
@@ -374,7 +377,6 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
        git_config(git_default_config, NULL);
        repo_init_revisions(the_repository, &revs, prefix);
        revs.abbrev = DEFAULT_ABBREV;
-       revs.allow_exclude_promisor_objects_opt = 1;
        revs.commit_format = CMIT_FMT_UNSPECIFIED;
        revs.do_not_die_on_missing_tree = 1;
 
@@ -406,7 +408,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
                }
        }
 
-       argc = setup_revisions(argc, argv, &revs, NULL);
+       argc = setup_revisions(argc, argv, &revs, &s_r_opt);
 
        memset(&info, 0, sizeof(info));
        info.revs = &revs;
index c93393c89be0290ebd9e300046ff56a2ee441715..a47b53ceaff92d4079b4ea73a61ce1552ad66b05 100644 (file)
@@ -69,7 +69,8 @@ static int option_parse_m(const struct option *opt,
 
        replay->mainline = strtol(arg, &end, 10);
        if (*end || replay->mainline <= 0)
-               return opterror(opt, "expects a number greater than zero", 0);
+               return error(_("option `%s' expects a number greater than zero"),
+                            opt->long_name);
 
        return 0;
 }
@@ -195,14 +196,14 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
        if (cmd == 'q') {
                int ret = sequencer_remove_state(opts);
                if (!ret)
-                       remove_branch_state();
+                       remove_branch_state(the_repository);
                return ret;
        }
        if (cmd == 'c')
-               return sequencer_continue(opts);
+               return sequencer_continue(the_repository, opts);
        if (cmd == 'a')
-               return sequencer_rollback(opts);
-       return sequencer_pick_revisions(opts);
+               return sequencer_rollback(the_repository, opts);
+       return sequencer_pick_revisions(the_repository, opts);
 }
 
 int cmd_revert(int argc, const char **argv, const char *prefix)
index 88f88e97b28c24f74aad6ec6cf1c637003f41a85..65cd41392c1c5e256313b10812a39bf4b848ce1b 100644 (file)
@@ -287,6 +287,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
                case PARSE_OPT_HELP:
                case PARSE_OPT_ERROR:
                        exit(129);
+               case PARSE_OPT_COMPLETE:
+                       exit(0);
                case PARSE_OPT_DONE:
                        goto parse_done;
                }
index bdf032886912bb768cf3528efbffab4fe3029a58..be33eb83c1b72664dffc17ddffd09f79b57a2887 100644 (file)
@@ -30,6 +30,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
 {
        struct strbuf buf = STRBUF_INIT;
        enum stripspace_mode mode = STRIP_DEFAULT;
+       int nongit;
 
        const struct option options[] = {
                OPT_CMDMODE('s', "strip-comments", &mode,
@@ -46,7 +47,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
                usage_with_options(stripspace_usage, options);
 
        if (mode == STRIP_COMMENTS || mode == COMMENT_LINES) {
-               setup_git_directory_gently(NULL);
+               setup_git_directory_gently(&nongit);
                git_config(git_default_config, NULL);
        }
 
index d38113a31aeb3838190b7339475c7454e45f3a89..6881b6a9cb0fa1cd44118663cd8d7c8eaef1c95a 100644 (file)
@@ -1131,6 +1131,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);
        }
 
@@ -1265,19 +1267,20 @@ struct submodule_alternate_setup {
        SUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }
 
 static int add_possible_reference_from_superproject(
-               struct alternate_object_database *alt, void *sas_cb)
+               struct object_directory *odb, void *sas_cb)
 {
        struct submodule_alternate_setup *sas = sas_cb;
+       size_t len;
 
        /*
         * If the alternate object store is another repository, try the
         * standard layout with .git/(modules/<name>)+/objects
         */
-       if (ends_with(alt->path, "/objects")) {
+       if (strip_suffix(odb->path, "/objects", &len)) {
                char *sm_alternate;
                struct strbuf sb = STRBUF_INIT;
                struct strbuf err = STRBUF_INIT;
-               strbuf_add(&sb, alt->path, strlen(alt->path) - strlen("objects"));
+               strbuf_add(&sb, odb->path, len);
 
                /*
                 * We need to end the new path with '/' to mark it as a dir,
@@ -1285,7 +1288,7 @@ static int add_possible_reference_from_superproject(
                 * as the last part of a missing submodule reference would
                 * be taken as a file name.
                 */
-               strbuf_addf(&sb, "modules/%s/", sas->submodule_name);
+               strbuf_addf(&sb, "/modules/%s/", sas->submodule_name);
 
                sm_alternate = compute_alternate_path(sb.buf, &err);
                if (sm_alternate) {
@@ -1551,7 +1554,7 @@ struct submodule_update_clone {
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
        SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
        NULL, NULL, NULL, \
-       NULL, 0, 0, 0, NULL, 0, 0, 0}
+       NULL, 0, 0, 0, NULL, 0, 0, 1}
 
 
 static void next_submodule_warn_missing(struct submodule_update_clone *suc,
@@ -2045,7 +2048,7 @@ static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
        struct repository subrepo;
 
        if (argc != 2)
-               BUG("submodule--helper connect-gitdir-workingtree <name> <path>");
+               BUG("submodule--helper ensure-core-worktree <path>");
 
        path = argv[1];
 
index 31e7cce3013a3b3f358834f24848fc73b67f8e8b..e19da77edcaa024cc2bffc6fa8818c2b1cf0d4b6 100644 (file)
@@ -1086,6 +1086,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                case PARSE_OPT_HELP:
                case PARSE_OPT_ERROR:
                        exit(129);
+               case PARSE_OPT_COMPLETE:
+                       exit(0);
                case PARSE_OPT_NON_OPTION:
                case PARSE_OPT_DONE:
                {
index 5e8402617727f9cf9c017df3ea6c576e2d59240d..3f9907fcc994d248ba604509f6feb5bdc0499329 100644 (file)
@@ -9,6 +9,7 @@
 #include "refs.h"
 #include "run-command.h"
 #include "sigchain.h"
+#include "submodule.h"
 #include "refs.h"
 #include "utf8.h"
 #include "worktree.h"
@@ -724,20 +725,36 @@ static int unlock_worktree(int ac, const char **av, const char *prefix)
 static void validate_no_submodules(const struct worktree *wt)
 {
        struct index_state istate = { NULL };
+       struct strbuf path = STRBUF_INIT;
        int i, found_submodules = 0;
 
-       if (read_index_from(&istate, worktree_git_path(wt, "index"),
-                           get_worktree_git_dir(wt)) > 0) {
+       if (is_directory(worktree_git_path(wt, "modules"))) {
+               /*
+                * There could be false positives, e.g. the "modules"
+                * directory exists but is empty. But it's a rare case and
+                * this simpler check is probably good enough for now.
+                */
+               found_submodules = 1;
+       } else if (read_index_from(&istate, worktree_git_path(wt, "index"),
+                                  get_worktree_git_dir(wt)) > 0) {
                for (i = 0; i < istate.cache_nr; i++) {
                        struct cache_entry *ce = istate.cache[i];
+                       int err;
 
-                       if (S_ISGITLINK(ce->ce_mode)) {
-                               found_submodules = 1;
-                               break;
-                       }
+                       if (!S_ISGITLINK(ce->ce_mode))
+                               continue;
+
+                       strbuf_reset(&path);
+                       strbuf_addf(&path, "%s/%s", wt->path, ce->name);
+                       if (!is_submodule_populated_gently(path.buf, &err))
+                               continue;
+
+                       found_submodules = 1;
+                       break;
                }
        }
        discard_index(&istate);
+       strbuf_release(&path);
 
        if (found_submodules)
                die(_("working trees containing submodules cannot be moved or removed"));
index 88c3e16d86162518ddde771703a3d2b0fc622f3b..37b1daa6918bafb6b21faba47d25fcc6433698ba 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -127,7 +127,9 @@ static int list_refs(struct ref_list *r, int argc, const char **argv)
 /* Remember to update object flag allocation in object.h */
 #define PREREQ_MARK (1u<<16)
 
-int verify_bundle(struct bundle_header *header, int verbose)
+int verify_bundle(struct repository *r,
+                 struct bundle_header *header,
+                 int verbose)
 {
        /*
         * Do fast check, then if any prereqs are missing then go line by line
@@ -140,10 +142,10 @@ int verify_bundle(struct bundle_header *header, int verbose)
        int i, ret = 0, req_nr;
        const char *message = _("Repository lacks these prerequisite commits:");
 
-       repo_init_revisions(the_repository, &revs, NULL);
+       repo_init_revisions(r, &revs, NULL);
        for (i = 0; i < p->nr; i++) {
                struct ref_list_entry *e = p->list + i;
-               struct object *o = parse_object(the_repository, &e->oid);
+               struct object *o = parse_object(r, &e->oid);
                if (o) {
                        o->flags |= PREREQ_MARK;
                        add_pending_object(&revs, o, e->name);
@@ -168,7 +170,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(the_repository, &e->oid);
+               struct object *o = parse_object(r, &e->oid);
                assert(o); /* otherwise we'd have returned early */
                if (o->flags & SHOWN)
                        continue;
@@ -180,7 +182,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(the_repository, &e->oid, 1);
+               commit = lookup_commit_reference_gently(r, &e->oid, 1);
                if (commit)
                        clear_commit_marks(commit, ALL_REV_FLAGS);
        }
@@ -389,8 +391,7 @@ 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(the_repository,
-                                                                    &oid);
+                       struct commit *one = lookup_commit_reference(revs->repo, &oid);
                        struct object *obj;
 
                        if (e->item == &(one->object)) {
@@ -423,8 +424,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
        return ref_count;
 }
 
-int create_bundle(struct bundle_header *header, const char *path,
-                 int argc, const char **argv)
+int create_bundle(struct repository *r, struct bundle_header *header,
+                 const char *path, int argc, const char **argv)
 {
        struct lock_file lock = LOCK_INIT;
        int bundle_fd = -1;
@@ -444,7 +445,7 @@ int create_bundle(struct bundle_header *header, const char *path,
 
        /* init revs to list objects for pack-objects later */
        save_commit_buffer = 0;
-       repo_init_revisions(the_repository, &revs, NULL);
+       repo_init_revisions(r, &revs, NULL);
 
        /* write prerequisites */
        if (compute_and_write_prerequisites(bundle_fd, &revs, argc, argv))
@@ -479,7 +480,8 @@ int create_bundle(struct bundle_header *header, const char *path,
        return -1;
 }
 
-int unbundle(struct bundle_header *header, int bundle_fd, int flags)
+int unbundle(struct repository *r, struct bundle_header *header,
+            int bundle_fd, int flags)
 {
        const char *argv_index_pack[] = {"index-pack",
                                         "--fix-thin", "--stdin", NULL, NULL};
@@ -488,7 +490,7 @@ int unbundle(struct bundle_header *header, int bundle_fd, int flags)
        if (flags & BUNDLE_VERBOSE)
                argv_index_pack[3] = "-v";
 
-       if (verify_bundle(header, 0))
+       if (verify_bundle(r, header, 0))
                return -1;
        ip.argv = argv_index_pack;
        ip.in = bundle_fd;
index e9a4cb6a74335cfd8972b19340b38e2210061a6d..781e6f5c3a837ac65e6911ec5e0ae458b8b6a5c7 100644 (file)
--- a/bundle.h
+++ b/bundle.h
@@ -18,11 +18,12 @@ struct bundle_header {
 
 int is_bundle(const char *path, int quiet);
 int read_bundle_header(const char *path, struct bundle_header *header);
-int create_bundle(struct bundle_header *header, const char *path,
-               int argc, const char **argv);
-int verify_bundle(struct bundle_header *header, int verbose);
+int create_bundle(struct repository *r, struct bundle_header *header,
+                 const char *path, int argc, const char **argv);
+int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
 #define BUNDLE_VERBOSE 1
-int unbundle(struct bundle_header *header, int bundle_fd, int flags);
+int unbundle(struct repository *r, struct bundle_header *header,
+            int bundle_fd, int flags);
 int list_bundle_refs(struct bundle_header *header,
                int argc, const char **argv);
 
index 9d454d24bca62dcdb8c941a64d09b7a53556323a..eabb8fb6546cbb5e418f30a4e9329d635520d601 100644 (file)
@@ -448,7 +448,7 @@ int cache_tree_update(struct index_state *istate, int flags)
 }
 
 static void write_one(struct strbuf *buffer, struct cache_tree *it,
-                      const char *path, int pathlen)
+                     const char *path, int pathlen)
 {
        int i;
 
@@ -659,7 +659,9 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state,
        return ret;
 }
 
-static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
+static void prime_cache_tree_rec(struct repository *r,
+                                struct cache_tree *it,
+                                struct tree *tree)
 {
        struct tree_desc desc;
        struct name_entry entry;
@@ -673,24 +675,25 @@ 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(the_repository,
-                                                          entry.oid);
+                       struct tree *subtree = lookup_tree(r, entry.oid);
                        if (!subtree->object.parsed)
                                parse_tree(subtree);
                        sub = cache_tree_sub(it, entry.path);
                        sub->cache_tree = cache_tree();
-                       prime_cache_tree_rec(sub->cache_tree, subtree);
+                       prime_cache_tree_rec(r, sub->cache_tree, subtree);
                        cnt += sub->cache_tree->entry_count;
                }
        }
        it->entry_count = cnt;
 }
 
-void prime_cache_tree(struct index_state *istate, struct tree *tree)
+void prime_cache_tree(struct repository *r,
+                     struct index_state *istate,
+                     struct tree *tree)
 {
        cache_tree_free(&istate->cache_tree);
        istate->cache_tree = cache_tree();
-       prime_cache_tree_rec(istate->cache_tree, tree);
+       prime_cache_tree_rec(r, istate->cache_tree, tree);
        istate->cache_changed |= CACHE_TREE_CHANGED;
 }
 
@@ -726,7 +729,8 @@ int cache_tree_matches_traversal(struct cache_tree *root,
        return 0;
 }
 
-static void verify_one(struct index_state *istate,
+static void verify_one(struct repository *r,
+                      struct index_state *istate,
                       struct cache_tree *it,
                       struct strbuf *path)
 {
@@ -736,13 +740,13 @@ static void verify_one(struct index_state *istate,
 
        for (i = 0; i < it->subtree_nr; i++) {
                strbuf_addf(path, "%s/", it->down[i]->name);
-               verify_one(istate, it->down[i]->cache_tree, path);
+               verify_one(r, istate, it->down[i]->cache_tree, path);
                strbuf_setlen(path, len);
        }
 
        if (it->entry_count < 0 ||
            /* no verification on tests (t7003) that replace trees */
-           lookup_replace_object(the_repository, &it->oid) != &it->oid)
+           lookup_replace_object(r, &it->oid) != &it->oid)
                return;
 
        if (path->len) {
@@ -793,12 +797,12 @@ static void verify_one(struct index_state *istate,
        strbuf_release(&tree_buf);
 }
 
-void cache_tree_verify(struct index_state *istate)
+void cache_tree_verify(struct repository *r, struct index_state *istate)
 {
        struct strbuf path = STRBUF_INIT;
 
        if (!istate->cache_tree)
                return;
-       verify_one(istate, istate->cache_tree, &path);
+       verify_one(r, istate, istate->cache_tree, &path);
        strbuf_release(&path);
 }
index 0ab6784ffea5da0581c905738aaa66215266b5f9..326209198b60fa8a6fdbd171c46132b8a5062e04 100644 (file)
@@ -32,7 +32,7 @@ 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);
-void cache_tree_verify(struct index_state *);
+void cache_tree_verify(struct repository *, struct index_state *);
 
 /* bitmasks to write_cache_as_tree flags */
 #define WRITE_TREE_MISSING_OK 1
@@ -47,7 +47,7 @@ void cache_tree_verify(struct index_state *);
 #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);
-void prime_cache_tree(struct index_state *, struct tree *);
+void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
 
 int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
 
diff --git a/cache.h b/cache.h
index ca36b44ee0b5851f837616c322a201ac420a90d2..49713cc5a5a61bf0749e596b94474f00286dc652 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1539,9 +1539,9 @@ struct checkout {
 #define CHECKOUT_INIT { NULL, "" }
 
 #define TEMPORARY_FILENAME_LENGTH 25
-extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
+extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath, int *nr_checkouts);
 extern void enable_delayed_checkout(struct checkout *state);
-extern int finish_delayed_checkout(struct checkout *state);
+extern int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);
 
 struct cache_def {
        struct strbuf path;
index ad7752ea6b7e3173066e346b7dd314e7707f7d8c..a143c006341170fad8c42604eca8f9bbf3226de8 100644 (file)
@@ -996,7 +996,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
        if (!userdiff)
                userdiff = userdiff_find_by_name("default");
        if (opt->flags.allow_textconv)
-               textconv = userdiff_get_textconv(userdiff);
+               textconv = userdiff_get_textconv(opt->repo, userdiff);
 
        /* Read the result of merge first */
        if (!working_tree_file)
index 40c855f1855595fbf5b285008d3c829e6a2f41eb..0d6ba6da2d76fa3a5d43dae74fc1bb7b652c6df0 100644 (file)
@@ -34,7 +34,6 @@
 #define GRAPH_OID_LEN GRAPH_OID_LEN_SHA1
 
 #define GRAPH_OCTOPUS_EDGES_NEEDED 0x80000000
-#define GRAPH_PARENT_MISSING 0x7fffffff
 #define GRAPH_EDGE_LAST_MASK 0x7fffffff
 #define GRAPH_PARENT_NONE 0x70000000
 
@@ -230,8 +229,7 @@ static void prepare_commit_graph_one(struct repository *r, const char *obj_dir)
  */
 static int prepare_commit_graph(struct repository *r)
 {
-       struct alternate_object_database *alt;
-       char *obj_dir;
+       struct object_directory *odb;
        int config_value;
 
        if (r->objects->commit_graph_attempted)
@@ -252,13 +250,11 @@ static int prepare_commit_graph(struct repository *r)
        if (!commit_graph_compatible(r))
                return 0;
 
-       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(r, alt->path);
+       for (odb = r->objects->odb;
+            !r->objects->commit_graph && odb;
+            odb = odb->next)
+               prepare_commit_graph_one(r, odb->path);
        return !!r->objects->commit_graph;
 }
 
@@ -496,7 +492,9 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
                                              commit_to_sha1);
 
                        if (edge_value < 0)
-                               edge_value = GRAPH_PARENT_MISSING;
+                               BUG("missing parent %s for commit %s",
+                                   oid_to_hex(&parent->item->object.oid),
+                                   oid_to_hex(&(*list)->object.oid));
                }
 
                hashwrite_be32(f, edge_value);
@@ -514,7 +512,9 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
                                              nr_commits,
                                              commit_to_sha1);
                        if (edge_value < 0)
-                               edge_value = GRAPH_PARENT_MISSING;
+                               BUG("missing parent %s for commit %s",
+                                   oid_to_hex(&parent->item->object.oid),
+                                   oid_to_hex(&(*list)->object.oid));
                }
 
                hashwrite_be32(f, edge_value);
@@ -567,7 +567,9 @@ static void write_graph_chunk_large_edges(struct hashfile *f,
                                                  commit_to_sha1);
 
                        if (edge_value < 0)
-                               edge_value = GRAPH_PARENT_MISSING;
+                               BUG("missing parent %s for commit %s",
+                                   oid_to_hex(&parent->item->object.oid),
+                                   oid_to_hex(&(*list)->object.oid));
                        else if (!parent->next)
                                edge_value |= GRAPH_LAST_EDGE;
 
@@ -641,26 +643,29 @@ static void add_missing_parents(struct packed_oid_list *oids, struct commit *com
 
 static void close_reachable(struct packed_oid_list *oids, int report_progress)
 {
-       int i;
+       int i, j;
        struct commit *commit;
        struct progress *progress = NULL;
-       int j = 0;
 
        if (report_progress)
                progress = start_delayed_progress(
-                       _("Annotating commits in commit graph"), 0);
+                       _("Loading known commits in commit graph"), j = 0);
        for (i = 0; i < oids->nr; i++) {
                display_progress(progress, ++j);
                commit = lookup_commit(the_repository, &oids->list[i]);
                if (commit)
                        commit->object.flags |= UNINTERESTING;
        }
+       stop_progress(&progress);
 
        /*
         * As this loop runs, oids->nr may grow, but not more
         * than the number of missing commits in the reachable
         * closure.
         */
+       if (report_progress)
+               progress = start_delayed_progress(
+                       _("Expanding reachable commits in commit graph"), j = 0);
        for (i = 0; i < oids->nr; i++) {
                display_progress(progress, ++j);
                commit = lookup_commit(the_repository, &oids->list[i]);
@@ -668,7 +673,11 @@ static void close_reachable(struct packed_oid_list *oids, int report_progress)
                if (commit && !parse_commit(commit))
                        add_missing_parents(oids, commit);
        }
+       stop_progress(&progress);
 
+       if (report_progress)
+               progress = start_delayed_progress(
+                       _("Clearing commit marks in commit graph"), j = 0);
        for (i = 0; i < oids->nr; i++) {
                display_progress(progress, ++j);
                commit = lookup_commit(the_repository, &oids->list[i]);
@@ -864,7 +873,7 @@ void write_commit_graph(const char *obj_dir,
                        count_distinct++;
        }
 
-       if (count_distinct >= GRAPH_PARENT_MISSING)
+       if (count_distinct >= GRAPH_EDGE_LAST_MASK)
                die(_("the commit graph format cannot write %d commits"), count_distinct);
 
        commits.nr = 0;
@@ -891,7 +900,7 @@ void write_commit_graph(const char *obj_dir,
        }
        num_chunks = num_extra_edges ? 4 : 3;
 
-       if (commits.nr >= GRAPH_PARENT_MISSING)
+       if (commits.nr >= GRAPH_EDGE_LAST_MASK)
                die(_("too many commits to write graph"));
 
        compute_generation_numbers(&commits, report_progress);
diff --git a/compat/cygwin.c b/compat/cygwin.c
deleted file mode 100644 (file)
index b9862d6..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "../git-compat-util.h"
-#include "../cache.h"
-
-int cygwin_offset_1st_component(const char *path)
-{
-       const char *pos = path;
-       /* unc paths */
-       if (is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {
-               /* skip server name */
-               pos = strchr(pos + 2, '/');
-               if (!pos)
-                       return 0; /* Error: malformed unc path */
-
-               do {
-                       pos++;
-               } while (*pos && pos[0] != '/');
-       }
-       return pos + is_dir_sep(*pos) - path;
-}
diff --git a/compat/cygwin.h b/compat/cygwin.h
deleted file mode 100644 (file)
index 8e52de4..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-int cygwin_offset_1st_component(const char *path);
-#define offset_1st_component cygwin_offset_1st_component
index 34b3880b29d57eee6d6ae0afbb786d7980e7fa3e..b459e1a291ab0fe906c9a53a0fbcc61ad2c7e153 100644 (file)
@@ -350,7 +350,7 @@ static inline int needs_hiding(const char *path)
                return 0;
 
        /* We cannot use basename(), as it would remove trailing slashes */
-       mingw_skip_dos_drive_prefix((char **)&path);
+       win32_skip_dos_drive_prefix((char **)&path);
        if (!*path)
                return 0;
 
@@ -2275,33 +2275,6 @@ pid_t waitpid(pid_t pid, int *status, int options)
        return -1;
 }
 
-int mingw_skip_dos_drive_prefix(char **path)
-{
-       int ret = has_dos_drive_prefix(*path);
-       *path += ret;
-       return ret;
-}
-
-int mingw_offset_1st_component(const char *path)
-{
-       char *pos = (char *)path;
-
-       /* unc paths */
-       if (!skip_dos_drive_prefix(&pos) &&
-                       is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {
-               /* skip server name */
-               pos = strpbrk(pos + 2, "\\/");
-               if (!pos)
-                       return 0; /* Error: malformed unc path */
-
-               do {
-                       pos++;
-               } while (*pos && !is_dir_sep(*pos));
-       }
-
-       return pos + is_dir_sep(*pos) - path;
-}
-
 int xutftowcsn(wchar_t *wcs, const char *utfs, size_t wcslen, int utflen)
 {
        int upos = 0, wpos = 0;
index 8c24ddaa3efc20e4454ebc87c51fa30316f64a22..30d9fb3e36274657e5d2a63ef2f5eb3e1c55ce61 100644 (file)
@@ -443,32 +443,12 @@ HANDLE winansi_get_osfhandle(int fd);
  * git specific compatibility
  */
 
-#define has_dos_drive_prefix(path) \
-       (isalpha(*(path)) && (path)[1] == ':' ? 2 : 0)
-int mingw_skip_dos_drive_prefix(char **path);
-#define skip_dos_drive_prefix mingw_skip_dos_drive_prefix
-static inline int mingw_is_dir_sep(int c)
-{
-       return c == '/' || c == '\\';
-}
-#define is_dir_sep mingw_is_dir_sep
-static inline char *mingw_find_last_dir_sep(const char *path)
-{
-       char *ret = NULL;
-       for (; *path; ++path)
-               if (is_dir_sep(*path))
-                       ret = (char *)path;
-       return ret;
-}
 static inline void convert_slashes(char *path)
 {
        for (; *path; path++)
                if (*path == '\\')
                        *path = '/';
 }
-#define find_last_dir_sep mingw_find_last_dir_sep
-int mingw_offset_1st_component(const char *path);
-#define offset_1st_component mingw_offset_1st_component
 #define PATH_SEP ';'
 extern char *mingw_query_user_email(void);
 #define query_user_email mingw_query_user_email
index 51cd60baa37adbeef788098482d804c58cb9979f..c0d838834ad8714cc29148bf23895ab30498947e 100644 (file)
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#if defined __TANDEM
+ /* This is currently duplicated from git-compat-utils.h */
+# ifdef NO_INTPTR_T
+ typedef long intptr_t;
+ typedef unsigned long uintptr_t;
+# endif
+#endif
+
 static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
                                          size_t length, reg_syntax_t syntax);
 static void re_compile_fastmap_iter (regex_t *bufp,
diff --git a/compat/win32/path-utils.c b/compat/win32/path-utils.c
new file mode 100644 (file)
index 0000000..d9d3641
--- /dev/null
@@ -0,0 +1,28 @@
+#include "../../git-compat-util.h"
+
+int win32_skip_dos_drive_prefix(char **path)
+{
+       int ret = has_dos_drive_prefix(*path);
+       *path += ret;
+       return ret;
+}
+
+int win32_offset_1st_component(const char *path)
+{
+       char *pos = (char *)path;
+
+       /* unc paths */
+       if (!skip_dos_drive_prefix(&pos) &&
+                       is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {
+               /* skip server name */
+               pos = strpbrk(pos + 2, "\\/");
+               if (!pos)
+                       return 0; /* Error: malformed unc path */
+
+               do {
+                       pos++;
+               } while (*pos && !is_dir_sep(*pos));
+       }
+
+       return pos + is_dir_sep(*pos) - path;
+}
diff --git a/compat/win32/path-utils.h b/compat/win32/path-utils.h
new file mode 100644 (file)
index 0000000..0f70d43
--- /dev/null
@@ -0,0 +1,20 @@
+#define has_dos_drive_prefix(path) \
+       (isalpha(*(path)) && (path)[1] == ':' ? 2 : 0)
+int win32_skip_dos_drive_prefix(char **path);
+#define skip_dos_drive_prefix win32_skip_dos_drive_prefix
+static inline int win32_is_dir_sep(int c)
+{
+       return c == '/' || c == '\\';
+}
+#define is_dir_sep win32_is_dir_sep
+static inline char *win32_find_last_dir_sep(const char *path)
+{
+       char *ret = NULL;
+       for (; *path; ++path)
+               if (is_dir_sep(*path))
+                       ret = (char *)path;
+       return ret;
+}
+#define find_last_dir_sep win32_find_last_dir_sep
+int win32_offset_1st_component(const char *path);
+#define offset_1st_component win32_offset_1st_component
index bbeeff44fe1e9b4a864cd0dc082906041d65de51..7354fe15b3d93737b1c15c74943da2b7630108d6 100644 (file)
@@ -6,6 +6,7 @@ CFLAGS += -pedantic
 # don't warn for each N_ use
 CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0
 endif
+CFLAGS += -Wall
 CFLAGS += -Wdeclaration-after-statement
 CFLAGS += -Wformat-security
 CFLAGS += -Wno-format-zero-length
index 3ee7da0e230c4c33e79ae2f3cf498a5cd7cc4881..7b36a1dfe7dc245ab0e9e9d431ee1d7c562915cb 100644 (file)
@@ -187,7 +187,7 @@ ifeq ($(uname_O),Cygwin)
        UNRELIABLE_FSTAT = UnfortunatelyYes
        OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
        MMAP_PREVENTS_DELETE = UnfortunatelyYes
-       COMPAT_OBJS += compat/cygwin.o
+       COMPAT_OBJS += compat/win32/path-utils.o
        FREAD_READS_DIRECTORIES = UnfortunatelyYes
 endif
 ifeq ($(uname_S),FreeBSD)
@@ -233,6 +233,7 @@ ifeq ($(uname_S),OpenBSD)
        HAVE_BSD_SYSCTL = YesPlease
        HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
        PROCFS_EXECUTABLE_PATH = /proc/curproc/file
+       FREAD_READS_DIRECTORIES = UnfortunatelyYes
 endif
 ifeq ($(uname_S),MirBSD)
        NO_STRCASESTR = YesPlease
@@ -441,26 +442,43 @@ ifeq ($(uname_S),NONSTOP_KERNEL)
        # INLINE='' would just replace one set of warnings with another and
        # still not compile in c89 mode, due to non-const array initializations.
        CC = cc -c99
+       # Build down-rev compatible objects that don't use our new getopt_long.
+       ifeq ($(uname_R).$(uname_V),J06.21)
+               CC += -WRVU=J06.20
+       endif
+       ifeq ($(uname_R).$(uname_V),L17.02)
+               CC += -WRVU=L16.05
+       endif
        # Disable all optimization, seems to result in bad code, with -O or -O2
        # or even -O1 (default), /usr/local/libexec/git-core/git-pack-objects
        # abends on "git push". Needs more investigation.
-       CFLAGS = -g -O0
+       CFLAGS = -g -O0 -Winline
        # We'd want it to be here.
        prefix = /usr/local
-       # Our's are in ${prefix}/bin (perl might also be in /usr/bin/perl).
-       PERL_PATH = ${prefix}/bin/perl
-       PYTHON_PATH = ${prefix}/bin/python
-
+       # perl and python must be in /usr/bin on NonStop - supplied by HPE
+       # with operating system in that managed directory.
+       PERL_PATH = /usr/bin/perl
+       PYTHON_PATH = /usr/bin/python
+       # The current /usr/coreutils/rm at lowest support level does not work
+       # with the git test structure. Long paths as in
+       # 'trash directory...' cause rm to terminate prematurely without fully
+       # removing the directory at OS releases J06.21 and L17.02.
+       # Default to the older rm until those two releases are deprecated.
+       RM = /bin/rm -f
        # As detected by './configure'.
        # Missdetected, hence commented out, see below.
        #NO_CURL = YesPlease
        # Added manually, see above.
+       NEEDS_SSL_WITH_CURL = YesPlease
+       NEEDS_CRYPTO_WITH_SSL = YesPlease
+       HAVE_DEV_TTY = YesPlease
        HAVE_LIBCHARSET_H = YesPlease
        HAVE_STRINGS_H = YesPlease
        NEEDS_LIBICONV = YesPlease
        NEEDS_LIBINTL_BEFORE_LIBICONV = YesPlease
        NO_SYS_SELECT_H = UnfortunatelyYes
        NO_D_TYPE_IN_DIRENT = YesPlease
+       NO_GETTEXT = YesPlease
        NO_HSTRERROR = YesPlease
        NO_STRCASESTR = YesPlease
        NO_MEMMEM = YesPlease
@@ -470,7 +488,7 @@ ifeq ($(uname_S),NONSTOP_KERNEL)
        NO_MKDTEMP = YesPlease
        # Currently libiconv-1.9.1.
        OLD_ICONV = UnfortunatelyYes
-       NO_REGEX = YesPlease
+       NO_REGEX = NeedsStartEnd
        NO_PTHREADS = UnfortunatelyYes
 
        # Not detected (nor checked for) by './configure'.
@@ -527,6 +545,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
        COMPAT_CFLAGS += -DNOGDI -Icompat -Icompat/win32
        COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
        COMPAT_OBJS += compat/mingw.o compat/winansi.o \
+               compat/win32/path-utils.o \
                compat/win32/pthread.o compat/win32/syslog.o \
                compat/win32/dirent.o
        BASIC_CFLAGS += -DWIN32 -DPROTECT_NTFS_DEFAULT=1
index 9e8ec95c3c7adb2956435ded43b020532aafa1c2..499e56f83d0a0592abd53686612c79358780eef2 100644 (file)
@@ -438,7 +438,7 @@ __gitcomp_nl ()
 # Callers must take care of providing only paths that match the current path
 # to be completed and adding any prefix path components, if necessary.
 # 1: List of newline-separated matching paths, complete with all prefix
-#    path componens.
+#    path components.
 __gitcomp_file_direct ()
 {
        local IFS=$'\n'
@@ -855,7 +855,7 @@ __git_compute_merge_strategies ()
 
 __git_complete_revlist_file ()
 {
-       local pfx ls ref cur_="$cur"
+       local dequoted_word pfx ls ref cur_="$cur"
        case "$cur_" in
        *..?*:*)
                return
@@ -863,14 +863,18 @@ __git_complete_revlist_file ()
        ?*:*)
                ref="${cur_%%:*}"
                cur_="${cur_#*:}"
-               case "$cur_" in
+
+               __git_dequote "$cur_"
+
+               case "$dequoted_word" in
                ?*/*)
-                       pfx="${cur_%/*}"
-                       cur_="${cur_##*/}"
+                       pfx="${dequoted_word%/*}"
+                       cur_="${dequoted_word##*/}"
                        ls="$ref:$pfx"
                        pfx="$pfx/"
                        ;;
                *)
+                       cur_="$dequoted_word"
                        ls="$ref"
                        ;;
                esac
@@ -880,21 +884,10 @@ __git_complete_revlist_file ()
                *)   pfx="$ref:$pfx" ;;
                esac
 
-               __gitcomp_nl "$(__git ls-tree "$ls" \
-                               | sed '/^100... blob /{
-                                          s,^.*        ,,
-                                          s,$, ,
-                                      }
-                                      /^120000 blob /{
-                                          s,^.*        ,,
-                                          s,$, ,
-                                      }
-                                      /^040000 tree /{
-                                          s,^.*        ,,
-                                          s,$,/,
-                                      }
-                                      s/^.*    //')" \
-                       "$pfx" "$cur_" ""
+               __gitcomp_file "$(__git ls-tree "$ls" \
+                               | sed 's/^.*    //
+                                      s/$//')" \
+                       "$pfx" "$cur_"
                ;;
        *...*)
                pfx="${cur_%...*}..."
@@ -2993,7 +2986,7 @@ if [[ -n ${ZSH_VERSION-} ]] &&
 
                local IFS=$'\n'
                compset -P '*[=:]'
-               compadd -Q -f -- ${=1} && _ret=0
+               compadd -f -- ${=1} && _ret=0
        }
 
        __gitcomp_file ()
@@ -3002,7 +2995,7 @@ if [[ -n ${ZSH_VERSION-} ]] &&
 
                local IFS=$'\n'
                compset -P '*[=:]'
-               compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
+               compadd -p "${2-}" -f -- ${=1} && _ret=0
        }
 
        _git ()
index 049d6b80f650717f20e68568251c21098f598d80..886bf95d1f5940987f5c4411097fd09b000be037 100644 (file)
@@ -99,7 +99,7 @@ __gitcomp_file_direct ()
 
        local IFS=$'\n'
        compset -P '*[=:]'
-       compadd -Q -f -- ${=1} && _ret=0
+       compadd -f -- ${=1} && _ret=0
 }
 
 __gitcomp_file ()
@@ -108,7 +108,7 @@ __gitcomp_file ()
 
        local IFS=$'\n'
        compset -P '*[=:]'
-       compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
+       compadd -p "${2-}" -f -- ${=1} && _ret=0
 }
 
 __git_zsh_bash_func ()
index 2076cf972b2865dc19cf60dc8df1b69d27041b02..35791fd02c21e6d43accf26ef8f1e4d4a4c1b62f 100644 (file)
@@ -1,3 +1,59 @@
+Release 1.5.0
+=============
+
+Backward-incompatible change
+----------------------------
+
+The name of classes for environment was misnamed as `*Environement`.
+It is now `*Environment`.
+
+New features
+------------
+
+* A Thread-Index header is now added to each email sent (except for
+  combined emails where it would not make sense), so that MS Outlook
+  properly groups messages by threads even though they have a
+  different subject line. Unfortunately, even adding this header the
+  threading still seems to be unreliable, but it is unclear whether
+  this is an issue on our side or on MS Outlook's side (see discussion
+  here: https://github.com/git-multimail/git-multimail/pull/194).
+
+* A new variable multimailhook.ExcludeMergeRevisions was added to send
+  notification emails only for non-merge commits.
+
+* For gitolite environment, it is now possible to specify the mail map
+  in a separate file in addition to gitolite.conf, using the variable
+  multimailhook.MailaddressMap.
+
+Internal changes
+----------------
+
+* The testsuite now uses GIT_PRINT_SHA1_ELLIPSIS where needed for
+  compatibility with recent Git versions. Only tests are affected.
+
+* We don't try to install pyflakes in the continuous integration job
+  for old Python versions where it's no longer available.
+
+* Stop using the deprecated cgi.escape in Python 3.
+
+* New flake8 warnings have been fixed.
+
+* Python 3.6 is now tested against on Travis-CI.
+
+* A bunch of lgtm.com warnings have been fixed.
+
+Bug fixes
+---------
+
+* SMTPMailer logs in only once now. It used to re-login for each email
+  sent which triggered errors for some SMTP servers.
+
+* migrate-mailhook-config was broken by internal refactoring, it
+  should now work again.
+
+This version was tested with Python 2.6 to 3.7. It was tested with Git
+1.7.10.406.gdc801, 2.15.1 and 2.20.1.98.gecbdaf0.
+
 Release 1.4.0
 =============
 
index da65570e9b0d271a12c35dc9d800ba6887323a8f..de20a5428730861268b5065a672cd432e99d0a43 100644 (file)
@@ -4,9 +4,8 @@ Contributing
 git-multimail is an open-source project, built by volunteers. We would
 welcome your help!
 
-The current maintainers are Matthieu Moy
-<matthieu.moy@grenoble-inp.fr> and Michael Haggerty
-<mhagger@alum.mit.edu>.
+The current maintainers are `Matthieu Moy <http://matthieu-moy.fr>`__ and
+`Michael Haggerty <https://github.com/mhagger>`__.
 
 Please note that although a copy of git-multimail is distributed in
 the "contrib" section of the main Git project, development takes place
@@ -33,6 +32,29 @@ mailing list`_.
 Please CC emails regarding git-multimail to the maintainers so that we
 don't overlook them.
 
+Help needed: testers/maintainer for specific environments/OS
+------------------------------------------------------------
+
+The current maintainer uses and tests git-multimail on Linux with the
+Generic environment. More testers, or better contributors are needed
+to test git-multimail on other real-life setups:
+
+* Mac OS X, Windows: git-multimail is currently not supported on these
+  platforms. But since we have no external dependencies and try to
+  write code as portable as possible, it is possible that
+  git-multimail already runs there and if not, it is likely that it
+  could be ported easily.
+
+  Patches to improve support for Windows and OS X are welcome.
+  Ideally, there would be a sub-maintainer for each OS who would test
+  at least once before each release (around twice a year).
+
+* Gerrit, Stash, Gitolite environments: although the testsuite
+  contains tests for these environments, a tester/maintainer for each
+  environment would be welcome to test and report failure (or success)
+  on real-life environments periodically (here also, feedback before
+  each release would be highly appreciated).
+
 
 .. _`git-multimail repository on GitHub`: https://github.com/git-multimail/git-multimail
 .. _`Git mailing list`: git@vger.kernel.org
diff --git a/contrib/hooks/multimail/README b/contrib/hooks/multimail/README
deleted file mode 100644 (file)
index 5105373..0000000
+++ /dev/null
@@ -1,748 +0,0 @@
-git-multimail version 1.4.0
-===========================
-
-.. image:: https://travis-ci.org/git-multimail/git-multimail.svg?branch=master
-    :target: https://travis-ci.org/git-multimail/git-multimail
-
-git-multimail is a tool for sending notification emails on pushes to a
-Git repository.  It includes a Python module called ``git_multimail.py``,
-which can either be used as a hook script directly or can be imported
-as a Python module into another script.
-
-git-multimail is derived from the Git project's old
-contrib/hooks/post-receive-email, and is mostly compatible with that
-script.  See README.migrate-from-post-receive-email for details about
-the differences and for how to migrate from post-receive-email to
-git-multimail.
-
-git-multimail, like the rest of the Git project, is licensed under
-GPLv2 (see the COPYING file for details).
-
-Please note: although, as a convenience, git-multimail may be
-distributed along with the main Git project, development of
-git-multimail takes place in its own, separate project.  See section
-"Getting involved" below for more information.
-
-
-By default, for each push received by the repository, git-multimail:
-
-1. Outputs one email summarizing each reference that was changed.
-   These "reference change" (called "refchange" below) emails describe
-   the nature of the change (e.g., was the reference created, deleted,
-   fast-forwarded, etc.) and include a one-line summary of each commit
-   that was added to the reference.
-
-2. Outputs one email for each new commit that was introduced by the
-   reference change.  These "commit" emails include a list of the
-   files changed by the commit, followed by the diffs of files
-   modified by the commit.  The commit emails are threaded to the
-   corresponding reference change email via "In-Reply-To".  This style
-   (similar to the "git format-patch" style used on the Git mailing
-   list) makes it easy to scan through the emails, jump to patches
-   that need further attention, and write comments about specific
-   commits.  Commits are handled in reverse topological order (i.e.,
-   parents shown before children).  For example::
-
-     [git] branch master updated
-     + [git] 01/08: doc: fix xref link from api docs to manual pages
-     + [git] 02/08: api-credentials.txt: show the big picture first
-     + [git] 03/08: api-credentials.txt: mention credential.helper explicitly
-     + [git] 04/08: api-credentials.txt: add "see also" section
-     + [git] 05/08: t3510 (cherry-pick-sequence): add missing '&&'
-     + [git] 06/08: Merge branch 'rr/maint-t3510-cascade-fix'
-     + [git] 07/08: Merge branch 'mm/api-credentials-doc'
-     + [git] 08/08: Git 1.7.11-rc2
-
-   By default, each commit appears in exactly one commit email, the
-   first time that it is pushed to the repository.  If a commit is later
-   merged into another branch, then a one-line summary of the commit
-   is included in the reference change email (as usual), but no
-   additional commit email is generated. See
-   `multimailhook.refFilter(Inclusion|Exclusion|DoSend|DontSend)Regex`
-   below to configure which branches and tags are watched by the hook.
-
-   By default, reference change emails have their "Reply-To" field set
-   to the person who pushed the change, and commit emails have their
-   "Reply-To" field set to the author of the commit.
-
-3. Output one "announce" mail for each new annotated tag, including
-   information about the tag and optionally a shortlog describing the
-   changes since the previous tag.  Such emails might be useful if you
-   use annotated tags to mark releases of your project.
-
-
-Requirements
-------------
-
-* Python 2.x, version 2.4 or later.  No non-standard Python modules
-  are required.  git-multimail has preliminary support for Python 3
-  (but it has been better tested with Python 2).
-
-* The ``git`` command must be in your PATH.  git-multimail is known to
-  work with Git versions back to 1.7.1.  (Earlier versions have not
-  been tested; if you do so, please report your results.)
-
-* To send emails using the default configuration, a standard sendmail
-  program must be located at '/usr/sbin/sendmail' or
-  '/usr/lib/sendmail' and must be configured correctly to send emails.
-  If this is not the case, set multimailhook.sendmailCommand, or see
-  the multimailhook.mailer configuration variable below for how to
-  configure git-multimail to send emails via an SMTP server.
-
-
-Invocation
-----------
-
-``git_multimail.py`` is designed to be used as a ``post-receive`` hook in a
-Git repository (see githooks(5)).  Link or copy it to
-$GIT_DIR/hooks/post-receive within the repository for which email
-notifications are desired.  Usually it should be installed on the
-central repository for a project, to which all commits are eventually
-pushed.
-
-For use on pre-v1.5.1 Git servers, ``git_multimail.py`` can also work as
-an ``update`` hook, taking its arguments on the command line.  To use
-this script in this manner, link or copy it to $GIT_DIR/hooks/update.
-Please note that the script is not completely reliable in this mode
-[1]_.
-
-Alternatively, ``git_multimail.py`` can be imported as a Python module
-into your own Python post-receive script.  This method is a bit more
-work, but allows the behavior of the hook to be customized using
-arbitrary Python code.  For example, you can use a custom environment
-(perhaps inheriting from GenericEnvironment or GitoliteEnvironment) to
-
-* change how the user who did the push is determined
-
-* read users' email addresses from an LDAP server or from a database
-
-* decide which users should be notified about which commits based on
-  the contents of the commits (e.g., for users who want to be notified
-  only about changes affecting particular files or subdirectories)
-
-Or you can change how emails are sent by writing your own Mailer
-class.  The ``post-receive`` script in this directory demonstrates how
-to use ``git_multimail.py`` as a Python module.  (If you make interesting
-changes of this type, please consider sharing them with the
-community.)
-
-
-Troubleshooting/FAQ
--------------------
-
-Please read `<doc/troubleshooting.rst>`__ for frequently asked
-questions and common issues with git-multimail.
-
-
-Configuration
--------------
-
-By default, git-multimail mostly takes its configuration from the
-following ``git config`` settings:
-
-multimailhook.environment
-    This describes the general environment of the repository. In most
-    cases, you do not need to specify a value for this variable:
-    `git-multimail` will autodetect which environment to use.
-    Currently supported values:
-
-    generic
-      the username of the pusher is read from $USER or $USERNAME and
-      the repository name is derived from the repository's path.
-
-    gitolite
-      Environment to use when ``git-multimail`` is ran as a gitolite_
-      hook.
-
-      The username of the pusher is read from $GL_USER, the repository
-      name is read from $GL_REPO, and the From: header value is
-      optionally read from gitolite.conf (see multimailhook.from).
-
-      For more information about gitolite and git-multimail, read
-      `<doc/gitolite.rst>`__
-
-    stash
-      Environment to use when ``git-multimail`` is ran as an Atlassian
-      BitBucket Server (formerly known as Atlassian Stash) hook.
-
-      **Warning:** this mode was provided by a third-party contributor
-      and never tested by the git-multimail maintainers. It is
-      provided as-is and may or may not work for you.
-
-      This value is automatically assumed when the stash-specific
-      flags (``--stash-user`` and ``--stash-repo``) are specified on
-      the command line. When this environment is active, the username
-      and repo come from these two command line flags, which must be
-      specified.
-
-    gerrit
-      Environment to use when ``git-multimail`` is ran as a
-      ``ref-updated`` Gerrit hook.
-
-      This value is used when the gerrit-specific command line flags
-      (``--oldrev``, ``--newrev``, ``--refname``, ``--project``) for
-      gerrit's ref-updated hook are present. When this environment is
-      active, the username of the pusher is taken from the
-      ``--submitter`` argument if that command line option is passed,
-      otherwise 'Gerrit' is used. The repository name is taken from
-      the ``--project`` option on the command line, which must be passed.
-
-      For more information about gerrit and git-multimail, read
-      `<doc/gerrit.rst>`__
-
-    If none of these environments is suitable for your setup, then you
-    can implement a Python class that inherits from Environment and
-    instantiate it via a script that looks like the example
-    post-receive script.
-
-    The environment value can be specified on the command line using
-    the ``--environment`` option. If it is not specified on the
-    command line or by ``multimailhook.environment``, the value is
-    guessed as follows:
-
-    * If stash-specific (respectively gerrit-specific) command flags
-      are present on the command-line, then ``stash`` (respectively
-      ``gerrit``) is used.
-
-    * If the environment variables $GL_USER and $GL_REPO are set, then
-      ``gitolite`` is used.
-
-    * If none of the above apply, then ``generic`` is used.
-
-multimailhook.repoName
-    A short name of this Git repository, to be used in various places
-    in the notification email text.  The default is to use $GL_REPO
-    for gitolite repositories, or otherwise to derive this value from
-    the repository path name.
-
-multimailhook.mailingList
-    The list of email addresses to which notification emails should be
-    sent, as RFC 2822 email addresses separated by commas.  This
-    configuration option can be multivalued.  Leave it unset or set it
-    to the empty string to not send emails by default.  The next few
-    settings can be used to configure specific address lists for
-    specific types of notification email.
-
-multimailhook.refchangeList
-    The list of email addresses to which summary emails about
-    reference changes should be sent, as RFC 2822 email addresses
-    separated by commas.  This configuration option can be
-    multivalued.  The default is the value in
-    multimailhook.mailingList.  Set this value to "none" (or the empty
-    string) to prevent reference change emails from being sent even if
-    multimailhook.mailingList is set.
-
-multimailhook.announceList
-    The list of email addresses to which emails about new annotated
-    tags should be sent, as RFC 2822 email addresses separated by
-    commas.  This configuration option can be multivalued.  The
-    default is the value in multimailhook.refchangeList or
-    multimailhook.mailingList.  Set this value to "none" (or the empty
-    string) to prevent annotated tag announcement emails from being sent
-    even if one of the other values is set.
-
-multimailhook.commitList
-    The list of email addresses to which emails about individual new
-    commits should be sent, as RFC 2822 email addresses separated by
-    commas.  This configuration option can be multivalued.  The
-    default is the value in multimailhook.mailingList.  Set this value
-    to "none" (or the empty string) to prevent notification emails about
-    individual commits from being sent even if
-    multimailhook.mailingList is set.
-
-multimailhook.announceShortlog
-    If this option is set to true, then emails about changes to
-    annotated tags include a shortlog of changes since the previous
-    tag.  This can be useful if the annotated tags represent releases;
-    then the shortlog will be a kind of rough summary of what has
-    happened since the last release.  But if your tagging policy is
-    not so straightforward, then the shortlog might be confusing
-    rather than useful.  Default is false.
-
-multimailhook.commitEmailFormat
-    The format of email messages for the individual commits, can be "text" or
-    "html". In the latter case, the emails will include diffs using colorized
-    HTML instead of plain text used by default. Note that this  currently the
-    ref change emails are always sent in plain text.
-
-    Note that when using "html", the formatting is done by parsing the
-    output of ``git log`` with ``-p``. When using
-    ``multimailhook.commitLogOpts`` to specify a ``--format`` for
-    ``git log``, one may get false positive (e.g. lines in the body of
-    the message starting with ``+++`` or ``---`` colored in red or
-    green).
-
-    By default, all the message is HTML-escaped. See
-    ``multimailhook.htmlInIntro`` to change this behavior.
-
-multimailhook.commitBrowseURL
-    Used to generate a link to an online repository browser in commit
-    emails. This variable must be a string. Format directives like
-    ``%(<variable>)s`` will be expanded the same way as template
-    strings. In particular, ``%(id)s`` will be replaced by the full
-    Git commit identifier (40-chars hexadecimal).
-
-    If the string does not contain any format directive, then
-    ``%(id)s`` will be automatically added to the string. If you don't
-    want ``%(id)s`` to be automatically added, use the empty format
-    directive ``%()s`` anywhere in the string.
-
-    For example, a suitable value for the git-multimail project itself
-    would be
-    ``https://github.com/git-multimail/git-multimail/commit/%(id)s``.
-
-multimailhook.htmlInIntro, multimailhook.htmlInFooter
-    When generating an HTML message, git-multimail escapes any HTML
-    sequence by default. This means that if a template contains HTML
-    like ``<a href="foo">link</a>``, the reader will see the HTML
-    source code and not a proper link.
-
-    Set ``multimailhook.htmlInIntro`` to true to allow writing HTML
-    formatting in introduction templates. Similarly, set
-    ``multimailhook.htmlInFooter`` for HTML in the footer.
-
-    Variables expanded in the template are still escaped. For example,
-    if a repository's path contains a ``<``, it will be rendered as
-    such in the message.
-
-    Read `<doc/customizing-emails.rst>`__ for more details and
-    examples.
-
-multimailhook.refchangeShowGraph
-    If this option is set to true, then summary emails about reference
-    changes will additionally include:
-
-    * a graph of the added commits (if any)
-
-    * a graph of the discarded commits (if any)
-
-    The log is generated by running ``git log --graph`` with the options
-    specified in graphOpts.  The default is false.
-
-multimailhook.refchangeShowLog
-    If this option is set to true, then summary emails about reference
-    changes will include a detailed log of the added commits in
-    addition to the one line summary.  The log is generated by running
-    ``git log`` with the options specified in multimailhook.logOpts.
-    Default is false.
-
-multimailhook.mailer
-    This option changes the way emails are sent.  Accepted values are:
-
-    * **sendmail (the default)**: use the command ``/usr/sbin/sendmail`` or
-      ``/usr/lib/sendmail`` (or sendmailCommand, if configured).  This
-      mode can be further customized via the following options:
-
-      multimailhook.sendmailCommand
-          The command used by mailer ``sendmail`` to send emails.  Shell
-          quoting is allowed in the value of this setting, but remember that
-          Git requires double-quotes to be escaped; e.g.::
-
-              git config multimailhook.sendmailcommand '/usr/sbin/sendmail -oi -t -F \"Git Repo\"'
-
-          Default is '/usr/sbin/sendmail -oi -t' or
-          '/usr/lib/sendmail -oi -t' (depending on which file is
-          present and executable).
-
-      multimailhook.envelopeSender
-          If set then pass this value to sendmail via the -f option to set
-          the envelope sender address.
-
-    * **smtp**: use Python's smtplib.  This is useful when the sendmail
-      command is not available on the system.  This mode can be
-      further customized via the following options:
-
-      multimailhook.smtpServer
-          The name of the SMTP server to connect to.  The value can
-          also include a colon and a port number; e.g.,
-          ``mail.example.com:25``.  Default is 'localhost' using port 25.
-
-      multimailhook.smtpUser, multimailhook.smtpPass
-          Server username and password. Required if smtpEncryption is 'ssl'.
-          Note that the username and password currently need to be
-          set cleartext in the configuration file, which is not
-          recommended. If you need to use this option, be sure your
-          configuration file is read-only.
-
-      multimailhook.envelopeSender
-        The sender address to be passed to the SMTP server.  If
-        unset, then the value of multimailhook.from is used.
-
-      multimailhook.smtpServerTimeout
-        Timeout in seconds.
-
-      multimailhook.smtpEncryption
-        Set the security type. Allowed values: ``none``, ``ssl``, ``tls`` (starttls).
-        Default is ``none``.
-
-      multimailhook.smtpCACerts
-        Set the path to a list of trusted CA certificate to verify the
-        server certificate, only supported when ``smtpEncryption`` is
-        ``tls``. If unset or empty, the server certificate is not
-        verified. If it targets a file containing a list of trusted CA
-        certificates (PEM format) these CAs will be used to verify the
-        server certificate. For debian, you can set
-        ``/etc/ssl/certs/ca-certificates.crt`` for using the system
-        trusted CAs. For self-signed server, you can add your server
-        certificate to the system store::
-
-            cd /usr/local/share/ca-certificates/
-            openssl s_client -starttls smtp \
-                   -connect mail.example.net:587 -showcerts \
-                   </dev/null 2>/dev/null \
-                 | openssl x509 -outform PEM >mail.example.net.crt
-            update-ca-certificates
-
-        and used the updated ``/etc/ssl/certs/ca-certificates.crt``. Or
-        directly use your ``/path/to/mail.example.net.crt``. Default is
-        unset.
-
-      multimailhook.smtpServerDebugLevel
-        Integer number. Set to greater than 0 to activate debugging.
-
-multimailhook.from, multimailhook.fromCommit, multimailhook.fromRefchange
-    If set, use this value in the From: field of generated emails.
-    ``fromCommit`` is used for commit emails, ``fromRefchange`` is
-    used for refchange emails, and ``from`` is used as fall-back in
-    all cases.
-
-    The value for these variables can be either:
-
-    - An email address, which will be used directly.
-
-    - The value ``pusher``, in which case the pusher's address (if
-      available) will be used.
-
-    - The value ``author`` (meaningful only for ``fromCommit``), in which
-      case the commit author's address will be used.
-
-    If config values are unset, the value of the From: header is
-    determined as follows:
-
-    1. (gitolite environment only) Parse gitolite.conf, looking for a
-       block of comments that looks like this::
-
-           # BEGIN USER EMAILS
-           # username Firstname Lastname <email@example.com>
-           # END USER EMAILS
-
-       If that block exists, and there is a line between the BEGIN
-       USER EMAILS and END USER EMAILS lines where the first field
-       matches the gitolite username ($GL_USER), use the rest of the
-       line for the From: header.
-
-    2. If the user.email configuration setting is set, use its value
-       (and the value of user.name, if set).
-
-    3. Use the value of multimailhook.envelopeSender.
-
-multimailhook.administrator
-    The name and/or email address of the administrator of the Git
-    repository; used in FOOTER_TEMPLATE.  Default is
-    multimailhook.envelopesender if it is set; otherwise a generic
-    string is used.
-
-multimailhook.emailPrefix
-    All emails have this string prepended to their subjects, to aid
-    email filtering (though filtering based on the X-Git-* email
-    headers is probably more robust).  Default is the short name of
-    the repository in square brackets; e.g., ``[myrepo]``.  Set this
-    value to the empty string to suppress the email prefix. You may
-    use the placeholder ``%(repo_shortname)s`` for the short name of
-    the repository.
-
-multimailhook.emailMaxLines
-    The maximum number of lines that should be included in the body of
-    a generated email.  If not specified, there is no limit.  Lines
-    beyond the limit are suppressed and counted, and a final line is
-    added indicating the number of suppressed lines.
-
-multimailhook.emailMaxLineLength
-    The maximum length of a line in the email body.  Lines longer than
-    this limit are truncated to this length with a trailing ``[...]``
-    added to indicate the missing text.  The default is 500, because
-    (a) diffs with longer lines are probably from binary files, for
-    which a diff is useless, and (b) even if a text file has such long
-    lines, the diffs are probably unreadable anyway.  To disable line
-    truncation, set this option to 0.
-
-multimailhook.subjectMaxLength
-    The maximum length of the subject line (i.e. the ``oneline`` field
-    in templates, not including the prefix). Lines longer than this
-    limit are truncated to this length with a trailing ``[...]`` added
-    to indicate the missing text. This option The default is to use
-    ``multimailhook.emailMaxLineLength``. This option avoids sending
-    emails with overly long subject lines, but should not be needed if
-    the commit messages follow the Git convention (one short subject
-    line, then a blank line, then the message body). To disable line
-    truncation, set this option to 0.
-
-multimailhook.maxCommitEmails
-    The maximum number of commit emails to send for a given change.
-    When the number of patches is larger that this value, only the
-    summary refchange email is sent.  This can avoid accidental
-    mailbombing, for example on an initial push.  To disable commit
-    emails limit, set this option to 0.  The default is 500.
-
-multimailhook.emailStrictUTF8
-    If this boolean option is set to `true`, then the main part of the
-    email body is forced to be valid UTF-8.  Any characters that are
-    not valid UTF-8 are converted to the Unicode replacement
-    character, U+FFFD.  The default is `true`.
-
-    This option is ineffective with Python 3, where non-UTF-8
-    characters are unconditionally replaced.
-
-multimailhook.diffOpts
-    Options passed to ``git diff-tree`` when generating the summary
-    information for ReferenceChange emails.  Default is ``--stat
-    --summary --find-copies-harder``.  Add -p to those options to
-    include a unified diff of changes in addition to the usual summary
-    output.  Shell quoting is allowed; see ``multimailhook.logOpts`` for
-    details.
-
-multimailhook.graphOpts
-    Options passed to ``git log --graph`` when generating graphs for the
-    reference change summary emails (used only if refchangeShowGraph
-    is true).  The default is '--oneline --decorate'.
-
-    Shell quoting is allowed; see logOpts for details.
-
-multimailhook.logOpts
-    Options passed to ``git log`` to generate additional info for
-    reference change emails (used only if refchangeShowLog is set).
-    For example, adding -p will show each commit's complete diff.  The
-    default is empty.
-
-    Shell quoting is allowed; for example, a log format that contains
-    spaces can be specified using something like::
-
-      git config multimailhook.logopts '--pretty=format:"%h %aN <%aE>%n%s%n%n%b%n"'
-
-    If you want to set this by editing your configuration file
-    directly, remember that Git requires double-quotes to be escaped
-    (see git-config(1) for more information)::
-
-      [multimailhook]
-              logopts = --pretty=format:\"%h %aN <%aE>%n%s%n%n%b%n\"
-
-multimailhook.commitLogOpts
-    Options passed to ``git log`` to generate additional info for
-    revision change emails.  For example, adding --ignore-all-spaces
-    will suppress whitespace changes.  The default options are ``-C
-    --stat -p --cc``.  Shell quoting is allowed; see
-    multimailhook.logOpts for details.
-
-multimailhook.dateSubstitute
-    String to use as a substitute for ``Date:`` in the output of ``git
-    log`` while formatting commit messages. This is useful to avoid
-    emitting a line that can be interpreted by mailers as the start of
-    a cited message (Zimbra webmail in particular). Defaults to
-    ``CommitDate:``. Set to an empty string or ``none`` to deactivate
-    the behavior.
-
-multimailhook.emailDomain
-    Domain name appended to the username of the person doing the push
-    to convert it into an email address
-    (via ``"%s@%s" % (username, emaildomain)``). More complicated
-    schemes can be implemented by overriding Environment and
-    overriding its get_pusher_email() method.
-
-multimailhook.replyTo, multimailhook.replyToCommit, multimailhook.replyToRefchange
-    Addresses to use in the Reply-To: field for commit emails
-    (replyToCommit) and refchange emails (replyToRefchange).
-    multimailhook.replyTo is used as default when replyToCommit or
-    replyToRefchange is not set. The shortcuts ``pusher`` and
-    ``author`` are allowed with the same semantics as for
-    ``multimailhook.from``. In addition, the value ``none`` can be
-    used to omit the ``Reply-To:`` field.
-
-    The default is ``pusher`` for refchange emails, and ``author`` for
-    commit emails.
-
-multimailhook.quiet
-    Do not output the list of email recipients from the hook
-
-multimailhook.stdout
-    For debugging, send emails to stdout rather than to the
-    mailer.  Equivalent to the --stdout command line option
-
-multimailhook.scanCommitForCc
-    If this option is set to true, than recipients from lines in commit body
-    that starts with ``CC:`` will be added to CC list.
-    Default: false
-
-multimailhook.combineWhenSingleCommit
-    If this option is set to true and a single new commit is pushed to
-    a branch, combine the summary and commit email messages into a
-    single email.
-    Default: true
-
-multimailhook.refFilterInclusionRegex, multimailhook.refFilterExclusionRegex, multimailhook.refFilterDoSendRegex, multimailhook.refFilterDontSendRegex
-    **Warning:** these options are experimental. They should work, but
-    the user-interface is not stable yet (in particular, the option
-    names may change). If you want to participate in stabilizing the
-    feature, please contact the maintainers and/or send pull-requests.
-    If you are happy with the current shape of the feature, please
-    report it too.
-
-    Regular expressions that can be used to limit refs for which email
-    updates will be sent.  It is an error to specify both an inclusion
-    and an exclusion regex.  If a ``refFilterInclusionRegex`` is
-    specified, emails will only be sent for refs which match this
-    regex.  If a ``refFilterExclusionRegex`` regex is specified,
-    emails will be sent for all refs except those that match this
-    regex (or that match a predefined regex specific to the
-    environment, such as "^refs/notes" for most environments and
-    "^refs/notes|^refs/changes" for the gerrit environment).
-
-    The expressions are matched against the complete refname, and is
-    considered to match if any substring matches. For example, to
-    filter-out all tags, set ``refFilterExclusionRegex`` to
-    ``^refs/tags/`` (note the leading ``^`` but no trailing ``$``). If
-    you set ``refFilterExclusionRegex`` to ``master``, then any ref
-    containing ``master`` will be excluded (the ``master`` branch, but
-    also ``refs/tags/master`` or ``refs/heads/foo-master-bar``).
-
-    ``refFilterDoSendRegex`` and ``refFilterDontSendRegex`` are
-    analogous to ``refFilterInclusionRegex`` and
-    ``refFilterExclusionRegex`` with one difference: with
-    ``refFilterDoSendRegex`` and ``refFilterDontSendRegex``, commits
-    introduced by one excluded ref will not be considered as new when
-    they reach an included ref. Typically, if you add a branch ``foo``
-    to  ``refFilterDontSendRegex``, push commits to this branch, and
-    later merge branch ``foo`` into ``master``, then the notification
-    email for ``master`` will contain a commit email only for the
-    merge commit. If you include ``foo`` in
-    ``refFilterExclusionRegex``, then at the time of merge, you will
-    receive one commit email per commit in the branch.
-
-    These variables can be multi-valued, like::
-
-      [multimailhook]
-              refFilterExclusionRegex = ^refs/tags/
-              refFilterExclusionRegex = ^refs/heads/master$
-
-    You can also provide a whitespace-separated list like::
-
-      [multimailhook]
-              refFilterExclusionRegex = ^refs/tags/ ^refs/heads/master$
-
-    Both examples exclude tags and the master branch, and are
-    equivalent to::
-
-      [multimailhook]
-              refFilterExclusionRegex = ^refs/tags/|^refs/heads/master$
-
-    ``refFilterInclusionRegex`` and ``refFilterExclusionRegex`` are
-    strictly stronger than ``refFilterDoSendRegex`` and
-    ``refFilterDontSendRegex``. In other words, adding a ref to a
-    DoSend/DontSend regex has no effect if it is already excluded by a
-    Exclusion/Inclusion regex.
-
-multimailhook.logFile, multimailhook.errorLogFile, multimailhook.debugLogFile
-
-    When set, these variable designate path to files where
-    git-multimail will log some messages. Normal messages and error
-    messages are sent to ``logFile``, and error messages are also sent
-    to ``errorLogFile``. Debug messages and all other messages are
-    sent to ``debugLogFile``. The recommended way is to set only one
-    of these variables, but it is also possible to set several of them
-    (part of the information is then duplicated in several log files,
-    for example errors are duplicated to all log files).
-
-    Relative path are relative to the Git repository where the push is
-    done.
-
-multimailhook.verbose
-
-    Verbosity level of git-multimail on its standard output. By
-    default, show only error and info messages. If set to true, show
-    also debug messages.
-
-Email filtering aids
---------------------
-
-All emails include extra headers to enable fine tuned filtering and
-give information for debugging.  All emails include the headers
-``X-Git-Host``, ``X-Git-Repo``, ``X-Git-Refname``, and ``X-Git-Reftype``.
-ReferenceChange emails also include headers ``X-Git-Oldrev`` and ``X-Git-Newrev``;
-Revision emails also include header ``X-Git-Rev``.
-
-
-Customizing email contents
---------------------------
-
-git-multimail mostly generates emails by expanding templates.  The
-templates can be customized.  To avoid the need to edit
-``git_multimail.py`` directly, the preferred way to change the templates
-is to write a separate Python script that imports ``git_multimail.py`` as
-a module, then replaces the templates in place.  See the provided
-post-receive script for an example of how this is done.
-
-
-Customizing git-multimail for your environment
-----------------------------------------------
-
-git-multimail is mostly customized via an "environment" that describes
-the local environment in which Git is running.  Two types of
-environment are built in:
-
-GenericEnvironment
-    a stand-alone Git repository.
-
-GitoliteEnvironment
-    a Git repository that is managed by gitolite_.  For such
-    repositories, the identity of the pusher is read from
-    environment variable $GL_USER, the name of the repository is read
-    from $GL_REPO (if it is not overridden by multimailhook.reponame),
-    and the From: header value is optionally read from gitolite.conf
-    (see multimailhook.from).
-
-By default, git-multimail assumes GitoliteEnvironment if $GL_USER and
-$GL_REPO are set, and otherwise assumes GenericEnvironment.
-Alternatively, you can choose one of these two environments explicitly
-by setting a ``multimailhook.environment`` config setting (which can
-have the value `generic` or `gitolite`) or by passing an --environment
-option to the script.
-
-If you need to customize the script in ways that are not supported by
-the existing environments, you can define your own environment class
-class using arbitrary Python code.  To do so, you need to import
-``git_multimail.py`` as a Python module, as demonstrated by the example
-post-receive script.  Then implement your environment class; it should
-usually inherit from one of the existing Environment classes and
-possibly one or more of the EnvironmentMixin classes.  Then set the
-``environment`` variable to an instance of your own environment class
-and pass it to ``run_as_post_receive_hook()``.
-
-The standard environment classes, GenericEnvironment and
-GitoliteEnvironment, are in fact themselves put together out of a
-number of mixin classes, each of which handles one aspect of the
-customization.  For the finest control over your configuration, you
-can specify exactly which mixin classes your own environment class
-should inherit from, and override individual methods (or even add your
-own mixin classes) to implement entirely new behaviors.  If you
-implement any mixins that might be useful to other people, please
-consider sharing them with the community!
-
-
-Getting involved
-----------------
-
-Please, read `<CONTRIBUTING.rst>`__ for instructions on how to
-contribute to git-multimail.
-
-
-Footnotes
----------
-
-.. [1] Because of the way information is passed to update hooks, the
-       script's method of determining whether a commit has already
-       been seen does not work when it is used as an ``update`` script.
-       In particular, no notification email will be generated for a
-       new commit that is added to multiple references in the same
-       push. A workaround is to use --force-send to force sending the
-       emails.
-
-.. _gitolite: https://github.com/sitaramc/gitolite
index 161b0230a05f1c011dbf28fcf1962c8fb3ee37c7..044444245d09e027e71878d11a5437b2b41af27a 100644 (file)
@@ -6,10 +6,10 @@ website:
     https://github.com/git-multimail/git-multimail
 
 The version in this directory was obtained from the upstream project
-on August 17 2016 and consists of the "git-multimail" subdirectory from
+on January 07 2019 and consists of the "git-multimail" subdirectory from
 revision
 
-    07b1cb6bfd7be156c62e1afa17cae13b850a869f refs/tags/1.4.0
+    04e80e6c40be465cc62b6c246f0fcb8fd2cfd454 refs/tags/1.5.0
 
 Please see the README file in this directory for information about how
 to report bugs or contribute to git-multimail.
diff --git a/contrib/hooks/multimail/README.rst b/contrib/hooks/multimail/README.rst
new file mode 100644 (file)
index 0000000..7c0fc4a
--- /dev/null
@@ -0,0 +1,774 @@
+git-multimail version 1.5.0
+===========================
+
+.. image:: https://travis-ci.org/git-multimail/git-multimail.svg?branch=master
+    :target: https://travis-ci.org/git-multimail/git-multimail
+
+git-multimail is a tool for sending notification emails on pushes to a
+Git repository.  It includes a Python module called ``git_multimail.py``,
+which can either be used as a hook script directly or can be imported
+as a Python module into another script.
+
+git-multimail is derived from the Git project's old
+contrib/hooks/post-receive-email, and is mostly compatible with that
+script.  See README.migrate-from-post-receive-email for details about
+the differences and for how to migrate from post-receive-email to
+git-multimail.
+
+git-multimail, like the rest of the Git project, is licensed under
+GPLv2 (see the COPYING file for details).
+
+Please note: although, as a convenience, git-multimail may be
+distributed along with the main Git project, development of
+git-multimail takes place in its own, separate project.  Please, read
+`<CONTRIBUTING.rst>`__ for more information.
+
+
+By default, for each push received by the repository, git-multimail:
+
+1. Outputs one email summarizing each reference that was changed.
+   These "reference change" (called "refchange" below) emails describe
+   the nature of the change (e.g., was the reference created, deleted,
+   fast-forwarded, etc.) and include a one-line summary of each commit
+   that was added to the reference.
+
+2. Outputs one email for each new commit that was introduced by the
+   reference change.  These "commit" emails include a list of the
+   files changed by the commit, followed by the diffs of files
+   modified by the commit.  The commit emails are threaded to the
+   corresponding reference change email via "In-Reply-To".  This style
+   (similar to the "git format-patch" style used on the Git mailing
+   list) makes it easy to scan through the emails, jump to patches
+   that need further attention, and write comments about specific
+   commits.  Commits are handled in reverse topological order (i.e.,
+   parents shown before children).  For example::
+
+     [git] branch master updated
+     + [git] 01/08: doc: fix xref link from api docs to manual pages
+     + [git] 02/08: api-credentials.txt: show the big picture first
+     + [git] 03/08: api-credentials.txt: mention credential.helper explicitly
+     + [git] 04/08: api-credentials.txt: add "see also" section
+     + [git] 05/08: t3510 (cherry-pick-sequence): add missing '&&'
+     + [git] 06/08: Merge branch 'rr/maint-t3510-cascade-fix'
+     + [git] 07/08: Merge branch 'mm/api-credentials-doc'
+     + [git] 08/08: Git 1.7.11-rc2
+
+   By default, each commit appears in exactly one commit email, the
+   first time that it is pushed to the repository.  If a commit is later
+   merged into another branch, then a one-line summary of the commit
+   is included in the reference change email (as usual), but no
+   additional commit email is generated. See
+   `multimailhook.refFilter(Inclusion|Exclusion|DoSend|DontSend)Regex`
+   below to configure which branches and tags are watched by the hook.
+
+   By default, reference change emails have their "Reply-To" field set
+   to the person who pushed the change, and commit emails have their
+   "Reply-To" field set to the author of the commit.
+
+3. Output one "announce" mail for each new annotated tag, including
+   information about the tag and optionally a shortlog describing the
+   changes since the previous tag.  Such emails might be useful if you
+   use annotated tags to mark releases of your project.
+
+
+Requirements
+------------
+
+* Python 2.x, version 2.4 or later.  No non-standard Python modules
+  are required.  git-multimail has preliminary support for Python 3
+  (but it has been better tested with Python 2).
+
+* The ``git`` command must be in your PATH.  git-multimail is known to
+  work with Git versions back to 1.7.1.  (Earlier versions have not
+  been tested; if you do so, please report your results.)
+
+* To send emails using the default configuration, a standard sendmail
+  program must be located at '/usr/sbin/sendmail' or
+  '/usr/lib/sendmail' and must be configured correctly to send emails.
+  If this is not the case, set multimailhook.sendmailCommand, or see
+  the multimailhook.mailer configuration variable below for how to
+  configure git-multimail to send emails via an SMTP server.
+
+* git-multimail is currently tested only on Linux. It may or may not
+  work on other platforms such as Windows and Mac OS. See
+  `<CONTRIBUTING.rst>`__ to improve the situation.
+
+
+Invocation
+----------
+
+``git_multimail.py`` is designed to be used as a ``post-receive`` hook in a
+Git repository (see githooks(5)).  Link or copy it to
+$GIT_DIR/hooks/post-receive within the repository for which email
+notifications are desired.  Usually it should be installed on the
+central repository for a project, to which all commits are eventually
+pushed.
+
+For use on pre-v1.5.1 Git servers, ``git_multimail.py`` can also work as
+an ``update`` hook, taking its arguments on the command line.  To use
+this script in this manner, link or copy it to $GIT_DIR/hooks/update.
+Please note that the script is not completely reliable in this mode
+[1]_.
+
+Alternatively, ``git_multimail.py`` can be imported as a Python module
+into your own Python post-receive script.  This method is a bit more
+work, but allows the behavior of the hook to be customized using
+arbitrary Python code.  For example, you can use a custom environment
+(perhaps inheriting from GenericEnvironment or GitoliteEnvironment) to
+
+* change how the user who did the push is determined
+
+* read users' email addresses from an LDAP server or from a database
+
+* decide which users should be notified about which commits based on
+  the contents of the commits (e.g., for users who want to be notified
+  only about changes affecting particular files or subdirectories)
+
+Or you can change how emails are sent by writing your own Mailer
+class.  The ``post-receive`` script in this directory demonstrates how
+to use ``git_multimail.py`` as a Python module.  (If you make interesting
+changes of this type, please consider sharing them with the
+community.)
+
+
+Troubleshooting/FAQ
+-------------------
+
+Please read `<doc/troubleshooting.rst>`__ for frequently asked
+questions and common issues with git-multimail.
+
+
+Configuration
+-------------
+
+By default, git-multimail mostly takes its configuration from the
+following ``git config`` settings:
+
+multimailhook.environment
+    This describes the general environment of the repository. In most
+    cases, you do not need to specify a value for this variable:
+    `git-multimail` will autodetect which environment to use.
+    Currently supported values:
+
+    generic
+      the username of the pusher is read from $USER or $USERNAME and
+      the repository name is derived from the repository's path.
+
+    gitolite
+      Environment to use when ``git-multimail`` is ran as a gitolite_
+      hook.
+
+      The username of the pusher is read from $GL_USER, the repository
+      name is read from $GL_REPO, and the From: header value is
+      optionally read from gitolite.conf (see multimailhook.from).
+
+      For more information about gitolite and git-multimail, read
+      `<doc/gitolite.rst>`__
+
+    stash
+      Environment to use when ``git-multimail`` is ran as an Atlassian
+      BitBucket Server (formerly known as Atlassian Stash) hook.
+
+      **Warning:** this mode was provided by a third-party contributor
+      and never tested by the git-multimail maintainers. It is
+      provided as-is and may or may not work for you.
+
+      This value is automatically assumed when the stash-specific
+      flags (``--stash-user`` and ``--stash-repo``) are specified on
+      the command line. When this environment is active, the username
+      and repo come from these two command line flags, which must be
+      specified.
+
+    gerrit
+      Environment to use when ``git-multimail`` is ran as a
+      ``ref-updated`` Gerrit hook.
+
+      This value is used when the gerrit-specific command line flags
+      (``--oldrev``, ``--newrev``, ``--refname``, ``--project``) for
+      gerrit's ref-updated hook are present. When this environment is
+      active, the username of the pusher is taken from the
+      ``--submitter`` argument if that command line option is passed,
+      otherwise 'Gerrit' is used. The repository name is taken from
+      the ``--project`` option on the command line, which must be passed.
+
+      For more information about gerrit and git-multimail, read
+      `<doc/gerrit.rst>`__
+
+    If none of these environments is suitable for your setup, then you
+    can implement a Python class that inherits from Environment and
+    instantiate it via a script that looks like the example
+    post-receive script.
+
+    The environment value can be specified on the command line using
+    the ``--environment`` option. If it is not specified on the
+    command line or by ``multimailhook.environment``, the value is
+    guessed as follows:
+
+    * If stash-specific (respectively gerrit-specific) command flags
+      are present on the command-line, then ``stash`` (respectively
+      ``gerrit``) is used.
+
+    * If the environment variables $GL_USER and $GL_REPO are set, then
+      ``gitolite`` is used.
+
+    * If none of the above apply, then ``generic`` is used.
+
+multimailhook.repoName
+    A short name of this Git repository, to be used in various places
+    in the notification email text.  The default is to use $GL_REPO
+    for gitolite repositories, or otherwise to derive this value from
+    the repository path name.
+
+multimailhook.mailingList
+    The list of email addresses to which notification emails should be
+    sent, as RFC 2822 email addresses separated by commas.  This
+    configuration option can be multivalued.  Leave it unset or set it
+    to the empty string to not send emails by default.  The next few
+    settings can be used to configure specific address lists for
+    specific types of notification email.
+
+multimailhook.refchangeList
+    The list of email addresses to which summary emails about
+    reference changes should be sent, as RFC 2822 email addresses
+    separated by commas.  This configuration option can be
+    multivalued.  The default is the value in
+    multimailhook.mailingList.  Set this value to "none" (or the empty
+    string) to prevent reference change emails from being sent even if
+    multimailhook.mailingList is set.
+
+multimailhook.announceList
+    The list of email addresses to which emails about new annotated
+    tags should be sent, as RFC 2822 email addresses separated by
+    commas.  This configuration option can be multivalued.  The
+    default is the value in multimailhook.refchangeList or
+    multimailhook.mailingList.  Set this value to "none" (or the empty
+    string) to prevent annotated tag announcement emails from being sent
+    even if one of the other values is set.
+
+multimailhook.commitList
+    The list of email addresses to which emails about individual new
+    commits should be sent, as RFC 2822 email addresses separated by
+    commas.  This configuration option can be multivalued.  The
+    default is the value in multimailhook.mailingList.  Set this value
+    to "none" (or the empty string) to prevent notification emails about
+    individual commits from being sent even if
+    multimailhook.mailingList is set.
+
+multimailhook.announceShortlog
+    If this option is set to true, then emails about changes to
+    annotated tags include a shortlog of changes since the previous
+    tag.  This can be useful if the annotated tags represent releases;
+    then the shortlog will be a kind of rough summary of what has
+    happened since the last release.  But if your tagging policy is
+    not so straightforward, then the shortlog might be confusing
+    rather than useful.  Default is false.
+
+multimailhook.commitEmailFormat
+    The format of email messages for the individual commits, can be "text" or
+    "html". In the latter case, the emails will include diffs using colorized
+    HTML instead of plain text used by default. Note that this  currently the
+    ref change emails are always sent in plain text.
+
+    Note that when using "html", the formatting is done by parsing the
+    output of ``git log`` with ``-p``. When using
+    ``multimailhook.commitLogOpts`` to specify a ``--format`` for
+    ``git log``, one may get false positive (e.g. lines in the body of
+    the message starting with ``+++`` or ``---`` colored in red or
+    green).
+
+    By default, all the message is HTML-escaped. See
+    ``multimailhook.htmlInIntro`` to change this behavior.
+
+multimailhook.commitBrowseURL
+    Used to generate a link to an online repository browser in commit
+    emails. This variable must be a string. Format directives like
+    ``%(<variable>)s`` will be expanded the same way as template
+    strings. In particular, ``%(id)s`` will be replaced by the full
+    Git commit identifier (40-chars hexadecimal).
+
+    If the string does not contain any format directive, then
+    ``%(id)s`` will be automatically added to the string. If you don't
+    want ``%(id)s`` to be automatically added, use the empty format
+    directive ``%()s`` anywhere in the string.
+
+    For example, a suitable value for the git-multimail project itself
+    would be
+    ``https://github.com/git-multimail/git-multimail/commit/%(id)s``.
+
+multimailhook.htmlInIntro, multimailhook.htmlInFooter
+    When generating an HTML message, git-multimail escapes any HTML
+    sequence by default. This means that if a template contains HTML
+    like ``<a href="foo">link</a>``, the reader will see the HTML
+    source code and not a proper link.
+
+    Set ``multimailhook.htmlInIntro`` to true to allow writing HTML
+    formatting in introduction templates. Similarly, set
+    ``multimailhook.htmlInFooter`` for HTML in the footer.
+
+    Variables expanded in the template are still escaped. For example,
+    if a repository's path contains a ``<``, it will be rendered as
+    such in the message.
+
+    Read `<doc/customizing-emails.rst>`__ for more details and
+    examples.
+
+multimailhook.refchangeShowGraph
+    If this option is set to true, then summary emails about reference
+    changes will additionally include:
+
+    * a graph of the added commits (if any)
+
+    * a graph of the discarded commits (if any)
+
+    The log is generated by running ``git log --graph`` with the options
+    specified in graphOpts.  The default is false.
+
+multimailhook.refchangeShowLog
+    If this option is set to true, then summary emails about reference
+    changes will include a detailed log of the added commits in
+    addition to the one line summary.  The log is generated by running
+    ``git log`` with the options specified in multimailhook.logOpts.
+    Default is false.
+
+multimailhook.mailer
+    This option changes the way emails are sent.  Accepted values are:
+
+    * **sendmail (the default)**: use the command ``/usr/sbin/sendmail`` or
+      ``/usr/lib/sendmail`` (or sendmailCommand, if configured).  This
+      mode can be further customized via the following options:
+
+      multimailhook.sendmailCommand
+          The command used by mailer ``sendmail`` to send emails.  Shell
+          quoting is allowed in the value of this setting, but remember that
+          Git requires double-quotes to be escaped; e.g.::
+
+              git config multimailhook.sendmailcommand '/usr/sbin/sendmail -oi -t -F \"Git Repo\"'
+
+          Default is '/usr/sbin/sendmail -oi -t' or
+          '/usr/lib/sendmail -oi -t' (depending on which file is
+          present and executable).
+
+      multimailhook.envelopeSender
+          If set then pass this value to sendmail via the -f option to set
+          the envelope sender address.
+
+    * **smtp**: use Python's smtplib.  This is useful when the sendmail
+      command is not available on the system.  This mode can be
+      further customized via the following options:
+
+      multimailhook.smtpServer
+          The name of the SMTP server to connect to.  The value can
+          also include a colon and a port number; e.g.,
+          ``mail.example.com:25``.  Default is 'localhost' using port 25.
+
+      multimailhook.smtpUser, multimailhook.smtpPass
+          Server username and password. Required if smtpEncryption is 'ssl'.
+          Note that the username and password currently need to be
+          set cleartext in the configuration file, which is not
+          recommended. If you need to use this option, be sure your
+          configuration file is read-only.
+
+      multimailhook.envelopeSender
+        The sender address to be passed to the SMTP server.  If
+        unset, then the value of multimailhook.from is used.
+
+      multimailhook.smtpServerTimeout
+        Timeout in seconds. Default is 10.
+
+      multimailhook.smtpEncryption
+        Set the security type. Allowed values: ``none``, ``ssl``, ``tls`` (starttls).
+        Default is ``none``.
+
+      multimailhook.smtpCACerts
+        Set the path to a list of trusted CA certificate to verify the
+        server certificate, only supported when ``smtpEncryption`` is
+        ``tls``. If unset or empty, the server certificate is not
+        verified. If it targets a file containing a list of trusted CA
+        certificates (PEM format) these CAs will be used to verify the
+        server certificate. For debian, you can set
+        ``/etc/ssl/certs/ca-certificates.crt`` for using the system
+        trusted CAs. For self-signed server, you can add your server
+        certificate to the system store::
+
+            cd /usr/local/share/ca-certificates/
+            openssl s_client -starttls smtp \
+                   -connect mail.example.net:587 -showcerts \
+                   </dev/null 2>/dev/null \
+                 | openssl x509 -outform PEM >mail.example.net.crt
+            update-ca-certificates
+
+        and used the updated ``/etc/ssl/certs/ca-certificates.crt``. Or
+        directly use your ``/path/to/mail.example.net.crt``. Default is
+        unset.
+
+      multimailhook.smtpServerDebugLevel
+        Integer number. Set to greater than 0 to activate debugging.
+
+multimailhook.from, multimailhook.fromCommit, multimailhook.fromRefchange
+    If set, use this value in the From: field of generated emails.
+    ``fromCommit`` is used for commit emails, ``fromRefchange`` is
+    used for refchange emails, and ``from`` is used as fall-back in
+    all cases.
+
+    The value for these variables can be either:
+
+    - An email address, which will be used directly.
+
+    - The value ``pusher``, in which case the pusher's address (if
+      available) will be used.
+
+    - The value ``author`` (meaningful only for ``fromCommit``), in which
+      case the commit author's address will be used.
+
+    If config values are unset, the value of the From: header is
+    determined as follows:
+
+    1. (gitolite environment only)
+       1.a) If ``multimailhook.MailaddressMap`` is set, and is a path
+       to an existing file (if relative, it is considered relative to
+       the place where ``gitolite.conf`` is located), then this file
+       should contain lines like::
+
+           username Firstname Lastname <email@example.com>
+
+       git-multimail will then look for a line where ``$GL_USER``
+       matches the ``username`` part, and use the rest of the line for
+       the ``From:`` header.
+
+       1.b) Parse gitolite.conf, looking for a block of comments that
+       looks like this::
+
+           # BEGIN USER EMAILS
+           # username Firstname Lastname <email@example.com>
+           # END USER EMAILS
+
+       If that block exists, and there is a line between the BEGIN
+       USER EMAILS and END USER EMAILS lines where the first field
+       matches the gitolite username ($GL_USER), use the rest of the
+       line for the From: header.
+
+    2. If the user.email configuration setting is set, use its value
+       (and the value of user.name, if set).
+
+    3. Use the value of multimailhook.envelopeSender.
+
+multimailhook.MailaddressMap
+    (gitolite environment only)
+    File to look for a ``From:`` address based on the user doing the
+    push. Defaults to unset. See ``multimailhook.from`` for details.
+
+multimailhook.administrator
+    The name and/or email address of the administrator of the Git
+    repository; used in FOOTER_TEMPLATE.  Default is
+    multimailhook.envelopesender if it is set; otherwise a generic
+    string is used.
+
+multimailhook.emailPrefix
+    All emails have this string prepended to their subjects, to aid
+    email filtering (though filtering based on the X-Git-* email
+    headers is probably more robust).  Default is the short name of
+    the repository in square brackets; e.g., ``[myrepo]``.  Set this
+    value to the empty string to suppress the email prefix. You may
+    use the placeholder ``%(repo_shortname)s`` for the short name of
+    the repository.
+
+multimailhook.emailMaxLines
+    The maximum number of lines that should be included in the body of
+    a generated email.  If not specified, there is no limit.  Lines
+    beyond the limit are suppressed and counted, and a final line is
+    added indicating the number of suppressed lines.
+
+multimailhook.emailMaxLineLength
+    The maximum length of a line in the email body.  Lines longer than
+    this limit are truncated to this length with a trailing ``[...]``
+    added to indicate the missing text.  The default is 500, because
+    (a) diffs with longer lines are probably from binary files, for
+    which a diff is useless, and (b) even if a text file has such long
+    lines, the diffs are probably unreadable anyway.  To disable line
+    truncation, set this option to 0.
+
+multimailhook.subjectMaxLength
+    The maximum length of the subject line (i.e. the ``oneline`` field
+    in templates, not including the prefix). Lines longer than this
+    limit are truncated to this length with a trailing ``[...]`` added
+    to indicate the missing text. This option The default is to use
+    ``multimailhook.emailMaxLineLength``. This option avoids sending
+    emails with overly long subject lines, but should not be needed if
+    the commit messages follow the Git convention (one short subject
+    line, then a blank line, then the message body). To disable line
+    truncation, set this option to 0.
+
+multimailhook.maxCommitEmails
+    The maximum number of commit emails to send for a given change.
+    When the number of patches is larger that this value, only the
+    summary refchange email is sent.  This can avoid accidental
+    mailbombing, for example on an initial push.  To disable commit
+    emails limit, set this option to 0.  The default is 500.
+
+multimailhook.excludeMergeRevisions
+    When sending out revision emails, do not consider merge commits (the
+    functional equivalent of `rev-list --no-merges`).
+    The default is `false` (send merge commit emails).
+
+multimailhook.emailStrictUTF8
+    If this boolean option is set to `true`, then the main part of the
+    email body is forced to be valid UTF-8.  Any characters that are
+    not valid UTF-8 are converted to the Unicode replacement
+    character, U+FFFD.  The default is `true`.
+
+    This option is ineffective with Python 3, where non-UTF-8
+    characters are unconditionally replaced.
+
+multimailhook.diffOpts
+    Options passed to ``git diff-tree`` when generating the summary
+    information for ReferenceChange emails.  Default is ``--stat
+    --summary --find-copies-harder``.  Add -p to those options to
+    include a unified diff of changes in addition to the usual summary
+    output.  Shell quoting is allowed; see ``multimailhook.logOpts`` for
+    details.
+
+multimailhook.graphOpts
+    Options passed to ``git log --graph`` when generating graphs for the
+    reference change summary emails (used only if refchangeShowGraph
+    is true).  The default is '--oneline --decorate'.
+
+    Shell quoting is allowed; see logOpts for details.
+
+multimailhook.logOpts
+    Options passed to ``git log`` to generate additional info for
+    reference change emails (used only if refchangeShowLog is set).
+    For example, adding -p will show each commit's complete diff.  The
+    default is empty.
+
+    Shell quoting is allowed; for example, a log format that contains
+    spaces can be specified using something like::
+
+      git config multimailhook.logopts '--pretty=format:"%h %aN <%aE>%n%s%n%n%b%n"'
+
+    If you want to set this by editing your configuration file
+    directly, remember that Git requires double-quotes to be escaped
+    (see git-config(1) for more information)::
+
+      [multimailhook]
+              logopts = --pretty=format:\"%h %aN <%aE>%n%s%n%n%b%n\"
+
+multimailhook.commitLogOpts
+    Options passed to ``git log`` to generate additional info for
+    revision change emails.  For example, adding --ignore-all-spaces
+    will suppress whitespace changes.  The default options are ``-C
+    --stat -p --cc``.  Shell quoting is allowed; see
+    multimailhook.logOpts for details.
+
+multimailhook.dateSubstitute
+    String to use as a substitute for ``Date:`` in the output of ``git
+    log`` while formatting commit messages. This is useful to avoid
+    emitting a line that can be interpreted by mailers as the start of
+    a cited message (Zimbra webmail in particular). Defaults to
+    ``CommitDate:``. Set to an empty string or ``none`` to deactivate
+    the behavior.
+
+multimailhook.emailDomain
+    Domain name appended to the username of the person doing the push
+    to convert it into an email address
+    (via ``"%s@%s" % (username, emaildomain)``). More complicated
+    schemes can be implemented by overriding Environment and
+    overriding its get_pusher_email() method.
+
+multimailhook.replyTo, multimailhook.replyToCommit, multimailhook.replyToRefchange
+    Addresses to use in the Reply-To: field for commit emails
+    (replyToCommit) and refchange emails (replyToRefchange).
+    multimailhook.replyTo is used as default when replyToCommit or
+    replyToRefchange is not set. The shortcuts ``pusher`` and
+    ``author`` are allowed with the same semantics as for
+    ``multimailhook.from``. In addition, the value ``none`` can be
+    used to omit the ``Reply-To:`` field.
+
+    The default is ``pusher`` for refchange emails, and ``author`` for
+    commit emails.
+
+multimailhook.quiet
+    Do not output the list of email recipients from the hook
+
+multimailhook.stdout
+    For debugging, send emails to stdout rather than to the
+    mailer.  Equivalent to the --stdout command line option
+
+multimailhook.scanCommitForCc
+    If this option is set to true, than recipients from lines in commit body
+    that starts with ``CC:`` will be added to CC list.
+    Default: false
+
+multimailhook.combineWhenSingleCommit
+    If this option is set to true and a single new commit is pushed to
+    a branch, combine the summary and commit email messages into a
+    single email.
+    Default: true
+
+multimailhook.refFilterInclusionRegex, multimailhook.refFilterExclusionRegex, multimailhook.refFilterDoSendRegex, multimailhook.refFilterDontSendRegex
+    **Warning:** these options are experimental. They should work, but
+    the user-interface is not stable yet (in particular, the option
+    names may change). If you want to participate in stabilizing the
+    feature, please contact the maintainers and/or send pull-requests.
+    If you are happy with the current shape of the feature, please
+    report it too.
+
+    Regular expressions that can be used to limit refs for which email
+    updates will be sent.  It is an error to specify both an inclusion
+    and an exclusion regex.  If a ``refFilterInclusionRegex`` is
+    specified, emails will only be sent for refs which match this
+    regex.  If a ``refFilterExclusionRegex`` regex is specified,
+    emails will be sent for all refs except those that match this
+    regex (or that match a predefined regex specific to the
+    environment, such as "^refs/notes" for most environments and
+    "^refs/notes|^refs/changes" for the gerrit environment).
+
+    The expressions are matched against the complete refname, and is
+    considered to match if any substring matches. For example, to
+    filter-out all tags, set ``refFilterExclusionRegex`` to
+    ``^refs/tags/`` (note the leading ``^`` but no trailing ``$``). If
+    you set ``refFilterExclusionRegex`` to ``master``, then any ref
+    containing ``master`` will be excluded (the ``master`` branch, but
+    also ``refs/tags/master`` or ``refs/heads/foo-master-bar``).
+
+    ``refFilterDoSendRegex`` and ``refFilterDontSendRegex`` are
+    analogous to ``refFilterInclusionRegex`` and
+    ``refFilterExclusionRegex`` with one difference: with
+    ``refFilterDoSendRegex`` and ``refFilterDontSendRegex``, commits
+    introduced by one excluded ref will not be considered as new when
+    they reach an included ref. Typically, if you add a branch ``foo``
+    to  ``refFilterDontSendRegex``, push commits to this branch, and
+    later merge branch ``foo`` into ``master``, then the notification
+    email for ``master`` will contain a commit email only for the
+    merge commit. If you include ``foo`` in
+    ``refFilterExclusionRegex``, then at the time of merge, you will
+    receive one commit email per commit in the branch.
+
+    These variables can be multi-valued, like::
+
+      [multimailhook]
+              refFilterExclusionRegex = ^refs/tags/
+              refFilterExclusionRegex = ^refs/heads/master$
+
+    You can also provide a whitespace-separated list like::
+
+      [multimailhook]
+              refFilterExclusionRegex = ^refs/tags/ ^refs/heads/master$
+
+    Both examples exclude tags and the master branch, and are
+    equivalent to::
+
+      [multimailhook]
+              refFilterExclusionRegex = ^refs/tags/|^refs/heads/master$
+
+    ``refFilterInclusionRegex`` and ``refFilterExclusionRegex`` are
+    strictly stronger than ``refFilterDoSendRegex`` and
+    ``refFilterDontSendRegex``. In other words, adding a ref to a
+    DoSend/DontSend regex has no effect if it is already excluded by a
+    Exclusion/Inclusion regex.
+
+multimailhook.logFile, multimailhook.errorLogFile, multimailhook.debugLogFile
+
+    When set, these variable designate path to files where
+    git-multimail will log some messages. Normal messages and error
+    messages are sent to ``logFile``, and error messages are also sent
+    to ``errorLogFile``. Debug messages and all other messages are
+    sent to ``debugLogFile``. The recommended way is to set only one
+    of these variables, but it is also possible to set several of them
+    (part of the information is then duplicated in several log files,
+    for example errors are duplicated to all log files).
+
+    Relative path are relative to the Git repository where the push is
+    done.
+
+multimailhook.verbose
+
+    Verbosity level of git-multimail on its standard output. By
+    default, show only error and info messages. If set to true, show
+    also debug messages.
+
+Email filtering aids
+--------------------
+
+All emails include extra headers to enable fine tuned filtering and
+give information for debugging.  All emails include the headers
+``X-Git-Host``, ``X-Git-Repo``, ``X-Git-Refname``, and ``X-Git-Reftype``.
+ReferenceChange emails also include headers ``X-Git-Oldrev`` and ``X-Git-Newrev``;
+Revision emails also include header ``X-Git-Rev``.
+
+
+Customizing email contents
+--------------------------
+
+git-multimail mostly generates emails by expanding templates.  The
+templates can be customized.  To avoid the need to edit
+``git_multimail.py`` directly, the preferred way to change the templates
+is to write a separate Python script that imports ``git_multimail.py`` as
+a module, then replaces the templates in place.  See the provided
+post-receive script for an example of how this is done.
+
+
+Customizing git-multimail for your environment
+----------------------------------------------
+
+git-multimail is mostly customized via an "environment" that describes
+the local environment in which Git is running.  Two types of
+environment are built in:
+
+GenericEnvironment
+    a stand-alone Git repository.
+
+GitoliteEnvironment
+    a Git repository that is managed by gitolite_.  For such
+    repositories, the identity of the pusher is read from
+    environment variable $GL_USER, the name of the repository is read
+    from $GL_REPO (if it is not overridden by multimailhook.reponame),
+    and the From: header value is optionally read from gitolite.conf
+    (see multimailhook.from).
+
+By default, git-multimail assumes GitoliteEnvironment if $GL_USER and
+$GL_REPO are set, and otherwise assumes GenericEnvironment.
+Alternatively, you can choose one of these two environments explicitly
+by setting a ``multimailhook.environment`` config setting (which can
+have the value `generic` or `gitolite`) or by passing an --environment
+option to the script.
+
+If you need to customize the script in ways that are not supported by
+the existing environments, you can define your own environment class
+class using arbitrary Python code.  To do so, you need to import
+``git_multimail.py`` as a Python module, as demonstrated by the example
+post-receive script.  Then implement your environment class; it should
+usually inherit from one of the existing Environment classes and
+possibly one or more of the EnvironmentMixin classes.  Then set the
+``environment`` variable to an instance of your own environment class
+and pass it to ``run_as_post_receive_hook()``.
+
+The standard environment classes, GenericEnvironment and
+GitoliteEnvironment, are in fact themselves put together out of a
+number of mixin classes, each of which handles one aspect of the
+customization.  For the finest control over your configuration, you
+can specify exactly which mixin classes your own environment class
+should inherit from, and override individual methods (or even add your
+own mixin classes) to implement entirely new behaviors.  If you
+implement any mixins that might be useful to other people, please
+consider sharing them with the community!
+
+
+Getting involved
+----------------
+
+Please, read `<CONTRIBUTING.rst>`__ for instructions on how to
+contribute to git-multimail.
+
+
+Footnotes
+---------
+
+.. [1] Because of the way information is passed to update hooks, the
+       script's method of determining whether a commit has already
+       been seen does not work when it is used as an ``update`` script.
+       In particular, no notification email will be generated for a
+       new commit that is added to multiple references in the same
+       push. A workaround is to use --force-send to force sending the
+       emails.
+
+.. _gitolite: https://github.com/sitaramc/gitolite
index 00aedd9c579f9acc2c94dc8632f2c2b9fa2c96bc..505483310552fa303af4b3533754cd089b537073 100644 (file)
@@ -46,6 +46,15 @@ and add::
       config multimailhook.mailingList = # Where emails should be sent
       config multimailhook.from = # From address to use
 
+Note that by default, gitolite forbids ``<`` and ``>`` in variable
+values (for security/paranoia reasons, see
+`compensating for UNSAFE_PATT
+<http://gitolite.com/gitolite/git-config/index.html#compensating-for-unsafe95patt>`__
+in gitolite's documentation for explanations and a way to disable
+this). As a consequence, you will not be able to use ``First Last
+<First.Last@example.com>`` as recipient email, but specifying
+``First.Last@example.com`` alone works.
+
 Obviously, you can customize all parameters on a per-repository basis by
 adding these ``config multimailhook.*`` lines in the section
 corresponding to a repository or set of repositories.
index 73fdda6b14e331871cf4879ba85906b09cc0add3..8823399e7522e59f9d4f9b9304c1b0ac919cec1f 100755 (executable)
@@ -1,6 +1,6 @@
 #! /usr/bin/env python
 
-__version__ = '1.4.0'
+__version__ = '1.5.0'
 
 # Copyright (c) 2015-2016 Matthieu Moy and others
 # Copyright (c) 2012-2014 Michael Haggerty and others
@@ -64,7 +64,9 @@
     # Python < 2.6 do not have ssl, but that's OK if we don't use it.
     pass
 import time
-import cgi
+
+import uuid
+import base64
 
 PYTHON3 = sys.version_info >= (3, 0)
 
@@ -73,7 +75,7 @@ def all(iterable):
         for element in iterable:
             if not element:
                 return False
-            return True
+        return True
 
 
 def is_ascii(s):
@@ -108,6 +110,12 @@ def read_line(f):
             return out.decode(sys.getdefaultencoding())
         except UnicodeEncodeError:
             return out.decode(ENCODING)
+
+    import html
+
+    def html_escape(s):
+        return html.escape(s)
+
 else:
     def is_string(s):
         try:
@@ -130,6 +138,10 @@ def read_line(f):
     def next(it):
         return it.next()
 
+    import cgi
+
+    def html_escape(s):
+        return cgi.escape(s, True)
 
 try:
     from email.charset import Charset
@@ -190,6 +202,7 @@ def next(it):
 Message-ID: %(msgid)s
 From: %(fromaddr)s
 Reply-To: %(reply_to)s
+Thread-Index: %(thread_index)s
 X-Git-Host: %(fqdn)s
 X-Git-Repo: %(repo_shortname)s
 X-Git-Refname: %(refname)s
@@ -322,6 +335,7 @@ def next(it):
 Reply-To: %(reply_to)s
 In-Reply-To: %(reply_to_msgid)s
 References: %(reply_to_msgid)s
+Thread-Index: %(thread_index)s
 X-Git-Host: %(fqdn)s
 X-Git-Repo: %(repo_shortname)s
 X-Git-Refname: %(refname)s
@@ -763,6 +777,9 @@ def get_summary(self):
     def __eq__(self, other):
         return isinstance(other, GitObject) and self.sha1 == other.sha1
 
+    def __ne__(self, other):
+        return not self == other
+
     def __hash__(self):
         return hash(self.sha1)
 
@@ -852,7 +869,7 @@ def expand_lines(self, template, html_escape_val=False, **extra_values):
         if html_escape_val:
             for k in values:
                 if is_string(values[k]):
-                    values[k] = cgi.escape(values[k], True)
+                    values[k] = html_escape(values[k])
         for line in template.splitlines(True):
             yield line % values
 
@@ -909,7 +926,7 @@ def generate_email_intro(self, html_escape_val=False):
 
         raise NotImplementedError()
 
-    def generate_email_body(self):
+    def generate_email_body(self, push):
         """Generate the main part of the email body, a line at a time.
 
         The text in the body might be truncated after a specified
@@ -936,7 +953,7 @@ def _wrap_for_html(self, lines):
             yield "<pre style='margin:0'>\n"
 
             for line in lines:
-                yield cgi.escape(line)
+                yield html_escape(line)
 
             yield '</pre>\n'
         else:
@@ -1011,7 +1028,7 @@ def generate_email(self, push, body_filter=None, extra_header_values={}):
                     fgcolor = '404040'
 
                 # Chop the trailing LF, we don't want it inside <pre>.
-                line = cgi.escape(line[:-1])
+                line = html_escape(line[:-1])
 
                 if bgcolor or fgcolor:
                     style = 'display:block; white-space:pre;'
@@ -1060,6 +1077,10 @@ def __init__(self, reference_change, rev, num, tot):
         self.author = read_git_output(['log', '--no-walk', '--format=%aN <%aE>', self.rev.sha1])
         self.recipients = self.environment.get_revision_recipients(self)
 
+        # -s is short for --no-patch, but -s works on older git's (e.g. 1.7)
+        self.parents = read_git_lines(['show', '-s', '--format=%P',
+                                      self.rev.sha1])[0].split()
+
         self.cc_recipients = ''
         if self.environment.get_scancommitforcc():
             self.cc_recipients = ', '.join(to.strip() for to in self._cc_recipients())
@@ -1090,6 +1111,7 @@ def _compute_values(self):
             oneline = oneline[:max_subject_length - 6] + ' [...]'
 
         values['rev'] = self.rev.sha1
+        values['parents'] = ' '.join(self.parents)
         values['rev_short'] = self.rev.short
         values['change_type'] = self.change_type
         values['refname'] = self.refname
@@ -1097,6 +1119,7 @@ def _compute_values(self):
         values['short_refname'] = self.reference_change.short_refname
         values['refname_type'] = self.reference_change.refname_type
         values['reply_to_msgid'] = self.reference_change.msgid
+        values['thread_index'] = self.reference_change.thread_index
         values['num'] = self.num
         values['tot'] = self.tot
         values['recipients'] = self.recipients
@@ -1244,6 +1267,23 @@ def create(environment, oldrev, newrev, refname):
             old=old, new=new, rev=rev,
             )
 
+    @staticmethod
+    def make_thread_index():
+        """Return a string appropriate for the Thread-Index header,
+        needed by MS Outlook to get threading right.
+
+        The format is (base64-encoded):
+        - 1 byte must be 1
+        - 5 bytes encode a date (hardcoded here)
+        - 16 bytes for a globally unique identifier
+
+        FIXME: Unfortunately, even with the Thread-Index field, MS
+        Outlook doesn't seem to do the threading reliably (see
+        https://github.com/git-multimail/git-multimail/pull/194).
+        """
+        thread_index = b'\x01\x00\x00\x12\x34\x56' + uuid.uuid4().bytes
+        return base64.standard_b64encode(thread_index).decode('ascii')
+
     def __init__(self, environment, refname, short_refname, old, new, rev):
         Change.__init__(self, environment)
         self.change_type = {
@@ -1257,6 +1297,7 @@ def __init__(self, environment, refname, short_refname, old, new, rev):
         self.new = new
         self.rev = rev
         self.msgid = make_msgid()
+        self.thread_index = self.make_thread_index()
         self.diffopts = environment.diffopts
         self.graphopts = environment.graphopts
         self.logopts = environment.logopts
@@ -1276,6 +1317,7 @@ def _compute_values(self):
         values['refname'] = self.refname
         values['short_refname'] = self.short_refname
         values['msgid'] = self.msgid
+        values['thread_index'] = self.thread_index
         values['recipients'] = self.recipients
         values['oldrev'] = str(self.old)
         values['oldrev_short'] = self.old.short
@@ -1941,6 +1983,9 @@ class Mailer(object):
     def __init__(self, environment):
         self.environment = environment
 
+    def close(self):
+        pass
+
     def send(self, lines, to_addrs):
         """Send an email consisting of lines.
 
@@ -2054,6 +2099,7 @@ def __init__(self, environment,
         self.username = smtpuser
         self.password = smtppass
         self.smtpcacerts = smtpcacerts
+        self.loggedin = False
         try:
             def call(klass, server, timeout):
                 try:
@@ -2130,20 +2176,30 @@ def call(klass, server, timeout):
                 % (self.smtpserver, sys.exc_info()[1]))
             sys.exit(1)
 
-    def __del__(self):
+    def close(self):
         if hasattr(self, 'smtp'):
             self.smtp.quit()
             del self.smtp
 
+    def __del__(self):
+        self.close()
+
     def send(self, lines, to_addrs):
         try:
             if self.username or self.password:
-                self.smtp.login(self.username, self.password)
+                if not self.loggedin:
+                    self.smtp.login(self.username, self.password)
+                    self.loggedin = True
             msg = ''.join(lines)
             # turn comma-separated list into Python list if needed.
             if is_string(to_addrs):
                 to_addrs = [email for (name, email) in getaddresses([to_addrs])]
             self.smtp.sendmail(self.envelopesender, to_addrs, msg)
+        except socket.timeout:
+            self.environment.get_logger().error(
+                '*** Error sending email ***\n'
+                '*** SMTP server timed out (timeout is %s)\n'
+                % self.smtpservertimeout)
         except smtplib.SMTPResponseException:
             err = sys.exc_info()[1]
             self.environment.get_logger().error(
@@ -2171,7 +2227,8 @@ class OutputMailer(Mailer):
 
     SEPARATOR = '=' * 75 + '\n'
 
-    def __init__(self, f):
+    def __init__(self, f, environment=None):
+        super(OutputMailer, self).__init__(environment=environment)
         self.f = f
 
     def send(self, lines, to_addrs):
@@ -2382,6 +2439,7 @@ def __init__(self, osenv=None):
         self.html_in_footer = False
         self.commitBrowseURL = None
         self.maxcommitemails = 500
+        self.excludemergerevisions = False
         self.diffopts = ['--stat', '--summary', '--find-copies-harder']
         self.graphopts = ['--oneline', '--decorate']
         self.logopts = []
@@ -2621,6 +2679,8 @@ def __init__(self, config, **kw):
 
         self.commitBrowseURL = config.get('commitBrowseURL')
 
+        self.excludemergerevisions = config.get('excludeMergeRevisions')
+
         maxcommitemails = config.get('maxcommitemails')
         if maxcommitemails is not None:
             try:
@@ -3152,7 +3212,10 @@ def get_pusher(self):
         return self.osenv.get('GL_USER', 'unknown user')
 
 
-class GitoliteEnvironmentLowPrecMixin(Environment):
+class GitoliteEnvironmentLowPrecMixin(
+        ConfigEnvironmentMixin,
+        Environment):
+
     def get_repo_shortname(self):
         # The gitolite environment variable $GL_REPO is a pretty good
         # repo_shortname (though it's probably not as good as a value
@@ -3162,6 +3225,16 @@ def get_repo_shortname(self):
             super(GitoliteEnvironmentLowPrecMixin, self).get_repo_shortname()
             )
 
+    @staticmethod
+    def _compile_regex(re_template):
+        return (
+            re.compile(re_template % x)
+            for x in (
+                r'BEGIN\s+USER\s+EMAILS',
+                r'([^\s]+)\s+(.*)',
+                r'END\s+USER\s+EMAILS',
+                ))
+
     def get_fromaddr(self, change=None):
         GL_USER = self.osenv.get('GL_USER')
         if GL_USER is not None:
@@ -3174,18 +3247,42 @@ def get_fromaddr(self, change=None):
             GL_CONF = self.osenv.get(
                 'GL_CONF',
                 os.path.join(GL_ADMINDIR, 'conf', 'gitolite.conf'))
+
+            mailaddress_map = self.config.get('MailaddressMap')
+            # If relative, consider relative to GL_CONF:
+            if mailaddress_map:
+                mailaddress_map = os.path.join(os.path.dirname(GL_CONF),
+                                               mailaddress_map)
+                if os.path.isfile(mailaddress_map):
+                    f = open(mailaddress_map, 'rU')
+                    try:
+                        # Leading '#' is optional
+                        re_begin, re_user, re_end = self._compile_regex(
+                            r'^(?:\s*#)?\s*%s\s*$')
+                        for l in f:
+                            l = l.rstrip('\n')
+                            if re_begin.match(l) or re_end.match(l):
+                                continue  # Ignore these lines
+                            m = re_user.match(l)
+                            if m:
+                                if m.group(1) == GL_USER:
+                                    return m.group(2)
+                                else:
+                                    continue  # Not this user, but not an error
+                            raise ConfigurationException(
+                                "Syntax error in mail address map.\n"
+                                "Check file {}.\n"
+                                "Line: {}".format(mailaddress_map, l))
+
+                    finally:
+                        f.close()
+
             if os.path.isfile(GL_CONF):
                 f = open(GL_CONF, 'rU')
                 try:
                     in_user_emails_section = False
-                    re_template = r'^\s*#\s*%s\s*$'
-                    re_begin, re_user, re_end = (
-                        re.compile(re_template % x)
-                        for x in (
-                            r'BEGIN\s+USER\s+EMAILS',
-                            re.escape(GL_USER) + r'\s+(.*)',
-                            r'END\s+USER\s+EMAILS',
-                            ))
+                    re_begin, re_user, re_end = self._compile_regex(
+                        r'^\s*#\s*%s\s*$')
                     for l in f:
                         l = l.rstrip('\n')
                         if not in_user_emails_section:
@@ -3195,8 +3292,8 @@ def get_fromaddr(self, change=None):
                         if re_end.match(l):
                             break
                         m = re_user.match(l)
-                        if m:
-                            return m.group(1)
+                        if m and m.group(1) == GL_USER:
+                            return m.group(2)
                 finally:
                     f.close()
         return super(GitoliteEnvironmentLowPrecMixin, self).get_fromaddr(change)
@@ -3228,7 +3325,7 @@ def __init__(self, user=None, repo=None, **kw):
         self.__repo = repo
 
     def get_pusher(self):
-        return re.match('(.*?)\s*<', self.__user).group(1)
+        return re.match(r'(.*?)\s*<', self.__user).group(1)
 
     def get_pusher_email(self):
         return self.__user
@@ -3262,7 +3359,7 @@ def get_pusher(self):
             if self.__submitter.find('<') != -1:
                 # Submitter has a configured email, we transformed
                 # __submitter into an RFC 2822 string already.
-                return re.match('(.*?)\s*<', self.__submitter).group(1)
+                return re.match(r'(.*?)\s*<', self.__submitter).group(1)
             else:
                 # Submitter has no configured email, it's just his name.
                 return self.__submitter
@@ -3615,6 +3712,9 @@ def send_emails(self, mailer, body_filter=None):
 
             for (num, sha1) in enumerate(sha1s):
                 rev = Revision(change, GitObject(sha1), num=num + 1, tot=len(sha1s))
+                if len(rev.parents) > 1 and change.environment.excludemergerevisions:
+                    # skipping a merge commit
+                    continue
                 if not rev.recipients and rev.cc_recipients:
                     change.environment.log_msg('*** Replacing Cc: with To:')
                     rev.recipients = rev.cc_recipients
@@ -3664,11 +3764,14 @@ def run_as_post_receive_hook(environment, mailer):
         changes.append(
             ReferenceChange.create(environment, oldrev, newrev, refname)
             )
-    if changes:
-        push = Push(environment, changes)
+    if not changes:
+        mailer.close()
+        return
+    push = Push(environment, changes)
+    try:
         push.send_emails(mailer, body_filter=environment.filter_body)
-    if hasattr(mailer, '__del__'):
-        mailer.__del__()
+    finally:
+        mailer.close()
 
 
 def run_as_update_hook(environment, mailer, refname, oldrev, newrev, force_send=False):
@@ -3687,10 +3790,14 @@ def run_as_update_hook(environment, mailer, refname, oldrev, newrev, force_send=
             refname,
             ),
         ]
+    if not changes:
+        mailer.close()
+        return
     push = Push(environment, changes, force_send)
-    push.send_emails(mailer, body_filter=environment.filter_body)
-    if hasattr(mailer, '__del__'):
-        mailer.__del__()
+    try:
+        push.send_emails(mailer, body_filter=environment.filter_body)
+    finally:
+        mailer.close()
 
 
 def check_ref_filter(environment):
@@ -3860,7 +3967,7 @@ def build_environment_klass(env_name):
         low_prec_mixin = known_env['lowprec']
         environment_mixins.append(low_prec_mixin)
     environment_mixins.append(Environment)
-    klass_name = env_name.capitalize() + 'Environement'
+    klass_name = env_name.capitalize() + 'Environment'
     environment_klass = type(
         klass_name,
         tuple(environment_mixins),
@@ -4057,21 +4164,21 @@ def flush(self):
                 environment, 'git_multimail.error', environment.error_log_file, logging.ERROR)
             self.loggers.append(error_log_file)
 
-    def info(self, msg):
+    def info(self, msg, *args, **kwargs):
         for l in self.loggers:
-            l.info(msg)
+            l.info(msg, *args, **kwargs)
 
-    def debug(self, msg):
+    def debug(self, msg, *args, **kwargs):
         for l in self.loggers:
-            l.debug(msg)
+            l.debug(msg, *args, **kwargs)
 
-    def warning(self, msg):
+    def warning(self, msg, *args, **kwargs):
         for l in self.loggers:
-            l.warning(msg)
+            l.warning(msg, *args, **kwargs)
 
-    def error(self, msg):
+    def error(self, msg, *args, **kwargs):
         for l in self.loggers:
-            l.error(msg)
+            l.error(msg, *args, **kwargs)
 
 
 def main(args):
@@ -4189,7 +4296,7 @@ def main(args):
             show_env(environment, sys.stderr)
 
         if options.stdout or environment.stdout:
-            mailer = OutputMailer(sys.stdout)
+            mailer = OutputMailer(sys.stdout, environment)
         else:
             mailer = choose_mailer(config, environment)
 
@@ -4234,5 +4341,6 @@ def main(args):
             sys.stderr.write(msg)
         sys.exit(1)
 
+
 if __name__ == '__main__':
     main(sys.argv[1:])
index 992657bbdc3545070496fbb43a287679cba03ca1..241ba22fa3c88f004798559a986cc51934b5d4f9 100755 (executable)
@@ -110,11 +110,12 @@ def is_section_empty(section, local):
 
     try:
         read_output(
-            ['git', 'config']
-            + local_option
-            ['--get-regexp', '^%s\.' % (section,)]
+            ['git', 'config'] +
+            local_option +
+            ['--get-regexp', '^%s\.' % (section,)]
             )
-    except CommandError, e:
+    except CommandError:
+        t, e, traceback = sys.exc_info()
         if e.retcode == 1:
             # This means that no settings were found.
             return True
@@ -188,7 +189,9 @@ def migrate_config(strict=False, retain=False, overwrite=False):
             sys.stderr.write(
                 '...copying "%s.%s" to "%s.%s"\n' % (old.section, name, new.section, name)
                 )
-            new.set_recipients(name, old.get_recipients(name))
+            old_recipients = old.get_all(name, default=None)
+            old_recipients = ', '.join(o.strip() for o in old_recipients)
+            new.set_recipients(name, old_recipients)
 
     if strict:
         sys.stderr.write(
index 1ea113d274e27adfede78bd5b5530608a47fa378..b9bb11834e1f2f0160ed6b56c4b6cd363006c731 100755 (executable)
@@ -30,7 +30,6 @@ script's behavior could be changed or customized.
 """
 
 import sys
-import os
 
 # If necessary, add the path to the directory containing
 # git_multimail.py to the Python path as follows.  (This is not
@@ -86,6 +85,7 @@ mailer = git_multimail.choose_mailer(config, environment)
 
 # Use Python's smtplib to send emails.  Both arguments are required.
 #mailer = git_multimail.SMTPMailer(
+#    environment=environment,
 #    envelopesender='git-repo@example.com',
 #    # The smtpserver argument can also include a port number; e.g.,
 #    #     smtpserver='mail.example.com:25'
index e0848226d21bbbeb26d9ac6217fe1e61ccc71fca..0d89ae7c2302a4bff3a6fdcb4a7015a81eeb8025 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -705,7 +705,7 @@ static int filter_buffer_or_fd(int in, int out, void *data)
 }
 
 static int apply_single_file_filter(const char *path, const char *src, size_t len, int fd,
-                        struct strbuf *dst, const char *cmd)
+                                   struct strbuf *dst, const char *cmd)
 {
        /*
         * Create a pipeline to have the command filter the buffer's
@@ -778,7 +778,8 @@ static int start_multi_file_filter_fn(struct subprocess_entry *subprocess)
 
 static void handle_filter_error(const struct strbuf *filter_status,
                                struct cmd2process *entry,
-                               const unsigned int wanted_capability) {
+                               const unsigned int wanted_capability)
+{
        if (!strcmp(filter_status->buf, "error"))
                ; /* The filter signaled a problem with the file. */
        else if (!strcmp(filter_status->buf, "abort") && wanted_capability) {
@@ -1091,7 +1092,7 @@ static int count_ident(const char *cp, unsigned long size)
 }
 
 static int ident_to_git(const char *path, const char *src, size_t len,
-                        struct strbuf *buf, int ident)
+                       struct strbuf *buf, int ident)
 {
        char *dst, *dollar;
 
@@ -1135,7 +1136,7 @@ static int ident_to_git(const char *path, const char *src, size_t len,
 }
 
 static int ident_to_worktree(const char *path, const char *src, size_t len,
-                             struct strbuf *buf, int ident)
+                            struct strbuf *buf, int ident)
 {
        struct object_id oid;
        char *to_free = NULL, *dollar, *spc;
index 4dfbc8c9f917a600c0995b7e33927df3fa19453d..ec1271f89ce08b3b117fe09715f61730c7943bea 100644 (file)
@@ -91,7 +91,8 @@ static timestamp_t check_expirations(void)
 }
 
 static int read_request(FILE *fh, struct credential *c,
-                       struct strbuf *action, int *timeout) {
+                       struct strbuf *action, int *timeout)
+{
        static struct strbuf item = STRBUF_INIT;
        const char *p;
 
index 8e5018e40614f3af617440fb0a2ee2f4b9e1d32c..191a930705480e044e816c2ba62afe039036eaf3 100644 (file)
@@ -190,13 +190,15 @@ static void set_island_marks(struct object *obj, struct island_bitmap *marks)
        island_bitmap_or(b, marks);
 }
 
-static void mark_remote_island_1(struct remote_island *rl, int is_core_island)
+static void mark_remote_island_1(struct repository *r,
+                                struct remote_island *rl,
+                                int is_core_island)
 {
        uint32_t i;
 
        for (i = 0; i < rl->oids.nr; ++i) {
                struct island_bitmap *marks;
-               struct object *obj = parse_object(the_repository, &rl->oids.oid[i]);
+               struct object *obj = parse_object(r, &rl->oids.oid[i]);
 
                if (!obj)
                        continue;
@@ -211,7 +213,7 @@ static void mark_remote_island_1(struct remote_island *rl, int is_core_island)
                while (obj && obj->type == OBJ_TAG) {
                        obj = ((struct tag *)obj)->tagged;
                        if (obj) {
-                               parse_object(the_repository, &obj->oid);
+                               parse_object(r, &obj->oid);
                                marks = create_or_get_island_marks(obj);
                                island_bitmap_set(marks, island_counter);
                        }
@@ -237,7 +239,9 @@ static int tree_depth_compare(const void *a, const void *b)
        return todo_a->depth - todo_b->depth;
 }
 
-void resolve_tree_islands(int progress, struct packing_data *to_pack)
+void resolve_tree_islands(struct repository *r,
+                         int progress,
+                         struct packing_data *to_pack)
 {
        struct progress *progress_state = NULL;
        struct tree_islands_todo *todo;
@@ -281,7 +285,7 @@ void resolve_tree_islands(int progress, struct packing_data *to_pack)
 
                root_marks = kh_value(island_marks, pos);
 
-               tree = lookup_tree(the_repository, &ent->idx.oid);
+               tree = lookup_tree(r, &ent->idx.oid);
                if (!tree || parse_tree(tree) < 0)
                        die(_("bad tree object %s"), oid_to_hex(&ent->idx.oid));
 
@@ -292,7 +296,7 @@ void resolve_tree_islands(int progress, struct packing_data *to_pack)
                        if (S_ISGITLINK(entry.mode))
                                continue;
 
-                       obj = lookup_object(the_repository, entry.oid->hash);
+                       obj = lookup_object(r, entry.oid->hash);
                        if (!obj)
                                continue;
 
@@ -415,7 +419,7 @@ static struct remote_island *get_core_island(void)
        return NULL;
 }
 
-static void deduplicate_islands(void)
+static void deduplicate_islands(struct repository *r)
 {
        struct remote_island *island, *core = NULL, **list;
        unsigned int island_count, dst, src, ref, i = 0;
@@ -444,20 +448,20 @@ static void deduplicate_islands(void)
        core = get_core_island();
 
        for (i = 0; i < island_count; ++i) {
-               mark_remote_island_1(list[i], core && list[i]->hash == core->hash);
+               mark_remote_island_1(r, list[i], core && list[i]->hash == core->hash);
        }
 
        free(list);
 }
 
-void load_delta_islands(void)
+void load_delta_islands(struct repository *r)
 {
        island_marks = kh_init_sha1();
        remote_islands = kh_init_str();
 
        git_config(island_config_callback, NULL);
        for_each_ref(find_island_for_ref, NULL);
-       deduplicate_islands();
+       deduplicate_islands(r);
 
        fprintf(stderr, _("Marked %d islands, done.\n"), island_counter);
 }
index b635cd07d8d80ea14b86e72da5dcaee1fb4ab11a..3ac8045d8c528be81ac1cbefe9942c534e3c498a 100644 (file)
@@ -1,14 +1,17 @@
 #ifndef DELTA_ISLANDS_H
 #define DELTA_ISLANDS_H
 
+struct commit;
 struct object_id;
 struct packing_data;
-struct commit;
+struct repository;
 
 int island_delta_cmp(const struct object_id *a, const struct object_id *b);
 int in_same_island(const struct object_id *, const struct object_id *);
-void resolve_tree_islands(int progress, struct packing_data *to_pack);
-void load_delta_islands(void);
+void resolve_tree_islands(struct repository *r,
+                         int progress,
+                         struct packing_data *to_pack);
+void load_delta_islands(struct repository *r);
 void propagate_island_marks(struct commit *commit);
 int compute_pack_layers(struct packing_data *to_pack);
 
index 83fce51518854754ee6f4d95cca86d61cc10e4cf..23c8d351b3aa5912c49c9da0eecd8727cf06ac72 100644 (file)
@@ -542,7 +542,7 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)
 {
        struct rev_info revs;
 
-       repo_init_revisions(the_repository, &revs, NULL);
+       repo_init_revisions(opt->repo, &revs, NULL);
        copy_pathspec(&revs.prune_data, &opt->pathspec);
        revs.diffopt = *opt;
 
@@ -551,13 +551,14 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)
        return 0;
 }
 
-int index_differs_from(const char *def, const struct diff_flags *flags,
+int index_differs_from(struct repository *r,
+                      const char *def, const struct diff_flags *flags,
                       int ita_invisible_in_index)
 {
        struct rev_info rev;
        struct setup_revision_opt opt;
 
-       repo_init_revisions(the_repository, &rev, NULL);
+       repo_init_revisions(r, &rev, NULL);
        memset(&opt, 0, sizeof(opt));
        opt.def = def;
        setup_revisions(0, NULL, &rev, &opt);
diff --git a/diff.c b/diff.c
index dc9965e836cd49c46a01293ef1d678a619b8f997..1b5f27636061feb0ecf273f257c5e080c5ff7481 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -291,7 +291,7 @@ static int parse_color_moved(const char *arg)
                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)
+static unsigned parse_color_moved_ws(const char *arg)
 {
        int ret = 0;
        struct string_list l = STRING_LIST_INIT_DUP;
@@ -312,15 +312,19 @@ static int parse_color_moved_ws(const char *arg)
                        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);
+               else {
+                       ret |= COLOR_MOVED_WS_ERROR;
+                       error(_("unknown color-moved-ws mode '%s', possible values are 'ignore-space-change', 'ignore-space-at-eol', 'ignore-all-space', 'allow-indentation-change'"), 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"));
+           (ret & XDF_WHITESPACE_FLAGS)) {
+               error(_("color-moved-ws: allow-indentation-change cannot be combined with other white space modes"));
+               ret |= COLOR_MOVED_WS_ERROR;
+       }
 
        string_list_clear(&l, 0);
 
@@ -341,8 +345,8 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
                return 0;
        }
        if (!strcmp(var, "diff.colormovedws")) {
-               int cm = parse_color_moved_ws(value);
-               if (cm < 0)
+               unsigned cm = parse_color_moved_ws(value);
+               if (cm & COLOR_MOVED_WS_ERROR)
                        return -1;
                diff_color_moved_ws_default = cm;
                return 0;
@@ -1637,7 +1641,8 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
        strbuf_release(&msgbuf);
 }
 
-static struct diff_tempfile *claim_diff_tempfile(void) {
+static struct diff_tempfile *claim_diff_tempfile(void)
+{
        int i;
        for (i = 0; i < ARRAY_SIZE(diff_temp); i++)
                if (!diff_temp[i].name)
@@ -3313,14 +3318,14 @@ void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const
                options->b_prefix = b;
 }
 
-struct userdiff_driver *get_textconv(struct index_state *istate,
+struct userdiff_driver *get_textconv(struct repository *r,
                                     struct diff_filespec *one)
 {
        if (!DIFF_FILE_VALID(one))
                return NULL;
 
-       diff_filespec_load_driver(one, istate);
-       return userdiff_get_textconv(one->driver);
+       diff_filespec_load_driver(one, r->index);
+       return userdiff_get_textconv(r, one->driver);
 }
 
 static void builtin_diff(const char *name_a,
@@ -3369,8 +3374,8 @@ static void builtin_diff(const char *name_a,
        }
 
        if (o->flags.allow_textconv) {
-               textconv_one = get_textconv(o->repo->index, one);
-               textconv_two = get_textconv(o->repo->index, two);
+               textconv_one = get_textconv(o->repo, one);
+               textconv_two = get_textconv(o->repo, two);
        }
 
        /* Never use a non-valid filename anywhere if at all possible */
@@ -4819,7 +4824,8 @@ static int parse_diff_filter_opt(const char *optarg, struct diff_options *opt)
        return 0;
 }
 
-static void enable_patch_output(int *fmt) {
+static void enable_patch_output(int *fmt)
+{
        *fmt &= ~DIFF_FORMAT_NO_OUTPUT;
        *fmt |= DIFF_FORMAT_PATCH;
 }
@@ -5034,10 +5040,13 @@ int diff_opt_parse(struct diff_options *options,
        else if (skip_prefix(arg, "--color-moved=", &arg)) {
                int cm = parse_color_moved(arg);
                if (cm < 0)
-                       die("bad --color-moved argument: %s", arg);
+                       return error("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);
+               unsigned cm = parse_color_moved_ws(arg);
+               if (cm & COLOR_MOVED_WS_ERROR)
+                       return -1;
+               options->color_moved_ws_handling = cm;
        } else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
                options->use_color = 1;
                options->word_diff = DIFF_WORDS_COLOR;
@@ -6434,7 +6443,7 @@ int textconv_object(struct repository *r,
 
        df = alloc_filespec(path);
        fill_filespec(df, oid, oid_valid, mode);
-       textconv = get_textconv(r->index, df);
+       textconv = get_textconv(r, df);
        if (!textconv) {
                free_filespec(df);
                return 0;
diff --git a/diff.h b/diff.h
index ce5e8a8183e848b2e36d50bea271f687a450e3af..b512d0477ac3a4a0338094a4d3b21770ecb57dd8 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -225,7 +225,8 @@ struct diff_options {
 
        /* 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;
+       #define COLOR_MOVED_WS_ERROR (1<<0)
+       unsigned color_moved_ws_handling;
 
        struct repository *repo;
 };
@@ -436,7 +437,8 @@ int diff_result_code(struct diff_options *, int);
 
 void diff_no_index(struct repository *, struct rev_info *, int, const char **);
 
-int index_differs_from(const char *def, const struct diff_flags *flags,
+int index_differs_from(struct repository *r, const char *def,
+                      const struct diff_flags *flags,
                       int ita_invisible_in_index);
 
 /*
@@ -460,7 +462,7 @@ size_t fill_textconv(struct repository *r,
  * and only if it has textconv enabled (otherwise return NULL). The result
  * can be passed to fill_textconv().
  */
-struct userdiff_driver *get_textconv(struct index_state *istate,
+struct userdiff_driver *get_textconv(struct repository *r,
                                     struct diff_filespec *one);
 
 /*
index 69fc55ea1e34af69b7ed4d57e521cb4825f99fd2..a9c6d60df22862e47ccb7fc1c7de9ed7cc4b1236 100644 (file)
@@ -140,8 +140,8 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
                return 0;
 
        if (o->flags.allow_textconv) {
-               textconv_one = get_textconv(o->repo->index, p->one);
-               textconv_two = get_textconv(o->repo->index, p->two);
+               textconv_one = get_textconv(o->repo, p->one);
+               textconv_two = get_textconv(o->repo, p->two);
        }
 
        /*
@@ -154,6 +154,12 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
        if (textconv_one == textconv_two && diff_unmodified_pair(p))
                return 0;
 
+       if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+           !o->flags.text &&
+           ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+            (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+               return 0;
+
        mf1.size = fill_textconv(o->repo, textconv_one, p->one, &mf1.ptr);
        mf2.size = fill_textconv(o->repo, textconv_two, p->two, &mf2.ptr);
 
diff --git a/dir.c b/dir.c
index ab6477d777e96cb9789f1c6b3220af349731a701..21284482198147687fb03892265f97ac5ed58d18 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -276,44 +276,6 @@ 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 struct index_state *istate,
-                      const char *name, int namelen,
-                      const struct pathspec_item *item)
-{
-       int i;
-       char *to_free = NULL;
-
-       if (name[namelen])
-               name = to_free = xmemdupz(name, namelen);
-
-       git_check_attr(istate, name, item->attr_check);
-
-       free(to_free);
-
-       for (i = 0; i < item->attr_match_nr; i++) {
-               const char *value;
-               int matched;
-               enum attr_match_mode match_mode;
-
-               value = item->attr_check->items[i].value;
-               match_mode = item->attr_match[i].match_mode;
-
-               if (ATTR_TRUE(value))
-                       matched = (match_mode == MATCH_SET);
-               else if (ATTR_FALSE(value))
-                       matched = (match_mode == MATCH_UNSET);
-               else if (ATTR_UNSET(value))
-                       matched = (match_mode == MATCH_UNSPECIFIED);
-               else
-                       matched = (match_mode == MATCH_VALUE &&
-                                  !strcmp(item->attr_match[i].value, value));
-               if (!matched)
-                       return 0;
-       }
-
-       return 1;
-}
-
 /*
  * Does 'match' match the given name?
  * A match is found if
@@ -367,7 +329,8 @@ static int match_pathspec_item(const struct index_state *istate,
            strncmp(item->match, name - prefix, item->prefix))
                return 0;
 
-       if (item->attr_match_nr && !match_attrs(istate, name, namelen, item))
+       if (item->attr_match_nr &&
+           !match_pathspec_attrs(istate, name, namelen, item))
                return 0;
 
        /* If the match was just the prefix, we matched */
diff --git a/entry.c b/entry.c
index 0a3c451f5f0f08deabe20b4ca1858825f2b29f3f..6fd72b30c8768677f044923ef5e715949d32fdae 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -161,7 +161,7 @@ static int remove_available_paths(struct string_list_item *item, void *cb_data)
        return !available;
 }
 
-int finish_delayed_checkout(struct checkout *state)
+int finish_delayed_checkout(struct checkout *state, int *nr_checkouts)
 {
        int errs = 0;
        unsigned delayed_object_count;
@@ -226,7 +226,7 @@ int finish_delayed_checkout(struct checkout *state)
                                ce = index_file_exists(state->istate, path->string,
                                                       strlen(path->string), 0);
                                if (ce) {
-                                       errs |= checkout_entry(ce, state, NULL);
+                                       errs |= checkout_entry(ce, state, NULL, nr_checkouts);
                                        filtered_bytes += ce->ce_stat_data.sd_size;
                                        display_throughput(progress, filtered_bytes);
                                } else
@@ -435,8 +435,8 @@ static void mark_colliding_entries(const struct checkout *state,
  * its name is returned in topath[], which must be able to hold at
  * least TEMPORARY_FILENAME_LENGTH bytes long.
  */
-int checkout_entry(struct cache_entry *ce,
-                  const struct checkout *state, char *topath)
+int checkout_entry(struct cache_entry *ce, const struct checkout *state,
+                  char *topath, int *nr_checkouts)
 {
        static struct strbuf path = STRBUF_INIT;
        struct stat st;
@@ -506,5 +506,7 @@ int checkout_entry(struct cache_entry *ce,
                return 0;
 
        create_directories(path.buf, path.len, state);
+       if (nr_checkouts)
+               (*nr_checkouts)++;
        return write_entry(ce, path.buf, state, 0);
 }
index 346559770773e923766c06593ada84c72815061f..0e37741d838256d196b2ec9f3ca4e54395c66d31 100644 (file)
@@ -274,9 +274,9 @@ const char *get_git_work_tree(void)
 
 char *get_object_directory(void)
 {
-       if (!the_repository->objects->objectdir)
+       if (!the_repository->objects->odb)
                BUG("git environment hasn't been setup");
-       return the_repository->objects->objectdir;
+       return the_repository->objects->odb->path;
 }
 
 int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
index 69886687ce95fd7dfe5363d0c776e21241b6b830..b7ba755c2b88df35d5e50272d7b9341134625c56 100644 (file)
@@ -1,157 +1,3 @@
-/*
-(See Documentation/git-fast-import.txt for maintained documentation.)
-Format of STDIN stream:
-
-  stream ::= cmd*;
-
-  cmd ::= new_blob
-        | new_commit
-        | new_tag
-        | reset_branch
-        | checkpoint
-        | progress
-        ;
-
-  new_blob ::= 'blob' lf
-    mark?
-    file_content;
-  file_content ::= data;
-
-  new_commit ::= 'commit' sp ref_str lf
-    mark?
-    ('author' (sp name)? sp '<' email '>' sp when lf)?
-    'committer' (sp name)? sp '<' email '>' sp when lf
-    commit_msg
-    ('from' sp commit-ish lf)?
-    ('merge' sp commit-ish lf)*
-    (file_change | ls)*
-    lf?;
-  commit_msg ::= data;
-
-  ls ::= 'ls' sp '"' quoted(path) '"' lf;
-
-  file_change ::= file_clr
-    | file_del
-    | file_rnm
-    | file_cpy
-    | file_obm
-    | file_inm;
-  file_clr ::= 'deleteall' lf;
-  file_del ::= 'D' sp path_str lf;
-  file_rnm ::= 'R' sp path_str sp path_str lf;
-  file_cpy ::= 'C' sp path_str sp path_str lf;
-  file_obm ::= 'M' sp mode sp (hexsha1 | idnum) sp path_str lf;
-  file_inm ::= 'M' sp mode sp 'inline' sp path_str lf
-    data;
-  note_obm ::= 'N' sp (hexsha1 | idnum) sp commit-ish lf;
-  note_inm ::= 'N' sp 'inline' sp commit-ish lf
-    data;
-
-  new_tag ::= 'tag' sp tag_str lf
-    'from' sp commit-ish lf
-    ('tagger' (sp name)? sp '<' email '>' sp when lf)?
-    tag_msg;
-  tag_msg ::= data;
-
-  reset_branch ::= 'reset' sp ref_str lf
-    ('from' sp commit-ish lf)?
-    lf?;
-
-  checkpoint ::= 'checkpoint' lf
-    lf?;
-
-  progress ::= 'progress' sp not_lf* lf
-    lf?;
-
-     # note: the first idnum in a stream should be 1 and subsequent
-     # idnums should not have gaps between values as this will cause
-     # the stream parser to reserve space for the gapped values.  An
-     # idnum can be updated in the future to a new object by issuing
-     # a new mark directive with the old idnum.
-     #
-  mark ::= 'mark' sp idnum lf;
-  data ::= (delimited_data | exact_data)
-    lf?;
-
-    # note: delim may be any string but must not contain lf.
-    # data_line may contain any data but must not be exactly
-    # delim.
-  delimited_data ::= 'data' sp '<<' delim lf
-    (data_line lf)*
-    delim lf;
-
-     # note: declen indicates the length of binary_data in bytes.
-     # declen does not include the lf preceding the binary data.
-     #
-  exact_data ::= 'data' sp declen lf
-    binary_data;
-
-     # note: quoted strings are C-style quoting supporting \c for
-     # common escapes of 'c' (e..g \n, \t, \\, \") or \nnn where nnn
-     # is the signed byte value in octal.  Note that the only
-     # characters which must actually be escaped to protect the
-     # stream formatting is: \, " and LF.  Otherwise these values
-     # are UTF8.
-     #
-  commit-ish  ::= (ref_str | hexsha1 | sha1exp_str | idnum);
-  ref_str     ::= ref;
-  sha1exp_str ::= sha1exp;
-  tag_str     ::= tag;
-  path_str    ::= path    | '"' quoted(path)    '"' ;
-  mode        ::= '100644' | '644'
-                | '100755' | '755'
-                | '120000'
-                ;
-
-  declen ::= # unsigned 32 bit value, ascii base10 notation;
-  bigint ::= # unsigned integer value, ascii base10 notation;
-  binary_data ::= # file content, not interpreted;
-
-  when         ::= raw_when | rfc2822_when;
-  raw_when     ::= ts sp tz;
-  rfc2822_when ::= # Valid RFC 2822 date and time;
-
-  sp ::= # ASCII space character;
-  lf ::= # ASCII newline (LF) character;
-
-     # note: a colon (':') must precede the numerical value assigned to
-     # an idnum.  This is to distinguish it from a ref or tag name as
-     # GIT does not permit ':' in ref or tag strings.
-     #
-  idnum   ::= ':' bigint;
-  path    ::= # GIT style file path, e.g. "a/b/c";
-  ref     ::= # GIT ref name, e.g. "refs/heads/MOZ_GECKO_EXPERIMENT";
-  tag     ::= # GIT tag name, e.g. "FIREFOX_1_5";
-  sha1exp ::= # Any valid GIT SHA1 expression;
-  hexsha1 ::= # SHA1 in hexadecimal format;
-
-     # note: name and email are UTF8 strings, however name must not
-     # contain '<' or lf and email must not contain any of the
-     # following: '<', '>', lf.
-     #
-  name  ::= # valid GIT author/committer name;
-  email ::= # valid GIT author/committer email;
-  ts    ::= # time since the epoch in seconds, ascii base10 notation;
-  tz    ::= # GIT style timezone;
-
-     # note: comments, get-mark, ls-tree, and cat-blob requests may
-     # appear anywhere in the input, except within a data command. Any
-     # form of the data command always escapes the related input from
-     # comment processing.
-     #
-     # In case it is not clear, the '#' that starts the comment
-     # must be the first character on that line (an lf
-     # preceded it).
-     #
-
-  get_mark ::= 'get-mark' sp idnum lf;
-  cat_blob ::= 'cat-blob' sp (hexsha1 | idnum) lf;
-  ls_tree  ::= 'ls' sp (hexsha1 | idnum) sp path_str lf;
-
-  comment ::= '#' not_lf* lf;
-  not_lf  ::= # Any byte that is not ASCII newline (LF);
-*/
-
 #include "builtin.h"
 #include "cache.h"
 #include "repository.h"
@@ -1968,6 +1814,13 @@ static void parse_mark(void)
                next_mark = 0;
 }
 
+static void parse_original_identifier(void)
+{
+       const char *v;
+       if (skip_prefix(command_buf.buf, "original-oid ", &v))
+               read_next_command();
+}
+
 static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res)
 {
        const char *data;
@@ -2110,6 +1963,7 @@ static void parse_new_blob(void)
 {
        read_next_command();
        parse_mark();
+       parse_original_identifier();
        parse_and_store_blob(&last_blob, NULL, next_mark);
 }
 
@@ -2733,6 +2587,7 @@ static void parse_new_commit(const char *arg)
 
        read_next_command();
        parse_mark();
+       parse_original_identifier();
        if (skip_prefix(command_buf.buf, "author ", &v)) {
                author = parse_ident(v);
                read_next_command();
@@ -2865,6 +2720,9 @@ static void parse_new_tag(const char *arg)
                die("Invalid ref name or SHA1 expression: %s", from);
        read_next_command();
 
+       /* original-oid ... */
+       parse_original_identifier();
+
        /* tagger ... */
        if (skip_prefix(command_buf.buf, "tagger ", &v)) {
                tagger = parse_ident(v);
index 9691046e6445837beefde3d8ae5e842063842575..dd6700bda9240f2278e663f9147df1c0808d2efc 100644 (file)
@@ -636,23 +636,6 @@ struct loose_object_iter {
        struct ref *refs;
 };
 
-/*
- *  If the number of refs is not larger than the number of loose objects,
- *  this function stops inserting.
- */
-static int add_loose_objects_to_set(const struct object_id *oid,
-                                   const char *path,
-                                   void *data)
-{
-       struct loose_object_iter *iter = data;
-       oidset_insert(iter->loose_object_set, oid);
-       if (iter->refs == NULL)
-               return 1;
-
-       iter->refs = iter->refs->next;
-       return 0;
-}
-
 /*
  * 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
@@ -670,30 +653,14 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
        struct ref *ref;
        int old_save_commit_buffer = save_commit_buffer;
        timestamp_t cutoff = 0;
-       struct oidset loose_oid_set = OIDSET_INIT;
-       int use_oidset = 0;
-       struct loose_object_iter iter = {&loose_oid_set, *refs};
-
-       /* Enumerate all loose objects or know refs are not so many. */
-       use_oidset = !for_each_loose_object(add_loose_objects_to_set,
-                                           &iter, 0);
 
        save_commit_buffer = 0;
 
        for (ref = *refs; ref; ref = ref->next) {
                struct object *o;
-               unsigned int flags = OBJECT_INFO_QUICK;
 
-               if (use_oidset &&
-                   !oidset_contains(&loose_oid_set, &ref->old_oid)) {
-                       /*
-                        * I know this does not exist in the loose form,
-                        * so check if it exists in a non-loose form.
-                        */
-                       flags |= OBJECT_INFO_IGNORE_LOOSE;
-               }
-
-               if (!has_object_file_with_flags(&ref->old_oid, flags))
+               if (!has_object_file_with_flags(&ref->old_oid,
+                                               OBJECT_INFO_QUICK))
                        continue;
                o = parse_object(the_repository, &ref->old_oid);
                if (!o)
@@ -710,8 +677,6 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
                }
        }
 
-       oidset_clear(&loose_oid_set);
-
        if (!args->deepen) {
                for_each_ref(mark_complete_oid, NULL);
                for_each_cached_alternate(NULL, mark_alternate_complete);
index 09b0102cae8c8c0e39dc239003ca599a896730cf..29a19902aaa00b90176e253c90c2384fca65857c 100644 (file)
 #endif
 
 #if defined(__CYGWIN__)
-#include "compat/cygwin.h"
+#include "compat/win32/path-utils.h"
 #endif
 #if defined(__MINGW32__)
 /* pull in Windows compatibility stuff */
+#include "compat/win32/path-utils.h"
 #include "compat/mingw.h"
 #elif defined(_MSC_VER)
 #include "compat/msvc.h"
@@ -397,6 +398,19 @@ static inline char *git_find_last_dir_sep(const char *path)
 #define query_user_email() NULL
 #endif
 
+#ifdef __TANDEM
+#include <floss.h(floss_execl,floss_execlp,floss_execv,floss_execvp)>
+#include <floss.h(floss_getpwuid)>
+#ifndef NSIG
+/*
+ * NonStop NSE and NSX do not provide NSIG. SIGGUARDIAN(99) is the highest
+ * known, by detective work using kill -l as a list is all signals
+ * instead of signal.h where it should be.
+ */
+# define NSIG 100
+#endif
+#endif
+
 #if defined(__HP_cc) && (__HP_cc >= 61000)
 #define NORETURN __attribute__((noreturn))
 #define NORETURN_PTR
@@ -721,7 +735,7 @@ extern const char *githstrerror(int herror);
 #ifdef NO_MEMMEM
 #define memmem gitmemmem
 void *gitmemmem(const void *haystack, size_t haystacklen,
-                const void *needle, size_t needlelen);
+               const void *needle, size_t needlelen);
 #endif
 
 #ifdef OVERRIDE_STRDUP
index 1998c3e141bec5142032f08623b916d7741e64ac..3e12774f96bb185bb6860290ad187c986ec7fa76 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -332,6 +332,8 @@ def p4_check_access(min_expiration=1):
             die_bad_access("p4 error: {0}".format(data))
         else:
             die_bad_access("unknown error")
+    elif code == "info":
+        return
     else:
         die_bad_access("unknown error code {0}".format(code))
 
index 6d3a88decdeee3f85d9ee43ef8e716ccd1a6328b..e3d390974331e83261ba32e757724723b9bea724 100755 (executable)
@@ -8,6 +8,7 @@ n,dry-run     dry run
 author=       author name and email address for patches without any
 patches=      path to the quilt patches
 series=       path to the quilt series file
+keep-non-patch Pass -b to git mailinfo
 "
 SUBDIRECTORY_ON=Yes
 . git-sh-setup
@@ -32,6 +33,9 @@ do
                shift
                QUILT_SERIES="$1"
                ;;
+       --keep-non-patch)
+               MAILINFO_OPT="-b"
+               ;;
        --)
                shift
                break;;
@@ -98,7 +102,7 @@ do
                continue
        fi
        echo $patch_name
-       git mailinfo "$tmp_msg" "$tmp_patch" \
+       git mailinfo $MAILINFO_OPT "$tmp_msg" "$tmp_patch" \
                <"$QUILT_PATCHES/$patch_name" >"$tmp_info" || exit 3
        test -s "$tmp_patch" || {
                echo "Patch is empty.  Was it split wrong?"
index 94793c1a913abf569ff9101d935c355b9eb27648..789ce2f41d4a3c6e88084412bcc2b7be6ae98526 100755 (executable)
@@ -55,6 +55,20 @@ untracked_files () {
        git ls-files -o $z $excl_opt -- "$@"
 }
 
+prepare_fallback_ident () {
+       if ! git -c user.useconfigonly=yes var GIT_COMMITTER_IDENT >/dev/null 2>&1
+       then
+               GIT_AUTHOR_NAME="git stash"
+               GIT_AUTHOR_EMAIL=git@stash
+               GIT_COMMITTER_NAME="git stash"
+               GIT_COMMITTER_EMAIL=git@stash
+               export GIT_AUTHOR_NAME
+               export GIT_AUTHOR_EMAIL
+               export GIT_COMMITTER_NAME
+               export GIT_COMMITTER_EMAIL
+       fi
+}
+
 clear_stash () {
        if test $# != 0
        then
@@ -67,6 +81,9 @@ clear_stash () {
 }
 
 create_stash () {
+
+       prepare_fallback_ident
+
        stash_msg=
        untracked=
        while test $# != 0
diff --git a/git.c b/git.c
index 2f604a41eaf620f4d185c612cd7c6aee975faa67..0ce0e13f0f4879ae4608bd61d3a6a1f55ef7892e 100644 (file)
--- a/git.c
+++ b/git.c
@@ -98,7 +98,8 @@ static int list_cmds(const char *spec)
        return 0;
 }
 
-static void commit_pager_choice(void) {
+static void commit_pager_choice(void)
+{
        switch (use_pager) {
        case 0:
                setenv("GIT_PAGER", "cat", 1);
@@ -338,27 +339,27 @@ static int handle_alias(int *argcp, const char ***argv)
                        if (ret >= 0)   /* normal exit */
                                exit(ret);
 
-                       die_errno("while expanding alias '%s': '%s'",
-                           alias_command, alias_string + 1);
+                       die_errno(_("while expanding alias '%s': '%s'"),
+                                 alias_command, alias_string + 1);
                }
                count = split_cmdline(alias_string, &new_argv);
                if (count < 0)
-                       die("Bad alias.%s string: %s", alias_command,
-                           split_cmdline_strerror(count));
+                       die(_("bad alias.%s string: %s"), alias_command,
+                           _(split_cmdline_strerror(count)));
                option_count = handle_options(&new_argv, &count, &envchanged);
                if (envchanged)
-                       die("alias '%s' changes environment variables.\n"
-                                "You can use '!git' in the alias to do this",
-                                alias_command);
+                       die(_("alias '%s' changes environment variables.\n"
+                             "You can use '!git' in the alias to do this"),
+                           alias_command);
                memmove(new_argv - option_count, new_argv,
                                count * sizeof(char *));
                new_argv -= option_count;
 
                if (count < 1)
-                       die("empty alias for %s", alias_command);
+                       die(_("empty alias for %s"), alias_command);
 
                if (!strcmp(alias_command, new_argv[0]))
-                       die("recursive alias: %s", alias_command);
+                       die(_("recursive alias: %s"), alias_command);
 
                trace_argv_printf(new_argv,
                                  "trace: alias expansion: %s =>",
@@ -409,7 +410,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 
        if (!help && get_super_prefix()) {
                if (!(p->option & SUPPORT_SUPER_PREFIX))
-                       die("%s doesn't support --super-prefix", p->cmd);
+                       die(_("%s doesn't support --super-prefix"), p->cmd);
        }
 
        if (!help && p->option & NEED_WORK_TREE)
@@ -433,11 +434,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 
        /* Check for ENOSPC and EIO errors.. */
        if (fflush(stdout))
-               die_errno("write failure on standard output");
+               die_errno(_("write failure on standard output"));
        if (ferror(stdout))
-               die("unknown write failure on standard output");
+               die(_("unknown write failure on standard output"));
        if (fclose(stdout))
-               die_errno("close failed on standard output");
+               die_errno(_("close failed on standard output"));
        return 0;
 }
 
@@ -654,7 +655,7 @@ static void execv_dashed_external(const char **argv)
        int status;
 
        if (get_super_prefix())
-               die("%s doesn't support --super-prefix", argv[0]);
+               die(_("%s doesn't support --super-prefix"), argv[0]);
 
        if (use_pager == -1 && !is_builtin(argv[0]))
                use_pager = check_pager_config(argv[0]);
@@ -766,7 +767,7 @@ int cmd_main(int argc, const char **argv)
        if (skip_prefix(cmd, "git-", &cmd)) {
                argv[0] = cmd;
                handle_builtin(argc, argv);
-               die("cannot handle %s as a builtin", cmd);
+               die(_("cannot handle %s as a builtin"), cmd);
        }
 
        /* Look for flags.. */
@@ -779,7 +780,7 @@ int cmd_main(int argc, const char **argv)
        } else {
                /* The user didn't specify a command; give them help */
                commit_pager_choice();
-               printf("usage: %s\n\n", git_usage_string);
+               printf(_("usage: %s\n\n"), git_usage_string);
                list_common_cmds_help();
                printf("\n%s\n", _(git_more_info_string));
                exit(1);
diff --git a/grep.c b/grep.c
index 4db1510d167c9fc3cc7b129c90aa874a4c7c2b0f..0d50598acda6f1c41951d1d656ea701114473239 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -1805,7 +1805,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
                 * is not thread-safe.
                 */
                grep_attr_lock();
-               textconv = userdiff_get_textconv(gs->driver);
+               textconv = userdiff_get_textconv(opt->repo, gs->driver);
                grep_attr_unlock();
        }
 
diff --git a/help.c b/help.c
index 4745b322993e6a3c32fa4e2ab8adad9f159193c1..ff05fd22dff064f0f872434d20d4ea1eacded07d 100644 (file)
--- a/help.c
+++ b/help.c
@@ -83,8 +83,9 @@ static void print_command_list(const struct cmdname_help *cmds,
 
        for (i = 0; cmds[i].name; i++) {
                if (cmds[i].category & mask) {
+                       size_t len = strlen(cmds[i].name);
                        printf("   %s   ", cmds[i].name);
-                       mput_char(' ', longest - strlen(cmds[i].name));
+                       mput_char(' ', longest > len ? longest - len : 1);
                        puts(_(cmds[i].help));
                }
        }
@@ -526,6 +527,13 @@ void list_all_cmds_help(void)
 
        git_config(get_alias, &alias_list);
        string_list_sort(&alias_list);
+
+       for (i = 0; i < alias_list.nr; i++) {
+               size_t len = strlen(alias_list.items[i].string);
+               if (longest < len)
+                       longest = len;
+       }
+
        if (alias_list.nr) {
                printf("\n%s\n", _("Command aliases"));
                ALLOC_ARRAY(aliases, alias_list.nr + 1);
diff --git a/help.h b/help.h
index 9eab6a3f898f22630e628b0aed209fc79a273434..a141e209aea22b19f12c5e27435c5ed773488177 100644 (file)
--- a/help.h
+++ b/help.h
@@ -15,7 +15,7 @@ struct cmdnames {
 
 static inline void mput_char(char c, unsigned int num)
 {
-       while(num--)
+       while (num--)
                putchar(c);
 }
 
index 9e894f197f91ee3565b0f3c618fdb4042e2f229f..29e68e38b5d5466126608642a96b9640aca44272 100644 (file)
@@ -486,6 +486,8 @@ static void run_service(const char **argv, int buffer_input)
        if (buffer_input || gzipped_request || req_len >= 0)
                cld.in = -1;
        cld.git_cmd = 1;
+       cld.clean_on_exit = 1;
+       cld.wait_after_clean = 1;
        if (start_command(&cld))
                exit(1);
 
index b3334bf657b5ea64e779eb470525eb0b7337baa9..0a392c85b67af254ddeca382faa79458c4ec3ca8 100644 (file)
@@ -547,7 +547,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
                ret = error("File %s has bad hash", hex);
        } else if (req->rename < 0) {
                struct strbuf buf = STRBUF_INIT;
-               sha1_file_name(the_repository, &buf, req->sha1);
+               loose_object_path(the_repository, &buf, req->sha1);
                ret = error("unable to write sha1 filename %s", buf.buf);
                strbuf_release(&buf);
        }
diff --git a/http.c b/http.c
index eacc2a75ef2e41da9d5f5741defcf1952e6c01a3..0b6807cef9aa0994be486581ecf18f7829ee4e19 100644 (file)
--- a/http.c
+++ b/http.c
@@ -48,6 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
 
 static int curl_ssl_verify = -1;
 static int curl_ssl_try;
+static const char *curl_http_version = NULL;
 static const char *ssl_cert;
 static const char *ssl_cipherlist;
 static const char *ssl_version;
@@ -284,6 +285,9 @@ static void process_curl_messages(void)
 
 static int http_options(const char *var, const char *value, void *cb)
 {
+       if (!strcmp("http.version", var)) {
+               return git_config_string(&curl_http_version, var, value);
+       }
        if (!strcmp("http.sslverify", var)) {
                curl_ssl_verify = git_config_bool(var, value);
                return 0;
@@ -789,6 +793,31 @@ static long get_curl_allowed_protocols(int from_user)
 }
 #endif
 
+#if LIBCURL_VERSION_NUM >=0x072f00
+static int get_curl_http_version_opt(const char *version_string, long *opt)
+{
+       int i;
+       static struct {
+               const char *name;
+               long opt_token;
+       } choice[] = {
+               { "HTTP/1.1", CURL_HTTP_VERSION_1_1 },
+               { "HTTP/2", CURL_HTTP_VERSION_2 }
+       };
+
+       for (i = 0; i < ARRAY_SIZE(choice); i++) {
+               if (!strcmp(version_string, choice[i].name)) {
+                       *opt = choice[i].opt_token;
+                       return 0;
+               }
+       }
+
+       warning("unknown value given to http.version: '%s'", version_string);
+       return -1; /* not found */
+}
+
+#endif
+
 static CURL *get_curl_handle(void)
 {
        CURL *result = curl_easy_init();
@@ -806,6 +835,16 @@ static CURL *get_curl_handle(void)
                curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
        }
 
+#if LIBCURL_VERSION_NUM >= 0x072f00 // 7.47.0
+    if (curl_http_version) {
+               long opt;
+               if (!get_curl_http_version_opt(curl_http_version, &opt)) {
+                       /* Set request use http version */
+                       curl_easy_setopt(result, CURLOPT_HTTP_VERSION, opt);
+               }
+    }
+#endif
+
 #if LIBCURL_VERSION_NUM >= 0x070907
        curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
 #endif
@@ -2314,7 +2353,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
        hashcpy(freq->sha1, sha1);
        freq->localfile = -1;
 
-       sha1_file_name(the_repository, &filename, sha1);
+       loose_object_path(the_repository, &filename, sha1);
        strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
 
        strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2465,7 +2504,7 @@ int finish_http_object_request(struct http_object_request *freq)
                unlink_or_warn(freq->tmpfile.buf);
                return -1;
        }
-       sha1_file_name(the_repository, &filename, freq->sha1);
+       loose_object_path(the_repository, &filename, freq->sha1);
        freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
        strbuf_release(&filename);
 
index b4eb886e2a6a40bce1e478d8d24f43f64ed2e3aa..18ca6ba10a81931e6b789fa2d25d6dc2e1767eec 100644 (file)
@@ -1471,7 +1471,8 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
 }
 
 static int curl_append_msgs_to_imap(struct imap_server_conf *server,
-                                   struct strbuf* all_msgs, int total) {
+                                   struct strbuf* all_msgs, int total)
+{
        int ofs = 0;
        int n = 0;
        struct buffer msgbuf = { STRBUF_INIT, 0 };
index d1d429d73818cf4ef47b3e9e64c1e39489200be5..24e21731c4315f414578b33178a7b784176bb24d 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(the_repository, obj, NULL, 0);
+               obj = deref_tag(revs->repo, obj, NULL, 0);
                if (obj->type != OBJ_COMMIT)
                        die("Non commit %s?", revs->pending.objects[i].name);
                if (commit)
index 765f3df3b067c5df7b98402ef4fc953edcd9179b..a62624a1ced704156395b3e30312f264aa46b862 100644 (file)
@@ -34,6 +34,7 @@ struct filter_blobs_none_data {
 };
 
 static enum list_objects_filter_result filter_blobs_none(
+       struct repository *r,
        enum list_objects_filter_situation filter_situation,
        struct object *obj,
        const char *pathname,
@@ -88,6 +89,7 @@ struct filter_trees_none_data {
 };
 
 static enum list_objects_filter_result filter_trees_none(
+       struct repository *r,
        enum list_objects_filter_situation filter_situation,
        struct object *obj,
        const char *pathname,
@@ -144,6 +146,7 @@ struct filter_blobs_limit_data {
 };
 
 static enum list_objects_filter_result filter_blobs_limit(
+       struct repository *r,
        enum list_objects_filter_situation filter_situation,
        struct object *obj,
        const char *pathname,
@@ -171,7 +174,7 @@ static enum list_objects_filter_result filter_blobs_limit(
                assert(obj->type == OBJ_BLOB);
                assert((obj->flags & SEEN) == 0);
 
-               t = oid_object_info(the_repository, &obj->oid, &object_length);
+               t = oid_object_info(r, &obj->oid, &object_length);
                if (t != OBJ_BLOB) { /* probably OBJ_NONE */
                        /*
                         * We DO NOT have the blob locally, so we cannot
@@ -249,6 +252,7 @@ struct filter_sparse_data {
 };
 
 static enum list_objects_filter_result filter_sparse(
+       struct repository *r,
        enum list_objects_filter_situation filter_situation,
        struct object *obj,
        const char *pathname,
@@ -268,7 +272,7 @@ static enum list_objects_filter_result filter_sparse(
                dtype = DT_DIR;
                val = is_excluded_from_list(pathname, strlen(pathname),
                                            filename, &dtype, &filter_data->el,
-                                           &the_index);
+                                           r->index);
                if (val < 0)
                        val = filter_data->array_frame[filter_data->nr].defval;
 
@@ -331,7 +335,7 @@ static enum list_objects_filter_result filter_sparse(
                dtype = DT_REG;
                val = is_excluded_from_list(pathname, strlen(pathname),
                                            filename, &dtype, &filter_data->el,
-                                           &the_index);
+                                           r->index);
                if (val < 0)
                        val = frame->defval;
                if (val > 0) {
index 52b4a84da9418497a4fc37e50cb8e0dcbc5b70bd..1d45a4ad5786c915f1fd597ce782cd96b7301532 100644 (file)
@@ -4,6 +4,7 @@
 struct list_objects_filter_options;
 struct object;
 struct oidset;
+struct repository;
 
 /*
  * During list-object traversal we allow certain objects to be
@@ -60,6 +61,7 @@ enum list_objects_filter_situation {
 };
 
 typedef enum list_objects_filter_result (*filter_object_fn)(
+       struct repository *r,
        enum list_objects_filter_situation filter_situation,
        struct object *obj,
        const char *pathname,
index c41cc80db5bc86279bcf560109f599a9783b2755..4e2789768d21ccb47a8fe2d5de62b6be58ea9bb7 100644 (file)
@@ -55,7 +55,8 @@ static void process_blob(struct traversal_context *ctx,
        pathlen = path->len;
        strbuf_addstr(path, name);
        if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn)
-               r = ctx->filter_fn(LOFS_BLOB, obj,
+               r = ctx->filter_fn(ctx->revs->repo,
+                                  LOFS_BLOB, obj,
                                   path->buf, &path->buf[pathlen],
                                   ctx->filter_data);
        if (r & LOFR_MARK_SEEN)
@@ -113,7 +114,8 @@ static void process_tree_contents(struct traversal_context *ctx,
 
        while (tree_entry(&desc, &entry)) {
                if (match != all_entries_interesting) {
-                       match = tree_entry_interesting(&entry, base, 0,
+                       match = tree_entry_interesting(ctx->revs->repo->index,
+                                                      &entry, base, 0,
                                                       &ctx->revs->diffopt.pathspec);
                        if (match == all_entries_not_interesting)
                                break;
@@ -122,7 +124,7 @@ static void process_tree_contents(struct traversal_context *ctx,
                }
 
                if (S_ISDIR(entry.mode)) {
-                       struct tree *t = lookup_tree(the_repository, entry.oid);
+                       struct tree *t = lookup_tree(ctx->revs->repo, entry.oid);
                        t->object.flags |= NOT_USER_GIVEN;
                        process_tree(ctx, t, base, entry.path);
                }
@@ -130,7 +132,7 @@ static void process_tree_contents(struct traversal_context *ctx,
                        process_gitlink(ctx, entry.oid->hash,
                                        base, entry.path);
                else {
-                       struct blob *b = lookup_blob(the_repository, entry.oid);
+                       struct blob *b = lookup_blob(ctx->revs->repo, entry.oid);
                        b->object.flags |= NOT_USER_GIVEN;
                        process_blob(ctx, b, base, entry.path);
                }
@@ -175,7 +177,8 @@ static void process_tree(struct traversal_context *ctx,
 
        strbuf_addstr(base, name);
        if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn)
-               r = ctx->filter_fn(LOFS_BEGIN_TREE, obj,
+               r = ctx->filter_fn(ctx->revs->repo,
+                                  LOFS_BEGIN_TREE, obj,
                                   base->buf, &base->buf[baselen],
                                   ctx->filter_data);
        if (r & LOFR_MARK_SEEN)
@@ -191,7 +194,8 @@ static void process_tree(struct traversal_context *ctx,
                process_tree_contents(ctx, tree, base);
 
        if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn) {
-               r = ctx->filter_fn(LOFS_END_TREE, obj,
+               r = ctx->filter_fn(ctx->revs->repo,
+                                  LOFS_END_TREE, obj,
                                   base->buf, &base->buf[baselen],
                                   ctx->filter_data);
                if (r & LOFR_MARK_SEEN)
index 3c8fb917e9748b1950d5df8c85aa310149f1f8df..5b8d46aedee72aab8b027cf4310b4234268965b6 100644 (file)
@@ -384,7 +384,9 @@ int ll_merge(mmbuffer_t *result_buf,
        if (opts->virtual_ancestor) {
                if (driver->recursive)
                        driver = find_ll_merge_driver(driver->recursive);
-               marker_size += 2;
+       }
+       if (opts->extra_marker_size) {
+               marker_size += opts->extra_marker_size;
        }
        return driver->fn(driver, result_buf, path, ancestor, ancestor_label,
                          ours, our_label, theirs, their_label,
index 6c6e22e40d9bab4b5071319acd5356993e7888b4..b9e2af1c884042adda8127a07ce8565b64303047 100644 (file)
@@ -13,6 +13,7 @@ struct ll_merge_options {
        unsigned virtual_ancestor : 1;
        unsigned variant : 2;   /* favor ours, favor theirs, or union merge */
        unsigned renormalize : 1;
+       unsigned extra_marker_size;
        long xdl_opts;
 };
 
index acc2f64a4e9d03f49165e3c46396ce00a09dc6bd..59ba4b4a1a083b07050c5e6eba8306cb63736a3e 100644 (file)
@@ -186,6 +186,7 @@ static int oid_eq(const struct object_id *a, const struct object_id *b)
 enum rename_type {
        RENAME_NORMAL = 0,
        RENAME_VIA_DIR,
+       RENAME_ADD,
        RENAME_DELETE,
        RENAME_ONE_FILE_TO_ONE,
        RENAME_ONE_FILE_TO_TWO,
@@ -228,6 +229,7 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
                                              struct stage_data *src_entry1,
                                              struct stage_data *src_entry2)
 {
+       int ostage1 = 0, ostage2;
        struct rename_conflict_info *ci;
 
        /*
@@ -264,18 +266,22 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
                dst_entry2->rename_conflict_info = ci;
        }
 
-       if (rename_type == RENAME_TWO_FILES_TO_ONE) {
-               /*
-                * For each rename, there could have been
-                * modifications on the side of history where that
-                * file was not renamed.
-                */
-               int ostage1 = o->branch1 == branch1 ? 3 : 2;
-               int ostage2 = ostage1 ^ 1;
+       /*
+        * For each rename, there could have been
+        * modifications on the side of history where that
+        * file was not renamed.
+        */
+       if (rename_type == RENAME_ADD ||
+           rename_type == RENAME_TWO_FILES_TO_ONE) {
+               ostage1 = o->branch1 == branch1 ? 3 : 2;
 
                ci->ren1_other.path = pair1->one->path;
                oidcpy(&ci->ren1_other.oid, &src_entry1->stages[ostage1].oid);
                ci->ren1_other.mode = src_entry1->stages[ostage1].mode;
+       }
+
+       if (rename_type == RENAME_TWO_FILES_TO_ONE) {
+               ostage2 = ostage1 ^ 1;
 
                ci->ren2_other.path = pair2->one->path;
                oidcpy(&ci->ren2_other.oid, &src_entry2->stages[ostage2].oid);
@@ -463,7 +469,8 @@ static void get_files_dirs(struct merge_options *o, struct tree *tree)
 {
        struct pathspec match_all;
        memset(&match_all, 0, sizeof(match_all));
-       read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o);
+       read_tree_recursive(the_repository, tree, "", 0, 0,
+                           &match_all, save_files_dirs, o);
 }
 
 static int get_tree_entry_if_blob(const struct object_id *tree,
@@ -690,27 +697,6 @@ static int update_stages(struct merge_options *opt, const char *path,
        return 0;
 }
 
-static int update_stages_for_stage_data(struct merge_options *opt,
-                                       const char *path,
-                                       const struct stage_data *stage_data)
-{
-       struct diff_filespec o, a, b;
-
-       o.mode = stage_data->stages[1].mode;
-       oidcpy(&o.oid, &stage_data->stages[1].oid);
-
-       a.mode = stage_data->stages[2].mode;
-       oidcpy(&a.oid, &stage_data->stages[2].oid);
-
-       b.mode = stage_data->stages[3].mode;
-       oidcpy(&b.oid, &stage_data->stages[3].oid);
-
-       return update_stages(opt, path,
-                            is_null_oid(&o.oid) ? NULL : &o,
-                            is_null_oid(&a.oid) ? NULL : &a,
-                            is_null_oid(&b.oid) ? NULL : &b);
-}
-
 static void update_entry(struct stage_data *entry,
                         struct diff_filespec *o,
                         struct diff_filespec *a,
@@ -1058,7 +1044,8 @@ static int merge_3way(struct merge_options *o,
                      const struct diff_filespec *a,
                      const struct diff_filespec *b,
                      const char *branch1,
-                     const char *branch2)
+                     const char *branch2,
+                     const int extra_marker_size)
 {
        mmfile_t orig, src1, src2;
        struct ll_merge_options ll_opts = {0};
@@ -1066,6 +1053,7 @@ static int merge_3way(struct merge_options *o,
        int merge_status;
 
        ll_opts.renormalize = o->renormalize;
+       ll_opts.extra_marker_size = extra_marker_size;
        ll_opts.xdl_opts = o->xdl_opts;
 
        if (o->call_depth) {
@@ -1301,6 +1289,7 @@ static int merge_mode_and_contents(struct merge_options *o,
                                   const char *filename,
                                   const char *branch1,
                                   const char *branch2,
+                                  const int extra_marker_size,
                                   struct merge_file_info *result)
 {
        if (o->branch1 != branch1) {
@@ -1311,7 +1300,8 @@ static int merge_mode_and_contents(struct merge_options *o,
                 */
                return merge_mode_and_contents(o, one, b, a,
                                               filename,
-                                              branch2, branch1, result);
+                                              branch2, branch1,
+                                              extra_marker_size, result);
        }
 
        result->merge = 0;
@@ -1352,7 +1342,8 @@ static int merge_mode_and_contents(struct merge_options *o,
                        int ret = 0, merge_status;
 
                        merge_status = merge_3way(o, &result_buf, one, a, b,
-                                                 branch1, branch2);
+                                                 branch1, branch2,
+                                                 extra_marker_size);
 
                        if ((merge_status < 0) || !result_buf.ptr)
                                ret = err(o, _("Failed to execute internal merge"));
@@ -1555,80 +1546,203 @@ static struct diff_filespec *filespec_from_entry(struct diff_filespec *target,
        return target;
 }
 
-static int handle_file(struct merge_options *o,
-                       struct diff_filespec *rename,
-                       int stage,
-                       struct rename_conflict_info *ci)
+static int handle_file_collision(struct merge_options *o,
+                                const char *collide_path,
+                                const char *prev_path1,
+                                const char *prev_path2,
+                                const char *branch1, const char *branch2,
+                                const struct object_id *a_oid,
+                                unsigned int a_mode,
+                                const struct object_id *b_oid,
+                                unsigned int b_mode)
 {
-       char *dst_name = rename->path;
-       struct stage_data *dst_entry;
-       const char *cur_branch, *other_branch;
-       struct diff_filespec other;
-       struct diff_filespec *add;
-       int ret;
+       struct merge_file_info mfi;
+       struct diff_filespec null, a, b;
+       char *alt_path = NULL;
+       const char *update_path = collide_path;
 
-       if (stage == 2) {
-               dst_entry = ci->dst_entry1;
-               cur_branch = ci->branch1;
-               other_branch = ci->branch2;
-       } else {
-               dst_entry = ci->dst_entry2;
-               cur_branch = ci->branch2;
-               other_branch = ci->branch1;
+       /*
+        * It's easiest to get the correct things into stage 2 and 3, and
+        * to make sure that the content merge puts HEAD before the other
+        * branch if we just ensure that branch1 == o->branch1.  So, simply
+        * flip arguments around if we don't have that.
+        */
+       if (branch1 != o->branch1) {
+               return handle_file_collision(o, collide_path,
+                                            prev_path2, prev_path1,
+                                            branch2, branch1,
+                                            b_oid, b_mode,
+                                            a_oid, a_mode);
        }
 
-       add = filespec_from_entry(&other, dst_entry, stage ^ 1);
-       if (add) {
-               int ren_src_was_dirty = was_dirty(o, rename->path);
-               char *add_name = unique_path(o, rename->path, other_branch);
-               if (update_file(o, 0, &add->oid, add->mode, add_name))
-                       return -1;
+       /*
+        * In the recursive case, we just opt to undo renames
+        */
+       if (o->call_depth && (prev_path1 || prev_path2)) {
+               /* Put first file (a_oid, a_mode) in its original spot */
+               if (prev_path1) {
+                       if (update_file(o, 1, a_oid, a_mode, prev_path1))
+                               return -1;
+               } else {
+                       if (update_file(o, 1, a_oid, a_mode, collide_path))
+                               return -1;
+               }
 
-               if (ren_src_was_dirty) {
-                       output(o, 1, _("Refusing to lose dirty file at %s"),
-                              rename->path);
+               /* Put second file (b_oid, b_mode) in its original spot */
+               if (prev_path2) {
+                       if (update_file(o, 1, b_oid, b_mode, prev_path2))
+                               return -1;
+               } else {
+                       if (update_file(o, 1, b_oid, b_mode, collide_path))
+                               return -1;
                }
+
+               /* Don't leave something at collision path if unrenaming both */
+               if (prev_path1 && prev_path2)
+                       remove_file(o, 1, collide_path, 0);
+
+               return 0;
+       }
+
+       /* Remove rename sources if rename/add or rename/rename(2to1) */
+       if (prev_path1)
+               remove_file(o, 1, prev_path1,
+                           o->call_depth || would_lose_untracked(prev_path1));
+       if (prev_path2)
+               remove_file(o, 1, prev_path2,
+                           o->call_depth || would_lose_untracked(prev_path2));
+
+       /*
+        * Remove the collision path, if it wouldn't cause dirty contents
+        * or an untracked file to get lost.  We'll either overwrite with
+        * merged contents, or just write out to differently named files.
+        */
+       if (was_dirty(o, collide_path)) {
+               output(o, 1, _("Refusing to lose dirty file at %s"),
+                      collide_path);
+               update_path = alt_path = unique_path(o, collide_path, "merged");
+       } else if (would_lose_untracked(collide_path)) {
                /*
-                * Because the double negatives somehow keep confusing me...
-                *    1) update_wd iff !ren_src_was_dirty.
-                *    2) no_wd iff !update_wd
-                *    3) so, no_wd == !!ren_src_was_dirty == ren_src_was_dirty
+                * Only way we get here is if both renames were from
+                * a directory rename AND user had an untracked file
+                * at the location where both files end up after the
+                * two directory renames.  See testcase 10d of t6043.
                 */
-               remove_file(o, 0, rename->path, ren_src_was_dirty);
-               dst_name = unique_path(o, rename->path, cur_branch);
+               output(o, 1, _("Refusing to lose untracked file at "
+                              "%s, even though it's in the way."),
+                      collide_path);
+               update_path = alt_path = unique_path(o, collide_path, "merged");
        } else {
-               if (dir_in_way(rename->path, !o->call_depth, 0)) {
-                       dst_name = unique_path(o, rename->path, cur_branch);
-                       output(o, 1, _("%s is a directory in %s adding as %s instead"),
-                              rename->path, other_branch, dst_name);
-               } else if (!o->call_depth &&
-                          would_lose_untracked(rename->path)) {
-                       dst_name = unique_path(o, rename->path, cur_branch);
-                       output(o, 1, _("Refusing to lose untracked file at %s; "
-                                      "adding as %s instead"),
-                              rename->path, dst_name);
-               }
+               /*
+                * FIXME: It's possible that the two files are identical
+                * and that the current working copy happens to match, in
+                * which case we are unnecessarily touching the working
+                * tree file.  It's not a likely enough scenario that I
+                * want to code up the checks for it and a better fix is
+                * available if we restructure how unpack_trees() and
+                * merge-recursive interoperate anyway, so punting for
+                * now...
+                */
+               remove_file(o, 0, collide_path, 0);
        }
-       if ((ret = update_file(o, 0, &rename->oid, rename->mode, dst_name)))
-               ; /* fall through, do allow dst_name to be released */
-       else if (stage == 2)
-               ret = update_stages(o, rename->path, NULL, rename, add);
-       else
-               ret = update_stages(o, rename->path, NULL, add, rename);
 
-       if (dst_name != rename->path)
-               free(dst_name);
+       /* Store things in diff_filespecs for functions that need it */
+       memset(&a, 0, sizeof(struct diff_filespec));
+       memset(&b, 0, sizeof(struct diff_filespec));
+       null.path = a.path = b.path = (char *)collide_path;
+       oidcpy(&null.oid, &null_oid);
+       null.mode = 0;
+       oidcpy(&a.oid, a_oid);
+       a.mode = a_mode;
+       a.oid_valid = 1;
+       oidcpy(&b.oid, b_oid);
+       b.mode = b_mode;
+       b.oid_valid = 1;
 
-       return ret;
+       if (merge_mode_and_contents(o, &null, &a, &b, collide_path,
+                                   branch1, branch2, o->call_depth * 2, &mfi))
+               return -1;
+       mfi.clean &= !alt_path;
+       if (update_file(o, mfi.clean, &mfi.oid, mfi.mode, update_path))
+               return -1;
+       if (!mfi.clean && !o->call_depth &&
+           update_stages(o, collide_path, NULL, &a, &b))
+               return -1;
+       free(alt_path);
+       /*
+        * FIXME: If both a & b both started with conflicts (only possible
+        * if they came from a rename/rename(2to1)), but had IDENTICAL
+        * contents including those conflicts, then in the next line we claim
+        * it was clean.  If someone cares about this case, we should have the
+        * caller notify us if we started with conflicts.
+        */
+       return mfi.clean;
+}
+
+static int handle_rename_add(struct merge_options *o,
+                            struct rename_conflict_info *ci)
+{
+       /* a was renamed to c, and a separate c was added. */
+       struct diff_filespec *a = ci->pair1->one;
+       struct diff_filespec *c = ci->pair1->two;
+       char *path = c->path;
+       char *prev_path_desc;
+       struct merge_file_info mfi;
+
+       int other_stage = (ci->branch1 == o->branch1 ? 3 : 2);
+
+       output(o, 1, _("CONFLICT (rename/add): "
+              "Rename %s->%s in %s.  Added %s in %s"),
+              a->path, c->path, ci->branch1,
+              c->path, ci->branch2);
+
+       prev_path_desc = xstrfmt("version of %s from %s", path, a->path);
+       if (merge_mode_and_contents(o, a, c, &ci->ren1_other, prev_path_desc,
+                                   o->branch1, o->branch2,
+                                   1 + o->call_depth * 2, &mfi))
+               return -1;
+       free(prev_path_desc);
+
+       return handle_file_collision(o,
+                                    c->path, a->path, NULL,
+                                    ci->branch1, ci->branch2,
+                                    &mfi.oid, mfi.mode,
+                                    &ci->dst_entry1->stages[other_stage].oid,
+                                    ci->dst_entry1->stages[other_stage].mode);
+}
+
+static char *find_path_for_conflict(struct merge_options *o,
+                                   const char *path,
+                                   const char *branch1,
+                                   const char *branch2)
+{
+       char *new_path = NULL;
+       if (dir_in_way(path, !o->call_depth, 0)) {
+               new_path = unique_path(o, path, branch1);
+               output(o, 1, _("%s is a directory in %s adding "
+                              "as %s instead"),
+                      path, branch2, new_path);
+       } else if (would_lose_untracked(path)) {
+               new_path = unique_path(o, path, branch1);
+               output(o, 1, _("Refusing to lose untracked file"
+                              " at %s; adding as %s instead"),
+                      path, new_path);
+       }
+
+       return new_path;
 }
 
 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 merge_file_info mfi;
+       struct diff_filespec other;
+       struct diff_filespec *add;
        struct diff_filespec *one = ci->pair1->one;
        struct diff_filespec *a = ci->pair1->two;
        struct diff_filespec *b = ci->pair2->two;
+       char *path_desc;
 
        output(o, 1, _("CONFLICT (rename/rename): "
               "Rename \"%s\"->\"%s\" in branch \"%s\" "
@@ -1636,14 +1750,16 @@ static int handle_rename_rename_1to2(struct merge_options *o,
               one->path, a->path, ci->branch1,
               one->path, b->path, ci->branch2,
               o->call_depth ? _(" (left unresolved)") : "");
-       if (o->call_depth) {
-               struct merge_file_info mfi;
-               struct diff_filespec other;
-               struct diff_filespec *add;
-               if (merge_mode_and_contents(o, one, a, b, one->path,
-                                           ci->branch1, ci->branch2, &mfi))
-                       return -1;
 
+       path_desc = xstrfmt("%s and %s, both renamed from %s",
+                           a->path, b->path, one->path);
+       if (merge_mode_and_contents(o, one, a, b, path_desc,
+                                   ci->branch1, ci->branch2,
+                                   o->call_depth * 2, &mfi))
+               return -1;
+       free(path_desc);
+
+       if (o->call_depth) {
                /*
                 * FIXME: For rename/add-source conflicts (if we could detect
                 * such), this is wrong.  We should instead find a unique
@@ -1675,8 +1791,50 @@ static int handle_rename_rename_1to2(struct merge_options *o,
                }
                else
                        remove_file_from_cache(b->path);
-       } else if (handle_file(o, a, 2, ci) || handle_file(o, b, 3, ci))
-               return -1;
+       } else {
+               /*
+                * For each destination path, we need to see if there is a
+                * rename/add collision.  If not, we can write the file out
+                * to the specified location.
+                */
+               add = filespec_from_entry(&other, ci->dst_entry1, 2 ^ 1);
+               if (add) {
+                       if (handle_file_collision(o, a->path,
+                                                 NULL, NULL,
+                                                 ci->branch1, ci->branch2,
+                                                 &mfi.oid, mfi.mode,
+                                                 &add->oid, add->mode) < 0)
+                               return -1;
+               } else {
+                       char *new_path = find_path_for_conflict(o, a->path,
+                                                               ci->branch1,
+                                                               ci->branch2);
+                       if (update_file(o, 0, &mfi.oid, mfi.mode, new_path ? new_path : a->path))
+                               return -1;
+                       free(new_path);
+                       if (update_stages(o, a->path, NULL, a, NULL))
+                               return -1;
+               }
+
+               add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);
+               if (add) {
+                       if (handle_file_collision(o, b->path,
+                                                 NULL, NULL,
+                                                 ci->branch1, ci->branch2,
+                                                 &add->oid, add->mode,
+                                                 &mfi.oid, mfi.mode) < 0)
+                               return -1;
+               } else {
+                       char *new_path = find_path_for_conflict(o, b->path,
+                                                               ci->branch2,
+                                                               ci->branch1);
+                       if (update_file(o, 0, &mfi.oid, mfi.mode, new_path ? new_path : b->path))
+                               return -1;
+                       free(new_path);
+                       if (update_stages(o, b->path, NULL, NULL, b))
+                               return -1;
+               }
+       }
 
        return 0;
 }
@@ -1694,7 +1852,6 @@ static int handle_rename_rename_2to1(struct merge_options *o,
        char *path_side_2_desc;
        struct merge_file_info mfi_c1;
        struct merge_file_info mfi_c2;
-       int ret;
 
        output(o, 1, _("CONFLICT (rename/rename): "
               "Rename %s->%s in %s. "
@@ -1702,79 +1859,22 @@ static int handle_rename_rename_2to1(struct merge_options *o,
               a->path, c1->path, ci->branch1,
               b->path, c2->path, ci->branch2);
 
-       remove_file(o, 1, a->path, o->call_depth || would_lose_untracked(a->path));
-       remove_file(o, 1, b->path, o->call_depth || would_lose_untracked(b->path));
-
        path_side_1_desc = xstrfmt("version of %s from %s", path, a->path);
        path_side_2_desc = xstrfmt("version of %s from %s", path, b->path);
        if (merge_mode_and_contents(o, a, c1, &ci->ren1_other, path_side_1_desc,
-                                   o->branch1, o->branch2, &mfi_c1) ||
+                                   o->branch1, o->branch2,
+                                   1 + o->call_depth * 2, &mfi_c1) ||
            merge_mode_and_contents(o, b, &ci->ren2_other, c2, path_side_2_desc,
-                                   o->branch1, o->branch2, &mfi_c2))
+                                   o->branch1, o->branch2,
+                                   1 + o->call_depth * 2, &mfi_c2))
                return -1;
        free(path_side_1_desc);
        free(path_side_2_desc);
 
-       if (o->call_depth) {
-               /*
-                * If mfi_c1.clean && mfi_c2.clean, then it might make
-                * sense to do a two-way merge of those results.  But, I
-                * think in all cases, it makes sense to have the virtual
-                * merge base just undo the renames; they can be detected
-                * again later for the non-recursive merge.
-                */
-               remove_file(o, 0, path, 0);
-               ret = update_file(o, 0, &mfi_c1.oid, mfi_c1.mode, a->path);
-               if (!ret)
-                       ret = update_file(o, 0, &mfi_c2.oid, mfi_c2.mode,
-                                         b->path);
-       } else {
-               char *new_path1 = unique_path(o, path, ci->branch1);
-               char *new_path2 = unique_path(o, path, ci->branch2);
-               output(o, 1, _("Renaming %s to %s and %s to %s instead"),
-                      a->path, new_path1, b->path, new_path2);
-               if (was_dirty(o, path))
-                       output(o, 1, _("Refusing to lose dirty file at %s"),
-                              path);
-               else if (would_lose_untracked(path))
-                       /*
-                        * Only way we get here is if both renames were from
-                        * a directory rename AND user had an untracked file
-                        * at the location where both files end up after the
-                        * two directory renames.  See testcase 10d of t6043.
-                        */
-                       output(o, 1, _("Refusing to lose untracked file at "
-                                      "%s, even though it's in the way."),
-                              path);
-               else
-                       remove_file(o, 0, path, 0);
-               ret = update_file(o, 0, &mfi_c1.oid, mfi_c1.mode, new_path1);
-               if (!ret)
-                       ret = update_file(o, 0, &mfi_c2.oid, mfi_c2.mode,
-                                         new_path2);
-               /*
-                * unpack_trees() actually populates the index for us for
-                * "normal" rename/rename(2to1) situtations so that the
-                * correct entries are at the higher stages, which would
-                * make the call below to update_stages_for_stage_data
-                * unnecessary.  However, if either of the renames came
-                * from a directory rename, then unpack_trees() will not
-                * have gotten the right data loaded into the index, so we
-                * need to do so now.  (While it'd be tempting to move this
-                * call to update_stages_for_stage_data() to
-                * apply_directory_rename_modifications(), that would break
-                * our intermediate calls to would_lose_untracked() since
-                * those rely on the current in-memory index.  See also the
-                * big "NOTE" in update_stages()).
-                */
-               if (update_stages_for_stage_data(o, path, ci->dst_entry1))
-                       ret = -1;
-
-               free(new_path2);
-               free(new_path1);
-       }
-
-       return ret;
+       return handle_file_collision(o, path, a->path, b->path,
+                                    ci->branch1, ci->branch2,
+                                    &mfi_c1.oid, mfi_c1.mode,
+                                    &mfi_c2.oid, mfi_c2.mode);
 }
 
 /*
@@ -2732,47 +2832,23 @@ static int process_renames(struct merge_options *o,
                                                      0  /* update_wd    */))
                                        clean_merge = -1;
                        } else if (!oid_eq(&dst_other.oid, &null_oid)) {
-                               clean_merge = 0;
-                               try_merge = 1;
-                               output(o, 1, _("CONFLICT (rename/add): Rename %s->%s in %s. "
-                                      "%s added in %s"),
-                                      ren1_src, ren1_dst, branch1,
-                                      ren1_dst, branch2);
-                               if (o->call_depth) {
-                                       struct merge_file_info mfi;
-                                       struct diff_filespec one, a, b;
-
-                                       oidcpy(&one.oid, &null_oid);
-                                       one.mode = 0;
-                                       one.path = ren1->pair->two->path;
-
-                                       oidcpy(&a.oid, &ren1->pair->two->oid);
-                                       a.mode = ren1->pair->two->mode;
-                                       a.path = one.path;
-
-                                       oidcpy(&b.oid, &dst_other.oid);
-                                       b.mode = dst_other.mode;
-                                       b.path = one.path;
-
-                                       if (merge_mode_and_contents(o, &one, &a, &b, ren1_dst,
-                                                                   branch1, branch2,
-                                                                   &mfi)) {
-                                               clean_merge = -1;
-                                               goto cleanup_and_return;
-                                       }
-                                       output(o, 1, _("Adding merged %s"), ren1_dst);
-                                       if (update_file(o, 0, &mfi.oid,
-                                                       mfi.mode, ren1_dst))
-                                               clean_merge = -1;
-                                       try_merge = 0;
-                               } else {
-                                       char *new_path = unique_path(o, ren1_dst, branch2);
-                                       output(o, 1, _("Adding as %s instead"), new_path);
-                                       if (update_file(o, 0, &dst_other.oid,
-                                                       dst_other.mode, new_path))
-                                               clean_merge = -1;
-                                       free(new_path);
-                               }
+                               /*
+                                * Probably not a clean merge, but it's
+                                * premature to set clean_merge to 0 here,
+                                * because if the rename merges cleanly and
+                                * the merge exactly matches the newly added
+                                * file, then the merge will be clean.
+                                */
+                               setup_rename_conflict_info(RENAME_ADD,
+                                                          ren1->pair,
+                                                          NULL,
+                                                          branch1,
+                                                          branch2,
+                                                          ren1->dst_entry,
+                                                          NULL,
+                                                          o,
+                                                          ren1->src_entry,
+                                                          NULL);
                        } else
                                try_merge = 1;
 
@@ -3053,7 +3129,8 @@ static int handle_content_merge(struct merge_options *o,
                        df_conflict_remains = 1;
        }
        if (merge_mode_and_contents(o, &one, &a, &b, path,
-                                   o->branch1, o->branch2, &mfi))
+                                   o->branch1, o->branch2,
+                                   o->call_depth * 2, &mfi))
                return -1;
 
        /*
@@ -3183,6 +3260,15 @@ static int process_entry(struct merge_options *o,
                                                  conflict_info->branch2))
                                clean_merge = -1;
                        break;
+               case RENAME_ADD:
+                       /*
+                        * Probably unclean merge, but if the renamed file
+                        * merges cleanly and the result can then be
+                        * two-way merged cleanly with the added file, I
+                        * guess it's a clean merge?
+                        */
+                       clean_merge = handle_rename_add(o, conflict_info);
+                       break;
                case RENAME_DELETE:
                        clean_merge = 0;
                        if (handle_rename_delete(o,
@@ -3197,9 +3283,14 @@ static int process_entry(struct merge_options *o,
                                clean_merge = -1;
                        break;
                case RENAME_TWO_FILES_TO_ONE:
-                       clean_merge = 0;
-                       if (handle_rename_rename_2to1(o, conflict_info))
-                               clean_merge = -1;
+                       /*
+                        * Probably unclean merge, but if the two renamed
+                        * files merge cleanly and the two resulting files
+                        * can then be two-way merged cleanly, I guess it's
+                        * a clean merge?
+                        */
+                       clean_merge = handle_rename_rename_2to1(o,
+                                                               conflict_info);
                        break;
                default:
                        entry->processed = 0;
@@ -3267,14 +3358,27 @@ static int process_entry(struct merge_options *o,
                                clean_merge = -1;
                }
        } else if (a_oid && b_oid) {
-               /* Case C: Added in both (check for same permissions) and */
-               /* case D: Modified in both, but differently. */
-               int is_dirty = 0; /* unpack_trees would have bailed if dirty */
-               clean_merge = handle_content_merge(o, path, is_dirty,
-                                                  o_oid, o_mode,
-                                                  a_oid, a_mode,
-                                                  b_oid, b_mode,
-                                                  NULL);
+               if (!o_oid) {
+                       /* Case C: Added in both (check for same permissions) */
+                       output(o, 1,
+                              _("CONFLICT (add/add): Merge conflict in %s"),
+                              path);
+                       clean_merge = handle_file_collision(o,
+                                                           path, NULL, NULL,
+                                                           o->branch1,
+                                                           o->branch2,
+                                                           a_oid, a_mode,
+                                                           b_oid, b_mode);
+               } else {
+                       /* case D: Modified in both, but differently. */
+                       int is_dirty = 0; /* unpack_trees would have bailed if dirty */
+                       clean_merge = handle_content_merge(o, path,
+                                                          is_dirty,
+                                                          o_oid, o_mode,
+                                                          a_oid, a_mode,
+                                                          b_oid, b_mode,
+                                                          NULL);
+               }
        } else if (!o_oid && !a_oid && !b_oid) {
                /*
                 * this entry was deleted altogether. a_mode == 0 means
diff --git a/midx.c b/midx.c
index 2a6a24fcd7eff1a074c37e6c556f2143ef134c19..8a505fd423efccf9986079542b47967cc93df7dc 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -931,7 +931,7 @@ int write_midx_file(const char *object_dir)
 
 void clear_midx_file(struct repository *r)
 {
-       char *midx = get_midx_filename(r->objects->objectdir);
+       char *midx = get_midx_filename(r->objects->odb->path);
 
        if (r->objects && r->objects->multi_pack_index) {
                close_midx(r->objects->multi_pack_index);
index d87e7ca91cdecb158ca93659fb58968e92b18b31..2473314d686858493c6730e895e7106e44a462f9 100644 (file)
@@ -5,7 +5,9 @@
 #include "commit.h"
 #include "refs.h"
 
-static int notes_cache_match_validity(const char *ref, const char *validity)
+static int notes_cache_match_validity(struct repository *r,
+                                     const char *ref,
+                                     const char *validity)
 {
        struct object_id oid;
        struct commit *commit;
@@ -16,7 +18,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(the_repository, &oid, 1);
+       commit = lookup_commit_reference_gently(r, &oid, 1);
        if (!commit)
                return 0;
 
@@ -30,8 +32,8 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
        return ret;
 }
 
-void notes_cache_init(struct notes_cache *c, const char *name,
-                    const char *validity)
+void notes_cache_init(struct repository *r, struct notes_cache *c,
+                     const char *name, const char *validity)
 {
        struct strbuf ref = STRBUF_INIT;
        int flags = NOTES_INIT_WRITABLE;
@@ -40,7 +42,7 @@ void notes_cache_init(struct notes_cache *c, const char *name,
        c->validity = xstrdup(validity);
 
        strbuf_addf(&ref, "refs/notes/%s", name);
-       if (!notes_cache_match_validity(ref.buf, validity))
+       if (!notes_cache_match_validity(r, ref.buf, validity))
                flags |= NOTES_INIT_EMPTY;
        init_notes(&c->tree, ref.buf, combine_notes_overwrite, flags);
        strbuf_release(&ref);
index aeeee8409d4320644a1f618f5cd25b815be52f1c..56f8c98e2445f036b1c3897dce976f419372cb61 100644 (file)
@@ -3,13 +3,15 @@
 
 #include "notes.h"
 
+struct repository;
+
 struct notes_cache {
        struct notes_tree tree;
        char *validity;
 };
 
-void notes_cache_init(struct notes_cache *c, const char *name,
-                    const char *validity);
+void notes_cache_init(struct repository *r, struct notes_cache *c,
+                     const char *name, const char *validity);
 int notes_cache_write(struct notes_cache *c);
 
 char *notes_cache_get(struct notes_cache *c, struct object_id *oid, size_t
index bd05d50b051288cb466de5afed52993a1edf3b1d..72688d301b7dd41ed1aa8ab5d3e5e61a6f4054c5 100644 (file)
@@ -18,11 +18,13 @@ struct notes_merge_pair {
        struct object_id obj, base, local, remote;
 };
 
-void init_notes_merge_options(struct notes_merge_options *o)
+void init_notes_merge_options(struct repository *r,
+                             struct notes_merge_options *o)
 {
        memset(o, 0, sizeof(struct notes_merge_options));
        strbuf_init(&(o->commit_msg), 0);
        o->verbosity = NOTES_MERGE_VERBOSITY_DEFAULT;
+       o->repo = r;
 }
 
 static int path_to_oid(const char *path, struct object_id *oid)
@@ -127,7 +129,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
        trace_printf("\tdiff_tree_remote(base = %.7s, remote = %.7s)\n",
               oid_to_hex(base), oid_to_hex(remote));
 
-       repo_diff_setup(the_repository, &opt);
+       repo_diff_setup(o->repo, &opt);
        opt.flags.recursive = 1;
        opt.output_format = DIFF_FORMAT_NO_OUTPUT;
        diff_setup_done(&opt);
@@ -190,7 +192,7 @@ static void diff_tree_local(struct notes_merge_options *o,
        trace_printf("\tdiff_tree_local(len = %i, base = %.7s, local = %.7s)\n",
               len, oid_to_hex(base), oid_to_hex(local));
 
-       repo_diff_setup(the_repository, &opt);
+       repo_diff_setup(o->repo, &opt);
        opt.flags.recursive = 1;
        opt.output_format = DIFF_FORMAT_NO_OUTPUT;
        diff_setup_done(&opt);
@@ -350,7 +352,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
 
        status = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL,
                          &local, o->local_ref, &remote, o->remote_ref,
-                         &the_index, NULL);
+                         o->repo->index, NULL);
 
        free(base.ptr);
        free(local.ptr);
@@ -556,7 +558,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(the_repository, &local_oid)))
+       else if (!(local = lookup_commit_reference(o->repo, &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));
@@ -574,7 +576,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(the_repository, &remote_oid))) {
+       } else if (!(remote = lookup_commit_reference(o->repo, &remote_oid))) {
                die("Could not parse remote commit %s (%s)",
                    oid_to_hex(&remote_oid), o->remote_ref);
        }
@@ -711,7 +713,7 @@ int notes_merge_commit(struct notes_merge_options *o,
                /* write file as blob, and add to partial_tree */
                if (stat(path.buf, &st))
                        die_errno("Failed to stat '%s'", path.buf);
-               if (index_path(&the_index, &blob_oid, path.buf, &st, HASH_WRITE_OBJECT))
+               if (index_path(o->repo->index, &blob_oid, path.buf, &st, HASH_WRITE_OBJECT))
                        die("Failed to write blob object from '%s'", path.buf);
                if (add_note(partial_tree, &obj_oid, &blob_oid, NULL))
                        die("Failed to add resolved note '%s' to notes tree",
index 6c74e9385b83ce317d6ca91f328c7790d0753e2c..99f9c709c536ac19c677e97348e9924c2764d217 100644 (file)
@@ -6,6 +6,7 @@
 
 struct commit;
 struct object_id;
+struct repository;
 
 #define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE"
 
@@ -15,6 +16,7 @@ enum notes_merge_verbosity {
 };
 
 struct notes_merge_options {
+       struct repository *repo;
        const char *local_ref;
        const char *remote_ref;
        struct strbuf commit_msg;
@@ -23,7 +25,8 @@ struct notes_merge_options {
        unsigned has_worktree:1;
 };
 
-void init_notes_merge_options(struct notes_merge_options *o);
+void init_notes_merge_options(struct repository *r,
+                             struct notes_merge_options *o);
 
 /*
  * Merge notes from o->remote_ref into o->local_ref
index 63b7605a3e0b3000641d8f39f22e1d5c8139f19b..e16aa38caebe69ae9bb3ace066f8103a60457407 100644 (file)
@@ -7,40 +7,33 @@
 #include "sha1-array.h"
 #include "strbuf.h"
 
-struct alternate_object_database {
-       struct alternate_object_database *next;
-
-       /* see alt_scratch_buf() */
-       struct strbuf scratch;
-       size_t base_len;
+struct object_directory {
+       struct object_directory *next;
 
        /*
-        * Used to store the results of readdir(3) calls when searching
-        * for unique abbreviated hashes.  This cache is never
-        * invalidated, thus it's racy and not necessarily accurate.
-        * That's fine for its purpose; don't use it for tasks requiring
-        * greater accuracy!
+        * Used to store the results of readdir(3) calls when we are OK
+        * sacrificing accuracy due to races for speed. That includes
+        * object existence with OBJECT_INFO_QUICK, as well as
+        * our search for unique abbreviated hashes. Don't use it for tasks
+        * requiring greater accuracy!
+        *
+        * Be sure to call odb_load_loose_cache() before using.
         */
        char loose_objects_subdir_seen[256];
-       struct oid_array loose_objects_cache;
+       struct oid_array loose_objects_cache[256];
 
        /*
         * Path to the alternative object store. If this is a relative path,
         * it is relative to the current working directory.
         */
-       char path[FLEX_ARRAY];
+       char *path;
 };
+
 void prepare_alt_odb(struct repository *r);
 char *compute_alternate_path(const char *path, struct strbuf *err);
-typedef int alt_odb_fn(struct alternate_object_database *, void *);
+typedef int alt_odb_fn(struct object_directory *, void *);
 int foreach_alt_odb(alt_odb_fn, void*);
 
-/*
- * Allocate a "struct alternate_object_database" but do _not_ actually
- * add it to the list of alternates.
- */
-struct alternate_object_database *alloc_alt_odb(const char *dir);
-
 /*
  * Add the directory to the on-disk alternates file; the new entry will also
  * take effect in the current process.
@@ -55,12 +48,14 @@ void add_to_alternates_file(const char *dir);
 void add_to_alternates_memory(const char *dir);
 
 /*
- * Returns a scratch strbuf pre-filled with the alternate object directory,
- * including a trailing slash, which can be used to access paths in the
- * alternate. Always use this over direct access to alt->scratch, as it
- * cleans up any previous use of the scratch buffer.
+ * Populate and return the loose object cache array corresponding to the
+ * given object ID.
  */
-struct strbuf *alt_scratch_buf(struct alternate_object_database *alt);
+struct oid_array *odb_loose_cache(struct object_directory *odb,
+                                 const struct object_id *oid);
+
+/* Empty the loose object cache for the specified object directory. */
+void odb_clear_loose_cache(struct object_directory *odb);
 
 struct packed_git {
        struct packed_git *next;
@@ -92,17 +87,21 @@ struct multi_pack_index;
 
 struct raw_object_store {
        /*
-        * Path to the repository's object store.
-        * Cannot be NULL after initialization.
+        * Set of all object directories; the main directory is first (and
+        * cannot be NULL after initialization). Subsequent directories are
+        * alternates.
         */
-       char *objectdir;
+       struct object_directory *odb;
+       struct object_directory **odb_tail;
+       int loaded_alternates;
 
-       /* Path to extra alternate object database if not NULL */
+       /*
+        * A list of alternate object directories loaded from the environment;
+        * this should not generally need to be accessed directly, but will
+        * populate the "odb" list when prepare_alt_odb() is run.
+        */
        char *alternate_db;
 
-       struct alternate_object_database *alt_odb_list;
-       struct alternate_object_database **alt_odb_tail;
-
        /*
         * Objects that should be substituted by other objects
         * (see git-replace(1)).
@@ -157,7 +156,7 @@ void raw_object_store_clear(struct raw_object_store *o);
  * Put in `buf` the name of the file in the local object database that
  * would be used to store a loose object with the specified sha1.
  */
-void sha1_file_name(struct repository *r, struct strbuf *buf, const unsigned char *sha1);
+const char *loose_object_path(struct repository *r, struct strbuf *buf, const unsigned char *sha1);
 
 void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
 
index e54160550c5a8e864f2e2bbcc58a29ff73045f8f..a5c5cf830fc52d03adb4283cafd097218e1117a0 100644 (file)
--- a/object.c
+++ b/object.c
@@ -482,27 +482,26 @@ struct raw_object_store *raw_object_store_new(void)
        return o;
 }
 
-static void free_alt_odb(struct alternate_object_database *alt)
+static void free_object_directory(struct object_directory *odb)
 {
-       strbuf_release(&alt->scratch);
-       oid_array_clear(&alt->loose_objects_cache);
-       free(alt);
+       free(odb->path);
+       odb_clear_loose_cache(odb);
+       free(odb);
 }
 
-static void free_alt_odbs(struct raw_object_store *o)
+static void free_object_directories(struct raw_object_store *o)
 {
-       while (o->alt_odb_list) {
-               struct alternate_object_database *next;
+       while (o->odb) {
+               struct object_directory *next;
 
-               next = o->alt_odb_list->next;
-               free_alt_odb(o->alt_odb_list);
-               o->alt_odb_list = next;
+               next = o->odb->next;
+               free_object_directory(o->odb);
+               o->odb = next;
        }
 }
 
 void raw_object_store_clear(struct raw_object_store *o)
 {
-       FREE_AND_NULL(o->objectdir);
        FREE_AND_NULL(o->alternate_db);
 
        oidmap_free(o->replace_map, 1);
@@ -512,8 +511,9 @@ void raw_object_store_clear(struct raw_object_store *o)
        o->commit_graph = NULL;
        o->commit_graph_attempted = 0;
 
-       free_alt_odbs(o);
-       o->alt_odb_tail = NULL;
+       free_object_directories(o);
+       o->odb_tail = NULL;
+       o->loaded_alternates = 0;
 
        INIT_LIST_HEAD(&o->packed_git_mru);
        close_all_packs(o);
index 9d1b951697e9552b80a502fd587e43b615369635..5566e94abed9f0838d4c1d999ee8e90159000256 100644 (file)
@@ -77,7 +77,7 @@ void bitmap_writer_build_type_index(struct packing_data *to_pack,
                        break;
 
                default:
-                       real_type = oid_object_info(the_repository,
+                       real_type = oid_object_info(to_pack->repo,
                                                    &entry->idx.oid, NULL);
                        break;
                }
@@ -262,7 +262,7 @@ void bitmap_writer_build(struct packing_data *to_pack)
        if (writer.show_progress)
                writer.progress = start_progress("Building bitmaps", writer.selected_nr);
 
-       repo_init_revisions(the_repository, &revs, NULL);
+       repo_init_revisions(to_pack->repo, &revs, NULL);
        revs.tag_objects = 1;
        revs.tree_objects = 1;
        revs.blob_objects = 1;
@@ -363,7 +363,7 @@ static int date_compare(const void *_a, const void *_b)
 void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack)
 {
        struct bitmap_index *bitmap_git;
-       if (!(bitmap_git = prepare_bitmap_git()))
+       if (!(bitmap_git = prepare_bitmap_git(to_pack->repo)))
                return;
 
        writer.reused = kh_init_sha1();
index 5848cc93aa254b8549f4c569882b5d781984ca47..4695aaf6b4eda41ec2479a326ddbe7a0bed065ab 100644 (file)
@@ -328,14 +328,15 @@ static int load_pack_bitmap(struct bitmap_index *bitmap_git)
        return -1;
 }
 
-static int open_pack_bitmap(struct bitmap_index *bitmap_git)
+static int open_pack_bitmap(struct repository *r,
+                           struct bitmap_index *bitmap_git)
 {
        struct packed_git *p;
        int ret = -1;
 
        assert(!bitmap_git->map);
 
-       for (p = get_all_packs(the_repository); p; p = p->next) {
+       for (p = get_all_packs(r); p; p = p->next) {
                if (open_pack_bitmap_1(bitmap_git, p) == 0)
                        ret = 0;
        }
@@ -343,11 +344,11 @@ static int open_pack_bitmap(struct bitmap_index *bitmap_git)
        return ret;
 }
 
-struct bitmap_index *prepare_bitmap_git(void)
+struct bitmap_index *prepare_bitmap_git(struct repository *r)
 {
        struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
 
-       if (!open_pack_bitmap(bitmap_git) && !load_pack_bitmap(bitmap_git))
+       if (!open_pack_bitmap(r, bitmap_git) && !load_pack_bitmap(bitmap_git))
                return bitmap_git;
 
        free_bitmap_index(bitmap_git);
@@ -690,7 +691,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
        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)
+       if (open_pack_bitmap(revs->repo, bitmap_git) < 0)
                goto cleanup;
 
        for (i = 0; i < revs->pending.nr; ++i) {
@@ -955,7 +956,7 @@ void test_bitmap_walk(struct rev_info *revs)
        struct bitmap_test_data tdata;
        struct bitmap_index *bitmap_git;
 
-       if (!(bitmap_git = prepare_bitmap_git()))
+       if (!(bitmap_git = prepare_bitmap_git(revs->repo)))
                die("failed to load bitmap indexes");
 
        if (revs->pending.nr != 1)
index 189dd68ad30b14281b42ea43bb21739006ea6061..8418ba8c7929ed49aec17d5a25d8d0a309f971b8 100644 (file)
@@ -6,6 +6,7 @@
 #include "pack-objects.h"
 
 struct commit;
+struct repository;
 struct rev_info;
 
 struct bitmap_disk_header {
@@ -39,7 +40,7 @@ typedef int (*show_reachable_fn)(
 
 struct bitmap_index;
 
-struct bitmap_index *prepare_bitmap_git(void);
+struct bitmap_index *prepare_bitmap_git(struct repository *r);
 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 *,
index fa5f0ff8fa57461486ab2f82e58ad3eeffab77f1..2cc3603189b8cd27781fd16cba2eb10a16817038 100644 (file)
@@ -48,7 +48,8 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,
        return data_crc != ntohl(*index_crc);
 }
 
-static int verify_packfile(struct packed_git *p,
+static int verify_packfile(struct repository *r,
+                          struct packed_git *p,
                           struct pack_window **w_curs,
                           verify_fn fn,
                           struct progress *progress, uint32_t base_count)
@@ -135,7 +136,7 @@ static int verify_packfile(struct packed_git *p,
                        data = NULL;
                        data_valid = 0;
                } else {
-                       data = unpack_entry(the_repository, p, entries[i].offset, &type, &size);
+                       data = unpack_entry(r, p, entries[i].offset, &type, &size);
                        data_valid = 1;
                }
 
@@ -186,7 +187,7 @@ int verify_pack_index(struct packed_git *p)
        return err;
 }
 
-int verify_pack(struct packed_git *p, verify_fn fn,
+int verify_pack(struct repository *r, struct packed_git *p, verify_fn fn,
                struct progress *progress, uint32_t base_count)
 {
        int err = 0;
@@ -196,7 +197,7 @@ int verify_pack(struct packed_git *p, verify_fn fn,
        if (!p->index_data)
                return -1;
 
-       err |= verify_packfile(p, &w_curs, fn, progress, base_count);
+       err |= verify_packfile(r, p, &w_curs, fn, progress, base_count);
        unuse_pack(&w_curs);
 
        return err;
index b6cdbb0166fb5a3d6af3cfda2e7e259e3d54abe8..9c45842df389270baf73f4aa5b65df2004c9ba4d 100644 (file)
@@ -99,7 +99,7 @@ static void prepare_in_pack_by_idx(struct packing_data *pdata)
         * (i.e. in_pack_idx also zero) should return NULL.
         */
        mapping[cnt++] = NULL;
-       for (p = get_all_packs(the_repository); p; p = p->next, cnt++) {
+       for (p = get_all_packs(pdata->repo); p; p = p->next, cnt++) {
                if (cnt == nr) {
                        free(mapping);
                        return;
@@ -133,8 +133,10 @@ void oe_map_new_pack(struct packing_data *pack,
 }
 
 /* assume pdata is already zero'd by caller */
-void prepare_packing_data(struct packing_data *pdata)
+void prepare_packing_data(struct repository *r, struct packing_data *pdata)
 {
+       pdata->repo = r;
+
        if (git_env_bool("GIT_TEST_FULL_IN_PACK_ARRAY", 0)) {
                /*
                 * do not initialize in_pack_by_idx[] to force the
index dc869f26c2b753593a875f275d896933b7723b31..3cd8d1f00a95978a5a8c86805506b9927aefcd0e 100644 (file)
@@ -5,6 +5,8 @@
 #include "thread-utils.h"
 #include "pack.h"
 
+struct repository;
+
 #define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024)
 
 #define OE_DFS_STATE_BITS      2
@@ -127,6 +129,7 @@ struct object_entry {
 };
 
 struct packing_data {
+       struct repository *repo;
        struct object_entry *objects;
        uint32_t nr_objects, nr_alloc;
 
@@ -163,7 +166,7 @@ struct packing_data {
        unsigned char *layer;
 };
 
-void prepare_packing_data(struct packing_data *pdata);
+void prepare_packing_data(struct repository *r, struct packing_data *pdata);
 
 static inline void packing_data_lock(struct packing_data *pdata)
 {
diff --git a/pack.h b/pack.h
index 34a9d458b411927b7c1e121e88387e022841ea2a..da99fdd1d2baf7574b606f4c2bc6e1dcfeacf0fa 100644 (file)
--- a/pack.h
+++ b/pack.h
@@ -4,6 +4,8 @@
 #include "object.h"
 #include "csum-file.h"
 
+struct repository;
+
 /*
  * Packed object header
  */
@@ -80,7 +82,7 @@ typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned lo
 extern const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, const struct pack_idx_option *, const unsigned char *sha1);
 extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);
 extern int verify_pack_index(struct packed_git *);
-extern int verify_pack(struct packed_git *, verify_fn fn, struct progress *, uint32_t);
+extern int verify_pack(struct repository *, struct packed_git *, verify_fn fn, struct progress *, uint32_t);
 extern off_t write_pack_header(struct hashfile *f, uint32_t);
 extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
 extern char *index_pack_lockfile(int fd);
index d1e6683ffe877d9bf1b0996f25f0720fdffe983a..0fe9c21bf108965867ca691c245c3be0124a9102 100644 (file)
@@ -971,16 +971,16 @@ static void prepare_packed_git_mru(struct repository *r)
 
 static void prepare_packed_git(struct repository *r)
 {
-       struct alternate_object_database *alt;
+       struct object_directory *odb;
 
        if (r->objects->packed_git_initialized)
                return;
-       prepare_multi_pack_index_one(r, r->objects->objectdir, 1);
-       prepare_packed_git_one(r, r->objects->objectdir, 1);
+
        prepare_alt_odb(r);
-       for (alt = r->objects->alt_odb_list; alt; alt = alt->next) {
-               prepare_multi_pack_index_one(r, alt->path, 0);
-               prepare_packed_git_one(r, alt->path, 0);
+       for (odb = r->objects->odb; odb; odb = odb->next) {
+               int local = (odb == r->objects->odb);
+               prepare_multi_pack_index_one(r, odb->path, local);
+               prepare_packed_git_one(r, odb->path, local);
        }
        rearrange_packed_git(r);
 
@@ -992,6 +992,11 @@ static void prepare_packed_git(struct repository *r)
 
 void reprepare_packed_git(struct repository *r)
 {
+       struct object_directory *odb;
+
+       for (odb = r->objects->odb; odb; odb = odb->next)
+               odb_clear_loose_cache(odb);
+
        r->objects->approximate_object_count_valid = 0;
        r->objects->packed_git_initialized = 0;
        prepare_packed_git(r);
index 8c9edce52f63bcb1085b119b3a2264a97b1fb374..e2f3eaed072f77d63890ec814d810199f57248d5 100644 (file)
@@ -18,7 +18,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
        } else {
                v = strtol(arg, (char **)&arg, 10);
                if (*arg)
-                       return opterror(opt, "expects a numerical value", 0);
+                       return error(_("option `%s' expects a numerical value"),
+                                    opt->long_name);
                if (v && v < MINIMUM_ABBREV)
                        v = MINIMUM_ABBREV;
                else if (v > 40)
@@ -47,8 +48,8 @@ int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
                arg = unset ? "never" : (const char *)opt->defval;
        value = git_config_colorbool(NULL, arg);
        if (value < 0)
-               return opterror(opt,
-                       "expects \"always\", \"auto\", or \"never\"", 0);
+               return error(_("option `%s' expects \"always\", \"auto\", or \"never\""),
+                            opt->long_name);
        *(int *)opt->value = value;
        return 0;
 }
index 3b874a83a0c897845deeec37c1a3b85e0b625050..9f84bacce64e72d117be2bdbe91db6d4c190e257 100644 (file)
@@ -32,7 +32,7 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
                p->argc--;
                *arg = *++p->argv;
        } else
-               return opterror(opt, "requires a value", flags);
+               return error(_("%s requires a value"), optname(opt, flags));
        return 0;
 }
 
@@ -49,7 +49,6 @@ static int opt_command_mode_error(const struct option *opt,
                                  int flags)
 {
        const struct option *that;
-       struct strbuf message = STRBUF_INIT;
        struct strbuf that_name = STRBUF_INIT;
 
        /*
@@ -67,13 +66,13 @@ static int opt_command_mode_error(const struct option *opt,
                        strbuf_addf(&that_name, "--%s", that->long_name);
                else
                        strbuf_addf(&that_name, "-%c", that->short_name);
-               strbuf_addf(&message, ": incompatible with %s", that_name.buf);
+               error(_("%s is incompatible with %s"),
+                     optname(opt, flags), that_name.buf);
                strbuf_release(&that_name);
-               opterror(opt, message.buf, flags);
-               strbuf_release(&message);
                return -1;
        }
-       return opterror(opt, ": incompatible with something else", flags);
+       return error(_("%s : incompatible with something else"),
+                    optname(opt, flags));
 }
 
 static int get_value(struct parse_opt_ctx_t *p,
@@ -86,11 +85,11 @@ static int get_value(struct parse_opt_ctx_t *p,
        int err;
 
        if (unset && p->opt)
-               return opterror(opt, "takes no value", flags);
+               return error(_("%s takes no value"), optname(opt, flags));
        if (unset && (opt->flags & PARSE_OPT_NONEG))
-               return opterror(opt, "isn't available", flags);
+               return error(_("%s isn't available"), optname(opt, flags));
        if (!(flags & OPT_SHORT) && p->opt && (opt->flags & PARSE_OPT_NOARG))
-               return opterror(opt, "takes no value", flags);
+               return error(_("%s takes no value"), optname(opt, flags));
 
        switch (opt->type) {
        case OPTION_LOWLEVEL_CALLBACK:
@@ -176,7 +175,8 @@ static int get_value(struct parse_opt_ctx_t *p,
                        return -1;
                *(int *)opt->value = strtol(arg, (char **)&s, 10);
                if (*s)
-                       return opterror(opt, "expects a numerical value", flags);
+                       return error(_("%s expects a numerical value"),
+                                    optname(opt, flags));
                return 0;
 
        case OPTION_MAGNITUDE:
@@ -191,13 +191,13 @@ static int get_value(struct parse_opt_ctx_t *p,
                if (get_arg(p, opt, flags, &arg))
                        return -1;
                if (!git_parse_ulong(arg, opt->value))
-                       return opterror(opt,
-                               "expects a non-negative integer value with an optional k/m/g suffix",
-                               flags);
+                       return error(_("%s expects a non-negative integer value"
+                                      " with an optional k/m/g suffix"),
+                                    optname(opt, flags));
                return 0;
 
        default:
-               die("should not happen, someone must be hit on the forehead");
+               BUG("opt->type %d should not happen", opt->type);
        }
 }
 
@@ -236,7 +236,7 @@ static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option *optio
 }
 
 static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
-                          const struct option *options)
+                         const struct option *options)
 {
        const struct option *all_opts = options;
        const char *arg_end = strchrnul(arg, '=');
@@ -257,7 +257,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
                        if (!rest)
                                continue;
                        if (*rest == '=')
-                               return opterror(options, "takes no value", flags);
+                               return error(_("%s takes no value"),
+                                            optname(options, flags));
                        if (*rest)
                                continue;
                        p->out[p->cpidx++] = arg - 2;
@@ -318,8 +319,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
        }
 
        if (ambiguous_option) {
-               error("Ambiguous option: %s "
-                       "(could be --%s%s or --%s%s)",
+               error(_("ambiguous option: %s "
+                       "(could be --%s%s or --%s%s)"),
                        arg,
                        (ambiguous_flags & OPT_UNSET) ?  "no-" : "",
                        ambiguous_option->long_name,
@@ -352,7 +353,7 @@ static void check_typos(const char *arg, const struct option *options)
                return;
 
        if (starts_with(arg, "no-")) {
-               error ("did you mean `--%s` (with two dashes ?)", arg);
+               error(_("did you mean `--%s` (with two dashes ?)"), arg);
                exit(129);
        }
 
@@ -360,7 +361,7 @@ static void check_typos(const char *arg, const struct option *options)
                if (!options->long_name)
                        continue;
                if (starts_with(options->long_name, arg)) {
-                       error ("did you mean `--%s` (with two dashes ?)", arg);
+                       error(_("did you mean `--%s` (with two dashes ?)"), arg);
                        exit(129);
                }
        }
@@ -423,7 +424,7 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
        ctx->flags = flags;
        if ((flags & PARSE_OPT_KEEP_UNKNOWN) &&
            (flags & PARSE_OPT_STOP_AT_NON_OPTION))
-               die("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together");
+               BUG("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together");
        parse_options_check(options);
 }
 
@@ -516,7 +517,7 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
        show_negated_gitcomp(original_opts, -1);
        show_negated_gitcomp(original_opts, nr_noopts);
        fputc('\n', stdout);
-       exit(0);
+       return PARSE_OPT_COMPLETE;
 }
 
 static int usage_with_options_internal(struct parse_opt_ctx_t *,
@@ -638,16 +639,18 @@ int parse_options(int argc, const char **argv, const char *prefix,
        case PARSE_OPT_HELP:
        case PARSE_OPT_ERROR:
                exit(129);
+       case PARSE_OPT_COMPLETE:
+               exit(0);
        case PARSE_OPT_NON_OPTION:
        case PARSE_OPT_DONE:
                break;
        default: /* PARSE_OPT_UNKNOWN */
                if (ctx.argv[0][1] == '-') {
-                       error("unknown option `%s'", ctx.argv[0] + 2);
+                       error(_("unknown option `%s'"), ctx.argv[0] + 2);
                } else if (isascii(*ctx.opt)) {
-                       error("unknown switch `%c'", *ctx.opt);
+                       error(_("unknown switch `%c'"), *ctx.opt);
                } else {
-                       error("unknown non-ascii option in string: `%s'",
+                       error(_("unknown non-ascii option in string: `%s'"),
                              ctx.argv[0]);
                }
                usage_with_options(usagestr, options);
@@ -773,12 +776,17 @@ void NORETURN usage_msg_opt(const char *msg,
        usage_with_options(usagestr, options);
 }
 
-#undef opterror
-int opterror(const struct option *opt, const char *reason, int flags)
+const char *optname(const struct option *opt, int flags)
 {
+       static struct strbuf sb = STRBUF_INIT;
+
+       strbuf_reset(&sb);
        if (flags & OPT_SHORT)
-               return error("switch `%c' %s", opt->short_name, reason);
-       if (flags & OPT_UNSET)
-               return error("option `no-%s' %s", opt->long_name, reason);
-       return error("option `%s' %s", opt->long_name, reason);
+               strbuf_addf(&sb, "switch `%c'", opt->short_name);
+       else if (flags & OPT_UNSET)
+               strbuf_addf(&sb, "option `no-%s'", opt->long_name);
+       else
+               strbuf_addf(&sb, "option `%s'", opt->long_name);
+
+       return sb.buf;
 }
index 6c4fe2016d65f1093400f8f5080085eb244f0026..14fe32428e57aee0716517219e3fc925ac5e8a0d 100644 (file)
@@ -175,21 +175,18 @@ struct option {
  * Returns the number of arguments left in argv[].
  */
 extern int parse_options(int argc, const char **argv, const char *prefix,
-                         const struct option *options,
-                         const char * const usagestr[], int flags);
+                        const struct option *options,
+                        const char * const usagestr[], int flags);
 
 extern NORETURN void usage_with_options(const char * const *usagestr,
-                                        const struct option *options);
+                                       const struct option *options);
 
 extern NORETURN void usage_msg_opt(const char *msg,
                                   const char * const *usagestr,
                                   const struct option *options);
 
 extern int optbug(const struct option *opt, const char *reason);
-extern int opterror(const struct option *opt, const char *reason, int flags);
-#if defined(__GNUC__)
-#define opterror(o,r,f) (opterror((o),(r),(f)), const_error())
-#endif
+const char *optname(const struct option *opt, int flags);
 
 /*
  * Use these assertions for callbacks that expect to be called with NONEG and
@@ -208,6 +205,7 @@ extern int opterror(const struct option *opt, const char *reason, int flags);
 /*----- incremental advanced APIs -----*/
 
 enum {
+       PARSE_OPT_COMPLETE = -2,
        PARSE_OPT_HELP = -1,
        PARSE_OPT_DONE,
        PARSE_OPT_NON_OPTION,
diff --git a/path.c b/path.c
index dc3294c71e1e72ae2aae9164c790e27d1237e956..03ab712839a7878e3d3b5d79c698f4e2bb29c8b1 100644 (file)
--- a/path.c
+++ b/path.c
@@ -385,7 +385,7 @@ static void adjust_git_path(const struct repository *repo,
                strbuf_splice(buf, 0, buf->len,
                              repo->index_file, strlen(repo->index_file));
        else if (dir_prefix(base, "objects"))
-               replace_dir(buf, git_dir_len + 7, repo->objects->objectdir);
+               replace_dir(buf, git_dir_len + 7, repo->objects->odb->path);
        else if (git_hooks_path && dir_prefix(base, "hooks"))
                replace_dir(buf, git_dir_len + 5, git_hooks_path);
        else if (repo->different_commondir)
index 6f005996fdc8f3e412b0faafc12e65aed359be3b..e85298f68cfeee14494466b0604e572a5c345810 100644 (file)
@@ -659,3 +659,41 @@ void clear_pathspec(struct pathspec *pathspec)
        FREE_AND_NULL(pathspec->items);
        pathspec->nr = 0;
 }
+
+int match_pathspec_attrs(const struct index_state *istate,
+                        const char *name, int namelen,
+                        const struct pathspec_item *item)
+{
+       int i;
+       char *to_free = NULL;
+
+       if (name[namelen])
+               name = to_free = xmemdupz(name, namelen);
+
+       git_check_attr(istate, name, item->attr_check);
+
+       free(to_free);
+
+       for (i = 0; i < item->attr_match_nr; i++) {
+               const char *value;
+               int matched;
+               enum attr_match_mode match_mode;
+
+               value = item->attr_check->items[i].value;
+               match_mode = item->attr_match[i].match_mode;
+
+               if (ATTR_TRUE(value))
+                       matched = (match_mode == MATCH_SET);
+               else if (ATTR_FALSE(value))
+                       matched = (match_mode == MATCH_UNSET);
+               else if (ATTR_UNSET(value))
+                       matched = (match_mode == MATCH_UNSPECIFIED);
+               else
+                       matched = (match_mode == MATCH_VALUE &&
+                                  !strcmp(item->attr_match[i].value, value));
+               if (!matched)
+                       return 0;
+       }
+
+       return 1;
+}
index a6525a65517bd08921ad836880184048e93c4cfa..1c18a2c90c4148471f52e27c39685e80a9a414e1 100644 (file)
@@ -80,13 +80,13 @@ struct pathspec {
  * Any arguments used are copied. It is safe for the caller to modify
  * or free 'prefix' and 'args' after calling this function.
  */
-extern void parse_pathspec(struct pathspec *pathspec,
-                          unsigned magic_mask,
-                          unsigned flags,
-                          const char *prefix,
-                          const char **args);
-extern void copy_pathspec(struct pathspec *dst, const struct pathspec *src);
-extern void clear_pathspec(struct pathspec *);
+void parse_pathspec(struct pathspec *pathspec,
+                   unsigned magic_mask,
+                   unsigned flags,
+                   const char *prefix,
+                   const char **args);
+void copy_pathspec(struct pathspec *dst, const struct pathspec *src);
+void clear_pathspec(struct pathspec *);
 
 static inline int ps_strncmp(const struct pathspec_item *item,
                             const char *s1, const char *s2, size_t n)
@@ -106,10 +106,13 @@ static inline int ps_strcmp(const struct pathspec_item *item,
                return strcmp(s1, s2);
 }
 
-extern void add_pathspec_matches_against_index(const struct pathspec *pathspec,
-                                              const struct index_state *istate,
-                                              char *seen);
-extern char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
-                                                  const struct index_state *istate);
+void add_pathspec_matches_against_index(const struct pathspec *pathspec,
+                                       const struct index_state *istate,
+                                       char *seen);
+char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
+                                           const struct index_state *istate);
+int match_pathspec_attrs(const struct index_state *istate,
+                        const char *name, int namelen,
+                        const struct pathspec_item *item);
 
 #endif /* PATHSPEC_H */
diff --git a/quote.c b/quote.c
index c95dd2cafbaa85c9c443a229134842bf06ce3200..7f2aa6faa43fed0cd19f23f6fcfdc7b0ebea5c01 100644 (file)
--- a/quote.c
+++ b/quote.c
@@ -234,7 +234,7 @@ static size_t next_quote_pos(const char *s, ssize_t maxlen)
  *     Return value is the same as in (1).
  */
 static size_t quote_c_style_counted(const char *name, ssize_t maxlen,
-                                    struct strbuf *sb, FILE *fp, int no_dq)
+                                   struct strbuf *sb, FILE *fp, int no_dq)
 {
 #undef EMIT
 #define EMIT(c)                                 \
index bd45dc3e24d7dc28820d26cc6e6d377f92fda46d..bfff271a3db92cfaaa93d23c5bf52297dda0419e 100644 (file)
@@ -316,7 +316,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
                        changed |= DATA_CHANGED;
                return changed;
        default:
-               die("internal error: ce_mode is %o", ce->ce_mode);
+               BUG("unsupported ce_mode: %o", ce->ce_mode);
        }
 
        changed |= match_stat_data(&ce->ce_stat_data, st);
@@ -672,7 +672,8 @@ static struct cache_entry *create_alias_ce(struct index_state *istate,
        struct cache_entry *new_entry;
 
        if (alias->ce_flags & CE_ADDED)
-               die("Will not add file alias '%s' ('%s' already exists in index)", ce->name, alias->name);
+               die(_("will not add file alias '%s' ('%s' already exists in index)"),
+                   ce->name, alias->name);
 
        /* Ok, create the new entry using the name of the existing alias */
        len = ce_namelen(alias);
@@ -687,7 +688,7 @@ void set_object_name_for_intent_to_add_entry(struct cache_entry *ce)
 {
        struct object_id oid;
        if (write_object_file("", 0, blob_type, &oid))
-               die("cannot create an empty blob in the object database");
+               die(_("cannot create an empty blob in the object database"));
        oidcpy(&ce->oid, &oid);
 }
 
@@ -708,7 +709,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
                newflags |= HASH_RENORMALIZE;
 
        if (!S_ISREG(st_mode) && !S_ISLNK(st_mode) && !S_ISDIR(st_mode))
-               return error("%s: can only add regular files, symbolic links or git-directories", path);
+               return error(_("%s: can only add regular files, symbolic links or git-directories"), path);
 
        namelen = strlen(path);
        if (S_ISDIR(st_mode)) {
@@ -763,7 +764,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
        if (!intent_only) {
                if (index_path(istate, &ce->oid, path, st, newflags)) {
                        discard_cache_entry(ce);
-                       return error("unable to index file %s", path);
+                       return error(_("unable to index file '%s'"), path);
                }
        } else
                set_object_name_for_intent_to_add_entry(ce);
@@ -782,7 +783,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
                discard_cache_entry(ce);
        else if (add_index_entry(istate, ce, add_option)) {
                discard_cache_entry(ce);
-               return error("unable to add %s to index", path);
+               return error(_("unable to add '%s' to index"), path);
        }
        if (verbose && !was_same)
                printf("add '%s'\n", path);
@@ -793,7 +794,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)
 {
        struct stat st;
        if (lstat(path, &st))
-               die_errno("unable to stat '%s'", path);
+               die_errno(_("unable to stat '%s'"), path);
        return add_to_index(istate, path, &st, flags);
 }
 
@@ -818,7 +819,7 @@ struct cache_entry *make_cache_entry(struct index_state *istate,
        int len;
 
        if (!verify_path(path, mode)) {
-               error("Invalid path '%s'", path);
+               error(_("invalid path '%s'"), path);
                return NULL;
        }
 
@@ -844,7 +845,7 @@ struct cache_entry *make_transient_cache_entry(unsigned int mode, const struct o
        int len;
 
        if (!verify_path(path, mode)) {
-               error("Invalid path '%s'", path);
+               error(_("invalid path '%s'"), path);
                return NULL;
        }
 
@@ -1297,12 +1298,12 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
        if (!ok_to_add)
                return -1;
        if (!verify_path(ce->name, ce->ce_mode))
-               return error("Invalid path '%s'", ce->name);
+               return error(_("invalid path '%s'"), ce->name);
 
        if (!skip_df_check &&
            check_file_directory_conflict(istate, ce, pos, ok_to_replace)) {
                if (!ok_to_replace)
-                       return error("'%s' appears as both a file and as a directory",
+                       return error(_("'%s' appears as both a file and as a directory"),
                                     ce->name);
                pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
                pos = -pos-1;
@@ -1491,11 +1492,11 @@ int refresh_index(struct index_state *istate, unsigned int flags,
                                                  istate->cache_nr);
 
        trace_performance_enter();
-       modified_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
-       deleted_fmt = (in_porcelain ? "D\t%s\n" : "%s: needs update\n");
-       typechange_fmt = (in_porcelain ? "T\t%s\n" : "%s needs update\n");
-       added_fmt = (in_porcelain ? "A\t%s\n" : "%s needs update\n");
-       unmerged_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
+       modified_fmt   = in_porcelain ? "M\t%s\n" : "%s: needs update\n";
+       deleted_fmt    = in_porcelain ? "D\t%s\n" : "%s: needs update\n";
+       typechange_fmt = in_porcelain ? "T\t%s\n" : "%s: needs update\n";
+       added_fmt      = in_porcelain ? "A\t%s\n" : "%s: needs update\n";
+       unmerged_fmt   = in_porcelain ? "U\t%s\n" : "%s: needs merge\n";
        /*
         * Use the multi-threaded preload_index() to refresh most of the
         * cache entries quickly then in the single threaded loop below,
@@ -1682,10 +1683,10 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
        int hdr_version;
 
        if (hdr->hdr_signature != htonl(CACHE_SIGNATURE))
-               return error("bad signature");
+               return error(_("bad signature 0x%08x"), hdr->hdr_signature);
        hdr_version = ntohl(hdr->hdr_version);
        if (hdr_version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < hdr_version)
-               return error("bad index version %d", hdr_version);
+               return error(_("bad index version %d"), hdr_version);
 
        if (!verify_index_checksum)
                return 0;
@@ -1694,7 +1695,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
        the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);
        the_hash_algo->final_fn(hash, &c);
        if (!hasheq(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))
-               return error("bad index file sha1 signature");
+               return error(_("bad index file sha1 signature"));
        return 0;
 }
 
@@ -1724,9 +1725,9 @@ static int read_index_extension(struct index_state *istate,
                break;
        default:
                if (*ext < 'A' || 'Z' < *ext)
-                       return error("index uses %.4s extension, which we do not understand",
+                       return error(_("index uses %.4s extension, which we do not understand"),
                                     ext);
-               fprintf(stderr, "ignoring %.4s extension\n", ext);
+               fprintf_ln(stderr, _("ignoring %.4s extension"), ext);
                break;
        }
        return 0;
@@ -1773,7 +1774,7 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
                extended_flags = get_be16(&ondisk2->flags2) << 16;
                /* We do not yet understand any bit out of CE_EXTENDED_FLAGS */
                if (extended_flags & ~CE_EXTENDED_FLAGS)
-                       die("Unknown index entry format %08x", extended_flags);
+                       die(_("unknown index entry format 0x%08x"), extended_flags);
                flags |= extended_flags;
                name = ondisk2->name;
        }
@@ -1844,13 +1845,13 @@ static void check_ce_order(struct index_state *istate)
                int name_compare = strcmp(ce->name, next_ce->name);
 
                if (0 < name_compare)
-                       die("unordered stage entries in index");
+                       die(_("unordered stage entries in index"));
                if (!name_compare) {
                        if (!ce_stage(ce))
-                               die("multiple stage entries for merged file '%s'",
+                               die(_("multiple stage entries for merged file '%s'"),
                                    ce->name);
                        if (ce_stage(ce) > ce_stage(next_ce))
-                               die("unordered stage entries for '%s'",
+                               die(_("unordered stage entries for '%s'"),
                                    ce->name);
                }
        }
@@ -2144,19 +2145,19 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
        if (fd < 0) {
                if (!must_exist && errno == ENOENT)
                        return 0;
-               die_errno("%s: index file open failed", path);
+               die_errno(_("%s: index file open failed"), path);
        }
 
        if (fstat(fd, &st))
-               die_errno("cannot stat the open index");
+               die_errno(_("%s: cannot stat the open index"), path);
 
        mmap_size = xsize_t(st.st_size);
        if (mmap_size < sizeof(struct cache_header) + the_hash_algo->rawsz)
-               die("index file smaller than expected");
+               die(_("%s: index file smaller than expected"), path);
 
        mmap = xmmap(NULL, mmap_size, PROT_READ, MAP_PRIVATE, fd, 0);
        if (mmap == MAP_FAILED)
-               die_errno("unable to map index file");
+               die_errno(_("%s: unable to map index file"), path);
        close(fd);
 
        hdr = (const struct cache_header *)mmap;
@@ -2235,7 +2236,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
 
 unmap:
        munmap((void *)mmap, mmap_size);
-       die("index file corrupt");
+       die(_("index file corrupt"));
 }
 
 /*
@@ -2247,7 +2248,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
 static void freshen_shared_index(const char *shared_index, int warn)
 {
        if (!check_and_freshen_file(shared_index, 1) && warn)
-               warning("could not freshen shared index '%s'", shared_index);
+               warning(_("could not freshen shared index '%s'"), shared_index);
 }
 
 int read_index_from(struct index_state *istate, const char *path,
@@ -2282,7 +2283,7 @@ int read_index_from(struct index_state *istate, const char *path,
        base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
        ret = do_read_index(split_index->base, base_path, 1);
        if (!oideq(&split_index->base_oid, &split_index->base->oid))
-               die("broken index, expect %s in %s, got %s",
+               die(_("broken index, expect %s in %s, got %s"),
                    base_oid_hex, base_path,
                    oid_to_hex(&split_index->base->oid));
 
@@ -2348,14 +2349,14 @@ void validate_cache_entries(const struct index_state *istate)
 
        for (i = 0; i < istate->cache_nr; i++) {
                if (!istate) {
-                       die("internal error: cache entry is not allocated from expected memory pool");
+                       BUG("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");
+                               BUG("cache entry is not allocated from expected memory pool");
                        }
                }
        }
@@ -3096,7 +3097,7 @@ static int write_shared_index(struct index_state *istate,
                return ret;
        ret = adjust_shared_perm(get_tempfile_path(*temp));
        if (ret) {
-               error("cannot fix permission bits on %s", get_tempfile_path(*temp));
+               error(_("cannot fix permission bits on '%s'"), get_tempfile_path(*temp));
                return ret;
        }
        ret = rename_tempfile(temp,
@@ -3146,7 +3147,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
        struct split_index *si = istate->split_index;
 
        if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
-               cache_tree_verify(istate);
+               cache_tree_verify(the_repository, istate);
 
        if ((flags & SKIP_IF_UNCHANGED) && !istate->cache_changed) {
                if (flags & COMMIT_LOCK)
@@ -3243,7 +3244,7 @@ int read_index_unmerged(struct index_state *istate)
                new_ce->ce_namelen = len;
                new_ce->ce_mode = ce->ce_mode;
                if (add_index_entry(istate, new_ce, ADD_CACHE_SKIP_DFCHECK))
-                       return error("%s: cannot drop to stage #0",
+                       return error(_("%s: cannot drop to stage #0"),
                                     new_ce->name);
        }
        return unmerged;
@@ -3494,71 +3495,71 @@ static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context,
 
 static struct index_entry_offset_table *read_ieot_extension(const char *mmap, size_t mmap_size, size_t offset)
 {
-       const char *index = NULL;
-       uint32_t extsize, ext_version;
-       struct index_entry_offset_table *ieot;
-       int i, nr;
-
-       /* find the IEOT extension */
-       if (!offset)
-              return NULL;
-       while (offset <= mmap_size - the_hash_algo->rawsz - 8) {
-              extsize = get_be32(mmap + offset + 4);
-              if (CACHE_EXT((mmap + offset)) == CACHE_EXT_INDEXENTRYOFFSETTABLE) {
-                      index = mmap + offset + 4 + 4;
-                      break;
-              }
-              offset += 8;
-              offset += extsize;
-       }
-       if (!index)
-              return NULL;
-
-       /* validate the version is IEOT_VERSION */
-       ext_version = get_be32(index);
-       if (ext_version != IEOT_VERSION) {
-              error("invalid IEOT version %d", ext_version);
-              return NULL;
-       }
-       index += sizeof(uint32_t);
-
-       /* extension size - version bytes / bytes per entry */
-       nr = (extsize - sizeof(uint32_t)) / (sizeof(uint32_t) + sizeof(uint32_t));
-       if (!nr) {
-              error("invalid number of IEOT entries %d", nr);
-              return NULL;
-       }
-       ieot = xmalloc(sizeof(struct index_entry_offset_table)
-              + (nr * sizeof(struct index_entry_offset)));
-       ieot->nr = nr;
-       for (i = 0; i < nr; i++) {
-              ieot->entries[i].offset = get_be32(index);
-              index += sizeof(uint32_t);
-              ieot->entries[i].nr = get_be32(index);
-              index += sizeof(uint32_t);
-       }
-
-       return ieot;
+       const char *index = NULL;
+       uint32_t extsize, ext_version;
+       struct index_entry_offset_table *ieot;
+       int i, nr;
+
+       /* find the IEOT extension */
+       if (!offset)
+               return NULL;
+       while (offset <= mmap_size - the_hash_algo->rawsz - 8) {
+               extsize = get_be32(mmap + offset + 4);
+               if (CACHE_EXT((mmap + offset)) == CACHE_EXT_INDEXENTRYOFFSETTABLE) {
+                       index = mmap + offset + 4 + 4;
+                       break;
+               }
+               offset += 8;
+               offset += extsize;
+       }
+       if (!index)
+               return NULL;
+
+       /* validate the version is IEOT_VERSION */
+       ext_version = get_be32(index);
+       if (ext_version != IEOT_VERSION) {
+               error("invalid IEOT version %d", ext_version);
+               return NULL;
+       }
+       index += sizeof(uint32_t);
+
+       /* extension size - version bytes / bytes per entry */
+       nr = (extsize - sizeof(uint32_t)) / (sizeof(uint32_t) + sizeof(uint32_t));
+       if (!nr) {
+               error("invalid number of IEOT entries %d", nr);
+               return NULL;
+       }
+       ieot = xmalloc(sizeof(struct index_entry_offset_table)
+                      + (nr * sizeof(struct index_entry_offset)));
+       ieot->nr = nr;
+       for (i = 0; i < nr; i++) {
+               ieot->entries[i].offset = get_be32(index);
+               index += sizeof(uint32_t);
+               ieot->entries[i].nr = get_be32(index);
+               index += sizeof(uint32_t);
+       }
+
+       return ieot;
 }
 
 static void write_ieot_extension(struct strbuf *sb, struct index_entry_offset_table *ieot)
 {
-       uint32_t buffer;
-       int i;
+       uint32_t buffer;
+       int i;
 
-       /* version */
-       put_be32(&buffer, IEOT_VERSION);
-       strbuf_add(sb, &buffer, sizeof(uint32_t));
+       /* version */
+       put_be32(&buffer, IEOT_VERSION);
+       strbuf_add(sb, &buffer, sizeof(uint32_t));
 
-       /* ieot */
-       for (i = 0; i < ieot->nr; i++) {
+       /* ieot */
+       for (i = 0; i < ieot->nr; i++) {
 
-              /* offset */
-              put_be32(&buffer, ieot->entries[i].offset);
-              strbuf_add(sb, &buffer, sizeof(uint32_t));
+               /* offset */
+               put_be32(&buffer, ieot->entries[i].offset);
+               strbuf_add(sb, &buffer, sizeof(uint32_t));
 
-              /* count */
-              put_be32(&buffer, ieot->entries[i].nr);
-              strbuf_add(sb, &buffer, sizeof(uint32_t));
-       }
+               /* count */
+               put_be32(&buffer, ieot->entries[i].nr);
+               strbuf_add(sb, &buffer, sizeof(uint32_t));
+       }
 }
index 78f3263fc153079938898989822b57e5888568d6..68aff1dac28878f2f9c010459bf5f4362322bd3f 100644 (file)
@@ -53,7 +53,7 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty,
        }
 }
 
-int edit_todo_list(unsigned flags)
+int edit_todo_list(struct repository *r, unsigned flags)
 {
        struct strbuf buf = STRBUF_INIT;
        const char *todo_file = rebase_path_todo();
@@ -69,7 +69,7 @@ int edit_todo_list(unsigned flags)
 
        strbuf_release(&buf);
 
-       transform_todos(flags | TODO_LIST_SHORTEN_IDS);
+       transform_todos(r, flags | TODO_LIST_SHORTEN_IDS);
 
        if (strbuf_read_file(&buf, todo_file, 0) < 0)
                return error_errno(_("could not read '%s'."), todo_file);
@@ -85,7 +85,7 @@ int edit_todo_list(unsigned flags)
        if (launch_sequence_editor(todo_file, NULL, NULL))
                return -1;
 
-       transform_todos(flags & ~(TODO_LIST_SHORTEN_IDS));
+       transform_todos(r, flags & ~(TODO_LIST_SHORTEN_IDS));
 
        return 0;
 }
index 971da037769476da196ae39eec89431be4923d54..17b6c9f6d05ea2372c58a50679cb0f8fb808aaef 100644 (file)
@@ -1,8 +1,11 @@
 #ifndef REBASE_INTERACTIVE_H
 #define REBASE_INTERACTIVE_H
 
+struct strbuf;
+struct repository;
+
 void append_todo_help(unsigned edit_todo, unsigned keep_empty,
                      struct strbuf *buf);
-int edit_todo_list(unsigned flags);
+int edit_todo_list(struct repository *r, unsigned flags);
 
 #endif
index 5de616befe46e64b014ebe7c3feb5913bc8af2df..61d75d5c86c644225a6a9549ca54d64a117d0c61 100644 (file)
@@ -1417,7 +1417,7 @@ char *get_head_description(void)
        struct strbuf desc = STRBUF_INIT;
        struct wt_status_state state;
        memset(&state, 0, sizeof(state));
-       wt_status_get_state(&state, 1);
+       wt_status_get_state(the_repository, &state, 1);
        if (state.rebase_in_progress ||
            state.rebase_interactive_in_progress) {
                if (state.branch)
@@ -2324,9 +2324,11 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
 
        if (rf->merge) {
                if (no_merged) {
-                       return opterror(opt, "is incompatible with --merged", 0);
+                       return error(_("option `%s' is incompatible with --merged"),
+                                    opt->long_name);
                } else {
-                       return opterror(opt, "is incompatible with --no-merged", 0);
+                       return error(_("option `%s' is incompatible with --no-merged"),
+                                    opt->long_name);
                }
        }
 
@@ -2340,7 +2342,7 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
        rf->merge_commit = lookup_commit_reference_gently(the_repository,
                                                          &oid, 0);
        if (!rf->merge_commit)
-               return opterror(opt, "must point to a commit", 0);
+               return error(_("option `%s' must point to a commit"), opt->long_name);
 
        return 0;
 }
index 1220dffcdc57a17476fb2021db5fb1605857ab80..90d565c8c5421eee7f929059e8e465ddfbe78dc2 100644 (file)
@@ -617,7 +617,8 @@ static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
        return err;
 }
 
-static curl_off_t xcurl_off_t(size_t len) {
+static curl_off_t xcurl_off_t(size_t len)
+{
        uintmax_t size = len;
        if (size > maximum_signed_value_of_type(curl_off_t))
                die("cannot handle pushes this big");
index b850f2feb34d41ca8c23d237f0acc52896530daa..670dd448130d20325f5f9f1de8afd0f011535db2 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -13,6 +13,7 @@
 #include "mergesort.h"
 #include "argv-array.h"
 #include "commit-reach.h"
+#include "advice.h"
 
 enum map_direction { FROM_SRC, FROM_DST };
 
@@ -359,7 +360,7 @@ static int handle_config(const char *key, const char *value, void *cb)
                return 0;
        /* Handle remote.<name>.* variables */
        if (*name == '/') {
-               warning("Config remote shorthand cannot begin with '/': %s",
+               warning(_("config remote shorthand cannot begin with '/': %s"),
                        name);
                return 0;
        }
@@ -406,7 +407,7 @@ static int handle_config(const char *key, const char *value, void *cb)
                if (!remote->receivepack)
                        remote->receivepack = v;
                else
-                       error("more than one receivepack given, using the first");
+                       error(_("more than one receivepack given, using the first"));
        } else if (!strcmp(subkey, "uploadpack")) {
                const char *v;
                if (git_config_string(&v, key, value))
@@ -414,7 +415,7 @@ static int handle_config(const char *key, const char *value, void *cb)
                if (!remote->uploadpack)
                        remote->uploadpack = v;
                else
-                       error("more than one uploadpack given, using the first");
+                       error(_("more than one uploadpack given, using the first"));
        } else if (!strcmp(subkey, "tagopt")) {
                if (!strcmp(value, "--no-tags"))
                        remote->fetch_tags = -1;
@@ -620,7 +621,7 @@ static void handle_duplicate(struct ref *ref1, struct ref *ref2)
                         * FETCH_HEAD_IGNORE entries always appear at
                         * the end of the list.
                         */
-                       die(_("Internal error"));
+                       BUG("Internal error");
                }
        }
        free(ref2->peer_ref);
@@ -680,7 +681,7 @@ static int match_name_with_pattern(const char *key, const char *name,
        size_t namelen;
        int ret;
        if (!kstar)
-               die("Key '%s' of pattern had no '*'", key);
+               die(_("key '%s' of pattern had no '*'"), key);
        klen = kstar - key;
        ksuffixlen = strlen(kstar + 1);
        namelen = strlen(name);
@@ -690,7 +691,7 @@ static int match_name_with_pattern(const char *key, const char *name,
                struct strbuf sb = STRBUF_INIT;
                const char *vstar = strchr(value, '*');
                if (!vstar)
-                       die("Value '%s' of pattern has no '*'", value);
+                       die(_("value '%s' of pattern has no '*'"), value);
                strbuf_add(&sb, value, vstar - value);
                strbuf_add(&sb, name + klen, namelen - klen - ksuffixlen);
                strbuf_addstr(&sb, vstar + 1);
@@ -707,7 +708,7 @@ static void query_refspecs_multiple(struct refspec *rs,
        int find_src = !query->src;
 
        if (find_src && !query->dst)
-               error("query_refspecs_multiple: need either src or dst");
+               BUG("query_refspecs_multiple: need either src or dst");
 
        for (i = 0; i < rs->nr; i++) {
                struct refspec_item *refspec = &rs->items[i];
@@ -735,7 +736,7 @@ int query_refspecs(struct refspec *rs, struct refspec_item *query)
        char **result = find_src ? &query->src : &query->dst;
 
        if (find_src && !query->dst)
-               return error("query_refspecs: need either src or dst");
+               BUG("query_refspecs: need either src or dst");
 
        for (i = 0; i < rs->nr; i++) {
                struct refspec_item *refspec = &rs->items[i];
@@ -968,12 +969,13 @@ static char *guess_ref(const char *name, struct ref *peer)
        if (!r)
                return NULL;
 
-       if (starts_with(r, "refs/heads/"))
+       if (starts_with(r, "refs/heads/")) {
                strbuf_addstr(&buf, "refs/heads/");
-       else if (starts_with(r, "refs/tags/"))
+       } else if (starts_with(r, "refs/tags/")) {
                strbuf_addstr(&buf, "refs/tags/");
-       else
+       } else {
                return NULL;
+       }
 
        strbuf_addstr(&buf, name);
        return strbuf_detach(&buf, NULL);
@@ -995,12 +997,68 @@ static int match_explicit_lhs(struct ref *src,
                 * way to delete 'other' ref at the remote end.
                 */
                if (try_explicit_object_name(rs->src, match) < 0)
-                       return error("src refspec %s does not match any.", rs->src);
+                       return error(_("src refspec %s does not match any"), rs->src);
                if (allocated_match)
                        *allocated_match = 1;
                return 0;
        default:
-               return error("src refspec %s matches more than one.", rs->src);
+               return error(_("src refspec %s matches more than one"), rs->src);
+       }
+}
+
+static void show_push_unqualified_ref_name_error(const char *dst_value,
+                                                const char *matched_src_name)
+{
+       struct object_id oid;
+       enum object_type type;
+
+       /*
+        * TRANSLATORS: "matches '%s'%" is the <dst> part of "git push
+        * <remote> <src>:<dst>" push, and "being pushed ('%s')" is
+        * the <src>.
+        */
+       error(_("The destination you provided is not a full refname (i.e.,\n"
+               "starting with \"refs/\"). We tried to guess what you meant by:\n"
+               "\n"
+               "- Looking for a ref that matches '%s' on the remote side.\n"
+               "- Checking if the <src> being pushed ('%s')\n"
+               "  is a ref in \"refs/{heads,tags}/\". If so we add a corresponding\n"
+               "  refs/{heads,tags}/ prefix on the remote side.\n"
+               "\n"
+               "Neither worked, so we gave up. You must fully qualify the ref."),
+             dst_value, matched_src_name);
+
+       if (!advice_push_unqualified_ref_name)
+               return;
+
+       if (get_oid(matched_src_name, &oid))
+               BUG("'%s' is not a valid object, "
+                   "match_explicit_lhs() should catch this!",
+                   matched_src_name);
+       type = oid_object_info(the_repository, &oid, NULL);
+       if (type == OBJ_COMMIT) {
+               advise(_("The <src> part of the refspec is a commit object.\n"
+                        "Did you mean to create a new branch by pushing to\n"
+                        "'%s:refs/heads/%s'?"),
+                      matched_src_name, dst_value);
+       } else if (type == OBJ_TAG) {
+               advise(_("The <src> part of the refspec is a tag object.\n"
+                        "Did you mean to create a new tag by pushing to\n"
+                        "'%s:refs/tags/%s'?"),
+                      matched_src_name, dst_value);
+       } else if (type == OBJ_TREE) {
+               advise(_("The <src> part of the refspec is a tree object.\n"
+                        "Did you mean to tag a new tree by pushing to\n"
+                        "'%s:refs/tags/%s'?"),
+                      matched_src_name, dst_value);
+       } else if (type == OBJ_BLOB) {
+               advise(_("The <src> part of the refspec is a blob object.\n"
+                        "Did you mean to tag a new blob by pushing to\n"
+                        "'%s:refs/tags/%s'?"),
+                      matched_src_name, dst_value);
+       } else {
+               BUG("'%s' should be commit/tag/tree/blob, is '%d'",
+                   matched_src_name, type);
        }
 }
 
@@ -1030,7 +1088,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
                if (!dst_value ||
                    ((flag & REF_ISSYMREF) &&
                     !starts_with(dst_value, "refs/heads/")))
-                       die("%s cannot be resolved to branch.",
+                       die(_("%s cannot be resolved to branch"),
                            matched_src->name);
        }
 
@@ -1038,33 +1096,30 @@ static int match_explicit(struct ref *src, struct ref *dst,
        case 1:
                break;
        case 0:
-               if (starts_with(dst_value, "refs/"))
+               if (starts_with(dst_value, "refs/")) {
                        matched_dst = make_linked_ref(dst_value, dst_tail);
-               else if (is_null_oid(&matched_src->new_oid))
-                       error("unable to delete '%s': remote ref does not exist",
+               } else if (is_null_oid(&matched_src->new_oid)) {
+                       error(_("unable to delete '%s': remote ref does not exist"),
                              dst_value);
-               else if ((dst_guess = guess_ref(dst_value, matched_src))) {
+               else if ((dst_guess = guess_ref(dst_value, matched_src))) {
                        matched_dst = make_linked_ref(dst_guess, dst_tail);
                        free(dst_guess);
-               } else
-                       error("unable to push to unqualified destination: %s\n"
-                             "The destination refspec neither matches an "
-                             "existing ref on the remote nor\n"
-                             "begins with refs/, and we are unable to "
-                             "guess a prefix based on the source ref.",
-                             dst_value);
+               } else {
+                       show_push_unqualified_ref_name_error(dst_value,
+                                                            matched_src->name);
+               }
                break;
        default:
                matched_dst = NULL;
-               error("dst refspec %s matches more than one.",
+               error(_("dst refspec %s matches more than one"),
                      dst_value);
                break;
        }
        if (!matched_dst)
                return -1;
        if (matched_dst->peer_ref)
-               return error("dst ref %s receives from more than one src.",
-                     matched_dst->name);
+               return error(_("dst ref %s receives from more than one src"),
+                            matched_dst->name);
        else {
                matched_dst->peer_ref = allocated_src ?
                                        matched_src :
@@ -1782,7 +1837,7 @@ int get_fetch_map(const struct ref *remote_refs,
                        ref_map = get_remote_ref(remote_refs, name);
                }
                if (!missing_ok && !ref_map)
-                       die("Couldn't find remote ref %s", name);
+                       die(_("couldn't find remote ref %s"), name);
                if (ref_map) {
                        ref_map->peer_ref = get_local_ref(refspec->dst);
                        if (ref_map->peer_ref && refspec->force)
@@ -1795,7 +1850,7 @@ int get_fetch_map(const struct ref *remote_refs,
                        if (!starts_with((*rmp)->peer_ref->name, "refs/") ||
                            check_refname_format((*rmp)->peer_ref->name, 0)) {
                                struct ref *ignore = *rmp;
-                               error("* Ignoring funny ref '%s' locally",
+                               error(_("* Ignoring funny ref '%s' locally"),
                                      (*rmp)->peer_ref->name);
                                *rmp = (*rmp)->next;
                                free(ignore->peer_ref);
@@ -1890,7 +1945,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
        repo_init_revisions(the_repository, &revs, NULL);
        setup_revisions(argv.argc, argv.argv, &revs, NULL);
        if (prepare_revision_walk(&revs))
-               die("revision walk setup failed");
+               die(_("revision walk setup failed"));
 
        /* ... and count the commits on each side. */
        while (1) {
@@ -2163,7 +2218,8 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i
        else if (!colon[1])
                oidclr(&entry->expect);
        else if (get_oid(colon + 1, &entry->expect))
-               return error("cannot parse expected object name '%s'", colon + 1);
+               return error(_("cannot parse expected object name '%s'"),
+                            colon + 1);
        return 0;
 }
 
index 5dd148671811b383a64b8f3adab87804cea9db08..7b02e1dffac077d0c21ecaef915f4ea33abc57bc 100644 (file)
@@ -63,8 +63,14 @@ void repo_set_gitdir(struct repository *repo,
        free(old_gitdir);
 
        repo_set_commondir(repo, o->commondir);
-       expand_base_dir(&repo->objects->objectdir, o->object_dir,
+
+       if (!repo->objects->odb) {
+               repo->objects->odb = xcalloc(1, sizeof(*repo->objects->odb));
+               repo->objects->odb_tail = &repo->objects->odb->next;
+       }
+       expand_base_dir(&repo->objects->odb->path, o->object_dir,
                        repo->commondir, "objects");
+
        free(repo->objects->alternate_db);
        repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
        expand_base_dir(&repo->graft_file, o->graft_file,
index b5b2357411f145867eb1918cbc79f77c6192db1a..13624038e66c2084c478711599ed9f005cf2e53d 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -198,10 +198,10 @@ static struct rerere_id *new_rerere_id(unsigned char *sha1)
  * work on (i.e. what is left by the previous invocation of "git
  * rerere" during the current conflict resolution session).
  */
-static void read_rr(struct string_list *rr)
+static void read_rr(struct repository *r, struct string_list *rr)
 {
        struct strbuf buf = STRBUF_INIT;
-       FILE *in = fopen_or_warn(git_path_merge_rr(the_repository), "r");
+       FILE *in = fopen_or_warn(git_path_merge_rr(r), "r");
 
        if (!in)
                return;
@@ -593,7 +593,7 @@ int rerere_remaining(struct repository *r, struct string_list *merge_rr)
 {
        int i;
 
-       if (setup_rerere(merge_rr, RERERE_READONLY))
+       if (setup_rerere(r, merge_rr, RERERE_READONLY))
                return 0;
        if (read_index(r->index) < 0)
                return error(_("index file corrupt"));
@@ -882,7 +882,7 @@ static int is_rerere_enabled(void)
        return 1;
 }
 
-int setup_rerere(struct string_list *merge_rr, int flags)
+int setup_rerere(struct repository *r, struct string_list *merge_rr, int flags)
 {
        int fd;
 
@@ -896,9 +896,9 @@ int setup_rerere(struct string_list *merge_rr, int flags)
                fd = 0;
        else
                fd = hold_lock_file_for_update(&write_lock,
-                                              git_path_merge_rr(the_repository),
+                                              git_path_merge_rr(r),
                                               LOCK_DIE_ON_ERROR);
-       read_rr(merge_rr);
+       read_rr(r, merge_rr);
        return fd;
 }
 
@@ -912,7 +912,7 @@ int repo_rerere(struct repository *r, int flags)
        struct string_list merge_rr = STRING_LIST_INIT_DUP;
        int fd, status;
 
-       fd = setup_rerere(&merge_rr, flags);
+       fd = setup_rerere(r, &merge_rr, flags);
        if (fd < 0)
                return 0;
        status = do_plain_rerere(r, &merge_rr, fd);
@@ -1110,7 +1110,7 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec)
        if (read_index(r->index) < 0)
                return error(_("index file corrupt"));
 
-       fd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE);
+       fd = setup_rerere(r, &merge_rr, RERERE_NOAUTOUPDATE);
        if (fd < 0)
                return 0;
 
@@ -1178,7 +1178,7 @@ static void prune_one(struct rerere_id *id,
                unlink_rr_item(id);
 }
 
-void rerere_gc(struct string_list *rr)
+void rerere_gc(struct repository *r, struct string_list *rr)
 {
        struct string_list to_remove = STRING_LIST_INIT_DUP;
        DIR *dir;
@@ -1188,7 +1188,7 @@ void rerere_gc(struct string_list *rr)
        timestamp_t cutoff_noresolve = now - 15 * 86400;
        timestamp_t cutoff_resolve = now - 60 * 86400;
 
-       if (setup_rerere(rr, 0) < 0)
+       if (setup_rerere(r, rr, 0) < 0)
                return;
 
        git_config_get_expiry_in_days("gc.rerereresolved", &cutoff_resolve, now);
@@ -1236,11 +1236,11 @@ void rerere_gc(struct string_list *rr)
  *
  * NEEDSWORK: shouldn't we be calling this from "reset --hard"?
  */
-void rerere_clear(struct string_list *merge_rr)
+void rerere_clear(struct repository *r, struct string_list *merge_rr)
 {
        int i;
 
-       if (setup_rerere(merge_rr, 0) < 0)
+       if (setup_rerere(r, merge_rr, 0) < 0)
                return;
 
        for (i = 0; i < merge_rr->nr; i++) {
@@ -1250,6 +1250,6 @@ void rerere_clear(struct string_list *merge_rr)
                        rmdir(rerere_path(id, NULL));
                }
        }
-       unlink_or_warn(git_path_merge_rr(the_repository));
+       unlink_or_warn(git_path_merge_rr(r));
        rollback_lock_file(&write_lock);
 }
index 5ad8864b3c71625a7fae5f67e625793d73e40fe4..c32d79c3bd81f1ff6e9247b77a050784b917ecfd 100644 (file)
--- a/rerere.h
+++ b/rerere.h
@@ -23,7 +23,7 @@ struct rerere_id {
        int variant;
 };
 
-int setup_rerere(struct string_list *, int);
+int setup_rerere(struct repository *,struct string_list *, int);
 #ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
 #define rerere(flags) repo_rerere(the_repository, flags)
 #endif
@@ -37,8 +37,8 @@ int repo_rerere(struct repository *, int);
 const char *rerere_path(const struct rerere_id *, const char *file);
 int rerere_forget(struct repository *, struct pathspec *);
 int rerere_remaining(struct repository *, struct string_list *);
-void rerere_clear(struct string_list *);
-void rerere_gc(struct string_list *);
+void rerere_clear(struct repository *, struct string_list *);
+void rerere_gc(struct repository *, 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 13e0519c0241635c0c1fd14a7ff12e9478c70bd4..13cfb59b388d1503adbaef424ea1dcecc410b673 100644 (file)
@@ -1463,6 +1463,7 @@ void repo_init_revisions(struct repository *r,
        revs->abbrev = DEFAULT_ABBREV;
        revs->ignore_merges = 1;
        revs->simplify_history = 1;
+       revs->pruning.repo = r;
        revs->pruning.flags.recursive = 1;
        revs->pruning.flags.quick = 1;
        revs->pruning.add_remove = file_add_remove;
@@ -1495,8 +1496,8 @@ void repo_init_revisions(struct repository *r,
 }
 
 static void add_pending_commit_list(struct rev_info *revs,
-                                    struct commit_list *commit_list,
-                                    unsigned int flags)
+                                   struct commit_list *commit_list,
+                                   unsigned int flags)
 {
        while (commit_list) {
                struct object *object = &commit_list->item->object;
@@ -1729,6 +1730,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
        if (!cant_be_filename)
                verify_non_filename(revs->prefix, arg);
        object = get_reference(revs, arg, &oid, flags ^ local_flags);
+       if (!object)
+               return revs->ignore_missing ? 0 : -1;
        add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags);
        add_pending_object_with_path(revs, object, arg, oc.mode, oc.path);
        free(oc.path);
@@ -1791,7 +1794,8 @@ static void add_message_grep(struct rev_info *revs, const char *pattern)
 }
 
 static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
-                              int *unkc, const char **unkv)
+                              int *unkc, const char **unkv,
+                              const struct setup_revision_opt* opt)
 {
        const char *arg = argv[0];
        const char *optarg;
@@ -2151,7 +2155,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->limited = 1;
        } else if (!strcmp(arg, "--ignore-missing")) {
                revs->ignore_missing = 1;
-       } else if (revs->allow_exclude_promisor_objects_opt &&
+       } else if (opt && opt->allow_exclude_promisor_objects &&
                   !strcmp(arg, "--exclude-promisor-objects")) {
                if (fetch_if_missing)
                        BUG("exclude_promisor_objects can only be used when fetch_if_missing is 0");
@@ -2173,7 +2177,7 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
                        const char * const usagestr[])
 {
        int n = handle_revision_opt(revs, ctx->argc, ctx->argv,
-                                   &ctx->cpidx, ctx->out);
+                                   &ctx->cpidx, ctx->out, NULL);
        if (n <= 0) {
                error("unknown option `%s'", ctx->argv[0]);
                usage_with_options(usagestr, options);
@@ -2391,7 +2395,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
                                continue;
                        }
 
-                       opts = handle_revision_opt(revs, argc - i, argv + i, &left, argv);
+                       opts = handle_revision_opt(revs, argc - i, argv + i,
+                                                  &left, argv, opt);
                        if (opts > 0) {
                                i += opts - 1;
                                continue;
index 7987bfcd2e9bd6ee7bac4f1cbeb10af17ab40b50..52e5a88ff5725862dced5c72fbc2aa6435b94e3b 100644 (file)
@@ -161,7 +161,6 @@ struct rev_info {
                        do_not_die_on_missing_tree:1,
 
                        /* for internal use only */
-                       allow_exclude_promisor_objects_opt:1,
                        exclude_promisor_objects:1;
 
        /* Diff flags */
@@ -297,7 +296,8 @@ struct setup_revision_opt {
        const char *def;
        void (*tweak)(struct rev_info *, struct setup_revision_opt *);
        const char *submodule;  /* TODO: drop this and use rev_info->repo */
-       int assume_dashdash;
+       unsigned int    assume_dashdash:1,
+                       allow_exclude_promisor_objects:1;
        unsigned revarg_opt;
 };
 
index c11ff8067481f70c444198bcc7477ef744d99fd3..3db26b7b0e2ab9b6b615387b36a2cd6b64800e9e 100644 (file)
@@ -728,6 +728,8 @@ int start_command(struct child_process *cmd)
        if (prepare_cmd(&argv, cmd) < 0) {
                failed_errno = errno;
                cmd->pid = -1;
+               if (!cmd->silent_exec_failure)
+                       error_errno("cannot run %s", cmd->argv[0]);
                goto end_of_spawn;
        }
 
index e1a4dd15f1a826c7bd1bf4780c8f85c21117c43b..f5370f49659a3da10c8092c0b1682da08a1fab07 100644 (file)
@@ -356,7 +356,8 @@ static void free_message(struct commit *commit, struct commit_message *msg)
        unuse_commit_buffer(commit, msg->message);
 }
 
-static void print_advice(int show_hint, struct replay_opts *opts)
+static void print_advice(struct repository *r, int show_hint,
+                        struct replay_opts *opts)
 {
        char *msg = getenv("GIT_CHERRY_PICK_HELP");
 
@@ -367,7 +368,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(the_repository));
+               unlink(git_path_cherry_pick_head(r));
                return;
        }
 
@@ -440,14 +441,14 @@ static int read_oneliner(struct strbuf *buf,
        return 1;
 }
 
-static struct tree *empty_tree(void)
+static struct tree *empty_tree(struct repository *r)
 {
-       return lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
+       return lookup_tree(r, the_hash_algo->empty_tree);
 }
 
-static int error_dirty_index(struct replay_opts *opts)
+static int error_dirty_index(struct index_state *istate, struct replay_opts *opts)
 {
-       if (read_cache_unmerged())
+       if (read_index_unmerged(istate))
                return error_resolve_conflict(_(action_name(opts)));
 
        error(_("your local changes would be overwritten by %s."),
@@ -472,15 +473,18 @@ static void update_abort_safety_file(void)
                write_file(git_path_abort_safety_file(), "%s", "");
 }
 
-static int fast_forward_to(const struct object_id *to, const struct object_id *from,
-                       int unborn, struct replay_opts *opts)
+static int fast_forward_to(struct repository *r,
+                          const struct object_id *to,
+                          const struct object_id *from,
+                          int unborn,
+                          struct replay_opts *opts)
 {
        struct ref_transaction *transaction;
        struct strbuf sb = STRBUF_INIT;
        struct strbuf err = STRBUF_INIT;
 
-       read_index(&the_index);
-       if (checkout_fast_forward(the_repository, from, to, 1))
+       read_index(r->index);
+       if (checkout_fast_forward(r, from, to, 1))
                return -1; /* the callee should have complained already */
 
        strbuf_addf(&sb, _("%s: fast-forward"), _(action_name(opts)));
@@ -506,24 +510,26 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *f
        return 0;
 }
 
-void append_conflicts_hint(struct strbuf *msgbuf)
+void append_conflicts_hint(struct index_state *istate,
+                          struct strbuf *msgbuf)
 {
        int i;
 
        strbuf_addch(msgbuf, '\n');
        strbuf_commented_addf(msgbuf, "Conflicts:\n");
-       for (i = 0; i < active_nr;) {
-               const struct cache_entry *ce = active_cache[i++];
+       for (i = 0; i < istate->cache_nr;) {
+               const struct cache_entry *ce = istate->cache[i++];
                if (ce_stage(ce)) {
                        strbuf_commented_addf(msgbuf, "\t%s\n", ce->name);
-                       while (i < active_nr && !strcmp(ce->name,
-                                                       active_cache[i]->name))
+                       while (i < istate->cache_nr &&
+                              !strcmp(ce->name, istate->cache[i]->name))
                                i++;
                }
        }
 }
 
-static int do_recursive_merge(struct commit *base, struct commit *next,
+static int do_recursive_merge(struct repository *r,
+                             struct commit *base, struct commit *next,
                              const char *base_label, const char *next_label,
                              struct object_id *head, struct strbuf *msgbuf,
                              struct replay_opts *opts)
@@ -537,7 +543,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
        if (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0)
                return -1;
 
-       read_cache();
+       read_index(r->index);
 
        init_merge_options(&o);
        o.ancestor = base ? base_label : "(empty tree)";
@@ -548,8 +554,8 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
        o.show_rename_progress = 1;
 
        head_tree = parse_tree_indirect(head);
-       next_tree = next ? get_commit_tree(next) : empty_tree();
-       base_tree = base ? get_commit_tree(base) : empty_tree();
+       next_tree = next ? get_commit_tree(next) : empty_tree(r);
+       base_tree = base ? get_commit_tree(base) : empty_tree(r);
 
        for (xopt = opts->xopts; xopt != opts->xopts + opts->xopts_nr; xopt++)
                parse_merge_opt(&o, *xopt);
@@ -566,7 +572,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
                return clean;
        }
 
-       if (write_locked_index(&the_index, &index_lock,
+       if (write_locked_index(r->index, &index_lock,
                               COMMIT_LOCK | SKIP_IF_UNCHANGED))
                /*
                 * TRANSLATORS: %s will be "revert", "cherry-pick" or
@@ -576,34 +582,35 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
                        _(action_name(opts)));
 
        if (!clean)
-               append_conflicts_hint(msgbuf);
+               append_conflicts_hint(r->index, msgbuf);
 
        return !clean;
 }
 
-static struct object_id *get_cache_tree_oid(void)
+static struct object_id *get_cache_tree_oid(struct index_state *istate)
 {
-       if (!active_cache_tree)
-               active_cache_tree = cache_tree();
+       if (!istate->cache_tree)
+               istate->cache_tree = cache_tree();
 
-       if (!cache_tree_fully_valid(active_cache_tree))
-               if (cache_tree_update(&the_index, 0)) {
+       if (!cache_tree_fully_valid(istate->cache_tree))
+               if (cache_tree_update(istate, 0)) {
                        error(_("unable to update cache tree"));
                        return NULL;
                }
 
-       return &active_cache_tree->oid;
+       return &istate->cache_tree->oid;
 }
 
-static int is_index_unchanged(void)
+static int is_index_unchanged(struct repository *r)
 {
        struct object_id head_oid, *cache_tree_oid;
        struct commit *head_commit;
+       struct index_state *istate = r->index;
 
        if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
                return error(_("could not resolve HEAD commit"));
 
-       head_commit = lookup_commit(the_repository, &head_oid);
+       head_commit = lookup_commit(r, &head_oid);
 
        /*
         * If head_commit is NULL, check_commit, called from
@@ -616,7 +623,7 @@ static int is_index_unchanged(void)
        if (parse_commit(head_commit))
                return -1;
 
-       if (!(cache_tree_oid = get_cache_tree_oid()))
+       if (!(cache_tree_oid = get_cache_tree_oid(istate)))
                return -1;
 
        return oideq(cache_tree_oid, get_commit_tree_oid(head_commit));
@@ -888,7 +895,9 @@ static int run_command_silent_on_success(struct child_process *cmd)
  * interactive rebase: in that case, we will want to retain the
  * author metadata.
  */
-static int run_git_commit(const char *defmsg, struct replay_opts *opts,
+static int run_git_commit(struct repository *r,
+                         const char *defmsg,
+                         struct replay_opts *opts,
                          unsigned int flags)
 {
        struct child_process cmd = CHILD_PROCESS_INIT;
@@ -911,7 +920,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
                if (!defmsg)
                        BUG("root commit without message");
 
-               if (!(cache_tree_oid = get_cache_tree_oid()))
+               if (!(cache_tree_oid = get_cache_tree_oid(r->index)))
                        res = -1;
 
                if (!res)
@@ -1120,7 +1129,9 @@ void commit_post_rewrite(const struct commit *old_head,
        run_rewrite_hook(&old_head->object.oid, new_head);
 }
 
-static int run_prepare_commit_msg_hook(struct strbuf *msg, const char *commit)
+static int run_prepare_commit_msg_hook(struct repository *r,
+                                      struct strbuf *msg,
+                                      const char *commit)
 {
        struct argv_array hook_env = ARGV_ARRAY_INIT;
        int ret;
@@ -1130,7 +1141,7 @@ static int run_prepare_commit_msg_hook(struct strbuf *msg, const char *commit)
        if (write_message(msg->buf, msg->len, name, 0))
                return -1;
 
-       argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", get_index_file());
+       argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", r->index_file);
        argv_array_push(&hook_env, "GIT_EDITOR=:");
        if (commit)
                ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name,
@@ -1186,7 +1197,9 @@ static const char *implicit_ident_advice(void)
 
 }
 
-void print_commit_summary(const char *prefix, const struct object_id *oid,
+void print_commit_summary(struct repository *r,
+                         const char *prefix,
+                         const struct object_id *oid,
                          unsigned int flags)
 {
        struct rev_info rev;
@@ -1197,7 +1210,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(the_repository, oid);
+       commit = lookup_commit(r, oid);
        if (!commit)
                die(_("couldn't look up newly created commit"));
        if (parse_commit(commit))
@@ -1230,7 +1243,7 @@ void print_commit_summary(const char *prefix, const struct object_id *oid,
        strbuf_release(&author_ident);
        strbuf_release(&committer_ident);
 
-       repo_init_revisions(the_repository, &rev, prefix);
+       repo_init_revisions(r, &rev, prefix);
        setup_revisions(0, NULL, &rev, NULL);
 
        rev.diff = 1;
@@ -1264,7 +1277,7 @@ void print_commit_summary(const char *prefix, const struct object_id *oid,
        strbuf_release(&format);
 }
 
-static int parse_head(struct commit **head)
+static int parse_head(struct repository *r, struct commit **head)
 {
        struct commit *current_head;
        struct object_id oid;
@@ -1272,7 +1285,7 @@ static int parse_head(struct commit **head)
        if (get_oid("HEAD", &oid)) {
                current_head = NULL;
        } else {
-               current_head = lookup_commit_reference(the_repository, &oid);
+               current_head = lookup_commit_reference(r, &oid);
                if (!current_head)
                        return error(_("could not parse HEAD"));
                if (!oideq(&oid, &current_head->object.oid)) {
@@ -1296,7 +1309,8 @@ static int parse_head(struct commit **head)
  *   0 - success
  *   1 - run 'git commit'
  */
-static int try_to_commit(struct strbuf *msg, const char *author,
+static int try_to_commit(struct repository *r,
+                        struct strbuf *msg, const char *author,
                         struct replay_opts *opts, unsigned int flags,
                         struct object_id *oid)
 {
@@ -1311,7 +1325,7 @@ static int try_to_commit(struct strbuf *msg, const char *author,
        enum commit_msg_cleanup_mode cleanup;
        int res = 0;
 
-       if (parse_head(&current_head))
+       if (parse_head(r, &current_head))
                return -1;
 
        if (flags & AMEND_MSG) {
@@ -1340,7 +1354,7 @@ static int try_to_commit(struct strbuf *msg, const char *author,
                commit_list_insert(current_head, &parents);
        }
 
-       if (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL)) {
+       if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) {
                res = error(_("git write-tree failed to write a tree"));
                goto out;
        }
@@ -1353,7 +1367,7 @@ static int try_to_commit(struct strbuf *msg, const char *author,
        }
 
        if (find_hook("prepare-commit-msg")) {
-               res = run_prepare_commit_msg_hook(msg, hook_commit);
+               res = run_prepare_commit_msg_hook(r, msg, hook_commit);
                if (res)
                        goto out;
                if (strbuf_read_file(&commit_msg, git_path_commit_editmsg(),
@@ -1402,7 +1416,8 @@ static int try_to_commit(struct strbuf *msg, const char *author,
        return res;
 }
 
-static int do_commit(const char *msg_file, const char *author,
+static int do_commit(struct repository *r,
+                    const char *msg_file, const char *author,
                     struct replay_opts *opts, unsigned int flags)
 {
        int res = 1;
@@ -1417,20 +1432,20 @@ static int do_commit(const char *msg_file, const char *author,
                                             "from '%s'"),
                                           msg_file);
 
-               res = try_to_commit(msg_file ? &sb : NULL, author, opts, flags,
-                                   &oid);
+               res = try_to_commit(r, msg_file ? &sb : NULL,
+                                   author, opts, flags, &oid);
                strbuf_release(&sb);
                if (!res) {
-                       unlink(git_path_cherry_pick_head(the_repository));
-                       unlink(git_path_merge_msg(the_repository));
+                       unlink(git_path_cherry_pick_head(r));
+                       unlink(git_path_merge_msg(r));
                        if (!is_rebase_i(opts))
-                               print_commit_summary(NULL, &oid,
+                               print_commit_summary(r, NULL, &oid,
                                                SUMMARY_SHOW_AUTHOR_DATE);
                        return res;
                }
        }
        if (res == 1)
-               return run_git_commit(msg_file, opts, flags);
+               return run_git_commit(r, msg_file, opts, flags);
 
        return res;
 }
@@ -1458,7 +1473,9 @@ static int is_original_commit_empty(struct commit *commit)
 /*
  * Do we run "git commit" with "--allow-empty"?
  */
-static int allow_empty(struct replay_opts *opts, struct commit *commit)
+static int allow_empty(struct repository *r,
+                      struct replay_opts *opts,
+                      struct commit *commit)
 {
        int index_unchanged, empty_commit;
 
@@ -1475,7 +1492,7 @@ static int allow_empty(struct replay_opts *opts, struct commit *commit)
        if (!opts->allow_empty)
                return 0; /* let "git commit" barf as necessary */
 
-       index_unchanged = is_index_unchanged();
+       index_unchanged = is_index_unchanged(r);
        if (index_unchanged < 0)
                return index_unchanged;
        if (!index_unchanged)
@@ -1579,8 +1596,10 @@ static int is_pick_or_similar(enum todo_command command)
        }
 }
 
-static int update_squash_messages(enum todo_command command,
-               struct commit *commit, struct replay_opts *opts)
+static int update_squash_messages(struct repository *r,
+                                 enum todo_command command,
+                                 struct commit *commit,
+                                 struct replay_opts *opts)
 {
        struct strbuf buf = STRBUF_INIT;
        int res;
@@ -1609,7 +1628,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(the_repository, &head)))
+               if (!(head_commit = lookup_commit_reference(r, &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"));
@@ -1670,7 +1689,8 @@ static int update_squash_messages(enum todo_command command,
        return res;
 }
 
-static void flush_rewritten_pending(void) {
+static void flush_rewritten_pending(void)
+{
        struct strbuf buf = STRBUF_INIT;
        struct object_id newoid;
        FILE *out;
@@ -1695,7 +1715,8 @@ static void flush_rewritten_pending(void) {
 }
 
 static void record_in_rewritten(struct object_id *oid,
-               enum todo_command next_command) {
+               enum todo_command next_command)
+{
        FILE *out = fopen_or_warn(rebase_path_rewritten_pending(), "a");
 
        if (!out)
@@ -1708,11 +1729,14 @@ static void record_in_rewritten(struct object_id *oid,
                flush_rewritten_pending();
 }
 
-static int do_pick_commit(enum todo_command command, struct commit *commit,
-               struct replay_opts *opts, int final_fixup)
+static int do_pick_commit(struct repository *r,
+                         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(the_repository);
+       const char *msg_file = opts->edit ? NULL : git_path_merge_msg(r);
        struct object_id head;
        struct commit *base, *next, *parent;
        const char *base_label, *next_label;
@@ -1728,7 +1752,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_index_as_tree(&head, &the_index, get_index_file(), 0, NULL))
+               if (write_index_as_tree(&head, r->index, r->index_file, 0, NULL))
                        return error(_("your index file is unmerged."));
        } else {
                unborn = get_oid("HEAD", &head);
@@ -1741,11 +1765,11 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                        unborn = 1;
                } else if (unborn)
                        oidcpy(&head, the_hash_algo->empty_tree);
-               if (index_differs_from(unborn ? empty_tree_oid_hex() : "HEAD",
+               if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
                                       NULL, 0))
-                       return error_dirty_index(opts);
+                       return error_dirty_index(r->index, opts);
        }
-       discard_cache();
+       discard_index(r->index);
 
        if (!commit->parents)
                parent = NULL;
@@ -1766,9 +1790,13 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                        return error(_("commit %s does not have parent %d"),
                                oid_to_hex(&commit->object.oid), opts->mainline);
                parent = p->item;
-       } else if (0 < opts->mainline)
-               return error(_("mainline was specified but commit %s is not a merge."),
-                       oid_to_hex(&commit->object.oid));
+       } else if (1 < opts->mainline)
+               /*
+                *  Non-first parent explicitly specified as mainline for
+                *  non-merge commit
+                */
+               return error(_("commit %s does not have parent %d"),
+                            oid_to_hex(&commit->object.oid), opts->mainline);
        else
                parent = commit->parents->item;
 
@@ -1781,7 +1809,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
             (!parent && unborn))) {
                if (is_rebase_i(opts))
                        write_author_script(msg.message);
-               res = fast_forward_to(&commit->object.oid, &head, unborn,
+               res = fast_forward_to(r, &commit->object.oid, &head, unborn,
                        opts);
                if (res || command != TODO_REWORD)
                        goto leave;
@@ -1845,7 +1873,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
        if (command == TODO_REWORD)
                flags |= EDIT_MSG | VERIFY_MSG;
        else if (is_fixup(command)) {
-               if (update_squash_messages(command, commit, opts))
+               if (update_squash_messages(r, command, commit, opts))
                        return -1;
                flags |= AMEND_MSG;
                if (!final_fixup)
@@ -1854,12 +1882,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(the_repository);
+                       const char *dest = git_path_squash_msg(r);
                        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(the_repository));
+                       unlink(git_path_merge_msg(r));
                        msg_file = dest;
                        flags |= EDIT_MSG;
                }
@@ -1871,23 +1899,23 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
        if (is_rebase_i(opts) && write_author_script(msg.message) < 0)
                res = -1;
        else if (!opts->strategy || !strcmp(opts->strategy, "recursive") || command == TODO_REVERT) {
-               res = do_recursive_merge(base, next, base_label, next_label,
+               res = do_recursive_merge(r, base, next, base_label, next_label,
                                         &head, &msgbuf, opts);
                if (res < 0)
                        goto leave;
 
                res |= write_message(msgbuf.buf, msgbuf.len,
-                                    git_path_merge_msg(the_repository), 0);
+                                    git_path_merge_msg(r), 0);
        } else {
                struct commit_list *common = NULL;
                struct commit_list *remotes = NULL;
 
                res = write_message(msgbuf.buf, msgbuf.len,
-                                   git_path_merge_msg(the_repository), 0);
+                                   git_path_merge_msg(r), 0);
 
                commit_list_insert(base, &common);
                commit_list_insert(next, &remotes);
-               res |= try_merge_command(the_repository, opts->strategy,
+               res |= try_merge_command(r, opts->strategy,
                                         opts->xopts_nr, (const char **)opts->xopts,
                                        common, oid_to_hex(&head), remotes);
                free_commit_list(common);
@@ -1915,12 +1943,12 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                      ? _("could not revert %s... %s")
                      : _("could not apply %s... %s"),
                      short_commit_name(commit), msg.subject);
-               print_advice(res == 1, opts);
-               repo_rerere(the_repository, opts->allow_rerere_auto);
+               print_advice(r, res == 1, opts);
+               repo_rerere(r, opts->allow_rerere_auto);
                goto leave;
        }
 
-       allow = allow_empty(opts, commit);
+       allow = allow_empty(r, opts, commit);
        if (allow < 0) {
                res = allow;
                goto leave;
@@ -1929,7 +1957,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
        if (!opts->no_commit) {
 fast_forward_edit:
                if (author || command == TODO_REVERT || (flags & AMEND_MSG))
-                       res = do_commit(msg_file, author, opts, flags);
+                       res = do_commit(r, msg_file, author, opts, flags);
                else
                        res = error(_("unable to parse commit author"));
        }
@@ -1965,18 +1993,19 @@ static int prepare_revs(struct replay_opts *opts)
        return 0;
 }
 
-static int read_and_refresh_cache(struct replay_opts *opts)
+static int read_and_refresh_cache(struct repository *r,
+                                 struct replay_opts *opts)
 {
        struct lock_file index_lock = LOCK_INIT;
        int index_fd = hold_locked_index(&index_lock, 0);
-       if (read_index(&the_index) < 0) {
+       if (read_index(r->index) < 0) {
                rollback_lock_file(&index_lock);
                return error(_("git %s: failed to read the index"),
                        _(action_name(opts)));
        }
-       refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
+       refresh_index(r->index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
        if (index_fd >= 0) {
-               if (write_locked_index(&the_index, &index_lock,
+               if (write_locked_index(r->index, &index_lock,
                                       COMMIT_LOCK | SKIP_IF_UNCHANGED)) {
                        return error(_("git %s: failed to refresh the index"),
                                _(action_name(opts)));
@@ -2021,7 +2050,8 @@ static struct todo_item *append_new_todo(struct todo_list *todo_list)
        return todo_list->items + todo_list->nr++;
 }
 
-static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
+static int parse_insn_line(struct repository *r, struct todo_item *item,
+                          const char *bol, char *eol)
 {
        struct object_id commit_oid;
        char *end_of_object_name;
@@ -2106,11 +2136,12 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
        if (status < 0)
                return -1;
 
-       item->commit = lookup_commit_reference(the_repository, &commit_oid);
+       item->commit = lookup_commit_reference(r, &commit_oid);
        return !item->commit;
 }
 
-static int parse_insn_buffer(char *buf, struct todo_list *todo_list)
+static int parse_insn_buffer(struct repository *r, char *buf,
+                            struct todo_list *todo_list)
 {
        struct todo_item *item;
        char *p = buf, *next_p;
@@ -2126,7 +2157,7 @@ static int parse_insn_buffer(char *buf, struct todo_list *todo_list)
 
                item = append_new_todo(todo_list);
                item->offset_in_buf = p - todo_list->buf.buf;
-               if (parse_insn_line(item, p, eol)) {
+               if (parse_insn_line(r, item, p, eol)) {
                        res = error(_("invalid line %d: %.*s"),
                                i, (int)(eol - p), p);
                        item->command = TODO_NOOP;
@@ -2187,8 +2218,9 @@ static ssize_t strbuf_read_file_or_whine(struct strbuf *sb, const char *path)
        return len;
 }
 
-static int read_populate_todo(struct todo_list *todo_list,
-                       struct replay_opts *opts)
+static int read_populate_todo(struct repository *r,
+                             struct todo_list *todo_list,
+                             struct replay_opts *opts)
 {
        struct stat st;
        const char *todo_file = get_todo_path(opts);
@@ -2203,7 +2235,7 @@ static int read_populate_todo(struct todo_list *todo_list,
                return error(_("could not stat '%s'"), todo_file);
        fill_stat_data(&todo_list->stat, &st);
 
-       res = parse_insn_buffer(todo_list->buf.buf, todo_list);
+       res = parse_insn_buffer(r, todo_list->buf.buf, todo_list);
        if (res) {
                if (is_rebase_i(opts))
                        return error(_("please fix this using "
@@ -2234,7 +2266,7 @@ static int read_populate_todo(struct todo_list *todo_list,
                FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w");
 
                if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
-                               !parse_insn_buffer(done.buf.buf, &done))
+                   !parse_insn_buffer(r, done.buf.buf, &done))
                        todo_list->done_nr = count_commands(&done);
                else
                        todo_list->done_nr = 0;
@@ -2551,12 +2583,12 @@ static int reset_for_rollback(const struct object_id *oid)
        return run_command_v_opt(argv, RUN_GIT_CMD);
 }
 
-static int rollback_single_pick(void)
+static int rollback_single_pick(struct repository *r)
 {
        struct object_id head_oid;
 
-       if (!file_exists(git_path_cherry_pick_head(the_repository)) &&
-           !file_exists(git_path_revert_head(the_repository)))
+       if (!file_exists(git_path_cherry_pick_head(r)) &&
+           !file_exists(git_path_revert_head(r)))
                return error(_("no cherry-pick or revert in progress"));
        if (read_ref_full("HEAD", 0, &head_oid, NULL))
                return error(_("cannot resolve HEAD"));
@@ -2565,7 +2597,7 @@ static int rollback_single_pick(void)
        return reset_for_rollback(&head_oid);
 }
 
-int sequencer_rollback(struct replay_opts *opts)
+int sequencer_rollback(struct repository *r, struct replay_opts *opts)
 {
        FILE *f;
        struct object_id oid;
@@ -2579,7 +2611,7 @@ int sequencer_rollback(struct replay_opts *opts)
                 * If CHERRY_PICK_HEAD or REVERT_HEAD indicates
                 * a single-cherry-pick in progress, abort that.
                 */
-               return rollback_single_pick();
+               return rollback_single_pick(r);
        }
        if (!f)
                return error_errno(_("cannot open '%s'"), git_path_head_file());
@@ -2694,7 +2726,9 @@ static int save_opts(struct replay_opts *opts)
        return res;
 }
 
-static int make_patch(struct commit *commit, struct replay_opts *opts)
+static int make_patch(struct repository *r,
+                     struct commit *commit,
+                     struct replay_opts *opts)
 {
        struct strbuf buf = STRBUF_INIT;
        struct rev_info log_tree_opt;
@@ -2710,7 +2744,7 @@ static int make_patch(struct commit *commit, struct replay_opts *opts)
 
        strbuf_addf(&buf, "%s/patch", get_dir(opts));
        memset(&log_tree_opt, 0, sizeof(log_tree_opt));
-       repo_init_revisions(the_repository, &log_tree_opt, NULL);
+       repo_init_revisions(r, &log_tree_opt, NULL);
        log_tree_opt.abbrev = 0;
        log_tree_opt.diff = 1;
        log_tree_opt.diffopt.output_format = DIFF_FORMAT_PATCH;
@@ -2750,17 +2784,19 @@ static int intend_to_amend(void)
        return write_message(p, strlen(p), rebase_path_amend(), 1);
 }
 
-static int error_with_patch(struct commit *commit,
-       const char *subject, int subject_len,
-       struct replay_opts *opts, int exit_code, int to_amend)
+static int error_with_patch(struct repository *r,
+                           struct commit *commit,
+                           const char *subject, int subject_len,
+                           struct replay_opts *opts,
+                           int exit_code, int to_amend)
 {
        if (commit) {
-               if (make_patch(commit, opts))
+               if (make_patch(r, commit, opts))
                        return -1;
        } else if (copy_file(rebase_path_message(),
-                            git_path_merge_msg(the_repository), 0666))
+                            git_path_merge_msg(r), 0666))
                return error(_("unable to copy '%s' to '%s'"),
-                            git_path_merge_msg(the_repository), rebase_path_message());
+                            git_path_merge_msg(r), rebase_path_message());
 
        if (to_amend) {
                if (intend_to_amend())
@@ -2791,21 +2827,24 @@ static int error_with_patch(struct commit *commit,
        return exit_code;
 }
 
-static int error_failed_squash(struct commit *commit,
-       struct replay_opts *opts, int subject_len, const char *subject)
+static int error_failed_squash(struct repository *r,
+                              struct commit *commit,
+                              struct replay_opts *opts,
+                              int subject_len,
+                              const char *subject)
 {
        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(the_repository));
-       if (copy_file(git_path_merge_msg(the_repository), rebase_path_message(), 0666))
+       unlink(git_path_merge_msg(r));
+       if (copy_file(git_path_merge_msg(r), rebase_path_message(), 0666))
                return error(_("could not copy '%s' to '%s'"),
                             rebase_path_message(),
-                            git_path_merge_msg(the_repository));
-       return error_with_patch(commit, subject, subject_len, opts, 1, 0);
+                            git_path_merge_msg(r));
+       return error_with_patch(r, commit, subject, subject_len, opts, 1, 0);
 }
 
-static int do_exec(const char *command_line)
+static int do_exec(struct repository *r, const char *command_line)
 {
        struct argv_array child_env = ARGV_ARRAY_INIT;
        const char *child_argv[] = { NULL, NULL };
@@ -2820,10 +2859,10 @@ static int do_exec(const char *command_line)
                                          child_env.argv);
 
        /* force re-reading of the cache */
-       if (discard_cache() < 0 || read_cache() < 0)
+       if (discard_index(r->index) < 0 || read_index(r->index) < 0)
                return error(_("could not read index"));
 
-       dirty = require_clean_work_tree("rebase", NULL, 1, 1);
+       dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1);
 
        if (status) {
                warning(_("execution failed: %s\n%s"
@@ -2889,9 +2928,9 @@ static int safe_append(const char *filename, const char *fmt, ...)
        return 0;
 }
 
-static int do_label(const char *name, int len)
+static int do_label(struct repository *r, const char *name, int len)
 {
-       struct ref_store *refs = get_main_ref_store(the_repository);
+       struct ref_store *refs = get_main_ref_store(r);
        struct ref_transaction *transaction;
        struct strbuf ref_name = STRBUF_INIT, err = STRBUF_INIT;
        struct strbuf msg = STRBUF_INIT;
@@ -2932,7 +2971,9 @@ static int do_label(const char *name, int len)
 static const char *reflog_message(struct replay_opts *opts,
        const char *sub_action, const char *fmt, ...);
 
-static int do_reset(const char *name, int len, struct replay_opts *opts)
+static int do_reset(struct repository *r,
+                   const char *name, int len,
+                   struct replay_opts *opts)
 {
        struct strbuf ref_name = STRBUF_INIT;
        struct object_id oid;
@@ -2981,13 +3022,13 @@ static int do_reset(const char *name, int len, struct replay_opts *opts)
        memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
        setup_unpack_trees_porcelain(&unpack_tree_opts, "reset");
        unpack_tree_opts.head_idx = 1;
-       unpack_tree_opts.src_index = &the_index;
-       unpack_tree_opts.dst_index = &the_index;
+       unpack_tree_opts.src_index = r->index;
+       unpack_tree_opts.dst_index = r->index;
        unpack_tree_opts.fn = oneway_merge;
        unpack_tree_opts.merge = 1;
        unpack_tree_opts.update = 1;
 
-       if (read_cache_unmerged()) {
+       if (read_index_unmerged(r->index)) {
                rollback_lock_file(&lock);
                strbuf_release(&ref_name);
                return error_resolve_conflict(_(action_name(opts)));
@@ -3009,9 +3050,9 @@ static int do_reset(const char *name, int len, struct replay_opts *opts)
        }
 
        tree = parse_tree_indirect(&oid);
-       prime_cache_tree(&the_index, tree);
+       prime_cache_tree(r, r->index, tree);
 
-       if (write_locked_index(&the_index, &lock, COMMIT_LOCK) < 0)
+       if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0)
                ret = error(_("could not write index"));
        free((void *)desc.buffer);
 
@@ -3044,7 +3085,9 @@ static struct commit *lookup_label(const char *label, int len,
        return commit;
 }
 
-static int do_merge(struct commit *commit, const char *arg, int arg_len,
+static int do_merge(struct repository *r,
+                   struct commit *commit,
+                   const char *arg, int arg_len,
                    int flags, struct replay_opts *opts)
 {
        int run_commit_flags = (flags & TODO_EDIT_MERGE_MSG) ?
@@ -3111,7 +3154,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
                        ret = error(_("octopus merge cannot be executed on "
                                      "top of a [new root]"));
                else
-                       ret = fast_forward_to(&to_merge->item->object.oid,
+                       ret = fast_forward_to(r, &to_merge->item->object.oid,
                                              &head_commit->object.oid, 0,
                                              opts);
                goto leave_merge;
@@ -3130,11 +3173,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(the_repository), 0);
+               ret = write_message(body, len, git_path_merge_msg(r), 0);
                unuse_commit_buffer(commit, message);
                if (ret) {
                        error_errno(_("could not write '%s'"),
-                                   git_path_merge_msg(the_repository));
+                                   git_path_merge_msg(r));
                        goto leave_merge;
                }
        } else {
@@ -3156,11 +3199,11 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
                        len = buf.len;
                }
 
-               ret = write_message(p, len, git_path_merge_msg(the_repository), 0);
+               ret = write_message(p, len, git_path_merge_msg(r), 0);
                strbuf_release(&buf);
                if (ret) {
                        error_errno(_("could not write '%s'"),
-                                   git_path_merge_msg(the_repository));
+                                   git_path_merge_msg(r));
                        goto leave_merge;
                }
        }
@@ -3196,7 +3239,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
 
        if (can_fast_forward) {
                rollback_lock_file(&lock);
-               ret = fast_forward_to(&commit->object.oid,
+               ret = fast_forward_to(r, &commit->object.oid,
                                      &head_commit->object.oid, 0, opts);
                goto leave_merge;
        }
@@ -3221,7 +3264,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
                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));
+               argv_array_push(&cmd.args, git_path_merge_msg(r));
                if (opts->gpg_sign)
                        argv_array_push(&cmd.args, opts->gpg_sign);
 
@@ -3231,14 +3274,15 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
                                        oid_to_hex(&j->item->object.oid));
 
                strbuf_release(&ref_name);
-               unlink(git_path_cherry_pick_head(the_repository));
+               unlink(git_path_cherry_pick_head(r));
                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))
+               if (!ret && (discard_index(r->index) < 0 ||
+                            read_index(r->index) < 0))
                        ret = error(_("could not read index"));
                goto leave_merge;
        }
@@ -3253,14 +3297,14 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
        }
 
        write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
-                     git_path_merge_head(the_repository), 0);
-       write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
+                     git_path_merge_head(r), 0);
+       write_message("no-ff", 5, git_path_merge_mode(r), 0);
 
        for (j = bases; j; j = j->next)
                commit_list_insert(j->item, &reversed);
        free_commit_list(bases);
 
-       read_cache();
+       read_index(r->index);
        init_merge_options(&o);
        o.branch1 = "HEAD";
        o.branch2 = ref_name.buf;
@@ -3285,23 +3329,23 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
         */
        ret = !ret;
 
-       if (active_cache_changed &&
-           write_locked_index(&the_index, &lock, COMMIT_LOCK)) {
+       if (r->index->cache_changed &&
+           write_locked_index(r->index, &lock, COMMIT_LOCK)) {
                ret = error(_("merge: Unable to write new index file"));
                goto leave_merge;
        }
 
        rollback_lock_file(&lock);
        if (ret)
-               repo_rerere(the_repository, opts->allow_rerere_auto);
+               repo_rerere(r, opts->allow_rerere_auto);
        else
                /*
                 * In case of problems, we now want to return a positive
                 * value (a negative one would indicate that the `merge`
                 * command needs to be rescheduled).
                 */
-               ret = !!run_git_commit(git_path_merge_msg(the_repository), opts,
-                                    run_commit_flags);
+               ret = !!run_git_commit(r, git_path_merge_msg(r), opts,
+                                      run_commit_flags);
 
 leave_merge:
        strbuf_release(&ref_name);
@@ -3449,14 +3493,14 @@ static int checkout_onto(struct replay_opts *opts,
        return update_ref(NULL, "ORIG_HEAD", &oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR);
 }
 
-static int stopped_at_head(void)
+static int stopped_at_head(struct repository *r)
 {
        struct object_id head;
        struct commit *commit;
        struct commit_message message;
 
        if (get_oid("HEAD", &head) ||
-           !(commit = lookup_commit(the_repository, &head)) ||
+           !(commit = lookup_commit(r, &head)) ||
            parse_commit(commit) || get_message(commit, &message))
                fprintf(stderr, _("Stopped at HEAD\n"));
        else {
@@ -3478,7 +3522,9 @@ N_("Could not execute the todo command\n"
 "    git rebase --edit-todo\n"
 "    git rebase --continue\n");
 
-static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
+static int pick_commits(struct repository *r,
+                       struct todo_list *todo_list,
+                       struct replay_opts *opts)
 {
        int res = 0, reschedule = 0;
 
@@ -3486,7 +3532,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
        if (opts->allow_ff)
                assert(!(opts->signoff || opts->no_commit ||
                                opts->record_origin || opts->edit));
-       if (read_and_refresh_cache(opts))
+       if (read_and_refresh_cache(r, opts))
                return -1;
 
        while (todo_list->current < todo_list->nr) {
@@ -3516,14 +3562,14 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                        delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
 
                        if (item->command == TODO_BREAK)
-                               return stopped_at_head();
+                               return stopped_at_head(r);
                }
                if (item->command <= TODO_SQUASH) {
                        if (is_rebase_i(opts))
                                setenv("GIT_REFLOG_ACTION", reflog_message(opts,
                                        command_to_string(item->command), NULL),
                                        1);
-                       res = do_pick_commit(item->command, item->commit,
+                       res = do_pick_commit(r, item->command, item->commit,
                                        opts, is_final_fixup(todo_list));
                        if (is_rebase_i(opts) && res < 0) {
                                /* Reschedule */
@@ -3543,7 +3589,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                                                _("Stopped at %s...  %.*s\n"),
                                                short_commit_name(commit),
                                                item->arg_len, item->arg);
-                               return error_with_patch(commit,
+                               return error_with_patch(r, commit,
                                        item->arg, item->arg_len, opts, res,
                                        !res);
                        }
@@ -3553,7 +3599,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                        if (res && is_fixup(item->command)) {
                                if (res == 1)
                                        intend_to_amend();
-                               return error_failed_squash(item->commit, opts,
+                               return error_failed_squash(r, item->commit, opts,
                                        item->arg_len, item->arg);
                        } else if (res && is_rebase_i(opts) && item->commit) {
                                int to_amend = 0;
@@ -3572,7 +3618,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                                      oideq(&opts->squash_onto, &oid))))
                                        to_amend = 1;
 
-                               return res | error_with_patch(item->commit,
+                               return res | error_with_patch(r, item->commit,
                                                item->arg, item->arg_len, opts,
                                                res, to_amend);
                        }
@@ -3582,7 +3628,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                        struct stat st;
 
                        *end_of_arg = '\0';
-                       res = do_exec(item->arg);
+                       res = do_exec(r, item->arg);
                        *end_of_arg = saved;
 
                        /* Reread the todo file if it has changed. */
@@ -3593,19 +3639,19 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                                                  get_todo_path(opts));
                        else if (match_stat_data(&todo_list->stat, &st)) {
                                todo_list_release(todo_list);
-                               if (read_populate_todo(todo_list, opts))
+                               if (read_populate_todo(r, todo_list, opts))
                                        res = -1; /* message was printed */
                                /* `current` will be incremented below */
                                todo_list->current = -1;
                        }
                } else if (item->command == TODO_LABEL) {
-                       if ((res = do_label(item->arg, item->arg_len)))
+                       if ((res = do_label(r, item->arg, item->arg_len)))
                                reschedule = 1;
                } else if (item->command == TODO_RESET) {
-                       if ((res = do_reset(item->arg, item->arg_len, opts)))
+                       if ((res = do_reset(r, item->arg, item->arg_len, opts)))
                                reschedule = 1;
                } else if (item->command == TODO_MERGE) {
-                       if ((res = do_merge(item->commit,
+                       if ((res = do_merge(r, item->commit,
                                            item->arg, item->arg_len,
                                            item->flags, opts)) < 0)
                                reschedule = 1;
@@ -3614,7 +3660,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                                                    peek_command(todo_list, 1));
                        if (res > 0)
                                /* failed with merge conflicts */
-                               return error_with_patch(item->commit,
+                               return error_with_patch(r, item->commit,
                                                        item->arg,
                                                        item->arg_len, opts,
                                                        res, 0);
@@ -3630,7 +3676,8 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                        if (save_todo(todo_list, opts))
                                return -1;
                        if (item->commit)
-                               return error_with_patch(item->commit,
+                               return error_with_patch(r,
+                                                       item->commit,
                                                        item->arg,
                                                        item->arg_len, opts,
                                                        res, 0);
@@ -3695,7 +3742,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                        struct object_id orig, head;
 
                        memset(&log_tree_opt, 0, sizeof(log_tree_opt));
-                       repo_init_revisions(the_repository, &log_tree_opt, NULL);
+                       repo_init_revisions(r, &log_tree_opt, NULL);
                        log_tree_opt.diff = 1;
                        log_tree_opt.diffopt.output_format =
                                DIFF_FORMAT_DIFFSTAT;
@@ -3752,26 +3799,27 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
        return sequencer_remove_state(opts);
 }
 
-static int continue_single_pick(void)
+static int continue_single_pick(struct repository *r)
 {
        const char *argv[] = { "commit", NULL };
 
-       if (!file_exists(git_path_cherry_pick_head(the_repository)) &&
-           !file_exists(git_path_revert_head(the_repository)))
+       if (!file_exists(git_path_cherry_pick_head(r)) &&
+           !file_exists(git_path_revert_head(r)))
                return error(_("no cherry-pick or revert in progress"));
        return run_command_v_opt(argv, RUN_GIT_CMD);
 }
 
-static int commit_staged_changes(struct replay_opts *opts,
+static int commit_staged_changes(struct repository *r,
+                                struct replay_opts *opts,
                                 struct todo_list *todo_list)
 {
        unsigned int flags = ALLOW_EMPTY | EDIT_MSG;
        unsigned int final_fixup = 0, is_clean;
 
-       if (has_unstaged_changes(1))
+       if (has_unstaged_changes(r, 1))
                return error(_("cannot rebase: You have unstaged changes."));
 
-       is_clean = !has_uncommitted_changes(0);
+       is_clean = !has_uncommitted_changes(r, 0);
 
        if (file_exists(rebase_path_amend())) {
                struct strbuf rev = STRBUF_INIT;
@@ -3855,7 +3903,7 @@ static int commit_staged_changes(struct replay_opts *opts,
                                struct commit *commit;
                                const char *path = rebase_path_squash_msg();
 
-                               if (parse_head(&commit) ||
+                               if (parse_head(r, &commit) ||
                                    !(p = get_commit_buffer(commit, NULL)) ||
                                    write_message(p, strlen(p), path, 0)) {
                                        unuse_commit_buffer(commit, p);
@@ -3871,7 +3919,7 @@ static int commit_staged_changes(struct replay_opts *opts,
        }
 
        if (is_clean) {
-               const char *cherry_pick_head = git_path_cherry_pick_head(the_repository);
+               const char *cherry_pick_head = git_path_cherry_pick_head(r);
 
                if (file_exists(cherry_pick_head) && unlink(cherry_pick_head))
                        return error(_("could not remove CHERRY_PICK_HEAD"));
@@ -3879,7 +3927,7 @@ static int commit_staged_changes(struct replay_opts *opts,
                        return 0;
        }
 
-       if (run_git_commit(final_fixup ? NULL : rebase_path_message(),
+       if (run_git_commit(r, final_fixup ? NULL : rebase_path_message(),
                           opts, flags))
                return error(_("could not commit staged changes."));
        unlink(rebase_path_amend());
@@ -3900,36 +3948,36 @@ static int commit_staged_changes(struct replay_opts *opts,
        return 0;
 }
 
-int sequencer_continue(struct replay_opts *opts)
+int sequencer_continue(struct repository *r, struct replay_opts *opts)
 {
        struct todo_list todo_list = TODO_LIST_INIT;
        int res;
 
-       if (read_and_refresh_cache(opts))
+       if (read_and_refresh_cache(r, opts))
                return -1;
 
        if (read_populate_opts(opts))
                return -1;
        if (is_rebase_i(opts)) {
-               if ((res = read_populate_todo(&todo_list, opts)))
+               if ((res = read_populate_todo(r, &todo_list, opts)))
                        goto release_todo_list;
-               if (commit_staged_changes(opts, &todo_list))
+               if (commit_staged_changes(r, opts, &todo_list))
                        return -1;
        } else if (!file_exists(get_todo_path(opts)))
-               return continue_single_pick();
-       else if ((res = read_populate_todo(&todo_list, opts)))
+               return continue_single_pick(r);
+       else if ((res = read_populate_todo(r, &todo_list, opts)))
                goto release_todo_list;
 
        if (!is_rebase_i(opts)) {
                /* Verify that the conflict has been resolved */
-               if (file_exists(git_path_cherry_pick_head(the_repository)) ||
-                   file_exists(git_path_revert_head(the_repository))) {
-                       res = continue_single_pick();
+               if (file_exists(git_path_cherry_pick_head(r)) ||
+                   file_exists(git_path_revert_head(r))) {
+                       res = continue_single_pick(r);
                        if (res)
                                goto release_todo_list;
                }
-               if (index_differs_from("HEAD", NULL, 0)) {
-                       res = error_dirty_index(opts);
+               if (index_differs_from(r, "HEAD", NULL, 0)) {
+                       res = error_dirty_index(r->index, opts);
                        goto release_todo_list;
                }
                todo_list.current++;
@@ -3943,27 +3991,30 @@ int sequencer_continue(struct replay_opts *opts)
                strbuf_release(&buf);
        }
 
-       res = pick_commits(&todo_list, opts);
+       res = pick_commits(r, &todo_list, opts);
 release_todo_list:
        todo_list_release(&todo_list);
        return res;
 }
 
-static int single_pick(struct commit *cmit, struct replay_opts *opts)
+static int single_pick(struct repository *r,
+                      struct commit *cmit,
+                      struct replay_opts *opts)
 {
        setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
-       return do_pick_commit(opts->action == REPLAY_PICK ?
+       return do_pick_commit(r, opts->action == REPLAY_PICK ?
                TODO_PICK : TODO_REVERT, cmit, opts, 0);
 }
 
-int sequencer_pick_revisions(struct replay_opts *opts)
+int sequencer_pick_revisions(struct repository *r,
+                            struct replay_opts *opts)
 {
        struct todo_list todo_list = TODO_LIST_INIT;
        struct object_id oid;
        int i, res;
 
        assert(opts->revs);
-       if (read_and_refresh_cache(opts))
+       if (read_and_refresh_cache(r, opts))
                return -1;
 
        for (i = 0; i < opts->revs->pending.nr; i++) {
@@ -3975,8 +4026,8 @@ int sequencer_pick_revisions(struct replay_opts *opts)
                        continue;
 
                if (!get_oid(name, &oid)) {
-                       if (!lookup_commit_reference_gently(the_repository, &oid, 1)) {
-                               enum object_type type = oid_object_info(the_repository,
+                       if (!lookup_commit_reference_gently(r, &oid, 1)) {
+                               enum object_type type = oid_object_info(r,
                                                                        &oid,
                                                                        NULL);
                                return error(_("%s: can't cherry-pick a %s"),
@@ -4005,7 +4056,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
                        return error(_("empty commit set passed"));
                if (get_revision(opts->revs))
                        BUG("unexpected extra commit from walk");
-               return single_pick(cmit, opts);
+               return single_pick(r, cmit, opts);
        }
 
        /*
@@ -4024,7 +4075,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
        if (save_opts(opts))
                return -1;
        update_abort_safety_file();
-       res = pick_commits(&todo_list, opts);
+       res = pick_commits(r, &todo_list, opts);
        todo_list_release(&todo_list);
        return res;
 }
@@ -4428,7 +4479,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
        return 0;
 }
 
-int sequencer_make_script(FILE *out, int argc, const char **argv,
+int sequencer_make_script(struct repository *r, FILE *out,
+                         int argc, const char **argv,
                          unsigned flags)
 {
        char *format = NULL;
@@ -4440,7 +4492,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
        const char *insn = flags & TODO_LIST_ABBREVIATE_CMDS ? "p" : "pick";
        int rebase_merges = flags & TODO_LIST_REBASE_MERGES;
 
-       repo_init_revisions(the_repository, &revs, NULL);
+       repo_init_revisions(r, &revs, NULL);
        revs.verbose_header = 1;
        if (!rebase_merges)
                revs.max_parents = 1;
@@ -4493,7 +4545,8 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
  * Add commands after pick and (series of) squash/fixup commands
  * in the todo list.
  */
-int sequencer_add_exec_commands(const char *commands)
+int sequencer_add_exec_commands(struct repository *r,
+                               const char *commands)
 {
        const char *todo_file = rebase_path_todo();
        struct todo_list todo_list = TODO_LIST_INIT;
@@ -4504,7 +4557,7 @@ int sequencer_add_exec_commands(const char *commands)
        if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
                return error(_("could not read '%s'."), todo_file);
 
-       if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) {
+       if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {
                todo_list_release(&todo_list);
                return error(_("unusable todo list: '%s'"), todo_file);
        }
@@ -4549,7 +4602,7 @@ int sequencer_add_exec_commands(const char *commands)
        return i;
 }
 
-int transform_todos(unsigned flags)
+int transform_todos(struct repository *r, unsigned flags)
 {
        const char *todo_file = rebase_path_todo();
        struct todo_list todo_list = TODO_LIST_INIT;
@@ -4560,7 +4613,7 @@ int transform_todos(unsigned flags)
        if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
                return error(_("could not read '%s'."), todo_file);
 
-       if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) {
+       if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {
                todo_list_release(&todo_list);
                return error(_("unusable todo list: '%s'"), todo_file);
        }
@@ -4629,7 +4682,7 @@ define_commit_slab(commit_seen, unsigned char);
  * Check if there is an unrecognized command or a
  * bad SHA-1 in a command.
  */
-int check_todo_list(void)
+int check_todo_list(struct repository *r)
 {
        enum missing_commit_check_level check_level = get_missing_commit_check_level();
        struct strbuf todo_file = STRBUF_INIT;
@@ -4646,7 +4699,7 @@ int check_todo_list(void)
                goto leave_check;
        }
        advise_to_edit_todo = res =
-               parse_insn_buffer(todo_list.buf.buf, &todo_list);
+               parse_insn_buffer(r, todo_list.buf.buf, &todo_list);
 
        if (res || check_level == MISSING_COMMIT_CHECK_IGNORE)
                goto leave_check;
@@ -4665,7 +4718,7 @@ int check_todo_list(void)
                goto leave_check;
        }
        strbuf_release(&todo_file);
-       res = !!parse_insn_buffer(todo_list.buf.buf, &todo_list);
+       res = !!parse_insn_buffer(r, todo_list.buf.buf, &todo_list);
 
        /* Find commits in git-rebase-todo.backup yet unseen */
        for (i = todo_list.nr - 1; i >= 0; i--) {
@@ -4729,7 +4782,7 @@ static int rewrite_file(const char *path, const char *buf, size_t len)
 }
 
 /* skip picking commits whose parents are unchanged */
-static int skip_unnecessary_picks(struct object_id *output_oid)
+static int skip_unnecessary_picks(struct repository *r, struct object_id *output_oid)
 {
        const char *todo_file = rebase_path_todo();
        struct strbuf buf = STRBUF_INIT;
@@ -4747,7 +4800,7 @@ static int skip_unnecessary_picks(struct object_id *output_oid)
 
        if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
                return -1;
-       if (parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) {
+       if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) {
                todo_list_release(&todo_list);
                return -1;
        }
@@ -4808,7 +4861,7 @@ static int skip_unnecessary_picks(struct object_id *output_oid)
        return 0;
 }
 
-int complete_action(struct replay_opts *opts, unsigned flags,
+int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
                    const char *shortrevisions, const char *onto_name,
                    const char *onto, const char *orig_head, const char *cmd,
                    unsigned autosquash)
@@ -4826,16 +4879,16 @@ int complete_action(struct replay_opts *opts, unsigned flags,
            write_message("noop\n", 5, todo_file, 0))
                return -1;
 
-       if (autosquash && rearrange_squash())
+       if (autosquash && rearrange_squash(r))
                return -1;
 
        if (cmd && *cmd)
-               sequencer_add_exec_commands(cmd);
+               sequencer_add_exec_commands(r, cmd);
 
        if (strbuf_read_file(buf, todo_file, 0) < 0)
                return error_errno(_("could not read '%s'."), todo_file);
 
-       if (parse_insn_buffer(buf->buf, &todo_list)) {
+       if (parse_insn_buffer(r, buf->buf, &todo_list)) {
                todo_list_release(&todo_list);
                return error(_("unusable todo list: '%s'"), todo_file);
        }
@@ -4864,7 +4917,7 @@ int complete_action(struct replay_opts *opts, unsigned flags,
                return error(_("could not copy '%s' to '%s'."), todo_file,
                             rebase_path_todo_backup());
 
-       if (transform_todos(flags | TODO_LIST_SHORTEN_IDS))
+       if (transform_todos(r, flags | TODO_LIST_SHORTEN_IDS))
                return error(_("could not transform the todo list"));
 
        strbuf_reset(buf);
@@ -4888,24 +4941,24 @@ int complete_action(struct replay_opts *opts, unsigned flags,
 
        todo_list_release(&todo_list);
 
-       if (check_todo_list()) {
+       if (check_todo_list(r)) {
                checkout_onto(opts, onto_name, onto, orig_head);
                return -1;
        }
 
-       if (transform_todos(flags & ~(TODO_LIST_SHORTEN_IDS)))
+       if (transform_todos(r, flags & ~(TODO_LIST_SHORTEN_IDS)))
                return error(_("could not transform the todo list"));
 
-       if (opts->allow_ff && skip_unnecessary_picks(&oid))
+       if (opts->allow_ff && skip_unnecessary_picks(r, &oid))
                return error(_("could not skip unnecessary pick commands"));
 
        if (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head))
                return -1;
 
-       if (require_clean_work_tree("rebase", "", 1, 1))
+       if (require_clean_work_tree(r, "rebase", "", 1, 1))
                return -1;
 
-       return sequencer_continue(opts);
+       return sequencer_continue(r, opts);
 }
 
 struct subject2item_entry {
@@ -4932,7 +4985,7 @@ define_commit_slab(commit_todo_item, struct todo_item *);
  * message will have to be retrieved from the commit (as the oneline in the
  * script cannot be trusted) in order to normalize the autosquash arrangement.
  */
-int rearrange_squash(void)
+int rearrange_squash(struct repository *r)
 {
        const char *todo_file = rebase_path_todo();
        struct todo_list todo_list = TODO_LIST_INIT;
@@ -4943,7 +4996,7 @@ int rearrange_squash(void)
 
        if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
                return -1;
-       if (parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) {
+       if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) {
                todo_list_release(&todo_list);
                return -1;
        }
index 5071a73563f1cdfc35060603d1fef4e085497798..9d83f0f3e90313be990439972845e9d4f2bc1804 100644 (file)
@@ -5,6 +5,7 @@
 #include "strbuf.h"
 
 struct commit;
+struct repository;
 
 const char *git_path_commit_editmsg(void);
 const char *git_path_seq_dir(void);
@@ -74,9 +75,10 @@ int write_message(const void *buf, size_t len, const char *filename,
 
 /* Call this to setup defaults before parsing command line options */
 void sequencer_init_config(struct replay_opts *opts);
-int sequencer_pick_revisions(struct replay_opts *opts);
-int sequencer_continue(struct replay_opts *opts);
-int sequencer_rollback(struct replay_opts *opts);
+int sequencer_pick_revisions(struct repository *repo,
+                            struct replay_opts *opts);
+int sequencer_continue(struct repository *repo, struct replay_opts *opts);
+int sequencer_rollback(struct repository *repo, struct replay_opts *opts);
 int sequencer_remove_state(struct replay_opts *opts);
 
 #define TODO_LIST_KEEP_EMPTY (1U << 0)
@@ -89,18 +91,19 @@ int sequencer_remove_state(struct replay_opts *opts);
  * commits should be rebased onto the new base, this flag needs to be passed.
  */
 #define TODO_LIST_REBASE_COUSINS (1U << 4)
-int sequencer_make_script(FILE *out, int argc, const char **argv,
+int sequencer_make_script(struct repository *repo, FILE *out,
+                         int argc, const char **argv,
                          unsigned flags);
 
-int sequencer_add_exec_commands(const char *command);
-int transform_todos(unsigned flags);
+int sequencer_add_exec_commands(struct repository *r, const char *command);
+int transform_todos(struct repository *r, unsigned flags);
 enum missing_commit_check_level get_missing_commit_check_level(void);
-int check_todo_list(void);
-int complete_action(struct replay_opts *opts, unsigned flags,
+int check_todo_list(struct repository *r);
+int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
                    const char *shortrevisions, const char *onto_name,
                    const char *onto, const char *orig_head, const char *cmd,
                    unsigned autosquash);
-int rearrange_squash(void);
+int rearrange_squash(struct repository *r);
 
 extern const char sign_off_header[];
 
@@ -112,7 +115,7 @@ extern const char sign_off_header[];
  */
 void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag);
 
-void append_conflicts_hint(struct strbuf *msgbuf);
+void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf);
 int message_is_empty(const struct strbuf *sb,
                     enum commit_msg_cleanup_mode cleanup_mode);
 int template_untouched(const struct strbuf *sb, const char *template_file,
@@ -128,7 +131,9 @@ int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit);
 
 #define SUMMARY_INITIAL_COMMIT   (1 << 0)
 #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)
-void print_commit_summary(const char *prefix, const struct object_id *oid,
+void print_commit_summary(struct repository *repo,
+                         const char *prefix,
+                         const struct object_id *oid,
                          unsigned int flags);
 
 int read_author_script(const char *path, char **name, char **email, char **date,
diff --git a/setup.c b/setup.c
index 1be5037f129646cd46d3dc048e8f58dc3bdac0b9..12bf25a0ebad33a8d8db9b8f9a44b0e6e04977d4 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -831,16 +831,6 @@ static const char *setup_bare_git_dir(struct strbuf *cwd, int offset,
        return NULL;
 }
 
-static const char *setup_nongit(const char *cwd, int *nongit_ok)
-{
-       if (!nongit_ok)
-               die(_("not a git repository (or any of the parent directories): %s"), DEFAULT_GIT_DIR_ENVIRONMENT);
-       if (chdir(cwd))
-               die_errno(_("cannot come back to cwd"));
-       *nongit_ok = 1;
-       return NULL;
-}
-
 static dev_t get_device_or_die(const char *path, const char *prefix, int prefix_len)
 {
        struct stat buf;
@@ -1054,7 +1044,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
 {
        static struct strbuf cwd = STRBUF_INIT;
        struct strbuf dir = STRBUF_INIT, gitdir = STRBUF_INIT;
-       const char *prefix;
+       const char *prefix = NULL;
        struct repository_format repo_fmt;
 
        /*
@@ -1079,9 +1069,6 @@ const char *setup_git_directory_gently(int *nongit_ok)
        strbuf_addbuf(&dir, &cwd);
 
        switch (setup_git_directory_gently_1(&dir, &gitdir, 1)) {
-       case GIT_DIR_NONE:
-               prefix = NULL;
-               break;
        case GIT_DIR_EXPLICIT:
                prefix = setup_explicit_git_dir(gitdir.buf, &cwd, &repo_fmt, nongit_ok);
                break;
@@ -1097,29 +1084,51 @@ const char *setup_git_directory_gently(int *nongit_ok)
                prefix = setup_bare_git_dir(&cwd, dir.len, &repo_fmt, nongit_ok);
                break;
        case GIT_DIR_HIT_CEILING:
-               prefix = setup_nongit(cwd.buf, nongit_ok);
+               if (!nongit_ok)
+                       die(_("not a git repository (or any of the parent directories): %s"),
+                           DEFAULT_GIT_DIR_ENVIRONMENT);
+               *nongit_ok = 1;
                break;
        case GIT_DIR_HIT_MOUNT_POINT:
-               if (nongit_ok) {
-                       *nongit_ok = 1;
-                       strbuf_release(&cwd);
-                       strbuf_release(&dir);
-                       return NULL;
-               }
-               die(_("not a git repository (or any parent up to mount point %s)\n"
-                     "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)."),
-                   dir.buf);
+               if (!nongit_ok)
+                       die(_("not a git repository (or any parent up to mount point %s)\n"
+                             "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)."),
+                           dir.buf);
+               *nongit_ok = 1;
+               break;
+       case GIT_DIR_NONE:
+               /*
+                * As a safeguard against setup_git_directory_gently_1 returning
+                * this value, fallthrough to BUG. Otherwise it is possible to
+                * set startup_info->have_repository to 1 when we did nothing to
+                * find a repository.
+                */
        default:
                BUG("unhandled setup_git_directory_1() result");
        }
 
-       if (prefix)
-               setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1);
-       else
+       /*
+        * At this point, nongit_ok is stable. If it is non-NULL and points
+        * to a non-zero value, then this means that we haven't found a
+        * repository and that the caller expects startup_info to reflect
+        * this.
+        *
+        * Regardless of the state of nongit_ok, startup_info->prefix and
+        * the GIT_PREFIX environment variable must always match. For details
+        * see Documentation/config/alias.txt.
+        */
+       if (nongit_ok && *nongit_ok) {
+               startup_info->have_repository = 0;
+               startup_info->prefix = NULL;
                setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
-
-       startup_info->have_repository = !nongit_ok || !*nongit_ok;
-       startup_info->prefix = prefix;
+       } else {
+               startup_info->have_repository = 1;
+               startup_info->prefix = prefix;
+               if (prefix)
+                       setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1);
+               else
+                       setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
+       }
 
        /*
         * Not all paths through the setup code will call 'set_git_dir()' (which
@@ -1132,7 +1141,10 @@ const char *setup_git_directory_gently(int *nongit_ok)
         * the user has set GIT_DIR.  It may be beneficial to disallow bogus
         * GIT_DIR values at some point in the future.
         */
-       if (startup_info->have_repository || getenv(GIT_DIR_ENVIRONMENT)) {
+       if (/* GIT_DIR_EXPLICIT, GIT_DIR_DISCOVERED, GIT_DIR_BARE */
+           startup_info->have_repository ||
+           /* GIT_DIR_EXPLICIT */
+           getenv(GIT_DIR_ENVIRONMENT)) {
                if (!the_repository->gitdir) {
                        const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
                        if (!gitdir)
index 5bd11c85bc563618b59dad3ff06e5ae5296c892b..386b96e1d76622e4650c1bbab90092fef7dd7303 100644 (file)
@@ -346,25 +346,21 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)
        }
 }
 
-void sha1_file_name(struct repository *r, struct strbuf *buf, const unsigned char *sha1)
+static const char *odb_loose_path(struct object_directory *odb,
+                                 struct strbuf *buf,
+                                 const unsigned char *sha1)
 {
-       strbuf_addstr(buf, r->objects->objectdir);
+       strbuf_reset(buf);
+       strbuf_addstr(buf, odb->path);
        strbuf_addch(buf, '/');
        fill_sha1_path(buf, sha1);
+       return buf->buf;
 }
 
-struct strbuf *alt_scratch_buf(struct alternate_object_database *alt)
+const char *loose_object_path(struct repository *r, struct strbuf *buf,
+                             const unsigned char *sha1)
 {
-       strbuf_setlen(&alt->scratch, alt->base_len);
-       return &alt->scratch;
-}
-
-static const char *alt_sha1_path(struct alternate_object_database *alt,
-                                const unsigned char *sha1)
-{
-       struct strbuf *buf = alt_scratch_buf(alt);
-       fill_sha1_path(buf, sha1);
-       return buf->buf;
+       return odb_loose_path(r->objects->odb, buf, sha1);
 }
 
 /*
@@ -374,7 +370,7 @@ static int alt_odb_usable(struct raw_object_store *o,
                          struct strbuf *path,
                          const char *normalized_objdir)
 {
-       struct alternate_object_database *alt;
+       struct object_directory *odb;
 
        /* Detect cases where alternate disappeared */
        if (!is_directory(path->buf)) {
@@ -388,8 +384,8 @@ static int alt_odb_usable(struct raw_object_store *o,
         * Prevent the common mistake of listing the same
         * thing twice, or object directory itself.
         */
-       for (alt = o->alt_odb_list; alt; alt = alt->next) {
-               if (!fspathcmp(path->buf, alt->path))
+       for (odb = o->odb; odb; odb = odb->next) {
+               if (!fspathcmp(path->buf, odb->path))
                        return 0;
        }
        if (!fspathcmp(path->buf, normalized_objdir))
@@ -402,7 +398,7 @@ static int alt_odb_usable(struct raw_object_store *o,
  * Prepare alternate object database registry.
  *
  * The variable alt_odb_list points at the list of struct
- * alternate_object_database.  The elements on this list come from
+ * object_directory.  The elements on this list come from
  * non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
  * environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
  * whose contents is similar to that environment variable but can be
@@ -419,7 +415,7 @@ static void read_info_alternates(struct repository *r,
 static int link_alt_odb_entry(struct repository *r, const char *entry,
        const char *relative_base, int depth, const char *normalized_objdir)
 {
-       struct alternate_object_database *ent;
+       struct object_directory *ent;
        struct strbuf pathbuf = STRBUF_INIT;
 
        if (!is_absolute_path(entry) && relative_base) {
@@ -447,11 +443,12 @@ static int link_alt_odb_entry(struct repository *r, const char *entry,
                return -1;
        }
 
-       ent = alloc_alt_odb(pathbuf.buf);
+       ent = xcalloc(1, sizeof(*ent));
+       ent->path = xstrdup(pathbuf.buf);
 
        /* add the alternate entry */
-       *r->objects->alt_odb_tail = ent;
-       r->objects->alt_odb_tail = &(ent->next);
+       *r->objects->odb_tail = ent;
+       r->objects->odb_tail = &(ent->next);
        ent->next = NULL;
 
        /* recursively add alternates */
@@ -505,7 +502,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
                return;
        }
 
-       strbuf_add_absolute_path(&objdirbuf, r->objects->objectdir);
+       strbuf_add_absolute_path(&objdirbuf, r->objects->odb->path);
        if (strbuf_normalize_path(&objdirbuf) < 0)
                die(_("unable to normalize object directory: %s"),
                    objdirbuf.buf);
@@ -540,18 +537,6 @@ static void read_info_alternates(struct repository *r,
        free(path);
 }
 
-struct alternate_object_database *alloc_alt_odb(const char *dir)
-{
-       struct alternate_object_database *ent;
-
-       FLEX_ALLOC_STR(ent, path, dir);
-       strbuf_init(&ent->scratch, 0);
-       strbuf_addf(&ent->scratch, "%s/", dir);
-       ent->base_len = ent->scratch.len;
-
-       return ent;
-}
-
 void add_to_alternates_file(const char *reference)
 {
        struct lock_file lock = LOCK_INIT;
@@ -588,7 +573,7 @@ void add_to_alternates_file(const char *reference)
                fprintf_or_die(out, "%s\n", reference);
                if (commit_lock_file(&lock))
                        die_errno(_("unable to move new alternates file into place"));
-               if (the_repository->objects->alt_odb_tail)
+               if (the_repository->objects->loaded_alternates)
                        link_alt_odb_entries(the_repository, reference,
                                             '\n', NULL, 0);
        }
@@ -684,11 +669,11 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
 
 int foreach_alt_odb(alt_odb_fn fn, void *cb)
 {
-       struct alternate_object_database *ent;
+       struct object_directory *ent;
        int r = 0;
 
        prepare_alt_odb(the_repository);
-       for (ent = the_repository->objects->alt_odb_list; ent; ent = ent->next) {
+       for (ent = the_repository->objects->odb->next; ent; ent = ent->next) {
                r = fn(ent, cb);
                if (r)
                        break;
@@ -698,13 +683,13 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
 
 void prepare_alt_odb(struct repository *r)
 {
-       if (r->objects->alt_odb_tail)
+       if (r->objects->loaded_alternates)
                return;
 
-       r->objects->alt_odb_tail = &r->objects->alt_odb_list;
        link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
 
-       read_info_alternates(r, r->objects->objectdir, 0);
+       read_info_alternates(r, r->objects->odb->path, 0);
+       r->objects->loaded_alternates = 1;
 }
 
 /* Returns 1 if we have successfully freshened the file, 0 otherwise. */
@@ -731,23 +716,27 @@ int check_and_freshen_file(const char *fn, int freshen)
        return 1;
 }
 
-static int check_and_freshen_local(const struct object_id *oid, int freshen)
+static int check_and_freshen_odb(struct object_directory *odb,
+                                const struct object_id *oid,
+                                int freshen)
 {
-       static struct strbuf buf = STRBUF_INIT;
-
-       strbuf_reset(&buf);
-       sha1_file_name(the_repository, &buf, oid->hash);
+       static struct strbuf path = STRBUF_INIT;
+       odb_loose_path(odb, &path, oid->hash);
+       return check_and_freshen_file(path.buf, freshen);
+}
 
-       return check_and_freshen_file(buf.buf, freshen);
+static int check_and_freshen_local(const struct object_id *oid, int freshen)
+{
+       return check_and_freshen_odb(the_repository->objects->odb, oid, freshen);
 }
 
 static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
 {
-       struct alternate_object_database *alt;
+       struct object_directory *odb;
+
        prepare_alt_odb(the_repository);
-       for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
-               const char *path = alt_sha1_path(alt, oid->hash);
-               if (check_and_freshen_file(path, freshen))
+       for (odb = the_repository->objects->odb->next; odb; odb = odb->next) {
+               if (check_and_freshen_odb(odb, oid, freshen))
                        return 1;
        }
        return 0;
@@ -888,25 +877,17 @@ int git_open_cloexec(const char *name, int flags)
  *
  * The "path" out-parameter will give the path of the object we found (if any).
  * Note that it may point to static storage and is only valid until another
- * call to sha1_file_name(), etc.
+ * call to stat_sha1_file().
  */
 static int stat_sha1_file(struct repository *r, const unsigned char *sha1,
                          struct stat *st, const char **path)
 {
-       struct alternate_object_database *alt;
+       struct object_directory *odb;
        static struct strbuf buf = STRBUF_INIT;
 
-       strbuf_reset(&buf);
-       sha1_file_name(r, &buf, sha1);
-       *path = buf.buf;
-
-       if (!lstat(*path, st))
-               return 0;
-
        prepare_alt_odb(r);
-       errno = ENOENT;
-       for (alt = r->objects->alt_odb_list; alt; alt = alt->next) {
-               *path = alt_sha1_path(alt, sha1);
+       for (odb = r->objects->odb; odb; odb = odb->next) {
+               *path = odb_loose_path(odb, &buf, sha1);
                if (!lstat(*path, st))
                        return 0;
        }
@@ -922,25 +903,17 @@ static int open_sha1_file(struct repository *r,
                          const unsigned char *sha1, const char **path)
 {
        int fd;
-       struct alternate_object_database *alt;
-       int most_interesting_errno;
+       struct object_directory *odb;
+       int most_interesting_errno = ENOENT;
        static struct strbuf buf = STRBUF_INIT;
 
-       strbuf_reset(&buf);
-       sha1_file_name(r, &buf, sha1);
-       *path = buf.buf;
-
-       fd = git_open(*path);
-       if (fd >= 0)
-               return fd;
-       most_interesting_errno = errno;
-
        prepare_alt_odb(r);
-       for (alt = r->objects->alt_odb_list; alt; alt = alt->next) {
-               *path = alt_sha1_path(alt, sha1);
+       for (odb = r->objects->odb; odb; odb = odb->next) {
+               *path = odb_loose_path(odb, &buf, sha1);
                fd = git_open(*path);
                if (fd >= 0)
                        return fd;
+
                if (most_interesting_errno == ENOENT)
                        most_interesting_errno = errno;
        }
@@ -948,6 +921,22 @@ static int open_sha1_file(struct repository *r,
        return -1;
 }
 
+static int quick_has_loose(struct repository *r,
+                          const unsigned char *sha1)
+{
+       struct object_id oid;
+       struct object_directory *odb;
+
+       hashcpy(oid.hash, sha1);
+
+       prepare_alt_odb(r);
+       for (odb = r->objects->odb; odb; odb = odb->next) {
+               if (oid_array_lookup(odb_loose_cache(odb, &oid), &oid) >= 0)
+                       return 1;
+       }
+       return 0;
+}
+
 /*
  * Map the loose object at "path" if it is not NULL, or the path found by
  * searching for a loose object named "sha1".
@@ -971,6 +960,7 @@ static void *map_sha1_file_1(struct repository *r, const char *path,
                        if (!*size) {
                                /* mmap() is forbidden on empty files */
                                error(_("object file %s is empty"), path);
+                               close(fd);
                                return NULL;
                        }
                        map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0);
@@ -1198,6 +1188,8 @@ static int sha1_loose_object_info(struct repository *r,
        if (!oi->typep && !oi->type_name && !oi->sizep && !oi->contentp) {
                const char *path;
                struct stat st;
+               if (!oi->disk_sizep && (flags & OBJECT_INFO_QUICK))
+                       return quick_has_loose(r, sha1) ? 0 : -1;
                if (stat_sha1_file(r, sha1, &st, &path) < 0)
                        return -1;
                if (oi->disk_sizep)
@@ -1626,8 +1618,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
        static struct strbuf tmp_file = STRBUF_INIT;
        static struct strbuf filename = STRBUF_INIT;
 
-       strbuf_reset(&filename);
-       sha1_file_name(the_repository, &filename, oid->hash);
+       loose_object_path(the_repository, &filename, oid->hash);
 
        fd = create_tmpfile(&tmp_file, filename.buf);
        if (fd < 0) {
@@ -2134,43 +2125,63 @@ int for_each_loose_file_in_objdir(const char *path,
        return r;
 }
 
-struct loose_alt_odb_data {
-       each_loose_object_fn *cb;
-       void *data;
-};
+int for_each_loose_object(each_loose_object_fn cb, void *data,
+                         enum for_each_object_flags flags)
+{
+       struct object_directory *odb;
+
+       prepare_alt_odb(the_repository);
+       for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+               int r = for_each_loose_file_in_objdir(odb->path, cb, NULL,
+                                                     NULL, data);
+               if (r)
+                       return r;
+
+               if (flags & FOR_EACH_OBJECT_LOCAL_ONLY)
+                       break;
+       }
+
+       return 0;
+}
 
-static int loose_from_alt_odb(struct alternate_object_database *alt,
-                             void *vdata)
+static int append_loose_object(const struct object_id *oid, const char *path,
+                              void *data)
 {
-       struct loose_alt_odb_data *data = vdata;
+       oid_array_append(data, oid);
+       return 0;
+}
+
+struct oid_array *odb_loose_cache(struct object_directory *odb,
+                                 const struct object_id *oid)
+{
+       int subdir_nr = oid->hash[0];
        struct strbuf buf = STRBUF_INIT;
-       int r;
 
-       strbuf_addstr(&buf, alt->path);
-       r = for_each_loose_file_in_objdir_buf(&buf,
-                                             data->cb, NULL, NULL,
-                                             data->data);
+       if (subdir_nr < 0 ||
+           subdir_nr >= ARRAY_SIZE(odb->loose_objects_subdir_seen))
+               BUG("subdir_nr out of range");
+
+       if (odb->loose_objects_subdir_seen[subdir_nr])
+               return &odb->loose_objects_cache[subdir_nr];
+
+       strbuf_addstr(&buf, odb->path);
+       for_each_file_in_obj_subdir(subdir_nr, &buf,
+                                   append_loose_object,
+                                   NULL, NULL,
+                                   &odb->loose_objects_cache[subdir_nr]);
+       odb->loose_objects_subdir_seen[subdir_nr] = 1;
        strbuf_release(&buf);
-       return r;
+       return &odb->loose_objects_cache[subdir_nr];
 }
 
-int for_each_loose_object(each_loose_object_fn cb, void *data,
-                         enum for_each_object_flags flags)
+void odb_clear_loose_cache(struct object_directory *odb)
 {
-       struct loose_alt_odb_data alt;
-       int r;
-
-       r = for_each_loose_file_in_objdir(get_object_directory(),
-                                         cb, NULL, NULL, data);
-       if (r)
-               return r;
-
-       if (flags & FOR_EACH_OBJECT_LOCAL_ONLY)
-               return 0;
+       int i;
 
-       alt.cb = cb;
-       alt.data = data;
-       return foreach_alt_odb(loose_from_alt_odb, &alt);
+       for (i = 0; i < ARRAY_SIZE(odb->loose_objects_cache); i++)
+               oid_array_clear(&odb->loose_objects_cache[i]);
+       memset(&odb->loose_objects_subdir_seen, 0,
+              sizeof(odb->loose_objects_subdir_seen));
 }
 
 static int check_stream_sha1(git_zstream *stream,
index faa60f69e311f5f09cd5b91a8fbbaf3e3e744ab0..a656481c6aa9fbfe3eeff2367232690208ab8566 100644 (file)
@@ -83,51 +83,25 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
        /* otherwise, current can be discarded and candidate is still good */
 }
 
-static int append_loose_object(const struct object_id *oid, const char *path,
-                              void *data)
-{
-       oid_array_append(data, oid);
-       return 0;
-}
-
 static int match_sha(unsigned, const unsigned char *, const unsigned char *);
 
 static void find_short_object_filename(struct disambiguate_state *ds)
 {
-       int subdir_nr = ds->bin_pfx.hash[0];
-       struct alternate_object_database *alt;
-       static struct alternate_object_database *fakeent;
+       struct object_directory *odb;
 
-       if (!fakeent) {
-               /*
-                * Create a "fake" alternate object database that
-                * points to our own object database, to make it
-                * easier to get a temporary working space in
-                * alt->name/alt->base while iterating over the
-                * object databases including our own.
-                */
-               fakeent = alloc_alt_odb(get_object_directory());
-       }
-       fakeent->next = the_repository->objects->alt_odb_list;
-
-       for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {
+       for (odb = the_repository->objects->odb;
+            odb && !ds->ambiguous;
+            odb = odb->next) {
                int pos;
+               struct oid_array *loose_objects;
 
-               if (!alt->loose_objects_subdir_seen[subdir_nr]) {
-                       struct strbuf *buf = alt_scratch_buf(alt);
-                       for_each_file_in_obj_subdir(subdir_nr, buf,
-                                                   append_loose_object,
-                                                   NULL, NULL,
-                                                   &alt->loose_objects_cache);
-                       alt->loose_objects_subdir_seen[subdir_nr] = 1;
-               }
-
-               pos = oid_array_lookup(&alt->loose_objects_cache, &ds->bin_pfx);
+               loose_objects = odb_loose_cache(odb, &ds->bin_pfx);
+               pos = oid_array_lookup(loose_objects, &ds->bin_pfx);
                if (pos < 0)
                        pos = -1 - pos;
-               while (!ds->ambiguous && pos < alt->loose_objects_cache.nr) {
+               while (!ds->ambiguous && pos < loose_objects->nr) {
                        const struct object_id *oid;
-                       oid = alt->loose_objects_cache.oid + pos;
+                       oid = loose_objects->oid + pos;
                        if (!match_sha(ds->len, ds->bin_pfx.hash, oid->hash))
                                break;
                        update_candidates(ds, oid);
index 368647acf8c04decee14ceea2f03c535a206ad18..7c3d33d3f87965fc96720ad47674a81a804f43dd 100644 (file)
@@ -87,7 +87,7 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
                struct keyword_entry *p = keywords + i;
                int len = strlen(p->keyword);
 
-               if (n <= len)
+               if (n < len)
                        continue;
                /*
                 * Match case insensitively, so we colorize output from existing
@@ -95,7 +95,8 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
                 * messages. We only highlight the word precisely, so
                 * "successful" stays uncolored.
                 */
-               if (!strncasecmp(p->keyword, src, len) && !isalnum(src[len])) {
+               if (!strncasecmp(p->keyword, src, len) &&
+                   (len == n || !isalnum(src[len]))) {
                        strbuf_addstr(dest, p->color);
                        strbuf_add(dest, src, len);
                        strbuf_addstr(dest, GIT_COLOR_RESET);
index 1f6063f2a27812ee27b5d510dc066249198b48e3..a917955fbd8d18956ae593b5fa190042e13db644 100644 (file)
@@ -155,7 +155,8 @@ static int item_is_not_empty(struct string_list_item *item, void *unused)
        return *item->string != '\0';
 }
 
-void string_list_remove_empty_items(struct string_list *list, int free_util) {
+void string_list_remove_empty_items(struct string_list *list, int free_util)
+{
        filter_string_list(list, free_util, item_is_not_empty, NULL);
 }
 
index 6415cc55807c7ed9ee4cbcaa57f41a5804b6e854..d393e947e699bb1d5764f42e94919218496a138d 100644 (file)
@@ -1561,6 +1561,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();
@@ -1726,6 +1738,8 @@ int submodule_move_head(const char *path,
 
                        if (is_empty_dir(path))
                                rmdir_or_warn(path);
+
+                       submodule_unset_core_worktree(sub);
                }
        }
 out:
index a680214c01a5fda90a21af547389f6333388683c..9e18e9b80760ad1562682125bc90d08fb6e1c0d3 100644 (file)
@@ -131,6 +131,8 @@ int submodule_move_head(const char *path,
                        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
index 5261e8cf499006c1d84fc42a3e96e4dee7f09ba1..69d458a24d531be606bb43d360a9020d530557c8 100644 (file)
@@ -221,7 +221,7 @@ int has_symlink_leading_path(const char *name, int len)
  */
 int check_leading_path(const char *name, int len)
 {
-    return threaded_check_leading_path(&default_cache, name, len);
+       return threaded_check_leading_path(&default_cache, name, len);
 }
 
 /*
index e7acedabe17f033d4205613c9af50152e5cec126..df05434d32cc1fa720d5408c26c22371d1f0e9e8 100644 (file)
@@ -16,6 +16,7 @@ t[0-9][0-9][0-9][0-9]/* -whitespace
 /t4135/* eol=lf
 /t4211/* eol=lf
 /t4252/* eol=lf
+/t4256/1/* eol=lf
 /t5100/* eol=lf
 /t5515/* eol=lf
 /t556x_common eol=lf
index b45bdac688c40104dd42ef68a07690420d96c142..8037eef7777b4f65af44b3c8cc3e4b46d48259ae 100755 (executable)
@@ -35,6 +35,7 @@ sub err {
                chomp;
        }
 
+       /\bcp\s+-a/ and err 'cp -a is not portable';
        /\bsed\s+-i/ and err 'sed -i is not portable';
        /\becho\s+-[neE]/ and err 'echo with option is not portable (use printf)';
        /^\s*declare\s+/ and err 'arrays/declare not portable';
index 77ac5bc33f8eb635f78d8ba590c23bbbe4f29636..d013bccddaebd9c7fb0eb4b4c4e1be0643f82260 100644 (file)
@@ -14,7 +14,8 @@ X(two)
 X(three)
 #undef X
 
-int cmd__sigchain(int argc, const char **argv) {
+int cmd__sigchain(int argc, const char **argv)
+{
        sigchain_push(SIGTERM, one);
        sigchain_push(SIGTERM, two);
        sigchain_push(SIGTERM, three);
index 41eb1e3ae85b2601578bc4684ae806436ca315fd..79db3b7ae513c01b07422ed1a8d95f9f5b285cb5 100644 (file)
@@ -54,19 +54,11 @@ start_git_daemon() {
                "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
                >&3 2>git_daemon_output &
        GIT_DAEMON_PID=$!
-       >daemon.log
        {
                read -r line <&7
-               printf "%s\n" "$line"
-               printf >&4 "%s\n" "$line"
-               (
-                       while read -r line <&7
-                       do
-                               printf "%s\n" "$line"
-                               printf >&4 "%s\n" "$line"
-                       done
-               ) &
-       } 7<git_daemon_output >>"$TRASH_DIRECTORY/daemon.log" &&
+               printf "%s\n" "$line" >&4
+               cat <&7 >&4 &
+       } 7<git_daemon_output &&
 
        # Check expected output
        if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
index 016391723c09491e53ebf4e0b69972783c7bc491..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.
index beb5927f77f7f21456eef2835ee67402e487a899..3587e454f19d9bf71f2b02c9189d4715ed216fd9 100755 (executable)
@@ -293,9 +293,9 @@ checkout_files () {
        do
                rm crlf_false_attr__$f.txt &&
                if test -z "$ceol"; then
-                       git checkout crlf_false_attr__$f.txt
+                       git checkout -- crlf_false_attr__$f.txt
                else
-                       git -c core.eol=$ceol checkout crlf_false_attr__$f.txt
+                       git -c core.eol=$ceol checkout -- crlf_false_attr__$f.txt
                fi
        done
 
index 5ce47e8af51d63c7bd294e6f7582f10e4891566d..0c24a0f9a377103f49fa7cb749a5657058da3490 100755 (executable)
@@ -430,9 +430,15 @@ test_expect_success '-c with changed comment char' '
 test_expect_success '-c with comment char defined in .git/config' '
        test_config core.commentchar = &&
        printf "= foo\n" >expect &&
-       printf "foo" | (
-               mkdir sub && cd sub && git stripspace -c
-       ) >actual &&
+       rm -fr sub &&
+       mkdir sub &&
+       printf "foo" | git -C sub stripspace -c >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '-c outside git repository' '
+       printf "# foo\n" >expect &&
+       printf "foo" | nongit git stripspace -c >actual &&
        test_cmp expect actual
 '
 
index f5b10861c498e435155f6aec5dec6f27c82aa51b..b8f366c4420f47d913b1d830037d846e4e443074 100755 (executable)
@@ -227,7 +227,7 @@ EOF
 test_expect_success 'detect possible typos' '
        test_must_fail test-tool parse-options -boolean >output 2>output.err &&
        test_must_be_empty output &&
-       test_cmp typo.err output.err
+       test_i18ncmp typo.err output.err
 '
 
 cat >typo.err <<\EOF
@@ -237,7 +237,7 @@ EOF
 test_expect_success 'detect possible typos' '
        test_must_fail test-tool parse-options -ambiguous >output 2>output.err &&
        test_must_be_empty output &&
-       test_cmp typo.err output.err
+       test_i18ncmp typo.err output.err
 '
 
 test_expect_success 'keep some options as arguments' '
index cf932c851411e5abd992005de474cc095abecead..99a614bc7c45ca792c7bbce7d16f793ab6107896 100755 (executable)
@@ -13,11 +13,13 @@ cat >hello-script <<-EOF
 EOF
 
 test_expect_success 'start_command reports ENOENT (slash)' '
-       test-tool run-command start-command-ENOENT ./does-not-exist
+       test-tool run-command start-command-ENOENT ./does-not-exist 2>err &&
+       test_i18ngrep "\./does-not-exist" err
 '
 
 test_expect_success 'start_command reports ENOENT (no slash)' '
-       test-tool run-command start-command-ENOENT does-not-exist
+       test-tool run-command start-command-ENOENT does-not-exist 2>err &&
+       test_i18ngrep "does-not-exist" err
 '
 
 test_expect_success 'run_command can run a command' '
@@ -29,11 +31,20 @@ test_expect_success 'run_command can run a command' '
        test_must_be_empty err
 '
 
-test_expect_success 'run_command is restricted to PATH' '
+
+test_lazy_prereq RUNS_COMMANDS_FROM_PWD '
+       write_script runs-commands-from-pwd <<-\EOF &&
+       true
+       EOF
+       runs-commands-from-pwd >/dev/null 2>&1
+'
+
+test_expect_success !RUNS_COMMANDS_FROM_PWD 'run_command is restricted to PATH' '
        write_script should-not-run <<-\EOF &&
        echo yikes
        EOF
-       test_must_fail test-tool run-command run-command should-not-run
+       test_must_fail test-tool run-command run-command should-not-run 2>err &&
+       test_i18ngrep "should-not-run" err
 '
 
 test_expect_success !MINGW 'run_command can run a script without a #! line' '
index 0aca8d7588cbb6b6cf0c2798525df53315941fb3..bce02788e6e1b03b87911fb13594e0cf6f80fdab 100755 (executable)
@@ -349,7 +349,7 @@ test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob
        grep $(git -C repo rev-parse bar) out  # sanity check that some walking was done
 '
 
-test_expect_success 'rev-list accepts missing and promised objects on command line' '
+test_expect_success 'rev-list dies for missing objects on cmd line' '
        rm -rf repo &&
        test_create_repo repo &&
        test_commit -C repo foo &&
@@ -366,7 +366,19 @@ test_expect_success 'rev-list accepts missing and promised objects on command li
 
        git -C repo config core.repositoryformatversion 1 &&
        git -C repo config extensions.partialclone "arbitrary string" &&
-       git -C repo rev-list --exclude-promisor-objects --objects "$COMMIT" "$TREE" "$BLOB"
+
+       for OBJ in "$COMMIT" "$TREE" "$BLOB"; do
+               test_must_fail git -C repo rev-list --objects \
+                       --exclude-promisor-objects "$OBJ" &&
+               test_must_fail git -C repo rev-list --objects-edge-aggressive \
+                       --exclude-promisor-objects "$OBJ" &&
+
+               # Do not die or crash when --ignore-missing is passed.
+               git -C repo rev-list --ignore-missing --objects \
+                       --exclude-promisor-objects "$OBJ" &&
+               git -C repo rev-list --ignore-missing --objects-edge-aggressive \
+                       --exclude-promisor-objects "$OBJ"
+       done
 '
 
 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
index 3e053532eb8df817e216532c807eba0ba549e8c3..ae8a448e34356034a88fcf0799ef2f53e55f73b8 100755 (executable)
@@ -20,12 +20,12 @@ check_have () {
 }
 
 check_fsck () {
-       output=$(git fsck --full)
+       git fsck --full >fsck.output
        case "$1" in
        '')
-               test -z "$output" ;;
+               test_must_be_empty fsck.output ;;
        *)
-               echo "$output" | grep "$1" ;;
+               test_i18ngrep "$1" fsck.output ;;
        esac
 }
 
index e20e8fa8301607b94cff7c42e83545f072d5191f..2e5e979336c5c67bf59667bbf5e0183b632ea2da 100755 (executable)
@@ -70,7 +70,7 @@ test_expect_success 'object with bad sha1' '
 
        test_must_fail git fsck 2>out &&
        cat out &&
-       grep "$sha.*corrupt" out
+       test_i18ngrep "$sha.*corrupt" out
 '
 
 test_expect_success 'branch pointing to non-commit' '
@@ -78,7 +78,7 @@ test_expect_success 'branch pointing to non-commit' '
        test_when_finished "git update-ref -d refs/heads/invalid" &&
        test_must_fail git fsck 2>out &&
        cat out &&
-       grep "not a commit" out
+       test_i18ngrep "not a commit" out
 '
 
 test_expect_success 'HEAD link pointing at a funny object' '
@@ -88,7 +88,7 @@ test_expect_success 'HEAD link pointing at a funny object' '
        # avoid corrupt/broken HEAD from interfering with repo discovery
        test_must_fail env GIT_DIR=.git git fsck 2>out &&
        cat out &&
-       grep "detached HEAD points" out
+       test_i18ngrep "detached HEAD points" out
 '
 
 test_expect_success 'HEAD link pointing at a funny place' '
@@ -98,7 +98,7 @@ test_expect_success 'HEAD link pointing at a funny place' '
        # avoid corrupt/broken HEAD from interfering with repo discovery
        test_must_fail env GIT_DIR=.git git fsck 2>out &&
        cat out &&
-       grep "HEAD points to something strange" out
+       test_i18ngrep "HEAD points to something strange" out
 '
 
 test_expect_success 'HEAD link pointing at a funny object (from different wt)' '
@@ -109,7 +109,7 @@ test_expect_success 'HEAD link pointing at a funny object (from different wt)' '
        echo $ZERO_OID >.git/HEAD &&
        # avoid corrupt/broken HEAD from interfering with repo discovery
        test_must_fail git -C wt fsck 2>out &&
-       grep "main-worktree/HEAD: detached HEAD points" out
+       test_i18ngrep "main-worktree/HEAD: detached HEAD points" out
 '
 
 test_expect_success 'other worktree HEAD link pointing at a funny object' '
@@ -117,7 +117,7 @@ test_expect_success 'other worktree HEAD link pointing at a funny object' '
        git worktree add other &&
        echo $ZERO_OID >.git/worktrees/other/HEAD &&
        test_must_fail git fsck 2>out &&
-       grep "worktrees/other/HEAD: detached HEAD points" out
+       test_i18ngrep "worktrees/other/HEAD: detached HEAD points" out
 '
 
 test_expect_success 'other worktree HEAD link pointing at missing object' '
@@ -125,7 +125,7 @@ test_expect_success 'other worktree HEAD link pointing at missing object' '
        git worktree add other &&
        echo "Contents missing from repo" | git hash-object --stdin >.git/worktrees/other/HEAD &&
        test_must_fail git fsck 2>out &&
-       grep "worktrees/other/HEAD: invalid sha1 pointer" out
+       test_i18ngrep "worktrees/other/HEAD: invalid sha1 pointer" out
 '
 
 test_expect_success 'other worktree HEAD link pointing at a funny place' '
@@ -133,7 +133,7 @@ test_expect_success 'other worktree HEAD link pointing at a funny place' '
        git worktree add other &&
        echo "ref: refs/funny/place" >.git/worktrees/other/HEAD &&
        test_must_fail git fsck 2>out &&
-       grep "worktrees/other/HEAD points to something strange" out
+       test_i18ngrep "worktrees/other/HEAD points to something strange" out
 '
 
 test_expect_success 'email without @ is okay' '
@@ -157,7 +157,7 @@ test_expect_success 'email with embedded > is not okay' '
        test_when_finished "git update-ref -d refs/heads/bogus" &&
        test_must_fail git fsck 2>out &&
        cat out &&
-       grep "error in commit $new" out
+       test_i18ngrep "error in commit $new" out
 '
 
 test_expect_success 'missing < email delimiter is reported nicely' '
@@ -169,7 +169,7 @@ test_expect_success 'missing < email delimiter is reported nicely' '
        test_when_finished "git update-ref -d refs/heads/bogus" &&
        test_must_fail git fsck 2>out &&
        cat out &&
-       grep "error in commit $new.* - bad name" out
+       test_i18ngrep "error in commit $new.* - bad name" out
 '
 
 test_expect_success 'missing email is reported nicely' '
@@ -181,7 +181,7 @@ test_expect_success 'missing email is reported nicely' '
        test_when_finished "git update-ref -d refs/heads/bogus" &&
        test_must_fail git fsck 2>out &&
        cat out &&
-       grep "error in commit $new.* - missing email" out
+       test_i18ngrep "error in commit $new.* - missing email" out
 '
 
 test_expect_success '> in name is reported' '
@@ -193,7 +193,7 @@ test_expect_success '> in name is reported' '
        test_when_finished "git update-ref -d refs/heads/bogus" &&
        test_must_fail git fsck 2>out &&
        cat out &&
-       grep "error in commit $new" out
+       test_i18ngrep "error in commit $new" out
 '
 
 # date is 2^64 + 1
@@ -207,7 +207,7 @@ test_expect_success 'integer overflow in timestamps is reported' '
        test_when_finished "git update-ref -d refs/heads/bogus" &&
        test_must_fail git fsck 2>out &&
        cat out &&
-       grep "error in commit $new.*integer overflow" out
+       test_i18ngrep "error in commit $new.*integer overflow" out
 '
 
 test_expect_success 'commit with NUL in header' '
@@ -219,7 +219,7 @@ test_expect_success 'commit with NUL in header' '
        test_when_finished "git update-ref -d refs/heads/bogus" &&
        test_must_fail git fsck 2>out &&
        cat out &&
-       grep "error in commit $new.*unterminated header: NUL at offset" out
+       test_i18ngrep "error in commit $new.*unterminated header: NUL at offset" out
 '
 
 test_expect_success 'tree object with duplicate entries' '
@@ -240,7 +240,7 @@ test_expect_success 'tree object with duplicate entries' '
                git hash-object -w -t tree --stdin
        ) &&
        test_must_fail git fsck 2>out &&
-       grep "error in tree .*contains duplicate file entries" out
+       test_i18ngrep "error in tree .*contains duplicate file entries" out
 '
 
 test_expect_success 'unparseable tree object' '
@@ -294,7 +294,7 @@ test_expect_success 'tag pointing to nonexistent' '
        test_when_finished "git update-ref -d refs/tags/invalid" &&
        test_must_fail git fsck --tags >out &&
        cat out &&
-       grep "broken link" out
+       test_i18ngrep "broken link" out
 '
 
 test_expect_success 'tag pointing to something else than its type' '
@@ -336,7 +336,7 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
        warning in tag $tag: badTagName: invalid '\''tag'\'' name: wrong name format
        warning in tag $tag: missingTaggerEntry: invalid format - expected '\''tagger'\'' line
        EOF
-       test_cmp expect out
+       test_i18ncmp expect out
 '
 
 test_expect_success 'tag with bad tagger' '
@@ -355,7 +355,7 @@ test_expect_success 'tag with bad tagger' '
        echo $tag >.git/refs/tags/wrong &&
        test_when_finished "git update-ref -d refs/tags/wrong" &&
        test_must_fail git fsck --tags 2>out &&
-       grep "error in tag .*: invalid author/committer" out
+       test_i18ngrep "error in tag .*: invalid author/committer" out
 '
 
 test_expect_success 'tag with NUL in header' '
@@ -375,7 +375,7 @@ test_expect_success 'tag with NUL in header' '
        test_when_finished "git update-ref -d refs/tags/wrong" &&
        test_must_fail git fsck --tags 2>out &&
        cat out &&
-       grep "error in tag $tag.*unterminated header: NUL at offset" out
+       test_i18ngrep "error in tag $tag.*unterminated header: NUL at offset" out
 '
 
 test_expect_success 'cleaned up' '
@@ -431,7 +431,7 @@ test_expect_success 'fsck notices blob entry pointing to null sha1' '
               git hash-object -w --stdin -t tree) &&
          git fsck 2>out &&
          cat out &&
-         grep "warning.*null sha1" out
+         test_i18ngrep "warning.*null sha1" out
        )
 '
 
@@ -442,7 +442,7 @@ test_expect_success 'fsck notices submodule entry pointing to null sha1' '
               git hash-object -w --stdin -t tree) &&
          git fsck 2>out &&
          cat out &&
-         grep "warning.*null sha1" out
+         test_i18ngrep "warning.*null sha1" out
        )
 '
 
@@ -463,7 +463,7 @@ while read name path pretty; do
                        bad_tree=$(git mktree <bad) &&
                        git fsck 2>out &&
                        cat out &&
-                       grep "warning.*tree $bad_tree" out
+                       test_i18ngrep "warning.*tree $bad_tree" out
                )'
        done <<-\EOF
        100644 blob
@@ -509,9 +509,9 @@ test_expect_success 'NUL in commit' '
                git branch bad $(cat name) &&
 
                test_must_fail git -c fsck.nulInCommit=error fsck 2>warn.1 &&
-               grep nulInCommit warn.1 &&
+               test_i18ngrep nulInCommit warn.1 &&
                git fsck 2>warn.2 &&
-               grep nulInCommit warn.2
+               test_i18ngrep nulInCommit warn.2
        )
 '
 
@@ -629,7 +629,7 @@ test_expect_success 'fsck --name-objects' '
                remove_object $(git rev-parse julius:caesar.t) &&
                test_must_fail git fsck --name-objects >out &&
                tree=$(git rev-parse --verify julius:) &&
-               egrep "$tree \((refs/heads/master|HEAD)@\{[0-9]*\}:" out
+               test_i18ngrep -E "$tree \((refs/heads/master|HEAD)@\{[0-9]*\}:" out
        )
 '
 
@@ -640,7 +640,7 @@ test_expect_success 'alternate objects are correctly blamed' '
        mkdir alt.git/objects/12 &&
        >alt.git/objects/12/34567890123456789012345678901234567890 &&
        test_must_fail git fsck >out 2>&1 &&
-       grep alt.git out
+       test_i18ngrep alt.git out
 '
 
 test_expect_success 'fsck errors in packed objects' '
@@ -659,8 +659,8 @@ test_expect_success 'fsck errors in packed objects' '
        remove_object $one &&
        remove_object $two &&
        test_must_fail git fsck 2>out &&
-       grep "error in commit $one.* - bad name" out &&
-       grep "error in commit $two.* - bad name" out &&
+       test_i18ngrep "error in commit $one.* - bad name" out &&
+       test_i18ngrep "error in commit $two.* - bad name" out &&
        ! grep corrupt out
 '
 
@@ -760,7 +760,7 @@ test_expect_success 'fsck notices dangling objects' '
                git fsck >actual &&
                # the output order is non-deterministic, as it comes from a hash
                sort <actual >actual.sorted &&
-               test_cmp expect actual.sorted
+               test_i18ncmp expect actual.sorted
        )
 '
 
@@ -808,7 +808,7 @@ test_expect_success 'detect corrupt index file in fsck' '
        test_when_finished "mv .git/index.backup .git/index" &&
        corrupt_index_checksum &&
        test_must_fail git fsck --cache 2>errors &&
-       grep "bad index file" errors
+       test_i18ngrep "bad index file" errors
 '
 
 test_done
index 69b6774d10a9d90790316e9feb0f718593465c76..fa0718c730c322bfe5f9e6642c4136a7533be5dc 100755 (executable)
@@ -278,4 +278,35 @@ test_expect_success 'loosely defined local base branch is reported correctly' '
        test_cmp expect actual
 '
 
+test_expect_success 'reject when arg could be part of dwim branch' '
+       git remote add foo file://non-existent-place &&
+       git update-ref refs/remotes/foo/dwim-arg HEAD &&
+       echo foo >dwim-arg &&
+       git add dwim-arg &&
+       echo bar >dwim-arg &&
+       test_must_fail git checkout dwim-arg &&
+       test_must_fail git rev-parse refs/heads/dwim-arg -- &&
+       grep bar dwim-arg
+'
+
+test_expect_success 'disambiguate dwim branch and checkout path (1)' '
+       git update-ref refs/remotes/foo/dwim-arg1 HEAD &&
+       echo foo >dwim-arg1 &&
+       git add dwim-arg1 &&
+       echo bar >dwim-arg1 &&
+       git checkout -- dwim-arg1 &&
+       test_must_fail git rev-parse refs/heads/dwim-arg1 -- &&
+       grep foo dwim-arg1
+'
+
+test_expect_success 'disambiguate dwim branch and checkout path (2)' '
+       git update-ref refs/remotes/foo/dwim-arg2 HEAD &&
+       echo foo >dwim-arg2 &&
+       git add dwim-arg2 &&
+       echo bar >dwim-arg2 &&
+       git checkout dwim-arg2 -- &&
+       git rev-parse refs/heads/dwim-arg2 -- &&
+       grep bar dwim-arg2
+'
+
 test_done
index 33c033773367a135d4cb7eb23f9e9d3131197174..939d18d7286c1be1e58a698e9164fda8e24c654a 100755 (executable)
@@ -112,6 +112,26 @@ test_expect_success 'move locked worktree (force)' '
        git worktree move --force --force flump ploof
 '
 
+test_expect_success 'move a repo with uninitialized submodule' '
+       git init withsub &&
+       (
+               cd withsub &&
+               test_commit initial &&
+               git submodule add "$PWD"/.git sub &&
+               git commit -m withsub &&
+               git worktree add second HEAD &&
+               git worktree move second third
+       )
+'
+
+test_expect_success 'not move a repo with initialized submodule' '
+       (
+               cd withsub &&
+               git -C third submodule update &&
+               test_must_fail git worktree move third forth
+       )
+'
+
 test_expect_success 'remove main worktree' '
        test_must_fail git worktree remove .
 '
@@ -185,4 +205,21 @@ test_expect_success 'remove cleans up .git/worktrees when empty' '
        )
 '
 
+test_expect_success 'remove a repo with uninitialized submodule' '
+       (
+               cd withsub &&
+               git worktree add to-remove HEAD &&
+               git worktree remove to-remove
+       )
+'
+
+test_expect_success 'not remove a repo with initialized submodule' '
+       (
+               cd withsub &&
+               git worktree add to-remove HEAD &&
+               git -C to-remove submodule update &&
+               test_must_fail git worktree remove to-remove
+       )
+'
+
 test_done
index b1602718f85468d17faa1cc0d7ae8854ac2f5407..8b635a196d5cc57016520466b92b5f439b217a9d 100755 (executable)
@@ -40,12 +40,12 @@ test_expect_success 'cherry-pick -m complains of bogus numbers' '
        test_expect_code 129 git cherry-pick -m 0 b
 '
 
-test_expect_success 'cherry-pick a non-merge with -m should fail' '
+test_expect_success 'cherry-pick explicit first parent of a non-merge' '
 
        git reset --hard &&
        git checkout a^0 &&
-       test_expect_code 128 git cherry-pick -m 1 b &&
-       git diff --exit-code a --
+       git cherry-pick -m 1 b &&
+       git diff --exit-code c --
 
 '
 
@@ -84,12 +84,12 @@ test_expect_success 'cherry pick a merge relative to nonexistent parent should f
 
 '
 
-test_expect_success 'revert a non-merge with -m should fail' '
+test_expect_success 'revert explicit first parent of a non-merge' '
 
        git reset --hard &&
        git checkout c^0 &&
-       test_must_fail git revert -m 1 b &&
-       git diff --exit-code c
+       git revert -m 1 b &&
+       git diff --exit-code a --
 
 '
 
index fb889ac6f05a3243b09fbb7ec05356ed61ff9cb0..127dd0082ff8f535eeb8dee93095cf1ce13f3a95 100755 (executable)
@@ -64,10 +64,10 @@ test_expect_success 'merge setup' '
        git checkout -b new A
 '
 
-test_expect_success 'cherry-pick a non-merge with --ff and -m should fail' '
+test_expect_success 'cherry-pick explicit first parent of a non-merge with --ff' '
        git reset --hard A -- &&
-       test_must_fail git cherry-pick --ff -m 1 B &&
-       git diff --exit-code A --
+       git cherry-pick --ff -m 1 B &&
+       git diff --exit-code C --
 '
 
 test_expect_success 'cherry pick a merge with --ff but without -m should fail' '
index c84eeefdc9ae0fc0bd5f91cf3eb1a51a6c7d34a2..941d5026da2adc857fa332f899ea3594876a550c 100755 (executable)
@@ -61,7 +61,11 @@ test_expect_success 'cherry-pick mid-cherry-pick-sequence' '
 
 test_expect_success 'cherry-pick persists opts correctly' '
        pristine_detach initial &&
-       test_expect_code 128 git cherry-pick -s -m 1 --strategy=recursive -X patience -X ours initial..anotherpick &&
+       # to make sure that the session to cherry-pick a sequence
+       # gets interrupted, use a high-enough number that is larger
+       # than the number of parents of any commit we have created
+       mainline=4 &&
+       test_expect_code 128 git cherry-pick -s -m $mainline --strategy=recursive -X patience -X ours initial..anotherpick &&
        test_path_is_dir .git/sequencer &&
        test_path_is_file .git/sequencer/head &&
        test_path_is_file .git/sequencer/todo &&
@@ -69,7 +73,7 @@ test_expect_success 'cherry-pick persists opts correctly' '
        echo "true" >expect &&
        git config --file=.git/sequencer/opts --get-all options.signoff >actual &&
        test_cmp expect actual &&
-       echo "1" >expect &&
+       echo "$mainline" >expect &&
        git config --file=.git/sequencer/opts --get-all options.mainline >actual &&
        test_cmp expect actual &&
        echo "recursive" >expect &&
index cd216655b97b852eec963916e796d11d32eb976a..5f8272b6f94b513b250575c6e99e4f76d6b08e75 100755 (executable)
@@ -1096,4 +1096,32 @@ test_expect_success 'stash -- <subdir> works with binary files' '
        test_path_is_file subdir/untracked
 '
 
+test_expect_success 'stash works when user.name and user.email are not set' '
+       git reset &&
+       >1 &&
+       git add 1 &&
+       echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect &&
+       git stash &&
+       git show -s --format="%an <%ae>" refs/stash >actual &&
+       test_cmp expect actual &&
+       >2 &&
+       git add 2 &&
+       test_config user.useconfigonly true &&
+       test_config stash.usebuiltin true &&
+       (
+               sane_unset GIT_AUTHOR_NAME &&
+               sane_unset GIT_AUTHOR_EMAIL &&
+               sane_unset GIT_COMMITTER_NAME &&
+               sane_unset GIT_COMMITTER_EMAIL &&
+               test_unconfig user.email &&
+               test_unconfig user.name &&
+               test_must_fail git commit -m "should fail" &&
+               echo "git stash <git@stash>" >expect &&
+               >2 &&
+               git stash &&
+               git show -s --format="%an <%ae>" refs/stash >actual &&
+               test_cmp expect actual
+       )
+'
+
 test_done
index a9fb226c5ad566095163c5141a4ca591f2aeacb1..9a3e4fdfecef4fa00d12b6ff32fc5b0beaff089e 100755 (executable)
@@ -1890,6 +1890,24 @@ test_expect_success 'compare whitespace delta across moved blocks' '
        test_cmp expected actual
 '
 
+test_expect_success 'bogus settings in move detection erroring out' '
+       test_must_fail git diff --color-moved=bogus 2>err &&
+       test_i18ngrep "must be one of" err &&
+       test_i18ngrep bogus err &&
+
+       test_must_fail git -c diff.colormoved=bogus diff 2>err &&
+       test_i18ngrep "must be one of" err &&
+       test_i18ngrep "from command-line config" err &&
+
+       test_must_fail git diff --color-moved-ws=bogus 2>err &&
+       test_i18ngrep "possible values" err &&
+       test_i18ngrep bogus err &&
+
+       test_must_fail git -c diff.colormovedws=bogus diff 2>err &&
+       test_i18ngrep "possible values" err &&
+       test_i18ngrep "from command-line config" err
+'
+
 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 \
index 844df760f7d1c2b1b25eb01fada039efd0354711..5d06f5f45eace6010c1a003e03a814b5ba03f324 100755 (executable)
@@ -106,4 +106,39 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
        rm .gitattributes
 '
 
+test_expect_success 'setup log -[GS] binary & --text' '
+       git checkout --orphan GS-binary-and-text &&
+       git read-tree --empty &&
+       printf "a\na\0a\n" >data.bin &&
+       git add data.bin &&
+       git commit -m "create binary file" data.bin &&
+       printf "a\na\0a\n" >>data.bin &&
+       git commit -m "modify binary file" data.bin &&
+       git rm data.bin &&
+       git commit -m "delete binary file" data.bin &&
+       git log >full-log
+'
+
+test_expect_success 'log -G ignores binary files' '
+       git log -Ga >log &&
+       test_must_be_empty log
+'
+
+test_expect_success 'log -G looks into binary files with -a' '
+       git log -a -Ga >log &&
+       test_cmp log full-log
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+       test_when_finished "rm .gitattributes" &&
+       echo "* diff=bin" >.gitattributes &&
+       git -c diff.bin.textconv=cat log -Ga >log &&
+       test_cmp log full-log
+'
+
+test_expect_success 'log -S looks into binary files' '
+       git log -Sa >log &&
+       test_cmp log full-log
+'
+
 test_done
index ef1322148e1413e4b90f46b6bea4f2d9b0300189..bd5fe4d1483005175d9c2211dee1901c2b132573 100755 (executable)
@@ -25,7 +25,7 @@ canned_test_failure () {
 test_bad_opts () {
        test_expect_success "invalid args: $1" "
                test_must_fail git log $1 2>errors &&
-               grep '$2' errors
+               test_i18ngrep '$2' errors
        "
 }
 
index ced44355cab99fc4f5fd9768daf10f5a2c1b21c7..271eb5a1fdfbfe4aab216271fc1897968283639d 100755 (executable)
@@ -3,8 +3,12 @@
 test_description='test corner cases of git-archive'
 . ./test-lib.sh
 
-test_expect_success 'create commit with empty tree' '
-       git commit --allow-empty -m foo
+# the 10knuls.tar file is used to test for an empty git generated tar
+# without having to invoke tar because an otherwise valid empty GNU tar
+# will be considered broken by {Open,Net}BSD tar
+test_expect_success 'create commit with empty tree and fake empty tar' '
+       git commit --allow-empty -m foo &&
+       perl -e "print \"\\0\" x 10240" >10knuls.tar
 '
 
 # Make a dir and clean it up afterwards
@@ -47,7 +51,6 @@ test_expect_success HEADER_ONLY_TAR_OK 'tar archive of commit with empty tree' '
 
 test_expect_success 'tar archive of empty tree is empty' '
        git archive --format=tar HEAD: >empty.tar &&
-       perl -e "print \"\\0\" x 10240" >10knuls.tar &&
        test_cmp_bin 10knuls.tar empty.tar
 '
 
@@ -106,16 +109,12 @@ test_expect_success 'create a commit with an empty subtree' '
 
 test_expect_success 'archive empty subtree with no pathspec' '
        git archive --format=tar $root_tree >subtree-all.tar &&
-       make_dir extract &&
-       "$TAR" xf subtree-all.tar -C extract &&
-       check_dir extract
+       test_cmp_bin 10knuls.tar subtree-all.tar
 '
 
 test_expect_success 'archive empty subtree by direct pathspec' '
        git archive --format=tar $root_tree -- sub >subtree-path.tar &&
-       make_dir extract &&
-       "$TAR" xf subtree-path.tar -C extract &&
-       check_dir extract
+       test_cmp_bin 10knuls.tar subtree-path.tar
 '
 
 ZIPINFO=zipinfo
index f81b6813c03090fe932852f86ce4b3517c914d7a..2a8c4496618523ebdbd03eb152a1e8189fafcd0a 100755 (executable)
@@ -17,6 +17,7 @@ test_expect_success 'setup' '
        echo " " "error: leading space"
        echo "    "
        echo Err
+       echo SUCCESS
        exit 0
        EOF
        echo 1 >file &&
@@ -35,6 +36,7 @@ test_expect_success 'keywords' '
        grep "<BOLD;RED>error<RESET>: error" decoded &&
        grep "<YELLOW>hint<RESET>:" decoded &&
        grep "<BOLD;GREEN>success<RESET>:" decoded &&
+       grep "<BOLD;GREEN>SUCCESS<RESET>" decoded &&
        grep "<BOLD;YELLOW>warning<RESET>:" decoded
 '
 
index d2a2cdd453396b1dba5525f32b6325ac8a10d95d..883b32efa024d97ac74e9ae5763dc8a218251675 100755 (executable)
@@ -1222,4 +1222,59 @@ test_expect_success 'add remote matching the "insteadOf" URL' '
        git remote add backup xyz@example.com
 '
 
+test_expect_success 'unqualified <dst> refspec DWIM and advice' '
+       test_when_finished "(cd test && git tag -d some-tag)" &&
+       (
+               cd test &&
+               git tag -a -m "Some tag" some-tag master &&
+               exit_with=true &&
+               for type in commit tag tree blob
+               do
+                       if test "$type" = "blob"
+                       then
+                               oid=$(git rev-parse some-tag:file)
+                       else
+                               oid=$(git rev-parse some-tag^{$type})
+                       fi &&
+                       test_must_fail git push origin $oid:dst 2>err &&
+                       test_i18ngrep "error: The destination you" err &&
+                       test_i18ngrep "hint: Did you mean" err &&
+                       test_must_fail git -c advice.pushUnqualifiedRefName=false \
+                               push origin $oid:dst 2>err &&
+                       test_i18ngrep "error: The destination you" err &&
+                       test_i18ngrep ! "hint: Did you mean" err ||
+                       exit_with=false
+               done &&
+               $exit_with
+       )
+'
+
+test_expect_success 'refs/remotes/* <src> refspec and unqualified <dst> DWIM and advice' '
+       (
+               cd two &&
+               git tag -a -m "Some tag" my-tag master &&
+               git update-ref refs/trees/my-head-tree HEAD^{tree} &&
+               git update-ref refs/blobs/my-file-blob HEAD:file
+       ) &&
+       (
+               cd test &&
+               git config --add remote.two.fetch "+refs/tags/*:refs/remotes/tags-from-two/*" &&
+               git config --add remote.two.fetch "+refs/trees/*:refs/remotes/trees-from-two/*" &&
+               git config --add remote.two.fetch "+refs/blobs/*:refs/remotes/blobs-from-two/*" &&
+               git fetch --no-tags two &&
+
+               test_must_fail git push origin refs/remotes/two/another:dst 2>err &&
+               test_i18ngrep "error: The destination you" err &&
+
+               test_must_fail git push origin refs/remotes/tags-from-two/my-tag:dst-tag 2>err &&
+               test_i18ngrep "error: The destination you" err &&
+
+               test_must_fail git push origin refs/remotes/trees-from-two/my-head-tree:dst-tree 2>err &&
+               test_i18ngrep "error: The destination you" err &&
+
+               test_must_fail git push origin refs/remotes/blobs-from-two/my-file-blob:dst-blob 2>err &&
+               test_i18ngrep "error: The destination you" err
+       )
+'
+
 test_done
index 6c2f9b2ba266ad910769745e72285a840b33238b..a0317556c690262e26ed99cd902ec30c8adda733 100755 (executable)
@@ -524,6 +524,8 @@ test_expect_success 'fetching submodules respects parallel settings' '
        git config fetch.recurseSubmodules true &&
        (
                cd downstream &&
+               GIT_TRACE=$(pwd)/trace.out git fetch &&
+               grep "1 tasks" trace.out &&
                GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
                grep "7 tasks" trace.out &&
                git config submodule.fetchJobs 8 &&
index 7466aad111fe4ef11b97d05a9616f8530993c288..58ee7876853161087c256e56e687f0b341fde915 100755 (executable)
@@ -183,19 +183,6 @@ test_expect_success 'hostname cannot break out of directory' '
                git ls-remote "$GIT_DAEMON_URL/escape.git"
 '
 
-test_expect_success 'daemon log records all attributes' '
-       cat >expect <<-\EOF &&
-       Extended attribute "host": localhost
-       Extended attribute "protocol": version=1
-       EOF
-       >daemon.log &&
-       GIT_OVERRIDE_VIRTUAL_HOST=localhost \
-               git -c protocol.version=1 \
-                       ls-remote "$GIT_DAEMON_URL/interp.git" &&
-       grep -i extended.attribute daemon.log | cut -d" " -f2- >actual &&
-       test_cmp expect actual
-'
-
 test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
        {
                printf "git-upload-pack /interp.git\n\0host=localhost" | packetize
index 8bbc7068acbd1eab9f0499ff1151abd58a87079c..d6948cbdab03cf827d86511ade26366e89fda149 100755 (executable)
@@ -487,7 +487,7 @@ test_clone_url () {
        expect_ssh "$@"
 }
 
-test_expect_success !MINGW 'clone c:temp is ssl' '
+test_expect_success !MINGW,!CYGWIN 'clone c:temp is ssl' '
        test_clone_url c:temp c temp
 '
 
index 39329eb7a8a64b177794b83ef8828b866fead547..60c1ba951b7d4178708574d10986659749925059 100755 (executable)
@@ -45,6 +45,53 @@ test_expect_success 'clone -c config is available during clone' '
        test_cmp expect child/file
 '
 
+test_expect_success 'clone -c remote.origin.fetch=<refspec> works' '
+       rm -rf child &&
+       git update-ref refs/grab/it refs/heads/master &&
+       git update-ref refs/leave/out refs/heads/master &&
+       git clone -c "remote.origin.fetch=+refs/grab/*:refs/grab/*" . child &&
+       git -C child for-each-ref --format="%(refname)" >actual &&
+
+       cat >expect <<-\EOF &&
+       refs/grab/it
+       refs/heads/master
+       refs/remotes/origin/HEAD
+       refs/remotes/origin/master
+       EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'git -c remote.origin.fetch=<refspec> clone works' '
+       rm -rf child &&
+       git -c "remote.origin.fetch=+refs/grab/*:refs/grab/*" clone . child &&
+       git -C child for-each-ref --format="%(refname)" >actual &&
+
+       cat >expect <<-\EOF &&
+       refs/grab/it
+       refs/heads/master
+       refs/remotes/origin/HEAD
+       refs/remotes/origin/master
+       EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'clone -c remote.<remote>.fetch=<refspec> --origin=<name>' '
+       rm -rf child &&
+       git clone --origin=upstream \
+                 -c "remote.upstream.fetch=+refs/grab/*:refs/grab/*" \
+                 -c "remote.origin.fetch=+refs/leave/*:refs/leave/*" \
+                 . child &&
+       git -C child for-each-ref --format="%(refname)" >actual &&
+
+       cat >expect <<-\EOF &&
+       refs/grab/it
+       refs/heads/master
+       refs/remotes/upstream/HEAD
+       refs/remotes/upstream/master
+       EOF
+       test_cmp expect actual
+'
+
 # Tests for the hidden file attribute on windows
 is_hidden () {
        # Use the output of `attrib`, ignore the absolute path
index 336f02a41a66b48269e8eb6030d5323cffb8b686..9643acb1615fe0d28a7f0e386fa69a570a93dc8e 100755 (executable)
@@ -281,7 +281,7 @@ test_expect_success 'upon cloning, check that all refs point to objects' '
        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 &&
+       test_i18ngrep "did not send all necessary objects" err &&
 
        # Ensure that the one-time-sed script was used.
        ! test -e "$HTTPD_ROOT_PATH/one-time-sed"
index 3f58f05cbb49d3b4a7f50e946e0f46bbc953140a..7053899cb5a0cbd5cca10cb4029b70df866dbff8 100755 (executable)
@@ -208,7 +208,7 @@ test_expect_success 'server is initially ahead - no ref in want' '
        cp -r "$LOCAL_PRISTINE" local &&
        inconsistency master 1234567890123456789012345678901234567890 &&
        test_must_fail git -C local fetch 2>err &&
-       grep "ERR upload-pack: not our ref" err
+       test_i18ngrep "ERR upload-pack: not our ref" err
 '
 
 test_expect_success 'server is initially ahead - ref in want' '
@@ -254,7 +254,7 @@ test_expect_success 'server loses a ref - ref in want' '
        echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-sed" &&
        test_must_fail git -C local fetch 2>err &&
 
-       grep "ERR unknown ref refs/heads/raster" err
+       test_i18ngrep "ERR unknown ref refs/heads/raster" err
 '
 
 stop_httpd
index e1cef58f2af96f6185ed93086c3966fb73d58f79..d23b948f27f13ec81dd40fb52caa2ea4b5b8500c 100755 (executable)
@@ -64,15 +64,12 @@ test_expect_success 'merge simple rename+criss-cross with no modifications' '
                git ls-files -u >out &&
                test_line_count = 2 out &&
                git ls-files -o >out &&
-               test_line_count = 3 out &&
+               test_line_count = 1 out &&
 
                git rev-parse >expect       \
-                       L2:three   R2:three \
                        L2:three   R2:three &&
                git rev-parse   >actual     \
                        :2:three   :3:three &&
-               git hash-object >>actual    \
-                       three~HEAD three~R2^0 &&
                test_cmp expect actual
        )
 '
@@ -140,15 +137,12 @@ test_expect_success 'merge criss-cross + rename merges with basic modification'
                git ls-files -u >out &&
                test_line_count = 2 out &&
                git ls-files -o >out &&
-               test_line_count = 3 out &&
+               test_line_count = 1 out &&
 
                git rev-parse >expect       \
-                       L2:three   R2:three \
                        L2:three   R2:three &&
                git rev-parse   >actual     \
                        :2:three   :3:three &&
-               git hash-object >>actual    \
-                       three~HEAD three~R2^0 &&
                test_cmp expect actual
        )
 '
@@ -185,7 +179,7 @@ test_expect_success 'setup differently handled merges of rename/add conflict' '
                git branch B &&
                git checkout -b C &&
                echo 10 >>a &&
-               echo "other content" >>new_a &&
+               test_write_lines 0 1 2 3 4 5 6 7 foobar >new_a &&
                git add a new_a &&
                test_tick && git commit -m C &&
 
@@ -195,14 +189,14 @@ test_expect_success 'setup differently handled merges of rename/add conflict' '
 
                git checkout B^0 &&
                test_must_fail git merge C &&
-               git clean -f &&
+               git show :2:new_a >new_a &&
+               git add new_a &&
                test_tick && git commit -m D &&
                git tag D &&
 
                git checkout C^0 &&
                test_must_fail git merge B &&
-               rm new_a~HEAD new_a &&
-               printf "Incorrectly merged content" >>new_a &&
+               test_write_lines 0 1 2 3 4 5 6 7 bad_merge >new_a &&
                git add -u &&
                test_tick && git commit -m E &&
                git tag E
@@ -225,21 +219,74 @@ test_expect_success 'git detects differently handled merges conflict' '
                test_line_count = 1 out &&
 
                git rev-parse >expect       \
-                       D:new_a  E:new_a &&
+                       C:new_a  D:new_a  E:new_a &&
                git rev-parse   >actual     \
-                       :2:new_a :3:new_a &&
+                       :1:new_a :2:new_a :3:new_a &&
                test_cmp expect actual &&
 
-               git cat-file -p C:new_a >ours &&
-               git cat-file -p B:new_a >theirs &&
+               # Test that the two-way merge in new_a is as expected
+               git cat-file -p D:new_a >ours &&
+               git cat-file -p E:new_a >theirs &&
                >empty &&
                test_must_fail git merge-file \
-                       -L "Temporary merge branch 1" \
+                       -L "HEAD" \
                        -L "" \
-                       -L "Temporary merge branch 2" \
+                       -L "E^0" \
                        ours empty theirs &&
                sed -e "s/^\([<=>]\)/\1\1\1/" ours >expect &&
-               git cat-file -p :1:new_a >actual &&
+               git hash-object new_a >actual &&
+               git hash-object ours  >expect &&
+               test_cmp expect actual
+       )
+'
+
+# Repeat the above testcase with precisely the same setup, other than with
+# the two merge bases having different orderings of commit timestamps so
+# that they are reversed in the order they are provided to merge-recursive,
+# so that we can improve code coverage.
+test_expect_success 'git detects differently handled merges conflict, swapped' '
+       (
+               cd rename-add &&
+
+               # Difference #1: Do cleanup from previous testrun
+               git reset --hard &&
+               git clean -fdqx &&
+
+               # Difference #2: Change commit timestamps
+               btime=$(git log --no-walk --date=raw --format=%cd B | awk "{print \$1}") &&
+               ctime=$(git log --no-walk --date=raw --format=%cd C | awk "{print \$1}") &&
+               newctime=$(($btime+1)) &&
+               git fast-export --no-data --all | sed -e s/$ctime/$newctime/ | git fast-import --force --quiet &&
+               # End of differences; rest is copy-paste of last test
+
+               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 &&
+
+               git rev-parse >expect       \
+                       C:new_a  D:new_a  E:new_a &&
+               git rev-parse   >actual     \
+                       :1:new_a :2:new_a :3:new_a &&
+               test_cmp expect actual &&
+
+               # Test that the two-way merge in new_a is as expected
+               git cat-file -p D:new_a >ours &&
+               git cat-file -p E:new_a >theirs &&
+               >empty &&
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "E^0" \
+                       ours empty theirs &&
+               sed -e "s/^\([<=>]\)/\1\1\1/" ours >expect &&
+               git hash-object new_a >actual &&
+               git hash-object ours  >expect &&
                test_cmp expect actual
        )
 '
@@ -1402,4 +1449,349 @@ test_expect_failure 'check conflicting modes for regular file' '
        )
 '
 
+# Setup:
+#          L1---L2
+#         /  \ /  \
+#   master    X    ?
+#         \  / \  /
+#          R1---R2
+#
+# Where:
+#   master has two files, named 'b' and 'a'
+#   branches L1 and R1 both modify each of the two files in conflicting ways
+#
+#   L2 is a merge of R1 into L1; more on it later.
+#   R2 is a merge of L1 into R1; more on it later.
+#
+#   X is an auto-generated merge-base used when merging L2 and R2.
+#   since X is a merge of L1 and R1, it has conflicting versions of each file
+#
+#   More about L2 and R2:
+#     - both resolve the conflicts in 'b' and 'a' differently
+#     - L2 renames 'b' to 'm'
+#     - R2 renames 'a' to 'm'
+#
+#   In the end, in file 'm' we have four different conflicting files (from
+#   two versions of 'b' and two of 'a').  In addition, if
+#   merge.conflictstyle is diff3, then the base version also has
+#   conflict markers of its own, leading to a total of three levels of
+#   conflict markers.  This is a pretty weird corner case, but we just want
+#   to ensure that we handle it as well as practical.
+
+test_expect_success 'setup nested conflicts' '
+       test_create_repo nested_conflicts &&
+       (
+               cd nested_conflicts &&
+
+               # Create some related files now
+               for i in $(test_seq 1 10)
+               do
+                       echo Random base content line $i
+               done >initial &&
+
+               cp initial b_L1 &&
+               cp initial b_R1 &&
+               cp initial b_L2 &&
+               cp initial b_R2 &&
+               cp initial a_L1 &&
+               cp initial a_R1 &&
+               cp initial a_L2 &&
+               cp initial a_R2 &&
+
+               test_write_lines b b_L1 >>b_L1 &&
+               test_write_lines b b_R1 >>b_R1 &&
+               test_write_lines b b_L2 >>b_L2 &&
+               test_write_lines b b_R2 >>b_R2 &&
+               test_write_lines a a_L1 >>a_L1 &&
+               test_write_lines a a_R1 >>a_R1 &&
+               test_write_lines a a_L2 >>a_L2 &&
+               test_write_lines a a_R2 >>a_R2 &&
+
+               # Setup original commit (or merge-base), consisting of
+               # files named "b" and "a"
+               cp initial b &&
+               cp initial a &&
+               echo b >>b &&
+               echo a >>a &&
+               git add b a &&
+               test_tick && git commit -m initial &&
+
+               git branch L &&
+               git branch R &&
+
+               # Handle the left side
+               git checkout L &&
+               mv -f b_L1 b &&
+               mv -f a_L1 a &&
+               git add b a &&
+               test_tick && git commit -m "version L1 of files" &&
+               git tag L1 &&
+
+               # Handle the right side
+               git checkout R &&
+               mv -f b_R1 b &&
+               mv -f a_R1 a &&
+               git add b a &&
+               test_tick && git commit -m "verson R1 of files" &&
+               git tag R1 &&
+
+               # Create first merge on left side
+               git checkout L &&
+               test_must_fail git merge R1 &&
+               mv -f b_L2 b &&
+               mv -f a_L2 a &&
+               git add b a &&
+               git mv b m &&
+               test_tick && git commit -m "left merge, rename b->m" &&
+               git tag L2 &&
+
+               # Create first merge on right side
+               git checkout R &&
+               test_must_fail git merge L1 &&
+               mv -f b_R2 b &&
+               mv -f a_R2 a &&
+               git add b a &&
+               git mv a m &&
+               test_tick && git commit -m "right merge, rename a->m" &&
+               git tag R2
+       )
+'
+
+test_expect_success 'check nested conflicts' '
+       (
+               cd nested_conflicts &&
+
+               git clean -f &&
+               git checkout L2^0 &&
+
+               # Merge must fail; there is a conflict
+               test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R2^0 &&
+
+               # Make sure the index has the right number of entries
+               git ls-files -s >out &&
+               test_line_count = 2 out &&
+               git ls-files -u >out &&
+               test_line_count = 2 out &&
+               # Ensure we have the correct number of untracked files
+               git ls-files -o >out &&
+               test_line_count = 1 out &&
+
+               # Create a and b from virtual merge base X
+               git cat-file -p master:a >base &&
+               git cat-file -p L1:a >ours &&
+               git cat-file -p R1:a >theirs &&
+               test_must_fail git merge-file --diff3 \
+                       -L "Temporary merge branch 1" \
+                       -L "merged common ancestors"  \
+                       -L "Temporary merge branch 2" \
+                       ours  \
+                       base  \
+                       theirs &&
+               sed -e "s/^\([<|=>]\)/\1\1/" ours >vmb_a &&
+
+               git cat-file -p master:b >base &&
+               git cat-file -p L1:b >ours &&
+               git cat-file -p R1:b >theirs &&
+               test_must_fail git merge-file --diff3 \
+                       -L "Temporary merge branch 1" \
+                       -L "merged common ancestors"  \
+                       -L "Temporary merge branch 2" \
+                       ours  \
+                       base  \
+                       theirs &&
+               sed -e "s/^\([<|=>]\)/\1\1/" ours >vmb_b &&
+
+               # Compare :2:m to expected values
+               git cat-file -p L2:m >ours &&
+               git cat-file -p R2:b >theirs &&
+               test_must_fail git merge-file --diff3  \
+                       -L "HEAD:m"                    \
+                       -L "merged common ancestors:b" \
+                       -L "R2^0:b"                    \
+                       ours                           \
+                       vmb_b                          \
+                       theirs                         &&
+               sed -e "s/^\([<|=>]\)/\1\1/" ours >m_stage_2 &&
+               git cat-file -p :2:m >actual &&
+               test_cmp m_stage_2 actual &&
+
+               # Compare :3:m to expected values
+               git cat-file -p L2:a >ours &&
+               git cat-file -p R2:m >theirs &&
+               test_must_fail git merge-file --diff3  \
+                       -L "HEAD:a"                    \
+                       -L "merged common ancestors:a" \
+                       -L "R2^0:m"                    \
+                       ours                           \
+                       vmb_a                          \
+                       theirs                         &&
+               sed -e "s/^\([<|=>]\)/\1\1/" ours >m_stage_3 &&
+               git cat-file -p :3:m >actual &&
+               test_cmp m_stage_3 actual &&
+
+               # Compare m to expected contents
+               >empty &&
+               cp m_stage_2 expected_final_m &&
+               test_must_fail git merge-file --diff3 \
+                       -L "HEAD"                     \
+                       -L "merged common ancestors"  \
+                       -L "R2^0"                     \
+                       expected_final_m              \
+                       empty                         \
+                       m_stage_3                     &&
+               test_cmp expected_final_m m
+       )
+'
+
+# Setup:
+#          L1---L2---L3
+#         /  \ /  \ /  \
+#   master    X1   X2   ?
+#         \  / \  / \  /
+#          R1---R2---R3
+#
+# Where:
+#   master has one file named 'content'
+#   branches L1 and R1 both modify each of the two files in conflicting ways
+#
+#   L<n> (n>1) is a merge of R<n-1> into L<n-1>
+#   R<n> (n>1) is a merge of L<n-1> into R<n-1>
+#   L<n> and R<n> resolve the conflicts differently.
+#
+#   X<n> is an auto-generated merge-base used when merging L<n+1> and R<n+1>.
+#   By construction, X1 has conflict markers due to conflicting versions.
+#   X2, due to using merge.conflictstyle=3, has nested conflict markers.
+#
+#   So, merging R3 into L3 using merge.conflictstyle=3 should show the
+#   nested conflict markers from X2 in the base version -- that means we
+#   have three levels of conflict markers.  Can we distinguish all three?
+
+test_expect_success 'setup virtual merge base with nested conflicts' '
+       test_create_repo virtual_merge_base_has_nested_conflicts &&
+       (
+               cd virtual_merge_base_has_nested_conflicts &&
+
+               # Create some related files now
+               for i in $(test_seq 1 10)
+               do
+                       echo Random base content line $i
+               done >content &&
+
+               # Setup original commit
+               git add content &&
+               test_tick && git commit -m initial &&
+
+               git branch L &&
+               git branch R &&
+
+               # Create L1
+               git checkout L &&
+               echo left >>content &&
+               git add content &&
+               test_tick && git commit -m "version L1 of content" &&
+               git tag L1 &&
+
+               # Create R1
+               git checkout R &&
+               echo right >>content &&
+               git add content &&
+               test_tick && git commit -m "verson R1 of content" &&
+               git tag R1 &&
+
+               # Create L2
+               git checkout L &&
+               test_must_fail git -c merge.conflictstyle=diff3 merge R1 &&
+               git checkout L1 content &&
+               test_tick && git commit -m "version L2 of content" &&
+               git tag L2 &&
+
+               # Create R2
+               git checkout R &&
+               test_must_fail git -c merge.conflictstyle=diff3 merge L1 &&
+               git checkout R1 content &&
+               test_tick && git commit -m "version R2 of content" &&
+               git tag R2 &&
+
+               # Create L3
+               git checkout L &&
+               test_must_fail git -c merge.conflictstyle=diff3 merge R2 &&
+               git checkout L1 content &&
+               test_tick && git commit -m "version L3 of content" &&
+               git tag L3 &&
+
+               # Create R3
+               git checkout R &&
+               test_must_fail git -c merge.conflictstyle=diff3 merge L2 &&
+               git checkout R1 content &&
+               test_tick && git commit -m "version R3 of content" &&
+               git tag R3
+       )
+'
+
+test_expect_success 'check virtual merge base with nested conflicts' '
+       (
+               cd virtual_merge_base_has_nested_conflicts &&
+
+               git checkout L3^0 &&
+
+               # Merge must fail; there is a conflict
+               test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R3^0 &&
+
+               # Make sure the index has the right number of entries
+               git ls-files -s >out &&
+               test_line_count = 3 out &&
+               git ls-files -u >out &&
+               test_line_count = 3 out &&
+               # Ensure we have the correct number of untracked files
+               git ls-files -o >out &&
+               test_line_count = 1 out &&
+
+               # Compare :[23]:content to expected values
+               git rev-parse L1:content R1:content >expect &&
+               git rev-parse :2:content :3:content >actual &&
+               test_cmp expect actual &&
+
+               # Imitate X1 merge base, except without long enough conflict
+               # markers because a subsequent sed will modify them.  Put
+               # result into vmb.
+               git cat-file -p master:content >base &&
+               git cat-file -p L:content >left &&
+               git cat-file -p R:content >right &&
+               cp left merged-once &&
+               test_must_fail git merge-file --diff3 \
+                       -L "Temporary merge branch 1" \
+                       -L "merged common ancestors"  \
+                       -L "Temporary merge branch 2" \
+                       merged-once \
+                       base        \
+                       right       &&
+               sed -e "s/^\([<|=>]\)/\1\1\1/" merged-once >vmb &&
+
+               # Imitate X2 merge base, overwriting vmb.  Note that we
+               # extend both sets of conflict markers to make them longer
+               # with the sed command.
+               cp left merged-twice &&
+               test_must_fail git merge-file --diff3 \
+                       -L "Temporary merge branch 1" \
+                       -L "merged common ancestors"  \
+                       -L "Temporary merge branch 2" \
+                       merged-twice \
+                       vmb          \
+                       right        &&
+               sed -e "s/^\([<|=>]\)/\1\1\1/" merged-twice >vmb &&
+
+               # Compare :1:content to expected value
+               git cat-file -p :1:content >actual &&
+               test_cmp vmb actual &&
+
+               # Determine expected content in final outer merge, compare to
+               # what the merge generated.
+               cp -f left expect &&
+               test_must_fail git merge-file --diff3                      \
+                       -L "HEAD"  -L "merged common ancestors"  -L "R3^0" \
+                       expect     vmb                           right     &&
+               test_cmp expect content
+       )
+'
+
 test_done
index b97aca7fa263f79520013b14d90fa0b49031484b..7cc34e75797b406096407ba1799a1ca54e48333c 100755 (executable)
@@ -464,17 +464,28 @@ test_expect_success 'handle rename/rename (2to1) conflict correctly' '
                git ls-files -u c >out &&
                test_line_count = 2 out &&
                git ls-files -o >out &&
-               test_line_count = 3 out &&
+               test_line_count = 1 out &&
 
                test_path_is_missing a &&
                test_path_is_missing b &&
-               test_path_is_file c~HEAD &&
-               test_path_is_file c~C^0 &&
 
-               git rev-parse >expect   \
-                       C:a     B:b     &&
-               git hash-object >actual \
-                       c~HEAD  c~C^0   &&
+               git rev-parse >expect  \
+                       C:a     B:b    &&
+               git rev-parse >actual  \
+                       :2:c    :3:c   &&
+               test_cmp expect actual &&
+
+               # Test that the two-way merge in new_a is as expected
+               git cat-file -p :2:c >>ours &&
+               git cat-file -p :3:c >>theirs &&
+               >empty &&
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "C^0" \
+                       ours empty theirs &&
+               git hash-object c >actual &&
+               git hash-object ours >expect &&
                test_cmp expect actual
        )
 '
@@ -673,7 +684,7 @@ test_expect_success 'rename/rename/add-dest merge still knows about conflicting
                git ls-files -u c >out &&
                test_line_count = 2 out &&
                git ls-files -o >out &&
-               test_line_count = 5 out &&
+               test_line_count = 1 out &&
 
                git rev-parse >expect               \
                        A:a   C:b   B:b   C:c   B:c &&
@@ -681,14 +692,27 @@ test_expect_success 'rename/rename/add-dest merge still knows about conflicting
                        :1:a  :2:b  :3:b  :2:c  :3:c &&
                test_cmp expect actual &&
 
-               git rev-parse >expect               \
-                       C:c     B:c     C:b     B:b &&
-               git hash-object >actual                \
-                       c~HEAD  c~B\^0  b~HEAD  b~B\^0 &&
-               test_cmp expect actual &&
+               # Record some contents for re-doing merges
+               git cat-file -p A:a >stuff &&
+               git cat-file -p C:b >important_info &&
+               git cat-file -p B:c >precious_data &&
+               >empty &&
 
-               test_path_is_missing b &&
-               test_path_is_missing c
+               # Test the merge in b
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "B^0" \
+                       important_info empty stuff &&
+               test_cmp important_info b &&
+
+               # Test the merge in c
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "B^0" \
+                       stuff empty precious_data &&
+               test_cmp stuff c
        )
 '
 
@@ -937,4 +961,283 @@ test_expect_failure 'mod6-check: chains of rename/rename(1to2) and rename/rename
        )
 '
 
+test_conflicts_with_adds_and_renames() {
+       sideL=$1
+       sideR=$2
+
+       # Setup:
+       #          L
+       #         / \
+       #   master   ?
+       #         \ /
+       #          R
+       #
+       # Where:
+       #   Both L and R have files named 'three' which collide.  Each of
+       #   the colliding files could have been involved in a rename, in
+       #   which case there was a file named 'one' or 'two' that was
+       #   modified on the opposite side of history and renamed into the
+       #   collision on this side of history.
+       #
+       # Questions:
+       #   1) The index should contain both a stage 2 and stage 3 entry
+       #      for the colliding file.  Does it?
+       #   2) When renames are involved, the content merges are clean, so
+       #      the index should reflect the content merges, not merely the
+       #      version of the colliding file from the prior commit.  Does
+       #      it?
+       #   3) There should be a file in the worktree named 'three'
+       #      containing the two-way merged contents of the content-merged
+       #      versions of 'three' from each of the two colliding
+       #      files.  Is it present?
+       #   4) There should not be any three~* files in the working
+       #      tree
+       test_expect_success "setup simple $sideL/$sideR conflict" '
+               test_create_repo simple_${sideL}_${sideR} &&
+               (
+                       cd simple_${sideL}_${sideR} &&
+
+                       # Create some related files now
+                       for i in $(test_seq 1 10)
+                       do
+                               echo Random base content line $i
+                       done >file_v1 &&
+                       cp file_v1 file_v2 &&
+                       echo modification >>file_v2 &&
+
+                       cp file_v1 file_v3 &&
+                       echo more stuff >>file_v3 &&
+                       cp file_v3 file_v4 &&
+                       echo yet more stuff >>file_v4 &&
+
+                       # Use a tag to record both these files for simple
+                       # access, and clean out these untracked files
+                       git tag file_v1 $(git hash-object -w file_v1) &&
+                       git tag file_v2 $(git hash-object -w file_v2) &&
+                       git tag file_v3 $(git hash-object -w file_v3) &&
+                       git tag file_v4 $(git hash-object -w file_v4) &&
+                       git clean -f &&
+
+                       # Setup original commit (or merge-base), consisting of
+                       # files named "one" and "two" if renames were involved.
+                       touch irrelevant_file &&
+                       git add irrelevant_file &&
+                       if [ $sideL = "rename" ]
+                       then
+                               git show file_v1 >one &&
+                               git add one
+                       fi &&
+                       if [ $sideR = "rename" ]
+                       then
+                               git show file_v3 >two &&
+                               git add two
+                       fi &&
+                       test_tick && git commit -m initial &&
+
+                       git branch L &&
+                       git branch R &&
+
+                       # Handle the left side
+                       git checkout L &&
+                       if [ $sideL = "rename" ]
+                       then
+                               git mv one three
+                       else
+                               git show file_v2 >three &&
+                               git add three
+                       fi &&
+                       if [ $sideR = "rename" ]
+                       then
+                               git show file_v4 >two &&
+                               git add two
+                       fi &&
+                       test_tick && git commit -m L &&
+
+                       # Handle the right side
+                       git checkout R &&
+                       if [ $sideL = "rename" ]
+                       then
+                               git show file_v2 >one &&
+                               git add one
+                       fi &&
+                       if [ $sideR = "rename" ]
+                       then
+                               git mv two three
+                       else
+                               git show file_v4 >three &&
+                               git add three
+                       fi &&
+                       test_tick && git commit -m R
+               )
+       '
+
+       test_expect_success "check simple $sideL/$sideR conflict" '
+               (
+                       cd simple_${sideL}_${sideR} &&
+
+                       git checkout L^0 &&
+
+                       # Merge must fail; there is a conflict
+                       test_must_fail git merge -s recursive R^0 &&
+
+                       # Make sure the index has the right number of entries
+                       git ls-files -s >out &&
+                       test_line_count = 3 out &&
+                       git ls-files -u >out &&
+                       test_line_count = 2 out &&
+                       # Ensure we have the correct number of untracked files
+                       git ls-files -o >out &&
+                       test_line_count = 1 out &&
+
+                       # Nothing should have touched irrelevant_file
+                       git rev-parse >actual      \
+                               :0:irrelevant_file \
+                               :2:three           \
+                               :3:three           &&
+                       git rev-parse >expected        \
+                               master:irrelevant_file \
+                               file_v2                \
+                               file_v4                &&
+                       test_cmp expected actual &&
+
+                       # Make sure we have the correct merged contents for
+                       # three
+                       git show file_v1 >expected &&
+                       cat <<-\EOF >>expected &&
+                       <<<<<<< HEAD
+                       modification
+                       =======
+                       more stuff
+                       yet more stuff
+                       >>>>>>> R^0
+                       EOF
+
+                       test_cmp expected three
+               )
+       '
+}
+
+test_conflicts_with_adds_and_renames rename rename
+test_conflicts_with_adds_and_renames rename add
+test_conflicts_with_adds_and_renames add    rename
+test_conflicts_with_adds_and_renames add    add
+
+# Setup:
+#          L
+#         / \
+#   master   ?
+#         \ /
+#          R
+#
+# Where:
+#   master has two files, named 'one' and 'two'.
+#   branches L and R both modify 'one', in conflicting ways.
+#   branches L and R both modify 'two', in conflicting ways.
+#   branch L also renames 'one' to 'three'.
+#   branch R also renames 'two' to 'three'.
+#
+#   So, we have four different conflicting files that all end up at path
+#   'three'.
+test_expect_success 'setup nested conflicts from rename/rename(2to1)' '
+       test_create_repo nested_conflicts_from_rename_rename &&
+       (
+               cd nested_conflicts_from_rename_rename &&
+
+               # Create some related files now
+               for i in $(test_seq 1 10)
+               do
+                       echo Random base content line $i
+               done >file_v1 &&
+
+               cp file_v1 file_v2 &&
+               cp file_v1 file_v3 &&
+               cp file_v1 file_v4 &&
+               cp file_v1 file_v5 &&
+               cp file_v1 file_v6 &&
+
+               echo one  >>file_v1 &&
+               echo uno  >>file_v2 &&
+               echo eins >>file_v3 &&
+
+               echo two  >>file_v4 &&
+               echo dos  >>file_v5 &&
+               echo zwei >>file_v6 &&
+
+               # Setup original commit (or merge-base), consisting of
+               # files named "one" and "two".
+               mv file_v1 one &&
+               mv file_v4 two &&
+               git add one two &&
+               test_tick && git commit -m english &&
+
+               git branch L &&
+               git branch R &&
+
+               # Handle the left side
+               git checkout L &&
+               git mv one three &&
+               mv -f file_v2 three &&
+               mv -f file_v5 two &&
+               git add two three &&
+               test_tick && git commit -m spanish &&
+
+               # Handle the right side
+               git checkout R &&
+               git mv two three &&
+               mv -f file_v3 one &&
+               mv -f file_v6 three &&
+               git add one three &&
+               test_tick && git commit -m german
+       )
+'
+
+test_expect_success 'check nested conflicts from rename/rename(2to1)' '
+       (
+               cd nested_conflicts_from_rename_rename &&
+
+               git checkout L^0 &&
+
+               # Merge must fail; there is a conflict
+               test_must_fail git merge -s recursive R^0 &&
+
+               # Make sure the index has the right number of entries
+               git ls-files -s >out &&
+               test_line_count = 2 out &&
+               git ls-files -u >out &&
+               test_line_count = 2 out &&
+               # Ensure we have the correct number of untracked files
+               git ls-files -o >out &&
+               test_line_count = 1 out &&
+
+               # Compare :2:three to expected values
+               git cat-file -p master:one >base &&
+               git cat-file -p L:three >ours &&
+               git cat-file -p R:one >theirs &&
+               test_must_fail git merge-file    \
+                       -L "HEAD:three"  -L ""  -L "R^0:one" \
+                       ours             base   theirs &&
+               sed -e "s/^\([<=>]\)/\1\1/" ours >L-three &&
+               git cat-file -p :2:three >expect &&
+               test_cmp expect L-three &&
+
+               # Compare :2:three to expected values
+               git cat-file -p master:two >base &&
+               git cat-file -p L:two >ours &&
+               git cat-file -p R:three >theirs &&
+               test_must_fail git merge-file    \
+                       -L "HEAD:two"  -L ""  -L "R^0:three" \
+                       ours           base   theirs &&
+               sed -e "s/^\([<=>]\)/\1\1/" ours >R-three &&
+               git cat-file -p :3:three >expect &&
+               test_cmp expect R-three &&
+
+               # Compare three to expected contents
+               >empty &&
+               test_must_fail git merge-file    \
+                       -L "HEAD"  -L ""  -L "R^0" \
+                       L-three    empty  R-three &&
+               test_cmp three L-three
+       )
+'
+
 test_done
index 4a71f17edd69a2cb6962cf759aa6ad1b7604c2db..62c564707b9ff8a8e86b1f8d2d2e3919c36f1b5f 100755 (executable)
@@ -278,7 +278,7 @@ test_expect_success '1d-check: Directory renames cause a rename/rename(2to1) con
                git ls-files -u >out &&
                test_line_count = 2 out &&
                git ls-files -o >out &&
-               test_line_count = 3 out &&
+               test_line_count = 1 out &&
 
                git rev-parse >actual \
                        :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
@@ -293,15 +293,16 @@ test_expect_success '1d-check: Directory renames cause a rename/rename(2to1) con
                         A:y/wham  B:z/wham &&
                test_cmp expect actual &&
 
-               test_path_is_missing x/wham &&
-               test_path_is_file x/wham~HEAD &&
-               test_path_is_file x/wham~B^0 &&
-
-               git hash-object >actual \
-                       x/wham~HEAD x/wham~B^0 &&
-               git rev-parse >expect \
-                       A:y/wham    B:z/wham &&
-               test_cmp expect actual
+               # Test that the two-way merge in x/wham is as expected
+               git cat-file -p :2:x/wham >expect &&
+               git cat-file -p :3:x/wham >other &&
+               >empty &&
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "B^0" \
+                       expect empty other &&
+               test_cmp expect x/wham
        )
 '
 
@@ -1077,7 +1078,7 @@ test_expect_success '5c-check: Transitive rename would cause rename/rename/renam
                git ls-files -u >out &&
                test_line_count = 6 out &&
                git ls-files -o >out &&
-               test_line_count = 3 out &&
+               test_line_count = 1 out &&
 
                git rev-parse >actual \
                        :0:y/b :0:y/c :0:y/e &&
@@ -1093,9 +1094,9 @@ test_expect_success '5c-check: Transitive rename would cause rename/rename/renam
                test_cmp expect actual &&
 
                git hash-object >actual \
-                       w/d~HEAD w/d~B^0 z/d &&
+                       z/d &&
                git rev-parse >expect \
-                       O:x/d    B:w/d   O:x/d &&
+                       O:x/d &&
                test_cmp expect actual &&
                test_path_is_missing x/d &&
                test_path_is_file y/d &&
@@ -1670,7 +1671,7 @@ test_expect_success '7b-check: rename/rename(2to1), but only due to transitive r
                git ls-files -u >out &&
                test_line_count = 2 out &&
                git ls-files -o >out &&
-               test_line_count = 3 out &&
+               test_line_count = 1 out &&
 
                git rev-parse >actual \
                        :0:y/b :0:y/c :2:y/d :3:y/d &&
@@ -1678,15 +1679,16 @@ test_expect_success '7b-check: rename/rename(2to1), but only due to transitive r
                         O:z/b  O:z/c  O:w/d  O:x/d &&
                test_cmp expect actual &&
 
-               test_path_is_missing y/d &&
-               test_path_is_file y/d~HEAD &&
-               test_path_is_file y/d~B^0 &&
-
-               git hash-object >actual \
-                       y/d~HEAD y/d~B^0 &&
-               git rev-parse >expect \
-                       O:w/d    O:x/d &&
-               test_cmp expect actual
+               # Test that the two-way merge in y/d is as expected
+               git cat-file -p :2:y/d >expect &&
+               git cat-file -p :3:y/d >other &&
+               >empty &&
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "B^0" \
+                       expect empty other &&
+               test_cmp expect y/d
        )
 '
 
@@ -3161,11 +3163,48 @@ test_expect_success '10c-check: Overwrite untracked with dir rename/rename(1to2)
        )
 '
 
+test_expect_success '10c-check: Overwrite untracked with dir rename/rename(1to2), other direction' '
+       (
+               cd 10c &&
+
+               git reset --hard &&
+               git clean -fdqx &&
+
+               git checkout B^0 &&
+               mkdir y &&
+               echo important >y/c &&
+
+               test_must_fail git merge -s recursive A^0 >out 2>err &&
+               test_i18ngrep "CONFLICT (rename/rename)" out &&
+               test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
+
+               git ls-files -s >out &&
+               test_line_count = 6 out &&
+               git ls-files -u >out &&
+               test_line_count = 3 out &&
+               git ls-files -o >out &&
+               test_line_count = 3 out &&
+
+               git rev-parse >actual \
+                       :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
+               git rev-parse >expect \
+                        O:z/a  O:z/b  O:x/d  O:x/c  O:x/c  O:x/c &&
+               test_cmp expect actual &&
+
+               git hash-object y/c~HEAD >actual &&
+               git rev-parse O:x/c >expect &&
+               test_cmp expect actual &&
+
+               echo important >expect &&
+               test_cmp expect y/c
+       )
+'
+
 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
 #   Commit O: z/{a,b,c_1},        x/{d,e,f_2}
 #   Commit A: y/{a,b},            x/{d,e,f_2,wham_1} + untracked y/wham
 #   Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
-#   Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~B^0,wham~HEAD}+
+#   Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~merged}+
 #             CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
 #             ERROR_MSG(Refusing to lose untracked file at y/wham)
 
@@ -3219,7 +3258,7 @@ test_expect_success '10d-check: Delete untracked with dir rename/rename(2to1)' '
                git ls-files -u >out &&
                test_line_count = 2 out &&
                git ls-files -o >out &&
-               test_line_count = 4 out &&
+               test_line_count = 3 out &&
 
                git rev-parse >actual \
                        :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
@@ -3232,11 +3271,16 @@ test_expect_success '10d-check: Delete untracked with dir rename/rename(2to1)' '
                echo important >expect &&
                test_cmp expect y/wham &&
 
-               git hash-object >actual \
-                       y/wham~B^0 y/wham~HEAD &&
-               git rev-parse >expect \
-                       O:x/f      O:z/c &&
-               test_cmp expect actual
+               # Test that the two-way merge in y/wham~merged is as expected
+               git cat-file -p :2:y/wham >expect &&
+               git cat-file -p :3:y/wham >other &&
+               >empty &&
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "B^0" \
+                       expect empty other &&
+               test_cmp expect y/wham~merged
        )
 '
 
@@ -3665,7 +3709,7 @@ test_expect_success '11e-check: Avoid deleting not-uptodate with dir rename/rena
                git ls-files -u >out &&
                test_line_count = 4 out &&
                git ls-files -o >out &&
-               test_line_count = 4 out &&
+               test_line_count = 3 out &&
 
                echo different >expected &&
                echo mods >>expected &&
@@ -3677,11 +3721,17 @@ test_expect_success '11e-check: Avoid deleting not-uptodate with dir rename/rena
                         O:z/a  O:z/b  O:x/d  O:x/c  O:x/c  A:y/c  O:x/c &&
                test_cmp expect actual &&
 
-               git hash-object >actual \
-                       y/c~B^0 y/c~HEAD &&
-               git rev-parse >expect \
-                       O:x/c   A:y/c &&
-               test_cmp expect actual
+               # See if y/c~merged has expected contents; requires manually
+               # doing the expected file merge
+               git cat-file -p A:y/c >c1 &&
+               git cat-file -p B:z/c >c2 &&
+               >empty &&
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "B^0" \
+                       c1 empty c2 &&
+               test_cmp c1 y/c~merged
        )
 '
 
@@ -3689,7 +3739,7 @@ test_expect_success '11e-check: Avoid deleting not-uptodate with dir rename/rena
 #   Commit O: z/{a,b},        x/{c_1,d_2}
 #   Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
 #   Commit B: z/{a,b,wham_2}, x/c_1
-#   Expected: Failed Merge; y/{a,b} + untracked y/{wham~B^0,wham~B^HEAD} +
+#   Expected: Failed Merge; y/{a,b} + untracked y/{wham~merged} +
 #             y/wham with dirty changes from before merge +
 #             CONFLICT(rename/rename) x/c vs x/d -> y/wham
 #             ERROR_MSG(Refusing to lose dirty file at y/wham)
@@ -3741,24 +3791,30 @@ test_expect_success '11f-check: Avoid deleting not-uptodate with dir rename/rena
                git ls-files -u >out &&
                test_line_count = 2 out &&
                git ls-files -o >out &&
-               test_line_count = 4 out &&
+               test_line_count = 3 out &&
 
                test_seq 1 10 >expected &&
                echo important >>expected &&
                test_cmp expected y/wham &&
 
                test_must_fail git rev-parse :1:y/wham &&
-               git hash-object >actual \
-                       y/wham~B^0 y/wham~HEAD &&
-               git rev-parse >expect \
-                       O:x/d      O:x/c &&
-               test_cmp expect actual &&
 
                git rev-parse >actual \
                        :0:y/a :0:y/b :2:y/wham :3:y/wham &&
                git rev-parse >expect \
                         O:z/a  O:z/b  O:x/c     O:x/d &&
-               test_cmp expect actual
+               test_cmp expect actual &&
+
+               # Test that the two-way merge in y/wham~merged is as expected
+               git cat-file -p :2:y/wham >expect &&
+               git cat-file -p :3:y/wham >other &&
+               >empty &&
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "B^0" \
+                       expect empty other &&
+               test_cmp expect y/wham~merged
        )
 '
 
index 5d6d3184ac390f2cd476a322cf6d15e69a912494..d638119750c5b9f11682814de466cc19a9d38770 100755 (executable)
@@ -133,8 +133,8 @@ test_expect_success 'tag replaced commit' '
 
 test_expect_success '"git fsck" works' '
      git fsck master >fsck_master.out &&
-     grep "dangling commit $R" fsck_master.out &&
-     grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out &&
+     test_i18ngrep "dangling commit $R" fsck_master.out &&
+     test_i18ngrep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out &&
      test -z "$(git fsck)"
 '
 
index e436a7396241e6aad71a5f62500ffe0b9d7c0b7e..457cc167c774a0e4551cfc98c4f9aec6a17e1416 100755 (executable)
@@ -31,7 +31,7 @@ test_expect_success 'setup a tree' '
        mkdir sub &&
        while read path
        do
-               : >$path &&
+               echo content >$path &&
                git add $path || return 1
        done <expect &&
        git commit -m "initial commit" &&
@@ -48,6 +48,10 @@ test_expect_success 'pathspec with labels and non existent .gitattributes' '
        test_must_be_empty actual
 '
 
+test_expect_success 'pathspec with labels and non existent .gitattributes (2)' '
+       test_must_fail git grep content HEAD -- ":(attr:label)"
+'
+
 test_expect_success 'setup .gitattributes' '
        cat <<-\EOF >.gitattributes &&
        fileA labelA
@@ -74,6 +78,15 @@ test_expect_success 'check specific set attr' '
        test_cmp expect actual
 '
 
+test_expect_success 'check specific set attr (2)' '
+       cat <<-\EOF >expect &&
+       HEAD:fileSetLabel
+       HEAD:sub/fileSetLabel
+       EOF
+       git grep -l content HEAD ":(attr:label)" >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'check specific unset attr' '
        cat <<-\EOF >expect &&
        fileUnsetLabel
@@ -83,6 +96,15 @@ test_expect_success 'check specific unset attr' '
        test_cmp expect actual
 '
 
+test_expect_success 'check specific unset attr (2)' '
+       cat <<-\EOF >expect &&
+       HEAD:fileUnsetLabel
+       HEAD:sub/fileUnsetLabel
+       EOF
+       git grep -l content HEAD ":(attr:-label)" >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'check specific value attr' '
        cat <<-\EOF >expect &&
        fileValue
@@ -94,6 +116,16 @@ test_expect_success 'check specific value attr' '
        test_must_be_empty actual
 '
 
+test_expect_success 'check specific value attr (2)' '
+       cat <<-\EOF >expect &&
+       HEAD:fileValue
+       HEAD:sub/fileValue
+       EOF
+       git grep -l content HEAD ":(attr:label=foo)" >actual &&
+       test_cmp expect actual &&
+       test_must_fail git grep -l content HEAD ":(attr:label=bar)"
+'
+
 test_expect_success 'check unspecified attr' '
        cat <<-\EOF >expect &&
        .gitattributes
@@ -118,6 +150,30 @@ test_expect_success 'check unspecified attr' '
        test_cmp expect actual
 '
 
+test_expect_success 'check unspecified attr (2)' '
+       cat <<-\EOF >expect &&
+       HEAD:.gitattributes
+       HEAD:fileA
+       HEAD:fileAB
+       HEAD:fileAC
+       HEAD:fileB
+       HEAD:fileBC
+       HEAD:fileC
+       HEAD:fileNoLabel
+       HEAD:fileWrongLabel
+       HEAD:sub/fileA
+       HEAD:sub/fileAB
+       HEAD:sub/fileAC
+       HEAD:sub/fileB
+       HEAD:sub/fileBC
+       HEAD:sub/fileC
+       HEAD:sub/fileNoLabel
+       HEAD:sub/fileWrongLabel
+       EOF
+       git grep -l ^ HEAD ":(attr:!label)" >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'check multiple unspecified attr' '
        cat <<-\EOF >expect &&
        .gitattributes
index 76a7cb0af7955aa618556a43cc9f2a568d8de3e8..aba2d4d6ee415ab5528ed67d518cfb26412f1142 100755 (executable)
@@ -984,6 +984,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 ce74c12da2daccd26edbb92070e5ff4eb1f09f9c..1cfa150768d7f813ba9943b4bd17887469cb1c04 100755 (executable)
@@ -75,7 +75,12 @@ test_expect_success 're-setup nested submodule' '
        GIT_WORK_TREE=../../../nested git -C sub1/.git/modules/nested config \
                core.worktree "../../../nested" &&
        # make sure this re-setup is correct
-       git status --ignore-submodules=none
+       git status --ignore-submodules=none &&
+
+       # also make sure this old setup does not regress
+       git submodule update --init --recursive >out 2>err &&
+       test_must_be_empty out &&
+       test_must_be_empty err
 '
 
 test_expect_success 'absorb the git dir in a nested submodule' '
index 293e2e1963962e49afa10882439b5106607439a1..49a37efe9c1d12567dab3997bd8307896ccaa01c 100755 (executable)
@@ -154,7 +154,7 @@ test_expect_success 'fsck detects symlinked .gitmodules file' '
                # symlink detector; this grep string comes from the config
                # variable name and will not be translated.
                test_must_fail git fsck 2>output &&
-               grep gitmodulesSymlink output
+               test_i18ngrep gitmodulesSymlink output
        )
 '
 
@@ -172,7 +172,7 @@ test_expect_success 'fsck detects non-blob .gitmodules' '
                git ls-tree HEAD | sed s/subdir/.gitmodules/ | git mktree &&
 
                test_must_fail git fsck 2>output &&
-               grep gitmodulesBlob output
+               test_i18ngrep gitmodulesBlob output
        )
 '
 
@@ -186,7 +186,7 @@ test_expect_success 'fsck detects corrupt .gitmodules' '
                git commit -m "broken gitmodules" &&
 
                git fsck 2>output &&
-               grep gitmodulesParse output &&
+               test_i18ngrep gitmodulesParse output &&
                test_i18ngrep ! "bad config" output
        )
 '
index 6a392e87bcc17712961c548c0ee84e11269aef0f..5690fe28106624f3d666ccdda1dbcdd58673fb13 100755 (executable)
@@ -66,6 +66,34 @@ test_expect_success 'fast-export master~2..master' '
 
 '
 
+test_expect_success 'fast-export --reference-excluded-parents master~2..master' '
+
+       git fast-export --reference-excluded-parents master~2..master >actual &&
+       grep commit.refs/heads/master actual >commit-count &&
+       test_line_count = 2 commit-count &&
+       sed "s/master/rewrite/" actual |
+               (cd new &&
+                git fast-import &&
+                test $MASTER = $(git rev-parse --verify refs/heads/rewrite))
+'
+
+test_expect_success 'fast-export --show-original-ids' '
+
+       git fast-export --show-original-ids master >output &&
+       grep ^original-oid output| sed -e s/^original-oid.// | sort >actual &&
+       git rev-list --objects master muss >objects-and-names &&
+       awk "{print \$1}" objects-and-names | sort >commits-trees-blobs &&
+       comm -23 actual commits-trees-blobs >unfound &&
+       test_must_be_empty unfound
+'
+
+test_expect_success 'fast-export --show-original-ids | git fast-import' '
+
+       git fast-export --show-original-ids master muss | git fast-import --quiet &&
+       test $MASTER = $(git rev-parse --verify refs/heads/master) &&
+       test $MUSS = $(git rev-parse --verify refs/tags/muss)
+'
+
 test_expect_success 'iso-8859-1' '
 
        git config i18n.commitencoding ISO8859-1 &&
@@ -325,6 +353,22 @@ test_expect_success 'rewriting tag of filtered out object' '
 )
 '
 
+test_expect_success 'rewrite tag predating pathspecs to nothing' '
+       test_create_repo rewrite_tag_predating_pathspecs &&
+       (
+               cd rewrite_tag_predating_pathspecs &&
+
+               test_commit initial &&
+
+               git tag -a -m "Some old tag" v0.0.0.0.0.0.1 &&
+
+               test_commit bar &&
+
+               git fast-export --tag-of-filtered-object=rewrite --all -- bar.t >output &&
+               grep from.$ZERO_OID output
+       )
+'
+
 cat > limit-by-paths/expected << EOF
 blob
 mark :1
@@ -366,6 +410,26 @@ test_expect_success 'path limiting with import-marks does not lose unmodified fi
        grep file0 actual
 '
 
+test_expect_success 'avoid corrupt stream with non-existent mark' '
+       test_create_repo avoid_non_existent_mark &&
+       (
+               cd avoid_non_existent_mark &&
+
+               test_commit important-path &&
+
+               test_commit ignored &&
+
+               git branch A &&
+               git branch B &&
+
+               echo foo >>important-path.t &&
+               git add important-path.t &&
+               test_commit more changes &&
+
+               git fast-export --all -- important-path.t | git fast-import --force
+       )
+'
+
 test_expect_success 'full-tree re-shows unmodified files'        '
        git checkout -f simple &&
        git fast-export --full-tree simple >actual &&
@@ -508,10 +572,20 @@ test_expect_success 'use refspec' '
        test_cmp expected actual
 '
 
-test_expect_success 'delete refspec' '
+test_expect_success 'delete ref because entire history excluded' '
        git branch to-delete &&
-       git fast-export --refspec :refs/heads/to-delete to-delete ^to-delete > actual &&
-       cat > expected <<-EOF &&
+       git fast-export to-delete ^to-delete >actual &&
+       cat >expected <<-EOF &&
+       reset refs/heads/to-delete
+       from 0000000000000000000000000000000000000000
+
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'delete refspec' '
+       git fast-export --refspec :refs/heads/to-delete >actual &&
+       cat >expected <<-EOF &&
        reset refs/heads/to-delete
        from 0000000000000000000000000000000000000000
 
index d01ad8eb2587ba32637d7ec8161811696a0aec34..3a2c6326d83b760194c600e2ccde619438200508 100755 (executable)
@@ -1434,7 +1434,8 @@ test_expect_success 'double dash "git checkout"' '
        --ignore-other-worktrees Z
        --recurse-submodules Z
        --progress Z
-       --no-quiet Z
+       --guess Z
+       --no-guess Z
        --no-... Z
        EOF
 '
@@ -1515,8 +1516,8 @@ test_expect_success 'show completes all refs' '
 
 test_expect_success '<ref>: completes paths' '
        test_completion "git show mytag:f" <<-\EOF
-       file1 Z
-       file2 Z
+       file1Z
+       file2Z
        EOF
 '
 
@@ -1525,7 +1526,7 @@ test_expect_success 'complete tree filename with spaces' '
        git add "name with spaces" &&
        git commit -m spaces &&
        test_completion "git show HEAD:nam" <<-\EOF
-       name with spaces Z
+       name with spacesZ
        EOF
 '
 
@@ -1534,12 +1535,12 @@ test_expect_success 'complete tree filename with metacharacters' '
        git add "name with \${meta}" &&
        git commit -m meta &&
        test_completion "git show HEAD:nam" <<-\EOF
-       name with ${meta} Z
-       name with spaces Z
+       name with ${meta}Z
+       name with spacesZ
        EOF
 '
 
-test_expect_success 'send-email' '
+test_expect_success PERL 'send-email' '
        test_completion "git send-email --cov" "--cover-letter " &&
        test_completion "git send-email ma" "master "
 '
index bf225c698fac81a9a94eff6d3371988ac4ff0bac..6cf3bb324e149c0180d332497edf2b2c15a6b71c 100644 (file)
@@ -1026,7 +1026,8 @@ static int push_refs(struct transport *transport,
 }
 
 
-static int has_attribute(const char *attrs, const char *attr) {
+static int has_attribute(const char *attrs, const char *attr)
+{
        int len;
        if (!attrs)
                return 0;
@@ -1225,9 +1226,8 @@ static int udt_do_read(struct unidirectional_transfer *t)
                return 0;       /* No space for more. */
 
        transfer_debug("%s is readable", t->src_name);
-       bytes = read(t->src, t->buf + t->bufuse, BUFFERSIZE - t->bufuse);
-       if (bytes < 0 && errno != EWOULDBLOCK && errno != EAGAIN &&
-               errno != EINTR) {
+       bytes = xread(t->src, t->buf + t->bufuse, BUFFERSIZE - t->bufuse);
+       if (bytes < 0) {
                error_errno(_("read(%s) failed"), t->src_name);
                return -1;
        } else if (bytes == 0) {
@@ -1254,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) {
+       if (bytes < 0) {
                error_errno(_("write(%s) failed"), t->dest_name);
                return -1;
        } else if (bytes > 0) {
index 5a74b609ffad51752ec91cc93c602f00292288d1..99678153c13a3ca442088595273fbcd6caacda29 100644 (file)
@@ -154,7 +154,7 @@ static int fetch_refs_from_bundle(struct transport *transport,
                               int nr_heads, struct ref **to_fetch)
 {
        struct bundle_transport_data *data = transport->data;
-       return unbundle(&data->header, data->fd,
+       return unbundle(the_repository, &data->header, data->fd,
                        transport->progress ? BUNDLE_VERBOSE : 0);
 }
 
@@ -1105,7 +1105,8 @@ static int run_pre_push_hook(struct transport *transport,
        return ret;
 }
 
-int transport_push(struct transport *transport,
+int transport_push(struct repository *r,
+                  struct transport *transport,
                   struct refspec *rs, int flags,
                   unsigned int *reject_reasons)
 {
@@ -1172,7 +1173,7 @@ int transport_push(struct transport *transport,
                                        oid_array_append(&commits,
                                                          &ref->new_oid);
 
-                       if (!push_unpushed_submodules(the_repository,
+                       if (!push_unpushed_submodules(r,
                                                      &commits,
                                                      transport->remote,
                                                      rs,
@@ -1197,7 +1198,7 @@ int transport_push(struct transport *transport,
                                        oid_array_append(&commits,
                                                          &ref->new_oid);
 
-                       if (find_unpushed_submodules(the_repository,
+                       if (find_unpushed_submodules(r,
                                                     &commits,
                                                     transport->remote->name,
                                                     &needs_pushing)) {
@@ -1433,7 +1434,7 @@ struct alternate_refs_data {
        void *data;
 };
 
-static int refs_from_alternate_cb(struct alternate_object_database *e,
+static int refs_from_alternate_cb(struct object_directory *e,
                                  void *data)
 {
        struct strbuf path = STRBUF_INIT;
index 9baeca2d7a34cf064a632a7677429f477cb8e014..f2ee7c4f499a0937ba4c7148db045665fcb7e4cf 100644 (file)
@@ -223,7 +223,8 @@ void transport_set_verbosity(struct transport *transport, int verbosity,
 #define REJECT_FETCH_FIRST     0x08
 #define REJECT_NEEDS_FORCE     0x10
 
-int transport_push(struct transport *connection,
+int transport_push(struct repository *repo,
+                  struct transport *connection,
                   struct refspec *rs, int flags,
                   unsigned int * reject_reasons);
 
index 0e5432461026eff15fe101cf017cd839702e5870..34ee3b13b8f8369de4315f71f0d9ab99b1d42f22 100644 (file)
@@ -299,7 +299,8 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base,
        enum interesting match;
 
        while (t->size) {
-               match = tree_entry_interesting(&t->entry, base, 0, &opt->pathspec);
+               match = tree_entry_interesting(opt->repo->index, &t->entry,
+                                              base, 0, &opt->pathspec);
                if (match) {
                        if (match == all_entries_not_interesting)
                                t->size = 0;
index 79bafbd1a23c4a9e20ec623c084778904c534be7..08210a4109c70364e630290a24478333aeee449a 100644 (file)
@@ -365,7 +365,8 @@ static void free_extended_entry(struct tree_desc_x *t)
        }
 }
 
-static inline int prune_traversal(struct name_entry *e,
+static inline int prune_traversal(struct index_state *istate,
+                                 struct name_entry *e,
                                  struct traverse_info *info,
                                  struct strbuf *base,
                                  int still_interesting)
@@ -374,10 +375,13 @@ static inline int prune_traversal(struct name_entry *e,
                return 2;
        if (still_interesting < 0)
                return still_interesting;
-       return tree_entry_interesting(e, base, 0, info->pathspec);
+       return tree_entry_interesting(istate, e, base,
+                                     0, info->pathspec);
 }
 
-int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
+int traverse_trees(struct index_state *istate,
+                  int n, struct tree_desc *t,
+                  struct traverse_info *info)
 {
        int error = 0;
        struct name_entry *entry = xmalloc(n*sizeof(*entry));
@@ -461,7 +465,7 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
                }
                if (!mask)
                        break;
-               interesting = prune_traversal(e, info, &base, interesting);
+               interesting = prune_traversal(istate, e, info, &base, interesting);
                if (interesting < 0)
                        break;
                if (interesting) {
@@ -928,7 +932,8 @@ static int match_wildcard_base(const struct pathspec_item *item,
  * Pre-condition: either baselen == base_offset (i.e. empty path)
  * or base[baselen-1] == '/' (i.e. with trailing slash).
  */
-static enum interesting do_match(const struct name_entry *entry,
+static enum interesting do_match(struct index_state *istate,
+                                const struct name_entry *entry,
                                 struct strbuf *base, int base_offset,
                                 const struct pathspec *ps,
                                 int exclude)
@@ -944,7 +949,8 @@ static enum interesting do_match(const struct name_entry *entry,
                       PATHSPEC_LITERAL |
                       PATHSPEC_GLOB |
                       PATHSPEC_ICASE |
-                      PATHSPEC_EXCLUDE);
+                      PATHSPEC_EXCLUDE |
+                      PATHSPEC_ATTR);
 
        if (!ps->nr) {
                if (!ps->recursive ||
@@ -976,14 +982,20 @@ static enum interesting do_match(const struct name_entry *entry,
 
                        if (!ps->recursive ||
                            !(ps->magic & PATHSPEC_MAXDEPTH) ||
-                           ps->max_depth == -1)
-                               return all_entries_interesting;
-
-                       return within_depth(base_str + matchlen + 1,
-                                           baselen - matchlen - 1,
-                                           !!S_ISDIR(entry->mode),
-                                           ps->max_depth) ?
-                               entry_interesting : entry_not_interesting;
+                           ps->max_depth == -1) {
+                               if (!item->attr_match_nr)
+                                       return all_entries_interesting;
+                               else
+                                       goto interesting;
+                       }
+
+                       if (within_depth(base_str + matchlen + 1,
+                                        baselen - matchlen - 1,
+                                        !!S_ISDIR(entry->mode),
+                                        ps->max_depth))
+                               goto interesting;
+                       else
+                               return entry_not_interesting;
                }
 
                /* Either there must be no base, or the base must match. */
@@ -991,12 +1003,12 @@ static enum interesting do_match(const struct name_entry *entry,
                        if (match_entry(item, entry, pathlen,
                                        match + baselen, matchlen - baselen,
                                        &never_interesting))
-                               return entry_interesting;
+                               goto interesting;
 
                        if (item->nowildcard_len < item->len) {
                                if (!git_fnmatch(item, match + baselen, entry->path,
                                                 item->nowildcard_len - baselen))
-                                       return entry_interesting;
+                                       goto interesting;
 
                                /*
                                 * Match all directories. We'll try to
@@ -1017,7 +1029,7 @@ static enum interesting do_match(const struct name_entry *entry,
                                    !ps_strncmp(item, match + baselen,
                                                entry->path,
                                                item->nowildcard_len - baselen))
-                                       return entry_interesting;
+                                       goto interesting;
                        }
 
                        continue;
@@ -1052,7 +1064,7 @@ static enum interesting do_match(const struct name_entry *entry,
                if (!git_fnmatch(item, match, base->buf + base_offset,
                                 item->nowildcard_len)) {
                        strbuf_setlen(base, base_offset + baselen);
-                       return entry_interesting;
+                       goto interesting;
                }
 
                /*
@@ -1066,7 +1078,7 @@ static enum interesting do_match(const struct name_entry *entry,
                    !ps_strncmp(item, match, base->buf + base_offset,
                                item->nowildcard_len)) {
                        strbuf_setlen(base, base_offset + baselen);
-                       return entry_interesting;
+                       goto interesting;
                }
 
                strbuf_setlen(base, base_offset + baselen);
@@ -1080,6 +1092,38 @@ static enum interesting do_match(const struct name_entry *entry,
                 */
                if (ps->recursive && S_ISDIR(entry->mode))
                        return entry_interesting;
+               continue;
+interesting:
+               if (item->attr_match_nr) {
+                       int ret;
+
+                       /*
+                        * Must not return all_entries_not_interesting
+                        * prematurely. We do not know if all entries do not
+                        * match some attributes with current attr API.
+                        */
+                       never_interesting = entry_not_interesting;
+
+                       /*
+                        * Consider all directories interesting (because some
+                        * of those files inside may match some attributes
+                        * even though the parent dir does not)
+                        *
+                        * FIXME: attributes _can_ match directories and we
+                        * can probably return all_entries_interesting or
+                        * all_entries_not_interesting here if matched.
+                        */
+                       if (S_ISDIR(entry->mode))
+                               return entry_interesting;
+
+                       strbuf_add(base, entry->path, pathlen);
+                       ret = match_pathspec_attrs(istate, base->buf + base_offset,
+                                                  base->len - base_offset, item);
+                       strbuf_setlen(base, base_offset + baselen);
+                       if (!ret)
+                               continue;
+               }
+               return entry_interesting;
        }
        return never_interesting; /* No matches */
 }
@@ -1090,12 +1134,13 @@ static enum interesting do_match(const struct name_entry *entry,
  * Pre-condition: either baselen == base_offset (i.e. empty path)
  * or base[baselen-1] == '/' (i.e. with trailing slash).
  */
-enum interesting tree_entry_interesting(const struct name_entry *entry,
+enum interesting tree_entry_interesting(struct index_state *istate,
+                                       const struct name_entry *entry,
                                        struct strbuf *base, int base_offset,
                                        const struct pathspec *ps)
 {
        enum interesting positive, negative;
-       positive = do_match(entry, base, base_offset, ps, 0);
+       positive = do_match(istate, entry, base, base_offset, ps, 0);
 
        /*
         * case | entry | positive | negative | result
@@ -1132,7 +1177,7 @@ enum interesting tree_entry_interesting(const struct name_entry *entry,
            positive <= entry_not_interesting) /* #1, #2, #11, #12 */
                return positive;
 
-       negative = do_match(entry, base, base_offset, ps, 1);
+       negative = do_match(istate, entry, base, base_offset, ps, 1);
 
        /* #8, #18 */
        if (positive == all_entries_interesting &&
index 196831007e618f808661bf4b7f54030890f48563..eefd26bb6214916f7c451d97710b5ee443e52088 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef TREE_WALK_H
 #define TREE_WALK_H
 
+struct index_state;
 struct strbuf;
 
 struct name_entry {
@@ -48,7 +49,7 @@ void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);
 
 struct traverse_info;
 typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
-int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info);
+int traverse_trees(struct index_state *istate, int n, struct tree_desc *t, struct traverse_info *info);
 
 enum follow_symlinks_result {
        FOUND = 0, /* This includes out-of-tree links */
@@ -98,8 +99,9 @@ enum interesting {
        all_entries_interesting = 2 /* yes, and all subsequent entries will be */
 };
 
-extern enum interesting tree_entry_interesting(const struct name_entry *,
-                                              struct strbuf *, int,
-                                              const struct pathspec *ps);
+enum interesting tree_entry_interesting(struct index_state *istate,
+                                       const struct name_entry *,
+                                       struct strbuf *, int,
+                                       const struct pathspec *ps);
 
 #endif
diff --git a/tree.c b/tree.c
index 215d3fdc7c4af2ef2faca1cf5d5d0b5de52b84a8..0b5c84d0d79ff6e598d50c829df47c4dcce7d32c 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -60,7 +60,8 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base
                                  ADD_CACHE_JUST_APPEND);
 }
 
-static int read_tree_1(struct tree *tree, struct strbuf *base,
+static int read_tree_1(struct repository *r,
+                      struct tree *tree, struct strbuf *base,
                       int stage, const struct pathspec *pathspec,
                       read_tree_fn_t fn, void *context)
 {
@@ -77,7 +78,8 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
 
        while (tree_entry(&desc, &entry)) {
                if (retval != all_entries_interesting) {
-                       retval = tree_entry_interesting(&entry, base, 0, pathspec);
+                       retval = tree_entry_interesting(r->index, &entry,
+                                                       base, 0, pathspec);
                        if (retval == all_entries_not_interesting)
                                break;
                        if (retval == entry_not_interesting)
@@ -99,7 +101,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
                else if (S_ISGITLINK(entry.mode)) {
                        struct commit *commit;
 
-                       commit = lookup_commit(the_repository, entry.oid);
+                       commit = lookup_commit(r, entry.oid);
                        if (!commit)
                                die("Commit %s in submodule path %s%s not found",
                                    oid_to_hex(entry.oid),
@@ -118,7 +120,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(the_repository, &oid),
+               retval = read_tree_1(r, lookup_tree(r, &oid),
                                     base, stage, pathspec,
                                     fn, context);
                strbuf_setlen(base, oldlen);
@@ -128,7 +130,8 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
        return 0;
 }
 
-int read_tree_recursive(struct tree *tree,
+int read_tree_recursive(struct repository *r,
+                       struct tree *tree,
                        const char *base, int baselen,
                        int stage, const struct pathspec *pathspec,
                        read_tree_fn_t fn, void *context)
@@ -137,7 +140,7 @@ int read_tree_recursive(struct tree *tree,
        int ret;
 
        strbuf_add(&sb, base, baselen);
-       ret = read_tree_1(tree, &sb, stage, pathspec, fn, context);
+       ret = read_tree_1(r, tree, &sb, stage, pathspec, fn, context);
        strbuf_release(&sb);
        return ret;
 }
@@ -152,8 +155,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_)
                                  ce2->name, ce2->ce_namelen, ce_stage(ce2));
 }
 
-int read_tree(struct tree *tree, int stage, struct pathspec *match,
-             struct index_state *istate)
+int read_tree(struct repository *r, struct tree *tree, int stage,
+             struct pathspec *match, struct index_state *istate)
 {
        read_tree_fn_t fn = NULL;
        int i, err;
@@ -181,7 +184,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
 
        if (!fn)
                fn = read_one_entry_quick;
-       err = read_tree_recursive(tree, "", 0, stage, match, fn, istate);
+       err = read_tree_recursive(r, tree, "", 0, stage, match, fn, istate);
        if (fn == read_one_entry || err)
                return err;
 
diff --git a/tree.h b/tree.h
index d4807dc805827e6fe07fd01721a8a4680af3403f..93837450739c23e69f3040b8747a54ede26df646 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -3,7 +3,7 @@
 
 #include "object.h"
 
-extern const char *tree_type;
+struct repository;
 struct strbuf;
 
 struct tree {
@@ -12,6 +12,8 @@ struct tree {
        unsigned long size;
 };
 
+extern const char *tree_type;
+
 struct tree *lookup_tree(struct repository *r, const struct object_id *oid);
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
@@ -29,12 +31,14 @@ struct tree *parse_tree_indirect(const struct object_id *oid);
 #define READ_TREE_RECURSIVE 1
 typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, int, void *);
 
-extern int read_tree_recursive(struct tree *tree,
-                              const char *base, int baselen,
-                              int stage, const struct pathspec *pathspec,
-                              read_tree_fn_t fn, void *context);
+int read_tree_recursive(struct repository *r,
+                       struct tree *tree,
+                       const char *base, int baselen,
+                       int stage, const struct pathspec *pathspec,
+                       read_tree_fn_t fn, void *context);
 
-extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec,
-                    struct index_state *istate);
+int read_tree(struct repository *r, struct tree *tree,
+             int stage, struct pathspec *pathspec,
+             struct index_state *istate);
 
 #endif /* TREE_H */
index 7570df481bf69824e4b163a6c7a15985b72d1326..94265a7df0fe78e49b720b7514d0457645f9ff05 100644 (file)
@@ -294,7 +294,7 @@ static void load_gitmodules_file(struct index_state *index,
                        repo_read_gitmodules(the_repository);
                } else if (state && (ce->ce_flags & CE_UPDATE)) {
                        submodule_free(the_repository);
-                       checkout_entry(ce, state, NULL);
+                       checkout_entry(ce, state, NULL, NULL);
                        repo_read_gitmodules(the_repository);
                }
        }
@@ -450,12 +450,12 @@ static int check_updates(struct unpack_trees_options *o)
                        display_progress(progress, ++cnt);
                        ce->ce_flags &= ~CE_UPDATE;
                        if (o->update && !o->dry_run) {
-                               errs |= checkout_entry(ce, &state, NULL);
+                               errs |= checkout_entry(ce, &state, NULL, NULL);
                        }
                }
        }
        stop_progress(&progress);
-       errs |= finish_delayed_checkout(&state);
+       errs |= finish_delayed_checkout(&state, NULL);
        if (o->update)
                git_attr_set_direction(GIT_ATTR_CHECKIN);
 
@@ -794,6 +794,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
                                    struct name_entry *names,
                                    struct traverse_info *info)
 {
+       struct unpack_trees_options *o = info->data;
        int i, ret, bottom;
        int nr_buf = 0;
        struct tree_desc t[MAX_UNPACK_TREES];
@@ -804,7 +805,6 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
 
        nr_entries = all_trees_same_as_cache_tree(n, dirmask, names, info);
        if (nr_entries > 0) {
-               struct unpack_trees_options *o = info->data;
                int pos = index_pos_by_traverse_info(names, info);
 
                if (!o->merge || df_conflicts)
@@ -863,7 +863,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
        }
 
        bottom = switch_cache_bottom(&newinfo);
-       ret = traverse_trees(n, t, &newinfo);
+       ret = traverse_trees(o->src_index, n, t, &newinfo);
        restore_cache_bottom(&newinfo, bottom);
 
        for (i = 0; i < nr_buf; i++)
@@ -1550,7 +1550,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
                }
 
                trace_performance_enter();
-               ret = traverse_trees(len, t, &info);
+               ret = traverse_trees(o->src_index, len, t, &info);
                trace_performance_leave("traverse_trees");
                if (ret < 0)
                        goto return_failed;
@@ -1630,7 +1630,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
                move_index_extensions(&o->result, o->src_index);
                if (!ret) {
                        if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
-                               cache_tree_verify(&o->result);
+                               cache_tree_verify(the_repository, &o->result);
                        if (!o->result.cache_tree)
                                o->result.cache_tree = cache_tree();
                        if (!cache_tree_fully_valid(o->result.cache_tree))
diff --git a/url.c b/url.c
index eaf4f07081eae122fbc38e05f60ee2f11a0c65a6..25576c390baa79cb0a203d7f682e8f3442f91a60 100644 (file)
--- a/url.c
+++ b/url.c
@@ -104,7 +104,8 @@ void end_url_with_slash(struct strbuf *buf, const char *url)
        strbuf_complete(buf, '/');
 }
 
-void str_end_url_with_slash(const char *url, char **dest) {
+void str_end_url_with_slash(const char *url, char **dest)
+{
        struct strbuf buf = STRBUF_INIT;
        end_url_with_slash(&buf, url);
        free(*dest);
index 46d34cc2a436c6084531d39628d013785700e2ba..3a78fbf5044fbc5d5624ce94e54eb4ab325e2cf1 100644 (file)
@@ -265,7 +265,8 @@ int userdiff_config(const char *k, const char *v)
        return 0;
 }
 
-struct userdiff_driver *userdiff_find_by_name(const char *name) {
+struct userdiff_driver *userdiff_find_by_name(const char *name)
+{
        int len = strlen(name);
        return userdiff_find_by_namelen(name, len);
 }
@@ -290,7 +291,8 @@ struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
        return userdiff_find_by_name(check->items[0].value);
 }
 
-struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
+struct userdiff_driver *userdiff_get_textconv(struct repository *r,
+                                             struct userdiff_driver *driver)
 {
        if (!driver->textconv)
                return NULL;
@@ -300,7 +302,7 @@ struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
                struct strbuf name = STRBUF_INIT;
 
                strbuf_addf(&name, "textconv/%s", driver->name);
-               notes_cache_init(c, name.buf, driver->textconv);
+               notes_cache_init(r, c, name.buf, driver->textconv);
                driver->textconv_cache = c;
                strbuf_release(&name);
        }
index b072bfe89a46efb47c2808b5469bdf1bbfb4cc63..203057e13e508adaaef1394da9fb086284c79733 100644 (file)
@@ -4,6 +4,7 @@
 #include "notes-cache.h"
 
 struct index_state;
+struct repository;
 
 struct userdiff_funcname {
        const char *pattern;
@@ -30,6 +31,7 @@ struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
  * Initialize any textconv-related fields in the driver and return it, or NULL
  * if it does not have textconv enabled at all.
  */
-struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver);
+struct userdiff_driver *userdiff_get_textconv(struct repository *r,
+                                             struct userdiff_driver *driver);
 
 #endif /* USERDIFF */
index a24711374c41918bed46fbe5d5a3060312917fa6..0fe3bcd4cd057b72a61cfc6d46e892ac890f0634 100644 (file)
@@ -119,9 +119,10 @@ static void status_printf_more(struct wt_status *s, const char *color,
        va_end(ap);
 }
 
-void wt_status_prepare(struct wt_status *s)
+void wt_status_prepare(struct repository *r, struct wt_status *s)
 {
        memset(s, 0, sizeof(*s));
+       s->repo = r;
        memcpy(s->color_palette, default_wt_status_colors,
               sizeof(default_wt_status_colors));
        s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
@@ -494,19 +495,19 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
        }
 }
 
-static int unmerged_mask(const char *path)
+static int unmerged_mask(struct index_state *istate, const char *path)
 {
        int pos, mask;
        const struct cache_entry *ce;
 
-       pos = cache_name_pos(path, strlen(path));
+       pos = index_name_pos(istate, path, strlen(path));
        if (0 <= pos)
                return 0;
 
        mask = 0;
        pos = -pos-1;
-       while (pos < active_nr) {
-               ce = active_cache[pos++];
+       while (pos < istate->cache_nr) {
+               ce = istate->cache[pos++];
                if (strcmp(ce->name, path) || !ce_stage(ce))
                        break;
                mask |= (1 << (ce_stage(ce) - 1));
@@ -566,7 +567,8 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
                        s->committable = 1;
                        break;
                case DIFF_STATUS_UNMERGED:
-                       d->stagemask = unmerged_mask(p->two->path);
+                       d->stagemask = unmerged_mask(s->repo->index,
+                                                    p->two->path);
                        /*
                         * Don't bother setting {mode,oid}_{head,index} since the print
                         * code will output the stage values directly and not use the
@@ -585,7 +587,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
 {
        struct rev_info rev;
 
-       repo_init_revisions(the_repository, &rev, NULL);
+       repo_init_revisions(s->repo, &rev, NULL);
        setup_revisions(0, NULL, &rev, NULL);
        rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
        rev.diffopt.flags.dirty_submodules = 1;
@@ -610,7 +612,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
        struct rev_info rev;
        struct setup_revision_opt opt;
 
-       repo_init_revisions(the_repository, &rev, NULL);
+       repo_init_revisions(s->repo, &rev, NULL);
        memset(&opt, 0, sizeof(opt));
        opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
        setup_revisions(0, NULL, &rev, &opt);
@@ -643,14 +645,15 @@ static void wt_status_collect_changes_index(struct wt_status *s)
 
 static void wt_status_collect_changes_initial(struct wt_status *s)
 {
+       struct index_state *istate = s->repo->index;
        int i;
 
-       for (i = 0; i < active_nr; i++) {
+       for (i = 0; i < istate->cache_nr; i++) {
                struct string_list_item *it;
                struct wt_status_change_data *d;
-               const struct cache_entry *ce = active_cache[i];
+               const struct cache_entry *ce = istate->cache[i];
 
-               if (!ce_path_match(&the_index, ce, &s->pathspec, NULL))
+               if (!ce_path_match(istate, ce, &s->pathspec, NULL))
                        continue;
                if (ce_intent_to_add(ce))
                        continue;
@@ -684,6 +687,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
        int i;
        struct dir_struct dir;
        uint64_t t_begin = getnanotime();
+       struct index_state *istate = s->repo->index;
 
        if (!s->show_untracked_files)
                return;
@@ -698,25 +702,25 @@ static void wt_status_collect_untracked(struct wt_status *s)
                if (s->show_ignored_mode == SHOW_MATCHING_IGNORED)
                        dir.flags |= DIR_SHOW_IGNORED_TOO_MODE_MATCHING;
        } else {
-               dir.untracked = the_index.untracked;
+               dir.untracked = istate->untracked;
        }
 
        setup_standard_excludes(&dir);
 
-       fill_directory(&dir, &the_index, &s->pathspec);
+       fill_directory(&dir, istate, &s->pathspec);
 
        for (i = 0; i < dir.nr; i++) {
                struct dir_entry *ent = dir.entries[i];
-               if (cache_name_is_other(ent->name, ent->len) &&
-                   dir_path_match(&the_index, ent, &s->pathspec, 0, NULL))
+               if (index_name_is_other(istate, ent->name, ent->len) &&
+                   dir_path_match(istate, ent, &s->pathspec, 0, NULL))
                        string_list_insert(&s->untracked, ent->name);
                free(ent);
        }
 
        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(&the_index, ent, &s->pathspec, 0, NULL))
+               if (index_name_is_other(istate, ent->name, ent->len) &&
+                   dir_path_match(istate, ent, &s->pathspec, 0, NULL))
                        string_list_insert(&s->ignored, ent->name);
                free(ent);
        }
@@ -751,7 +755,7 @@ void wt_status_collect(struct wt_status *s)
                wt_status_collect_changes_index(s);
        wt_status_collect_untracked(s);
 
-       wt_status_get_state(&s->state, s->branch && !strcmp(s->branch, "HEAD"));
+       wt_status_get_state(s->repo, &s->state, s->branch && !strcmp(s->branch, "HEAD"));
        if (s->state.merge_in_progress && !has_unmerged(s))
                s->committable = 1;
 }
@@ -1009,7 +1013,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
        int dirty_submodules;
        const char *c = color(WT_STATUS_HEADER, s);
 
-       repo_init_revisions(the_repository, &rev, NULL);
+       repo_init_revisions(s->repo, &rev, NULL);
        rev.diffopt.flags.allow_textconv = 1;
        rev.diffopt.ita_invisible_in_index = 1;
 
@@ -1326,7 +1330,7 @@ static void show_rebase_in_progress(struct wt_status *s,
                                _("  (use \"git rebase --abort\" to check out the original branch)"));
                }
        } else if (s->state.rebase_in_progress ||
-                  !stat(git_path_merge_msg(the_repository), &st)) {
+                  !stat(git_path_merge_msg(s->repo), &st)) {
                print_rebase_state(s, color);
                if (s->hints)
                        status_printf_ln(s, color,
@@ -1478,7 +1482,8 @@ static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,
        return 1;
 }
 
-static void wt_status_get_detached_from(struct wt_status_state *state)
+static void wt_status_get_detached_from(struct repository *r,
+                                       struct wt_status_state *state)
 {
        struct grab_1st_switch_cbdata cb;
        struct commit *commit;
@@ -1495,7 +1500,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
            /* sha1 is a commit? match without further lookup */
            (oideq(&cb.noid, &oid) ||
             /* perhaps sha1 is a tag, try to dereference to a commit */
-            ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&
+            ((commit = lookup_commit_reference_gently(r, &oid, 1)) != NULL &&
              oideq(&cb.noid, &commit->object.oid)))) {
                const char *from = ref;
                if (!skip_prefix(from, "refs/tags/", &from))
@@ -1552,31 +1557,32 @@ int wt_status_check_bisect(const struct worktree *wt,
        return 0;
 }
 
-void wt_status_get_state(struct wt_status_state *state,
+void wt_status_get_state(struct repository *r,
+                        struct wt_status_state *state,
                         int get_detached_from)
 {
        struct stat st;
        struct object_id oid;
 
-       if (!stat(git_path_merge_head(the_repository), &st)) {
+       if (!stat(git_path_merge_head(r), &st)) {
                wt_status_check_rebase(NULL, state);
                state->merge_in_progress = 1;
        } else if (wt_status_check_rebase(NULL, state)) {
                ;               /* all set */
-       } else if (!stat(git_path_cherry_pick_head(the_repository), &st) &&
+       } else if (!stat(git_path_cherry_pick_head(r), &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(the_repository), &st) &&
+       if (!stat(git_path_revert_head(r), &st) &&
            !get_oid("REVERT_HEAD", &oid)) {
                state->revert_in_progress = 1;
                oidcpy(&state->revert_head_oid, &oid);
        }
 
        if (get_detached_from)
-               wt_status_get_detached_from(state);
+               wt_status_get_detached_from(r, state);
 }
 
 static void wt_longstatus_print_state(struct wt_status *s)
@@ -2140,6 +2146,7 @@ static void wt_porcelain_v2_print_unmerged_entry(
        struct wt_status *s)
 {
        struct wt_status_change_data *d = it->util;
+       struct index_state *istate = s->repo->index;
        const struct cache_entry *ce;
        struct strbuf buf_index = STRBUF_INIT;
        const char *path_index = NULL;
@@ -2178,11 +2185,11 @@ static void wt_porcelain_v2_print_unmerged_entry(
         */
        memset(stages, 0, sizeof(stages));
        sum = 0;
-       pos = cache_name_pos(it->string, strlen(it->string));
+       pos = index_name_pos(istate, it->string, strlen(it->string));
        assert(pos < 0);
        pos = -pos-1;
-       while (pos < active_nr) {
-               ce = active_cache[pos++];
+       while (pos < istate->cache_nr) {
+               ce = istate->cache[pos++];
                stage = ce_stage(ce);
                if (strcmp(ce->name, it->string) || !stage)
                        break;
@@ -2307,12 +2314,12 @@ void wt_status_print(struct wt_status *s)
 /**
  * Returns 1 if there are unstaged changes, 0 otherwise.
  */
-int has_unstaged_changes(int ignore_submodules)
+int has_unstaged_changes(struct repository *r, int ignore_submodules)
 {
        struct rev_info rev_info;
        int result;
 
-       repo_init_revisions(the_repository, &rev_info, NULL);
+       repo_init_revisions(r, &rev_info, NULL);
        if (ignore_submodules) {
                rev_info.diffopt.flags.ignore_submodules = 1;
                rev_info.diffopt.flags.override_submodule_config = 1;
@@ -2326,15 +2333,16 @@ int has_unstaged_changes(int ignore_submodules)
 /**
  * Returns 1 if there are uncommitted changes, 0 otherwise.
  */
-int has_uncommitted_changes(int ignore_submodules)
+int has_uncommitted_changes(struct repository *r,
+                           int ignore_submodules)
 {
        struct rev_info rev_info;
        int result;
 
-       if (is_cache_unborn())
+       if (is_index_unborn(r->index))
                return 0;
 
-       repo_init_revisions(the_repository, &rev_info, NULL);
+       repo_init_revisions(r, &rev_info, NULL);
        if (ignore_submodules)
                rev_info.diffopt.flags.ignore_submodules = 1;
        rev_info.diffopt.flags.quick = 1;
@@ -2345,7 +2353,7 @@ int has_uncommitted_changes(int ignore_submodules)
                 * 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);
+               struct tree *tree = lookup_tree(r, the_hash_algo->empty_tree);
                add_pending_object(&rev_info, &tree->object, "");
        }
 
@@ -2358,24 +2366,28 @@ int has_uncommitted_changes(int ignore_submodules)
  * If the work tree has unstaged or uncommitted changes, dies with the
  * appropriate message.
  */
-int require_clean_work_tree(const char *action, const char *hint, int ignore_submodules, int gently)
+int require_clean_work_tree(struct repository *r,
+                           const char *action,
+                           const char *hint,
+                           int ignore_submodules,
+                           int gently)
 {
        struct lock_file lock_file = LOCK_INIT;
        int err = 0, fd;
 
        fd = hold_locked_index(&lock_file, 0);
-       refresh_cache(REFRESH_QUIET);
+       refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
        if (0 <= fd)
-               update_index_if_able(&the_index, &lock_file);
+               update_index_if_able(r->index, &lock_file);
        rollback_lock_file(&lock_file);
 
-       if (has_unstaged_changes(ignore_submodules)) {
+       if (has_unstaged_changes(r, ignore_submodules)) {
                /* TRANSLATORS: the action is e.g. "pull with rebase" */
                error(_("cannot %s: You have unstaged changes."), _(action));
                err = 1;
        }
 
-       if (has_uncommitted_changes(ignore_submodules)) {
+       if (has_uncommitted_changes(r, ignore_submodules)) {
                if (err)
                        error(_("additionally, your index contains uncommitted changes."));
                else
index 1fcf93afbf57a9a6384b6be485846cd35fb3f465..3a95975032bb1ee8d87cca4e8a1bbc0afe62e42c 100644 (file)
@@ -7,6 +7,7 @@
 #include "pathspec.h"
 #include "remote.h"
 
+struct repository;
 struct worktree;
 
 enum color_wt_status {
@@ -83,6 +84,7 @@ struct wt_status_state {
 };
 
 struct wt_status {
+       struct repository *repo;
        int is_initial;
        char *branch;
        const char *reference;
@@ -128,11 +130,13 @@ struct wt_status {
 
 size_t wt_status_locate_end(const char *s, size_t len);
 void wt_status_add_cut_line(FILE *fp);
-void wt_status_prepare(struct wt_status *s);
+void wt_status_prepare(struct repository *r, struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
 void wt_status_collect_free_buffers(struct wt_status *s);
-void wt_status_get_state(struct wt_status_state *state, int get_detached_from);
+void wt_status_get_state(struct repository *repo,
+                        struct wt_status_state *state,
+                        int get_detached_from);
 int wt_status_check_rebase(const struct worktree *wt,
                           struct wt_status_state *state);
 int wt_status_check_bisect(const struct worktree *wt,
@@ -144,9 +148,14 @@ __attribute__((format (printf, 3, 4)))
 void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
 
 /* The following functions expect that the caller took care of reading the index. */
-int has_unstaged_changes(int ignore_submodules);
-int has_uncommitted_changes(int ignore_submodules);
-int require_clean_work_tree(const char *action, const char *hint,
-       int ignore_submodules, int gently);
+int has_unstaged_changes(struct repository *repo,
+                        int ignore_submodules);
+int has_uncommitted_changes(struct repository *repo,
+                           int ignore_submodules);
+int require_clean_work_tree(struct repository *repo,
+                           const char *action,
+                           const char *hint,
+                           int ignore_submodules,
+                           int gently);
 
 #endif /* STATUS_H */