Merge branch 'sb/submodule-cleanup'
authorJunio C Hamano <gitster@pobox.com>
Mon, 20 Aug 2018 19:41:33 +0000 (12:41 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Aug 2018 19:41:33 +0000 (12:41 -0700)
A few preliminary minor clean-ups in the area around submodules.

* sb/submodule-cleanup:
builtin/submodule--helper: remove stray new line
t7410: update to new style

269 files changed:
.gitignore
Documentation/.gitignore
Documentation/Makefile
Documentation/RelNotes/2.19.0.txt
Documentation/config.txt
Documentation/doc-diff [new file with mode: 0755]
Documentation/fetch-options.txt
Documentation/git-cat-file.txt
Documentation/git-config.txt
Documentation/git-range-diff.txt [new file with mode: 0644]
Documentation/git-repack.txt
Documentation/git-update-index.txt
Documentation/pull-fetch-param.txt
Documentation/technical/hash-function-transition.txt
Documentation/technical/partial-clone.txt
Makefile
alloc.c
alloc.h
apply.c
apply.h
archive-tar.c
archive-zip.c
archive.c
archive.h
attr.c
attr.h
bisect.h
blame.c
blame.h
branch.h
builtin.h
builtin/add.c
builtin/am.c
builtin/apply.c
builtin/archive.c
builtin/blame.c
builtin/cat-file.c
builtin/check-attr.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clean.c
builtin/commit.c
builtin/diff-tree.c
builtin/difftool.c
builtin/grep.c
builtin/ls-files.c
builtin/pack-objects.c
builtin/prune-packed.c
builtin/pull.c
builtin/push.c
builtin/range-diff.c [new file with mode: 0644]
builtin/read-tree.c
builtin/repack.c
builtin/rm.c
builtin/send-pack.c
builtin/shortlog.c
builtin/show-branch.c
builtin/submodule--helper.c
builtin/update-index.c
builtin/upload-archive.c
builtin/write-tree.c
bulk-checkin.h
cache-tree.c
cache-tree.h
cache.h
color.c
color.h
column.h
command-list.txt
commit-graph.c
commit-graph.h
compat/mingw.c
compat/precompose_utf8.h
config.c
config.h
connected.h
contrib/completion/git-completion.bash
convert.c
convert.h
csum-file.h
diff-lib.c
diff.c
diff.h
diffcore.h
dir-iterator.h
dir.c
dir.h
entry.c
environment.c
fetch-negotiator.c
fetch-pack.c
fsck.h
fsmonitor.h
git-compat-util.h
git-instaweb.sh
git-mergetool.sh
git-submodule.sh
git.c
gpg-interface.c
gpg-interface.h
help.c
http-backend.c
khash.h
line-range.h
linear-assignment.c [new file with mode: 0644]
linear-assignment.h [new file with mode: 0644]
list-objects-filter.h
list-objects.h
ll-merge.c
ll-merge.h
mailinfo.h
mailmap.h
match-trees.c
merge-recursive.c
merge-recursive.h
notes-merge.h
notes-utils.h
notes.h
object-store.h
object.h
oidmap.h
pack-bitmap.h
pack-objects.h
packfile.c
packfile.h
parse-options.c
patch-ids.h
path.h
pathspec.c
pathspec.h
preload-index.c
pretty.h
range-diff.c [new file with mode: 0644]
range-diff.h [new file with mode: 0644]
reachable.h
read-cache.c
ref-filter.c
reflog-walk.h
refs.c
refs.h
remote-curl.c
remote.c
remote.h
repository.h
rerere.c
rerere.h
resolve-undo.c
resolve-undo.h
revision.c
revision.h
send-pack.h
sequencer.c
sequencer.h
sha1-file.c
sha1collisiondetection
sha1dc/sha1.c
shortlog.h
submodule.c
submodule.h
t/.gitattributes
t/chainlint.sed
t/chainlint/here-doc-close-subshell.expect [new file with mode: 0644]
t/chainlint/here-doc-close-subshell.test [new file with mode: 0644]
t/chainlint/here-doc-multi-line-command-subst.expect [new file with mode: 0644]
t/chainlint/here-doc-multi-line-command-subst.test [new file with mode: 0644]
t/chainlint/here-doc-multi-line-string.expect [new file with mode: 0644]
t/chainlint/here-doc-multi-line-string.test [new file with mode: 0644]
t/chainlint/here-doc.expect
t/chainlint/here-doc.test
t/chainlint/multi-line-nested-command-substitution.expect
t/chainlint/multi-line-nested-command-substitution.test
t/chainlint/multi-line-string.expect
t/chainlint/multi-line-string.test
t/chainlint/nested-here-doc.expect
t/chainlint/nested-here-doc.test
t/chainlint/subshell-here-doc.expect
t/chainlint/subshell-here-doc.test
t/chainlint/t7900-subtree.expect [new file with mode: 0644]
t/chainlint/t7900-subtree.test [new file with mode: 0644]
t/t0008-ignores.sh
t/t0030-stripspace.sh
t/t0060-path-utils.sh
t/t0300-credentials.sh
t/t0410-partial-clone.sh
t/t1006-cat-file.sh
t/t1011-read-tree-sparse-checkout.sh
t/t1015-read-index-unmerged.sh [new file with mode: 0755]
t/t1300-config.sh
t/t1306-xdg-files.sh
t/t1403-show-ref.sh
t/t1507-rev-parse-upstream.sh
t/t2024-checkout-dwim.sh
t/t2025-worktree-add.sh
t/t2202-add-addremove.sh
t/t3001-ls-files-others-exclude.sh
t/t3031-merge-criscross.sh
t/t3070-wildmatch.sh
t/t3201-branch-contains.sh
t/t3206-range-diff.sh [new file with mode: 0755]
t/t3206/history.export [new file with mode: 0644]
t/t3404-rebase-interactive.sh
t/t3418-rebase-continue.sh
t/t3430-rebase-merges.sh
t/t3600-rm.sh
t/t3700-add.sh
t/t3910-mac-os-precompose.sh
t/t4010-diff-pathspec.sh
t/t4015-diff-whitespace.sh
t/t4039-diff-assume-unchanged.sh
t/t4135-apply-weird-filenames.sh
t/t4150-am.sh
t/t4200-rerere.sh
t/t4202-log.sh
t/t4210-log-i18n.sh
t/t5310-pack-bitmaps.sh
t/t5313-pack-bounds-checks.sh
t/t5318-commit-graph.sh
t/t5504-fetch-receive-strict.sh
t/t5505-remote.sh
t/t5510-fetch.sh
t/t5512-ls-remote.sh
t/t5514-fetch-multiple.sh
t/t5516-fetch-push.sh
t/t5520-pull.sh
t/t5533-push-cas.sh
t/t5552-skipping-fetch-negotiator.sh
t/t5562-http-backend-content-length.sh [new file with mode: 0755]
t/t5562/invoke-with-content-length.pl [new file with mode: 0755]
t/t5612-clone-refspec.sh
t/t6000-rev-list-misc.sh
t/t6009-rev-list-parent.sh
t/t6018-rev-list-glob.sh
t/t6019-rev-list-ancestry-path.sh
t/t6020-merge-df.sh
t/t6022-merge-rename.sh
t/t6029-merge-subtree.sh
t/t6042-merge-rename-corner-cases.sh
t/t6060-merge-index.sh
t/t6300-for-each-ref.sh
t/t7004-tag.sh
t/t7006-pager.sh
t/t7030-verify-tag.sh
t/t7063-status-untracked-cache.sh
t/t7102-reset.sh
t/t7106-reset-unborn-branch.sh
t/t7401-submodule-summary.sh
t/t7406-submodule-update.sh
t/t7502-commit.sh
t/t7610-mergetool.sh
t/t7810-grep.sh
t/t9001-send-email.sh
t/t9300-fast-import.sh
t/t9902-completion.sh
t/t9903-bash-prompt.sh
t/test-lib-functions.sh
t/test-lib.sh
tempfile.h
trailer.h
tree-walk.h
unpack-trees.c
unpack-trees.h
url.h
urlmatch.h
userdiff.c
utf8.h
worktree.h
ws.c
wt-status.c
xdiff/xdiffi.c
index 3524803da5d23fe2fcde45cc31c746d4e73a7795..ffceea7d59fd21d5c5deed2c8d14f507bdbf1666 100644 (file)
 /git-pull
 /git-push
 /git-quiltimport
+/git-range-diff
 /git-read-tree
 /git-rebase
 /git-rebase--am
index c7096f11f1e03f5eae463fa23dc7802136097f99..3ef54e0adbad5fbfd4468581037a2dcb9a9a4681 100644 (file)
@@ -12,3 +12,4 @@ cmds-*.txt
 mergetools-*.txt
 manpage-base-url.xsl
 SubmittingPatches.txt
+tmp-doc-diff/
index d079d7c73aca1fd91ac18045aab46b2446f43a16..a42dcfc74599a29bce540a54191b84755c161e05 100644 (file)
@@ -76,6 +76,7 @@ TECH_DOCS += technical/long-running-process-protocol
 TECH_DOCS += technical/pack-format
 TECH_DOCS += technical/pack-heuristics
 TECH_DOCS += technical/pack-protocol
+TECH_DOCS += technical/partial-clone
 TECH_DOCS += technical/protocol-capabilities
 TECH_DOCS += technical/protocol-common
 TECH_DOCS += technical/protocol-v2
index 5075bad51f11cbcc9253c644313b2f0fda2621d4..8f8da9f9c84a91e746cdbe168eb4fa72a4fac780 100644 (file)
@@ -65,6 +65,14 @@ UI, Workflows & Features
  * "git p4 submit" learns to ask its own pre-submit hook if it should
    continue with submitting.
 
+ * The test performed at the receiving end of "git push" to prevent
+   bad objects from entering repository can be customized via
+   receive.fsck.* configuration variables; we now have gained a
+   counterpart to do the same on the "git fetch" side, with
+   fetch.fsck.* configuration variables.
+
+ * "git pull --rebase=interactive" learned "i" as a short-hand for
+   "interactive".
 
 Performance, Internal Implementation, Development Support etc.
 
@@ -193,6 +201,25 @@ Performance, Internal Implementation, Development Support etc.
    failed tests.
    (merge aea8879a6a sg/travis-retrieve-trash-upon-failure later to maint).
 
+ * The parse-options machinery learned to refrain from enclosing
+   placeholder string inside a "<bra" and "ket>" pair automatically
+   without PARSE_OPT_LITERAL_ARGHELP.  Existing help text for option
+   arguments that are not formatted correctly have been identified and
+   fixed.
+   (merge 5f0df44cd7 rs/parse-opt-lithelp later to maint).
+
+ * Noiseword "extern" has been removed from function decls in the
+   header files.
+
+ * A few atoms like %(objecttype) and %(objectsize) in the format
+   specifier of "for-each-ref --format=<format>" can be filled without
+   getting the full contents of the object, but just with the object
+   header.  These cases have been optimized by calling
+   oid_object_info() API (instead of reading and inspecting the data).
+
+ * The end result of documentation update has been made to be
+   inspected more easily to help developers.
+
 
 Fixes since v2.18
 -----------------
@@ -399,6 +426,39 @@ Fixes since v2.18
    bit (and not materializing the file in the working tree).
    (merge 2b75fb601c en/merge-recursive-skip-fix later to maint).
 
+ * The "author-script" file "git rebase -i" creates got broken when
+   we started to move the command away from shell script, which is
+   getting fixed now.
+   (merge 5522bbac20 es/rebase-i-author-script-fix later to maint).
+
+ * The automatic tree-matching in "git merge -s subtree" was broken 5
+   years ago and nobody has noticed since then, which is now fixed.
+   (merge 2ec4150713 jk/merge-subtree-heuristics later to maint).
+
+ * "git fetch $there refs/heads/s" ought to fetch the tip of the
+   branch 's', but when "refs/heads/refs/heads/s", i.e. a branch whose
+   name is "refs/heads/s" exists at the same time, fetched that one
+   instead by mistake.  This has been corrected to honor the usual
+   disambiguation rules for abbreviated refnames.
+   (merge 60650a48c0 jt/refspec-dwim-precedence-fix later to maint).
+
+ * Futureproofing a helper function that can easily be misused.
+   (merge 65bb21e77e es/want-color-fd-defensive later to maint).
+
+ * The http-backend (used for smart-http transport) used to slurp the
+   whole input until EOF, without paying attention to CONTENT_LENGTH
+   that is supplied in the environment and instead expecting the Web
+   server to close the input stream.  This has been fixed.
+   (merge eebfe40962 mk/http-backend-content-length later to maint).
+
+ * "git merge --abort" etc. did not clean things up properly when
+   there were conflicted entries in the index in certain order that
+   are involved in D/F conflicts.  This has been corrected.
+   (merge ad3762042a en/abort-df-conflict-fixes later to maint).
+
+ * "git diff --indent-heuristic" had a bad corner case performance.
+   (merge 301ef85401 sb/indent-heuristic-optim later to maint).
+
  * Code cleanup, docfix, build fix, etc.
    (merge aee9be2ebe sg/update-ref-stdin-cleanup later to maint).
    (merge 037714252f jc/clean-after-sanity-tests later to maint).
@@ -421,3 +481,7 @@ Fixes since v2.18
    (merge ffbd51cc60 nd/pack-objects-threading-doc later to maint).
    (merge e9dac7be60 es/mw-to-git-chain-fix later to maint).
    (merge fe583c6c7a rs/remote-mv-leakfix later to maint).
+   (merge 69885ab015 en/t3031-title-fix later to maint).
+   (merge 8578037bed nd/config-blame-sort later to maint).
+   (merge 8ad169c4ba hn/config-in-code-comment later to maint).
+   (merge b7446fcfdf ar/t4150-am-scissors-test-fix later to maint).
index fd8d27e7618b2c3d29ed0d61ba63b707571752d7..1c78df7b90468db379cbca8790f3cac9a6aef6b3 100644 (file)
@@ -995,23 +995,28 @@ apply.whitespace::
        Tells 'git apply' how to handle whitespaces, in the same way
        as the `--whitespace` option. See linkgit:git-apply[1].
 
-blame.showRoot::
-       Do not treat root commits as boundaries in linkgit:git-blame[1].
-       This option defaults to false.
-
 blame.blankBoundary::
        Show blank commit object name for boundary commits in
        linkgit:git-blame[1]. This option defaults to false.
 
-blame.showEmail::
-       Show the author email instead of author name in linkgit:git-blame[1].
-       This option defaults to false.
+blame.coloring::
+       This determines the coloring scheme to be applied to blame
+       output. It can be 'repeatedLines', 'highlightRecent',
+       or 'none' which is the default.
 
 blame.date::
        Specifies the format used to output dates in linkgit:git-blame[1].
        If unset the iso format is used. For supported values,
        see the discussion of the `--date` option at linkgit:git-log[1].
 
+blame.showEmail::
+       Show the author email instead of author name in linkgit:git-blame[1].
+       This option defaults to false.
+
+blame.showRoot::
+       Do not treat root commits as boundaries in linkgit:git-blame[1].
+       This option defaults to false.
+
 branch.autoSetupMerge::
        Tells 'git branch' and 'git checkout' to set up new branches
        so that linkgit:git-pull[1] will appropriately merge from the
@@ -1149,6 +1154,28 @@ color.advice::
 color.advice.hint::
        Use customized color for hints.
 
+color.blame.highlightRecent::
+       This can be used to color the metadata of a blame line depending
+       on age of the line.
++
+This setting should be set to a comma-separated list of color and date settings,
+starting and ending with a color, the dates should be set from oldest to newest.
+The metadata will be colored given the colors if the the line was introduced
+before the given timestamp, overwriting older timestamped colors.
++
+Instead of an absolute timestamp relative timestamps work as well, e.g.
+2.weeks.ago is valid to address anything older than 2 weeks.
++
+It defaults to 'blue,12 month ago,white,1 month ago,red', which colors
+everything older than one year blue, recent changes between one month and
+one year old are kept white, and lines introduced within the last month are
+colored red.
+
+color.blame.repeatedLines::
+       Use the customized color for the part of git-blame output that
+       is repeated meta information per line (such as commit id,
+       author name, date and timezone). Defaults to cyan.
+
 color.branch::
        A boolean to enable/disable color in the output of
        linkgit:git-branch[1]. May be set to `always`,
@@ -1198,8 +1225,10 @@ color.diff.<slot>::
        (highlighting whitespace errors), `oldMoved` (deleted lines),
        `newMoved` (added lines), `oldMovedDimmed`, `oldMovedAlternative`,
        `oldMovedAlternativeDimmed`, `newMovedDimmed`, `newMovedAlternative`
-       and `newMovedAlternativeDimmed` (See the '<mode>'
-       setting of '--color-moved' in linkgit:git-diff[1] for details).
+       `newMovedAlternativeDimmed` (See the '<mode>'
+       setting of '--color-moved' in linkgit:git-diff[1] for details),
+       `contextDimmed`, `oldDimmed`, `newDimmed`, `contextBold`,
+       `oldBold`, and `newBold` (see linkgit:git-range-diff[1] for details).
 
 color.decorate.<slot>::
        Use customized color for 'git log --decorate' output.  `<slot>` is one
@@ -1296,33 +1325,6 @@ color.status.<slot>::
        status short-format), or
        `unmerged` (files which have unmerged changes).
 
-color.blame.repeatedLines::
-       Use the customized color for the part of git-blame output that
-       is repeated meta information per line (such as commit id,
-       author name, date and timezone). Defaults to cyan.
-
-color.blame.highlightRecent::
-       This can be used to color the metadata of a blame line depending
-       on age of the line.
-+
-This setting should be set to a comma-separated list of color and date settings,
-starting and ending with a color, the dates should be set from oldest to newest.
-The metadata will be colored given the colors if the the line was introduced
-before the given timestamp, overwriting older timestamped colors.
-+
-Instead of an absolute timestamp relative timestamps work as well, e.g.
-2.weeks.ago is valid to address anything older than 2 weeks.
-+
-It defaults to 'blue,12 month ago,white,1 month ago,red', which colors
-everything older than one year blue, recent changes between one month and
-one year old are kept white, and lines introduced within the last month are
-colored red.
-
-blame.coloring::
-       This determines the coloring scheme to be applied to blame
-       output. It can be 'repeatedLines', 'highlightRecent',
-       or 'none' which is the default.
-
 color.transport::
        A boolean to enable/disable color when pushes are rejected. May be
        set to `always`, `false` (or `never`) or `auto` (or `true`), in which
@@ -1502,10 +1504,19 @@ fetch.recurseSubmodules::
 
 fetch.fsckObjects::
        If it is set to true, git-fetch-pack will check all fetched
-       objects. It will abort in the case of a malformed object or a
-       broken link. The result of an abort are only dangling objects.
-       Defaults to false. If not set, the value of `transfer.fsckObjects`
-       is used instead.
+       objects. See `transfer.fsckObjects` for what's
+       checked. Defaults to false. If not set, the value of
+       `transfer.fsckObjects` is used instead.
+
+fetch.fsck.<msg-id>::
+       Acts like `fsck.<msg-id>`, but is used by
+       linkgit:git-fetch-pack[1] instead of linkgit:git-fsck[1]. See
+       the `fsck.<msg-id>` documentation for details.
+
+fetch.fsck.skipList::
+       Acts like `fsck.skipList`, but is used by
+       linkgit:git-fetch-pack[1] instead of linkgit:git-fsck[1]. See
+       the `fsck.skipList` documentation for details.
 
 fetch.unpackLimit::
        If the number of objects fetched over the Git native
@@ -1541,9 +1552,12 @@ fetch.negotiationAlgorithm::
        sent when negotiating the contents of the packfile to be sent by the
        server. Set to "skipping" to use an algorithm that skips commits in an
        effort to converge faster, but may result in a larger-than-necessary
-       packfile; any other value instructs Git to use the default algorithm
+       packfile; The default is "default" which instructs Git to use the default algorithm
        that never skips commits (unless the server has acknowledged it or one
        of its descendants).
+       Unknown values will cause 'git fetch' to error out.
++
+See also the `--negotiation-tip` option for linkgit:git-fetch[1].
 
 format.attach::
        Enable multipart/mixed attachments as the default for
@@ -1644,15 +1658,42 @@ filter.<driver>.smudge::
        linkgit:gitattributes[5] for details.
 
 fsck.<msg-id>::
-       Allows overriding the message type (error, warn or ignore) of a
-       specific message ID such as `missingEmail`.
-+
-For convenience, fsck prefixes the error/warning with the message ID,
-e.g.  "missingEmail: invalid author/committer line - missing email" means
-that setting `fsck.missingEmail = ignore` will hide that issue.
-+
-This feature is intended to support working with legacy repositories
-which cannot be repaired without disruptive changes.
+       During fsck git may find issues with legacy data which
+       wouldn't be generated by current versions of git, and which
+       wouldn't be sent over the wire if `transfer.fsckObjects` was
+       set. This feature is intended to support working with legacy
+       repositories containing such data.
++
+Setting `fsck.<msg-id>` will be picked up by linkgit:git-fsck[1], but
+to accept pushes of such data set `receive.fsck.<msg-id>` instead, or
+to clone or fetch it set `fetch.fsck.<msg-id>`.
++
+The rest of the documentation discusses `fsck.*` for brevity, but the
+same applies for the corresponding `receive.fsck.*` and
+`fetch.<msg-id>.*`. variables.
++
+Unlike variables like `color.ui` and `core.editor` the
+`receive.fsck.<msg-id>` and `fetch.fsck.<msg-id>` variables will not
+fall back on the `fsck.<msg-id>` configuration if they aren't set. To
+uniformly configure the same fsck settings in different circumstances
+all three of them they must all set to the same values.
++
+When `fsck.<msg-id>` is set, errors can be switched to warnings and
+vice versa by configuring the `fsck.<msg-id>` setting where the
+`<msg-id>` is the fsck message ID and the value is one of `error`,
+`warn` or `ignore`. For convenience, fsck prefixes the error/warning
+with the message ID, e.g. "missingEmail: invalid author/committer line
+- missing email" means that setting `fsck.missingEmail = ignore` will
+hide that issue.
++
+In general, it is better to enumerate existing objects with problems
+with `fsck.skipList`, instead of listing the kind of breakages these
+problematic objects share to be ignored, as doing the latter will
+allow new instances of the same breakages go unnoticed.
++
+Setting an unknown `fsck.<msg-id>` value will cause fsck to die, but
+doing the same for `receive.fsck.<msg-id>` and `fetch.fsck.<msg-id>`
+will only cause git to warn.
 
 fsck.skipList::
        The path to a sorted list of object names (i.e. one SHA-1 per
@@ -1661,6 +1702,15 @@ fsck.skipList::
        should be accepted despite early commits containing errors that
        can be safely ignored such as invalid committer email addresses.
        Note: corrupt objects cannot be skipped with this setting.
++
+Like `fsck.<msg-id>` this variable has corresponding
+`receive.fsck.skipList` and `fetch.fsck.skipList` variants.
++
+Unlike variables like `color.ui` and `core.editor` the
+`receive.fsck.skipList` and `fetch.fsck.skipList` variables will not
+fall back on the `fsck.skipList` configuration if they aren't set. To
+uniformly configure the same fsck settings in different circumstances
+all three of them they must all set to the same values.
 
 gc.aggressiveDepth::
        The depth parameter used in the delta compression
@@ -2947,32 +2997,21 @@ receive.certNonceSlop::
 
 receive.fsckObjects::
        If it is set to true, git-receive-pack will check all received
-       objects. It will abort in the case of a malformed object or a
-       broken link. The result of an abort are only dangling objects.
-       Defaults to false. If not set, the value of `transfer.fsckObjects`
-       is used instead.
+       objects. See `transfer.fsckObjects` for what's checked.
+       Defaults to false. If not set, the value of
+       `transfer.fsckObjects` is used instead.
 
 receive.fsck.<msg-id>::
-       When `receive.fsckObjects` is set to true, errors can be switched
-       to warnings and vice versa by configuring the `receive.fsck.<msg-id>`
-       setting where the `<msg-id>` is the fsck message ID and the value
-       is one of `error`, `warn` or `ignore`. For convenience, fsck prefixes
-       the error/warning with the message ID, e.g. "missingEmail: invalid
-       author/committer line - missing email" means that setting
-       `receive.fsck.missingEmail = ignore` will hide that issue.
-+
-This feature is intended to support working with legacy repositories
-which would not pass pushing when `receive.fsckObjects = true`, allowing
-the host to accept repositories with certain known issues but still catch
-other issues.
+       Acts like `fsck.<msg-id>`, but is used by
+       linkgit:git-receive-pack[1] instead of
+       linkgit:git-fsck[1]. See the `fsck.<msg-id>` documentation for
+       details.
 
 receive.fsck.skipList::
-       The path to a sorted list of object names (i.e. one SHA-1 per
-       line) that are known to be broken in a non-fatal way and should
-       be ignored. This feature is useful when an established project
-       should be accepted despite early commits containing errors that
-       can be safely ignored such as invalid committer email addresses.
-       Note: corrupt objects cannot be skipped with this setting.
+       Acts like `fsck.skipList`, but is used by
+       linkgit:git-receive-pack[1] instead of
+       linkgit:git-fsck[1]. See the `fsck.skipList` documentation for
+       details.
 
 receive.keepAlive::
        After receiving the pack from the client, `receive-pack` may
@@ -3447,6 +3486,40 @@ transfer.fsckObjects::
        When `fetch.fsckObjects` or `receive.fsckObjects` are
        not set, the value of this variable is used instead.
        Defaults to false.
++
+When set, the fetch or receive will abort in the case of a malformed
+object or a link to a nonexistent object. In addition, various other
+issues are checked for, including legacy issues (see `fsck.<msg-id>`),
+and potential security issues like the existence of a `.GIT` directory
+or a malicious `.gitmodules` file (see the release notes for v2.2.1
+and v2.17.1 for details). Other sanity and security checks may be
+added in future releases.
++
+On the receiving side, failing fsckObjects will make those objects
+unreachable, see "QUARANTINE ENVIRONMENT" in
+linkgit:git-receive-pack[1]. On the fetch side, malformed objects will
+instead be left unreferenced in the repository.
++
+Due to the non-quarantine nature of the `fetch.fsckObjects`
+implementation it can not be relied upon to leave the object store
+clean like `receive.fsckObjects` can.
++
+As objects are unpacked they're written to the object store, so there
+can be cases where malicious objects get introduced even though the
+"fetch" failed, only to have a subsequent "fetch" succeed because only
+new incoming objects are checked, not those that have already been
+written to the object store. That difference in behavior should not be
+relied upon. In the future, such objects may be quarantined for
+"fetch" as well.
++
+For now, the paranoid need to find some way to emulate the quarantine
+environment if they'd like the same protection as "push". E.g. in the
+case of an internal mirror do the mirroring in two steps, one to fetch
+the untrusted objects, and then do a second "push" (which will use the
+quarantine) to another internal repo, and have internal clients
+consume this pushed-to repository, or embargo internal fetches and
+only allow them once a full "fsck" has run (and no new fetches have
+happened in the meantime).
 
 transfer.hideRefs::
        String(s) `receive-pack` and `upload-pack` use to decide which
diff --git a/Documentation/doc-diff b/Documentation/doc-diff
new file mode 100755 (executable)
index 0000000..f483fe4
--- /dev/null
@@ -0,0 +1,109 @@
+#!/bin/sh
+
+OPTIONS_SPEC="\
+doc-diff [options] <from> <to> [-- <diff-options>]
+--
+j=n    parallel argument to pass to make
+f      force rebuild; do not rely on cached results
+"
+SUBDIRECTORY_OK=1
+. "$(git --exec-path)/git-sh-setup"
+
+parallel=
+force=
+while test $# -gt 0
+do
+       case "$1" in
+       -j)
+               parallel=$2; shift ;;
+       -f)
+               force=t ;;
+       --)
+               shift; break ;;
+       *)
+               usage ;;
+       esac
+       shift
+done
+
+if test -z "$parallel"
+then
+       parallel=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
+       if test $? != 0 || test -z "$parallel"
+       then
+               parallel=1
+       fi
+fi
+
+test $# -gt 1 || usage
+from=$1; shift
+to=$1; shift
+
+from_oid=$(git rev-parse --verify "$from") || exit 1
+to_oid=$(git rev-parse --verify "$to") || exit 1
+
+cd_to_toplevel
+tmp=Documentation/tmp-doc-diff
+
+if test -n "$force"
+then
+       rm -rf "$tmp"
+fi
+
+# We'll do both builds in a single worktree, which lets "make" reuse
+# results that don't differ between the two trees.
+if ! test -d "$tmp/worktree"
+then
+       git worktree add --detach "$tmp/worktree" "$from" &&
+       dots=$(echo "$tmp/worktree" | sed 's#[^/]*#..#g') &&
+       ln -s "$dots/config.mak" "$tmp/worktree/config.mak"
+fi
+
+# generate_render_makefile <srcdir> <dstdir>
+generate_render_makefile () {
+       find "$1" -type f |
+       while read src
+       do
+               dst=$2/${src#$1/}
+               printf 'all:: %s\n' "$dst"
+               printf '%s: %s\n' "$dst" "$src"
+               printf '\t@echo >&2 "  RENDER $(notdir $@)" && \\\n'
+               printf '\tmkdir -p $(dir $@) && \\\n'
+               printf '\tMANWIDTH=80 man -l $< >$@+ && \\\n'
+               printf '\tmv $@+ $@\n'
+       done
+}
+
+# render_tree <dirname> <committish>
+render_tree () {
+       # Skip install-man entirely if we already have an installed directory.
+       # We can't rely on make here, since "install-man" unconditionally
+       # copies the files (spending effort, but also updating timestamps that
+       # we then can't rely on during the render step). We use "mv" to make
+       # sure we don't get confused by a previous run that failed partway
+       # through.
+       if ! test -d "$tmp/installed/$1"
+       then
+               git -C "$tmp/worktree" checkout "$2" &&
+               make -j$parallel -C "$tmp/worktree" \
+                       GIT_VERSION=omitted \
+                       SOURCE_DATE_EPOCH=0 \
+                       DESTDIR="$PWD/$tmp/installed/$1+" \
+                       install-man &&
+               mv "$tmp/installed/$1+" "$tmp/installed/$1"
+       fi &&
+
+       # As with "installed" above, we skip the render if it's already been
+       # done.  So using make here is primarily just about running in
+       # parallel.
+       if ! test -d "$tmp/rendered/$1"
+       then
+               generate_render_makefile "$tmp/installed/$1" "$tmp/rendered/$1+" |
+               make -j$parallel -f - &&
+               mv "$tmp/rendered/$1+" "$tmp/rendered/$1"
+       fi
+}
+
+render_tree $from_oid "$from" &&
+render_tree $to_oid "$to" &&
+git -C $tmp/rendered diff --no-index "$@" $from_oid $to_oid
index 2d09f87b4b38dbb98e0e1e5e341e09e5f84ece17..8bc36af4b1b10375c81c6f700ea300cee2295cc1 100644 (file)
@@ -57,6 +57,9 @@ commits reachable from any of the given commits.
 The argument to this option may be a glob on ref names, a ref, or the (possibly
 abbreviated) SHA-1 of a commit. Specifying a glob is equivalent to specifying
 this option multiple times, one for each matching ref name.
++
+See also the `fetch.negotiationAlgorithm` configuration variable
+documented in linkgit:git-config[1].
 
 ifndef::git-pull[]
 --dry-run::
index f90f09b03fae578e867335d1be3ab85d83195f27..74013335a1ccd18228a53acbd8dd7f5fe1ab40ca 100644 (file)
@@ -104,6 +104,16 @@ OPTIONS
        buffering; this is much more efficient when invoking
        `--batch-check` on a large number of objects.
 
+--unordered::
+       When `--batch-all-objects` is in use, visit objects in an
+       order which may be more efficient for accessing the object
+       contents than hash order. The exact details of the order are
+       unspecified, but if you do not require a specific order, this
+       should generally result in faster output, especially with
+       `--batch`.  Note that `cat-file` will still show each object
+       only once, even if it is stored multiple times in the
+       repository.
+
 --allow-unknown-type::
        Allow -s or -t to query broken/corrupt objects of unknown type.
 
index 18ddc78f42d69724cf5a04087a7dbd13c5ebf711..8e240435bee8fb9599fc979a5dab48742d7e1e1d 100644 (file)
@@ -453,6 +453,27 @@ http.sslverify false
 
 include::config.txt[]
 
+BUGS
+----
+When using the deprecated `[section.subsection]` syntax, changing a value
+will result in adding a multi-line key instead of a change, if the subsection
+is given with at least one uppercase character. For example when the config
+looks like
+
+--------
+  [section.subsection]
+    key = value1
+--------
+
+and running `git config section.Subsection.key value2` will result in
+
+--------
+  [section.subsection]
+    key = value1
+    key = value2
+--------
+
+
 GIT
 ---
 Part of the linkgit:git[1] suite
diff --git a/Documentation/git-range-diff.txt b/Documentation/git-range-diff.txt
new file mode 100644 (file)
index 0000000..f693930
--- /dev/null
@@ -0,0 +1,252 @@
+git-range-diff(1)
+=================
+
+NAME
+----
+git-range-diff - Compare two commit ranges (e.g. two versions of a branch)
+
+SYNOPSIS
+--------
+[verse]
+'git range-diff' [--color=[<when>]] [--no-color] [<diff-options>]
+       [--no-dual-color] [--creation-factor=<factor>]
+       ( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> )
+
+DESCRIPTION
+-----------
+
+This command shows the differences between two versions of a patch
+series, or more generally, two commit ranges (ignoring merge commits).
+
+To that end, it first finds pairs of commits from both commit ranges
+that correspond with each other. Two commits are said to correspond when
+the diff between their patches (i.e. the author information, the commit
+message and the commit diff) is reasonably small compared to the
+patches' size. See ``Algorithm`` below for details.
+
+Finally, the list of matching commits is shown in the order of the
+second commit range, with unmatched commits being inserted just after
+all of their ancestors have been shown.
+
+
+OPTIONS
+-------
+--no-dual-color::
+       When the commit diffs differ, `git range-diff` recreates the
+       original diffs' coloring, and adds outer -/+ diff markers with
+       the *background* being red/green to make it easier to see e.g.
+       when there was a change in what exact lines were added.
++
+Additionally, the commit diff lines that are only present in the first commit
+range are shown "dimmed" (this can be overridden using the `color.diff.<slot>`
+config setting where `<slot>` is one of `contextDimmed`, `oldDimmed` and
+`newDimmed`), and the commit diff lines that are only present in the second
+commit range are shown in bold (which can be overridden using the config
+settings `color.diff.<slot>` with `<slot>` being one of `contextBold`,
+`oldBold` or `newBold`).
++
+This is known to `range-diff` as "dual coloring". Use `--no-dual-color`
+to revert to color all lines according to the outer diff markers
+(and completely ignore the inner diff when it comes to color).
+
+--creation-factor=<percent>::
+       Set the creation/deletion cost fudge factor to `<percent>`.
+       Defaults to 60. Try a larger value if `git range-diff` erroneously
+       considers a large change a total rewrite (deletion of one commit
+       and addition of another), and a smaller one in the reverse case.
+       See the ``Algorithm`` section below for an explanation why this is
+       needed.
+
+<range1> <range2>::
+       Compare the commits specified by the two ranges, where
+       `<range1>` is considered an older version of `<range2>`.
+
+<rev1>...<rev2>::
+       Equivalent to passing `<rev2>..<rev1>` and `<rev1>..<rev2>`.
+
+<base> <rev1> <rev2>::
+       Equivalent to passing `<base>..<rev1>` and `<base>..<rev2>`.
+       Note that `<base>` does not need to be the exact branch point
+       of the branches. Example: after rebasing a branch `my-topic`,
+       `git range-diff my-topic@{u} my-topic@{1} my-topic` would
+       show the differences introduced by the rebase.
+
+`git range-diff` also accepts the regular diff options (see
+linkgit:git-diff[1]), most notably the `--color=[<when>]` and
+`--no-color` options. These options are used when generating the "diff
+between patches", i.e. to compare the author, commit message and diff of
+corresponding old/new commits. There is currently no means to tweak the
+diff options passed to `git log` when generating those patches.
+
+
+CONFIGURATION
+-------------
+This command uses the `diff.color.*` and `pager.range-diff` settings
+(the latter is on by default).
+See linkgit:git-config[1].
+
+
+EXAMPLES
+--------
+
+When a rebase required merge conflicts to be resolved, compare the changes
+introduced by the rebase directly afterwards using:
+
+------------
+$ git range-diff @{u} @{1} @
+------------
+
+
+A typical output of `git range-diff` would look like this:
+
+------------
+-:  ------- > 1:  0ddba11 Prepare for the inevitable!
+1:  c0debee = 2:  cab005e Add a helpful message at the start
+2:  f00dbal ! 3:  decafe1 Describe a bug
+    @@ -1,3 +1,3 @@
+     Author: A U Thor <author@example.com>
+
+    -TODO: Describe a bug
+    +Describe a bug
+    @@ -324,5 +324,6
+      This is expected.
+
+    -+What is unexpected is that it will also crash.
+    ++Unexpectedly, it also crashes. This is a bug, and the jury is
+    ++still out there how to fix it best. See ticket #314 for details.
+
+      Contact
+3:  bedead < -:  ------- TO-UNDO
+------------
+
+In this example, there are 3 old and 3 new commits, where the developer
+removed the 3rd, added a new one before the first two, and modified the
+commit message of the 2nd commit as well its diff.
+
+When the output goes to a terminal, it is color-coded by default, just
+like regular `git diff`'s output. In addition, the first line (adding a
+commit) is green, the last line (deleting a commit) is red, the second
+line (with a perfect match) is yellow like the commit header of `git
+show`'s output, and the third line colors the old commit red, the new
+one green and the rest like `git show`'s commit header.
+
+A naive color-coded diff of diffs is actually a bit hard to read,
+though, as it colors the entire lines red or green. The line that added
+"What is unexpected" in the old commit, for example, is completely red,
+even if the intent of the old commit was to add something.
+
+To help with that, `range` uses the `--dual-color` mode by default. In
+this mode, the diff of diffs will retain the original diff colors, and
+prefix the lines with -/+ markers that have their *background* red or
+green, to make it more obvious that they describe how the diff itself
+changed.
+
+
+Algorithm
+---------
+
+The general idea is this: we generate a cost matrix between the commits
+in both commit ranges, then solve the least-cost assignment.
+
+The cost matrix is populated thusly: for each pair of commits, both
+diffs are generated and the "diff of diffs" is generated, with 3 context
+lines, then the number of lines in that diff is used as cost.
+
+To avoid false positives (e.g. when a patch has been removed, and an
+unrelated patch has been added between two iterations of the same patch
+series), the cost matrix is extended to allow for that, by adding
+fixed-cost entries for wholesale deletes/adds.
+
+Example: Let commits `1--2` be the first iteration of a patch series and
+`A--C` the second iteration. Let's assume that `A` is a cherry-pick of
+`2,` and `C` is a cherry-pick of `1` but with a small modification (say,
+a fixed typo). Visualize the commits as a bipartite graph:
+
+------------
+    1            A
+
+    2            B
+
+                C
+------------
+
+We are looking for a "best" explanation of the new series in terms of
+the old one. We can represent an "explanation" as an edge in the graph:
+
+
+------------
+    1            A
+              /
+    2 --------'  B
+
+                C
+------------
+
+This explanation comes for "free" because there was no change. Similarly
+`C` could be explained using `1`, but that comes at some cost c>0
+because of the modification:
+
+------------
+    1 ----.      A
+         |    /
+    2 ----+---'  B
+         |
+         `----- C
+         c>0
+------------
+
+In mathematical terms, what we are looking for is some sort of a minimum
+cost bipartite matching; `1` is matched to `C` at some cost, etc. The
+underlying graph is in fact a complete bipartite graph; the cost we
+associate with every edge is the size of the diff between the two
+commits' patches. To explain also new commits, we introduce dummy nodes
+on both sides:
+
+------------
+    1 ----.      A
+         |    /
+    2 ----+---'  B
+         |
+    o     `----- C
+         c>0
+    o            o
+
+    o            o
+------------
+
+The cost of an edge `o--C` is the size of `C`'s diff, modified by a
+fudge factor that should be smaller than 100%. The cost of an edge
+`o--o` is free. The fudge factor is necessary because even if `1` and
+`C` have nothing in common, they may still share a few empty lines and
+such, possibly making the assignment `1--C`, `o--o` slightly cheaper
+than `1--o`, `o--C` even if `1` and `C` have nothing in common. With the
+fudge factor we require a much larger common part to consider patches as
+corresponding.
+
+The overall time needed to compute this algorithm is the time needed to
+compute n+m commit diffs and then n*m diffs of patches, plus the time
+needed to compute the least-cost assigment between n and m diffs. Git
+uses an implementation of the Jonker-Volgenant algorithm to solve the
+assignment problem, which has cubic runtime complexity. The matching
+found in this case will look like this:
+
+------------
+    1 ----.      A
+         |    /
+    2 ----+---'  B
+       .--+-----'
+    o -'  `----- C
+         c>0
+    o ---------- o
+
+    o ---------- o
+------------
+
+
+SEE ALSO
+--------
+linkgit:git-log[1]
+
+GIT
+---
+Part of the linkgit:git[1] suite
index d90e7907f4843a048caf11a2fae42a973d893d9a..d056250968e13953bd8bc7dae71e745336788e38 100644 (file)
@@ -40,6 +40,11 @@ OPTIONS
 Note that users fetching over dumb protocols will have to fetch the
 whole new pack in order to get any contained object, no matter how many
 other objects in that pack they already have locally.
++
+Promisor packfiles are repacked separately: if there are packfiles that
+have an associated ".promisor" file, these packfiles will be repacked
+into another separate pack, and an empty ".promisor" file corresponding
+to the new separate pack will be written.
 
 -A::
        Same as `-a`, unless `-d` is used.  Then any unreachable
index 4e8e762e68690cab880460fbe1fef0077c8351e2..1c4d146a41ce091755b2e4baef0fa79f45a4b515 100644 (file)
@@ -245,10 +245,10 @@ USING --CACHEINFO OR --INFO-ONLY
 current working directory.  This is useful for minimum-checkout
 merging.
 
-To pretend you have a file with mode and sha1 at path, say:
+To pretend you have a file at path with mode and sha1, say:
 
 ----------------
-$ git update-index --cacheinfo <mode>,<sha1>,<path>
+$ git update-index --add --cacheinfo <mode>,<sha1>,<path>
 ----------------
 
 `--info-only` is used to register files without placing them in the object
@@ -268,23 +268,20 @@ USING --INDEX-INFO
 multiple entry definitions from the standard input, and designed
 specifically for scripts.  It can take inputs of three formats:
 
-    . mode         SP sha1          TAB path
-+
-The first format is what "git-apply --index-info"
-reports, and used to reconstruct a partial tree
-that is used for phony merge base tree when falling
-back on 3-way merge.
-
     . mode SP type SP sha1          TAB path
 +
-The second format is to stuff 'git ls-tree' output
-into the index file.
+This format is to stuff `git ls-tree` output into the index.
 
     . mode         SP sha1 SP stage TAB path
 +
 This format is to put higher order stages into the
 index file and matches 'git ls-files --stage' output.
 
+    . mode         SP sha1          TAB path
++
+This format is no longer produced by any Git command, but is
+and will continue to be supported by `update-index --index-info`.
+
 To place a higher stage entry to the index, the path should
 first be removed by feeding a mode=0 entry for the path, and
 then feeding necessary input lines in the third format.
index c579793af5b41a01fecda884c514ff78bf25672a..f1fb08dc683778b2ebddd4a92c8d3d5d17ee4b7f 100644 (file)
@@ -33,7 +33,7 @@ name.
 it requests fetching everything up to the given tag.
 +
 The remote ref that matches <src>
-is fetched, and if <dst> is not empty string, the local
+is fetched, and if <dst> is not an empty string, the local
 ref that matches it is fast-forwarded using <src>.
 If the optional plus `+` is used, the local ref
 is updated even if it does not result in a fast-forward
index 4ab6cd1012abae711acf02e6a76ee93eae86a1ad..bc2ace2a6e0563f655fedb5681307b43c98cedc7 100644 (file)
@@ -59,14 +59,11 @@ that are believed to be cryptographically secure.
 
 Goals
 -----
-Where NewHash is a strong 256-bit hash function to replace SHA-1 (see
-"Selection of a New Hash", below):
-
-1. The transition to NewHash can be done one local repository at a time.
+1. The transition to SHA-256 can be done one local repository at a time.
    a. Requiring no action by any other party.
-   b. A NewHash repository can communicate with SHA-1 Git servers
+   b. A SHA-256 repository can communicate with SHA-1 Git servers
       (push/fetch).
-   c. Users can use SHA-1 and NewHash identifiers for objects
+   c. Users can use SHA-1 and SHA-256 identifiers for objects
       interchangeably (see "Object names on the command line", below).
    d. New signed objects make use of a stronger hash function than
       SHA-1 for their security guarantees.
@@ -79,7 +76,7 @@ Where NewHash is a strong 256-bit hash function to replace SHA-1 (see
 
 Non-Goals
 ---------
-1. Add NewHash support to Git protocol. This is valuable and the
+1. Add SHA-256 support to Git protocol. This is valuable and the
    logical next step but it is out of scope for this initial design.
 2. Transparently improving the security of existing SHA-1 signed
    objects.
@@ -87,26 +84,26 @@ Non-Goals
    repository.
 4. Taking the opportunity to fix other bugs in Git's formats and
    protocols.
-5. Shallow clones and fetches into a NewHash repository. (This will
-   change when we add NewHash support to Git protocol.)
-6. Skip fetching some submodules of a project into a NewHash
-   repository. (This also depends on NewHash support in Git
+5. Shallow clones and fetches into a SHA-256 repository. (This will
+   change when we add SHA-256 support to Git protocol.)
+6. Skip fetching some submodules of a project into a SHA-256
+   repository. (This also depends on SHA-256 support in Git
    protocol.)
 
 Overview
 --------
 We introduce a new repository format extension. Repositories with this
-extension enabled use NewHash instead of SHA-1 to name their objects.
+extension enabled use SHA-256 instead of SHA-1 to name their objects.
 This affects both object names and object content --- both the names
 of objects and all references to other objects within an object are
 switched to the new hash function.
 
-NewHash repositories cannot be read by older versions of Git.
+SHA-256 repositories cannot be read by older versions of Git.
 
-Alongside the packfile, a NewHash repository stores a bidirectional
-mapping between NewHash and SHA-1 object names. The mapping is generated
+Alongside the packfile, a SHA-256 repository stores a bidirectional
+mapping between SHA-256 and SHA-1 object names. The mapping is generated
 locally and can be verified using "git fsck". Object lookups use this
-mapping to allow naming objects using either their SHA-1 and NewHash names
+mapping to allow naming objects using either their SHA-1 and SHA-256 names
 interchangeably.
 
 "git cat-file" and "git hash-object" gain options to display an object
@@ -116,7 +113,7 @@ object database so that they can be named using the appropriate name
 (using the bidirectional hash mapping).
 
 Fetches from a SHA-1 based server convert the fetched objects into
-NewHash form and record the mapping in the bidirectional mapping table
+SHA-256 form and record the mapping in the bidirectional mapping table
 (see below for details). Pushes to a SHA-1 based server convert the
 objects being pushed into sha1 form so the server does not have to be
 aware of the hash function the client is using.
@@ -125,19 +122,19 @@ Detailed Design
 ---------------
 Repository format extension
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-A NewHash repository uses repository format version `1` (see
+A SHA-256 repository uses repository format version `1` (see
 Documentation/technical/repository-version.txt) with extensions
 `objectFormat` and `compatObjectFormat`:
 
        [core]
                repositoryFormatVersion = 1
        [extensions]
-               objectFormat = newhash
+               objectFormat = sha256
                compatObjectFormat = sha1
 
 The combination of setting `core.repositoryFormatVersion=1` and
 populating `extensions.*` ensures that all versions of Git later than
-`v0.99.9l` will die instead of trying to operate on the NewHash
+`v0.99.9l` will die instead of trying to operate on the SHA-256
 repository, instead producing an error message.
 
        # Between v0.99.9l and v2.7.0
@@ -155,36 +152,36 @@ repository extensions.
 Object names
 ~~~~~~~~~~~~
 Objects can be named by their 40 hexadecimal digit sha1-name or 64
-hexadecimal digit newhash-name, plus names derived from those (see
+hexadecimal digit sha256-name, plus names derived from those (see
 gitrevisions(7)).
 
 The sha1-name of an object is the SHA-1 of the concatenation of its
 type, length, a nul byte, and the object's sha1-content. This is the
 traditional <sha1> used in Git to name objects.
 
-The newhash-name of an object is the NewHash of the concatenation of its
-type, length, a nul byte, and the object's newhash-content.
+The sha256-name of an object is the SHA-256 of the concatenation of its
+type, length, a nul byte, and the object's sha256-content.
 
 Object format
 ~~~~~~~~~~~~~
 The content as a byte sequence of a tag, commit, or tree object named
-by sha1 and newhash differ because an object named by newhash-name refers to
-other objects by their newhash-names and an object named by sha1-name
+by sha1 and sha256 differ because an object named by sha256-name refers to
+other objects by their sha256-names and an object named by sha1-name
 refers to other objects by their sha1-names.
 
-The newhash-content of an object is the same as its sha1-content, except
-that objects referenced by the object are named using their newhash-names
+The sha256-content of an object is the same as its sha1-content, except
+that objects referenced by the object are named using their sha256-names
 instead of sha1-names. Because a blob object does not refer to any
-other object, its sha1-content and newhash-content are the same.
+other object, its sha1-content and sha256-content are the same.
 
-The format allows round-trip conversion between newhash-content and
+The format allows round-trip conversion between sha256-content and
 sha1-content.
 
 Object storage
 ~~~~~~~~~~~~~~
 Loose objects use zlib compression and packed objects use the packed
 format described in Documentation/technical/pack-format.txt, just like
-today. The content that is compressed and stored uses newhash-content
+today. The content that is compressed and stored uses sha256-content
 instead of sha1-content.
 
 Pack index
@@ -255,10 +252,10 @@ network byte order):
   up to and not including the table of CRC32 values.
 - Zero or more NUL bytes.
 - The trailer consists of the following:
-  - A copy of the 20-byte NewHash checksum at the end of the
+  - A copy of the 20-byte SHA-256 checksum at the end of the
     corresponding packfile.
 
-  - 20-byte NewHash checksum of all of the above.
+  - 20-byte SHA-256 checksum of all of the above.
 
 Loose object index
 ~~~~~~~~~~~~~~~~~~
@@ -266,7 +263,7 @@ A new file $GIT_OBJECT_DIR/loose-object-idx contains information about
 all loose objects. Its format is
 
   # loose-object-idx
-  (newhash-name SP sha1-name LF)*
+  (sha256-name SP sha1-name LF)*
 
 where the object names are in hexadecimal format. The file is not
 sorted.
@@ -292,8 +289,8 @@ To remove entries (e.g. in "git pack-refs" or "git-prune"):
 Translation table
 ~~~~~~~~~~~~~~~~~
 The index files support a bidirectional mapping between sha1-names
-and newhash-names. The lookup proceeds similarly to ordinary object
-lookups. For example, to convert a sha1-name to a newhash-name:
+and sha256-names. The lookup proceeds similarly to ordinary object
+lookups. For example, to convert a sha1-name to a sha256-name:
 
  1. Look for the object in idx files. If a match is present in the
     idx's sorted list of truncated sha1-names, then:
@@ -301,8 +298,8 @@ lookups. For example, to convert a sha1-name to a newhash-name:
        name order mapping.
     b. Read the corresponding entry in the full sha1-name table to
        verify we found the right object. If it is, then
-    c. Read the corresponding entry in the full newhash-name table.
-       That is the object's newhash-name.
+    c. Read the corresponding entry in the full sha256-name table.
+       That is the object's sha256-name.
  2. Check for a loose object. Read lines from loose-object-idx until
     we find a match.
 
@@ -318,25 +315,25 @@ for all objects in the object store.
 
 Reading an object's sha1-content
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The sha1-content of an object can be read by converting all newhash-names
-its newhash-content references to sha1-names using the translation table.
+The sha1-content of an object can be read by converting all sha256-names
+its sha256-content references to sha1-names using the translation table.
 
 Fetch
 ~~~~~
 Fetching from a SHA-1 based server requires translating between SHA-1
-and NewHash based representations on the fly.
+and SHA-256 based representations on the fly.
 
 SHA-1s named in the ref advertisement that are present on the client
-can be translated to NewHash and looked up as local objects using the
+can be translated to SHA-256 and looked up as local objects using the
 translation table.
 
 Negotiation proceeds as today. Any "have"s generated locally are
 converted to SHA-1 before being sent to the server, and SHA-1s
-mentioned by the server are converted to NewHash when looking them up
+mentioned by the server are converted to SHA-256 when looking them up
 locally.
 
 After negotiation, the server sends a packfile containing the
-requested objects. We convert the packfile to NewHash format using
+requested objects. We convert the packfile to SHA-256 format using
 the following steps:
 
 1. index-pack: inflate each object in the packfile and compute its
@@ -351,12 +348,12 @@ the following steps:
    (This list only contains objects reachable from the "wants". If the
    pack from the server contained additional extraneous objects, then
    they will be discarded.)
-3. convert to newhash: open a new (newhash) packfile. Read the topologically
+3. convert to sha256: open a new (sha256) packfile. Read the topologically
    sorted list just generated. For each object, inflate its
-   sha1-content, convert to newhash-content, and write it to the newhash
-   pack. Record the new sha1<->newhash mapping entry for use in the idx.
+   sha1-content, convert to sha256-content, and write it to the sha256
+   pack. Record the new sha1<->sha256 mapping entry for use in the idx.
 4. sort: reorder entries in the new pack to match the order of objects
-   in the pack the server generated and include blobs. Write a newhash idx
+   in the pack the server generated and include blobs. Write a sha256 idx
    file
 5. clean up: remove the SHA-1 based pack file, index, and
    topologically sorted list obtained from the server in steps 1
@@ -388,16 +385,16 @@ send-pack.
 
 Signed Commits
 ~~~~~~~~~~~~~~
-We add a new field "gpgsig-newhash" to the commit object format to allow
+We add a new field "gpgsig-sha256" to the commit object format to allow
 signing commits without relying on SHA-1. It is similar to the
-existing "gpgsig" field. Its signed payload is the newhash-content of the
-commit object with any "gpgsig" and "gpgsig-newhash" fields removed.
+existing "gpgsig" field. Its signed payload is the sha256-content of the
+commit object with any "gpgsig" and "gpgsig-sha256" fields removed.
 
 This means commits can be signed
 1. using SHA-1 only, as in existing signed commit objects
-2. using both SHA-1 and NewHash, by using both gpgsig-newhash and gpgsig
+2. using both SHA-1 and SHA-256, by using both gpgsig-sha256 and gpgsig
    fields.
-3. using only NewHash, by only using the gpgsig-newhash field.
+3. using only SHA-256, by only using the gpgsig-sha256 field.
 
 Old versions of "git verify-commit" can verify the gpgsig signature in
 cases (1) and (2) without modifications and view case (3) as an
@@ -405,24 +402,24 @@ ordinary unsigned commit.
 
 Signed Tags
 ~~~~~~~~~~~
-We add a new field "gpgsig-newhash" to the tag object format to allow
+We add a new field "gpgsig-sha256" to the tag object format to allow
 signing tags without relying on SHA-1. Its signed payload is the
-newhash-content of the tag with its gpgsig-newhash field and "-----BEGIN PGP
+sha256-content of the tag with its gpgsig-sha256 field and "-----BEGIN PGP
 SIGNATURE-----" delimited in-body signature removed.
 
 This means tags can be signed
 1. using SHA-1 only, as in existing signed tag objects
-2. using both SHA-1 and NewHash, by using gpgsig-newhash and an in-body
+2. using both SHA-1 and SHA-256, by using gpgsig-sha256 and an in-body
    signature.
-3. using only NewHash, by only using the gpgsig-newhash field.
+3. using only SHA-256, by only using the gpgsig-sha256 field.
 
 Mergetag embedding
 ~~~~~~~~~~~~~~~~~~
 The mergetag field in the sha1-content of a commit contains the
 sha1-content of a tag that was merged by that commit.
 
-The mergetag field in the newhash-content of the same commit contains the
-newhash-content of the same tag.
+The mergetag field in the sha256-content of the same commit contains the
+sha256-content of the same tag.
 
 Submodules
 ~~~~~~~~~~
@@ -497,7 +494,7 @@ Caveats
 -------
 Invalid objects
 ~~~~~~~~~~~~~~~
-The conversion from sha1-content to newhash-content retains any
+The conversion from sha1-content to sha256-content retains any
 brokenness in the original object (e.g., tree entry modes encoded with
 leading 0, tree objects whose paths are not sorted correctly, and
 commit objects without an author or committer). This is a deliberate
@@ -516,7 +513,7 @@ allow lifting this restriction.
 
 Alternates
 ~~~~~~~~~~
-For the same reason, a newhash repository cannot borrow objects from a
+For the same reason, a sha256 repository cannot borrow objects from a
 sha1 repository using objects/info/alternates or
 $GIT_ALTERNATE_OBJECT_REPOSITORIES.
 
@@ -524,20 +521,20 @@ git notes
 ~~~~~~~~~
 The "git notes" tool annotates objects using their sha1-name as key.
 This design does not describe a way to migrate notes trees to use
-newhash-names. That migration is expected to happen separately (for
+sha256-names. That migration is expected to happen separately (for
 example using a file at the root of the notes tree to describe which
 hash it uses).
 
 Server-side cost
 ~~~~~~~~~~~~~~~~
-Until Git protocol gains NewHash support, using NewHash based storage
+Until Git protocol gains SHA-256 support, using SHA-256 based storage
 on public-facing Git servers is strongly discouraged. Once Git
-protocol gains NewHash support, NewHash based servers are likely not
+protocol gains SHA-256 support, SHA-256 based servers are likely not
 to support SHA-1 compatibility, to avoid what may be a very expensive
 hash reencode during clone and to encourage peers to modernize.
 
 The design described here allows fetches by SHA-1 clients of a
-personal NewHash repository because it's not much more difficult than
+personal SHA-256 repository because it's not much more difficult than
 allowing pushes from that repository. This support needs to be guarded
 by a configuration option --- servers like git.kernel.org that serve a
 large number of clients would not be expected to bear that cost.
@@ -547,7 +544,7 @@ Meaning of signatures
 The signed payload for signed commits and tags does not explicitly
 name the hash used to identify objects. If some day Git adopts a new
 hash function with the same length as the current SHA-1 (40
-hexadecimal digit) or NewHash (64 hexadecimal digit) objects then the
+hexadecimal digit) or SHA-256 (64 hexadecimal digit) objects then the
 intent behind the PGP signed payload in an object signature is
 unclear:
 
@@ -562,7 +559,7 @@ Does this mean Git v2.12.0 is the commit with sha1-name
 e7e07d5a4fcc2a203d9873968ad3e6bd4d7419d7 or the commit with
 new-40-digit-hash-name e7e07d5a4fcc2a203d9873968ad3e6bd4d7419d7?
 
-Fortunately NewHash and SHA-1 have different lengths. If Git starts
+Fortunately SHA-256 and SHA-1 have different lengths. If Git starts
 using another hash with the same length to name objects, then it will
 need to change the format of signed payloads using that hash to
 address this issue.
@@ -574,24 +571,24 @@ supports four different modes of operation:
 
  1. ("dark launch") Treat object names input by the user as SHA-1 and
     convert any object names written to output to SHA-1, but store
-    objects using NewHash.  This allows users to test the code with no
+    objects using SHA-256.  This allows users to test the code with no
     visible behavior change except for performance.  This allows
     allows running even tests that assume the SHA-1 hash function, to
     sanity-check the behavior of the new mode.
 
- 2. ("early transition") Allow both SHA-1 and NewHash object names in
+ 2. ("early transition") Allow both SHA-1 and SHA-256 object names in
     input. Any object names written to output use SHA-1. This allows
     users to continue to make use of SHA-1 to communicate with peers
     (e.g. by email) that have not migrated yet and prepares for mode 3.
 
- 3. ("late transition") Allow both SHA-1 and NewHash object names in
-    input. Any object names written to output use NewHash. In this
+ 3. ("late transition") Allow both SHA-1 and SHA-256 object names in
+    input. Any object names written to output use SHA-256. In this
     mode, users are using a more secure object naming method by
     default.  The disruption is minimal as long as most of their peers
     are in mode 2 or mode 3.
 
  4. ("post-transition") Treat object names input by the user as
-    NewHash and write output using NewHash. This is safer than mode 3
+    SHA-256 and write output using SHA-256. This is safer than mode 3
     because there is less risk that input is incorrectly interpreted
     using the wrong hash function.
 
@@ -601,27 +598,31 @@ The user can also explicitly specify which format to use for a
 particular revision specifier and for output, overriding the mode. For
 example:
 
-git --output-format=sha1 log abac87a^{sha1}..f787cac^{newhash}
+git --output-format=sha1 log abac87a^{sha1}..f787cac^{sha256}
 
-Selection of a New Hash
------------------------
+Choice of Hash
+--------------
 In early 2005, around the time that Git was written,  Xiaoyun Wang,
 Yiqun Lisa Yin, and Hongbo Yu announced an attack finding SHA-1
 collisions in 2^69 operations. In August they published details.
 Luckily, no practical demonstrations of a collision in full SHA-1 were
 published until 10 years later, in 2017.
 
-The hash function NewHash to replace SHA-1 should be stronger than
-SHA-1 was: we would like it to be trustworthy and useful in practice
-for at least 10 years.
+Git v2.13.0 and later subsequently moved to a hardened SHA-1
+implementation by default that mitigates the SHAttered attack, but
+SHA-1 is still believed to be weak.
+
+The hash to replace this hardened SHA-1 should be stronger than SHA-1
+was: we would like it to be trustworthy and useful in practice for at
+least 10 years.
 
 Some other relevant properties:
 
 1. A 256-bit hash (long enough to match common security practice; not
    excessively long to hurt performance and disk usage).
 
-2. High quality implementations should be widely available (e.g. in
-   OpenSSL).
+2. High quality implementations should be widely available (e.g., in
+   OpenSSL and Apple CommonCrypto).
 
 3. The hash function's properties should match Git's needs (e.g. Git
    requires collision and 2nd preimage resistance and does not require
@@ -630,14 +631,13 @@ Some other relevant properties:
 4. As a tiebreaker, the hash should be fast to compute (fortunately
    many contenders are faster than SHA-1).
 
-Some hashes under consideration are SHA-256, SHA-512/256, SHA-256x16,
-K12, and BLAKE2bp-256.
+We choose SHA-256.
 
 Transition plan
 ---------------
 Some initial steps can be implemented independently of one another:
 - adding a hash function API (vtable)
-- teaching fsck to tolerate the gpgsig-newhash field
+- teaching fsck to tolerate the gpgsig-sha256 field
 - excluding gpgsig-* from the fields copied by "git commit --amend"
 - annotating tests that depend on SHA-1 values with a SHA1 test
   prerequisite
@@ -664,7 +664,7 @@ Next comes introduction of compatObjectFormat:
 - adding appropriate index entries when adding a new object to the
   object store
 - --output-format option
-- ^{sha1} and ^{newhash} revision notation
+- ^{sha1} and ^{sha256} revision notation
 - configuration to specify default input and output format (see
   "Object names on the command line" above)
 
@@ -672,7 +672,7 @@ The next step is supporting fetches and pushes to SHA-1 repositories:
 - allow pushes to a repository using the compat format
 - generate a topologically sorted list of the SHA-1 names of fetched
   objects
-- convert the fetched packfile to newhash format and generate an idx
+- convert the fetched packfile to sha256 format and generate an idx
   file
 - re-sort to match the order of objects in the fetched packfile
 
@@ -680,30 +680,30 @@ The infrastructure supporting fetch also allows converting an existing
 repository. In converted repositories and new clones, end users can
 gain support for the new hash function without any visible change in
 behavior (see "dark launch" in the "Object names on the command line"
-section). In particular this allows users to verify NewHash signatures
+section). In particular this allows users to verify SHA-256 signatures
 on objects in the repository, and it should ensure the transition code
 is stable in production in preparation for using it more widely.
 
 Over time projects would encourage their users to adopt the "early
 transition" and then "late transition" modes to take advantage of the
-new, more futureproof NewHash object names.
+new, more futureproof SHA-256 object names.
 
 When objectFormat and compatObjectFormat are both set, commands
-generating signatures would generate both SHA-1 and NewHash signatures
+generating signatures would generate both SHA-1 and SHA-256 signatures
 by default to support both new and old users.
 
-In projects using NewHash heavily, users could be encouraged to adopt
+In projects using SHA-256 heavily, users could be encouraged to adopt
 the "post-transition" mode to avoid accidentally making implicit use
 of SHA-1 object names.
 
 Once a critical mass of users have upgraded to a version of Git that
-can verify NewHash signatures and have converted their existing
+can verify SHA-256 signatures and have converted their existing
 repositories to support verifying them, we can add support for a
-setting to generate only NewHash signatures. This is expected to be at
+setting to generate only SHA-256 signatures. This is expected to be at
 least a year later.
 
 That is also a good moment to advertise the ability to convert
-repositories to use NewHash only, stripping out all SHA-1 related
+repositories to use SHA-256 only, stripping out all SHA-1 related
 metadata. This improves performance by eliminating translation
 overhead and security by avoiding the possibility of accidentally
 relying on the safety of SHA-1.
@@ -742,16 +742,16 @@ using the old hash function.
 
 Signed objects with multiple hashes
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Instead of introducing the gpgsig-newhash field in commit and tag objects
-for newhash-content based signatures, an earlier version of this design
-added "hash newhash <newhash-name>" fields to strengthen the existing
+Instead of introducing the gpgsig-sha256 field in commit and tag objects
+for sha256-content based signatures, an earlier version of this design
+added "hash sha256 <sha256-name>" fields to strengthen the existing
 sha1-content based signatures.
 
 In other words, a single signature was used to attest to the object
 content using both hash functions. This had some advantages:
 * Using one signature instead of two speeds up the signing process.
 * Having one signed payload with both hashes allows the signer to
-  attest to the sha1-name and newhash-name referring to the same object.
+  attest to the sha1-name and sha256-name referring to the same object.
 * All users consume the same signature. Broken signatures are likely
   to be detected quickly using current versions of git.
 
@@ -760,11 +760,11 @@ However, it also came with disadvantages:
   objects it references, even after the transition is complete and
   translation table is no longer needed for anything else. To support
   this, the design added fields such as "hash sha1 tree <sha1-name>"
-  and "hash sha1 parent <sha1-name>" to the newhash-content of a signed
+  and "hash sha1 parent <sha1-name>" to the sha256-content of a signed
   commit, complicating the conversion process.
 * Allowing signed objects without a sha1 (for after the transition is
   complete) complicated the design further, requiring a "nohash sha1"
-  field to suppress including "hash sha1" fields in the newhash-content
+  field to suppress including "hash sha1" fields in the sha256-content
   and signed payload.
 
 Lazily populated translation table
@@ -772,7 +772,7 @@ Lazily populated translation table
 Some of the work of building the translation table could be deferred to
 push time, but that would significantly complicate and slow down pushes.
 Calculating the sha1-name at object creation time at the same time it is
-being streamed to disk and having its newhash-name calculated should be
+being streamed to disk and having its sha256-name calculated should be
 an acceptable cost.
 
 Document History
@@ -814,6 +814,12 @@ Incorporated suggestions from jonathantanmy and sbeller:
 * avoid loose object overhead by packing more aggressively in
   "git gc --auto"
 
+Later history:
+
+ See the history of this file in git.git for the history of subsequent
+ edits. This document history is no longer being maintained as it
+ would now be superfluous to the commit log
+
 [1] http://public-inbox.org/git/CA+55aFzJtejiCjV0e43+9oR3QuJK2PiFiLQemytoLpyJWe6P9w@mail.gmail.com/
 [2] http://public-inbox.org/git/CA+55aFz+gkAsDZ24zmePQuEs1XPS9BP_s8O7Q4wQ7LV7X5-oDA@mail.gmail.com/
 [3] http://public-inbox.org/git/20170306084353.nrns455dvkdsfgo5@sigill.intra.peff.net/
index 0bed2472c815dc8c0e5886d0fb6f301c5550a390..1ef66bd788a0997f73ec736c806a5aadad63ee39 100644 (file)
@@ -69,24 +69,24 @@ Design Details
 
 - A new pack-protocol capability "filter" is added to the fetch-pack and
   upload-pack negotiation.
-
-  This uses the existing capability discovery mechanism.
-  See "filter" in Documentation/technical/pack-protocol.txt.
++
+This uses the existing capability discovery mechanism.
+See "filter" in Documentation/technical/pack-protocol.txt.
 
 - Clients pass a "filter-spec" to clone and fetch which is passed to the
   server to request filtering during packfile construction.
-
-  There are various filters available to accommodate different situations.
-  See "--filter=<filter-spec>" in Documentation/rev-list-options.txt.
++
+There are various filters available to accommodate different situations.
+See "--filter=<filter-spec>" in Documentation/rev-list-options.txt.
 
 - On the server pack-objects applies the requested filter-spec as it
   creates "filtered" packfiles for the client.
-
-  These filtered packfiles are *incomplete* in the traditional sense because
-  they may contain objects that reference objects not contained in the
-  packfile and that the client doesn't already have.  For example, the
-  filtered packfile may contain trees or tags that reference missing blobs
-  or commits that reference missing trees.
++
+These filtered packfiles are *incomplete* in the traditional sense because
+they may contain objects that reference objects not contained in the
+packfile and that the client doesn't already have.  For example, the
+filtered packfile may contain trees or tags that reference missing blobs
+or commits that reference missing trees.
 
 - On the client these incomplete packfiles are marked as "promisor packfiles"
   and treated differently by various commands.
@@ -104,47 +104,47 @@ Handling Missing Objects
   to repository corruption.  To differentiate these cases, the local
   repository specially indicates such filtered packfiles obtained from the
   promisor remote as "promisor packfiles".
-
-  These promisor packfiles consist of a "<name>.promisor" file with
-  arbitrary contents (like the "<name>.keep" files), in addition to
-  their "<name>.pack" and "<name>.idx" files.
++
+These promisor packfiles consist of a "<name>.promisor" file with
+arbitrary contents (like the "<name>.keep" files), in addition to
+their "<name>.pack" and "<name>.idx" files.
 
 - The local repository considers a "promisor object" to be an object that
   it knows (to the best of its ability) that the promisor remote has promised
   that it has, either because the local repository has that object in one of
   its promisor packfiles, or because another promisor object refers to it.
-
-  When Git encounters a missing object, Git can see if it a promisor object
-  and handle it appropriately.  If not, Git can report a corruption.
-
-  This means that there is no need for the client to explicitly maintain an
-  expensive-to-modify list of missing objects.[a]
++
+When Git encounters a missing object, Git can see if it a promisor object
+and handle it appropriately.  If not, Git can report a corruption.
++
+This means that there is no need for the client to explicitly maintain an
+expensive-to-modify list of missing objects.[a]
 
 - Since almost all Git code currently expects any referenced object to be
   present locally and because we do not want to force every command to do
   a dry-run first, a fallback mechanism is added to allow Git to attempt
   to dynamically fetch missing objects from the promisor remote.
-
-  When the normal object lookup fails to find an object, Git invokes
-  fetch-object to try to get the object from the server and then retry
-  the object lookup.  This allows objects to be "faulted in" without
-  complicated prediction algorithms.
-
-  For efficiency reasons, no check as to whether the missing object is
-  actually a promisor object is performed.
-
-  Dynamic object fetching tends to be slow as objects are fetched one at
-  a time.
++
+When the normal object lookup fails to find an object, Git invokes
+fetch-object to try to get the object from the server and then retry
+the object lookup.  This allows objects to be "faulted in" without
+complicated prediction algorithms.
++
+For efficiency reasons, no check as to whether the missing object is
+actually a promisor object is performed.
++
+Dynamic object fetching tends to be slow as objects are fetched one at
+a time.
 
 - `checkout` (and any other command using `unpack-trees`) has been taught
   to bulk pre-fetch all required missing blobs in a single batch.
 
 - `rev-list` has been taught to print missing objects.
-
-  This can be used by other commands to bulk prefetch objects.
-  For example, a "git log -p A..B" may internally want to first do
-  something like "git rev-list --objects --quiet --missing=print A..B"
-  and prefetch those objects in bulk.
++
+This can be used by other commands to bulk prefetch objects.
+For example, a "git log -p A..B" may internally want to first do
+something like "git rev-list --objects --quiet --missing=print A..B"
+and prefetch those objects in bulk.
 
 - `fsck` has been updated to be fully aware of promisor objects.
 
@@ -154,11 +154,11 @@ Handling Missing Objects
 - The global variable "fetch_if_missing" is used to control whether an
   object lookup will attempt to dynamically fetch a missing object or
   report an error.
-
-  We are not happy with this global variable and would like to remove it,
-  but that requires significant refactoring of the object code to pass an
-  additional flag.  We hope that concurrent efforts to add an ODB API can
-  encompass this.
++
+We are not happy with this global variable and would like to remove it,
+but that requires significant refactoring of the object code to pass an
+additional flag.  We hope that concurrent efforts to add an ODB API can
+encompass this.
 
 
 Fetching Missing Objects
@@ -168,10 +168,10 @@ Fetching Missing Objects
   transport_fetch_refs(), setting a new transport option
   TRANS_OPT_NO_DEPENDENTS to indicate that only the objects themselves are
   desired, not any object that they refer to.
-
-  Because some transports invoke fetch_pack() in the same process, fetch_pack()
-  has been updated to not use any object flags when the corresponding argument
-  (no_dependents) is set.
++
+Because some transports invoke fetch_pack() in the same process, fetch_pack()
+has been updated to not use any object flags when the corresponding argument
+(no_dependents) is set.
 
 - The local repository sends a request with the hashes of all requested
   objects as "want" lines, and does not perform any packfile negotiation.
@@ -187,13 +187,13 @@ Current Limitations
 
 - The remote used for a partial clone (or the first partial fetch
   following a regular clone) is marked as the "promisor remote".
-
-  We are currently limited to a single promisor remote and only that
-  remote may be used for subsequent partial fetches.
-
-  We accept this limitation because we believe initial users of this
-  feature will be using it on repositories with a strong single central
-  server.
++
+We are currently limited to a single promisor remote and only that
+remote may be used for subsequent partial fetches.
++
+We accept this limitation because we believe initial users of this
+feature will be using it on repositories with a strong single central
+server.
 
 - Dynamic object fetching will only ask the promisor remote for missing
   objects.  We assume that the promisor remote has a complete view of the
@@ -221,13 +221,13 @@ Future Work
 - Allow more than one promisor remote and define a strategy for fetching
   missing objects from specific promisor remotes or of iterating over the
   set of promisor remotes until a missing object is found.
-
-  A user might want to have multiple geographically-close cache servers
-  for fetching missing blobs while continuing to do filtered `git-fetch`
-  commands from the central server, for example.
-
-  Or the user might want to work in a triangular work flow with multiple
-  promisor remotes that each have an incomplete view of the repository.
++
+A user might want to have multiple geographically-close cache servers
+for fetching missing blobs while continuing to do filtered `git-fetch`
+commands from the central server, for example.
++
+Or the user might want to work in a triangular work flow with multiple
+promisor remotes that each have an incomplete view of the repository.
 
 - Allow repack to work on promisor packfiles (while keeping them distinct
   from non-promisor packfiles).
@@ -238,25 +238,25 @@ Future Work
 - Investigate use of a long-running process to dynamically fetch a series
   of objects, such as proposed in [5,6] to reduce process startup and
   overhead costs.
-
-  It would be nice if pack protocol V2 could allow that long-running
-  process to make a series of requests over a single long-running
-  connection.
++
+It would be nice if pack protocol V2 could allow that long-running
+process to make a series of requests over a single long-running
+connection.
 
 - Investigate pack protocol V2 to avoid the info/refs broadcast on
   each connection with the server to dynamically fetch missing objects.
 
 - Investigate the need to handle loose promisor objects.
-
-  Objects in promisor packfiles are allowed to reference missing objects
-  that can be dynamically fetched from the server.  An assumption was
-  made that loose objects are only created locally and therefore should
-  not reference a missing object.  We may need to revisit that assumption
-  if, for example, we dynamically fetch a missing tree and store it as a
-  loose object rather than a single object packfile.
-
-  This does not necessarily mean we need to mark loose objects as promisor;
-  it may be sufficient to relax the object lookup or is-promisor functions.
++
+Objects in promisor packfiles are allowed to reference missing objects
+that can be dynamically fetched from the server.  An assumption was
+made that loose objects are only created locally and therefore should
+not reference a missing object.  We may need to revisit that assumption
+if, for example, we dynamically fetch a missing tree and store it as a
+loose object rather than a single object packfile.
++
+This does not necessarily mean we need to mark loose objects as promisor;
+it may be sufficient to relax the object lookup or is-promisor functions.
 
 
 Non-Tasks
@@ -265,13 +265,13 @@ Non-Tasks
 - Every time the subject of "demand loading blobs" comes up it seems
   that someone suggests that the server be allowed to "guess" and send
   additional objects that may be related to the requested objects.
-
-  No work has gone into actually doing that; we're just documenting that
-  it is a common suggestion.  We're not sure how it would work and have
-  no plans to work on it.
-
-  It is valid for the server to send more objects than requested (even
-  for a dynamic object fetch), but we are not building on that.
++
+No work has gone into actually doing that; we're just documenting that
+it is a common suggestion.  We're not sure how it would work and have
+no plans to work on it.
++
+It is valid for the server to send more objects than requested (even
+for a dynamic object fetch), but we are not building on that.
 
 
 Footnotes
@@ -282,43 +282,43 @@ Footnotes
     This would essentially be a sorted linear list of OIDs that the were
     omitted by the server during a clone or subsequent fetches.
 
-    This file would need to be loaded into memory on every object lookup.
-    It would need to be read, updated, and re-written (like the .git/index)
-    on every explicit "git fetch" command *and* on any dynamic object fetch.
+This file would need to be loaded into memory on every object lookup.
+It would need to be read, updated, and re-written (like the .git/index)
+on every explicit "git fetch" command *and* on any dynamic object fetch.
 
-    The cost to read, update, and write this file could add significant
-    overhead to every command if there are many missing objects.  For example,
-    if there are 100M missing blobs, this file would be at least 2GiB on disk.
+The cost to read, update, and write this file could add significant
+overhead to every command if there are many missing objects.  For example,
+if there are 100M missing blobs, this file would be at least 2GiB on disk.
 
-    With the "promisor" concept, we *infer* a missing object based upon the
-    type of packfile that references it.
+With the "promisor" concept, we *infer* a missing object based upon the
+type of packfile that references it.
 
 
 Related Links
 -------------
-[0] https://bugs.chromium.org/p/git/issues/detail?id=2
-    Chromium work item for: Partial Clone
+[0] https://crbug.com/git/2
+    Bug#2: Partial Clone
 
-[1] https://public-inbox.org/git/20170113155253.1644-1-benpeart@microsoft.com/
-    Subject: [RFC] Add support for downloading blobs on demand
+[1] https://public-inbox.org/git/20170113155253.1644-1-benpeart@microsoft.com/ +
+    Subject: [RFC] Add support for downloading blobs on demand +
     Date: Fri, 13 Jan 2017 10:52:53 -0500
 
-[2] https://public-inbox.org/git/cover.1506714999.git.jonathantanmy@google.com/
-    Subject: [PATCH 00/18] Partial clone (from clone to lazy fetch in 18 patches)
+[2] https://public-inbox.org/git/cover.1506714999.git.jonathantanmy@google.com/ +
+    Subject: [PATCH 00/18] Partial clone (from clone to lazy fetch in 18 patches) +
     Date: Fri, 29 Sep 2017 13:11:36 -0700
 
-[3] https://public-inbox.org/git/20170426221346.25337-1-jonathantanmy@google.com/
-    Subject: Proposal for missing blob support in Git repos
+[3] https://public-inbox.org/git/20170426221346.25337-1-jonathantanmy@google.com/ +
+    Subject: Proposal for missing blob support in Git repos +
     Date: Wed, 26 Apr 2017 15:13:46 -0700
 
-[4] https://public-inbox.org/git/1488999039-37631-1-git-send-email-git@jeffhostetler.com/
-    Subject: [PATCH 00/10] RFC Partial Clone and Fetch
+[4] https://public-inbox.org/git/1488999039-37631-1-git-send-email-git@jeffhostetler.com/ +
+    Subject: [PATCH 00/10] RFC Partial Clone and Fetch +
     Date: Wed,  8 Mar 2017 18:50:29 +0000
 
-[5] https://public-inbox.org/git/20170505152802.6724-1-benpeart@microsoft.com/
-    Subject: [PATCH v7 00/10] refactor the filter process code into a reusable module
+[5] https://public-inbox.org/git/20170505152802.6724-1-benpeart@microsoft.com/ +
+    Subject: [PATCH v7 00/10] refactor the filter process code into a reusable module +
     Date: Fri,  5 May 2017 11:27:52 -0400
 
-[6] https://public-inbox.org/git/20170714132651.170708-1-benpeart@microsoft.com/
-    Subject: [RFC/PATCH v2 0/1] Add support for downloading blobs on demand
+[6] https://public-inbox.org/git/20170714132651.170708-1-benpeart@microsoft.com/ +
+    Subject: [RFC/PATCH v2 0/1] Add support for downloading blobs on demand +
     Date: Fri, 14 Jul 2017 09:26:50 -0400
index e3364a42a55bd0df0c4fd6bd75f91e38962410e9..d03df31c2a61b29caa60928eb3b3f131562152d3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -876,6 +876,7 @@ LIB_OBJS += gpg-interface.o
 LIB_OBJS += graph.o
 LIB_OBJS += grep.o
 LIB_OBJS += hashmap.o
+LIB_OBJS += linear-assignment.o
 LIB_OBJS += help.o
 LIB_OBJS += hex.o
 LIB_OBJS += ident.o
@@ -931,6 +932,7 @@ LIB_OBJS += progress.o
 LIB_OBJS += prompt.o
 LIB_OBJS += protocol.o
 LIB_OBJS += quote.o
+LIB_OBJS += range-diff.o
 LIB_OBJS += reachable.o
 LIB_OBJS += read-cache.o
 LIB_OBJS += reflog-walk.o
@@ -1069,6 +1071,7 @@ BUILTIN_OBJS += builtin/prune-packed.o
 BUILTIN_OBJS += builtin/prune.o
 BUILTIN_OBJS += builtin/pull.o
 BUILTIN_OBJS += builtin/push.o
+BUILTIN_OBJS += builtin/range-diff.o
 BUILTIN_OBJS += builtin/read-tree.o
 BUILTIN_OBJS += builtin/rebase--helper.o
 BUILTIN_OBJS += builtin/receive-pack.o
@@ -2044,7 +2047,7 @@ $(BUILT_INS): git$X
 
 command-list.h: generate-cmdlist.sh command-list.txt
 
-command-list.h: $(wildcard Documentation/git*.txt)
+command-list.h: $(wildcard Documentation/git*.txt) Documentation/config.txt
        $(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@
 
 SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
diff --git a/alloc.c b/alloc.c
index c2fc5d68886bf3f74a1f013a3a36c7b5dcad2258..e7aa81b7aa48c14f2a98894eb6e8c2e28998945e 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -36,7 +36,7 @@ struct alloc_state {
        int slab_nr, slab_alloc;
 };
 
-void *allocate_alloc_state(void)
+struct alloc_state *allocate_alloc_state(void)
 {
        return xcalloc(1, sizeof(struct alloc_state));
 }
diff --git a/alloc.h b/alloc.h
index 3e4e828db48e2be2dff993d01175d7bf8c41c8f0..ba356ed8478d13f05f49efd5bacccaac3e69dfd7 100644 (file)
--- a/alloc.h
+++ b/alloc.h
@@ -1,9 +1,11 @@
 #ifndef ALLOC_H
 #define ALLOC_H
 
+struct alloc_state;
 struct tree;
 struct commit;
 struct tag;
+struct repository;
 
 void *alloc_blob_node(struct repository *r);
 void *alloc_tree_node(struct repository *r);
@@ -13,7 +15,7 @@ void *alloc_object_node(struct repository *r);
 void alloc_report(struct repository *r);
 unsigned int alloc_commit_index(struct repository *r);
 
-void *allocate_alloc_state(void);
+struct alloc_state *allocate_alloc_state(void);
 void clear_alloc_state(struct alloc_state *s);
 
 #endif
diff --git a/apply.c b/apply.c
index 2594927248b44715054d8a52faeb2cd3948c2d30..e485fbc6bc11efc6daefe78cbe949a65560ff4fa 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -76,10 +76,12 @@ static int parse_ignorewhitespace_option(struct apply_state *state,
 }
 
 int init_apply_state(struct apply_state *state,
+                    struct repository *repo,
                     const char *prefix)
 {
        memset(state, 0, sizeof(*state));
        state->prefix = prefix;
+       state->repo = repo;
        state->apply = 1;
        state->line_termination = '\n';
        state->p_value = 1;
@@ -3374,14 +3376,17 @@ static struct patch *previous_patch(struct apply_state *state,
        return previous;
 }
 
-static int verify_index_match(const struct cache_entry *ce, struct stat *st)
+static int verify_index_match(struct apply_state *state,
+                             const struct cache_entry *ce,
+                             struct stat *st)
 {
        if (S_ISGITLINK(ce->ce_mode)) {
                if (!S_ISDIR(st->st_mode))
                        return -1;
                return 0;
        }
-       return ce_match_stat(ce, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
+       return ie_match_stat(state->repo->index, ce, st,
+                            CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);
 }
 
 #define SUBMODULE_PATCH_WITHOUT_INDEX 1
@@ -3514,17 +3519,17 @@ static int load_current(struct apply_state *state,
        if (!patch->is_new)
                BUG("patch to %s is not a creation", patch->old_name);
 
-       pos = cache_name_pos(name, strlen(name));
+       pos = index_name_pos(state->repo->index, name, strlen(name));
        if (pos < 0)
                return error(_("%s: does not exist in index"), name);
-       ce = active_cache[pos];
+       ce = state->repo->index->cache[pos];
        if (lstat(name, &st)) {
                if (errno != ENOENT)
                        return error_errno("%s", name);
-               if (checkout_target(&the_index, ce, &st))
+               if (checkout_target(state->repo->index, ce, &st))
                        return -1;
        }
-       if (verify_index_match(ce, &st))
+       if (verify_index_match(state, ce, &st))
                return error(_("%s: does not match index"), name);
 
        status = load_patch_target(state, &buf, ce, &st, patch, name, mode);
@@ -3683,18 +3688,19 @@ static int check_preimage(struct apply_state *state,
        }
 
        if (state->check_index && !previous) {
-               int pos = cache_name_pos(old_name, strlen(old_name));
+               int pos = index_name_pos(state->repo->index, old_name,
+                                        strlen(old_name));
                if (pos < 0) {
                        if (patch->is_new < 0)
                                goto is_new;
                        return error(_("%s: does not exist in index"), old_name);
                }
-               *ce = active_cache[pos];
+               *ce = state->repo->index->cache[pos];
                if (stat_ret < 0) {
-                       if (checkout_target(&the_index, *ce, st))
+                       if (checkout_target(state->repo->index, *ce, st))
                                return -1;
                }
-               if (!state->cached && verify_index_match(*ce, st))
+               if (!state->cached && verify_index_match(state, *ce, st))
                        return error(_("%s: does not match index"), old_name);
                if (state->cached)
                        st_mode = (*ce)->ce_mode;
@@ -3738,7 +3744,7 @@ static int check_to_create(struct apply_state *state,
        struct stat nst;
 
        if (state->check_index &&
-           cache_name_pos(new_name, strlen(new_name)) >= 0 &&
+           index_name_pos(state->repo->index, new_name, strlen(new_name)) >= 0 &&
            !ok_if_exists)
                return EXISTS_IN_INDEX;
        if (state->cached)
@@ -3827,7 +3833,8 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *na
                if (state->check_index) {
                        struct cache_entry *ce;
 
-                       ce = cache_file_exists(name->buf, name->len, ignore_case);
+                       ce = index_file_exists(state->repo->index, name->buf,
+                                              name->len, ignore_case);
                        if (ce && S_ISLNK(ce->ce_mode))
                                return 1;
                } else {
@@ -4002,9 +4009,10 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)
 static int read_apply_cache(struct apply_state *state)
 {
        if (state->index_file)
-               return read_cache_from(state->index_file);
+               return read_index_from(state->repo->index, state->index_file,
+                                      get_git_dir());
        else
-               return read_cache();
+               return read_index(state->repo->index);
 }
 
 /* This function tries to read the object name from the current index */
@@ -4015,10 +4023,10 @@ static int get_current_oid(struct apply_state *state, const char *path,
 
        if (read_apply_cache(state) < 0)
                return -1;
-       pos = cache_name_pos(path, strlen(path));
+       pos = index_name_pos(state->repo->index, path, strlen(path));
        if (pos < 0)
                return -1;
-       oidcpy(oid, &active_cache[pos]->oid);
+       oidcpy(oid, &state->repo->index->cache[pos]->oid);
        return 0;
 }
 
@@ -4246,7 +4254,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
 static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
 {
        if (state->update_index && !state->ita_only) {
-               if (remove_file_from_cache(patch->old_name) < 0)
+               if (remove_file_from_index(state->repo->index, patch->old_name) < 0)
                        return error(_("unable to remove %s from index"), patch->old_name);
        }
        if (!state->cached) {
@@ -4267,7 +4275,7 @@ static int add_index_file(struct apply_state *state,
        struct cache_entry *ce;
        int namelen = strlen(path);
 
-       ce = make_empty_cache_entry(&the_index, namelen);
+       ce = make_empty_cache_entry(state->repo->index, namelen);
        memcpy(ce->name, path, namelen);
        ce->ce_mode = create_ce_mode(mode);
        ce->ce_flags = create_ce_flags(0);
@@ -4299,7 +4307,7 @@ static int add_index_file(struct apply_state *state,
                                       "for newly created file %s"), path);
                }
        }
-       if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
+       if (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
                discard_cache_entry(ce);
                return error(_("unable to add cache entry for %s"), path);
        }
@@ -4313,7 +4321,9 @@ static int add_index_file(struct apply_state *state,
  *   0 if everything went well
  *   1 if a recoverable error happened
  */
-static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
+static int try_create_file(struct apply_state *state, const char *path,
+                          unsigned int mode, const char *buf,
+                          unsigned long size)
 {
        int fd, res;
        struct strbuf nbuf = STRBUF_INIT;
@@ -4335,7 +4345,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
        if (fd < 0)
                return 1;
 
-       if (convert_to_working_tree(path, buf, size, &nbuf)) {
+       if (convert_to_working_tree(state->repo->index, path, buf, size, &nbuf)) {
                size = nbuf.len;
                buf  = nbuf.buf;
        }
@@ -4371,7 +4381,7 @@ static int create_one_file(struct apply_state *state,
        if (state->cached)
                return 0;
 
-       res = try_create_file(path, mode, buf, size);
+       res = try_create_file(state, path, mode, buf, size);
        if (res < 0)
                return -1;
        if (!res)
@@ -4380,7 +4390,7 @@ static int create_one_file(struct apply_state *state,
        if (errno == ENOENT) {
                if (safe_create_leading_directories(path))
                        return 0;
-               res = try_create_file(path, mode, buf, size);
+               res = try_create_file(state, path, mode, buf, size);
                if (res < 0)
                        return -1;
                if (!res)
@@ -4402,7 +4412,7 @@ static int create_one_file(struct apply_state *state,
                for (;;) {
                        char newpath[PATH_MAX];
                        mksnpath(newpath, sizeof(newpath), "%s~%u", path, nr);
-                       res = try_create_file(newpath, mode, buf, size);
+                       res = try_create_file(state, newpath, mode, buf, size);
                        if (res < 0)
                                return -1;
                        if (!res) {
@@ -4432,17 +4442,17 @@ static int add_conflicted_stages_file(struct apply_state *state,
        namelen = strlen(patch->new_name);
        mode = patch->new_mode ? patch->new_mode : (S_IFREG | 0644);
 
-       remove_file_from_cache(patch->new_name);
+       remove_file_from_index(state->repo->index, patch->new_name);
        for (stage = 1; stage < 4; stage++) {
                if (is_null_oid(&patch->threeway_stage[stage - 1]))
                        continue;
-               ce = make_empty_cache_entry(&the_index, namelen);
+               ce = make_empty_cache_entry(state->repo->index, namelen);
                memcpy(ce->name, patch->new_name, namelen);
                ce->ce_mode = create_ce_mode(mode);
                ce->ce_flags = create_ce_flags(stage);
                ce->ce_namelen = namelen;
                oidcpy(&ce->oid, &patch->threeway_stage[stage - 1]);
-               if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
+               if (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
                        discard_cache_entry(ce);
                        return error(_("unable to add cache entry for %s"),
                                     patch->new_name);
@@ -4891,7 +4901,7 @@ int apply_all_patches(struct apply_state *state,
        }
 
        if (state->update_index) {
-               res = write_locked_index(&the_index, &state->lock_file, COMMIT_LOCK);
+               res = write_locked_index(state->repo->index, &state->lock_file, COMMIT_LOCK);
                if (res) {
                        error(_("Unable to write new index file"));
                        res = -128;
diff --git a/apply.h b/apply.h
index b80d8ba73633c042989e52a00f7df8ee3afcd192..59483481330c61033d56e363f70dff08f4d689af 100644 (file)
--- a/apply.h
+++ b/apply.h
@@ -1,6 +1,11 @@
 #ifndef APPLY_H
 #define APPLY_H
 
+#include "lockfile.h"
+#include "string-list.h"
+
+struct repository;
+
 enum apply_ws_error_action {
        nowarn_ws_error,
        warn_on_ws_error,
@@ -62,6 +67,7 @@ struct apply_state {
        int unsafe_paths;
 
        /* Other non boolean parameters */
+       struct repository *repo;
        const char *index_file;
        enum apply_verbosity apply_verbosity;
        const char *fake_ancestor;
@@ -111,14 +117,15 @@ struct apply_state {
        int applied_after_fixing_ws;
 };
 
-extern int apply_parse_options(int argc, const char **argv,
-                              struct apply_state *state,
-                              int *force_apply, int *options,
-                              const char * const *apply_usage);
-extern int init_apply_state(struct apply_state *state,
-                           const char *prefix);
-extern void clear_apply_state(struct apply_state *state);
-extern int check_apply_state(struct apply_state *state, int force_apply);
+int apply_parse_options(int argc, const char **argv,
+                       struct apply_state *state,
+                       int *force_apply, int *options,
+                       const char * const *apply_usage);
+int init_apply_state(struct apply_state *state,
+                    struct repository *repo,
+                    const char *prefix);
+void clear_apply_state(struct apply_state *state);
+int check_apply_state(struct apply_state *state, int force_apply);
 
 /*
  * Some aspects of the apply behavior are controlled by the following
@@ -127,9 +134,8 @@ extern int check_apply_state(struct apply_state *state, int force_apply);
 #define APPLY_OPT_INACCURATE_EOF       (1<<0) /* accept inaccurate eof */
 #define APPLY_OPT_RECOUNT              (1<<1) /* accept inaccurate line count */
 
-extern int apply_all_patches(struct apply_state *state,
-                            int argc,
-                            const char **argv,
-                            int options);
+int apply_all_patches(struct apply_state *state,
+                     int argc, const char **argv,
+                     int options);
 
 #endif
index 0bc50f6e8944243c4f66659786beb63d6df48df6..7a535cba24a2a0535b412f1cfb3531ddde155c1e 100644 (file)
@@ -277,7 +277,7 @@ static int write_tar_entry(struct archiver_args *args,
                memcpy(header.name, path, pathlen);
 
        if (S_ISREG(mode) && !args->convert &&
-           oid_object_info(the_repository, oid, &size) == OBJ_BLOB &&
+           oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
            size > big_file_threshold)
                buffer = NULL;
        else if (S_ISLNK(mode) || S_ISREG(mode)) {
index 024267ff0f771a73d4e80dec32934a8e5b8455f5..5a62351ab1a46f6a0827a7d41e794c00a4839edc 100644 (file)
@@ -326,7 +326,7 @@ static int write_zip_entry(struct archiver_args *args,
                compressed_size = 0;
                buffer = NULL;
        } else if (S_ISREG(mode) || S_ISLNK(mode)) {
-               enum object_type type = oid_object_info(the_repository, oid,
+               enum object_type type = oid_object_info(args->repo, oid,
                                                        &size);
 
                method = 0;
index 78b0a398a0ff74e6d6d5afb2f7f0028b41fea32e..0a07b140fedd8fb1f14dd844dae9844641842c57 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -79,7 +79,7 @@ void *object_file_to_archive(const struct archiver_args *args,
                size_t size = 0;
 
                strbuf_attach(&buf, buffer, *sizep, *sizep + 1);
-               convert_to_working_tree(path, buf.buf, buf.len, &buf);
+               convert_to_working_tree(args->repo->index, path, buf.buf, buf.len, &buf);
                if (commit)
                        format_subst(commit, buf.buf, buf.len, &buf);
                buffer = strbuf_detach(&buf, &size);
@@ -104,12 +104,13 @@ struct archiver_context {
        struct directory *bottom;
 };
 
-static const struct attr_check *get_archive_attrs(const char *path)
+static const struct attr_check *get_archive_attrs(struct index_state *istate,
+                                                 const char *path)
 {
        static struct attr_check *check;
        if (!check)
                check = attr_check_initl("export-ignore", "export-subst", NULL);
-       return git_check_attr(path, check) ? NULL : check;
+       return git_check_attr(istate, path, check) ? NULL : check;
 }
 
 static int check_attr_export_ignore(const struct attr_check *check)
@@ -145,7 +146,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
 
        if (!S_ISDIR(mode)) {
                const struct attr_check *check;
-               check = get_archive_attrs(path_without_prefix);
+               check = get_archive_attrs(args->repo->index, path_without_prefix);
                if (check_attr_export_ignore(check))
                        return 0;
                args->convert = check_attr_export_subst(check);
@@ -220,7 +221,7 @@ static int queue_or_write_archive_entry(const struct object_id *oid,
                /* Borrow base, but restore its original value when done. */
                strbuf_addstr(base, filename);
                strbuf_addch(base, '/');
-               check = get_archive_attrs(base->buf);
+               check = get_archive_attrs(c->args->repo->index, base->buf);
                strbuf_setlen(base, baselen);
 
                if (check_attr_export_ignore(check))
@@ -268,13 +269,13 @@ int write_archive_entries(struct archiver_args *args,
                memset(&opts, 0, sizeof(opts));
                opts.index_only = 1;
                opts.head_idx = -1;
-               opts.src_index = &the_index;
-               opts.dst_index = &the_index;
+               opts.src_index = args->repo->index;
+               opts.dst_index = args->repo->index;
                opts.fn = oneway_merge;
                init_tree_desc(&t, args->tree->buffer, args->tree->size);
                if (unpack_trees(1, &t, &opts))
                        return -1;
-               git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
+               git_attr_set_direction(GIT_ATTR_INDEX);
        }
 
        err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
@@ -304,33 +305,43 @@ static const struct archiver *lookup_archiver(const char *name)
        return NULL;
 }
 
+struct path_exists_context {
+       struct pathspec pathspec;
+       struct archiver_args *args;
+};
+
 static int reject_entry(const struct object_id *oid, struct strbuf *base,
                        const char *filename, unsigned mode,
                        int stage, void *context)
 {
        int ret = -1;
+       struct path_exists_context *ctx = context;
+
        if (S_ISDIR(mode)) {
                struct strbuf sb = STRBUF_INIT;
                strbuf_addbuf(&sb, base);
                strbuf_addstr(&sb, filename);
-               if (!match_pathspec(context, sb.buf, sb.len, 0, NULL, 1))
+               if (!match_pathspec(ctx->args->repo->index,
+                                   &ctx->pathspec,
+                                   sb.buf, sb.len, 0, NULL, 1))
                        ret = READ_TREE_RECURSIVE;
                strbuf_release(&sb);
        }
        return ret;
 }
 
-static int path_exists(struct tree *tree, const char *path)
+static int path_exists(struct archiver_args *args, const char *path)
 {
        const char *paths[] = { path, NULL };
-       struct pathspec pathspec;
+       struct path_exists_context ctx;
        int ret;
 
-       parse_pathspec(&pathspec, 0, 0, "", paths);
-       pathspec.recursive = 1;
-       ret = read_tree_recursive(tree, "", 0, 0, &pathspec,
-                                 reject_entry, &pathspec);
-       clear_pathspec(&pathspec);
+       ctx.args = args;
+       parse_pathspec(&ctx.pathspec, 0, 0, "", paths);
+       ctx.pathspec.recursive = 1;
+       ret = read_tree_recursive(args->tree, "", 0, 0, &ctx.pathspec,
+                                 reject_entry, &ctx);
+       clear_pathspec(&ctx.pathspec);
        return ret != 0;
 }
 
@@ -348,7 +359,7 @@ static void parse_pathspec_arg(const char **pathspec,
        ar_args->pathspec.recursive = 1;
        if (pathspec) {
                while (*pathspec) {
-                       if (**pathspec && !path_exists(ar_args->tree, *pathspec))
+                       if (**pathspec && !path_exists(ar_args, *pathspec))
                                die(_("pathspec '%s' did not match any files"), *pathspec);
                        pathspec++;
                }
@@ -510,6 +521,7 @@ static int parse_archive_args(int argc, const char **argv,
 }
 
 int write_archive(int argc, const char **argv, const char *prefix,
+                 struct repository *repo,
                  const char *name_hint, int remote)
 {
        const struct archiver *ar = NULL;
@@ -521,6 +533,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
        init_tar_archiver();
        init_zip_archiver();
 
+       args.repo = repo;
        argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote);
        if (!startup_info->have_repository) {
                /*
index 1f9954f7cdc5a1ee8036321e439a65bdfb90e59f..d4f97a00f541c66b694ff00340ead218752bf37e 100644 (file)
--- a/archive.h
+++ b/archive.h
@@ -1,9 +1,13 @@
 #ifndef ARCHIVE_H
 #define ARCHIVE_H
 
+#include "cache.h"
 #include "pathspec.h"
 
+struct repository;
+
 struct archiver_args {
+       struct repository *repo;
        const char *base;
        size_t baselen;
        struct tree *tree;
@@ -17,6 +21,16 @@ struct archiver_args {
        int compression_level;
 };
 
+/* main api */
+
+extern int write_archive(int argc, const char **argv, const char *prefix,
+                        struct repository *repo,
+                        const char *name_hint, int remote);
+
+const char *archive_format_from_filename(const char *filename);
+
+/* archive backend stuff */
+
 #define ARCHIVER_WANT_COMPRESSION_LEVELS 1
 #define ARCHIVER_REMOTE 2
 struct archiver {
@@ -36,9 +50,6 @@ typedef int (*write_archive_entry_fn_t)(struct archiver_args *args,
                                        unsigned int mode);
 
 extern int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
-extern int write_archive(int argc, const char **argv, const char *prefix, const char *name_hint, int remote);
-
-const char *archive_format_from_filename(const char *filename);
 extern void *object_file_to_archive(const struct archiver_args *args,
                                    const char *path, const struct object_id *oid,
                                    unsigned int mode, enum object_type *type,
diff --git a/attr.c b/attr.c
index 067fb9e0c08cefa2ba1a9b1d3444938c9bab6e3d..98e4953f6e87f5f5ff777ee57cedf705086e109e 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -708,10 +708,8 @@ static struct attr_stack *read_attr_from_array(const char **list)
  * another thread could potentially be calling into the attribute system.
  */
 static enum git_attr_direction direction;
-static struct index_state *use_index;
 
-void git_attr_set_direction(enum git_attr_direction new_direction,
-                           struct index_state *istate)
+void git_attr_set_direction(enum git_attr_direction new_direction)
 {
        if (is_bare_repository() && new_direction != GIT_ATTR_INDEX)
                BUG("non-INDEX attr direction in a bare repo");
@@ -720,7 +718,6 @@ void git_attr_set_direction(enum git_attr_direction new_direction,
                drop_all_attr_stacks();
 
        direction = new_direction;
-       use_index = istate;
 }
 
 static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
@@ -743,13 +740,18 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
        return res;
 }
 
-static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)
+static struct attr_stack *read_attr_from_index(const struct index_state *istate,
+                                              const char *path,
+                                              int macro_ok)
 {
        struct attr_stack *res;
        char *buf, *sp;
        int lineno = 0;
 
-       buf = read_blob_data_from_index(use_index ? use_index : &the_index, path, NULL);
+       if (!istate)
+               return NULL;
+
+       buf = read_blob_data_from_index(istate, path, NULL);
        if (!buf)
                return NULL;
 
@@ -768,15 +770,16 @@ static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)
        return res;
 }
 
-static struct attr_stack *read_attr(const char *path, int macro_ok)
+static struct attr_stack *read_attr(const struct index_state *istate,
+                                   const char *path, int macro_ok)
 {
        struct attr_stack *res = NULL;
 
        if (direction == GIT_ATTR_INDEX) {
-               res = read_attr_from_index(path, macro_ok);
+               res = read_attr_from_index(istate, path, macro_ok);
        } else if (!is_bare_repository()) {
                if (direction == GIT_ATTR_CHECKOUT) {
-                       res = read_attr_from_index(path, macro_ok);
+                       res = read_attr_from_index(istate, path, macro_ok);
                        if (!res)
                                res = read_attr_from_file(path, macro_ok);
                } else if (direction == GIT_ATTR_CHECKIN) {
@@ -788,7 +791,7 @@ static struct attr_stack *read_attr(const char *path, int macro_ok)
                                 * We allow operation in a sparsely checked out
                                 * work tree, so read from it.
                                 */
-                               res = read_attr_from_index(path, macro_ok);
+                               res = read_attr_from_index(istate, path, macro_ok);
                }
        }
 
@@ -859,7 +862,8 @@ static void push_stack(struct attr_stack **attr_stack_p,
        }
 }
 
-static void bootstrap_attr_stack(struct attr_stack **stack)
+static void bootstrap_attr_stack(const struct index_state *istate,
+                                struct attr_stack **stack)
 {
        struct attr_stack *e;
 
@@ -883,7 +887,7 @@ static void bootstrap_attr_stack(struct attr_stack **stack)
        }
 
        /* root directory */
-       e = read_attr(GITATTRIBUTES_FILE, 1);
+       e = read_attr(istate, GITATTRIBUTES_FILE, 1);
        push_stack(stack, e, xstrdup(""), 0);
 
        /* info frame */
@@ -896,7 +900,8 @@ static void bootstrap_attr_stack(struct attr_stack **stack)
        push_stack(stack, e, NULL, 0);
 }
 
-static void prepare_attr_stack(const char *path, int dirlen,
+static void prepare_attr_stack(const struct index_state *istate,
+                              const char *path, int dirlen,
                               struct attr_stack **stack)
 {
        struct attr_stack *info;
@@ -917,7 +922,7 @@ static void prepare_attr_stack(const char *path, int dirlen,
         * .gitattributes in deeper directories to shallower ones,
         * and finally use the built-in set as the default.
         */
-       bootstrap_attr_stack(stack);
+       bootstrap_attr_stack(istate, stack);
 
        /*
         * Pop the "info" one that is always at the top of the stack.
@@ -973,7 +978,7 @@ static void prepare_attr_stack(const char *path, int dirlen,
                strbuf_add(&pathbuf, path + pathbuf.len, (len - pathbuf.len));
                strbuf_addf(&pathbuf, "/%s", GITATTRIBUTES_FILE);
 
-               next = read_attr(pathbuf.buf, 0);
+               next = read_attr(istate, pathbuf.buf, 0);
 
                /* reset the pathbuf to not include "/.gitattributes" */
                strbuf_setlen(&pathbuf, len);
@@ -1095,7 +1100,9 @@ static void determine_macros(struct all_attrs_item *all_attrs,
  * If check->check_nr is non-zero, only attributes in check[] are collected.
  * Otherwise all attributes are collected.
  */
-static void collect_some_attrs(const char *path, struct attr_check *check)
+static void collect_some_attrs(const struct index_state *istate,
+                              const char *path,
+                              struct attr_check *check)
 {
        int i, pathlen, rem, dirlen;
        const char *cp, *last_slash = NULL;
@@ -1114,7 +1121,7 @@ static void collect_some_attrs(const char *path, struct attr_check *check)
                dirlen = 0;
        }
 
-       prepare_attr_stack(path, dirlen, &check->stack);
+       prepare_attr_stack(istate, path, dirlen, &check->stack);
        all_attrs_init(&g_attr_hashmap, check);
        determine_macros(check->all_attrs, check->stack);
 
@@ -1136,11 +1143,13 @@ static void collect_some_attrs(const char *path, struct attr_check *check)
        fill(path, pathlen, basename_offset, check->stack, check->all_attrs, rem);
 }
 
-int git_check_attr(const char *path, struct attr_check *check)
+int git_check_attr(const struct index_state *istate,
+                  const char *path,
+                  struct attr_check *check)
 {
        int i;
 
-       collect_some_attrs(path, check);
+       collect_some_attrs(istate, path, check);
 
        for (i = 0; i < check->nr; i++) {
                size_t n = check->items[i].attr->attr_nr;
@@ -1153,12 +1162,13 @@ int git_check_attr(const char *path, struct attr_check *check)
        return 0;
 }
 
-void git_all_attrs(const char *path, struct attr_check *check)
+void git_all_attrs(const struct index_state *istate,
+                  const char *path, struct attr_check *check)
 {
        int i;
 
        attr_check_reset(check);
-       collect_some_attrs(path, check);
+       collect_some_attrs(istate, path, check);
 
        for (i = 0; i < check->all_attrs_nr; i++) {
                const char *name = check->all_attrs[i].attr->name;
diff --git a/attr.h b/attr.h
index 442d464db6271da48a4ef133127c7d3a18c186cf..2be86db36e730938777066f1951360396ddc9676 100644 (file)
--- a/attr.h
+++ b/attr.h
@@ -1,12 +1,15 @@
 #ifndef ATTR_H
 #define ATTR_H
 
+struct index_state;
+
 /* An attribute is a pointer to this opaque structure */
 struct git_attr;
 
 /* opaque structures used internally for attribute collection */
 struct all_attrs_item;
 struct attr_stack;
+struct index_state;
 
 /*
  * Given a string, return the gitattribute object that
@@ -42,40 +45,41 @@ struct attr_check {
        struct attr_stack *stack;
 };
 
-extern struct attr_check *attr_check_alloc(void);
-extern struct attr_check *attr_check_initl(const char *, ...);
-extern struct attr_check *attr_check_dup(const struct attr_check *check);
+struct attr_check *attr_check_alloc(void);
+struct attr_check *attr_check_initl(const char *, ...);
+struct attr_check *attr_check_dup(const struct attr_check *check);
 
-extern struct attr_check_item *attr_check_append(struct attr_check *check,
-                                                const struct git_attr *attr);
+struct attr_check_item *attr_check_append(struct attr_check *check,
+                                         const struct git_attr *attr);
 
-extern void attr_check_reset(struct attr_check *check);
-extern void attr_check_clear(struct attr_check *check);
-extern void attr_check_free(struct attr_check *check);
+void attr_check_reset(struct attr_check *check);
+void attr_check_clear(struct attr_check *check);
+void attr_check_free(struct attr_check *check);
 
 /*
  * Return the name of the attribute represented by the argument.  The
  * return value is a pointer to a null-delimited string that is part
  * of the internal data structure; it should not be modified or freed.
  */
-extern const char *git_attr_name(const struct git_attr *);
+const char *git_attr_name(const struct git_attr *);
 
-extern int git_check_attr(const char *path, struct attr_check *check);
+int git_check_attr(const struct index_state *istate,
+                  const char *path, struct attr_check *check);
 
 /*
  * Retrieve all attributes that apply to the specified path.
  * check holds the attributes and their values.
  */
-extern void git_all_attrs(const char *path, struct attr_check *check);
+void git_all_attrs(const struct index_state *istate,
+                  const char *path, struct attr_check *check);
 
 enum git_attr_direction {
        GIT_ATTR_CHECKIN,
        GIT_ATTR_CHECKOUT,
        GIT_ATTR_INDEX
 };
-void git_attr_set_direction(enum git_attr_direction new_direction,
-                           struct index_state *istate);
+void git_attr_set_direction(enum git_attr_direction new_direction);
 
-extern void attr_start(void);
+void attr_start(void);
 
 #endif /* ATTR_H */
index a5d9248a47675194e7e0d16aed37018cbb67eb33..34df20935123065b4b253288ea0e22b1721af0e9 100644 (file)
--- a/bisect.h
+++ b/bisect.h
@@ -1,6 +1,8 @@
 #ifndef BISECT_H
 #define BISECT_H
 
+struct commit_list;
+
 /*
  * Find bisection. If something is found, `reaches` will be the number of
  * commits that the best commit reaches. `all` will be the count of
diff --git a/blame.c b/blame.c
index 58a7036847d9be574bbc3863d7ba4deb548628b7..08c0c6cf73c349a2b7ad6fe129443852318a5044 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -90,7 +90,8 @@ static struct blame_origin *get_origin(struct commit *commit, const char *path)
 
 
 
-static void verify_working_tree_path(struct commit *work_tree, const char *path)
+static void verify_working_tree_path(struct repository *repo,
+                                    struct commit *work_tree, const char *path)
 {
        struct commit_list *parents;
        int pos;
@@ -101,15 +102,15 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
                unsigned mode;
 
                if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
-                   oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB)
+                   oid_object_info(repo, &blob_oid, NULL) == OBJ_BLOB)
                        return;
        }
 
-       pos = cache_name_pos(path, strlen(path));
+       pos = index_name_pos(repo->index, path, strlen(path));
        if (pos >= 0)
                ; /* path is in the index */
-       else if (-1 - pos < active_nr &&
-                !strcmp(active_cache[-1 - pos]->name, path))
+       else if (-1 - pos < repo->index->cache_nr &&
+                !strcmp(repo->index->cache[-1 - pos]->name, path))
                ; /* path is in the index, unmerged */
        else
                die("no such path '%s' in HEAD", path);
@@ -165,7 +166,8 @@ static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
  * Prepare a dummy commit that represents the work tree (or staged) item.
  * Note that annotating work tree item never works in the reverse.
  */
-static struct commit *fake_working_tree_commit(struct diff_options *opt,
+static struct commit *fake_working_tree_commit(struct repository *repo,
+                                              struct diff_options *opt,
                                               const char *path,
                                               const char *contents_from)
 {
@@ -181,7 +183,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
        unsigned mode;
        struct strbuf msg = STRBUF_INIT;
 
-       read_cache();
+       read_index(repo->index);
        time(&now);
        commit = alloc_commit_node(the_repository);
        commit->object.parsed = 1;
@@ -193,7 +195,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 
        parent_tail = append_parent(parent_tail, &head_oid);
        append_merge_parents(parent_tail);
-       verify_working_tree_path(commit, path);
+       verify_working_tree_path(repo, commit, path);
 
        origin = make_origin(commit, path);
 
@@ -251,7 +253,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
                if (strbuf_read(&buf, 0, 0) < 0)
                        die_errno("failed to read from stdin");
        }
-       convert_to_git(&the_index, path, buf.buf, buf.len, &buf, 0);
+       convert_to_git(repo->index, path, buf.buf, buf.len, &buf, 0);
        origin->file.ptr = buf.buf;
        origin->file.size = buf.len;
        pretend_object_file(buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
@@ -262,27 +264,28 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
         * bits; we are not going to write this index out -- we just
         * want to run "diff-index --cached".
         */
-       discard_cache();
-       read_cache();
+       discard_index(repo->index);
+       read_index(repo->index);
 
        len = strlen(path);
        if (!mode) {
-               int pos = cache_name_pos(path, len);
+               int pos = index_name_pos(repo->index, path, len);
                if (0 <= pos)
-                       mode = active_cache[pos]->ce_mode;
+                       mode = repo->index->cache[pos]->ce_mode;
                else
                        /* Let's not bother reading from HEAD tree */
                        mode = S_IFREG | 0644;
        }
-       ce = make_empty_cache_entry(&the_index, len);
+       ce = make_empty_cache_entry(repo->index, len);
        oidcpy(&ce->oid, &origin->blob_oid);
        memcpy(ce->name, path, len);
        ce->ce_flags = create_ce_flags(0);
        ce->ce_namelen = len;
        ce->ce_mode = create_ce_mode(mode);
-       add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
+       add_index_entry(repo->index, ce,
+                       ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
 
-       cache_tree_invalidate_path(&the_index, path);
+       cache_tree_invalidate_path(repo->index, path);
 
        return commit;
 }
@@ -519,13 +522,14 @@ static void queue_blames(struct blame_scoreboard *sb, struct blame_origin *porig
  *
  * This also fills origin->mode for corresponding tree path.
  */
-static int fill_blob_sha1_and_mode(struct blame_origin *origin)
+static int fill_blob_sha1_and_mode(struct repository *repo,
+                                  struct blame_origin *origin)
 {
        if (!is_null_oid(&origin->blob_oid))
                return 0;
        if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
                goto error_out;
-       if (oid_object_info(the_repository, &origin->blob_oid, NULL) != OBJ_BLOB)
+       if (oid_object_info(repo, &origin->blob_oid, NULL) != OBJ_BLOB)
                goto error_out;
        return 0;
  error_out:
@@ -1767,7 +1771,9 @@ void init_scoreboard(struct blame_scoreboard *sb)
        sb->copy_score = BLAME_DEFAULT_COPY_SCORE;
 }
 
-void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blame_origin **orig)
+void setup_scoreboard(struct blame_scoreboard *sb,
+                     const char *path,
+                     struct blame_origin **orig)
 {
        const char *final_commit_name = NULL;
        struct blame_origin *o;
@@ -1779,6 +1785,9 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
        if (sb->reverse && sb->contents_from)
                die(_("--contents and --reverse do not blend well."));
 
+       if (!sb->repo)
+               BUG("repo is NULL");
+
        if (!sb->reverse) {
                sb->final = find_single_final(sb->revs, &final_commit_name);
                sb->commits.compare = compare_commits_by_commit_date;
@@ -1800,7 +1809,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
                 * or "--contents".
                 */
                setup_work_tree();
-               sb->final = fake_working_tree_commit(&sb->revs->diffopt,
+               sb->final = fake_working_tree_commit(sb->repo,
+                                                    &sb->revs->diffopt,
                                                     path, sb->contents_from);
                add_pending_object(sb->revs, &(sb->final->object), ":");
        }
@@ -1845,7 +1855,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
        }
        else {
                o = get_origin(sb->final, path);
-               if (fill_blob_sha1_and_mode(o))
+               if (fill_blob_sha1_and_mode(sb->repo, o))
                        die(_("no such path %s in %s"), path, final_commit_name);
 
                if (sb->revs->diffopt.flags.allow_textconv &&
diff --git a/blame.h b/blame.h
index 2092f9529c108d40100ec2a8175098edc8e8e5dd..be3a895043e07a2508d407ac35e74d634acd7886 100644 (file)
--- a/blame.h
+++ b/blame.h
@@ -102,6 +102,7 @@ struct blame_scoreboard {
        struct commit *final;
        /* Priority queue for commits with unassigned blame records */
        struct prio_queue commits;
+       struct repository *repo;
        struct rev_info *revs;
        const char *path;
 
@@ -159,18 +160,22 @@ static inline struct blame_origin *blame_origin_incref(struct blame_origin *o)
                o->refcnt++;
        return o;
 }
-extern void blame_origin_decref(struct blame_origin *o);
-
-extern void blame_coalesce(struct blame_scoreboard *sb);
-extern void blame_sort_final(struct blame_scoreboard *sb);
-extern unsigned blame_entry_score(struct blame_scoreboard *sb, struct blame_entry *e);
-extern void assign_blame(struct blame_scoreboard *sb, int opt);
-extern const char *blame_nth_line(struct blame_scoreboard *sb, long lno);
-
-extern void init_scoreboard(struct blame_scoreboard *sb);
-extern void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blame_origin **orig);
-
-extern struct blame_entry *blame_entry_prepend(struct blame_entry *head, long start, long end, struct blame_origin *o);
+void blame_origin_decref(struct blame_origin *o);
+
+void blame_coalesce(struct blame_scoreboard *sb);
+void blame_sort_final(struct blame_scoreboard *sb);
+unsigned blame_entry_score(struct blame_scoreboard *sb, struct blame_entry *e);
+void assign_blame(struct blame_scoreboard *sb, int opt);
+const char *blame_nth_line(struct blame_scoreboard *sb, long lno);
+
+void init_scoreboard(struct blame_scoreboard *sb);
+void setup_scoreboard(struct blame_scoreboard *sb,
+                     const char *path,
+                     struct blame_origin **orig);
+
+struct blame_entry *blame_entry_prepend(struct blame_entry *head,
+                                       long start, long end,
+                                       struct blame_origin *o);
 
 extern struct blame_origin *get_blame_suspects(struct commit *commit);
 
index 473d0a93e910d8f053e6e8c919e430048a3033a0..5cace4581fe43aa5fdc20b4315cee6eff1034003 100644 (file)
--- a/branch.h
+++ b/branch.h
@@ -1,6 +1,19 @@
 #ifndef BRANCH_H
 #define BRANCH_H
 
+struct strbuf;
+
+enum branch_track {
+       BRANCH_TRACK_UNSPECIFIED = -1,
+       BRANCH_TRACK_NEVER = 0,
+       BRANCH_TRACK_REMOTE,
+       BRANCH_TRACK_ALWAYS,
+       BRANCH_TRACK_EXPLICIT,
+       BRANCH_TRACK_OVERRIDE
+};
+
+extern enum branch_track git_branch_track;
+
 /* Functions for acting on the information about branches. */
 
 /*
index 0362f1ce25fb64631e28f00eafa46f35bc94c7eb..99206df4bd43fc0c4ff8db538912dec1c600c397 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -201,6 +201,7 @@ extern int cmd_prune(int argc, const char **argv, const char *prefix);
 extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
 extern int cmd_pull(int argc, const char **argv, const char *prefix);
 extern int cmd_push(int argc, const char **argv, const char *prefix);
+extern int cmd_range_diff(int argc, const char **argv, const char *prefix);
 extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
 extern int cmd_rebase__helper(int argc, const char **argv, const char *prefix);
 extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
index 8a155dd41eccd8004a55b1302111293ae59ea542..9916498a29bbd8fa7c5c5d8e7bd32e1dc184909b 100644 (file)
@@ -40,7 +40,7 @@ static void chmod_pathspec(struct pathspec *pathspec, char flip)
        for (i = 0; i < active_nr; i++) {
                struct cache_entry *ce = active_cache[i];
 
-               if (pathspec && !ce_path_match(ce, pathspec, NULL))
+               if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
                        continue;
 
                if (chmod_cache_entry(ce, flip) < 0)
@@ -135,7 +135,7 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
                        continue; /* do not touch unmerged paths */
                if (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))
                        continue; /* do not touch non blobs */
-               if (pathspec && !ce_path_match(ce, pathspec, NULL))
+               if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
                        continue;
                retval |= add_file_to_cache(ce->name, flags | HASH_RENORMALIZE);
        }
@@ -155,7 +155,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
        i = dir->nr;
        while (--i >= 0) {
                struct dir_entry *entry = *src++;
-               if (dir_path_match(entry, pathspec, prefix, seen))
+               if (dir_path_match(&the_index, entry, pathspec, prefix, seen))
                        *dst++ = entry;
        }
        dir->nr = dst - dir->entries;
@@ -304,7 +304,8 @@ static struct option builtin_add_options[] = {
        OPT_BOOL( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")),
        OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
        OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
-       OPT_STRING( 0 , "chmod", &chmod_arg, N_("(+/-)x"), N_("override the executable bit of the listed files")),
+       OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
+                  N_("override the executable bit of the listed files")),
        OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
                        N_("warn when adding an embedded repository")),
        OPT_END(),
index 2c19e69f585a46330718ddea1c13a095cefe9d19..9f7ecf6ecb7711c35277fa827c4c2afc0dfba867 100644 (file)
@@ -1464,7 +1464,7 @@ static int run_apply(const struct am_state *state, const char *index_file)
        int force_apply = 0;
        int options = 0;
 
-       if (init_apply_state(&apply_state, NULL))
+       if (init_apply_state(&apply_state, the_repository, NULL))
                BUG("init_apply_state() failed");
 
        argv_array_push(&apply_opts, "apply");
index 48d3989331d9b7deeb034642a027729bd1267e38..3f099b960565ff2944209ba514ea7274dad852f5 100644 (file)
@@ -16,7 +16,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
        int ret;
        struct apply_state state;
 
-       if (init_apply_state(&state, prefix))
+       if (init_apply_state(&state, the_repository, prefix))
                exit(128);
 
        argc = apply_parse_options(argc, argv,
index 73971d0dd20e7233d6cb1e6c16986ede25526939..e74f675390d975e3a8993037796aa6ef2f975cb7 100644 (file)
@@ -105,5 +105,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 
        setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
 
-       return write_archive(argc, argv, prefix, output, 0);
+       return write_archive(argc, argv, prefix, the_repository, output, 0);
 }
index 97f6ecaf370dfdda1f0a9e5a1fe824a034fdbf61..c2da673ac802b02609d54de3932fa8a2db221dbd 100644 (file)
@@ -988,6 +988,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        sb.revs = &revs;
        sb.contents_from = contents_from;
        sb.reverse = reverse;
+       sb.repo = the_repository;
        setup_scoreboard(&sb, path, &o);
        lno = sb.num_lines;
 
index 4a44b2404fb36bb01758cc68964799a0438d5933..64ec1745ab2c20ef18a9292ef3b3c82efd46de17 100644 (file)
@@ -21,6 +21,7 @@ struct batch_options {
        int print_contents;
        int buffer_output;
        int all_objects;
+       int unordered;
        int cmdmode; /* may be 'w' or 'c' for --filters or --textconv */
        const char *format;
 };
@@ -39,7 +40,7 @@ static int filter_object(const char *path, unsigned mode,
                             oid_to_hex(oid), path);
        if ((type == OBJ_BLOB) && S_ISREG(mode)) {
                struct strbuf strbuf = STRBUF_INIT;
-               if (convert_to_working_tree(path, *buf, *size, &strbuf)) {
+               if (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf)) {
                        free(*buf);
                        *size = strbuf.len;
                        *buf = strbuf_detach(&strbuf, NULL);
@@ -337,11 +338,11 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
        }
 }
 
-static void batch_object_write(const char *obj_name, struct batch_options *opt,
+static void batch_object_write(const char *obj_name,
+                              struct strbuf *scratch,
+                              struct batch_options *opt,
                               struct expand_data *data)
 {
-       struct strbuf buf = STRBUF_INIT;
-
        if (!data->skip_object_info &&
            oid_object_info_extended(the_repository, &data->oid, &data->info,
                                     OBJECT_INFO_LOOKUP_REPLACE) < 0) {
@@ -351,10 +352,10 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
                return;
        }
 
-       strbuf_expand(&buf, opt->format, expand_format, data);
-       strbuf_addch(&buf, '\n');
-       batch_write(opt, buf.buf, buf.len);
-       strbuf_release(&buf);
+       strbuf_reset(scratch);
+       strbuf_expand(scratch, opt->format, expand_format, data);
+       strbuf_addch(scratch, '\n');
+       batch_write(opt, scratch->buf, scratch->len);
 
        if (opt->print_contents) {
                print_object_or_die(opt, data);
@@ -362,7 +363,9 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
        }
 }
 
-static void batch_one_object(const char *obj_name, struct batch_options *opt,
+static void batch_one_object(const char *obj_name,
+                            struct strbuf *scratch,
+                            struct batch_options *opt,
                             struct expand_data *data)
 {
        struct object_context ctx;
@@ -404,42 +407,70 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt,
                return;
        }
 
-       batch_object_write(obj_name, opt, data);
+       batch_object_write(obj_name, scratch, opt, data);
 }
 
 struct object_cb_data {
        struct batch_options *opt;
        struct expand_data *expand;
+       struct oidset *seen;
+       struct strbuf *scratch;
 };
 
 static int batch_object_cb(const struct object_id *oid, void *vdata)
 {
        struct object_cb_data *data = vdata;
        oidcpy(&data->expand->oid, oid);
-       batch_object_write(NULL, data->opt, data->expand);
+       batch_object_write(NULL, data->scratch, data->opt, data->expand);
        return 0;
 }
 
-static int batch_loose_object(const struct object_id *oid,
-                             const char *path,
-                             void *data)
+static int collect_loose_object(const struct object_id *oid,
+                               const char *path,
+                               void *data)
 {
        oid_array_append(data, oid);
        return 0;
 }
 
-static int batch_packed_object(const struct object_id *oid,
-                              struct packed_git *pack,
-                              uint32_t pos,
-                              void *data)
+static int collect_packed_object(const struct object_id *oid,
+                                struct packed_git *pack,
+                                uint32_t pos,
+                                void *data)
 {
        oid_array_append(data, oid);
        return 0;
 }
 
+static int batch_unordered_object(const struct object_id *oid, void *vdata)
+{
+       struct object_cb_data *data = vdata;
+
+       if (oidset_insert(data->seen, oid))
+               return 0;
+
+       return batch_object_cb(oid, data);
+}
+
+static int batch_unordered_loose(const struct object_id *oid,
+                                const char *path,
+                                void *data)
+{
+       return batch_unordered_object(oid, data);
+}
+
+static int batch_unordered_packed(const struct object_id *oid,
+                                 struct packed_git *pack,
+                                 uint32_t pos,
+                                 void *data)
+{
+       return batch_unordered_object(oid, data);
+}
+
 static int batch_objects(struct batch_options *opt)
 {
-       struct strbuf buf = STRBUF_INIT;
+       struct strbuf input = STRBUF_INIT;
+       struct strbuf output = STRBUF_INIT;
        struct expand_data data;
        int save_warning;
        int retval = 0;
@@ -454,8 +485,9 @@ static int batch_objects(struct batch_options *opt)
         */
        memset(&data, 0, sizeof(data));
        data.mark_query = 1;
-       strbuf_expand(&buf, opt->format, expand_format, &data);
+       strbuf_expand(&output, opt->format, expand_format, &data);
        data.mark_query = 0;
+       strbuf_release(&output);
        if (opt->cmdmode)
                data.split_on_whitespace = 1;
 
@@ -473,19 +505,37 @@ static int batch_objects(struct batch_options *opt)
                data.info.typep = &data.type;
 
        if (opt->all_objects) {
-               struct oid_array sa = OID_ARRAY_INIT;
                struct object_cb_data cb;
 
-               for_each_loose_object(batch_loose_object, &sa, 0);
-               for_each_packed_object(batch_packed_object, &sa, 0);
                if (repository_format_partial_clone)
                        warning("This repository has extensions.partialClone set. Some objects may not be loaded.");
 
                cb.opt = opt;
                cb.expand = &data;
-               oid_array_for_each_unique(&sa, batch_object_cb, &cb);
+               cb.scratch = &output;
+
+               if (opt->unordered) {
+                       struct oidset seen = OIDSET_INIT;
+
+                       cb.seen = &seen;
+
+                       for_each_loose_object(batch_unordered_loose, &cb, 0);
+                       for_each_packed_object(batch_unordered_packed, &cb,
+                                              FOR_EACH_OBJECT_PACK_ORDER);
+
+                       oidset_clear(&seen);
+               } else {
+                       struct oid_array sa = OID_ARRAY_INIT;
+
+                       for_each_loose_object(collect_loose_object, &sa, 0);
+                       for_each_packed_object(collect_packed_object, &sa, 0);
+
+                       oid_array_for_each_unique(&sa, batch_object_cb, &cb);
+
+                       oid_array_clear(&sa);
+               }
 
-               oid_array_clear(&sa);
+               strbuf_release(&output);
                return 0;
        }
 
@@ -499,14 +549,14 @@ static int batch_objects(struct batch_options *opt)
        save_warning = warn_on_object_refname_ambiguity;
        warn_on_object_refname_ambiguity = 0;
 
-       while (strbuf_getline(&buf, stdin) != EOF) {
+       while (strbuf_getline(&input, stdin) != EOF) {
                if (data.split_on_whitespace) {
                        /*
                         * Split at first whitespace, tying off the beginning
                         * of the string and saving the remainder (or NULL) in
                         * data.rest.
                         */
-                       char *p = strpbrk(buf.buf, " \t");
+                       char *p = strpbrk(input.buf, " \t");
                        if (p) {
                                while (*p && strchr(" \t", *p))
                                        *p++ = '\0';
@@ -514,10 +564,11 @@ static int batch_objects(struct batch_options *opt)
                        data.rest = p;
                }
 
-               batch_one_object(buf.buf, opt, &data);
+               batch_one_object(input.buf, &output, opt, &data);
        }
 
-       strbuf_release(&buf);
+       strbuf_release(&input);
+       strbuf_release(&output);
        warn_on_object_refname_ambiguity = save_warning;
        return retval;
 }
@@ -586,6 +637,8 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
                         N_("follow in-tree symlinks (used with --batch or --batch-check)")),
                OPT_BOOL(0, "batch-all-objects", &batch.all_objects,
                         N_("show all objects with --batch or --batch-check")),
+               OPT_BOOL(0, "unordered", &batch.unordered,
+                        N_("do not order --batch-all-objects output")),
                OPT_END()
        };
 
index 91444dc0448b32e854f1923fe1e57e28c87f5b35..c05573ff9cd091cbe3b5ff1980fa7fb4815f6ebd 100644 (file)
@@ -63,9 +63,9 @@ static void check_attr(const char *prefix,
                prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
 
        if (collect_all) {
-               git_all_attrs(full_path, check);
+               git_all_attrs(&the_index, full_path, check);
        } else {
-               if (git_check_attr(full_path, check))
+               if (git_check_attr(&the_index, full_path, check))
                        die("git_check_attr died");
        }
        output_attr(check, file);
@@ -120,7 +120,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
        }
 
        if (cached_attrs)
-               git_attr_set_direction(GIT_ATTR_INDEX, NULL);
+               git_attr_set_direction(GIT_ATTR_INDEX);
 
        doubledash = -1;
        for (i = 0; doubledash < 0 && i < argc; i++) {
index a730f6a1aa47a60d4c131ee47076411a129d8080..d92db62fbdf15c14ff3d85b767a069b22aa3897d 100644 (file)
@@ -190,6 +190,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
 
        argc = parse_options(argc, argv, prefix, builtin_checkout_index_options,
                        builtin_checkout_index_usage, 0);
+       state.istate = &the_index;
        state.force = force;
        state.quiet = quiet;
        state.not_new = not_new;
index cb6bb76312a00cbcf997ef44e43128964777e86e..29ef50013dccbd118093af0b4dc08eb907953cc2 100644 (file)
@@ -318,7 +318,7 @@ static int checkout_paths(const struct checkout_opts *opts,
                 * match_pathspec() for _all_ entries when
                 * opts->source_tree != NULL.
                 */
-               if (ce_path_match(ce, &opts->pathspec, ps_matched))
+               if (ce_path_match(&the_index, ce, &opts->pathspec, ps_matched))
                        ce->ce_flags |= CE_MATCHED;
        }
 
index ab402c204cbcaea6190608753311605d37ca83d2..8d9a7dc20647079bc5f35b446bbbab5479abb32d 100644 (file)
@@ -976,7 +976,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
                        continue;
 
                if (pathspec.nr)
-                       matches = dir_path_match(ent, &pathspec, 0, NULL);
+                       matches = dir_path_match(&the_index, ent, &pathspec, 0, NULL);
 
                if (pathspec.nr && !matches)
                        continue;
index 213fca2d8ecdf726661e6b31b7ec6cb004acb2f7..0d9828e29ebe89f037e68761d5cd5b407339cd48 100644 (file)
@@ -251,7 +251,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
 
                if (ce->ce_flags & CE_UPDATE)
                        continue;
-               if (!ce_path_match(ce, pattern, m))
+               if (!ce_path_match(&the_index, ce, pattern, m))
                        continue;
                item = string_list_insert(list, ce->name);
                if (ce_skip_worktree(ce))
index 91ba67070e252fa13a0e32e08a251ca58c7f930b..d07bf2e4c4b5c2ec2f93930c0dd16897df32b25f 100644 (file)
@@ -163,9 +163,11 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
                int saved_nrl = 0;
                int saved_dcctc = 0;
 
-               if (opt->diffopt.detect_rename)
-                       opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
-                                              DIFF_SETUP_USE_CACHE);
+               if (opt->diffopt.detect_rename) {
+                       if (!the_index.cache)
+                               read_index(&the_index);
+                       opt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;
+               }
                while (fgets(line, sizeof(line), stdin)) {
                        struct object_id oid;
 
index 3018e61d048dacd178200ce380e319ae302b5790..cdd585ca76d51f6d5dcca78a9e1dfa6f8102c476 100644 (file)
@@ -703,7 +703,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
                        1, PARSE_OPT_NONEG | PARSE_OPT_HIDDEN),
                OPT_BOOL(0, "symlinks", &symlinks,
                         N_("use symlinks in dir-diff mode")),
-               OPT_STRING('t', "tool", &difftool_cmd, N_("<tool>"),
+               OPT_STRING('t', "tool", &difftool_cmd, N_("tool"),
                           N_("use the specified diff tool")),
                OPT_BOOL(0, "tool-help", &tool_help,
                         N_("print a list of diff tools that may be used with "
@@ -711,7 +711,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
                OPT_BOOL(0, "trust-exit-code", &trust_exit_code,
                         N_("make 'git-difftool' exit when an invoked diff "
                            "tool returns a non - zero exit code")),
-               OPT_STRING('x', "extcmd", &extcmd, N_("<command>"),
+               OPT_STRING('x', "extcmd", &extcmd, N_("command"),
                           N_("specify a custom command for viewing diffs")),
                OPT_END()
        };
index ee5a1bd355a5f239a23b524a3e05b9c8646f6bc8..601f801158f097b302dcf6615016bb4cefbc0225 100644 (file)
@@ -497,7 +497,7 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
                strbuf_addstr(&name, ce->name);
 
                if (S_ISREG(ce->ce_mode) &&
-                   match_pathspec(pathspec, name.buf, name.len, 0, NULL,
+                   match_pathspec(repo->index, pathspec, name.buf, name.len, 0, NULL,
                                   S_ISDIR(ce->ce_mode) ||
                                   S_ISGITLINK(ce->ce_mode))) {
                        /*
@@ -515,7 +515,7 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
                                hit |= grep_file(opt, name.buf);
                        }
                } else if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
-                          submodule_path_match(pathspec, name.buf, NULL)) {
+                          submodule_path_match(repo->index, pathspec, name.buf, NULL)) {
                        hit |= grep_submodule(opt, repo, pathspec, NULL, ce->name, ce->name);
                } else {
                        continue;
@@ -679,7 +679,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
 
        fill_directory(&dir, &the_index, pathspec);
        for (i = 0; i < dir.nr; i++) {
-               if (!dir_path_match(dir.entries[i], pathspec, 0, NULL))
+               if (!dir_path_match(&the_index, dir.entries[i], pathspec, 0, NULL))
                        continue;
                hit |= grep_file(opt, dir.entries[i]->name);
                if (hit && opt->status_only)
index 88bb2019ad7a52a13373d4c88b127915b219e4a5..7f9919a36234f603ffe76d7324fafc7f5872d404 100644 (file)
@@ -63,7 +63,7 @@ static void write_eolinfo(const struct index_state *istate,
                struct stat st;
                const char *i_txt = "";
                const char *w_txt = "";
-               const char *a_txt = get_convert_attr_ascii(path);
+               const char *a_txt = get_convert_attr_ascii(istate, path);
                if (ce && S_ISREG(ce->ce_mode))
                        i_txt = get_cached_convert_stats_ascii(istate,
                                                               ce->name);
@@ -121,18 +121,19 @@ static void print_debug(const struct cache_entry *ce)
        }
 }
 
-static void show_dir_entry(const char *tag, struct dir_entry *ent)
+static void show_dir_entry(const struct index_state *istate,
+                          const char *tag, struct dir_entry *ent)
 {
        int len = max_prefix_len;
 
        if (len > ent->len)
                die("git ls-files: internal error - directory entry not superset of prefix");
 
-       if (!dir_path_match(ent, &pathspec, len, ps_matched))
+       if (!dir_path_match(istate, ent, &pathspec, len, ps_matched))
                return;
 
        fputs(tag, stdout);
-       write_eolinfo(NULL, NULL, ent->name);
+       write_eolinfo(istate, NULL, ent->name);
        write_name(ent->name);
 }
 
@@ -145,7 +146,7 @@ static void show_other_files(const struct index_state *istate,
                struct dir_entry *ent = dir->entries[i];
                if (!index_name_is_other(istate, ent->name, ent->len))
                        continue;
-               show_dir_entry(tag_other, ent);
+               show_dir_entry(istate, tag_other, ent);
        }
 }
 
@@ -196,7 +197,7 @@ static void show_killed_files(const struct index_state *istate,
                        }
                }
                if (killed)
-                       show_dir_entry(tag_killed, dir->entries[i]);
+                       show_dir_entry(istate, tag_killed, dir->entries[i]);
        }
 }
 
@@ -228,7 +229,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
        if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
            is_submodule_active(repo, ce->name)) {
                show_submodule(repo, dir, ce->name);
-       } else if (match_pathspec(&pathspec, fullname, strlen(fullname),
+       } else if (match_pathspec(repo->index, &pathspec, fullname, strlen(fullname),
                                  max_prefix_len, ps_matched,
                                  S_ISDIR(ce->ce_mode) ||
                                  S_ISGITLINK(ce->ce_mode))) {
@@ -264,7 +265,7 @@ static void show_ru_info(const struct index_state *istate)
                len = strlen(path);
                if (len < max_prefix_len)
                        continue; /* outside of the prefix */
-               if (!match_pathspec(&pathspec, path, len,
+               if (!match_pathspec(istate, &pathspec, path, len,
                                    max_prefix_len, ps_matched, 0))
                        continue; /* uninterested */
                for (i = 0; i < 3; i++) {
index 80c880e9ad271576a441a16be0328a2d94cd415d..0d80dee2ba1ad82fd21622f73dac86b6010da4b6 100644 (file)
@@ -951,7 +951,7 @@ static int no_try_delta(const char *path)
 
        if (!check)
                check = attr_check_initl("delta", NULL);
-       if (git_check_attr(path, check))
+       if (git_check_attr(&the_index, path, check))
                return 0;
        if (ATTR_FALSE(check->items[0].value))
                return 1;
@@ -3135,7 +3135,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                OPT_BOOL(0, "all-progress-implied",
                         &all_progress_implied,
                         N_("similar to --all-progress when progress meter is shown")),
-               { OPTION_CALLBACK, 0, "index-version", NULL, N_("version[,offset]"),
+               { OPTION_CALLBACK, 0, "index-version", NULL, N_("<version>[,<offset>]"),
                  N_("write the pack index file in the specified idx format version"),
                  0, option_parse_index_version },
                OPT_MAGNITUDE(0, "max-pack-size", &pack_size_limit,
index 4ff525e50fc701392e7ed276ae4bba4a82ddf8a1..a9e7b552b9d117c5f1078a0dd5864bbed724c6b6 100644 (file)
@@ -3,6 +3,7 @@
 #include "progress.h"
 #include "parse-options.h"
 #include "packfile.h"
+#include "object-store.h"
 
 static const char * const prune_packed_usage[] = {
        N_("git prune-packed [-n | --dry-run] [-q | --quiet]"),
index 4e789353922340c3d0727a2e2c3e60e5a9936ee5..53bc5facfdabd05934a351091f2040744b2575ca 100644 (file)
@@ -48,11 +48,11 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value,
                return REBASE_FALSE;
        else if (v > 0)
                return REBASE_TRUE;
-       else if (!strcmp(value, "preserve"))
+       else if (!strcmp(value, "preserve") || !strcmp(value, "p"))
                return REBASE_PRESERVE;
-       else if (!strcmp(value, "merges"))
+       else if (!strcmp(value, "merges") || !strcmp(value, "m"))
                return REBASE_MERGES;
-       else if (!strcmp(value, "interactive"))
+       else if (!strcmp(value, "interactive") || !strcmp(value, "i"))
                return REBASE_INTERACTIVE;
 
        if (fatal)
index 9cd8e8cd5631158e0904826567f2d3c02bca2bda..ef4c188895beab317a66523b23a9f1c87e634405 100644 (file)
@@ -558,9 +558,9 @@ int cmd_push(int argc, const char **argv, const char *prefix)
                OPT_BIT( 0,  "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
                OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
                { OPTION_CALLBACK,
-                 0, CAS_OPT_NAME, &cas, N_("refname>:<expect"),
+                 0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
                  N_("require old value of ref to be at this value"),
-                 PARSE_OPT_OPTARG, parseopt_push_cas_option },
+                 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option },
                { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, "check|on-demand|no",
                        N_("control recursive pushing of submodules"),
                        PARSE_OPT_OPTARG, option_parse_recurse_submodules },
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
new file mode 100644 (file)
index 0000000..f52d45d
--- /dev/null
@@ -0,0 +1,116 @@
+#include "cache.h"
+#include "builtin.h"
+#include "parse-options.h"
+#include "range-diff.h"
+#include "config.h"
+
+static const char * const builtin_range_diff_usage[] = {
+N_("git range-diff [<options>] <old-base>..<old-tip> <new-base>..<new-tip>"),
+N_("git range-diff [<options>] <old-tip>...<new-tip>"),
+N_("git range-diff [<options>] <base> <old-tip> <new-tip>"),
+NULL
+};
+
+static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data)
+{
+       return data;
+}
+
+int cmd_range_diff(int argc, const char **argv, const char *prefix)
+{
+       int creation_factor = 60;
+       struct diff_options diffopt = { NULL };
+       int simple_color = -1;
+       struct option options[] = {
+               OPT_INTEGER(0, "creation-factor", &creation_factor,
+                           N_("Percentage by which creation is weighted")),
+               OPT_BOOL(0, "no-dual-color", &simple_color,
+                           N_("color both diff and diff-between-diffs")),
+               OPT_END()
+       };
+       int i, j, res = 0;
+       struct strbuf four_spaces = STRBUF_INIT;
+       struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
+
+       git_config(git_diff_ui_config, NULL);
+
+       diff_setup(&diffopt);
+       diffopt.output_format = DIFF_FORMAT_PATCH;
+       diffopt.flags.suppress_diff_headers = 1;
+       diffopt.output_prefix = output_prefix_cb;
+       strbuf_addstr(&four_spaces, "    ");
+       diffopt.output_prefix_data = &four_spaces;
+
+       argc = parse_options(argc, argv, NULL, options,
+                            builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN |
+                            PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
+
+       for (i = j = 1; i < argc && strcmp("--", argv[i]); ) {
+               int c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix);
+
+               if (!c)
+                       argv[j++] = argv[i++];
+               else
+                       i += c;
+       }
+       while (i < argc)
+               argv[j++] = argv[i++];
+       argc = j;
+       diff_setup_done(&diffopt);
+
+       /* Make sure that there are no unparsed options */
+       argc = parse_options(argc, argv, NULL,
+                            options + ARRAY_SIZE(options) - 1, /* OPT_END */
+                            builtin_range_diff_usage, 0);
+
+       if (simple_color < 1) {
+               if (!simple_color)
+                       /* force color when --dual-color was used */
+                       diffopt.use_color = 1;
+               diffopt.flags.dual_color_diffed_diffs = 1;
+       }
+
+       if (argc == 2) {
+               if (!strstr(argv[0], ".."))
+                       die(_("no .. in range: '%s'"), argv[0]);
+               strbuf_addstr(&range1, argv[0]);
+
+               if (!strstr(argv[1], ".."))
+                       die(_("no .. in range: '%s'"), argv[1]);
+               strbuf_addstr(&range2, argv[1]);
+       } else if (argc == 3) {
+               strbuf_addf(&range1, "%s..%s", argv[0], argv[1]);
+               strbuf_addf(&range2, "%s..%s", argv[0], argv[2]);
+       } else if (argc == 1) {
+               const char *b = strstr(argv[0], "..."), *a = argv[0];
+               int a_len;
+
+               if (!b) {
+                       error(_("single arg format must be symmetric range"));
+                       usage_with_options(builtin_range_diff_usage, options);
+               }
+
+               a_len = (int)(b - a);
+               if (!a_len) {
+                       a = "HEAD";
+                       a_len = strlen(a);
+               }
+               b += 3;
+               if (!*b)
+                       b = "HEAD";
+               strbuf_addf(&range1, "%s..%.*s", b, a_len, a);
+               strbuf_addf(&range2, "%.*s..%s", a_len, a, b);
+       } else {
+               error(_("need two commit ranges"));
+               usage_with_options(builtin_range_diff_usage, options);
+       }
+
+       res = show_range_diff(range1.buf, range2.buf, creation_factor,
+                             &diffopt);
+
+       strbuf_release(&range1);
+       strbuf_release(&range2);
+       strbuf_release(&four_spaces);
+
+       return res;
+}
index ebc43eb8057dc9c85aad4c608250ed9a6c4d6cd1..fbbc98e5161f011a25743a528e6bb3f85e415f51 100644 (file)
@@ -133,7 +133,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
                         N_("same as -m, but discard unmerged entries")),
                { OPTION_STRING, 0, "prefix", &opts.prefix, N_("<subdirectory>/"),
                  N_("read the tree into the index under <subdirectory>/"),
-                 PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP },
+                 PARSE_OPT_NONEG },
                OPT_BOOL('u', NULL, &opts.update,
                         N_("update working tree with merge result")),
                { OPTION_CALLBACK, 0, "exclude-per-directory", &opts,
index 6c636e159eaf2d67d617c459aceddd7423e326ab..d5886039cc6656609962fd522a27f61eda6cd0ec 100644 (file)
@@ -8,6 +8,8 @@
 #include "strbuf.h"
 #include "string-list.h"
 #include "argv-array.h"
+#include "packfile.h"
+#include "object-store.h"
 
 static int delta_base_offset = 1;
 static int pack_kept_objects = -1;
@@ -83,7 +85,7 @@ static void remove_pack_on_signal(int signo)
 
 /*
  * Adds all packs hex strings to the fname list, which do not
- * have a corresponding .keep or .promisor file. These packs are not to
+ * have a corresponding .keep file. These packs are not to
  * be kept if we are going to pack everything into one file.
  */
 static void get_non_kept_pack_filenames(struct string_list *fname_list,
@@ -111,8 +113,7 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list,
 
                fname = xmemdupz(e->d_name, len);
 
-               if (!file_exists(mkpath("%s/%s.keep", packdir, fname)) &&
-                   !file_exists(mkpath("%s/%s.promisor", packdir, fname)))
+               if (!file_exists(mkpath("%s/%s.keep", packdir, fname)))
                        string_list_append_nodup(fname_list, fname);
                else
                        free(fname);
@@ -122,7 +123,7 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list,
 
 static void remove_redundant_pack(const char *dir_name, const char *base_name)
 {
-       const char *exts[] = {".pack", ".idx", ".keep", ".bitmap"};
+       const char *exts[] = {".pack", ".idx", ".keep", ".bitmap", ".promisor"};
        int i;
        struct strbuf buf = STRBUF_INIT;
        size_t plen;
@@ -138,6 +139,117 @@ static void remove_redundant_pack(const char *dir_name, const char *base_name)
        strbuf_release(&buf);
 }
 
+struct pack_objects_args {
+       const char *window;
+       const char *window_memory;
+       const char *depth;
+       const char *threads;
+       const char *max_pack_size;
+       int no_reuse_delta;
+       int no_reuse_object;
+       int quiet;
+       int local;
+};
+
+static void prepare_pack_objects(struct child_process *cmd,
+                                const struct pack_objects_args *args)
+{
+       argv_array_push(&cmd->args, "pack-objects");
+       if (args->window)
+               argv_array_pushf(&cmd->args, "--window=%s", args->window);
+       if (args->window_memory)
+               argv_array_pushf(&cmd->args, "--window-memory=%s", args->window_memory);
+       if (args->depth)
+               argv_array_pushf(&cmd->args, "--depth=%s", args->depth);
+       if (args->threads)
+               argv_array_pushf(&cmd->args, "--threads=%s", args->threads);
+       if (args->max_pack_size)
+               argv_array_pushf(&cmd->args, "--max-pack-size=%s", args->max_pack_size);
+       if (args->no_reuse_delta)
+               argv_array_pushf(&cmd->args, "--no-reuse-delta");
+       if (args->no_reuse_object)
+               argv_array_pushf(&cmd->args, "--no-reuse-object");
+       if (args->local)
+               argv_array_push(&cmd->args,  "--local");
+       if (args->quiet)
+               argv_array_push(&cmd->args,  "--quiet");
+       if (delta_base_offset)
+               argv_array_push(&cmd->args,  "--delta-base-offset");
+       argv_array_push(&cmd->args, packtmp);
+       cmd->git_cmd = 1;
+       cmd->out = -1;
+}
+
+/*
+ * Write oid to the given struct child_process's stdin, starting it first if
+ * necessary.
+ */
+static int write_oid(const struct object_id *oid, struct packed_git *pack,
+                    uint32_t pos, void *data)
+{
+       struct child_process *cmd = data;
+
+       if (cmd->in == -1) {
+               if (start_command(cmd))
+                       die("Could not start pack-objects to repack promisor objects");
+       }
+
+       xwrite(cmd->in, oid_to_hex(oid), GIT_SHA1_HEXSZ);
+       xwrite(cmd->in, "\n", 1);
+       return 0;
+}
+
+static void repack_promisor_objects(const struct pack_objects_args *args,
+                                   struct string_list *names)
+{
+       struct child_process cmd = CHILD_PROCESS_INIT;
+       FILE *out;
+       struct strbuf line = STRBUF_INIT;
+
+       prepare_pack_objects(&cmd, args);
+       cmd.in = -1;
+
+       /*
+        * NEEDSWORK: Giving pack-objects only the OIDs without any ordering
+        * hints may result in suboptimal deltas in the resulting pack. See if
+        * the OIDs can be sent with fake paths such that pack-objects can use a
+        * {type -> existing pack order} ordering when computing deltas instead
+        * of a {type -> size} ordering, which may produce better deltas.
+        */
+       for_each_packed_object(write_oid, &cmd,
+                              FOR_EACH_OBJECT_PROMISOR_ONLY);
+
+       if (cmd.in == -1)
+               /* No packed objects; cmd was never started */
+               return;
+
+       close(cmd.in);
+
+       out = xfdopen(cmd.out, "r");
+       while (strbuf_getline_lf(&line, out) != EOF) {
+               char *promisor_name;
+               int fd;
+               if (line.len != 40)
+                       die("repack: Expecting 40 character sha1 lines only from pack-objects.");
+               string_list_append(names, line.buf);
+
+               /*
+                * pack-objects creates the .pack and .idx files, but not the
+                * .promisor file. Create the .promisor file, which is empty.
+                */
+               promisor_name = mkpathdup("%s-%s.promisor", packtmp,
+                                         line.buf);
+               fd = open(promisor_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
+               if (fd < 0)
+                       die_errno("unable to create '%s'", promisor_name);
+               close(fd);
+               free(promisor_name);
+       }
+       fclose(out);
+       if (finish_command(&cmd))
+               die("Could not finish pack-objects to repack promisor objects");
+}
+
 #define ALL_INTO_ONE 1
 #define LOOSEN_UNREACHABLE 2
 
@@ -150,6 +262,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                {".pack"},
                {".idx"},
                {".bitmap", 1},
+               {".promisor", 1},
        };
        struct child_process cmd = CHILD_PROCESS_INIT;
        struct string_list_item *item;
@@ -165,15 +278,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        int delete_redundant = 0;
        const char *unpack_unreachable = NULL;
        int keep_unreachable = 0;
-       const char *window = NULL, *window_memory = NULL;
-       const char *depth = NULL;
-       const char *threads = NULL;
-       const char *max_pack_size = NULL;
        struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
-       int no_reuse_delta = 0, no_reuse_object = 0;
        int no_update_server_info = 0;
-       int quiet = 0;
-       int local = 0;
+       struct pack_objects_args po_args = {NULL};
 
        struct option builtin_repack_options[] = {
                OPT_BIT('a', NULL, &pack_everything,
@@ -183,14 +290,14 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                                   LOOSEN_UNREACHABLE | ALL_INTO_ONE),
                OPT_BOOL('d', NULL, &delete_redundant,
                                N_("remove redundant packs, and run git-prune-packed")),
-               OPT_BOOL('f', NULL, &no_reuse_delta,
+               OPT_BOOL('f', NULL, &po_args.no_reuse_delta,
                                N_("pass --no-reuse-delta to git-pack-objects")),
-               OPT_BOOL('F', NULL, &no_reuse_object,
+               OPT_BOOL('F', NULL, &po_args.no_reuse_object,
                                N_("pass --no-reuse-object to git-pack-objects")),
                OPT_BOOL('n', NULL, &no_update_server_info,
                                N_("do not run git-update-server-info")),
-               OPT__QUIET(&quiet, N_("be quiet")),
-               OPT_BOOL('l', "local", &local,
+               OPT__QUIET(&po_args.quiet, N_("be quiet")),
+               OPT_BOOL('l', "local", &po_args.local,
                                N_("pass --local to git-pack-objects")),
                OPT_BOOL('b', "write-bitmap-index", &write_bitmaps,
                                N_("write bitmap index")),
@@ -198,15 +305,15 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                                N_("with -A, do not loosen objects older than this")),
                OPT_BOOL('k', "keep-unreachable", &keep_unreachable,
                                N_("with -a, repack unreachable objects")),
-               OPT_STRING(0, "window", &window, N_("n"),
+               OPT_STRING(0, "window", &po_args.window, N_("n"),
                                N_("size of the window used for delta compression")),
-               OPT_STRING(0, "window-memory", &window_memory, N_("bytes"),
+               OPT_STRING(0, "window-memory", &po_args.window_memory, N_("bytes"),
                                N_("same as the above, but limit memory size instead of entries count")),
-               OPT_STRING(0, "depth", &depth, N_("n"),
+               OPT_STRING(0, "depth", &po_args.depth, N_("n"),
                                N_("limits the maximum delta depth")),
-               OPT_STRING(0, "threads", &threads, N_("n"),
+               OPT_STRING(0, "threads", &po_args.threads, N_("n"),
                                N_("limits the maximum number of threads")),
-               OPT_STRING(0, "max-pack-size", &max_pack_size, N_("bytes"),
+               OPT_STRING(0, "max-pack-size", &po_args.max_pack_size, N_("bytes"),
                                N_("maximum size of each packfile")),
                OPT_BOOL(0, "pack-kept-objects", &pack_kept_objects,
                                N_("repack objects in packs marked with .keep")),
@@ -238,7 +345,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 
        sigchain_push_common(remove_pack_on_signal);
 
-       argv_array_push(&cmd.args, "pack-objects");
+       prepare_pack_objects(&cmd, &po_args);
+
        argv_array_push(&cmd.args, "--keep-true-parents");
        if (!pack_kept_objects)
                argv_array_push(&cmd.args, "--honor-pack-keep");
@@ -251,26 +359,14 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        argv_array_push(&cmd.args, "--indexed-objects");
        if (repository_format_partial_clone)
                argv_array_push(&cmd.args, "--exclude-promisor-objects");
-       if (window)
-               argv_array_pushf(&cmd.args, "--window=%s", window);
-       if (window_memory)
-               argv_array_pushf(&cmd.args, "--window-memory=%s", window_memory);
-       if (depth)
-               argv_array_pushf(&cmd.args, "--depth=%s", depth);
-       if (threads)
-               argv_array_pushf(&cmd.args, "--threads=%s", threads);
-       if (max_pack_size)
-               argv_array_pushf(&cmd.args, "--max-pack-size=%s", max_pack_size);
-       if (no_reuse_delta)
-               argv_array_pushf(&cmd.args, "--no-reuse-delta");
-       if (no_reuse_object)
-               argv_array_pushf(&cmd.args, "--no-reuse-object");
        if (write_bitmaps)
                argv_array_push(&cmd.args, "--write-bitmap-index");
 
        if (pack_everything & ALL_INTO_ONE) {
                get_non_kept_pack_filenames(&existing_packs, &keep_pack_list);
 
+               repack_promisor_objects(&po_args, &names);
+
                if (existing_packs.nr && delete_redundant) {
                        if (unpack_unreachable) {
                                argv_array_pushf(&cmd.args,
@@ -292,17 +388,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                argv_array_push(&cmd.args, "--incremental");
        }
 
-       if (local)
-               argv_array_push(&cmd.args,  "--local");
-       if (quiet)
-               argv_array_push(&cmd.args,  "--quiet");
-       if (delta_base_offset)
-               argv_array_push(&cmd.args,  "--delta-base-offset");
-
-       argv_array_push(&cmd.args, packtmp);
-
-       cmd.git_cmd = 1;
-       cmd.out = -1;
        cmd.no_stdin = 1;
 
        ret = start_command(&cmd);
@@ -320,7 +405,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        if (ret)
                return ret;
 
-       if (!names.nr && !quiet)
+       if (!names.nr && !po_args.quiet)
                printf("Nothing new to pack.\n");
 
        /*
@@ -429,6 +514,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 
        /* End of pack replacement. */
 
+       reprepare_packed_git(the_repository);
+
        if (delete_redundant) {
                int opts = 0;
                string_list_sort(&names);
@@ -441,7 +528,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                        if (!string_list_has_string(&names, sha1))
                                remove_redundant_pack(packdir, item->string);
                }
-               if (!quiet && isatty(2))
+               if (!po_args.quiet && isatty(2))
                        opts |= PRUNE_PACKED_VERBOSE;
                prune_packed_objects(opts);
        }
index f4d3f000b624564737bf7b851f4bf9abf5497684..2cbe89e0ae3b7a4801ac27d25fd37306813104ba 100644 (file)
@@ -278,7 +278,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 
        for (i = 0; i < active_nr; i++) {
                const struct cache_entry *ce = active_cache[i];
-               if (!ce_path_match(ce, &pathspec, seen))
+               if (!ce_path_match(&the_index, ce, &pathspec, seen))
                        continue;
                ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
                list.entry[list.nr].name = xstrdup(ce->name);
index 42fd8d1a3528c3ea0b30007407b2ae38f240f4c7..724b4848508d67b3693edf458033e7e29a92b3d3 100644 (file)
@@ -178,7 +178,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
                OPT_BOOL(0, "stdin", &from_stdin, N_("read refs from stdin")),
                OPT_BOOL(0, "helper-status", &helper_status, N_("print status from remote helper")),
                { OPTION_CALLBACK,
-                 0, CAS_OPT_NAME, &cas, N_("refname>:<expect"),
+                 0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
                  N_("require old value of ref to be at this value"),
                  PARSE_OPT_OPTARG, parseopt_push_cas_option },
                OPT_END()
index 608d6ba77bdfb4673513444651053d0e8e789020..3898a2c9c428864caf43b0f8160a441488643e29 100644 (file)
@@ -268,8 +268,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
                         N_("Suppress commit descriptions, only provides commit count")),
                OPT_BOOL('e', "email", &log.email,
                         N_("Show the email address of each author")),
-               { OPTION_CALLBACK, 'w', NULL, &log, N_("w[,i1[,i2]]"),
-                       N_("Linewrap output"), PARSE_OPT_OPTARG, &parse_wrap_args },
+               { OPTION_CALLBACK, 'w', NULL, &log, N_("<w>[,<i1>[,<i2>]]"),
+                       N_("Linewrap output"), PARSE_OPT_OPTARG,
+                       &parse_wrap_args },
                OPT_END(),
        };
 
index 4b9d3c0059bb866a699ce7060fef1047e9019e3b..363cf8509af5bf640da60c36118b841da06918fe 100644 (file)
@@ -674,7 +674,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                { OPTION_CALLBACK, 'g', "reflog", &reflog_base, N_("<n>[,<base>]"),
                            N_("show <n> most recent ref-log entries starting at "
                               "base"),
-                           PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP,
+                           PARSE_OPT_OPTARG,
                            parse_reflog_param },
                OPT_END()
        };
index 65f8760ee2a18fc5511b27172517295afb4cc105..2bcc70fdfe2608ccbbab02b6f593dd81781ada41 100644 (file)
@@ -331,7 +331,7 @@ static int module_list_compute(int argc, const char **argv,
        for (i = 0; i < active_nr; i++) {
                const struct cache_entry *ce = active_cache[i];
 
-               if (!match_pathspec(pathspec, ce->name, ce_namelen(ce),
+               if (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),
                                    0, ps_matched, 1) ||
                    !S_ISGITLINK(ce->ce_mode))
                        continue;
index f5c0b6a1d23b203de5379cf898b70679857683ff..fe84003b4fa05c377bb4ab1de04a7cd1c9ae4d5d 100644 (file)
@@ -748,7 +748,7 @@ static int do_reupdate(int ac, const char **av,
                int save_nr;
                char *path;
 
-               if (ce_stage(ce) || !ce_path_match(ce, &pathspec, NULL))
+               if (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL))
                        continue;
                if (has_head)
                        old = read_one_ent(NULL, &head_oid,
@@ -969,9 +969,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                        PARSE_OPT_NOARG | /* disallow --cacheinfo=<mode> form */
                        PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
                        (parse_opt_cb *) cacheinfo_callback},
-               {OPTION_CALLBACK, 0, "chmod", &set_executable_bit, N_("(+/-)x"),
+               {OPTION_CALLBACK, 0, "chmod", &set_executable_bit, "(+|-)x",
                        N_("override the executable bit of the listed files"),
-                       PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
+                       PARSE_OPT_NONEG,
                        chmod_callback},
                {OPTION_SET_INT, 0, "assume-unchanged", &mark_valid_only, NULL,
                        N_("mark files as \"not changing\""),
index 84532ae9a93e7fb526a6fd28901875b3a10f3ffa..25d91163563614110d2c93802ce3fef6d5844325 100644 (file)
@@ -43,7 +43,8 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
        }
 
        /* parse all options sent by the client */
-       return write_archive(sent_argv.argc, sent_argv.argv, prefix, NULL, 1);
+       return write_archive(sent_argv.argc, sent_argv.argv, prefix,
+                            the_repository, NULL, 1);
 }
 
 __attribute__((format (printf, 1, 2)))
index c9d3c544e79f46bab9e5fd50079d1bb574b722f2..cdcbf8264e8c6e9b56977b99ad28160754d8fb7c 100644 (file)
@@ -24,9 +24,8 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
        struct option write_tree_options[] = {
                OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
                        WRITE_TREE_MISSING_OK),
-               { OPTION_STRING, 0, "prefix", &prefix, N_("<prefix>/"),
-                 N_("write tree object for a subdirectory <prefix>") ,
-                 PARSE_OPT_LITERAL_ARGHELP },
+               OPT_STRING(0, "prefix", &prefix, N_("<prefix>/"),
+                          N_("write tree object for a subdirectory <prefix>")),
                { OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
                  N_("only useful for debugging"),
                  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
index a85527318b15b36bb60b0b6b166569b4fcaa9dcf..f438f93811bfc62aa79a9ba6f9476240100e286f 100644 (file)
@@ -4,6 +4,8 @@
 #ifndef BULK_CHECKIN_H
 #define BULK_CHECKIN_H
 
+#include "cache.h"
+
 extern int index_bulk_checkin(struct object_id *oid,
                              int fd, size_t size, enum object_type type,
                              const char *path, unsigned flags);
index 181d5919f0fd4d8e838684cd14adafc8fa31ab71..16ea022c46d3b281d04a3956f865d8a886a5b714 100644 (file)
@@ -652,11 +652,6 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state,
        return ret;
 }
 
-int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)
-{
-       return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);
-}
-
 static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
 {
        struct tree_desc desc;
@@ -723,10 +718,3 @@ int cache_tree_matches_traversal(struct cache_tree *root,
                return it->entry_count;
        return 0;
 }
-
-int update_main_cache_tree(int flags)
-{
-       if (!the_index.cache_tree)
-               the_index.cache_tree = cache_tree();
-       return cache_tree_update(&the_index, flags);
-}
index cfd5328cc93694e23037e15148241e17bd4f3a04..fc0c842e773f648d64858d1891f64d222633fc3a 100644 (file)
@@ -33,8 +33,6 @@ struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
 int cache_tree_fully_valid(struct cache_tree *);
 int cache_tree_update(struct index_state *, int);
 
-int update_main_cache_tree(int);
-
 /* bitmasks to write_cache_as_tree flags */
 #define WRITE_TREE_MISSING_OK 1
 #define WRITE_TREE_IGNORE_CACHE_TREE 2
@@ -48,9 +46,22 @@ int update_main_cache_tree(int);
 #define WRITE_TREE_PREFIX_ERROR (-3)
 
 int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix);
-int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix);
 void prime_cache_tree(struct index_state *, struct tree *);
 
-extern int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
+int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
+
+#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS
+static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)
+{
+       return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);
+}
+
+static inline int update_main_cache_tree(int flags)
+{
+       if (!the_index.cache_tree)
+               the_index.cache_tree = cache_tree();
+       return cache_tree_update(&the_index, flags);
+}
+#endif
 
 #endif
diff --git a/cache.h b/cache.h
index 1398b2a4e4aa18958044acb49607c69ed0e6c125..b1fd3d58ab20b6fd4460c6475c0eb0390c3ab9ac 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -917,15 +917,6 @@ enum log_refs_config {
 };
 extern enum log_refs_config log_all_ref_updates;
 
-enum branch_track {
-       BRANCH_TRACK_UNSPECIFIED = -1,
-       BRANCH_TRACK_NEVER = 0,
-       BRANCH_TRACK_REMOTE,
-       BRANCH_TRACK_ALWAYS,
-       BRANCH_TRACK_EXPLICIT,
-       BRANCH_TRACK_OVERRIDE
-};
-
 enum rebase_setup_type {
        AUTOREBASE_NEVER = 0,
        AUTOREBASE_LOCAL,
@@ -942,7 +933,6 @@ enum push_default_type {
        PUSH_DEFAULT_UNSPECIFIED
 };
 
-extern enum branch_track git_branch_track;
 extern enum rebase_setup_type autorebase;
 extern enum push_default_type push_default;
 
@@ -1575,62 +1565,6 @@ extern int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
  */
 extern int odb_pack_keep(const char *name);
 
-/*
- * Iterate over the files in the loose-object parts of the object
- * directory "path", triggering the following callbacks:
- *
- *  - loose_object is called for each loose object we find.
- *
- *  - loose_cruft is called for any files that do not appear to be
- *    loose objects. Note that we only look in the loose object
- *    directories "objects/[0-9a-f]{2}/", so we will not report
- *    "objects/foobar" as cruft.
- *
- *  - loose_subdir is called for each top-level hashed subdirectory
- *    of the object directory (e.g., "$OBJDIR/f0"). It is called
- *    after the objects in the directory are processed.
- *
- * Any callback that is NULL will be ignored. Callbacks returning non-zero
- * will end the iteration.
- *
- * In the "buf" variant, "path" is a strbuf which will also be used as a
- * scratch buffer, but restored to its original contents before
- * the function returns.
- */
-typedef int each_loose_object_fn(const struct object_id *oid,
-                                const char *path,
-                                void *data);
-typedef int each_loose_cruft_fn(const char *basename,
-                               const char *path,
-                               void *data);
-typedef int each_loose_subdir_fn(unsigned int nr,
-                                const char *path,
-                                void *data);
-int for_each_file_in_obj_subdir(unsigned int subdir_nr,
-                               struct strbuf *path,
-                               each_loose_object_fn obj_cb,
-                               each_loose_cruft_fn cruft_cb,
-                               each_loose_subdir_fn subdir_cb,
-                               void *data);
-int for_each_loose_file_in_objdir(const char *path,
-                                 each_loose_object_fn obj_cb,
-                                 each_loose_cruft_fn cruft_cb,
-                                 each_loose_subdir_fn subdir_cb,
-                                 void *data);
-int for_each_loose_file_in_objdir_buf(struct strbuf *path,
-                                     each_loose_object_fn obj_cb,
-                                     each_loose_cruft_fn cruft_cb,
-                                     each_loose_subdir_fn subdir_cb,
-                                     void *data);
-
-/*
- * Iterate over loose objects in both the local
- * repository and any alternates repositories (unless the
- * LOCAL_ONLY flag is set).
- */
-#define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
-extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);
-
 /*
  * Set this to 0 to prevent sha1_object_info_extended() from fetching missing
  * blobs. This has a difference only if extensions.partialClone is set.
diff --git a/color.c b/color.c
index b1c24c69de652b0b8900e76ebd5b4e6cd24e5203..ebb222ec3323d45bdcd298208903dff9a90d5c3f 100644 (file)
--- a/color.c
+++ b/color.c
@@ -343,6 +343,9 @@ int want_color_fd(int fd, int var)
 
        static int want_auto[3] = { -1, -1, -1 };
 
+       if (fd < 1 || fd >= ARRAY_SIZE(want_auto))
+               BUG("file descriptor out of range: %d", fd);
+
        if (var < 0)
                var = git_use_color_default;
 
diff --git a/color.h b/color.h
index 5b744e1bc68617d196bdd864042e738cb4d75ebe..98894d6a17563d7005a2ba3a1fb6070c06cbcefc 100644 (file)
--- a/color.h
+++ b/color.h
@@ -36,6 +36,12 @@ struct strbuf;
 #define GIT_COLOR_BOLD_BLUE    "\033[1;34m"
 #define GIT_COLOR_BOLD_MAGENTA "\033[1;35m"
 #define GIT_COLOR_BOLD_CYAN    "\033[1;36m"
+#define GIT_COLOR_FAINT_RED    "\033[2;31m"
+#define GIT_COLOR_FAINT_GREEN  "\033[2;32m"
+#define GIT_COLOR_FAINT_YELLOW "\033[2;33m"
+#define GIT_COLOR_FAINT_BLUE   "\033[2;34m"
+#define GIT_COLOR_FAINT_MAGENTA        "\033[2;35m"
+#define GIT_COLOR_FAINT_CYAN   "\033[2;36m"
 #define GIT_COLOR_BG_RED       "\033[41m"
 #define GIT_COLOR_BG_GREEN     "\033[42m"
 #define GIT_COLOR_BG_YELLOW    "\033[43m"
@@ -44,6 +50,7 @@ struct strbuf;
 #define GIT_COLOR_BG_CYAN      "\033[46m"
 #define GIT_COLOR_FAINT                "\033[2m"
 #define GIT_COLOR_FAINT_ITALIC "\033[2;3m"
+#define GIT_COLOR_REVERSE      "\033[7m"
 
 /* A special value meaning "no color selected" */
 #define GIT_COLOR_NIL "NIL"
index 0a61917fa75484622e39ef54bfbc7d8a43b059ed..2567a5cf4dff99bcaf0e507168e1d4cbaba05bce 100644 (file)
--- a/column.h
+++ b/column.h
@@ -36,6 +36,7 @@ static inline int column_active(unsigned int colopts)
        return (colopts & COL_ENABLE_MASK) == COL_ENABLED;
 }
 
+struct string_list;
 extern void print_columns(const struct string_list *list, unsigned int colopts,
                          const struct column_options *opts);
 
index e1c26c1bb7e618f6f372d9a568e7cab75612d2db..a9dda3b8af6a754564f8f840f0ca63d93f6c88dc 100644 (file)
@@ -139,6 +139,7 @@ git-prune-packed                        plumbingmanipulators
 git-pull                                mainporcelain           remote
 git-push                                mainporcelain           remote
 git-quiltimport                         foreignscminterface
+git-range-diff                          mainporcelain
 git-read-tree                           plumbingmanipulators
 git-rebase                              mainporcelain           history
 git-receive-pack                        synchelpers
index 0034740c26b48eda147d45258505df278b84cc0a..8a1bec7b8aa420dd3d4ecadc95dee31029533c07 100644 (file)
@@ -730,7 +730,7 @@ void write_commit_graph(const char *obj_dir,
                                die(_("error adding pack %s"), packname.buf);
                        if (open_pack_index(p))
                                die(_("error opening index for %s"), packname.buf);
-                       for_each_object_in_pack(p, add_packed_commits, &oids);
+                       for_each_object_in_pack(p, add_packed_commits, &oids, 0);
                        close_pack(p);
                }
                strbuf_release(&packname);
index 76e098934a7f6740b52a479baa5c68fe605d1ea6..eea62f8c0ee53b56630a1a2b0c2c716b4cd63670 100644 (file)
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "repository.h"
 #include "string-list.h"
+#include "cache.h"
 
 struct commit;
 
index 6ded1c859f1b5ae1ffe035ac228c0f8a5298097a..858ca14a57351062d2bba147c72ed460fb0aa533 100644 (file)
@@ -341,12 +341,44 @@ int mingw_mkdir(const char *path, int mode)
        return ret;
 }
 
+static int mingw_open_append(wchar_t const *wfilename, int oflags, ...)
+{
+       HANDLE handle;
+       int fd;
+       DWORD create = (oflags & O_CREAT) ? OPEN_ALWAYS : OPEN_EXISTING;
+
+       /* only these flags are supported */
+       if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND))
+               return errno = ENOSYS, -1;
+
+       /*
+        * FILE_SHARE_WRITE is required to permit child processes
+        * to append to the file.
+        */
+       handle = CreateFileW(wfilename, FILE_APPEND_DATA,
+                       FILE_SHARE_WRITE | FILE_SHARE_READ,
+                       NULL, create, FILE_ATTRIBUTE_NORMAL, NULL);
+       if (handle == INVALID_HANDLE_VALUE)
+               return errno = err_win_to_posix(GetLastError()), -1;
+       /*
+        * No O_APPEND here, because the CRT uses it only to reset the
+        * file pointer to EOF on write(); but that is not necessary
+        * for a file created with FILE_APPEND_DATA.
+        */
+       fd = _open_osfhandle((intptr_t)handle, O_BINARY);
+       if (fd < 0)
+               CloseHandle(handle);
+       return fd;
+}
+
 int mingw_open (const char *filename, int oflags, ...)
 {
+       typedef int (*open_fn_t)(wchar_t const *wfilename, int oflags, ...);
        va_list args;
        unsigned mode;
        int fd;
        wchar_t wfilename[MAX_PATH];
+       open_fn_t open_fn;
 
        va_start(args, oflags);
        mode = va_arg(args, int);
@@ -355,9 +387,14 @@ int mingw_open (const char *filename, int oflags, ...)
        if (filename && !strcmp(filename, "/dev/null"))
                filename = "nul";
 
+       if (oflags & O_APPEND)
+               open_fn = mingw_open_append;
+       else
+               open_fn = _wopen;
+
        if (xutftowcs_path(wfilename, filename) < 0)
                return -1;
-       fd = _wopen(wfilename, oflags, mode);
+       fd = open_fn(wfilename, oflags, mode);
 
        if (fd < 0 && (oflags & O_ACCMODE) != O_RDONLY && errno == EACCES) {
                DWORD attrs = GetFileAttributesW(wfilename);
@@ -375,7 +412,7 @@ int mingw_open (const char *filename, int oflags, ...)
                 * CREATE_ALWAYS flag of CreateFile()).
                 */
                if (fd < 0 && errno == EACCES)
-                       fd = _wopen(wfilename, oflags & ~O_CREAT, mode);
+                       fd = open_fn(wfilename, oflags & ~O_CREAT, mode);
                if (fd >= 0 && set_hidden_flag(wfilename, 1))
                        warning("could not mark '%s' as hidden.", filename);
        }
index a94e7c43422d87ae062842ae2c2aad430c4b13e4..6f843d3e1a121cf8f73409bc66898f74a9f14f2c 100644 (file)
@@ -1,4 +1,6 @@
 #ifndef PRECOMPOSE_UNICODE_H
+#define PRECOMPOSE_UNICODE_H
+
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <dirent.h>
@@ -41,5 +43,4 @@ int precompose_utf8_closedir(PREC_DIR *dirp);
 #define DIR PREC_DIR
 #endif /* PRECOMPOSE_UNICODE_C */
 
-#define  PRECOMPOSE_UNICODE_H
 #endif /* PRECOMPOSE_UNICODE_H */
index 10522f399e6eb5300b55eaeaf8fcbf6546e53d11..9a0b10d4bc23fc0381ea61b492c1199e91ae5861 100644 (file)
--- a/config.c
+++ b/config.c
@@ -6,6 +6,7 @@
  *
  */
 #include "cache.h"
+#include "branch.h"
 #include "config.h"
 #include "repository.h"
 #include "lockfile.h"
@@ -37,6 +38,7 @@ struct config_source {
        int eof;
        struct strbuf value;
        struct strbuf var;
+       unsigned subsection_case_sensitive : 1;
 
        int (*do_fgetc)(struct config_source *c);
        int (*do_ungetc)(int c, struct config_source *conf);
@@ -605,6 +607,7 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
 
 static int get_extended_base_var(struct strbuf *name, int c)
 {
+       cf->subsection_case_sensitive = 0;
        do {
                if (c == '\n')
                        goto error_incomplete_line;
@@ -641,6 +644,7 @@ static int get_extended_base_var(struct strbuf *name, int c)
 
 static int get_base_var(struct strbuf *name)
 {
+       cf->subsection_case_sensitive = 1;
        for (;;) {
                int c = get_next_char();
                if (cf->eof)
@@ -933,7 +937,7 @@ int git_parse_ulong(const char *value, unsigned long *ret)
        return 1;
 }
 
-static int git_parse_ssize_t(const char *value, ssize_t *ret)
+int git_parse_ssize_t(const char *value, ssize_t *ret)
 {
        intmax_t tmp;
        if (!git_parse_signed(value, &tmp, maximum_signed_value_of_type(ssize_t)))
@@ -2369,14 +2373,21 @@ static int store_aux_event(enum config_event_t type,
        store->parsed[store->parsed_nr].type = type;
 
        if (type == CONFIG_EVENT_SECTION) {
+               int (*cmpfn)(const char *, const char *, size_t);
+
                if (cf->var.len < 2 || cf->var.buf[cf->var.len - 1] != '.')
                        return error(_("invalid section name '%s'"), cf->var.buf);
 
+               if (cf->subsection_case_sensitive)
+                       cmpfn = strncasecmp;
+               else
+                       cmpfn = strncmp;
+
                /* Is this the section we were looking for? */
                store->is_keys_section =
                        store->parsed[store->parsed_nr].is_keys_section =
                        cf->var.len - 1 == store->baselen &&
-                       !strncasecmp(cf->var.buf, store->key, store->baselen);
+                       !cmpfn(cf->var.buf, store->key, store->baselen);
                if (store->is_keys_section) {
                        store->section_seen = 1;
                        ALLOC_GROW(store->seen, store->seen_nr + 1,
index bb2f506b27137e8d66ab4cd96439143dced94780..ab46e0165d8ffa782a796d0e2b23337aa9004b51 100644 (file)
--- a/config.h
+++ b/config.h
@@ -1,6 +1,11 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
+#include "hashmap.h"
+#include "string-list.h"
+
+struct object_id;
+
 /* git_config_parse_key() returns these negated: */
 #define CONFIG_INVALID_KEY 1
 #define CONFIG_NO_SECTION_OR_NAME 2
@@ -82,6 +87,7 @@ extern void git_config(config_fn_t fn, void *);
 extern int config_with_options(config_fn_t fn, void *,
                               struct git_config_source *config_source,
                               const struct config_options *opts);
+extern int git_parse_ssize_t(const char *, ssize_t *);
 extern int git_parse_ulong(const char *, unsigned long *);
 extern int git_parse_maybe_bool(const char *);
 extern int git_config_int(const char *, const char *);
@@ -188,9 +194,14 @@ struct config_set {
 
 extern void git_configset_init(struct config_set *cs);
 extern int git_configset_add_file(struct config_set *cs, const char *filename);
-extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value);
 extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key);
 extern void git_configset_clear(struct config_set *cs);
+
+/*
+ * These functions return 1 if not found, and 0 if found, leaving the found
+ * value in the 'dest' pointer.
+ */
+extern int git_configset_get_value(struct config_set *cs, const char *key, const char **dest);
 extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest);
 extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
 extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest);
index 322dc7637263630712e5ab3e875720c5e39eda22..e4c961817d33f64286d3415b370e6a297e381559 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef CONNECTED_H
 #define CONNECTED_H
 
+struct object_id;
 struct transport;
 
 /*
index 94c95516ebec7f32787cc5a2fb45cae83c7e28e3..d63d2dffd4e12186e734adb0cc2ae7c1db7a6374 100644 (file)
@@ -1976,6 +1976,20 @@ _git_push ()
        __git_complete_remote_or_refspec
 }
 
+_git_range_diff ()
+{
+       case "$cur" in
+       --*)
+               __gitcomp "
+                       --creation-factor= --no-dual-color
+                       $__git_diff_common_options
+               "
+               return
+               ;;
+       esac
+       __git_complete_revlist
+}
+
 _git_rebase ()
 {
        __git_find_repo_path
index ce7ea0db067ea9fe48933b6d85397c64c80dea36..6057f1f58015ad7cae9792309dd635a1e7933586 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -1293,7 +1293,8 @@ struct conv_attrs {
        const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */
 };
 
-static void convert_attrs(struct conv_attrs *ca, const char *path)
+static void convert_attrs(const struct index_state *istate,
+                         struct conv_attrs *ca, const char *path)
 {
        static struct attr_check *check;
 
@@ -1305,7 +1306,7 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
                git_config(read_convert_config, NULL);
        }
 
-       if (!git_check_attr(path, check)) {
+       if (!git_check_attr(istate, path, check)) {
                struct attr_check_item *ccheck = check->items;
                ca->crlf_action = git_path_check_crlf(ccheck + 4);
                if (ca->crlf_action == CRLF_UNDEFINED)
@@ -1342,11 +1343,11 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
                ca->crlf_action = CRLF_AUTO_INPUT;
 }
 
-int would_convert_to_git_filter_fd(const char *path)
+int would_convert_to_git_filter_fd(const struct index_state *istate, const char *path)
 {
        struct conv_attrs ca;
 
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
        if (!ca.drv)
                return 0;
 
@@ -1361,11 +1362,11 @@ int would_convert_to_git_filter_fd(const char *path)
        return apply_filter(path, NULL, 0, -1, NULL, ca.drv, CAP_CLEAN, NULL);
 }
 
-const char *get_convert_attr_ascii(const char *path)
+const char *get_convert_attr_ascii(const struct index_state *istate, const char *path)
 {
        struct conv_attrs ca;
 
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
        switch (ca.attr_action) {
        case CRLF_UNDEFINED:
                return "";
@@ -1394,7 +1395,7 @@ int convert_to_git(const struct index_state *istate,
        int ret = 0;
        struct conv_attrs ca;
 
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
 
        ret |= apply_filter(path, src, len, -1, dst, ca.drv, CAP_CLEAN, NULL);
        if (!ret && ca.drv && ca.drv->required)
@@ -1426,7 +1427,7 @@ void convert_to_git_filter_fd(const struct index_state *istate,
                              int conv_flags)
 {
        struct conv_attrs ca;
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
 
        assert(ca.drv);
        assert(ca.drv->clean || ca.drv->process);
@@ -1439,14 +1440,15 @@ void convert_to_git_filter_fd(const struct index_state *istate,
        ident_to_git(path, dst->buf, dst->len, dst, ca.ident);
 }
 
-static int convert_to_working_tree_internal(const char *path, const char *src,
+static int convert_to_working_tree_internal(const struct index_state *istate,
+                                           const char *path, const char *src,
                                            size_t len, struct strbuf *dst,
                                            int normalizing, struct delayed_checkout *dco)
 {
        int ret = 0, ret_filter = 0;
        struct conv_attrs ca;
 
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
 
        ret |= ident_to_worktree(path, src, len, dst, ca.ident);
        if (ret) {
@@ -1480,22 +1482,25 @@ static int convert_to_working_tree_internal(const char *path, const char *src,
        return ret | ret_filter;
 }
 
-int async_convert_to_working_tree(const char *path, const char *src,
+int async_convert_to_working_tree(const struct index_state *istate,
+                                 const char *path, const char *src,
                                  size_t len, struct strbuf *dst,
                                  void *dco)
 {
-       return convert_to_working_tree_internal(path, src, len, dst, 0, dco);
+       return convert_to_working_tree_internal(istate, path, src, len, dst, 0, dco);
 }
 
-int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)
+int convert_to_working_tree(const struct index_state *istate,
+                           const char *path, const char *src,
+                           size_t len, struct strbuf *dst)
 {
-       return convert_to_working_tree_internal(path, src, len, dst, 0, NULL);
+       return convert_to_working_tree_internal(istate, path, src, len, dst, 0, NULL);
 }
 
 int renormalize_buffer(const struct index_state *istate, const char *path,
                       const char *src, size_t len, struct strbuf *dst)
 {
-       int ret = convert_to_working_tree_internal(path, src, len, dst, 1, NULL);
+       int ret = convert_to_working_tree_internal(istate, path, src, len, dst, 1, NULL);
        if (ret) {
                src = dst->buf;
                len = dst->len;
@@ -1929,12 +1934,14 @@ static struct stream_filter *ident_filter(const struct object_id *oid)
  * Note that you would be crazy to set CRLF, smuge/clean or ident to a
  * large binary blob you would want us not to slurp into the memory!
  */
-struct stream_filter *get_stream_filter(const char *path, const struct object_id *oid)
+struct stream_filter *get_stream_filter(const struct index_state *istate,
+                                       const char *path,
+                                       const struct object_id *oid)
 {
        struct conv_attrs ca;
        struct stream_filter *filter = NULL;
 
-       convert_attrs(&ca, path);
+       convert_attrs(istate, &ca, path);
        if (ca.drv && (ca.drv->process || ca.drv->smudge || ca.drv->clean))
                return NULL;
 
index 01385d92886223ab7b1d951d12c5de9b07612401..831559f10d4442b35a43c642b0fd6c203d996f3c 100644 (file)
--- a/convert.h
+++ b/convert.h
@@ -7,6 +7,8 @@
 #include "string-list.h"
 
 struct index_state;
+struct object_id;
+struct strbuf;
 
 #define CONV_EOL_RNDTRP_DIE   (1<<0) /* Die if CRLF to LF to CRLF is different */
 #define CONV_EOL_RNDTRP_WARN  (1<<1) /* Warn if CRLF to LF to CRLF is different */
@@ -57,35 +59,40 @@ struct delayed_checkout {
 
 extern enum eol core_eol;
 extern char *check_roundtrip_encoding;
-extern const char *get_cached_convert_stats_ascii(const struct index_state *istate,
-                                                 const char *path);
-extern const char *get_wt_convert_stats_ascii(const char *path);
-extern const char *get_convert_attr_ascii(const char *path);
+const char *get_cached_convert_stats_ascii(const struct index_state *istate,
+                                          const char *path);
+const char *get_wt_convert_stats_ascii(const char *path);
+const char *get_convert_attr_ascii(const struct index_state *istate,
+                                  const char *path);
 
 /* returns 1 if *dst was used */
-extern int convert_to_git(const struct index_state *istate,
-                         const char *path, const char *src, size_t len,
-                         struct strbuf *dst, int conv_flags);
-extern int convert_to_working_tree(const char *path, const char *src,
-                                  size_t len, struct strbuf *dst);
-extern int async_convert_to_working_tree(const char *path, const char *src,
-                                        size_t len, struct strbuf *dst,
-                                        void *dco);
-extern int async_query_available_blobs(const char *cmd, struct string_list *available_paths);
-extern int renormalize_buffer(const struct index_state *istate,
-                             const char *path, const char *src, size_t len,
-                             struct strbuf *dst);
+int convert_to_git(const struct index_state *istate,
+                  const char *path, const char *src, size_t len,
+                  struct strbuf *dst, int conv_flags);
+int convert_to_working_tree(const struct index_state *istate,
+                           const char *path, const char *src,
+                           size_t len, struct strbuf *dst);
+int async_convert_to_working_tree(const struct index_state *istate,
+                                 const char *path, const char *src,
+                                 size_t len, struct strbuf *dst,
+                                 void *dco);
+int async_query_available_blobs(const char *cmd,
+                               struct string_list *available_paths);
+int renormalize_buffer(const struct index_state *istate,
+                      const char *path, const char *src, size_t len,
+                      struct strbuf *dst);
 static inline int would_convert_to_git(const struct index_state *istate,
                                       const char *path)
 {
        return convert_to_git(istate, path, NULL, 0, NULL, 0);
 }
 /* Precondition: would_convert_to_git_filter_fd(path) == true */
-extern void convert_to_git_filter_fd(const struct index_state *istate,
-                                    const char *path, int fd,
-                                    struct strbuf *dst,
-                                    int conv_flags);
-extern int would_convert_to_git_filter_fd(const char *path);
+void convert_to_git_filter_fd(const struct index_state *istate,
+                             const char *path, int fd,
+                             struct strbuf *dst,
+                             int conv_flags);
+int would_convert_to_git_filter_fd(const struct index_state *istate,
+                                  const char *path);
 
 /*****************************************************************
  *
@@ -95,9 +102,11 @@ extern int would_convert_to_git_filter_fd(const char *path);
 
 struct stream_filter; /* opaque */
 
-extern struct stream_filter *get_stream_filter(const char *path, const struct object_id *);
-extern void free_stream_filter(struct stream_filter *);
-extern int is_null_stream_filter(struct stream_filter *);
+struct stream_filter *get_stream_filter(const struct index_state *istate,
+                                       const char *path,
+                                       const struct object_id *);
+void free_stream_filter(struct stream_filter *);
+int is_null_stream_filter(struct stream_filter *);
 
 /*
  * Use as much input up to *isize_p and fill output up to *osize_p;
@@ -111,8 +120,8 @@ extern int is_null_stream_filter(struct stream_filter *);
  * such filters know there is no more input coming and it is time for
  * them to produce the remaining output based on the buffered input.
  */
-extern int stream_filter(struct stream_filter *,
-                        const char *input, size_t *isize_p,
-                        char *output, size_t *osize_p);
+int stream_filter(struct stream_filter *,
+                 const char *input, size_t *isize_p,
+                 char *output, size_t *osize_p);
 
 #endif /* CONVERT_H */
index c5a2e335e7e063528da8386cc95fba4f7bb5bfe8..3bf7184736365c2034b6851ca4a1f3c9d052cb42 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef CSUM_FILE_H
 #define CSUM_FILE_H
 
+#include "hash.h"
+
 struct progress;
 
 /* A SHA1-protected file */
index 732f684a49c54cdbc3b9708e91c064b7845d7716..88a98b1c06e8792136eced81a7da5f9aacb8542f 100644 (file)
@@ -109,7 +109,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                if (diff_can_quit_early(&revs->diffopt))
                        break;
 
-               if (!ce_path_match(ce, &revs->prune_data, NULL))
+               if (!ce_path_match(&the_index, ce, &revs->prune_data, NULL))
                        continue;
 
                if (ce_stage(ce)) {
@@ -474,7 +474,7 @@ static int oneway_diff(const struct cache_entry * const *src,
        if (tree == o->df_conflict_entry)
                tree = NULL;
 
-       if (ce_path_match(idx ? idx : tree, &revs->prune_data, NULL)) {
+       if (ce_path_match(&the_index, idx ? idx : tree, &revs->prune_data, NULL)) {
                do_oneway_diff(o, idx, tree);
                if (diff_can_quit_early(&revs->diffopt)) {
                        o->exiting_early = 1;
diff --git a/diff.c b/diff.c
index f830afac79134219e706730c05d98f81d4a1d8cd..145cfbae5929c69224f9f9e5bc473f2a221603de 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -70,6 +70,12 @@ static char diff_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_BOLD_YELLOW,  /* NEW_MOVED ALTERNATIVE */
        GIT_COLOR_FAINT,        /* NEW_MOVED_DIM */
        GIT_COLOR_FAINT_ITALIC, /* NEW_MOVED_ALTERNATIVE_DIM */
+       GIT_COLOR_FAINT,        /* CONTEXT_DIM */
+       GIT_COLOR_FAINT_RED,    /* OLD_DIM */
+       GIT_COLOR_FAINT_GREEN,  /* NEW_DIM */
+       GIT_COLOR_BOLD,         /* CONTEXT_BOLD */
+       GIT_COLOR_BOLD_RED,     /* OLD_BOLD */
+       GIT_COLOR_BOLD_GREEN,   /* NEW_BOLD */
 };
 
 static const char *color_diff_slots[] = {
@@ -89,6 +95,12 @@ static const char *color_diff_slots[] = {
        [DIFF_FILE_NEW_MOVED_ALT]     = "newMovedAlternative",
        [DIFF_FILE_NEW_MOVED_DIM]     = "newMovedDimmed",
        [DIFF_FILE_NEW_MOVED_ALT_DIM] = "newMovedAlternativeDimmed",
+       [DIFF_CONTEXT_DIM]            = "contextDimmed",
+       [DIFF_FILE_OLD_DIM]           = "oldDimmed",
+       [DIFF_FILE_NEW_DIM]           = "newDimmed",
+       [DIFF_CONTEXT_BOLD]           = "contextBold",
+       [DIFF_FILE_OLD_BOLD]          = "oldBold",
+       [DIFF_FILE_NEW_BOLD]          = "newBold",
 };
 
 static NORETURN void die_want_option(const char *option_name)
@@ -611,14 +623,18 @@ static void check_blank_at_eof(mmfile_t *mf1, mmfile_t *mf2,
        ecbdata->blank_at_eof_in_postimage = (at - l2) + 1;
 }
 
-static void emit_line_0(struct diff_options *o, const char *set, const char *reset,
+static void emit_line_0(struct diff_options *o,
+                       const char *set, unsigned reverse, const char *reset,
                        int first, const char *line, int len)
 {
        int has_trailing_newline, has_trailing_carriage_return;
        int nofirst;
        FILE *file = o->file;
 
-       fputs(diff_line_prefix(o), file);
+       if (first)
+               fputs(diff_line_prefix(o), file);
+       else if (!len)
+               return;
 
        if (len == 0) {
                has_trailing_newline = (first == '\n');
@@ -636,8 +652,10 @@ static void emit_line_0(struct diff_options *o, const char *set, const char *res
        }
 
        if (len || !nofirst) {
+               if (reverse && want_color(o->use_color))
+                       fputs(GIT_COLOR_REVERSE, file);
                fputs(set, file);
-               if (!nofirst)
+               if (first && !nofirst)
                        fputc(first, file);
                fwrite(line, len, 1, file);
                fputs(reset, file);
@@ -651,7 +669,7 @@ static void emit_line_0(struct diff_options *o, const char *set, const char *res
 static void emit_line(struct diff_options *o, const char *set, const char *reset,
                      const char *line, int len)
 {
-       emit_line_0(o, set, reset, line[0], line+1, len-1);
+       emit_line_0(o, set, 0, reset, line[0], line+1, len-1);
 }
 
 enum diff_symbol {
@@ -1170,7 +1188,8 @@ static void dim_moved_lines(struct diff_options *o)
 
 static void emit_line_ws_markup(struct diff_options *o,
                                const char *set, const char *reset,
-                               const char *line, int len, char sign,
+                               const char *line, int len,
+                               const char *set_sign, char sign,
                                unsigned ws_rule, int blank_at_eof)
 {
        const char *ws = NULL;
@@ -1181,14 +1200,20 @@ static void emit_line_ws_markup(struct diff_options *o,
                        ws = NULL;
        }
 
-       if (!ws)
-               emit_line_0(o, set, reset, sign, line, len);
-       else if (blank_at_eof)
+       if (!ws && !set_sign)
+               emit_line_0(o, set, 0, reset, sign, line, len);
+       else if (!ws) {
+               /* Emit just the prefix, then the rest. */
+               emit_line_0(o, set_sign ? set_sign : set, !!set_sign, reset,
+                           sign, "", 0);
+               emit_line_0(o, set, 0, reset, 0, line, len);
+       } else if (blank_at_eof)
                /* Blank line at EOF - paint '+' as well */
-               emit_line_0(o, ws, reset, sign, line, len);
+               emit_line_0(o, ws, 0, reset, sign, line, len);
        else {
                /* Emit just the prefix, then the rest. */
-               emit_line_0(o, set, reset, sign, "", 0);
+               emit_line_0(o, set_sign ? set_sign : set, !!set_sign, reset,
+                           sign, "", 0);
                ws_check_emit(line, len, ws_rule,
                              o->file, set, reset, ws);
        }
@@ -1198,7 +1223,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
                                         struct emitted_diff_symbol *eds)
 {
        static const char *nneof = " No newline at end of file\n";
-       const char *context, *reset, *set, *meta, *fraginfo;
+       const char *context, *reset, *set, *set_sign, *meta, *fraginfo;
        struct strbuf sb = STRBUF_INIT;
 
        enum diff_symbol s = eds->s;
@@ -1211,7 +1236,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
                context = diff_get_color_opt(o, DIFF_CONTEXT);
                reset = diff_get_color_opt(o, DIFF_RESET);
                putc('\n', o->file);
-               emit_line_0(o, context, reset, '\\',
+               emit_line_0(o, context, 0, reset, '\\',
                            nneof, strlen(nneof));
                break;
        case DIFF_SYMBOL_SUBMODULE_HEADER:
@@ -1238,7 +1263,18 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
        case DIFF_SYMBOL_CONTEXT:
                set = diff_get_color_opt(o, DIFF_CONTEXT);
                reset = diff_get_color_opt(o, DIFF_RESET);
-               emit_line_ws_markup(o, set, reset, line, len, ' ',
+               set_sign = NULL;
+               if (o->flags.dual_color_diffed_diffs) {
+                       char c = !len ? 0 : line[0];
+
+                       if (c == '+')
+                               set = diff_get_color_opt(o, DIFF_FILE_NEW);
+                       else if (c == '@')
+                               set = diff_get_color_opt(o, DIFF_FRAGINFO);
+                       else if (c == '-')
+                               set = diff_get_color_opt(o, DIFF_FILE_OLD);
+               }
+               emit_line_ws_markup(o, set, reset, line, len, set_sign, ' ',
                                    flags & (DIFF_SYMBOL_CONTENT_WS_MASK), 0);
                break;
        case DIFF_SYMBOL_PLUS:
@@ -1265,7 +1301,23 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
                        set = diff_get_color_opt(o, DIFF_FILE_NEW);
                }
                reset = diff_get_color_opt(o, DIFF_RESET);
-               emit_line_ws_markup(o, set, reset, line, len, '+',
+               if (!o->flags.dual_color_diffed_diffs)
+                       set_sign = NULL;
+               else {
+                       char c = !len ? 0 : line[0];
+
+                       set_sign = set;
+                       if (c == '-')
+                               set = diff_get_color_opt(o, DIFF_FILE_OLD_BOLD);
+                       else if (c == '@')
+                               set = diff_get_color_opt(o, DIFF_FRAGINFO);
+                       else if (c == '+')
+                               set = diff_get_color_opt(o, DIFF_FILE_NEW_BOLD);
+                       else
+                               set = diff_get_color_opt(o, DIFF_CONTEXT_BOLD);
+                       flags &= ~DIFF_SYMBOL_CONTENT_WS_MASK;
+               }
+               emit_line_ws_markup(o, set, reset, line, len, set_sign, '+',
                                    flags & DIFF_SYMBOL_CONTENT_WS_MASK,
                                    flags & DIFF_SYMBOL_CONTENT_BLANK_LINE_EOF);
                break;
@@ -1293,7 +1345,22 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
                        set = diff_get_color_opt(o, DIFF_FILE_OLD);
                }
                reset = diff_get_color_opt(o, DIFF_RESET);
-               emit_line_ws_markup(o, set, reset, line, len, '-',
+               if (!o->flags.dual_color_diffed_diffs)
+                       set_sign = NULL;
+               else {
+                       char c = !len ? 0 : line[0];
+
+                       set_sign = set;
+                       if (c == '+')
+                               set = diff_get_color_opt(o, DIFF_FILE_NEW_DIM);
+                       else if (c == '@')
+                               set = diff_get_color_opt(o, DIFF_FRAGINFO);
+                       else if (c == '-')
+                               set = diff_get_color_opt(o, DIFF_FILE_OLD_DIM);
+                       else
+                               set = diff_get_color_opt(o, DIFF_CONTEXT_DIM);
+               }
+               emit_line_ws_markup(o, set, reset, line, len, set_sign, '-',
                                    flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
                break;
        case DIFF_SYMBOL_WORDS_PORCELAIN:
@@ -1484,6 +1551,7 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
        const char *frag = diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO);
        const char *func = diff_get_color(ecbdata->color_diff, DIFF_FUNCINFO);
        const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
+       const char *reverse = ecbdata->color_diff ? GIT_COLOR_REVERSE : "";
        static const char atat[2] = { '@', '@' };
        const char *cp, *ep;
        struct strbuf msgbuf = STRBUF_INIT;
@@ -1504,6 +1572,8 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
        ep += 2; /* skip over @@ */
 
        /* The hunk header in fraginfo color */
+       if (ecbdata->opt->flags.dual_color_diffed_diffs)
+               strbuf_addstr(&msgbuf, reverse);
        strbuf_addstr(&msgbuf, frag);
        strbuf_add(&msgbuf, line, ep - line);
        strbuf_addstr(&msgbuf, reset);
@@ -3397,13 +3467,16 @@ static void builtin_diff(const char *name_a,
                memset(&xpp, 0, sizeof(xpp));
                memset(&xecfg, 0, sizeof(xecfg));
                memset(&ecbdata, 0, sizeof(ecbdata));
+               if (o->flags.suppress_diff_headers)
+                       lbl[0] = NULL;
                ecbdata.label_path = lbl;
                ecbdata.color_diff = want_color(o->use_color);
                ecbdata.ws_rule = whitespace_rule(name_b);
                if (ecbdata.ws_rule & WS_BLANK_AT_EOF)
                        check_blank_at_eof(&mf1, &mf2, &ecbdata);
                ecbdata.opt = o;
-               ecbdata.header = header.len ? &header : NULL;
+               if (header.len && !o->flags.suppress_diff_headers)
+                       ecbdata.header = &header;
                xpp.flags = o->xdl_opts;
                xpp.anchors = o->anchors;
                xpp.anchors_nr = o->anchors_nr;
@@ -3895,7 +3968,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
        temp->tempfile = mks_tempfile_ts(tempfile.buf, strlen(base) + 1);
        if (!temp->tempfile)
                die_errno("unable to create temp-file");
-       if (convert_to_working_tree(path,
+       if (convert_to_working_tree(&the_index, path,
                        (const char *)blob, (size_t)size, &buf)) {
                blob = buf.buf;
                size = buf.len;
@@ -4416,16 +4489,6 @@ void diff_setup_done(struct diff_options *options)
 
        if (options->detect_rename && options->rename_limit < 0)
                options->rename_limit = diff_rename_limit_default;
-       if (options->setup & DIFF_SETUP_USE_CACHE) {
-               if (!active_cache)
-                       /* read-cache does not die even when it fails
-                        * so it is safe for us to do this here.  Also
-                        * it does not smudge active_cache or active_nr
-                        * when it fails, so we do not have to worry about
-                        * cleaning it up ourselves either.
-                        */
-                       read_cache();
-       }
        if (hexsz < options->abbrev)
                options->abbrev = hexsz; /* full */
 
diff --git a/diff.h b/diff.h
index a14895bb824f2c844f8d2382b42d6c6f738e3835..89544e64bc5797fe40f069e84657d85589f0252a 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -94,6 +94,8 @@ struct diff_flags {
        unsigned funccontext:1;
        unsigned default_follow_renames:1;
        unsigned stat_with_summary:1;
+       unsigned suppress_diff_headers:1;
+       unsigned dual_color_diffed_diffs:1;
 };
 
 static inline void diff_flags_or(struct diff_flags *a,
@@ -246,7 +248,13 @@ enum color_diff {
        DIFF_FILE_NEW_MOVED = 13,
        DIFF_FILE_NEW_MOVED_ALT = 14,
        DIFF_FILE_NEW_MOVED_DIM = 15,
-       DIFF_FILE_NEW_MOVED_ALT_DIM = 16
+       DIFF_FILE_NEW_MOVED_ALT_DIM = 16,
+       DIFF_CONTEXT_DIM = 17,
+       DIFF_FILE_OLD_DIM = 18,
+       DIFF_FILE_NEW_DIM = 19,
+       DIFF_CONTEXT_BOLD = 20,
+       DIFF_FILE_OLD_BOLD = 21,
+       DIFF_FILE_NEW_BOLD = 22,
 };
 const char *diff_get_color(int diff_use_color, enum color_diff ix);
 #define diff_get_color_opt(o, ix) \
@@ -258,15 +266,15 @@ const char *diff_line_prefix(struct diff_options *);
 
 extern const char mime_boundary_leader[];
 
-extern struct combine_diff_path *diff_tree_paths(
+struct combine_diff_path *diff_tree_paths(
        struct combine_diff_path *p, const struct object_id *oid,
        const struct object_id **parents_oid, int nparent,
        struct strbuf *base, struct diff_options *opt);
-extern int diff_tree_oid(const struct object_id *old_oid,
-                        const struct object_id *new_oid,
-                        const char *base, struct diff_options *opt);
-extern int diff_root_tree_oid(const struct object_id *new_oid, const char *base,
-                             struct diff_options *opt);
+int diff_tree_oid(const struct object_id *old_oid,
+                 const struct object_id *new_oid,
+                 const char *base, struct diff_options *opt);
+int diff_root_tree_oid(const struct object_id *new_oid, const char *base,
+                      struct diff_options *opt);
 
 struct combine_diff_path {
        struct combine_diff_path *next;
@@ -283,53 +291,52 @@ struct combine_diff_path {
        st_add4(sizeof(struct combine_diff_path), (l), 1, \
                st_mult(sizeof(struct combine_diff_parent), (n)))
 
-extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
-                             int dense, struct rev_info *);
+void show_combined_diff(struct combine_diff_path *elem, int num_parent,
+                       int dense, struct rev_info *);
 
-extern void diff_tree_combined(const struct object_id *oid, const struct oid_array *parents, int dense, struct rev_info *rev);
+void diff_tree_combined(const struct object_id *oid, const struct oid_array *parents, int dense, struct rev_info *rev);
 
-extern void diff_tree_combined_merge(const struct commit *commit, int dense, struct rev_info *rev);
+void diff_tree_combined_merge(const struct commit *commit, int dense, struct rev_info *rev);
 
 void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
 
-extern int diff_can_quit_early(struct diff_options *);
+int diff_can_quit_early(struct diff_options *);
 
-extern void diff_addremove(struct diff_options *,
-                          int addremove,
-                          unsigned mode,
-                          const struct object_id *oid,
-                          int oid_valid,
-                          const char *fullpath, unsigned dirty_submodule);
+void diff_addremove(struct diff_options *,
+                   int addremove,
+                   unsigned mode,
+                   const struct object_id *oid,
+                   int oid_valid,
+                   const char *fullpath, unsigned dirty_submodule);
 
-extern void diff_change(struct diff_options *,
-                       unsigned mode1, unsigned mode2,
-                       const struct object_id *old_oid,
-                       const struct object_id *new_oid,
-                       int old_oid_valid, int new_oid_valid,
-                       const char *fullpath,
-                       unsigned dirty_submodule1, unsigned dirty_submodule2);
+void diff_change(struct diff_options *,
+                unsigned mode1, unsigned mode2,
+                const struct object_id *old_oid,
+                const struct object_id *new_oid,
+                int old_oid_valid, int new_oid_valid,
+                const char *fullpath,
+                unsigned dirty_submodule1, unsigned dirty_submodule2);
 
-extern struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
+struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
 
 #define DIFF_SETUP_REVERSE             1
-#define DIFF_SETUP_USE_CACHE           2
 #define DIFF_SETUP_USE_SIZE_CACHE      4
 
 /*
  * Poor man's alternative to parse-option, to allow both stuck form
  * (--option=value) and separate form (--option value).
  */
-extern int parse_long_opt(const char *opt, const char **argv,
-                        const char **optarg);
-
-extern int git_diff_basic_config(const char *var, const char *value, void *cb);
-extern int git_diff_heuristic_config(const char *var, const char *value, void *cb);
-extern void init_diff_ui_defaults(void);
-extern int git_diff_ui_config(const char *var, const char *value, void *cb);
-extern void diff_setup(struct diff_options *);
-extern int diff_opt_parse(struct diff_options *, const char **, int, const char *);
-extern void diff_setup_done(struct diff_options *);
-extern int git_config_rename(const char *var, const char *value);
+int parse_long_opt(const char *opt, const char **argv,
+                  const char **optarg);
+
+int git_diff_basic_config(const char *var, const char *value, void *cb);
+int git_diff_heuristic_config(const char *var, const char *value, void *cb);
+void init_diff_ui_defaults(void);
+int git_diff_ui_config(const char *var, const char *value, void *cb);
+void diff_setup(struct diff_options *);
+int diff_opt_parse(struct diff_options *, const char **, int, const char *);
+void diff_setup_done(struct diff_options *);
+int git_config_rename(const char *var, const char *value);
 
 #define DIFF_DETECT_RENAME     1
 #define DIFF_DETECT_COPY       2
@@ -347,8 +354,8 @@ extern int git_config_rename(const char *var, const char *value);
 
 #define DIFF_PICKAXE_IGNORE_CASE       32
 
-extern void diffcore_std(struct diff_options *);
-extern void diffcore_fix_diff_index(struct diff_options *);
+void diffcore_std(struct diff_options *);
+void diffcore_fix_diff_index(struct diff_options *);
 
 #define COMMON_DIFF_OPTIONS_HELP \
 "\ncommon diff options:\n" \
@@ -378,9 +385,9 @@ extern void diffcore_fix_diff_index(struct diff_options *);
 "                show all files diff when -S is used and hit is found.\n" \
 "  -a  --text    treat all files as text.\n"
 
-extern int diff_queue_is_empty(void);
-extern void diff_flush(struct diff_options*);
-extern void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc);
+int diff_queue_is_empty(void);
+void diff_flush(struct diff_options*);
+void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc);
 
 /* diff-raw status letters */
 #define DIFF_STATUS_ADDED              'A'
@@ -402,24 +409,24 @@ extern void diff_warn_rename_limit(const char *varname, int needed, int degraded
  * This is different from find_unique_abbrev() in that
  * it stuffs the result with dots for alignment.
  */
-extern const char *diff_aligned_abbrev(const struct object_id *sha1, int);
+const char *diff_aligned_abbrev(const struct object_id *sha1, int);
 
 /* do not report anything on removed paths */
 #define DIFF_SILENT_ON_REMOVED 01
 /* report racily-clean paths as modified */
 #define DIFF_RACY_IS_MODIFIED 02
-extern int run_diff_files(struct rev_info *revs, unsigned int option);
-extern int run_diff_index(struct rev_info *revs, int cached);
+int run_diff_files(struct rev_info *revs, unsigned int option);
+int run_diff_index(struct rev_info *revs, int cached);
 
-extern int do_diff_cache(const struct object_id *, struct diff_options *);
-extern int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
+int do_diff_cache(const struct object_id *, struct diff_options *);
+int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
 
-extern int diff_result_code(struct diff_options *, int);
+int diff_result_code(struct diff_options *, int);
 
-extern void diff_no_index(struct rev_info *, int, const char **);
+void diff_no_index(struct rev_info *, int, const char **);
 
-extern int index_differs_from(const char *def, const struct diff_flags *flags,
-                             int ita_invisible_in_index);
+int index_differs_from(const char *def, const struct diff_flags *flags,
+                      int ita_invisible_in_index);
 
 /*
  * Fill the contents of the filespec "df", respecting any textconv defined by
@@ -432,30 +439,30 @@ extern int index_differs_from(const char *def, const struct diff_flags *flags,
  * struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
  * that should be freed by the caller.
  */
-extern size_t fill_textconv(struct userdiff_driver *driver,
-                           struct diff_filespec *df,
-                           char **outbuf);
+size_t fill_textconv(struct userdiff_driver *driver,
+                    struct diff_filespec *df,
+                    char **outbuf);
 
 /*
  * Look up the userdiff driver for the given filespec, and return it if
  * and only if it has textconv enabled (otherwise return NULL). The result
  * can be passed to fill_textconv().
  */
-extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
+struct userdiff_driver *get_textconv(struct diff_filespec *one);
 
 /*
  * Prepare diff_filespec and convert it using diff textconv API
  * if the textconv driver exists.
  * Return 1 if the conversion succeeds, 0 otherwise.
  */
-extern int textconv_object(const char *path, unsigned mode, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size);
+int textconv_object(const char *path, unsigned mode, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size);
 
-extern int parse_rename_score(const char **cp_p);
+int parse_rename_score(const char **cp_p);
 
-extern long parse_algorithm_value(const char *value);
+long parse_algorithm_value(const char *value);
 
-extern void print_stat_summary(FILE *fp, int files,
-                              int insertions, int deletions);
-extern void setup_diff_pager(struct diff_options *);
+void print_stat_summary(FILE *fp, int files,
+                       int insertions, int deletions);
+void setup_diff_pager(struct diff_options *);
 
 #endif /* DIFF_H */
index a30da161dafcf0d3951e3208000c54388803c8f0..8d81a45f510c0aed0cafcd3dce638f18fc6566f7 100644 (file)
@@ -4,6 +4,10 @@
 #ifndef DIFFCORE_H
 #define DIFFCORE_H
 
+#include "cache.h"
+
+struct diff_options;
+
 /* This header file is internal between diff.c and its diff transformers
  * (e.g. diffcore-rename, diffcore-pickaxe).  Never include this header
  * in anything else.
@@ -50,17 +54,17 @@ struct diff_filespec {
        struct userdiff_driver *driver;
 };
 
-extern struct diff_filespec *alloc_filespec(const char *);
-extern void free_filespec(struct diff_filespec *);
-extern void fill_filespec(struct diff_filespec *, const struct object_id *,
-                         int, unsigned short);
+struct diff_filespec *alloc_filespec(const char *);
+void free_filespec(struct diff_filespec *);
+void fill_filespec(struct diff_filespec *, const struct object_id *,
+                  int, unsigned short);
 
 #define CHECK_SIZE_ONLY 1
 #define CHECK_BINARY    2
-extern int diff_populate_filespec(struct diff_filespec *, unsigned int);
-extern void diff_free_filespec_data(struct diff_filespec *);
-extern void diff_free_filespec_blob(struct diff_filespec *);
-extern int diff_filespec_is_binary(struct diff_filespec *);
+int diff_populate_filespec(struct diff_filespec *, unsigned int);
+void diff_free_filespec_data(struct diff_filespec *);
+void diff_free_filespec_blob(struct diff_filespec *);
+int diff_filespec_is_binary(struct diff_filespec *);
 
 struct diff_filepair {
        struct diff_filespec *one;
@@ -86,9 +90,9 @@ struct diff_filepair {
 
 #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
 
-extern void diff_free_filepair(struct diff_filepair *);
+void diff_free_filepair(struct diff_filepair *);
 
-extern int diff_unmodified_pair(struct diff_filepair *);
+int diff_unmodified_pair(struct diff_filepair *);
 
 struct diff_queue_struct {
        struct diff_filepair **queue;
@@ -102,16 +106,16 @@ struct diff_queue_struct {
        } while (0)
 
 extern struct diff_queue_struct diff_queued_diff;
-extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
-                                       struct diff_filespec *,
-                                       struct diff_filespec *);
-extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
+struct diff_filepair *diff_queue(struct diff_queue_struct *,
+                                struct diff_filespec *,
+                                struct diff_filespec *);
+void diff_q(struct diff_queue_struct *, struct diff_filepair *);
 
-extern void diffcore_break(int);
-extern void diffcore_rename(struct diff_options *);
-extern void diffcore_merge_broken(void);
-extern void diffcore_pickaxe(struct diff_options *);
-extern void diffcore_order(const char *orderfile);
+void diffcore_break(int);
+void diffcore_rename(struct diff_options *);
+void diffcore_merge_broken(void);
+void diffcore_pickaxe(struct diff_options *);
+void diffcore_order(const char *orderfile);
 
 /* low-level interface to diffcore_order */
 struct obj_order {
@@ -138,11 +142,11 @@ void diff_debug_queue(const char *, struct diff_queue_struct *);
 #define diff_debug_queue(a,b) do { /* nothing */ } while (0)
 #endif
 
-extern int diffcore_count_changes(struct diff_filespec *src,
-                                 struct diff_filespec *dst,
-                                 void **src_count_p,
-                                 void **dst_count_p,
-                                 unsigned long *src_copied,
-                                 unsigned long *literal_added);
+int diffcore_count_changes(struct diff_filespec *src,
+                          struct diff_filespec *dst,
+                          void **src_count_p,
+                          void **dst_count_p,
+                          unsigned long *src_copied,
+                          unsigned long *literal_added);
 
 #endif
index 27739e6c29560492254c7fb7e22170cd1ff327ba..970793d07a1d72761159adca51d16859c7b72a29 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef DIR_ITERATOR_H
 #define DIR_ITERATOR_H
 
+#include "strbuf.h"
+
 /*
  * Iterate over a directory tree.
  *
diff --git a/dir.c b/dir.c
index 32f5f7275981ea1bd9a4be2fe87f5f7f47ffb571..aceb0d48692b7d727cfd2645ae88b0d45d660c09 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -276,12 +276,13 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
 #define DO_MATCH_DIRECTORY (1<<1)
 #define DO_MATCH_SUBMODULE (1<<2)
 
-static int match_attrs(const char *name, int namelen,
+static int match_attrs(const struct index_state *istate,
+                      const char *name, int namelen,
                       const struct pathspec_item *item)
 {
        int i;
 
-       git_check_attr(name, item->attr_check);
+       git_check_attr(istate, name, item->attr_check);
        for (i = 0; i < item->attr_match_nr; i++) {
                const char *value;
                int matched;
@@ -318,7 +319,8 @@ static int match_attrs(const char *name, int namelen,
  *
  * It returns 0 when there is no match.
  */
-static int match_pathspec_item(const struct pathspec_item *item, int prefix,
+static int match_pathspec_item(const struct index_state *istate,
+                              const struct pathspec_item *item, int prefix,
                               const char *name, int namelen, unsigned flags)
 {
        /* name/namelen has prefix cut off by caller */
@@ -358,7 +360,7 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,
            strncmp(item->match, name - prefix, item->prefix))
                return 0;
 
-       if (item->attr_match_nr && !match_attrs(name, namelen, item))
+       if (item->attr_match_nr && !match_attrs(istate, name, namelen, item))
                return 0;
 
        /* If the match was just the prefix, we matched */
@@ -426,7 +428,8 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,
  * pathspec did not match any names, which could indicate that the
  * user mistyped the nth pathspec.
  */
-static int do_match_pathspec(const struct pathspec *ps,
+static int do_match_pathspec(const struct index_state *istate,
+                            const struct pathspec *ps,
                             const char *name, int namelen,
                             int prefix, char *seen,
                             unsigned flags)
@@ -472,7 +475,7 @@ static int do_match_pathspec(const struct pathspec *ps,
                 */
                if (seen && ps->items[i].magic & PATHSPEC_EXCLUDE)
                        seen[i] = MATCHED_FNMATCH;
-               how = match_pathspec_item(ps->items+i, prefix, name,
+               how = match_pathspec_item(istate, ps->items+i, prefix, name,
                                          namelen, flags);
                if (ps->recursive &&
                    (ps->magic & PATHSPEC_MAXDEPTH) &&
@@ -496,17 +499,18 @@ static int do_match_pathspec(const struct pathspec *ps,
        return retval;
 }
 
-int match_pathspec(const struct pathspec *ps,
+int match_pathspec(const struct index_state *istate,
+                  const struct pathspec *ps,
                   const char *name, int namelen,
                   int prefix, char *seen, int is_dir)
 {
        int positive, negative;
        unsigned flags = is_dir ? DO_MATCH_DIRECTORY : 0;
-       positive = do_match_pathspec(ps, name, namelen,
+       positive = do_match_pathspec(istate, ps, name, namelen,
                                     prefix, seen, flags);
        if (!(ps->magic & PATHSPEC_EXCLUDE) || !positive)
                return positive;
-       negative = do_match_pathspec(ps, name, namelen,
+       negative = do_match_pathspec(istate, ps, name, namelen,
                                     prefix, seen,
                                     flags | DO_MATCH_EXCLUDE);
        return negative ? 0 : positive;
@@ -515,11 +519,12 @@ int match_pathspec(const struct pathspec *ps,
 /**
  * Check if a submodule is a superset of the pathspec
  */
-int submodule_path_match(const struct pathspec *ps,
+int submodule_path_match(const struct index_state *istate,
+                        const struct pathspec *ps,
                         const char *submodule_name,
                         char *seen)
 {
-       int matched = do_match_pathspec(ps, submodule_name,
+       int matched = do_match_pathspec(istate, ps, submodule_name,
                                        strlen(submodule_name),
                                        0, seen,
                                        DO_MATCH_DIRECTORY |
diff --git a/dir.h b/dir.h
index f5fdedbab2520547f8de2e7c827f5f9c85c932ac..e3ec26143db26f3b8c300627a3c9557b08a17edb 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -216,7 +216,8 @@ extern int count_slashes(const char *s);
 extern int simple_length(const char *match);
 extern int no_wildcard(const char *string);
 extern char *common_prefix(const struct pathspec *pathspec);
-extern int match_pathspec(const struct pathspec *pathspec,
+extern int match_pathspec(const struct index_state *istate,
+                         const struct pathspec *pathspec,
                          const char *name, int namelen,
                          int prefix, char *seen, int is_dir);
 extern int report_path_error(const char *ps_matched, const struct pathspec *pathspec, const char *prefix);
@@ -326,25 +327,28 @@ extern int git_fnmatch(const struct pathspec_item *item,
                       const char *pattern, const char *string,
                       int prefix);
 
-extern int submodule_path_match(const struct pathspec *ps,
+extern int submodule_path_match(const struct index_state *istate,
+                               const struct pathspec *ps,
                                const char *submodule_name,
                                char *seen);
 
-static inline int ce_path_match(const struct cache_entry *ce,
+static inline int ce_path_match(const struct index_state *istate,
+                               const struct cache_entry *ce,
                                const struct pathspec *pathspec,
                                char *seen)
 {
-       return match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen,
+       return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
                              S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
 }
 
-static inline int dir_path_match(const struct dir_entry *ent,
+static inline int dir_path_match(const struct index_state *istate,
+                                const struct dir_entry *ent,
                                 const struct pathspec *pathspec,
                                 int prefix, char *seen)
 {
        int has_trailing_dir = ent->len && ent->name[ent->len - 1] == '/';
        int len = has_trailing_dir ? ent->len - 1 : ent->len;
-       return match_pathspec(pathspec, ent->name, len, prefix, seen,
+       return match_pathspec(istate, pathspec, ent->name, len, prefix, seen,
                              has_trailing_dir);
 }
 
diff --git a/entry.c b/entry.c
index b5d1d3cf2312f61b551258759fcc4b217d8a6fa7..2a2ab6c839490aba1b9d2723b8e05837855f5b39 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -266,7 +266,7 @@ static int write_entry(struct cache_entry *ce,
        const struct submodule *sub;
 
        if (ce_mode_s_ifmt == S_IFREG) {
-               struct stream_filter *filter = get_stream_filter(ce->name,
+               struct stream_filter *filter = get_stream_filter(state->istate, ce->name,
                                                                 &ce->oid);
                if (filter &&
                    !streaming_write_entry(ce, path, filter,
@@ -314,14 +314,14 @@ static int write_entry(struct cache_entry *ce,
                 * Convert from git internal format to working tree format
                 */
                if (dco && dco->state != CE_NO_DELAY) {
-                       ret = async_convert_to_working_tree(ce->name, new_blob,
+                       ret = async_convert_to_working_tree(state->istate, ce->name, new_blob,
                                                            size, &buf, dco);
                        if (ret && string_list_has_string(&dco->paths, ce->name)) {
                                free(new_blob);
                                goto delayed;
                        }
                } else
-                       ret = convert_to_working_tree(ce->name, new_blob, size, &buf);
+                       ret = convert_to_working_tree(state->istate, ce->name, new_blob, size, &buf);
 
                if (ret) {
                        free(new_blob);
@@ -422,7 +422,8 @@ int checkout_entry(struct cache_entry *ce,
 
        if (!check_path(path.buf, path.len, &st, state->base_dir_len)) {
                const struct submodule *sub;
-               unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
+               unsigned changed = ie_match_stat(state->istate, ce, &st,
+                                                CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);
                /*
                 * Needs to be checked before !changed returns early,
                 * as the possibly empty directory was not changed
index 68523b6b0ecd3bf924b075bd47bf0cd3426795f3..3f3c8746c2b6e30c5d9e40772078a39c3a9638c8 100644 (file)
@@ -8,6 +8,7 @@
  * are.
  */
 #include "cache.h"
+#include "branch.h"
 #include "repository.h"
 #include "config.h"
 #include "refs.h"
index 5d283049f4ac0a1282db16dd9d61cffd2b9a53dd..d6d685cba012d6765b3998fde14b5c40fff82a96 100644 (file)
@@ -6,9 +6,15 @@
 void fetch_negotiator_init(struct fetch_negotiator *negotiator,
                           const char *algorithm)
 {
-       if (algorithm && !strcmp(algorithm, "skipping")) {
-               skipping_negotiator_init(negotiator);
-               return;
+       if (algorithm) {
+               if (!strcmp(algorithm, "skipping")) {
+                       skipping_negotiator_init(negotiator);
+                       return;
+               } else if (!strcmp(algorithm, "default")) {
+                       /* Fall through to default initialization */
+               } else {
+                       die("unknown fetch negotiation algorithm '%s'", algorithm);
+               }
        }
        default_negotiator_init(negotiator);
 }
index f80a7acdf3b3edd7425a56434c9fae6adcc4f9bd..88a078e9befd281cf5f03e9e64615b14ca768a35 100644 (file)
@@ -21,6 +21,7 @@
 #include "object-store.h"
 #include "connected.h"
 #include "fetch-negotiator.h"
+#include "fsck.h"
 
 static int transfer_unpack_limit = -1;
 static int fetch_unpack_limit = -1;
@@ -36,6 +37,7 @@ static int server_supports_filtering;
 static struct lock_file shallow_lock;
 static const char *alternate_shallow_file;
 static char *negotiation_algorithm;
+static struct strbuf fsck_msg_types = STRBUF_INIT;
 
 /* Remember to update object flag allocation in object.h */
 #define COMPLETE       (1U << 0)
@@ -867,7 +869,8 @@ static int get_pack(struct fetch_pack_args *args,
                         */
                        argv_array_push(&cmd.args, "--fsck-objects");
                else
-                       argv_array_push(&cmd.args, "--strict");
+                       argv_array_pushf(&cmd.args, "--strict%s",
+                                        fsck_msg_types.buf);
        }
 
        cmd.in = demux.out;
@@ -1401,6 +1404,31 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
        return ref;
 }
 
+static int fetch_pack_config_cb(const char *var, const char *value, void *cb)
+{
+       if (strcmp(var, "fetch.fsck.skiplist") == 0) {
+               const char *path;
+
+               if (git_config_pathname(&path, var, value))
+                       return 1;
+               strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
+                       fsck_msg_types.len ? ',' : '=', path);
+               free((char *)path);
+               return 0;
+       }
+
+       if (skip_prefix(var, "fetch.fsck.", &var)) {
+               if (is_valid_msg_type(var, value))
+                       strbuf_addf(&fsck_msg_types, "%c%s=%s",
+                               fsck_msg_types.len ? ',' : '=', var, value);
+               else
+                       warning("Skipping unknown msg id '%s'", var);
+               return 0;
+       }
+
+       return git_default_config(var, value, cb);
+}
+
 static void fetch_pack_config(void)
 {
        git_config_get_int("fetch.unpacklimit", &fetch_unpack_limit);
@@ -1411,7 +1439,7 @@ static void fetch_pack_config(void)
        git_config_get_string("fetch.negotiationalgorithm",
                              &negotiation_algorithm);
 
-       git_config(git_default_config, NULL);
+       git_config(fetch_pack_config_cb, NULL);
 }
 
 static void fetch_pack_setup(void)
diff --git a/fsck.h b/fsck.h
index c3cf5e00347bee21e161a558c6f3b8fbcad0be66..0c7e8c9428bbc808abf27ff5dfe77d8d7309b470 100644 (file)
--- a/fsck.h
+++ b/fsck.h
@@ -6,6 +6,7 @@
 #define FSCK_IGNORE 3
 
 struct fsck_options;
+struct object;
 
 void fsck_set_msg_type(struct fsck_options *options,
                const char *msg_id, const char *msg_type);
index 65f37436369cd934f2bdb3b627396c5f72a7cb03..01017c43aa68be952ec6b89530fb5aa85c8a098b 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef FSMONITOR_H
 #define FSMONITOR_H
 
+#include "cache.h"
+#include "dir.h"
+
 extern struct trace_key trace_fsmonitor;
 
 /*
index 89d37095c75775a6471b0188097a58a8d1440cb1..5f2e90932f9990419d75d803d9552acf2f14adef 100644 (file)
 #endif
 #ifdef NO_INTPTR_T
 /*
- * On I16LP32, ILP32 and LP64 "long" is the save bet, however
+ * On I16LP32, ILP32 and LP64 "long" is the safe bet, however
  * on LLP86, IL33LLP64 and P64 it needs to be "long long",
  * while on IP16 and IP16L32 it is "int" (resp. "short")
  * Size needs to match (or exceed) 'sizeof(void *)'.
index 47e38f34c3a871349630660e6e3387d554c29d36..eec264e6303684c5886804361c630e1572c1fe09 100755 (executable)
@@ -326,13 +326,17 @@ EOF
 }
 
 apache2_conf () {
-       if test -z "$module_path"
-       then
-               test -d "/usr/lib/httpd/modules" &&
-                       module_path="/usr/lib/httpd/modules"
-               test -d "/usr/lib/apache2/modules" &&
-                       module_path="/usr/lib/apache2/modules"
-       fi
+       for candidate in \
+               /etc/httpd \
+               /usr/lib/apache2 \
+               /usr/lib/httpd ;
+       do
+               if test -d "$candidate/modules"
+               then
+                       module_path="$candidate/modules"
+                       break
+               fi
+       done
        bind=
        test x"$local" = xtrue && bind='127.0.0.1:'
        echo 'text/css css' > "$fqgitdir/mime.types"
@@ -356,7 +360,7 @@ EOF
                        break
                fi
        done
-       for mod in mime dir env log_config authz_core
+       for mod in mime dir env log_config authz_core unixd
        do
                if test -e $module_path/mod_${mod}.so
                then
index c062e3de3a503bd01203f2a6aef63eea63cae5c5..d07c7f387cf478bbd93d1dada1afa1de80db0fbf 100755 (executable)
@@ -491,14 +491,16 @@ main () {
        printf "%s\n" "$files"
 
        rc=0
-       for i in $files
+       set -- $files
+       while test $# -ne 0
        do
                printf "\n"
-               if ! merge_file "$i"
+               if ! merge_file "$1"
                then
                        rc=1
-                       prompt_after_failed_merge || exit 1
+                       test $# -ne 1 && prompt_after_failed_merge || exit 1
                fi
+               shift
        done
 
        exit $rc
index 8b5ad59bdee39eba4fc56b28d6771a291dac55f0..f7fd80345cd991df4b17c6598d7dd7bd462424c7 100755 (executable)
@@ -438,6 +438,9 @@ cmd_update()
                -q|--quiet)
                        GIT_QUIET=1
                        ;;
+               -v)
+                       GIT_QUIET=0
+                       ;;
                --progress)
                        progress=1
                        ;;
diff --git a/git.c b/git.c
index cc0fad93e0ac38459b981b0700260e5832e30cc9..c27c38738b2a9d9d61460b150d5ab4d36bb9cf5b 100644 (file)
--- a/git.c
+++ b/git.c
@@ -520,6 +520,7 @@ static struct cmd_struct commands[] = {
        { "prune-packed", cmd_prune_packed, RUN_SETUP },
        { "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
        { "push", cmd_push, RUN_SETUP },
+       { "range-diff", cmd_range_diff, RUN_SETUP | USE_PAGER },
        { "read-tree", cmd_read_tree, RUN_SETUP | SUPPORT_SUPER_PREFIX},
        { "rebase--helper", cmd_rebase__helper, RUN_SETUP | NEED_WORK_TREE },
        { "receive-pack", cmd_receive_pack },
index bb8ea668b3719a2da1ec2b91c4095a58d957546c..db17d65f8ac977ddc5204130cb0af6a7565ae04b 100644 (file)
@@ -136,12 +136,13 @@ int check_signature(const char *payload, size_t plen, const char *signature,
        sigc->gpg_output = strbuf_detach(&gpg_output, NULL);
        sigc->gpg_status = strbuf_detach(&gpg_status, NULL);
        parse_gpg_output(sigc);
+       status |= sigc->result != 'G' && sigc->result != 'U';
 
  out:
        strbuf_release(&gpg_status);
        strbuf_release(&gpg_output);
 
-       return sigc->result != 'G' && sigc->result != 'U';
+       return !!status;
 }
 
 void print_signature_buffer(const struct signature_check *sigc, unsigned flags)
index 5ecff4aa0c062d8a33290d39456e24c073fd48e4..acf50c46109e57bcc7809ab394c73a4d050ad9f0 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef GPG_INTERFACE_H
 #define GPG_INTERFACE_H
 
+struct strbuf;
+
 #define GPG_VERIFY_VERBOSE             1
 #define GPG_VERIFY_RAW                 2
 #define GPG_VERIFY_OMIT_STATUS 4
diff --git a/help.c b/help.c
index 3ebf0568dba1f20039b6e4d02c18c652078ad2cb..9c0b5a8de974727e98efc1ad28fd49655290ffd8 100644 (file)
--- a/help.c
+++ b/help.c
@@ -693,6 +693,7 @@ int cmd_version(int argc, const char **argv, const char *prefix)
                else
                        printf("no commit associated with this build\n");
                printf("sizeof-long: %d\n", (int)sizeof(long));
+               printf("sizeof-size_t: %d\n", (int)sizeof(size_t));
                /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
        }
        return 0;
index bd0442a805a16bf2313b65a54fdfd4bf937b13ad..88c38c834ba479447be8eb64f3bc5331cdb9ed49 100644 (file)
@@ -279,12 +279,18 @@ static struct rpc_service *select_service(struct strbuf *hdr, const char *name)
        return svc;
 }
 
+static void write_to_child(int out, const unsigned char *buf, ssize_t len, const char *prog_name)
+{
+       if (write_in_full(out, buf, len) < 0)
+               die("unable to write to '%s'", prog_name);
+}
+
 /*
  * This is basically strbuf_read(), except that if we
  * hit max_request_buffer we die (we'd rather reject a
  * maliciously large request than chew up infinite memory).
  */
-static ssize_t read_request(int fd, unsigned char **out)
+static ssize_t read_request_eof(int fd, unsigned char **out)
 {
        size_t len = 0, alloc = 8192;
        unsigned char *buf = xmalloc(alloc);
@@ -321,13 +327,54 @@ static ssize_t read_request(int fd, unsigned char **out)
        }
 }
 
-static void inflate_request(const char *prog_name, int out, int buffer_input)
+static ssize_t read_request_fixed_len(int fd, ssize_t req_len, unsigned char **out)
+{
+       unsigned char *buf = NULL;
+       ssize_t cnt = 0;
+
+       if (max_request_buffer < req_len) {
+               die("request was larger than our maximum size (%lu): "
+                   "%" PRIuMAX "; try setting GIT_HTTP_MAX_REQUEST_BUFFER",
+                   max_request_buffer, (uintmax_t)req_len);
+       }
+
+       buf = xmalloc(req_len);
+       cnt = read_in_full(fd, buf, req_len);
+       if (cnt < 0) {
+               free(buf);
+               return -1;
+       }
+       *out = buf;
+       return cnt;
+}
+
+static ssize_t get_content_length(void)
+{
+       ssize_t val = -1;
+       const char *str = getenv("CONTENT_LENGTH");
+
+       if (str && !git_parse_ssize_t(str, &val))
+               die("failed to parse CONTENT_LENGTH: %s", str);
+       return val;
+}
+
+static ssize_t read_request(int fd, unsigned char **out, ssize_t req_len)
+{
+       if (req_len < 0)
+               return read_request_eof(fd, out);
+       else
+               return read_request_fixed_len(fd, req_len, out);
+}
+
+static void inflate_request(const char *prog_name, int out, int buffer_input, ssize_t req_len)
 {
        git_zstream stream;
        unsigned char *full_request = NULL;
        unsigned char in_buf[8192];
        unsigned char out_buf[8192];
        unsigned long cnt = 0;
+       int req_len_defined = req_len >= 0;
+       size_t req_remaining_len = req_len;
 
        memset(&stream, 0, sizeof(stream));
        git_inflate_init_gzip_only(&stream);
@@ -339,11 +386,18 @@ static void inflate_request(const char *prog_name, int out, int buffer_input)
                        if (full_request)
                                n = 0; /* nothing left to read */
                        else
-                               n = read_request(0, &full_request);
+                               n = read_request(0, &full_request, req_len);
                        stream.next_in = full_request;
                } else {
-                       n = xread(0, in_buf, sizeof(in_buf));
+                       ssize_t buffer_len;
+                       if (req_len_defined && req_remaining_len <= sizeof(in_buf))
+                               buffer_len = req_remaining_len;
+                       else
+                               buffer_len = sizeof(in_buf);
+                       n = xread(0, in_buf, buffer_len);
                        stream.next_in = in_buf;
+                       if (req_len_defined && n > 0)
+                               req_remaining_len -= n;
                }
 
                if (n <= 0)
@@ -361,9 +415,8 @@ static void inflate_request(const char *prog_name, int out, int buffer_input)
                                die("zlib error inflating request, result %d", ret);
 
                        n = stream.total_out - cnt;
-                       if (write_in_full(out, out_buf, n) < 0)
-                               die("%s aborted reading request", prog_name);
-                       cnt += n;
+                       write_to_child(out, out_buf, stream.total_out - cnt, prog_name);
+                       cnt = stream.total_out;
 
                        if (ret == Z_STREAM_END)
                                goto done;
@@ -376,18 +429,34 @@ static void inflate_request(const char *prog_name, int out, int buffer_input)
        free(full_request);
 }
 
-static void copy_request(const char *prog_name, int out)
+static void copy_request(const char *prog_name, int out, ssize_t req_len)
 {
        unsigned char *buf;
-       ssize_t n = read_request(0, &buf);
+       ssize_t n = read_request(0, &buf, req_len);
        if (n < 0)
                die_errno("error reading request body");
-       if (write_in_full(out, buf, n) < 0)
-               die("%s aborted reading request", prog_name);
+       write_to_child(out, buf, n, prog_name);
        close(out);
        free(buf);
 }
 
+static void pipe_fixed_length(const char *prog_name, int out, size_t req_len)
+{
+       unsigned char buf[8192];
+       size_t remaining_len = req_len;
+
+       while (remaining_len > 0) {
+               size_t chunk_length = remaining_len > sizeof(buf) ? sizeof(buf) : remaining_len;
+               ssize_t n = xread(0, buf, chunk_length);
+               if (n < 0)
+                       die_errno("Reading request failed");
+               write_to_child(out, buf, n, prog_name);
+               remaining_len -= n;
+       }
+
+       close(out);
+}
+
 static void run_service(const char **argv, int buffer_input)
 {
        const char *encoding = getenv("HTTP_CONTENT_ENCODING");
@@ -395,6 +464,7 @@ static void run_service(const char **argv, int buffer_input)
        const char *host = getenv("REMOTE_ADDR");
        int gzipped_request = 0;
        struct child_process cld = CHILD_PROCESS_INIT;
+       ssize_t req_len = get_content_length();
 
        if (encoding && !strcmp(encoding, "gzip"))
                gzipped_request = 1;
@@ -413,7 +483,7 @@ static void run_service(const char **argv, int buffer_input)
                                 "GIT_COMMITTER_EMAIL=%s@http.%s", user, host);
 
        cld.argv = argv;
-       if (buffer_input || gzipped_request)
+       if (buffer_input || gzipped_request || req_len >= 0)
                cld.in = -1;
        cld.git_cmd = 1;
        if (start_command(&cld))
@@ -421,9 +491,11 @@ static void run_service(const char **argv, int buffer_input)
 
        close(1);
        if (gzipped_request)
-               inflate_request(argv[0], cld.in, buffer_input);
+               inflate_request(argv[0], cld.in, buffer_input, req_len);
        else if (buffer_input)
-               copy_request(argv[0], cld.in);
+               copy_request(argv[0], cld.in, req_len);
+       else if (req_len >= 0)
+               pipe_fixed_length(argv[0], cld.in, req_len);
        else
                close(0);
 
diff --git a/khash.h b/khash.h
index c0da40daa78f703f825208bb7d1b4b5b3cc05ae3..07b4cc2e6714598ef920dcf28b8f73ba34979677 100644 (file)
--- a/khash.h
+++ b/khash.h
@@ -26,6 +26,9 @@
 #ifndef __AC_KHASH_H
 #define __AC_KHASH_H
 
+#include "cache.h"
+#include "hashmap.h"
+
 #define AC_VERSION_KHASH_H "0.2.8"
 
 typedef uint32_t khint32_t;
index 83ba3c25e88a4601dc17ce01dc57dfbc33c05b2e..d3c54e45aa8a8e488778bbc7db1c6a5c0f602ab2 100644 (file)
 
 typedef const char *(*nth_line_fn_t)(void *data, long lno);
 
-extern int parse_range_arg(const char *arg,
-                          nth_line_fn_t nth_line_cb,
-                          void *cb_data, long lines, long anchor,
-                          long *begin, long *end,
-                          const char *path);
+int parse_range_arg(const char *arg,
+                   nth_line_fn_t nth_line_cb,
+                   void *cb_data, long lines, long anchor,
+                   long *begin, long *end,
+                   const char *path);
 
 /*
  * Scan past a range argument that could be parsed by
@@ -34,6 +34,6 @@ extern int parse_range_arg(const char *arg,
  * NULL in case the argument is obviously malformed.
  */
 
-extern const char *skip_range_arg(const char *arg);
+const char *skip_range_arg(const char *arg);
 
 #endif /* LINE_RANGE_H */
diff --git a/linear-assignment.c b/linear-assignment.c
new file mode 100644 (file)
index 0000000..9b3e56e
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * Based on: Jonker, R., & Volgenant, A. (1987). <i>A shortest augmenting path
+ * algorithm for dense and sparse linear assignment problems</i>. Computing,
+ * 38(4), 325-340.
+ */
+#include "cache.h"
+#include "linear-assignment.h"
+
+#define COST(column, row) cost[(column) + column_count * (row)]
+
+/*
+ * The parameter `cost` is the cost matrix: the cost to assign column j to row
+ * i is `cost[j + column_count * i].
+ */
+void compute_assignment(int column_count, int row_count, int *cost,
+                       int *column2row, int *row2column)
+{
+       int *v, *d;
+       int *free_row, free_count = 0, saved_free_count, *pred, *col;
+       int i, j, phase;
+
+       memset(column2row, -1, sizeof(int) * column_count);
+       memset(row2column, -1, sizeof(int) * row_count);
+       ALLOC_ARRAY(v, column_count);
+
+       /* column reduction */
+       for (j = column_count - 1; j >= 0; j--) {
+               int i1 = 0;
+
+               for (i = 1; i < row_count; i++)
+                       if (COST(j, i1) > COST(j, i))
+                               i1 = i;
+               v[j] = COST(j, i1);
+               if (row2column[i1] == -1) {
+                       /* row i1 unassigned */
+                       row2column[i1] = j;
+                       column2row[j] = i1;
+               } else {
+                       if (row2column[i1] >= 0)
+                               row2column[i1] = -2 - row2column[i1];
+                       column2row[j] = -1;
+               }
+       }
+
+       /* reduction transfer */
+       ALLOC_ARRAY(free_row, row_count);
+       for (i = 0; i < row_count; i++) {
+               int j1 = row2column[i];
+               if (j1 == -1)
+                       free_row[free_count++] = i;
+               else if (j1 < -1)
+                       row2column[i] = -2 - j1;
+               else {
+                       int min = COST(!j1, i) - v[!j1];
+                       for (j = 1; j < column_count; j++)
+                               if (j != j1 && min > COST(j, i) - v[j])
+                                       min = COST(j, i) - v[j];
+                       v[j1] -= min;
+               }
+       }
+
+       if (free_count ==
+           (column_count < row_count ? row_count - column_count : 0)) {
+               free(v);
+               free(free_row);
+               return;
+       }
+
+       /* augmenting row reduction */
+       for (phase = 0; phase < 2; phase++) {
+               int k = 0;
+
+               saved_free_count = free_count;
+               free_count = 0;
+               while (k < saved_free_count) {
+                       int u1, u2;
+                       int j1 = 0, j2, i0;
+
+                       i = free_row[k++];
+                       u1 = COST(j1, i) - v[j1];
+                       j2 = -1;
+                       u2 = INT_MAX;
+                       for (j = 1; j < column_count; j++) {
+                               int c = COST(j, i) - v[j];
+                               if (u2 > c) {
+                                       if (u1 < c) {
+                                               u2 = c;
+                                               j2 = j;
+                                       } else {
+                                               u2 = u1;
+                                               u1 = c;
+                                               j2 = j1;
+                                               j1 = j;
+                                       }
+                               }
+                       }
+                       if (j2 < 0) {
+                               j2 = j1;
+                               u2 = u1;
+                       }
+
+                       i0 = column2row[j1];
+                       if (u1 < u2)
+                               v[j1] -= u2 - u1;
+                       else if (i0 >= 0) {
+                               j1 = j2;
+                               i0 = column2row[j1];
+                       }
+
+                       if (i0 >= 0) {
+                               if (u1 < u2)
+                                       free_row[--k] = i0;
+                               else
+                                       free_row[free_count++] = i0;
+                       }
+                       row2column[i] = j1;
+                       column2row[j1] = i;
+               }
+       }
+
+       /* augmentation */
+       saved_free_count = free_count;
+       ALLOC_ARRAY(d, column_count);
+       ALLOC_ARRAY(pred, column_count);
+       ALLOC_ARRAY(col, column_count);
+       for (free_count = 0; free_count < saved_free_count; free_count++) {
+               int i1 = free_row[free_count], low = 0, up = 0, last, k;
+               int min, c, u1;
+
+               for (j = 0; j < column_count; j++) {
+                       d[j] = COST(j, i1) - v[j];
+                       pred[j] = i1;
+                       col[j] = j;
+               }
+
+               j = -1;
+               do {
+                       last = low;
+                       min = d[col[up++]];
+                       for (k = up; k < column_count; k++) {
+                               j = col[k];
+                               c = d[j];
+                               if (c <= min) {
+                                       if (c < min) {
+                                               up = low;
+                                               min = c;
+                                       }
+                                       col[k] = col[up];
+                                       col[up++] = j;
+                               }
+                       }
+                       for (k = low; k < up; k++)
+                               if (column2row[col[k]] == -1)
+                                       goto update;
+
+                       /* scan a row */
+                       do {
+                               int j1 = col[low++];
+
+                               i = column2row[j1];
+                               u1 = COST(j1, i) - v[j1] - min;
+                               for (k = up; k < column_count; k++) {
+                                       j = col[k];
+                                       c = COST(j, i) - v[j] - u1;
+                                       if (c < d[j]) {
+                                               d[j] = c;
+                                               pred[j] = i;
+                                               if (c == min) {
+                                                       if (column2row[j] == -1)
+                                                               goto update;
+                                                       col[k] = col[up];
+                                                       col[up++] = j;
+                                               }
+                                       }
+                               }
+                       } while (low != up);
+               } while (low == up);
+
+update:
+               /* updating of the column pieces */
+               for (k = 0; k < last; k++) {
+                       int j1 = col[k];
+                       v[j1] += d[j1] - min;
+               }
+
+               /* augmentation */
+               do {
+                       if (j < 0)
+                               BUG("negative j: %d", j);
+                       i = pred[j];
+                       column2row[j] = i;
+                       SWAP(j, row2column[i]);
+               } while (i1 != i);
+       }
+
+       free(col);
+       free(pred);
+       free(d);
+       free(v);
+       free(free_row);
+}
diff --git a/linear-assignment.h b/linear-assignment.h
new file mode 100644 (file)
index 0000000..1dfea76
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef LINEAR_ASSIGNMENT_H
+#define LINEAR_ASSIGNMENT_H
+
+/*
+ * Compute an assignment of columns -> rows (and vice versa) such that every
+ * column is assigned to at most one row (and vice versa) minimizing the
+ * overall cost.
+ *
+ * The parameter `cost` is the cost matrix: the cost to assign column j to row
+ * i is `cost[j + column_count * i].
+ *
+ * The arrays column2row and row2column will be populated with the respective
+ * assignments (-1 for unassigned, which can happen only if column_count !=
+ * row_count).
+ */
+void compute_assignment(int column_count, int row_count, int *cost,
+                       int *column2row, int *row2column);
+
+/* The maximal cost in the cost matrix (to prevent integer overflows). */
+#define COST_MAX (1<<16)
+
+#endif
index a963d0274ceb1ea80c9b4ba2003dfb4dd0226116..a6f6b4990b43c8f4c8cb94ba5b890370287ec868 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef LIST_OBJECTS_FILTER_H
 #define LIST_OBJECTS_FILTER_H
 
+struct list_objects_filter_options;
+struct object;
+struct oidset;
+
 /*
  * During list-object traversal we allow certain objects to be
  * filtered (omitted) from the result.  The active filter uses
index aa618d7f4579b2ec9c4e506f821caa1fc3fb2b37..ad407629269a7e7c77953390beccf036fd2452f6 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef LIST_OBJECTS_H
 #define LIST_OBJECTS_H
 
+struct commit;
+struct object;
+struct rev_info;
+
 typedef void (*show_commit_fn)(struct commit *, void *);
 typedef void (*show_object_fn)(struct object *, const char *, void *);
 void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, void *);
index a6ad2ec12dc9c1ece81f120196c81fd259e40eb6..0e2800f7bb46bdf9e1713d210a5dc1c02fbbaa26 100644 (file)
@@ -371,7 +371,7 @@ int ll_merge(mmbuffer_t *result_buf,
        if (!check)
                check = attr_check_initl("merge", "conflict-marker-size", NULL);
 
-       if (!git_check_attr(path, check)) {
+       if (!git_check_attr(&the_index, path, check)) {
                ll_driver_name = check->items[0].value;
                if (check->items[1].value) {
                        marker_size = atoi(check->items[1].value);
@@ -398,7 +398,7 @@ int ll_merge_marker_size(const char *path)
 
        if (!check)
                check = attr_check_initl("conflict-marker-size", NULL);
-       if (!git_check_attr(path, check) && check->items[0].value) {
+       if (!git_check_attr(&the_index, path, check) && check->items[0].value) {
                marker_size = atoi(check->items[0].value);
                if (marker_size <= 0)
                        marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
index 244a31f55ac7375b59d7c257bfc2391957fdca94..b72b19921e8f33ab23aa5bb6293b9b6841035df9 100644 (file)
@@ -5,6 +5,8 @@
 #ifndef LL_MERGE_H
 #define LL_MERGE_H
 
+#include "xdiff/xdiff.h"
+
 struct ll_merge_options {
        unsigned virtual_ancestor : 1;
        unsigned variant : 2;   /* favor ours, favor theirs, or union merge */
index 04a25351d6d39c4d0bb00943bb23ee99e8d41bcf..766c03dd1d29d00beb75b7553fc6717e24978384 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef MAILINFO_H
 #define MAILINFO_H
 
+#include "strbuf.h"
+
 #define MAX_BOUNDARIES 5
 
 struct mailinfo {
index ed7c93b05c3cc904c3052bae199346a698eec1e6..d0e65646cb57e60aa9021c0d8754c6844199acb8 100644 (file)
--- a/mailmap.h
+++ b/mailmap.h
@@ -1,6 +1,8 @@
 #ifndef MAILMAP_H
 #define MAILMAP_H
 
+struct string_list;
+
 int read_mailmap(struct string_list *map, char **repo_abbrev);
 void clear_mailmap(struct string_list *map);
 
index 4cdeff53e1e8533b0dba168c19187353901253ea..37653308d3601e56191d2f83f967cc77ad1517af 100644 (file)
@@ -83,34 +83,43 @@ static int score_trees(const struct object_id *hash1, const struct object_id *ha
        int score = 0;
 
        for (;;) {
-               struct name_entry e1, e2;
-               int got_entry_from_one = tree_entry(&one, &e1);
-               int got_entry_from_two = tree_entry(&two, &e2);
                int cmp;
 
-               if (got_entry_from_one && got_entry_from_two)
-                       cmp = base_name_entries_compare(&e1, &e2);
-               else if (got_entry_from_one)
+               if (one.size && two.size)
+                       cmp = base_name_entries_compare(&one.entry, &two.entry);
+               else if (one.size)
                        /* two lacks this entry */
                        cmp = -1;
-               else if (got_entry_from_two)
+               else if (two.size)
                        /* two has more entries */
                        cmp = 1;
                else
                        break;
 
-               if (cmp < 0)
+               if (cmp < 0) {
                        /* path1 does not appear in two */
-                       score += score_missing(e1.mode, e1.path);
-               else if (cmp > 0)
+                       score += score_missing(one.entry.mode, one.entry.path);
+                       update_tree_entry(&one);
+               } else if (cmp > 0) {
                        /* path2 does not appear in one */
-                       score += score_missing(e2.mode, e2.path);
-               else if (oidcmp(e1.oid, e2.oid))
-                       /* they are different */
-                       score += score_differs(e1.mode, e2.mode, e1.path);
-               else
-                       /* same subtree or blob */
-                       score += score_matches(e1.mode, e2.mode, e1.path);
+                       score += score_missing(two.entry.mode, two.entry.path);
+                       update_tree_entry(&two);
+               } else {
+                       /* path appears in both */
+                       if (oidcmp(one.entry.oid, two.entry.oid)) {
+                               /* they are different */
+                               score += score_differs(one.entry.mode,
+                                                      two.entry.mode,
+                                                      one.entry.path);
+                       } else {
+                               /* same subtree or blob */
+                               score += score_matches(one.entry.mode,
+                                                      two.entry.mode,
+                                                      one.entry.path);
+                       }
+                       update_tree_entry(&one);
+                       update_tree_entry(&two);
+               }
        }
        free(one_buf);
        free(two_buf);
index bd053c70dfc518b6265ec273aad2e61c05d60d18..dcdc93019cec870f196191caf3055611faae4ede 100644 (file)
@@ -966,7 +966,7 @@ static int update_file_flags(struct merge_options *o,
                }
                if (S_ISREG(mode)) {
                        struct strbuf strbuf = STRBUF_INIT;
-                       if (convert_to_working_tree(path, buf, size, &strbuf)) {
+                       if (convert_to_working_tree(&the_index, path, buf, size, &strbuf)) {
                                free(buf);
                                size = strbuf.len;
                                buf = strbuf_detach(&strbuf, NULL);
index fa7bc6b6836f99ab9c417e2865cd5a544488d025..0c46a5a4ff48340efac6c4fd6399855067313c3b 100644 (file)
@@ -1,8 +1,10 @@
 #ifndef MERGE_RECURSIVE_H
 #define MERGE_RECURSIVE_H
 
-#include "unpack-trees.h"
 #include "string-list.h"
+#include "unpack-trees.h"
+
+struct commit;
 
 struct merge_options {
        const char *ancestor;
index f815f23451b4fc8c8a88be0f9475890d8c84c60f..6c74e9385b83ce317d6ca91f328c7790d0753e2c 100644 (file)
@@ -2,6 +2,10 @@
 #define NOTES_MERGE_H
 
 #include "notes-utils.h"
+#include "strbuf.h"
+
+struct commit;
+struct object_id;
 
 #define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE"
 
index 5d79cbef512e3bdbbfafedbd7650036aff695f83..54083065283f681d8354af633b805a4896c8b036 100644 (file)
@@ -3,6 +3,9 @@
 
 #include "notes.h"
 
+struct commit_list;
+struct object_id;
+
 /*
  * Create new notes commit from the given notes tree
  *
diff --git a/notes.h b/notes.h
index 0433f45db55b5b807abcd633f507e9c75324d4e6..414bc6855ad1593fb281f6a829797b34f3fb2e12 100644 (file)
--- a/notes.h
+++ b/notes.h
@@ -3,6 +3,9 @@
 
 #include "string-list.h"
 
+struct object_id;
+struct strbuf;
+
 /*
  * Function type for combining two notes annotating the same object.
  *
index e481f7ad41bd876df3fb98f1578c38f55fc288e5..67e66227d9c41e2f3036d0aeb89afaf5a17ec98a 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef OBJECT_STORE_H
 #define OBJECT_STORE_H
 
+#include "cache.h"
 #include "oidmap.h"
 #include "list.h"
 #include "sha1-array.h"
@@ -262,4 +263,94 @@ int oid_object_info_extended(struct repository *r,
                             const struct object_id *,
                             struct object_info *, unsigned flags);
 
+/*
+ * Iterate over the files in the loose-object parts of the object
+ * directory "path", triggering the following callbacks:
+ *
+ *  - loose_object is called for each loose object we find.
+ *
+ *  - loose_cruft is called for any files that do not appear to be
+ *    loose objects. Note that we only look in the loose object
+ *    directories "objects/[0-9a-f]{2}/", so we will not report
+ *    "objects/foobar" as cruft.
+ *
+ *  - loose_subdir is called for each top-level hashed subdirectory
+ *    of the object directory (e.g., "$OBJDIR/f0"). It is called
+ *    after the objects in the directory are processed.
+ *
+ * Any callback that is NULL will be ignored. Callbacks returning non-zero
+ * will end the iteration.
+ *
+ * In the "buf" variant, "path" is a strbuf which will also be used as a
+ * scratch buffer, but restored to its original contents before
+ * the function returns.
+ */
+typedef int each_loose_object_fn(const struct object_id *oid,
+                                const char *path,
+                                void *data);
+typedef int each_loose_cruft_fn(const char *basename,
+                               const char *path,
+                               void *data);
+typedef int each_loose_subdir_fn(unsigned int nr,
+                                const char *path,
+                                void *data);
+int for_each_file_in_obj_subdir(unsigned int subdir_nr,
+                               struct strbuf *path,
+                               each_loose_object_fn obj_cb,
+                               each_loose_cruft_fn cruft_cb,
+                               each_loose_subdir_fn subdir_cb,
+                               void *data);
+int for_each_loose_file_in_objdir(const char *path,
+                                 each_loose_object_fn obj_cb,
+                                 each_loose_cruft_fn cruft_cb,
+                                 each_loose_subdir_fn subdir_cb,
+                                 void *data);
+int for_each_loose_file_in_objdir_buf(struct strbuf *path,
+                                     each_loose_object_fn obj_cb,
+                                     each_loose_cruft_fn cruft_cb,
+                                     each_loose_subdir_fn subdir_cb,
+                                     void *data);
+
+/* Flags for for_each_*_object() below. */
+enum for_each_object_flags {
+       /* Iterate only over local objects, not alternates. */
+       FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
+
+       /* Only iterate over packs obtained from the promisor remote. */
+       FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
+
+       /*
+        * Visit objects within a pack in packfile order rather than .idx order
+        */
+       FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
+};
+
+/*
+ * Iterate over all accessible loose objects without respect to
+ * reachability. By default, this includes both local and alternate objects.
+ * The order in which objects are visited is unspecified.
+ *
+ * Any flags specific to packs are ignored.
+ */
+int for_each_loose_object(each_loose_object_fn, void *,
+                         enum for_each_object_flags flags);
+
+/*
+ * Iterate over all accessible packed objects without respect to reachability.
+ * By default, this includes both local and alternate packs.
+ *
+ * Note that some objects may appear twice if they are found in multiple packs.
+ * Each pack is visited in an unspecified order. By default, objects within a
+ * pack are visited in pack-idx order (i.e., sorted by oid).
+ */
+typedef int each_packed_object_fn(const struct object_id *oid,
+                                 struct packed_git *pack,
+                                 uint32_t pos,
+                                 void *data);
+int for_each_object_in_pack(struct packed_git *p,
+                           each_packed_object_fn, void *data,
+                           enum for_each_object_flags flags);
+int for_each_packed_object(each_packed_object_fn, void *,
+                          enum for_each_object_flags flags);
+
 #endif /* OBJECT_STORE_H */
index 177b1a4571fb60f75d523124c09c133c2f5c84e6..6e28fdd0b426a3e276001e674675cf386f7d86c1 100644 (file)
--- a/object.h
+++ b/object.h
@@ -1,6 +1,8 @@
 #ifndef OBJECT_H
 #define OBJECT_H
 
+#include "cache.h"
+
 struct buffer_slab;
 
 struct parsed_object_pool {
index d3cd2bb5902964554a16313cdb9ba4924e871e56..72430b611ebf710b4c3ba0160af91104258db138 100644 (file)
--- a/oidmap.h
+++ b/oidmap.h
@@ -1,6 +1,7 @@
 #ifndef OIDMAP_H
 #define OIDMAP_H
 
+#include "cache.h"
 #include "hashmap.h"
 
 /*
index 4555907dee99fbf731b739c584837adbbe8270f1..8a04741e1253b0ba801445a76ceb8e4937121f73 100644 (file)
@@ -5,6 +5,9 @@
 #include "khash.h"
 #include "pack-objects.h"
 
+struct commit;
+struct rev_info;
+
 struct bitmap_disk_header {
        char magic[4];
        uint16_t version;
index edf74dabddfdb2b67bad803d1c898e93a3af4d8b..08c6b57d49791556f323ebf8654e98689a19593c 100644 (file)
@@ -2,6 +2,7 @@
 #define PACK_OBJECTS_H
 
 #include "object-store.h"
+#include "pack.h"
 
 #define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024)
 
index 6974903e581ae4517979ec083da844bde3034c8f..ebcb5742ec748d730f8d730ad8b0744e9094d121 100644 (file)
@@ -1885,26 +1885,38 @@ int has_pack_index(const unsigned char *sha1)
        return 1;
 }
 
-int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn cb, void *data)
+int for_each_object_in_pack(struct packed_git *p,
+                           each_packed_object_fn cb, void *data,
+                           enum for_each_object_flags flags)
 {
        uint32_t i;
        int r = 0;
 
+       if (flags & FOR_EACH_OBJECT_PACK_ORDER)
+               load_pack_revindex(p);
+
        for (i = 0; i < p->num_objects; i++) {
+               uint32_t pos;
                struct object_id oid;
 
-               if (!nth_packed_object_oid(&oid, p, i))
+               if (flags & FOR_EACH_OBJECT_PACK_ORDER)
+                       pos = p->revindex[i].nr;
+               else
+                       pos = i;
+
+               if (!nth_packed_object_oid(&oid, p, pos))
                        return error("unable to get sha1 of object %u in %s",
-                                    i, p->pack_name);
+                                    pos, p->pack_name);
 
-               r = cb(&oid, p, i, data);
+               r = cb(&oid, p, pos, data);
                if (r)
                        break;
        }
        return r;
 }
 
-int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)
+int for_each_packed_object(each_packed_object_fn cb, void *data,
+                          enum for_each_object_flags flags)
 {
        struct packed_git *p;
        int r = 0;
@@ -1921,7 +1933,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)
                        pack_errors = 1;
                        continue;
                }
-               r = for_each_object_in_pack(p, cb, data);
+               r = for_each_object_in_pack(p, cb, data, flags);
                if (r)
                        break;
        }
index fa36c473adaf02df7395329587baf07e47febb34..630f35cf31ef74975c04d17820314a85bba675af 100644 (file)
@@ -148,23 +148,6 @@ extern int has_object_pack(const struct object_id *oid);
 
 extern int has_pack_index(const unsigned char *sha1);
 
-/*
- * Only iterate over packs obtained from the promisor remote.
- */
-#define FOR_EACH_OBJECT_PROMISOR_ONLY 2
-
-/*
- * Iterate over packed objects in both the local
- * repository and any alternates repositories (unless the
- * FOR_EACH_OBJECT_LOCAL_ONLY flag, defined in cache.h, is set).
- */
-typedef int each_packed_object_fn(const struct object_id *oid,
-                                 struct packed_git *pack,
-                                 uint32_t pos,
-                                 void *data);
-extern int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn, void *data);
-extern int for_each_packed_object(each_packed_object_fn, void *, unsigned flags);
-
 /*
  * Return 1 if an object in a promisor packfile is or refers to the given
  * object, 0 otherwise.
index 7db84227ab34cb33849f4327af58acd925f782c8..3b874a83a0c897845deeec37c1a3b85e0b625050 100644 (file)
@@ -660,7 +660,8 @@ int parse_options(int argc, const char **argv, const char *prefix,
 static int usage_argh(const struct option *opts, FILE *outfile)
 {
        const char *s;
-       int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh;
+       int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) ||
+               !opts->argh || !!strpbrk(opts->argh, "()<>[]|");
        if (opts->flags & PARSE_OPT_OPTARG)
                if (opts->long_name)
                        s = literal ? "[=%s]" : "[=<%s>]";
index bec0f727a7bc4345e524ff04d9569c68fabd2209..79ac9a8498383b971107f4b30a7a75dbd30613d1 100644 (file)
@@ -1,6 +1,12 @@
 #ifndef PATCH_IDS_H
 #define PATCH_IDS_H
 
+#include "diff.h"
+#include "hashmap.h"
+
+struct commit;
+struct object_id;
+
 struct patch_id {
        struct hashmap_entry ent;
        struct object_id patch_id;
diff --git a/path.h b/path.h
index ed6732e5a22ca8fbceff68437c9df616bb819cc9..b654ea8ff5f2e701239ec17b8d1fc81cebfc25dd 100644 (file)
--- a/path.h
+++ b/path.h
@@ -2,6 +2,7 @@
 #define PATH_H
 
 struct repository;
+struct strbuf;
 
 /*
  * The result to all functions which return statically allocated memory may be
index 27cd6067860d4fdb0b48b6bcf7c84d5903efd71b..6f005996fdc8f3e412b0faafc12e65aed359be3b 100644 (file)
@@ -37,7 +37,7 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
                return;
        for (i = 0; i < istate->cache_nr; i++) {
                const struct cache_entry *ce = istate->cache[i];
-               ce_path_match(ce, pathspec, seen);
+               ce_path_match(istate, ce, pathspec, seen);
        }
 }
 
index 099a170c2ef6eb01bee98c7ebf638f34655fda86..a6525a65517bd08921ad836880184048e93c4cfa 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef PATHSPEC_H
 #define PATHSPEC_H
 
+struct index_state;
+
 /* Pathspec magic */
 #define PATHSPEC_FROMTOP       (1<<0)
 #define PATHSPEC_MAXDEPTH      (1<<1)
index 4d08d4487460f839f39f667c714f1bb85fa1e144..71cd2437a3b33b343696bf96067603e8dc9e4464 100644 (file)
@@ -58,7 +58,7 @@ static void *preload_thread(void *_data)
                        continue;
                if (ce->ce_flags & CE_FSMONITOR_VALID)
                        continue;
-               if (!ce_path_match(ce, &p->pathspec, NULL))
+               if (!ce_path_match(index, ce, &p->pathspec, NULL))
                        continue;
                if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
                        continue;
index 5c85d94e332d7f87f3f963c775eabdfa08347033..7359d318a92c167e0f36eabf73fdd1142f0e9031 100644 (file)
--- a/pretty.h
+++ b/pretty.h
@@ -1,7 +1,11 @@
 #ifndef PRETTY_H
 #define PRETTY_H
 
+#include "cache.h"
+#include "string-list.h"
+
 struct commit;
+struct strbuf;
 
 /* Commit formats */
 enum cmit_fmt {
diff --git a/range-diff.c b/range-diff.c
new file mode 100644 (file)
index 0000000..b6b9aba
--- /dev/null
@@ -0,0 +1,435 @@
+#include "cache.h"
+#include "range-diff.h"
+#include "string-list.h"
+#include "run-command.h"
+#include "argv-array.h"
+#include "hashmap.h"
+#include "xdiff-interface.h"
+#include "linear-assignment.h"
+#include "diffcore.h"
+#include "commit.h"
+#include "pretty.h"
+#include "userdiff.h"
+
+struct patch_util {
+       /* For the search for an exact match */
+       struct hashmap_entry e;
+       const char *diff, *patch;
+
+       int i, shown;
+       int diffsize;
+       size_t diff_offset;
+       /* the index of the matching item in the other branch, or -1 */
+       int matching;
+       struct object_id oid;
+};
+
+/*
+ * Reads the patches into a string list, with the `util` field being populated
+ * as struct object_id (will need to be free()d).
+ */
+static int read_patches(const char *range, struct string_list *list)
+{
+       struct child_process cp = CHILD_PROCESS_INIT;
+       FILE *in;
+       struct strbuf buf = STRBUF_INIT, line = STRBUF_INIT;
+       struct patch_util *util = NULL;
+       int in_header = 1;
+
+       argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
+                       "--reverse", "--date-order", "--decorate=no",
+                       "--no-abbrev-commit", range,
+                       NULL);
+       cp.out = -1;
+       cp.no_stdin = 1;
+       cp.git_cmd = 1;
+
+       if (start_command(&cp))
+               return error_errno(_("could not start `log`"));
+       in = fdopen(cp.out, "r");
+       if (!in) {
+               error_errno(_("could not read `log` output"));
+               finish_command(&cp);
+               return -1;
+       }
+
+       while (strbuf_getline(&line, in) != EOF) {
+               const char *p;
+
+               if (skip_prefix(line.buf, "commit ", &p)) {
+                       if (util) {
+                               string_list_append(list, buf.buf)->util = util;
+                               strbuf_reset(&buf);
+                       }
+                       util = xcalloc(sizeof(*util), 1);
+                       if (get_oid(p, &util->oid)) {
+                               error(_("could not parse commit '%s'"), p);
+                               free(util);
+                               string_list_clear(list, 1);
+                               strbuf_release(&buf);
+                               strbuf_release(&line);
+                               fclose(in);
+                               finish_command(&cp);
+                               return -1;
+                       }
+                       util->matching = -1;
+                       in_header = 1;
+                       continue;
+               }
+
+               if (starts_with(line.buf, "diff --git")) {
+                       in_header = 0;
+                       strbuf_addch(&buf, '\n');
+                       if (!util->diff_offset)
+                               util->diff_offset = buf.len;
+                       strbuf_addbuf(&buf, &line);
+               } else if (in_header) {
+                       if (starts_with(line.buf, "Author: ")) {
+                               strbuf_addbuf(&buf, &line);
+                               strbuf_addstr(&buf, "\n\n");
+                       } else if (starts_with(line.buf, "    ")) {
+                               strbuf_rtrim(&line);
+                               strbuf_addbuf(&buf, &line);
+                               strbuf_addch(&buf, '\n');
+                       }
+                       continue;
+               } else if (starts_with(line.buf, "@@ "))
+                       strbuf_addstr(&buf, "@@");
+               else if (!line.buf[0] || starts_with(line.buf, "index "))
+                       /*
+                        * A completely blank (not ' \n', which is context)
+                        * line is not valid in a diff.  We skip it
+                        * silently, because this neatly handles the blank
+                        * separator line between commits in git-log
+                        * output.
+                        *
+                        * We also want to ignore the diff's `index` lines
+                        * because they contain exact blob hashes in which
+                        * we are not interested.
+                        */
+                       continue;
+               else
+                       strbuf_addbuf(&buf, &line);
+
+               strbuf_addch(&buf, '\n');
+               util->diffsize++;
+       }
+       fclose(in);
+       strbuf_release(&line);
+
+       if (util)
+               string_list_append(list, buf.buf)->util = util;
+       strbuf_release(&buf);
+
+       if (finish_command(&cp))
+               return -1;
+
+       return 0;
+}
+
+static int patch_util_cmp(const void *dummy, const struct patch_util *a,
+                    const struct patch_util *b, const char *keydata)
+{
+       return strcmp(a->diff, keydata ? keydata : b->diff);
+}
+
+static void find_exact_matches(struct string_list *a, struct string_list *b)
+{
+       struct hashmap map;
+       int i;
+
+       hashmap_init(&map, (hashmap_cmp_fn)patch_util_cmp, NULL, 0);
+
+       /* First, add the patches of a to a hash map */
+       for (i = 0; i < a->nr; i++) {
+               struct patch_util *util = a->items[i].util;
+
+               util->i = i;
+               util->patch = a->items[i].string;
+               util->diff = util->patch + util->diff_offset;
+               hashmap_entry_init(util, strhash(util->diff));
+               hashmap_add(&map, util);
+       }
+
+       /* Now try to find exact matches in b */
+       for (i = 0; i < b->nr; i++) {
+               struct patch_util *util = b->items[i].util, *other;
+
+               util->i = i;
+               util->patch = b->items[i].string;
+               util->diff = util->patch + util->diff_offset;
+               hashmap_entry_init(util, strhash(util->diff));
+               other = hashmap_remove(&map, util, NULL);
+               if (other) {
+                       if (other->matching >= 0)
+                               BUG("already assigned!");
+
+                       other->matching = i;
+                       util->matching = other->i;
+               }
+       }
+
+       hashmap_free(&map, 0);
+}
+
+static void diffsize_consume(void *data, char *line, unsigned long len)
+{
+       (*(int *)data)++;
+}
+
+static int diffsize(const char *a, const char *b)
+{
+       xpparam_t pp = { 0 };
+       xdemitconf_t cfg = { 0 };
+       mmfile_t mf1, mf2;
+       int count = 0;
+
+       mf1.ptr = (char *)a;
+       mf1.size = strlen(a);
+       mf2.ptr = (char *)b;
+       mf2.size = strlen(b);
+
+       cfg.ctxlen = 3;
+       if (!xdi_diff_outf(&mf1, &mf2, diffsize_consume, &count, &pp, &cfg))
+               return count;
+
+       error(_("failed to generate diff"));
+       return COST_MAX;
+}
+
+static void get_correspondences(struct string_list *a, struct string_list *b,
+                               int creation_factor)
+{
+       int n = a->nr + b->nr;
+       int *cost, c, *a2b, *b2a;
+       int i, j;
+
+       ALLOC_ARRAY(cost, st_mult(n, n));
+       ALLOC_ARRAY(a2b, n);
+       ALLOC_ARRAY(b2a, n);
+
+       for (i = 0; i < a->nr; i++) {
+               struct patch_util *a_util = a->items[i].util;
+
+               for (j = 0; j < b->nr; j++) {
+                       struct patch_util *b_util = b->items[j].util;
+
+                       if (a_util->matching == j)
+                               c = 0;
+                       else if (a_util->matching < 0 && b_util->matching < 0)
+                               c = diffsize(a_util->diff, b_util->diff);
+                       else
+                               c = COST_MAX;
+                       cost[i + n * j] = c;
+               }
+
+               c = a_util->matching < 0 ?
+                       a_util->diffsize * creation_factor / 100 : COST_MAX;
+               for (j = b->nr; j < n; j++)
+                       cost[i + n * j] = c;
+       }
+
+       for (j = 0; j < b->nr; j++) {
+               struct patch_util *util = b->items[j].util;
+
+               c = util->matching < 0 ?
+                       util->diffsize * creation_factor / 100 : COST_MAX;
+               for (i = a->nr; i < n; i++)
+                       cost[i + n * j] = c;
+       }
+
+       for (i = a->nr; i < n; i++)
+               for (j = b->nr; j < n; j++)
+                       cost[i + n * j] = 0;
+
+       compute_assignment(n, n, cost, a2b, b2a);
+
+       for (i = 0; i < a->nr; i++)
+               if (a2b[i] >= 0 && a2b[i] < b->nr) {
+                       struct patch_util *a_util = a->items[i].util;
+                       struct patch_util *b_util = b->items[a2b[i]].util;
+
+                       a_util->matching = a2b[i];
+                       b_util->matching = i;
+               }
+
+       free(cost);
+       free(a2b);
+       free(b2a);
+}
+
+static void output_pair_header(struct diff_options *diffopt,
+                              int patch_no_width,
+                              struct strbuf *buf,
+                              struct strbuf *dashes,
+                              struct patch_util *a_util,
+                              struct patch_util *b_util)
+{
+       struct object_id *oid = a_util ? &a_util->oid : &b_util->oid;
+       struct commit *commit;
+       char status;
+       const char *color_reset = diff_get_color_opt(diffopt, DIFF_RESET);
+       const char *color_old = diff_get_color_opt(diffopt, DIFF_FILE_OLD);
+       const char *color_new = diff_get_color_opt(diffopt, DIFF_FILE_NEW);
+       const char *color_commit = diff_get_color_opt(diffopt, DIFF_COMMIT);
+       const char *color;
+
+       if (!dashes->len)
+               strbuf_addchars(dashes, '-',
+                               strlen(find_unique_abbrev(oid,
+                                                         DEFAULT_ABBREV)));
+
+       if (!b_util) {
+               color = color_old;
+               status = '<';
+       } else if (!a_util) {
+               color = color_new;
+               status = '>';
+       } else if (strcmp(a_util->patch, b_util->patch)) {
+               color = color_commit;
+               status = '!';
+       } else {
+               color = color_commit;
+               status = '=';
+       }
+
+       strbuf_reset(buf);
+       strbuf_addstr(buf, status == '!' ? color_old : color);
+       if (!a_util)
+               strbuf_addf(buf, "%*s:  %s ", patch_no_width, "-", dashes->buf);
+       else
+               strbuf_addf(buf, "%*d:  %s ", patch_no_width, a_util->i + 1,
+                           find_unique_abbrev(&a_util->oid, DEFAULT_ABBREV));
+
+       if (status == '!')
+               strbuf_addf(buf, "%s%s", color_reset, color);
+       strbuf_addch(buf, status);
+       if (status == '!')
+               strbuf_addf(buf, "%s%s", color_reset, color_new);
+
+       if (!b_util)
+               strbuf_addf(buf, " %*s:  %s", patch_no_width, "-", dashes->buf);
+       else
+               strbuf_addf(buf, " %*d:  %s", patch_no_width, b_util->i + 1,
+                           find_unique_abbrev(&b_util->oid, DEFAULT_ABBREV));
+
+       commit = lookup_commit_reference(the_repository, oid);
+       if (commit) {
+               if (status == '!')
+                       strbuf_addf(buf, "%s%s", color_reset, color);
+
+               strbuf_addch(buf, ' ');
+               pp_commit_easy(CMIT_FMT_ONELINE, commit, buf);
+       }
+       strbuf_addf(buf, "%s\n", color_reset);
+
+       fwrite(buf->buf, buf->len, 1, stdout);
+}
+
+static struct userdiff_driver no_func_name = {
+       .funcname = { "$^", 0 }
+};
+
+static struct diff_filespec *get_filespec(const char *name, const char *p)
+{
+       struct diff_filespec *spec = alloc_filespec(name);
+
+       fill_filespec(spec, &null_oid, 0, 0644);
+       spec->data = (char *)p;
+       spec->size = strlen(p);
+       spec->should_munmap = 0;
+       spec->is_stdin = 1;
+       spec->driver = &no_func_name;
+
+       return spec;
+}
+
+static void patch_diff(const char *a, const char *b,
+                             struct diff_options *diffopt)
+{
+       diff_queue(&diff_queued_diff,
+                  get_filespec("a", a), get_filespec("b", b));
+
+       diffcore_std(diffopt);
+       diff_flush(diffopt);
+}
+
+static void output(struct string_list *a, struct string_list *b,
+                  struct diff_options *diffopt)
+{
+       struct strbuf buf = STRBUF_INIT, dashes = STRBUF_INIT;
+       int patch_no_width = decimal_width(1 + (a->nr > b->nr ? a->nr : b->nr));
+       int i = 0, j = 0;
+
+       /*
+        * We assume the user is really more interested in the second argument
+        * ("newer" version). To that end, we print the output in the order of
+        * the RHS (the `b` parameter). To put the LHS (the `a` parameter)
+        * commits that are no longer in the RHS into a good place, we place
+        * them once we have shown all of their predecessors in the LHS.
+        */
+
+       while (i < a->nr || j < b->nr) {
+               struct patch_util *a_util, *b_util;
+               a_util = i < a->nr ? a->items[i].util : NULL;
+               b_util = j < b->nr ? b->items[j].util : NULL;
+
+               /* Skip all the already-shown commits from the LHS. */
+               while (i < a->nr && a_util->shown)
+                       a_util = ++i < a->nr ? a->items[i].util : NULL;
+
+               /* Show unmatched LHS commit whose predecessors were shown. */
+               if (i < a->nr && a_util->matching < 0) {
+                       output_pair_header(diffopt, patch_no_width,
+                                          &buf, &dashes, a_util, NULL);
+                       i++;
+                       continue;
+               }
+
+               /* Show unmatched RHS commits. */
+               while (j < b->nr && b_util->matching < 0) {
+                       output_pair_header(diffopt, patch_no_width,
+                                          &buf, &dashes, NULL, b_util);
+                       b_util = ++j < b->nr ? b->items[j].util : NULL;
+               }
+
+               /* Show matching LHS/RHS pair. */
+               if (j < b->nr) {
+                       a_util = a->items[b_util->matching].util;
+                       output_pair_header(diffopt, patch_no_width,
+                                          &buf, &dashes, a_util, b_util);
+                       if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT))
+                               patch_diff(a->items[b_util->matching].string,
+                                          b->items[j].string, diffopt);
+                       a_util->shown = 1;
+                       j++;
+               }
+       }
+       strbuf_release(&buf);
+       strbuf_release(&dashes);
+}
+
+int show_range_diff(const char *range1, const char *range2,
+                   int creation_factor, struct diff_options *diffopt)
+{
+       int res = 0;
+
+       struct string_list branch1 = STRING_LIST_INIT_DUP;
+       struct string_list branch2 = STRING_LIST_INIT_DUP;
+
+       if (read_patches(range1, &branch1))
+               res = error(_("could not parse log for '%s'"), range1);
+       if (!res && read_patches(range2, &branch2))
+               res = error(_("could not parse log for '%s'"), range2);
+
+       if (!res) {
+               find_exact_matches(&branch1, &branch2);
+               get_correspondences(&branch1, &branch2, creation_factor);
+               output(&branch1, &branch2, diffopt);
+       }
+
+       string_list_clear(&branch1, 1);
+       string_list_clear(&branch2, 1);
+
+       return res;
+}
diff --git a/range-diff.h b/range-diff.h
new file mode 100644 (file)
index 0000000..2407d46
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef RANGE_DIFF_H
+#define RANGE_DIFF_H
+
+#include "diff.h"
+
+int show_range_diff(const char *range1, const char *range2,
+                   int creation_factor, struct diff_options *diffopt);
+
+#endif
index 3c00fa0526cd97e36111f2d94ccbf3d2817ccf34..18b0f9f2f0df0b6cceb67bc0eee81244e3c8a114 100644 (file)
@@ -2,6 +2,8 @@
 #define REACHEABLE_H
 
 struct progress;
+struct rev_info;
+
 extern int add_unseen_recent_objects_to_traversal(struct rev_info *revs,
                                                  timestamp_t timestamp);
 extern void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
index 880849fc8ad8454a756ac0849dff288ad8f38eaa..7b1354d7590a70ecbd6e508bdd95eafd4793efcc 100644 (file)
@@ -1493,7 +1493,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
                if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
                        continue;
 
-               if (pathspec && !ce_path_match(ce, pathspec, seen))
+               if (pathspec && !ce_path_match(&the_index, ce, pathspec, seen))
                        filtered = 1;
 
                if (ce_stage(ce)) {
@@ -2808,10 +2808,13 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
 
 /*
  * Read the index file that is potentially unmerged into given
- * index_state, dropping any unmerged entries.  Returns true if
- * the index is unmerged.  Callers who want to refuse to work
- * from an unmerged state can call this and check its return value,
- * instead of calling read_cache().
+ * index_state, dropping any unmerged entries to stage #0 (potentially
+ * resulting in a path appearing as both a file and a directory in the
+ * index; the caller is responsible to clear out the extra entries
+ * before writing the index to a tree).  Returns true if the index is
+ * unmerged.  Callers who want to refuse to work from an unmerged
+ * state can call this and check its return value, instead of calling
+ * read_cache().
  */
 int read_index_unmerged(struct index_state *istate)
 {
@@ -2833,7 +2836,7 @@ int read_index_unmerged(struct index_state *istate)
                new_ce->ce_flags = create_ce_flags(0) | CE_CONFLICTED;
                new_ce->ce_namelen = len;
                new_ce->ce_mode = ce->ce_mode;
-               if (add_index_entry(istate, new_ce, 0))
+               if (add_index_entry(istate, new_ce, ADD_CACHE_SKIP_DFCHECK))
                        return error("%s: cannot drop to stage #0",
                                     new_ce->name);
        }
index a8def7b3a36fde5fd4b7184b84f8ae36740642f5..0bccfceff2ae31200019838d9f2b67e13e32ef6f 100644 (file)
@@ -43,6 +43,7 @@ void setup_ref_filter_porcelain_msg(void)
 
 typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
 typedef enum { COMPARE_EQUAL, COMPARE_UNEQUAL, COMPARE_NONE } cmp_status;
+typedef enum { SOURCE_NONE = 0, SOURCE_OBJ, SOURCE_OTHER } info_source;
 
 struct align {
        align_type position;
@@ -62,6 +63,17 @@ struct refname_atom {
        int lstrip, rstrip;
 };
 
+static struct expand_data {
+       struct object_id oid;
+       enum object_type type;
+       unsigned long size;
+       off_t disk_size;
+       struct object_id delta_base_oid;
+       void *content;
+
+       struct object_info info;
+} oi, oi_deref;
+
 /*
  * An atom is a valid field atom listed below, possibly prefixed with
  * a "*" to denote deref_tag().
@@ -75,6 +87,7 @@ struct refname_atom {
 static struct used_atom {
        const char *name;
        cmp_type type;
+       info_source source;
        union {
                char color[COLOR_MAXLEN];
                struct align align;
@@ -202,6 +215,30 @@ static int remote_ref_atom_parser(const struct ref_format *format, struct used_a
        return 0;
 }
 
+static int objecttype_atom_parser(const struct ref_format *format, struct used_atom *atom,
+                                 const char *arg, struct strbuf *err)
+{
+       if (arg)
+               return strbuf_addf_ret(err, -1, _("%%(objecttype) does not take arguments"));
+       if (*atom->name == '*')
+               oi_deref.info.typep = &oi_deref.type;
+       else
+               oi.info.typep = &oi.type;
+       return 0;
+}
+
+static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom,
+                                 const char *arg, struct strbuf *err)
+{
+       if (arg)
+               return strbuf_addf_ret(err, -1, _("%%(objectsize) does not take arguments"));
+       if (*atom->name == '*')
+               oi_deref.info.sizep = &oi_deref.size;
+       else
+               oi.info.sizep = &oi.size;
+       return 0;
+}
+
 static int body_atom_parser(const struct ref_format *format, struct used_atom *atom,
                            const char *arg, struct strbuf *err)
 {
@@ -382,49 +419,50 @@ static int head_atom_parser(const struct ref_format *format, struct used_atom *a
 
 static struct {
        const char *name;
+       info_source source;
        cmp_type cmp_type;
        int (*parser)(const struct ref_format *format, struct used_atom *atom,
                      const char *arg, struct strbuf *err);
 } valid_atom[] = {
-       { "refname" , FIELD_STR, refname_atom_parser },
-       { "objecttype" },
-       { "objectsize", FIELD_ULONG },
-       { "objectname", FIELD_STR, objectname_atom_parser },
-       { "tree" },
-       { "parent" },
-       { "numparent", FIELD_ULONG },
-       { "object" },
-       { "type" },
-       { "tag" },
-       { "author" },
-       { "authorname" },
-       { "authoremail" },
-       { "authordate", FIELD_TIME },
-       { "committer" },
-       { "committername" },
-       { "committeremail" },
-       { "committerdate", FIELD_TIME },
-       { "tagger" },
-       { "taggername" },
-       { "taggeremail" },
-       { "taggerdate", FIELD_TIME },
-       { "creator" },
-       { "creatordate", FIELD_TIME },
-       { "subject", FIELD_STR, subject_atom_parser },
-       { "body", FIELD_STR, body_atom_parser },
-       { "trailers", FIELD_STR, trailers_atom_parser },
-       { "contents", FIELD_STR, contents_atom_parser },
-       { "upstream", FIELD_STR, remote_ref_atom_parser },
-       { "push", FIELD_STR, remote_ref_atom_parser },
-       { "symref", FIELD_STR, refname_atom_parser },
-       { "flag" },
-       { "HEAD", FIELD_STR, head_atom_parser },
-       { "color", FIELD_STR, color_atom_parser },
-       { "align", FIELD_STR, align_atom_parser },
-       { "end" },
-       { "if", FIELD_STR, if_atom_parser },
-       { "then" },
-       { "else" },
+       { "refname", SOURCE_NONE, FIELD_STR, refname_atom_parser },
+       { "objecttype", SOURCE_OTHER, FIELD_STR, objecttype_atom_parser },
+       { "objectsize", SOURCE_OTHER, FIELD_ULONG, objectsize_atom_parser },
+       { "objectname", SOURCE_OTHER, FIELD_STR, objectname_atom_parser },
+       { "tree", SOURCE_OBJ },
+       { "parent", SOURCE_OBJ },
+       { "numparent", SOURCE_OBJ, FIELD_ULONG },
+       { "object", SOURCE_OBJ },
+       { "type", SOURCE_OBJ },
+       { "tag", SOURCE_OBJ },
+       { "author", SOURCE_OBJ },
+       { "authorname", SOURCE_OBJ },
+       { "authoremail", SOURCE_OBJ },
+       { "authordate", SOURCE_OBJ, FIELD_TIME },
+       { "committer", SOURCE_OBJ },
+       { "committername", SOURCE_OBJ },
+       { "committeremail", SOURCE_OBJ },
+       { "committerdate", SOURCE_OBJ, FIELD_TIME },
+       { "tagger", SOURCE_OBJ },
+       { "taggername", SOURCE_OBJ },
+       { "taggeremail", SOURCE_OBJ },
+       { "taggerdate", SOURCE_OBJ, FIELD_TIME },
+       { "creator", SOURCE_OBJ },
+       { "creatordate", SOURCE_OBJ, FIELD_TIME },
+       { "subject", SOURCE_OBJ, FIELD_STR, subject_atom_parser },
+       { "body", SOURCE_OBJ, FIELD_STR, body_atom_parser },
+       { "trailers", SOURCE_OBJ, FIELD_STR, trailers_atom_parser },
+       { "contents", SOURCE_OBJ, FIELD_STR, contents_atom_parser },
+       { "upstream", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
+       { "push", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
+       { "symref", SOURCE_NONE, FIELD_STR, refname_atom_parser },
+       { "flag", SOURCE_NONE },
+       { "HEAD", SOURCE_NONE, FIELD_STR, head_atom_parser },
+       { "color", SOURCE_NONE, FIELD_STR, color_atom_parser },
+       { "align", SOURCE_NONE, FIELD_STR, align_atom_parser },
+       { "end", SOURCE_NONE },
+       { "if", SOURCE_NONE, FIELD_STR, if_atom_parser },
+       { "then", SOURCE_NONE },
+       { "else", SOURCE_NONE },
 };
 
 #define REF_FORMATTING_STATE_INIT  { 0, NULL }
@@ -500,6 +538,13 @@ static int parse_ref_filter_atom(const struct ref_format *format,
        REALLOC_ARRAY(used_atom, used_atom_cnt);
        used_atom[at].name = xmemdupz(atom, ep - atom);
        used_atom[at].type = valid_atom[i].cmp_type;
+       used_atom[at].source = valid_atom[i].source;
+       if (used_atom[at].source == SOURCE_OBJ) {
+               if (*atom == '*')
+                       oi_deref.info.contentp = &oi_deref.content;
+               else
+                       oi.info.contentp = &oi.content;
+       }
        if (arg) {
                arg = used_atom[at].name + (arg - atom) + 1;
                if (!*arg) {
@@ -795,25 +840,6 @@ int verify_ref_format(struct ref_format *format)
        return 0;
 }
 
-/*
- * Given an object name, read the object data and size, and return a
- * "struct object".  If the object data we are returning is also borrowed
- * by the "struct object" representation, set *eaten as well---it is a
- * signal from parse_object_buffer to us not to free the buffer.
- */
-static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten)
-{
-       enum object_type type;
-       void *buf = read_object_file(oid, &type, sz);
-
-       if (buf)
-               *obj = parse_object_buffer(the_repository, oid, type, *sz,
-                                          buf, eaten);
-       else
-               *obj = NULL;
-       return buf;
-}
-
 static int grab_objectname(const char *name, const struct object_id *oid,
                           struct atom_value *v, struct used_atom *atom)
 {
@@ -834,7 +860,7 @@ static int grab_objectname(const char *name, const struct object_id *oid,
 }
 
 /* See grab_values */
-static void grab_common_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
+static void grab_common_values(struct atom_value *val, int deref, struct expand_data *oi)
 {
        int i;
 
@@ -846,13 +872,13 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
                if (deref)
                        name++;
                if (!strcmp(name, "objecttype"))
-                       v->s = type_name(obj->type);
+                       v->s = type_name(oi->type);
                else if (!strcmp(name, "objectsize")) {
-                       v->value = sz;
-                       v->s = xstrfmt("%lu", sz);
+                       v->value = oi->size;
+                       v->s = xstrfmt("%lu", oi->size);
                }
                else if (deref)
-                       grab_objectname(name, &obj->oid, v, &used_atom[i]);
+                       grab_objectname(name, &oi->oid, v, &used_atom[i]);
        }
 }
 
@@ -1211,7 +1237,6 @@ static void fill_missing_values(struct atom_value *val)
  */
 static void grab_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
 {
-       grab_common_values(val, deref, obj, buf, sz);
        switch (obj->type) {
        case OBJ_TAG:
                grab_tag_values(val, deref, obj, buf, sz);
@@ -1435,24 +1460,36 @@ static const char *get_refname(struct used_atom *atom, struct ref_array_item *re
        return show_ref(&atom->u.refname, ref->refname);
 }
 
-static int get_object(struct ref_array_item *ref, const struct object_id *oid,
-                      int deref, struct object **obj, struct strbuf *err)
+static int get_object(struct ref_array_item *ref, int deref, struct object **obj,
+                     struct expand_data *oi, struct strbuf *err)
 {
-       int eaten;
-       int ret = 0;
-       unsigned long size;
-       void *buf = get_obj(oid, obj, &size, &eaten);
-       if (!buf)
-               ret = strbuf_addf_ret(err, -1, _("missing object %s for %s"),
-                                     oid_to_hex(oid), ref->refname);
-       else if (!*obj)
-               ret = strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"),
-                                     oid_to_hex(oid), ref->refname);
-       else
-               grab_values(ref->value, deref, *obj, buf, size);
+       /* parse_object_buffer() will set eaten to 0 if free() will be needed */
+       int eaten = 1;
+       if (oi->info.contentp) {
+               /* We need to know that to use parse_object_buffer properly */
+               oi->info.sizep = &oi->size;
+               oi->info.typep = &oi->type;
+       }
+       if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
+                                    OBJECT_INFO_LOOKUP_REPLACE))
+               return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
+                                      oid_to_hex(&oi->oid), ref->refname);
+
+       if (oi->info.contentp) {
+               *obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten);
+               if (!obj) {
+                       if (!eaten)
+                               free(oi->content);
+                       return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"),
+                                              oid_to_hex(&oi->oid), ref->refname);
+               }
+               grab_values(ref->value, deref, *obj, oi->content, oi->size);
+       }
+
+       grab_common_values(ref->value, deref, oi);
        if (!eaten)
-               free(buf);
-       return ret;
+               free(oi->content);
+       return 0;
 }
 
 /*
@@ -1462,7 +1499,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
 {
        struct object *obj;
        int i;
-       const struct object_id *tagged;
+       struct object_info empty = OBJECT_INFO_INIT;
 
        ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));
 
@@ -1496,6 +1533,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
                        refname = get_symref(atom, ref);
                else if (starts_with(name, "upstream")) {
                        const char *branch_name;
+                       v->s = "";
                        /* only local branches may have an upstream */
                        if (!skip_prefix(ref->refname, "refs/heads/",
                                         &branch_name))
@@ -1508,6 +1546,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
                        continue;
                } else if (atom->u.remote_ref.push) {
                        const char *branch_name;
+                       v->s = "";
                        if (!skip_prefix(ref->refname, "refs/heads/",
                                         &branch_name))
                                continue;
@@ -1548,22 +1587,26 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
                        continue;
                } else if (starts_with(name, "align")) {
                        v->handler = align_atom_handler;
+                       v->s = "";
                        continue;
                } else if (!strcmp(name, "end")) {
                        v->handler = end_atom_handler;
+                       v->s = "";
                        continue;
                } else if (starts_with(name, "if")) {
                        const char *s;
-
+                       v->s = "";
                        if (skip_prefix(name, "if:", &s))
                                v->s = xstrdup(s);
                        v->handler = if_atom_handler;
                        continue;
                } else if (!strcmp(name, "then")) {
                        v->handler = then_atom_handler;
+                       v->s = "";
                        continue;
                } else if (!strcmp(name, "else")) {
                        v->handler = else_atom_handler;
+                       v->s = "";
                        continue;
                } else
                        continue;
@@ -1576,13 +1619,20 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
 
        for (i = 0; i < used_atom_cnt; i++) {
                struct atom_value *v = &ref->value[i];
-               if (v->s == NULL)
-                       break;
+               if (v->s == NULL && used_atom[i].source == SOURCE_NONE)
+                       return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
+                                              oid_to_hex(&ref->objectname), ref->refname);
        }
-       if (used_atom_cnt <= i)
+
+       if (need_tagged)
+               oi.info.contentp = &oi.content;
+       if (!memcmp(&oi.info, &empty, sizeof(empty)) &&
+           !memcmp(&oi_deref.info, &empty, sizeof(empty)))
                return 0;
 
-       if (get_object(ref, &ref->objectname, 0, &obj, err))
+
+       oi.oid = ref->objectname;
+       if (get_object(ref, 0, &obj, &oi, err))
                return -1;
 
        /*
@@ -1596,7 +1646,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
         * If it is a tag object, see if we use a value that derefs
         * the object, and if we do grab the object it refers to.
         */
-       tagged = &((struct tag *)obj)->tagged->oid;
+       oi_deref.oid = ((struct tag *)obj)->tagged->oid;
 
        /*
         * NEEDSWORK: This derefs tag only once, which
@@ -1604,7 +1654,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
         * is not consistent with what deref_tag() does
         * which peels the onion to the core.
         */
-       return get_object(ref, tagged, 1, &obj, err);
+       return get_object(ref, 1, &obj, &oi_deref, err);
 }
 
 /*
index 7553c448fe5bf8b432d7fdb2ef5cba967bb985cd..cb3e73755d445b866ad51246dc8b1ea3ab6f1639 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "cache.h"
 
+struct commit;
 struct reflog_walk_info;
 
 extern void init_reflog_walk(struct reflog_walk_info **info);
diff --git a/refs.c b/refs.c
index 5b412c61efb94cfd4549c68ac561b596dbf0463e..de81c7be7ca8d3ca033b34a61f33b0bff069932f 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -490,16 +490,24 @@ static const char *ref_rev_parse_rules[] = {
        NULL
 };
 
+#define NUM_REV_PARSE_RULES (ARRAY_SIZE(ref_rev_parse_rules) - 1)
+
+/*
+ * Is it possible that the caller meant full_name with abbrev_name?
+ * If so return a non-zero value to signal "yes"; the magnitude of
+ * the returned value gives the precedence used for disambiguation.
+ *
+ * If abbrev_name cannot mean full_name, return 0.
+ */
 int refname_match(const char *abbrev_name, const char *full_name)
 {
        const char **p;
        const int abbrev_name_len = strlen(abbrev_name);
+       const int num_rules = NUM_REV_PARSE_RULES;
 
-       for (p = ref_rev_parse_rules; *p; p++) {
-               if (!strcmp(full_name, mkpath(*p, abbrev_name_len, abbrev_name))) {
-                       return 1;
-               }
-       }
+       for (p = ref_rev_parse_rules; *p; p++)
+               if (!strcmp(full_name, mkpath(*p, abbrev_name_len, abbrev_name)))
+                       return &ref_rev_parse_rules[num_rules] - p;
 
        return 0;
 }
diff --git a/refs.h b/refs.h
index cc2fb4c68c0e194dc51e3846192911c2c6949c6b..bd52c1bbae3a68fe8ca8f9e6cae7cc54bdbf9852 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -3,8 +3,10 @@
 
 struct object_id;
 struct ref_store;
+struct repository;
 struct strbuf;
 struct string_list;
+struct string_list_item;
 struct worktree;
 
 /*
index 99b0bedc6ddc670cad6e74083dc33dc0aa4b595a..fb28309e850518018667dc746c630acc1f497981 100644 (file)
@@ -714,7 +714,7 @@ static int post_rpc(struct rpc_state *rpc)
 
        } else if (use_gzip && 1024 < rpc->len) {
                /* The client backend isn't giving us compressed data so
-                * we can try to deflate it ourselves, this may save on.
+                * we can try to deflate it ourselves, this may save on
                 * the transfer time.
                 */
                git_zstream stream;
index 86e6098774d891a3b7045cf1dd9c11959faf13dc..7f6277a1451d147fc5af4ae2910e7c40dd330aec 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -1689,11 +1689,18 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
 static const struct ref *find_ref_by_name_abbrev(const struct ref *refs, const char *name)
 {
        const struct ref *ref;
+       const struct ref *best_match = NULL;
+       int best_score = 0;
+
        for (ref = refs; ref; ref = ref->next) {
-               if (refname_match(name, ref->name))
-                       return ref;
+               int score = refname_match(name, ref->name);
+
+               if (best_score < score) {
+                       best_match = ref;
+                       best_score = score;
+               }
        }
-       return NULL;
+       return best_match;
 }
 
 struct ref *get_remote_ref(const struct ref *remote_refs, const char *name)
index 976292152c020127e6c88d54e5448ef21e0eb4e8..88f8480c71a2e5ac494ef65532619a4322c1d32a 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -1,6 +1,7 @@
 #ifndef REMOTE_H
 #define REMOTE_H
 
+#include "cache.h"
 #include "parse-options.h"
 #include "hashmap.h"
 #include "refspec.h"
index b9413be50cfd0c9d17865220c3db5eb16024187e..9f16c42c1ed04af3bf2e7767c4fd6c05b28ccf9c 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef REPOSITORY_H
 #define REPOSITORY_H
 
+#include "path.h"
+
 struct config_set;
 struct git_hash_algo;
 struct index_state;
@@ -108,19 +110,16 @@ struct set_gitdir_args {
        const char *alternate_db;
 };
 
-extern void repo_set_gitdir(struct repository *repo,
-                           const char *root,
-                           const struct set_gitdir_args *extra_args);
-extern void repo_set_worktree(struct repository *repo, const char *path);
-extern void repo_set_hash_algo(struct repository *repo, int algo);
-extern void initialize_the_repository(void);
-extern int repo_init(struct repository *r,
-                    const char *gitdir,
-                    const char *worktree);
-extern int repo_submodule_init(struct repository *submodule,
-                              struct repository *superproject,
-                              const char *path);
-extern void repo_clear(struct repository *repo);
+void repo_set_gitdir(struct repository *repo, const char *root,
+                    const struct set_gitdir_args *extra_args);
+void repo_set_worktree(struct repository *repo, const char *path);
+void repo_set_hash_algo(struct repository *repo, int algo);
+void initialize_the_repository(void);
+int repo_init(struct repository *r, const char *gitdir, const char *worktree);
+int repo_submodule_init(struct repository *submodule,
+                       struct repository *superproject,
+                       const char *path);
+void repo_clear(struct repository *repo);
 
 /*
  * Populates the repository's index from its index_file, an index struct will
@@ -130,6 +129,6 @@ extern void repo_clear(struct repository *repo);
  * than zero if an error occured.  If the repository's index has already been
  * populated then the number of entries will simply be returned.
  */
-extern int repo_read_index(struct repository *repo);
+int repo_read_index(struct repository *repo);
 
 #endif /* REPOSITORY_H */
index 16c8aac6211ac74de77b1f2cad5eddb4d1abcc95..c7787aa07f80f00589e3c4f4e4e3cc825c43044e 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -1120,7 +1120,7 @@ int rerere_forget(struct pathspec *pathspec)
        find_conflict(&conflict);
        for (i = 0; i < conflict.nr; i++) {
                struct string_list_item *it = &conflict.items[i];
-               if (!match_pathspec(pathspec, it->string,
+               if (!match_pathspec(&the_index, pathspec, it->string,
                                    strlen(it->string), 0, NULL, 0))
                        continue;
                rerere_forget_one_path(it->string, &merge_rr);
index c2961feaaa8a8297d59fb13b120c1a57c8a2868a..cd948f28f494286c8e5750908eb7e35cf4293af3 100644 (file)
--- a/rerere.h
+++ b/rerere.h
@@ -22,19 +22,19 @@ struct rerere_id {
        int variant;
 };
 
-extern int setup_rerere(struct string_list *, int);
-extern int rerere(int);
+int setup_rerere(struct string_list *, int);
+int rerere(int);
 /*
  * Given the conflict ID and the name of a "file" used for replaying
  * the recorded resolution (e.g. "preimage", "postimage"), return the
  * path to that filesystem entity.  With "file" specified with NULL,
  * return the path to the directory that houses these files.
  */
-extern const char *rerere_path(const struct rerere_id *, const char *file);
-extern int rerere_forget(struct pathspec *);
-extern int rerere_remaining(struct string_list *);
-extern void rerere_clear(struct string_list *);
-extern void rerere_gc(struct string_list *);
+const char *rerere_path(const struct rerere_id *, const char *file);
+int rerere_forget(struct pathspec *);
+int rerere_remaining(struct string_list *);
+void rerere_clear(struct string_list *);
+void rerere_gc(struct string_list *);
 
 #define OPT_RERERE_AUTOUPDATE(v) OPT_UYN(0, "rerere-autoupdate", (v), \
        N_("update the index with reused conflict resolution if possible"))
index c30ae5cf49aab6a3a88060740ffc679ad940c2aa..236320f179cbf60a312f882ee57e1f843398e907 100644 (file)
@@ -188,7 +188,7 @@ void unmerge_index(struct index_state *istate, const struct pathspec *pathspec)
 
        for (i = 0; i < istate->cache_nr; i++) {
                const struct cache_entry *ce = istate->cache[i];
-               if (!ce_path_match(ce, pathspec, NULL))
+               if (!ce_path_match(istate, ce, pathspec, NULL))
                        continue;
                i = unmerge_index_entry_at(istate, i);
        }
index 87291904bd34e0e7f3a3601b6742f5345391824d..fbe348efac929f9202c4f3e81d962e84157b9082 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef RESOLVE_UNDO_H
 #define RESOLVE_UNDO_H
 
+#include "cache.h"
+
 struct resolve_undo_info {
        unsigned int mode[3];
        struct object_id oid[3];
index 0627494378dcf6d921af59cc83d02e6a6feb0030..de4dce600d00282655907e9014228791a352f813 100644 (file)
@@ -1517,7 +1517,7 @@ static void prepare_show_merge(struct rev_info *revs)
                const struct cache_entry *ce = active_cache[i];
                if (!ce_stage(ce))
                        continue;
-               if (ce_path_match(ce, &revs->prune_data, NULL)) {
+               if (ce_path_match(&the_index, ce, &revs->prune_data, NULL)) {
                        prune_num++;
                        REALLOC_ARRAY(prune, prune_num);
                        prune[prune_num-2] = ce->name;
index c599c34da91e57572b1c5b315c353d33399e8a09..007278cc119fded9f97832d87ffe5d6b95a5ce41 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef REVISION_H
 #define REVISION_H
 
+#include "commit.h"
 #include "parse-options.h"
 #include "grep.h"
 #include "notes.h"
@@ -230,7 +231,7 @@ struct rev_info {
        struct revision_sources *sources;
 };
 
-extern int ref_excluded(struct string_list *, const char *path);
+int ref_excluded(struct string_list *, const char *path);
 void clear_ref_exclusion(struct string_list **);
 void add_ref_exclusion(struct string_list **, const char *exclude);
 
@@ -252,39 +253,39 @@ struct setup_revision_opt {
        unsigned revarg_opt;
 };
 
-extern void init_revisions(struct rev_info *revs, const char *prefix);
-extern int setup_revisions(int argc, const char **argv, struct rev_info *revs,
-                          struct setup_revision_opt *);
-extern void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
-                              const struct option *options,
-                              const char * const usagestr[]);
+void init_revisions(struct rev_info *revs, const char *prefix);
+int setup_revisions(int argc, const char **argv, struct rev_info *revs,
+                   struct setup_revision_opt *);
+void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
+                       const struct option *options,
+                       const char * const usagestr[]);
 #define REVARG_CANNOT_BE_FILENAME 01
 #define REVARG_COMMITTISH 02
-extern int handle_revision_arg(const char *arg, struct rev_info *revs,
-                              int flags, unsigned revarg_opt);
+int handle_revision_arg(const char *arg, struct rev_info *revs,
+                       int flags, unsigned revarg_opt);
 
-extern void reset_revision_walk(void);
-extern int prepare_revision_walk(struct rev_info *revs);
-extern struct commit *get_revision(struct rev_info *revs);
-extern char *get_revision_mark(const struct rev_info *revs,
-                              const struct commit *commit);
-extern void put_revision_mark(const struct rev_info *revs,
-                             const struct commit *commit);
+void reset_revision_walk(void);
+int prepare_revision_walk(struct rev_info *revs);
+struct commit *get_revision(struct rev_info *revs);
+char *get_revision_mark(const struct rev_info *revs,
+                       const struct commit *commit);
+void put_revision_mark(const struct rev_info *revs,
+                      const struct commit *commit);
 
-extern void mark_parents_uninteresting(struct commit *commit);
-extern void mark_tree_uninteresting(struct tree *tree);
+void mark_parents_uninteresting(struct commit *commit);
+void mark_tree_uninteresting(struct tree *tree);
 
-extern void show_object_with_name(FILE *, struct object *, const char *);
+void show_object_with_name(FILE *, struct object *, const char *);
 
-extern void add_pending_object(struct rev_info *revs,
-                              struct object *obj, const char *name);
-extern void add_pending_oid(struct rev_info *revs,
-                           const char *name, const struct object_id *oid,
-                           unsigned int flags);
+void add_pending_object(struct rev_info *revs,
+                       struct object *obj, const char *name);
+void add_pending_oid(struct rev_info *revs,
+                    const char *name, const struct object_id *oid,
+                    unsigned int flags);
 
-extern void add_head_to_pending(struct rev_info *);
-extern void add_reflogs_to_pending(struct rev_info *, unsigned int flags);
-extern void add_index_objects_to_pending(struct rev_info *, unsigned int flags);
+void add_head_to_pending(struct rev_info *);
+void add_reflogs_to_pending(struct rev_info *, unsigned int flags);
+void add_index_objects_to_pending(struct rev_info *, unsigned int flags);
 
 enum commit_action {
        commit_ignore,
@@ -292,10 +293,10 @@ enum commit_action {
        commit_error
 };
 
-extern enum commit_action get_commit_action(struct rev_info *revs,
-                                           struct commit *commit);
-extern enum commit_action simplify_commit(struct rev_info *revs,
-                                         struct commit *commit);
+enum commit_action get_commit_action(struct rev_info *revs,
+                                    struct commit *commit);
+enum commit_action simplify_commit(struct rev_info *revs,
+                                  struct commit *commit);
 
 enum rewrite_result {
        rewrite_one_ok,
@@ -305,8 +306,9 @@ enum rewrite_result {
 
 typedef enum rewrite_result (*rewrite_parent_fn_t)(struct rev_info *revs, struct commit **pp);
 
-extern int rewrite_parents(struct rev_info *revs, struct commit *commit,
-       rewrite_parent_fn_t rewrite_parent);
+int rewrite_parents(struct rev_info *revs,
+                   struct commit *commit,
+                   rewrite_parent_fn_t rewrite_parent);
 
 /*
  * The log machinery saves the original parent list so that
@@ -317,6 +319,6 @@ extern int rewrite_parents(struct rev_info *revs, struct commit *commit,
  * get_saved_parents() will transparently return commit->parents if
  * history simplification is off.
  */
-extern struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit);
+struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit);
 
 #endif
index 6af71f7008127df0acb72cfaf3b679f7ef332a4e..e148fcd960994b1724f8d09c4ea4897b1cf069f0 100644 (file)
@@ -3,6 +3,10 @@
 
 #include "string-list.h"
 
+struct child_process;
+struct oid_array;
+struct ref;
+
 /* Possible values for push_cert field in send_pack_args. */
 #define SEND_PACK_PUSH_CERT_NEVER 0
 #define SEND_PACK_PUSH_CERT_IF_ASKED 1
index af204d0cf118070b037120eec3a02c6ac2a59ca8..65d371c7461c1f8098e0334532ae7804c30f66d6 100644 (file)
@@ -654,6 +654,7 @@ static int write_author_script(const char *message)
                        strbuf_addch(&buf, *(message++));
                else
                        strbuf_addf(&buf, "'\\\\%c'", *(message++));
+       strbuf_addch(&buf, '\'');
        res = write_message(buf.buf, buf.len, rebase_path_author_script(), 1);
        strbuf_release(&buf);
        return res;
@@ -708,14 +709,16 @@ static const char *read_author_ident(struct strbuf *buf)
        const char *keys[] = {
                "GIT_AUTHOR_NAME=", "GIT_AUTHOR_EMAIL=", "GIT_AUTHOR_DATE="
        };
-       char *in, *out, *eol;
-       int i = 0, len;
+       struct strbuf out = STRBUF_INIT;
+       char *in, *eol;
+       const char *val[3];
+       int i = 0;
 
        if (strbuf_read_file(buf, rebase_path_author_script(), 256) <= 0)
                return NULL;
 
        /* dequote values and construct ident line in-place */
-       for (in = out = buf->buf; i < 3 && in - buf->buf < buf->len; i++) {
+       for (in = buf->buf; i < 3 && in - buf->buf < buf->len; i++) {
                if (!skip_prefix(in, keys[i], (const char **)&in)) {
                        warning(_("could not parse '%s' (looking for '%s'"),
                                rebase_path_author_script(), keys[i]);
@@ -724,17 +727,12 @@ static const char *read_author_ident(struct strbuf *buf)
 
                eol = strchrnul(in, '\n');
                *eol = '\0';
-               sq_dequote(in);
-               len = strlen(in);
-
-               if (i > 0) /* separate values by spaces */
-                       *(out++) = ' ';
-               if (i == 1) /* email needs to be surrounded by <...> */
-                       *(out++) = '<';
-               memmove(out, in, len);
-               out += len;
-               if (i == 1) /* email needs to be surrounded by <...> */
-                       *(out++) = '>';
+               if (!sq_dequote(in)) {
+                       warning(_("bad quoting on %s value in '%s'"),
+                               keys[i], rebase_path_author_script());
+                       return NULL;
+               }
+               val[i] = in;
                in = eol + 1;
        }
 
@@ -744,7 +742,18 @@ static const char *read_author_ident(struct strbuf *buf)
                return NULL;
        }
 
-       buf->len = out - buf->buf;
+       /* validate date since fmt_ident() will die() on bad value */
+       if (parse_date(val[2], &out)){
+               warning(_("invalid date format '%s' in '%s'"),
+                       val[2], rebase_path_author_script());
+               strbuf_release(&out);
+               return NULL;
+       }
+
+       strbuf_reset(&out);
+       strbuf_addstr(&out, fmt_ident(val[0], val[1], val[2], 0));
+       strbuf_swap(buf, &out);
+       strbuf_release(&out);
        return buf->buf;
 }
 
@@ -1244,7 +1253,7 @@ static int try_to_commit(struct strbuf *msg, const char *author,
                commit_list_insert(current_head, &parents);
        }
 
-       if (write_cache_as_tree(&tree, 0, NULL)) {
+       if (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL)) {
                res = error(_("git write-tree failed to write a tree"));
                goto out;
        }
@@ -1543,13 +1552,13 @@ static int update_squash_messages(enum todo_command command,
                unlink(rebase_path_fixup_msg());
                strbuf_addf(&buf, "\n%c ", comment_line_char);
                strbuf_addf(&buf, _("This is the commit message #%d:"),
-                           ++opts->current_fixup_count);
+                           ++opts->current_fixup_count + 1);
                strbuf_addstr(&buf, "\n\n");
                strbuf_addstr(&buf, body);
        } else if (command == TODO_FIXUP) {
                strbuf_addf(&buf, "\n%c ", comment_line_char);
                strbuf_addf(&buf, _("The commit message #%d will be skipped:"),
-                           ++opts->current_fixup_count);
+                           ++opts->current_fixup_count + 1);
                strbuf_addstr(&buf, "\n\n");
                strbuf_add_commented_lines(&buf, body, strlen(body));
        } else
@@ -1630,7 +1639,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                 * that represents the "current" state for merge-recursive
                 * to work on.
                 */
-               if (write_cache_as_tree(&head, 0, NULL))
+               if (write_index_as_tree(&head, &the_index, get_index_file(), 0, NULL))
                        return error(_("your index file is unmerged."));
        } else {
                unborn = get_oid("HEAD", &head);
@@ -2601,8 +2610,13 @@ static int error_with_patch(struct commit *commit,
        const char *subject, int subject_len,
        struct replay_opts *opts, int exit_code, int to_amend)
 {
-       if (make_patch(commit, opts))
-               return -1;
+       if (commit) {
+               if (make_patch(commit, opts))
+                       return -1;
+       } else if (copy_file(rebase_path_message(),
+                            git_path_merge_msg(the_repository), 0666))
+               return error(_("unable to copy '%s' to '%s'"),
+                            git_path_merge_msg(the_repository), rebase_path_message());
 
        if (to_amend) {
                if (intend_to_amend())
@@ -2617,9 +2631,18 @@ static int error_with_patch(struct commit *commit,
                          "\n"
                          "  git rebase --continue\n"),
                        gpg_sign_opt_quoted(opts));
-       } else if (exit_code)
-               fprintf_ln(stderr, _("Could not apply %s... %.*s"),
-                       short_commit_name(commit), subject_len, subject);
+       } else if (exit_code) {
+               if (commit)
+                       fprintf_ln(stderr, _("Could not apply %s... %.*s"),
+                                  short_commit_name(commit), subject_len, subject);
+               else
+                       /*
+                        * We don't have the hash of the parent so
+                        * just print the line from the todo file.
+                        */
+                       fprintf_ln(stderr, _("Could not merge %.*s"),
+                                  subject_len, subject);
+       }
 
        return exit_code;
 }
@@ -4246,10 +4269,9 @@ int sequencer_add_exec_commands(const char *commands)
 {
        const char *todo_file = rebase_path_todo();
        struct todo_list todo_list = TODO_LIST_INIT;
-       struct todo_item *item;
        struct strbuf *buf = &todo_list.buf;
        size_t offset = 0, commands_len = strlen(commands);
-       int i, first;
+       int i, insert;
 
        if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
                return error(_("could not read '%s'."), todo_file);
@@ -4259,19 +4281,40 @@ int sequencer_add_exec_commands(const char *commands)
                return error(_("unusable todo list: '%s'"), todo_file);
        }
 
-       first = 1;
-       /* insert <commands> before every pick except the first one */
-       for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) {
-               if (item->command == TODO_PICK && !first) {
-                       strbuf_insert(buf, item->offset_in_buf + offset,
-                                     commands, commands_len);
+       /*
+        * Insert <commands> after every pick. Here, fixup/squash chains
+        * are considered part of the pick, so we insert the commands *after*
+        * those chains if there are any.
+        */
+       insert = -1;
+       for (i = 0; i < todo_list.nr; i++) {
+               enum todo_command command = todo_list.items[i].command;
+
+               if (insert >= 0) {
+                       /* skip fixup/squash chains */
+                       if (command == TODO_COMMENT)
+                               continue;
+                       else if (is_fixup(command)) {
+                               insert = i + 1;
+                               continue;
+                       }
+                       strbuf_insert(buf,
+                                     todo_list.items[insert].offset_in_buf +
+                                     offset, commands, commands_len);
                        offset += commands_len;
+                       insert = -1;
                }
-               first = 0;
+
+               if (command == TODO_PICK || command == TODO_MERGE)
+                       insert = i + 1;
        }
 
-       /* append final <commands> */
-       strbuf_add(buf, commands, commands_len);
+       /* insert or append final <commands> */
+       if (insert >= 0 && insert < todo_list.nr)
+               strbuf_insert(buf, todo_list.items[insert].offset_in_buf +
+                             offset, commands, commands_len);
+       else if (insert >= 0 || !offset)
+               strbuf_add(buf, commands, commands_len);
 
        i = write_message(buf->buf, buf->len, todo_file, 0);
        todo_list_release(&todo_list);
index c5787c6b566bbc89caad1a099f4281fecba01766..c751c9d6e4f78e7d9e2700dcc3fb3157961fb049 100644 (file)
@@ -1,6 +1,11 @@
 #ifndef SEQUENCER_H
 #define SEQUENCER_H
 
+#include "cache.h"
+#include "strbuf.h"
+
+struct commit;
+
 const char *git_path_commit_editmsg(void);
 const char *git_path_seq_dir(void);
 
index c6ca960eb2aa6b70841350d894bfda77856d980a..97b74238483e00c3f07bd5ab0879eb84bf5c8dfa 100644 (file)
@@ -1860,7 +1860,7 @@ static int index_stream_convert_blob(struct object_id *oid, int fd,
        struct strbuf sbuf = STRBUF_INIT;
 
        assert(path);
-       assert(would_convert_to_git_filter_fd(path));
+       assert(would_convert_to_git_filter_fd(&the_index, path));
 
        convert_to_git_filter_fd(&the_index, path, fd, &sbuf,
                                 get_conv_flags(flags));
@@ -1950,7 +1950,7 @@ int index_fd(struct object_id *oid, int fd, struct stat *st,
         * Call xsize_t() only when needed to avoid potentially unnecessary
         * die() for large files.
         */
-       if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(path))
+       if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(&the_index, path))
                ret = index_stream_convert_blob(oid, fd, path, flags);
        else if (!S_ISREG(st->st_mode))
                ret = index_pipe(oid, fd, type, path, flags);
@@ -2146,7 +2146,8 @@ static int loose_from_alt_odb(struct alternate_object_database *alt,
        return r;
 }
 
-int for_each_loose_object(each_loose_object_fn cb, void *data, unsigned flags)
+int for_each_loose_object(each_loose_object_fn cb, void *data,
+                         enum for_each_object_flags flags)
 {
        struct loose_alt_odb_data alt;
        int r;
index 19d97bf5af05312267c2e874ee6bcf584d9e9681..232357eb2ea0397388254a4b188333a227bf5b10 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 19d97bf5af05312267c2e874ee6bcf584d9e9681
+Subproject commit 232357eb2ea0397388254a4b188333a227bf5b10
index 25eded1399a8c3ae1532074ccdd388b24e660071..df0630bc6d607749f80955bc9ffaa5b0bbc506a5 100644 (file)
 #define SHA1DC_BIGENDIAN
 
 /* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist> */
+#elif (defined(_AIX))
+
+/*
+ * Defines Big Endian on a whitelist of OSs that are known to be Big
+ * Endian-only. See
+ * https://public-inbox.org/git/93056823-2740-d072-1ebd-46b440b33d7e@felt.demon.nl/
+ */
+#define SHA1DC_BIGENDIAN
+
+/* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist> or <os whitelist> */
 #elif defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR)
 /*
  * As a last resort before we do anything else we're not 100% sure
  * about below, we blacklist specific processors here. We could add
  * more, see e.g. https://wiki.debian.org/ArchitectureSpecificsMemo
  */
-#else /* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist>  or <processor blacklist> */
+#else /* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist> or <os whitelist> or <processor blacklist> */
 
 /* We do nothing more here for now */
 /*#error "Uncomment this to see if you fall through all the detection"*/
index 5d64cfe929684807fcfa004ec3edf10d720189c9..2fa61c42946262238ae2f1662ef3c2d1e981b274 100644 (file)
@@ -3,6 +3,8 @@
 
 #include "string-list.h"
 
+struct commit;
+
 struct shortlog {
        struct string_list list;
        int summary;
index 6e14547e9e0000e6bf80e9ad21da81795cebcab7..50cbf5f13ed84c5da081b4130bbd50b7b97e3121 100644 (file)
@@ -93,7 +93,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
        if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
                return -1;
 
-       if (is_gitmodules_unmerged(&the_index))
+       if (is_gitmodules_unmerged(the_repository->index))
                die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
 
        submodule = submodule_from_path(the_repository, &null_oid, oldpath);
@@ -127,7 +127,7 @@ int remove_path_from_gitmodules(const char *path)
        if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
                return -1;
 
-       if (is_gitmodules_unmerged(&the_index))
+       if (is_gitmodules_unmerged(the_repository->index))
                die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
 
        submodule = submodule_from_path(the_repository, &null_oid, path);
@@ -188,7 +188,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 
                if (ignore)
                        handle_ignore_submodules_arg(diffopt, ignore);
-               else if (is_gitmodules_unmerged(&the_index))
+               else if (is_gitmodules_unmerged(the_repository->index))
                        diffopt->flags.ignore_submodules = 1;
        }
 }
@@ -258,7 +258,7 @@ int is_submodule_active(struct repository *repo, const char *path)
                }
 
                parse_pathspec(&ps, 0, 0, NULL, args.argv);
-               ret = match_pathspec(&ps, path, strlen(path), 0, NULL, 1);
+               ret = match_pathspec(repo->index, &ps, path, strlen(path), 0, NULL, 1);
 
                argv_array_clear(&args);
                clear_pathspec(&ps);
index 4644683e6cb39916a942e501eacb8663d89c3f6b..7d476cefa7eea0c183bf515a6f48f1fa27ca8b25 100644 (file)
@@ -1,11 +1,17 @@
 #ifndef SUBMODULE_H
 #define SUBMODULE_H
 
-struct repository;
-struct diff_options;
 struct argv_array;
+struct cache_entry;
+struct diff_options;
+struct index_state;
+struct object_id;
 struct oid_array;
+struct pathspec;
 struct remote;
+struct repository;
+struct string_list;
+struct strbuf;
 
 enum {
        RECURSE_SUBMODULES_ONLY = -5,
@@ -33,62 +39,62 @@ struct submodule_update_strategy {
 };
 #define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
 
-extern int is_gitmodules_unmerged(const struct index_state *istate);
-extern int is_staging_gitmodules_ok(struct index_state *istate);
-extern int update_path_in_gitmodules(const char *oldpath, const char *newpath);
-extern int remove_path_from_gitmodules(const char *path);
-extern void stage_updated_gitmodules(struct index_state *istate);
-extern void set_diffopt_flags_from_submodule_config(struct diff_options *,
-               const char *path);
-extern int git_default_submodule_config(const char *var, const char *value, void *cb);
+int is_gitmodules_unmerged(const struct index_state *istate);
+int is_staging_gitmodules_ok(struct index_state *istate);
+int update_path_in_gitmodules(const char *oldpath, const char *newpath);
+int remove_path_from_gitmodules(const char *path);
+void stage_updated_gitmodules(struct index_state *istate);
+void set_diffopt_flags_from_submodule_config(struct diff_options *,
+                                            const char *path);
+int git_default_submodule_config(const char *var, const char *value, void *cb);
 
 struct option;
 int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
                                                     const char *arg, int unset);
-extern int is_submodule_active(struct repository *repo, const char *path);
+int is_submodule_active(struct repository *repo, const char *path);
 /*
  * Determine if a submodule has been populated at a given 'path' by checking if
  * the <path>/.git resolves to a valid git repository.
  * If return_error_code is NULL, die on error.
  * Otherwise the return error code is the same as of resolve_gitdir_gently.
  */
-extern int is_submodule_populated_gently(const char *path, int *return_error_code);
-extern void die_in_unpopulated_submodule(const struct index_state *istate,
-                                        const char *prefix);
-extern void die_path_inside_submodule(const struct index_state *istate,
-                                     const struct pathspec *ps);
-extern enum submodule_update_type parse_submodule_update_type(const char *value);
-extern int parse_submodule_update_strategy(const char *value,
-               struct submodule_update_strategy *dst);
-extern const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);
-extern void handle_ignore_submodules_arg(struct diff_options *, const char *);
-extern void show_submodule_summary(struct diff_options *o, const char *path,
-               struct object_id *one, struct object_id *two,
-               unsigned dirty_submodule);
-extern void show_submodule_inline_diff(struct diff_options *o, const char *path,
-               struct object_id *one, struct object_id *two,
-               unsigned dirty_submodule);
+int is_submodule_populated_gently(const char *path, int *return_error_code);
+void die_in_unpopulated_submodule(const struct index_state *istate,
+                                 const char *prefix);
+void die_path_inside_submodule(const struct index_state *istate,
+                              const struct pathspec *ps);
+enum submodule_update_type parse_submodule_update_type(const char *value);
+int parse_submodule_update_strategy(const char *value,
+                                   struct submodule_update_strategy *dst);
+const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);
+void handle_ignore_submodules_arg(struct diff_options *, const char *);
+void show_submodule_summary(struct diff_options *o, const char *path,
+                           struct object_id *one, struct object_id *two,
+                           unsigned dirty_submodule);
+void show_submodule_inline_diff(struct diff_options *o, const char *path,
+                               struct object_id *one, struct object_id *two,
+                               unsigned dirty_submodule);
 /* Check if we want to update any submodule.*/
-extern int should_update_submodules(void);
+int should_update_submodules(void);
 /*
  * Returns the submodule struct if the given ce entry is a submodule
  * and it should be updated. Returns NULL otherwise.
  */
-extern const struct submodule *submodule_from_ce(const struct cache_entry *ce);
-extern void check_for_new_submodule_commits(struct object_id *oid);
-extern int fetch_populated_submodules(struct repository *r,
-                                     const struct argv_array *options,
-                                     const char *prefix,
-                                     int command_line_option,
-                                     int default_option,
-                                     int quiet, int max_parallel_jobs);
-extern unsigned is_submodule_modified(const char *path, int ignore_untracked);
-extern int submodule_uses_gitfile(const char *path);
+const struct submodule *submodule_from_ce(const struct cache_entry *ce);
+void check_for_new_submodule_commits(struct object_id *oid);
+int fetch_populated_submodules(struct repository *r,
+                              const struct argv_array *options,
+                              const char *prefix,
+                              int command_line_option,
+                              int default_option,
+                              int quiet, int max_parallel_jobs);
+unsigned is_submodule_modified(const char *path, int ignore_untracked);
+int submodule_uses_gitfile(const char *path);
 
 #define SUBMODULE_REMOVAL_DIE_ON_ERROR (1<<0)
 #define SUBMODULE_REMOVAL_IGNORE_UNTRACKED (1<<1)
 #define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
-extern int bad_to_remove_submodule(const char *path, unsigned flags);
+int bad_to_remove_submodule(const char *path, unsigned flags);
 
 int add_submodule_odb(const char *path);
 
@@ -96,17 +102,17 @@ int add_submodule_odb(const char *path);
  * Checks if there are submodule changes in a..b. If a is the null OID,
  * checks b and all its ancestors instead.
  */
-extern int submodule_touches_in_range(struct object_id *a,
-                                     struct object_id *b);
-extern int find_unpushed_submodules(struct oid_array *commits,
-                                   const char *remotes_name,
-                                   struct string_list *needs_pushing);
+int submodule_touches_in_range(struct object_id *a,
+                              struct object_id *b);
+int find_unpushed_submodules(struct oid_array *commits,
+                            const char *remotes_name,
+                            struct string_list *needs_pushing);
 struct refspec;
-extern int push_unpushed_submodules(struct oid_array *commits,
-                                   const struct remote *remote,
-                                   const struct refspec *rs,
-                                   const struct string_list *push_options,
-                                   int dry_run);
+int push_unpushed_submodules(struct oid_array *commits,
+                            const struct remote *remote,
+                            const struct refspec *rs,
+                            const struct string_list *push_options,
+                            int dry_run);
 /*
  * Given a submodule path (as in the index), return the repository
  * path of that submodule in 'buf'. Return -1 on error or when the
@@ -116,10 +122,10 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule);
 
 #define SUBMODULE_MOVE_HEAD_DRY_RUN (1<<0)
 #define SUBMODULE_MOVE_HEAD_FORCE   (1<<1)
-extern int submodule_move_head(const char *path,
-                              const char *old,
-                              const char *new_head,
-                              unsigned flags);
+int submodule_move_head(const char *path,
+                       const char *old,
+                       const char *new_head,
+                       unsigned flags);
 
 void submodule_unset_core_worktree(const struct submodule *sub);
 
@@ -128,18 +134,18 @@ void submodule_unset_core_worktree(const struct submodule *sub);
  * a submodule by clearing any repo-specific environment variables, but
  * retaining any config in the environment.
  */
-extern void prepare_submodule_repo_env(struct argv_array *out);
+void prepare_submodule_repo_env(struct argv_array *out);
 
 #define ABSORB_GITDIR_RECURSE_SUBMODULES (1<<0)
-extern void absorb_git_dir_into_superproject(const char *prefix,
-                                            const char *path,
-                                            unsigned flags);
+void absorb_git_dir_into_superproject(const char *prefix,
+                                     const char *path,
+                                     unsigned flags);
 
 /*
  * Return the absolute path of the working tree of the superproject, which this
  * project is a submodule of. If this repository is not a submodule of
  * another repository, return NULL.
  */
-extern const char *get_superproject_working_tree(void);
+const char *get_superproject_working_tree(void);
 
 #endif
index 3bd959ae523cff7fe3a29f1abb92019b6d10515f..e7acedabe17f033d4205613c9af50152e5cec126 100644 (file)
@@ -1,6 +1,8 @@
 t[0-9][0-9][0-9][0-9]/* -whitespace
+/chainlint/*.expect eol=lf
 /diff-lib/* eol=lf
 /t0110/url-* binary
+/t3206/* eol=lf
 /t3900/*.txt eol=lf
 /t3901/*.txt eol=lf
 /t4034/*/* eol=lf
index 5f0882cb3810114dfdbbe244799af0c676bf7126..8544df38dfc0c557120a8a250529147edbc3d2a4 100644 (file)
 # "else", and "fi" in if-then-else likewise must not end with "&&", thus
 # receives similar treatment.
 #
+# Swallowing here-docs with arbitrary tags requires a bit of finesse. When a
+# line such as "cat <<EOF >out" is seen, the here-doc tag is moved to the front
+# of the line enclosed in angle brackets as a sentinel, giving "<EOF>cat >out".
+# As each subsequent line is read, it is appended to the target line and a
+# (whitespace-loose) back-reference match /^<(.*)>\n\1$/ is attempted to see if
+# the content inside "<...>" matches the entirety of the newly-read line. For
+# instance, if the next line read is "some data", when concatenated with the
+# target line, it becomes "<EOF>cat >out\nsome data", and a match is attempted
+# to see if "EOF" matches "some data". Since it doesn't, the next line is
+# attempted. When a line consisting of only "EOF" (and possible whitespace) is
+# encountered, it is appended to the target line giving "<EOF>cat >out\nEOF",
+# in which case the "EOF" inside "<...>" does match the text following the
+# newline, thus the closing here-doc tag has been found. The closing tag line
+# and the "<...>" prefix on the target line are then discarded, leaving just
+# the target line "cat >out".
+#
 # To facilitate regression testing (and manual debugging), a ">" annotation is
 # applied to the line containing ")" which closes a subshell, ">>" to a line
 # closing a nested subshell, and ">>>" to a line closing both at once. This
 
 # here-doc -- swallow it to avoid false hits within its body (but keep the
 # command to which it was attached)
-/<<[   ]*[-\\]*EOF[    ]*/ {
-       s/[     ]*<<[   ]*[-\\]*EOF//
-       h
+/<<[   ]*[-\\']*[A-Za-z0-9_]/ {
+       s/^\(.*\)<<[    ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
+       s/[     ]*<<//
        :hereslurp
        N
-       s/.*\n//
-       /^[     ]*EOF[  ]*$/!bhereslurp
-       x
+       /^<\([^>]*\)>.*\n[      ]*\1[   ]*$/!{
+               s/\n.*$//
+               bhereslurp
+       }
+       s/^<[^>]*>//
+       s/\n.*$//
 }
 
 # one-liner "(...) &&"
@@ -132,16 +151,15 @@ s/.*\n//
 :slurp
 # incomplete line "...\"
 /\\$/bincomplete
-# multi-line quoted string "...\n..."
-/^[^"]*"[^"]*$/bdqstring
-# multi-line quoted string '...\n...' (but not contraction in string "it's so")
-/^[^']*'[^']*$/{
+# multi-line quoted string "...\n..."?
+/"/bdqstring
+# multi-line quoted string '...\n...'? (but not contraction in string "it's")
+/'/{
        /"[^'"]*'[^'"]*"/!bsqstring
 }
+:folded
 # here-doc -- swallow it
-/<<[   ]*[-\\]*EOF/bheredoc
-/<<[   ]*[-\\]*EOT/bheredoc
-/<<[   ]*[-\\]*INPUT_END/bheredoc
+/<<[   ]*[-\\']*[A-Za-z0-9_]/bheredoc
 # comment or empty line -- discard since final non-comment, non-empty line
 # before closing ")", "done", "elsif", "else", or "fi" will need to be
 # re-visited to drop "suspect" marking since final line of those constructs
@@ -199,7 +217,7 @@ s/.*\n//
 # "$(...)" -- command substitution; not closing ")"
 /\$([^)][^)]*)[^)]*$/bcheckchain
 # multi-line "$(...\n...)" -- command substitution; treat as nested subshell
-/\$([  ]*$/bnest
+/\$([^)]*$/bnest
 # "=(...)" -- Bash array assignment; not closing ")"
 /=(/bcheckchain
 # closing "...) &&"
@@ -232,42 +250,48 @@ N
 s/\\\n//
 bslurp
 
-# found multi-line double-quoted string "...\n..." -- slurp until end of string
+# check for multi-line double-quoted string "...\n..." -- fold to one line
 :dqstring
-s/"//g
+# remove all quote pairs
+s/"\([^"]*\)"/@!\1@!/g
+# done if no dangling quote
+/"/!bdqdone
+# otherwise, slurp next line and try again
 N
 s/\n//
-/"/!bdqstring
-bcheckchain
+bdqstring
+:dqdone
+s/@!/"/g
+bfolded
 
-# found multi-line single-quoted string '...\n...' -- slurp until end of string
+# check for multi-line single-quoted string '...\n...' -- fold to one line
 :sqstring
-s/'//g
+# remove all quote pairs
+s/'\([^']*\)'/@!\1@!/g
+# done if no dangling quote
+/'/!bsqdone
+# otherwise, slurp next line and try again
 N
 s/\n//
-/'/!bsqstring
-bcheckchain
+bsqstring
+:sqdone
+s/@!/'/g
+bfolded
 
 # found here-doc -- swallow it to avoid false hits within its body (but keep
-# the command to which it was attached); take care to handle here-docs nested
-# within here-docs by only recognizing closing tag matching outer here-doc
-# opening tag
+# the command to which it was attached)
 :heredoc
-/EOF/{ s/[     ]*<<[   ]*[-\\]*EOF//; s/^/EOF/; }
-/EOT/{ s/[     ]*<<[   ]*[-\\]*EOT//; s/^/EOT/; }
-/INPUT_END/{ s/[       ]*<<[   ]*[-\\]*INPUT_END//; s/^/INPUT_END/; }
+s/^\(.*\)<<[   ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
+s/[    ]*<<//
 :hereslurpsub
 N
-/^EOF.*\n[     ]*EOF[  ]*$/bhereclose
-/^EOT.*\n[     ]*EOT[  ]*$/bhereclose
-/^INPUT_END.*\n[       ]*INPUT_END[    ]*$/bhereclose
-bhereslurpsub
-:hereclose
-s/^EOF//
-s/^EOT//
-s/^INPUT_END//
+/^<\([^>]*\)>.*\n[     ]*\1[   ]*$/!{
+       s/\n.*$//
+       bhereslurpsub
+}
+s/^<[^>]*>//
 s/\n.*$//
-bcheckchain
+bfolded
 
 # found "case ... in" -- pass through untouched
 :case
diff --git a/t/chainlint/here-doc-close-subshell.expect b/t/chainlint/here-doc-close-subshell.expect
new file mode 100644 (file)
index 0000000..f011e33
--- /dev/null
@@ -0,0 +1,2 @@
+(
+>      cat)
diff --git a/t/chainlint/here-doc-close-subshell.test b/t/chainlint/here-doc-close-subshell.test
new file mode 100644 (file)
index 0000000..b857ff5
--- /dev/null
@@ -0,0 +1,5 @@
+(
+# LINT: line contains here-doc and closes nested subshell
+       cat <<-\INPUT)
+       fizz
+       INPUT
diff --git a/t/chainlint/here-doc-multi-line-command-subst.expect b/t/chainlint/here-doc-multi-line-command-subst.expect
new file mode 100644 (file)
index 0000000..e5fb752
--- /dev/null
@@ -0,0 +1,5 @@
+(
+       x=$(bobble &&
+?!AMP?!>>              wiffle)
+       echo $x
+>)
diff --git a/t/chainlint/here-doc-multi-line-command-subst.test b/t/chainlint/here-doc-multi-line-command-subst.test
new file mode 100644 (file)
index 0000000..899bc5d
--- /dev/null
@@ -0,0 +1,9 @@
+(
+# LINT: line contains here-doc and opens multi-line $(...)
+       x=$(bobble <<-\END &&
+               fossil
+               vegetable
+               END
+               wiffle)
+       echo $x
+)
diff --git a/t/chainlint/here-doc-multi-line-string.expect b/t/chainlint/here-doc-multi-line-string.expect
new file mode 100644 (file)
index 0000000..32038a0
--- /dev/null
@@ -0,0 +1,4 @@
+(
+?!AMP?!        cat && echo "multi-line string"
+       bap
+>)
diff --git a/t/chainlint/here-doc-multi-line-string.test b/t/chainlint/here-doc-multi-line-string.test
new file mode 100644 (file)
index 0000000..a53edbc
--- /dev/null
@@ -0,0 +1,8 @@
+(
+# LINT: line contains here-doc and opens multi-line string
+       cat <<-\TXT && echo "multi-line
+       string"
+       fizzle
+       TXT
+       bap
+)
index 2328fe7753908b455ec8034b6724acc7f21e891d..aff65687168ec7e8e38cb4db79ada69b199da1ea 100644 (file)
@@ -1,3 +1,7 @@
 boodle wobba        gorgo snoot        wafta snurb &&
 
+cat >foo &&
+
+cat >bar &&
+
 horticulture
index bd36f6e1d35f6a423acc6630ef8b24004f322dcf..f2bb14b693a4bf2a8c371bef82cb6d3aea453528 100644 (file)
@@ -7,6 +7,20 @@ quoth the raven,
 nevermore...
 EOF
 
+# LINT: swallow here-doc with arbitrary tag
+cat <<-Arbitrary_Tag_42 >foo &&
+snoz
+boz
+woz
+Arbitrary_Tag_42
+
+# LINT: swallow 'quoted' here-doc
+cat <<'FUMP' >bar &&
+snoz
+boz
+woz
+FUMP
+
 # LINT: swallow here-doc (EOF is last line of test)
 horticulture <<\EOF
 gomez
index 19c023b1c871daa34df20735ca848a454bf647bc..59b6c8b850a16d087e5d322c8ee25dcbeb553fa5 100644 (file)
@@ -6,4 +6,13 @@
 >>     ) &&
        echo ok
 >) |
-sort
+sort &&
+(
+       bar &&
+       x=$(echo bar |
+               cat
+>>     ) &&
+       y=$(echo baz |
+>>             fip) &&
+       echo fail
+>)
index ca0620ab6b14b6bed39226565eb3d2d120f6f36e..300058341b6f303dce9d8e8105b6f16fa25f2ebf 100644 (file)
@@ -6,4 +6,13 @@
        ) &&
        echo ok
 ) |
-sort
+sort &&
+(
+       bar &&
+       x=$(echo bar |
+               cat
+       ) &&
+       y=$(echo baz |
+               fip) &&
+       echo fail
+)
index 8334c4cc8e08d3e8f296de90bfd6ab3dd1983629..170cb5999322ea7798bceafb2222274c4112adde 100644 (file)
@@ -1,9 +1,15 @@
 (
-       x=line 1                line 2          line 3" &&
-?!AMP?!        y=line 1                line2'
+       x="line 1               line 2          line 3" &&
+?!AMP?!        y='line 1               line2'
        foobar
 >) &&
 (
        echo "there's nothing to see here" &&
        exit
+>) &&
+(
+       echo "xyz" "abc         def             ghi" &&
+       echo 'xyz' 'abc         def             ghi' &&
+       echo 'xyz' "abc         def             ghi" &&
+       barfoo
 >)
index 14cb44d51cbdaebc7ab16fa39d921b391e96ec5c..287ab897054874972076ec6913bf8c8144196296 100644 (file)
 # LINT: starting multi-line single-quoted string
        echo "there's nothing to see here" &&
        exit
+) &&
+(
+       echo "xyz" "abc
+               def
+               ghi" &&
+       echo 'xyz' 'abc
+               def
+               ghi' &&
+       echo 'xyz' "abc
+               def
+               ghi" &&
+       barfoo
 )
index 559301e005e1f16e748f728b4da6fdf7c59496a1..0c9ef1cfc6959e1b4093200769b2401467e927ad 100644 (file)
@@ -1,3 +1,5 @@
+cat >foop &&
+
 (
        cat &&
 ?!AMP?!        cat
index 027e0bb3ff1af3e2acf76abe5bbcf21eff8a2389..f35404bf0f9313f33040d49b685d087d4f11b29b 100644 (file)
@@ -1,3 +1,13 @@
+# LINT: inner "EOF" not misintrepreted as closing ARBITRARY here-doc
+cat <<ARBITRARY >foop &&
+naddle
+fub <<EOF
+       nozzle
+       noodle
+EOF
+formp
+ARBITRARY
+
 (
 # LINT: inner "EOF" not misintrepreted as closing INPUT_END here-doc
        cat <<-\INPUT_END &&
index 19d5aff233f30c15645fe9c700e7f70506a84272..7663ea7fc4adba607279a3f36c57200e9e56a800 100644 (file)
@@ -2,4 +2,9 @@
        echo wobba             gorgo snoot             wafta snurb &&
 ?!AMP?!        cat >bip
        echo >bop
+>) &&
+(
+       cat >bup &&
+       cat >bup2 &&
+       meep
 >)
index 9c3564c247e0d15e96a13e1092f848d301a828a5..b6b5a9b33aac57156df37da5b3bc420baab78796 100644 (file)
        wednesday
        pugsly
        EOF
+) &&
+(
+# LINT: swallow here-doc with arbitrary tag
+       cat <<-\ARBITRARY >bup &&
+       glink
+       FIZZ
+       ARBITRARY
+       cat <<-'ARBITRARY2' >bup2 &&
+       glink
+       FIZZ
+       ARBITRARY2
+       meep
 )
diff --git a/t/chainlint/t7900-subtree.expect b/t/chainlint/t7900-subtree.expect
new file mode 100644 (file)
index 0000000..c991342
--- /dev/null
@@ -0,0 +1,10 @@
+(
+       chks="sub1sub2sub3sub4" &&
+       chks_sub=$(cat | sed 's,^,sub dir/,'
+>>) &&
+       chkms="main-sub1main-sub2main-sub3main-sub4" &&
+       chkms_sub=$(cat | sed 's,^,sub dir/,'
+>>) &&
+       subfiles=$(git ls-files) &&
+       check_equal "$subfiles" "$chkms$chks"
+>)
diff --git a/t/chainlint/t7900-subtree.test b/t/chainlint/t7900-subtree.test
new file mode 100644 (file)
index 0000000..277d835
--- /dev/null
@@ -0,0 +1,22 @@
+(
+       chks="sub1
+sub2
+sub3
+sub4" &&
+       chks_sub=$(cat <<TXT | sed 's,^,sub dir/,'
+$chks
+TXT
+) &&
+       chkms="main-sub1
+main-sub2
+main-sub3
+main-sub4" &&
+       chkms_sub=$(cat <<TXT | sed 's,^,sub dir/,'
+$chkms
+TXT
+) &&
+
+       subfiles=$(git ls-files) &&
+       check_equal "$subfiles" "$chkms
+$chks"
+)
index c03f155a357446338fa831e061dc58d8e5f4c657..1744cee5e996fe4e03149de3a0fb8065d2aa6d67 100755 (executable)
@@ -807,10 +807,9 @@ test_expect_success 'trailing whitespace is ignored' '
        cat >expect <<EOF &&
 whitespace/untracked
 EOF
-       : >err.expect &&
        git ls-files -o -X ignore whitespace >actual 2>err &&
        test_cmp expect actual &&
-       test_cmp err.expect err
+       test_must_be_empty err
 '
 
 test_expect_success !MINGW 'quoting allows trailing whitespace' '
@@ -820,10 +819,9 @@ test_expect_success !MINGW 'quoting allows trailing whitespace' '
        >whitespace/untracked &&
        echo "whitespace/trailing\\ \\ " >ignore &&
        echo whitespace/untracked >expect &&
-       : >err.expect &&
        git ls-files -o -X ignore whitespace >actual 2>err &&
        test_cmp expect actual &&
-       test_cmp err.expect err
+       test_must_be_empty err
 '
 
 test_expect_success !MINGW,!CYGWIN 'correct handling of backslashes' '
@@ -845,10 +843,9 @@ test_expect_success !MINGW,!CYGWIN 'correct handling of backslashes' '
        whitespace/trailing 6 \\a\\Z
        EOF
        echo whitespace/untracked >expect &&
-       >err.expect &&
        git ls-files -o -X ignore whitespace >actual 2>err &&
        test_cmp expect actual &&
-       test_cmp err.expect err
+       test_must_be_empty err
 '
 
 test_expect_success 'info/exclude trumps core.excludesfile' '
index bbf3e39e3d229fbda5b7e40e9caca3aba2e1f52b..b77948c618ecdd3ac654500ae2143863eccf4f9f 100755 (executable)
@@ -110,31 +110,30 @@ test_expect_success \
 
 test_expect_success \
     'only consecutive blank lines should be completely removed' '
-    > expect &&
 
     printf "\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "\n\n\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "$sss\n$sss\n$sss\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "$sss$sss\n$sss\n\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "\n$sss\n$sss$sss\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "$sss$sss$sss$sss\n\n\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "\n$sss$sss$sss$sss\n\n" | git stripspace >actual &&
-    test_cmp expect actual &&
+    test_must_be_empty actual &&
 
     printf "\n\n$sss$sss$sss$sss\n" | git stripspace >actual &&
-    test_cmp expect actual
+    test_must_be_empty actual
 '
 
 test_expect_success \
index 21a8b531322ca75695ca16c6e8ec7e0ba1056f10..cd74c0a4714680a935c7f52a09ffed2f0a5ebc11 100755 (executable)
@@ -330,6 +330,9 @@ test_submodule_relative_url "(null)" "../foo" "../submodule" "../submodule"
 test_submodule_relative_url "(null)" "./foo/bar" "../submodule" "foo/submodule"
 test_submodule_relative_url "(null)" "./foo" "../submodule" "submodule"
 test_submodule_relative_url "(null)" "//somewhere else/repo" "../subrepo" "//somewhere else/subrepo"
+test_submodule_relative_url "(null)" "//somewhere else/repo" "../../subrepo" "//subrepo"
+test_submodule_relative_url "(null)" "//somewhere else/repo" "../../../subrepo" "/subrepo"
+test_submodule_relative_url "(null)" "//somewhere else/repo" "../../../../subrepo" "subrepo"
 test_submodule_relative_url "(null)" "$(pwd)/subsuper_update_r" "../subsubsuper_update_r" "$(pwd)/subsubsuper_update_r"
 test_submodule_relative_url "(null)" "$(pwd)/super_update_r2" "../subsuper_update_r" "$(pwd)/subsuper_update_r"
 test_submodule_relative_url "(null)" "$(pwd)/." "../." "$(pwd)/."
@@ -344,10 +347,20 @@ test_submodule_relative_url "(null)" "file:///tmp/repo" "../subrepo" "file:///tm
 test_submodule_relative_url "(null)" "foo/bar" "../submodule" "foo/submodule"
 test_submodule_relative_url "(null)" "foo" "../submodule" "submodule"
 test_submodule_relative_url "(null)" "helper:://hostname/repo" "../subrepo" "helper:://hostname/subrepo"
+test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../subrepo" "helper:://subrepo"
+test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../subrepo" "helper::/subrepo"
+test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../subrepo" "helper::subrepo"
+test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../../subrepo" "helper:subrepo"
+test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../../../subrepo" ".:subrepo"
 test_submodule_relative_url "(null)" "ssh://hostname/repo" "../subrepo" "ssh://hostname/subrepo"
+test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../subrepo" "ssh://subrepo"
+test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../subrepo" "ssh:/subrepo"
+test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../../subrepo" "ssh:subrepo"
+test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../../../subrepo" ".:subrepo"
 test_submodule_relative_url "(null)" "ssh://hostname:22/repo" "../subrepo" "ssh://hostname:22/subrepo"
 test_submodule_relative_url "(null)" "user@host:path/to/repo" "../subrepo" "user@host:path/to/subrepo"
 test_submodule_relative_url "(null)" "user@host:repo" "../subrepo" "user@host:subrepo"
+test_submodule_relative_url "(null)" "user@host:repo" "../../subrepo" ".:subrepo"
 
 test_expect_success 'match .gitmodules' '
        test-tool path-utils is_dotgitmodules \
index 03bd31e9f22a1964551cb07d76c45ce90a3cd17e..82eaaea0f4954d22861a4733b80aebcc361aca9a 100755 (executable)
@@ -294,8 +294,7 @@ test_expect_success 'helpers can abort the process' '
                -c credential.helper="!f() { echo quit=1; }; f" \
                -c credential.helper="verbatim foo bar" \
                credential fill >stdout &&
-       >expect &&
-       test_cmp expect stdout
+       test_must_be_empty stdout
 '
 
 test_expect_success 'empty helper spec resets helper list' '
index 4984ca583d03a7cc0a6fb9323799e776eee4565b..128130066499feb5bdad705b6fb0ef03bf446fe9 100755 (executable)
@@ -271,28 +271,91 @@ test_expect_success 'rev-list accepts missing and promised objects on command li
        git -C repo rev-list --exclude-promisor-objects --objects "$COMMIT" "$TREE" "$BLOB"
 '
 
-test_expect_success 'gc does not repack promisor objects' '
+test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
        rm -rf repo &&
        test_create_repo repo &&
-       test_commit -C repo my_commit &&
+       test_commit -C repo one &&
+       test_commit -C repo two &&
 
-       TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
-       HASH=$(printf "$TREE_HASH\n" | pack_as_from_promisor) &&
+       TREE_ONE=$(git -C repo rev-parse one^{tree}) &&
+       printf "$TREE_ONE\n" | pack_as_from_promisor &&
+       TREE_TWO=$(git -C repo rev-parse two^{tree}) &&
+       printf "$TREE_TWO\n" | pack_as_from_promisor &&
 
        git -C repo config core.repositoryformatversion 1 &&
        git -C repo config extensions.partialclone "arbitrary string" &&
        git -C repo gc &&
 
-       # Ensure that the promisor packfile still exists, and remove it
-       test -e repo/.git/objects/pack/pack-$HASH.pack &&
-       rm repo/.git/objects/pack/pack-$HASH.* &&
-
-       # Ensure that the single other pack contains the commit, but not the tree
+       # Ensure that exactly one promisor packfile exists, and that it
+       # contains the trees but not the commits
+       ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
+       test_line_count = 1 promisorlist &&
+       PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) &&
+       git verify-pack $PROMISOR_PACKFILE -v >out &&
+       grep "$TREE_ONE" out &&
+       grep "$TREE_TWO" out &&
+       ! grep "$(git -C repo rev-parse one)" out &&
+       ! grep "$(git -C repo rev-parse two)" out &&
+
+       # Remove the promisor packfile and associated files
+       rm $(sed "s/.promisor//" <promisorlist).* &&
+
+       # Ensure that the single other pack contains the commits, but not the
+       # trees
        ls repo/.git/objects/pack/pack-*.pack >packlist &&
        test_line_count = 1 packlist &&
        git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
-       grep "$(git -C repo rev-parse HEAD)" out &&
-       ! grep "$TREE_HASH" out
+       grep "$(git -C repo rev-parse one)" out &&
+       grep "$(git -C repo rev-parse two)" out &&
+       ! grep "$TREE_ONE" out &&
+       ! grep "$TREE_TWO" out
+'
+
+test_expect_success 'gc does not repack promisor objects if there are none' '
+       rm -rf repo &&
+       test_create_repo repo &&
+       test_commit -C repo one &&
+
+       git -C repo config core.repositoryformatversion 1 &&
+       git -C repo config extensions.partialclone "arbitrary string" &&
+       git -C repo gc &&
+
+       # Ensure that only one pack exists
+       ls repo/.git/objects/pack/pack-*.pack >packlist &&
+       test_line_count = 1 packlist
+'
+
+repack_and_check () {
+       rm -rf repo2 &&
+       cp -r repo repo2 &&
+       git -C repo2 repack $1 -d &&
+       git -C repo2 fsck &&
+
+       git -C repo2 cat-file -e $2 &&
+       git -C repo2 cat-file -e $3
+}
+
+test_expect_success 'repack -d does not irreversibly delete promisor objects' '
+       rm -rf repo &&
+       test_create_repo repo &&
+       git -C repo config core.repositoryformatversion 1 &&
+       git -C repo config extensions.partialclone "arbitrary string" &&
+
+       git -C repo commit --allow-empty -m one &&
+       git -C repo commit --allow-empty -m two &&
+       git -C repo commit --allow-empty -m three &&
+       git -C repo commit --allow-empty -m four &&
+       ONE=$(git -C repo rev-parse HEAD^^^) &&
+       TWO=$(git -C repo rev-parse HEAD^^) &&
+       THREE=$(git -C repo rev-parse HEAD^) &&
+
+       printf "$TWO\n" | pack_as_from_promisor &&
+       printf "$THREE\n" | pack_as_from_promisor &&
+       delete_object repo "$ONE" &&
+
+       repack_and_check -a "$TWO" "$THREE" &&
+       repack_and_check -A "$TWO" "$THREE" &&
+       repack_and_check -l "$TWO" "$THREE"
 '
 
 test_expect_success 'gc stops traversal when a missing but promised object is reached' '
index 13dd510b2ed8c4ce3b48666557bf68ad2aa03953..7f19d591f250bd61f7d25a5e5e0fae2ca1d8f118 100755 (executable)
@@ -550,8 +550,8 @@ test_expect_success 'git cat-file --batch --follow-symlink returns correct sha a
 test_expect_success 'cat-file --batch-all-objects shows all objects' '
        # make new repos so we know the full set of objects; we will
        # also make sure that there are some packed and some loose
-       # objects, some referenced and some not, and that there are
-       # some available only via alternates.
+       # objects, some referenced and some not, some duplicates, and that
+       # there are some available only via alternates.
        git init all-one &&
        (
                cd all-one &&
@@ -567,10 +567,23 @@ test_expect_success 'cat-file --batch-all-objects shows all objects' '
                cd all-two &&
                echo local-unref | git hash-object -w --stdin
        ) >>expect.unsorted &&
+       git -C all-two rev-parse HEAD:file |
+               git -C all-two pack-objects .git/objects/pack/pack &&
        sort <expect.unsorted >expect &&
        git -C all-two cat-file --batch-all-objects \
                                --batch-check="%(objectname)" >actual &&
        test_cmp expect actual
 '
 
+# The only user-visible difference is that the objects are no longer sorted,
+# and the resulting sort order is undefined. So we can only check that it
+# produces the same objects as the ordered case, but that at least exercises
+# the code.
+test_expect_success 'cat-file --unordered works' '
+       git -C all-two cat-file --batch-all-objects --unordered \
+                               --batch-check="%(objectname)" >actual.unsorted &&
+       sort <actual.unsorted >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 0c6f48f3024c81de765a8acb489e2d5e3ec42a56..ba71b159ba8ce1aae9c13d470bdceb7963da58da 100755 (executable)
@@ -227,12 +227,11 @@ test_expect_success 'index removal and worktree narrowing at the same time' '
 '
 
 test_expect_success 'read-tree --reset removes outside worktree' '
-       >empty &&
        echo init.t >.git/info/sparse-checkout &&
        git checkout -f top &&
        git reset --hard removed &&
        git ls-files sub/added >result &&
-       test_cmp empty result
+       test_must_be_empty result
 '
 
 test_expect_success 'print errors when failed to update worktree' '
diff --git a/t/t1015-read-index-unmerged.sh b/t/t1015-read-index-unmerged.sh
new file mode 100755 (executable)
index 0000000..55d22da
--- /dev/null
@@ -0,0 +1,123 @@
+#!/bin/sh
+
+test_description='Test various callers of read_index_unmerged'
+. ./test-lib.sh
+
+test_expect_success 'setup modify/delete + directory/file conflict' '
+       test_create_repo df_plus_modify_delete &&
+       (
+               cd df_plus_modify_delete &&
+
+               test_write_lines a b c d e f g h >letters &&
+               git add letters &&
+               git commit -m initial &&
+
+               git checkout -b modify &&
+               # Throw in letters.txt for sorting order fun
+               # ("letters.txt" sorts between "letters" and "letters/file")
+               echo i >>letters &&
+               echo "version 2" >letters.txt &&
+               git add letters letters.txt &&
+               git commit -m modified &&
+
+               git checkout -b delete HEAD^ &&
+               git rm letters &&
+               mkdir letters &&
+               >letters/file &&
+               echo "version 1" >letters.txt &&
+               git add letters letters.txt &&
+               git commit -m deleted
+       )
+'
+
+test_expect_success 'read-tree --reset cleans unmerged entries' '
+       test_when_finished "git -C df_plus_modify_delete clean -f" &&
+       test_when_finished "git -C df_plus_modify_delete reset --hard" &&
+       (
+               cd df_plus_modify_delete &&
+
+               git checkout delete^0 &&
+               test_must_fail git merge modify &&
+
+               git read-tree --reset HEAD &&
+               git ls-files -u >conflicts &&
+               test_must_be_empty conflicts
+       )
+'
+
+test_expect_success 'One reset --hard cleans unmerged entries' '
+       test_when_finished "git -C df_plus_modify_delete clean -f" &&
+       test_when_finished "git -C df_plus_modify_delete reset --hard" &&
+       (
+               cd df_plus_modify_delete &&
+
+               git checkout delete^0 &&
+               test_must_fail git merge modify &&
+
+               git reset --hard &&
+               test_path_is_missing .git/MERGE_HEAD &&
+               git ls-files -u >conflicts &&
+               test_must_be_empty conflicts
+       )
+'
+
+test_expect_success 'setup directory/file conflict + simple edit/edit' '
+       test_create_repo df_plus_edit_edit &&
+       (
+               cd df_plus_edit_edit &&
+
+               test_seq 1 10 >numbers &&
+               git add numbers &&
+               git commit -m initial &&
+
+               git checkout -b d-edit &&
+               mkdir foo &&
+               echo content >foo/bar &&
+               git add foo &&
+               echo 11 >>numbers &&
+               git add numbers &&
+               git commit -m "directory and edit" &&
+
+               git checkout -b f-edit d-edit^1 &&
+               echo content >foo &&
+               git add foo &&
+               echo eleven >>numbers &&
+               git add numbers &&
+               git commit -m "file and edit"
+       )
+'
+
+test_expect_success 'git merge --abort succeeds despite D/F conflict' '
+       test_when_finished "git -C df_plus_edit_edit clean -f" &&
+       test_when_finished "git -C df_plus_edit_edit reset --hard" &&
+       (
+               cd df_plus_edit_edit &&
+
+               git checkout f-edit^0 &&
+               test_must_fail git merge d-edit^0 &&
+
+               git merge --abort &&
+               test_path_is_missing .git/MERGE_HEAD &&
+               git ls-files -u >conflicts &&
+               test_must_be_empty conflicts
+       )
+'
+
+test_expect_success 'git am --skip succeeds despite D/F conflict' '
+       test_when_finished "git -C df_plus_edit_edit clean -f" &&
+       test_when_finished "git -C df_plus_edit_edit reset --hard" &&
+       (
+               cd df_plus_edit_edit &&
+
+               git checkout f-edit^0 &&
+               git format-patch -1 d-edit &&
+               test_must_fail git am -3 0001*.patch &&
+
+               git am --skip &&
+               test_path_is_missing .git/rebase-apply &&
+               git ls-files -u >conflicts &&
+               test_must_be_empty conflicts
+       )
+'
+
+test_done
index 24706ba4125c44f7c32539dc7bfcbb24f3371462..4976e2fcd3fc8be5b39ff44f662dfc71c6cabdc9 100755 (executable)
@@ -1218,6 +1218,93 @@ test_expect_success 'last one wins: three level vars' '
        test_cmp expect actual
 '
 
+test_expect_success 'old-fashioned settings are case insensitive' '
+       test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
+
+       cat >testConfig_actual <<-EOF &&
+               [V.A]
+               r = value1
+       EOF
+       q_to_tab >testConfig_expect <<-EOF &&
+               [V.A]
+               Qr = value2
+       EOF
+       git config -f testConfig_actual "v.a.r" value2 &&
+       test_cmp testConfig_expect testConfig_actual &&
+
+       cat >testConfig_actual <<-EOF &&
+               [V.A]
+               r = value1
+       EOF
+       q_to_tab >testConfig_expect <<-EOF &&
+               [V.A]
+               QR = value2
+       EOF
+       git config -f testConfig_actual "V.a.R" value2 &&
+       test_cmp testConfig_expect testConfig_actual &&
+
+       cat >testConfig_actual <<-EOF &&
+               [V.A]
+               r = value1
+       EOF
+       q_to_tab >testConfig_expect <<-EOF &&
+               [V.A]
+               r = value1
+               Qr = value2
+       EOF
+       git config -f testConfig_actual "V.A.r" value2 &&
+       test_cmp testConfig_expect testConfig_actual &&
+
+       cat >testConfig_actual <<-EOF &&
+               [V.A]
+               r = value1
+       EOF
+       q_to_tab >testConfig_expect <<-EOF &&
+               [V.A]
+               r = value1
+               Qr = value2
+       EOF
+       git config -f testConfig_actual "v.A.r" value2 &&
+       test_cmp testConfig_expect testConfig_actual
+'
+
+test_expect_success 'setting different case sensitive subsections ' '
+       test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
+
+       cat >testConfig_actual <<-EOF &&
+               [V "A"]
+               R = v1
+               [K "E"]
+               Y = v1
+               [a "b"]
+               c = v1
+               [d "e"]
+               f = v1
+       EOF
+       q_to_tab >testConfig_expect <<-EOF &&
+               [V "A"]
+               Qr = v2
+               [K "E"]
+               Qy = v2
+               [a "b"]
+               Qc = v2
+               [d "e"]
+               f = v1
+               [d "E"]
+               Qf = v2
+       EOF
+       # exact match
+       git config -f testConfig_actual a.b.c v2 &&
+       # match section and subsection, key is cased differently.
+       git config -f testConfig_actual K.E.y v2 &&
+       # section and key are matched case insensitive, but subsection needs
+       # to match; When writing out new values only the key is adjusted
+       git config -f testConfig_actual v.A.r v2 &&
+       # subsection is not matched:
+       git config -f testConfig_actual d.E.f v2 &&
+       test_cmp testConfig_expect testConfig_actual
+'
+
 for VAR in a .a a. a.0b a."b c". a."b c".0d
 do
        test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
index 8b14ab187c5e01a27bbc4964e3ac9d89e2eb8934..21e139a313bed1d91121044f64a5e7ce5078002c 100755 (executable)
@@ -114,11 +114,10 @@ test_expect_success 'Exclusion in a non-XDG global ignore file' '
 '
 
 test_expect_success 'Checking XDG ignore file when HOME is unset' '
-       >expected &&
        (sane_unset HOME &&
         git config --unset core.excludesfile &&
         git ls-files --exclude-standard --ignored >actual) &&
-       test_cmp expected actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'Checking attributes in the XDG attributes file' '
@@ -132,10 +131,9 @@ test_expect_success 'Checking attributes in the XDG attributes file' '
 '
 
 test_expect_success 'Checking XDG attributes when HOME is unset' '
-       >expected &&
        (sane_unset HOME &&
         git check-attr -a f >actual) &&
-       test_cmp expected actual
+       test_must_be_empty actual
 '
 
 test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/attributes' '
index 30354fd26c0cf6b6e2a6c01bc2bcbef48168e562..5d955c3bff2ce9c276acd363f7c906565333da79 100755 (executable)
@@ -26,26 +26,22 @@ test_expect_success 'show-ref' '
        git show-ref refs/tags/A >actual &&
        test_cmp expect actual &&
 
-       >expect &&
-
        test_must_fail git show-ref D >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show-ref -q' '
-       >expect &&
-
        git show-ref -q A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        git show-ref -q tags/A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        git show-ref -q refs/tags/A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref -q D >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show-ref --verify' '
@@ -54,32 +50,28 @@ test_expect_success 'show-ref --verify' '
        git show-ref --verify refs/tags/A >actual &&
        test_cmp expect actual &&
 
-       >expect &&
-
        test_must_fail git show-ref --verify A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify tags/A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify D >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show-ref --verify -q' '
-       >expect &&
-
        git show-ref --verify -q refs/tags/A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify -q A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify -q tags/A >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify -q D >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show-ref -d' '
@@ -113,19 +105,17 @@ test_expect_success 'show-ref -d' '
        git show-ref -d --verify refs/heads/master >actual &&
        test_cmp expect actual &&
 
-       >expect &&
-
        test_must_fail git show-ref -d --verify master >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref -d --verify heads/master >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify -d A C >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        test_must_fail git show-ref --verify -d tags/A tags/C >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
@@ -178,10 +168,8 @@ test_expect_success 'show-ref --verify HEAD' '
        git show-ref --verify HEAD >actual &&
        test_cmp expect actual &&
 
-       >expect &&
-
        git show-ref --verify -q HEAD >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show-ref --verify with dangling ref' '
index 349f6e10af9ea64a0e874b863f784feab4d12386..fa3e4996418d6d78afa31e9be19b6c77b22cd819 100755 (executable)
@@ -138,8 +138,7 @@ test_expect_success 'branch -d other@{u}' '
        git checkout -t -b other master &&
        git branch -d @{u} &&
        git for-each-ref refs/heads/master >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'checkout other@{u}' '
index 26dc3f1fc0c25df1b359b5d56aece9f171344f5a..f79dfbbdd693b3fd7443d3c839e86e627663eb4b 100755 (executable)
@@ -24,9 +24,8 @@ test_branch_upstream () {
 }
 
 status_uno_is_clean () {
-       >status.expect &&
        git status -uno --porcelain >status.actual &&
-       test_cmp status.expect status.actual
+       test_must_be_empty status.actual
 }
 
 test_expect_success 'setup' '
index be6e093142cdbeb18fa0ff155f3adf1e7a566ca2..166942c1bd2943b778b7df66e21d2e84861ef958 100755 (executable)
@@ -412,9 +412,8 @@ test_expect_success '"add" <path> <branch> dwims with checkout.defaultRemote' '
                git fetch repo_upstream2 &&
                test_must_fail git worktree add ../foo foo &&
                git -c checkout.defaultRemote=repo_upstream worktree add ../foo foo &&
-               >status.expect &&
                git status -uno --porcelain >status.actual &&
-               test_cmp status.expect status.actual
+               test_must_be_empty status.actual
        ) &&
        (
                cd foo &&
index 17744e8c57b8adbe976e9abe5a8c8350429e4c19..9ee659098c45fbc18dfb5ccc2292f978320c1ebb 100755 (executable)
@@ -48,8 +48,7 @@ test_expect_success 'Just "git add" is a no-op' '
        >will-not-be-added &&
        git add &&
        git diff-index --name-status --cached HEAD >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_done
index 3fc484e8c3f8d910f02e409baf7bf1d5682b4f2f..3b47647ed56aa88b35227ef295e6a3432e5ab8f1 100755 (executable)
@@ -210,8 +210,7 @@ test_expect_success 'subdirectory ignore (toplevel)' '
                cd top &&
                git ls-files -o --exclude-standard
        ) >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'subdirectory ignore (l1/l2)' '
@@ -219,8 +218,7 @@ test_expect_success 'subdirectory ignore (l1/l2)' '
                cd top/l1/l2 &&
                git ls-files -o --exclude-standard
        ) >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'subdirectory ignore (l1)' '
@@ -228,8 +226,7 @@ test_expect_success 'subdirectory ignore (l1)' '
                cd top/l1 &&
                git ls-files -o --exclude-standard
        ) >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show/hide empty ignored directory (setup)' '
@@ -251,8 +248,7 @@ test_expect_success 'hide empty ignored directory with --no-empty-directory' '
                cd top &&
                git ls-files -o -i --exclude l1 --directory --no-empty-directory
        ) >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'show/hide empty ignored sub-directory (setup)' '
@@ -277,8 +273,7 @@ test_expect_success 'hide empty ignored sub-directory with --no-empty-directory'
                cd top &&
                git ls-files -o -i --exclude l1 --directory --no-empty-directory
        ) >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'pattern matches prefix completely' '
index e59b0a32d67ec86074059eee7a64c4b7bae6c145..3824756a02ec31c228e2eeda92fc13a33b1e4b75 100755 (executable)
@@ -88,7 +88,7 @@ test_expect_success 'setup repo with criss-cross history' '
        git branch G
 '
 
-test_expect_success 'recursive merge between F and G, causes segfault' '
+test_expect_success 'recursive merge between F and G does not cause segfault' '
        git merge F
 '
 
index dce102130fb77ddda7cdc9aa9211507d9c2f2e09..46aca0af102e863f8c46f160d3f2022aee5ba29e 100755 (executable)
@@ -101,8 +101,7 @@ match_with_ls_files() {
 
        match_stdout_stderr_cmp="
                tr -d '\0' <actual.raw >actual &&
-               >expect.err &&
-               test_cmp expect.err actual.err &&
+               test_must_be_empty actual.err &&
                test_cmp expect actual"
 
        if test "$match_expect" = 'E'
index 0ef1b6fdcc420d6fac2cbe0abd5f1ec6ebec90c6..0ea4fc46949daf8d9522ff9ae52d8583ca5e9754 100755 (executable)
@@ -48,16 +48,14 @@ test_expect_success 'branch --contains master' '
 test_expect_success 'branch --no-contains=master' '
 
        git branch --no-contains=master >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
 test_expect_success 'branch --no-contains master' '
 
        git branch --no-contains master >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
@@ -94,8 +92,7 @@ test_expect_success 'branch --contains with pattern implies --list' '
 test_expect_success 'branch --no-contains with pattern implies --list' '
 
        git branch --no-contains=master master >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
@@ -123,8 +120,7 @@ test_expect_success 'branch --merged with pattern implies --list' '
 test_expect_success 'side: branch --no-merged' '
 
        git branch --no-merged >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
@@ -152,8 +148,7 @@ test_expect_success 'master: branch --no-merged' '
 test_expect_success 'branch --no-merged with pattern implies --list' '
 
        git branch --no-merged=master master >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 
 '
 
diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh
new file mode 100755 (executable)
index 0000000..2237c7f
--- /dev/null
@@ -0,0 +1,145 @@
+#!/bin/sh
+
+test_description='range-diff tests'
+
+. ./test-lib.sh
+
+# Note that because of the range-diff's heuristics, test_commit does more
+# harm than good.  We need some real history.
+
+test_expect_success 'setup' '
+       git fast-import < "$TEST_DIRECTORY"/t3206/history.export
+'
+
+test_expect_success 'simple A..B A..C (unmodified)' '
+       git range-diff --no-color master..topic master..unmodified \
+               >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  35b9b25 s/5/A/
+       2:  fccce22 = 2:  de345ab s/4/A/
+       3:  147e64e = 3:  9af6654 s/11/B/
+       4:  a63e992 = 4:  2901f77 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'simple B...C (unmodified)' '
+       git range-diff --no-color topic...unmodified >actual &&
+       # same "expected" as above
+       test_cmp expected actual
+'
+
+test_expect_success 'simple A B C (unmodified)' '
+       git range-diff --no-color master topic unmodified >actual &&
+       # same "expected" as above
+       test_cmp expected actual
+'
+
+test_expect_success 'trivial reordering' '
+       git range-diff --no-color master topic reordered >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  aca177a s/5/A/
+       3:  147e64e = 2:  14ad629 s/11/B/
+       4:  a63e992 = 3:  ee58208 s/12/B/
+       2:  fccce22 = 4:  307b27a s/4/A/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'removed a commit' '
+       git range-diff --no-color master topic removed >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  7657159 s/5/A/
+       2:  fccce22 < -:  ------- s/4/A/
+       3:  147e64e = 2:  43d84d3 s/11/B/
+       4:  a63e992 = 3:  a740396 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'added a commit' '
+       git range-diff --no-color master topic added >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  2716022 s/5/A/
+       2:  fccce22 = 2:  b62accd s/4/A/
+       -:  ------- > 3:  df46cfa s/6/A/
+       3:  147e64e = 4:  3e64548 s/11/B/
+       4:  a63e992 = 5:  12b4063 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'new base, A B C' '
+       git range-diff --no-color master topic rebased >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  cc9c443 s/5/A/
+       2:  fccce22 = 2:  c5d9641 s/4/A/
+       3:  147e64e = 3:  28cc2b6 s/11/B/
+       4:  a63e992 = 4:  5628ab7 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'new base, B...C' '
+       # this syntax includes the commits from master!
+       git range-diff --no-color topic...rebased >actual &&
+       cat >expected <<-EOF &&
+       -:  ------- > 1:  a31b12e unrelated
+       1:  4de457d = 2:  cc9c443 s/5/A/
+       2:  fccce22 = 3:  c5d9641 s/4/A/
+       3:  147e64e = 4:  28cc2b6 s/11/B/
+       4:  a63e992 = 5:  5628ab7 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'changed commit' '
+       git range-diff --no-color topic...changed >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  a4b3333 s/5/A/
+       2:  fccce22 = 2:  f51d370 s/4/A/
+       3:  147e64e ! 3:  0559556 s/11/B/
+           @@ -10,7 +10,7 @@
+             9
+             10
+            -11
+           -+B
+           ++BB
+             12
+             13
+             14
+       4:  a63e992 ! 4:  d966c5c s/12/B/
+           @@ -8,7 +8,7 @@
+            @@
+             9
+             10
+           - B
+           + BB
+            -12
+            +B
+             13
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'changed message' '
+       git range-diff --no-color topic...changed-message >actual &&
+       sed s/Z/\ /g >expected <<-EOF &&
+       1:  4de457d = 1:  f686024 s/5/A/
+       2:  fccce22 ! 2:  4ab067d s/4/A/
+           @@ -2,6 +2,8 @@
+           Z
+           Z    s/4/A/
+           Z
+           +    Also a silly comment here!
+           +
+           Zdiff --git a/file b/file
+           Z--- a/file
+           Z+++ b/file
+       3:  147e64e = 3:  b9cb956 s/11/B/
+       4:  a63e992 = 4:  8add5f1 s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_done
diff --git a/t/t3206/history.export b/t/t3206/history.export
new file mode 100644 (file)
index 0000000..b8ffff0
--- /dev/null
@@ -0,0 +1,604 @@
+blob
+mark :1
+data 51
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+reset refs/heads/removed
+commit refs/heads/removed
+mark :2
+author Thomas Rast <trast@inf.ethz.ch> 1374424921 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374484724 +0200
+data 8
+initial
+M 100644 :1 file
+
+blob
+mark :3
+data 51
+1
+2
+3
+4
+A
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/topic
+mark :4
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+blob
+mark :5
+data 51
+1
+2
+3
+A
+A
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/topic
+mark :6
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+data 7
+s/4/A/
+from :4
+M 100644 :5 file
+
+blob
+mark :7
+data 50
+1
+2
+3
+A
+A
+6
+7
+8
+9
+10
+B
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/topic
+mark :8
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+data 8
+s/11/B/
+from :6
+M 100644 :7 file
+
+blob
+mark :9
+data 49
+1
+2
+3
+A
+A
+6
+7
+8
+9
+10
+B
+B
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/topic
+mark :10
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+data 8
+s/12/B/
+from :8
+M 100644 :9 file
+
+blob
+mark :11
+data 10
+unrelated
+
+commit refs/heads/master
+mark :12
+author Thomas Rast <trast@inf.ethz.ch> 1374485127 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485127 +0200
+data 10
+unrelated
+from :2
+M 100644 :11 otherfile
+
+commit refs/heads/rebased
+mark :13
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485137 +0200
+data 7
+s/5/A/
+from :12
+M 100644 :3 file
+
+commit refs/heads/rebased
+mark :14
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485138 +0200
+data 7
+s/4/A/
+from :13
+M 100644 :5 file
+
+commit refs/heads/rebased
+mark :15
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485138 +0200
+data 8
+s/11/B/
+from :14
+M 100644 :7 file
+
+commit refs/heads/rebased
+mark :16
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485138 +0200
+data 8
+s/12/B/
+from :15
+M 100644 :9 file
+
+commit refs/heads/added
+mark :17
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+commit refs/heads/added
+mark :18
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
+data 7
+s/4/A/
+from :17
+M 100644 :5 file
+
+blob
+mark :19
+data 51
+1
+2
+3
+A
+A
+A
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/added
+mark :20
+author Thomas Rast <trast@inf.ethz.ch> 1374485186 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
+data 7
+s/6/A/
+from :18
+M 100644 :19 file
+
+blob
+mark :21
+data 50
+1
+2
+3
+A
+A
+A
+7
+8
+9
+10
+B
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/added
+mark :22
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
+data 8
+s/11/B/
+from :20
+M 100644 :21 file
+
+blob
+mark :23
+data 49
+1
+2
+3
+A
+A
+A
+7
+8
+9
+10
+B
+B
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/added
+mark :24
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
+data 8
+s/12/B/
+from :22
+M 100644 :23 file
+
+commit refs/heads/reordered
+mark :25
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+blob
+mark :26
+data 50
+1
+2
+3
+4
+A
+6
+7
+8
+9
+10
+B
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/reordered
+mark :27
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
+data 8
+s/11/B/
+from :25
+M 100644 :26 file
+
+blob
+mark :28
+data 49
+1
+2
+3
+4
+A
+6
+7
+8
+9
+10
+B
+B
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/reordered
+mark :29
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
+data 8
+s/12/B/
+from :27
+M 100644 :28 file
+
+commit refs/heads/reordered
+mark :30
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
+data 7
+s/4/A/
+from :29
+M 100644 :9 file
+
+commit refs/heads/changed
+mark :31
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+commit refs/heads/changed
+mark :32
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
+data 7
+s/4/A/
+from :31
+M 100644 :5 file
+
+blob
+mark :33
+data 51
+1
+2
+3
+A
+A
+6
+7
+8
+9
+10
+BB
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/changed
+mark :34
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
+data 8
+s/11/B/
+from :32
+M 100644 :33 file
+
+blob
+mark :35
+data 50
+1
+2
+3
+A
+A
+6
+7
+8
+9
+10
+BB
+B
+13
+14
+15
+16
+17
+18
+19
+20
+
+commit refs/heads/changed
+mark :36
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
+data 8
+s/12/B/
+from :34
+M 100644 :35 file
+
+commit refs/heads/changed-message
+mark :37
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485530 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+commit refs/heads/changed-message
+mark :38
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485530 +0200
+data 35
+s/4/A/
+
+Also a silly comment here!
+from :37
+M 100644 :5 file
+
+commit refs/heads/changed-message
+mark :39
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485536 +0200
+data 8
+s/11/B/
+from :38
+M 100644 :7 file
+
+commit refs/heads/changed-message
+mark :40
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485536 +0200
+data 8
+s/12/B/
+from :39
+M 100644 :9 file
+
+commit refs/heads/unmodified
+mark :41
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485631 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+commit refs/heads/unmodified
+mark :42
+author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485631 +0200
+data 7
+s/4/A/
+from :41
+M 100644 :5 file
+
+commit refs/heads/unmodified
+mark :43
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485632 +0200
+data 8
+s/11/B/
+from :42
+M 100644 :7 file
+
+commit refs/heads/unmodified
+mark :44
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374485632 +0200
+data 8
+s/12/B/
+from :43
+M 100644 :9 file
+
+commit refs/heads/removed
+mark :45
+author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374486061 +0200
+data 7
+s/5/A/
+from :2
+M 100644 :3 file
+
+commit refs/heads/removed
+mark :46
+author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374486061 +0200
+data 8
+s/11/B/
+from :45
+M 100644 :26 file
+
+commit refs/heads/removed
+mark :47
+author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
+committer Thomas Rast <trast@inf.ethz.ch> 1374486061 +0200
+data 8
+s/12/B/
+from :46
+M 100644 :28 file
+
+reset refs/heads/removed
+from :47
+
index 640fddc9c3903ba660d99b59a382d413706f7790..4c7b1ea3563274c7c3551e417c819b70200e90e9 100755 (executable)
@@ -1247,7 +1247,7 @@ rebase_setup_and_clean () {
                test_might_fail git branch -D $1 &&
                test_might_fail git rebase --abort
        " &&
-       git checkout -b $1 master
+       git checkout -b $1 ${2:-master}
 }
 
 test_expect_success 'drop' '
@@ -1424,4 +1424,12 @@ test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
        test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
 '
 
+test_expect_success 'valid author header after --root swap' '
+       rebase_setup_and_clean author-header no-conflict-branch &&
+       set_fake_editor &&
+       FAKE_LINES="2 1" git rebase -i --root &&
+       git cat-file commit HEAD^ >out &&
+       grep "^author ..*> [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$" out
+'
+
 test_done
index 65ed7db1592d97ae7120e028bc6023446e973a4a..25099d715cee0dff321c75b944f25f58169bf645 100755 (executable)
@@ -160,13 +160,15 @@ test_expect_success '--skip after failed fixup cleans commit message' '
        : The first squash was skipped, therefore: &&
        git show HEAD >out &&
        test_i18ngrep "# This is a combination of 2 commits" out &&
+       test_i18ngrep "# This is the commit message #2:" out &&
 
        (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
        git show HEAD >out &&
        test_i18ngrep ! "# This is a combination" out &&
 
        : Final squash failed, but there was still a squash &&
-       test_i18ngrep "# This is a combination of 2 commits" .git/copy.txt
+       test_i18ngrep "# This is a combination of 2 commits" .git/copy.txt &&
+       test_i18ngrep "# This is the commit message #2:" .git/copy.txt
 '
 
 test_expect_success 'setup rerere database' '
index 9e622972744a15a9e20c032b390426d39e59ddbf..aa7bfc88ece9de7f542f354c78b7be9ec6d2bdf7 100755 (executable)
@@ -13,8 +13,10 @@ Initial setup:
     -- B --                   (first)
    /       \
  A - C - D - E - H            (master)
-       \       /
-         F - G                (second)
+   \    \       /
+    \    F - G                (second)
+     \
+      Conflicting-G
 '
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-rebase.sh
@@ -49,7 +51,9 @@ test_expect_success 'setup' '
        git merge --no-commit G &&
        test_tick &&
        git commit -m H &&
-       git tag -m H H
+       git tag -m H H &&
+       git checkout A &&
+       test_commit conflicting-G G.t
 '
 
 test_expect_success 'create completely different structure' '
@@ -72,7 +76,7 @@ test_expect_success 'create completely different structure' '
        EOF
        test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
        test_tick &&
-       git rebase -i -r A &&
+       git rebase -i -r A master &&
        test_cmp_graph <<-\EOF
        *   Merge the topic branch '\''onebranch'\''
        |\
@@ -125,7 +129,7 @@ test_expect_success '`reset` refuses to overwrite untracked files' '
        git rebase --abort
 '
 
-test_expect_success 'failed `merge` writes patch (may be rescheduled, too)' '
+test_expect_success 'failed `merge -C` writes patch (may be rescheduled, too)' '
        test_when_finished "test_might_fail git rebase --abort" &&
        git checkout -b conflicting-merge A &&
 
@@ -141,13 +145,25 @@ test_expect_success 'failed `merge` writes patch (may be rescheduled, too)' '
 
        : fail because of merge conflict &&
        rm G.t .git/rebase-merge/patch &&
-       git reset --hard &&
-       test_commit conflicting-G G.t not-G conflicting-G &&
+       git reset --hard conflicting-G &&
        test_must_fail git rebase --continue &&
        ! grep "^merge -C .* G$" .git/rebase-merge/git-rebase-todo &&
        test_path_is_file .git/rebase-merge/patch
 '
 
+SQ="'"
+test_expect_success 'failed `merge <branch>` does not crash' '
+       test_when_finished "test_might_fail git rebase --abort" &&
+       git checkout conflicting-G &&
+
+       echo "merge G" >script-from-scratch &&
+       test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
+       test_tick &&
+       test_must_fail git rebase -ir HEAD &&
+       ! grep "^merge G$" .git/rebase-merge/git-rebase-todo &&
+       grep "^Merge branch ${SQ}G${SQ}$" .git/rebase-merge/message
+'
+
 test_expect_success 'with a branch tip that was cherry-picked already' '
        git checkout -b already-upstream master &&
        base="$(git rev-parse --verify HEAD)" &&
@@ -363,4 +379,21 @@ test_expect_success 'octopus merges' '
        EOF
 '
 
+test_expect_success 'with --autosquash and --exec' '
+       git checkout -b with-exec H &&
+       echo Booh >B.t &&
+       test_tick &&
+       git commit --fixup B B.t &&
+       write_script show.sh <<-\EOF &&
+       subject="$(git show -s --format=%s HEAD)"
+       content="$(git diff HEAD^! | tail -n 1)"
+       echo "$subject: $content"
+       EOF
+       test_tick &&
+       git rebase -ir --autosquash --exec ./show.sh A >actual &&
+       grep "B: +Booh" actual &&
+       grep "E: +Booh" actual &&
+       grep "G: +G" actual
+'
+
 test_done
index b8fbdefcdc34ffa6fb54fc1ad375a583a194fb38..5829dfd12cfdcbfe3061b7dcc7a91cd9799f4687 100755 (executable)
@@ -14,15 +14,13 @@ test_expect_success \
      git add -- foo bar baz 'space embedded' -q &&
      git commit -m 'add normal files'"
 
-if test_have_prereq !MINGW && touch -- 'tab    embedded' 'newline
-embedded' 2>/dev/null
-then
-       test_set_prereq FUNNYNAMES
-else
+if test_have_prereq !FUNNYNAMES; then
        say 'Your filesystem does not allow tabs in filenames.'
 fi
 
 test_expect_success FUNNYNAMES 'add files with funny names' "
+     touch -- 'tab     embedded' 'newline
+embedded' &&
      git add -- 'tab   embedded' 'newline
 embedded' &&
      git commit -m 'add files with tabs and newlines'
index 618750167aed8d99a57b2642713d12406cd2e5f6..37729ba2582119047d559d22df8c522f9c0ab0f1 100755 (executable)
@@ -188,9 +188,8 @@ test_expect_success 'git add --refresh with pathspec' '
        git add foo bar baz && H=$(git rev-parse :foo) && git rm -f foo &&
        echo "100644 $H 3       foo" | git update-index --index-info &&
        test-tool chmtime -60 bar baz &&
-       >expect &&
        git add --refresh bar >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        git diff-files --name-only >actual &&
        ! grep bar actual&&
index 26dd5b7f78a7f7e65ddda24c4686d2ae26fc30de..54ce19e353d924de08d4242f519fef7a44ce4787 100755 (executable)
@@ -187,9 +187,8 @@ test_expect_failure 'handle existing decomposed filenames' '
        echo content >"verbatim.$Adiarnfd" &&
        git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" &&
        git commit -m "existing decomposed file" &&
-       >expect &&
        git ls-files --exclude-standard -o "verbatim*" >untracked &&
-       test_cmp expect untracked
+       test_must_be_empty untracked
 '
 
 # Test if the global core.precomposeunicode stops autosensing
index b7f25071cfb24408f43634d016ac785bba282614..281f8fad0c71687aecec7479328ce8609cda5c83 100755 (executable)
@@ -74,8 +74,7 @@ test_expect_success 'diff-tree pathspec' '
        tree2=$(git write-tree) &&
        echo "$tree2" &&
        git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
-       >expected &&
-       test_cmp expected current
+       test_must_be_empty current
 '
 
 test_expect_success 'diff-tree with wildcard shows dir also matches' '
index e2dc1895ba3942954dfaba3c0af914494d2aa317..35fc8b5c2aa559a40000588f9a1e2b86215cb6ef 100755 (executable)
@@ -93,21 +93,20 @@ test_expect_success 'another test, without options' '
        git diff >out &&
        test_cmp expect out &&
 
-       >expect &&
        git diff -w >out &&
-       test_cmp expect out &&
+       test_must_be_empty out &&
 
        git diff -w -b >out &&
-       test_cmp expect out &&
+       test_must_be_empty out &&
 
        git diff -w --ignore-space-at-eol >out &&
-       test_cmp expect out &&
+       test_must_be_empty out &&
 
        git diff -w -b --ignore-space-at-eol >out &&
-       test_cmp expect out &&
+       test_must_be_empty out &&
 
        git diff -w --ignore-cr-at-eol >out &&
-       test_cmp expect out &&
+       test_must_be_empty out &&
 
        tr "Q_" "\015 " <<-\EOF >expect &&
        diff --git a/x b/x
@@ -182,8 +181,7 @@ test_expect_success 'ignore-blank-lines: only new lines' '
        test_seq 5 | sed "/3/i\\
 " >x &&
        git diff --ignore-blank-lines >out &&
-       >expect &&
-       test_cmp expect out
+       test_must_be_empty out
 '
 
 test_expect_success 'ignore-blank-lines: only new lines with space' '
@@ -192,8 +190,7 @@ test_expect_success 'ignore-blank-lines: only new lines with space' '
        test_seq 5 | sed "/3/i\\
  " >x &&
        git diff -w --ignore-blank-lines >out &&
-       >expect &&
-       test_cmp expect out
+       test_must_be_empty out
 '
 
 test_expect_success 'ignore-blank-lines: after change' '
index 23c0e357a765f00d807938fccf81a250c371ec4f..53ac44b0f0036803b48979c3c5f343ca02b1b80a 100755 (executable)
@@ -34,9 +34,8 @@ test_expect_success POSIXPERM 'find-copies-harder is not confused by mode bits'
        git add exec &&
        git commit -m exec &&
        git update-index --assume-unchanged exec &&
-       >expect &&
        git diff-files --find-copies-harder -- exec >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_done
index c7c688fcc4bbdfe97a5c595fddc96e2590e021a2..6bc3fb97a754bf242f8baf1ba867aa9f7fa93d0d 100755 (executable)
@@ -15,15 +15,7 @@ test_expect_success 'setup' '
                git checkout -f preimage^0 &&
                git read-tree -u --reset HEAD &&
                git update-index --refresh
-       } &&
-
-       test_when_finished "rm -f \"tab embedded.txt\"" &&
-       test_when_finished "rm -f '\''\"quoteembedded\".txt'\''" &&
-       if test_have_prereq !MINGW &&
-               touch -- "tab   embedded.txt" '\''"quoteembedded".txt'\''
-       then
-               test_set_prereq FUNNYNAMES
-       fi
+       }
 '
 
 try_filename() {
index 1ebc587f8fc0010713f52196206462fa915cbca5..01867a989885e1272e998df54375b74438a8059e 100755 (executable)
@@ -69,13 +69,15 @@ test_expect_success 'setup: messages' '
 
        EOF
 
-       cat >scissors-msg <<-\EOF &&
-       Test git-am with scissors line
+       cat >msg-without-scissors-line <<-\EOF &&
+       Test that git-am --scissors cuts at the scissors line
 
        This line should be included in the commit message.
        EOF
 
-       cat - scissors-msg >no-scissors-msg <<-\EOF &&
+       printf "Subject: " >subject-prefix &&
+
+       cat - subject-prefix msg-without-scissors-line >msg-with-scissors-line <<-\EOF &&
        This line should not be included in the commit message with --scissors enabled.
 
         - - >8 - - remove everything above this line - - >8 - -
@@ -148,18 +150,17 @@ test_expect_success setup '
        } >patch1-hg.eml &&
 
 
-       echo scissors-file >scissors-file &&
-       git add scissors-file &&
-       git commit -F scissors-msg &&
-       git tag scissors &&
-       git format-patch --stdout scissors^ >scissors-patch.eml &&
+       echo file >file &&
+       git add file &&
+       git commit -F msg-without-scissors-line &&
+       git tag expected-for-scissors &&
        git reset --hard HEAD^ &&
 
-       echo no-scissors-file >no-scissors-file &&
-       git add no-scissors-file &&
-       git commit -F no-scissors-msg &&
-       git tag no-scissors &&
-       git format-patch --stdout no-scissors^ >no-scissors-patch.eml &&
+       echo file >file &&
+       git add file &&
+       git commit -F msg-with-scissors-line &&
+       git tag expected-for-no-scissors &&
+       git format-patch --stdout expected-for-no-scissors^ >patch-with-scissors-line.eml &&
        git reset --hard HEAD^ &&
 
        sed -n -e "3,\$p" msg >file &&
@@ -416,10 +417,10 @@ test_expect_success 'am --scissors cuts the message at the scissors line' '
        rm -fr .git/rebase-apply &&
        git reset --hard &&
        git checkout second &&
-       git am --scissors scissors-patch.eml &&
+       git am --scissors patch-with-scissors-line.eml &&
        test_path_is_missing .git/rebase-apply &&
-       git diff --exit-code scissors &&
-       test_cmp_rev scissors HEAD
+       git diff --exit-code expected-for-scissors &&
+       test_cmp_rev expected-for-scissors HEAD
 '
 
 test_expect_success 'am --no-scissors overrides mailinfo.scissors' '
@@ -427,10 +428,10 @@ test_expect_success 'am --no-scissors overrides mailinfo.scissors' '
        git reset --hard &&
        git checkout second &&
        test_config mailinfo.scissors true &&
-       git am --no-scissors no-scissors-patch.eml &&
+       git am --no-scissors patch-with-scissors-line.eml &&
        test_path_is_missing .git/rebase-apply &&
-       git diff --exit-code no-scissors &&
-       test_cmp_rev no-scissors HEAD
+       git diff --exit-code expected-for-no-scissors &&
+       test_cmp_rev expected-for-no-scissors HEAD
 '
 
 test_expect_success 'setup: new author and committer' '
index 8417e5a4b105a54a8de23af8bae2bdaf28c257cb..65da74c76683c0ccd109fdec63766ab6bdfb08f0 100755 (executable)
@@ -267,8 +267,7 @@ rerere_gc_custom_expiry_test () {
                git -c "gc.rerereresolved=$right_now" \
                    -c "gc.rerereunresolved=$right_now" rerere gc &&
                find .git/rr-cache -type f | sort >actual &&
-               >expect &&
-               test_cmp expect actual
+               test_must_be_empty actual
        '
 }
 
@@ -536,9 +535,8 @@ test_expect_success 'multiple identical conflicts' '
 
        # We resolved file1 and file2
        git rerere &&
-       >expect &&
        git rerere remaining >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        # We must have recorded both of them
        count_pre_post 2 2 &&
@@ -548,9 +546,8 @@ test_expect_success 'multiple identical conflicts' '
        test_must_fail git merge six.1 &&
        git rerere &&
 
-       >expect &&
        git rerere remaining >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        concat_insert short 6.1 6.2 >file1.expect &&
        concat_insert long 6.1 6.2 >file2.expect &&
index 05d3707e38befc214678b4010ed96b6be94f16b3..153a506151e2afe3f1e047cd5a00270f1378ce14 100755 (executable)
@@ -340,10 +340,9 @@ test_expect_success PCRE 'log -F -E --perl-regexp --grep=<pcre> uses PCRE' '
 '
 
 test_expect_success 'log with grep.patternType configuration' '
-       >expect &&
        git -c grep.patterntype=fixed \
        log -1 --pretty=tformat:%s --grep=s.c.nd >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'log with grep.patternType configuration and command line' '
@@ -1662,9 +1661,8 @@ test_expect_success 'log diagnoses bogus HEAD' '
 '
 
 test_expect_success 'log does not default to HEAD when rev input is given' '
-       >expect &&
        git log --branches=does-not-exist >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'set up --source tests' '
index e585fe6129b7af264427d8af46de21cb08efad7f..7c519436ef3d2ed4843d173948c8fcac1069cffe 100755 (executable)
@@ -44,15 +44,13 @@ test_expect_success !MINGW 'log --grep searches in log output encoding (latin1)'
 '
 
 test_expect_success !MINGW 'log --grep does not find non-reencoded values (utf8)' '
-       >expect &&
        git log --encoding=utf8 --format=%s --grep=$latin1_e >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'log --grep does not find non-reencoded values (latin1)' '
-       >expect &&
        git log --encoding=ISO-8859-1 --format=%s --grep=$utf8_e >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_done
index 2d22a17c4a7f9dcc402e89e73ce01c97ebd4ba48..557bd0d0c09e370515acb7fc75391f0a7d62d73e 100755 (executable)
@@ -9,7 +9,8 @@ objpath () {
 
 # show objects present in pack ($1 should be associated *.idx)
 list_packed_objects () {
-       git show-index <"$1" | cut -d' ' -f2
+       git show-index <"$1" >object-list &&
+       cut -d' ' -f2 object-list
 }
 
 # has_any pattern-file content-file
@@ -204,8 +205,8 @@ test_expect_success 'pack-objects to file can use bitmap' '
        # verify equivalent packs are generated with/without using bitmap index
        packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
        packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
-       list_packed_objects <packa-$packasha1.idx >packa.objects &&
-       list_packed_objects <packb-$packbsha1.idx >packb.objects &&
+       list_packed_objects packa-$packasha1.idx >packa.objects &&
+       list_packed_objects packb-$packbsha1.idx >packb.objects &&
        test_cmp packa.objects packb.objects
 '
 
@@ -309,9 +310,8 @@ test_expect_success 'pack reuse respects --honor-pack-keep' '
        done &&
        reusable_pack --honor-pack-keep >empty.pack &&
        git index-pack empty.pack &&
-       >expect &&
        git show-index <empty.idx >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'pack reuse respects --local' '
@@ -319,17 +319,15 @@ test_expect_success 'pack reuse respects --local' '
        test_when_finished "mv alt.git/objects/pack/* .git/objects/pack/" &&
        reusable_pack --local >empty.pack &&
        git index-pack empty.pack &&
-       >expect &&
        git show-index <empty.idx >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'pack reuse respects --incremental' '
        reusable_pack --incremental >empty.pack &&
        git index-pack empty.pack &&
-       >expect &&
        git show-index <empty.idx >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'truncated bitmap fails gracefully' '
index 4fe4ad9d6166d9a82cb944fadfc0317b5052b973..f1708d415e55c25be441ae47f865fbe7f5973c93 100755 (executable)
@@ -90,9 +90,8 @@ test_expect_success 'matched bogus object count' '
 
        # Unlike above, we should notice early that the .idx is totally
        # bogus, and not even enumerate its contents.
-       >expect &&
        git cat-file --batch-all-objects --batch-check >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        # But as before, we can do the same object-access checks.
        test_must_fail git cat-file blob $object &&
index 4f17d7701e456bbb0992efdba2861e1dac8f7c23..3c1ffad49144d177a56f2f6a0b26612899e25adb 100755 (executable)
@@ -254,9 +254,9 @@ test_expect_success 'check that gc computes commit-graph' '
        git config gc.writeCommitGraph true &&
        git gc &&
        cp $objdir/info/commit-graph commit-graph-after-gc &&
-       ! test_cmp commit-graph-before-gc commit-graph-after-gc &&
+       ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
        git commit-graph write --reachable &&
-       test_cmp commit-graph-after-gc $objdir/info/commit-graph
+       test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
 '
 
 # the verify tests below expect the commit-graph to contain
@@ -444,25 +444,27 @@ test_expect_success 'setup non-the_repository tests' '
 test_expect_success 'parse_commit_in_graph works for non-the_repository' '
        test-tool repository parse_commit_in_graph \
                repo/.git repo "$(git -C repo rev-parse two)" >actual &&
-       echo $(git -C repo log --pretty="%ct" -1) \
-               $(git -C repo rev-parse one) >expect &&
+       {
+               git -C repo log --pretty=format:"%ct " -1 &&
+               git -C repo rev-parse one
+       } >expect &&
        test_cmp expect actual &&
 
        test-tool repository parse_commit_in_graph \
                repo/.git repo "$(git -C repo rev-parse one)" >actual &&
-       echo $(git -C repo log --pretty="%ct" -1 one) >expect &&
+       git -C repo log --pretty="%ct" -1 one >expect &&
        test_cmp expect actual
 '
 
 test_expect_success 'get_commit_tree_in_graph works for non-the_repository' '
        test-tool repository get_commit_tree_in_graph \
                repo/.git repo "$(git -C repo rev-parse two)" >actual &&
-       echo $(git -C repo rev-parse two^{tree}) >expect &&
+       git -C repo rev-parse two^{tree} >expect &&
        test_cmp expect actual &&
 
        test-tool repository get_commit_tree_in_graph \
                repo/.git repo "$(git -C repo rev-parse one)" >actual &&
-       echo $(git -C repo rev-parse one^{tree}) >expect &&
+       git -C repo rev-parse one^{tree} >expect &&
        test_cmp expect actual
 '
 
index 49d3621a926786dfbfd71b205dfcb5dd3fa2d889..62f35698912d0655e44d53d50c7197b8200d2710 100755 (executable)
@@ -3,13 +3,16 @@
 test_description='fetch/receive strict mode'
 . ./test-lib.sh
 
-test_expect_success setup '
+test_expect_success 'setup and inject "corrupt or missing" object' '
        echo hello >greetings &&
        git add greetings &&
        git commit -m greetings &&
 
        S=$(git rev-parse :greetings | sed -e "s|^..|&/|") &&
        X=$(echo bye | git hash-object -w --stdin | sed -e "s|^..|&/|") &&
+       echo $S >S &&
+       echo $X >X &&
+       cp .git/objects/$S .git/objects/$S.back &&
        mv -f .git/objects/$X .git/objects/$S &&
 
        test_must_fail git fsck
@@ -115,6 +118,13 @@ test_expect_success 'push with transfer.fsckobjects' '
        test_cmp exp act
 '
 
+test_expect_success 'repair the "corrupt or missing" object' '
+       mv -f .git/objects/$(cat S) .git/objects/$(cat X) &&
+       mv .git/objects/$(cat S).back .git/objects/$(cat S) &&
+       rm -rf .git/objects/$(cat X) &&
+       git fsck
+'
+
 cat >bogus-commit <<EOF
 tree $EMPTY_TREE
 author Bugs Bunny 1234567890 +0000
@@ -123,6 +133,14 @@ committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
 This commit object intentionally broken
 EOF
 
+test_expect_success 'fsck with invalid or bogus skipList input' '
+       git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
+       test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err &&
+       test_i18ngrep "Could not open skip list: does-not-exist" err &&
+       test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
+       test_i18ngrep "Invalid SHA-1: \[core\]" err
+'
+
 test_expect_success 'push with receive.fsck.skipList' '
        commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
        git push . $commit:refs/heads/bogus &&
@@ -130,11 +148,61 @@ test_expect_success 'push with receive.fsck.skipList' '
        git init dst &&
        git --git-dir=dst/.git config receive.fsckObjects true &&
        test_must_fail git push --porcelain dst bogus &&
-       git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
        echo $commit >dst/.git/SKIP &&
+
+       # receive.fsck.* does not fall back on fsck.*
+       git --git-dir=dst/.git config fsck.skipList SKIP &&
+       test_must_fail git push --porcelain dst bogus &&
+
+       # Invalid and/or bogus skipList input
+       git --git-dir=dst/.git config receive.fsck.skipList /dev/null &&
+       test_must_fail git push --porcelain dst bogus &&
+       git --git-dir=dst/.git config receive.fsck.skipList does-not-exist &&
+       test_must_fail git push --porcelain dst bogus 2>err &&
+       test_i18ngrep "Could not open skip list: does-not-exist" err &&
+       git --git-dir=dst/.git config receive.fsck.skipList config &&
+       test_must_fail git push --porcelain dst bogus 2>err &&
+       test_i18ngrep "Invalid SHA-1: \[core\]" err &&
+
+       git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
        git push --porcelain dst bogus
 '
 
+test_expect_success 'fetch with fetch.fsck.skipList' '
+       commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
+       refspec=refs/heads/bogus:refs/heads/bogus &&
+       git push . $commit:refs/heads/bogus &&
+       rm -rf dst &&
+       git init dst &&
+       git --git-dir=dst/.git config fetch.fsckObjects true &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+       git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+       echo $commit >dst/.git/SKIP &&
+
+       # fetch.fsck.* does not fall back on fsck.*
+       git --git-dir=dst/.git config fsck.skipList dst/.git/SKIP &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+
+       # Invalid and/or bogus skipList input
+       git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+       git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
+       test_i18ngrep "Could not open skip list: does-not-exist" err &&
+       git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
+       test_i18ngrep "Invalid SHA-1: \[core\]" err &&
+
+       git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
+       git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
+'
+
+test_expect_success 'fsck.<unknownmsg-id> dies' '
+       test_must_fail git -c fsck.whatEver=ignore fsck 2>err &&
+       test_i18ngrep "Unhandled message id: whatever" err
+'
+
 test_expect_success 'push with receive.fsck.missingEmail=warn' '
        commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
        git push . $commit:refs/heads/bogus &&
@@ -142,19 +210,58 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
        git init dst &&
        git --git-dir=dst/.git config receive.fsckobjects true &&
        test_must_fail git push --porcelain dst bogus &&
+
+       # receive.fsck.<msg-id> does not fall back on fsck.<msg-id>
+       git --git-dir=dst/.git config fsck.missingEmail warn &&
+       test_must_fail git push --porcelain dst bogus &&
+
+       # receive.fsck.<unknownmsg-id> warns
+       git --git-dir=dst/.git config \
+               receive.fsck.whatEver error &&
+
        git --git-dir=dst/.git config \
                receive.fsck.missingEmail warn &&
        git push --porcelain dst bogus >act 2>&1 &&
        grep "missingEmail" act &&
+       test_i18ngrep "Skipping unknown msg id.*whatever" act &&
        git --git-dir=dst/.git branch -D bogus &&
        git --git-dir=dst/.git config --add \
                receive.fsck.missingEmail ignore &&
-       git --git-dir=dst/.git config --add \
-               receive.fsck.badDate warn &&
        git push --porcelain dst bogus >act 2>&1 &&
        ! grep "missingEmail" act
 '
 
+test_expect_success 'fetch with fetch.fsck.missingEmail=warn' '
+       commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
+       refspec=refs/heads/bogus:refs/heads/bogus &&
+       git push . $commit:refs/heads/bogus &&
+       rm -rf dst &&
+       git init dst &&
+       git --git-dir=dst/.git config fetch.fsckobjects true &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+
+       # fetch.fsck.<msg-id> does not fall back on fsck.<msg-id>
+       git --git-dir=dst/.git config fsck.missingEmail warn &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
+
+       # receive.fsck.<unknownmsg-id> warns
+       git --git-dir=dst/.git config \
+               fetch.fsck.whatEver error &&
+
+       git --git-dir=dst/.git config \
+               fetch.fsck.missingEmail warn &&
+       git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
+       grep "missingEmail" act &&
+       test_i18ngrep "Skipping unknown msg id.*whatever" act &&
+       rm -rf dst &&
+       git init dst &&
+       git --git-dir=dst/.git config fetch.fsckobjects true &&
+       git --git-dir=dst/.git config \
+               fetch.fsck.missingEmail ignore &&
+       git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
+       ! grep "missingEmail" act
+'
+
 test_expect_success \
        'receive.fsck.unterminatedHeader=warn triggers error' '
        rm -rf dst &&
@@ -166,4 +273,15 @@ test_expect_success \
        grep "Cannot demote unterminatedheader" act
 '
 
+test_expect_success \
+       'fetch.fsck.unterminatedHeader=warn triggers error' '
+       rm -rf dst &&
+       git init dst &&
+       git --git-dir=dst/.git config fetch.fsckobjects true &&
+       git --git-dir=dst/.git config \
+               fetch.fsck.unterminatedheader warn &&
+       test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" HEAD &&
+       grep "Cannot demote unterminatedheader" act
+'
+
 test_done
index a6856e052b8f9e33a98a869d0b37c5977d93418f..241e6a319df4cefa612b6744c79e72e5cf929462 100755 (executable)
@@ -74,8 +74,7 @@ test_expect_success 'add another remote' '
                git for-each-ref "--format=%(refname)" refs/remotes |
                sed -e "/^refs\/remotes\/origin\//d" \
                    -e "/^refs\/remotes\/second\//d" >actual &&
-               >expect &&
-               test_cmp expect actual
+               test_must_be_empty actual
        )
 '
 
@@ -112,8 +111,7 @@ test_expect_success C_LOCALE_OUTPUT 'remove remote' '
                check_remote_track origin master side &&
                git for-each-ref "--format=%(refname)" refs/remotes |
                sed -e "/^refs\/remotes\/origin\//d" >actual &&
-               >expect &&
-               test_cmp expect actual
+               test_must_be_empty actual
        )
 '
 
index 62308be499ffd862484eb23de61850d00f80720c..3b7b30568cddd5d9ea1a8979e5366a262f81bf09 100755 (executable)
@@ -535,6 +535,41 @@ test_expect_success "should be able to fetch with duplicate refspecs" '
        )
 '
 
+test_expect_success 'LHS of refspec follows ref disambiguation rules' '
+       mkdir lhs-ambiguous &&
+       (
+               cd lhs-ambiguous &&
+               git init server &&
+               test_commit -C server unwanted &&
+               test_commit -C server wanted &&
+
+               git init client &&
+
+               # Check a name coming after "refs" alphabetically ...
+               git -C server update-ref refs/heads/s wanted &&
+               git -C server update-ref refs/heads/refs/heads/s unwanted &&
+               git -C client fetch ../server +refs/heads/s:refs/heads/checkthis &&
+               git -C server rev-parse wanted >expect &&
+               git -C client rev-parse checkthis >actual &&
+               test_cmp expect actual &&
+
+               # ... and one before.
+               git -C server update-ref refs/heads/q wanted &&
+               git -C server update-ref refs/heads/refs/heads/q unwanted &&
+               git -C client fetch ../server +refs/heads/q:refs/heads/checkthis &&
+               git -C server rev-parse wanted >expect &&
+               git -C client rev-parse checkthis >actual &&
+               test_cmp expect actual &&
+
+               # Tags are preferred over branches like refs/{heads,tags}/*
+               git -C server update-ref refs/tags/t wanted &&
+               git -C server update-ref refs/heads/t unwanted &&
+               git -C client fetch ../server +t:refs/heads/checkthis &&
+               git -C server rev-parse wanted >expect &&
+               git -C client rev-parse checkthis >actual
+       )
+'
+
 # configured prune tests
 
 set_config_tristate () {
@@ -613,7 +648,7 @@ test_configured_prune_type () {
                        git rev-parse --verify refs/tags/newtag
                ) &&
 
-               # now remove it
+               # now remove them
                git branch -d newbranch &&
                git tag -d newtag &&
 
index ea020040e858de0c65759e299ce9cf646573fc63..bc5703ff9ba166b928199abf3085ff55a8fc09f1 100755 (executable)
@@ -155,14 +155,12 @@ test_expect_success 'die with non-2 for wrong repository even with --exit-code'
 
 test_expect_success 'Report success even when nothing matches' '
        git ls-remote other.git "refs/nsn/*" >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'Report no-match with --exit-code' '
        test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'Report match with --exit-code' '
index 4b4b6673b8fe25d96044cdc5d1196b191a7ae0e9..0030c92e1afa2a83066944272fcf3925f821bc54 100755 (executable)
@@ -152,7 +152,6 @@ test_expect_success 'git fetch --multiple (ignoring skipFetchAll)' '
 '
 
 test_expect_success 'git fetch --all --no-tags' '
-       >expect &&
        git clone one test5 &&
        git clone test5 test6 &&
        (cd test5 && git tag test-tag) &&
@@ -161,7 +160,7 @@ test_expect_success 'git fetch --all --no-tags' '
                git fetch --all --no-tags &&
                git tag >output
        ) &&
-       test_cmp expect test6/output
+       test_must_be_empty test6/output
 '
 
 test_expect_success 'git fetch --all --tags' '
index bd8f23e4300218fba33a5bea5effa167a2e9155a..539c25aadafdcf6aa9fbcce0988631702d3fb02d 100755 (executable)
@@ -965,26 +965,51 @@ test_expect_success 'push into aliased refs (inconsistent)' '
        )
 '
 
-test_expect_success 'push requires --force to update lightweight tag' '
-       mk_test testrepo heads/master &&
-       mk_child testrepo child1 &&
-       mk_child testrepo child2 &&
-       (
-               cd child1 &&
-               git tag Tag &&
-               git push ../child2 Tag &&
-               git push ../child2 Tag &&
-               >file1 &&
-               git add file1 &&
-               git commit -m "file1" &&
-               git tag -f Tag &&
-               test_must_fail git push ../child2 Tag &&
-               git push --force ../child2 Tag &&
-               git tag -f Tag &&
-               test_must_fail git push ../child2 Tag HEAD~ &&
-               git push --force ../child2 Tag
-       )
-'
+test_force_push_tag () {
+       tag_type_description=$1
+       tag_args=$2
+
+       test_expect_success 'force pushing required to update lightweight tag' "
+               mk_test testrepo heads/master &&
+               mk_child testrepo child1 &&
+               mk_child testrepo child2 &&
+               (
+                       cd child1 &&
+                       git tag testTag &&
+                       git push ../child2 testTag &&
+                       >file1 &&
+                       git add file1 &&
+                       git commit -m 'file1' &&
+                       git tag $tag_args testTag &&
+                       test_must_fail git push ../child2 testTag &&
+                       git push --force ../child2 testTag &&
+                       git tag $tag_args testTag HEAD~ &&
+                       test_must_fail git push ../child2 testTag &&
+                       git push --force ../child2 testTag &&
+
+                       # Clobbering without + in refspec needs --force
+                       git tag -f testTag &&
+                       test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' &&
+                       git push --force ../child2 'refs/tags/*:refs/tags/*' &&
+
+                       # Clobbering with + in refspec does not need --force
+                       git tag -f testTag HEAD~ &&
+                       git push ../child2 '+refs/tags/*:refs/tags/*' &&
+
+                       # Clobbering with --no-force still obeys + in refspec
+                       git tag -f testTag &&
+                       git push --no-force ../child2 '+refs/tags/*:refs/tags/*' &&
+
+                       # Clobbering with/without --force and 'tag <name>' format
+                       git tag -f testTag HEAD~ &&
+                       test_must_fail git push ../child2 tag testTag &&
+                       git push --force ../child2 tag testTag
+               )
+       "
+}
+
+test_force_push_tag "lightweight tag" "-f"
+test_force_push_tag "annotated tag" "-f -a -m'msg'"
 
 test_expect_success 'push --porcelain' '
        mk_empty testrepo &&
index 68aa5f0340132e8d3fabfd85aa70f1cdfe755cf3..5e501c8b08868b17478b8baa91db2cd129cd1c67 100755 (executable)
@@ -475,10 +475,22 @@ test_expect_success 'pull.rebase=interactive' '
        false
        EOF
        test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
+       test_when_finished "test_might_fail git rebase --abort" &&
        test_must_fail git pull --rebase=interactive . copy &&
        test "I was here" = "$(cat fake.out)"
 '
 
+test_expect_success 'pull --rebase=i' '
+       write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
+       echo I was here, too >fake.out &&
+       false
+       EOF
+       test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
+       test_when_finished "test_might_fail git rebase --abort" &&
+       test_must_fail git pull --rebase=i . copy &&
+       test "I was here, too" = "$(cat fake.out)"
+'
+
 test_expect_success 'pull.rebase=invalid fails' '
        git reset --hard before-preserve-rebase &&
        test_config pull.rebase invalid &&
index d38ecee2172a6e5599cfbeb18e472816e98e553c..0b0eb1d0259f314261c131db8e089e6859a7f3ba 100755 (executable)
@@ -142,9 +142,8 @@ test_expect_success 'push to delete (protected, forced)' '
                cd dst &&
                git push --force --force-with-lease=master:master^ origin :master
        ) &&
-       >expect &&
        git ls-remote src refs/heads/master >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'push to delete (allowed)' '
@@ -154,9 +153,8 @@ test_expect_success 'push to delete (allowed)' '
                git push --force-with-lease=master origin :master 2>err &&
                grep deleted err
        ) &&
-       >expect &&
        git ls-remote src refs/heads/master >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'cover everything with default force-with-lease (protected)' '
index 0a8e0e42ed3b0992ffa645464eeb33bdf727d6da..5ad5bece55620138ce76579abb6e76c0710d126d 100755 (executable)
@@ -28,6 +28,19 @@ have_not_sent () {
        done
 }
 
+# trace_fetch <client_dir> <server_dir> [args]
+#
+# Trace the packet output of fetch, but make sure we disable the variable
+# in the child upload-pack, so we don't combine the results in the same file.
+trace_fetch () {
+       client=$1; shift
+       server=$1; shift
+       GIT_TRACE_PACKET="$(pwd)/trace" \
+       git -C "$client" fetch \
+         --upload-pack 'unset GIT_TRACE_PACKET; git-upload-pack' \
+         "$server" "$@"
+}
+
 test_expect_success 'commits with no parents are sent regardless of skip distance' '
        git init server &&
        test_commit -C server to_fetch &&
@@ -42,11 +55,34 @@ test_expect_success 'commits with no parents are sent regardless of skip distanc
        # "c1" has no parent, it is still sent as "have" even though it would
        # normally be skipped.
        test_config -C client fetch.negotiationalgorithm skipping &&
-       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
+       trace_fetch client "$(pwd)/server" &&
        have_sent c7 c5 c2 c1 &&
        have_not_sent c6 c4 c3
 '
 
+test_expect_success 'unknown fetch.negotiationAlgorithm values error out' '
+       rm -rf server client trace &&
+       git init server &&
+       test_commit -C server to_fetch &&
+
+       git init client &&
+       test_commit -C client on_client &&
+       git -C client checkout on_client &&
+
+       test_config -C client fetch.negotiationAlgorithm invalid &&
+       test_must_fail git -C client fetch "$(pwd)/server" 2>err &&
+       test_i18ngrep "unknown fetch negotiation algorithm" err &&
+
+       # Explicit "default" value
+       test_config -C client fetch.negotiationAlgorithm default &&
+       git -C client -c fetch.negotiationAlgorithm=default fetch "$(pwd)/server" &&
+
+       # Implementation detail: If there is nothing to fetch, we will not error out
+       test_config -C client fetch.negotiationAlgorithm invalid &&
+       git -C client fetch "$(pwd)/server" 2>err &&
+       test_i18ngrep ! "unknown fetch negotiation algorithm" err
+'
+
 test_expect_success 'when two skips collide, favor the larger one' '
        rm -rf server client trace &&
        git init server &&
@@ -65,7 +101,7 @@ test_expect_success 'when two skips collide, favor the larger one' '
        # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
        # (from "c5side" skip 1).
        test_config -C client fetch.negotiationalgorithm skipping &&
-       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
+       trace_fetch client "$(pwd)/server" &&
        have_sent c5side c11 c9 c6 c1 &&
        have_not_sent c10 c8 c7 c5 c4 c3 c2
 '
@@ -91,7 +127,7 @@ test_expect_success 'use ref advertisement to filter out commits' '
        # not need to send any ancestors of "c3", but we still need to send "c3"
        # itself.
        test_config -C client fetch.negotiationalgorithm skipping &&
-       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch origin to_fetch &&
+       trace_fetch client origin to_fetch &&
        have_sent c5 c4^ c2side &&
        have_not_sent c4 c4^^ c4^^^
 '
@@ -121,7 +157,7 @@ test_expect_success 'handle clock skew' '
        # and sent, because (due to clock skew) its only parent has already been
        # popped off the priority queue.
        test_config -C client fetch.negotiationalgorithm skipping &&
-       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
+       trace_fetch client "$(pwd)/server" &&
        have_sent c2 c1 old4 old2 old1 &&
        have_not_sent old3
 '
@@ -153,7 +189,7 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
        test_commit -C server commit-on-b1 &&
 
        test_config -C client fetch.negotiationalgorithm skipping &&
-       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" to_fetch &&
+       trace_fetch client "$(pwd)/server" to_fetch &&
        grep "  fetch" trace &&
 
        # fetch-pack sends 2 requests each containing 16 "have" lines before
diff --git a/t/t5562-http-backend-content-length.sh b/t/t5562-http-backend-content-length.sh
new file mode 100755 (executable)
index 0000000..43570ce
--- /dev/null
@@ -0,0 +1,156 @@
+#!/bin/sh
+
+test_description='test git-http-backend respects CONTENT_LENGTH'
+. ./test-lib.sh
+
+test_lazy_prereq GZIP 'gzip --version'
+
+verify_http_result() {
+       # some fatal errors still produce status 200
+       # so check if there is the error message
+       if grep 'fatal:' act.err
+       then
+               return 1
+       fi
+
+       if ! grep "Status" act.out >act
+       then
+               printf "Status: 200 OK\r\n" >act
+       fi
+       printf "Status: $1\r\n" >exp &&
+       test_cmp exp act
+}
+
+test_http_env() {
+       handler_type="$1"
+       request_body="$2"
+       shift
+       env \
+               CONTENT_TYPE="application/x-git-$handler_type-pack-request" \
+               QUERY_STRING="/repo.git/git-$handler_type-pack" \
+               PATH_TRANSLATED="$PWD/.git/git-$handler_type-pack" \
+               GIT_HTTP_EXPORT_ALL=TRUE \
+               REQUEST_METHOD=POST \
+               "$TEST_DIRECTORY"/t5562/invoke-with-content-length.pl \
+                   "$request_body" git http-backend >act.out 2>act.err
+}
+
+ssize_b100dots() {
+       # hardcoded ((size_t) SSIZE_MAX) + 1
+       case "$(build_option sizeof-size_t)" in
+       8) echo 9223372036854775808;;
+       4) echo 2147483648;;
+       *) die "Unexpected ssize_t size: $(build_option sizeof-size_t)";;
+       esac
+}
+
+test_expect_success 'setup' '
+       HTTP_CONTENT_ENCODING="identity" &&
+       export HTTP_CONTENT_ENCODING &&
+       git config http.receivepack true &&
+       test_commit c0 &&
+       test_commit c1 &&
+       hash_head=$(git rev-parse HEAD) &&
+       hash_prev=$(git rev-parse HEAD~1) &&
+       printf "want %s" "$hash_head" | packetize >fetch_body &&
+       printf 0000 >>fetch_body &&
+       printf "have %s" "$hash_prev" | packetize >>fetch_body &&
+       printf done | packetize >>fetch_body &&
+       test_copy_bytes 10 <fetch_body >fetch_body.trunc &&
+       hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) &&
+       printf "%s %s refs/heads/newbranch\\0report-status\\n" "$_z40" "$hash_next" | packetize >push_body &&
+       printf 0000 >>push_body &&
+       echo "$hash_next" | git pack-objects --stdout >>push_body &&
+       test_copy_bytes 10 <push_body >push_body.trunc &&
+       : >empty_body
+'
+
+test_expect_success GZIP 'setup, compression related' '
+       gzip -c fetch_body >fetch_body.gz &&
+       test_copy_bytes 10 <fetch_body.gz >fetch_body.gz.trunc &&
+       gzip -c push_body >push_body.gz &&
+       test_copy_bytes 10 <push_body.gz >push_body.gz.trunc
+'
+
+test_expect_success 'fetch plain' '
+       test_http_env upload fetch_body &&
+       verify_http_result "200 OK"
+'
+
+test_expect_success 'fetch plain truncated' '
+       test_http_env upload fetch_body.trunc &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success 'fetch plain empty' '
+       test_http_env upload empty_body &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'fetch gzipped' '
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload fetch_body.gz &&
+       verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'fetch gzipped truncated' '
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload fetch_body.gz.trunc &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'fetch gzipped empty' '
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload empty_body &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'push plain' '
+       test_when_finished "git branch -D newbranch" &&
+       test_http_env receive push_body &&
+       verify_http_result "200 OK" &&
+       git rev-parse newbranch >act.head &&
+       echo "$hash_next" >exp.head &&
+       test_cmp act.head exp.head
+'
+
+test_expect_success 'push plain truncated' '
+       test_http_env receive push_body.trunc &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success 'push plain empty' '
+       test_http_env receive empty_body &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'push gzipped' '
+       test_when_finished "git branch -D newbranch" &&
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive push_body.gz &&
+       verify_http_result "200 OK" &&
+       git rev-parse newbranch >act.head &&
+       echo "$hash_next" >exp.head &&
+       test_cmp act.head exp.head
+'
+
+test_expect_success GZIP 'push gzipped truncated' '
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive push_body.gz.trunc &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success GZIP 'push gzipped empty' '
+       test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive empty_body &&
+       ! verify_http_result "200 OK"
+'
+
+test_expect_success 'CONTENT_LENGTH overflow ssite_t' '
+       NOT_FIT_IN_SSIZE=$(ssize_b100dots) &&
+       env \
+               CONTENT_TYPE=application/x-git-upload-pack-request \
+               QUERY_STRING=/repo.git/git-upload-pack \
+               PATH_TRANSLATED="$PWD"/.git/git-upload-pack \
+               GIT_HTTP_EXPORT_ALL=TRUE \
+               REQUEST_METHOD=POST \
+               CONTENT_LENGTH="$NOT_FIT_IN_SSIZE" \
+               git http-backend </dev/zero >/dev/null 2>err &&
+       grep "fatal:.*CONTENT_LENGTH" err
+'
+
+test_done
diff --git a/t/t5562/invoke-with-content-length.pl b/t/t5562/invoke-with-content-length.pl
new file mode 100755 (executable)
index 0000000..6c2aae7
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+use 5.008;
+use strict;
+use warnings;
+
+my $body_filename = $ARGV[0];
+my @command = @ARGV[1 .. $#ARGV];
+
+# read data
+my $body_size = -s $body_filename;
+$ENV{"CONTENT_LENGTH"} = $body_size;
+open(my $body_fh, "<", $body_filename) or die "Cannot open $body_filename: $!";
+my $body_data;
+defined read($body_fh, $body_data, $body_size) or die "Cannot read $body_filename: $!";
+close($body_fh);
+
+my $exited = 0;
+$SIG{"CHLD"} = sub {
+        $exited = 1;
+};
+
+# write data
+my $pid = open(my $out, "|-", @command);
+{
+        # disable buffering at $out
+        my $old_selected = select;
+        select $out;
+        $| = 1;
+        select $old_selected;
+}
+print $out $body_data or die "Cannot write data: $!";
+
+sleep 60; # is interrupted by SIGCHLD
+if (!$exited) {
+        close($out);
+        die "Command did not exit after reading whole body";
+}
index fac5a738519fe4aec0c3b2328c410db693c11f63..5582b3d5fd7118398bad00e43864d9e73c055f01 100755 (executable)
@@ -97,8 +97,7 @@ test_expect_success 'clone with --no-tags' '
                git fetch &&
                git for-each-ref refs/tags >../actual
        ) &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success '--single-branch while HEAD pointing at master' '
@@ -140,8 +139,7 @@ test_expect_success '--single-branch while HEAD pointing at master and --no-tags
                git fetch &&
                git for-each-ref refs/tags >../actual
        ) &&
-       >expect &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
        test_line_count = 0 actual &&
        # get tags with --tags overrides tagOpt
        (
@@ -230,8 +228,7 @@ test_expect_success '--single-branch with detached' '
                    -e "s|/remotes/origin/|/heads/|" >../actual
        ) &&
        # nothing
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_done
index 969e4e9e5261640dc690806ed06f8e58e760633f..fb4d295aa0f17c6aa967555ed92b4bc02884a9b3 100755 (executable)
@@ -58,8 +58,7 @@ test_expect_success 'rev-list A..B and rev-list ^A B are the same' '
 
 test_expect_success 'propagate uninteresting flag down correctly' '
        git rev-list --objects ^HEAD^{tree} HEAD^{tree} >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'symleft flag bit is propagated down from tag' '
index 20e3e2554a132552b5e398a2c449cedbef6ccb1e..916d9692bc05fdc87b28b7dbd4afdb173dd1d244 100755 (executable)
@@ -31,8 +31,7 @@ test_expect_success setup '
 test_expect_success 'one is ancestor of others and should not be shown' '
 
        git rev-list one --not four >result &&
-       >expect &&
-       test_cmp expect result
+       test_must_be_empty result
 
 '
 
@@ -144,8 +143,7 @@ test_expect_success 'ancestors with the same commit time' '
                test_commit t$i
        done &&
        git rev-list t1^! --not t$i >result &&
-       >expect &&
-       test_cmp expect result
+       test_must_be_empty result
 '
 
 test_done
index d3453c583c1921a10409c16b5e2cf949edde6cd2..02936c2f24aeaa3961bc11c623b7fd25d3280c43 100755 (executable)
@@ -256,31 +256,27 @@ test_expect_success 'rev-list accumulates multiple --exclude' '
 '
 
 test_expect_failure 'rev-list should succeed with empty output on empty stdin' '
-       >expect &&
        git rev-list --stdin <expect >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'rev-list should succeed with empty output with all refs excluded' '
-       >expect &&
        git rev-list --exclude=* --all >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'rev-list should succeed with empty output with empty --all' '
        (
                test_create_repo empty &&
                cd empty &&
-               >expect &&
                git rev-list --all >actual &&
-               test_cmp expect actual
+               test_must_be_empty actual
        )
 '
 
 test_expect_success 'rev-list should succeed with empty output with empty glob' '
-       >expect &&
        git rev-list --glob=does-not-match-anything >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
index dabebaee0b7b474387d4bc9b466b969624822d6d..beadaf6cca054bc2d821be19b4358286c6107165 100755 (executable)
@@ -95,10 +95,9 @@ test_expect_success 'rev-list --ancestry-path F...I' '
 
 # G.t is dropped in an "-s ours" merge
 test_expect_success 'rev-list G..M -- G.t' '
-       >expect &&
        git rev-list --format=%s G..M -- G.t |
        sed -e "/^commit /d" >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'rev-list --ancestry-path G..M -- G.t' '
index 2af1beec5f6f330072b3739e3c8b855f988173a9..46b506b3b7b6f6308994082abda2fcaddaaadf0e 100755 (executable)
@@ -89,9 +89,6 @@ test_expect_success 'modify/delete + directory/file conflict' '
 '
 
 test_expect_success 'modify/delete + directory/file conflict; other way' '
-       # Yes, we really need the double reset since "letters" appears as
-       # both a file and a directory.
-       git reset --hard &&
        git reset --hard &&
        git clean -f &&
        git checkout modify^0 &&
index b760c223c6a56609b7dace5353671aec8243b85d..53cc9b2ffbdbc551c358c8d5d1d4185ef63f0c0b 100755 (executable)
@@ -893,8 +893,7 @@ test_expect_success 'do not follow renames for empty files' '
        git mv empty1 empty2 &&
        git commit -m rename &&
        test_must_fail git merge empty-base &&
-       >expect &&
-       test_cmp expect empty2
+       test_must_be_empty empty2
 '
 
 test_done
index 7d5bc784721411a3abe475a8ed9f291204072b7d..793f0c8bf38aba350542c0710f509a1c69b33a9b 100755 (executable)
@@ -29,6 +29,34 @@ test_expect_success 'subtree available and works like recursive' '
 
 '
 
+test_expect_success 'setup branch sub' '
+       git checkout --orphan sub &&
+       git rm -rf . &&
+       test_commit foo
+'
+
+test_expect_success 'setup branch main' '
+       git checkout -b main master &&
+       git merge -s ours --no-commit --allow-unrelated-histories sub &&
+       git read-tree --prefix=dir/ -u sub &&
+       git commit -m "initial merge of sub into main" &&
+       test_path_is_file dir/foo.t &&
+       test_path_is_file hello
+'
+
+test_expect_success 'update branch sub' '
+       git checkout sub &&
+       test_commit bar
+'
+
+test_expect_success 'update branch main' '
+       git checkout main &&
+       git merge -s subtree sub -m "second merge of sub into main" &&
+       test_path_is_file dir/bar.t &&
+       test_path_is_file dir/foo.t &&
+       test_path_is_file hello
+'
+
 test_expect_success 'setup' '
        mkdir git-gui &&
        cd git-gui &&
index 07dd09d985fad600c6f21d335ccfb30e3626db13..b97aca7fa263f79520013b14d90fa0b49031484b 100755 (executable)
@@ -323,7 +323,6 @@ test_expect_success 'rename/directory conflict + content merge conflict' '
        (
                cd rename-directory-1 &&
 
-               git reset --hard &&
                git reset --hard &&
                git clean -fdqx &&
 
index debadbd299c02630097a3f476729719d4d71a10c..ddf34f0115b08b401a8981099459d10e1b1c4a02 100755 (executable)
@@ -44,8 +44,7 @@ test_expect_success 'read-tree does not resolve content merge' '
 test_expect_success 'git merge-index git-merge-one-file resolves' '
        git merge-index git-merge-one-file -a &&
        git diff-files --name-only --diff-filter=U >unmerged &&
-       >expect &&
-       test_cmp expect unmerged &&
+       test_must_be_empty unmerged &&
        test_cmp expect-merged file &&
        git cat-file blob :file >file-index &&
        test_cmp expect-merged file-index
index e0496da812f34df16ef7c3417788f9096ddc1e0f..024f8c06f7c58a424204d6fca69021ace2de3cbf 100755 (executable)
@@ -796,9 +796,8 @@ test_expect_success ':remotename and :remoteref' '
 '
 
 test_expect_success 'for-each-ref --ignore-case ignores case' '
-       >expect &&
        git for-each-ref --format="%(refname)" refs/heads/MASTER >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        echo refs/heads/master >expect &&
        git for-each-ref --format="%(refname)" --ignore-case \
index 2147938aa1b60d8b67557e0bbe3c0368ef712b69..465eb4ea3f973943367b1c8b2e560d1b16b3c31b 100755 (executable)
@@ -693,9 +693,8 @@ test_expect_success \
 '
 
 test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
-       >expect &&
        git tag -n 100 >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        git tag -m "A msg" 100 &&
        echo "100             A msg" >expect &&
@@ -974,9 +973,8 @@ test_expect_success GPG 'verifying a proper tag with --format pass and format ac
 '
 
 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
-       >expect &&
        test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 # blank and empty messages for signed tags:
@@ -1395,9 +1393,8 @@ test_expect_success 'message in editor has initial comment: first line' '
 test_expect_success \
        'message in editor has initial comment: remainder' '
        # remove commented lines from the remainder -- should be empty
-       >rest.expect &&
        sed -e 1d -e "/^#/d" <actual >rest.actual &&
-       test_cmp rest.expect rest.actual
+       test_must_be_empty rest.actual
 '
 
 get_tag_header reuse $commit commit $time >expect
@@ -1479,19 +1476,18 @@ test_expect_success 'checking that first commit is in all tags (relative)' "
 
 # All the --contains tests above, but with --no-contains
 test_expect_success 'checking that first commit is not listed in any tag with --no-contains  (hash)' "
-       >expected &&
        git tag -l --no-contains $hash1 v* >actual &&
-       test_cmp expected actual
+       test_must_be_empty actual
 "
 
 test_expect_success 'checking that first commit is in all tags (tag)' "
        git tag -l --no-contains v1.0 v* >actual &&
-       test_cmp expected actual
+       test_must_be_empty actual
 "
 
 test_expect_success 'checking that first commit is in all tags (relative)' "
        git tag -l --no-contains HEAD~2 v* >actual &&
-       test_cmp expected actual
+       test_must_be_empty actual
 "
 
 cat > expected <<EOF
@@ -1619,9 +1615,8 @@ test_expect_success 'checking that --contains can be used in non-list mode' '
 '
 
 test_expect_success 'checking that initial commit is in all tags with --no-contains' "
-       >expected &&
        git tag -l --no-contains $hash1 v* >actual &&
-       test_cmp expected actual
+       test_must_be_empty actual
 "
 
 # mixing modes and options:
@@ -1918,7 +1913,6 @@ test_expect_success 'version sort with very long prerelease suffix' '
 '
 
 test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
-       >expect &&
        i=1 &&
        while test $i -lt 8000
        do
@@ -1933,7 +1927,7 @@ EOF"
        git checkout master &&
        git tag far-far-away HEAD^ &&
        run_with_limited_stack git tag --contains HEAD >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
        run_with_limited_stack git tag --no-contains HEAD >actual &&
        test_line_count "-gt" 10 actual
 '
index 7541ba5edbcae1f1555c367b7f8bfc795913ff60..00e09a375c2e6e3bfce2c2f8ce93493513082b2d 100755 (executable)
@@ -626,12 +626,11 @@ test_expect_success TTY 'sub-commands of externals use their own pager' '
 
 test_expect_success TTY 'external command pagers override sub-commands' '
        sane_unset PAGER GIT_PAGER &&
-       >expect &&
        >actual &&
        test_config pager.external false &&
        test_config pager.log "sed s/^/log:/ >actual" &&
        test_terminal git --exec-path=. external log --format=%s -1 &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'command with underscores does not complain' '
index 99f35a5bbe47aff93121c5e6beeec2dce00d18be..041e319e79aacb74ea9ec8fc20a38cc222961b6e 100755 (executable)
@@ -168,9 +168,8 @@ test_expect_success GPG 'verifying tag with --format' '
 '
 
 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
-       >expect &&
        test_must_fail git verify-tag --format="tagname : %(tag)" $(cat forged1.tag) >actual-forged &&
-       test_cmp expect actual-forged
+       test_must_be_empty actual-forged
 '
 
 test_done
index c9162c54f4ceab56cd9fbbb455f3030cc7ae60d9..2da57fce7b12bd9a2cfac38ba4d98fc9c4af1a4c 100755 (executable)
@@ -26,9 +26,8 @@ avoid_racy() {
 }
 
 status_is_clean() {
-       >../status.expect &&
        git status --porcelain >../status.actual &&
-       test_cmp ../status.expect ../status.actual
+       test_must_be_empty ../status.actual
 }
 
 test_lazy_prereq UNTRACKED_CACHE '
index 95653a08cade25fb6edd7dcc479fb102d800f534..97be0d968dbcedba226b39862faddd23da39d863 100755 (executable)
@@ -549,8 +549,7 @@ test_expect_success 'reset -N keeps removed files as intent-to-add' '
 
        tree=$(git write-tree) &&
        git ls-tree $tree new-file >actual &&
-       >expect &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
 
        git diff --name-only >actual &&
        echo new-file >expect &&
@@ -563,9 +562,8 @@ test_expect_success 'reset --mixed sets up work tree' '
                cd mixed_worktree &&
                test_commit dummy
        ) &&
-       : >expect &&
        git --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_done
index 0f95f004777ac3db191264fc5760c17bc1bdf77b..ecb85c3b823275efc68fb64643a4304a3cbf28b2 100755 (executable)
@@ -12,9 +12,8 @@ test_expect_success 'reset' '
        git add a b &&
        git reset &&
 
-       >expect &&
        git ls-files >actual &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'reset HEAD' '
@@ -39,9 +38,8 @@ test_expect_success PERL 'reset -p' '
        echo y >yes &&
        git reset -p <yes >output &&
 
-       >expect &&
        git ls-files >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
        test_i18ngrep "Unstage" output
 '
 
@@ -61,9 +59,8 @@ test_expect_success 'reset --hard' '
        test_when_finished "echo a >a" &&
        git reset --hard &&
 
-       >expect &&
        git ls-files >actual &&
-       test_cmp expect actual &&
+       test_must_be_empty actual &&
        test_path_is_missing a
 '
 
index 4e4c45550262ca75b36d15e80aa1f4bffc45465f..1cd12b38c53c7fdfedb937151d961527aa990dbd 100755 (executable)
@@ -64,8 +64,7 @@ test_expect_success 'added submodule (subdirectory only)' "
                cd sub &&
                git submodule summary . >../actual
        ) &&
-       >expected &&
-       test_cmp expected actual
+       test_must_be_empty actual
 "
 
 test_expect_success 'added submodule (subdirectory with explicit path)' "
index 686e6a439ec705e681ec7d4e58808e0d51ecd777..10dc91620a69870ab5dac213d032ae5d9938128c 100755 (executable)
@@ -175,7 +175,7 @@ test_expect_success 'submodule update does not fetch already present commits' '
          git submodule update > ../actual 2> ../actual.err
        ) &&
        test_i18ncmp expected actual &&
-       ! test -s actual.err
+       test_must_be_empty actual.err
 '
 
 test_expect_success 'submodule update should fail due to local changes' '
@@ -482,7 +482,8 @@ test_expect_success 'recursive submodule update - command in .git/config catches
 
 test_expect_success 'submodule init does not copy command into .git/config' '
        (cd super &&
-        H=$(git ls-files -s submodule | cut -d" " -f2) &&
+        git ls-files -s submodule >out &&
+        H=$(cut -d" " -f2 out) &&
         mkdir submodule1 &&
         git update-index --add --cacheinfo 160000 $H submodule1 &&
         git config -f .gitmodules submodule.submodule1.path submodule1 &&
@@ -580,9 +581,11 @@ test_expect_success 'submodule update - update=none in .git/config' '
          git checkout master &&
          compare_head
         ) &&
-        git diff --raw | grep "        submodule" &&
+        git diff --name-only >out &&
+        grep ^submodule$ out &&
         git submodule update &&
-        git diff --raw | grep "        submodule" &&
+        git diff --name-only >out &&
+        grep ^submodule$ out &&
         (cd submodule &&
          compare_head
         ) &&
@@ -598,11 +601,13 @@ test_expect_success 'submodule update - update=none in .git/config but --checkou
          git checkout master &&
          compare_head
         ) &&
-        git diff --raw | grep "        submodule" &&
+        git diff --name-only >out &&
+        grep ^submodule$ out &&
         git submodule update --checkout &&
-        test_must_fail git diff --raw \| grep "        submodule" &&
+        git diff --name-only >out &&
+        ! grep ^submodule$ out &&
         (cd submodule &&
-         test_must_fail compare_head
+         ! compare_head
         ) &&
         git config --unset submodule.submodule.update
        )
@@ -616,8 +621,8 @@ test_expect_success 'submodule update --init skips submodule with update=none' '
        git clone super cloned &&
        (cd cloned &&
         git submodule update --init &&
-        test -e submodule/.git &&
-        test_must_fail test -e none/.git
+        test_path_exists submodule/.git &&
+        test_path_is_missing none/.git
        )
 '
 
@@ -886,7 +891,8 @@ test_expect_success 'submodule update properly revives a moved submodule' '
         H=$(git rev-parse --short HEAD) &&
         git commit -am "pre move" &&
         H2=$(git rev-parse --short HEAD) &&
-        git status | sed "s/$H/XXX/" >expect &&
+        git status >out &&
+        sed "s/$H/XXX/" out >expect &&
         H=$(cd submodule2 && git rev-parse HEAD) &&
         git rm --cached submodule2 &&
         rm -rf submodule2 &&
@@ -895,7 +901,8 @@ test_expect_success 'submodule update properly revives a moved submodule' '
         git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
         git commit -am "post move" &&
         git submodule update &&
-        git status | sed "s/$H2/XXX/" >actual &&
+        git status > out &&
+        sed "s/$H2/XXX/" out >actual &&
         test_cmp expect actual
        )
 '
@@ -913,7 +920,7 @@ test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd'
 
 test_expect_success 'submodule update clone shallow submodule' '
        test_when_finished "rm -rf super3" &&
-       first=$(git -C cloned submodule status submodule |cut -c2-41) &&
+       first=$(git -C cloned rev-parse HEAD:submodule) &&
        second=$(git -C submodule rev-parse HEAD) &&
        commit_count=$(git -C submodule rev-list --count $first^..$second) &&
        git clone cloned super3 &&
@@ -923,7 +930,8 @@ test_expect_success 'submodule update clone shallow submodule' '
                sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
                mv -f .gitmodules.tmp .gitmodules &&
                git submodule update --init --depth=$commit_count &&
-               test 1 = $(git -C submodule log --oneline | wc -l)
+               git -C submodule log --oneline >out &&
+               test_line_count = 1 out
        )
 '
 
@@ -939,7 +947,8 @@ test_expect_success 'submodule update clone shallow submodule outside of depth'
                test_i18ngrep "Direct fetching of that commit failed." actual &&
                git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
                git submodule update --init --depth=1 >actual &&
-               test 1 = $(git -C submodule log --oneline | wc -l)
+               git -C submodule log --oneline >out &&
+               test_line_count = 1 out
        )
 '
 
index d33a3cb331b6c022343aff0bb7091cf8219b40df..ca4a740da0258b5522f29051c3d18632d1bafa1b 100755 (executable)
@@ -393,7 +393,6 @@ EOF
 
 test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '
        >.git/result &&
-       >expect &&
 
        echo >>negative &&
        (
@@ -403,7 +402,7 @@ test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '
                export GIT_EDITOR &&
                test_must_fail git commit -e -m sample -a
        ) &&
-       test_cmp expect .git/result
+       test_must_be_empty .git/result
 '
 
 test_expect_success 'do not fire editor if -m <msg> was given' '
index 047156e9d51141a97ad71687c6da036b5ce76548..b18503de8158aa6583423f923675d415ab408e76 100755 (executable)
@@ -620,8 +620,7 @@ test_expect_success 'file with no base' '
        git checkout -b test$test_count branch1 &&
        test_must_fail git merge master &&
        git mergetool --no-prompt --tool mybase -- both &&
-       >expected &&
-       test_cmp expected both
+       test_must_be_empty both
 '
 
 test_expect_success 'custom commands override built-ins' '
index dcaab1557b4082adbd2507d1ca4beba629723022..d826e24b45118d4b87a2723f540c742ac6300f44 100755 (executable)
@@ -691,8 +691,7 @@ test_expect_success 'log grep (5)' '
 
 test_expect_success 'log grep (6)' '
        git log --author=-0700  --pretty=tformat:%s >actual &&
-       >expect &&
-       test_cmp expect actual
+       test_must_be_empty actual
 '
 
 test_expect_success 'log grep (7)' '
index b8e919e25d6b4def87a6d66db32b94e8813b1cd7..1ef1a19003db5c9be94197e9d6cb25110591705b 100755 (executable)
@@ -253,10 +253,9 @@ test_suppress_self () {
 
        mv msgtxt1 msgtxt1-$3 &&
        sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
-       >"expected-no-cc-$3" &&
 
        (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
-        test_cmp expected-no-cc-$3 actual-no-cc-$3)
+        test_must_be_empty actual-no-cc-$3)
 }
 
 test_suppress_self_unquoted () {
index fac33e524c760c5dedc908c02e2efc185eeed92a..40fe7e49767ac4e0bbe5686413ff2b667171747a 100755 (executable)
@@ -2191,12 +2191,11 @@ test_expect_success 'R: --import-marks-if-exists' '
 
 test_expect_success 'R: feature import-marks-if-exists' '
        rm -f io.marks &&
-       >expect &&
 
        git fast-import --export-marks=io.marks <<-\EOF &&
        feature import-marks-if-exists=not_io.marks
        EOF
-       test_cmp expect io.marks &&
+       test_must_be_empty io.marks &&
 
        blob=$(echo hi | git hash-object --stdin) &&
 
@@ -2227,13 +2226,11 @@ test_expect_success 'R: feature import-marks-if-exists' '
        EOF
        test_cmp expect io.marks &&
 
-       >expect &&
-
        git fast-import --import-marks-if-exists=not_io.marks \
                        --export-marks=io.marks <<-\EOF &&
        feature import-marks-if-exists=io.marks
        EOF
-       test_cmp expect io.marks
+       test_must_be_empty io.marks
 '
 
 test_expect_success 'R: import to output marks works without any content' '
index 5ff43b9cbbe1693ac23ac7f020522d16424cb936..175f83d7042a0fb9f093bc6f25e1d0b25ce548af 100755 (executable)
@@ -1278,7 +1278,7 @@ test_expect_success 'setup for path completion tests' '
           touch BS\\dir/DQ\"file \
                 '$'separators\034in\035dir/sep\036in\037file''
        then
-               test_set_prereq FUNNYNAMES
+               test_set_prereq FUNNIERNAMES
        else
                rm -rf BS\\dir '$'separators\034in\035dir''
        fi
@@ -1320,7 +1320,7 @@ test_expect_success '__git_complete_index_file - UTF-8 in ls-files output' '
        test_path_completion árvíztűrő/С "árvíztűrő/Сайн яваарай"
 '
 
-test_expect_success FUNNYNAMES \
+test_expect_success FUNNIERNAMES \
     '__git_complete_index_file - C-style escapes in ls-files output' '
        test_path_completion BS \
                             BS\\dir &&
@@ -1332,7 +1332,7 @@ test_expect_success FUNNYNAMES \
                             BS\\dir/DQ\"file
 '
 
-test_expect_success FUNNYNAMES \
+test_expect_success FUNNIERNAMES \
     '__git_complete_index_file - \nnn-escaped characters in ls-files output' '
        test_path_completion sep '$'separators\034in\035dir'' &&
        test_path_completion '$'separators\034i'' \
index 04440685a66d6baff98c1739979c8f866255572b..ab890d3d4b3e2a39bb787bd29d7865c46f64c7f6 100755 (executable)
@@ -63,18 +63,15 @@ test_expect_success 'prompt - unborn branch' '
        test_cmp expected "$actual"
 '
 
-repo_with_newline='repo
-with
-newline'
-
-if test_have_prereq !MINGW && mkdir "$repo_with_newline" 2>/dev/null
-then
-       test_set_prereq FUNNYNAMES
-else
+if test_have_prereq !FUNNYNAMES; then
        say 'Your filesystem does not allow newlines in filenames.'
 fi
 
 test_expect_success FUNNYNAMES 'prompt - with newline in path' '
+    repo_with_newline="repo
+with
+newline" &&
+       mkdir "$repo_with_newline" &&
        printf " (master)" >expected &&
        git init "$repo_with_newline" &&
        test_when_finished "rm -rf \"$repo_with_newline\"" &&
index 2b2181dca09089ed36d10ee8f6f67eedda8cf352..4207af40777c69365dc395e800a7e4214beab076 100644 (file)
@@ -565,6 +565,14 @@ test_path_is_dir () {
        fi
 }
 
+test_path_exists () {
+       if ! test -e "$1"
+       then
+               echo "Path $1 doesn't exist. $2"
+               false
+       fi
+}
+
 # Check if the directory exists and is empty as expected, barf otherwise.
 test_dir_is_empty () {
        test_path_is_dir "$1" &&
index 78f7097746fc88f1de5321e5f78d9aec8c5e0b5f..8bb0f4348e94037ab8877fdb0389bde5a11a86e3 100644 (file)
@@ -1104,6 +1104,20 @@ test_lazy_prereq CASE_INSENSITIVE_FS '
        test "$(cat CamelCase)" != good
 '
 
+test_lazy_prereq FUNNYNAMES '
+       test_have_prereq !MINGW &&
+       touch -- \
+               "FUNNYNAMES tab embedded" \
+               "FUNNYNAMES \"quote embedded\"" \
+               "FUNNYNAMES newline
+embedded" 2>/dev/null &&
+       rm -- \
+               "FUNNYNAMES tab embedded" \
+               "FUNNYNAMES \"quote embedded\"" \
+               "FUNNYNAMES newline
+embedded" 2>/dev/null
+'
+
 test_lazy_prereq UTF8_NFD_TO_NFC '
        # check whether FS converts nfd unicode to nfc
        auml=$(printf "\303\244")
index 8959c5f1b5761dc34f1742a96941f67efd6429a7..36434eb6fa64721bcafdb40db5f9e7d0400a50b4 100644 (file)
@@ -2,6 +2,7 @@
 #define TEMPFILE_H
 
 #include "list.h"
+#include "strbuf.h"
 
 /*
  * Handle temporary files.
index 6d7f8c2a52305d3d937b69a877f1ae0b7af94363..9c10026c358326ce0c0098ca52341ce8160c5bbe 100644 (file)
--- a/trailer.h
+++ b/trailer.h
@@ -3,6 +3,8 @@
 
 #include "list.h"
 
+struct strbuf;
+
 enum trailer_where {
        WHERE_DEFAULT,
        WHERE_END,
index 805f58f00f6f0d4c9e6f6f05520bd1cd62d5f661..196831007e618f808661bf4b7f54030890f48563 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef TREE_WALK_H
 #define TREE_WALK_H
 
+struct strbuf;
+
 struct name_entry {
        const struct object_id *oid;
        const char *path;
index f9efee0836a20e7072477ae0f3de7c9e1a29ff78..f25089b878a8b0842a9d6407cb6b1821867a737c 100644 (file)
@@ -353,7 +353,7 @@ static int check_updates(struct unpack_trees_options *o)
        progress = get_progress(o);
 
        if (o->update)
-               git_attr_set_direction(GIT_ATTR_CHECKOUT, index);
+               git_attr_set_direction(GIT_ATTR_CHECKOUT);
 
        if (should_update_submodules() && o->update && !o->dry_run)
                load_gitmodules_file(index, NULL);
@@ -413,7 +413,7 @@ static int check_updates(struct unpack_trees_options *o)
        stop_progress(&progress);
        errs |= finish_delayed_checkout(&state);
        if (o->update)
-               git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);
+               git_attr_set_direction(GIT_ATTR_CHECKIN);
        return errs != 0;
 }
 
@@ -1092,13 +1092,15 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
        return mask;
 }
 
-static int clear_ce_flags_1(struct cache_entry **cache, int nr,
+static int clear_ce_flags_1(struct index_state *istate,
+                           struct cache_entry **cache, int nr,
                            struct strbuf *prefix,
                            int select_mask, int clear_mask,
                            struct exclude_list *el, int defval);
 
 /* Whole directory matching */
-static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
+static int clear_ce_flags_dir(struct index_state *istate,
+                             struct cache_entry **cache, int nr,
                              struct strbuf *prefix,
                              char *basename,
                              int select_mask, int clear_mask,
@@ -1107,7 +1109,7 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
        struct cache_entry **cache_end;
        int dtype = DT_DIR;
        int ret = is_excluded_from_list(prefix->buf, prefix->len,
-                                       basename, &dtype, el, &the_index);
+                                       basename, &dtype, el, istate);
        int rc;
 
        strbuf_addch(prefix, '/');
@@ -1129,7 +1131,7 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
         * calling clear_ce_flags_1(). That function will call
         * the expensive is_excluded_from_list() on every entry.
         */
-       rc = clear_ce_flags_1(cache, cache_end - cache,
+       rc = clear_ce_flags_1(istate, cache, cache_end - cache,
                              prefix,
                              select_mask, clear_mask,
                              el, ret);
@@ -1152,7 +1154,8 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
  *   cache[0]->name[0..(prefix_len-1)]
  * Top level path has prefix_len zero.
  */
-static int clear_ce_flags_1(struct cache_entry **cache, int nr,
+static int clear_ce_flags_1(struct index_state *istate,
+                           struct cache_entry **cache, int nr,
                            struct strbuf *prefix,
                            int select_mask, int clear_mask,
                            struct exclude_list *el, int defval)
@@ -1186,7 +1189,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
                        len = slash - name;
                        strbuf_add(prefix, name, len);
 
-                       processed = clear_ce_flags_dir(cache, cache_end - cache,
+                       processed = clear_ce_flags_dir(istate, cache, cache_end - cache,
                                                       prefix,
                                                       prefix->buf + prefix->len - len,
                                                       select_mask, clear_mask,
@@ -1200,7 +1203,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
                        }
 
                        strbuf_addch(prefix, '/');
-                       cache += clear_ce_flags_1(cache, cache_end - cache,
+                       cache += clear_ce_flags_1(istate, cache, cache_end - cache,
                                                  prefix,
                                                  select_mask, clear_mask, el, defval);
                        strbuf_setlen(prefix, prefix->len - len - 1);
@@ -1210,7 +1213,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
                /* Non-directory */
                dtype = ce_to_dtype(ce);
                ret = is_excluded_from_list(ce->name, ce_namelen(ce),
-                                           name, &dtype, el, &the_index);
+                                           name, &dtype, el, istate);
                if (ret < 0)
                        ret = defval;
                if (ret > 0)
@@ -1220,15 +1223,17 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
        return nr - (cache_end - cache);
 }
 
-static int clear_ce_flags(struct cache_entry **cache, int nr,
-                           int select_mask, int clear_mask,
-                           struct exclude_list *el)
+static int clear_ce_flags(struct index_state *istate,
+                         int select_mask, int clear_mask,
+                         struct exclude_list *el)
 {
        static struct strbuf prefix = STRBUF_INIT;
 
        strbuf_reset(&prefix);
 
-       return clear_ce_flags_1(cache, nr,
+       return clear_ce_flags_1(istate,
+                               istate->cache,
+                               istate->cache_nr,
                                &prefix,
                                select_mask, clear_mask,
                                el, 0);
@@ -1238,7 +1243,7 @@ static int clear_ce_flags(struct cache_entry **cache, int nr,
  * Set/Clear CE_NEW_SKIP_WORKTREE according to $GIT_DIR/info/sparse-checkout
  */
 static void mark_new_skip_worktree(struct exclude_list *el,
-                                  struct index_state *the_index,
+                                  struct index_state *istate,
                                   int select_flag, int skip_wt_flag)
 {
        int i;
@@ -1247,8 +1252,8 @@ static void mark_new_skip_worktree(struct exclude_list *el,
         * 1. Pretend the narrowest worktree: only unmerged entries
         * are checked out
         */
-       for (i = 0; i < the_index->cache_nr; i++) {
-               struct cache_entry *ce = the_index->cache[i];
+       for (i = 0; i < istate->cache_nr; i++) {
+               struct cache_entry *ce = istate->cache[i];
 
                if (select_flag && !(ce->ce_flags & select_flag))
                        continue;
@@ -1263,8 +1268,7 @@ static void mark_new_skip_worktree(struct exclude_list *el,
         * 2. Widen worktree according to sparse-checkout file.
         * Matched entries will have skip_wt_flag cleared (i.e. "in")
         */
-       clear_ce_flags(the_index->cache, the_index->cache_nr,
-                      select_flag, skip_wt_flag, el);
+       clear_ce_flags(istate, select_flag, skip_wt_flag, el);
 }
 
 static int verify_absent(const struct cache_entry *,
@@ -1552,6 +1556,17 @@ static int verify_uptodate_sparse(const struct cache_entry *ce,
        return verify_uptodate_1(ce, o, ERROR_SPARSE_NOT_UPTODATE_FILE);
 }
 
+/*
+ * TODO: We should actually invalidate o->result, not src_index [1].
+ * But since cache tree and untracked cache both are not copied to
+ * o->result until unpacking is complete, we invalidate them on
+ * src_index instead with the assumption that they will be copied to
+ * dst_index at the end.
+ *
+ * [1] src_index->cache_tree is also used in unpack_callback() so if
+ * we invalidate o->result, we need to update it to use
+ * o->result.cache_tree as well.
+ */
 static void invalidate_ce_path(const struct cache_entry *ce,
                               struct unpack_trees_options *o)
 {
@@ -1643,7 +1658,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
        memset(&d, 0, sizeof(d));
        if (o->dir)
                d.exclude_per_dir = o->dir->exclude_per_dir;
-       i = read_directory(&d, &the_index, pathbuf, namelen+1, NULL);
+       i = read_directory(&d, o->src_index, pathbuf, namelen+1, NULL);
        if (i)
                return o->gently ? -1 :
                        add_rejected_path(o, ERROR_NOT_UPTODATE_DIR, ce->name);
@@ -1685,7 +1700,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
                return 0;
 
        if (o->dir &&
-           is_excluded(o->dir, &the_index, name, &dtype))
+           is_excluded(o->dir, o->src_index, name, &dtype))
                /*
                 * ce->name is explicitly excluded, so it is Ok to
                 * overwrite it.
index c2b434c60648fb0e287c100a32d9346a765ab74f..847f217dbaecea678f48d5086e7099c3c24a53c4 100644 (file)
@@ -1,11 +1,14 @@
 #ifndef UNPACK_TREES_H
 #define UNPACK_TREES_H
 
-#include "tree-walk.h"
+#include "cache.h"
 #include "argv-array.h"
+#include "string-list.h"
+#include "tree-walk.h"
 
 #define MAX_UNPACK_TREES 8
 
+struct cache_entry;
 struct unpack_trees_options;
 struct exclude_list;
 
@@ -82,8 +85,8 @@ struct unpack_trees_options {
        struct exclude_list *el; /* for internal use */
 };
 
-extern int unpack_trees(unsigned n, struct tree_desc *t,
-               struct unpack_trees_options *options);
+int unpack_trees(unsigned n, struct tree_desc *t,
+                struct unpack_trees_options *options);
 
 int verify_uptodate(const struct cache_entry *ce,
                    struct unpack_trees_options *o);
diff --git a/url.h b/url.h
index abdaf6fa30b68767f48b056c977e498f9cfe7de2..f311c40a4680bfedf0ad2d511a5599fb5dcabd6e 100644 (file)
--- a/url.h
+++ b/url.h
@@ -1,6 +1,8 @@
 #ifndef URL_H
 #define URL_H
 
+struct strbuf;
+
 extern int is_url(const char *url);
 extern int is_urlschemechar(int first_flag, int ch);
 extern char *url_decode(const char *url);
index 37ee5da85e2dd3f0ba3ee12d0c515fa6def2a043..e482148248d2dac64656bd9a66af0bd6224ea929 100644 (file)
@@ -1,4 +1,6 @@
 #ifndef URL_MATCH_H
+#define URL_MATCH_H
+
 #include "string-list.h"
 
 struct url_info {
index 36af25e7f9f4693b196320f56bb0546d7dd2986a..f3f4be579c9810d0fcf94badd4bf21770b99c91b 100644 (file)
@@ -278,7 +278,7 @@ struct userdiff_driver *userdiff_find_by_path(const char *path)
                check = attr_check_initl("diff", NULL);
        if (!path)
                return NULL;
-       if (git_check_attr(path, check))
+       if (git_check_attr(&the_index, path, check))
                return NULL;
 
        if (ATTR_TRUE(check->items[0].value))
diff --git a/utf8.h b/utf8.h
index ce1c2696e069782807354a846f2cfe075e1dfd5c..edea55e093a4713dcd0056da9a31b63f0cb51272 100644 (file)
--- a/utf8.h
+++ b/utf8.h
@@ -1,6 +1,8 @@
 #ifndef GIT_UTF8_H
 #define GIT_UTF8_H
 
+struct strbuf;
+
 typedef unsigned int ucs_char_t;  /* assuming 32bit int */
 
 size_t display_mode_esc_sequence_len(const char *s);
index fe38ce10c300ba456f406950bf960d19d5d79cce..df3fc30f73692d296fc875bf1944813fa7e1fb3a 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef WORKTREE_H
 #define WORKTREE_H
 
+#include "cache.h"
 #include "refs.h"
 
 struct strbuf;
diff --git a/ws.c b/ws.c
index a07caedd5a565bbf29e4f9b3036ac60e6e9f716e..5b67b426e7b41d92f9b11bd82fd7e9bd09c89d79 100644 (file)
--- a/ws.c
+++ b/ws.c
@@ -78,7 +78,7 @@ unsigned whitespace_rule(const char *pathname)
        if (!attr_whitespace_rule)
                attr_whitespace_rule = attr_check_initl("whitespace", NULL);
 
-       if (!git_check_attr(pathname, attr_whitespace_rule)) {
+       if (!git_check_attr(&the_index, pathname, attr_whitespace_rule)) {
                const char *value;
 
                value = attr_whitespace_rule->items[0].value;
index 6bf2fdbab67fffb4c9ef451b61bbc7ca8f6780ea..5ffab61015da908ed36b7ca6455f53fd42f1e292 100644 (file)
@@ -647,7 +647,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
                struct wt_status_change_data *d;
                const struct cache_entry *ce = active_cache[i];
 
-               if (!ce_path_match(ce, &s->pathspec, NULL))
+               if (!ce_path_match(&the_index, ce, &s->pathspec, NULL))
                        continue;
                if (ce_intent_to_add(ce))
                        continue;
@@ -703,7 +703,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
        for (i = 0; i < dir.nr; i++) {
                struct dir_entry *ent = dir.entries[i];
                if (cache_name_is_other(ent->name, ent->len) &&
-                   dir_path_match(ent, &s->pathspec, 0, NULL))
+                   dir_path_match(&the_index, ent, &s->pathspec, 0, NULL))
                        string_list_insert(&s->untracked, ent->name);
                free(ent);
        }
@@ -711,7 +711,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
        for (i = 0; i < dir.ignored_nr; i++) {
                struct dir_entry *ent = dir.ignored[i];
                if (cache_name_is_other(ent->name, ent->len) &&
-                   dir_path_match(ent, &s->pathspec, 0, NULL))
+                   dir_path_match(&the_index, ent, &s->pathspec, 0, NULL))
                        string_list_insert(&s->ignored, ent->name);
                free(ent);
        }
index 3e8aff92bc436ee99a698fdd748fb1845e28db8c..1f1f4a3c7808435f73b0ffd1c35d5b0572516b6c 100644 (file)
@@ -574,6 +574,11 @@ static void measure_split(const xdfile_t *xdf, long split,
  */
 #define INDENT_WEIGHT 60
 
+/*
+ * How far do we slide a hunk at most?
+ */
+#define INDENT_HEURISTIC_MAX_SLIDING 100
+
 /*
  * Compute a badness score for the hypothetical split whose measurements are
  * stored in m. The weight factors were determined empirically using the tools and
@@ -886,7 +891,12 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
                        long shift, best_shift = -1;
                        struct split_score best_score;
 
-                       for (shift = earliest_end; shift <= g.end; shift++) {
+                       shift = earliest_end;
+                       if (g.end - groupsize - 1 > shift)
+                               shift = g.end - groupsize - 1;
+                       if (g.end - INDENT_HEURISTIC_MAX_SLIDING > shift)
+                               shift = g.end - INDENT_HEURISTIC_MAX_SLIDING;
+                       for (; shift <= g.end; shift++) {
                                struct split_measurement m;
                                struct split_score score = {0, 0};