]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'hd/config-mak-os390'
authorJunio C Hamano <gitster@pobox.com>
Fri, 15 Mar 2024 23:06:00 +0000 (16:06 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 15 Mar 2024 23:06:00 +0000 (16:06 -0700)
Platform specific tweaks for OS/390 has been added to
config.mak.uname.

* hd/config-mak-os390:
  build: support z/OS (OS/390).

122 files changed:
Documentation/RelNotes/2.45.0.txt
Documentation/config.txt
Documentation/config/advice.txt
Documentation/config/clean.txt
Documentation/config/core.txt
Documentation/config/transfer.txt
Documentation/git-clean.txt
Documentation/git-merge-tree.txt
Documentation/git.txt
Documentation/gitcli.txt
Documentation/gitprotocol-v2.txt
Documentation/rev-list-options.txt
advice.c
advice.h
bisect.c
branch.c
builtin/add.c
builtin/branch.c
builtin/checkout.c
builtin/clean.c
builtin/clone.c
builtin/commit.c
builtin/fast-import.c
builtin/fetch.c
builtin/index-pack.c
builtin/interpret-trailers.c
builtin/log.c
builtin/merge-base.c
builtin/merge-tree.c
builtin/merge.c
builtin/pull.c
builtin/read-tree.c
builtin/rebase.c
builtin/receive-pack.c
builtin/remote.c
builtin/repack.c
builtin/reset.c
builtin/rev-list.c
builtin/rev-parse.c
builtin/unpack-objects.c
builtin/upload-pack.c
cache-tree.c
commit-reach.c
commit-reach.h
commit.c
contrib/completion/git-completion.bash
diff-lib.c
dir.c
dir.h
environment.c
environment.h
fsmonitor.c
git.c
http-push.c
list-objects-filter.c
log-tree.c
merge-ort.c
merge-recursive.c
merge.c
name-hash.c
name-hash.h
notes-merge.c
object-name.c
object.c
object.h
oidset.c
oidset.h
pretty.c
ref-filter.c
refs/reftable-backend.c
reftable/block.c
reftable/block.h
reftable/iter.c
reftable/iter.h
reftable/merged.c
reftable/merged.h
reftable/pq.c
reftable/pq.h
reftable/pq_test.c
reftable/record.c
reftable/record.h
reftable/record_test.c
reftable/reftable-record.h
remote.c
reset.c
revision.c
sequencer.c
serve.c
setup.c
shallow.c
sideband.c
submodule.c
t/helper/test-reach.c
t/t0010-racy-git.sh
t/t0410-partial-clone.sh
t/t0610-reftable-basics.sh
t/t1301-shared-repo.sh
t/t3200-branch.sh
t/t4201-shortlog.sh
t/t4301-merge-tree-write-tree.sh
t/t5555-http-smart-common.sh
t/t5606-clone-options.sh
t/t5701-git-serve.sh
t/t5702-protocol-v2.sh
t/t5801/git-remote-testgit
t/t6022-rev-list-missing.sh
t/t6030-bisect-porcelain.sh
t/t7300-clean.sh
t/t7301-clean-interactive.sh
t/t7502-commit-porcelain.sh
t/t7527-builtin-fsmonitor.sh
t/t9117-git-svn-init-clone.sh
t/t9902-completion.sh
t/test-lib-functions.sh
t/unit-tests/t-ctype.c
trailer.c
trailer.h
transport-helper.c
tree-walk.c
upload-pack.c
wt-status.c
wt-status.h

index fe8832b8df6b909917fae25c6e26fe9ef245322a..b7662931f58342bececc5409a2a59aa99ad8b7dd 100644 (file)
@@ -24,6 +24,16 @@ UI, Workflows & Features
  * "git for-each-ref" learned "--include-root-refs" option to show
    even the stuff outside the 'refs/' hierarchy.
 
+ * "git rev-list --missing=print" has learned to optionally take
+   "--allow-missing-tips", which allows the objects at the starting
+   points to be missing.
+
+ * "git merge-tree" has learned that the three trees involved in the
+   3-way merge only need to be trees, not necessarily commits.
+
+ * "git log --merge" learned to pay attention to CHERRY_PICK_HEAD and
+   other kinds of *_HEAD pseudorefs.
+
 
 Performance, Internal Implementation, Development Support etc.
 
@@ -40,6 +50,17 @@ Performance, Internal Implementation, Development Support etc.
    specified; use "_<placeholder>_" to typeset the word inside a pair
    of <angle-brakets> emphasized.
 
+ * "git --no-lazy-fetch cmd" allows to run "cmd" while disabling lazy
+   fetching of objects from the promisor remote, which may be handy
+   for debugging.
+
+ * The implementation in "git clean" that makes "-n" and "-i" ignore
+   clean.requireForce has been simplified, together with the
+   documentation.
+
+ * The code to iterate over refs with the reftable backend has seen
+   some optimization.
+
 
 Fixes since v2.44
 -----------------
@@ -94,6 +115,53 @@ Fixes since v2.44
    to be the first header file.
    (merge 4e89f0e07c jc/doc-compat-util later to maint).
 
+ * "git commit -v --cleanup=scissors" used to add the scissors line
+   twice in the log message buffer, which has been corrected.
+   (merge e90cc075cc jt/commit-redundant-scissors-fix later to maint).
+
+ * A custom remote helper no longer cannot access the newly created
+   repository during "git clone", which is a regression in Git 2.44.
+   This has been corrected.
+   (merge 199f44cb2e ps/remote-helper-repo-initialization-fix later to maint).
+
+ * Various parts of upload-pack has been updated to bound the resource
+   consumption relative to the size of the repository to protect from
+   abusive clients.
+   (merge 6cd05e768b jk/upload-pack-bounded-resources later to maint).
+
+ * The upload-pack program, when talking over v2, accepted the
+   packfile-uris protocol extension from the client, even if it did
+   not advertise the capability, which has been corrected.
+   (merge a922bfa3b5 jk/upload-pack-v2-capability-cleanup later to maint).
+
+ * Make sure failure return from merge_bases_many() is properly caught.
+   (merge 25fd20eb44 js/merge-base-with-missing-commit later to maint).
+
+ * FSMonitor client code was confused when FSEvents were given in a
+   different case on a case-insensitive filesystem, which has been
+   corrected.
+   (merge 29c139ce78 jh/fsmonitor-icase-corner-case-fix later to maint).
+
+ * The "core.commentChar" configuration variable only allows an ASCII
+   character, which was not clearly documented, which has been
+   corrected.
+   (merge fb7c556f58 kh/doc-commentchar-is-a-byte later to maint).
+
+ * With release 2.44 we got rid of all uses of test_i18ngrep and there
+   is no in-flight topic that adds a new use of it.  Make a call to
+   test_i18ngrep a hard failure, so that we can remove it at the end
+   of this release cycle.
+   (merge 381a83dfa3 jc/test-i18ngrep later to maint).
+
+ * The command line completion script (in contrib/) learned to
+   complete "git reflog" better.
+   (merge 1284f9cc11 rj/complete-reflog later to maint).
+
+ * The logic to complete the command line arguments to "git worktree"
+   subcommand (in contrib/) has been updated to correctly honor things
+   like "git -C dir" etc.
+   (merge 3574816d98 rj/complete-worktree-paths-fix later to maint).
+
  * Other code cleanup, docfix, build fix, etc.
    (merge f0e578c69c rs/use-xstrncmpz later to maint).
    (merge 83e6eb7d7a ba/credential-test-clean-fix later to maint).
@@ -108,3 +176,5 @@ Fixes since v2.44
    (merge f39addd0d9 rs/name-rev-with-mempool later to maint).
    (merge 9a97b43e03 rs/submodule-prefix-simplify later to maint).
    (merge 40b8076462 ak/rebase-autosquash later to maint).
+   (merge 3223204456 eg/add-uflags later to maint).
+   (merge 5f78d52dce es/config-doc-sort-sections later to maint).
index e3a74dd1c19db44b3a0980cc778bf0ab4ba60b07..782c2bab906cf188e3cb21fa6d9fa8c4fe78663d 100644 (file)
@@ -369,20 +369,18 @@ inventing new variables for use in your own tool, make sure their
 names do not conflict with those that are used by Git itself and
 other popular tools, and describe them in your documentation.
 
-include::config/advice.txt[]
-
-include::config/attr.txt[]
-
-include::config/core.txt[]
-
 include::config/add.txt[]
 
+include::config/advice.txt[]
+
 include::config/alias.txt[]
 
 include::config/am.txt[]
 
 include::config/apply.txt[]
 
+include::config/attr.txt[]
+
 include::config/blame.txt[]
 
 include::config/branch.txt[]
@@ -405,10 +403,12 @@ include::config/commit.txt[]
 
 include::config/commitgraph.txt[]
 
-include::config/credential.txt[]
-
 include::config/completion.txt[]
 
+include::config/core.txt[]
+
+include::config/credential.txt[]
+
 include::config/diff.txt[]
 
 include::config/difftool.txt[]
@@ -421,10 +421,10 @@ include::config/feature.txt[]
 
 include::config/fetch.txt[]
 
-include::config/format.txt[]
-
 include::config/filter.txt[]
 
+include::config/format.txt[]
+
 include::config/fsck.txt[]
 
 include::config/fsmonitor--daemon.txt[]
@@ -435,10 +435,10 @@ include::config/gitcvs.txt[]
 
 include::config/gitweb.txt[]
 
-include::config/grep.txt[]
-
 include::config/gpg.txt[]
 
+include::config/grep.txt[]
+
 include::config/gui.txt[]
 
 include::config/guitool.txt[]
@@ -519,10 +519,10 @@ include::config/splitindex.txt[]
 
 include::config/ssh.txt[]
 
-include::config/status.txt[]
-
 include::config/stash.txt[]
 
+include::config/status.txt[]
+
 include::config/submodule.txt[]
 
 include::config/tag.txt[]
index dde8e7840ef38225995549411fbcf9305b160c37..f83341165367baac4f02779eedf432822644e615 100644 (file)
@@ -2,27 +2,27 @@ advice.*::
        These variables control various optional help messages designed to
        aid new users.  When left unconfigured, Git will give the message
        alongside instructions on how to squelch it.  You can tell Git
-       that you do not need the help message by setting these to 'false':
+       that you do not need the help message by setting these to `false`:
 +
 --
        addEmbeddedRepo::
-               Advice on what to do when you've accidentally added one
+               Shown when the user accidentally adds one
                git repo inside of another.
        addEmptyPathspec::
-               Advice shown if a user runs the add command without providing
+               Shown when the user runs `git add` without providing
                the pathspec parameter.
        addIgnoredFile::
-               Advice shown if a user attempts to add an ignored file to
+               Shown when the user attempts to add an ignored file to
                the index.
        amWorkDir::
-               Advice that shows the location of the patch file when
-               linkgit:git-am[1] fails to apply it.
+               Shown when linkgit:git-am[1] fails to apply a patch
+               file, to tell the user the location of the file.
        ambiguousFetchRefspec::
-               Advice shown when a fetch refspec for multiple remotes maps to
+               Shown when a fetch refspec for multiple remotes maps to
                the same remote-tracking branch namespace and causes branch
                tracking set-up to fail.
        checkoutAmbiguousRemoteBranchName::
-               Advice shown when the argument to
+               Shown when the argument to
                linkgit:git-checkout[1] and linkgit:git-switch[1]
                ambiguously resolves to a
                remote tracking branch on more than one remote in
@@ -33,31 +33,31 @@ advice.*::
                to be used by default in some situations where this
                advice would be printed.
        commitBeforeMerge::
-               Advice shown when linkgit:git-merge[1] refuses to
+               Shown when linkgit:git-merge[1] refuses to
                merge to avoid overwriting local changes.
        detachedHead::
-               Advice shown when you used
+               Shown when the user uses
                linkgit:git-switch[1] or linkgit:git-checkout[1]
-               to move to the detached HEAD state, to instruct how to
-               create a local branch after the fact.
+               to move to the detached HEAD state, to tell the user how
+               to create a local branch after the fact.
        diverging::
-               Advice shown when a fast-forward is not possible.
+               Shown when a fast-forward is not possible.
        fetchShowForcedUpdates::
-               Advice shown when linkgit:git-fetch[1] takes a long time
+               Shown when linkgit:git-fetch[1] takes a long time
                to calculate forced updates after ref updates, or to warn
                that the check is disabled.
        forceDeleteBranch::
-               Advice shown when a user tries to delete a not fully merged
+               Shown when the user tries to delete a not fully merged
                branch without the force option set.
        ignoredHook::
-               Advice shown if a hook is ignored because the hook is not
+               Shown when a hook is ignored because the hook is not
                set as executable.
        implicitIdentity::
-               Advice on how to set your identity configuration when
-               your information is guessed from the system username and
-               domain name.
+               Shown when the user's information is guessed from the
+               system username and domain name, to tell the user how to
+               set their identity configuration.
        nestedTag::
-               Advice shown if a user attempts to recursively tag a tag object.
+               Shown when a user attempts to recursively tag a tag object.
        pushAlreadyExists::
                Shown when linkgit:git-push[1] rejects an update that
                does not qualify for fast-forwarding (e.g., a tag.)
@@ -71,12 +71,12 @@ advice.*::
                object that is not a commit-ish, or make the remote
                ref point at an object that is not a commit-ish.
        pushNonFFCurrent::
-               Advice shown when linkgit:git-push[1] fails due to a
+               Shown when linkgit:git-push[1] fails due to a
                non-fast-forward update to the current branch.
        pushNonFFMatching::
-               Advice shown when you ran linkgit:git-push[1] and pushed
-               'matching refs' explicitly (i.e. you used ':', or
-               specified a refspec that isn't your current branch) and
+               Shown when the user ran linkgit:git-push[1] and pushed
+               "matching refs" explicitly (i.e. used `:`, or
+               specified a refspec that isn't the current branch) and
                it resulted in a non-fast-forward error.
        pushRefNeedsUpdate::
                Shown when linkgit:git-push[1] rejects a forced update of
@@ -87,25 +87,28 @@ advice.*::
                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
+               `refs/heads/*` or `refs/tags/*` based on the type of the
                source object.
        pushUpdateRejected::
-               Set this variable to 'false' if you want to disable
-               'pushNonFFCurrent', 'pushNonFFMatching', 'pushAlreadyExists',
-               'pushFetchFirst', 'pushNeedsForce', and 'pushRefNeedsUpdate'
+               Set this variable to `false` if you want to disable
+               `pushNonFFCurrent`, `pushNonFFMatching`, `pushAlreadyExists`,
+               `pushFetchFirst`, `pushNeedsForce`, and `pushRefNeedsUpdate`
                simultaneously.
+       refSyntax::
+               Shown when the user provides an illegal ref name, to
+               tell the user about the ref syntax documentation.
        resetNoRefresh::
-               Advice to consider using the `--no-refresh` option to
-               linkgit:git-reset[1] when the command takes more than 2 seconds
-               to refresh the index after reset.
+               Shown when linkgit:git-reset[1] takes more than 2
+               seconds to refresh the index after reset, to tell the user
+               that they can use the `--no-refresh` option.
        resolveConflict::
-               Advice shown by various commands when conflicts
+               Shown by various commands when conflicts
                prevent the operation from being performed.
        rmHints::
-               In case of failure in the output of linkgit:git-rm[1],
-               show directions on how to proceed from the current state.
+               Shown on failure in the output of linkgit:git-rm[1], to
+               give directions on how to proceed from the current state.
        sequencerInUse::
-               Advice shown when a sequencer command is already in progress.
+               Shown when a sequencer command is already in progress.
        skippedCherryPicks::
                Shown when linkgit:git-rebase[1] skips a commit that has already
                been cherry-picked onto the upstream branch.
@@ -123,30 +126,30 @@ advice.*::
                by linkgit:git-switch[1] or
                linkgit:git-checkout[1] when switching branches.
        statusUoption::
-               Advise to consider using the `-u` option to linkgit:git-status[1]
-               when the command takes more than 2 seconds to enumerate untracked
-               files.
+               Shown when linkgit:git-status[1] takes more than 2
+               seconds to enumerate untracked files, to tell the user that
+               they can use the `-u` option.
        submoduleAlternateErrorStrategyDie::
-               Advice shown when a submodule.alternateErrorStrategy option
+               Shown when a submodule.alternateErrorStrategy option
                configured to "die" causes a fatal error.
        submoduleMergeConflict::
                Advice shown when a non-trivial submodule merge conflict is
                encountered.
        submodulesNotUpdated::
-               Advice shown when a user runs a submodule command that fails
+               Shown when a user runs a submodule command that fails
                because `git submodule update --init` was not run.
        suggestDetachingHead::
-               Advice shown when linkgit:git-switch[1] refuses to detach HEAD
+               Shown when linkgit:git-switch[1] refuses to detach HEAD
                without the explicit `--detach` option.
        updateSparsePath::
-               Advice shown when either linkgit:git-add[1] or linkgit:git-rm[1]
+               Shown when either linkgit:git-add[1] or linkgit:git-rm[1]
                is asked to update index entries outside the current sparse
                checkout.
        waitingForEditor::
-               Print a message to the terminal whenever Git is waiting for
-               editor input from the user.
+               Shown when Git is waiting for editor input. Relevant
+               when e.g. the editor is not launched inside the terminal.
        worktreeAddOrphan::
-               Advice shown when a user tries to create a worktree from an
-               invalid reference, to instruct how to create a new unborn
+               Shown when the user tries to create a worktree from an
+               invalid reference, to tell the user how to create a new unborn
                branch instead.
 --
index f05b9403b5ad903ea68d68e896acaff253bfde37..c0188ead4e6cd8b2b38a5feecb20c24897e03161 100644 (file)
@@ -1,3 +1,3 @@
 clean.requireForce::
-       A boolean to make git-clean do nothing unless given -f,
-       -i, or -n.  Defaults to true.
+       A boolean to make git-clean refuse to delete files unless -f
+       is given. Defaults to true.
index 0e8c2832bf9b8a5251c51f346ecfcf47c7e8d530..2d4bbdb25fa3104bf5151ca98be42f0b4c438b2a 100644 (file)
@@ -521,7 +521,7 @@ core.editor::
 
 core.commentChar::
        Commands such as `commit` and `tag` that let you edit
-       messages consider a line that begins with this character
+       messages consider a line that begins with this ASCII character
        commented, and removes them after the editor returns
        (default '#').
 +
index a9cbdb88a1fe11f364da005bdfe490cd2e28dc0b..f1ce50f4a6e6baf4ffde131339e8527e34e2e90b 100644 (file)
@@ -121,3 +121,7 @@ transfer.bundleURI::
        information from the remote server (if advertised) and download
        bundles before continuing the clone through the Git protocol.
        Defaults to `false`.
+
+transfer.advertiseObjectInfo::
+       When `true`, the `object-info` capability is advertised by
+       servers. Defaults to false.
index 69331e3f05a13eed6ffb084e292f8452b241f13c..fd171654163c1fc4e34de3b24cdd4063a604dae1 100644 (file)
@@ -37,7 +37,7 @@ OPTIONS
 --force::
        If the Git configuration variable clean.requireForce is not set
        to false, 'git clean' will refuse to delete files or directories
-       unless given -f or -i.  Git will refuse to modify untracked
+       unless given -f.  Git will refuse to modify untracked
        nested git repositories (directories with a .git subdirectory)
        unless a second -f is given.
 
@@ -45,10 +45,14 @@ OPTIONS
 --interactive::
        Show what would be done and clean files interactively. See
        ``Interactive mode'' for details.
+       Configuration variable `clean.requireForce` is ignored, as
+       this mode gives its own safety protection by going interactive.
 
 -n::
 --dry-run::
        Don't actually remove anything, just show what would be done.
+       Configuration variable `clean.requireForce` is ignored, as
+       nothing will be deleted anyway.
 
 -q::
 --quiet::
index b50acace3bc367ad7b73d2da10252e6b5f2e0d07..dd388fa21d5a51d1b6c3aca1b1d18b98f69a4f88 100644 (file)
@@ -64,10 +64,13 @@ OPTIONS
        share no common history.  This flag can be given to override that
        check and make the merge proceed anyway.
 
---merge-base=<commit>::
+--merge-base=<tree-ish>::
        Instead of finding the merge-bases for <branch1> and <branch2>,
        specify a merge-base for the merge, and specifying multiple bases is
        currently not supported. This option is incompatible with `--stdin`.
++
+As the merge-base is provided directly, <branch1> and <branch2> do not need
+to specify commits; trees are enough.
 
 [[OUTPUT]]
 OUTPUT
index 0d25224c9696942b797d64895d98bbcdd80db62a..e6b766d5c3ab54e6fc97d3cf31f9093a6eac5a41 100644 (file)
@@ -174,8 +174,17 @@ If you just want to run git as if it was started in `<path>` then use
        directory.
 
 --no-replace-objects::
-       Do not use replacement refs to replace Git objects. See
-       linkgit:git-replace[1] for more information.
+       Do not use replacement refs to replace Git objects.
+       This is equivalent to exporting the `GIT_NO_REPLACE_OBJECTS`
+       environment variable with any value.
+       See linkgit:git-replace[1] for more information.
+
+--no-lazy-fetch::
+       Do not fetch missing objects from the promisor remote on
+       demand.  Useful together with `git cat-file -e <object>` to
+       see if the object is locally available.
+       This is equivalent to setting the `GIT_NO_LAZY_FETCH`
+       environment variable to `1`.
 
 --literal-pathspecs::
        Treat pathspecs literally (i.e. no globbing, no pathspec magic).
@@ -872,6 +881,10 @@ for full details.
        header and packfile URIs. Set this Boolean environment variable to false to prevent this
        redaction.
 
+`GIT_NO_REPLACE_OBJECTS`::
+       Setting and exporting this environment variable tells Git to
+       ignore replacement refs and do not replace Git objects.
+
 `GIT_LITERAL_PATHSPECS`::
        Setting this Boolean environment variable to true will cause Git to treat all
        pathspecs literally, rather than as glob patterns. For example,
@@ -893,6 +906,11 @@ for full details.
        Setting this Boolean environment variable to true will cause Git to treat all
        pathspecs as case-insensitive.
 
+`GIT_NO_LAZY_FETCH`::
+       Setting this Boolean environment variable to true tells Git
+       not to lazily fetch missing objects from the promisor remote
+       on demand.
+
 `GIT_REFLOG_ACTION`::
        When a ref is updated, reflog entries are created to keep
        track of the reason why the ref was updated (which is
index e5fac943227a23a5bf9214cddb08d48b0ce3c5ca..7c709324ba904efe5f6a544086c767fbc1ab7cb4 100644 (file)
@@ -81,9 +81,6 @@ you will.
 Here are the rules regarding the "flags" that you should follow when you are
 scripting Git:
 
- * It's preferred to use the non-dashed form of Git commands, which means that
-   you should prefer `git foo` to `git-foo`.
-
  * Splitting short options to separate words (prefer `git foo -a -b`
    to `git foo -ab`, the latter may not even work).
 
index 0b800abd567a49b24be7c9feade0596ff758df92..414bc625d5dd219faefcf7fe06aa93d6443763f4 100644 (file)
@@ -346,7 +346,8 @@ the 'wanted-refs' section in the server's response as explained below.
     want-ref <ref>
        Indicates to the server that the client wants to retrieve a
        particular ref, where <ref> is the full name of a ref on the
-       server.
+       server.  It is a protocol error to send want-ref for the
+       same ref more than once.
 
 If the 'sideband-all' feature is advertised, the following argument can be
 included in the client's request:
@@ -361,7 +362,8 @@ included in the client's request:
 If the 'packfile-uris' feature is advertised, the following argument
 can be included in the client's request as well as the potential
 addition of the 'packfile-uris' section in the server's response as
-explained below.
+explained below. Note that at most one `packfile-uris` line can be sent
+to the server.
 
     packfile-uris <comma-separated-list-of-protocols>
        Indicates to the server that the client is willing to receive
index a583b52c612aece1f7d1fd24086c0f7961eecceb..408d9314d0887969a8cb485b59265a3c4b570ced 100644 (file)
@@ -341,8 +341,11 @@ See also linkgit:git-reflog[1].
 Under `--pretty=reference`, this information will not be shown at all.
 
 --merge::
-       After a failed merge, show refs that touch files having a
-       conflict and don't exist on all heads to merge.
+       Show commits touching conflicted paths in the range `HEAD...<other>`,
+       where `<other>` is the first existing pseudoref in `MERGE_HEAD`,
+       `CHERRY_PICK_HEAD`, `REVERT_HEAD` or `REBASE_HEAD`. Only works
+       when the index has unmerged entries. This option can be used to show
+       relevant commits when resolving conflicts from a 3-way merge.
 
 --boundary::
        Output excluded boundary commits. Boundary commits are
@@ -1019,6 +1022,10 @@ Unexpected missing objects will raise an error.
 +
 The form '--missing=print' is like 'allow-any', but will also print a
 list of the missing objects.  Object IDs are prefixed with a ``?'' character.
++
+If some tips passed to the traversal are missing, they will be
+considered as missing too, and the traversal will ignore them. In case
+we cannot get their Object ID though, an error will be raised.
 
 --exclude-promisor-objects::
        (For internal use only.)  Prefilter object traversal at
index 4ba64ee5b2d315eeeaa6143f5c8c2053d066a830..b0e05506871b9c402b75ad7ba52c47776797611d 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -68,6 +68,7 @@ static struct {
        [ADVICE_PUSH_UNQUALIFIED_REF_NAME]              = { "pushUnqualifiedRefName" },
        [ADVICE_PUSH_UPDATE_REJECTED]                   = { "pushUpdateRejected" },
        [ADVICE_PUSH_UPDATE_REJECTED_ALIAS]             = { "pushNonFastForward" }, /* backwards compatibility */
+       [ADVICE_REF_SYNTAX]                             = { "refSyntax" },
        [ADVICE_RESET_NO_REFRESH_WARNING]               = { "resetNoRefresh" },
        [ADVICE_RESOLVE_CONFLICT]                       = { "resolveConflict" },
        [ADVICE_RM_HINTS]                               = { "rmHints" },
index 7d0a821f5cb8a1818154852bbb76d7e15d4fe97b..bf630ee3ac3eae23b05b9554f4cc20ce2ea7a280 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -36,6 +36,7 @@ enum advice_type {
        ADVICE_PUSH_UNQUALIFIED_REF_NAME,
        ADVICE_PUSH_UPDATE_REJECTED,
        ADVICE_PUSH_UPDATE_REJECTED_ALIAS,
+       ADVICE_REF_SYNTAX,
        ADVICE_RESET_NO_REFRESH_WARNING,
        ADVICE_RESOLVE_CONFLICT,
        ADVICE_RM_HINTS,
index f75e50c339764db8a6b9f2266281541203d4e76f..60aae2fe50d4edaa520c9cf9f7e4a23ed6c60085 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -836,10 +836,11 @@ static void handle_skipped_merge_base(const struct object_id *mb)
 static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
 {
        enum bisect_error res = BISECT_OK;
-       struct commit_list *result;
+       struct commit_list *result = NULL;
 
-       result = repo_get_merge_bases_many(the_repository, rev[0], rev_nr - 1,
-                                          rev + 1);
+       if (repo_get_merge_bases_many(the_repository, rev[0], rev_nr - 1,
+                                     rev + 1, &result) < 0)
+               exit(128);
 
        for (; result; result = result->next) {
                const struct object_id *mb = &result->item->object.oid;
index 6719a181bd1f03af21b92d8be71a93142ef700e7..621019fcf4bde0a0568dbae2a1055e12cf8df030 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -370,8 +370,12 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
  */
 int validate_branchname(const char *name, struct strbuf *ref)
 {
-       if (strbuf_check_branch_ref(ref, name))
-               die(_("'%s' is not a valid branch name"), name);
+       if (strbuf_check_branch_ref(ref, name)) {
+               int code = die_message(_("'%s' is not a valid branch name"), name);
+               advise_if_enabled(ADVICE_REF_SYNTAX,
+                                 _("See `man git check-ref-format`"));
+               exit(code);
+       }
 
        return ref_exists(ref->buf);
 }
index ada7719561f0ec324238e613a9788a5f5a2981eb..393c10cbcf6315efb525b38db26e218bf6b1959d 100644 (file)
@@ -115,7 +115,7 @@ static int refresh(int verbose, const struct pathspec *pathspec)
        int i, ret = 0;
        char *skip_worktree_seen = NULL;
        struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP;
-       int flags = REFRESH_IGNORE_SKIP_WORKTREE |
+       unsigned int flags = REFRESH_IGNORE_SKIP_WORKTREE |
                    (verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET);
 
        seen = xcalloc(pathspec->nr, 1);
index cfb63cce5fb9dff64106907947d0df25a2c25489..8c2305ad2c85586c960c986582f1d9e874a26a24 100644 (file)
@@ -158,6 +158,8 @@ static int branch_merged(int kind, const char *name,
 
        merged = reference_rev ? repo_in_merge_bases(the_repository, rev,
                                                     reference_rev) : 0;
+       if (merged < 0)
+               exit(128);
 
        /*
         * After the safety valve is fully redefined to "check with
@@ -166,9 +168,13 @@ static int branch_merged(int kind, const char *name,
         * any of the following code, but during the transition period,
         * a gentle reminder is in order.
         */
-       if ((head_rev != reference_rev) &&
-           (head_rev ? repo_in_merge_bases(the_repository, rev, head_rev) : 0) != merged) {
-               if (merged)
+       if (head_rev != reference_rev) {
+               int expect = head_rev ? repo_in_merge_bases(the_repository, rev, head_rev) : 0;
+               if (expect < 0)
+                       exit(128);
+               if (expect == merged)
+                       ; /* okay */
+               else if (merged)
                        warning(_("deleting branch '%s' that has been merged to\n"
                                "         '%s', but not yet merged to HEAD"),
                                name, reference_name);
@@ -576,8 +582,12 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
                 */
                if (ref_exists(oldref.buf))
                        recovery = 1;
-               else
-                       die(_("invalid branch name: '%s'"), oldname);
+               else {
+                       int code = die_message(_("invalid branch name: '%s'"), oldname);
+                       advise_if_enabled(ADVICE_REF_SYNTAX,
+                                         _("See `man git check-ref-format`"));
+                       exit(code);
+               }
        }
 
        for (int i = 0; worktrees[i]; i++) {
index 067c2519334db3198f4627e58469fd6ad48da16a..15293a30134094f699d15035232bbc644277910c 100644 (file)
@@ -704,7 +704,8 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
        init_checkout_metadata(&opts.meta, info->refname,
                               info->commit ? &info->commit->object.oid : null_oid(),
                               NULL);
-       parse_tree(tree);
+       if (parse_tree(tree) < 0)
+               return 128;
        init_tree_desc(&tree_desc, tree->buffer, tree->size);
        switch (unpack_trees(1, &tree_desc, &opts)) {
        case -2:
@@ -783,9 +784,15 @@ static int merge_working_tree(const struct checkout_opts *opts,
                if (new_branch_info->commit)
                        BUG("'switch --orphan' should never accept a commit as starting point");
                new_tree = parse_tree_indirect(the_hash_algo->empty_tree);
-       } else
+               if (!new_tree)
+                       BUG("unable to read empty tree");
+       } else {
                new_tree = repo_get_commit_tree(the_repository,
                                                new_branch_info->commit);
+               if (!new_tree)
+                       return error(_("unable to read tree (%s)"),
+                                    oid_to_hex(&new_branch_info->commit->object.oid));
+       }
        if (opts->discard_changes) {
                ret = reset_tree(new_tree, opts, 1, writeout_error, new_branch_info);
                if (ret)
@@ -820,7 +827,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
                                oid_to_hex(old_commit_oid));
 
                init_tree_desc(&trees[0], tree->buffer, tree->size);
-               parse_tree(new_tree);
+               if (parse_tree(new_tree) < 0)
+                       exit(128);
                tree = new_tree;
                init_tree_desc(&trees[1], tree->buffer, tree->size);
 
@@ -1240,10 +1248,15 @@ static void setup_new_branch_info_and_source_tree(
        if (!new_branch_info->commit) {
                /* not a commit */
                *source_tree = parse_tree_indirect(rev);
+               if (!*source_tree)
+                       die(_("unable to read tree (%s)"), oid_to_hex(rev));
        } else {
                parse_commit_or_die(new_branch_info->commit);
                *source_tree = repo_get_commit_tree(the_repository,
                                                    new_branch_info->commit);
+               if (!*source_tree)
+                       die(_("unable to read tree (%s)"),
+                           oid_to_hex(&new_branch_info->commit->object.oid));
        }
 }
 
index d90766cad3a0ba13c41dd0b90c03254ba5eb83ee..29efe841537b341776bdca2fc70f3df4d333e066 100644 (file)
@@ -25,7 +25,7 @@
 #include "help.h"
 #include "prompt.h"
 
-static int force = -1; /* unset */
+static int require_force = -1; /* unset */
 static int interactive;
 static struct string_list del_list = STRING_LIST_INIT_DUP;
 static unsigned int colopts;
@@ -128,7 +128,7 @@ static int git_clean_config(const char *var, const char *value,
        }
 
        if (!strcmp(var, "clean.requireforce")) {
-               force = !git_config_bool(var, value);
+               require_force = git_config_bool(var, value);
                return 0;
        }
 
@@ -920,7 +920,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 {
        int i, res;
        int dry_run = 0, remove_directories = 0, quiet = 0, ignored = 0;
-       int ignored_only = 0, config_set = 0, errors = 0, gone = 1;
+       int ignored_only = 0, force = 0, errors = 0, gone = 1;
        int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT;
        struct strbuf abs_path = STRBUF_INIT;
        struct dir_struct dir = DIR_INIT;
@@ -946,22 +946,12 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
        };
 
        git_config(git_clean_config, NULL);
-       if (force < 0)
-               force = 0;
-       else
-               config_set = 1;
 
        argc = parse_options(argc, argv, prefix, options, builtin_clean_usage,
                             0);
 
-       if (!interactive && !dry_run && !force) {
-               if (config_set)
-                       die(_("clean.requireForce set to true and neither -i, -n, nor -f given; "
-                                 "refusing to clean"));
-               else
-                       die(_("clean.requireForce defaults to true and neither -i, -n, nor -f given;"
-                                 " refusing to clean"));
-       }
+       if (require_force != 0 && !force && !interactive && !dry_run)
+               die(_("clean.requireForce is true and -f not given: refusing to clean"));
 
        if (force > 1)
                rm_flags = 0;
index bad1b70ce8255156cf4745aca5e120371d39642d..f3bc6edef8ce4bf15998bbf87fd2d5af4d7e3353 100644 (file)
@@ -116,7 +116,7 @@ static struct option builtin_clone_options[] = {
        OPT_HIDDEN_BOOL(0, "naked", &option_bare,
                        N_("create a bare repository")),
        OPT_BOOL(0, "mirror", &option_mirror,
-                N_("create a mirror repository (implies bare)")),
+                N_("create a mirror repository (implies --bare)")),
        OPT_BOOL('l', "local", &option_local,
                N_("to clone from a local repository")),
        OPT_BOOL(0, "no-hardlinks", &option_no_hardlinks,
@@ -738,7 +738,8 @@ static int checkout(int submodule_progress, int filter_submodules)
        tree = parse_tree_indirect(&oid);
        if (!tree)
                die(_("unable to parse commit %s"), oid_to_hex(&oid));
-       parse_tree(tree);
+       if (parse_tree(tree) < 0)
+               exit(128);
        init_tree_desc(&t, tree->buffer, tree->size);
        if (unpack_trees(1, &t, &opts) < 0)
                die(_("unable to checkout working tree"));
@@ -926,6 +927,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        struct ref *mapped_refs = NULL;
        const struct ref *ref;
        struct strbuf key = STRBUF_INIT;
+       struct strbuf buf = STRBUF_INIT;
        struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
        struct transport *transport = NULL;
        const char *src_ref_prefix = "refs/heads/";
@@ -1125,6 +1127,50 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                git_dir = real_git_dir;
        }
 
+       /*
+        * We have a chicken-and-egg situation between initializing the refdb
+        * and spawning transport helpers:
+        *
+        *   - Initializing the refdb requires us to know about the object
+        *     format. We thus have to spawn the transport helper to learn
+        *     about it.
+        *
+        *   - The transport helper may want to access the Git repository. But
+        *     because the refdb has not been initialized, we don't have "HEAD"
+        *     or "refs/". Thus, the helper cannot find the Git repository.
+        *
+        * Ideally, we would have structured the helper protocol such that it's
+        * mandatory for the helper to first announce its capabilities without
+        * yet assuming a fully initialized repository. Like that, we could
+        * have added a "lazy-refdb-init" capability that announces whether the
+        * helper is ready to handle not-yet-initialized refdbs. If any helper
+        * didn't support them, we would have fully initialized the refdb with
+        * the SHA1 object format, but later on bailed out if we found out that
+        * the remote repository used a different object format.
+        *
+        * But we didn't, and thus we use the following workaround to partially
+        * initialize the repository's refdb such that it can be discovered by
+        * Git commands. To do so, we:
+        *
+        *   - Create an invalid HEAD ref pointing at "refs/heads/.invalid".
+        *
+        *   - Create the "refs/" directory.
+        *
+        *   - Set up the ref storage format and repository version as
+        *     required.
+        *
+        * This is sufficient for Git commands to discover the Git directory.
+        */
+       initialize_repository_version(GIT_HASH_UNKNOWN,
+                                     the_repository->ref_storage_format, 1);
+
+       strbuf_addf(&buf, "%s/HEAD", git_dir);
+       write_file(buf.buf, "ref: refs/heads/.invalid");
+
+       strbuf_reset(&buf);
+       strbuf_addf(&buf, "%s/refs", git_dir);
+       safe_create_dir(buf.buf, 1);
+
        /*
         * additional config can be injected with -c, make sure it's included
         * after init_db, which clears the entire config environment.
@@ -1453,6 +1499,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        free(remote_name);
        strbuf_release(&reflog_msg);
        strbuf_release(&branch_top);
+       strbuf_release(&buf);
        strbuf_release(&key);
        free_refs(mapped_refs);
        free_refs(remote_head_points_at);
index 6d1fa71676f735b7ef1c3ab7bd56b767348ed992..a91197245f18ed7b73eee64d3d5d930ca164bb06 100644 (file)
@@ -331,7 +331,8 @@ static void create_base_index(const struct commit *current_head)
        tree = parse_tree_indirect(&current_head->object.oid);
        if (!tree)
                die(_("failed to unpack HEAD tree object"));
-       parse_tree(tree);
+       if (parse_tree(tree) < 0)
+               exit(128);
        init_tree_desc(&t, tree->buffer, tree->size);
        if (unpack_trees(1, &t, &opts))
                exit(128); /* We've already reported the error, finish dying */
@@ -737,7 +738,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        const char *hook_arg2 = NULL;
        int clean_message_contents = (cleanup_mode != COMMIT_MSG_CLEANUP_NONE);
        int old_display_comment_prefix;
-       int merge_contains_scissors = 0;
        int invoked_hook;
 
        /* This checks and barfs if author is badly specified */
@@ -841,7 +841,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                    wt_status_locate_end(sb.buf + merge_msg_start,
                                         sb.len - merge_msg_start) <
                                sb.len - merge_msg_start)
-                       merge_contains_scissors = 1;
+                       s->added_cut_line = 1;
        } else if (!stat(git_path_squash_msg(the_repository), &statbuf)) {
                if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)
                        die_errno(_("could not read SQUASH_MSG"));
@@ -924,9 +924,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                          " yourself if you want to.\n"
                          "An empty message aborts the commit.\n");
                if (whence != FROM_COMMIT) {
-                       if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS &&
-                               !merge_contains_scissors)
-                               wt_status_add_cut_line(s->fp);
+                       if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
+                               wt_status_add_cut_line(s);
                        status_printf_ln(
                                s, GIT_COLOR_NORMAL,
                                whence == FROM_MERGE ?
@@ -946,8 +945,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                if (cleanup_mode == COMMIT_MSG_CLEANUP_ALL)
                        status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_all, comment_line_char);
                else if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
-                       if (whence == FROM_COMMIT && !merge_contains_scissors)
-                               wt_status_add_cut_line(s->fp);
+                       if (whence == FROM_COMMIT)
+                               wt_status_add_cut_line(s);
                } else /* COMMIT_MSG_CLEANUP_SPACE, that is. */
                        status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_space, comment_line_char);
 
index 92eda20683ca2d07c24a03f5903d1e604ce54763..71a195ca227315d799c03dd766d4723f7ffbec46 100644 (file)
@@ -1625,6 +1625,7 @@ static int update_branch(struct branch *b)
                oidclr(&old_oid);
        if (!force_update && !is_null_oid(&old_oid)) {
                struct commit *old_cmit, *new_cmit;
+               int ret;
 
                old_cmit = lookup_commit_reference_gently(the_repository,
                                                          &old_oid, 0);
@@ -1633,7 +1634,10 @@ static int update_branch(struct branch *b)
                if (!old_cmit || !new_cmit)
                        return error("Branch %s is missing commits.", b->name);
 
-               if (!repo_in_merge_bases(the_repository, old_cmit, new_cmit)) {
+               ret = repo_in_merge_bases(the_repository, old_cmit, new_cmit);
+               if (ret < 0)
+                       exit(128);
+               if (!ret) {
                        warning("Not updating %s"
                                " (new tip %s does not contain %s)",
                                b->name, oid_to_hex(&b->oid),
index 0a7a1a34765483e9f207ec26c5ca408df88c9dfc..46a793411a437969b53c4f14d941df27358d00ed 100644 (file)
@@ -981,6 +981,8 @@ static int update_local_ref(struct ref *ref,
                uint64_t t_before = getnanotime();
                fast_forward = repo_in_merge_bases(the_repository, current,
                                                   updated);
+               if (fast_forward < 0)
+                       exit(128);
                forced_updates_ms += (getnanotime() - t_before) / 1000000;
        } else {
                fast_forward = 1;
index a3a37bd215d844806814d677d2c7dfa71c8f31c6..856428fef9577eaa7f4407d598e073e488e4d089 100644 (file)
@@ -1524,14 +1524,12 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
        struct strbuf pack_name = STRBUF_INIT;
        struct strbuf index_name = STRBUF_INIT;
        struct strbuf rev_index_name = STRBUF_INIT;
-       int err;
 
        if (!from_stdin) {
                close(input_fd);
        } else {
                fsync_component_or_die(FSYNC_COMPONENT_PACK, output_fd, curr_pack_name);
-               err = close(output_fd);
-               if (err)
+               if (close(output_fd))
                        die_errno(_("error while closing pack file"));
        }
 
@@ -1566,17 +1564,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
                write_or_die(1, buf.buf, buf.len);
                strbuf_release(&buf);
 
-               /*
-                * Let's just mimic git-unpack-objects here and write
-                * the last part of the input buffer to stdout.
-                */
-               while (input_len) {
-                       err = xwrite(1, input_buffer + input_offset, input_len);
-                       if (err <= 0)
-                               break;
-                       input_len -= err;
-                       input_offset += err;
-               }
+               /* Write the last part of the buffer to stdout */
+               write_in_full(1, input_buffer + input_offset, input_len);
        }
 
        strbuf_release(&rev_index_name);
index 033bd1556cf9f8d6e56c2730a3e868500388144e..11f4ce9e4a274c666fe4127a904872653d35010d 100644 (file)
@@ -9,6 +9,7 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "string-list.h"
+#include "tempfile.h"
 #include "trailer.h"
 #include "config.h"
 
@@ -91,6 +92,102 @@ static int parse_opt_parse(const struct option *opt, const char *arg,
        return 0;
 }
 
+static struct tempfile *trailers_tempfile;
+
+static FILE *create_in_place_tempfile(const char *file)
+{
+       struct stat st;
+       struct strbuf filename_template = STRBUF_INIT;
+       const char *tail;
+       FILE *outfile;
+
+       if (stat(file, &st))
+               die_errno(_("could not stat %s"), file);
+       if (!S_ISREG(st.st_mode))
+               die(_("file %s is not a regular file"), file);
+       if (!(st.st_mode & S_IWUSR))
+               die(_("file %s is not writable by user"), file);
+
+       /* Create temporary file in the same directory as the original */
+       tail = strrchr(file, '/');
+       if (tail)
+               strbuf_add(&filename_template, file, tail - file + 1);
+       strbuf_addstr(&filename_template, "git-interpret-trailers-XXXXXX");
+
+       trailers_tempfile = xmks_tempfile_m(filename_template.buf, st.st_mode);
+       strbuf_release(&filename_template);
+       outfile = fdopen_tempfile(trailers_tempfile, "w");
+       if (!outfile)
+               die_errno(_("could not open temporary file"));
+
+       return outfile;
+}
+
+static void read_input_file(struct strbuf *sb, const char *file)
+{
+       if (file) {
+               if (strbuf_read_file(sb, file, 0) < 0)
+                       die_errno(_("could not read input file '%s'"), file);
+       } else {
+               if (strbuf_read(sb, fileno(stdin), 0) < 0)
+                       die_errno(_("could not read from stdin"));
+       }
+}
+
+static void interpret_trailers(const struct process_trailer_options *opts,
+                              struct list_head *new_trailer_head,
+                              const char *file)
+{
+       LIST_HEAD(head);
+       struct strbuf sb = STRBUF_INIT;
+       struct strbuf trailer_block = STRBUF_INIT;
+       struct trailer_info info;
+       FILE *outfile = stdout;
+
+       trailer_config_init();
+
+       read_input_file(&sb, file);
+
+       if (opts->in_place)
+               outfile = create_in_place_tempfile(file);
+
+       parse_trailers(opts, &info, sb.buf, &head);
+
+       /* Print the lines before the trailers */
+       if (!opts->only_trailers)
+               fwrite(sb.buf, 1, info.trailer_block_start, outfile);
+
+       if (!opts->only_trailers && !info.blank_line_before_trailer)
+               fprintf(outfile, "\n");
+
+
+       if (!opts->only_input) {
+               LIST_HEAD(config_head);
+               LIST_HEAD(arg_head);
+               parse_trailers_from_config(&config_head);
+               parse_trailers_from_command_line_args(&arg_head, new_trailer_head);
+               list_splice(&config_head, &arg_head);
+               process_trailers_lists(&head, &arg_head);
+       }
+
+       /* Print trailer block. */
+       format_trailers(opts, &head, &trailer_block);
+       free_trailers(&head);
+       fwrite(trailer_block.buf, 1, trailer_block.len, outfile);
+       strbuf_release(&trailer_block);
+
+       /* Print the lines after the trailers as is */
+       if (!opts->only_trailers)
+               fwrite(sb.buf + info.trailer_block_end, 1, sb.len - info.trailer_block_end, outfile);
+       trailer_info_release(&info);
+
+       if (opts->in_place)
+               if (rename_tempfile(&trailers_tempfile, file))
+                       die_errno(_("could not rename temporary file to %s"), file);
+
+       strbuf_release(&sb);
+}
+
 int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
 {
        struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
@@ -132,11 +229,11 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
        if (argc) {
                int i;
                for (i = 0; i < argc; i++)
-                       process_trailers(argv[i], &opts, &trailers);
+                       interpret_trailers(&opts, &trailers, argv[i]);
        } else {
                if (opts.in_place)
                        die(_("no input file given for in-place editing"));
-               process_trailers(NULL, &opts, &trailers);
+               interpret_trailers(&opts, &trailers, NULL);
        }
 
        new_trailers_clear(&trailers);
index db1808d7c13dfd523e31d1da395122b52b6579ab..e5da0d10434dddc146ee00d9b035e76c28e3b214 100644 (file)
@@ -1625,7 +1625,7 @@ static struct commit *get_base_commit(const char *base_commit,
 {
        struct commit *base = NULL;
        struct commit **rev;
-       int i = 0, rev_nr = 0, auto_select, die_on_failure;
+       int i = 0, rev_nr = 0, auto_select, die_on_failure, ret;
 
        switch (auto_base) {
        case AUTO_BASE_NEVER:
@@ -1658,7 +1658,7 @@ static struct commit *get_base_commit(const char *base_commit,
                struct branch *curr_branch = branch_get(NULL);
                const char *upstream = branch_get_upstream(curr_branch, NULL);
                if (upstream) {
-                       struct commit_list *base_list;
+                       struct commit_list *base_list = NULL;
                        struct commit *commit;
                        struct object_id oid;
 
@@ -1669,11 +1669,12 @@ static struct commit *get_base_commit(const char *base_commit,
                                        return NULL;
                        }
                        commit = lookup_commit_or_die(&oid, "upstream base");
-                       base_list = repo_get_merge_bases_many(the_repository,
-                                                             commit, total,
-                                                             list);
-                       /* There should be one and only one merge base. */
-                       if (!base_list || base_list->next) {
+                       if (repo_get_merge_bases_many(the_repository,
+                                                     commit, total,
+                                                     list,
+                                                     &base_list) < 0 ||
+                           /* There should be one and only one merge base. */
+                           !base_list || base_list->next) {
                                if (die_on_failure) {
                                        die(_("could not find exact merge base"));
                                } else {
@@ -1704,11 +1705,11 @@ static struct commit *get_base_commit(const char *base_commit,
         */
        while (rev_nr > 1) {
                for (i = 0; i < rev_nr / 2; i++) {
-                       struct commit_list *merge_base;
-                       merge_base = repo_get_merge_bases(the_repository,
-                                                         rev[2 * i],
-                                                         rev[2 * i + 1]);
-                       if (!merge_base || merge_base->next) {
+                       struct commit_list *merge_base = NULL;
+                       if (repo_get_merge_bases(the_repository,
+                                                rev[2 * i],
+                                                rev[2 * i + 1], &merge_base) < 0 ||
+                           !merge_base || merge_base->next) {
                                if (die_on_failure) {
                                        die(_("failed to find exact merge base"));
                                } else {
@@ -1725,7 +1726,10 @@ static struct commit *get_base_commit(const char *base_commit,
                rev_nr = DIV_ROUND_UP(rev_nr, 2);
        }
 
-       if (!repo_in_merge_bases(the_repository, base, rev[0])) {
+       ret = repo_in_merge_bases(the_repository, base, rev[0]);
+       if (ret < 0)
+               exit(128);
+       if (!ret) {
                if (die_on_failure) {
                        die(_("base commit should be the ancestor of revision list"));
                } else {
index d26e8fbf6f75d9971762afdc0ea5c04e209db387..5a8e72950298c254d430664c6e931ca13c699590 100644 (file)
 
 static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
 {
-       struct commit_list *result, *r;
+       struct commit_list *result = NULL, *r;
 
-       result = repo_get_merge_bases_many_dirty(the_repository, rev[0],
-                                                rev_nr - 1, rev + 1);
+       if (repo_get_merge_bases_many_dirty(the_repository, rev[0],
+                                           rev_nr - 1, rev + 1, &result) < 0) {
+               free_commit_list(result);
+               return -1;
+       }
 
        if (!result)
                return 1;
@@ -74,13 +77,17 @@ static int handle_independent(int count, const char **args)
 static int handle_octopus(int count, const char **args, int show_all)
 {
        struct commit_list *revs = NULL;
-       struct commit_list *result, *rev;
+       struct commit_list *result = NULL, *rev;
        int i;
 
        for (i = count - 1; i >= 0; i--)
                commit_list_insert(get_commit_reference(args[i]), &revs);
 
-       result = get_octopus_merge_bases(revs);
+       if (get_octopus_merge_bases(revs, &result) < 0) {
+               free_commit_list(revs);
+               free_commit_list(result);
+               return 128;
+       }
        free_commit_list(revs);
        reduce_heads_replace(&result);
 
@@ -100,12 +107,16 @@ static int handle_octopus(int count, const char **args, int show_all)
 static int handle_is_ancestor(int argc, const char **argv)
 {
        struct commit *one, *two;
+       int ret;
 
        if (argc != 2)
                die("--is-ancestor takes exactly two commits");
        one = get_commit_reference(argv[0]);
        two = get_commit_reference(argv[1]);
-       if (repo_in_merge_bases(the_repository, one, two))
+       ret = repo_in_merge_bases(the_repository, one, two);
+       if (ret < 0)
+               exit(128);
+       if (ret)
                return 0;
        else
                return 1;
index 3bdec53fbe58bb5edef6e4d425829a58ce87bffe..05d0cad55438a90b72c8e001dfe71b05ad8203d3 100644 (file)
@@ -429,41 +429,56 @@ static int real_merge(struct merge_tree_options *o,
        struct merge_options opt;
 
        copy_merge_options(&opt, &o->merge_options);
-       parent1 = get_merge_parent(branch1);
-       if (!parent1)
-               help_unknown_ref(branch1, "merge-tree",
-                                _("not something we can merge"));
-
-       parent2 = get_merge_parent(branch2);
-       if (!parent2)
-               help_unknown_ref(branch2, "merge-tree",
-                                _("not something we can merge"));
-
        opt.show_rename_progress = 0;
 
        opt.branch1 = branch1;
        opt.branch2 = branch2;
 
        if (merge_base) {
-               struct commit *base_commit;
                struct tree *base_tree, *parent1_tree, *parent2_tree;
 
-               base_commit = lookup_commit_reference_by_name(merge_base);
-               if (!base_commit)
-                       die(_("could not lookup commit '%s'"), merge_base);
+               /*
+                * We actually only need the trees because we already
+                * have a merge base.
+                */
+               struct object_id base_oid, head_oid, merge_oid;
+
+               if (repo_get_oid_treeish(the_repository, merge_base, &base_oid))
+                       die(_("could not parse as tree '%s'"), merge_base);
+               base_tree = parse_tree_indirect(&base_oid);
+               if (!base_tree)
+                       die(_("unable to read tree (%s)"), oid_to_hex(&base_oid));
+               if (repo_get_oid_treeish(the_repository, branch1, &head_oid))
+                       die(_("could not parse as tree '%s'"), branch1);
+               parent1_tree = parse_tree_indirect(&head_oid);
+               if (!parent1_tree)
+                       die(_("unable to read tree (%s)"), oid_to_hex(&head_oid));
+               if (repo_get_oid_treeish(the_repository, branch2, &merge_oid))
+                       die(_("could not parse as tree '%s'"), branch2);
+               parent2_tree = parse_tree_indirect(&merge_oid);
+               if (!parent2_tree)
+                       die(_("unable to read tree (%s)"), oid_to_hex(&merge_oid));
 
                opt.ancestor = merge_base;
-               base_tree = repo_get_commit_tree(the_repository, base_commit);
-               parent1_tree = repo_get_commit_tree(the_repository, parent1);
-               parent2_tree = repo_get_commit_tree(the_repository, parent2);
                merge_incore_nonrecursive(&opt, base_tree, parent1_tree, parent2_tree, &result);
        } else {
+               parent1 = get_merge_parent(branch1);
+               if (!parent1)
+                       help_unknown_ref(branch1, "merge-tree",
+                                        _("not something we can merge"));
+
+               parent2 = get_merge_parent(branch2);
+               if (!parent2)
+                       help_unknown_ref(branch2, "merge-tree",
+                                        _("not something we can merge"));
+
                /*
                 * Get the merge bases, in reverse order; see comment above
                 * merge_incore_recursive in merge-ort.h
                 */
-               merge_bases = repo_get_merge_bases(the_repository, parent1,
-                                                  parent2);
+               if (repo_get_merge_bases(the_repository, parent1,
+                                        parent2, &merge_bases) < 0)
+                       exit(128);
                if (!merge_bases && !o->allow_unrelated_histories)
                        die(_("refusing to merge unrelated histories"));
                merge_bases = reverse_commit_list(merge_bases);
index 935c8a57ddbcaa3b396bdcf633f34eb29d8860c1..a0ba1f9815d9f45a1525bab8932810c9f5919aff 100644 (file)
@@ -1513,13 +1513,20 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 
        if (!remoteheads)
                ; /* already up-to-date */
-       else if (!remoteheads->next)
-               common = repo_get_merge_bases(the_repository, head_commit,
-                                             remoteheads->item);
-       else {
+       else if (!remoteheads->next) {
+               if (repo_get_merge_bases(the_repository, head_commit,
+                                        remoteheads->item, &common) < 0) {
+                       ret = 2;
+                       goto done;
+               }
+       } else {
                struct commit_list *list = remoteheads;
                commit_list_insert(head_commit, &list);
-               common = get_octopus_merge_bases(list);
+               if (get_octopus_merge_bases(list, &common) < 0) {
+                       free(list);
+                       ret = 2;
+                       goto done;
+               }
                free(list);
        }
 
@@ -1626,7 +1633,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                struct commit_list *j;
 
                for (j = remoteheads; j; j = j->next) {
-                       struct commit_list *common_one;
+                       struct commit_list *common_one = NULL;
                        struct commit *common_item;
 
                        /*
@@ -1634,9 +1641,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                         * merge_bases again, otherwise "git merge HEAD^
                         * HEAD^^" would be missed.
                         */
-                       common_one = repo_get_merge_bases(the_repository,
-                                                         head_commit,
-                                                         j->item);
+                       if (repo_get_merge_bases(the_repository, head_commit,
+                                                j->item, &common_one) < 0)
+                               exit(128);
+
                        common_item = common_one->item;
                        free_commit_list(common_one);
                        if (!oideq(&common_item->object.oid, &j->item->object.oid)) {
index 73a68b75b0672487013299f992d382d1957a02a4..72cbb76d520718cfc2f23093dd5ef76ea2d682bf 100644 (file)
@@ -815,7 +815,7 @@ static int get_octopus_merge_base(struct object_id *merge_base,
                const struct object_id *merge_head,
                const struct object_id *fork_point)
 {
-       struct commit_list *revs = NULL, *result;
+       struct commit_list *revs = NULL, *result = NULL;
 
        commit_list_insert(lookup_commit_reference(the_repository, curr_head),
                           &revs);
@@ -825,7 +825,8 @@ static int get_octopus_merge_base(struct object_id *merge_base,
                commit_list_insert(lookup_commit_reference(the_repository, fork_point),
                                   &revs);
 
-       result = get_octopus_merge_bases(revs);
+       if (get_octopus_merge_bases(revs, &result) < 0)
+               exit(128);
        free_commit_list(revs);
        reduce_heads_replace(&result);
 
@@ -926,6 +927,8 @@ static int get_can_ff(struct object_id *orig_head,
        merge_head = lookup_commit_reference(the_repository, orig_merge_head);
        ret = repo_is_descendant_of(the_repository, merge_head, list);
        free_commit_list(list);
+       if (ret < 0)
+               exit(128);
        return ret;
 }
 
@@ -950,6 +953,8 @@ static int already_up_to_date(struct object_id *orig_head,
                commit_list_insert(theirs, &list);
                ok = repo_is_descendant_of(the_repository, ours, list);
                free_commit_list(list);
+               if (ok < 0)
+                       exit(128);
                if (!ok)
                        return 0;
        }
index 20e7db19737d5a5070068a131797042d37a936a5..1ffd863cff6701af8013130d2e2801366f4e7228 100644 (file)
@@ -261,7 +261,8 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
        cache_tree_free(&the_index.cache_tree);
        for (i = 0; i < nr_trees; i++) {
                struct tree *tree = trees[i];
-               parse_tree(tree);
+               if (parse_tree(tree) < 0)
+                       return 128;
                init_tree_desc(t+i, tree->buffer, tree->size);
        }
        if (unpack_trees(nr_trees, t, &opts))
index 6ead9465a42c6d3c6ff7a547bb42ed9dd919dd90..be787690bd7c2b6396784a1476314b8f757ab749 100644 (file)
@@ -867,7 +867,8 @@ static int can_fast_forward(struct commit *onto, struct commit *upstream,
        if (!upstream)
                goto done;
 
-       merge_bases = repo_get_merge_bases(the_repository, upstream, head);
+       if (repo_get_merge_bases(the_repository, upstream, head, &merge_bases) < 0)
+               exit(128);
        if (!merge_bases || merge_bases->next)
                goto done;
 
@@ -886,8 +887,9 @@ static void fill_branch_base(struct rebase_options *options,
 {
        struct commit_list *merge_bases = NULL;
 
-       merge_bases = repo_get_merge_bases(the_repository, options->onto,
-                                          options->orig_head);
+       if (repo_get_merge_bases(the_repository, options->onto,
+                                options->orig_head, &merge_bases) < 0)
+               exit(128);
        if (!merge_bases || merge_bases->next)
                oidcpy(branch_base, null_oid());
        else
index db656074857e765c8b5d5c91ab1b872de0bad66d..56d8a77ed75f65c1bcf47bd580e8e4e7cbbc32d9 100644 (file)
@@ -1526,6 +1526,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
            starts_with(name, "refs/heads/")) {
                struct object *old_object, *new_object;
                struct commit *old_commit, *new_commit;
+               int ret2;
 
                old_object = parse_object(the_repository, old_oid);
                new_object = parse_object(the_repository, new_oid);
@@ -1539,7 +1540,10 @@ static const char *update(struct command *cmd, struct shallow_info *si)
                }
                old_commit = (struct commit *)old_object;
                new_commit = (struct commit *)new_object;
-               if (!repo_in_merge_bases(the_repository, old_commit, new_commit)) {
+               ret2 = repo_in_merge_bases(the_repository, old_commit, new_commit);
+               if (ret2 < 0)
+                       exit(128);
+               if (!ret2) {
                        rp_error("denying non-fast-forward %s"
                                 " (you should pull first)", name);
                        ret = "non-fast-forward";
index d91bbe728d739e074e5f4fa54f70c186f371c1b7..8412d12fa55100132c69ae24914b2db536bf77c9 100644 (file)
@@ -150,7 +150,7 @@ static int parse_mirror_opt(const struct option *opt, const char *arg, int not)
        else if (!strcmp(arg, "push"))
                *mirror = MIRROR_PUSH;
        else
-               return error(_("unknown mirror argument: %s"), arg);
+               return error(_("unknown --mirror argument: %s"), arg);
        return 0;
 }
 
index ede36328a3cab9170bc59cb98dda097ea6eb24f7..15e4cccc45687d4902979911e7162e7c82567e6e 100644 (file)
@@ -314,8 +314,9 @@ static int write_oid(const struct object_id *oid,
                        die(_("could not start pack-objects to repack promisor objects"));
        }
 
-       xwrite(cmd->in, oid_to_hex(oid), the_hash_algo->hexsz);
-       xwrite(cmd->in, "\n", 1);
+       if (write_in_full(cmd->in, oid_to_hex(oid), the_hash_algo->hexsz) < 0 ||
+           write_in_full(cmd->in, "\n", 1) < 0)
+               die(_("failed to feed promisor objects to pack-objects"));
        return 0;
 }
 
index f0bf29a4783b81fde5fb97478b974dade7a310d0..1d62ff6332737c6449c76f66d2ebcbadb36bfb11 100644 (file)
@@ -116,6 +116,10 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t
 
        if (reset_type == MIXED || reset_type == HARD) {
                tree = parse_tree_indirect(oid);
+               if (!tree) {
+                       error(_("unable to read tree (%s)"), oid_to_hex(oid));
+                       goto out;
+               }
                prime_cache_tree(the_repository, the_repository->index, tree);
        }
 
index b3f47838580c9dd0ed233a3ac34c19aac6b7fa0f..ec455aa97277dd58d106c10623ad36aa923bcd10 100644 (file)
@@ -545,6 +545,18 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
         *
         * Let "--missing" to conditionally set fetch_if_missing.
         */
+       /*
+        * NEEDSWORK: These loops that attempt to find presence of
+        * options without understanding that the options they are
+        * skipping are broken (e.g., it would not know "--grep
+        * --exclude-promisor-objects" is not triggering
+        * "--exclude-promisor-objects" option).  We really need
+        * setup_revisions() to have a mechanism to allow and disallow
+        * some sets of options for different commands (like rev-list,
+        * replay, etc). Such a mechanism should do an early parsing
+        * of options and be able to manage the `--missing=...` and
+        * `--exclude-promisor-objects` options below.
+        */
        for (i = 1; i < argc; i++) {
                const char *arg = argv[i];
                if (!strcmp(arg, "--exclude-promisor-objects")) {
@@ -753,8 +765,12 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 
        if (arg_print_omitted)
                oidset_init(&omitted_objects, DEFAULT_OIDSET_SIZE);
-       if (arg_missing_action == MA_PRINT)
+       if (arg_missing_action == MA_PRINT) {
                oidset_init(&missing_objects, DEFAULT_OIDSET_SIZE);
+               /* Add missing tips */
+               oidset_insert_from_set(&missing_objects, &revs.missing_commits);
+               oidset_clear(&revs.missing_commits);
+       }
 
        traverse_commit_list_filtered(
                &revs, show_commit, show_object, &info,
index d08987646a0a533ad81480ae4667b577a335f9f7..181c703d4c00bcce1f1715f1a8913fad0892828d 100644 (file)
@@ -297,7 +297,7 @@ static int try_difference(const char *arg)
                show_rev(NORMAL, &end_oid, end);
                show_rev(symmetric ? NORMAL : REVERSED, &start_oid, start);
                if (symmetric) {
-                       struct commit_list *exclude;
+                       struct commit_list *exclude = NULL;
                        struct commit *a, *b;
                        a = lookup_commit_reference(the_repository, &start_oid);
                        b = lookup_commit_reference(the_repository, &end_oid);
@@ -305,7 +305,8 @@ static int try_difference(const char *arg)
                                *dotdot = '.';
                                return 0;
                        }
-                       exclude = repo_get_merge_bases(the_repository, a, b);
+                       if (repo_get_merge_bases(the_repository, a, b, &exclude) < 0)
+                               exit(128);
                        while (exclude) {
                                struct commit *commit = pop_commit(&exclude);
                                show_rev(REVERSED, &commit->object.oid, NULL);
index e0a701f2b383bbbd95fc1e7fef3fec30c3783c37..f1c85a00ae9bb6586527a845c302cba47c4c8daf 100644 (file)
@@ -679,13 +679,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
        use(the_hash_algo->rawsz);
 
        /* Write the last part of the buffer to stdout */
-       while (len) {
-               int ret = xwrite(1, buffer + offset, len);
-               if (ret <= 0)
-                       break;
-               len -= ret;
-               offset += ret;
-       }
+       write_in_full(1, buffer + offset, len);
 
        /* All done */
        return has_errors;
index 9b021ef026c28c97ece12b924833dff87c15a103..15afb97260165bc51cc85bae59b08afb37bfc6a6 100644 (file)
@@ -8,6 +8,7 @@
 #include "replace-object.h"
 #include "upload-pack.h"
 #include "serve.h"
+#include "commit.h"
 
 static const char * const upload_pack_usage[] = {
        N_("git-upload-pack [--[no-]strict] [--timeout=<n>] [--stateless-rpc]\n"
@@ -37,6 +38,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
 
        packet_trace_identity("upload-pack");
        disable_replace_refs();
+       save_commit_buffer = 0;
 
        argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
 
index 64678fe19930402b8400cb05d3ccaad5bb5b00a6..80ca8324773d2dc352bf4d47cfc4d0036316180e 100644 (file)
@@ -778,8 +778,8 @@ static void prime_cache_tree_rec(struct repository *r,
                        struct cache_tree_sub *sub;
                        struct tree *subtree = lookup_tree(r, &entry.oid);
 
-                       if (!subtree->object.parsed)
-                               parse_tree(subtree);
+                       if (parse_tree(subtree) < 0)
+                               exit(128);
                        sub = cache_tree_sub(it, entry.path);
                        sub->cache_tree = cache_tree();
 
index ecc913fc99ba9e6b88df675462a2b8f912cbd0ce..8f9b008f876787abf12ca89af5541f0b3bdf6ba7 100644 (file)
@@ -49,13 +49,14 @@ static int queue_has_nonstale(struct prio_queue *queue)
 }
 
 /* all input commits in one and twos[] must have been parsed! */
-static struct commit_list *paint_down_to_common(struct repository *r,
-                                               struct commit *one, int n,
-                                               struct commit **twos,
-                                               timestamp_t min_generation)
+static int paint_down_to_common(struct repository *r,
+                               struct commit *one, int n,
+                               struct commit **twos,
+                               timestamp_t min_generation,
+                               int ignore_missing_commits,
+                               struct commit_list **result)
 {
        struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
-       struct commit_list *result = NULL;
        int i;
        timestamp_t last_gen = GENERATION_NUMBER_INFINITY;
 
@@ -64,8 +65,8 @@ static struct commit_list *paint_down_to_common(struct repository *r,
 
        one->object.flags |= PARENT1;
        if (!n) {
-               commit_list_append(one, &result);
-               return result;
+               commit_list_append(one, result);
+               return 0;
        }
        prio_queue_put(&queue, one);
 
@@ -93,7 +94,7 @@ static struct commit_list *paint_down_to_common(struct repository *r,
                if (flags == (PARENT1 | PARENT2)) {
                        if (!(commit->object.flags & RESULT)) {
                                commit->object.flags |= RESULT;
-                               commit_list_insert_by_date(commit, &result);
+                               commit_list_insert_by_date(commit, result);
                        }
                        /* Mark parents of a found merge stale */
                        flags |= STALE;
@@ -104,67 +105,97 @@ static struct commit_list *paint_down_to_common(struct repository *r,
                        parents = parents->next;
                        if ((p->object.flags & flags) == flags)
                                continue;
-                       if (repo_parse_commit(r, p))
-                               return NULL;
+                       if (repo_parse_commit(r, p)) {
+                               clear_prio_queue(&queue);
+                               free_commit_list(*result);
+                               *result = NULL;
+                               /*
+                                * At this stage, we know that the commit is
+                                * missing: `repo_parse_commit()` uses
+                                * `OBJECT_INFO_DIE_IF_CORRUPT` and therefore
+                                * corrupt commits would already have been
+                                * dispatched with a `die()`.
+                                */
+                               if (ignore_missing_commits)
+                                       return 0;
+                               return error(_("could not parse commit %s"),
+                                            oid_to_hex(&p->object.oid));
+                       }
                        p->object.flags |= flags;
                        prio_queue_put(&queue, p);
                }
        }
 
        clear_prio_queue(&queue);
-       return result;
+       return 0;
 }
 
-static struct commit_list *merge_bases_many(struct repository *r,
-                                           struct commit *one, int n,
-                                           struct commit **twos)
+static int merge_bases_many(struct repository *r,
+                           struct commit *one, int n,
+                           struct commit **twos,
+                           struct commit_list **result)
 {
        struct commit_list *list = NULL;
-       struct commit_list *result = NULL;
        int i;
 
        for (i = 0; i < n; i++) {
-               if (one == twos[i])
+               if (one == twos[i]) {
                        /*
                         * We do not mark this even with RESULT so we do not
                         * have to clean it up.
                         */
-                       return commit_list_insert(one, &result);
+                       *result = commit_list_insert(one, result);
+                       return 0;
+               }
        }
 
+       if (!one)
+               return 0;
        if (repo_parse_commit(r, one))
-               return NULL;
+               return error(_("could not parse commit %s"),
+                            oid_to_hex(&one->object.oid));
        for (i = 0; i < n; i++) {
+               if (!twos[i])
+                       return 0;
                if (repo_parse_commit(r, twos[i]))
-                       return NULL;
+                       return error(_("could not parse commit %s"),
+                                    oid_to_hex(&twos[i]->object.oid));
        }
 
-       list = paint_down_to_common(r, one, n, twos, 0);
+       if (paint_down_to_common(r, one, n, twos, 0, 0, &list)) {
+               free_commit_list(list);
+               return -1;
+       }
 
        while (list) {
                struct commit *commit = pop_commit(&list);
                if (!(commit->object.flags & STALE))
-                       commit_list_insert_by_date(commit, &result);
+                       commit_list_insert_by_date(commit, result);
        }
-       return result;
+       return 0;
 }
 
-struct commit_list *get_octopus_merge_bases(struct commit_list *in)
+int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result)
 {
-       struct commit_list *i, *j, *k, *ret = NULL;
+       struct commit_list *i, *j, *k;
 
        if (!in)
-               return ret;
+               return 0;
 
-       commit_list_insert(in->item, &ret);
+       commit_list_insert(in->item, result);
 
        for (i = in->next; i; i = i->next) {
                struct commit_list *new_commits = NULL, *end = NULL;
 
-               for (j = ret; j; j = j->next) {
-                       struct commit_list *bases;
-                       bases = repo_get_merge_bases(the_repository, i->item,
-                                                    j->item);
+               for (j = *result; j; j = j->next) {
+                       struct commit_list *bases = NULL;
+                       if (repo_get_merge_bases(the_repository, i->item,
+                                                j->item, &bases) < 0) {
+                               free_commit_list(bases);
+                               free_commit_list(*result);
+                               *result = NULL;
+                               return -1;
+                       }
                        if (!new_commits)
                                new_commits = bases;
                        else
@@ -172,10 +203,10 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
                        for (k = bases; k; k = k->next)
                                end = k;
                }
-               free_commit_list(ret);
-               ret = new_commits;
+               free_commit_list(*result);
+               *result = new_commits;
        }
-       return ret;
+       return 0;
 }
 
 static int remove_redundant_no_gen(struct repository *r,
@@ -193,7 +224,7 @@ static int remove_redundant_no_gen(struct repository *r,
        for (i = 0; i < cnt; i++)
                repo_parse_commit(r, array[i]);
        for (i = 0; i < cnt; i++) {
-               struct commit_list *common;
+               struct commit_list *common = NULL;
                timestamp_t min_generation = commit_graph_generation(array[i]);
 
                if (redundant[i])
@@ -209,8 +240,16 @@ static int remove_redundant_no_gen(struct repository *r,
                        if (curr_generation < min_generation)
                                min_generation = curr_generation;
                }
-               common = paint_down_to_common(r, array[i], filled,
-                                             work, min_generation);
+               if (paint_down_to_common(r, array[i], filled,
+                                        work, min_generation, 0, &common)) {
+                       clear_commit_marks(array[i], all_flags);
+                       clear_commit_marks_many(filled, work, all_flags);
+                       free_commit_list(common);
+                       free(work);
+                       free(redundant);
+                       free(filled_index);
+                       return -1;
+               }
                if (array[i]->object.flags & PARENT2)
                        redundant[i] = 1;
                for (j = 0; j < filled; j++)
@@ -375,69 +414,77 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
        return remove_redundant_no_gen(r, array, cnt);
 }
 
-static struct commit_list *get_merge_bases_many_0(struct repository *r,
-                                                 struct commit *one,
-                                                 int n,
-                                                 struct commit **twos,
-                                                 int cleanup)
+static int get_merge_bases_many_0(struct repository *r,
+                                 struct commit *one,
+                                 int n,
+                                 struct commit **twos,
+                                 int cleanup,
+                                 struct commit_list **result)
 {
        struct commit_list *list;
        struct commit **rslt;
-       struct commit_list *result;
        int cnt, i;
 
-       result = merge_bases_many(r, one, n, twos);
+       if (merge_bases_many(r, one, n, twos, result) < 0)
+               return -1;
        for (i = 0; i < n; i++) {
                if (one == twos[i])
-                       return result;
+                       return 0;
        }
-       if (!result || !result->next) {
+       if (!*result || !(*result)->next) {
                if (cleanup) {
                        clear_commit_marks(one, all_flags);
                        clear_commit_marks_many(n, twos, all_flags);
                }
-               return result;
+               return 0;
        }
 
        /* There are more than one */
-       cnt = commit_list_count(result);
+       cnt = commit_list_count(*result);
        CALLOC_ARRAY(rslt, cnt);
-       for (list = result, i = 0; list; list = list->next)
+       for (list = *result, i = 0; list; list = list->next)
                rslt[i++] = list->item;
-       free_commit_list(result);
+       free_commit_list(*result);
+       *result = NULL;
 
        clear_commit_marks(one, all_flags);
        clear_commit_marks_many(n, twos, all_flags);
 
        cnt = remove_redundant(r, rslt, cnt);
-       result = NULL;
+       if (cnt < 0) {
+               free(rslt);
+               return -1;
+       }
        for (i = 0; i < cnt; i++)
-               commit_list_insert_by_date(rslt[i], &result);
+               commit_list_insert_by_date(rslt[i], result);
        free(rslt);
-       return result;
+       return 0;
 }
 
-struct commit_list *repo_get_merge_bases_many(struct repository *r,
-                                             struct commit *one,
-                                             int n,
-                                             struct commit **twos)
+int repo_get_merge_bases_many(struct repository *r,
+                             struct commit *one,
+                             int n,
+                             struct commit **twos,
+                             struct commit_list **result)
 {
-       return get_merge_bases_many_0(r, one, n, twos, 1);
+       return get_merge_bases_many_0(r, one, n, twos, 1, result);
 }
 
-struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
-                                                   struct commit *one,
-                                                   int n,
-                                                   struct commit **twos)
+int repo_get_merge_bases_many_dirty(struct repository *r,
+                                   struct commit *one,
+                                   int n,
+                                   struct commit **twos,
+                                   struct commit_list **result)
 {
-       return get_merge_bases_many_0(r, one, n, twos, 0);
+       return get_merge_bases_many_0(r, one, n, twos, 0, result);
 }
 
-struct commit_list *repo_get_merge_bases(struct repository *r,
-                                        struct commit *one,
-                                        struct commit *two)
+int repo_get_merge_bases(struct repository *r,
+                        struct commit *one,
+                        struct commit *two,
+                        struct commit_list **result)
 {
-       return get_merge_bases_many_0(r, one, 1, &two, 1);
+       return get_merge_bases_many_0(r, one, 1, &two, 1, result);
 }
 
 /*
@@ -460,11 +507,13 @@ int repo_is_descendant_of(struct repository *r,
        } else {
                while (with_commit) {
                        struct commit *other;
+                       int ret;
 
                        other = with_commit->item;
                        with_commit = with_commit->next;
-                       if (repo_in_merge_bases_many(r, other, 1, &commit))
-                               return 1;
+                       ret = repo_in_merge_bases_many(r, other, 1, &commit, 0);
+                       if (ret)
+                               return ret;
                }
                return 0;
        }
@@ -474,17 +523,18 @@ int repo_is_descendant_of(struct repository *r,
  * Is "commit" an ancestor of one of the "references"?
  */
 int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
-                            int nr_reference, struct commit **reference)
+                            int nr_reference, struct commit **reference,
+                            int ignore_missing_commits)
 {
-       struct commit_list *bases;
+       struct commit_list *bases = NULL;
        int ret = 0, i;
        timestamp_t generation, max_generation = GENERATION_NUMBER_ZERO;
 
        if (repo_parse_commit(r, commit))
-               return ret;
+               return ignore_missing_commits ? 0 : -1;
        for (i = 0; i < nr_reference; i++) {
                if (repo_parse_commit(r, reference[i]))
-                       return ret;
+                       return ignore_missing_commits ? 0 : -1;
 
                generation = commit_graph_generation(reference[i]);
                if (generation > max_generation)
@@ -495,10 +545,11 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
        if (generation > max_generation)
                return ret;
 
-       bases = paint_down_to_common(r, commit,
-                                    nr_reference, reference,
-                                    generation);
-       if (commit->object.flags & PARENT2)
+       if (paint_down_to_common(r, commit,
+                                nr_reference, reference,
+                                generation, ignore_missing_commits, &bases))
+               ret = -1;
+       else if (commit->object.flags & PARENT2)
                ret = 1;
        clear_commit_marks(commit, all_flags);
        clear_commit_marks_many(nr_reference, reference, all_flags);
@@ -551,6 +602,10 @@ struct commit_list *reduce_heads(struct commit_list *heads)
                }
        }
        num_head = remove_redundant(the_repository, array, num_head);
+       if (num_head < 0) {
+               free(array);
+               return NULL;
+       }
        for (i = 0; i < num_head; i++)
                tail = &commit_list_insert(array[i], tail)->next;
        free(array);
@@ -593,6 +648,8 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
        commit_list_insert(old_commit, &old_commit_list);
        ret = repo_is_descendant_of(the_repository,
                                    new_commit, old_commit_list);
+       if (ret < 0)
+               exit(128);
        free_commit_list(old_commit_list);
        return ret;
 }
index 35c4da4948122a6caea3a1757484b487db16b0fd..bf63cc468fd311a9ef658a23cec3db4fbbbac767 100644 (file)
@@ -9,18 +9,21 @@ struct ref_filter;
 struct object_id;
 struct object_array;
 
-struct commit_list *repo_get_merge_bases(struct repository *r,
-                                        struct commit *rev1,
-                                        struct commit *rev2);
-struct commit_list *repo_get_merge_bases_many(struct repository *r,
-                                             struct commit *one, int n,
-                                             struct commit **twos);
+int repo_get_merge_bases(struct repository *r,
+                        struct commit *rev1,
+                        struct commit *rev2,
+                        struct commit_list **result);
+int repo_get_merge_bases_many(struct repository *r,
+                             struct commit *one, int n,
+                             struct commit **twos,
+                             struct commit_list **result);
 /* To be used only when object flags after this call no longer matter */
-struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
-                                                   struct commit *one, int n,
-                                                   struct commit **twos);
+int repo_get_merge_bases_many_dirty(struct repository *r,
+                                   struct commit *one, int n,
+                                   struct commit **twos,
+                                   struct commit_list **result);
 
-struct commit_list *get_octopus_merge_bases(struct commit_list *in);
+int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result);
 
 int repo_is_descendant_of(struct repository *r,
                          struct commit *commit,
@@ -30,7 +33,8 @@ int repo_in_merge_bases(struct repository *r,
                        struct commit *reference);
 int repo_in_merge_bases_many(struct repository *r,
                             struct commit *commit,
-                            int nr_reference, struct commit **reference);
+                            int nr_reference, struct commit **reference,
+                            int ignore_missing_commits);
 
 /*
  * Takes a list of commits and returns a new list where those
index ef679a0b939046c4aac15567cdf3c0ae8c079d29..467be9f7f99408edbe1a34e2f21c491dd50e2813 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -1052,7 +1052,7 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
 {
        struct object_id oid;
        struct rev_collect revs;
-       struct commit_list *bases;
+       struct commit_list *bases = NULL;
        int i;
        struct commit *ret = NULL;
        char *full_refname;
@@ -1077,8 +1077,9 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
        for (i = 0; i < revs.nr; i++)
                revs.commit[i]->object.flags &= ~TMP_MARK;
 
-       bases = repo_get_merge_bases_many(the_repository, commit, revs.nr,
-                                         revs.commit);
+       if (repo_get_merge_bases_many(the_repository, commit, revs.nr,
+                                     revs.commit, &bases) < 0)
+               exit(128);
 
        /*
         * There should be one and only one merge base, when we found
index fcf1afd75de4eb14a0123a2a75692298f2c39a0b..75193ded4bdeda01fc440db26b08e40ae2d3a73f 100644 (file)
@@ -454,16 +454,18 @@ fi
 
 # This function is equivalent to
 #
-#    __gitcomp "$(git xxx --git-completion-helper) ..."
+#    ___git_resolved_builtins=$(git xxx --git-completion-helper)
 #
-# except that the output is cached. Accept 1-3 arguments:
+# except that the result of the execution is cached.
+#
+# Accept 1-3 arguments:
 # 1: the git command to execute, this is also the cache key
+#    (use "_" when the command contains spaces, e.g. "remote add"
+#    becomes "remote_add")
 # 2: extra options to be added on top (e.g. negative forms)
 # 3: options to be excluded
-__gitcomp_builtin ()
+__git_resolve_builtins ()
 {
-       # spaces must be replaced with underscore for multi-word
-       # commands, e.g. "git remote add" becomes remote_add.
        local cmd="$1"
        local incl="${2-}"
        local excl="${3-}"
@@ -489,7 +491,24 @@ __gitcomp_builtin ()
                eval "$var=\"$options\""
        fi
 
-       __gitcomp "$options"
+       ___git_resolved_builtins="$options"
+}
+
+# This function is equivalent to
+#
+#    __gitcomp "$(git xxx --git-completion-helper) ..."
+#
+# except that the output is cached. Accept 1-3 arguments:
+# 1: the git command to execute, this is also the cache key
+#    (use "_" when the command contains spaces, e.g. "remote add"
+#    becomes "remote_add")
+# 2: extra options to be added on top (e.g. negative forms)
+# 3: options to be excluded
+__gitcomp_builtin ()
+{
+       __git_resolve_builtins "$1" "$2" "$3"
+
+       __gitcomp "$___git_resolved_builtins"
 }
 
 # Variation of __gitcomp_nl () that appends to the existing list of
@@ -556,6 +575,26 @@ __gitcomp_file ()
        true
 }
 
+# Find the current subcommand for commands that follow the syntax:
+#
+#    git <command> <subcommand>
+#
+# 1: List of possible subcommands.
+# 2: Optional subcommand to return when none is found.
+__git_find_subcommand ()
+{
+       local subcommand subcommands="$1" default_subcommand="$2"
+
+       for subcommand in $subcommands; do
+               if [ "$subcommand" = "${words[__git_cmd_idx+1]}" ]; then
+                       echo $subcommand
+                       return
+               fi
+       done
+
+       echo $default_subcommand
+}
+
 # Execute 'git ls-files', unless the --committable option is specified, in
 # which case it runs 'git diff-index' to find out the files that can be
 # committed.  It return paths relative to the directory specified in the first
@@ -2471,13 +2510,30 @@ _git_rebase ()
 
 _git_reflog ()
 {
-       local subcommands="show delete expire"
-       local subcommand="$(__git_find_on_cmdline "$subcommands")"
+       local subcommands subcommand
 
-       if [ -z "$subcommand" ]; then
-               __gitcomp "$subcommands"
-       else
-               __git_complete_refs
+       __git_resolve_builtins "reflog"
+
+       subcommands="$___git_resolved_builtins"
+       subcommand="$(__git_find_subcommand "$subcommands" "show")"
+
+       case "$subcommand,$cur" in
+       show,--*)
+               __gitcomp "
+                       $__git_log_common_options
+                       "
+               return
+               ;;
+       $subcommand,--*)
+               __gitcomp_builtin "reflog_$subcommand"
+               return
+               ;;
+       esac
+
+       __git_complete_refs
+
+       if [ $((cword - __git_cmd_idx)) -eq 1 ]; then
+               __gitcompappend "$subcommands" "" "$cur" " "
        fi
 }
 
@@ -3573,7 +3629,7 @@ __git_complete_worktree_paths ()
        # Generate completion reply from worktree list skipping the first
        # entry: it's the path of the main worktree, which can't be moved,
        # removed, locked, etc.
-       __gitcomp_nl "$(git worktree list --porcelain |
+       __gitcomp_nl "$(__git worktree list --porcelain |
                sed -n -e '2,$ s/^worktree //p')"
 }
 
index 6c8df04273702fa47215dffa263477df347900ee..5e8717c774eff4bb2364344c440a4efb4686e4f4 100644 (file)
@@ -570,7 +570,7 @@ void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb)
 {
        int i;
        struct commit *mb_child[2] = {0};
-       struct commit_list *merge_bases;
+       struct commit_list *merge_bases = NULL;
 
        for (i = 0; i < revs->pending.nr; i++) {
                struct object *obj = revs->pending.objects[i].item;
@@ -597,7 +597,8 @@ void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb)
                mb_child[1] = lookup_commit_reference(the_repository, &oid);
        }
 
-       merge_bases = repo_get_merge_bases(the_repository, mb_child[0], mb_child[1]);
+       if (repo_get_merge_bases(the_repository, mb_child[0], mb_child[1], &merge_bases) < 0)
+               exit(128);
        if (!merge_bases)
                die(_("no merge base found"));
        if (merge_bases->next)
diff --git a/dir.c b/dir.c
index ac699542302cece1d1aea426cd4cc37940e6fead..20ebe4cba2687e027765876ddc57b086fa85dd71 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -3918,6 +3918,26 @@ void untracked_cache_invalidate_path(struct index_state *istate,
                                 path, strlen(path));
 }
 
+void untracked_cache_invalidate_trimmed_path(struct index_state *istate,
+                                            const char *path,
+                                            int safe_path)
+{
+       size_t len = strlen(path);
+
+       if (!len)
+               BUG("untracked_cache_invalidate_trimmed_path given zero length path");
+
+       if (path[len - 1] != '/') {
+               untracked_cache_invalidate_path(istate, path, safe_path);
+       } else {
+               struct strbuf tmp = STRBUF_INIT;
+
+               strbuf_add(&tmp, path, len - 1);
+               untracked_cache_invalidate_path(istate, tmp.buf, safe_path);
+               strbuf_release(&tmp);
+       }
+}
+
 void untracked_cache_remove_from_index(struct index_state *istate,
                                       const char *path)
 {
diff --git a/dir.h b/dir.h
index 98aa85fcc0ee357a2df50014008c3e5ec12acb25..45a7b9ec5f2d52214e8000dbd68913056a1a2d77 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -576,6 +576,13 @@ int cmp_dir_entry(const void *p1, const void *p2);
 int check_dir_entry_contains(const struct dir_entry *out, const struct dir_entry *in);
 
 void untracked_cache_invalidate_path(struct index_state *, const char *, int safe_path);
+/*
+ * Invalidate the untracked-cache for this path, but first strip
+ * off a trailing slash, if present.
+ */
+void untracked_cache_invalidate_trimmed_path(struct index_state *,
+                                            const char *path,
+                                            int safe_path);
 void untracked_cache_remove_from_index(struct index_state *, const char *);
 void untracked_cache_add_to_index(struct index_state *, const char *);
 
index 90632a39bc995af8bf56166b4d89bba5d6dd5272..60706ea3987f2c4d11e5e2e2d21aa5cd5e9196e1 100644 (file)
@@ -207,6 +207,9 @@ void setup_git_env(const char *git_dir)
        shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
        if (shallow_file)
                set_alternate_shallow_file(the_repository, shallow_file, 0);
+
+       if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0))
+               fetch_if_missing = 0;
 }
 
 int is_bare_repository(void)
index e5351c9dd95ea6e7afe77b1db466d6ab30310491..5cec19cecc1a5a2c057f807f3b96dd2b29f0b355 100644 (file)
@@ -36,6 +36,7 @@ const char *getenv_safe(struct strvec *argv, const char *name);
 #define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
 #define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
 #define GIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE"
+#define NO_LAZY_FETCH_ENVIRONMENT "GIT_NO_LAZY_FETCH"
 #define GITATTRIBUTES_FILE ".gitattributes"
 #define INFOATTRIBUTES_FILE "info/attributes"
 #define ATTRIBUTE_MACRO_PREFIX "[attr]"
index f670c50937898342f693708c706a0db270be3a6d..2b17d60bbbecb0e0e53a934b4376e2207649e826 100644 (file)
@@ -5,6 +5,7 @@
 #include "ewah/ewok.h"
 #include "fsmonitor.h"
 #include "fsmonitor-ipc.h"
+#include "name-hash.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "trace2.h"
@@ -183,79 +184,282 @@ static int query_fsmonitor_hook(struct repository *r,
        return result;
 }
 
-static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
+/*
+ * Invalidate the FSM bit on this CE.  This is like mark_fsmonitor_invalid()
+ * but we've already handled the untracked-cache, so let's not repeat that
+ * work.  This also lets us have a different trace message so that we can
+ * see everything that was done as part of the refresh-callback.
+ */
+static void invalidate_ce_fsm(struct cache_entry *ce)
 {
-       int i, len = strlen(name);
-       int pos = index_name_pos(istate, name, len);
+       if (ce->ce_flags & CE_FSMONITOR_VALID) {
+               trace_printf_key(&trace_fsmonitor,
+                                "fsmonitor_refresh_callback INV: '%s'",
+                                ce->name);
+               ce->ce_flags &= ~CE_FSMONITOR_VALID;
+       }
+}
+
+static size_t handle_path_with_trailing_slash(
+       struct index_state *istate, const char *name, int pos);
+
+/*
+ * Use the name-hash to do a case-insensitive cache-entry lookup with
+ * the pathname and invalidate the cache-entry.
+ *
+ * Returns the number of cache-entries that we invalidated.
+ */
+static size_t handle_using_name_hash_icase(
+       struct index_state *istate, const char *name)
+{
+       struct cache_entry *ce = NULL;
+
+       ce = index_file_exists(istate, name, strlen(name), 1);
+       if (!ce)
+               return 0;
 
+       /*
+        * A case-insensitive search in the name-hash using the
+        * observed pathname found a cache-entry, so the observed path
+        * is case-incorrect.  Invalidate the cache-entry and use the
+        * correct spelling from the cache-entry to invalidate the
+        * untracked-cache.  Since we now have sparse-directories in
+        * the index, the observed pathname may represent a regular
+        * file or a sparse-index directory.
+        *
+        * Note that we should not have seen FSEvents for a
+        * sparse-index directory, but we handle it just in case.
+        *
+        * Either way, we know that there are not any cache-entries for
+        * children inside the cone of the directory, so we don't need to
+        * do the usual scan.
+        */
        trace_printf_key(&trace_fsmonitor,
-                        "fsmonitor_refresh_callback '%s' (pos %d)",
-                        name, pos);
+                        "fsmonitor_refresh_callback MAP: '%s' '%s'",
+                        name, ce->name);
 
-       if (name[len - 1] == '/') {
-               /*
-                * The daemon can decorate directory events, such as
-                * moves or renames, with a trailing slash if the OS
-                * FS Event contains sufficient information, such as
-                * MacOS.
-                *
-                * Use this to invalidate the entire cone under that
-                * directory.
-                *
-                * We do not expect an exact match because the index
-                * does not normally contain directory entries, so we
-                * start at the insertion point and scan.
-                */
-               if (pos < 0)
-                       pos = -pos - 1;
+       /*
+        * NEEDSWORK: We used the name-hash to find the correct
+        * case-spelling of the pathname in the cache-entry[], so
+        * technically this is a tracked file or a sparse-directory.
+        * It should not have any entries in the untracked-cache, so
+        * we should not need to use the case-corrected spelling to
+        * invalidate the the untracked-cache.  So we may not need to
+        * do this.  For now, I'm going to be conservative and always
+        * do it; we can revisit this later.
+        */
+       untracked_cache_invalidate_trimmed_path(istate, ce->name, 0);
 
-               /* Mark all entries for the folder invalid */
-               for (i = pos; i < istate->cache_nr; i++) {
-                       if (!starts_with(istate->cache[i]->name, name))
-                               break;
-                       istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
-               }
+       invalidate_ce_fsm(ce);
+       return 1;
+}
+
+/*
+ * Use the dir-name-hash to find the correct-case spelling of the
+ * directory.  Use the canonical spelling to invalidate all of the
+ * cache-entries within the matching cone.
+ *
+ * Returns the number of cache-entries that we invalidated.
+ */
+static size_t handle_using_dir_name_hash_icase(
+       struct index_state *istate, const char *name)
+{
+       struct strbuf canonical_path = STRBUF_INIT;
+       int pos;
+       size_t len = strlen(name);
+       size_t nr_in_cone;
+
+       if (name[len - 1] == '/')
+               len--;
+
+       if (!index_dir_find(istate, name, len, &canonical_path))
+               return 0; /* name is untracked */
 
+       if (!memcmp(name, canonical_path.buf, canonical_path.len)) {
+               strbuf_release(&canonical_path);
                /*
-                * We need to remove the traling "/" from the path
-                * for the untracked cache.
+                * NEEDSWORK: Our caller already tried an exact match
+                * and failed to find one.  They called us to do an
+                * ICASE match, so we should never get an exact match,
+                * so we could promote this to a BUG() here if we
+                * wanted to.  It doesn't hurt anything to just return
+                * 0 and go on because we should never get here.  Or we
+                * could just get rid of the memcmp() and this "if"
+                * clause completely.
                 */
-               name[len - 1] = '\0';
-       } else if (pos >= 0) {
+               BUG("handle_using_dir_name_hash_icase(%s) did not exact match",
+                   name);
+       }
+
+       trace_printf_key(&trace_fsmonitor,
+                        "fsmonitor_refresh_callback MAP: '%s' '%s'",
+                        name, canonical_path.buf);
+
+       /*
+        * The dir-name-hash only tells us the corrected spelling of
+        * the prefix.  We have to use this canonical path to do a
+        * lookup in the cache-entry array so that we repeat the
+        * original search using the case-corrected spelling.
+        */
+       strbuf_addch(&canonical_path, '/');
+       pos = index_name_pos(istate, canonical_path.buf,
+                            canonical_path.len);
+       nr_in_cone = handle_path_with_trailing_slash(
+               istate, canonical_path.buf, pos);
+       strbuf_release(&canonical_path);
+       return nr_in_cone;
+}
+
+/*
+ * The daemon sent an observed pathname without a trailing slash.
+ * (This is the normal case.)  We do not know if it is a tracked or
+ * untracked file, a sparse-directory, or a populated directory (on a
+ * platform such as Windows where FSEvents are not qualified).
+ *
+ * The pathname contains the observed case reported by the FS. We
+ * do not know it is case-correct or -incorrect.
+ *
+ * Assume it is case-correct and try an exact match.
+ *
+ * Return the number of cache-entries that we invalidated.
+ */
+static size_t handle_path_without_trailing_slash(
+       struct index_state *istate, const char *name, int pos)
+{
+       /*
+        * Mark the untracked cache dirty for this path (regardless of
+        * whether or not we find an exact match for it in the index).
+        * Since the path is unqualified (no trailing slash hint in the
+        * FSEvent), it may refer to a file or directory. So we should
+        * not assume one or the other and should always let the untracked
+        * cache decide what needs to invalidated.
+        */
+       untracked_cache_invalidate_trimmed_path(istate, name, 0);
+
+       if (pos >= 0) {
                /*
-                * We have an exact match for this path and can just
-                * invalidate it.
+                * An exact match on a tracked file. We assume that we
+                * do not need to scan forward for a sparse-directory
+                * cache-entry with the same pathname, nor for a cone
+                * at that directory. (That is, assume no D/F conflicts.)
                 */
-               istate->cache[pos]->ce_flags &= ~CE_FSMONITOR_VALID;
+               invalidate_ce_fsm(istate->cache[pos]);
+               return 1;
        } else {
+               size_t nr_in_cone;
+               struct strbuf work_path = STRBUF_INIT;
+
                /*
-                * The path is not a tracked file -or- it is a
-                * directory event on a platform that cannot
-                * distinguish between file and directory events in
-                * the event handler, such as Windows.
-                *
-                * Scan as if it is a directory and invalidate the
-                * cone under it.  (But remember to ignore items
-                * between "name" and "name/", such as "name-" and
-                * "name.".
+                * The negative "pos" gives us the suggested insertion
+                * point for the pathname (without the trailing slash).
+                * We need to see if there is a directory with that
+                * prefix, but there can be lots of pathnames between
+                * "foo" and "foo/" like "foo-" or "foo-bar", so we
+                * don't want to do our own scan.
                 */
+               strbuf_add(&work_path, name, strlen(name));
+               strbuf_addch(&work_path, '/');
+               pos = index_name_pos(istate, work_path.buf, work_path.len);
+               nr_in_cone = handle_path_with_trailing_slash(
+                       istate, work_path.buf, pos);
+               strbuf_release(&work_path);
+               return nr_in_cone;
+       }
+}
+
+/*
+ * The daemon can decorate directory events, such as a move or rename,
+ * by adding a trailing slash to the observed name.  Use this to
+ * explicitly invalidate the entire cone under that directory.
+ *
+ * The daemon can only reliably do that if the OS FSEvent contains
+ * sufficient information in the event.
+ *
+ * macOS FSEvents have enough information.
+ *
+ * Other platforms may or may not be able to do it (and it might
+ * depend on the type of event (for example, a daemon could lstat() an
+ * observed pathname after a rename, but not after a delete)).
+ *
+ * If we find an exact match in the index for a path with a trailing
+ * slash, it means that we matched a sparse-index directory in a
+ * cone-mode sparse-checkout (since that's the only time we have
+ * directories in the index).  We should never see this in practice
+ * (because sparse directories should not be present and therefore
+ * not generating FS events).  Either way, we can treat them in the
+ * same way and just invalidate the cache-entry and the untracked
+ * cache (and in this case, the forward cache-entry scan won't find
+ * anything and it doesn't hurt to let it run).
+ *
+ * Return the number of cache-entries that we invalidated.  We will
+ * use this later to determine if we need to attempt a second
+ * case-insensitive search on case-insensitive file systems.  That is,
+ * if the search using the observed-case in the FSEvent yields any
+ * results, we assume the prefix is case-correct.  If there are no
+ * matches, we still don't know if the observed path is simply
+ * untracked or case-incorrect.
+ */
+static size_t handle_path_with_trailing_slash(
+       struct index_state *istate, const char *name, int pos)
+{
+       int i;
+       size_t nr_in_cone = 0;
+
+       /*
+        * Mark the untracked cache dirty for this directory path
+        * (regardless of whether or not we find an exact match for it
+        * in the index or find it to be proper prefix of one or more
+        * files in the index), since the FSEvent is hinting that
+        * there may be changes on or within the directory.
+        */
+       untracked_cache_invalidate_trimmed_path(istate, name, 0);
+
+       if (pos < 0)
                pos = -pos - 1;
 
-               for (i = pos; i < istate->cache_nr; i++) {
-                       if (!starts_with(istate->cache[i]->name, name))
-                               break;
-                       if ((unsigned char)istate->cache[i]->name[len] > '/')
-                               break;
-                       if (istate->cache[i]->name[len] == '/')
-                               istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
-               }
+       /* Mark all entries for the folder invalid */
+       for (i = pos; i < istate->cache_nr; i++) {
+               if (!starts_with(istate->cache[i]->name, name))
+                       break;
+               invalidate_ce_fsm(istate->cache[i]);
+               nr_in_cone++;
        }
 
+       return nr_in_cone;
+}
+
+static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
+{
+       int len = strlen(name);
+       int pos = index_name_pos(istate, name, len);
+       size_t nr_in_cone;
+
+       trace_printf_key(&trace_fsmonitor,
+                        "fsmonitor_refresh_callback '%s' (pos %d)",
+                        name, pos);
+
+       if (name[len - 1] == '/')
+               nr_in_cone = handle_path_with_trailing_slash(istate, name, pos);
+       else
+               nr_in_cone = handle_path_without_trailing_slash(istate, name, pos);
+
        /*
-        * Mark the untracked cache dirty even if it wasn't found in the index
-        * as it could be a new untracked file.
+        * If we did not find an exact match for this pathname or any
+        * cache-entries with this directory prefix and we're on a
+        * case-insensitive file system, try again using the name-hash
+        * and dir-name-hash.
         */
-       untracked_cache_invalidate_path(istate, name, 0);
+       if (!nr_in_cone && ignore_case) {
+               nr_in_cone = handle_using_name_hash_icase(istate, name);
+               if (!nr_in_cone)
+                       nr_in_cone = handle_using_dir_name_hash_icase(
+                               istate, name);
+       }
+
+       if (nr_in_cone)
+               trace_printf_key(&trace_fsmonitor,
+                                "fsmonitor_refresh_callback CNT: %d",
+                                (int)nr_in_cone);
 }
 
 /*
diff --git a/git.c b/git.c
index 7068a184b0a2947c6d62c3331c6f1a418708c7be..5265f920f165d99f01584eed54554dd51563acca 100644 (file)
--- a/git.c
+++ b/git.c
@@ -4,6 +4,7 @@
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "help.h"
+#include "object-file.h"
 #include "pager.h"
 #include "read-cache-ll.h"
 #include "run-command.h"
@@ -186,6 +187,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                        use_pager = 0;
                        if (envchanged)
                                *envchanged = 1;
+               } else if (!strcmp(cmd, "--no-lazy-fetch")) {
+                       fetch_if_missing = 0;
+                       setenv(NO_LAZY_FETCH_ENVIRONMENT, "1", 1);
+                       if (envchanged)
+                               *envchanged = 1;
                } else if (!strcmp(cmd, "--no-replace-objects")) {
                        disable_replace_refs();
                        setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
index 12d111374107a7a071ac90d035c5172af2b63c79..33db41bfac5f977747ce7af864207df3f255e491 100644 (file)
@@ -1575,8 +1575,11 @@ static int verify_merge_base(struct object_id *head_oid, struct ref *remote)
        struct commit *head = lookup_commit_or_die(head_oid, "HEAD");
        struct commit *branch = lookup_commit_or_die(&remote->old_oid,
                                                     remote->name);
+       int ret = repo_in_merge_bases(the_repository, branch, head);
 
-       return repo_in_merge_bases(the_repository, branch, head);
+       if (ret < 0)
+               exit(128);
+       return ret;
 }
 
 static int delete_remote_branch(const char *pattern, int force)
index da287cc8e0dd2935cb230dd256d5f268495ed40f..4346f8da4560fd518d73db7969faa9127e302090 100644 (file)
@@ -711,15 +711,6 @@ static void filter_combine__free(void *filter_data)
        free(d);
 }
 
-static void add_all(struct oidset *dest, struct oidset *src) {
-       struct oidset_iter iter;
-       struct object_id *src_oid;
-
-       oidset_iter_init(src, &iter);
-       while ((src_oid = oidset_iter_next(&iter)) != NULL)
-               oidset_insert(dest, src_oid);
-}
-
 static void filter_combine__finalize_omits(
        struct oidset *omits,
        void *filter_data)
@@ -728,7 +719,7 @@ static void filter_combine__finalize_omits(
        size_t sub;
 
        for (sub = 0; sub < d->nr; sub++) {
-               add_all(omits, &d->sub[sub].omits);
+               oidset_insert_from_set(omits, &d->sub[sub].omits);
                oidset_clear(&d->sub[sub].omits);
        }
 }
index 337b9334cdbafe0d3ffd2bf2fd36898f6d112410..e5438b029d90f352f0c434ebc8088c01fce11f3a 100644 (file)
@@ -1011,7 +1011,7 @@ static int do_remerge_diff(struct rev_info *opt,
                           struct object_id *oid)
 {
        struct merge_options o;
-       struct commit_list *bases;
+       struct commit_list *bases = NULL;
        struct merge_result res = {0};
        struct pretty_print_context ctx = {0};
        struct commit *parent1 = parents->item;
@@ -1036,7 +1036,8 @@ static int do_remerge_diff(struct rev_info *opt,
        /* Parse the relevant commits and get the merge bases */
        parse_commit_or_die(parent1);
        parse_commit_or_die(parent2);
-       bases = repo_get_merge_bases(the_repository, parent1, parent2);
+       if (repo_get_merge_bases(the_repository, parent1, parent2, &bases) < 0)
+               exit(128);
 
        /* Re-merge the parents */
        merge_incore_recursive(&o, bases, parent1, parent2, &res);
index 6a48aea227526e8891e57b7fb53439ecc43a4cd6..201f8f77755b439ad1b91b5b692c16aaeba5d032 100644 (file)
@@ -543,6 +543,7 @@ enum conflict_and_info_types {
        CONFLICT_SUBMODULE_HISTORY_NOT_AVAILABLE,
        CONFLICT_SUBMODULE_MAY_HAVE_REWINDS,
        CONFLICT_SUBMODULE_NULL_MERGE_BASE,
+       CONFLICT_SUBMODULE_CORRUPT,
 
        /* Keep this entry _last_ in the list */
        NB_CONFLICT_TYPES,
@@ -595,7 +596,9 @@ static const char *type_short_descriptions[] = {
        [CONFLICT_SUBMODULE_MAY_HAVE_REWINDS] =
                "CONFLICT (submodule may have rewinds)",
        [CONFLICT_SUBMODULE_NULL_MERGE_BASE] =
-               "CONFLICT (submodule lacks merge base)"
+               "CONFLICT (submodule lacks merge base)",
+       [CONFLICT_SUBMODULE_CORRUPT] =
+               "CONFLICT (submodule corrupt)"
 };
 
 struct logical_conflict_info {
@@ -1658,9 +1661,10 @@ static int collect_merge_info(struct merge_options *opt,
        info.data = opt;
        info.show_all_errors = 1;
 
-       parse_tree(merge_base);
-       parse_tree(side1);
-       parse_tree(side2);
+       if (parse_tree(merge_base) < 0 ||
+           parse_tree(side1) < 0 ||
+           parse_tree(side2) < 0)
+               return -1;
        init_tree_desc(t + 0, merge_base->buffer, merge_base->size);
        init_tree_desc(t + 1, side1->buffer, side1->size);
        init_tree_desc(t + 2, side2->buffer, side2->size);
@@ -1709,7 +1713,14 @@ static int find_first_merges(struct repository *repo,
                die("revision walk setup failed");
        while ((commit = get_revision(&revs)) != NULL) {
                struct object *o = &(commit->object);
-               if (repo_in_merge_bases(repo, b, commit))
+               int ret = repo_in_merge_bases(repo, b, commit);
+
+               if (ret < 0) {
+                       object_array_clear(&merges);
+                       release_revisions(&revs);
+                       return ret;
+               }
+               if (ret > 0)
                        add_object_array(o, NULL, &merges);
        }
        reset_revision_walk();
@@ -1724,9 +1735,17 @@ static int find_first_merges(struct repository *repo,
                contains_another = 0;
                for (j = 0; j < merges.nr; j++) {
                        struct commit *m2 = (struct commit *) merges.objects[j].item;
-                       if (i != j && repo_in_merge_bases(repo, m2, m1)) {
-                               contains_another = 1;
-                               break;
+                       if (i != j) {
+                               int ret = repo_in_merge_bases(repo, m2, m1);
+                               if (ret < 0) {
+                                       object_array_clear(&merges);
+                                       release_revisions(&revs);
+                                       return ret;
+                               }
+                               if (ret > 0) {
+                                       contains_another = 1;
+                                       break;
+                               }
                        }
                }
 
@@ -1748,7 +1767,7 @@ static int merge_submodule(struct merge_options *opt,
 {
        struct repository subrepo;
        struct strbuf sb = STRBUF_INIT;
-       int ret = 0;
+       int ret = 0, ret2;
        struct commit *commit_o, *commit_a, *commit_b;
        int parent_count;
        struct object_array merges;
@@ -1795,8 +1814,28 @@ static int merge_submodule(struct merge_options *opt,
        }
 
        /* check whether both changes are forward */
-       if (!repo_in_merge_bases(&subrepo, commit_o, commit_a) ||
-           !repo_in_merge_bases(&subrepo, commit_o, commit_b)) {
+       ret2 = repo_in_merge_bases(&subrepo, commit_o, commit_a);
+       if (ret2 < 0) {
+               path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0,
+                        path, NULL, NULL, NULL,
+                        _("Failed to merge submodule %s "
+                          "(repository corrupt)"),
+                        path);
+               ret = -1;
+               goto cleanup;
+       }
+       if (ret2 > 0)
+               ret2 = repo_in_merge_bases(&subrepo, commit_o, commit_b);
+       if (ret2 < 0) {
+               path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0,
+                        path, NULL, NULL, NULL,
+                        _("Failed to merge submodule %s "
+                          "(repository corrupt)"),
+                        path);
+               ret = -1;
+               goto cleanup;
+       }
+       if (!ret2) {
                path_msg(opt, CONFLICT_SUBMODULE_MAY_HAVE_REWINDS, 0,
                         path, NULL, NULL, NULL,
                         _("Failed to merge submodule %s "
@@ -1806,7 +1845,17 @@ static int merge_submodule(struct merge_options *opt,
        }
 
        /* Case #1: a is contained in b or vice versa */
-       if (repo_in_merge_bases(&subrepo, commit_a, commit_b)) {
+       ret2 = repo_in_merge_bases(&subrepo, commit_a, commit_b);
+       if (ret2 < 0) {
+               path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0,
+                        path, NULL, NULL, NULL,
+                        _("Failed to merge submodule %s "
+                          "(repository corrupt)"),
+                        path);
+               ret = -1;
+               goto cleanup;
+       }
+       if (ret2 > 0) {
                oidcpy(result, b);
                path_msg(opt, INFO_SUBMODULE_FAST_FORWARDING, 1,
                         path, NULL, NULL, NULL,
@@ -1815,7 +1864,17 @@ static int merge_submodule(struct merge_options *opt,
                ret = 1;
                goto cleanup;
        }
-       if (repo_in_merge_bases(&subrepo, commit_b, commit_a)) {
+       ret2 = repo_in_merge_bases(&subrepo, commit_b, commit_a);
+       if (ret2 < 0) {
+               path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0,
+                        path, NULL, NULL, NULL,
+                        _("Failed to merge submodule %s "
+                          "(repository corrupt)"),
+                        path);
+               ret = -1;
+               goto cleanup;
+       }
+       if (ret2 > 0) {
                oidcpy(result, a);
                path_msg(opt, INFO_SUBMODULE_FAST_FORWARDING, 1,
                         path, NULL, NULL, NULL,
@@ -1840,6 +1899,14 @@ static int merge_submodule(struct merge_options *opt,
        parent_count = find_first_merges(&subrepo, path, commit_a, commit_b,
                                         &merges);
        switch (parent_count) {
+       case -1:
+               path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0,
+                        path, NULL, NULL, NULL,
+                        _("Failed to merge submodule %s "
+                          "(repository corrupt)"),
+                        path);
+               ret = -1;
+               break;
        case 0:
                path_msg(opt, CONFLICT_SUBMODULE_FAILED_TO_MERGE, 0,
                         path, NULL, NULL, NULL,
@@ -4377,9 +4444,11 @@ static int checkout(struct merge_options *opt,
        unpack_opts.verbose_update = (opt->verbosity > 2);
        unpack_opts.fn = twoway_merge;
        unpack_opts.preserve_ignored = 0; /* FIXME: !opts->overwrite_ignore */
-       parse_tree(prev);
+       if (parse_tree(prev) < 0)
+               return -1;
        init_tree_desc(&trees[0], prev->buffer, prev->size);
-       parse_tree(next);
+       if (parse_tree(next) < 0)
+               return -1;
        init_tree_desc(&trees[1], next->buffer, next->size);
 
        ret = unpack_trees(2, trees, &unpack_opts);
@@ -4983,6 +5052,9 @@ redo:
 
        if (result->clean >= 0) {
                result->tree = parse_tree_indirect(&working_tree_oid);
+               if (!result->tree)
+                       die(_("unable to read tree (%s)"),
+                           oid_to_hex(&working_tree_oid));
                /* existence of conflicted entries implies unclean */
                result->clean &= strmap_empty(&opt->priv->conflicted);
        }
@@ -5008,7 +5080,11 @@ static void merge_ort_internal(struct merge_options *opt,
        struct strbuf merge_base_abbrev = STRBUF_INIT;
 
        if (!merge_bases) {
-               merge_bases = repo_get_merge_bases(the_repository, h1, h2);
+               if (repo_get_merge_bases(the_repository, h1, h2,
+                                        &merge_bases) < 0) {
+                       result->clean = -1;
+                       return;
+               }
                /* See merge-ort.h:merge_incore_recursive() declaration NOTE */
                merge_bases = reverse_commit_list(merge_bases);
        }
index a0c3e7a2d9105dd895f0ae2613d0f87f00b8d794..103ee321aeb8cd8c169d35316bb20cfd9eea1693 100644 (file)
@@ -405,7 +405,8 @@ static inline int merge_detect_rename(struct merge_options *opt)
 
 static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
 {
-       parse_tree(tree);
+       if (parse_tree(tree) < 0)
+               exit(128);
        init_tree_desc(desc, tree->buffer, tree->size);
 }
 
@@ -1139,7 +1140,13 @@ static int find_first_merges(struct repository *repo,
                die("revision walk setup failed");
        while ((commit = get_revision(&revs)) != NULL) {
                struct object *o = &(commit->object);
-               if (repo_in_merge_bases(repo, b, commit))
+               int ret = repo_in_merge_bases(repo, b, commit);
+               if (ret < 0) {
+                       object_array_clear(&merges);
+                       release_revisions(&revs);
+                       return ret;
+               }
+               if (ret)
                        add_object_array(o, NULL, &merges);
        }
        reset_revision_walk();
@@ -1154,9 +1161,17 @@ static int find_first_merges(struct repository *repo,
                contains_another = 0;
                for (j = 0; j < merges.nr; j++) {
                        struct commit *m2 = (struct commit *) merges.objects[j].item;
-                       if (i != j && repo_in_merge_bases(repo, m2, m1)) {
-                               contains_another = 1;
-                               break;
+                       if (i != j) {
+                               int ret = repo_in_merge_bases(repo, m2, m1);
+                               if (ret < 0) {
+                                       object_array_clear(&merges);
+                                       release_revisions(&revs);
+                                       return ret;
+                               }
+                               if (ret > 0) {
+                                       contains_another = 1;
+                                       break;
+                               }
                        }
                }
 
@@ -1192,7 +1207,7 @@ static int merge_submodule(struct merge_options *opt,
                           const struct object_id *b)
 {
        struct repository subrepo;
-       int ret = 0;
+       int ret = 0, ret2;
        struct commit *commit_base, *commit_a, *commit_b;
        int parent_count;
        struct object_array merges;
@@ -1229,14 +1244,32 @@ static int merge_submodule(struct merge_options *opt,
        }
 
        /* check whether both changes are forward */
-       if (!repo_in_merge_bases(&subrepo, commit_base, commit_a) ||
-           !repo_in_merge_bases(&subrepo, commit_base, commit_b)) {
+       ret2 = repo_in_merge_bases(&subrepo, commit_base, commit_a);
+       if (ret2 < 0) {
+               output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
+               ret = -1;
+               goto cleanup;
+       }
+       if (ret2 > 0)
+               ret2 = repo_in_merge_bases(&subrepo, commit_base, commit_b);
+       if (ret2 < 0) {
+               output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
+               ret = -1;
+               goto cleanup;
+       }
+       if (!ret2) {
                output(opt, 1, _("Failed to merge submodule %s (commits don't follow merge-base)"), path);
                goto cleanup;
        }
 
        /* Case #1: a is contained in b or vice versa */
-       if (repo_in_merge_bases(&subrepo, commit_a, commit_b)) {
+       ret2 = repo_in_merge_bases(&subrepo, commit_a, commit_b);
+       if (ret2 < 0) {
+               output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
+               ret = -1;
+               goto cleanup;
+       }
+       if (ret2) {
                oidcpy(result, b);
                if (show(opt, 3)) {
                        output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path);
@@ -1249,7 +1282,13 @@ static int merge_submodule(struct merge_options *opt,
                ret = 1;
                goto cleanup;
        }
-       if (repo_in_merge_bases(&subrepo, commit_b, commit_a)) {
+       ret2 = repo_in_merge_bases(&subrepo, commit_b, commit_a);
+       if (ret2 < 0) {
+               output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
+               ret = -1;
+               goto cleanup;
+       }
+       if (ret2) {
                oidcpy(result, a);
                if (show(opt, 3)) {
                        output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path);
@@ -1278,6 +1317,10 @@ static int merge_submodule(struct merge_options *opt,
        parent_count = find_first_merges(&subrepo, &merges, path,
                                         commit_a, commit_b);
        switch (parent_count) {
+       case -1:
+               output(opt, 1,_("Failed to merge submodule %s (repository corrupt)"), path);
+               ret = -1;
+               break;
        case 0:
                output(opt, 1, _("Failed to merge submodule %s (merge following commits not found)"), path);
                break;
@@ -1392,11 +1435,14 @@ static int merge_mode_and_contents(struct merge_options *opt,
                        /* FIXME: bug, what if modes didn't match? */
                        result->clean = (merge_status == 0);
                } else if (S_ISGITLINK(a->mode)) {
-                       result->clean = merge_submodule(opt, &result->blob.oid,
-                                                       o->path,
-                                                       &o->oid,
-                                                       &a->oid,
-                                                       &b->oid);
+                       int clean = merge_submodule(opt, &result->blob.oid,
+                                                   o->path,
+                                                   &o->oid,
+                                                   &a->oid,
+                                                   &b->oid);
+                       if (clean < 0)
+                               return -1;
+                       result->clean = clean;
                } else if (S_ISLNK(a->mode)) {
                        switch (opt->recursive_variant) {
                        case MERGE_VARIANT_NORMAL:
@@ -3597,7 +3643,9 @@ static int merge_recursive_internal(struct merge_options *opt,
        }
 
        if (!merge_bases) {
-               merge_bases = repo_get_merge_bases(the_repository, h1, h2);
+               if (repo_get_merge_bases(the_repository, h1, h2,
+                                        &merge_bases) < 0)
+                       return -1;
                merge_bases = reverse_commit_list(merge_bases);
        }
 
diff --git a/merge.c b/merge.c
index ca89b312d173530f8c8a1e5d07470b9d2404e9d4..563281b10f1d04bd6b51a79f2852a61aa49552fd 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -77,7 +77,10 @@ int checkout_fast_forward(struct repository *r,
                return -1;
        }
        for (i = 0; i < nr_trees; i++) {
-               parse_tree(trees[i]);
+               if (parse_tree(trees[i]) < 0) {
+                       rollback_lock_file(&lock_file);
+                       return -1;
+               }
                init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
        }
 
index 251f036eef6983a66ac13013e5bee3ef770e8f9f..3a58ce03d9c4a6721941f0ff8b262b6ddb73acd2 100644 (file)
@@ -685,13 +685,20 @@ static int same_name(const struct cache_entry *ce, const char *name, int namelen
        return slow_same_name(name, namelen, ce->name, len);
 }
 
-int index_dir_exists(struct index_state *istate, const char *name, int namelen)
+int index_dir_find(struct index_state *istate, const char *name, int namelen,
+                  struct strbuf *canonical_path)
 {
        struct dir_entry *dir;
 
        lazy_init_name_hash(istate);
        expand_to_path(istate, name, namelen, 0);
        dir = find_dir_entry(istate, name, namelen);
+
+       if (canonical_path && dir && dir->nr) {
+               strbuf_reset(canonical_path);
+               strbuf_add(canonical_path, dir->name, dir->namelen);
+       }
+
        return dir && dir->nr;
 }
 
index b1b4b0fb337f12eb5878dbedcaa66ae394cba425..0cbfc4286316b244a0902c7fffd1168ba320d52f 100644 (file)
@@ -4,7 +4,12 @@
 struct cache_entry;
 struct index_state;
 
-int index_dir_exists(struct index_state *istate, const char *name, int namelen);
+
+int index_dir_find(struct index_state *istate, const char *name, int namelen,
+                  struct strbuf *canonical_path);
+
+#define index_dir_exists(i, n, l) index_dir_find((i), (n), (l), NULL)
+
 void adjust_dirname_case(struct index_state *istate, char *name);
 struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
 
index 8799b522a55f31869dcc8cbfd7229cc8db65af4c..51282934ae62b8e7daefcf8202b98e006c416c07 100644 (file)
@@ -607,7 +607,8 @@ int notes_merge(struct notes_merge_options *o,
        assert(local && remote);
 
        /* Find merge bases */
-       bases = repo_get_merge_bases(the_repository, local, remote);
+       if (repo_get_merge_bases(the_repository, local, remote, &bases) < 0)
+               exit(128);
        if (!bases) {
                base_oid = null_oid();
                base_tree_oid = the_hash_algo->empty_tree;
index 511f09bc0fea75301433fe888efbe10d5227fdc0..bd77695d7eac539ff114c4b6a031cdd81931d7d8 100644 (file)
@@ -1488,7 +1488,7 @@ int repo_get_oid_mb(struct repository *r,
                    struct object_id *oid)
 {
        struct commit *one, *two;
-       struct commit_list *mbs;
+       struct commit_list *mbs = NULL;
        struct object_id oid_tmp;
        const char *dots;
        int st;
@@ -1516,7 +1516,10 @@ int repo_get_oid_mb(struct repository *r,
        two = lookup_commit_reference_gently(r, &oid_tmp, 0);
        if (!two)
                return -1;
-       mbs = repo_get_merge_bases(r, one, two);
+       if (repo_get_merge_bases(r, one, two, &mbs) < 0) {
+               free_commit_list(mbs);
+               return -1;
+       }
        if (!mbs || mbs->next)
                st = -1;
        else {
index e6a1c4d9059ab398f06f042a7b7cdd953ff6a943..f11c59ac0cf4d41e3c19f48e04af47237797db03 100644 (file)
--- a/object.c
+++ b/object.c
@@ -271,6 +271,7 @@ struct object *parse_object_with_flags(struct repository *r,
                                       enum parse_object_flags flags)
 {
        int skip_hash = !!(flags & PARSE_OBJECT_SKIP_HASH_CHECK);
+       int discard_tree = !!(flags & PARSE_OBJECT_DISCARD_TREE);
        unsigned long size;
        enum object_type type;
        int eaten;
@@ -298,6 +299,17 @@ struct object *parse_object_with_flags(struct repository *r,
                return lookup_object(r, oid);
        }
 
+       /*
+        * If the caller does not care about the tree buffer and does not
+        * care about checking the hash, we can simply verify that we
+        * have the on-disk object with the correct type.
+        */
+       if (skip_hash && discard_tree &&
+           (!obj || obj->type == OBJ_TREE) &&
+           oid_object_info(r, oid, NULL) == OBJ_TREE) {
+               return &lookup_tree(r, oid)->object;
+       }
+
        buffer = repo_read_object_file(r, oid, &type, &size);
        if (buffer) {
                if (!skip_hash &&
@@ -311,6 +323,8 @@ struct object *parse_object_with_flags(struct repository *r,
                                          buffer, &eaten);
                if (!eaten)
                        free(buffer);
+               if (discard_tree && type == OBJ_TREE)
+                       free_tree_buffer((struct tree *)obj);
                return obj;
        }
        return NULL;
index 114d45954d082229ed747dee16f2510387145771..c7123cade622cd2a5b6aafc99ad924aafeaaa301 100644 (file)
--- a/object.h
+++ b/object.h
@@ -197,6 +197,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet);
  */
 enum parse_object_flags {
        PARSE_OBJECT_SKIP_HASH_CHECK = 1 << 0,
+       PARSE_OBJECT_DISCARD_TREE = 1 << 1,
 };
 struct object *parse_object(struct repository *r, const struct object_id *oid);
 struct object *parse_object_with_flags(struct repository *r,
index d1e5376316ecd5f9dcf549e1067697283bdc712c..91d13859106a1bc56632aeedd4030a007608a359 100644 (file)
--- a/oidset.c
+++ b/oidset.c
@@ -23,6 +23,16 @@ int oidset_insert(struct oidset *set, const struct object_id *oid)
        return !added;
 }
 
+void oidset_insert_from_set(struct oidset *dest, struct oidset *src)
+{
+       struct oidset_iter iter;
+       struct object_id *src_oid;
+
+       oidset_iter_init(src, &iter);
+       while ((src_oid = oidset_iter_next(&iter)))
+               oidset_insert(dest, src_oid);
+}
+
 int oidset_remove(struct oidset *set, const struct object_id *oid)
 {
        khiter_t pos = kh_get_oid_set(&set->set, *oid);
index ba4a5a2cd3a7a233bc9ca2cb7cf4a58a1e5a122c..262f4256d6ac5ad39e1cef4a39e36716e817d651 100644 (file)
--- a/oidset.h
+++ b/oidset.h
@@ -47,6 +47,12 @@ int oidset_contains(const struct oidset *set, const struct object_id *oid);
  */
 int oidset_insert(struct oidset *set, const struct object_id *oid);
 
+/**
+ * Insert all the oids that are in set 'src' into set 'dest'; a copy
+ * is made of each oid inserted into set 'dest'.
+ */
+void oidset_insert_from_set(struct oidset *dest, struct oidset *src);
+
 /**
  * Remove the oid from the set.
  *
index cf964b060cd128e2bc271c07ed8bb8b4c28bfe29..bdbed4295aab2f0309eb872170251e2e9b185bbf 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1759,7 +1759,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
                                goto trailer_out;
                }
                if (*arg == ')') {
-                       format_trailers_from_commit(sb, msg + c->subject_off, &opts);
+                       format_trailers_from_commit(&opts, msg + c->subject_off, sb);
                        ret = arg - placeholder + 1;
                }
        trailer_out:
index 0ec29f7385480ad4ee71a6cc684307b2bf19c814..03542d023686f8b9d7089dddef0d17caf6c1ae44 100644 (file)
@@ -1991,7 +1991,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct exp
                        struct strbuf s = STRBUF_INIT;
 
                        /* Format the trailer info according to the trailer_opts given */
-                       format_trailers_from_commit(&s, subpos, &atom->u.contents.trailer_opts);
+                       format_trailers_from_commit(&atom->u.contents.trailer_opts, subpos, &s);
 
                        v->s = strbuf_detach(&s, NULL);
                } else if (atom->u.contents.option == C_BARE)
index eaa82967ee9ae347af9e0de590d09e7b424fe60d..74dab18eda50f8158f3e8c133a8dde70299ce3cb 100644 (file)
@@ -346,6 +346,7 @@ struct reftable_ref_iterator {
        struct object_id oid;
 
        const char *prefix;
+       size_t prefix_len;
        unsigned int flags;
        int err;
 };
@@ -374,8 +375,8 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
                        continue;
                }
 
-               if (iter->prefix &&
-                   strncmp(iter->prefix, iter->ref.refname, strlen(iter->prefix))) {
+               if (iter->prefix_len &&
+                   strncmp(iter->prefix, iter->ref.refname, iter->prefix_len)) {
                        iter->err = 1;
                        break;
                }
@@ -484,6 +485,7 @@ static struct reftable_ref_iterator *ref_iterator_for_stack(struct reftable_ref_
        iter = xcalloc(1, sizeof(*iter));
        base_ref_iterator_init(&iter->base, &reftable_ref_iterator_vtable);
        iter->prefix = prefix;
+       iter->prefix_len = prefix ? strlen(prefix) : 0;
        iter->base.oid = &iter->oid;
        iter->flags = flags;
        iter->refs = refs;
@@ -781,6 +783,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
                                      &head_referent, &head_type);
        if (ret < 0)
                goto done;
+       ret = 0;
 
        for (i = 0; i < transaction->nr; i++) {
                struct ref_update *u = transaction->updates[i];
index 72eb73b3806d623010c0e224f4f8ce77d555ce43..ad9074dba6121e9e40265f73494b233d99fa74d4 100644 (file)
@@ -291,9 +291,8 @@ static int restart_key_less(size_t idx, void *args)
        /* the restart key is verbatim in the block, so this could avoid the
           alloc for decoding the key */
        struct strbuf rkey = STRBUF_INIT;
-       struct strbuf last_key = STRBUF_INIT;
        uint8_t unused_extra;
-       int n = reftable_decode_key(&rkey, &unused_extra, last_key, in);
+       int n = reftable_decode_key(&rkey, &unused_extra, in);
        int result;
        if (n < 0) {
                a->error = 1;
@@ -326,35 +325,34 @@ int block_iter_next(struct block_iter *it, struct reftable_record *rec)
        if (it->next_off >= it->br->block_len)
                return 1;
 
-       n = reftable_decode_key(&it->key, &extra, it->last_key, in);
+       n = reftable_decode_key(&it->last_key, &extra, in);
        if (n < 0)
                return -1;
-
-       if (!it->key.len)
+       if (!it->last_key.len)
                return REFTABLE_FORMAT_ERROR;
 
        string_view_consume(&in, n);
-       n = reftable_record_decode(rec, it->key, extra, in, it->br->hash_size);
+       n = reftable_record_decode(rec, it->last_key, extra, in, it->br->hash_size);
        if (n < 0)
                return -1;
        string_view_consume(&in, n);
 
-       strbuf_swap(&it->last_key, &it->key);
        it->next_off += start.len - in.len;
        return 0;
 }
 
 int block_reader_first_key(struct block_reader *br, struct strbuf *key)
 {
-       struct strbuf empty = STRBUF_INIT;
-       int off = br->header_off + 4;
+       int off = br->header_off + 4, n;
        struct string_view in = {
                .buf = br->block.data + off,
                .len = br->block_len - off,
        };
-
        uint8_t extra = 0;
-       int n = reftable_decode_key(key, &extra, empty, in);
+
+       strbuf_reset(key);
+
+       n = reftable_decode_key(key, &extra, in);
        if (n < 0)
                return n;
        if (!key->len)
@@ -371,7 +369,6 @@ int block_iter_seek(struct block_iter *it, struct strbuf *want)
 void block_iter_close(struct block_iter *it)
 {
        strbuf_release(&it->last_key);
-       strbuf_release(&it->key);
 }
 
 int block_reader_seek(struct block_reader *br, struct block_iter *it,
@@ -408,8 +405,8 @@ int block_reader_seek(struct block_reader *br, struct block_iter *it,
                if (err < 0)
                        goto done;
 
-               reftable_record_key(&rec, &it->key);
-               if (err > 0 || strbuf_cmp(&it->key, want) >= 0) {
+               reftable_record_key(&rec, &it->last_key);
+               if (err > 0 || strbuf_cmp(&it->last_key, want) >= 0) {
                        err = 0;
                        goto done;
                }
index 17481e6331979cc31972ee3dad576e9c594a1769..51699af233d823fafe681f3d7cbb20cf61b88d8a 100644 (file)
@@ -84,12 +84,10 @@ struct block_iter {
 
        /* key for last entry we read. */
        struct strbuf last_key;
-       struct strbuf key;
 };
 
 #define BLOCK_ITER_INIT { \
        .last_key = STRBUF_INIT, \
-       .key = STRBUF_INIT, \
 }
 
 /* initializes a block reader. */
index 8b5ebf6183a97f3ea16a0773880ccd3b835ef68e..7aa30c4a51e54ec5442b9d8a3bf90b8119c5a4f0 100644 (file)
@@ -16,11 +16,6 @@ https://developers.google.com/open-source/licenses/bsd
 #include "reader.h"
 #include "reftable-error.h"
 
-int iterator_is_null(struct reftable_iterator *it)
-{
-       return !it->ops;
-}
-
 static void filtering_ref_iterator_close(void *iter_arg)
 {
        struct filtering_ref_iterator *fri = iter_arg;
index 47d67d84df679c522ce50d1d7aade2d1be683b5a..537431baba075ad72614b1c68eff1fd28fa51288 100644 (file)
@@ -16,10 +16,6 @@ https://developers.google.com/open-source/licenses/bsd
 #include "reftable-iterator.h"
 #include "reftable-generic.h"
 
-/* Returns true for a zeroed out iterator, such as the one returned from
- * iterator_destroy. */
-int iterator_is_null(struct reftable_iterator *it);
-
 /* iterator that produces only ref records that point to `oid` */
 struct filtering_ref_iterator {
        int double_check;
index 1aa6cd31b74954da9b1b5140cd350459c37c1378..f85a24c6786c6fb8e102ffc9ceb35f23706c8c9b 100644 (file)
@@ -17,23 +17,37 @@ https://developers.google.com/open-source/licenses/bsd
 #include "reftable-error.h"
 #include "system.h"
 
+struct merged_subiter {
+       struct reftable_iterator iter;
+       struct reftable_record rec;
+};
+
+struct merged_iter {
+       struct merged_subiter *subiters;
+       struct merged_iter_pqueue pq;
+       uint32_t hash_id;
+       size_t stack_len;
+       uint8_t typ;
+       int suppress_deletions;
+       ssize_t advance_index;
+};
+
 static int merged_iter_init(struct merged_iter *mi)
 {
        for (size_t i = 0; i < mi->stack_len; i++) {
                struct pq_entry e = {
                        .index = i,
+                       .rec = &mi->subiters[i].rec,
                };
                int err;
 
-               reftable_record_init(&e.rec, mi->typ);
-               err = iterator_next(&mi->stack[i], &e.rec);
+               reftable_record_init(&mi->subiters[i].rec, mi->typ);
+               err = iterator_next(&mi->subiters[i].iter,
+                                   &mi->subiters[i].rec);
                if (err < 0)
                        return err;
-               if (err > 0) {
-                       reftable_iterator_destroy(&mi->stack[i]);
-                       reftable_record_release(&e.rec);
+               if (err > 0)
                        continue;
-               }
 
                merged_iter_pqueue_add(&mi->pq, &e);
        }
@@ -46,54 +60,66 @@ static void merged_iter_close(void *p)
        struct merged_iter *mi = p;
 
        merged_iter_pqueue_release(&mi->pq);
-       for (size_t i = 0; i < mi->stack_len; i++)
-               reftable_iterator_destroy(&mi->stack[i]);
-       reftable_free(mi->stack);
+       for (size_t i = 0; i < mi->stack_len; i++) {
+               reftable_iterator_destroy(&mi->subiters[i].iter);
+               reftable_record_release(&mi->subiters[i].rec);
+       }
+       reftable_free(mi->subiters);
 }
 
-static int merged_iter_advance_nonnull_subiter(struct merged_iter *mi,
-                                              size_t idx)
+static int merged_iter_advance_subiter(struct merged_iter *mi, size_t idx)
 {
        struct pq_entry e = {
                .index = idx,
+               .rec = &mi->subiters[idx].rec,
        };
        int err;
 
-       reftable_record_init(&e.rec, mi->typ);
-       err = iterator_next(&mi->stack[idx], &e.rec);
-       if (err < 0)
+       err = iterator_next(&mi->subiters[idx].iter, &mi->subiters[idx].rec);
+       if (err)
                return err;
 
-       if (err > 0) {
-               reftable_iterator_destroy(&mi->stack[idx]);
-               reftable_record_release(&e.rec);
-               return 0;
-       }
-
        merged_iter_pqueue_add(&mi->pq, &e);
        return 0;
 }
 
-static int merged_iter_advance_subiter(struct merged_iter *mi, size_t idx)
-{
-       if (iterator_is_null(&mi->stack[idx]))
-               return 0;
-       return merged_iter_advance_nonnull_subiter(mi, idx);
-}
-
 static int merged_iter_next_entry(struct merged_iter *mi,
                                  struct reftable_record *rec)
 {
        struct pq_entry entry = { 0 };
-       int err = 0;
+       int err = 0, empty;
+
+       empty = merged_iter_pqueue_is_empty(mi->pq);
+
+       if (mi->advance_index >= 0) {
+               /*
+                * When there are no pqueue entries then we only have a single
+                * subiter left. There is no need to use the pqueue in that
+                * case anymore as we know that the subiter will return entries
+                * in the correct order already.
+                *
+                * While this may sound like a very specific edge case, it may
+                * happen more frequently than you think. Most repositories
+                * will end up having a single large base table that contains
+                * most of the refs. It's thus likely that we exhaust all
+                * subiters but the one from that base ref.
+                */
+               if (empty)
+                       return iterator_next(&mi->subiters[mi->advance_index].iter,
+                                            rec);
+
+               err = merged_iter_advance_subiter(mi, mi->advance_index);
+               if (err < 0)
+                       return err;
+               if (!err)
+                       empty = 0;
+               mi->advance_index = -1;
+       }
 
-       if (merged_iter_pqueue_is_empty(mi->pq))
+       if (empty)
                return 1;
 
        entry = merged_iter_pqueue_remove(&mi->pq);
-       err = merged_iter_advance_subiter(mi, entry.index);
-       if (err < 0)
-               return err;
 
        /*
          One can also use reftable as datacenter-local storage, where the ref
@@ -107,56 +133,34 @@ static int merged_iter_next_entry(struct merged_iter *mi,
                struct pq_entry top = merged_iter_pqueue_top(mi->pq);
                int cmp;
 
-               /*
-                * When the next entry comes from the same queue as the current
-                * entry then it must by definition be larger. This avoids a
-                * comparison in the most common case.
-                */
-               if (top.index == entry.index)
-                       break;
-
-               cmp = reftable_record_cmp(&top.rec, &entry.rec);
+               cmp = reftable_record_cmp(top.rec, entry.rec);
                if (cmp > 0)
                        break;
 
                merged_iter_pqueue_remove(&mi->pq);
                err = merged_iter_advance_subiter(mi, top.index);
                if (err < 0)
-                       goto done;
-               reftable_record_release(&top.rec);
+                       return err;
        }
 
-       reftable_record_release(rec);
-       *rec = entry.rec;
-
-done:
-       if (err)
-               reftable_record_release(&entry.rec);
-       return err;
+       mi->advance_index = entry.index;
+       SWAP(*rec, *entry.rec);
+       return 0;
 }
 
-static int merged_iter_next(struct merged_iter *mi, struct reftable_record *rec)
+static int merged_iter_next_void(void *p, struct reftable_record *rec)
 {
+       struct merged_iter *mi = p;
        while (1) {
                int err = merged_iter_next_entry(mi, rec);
-               if (err == 0 && mi->suppress_deletions &&
-                   reftable_record_is_deletion(rec)) {
+               if (err)
+                       return err;
+               if (mi->suppress_deletions && reftable_record_is_deletion(rec))
                        continue;
-               }
-
-               return err;
+               return 0;
        }
 }
 
-static int merged_iter_next_void(void *p, struct reftable_record *rec)
-{
-       struct merged_iter *mi = p;
-       if (merged_iter_pqueue_is_empty(mi->pq))
-               return 1;
-
-       return merged_iter_next(mi, rec);
-}
-
 static struct reftable_iterator_vtable merged_iter_vtable = {
        .next = &merged_iter_next_void,
        .close = &merged_iter_close,
@@ -246,14 +250,15 @@ static int merged_table_seek_record(struct reftable_merged_table *mt,
                .typ = reftable_record_type(rec),
                .hash_id = mt->hash_id,
                .suppress_deletions = mt->suppress_deletions,
+               .advance_index = -1,
        };
        struct merged_iter *p;
        int err;
 
-       REFTABLE_CALLOC_ARRAY(merged.stack, mt->stack_len);
+       REFTABLE_CALLOC_ARRAY(merged.subiters, mt->stack_len);
        for (size_t i = 0; i < mt->stack_len; i++) {
                err = reftable_table_seek_record(&mt->stack[i],
-                                                &merged.stack[merged.stack_len], rec);
+                                                &merged.subiters[merged.stack_len].iter, rec);
                if (err < 0)
                        goto out;
                if (!err)
index 7d9f95d27ed0a44c4208e743b6b83ba4cdc5536c..a2571dbc99d68c9954e9d07372bae984cf5ccccc 100644 (file)
@@ -9,7 +9,7 @@ https://developers.google.com/open-source/licenses/bsd
 #ifndef MERGED_H
 #define MERGED_H
 
-#include "pq.h"
+#include "system.h"
 
 struct reftable_merged_table {
        struct reftable_table *stack;
@@ -24,15 +24,6 @@ struct reftable_merged_table {
        uint64_t max;
 };
 
-struct merged_iter {
-       struct reftable_iterator *stack;
-       uint32_t hash_id;
-       size_t stack_len;
-       uint8_t typ;
-       int suppress_deletions;
-       struct merged_iter_pqueue pq;
-};
-
 void merged_table_release(struct reftable_merged_table *mt);
 
 #endif
index e0ccce2b9779a8bfd1acac6d42bc7d0e46e3fe0e..7fb45d8c60dbca6106c51732005ce15c59d2c7e0 100644 (file)
@@ -14,22 +14,12 @@ https://developers.google.com/open-source/licenses/bsd
 
 int pq_less(struct pq_entry *a, struct pq_entry *b)
 {
-       int cmp = reftable_record_cmp(&a->rec, &b->rec);
+       int cmp = reftable_record_cmp(a->rec, b->rec);
        if (cmp == 0)
                return a->index > b->index;
        return cmp < 0;
 }
 
-struct pq_entry merged_iter_pqueue_top(struct merged_iter_pqueue pq)
-{
-       return pq.heap[0];
-}
-
-int merged_iter_pqueue_is_empty(struct merged_iter_pqueue pq)
-{
-       return pq.len == 0;
-}
-
 struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)
 {
        int i = 0;
@@ -82,10 +72,6 @@ void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry
 
 void merged_iter_pqueue_release(struct merged_iter_pqueue *pq)
 {
-       int i = 0;
-       for (i = 0; i < pq->len; i++) {
-               reftable_record_release(&pq->heap[i].rec);
-       }
        FREE_AND_NULL(pq->heap);
-       pq->len = pq->cap = 0;
+       memset(pq, 0, sizeof(*pq));
 }
index e85bac9b52e0039bd378cb1073215af4d48196c7..f796c2317948be2c82aaa15c29b5e9aba1730168 100644 (file)
@@ -12,8 +12,8 @@ https://developers.google.com/open-source/licenses/bsd
 #include "record.h"
 
 struct pq_entry {
-       int index;
-       struct reftable_record rec;
+       size_t index;
+       struct reftable_record *rec;
 };
 
 struct merged_iter_pqueue {
@@ -22,12 +22,20 @@ struct merged_iter_pqueue {
        size_t cap;
 };
 
-struct pq_entry merged_iter_pqueue_top(struct merged_iter_pqueue pq);
-int merged_iter_pqueue_is_empty(struct merged_iter_pqueue pq);
 void merged_iter_pqueue_check(struct merged_iter_pqueue pq);
 struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq);
 void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e);
 void merged_iter_pqueue_release(struct merged_iter_pqueue *pq);
 int pq_less(struct pq_entry *a, struct pq_entry *b);
 
+static inline struct pq_entry merged_iter_pqueue_top(struct merged_iter_pqueue pq)
+{
+       return pq.heap[0];
+}
+
+static inline int merged_iter_pqueue_is_empty(struct merged_iter_pqueue pq)
+{
+       return pq.len == 0;
+}
+
 #endif
index c202eff84801820b28c56ddb7de28a2d041f3c08..b7d3c80cc7260298749800696e4a8bcc5be3284c 100644 (file)
@@ -27,48 +27,43 @@ void merged_iter_pqueue_check(struct merged_iter_pqueue pq)
 
 static void test_pq(void)
 {
-       char *names[54] = { NULL };
-       int N = ARRAY_SIZE(names) - 1;
-
        struct merged_iter_pqueue pq = { NULL };
+       struct reftable_record recs[54];
+       int N = ARRAY_SIZE(recs) - 1, i;
        char *last = NULL;
 
-       int i = 0;
        for (i = 0; i < N; i++) {
-               char name[100];
-               snprintf(name, sizeof(name), "%02d", i);
-               names[i] = xstrdup(name);
+               struct strbuf refname = STRBUF_INIT;
+               strbuf_addf(&refname, "%02d", i);
+
+               reftable_record_init(&recs[i], BLOCK_TYPE_REF);
+               recs[i].u.ref.refname = strbuf_detach(&refname, NULL);
        }
 
        i = 1;
        do {
-               struct pq_entry e = { .rec = { .type = BLOCK_TYPE_REF,
-                                              .u.ref = {
-                                                      .refname = names[i],
-                                              } } };
+               struct pq_entry e = {
+                       .rec = &recs[i],
+               };
+
                merged_iter_pqueue_add(&pq, &e);
                merged_iter_pqueue_check(pq);
+
                i = (i * 7) % N;
        } while (i != 1);
 
        while (!merged_iter_pqueue_is_empty(pq)) {
                struct pq_entry e = merged_iter_pqueue_remove(&pq);
-               struct reftable_record *rec = &e.rec;
                merged_iter_pqueue_check(pq);
 
-               EXPECT(reftable_record_type(rec) == BLOCK_TYPE_REF);
-               if (last) {
-                       EXPECT(strcmp(last, rec->u.ref.refname) < 0);
-               }
-               /* this is names[i], so don't dealloc. */
-               last = rec->u.ref.refname;
-               rec->u.ref.refname = NULL;
-               reftable_record_release(rec);
-       }
-       for (i = 0; i < N; i++) {
-               reftable_free(names[i]);
+               EXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF);
+               if (last)
+                       EXPECT(strcmp(last, e.rec->u.ref.refname) < 0);
+               last = e.rec->u.ref.refname;
        }
 
+       for (i = 0; i < N; i++)
+               reftable_record_release(&recs[i]);
        merged_iter_pqueue_release(&pq);
 }
 
index d6bb42e887423d95f2fcc1b2b146505ab4bef62a..367de046006b25b497eb82fb35281e98733f609e 100644 (file)
@@ -159,20 +159,19 @@ int reftable_encode_key(int *restart, struct string_view dest,
        return start.len - dest.len;
 }
 
-int reftable_decode_key(struct strbuf *key, uint8_t *extra,
-                       struct strbuf last_key, struct string_view in)
+int reftable_decode_key(struct strbuf *last_key, uint8_t *extra,
+                       struct string_view in)
 {
        int start_len = in.len;
        uint64_t prefix_len = 0;
        uint64_t suffix_len = 0;
-       int n = get_var_int(&prefix_len, &in);
+       int n;
+
+       n = get_var_int(&prefix_len, &in);
        if (n < 0)
                return -1;
        string_view_consume(&in, n);
 
-       if (prefix_len > last_key.len)
-               return -1;
-
        n = get_var_int(&suffix_len, &in);
        if (n <= 0)
                return -1;
@@ -181,12 +180,12 @@ int reftable_decode_key(struct strbuf *key, uint8_t *extra,
        *extra = (uint8_t)(suffix_len & 0x7);
        suffix_len >>= 3;
 
-       if (in.len < suffix_len)
+       if (in.len < suffix_len ||
+           prefix_len > last_key->len)
                return -1;
 
-       strbuf_reset(key);
-       strbuf_add(key, last_key.buf, prefix_len);
-       strbuf_add(key, in.buf, suffix_len);
+       strbuf_setlen(last_key, prefix_len);
+       strbuf_add(last_key, in.buf, suffix_len);
        string_view_consume(&in, suffix_len);
 
        return start_len - in.len;
@@ -205,14 +204,26 @@ static void reftable_ref_record_copy_from(void *rec, const void *src_rec,
 {
        struct reftable_ref_record *ref = rec;
        const struct reftable_ref_record *src = src_rec;
+       char *refname = NULL;
+       size_t refname_cap = 0;
+
        assert(hash_size > 0);
 
-       /* This is simple and correct, but we could probably reuse the hash
-        * fields. */
+       SWAP(refname, ref->refname);
+       SWAP(refname_cap, ref->refname_cap);
        reftable_ref_record_release(ref);
+       SWAP(ref->refname, refname);
+       SWAP(ref->refname_cap, refname_cap);
+
        if (src->refname) {
-               ref->refname = xstrdup(src->refname);
+               size_t refname_len = strlen(src->refname);
+
+               REFTABLE_ALLOC_GROW(ref->refname, refname_len + 1,
+                                   ref->refname_cap);
+               memcpy(ref->refname, src->refname, refname_len);
+               ref->refname[refname_len] = 0;
        }
+
        ref->update_index = src->update_index;
        ref->value_type = src->value_type;
        switch (src->value_type) {
@@ -368,16 +379,24 @@ static int reftable_ref_record_decode(void *rec, struct strbuf key,
        struct reftable_ref_record *r = rec;
        struct string_view start = in;
        uint64_t update_index = 0;
-       int n = get_var_int(&update_index, &in);
+       const char *refname = NULL;
+       size_t refname_cap = 0;
+       int n;
+
+       assert(hash_size > 0);
+
+       n = get_var_int(&update_index, &in);
        if (n < 0)
                return n;
        string_view_consume(&in, n);
 
+       SWAP(refname, r->refname);
+       SWAP(refname_cap, r->refname_cap);
        reftable_ref_record_release(r);
+       SWAP(r->refname, refname);
+       SWAP(r->refname_cap, refname_cap);
 
-       assert(hash_size > 0);
-
-       r->refname = reftable_malloc(key.len + 1);
+       REFTABLE_ALLOC_GROW(r->refname, key.len + 1, r->refname_cap);
        memcpy(r->refname, key.buf, key.len);
        r->refname[key.len] = 0;
 
@@ -1157,11 +1176,6 @@ void reftable_record_key(struct reftable_record *rec, struct strbuf *dest)
        reftable_record_vtable(rec)->key(reftable_record_data(rec), dest);
 }
 
-uint8_t reftable_record_type(struct reftable_record *rec)
-{
-       return rec->type;
-}
-
 int reftable_record_encode(struct reftable_record *rec, struct string_view dest,
                           int hash_size)
 {
@@ -1283,12 +1297,6 @@ int reftable_log_record_is_deletion(const struct reftable_log_record *log)
        return (log->value_type == REFTABLE_LOG_DELETION);
 }
 
-void string_view_consume(struct string_view *s, int n)
-{
-       s->buf += n;
-       s->len -= n;
-}
-
 static void *reftable_record_data(struct reftable_record *rec)
 {
        switch (rec->type) {
index a05e2be17971d5e26f27871159cda293aa2640ad..5e8304e05284c7bbc2f5b2940904023ae032f15a 100644 (file)
@@ -25,7 +25,11 @@ struct string_view {
 };
 
 /* Advance `s.buf` by `n`, and decrease length. */
-void string_view_consume(struct string_view *s, int n);
+static inline void string_view_consume(struct string_view *s, int n)
+{
+       s->buf += n;
+       s->len -= n;
+}
 
 /* utilities for de/encoding varints */
 
@@ -81,9 +85,12 @@ int reftable_encode_key(int *is_restart, struct string_view dest,
                        struct strbuf prev_key, struct strbuf key,
                        uint8_t extra);
 
-/* Decode into `key` and `extra` from `in` */
-int reftable_decode_key(struct strbuf *key, uint8_t *extra,
-                       struct strbuf last_key, struct string_view in);
+/*
+ * Decode into `last_key` and `extra` from `in`. `last_key` is expected to
+ * contain the decoded key of the preceding record, if any.
+ */
+int reftable_decode_key(struct strbuf *last_key, uint8_t *extra,
+                       struct string_view in);
 
 /* reftable_index_record are used internally to speed up lookups. */
 struct reftable_index_record {
@@ -124,7 +131,6 @@ int reftable_record_cmp(struct reftable_record *a, struct reftable_record *b);
 int reftable_record_equal(struct reftable_record *a, struct reftable_record *b, int hash_size);
 void reftable_record_print(struct reftable_record *rec, int hash_size);
 void reftable_record_key(struct reftable_record *rec, struct strbuf *dest);
-uint8_t reftable_record_type(struct reftable_record *rec);
 void reftable_record_copy_from(struct reftable_record *rec,
                               struct reftable_record *src, int hash_size);
 uint8_t reftable_record_val_type(struct reftable_record *rec);
@@ -135,6 +141,11 @@ int reftable_record_decode(struct reftable_record *rec, struct strbuf key,
                           int hash_size);
 int reftable_record_is_deletion(struct reftable_record *rec);
 
+static inline uint8_t reftable_record_type(struct reftable_record *rec)
+{
+       return rec->type;
+}
+
 /* frees and zeroes out the embedded record */
 void reftable_record_release(struct reftable_record *rec);
 
index a86cff552661ba0f00be32200bf8b0c800a9fa87..89209894d84395ce9ae476ba461fea04100c05a6 100644 (file)
@@ -295,7 +295,8 @@ static void test_key_roundtrip(void)
        EXPECT(!restart);
        EXPECT(n > 0);
 
-       m = reftable_decode_key(&roundtrip, &rt_extra, last_key, dest);
+       strbuf_addstr(&roundtrip, "refs/heads/master");
+       m = reftable_decode_key(&roundtrip, &rt_extra, dest);
        EXPECT(n == m);
        EXPECT(0 == strbuf_cmp(&key, &roundtrip));
        EXPECT(rt_extra == extra);
index bb6e99acd3151ec75a7a2dc60e930064b7322e60..e657001d42fc9e640052092c59db17121e60cf12 100644 (file)
@@ -22,6 +22,7 @@ https://developers.google.com/open-source/licenses/bsd
 /* reftable_ref_record holds a ref database entry target_value */
 struct reftable_ref_record {
        char *refname; /* Name of the ref, malloced. */
+       size_t refname_cap;
        uint64_t update_index; /* Logical timestamp at which this value is
                                * written */
 
index 9090632e96daddfc1217bc64ae4e0dac11bdb993..2b650b813b741f722a5f6c69f359a1f53249bcb1 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -2679,7 +2679,7 @@ static int is_reachable_in_reflog(const char *local, const struct ref *remote)
                if (MERGE_BASES_BATCH_SIZE < size)
                        size = MERGE_BASES_BATCH_SIZE;
 
-               if ((ret = repo_in_merge_bases_many(the_repository, commit, size, chunk)))
+               if ((ret = repo_in_merge_bases_many(the_repository, commit, size, chunk, 0)))
                        break;
        }
 
diff --git a/reset.c b/reset.c
index 0f2ff0fe31531fc5602025cfcd866a9348cfcf63..d619cb7115323febadbf4ae84e6764200f962cab 100644 (file)
--- a/reset.c
+++ b/reset.c
@@ -157,6 +157,11 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts)
        }
 
        tree = parse_tree_indirect(oid);
+       if (!tree) {
+               ret = error(_("unable to read tree (%s)"), oid_to_hex(oid));
+               goto leave_reset_head;
+       }
+
        prime_cache_tree(r, r->index, tree);
 
        if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) {
index ac45c6d8f29639dbb5cdd759f5339726a7d4dfe5..d6436ee66b146f63e4aabf16377491d470583328 100644 (file)
@@ -381,13 +381,18 @@ static struct object *get_reference(struct rev_info *revs, const char *name,
 
        object = parse_object_with_flags(revs->repo, oid,
                                         revs->verify_objects ? 0 :
-                                        PARSE_OBJECT_SKIP_HASH_CHECK);
+                                        PARSE_OBJECT_SKIP_HASH_CHECK |
+                                        PARSE_OBJECT_DISCARD_TREE);
 
        if (!object) {
                if (revs->ignore_missing)
-                       return object;
+                       return NULL;
                if (revs->exclude_promisor_objects && is_promisor_object(oid))
                        return NULL;
+               if (revs->do_not_die_on_missing_objects) {
+                       oidset_insert(&revs->missing_commits, oid);
+                       return NULL;
+               }
                die("bad object %s", name);
        }
        object->flags |= flags;
@@ -415,15 +420,21 @@ static struct commit *handle_commit(struct rev_info *revs,
         */
        while (object->type == OBJ_TAG) {
                struct tag *tag = (struct tag *) object;
+               struct object_id *oid;
                if (revs->tag_objects && !(flags & UNINTERESTING))
                        add_pending_object(revs, object, tag->tag);
-               object = parse_object(revs->repo, get_tagged_oid(tag));
+               oid = get_tagged_oid(tag);
+               object = parse_object(revs->repo, oid);
                if (!object) {
                        if (revs->ignore_missing_links || (flags & UNINTERESTING))
                                return NULL;
                        if (revs->exclude_promisor_objects &&
                            is_promisor_object(&tag->tagged->oid))
                                return NULL;
+                       if (revs->do_not_die_on_missing_objects && oid) {
+                               oidset_insert(&revs->missing_commits, oid);
+                               return NULL;
+                       }
                        die("bad object %s", oid_to_hex(&tag->tagged->oid));
                }
                object->flags |= flags;
@@ -1945,6 +1956,7 @@ void repo_init_revisions(struct repository *r,
        init_display_notes(&revs->notes_opt);
        list_objects_filter_init(&revs->filter);
        init_ref_exclusions(&revs->ref_excludes);
+       oidset_init(&revs->missing_commits, 0);
 }
 
 static void add_pending_commit_list(struct rev_info *revs,
@@ -1959,11 +1971,31 @@ static void add_pending_commit_list(struct rev_info *revs,
        }
 }
 
+static const char *lookup_other_head(struct object_id *oid)
+{
+       int i;
+       static const char *const other_head[] = {
+               "MERGE_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD", "REBASE_HEAD"
+       };
+
+       for (i = 0; i < ARRAY_SIZE(other_head); i++)
+               if (!read_ref_full(other_head[i],
+                               RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
+                               oid, NULL)) {
+                       if (is_null_oid(oid))
+                               die(_("%s exists but is a symbolic ref"), other_head[i]);
+                       return other_head[i];
+               }
+
+       die(_("--merge requires one of the pseudorefs MERGE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD or REBASE_HEAD"));
+}
+
 static void prepare_show_merge(struct rev_info *revs)
 {
-       struct commit_list *bases;
+       struct commit_list *bases = NULL;
        struct commit *head, *other;
        struct object_id oid;
+       const char *other_name;
        const char **prune = NULL;
        int i, prune_num = 1; /* counting terminating NULL */
        struct index_state *istate = revs->repo->index;
@@ -1971,12 +2003,12 @@ static void prepare_show_merge(struct rev_info *revs)
        if (repo_get_oid(the_repository, "HEAD", &oid))
                die("--merge without HEAD?");
        head = lookup_commit_or_die(&oid, "HEAD");
-       if (repo_get_oid(the_repository, "MERGE_HEAD", &oid))
-               die("--merge without MERGE_HEAD?");
-       other = lookup_commit_or_die(&oid, "MERGE_HEAD");
+       other_name = lookup_other_head(&oid);
+       other = lookup_commit_or_die(&oid, other_name);
        add_pending_object(revs, &head->object, "HEAD");
-       add_pending_object(revs, &other->object, "MERGE_HEAD");
-       bases = repo_get_merge_bases(the_repository, head, other);
+       add_pending_object(revs, &other->object, other_name);
+       if (repo_get_merge_bases(the_repository, head, other, &bases) < 0)
+               exit(128);
        add_rev_cmdline_list(revs, bases, REV_CMD_MERGE_BASE, UNINTERESTING | BOTTOM);
        add_pending_commit_list(revs, bases, UNINTERESTING | BOTTOM);
        free_commit_list(bases);
@@ -2064,14 +2096,17 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
        } else {
                /* A...B -- find merge bases between the two */
                struct commit *a, *b;
-               struct commit_list *exclude;
+               struct commit_list *exclude = NULL;
 
                a = lookup_commit_reference(revs->repo, &a_obj->oid);
                b = lookup_commit_reference(revs->repo, &b_obj->oid);
                if (!a || !b)
                        return dotdot_missing(arg, dotdot, revs, symmetric);
 
-               exclude = repo_get_merge_bases(the_repository, a, b);
+               if (repo_get_merge_bases(the_repository, a, b, &exclude) < 0) {
+                       free_commit_list(exclude);
+                       return -1;
+               }
                add_rev_cmdline_list(revs, exclude, REV_CMD_MERGE_BASE,
                                     flags_exclude);
                add_pending_commit_list(revs, exclude, flags_exclude);
@@ -2176,13 +2211,18 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl
        if (revarg_opt & REVARG_COMMITTISH)
                get_sha1_flags |= GET_OID_COMMITTISH;
 
+       /*
+        * Even if revs->do_not_die_on_missing_objects is set, we
+        * should error out if we can't even get an oid, as
+        * `--missing=print` should be able to report missing oids.
+        */
        if (get_oid_with_context(revs->repo, arg, get_sha1_flags, &oid, &oc))
                return revs->ignore_missing ? 0 : -1;
        if (!cant_be_filename)
                verify_non_filename(revs->prefix, arg);
        object = get_reference(revs, arg, &oid, flags ^ local_flags);
        if (!object)
-               return revs->ignore_missing ? 0 : -1;
+               return (revs->ignore_missing || revs->do_not_die_on_missing_objects) ? 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);
@@ -2318,7 +2358,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
        } else if (skip_prefix(arg, "--ancestry-path=", &optarg)) {
                struct commit *c;
                struct object_id oid;
-               const char *msg = _("could not get commit for ancestry-path argument %s");
+               const char *msg = _("could not get commit for --ancestry-path argument %s");
 
                revs->ancestry_path = 1;
                revs->simplify_history = 0;
@@ -3828,8 +3868,6 @@ int prepare_revision_walk(struct rev_info *revs)
                                       FOR_EACH_OBJECT_PROMISOR_ONLY);
        }
 
-       oidset_init(&revs->missing_commits, 0);
-
        if (!revs->reflog_info)
                prepare_to_use_bloom_filter(revs);
        if (!revs->unsorted_input)
index f49a871ac0666b10393331ed3c9b611921f1039e..ea1441e617400717458a805b1c27766e27ea7a34 100644 (file)
@@ -332,7 +332,7 @@ static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
                sb->buf[sb->len - ignore_footer] = '\0';
        }
 
-       trailer_info_get(&info, sb->buf, &opts);
+       trailer_info_get(&opts, sb->buf, &info);
 
        if (ignore_footer)
                sb->buf[sb->len - ignore_footer] = saved_char;
@@ -707,6 +707,8 @@ static int do_recursive_merge(struct repository *r,
        o.show_rename_progress = 1;
 
        head_tree = parse_tree_indirect(head);
+       if (!head_tree)
+               return error(_("unable to read tree (%s)"), oid_to_hex(head));
        next_tree = next ? repo_get_commit_tree(r, next) : empty_tree(r);
        base_tree = base ? repo_get_commit_tree(r, base) : empty_tree(r);
 
@@ -3882,6 +3884,8 @@ static int do_reset(struct repository *r,
        }
 
        tree = parse_tree_indirect(&oid);
+       if (!tree)
+               return error(_("unable to read tree (%s)"), oid_to_hex(&oid));
        prime_cache_tree(r, r->index, tree);
 
        if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0)
@@ -3908,7 +3912,7 @@ static int do_merge(struct repository *r,
        int run_commit_flags = 0;
        struct strbuf ref_name = STRBUF_INIT;
        struct commit *head_commit, *merge_commit, *i;
-       struct commit_list *bases, *j;
+       struct commit_list *bases = NULL, *j;
        struct commit_list *to_merge = NULL, **tail = &to_merge;
        const char *strategy = !opts->xopts.nr &&
                (!opts->strategy ||
@@ -4134,7 +4138,11 @@ static int do_merge(struct repository *r,
        }
 
        merge_commit = to_merge->item;
-       bases = repo_get_merge_bases(r, head_commit, merge_commit);
+       if (repo_get_merge_bases(r, head_commit, merge_commit, &bases) < 0) {
+               ret = -1;
+               goto leave_merge;
+       }
+
        if (bases && oideq(&merge_commit->object.oid,
                           &bases->item->object.oid)) {
                ret = 0;
diff --git a/serve.c b/serve.c
index a1d71134d49cc88ead5af690315b27ae23215e56..aa651b73e9b7a3378c51f7c92533a6dd0f82ce73 100644 (file)
--- a/serve.c
+++ b/serve.c
@@ -12,6 +12,7 @@
 #include "trace2.h"
 
 static int advertise_sid = -1;
+static int advertise_object_info = -1;
 static int client_hash_algo = GIT_HASH_SHA1;
 
 static int always_advertise(struct repository *r UNUSED,
@@ -67,6 +68,17 @@ static void session_id_receive(struct repository *r UNUSED,
        trace2_data_string("transfer", NULL, "client-sid", client_sid);
 }
 
+static int object_info_advertise(struct repository *r, struct strbuf *value UNUSED)
+{
+       if (advertise_object_info == -1 &&
+           repo_config_get_bool(r, "transfer.advertiseobjectinfo",
+                                &advertise_object_info)) {
+               /* disabled by default */
+               advertise_object_info = 0;
+       }
+       return advertise_object_info;
+}
+
 struct protocol_capability {
        /*
         * The name of the capability.  The server uses this name when
@@ -135,7 +147,7 @@ static struct protocol_capability capabilities[] = {
        },
        {
                .name = "object-info",
-               .advertise = always_advertise,
+               .advertise = object_info_advertise,
                .command = cap_object_info,
        },
        {
diff --git a/setup.c b/setup.c
index b69b1cbc2adb41aa5f4df8b1aff88761ea2cba5c..b2d9371ddc229f9999121f12d8cd9096a8d554d6 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -1889,6 +1889,13 @@ void initialize_repository_version(int hash_algo,
        char repo_version_string[10];
        int repo_version = GIT_REPO_VERSION;
 
+       /*
+        * Note that we initialize the repository version to 1 when the ref
+        * storage format is unknown. This is on purpose so that we can add the
+        * correct object format to the config during git-clone(1). The format
+        * version will get adjusted by git-clone(1) once it has learned about
+        * the remote repository's format.
+        */
        if (hash_algo != GIT_HASH_SHA1 ||
            ref_storage_format != REF_STORAGE_FORMAT_FILES)
                repo_version = GIT_REPO_VERSION_READ;
@@ -1898,7 +1905,7 @@ void initialize_repository_version(int hash_algo,
                  "%d", repo_version);
        git_config_set("core.repositoryformatversion", repo_version_string);
 
-       if (hash_algo != GIT_HASH_SHA1)
+       if (hash_algo != GIT_HASH_SHA1 && hash_algo != GIT_HASH_UNKNOWN)
                git_config_set("extensions.objectformat",
                               hash_algos[hash_algo].name);
        else if (reinit)
@@ -1961,7 +1968,6 @@ void create_reference_database(unsigned int ref_storage_format,
 static int create_default_files(const char *template_path,
                                const char *original_git_dir,
                                const struct repository_format *fmt,
-                               int prev_bare_repository,
                                int init_shared_repository)
 {
        struct stat st1;
@@ -1996,34 +2002,8 @@ static int create_default_files(const char *template_path,
         */
        if (init_shared_repository != -1)
                set_shared_repository(init_shared_repository);
-       /*
-        * TODO: heed core.bare from config file in templates if no
-        *       command-line override given
-        */
-       is_bare_repository_cfg = prev_bare_repository || !work_tree;
-       /* TODO (continued):
-        *
-        * Unfortunately, the line above is equivalent to
-        *    is_bare_repository_cfg = !work_tree;
-        * which ignores the config entirely even if no `--[no-]bare`
-        * command line option was present.
-        *
-        * To see why, note that before this function, there was this call:
-        *    prev_bare_repository = is_bare_repository()
-        * expanding the right hand side:
-        *                 = is_bare_repository_cfg && !get_git_work_tree()
-        *                 = is_bare_repository_cfg && !work_tree
-        * note that the last simplification above is valid because nothing
-        * calls repo_init() or set_git_work_tree() between any of the
-        * relevant calls in the code, and thus the !get_git_work_tree()
-        * calls will return the same result each time.  So, what we are
-        * interested in computing is the right hand side of the line of
-        * code just above this comment:
-        *     prev_bare_repository || !work_tree
-        *        = is_bare_repository_cfg && !work_tree || !work_tree
-        *        = !work_tree
-        * because "A && !B || !B == !B" for all boolean values of A & B.
-        */
+
+       is_bare_repository_cfg = !work_tree;
 
        /*
         * We would have created the above under user's umask -- under
@@ -2175,7 +2155,6 @@ int init_db(const char *git_dir, const char *real_git_dir,
        int exist_ok = flags & INIT_DB_EXIST_OK;
        char *original_git_dir = real_pathdup(git_dir, 1);
        struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
-       int prev_bare_repository;
 
        if (real_git_dir) {
                struct stat st;
@@ -2201,7 +2180,6 @@ int init_db(const char *git_dir, const char *real_git_dir,
 
        safe_create_dir(git_dir, 0);
 
-       prev_bare_repository = is_bare_repository();
 
        /* Check to see if the repository version is right.
         * Note that a newly created repository does not have
@@ -2214,8 +2192,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
        validate_ref_storage_format(&repo_fmt, ref_storage_format);
 
        reinit = create_default_files(template_dir, original_git_dir,
-                                     &repo_fmt, prev_bare_repository,
-                                     init_shared_repository);
+                                     &repo_fmt, init_shared_repository);
 
        /*
         * Now that we have set up both the hash algorithm and the ref storage
index 7711798127e49efaa18b6403ecf103f05e92f7e7..7ff50dd0da45e00ac3de5e03af473ff361d33b02 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -794,12 +794,16 @@ static void post_assign_shallow(struct shallow_info *info,
                if (!*bitmap)
                        continue;
                for (j = 0; j < bitmap_nr; j++)
-                       if (bitmap[0][j] &&
-                           /* Step 7, reachability test at commit level */
-                           !repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits)) {
-                               update_refstatus(ref_status, info->ref->nr, *bitmap);
-                               dst++;
-                               break;
+                       if (bitmap[0][j]) {
+                               /* Step 7, reachability test at commit level */
+                               int ret = repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits, 1);
+                               if (ret < 0)
+                                       exit(128);
+                               if (!ret) {
+                                       update_refstatus(ref_status, info->ref->nr, *bitmap);
+                                       dst++;
+                                       break;
+                               }
                        }
        }
        info->nr_ours = dst;
@@ -827,7 +831,10 @@ int delayed_reachability_test(struct shallow_info *si, int c)
                si->reachable[c] = repo_in_merge_bases_many(the_repository,
                                                            commit,
                                                            si->nr_commits,
-                                                           si->commits);
+                                                           si->commits,
+                                                           1);
+               if (si->reachable[c] < 0)
+                       exit(128);
                si->need_reachability_test[c] = 0;
        }
        return si->reachable[c];
index 266a67342be7245ae3c1dfae5a1a5ad6647f95df..5d8907151fec3982e906025fc19c2165ef4572d3 100644 (file)
@@ -220,7 +220,7 @@ int demultiplex_sideband(const char *me, int status,
                        }
 
                        strbuf_addch(scratch, *brk);
-                       xwrite(2, scratch->buf, scratch->len);
+                       write_in_full(2, scratch->buf, scratch->len);
                        strbuf_reset(scratch);
 
                        b = brk + 1;
@@ -247,7 +247,7 @@ cleanup:
                die("%s", scratch->buf);
        if (scratch->len) {
                strbuf_addch(scratch, '\n');
-               xwrite(2, scratch->buf, scratch->len);
+               write_in_full(2, scratch->buf, scratch->len);
        }
        strbuf_release(scratch);
        return 1;
index 40f13a36857179c39d31891396c892c5b7e54f72..f0ddb31e8fb535264dded9fb0a7434fda1330f39 100644 (file)
@@ -592,7 +592,12 @@ static void show_submodule_header(struct diff_options *o,
             (!is_null_oid(two) && !*right))
                message = "(commits not present)";
 
-       *merge_bases = repo_get_merge_bases(sub, *left, *right);
+       *merge_bases = NULL;
+       if (repo_get_merge_bases(sub, *left, *right, merge_bases) < 0) {
+               message = "(corrupt repository)";
+               goto output_header;
+       }
+
        if (*merge_bases) {
                if ((*merge_bases)->item == *left)
                        fast_forward = 1;
index 1e159a754db6db5d02eaa81072b0ab19fa863004..1e3b431e3e72116df65e825bed1916d5ff7859e6 100644 (file)
@@ -111,13 +111,16 @@ int cmd__reach(int ac, const char **av)
                       repo_in_merge_bases(the_repository, A, B));
        else if (!strcmp(av[1], "in_merge_bases_many"))
                printf("%s(A,X):%d\n", av[1],
-                      repo_in_merge_bases_many(the_repository, A, X_nr, X_array));
+                      repo_in_merge_bases_many(the_repository, A, X_nr, X_array, 0));
        else if (!strcmp(av[1], "is_descendant_of"))
                printf("%s(A,X):%d\n", av[1], repo_is_descendant_of(r, A, X));
        else if (!strcmp(av[1], "get_merge_bases_many")) {
-               struct commit_list *list = repo_get_merge_bases_many(the_repository,
-                                                                    A, X_nr,
-                                                                    X_array);
+               struct commit_list *list = NULL;
+               if (repo_get_merge_bases_many(the_repository,
+                                             A, X_nr,
+                                             X_array,
+                                             &list) < 0)
+                       exit(128);
                printf("%s(A,X):\n", av[1]);
                print_sorted_commit_ids(list);
        } else if (!strcmp(av[1], "reduce_heads")) {
index 837c8b7228b98e8e7b3dbfecd5046673554ef464..84172a3739094adc6cdf6496b016fe68e0b2a771 100755 (executable)
@@ -10,25 +10,24 @@ TEST_PASSES_SANITIZE_LEAK=true
 
 for trial in 0 1 2 3 4
 do
-       rm -f .git/index
-       echo frotz >infocom
-       git update-index --add infocom
-       echo xyzzy >infocom
-
-       files=$(git diff-files -p)
-       test_expect_success \
-       "Racy GIT trial #$trial part A" \
-       'test "" != "$files"'
-
+       test_expect_success "Racy git trial #$trial part A" '
+               rm -f .git/index &&
+               echo frotz >infocom &&
+               git update-index --add infocom &&
+               echo xyzzy >infocom &&
+
+               git diff-files -p >out &&
+               test_file_not_empty out
+       '
        sleep 1
-       echo xyzzy >cornerstone
-       git update-index --add cornerstone
 
-       files=$(git diff-files -p)
-       test_expect_success \
-       "Racy GIT trial #$trial part B" \
-       'test "" != "$files"'
+       test_expect_success "Racy git trial #$trial part B" '
+               echo xyzzy >cornerstone &&
+               git update-index --add cornerstone &&
 
+               git diff-files -p >out &&
+               test_file_not_empty out
+       '
 done
 
 test_done
index 0f98b21be8d132d9595d54b364c2e5d4aa81dca2..88a66f09040ce0aa2a3a653579d6c3685e750ba1 100755 (executable)
@@ -665,6 +665,21 @@ test_expect_success 'lazy-fetch when accessing object not in the_repository' '
        git -C partial.git rev-list --objects --missing=print HEAD >out &&
        grep "[?]$FILE_HASH" out &&
 
+       # The no-lazy-fetch mechanism prevents Git from fetching
+       test_must_fail env GIT_NO_LAZY_FETCH=1 \
+               git -C partial.git cat-file -e "$FILE_HASH" &&
+
+       # The same with command line option to "git"
+       test_must_fail git --no-lazy-fetch -C partial.git cat-file -e "$FILE_HASH" &&
+
+       # The same, forcing a subprocess via an alias
+       test_must_fail git --no-lazy-fetch -C partial.git \
+               -c alias.foo="!git cat-file" foo -e "$FILE_HASH" &&
+
+       # Sanity check that the file is still missing
+       git -C partial.git rev-list --objects --missing=print HEAD >out &&
+       grep "[?]$FILE_HASH" out &&
+
        git -C full cat-file -s "$FILE_HASH" >expect &&
        test-tool partial-clone object-info partial.git "$FILE_HASH" >actual &&
        test_cmp expect actual &&
index 6a131e40b8157dc3fefea53704ad2377b7ce5c3a..686781192eb7c2d820e28393b6d0352db3f4822e 100755 (executable)
@@ -328,6 +328,18 @@ test_expect_success 'ref transaction: writes are synced' '
        EOF
 '
 
+test_expect_success 'ref transaction: empty transaction in empty repo' '
+       test_when_finished "rm -rf repo" &&
+       git init repo &&
+       test_commit -C repo --no-tag A &&
+       git -C repo update-ref -d refs/heads/main &&
+       test-tool -C repo ref-store main delete-refs REF_NO_DEREF msg HEAD &&
+       git -C repo update-ref --stdin <<-EOF
+       prepare
+       commit
+       EOF
+'
+
 test_expect_success 'pack-refs: compacts tables' '
        test_when_finished "rm -rf repo" &&
        git init repo &&
index b1eb5c01b899daf9a0075393e3e79d47da069d5d..29cf8a966133a7851722c8cdf828fe3c524a12ec 100755 (executable)
@@ -52,7 +52,7 @@ test_expect_success 'shared=all' '
        test 2 = $(git config core.sharedrepository)
 '
 
-test_expect_failure 'template can set core.bare' '
+test_expect_success 'template cannot set core.bare' '
        test_when_finished "rm -rf subdir" &&
        test_when_finished "rm -rf templates" &&
        test_config core.bare true &&
@@ -60,18 +60,7 @@ test_expect_failure 'template can set core.bare' '
        mkdir -p templates/ &&
        cp .git/config templates/config &&
        git init --template=templates subdir &&
-       test_path_exists subdir/HEAD
-'
-
-test_expect_success 'template can set core.bare but overridden by command line' '
-       test_when_finished "rm -rf subdir" &&
-       test_when_finished "rm -rf templates" &&
-       test_config core.bare true &&
-       umask 0022 &&
-       mkdir -p templates/ &&
-       cp .git/config templates/config &&
-       git init --no-bare --template=templates subdir &&
-       test_path_exists subdir/.git/HEAD
+       test_path_is_missing subdir/HEAD
 '
 
 test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '
index e36f4d15f2ddd4f64d6aaf8e087370c3b9f92ce5..33aba87b9a4db314880a640b7ae65d7ba9c76a06 100755 (executable)
@@ -75,13 +75,13 @@ test_expect_success 'git branch HEAD should fail' '
        test_must_fail git branch HEAD
 '
 
-cat >expect <<EOF
-$HEAD refs/heads/d/e/f@{0}: branch: Created from main
-EOF
 test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
        GIT_COMMITTER_DATE="2005-05-26 23:30" \
        git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
        test_ref_exists refs/heads/d/e/f &&
+       cat >expect <<-EOF &&
+       $HEAD refs/heads/d/e/f@{0}: branch: Created from main
+       EOF
        git reflog show --no-abbrev-commit refs/heads/d/e/f >actual &&
        test_cmp expect actual
 '
@@ -440,10 +440,10 @@ test_expect_success 'git branch --list -v with --abbrev' '
 
 test_expect_success 'git branch --column' '
        COLUMNS=81 git branch --column=column >actual &&
-       cat >expect <<\EOF &&
-  a/b/c   bam     foo     l     * main    n       o/p     r
-  abc     bar     j/k     m/m     mb      o/o     q       topic
-EOF
+       cat >expect <<-\EOF &&
+         a/b/c   bam     foo     l     * main    n       o/p     r
+         abc     bar     j/k     m/m     mb      o/o     q       topic
+       EOF
        test_cmp expect actual
 '
 
@@ -453,25 +453,25 @@ test_expect_success 'git branch --column with an extremely long branch name' '
        test_when_finished "git branch -d $long" &&
        git branch $long &&
        COLUMNS=80 git branch --column=column >actual &&
-       cat >expect <<EOF &&
-  a/b/c
-  abc
-  bam
-  bar
-  foo
-  j/k
-  l
-  m/m
-* main
-  mb
-  n
-  o/o
-  o/p
-  q
-  r
-  topic
-  $long
-EOF
+       cat >expect <<-EOF &&
+         a/b/c
+         abc
+         bam
+         bar
+         foo
+         j/k
+         l
+         m/m
+       * main
+         mb
+         n
+         o/o
+         o/p
+         q
+         r
+         topic
+         $long
+       EOF
        test_cmp expect actual
 '
 
@@ -481,10 +481,10 @@ test_expect_success 'git branch with column.*' '
        COLUMNS=80 git branch >actual &&
        git config --unset column.branch &&
        git config --unset column.ui &&
-       cat >expect <<\EOF &&
-  a/b/c   bam   foo   l   * main   n     o/p   r
-  abc     bar   j/k   m/m   mb     o/o   q     topic
-EOF
+       cat >expect <<-\EOF &&
+         a/b/c   bam   foo   l   * main   n     o/p   r
+         abc     bar   j/k   m/m   mb     o/o   q     topic
+       EOF
        test_cmp expect actual
 '
 
@@ -496,39 +496,36 @@ test_expect_success 'git branch -v with column.ui ignored' '
        git config column.ui column &&
        COLUMNS=80 git branch -v | cut -c -8 | sed "s/ *$//" >actual &&
        git config --unset column.ui &&
-       cat >expect <<\EOF &&
-  a/b/c
-  abc
-  bam
-  bar
-  foo
-  j/k
-  l
-  m/m
-* main
-  mb
-  n
-  o/o
-  o/p
-  q
-  r
-  topic
-EOF
+       cat >expect <<-\EOF &&
+         a/b/c
+         abc
+         bam
+         bar
+         foo
+         j/k
+         l
+         m/m
+       * main
+         mb
+         n
+         o/o
+         o/p
+         q
+         r
+         topic
+       EOF
        test_cmp expect actual
 '
 
-mv .git/config .git/config-saved
-
 test_expect_success DEFAULT_REPO_FORMAT 'git branch -m q q2 without config should succeed' '
+       test_when_finished mv .git/config-saved .git/config &&
+       mv .git/config .git/config-saved &&
        git branch -m q q2 &&
        git branch -m q2 q
 '
 
-mv .git/config-saved .git/config
-
-git config branch.s/s.dummy Hello
-
 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
+       git config branch.s/s.dummy Hello &&
        git branch --create-reflog s/s &&
        git reflog exists refs/heads/s/s &&
        git branch --create-reflog s/t &&
@@ -1112,14 +1109,14 @@ test_expect_success '--set-upstream-to notices an error to set branch as own ups
        test_cmp expect actual
 "
 
-# Keep this test last, as it changes the current branch
-cat >expect <<EOF
-$HEAD refs/heads/g/h/i@{0}: branch: Created from main
-EOF
 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
+       test_when_finished git checkout main &&
        GIT_COMMITTER_DATE="2005-05-26 23:30" \
        git checkout -b g/h/i -l main &&
        test_ref_exists refs/heads/g/h/i &&
+       cat >expect <<-EOF &&
+       $HEAD refs/heads/g/h/i@{0}: branch: Created from main
+       EOF
        git reflog show --no-abbrev-commit refs/heads/g/h/i >actual &&
        test_cmp expect actual
 '
@@ -1696,4 +1693,14 @@ test_expect_success '--track overrides branch.autoSetupMerge' '
        test_cmp_config "" --default "" branch.foo5.merge
 '
 
+test_expect_success 'errors if given a bad branch name' '
+       cat <<-\EOF >expect &&
+       fatal: '\''foo..bar'\'' is not a valid branch name
+       hint: See `man git check-ref-format`
+       hint: Disable this message with "git config advice.refSyntax false"
+       EOF
+       test_must_fail git branch foo..bar >actual 2>&1 &&
+       test_cmp expect actual
+'
+
 test_done
index d7382709fc11055be003751d802f953ed56b6eab..f698d0c9ad274137a9aa254c8e89bcece8f4cddd 100755 (executable)
@@ -312,6 +312,38 @@ test_expect_success 'shortlog de-duplicates trailers in a single commit' '
        test_cmp expect actual
 '
 
+# Trailers that have unfolded (single line) and folded (multiline) values which
+# are otherwise identical are treated as the same trailer for de-duplication.
+test_expect_success 'shortlog de-duplicates trailers in a single commit (folded/unfolded values)' '
+       git commit --allow-empty -F - <<-\EOF &&
+       subject one
+
+       this message has two distinct values, plus a repeat (folded)
+
+       Repeated-trailer: Foo foo foo
+       Repeated-trailer: Bar
+       Repeated-trailer: Foo
+         foo foo
+       EOF
+
+       git commit --allow-empty -F - <<-\EOF &&
+       subject two
+
+       similar to the previous, but without the second distinct value
+
+       Repeated-trailer: Foo foo foo
+       Repeated-trailer: Foo
+         foo foo
+       EOF
+
+       cat >expect <<-\EOF &&
+            2  Foo foo foo
+            1  Bar
+       EOF
+       git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'shortlog can match multiple groups' '
        git commit --allow-empty -F - <<-\EOF &&
        subject one
index 12ac43687366d72f2fa2870c72a9d5563a05fc66..29e9974cdfd421f6fb7dd17fa2bb12db8d5d6e04 100755 (executable)
@@ -945,4 +945,49 @@ test_expect_success 'check the input format when --stdin is passed' '
        test_cmp expect actual
 '
 
+test_expect_success '--merge-base with tree OIDs' '
+       git merge-tree --merge-base=side1^ side1 side3 >with-commits &&
+       git merge-tree --merge-base=side1^^{tree} side1^{tree} side3^{tree} >with-trees &&
+       test_cmp with-commits with-trees
+'
+
+test_expect_success 'error out on missing tree objects' '
+       git init --bare missing-tree.git &&
+       git rev-list side3 >list &&
+       git rev-parse side3^: >>list &&
+       git pack-objects missing-tree.git/objects/pack/side3-tree-is-missing <list &&
+       side3=$(git rev-parse side3) &&
+       test_must_fail git --git-dir=missing-tree.git merge-tree $side3^ $side3 >actual 2>err &&
+       test_grep "Could not read $(git rev-parse $side3:)" err &&
+       test_must_be_empty actual
+'
+
+test_expect_success 'error out on missing blob objects' '
+       echo 1 | git hash-object -w --stdin >blob1 &&
+       echo 2 | git hash-object -w --stdin >blob2 &&
+       echo 3 | git hash-object -w --stdin >blob3 &&
+       printf "100644 blob $(cat blob1)\tblob\n" | git mktree >tree1 &&
+       printf "100644 blob $(cat blob2)\tblob\n" | git mktree >tree2 &&
+       printf "100644 blob $(cat blob3)\tblob\n" | git mktree >tree3 &&
+       git init --bare missing-blob.git &&
+       cat blob1 blob3 tree1 tree2 tree3 |
+       git pack-objects missing-blob.git/objects/pack/side1-whatever-is-missing &&
+       test_must_fail git --git-dir=missing-blob.git >actual 2>err \
+               merge-tree --merge-base=$(cat tree1) $(cat tree2) $(cat tree3) &&
+       test_grep "unable to read blob object $(cat blob2)" err &&
+       test_must_be_empty actual
+'
+
+test_expect_success 'error out on missing commits as well' '
+       git init --bare missing-commit.git &&
+       git rev-list --objects side1 side3 >list-including-initial &&
+       grep -v ^$(git rev-parse side1^) <list-including-initial >list &&
+       git pack-objects missing-commit.git/objects/pack/missing-initial <list &&
+       side1=$(git rev-parse side1) &&
+       side3=$(git rev-parse side3) &&
+       test_must_fail git --git-dir=missing-commit.git \
+               merge-tree --allow-unrelated-histories $side1 $side3 >actual &&
+       test_must_be_empty actual
+'
+
 test_done
index b1cfe8b7dba816ddcaee85c0a3e19d0c958e6cd5..3dcb3340a36bb0e0efca1c1dfad6373dd5aeedc5 100755 (executable)
@@ -131,7 +131,6 @@ test_expect_success 'git upload-pack --advertise-refs: v2' '
        fetch=shallow wait-for-done
        server-option
        object-format=$(test_oid algo)
-       object-info
        0000
        EOF
 
index a400bcca622f464f13fe4f0a57c4d44ec8dd827b..e93e0d0cc397a323bae99e9f92ee5d02cb026f2b 100755 (executable)
@@ -120,14 +120,14 @@ test_expect_success 'prefers -c config over --template config' '
 
 '
 
-test_expect_failure 'prefers --template config even for core.bare' '
+test_expect_success 'ignore --template config for core.bare' '
 
        template="$TRASH_DIRECTORY/template-with-bare-config" &&
        mkdir "$template" &&
        git config --file "$template/config" core.bare true &&
        git clone "--template=$template" parent clone-bare-config &&
-       test "$(git -C clone-bare-config config --local core.bare)" = "true" &&
-       test_path_is_file clone-bare-config/HEAD
+       test "$(git -C clone-bare-config config --local core.bare)" = "false" &&
+       test_path_is_missing clone-bare-config/HEAD
 '
 
 test_expect_success 'prefers config "clone.defaultRemoteName" over default' '
index 3591bc2417119c75181cc1884ea9e48a7a87646a..c48830de8fe20448116f7988b450fe2d52d786e3 100755 (executable)
@@ -20,7 +20,6 @@ test_expect_success 'test capability advertisement' '
        fetch=shallow wait-for-done
        server-option
        object-format=$(test_oid algo)
-       object-info
        EOF
        cat >expect.trailer <<-EOF &&
        0000
@@ -323,6 +322,8 @@ test_expect_success 'unexpected lines are not allowed in fetch request' '
 # Test the basics of object-info
 #
 test_expect_success 'basics of object-info' '
+       test_config transfer.advertiseObjectInfo true &&
+
        test-tool pkt-line pack >in <<-EOF &&
        command=object-info
        object-format=$(test_oid algo)
@@ -380,4 +381,25 @@ test_expect_success 'basics of bundle-uri: dies if not enabled' '
        test_must_be_empty out
 '
 
+test_expect_success 'object-info missing from capabilities when disabled' '
+       test_config transfer.advertiseObjectInfo false &&
+
+       GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
+               --advertise-capabilities >out &&
+       test-tool pkt-line unpack <out >actual &&
+
+       ! grep object.info actual
+'
+
+test_expect_success 'object-info commands rejected when disabled' '
+       test_config transfer.advertiseObjectInfo false &&
+
+       test-tool pkt-line pack >in <<-EOF &&
+       command=object-info
+       EOF
+
+       test_must_fail test-tool serve-v2 --stateless-rpc <in 2>err &&
+       grep invalid.command err
+'
+
 test_done
index 6ef4971845fb4407977e98cb62b3468abfca5838..1ef540f73d34756673423ff77fa46567bd34b2ab 100755 (executable)
@@ -778,6 +778,25 @@ test_expect_success 'archive with custom path does not request v2' '
        ! grep ^GIT_PROTOCOL env.trace
 '
 
+test_expect_success 'reject client packfile-uris if not advertised' '
+       {
+               packetize command=fetch &&
+               packetize object-format=$(test_oid algo) &&
+               printf 0001 &&
+               packetize packfile-uris https &&
+               packetize done &&
+               printf 0000
+       } >input &&
+       test_must_fail env GIT_PROTOCOL=version=2 \
+               git upload-pack client <input &&
+       test_must_fail env GIT_PROTOCOL=version=2 \
+               git -c uploadpack.blobpackfileuri \
+               upload-pack client <input &&
+       GIT_PROTOCOL=version=2 \
+               git -c uploadpack.blobpackfileuri=anything \
+               upload-pack client <input
+'
+
 # Test protocol v2 with 'http://' transport
 #
 . "$TEST_DIRECTORY"/lib-httpd.sh
index 1544d6dc6ba19170a1dfdb8ded299530f70be1de..bcfb358c51cc087efd75aa04488f9b16a75e7293 100755 (executable)
@@ -12,6 +12,11 @@ url=$2
 
 dir="$GIT_DIR/testgit/$alias"
 
+if ! git rev-parse --is-inside-git-dir
+then
+       exit 1
+fi
+
 h_refspec="refs/heads/*:refs/testgit/$alias/heads/*"
 t_refspec="refs/tags/*:refs/testgit/$alias/tags/*"
 
index 211672759a2260e5a1bb572f96aad93b3d3f91e5..127180e1c9a246769fb5bb7ede57f814abb4fc79 100755 (executable)
@@ -10,7 +10,10 @@ TEST_PASSES_SANITIZE_LEAK=true
 test_expect_success 'create repository and alternate directory' '
        test_commit 1 &&
        test_commit 2 &&
-       test_commit 3
+       test_commit 3 &&
+       git tag -m "tag message" annot_tag HEAD~1 &&
+       git tag regul_tag HEAD~1 &&
+       git branch a_branch HEAD~1
 '
 
 # We manually corrupt the repository, which means that the commit-graph may
@@ -46,9 +49,10 @@ do
                        git rev-list --objects --no-object-names \
                                HEAD ^$obj >expect.raw &&
 
-                       # Blobs are shared by all commits, so evethough a commit/tree
+                       # Blobs are shared by all commits, so evethough a commit/tree
                        # might be skipped, its blob must be accounted for.
-                       if [ $obj != "HEAD:1.t" ]; then
+                       if test $obj != "HEAD:1.t"
+                       then
                                echo $(git rev-parse HEAD:1.t) >>expect.raw &&
                                echo $(git rev-parse HEAD:2.t) >>expect.raw
                        fi &&
@@ -77,4 +81,69 @@ do
        done
 done
 
+for missing_tip in "annot_tag" "regul_tag" "a_branch" "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t"
+do
+       # We want to check that things work when both
+       #   - all the tips passed are missing (case existing_tip = ""), and
+       #   - there is one missing tip and one existing tip (case existing_tip = "HEAD")
+       for existing_tip in "" "HEAD"
+       do
+               for action in "allow-any" "print"
+               do
+                       test_expect_success "--missing=$action with tip '$missing_tip' missing and tip '$existing_tip'" '
+                               # Before the object is made missing, we use rev-list to
+                               # get the expected oids.
+                               if test "$existing_tip" = "HEAD"
+                               then
+                                       git rev-list --objects --no-object-names \
+                                               HEAD ^$missing_tip >expect.raw
+                               else
+                                       >expect.raw
+                               fi &&
+
+                               # Blobs are shared by all commits, so even though a commit/tree
+                               # might be skipped, its blob must be accounted for.
+                               if test "$existing_tip" = "HEAD" && test $missing_tip != "HEAD:1.t"
+                               then
+                                       echo $(git rev-parse HEAD:1.t) >>expect.raw &&
+                                       echo $(git rev-parse HEAD:2.t) >>expect.raw
+                               fi &&
+
+                               missing_oid="$(git rev-parse $missing_tip)" &&
+
+                               if test "$missing_tip" = "annot_tag"
+                               then
+                                       oid="$(git rev-parse $missing_tip^{commit})" &&
+                                       echo "$missing_oid" >>expect.raw
+                               else
+                                       oid="$missing_oid"
+                               fi &&
+
+                               path=".git/objects/$(test_oid_to_path $oid)" &&
+
+                               mv "$path" "$path.hidden" &&
+                               test_when_finished "mv $path.hidden $path" &&
+
+                               git rev-list --missing=$action --objects --no-object-names \
+                                    $missing_oid $existing_tip >actual.raw &&
+
+                               # When the action is to print, we should also add the missing
+                               # oid to the expect list.
+                               case $action in
+                               allow-any)
+                                       ;;
+                               print)
+                                       grep ?$oid actual.raw &&
+                                       echo ?$oid >>expect.raw
+                                       ;;
+                               esac &&
+
+                               sort actual.raw >actual &&
+                               sort expect.raw >expect &&
+                               test_cmp expect actual
+                       '
+               done
+       done
+done
+
 test_done
index 561080bf240d6d5de7b557c6332995846f60e56e..cdc02706404b34b17b29692d72d97fab7eba58b1 100755 (executable)
@@ -878,7 +878,7 @@ test_expect_success 'broken branch creation' '
 
 echo "" > expected.ok
 cat > expected.missing-tree.default <<EOF
-fatal: unable to read tree $deleted
+fatal: unable to read tree ($deleted)
 EOF
 
 test_expect_success 'bisect fails if tree is broken on start commit' '
index 611b3dd3aedb44c9b5d4657f3058c72a60258cb0..1f7201eb60caf9b31fd3db1a83dc834bb145157c 100755 (executable)
@@ -407,6 +407,12 @@ test_expect_success 'clean.requireForce and -f' '
 
 '
 
+test_expect_success 'clean.requireForce and --interactive' '
+       git clean --interactive </dev/null >output 2>error &&
+       test_grep ! "requireForce is true and" error &&
+       test_grep "\*\*\* Commands \*\*\*" output
+'
+
 test_expect_success 'core.excludesfile' '
 
        echo excludes >excludes &&
index d82a3210a1db48288c54ce3c06d430546da70f48..4afe53c66ae57acdadc7177b98fd0aacefdd576c 100755 (executable)
@@ -25,18 +25,18 @@ test_expect_success 'git clean -i (c: clean hotkey)' '
        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
        docs/manual.txt obj.o build/lib.so &&
        echo c | git clean -i &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test ! -f a.out &&
-       test -f docs/manual.txt &&
-       test ! -f src/part3.c &&
-       test ! -f src/part3.h &&
-       test ! -f src/part4.c &&
-       test ! -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_missing a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_missing src/part3.c &&
+       test_path_is_missing src/part3.h &&
+       test_path_is_missing src/part4.c &&
+       test_path_is_missing src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -46,18 +46,18 @@ test_expect_success 'git clean -i (cl: clean prefix)' '
        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
        docs/manual.txt obj.o build/lib.so &&
        echo cl | git clean -i &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test ! -f a.out &&
-       test -f docs/manual.txt &&
-       test ! -f src/part3.c &&
-       test ! -f src/part3.h &&
-       test ! -f src/part4.c &&
-       test ! -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_missing a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_missing src/part3.c &&
+       test_path_is_missing src/part3.h &&
+       test_path_is_missing src/part4.c &&
+       test_path_is_missing src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -67,18 +67,18 @@ test_expect_success 'git clean -i (quit)' '
        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
        docs/manual.txt obj.o build/lib.so &&
        echo quit | git clean -i &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test -f a.out &&
-       test -f docs/manual.txt &&
-       test -f src/part3.c &&
-       test -f src/part3.h &&
-       test -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_file a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_file src/part3.c &&
+       test_path_is_file src/part3.h &&
+       test_path_is_file src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -88,18 +88,18 @@ test_expect_success 'git clean -i (Ctrl+D)' '
        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
        docs/manual.txt obj.o build/lib.so &&
        echo "\04" | git clean -i &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test -f a.out &&
-       test -f docs/manual.txt &&
-       test -f src/part3.c &&
-       test -f src/part3.h &&
-       test -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_file a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_file src/part3.c &&
+       test_path_is_file src/part3.h &&
+       test_path_is_file src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -110,18 +110,18 @@ test_expect_success 'git clean -id (filter all)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines f "*" "" c |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test -f a.out &&
-       test -f docs/manual.txt &&
-       test -f src/part3.c &&
-       test -f src/part3.h &&
-       test -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_file a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_file src/part3.c &&
+       test_path_is_file src/part3.h &&
+       test_path_is_file src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -132,18 +132,18 @@ test_expect_success 'git clean -id (filter patterns)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines f "part3.* *.out" "" c |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test -f a.out &&
-       test ! -f docs/manual.txt &&
-       test -f src/part3.c &&
-       test -f src/part3.h &&
-       test ! -f src/part4.c &&
-       test ! -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_file a.out &&
+       test_path_is_missing docs/manual.txt &&
+       test_path_is_file src/part3.c &&
+       test_path_is_file src/part3.h &&
+       test_path_is_missing src/part4.c &&
+       test_path_is_missing src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -154,18 +154,18 @@ test_expect_success 'git clean -id (filter patterns 2)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines f "* !*.out" "" c |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test ! -f a.out &&
-       test -f docs/manual.txt &&
-       test -f src/part3.c &&
-       test -f src/part3.h &&
-       test -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_missing a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_file src/part3.c &&
+       test_path_is_file src/part3.h &&
+       test_path_is_file src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -176,18 +176,18 @@ test_expect_success 'git clean -id (select - all)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines s "*" "" c |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test ! -f a.out &&
-       test ! -f docs/manual.txt &&
-       test ! -f src/part3.c &&
-       test ! -f src/part3.h &&
-       test ! -f src/part4.c &&
-       test ! -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_missing a.out &&
+       test_path_is_missing docs/manual.txt &&
+       test_path_is_missing src/part3.c &&
+       test_path_is_missing src/part3.h &&
+       test_path_is_missing src/part4.c &&
+       test_path_is_missing src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -198,18 +198,18 @@ test_expect_success 'git clean -id (select - none)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines s "" c |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test -f a.out &&
-       test -f docs/manual.txt &&
-       test -f src/part3.c &&
-       test -f src/part3.h &&
-       test -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_file a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_file src/part3.c &&
+       test_path_is_file src/part3.h &&
+       test_path_is_file src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -220,18 +220,18 @@ test_expect_success 'git clean -id (select - number)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines s 3 "" c |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test -f a.out &&
-       test -f docs/manual.txt &&
-       test ! -f src/part3.c &&
-       test -f src/part3.h &&
-       test -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_file a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_missing src/part3.c &&
+       test_path_is_file src/part3.h &&
+       test_path_is_file src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -242,18 +242,18 @@ test_expect_success 'git clean -id (select - number 2)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines s "2 3" 5 "" c |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test -f a.out &&
-       test ! -f docs/manual.txt &&
-       test ! -f src/part3.c &&
-       test -f src/part3.h &&
-       test ! -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_file a.out &&
+       test_path_is_missing docs/manual.txt &&
+       test_path_is_missing src/part3.c &&
+       test_path_is_file src/part3.h &&
+       test_path_is_missing src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -264,18 +264,18 @@ test_expect_success 'git clean -id (select - number 3)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines s "3,4 5" "" c |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test -f a.out &&
-       test -f docs/manual.txt &&
-       test ! -f src/part3.c &&
-       test ! -f src/part3.h &&
-       test ! -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_file a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_missing src/part3.c &&
+       test_path_is_missing src/part3.h &&
+       test_path_is_missing src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -285,11 +285,11 @@ test_expect_success 'git clean -id (select - filenames)' '
        touch a.out foo.txt bar.txt baz.txt &&
        test_write_lines s "a.out fo ba bar" "" c |
        git clean -id &&
-       test -f Makefile &&
-       test ! -f a.out &&
-       test ! -f foo.txt &&
-       test ! -f bar.txt &&
-       test -f baz.txt &&
+       test_path_is_file Makefile &&
+       test_path_is_missing a.out &&
+       test_path_is_missing foo.txt &&
+       test_path_is_missing bar.txt &&
+       test_path_is_file baz.txt &&
        rm baz.txt
 
 '
@@ -301,18 +301,18 @@ test_expect_success 'git clean -id (select - range)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines s "1,3-4" 2 "" c |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test ! -f a.out &&
-       test ! -f src/part3.c &&
-       test ! -f src/part3.h &&
-       test -f src/part4.c &&
-       test -f src/part4.h &&
-       test ! -f docs/manual.txt &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_missing a.out &&
+       test_path_is_missing src/part3.c &&
+       test_path_is_missing src/part3.h &&
+       test_path_is_file src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_missing docs/manual.txt &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -323,18 +323,18 @@ test_expect_success 'git clean -id (select - range 2)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines s "4- 1" "" c |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test ! -f a.out &&
-       test -f docs/manual.txt &&
-       test -f src/part3.c &&
-       test ! -f src/part3.h &&
-       test ! -f src/part4.c &&
-       test ! -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_missing a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_file src/part3.c &&
+       test_path_is_missing src/part3.h &&
+       test_path_is_missing src/part4.c &&
+       test_path_is_missing src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -345,18 +345,18 @@ test_expect_success 'git clean -id (inverse select)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines s "*" "-5- 1 -2" "" c |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test ! -f a.out &&
-       test -f docs/manual.txt &&
-       test ! -f src/part3.c &&
-       test ! -f src/part3.h &&
-       test -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_missing a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_missing src/part3.c &&
+       test_path_is_missing src/part3.h &&
+       test_path_is_file src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -367,18 +367,18 @@ test_expect_success 'git clean -id (ask)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines a Y y no yes bad "" |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test ! -f a.out &&
-       test ! -f docs/manual.txt &&
-       test -f src/part3.c &&
-       test ! -f src/part3.h &&
-       test -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_missing a.out &&
+       test_path_is_missing docs/manual.txt &&
+       test_path_is_file src/part3.c &&
+       test_path_is_missing src/part3.h &&
+       test_path_is_file src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -389,18 +389,18 @@ test_expect_success 'git clean -id (ask - Ctrl+D)' '
        docs/manual.txt obj.o build/lib.so &&
        test_write_lines a Y no yes "\04" |
        git clean -id &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test ! -f a.out &&
-       test -f docs/manual.txt &&
-       test ! -f src/part3.c &&
-       test -f src/part3.h &&
-       test -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_missing a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_missing src/part3.c &&
+       test_path_is_file src/part3.h &&
+       test_path_is_file src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -412,18 +412,18 @@ test_expect_success 'git clean -id with prefix and path (filter)' '
        (cd build/ &&
         test_write_lines f docs "*.h" "" c |
         git clean -id ..) &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test ! -f a.out &&
-       test -f docs/manual.txt &&
-       test ! -f src/part3.c &&
-       test -f src/part3.h &&
-       test ! -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_missing a.out &&
+       test_path_is_file docs/manual.txt &&
+       test_path_is_missing src/part3.c &&
+       test_path_is_file src/part3.h &&
+       test_path_is_missing src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -435,18 +435,18 @@ test_expect_success 'git clean -id with prefix and path (select by name)' '
        (cd build/ &&
         test_write_lines s ../docs/ ../src/part3.c ../src/part4.c "" c |
         git clean -id ..) &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test -f a.out &&
-       test ! -f docs/manual.txt &&
-       test ! -f src/part3.c &&
-       test -f src/part3.h &&
-       test ! -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_file a.out &&
+       test_path_is_missing docs/manual.txt &&
+       test_path_is_missing src/part3.c &&
+       test_path_is_file src/part3.h &&
+       test_path_is_missing src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
@@ -458,18 +458,18 @@ test_expect_success 'git clean -id with prefix and path (ask)' '
        (cd build/ &&
         test_write_lines a Y y no yes bad "" |
         git clean -id ..) &&
-       test -f Makefile &&
-       test -f README &&
-       test -f src/part1.c &&
-       test -f src/part2.c &&
-       test ! -f a.out &&
-       test ! -f docs/manual.txt &&
-       test -f src/part3.c &&
-       test ! -f src/part3.h &&
-       test -f src/part4.c &&
-       test -f src/part4.h &&
-       test -f obj.o &&
-       test -f build/lib.so
+       test_path_is_file Makefile &&
+       test_path_is_file README &&
+       test_path_is_file src/part1.c &&
+       test_path_is_file src/part2.c &&
+       test_path_is_missing a.out &&
+       test_path_is_missing docs/manual.txt &&
+       test_path_is_file src/part3.c &&
+       test_path_is_missing src/part3.h &&
+       test_path_is_file src/part4.c &&
+       test_path_is_file src/part4.h &&
+       test_path_is_file obj.o &&
+       test_path_is_file build/lib.so
 
 '
 
index a87c211d0b16d0ffc4f8c7c2d6366209af1198f5..b37e2018a74a7b28725fa277a95cca516daf5cbe 100755 (executable)
@@ -736,6 +736,11 @@ test_expect_success 'message shows date when it is explicitly set' '
          .git/COMMIT_EDITMSG
 '
 
+test_expect_success 'message does not have multiple scissors lines' '
+       git commit --cleanup=scissors -v --allow-empty -e -m foo &&
+       test $(grep -c -e "--- >8 ---" .git/COMMIT_EDITMSG) -eq 1
+'
+
 test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
 
        echo >>negative &&
index 363f9dc0e41b2686aa9892d5e21e153ca54727b9..730f3c7f81090e9d08d02b1ca0e370b05b3dd746 100755 (executable)
@@ -1037,4 +1037,227 @@ test_expect_success 'split-index and FSMonitor work well together' '
        )
 '
 
+# The FSMonitor daemon reports the OBSERVED pathname of modified files
+# and thus contains the OBSERVED spelling on case-insensitive file
+# systems.  The daemon does not (and should not) load the .git/index
+# file and therefore does not know the expected case-spelling.  Since
+# it is possible for the user to create files/subdirectories with the
+# incorrect case, a modified file event for a tracked will not have
+# the EXPECTED case. This can cause `index_name_pos()` to incorrectly
+# report that the file is untracked. This causes the client to fail to
+# mark the file as possibly dirty (keeping the CE_FSMONITOR_VALID bit
+# set) so that `git status` will avoid inspecting it and thus not
+# present in the status output.
+#
+# The setup is a little contrived.
+#
+test_expect_success CASE_INSENSITIVE_FS 'fsmonitor subdir case wrong on disk' '
+       test_when_finished "stop_daemon_delete_repo subdir_case_wrong" &&
+
+       git init subdir_case_wrong &&
+       (
+               cd subdir_case_wrong &&
+               echo x >AAA &&
+               echo x >BBB &&
+
+               mkdir dir1 &&
+               echo x >dir1/file1 &&
+               mkdir dir1/dir2 &&
+               echo x >dir1/dir2/file2 &&
+               mkdir dir1/dir2/dir3 &&
+               echo x >dir1/dir2/dir3/file3 &&
+
+               echo x >yyy &&
+               echo x >zzz &&
+               git add . &&
+               git commit -m "data" &&
+
+               # This will cause "dir1/" and everything under it
+               # to be deleted.
+               git sparse-checkout set --cone --sparse-index &&
+
+               # Create dir2 with the wrong case and then let Git
+               # repopulate dir3 -- it will not correct the spelling
+               # of dir2.
+               mkdir dir1 &&
+               mkdir dir1/DIR2 &&
+               git sparse-checkout add dir1/dir2/dir3
+       ) &&
+
+       start_daemon -C subdir_case_wrong --tf "$PWD/subdir_case_wrong.trace" &&
+
+       # Enable FSMonitor in the client. Run enough commands for
+       # the .git/index to sync up with the daemon with everything
+       # marked clean.
+       git -C subdir_case_wrong config core.fsmonitor true &&
+       git -C subdir_case_wrong update-index --fsmonitor &&
+       git -C subdir_case_wrong status &&
+
+       # Make some files dirty so that FSMonitor gets FSEvents for
+       # each of them.
+       echo xx >>subdir_case_wrong/AAA &&
+       echo xx >>subdir_case_wrong/dir1/DIR2/dir3/file3 &&
+       echo xx >>subdir_case_wrong/zzz &&
+
+       GIT_TRACE_FSMONITOR="$PWD/subdir_case_wrong.log" \
+               git -C subdir_case_wrong --no-optional-locks status --short \
+                       >"$PWD/subdir_case_wrong.out" &&
+
+       # "git status" should have gotten file events for each of
+       # the 3 files.
+       #
+       # "dir2" should be in the observed case on disk.
+       grep "fsmonitor_refresh_callback" \
+               <"$PWD/subdir_case_wrong.log" \
+               >"$PWD/subdir_case_wrong.log1" &&
+
+       grep -q "AAA.*pos 0" "$PWD/subdir_case_wrong.log1" &&
+       grep -q "zzz.*pos 6" "$PWD/subdir_case_wrong.log1" &&
+
+       grep -q "dir1/DIR2/dir3/file3.*pos -3" "$PWD/subdir_case_wrong.log1" &&
+
+       # Verify that we get a mapping event to correct the case.
+       grep -q "MAP:.*dir1/DIR2/dir3/file3.*dir1/dir2/dir3/file3" \
+               "$PWD/subdir_case_wrong.log1" &&
+
+       # The refresh-callbacks should have caused "git status" to clear
+       # the CE_FSMONITOR_VALID bit on each of those files and caused
+       # the worktree scan to visit them and mark them as modified.
+       grep -q " M AAA" "$PWD/subdir_case_wrong.out" &&
+       grep -q " M zzz" "$PWD/subdir_case_wrong.out" &&
+       grep -q " M dir1/dir2/dir3/file3" "$PWD/subdir_case_wrong.out"
+'
+
+test_expect_success CASE_INSENSITIVE_FS 'fsmonitor file case wrong on disk' '
+       test_when_finished "stop_daemon_delete_repo file_case_wrong" &&
+
+       git init file_case_wrong &&
+       (
+               cd file_case_wrong &&
+               echo x >AAA &&
+               echo x >BBB &&
+
+               mkdir dir1 &&
+               mkdir dir1/dir2 &&
+               mkdir dir1/dir2/dir3 &&
+               echo x >dir1/dir2/dir3/FILE-3-B &&
+               echo x >dir1/dir2/dir3/XXXX-3-X &&
+               echo x >dir1/dir2/dir3/file-3-a &&
+               echo x >dir1/dir2/dir3/yyyy-3-y &&
+               mkdir dir1/dir2/dir4 &&
+               echo x >dir1/dir2/dir4/FILE-4-A &&
+               echo x >dir1/dir2/dir4/XXXX-4-X &&
+               echo x >dir1/dir2/dir4/file-4-b &&
+               echo x >dir1/dir2/dir4/yyyy-4-y &&
+
+               echo x >yyy &&
+               echo x >zzz &&
+               git add . &&
+               git commit -m "data"
+       ) &&
+
+       start_daemon -C file_case_wrong --tf "$PWD/file_case_wrong.trace" &&
+
+       # Enable FSMonitor in the client. Run enough commands for
+       # the .git/index to sync up with the daemon with everything
+       # marked clean.
+       git -C file_case_wrong config core.fsmonitor true &&
+       git -C file_case_wrong update-index --fsmonitor &&
+       git -C file_case_wrong status &&
+
+       # Make some files dirty so that FSMonitor gets FSEvents for
+       # each of them.
+       echo xx >>file_case_wrong/AAA &&
+       echo xx >>file_case_wrong/zzz &&
+
+       # Rename some files so that FSMonitor sees a create and delete
+       # FSEvent for each.  (A simple "mv foo FOO" is not portable
+       # between macOS and Windows. It works on both platforms, but makes
+       # the test messy, since (1) one platform updates "ctime" on the
+       # moved file and one does not and (2) it causes a directory event
+       # on one platform and not on the other which causes additional
+       # scanning during "git status" which causes a "H" vs "h" discrepancy
+       # in "git ls-files -f".)  So old-school it and move it out of the
+       # way and copy it to the case-incorrect name so that we get fresh
+       # "ctime" and "mtime" values.
+
+       mv file_case_wrong/dir1/dir2/dir3/file-3-a file_case_wrong/dir1/dir2/dir3/ORIG &&
+       cp file_case_wrong/dir1/dir2/dir3/ORIG     file_case_wrong/dir1/dir2/dir3/FILE-3-A &&
+       rm file_case_wrong/dir1/dir2/dir3/ORIG &&
+       mv file_case_wrong/dir1/dir2/dir4/FILE-4-A file_case_wrong/dir1/dir2/dir4/ORIG &&
+       cp file_case_wrong/dir1/dir2/dir4/ORIG     file_case_wrong/dir1/dir2/dir4/file-4-a &&
+       rm file_case_wrong/dir1/dir2/dir4/ORIG &&
+
+       # Run status enough times to fully sync.
+       #
+       # The first instance should get the create and delete FSEvents
+       # for each pair.  Status should update the index with a new FSM
+       # token (so the next invocation will not see data for these
+       # events).
+
+       GIT_TRACE_FSMONITOR="$PWD/file_case_wrong-try1.log" \
+               git -C file_case_wrong status --short \
+                       >"$PWD/file_case_wrong-try1.out" &&
+       grep -q "fsmonitor_refresh_callback.*FILE-3-A.*pos -3" "$PWD/file_case_wrong-try1.log" &&
+       grep -q "fsmonitor_refresh_callback.*file-3-a.*pos 4"  "$PWD/file_case_wrong-try1.log" &&
+       grep -q "fsmonitor_refresh_callback.*FILE-4-A.*pos 6"  "$PWD/file_case_wrong-try1.log" &&
+       grep -q "fsmonitor_refresh_callback.*file-4-a.*pos -9" "$PWD/file_case_wrong-try1.log" &&
+
+       # FSM refresh will have invalidated the FSM bit and cause a regular
+       # (real) scan of these tracked files, so they should have "H" status.
+       # (We will not see a "h" status until the next refresh (on the next
+       # command).)
+
+       git -C file_case_wrong ls-files -f >"$PWD/file_case_wrong-lsf1.out" &&
+       grep -q "H dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-lsf1.out" &&
+       grep -q "H dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-lsf1.out" &&
+
+
+       # Try the status again. We assume that the above status command
+       # advanced the token so that the next one will not see those events.
+
+       GIT_TRACE_FSMONITOR="$PWD/file_case_wrong-try2.log" \
+               git -C file_case_wrong status --short \
+                       >"$PWD/file_case_wrong-try2.out" &&
+       ! grep -q "fsmonitor_refresh_callback.*FILE-3-A.*pos" "$PWD/file_case_wrong-try2.log" &&
+       ! grep -q "fsmonitor_refresh_callback.*file-3-a.*pos" "$PWD/file_case_wrong-try2.log" &&
+       ! grep -q "fsmonitor_refresh_callback.*FILE-4-A.*pos" "$PWD/file_case_wrong-try2.log" &&
+       ! grep -q "fsmonitor_refresh_callback.*file-4-a.*pos" "$PWD/file_case_wrong-try2.log" &&
+
+       # FSM refresh saw nothing, so it will mark all files as valid,
+       # so they should now have "h" status.
+
+       git -C file_case_wrong ls-files -f >"$PWD/file_case_wrong-lsf2.out" &&
+       grep -q "h dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-lsf2.out" &&
+       grep -q "h dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-lsf2.out" &&
+
+
+       # We now have files with clean content, but with case-incorrect
+       # file names.  Modify them to see if status properly reports
+       # them.
+
+       echo xx >>file_case_wrong/dir1/dir2/dir3/FILE-3-A &&
+       echo xx >>file_case_wrong/dir1/dir2/dir4/file-4-a &&
+
+       GIT_TRACE_FSMONITOR="$PWD/file_case_wrong-try3.log" \
+               git -C file_case_wrong --no-optional-locks status --short \
+                       >"$PWD/file_case_wrong-try3.out" &&
+
+       # Verify that we get a mapping event to correct the case.
+       grep -q "fsmonitor_refresh_callback MAP:.*dir1/dir2/dir3/FILE-3-A.*dir1/dir2/dir3/file-3-a" \
+               "$PWD/file_case_wrong-try3.log" &&
+       grep -q "fsmonitor_refresh_callback MAP:.*dir1/dir2/dir4/file-4-a.*dir1/dir2/dir4/FILE-4-A" \
+               "$PWD/file_case_wrong-try3.log" &&
+
+       # FSEvents are in observed case.
+       grep -q "fsmonitor_refresh_callback.*FILE-3-A.*pos -3" "$PWD/file_case_wrong-try3.log" &&
+       grep -q "fsmonitor_refresh_callback.*file-4-a.*pos -9" "$PWD/file_case_wrong-try3.log" &&
+
+       # The refresh-callbacks should have caused "git status" to clear
+       # the CE_FSMONITOR_VALID bit on each of those files and caused
+       # the worktree scan to visit them and mark them as modified.
+       grep -q " M dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-try3.out" &&
+       grep -q " M dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-try3.out"
+'
+
 test_done
index 62de819a44e40c8fae821789e1d11753054a2258..3b038c338f2154e4470d3f472a448d5881adf54d 100755 (executable)
@@ -17,32 +17,32 @@ test_expect_success 'setup svnrepo' '
 test_expect_success 'basic clone' '
        test ! -d trunk &&
        git svn clone "$svnrepo"/project/trunk &&
-       test -d trunk/.git/svn &&
-       test -e trunk/foo &&
+       test_path_is_dir trunk/.git/svn &&
+       test_path_exists trunk/foo &&
        rm -rf trunk
        '
 
 test_expect_success 'clone to target directory' '
        test ! -d target &&
        git svn clone "$svnrepo"/project/trunk target &&
-       test -d target/.git/svn &&
-       test -e target/foo &&
+       test_path_is_dir target/.git/svn &&
+       test_path_exists target/foo &&
        rm -rf target
        '
 
 test_expect_success 'clone with --stdlayout' '
        test ! -d project &&
        git svn clone -s "$svnrepo"/project &&
-       test -d project/.git/svn &&
-       test -e project/foo &&
+       test_path_is_dir project/.git/svn &&
+       test_path_exists project/foo &&
        rm -rf project
        '
 
 test_expect_success 'clone to target directory with --stdlayout' '
        test ! -d target &&
        git svn clone -s "$svnrepo"/project target &&
-       test -d target/.git/svn &&
-       test -e target/foo &&
+       test_path_is_dir target/.git/svn &&
+       test_path_exists target/foo &&
        rm -rf target
        '
 
index b16c284181b8707ed21c85efa0e0a0fea128faae..569cf2310434358d268028ea8d26361727bf8652 100755 (executable)
@@ -1263,6 +1263,29 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '
        test_cmp expected out
 '
 
+test_expect_success '__git_complete_worktree_paths' '
+       test_when_finished "git worktree remove other_wt" &&
+       git worktree add --orphan other_wt &&
+       run_completion "git worktree remove " &&
+       grep other_wt out
+'
+
+test_expect_success '__git_complete_worktree_paths - not a git repository' '
+       (
+               cd non-repo &&
+               GIT_CEILING_DIRECTORIES="$ROOT" &&
+               export GIT_CEILING_DIRECTORIES &&
+               test_completion "git worktree remove " ""
+       )
+'
+
+test_expect_success '__git_complete_worktree_paths with -C' '
+       test_when_finished "git -C otherrepo worktree remove otherrepo_wt" &&
+       git -C otherrepo worktree add --orphan otherrepo_wt &&
+       run_completion "git -C otherrepo worktree remove " &&
+       grep otherrepo_wt out
+'
+
 test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '
        test_completion "git switch " <<-\EOF
        branch-in-other Z
@@ -2804,6 +2827,20 @@ test_expect_success 'git clone --config= - value' '
        EOF
 '
 
+test_expect_success 'git reflog show' '
+       test_when_finished "git checkout - && git branch -d shown" &&
+       git checkout -b shown &&
+       test_completion "git reflog sho" <<-\EOF &&
+       show Z
+       shown Z
+       EOF
+       test_completion "git reflog show sho" "shown " &&
+       test_completion "git reflog shown sho" "shown " &&
+       test_completion "git reflog --unt" "--until=" &&
+       test_completion "git reflog show --unt" "--until=" &&
+       test_completion "git reflog shown --unt" "--until="
+'
+
 test_expect_success 'options with value' '
        test_completion "git merge -X diff-algorithm=" <<-\EOF
 
index b5eaf7fdc1186d4420388c355e794bfdba783f2f..6eaf116346be3ee52d2094715ac979aa059093c5 100644 (file)
@@ -1263,9 +1263,8 @@ test_cmp_bin () {
        cmp "$@"
 }
 
-# Deprecated - do not use this in new code
 test_i18ngrep () {
-       test_grep "$@"
+       BUG "do not use test_i18ngrep---use test_grep instead"
 }
 
 test_grep () {
index f3154899843708308a6d43074d200b8d145424be..d6ac1fe678dc73c6e126c6d1357c21d0af267a56 100644 (file)
@@ -1,30 +1,19 @@
 #include "test-lib.h"
 
-static int is_in(const char *s, int ch)
-{
-       /*
-        * We can't find NUL using strchr. Accept it as the first
-        * character in the spec -- there are no empty classes.
-        */
-       if (ch == '\0')
-               return ch == *s;
-       if (*s == '\0')
-               s++;
-       return !!strchr(s, ch);
-}
-
-/* Macro to test a character type */
-#define TEST_CTYPE_FUNC(func, string) \
-static void test_ctype_##func(void) { \
-       for (int i = 0; i < 256; i++) { \
-               if (!check_int(func(i), ==, is_in(string, i))) \
-                       test_msg("       i: 0x%02x", i); \
+#define TEST_CHAR_CLASS(class, string) do { \
+       size_t len = ARRAY_SIZE(string) - 1 + \
+               BUILD_ASSERT_OR_ZERO(ARRAY_SIZE(string) > 0) + \
+               BUILD_ASSERT_OR_ZERO(sizeof(string[0]) == sizeof(char)); \
+       int skip = test__run_begin(); \
+       if (!skip) { \
+               for (int i = 0; i < 256; i++) { \
+                       if (!check_int(class(i), ==, !!memchr(string, i, len)))\
+                               test_msg("      i: 0x%02x", i); \
+               } \
+               check(!class(EOF)); \
        } \
-       if (!check(!func(EOF))) \
-                       test_msg("      i: 0x%02x (EOF)", EOF); \
-}
-
-#define TEST_CHAR_CLASS(class) TEST(test_ctype_##class(), #class " works")
+       test__run_end(!skip, TEST_LOCATION(), #class " works"); \
+} while (0)
 
 #define DIGIT "0123456789"
 #define LOWER "abcdefghijklmnopqrstuvwxyz"
@@ -44,37 +33,21 @@ static void test_ctype_##func(void) { \
        "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \
        "\x7f"
 
-TEST_CTYPE_FUNC(isdigit, DIGIT)
-TEST_CTYPE_FUNC(isspace, " \n\r\t")
-TEST_CTYPE_FUNC(isalpha, LOWER UPPER)
-TEST_CTYPE_FUNC(isalnum, LOWER UPPER DIGIT)
-TEST_CTYPE_FUNC(is_glob_special, "*?[\\")
-TEST_CTYPE_FUNC(is_regex_special, "$()*+.?[\\^{|")
-TEST_CTYPE_FUNC(is_pathspec_magic, "!\"#%&',-/:;<=>@_`~")
-TEST_CTYPE_FUNC(isascii, ASCII)
-TEST_CTYPE_FUNC(islower, LOWER)
-TEST_CTYPE_FUNC(isupper, UPPER)
-TEST_CTYPE_FUNC(iscntrl, CNTRL)
-TEST_CTYPE_FUNC(ispunct, PUNCT)
-TEST_CTYPE_FUNC(isxdigit, DIGIT "abcdefABCDEF")
-TEST_CTYPE_FUNC(isprint, LOWER UPPER DIGIT PUNCT " ")
-
 int cmd_main(int argc, const char **argv) {
-       /* Run all character type tests */
-       TEST_CHAR_CLASS(isspace);
-       TEST_CHAR_CLASS(isdigit);
-       TEST_CHAR_CLASS(isalpha);
-       TEST_CHAR_CLASS(isalnum);
-       TEST_CHAR_CLASS(is_glob_special);
-       TEST_CHAR_CLASS(is_regex_special);
-       TEST_CHAR_CLASS(is_pathspec_magic);
-       TEST_CHAR_CLASS(isascii);
-       TEST_CHAR_CLASS(islower);
-       TEST_CHAR_CLASS(isupper);
-       TEST_CHAR_CLASS(iscntrl);
-       TEST_CHAR_CLASS(ispunct);
-       TEST_CHAR_CLASS(isxdigit);
-       TEST_CHAR_CLASS(isprint);
+       TEST_CHAR_CLASS(isspace, " \n\r\t");
+       TEST_CHAR_CLASS(isdigit, DIGIT);
+       TEST_CHAR_CLASS(isalpha, LOWER UPPER);
+       TEST_CHAR_CLASS(isalnum, LOWER UPPER DIGIT);
+       TEST_CHAR_CLASS(is_glob_special, "*?[\\");
+       TEST_CHAR_CLASS(is_regex_special, "$()*+.?[\\^{|");
+       TEST_CHAR_CLASS(is_pathspec_magic, "!\"#%&',-/:;<=>@_`~");
+       TEST_CHAR_CLASS(isascii, ASCII);
+       TEST_CHAR_CLASS(islower, LOWER);
+       TEST_CHAR_CLASS(isupper, UPPER);
+       TEST_CHAR_CLASS(iscntrl, CNTRL);
+       TEST_CHAR_CLASS(ispunct, PUNCT);
+       TEST_CHAR_CLASS(isxdigit, DIGIT "abcdefABCDEF");
+       TEST_CHAR_CLASS(isprint, LOWER UPPER DIGIT PUNCT " ");
 
        return test_done();
 }
index ef9df4af558fbb18849279cff2e67507026af106..57b4aa7d5acb515b03b2cf123744d8af34d30166 100644 (file)
--- a/trailer.c
+++ b/trailer.c
@@ -5,7 +5,6 @@
 #include "string-list.h"
 #include "run-command.h"
 #include "commit.h"
-#include "tempfile.h"
 #include "trailer.h"
 #include "list.h"
 /*
@@ -145,12 +144,12 @@ static char last_non_space_char(const char *s)
        return '\0';
 }
 
-static void print_tok_val(FILE *outfile, const char *tok, const char *val)
+static void print_tok_val(struct strbuf *out, const char *tok, const char *val)
 {
        char c;
 
        if (!tok) {
-               fprintf(outfile, "%s\n", val);
+               strbuf_addf(out, "%s\n", val);
                return;
        }
 
@@ -158,21 +157,22 @@ static void print_tok_val(FILE *outfile, const char *tok, const char *val)
        if (!c)
                return;
        if (strchr(separators, c))
-               fprintf(outfile, "%s%s\n", tok, val);
+               strbuf_addf(out, "%s%s\n", tok, val);
        else
-               fprintf(outfile, "%s%c %s\n", tok, separators[0], val);
+               strbuf_addf(out, "%s%c %s\n", tok, separators[0], val);
 }
 
-static void print_all(FILE *outfile, struct list_head *head,
-                     const struct process_trailer_options *opts)
+void format_trailers(const struct process_trailer_options *opts,
+                    struct list_head *trailers,
+                    struct strbuf *out)
 {
        struct list_head *pos;
        struct trailer_item *item;
-       list_for_each(pos, head) {
+       list_for_each(pos, trailers) {
                item = list_entry(pos, struct trailer_item, list);
                if ((!opts->trim_empty || strlen(item->value) > 0) &&
                    (!opts->only_trailers || item->token))
-                       print_tok_val(outfile, item->token, item->value);
+                       print_tok_val(out, item->token, item->value);
        }
 }
 
@@ -366,8 +366,8 @@ static int find_same_and_apply_arg(struct list_head *head,
        return 0;
 }
 
-static void process_trailers_lists(struct list_head *head,
-                                  struct list_head *arg_head)
+void process_trailers_lists(struct list_head *head,
+                           struct list_head *arg_head)
 {
        struct list_head *pos, *p;
        struct arg_item *arg_tok;
@@ -589,7 +589,7 @@ static int git_trailer_config(const char *conf_key, const char *value,
        return 0;
 }
 
-static void ensure_configured(void)
+void trailer_config_init(void)
 {
        if (configured)
                return;
@@ -719,7 +719,7 @@ static void add_arg_item(struct list_head *arg_head, char *tok, char *val,
        list_add_tail(&new_item->list, arg_head);
 }
 
-static void parse_trailers_from_config(struct list_head *config_head)
+void parse_trailers_from_config(struct list_head *config_head)
 {
        struct arg_item *item;
        struct list_head *pos;
@@ -735,8 +735,8 @@ static void parse_trailers_from_config(struct list_head *config_head)
        }
 }
 
-static void parse_trailers_from_command_line_args(struct list_head *arg_head,
-                                                 struct list_head *new_trailer_head)
+void parse_trailers_from_command_line_args(struct list_head *arg_head,
+                                          struct list_head *new_trailer_head)
 {
        struct strbuf tok = STRBUF_INIT;
        struct strbuf val = STRBUF_INIT;
@@ -775,17 +775,6 @@ static void parse_trailers_from_command_line_args(struct list_head *arg_head,
        free(cl_separators);
 }
 
-static void read_input_file(struct strbuf *sb, const char *file)
-{
-       if (file) {
-               if (strbuf_read_file(sb, file, 0) < 0)
-                       die_errno(_("could not read input file '%s'"), file);
-       } else {
-               if (strbuf_read(sb, fileno(stdin), 0) < 0)
-                       die_errno(_("could not read from stdin"));
-       }
-}
-
 static const char *next_line(const char *str)
 {
        const char *nl = strchrnul(str, '\n');
@@ -999,16 +988,16 @@ static void unfold_value(struct strbuf *val)
  * Parse trailers in "str", populating the trailer info and "head"
  * linked list structure.
  */
-static void parse_trailers(struct trailer_info *info,
-                            const char *str,
-                            struct list_head *head,
-                            const struct process_trailer_options *opts)
+void parse_trailers(const struct process_trailer_options *opts,
+                   struct trailer_info *info,
+                   const char *str,
+                   struct list_head *head)
 {
        struct strbuf tok = STRBUF_INIT;
        struct strbuf val = STRBUF_INIT;
        size_t i;
 
-       trailer_info_get(info, str, opts);
+       trailer_info_get(opts, str, info);
 
        for (i = 0; i < info->trailer_nr; i++) {
                int separator_pos;
@@ -1034,99 +1023,18 @@ static void parse_trailers(struct trailer_info *info,
        }
 }
 
-static void free_all(struct list_head *head)
+void free_trailers(struct list_head *trailers)
 {
        struct list_head *pos, *p;
-       list_for_each_safe(pos, p, head) {
+       list_for_each_safe(pos, p, trailers) {
                list_del(pos);
                free_trailer_item(list_entry(pos, struct trailer_item, list));
        }
 }
 
-static struct tempfile *trailers_tempfile;
-
-static FILE *create_in_place_tempfile(const char *file)
-{
-       struct stat st;
-       struct strbuf filename_template = STRBUF_INIT;
-       const char *tail;
-       FILE *outfile;
-
-       if (stat(file, &st))
-               die_errno(_("could not stat %s"), file);
-       if (!S_ISREG(st.st_mode))
-               die(_("file %s is not a regular file"), file);
-       if (!(st.st_mode & S_IWUSR))
-               die(_("file %s is not writable by user"), file);
-
-       /* Create temporary file in the same directory as the original */
-       tail = strrchr(file, '/');
-       if (tail)
-               strbuf_add(&filename_template, file, tail - file + 1);
-       strbuf_addstr(&filename_template, "git-interpret-trailers-XXXXXX");
-
-       trailers_tempfile = xmks_tempfile_m(filename_template.buf, st.st_mode);
-       strbuf_release(&filename_template);
-       outfile = fdopen_tempfile(trailers_tempfile, "w");
-       if (!outfile)
-               die_errno(_("could not open temporary file"));
-
-       return outfile;
-}
-
-void process_trailers(const char *file,
-                     const struct process_trailer_options *opts,
-                     struct list_head *new_trailer_head)
-{
-       LIST_HEAD(head);
-       struct strbuf sb = STRBUF_INIT;
-       struct trailer_info info;
-       FILE *outfile = stdout;
-
-       ensure_configured();
-
-       read_input_file(&sb, file);
-
-       if (opts->in_place)
-               outfile = create_in_place_tempfile(file);
-
-       parse_trailers(&info, sb.buf, &head, opts);
-
-       /* Print the lines before the trailers */
-       if (!opts->only_trailers)
-               fwrite(sb.buf, 1, info.trailer_block_start, outfile);
-
-       if (!opts->only_trailers && !info.blank_line_before_trailer)
-               fprintf(outfile, "\n");
-
-
-       if (!opts->only_input) {
-               LIST_HEAD(config_head);
-               LIST_HEAD(arg_head);
-               parse_trailers_from_config(&config_head);
-               parse_trailers_from_command_line_args(&arg_head, new_trailer_head);
-               list_splice(&config_head, &arg_head);
-               process_trailers_lists(&head, &arg_head);
-       }
-
-       print_all(outfile, &head, opts);
-
-       free_all(&head);
-       trailer_info_release(&info);
-
-       /* Print the lines after the trailers as is */
-       if (!opts->only_trailers)
-               fwrite(sb.buf + info.trailer_block_end, 1, sb.len - info.trailer_block_end, outfile);
-
-       if (opts->in_place)
-               if (rename_tempfile(&trailers_tempfile, file))
-                       die_errno(_("could not rename temporary file to %s"), file);
-
-       strbuf_release(&sb);
-}
-
-void trailer_info_get(struct trailer_info *info, const char *str,
-                     const struct process_trailer_options *opts)
+void trailer_info_get(const struct process_trailer_options *opts,
+                     const char *str,
+                     struct trailer_info *info)
 {
        size_t end_of_log_message = 0, trailer_block_start = 0;
        struct strbuf **trailer_lines, **ptr;
@@ -1134,7 +1042,7 @@ void trailer_info_get(struct trailer_info *info, const char *str,
        size_t nr = 0, alloc = 0;
        char **last = NULL;
 
-       ensure_configured();
+       trailer_config_init();
 
        end_of_log_message = find_end_of_log_message(str, opts->no_divider);
        trailer_block_start = find_trailer_block_start(str, end_of_log_message);
@@ -1176,23 +1084,13 @@ void trailer_info_release(struct trailer_info *info)
        free(info->trailers);
 }
 
-static void format_trailer_info(struct strbuf *out,
+static void format_trailer_info(const struct process_trailer_options *opts,
                                const struct trailer_info *info,
-                               const char *msg,
-                               const struct process_trailer_options *opts)
+                               struct strbuf *out)
 {
        size_t origlen = out->len;
        size_t i;
 
-       /* If we want the whole block untouched, we can take the fast path. */
-       if (!opts->only_trailers && !opts->unfold && !opts->filter &&
-           !opts->separator && !opts->key_only && !opts->value_only &&
-           !opts->key_value_separator) {
-               strbuf_add(out, msg + info->trailer_block_start,
-                          info->trailer_block_end - info->trailer_block_start);
-               return;
-       }
-
        for (i = 0; i < info->trailer_nr; i++) {
                char *trailer = info->trailers[i];
                ssize_t separator_pos = find_separator(trailer, separators);
@@ -1237,13 +1135,25 @@ static void format_trailer_info(struct strbuf *out,
 
 }
 
-void format_trailers_from_commit(struct strbuf *out, const char *msg,
-                                const struct process_trailer_options *opts)
+void format_trailers_from_commit(const struct process_trailer_options *opts,
+                                const char *msg,
+                                struct strbuf *out)
 {
+       LIST_HEAD(trailer_objects);
        struct trailer_info info;
 
-       trailer_info_get(&info, msg, opts);
-       format_trailer_info(out, &info, msg, opts);
+       parse_trailers(opts, &info, msg, &trailer_objects);
+
+       /* If we want the whole block untouched, we can take the fast path. */
+       if (!opts->only_trailers && !opts->unfold && !opts->filter &&
+           !opts->separator && !opts->key_only && !opts->value_only &&
+           !opts->key_value_separator) {
+               strbuf_add(out, msg + info.trailer_block_start,
+                          info.trailer_block_end - info.trailer_block_start);
+       } else
+               format_trailer_info(opts, &info, out);
+
+       free_trailers(&trailer_objects);
        trailer_info_release(&info);
 }
 
@@ -1253,7 +1163,7 @@ void trailer_iterator_init(struct trailer_iterator *iter, const char *msg)
        strbuf_init(&iter->key, 0);
        strbuf_init(&iter->val, 0);
        opts.no_divider = 1;
-       trailer_info_get(&iter->internal.info, msg, &opts);
+       trailer_info_get(&opts, msg, &iter->internal.info);
        iter->internal.cur = 0;
 }
 
@@ -1270,6 +1180,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter)
                strbuf_reset(&iter->val);
                parse_trailer(&iter->key, &iter->val, NULL,
                              trailer, separator_pos);
+               /* Always unfold values during iteration. */
                unfold_value(&iter->val);
                return 1;
        }
index 1644cd05f60d9f3ceb89ffa66fb5c5b3da9e5cd4..1d106b6dd403b7755e4c81a1a40c1eea8eeae1d6 100644 (file)
--- a/trailer.h
+++ b/trailer.h
@@ -81,15 +81,31 @@ struct process_trailer_options {
 
 #define PROCESS_TRAILER_OPTIONS_INIT {0}
 
-void process_trailers(const char *file,
-                     const struct process_trailer_options *opts,
-                     struct list_head *new_trailer_head);
+void parse_trailers_from_config(struct list_head *config_head);
 
-void trailer_info_get(struct trailer_info *info, const char *str,
-                     const struct process_trailer_options *opts);
+void parse_trailers_from_command_line_args(struct list_head *arg_head,
+                                          struct list_head *new_trailer_head);
+
+void process_trailers_lists(struct list_head *head,
+                           struct list_head *arg_head);
+
+void parse_trailers(const struct process_trailer_options *,
+                   struct trailer_info *,
+                   const char *str,
+                   struct list_head *head);
+
+void trailer_info_get(const struct process_trailer_options *,
+                     const char *str,
+                     struct trailer_info *);
 
 void trailer_info_release(struct trailer_info *info);
 
+void trailer_config_init(void);
+void format_trailers(const struct process_trailer_options *,
+                    struct list_head *trailers,
+                    struct strbuf *out);
+void free_trailers(struct list_head *);
+
 /*
  * Format the trailers from the commit msg "msg" into the strbuf "out".
  * Note two caveats about "opts":
@@ -101,8 +117,9 @@ void trailer_info_release(struct trailer_info *info);
  *     only the trailer block itself, even if the "only_trailers" option is not
  *     set.
  */
-void format_trailers_from_commit(struct strbuf *out, const char *msg,
-                                const struct process_trailer_options *opts);
+void format_trailers_from_commit(const struct process_trailer_options *opts,
+                                const char *msg,
+                                struct strbuf *out);
 
 /*
  * An interface for iterating over the trailers found in a particular commit
index dd6002b393738df81c7ecfc85deb4ed0abe4943c..b660b7942f9f9dbfc76193968d3511047b8afd84 100644 (file)
@@ -1078,7 +1078,7 @@ static int push_refs_with_export(struct transport *transport,
        set_common_push_options(transport, data->name, flags);
        if (flags & TRANSPORT_PUSH_FORCE) {
                if (set_helper_option(transport, "force", "true") != 0)
-                       warning(_("helper %s does not support 'force'"), data->name);
+                       warning(_("helper %s does not support '--force'"), data->name);
        }
 
        helper = get_helper(transport);
index b517792ba23a2104f5f8207519e64cbc5d2daaa4..690fa6569bd7fe03ca104e3e789fd67b58e41270 100644 (file)
@@ -100,7 +100,7 @@ void *fill_tree_descriptor(struct repository *r,
        if (oid) {
                buf = read_object_with_reference(r, oid, OBJ_TREE, &size, NULL);
                if (!buf)
-                       die("unable to read tree %s", oid_to_hex(oid));
+                       die(_("unable to read tree (%s)"), oid_to_hex(oid));
        }
        init_tree_desc(desc, buf, size);
        return buf;
index 6e0d441ef523edaeca10ffdf2e13f8d52ee592d0..902144b9d3470b9a603a584f7f4207511b15dc2b 100644 (file)
@@ -28,6 +28,7 @@
 #include "shallow.h"
 #include "write-or-die.h"
 #include "json-writer.h"
+#include "strmap.h"
 
 /* Remember to update object flag allocation in object.h */
 #define THEY_HAVE      (1u << 11)
@@ -61,12 +62,11 @@ struct upload_pack_data {
        struct string_list symref;                              /* v0 only */
        struct object_array want_obj;
        struct object_array have_obj;
-       struct oid_array haves;                                 /* v2 only */
-       struct string_list wanted_refs;                         /* v2 only */
+       struct strmap wanted_refs;                              /* v2 only */
        struct strvec hidden_refs;
 
        struct object_array shallows;
-       struct string_list deepen_not;
+       struct oidset deepen_not;
        struct object_array extra_edge_obj;
        int depth;
        timestamp_t deepen_since;
@@ -113,6 +113,8 @@ struct upload_pack_data {
        unsigned done : 1;                                      /* v2 only */
        unsigned allow_ref_in_want : 1;                         /* v2 only */
        unsigned allow_sideband_all : 1;                        /* v2 only */
+       unsigned seen_haves : 1;                                /* v2 only */
+       unsigned allow_packfile_uris : 1;                       /* v2 only */
        unsigned advertise_sid : 1;
        unsigned sent_capabilities : 1;
 };
@@ -120,13 +122,12 @@ struct upload_pack_data {
 static void upload_pack_data_init(struct upload_pack_data *data)
 {
        struct string_list symref = STRING_LIST_INIT_DUP;
-       struct string_list wanted_refs = STRING_LIST_INIT_DUP;
+       struct strmap wanted_refs = STRMAP_INIT;
        struct strvec hidden_refs = STRVEC_INIT;
        struct object_array want_obj = OBJECT_ARRAY_INIT;
        struct object_array have_obj = OBJECT_ARRAY_INIT;
-       struct oid_array haves = OID_ARRAY_INIT;
        struct object_array shallows = OBJECT_ARRAY_INIT;
-       struct string_list deepen_not = STRING_LIST_INIT_DUP;
+       struct oidset deepen_not = OID_ARRAY_INIT;
        struct string_list uri_protocols = STRING_LIST_INIT_DUP;
        struct object_array extra_edge_obj = OBJECT_ARRAY_INIT;
        struct string_list allowed_filters = STRING_LIST_INIT_DUP;
@@ -137,7 +138,6 @@ static void upload_pack_data_init(struct upload_pack_data *data)
        data->hidden_refs = hidden_refs;
        data->want_obj = want_obj;
        data->have_obj = have_obj;
-       data->haves = haves;
        data->shallows = shallows;
        data->deepen_not = deepen_not;
        data->uri_protocols = uri_protocols;
@@ -155,13 +155,12 @@ static void upload_pack_data_init(struct upload_pack_data *data)
 static void upload_pack_data_clear(struct upload_pack_data *data)
 {
        string_list_clear(&data->symref, 1);
-       string_list_clear(&data->wanted_refs, 1);
+       strmap_clear(&data->wanted_refs, 1);
        strvec_clear(&data->hidden_refs);
        object_array_clear(&data->want_obj);
        object_array_clear(&data->have_obj);
-       oid_array_clear(&data->haves);
        object_array_clear(&data->shallows);
-       string_list_clear(&data->deepen_not, 0);
+       oidset_clear(&data->deepen_not);
        object_array_clear(&data->extra_edge_obj);
        list_objects_filter_release(&data->filter_options);
        string_list_clear(&data->allowed_filters, 0);
@@ -471,7 +470,9 @@ static void create_pack_file(struct upload_pack_data *pack_data,
 static int do_got_oid(struct upload_pack_data *data, const struct object_id *oid)
 {
        int we_knew_they_have = 0;
-       struct object *o = parse_object(the_repository, oid);
+       struct object *o = parse_object_with_flags(the_repository, oid,
+                                                  PARSE_OBJECT_SKIP_HASH_CHECK |
+                                                  PARSE_OBJECT_DISCARD_TREE);
 
        if (!o)
                die("oops (%s)", oid_to_hex(oid));
@@ -528,8 +529,6 @@ static int get_common_commits(struct upload_pack_data *data,
        int got_other = 0;
        int sent_ready = 0;
 
-       save_commit_buffer = 0;
-
        for (;;) {
                const char *arg;
 
@@ -926,12 +925,13 @@ static int send_shallow_list(struct upload_pack_data *data)
                strvec_push(&av, "rev-list");
                if (data->deepen_since)
                        strvec_pushf(&av, "--max-age=%"PRItime, data->deepen_since);
-               if (data->deepen_not.nr) {
+               if (oidset_size(&data->deepen_not)) {
+                       const struct object_id *oid;
+                       struct oidset_iter iter;
                        strvec_push(&av, "--not");
-                       for (i = 0; i < data->deepen_not.nr; i++) {
-                               struct string_list_item *s = data->deepen_not.items + i;
-                               strvec_push(&av, s->string);
-                       }
+                       oidset_iter_init(&data->deepen_not, &iter);
+                       while ((oid = oidset_iter_next(&iter)))
+                               strvec_push(&av, oid_to_hex(oid));
                        strvec_push(&av, "--not");
                }
                for (i = 0; i < data->want_obj.nr; i++) {
@@ -1007,7 +1007,7 @@ static int process_deepen_since(const char *line, timestamp_t *deepen_since, int
        return 0;
 }
 
-static int process_deepen_not(const char *line, struct string_list *deepen_not, int *deepen_rev_list)
+static int process_deepen_not(const char *line, struct oidset *deepen_not, int *deepen_rev_list)
 {
        const char *arg;
        if (skip_prefix(line, "deepen-not ", &arg)) {
@@ -1015,7 +1015,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
                struct object_id oid;
                if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
                        die("git upload-pack: ambiguous deepen-not: %s", line);
-               string_list_append(deepen_not, ref);
+               oidset_insert(deepen_not, &oid);
                free(ref);
                *deepen_rev_list = 1;
                return 1;
@@ -1151,7 +1151,9 @@ static void receive_needs(struct upload_pack_data *data,
                        free(client_sid);
                }
 
-               o = parse_object(the_repository, &oid_buf);
+               o = parse_object_with_flags(the_repository, &oid_buf,
+                                           PARSE_OBJECT_SKIP_HASH_CHECK |
+                                           PARSE_OBJECT_DISCARD_TREE);
                if (!o) {
                        packet_writer_error(&data->writer,
                                            "upload-pack: not our ref %s",
@@ -1362,6 +1364,9 @@ static int upload_pack_config(const char *var, const char *value,
                data->allow_ref_in_want = git_config_bool(var, value);
        } else if (!strcmp("uploadpack.allowsidebandall", var)) {
                data->allow_sideband_all = git_config_bool(var, value);
+       } else if (!strcmp("uploadpack.blobpackfileuri", var)) {
+               if (value)
+                       data->allow_packfile_uris = 1;
        } else if (!strcmp("core.precomposeunicode", var)) {
                precomposed_unicode = git_config_bool(var, value);
        } else if (!strcmp("transfer.advertisesid", var)) {
@@ -1385,10 +1390,13 @@ static int upload_pack_protected_config(const char *var, const char *value,
        return 0;
 }
 
-static void get_upload_pack_config(struct upload_pack_data *data)
+static void get_upload_pack_config(struct repository *r,
+                                  struct upload_pack_data *data)
 {
-       git_config(upload_pack_config, data);
+       repo_config(r, upload_pack_config, data);
        git_protected_config(upload_pack_protected_config, data);
+
+       data->allow_sideband_all |= git_env_bool("GIT_TEST_SIDEBAND_ALL", 0);
 }
 
 void upload_pack(const int advertise_refs, const int stateless_rpc,
@@ -1398,7 +1406,7 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
        struct upload_pack_data data;
 
        upload_pack_data_init(&data);
-       get_upload_pack_config(&data);
+       get_upload_pack_config(the_repository, &data);
 
        data.stateless_rpc = stateless_rpc;
        data.timeout = timeout;
@@ -1468,7 +1476,8 @@ static int parse_want(struct packet_writer *writer, const char *line,
                            "expected to get oid, not '%s'", line);
 
                o = parse_object_with_flags(the_repository, &oid,
-                                           PARSE_OBJECT_SKIP_HASH_CHECK);
+                                           PARSE_OBJECT_SKIP_HASH_CHECK |
+                                           PARSE_OBJECT_DISCARD_TREE);
 
                if (!o) {
                        packet_writer_error(writer,
@@ -1490,14 +1499,13 @@ static int parse_want(struct packet_writer *writer, const char *line,
 }
 
 static int parse_want_ref(struct packet_writer *writer, const char *line,
-                         struct string_list *wanted_refs,
+                         struct strmap *wanted_refs,
                          struct strvec *hidden_refs,
                          struct object_array *want_obj)
 {
        const char *refname_nons;
        if (skip_prefix(line, "want-ref ", &refname_nons)) {
                struct object_id oid;
-               struct string_list_item *item;
                struct object *o = NULL;
                struct strbuf refname = STRBUF_INIT;
 
@@ -1509,8 +1517,11 @@ static int parse_want_ref(struct packet_writer *writer, const char *line,
                }
                strbuf_release(&refname);
 
-               item = string_list_append(wanted_refs, refname_nons);
-               item->util = oiddup(&oid);
+               if (strmap_put(wanted_refs, refname_nons, oiddup(&oid))) {
+                       packet_writer_error(writer, "duplicate want-ref %s",
+                                           refname_nons);
+                       die("duplicate want-ref %s", refname_nons);
+               }
 
                if (!starts_with(refname_nons, "refs/tags/")) {
                        struct commit *commit = lookup_commit_in_graph(the_repository, &oid);
@@ -1532,15 +1543,14 @@ static int parse_want_ref(struct packet_writer *writer, const char *line,
        return 0;
 }
 
-static int parse_have(const char *line, struct oid_array *haves)
+static int parse_have(const char *line, struct upload_pack_data *data)
 {
        const char *arg;
        if (skip_prefix(line, "have ", &arg)) {
                struct object_id oid;
 
-               if (get_oid_hex(arg, &oid))
-                       die("git upload-pack: expected SHA1 object, got '%s'", arg);
-               oid_array_append(haves, &oid);
+               got_oid(data, arg, &oid);
+               data->seen_haves = 1;
                return 1;
        }
 
@@ -1552,13 +1562,13 @@ static void trace2_fetch_info(struct upload_pack_data *data)
        struct json_writer jw = JSON_WRITER_INIT;
 
        jw_object_begin(&jw, 0);
-       jw_object_intmax(&jw, "haves", data->haves.nr);
+       jw_object_intmax(&jw, "haves", data->have_obj.nr);
        jw_object_intmax(&jw, "wants", data->want_obj.nr);
-       jw_object_intmax(&jw, "want-refs", data->wanted_refs.nr);
+       jw_object_intmax(&jw, "want-refs", strmap_get_size(&data->wanted_refs));
        jw_object_intmax(&jw, "depth", data->depth);
        jw_object_intmax(&jw, "shallows", data->shallows.nr);
        jw_object_bool(&jw, "deepen-since", data->deepen_since);
-       jw_object_intmax(&jw, "deepen-not", data->deepen_not.nr);
+       jw_object_intmax(&jw, "deepen-not", oidset_size(&data->deepen_not));
        jw_object_bool(&jw, "deepen-relative", data->deepen_relative);
        if (data->filter_options.choice)
                jw_object_string(&jw, "filter", list_object_filter_config_name(data->filter_options.choice));
@@ -1586,7 +1596,7 @@ static void process_args(struct packet_reader *request,
                                   &data->hidden_refs, &data->want_obj))
                        continue;
                /* process have line */
-               if (parse_have(arg, &data->haves))
+               if (parse_have(arg, data))
                        continue;
 
                /* process args like thin-pack */
@@ -1638,14 +1648,17 @@ static void process_args(struct packet_reader *request,
                        continue;
                }
 
-               if ((git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
-                    data->allow_sideband_all) &&
+               if (data->allow_sideband_all &&
                    !strcmp(arg, "sideband-all")) {
                        data->writer.use_sideband = 1;
                        continue;
                }
 
-               if (skip_prefix(arg, "packfile-uris ", &p)) {
+               if (data->allow_packfile_uris &&
+                   skip_prefix(arg, "packfile-uris ", &p)) {
+                       if (data->uri_protocols.nr)
+                               send_err_and_die(data,
+                                                "multiple packfile-uris lines forbidden");
                        string_list_split(&data->uri_protocols, p, ',', -1);
                        continue;
                }
@@ -1664,27 +1677,7 @@ static void process_args(struct packet_reader *request,
                trace2_fetch_info(data);
 }
 
-static int process_haves(struct upload_pack_data *data, struct oid_array *common)
-{
-       int i;
-
-       /* Process haves */
-       for (i = 0; i < data->haves.nr; i++) {
-               const struct object_id *oid = &data->haves.oid[i];
-
-               if (!repo_has_object_file_with_flags(the_repository, oid,
-                                                    OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT))
-                       continue;
-
-               oid_array_append(common, oid);
-
-               do_got_oid(data, oid);
-       }
-
-       return 0;
-}
-
-static int send_acks(struct upload_pack_data *data, struct oid_array *acks)
+static int send_acks(struct upload_pack_data *data, struct object_array *acks)
 {
        int i;
 
@@ -1696,7 +1689,7 @@ static int send_acks(struct upload_pack_data *data, struct oid_array *acks)
 
        for (i = 0; i < acks->nr; i++) {
                packet_writer_write(&data->writer, "ACK %s\n",
-                                   oid_to_hex(&acks->oid[i]));
+                                   oid_to_hex(&acks->objects[i].item->oid));
        }
 
        if (!data->wait_for_done && ok_to_give_up(data)) {
@@ -1710,13 +1703,11 @@ static int send_acks(struct upload_pack_data *data, struct oid_array *acks)
 
 static int process_haves_and_send_acks(struct upload_pack_data *data)
 {
-       struct oid_array common = OID_ARRAY_INIT;
        int ret = 0;
 
-       process_haves(data, &common);
        if (data->done) {
                ret = 1;
-       } else if (send_acks(data, &common)) {
+       } else if (send_acks(data, &data->have_obj)) {
                packet_writer_delim(&data->writer);
                ret = 1;
        } else {
@@ -1725,24 +1716,23 @@ static int process_haves_and_send_acks(struct upload_pack_data *data)
                ret = 0;
        }
 
-       oid_array_clear(&data->haves);
-       oid_array_clear(&common);
        return ret;
 }
 
 static void send_wanted_ref_info(struct upload_pack_data *data)
 {
-       const struct string_list_item *item;
+       struct hashmap_iter iter;
+       const struct strmap_entry *e;
 
-       if (!data->wanted_refs.nr)
+       if (strmap_empty(&data->wanted_refs))
                return;
 
        packet_writer_write(&data->writer, "wanted-refs\n");
 
-       for_each_string_list_item(item, &data->wanted_refs) {
+       strmap_for_each_entry(&data->wanted_refs, &iter, e) {
                packet_writer_write(&data->writer, "%s %s\n",
-                                   oid_to_hex(item->util),
-                                   item->string);
+                                   oid_to_hex(e->value),
+                                   e->key);
        }
 
        packet_writer_delim(&data->writer);
@@ -1771,7 +1761,7 @@ enum fetch_state {
        FETCH_DONE,
 };
 
-int upload_pack_v2(struct repository *r UNUSED, struct packet_reader *request)
+int upload_pack_v2(struct repository *r, struct packet_reader *request)
 {
        enum fetch_state state = FETCH_PROCESS_ARGS;
        struct upload_pack_data data;
@@ -1780,7 +1770,7 @@ int upload_pack_v2(struct repository *r UNUSED, struct packet_reader *request)
 
        upload_pack_data_init(&data);
        data.use_sideband = LARGE_PACKET_MAX;
-       get_upload_pack_config(&data);
+       get_upload_pack_config(r, &data);
 
        while (state != FETCH_DONE) {
                switch (state) {
@@ -1796,7 +1786,7 @@ int upload_pack_v2(struct repository *r UNUSED, struct packet_reader *request)
                                 * they didn't want anything.
                                 */
                                state = FETCH_DONE;
-                       } else if (data.haves.nr) {
+                       } else if (data.seen_haves) {
                                /*
                                 * Request had 'have' lines, so lets ACK them.
                                 */
@@ -1839,41 +1829,28 @@ int upload_pack_v2(struct repository *r UNUSED, struct packet_reader *request)
 int upload_pack_advertise(struct repository *r,
                          struct strbuf *value)
 {
-       if (value) {
-               int allow_filter_value;
-               int allow_ref_in_want;
-               int allow_sideband_all_value;
-               char *str = NULL;
+       struct upload_pack_data data;
 
+       upload_pack_data_init(&data);
+       get_upload_pack_config(r, &data);
+
+       if (value) {
                strbuf_addstr(value, "shallow wait-for-done");
 
-               if (!repo_config_get_bool(r,
-                                        "uploadpack.allowfilter",
-                                        &allow_filter_value) &&
-                   allow_filter_value)
+               if (data.allow_filter)
                        strbuf_addstr(value, " filter");
 
-               if (!repo_config_get_bool(r,
-                                        "uploadpack.allowrefinwant",
-                                        &allow_ref_in_want) &&
-                   allow_ref_in_want)
+               if (data.allow_ref_in_want)
                        strbuf_addstr(value, " ref-in-want");
 
-               if (git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
-                   (!repo_config_get_bool(r,
-                                          "uploadpack.allowsidebandall",
-                                          &allow_sideband_all_value) &&
-                    allow_sideband_all_value))
+               if (data.allow_sideband_all)
                        strbuf_addstr(value, " sideband-all");
 
-               if (!repo_config_get_string(r,
-                                           "uploadpack.blobpackfileuri",
-                                           &str) &&
-                   str) {
+               if (data.allow_packfile_uris)
                        strbuf_addstr(value, " packfile-uris");
-                       free(str);
-               }
        }
 
+       upload_pack_data_clear(&data);
+
        return 1;
 }
index b5a29083df503e3adfb6f2e4a74e55d4f44514b6..7108a92b52ce06e5674aadfc5c89d05157a9db93 100644 (file)
@@ -1107,12 +1107,15 @@ void wt_status_append_cut_line(struct strbuf *buf)
        strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_char);
 }
 
-void wt_status_add_cut_line(FILE *fp)
+void wt_status_add_cut_line(struct wt_status *s)
 {
        struct strbuf buf = STRBUF_INIT;
 
+       if (s->added_cut_line)
+               return;
+       s->added_cut_line = 1;
        wt_status_append_cut_line(&buf);
-       fputs(buf.buf, fp);
+       fputs(buf.buf, s->fp);
        strbuf_release(&buf);
 }
 
@@ -1143,11 +1146,12 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
         * file (and even the "auto" setting won't work, since it
         * will have checked isatty on stdout). But we then do want
         * to insert the scissor line here to reliably remove the
-        * diff before committing.
+        * diff before committing, if we didn't already include one
+        * before.
         */
        if (s->fp != stdout) {
                rev.diffopt.use_color = 0;
-               wt_status_add_cut_line(s->fp);
+               wt_status_add_cut_line(s);
        }
        if (s->verbose > 1 && s->committable) {
                /* print_updated() printed a header, so do we */
index 819dcad72300c56900ac05f3943d27dd2b9ed7a4..5e99ba47073493aa4ee80a9501dd4375ec903d8f 100644 (file)
@@ -130,6 +130,7 @@ struct wt_status {
        int rename_score;
        int rename_limit;
        enum wt_status_format status_format;
+       unsigned char added_cut_line; /* boolean */
        struct wt_status_state state;
        struct object_id oid_commit; /* when not Initial */
 
@@ -147,7 +148,7 @@ struct wt_status {
 
 size_t wt_status_locate_end(const char *s, size_t len);
 void wt_status_append_cut_line(struct strbuf *buf);
-void wt_status_add_cut_line(FILE *fp);
+void wt_status_add_cut_line(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);