aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/CONTRIBUTING.md19
-rw-r--r--.github/PULL_REQUEST_TEMPLATE.md7
-rw-r--r--Documentation/RelNotes/2.13.2.txt17
-rw-r--r--Documentation/RelNotes/2.14.0.txt95
-rw-r--r--Documentation/config.txt17
-rw-r--r--Documentation/git-add.txt7
-rw-r--r--Documentation/git-fast-import.txt2
-rw-r--r--Documentation/git-filter-branch.txt17
-rw-r--r--Documentation/git-pull.txt2
-rw-r--r--Documentation/git-rebase.txt2
-rw-r--r--Documentation/git-reset.txt2
-rw-r--r--Documentation/git-stash.txt60
-rw-r--r--Documentation/git-status.txt3
-rw-r--r--Documentation/gitattributes.txt2
-rw-r--r--Documentation/gitcli.txt2
-rw-r--r--Documentation/glossary-content.txt4
-rw-r--r--Documentation/pretty-formats.txt4
-rw-r--r--Documentation/rev-list-options.txt3
-rw-r--r--Makefile3
-rw-r--r--advice.c3
-rw-r--r--advice.h1
-rw-r--r--alias.c35
-rw-r--r--apply.c17
-rw-r--r--archive-tar.c1
-rw-r--r--archive-zip.c1
-rw-r--r--archive.c1
-rw-r--r--attr.c7
-rw-r--r--bisect.c1
-rw-r--r--blame.c5
-rw-r--r--branch.c4
-rw-r--r--builtin/add.c47
-rw-r--r--builtin/am.c19
-rw-r--r--builtin/blame.c1
-rw-r--r--builtin/branch.c1
-rw-r--r--builtin/cat-file.c1
-rw-r--r--builtin/check-attr.c1
-rw-r--r--builtin/check-ignore.c1
-rw-r--r--builtin/check-mailmap.c1
-rw-r--r--builtin/checkout-index.c1
-rw-r--r--builtin/checkout.c1
-rw-r--r--builtin/clean.c7
-rw-r--r--builtin/clone.c1
-rw-r--r--builtin/column.c1
-rw-r--r--builtin/commit-tree.c1
-rw-r--r--builtin/commit.c11
-rw-r--r--builtin/config.c33
-rw-r--r--builtin/count-objects.c1
-rw-r--r--builtin/describe.c1
-rw-r--r--builtin/diff-files.c1
-rw-r--r--builtin/diff-index.c1
-rw-r--r--builtin/diff-tree.c1
-rw-r--r--builtin/diff.c1
-rw-r--r--builtin/difftool.c1
-rw-r--r--builtin/fast-export.c1
-rw-r--r--builtin/fetch.c1
-rw-r--r--builtin/fmt-merge-msg.c1
-rw-r--r--builtin/for-each-ref.c1
-rw-r--r--builtin/fsck.c1
-rw-r--r--builtin/gc.c1
-rw-r--r--builtin/grep.c1
-rw-r--r--builtin/hash-object.c1
-rw-r--r--builtin/help.c1
-rw-r--r--builtin/index-pack.c7
-rw-r--r--builtin/init-db.c1
-rw-r--r--builtin/log.c1
-rw-r--r--builtin/ls-files.c179
-rw-r--r--builtin/ls-tree.c1
-rw-r--r--builtin/merge-base.c1
-rw-r--r--builtin/merge-file.c1
-rw-r--r--builtin/merge.c1
-rw-r--r--builtin/mv.c1
-rw-r--r--builtin/name-rev.c1
-rw-r--r--builtin/notes.c1
-rw-r--r--builtin/pack-objects.c13
-rw-r--r--builtin/patch-id.c1
-rw-r--r--builtin/pull.c1
-rw-r--r--builtin/push.c1
-rw-r--r--builtin/read-tree.c1
-rw-r--r--builtin/rebase--helper.c1
-rw-r--r--builtin/receive-pack.c1
-rw-r--r--builtin/reflog.c1
-rw-r--r--builtin/remote.c1
-rw-r--r--builtin/repack.c1
-rw-r--r--builtin/replace.c1
-rw-r--r--builtin/rerere.c1
-rw-r--r--builtin/reset.c1
-rw-r--r--builtin/rev-list.c1
-rw-r--r--builtin/rev-parse.c1
-rw-r--r--builtin/revert.c1
-rw-r--r--builtin/rm.c1
-rw-r--r--builtin/send-pack.c1
-rw-r--r--builtin/shortlog.c1
-rw-r--r--builtin/show-branch.c14
-rw-r--r--builtin/stripspace.c1
-rw-r--r--builtin/submodule--helper.c1
-rw-r--r--builtin/symbolic-ref.c1
-rw-r--r--builtin/tag.c1
-rw-r--r--builtin/unpack-file.c1
-rw-r--r--builtin/unpack-objects.c4
-rw-r--r--builtin/update-index.c1
-rw-r--r--builtin/update-ref.c1
-rw-r--r--builtin/update-server-info.c1
-rw-r--r--builtin/var.c1
-rw-r--r--builtin/verify-commit.c1
-rw-r--r--builtin/verify-pack.c1
-rw-r--r--builtin/verify-tag.c1
-rw-r--r--builtin/worktree.c7
-rw-r--r--builtin/write-tree.c1
-rw-r--r--cache.h207
-rw-r--r--color.c1
-rw-r--r--column.c1
-rw-r--r--combine-diff.c2
-rw-r--r--commit-slab.h3
-rw-r--r--commit.c3
-rw-r--r--compat/precompose_utf8.c1
-rw-r--r--config.c47
-rw-r--r--config.h194
-rw-r--r--configure.ac4
-rw-r--r--connect.c1
-rw-r--r--contrib/coccinelle/free.cocci15
-rw-r--r--contrib/diff-highlight/.gitignore2
-rw-r--r--[-rwxr-xr-x]contrib/diff-highlight/DiffHighlight.pm (renamed from contrib/diff-highlight/diff-highlight)40
-rw-r--r--contrib/diff-highlight/Makefile21
-rw-r--r--contrib/diff-highlight/README30
-rw-r--r--contrib/diff-highlight/diff-highlight.perl8
-rw-r--r--convert.c32
-rw-r--r--convert.h19
-rw-r--r--credential-cache--daemon.c1
-rw-r--r--credential.c10
-rw-r--r--daemon.c1
-rw-r--r--date.c14
-rw-r--r--diff-lib.c3
-rw-r--r--diff.c13
-rw-r--r--diffcore-rename.c6
-rw-r--r--dir.c21
-rw-r--r--dir.h3
-rw-r--r--environment.c1
-rw-r--r--fast-import.c9
-rw-r--r--fetch-pack.c1
-rwxr-xr-xgit-add--interactive.perl3
-rw-r--r--git-compat-util.h6
-rwxr-xr-xgit-filter-branch.sh20
-rwxr-xr-xgit-rebase.sh4
-rwxr-xr-xgit-stash.sh9
-rwxr-xr-xgit-submodule.sh5
-rw-r--r--git.c56
-rw-r--r--gpg-interface.c16
-rw-r--r--graph.c1
-rw-r--r--grep.c15
-rw-r--r--help.c24
-rw-r--r--http-backend.c1
-rw-r--r--http-fetch.c1
-rw-r--r--http-push.c24
-rw-r--r--http.c16
-rw-r--r--ident.c1
-rw-r--r--imap-send.c4
-rw-r--r--line-log.c6
-rw-r--r--ll-merge.c6
-rw-r--r--log-tree.c1
-rw-r--r--mailinfo.c4
-rw-r--r--merge-recursive.c5
-rw-r--r--mergetools/meld2
-rw-r--r--notes-utils.c1
-rw-r--r--notes.c1
-rw-r--r--object.c3
-rw-r--r--pager.c1
-rw-r--r--parse-options.c1
-rw-r--r--pathspec.c4
-rw-r--r--pretty.c33
-rw-r--r--prio-queue.c3
-rw-r--r--prompt.c1
-rw-r--r--read-cache.c17
-rw-r--r--ref-filter.c3
-rw-r--r--refs.c13
-rw-r--r--refs.h5
-rw-r--r--refs/files-backend.c36
-rw-r--r--refs/ref-cache.c3
-rw-r--r--remote-curl.c1
-rw-r--r--remote-testsvn.c3
-rw-r--r--remote.c1
-rw-r--r--rerere.c4
-rw-r--r--revision.c89
-rw-r--r--revision.h5
-rw-r--r--send-pack.c1
-rw-r--r--sequencer.c15
-rw-r--r--setup.c19
-rw-r--r--sha1-array.c3
-rw-r--r--sha1_file.c10
-rw-r--r--sha1_name.c1
-rw-r--r--split-index.c60
-rw-r--r--split-index.h1
-rw-r--r--strbuf.c48
-rw-r--r--strbuf.h16
-rw-r--r--submodule-config.c1
-rw-r--r--submodule.c1
-rw-r--r--t/helper/test-config.c1
-rw-r--r--t/helper/test-submodule-config.c1
-rwxr-xr-xt/t0006-date.sh16
-rwxr-xr-xt/t1300-repo-config.sh6
-rwxr-xr-xt/t1308-config-set.sh4
-rwxr-xr-xt/t3070-wildmatch.sh2
-rwxr-xr-xt/t3200-branch.sh17
-rwxr-xr-xt/t3404-rebase-interactive.sh7
-rwxr-xr-xt/t3420-rebase-autostash.sh138
-rwxr-xr-xt/t3701-add-interactive.sh8
-rwxr-xr-xt/t3903-stash.sh16
-rwxr-xr-xt/t4005-diff-rename-2.sh95
-rwxr-xr-xt/t4041-diff-submodule-option.sh8
-rwxr-xr-xt/t4060-diff-submodule-option-diff-format.sh8
-rwxr-xr-xt/t5100-mailinfo.sh42
-rwxr-xr-xt/t6002-rev-list-bisect.sh14
-rwxr-xr-xt/t7006-pager.sh11
-rwxr-xr-xt/t7401-submodule-summary.sh8
-rwxr-xr-xt/t7414-submodule-mistakes.sh37
-rwxr-xr-xt/t7501-commit.sh2
-rwxr-xr-xt/t7508-status.sh64
-rw-r--r--trailer.c1
-rw-r--r--transport-helper.c27
-rw-r--r--transport.c4
-rw-r--r--tree-diff.c6
-rw-r--r--tree.c31
-rw-r--r--tree.h3
-rw-r--r--unpack-trees.c1
-rw-r--r--upload-pack.c1
-rw-r--r--usage.c18
-rw-r--r--userdiff.c1
-rw-r--r--versioncmp.c1
-rw-r--r--wrapper.c1
-rw-r--r--wt-status.c31
-rw-r--r--wt-status.h2
-rw-r--r--xdiff-interface.c1
231 files changed, 1756 insertions, 978 deletions
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
new file mode 100644
index 000000000..64e605a02
--- /dev/null
+++ b/.github/CONTRIBUTING.md
@@ -0,0 +1,19 @@
+## Contributing to Git
+
+Thanks for taking the time to contribute to Git! Please be advised that the
+Git community does not use github.com for their contributions. Instead, we use
+a mailing list (git@vger.kernel.org) for code submissions, code
+reviews, and bug reports.
+
+Nevertheless, you can use [submitGit](http://submitgit.herokuapp.com/) to
+conveniently send your Pull Requests commits to our mailing list.
+
+Please read ["A note from the maintainer"](https://git.kernel.org/pub/scm/git/git.git/plain/MaintNotes?h=todo)
+to learn how the Git project is managed, and how you can work with it.
+In addition, we highly recommend you to read [our submission guidelines](../Documentation/SubmittingPatches).
+
+If you prefer video, then [this talk](https://www.youtube.com/watch?v=Q7i_qQW__q4&feature=youtu.be&t=6m4s)
+might be useful to you as the presenter walks you through the contribution
+process by example.
+
+Your friendly Git community!
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 000000000..adba13e5b
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,7 @@
+Thanks for taking the time to contribute to Git! Please be advised that the
+Git community does not use github.com for their contributions. Instead, we use
+a mailing list (git@vger.kernel.org) for code submissions, code reviews, and
+bug reports. Nevertheless, you can use submitGit to conveniently send your Pull
+Requests commits to our mailing list.
+
+Please read the "guidelines for contributing" linked above!
diff --git a/Documentation/RelNotes/2.13.2.txt b/Documentation/RelNotes/2.13.2.txt
index c8ba0fa16..8c2b20071 100644
--- a/Documentation/RelNotes/2.13.2.txt
+++ b/Documentation/RelNotes/2.13.2.txt
@@ -34,4 +34,21 @@ Fixes since v2.13.1
* "git pull --rebase --autostash" didn't auto-stash when the local history
fast-forwards to the upstream.
+ * "git describe --contains" penalized light-weight tags so much that
+ they were almost never considered. Instead, give them about the
+ same chance to be considered as an annotated tag that is the same
+ age as the underlying commit would.
+
+ * The result from "git diff" that compares two blobs, e.g. "git diff
+ $commit1:$path $commit2:$path", used to be shown with the full
+ object name as given on the command line, but it is more natural to
+ use the $path in the output and use it to look up .gitattributes.
+
+ * A flaky test has been corrected.
+
+ * Help contributors that visit us at GitHub.
+
+ * "git stash push <pathspec>" did not work from a subdirectory at all.
+ Bugfix for a topic in v2.13
+
Also contains various documentation updates and code clean-ups.
diff --git a/Documentation/RelNotes/2.14.0.txt b/Documentation/RelNotes/2.14.0.txt
index a71615a6b..8b80058a8 100644
--- a/Documentation/RelNotes/2.14.0.txt
+++ b/Documentation/RelNotes/2.14.0.txt
@@ -38,19 +38,16 @@ UI, Workflows & Features
* "git archive --format=zip" learned to use zip64 extension when
necessary to go beyond the 4GB limit.
- (merge 867e40ff3a rs/large-zip later to maint).
* "git reset" learned "--recurse-submodules" option.
* "git diff --submodule=diff" now recurses into nested submodules.
- (merge 5a5221427c jk/diff-submodule-diff-inline later to maint).
* "git repack" learned to accept the --threads=<n> option and pass it
to pack-objects.
* "git send-email" learned to run sendemail-validate hook to inspect
and reject a message before sending it out.
- (merge 177409e589 jt/send-email-validate-hook later to maint).
* There is no good reason why "git fetch $there $sha1" should fail
when the $sha1 names an object at the tip of an advertised ref,
@@ -81,11 +78,22 @@ UI, Workflows & Features
required disambiguation more often. The command line parser
learned to say "it's a pathspec" a bit more often when the syntax
looks like so.
- (merge 2cb47ab695 jk/pathspec-magic-disambiguation later to maint).
* Update "perl-compatible regular expression" support to enable JIT
and also allow linking with the newer PCRE v2 library.
+ * "filter-branch" learned a pseudo filter "--setup" that can be used
+ to define common functions/variables that can be used by other
+ filters.
+
+ * Using "git add d/i/r" when d/i/r is the top of the working tree of
+ a separate repository would create a gitlink in the index, which
+ would appear as a not-quite-initialized submodule to others. We
+ learned to give warnings when this happens.
+
+ * "git status" learned to optionally give how many stash entries the
+ user has in its output.
+
Performance, Internal Implementation, Development Support etc.
@@ -95,7 +103,6 @@ Performance, Internal Implementation, Development Support etc.
* Code to update the cache-tree has been tightened so that we won't
accidentally write out any 0{40} entry in the tree object.
- (merge a96d3cc3f6 jk/no-null-sha1-in-cache-tree later to maint).
* Attempt to allow us notice "fishy" situation where we fail to
remove the temporary directory used during the test.
@@ -118,14 +125,11 @@ Performance, Internal Implementation, Development Support etc.
* Simplify parse_pathspec() codepath and stop it from looking at the
default in-core index.
- (merge 08de9151a8 bw/pathspec-sans-the-index later to maint).
* Add perf-test for wildmatch.
- (merge 62ca75a6b9 ab/perf-wildmatch later to maint).
* Code from "conversion using external process" codepath has been
extracted to a separate sub-process.[ch] module.
- (merge 4f2a2e9f0e bp/sub-process-convert-filter later to maint).
* When "git checkout", "git merge", etc. manipulates the in-core
index, various pieces of information in the index extensions are
@@ -136,7 +140,6 @@ Performance, Internal Implementation, Development Support etc.
cache is properly invalidated).
* The internal implementation of "git grep" has seen some clean-up.
- (merge 8df4c2953f ab/grep-preparatory-cleanup later to maint).
* Update the C style recommendation for notes for translators, as
recent versions of gettext tools can work with our style of
@@ -168,6 +171,25 @@ Performance, Internal Implementation, Development Support etc.
which then may cause Git operations to fail. Single out "the index
being locked" case and forcibly drop the lock from the copy.
+ * Three instances of the same helper function have been consolidated
+ to one.
+
+ * "fast-import" uses a default pack chain depth that is consistent
+ with other parts of the system.
+
+ * A new test to show the interaction between the pattern [^a-z]
+ (which matches '/') and a slash in a path has been added. The
+ pattern should not match the slash with "pathmatch", but should
+ with "wildmatch".
+
+ * The 'diff-highlight' program (in contrib/) has been restructured
+ for easier reuse by an external project 'diff-so-fancy'.
+ (merge 0c977dbc81 jk/diff-highlight-module later to maint).
+
+ * A common pattern to free a piece of memory and assign NULL to the
+ pointer that used to point at it has been replaced with a new
+ FREE_AND_NULL() macro.
+
Also contains various documentation updates and code clean-ups.
@@ -216,11 +238,6 @@ notes for details).
* "git checkout --recurse-submodules" did not quite work with a
submodule that itself has submodules.
- * Plug some leaks and updates internal API used to implement the
- split index feature to make it easier to avoid such a leak in the
- future.
- (merge de950c5773 nd/split-index-unshare later to maint).
-
* "pack-objects" can stream a slice of an existing packfile out when
the pack bitmap can tell that the reachable objects are all needed
in the output, without inspecting individual objects. This
@@ -282,7 +299,6 @@ notes for details).
they were almost never considered. Instead, give them about the
same chance to be considered as an annotated tag that is the same
age as the underlying commit would.
- (merge ef1e74065c jc/name-rev-lw-tag later to maint).
* The "run-command" API implementation has been made more robust
against dead-locking in a threaded environment.
@@ -308,7 +324,6 @@ notes for details).
$commit1:$path $commit2:$path", used to be shown with the full
object name as given on the command line, but it is more natural to
use the $path in the output and use it to look up .gitattributes.
- (merge 30d005c020 jk/diff-blob later to maint).
* The "collision detecting" SHA-1 implementation shipped with 2.13
was quite broken on some big-endian platforms and/or platforms that
@@ -329,7 +344,6 @@ notes for details).
fast-forwards to the upstream.
* A flaky test has been corrected.
- (merge 7c2115aa07 jk/pack-idx-corruption-safety later to maint).
* "git $cmd -h" for builtin commands calls the implementation of the
command (i.e. cmd_$cmd() function) without doing any repository
@@ -337,6 +351,49 @@ notes for details).
potty needs to be prepared to show the help text without barfing.
(merge d691551192 jk/consistent-h later to maint).
+ * Help contributors that visit us at GitHub.
+
+ * "git stash push <pathspec>" did not work from a subdirectory at all.
+ Bugfix for a topic in v2.13
+
+ * As there is no portable way to pass timezone information to
+ strftime, some output format from "git log" and friends are
+ impossible to produce. Teach our own strbuf_addftime to replace %z
+ and %Z with caller-supplied values to help working around this.
+ (merge 6eced3ec5e rs/strbuf-addftime-zZ later to maint).
+
+ * "git mergetool" learned to work around a wrapper MacOS X adds
+ around underlying meld.
+ (merge 0af85f84bd da/mergetools-meld-output-opt-on-macos later to maint).
+
+ * An example in documentation that does not work in multi worktree
+ configuration has been corrected.
+ (merge 773a88914f ah/doc-gitattributes-empty-index later to maint).
+
+ * The pretty-format specifiers like '%h', '%t', etc. had an
+ optimization that no longer works correctly. In preparation/hope
+ of getting it correctly implemented, first discard the optimization
+ that is broken.
+ (merge fe9e2aefd4 rs/pretty-add-again later to maint).
+
+ * The code to pick up and execute command alias definition from the
+ configuration used to switch to the top of the working tree and
+ then come back when the expanded alias was executed, which was
+ unnecessarilyl complex. Attempt to simplify the logic by using the
+ early-config mechanism that does not chdir around.
+ (merge a9bcf6586d js/alias-early-config later to maint).
+
+ * Fix configuration codepath to pay proper attention to commondir
+ that is used in multi-worktree situation, and isolate config API
+ into its own header file.
+ (merge dc8441fdb4 bw/config-h later to maint).
+
+ * "git add -p" were updated in 2.12 timeframe to cope with custom
+ core.commentchar but the implementation was buggy and a
+ metacharacter like $ and * did not work.
+ (merge d85d7ecb80 jk/add-p-commentchar-fix later to maint).
+
* Other minor doc, test and build updates and code cleanups.
- (merge 8ba74bfd7c jc/diff-tree-stale-comment later to maint).
- (merge 68602c01fd sb/submodule-rm-absorb later to maint).
+ (merge 68241cb9dd sb/t4005-modernize later to maint).
+ (merge 4fced24712 ks/t7508-indent-fix later to maint).
+ (merge 968b1fe263 mb/reword-autocomplete-message later to maint).
diff --git a/Documentation/config.txt b/Documentation/config.txt
index f6278a5ae..06898a749 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -348,6 +348,9 @@ advice.*::
rmHints::
In case of failure in the output of linkgit:git-rm[1],
show directions on how to proceed from the current state.
+ addEmbeddedRepo::
+ Advice on what to do when you've accidentally added one
+ git repo inside of another.
--
core.fileMode::
@@ -683,7 +686,8 @@ core.packedGitLimit::
bytes at once to complete an operation it will unmap existing
regions to reclaim virtual address space within the process.
+
-Default is 256 MiB on 32 bit platforms and 8 GiB on 64 bit platforms.
+Default is 256 MiB on 32 bit platforms and 32 TiB (effectively
+unlimited) on 64 bit platforms.
This should be reasonable for all users/operating systems, except on
the largest projects. You probably do not need to adjust this value.
+
@@ -2620,7 +2624,7 @@ rebase.autoSquash::
If set to true enable `--autosquash` option by default.
rebase.autoStash::
- When set to true, automatically create a temporary stash
+ When set to true, automatically create a temporary stash entry
before the operation begins, and apply it after the operation
ends. This means that you can run rebase on a dirty worktree.
However, use with care: the final stash application after a
@@ -2992,6 +2996,11 @@ status.displayCommentPrefix::
behavior of linkgit:git-status[1] in Git 1.8.4 and previous.
Defaults to false.
+status.showStash::
+ If set to true, linkgit:git-status[1] will display the number of
+ entries currently stashed away.
+ Defaults to false.
+
status.showUntrackedFiles::
By default, linkgit:git-status[1] and linkgit:git-commit[1] show
files which are not currently tracked by Git. Directories which
@@ -3029,12 +3038,12 @@ status.submoduleSummary::
stash.showPatch::
If this is set to true, the `git stash show` command without an
- option will show the stash in patch form. Defaults to false.
+ option will show the stash entry in patch form. Defaults to false.
See description of 'show' command in linkgit:git-stash[1].
stash.showStat::
If this is set to true, the `git stash show` command without an
- option will show diffstat of the stash. Defaults to true.
+ option will show diffstat of the stash entry. Defaults to true.
See description of 'show' command in linkgit:git-stash[1].
submodule.<name>.url::
diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index 7ed63dce0..f4169fb1e 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -165,6 +165,13 @@ for "git add --no-all <pathspec>...", i.e. ignored removed files.
be ignored, no matter if they are already present in the work
tree or not.
+--no-warn-embedded-repo::
+ By default, `git add` will warn when adding an embedded
+ repository to the index without using `git submodule add` to
+ create an entry in `.gitmodules`. This option will suppress the
+ warning (e.g., if you are manually performing operations on
+ submodules).
+
--chmod=(+|-)x::
Override the executable bit of the added files. The executable
bit is only changed in the index, the files on disk are left
diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt
index 2b762654b..3d3d219e5 100644
--- a/Documentation/git-fast-import.txt
+++ b/Documentation/git-fast-import.txt
@@ -121,7 +121,7 @@ Performance and Compression Tuning
--depth=<n>::
Maximum delta depth, for blob and tree deltification.
- Default is 10.
+ Default is 50.
--export-pack-edges=<file>::
After creating a packfile, print a line of data to
diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index 7b695dbb7..9e5169aa6 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -8,11 +8,11 @@ git-filter-branch - Rewrite branches
SYNOPSIS
--------
[verse]
-'git filter-branch' [--env-filter <command>] [--tree-filter <command>]
- [--index-filter <command>] [--parent-filter <command>]
- [--msg-filter <command>] [--commit-filter <command>]
- [--tag-name-filter <command>] [--subdirectory-filter <directory>]
- [--prune-empty]
+'git filter-branch' [--setup <command>] [--env-filter <command>]
+ [--tree-filter <command>] [--index-filter <command>]
+ [--parent-filter <command>] [--msg-filter <command>]
+ [--commit-filter <command>] [--tag-name-filter <command>]
+ [--subdirectory-filter <directory>] [--prune-empty]
[--original <namespace>] [-d <directory>] [-f | --force]
[--] [<rev-list options>...]
@@ -82,6 +82,13 @@ multiple commits.
OPTIONS
-------
+--setup <command>::
+ This is not a real filter executed for each commit but a one
+ time setup just before the loop. Therefore no commit-specific
+ variables are defined yet. Functions or variables defined here
+ can be used or modified in the following filter steps except
+ the commit filter, for technical reasons.
+
--env-filter <command>::
This filter may be used if you only need to modify the environment
in which the commit will be performed. Specifically, you might
diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt
index e414185f5..9db5e08f4 100644
--- a/Documentation/git-pull.txt
+++ b/Documentation/git-pull.txt
@@ -131,7 +131,7 @@ unless you have read linkgit:git-rebase[1] carefully.
--autostash::
--no-autostash::
Before starting rebase, stash local modifications away (see
- linkgit:git-stash[1]) if needed, and apply the stash when
+ linkgit:git-stash[1]) if needed, and apply the stash entry when
done. `--no-autostash` is useful to override the `rebase.autoStash`
configuration variable (see linkgit:git-config[1]).
+
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 53f4e1444..a5afd602d 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -446,7 +446,7 @@ used to override and disable this setting.
--autostash::
--no-autostash::
- Automatically create a temporary stash before the operation
+ Automatically create a temporary stash entry before the operation
begins, and apply it after the operation ends. This means
that you can run rebase on a dirty worktree. However, use
with care: the final stash application after a successful
diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt
index 8a21198d6..70f3753e1 100644
--- a/Documentation/git-reset.txt
+++ b/Documentation/git-reset.txt
@@ -115,7 +115,7 @@ $ git pull git://info.example.com/ nitfol <4>
in these files are in good order. You do not want to see them
when you run "git diff", because you plan to work on other files
and changes with these files are distracting.
-<2> Somebody asks you to pull, and the changes sounds worthy of merging.
+<2> Somebody asks you to pull, and the changes sound worthy of merging.
<3> However, you already dirtied the index (i.e. your index does
not match the HEAD commit). But you know the pull you are going
to make does not affect frotz.c or filfre.c, so you revert the
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 70191d06b..00f95fee1 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -51,18 +51,18 @@ OPTIONS
save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]::
push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>] [--] [<pathspec>...]::
- Save your local modifications to a new 'stash' and roll them
+ Save your local modifications to a new 'stash entry' and roll them
back to HEAD (in the working tree and in the index).
The <message> part is optional and gives
the description along with the stashed state.
+
For quickly making a snapshot, you can omit "push". In this mode,
non-option arguments are not allowed to prevent a misspelled
-subcommand from making an unwanted stash. The two exceptions to this
+subcommand from making an unwanted stash entry. The two exceptions to this
are `stash -p` which acts as alias for `stash push -p` and pathspecs,
which are allowed after a double hyphen `--` for disambiguation.
+
-When pathspec is given to 'git stash push', the new stash records the
+When pathspec is given to 'git stash push', the new stash entry records the
modified states only for the files that match the pathspec. The index
entries and working tree files are then rolled back to the state in
HEAD only for these files, too, leaving files that do not match the
@@ -89,10 +89,10 @@ The `--patch` option implies `--keep-index`. You can use
list [<options>]::
- List the stashes that you currently have. Each 'stash' is listed
- with its name (e.g. `stash@{0}` is the latest stash, `stash@{1}` is
+ List the stash entries that you currently have. Each 'stash entry' is
+ listed with its name (e.g. `stash@{0}` is the latest entry, `stash@{1}` is
the one before, etc.), the name of the branch that was current when the
- stash was made, and a short description of the commit the stash was
+ entry was made, and a short description of the commit the entry was
based on.
+
----------------------------------------------------------------
@@ -105,11 +105,12 @@ command to control what is shown and how. See linkgit:git-log[1].
show [<stash>]::
- Show the changes recorded in the stash as a diff between the
- stashed state and its original parent. When no `<stash>` is given,
- shows the latest one. By default, the command shows the diffstat, but
- it will accept any format known to 'git diff' (e.g., `git stash show
- -p stash@{1}` to view the second most recent stash in patch form).
+ Show the changes recorded in the stash entry as a diff between the
+ stashed contents and the commit back when the stash entry was first
+ created. When no `<stash>` is given, it shows the latest one.
+ By default, the command shows the diffstat, but it will accept any
+ format known to 'git diff' (e.g., `git stash show -p stash@{1}`
+ to view the second most recent entry in patch form).
You can use stash.showStat and/or stash.showPatch config variables
to change the default behavior.
@@ -149,26 +150,27 @@ branch <branchname> [<stash>]::
+
This is useful if the branch on which you ran `git stash save` has
changed enough that `git stash apply` fails due to conflicts. Since
-the stash is applied on top of the commit that was HEAD at the time
-`git stash` was run, it restores the originally stashed state with
-no conflicts.
+the stash entry is applied on top of the commit that was HEAD at the
+time `git stash` was run, it restores the originally stashed state
+with no conflicts.
clear::
- Remove all the stashed states. Note that those states will then
+ Remove all the stash entries. Note that those entries will then
be subject to pruning, and may be impossible to recover (see
'Examples' below for a possible strategy).
drop [-q|--quiet] [<stash>]::
- Remove a single stashed state from the stash list. When no `<stash>`
- is given, it removes the latest one. i.e. `stash@{0}`, otherwise
- `<stash>` must be a valid stash log reference of the form
- `stash@{<revision>}`.
+ Remove a single stash entry from the list of stash entries.
+ When no `<stash>` is given, it removes the latest one.
+ i.e. `stash@{0}`, otherwise `<stash>` must be a valid stash
+ log reference of the form `stash@{<revision>}`.
create::
- Create a stash (which is a regular commit object) and return its
- object name, without storing it anywhere in the ref namespace.
+ Create a stash entry (which is a regular commit object) and
+ return its object name, without storing it anywhere in the ref
+ namespace.
This is intended to be useful for scripts. It is probably not
the command you want to use; see "save" above.
@@ -182,10 +184,10 @@ store::
DISCUSSION
----------
-A stash is represented as a commit whose tree records the state of the
-working directory, and its first parent is the commit at `HEAD` when
-the stash was created. The tree of the second parent records the
-state of the index when the stash is made, and it is made a child of
+A stash entry is represented as a commit whose tree records the state
+of the working directory, and its first parent is the commit at `HEAD`
+when the entry was created. The tree of the second parent records the
+state of the index when the entry is made, and it is made a child of
the `HEAD` commit. The ancestry graph looks like this:
.----W
@@ -269,12 +271,12 @@ $ edit/build/test remaining parts
$ git commit foo -m 'Remaining parts'
----------------------------------------------------------------
-Recovering stashes that were cleared/dropped erroneously::
+Recovering stash entries that were cleared/dropped erroneously::
-If you mistakenly drop or clear stashes, they cannot be recovered
+If you mistakenly drop or clear stash entries, they cannot be recovered
through the normal safety mechanisms. However, you can try the
-following incantation to get a list of stashes that are still in your
-repository, but not reachable any more:
+following incantation to get a list of stash entries that are still in
+your repository, but not reachable any more:
+
----------------------------------------------------------------
git fsck --unreachable |
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index d70abc6af..d47f198f1 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -32,6 +32,9 @@ OPTIONS
--branch::
Show the branch and tracking info even in short-format.
+--show-stash::
+ Show the number of entries currently stashed away.
+
--porcelain[=<version>]::
Give the output in an easy-to-parse format for scripts.
This is similar to the short output, but will remain stable
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 473648386..2a2d7e2a4 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -229,7 +229,7 @@ From a clean working directory:
-------------------------------------------------
$ echo "* text=auto" >.gitattributes
-$ rm .git/index # Remove the index to re-scan the working directory
+$ git read-tree --empty # Clean index, force re-scan of working directory
$ git add .
$ git status # Show files that will be normalized
$ git commit -m "Introduce end-of-line normalization"
diff --git a/Documentation/gitcli.txt b/Documentation/gitcli.txt
index dfe7d8372..9f13266a6 100644
--- a/Documentation/gitcli.txt
+++ b/Documentation/gitcli.txt
@@ -194,7 +194,7 @@ different things.
* The `--index` option is used to ask a command that
usually works on files in the working tree to *also*
affect the index. For example, `git stash apply` usually
- merges changes recorded in a stash to the working tree,
+ merges changes recorded in a stash entry to the working tree,
but with the `--index` option, it also merges changes to
the index as well.
diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt
index 6e991c246..b71b943b1 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -570,6 +570,10 @@ The most notable example is `HEAD`.
is created by giving the `--depth` option to linkgit:git-clone[1], and
its history can be later deepened with linkgit:git-fetch[1].
+[[def_stash]]stash entry::
+ An <<def_object,object>> used to temporarily store the contents of a
+ <<def_dirty,dirty>> working directory and the index for future reuse.
+
[[def_submodule]]submodule::
A <<def_repository,repository>> that holds the history of a
separate project inside another repository (the latter of
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 38040e95b..a48d267e2 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -213,8 +213,8 @@ If you add a `+` (plus sign) after '%' of a placeholder, a line-feed
is inserted immediately before the expansion if and only if the
placeholder expands to a non-empty string.
-If you add a `-` (minus sign) after '%' of a placeholder, line-feeds that
-immediately precede the expansion are deleted if and only if the
+If you add a `-` (minus sign) after '%' of a placeholder, all consecutive
+line-feeds immediately preceding the expansion are deleted if and only if the
placeholder expands to an empty string.
If you add a ` ` (space) after '%' of a placeholder, a space
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 9c44eae55..a6cf9eb38 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -769,7 +769,8 @@ timezone value.
1970). As with `--raw`, this is always in UTC and therefore `-local`
has no effect.
+
-`--date=format:...` feeds the format `...` to your system `strftime`.
+`--date=format:...` feeds the format `...` to your system `strftime`,
+except for %z and %Z, which are handled internally.
Use `--date=format:%c` to show the date in your system locale's
preferred format. See the `strftime` manual for a complete list of
format placeholders. When using `-local`, the correct syntax is
diff --git a/Makefile b/Makefile
index f48480163..b94cd5633 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,8 @@ all::
# have been written to the final string if enough space had been available.
#
# Define FREAD_READS_DIRECTORIES if you are on a system which succeeds
-# when attempting to read from an fopen'ed directory.
+# when attempting to read from an fopen'ed directory (or even to fopen
+# it at all).
#
# Define NO_OPENSSL environment variable if you do not have OpenSSL.
# This also implies BLK_SHA1.
diff --git a/advice.c b/advice.c
index b84ae4960..d81e1cb74 100644
--- a/advice.c
+++ b/advice.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
int advice_push_update_rejected = 1;
int advice_push_non_ff_current = 1;
@@ -15,6 +16,7 @@ int advice_detached_head = 1;
int advice_set_upstream_failure = 1;
int advice_object_name_warning = 1;
int advice_rm_hints = 1;
+int advice_add_embedded_repo = 1;
static struct {
const char *name;
@@ -35,6 +37,7 @@ static struct {
{ "setupstreamfailure", &advice_set_upstream_failure },
{ "objectnamewarning", &advice_object_name_warning },
{ "rmhints", &advice_rm_hints },
+ { "addembeddedrepo", &advice_add_embedded_repo },
/* make this an alias for backward compatibility */
{ "pushnonfastforward", &advice_push_update_rejected }
diff --git a/advice.h b/advice.h
index b341a55ce..c84a44531 100644
--- a/advice.h
+++ b/advice.h
@@ -18,6 +18,7 @@ extern int advice_detached_head;
extern int advice_set_upstream_failure;
extern int advice_object_name_warning;
extern int advice_rm_hints;
+extern int advice_add_embedded_repo;
int git_default_advice_config(const char *var, const char *value);
__attribute__((format (printf, 1, 2)))
diff --git a/alias.c b/alias.c
index 3b90397a9..39f622e41 100644
--- a/alias.c
+++ b/alias.c
@@ -1,14 +1,29 @@
#include "cache.h"
+#include "config.h"
+
+struct config_alias_data {
+ const char *alias;
+ char *v;
+};
+
+static int config_alias_cb(const char *key, const char *value, void *d)
+{
+ struct config_alias_data *data = d;
+ const char *p;
+
+ if (skip_prefix(key, "alias.", &p) && !strcmp(p, data->alias))
+ return git_config_string((const char **)&data->v, key, value);
+
+ return 0;
+}
char *alias_lookup(const char *alias)
{
- char *v = NULL;
- struct strbuf key = STRBUF_INIT;
- strbuf_addf(&key, "alias.%s", alias);
- if (git_config_key_is_valid(key.buf))
- git_config_get_string(key.buf, &v);
- strbuf_release(&key);
- return v;
+ struct config_alias_data data = { alias, NULL };
+
+ read_early_config(config_alias_cb, &data);
+
+ return data.v;
}
#define SPLIT_CMDLINE_BAD_ENDING 1
@@ -47,8 +62,7 @@ int split_cmdline(char *cmdline, const char ***argv)
src++;
c = cmdline[src];
if (!c) {
- free(*argv);
- *argv = NULL;
+ FREE_AND_NULL(*argv);
return -SPLIT_CMDLINE_BAD_ENDING;
}
}
@@ -60,8 +74,7 @@ int split_cmdline(char *cmdline, const char ***argv)
cmdline[dst] = 0;
if (quoted) {
- free(*argv);
- *argv = NULL;
+ FREE_AND_NULL(*argv);
return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
}
diff --git a/apply.c b/apply.c
index 854faa677..b963d7d8f 100644
--- a/apply.c
+++ b/apply.c
@@ -8,6 +8,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "blob.h"
#include "delta.h"
#include "diff.h"
@@ -762,17 +763,6 @@ static char *find_name_traditional(struct apply_state *state,
return find_name_common(state, line, def, p_value, line + len, 0);
}
-static int count_slashes(const char *cp)
-{
- int cnt = 0;
- char ch;
-
- while ((ch = *cp++))
- if (ch == '/')
- cnt++;
- return cnt;
-}
-
/*
* Given the string after "--- " or "+++ ", guess the appropriate
* p_value for the given patch.
@@ -2267,7 +2257,7 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf)
case S_IFREG:
if (strbuf_read_file(buf, path, st->st_size) != st->st_size)
return error(_("unable to open or read %s"), path);
- convert_to_git(path, buf->buf, buf->len, buf, 0);
+ convert_to_git(&the_index, path, buf->buf, buf->len, buf, 0);
return 0;
default:
return -1;
@@ -3705,8 +3695,7 @@ static int check_preimage(struct apply_state *state,
is_new:
patch->is_new = 1;
patch->is_delete = 0;
- free(patch->old_name);
- patch->old_name = NULL;
+ FREE_AND_NULL(patch->old_name);
return 0;
}
diff --git a/archive-tar.c b/archive-tar.c
index 073e60ebd..c6ed96ee7 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -2,6 +2,7 @@
* Copyright (c) 2005, 2006 Rene Scharfe
*/
#include "cache.h"
+#include "config.h"
#include "tar.h"
#include "archive.h"
#include "streaming.h"
diff --git a/archive-zip.c b/archive-zip.c
index 27563e9e2..e8913e5a2 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -2,6 +2,7 @@
* Copyright (c) 2006 Rene Scharfe
*/
#include "cache.h"
+#include "config.h"
#include "archive.h"
#include "streaming.h"
#include "utf8.h"
diff --git a/archive.c b/archive.c
index b15a922da..60b3035a7 100644
--- a/archive.c
+++ b/archive.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "commit.h"
#include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 821203e2a..37454999d 100644
--- a/attr.c
+++ b/attr.c
@@ -9,6 +9,7 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
+#include "config.h"
#include "exec_cmd.h"
#include "attr.h"
#include "dir.h"
@@ -638,13 +639,11 @@ void attr_check_reset(struct attr_check *check)
void attr_check_clear(struct attr_check *check)
{
- free(check->items);
- check->items = NULL;
+ FREE_AND_NULL(check->items);
check->alloc = 0;
check->nr = 0;
- free(check->all_attrs);
- check->all_attrs = NULL;
+ FREE_AND_NULL(check->all_attrs);
check->all_attrs_nr = 0;
drop_attr_stack(&check->stack);
diff --git a/bisect.c b/bisect.c
index 2a2b9b726..a9fd9fbc6 100644
--- a/bisect.c
+++ b/bisect.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
diff --git a/blame.c b/blame.c
index 194b58e96..91e26e93e 100644
--- a/blame.c
+++ b/blame.c
@@ -229,7 +229,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(path, buf.buf, buf.len, &buf, 0);
+ convert_to_git(&the_index, path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf;
origin->file.size = buf.len;
pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash);
@@ -314,8 +314,7 @@ static void fill_origin_blob(struct diff_options *opt,
static void drop_origin_blob(struct blame_origin *o)
{
if (o->file.ptr) {
- free(o->file.ptr);
- o->file.ptr = NULL;
+ FREE_AND_NULL(o->file.ptr);
}
}
diff --git a/branch.c b/branch.c
index 985316eb7..36541d05c 100644
--- a/branch.c
+++ b/branch.c
@@ -1,5 +1,6 @@
#include "git-compat-util.h"
#include "cache.h"
+#include "config.h"
#include "branch.h"
#include "refs.h"
#include "remote.h"
@@ -24,8 +25,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
} else {
free(tracking->spec.src);
if (tracking->src) {
- free(tracking->src);
- tracking->src = NULL;
+ FREE_AND_NULL(tracking->src);
}
}
tracking->spec.src = NULL;
diff --git a/builtin/add.c b/builtin/add.c
index d9a2491e4..e888fb8c5 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -4,6 +4,7 @@
* Copyright (C) 2006 Linus Torvalds
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "lockfile.h"
#include "dir.h"
@@ -249,6 +250,7 @@ N_("The following paths are ignored by one of your .gitignore files:\n");
static int verbose, show_only, ignored_too, refresh_only;
static int ignore_add_errors, intent_to_add, ignore_missing;
+static int warn_on_embedded_repo = 1;
#define ADDREMOVE_DEFAULT 1
static int addremove = ADDREMOVE_DEFAULT;
@@ -282,6 +284,8 @@ static struct option builtin_add_options[] = {
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_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
+ N_("warn when adding an embedded repository")),
OPT_END(),
};
@@ -295,6 +299,45 @@ static int add_config(const char *var, const char *value, void *cb)
return git_default_config(var, value, cb);
}
+static const char embedded_advice[] = N_(
+"You've added another git repository inside your current repository.\n"
+"Clones of the outer repository will not contain the contents of\n"
+"the embedded repository and will not know how to obtain it.\n"
+"If you meant to add a submodule, use:\n"
+"\n"
+" git submodule add <url> %s\n"
+"\n"
+"If you added this path by mistake, you can remove it from the\n"
+"index with:\n"
+"\n"
+" git rm --cached %s\n"
+"\n"
+"See \"git help submodule\" for more information."
+);
+
+static void check_embedded_repo(const char *path)
+{
+ struct strbuf name = STRBUF_INIT;
+
+ if (!warn_on_embedded_repo)
+ return;
+ if (!ends_with(path, "/"))
+ return;
+
+ /* Drop trailing slash for aesthetics */
+ strbuf_addstr(&name, path);
+ strbuf_strip_suffix(&name, "/");
+
+ warning(_("adding embedded git repository: %s"), name.buf);
+ if (advice_add_embedded_repo) {
+ advise(embedded_advice, name.buf, name.buf);
+ /* there may be multiple entries; advise only once */
+ advice_add_embedded_repo = 0;
+ }
+
+ strbuf_release(&name);
+}
+
static int add_files(struct dir_struct *dir, int flags)
{
int i, exit_status = 0;
@@ -307,12 +350,14 @@ static int add_files(struct dir_struct *dir, int flags)
exit_status = 1;
}
- for (i = 0; i < dir->nr; i++)
+ for (i = 0; i < dir->nr; i++) {
+ check_embedded_repo(dir->entries[i]->name);
if (add_file_to_index(&the_index, dir->entries[i]->name, flags)) {
if (!ignore_add_errors)
die(_("adding files failed"));
exit_status = 1;
}
+ }
return exit_status;
}
diff --git a/builtin/am.c b/builtin/am.c
index 3985f9a89..c973bd96d 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -4,6 +4,7 @@
* Based on git-am.sh by Junio C Hamano.
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "exec_cmd.h"
#include "parse-options.h"
@@ -483,8 +484,7 @@ static int run_applypatch_msg_hook(struct am_state *state)
ret = run_hook_le(NULL, "applypatch-msg", am_path(state, "final-commit"), NULL);
if (!ret) {
- free(state->msg);
- state->msg = NULL;
+ FREE_AND_NULL(state->msg);
if (read_commit_msg(state) < 0)
die(_("'%s' was deleted by the applypatch-msg hook"),
am_path(state, "final-commit"));
@@ -1073,17 +1073,10 @@ static void am_next(struct am_state *state)
{
struct object_id head;
- free(state->author_name);
- state->author_name = NULL;
-
- free(state->author_email);
- state->author_email = NULL;
-
- free(state->author_date);
- state->author_date = NULL;
-
- free(state->msg);
- state->msg = NULL;
+ FREE_AND_NULL(state->author_name);
+ FREE_AND_NULL(state->author_email);
+ FREE_AND_NULL(state->author_date);
+ FREE_AND_NULL(state->msg);
state->msg_len = 0;
unlink(am_path(state, "author-script"));
diff --git a/builtin/blame.c b/builtin/blame.c
index 749ad7f05..bda1a7872 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -6,6 +6,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "commit.h"
#include "diff.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index 83fcda43d..c958e9325 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -6,6 +6,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "color.h"
#include "refs.h"
#include "commit.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 4bffd7a2d..7efbc4019 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "diff.h"
#include "parse-options.h"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 4d01ca0c8..91444dc04 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "attr.h"
#include "quote.h"
#include "parse-options.h"
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index c7b8c0889..3e280b9c7 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "quote.h"
#include "pathspec.h"
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index cf0f54f6b..cdce144f3 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "mailmap.h"
#include "parse-options.h"
#include "string-list.h"
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 07631d0c9..39c8be05d 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -5,6 +5,7 @@
*
*/
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "quote.h"
#include "cache-tree.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 1624eed7e..9661e1bcb 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "parse-options.h"
#include "refs.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 142bf668c..057fc97fe 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -8,6 +8,7 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "parse-options.h"
#include "string-list.h"
@@ -837,8 +838,7 @@ static void interactive_main_loop(void)
int ret;
ret = menus[*chosen].fn();
if (ret != MENU_RETURN_NO_LOOP) {
- free(chosen);
- chosen = NULL;
+ FREE_AND_NULL(chosen);
if (!del_list.nr) {
clean_print_color(CLEAN_COLOR_ERROR);
printf_ln(_("No more files to clean, exiting."));
@@ -851,8 +851,7 @@ static void interactive_main_loop(void)
quit_cmd();
}
- free(chosen);
- chosen = NULL;
+ FREE_AND_NULL(chosen);
break;
}
}
diff --git a/builtin/clone.c b/builtin/clone.c
index a2ea019c5..08b5cc433 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -9,6 +9,7 @@
*/
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "parse-options.h"
#include "fetch-pack.h"
diff --git a/builtin/column.c b/builtin/column.c
index 33314b4d7..0c3223d64 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "strbuf.h"
#include "parse-options.h"
#include "string-list.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index f39c2b273..a4a923d7c 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "tree.h"
#include "builtin.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index e3c9e190b..03b97c644 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -6,6 +6,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "cache-tree.h"
#include "color.h"
@@ -253,7 +254,8 @@ static int list_paths(struct string_list *list, const char *with_tree,
if (with_tree) {
char *max_prefix = common_prefix(pattern);
- overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);
+ overlay_tree_on_index(&the_index, with_tree,
+ max_prefix ? max_prefix : prefix);
free(max_prefix);
}
@@ -1295,6 +1297,10 @@ static int git_status_config(const char *k, const char *v, void *cb)
status_deferred_config.show_branch = git_config_bool(k, v);
return 0;
}
+ if (!strcmp(k, "status.showstash")) {
+ s->show_stash = git_config_bool(k, v);
+ return 0;
+ }
if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
s->use_color = git_config_colorbool(k, v);
return 0;
@@ -1343,6 +1349,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
N_("show status concisely"), STATUS_FORMAT_SHORT),
OPT_BOOL('b', "branch", &s.show_branch,
N_("show branch information")),
+ OPT_BOOL(0, "show-stash", &s.show_stash,
+ N_("show stash information")),
{ OPTION_CALLBACK, 0, "porcelain", &status_format,
N_("version"), N_("machine-readable output"),
PARSE_OPT_OPTARG, opt_parse_porcelain },
@@ -1652,6 +1660,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
usage_with_options(builtin_commit_usage, builtin_commit_options);
status_init_config(&s, git_commit_config);
+ s.commit_template = 1;
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
s.colopts = 0;
diff --git a/builtin/config.c b/builtin/config.c
index 7f6c25d4d..70ff231e9 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "color.h"
#include "parse-options.h"
#include "urlmatch.h"
@@ -214,8 +215,7 @@ static int get_value(const char *key_, const char *regex_)
key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
if (regcomp(key_regexp, key, REG_EXTENDED)) {
error("invalid key pattern: %s", key_);
- free(key_regexp);
- key_regexp = NULL;
+ FREE_AND_NULL(key_regexp);
ret = CONFIG_INVALID_PATTERN;
goto free_strings;
}
@@ -235,15 +235,14 @@ static int get_value(const char *key_, const char *regex_)
regexp = (regex_t*)xmalloc(sizeof(regex_t));
if (regcomp(regexp, regex_, REG_EXTENDED)) {
error("invalid pattern: %s", regex_);
- free(regexp);
- regexp = NULL;
+ FREE_AND_NULL(regexp);
ret = CONFIG_INVALID_PATTERN;
goto free_strings;
}
}
- git_config_with_options(collect_config, &values,
- &given_config_source, &config_options);
+ config_with_options(collect_config, &values,
+ &given_config_source, &config_options);
ret = !values.nr;
@@ -320,8 +319,8 @@ static void get_color(const char *var, const char *def_color)
get_color_slot = var;
get_color_found = 0;
parsed_color[0] = '\0';
- git_config_with_options(git_get_color_config, NULL,
- &given_config_source, &config_options);
+ config_with_options(git_get_color_config, NULL,
+ &given_config_source, &config_options);
if (!get_color_found && def_color) {
if (color_parse(def_color, parsed_color) < 0)
@@ -352,8 +351,8 @@ static int get_colorbool(const char *var, int print)
get_colorbool_found = -1;
get_diff_color_found = -1;
get_color_ui_found = -1;
- git_config_with_options(git_get_colorbool_config, NULL,
- &given_config_source, &config_options);
+ config_with_options(git_get_colorbool_config, NULL,
+ &given_config_source, &config_options);
if (get_colorbool_found < 0) {
if (!strcmp(get_colorbool_slot, "color.diff"))
@@ -441,8 +440,8 @@ static int get_urlmatch(const char *var, const char *url)
show_keys = 1;
}
- git_config_with_options(urlmatch_config_entry, &config,
- &given_config_source, &config_options);
+ config_with_options(urlmatch_config_entry, &config,
+ &given_config_source, &config_options);
ret = !values.nr;
@@ -538,6 +537,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
config_options.respect_includes = !given_config_source.file;
else
config_options.respect_includes = respect_includes_opt;
+ if (!nongit) {
+ config_options.commondir = get_git_common_dir();
+ config_options.git_dir = get_git_dir();
+ }
if (end_null) {
term = '\0';
@@ -582,9 +585,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)
if (actions == ACTION_LIST) {
check_argc(argc, 0, 0);
- if (git_config_with_options(show_all_config, NULL,
- &given_config_source,
- &config_options) < 0) {
+ if (config_with_options(show_all_config, NULL,
+ &given_config_source,
+ &config_options) < 0) {
if (given_config_source.file)
die_errno("unable to read config file '%s'",
given_config_source.file);
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index acb05940f..1d82e61f2 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -5,6 +5,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "builtin.h"
#include "parse-options.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 893c8789f..70eb14460 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "commit.h"
#include "tag.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index c97069a71..17bf84d18 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "diff.h"
#include "commit.h"
#include "revision.h"
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index d59bf6cf5..185e6f9b5 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "diff.h"
#include "commit.h"
#include "revision.h"
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 7e15d01f3..31d2cb410 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "diff.h"
#include "commit.h"
#include "log-tree.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index d9152c21b..7cde6abbc 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -4,6 +4,7 @@
* Copyright (c) 2006 Junio C Hamano
*/
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "color.h"
#include "commit.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index b9a892f26..9199227f6 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -12,6 +12,7 @@
* Copyright (C) 2016 Johannes Schindelin
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "run-command.h"
#include "exec_cmd.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index a932be04f..12d501bfd 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -5,6 +5,7 @@
*/
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "commit.h"
#include "object.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 100248c5a..16cf8421c 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2,6 +2,7 @@
* "git fetch"
*/
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "commit.h"
#include "builtin.h"
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 70137b0b7..10cbb4341 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "commit.h"
#include "diff.h"
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index eca365bf8..52be99cba 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "object.h"
#include "parse-options.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 3a2c27f24..87c675689 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "tree.h"
#include "blob.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index f484eda43..bd91f136f 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -11,6 +11,7 @@
*/
#include "builtin.h"
+#include "config.h"
#include "tempfile.h"
#include "lockfile.h"
#include "parse-options.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 3e4b9600e..f61a9d938 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -4,6 +4,7 @@
* Copyright (c) 2006 Junio C Hamano
*/
#include "cache.h"
+#include "config.h"
#include "blob.h"
#include "tree.h"
#include "commit.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index bbeaf20bc..d04baf999 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -5,6 +5,7 @@
* Copyright (C) Junio C Hamano, 2005
*/
#include "builtin.h"
+#include "config.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"
diff --git a/builtin/help.c b/builtin/help.c
index 49f7a07f8..334a8494a 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -2,6 +2,7 @@
* Builtin help command
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "exec_cmd.h"
#include "parse-options.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 04b9dcaf0..ad4de3517 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "delta.h"
#include "pack.h"
#include "csum-file.h"
@@ -388,8 +389,7 @@ static struct base_data *alloc_base_data(void)
static void free_base_data(struct base_data *c)
{
if (c->data) {
- free(c->data);
- c->data = NULL;
+ FREE_AND_NULL(c->data);
get_thread_data()->base_cache_used -= c->size;
}
}
@@ -605,8 +605,7 @@ static void *unpack_data(struct object_entry *obj,
git_inflate_end(&stream);
free(inbuf);
if (consume) {
- free(data);
- data = NULL;
+ FREE_AND_NULL(data);
}
return data;
}
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 8a6acb0ec..47823f9aa 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "builtin.h"
#include "exec_cmd.h"
diff --git a/builtin/log.c b/builtin/log.c
index 998437b23..8ca1de989 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -5,6 +5,7 @@
* 2006 Junio Hamano
*/
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "color.h"
#include "commit.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b376afc31..b12d0bb61 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -6,6 +6,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "quote.h"
#include "dir.h"
#include "builtin.h"
@@ -53,17 +54,17 @@ static const char *tag_modified = "";
static const char *tag_skip_worktree = "";
static const char *tag_resolve_undo = "";
-static void write_eolinfo(const struct cache_entry *ce, const char *path)
+static void write_eolinfo(const struct index_state *istate,
+ const struct cache_entry *ce, const char *path)
{
- if (!show_eol)
- return;
- else {
+ if (show_eol) {
struct stat st;
const char *i_txt = "";
const char *w_txt = "";
const char *a_txt = get_convert_attr_ascii(path);
if (ce && S_ISREG(ce->ce_mode))
- i_txt = get_cached_convert_stats_ascii(ce->name);
+ i_txt = get_cached_convert_stats_ascii(istate,
+ ce->name);
if (!lstat(path, &st) && S_ISREG(st.st_mode))
w_txt = get_wt_convert_stats_ascii(path);
printf("i/%-5s w/%-5s attr/%-17s\t", i_txt, w_txt, a_txt);
@@ -93,6 +94,43 @@ static void write_name(const char *name)
strbuf_release(&full_name);
}
+static const char *get_tag(const struct cache_entry *ce, const char *tag)
+{
+ static char alttag[4];
+
+ if (tag && *tag && show_valid_bit && (ce->ce_flags & CE_VALID)) {
+ memcpy(alttag, tag, 3);
+
+ if (isalpha(tag[0])) {
+ alttag[0] = tolower(tag[0]);
+ } else if (tag[0] == '?') {
+ alttag[0] = '!';
+ } else {
+ alttag[0] = 'v';
+ alttag[1] = tag[0];
+ alttag[2] = ' ';
+ alttag[3] = 0;
+ }
+
+ tag = alttag;
+ }
+
+ return tag;
+}
+
+static void print_debug(const struct cache_entry *ce)
+{
+ if (debug_mode) {
+ const struct stat_data *sd = &ce->ce_stat_data;
+
+ printf(" ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec);
+ printf(" mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec);
+ printf(" dev: %d\tino: %d\n", sd->sd_dev, sd->sd_ino);
+ printf(" uid: %d\tgid: %d\n", sd->sd_uid, sd->sd_gid);
+ printf(" size: %d\tflags: %x\n", sd->sd_size, ce->ce_flags);
+ }
+}
+
static void show_dir_entry(const char *tag, struct dir_entry *ent)
{
int len = max_prefix_len;
@@ -104,23 +142,25 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
return;
fputs(tag, stdout);
- write_eolinfo(NULL, ent->name);
+ write_eolinfo(NULL, NULL, ent->name);
write_name(ent->name);
}
-static void show_other_files(struct dir_struct *dir)
+static void show_other_files(const struct index_state *istate,
+ const struct dir_struct *dir)
{
int i;
for (i = 0; i < dir->nr; i++) {
struct dir_entry *ent = dir->entries[i];
- if (!cache_name_is_other(ent->name, ent->len))
+ if (!index_name_is_other(istate, ent->name, ent->len))
continue;
show_dir_entry(tag_other, ent);
}
}
-static void show_killed_files(struct dir_struct *dir)
+static void show_killed_files(const struct index_state *istate,
+ const struct dir_struct *dir)
{
int i;
for (i = 0; i < dir->nr; i++) {
@@ -134,29 +174,29 @@ static void show_killed_files(struct dir_struct *dir)
/* If ent->name is prefix of an entry in the
* cache, it will be killed.
*/
- pos = cache_name_pos(ent->name, ent->len);
+ pos = index_name_pos(istate, ent->name, ent->len);
if (0 <= pos)
die("BUG: killed-file %.*s not found",
ent->len, ent->name);
pos = -pos - 1;
- while (pos < active_nr &&
- ce_stage(active_cache[pos]))
+ while (pos < istate->cache_nr &&
+ ce_stage(istate->cache[pos]))
pos++; /* skip unmerged */
- if (active_nr <= pos)
+ if (istate->cache_nr <= pos)
break;
/* pos points at a name immediately after
* ent->name in the cache. Does it expect
* ent->name to be a directory?
*/
- len = ce_namelen(active_cache[pos]);
+ len = ce_namelen(istate->cache[pos]);
if ((ent->len < len) &&
- !strncmp(active_cache[pos]->name,
+ !strncmp(istate->cache[pos]->name,
ent->name, ent->len) &&
- active_cache[pos]->name[ent->len] == '/')
+ istate->cache[pos]->name[ent->len] == '/')
killed = 1;
break;
}
- if (0 <= cache_name_pos(ent->name, sp - ent->name)) {
+ if (0 <= index_name_pos(istate, ent->name, sp - ent->name)) {
/* If any of the leading directories in
* ent->name is registered in the cache,
* ent->name will be killed.
@@ -230,7 +270,8 @@ static void show_gitlink(const struct cache_entry *ce)
exit(status);
}
-static void show_ce_entry(const char *tag, const struct cache_entry *ce)
+static void show_ce_entry(const struct index_state *istate,
+ const char *tag, const struct cache_entry *ce)
{
struct strbuf name = STRBUF_INIT;
int len = max_prefix_len;
@@ -248,22 +289,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)
len, ps_matched,
S_ISDIR(ce->ce_mode) ||
S_ISGITLINK(ce->ce_mode))) {
- if (tag && *tag && show_valid_bit &&
- (ce->ce_flags & CE_VALID)) {
- static char alttag[4];
- memcpy(alttag, tag, 3);
- if (isalpha(tag[0]))
- alttag[0] = tolower(tag[0]);
- else if (tag[0] == '?')
- alttag[0] = '!';
- else {
- alttag[0] = 'v';
- alttag[1] = tag[0];
- alttag[2] = ' ';
- alttag[3] = 0;
- }
- tag = alttag;
- }
+ tag = get_tag(ce, tag);
if (!show_stage) {
fputs(tag, stdout);
@@ -274,30 +300,22 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)
find_unique_abbrev(ce->oid.hash, abbrev),
ce_stage(ce));
}
- write_eolinfo(ce, ce->name);
+ write_eolinfo(istate, ce, ce->name);
write_name(ce->name);
- if (debug_mode) {
- const struct stat_data *sd = &ce->ce_stat_data;
-
- printf(" ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec);
- printf(" mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec);
- printf(" dev: %d\tino: %d\n", sd->sd_dev, sd->sd_ino);
- printf(" uid: %d\tgid: %d\n", sd->sd_uid, sd->sd_gid);
- printf(" size: %d\tflags: %x\n", sd->sd_size, ce->ce_flags);
- }
+ print_debug(ce);
}
strbuf_release(&name);
}
-static void show_ru_info(void)
+static void show_ru_info(const struct index_state *istate)
{
struct string_list_item *item;
- if (!the_index.resolve_undo)
+ if (!istate->resolve_undo)
return;
- for_each_string_list_item(item, the_index.resolve_undo) {
+ for_each_string_list_item(item, istate->resolve_undo) {
const char *path = item->string;
struct resolve_undo_info *ui = item->util;
int i, len;
@@ -319,13 +337,14 @@ static void show_ru_info(void)
}
}
-static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce)
+static int ce_excluded(struct dir_struct *dir, struct index_state *istate,
+ const struct cache_entry *ce)
{
int dtype = ce_to_dtype(ce);
- return is_excluded(dir, &the_index, ce->name, &dtype);
+ return is_excluded(dir, istate, ce->name, &dtype);
}
-static void show_files(struct dir_struct *dir)
+static void show_files(struct index_state *istate, struct dir_struct *dir)
{
int i;
@@ -333,33 +352,33 @@ static void show_files(struct dir_struct *dir)
if (show_others || show_killed) {
if (!show_others)
dir->flags |= DIR_COLLECT_KILLED_ONLY;
- fill_directory(dir, &the_index, &pathspec);
+ fill_directory(dir, istate, &pathspec);
if (show_others)
- show_other_files(dir);
+ show_other_files(istate, dir);
if (show_killed)
- show_killed_files(dir);
+ show_killed_files(istate, dir);
}
if (show_cached || show_stage) {
- for (i = 0; i < active_nr; i++) {
- const struct cache_entry *ce = active_cache[i];
+ for (i = 0; i < istate->cache_nr; i++) {
+ const struct cache_entry *ce = istate->cache[i];
if ((dir->flags & DIR_SHOW_IGNORED) &&
- !ce_excluded(dir, ce))
+ !ce_excluded(dir, istate, ce))
continue;
if (show_unmerged && !ce_stage(ce))
continue;
if (ce->ce_flags & CE_UPDATE)
continue;
- show_ce_entry(ce_stage(ce) ? tag_unmerged :
+ show_ce_entry(istate, ce_stage(ce) ? tag_unmerged :
(ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce);
}
}
if (show_deleted || show_modified) {
- for (i = 0; i < active_nr; i++) {
- const struct cache_entry *ce = active_cache[i];
+ for (i = 0; i < istate->cache_nr; i++) {
+ const struct cache_entry *ce = istate->cache[i];
struct stat st;
int err;
if ((dir->flags & DIR_SHOW_IGNORED) &&
- !ce_excluded(dir, ce))
+ !ce_excluded(dir, istate, ce))
continue;
if (ce->ce_flags & CE_UPDATE)
continue;
@@ -367,9 +386,9 @@ static void show_files(struct dir_struct *dir)
continue;
err = lstat(ce->name, &st);
if (show_deleted && err)
- show_ce_entry(tag_removed, ce);
- if (show_modified && ce_modified(ce, &st, 0))
- show_ce_entry(tag_modified, ce);
+ show_ce_entry(istate, tag_removed, ce);
+ if (show_modified && ie_modified(istate, ce, &st, 0))
+ show_ce_entry(istate, tag_modified, ce);
}
}
}
@@ -377,30 +396,31 @@ static void show_files(struct dir_struct *dir)
/*
* Prune the index to only contain stuff starting with "prefix"
*/
-static void prune_cache(const char *prefix, size_t prefixlen)
+static void prune_index(struct index_state *istate,
+ const char *prefix, size_t prefixlen)
{
int pos;
unsigned int first, last;
if (!prefix)
return;
- pos = cache_name_pos(prefix, prefixlen);
+ pos = index_name_pos(istate, prefix, prefixlen);
if (pos < 0)
pos = -pos-1;
first = pos;
- last = active_nr;
+ last = istate->cache_nr;
while (last > first) {
int next = (last + first) >> 1;
- const struct cache_entry *ce = active_cache[next];
+ const struct cache_entry *ce = istate->cache[next];
if (!strncmp(ce->name, prefix, prefixlen)) {
first = next+1;
continue;
}
last = next;
}
- memmove(active_cache, active_cache + pos,
+ memmove(istate->cache, istate->cache + pos,
(last - pos) * sizeof(struct cache_entry *));
- active_nr = last - pos;
+ istate->cache_nr = last - pos;
}
static int get_common_prefix_len(const char *common_prefix)
@@ -430,7 +450,8 @@ static int get_common_prefix_len(const char *common_prefix)
* that were given from the command line. We are not
* going to write this index out.
*/
-void overlay_tree_on_cache(const char *tree_name, const char *prefix)
+void overlay_tree_on_index(struct index_state *istate,
+ const char *tree_name, const char *prefix)
{
struct tree *tree;
struct object_id oid;
@@ -445,8 +466,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
die("bad tree-ish %s", tree_name);
/* Hoist the unmerged entries up to stage #3 to make room */
- for (i = 0; i < active_nr; i++) {
- struct cache_entry *ce = active_cache[i];
+ for (i = 0; i < istate->cache_nr; i++) {
+ struct cache_entry *ce = istate->cache[i];
if (!ce_stage(ce))
continue;
ce->ce_flags |= CE_STAGEMASK;
@@ -459,11 +480,11 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
PATHSPEC_PREFER_CWD, prefix, matchbuf);
} else
memset(&pathspec, 0, sizeof(pathspec));
- if (read_tree(tree, 1, &pathspec))
+ if (read_tree(tree, 1, &pathspec, istate))
die("unable to read tree entries %s", tree_name);
- for (i = 0; i < active_nr; i++) {
- struct cache_entry *ce = active_cache[i];
+ for (i = 0; i < istate->cache_nr; i++) {
+ struct cache_entry *ce = istate->cache[i];
switch (ce_stage(ce)) {
case 0:
last_stage0 = ce;
@@ -657,7 +678,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
max_prefix = common_prefix(&pathspec);
max_prefix_len = get_common_prefix_len(max_prefix);
- prune_cache(max_prefix, max_prefix_len);
+ prune_index(&the_index, max_prefix, max_prefix_len);
/* Treat unmatching pathspec elements as errors */
if (pathspec.nr && error_unmatch)
@@ -678,11 +699,11 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
*/
if (show_stage || show_unmerged)
die("ls-files --with-tree is incompatible with -s or -u");
- overlay_tree_on_cache(with_tree, max_prefix);
+ overlay_tree_on_index(&the_index, with_tree, max_prefix);
}
- show_files(&dir);
+ show_files(&the_index, &dir);
if (show_resolve_undo)
- show_ru_info();
+ show_ru_info(&the_index);
if (ps_matched) {
int bad;
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index ee7b293b1..ef965408e 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "blob.h"
#include "tree.h"
#include "commit.h"
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 0c36a70ad..6dbd167d3 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "refs.h"
#include "diff.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 47dde7c39..b08803e61 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "xdiff/xdiff.h"
#include "xdiff-interface.h"
#include "parse-options.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index 84970cd85..900bafdb4 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -7,6 +7,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "parse-options.h"
#include "builtin.h"
#include "lockfile.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index 61d20037a..dcf6736b5 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -4,6 +4,7 @@
* Copyright (C) 2006 Johannes Schindelin
*/
#include "builtin.h"
+#include "config.h"
#include "pathspec.h"
#include "lockfile.h"
#include "dir.h"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 7fc7e66e8..e21715f1d 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "tag.h"
#include "refs.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index c939a84b7..77573cf1e 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -8,6 +8,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "notes.h"
#include "blob.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index f672225de..f4a8441fe 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "attr.h"
#include "object.h"
#include "blob.h"
@@ -264,8 +265,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
* make sure no cached delta data remains from a
* previous attempt before a pack split occurred.
*/
- free(entry->delta_data);
- entry->delta_data = NULL;
+ FREE_AND_NULL(entry->delta_data);
entry->z_delta_size = 0;
} else if (entry->delta_data) {
size = entry->delta_size;
@@ -1375,12 +1375,10 @@ static void cleanup_preferred_base(void)
if (!pbase_tree_cache[i])
continue;
free(pbase_tree_cache[i]->tree_data);
- free(pbase_tree_cache[i]);
- pbase_tree_cache[i] = NULL;
+ FREE_AND_NULL(pbase_tree_cache[i]);
}
- free(done_pbase_paths);
- done_pbase_paths = NULL;
+ FREE_AND_NULL(done_pbase_paths);
done_pbase_paths_num = done_pbase_paths_alloc = 0;
}
@@ -1970,8 +1968,7 @@ static unsigned long free_unpacked(struct unpacked *n)
n->index = NULL;
if (n->data) {
freed_mem += n->entry->size;
- free(n->data);
- n->data = NULL;
+ FREE_AND_NULL(n->data);
}
n->entry = NULL;
n->depth = 0;
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 81552e02e..970d0d30b 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
{
diff --git a/builtin/pull.c b/builtin/pull.c
index 69417e4f3..2ce311a52 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -6,6 +6,7 @@
* Fetch one or more remote refs and merge it/them into the current HEAD.
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "parse-options.h"
#include "exec_cmd.h"
diff --git a/builtin/push.c b/builtin/push.c
index 258648d5f..03846e837 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -2,6 +2,7 @@
* "git push"
*/
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "run-command.h"
#include "builtin.h"
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 5bfd4c9f7..d5f618d08 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -5,6 +5,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "object.h"
#include "tree.h"
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c
index ca1ebb2fa..c82b4dce6 100644
--- a/builtin/rebase--helper.c
+++ b/builtin/rebase--helper.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "parse-options.h"
#include "sequencer.h"
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index b1706a573..71c0c768d 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "pack.h"
#include "refs.h"
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 920c16dac..44cdc2dbd 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "commit.h"
#include "refs.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index f1a88fe26..6273c0c23 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "parse-options.h"
#include "transport.h"
#include "remote.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 38ba4ef82..f17a68a17 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "parse-options.h"
#include "run-command.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index c921bc976..80a15cf35 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -9,6 +9,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "refs.h"
#include "parse-options.h"
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 1bf72423b..ffb66e290 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "parse-options.h"
#include "string-list.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 45001e520..7aeaea273 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -8,6 +8,7 @@
* Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
*/
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "tag.h"
#include "object.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index b250c515b..95d84d5cd 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index efdc14473..c78b7b33d 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "refs.h"
#include "quote.h"
diff --git a/builtin/revert.c b/builtin/revert.c
index 345d9586a..16028b9ea 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "parse-options.h"
#include "diff.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index b39f10fcb..52826d137 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds 2006
*/
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "dir.h"
#include "cache-tree.h"
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index b8e2e74fe..633e0c3cd 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "commit.h"
#include "refs.h"
#include "pkt-line.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 7cff1839f..43c4799ea 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "diff.h"
#include "string-list.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 4a6cc6f49..527f69e28 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,10 +1,12 @@
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "refs.h"
#include "builtin.h"
#include "color.h"
#include "argv-array.h"
#include "parse-options.h"
+#include "dir.h"
static const char* show_branch_usage[] = {
N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
@@ -421,14 +423,6 @@ static int append_tag_ref(const char *refname, const struct object_id *oid,
static const char *match_ref_pattern = NULL;
static int match_ref_slash = 0;
-static int count_slash(const char *s)
-{
- int cnt = 0;
- while (*s)
- if (*s++ == '/')
- cnt++;
- return cnt;
-}
static int append_matching_ref(const char *refname, const struct object_id *oid,
int flag, void *cb_data)
@@ -438,7 +432,7 @@ static int append_matching_ref(const char *refname, const struct object_id *oid,
* refs/tags/v0.99.9a and friends.
*/
const char *tail;
- int slash = count_slash(refname);
+ int slash = count_slashes(refname);
for (tail = refname; *tail && match_ref_slash < slash; )
if (*tail++ == '/')
slash--;
@@ -529,7 +523,7 @@ static void append_one_rev(const char *av)
int saved_matches = ref_name_cnt;
match_ref_pattern = av;
- match_ref_slash = count_slash(av);
+ match_ref_slash = count_slashes(av);
for_each_ref(append_matching_ref, NULL);
if (saved_matches == ref_name_cnt &&
ref_name_cnt < MAX_REVS)
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 1e62a008c..bdf032886 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "parse-options.h"
#include "strbuf.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 1b4d2b346..8517032b3 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "parse-options.h"
#include "quote.h"
#include "pathspec.h"
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 70addef15..df75cb9d4 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "cache.h"
#include "refs.h"
#include "parse-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 1f74a56db..01154ea8d 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -7,6 +7,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "refs.h"
#include "tag.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index 6fc6bcdf7..73f133419 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
static char *create_temp_file(unsigned char *sha1)
{
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 8bc999776..689a29fac 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "object.h"
#include "delta.h"
#include "pack.h"
@@ -112,8 +113,7 @@ static void *get_data(unsigned long size)
break;
if (ret != Z_OK) {
error("inflate returned %d", ret);
- free(buf);
- buf = NULL;
+ FREE_AND_NULL(buf);
if (!recover)
exit(1);
has_errors = 1;
diff --git a/builtin/update-index.c b/builtin/update-index.c
index f99b1e579..56721cf03 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "quote.h"
#include "cache-tree.h"
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 0b2ecf41a..40ccfc193 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "builtin.h"
#include "parse-options.h"
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index 6c8cc3edc..873070e51 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "parse-options.h"
diff --git a/builtin/var.c b/builtin/var.c
index aedbb53a2..6c6f46b4a 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -4,6 +4,7 @@
* Copyright (C) Eric Biederman, 2005
*/
#include "builtin.h"
+#include "config.h"
static const char var_usage[] = "git var (-l | <variable>)";
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 05b734e6d..ba38ac9b1 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -6,6 +6,7 @@
* Based on git-verify-tag
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "commit.h"
#include "run-command.h"
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index c94e15693..c2a1a5c50 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "run-command.h"
#include "parse-options.h"
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 5199553d9..f9a5f7535 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -6,6 +6,7 @@
* Based on git-verify-tag.sh
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "tag.h"
#include "run-command.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 793306ea5..c98e2ce5f 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "dir.h"
#include "parse-options.h"
@@ -299,10 +300,8 @@ static int add_worktree(const char *path, const char *refname,
}
is_junk = 0;
- free(junk_work_tree);
- free(junk_git_dir);
- junk_work_tree = NULL;
- junk_git_dir = NULL;
+ FREE_AND_NULL(junk_work_tree);
+ FREE_AND_NULL(junk_git_dir);
done:
if (ret || !opts->keep_locked) {
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index 084c0df78..bd0a78aa3 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -5,6 +5,7 @@
*/
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "tree.h"
#include "cache-tree.h"
#include "parse-options.h"
diff --git a/cache.h b/cache.h
index d6ba8a2f1..96055c222 100644
--- a/cache.h
+++ b/cache.h
@@ -525,12 +525,15 @@ extern void set_git_work_tree(const char *tree);
extern void setup_work_tree(void);
/*
- * Find GIT_DIR of the repository that contains the current working directory,
- * without changing the working directory or other global state. The result is
- * appended to gitdir. The return value is either NULL if no repository was
- * found, or pointing to the path inside gitdir's buffer.
- */
-extern const char *discover_git_directory(struct strbuf *gitdir);
+ * Find the commondir and gitdir of the repository that contains the current
+ * working directory, without changing the working directory or other global
+ * state. The result is appended to commondir and gitdir. If the discovered
+ * gitdir does not correspond to a worktree, then 'commondir' and 'gitdir' will
+ * both have the same result appended to the buffer. The return value is
+ * either 0 upon success and non-zero if no repository was found.
+ */
+extern int discover_git_directory(struct strbuf *commondir,
+ struct strbuf *gitdir);
extern const char *setup_git_directory_gently(int *);
extern const char *setup_git_directory(void);
extern char *prefix_path(const char *prefix, int len, const char *path);
@@ -1879,188 +1882,9 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje
/* Dumb servers support */
extern int update_server_info(int);
-/* git_config_parse_key() returns these negated: */
-#define CONFIG_INVALID_KEY 1
-#define CONFIG_NO_SECTION_OR_NAME 2
-/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
-#define CONFIG_NO_LOCK -1
-#define CONFIG_INVALID_FILE 3
-#define CONFIG_NO_WRITE 4
-#define CONFIG_NOTHING_SET 5
-#define CONFIG_INVALID_PATTERN 6
-#define CONFIG_GENERIC_ERROR 7
-
-#define CONFIG_REGEX_NONE ((void *)1)
-
-struct git_config_source {
- unsigned int use_stdin:1;
- const char *file;
- const char *blob;
-};
-
-enum config_origin_type {
- CONFIG_ORIGIN_BLOB,
- CONFIG_ORIGIN_FILE,
- CONFIG_ORIGIN_STDIN,
- CONFIG_ORIGIN_SUBMODULE_BLOB,
- CONFIG_ORIGIN_CMDLINE
-};
-
-struct config_options {
- unsigned int respect_includes : 1;
- const char *git_dir;
-};
-
-typedef int (*config_fn_t)(const char *, const char *, void *);
-extern int git_default_config(const char *, const char *, void *);
-extern int git_config_from_file(config_fn_t fn, const char *, void *);
-extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
- const char *name, const char *buf, size_t len, void *data);
-extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
- const unsigned char *sha1, void *data);
-extern void git_config_push_parameter(const char *text);
-extern int git_config_from_parameters(config_fn_t fn, void *data);
-extern void read_early_config(config_fn_t cb, void *data);
-extern void git_config(config_fn_t fn, void *);
-extern int git_config_with_options(config_fn_t fn, void *,
- struct git_config_source *config_source,
- const struct config_options *opts);
-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 *);
-extern int64_t git_config_int64(const char *, const char *);
-extern unsigned long git_config_ulong(const char *, const char *);
-extern ssize_t git_config_ssize_t(const char *, const char *);
-extern int git_config_bool_or_int(const char *, const char *, int *);
-extern int git_config_bool(const char *, const char *);
-extern int git_config_maybe_bool(const char *, const char *);
-extern int git_config_string(const char **, const char *, const char *);
-extern int git_config_pathname(const char **, const char *, const char *);
-extern int git_config_set_in_file_gently(const char *, const char *, const char *);
-extern void git_config_set_in_file(const char *, const char *, const char *);
-extern int git_config_set_gently(const char *, const char *);
-extern void git_config_set(const char *, const char *);
-extern int git_config_parse_key(const char *, char **, int *);
-extern int git_config_key_is_valid(const char *key);
-extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
-extern void git_config_set_multivar(const char *, const char *, const char *, int);
-extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
-extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
-extern int git_config_rename_section(const char *, const char *);
-extern int git_config_rename_section_in_file(const char *, const char *, const char *);
-extern const char *git_etc_gitconfig(void);
-extern int git_env_bool(const char *, int);
-extern unsigned long git_env_ulong(const char *, unsigned long);
-extern int git_config_system(void);
-extern int config_error_nonbool(const char *);
-#if defined(__GNUC__)
-#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
-#endif
extern const char *get_log_output_encoding(void);
extern const char *get_commit_output_encoding(void);
-extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
-
-enum config_scope {
- CONFIG_SCOPE_UNKNOWN = 0,
- CONFIG_SCOPE_SYSTEM,
- CONFIG_SCOPE_GLOBAL,
- CONFIG_SCOPE_REPO,
- CONFIG_SCOPE_CMDLINE,
-};
-
-extern enum config_scope current_config_scope(void);
-extern const char *current_config_origin_type(void);
-extern const char *current_config_name(void);
-
-struct config_include_data {
- int depth;
- config_fn_t fn;
- void *data;
- const struct config_options *opts;
-};
-#define CONFIG_INCLUDE_INIT { 0 }
-extern int git_config_include(const char *name, const char *value, void *data);
-
-/*
- * Match and parse a config key of the form:
- *
- * section.(subsection.)?key
- *
- * (i.e., what gets handed to a config_fn_t). The caller provides the section;
- * we return -1 if it does not match, 0 otherwise. The subsection and key
- * out-parameters are filled by the function (and *subsection is NULL if it is
- * missing).
- *
- * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
- * there is no subsection at all.
- */
-extern int parse_config_key(const char *var,
- const char *section,
- const char **subsection, int *subsection_len,
- const char **key);
-
-struct config_set_element {
- struct hashmap_entry ent;
- char *key;
- struct string_list value_list;
-};
-
-struct configset_list_item {
- struct config_set_element *e;
- int value_index;
-};
-
-/*
- * the contents of the list are ordered according to their
- * position in the config files and order of parsing the files.
- * (i.e. key-value pair at the last position of .git/config will
- * be at the last item of the list)
- */
-struct configset_list {
- struct configset_list_item *items;
- unsigned int nr, alloc;
-};
-
-struct config_set {
- struct hashmap config_hash;
- int hash_initialized;
- struct configset_list list;
-};
-
-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);
-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);
-extern int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest);
-extern int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
-extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
-extern int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
-extern int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
-
-extern int git_config_get_value(const char *key, const char **value);
-extern const struct string_list *git_config_get_value_multi(const char *key);
-extern void git_config_clear(void);
-extern void git_config_iter(config_fn_t fn, void *data);
-extern int git_config_get_string_const(const char *key, const char **dest);
-extern int git_config_get_string(const char *key, char **dest);
-extern int git_config_get_int(const char *key, int *dest);
-extern int git_config_get_ulong(const char *key, unsigned long *dest);
-extern int git_config_get_bool(const char *key, int *dest);
-extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
-extern int git_config_get_maybe_bool(const char *key, int *dest);
-extern int git_config_get_pathname(const char *key, const char **dest);
-extern int git_config_get_untracked_cache(void);
-extern int git_config_get_split_index(void);
-extern int git_config_get_max_percent_split_change(void);
-
-/* This dies if the configured or default date is in the future */
-extern int git_config_get_expiry(const char *key, const char **output);
-
/*
* This is a hack for test programs like test-dump-untracked-cache to
* ensure that they do not modify the untracked cache when reading it.
@@ -2068,16 +1892,6 @@ extern int git_config_get_expiry(const char *key, const char **output);
*/
extern int ignore_untracked_cache_config;
-struct key_value_info {
- const char *filename;
- int linenr;
- enum config_origin_type origin_type;
- enum config_scope scope;
-};
-
-extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3)));
-extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr);
-
extern int committer_ident_sufficiently_given(void);
extern int author_ident_sufficiently_given(void);
@@ -2193,7 +2007,8 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
#define ws_tab_width(rule) ((rule) & WS_TAB_WIDTH_MASK)
/* ls-files */
-void overlay_tree_on_cache(const char *tree_name, const char *prefix);
+void overlay_tree_on_index(struct index_state *istate,
+ const char *tree_name, const char *prefix);
char *alias_lookup(const char *alias);
int split_cmdline(char *cmdline, const char ***argv);
diff --git a/color.c b/color.c
index dee61557e..31b6207a0 100644
--- a/color.c
+++ b/color.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "color.h"
static int git_use_color_default = GIT_COLOR_AUTO;
diff --git a/column.c b/column.c
index d55ead18e..ff7bdab1a 100644
--- a/column.c
+++ b/column.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "column.h"
#include "string-list.h"
#include "parse-options.h"
diff --git a/combine-diff.c b/combine-diff.c
index ec9d93044..9e163d5ad 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1053,7 +1053,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
if (is_file) {
struct strbuf buf = STRBUF_INIT;
- if (convert_to_git(elem->path, result, len, &buf, safe_crlf)) {
+ if (convert_to_git(&the_index, elem->path, result, len, &buf, safe_crlf)) {
free(result);
result = strbuf_detach(&buf, &len);
result_size = len;
diff --git a/commit-slab.h b/commit-slab.h
index 42d16dcde..333d81e37 100644
--- a/commit-slab.h
+++ b/commit-slab.h
@@ -82,8 +82,7 @@ static MAYBE_UNUSED void clear_ ##slabname(struct slabname *s) \
for (i = 0; i < s->slab_count; i++) \
free(s->slab[i]); \
s->slab_count = 0; \
- free(s->slab); \
- s->slab = NULL; \
+ FREE_AND_NULL(s->slab); \
} \
\
static MAYBE_UNUSED elemtype *slabname## _at_peek(struct slabname *s, \
diff --git a/commit.c b/commit.c
index 99846d9bf..cbfd68993 100644
--- a/commit.c
+++ b/commit.c
@@ -287,8 +287,7 @@ void free_commit_buffer(struct commit *commit)
{
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
if (v) {
- free(v->buffer);
- v->buffer = NULL;
+ FREE_AND_NULL(v->buffer);
v->size = 0;
}
}
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index 4293b53b1..de61c15d3 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -6,6 +6,7 @@
#define PRECOMPOSE_UNICODE_C
#include "cache.h"
+#include "config.h"
#include "utf8.h"
#include "precompose_utf8.h"
diff --git a/config.c b/config.c
index 34a139c40..1cd40a5fe 100644
--- a/config.c
+++ b/config.c
@@ -6,6 +6,7 @@
*
*/
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "exec_cmd.h"
#include "strbuf.h"
@@ -218,8 +219,6 @@ static int include_by_gitdir(const struct config_options *opts,
if (opts->git_dir)
git_dir = opts->git_dir;
- else if (have_git_dir())
- git_dir = get_git_dir();
else
goto done;
@@ -395,8 +394,7 @@ static int git_config_parse_key_1(const char *key, char **store_key, int *basele
out_free_ret_1:
if (store_key) {
- free(*store_key);
- *store_key = NULL;
+ FREE_AND_NULL(*store_key);
}
return -CONFIG_INVALID_KEY;
}
@@ -604,7 +602,8 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
*/
cf->linenr--;
ret = fn(name->buf, value, data);
- cf->linenr++;
+ if (ret >= 0)
+ cf->linenr++;
return ret;
}
@@ -1545,10 +1544,8 @@ static int do_git_config_sequence(const struct config_options *opts,
char *user_config = expand_user_path("~/.gitconfig", 0);
char *repo_config;
- if (opts->git_dir)
- repo_config = mkpathdup("%s/config", opts->git_dir);
- else if (have_git_dir())
- repo_config = git_pathdup("config");
+ if (opts->commondir)
+ repo_config = mkpathdup("%s/config", opts->commondir);
else
repo_config = NULL;
@@ -1579,9 +1576,9 @@ static int do_git_config_sequence(const struct config_options *opts,
return ret;
}
-int git_config_with_options(config_fn_t fn, void *data,
- struct git_config_source *config_source,
- const struct config_options *opts)
+int config_with_options(config_fn_t fn, void *data,
+ struct git_config_source *config_source,
+ const struct config_options *opts)
{
struct config_include_data inc = CONFIG_INCLUDE_INIT;
@@ -1612,9 +1609,14 @@ static void git_config_raw(config_fn_t fn, void *data)
struct config_options opts = {0};
opts.respect_includes = 1;
- if (git_config_with_options(fn, data, NULL, &opts) < 0)
+ if (have_git_dir()) {
+ opts.commondir = get_git_common_dir();
+ opts.git_dir = get_git_dir();
+ }
+
+ if (config_with_options(fn, data, NULL, &opts) < 0)
/*
- * git_config_with_options() normally returns only
+ * config_with_options() normally returns only
* zero, as most errors are fatal, and
* non-fatal potential errors are guarded by "if"
* statements that are entered only when no error is
@@ -1653,11 +1655,13 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
void read_early_config(config_fn_t cb, void *data)
{
struct config_options opts = {0};
- struct strbuf buf = STRBUF_INIT;
+ struct strbuf commondir = STRBUF_INIT;
+ struct strbuf gitdir = STRBUF_INIT;
opts.respect_includes = 1;
- if (have_git_dir())
+ if (have_git_dir()) {
+ opts.commondir = get_git_common_dir();
opts.git_dir = get_git_dir();
/*
* When setup_git_directory() was not yet asked to discover the
@@ -1667,12 +1671,15 @@ void read_early_config(config_fn_t cb, void *data)
* notably, the current working directory is still the same after the
* call).
*/
- else if (discover_git_directory(&buf))
- opts.git_dir = buf.buf;
+ } else if (!discover_git_directory(&commondir, &gitdir)) {
+ opts.commondir = commondir.buf;
+ opts.git_dir = gitdir.buf;
+ }
- git_config_with_options(cb, data, NULL, &opts);
+ config_with_options(cb, data, NULL, &opts);
- strbuf_release(&buf);
+ strbuf_release(&commondir);
+ strbuf_release(&gitdir);
}
static void git_config_check_init(void);
diff --git a/config.h b/config.h
new file mode 100644
index 000000000..9e038cce2
--- /dev/null
+++ b/config.h
@@ -0,0 +1,194 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+/* git_config_parse_key() returns these negated: */
+#define CONFIG_INVALID_KEY 1
+#define CONFIG_NO_SECTION_OR_NAME 2
+/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
+#define CONFIG_NO_LOCK -1
+#define CONFIG_INVALID_FILE 3
+#define CONFIG_NO_WRITE 4
+#define CONFIG_NOTHING_SET 5
+#define CONFIG_INVALID_PATTERN 6
+#define CONFIG_GENERIC_ERROR 7
+
+#define CONFIG_REGEX_NONE ((void *)1)
+
+struct git_config_source {
+ unsigned int use_stdin:1;
+ const char *file;
+ const char *blob;
+};
+
+enum config_origin_type {
+ CONFIG_ORIGIN_BLOB,
+ CONFIG_ORIGIN_FILE,
+ CONFIG_ORIGIN_STDIN,
+ CONFIG_ORIGIN_SUBMODULE_BLOB,
+ CONFIG_ORIGIN_CMDLINE
+};
+
+struct config_options {
+ unsigned int respect_includes : 1;
+ const char *commondir;
+ const char *git_dir;
+};
+
+typedef int (*config_fn_t)(const char *, const char *, void *);
+extern int git_default_config(const char *, const char *, void *);
+extern int git_config_from_file(config_fn_t fn, const char *, void *);
+extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
+ const char *name, const char *buf, size_t len, void *data);
+extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
+ const unsigned char *sha1, void *data);
+extern void git_config_push_parameter(const char *text);
+extern int git_config_from_parameters(config_fn_t fn, void *data);
+extern void read_early_config(config_fn_t cb, void *data);
+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_ulong(const char *, unsigned long *);
+extern int git_parse_maybe_bool(const char *);
+extern int git_config_int(const char *, const char *);
+extern int64_t git_config_int64(const char *, const char *);
+extern unsigned long git_config_ulong(const char *, const char *);
+extern ssize_t git_config_ssize_t(const char *, const char *);
+extern int git_config_bool_or_int(const char *, const char *, int *);
+extern int git_config_bool(const char *, const char *);
+extern int git_config_maybe_bool(const char *, const char *);
+extern int git_config_string(const char **, const char *, const char *);
+extern int git_config_pathname(const char **, const char *, const char *);
+extern int git_config_set_in_file_gently(const char *, const char *, const char *);
+extern void git_config_set_in_file(const char *, const char *, const char *);
+extern int git_config_set_gently(const char *, const char *);
+extern void git_config_set(const char *, const char *);
+extern int git_config_parse_key(const char *, char **, int *);
+extern int git_config_key_is_valid(const char *key);
+extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
+extern void git_config_set_multivar(const char *, const char *, const char *, int);
+extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
+extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
+extern int git_config_rename_section(const char *, const char *);
+extern int git_config_rename_section_in_file(const char *, const char *, const char *);
+extern const char *git_etc_gitconfig(void);
+extern int git_env_bool(const char *, int);
+extern unsigned long git_env_ulong(const char *, unsigned long);
+extern int git_config_system(void);
+extern int config_error_nonbool(const char *);
+#if defined(__GNUC__)
+#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
+#endif
+
+extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
+
+enum config_scope {
+ CONFIG_SCOPE_UNKNOWN = 0,
+ CONFIG_SCOPE_SYSTEM,
+ CONFIG_SCOPE_GLOBAL,
+ CONFIG_SCOPE_REPO,
+ CONFIG_SCOPE_CMDLINE,
+};
+
+extern enum config_scope current_config_scope(void);
+extern const char *current_config_origin_type(void);
+extern const char *current_config_name(void);
+
+struct config_include_data {
+ int depth;
+ config_fn_t fn;
+ void *data;
+ const struct config_options *opts;
+};
+#define CONFIG_INCLUDE_INIT { 0 }
+extern int git_config_include(const char *name, const char *value, void *data);
+
+/*
+ * Match and parse a config key of the form:
+ *
+ * section.(subsection.)?key
+ *
+ * (i.e., what gets handed to a config_fn_t). The caller provides the section;
+ * we return -1 if it does not match, 0 otherwise. The subsection and key
+ * out-parameters are filled by the function (and *subsection is NULL if it is
+ * missing).
+ *
+ * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
+ * there is no subsection at all.
+ */
+extern int parse_config_key(const char *var,
+ const char *section,
+ const char **subsection, int *subsection_len,
+ const char **key);
+
+struct config_set_element {
+ struct hashmap_entry ent;
+ char *key;
+ struct string_list value_list;
+};
+
+struct configset_list_item {
+ struct config_set_element *e;
+ int value_index;
+};
+
+/*
+ * the contents of the list are ordered according to their
+ * position in the config files and order of parsing the files.
+ * (i.e. key-value pair at the last position of .git/config will
+ * be at the last item of the list)
+ */
+struct configset_list {
+ struct configset_list_item *items;
+ unsigned int nr, alloc;
+};
+
+struct config_set {
+ struct hashmap config_hash;
+ int hash_initialized;
+ struct configset_list list;
+};
+
+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);
+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);
+extern int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest);
+extern int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
+extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
+extern int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
+extern int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
+
+extern int git_config_get_value(const char *key, const char **value);
+extern const struct string_list *git_config_get_value_multi(const char *key);
+extern void git_config_clear(void);
+extern int git_config_get_string_const(const char *key, const char **dest);
+extern int git_config_get_string(const char *key, char **dest);
+extern int git_config_get_int(const char *key, int *dest);
+extern int git_config_get_ulong(const char *key, unsigned long *dest);
+extern int git_config_get_bool(const char *key, int *dest);
+extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
+extern int git_config_get_maybe_bool(const char *key, int *dest);
+extern int git_config_get_pathname(const char *key, const char **dest);
+extern int git_config_get_untracked_cache(void);
+extern int git_config_get_split_index(void);
+extern int git_config_get_max_percent_split_change(void);
+
+/* This dies if the configured or default date is in the future */
+extern int git_config_get_expiry(const char *key, const char **output);
+
+struct key_value_info {
+ const char *filename;
+ int linenr;
+ enum config_origin_type origin_type;
+ enum config_scope scope;
+};
+
+extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3)));
+extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr);
+
+#endif /* CONFIG_H */
diff --git a/configure.ac b/configure.ac
index 11d083fbe..2f55237e6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -922,9 +922,9 @@ AC_CACHE_CHECK([whether system succeeds to read fopen'ed directory],
[
AC_RUN_IFELSE(
[AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
- [[char c;
+ [[
FILE *f = fopen(".", "r");
- return f && fread(&c, 1, 1, f)]])],
+ return f)]])],
[ac_cv_fread_reads_directories=no],
[ac_cv_fread_reads_directories=yes])
])
diff --git a/connect.c b/connect.c
index c72b1d115..e78d3f43d 100644
--- a/connect.c
+++ b/connect.c
@@ -1,5 +1,6 @@
#include "git-compat-util.h"
#include "cache.h"
+#include "config.h"
#include "pkt-line.h"
#include "quote.h"
#include "refs.h"
diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci
index c03ba737e..f2d97e755 100644
--- a/contrib/coccinelle/free.cocci
+++ b/contrib/coccinelle/free.cocci
@@ -9,3 +9,18 @@ expression E;
@@
- if (!E)
free(E);
+
+@@
+type T;
+T *ptr;
+@@
+- free(ptr);
+- ptr = NULL;
++ FREE_AND_NULL(ptr);
+
+@@
+expression E;
+@@
+- free(E);
+- E = NULL;
++ FREE_AND_NULL(E);
diff --git a/contrib/diff-highlight/.gitignore b/contrib/diff-highlight/.gitignore
new file mode 100644
index 000000000..c07454824
--- /dev/null
+++ b/contrib/diff-highlight/.gitignore
@@ -0,0 +1,2 @@
+shebang.perl
+diff-highlight
diff --git a/contrib/diff-highlight/diff-highlight b/contrib/diff-highlight/DiffHighlight.pm
index 81bd8040e..663992e53 100755..100644
--- a/contrib/diff-highlight/diff-highlight
+++ b/contrib/diff-highlight/DiffHighlight.pm
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+package DiffHighlight;
use 5.008;
use warnings FATAL => 'all';
@@ -29,13 +29,14 @@ my @removed;
my @added;
my $in_hunk;
-# Some scripts may not realize that SIGPIPE is being ignored when launching the
-# pager--for instance scripts written in Python.
-$SIG{PIPE} = 'DEFAULT';
+our $line_cb = sub { print @_ };
+our $flush_cb = sub { local $| = 1 };
+
+sub handle_line {
+ local $_ = shift;
-while (<>) {
if (!$in_hunk) {
- print;
+ $line_cb->($_);
$in_hunk = /^$GRAPH*$COLOR*\@\@ /;
}
elsif (/^$GRAPH*$COLOR*-/) {
@@ -49,7 +50,7 @@ while (<>) {
@removed = ();
@added = ();
- print;
+ $line_cb->($_);
$in_hunk = /^$GRAPH*$COLOR*[\@ ]/;
}
@@ -62,15 +63,22 @@ while (<>) {
# place to flush. Flushing on a blank line is a heuristic that
# happens to match git-log output.
if (!length) {
- local $| = 1;
+ $flush_cb->();
}
}
-# Flush any queued hunk (this can happen when there is no trailing context in
-# the final diff of the input).
-show_hunk(\@removed, \@added);
+sub flush {
+ # Flush any queued hunk (this can happen when there is no trailing
+ # context in the final diff of the input).
+ show_hunk(\@removed, \@added);
+}
-exit 0;
+sub highlight_stdin {
+ while (<STDIN>) {
+ handle_line($_);
+ }
+ flush();
+}
# Ideally we would feed the default as a human-readable color to
# git-config as the fallback value. But diff-highlight does
@@ -88,7 +96,7 @@ sub show_hunk {
# If one side is empty, then there is nothing to compare or highlight.
if (!@$a || !@$b) {
- print @$a, @$b;
+ $line_cb->(@$a, @$b);
return;
}
@@ -97,17 +105,17 @@ sub show_hunk {
# stupid, and only handle multi-line hunks that remove and add the same
# number of lines.
if (@$a != @$b) {
- print @$a, @$b;
+ $line_cb->(@$a, @$b);
return;
}
my @queue;
for (my $i = 0; $i < @$a; $i++) {
my ($rm, $add) = highlight_pair($a->[$i], $b->[$i]);
- print $rm;
+ $line_cb->($rm);
push @queue, $add;
}
- print @queue;
+ $line_cb->(@queue);
}
sub highlight_pair {
diff --git a/contrib/diff-highlight/Makefile b/contrib/diff-highlight/Makefile
index 901872452..fbf5c5824 100644
--- a/contrib/diff-highlight/Makefile
+++ b/contrib/diff-highlight/Makefile
@@ -1,5 +1,20 @@
-# nothing to build
-all:
+all: diff-highlight
-test:
+PERL_PATH = /usr/bin/perl
+-include ../../config.mak
+
+PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
+
+diff-highlight: shebang.perl DiffHighlight.pm diff-highlight.perl
+ cat $^ >$@+
+ chmod +x $@+
+ mv $@+ $@
+
+shebang.perl: FORCE
+ @echo '#!$(PERL_PATH_SQ)' >$@+
+ @cmp $@+ $@ >/dev/null 2>/dev/null || mv $@+ $@
+
+test: all
$(MAKE) -C t
+
+.PHONY: FORCE
diff --git a/contrib/diff-highlight/README b/contrib/diff-highlight/README
index 836b97a73..d4c234317 100644
--- a/contrib/diff-highlight/README
+++ b/contrib/diff-highlight/README
@@ -99,6 +99,36 @@ newHighlight = "black #aaffaa"
---------------------------------------------
+Using diff-highlight as a module
+--------------------------------
+
+If you want to pre- or post- process the highlighted lines as part of
+another perl script, you can use the DiffHighlight module. You can
+either "require" it or just cat the module together with your script (to
+avoid run-time dependencies).
+
+Your script may set up one or more of the following variables:
+
+ - $DiffHighlight::line_cb - this should point to a function which is
+ called whenever DiffHighlight has lines (which may contain
+ highlights) to output. The default function prints each line to
+ stdout. Note that the function may be called with multiple lines.
+
+ - $DiffHighlight::flush_cb - this should point to a function which
+ flushes the output (because DiffHighlight believes it has completed
+ processing a logical chunk of input). The default function flushes
+ stdout.
+
+The script may then feed lines, one at a time, to DiffHighlight::handle_line().
+When lines are done processing, they will be fed to $line_cb. Note that
+DiffHighlight may queue up many input lines (to analyze a whole hunk)
+before calling $line_cb. After providing all lines, call
+DiffHighlight::flush() to flush any unprocessed lines.
+
+If you just want to process stdin, DiffHighlight::highlight_stdin()
+is a convenience helper which will loop and flush for you.
+
+
Bugs
----
diff --git a/contrib/diff-highlight/diff-highlight.perl b/contrib/diff-highlight/diff-highlight.perl
new file mode 100644
index 000000000..9b3e9c1f4
--- /dev/null
+++ b/contrib/diff-highlight/diff-highlight.perl
@@ -0,0 +1,8 @@
+package main;
+
+# Some scripts may not realize that SIGPIPE is being ignored when launching the
+# pager--for instance scripts written in Python.
+$SIG{PIPE} = 'DEFAULT';
+
+DiffHighlight::highlight_stdin();
+exit 0;
diff --git a/convert.c b/convert.c
index f1e168bc3..7d2a519da 100644
--- a/convert.c
+++ b/convert.c
@@ -1,4 +1,6 @@
+#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
+#include "config.h"
#include "attr.h"
#include "run-command.h"
#include "quote.h"
@@ -134,11 +136,12 @@ static const char *gather_convert_stats_ascii(const char *data, unsigned long si
}
}
-const char *get_cached_convert_stats_ascii(const char *path)
+const char *get_cached_convert_stats_ascii(const struct index_state *istate,
+ const char *path)
{
const char *ret;
unsigned long sz;
- void *data = read_blob_data_from_cache(path, &sz);
+ void *data = read_blob_data_from_index(istate, path, &sz);
ret = gather_convert_stats_ascii(data, sz);
free(data);
return ret;
@@ -217,13 +220,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,
}
}
-static int has_cr_in_index(const char *path)
+static int has_cr_in_index(const struct index_state *istate, const char *path)
{
unsigned long sz;
void *data;
int has_cr;
- data = read_blob_data_from_cache(path, &sz);
+ data = read_blob_data_from_index(istate, path, &sz);
if (!data)
return 0;
has_cr = memchr(data, '\r', sz) != NULL;
@@ -253,7 +256,8 @@ static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats,
}
-static int crlf_to_git(const char *path, const char *src, size_t len,
+static int crlf_to_git(const struct index_state *istate,
+ const char *path, const char *src, size_t len,
struct strbuf *buf,
enum crlf_action crlf_action, enum safe_crlf checksafe)
{
@@ -285,7 +289,8 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
* unless we want to renormalize in a merge or
* cherry-pick.
*/
- if ((checksafe != SAFE_CRLF_RENORMALIZE) && has_cr_in_index(path))
+ if ((checksafe != SAFE_CRLF_RENORMALIZE) &&
+ has_cr_in_index(istate, path))
convert_crlf_into_lf = 0;
}
if ((checksafe == SAFE_CRLF_WARN ||
@@ -1081,7 +1086,8 @@ const char *get_convert_attr_ascii(const char *path)
return "";
}
-int convert_to_git(const char *path, const char *src, size_t len,
+int convert_to_git(const struct index_state *istate,
+ const char *path, const char *src, size_t len,
struct strbuf *dst, enum safe_crlf checksafe)
{
int ret = 0;
@@ -1097,7 +1103,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
src = dst->buf;
len = dst->len;
}
- ret |= crlf_to_git(path, src, len, dst, ca.crlf_action, checksafe);
+ ret |= crlf_to_git(istate, path, src, len, dst, ca.crlf_action, checksafe);
if (ret && dst) {
src = dst->buf;
len = dst->len;
@@ -1105,7 +1111,8 @@ int convert_to_git(const char *path, const char *src, size_t len,
return ret | ident_to_git(path, src, len, dst, ca.ident);
}
-void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,
+void convert_to_git_filter_fd(const struct index_state *istate,
+ const char *path, int fd, struct strbuf *dst,
enum safe_crlf checksafe)
{
struct conv_attrs ca;
@@ -1117,7 +1124,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,
if (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN))
die("%s: clean filter '%s' failed", path, ca.drv->name);
- crlf_to_git(path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);
+ crlf_to_git(istate, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);
ident_to_git(path, dst->buf, dst->len, dst, ca.ident);
}
@@ -1160,14 +1167,15 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc
return convert_to_working_tree_internal(path, src, len, dst, 0);
}
-int renormalize_buffer(const char *path, const char *src, size_t len, struct strbuf *dst)
+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);
if (ret) {
src = dst->buf;
len = dst->len;
}
- return ret | convert_to_git(path, src, len, dst, SAFE_CRLF_RENORMALIZE);
+ return ret | convert_to_git(istate, path, src, len, dst, SAFE_CRLF_RENORMALIZE);
}
/*****************************************************************
diff --git a/convert.h b/convert.h
index 82871a11d..cecf59d1a 100644
--- a/convert.h
+++ b/convert.h
@@ -4,6 +4,8 @@
#ifndef CONVERT_H
#define CONVERT_H
+struct index_state;
+
enum safe_crlf {
SAFE_CRLF_FALSE = 0,
SAFE_CRLF_FAIL = 1,
@@ -33,23 +35,28 @@ enum eol {
};
extern enum eol core_eol;
-extern const char *get_cached_convert_stats_ascii(const char *path);
+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);
/* returns 1 if *dst was used */
-extern int convert_to_git(const char *path, const char *src, size_t len,
+extern int convert_to_git(const struct index_state *istate,
+ const char *path, const char *src, size_t len,
struct strbuf *dst, enum safe_crlf checksafe);
extern int convert_to_working_tree(const char *path, const char *src,
size_t len, struct strbuf *dst);
-extern int renormalize_buffer(const char *path, const char *src, size_t len,
+extern 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 char *path)
+static inline int would_convert_to_git(const struct index_state *istate,
+ const char *path)
{
- return convert_to_git(path, NULL, 0, NULL, 0);
+ 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 char *path, int fd,
+extern void convert_to_git_filter_fd(const struct index_state *istate,
+ const char *path, int fd,
struct strbuf *dst,
enum safe_crlf checksafe);
extern int would_convert_to_git_filter_fd(const char *path);
diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c
index f3814cc47..0d5c62509 100644
--- a/credential-cache--daemon.c
+++ b/credential-cache--daemon.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "tempfile.h"
#include "credential.h"
#include "unix-socket.h"
diff --git a/credential.c b/credential.c
index aa996669f..9747f47b1 100644
--- a/credential.c
+++ b/credential.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "credential.h"
#include "string-list.h"
#include "run-command.h"
@@ -93,8 +94,7 @@ static void credential_apply_config(struct credential *c)
c->configured = 1;
if (!c->use_http_path && proto_is_http(c->protocol)) {
- free(c->path);
- c->path = NULL;
+ FREE_AND_NULL(c->path);
}
}
@@ -314,10 +314,8 @@ void credential_reject(struct credential *c)
for (i = 0; i < c->helpers.nr; i++)
credential_do(c, c->helpers.items[i].string, "erase");
- free(c->username);
- c->username = NULL;
- free(c->password);
- c->password = NULL;
+ FREE_AND_NULL(c->username);
+ FREE_AND_NULL(c->password);
c->approved = 0;
}
diff --git a/daemon.c b/daemon.c
index ac7181a48..30747075f 100644
--- a/daemon.c
+++ b/daemon.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "pkt-line.h"
#include "run-command.h"
#include "strbuf.h"
diff --git a/date.c b/date.c
index 63fa99685..1fd6d6637 100644
--- a/date.c
+++ b/date.c
@@ -70,6 +70,12 @@ static struct tm *time_to_tm(timestamp_t time, int tz)
return gmtime(&t);
}
+static struct tm *time_to_tm_local(timestamp_t time)
+{
+ time_t t = time;
+ return localtime(&t);
+}
+
/*
* What value of "tz" was in effect back then at "time" in the
* local timezone?
@@ -214,7 +220,10 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
return timebuf.buf;
}
- tm = time_to_tm(time, tz);
+ if (mode->local)
+ tm = time_to_tm_local(time);
+ else
+ tm = time_to_tm(time, tz);
if (!tm) {
tm = time_to_tm(0, 0);
tz = 0;
@@ -246,7 +255,8 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
month_names[tm->tm_mon], tm->tm_year + 1900,
tm->tm_hour, tm->tm_min, tm->tm_sec, tz);
else if (mode->type == DATE_STRFTIME)
- strbuf_addftime(&timebuf, mode->strftime_fmt, tm);
+ strbuf_addftime(&timebuf, mode->strftime_fmt, tm, tz,
+ mode->local ? NULL : "");
else
strbuf_addf(&timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
weekday_names[tm->tm_wday],
diff --git a/diff-lib.c b/diff-lib.c
index 0c0e20f7c..2a52b0795 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -179,8 +179,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
free(dpath);
continue;
}
- free(dpath);
- dpath = NULL;
+ FREE_AND_NULL(dpath);
/*
* Show the diff for the 'ce' if we found the one
diff --git a/diff.c b/diff.c
index acedf86ae..00b4c8669 100644
--- a/diff.c
+++ b/diff.c
@@ -2,6 +2,7 @@
* Copyright (C) 2005 Junio C Hamano
*/
#include "cache.h"
+#include "config.h"
#include "tempfile.h"
#include "quote.h"
#include "diff.h"
@@ -1218,8 +1219,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
regfree(ecbdata->diff_words->word_regex);
free(ecbdata->diff_words->word_regex);
}
- free(ecbdata->diff_words);
- ecbdata->diff_words = NULL;
+ FREE_AND_NULL(ecbdata->diff_words);
}
}
@@ -2755,7 +2755,7 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in
* Similarly, if we'd have to convert the file contents anyway, that
* makes the optimization not worthwhile.
*/
- if (!want_file && would_convert_to_git(name))
+ if (!want_file && would_convert_to_git(&the_index, name))
return 0;
len = strlen(name);
@@ -2877,7 +2877,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
* point if the path requires us to run the content
* conversion.
*/
- if (size_only && !would_convert_to_git(s->path))
+ if (size_only && !would_convert_to_git(&the_index, s->path))
return 0;
/*
@@ -2904,7 +2904,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
/*
* Convert from working tree format to canonical git format
*/
- if (convert_to_git(s->path, s->data, s->size, &buf, crlf_warn)) {
+ if (convert_to_git(&the_index, s->path, s->data, s->size, &buf, crlf_warn)) {
size_t size = 0;
munmap(s->data, s->size);
s->should_munmap = 0;
@@ -2951,8 +2951,7 @@ void diff_free_filespec_blob(struct diff_filespec *s)
void diff_free_filespec_data(struct diff_filespec *s)
{
diff_free_filespec_blob(s);
- free(s->cnt_data);
- s->cnt_data = NULL;
+ FREE_AND_NULL(s->cnt_data);
}
static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 03d1e8d40..1e4678b7d 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -667,11 +667,9 @@ void diffcore_rename(struct diff_options *options)
for (i = 0; i < rename_dst_nr; i++)
free_filespec(rename_dst[i].two);
- free(rename_dst);
- rename_dst = NULL;
+ FREE_AND_NULL(rename_dst);
rename_dst_nr = rename_dst_alloc = 0;
- free(rename_src);
- rename_src = NULL;
+ FREE_AND_NULL(rename_src);
rename_src_nr = rename_src_alloc = 0;
return;
}
diff --git a/dir.c b/dir.c
index 175906381..332f9d809 100644
--- a/dir.c
+++ b/dir.c
@@ -9,6 +9,7 @@
*/
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "attr.h"
#include "refs.h"
@@ -52,6 +53,15 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
static int get_dtype(struct dirent *de, struct index_state *istate,
const char *path, int len);
+int count_slashes(const char *s)
+{
+ int cnt = 0;
+ while (*s)
+ if (*s++ == '/')
+ cnt++;
+ return cnt;
+}
+
int fspathcmp(const char *a, const char *b)
{
return ignore_case ? strcasecmp(a, b) : strcmp(a, b);
@@ -795,7 +805,7 @@ static int add_excludes(const char *fname, const char *base, int baselen,
(pos = index_name_pos(istate, fname, strlen(fname))) >= 0 &&
!ce_stage(istate->cache[pos]) &&
ce_uptodate(istate->cache[pos]) &&
- !would_convert_to_git(fname))
+ !would_convert_to_git(istate, fname))
hashcpy(sha1_stat->sha1,
istate->cache[pos]->oid.hash);
else
@@ -2117,8 +2127,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
for (i = j = 0; j < dir->nr; j++) {
if (i &&
check_dir_entry_contains(dir->entries[i - 1], dir->entries[j])) {
- free(dir->entries[j]);
- dir->entries[j] = NULL;
+ FREE_AND_NULL(dir->entries[j]);
} else {
dir->entries[i++] = dir->entries[j];
}
@@ -2144,8 +2153,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
dir->untracked->dir_invalidated))
istate->cache_changed |= UNTRACKED_CHANGED;
if (dir->untracked != istate->untracked) {
- free(dir->untracked);
- dir->untracked = NULL;
+ FREE_AND_NULL(dir->untracked);
}
}
return dir->nr;
@@ -2488,8 +2496,7 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
strbuf_addbuf(out, &untracked->ident);
strbuf_add(out, ouc, ouc_size(len));
- free(ouc);
- ouc = NULL;
+ FREE_AND_NULL(ouc);
if (!untracked->root) {
varint_len = encode_varint(0, varbuf);
diff --git a/dir.h b/dir.h
index a89c13e27..e3717055d 100644
--- a/dir.h
+++ b/dir.h
@@ -197,6 +197,9 @@ struct dir_struct {
unsigned unmanaged_exclude_files;
};
+/*Count the number of slashes for string s*/
+extern int count_slashes(const char *s);
+
/*
* The ordering of these constants is significant, with
* higher-numbered match types signifying "closer" (i.e. more
diff --git a/environment.c b/environment.c
index aa478e71d..d40b21fb7 100644
--- a/environment.c
+++ b/environment.c
@@ -8,6 +8,7 @@
* are.
*/
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "fmt-merge-msg.h"
#include "commit.h"
diff --git a/fast-import.c b/fast-import.c
index 9a22fc92c..a959161b4 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -154,6 +154,7 @@ Format of STDIN stream:
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "object.h"
#include "blob.h"
@@ -280,7 +281,7 @@ struct recent_command {
};
/* Configured limits on output */
-static unsigned long max_depth = 10;
+static unsigned long max_depth = 50;
static off_t max_packsize;
static int unpack_limit = 100;
static int force_update;
@@ -1063,8 +1064,7 @@ discard_pack:
close(pack_data->pack_fd);
unlink_or_warn(pack_data->pack_name);
}
- free(pack_data);
- pack_data = NULL;
+ FREE_AND_NULL(pack_data);
running = 0;
/* We can't carry a delta across packfiles. */
@@ -1149,8 +1149,7 @@ static int store_object(
/* We cannot carry a delta into the new pack. */
if (delta) {
- free(delta);
- delta = NULL;
+ FREE_AND_NULL(delta);
git_deflate_init(&s, pack_compression_level);
s.next_in = (void *)dat->buf;
diff --git a/fetch-pack.c b/fetch-pack.c
index cd86865be..fbbc99c88 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "refs.h"
#include "pkt-line.h"
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 79d675b5b..0e8543c86 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1081,7 +1081,7 @@ EOF2
open $fh, '<', $hunkfile
or die sprintf(__("failed to open hunk edit file for reading: %s"), $!);
- my @newtext = grep { !/^$comment_line_char/ } <$fh>;
+ my @newtext = grep { !/^\Q$comment_line_char\E/ } <$fh>;
close $fh;
unlink $hunkfile;
@@ -1136,6 +1136,7 @@ sub prompt_yesno {
while (1) {
print colored $prompt_color, $prompt;
my $line = prompt_single_character;
+ return undef unless defined $line;
return 0 if $line =~ /^n/i;
return 1 if $line =~ /^y/i;
}
diff --git a/git-compat-util.h b/git-compat-util.h
index 51ba4e6b3..047172d17 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -808,6 +808,12 @@ extern char *xgetcwd(void);
extern FILE *fopen_for_writing(const char *path);
extern FILE *fopen_or_warn(const char *path, const char *mode);
+/*
+ * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note
+ * that ptr is used twice, so don't pass e.g. ptr++.
+ */
+#define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)
+
#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))
#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index aafaf708d..3a74602ef 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -81,12 +81,13 @@ set_ident () {
finish_ident COMMITTER
}
-USAGE="[--env-filter <command>] [--tree-filter <command>]
- [--index-filter <command>] [--parent-filter <command>]
- [--msg-filter <command>] [--commit-filter <command>]
- [--tag-name-filter <command>] [--subdirectory-filter <directory>]
- [--original <namespace>] [-d <directory>] [-f | --force]
- [<rev-list options>...]"
+USAGE="[--setup <command>] [--env-filter <command>]
+ [--tree-filter <command>] [--index-filter <command>]
+ [--parent-filter <command>] [--msg-filter <command>]
+ [--commit-filter <command>] [--tag-name-filter <command>]
+ [--subdirectory-filter <directory>] [--original <namespace>]
+ [-d <directory>] [-f | --force]
+ [--] [<rev-list options>...]"
OPTIONS_SPEC=
. git-sh-setup
@@ -96,6 +97,7 @@ if [ "$(is_bare_repository)" = false ]; then
fi
tempdir=.git-rewrite
+filter_setup=
filter_env=
filter_tree=
filter_index=
@@ -148,6 +150,9 @@ do
-d)
tempdir="$OPTARG"
;;
+ --setup)
+ filter_setup="$OPTARG"
+ ;;
--env-filter)
filter_env="$OPTARG"
;;
@@ -317,6 +322,9 @@ else
need_index=
fi
+eval "$filter_setup" < /dev/null ||
+ die "filter setup failed: $filter_setup"
+
while read commit parents; do
git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
diff --git a/git-rebase.sh b/git-rebase.sh
index db1deed84..2cf73b88e 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -166,14 +166,14 @@ apply_autostash () {
stash_sha1=$(cat "$state_dir/autostash")
if git stash apply $stash_sha1 2>&1 >/dev/null
then
- echo "$(gettext 'Applied autostash.')"
+ echo "$(gettext 'Applied autostash.')" >&2
else
git stash store -m "autostash" -q $stash_sha1 ||
die "$(eval_gettext "Cannot store \$stash_sha1")"
gettext 'Applying autostash resulted in conflicts.
Your changes are safe in the stash.
You can run "git stash pop" or "git stash drop" at any time.
-'
+' >&2
fi
fi
}
diff --git a/git-stash.sh b/git-stash.sh
index 2fb651b2b..9b6c2da7b 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -19,6 +19,7 @@ OPTIONS_SPEC=
START_DIR=$(pwd)
. git-sh-setup
require_work_tree
+prefix=$(git rev-parse --show-prefix) || exit 1
cd_to_toplevel
TMP="$GIT_DIR/.git-stash.$$"
@@ -273,6 +274,8 @@ push_stash () {
shift
done
+ eval "set $(git rev-parse --sq --prefix "$prefix" -- "$@")"
+
if test -n "$patch_mode" && test -n "$untracked"
then
die "$(gettext "Can't use --patch and --include-untracked or --all at the same time")"
@@ -481,7 +484,7 @@ parse_flags_and_rev()
case $# in
0)
- have_stash || die "$(gettext "No stash found.")"
+ have_stash || die "$(gettext "No stash entries found.")"
set -- ${ref_stash}@{0}
;;
1)
@@ -573,7 +576,7 @@ apply_stash () {
GIT_INDEX_FILE="$TMPindex" git-read-tree "$u_tree" &&
GIT_INDEX_FILE="$TMPindex" git checkout-index --all &&
rm -f "$TMPindex" ||
- die "$(gettext "Could not restore untracked files from stash")"
+ die "$(gettext "Could not restore untracked files from stash entry")"
fi
eval "
@@ -627,7 +630,7 @@ pop_stash() {
drop_stash "$@"
else
status=$?
- say "$(gettext "The stash is kept in case you need it again.")"
+ say "$(gettext "The stash entry is kept in case you need it again.")"
exit $status
fi
}
diff --git a/git-submodule.sh b/git-submodule.sh
index c0d0e9a4c..e131760ee 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -213,7 +213,8 @@ cmd_add()
die "$(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")"
fi
- if test -z "$force" && ! git add --dry-run --ignore-missing "$sm_path" > /dev/null 2>&1
+ if test -z "$force" &&
+ ! git add --dry-run --ignore-missing --no-warn-embedded-repo "$sm_path" > /dev/null 2>&1
then
eval_gettextln "The following path is ignored by one of your .gitignore files:
\$sm_path
@@ -267,7 +268,7 @@ or you are unsure what this means choose another name with the '--name' option."
fi
git config submodule."$sm_name".url "$realrepo"
- git add $force "$sm_path" ||
+ git add --no-warn-embedded-repo $force "$sm_path" ||
die "$(eval_gettext "Failed to add submodule '\$sm_path'")"
git config -f .gitmodules submodule."$sm_name".path "$sm_path" &&
diff --git a/git.c b/git.c
index 1b8b7f51a..5be27b07e 100644
--- a/git.c
+++ b/git.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "exec_cmd.h"
#include "help.h"
#include "run-command.h"
@@ -16,53 +17,9 @@ const char git_more_info_string[] =
"to read about a specific subcommand or concept.");
static int use_pager = -1;
-static char *orig_cwd;
-static const char *env_names[] = {
- GIT_DIR_ENVIRONMENT,
- GIT_WORK_TREE_ENVIRONMENT,
- GIT_IMPLICIT_WORK_TREE_ENVIRONMENT,
- GIT_PREFIX_ENVIRONMENT
-};
-static char *orig_env[4];
-static int save_restore_env_balance;
static void list_builtins(void);
-static void save_env_before_alias(void)
-{
- int i;
-
- assert(save_restore_env_balance == 0);
- save_restore_env_balance = 1;
- orig_cwd = xgetcwd();
- for (i = 0; i < ARRAY_SIZE(env_names); i++) {
- orig_env[i] = getenv(env_names[i]);
- orig_env[i] = xstrdup_or_null(orig_env[i]);
- }
-}
-
-static void restore_env(int external_alias)
-{
- int i;
-
- assert(save_restore_env_balance == 1);
- save_restore_env_balance = 0;
- if (!external_alias && orig_cwd && chdir(orig_cwd))
- die_errno("could not move to %s", orig_cwd);
- free(orig_cwd);
- for (i = 0; i < ARRAY_SIZE(env_names); i++) {
- if (external_alias &&
- !strcmp(env_names[i], GIT_PREFIX_ENVIRONMENT))
- continue;
- if (orig_env[i]) {
- setenv(env_names[i], orig_env[i], 1);
- free(orig_env[i]);
- } else {
- unsetenv(env_names[i]);
- }
- }
-}
-
static void commit_pager_choice(void) {
switch (use_pager) {
case 0:
@@ -255,19 +212,18 @@ static int handle_alias(int *argcp, const char ***argv)
const char **new_argv;
const char *alias_command;
char *alias_string;
- int unused_nongit;
-
- save_env_before_alias();
- setup_git_directory_gently(&unused_nongit);
alias_command = (*argv)[0];
alias_string = alias_lookup(alias_command);
if (alias_string) {
if (alias_string[0] == '!') {
struct child_process child = CHILD_PROCESS_INIT;
+ int nongit_ok;
+
+ /* Aliases expect GIT_PREFIX, GIT_DIR etc to be set */
+ setup_git_directory_gently(&nongit_ok);
commit_pager_choice();
- restore_env(1);
child.use_shell = 1;
argv_array_push(&child.args, alias_string + 1);
@@ -313,8 +269,6 @@ static int handle_alias(int *argcp, const char ***argv)
ret = 1;
}
- restore_env(0);
-
errno = saved_errno;
return ret;
diff --git a/gpg-interface.c b/gpg-interface.c
index e44cc27da..d936f3a32 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "run-command.h"
#include "strbuf.h"
#include "gpg-interface.h"
@@ -13,16 +14,11 @@ static const char *gpg_program = "gpg";
void signature_check_clear(struct signature_check *sigc)
{
- free(sigc->payload);
- free(sigc->gpg_output);
- free(sigc->gpg_status);
- free(sigc->signer);
- free(sigc->key);
- sigc->payload = NULL;
- sigc->gpg_output = NULL;
- sigc->gpg_status = NULL;
- sigc->signer = NULL;
- sigc->key = NULL;
+ FREE_AND_NULL(sigc->payload);
+ FREE_AND_NULL(sigc->gpg_output);
+ FREE_AND_NULL(sigc->gpg_status);
+ FREE_AND_NULL(sigc->signer);
+ FREE_AND_NULL(sigc->key);
}
static struct {
diff --git a/graph.c b/graph.c
index 8b9049dd2..e7e20650d 100644
--- a/graph.c
+++ b/graph.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "color.h"
#include "graph.h"
diff --git a/grep.c b/grep.c
index d7ef21358..98733db62 100644
--- a/grep.c
+++ b/grep.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "grep.h"
#include "userdiff.h"
#include "xdiff-interface.h"
@@ -508,7 +509,7 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
if (!p->pcre2_jit_stack)
die("Couldn't allocate PCRE2 JIT stack");
p->pcre2_match_context = pcre2_match_context_create(NULL);
- if (!p->pcre2_jit_stack)
+ if (!p->pcre2_match_context)
die("Couldn't allocate PCRE2 match context");
pcre2_jit_stack_assign(p->pcre2_match_context, NULL, p->pcre2_jit_stack);
} else if (p->pcre2_jit_on != 0) {
@@ -1939,12 +1940,9 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type,
void grep_source_clear(struct grep_source *gs)
{
- free(gs->name);
- gs->name = NULL;
- free(gs->path);
- gs->path = NULL;
- free(gs->identifier);
- gs->identifier = NULL;
+ FREE_AND_NULL(gs->name);
+ FREE_AND_NULL(gs->path);
+ FREE_AND_NULL(gs->identifier);
grep_source_clear_data(gs);
}
@@ -1954,8 +1952,7 @@ void grep_source_clear_data(struct grep_source *gs)
case GREP_SOURCE_FILE:
case GREP_SOURCE_OID:
case GREP_SOURCE_SUBMODULE:
- free(gs->buf);
- gs->buf = NULL;
+ FREE_AND_NULL(gs->buf);
gs->size = 0;
break;
case GREP_SOURCE_BUF:
diff --git a/help.c b/help.c
index f637fc800..88a3aeaeb 100644
--- a/help.c
+++ b/help.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "exec_cmd.h"
#include "run-command.h"
@@ -268,9 +269,8 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
for (i = 0; i < old->cnt; i++)
cmds->names[cmds->cnt++] = old->names[i];
- free(old->names);
+ FREE_AND_NULL(old->names);
old->cnt = 0;
- old->names = NULL;
}
/* An empirically derived magic number */
@@ -290,7 +290,7 @@ const char *help_unknown_cmd(const char *cmd)
memset(&other_cmds, 0, sizeof(other_cmds));
memset(&aliases, 0, sizeof(aliases));
- git_config(git_unknown_cmd_config, NULL);
+ read_early_config(git_unknown_cmd_config, NULL);
load_command_list("git-", &main_cmds, &other_cmds);
@@ -356,12 +356,18 @@ const char *help_unknown_cmd(const char *cmd)
clean_cmdnames(&main_cmds);
fprintf_ln(stderr,
_("WARNING: You called a Git command named '%s', "
- "which does not exist.\n"
- "Continuing under the assumption that you meant '%s'"),
- cmd, assumed);
- if (autocorrect > 0) {
- fprintf_ln(stderr, _("in %0.1f seconds automatically..."),
- (float)autocorrect/10.0);
+ "which does not exist."),
+ cmd);
+ if (autocorrect < 0)
+ fprintf_ln(stderr,
+ _("Continuing under the assumption that "
+ "you meant '%s'."),
+ assumed);
+ else {
+ fprintf_ln(stderr,
+ _("Continuing in %0.1f seconds, "
+ "assuming that you meant '%s'."),
+ (float)autocorrect/10.0, assumed);
sleep_millisec(autocorrect * 100);
}
return assumed;
diff --git a/http-backend.c b/http-backend.c
index ba5ff1aa2..519025d2c 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "pkt-line.h"
#include "object.h"
diff --git a/http-fetch.c b/http-fetch.c
index 3b556d661..8af380050 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "exec_cmd.h"
#include "http.h"
#include "walker.h"
diff --git a/http-push.c b/http-push.c
index 67c4d4b47..c91f40a61 100644
--- a/http-push.c
+++ b/http-push.c
@@ -291,8 +291,7 @@ static void start_mkcol(struct transfer_request *request)
request->state = RUN_MKCOL;
} else {
request->state = ABORTED;
- free(request->url);
- request->url = NULL;
+ FREE_AND_NULL(request->url);
}
}
#endif
@@ -409,8 +408,7 @@ static void start_put(struct transfer_request *request)
request->state = RUN_PUT;
} else {
request->state = ABORTED;
- free(request->url);
- request->url = NULL;
+ FREE_AND_NULL(request->url);
}
}
@@ -432,8 +430,7 @@ static void start_move(struct transfer_request *request)
request->state = RUN_MOVE;
} else {
request->state = ABORTED;
- free(request->url);
- request->url = NULL;
+ FREE_AND_NULL(request->url);
}
}
@@ -526,8 +523,7 @@ static void finish_request(struct transfer_request *request)
/* URL is reused for MOVE after PUT */
if (request->state != RUN_PUT) {
- free(request->url);
- request->url = NULL;
+ FREE_AND_NULL(request->url);
}
if (request->state == RUN_MKCOL) {
@@ -803,8 +799,7 @@ xml_start_tag(void *userData, const char *name, const char **atts)
}
xsnprintf(ctx->name + old_namelen, ctx->len - old_namelen, ".%s", c);
- free(ctx->cdata);
- ctx->cdata = NULL;
+ FREE_AND_NULL(ctx->cdata);
ctx->userFunc(ctx, 0);
}
@@ -932,8 +927,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
free(lock->token);
free(lock->owner);
free(url);
- free(lock);
- lock = NULL;
+ FREE_AND_NULL(lock);
} else {
lock->url = url;
lock->start_time = time(NULL);
@@ -1105,8 +1099,7 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)
ls->dentry_flags |= IS_DIR;
}
} else if (!strcmp(ctx->name, DAV_PROPFIND_RESP)) {
- free(ls->dentry_name);
- ls->dentry_name = NULL;
+ FREE_AND_NULL(ls->dentry_name);
ls->dentry_flags = 0;
}
}
@@ -1547,8 +1540,7 @@ static void fetch_symref(const char *path, char **symref, struct object_id *oid)
curl_errorstr);
free(url);
- free(*symref);
- *symref = NULL;
+ FREE_AND_NULL(*symref);
oidclr(oid);
if (buffer.len == 0)
diff --git a/http.c b/http.c
index d2e11ec6f..c6c010f88 100644
--- a/http.c
+++ b/http.c
@@ -1,5 +1,6 @@
#include "git-compat-util.h"
#include "http.h"
+#include "config.h"
#include "pack.h"
#include "sideband.h"
#include "run-command.h"
@@ -1026,8 +1027,7 @@ void http_cleanup(void)
if (proxy_auth.password) {
memset(proxy_auth.password, 0, strlen(proxy_auth.password));
- free(proxy_auth.password);
- proxy_auth.password = NULL;
+ FREE_AND_NULL(proxy_auth.password);
}
free((void *)curl_proxyuserpwd);
@@ -1038,13 +1038,11 @@ void http_cleanup(void)
if (cert_auth.password != NULL) {
memset(cert_auth.password, 0, strlen(cert_auth.password));
- free(cert_auth.password);
- cert_auth.password = NULL;
+ FREE_AND_NULL(cert_auth.password);
}
ssl_cert_password_required = 0;
- free(cached_accept_language);
- cached_accept_language = NULL;
+ FREE_AND_NULL(cached_accept_language);
}
struct active_request_slot *get_active_slot(void)
@@ -1896,8 +1894,7 @@ static char *fetch_pack_index(unsigned char *sha1, const char *base_url)
if (http_get_file(url, tmp, NULL) != HTTP_OK) {
error("Unable to get pack index %s", url);
- free(tmp);
- tmp = NULL;
+ FREE_AND_NULL(tmp);
}
free(url);
@@ -2328,8 +2325,7 @@ void release_http_object_request(struct http_object_request *freq)
freq->localfile = -1;
}
if (freq->url != NULL) {
- free(freq->url);
- freq->url = NULL;
+ FREE_AND_NULL(freq->url);
}
if (freq->slot != NULL) {
freq->slot->callback_func = NULL;
diff --git a/ident.c b/ident.c
index 91c760905..327abe557 100644
--- a/ident.c
+++ b/ident.c
@@ -6,6 +6,7 @@
* Copyright (C) 2005 Linus Torvalds
*/
#include "cache.h"
+#include "config.h"
static struct strbuf git_default_name = STRBUF_INIT;
static struct strbuf git_default_email = STRBUF_INIT;
diff --git a/imap-send.c b/imap-send.c
index 857591660..351e84aea 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -23,6 +23,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "credential.h"
#include "exec_cmd.h"
#include "run-command.h"
@@ -776,8 +777,7 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
offsetof(struct imap_cmd, next));
if (cmdp->cb.data) {
n = socket_write(&imap->buf.sock, cmdp->cb.data, cmdp->cb.dlen);
- free(cmdp->cb.data);
- cmdp->cb.data = NULL;
+ FREE_AND_NULL(cmdp->cb.data);
if (n != (int)cmdp->cb.dlen)
return RESP_BAD;
} else if (cmdp->cb.cont) {
diff --git a/line-log.c b/line-log.c
index 2588ce076..ab0709f9a 100644
--- a/line-log.c
+++ b/line-log.c
@@ -34,9 +34,8 @@ void range_set_init(struct range_set *rs, size_t prealloc)
void range_set_release(struct range_set *rs)
{
- free(rs->ranges);
+ FREE_AND_NULL(rs->ranges);
rs->alloc = rs->nr = 0;
- rs->ranges = NULL;
}
/* dst must be uninitialized! */
@@ -610,8 +609,7 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
line_log_data_insert(&ranges, full_name, begin, end);
free_filespec(spec);
- free(ends);
- ends = NULL;
+ FREE_AND_NULL(ends);
}
for (p = ranges; p; p = p->next)
diff --git a/ll-merge.c b/ll-merge.c
index ac0d4a5d7..9fb855a90 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -5,6 +5,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "attr.h"
#include "xdiff-interface.h"
#include "run-command.h"
@@ -209,8 +210,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
result->size = st.st_size;
result->ptr = xmallocz(result->size);
if (read_in_full(fd, result->ptr, result->size) != result->size) {
- free(result->ptr);
- result->ptr = NULL;
+ FREE_AND_NULL(result->ptr);
result->size = 0;
}
close_bad:
@@ -339,7 +339,7 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr
static void normalize_file(mmfile_t *mm, const char *path)
{
struct strbuf strbuf = STRBUF_INIT;
- if (renormalize_buffer(path, mm->ptr, mm->size, &strbuf)) {
+ if (renormalize_buffer(&the_index, path, mm->ptr, mm->size, &strbuf)) {
free(mm->ptr);
mm->size = strbuf.len;
mm->ptr = strbuf_detach(&strbuf, NULL);
diff --git a/log-tree.c b/log-tree.c
index 2903874ec..410ab4f02 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "diff.h"
#include "commit.h"
#include "tag.h"
diff --git a/mailinfo.c b/mailinfo.c
index f92cb9f72..1652ec11f 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "utf8.h"
#include "strbuf.h"
#include "mailinfo.h"
@@ -919,8 +920,7 @@ again:
/* we hit an end boundary */
/* pop the current boundary off the stack */
strbuf_release(*(mi->content_top));
- free(*(mi->content_top));
- *(mi->content_top) = NULL;
+ FREE_AND_NULL(*(mi->content_top));
/* technically won't happen as is_multipart_boundary()
will fail first. But just in case..
diff --git a/merge-recursive.c b/merge-recursive.c
index 5cc86df2d..59e5ee41a 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -4,6 +4,7 @@
* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
*/
#include "cache.h"
+#include "config.h"
#include "advice.h"
#include "lockfile.h"
#include "cache-tree.h"
@@ -1639,8 +1640,8 @@ static int blob_unchanged(struct merge_options *opt,
* performed. Comparison can be skipped if both files are
* unchanged since their sha1s have already been compared.
*/
- if (renormalize_buffer(path, o.buf, o.len, &o) |
- renormalize_buffer(path, a.buf, a.len, &a))
+ if (renormalize_buffer(&the_index, path, o.buf, o.len, &o) |
+ renormalize_buffer(&the_index, path, a.buf, a.len, &a))
ret = (o.len == a.len && !memcmp(o.buf, a.buf, o.len));
error_return:
diff --git a/mergetools/meld b/mergetools/meld
index bc178e888..7a08470f8 100644
--- a/mergetools/meld
+++ b/mergetools/meld
@@ -10,7 +10,7 @@ merge_cmd () {
if test "$meld_has_output_option" = true
then
- "$merge_tool_path" --output "$MERGED" \
+ "$merge_tool_path" --output="$MERGED" \
"$LOCAL" "$BASE" "$REMOTE"
else
"$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE"
diff --git a/notes-utils.c b/notes-utils.c
index 9ebf84195..9765deb41 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "refs.h"
#include "notes-utils.h"
diff --git a/notes.c b/notes.c
index 4b3a1adda..8f47c202c 100644
--- a/notes.c
+++ b/notes.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "notes.h"
#include "blob.h"
#include "tree.h"
diff --git a/object.c b/object.c
index 06ba3a11d..f81877741 100644
--- a/object.c
+++ b/object.c
@@ -377,8 +377,7 @@ void object_array_clear(struct object_array *array)
int i;
for (i = 0; i < array->nr; i++)
object_array_release_entry(&array->objects[i]);
- free(array->objects);
- array->objects = NULL;
+ FREE_AND_NULL(array->objects);
array->nr = array->alloc = 0;
}
diff --git a/pager.c b/pager.c
index c113d898a..4dd9e1b26 100644
--- a/pager.c
+++ b/pager.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "run-command.h"
#include "sigchain.h"
diff --git a/parse-options.c b/parse-options.c
index e5ad34a2c..0dd9fc6a0 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1,6 +1,7 @@
#include "git-compat-util.h"
#include "parse-options.h"
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "color.h"
#include "utf8.h"
diff --git a/pathspec.c b/pathspec.c
index 828405021..a5f4df31e 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,5 +1,6 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "pathspec.h"
#include "attr.h"
@@ -662,7 +663,6 @@ void clear_pathspec(struct pathspec *pathspec)
attr_check_free(pathspec->items[i].attr_check);
}
- free(pathspec->items);
- pathspec->items = NULL;
+ FREE_AND_NULL(pathspec->items);
pathspec->nr = 0;
}
diff --git a/pretty.c b/pretty.c
index 09701bd2f..e4b561c58 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "utf8.h"
#include "diff.h"
@@ -783,29 +784,9 @@ struct format_commit_context {
size_t body_off;
/* The following ones are relative to the result struct strbuf. */
- struct chunk abbrev_commit_hash;
- struct chunk abbrev_tree_hash;
- struct chunk abbrev_parent_hashes;
size_t wrap_start;
};
-static int add_again(struct strbuf *sb, struct chunk *chunk)
-{
- if (chunk->len) {
- strbuf_adddup(sb, chunk->off, chunk->len);
- return 1;
- }
-
- /*
- * We haven't seen this chunk before. Our caller is surely
- * going to add it the hard way now. Remember the most likely
- * start of the to-be-added chunk: the current end of the
- * struct strbuf.
- */
- chunk->off = sb->len;
- return 0;
-}
-
static void parse_commit_header(struct format_commit_context *context)
{
const char *msg = context->message;
@@ -1147,24 +1128,16 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
return 1;
case 'h': /* abbreviated commit hash */
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT));
- if (add_again(sb, &c->abbrev_commit_hash)) {
- strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
- return 1;
- }
strbuf_add_unique_abbrev(sb, commit->object.oid.hash,
c->pretty_ctx->abbrev);
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
- c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;
return 1;
case 'T': /* tree hash */
strbuf_addstr(sb, oid_to_hex(&commit->tree->object.oid));
return 1;
case 't': /* abbreviated tree hash */
- if (add_again(sb, &c->abbrev_tree_hash))
- return 1;
strbuf_add_unique_abbrev(sb, commit->tree->object.oid.hash,
c->pretty_ctx->abbrev);
- c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;
return 1;
case 'P': /* parent hashes */
for (p = commit->parents; p; p = p->next) {
@@ -1174,16 +1147,12 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
}
return 1;
case 'p': /* abbreviated parent hashes */
- if (add_again(sb, &c->abbrev_parent_hashes))
- return 1;
for (p = commit->parents; p; p = p->next) {
if (p != commit->parents)
strbuf_addch(sb, ' ');
strbuf_add_unique_abbrev(sb, p->item->object.oid.hash,
c->pretty_ctx->abbrev);
}
- c->abbrev_parent_hashes.len = sb->len -
- c->abbrev_parent_hashes.off;
return 1;
case 'm': /* left/right/bottom */
strbuf_addstr(sb, get_revision_mark(NULL, commit));
diff --git a/prio-queue.c b/prio-queue.c
index fc3860fdc..126d09672 100644
--- a/prio-queue.c
+++ b/prio-queue.c
@@ -27,10 +27,9 @@ void prio_queue_reverse(struct prio_queue *queue)
void clear_prio_queue(struct prio_queue *queue)
{
- free(queue->array);
+ FREE_AND_NULL(queue->array);
queue->nr = 0;
queue->alloc = 0;
- queue->array = NULL;
queue->insertion_ctr = 0;
}
diff --git a/prompt.c b/prompt.c
index 75406390c..6d5885d00 100644
--- a/prompt.c
+++ b/prompt.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "run-command.h"
#include "strbuf.h"
#include "prompt.h"
diff --git a/read-cache.c b/read-cache.c
index bc156a133..3c4354ee2 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -5,6 +5,7 @@
*/
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
+#include "config.h"
#include "tempfile.h"
#include "lockfile.h"
#include "cache-tree.h"
@@ -1877,9 +1878,15 @@ int discard_index(struct index_state *istate)
{
int i;
- unshare_split_index(istate, 1);
- for (i = 0; i < istate->cache_nr; i++)
+ for (i = 0; i < istate->cache_nr; i++) {
+ if (istate->cache[i]->index &&
+ istate->split_index &&
+ istate->split_index->base &&
+ istate->cache[i]->index <= istate->split_index->base->cache_nr &&
+ istate->cache[i] == istate->split_index->base->cache[istate->cache[i]->index - 1])
+ continue;
free(istate->cache[i]);
+ }
resolve_undo_clear_index(istate);
istate->cache_nr = 0;
istate->cache_changed = 0;
@@ -1888,8 +1895,7 @@ int discard_index(struct index_state *istate)
free_name_hash(istate);
cache_tree_free(&(istate->cache_tree));
istate->initialized = 0;
- free(istate->cache);
- istate->cache = NULL;
+ FREE_AND_NULL(istate->cache);
istate->cache_alloc = 0;
discard_split_index(istate);
free_untracked_cache(istate->untracked);
@@ -2603,8 +2609,7 @@ void *read_blob_data_from_index(const struct index_state *istate,
void stat_validity_clear(struct stat_validity *sv)
{
- free(sv->sd);
- sv->sd = NULL;
+ FREE_AND_NULL(sv->sd);
}
int stat_validity_check(struct stat_validity *sv, const char *path)
diff --git a/ref-filter.c b/ref-filter.c
index ab32bc9c3..72e6cb8ec 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1891,8 +1891,7 @@ void ref_array_clear(struct ref_array *array)
for (i = 0; i < array->nr; i++)
free_array_item(array->items[i]);
- free(array->items);
- array->items = NULL;
+ FREE_AND_NULL(array->items);
array->nr = array->alloc = 0;
}
diff --git a/refs.c b/refs.c
index f0685c925..88658ba76 100644
--- a/refs.c
+++ b/refs.c
@@ -3,6 +3,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "hashmap.h"
#include "lockfile.h"
#include "iterator.h"
@@ -1341,6 +1342,18 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix,
prefix, fn, cb_data);
}
+int for_each_fullref_in_submodule(const char *submodule, const char *prefix,
+ each_ref_fn fn, void *cb_data,
+ unsigned int broken)
+{
+ unsigned int flag = 0;
+
+ if (broken)
+ flag = DO_FOR_EACH_INCLUDE_BROKEN;
+ return do_for_each_ref(get_submodule_ref_store(submodule),
+ prefix, fn, 0, flag, cb_data);
+}
+
int for_each_replace_ref(each_ref_fn fn, void *cb_data)
{
return do_for_each_ref(get_main_ref_store(),
diff --git a/refs.h b/refs.h
index 4be14c4b3..aa4ecc83d 100644
--- a/refs.h
+++ b/refs.h
@@ -303,7 +303,10 @@ int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
int for_each_ref_submodule(const char *submodule,
each_ref_fn fn, void *cb_data);
int for_each_ref_in_submodule(const char *submodule, const char *prefix,
- each_ref_fn fn, void *cb_data);
+ each_ref_fn fn, void *cb_data);
+int for_each_fullref_in_submodule(const char *submodule, const char *prefix,
+ each_ref_fn fn, void *cb_data,
+ unsigned int broken);
int for_each_tag_ref_submodule(const char *submodule,
each_ref_fn fn, void *cb_data);
int for_each_branch_ref_submodule(const char *submodule,
diff --git a/refs/files-backend.c b/refs/files-backend.c
index d8b3f7314..0404f2c23 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,4 +1,5 @@
#include "../cache.h"
+#include "../config.h"
#include "../refs.h"
#include "refs-internal.h"
#include "ref-cache.h"
@@ -370,6 +371,18 @@ static void files_ref_path(struct files_ref_store *refs,
}
/*
+ * Check that the packed refs cache (if any) still reflects the
+ * contents of the file. If not, clear the cache.
+ */
+static void validate_packed_ref_cache(struct files_ref_store *refs)
+{
+ if (refs->packed &&
+ !stat_validity_check(&refs->packed->validity,
+ files_packed_refs_path(refs)))
+ clear_packed_ref_cache(refs);
+}
+
+/*
* Get the packed_ref_cache for the specified files_ref_store,
* creating and populating it if it hasn't been read before or if the
* file has been changed (according to its `validity` field) since it
@@ -381,10 +394,8 @@ static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *ref
{
const char *packed_refs_file = files_packed_refs_path(refs);
- if (refs->packed &&
- !is_lock_file_locked(&refs->packed_refs_lock) &&
- !stat_validity_check(&refs->packed->validity, packed_refs_file))
- clear_packed_ref_cache(refs);
+ if (!is_lock_file_locked(&refs->packed_refs_lock))
+ validate_packed_ref_cache(refs);
if (!refs->packed)
refs->packed = read_packed_refs(packed_refs_file);
@@ -1311,13 +1322,17 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
&refs->packed_refs_lock, files_packed_refs_path(refs),
flags, timeout_value) < 0)
return -1;
+
/*
- * Get the current packed-refs while holding the lock. It is
- * important that we call `get_packed_ref_cache()` before
- * setting `packed_ref_cache->lock`, because otherwise the
- * former will see that the file is locked and assume that the
- * cache can't be stale.
+ * Now that we hold the `packed-refs` lock, make sure that our
+ * cache matches the current version of the file. Normally
+ * `get_packed_ref_cache()` does that for us, but that
+ * function assumes that when the file is locked, any existing
+ * cache is still valid. We've just locked the file, but it
+ * might have changed the moment *before* we locked it.
*/
+ validate_packed_ref_cache(refs);
+
packed_ref_cache = get_packed_ref_cache(refs);
/* Increment the reference count to prevent it from being freed: */
acquire_packed_ref_cache(packed_ref_cache);
@@ -2944,8 +2959,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
head_oid.hash, &head_type);
if (head_ref && !(head_type & REF_ISSYMREF)) {
- free(head_ref);
- head_ref = NULL;
+ FREE_AND_NULL(head_ref);
}
/*
diff --git a/refs/ref-cache.c b/refs/ref-cache.c
index af2fcb2c1..76bb723c8 100644
--- a/refs/ref-cache.c
+++ b/refs/ref-cache.c
@@ -82,9 +82,8 @@ static void clear_ref_dir(struct ref_dir *dir)
int i;
for (i = 0; i < dir->nr; i++)
free_ref_entry(dir->entries[i]);
- free(dir->entries);
+ FREE_AND_NULL(dir->entries);
dir->sorted = dir->nr = dir->alloc = 0;
- dir->entries = NULL;
}
struct ref_entry *create_dir_entry(struct ref_cache *cache,
diff --git a/remote-curl.c b/remote-curl.c
index ece45993d..0053b0954 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "remote.h"
#include "strbuf.h"
#include "walker.h"
diff --git a/remote-testsvn.c b/remote-testsvn.c
index e034ea00d..0ff4a3126 100644
--- a/remote-testsvn.c
+++ b/remote-testsvn.c
@@ -66,8 +66,7 @@ static char *read_ref_note(const struct object_id *oid)
else if (!msglen || type != OBJ_BLOB) {
error("Note contains unusable content. "
"Is something else using this notes tree? %s", notes_ref);
- free(msg);
- msg = NULL;
+ FREE_AND_NULL(msg);
}
free_notes(NULL);
return msg;
diff --git a/remote.c b/remote.c
index f998f989e..d87482573 100644
--- a/remote.c
+++ b/remote.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "remote.h"
#include "refs.h"
#include "commit.h"
diff --git a/rerere.c b/rerere.c
index c26c29f87..70634d456 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "string-list.h"
#include "rerere.h"
@@ -39,9 +40,8 @@ static void free_rerere_dirs(void)
free(rerere_dir[i]->status);
free(rerere_dir[i]);
}
- free(rerere_dir);
+ FREE_AND_NULL(rerere_dir);
rerere_dir_nr = rerere_dir_alloc = 0;
- rerere_dir = NULL;
}
static void free_rerere_id(struct string_list_item *item)
diff --git a/revision.c b/revision.c
index 12eb33235..e181ad1b7 100644
--- a/revision.c
+++ b/revision.c
@@ -1725,8 +1725,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->max_count = atoi(argv[1]);
revs->no_walk = 0;
return 2;
- } else if (starts_with(arg, "-n")) {
- revs->max_count = atoi(arg + 2);
+ } else if (skip_prefix(arg, "-n", &optarg)) {
+ revs->max_count = atoi(optarg);
revs->no_walk = 0;
} else if ((argcount = parse_long_opt("max-age", argv, &optarg))) {
revs->max_age = atoi(optarg);
@@ -1785,16 +1785,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
} else if (!strcmp(arg, "--author-date-order")) {
revs->sort_order = REV_SORT_BY_AUTHOR_DATE;
revs->topo_order = 1;
- } else if (starts_with(arg, "--early-output")) {
- int count = 100;
- switch (arg[14]) {
- case '=':
- count = atoi(arg+15);
- /* Fallthrough */
- case 0:
- revs->topo_order = 1;
- revs->early_output = count;
- }
+ } else if (!strcmp(arg, "--early-output")) {
+ revs->early_output = 100;
+ revs->topo_order = 1;
+ } else if (skip_prefix(arg, "--early-output=", &optarg)) {
+ if (strtoul_ui(optarg, 10, &revs->early_output) < 0)
+ die("'%s': not a non-negative integer", optarg);
+ revs->topo_order = 1;
} else if (!strcmp(arg, "--parents")) {
revs->rewrite_parents = 1;
revs->print_parents = 1;
@@ -1810,13 +1807,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->min_parents = 2;
} else if (!strcmp(arg, "--no-merges")) {
revs->max_parents = 1;
- } else if (starts_with(arg, "--min-parents=")) {
- revs->min_parents = atoi(arg+14);
- } else if (starts_with(arg, "--no-min-parents")) {
+ } else if (skip_prefix(arg, "--min-parents=", &optarg)) {
+ revs->min_parents = atoi(optarg);
+ } else if (!strcmp(arg, "--no-min-parents")) {
revs->min_parents = 0;
- } else if (starts_with(arg, "--max-parents=")) {
- revs->max_parents = atoi(arg+14);
- } else if (starts_with(arg, "--no-max-parents")) {
+ } else if (skip_prefix(arg, "--max-parents=", &optarg)) {
+ revs->max_parents = atoi(optarg);
+ } else if (!strcmp(arg, "--no-max-parents")) {
revs->max_parents = -1;
} else if (!strcmp(arg, "--boundary")) {
revs->boundary = 1;
@@ -1897,14 +1894,15 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->verbose_header = 1;
revs->pretty_given = 1;
get_commit_format(NULL, revs);
- } else if (starts_with(arg, "--pretty=") || starts_with(arg, "--format=")) {
+ } else if (skip_prefix(arg, "--pretty=", &optarg) ||
+ skip_prefix(arg, "--format=", &optarg)) {
/*
* Detached form ("--pretty X" as opposed to "--pretty=X")
* not allowed, since the argument is optional.
*/
revs->verbose_header = 1;
revs->pretty_given = 1;
- get_commit_format(arg+9, revs);
+ get_commit_format(optarg, revs);
} else if (!strcmp(arg, "--expand-tabs")) {
revs->expand_tabs_in_log = 8;
} else if (!strcmp(arg, "--no-expand-tabs")) {
@@ -1922,26 +1920,23 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->show_signature = 1;
} else if (!strcmp(arg, "--no-show-signature")) {
revs->show_signature = 0;
- } else if (!strcmp(arg, "--show-linear-break") ||
- starts_with(arg, "--show-linear-break=")) {
- if (starts_with(arg, "--show-linear-break="))
- revs->break_bar = xstrdup(arg + 20);
- else
- revs->break_bar = " ..........";
+ } else if (!strcmp(arg, "--show-linear-break")) {
+ revs->break_bar = " ..........";
revs->track_linear = 1;
revs->track_first_time = 1;
- } else if (starts_with(arg, "--show-notes=") ||
- starts_with(arg, "--notes=")) {
+ } else if (skip_prefix(arg, "--show-linear-break=", &optarg)) {
+ revs->break_bar = xstrdup(optarg);
+ revs->track_linear = 1;
+ revs->track_first_time = 1;
+ } else if (skip_prefix(arg, "--show-notes=", &optarg) ||
+ skip_prefix(arg, "--notes=", &optarg)) {
struct strbuf buf = STRBUF_INIT;
revs->show_notes = 1;
revs->show_notes_given = 1;
- if (starts_with(arg, "--show-notes")) {
- if (revs->notes_opt.use_default_notes < 0)
- revs->notes_opt.use_default_notes = 1;
- strbuf_addstr(&buf, arg+13);
- }
- else
- strbuf_addstr(&buf, arg+8);
+ if (starts_with(arg, "--show-notes=") &&
+ revs->notes_opt.use_default_notes < 0)
+ revs->notes_opt.use_default_notes = 1;
+ strbuf_addstr(&buf, optarg);
expand_notes_ref(&buf);
string_list_append(&revs->notes_opt.extra_notes_refs,
strbuf_detach(&buf, NULL));
@@ -1978,8 +1973,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->abbrev = 0;
} else if (!strcmp(arg, "--abbrev")) {
revs->abbrev = DEFAULT_ABBREV;
- } else if (starts_with(arg, "--abbrev=")) {
- revs->abbrev = strtoul(arg + 9, NULL, 10);
+ } else if (skip_prefix(arg, "--abbrev=", &optarg)) {
+ revs->abbrev = strtoul(optarg, NULL, 10);
if (revs->abbrev < MINIMUM_ABBREV)
revs->abbrev = MINIMUM_ABBREV;
else if (revs->abbrev > 40)
@@ -2080,7 +2075,7 @@ static int for_each_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_d
struct strbuf bisect_refs = STRBUF_INIT;
int status;
strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
- status = for_each_ref_in_submodule(submodule, bisect_refs.buf, fn, cb_data);
+ status = for_each_fullref_in_submodule(submodule, bisect_refs.buf, fn, cb_data, 0);
strbuf_release(&bisect_refs);
return status;
}
@@ -2140,20 +2135,20 @@ static int handle_revision_pseudo_opt(const char *submodule,
} else if ((argcount = parse_long_opt("exclude", argv, &optarg))) {
add_ref_exclusion(&revs->ref_excludes, optarg);
return argcount;
- } else if (starts_with(arg, "--branches=")) {
+ } else if (skip_prefix(arg, "--branches=", &optarg)) {
struct all_refs_cb cb;
init_all_refs_cb(&cb, revs, *flags);
- for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb);
+ for_each_glob_ref_in(handle_one_ref, optarg, "refs/heads/", &cb);
clear_ref_exclusion(&revs->ref_excludes);
- } else if (starts_with(arg, "--tags=")) {
+ } else if (skip_prefix(arg, "--tags=", &optarg)) {
struct all_refs_cb cb;
init_all_refs_cb(&cb, revs, *flags);
- for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb);
+ for_each_glob_ref_in(handle_one_ref, optarg, "refs/tags/", &cb);
clear_ref_exclusion(&revs->ref_excludes);
- } else if (starts_with(arg, "--remotes=")) {
+ } else if (skip_prefix(arg, "--remotes=", &optarg)) {
struct all_refs_cb cb;
init_all_refs_cb(&cb, revs, *flags);
- for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
+ for_each_glob_ref_in(handle_one_ref, optarg, "refs/remotes/", &cb);
clear_ref_exclusion(&revs->ref_excludes);
} else if (!strcmp(arg, "--reflog")) {
add_reflogs_to_pending(revs, *flags);
@@ -2163,14 +2158,14 @@ static int handle_revision_pseudo_opt(const char *submodule,
*flags ^= UNINTERESTING | BOTTOM;
} else if (!strcmp(arg, "--no-walk")) {
revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
- } else if (starts_with(arg, "--no-walk=")) {
+ } else if (skip_prefix(arg, "--no-walk=", &optarg)) {
/*
* Detached form ("--no-walk X" as opposed to "--no-walk=X")
* not allowed, since the argument is optional.
*/
- if (!strcmp(arg + 10, "sorted"))
+ if (!strcmp(optarg, "sorted"))
revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
- else if (!strcmp(arg + 10, "unsorted"))
+ else if (!strcmp(optarg, "unsorted"))
revs->no_walk = REVISION_WALK_NO_WALK_UNSORTED;
else
return error("invalid argument to --no-walk");
diff --git a/revision.h b/revision.h
index a91dd3d5d..f96e7f7f4 100644
--- a/revision.h
+++ b/revision.h
@@ -74,8 +74,9 @@ struct rev_info {
/* topo-sort */
enum rev_sort_order sort_order;
- unsigned int early_output:1,
- ignore_missing:1,
+ unsigned int early_output;
+
+ unsigned int ignore_missing:1,
ignore_missing_links:1;
/* Traversal flags */
diff --git a/send-pack.c b/send-pack.c
index 78bb34ebe..ed3cee321 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "commit.h"
#include "refs.h"
#include "pkt-line.h"
diff --git a/sequencer.c b/sequencer.c
index d63099d50..3010faf86 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "sequencer.h"
#include "dir.h"
@@ -1211,8 +1212,7 @@ struct todo_list {
static void todo_list_release(struct todo_list *todo_list)
{
strbuf_release(&todo_list->buf);
- free(todo_list->items);
- todo_list->items = NULL;
+ FREE_AND_NULL(todo_list->items);
todo_list->nr = todo_list->alloc = 0;
}
@@ -1922,7 +1922,7 @@ static int apply_autostash(struct replay_opts *opts)
argv_array_push(&child.args, "apply");
argv_array_push(&child.args, stash_sha1.buf);
if (!run_command(&child))
- printf(_("Applied autostash.\n"));
+ fprintf(stderr, _("Applied autostash.\n"));
else {
struct child_process store = CHILD_PROCESS_INIT;
@@ -1936,10 +1936,11 @@ static int apply_autostash(struct replay_opts *opts)
if (run_command(&store))
ret = error(_("cannot store %s"), stash_sha1.buf);
else
- printf(_("Applying autostash resulted in conflicts.\n"
- "Your changes are safe in the stash.\n"
- "You can run \"git stash pop\" or"
- " \"git stash drop\" at any time.\n"));
+ fprintf(stderr,
+ _("Applying autostash resulted in conflicts.\n"
+ "Your changes are safe in the stash.\n"
+ "You can run \"git stash pop\" or"
+ " \"git stash drop\" at any time.\n"));
}
strbuf_release(&stash_sha1);
diff --git a/setup.c b/setup.c
index 751d02b9b..358fbc2e5 100644
--- a/setup.c
+++ b/setup.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "string-list.h"
@@ -967,19 +968,21 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
}
}
-const char *discover_git_directory(struct strbuf *gitdir)
+int discover_git_directory(struct strbuf *commondir,
+ struct strbuf *gitdir)
{
struct strbuf dir = STRBUF_INIT, err = STRBUF_INIT;
size_t gitdir_offset = gitdir->len, cwd_len;
+ size_t commondir_offset = commondir->len;
struct repository_format candidate;
if (strbuf_getcwd(&dir))
- return NULL;
+ return -1;
cwd_len = dir.len;
if (setup_git_directory_gently_1(&dir, gitdir, 0) <= 0) {
strbuf_release(&dir);
- return NULL;
+ return -1;
}
/*
@@ -995,8 +998,10 @@ const char *discover_git_directory(struct strbuf *gitdir)
strbuf_insert(gitdir, gitdir_offset, dir.buf, dir.len);
}
+ get_common_dir(commondir, gitdir->buf + gitdir_offset);
+
strbuf_reset(&dir);
- strbuf_addf(&dir, "%s/config", gitdir->buf + gitdir_offset);
+ strbuf_addf(&dir, "%s/config", commondir->buf + commondir_offset);
read_repository_format(&candidate, dir.buf);
strbuf_release(&dir);
@@ -1004,10 +1009,12 @@ const char *discover_git_directory(struct strbuf *gitdir)
warning("ignoring git dir '%s': %s",
gitdir->buf + gitdir_offset, err.buf);
strbuf_release(&err);
- return NULL;
+ strbuf_setlen(commondir, commondir_offset);
+ strbuf_setlen(gitdir, gitdir_offset);
+ return -1;
}
- return gitdir->buf + gitdir_offset;
+ return 0;
}
const char *setup_git_directory_gently(int *nongit_ok)
diff --git a/sha1-array.c b/sha1-array.c
index 7d646ab5b..838b3bf84 100644
--- a/sha1-array.c
+++ b/sha1-array.c
@@ -35,8 +35,7 @@ int oid_array_lookup(struct oid_array *array, const struct object_id *oid)
void oid_array_clear(struct oid_array *array)
{
- free(array->oid);
- array->oid = NULL;
+ FREE_AND_NULL(array->oid);
array->nr = 0;
array->alloc = 0;
array->sorted = 0;
diff --git a/sha1_file.c b/sha1_file.c
index 59a4ed2ed..fb1fd809d 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -7,6 +7,7 @@
* creation etc.
*/
#include "cache.h"
+#include "config.h"
#include "string-list.h"
#include "lockfile.h"
#include "delta.h"
@@ -610,8 +611,7 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
out:
if (seen_error) {
- free(ref_git);
- ref_git = NULL;
+ FREE_AND_NULL(ref_git);
}
return ref_git;
@@ -3546,7 +3546,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,
*/
if ((type == OBJ_BLOB) && path) {
struct strbuf nbuf = STRBUF_INIT;
- if (convert_to_git(path, buf, size, &nbuf,
+ if (convert_to_git(&the_index, path, buf, size, &nbuf,
write_object ? safe_crlf : SAFE_CRLF_FALSE)) {
buf = strbuf_detach(&nbuf, &size);
re_allocated = 1;
@@ -3580,7 +3580,7 @@ static int index_stream_convert_blob(unsigned char *sha1, int fd,
assert(path);
assert(would_convert_to_git_filter_fd(path));
- convert_to_git_filter_fd(path, fd, &sbuf,
+ convert_to_git_filter_fd(&the_index, path, fd, &sbuf,
write_object ? safe_crlf : SAFE_CRLF_FALSE);
if (write_object)
@@ -3668,7 +3668,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st,
else if (!S_ISREG(st->st_mode))
ret = index_pipe(sha1, fd, type, path, flags);
else if (st->st_size <= big_file_threshold || type != OBJ_BLOB ||
- (path && would_convert_to_git(path)))
+ (path && would_convert_to_git(&the_index, path)))
ret = index_core(sha1, fd, xsize_t(st->st_size), type, path,
flags);
else
diff --git a/sha1_name.c b/sha1_name.c
index 5126853bb..d2d732c19 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "tag.h"
#include "commit.h"
#include "tree.h"
diff --git a/split-index.c b/split-index.c
index 49bd197f7..83e39ec8d 100644
--- a/split-index.c
+++ b/split-index.c
@@ -73,17 +73,10 @@ void move_cache_to_base_index(struct index_state *istate)
int i;
/*
- * If "si" is shared with another index_state (e.g. by
- * unpack-trees code), we will need to duplicate split_index
- * struct. It's not happening now though, luckily.
+ * do not delete old si->base, its index entries may be shared
+ * with istate->cache[]. Accept a bit of leaking here because
+ * this code is only used by short-lived update-index.
*/
- assert(si->refcount <= 1);
-
- unshare_split_index(istate, 0);
- if (si->base) {
- discard_index(si->base);
- free(si->base);
- }
si->base = xcalloc(1, sizeof(*si->base));
si->base->version = istate->version;
/* zero timestamp disables racy test in ce_write_index() */
@@ -174,10 +167,9 @@ void merge_base_index(struct index_state *istate)
ewah_free(si->delete_bitmap);
ewah_free(si->replace_bitmap);
- free(si->saved_cache);
+ FREE_AND_NULL(si->saved_cache);
si->delete_bitmap = NULL;
si->replace_bitmap = NULL;
- si->saved_cache = NULL;
si->saved_cache_nr = 0;
}
@@ -282,41 +274,11 @@ void finish_writing_split_index(struct index_state *istate)
istate->cache_nr = si->saved_cache_nr;
}
-void unshare_split_index(struct index_state *istate, int discard)
-{
- struct split_index *si = istate->split_index;
- int i;
-
- if (!si || !si->base)
- return;
-
- for (i = 0; i < istate->cache_nr; i++) {
- struct cache_entry *ce = istate->cache[i];
- struct cache_entry *new = NULL;
-
- if (!ce->index ||
- ce->index > si->base->cache_nr ||
- ce != si->base->cache[ce->index - 1])
- continue;
-
- if (!discard) {
- int len = ce_namelen(ce);
- new = xcalloc(1, cache_entry_size(len));
- copy_cache_entry(new, ce);
- memcpy(new->name, ce->name, len);
- new->index = 0;
- }
- istate->cache[i] = new;
- }
-}
-
-
void discard_split_index(struct index_state *istate)
{
struct split_index *si = istate->split_index;
if (!si)
return;
- unshare_split_index(istate, 0);
istate->split_index = NULL;
si->refcount--;
if (si->refcount)
@@ -365,8 +327,14 @@ void add_split_index(struct index_state *istate)
void remove_split_index(struct index_state *istate)
{
- if (!istate->split_index)
- return;
- discard_split_index(istate);
- istate->cache_changed |= SOMETHING_CHANGED;
+ if (istate->split_index) {
+ /*
+ * can't discard_split_index(&the_index); because that
+ * will destroy split_index->base->cache[], which may
+ * be shared with the_index.cache[]. So yeah we're
+ * leaking a bit here.
+ */
+ istate->split_index = NULL;
+ istate->cache_changed |= SOMETHING_CHANGED;
+ }
}
diff --git a/split-index.h b/split-index.h
index 65c0f09b2..df91c1bda 100644
--- a/split-index.h
+++ b/split-index.h
@@ -33,6 +33,5 @@ void finish_writing_split_index(struct index_state *istate);
void discard_split_index(struct index_state *istate);
void add_split_index(struct index_state *istate);
void remove_split_index(struct index_state *istate);
-void unshare_split_index(struct index_state *istate, int discard);
#endif
diff --git a/strbuf.c b/strbuf.c
index 00457940c..c4e91a665 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -204,13 +204,6 @@ void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2)
strbuf_setlen(sb, sb->len + sb2->len);
}
-void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len)
-{
- strbuf_grow(sb, len);
- memcpy(sb->buf + sb->len, sb->buf + pos, len);
- strbuf_setlen(sb, sb->len + len);
-}
-
void strbuf_addchars(struct strbuf *sb, int c, size_t n)
{
strbuf_grow(sb, n);
@@ -785,14 +778,48 @@ char *xstrfmt(const char *fmt, ...)
return ret;
}
-void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm)
+void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
+ int tz_offset, const char *tz_name)
{
+ struct strbuf munged_fmt = STRBUF_INIT;
size_t hint = 128;
size_t len;
if (!*fmt)
return;
+ /*
+ * There is no portable way to pass timezone information to
+ * strftime, so we handle %z and %Z here.
+ */
+ for (;;) {
+ const char *percent = strchrnul(fmt, '%');
+ strbuf_add(&munged_fmt, fmt, percent - fmt);
+ if (!*percent)
+ break;
+ fmt = percent + 1;
+ switch (*fmt) {
+ case '%':
+ strbuf_addstr(&munged_fmt, "%%");
+ fmt++;
+ break;
+ case 'z':
+ strbuf_addf(&munged_fmt, "%+05d", tz_offset);
+ fmt++;
+ break;
+ case 'Z':
+ if (tz_name) {
+ strbuf_addstr(&munged_fmt, tz_name);
+ fmt++;
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ strbuf_addch(&munged_fmt, '%');
+ }
+ }
+ fmt = munged_fmt.buf;
+
strbuf_grow(sb, hint);
len = strftime(sb->buf + sb->len, sb->alloc - sb->len, fmt, tm);
@@ -804,17 +831,16 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm)
* output contains at least one character, and then drop the extra
* character before returning.
*/
- struct strbuf munged_fmt = STRBUF_INIT;
- strbuf_addf(&munged_fmt, "%s ", fmt);
+ strbuf_addch(&munged_fmt, ' ');
while (!len) {
hint *= 2;
strbuf_grow(sb, hint);
len = strftime(sb->buf + sb->len, sb->alloc - sb->len,
munged_fmt.buf, tm);
}
- strbuf_release(&munged_fmt);
len--; /* drop munged space */
}
+ strbuf_release(&munged_fmt);
strbuf_setlen(sb, sb->len + len);
}
diff --git a/strbuf.h b/strbuf.h
index 80047b1bb..3646a6291 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -264,12 +264,6 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s)
extern void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2);
/**
- * Copy part of the buffer from a given position till a given length to the
- * end of the buffer.
- */
-extern void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len);
-
-/**
* This function can be used to expand a format string containing
* placeholders. To that end, it parses the string and calls the specified
* function for every percent sign found.
@@ -340,8 +334,14 @@ extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
/**
* Add the time specified by `tm`, as formatted by `strftime`.
- */
-extern void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm);
+ * `tz_name` is used to expand %Z internally unless it's NULL.
+ * `tz_offset` is in decimal hhmm format, e.g. -600 means six hours west
+ * of Greenwich, and it's used to expand %z internally. However, tokens
+ * with modifiers (e.g. %Ez) are passed to `strftime`.
+ */
+extern void strbuf_addftime(struct strbuf *sb, const char *fmt,
+ const struct tm *tm, int tz_offset,
+ const char *tz_name);
/**
* Read a given size of data from a FILE* pointer to the buffer.
diff --git a/submodule-config.c b/submodule-config.c
index 4f58491dd..d8f8d5ea3 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "submodule-config.h"
#include "submodule.h"
#include "strbuf.h"
diff --git a/submodule.c b/submodule.c
index 1b8a3b575..da0b80549 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "submodule-config.h"
#include "submodule.h"
#include "dir.h"
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 8e3ed6a76..1a7b8bd3d 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "string-list.h"
/*
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 2f144d539..c6c57bba0 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "submodule-config.h"
#include "submodule.h"
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
index 42d4ea61e..7ac9466d5 100755
--- a/t/t0006-date.sh
+++ b/t/t0006-date.sh
@@ -31,9 +31,11 @@ check_show () {
format=$1
time=$2
expect=$3
- test_expect_success $4 "show date ($format:$time)" '
+ prereqs=$4
+ zone=$5
+ test_expect_success $prereqs "show date ($format:$time)" '
echo "$time -> $expect" >expect &&
- test-date show:$format "$time" >actual &&
+ TZ=${zone:-$TZ} test-date show:"$format" "$time" >actual &&
test_cmp expect actual
'
}
@@ -51,6 +53,16 @@ check_show iso-local "$TIME" '2016-06-15 14:13:20 +0000'
check_show raw-local "$TIME" '1466000000 +0000'
check_show unix-local "$TIME" '1466000000'
+check_show 'format:%z' "$TIME" '+0200'
+check_show 'format-local:%z' "$TIME" '+0000'
+check_show 'format:%Z' "$TIME" ''
+check_show 'format-local:%Z' "$TIME" 'UTC'
+check_show 'format:%%z' "$TIME" '%z'
+check_show 'format-local:%%z' "$TIME" '%z'
+
+check_show 'format:%Y-%m-%d %H:%M:%S' "$TIME" '2016-06-15 16:13:20'
+check_show 'format-local:%Y-%m-%d %H:%M:%S' "$TIME" '2016-06-15 09:13:20' '' EST5
+
# arbitrary time absurdly far in the future
FUTURE="5758122296 -0400"
check_show iso "$FUTURE" "2152-06-19 18:24:56 -0400" TIME_IS_64BIT,TIME_T_IS_64BIT
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 13b7851f7..a37ef0422 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -703,6 +703,12 @@ test_expect_success 'invalid unit' '
test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
'
+test_expect_success 'line number is reported correctly' '
+ printf "[bool]\n\tvar\n" >invalid &&
+ test_must_fail git config -f invalid --path bool.var 2>actual &&
+ test_i18ngrep "line 2" actual
+'
+
test_expect_success 'invalid stdin config' '
echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
test_i18ngrep "bad config line 1 in standard input" output
diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh
index e495a6161..bafed5c9b 100755
--- a/t/t1308-config-set.sh
+++ b/t/t1308-config-set.sh
@@ -226,7 +226,9 @@ test_expect_success 'check line errors for malformed values' '
br
EOF
test_expect_code 128 git br 2>result &&
- test_i18ngrep "fatal: .*alias\.br.*\.git/config.*line 2" result
+ test_i18ngrep "missing value for .alias\.br" result &&
+ test_i18ngrep "fatal: .*\.git/config" result &&
+ test_i18ngrep "fatal: .*line 2" result
'
test_expect_success 'error on modifying repo config without repo' '
diff --git a/t/t3070-wildmatch.sh b/t/t3070-wildmatch.sh
index 7ca69f4be..8fd70d3aa 100755
--- a/t/t3070-wildmatch.sh
+++ b/t/t3070-wildmatch.sh
@@ -82,6 +82,7 @@ match 1 0 'foo/bar' 'foo/**/bar'
match 1 0 'foo/bar' 'foo/**/**/bar'
match 0 0 'foo/bar' 'foo?bar'
match 0 0 'foo/bar' 'foo[/]bar'
+match 0 0 'foo/bar' 'foo[^a-z]bar'
match 0 0 'foo/bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
match 1 1 'foo-bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
match 1 0 'foo' '**/foo'
@@ -225,6 +226,7 @@ pathmatch 0 foo/bba/arr 'foo/*z'
pathmatch 0 foo/bba/arr 'foo/**z'
pathmatch 1 foo/bar 'foo?bar'
pathmatch 1 foo/bar 'foo[/]bar'
+pathmatch 1 foo/bar 'foo[^a-z]bar'
pathmatch 0 foo '*/*/*'
pathmatch 0 foo/bar '*/*/*'
pathmatch 1 foo/bba/arr '*/*/*'
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 10f8f026f..48d152b9a 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -100,6 +100,23 @@ test_expect_success 'git branch -m n/n n should work' '
git reflog exists refs/heads/n
'
+# The topmost entry in reflog for branch bbb is about branch creation.
+# Hence, we compare bbb@{1} (instead of bbb@{0}) with aaa@{0}.
+
+test_expect_success 'git branch -m bbb should rename checked out branch' '
+ test_when_finished git branch -D bbb &&
+ test_when_finished git checkout master &&
+ git checkout -b aaa &&
+ git commit --allow-empty -m "a new commit" &&
+ git rev-parse aaa@{0} >expect &&
+ git branch -m bbb &&
+ git rev-parse bbb@{1} >actual &&
+ test_cmp expect actual &&
+ git symbolic-ref HEAD >actual &&
+ echo refs/heads/bbb >expect &&
+ test_cmp expect actual
+'
+
test_expect_success 'git branch -m o/o o should fail when o/p exists' '
git branch o/o &&
git branch o/p &&
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 5bd027593..37821d245 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -169,6 +169,13 @@ test_expect_success 'reflog for the branch shows state before rebase' '
test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
'
+test_expect_success 'reflog for the branch shows correct finish message' '
+ printf "rebase -i (finish): refs/heads/branch1 onto %s\n" \
+ "$(git rev-parse branch2)" >expected &&
+ git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
+ test_cmp expected actual
+'
+
test_expect_success 'exchange two commits' '
set_fake_editor &&
FAKE_LINES="2 1" git rebase -i HEAD~2 &&
diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh
index ab8a63e8d..e24370066 100755
--- a/t/t3420-rebase-autostash.sh
+++ b/t/t3420-rebase-autostash.sh
@@ -33,7 +33,123 @@ test_expect_success setup '
git commit -m "related commit"
'
-testrebase() {
+create_expected_success_am () {
+ cat >expected <<-EOF
+ $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
+ HEAD is now at $(git rev-parse --short feature-branch) third commit
+ First, rewinding head to replay your work on top of it...
+ Applying: second commit
+ Applying: third commit
+ Applied autostash.
+ EOF
+}
+
+create_expected_success_interactive () {
+ q_to_cr >expected <<-EOF
+ $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
+ HEAD is now at $(git rev-parse --short feature-branch) third commit
+ Rebasing (1/2)QRebasing (2/2)QApplied autostash.
+ Successfully rebased and updated refs/heads/rebased-feature-branch.
+ EOF
+}
+
+create_expected_success_merge () {
+ cat >expected <<-EOF
+ $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
+ HEAD is now at $(git rev-parse --short feature-branch) third commit
+ First, rewinding head to replay your work on top of it...
+ Merging unrelated-onto-branch with HEAD~1
+ Merging:
+ $(git rev-parse --short unrelated-onto-branch) unrelated commit
+ $(git rev-parse --short feature-branch^) second commit
+ found 1 common ancestor:
+ $(git rev-parse --short feature-branch~2) initial commit
+ [detached HEAD $(git rev-parse --short rebased-feature-branch~1)] second commit
+ Author: A U Thor <author@example.com>
+ Date: Thu Apr 7 15:14:13 2005 -0700
+ 2 files changed, 2 insertions(+)
+ create mode 100644 file1
+ create mode 100644 file2
+ Committed: 0001 second commit
+ Merging unrelated-onto-branch with HEAD~0
+ Merging:
+ $(git rev-parse --short rebased-feature-branch~1) second commit
+ $(git rev-parse --short feature-branch) third commit
+ found 1 common ancestor:
+ $(git rev-parse --short feature-branch~1) second commit
+ [detached HEAD $(git rev-parse --short rebased-feature-branch)] third commit
+ Author: A U Thor <author@example.com>
+ Date: Thu Apr 7 15:15:13 2005 -0700
+ 1 file changed, 1 insertion(+)
+ create mode 100644 file3
+ Committed: 0002 third commit
+ All done.
+ Applied autostash.
+ EOF
+}
+
+create_expected_failure_am () {
+ cat >expected <<-EOF
+ $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
+ HEAD is now at $(git rev-parse --short feature-branch) third commit
+ First, rewinding head to replay your work on top of it...
+ Applying: second commit
+ Applying: third commit
+ Applying autostash resulted in conflicts.
+ Your changes are safe in the stash.
+ You can run "git stash pop" or "git stash drop" at any time.
+ EOF
+}
+
+create_expected_failure_interactive () {
+ q_to_cr >expected <<-EOF
+ $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
+ HEAD is now at $(git rev-parse --short feature-branch) third commit
+ Rebasing (1/2)QRebasing (2/2)QApplying autostash resulted in conflicts.
+ Your changes are safe in the stash.
+ You can run "git stash pop" or "git stash drop" at any time.
+ Successfully rebased and updated refs/heads/rebased-feature-branch.
+ EOF
+}
+
+create_expected_failure_merge () {
+ cat >expected <<-EOF
+ $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
+ HEAD is now at $(git rev-parse --short feature-branch) third commit
+ First, rewinding head to replay your work on top of it...
+ Merging unrelated-onto-branch with HEAD~1
+ Merging:
+ $(git rev-parse --short unrelated-onto-branch) unrelated commit
+ $(git rev-parse --short feature-branch^) second commit
+ found 1 common ancestor:
+ $(git rev-parse --short feature-branch~2) initial commit
+ [detached HEAD $(git rev-parse --short rebased-feature-branch~1)] second commit
+ Author: A U Thor <author@example.com>
+ Date: Thu Apr 7 15:14:13 2005 -0700
+ 2 files changed, 2 insertions(+)
+ create mode 100644 file1
+ create mode 100644 file2
+ Committed: 0001 second commit
+ Merging unrelated-onto-branch with HEAD~0
+ Merging:
+ $(git rev-parse --short rebased-feature-branch~1) second commit
+ $(git rev-parse --short feature-branch) third commit
+ found 1 common ancestor:
+ $(git rev-parse --short feature-branch~1) second commit
+ [detached HEAD $(git rev-parse --short rebased-feature-branch)] third commit
+ Author: A U Thor <author@example.com>
+ Date: Thu Apr 7 15:15:13 2005 -0700
+ 1 file changed, 1 insertion(+)
+ create mode 100644 file3
+ Committed: 0002 third commit
+ All done.
+ Applying autostash resulted in conflicts.
+ Your changes are safe in the stash.
+ You can run "git stash pop" or "git stash drop" at any time.
+ EOF
+}
+
+testrebase () {
type=$1
dotest=$2
@@ -51,14 +167,20 @@ testrebase() {
test_config rebase.autostash true &&
git reset --hard &&
git checkout -b rebased-feature-branch feature-branch &&
- test_when_finished git branch -D rebased-feature-branch &&
echo dirty >>file3 &&
- git rebase$type unrelated-onto-branch &&
+ git rebase$type unrelated-onto-branch >actual 2>&1 &&
grep unrelated file4 &&
grep dirty file3 &&
git checkout feature-branch
'
+ test_expect_success "rebase$type --autostash: check output" '
+ test_when_finished git branch -D rebased-feature-branch &&
+ suffix=${type#\ --} && suffix=${suffix:-am} &&
+ create_expected_success_$suffix &&
+ test_i18ncmp expected actual
+ '
+
test_expect_success "rebase$type: dirty index, non-conflicting rebase" '
test_config rebase.autostash true &&
git reset --hard &&
@@ -137,10 +259,9 @@ testrebase() {
test_config rebase.autostash true &&
git reset --hard &&
git checkout -b rebased-feature-branch feature-branch &&
- test_when_finished git branch -D rebased-feature-branch &&
echo dirty >file4 &&
git add file4 &&
- git rebase$type unrelated-onto-branch &&
+ git rebase$type unrelated-onto-branch >actual 2>&1 &&
test_path_is_missing $dotest &&
git reset --hard &&
grep unrelated file4 &&
@@ -149,6 +270,13 @@ testrebase() {
git stash pop &&
grep dirty file4
'
+
+ test_expect_success "rebase$type: check output with conflicting stash" '
+ test_when_finished git branch -D rebased-feature-branch &&
+ suffix=${type#\ --} && suffix=${suffix:-am} &&
+ create_expected_failure_$suffix &&
+ test_i18ncmp expected actual
+ '
}
test_expect_success "rebase: fast-forward rebase" '
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 2ecb43a61..2f3e7cea6 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -477,4 +477,12 @@ test_expect_success 'add -p does not expand argument lists' '
! grep not-changed trace.out
'
+test_expect_success 'hunk-editing handles custom comment char' '
+ git reset --hard &&
+ echo change >>file &&
+ test_config core.commentChar "\$" &&
+ echo e | GIT_EDITOR=true git add -p &&
+ git diff --exit-code
+'
+
test_done
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 3b4bed5c9..4046817d7 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -812,6 +812,22 @@ test_expect_success 'stash -- <pathspec> stashes and restores the file' '
test_path_is_file bar
'
+test_expect_success 'stash -- <pathspec> stashes in subdirectory' '
+ mkdir sub &&
+ >foo &&
+ >bar &&
+ git add foo bar &&
+ (
+ cd sub &&
+ git stash push -- ../foo
+ ) &&
+ test_path_is_file bar &&
+ test_path_is_missing foo &&
+ git stash pop &&
+ test_path_is_file foo &&
+ test_path_is_file bar
+'
+
test_expect_success 'stash with multiple pathspec arguments' '
>foo &&
>bar &&
diff --git a/t/t4005-diff-rename-2.sh b/t/t4005-diff-rename-2.sh
index 135addbfb..f542d2929 100755
--- a/t/t4005-diff-rename-2.sh
+++ b/t/t4005-diff-rename-2.sh
@@ -3,84 +3,75 @@
# Copyright (c) 2005 Junio C Hamano
#
-test_description='Same rename detection as t4003 but testing diff-raw.
+test_description='Same rename detection as t4003 but testing diff-raw.'
-'
. ./test-lib.sh
. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
-test_expect_success \
- 'prepare reference tree' \
- 'cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
- echo frotz >rezrov &&
- git update-index --add COPYING rezrov &&
- tree=$(git write-tree) &&
- echo $tree'
-
-test_expect_success \
- 'prepare work tree' \
- 'sed -e 's/HOWEVER/However/' <COPYING >COPYING.1 &&
- sed -e 's/GPL/G.P.L/g' <COPYING >COPYING.2 &&
- rm -f COPYING &&
- git update-index --add --remove COPYING COPYING.?'
+test_expect_success 'setup reference tree' '
+ cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
+ echo frotz >rezrov &&
+ git update-index --add COPYING rezrov &&
+ tree=$(git write-tree) &&
+ echo $tree &&
+ sed -e 's/HOWEVER/However/' <COPYING >COPYING.1 &&
+ sed -e 's/GPL/G.P.L/g' <COPYING >COPYING.2 &&
+ origoid=$(git hash-object COPYING) &&
+ oid1=$(git hash-object COPYING.1) &&
+ oid2=$(git hash-object COPYING.2)
+'
+################################################################
# tree has COPYING and rezrov. work tree has COPYING.1 and COPYING.2,
# both are slightly edited, and unchanged rezrov. We say COPYING.1
# and COPYING.2 are based on COPYING, and do not say anything about
# rezrov.
-git diff-index -C $tree >current
-
-cat >expected <<\EOF
-:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
-:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 06c67961bbaed34a127f76d261f4c0bf73eda471 R1234 COPYING COPYING.2
-EOF
+test_expect_success 'validate output from rename/copy detection (#1)' '
+ rm -f COPYING &&
+ git update-index --add --remove COPYING COPYING.? &&
-test_expect_success \
- 'validate output from rename/copy detection (#1)' \
- 'compare_diff_raw current expected'
+ cat <<-EOF >expected &&
+ :100644 100644 $origoid $oid1 C1234 COPYING COPYING.1
+ :100644 100644 $origoid $oid2 R1234 COPYING COPYING.2
+ EOF
+ git diff-index -C $tree >current &&
+ compare_diff_raw expected current
+'
################################################################
-
-test_expect_success \
- 'prepare work tree again' \
- 'mv COPYING.2 COPYING &&
- git update-index --add --remove COPYING COPYING.1 COPYING.2'
-
# tree has COPYING and rezrov. work tree has COPYING and COPYING.1,
# both are slightly edited, and unchanged rezrov. We say COPYING.1
# is based on COPYING and COPYING is still there, and do not say anything
# about rezrov.
-git diff-index -C $tree >current
-cat >expected <<\EOF
-:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 06c67961bbaed34a127f76d261f4c0bf73eda471 M COPYING
-:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
-EOF
+test_expect_success 'validate output from rename/copy detection (#2)' '
+ mv COPYING.2 COPYING &&
+ git update-index --add --remove COPYING COPYING.1 COPYING.2 &&
-test_expect_success \
- 'validate output from rename/copy detection (#2)' \
- 'compare_diff_raw current expected'
+ cat <<-EOF >expected &&
+ :100644 100644 $origoid $oid2 M COPYING
+ :100644 100644 $origoid $oid1 C1234 COPYING COPYING.1
+ EOF
+ git diff-index -C $tree >current &&
+ compare_diff_raw current expected
+'
################################################################
-
# tree has COPYING and rezrov. work tree has the same COPYING and
# copy-edited COPYING.1, and unchanged rezrov. We should not say
# anything about rezrov or COPYING, since the revised again diff-raw
# nows how to say Copy.
-test_expect_success \
- 'prepare work tree once again' \
- 'cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
- git update-index --add --remove COPYING COPYING.1'
-
-git diff-index -C --find-copies-harder $tree >current
-cat >expected <<\EOF
-:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
-EOF
+test_expect_success 'validate output from rename/copy detection (#3)' '
+ cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
+ git update-index --add --remove COPYING COPYING.1 &&
-test_expect_success \
- 'validate output from rename/copy detection (#3)' \
- 'compare_diff_raw current expected'
+ cat <<-EOF >expected &&
+ :100644 100644 $origoid $oid1 C1234 COPYING COPYING.1
+ EOF
+ git diff-index -C --find-copies-harder $tree >current &&
+ compare_diff_raw current expected
+'
test_done
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index 2d9731b52..058ee0829 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -430,9 +430,11 @@ test_expect_success 'deleted submodule' '
test_cmp expected actual
'
-test_create_repo sm2 &&
-head7=$(add_file sm2 foo8 foo9) &&
-git add sm2
+test_expect_success 'create second submodule' '
+ test_create_repo sm2 &&
+ head7=$(add_file sm2 foo8 foo9) &&
+ git add sm2
+'
test_expect_success 'multiple submodules' '
git diff-index -p --submodule=log HEAD >actual &&
diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
index 33ec26d75..4b168d0ed 100755
--- a/t/t4060-diff-submodule-option-diff-format.sh
+++ b/t/t4060-diff-submodule-option-diff-format.sh
@@ -643,9 +643,11 @@ test_expect_success 'deleted submodule' '
test_cmp expected actual
'
-test_create_repo sm2 &&
-head7=$(add_file sm2 foo8 foo9) &&
-git add sm2
+test_expect_success 'create second submodule' '
+ test_create_repo sm2 &&
+ head7=$(add_file sm2 foo8 foo9) &&
+ git add sm2
+'
test_expect_success 'multiple submodules' '
git diff-index -p --submodule=diff HEAD >actual &&
diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh
index 7171f6753..9690dcad4 100755
--- a/t/t5100-mailinfo.sh
+++ b/t/t5100-mailinfo.sh
@@ -171,4 +171,46 @@ test_expect_success 'mailinfo with mailinfo.scissors config' '
'
+test_expect_success 'mailinfo no options' '
+ subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
+ git mailinfo /dev/null /dev/null)" &&
+ test z"$subj" = z"Subject: message"
+'
+
+test_expect_success 'mailinfo -k' '
+ subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
+ git mailinfo -k /dev/null /dev/null)" &&
+ test z"$subj" = z"Subject: [PATCH] [other] [PATCH] message"
+'
+
+test_expect_success 'mailinfo -b no [PATCH]' '
+ subj="$(echo "Subject: [other] message" |
+ git mailinfo -b /dev/null /dev/null)" &&
+ test z"$subj" = z"Subject: [other] message"
+'
+
+test_expect_success 'mailinfo -b leading [PATCH]' '
+ subj="$(echo "Subject: [PATCH] [other] message" |
+ git mailinfo -b /dev/null /dev/null)" &&
+ test z"$subj" = z"Subject: [other] message"
+'
+
+test_expect_success 'mailinfo -b double [PATCH]' '
+ subj="$(echo "Subject: [PATCH] [PATCH] message" |
+ git mailinfo -b /dev/null /dev/null)" &&
+ test z"$subj" = z"Subject: message"
+'
+
+test_expect_failure 'mailinfo -b trailing [PATCH]' '
+ subj="$(echo "Subject: [other] [PATCH] message" |
+ git mailinfo -b /dev/null /dev/null)" &&
+ test z"$subj" = z"Subject: [other] message"
+'
+
+test_expect_failure 'mailinfo -b separated double [PATCH]' '
+ subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
+ git mailinfo -b /dev/null /dev/null)" &&
+ test z"$subj" = z"Subject: [other] message"
+'
+
test_done
diff --git a/t/t6002-rev-list-bisect.sh b/t/t6002-rev-list-bisect.sh
index 3bf2759ea..534903bbd 100755
--- a/t/t6002-rev-list-bisect.sh
+++ b/t/t6002-rev-list-bisect.sh
@@ -235,4 +235,18 @@ test_sequence "--bisect"
#
#
+
+test_expect_success '--bisect can default to good/bad refs' '
+ git update-ref refs/bisect/bad c3 &&
+ good=$(git rev-parse b1) &&
+ git update-ref refs/bisect/good-$good $good &&
+ good=$(git rev-parse c1) &&
+ git update-ref refs/bisect/good-$good $good &&
+
+ # the only thing between c3 and c1 is c2
+ git rev-parse c2 >expect &&
+ git rev-list --bisect >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
index 4f3794d41..20b4d83c2 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -391,6 +391,17 @@ test_expect_success TTY 'core.pager in repo config works and retains cwd' '
)
'
+test_expect_success TTY 'core.pager is found via alias in subdirectory' '
+ sane_unset GIT_PAGER &&
+ test_config core.pager "cat >via-alias" &&
+ (
+ cd sub &&
+ rm -f via-alias &&
+ test_terminal git -c alias.r="-p rev-parse" r HEAD &&
+ test_path_is_file via-alias
+ )
+'
+
test_doesnt_paginate expect_failure test_must_fail 'git -p nonsense'
test_pager_choices 'git shortlog'
diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh
index 366746f0d..4e4c45550 100755
--- a/t/t7401-submodule-summary.sh
+++ b/t/t7401-submodule-summary.sh
@@ -241,9 +241,11 @@ EOF
test_cmp expected actual
"
-test_create_repo sm2 &&
-head7=$(add_file sm2 foo8 foo9) &&
-git add sm2
+test_expect_success 'create second submodule' '
+ test_create_repo sm2 &&
+ head7=$(add_file sm2 foo8 foo9) &&
+ git add sm2
+'
test_expect_success 'multiple submodules' "
git submodule summary >actual &&
diff --git a/t/t7414-submodule-mistakes.sh b/t/t7414-submodule-mistakes.sh
new file mode 100755
index 000000000..f2e7df59c
--- /dev/null
+++ b/t/t7414-submodule-mistakes.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+test_description='handling of common mistakes people may make with submodules'
+. ./test-lib.sh
+
+test_expect_success 'create embedded repository' '
+ git init embed &&
+ test_commit -C embed one
+'
+
+test_expect_success 'git-add on embedded repository warns' '
+ test_when_finished "git rm --cached -f embed" &&
+ git add embed 2>stderr &&
+ test_i18ngrep warning stderr
+'
+
+test_expect_success '--no-warn-embedded-repo suppresses warning' '
+ test_when_finished "git rm --cached -f embed" &&
+ git add --no-warn-embedded-repo embed 2>stderr &&
+ test_i18ngrep ! warning stderr
+'
+
+test_expect_success 'no warning when updating entry' '
+ test_when_finished "git rm --cached -f embed" &&
+ git add embed &&
+ git -C embed commit --allow-empty -m two &&
+ git add embed 2>stderr &&
+ test_i18ngrep ! warning stderr
+'
+
+test_expect_success 'submodule add does not warn' '
+ test_when_finished "git rm -rf submodule .gitmodules" &&
+ git submodule add ./embed submodule 2>stderr &&
+ test_i18ngrep ! warning stderr
+'
+
+test_done
diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
index 0b6da7ae1..fa61b1a4e 100755
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
@@ -18,7 +18,7 @@ test_expect_success 'initial status' '
echo bongo bongo >file &&
git add file &&
git status >actual &&
- test_i18ngrep "Initial commit" actual
+ test_i18ngrep "No commits yet" actual
'
test_expect_success 'fail initial amend' '
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 79427840a..43d19a9b2 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1603,9 +1603,71 @@ EOF
test_expect_success 'git commit -m will commit a staged but ignored submodule' '
git commit -uno -m message &&
git status -s --ignore-submodules=dirty >output &&
- test_i18ngrep ! "^M. sm" output &&
+ test_i18ngrep ! "^M. sm" output &&
git config --remove-section submodule.subname &&
git config -f .gitmodules --remove-section submodule.subname
'
+test_expect_success 'show stash info with "--show-stash"' '
+ git reset --hard &&
+ git stash clear &&
+ echo 1 >file &&
+ git add file &&
+ git stash &&
+ git status >expected_default &&
+ git status --show-stash >expected_with_stash &&
+ test_i18ngrep "^Your stash currently has 1 entry$" expected_with_stash
+'
+
+test_expect_success 'no stash info with "--show-stash --no-show-stash"' '
+ git status --show-stash --no-show-stash >expected_without_stash &&
+ test_cmp expected_default expected_without_stash
+'
+
+test_expect_success '"status.showStash=false" weaker than "--show-stash"' '
+ git -c status.showStash=false status --show-stash >actual &&
+ test_cmp expected_with_stash actual
+'
+
+test_expect_success '"status.showStash=true" weaker than "--no-show-stash"' '
+ git -c status.showStash=true status --no-show-stash >actual &&
+ test_cmp expected_without_stash actual
+'
+
+test_expect_success 'no additionnal info if no stash entries' '
+ git stash clear &&
+ git -c status.showStash=true status >actual &&
+ test_cmp expected_without_stash actual
+'
+
+test_expect_success '"No commits yet" should be noted in status output' '
+ git checkout --orphan empty-branch-1 &&
+ git status >output &&
+ test_i18ngrep "No commits yet" output
+'
+
+test_expect_success '"No commits yet" should not be noted in status output' '
+ git checkout --orphan empty-branch-2 &&
+ test_commit test-commit-1 &&
+ git status >output &&
+ test_i18ngrep ! "No commits yet" output
+'
+
+test_expect_success '"Initial commit" should be noted in commit template' '
+ git checkout --orphan empty-branch-3 &&
+ touch to_be_committed_1 &&
+ git add to_be_committed_1 &&
+ git commit --dry-run >output &&
+ test_i18ngrep "Initial commit" output
+'
+
+test_expect_success '"Initial commit" should not be noted in commit template' '
+ git checkout --orphan empty-branch-4 &&
+ test_commit test-commit-2 &&
+ touch to_be_committed_2 &&
+ git add to_be_committed_2 &&
+ git commit --dry-run >output &&
+ test_i18ngrep ! "Initial commit" output
+'
+
test_done
diff --git a/trailer.c b/trailer.c
index 11f0b9fb4..751b56c00 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "string-list.h"
#include "run-command.h"
#include "commit.h"
diff --git a/transport-helper.c b/transport-helper.c
index 36408046e..33cff38cc 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -242,8 +242,7 @@ static int disconnect_helper(struct transport *transport)
close(data->helper->out);
fclose(data->out);
res = finish_command(data->helper);
- free(data->helper);
- data->helper = NULL;
+ FREE_AND_NULL(data->helper);
}
return res;
}
@@ -711,43 +710,35 @@ static int push_update_ref_status(struct strbuf *buf,
if (!strcmp(msg, "no match")) {
status = REF_STATUS_NONE;
- free(msg);
- msg = NULL;
+ FREE_AND_NULL(msg);
}
else if (!strcmp(msg, "up to date")) {
status = REF_STATUS_UPTODATE;
- free(msg);
- msg = NULL;
+ FREE_AND_NULL(msg);
}
else if (!strcmp(msg, "non-fast forward")) {
status = REF_STATUS_REJECT_NONFASTFORWARD;
- free(msg);
- msg = NULL;
+ FREE_AND_NULL(msg);
}
else if (!strcmp(msg, "already exists")) {
status = REF_STATUS_REJECT_ALREADY_EXISTS;
- free(msg);
- msg = NULL;
+ FREE_AND_NULL(msg);
}
else if (!strcmp(msg, "fetch first")) {
status = REF_STATUS_REJECT_FETCH_FIRST;
- free(msg);
- msg = NULL;
+ FREE_AND_NULL(msg);
}
else if (!strcmp(msg, "needs force")) {
status = REF_STATUS_REJECT_NEEDS_FORCE;
- free(msg);
- msg = NULL;
+ FREE_AND_NULL(msg);
}
else if (!strcmp(msg, "stale info")) {
status = REF_STATUS_REJECT_STALE;
- free(msg);
- msg = NULL;
+ FREE_AND_NULL(msg);
}
else if (!strcmp(msg, "forced update")) {
forced = 1;
- free(msg);
- msg = NULL;
+ FREE_AND_NULL(msg);
}
}
diff --git a/transport.c b/transport.c
index 9bfcf870f..d75ff0514 100644
--- a/transport.c
+++ b/transport.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "transport.h"
#include "run-command.h"
#include "pkt-line.h"
@@ -1145,8 +1146,7 @@ void transport_unlock_pack(struct transport *transport)
{
if (transport->pack_lockfile) {
unlink_or_warn(transport->pack_lockfile);
- free(transport->pack_lockfile);
- transport->pack_lockfile = NULL;
+ FREE_AND_NULL(transport->pack_lockfile);
}
}
diff --git a/tree-diff.c b/tree-diff.c
index 467e38172..bd6d65a40 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -141,8 +141,7 @@ static struct combine_diff_path *path_appendnew(struct combine_diff_path *last,
/* if last->next is !NULL - it is a pre-allocated memory, we can reuse */
p = last->next;
if (p && (alloclen > (intptr_t)p->next)) {
- free(p);
- p = NULL;
+ FREE_AND_NULL(p);
}
if (!p) {
@@ -559,8 +558,7 @@ struct combine_diff_path *diff_tree_paths(
* (see path_appendnew() for details about why)
*/
if (p->next) {
- free(p->next);
- p->next = NULL;
+ FREE_AND_NULL(p->next);
}
return p;
diff --git a/tree.c b/tree.c
index 603b29ee8..b224115e0 100644
--- a/tree.c
+++ b/tree.c
@@ -1,3 +1,4 @@
+#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "cache-tree.h"
#include "tree.h"
@@ -8,7 +9,11 @@
const char *tree_type = "tree";
-static int read_one_entry_opt(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, int opt)
+static int read_one_entry_opt(struct index_state *istate,
+ const unsigned char *sha1,
+ const char *base, int baselen,
+ const char *pathname,
+ unsigned mode, int stage, int opt)
{
int len;
unsigned int size;
@@ -27,14 +32,15 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b
memcpy(ce->name, base, baselen);
memcpy(ce->name + baselen, pathname, len+1);
hashcpy(ce->oid.hash, sha1);
- return add_cache_entry(ce, opt);
+ return add_index_entry(istate, ce, opt);
}
static int read_one_entry(const unsigned char *sha1, struct strbuf *base,
const char *pathname, unsigned mode, int stage,
void *context)
{
- return read_one_entry_opt(sha1, base->buf, base->len, pathname,
+ struct index_state *istate = context;
+ return read_one_entry_opt(istate, sha1, base->buf, base->len, pathname,
mode, stage,
ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
}
@@ -47,7 +53,8 @@ static int read_one_entry_quick(const unsigned char *sha1, struct strbuf *base,
const char *pathname, unsigned mode, int stage,
void *context)
{
- return read_one_entry_opt(sha1, base->buf, base->len, pathname,
+ struct index_state *istate = context;
+ return read_one_entry_opt(istate, sha1, base->buf, base->len, pathname,
mode, stage,
ADD_CACHE_JUST_APPEND);
}
@@ -144,7 +151,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_)
ce2->name, ce2->ce_namelen, ce_stage(ce2));
}
-int read_tree(struct tree *tree, int stage, struct pathspec *match)
+int read_tree(struct tree *tree, int stage, struct pathspec *match,
+ struct index_state *istate)
{
read_tree_fn_t fn = NULL;
int i, err;
@@ -164,23 +172,23 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)
* do it the original slow way, otherwise, append and then
* sort at the end.
*/
- for (i = 0; !fn && i < active_nr; i++) {
- const struct cache_entry *ce = active_cache[i];
+ for (i = 0; !fn && i < istate->cache_nr; i++) {
+ const struct cache_entry *ce = istate->cache[i];
if (ce_stage(ce) == stage)
fn = read_one_entry;
}
if (!fn)
fn = read_one_entry_quick;
- err = read_tree_recursive(tree, "", 0, stage, match, fn, NULL);
+ err = read_tree_recursive(tree, "", 0, stage, match, fn, istate);
if (fn == read_one_entry || err)
return err;
/*
* Sort the cache entry -- we need to nuke the cache tree, though.
*/
- cache_tree_free(&active_cache_tree);
- QSORT(active_cache, active_nr, cmp_cache_name_compare);
+ cache_tree_free(&istate->cache_tree);
+ QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);
return 0;
}
@@ -226,8 +234,7 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
void free_tree_buffer(struct tree *tree)
{
- free(tree->buffer);
- tree->buffer = NULL;
+ FREE_AND_NULL(tree->buffer);
tree->size = 0;
tree->object.parsed = 0;
}
diff --git a/tree.h b/tree.h
index 0d4734b94..744e6dc2a 100644
--- a/tree.h
+++ b/tree.h
@@ -34,6 +34,7 @@ extern int read_tree_recursive(struct tree *tree,
int stage, const struct pathspec *pathspec,
read_tree_fn_t fn, void *context);
-extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec);
+extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec,
+ struct index_state *istate);
#endif /* TREE_H */
diff --git a/unpack-trees.c b/unpack-trees.c
index d38c37e38..dd535bc84 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,5 +1,6 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "tree.h"
#include "tree-walk.h"
diff --git a/upload-pack.c b/upload-pack.c
index 5330c02c1..7efff2fbf 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "pkt-line.h"
#include "sideband.h"
diff --git a/usage.c b/usage.c
index 2f87ca69a..1ea7df9a2 100644
--- a/usage.c
+++ b/usage.c
@@ -44,7 +44,23 @@ static void warn_builtin(const char *warn, va_list params)
static int die_is_recursing_builtin(void)
{
static int dying;
- return dying++;
+ /*
+ * Just an arbitrary number X where "a < x < b" where "a" is
+ * "maximum number of pthreads we'll ever plausibly spawn" and
+ * "b" is "something less than Inf", since the point is to
+ * prevent infinite recursion.
+ */
+ static const int recursion_limit = 1024;
+
+ dying++;
+ if (dying > recursion_limit) {
+ return 1;
+ } else if (dying == 2) {
+ warning("die() called many times. Recursion error or racy threaded death!");
+ return 0;
+ } else {
+ return 0;
+ }
}
/* If we are in a dlopen()ed .so write to a global variable would segfault
diff --git a/userdiff.c b/userdiff.c
index 8b732e40b..2c1502f71 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "userdiff.h"
#include "attr.h"
diff --git a/versioncmp.c b/versioncmp.c
index 9f81dc106..069ee94a4 100644
--- a/versioncmp.c
+++ b/versioncmp.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "string-list.h"
/*
diff --git a/wrapper.c b/wrapper.c
index 4632c7d4c..36630e5d1 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -2,6 +2,7 @@
* Various trivial helper wrappers around standard functions
*/
#include "cache.h"
+#include "config.h"
static void do_nothing(size_t size)
{
diff --git a/wt-status.c b/wt-status.c
index bf651f16f..8d2fb35b0 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -137,6 +137,7 @@ void wt_status_prepare(struct wt_status *s)
s->untracked.strdup_strings = 1;
s->ignored.strdup_strings = 1;
s->show_branch = -1; /* unspecified */
+ s->show_stash = 0;
s->display_comment_prefix = 0;
}
@@ -801,6 +802,27 @@ static void wt_longstatus_print_changed(struct wt_status *s)
wt_longstatus_print_trailer(s);
}
+static int stash_count_refs(struct object_id *ooid, struct object_id *noid,
+ const char *email, timestamp_t timestamp, int tz,
+ const char *message, void *cb_data)
+{
+ int *c = cb_data;
+ (*c)++;
+ return 0;
+}
+
+static void wt_longstatus_print_stash_summary(struct wt_status *s)
+{
+ int stash_count = 0;
+
+ for_each_reflog_ent("refs/stash", stash_count_refs, &stash_count);
+ if (stash_count > 0)
+ status_printf_ln(s, GIT_COLOR_NORMAL,
+ Q_("Your stash currently has %d entry",
+ "Your stash currently has %d entries", stash_count),
+ stash_count);
+}
+
static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncommitted)
{
struct child_process sm_summary = CHILD_PROCESS_INIT;
@@ -1579,7 +1601,10 @@ static void wt_longstatus_print(struct wt_status *s)
if (s->is_initial) {
status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", "");
- status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit"));
+ status_printf_ln(s, color(WT_STATUS_HEADER, s),
+ s->commit_template
+ ? _("Initial commit")
+ : _("No commits yet"));
status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", "");
}
@@ -1642,6 +1667,8 @@ static void wt_longstatus_print(struct wt_status *s)
} else
printf(_("nothing to commit, working tree clean\n"));
}
+ if(s->show_stash)
+ wt_longstatus_print_stash_summary(s);
}
static void wt_shortstatus_unmerged(struct string_list_item *it,
@@ -1749,7 +1776,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
#define LABEL(string) (s->no_gettext ? (string) : _(string))
if (s->is_initial)
- color_fprintf(s->fp, header_color, LABEL(N_("Initial commit on ")));
+ color_fprintf(s->fp, header_color, LABEL(N_("No commits yet on ")));
if (!strcmp(s->branch, "HEAD")) {
color_fprintf(s->fp, color(WT_STATUS_NOBRANCH, s), "%s",
diff --git a/wt-status.h b/wt-status.h
index 8a3864783..64f4d33ea 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -76,7 +76,9 @@ struct wt_status {
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
unsigned colopts;
int null_termination;
+ int commit_template;
int show_branch;
+ int show_stash;
int hints;
enum wt_status_format status_format;
diff --git a/xdiff-interface.c b/xdiff-interface.c
index d3f78ca2a..018e03308 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "xdiff-interface.h"
#include "xdiff/xtypes.h"
#include "xdiff/xdiffi.h"