Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/check-whitespace.yml5
-rw-r--r--.github/workflows/main.yml1
-rw-r--r--Documentation/MyFirstContribution.txt41
-rw-r--r--Documentation/MyFirstObjectWalk.txt31
-rw-r--r--Documentation/RelNotes/2.35.0.txt39
-rw-r--r--Documentation/date-formats.txt6
-rw-r--r--Documentation/git-archimport.txt14
-rw-r--r--Documentation/git-checkout.txt36
-rw-r--r--Documentation/git-cherry-pick.txt6
-rw-r--r--Documentation/git-clone.txt8
-rw-r--r--Documentation/git-config.txt46
-rw-r--r--Documentation/git-credential.txt2
-rw-r--r--Documentation/git-cvsexportcommit.txt4
-rw-r--r--Documentation/git-cvsimport.txt8
-rw-r--r--Documentation/git-diff-files.txt2
-rw-r--r--Documentation/git-diff-index.txt2
-rw-r--r--Documentation/git-diff-tree.txt2
-rw-r--r--Documentation/git-fsck.txt2
-rw-r--r--Documentation/git-gui.txt2
-rw-r--r--Documentation/git-help.txt6
-rw-r--r--Documentation/git-http-fetch.txt2
-rw-r--r--Documentation/git-http-push.txt15
-rw-r--r--Documentation/git-init-db.txt2
-rw-r--r--Documentation/git-init.txt27
-rw-r--r--Documentation/git-log.txt8
-rw-r--r--Documentation/git-ls-files.txt6
-rw-r--r--Documentation/git-merge-index.txt2
-rw-r--r--Documentation/git-p4.txt8
-rw-r--r--Documentation/git-pack-objects.txt4
-rw-r--r--Documentation/git-pack-redundant.txt2
-rw-r--r--Documentation/git-reflog.txt4
-rw-r--r--Documentation/git-remote.txt8
-rw-r--r--Documentation/git-request-pull.txt8
-rw-r--r--Documentation/git-send-email.txt6
-rw-r--r--Documentation/git-shortlog.txt8
-rw-r--r--Documentation/git-sparse-checkout.txt2
-rw-r--r--Documentation/git-stage.txt2
-rw-r--r--Documentation/git-stash.txt34
-rw-r--r--Documentation/git-status.txt8
-rw-r--r--Documentation/git-svn.txt2
-rw-r--r--Documentation/git-var.txt3
-rw-r--r--Documentation/git-web--browse.txt2
-rw-r--r--Documentation/git.txt5
-rw-r--r--Documentation/gitcredentials.txt4
-rw-r--r--Documentation/gitsubmodules.txt2
-rw-r--r--Documentation/gitworkflows.txt6
-rw-r--r--Documentation/pretty-formats.txt54
-rw-r--r--Documentation/rev-list-options.txt2
-rw-r--r--Documentation/technical/multi-pack-index.txt17
-rw-r--r--Documentation/technical/protocol-v2.txt6
-rw-r--r--Documentation/urls-remotes.txt8
-rw-r--r--Makefile28
-rw-r--r--builtin/branch.c13
-rw-r--r--builtin/checkout.c88
-rw-r--r--builtin/credential.c2
-rw-r--r--builtin/for-each-ref.c8
-rw-r--r--builtin/ls-remote.c13
-rw-r--r--builtin/multi-pack-index.c4
-rw-r--r--builtin/pack-objects.c11
-rw-r--r--builtin/pull.c2
-rw-r--r--builtin/repack.c6
-rw-r--r--builtin/reset.c113
-rw-r--r--builtin/stash.c80
-rw-r--r--builtin/submodule--helper.c21
-rw-r--r--builtin/tag.c13
-rw-r--r--builtin/var.c7
-rw-r--r--cache-tree.c46
-rw-r--r--cache.h11
-rwxr-xr-xci/check-directional-formatting.bash27
-rw-r--r--command-list.txt22
-rw-r--r--compat/unsetenv.c4
-rw-r--r--config.mak.uname1
-rw-r--r--configure.ac8
-rw-r--r--contrib/buildsystems/CMakeLists.txt3
-rw-r--r--contrib/completion/git-completion.bash11
-rw-r--r--contrib/git-jump/README3
-rwxr-xr-xcontrib/git-jump/git-jump2
-rw-r--r--convert.c2
-rw-r--r--date.c2
-rw-r--r--delta.h6
-rw-r--r--diffcore-delta.c6
-rw-r--r--entry.c8
-rw-r--r--entry.h2
-rw-r--r--fetch-pack.c10
-rwxr-xr-xgenerate-cmdlist.sh78
-rw-r--r--git-compat-util.h40
-rwxr-xr-xgit-filter-branch.sh2
-rwxr-xr-xgit-instaweb.sh9
-rwxr-xr-xgit-send-email.perl56
-rw-r--r--git-sh-setup.sh8
-rw-r--r--http-fetch.c14
-rw-r--r--mergesort.c2
-rw-r--r--midx.c66
-rw-r--r--midx.h4
-rw-r--r--object-file.c8
-rw-r--r--pack-bitmap.c31
-rw-r--r--pack-revindex.c8
-rw-r--r--packfile.c8
-rw-r--r--pager.c4
-rw-r--r--parallel-checkout.c2
-rw-r--r--pkt-line.c40
-rw-r--r--pkt-line.h1
-rw-r--r--read-cache.c35
-rw-r--r--ref-filter.c34
-rw-r--r--ref-filter.h28
-rw-r--r--refs.c140
-rw-r--r--refs.h14
-rw-r--r--refs/debug.c5
-rw-r--r--refs/files-backend.c158
-rw-r--r--refs/packed-backend.c10
-rw-r--r--refs/refs-internal.h28
-rw-r--r--remote.c369
-rw-r--r--remote.h35
-rw-r--r--repository.c8
-rw-r--r--repository.h4
-rw-r--r--run-command.c19
-rw-r--r--sequencer.c10
-rw-r--r--sparse-index.c58
-rw-r--r--sparse-index.h1
-rw-r--r--strbuf.c14
-rw-r--r--t/helper/test-genzeros.c21
-rw-r--r--t/helper/test-read-cache.c5
-rw-r--r--t/helper/test-read-midx.c3
-rw-r--r--t/helper/test-ref-store.c6
-rwxr-xr-xt/perf/p2000-sparse-operations.sh3
-rwxr-xr-xt/t0006-date.sh4
-rwxr-xr-xt/t0007-git-var.sh20
-rwxr-xr-xt/t0020-crlf.sh1
-rwxr-xr-xt/t0110-urlmatch-normalization.sh2
-rwxr-xr-xt/t1005-read-tree-reset.sh1
-rwxr-xr-xt/t1008-read-tree-overlay.sh1
-rwxr-xr-xt/t1051-large-conversion.sh26
-rwxr-xr-xt/t1092-sparse-checkout-compatibility.sh185
-rwxr-xr-xt/t1403-show-ref.sh1
-rwxr-xr-xt/t1405-main-ref-store.sh2
-rwxr-xr-xt/t1406-submodule-ref-store.sh3
-rwxr-xr-xt/t1417-reflog-updateref.sh65
-rwxr-xr-xt/t1505-rev-parse-last.sh1
-rwxr-xr-xt/t2007-checkout-symlink.sh1
-rwxr-xr-xt/t2008-checkout-subdir.sh1
-rwxr-xr-xt/t2009-checkout-statinfo.sh1
-rwxr-xr-xt/t2010-checkout-ambiguous.sh1
-rwxr-xr-xt/t2011-checkout-invalid-head.sh1
-rwxr-xr-xt/t2014-checkout-switch.sh2
-rwxr-xr-xt/t2017-checkout-orphan.sh1
-rwxr-xr-xt/t2019-checkout-ambiguous-ref.sh2
-rwxr-xr-xt/t2021-checkout-overwrite.sh2
-rwxr-xr-xt/t2022-checkout-paths.sh1
-rwxr-xr-xt/t2026-checkout-pathspec-file.sh1
-rwxr-xr-xt/t2106-update-index-assume-unchanged.sh1
-rwxr-xr-xt/t3040-subprojects-basic.sh2
-rwxr-xr-xt/t3200-branch.sh34
-rwxr-xr-xt/t3305-notes-fanout.sh1
-rwxr-xr-xt/t3422-rebase-incompatible-options.sh2
-rwxr-xr-xt/t3903-stash.sh11
-rwxr-xr-xt/t4115-apply-symlink.sh1
-rwxr-xr-xt/t4121-apply-diffs.sh1
-rwxr-xr-xt/t4204-patch-id.sh1
-rwxr-xr-xt/t5319-multi-pack-index.sh6
-rwxr-xr-xt/t5410-receive-pack-alternates.sh1
-rwxr-xr-xt/t5516-fetch-push.sh9
-rwxr-xr-xt/t5609-clone-branch.sh1
-rwxr-xr-xt/t5702-protocol-v2.sh51
-rwxr-xr-xt/t6300-for-each-ref.sh26
-rwxr-xr-xt/t6407-merge-binary.sh1
-rwxr-xr-xt/t6414-merge-rename-nocruft.sh1
-rwxr-xr-xt/t7006-pager.sh59
-rwxr-xr-xt/t7064-wtstatus-pv2.sh15
-rwxr-xr-xt/t7102-reset.sh17
-rwxr-xr-xt/t7113-post-index-change-hook.sh1
-rwxr-xr-xt/t7400-submodule-basic.sh11
-rwxr-xr-xt/t7509-commit-authorship.sh1
-rwxr-xr-xt/t7815-grep-binary.sh1
-rwxr-xr-xt/t9102-git-svn-deep-rmdir.sh2
-rwxr-xr-xt/t9123-git-svn-rebuild-with-rewriteroot.sh1
-rwxr-xr-xt/t9128-git-svn-cmd-branch.sh2
-rwxr-xr-xt/t9167-git-svn-cmd-branch-subproject.sh2
-rwxr-xr-xt/t9902-completion.sh3
-rw-r--r--t/test-lib.sh4
-rw-r--r--trace2/tr2_dst.c9
-rw-r--r--unpack-trees.c23
-rw-r--r--urlmatch.c2
-rw-r--r--worktree.c17
-rw-r--r--wt-status.c25
184 files changed, 2275 insertions, 898 deletions
diff --git a/.github/workflows/check-whitespace.yml b/.github/workflows/check-whitespace.yml
index 8c4358d805..ad3466ad16 100644
--- a/.github/workflows/check-whitespace.yml
+++ b/.github/workflows/check-whitespace.yml
@@ -1,8 +1,9 @@
name: check-whitespace
-# Get the repo with the commits(+1) in the series.
+# Get the repository with all commits to ensure that we can analyze
+# all of the commits contributed via the Pull Request.
# Process `git log --check` output to extract just the check errors.
-# Add a comment to the pull request with the check errors.
+# Exit with failure upon white-space issues.
on:
pull_request:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 6ed6a9e807..deda12db3a 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -289,6 +289,7 @@ jobs:
- uses: actions/checkout@v2
- run: ci/install-dependencies.sh
- run: ci/run-static-analysis.sh
+ - run: ci/check-directional-formatting.bash
sparse:
needs: ci-config
if: needs.ci-config.outputs.enabled == 'yes'
diff --git a/Documentation/MyFirstContribution.txt b/Documentation/MyFirstContribution.txt
index b20bc8e914..63a2ef5449 100644
--- a/Documentation/MyFirstContribution.txt
+++ b/Documentation/MyFirstContribution.txt
@@ -905,19 +905,34 @@ Sending emails with Git is a two-part process; before you can prepare the emails
themselves, you'll need to prepare the patches. Luckily, this is pretty simple:
----
-$ git format-patch --cover-letter -o psuh/ master..psuh
-----
-
-The `--cover-letter` parameter tells `format-patch` to create a cover letter
-template for you. You will need to fill in the template before you're ready
-to send - but for now, the template will be next to your other patches.
-
-The `-o psuh/` parameter tells `format-patch` to place the patch files into a
-directory. This is useful because `git send-email` can take a directory and
-send out all the patches from there.
-
-`master..psuh` tells `format-patch` to generate patches for the difference
-between `master` and `psuh`. It will make one patch file per commit. After you
+$ git format-patch --cover-letter -o psuh/ --base=auto psuh@{u}..psuh
+----
+
+ . The `--cover-letter` option tells `format-patch` to create a
+ cover letter template for you. You will need to fill in the
+ template before you're ready to send - but for now, the template
+ will be next to your other patches.
+
+ . The `-o psuh/` option tells `format-patch` to place the patch
+ files into a directory. This is useful because `git send-email`
+ can take a directory and send out all the patches from there.
+
+ . The `--base=auto` option tells the command to record the "base
+ commit", on which the recipient is expected to apply the patch
+ series. The `auto` value will cause `format-patch` to compute
+ the base commit automatically, which is the merge base of tip
+ commit of the remote-tracking branch and the specified revision
+ range.
+
+ . The `psuh@{u}..psuh` option tells `format-patch` to generate
+ patches for the commits you created on the `psuh` branch since it
+ forked from its upstream (which is `origin/master` if you
+ followed the example in the "Set up your workspace" section). If
+ you are already on the `psuh` branch, you can just say `@{u}`,
+ which means "commits on the current branch since it forked from
+ its upstream", which is the same thing.
+
+The command will make one patch file per commit. After you
run, you can go have a look at each of the patches with your favorite text
editor and make sure everything looks alright; however, it's not recommended to
make code fixups via the patch file. It's a better idea to make the change the
diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index 45eb84d8b4..ca267941f3 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -58,14 +58,19 @@ running, enable trace output by setting the environment variable `GIT_TRACE`.
Add usage text and `-h` handling, like all subcommands should consistently do
(our test suite will notice and complain if you fail to do so).
+We'll need to include the `parse-options.h` header.
----
+#include "parse-options.h"
+
+...
+
int cmd_walken(int argc, const char **argv, const char *prefix)
{
const char * const walken_usage[] = {
N_("git walken"),
NULL,
- }
+ };
struct option options[] = {
OPT_END()
};
@@ -195,9 +200,14 @@ Similarly to the default values, we don't have anything to do here yet
ourselves; however, we should call `git_default_config()` if we aren't calling
any other existing config callbacks.
-Add a new function to `builtin/walken.c`:
+Add a new function to `builtin/walken.c`.
+We'll also need to include the `config.h` header:
----
+#include "config.h"
+
+...
+
static int git_walken_config(const char *var, const char *value, void *cb)
{
/*
@@ -229,8 +239,14 @@ typically done by calling `repo_init_revisions()` with the repository you intend
to target, as well as the `prefix` argument of `cmd_walken` and your `rev_info`
struct.
-Add the `struct rev_info` and the `repo_init_revisions()` call:
+Add the `struct rev_info` and the `repo_init_revisions()` call.
+We'll also need to include the `revision.h` header:
+
----
+#include "revision.h"
+
+...
+
int cmd_walken(int argc, const char **argv, const char *prefix)
{
/* This can go wherever you like in your declarations.*/
@@ -624,9 +640,14 @@ static void walken_object_walk(struct rev_info *rev)
----
Let's start by calling just the unfiltered walk and reporting our counts.
-Complete your implementation of `walken_object_walk()`:
+Complete your implementation of `walken_object_walk()`.
+We'll also need to include the `list-objects.h` header.
----
+#include "list-objects.h"
+
+...
+
traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL);
printf("commits %d\nblobs %d\ntags %d\ntrees %d\n", commit_count,
@@ -697,7 +718,7 @@ First, we'll need to `#include "list-objects-filter-options.h"` and set up the
----
static void walken_object_walk(struct rev_info *rev)
{
- struct list_objects_filter_options filter_options = {};
+ struct list_objects_filter_options filter_options = { 0 };
...
----
diff --git a/Documentation/RelNotes/2.35.0.txt b/Documentation/RelNotes/2.35.0.txt
index 47124fdbd9..120fac5b21 100644
--- a/Documentation/RelNotes/2.35.0.txt
+++ b/Documentation/RelNotes/2.35.0.txt
@@ -4,11 +4,31 @@ Git 2.35 Release Notes
Updates since Git 2.34
----------------------
+Backward compatibility warts
+
+ * "_" is now treated as any other URL-valid characters in an URL when
+ matching the per-URL configuration variable names.
+
+
UI, Workflows & Features
+ * "git status --porcelain=v2" now show the number of stash entries
+ with --show-stash like the normal output does.
+
+ * "git stash" learned the "--staged" option to stash away what has
+ been added to the index (and nothing else).
+
Performance, Internal Implementation, Development Support etc.
+ * The use of errno as a means to carry the nature of error in the ref
+ API implementation has been reworked and reduced.
+
+ * Teach and encourage first-time contributors to this project to
+ state the base commit when they submit their topic.
+
+ * The command line complation for "git send-email" options have been
+ tweaked to make it easier to keep it in sync with the command itself.
Fixes since v2.34
@@ -19,16 +39,27 @@ Fixes since v2.34
library in the latest release.
* Other code cleanup, docfix, build fix, etc.
- (merge edbd9f3715 ab/update-submitting-patches later to maint).
* "git pull" with any strategy when the other side is behind us
should succeed as it is a no-op, but doesn't.
- (merge ea1954af ev/pull-already-up-to-date-is-noop later to maint).
* An earlier change in 2.34.0 caused JGit application (that abused
GIT_EDITOR mechanism when invoking "git config") to get stuck with
a SIGTTOU signal; it has been reverted.
- (merge e3f7e01b50 jc/save-restore-terminal-revert later to maint).
* An earlier change that broke .gitignore matching has been reverted.
- (merge 33c5d6c845 ds/add-rm-with-sparse-index later to maint).
+
+ * Things like "git -c branch.sort=bogus branch new HEAD", i.e. the
+ operation modes of the "git branch" command that do not need the
+ sort key information, no longer errors out by seeing a bogus sort
+ key.
+ (merge 98e7ab6d42 jc/fix-ref-sorting-parse later to maint).
+
+ * The compatibility implementation for unsetenv(3) were written to
+ mimic ancient, non-POSIX, variant seen in an old glibc; it has been
+ changed to return an integer to match the more modern era.
+ (merge a38989bd5b jc/unsetenv-returns-an-int later to maint).
+
+ * The clean/smudge conversion code path has been prepared to better
+ work on platforms where ulong is narrower than size_t.
+ (merge 596b5e77c9 mc/clean-smudge-with-llp64 later to maint).
diff --git a/Documentation/date-formats.txt b/Documentation/date-formats.txt
index 99c455f51c..67645cae64 100644
--- a/Documentation/date-formats.txt
+++ b/Documentation/date-formats.txt
@@ -5,9 +5,9 @@ The `GIT_AUTHOR_DATE` and `GIT_COMMITTER_DATE` environment variables
support the following date formats:
Git internal format::
- It is `<unix timestamp> <time zone offset>`, where `<unix
- timestamp>` is the number of seconds since the UNIX epoch.
- `<time zone offset>` is a positive or negative offset from UTC.
+ It is `<unix-timestamp> <time-zone-offset>`, where
+ `<unix-timestamp>` is the number of seconds since the UNIX epoch.
+ `<time-zone-offset>` is a positive or negative offset from UTC.
For example CET (which is 1 hour ahead of UTC) is `+0100`.
RFC 2822::
diff --git a/Documentation/git-archimport.txt b/Documentation/git-archimport.txt
index a595a0ffee..847777fd17 100644
--- a/Documentation/git-archimport.txt
+++ b/Documentation/git-archimport.txt
@@ -9,14 +9,14 @@ git-archimport - Import a GNU Arch repository into Git
SYNOPSIS
--------
[verse]
-'git archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir]
- <archive/branch>[:<git-branch>] ...
+'git archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D <depth>] [-t <tempdir>]
+ <archive>/<branch>[:<git-branch>]...
DESCRIPTION
-----------
Imports a project from one or more GNU Arch repositories.
It will follow branches
-and repositories within the namespaces defined by the <archive/branch>
+and repositories within the namespaces defined by the <archive>/<branch>
parameters supplied. If it cannot find the remote branch a merge comes from
it will just import it as a regular commit. If it can find it, it will mark it
as a merge whenever possible (see discussion below).
@@ -27,7 +27,7 @@ import new branches within the provided roots.
It expects to be dealing with one project only. If it sees
branches that have different roots, it will refuse to run. In that case,
-edit your <archive/branch> parameters to define clearly the scope of the
+edit your <archive>/<branch> parameters to define clearly the scope of the
import.
'git archimport' uses `tla` extensively in the background to access the
@@ -42,7 +42,7 @@ incremental imports.
While 'git archimport' will try to create sensible branch names for the
archives that it imports, it is also possible to specify Git branch names
-manually. To do so, write a Git branch name after each <archive/branch>
+manually. To do so, write a Git branch name after each <archive>/<branch>
parameter, separated by a colon. This way, you can shorten the Arch
branch names and convert Arch jargon to Git jargon, for example mapping a
"PROJECT{litdd}devo{litdd}VERSION" branch to "master".
@@ -104,8 +104,8 @@ OPTIONS
Override the default tempdir.
-<archive/branch>::
- Archive/branch identifier in a format that `tla log` understands.
+<archive>/<branch>::
+ <archive>/<branch> identifier in a format that `tla log` understands.
GIT
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index d473c9bf38..a52dc49a3d 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -11,7 +11,7 @@ SYNOPSIS
'git checkout' [-q] [-f] [-m] [<branch>]
'git checkout' [-q] [-f] [-m] --detach [<branch>]
'git checkout' [-q] [-f] [-m] [--detach] <commit>
-'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
+'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] <new-branch>] [<start-point>]
'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <pathspec>...
'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] --pathspec-from-file=<file> [--pathspec-file-nul]
'git checkout' (-p|--patch) [<tree-ish>] [--] [<pathspec>...]
@@ -43,7 +43,7 @@ You could omit `<branch>`, in which case the command degenerates to
rather expensive side-effects to show only the tracking information,
if exists, for the current branch.
-'git checkout' -b|-B <new_branch> [<start point>]::
+'git checkout' -b|-B <new-branch> [<start-point>]::
Specifying `-b` causes a new branch to be created as if
linkgit:git-branch[1] were called and then checked out. In
@@ -52,11 +52,11 @@ if exists, for the current branch.
`--track` without `-b` implies branch creation; see the
description of `--track` below.
+
-If `-B` is given, `<new_branch>` is created if it doesn't exist; otherwise, it
+If `-B` is given, `<new-branch>` is created if it doesn't exist; otherwise, it
is reset. This is the transactional equivalent of
+
------------
-$ git branch -f <branch> [<start point>]
+$ git branch -f <branch> [<start-point>]
$ git checkout <branch>
------------
+
@@ -145,13 +145,13 @@ as `ours` (i.e. "our shared canonical history"), while what you did
on your side branch as `theirs` (i.e. "one contributor's work on top
of it").
--b <new_branch>::
- Create a new branch named `<new_branch>` and start it at
- `<start_point>`; see linkgit:git-branch[1] for details.
+-b <new-branch>::
+ Create a new branch named `<new-branch>` and start it at
+ `<start-point>`; see linkgit:git-branch[1] for details.
--B <new_branch>::
- Creates the branch `<new_branch>` and start it at `<start_point>`;
- if it already exists, then reset it to `<start_point>`. This is
+-B <new-branch>::
+ Creates the branch `<new-branch>` and start it at `<start-point>`;
+ if it already exists, then reset it to `<start-point>`. This is
equivalent to running "git branch" with "-f"; see
linkgit:git-branch[1] for details.
@@ -210,16 +210,16 @@ variable.
`<commit>` is not a branch name. See the "DETACHED HEAD" section
below for details.
---orphan <new_branch>::
- Create a new 'orphan' branch, named `<new_branch>`, started from
- `<start_point>` and switch to it. The first commit made on this
+--orphan <new-branch>::
+ Create a new 'orphan' branch, named `<new-branch>`, started from
+ `<start-point>` and switch to it. The first commit made on this
new branch will have no parents and it will be the root of a new
history totally disconnected from all the other branches and
commits.
+
The index and the working tree are adjusted as if you had previously run
-`git checkout <start_point>`. This allows you to start a new history
-that records a set of paths similar to `<start_point>` by easily running
+`git checkout <start-point>`. This allows you to start a new history
+that records a set of paths similar to `<start-point>` by easily running
`git commit -a` to make the root commit.
+
This can be useful when you want to publish the tree from a commit
@@ -229,7 +229,7 @@ whose full history contains proprietary or otherwise encumbered bits of
code.
+
If you want to start a disconnected history that records a set of paths
-that is totally different from the one of `<start_point>`, then you should
+that is totally different from the one of `<start-point>`, then you should
clear the index and the working tree right after creating the orphan
branch by running `git rm -rf .` from the top level of the working tree.
Afterwards you will be ready to prepare your new files, repopulating the
@@ -341,10 +341,10 @@ As a special case, you may use `A...B` as a shortcut for the
merge base of `A` and `B` if there is exactly one merge base. You can
leave out at most one of `A` and `B`, in which case it defaults to `HEAD`.
-<new_branch>::
+<new-branch>::
Name for the new branch.
-<start_point>::
+<start-point>::
The name of a commit at which to start the new branch; see
linkgit:git-branch[1] for details. Defaults to `HEAD`.
+
diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
index 5d750314b2..78dcc9171f 100644
--- a/Documentation/git-cherry-pick.txt
+++ b/Documentation/git-cherry-pick.txt
@@ -8,7 +8,7 @@ git-cherry-pick - Apply the changes introduced by some existing commits
SYNOPSIS
--------
[verse]
-'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]
+'git cherry-pick' [--edit] [-n] [-m <parent-number>] [-s] [-x] [--ff]
[-S[<keyid>]] <commit>...
'git cherry-pick' (--continue | --skip | --abort | --quit)
@@ -81,8 +81,8 @@ OPTIONS
described above, and `-r` was to disable it. Now the
default is not to do `-x` so this option is a no-op.
--m parent-number::
---mainline parent-number::
+-m <parent-number>::
+--mainline <parent-number>::
Usually you cannot cherry-pick a merge because you do not know which
side of the merge should be considered the mainline. This
option specifies the parent number (starting from 1) of
diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 3fe3810f1c..9685ea0691 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -9,10 +9,10 @@ git-clone - Clone a repository into a new directory
SYNOPSIS
--------
[verse]
-'git clone' [--template=<template_directory>]
+'git clone' [--template=<template-directory>]
[-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
[-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
- [--dissociate] [--separate-git-dir <git dir>]
+ [--dissociate] [--separate-git-dir <git-dir>]
[--depth <depth>] [--[no-]single-branch] [--no-tags]
[--recurse-submodules[=<pathspec>]] [--[no-]shallow-submodules]
[--[no-]remote-submodules] [--jobs <n>] [--sparse] [--[no-]reject-shallow]
@@ -211,7 +211,7 @@ objects from the source repository into a pack in the cloned repository.
via ssh, this specifies a non-default path for the command
run on the other end.
---template=<template_directory>::
+--template=<template-directory>::
Specify the directory from which templates will be used;
(See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].)
@@ -294,7 +294,7 @@ or `--mirror` is given)
superproject's recorded SHA-1. Equivalent to passing `--remote` to
`git submodule update`.
---separate-git-dir=<git dir>::
+--separate-git-dir=<git-dir>::
Instead of placing the cloned repository where it is supposed
to be, place the cloned repository at the specified directory,
then make a filesystem-agnostic Git symbolic link to there.
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index 992225f612..2285effb36 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -9,20 +9,20 @@ git-config - Get and set repository or global options
SYNOPSIS
--------
[verse]
-'git config' [<file-option>] [--type=<type>] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] name [value [value-pattern]]
-'git config' [<file-option>] [--type=<type>] --add name value
-'git config' [<file-option>] [--type=<type>] [--fixed-value] --replace-all name value [value-pattern]
-'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get name [value-pattern]
-'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get-all name [value-pattern]
-'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] --get-regexp name_regex [value-pattern]
-'git config' [<file-option>] [--type=<type>] [-z|--null] --get-urlmatch name URL
-'git config' [<file-option>] [--fixed-value] --unset name [value-pattern]
-'git config' [<file-option>] [--fixed-value] --unset-all name [value-pattern]
-'git config' [<file-option>] --rename-section old_name new_name
-'git config' [<file-option>] --remove-section name
+'git config' [<file-option>] [--type=<type>] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] <name> [<value> [<value-pattern>]]
+'git config' [<file-option>] [--type=<type>] --add <name> <value>
+'git config' [<file-option>] [--type=<type>] [--fixed-value] --replace-all <name> <value> [<value-pattern>]
+'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get <name> [<value-pattern>]
+'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get-all <name> [<value-pattern>]
+'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] --get-regexp <name-regex> [<value-pattern>]
+'git config' [<file-option>] [--type=<type>] [-z|--null] --get-urlmatch <name> <URL>
+'git config' [<file-option>] [--fixed-value] --unset <name> [<value-pattern>]
+'git config' [<file-option>] [--fixed-value] --unset-all <name> [<value-pattern>]
+'git config' [<file-option>] --rename-section <old-name> <new-name>
+'git config' [<file-option>] --remove-section <name>
'git config' [<file-option>] [--show-origin] [--show-scope] [-z|--null] [--name-only] -l | --list
-'git config' [<file-option>] --get-color name [default]
-'git config' [<file-option>] --get-colorbool name [stdout-is-tty]
+'git config' [<file-option>] --get-color <name> [<default>]
+'git config' [<file-option>] --get-colorbool <name> [<stdout-is-tty>]
'git config' [<file-option>] -e | --edit
DESCRIPTION
@@ -102,9 +102,9 @@ OPTIONS
in which section and variable names are lowercased, but subsection
names are not.
---get-urlmatch name URL::
+--get-urlmatch <name> <URL>::
When given a two-part name section.key, the value for
- section.<url>.key whose <url> part matches the best to the
+ section.<URL>.key whose <URL> part matches the best to the
given URL is returned (if no such key exists, the value for
section.key is used as a fallback). When given just the
section as name, do so for all the keys in the section and
@@ -145,8 +145,8 @@ See also <<FILES>>.
read from or written to if `extensions.worktreeConfig` is
present. If not it's the same as `--local`.
--f config-file::
---file config-file::
+-f <config-file>::
+--file <config-file>::
For writing options: write to the specified file rather than the
repository `.git/config`.
+
@@ -155,7 +155,7 @@ available files.
+
See also <<FILES>>.
---blob blob::
+--blob <blob>::
Similar to `--file` but use the given blob instead of a file. E.g.
you can use 'master:.gitmodules' to read values from the file
'.gitmodules' in the master branch. See "SPECIFYING REVISIONS"
@@ -246,18 +246,18 @@ Valid `<type>`'s include:
all queried config options with the scope of that value
(local, global, system, command).
---get-colorbool name [stdout-is-tty]::
+--get-colorbool <name> [<stdout-is-tty>]::
- Find the color setting for `name` (e.g. `color.diff`) and output
- "true" or "false". `stdout-is-tty` should be either "true" or
+ Find the color setting for `<name>` (e.g. `color.diff`) and output
+ "true" or "false". `<stdout-is-tty>` should be either "true" or
"false", and is taken into account when configuration says
- "auto". If `stdout-is-tty` is missing, then checks the standard
+ "auto". If `<stdout-is-tty>` is missing, then checks the standard
output of the command itself, and exits with status 0 if color
is to be used, or exits with status 1 otherwise.
When the color setting for `name` is undefined, the command uses
`color.ui` as fallback.
---get-color name [default]::
+--get-color <name> [<default>]::
Find the color configured for `name` (e.g. `color.diff.new`) and
output it as the ANSI color escape sequence to the standard
diff --git a/Documentation/git-credential.txt b/Documentation/git-credential.txt
index 206e3c5f40..f18673017f 100644
--- a/Documentation/git-credential.txt
+++ b/Documentation/git-credential.txt
@@ -8,7 +8,7 @@ git-credential - Retrieve and store user credentials
SYNOPSIS
--------
------------------
-git credential <fill|approve|reject>
+'git credential' (fill|approve|reject)
------------------
DESCRIPTION
diff --git a/Documentation/git-cvsexportcommit.txt b/Documentation/git-cvsexportcommit.txt
index 00154b6c85..41c8a8a05c 100644
--- a/Documentation/git-cvsexportcommit.txt
+++ b/Documentation/git-cvsexportcommit.txt
@@ -9,8 +9,8 @@ git-cvsexportcommit - Export a single commit to a CVS checkout
SYNOPSIS
--------
[verse]
-'git cvsexportcommit' [-h] [-u] [-v] [-c] [-P] [-p] [-a] [-d cvsroot]
- [-w cvsworkdir] [-W] [-f] [-m msgprefix] [PARENTCOMMIT] COMMITID
+'git cvsexportcommit' [-h] [-u] [-v] [-c] [-P] [-p] [-a] [-d <cvsroot>]
+ [-w <cvs-workdir>] [-W] [-f] [-m <msgprefix>] [<parent-commit>] <commit-id>
DESCRIPTION
diff --git a/Documentation/git-cvsimport.txt b/Documentation/git-cvsimport.txt
index de1ebed67d..b3f27671a0 100644
--- a/Documentation/git-cvsimport.txt
+++ b/Documentation/git-cvsimport.txt
@@ -11,9 +11,9 @@ SYNOPSIS
[verse]
'git cvsimport' [-o <branch-for-HEAD>] [-h] [-v] [-d <CVSROOT>]
[-A <author-conv-file>] [-p <options-for-cvsps>] [-P <file>]
- [-C <git_repository>] [-z <fuzz>] [-i] [-k] [-u] [-s <subst>]
- [-a] [-m] [-M <regex>] [-S <regex>] [-L <commitlimit>]
- [-r <remote>] [-R] [<CVS_module>]
+ [-C <git-repository>] [-z <fuzz>] [-i] [-k] [-u] [-s <subst>]
+ [-a] [-m] [-M <regex>] [-S <regex>] [-L <commit-limit>]
+ [-r <remote>] [-R] [<CVS-module>]
DESCRIPTION
@@ -59,7 +59,7 @@ OPTIONS
from `CVS/Root`. If no such file exists, it checks for the
`CVSROOT` environment variable.
-<CVS_module>::
+<CVS-module>::
The CVS module you want to import. Relative to <CVSROOT>.
If not given, 'git cvsimport' tries to read it from
`CVS/Repository`.
diff --git a/Documentation/git-diff-files.txt b/Documentation/git-diff-files.txt
index 906774f0f7..bf1febb9ae 100644
--- a/Documentation/git-diff-files.txt
+++ b/Documentation/git-diff-files.txt
@@ -9,7 +9,7 @@ git-diff-files - Compares files in the working tree and the index
SYNOPSIS
--------
[verse]
-'git diff-files' [-q] [-0|-1|-2|-3|-c|--cc] [<common diff options>] [<path>...]
+'git diff-files' [-q] [-0|-1|-2|-3|-c|--cc] [<common-diff-options>] [<path>...]
DESCRIPTION
-----------
diff --git a/Documentation/git-diff-index.txt b/Documentation/git-diff-index.txt
index 27acb31cbf..679cae27d9 100644
--- a/Documentation/git-diff-index.txt
+++ b/Documentation/git-diff-index.txt
@@ -9,7 +9,7 @@ git-diff-index - Compare a tree to the working tree or index
SYNOPSIS
--------
[verse]
-'git diff-index' [-m] [--cached] [--merge-base] [<common diff options>] <tree-ish> [<path>...]
+'git diff-index' [-m] [--cached] [--merge-base] [<common-diff-options>] <tree-ish> [<path>...]
DESCRIPTION
-----------
diff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt
index 2fc24c542f..274d5eaba9 100644
--- a/Documentation/git-diff-tree.txt
+++ b/Documentation/git-diff-tree.txt
@@ -11,7 +11,7 @@ SYNOPSIS
[verse]
'git diff-tree' [--stdin] [-m] [-s] [-v] [--no-commit-id] [--pretty]
[-t] [-r] [-c | --cc] [--combined-all-paths] [--root] [--merge-base]
- [<common diff options>] <tree-ish> [<tree-ish>] [<path>...]
+ [<common-diff-options>] <tree-ish> [<tree-ish>] [<path>...]
DESCRIPTION
-----------
diff --git a/Documentation/git-fsck.txt b/Documentation/git-fsck.txt
index bd596619c0..5088783dcc 100644
--- a/Documentation/git-fsck.txt
+++ b/Documentation/git-fsck.txt
@@ -12,7 +12,7 @@ SYNOPSIS
'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
[--[no-]full] [--strict] [--verbose] [--lost-found]
[--[no-]dangling] [--[no-]progress] [--connectivity-only]
- [--[no-]name-objects] [<object>*]
+ [--[no-]name-objects] [<object>...]
DESCRIPTION
-----------
diff --git a/Documentation/git-gui.txt b/Documentation/git-gui.txt
index c9d7e96214..e8f3ccb433 100644
--- a/Documentation/git-gui.txt
+++ b/Documentation/git-gui.txt
@@ -8,7 +8,7 @@ git-gui - A portable graphical interface to Git
SYNOPSIS
--------
[verse]
-'git gui' [<command>] [arguments]
+'git gui' [<command>] [<arguments>]
DESCRIPTION
-----------
diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt
index 96d5f598b4..44ea63cc6d 100644
--- a/Documentation/git-help.txt
+++ b/Documentation/git-help.txt
@@ -9,14 +9,14 @@ SYNOPSIS
--------
[verse]
'git help' [-a|--all [--[no-]verbose]]
- [[-i|--info] [-m|--man] [-w|--web]] [COMMAND|GUIDE]
+ [[-i|--info] [-m|--man] [-w|--web]] [<command>|<guide>]
'git help' [-g|--guides]
'git help' [-c|--config]
DESCRIPTION
-----------
-With no options and no COMMAND or GUIDE given, the synopsis of the 'git'
+With no options and no '<command>' or '<guide>' given, the synopsis of the 'git'
command and a list of the most commonly used Git commands are printed
on the standard output.
@@ -33,7 +33,7 @@ variables.
If an alias is given, git shows the definition of the alias on
standard output. To get the manual page for the aliased command, use
-`git COMMAND --help`.
+`git <command> --help`.
Note that `git --help ...` is identical to `git help ...` because the
former is internally converted into the latter.
diff --git a/Documentation/git-http-fetch.txt b/Documentation/git-http-fetch.txt
index 9fa17b60e4..319062c021 100644
--- a/Documentation/git-http-fetch.txt
+++ b/Documentation/git-http-fetch.txt
@@ -9,7 +9,7 @@ git-http-fetch - Download from a remote Git repository via HTTP
SYNOPSIS
--------
[verse]
-'git http-fetch' [-c] [-t] [-a] [-d] [-v] [-w filename] [--recover] [--stdin | --packfile=<hash> | <commit>] <url>
+'git http-fetch' [-c] [-t] [-a] [-d] [-v] [-w <filename>] [--recover] [--stdin | --packfile=<hash> | <commit>] <URL>
DESCRIPTION
-----------
diff --git a/Documentation/git-http-push.txt b/Documentation/git-http-push.txt
index ea03a4eeb0..7c6a6dd7f6 100644
--- a/Documentation/git-http-push.txt
+++ b/Documentation/git-http-push.txt
@@ -9,7 +9,7 @@ git-http-push - Push objects over HTTP/DAV to another repository
SYNOPSIS
--------
[verse]
-'git http-push' [--all] [--dry-run] [--force] [--verbose] <url> <ref> [<ref>...]
+'git http-push' [--all] [--dry-run] [--force] [--verbose] <URL> <ref> [<ref>...]
DESCRIPTION
-----------
@@ -63,16 +63,15 @@ of such patterns separated by a colon ":" (this means that a ref name
cannot have a colon in it). A single pattern '<name>' is just a
shorthand for '<name>:<name>'.
-Each pattern pair consists of the source side (before the colon)
-and the destination side (after the colon). The ref to be
-pushed is determined by finding a match that matches the source
-side, and where it is pushed is determined by using the
-destination side.
+Each pattern pair '<src>:<dst>' consists of the source side (before
+the colon) and the destination side (after the colon). The ref to be
+pushed is determined by finding a match that matches the source side,
+and where it is pushed is determined by using the destination side.
- - It is an error if <src> does not match exactly one of the
+ - It is an error if '<src>' does not match exactly one of the
local refs.
- - If <dst> does not match any remote ref, either
+ - If '<dst>' does not match any remote ref, either
* it has to start with "refs/"; <dst> is used as the
destination literally in this case.
diff --git a/Documentation/git-init-db.txt b/Documentation/git-init-db.txt
index 648a6cd78a..18bf1a3c8c 100644
--- a/Documentation/git-init-db.txt
+++ b/Documentation/git-init-db.txt
@@ -9,7 +9,7 @@ git-init-db - Creates an empty Git repository
SYNOPSIS
--------
[verse]
-'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--separate-git-dir <git dir>] [--shared[=<permissions>]]
+'git init-db' [-q | --quiet] [--bare] [--template=<template-directory>] [--separate-git-dir <git-dir>] [--shared[=<permissions>]]
DESCRIPTION
diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt
index b611d80697..ad921fe782 100644
--- a/Documentation/git-init.txt
+++ b/Documentation/git-init.txt
@@ -9,10 +9,10 @@ git-init - Create an empty Git repository or reinitialize an existing one
SYNOPSIS
--------
[verse]
-'git init' [-q | --quiet] [--bare] [--template=<template_directory>]
- [--separate-git-dir <git dir>] [--object-format=<format>]
+'git init' [-q | --quiet] [--bare] [--template=<template-directory>]
+ [--separate-git-dir <git-dir>] [--object-format=<format>]
[-b <branch-name> | --initial-branch=<branch-name>]
- [--shared[=<permissions>]] [directory]
+ [--shared[=<permissions>]] [<directory>]
DESCRIPTION
@@ -57,12 +57,12 @@ values are 'sha1' and (if enabled) 'sha256'. 'sha1' is the default.
+
include::object-format-disclaimer.txt[]
---template=<template_directory>::
+--template=<template-directory>::
Specify the directory from which templates will be used. (See the "TEMPLATE
DIRECTORY" section below.)
---separate-git-dir=<git dir>::
+--separate-git-dir=<git-dir>::
Instead of initializing the repository as a directory to either `$GIT_DIR` or
`./.git/`, create a text file there containing the path to the actual
@@ -79,7 +79,7 @@ repository. If not specified, fall back to the default name (currently
`master`, but this is subject to change in the future; the name can be
customized via the `init.defaultBranch` configuration variable).
---shared[=(false|true|umask|group|all|world|everybody|0xxx)]::
+--shared[=(false|true|umask|group|all|world|everybody|<perm>)]::
Specify that the Git repository is to be shared amongst several users. This
allows users belonging to the same group to push into that
@@ -110,13 +110,16 @@ the repository permissions.
Same as 'group', but make the repository readable by all users.
-'0xxx'::
+'<perm>'::
-'0xxx' is an octal number and each file will have mode '0xxx'. '0xxx' will
-override users' umask(2) value (and not only loosen permissions as 'group' and
-'all' does). '0640' will create a repository which is group-readable, but not
-group-writable or accessible to others. '0660' will create a repo that is
-readable and writable to the current user and group, but inaccessible to others.
+'<perm>' is a 3-digit octal number prefixed with `0` and each file
+will have mode '<perm>'. '<perm>' will override users' umask(2)
+value (and not only loosen permissions as 'group' and 'all'
+does). '0640' will create a repository which is group-readable, but
+not group-writable or accessible to others. '0660' will create a repo
+that is readable and writable to the current user and group, but
+inaccessible to others (directories and executable files get their
+`x` bit from the `r` bit for corresponding classes of users).
--
By default, the configuration flag `receive.denyNonFastForwards` is enabled
diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 0498e7bacb..20e87cecf4 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -9,7 +9,7 @@ git-log - Show commit logs
SYNOPSIS
--------
[verse]
-'git log' [<options>] [<revision range>] [[--] <path>...]
+'git log' [<options>] [<revision-range>] [[--] <path>...]
DESCRIPTION
-----------
@@ -81,13 +81,13 @@ produced by `--stat`, etc.
include::line-range-options.txt[]
-<revision range>::
+<revision-range>::
Show only commits in the specified revision range. When no
- <revision range> is specified, it defaults to `HEAD` (i.e. the
+ <revision-range> is specified, it defaults to `HEAD` (i.e. the
whole history leading to the current commit). `origin..HEAD`
specifies all the commits reachable from the current commit
(i.e. `HEAD`), but not from `origin`. For a complete list of
- ways to spell <revision range>, see the 'Specifying Ranges'
+ ways to spell <revision-range>, see the 'Specifying Ranges'
section of linkgit:gitrevisions[7].
[--] <path>...::
diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
index 6d11ab506b..2e3d695fa2 100644
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -10,9 +10,9 @@ SYNOPSIS
--------
[verse]
'git ls-files' [-z] [-t] [-v] [-f]
- (--[cached|deleted|others|ignored|stage|unmerged|killed|modified])*
- (-[c|d|o|i|s|u|k|m])*
- [--eol]
+ [-c|--cached] [-d|--deleted] [-o|--others] [-i|--|ignored]
+ [-s|--stage] [-u|--unmerged] [-k|--|killed] [-m|--modified]
+ [--directory [--no-empty-directory]] [--eol]
[--deduplicate]
[-x <pattern>|--exclude=<pattern>]
[-X <file>|--exclude-from=<file>]
diff --git a/Documentation/git-merge-index.txt b/Documentation/git-merge-index.txt
index 2ab84a91e5..eea56b3154 100644
--- a/Documentation/git-merge-index.txt
+++ b/Documentation/git-merge-index.txt
@@ -9,7 +9,7 @@ git-merge-index - Run a merge for files needing merging
SYNOPSIS
--------
[verse]
-'git merge-index' [-o] [-q] <merge-program> (-a | [--] <file>*)
+'git merge-index' [-o] [-q] <merge-program> (-a | ( [--] <file>...) )
DESCRIPTION
-----------
diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt
index 38e5257b2a..e21fcd8f71 100644
--- a/Documentation/git-p4.txt
+++ b/Documentation/git-p4.txt
@@ -9,10 +9,10 @@ git-p4 - Import from and submit to Perforce repositories
SYNOPSIS
--------
[verse]
-'git p4 clone' [<sync options>] [<clone options>] <p4 depot path>...
-'git p4 sync' [<sync options>] [<p4 depot path>...]
+'git p4 clone' [<sync-options>] [<clone-options>] <p4-depot-path>...
+'git p4 sync' [<sync-options>] [<p4-depot-path>...]
'git p4 rebase'
-'git p4 submit' [<submit options>] [<master branch name>]
+'git p4 submit' [<submit-options>] [<master-branch-name>]
DESCRIPTION
@@ -361,7 +361,7 @@ These options can be used to modify 'git p4 submit' behavior.
p4/master. See the "Sync options" section above for more
information.
---commit <sha1>|<sha1..sha1>::
+--commit (<sha1>|<sha1>..<sha1>)::
Submit only the specified commit or range of commits, instead of the full
list of changes that are in the current Git branch.
diff --git a/Documentation/git-pack-objects.txt b/Documentation/git-pack-objects.txt
index dbfd1f9017..f8344e1e5b 100644
--- a/Documentation/git-pack-objects.txt
+++ b/Documentation/git-pack-objects.txt
@@ -13,8 +13,8 @@ SYNOPSIS
[--no-reuse-delta] [--delta-base-offset] [--non-empty]
[--local] [--incremental] [--window=<n>] [--depth=<n>]
[--revs [--unpacked | --all]] [--keep-pack=<pack-name>]
- [--stdout [--filter=<filter-spec>] | base-name]
- [--shallow] [--keep-true-parents] [--[no-]sparse] < object-list
+ [--stdout [--filter=<filter-spec>] | <base-name>]
+ [--shallow] [--keep-true-parents] [--[no-]sparse] < <object-list>
DESCRIPTION
diff --git a/Documentation/git-pack-redundant.txt b/Documentation/git-pack-redundant.txt
index f2869da572..ee7034b5e5 100644
--- a/Documentation/git-pack-redundant.txt
+++ b/Documentation/git-pack-redundant.txt
@@ -9,7 +9,7 @@ git-pack-redundant - Find redundant pack files
SYNOPSIS
--------
[verse]
-'git pack-redundant' [ --verbose ] [ --alt-odb ] < --all | .pack filename ... >
+'git pack-redundant' [ --verbose ] [ --alt-odb ] ( --all | <pack-filename>... )
DESCRIPTION
-----------
diff --git a/Documentation/git-reflog.txt b/Documentation/git-reflog.txt
index ff487ff77d..5ced7ad4f8 100644
--- a/Documentation/git-reflog.txt
+++ b/Documentation/git-reflog.txt
@@ -17,12 +17,12 @@ The command takes various subcommands, and different options
depending on the subcommand:
[verse]
-'git reflog' ['show'] [log-options] [<ref>]
+'git reflog' ['show'] [<log-options>] [<ref>]
'git reflog expire' [--expire=<time>] [--expire-unreachable=<time>]
[--rewrite] [--updateref] [--stale-fix]
[--dry-run | -n] [--verbose] [--all [--single-worktree] | <refs>...]
'git reflog delete' [--rewrite] [--updateref]
- [--dry-run | -n] [--verbose] ref@\{specifier\}...
+ [--dry-run | -n] [--verbose] <ref>@\{<specifier>\}...
'git reflog exists' <ref>
Reference logs, or "reflogs", record when the tips of branches and
diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index 31c29c9b31..2bebc32566 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
--------
[verse]
'git remote' [-v | --verbose]
-'git remote add' [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=(fetch|push)] <name> <url>
+'git remote add' [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=(fetch|push)] <name> <URL>
'git remote rename' <old> <new>
'git remote remove' <name>
'git remote set-head' <name> (-a | --auto | -d | --delete | <branch>)
@@ -18,7 +18,7 @@ SYNOPSIS
'git remote get-url' [--push] [--all] <name>
'git remote set-url' [--push] <name> <newurl> [<oldurl>]
'git remote set-url --add' [--push] <name> <newurl>
-'git remote set-url --delete' [--push] <name> <url>
+'git remote set-url --delete' [--push] <name> <URL>
'git remote' [-v | --verbose] 'show' [-n] <name>...
'git remote prune' [-n | --dry-run] <name>...
'git remote' [-v | --verbose] 'update' [-p | --prune] [(<group> | <remote>)...]
@@ -47,7 +47,7 @@ subcommands are available to perform operations on the remotes.
'add'::
Add a remote named <name> for the repository at
-<url>. The command `git fetch <name>` can then be used to create and
+<URL>. The command `git fetch <name>` can then be used to create and
update remote-tracking branches <name>/<branch>.
+
With `-f` option, `git fetch <name>` is run immediately after
@@ -152,7 +152,7 @@ With `--push`, push URLs are manipulated instead of fetch URLs.
With `--add`, instead of changing existing URLs, new URL is added.
+
With `--delete`, instead of changing existing URLs, all URLs matching
-regex <url> are deleted for remote <name>. Trying to delete all
+regex <URL> are deleted for remote <name>. Trying to delete all
non-push URLs is an error.
+
Note that the push URL and the fetch URL, even though they can
diff --git a/Documentation/git-request-pull.txt b/Documentation/git-request-pull.txt
index 4d4392d0f8..fa5a426709 100644
--- a/Documentation/git-request-pull.txt
+++ b/Documentation/git-request-pull.txt
@@ -8,7 +8,7 @@ git-request-pull - Generates a summary of pending changes
SYNOPSIS
--------
[verse]
-'git request-pull' [-p] <start> <url> [<end>]
+'git request-pull' [-p] <start> <URL> [<end>]
DESCRIPTION
-----------
@@ -21,7 +21,7 @@ the changes and indicates from where they can be pulled.
The upstream project is expected to have the commit named by
`<start>` and the output asks it to integrate the changes you made
since that commit, up to the commit named by `<end>`, by visiting
-the repository named by `<url>`.
+the repository named by `<URL>`.
OPTIONS
@@ -33,14 +33,14 @@ OPTIONS
Commit to start at. This names a commit that is already in
the upstream history.
-<url>::
+<URL>::
The repository URL to be pulled from.
<end>::
Commit to end at (defaults to HEAD). This names the commit
at the tip of the history you are asking to be pulled.
+
-When the repository named by `<url>` has the commit at a tip of a
+When the repository named by `<URL>` has the commit at a tip of a
ref that is different from the ref you have locally, you can use the
`<local>:<remote>` syntax, to have its local name, a colon `:`, and
its remote name.
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 3db4eab4ba..41cd8cb424 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -9,7 +9,8 @@ git-send-email - Send a collection of patches as emails
SYNOPSIS
--------
[verse]
-'git send-email' [<options>] <file|directory|rev-list options>...
+'git send-email' [<options>] <file|directory>...
+'git send-email' [<options>] <format-patch options>
'git send-email' --dump-aliases
@@ -19,7 +20,8 @@ Takes the patches given on the command line and emails them out.
Patches can be specified as files, directories (which will send all
files in the directory), or directly as a revision list. In the
last case, any format accepted by linkgit:git-format-patch[1] can
-be passed to git send-email.
+be passed to git send-email, as well as options understood by
+linkgit:git-format-patch[1].
The header of the email is configurable via command-line options. If not
specified on the command line, the user will be prompted with a ReadLine
diff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt
index c9c7f3065c..f64e77047b 100644
--- a/Documentation/git-shortlog.txt
+++ b/Documentation/git-shortlog.txt
@@ -8,7 +8,7 @@ git-shortlog - Summarize 'git log' output
SYNOPSIS
--------
[verse]
-'git shortlog' [<options>] [<revision range>] [[--] <path>...]
+'git shortlog' [<options>] [<revision-range>] [[--] <path>...]
git log --pretty=short | 'git shortlog' [<options>]
DESCRIPTION
@@ -89,13 +89,13 @@ counts both authors and co-authors.
If width is `0` (zero) then indent the lines of the output without wrapping
them.
-<revision range>::
+<revision-range>::
Show only commits in the specified revision range. When no
- <revision range> is specified, it defaults to `HEAD` (i.e. the
+ <revision-range> is specified, it defaults to `HEAD` (i.e. the
whole history leading to the current commit). `origin..HEAD`
specifies all the commits reachable from the current commit
(i.e. `HEAD`), but not from `origin`. For a complete list of
- ways to spell <revision range>, see the "Specifying Ranges"
+ ways to spell <revision-range>, see the "Specifying Ranges"
section of linkgit:gitrevisions[7].
[--] <path>...::
diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt
index 42056ee9ff..9a78dd721e 100644
--- a/Documentation/git-sparse-checkout.txt
+++ b/Documentation/git-sparse-checkout.txt
@@ -11,7 +11,7 @@ given by a list of patterns.
SYNOPSIS
--------
[verse]
-'git sparse-checkout <subcommand> [options]'
+'git sparse-checkout <subcommand> [<options>]'
DESCRIPTION
diff --git a/Documentation/git-stage.txt b/Documentation/git-stage.txt
index 25bcda936d..2f6aaa75b9 100644
--- a/Documentation/git-stage.txt
+++ b/Documentation/git-stage.txt
@@ -9,7 +9,7 @@ git-stage - Add file contents to the staging area
SYNOPSIS
--------
[verse]
-'git stage' args...
+'git stage' <arg>...
DESCRIPTION
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index be6084ccef..6e15f47525 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -13,7 +13,7 @@ SYNOPSIS
'git stash' drop [-q|--quiet] [<stash>]
'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>]
'git stash' branch <branchname> [<stash>]
-'git stash' [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
+'git stash' [push [-p|--patch] [-S|--staged] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [-m|--message <message>]
[--pathspec-from-file=<file> [--pathspec-file-nul]]
[--] [<pathspec>...]]
@@ -47,7 +47,7 @@ stash index (e.g. the integer `n` is equivalent to `stash@{n}`).
COMMANDS
--------
-push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>] [--pathspec-from-file=<file> [--pathspec-file-nul]] [--] [<pathspec>...]::
+push [-p|--patch] [-S|--staged] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>] [--pathspec-from-file=<file> [--pathspec-file-nul]] [--] [<pathspec>...]::
Save your local modifications to a new 'stash entry' and roll them
back to HEAD (in the working tree and in the index).
@@ -60,7 +60,7 @@ subcommand from making an unwanted stash entry. The two exceptions to this
are `stash -p` which acts as alias for `stash push -p` and pathspec elements,
which are allowed after a double hyphen `--` for disambiguation.
-save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]::
+save [-p|--patch] [-S|--staged] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]::
This option is deprecated in favour of 'git stash push'. It
differs from "stash push" in that it cannot take pathspec.
@@ -205,6 +205,16 @@ to learn how to operate the `--patch` mode.
The `--patch` option implies `--keep-index`. You can use
`--no-keep-index` to override this.
+-S::
+--staged::
+ This option is only valid for `push` and `save` commands.
++
+Stash only the changes that are currently staged. This is similar to
+basic `git commit` except the state is committed to the stash instead
+of current branch.
++
+The `--patch` option has priority over this one.
+
--pathspec-from-file=<file>::
This option is only valid for `push` command.
+
@@ -341,6 +351,24 @@ $ edit/build/test remaining parts
$ git commit foo -m 'Remaining parts'
----------------------------------------------------------------
+Saving unrelated changes for future use::
+
+When you are in the middle of massive changes and you find some
+unrelated issue that you don't want to forget to fix, you can do the
+change(s), stage them, and use `git stash push --staged` to stash them
+out for future use. This is similar to committing the staged changes,
+only the commit ends-up being in the stash and not on the current branch.
++
+----------------------------------------------------------------
+# ... hack hack hack ...
+$ git add --patch foo # add unrelated changes to the index
+$ git stash push --staged # save these changes to the stash
+# ... hack hack hack, finish curent changes ...
+$ git commit -m 'Massive' # commit fully tested changes
+$ git switch fixup-branch # switch to another branch
+$ git stash pop # to finish work on the saved changes
+----------------------------------------------------------------
+
Recovering stash entries that were cleared/dropped erroneously::
If you mistakenly drop or clear stash entries, they cannot be recovered
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index 4a2c3e0408..54a4b29b47 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -314,6 +314,14 @@ Line Notes
------------------------------------------------------------
....
+Stash Information
+^^^^^^^^^^^^^^^^^
+
+If `--show-stash` is given, one line is printed showing the number of stash
+entries if non-zero:
+
+ # stash <N>
+
Changed Tracked Entries
^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index 222b556d7a..4e92308e85 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -575,7 +575,7 @@ OPTIONS
-------
--shared[=(false|true|umask|group|all|world|everybody)]::
---template=<template_directory>::
+--template=<template-directory>::
Only used with the 'init' command.
These are passed directly to 'git init'.
diff --git a/Documentation/git-var.txt b/Documentation/git-var.txt
index 6072f936ab..387cc1b914 100644
--- a/Documentation/git-var.txt
+++ b/Documentation/git-var.txt
@@ -59,6 +59,9 @@ ifdef::git-default-pager[]
The build you are using chose '{git-default-pager}' as the default.
endif::git-default-pager[]
+GIT_DEFAULT_BRANCH::
+ The name of the first branch created in newly initialized repositories.
+
SEE ALSO
--------
linkgit:git-commit-tree[1]
diff --git a/Documentation/git-web--browse.txt b/Documentation/git-web--browse.txt
index 8d162b56c5..f2f996cbe1 100644
--- a/Documentation/git-web--browse.txt
+++ b/Documentation/git-web--browse.txt
@@ -8,7 +8,7 @@ git-web--browse - Git helper script to launch a web browser
SYNOPSIS
--------
[verse]
-'git web{litdd}browse' [<options>] <url|file>...
+'git web{litdd}browse' [<options>] (<URL>|<file>)...
DESCRIPTION
-----------
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 281c5f8cae..13f83a2a3a 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -832,8 +832,9 @@ for full details.
`GIT_TRACE_REDACT`::
By default, when tracing is activated, Git redacts the values of
- cookies, the "Authorization:" header, and the "Proxy-Authorization:"
- header. Set this variable to `0` to prevent this redaction.
+ cookies, the "Authorization:" header, the "Proxy-Authorization:"
+ header and packfile URIs. Set this variable to `0` to prevent this
+ redaction.
`GIT_LITERAL_PATHSPECS`::
Setting this variable to `1` will cause Git to treat all
diff --git a/Documentation/gitcredentials.txt b/Documentation/gitcredentials.txt
index 758bf39ba3..80517b4eb2 100644
--- a/Documentation/gitcredentials.txt
+++ b/Documentation/gitcredentials.txt
@@ -132,7 +132,7 @@ because the hostnames differ. Nor would it match `foo.example.com`; Git
compares hostnames exactly, without considering whether two hosts are part of
the same domain. Likewise, a config entry for `http://example.com` would not
match: Git compares the protocols exactly. However, you may use wildcards in
-the domain name and other pattern matching techniques as with the `http.<url>.*`
+the domain name and other pattern matching techniques as with the `http.<URL>.*`
options.
If the "pattern" URL does include a path component, then this too must match
@@ -147,7 +147,7 @@ CONFIGURATION OPTIONS
Options for a credential context can be configured either in
`credential.*` (which applies to all credentials), or
-`credential.<url>.*`, where <url> matches the context as described
+`credential.<URL>.*`, where <URL> matches the context as described
above.
The following options are available in either location:
diff --git a/Documentation/gitsubmodules.txt b/Documentation/gitsubmodules.txt
index 891c8da4fd..941858a6ec 100644
--- a/Documentation/gitsubmodules.txt
+++ b/Documentation/gitsubmodules.txt
@@ -226,7 +226,7 @@ Workflow for a third party library
----------------------------------
# Add a submodule
- git submodule add <url> <path>
+ git submodule add <URL> <path>
# Occasionally update the submodule to a new version:
git -C <path> checkout <new version>
diff --git a/Documentation/gitworkflows.txt b/Documentation/gitworkflows.txt
index 47cf97f9be..59305265c5 100644
--- a/Documentation/gitworkflows.txt
+++ b/Documentation/gitworkflows.txt
@@ -394,7 +394,7 @@ request to do so by mail. Such a request looks like
-------------------------------------
Please pull from
- <url> <branch>
+ <URL> <branch>
-------------------------------------
In that case, 'git pull' can do the fetch and merge in one go, as
@@ -403,7 +403,7 @@ follows.
.Push/pull: Merging remote topics
[caption="Recipe: "]
=====================================
-`git pull <url> <branch>`
+`git pull <URL> <branch>`
=====================================
Occasionally, the maintainer may get merge conflicts when they try to
@@ -440,7 +440,7 @@ merge because you cannot format-patch merges):
.format-patch/am: Keeping topics up to date
[caption="Recipe: "]
=====================================
-`git pull --rebase <url> <branch>`
+`git pull --rebase <URL> <branch>`
=====================================
You can then fix the conflicts during the rebase. Presumably you have
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index ef6bd420ae..23f6335887 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -20,7 +20,7 @@ built-in formats:
* 'oneline'
- <hash> <title line>
+ <hash> <title-line>
+
This is designed to be as compact as possible.
@@ -29,17 +29,17 @@ This is designed to be as compact as possible.
commit <hash>
Author: <author>
- <title line>
+ <title-line>
* 'medium'
commit <hash>
Author: <author>
- Date: <author date>
+ Date: <author-date>
- <title line>
+ <title-line>
- <full commit message>
+ <full-commit-message>
* 'full'
@@ -47,25 +47,25 @@ This is designed to be as compact as possible.
Author: <author>
Commit: <committer>
- <title line>
+ <title-line>
- <full commit message>
+ <full-commit-message>
* 'fuller'
commit <hash>
Author: <author>
- AuthorDate: <author date>
+ AuthorDate: <author-date>
Commit: <committer>
- CommitDate: <committer date>
+ CommitDate: <committer-date>
- <title line>
+ <title-line>
- <full commit message>
+ <full-commit-message>
* 'reference'
- <abbrev hash> (<title line>, <short author date>)
+ <abbrev-hash> (<title-line>, <short-author-date>)
+
This format is used to refer to another commit in a commit message and
is the same as `--pretty='format:%C(auto)%h (%s, %ad)'`. By default,
@@ -78,10 +78,10 @@ placeholders, its output is not affected by other options like
From <hash> <date>
From: <author>
- Date: <author date>
- Subject: [PATCH] <title line>
+ Date: <author-date>
+ Subject: [PATCH] <title-line>
- <full commit message>
+ <full-commit-message>
* 'mboxrd'
+
@@ -101,9 +101,9 @@ commits are displayed, but not the way the diff is shown e.g. with
`git log --raw`. To get full object names in a raw diff format,
use `--no-abbrev`.
-* 'format:<string>'
+* 'format:<format-string>'
+
-The 'format:<string>' format allows you to specify which information
+The 'format:<format-string>' format allows you to specify which information
you want to show. It works a little bit like printf format,
with the notable exception that you get a newline with '%n'
instead of '\n'.
@@ -273,12 +273,12 @@ endif::git-rev-list[]
If any option is provided multiple times the
last occurrence wins.
+
-The boolean options accept an optional value `[=<BOOL>]`. The values
+The boolean options accept an optional value `[=<value>]`. The values
`true`, `false`, `on`, `off` etc. are all accepted. See the "boolean"
sub-section in "EXAMPLES" in linkgit:git-config[1]. If a boolean
option is given with no value, it's enabled.
+
-** 'key=<K>': only show trailers with specified key. Matching is done
+** 'key=<key>': only show trailers with specified <key>. Matching is done
case-insensitively and trailing colon is optional. If option is
given multiple times trailer lines matching any of the keys are
shown. This option automatically enables the `only` option so that
@@ -286,25 +286,25 @@ option is given with no value, it's enabled.
desired it can be disabled with `only=false`. E.g.,
`%(trailers:key=Reviewed-by)` shows trailer lines with key
`Reviewed-by`.
-** 'only[=<BOOL>]': select whether non-trailer lines from the trailer
+** 'only[=<bool>]': select whether non-trailer lines from the trailer
block should be included.
-** 'separator=<SEP>': specify a separator inserted between trailer
+** 'separator=<sep>': specify a separator inserted between trailer
lines. When this option is not given each trailer line is
- terminated with a line feed character. The string SEP may contain
+ terminated with a line feed character. The string <sep> may contain
the literal formatting codes described above. To use comma as
separator one must use `%x2C` as it would otherwise be parsed as
next option. E.g., `%(trailers:key=Ticket,separator=%x2C )`
shows all trailer lines whose key is "Ticket" separated by a comma
and a space.
-** 'unfold[=<BOOL>]': make it behave as if interpret-trailer's `--unfold`
+** 'unfold[=<bool>]': make it behave as if interpret-trailer's `--unfold`
option was given. E.g.,
`%(trailers:only,unfold=true)` unfolds and shows all trailer lines.
-** 'keyonly[=<BOOL>]': only show the key part of the trailer.
-** 'valueonly[=<BOOL>]': only show the value part of the trailer.
-** 'key_value_separator=<SEP>': specify a separator inserted between
+** 'keyonly[=<bool>]': only show the key part of the trailer.
+** 'valueonly[=<bool>]': only show the value part of the trailer.
+** 'key_value_separator=<sep>': specify a separator inserted between
trailer lines. When this option is not given each trailer key-value
pair is separated by ": ". Otherwise it shares the same semantics
- as 'separator=<SEP>' above.
+ as 'separator=<sep>' above.
NOTE: Some placeholders may depend on other options given to the
revision traversal engine. For example, the `%g*` reflog options will
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 24569b06d1..43a86fa562 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -1047,7 +1047,7 @@ omitted.
has no effect.
`--date=format:...` feeds the format `...` to your system `strftime`,
-except for %z and %Z, which are handled internally.
+except for %s, %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/Documentation/technical/multi-pack-index.txt b/Documentation/technical/multi-pack-index.txt
index 86f40f2490..b39c69da8c 100644
--- a/Documentation/technical/multi-pack-index.txt
+++ b/Documentation/technical/multi-pack-index.txt
@@ -17,12 +17,12 @@ is not feasible due to storage space or excessive repack times.
The multi-pack-index (MIDX for short) stores a list of objects
and their offsets into multiple packfiles. It contains:
-- A list of packfile names.
-- A sorted list of object IDs.
-- A list of metadata for the ith object ID including:
- - A value j referring to the jth packfile.
- - An offset within the jth packfile for the object.
-- If large offsets are required, we use another list of large
+* A list of packfile names.
+* A sorted list of object IDs.
+* A list of metadata for the ith object ID including:
+** A value j referring to the jth packfile.
+** An offset within the jth packfile for the object.
+* If large offsets are required, we use another list of large
offsets similar to version 2 pack-indexes.
Thus, we can provide O(log N) lookup time for any number
@@ -87,11 +87,6 @@ Future Work
helpful to organize packfiles by object type (commit, tree, blob,
etc.) and use this metadata to help that maintenance.
-- The partial clone feature records special "promisor" packs that
- may point to objects that are not stored locally, but available
- on request to a server. The multi-pack-index does not currently
- track these promisor packs.
-
Related Links
-------------
[0] https://bugs.chromium.org/p/git/issues/detail?id=6
diff --git a/Documentation/technical/protocol-v2.txt b/Documentation/technical/protocol-v2.txt
index 21e8258ccf..8a877d27e2 100644
--- a/Documentation/technical/protocol-v2.txt
+++ b/Documentation/technical/protocol-v2.txt
@@ -125,11 +125,11 @@ command can be requested at a time.
empty-request = flush-pkt
command-request = command
capability-list
- [command-args]
+ delim-pkt
+ command-args
flush-pkt
command = PKT-LINE("command=" key LF)
- command-args = delim-pkt
- *command-specific-arg
+ command-args = *command-specific-arg
command-specific-args are packet line framed arguments defined by
each individual command.
diff --git a/Documentation/urls-remotes.txt b/Documentation/urls-remotes.txt
index bd184cd653..86d0008f94 100644
--- a/Documentation/urls-remotes.txt
+++ b/Documentation/urls-remotes.txt
@@ -26,14 +26,14 @@ config file would appear like this:
------------
[remote "<name>"]
- url = <url>
+ url = <URL>
pushurl = <pushurl>
push = <refspec>
fetch = <refspec>
------------
The `<pushurl>` is used for pushes only. It is optional and defaults
-to `<url>`.
+to `<URL>`.
Named file in `$GIT_DIR/remotes`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -67,10 +67,10 @@ This file should have the following format:
------------
- <url>#<head>
+ <URL>#<head>
------------
-`<url>` is required; `#<head>` is optional.
+`<URL>` is required; `#<head>` is optional.
Depending on the operation, git will use one of the following
refspecs, if you don't provide one on the command line.
diff --git a/Makefile b/Makefile
index 12be39ac49..ed75ed422b 100644
--- a/Makefile
+++ b/Makefile
@@ -305,9 +305,6 @@ all::
#
# Define NO_TCLTK if you do not want Tcl/Tk GUI.
#
-# Define SANE_TEXT_GREP to "-a" if you use recent versions of GNU grep
-# and egrep that are pickier when their input contains non-ASCII data.
-#
# The TCL_PATH variable governs the location of the Tcl interpreter
# used to optimize git-gui for your system. Only used if NO_TCLTK
# is not set. Defaults to the bare 'tclsh'.
@@ -1215,7 +1212,7 @@ ARFLAGS = rcs
PTHREAD_CFLAGS =
# For the 'sparse' target
-SPARSE_FLAGS ?=
+SPARSE_FLAGS ?= -std=gnu99
SP_EXTRA_FLAGS = -Wno-universal-initializer
# For informing GIT-BUILD-OPTIONS of the SANITIZE=leak target
@@ -2252,33 +2249,30 @@ command-list.h: $(wildcard Documentation/git*.txt)
hook-list.h: generate-hooklist.sh Documentation/githooks.txt
$(QUIET_GEN)$(SHELL_PATH) ./generate-hooklist.sh >$@
-SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
- $(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\
- $(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP):$(PAGER_ENV):\
+SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):\
+ $(localedir_SQ):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\
+ $(gitwebdir_SQ):$(PERL_PATH_SQ):$(PAGER_ENV):\
$(perllibdir_SQ)
+GIT-SCRIPT-DEFINES: FORCE
+ @FLAGS='$(SCRIPT_DEFINES)'; \
+ if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \
+ echo >&2 " * new script parameters"; \
+ echo "$$FLAGS" >$@; \
+ fi
+
define cmd_munge_script
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
-e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
-e 's|@@DIFF@@|$(DIFF_SQ)|' \
-e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
- -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
-e 's/@@USE_GETTEXT_SCHEME@@/$(USE_GETTEXT_SCHEME)/g' \
-e $(BROKEN_PATH_FIX) \
-e 's|@@GITWEBDIR@@|$(gitwebdir_SQ)|g' \
-e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
- -e 's|@@SANE_TEXT_GREP@@|$(SANE_TEXT_GREP)|g' \
-e 's|@@PAGER_ENV@@|$(PAGER_ENV_SQ)|g' \
$@.sh >$@+
endef
-GIT-SCRIPT-DEFINES: FORCE
- @FLAGS='$(SCRIPT_DEFINES)'; \
- if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \
- echo >&2 " * new script parameters"; \
- echo "$$FLAGS" >$@; \
- fi
-
-
$(SCRIPT_SH_GEN) : % : %.sh GIT-SCRIPT-DEFINES
$(QUIET_GEN)$(cmd_munge_script) && \
chmod +x $@+ && \
diff --git a/builtin/branch.c b/builtin/branch.c
index 7a1d1eeb07..81b5c111cb 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -77,12 +77,11 @@ define_list_config_array(color_branch_slots);
static int git_branch_config(const char *var, const char *value, void *cb)
{
const char *slot_name;
- struct ref_sorting **sorting_tail = (struct ref_sorting **)cb;
if (!strcmp(var, "branch.sort")) {
if (!value)
return config_error_nonbool(var);
- parse_ref_sorting(sorting_tail, value);
+ string_list_append(cb, value);
return 0;
}
@@ -625,7 +624,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
enum branch_track track;
struct ref_filter filter;
int icase = 0;
- static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
+ static struct ref_sorting *sorting;
+ struct string_list sorting_options = STRING_LIST_INIT_DUP;
struct ref_format format = REF_FORMAT_INIT;
struct option options[] = {
@@ -666,7 +666,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT_MERGED(&filter, N_("print only branches that are merged")),
OPT_NO_MERGED(&filter, N_("print only branches that are not merged")),
OPT_COLUMN(0, "column", &colopts, N_("list branches in columns")),
- OPT_REF_SORT(sorting_tail),
+ OPT_REF_SORT(&sorting_options),
OPT_CALLBACK(0, "points-at", &filter.points_at, N_("object"),
N_("print only branches of the object"), parse_opt_object_name),
OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
@@ -683,7 +683,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(builtin_branch_usage, options);
- git_config(git_branch_config, sorting_tail);
+ git_config(git_branch_config, &sorting_options);
track = git_branch_track;
@@ -749,8 +749,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
* local branches 'refs/heads/...' and finally remote-tracking
* branches 'refs/remotes/...'.
*/
- if (!sorting)
- sorting = ref_default_sorting();
+ sorting = ref_sorting_options(&sorting_options);
ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);
ref_sorting_set_sort_flags_all(
sorting, REF_SORTING_DETACHED_HEAD_FIRST, 1);
diff --git a/builtin/checkout.c b/builtin/checkout.c
index cbf73b8c9f..3fe87a632e 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -91,8 +91,8 @@ struct checkout_opts {
};
struct branch_info {
- const char *name; /* The short name used */
- const char *path; /* The full name of a real branch */
+ char *name; /* The short name used */
+ char *path; /* The full name of a real branch */
struct commit *commit; /* The named commit */
char *refname; /* The full name of the ref being checked out. */
struct object_id oid; /* The object ID of the commit being checked out. */
@@ -103,6 +103,14 @@ struct branch_info {
char *checkout;
};
+static void branch_info_release(struct branch_info *info)
+{
+ free(info->name);
+ free(info->path);
+ free(info->refname);
+ free(info->checkout);
+}
+
static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit,
int changed)
{
@@ -688,9 +696,12 @@ static void setup_branch_path(struct branch_info *branch)
repo_get_oid_committish(the_repository, branch->name, &branch->oid);
strbuf_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);
- if (strcmp(buf.buf, branch->name))
+ if (strcmp(buf.buf, branch->name)) {
+ free(branch->name);
branch->name = xstrdup(buf.buf);
+ }
strbuf_splice(&buf, 0, 0, "refs/heads/", 11);
+ free(branch->path);
branch->path = strbuf_detach(&buf, NULL);
}
@@ -874,7 +885,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
int ret;
struct strbuf err = STRBUF_INIT;
- ret = safe_create_reflog(refname, 1, &err);
+ ret = safe_create_reflog(refname, &err);
if (ret) {
fprintf(stderr, _("Can not do reflog for '%s': %s\n"),
opts->new_orphan_branch, err.buf);
@@ -894,7 +905,9 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
opts->new_branch_log,
opts->quiet,
opts->track);
- new_branch_info->name = opts->new_branch;
+ free(new_branch_info->name);
+ free(new_branch_info->refname);
+ new_branch_info->name = xstrdup(opts->new_branch);
setup_branch_path(new_branch_info);
}
@@ -1062,8 +1075,7 @@ static int switch_branches(const struct checkout_opts *opts,
struct branch_info *new_branch_info)
{
int ret = 0;
- struct branch_info old_branch_info;
- void *path_to_free;
+ struct branch_info old_branch_info = { 0 };
struct object_id rev;
int flag, writeout_error = 0;
int do_merge = 1;
@@ -1071,25 +1083,32 @@ static int switch_branches(const struct checkout_opts *opts,
trace2_cmd_mode("branch");
memset(&old_branch_info, 0, sizeof(old_branch_info));
- old_branch_info.path = path_to_free = resolve_refdup("HEAD", 0, &rev, &flag);
+ old_branch_info.path = resolve_refdup("HEAD", 0, &rev, &flag);
if (old_branch_info.path)
old_branch_info.commit = lookup_commit_reference_gently(the_repository, &rev, 1);
if (!(flag & REF_ISSYMREF))
- old_branch_info.path = NULL;
+ FREE_AND_NULL(old_branch_info.path);
- if (old_branch_info.path)
- skip_prefix(old_branch_info.path, "refs/heads/", &old_branch_info.name);
+ if (old_branch_info.path) {
+ const char *const prefix = "refs/heads/";
+ const char *p;
+ if (skip_prefix(old_branch_info.path, prefix, &p))
+ old_branch_info.name = xstrdup(p);
+ else
+ BUG("should be able to skip past '%s' in '%s'!",
+ prefix, old_branch_info.path);
+ }
if (opts->new_orphan_branch && opts->orphan_from_empty_tree) {
if (new_branch_info->name)
BUG("'switch --orphan' should never accept a commit as starting point");
new_branch_info->commit = NULL;
- new_branch_info->name = "(empty)";
+ new_branch_info->name = xstrdup("(empty)");
do_merge = 1;
}
if (!new_branch_info->name) {
- new_branch_info->name = "HEAD";
+ new_branch_info->name = xstrdup("HEAD");
new_branch_info->commit = old_branch_info.commit;
if (!new_branch_info->commit)
die(_("You are on a branch yet to be born"));
@@ -1102,7 +1121,7 @@ static int switch_branches(const struct checkout_opts *opts,
if (do_merge) {
ret = merge_working_tree(opts, &old_branch_info, new_branch_info, &writeout_error);
if (ret) {
- free(path_to_free);
+ branch_info_release(&old_branch_info);
return ret;
}
}
@@ -1113,7 +1132,8 @@ static int switch_branches(const struct checkout_opts *opts,
update_refs_for_switch(opts, &old_branch_info, new_branch_info);
ret = post_checkout_hook(old_branch_info.commit, new_branch_info->commit, 1);
- free(path_to_free);
+ branch_info_release(&old_branch_info);
+
return ret || writeout_error;
}
@@ -1145,16 +1165,15 @@ static void setup_new_branch_info_and_source_tree(
struct tree **source_tree = &opts->source_tree;
struct object_id branch_rev;
- new_branch_info->name = arg;
+ new_branch_info->name = xstrdup(arg);
setup_branch_path(new_branch_info);
if (!check_refname_format(new_branch_info->path, 0) &&
!read_ref(new_branch_info->path, &branch_rev))
oidcpy(rev, &branch_rev);
- else {
- free((char *)new_branch_info->path);
- new_branch_info->path = NULL; /* not an existing branch */
- }
+ else
+ /* not an existing branch */
+ FREE_AND_NULL(new_branch_info->path);
new_branch_info->commit = lookup_commit_reference_gently(the_repository, rev, 1);
if (!new_branch_info->commit) {
@@ -1574,12 +1593,11 @@ static char cb_option = 'b';
static int checkout_main(int argc, const char **argv, const char *prefix,
struct checkout_opts *opts, struct option *options,
- const char * const usagestr[])
+ const char * const usagestr[],
+ struct branch_info *new_branch_info)
{
- struct branch_info new_branch_info;
int parseopt_flags = 0;
- memset(&new_branch_info, 0, sizeof(new_branch_info));
opts->overwrite_ignore = 1;
opts->prefix = prefix;
opts->show_progress = -1;
@@ -1688,7 +1706,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
opts->track == BRANCH_TRACK_UNSPECIFIED &&
!opts->new_branch;
int n = parse_branchname_arg(argc, argv, dwim_ok,
- &new_branch_info, opts, &rev);
+ new_branch_info, opts, &rev);
argv += n;
argc -= n;
} else if (!opts->accept_ref && opts->from_treeish) {
@@ -1697,7 +1715,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
if (get_oid_mb(opts->from_treeish, &rev))
die(_("could not resolve %s"), opts->from_treeish);
- setup_new_branch_info_and_source_tree(&new_branch_info,
+ setup_new_branch_info_and_source_tree(new_branch_info,
opts, &rev,
opts->from_treeish);
@@ -1717,7 +1735,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
* Try to give more helpful suggestion.
* new_branch && argc > 1 will be caught later.
*/
- if (opts->new_branch && argc == 1 && !new_branch_info.commit)
+ if (opts->new_branch && argc == 1 && !new_branch_info->commit)
die(_("'%s' is not a commit and a branch '%s' cannot be created from it"),
argv[0], opts->new_branch);
@@ -1766,11 +1784,10 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
strbuf_release(&buf);
}
- UNLEAK(opts);
if (opts->patch_mode || opts->pathspec.nr)
- return checkout_paths(opts, &new_branch_info);
+ return checkout_paths(opts, new_branch_info);
else
- return checkout_branch(opts, &new_branch_info);
+ return checkout_branch(opts, new_branch_info);
}
int cmd_checkout(int argc, const char **argv, const char *prefix)
@@ -1789,6 +1806,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
OPT_END()
};
int ret;
+ struct branch_info new_branch_info = { 0 };
memset(&opts, 0, sizeof(opts));
opts.dwim_new_local_branch = 1;
@@ -1819,7 +1837,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
options = add_checkout_path_options(&opts, options);
ret = checkout_main(argc, argv, prefix, &opts,
- options, checkout_usage);
+ options, checkout_usage, &new_branch_info);
+ branch_info_release(&new_branch_info);
+ clear_pathspec(&opts.pathspec);
FREE_AND_NULL(options);
return ret;
}
@@ -1840,6 +1860,7 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
OPT_END()
};
int ret;
+ struct branch_info new_branch_info = { 0 };
memset(&opts, 0, sizeof(opts));
opts.dwim_new_local_branch = 1;
@@ -1859,7 +1880,8 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
cb_option = 'c';
ret = checkout_main(argc, argv, prefix, &opts,
- options, switch_branch_usage);
+ options, switch_branch_usage, &new_branch_info);
+ branch_info_release(&new_branch_info);
FREE_AND_NULL(options);
return ret;
}
@@ -1881,6 +1903,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
OPT_END()
};
int ret;
+ struct branch_info new_branch_info = { 0 };
memset(&opts, 0, sizeof(opts));
opts.accept_ref = 0;
@@ -1896,7 +1919,8 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
options = add_checkout_path_options(&opts, options);
ret = checkout_main(argc, argv, prefix, &opts,
- options, restore_usage);
+ options, restore_usage, &new_branch_info);
+ branch_info_release(&new_branch_info);
FREE_AND_NULL(options);
return ret;
}
diff --git a/builtin/credential.c b/builtin/credential.c
index d75dcdc64a..d7b304fa08 100644
--- a/builtin/credential.c
+++ b/builtin/credential.c
@@ -4,7 +4,7 @@
#include "config.h"
static const char usage_msg[] =
- "git credential [fill|approve|reject]";
+ "git credential (fill|approve|reject)";
int cmd_credential(int argc, const char **argv, const char *prefix)
{
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 16a2c7d57c..6f62f40d12 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -17,7 +17,8 @@ static char const * const for_each_ref_usage[] = {
int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
{
int i;
- struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
+ struct ref_sorting *sorting;
+ struct string_list sorting_options = STRING_LIST_INIT_DUP;
int maxcount = 0, icase = 0;
struct ref_array array;
struct ref_filter filter;
@@ -39,7 +40,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")),
OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")),
OPT__COLOR(&format.use_color, N_("respect format colors")),
- OPT_REF_SORT(sorting_tail),
+ OPT_REF_SORT(&sorting_options),
OPT_CALLBACK(0, "points-at", &filter.points_at,
N_("object"), N_("print only refs which points at the given object"),
parse_opt_object_name),
@@ -70,8 +71,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
if (verify_ref_format(&format))
usage_with_options(for_each_ref_usage, opts);
- if (!sorting)
- sorting = ref_default_sorting();
+ sorting = ref_sorting_options(&sorting_options);
ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);
filter.ignore_case = icase;
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 318949c3d7..44448fa61d 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -54,7 +54,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
struct transport *transport;
const struct ref *ref;
struct ref_array ref_array;
- static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
+ struct string_list sorting_options = STRING_LIST_INIT_DUP;
struct option options[] = {
OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -68,7 +68,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
OPT_BOOL(0, "get-url", &get_url,
N_("take url.<base>.insteadOf into account")),
- OPT_REF_SORT(sorting_tail),
+ OPT_REF_SORT(&sorting_options),
OPT_SET_INT_F(0, "exit-code", &status,
N_("exit with exit code 2 if no matching refs are found"),
2, PARSE_OPT_NOCOMPLETE),
@@ -86,8 +86,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
packet_trace_identity("ls-remote");
- UNLEAK(sorting);
-
if (argc > 1) {
int i;
CALLOC_ARRAY(pattern, argc);
@@ -139,8 +137,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
item->symref = xstrdup_or_null(ref->symref);
}
- if (sorting)
+ if (sorting_options.nr) {
+ struct ref_sorting *sorting;
+
+ sorting = ref_sorting_options(&sorting_options);
ref_array_sort(sorting, &ref_array);
+ ref_sorting_release(sorting);
+ }
for (i = 0; i < ref_array.nr; i++) {
const struct ref_array_item *ref = ref_array.items[i];
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 075d15d706..4480ba3982 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -167,6 +167,8 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv)
usage_with_options(builtin_multi_pack_index_verify_usage,
options);
+ FREE_AND_NULL(options);
+
return verify_midx_file(the_repository, opts.object_dir, opts.flags);
}
@@ -191,6 +193,8 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv)
usage_with_options(builtin_multi_pack_index_expire_usage,
options);
+ FREE_AND_NULL(options);
+
return expire_midx_packs(the_repository, opts.object_dir, opts.flags);
}
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 1a3dd445f8..857be7826f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -4148,11 +4148,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
read_packs_list_from_stdin();
if (rev_list_unpacked)
add_unreachable_loose_objects();
- } else if (!use_internal_rev_list)
+ } else if (!use_internal_rev_list) {
read_object_list_from_stdin();
- else {
+ } else {
get_object_list(rp.nr, rp.v);
- strvec_clear(&rp);
}
cleanup_preferred_base();
if (include_tag && nr_result)
@@ -4162,7 +4161,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
the_repository);
if (non_empty && !nr_result)
- return 0;
+ goto cleanup;
if (nr_result) {
trace2_region_enter("pack-objects", "prepare-pack",
the_repository);
@@ -4183,5 +4182,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
" pack-reused %"PRIu32),
written, written_delta, reused, reused_delta,
reuse_packfile_objects);
+
+cleanup:
+ strvec_clear(&rp);
+
return 0;
}
diff --git a/builtin/pull.c b/builtin/pull.c
index 1cfaf9f343..c8457619d8 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -970,7 +970,7 @@ static void show_advice_pull_non_ff(void)
"You can do so by running one of the following commands sometime before\n"
"your next pull:\n"
"\n"
- " git config pull.rebase false # merge (the default strategy)\n"
+ " git config pull.rebase false # merge\n"
" git config pull.rebase true # rebase\n"
" git config pull.ff only # fast-forward only\n"
"\n"
diff --git a/builtin/repack.c b/builtin/repack.c
index 0b2d1e5d82..9b0be6a6ab 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -258,9 +258,11 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
for_each_packed_object(write_oid, &cmd,
FOR_EACH_OBJECT_PROMISOR_ONLY);
- if (cmd.in == -1)
+ if (cmd.in == -1) {
/* No packed objects; cmd was never started */
+ child_process_clear(&cmd);
return;
+ }
close(cmd.in);
@@ -842,7 +844,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
fname_old = mkpathdup("%s-%s%s",
packtmp, item->string, exts[ext].name);
- if (((uintptr_t)item->util) & (1 << ext)) {
+ if (((uintptr_t)item->util) & ((uintptr_t)1 << ext)) {
struct stat statbuffer;
if (!stat(fname_old, &statbuffer)) {
statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
diff --git a/builtin/reset.c b/builtin/reset.c
index 7393595349..b1ff699b43 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -25,6 +25,7 @@
#include "cache-tree.h"
#include "submodule.h"
#include "submodule-config.h"
+#include "dir.h"
#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
@@ -136,21 +137,36 @@ static void update_index_from_diff(struct diff_queue_struct *q,
int intent_to_add = *(int *)data;
for (i = 0; i < q->nr; i++) {
+ int pos;
struct diff_filespec *one = q->queue[i]->one;
- int is_missing = !(one->mode && !is_null_oid(&one->oid));
+ int is_in_reset_tree = one->mode && !is_null_oid(&one->oid);
struct cache_entry *ce;
- if (is_missing && !intent_to_add) {
+ if (!is_in_reset_tree && !intent_to_add) {
remove_file_from_cache(one->path);
continue;
}
ce = make_cache_entry(&the_index, one->mode, &one->oid, one->path,
0, 0);
+
+ /*
+ * If the file 1) corresponds to an existing index entry with
+ * skip-worktree set, or 2) does not exist in the index but is
+ * outside the sparse checkout definition, add a skip-worktree bit
+ * to the new index entry. Note that a sparse index will be expanded
+ * if this entry is outside the sparse cone - this is necessary
+ * to properly construct the reset sparse directory.
+ */
+ pos = cache_name_pos(one->path, strlen(one->path));
+ if ((pos >= 0 && ce_skip_worktree(active_cache[pos])) ||
+ (pos < 0 && !path_in_sparse_checkout(one->path, &the_index)))
+ ce->ce_flags |= CE_SKIP_WORKTREE;
+
if (!ce)
die(_("make_cache_entry failed for path '%s'"),
one->path);
- if (is_missing) {
+ if (!is_in_reset_tree) {
ce->ce_flags |= CE_INTENT_TO_ADD;
set_object_name_for_intent_to_add_entry(ce);
}
@@ -158,6 +174,82 @@ static void update_index_from_diff(struct diff_queue_struct *q,
}
}
+static int pathspec_needs_expanded_index(const struct pathspec *pathspec)
+{
+ unsigned int i, pos;
+ int res = 0;
+ char *skip_worktree_seen = NULL;
+
+ /*
+ * When using a magic pathspec, assume for the sake of simplicity that
+ * the index needs to be expanded to match all matchable files.
+ */
+ if (pathspec->magic)
+ return 1;
+
+ for (i = 0; i < pathspec->nr; i++) {
+ struct pathspec_item item = pathspec->items[i];
+
+ /*
+ * If the pathspec item has a wildcard, the index should be expanded
+ * if the pathspec has the possibility of matching a subset of entries inside
+ * of a sparse directory (but not the entire directory).
+ *
+ * If the pathspec item is a literal path, the index only needs to be expanded
+ * if a) the pathspec isn't in the sparse checkout cone (to make sure we don't
+ * expand for in-cone files) and b) it doesn't match any sparse directories
+ * (since we can reset whole sparse directories without expanding them).
+ */
+ if (item.nowildcard_len < item.len) {
+ /*
+ * Special case: if the pattern is a path inside the cone
+ * followed by only wildcards, the pattern cannot match
+ * partial sparse directories, so we don't expand the index.
+ */
+ if (path_in_cone_mode_sparse_checkout(item.original, &the_index) &&
+ strspn(item.original + item.nowildcard_len, "*") == item.len - item.nowildcard_len)
+ continue;
+
+ for (pos = 0; pos < active_nr; pos++) {
+ struct cache_entry *ce = active_cache[pos];
+
+ if (!S_ISSPARSEDIR(ce->ce_mode))
+ continue;
+
+ /*
+ * If the pre-wildcard length is longer than the sparse
+ * directory name and the sparse directory is the first
+ * component of the pathspec, need to expand the index.
+ */
+ if (item.nowildcard_len > ce_namelen(ce) &&
+ !strncmp(item.original, ce->name, ce_namelen(ce))) {
+ res = 1;
+ break;
+ }
+
+ /*
+ * If the pre-wildcard length is shorter than the sparse
+ * directory and the pathspec does not match the whole
+ * directory, need to expand the index.
+ */
+ if (!strncmp(item.original, ce->name, item.nowildcard_len) &&
+ wildmatch(item.original, ce->name, 0)) {
+ res = 1;
+ break;
+ }
+ }
+ } else if (!path_in_cone_mode_sparse_checkout(item.original, &the_index) &&
+ !matches_skip_worktree(pathspec, i, &skip_worktree_seen))
+ res = 1;
+
+ if (res > 0)
+ break;
+ }
+
+ free(skip_worktree_seen);
+ return res;
+}
+
static int read_from_tree(const struct pathspec *pathspec,
struct object_id *tree_oid,
int intent_to_add)
@@ -170,7 +262,13 @@ static int read_from_tree(const struct pathspec *pathspec,
opt.format_callback = update_index_from_diff;
opt.format_callback_data = &intent_to_add;
opt.flags.override_submodule_config = 1;
+ opt.flags.recursive = 1;
opt.repo = the_repository;
+ opt.change = diff_change;
+ opt.add_remove = diff_addremove;
+
+ if (pathspec->nr && the_index.sparse_index && pathspec_needs_expanded_index(pathspec))
+ ensure_full_index(&the_index);
if (do_diff_cache(tree_oid, &opt))
return 1;
@@ -249,9 +347,6 @@ static void parse_args(struct pathspec *pathspec,
}
*rev_ret = rev;
- if (read_cache() < 0)
- die(_("index file corrupt"));
-
parse_pathspec(pathspec, 0,
PATHSPEC_PREFER_FULL |
(patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0),
@@ -397,6 +492,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
if (intent_to_add && reset_type != MIXED)
die(_("-N can only be used with --mixed"));
+ prepare_repo_settings(the_repository);
+ the_repository->settings.command_requires_full_index = 0;
+
+ if (read_cache() < 0)
+ die(_("index file corrupt"));
+
/* Soft reset does not touch the index file nor the working tree
* at all, but requires them in a good order. Other resets reset
* the index file to the tree object we are switching to. */
diff --git a/builtin/stash.c b/builtin/stash.c
index a0ccc8654d..18c812bbe0 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -27,11 +27,11 @@ static const char * const git_stash_usage[] = {
N_("git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]"),
N_("git stash branch <branchname> [<stash>]"),
"git stash clear",
- N_("git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
+ N_("git stash [push [-p|--patch] [-S|--staged] [-k|--[no-]keep-index] [-q|--quiet]\n"
" [-u|--include-untracked] [-a|--all] [-m|--message <message>]\n"
" [--pathspec-from-file=<file> [--pathspec-file-nul]]\n"
" [--] [<pathspec>...]]"),
- N_("git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
+ N_("git stash save [-p|--patch] [-S|--staged] [-k|--[no-]keep-index] [-q|--quiet]\n"
" [-u|--include-untracked] [-a|--all] [<message>]"),
NULL
};
@@ -1132,6 +1132,38 @@ done:
return ret;
}
+static int stash_staged(struct stash_info *info, struct strbuf *out_patch,
+ int quiet)
+{
+ int ret = 0;
+ struct child_process cp_diff_tree = CHILD_PROCESS_INIT;
+ struct index_state istate = { NULL };
+
+ if (write_index_as_tree(&info->w_tree, &istate, the_repository->index_file,
+ 0, NULL)) {
+ ret = -1;
+ goto done;
+ }
+
+ cp_diff_tree.git_cmd = 1;
+ strvec_pushl(&cp_diff_tree.args, "diff-tree", "-p", "-U1", "HEAD",
+ oid_to_hex(&info->w_tree), "--", NULL);
+ if (pipe_command(&cp_diff_tree, NULL, 0, out_patch, 0, NULL, 0)) {
+ ret = -1;
+ goto done;
+ }
+
+ if (!out_patch->len) {
+ if (!quiet)
+ fprintf_ln(stderr, _("No staged changes"));
+ ret = 1;
+ }
+
+done:
+ discard_index(&istate);
+ return ret;
+}
+
static int stash_patch(struct stash_info *info, const struct pathspec *ps,
struct strbuf *out_patch, int quiet)
{
@@ -1258,7 +1290,7 @@ done:
}
static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_buf,
- int include_untracked, int patch_mode,
+ int include_untracked, int patch_mode, int only_staged,
struct stash_info *info, struct strbuf *patch,
int quiet)
{
@@ -1337,6 +1369,16 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
} else if (ret > 0) {
goto done;
}
+ } else if (only_staged) {
+ ret = stash_staged(info, patch, quiet);
+ if (ret < 0) {
+ if (!quiet)
+ fprintf_ln(stderr, _("Cannot save the current "
+ "staged state"));
+ goto done;
+ } else if (ret > 0) {
+ goto done;
+ }
} else {
if (stash_working_tree(info, ps)) {
if (!quiet)
@@ -1395,7 +1437,7 @@ static int create_stash(int argc, const char **argv, const char *prefix)
if (!check_changes_tracked_files(&ps))
return 0;
- ret = do_create_stash(&ps, &stash_msg_buf, 0, 0, &info,
+ ret = do_create_stash(&ps, &stash_msg_buf, 0, 0, 0, &info,
NULL, 0);
if (!ret)
printf_ln("%s", oid_to_hex(&info.w_commit));
@@ -1405,7 +1447,7 @@ static int create_stash(int argc, const char **argv, const char *prefix)
}
static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int quiet,
- int keep_index, int patch_mode, int include_untracked)
+ int keep_index, int patch_mode, int include_untracked, int only_staged)
{
int ret = 0;
struct stash_info info;
@@ -1423,6 +1465,17 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
goto done;
}
+ /* --patch overrides --staged */
+ if (patch_mode)
+ only_staged = 0;
+
+ if (only_staged && include_untracked) {
+ fprintf_ln(stderr, _("Can't use --staged and --include-untracked"
+ " or --all at the same time"));
+ ret = -1;
+ goto done;
+ }
+
read_cache_preload(NULL);
if (!include_untracked && ps->nr) {
int i;
@@ -1463,7 +1516,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
if (stash_msg)
strbuf_addstr(&stash_msg_buf, stash_msg);
- if (do_create_stash(ps, &stash_msg_buf, include_untracked, patch_mode,
+ if (do_create_stash(ps, &stash_msg_buf, include_untracked, patch_mode, only_staged,
&info, &patch, quiet)) {
ret = -1;
goto done;
@@ -1480,7 +1533,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
printf_ln(_("Saved working directory and index state %s"),
stash_msg_buf.buf);
- if (!patch_mode) {
+ if (!(patch_mode || only_staged)) {
if (include_untracked && !ps->nr) {
struct child_process cp = CHILD_PROCESS_INIT;
@@ -1598,6 +1651,7 @@ static int push_stash(int argc, const char **argv, const char *prefix,
{
int force_assume = 0;
int keep_index = -1;
+ int only_staged = 0;
int patch_mode = 0;
int include_untracked = 0;
int quiet = 0;
@@ -1608,6 +1662,8 @@ static int push_stash(int argc, const char **argv, const char *prefix,
struct option options[] = {
OPT_BOOL('k', "keep-index", &keep_index,
N_("keep index")),
+ OPT_BOOL('S', "staged", &only_staged,
+ N_("stash staged changes only")),
OPT_BOOL('p', "patch", &patch_mode,
N_("stash in patch mode")),
OPT__QUIET(&quiet, N_("quiet mode")),
@@ -1646,6 +1702,9 @@ static int push_stash(int argc, const char **argv, const char *prefix,
if (patch_mode)
die(_("--pathspec-from-file is incompatible with --patch"));
+ if (only_staged)
+ die(_("--pathspec-from-file is incompatible with --staged"));
+
if (ps.nr)
die(_("--pathspec-from-file is incompatible with pathspec arguments"));
@@ -1657,12 +1716,13 @@ static int push_stash(int argc, const char **argv, const char *prefix,
}
return do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode,
- include_untracked);
+ include_untracked, only_staged);
}
static int save_stash(int argc, const char **argv, const char *prefix)
{
int keep_index = -1;
+ int only_staged = 0;
int patch_mode = 0;
int include_untracked = 0;
int quiet = 0;
@@ -1673,6 +1733,8 @@ static int save_stash(int argc, const char **argv, const char *prefix)
struct option options[] = {
OPT_BOOL('k', "keep-index", &keep_index,
N_("keep index")),
+ OPT_BOOL('S', "staged", &only_staged,
+ N_("stash staged changes only")),
OPT_BOOL('p', "patch", &patch_mode,
N_("stash in patch mode")),
OPT__QUIET(&quiet, N_("quiet mode")),
@@ -1694,7 +1756,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)
memset(&ps, 0, sizeof(ps));
ret = do_push_stash(&ps, stash_msg, quiet, keep_index,
- patch_mode, include_untracked);
+ patch_mode, include_untracked, only_staged);
strbuf_release(&stash_msg_buf);
return ret;
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index e630f0c730..9b25a508e6 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1503,16 +1503,17 @@ static void deinit_submodule(const char *path, const char *prefix,
struct strbuf sb_rm = STRBUF_INIT;
const char *format;
- /*
- * protect submodules containing a .git directory
- * NEEDSWORK: instead of dying, automatically call
- * absorbgitdirs and (possibly) warn.
- */
- if (is_directory(sub_git_dir))
- die(_("Submodule work tree '%s' contains a .git "
- "directory (use 'rm -rf' if you really want "
- "to remove it including all of its history)"),
- displaypath);
+ if (is_directory(sub_git_dir)) {
+ if (!(flags & OPT_QUIET))
+ warning(_("Submodule work tree '%s' contains a .git "
+ "directory. This will be replaced with a "
+ ".git file by using absorbgitdirs."),
+ displaypath);
+
+ absorb_git_dir_into_superproject(path,
+ ABSORB_GITDIR_RECURSE_SUBMODULES);
+
+ }
if (!(flags & OPT_FORCE)) {
struct child_process cp_rm = CHILD_PROCESS_INIT;
diff --git a/builtin/tag.c b/builtin/tag.c
index 6fe646710d..41863c5ab7 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -178,7 +178,6 @@ static const char tag_template_nocleanup[] =
static int git_tag_config(const char *var, const char *value, void *cb)
{
int status;
- struct ref_sorting **sorting_tail = (struct ref_sorting **)cb;
if (!strcmp(var, "tag.gpgsign")) {
config_sign_tag = git_config_bool(var, value);
@@ -188,7 +187,7 @@ static int git_tag_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "tag.sort")) {
if (!value)
return config_error_nonbool(var);
- parse_ref_sorting(sorting_tail, value);
+ string_list_append(cb, value);
return 0;
}
@@ -436,7 +435,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
struct ref_transaction *transaction;
struct strbuf err = STRBUF_INIT;
struct ref_filter filter;
- static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
+ struct ref_sorting *sorting;
+ struct string_list sorting_options = STRING_LIST_INIT_DUP;
struct ref_format format = REF_FORMAT_INIT;
int icase = 0;
int edit_flag = 0;
@@ -470,7 +470,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
OPT_WITHOUT(&filter.no_commit, N_("print only tags that don't contain the commit")),
OPT_MERGED(&filter, N_("print only tags that are merged")),
OPT_NO_MERGED(&filter, N_("print only tags that are not merged")),
- OPT_REF_SORT(sorting_tail),
+ OPT_REF_SORT(&sorting_options),
{
OPTION_CALLBACK, 0, "points-at", &filter.points_at, N_("object"),
N_("print only tags of the object"), PARSE_OPT_LASTARG_DEFAULT,
@@ -486,7 +486,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
setup_ref_filter_porcelain_msg();
- git_config(git_tag_config, sorting_tail);
+ git_config(git_tag_config, &sorting_options);
memset(&opt, 0, sizeof(opt));
memset(&filter, 0, sizeof(filter));
@@ -525,8 +525,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die(_("--column and -n are incompatible"));
colopts = 0;
}
- if (!sorting)
- sorting = ref_default_sorting();
+ sorting = ref_sorting_options(&sorting_options);
ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);
filter.ignore_case = icase;
if (cmdmode == 'l') {
diff --git a/builtin/var.c b/builtin/var.c
index 6c6f46b4ae..491db27429 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -5,6 +5,7 @@
*/
#include "builtin.h"
#include "config.h"
+#include "refs.h"
static const char var_usage[] = "git var (-l | <variable>)";
@@ -27,6 +28,11 @@ static const char *pager(int flag)
return pgm;
}
+static const char *default_branch(int flag)
+{
+ return git_default_branch_name(1);
+}
+
struct git_var {
const char *name;
const char *(*read)(int);
@@ -36,6 +42,7 @@ static struct git_var git_vars[] = {
{ "GIT_AUTHOR_IDENT", git_author_info },
{ "GIT_EDITOR", editor },
{ "GIT_PAGER", pager },
+ { "GIT_DEFAULT_BRANCH", default_branch },
{ "", NULL },
};
diff --git a/cache-tree.c b/cache-tree.c
index 79d168192d..65ca993361 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -741,15 +741,26 @@ out:
return ret;
}
+static void prime_cache_tree_sparse_dir(struct cache_tree *it,
+ struct tree *tree)
+{
+
+ oidcpy(&it->oid, &tree->object.oid);
+ it->entry_count = 1;
+}
+
static void prime_cache_tree_rec(struct repository *r,
struct cache_tree *it,
- struct tree *tree)
+ struct tree *tree,
+ struct strbuf *tree_path)
{
struct tree_desc desc;
struct name_entry entry;
int cnt;
+ int base_path_len = tree_path->len;
oidcpy(&it->oid, &tree->object.oid);
+
init_tree_desc(&desc, tree->buffer, tree->size);
cnt = 0;
while (tree_entry(&desc, &entry)) {
@@ -758,14 +769,40 @@ static void prime_cache_tree_rec(struct repository *r,
else {
struct cache_tree_sub *sub;
struct tree *subtree = lookup_tree(r, &entry.oid);
+
if (!subtree->object.parsed)
parse_tree(subtree);
sub = cache_tree_sub(it, entry.path);
sub->cache_tree = cache_tree();
- prime_cache_tree_rec(r, sub->cache_tree, subtree);
+
+ /*
+ * Recursively-constructed subtree path is only needed when working
+ * in a sparse index (where it's used to determine whether the
+ * subtree is a sparse directory in the index).
+ */
+ if (r->index->sparse_index) {
+ strbuf_setlen(tree_path, base_path_len);
+ strbuf_grow(tree_path, base_path_len + entry.pathlen + 1);
+ strbuf_add(tree_path, entry.path, entry.pathlen);
+ strbuf_addch(tree_path, '/');
+ }
+
+ /*
+ * If a sparse index is in use, the directory being processed may be
+ * sparse. To confirm that, we can check whether an entry with that
+ * exact name exists in the index. If it does, the created subtree
+ * should be sparse. Otherwise, cache tree expansion should continue
+ * as normal.
+ */
+ if (r->index->sparse_index &&
+ index_entry_exists(r->index, tree_path->buf, tree_path->len))
+ prime_cache_tree_sparse_dir(sub->cache_tree, subtree);
+ else
+ prime_cache_tree_rec(r, sub->cache_tree, subtree, tree_path);
cnt += sub->cache_tree->entry_count;
}
}
+
it->entry_count = cnt;
}
@@ -773,11 +810,14 @@ void prime_cache_tree(struct repository *r,
struct index_state *istate,
struct tree *tree)
{
+ struct strbuf tree_path = STRBUF_INIT;
+
trace2_region_enter("cache-tree", "prime_cache_tree", the_repository);
cache_tree_free(&istate->cache_tree);
istate->cache_tree = cache_tree();
- prime_cache_tree_rec(r, istate->cache_tree, tree);
+ prime_cache_tree_rec(r, istate->cache_tree, tree, &tree_path);
+ strbuf_release(&tree_path);
istate->cache_changed |= CACHE_TREE_CHANGED;
trace2_region_leave("cache-tree", "prime_cache_tree", the_repository);
}
diff --git a/cache.h b/cache.h
index eba12487b9..d5cafba17d 100644
--- a/cache.h
+++ b/cache.h
@@ -817,6 +817,16 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na
int index_name_pos(struct index_state *, const char *name, int namelen);
/*
+ * Determines whether an entry with the given name exists within the
+ * given index. The return value is 1 if an exact match is found, otherwise
+ * it is 0. Note that, unlike index_name_pos, this function does not expand
+ * the index if it is sparse. If an item exists within the full index but it
+ * is contained within a sparse directory (and not in the sparse index), 0 is
+ * returned.
+ */
+int index_entry_exists(struct index_state *, const char *name, int namelen);
+
+/*
* Some functions return the negative complement of an insert position when a
* precise match was not found but a position was found where the entry would
* need to be inserted. This helper protects that logic from any integer
@@ -1588,6 +1598,7 @@ timestamp_t approxidate_careful(const char *, int *);
timestamp_t approxidate_relative(const char *date);
void parse_date_format(const char *format, struct date_mode *mode);
int date_overflows(timestamp_t date);
+time_t tm_to_time_t(const struct tm *tm);
#define IDENT_STRICT 1
#define IDENT_NO_DATE 2
diff --git a/ci/check-directional-formatting.bash b/ci/check-directional-formatting.bash
new file mode 100755
index 0000000000..e6211b141a
--- /dev/null
+++ b/ci/check-directional-formatting.bash
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# This script verifies that the non-binary files tracked in the Git index do
+# not contain any Unicode directional formatting: such formatting could be used
+# to deceive reviewers into interpreting code differently from the compiler.
+# This is intended to run on an Ubuntu agent in a GitHub workflow.
+#
+# To allow translated messages to introduce such directional formatting in the
+# future, we exclude the `.po` files from this validation.
+#
+# Neither GNU grep nor `git grep` (not even with `-P`) handle `\u` as a way to
+# specify UTF-8.
+#
+# To work around that, we use `printf` to produce the pattern as a byte
+# sequence, and then feed that to `git grep` as a byte sequence (setting
+# `LC_CTYPE` to make sure that the arguments are interpreted as intended).
+#
+# Note: we need to use Bash here because its `printf` interprets `\uNNNN` as
+# UTF-8 code points, as desired. Running this script through Ubuntu's `dash`,
+# for example, would use a `printf` that does not understand that syntax.
+
+# U+202a..U+2a2e: LRE, RLE, PDF, LRO and RLO
+# U+2066..U+2069: LRI, RLI, FSI and PDI
+regex='(\u202a|\u202b|\u202c|\u202d|\u202e|\u2066|\u2067|\u2068|\u2069)'
+
+! LC_CTYPE=C git grep -El "$(LC_CTYPE=C.UTF-8 printf "$regex")" \
+ -- ':(exclude,attr:binary)' ':(exclude)*.po'
diff --git a/command-list.txt b/command-list.txt
index eb9cee8dee..675c28f0bd 100644
--- a/command-list.txt
+++ b/command-list.txt
@@ -43,7 +43,7 @@
# specified here, which can only have "guide" attribute and nothing
# else.
#
-### command list (do not change this line, also do not change alignment)
+### command list (do not change this line)
# command name category [category] [category]
git-add mainporcelain worktree
git-am mainporcelain
@@ -60,9 +60,9 @@ git-cat-file plumbinginterrogators
git-check-attr purehelpers
git-check-ignore purehelpers
git-check-mailmap purehelpers
+git-check-ref-format purehelpers
git-checkout mainporcelain
git-checkout-index plumbingmanipulators
-git-check-ref-format purehelpers
git-cherry plumbinginterrogators complete
git-cherry-pick mainporcelain
git-citool mainporcelain
@@ -111,7 +111,6 @@ git-index-pack plumbingmanipulators
git-init mainporcelain init
git-instaweb ancillaryinterrogators complete
git-interpret-trailers purehelpers
-gitk mainporcelain
git-log mainporcelain info
git-ls-files plumbinginterrogators
git-ls-remote plumbinginterrogators
@@ -124,11 +123,11 @@ git-merge-base plumbinginterrogators
git-merge-file plumbingmanipulators
git-merge-index plumbingmanipulators
git-merge-one-file purehelpers
-git-mergetool ancillarymanipulators complete
git-merge-tree ancillaryinterrogators
-git-multi-pack-index plumbingmanipulators
+git-mergetool ancillarymanipulators complete
git-mktag plumbingmanipulators
git-mktree plumbingmanipulators
+git-multi-pack-index plumbingmanipulators
git-mv mainporcelain worktree
git-name-rev plumbinginterrogators
git-notes mainporcelain
@@ -154,23 +153,23 @@ git-request-pull foreignscminterface complete
git-rerere ancillaryinterrogators
git-reset mainporcelain history
git-restore mainporcelain worktree
-git-revert mainporcelain
git-rev-list plumbinginterrogators
git-rev-parse plumbinginterrogators
+git-revert mainporcelain
git-rm mainporcelain worktree
git-send-email foreignscminterface complete
git-send-pack synchingrepositories
+git-sh-i18n purehelpers
+git-sh-setup purehelpers
git-shell synchelpers
git-shortlog mainporcelain
git-show mainporcelain info
git-show-branch ancillaryinterrogators complete
git-show-index plumbinginterrogators
git-show-ref plumbinginterrogators
-git-sh-i18n purehelpers
-git-sh-setup purehelpers
git-sparse-checkout mainporcelain
-git-stash mainporcelain
git-stage complete
+git-stash mainporcelain
git-status mainporcelain info
git-stripspace purehelpers
git-submodule mainporcelain
@@ -189,7 +188,6 @@ git-var plumbinginterrogators
git-verify-commit ancillaryinterrogators
git-verify-pack plumbinginterrogators
git-verify-tag ancillaryinterrogators
-gitweb ancillaryinterrogators
git-whatchanged ancillaryinterrogators complete
git-worktree mainporcelain
git-write-tree plumbingmanipulators
@@ -204,6 +202,7 @@ gitfaq guide
gitglossary guide
githooks guide
gitignore guide
+gitk mainporcelain
gitmailmap guide
gitmodules guide
gitnamespaces guide
@@ -211,6 +210,7 @@ gitremote-helpers guide
gitrepository-layout guide
gitrevisions guide
gitsubmodules guide
-gittutorial-2 guide
gittutorial guide
+gittutorial-2 guide
+gitweb ancillaryinterrogators
gitworkflows guide
diff --git a/compat/unsetenv.c b/compat/unsetenv.c
index bf5fd7063b..b9d34af613 100644
--- a/compat/unsetenv.c
+++ b/compat/unsetenv.c
@@ -1,6 +1,6 @@
#include "../git-compat-util.h"
-void gitunsetenv (const char *name)
+int gitunsetenv(const char *name)
{
#if !defined(__MINGW32__)
extern char **environ;
@@ -24,4 +24,6 @@ void gitunsetenv (const char *name)
++dst;
}
environ[dst] = NULL;
+
+ return 0;
}
diff --git a/config.mak.uname b/config.mak.uname
index 3236a4918a..d0701f9beb 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -58,7 +58,6 @@ ifeq ($(uname_S),Linux)
# -lrt is needed for clock_gettime on glibc <= 2.16
NEEDS_LIBRT = YesPlease
HAVE_GETDELIM = YesPlease
- SANE_TEXT_GREP=-a
FREAD_READS_DIRECTORIES = UnfortunatelyYes
BASIC_CFLAGS += -DHAVE_SYSINFO
PROCFS_EXECUTABLE_PATH = /proc/self/exe
diff --git a/configure.ac b/configure.ac
index 031e8d3fee..5ee25ec95c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -507,14 +507,6 @@ if test -n "$ASCIIDOC"; then
esac
fi
-if grep -a ascii configure.ac >/dev/null; then
- AC_MSG_RESULT([Using 'grep -a' for sane_grep])
- SANE_TEXT_GREP=-a
-else
- SANE_TEXT_GREP=
-fi
-GIT_CONF_SUBST([SANE_TEXT_GREP])
-
## Checks for libraries.
AC_MSG_NOTICE([CHECKS for libraries])
#
diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index fd1399c440..be67b4dab0 100644
--- a/contrib/buildsystems/CMakeLists.txt
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -208,7 +208,7 @@ endif()
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
- add_compile_options(/MP)
+ add_compile_options(/MP /std:c11)
endif()
#default behaviour
@@ -781,7 +781,6 @@ foreach(script ${git_shell_scripts})
string(REPLACE "@@USE_GETTEXT_SCHEME@@" "" content "${content}")
string(REPLACE "# @@BROKEN_PATH_FIX@@" "" content "${content}")
string(REPLACE "@@PERL@@" "${PERL_PATH}" content "${content}")
- string(REPLACE "@@SANE_TEXT_GREP@@" "-a" content "${content}")
string(REPLACE "@@PAGER_ENV@@" "LESS=FRX LV=-c" content "${content}")
file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})
endforeach()
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 37fd5c4c88..63b3a6b22e 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2359,16 +2359,7 @@ _git_send_email ()
return
;;
--*)
- __gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to
- --compose --confirm= --dry-run --envelope-sender
- --from --identity
- --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
- --no-suppress-from --no-thread --quiet --reply-to
- --signed-off-by-cc --smtp-pass --smtp-server
- --smtp-server-port --smtp-encryption= --smtp-user
- --subject --suppress-cc= --suppress-from --thread --to
- --validate --no-validate
- $__git_format_patch_extra_options"
+ __gitcomp_builtin send-email "$__git_format_patch_extra_options"
return
;;
esac
diff --git a/contrib/git-jump/README b/contrib/git-jump/README
index 2f618a7f97..8bcace29d2 100644
--- a/contrib/git-jump/README
+++ b/contrib/git-jump/README
@@ -65,6 +65,9 @@ git jump diff --cached
# jump to merge conflicts
git jump merge
+# documentation conflicts are hard; skip past them for now
+git jump merge :^Documentation
+
# jump to all instances of foo_bar
git jump grep foo_bar
diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
index 931b0fe3a9..92dbd4cde1 100755
--- a/contrib/git-jump/git-jump
+++ b/contrib/git-jump/git-jump
@@ -39,7 +39,7 @@ mode_diff() {
}
mode_merge() {
- git ls-files -u |
+ git ls-files -u "$@" |
perl -pe 's/^.*?\t//' |
sort -u |
while IFS= read fn; do
diff --git a/convert.c b/convert.c
index 0d6fb3410a..df7186bd81 100644
--- a/convert.c
+++ b/convert.c
@@ -613,7 +613,7 @@ static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
struct filter_params {
const char *src;
- unsigned long size;
+ size_t size;
int fd;
const char *cmd;
const char *path;
diff --git a/date.c b/date.c
index c55ea47e96..84bb4451c1 100644
--- a/date.c
+++ b/date.c
@@ -9,7 +9,7 @@
/*
* This is like mktime, but without normalization of tm_wday and tm_yday.
*/
-static time_t tm_to_time_t(const struct tm *tm)
+time_t tm_to_time_t(const struct tm *tm)
{
static const int mdays[] = {
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
diff --git a/delta.h b/delta.h
index 2df5fe13d9..8a56ec0799 100644
--- a/delta.h
+++ b/delta.h
@@ -90,15 +90,15 @@ static inline unsigned long get_delta_hdr_size(const unsigned char **datap,
const unsigned char *top)
{
const unsigned char *data = *datap;
- unsigned long cmd, size = 0;
+ size_t cmd, size = 0;
int i = 0;
do {
cmd = *data++;
- size |= (cmd & 0x7f) << i;
+ size |= st_left_shift(cmd & 0x7f, i);
i += 7;
} while (cmd & 0x80 && data < top);
*datap = data;
- return size;
+ return cast_size_t_to_ulong(size);
}
#endif
diff --git a/diffcore-delta.c b/diffcore-delta.c
index 5668ace60d..18d8f766d7 100644
--- a/diffcore-delta.c
+++ b/diffcore-delta.c
@@ -133,10 +133,10 @@ static struct spanhash_top *hash_chars(struct repository *r,
i = INITIAL_HASH_SIZE;
hash = xmalloc(st_add(sizeof(*hash),
- st_mult(sizeof(struct spanhash), 1<<i)));
+ st_mult(sizeof(struct spanhash), (size_t)1 << i)));
hash->alloc_log2 = i;
hash->free = INITIAL_FREE(i);
- memset(hash->data, 0, sizeof(struct spanhash) * (1<<i));
+ memset(hash->data, 0, sizeof(struct spanhash) * ((size_t)1 << i));
n = 0;
accum1 = accum2 = 0;
@@ -159,7 +159,7 @@ static struct spanhash_top *hash_chars(struct repository *r,
n = 0;
accum1 = accum2 = 0;
}
- QSORT(hash->data, 1ul << hash->alloc_log2, spanhash_cmp);
+ QSORT(hash->data, (size_t)1ul << hash->alloc_log2, spanhash_cmp);
return hash;
}
diff --git a/entry.c b/entry.c
index 9b0f968a70..1c9df62b30 100644
--- a/entry.c
+++ b/entry.c
@@ -82,11 +82,13 @@ static int create_file(const char *path, unsigned int mode)
return open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
}
-void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)
+void *read_blob_entry(const struct cache_entry *ce, size_t *size)
{
enum object_type type;
- void *blob_data = read_object_file(&ce->oid, &type, size);
+ unsigned long ul;
+ void *blob_data = read_object_file(&ce->oid, &type, &ul);
+ *size = ul;
if (blob_data) {
if (type == OBJ_BLOB)
return blob_data;
@@ -271,7 +273,7 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca
int fd, ret, fstat_done = 0;
char *new_blob;
struct strbuf buf = STRBUF_INIT;
- unsigned long size;
+ size_t size;
ssize_t wrote;
size_t newsize = 0;
struct stat st;
diff --git a/entry.h b/entry.h
index 2254c62727..252fd24c2e 100644
--- a/entry.h
+++ b/entry.h
@@ -52,7 +52,7 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts,
*/
void unlink_entry(const struct cache_entry *ce);
-void *read_blob_entry(const struct cache_entry *ce, unsigned long *size);
+void *read_blob_entry(const struct cache_entry *ce, size_t *size);
int fstat_checkout_output(int fd, const struct checkout *state, struct stat *st);
void update_ce_after_write(const struct checkout *state, struct cache_entry *ce,
struct stat *st);
diff --git a/fetch-pack.c b/fetch-pack.c
index a9604f35a3..34987a2c30 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -25,6 +25,7 @@
#include "shallow.h"
#include "commit-reach.h"
#include "commit-graph.h"
+#include "sigchain.h"
static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
@@ -956,6 +957,8 @@ static int get_pack(struct fetch_pack_args *args,
strvec_push(index_pack_args, cmd.args.v[i]);
}
+ sigchain_push(SIGPIPE, SIG_IGN);
+
cmd.in = demux.out;
cmd.git_cmd = 1;
if (start_command(&cmd))
@@ -986,6 +989,8 @@ static int get_pack(struct fetch_pack_args *args,
if (use_sideband && finish_async(&demux))
die(_("error in sideband demultiplexer"));
+ sigchain_pop(SIGPIPE);
+
/*
* Now that index-pack has succeeded, write the promisor file using the
* obtained .keep filename if necessary
@@ -1653,8 +1658,13 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
receive_wanted_refs(&reader, sought, nr_sought);
/* get the pack(s) */
+ if (git_env_bool("GIT_TRACE_REDACT", 1))
+ reader.options |= PACKET_READ_REDACT_URI_PATH;
if (process_section_header(&reader, "packfile-uris", 1))
receive_packfile_uris(&reader, &packfile_uris);
+ /* We don't expect more URIs. Reset to avoid expensive URI check. */
+ reader.options &= ~PACKET_READ_REDACT_URI_PATH;
+
process_section_header(&reader, "packfile", 0);
/*
diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh
index 9dbbb08e70..205541e0f7 100755
--- a/generate-cmdlist.sh
+++ b/generate-cmdlist.sh
@@ -6,37 +6,38 @@ die () {
}
command_list () {
- eval "grep -ve '^#' $exclude_programs" <"$1"
-}
-
-get_categories () {
- tr ' ' '\012'|
- grep -v '^$' |
- sort |
- uniq
+ while read cmd rest
+ do
+ case "$cmd" in
+ "#"* | '')
+ # Ignore comments and allow empty lines
+ continue
+ ;;
+ *)
+ case "$exclude_programs" in
+ *":$cmd:"*)
+ ;;
+ *)
+ echo "$cmd $rest"
+ ;;
+ esac
+ esac
+ done <"$1"
}
category_list () {
- command_list "$1" |
- cut -c 40- |
- get_categories
-}
-
-get_synopsis () {
- sed -n '
- /^NAME/,/'"$1"'/H
- ${
- x
- s/.*'"$1"' - \(.*\)/N_("\1")/
- p
- }' "Documentation/$1.txt"
+ echo "$1" |
+ cut -d' ' -f2- |
+ tr ' ' '\012' |
+ grep -v '^$' |
+ LC_ALL=C sort -u
}
define_categories () {
echo
echo "/* Command categories */"
bit=0
- category_list "$1" |
+ echo "$1" |
while read cat
do
echo "#define CAT_$cat (1UL << $bit)"
@@ -50,7 +51,7 @@ define_category_names () {
echo "/* Category names */"
echo "static const char *category_names[] = {"
bit=0
- category_list "$1" |
+ echo "$1" |
while read cat
do
echo " \"$cat\", /* (1UL << $bit) */"
@@ -63,27 +64,38 @@ define_category_names () {
print_command_list () {
echo "static struct cmdname_help command_list[] = {"
- command_list "$1" |
+ echo "$1" |
while read cmd rest
do
- printf " { \"$cmd\", $(get_synopsis $cmd), 0"
- for cat in $(echo "$rest" | get_categories)
+ synopsis=
+ while read line
do
- printf " | CAT_$cat"
- done
+ case "$line" in
+ "$cmd - "*)
+ synopsis=${line#$cmd - }
+ break
+ ;;
+ esac
+ done <"Documentation/$cmd.txt"
+
+ printf '\t{ "%s", N_("%s"), 0' "$cmd" "$synopsis"
+ printf " | CAT_%s" $rest
echo " },"
done
echo "};"
}
-exclude_programs=
+exclude_programs=:
while test "--exclude-program" = "$1"
do
shift
- exclude_programs="$exclude_programs -e \"^$1 \""
+ exclude_programs="$exclude_programs$1:"
shift
done
+commands="$(command_list "$1")"
+categories="$(category_list "$commands")"
+
echo "/* Automatically generated by generate-cmdlist.sh */
struct cmdname_help {
const char *name;
@@ -91,8 +103,8 @@ struct cmdname_help {
uint32_t category;
};
"
-define_categories "$1"
+define_categories "$categories"
echo
-define_category_names "$1"
+define_category_names "$categories"
echo
-print_command_list "$1"
+print_command_list "$commands"
diff --git a/git-compat-util.h b/git-compat-util.h
index d70ce14286..98c4f2c81e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1,6 +1,19 @@
#ifndef GIT_COMPAT_UTIL_H
#define GIT_COMPAT_UTIL_H
+#if __STDC_VERSION__ - 0 < 199901L
+/*
+ * Git is in a testing period for mandatory C99 support in the compiler. If
+ * your compiler is reasonably recent, you can try to enable C99 support (or,
+ * for MSVC, C11 support). If you encounter a problem and can't enable C99
+ * support with your compiler (such as with "-std=gnu99") and don't have access
+ * to one with this support, such as GCC or Clang, you can remove this #if
+ * directive, but please report the details of your system to
+ * git@vger.kernel.org.
+ */
+#error "Required C99 support is in a test phase. Please see git-compat-util.h for more details."
+#endif
+
#ifdef USE_MSVC_CRTDBG
/*
* For these to work they must appear very early in each
@@ -113,6 +126,14 @@
#define unsigned_mult_overflows(a, b) \
((a) && (b) > maximum_unsigned_value_of_type(a) / (a))
+/*
+ * Returns true if the left shift of "a" by "shift" bits will
+ * overflow. The type of "a" must be unsigned.
+ */
+#define unsigned_left_shift_overflows(a, shift) \
+ ((shift) < bitsizeof(a) && \
+ (a) > maximum_unsigned_value_of_type(a) >> (shift))
+
#ifdef __GNUC__
#define TYPEOF(x) (__typeof__(x))
#else
@@ -729,7 +750,7 @@ char *gitmkdtemp(char *);
#ifdef NO_UNSETENV
#define unsetenv gitunsetenv
-void gitunsetenv(const char *);
+int gitunsetenv(const char *);
#endif
#ifdef NO_STRCASESTR
@@ -862,6 +883,23 @@ static inline size_t st_sub(size_t a, size_t b)
return a - b;
}
+static inline size_t st_left_shift(size_t a, unsigned shift)
+{
+ if (unsigned_left_shift_overflows(a, shift))
+ die("size_t overflow: %"PRIuMAX" << %u",
+ (uintmax_t)a, shift);
+ return a << shift;
+}
+
+static inline unsigned long cast_size_t_to_ulong(size_t a)
+{
+ if (a != (unsigned long)a)
+ die("object too large to read on this platform: %"
+ PRIuMAX" is cut off to %lu",
+ (uintmax_t)a, (unsigned long)a);
+ return (unsigned long)a;
+}
+
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
# define xalloca(size) (alloca(size))
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index cb89372813..3a51d4507c 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -579,7 +579,7 @@ if [ "$filter_tag_name" ]; then
git hash-object -t tag -w --stdin) ||
die "Could not create new tag object for $ref"
if git cat-file tag "$ref" | \
- sane_grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1
+ grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1
then
warn "gpg signature stripped from tag object $sha1t"
fi
diff --git a/git-instaweb.sh b/git-instaweb.sh
index 7c55229773..4349566c89 100755
--- a/git-instaweb.sh
+++ b/git-instaweb.sh
@@ -49,7 +49,7 @@ resolve_full_httpd () {
*apache2*|*lighttpd*|*httpd*)
# yes, *httpd* covers *lighttpd* above, but it is there for clarity
# ensure that the apache2/lighttpd command ends with "-f"
- if ! echo "$httpd" | sane_grep -- '-f *$' >/dev/null 2>&1
+ if ! echo "$httpd" | grep -- '-f *$' >/dev/null 2>&1
then
httpd="$httpd -f"
fi
@@ -380,10 +380,7 @@ TypesConfig "$fqgitdir/mime.types"
DirectoryIndex gitweb.cgi
EOF
- # check to see if Dennis Stosberg's mod_perl compatibility patch
- # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
- if test -f "$module_path/mod_perl.so" &&
- sane_grep 'MOD_PERL' "$root/gitweb.cgi" >/dev/null
+ if test -f "$module_path/mod_perl.so"
then
# favor mod_perl if available
cat >> "$conf" <<EOF
@@ -402,7 +399,7 @@ EOF
# plain-old CGI
resolve_full_httpd
list_mods=$(echo "$full_httpd" | sed 's/-f$/-l/')
- $list_mods | sane_grep 'mod_cgi\.c' >/dev/null 2>&1 || \
+ $list_mods | grep 'mod_cgi\.c' >/dev/null 2>&1 || \
if test -f "$module_path/mod_cgi.so"
then
echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
diff --git a/git-send-email.perl b/git-send-email.perl
index 5262d88ee3..04087221aa 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -40,7 +40,8 @@ package main;
sub usage {
print <<EOT;
-git send-email [options] <file | directory | rev-list options >
+git send-email' [<options>] <file|directory>
+git send-email' [<options>] <format-patch options>
git send-email --dump-aliases
Composing:
@@ -113,9 +114,38 @@ EOT
exit(1);
}
+sub uniq {
+ my %seen;
+ grep !$seen{$_}++, @_;
+}
+
sub completion_helper {
- print Git::command('format-patch', '--git-completion-helper');
- exit(0);
+ my ($original_opts) = @_;
+ my %not_for_completion = (
+ "git-completion-helper" => undef,
+ "h" => undef,
+ );
+ my @send_email_opts = ();
+
+ foreach my $key (keys %$original_opts) {
+ unless (exists $not_for_completion{$key}) {
+ $key =~ s/!$//;
+
+ if ($key =~ /[:=][si]$/) {
+ $key =~ s/[:=][si]$//;
+ push (@send_email_opts, "--$_=") foreach (split (/\|/, $key));
+ } else {
+ push (@send_email_opts, "--$_") foreach (split (/\|/, $key));
+ }
+ }
+ }
+
+ my @format_patch_opts = split(/ /, Git::command('format-patch', '--git-completion-helper'));
+ my @opts = (@send_email_opts, @format_patch_opts);
+ @opts = uniq (grep !/^$/, @opts);
+ # There's an implicit '\n' here already, no need to add an explicit one.
+ print "@opts";
+ exit(0);
}
# most mail servers generate the Date: header, but not all...
@@ -425,10 +455,11 @@ my %known_config_keys;
my $key = "sendemail.identity";
$identity = Git::config(@repo, $key) if exists $known_config_keys{$key};
}
-my $rc = GetOptions(
+my %identity_options = (
"identity=s" => \$identity,
"no-identity" => \$no_identity,
);
+my $rc = GetOptions(%identity_options);
usage() unless $rc;
undef $identity if $no_identity;
@@ -444,14 +475,17 @@ undef $identity if $no_identity;
my $help;
my $git_completion_helper;
-$rc = GetOptions("h" => \$help,
- "dump-aliases" => \$dump_aliases);
+my %dump_aliases_options = (
+ "h" => \$help,
+ "dump-aliases" => \$dump_aliases,
+);
+$rc = GetOptions(%dump_aliases_options);
usage() unless $rc;
die __("--dump-aliases incompatible with other options\n")
if !$help and $dump_aliases and @ARGV;
-$rc = GetOptions(
+my %options = (
"sender|from=s" => \$sender,
- "in-reply-to=s" => \$initial_in_reply_to,
+ "in-reply-to=s" => \$initial_in_reply_to,
"reply-to=s" => \$reply_to,
"subject=s" => \$initial_subject,
"to=s" => \@getopt_to,
@@ -508,7 +542,8 @@ $rc = GetOptions(
"batch-size=i" => \$batch_size,
"relogin-delay=i" => \$relogin_delay,
"git-completion-helper" => \$git_completion_helper,
- );
+);
+$rc = GetOptions(%options);
# Munge any "either config or getopt, not both" variables
my @initial_to = @getopt_to ? @getopt_to : ($no_to ? () : @config_to);
@@ -516,7 +551,8 @@ my @initial_cc = @getopt_cc ? @getopt_cc : ($no_cc ? () : @config_cc);
my @initial_bcc = @getopt_bcc ? @getopt_bcc : ($no_bcc ? () : @config_bcc);
usage() if $help;
-completion_helper() if $git_completion_helper;
+my %all_options = (%options, %dump_aliases_options, %identity_options);
+completion_helper(\%all_options) if $git_completion_helper;
unless ($rc) {
usage();
}
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 960982f9d5..b93f39288c 100644
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -173,14 +173,6 @@ git_pager() {
eval "$GIT_PAGER" '"$@"'
}
-sane_grep () {
- GREP_OPTIONS= LC_ALL=C grep @@SANE_TEXT_GREP@@ "$@"
-}
-
-sane_egrep () {
- GREP_OPTIONS= LC_ALL=C egrep @@SANE_TEXT_GREP@@ "$@"
-}
-
is_bare_repository () {
git rev-parse --is-bare-repository
}
diff --git a/http-fetch.c b/http-fetch.c
index fa642462a9..c7c7d391ac 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -4,6 +4,7 @@
#include "http.h"
#include "walker.h"
#include "strvec.h"
+#include "urlmatch.h"
static const char http_fetch_usage[] = "git http-fetch "
"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin | --packfile=hash | commit-id] url";
@@ -63,8 +64,17 @@ static void fetch_single_packfile(struct object_id *packfile_hash,
if (start_active_slot(preq->slot)) {
run_active_slot(preq->slot);
if (results.curl_result != CURLE_OK) {
- die("Unable to get pack file %s\n%s", preq->url,
- curl_errorstr);
+ struct url_info url;
+ char *nurl = url_normalize(preq->url, &url);
+ if (!nurl || !git_env_bool("GIT_TRACE_REDACT", 1)) {
+ die("unable to get pack file '%s'\n%s", preq->url,
+ curl_errorstr);
+ } else {
+ die("failed to get '%.*s' url from '%.*s' "
+ "(full URL redacted due to GIT_TRACE_REDACT setting)\n%s",
+ (int)url.scheme_len, url.url,
+ (int)url.host_len, &url.url[url.host_off], curl_errorstr);
+ }
}
} else {
die("Unable to start request");
diff --git a/mergesort.c b/mergesort.c
index 6216835566..bd9c6ef8ee 100644
--- a/mergesort.c
+++ b/mergesort.c
@@ -63,7 +63,7 @@ void *llist_mergesort(void *list,
void *next = get_next_fn(list);
if (next)
set_next_fn(list, NULL);
- for (i = 0; n & (1 << i); i++)
+ for (i = 0; n & ((size_t)1 << i); i++)
list = llist_merge(ranks[i], list, get_next_fn,
set_next_fn, compare_fn);
n++;
diff --git a/midx.c b/midx.c
index 8433086ac1..837b46b2af 100644
--- a/midx.c
+++ b/midx.c
@@ -57,15 +57,15 @@ const unsigned char *get_midx_checksum(struct multi_pack_index *m)
return m->data + m->data_len - the_hash_algo->rawsz;
}
-char *get_midx_filename(const char *object_dir)
+void get_midx_filename(struct strbuf *out, const char *object_dir)
{
- return xstrfmt("%s/pack/multi-pack-index", object_dir);
+ strbuf_addf(out, "%s/pack/multi-pack-index", object_dir);
}
-char *get_midx_rev_filename(struct multi_pack_index *m)
+void get_midx_rev_filename(struct strbuf *out, struct multi_pack_index *m)
{
- return xstrfmt("%s/pack/multi-pack-index-%s.rev",
- m->object_dir, hash_to_hex(get_midx_checksum(m)));
+ get_midx_filename(out, m->object_dir);
+ strbuf_addf(out, "-%s.rev", hash_to_hex(get_midx_checksum(m)));
}
static int midx_read_oid_fanout(const unsigned char *chunk_start,
@@ -89,28 +89,30 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
size_t midx_size;
void *midx_map = NULL;
uint32_t hash_version;
- char *midx_name = get_midx_filename(object_dir);
+ struct strbuf midx_name = STRBUF_INIT;
uint32_t i;
const char *cur_pack_name;
struct chunkfile *cf = NULL;
- fd = git_open(midx_name);
+ get_midx_filename(&midx_name, object_dir);
+
+ fd = git_open(midx_name.buf);
if (fd < 0)
goto cleanup_fail;
if (fstat(fd, &st)) {
- error_errno(_("failed to read %s"), midx_name);
+ error_errno(_("failed to read %s"), midx_name.buf);
goto cleanup_fail;
}
midx_size = xsize_t(st.st_size);
if (midx_size < MIDX_MIN_SIZE) {
- error(_("multi-pack-index file %s is too small"), midx_name);
+ error(_("multi-pack-index file %s is too small"), midx_name.buf);
goto cleanup_fail;
}
- FREE_AND_NULL(midx_name);
+ strbuf_release(&midx_name);
midx_map = xmmap(NULL, midx_size, PROT_READ, MAP_PRIVATE, fd, 0);
close(fd);
@@ -179,12 +181,13 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
trace2_data_intmax("midx", the_repository, "load/num_packs", m->num_packs);
trace2_data_intmax("midx", the_repository, "load/num_objects", m->num_objects);
+ free_chunkfile(cf);
return m;
cleanup_fail:
free(m);
- free(midx_name);
- free(cf);
+ strbuf_release(&midx_name);
+ free_chunkfile(cf);
if (midx_map)
munmap(midx_map, midx_size);
if (0 <= fd)
@@ -1130,7 +1133,7 @@ static int write_midx_internal(const char *object_dir,
const char *refs_snapshot,
unsigned flags)
{
- char *midx_name;
+ struct strbuf midx_name = STRBUF_INIT;
unsigned char midx_hash[GIT_MAX_RAWSZ];
uint32_t i;
struct hashfile *f = NULL;
@@ -1141,10 +1144,10 @@ static int write_midx_internal(const char *object_dir,
int result = 0;
struct chunkfile *cf;
- midx_name = get_midx_filename(object_dir);
- if (safe_create_leading_directories(midx_name))
+ get_midx_filename(&midx_name, object_dir);
+ if (safe_create_leading_directories(midx_name.buf))
die_errno(_("unable to create leading directories of %s"),
- midx_name);
+ midx_name.buf);
if (!packs_to_include) {
/*
@@ -1373,7 +1376,7 @@ static int write_midx_internal(const char *object_dir,
pack_name_concat_len += MIDX_CHUNK_ALIGNMENT -
(pack_name_concat_len % MIDX_CHUNK_ALIGNMENT);
- hold_lock_file_for_update(&lk, midx_name, LOCK_DIE_ON_ERROR);
+ hold_lock_file_for_update(&lk, midx_name.buf, LOCK_DIE_ON_ERROR);
f = hashfd(get_lock_file_fd(&lk), get_lock_file_path(&lk));
if (ctx.nr - dropped_packs == 0) {
@@ -1410,9 +1413,9 @@ static int write_midx_internal(const char *object_dir,
ctx.pack_order = midx_pack_order(&ctx);
if (flags & MIDX_WRITE_REV_INDEX)
- write_midx_reverse_index(midx_name, midx_hash, &ctx);
+ write_midx_reverse_index(midx_name.buf, midx_hash, &ctx);
if (flags & MIDX_WRITE_BITMAP) {
- if (write_midx_bitmap(midx_name, midx_hash, &ctx,
+ if (write_midx_bitmap(midx_name.buf, midx_hash, &ctx,
refs_snapshot, flags) < 0) {
error(_("could not write multi-pack bitmap"));
result = 1;
@@ -1442,7 +1445,7 @@ cleanup:
free(ctx.entries);
free(ctx.pack_perm);
free(ctx.pack_order);
- free(midx_name);
+ strbuf_release(&midx_name);
return result;
}
@@ -1506,20 +1509,22 @@ static void clear_midx_files_ext(const char *object_dir, const char *ext,
void clear_midx_file(struct repository *r)
{
- char *midx = get_midx_filename(r->objects->odb->path);
+ struct strbuf midx = STRBUF_INIT;
+
+ get_midx_filename(&midx, r->objects->odb->path);
if (r->objects && r->objects->multi_pack_index) {
close_midx(r->objects->multi_pack_index);
r->objects->multi_pack_index = NULL;
}
- if (remove_path(midx))
- die(_("failed to clear multi-pack-index at %s"), midx);
+ if (remove_path(midx.buf))
+ die(_("failed to clear multi-pack-index at %s"), midx.buf);
clear_midx_files_ext(r->objects->odb->path, ".bitmap", NULL);
clear_midx_files_ext(r->objects->odb->path, ".rev", NULL);
- free(midx);
+ strbuf_release(&midx);
}
static int verify_midx_error;
@@ -1572,12 +1577,15 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
if (!m) {
int result = 0;
struct stat sb;
- char *filename = get_midx_filename(object_dir);
- if (!stat(filename, &sb)) {
+ struct strbuf filename = STRBUF_INIT;
+
+ get_midx_filename(&filename, object_dir);
+
+ if (!stat(filename.buf, &sb)) {
error(_("multi-pack-index file exists, but failed to parse"));
result = 1;
}
- free(filename);
+ strbuf_release(&filename);
return result;
}
@@ -1610,7 +1618,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
* Remaining tests assume that we have objects, so we can
* return here.
*/
- return verify_midx_error;
+ goto cleanup;
}
if (flags & MIDX_PROGRESS)
@@ -1688,7 +1696,9 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
}
stop_progress(&progress);
+cleanup:
free(pairs);
+ close_midx(m);
return verify_midx_error;
}
diff --git a/midx.h b/midx.h
index 6e32297fa3..b7d79a515c 100644
--- a/midx.h
+++ b/midx.h
@@ -48,8 +48,8 @@ struct multi_pack_index {
#define MIDX_WRITE_BITMAP_HASH_CACHE (1 << 3)
const unsigned char *get_midx_checksum(struct multi_pack_index *m);
-char *get_midx_filename(const char *object_dir);
-char *get_midx_rev_filename(struct multi_pack_index *m);
+void get_midx_filename(struct strbuf *out, const char *object_dir);
+void get_midx_rev_filename(struct strbuf *out, struct multi_pack_index *m);
struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
diff --git a/object-file.c b/object-file.c
index c3d866a287..eac67f6f5f 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1306,7 +1306,7 @@ static void *unpack_loose_rest(git_zstream *stream,
int parse_loose_header(const char *hdr, struct object_info *oi)
{
const char *type_buf = hdr;
- unsigned long size;
+ size_t size;
int type, type_len = 0;
/*
@@ -1341,12 +1341,12 @@ int parse_loose_header(const char *hdr, struct object_info *oi)
if (c > 9)
break;
hdr++;
- size = size * 10 + c;
+ size = st_add(st_mult(size, 10), c);
}
}
if (oi->sizep)
- *oi->sizep = size;
+ *oi->sizep = cast_size_t_to_ulong(size);
/*
* The length must be followed by a zero byte
@@ -2425,7 +2425,7 @@ struct oidtree *odb_loose_cache(struct object_directory *odb,
struct strbuf buf = STRBUF_INIT;
size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
size_t word_index = subdir_nr / word_bits;
- size_t mask = 1u << (subdir_nr % word_bits);
+ size_t mask = (size_t)1u << (subdir_nr % word_bits);
uint32_t *bitmap;
if (subdir_nr < 0 ||
diff --git a/pack-bitmap.c b/pack-bitmap.c
index f47a0a7db4..f772d3cb7f 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -292,9 +292,12 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
char *midx_bitmap_filename(struct multi_pack_index *midx)
{
- return xstrfmt("%s-%s.bitmap",
- get_midx_filename(midx->object_dir),
- hash_to_hex(get_midx_checksum(midx)));
+ struct strbuf buf = STRBUF_INIT;
+
+ get_midx_filename(&buf, midx->object_dir);
+ strbuf_addf(&buf, "-%s.bitmap", hash_to_hex(get_midx_checksum(midx)));
+
+ return strbuf_detach(&buf, NULL);
}
char *pack_bitmap_filename(struct packed_git *p)
@@ -324,10 +327,12 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
}
if (bitmap_git->pack || bitmap_git->midx) {
+ struct strbuf buf = STRBUF_INIT;
+ get_midx_filename(&buf, midx->object_dir);
/* ignore extra bitmap file; we can only handle one */
- warning("ignoring extra bitmap file: %s",
- get_midx_filename(midx->object_dir));
+ warning("ignoring extra bitmap file: %s", buf.buf);
close(fd);
+ strbuf_release(&buf);
return -1;
}
@@ -1721,6 +1726,12 @@ void test_bitmap_walk(struct rev_info *revs)
else
die("mismatch in bitmap results");
+ bitmap_free(result);
+ bitmap_free(tdata.base);
+ bitmap_free(tdata.commits);
+ bitmap_free(tdata.trees);
+ bitmap_free(tdata.blobs);
+ bitmap_free(tdata.tags);
free_bitmap_index(bitmap_git);
}
@@ -1748,7 +1759,7 @@ int test_bitmap_hashes(struct repository *r)
struct object_id oid;
uint32_t i, index_pos;
- if (!bitmap_git->hashes)
+ if (!bitmap_git || !bitmap_git->hashes)
goto cleanup;
for (i = 0; i < bitmap_num_objects(bitmap_git); i++) {
@@ -1848,9 +1859,17 @@ void free_bitmap_index(struct bitmap_index *b)
ewah_pool_free(b->trees);
ewah_pool_free(b->blobs);
ewah_pool_free(b->tags);
+ if (b->bitmaps) {
+ struct stored_bitmap *sb;
+ kh_foreach_value(b->bitmaps, sb, {
+ ewah_pool_free(sb->root);
+ free(sb);
+ });
+ }
kh_destroy_oid_map(b->bitmaps);
free(b->ext_index.objects);
free(b->ext_index.hashes);
+ kh_destroy_oid_pos(b->ext_index.positions);
bitmap_free(b->result);
bitmap_free(b->haves);
if (bitmap_is_midx(b)) {
diff --git a/pack-revindex.c b/pack-revindex.c
index 0e4a31d9db..70d0fbafcb 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -296,14 +296,14 @@ int load_pack_revindex(struct packed_git *p)
int load_midx_revindex(struct multi_pack_index *m)
{
- char *revindex_name;
+ struct strbuf revindex_name = STRBUF_INIT;
int ret;
if (m->revindex_data)
return 0;
- revindex_name = get_midx_rev_filename(m);
+ get_midx_rev_filename(&revindex_name, m);
- ret = load_revindex_from_disk(revindex_name,
+ ret = load_revindex_from_disk(revindex_name.buf,
m->num_objects,
&m->revindex_map,
&m->revindex_len);
@@ -313,7 +313,7 @@ int load_midx_revindex(struct multi_pack_index *m)
m->revindex_data = (const uint32_t *)((const char *)m->revindex_map + RIDX_HEADER_SIZE);
cleanup:
- free(revindex_name);
+ strbuf_release(&revindex_name);
return ret;
}
diff --git a/packfile.c b/packfile.c
index 89402cfc69..e30b051c8a 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1060,7 +1060,7 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
unsigned long len, enum object_type *type, unsigned long *sizep)
{
unsigned shift;
- unsigned long size, c;
+ size_t size, c;
unsigned long used = 0;
c = buf[used++];
@@ -1068,16 +1068,16 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
size = c & 15;
shift = 4;
while (c & 0x80) {
- if (len <= used || bitsizeof(long) <= shift) {
+ if (len <= used || (bitsizeof(long) - 7) <= shift) {
error("bad object header");
size = used = 0;
break;
}
c = buf[used++];
- size += (c & 0x7f) << shift;
+ size = st_add(size, st_left_shift(c & 0x7f, shift));
shift += 7;
}
- *sizep = size;
+ *sizep = cast_size_t_to_ulong(size);
return used;
}
diff --git a/pager.c b/pager.c
index 52f27a6765..27877f8ebb 100644
--- a/pager.c
+++ b/pager.c
@@ -8,7 +8,7 @@
#define DEFAULT_PAGER "less"
#endif
-static struct child_process pager_process = CHILD_PROCESS_INIT;
+static struct child_process pager_process;
static const char *pager_program;
/* Is the value coming back from term_columns() just a guess? */
@@ -124,6 +124,8 @@ void setup_pager(void)
setenv("GIT_PAGER_IN_USE", "true", 1);
+ child_process_init(&pager_process);
+
/* spawn the pager */
prepare_pager_args(&pager_process, pager);
pager_process.in = -1;
diff --git a/parallel-checkout.c b/parallel-checkout.c
index ed9c999520..8dd7e7bad4 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -261,7 +261,7 @@ static int write_pc_item_to_fd(struct parallel_checkout_item *pc_item, int fd,
struct stream_filter *filter;
struct strbuf buf = STRBUF_INIT;
char *blob;
- unsigned long size;
+ size_t size;
ssize_t wrote;
/* Sanity check */
diff --git a/pkt-line.c b/pkt-line.c
index 2dc8ac274b..8e43c2def4 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -370,6 +370,32 @@ int packet_length(const char lenbuf_hex[4])
return (val < 0) ? val : (val << 8) | hex2chr(lenbuf_hex + 2);
}
+static char *find_packfile_uri_path(const char *buffer)
+{
+ const char *URI_MARK = "://";
+ char *path;
+ int len;
+
+ /* First char is sideband mark */
+ buffer += 1;
+
+ len = strspn(buffer, "0123456789abcdefABCDEF");
+ /* size of SHA1 and SHA256 hash */
+ if (!(len == 40 || len == 64) || buffer[len] != ' ')
+ return NULL; /* required "<hash>SP" not seen */
+
+ path = strstr(buffer + len + 1, URI_MARK);
+ if (!path)
+ return NULL;
+
+ path = strchr(path + strlen(URI_MARK), '/');
+ if (!path || !*(path + 1))
+ return NULL;
+
+ /* position after '/' */
+ return ++path;
+}
+
enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
size_t *src_len, char *buffer,
unsigned size, int *pktlen,
@@ -377,6 +403,7 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
{
int len;
char linelen[4];
+ char *uri_path_start;
if (get_packet_data(fd, src_buffer, src_len, linelen, 4, options) < 0) {
*pktlen = -1;
@@ -427,7 +454,18 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
len--;
buffer[len] = 0;
- packet_trace(buffer, len, 0);
+ if (options & PACKET_READ_REDACT_URI_PATH &&
+ (uri_path_start = find_packfile_uri_path(buffer))) {
+ const char *redacted = "<redacted>";
+ struct strbuf tracebuf = STRBUF_INIT;
+ strbuf_insert(&tracebuf, 0, buffer, len);
+ strbuf_splice(&tracebuf, uri_path_start - buffer,
+ strlen(uri_path_start), redacted, strlen(redacted));
+ packet_trace(tracebuf.buf, tracebuf.len, 0);
+ strbuf_release(&tracebuf);
+ } else {
+ packet_trace(buffer, len, 0);
+ }
if ((options & PACKET_READ_DIE_ON_ERR_PACKET) &&
starts_with(buffer, "ERR "))
diff --git a/pkt-line.h b/pkt-line.h
index 467ae01357..6d2a63db23 100644
--- a/pkt-line.h
+++ b/pkt-line.h
@@ -87,6 +87,7 @@ void packet_fflush(FILE *f);
#define PACKET_READ_CHOMP_NEWLINE (1u<<1)
#define PACKET_READ_DIE_ON_ERR_PACKET (1u<<2)
#define PACKET_READ_GENTLE_ON_READ_ERROR (1u<<3)
+#define PACKET_READ_REDACT_URI_PATH (1u<<4)
int packet_read(int fd, char *buffer, unsigned size, int options);
/*
diff --git a/read-cache.c b/read-cache.c
index f398659662..cbe73f14e5 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -68,6 +68,11 @@
*/
#define CACHE_ENTRY_PATH_LENGTH 80
+enum index_search_mode {
+ NO_EXPAND_SPARSE = 0,
+ EXPAND_SPARSE = 1
+};
+
static inline struct cache_entry *mem_pool__ce_alloc(struct mem_pool *mem_pool, size_t len)
{
struct cache_entry *ce;
@@ -551,7 +556,10 @@ int cache_name_stage_compare(const char *name1, int len1, int stage1, const char
return 0;
}
-static int index_name_stage_pos(struct index_state *istate, const char *name, int namelen, int stage)
+static int index_name_stage_pos(struct index_state *istate,
+ const char *name, int namelen,
+ int stage,
+ enum index_search_mode search_mode)
{
int first, last;
@@ -570,7 +578,7 @@ static int index_name_stage_pos(struct index_state *istate, const char *name, in
first = next+1;
}
- if (istate->sparse_index &&
+ if (search_mode == EXPAND_SPARSE && istate->sparse_index &&
first > 0) {
/* Note: first <= istate->cache_nr */
struct cache_entry *ce = istate->cache[first - 1];
@@ -586,7 +594,7 @@ static int index_name_stage_pos(struct index_state *istate, const char *name, in
ce_namelen(ce) < namelen &&
!strncmp(name, ce->name, ce_namelen(ce))) {
ensure_full_index(istate);
- return index_name_stage_pos(istate, name, namelen, stage);
+ return index_name_stage_pos(istate, name, namelen, stage, search_mode);
}
}
@@ -595,7 +603,12 @@ static int index_name_stage_pos(struct index_state *istate, const char *name, in
int index_name_pos(struct index_state *istate, const char *name, int namelen)
{
- return index_name_stage_pos(istate, name, namelen, 0);
+ return index_name_stage_pos(istate, name, namelen, 0, EXPAND_SPARSE);
+}
+
+int index_entry_exists(struct index_state *istate, const char *name, int namelen)
+{
+ return index_name_stage_pos(istate, name, namelen, 0, NO_EXPAND_SPARSE) >= 0;
}
int remove_index_entry_at(struct index_state *istate, int pos)
@@ -1237,7 +1250,7 @@ static int has_dir_name(struct index_state *istate,
*/
}
- pos = index_name_stage_pos(istate, name, len, stage);
+ pos = index_name_stage_pos(istate, name, len, stage, EXPAND_SPARSE);
if (pos >= 0) {
/*
* Found one, but not so fast. This could
@@ -1337,7 +1350,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
strcmp(ce->name, istate->cache[istate->cache_nr - 1]->name) > 0)
pos = index_pos_to_insert_pos(istate->cache_nr);
else
- pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
+ pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce), EXPAND_SPARSE);
/* existing match? Just replace it. */
if (pos >= 0) {
@@ -1372,7 +1385,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
if (!ok_to_replace)
return error(_("'%s' appears as both a file and as a directory"),
ce->name);
- pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
+ pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce), EXPAND_SPARSE);
pos = -pos-1;
}
return pos + 1;
@@ -2352,9 +2365,17 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
if (!istate->repo)
istate->repo = the_repository;
+
+ /*
+ * If the command explicitly requires a full index, force it
+ * to be full. Otherwise, correct the sparsity based on repository
+ * settings and other properties of the index (if necessary).
+ */
prepare_repo_settings(istate->repo);
if (istate->repo->settings.command_requires_full_index)
ensure_full_index(istate);
+ else
+ ensure_correct_sparsity(istate);
return istate->cache_nr;
diff --git a/ref-filter.c b/ref-filter.c
index 08a3f839c9..7260fce31d 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2470,6 +2470,12 @@ static int memcasecmp(const void *vs1, const void *vs2, size_t n)
return 0;
}
+struct ref_sorting {
+ struct ref_sorting *next;
+ int atom; /* index into used_atom array (internal) */
+ enum ref_sorting_order sort_flags;
+};
+
static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, struct ref_array_item *b)
{
struct atom_value *va, *vb;
@@ -2663,7 +2669,7 @@ static int parse_sorting_atom(const char *atom)
}
/* If no sorting option is given, use refname to sort as default */
-struct ref_sorting *ref_default_sorting(void)
+static struct ref_sorting *ref_default_sorting(void)
{
static const char cstr_name[] = "refname";
@@ -2674,7 +2680,7 @@ struct ref_sorting *ref_default_sorting(void)
return sorting;
}
-void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
+static void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
{
struct ref_sorting *s;
@@ -2692,17 +2698,25 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
s->atom = parse_sorting_atom(arg);
}
-int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
+struct ref_sorting *ref_sorting_options(struct string_list *options)
{
+ struct string_list_item *item;
+ struct ref_sorting *sorting = NULL, **tail = &sorting;
+
+ if (!options->nr) {
+ sorting = ref_default_sorting();
+ } else {
+ for_each_string_list_item(item, options)
+ parse_ref_sorting(tail, item->string);
+ }
+
/*
- * NEEDSWORK: We should probably clear the list in this case, but we've
- * already munged the global used_atoms list, which would need to be
- * undone.
+ * From here on, the ref_sorting list should be used to talk
+ * about the sort order used for the output. The caller
+ * should not touch the string form anymore.
*/
- BUG_ON_OPT_NEG(unset);
-
- parse_ref_sorting(opt->value, arg);
- return 0;
+ string_list_clear(options, 0);
+ return sorting;
}
void ref_sorting_release(struct ref_sorting *sorting)
diff --git a/ref-filter.h b/ref-filter.h
index 6228458d30..aa0eea4ecf 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -23,16 +23,13 @@
#define FILTER_REFS_KIND_MASK (FILTER_REFS_ALL | FILTER_REFS_DETACHED_HEAD)
struct atom_value;
+struct ref_sorting;
-struct ref_sorting {
- struct ref_sorting *next;
- int atom; /* index into used_atom array (internal) */
- enum {
- REF_SORTING_REVERSE = 1<<0,
- REF_SORTING_ICASE = 1<<1,
- REF_SORTING_VERSION = 1<<2,
- REF_SORTING_DETACHED_HEAD_FIRST = 1<<3,
- } sort_flags;
+enum ref_sorting_order {
+ REF_SORTING_REVERSE = 1<<0,
+ REF_SORTING_ICASE = 1<<1,
+ REF_SORTING_VERSION = 1<<2,
+ REF_SORTING_DETACHED_HEAD_FIRST = 1<<3,
};
struct ref_array_item {
@@ -97,9 +94,8 @@ struct ref_format {
#define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h)
#define OPT_REF_SORT(var) \
- OPT_CALLBACK_F(0, "sort", (var), \
- N_("key"), N_("field name to sort on"), \
- PARSE_OPT_NONEG, parse_opt_ref_sorting)
+ OPT_STRING_LIST(0, "sort", (var), \
+ N_("key"), N_("field name to sort on"))
/*
* API for filtering a set of refs. Based on the type of refs the user
@@ -121,14 +117,10 @@ int format_ref_array_item(struct ref_array_item *info,
struct ref_format *format,
struct strbuf *final_buf,
struct strbuf *error_buf);
-/* Parse a single sort specifier and add it to the list */
-void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);
-/* Callback function for parsing the sort option */
-int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset);
-/* Default sort option based on refname */
-struct ref_sorting *ref_default_sorting(void);
/* Release a "struct ref_sorting" */
void ref_sorting_release(struct ref_sorting *);
+/* Convert list of sort options into ref_sorting */
+struct ref_sorting *ref_sorting_options(struct string_list *);
/* Function to parse --merged and --no-merged options */
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
/* Get the current HEAD's description */
diff --git a/refs.c b/refs.c
index d7cc0a23a3..4338875d86 100644
--- a/refs.c
+++ b/refs.c
@@ -269,9 +269,10 @@ char *refs_resolve_refdup(struct ref_store *refs,
struct object_id *oid, int *flags)
{
const char *result;
+ int ignore_errno;
result = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
- oid, flags);
+ oid, flags, &ignore_errno);
return xstrdup_or_null(result);
}
@@ -291,20 +292,17 @@ struct ref_filter {
void *cb_data;
};
-int refs_read_ref_full(struct ref_store *refs, const char *refname,
- int resolve_flags, struct object_id *oid, int *flags)
+int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
{
- if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid, flags))
+ int ignore_errno;
+ struct ref_store *refs = get_main_ref_store(the_repository);
+
+ if (refs_resolve_ref_unsafe(refs, refname, resolve_flags,
+ oid, flags, &ignore_errno))
return 0;
return -1;
}
-int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
-{
- return refs_read_ref_full(get_main_ref_store(the_repository), refname,
- resolve_flags, oid, flags);
-}
-
int read_ref(const char *refname, struct object_id *oid)
{
return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
@@ -312,7 +310,9 @@ int read_ref(const char *refname, struct object_id *oid)
int refs_ref_exists(struct ref_store *refs, const char *refname)
{
- return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);
+ int ignore_errno;
+ return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING,
+ NULL, NULL, &ignore_errno);
}
int ref_exists(const char *refname)
@@ -655,13 +655,16 @@ int expand_ref(struct repository *repo, const char *str, int len,
struct object_id oid_from_ref;
struct object_id *this_result;
int flag;
+ struct ref_store *refs = get_main_ref_store(repo);
+ int ignore_errno;
this_result = refs_found ? &oid_from_ref : oid;
strbuf_reset(&fullref);
strbuf_addf(&fullref, *p, len, str);
- r = refs_resolve_ref_unsafe(get_main_ref_store(repo),
- fullref.buf, RESOLVE_REF_READING,
- this_result, &flag);
+ r = refs_resolve_ref_unsafe(refs, fullref.buf,
+ RESOLVE_REF_READING,
+ this_result, &flag,
+ &ignore_errno);
if (r) {
if (!refs_found++)
*ref = xstrdup(r);
@@ -690,12 +693,14 @@ int repo_dwim_log(struct repository *r, const char *str, int len,
for (p = ref_rev_parse_rules; *p; p++) {
struct object_id hash;
const char *ref, *it;
+ int ignore_errno;
strbuf_reset(&path);
strbuf_addf(&path, *p, len, str);
ref = refs_resolve_ref_unsafe(refs, path.buf,
RESOLVE_REF_READING,
- oid ? &hash : NULL, NULL);
+ oid ? &hash : NULL, NULL,
+ &ignore_errno);
if (!ref)
continue;
if (refs_reflog_exists(refs, path.buf))
@@ -1089,6 +1094,13 @@ int ref_transaction_update(struct ref_transaction *transaction,
if (flags & ~REF_TRANSACTION_UPDATE_ALLOWED_FLAGS)
BUG("illegal flags 0x%x passed to ref_transaction_update()", flags);
+ /*
+ * Clear flags outside the allowed set; this should be a noop because
+ * of the BUG() check above, but it works around a -Wnonnull warning
+ * with some versions of "gcc -O3".
+ */
+ flags &= REF_TRANSACTION_UPDATE_ALLOWED_FLAGS;
+
flags |= (new_oid ? REF_HAVE_NEW : 0) | (old_oid ? REF_HAVE_OLD : 0);
ref_transaction_add_update(transaction, refname, flags,
@@ -1373,32 +1385,14 @@ const char *find_descendant_ref(const char *dirname,
return NULL;
}
-int refs_rename_ref_available(struct ref_store *refs,
- const char *old_refname,
- const char *new_refname)
-{
- struct string_list skip = STRING_LIST_INIT_NODUP;
- struct strbuf err = STRBUF_INIT;
- int ok;
-
- string_list_insert(&skip, old_refname);
- ok = !refs_verify_refname_available(refs, new_refname,
- NULL, &skip, &err);
- if (!ok)
- error("%s", err.buf);
-
- string_list_clear(&skip, 0);
- strbuf_release(&err);
- return ok;
-}
-
int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
{
struct object_id oid;
int flag;
+ int ignore_errno;
- if (!refs_read_ref_full(refs, "HEAD", RESOLVE_REF_READING,
- &oid, &flag))
+ if (refs_resolve_ref_unsafe(refs, "HEAD", RESOLVE_REF_READING,
+ &oid, &flag, &ignore_errno))
return fn("HEAD", &oid, flag, cb_data);
return 0;
@@ -1649,7 +1643,8 @@ int for_each_fullref_in_prefixes(const char *namespace,
static int refs_read_special_head(struct ref_store *ref_store,
const char *refname, struct object_id *oid,
- struct strbuf *referent, unsigned int *type)
+ struct strbuf *referent, unsigned int *type,
+ int *failure_errno)
{
struct strbuf full_path = STRBUF_INIT;
struct strbuf content = STRBUF_INIT;
@@ -1659,7 +1654,8 @@ static int refs_read_special_head(struct ref_store *ref_store,
if (strbuf_read_file(&content, full_path.buf, 0) < 0)
goto done;
- result = parse_loose_ref_contents(content.buf, oid, referent, type);
+ result = parse_loose_ref_contents(content.buf, oid, referent, type,
+ failure_errno);
done:
strbuf_release(&full_path);
@@ -1667,30 +1663,33 @@ done:
return result;
}
-int refs_read_raw_ref(struct ref_store *ref_store,
- const char *refname, struct object_id *oid,
- struct strbuf *referent, unsigned int *type)
+int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
+ struct object_id *oid, struct strbuf *referent,
+ unsigned int *type, int *failure_errno)
{
+ assert(failure_errno);
if (!strcmp(refname, "FETCH_HEAD") || !strcmp(refname, "MERGE_HEAD")) {
return refs_read_special_head(ref_store, refname, oid, referent,
- type);
+ type, failure_errno);
}
return ref_store->be->read_raw_ref(ref_store, refname, oid, referent,
- type, &errno);
+ type, failure_errno);
}
-/* This function needs to return a meaningful errno on failure */
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
const char *refname,
int resolve_flags,
- struct object_id *oid, int *flags)
+ struct object_id *oid,
+ int *flags, int *failure_errno)
{
static struct strbuf sb_refname = STRBUF_INIT;
struct object_id unused_oid;
int unused_flags;
int symref_count;
+ assert(failure_errno);
+
if (!oid)
oid = &unused_oid;
if (!flags)
@@ -1701,7 +1700,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
if (!(resolve_flags & RESOLVE_REF_ALLOW_BAD_NAME) ||
!refname_is_safe(refname)) {
- errno = EINVAL;
+ *failure_errno = EINVAL;
return NULL;
}
@@ -1719,9 +1718,11 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
for (symref_count = 0; symref_count < SYMREF_MAXDEPTH; symref_count++) {
unsigned int read_flags = 0;
- if (refs_read_raw_ref(refs, refname,
- oid, &sb_refname, &read_flags)) {
+ if (refs_read_raw_ref(refs, refname, oid, &sb_refname,
+ &read_flags, failure_errno)) {
*flags |= read_flags;
+ if (errno)
+ *failure_errno = errno;
/* In reading mode, refs must eventually resolve */
if (resolve_flags & RESOLVE_REF_READING)
@@ -1732,9 +1733,9 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
* may show errors besides ENOENT if there are
* similarly-named refs.
*/
- if (errno != ENOENT &&
- errno != EISDIR &&
- errno != ENOTDIR)
+ if (*failure_errno != ENOENT &&
+ *failure_errno != EISDIR &&
+ *failure_errno != ENOTDIR)
return NULL;
oidclr(oid);
@@ -1761,7 +1762,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
if (!(resolve_flags & RESOLVE_REF_ALLOW_BAD_NAME) ||
!refname_is_safe(refname)) {
- errno = EINVAL;
+ *failure_errno = EINVAL;
return NULL;
}
@@ -1769,7 +1770,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
}
}
- errno = ELOOP;
+ *failure_errno = ELOOP;
return NULL;
}
@@ -1784,8 +1785,10 @@ int refs_init_db(struct strbuf *err)
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
struct object_id *oid, int *flags)
{
+ int ignore_errno;
+
return refs_resolve_ref_unsafe(get_main_ref_store(the_repository), refname,
- resolve_flags, oid, flags);
+ resolve_flags, oid, flags, &ignore_errno);
}
int resolve_gitlink_ref(const char *submodule, const char *refname,
@@ -1793,14 +1796,15 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
{
struct ref_store *refs;
int flags;
+ int ignore_errno;
refs = get_submodule_ref_store(submodule);
if (!refs)
return -1;
- if (!refs_resolve_ref_unsafe(refs, refname, 0, oid, &flags) ||
- is_null_oid(oid))
+ if (!refs_resolve_ref_unsafe(refs, refname, 0, oid, &flags,
+ &ignore_errno) || is_null_oid(oid))
return -1;
return 0;
}
@@ -2102,8 +2106,11 @@ static int run_transaction_hook(struct ref_transaction *transaction,
update->refname);
if (write_in_full(proc.in, buf.buf, buf.len) < 0) {
- if (errno != EPIPE)
+ if (errno != EPIPE) {
+ /* Don't leak errno outside this API */
+ errno = 0;
ret = -1;
+ }
break;
}
}
@@ -2238,6 +2245,13 @@ int refs_verify_refname_available(struct ref_store *refs,
strbuf_grow(&dirname, strlen(refname) + 1);
for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
+ /*
+ * Just saying "Is a directory" when we e.g. can't
+ * lock some multi-level ref isn't very informative,
+ * the user won't be told *what* is a directory, so
+ * let's not use strerror() below.
+ */
+ int ignore_errno;
/* Expand dirname to the new prefix, not including the trailing slash: */
strbuf_add(&dirname, refname + dirname.len, slash - refname - dirname.len);
@@ -2249,7 +2263,8 @@ int refs_verify_refname_available(struct ref_store *refs,
if (skip && string_list_has_string(skip, dirname.buf))
continue;
- if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent, &type)) {
+ if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent,
+ &type, &ignore_errno)) {
strbuf_addf(err, _("'%s' exists; cannot create '%s'"),
dirname.buf, refname);
goto cleanup;
@@ -2358,16 +2373,15 @@ int reflog_exists(const char *refname)
}
int refs_create_reflog(struct ref_store *refs, const char *refname,
- int force_create, struct strbuf *err)
+ struct strbuf *err)
{
- return refs->be->create_reflog(refs, refname, force_create, err);
+ return refs->be->create_reflog(refs, refname, err);
}
-int safe_create_reflog(const char *refname, int force_create,
- struct strbuf *err)
+int safe_create_reflog(const char *refname, struct strbuf *err)
{
return refs_create_reflog(get_main_ref_store(the_repository), refname,
- force_create, err);
+ err);
}
int refs_delete_reflog(struct ref_store *refs, const char *refname)
diff --git a/refs.h b/refs.h
index d5099d4984..bb50d1eb19 100644
--- a/refs.h
+++ b/refs.h
@@ -58,6 +58,11 @@ struct worktree;
* resolved. The function returns NULL for such ref names.
* Caps and underscores refers to the special refs, such as HEAD,
* FETCH_HEAD and friends, that all live outside of the refs/ directory.
+ *
+ * Callers should not inspect "errno" on failure, but rather pass in a
+ * "failure_errno" parameter, on failure the "errno" will indicate the
+ * type of failure encountered, but not necessarily one that came from
+ * a syscall. We might have faked it up.
*/
#define RESOLVE_REF_READING 0x01
#define RESOLVE_REF_NO_RECURSE 0x02
@@ -67,7 +72,8 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
const char *refname,
int resolve_flags,
struct object_id *oid,
- int *flags);
+ int *flags, int *failure_errno);
+
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
struct object_id *oid, int *flags);
@@ -77,8 +83,6 @@ char *refs_resolve_refdup(struct ref_store *refs,
char *resolve_refdup(const char *refname, int resolve_flags,
struct object_id *oid, int *flags);
-int refs_read_ref_full(struct ref_store *refs, const char *refname,
- int resolve_flags, struct object_id *oid, int *flags);
int read_ref_full(const char *refname, int resolve_flags,
struct object_id *oid, int *flags);
int read_ref(const char *refname, struct object_id *oid);
@@ -413,8 +417,8 @@ int refs_pack_refs(struct ref_store *refs, unsigned int flags);
* Setup reflog before using. Fill in err and return -1 on failure.
*/
int refs_create_reflog(struct ref_store *refs, const char *refname,
- int force_create, struct strbuf *err);
-int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);
+ struct strbuf *err);
+int safe_create_reflog(const char *refname, struct strbuf *err);
/** Reads log for the value of ref during at_time. **/
int read_ref_at(struct ref_store *refs,
diff --git a/refs/debug.c b/refs/debug.c
index 8667c64023..756d07c724 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -339,11 +339,10 @@ static int debug_reflog_exists(struct ref_store *ref_store, const char *refname)
}
static int debug_create_reflog(struct ref_store *ref_store, const char *refname,
- int force_create, struct strbuf *err)
+ struct strbuf *err)
{
struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
- int res = drefs->refs->be->create_reflog(drefs->refs, refname,
- force_create, err);
+ int res = drefs->refs->be->create_reflog(drefs->refs, refname, err);
trace_printf_key(&trace_refs, "create_reflog: %s: %d\n", refname, res);
return res;
}
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 151b0056fe..237a2afb5d 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -282,10 +282,11 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
create_dir_entry(dir->cache, refname.buf,
refname.len));
} else {
+ int ignore_errno;
if (!refs_resolve_ref_unsafe(&refs->base,
refname.buf,
RESOLVE_REF_READING,
- &oid, &flag)) {
+ &oid, &flag, &ignore_errno)) {
oidclr(&oid);
flag |= REF_ISBROKEN;
} else if (is_null_oid(&oid)) {
@@ -357,6 +358,7 @@ static int files_read_raw_ref(struct ref_store *ref_store, const char *refname,
int fd;
int ret = -1;
int remaining_retries = 3;
+ int myerr = 0;
*type = 0;
strbuf_reset(&sb_path);
@@ -383,11 +385,14 @@ stat_ref:
goto out;
if (lstat(path, &st) < 0) {
- if (errno != ENOENT)
+ int ignore_errno;
+ myerr = errno;
+ errno = 0;
+ if (myerr != ENOENT)
goto out;
- if (refs_read_raw_ref(refs->packed_ref_store, refname,
- oid, referent, type)) {
- errno = ENOENT;
+ if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
+ referent, type, &ignore_errno)) {
+ myerr = ENOENT;
goto out;
}
ret = 0;
@@ -398,7 +403,9 @@ stat_ref:
if (S_ISLNK(st.st_mode)) {
strbuf_reset(&sb_contents);
if (strbuf_readlink(&sb_contents, path, st.st_size) < 0) {
- if (errno == ENOENT || errno == EINVAL)
+ myerr = errno;
+ errno = 0;
+ if (myerr == ENOENT || myerr == EINVAL)
/* inconsistent with lstat; retry */
goto stat_ref;
else
@@ -420,14 +427,15 @@ stat_ref:
/* Is it a directory? */
if (S_ISDIR(st.st_mode)) {
+ int ignore_errno;
/*
* Even though there is a directory where the loose
* ref is supposed to be, there could still be a
* packed ref:
*/
- if (refs_read_raw_ref(refs->packed_ref_store, refname,
- oid, referent, type)) {
- errno = EISDIR;
+ if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
+ referent, type, &ignore_errno)) {
+ myerr = EISDIR;
goto out;
}
ret = 0;
@@ -440,7 +448,8 @@ stat_ref:
*/
fd = open(path, O_RDONLY);
if (fd < 0) {
- if (errno == ENOENT && !S_ISLNK(st.st_mode))
+ myerr = errno;
+ if (myerr == ENOENT && !S_ISLNK(st.st_mode))
/* inconsistent with lstat; retry */
goto stat_ref;
else
@@ -448,26 +457,29 @@ stat_ref:
}
strbuf_reset(&sb_contents);
if (strbuf_read(&sb_contents, fd, 256) < 0) {
- int save_errno = errno;
+ myerr = errno;
close(fd);
- errno = save_errno;
goto out;
}
close(fd);
strbuf_rtrim(&sb_contents);
buf = sb_contents.buf;
- ret = parse_loose_ref_contents(buf, oid, referent, type);
+ ret = parse_loose_ref_contents(buf, oid, referent, type, &myerr);
out:
- *failure_errno = errno;
+ if (ret && !myerr)
+ BUG("returning non-zero %d, should have set myerr!", ret);
+ *failure_errno = myerr;
+
strbuf_release(&sb_path);
strbuf_release(&sb_contents);
return ret;
}
int parse_loose_ref_contents(const char *buf, struct object_id *oid,
- struct strbuf *referent, unsigned int *type)
+ struct strbuf *referent, unsigned int *type,
+ int *failure_errno)
{
const char *p;
if (skip_prefix(buf, "ref:", &buf)) {
@@ -486,7 +498,7 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid,
if (parse_oid_hex(buf, oid, &p) ||
(*p != '\0' && !isspace(*p))) {
*type |= REF_ISBROKEN;
- errno = EINVAL;
+ *failure_errno = EINVAL;
return -1;
}
return 0;
@@ -995,11 +1007,12 @@ static int create_reflock(const char *path, void *cb)
* Locks a ref returning the lock on success and NULL on failure.
*/
static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
- const char *refname, int *type,
+ const char *refname,
struct strbuf *err)
{
struct strbuf ref_file = STRBUF_INIT;
struct ref_lock *lock;
+ int ignore_errno;
files_assert_main_repository(refs, "lock_ref_oid_basic");
assert(err);
@@ -1007,16 +1020,6 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
CALLOC_ARRAY(lock, 1);
files_ref_path(refs, &ref_file, refname);
- if (!refs_resolve_ref_unsafe(&refs->base, refname,
- RESOLVE_REF_NO_RECURSE,
- &lock->old_oid, type)) {
- if (!refs_verify_refname_available(&refs->base, refname,
- NULL, NULL, err))
- strbuf_addf(err, "unable to resolve reference '%s': %s",
- refname, strerror(errno));
-
- goto error_return;
- }
/*
* If the ref did not exist and we are creating it, make sure
@@ -1036,9 +1039,8 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
goto error_return;
}
- if (refs_read_ref_full(&refs->base, lock->ref_name,
- 0,
- &lock->old_oid, NULL))
+ if (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, 0,
+ &lock->old_oid, NULL, &ignore_errno))
oidclr(&lock->old_oid);
goto out;
@@ -1358,6 +1360,35 @@ static int commit_ref_update(struct files_ref_store *refs,
const struct object_id *oid, const char *logmsg,
struct strbuf *err);
+/*
+ * Emit a better error message than lockfile.c's
+ * unable_to_lock_message() would in case there is a D/F conflict with
+ * another existing reference. If there would be a conflict, emit an error
+ * message and return false; otherwise, return true.
+ *
+ * Note that this function is not safe against all races with other
+ * processes, and that's not its job. We'll emit a more verbose error on D/f
+ * conflicts if we get past it into lock_ref_oid_basic().
+ */
+static int refs_rename_ref_available(struct ref_store *refs,
+ const char *old_refname,
+ const char *new_refname)
+{
+ struct string_list skip = STRING_LIST_INIT_NODUP;
+ struct strbuf err = STRBUF_INIT;
+ int ok;
+
+ string_list_insert(&skip, old_refname);
+ ok = !refs_verify_refname_available(refs, new_refname,
+ NULL, &skip, &err);
+ if (!ok)
+ error("%s", err.buf);
+
+ string_list_clear(&skip, 0);
+ strbuf_release(&err);
+ return ok;
+}
+
static int files_copy_or_rename_ref(struct ref_store *ref_store,
const char *oldrefname, const char *newrefname,
const char *logmsg, int copy)
@@ -1373,6 +1404,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
struct strbuf tmp_renamed_log = STRBUF_INIT;
int log, ret;
struct strbuf err = STRBUF_INIT;
+ int ignore_errno;
files_reflog_path(refs, &sb_oldref, oldrefname);
files_reflog_path(refs, &sb_newref, newrefname);
@@ -1386,7 +1418,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
if (!refs_resolve_ref_unsafe(&refs->base, oldrefname,
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
- &orig_oid, &flag)) {
+ &orig_oid, &flag, &ignore_errno)) {
ret = error("refname %s not found", oldrefname);
goto out;
}
@@ -1430,9 +1462,9 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
* the safety anyway; we want to delete the reference whatever
* its current value.
*/
- if (!copy && !refs_read_ref_full(&refs->base, newrefname,
- RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
- NULL, NULL) &&
+ if (!copy && refs_resolve_ref_unsafe(&refs->base, newrefname,
+ RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
+ NULL, NULL, &ignore_errno) &&
refs_delete_ref(&refs->base, NULL, newrefname,
NULL, REF_NO_DEREF)) {
if (errno == EISDIR) {
@@ -1458,7 +1490,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
logmoved = log;
- lock = lock_ref_oid_basic(refs, newrefname, NULL, &err);
+ lock = lock_ref_oid_basic(refs, newrefname, &err);
if (!lock) {
if (copy)
error("unable to copy '%s' to '%s': %s", oldrefname, newrefname, err.buf);
@@ -1480,7 +1512,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
goto out;
rollback:
- lock = lock_ref_oid_basic(refs, oldrefname, NULL, &err);
+ lock = lock_ref_oid_basic(refs, oldrefname, &err);
if (!lock) {
error("unable to lock %s for rollback: %s", oldrefname, err.buf);
strbuf_release(&err);
@@ -1639,15 +1671,14 @@ error:
return -1;
}
-static int files_create_reflog(struct ref_store *ref_store,
- const char *refname, int force_create,
+static int files_create_reflog(struct ref_store *ref_store, const char *refname,
struct strbuf *err)
{
struct files_ref_store *refs =
files_downcast(ref_store, REF_STORE_WRITE, "create_reflog");
int fd;
- if (log_ref_setup(refs, refname, force_create, &fd, err))
+ if (log_ref_setup(refs, refname, 1, &fd, err))
return -1;
if (fd >= 0)
@@ -1797,10 +1828,12 @@ static int commit_ref_update(struct files_ref_store *refs,
*/
int head_flag;
const char *head_ref;
+ int ignore_errno;
head_ref = refs_resolve_ref_unsafe(&refs->base, "HEAD",
RESOLVE_REF_READING,
- NULL, &head_flag);
+ NULL, &head_flag,
+ &ignore_errno);
if (head_ref && (head_flag & REF_ISSYMREF) &&
!strcmp(head_ref, lock->ref_name)) {
struct strbuf log_err = STRBUF_INIT;
@@ -1844,9 +1877,12 @@ static void update_symref_reflog(struct files_ref_store *refs,
{
struct strbuf err = STRBUF_INIT;
struct object_id new_oid;
+ int ignore_errno;
+
if (logmsg &&
- !refs_read_ref_full(&refs->base, target,
- RESOLVE_REF_READING, &new_oid, NULL) &&
+ refs_resolve_ref_unsafe(&refs->base, target,
+ RESOLVE_REF_READING, &new_oid, NULL,
+ &ignore_errno) &&
files_log_ref_write(refs, refname, &lock->old_oid,
&new_oid, logmsg, 0, &err)) {
error("%s", err.buf);
@@ -1887,7 +1923,7 @@ static int files_create_symref(struct ref_store *ref_store,
struct ref_lock *lock;
int ret;
- lock = lock_ref_oid_basic(refs, refname, NULL, &err);
+ lock = lock_ref_oid_basic(refs, refname, &err);
if (!lock) {
error("%s", err.buf);
strbuf_release(&err);
@@ -2120,6 +2156,7 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
(struct files_reflog_iterator *)ref_iterator;
struct dir_iterator *diter = iter->dir_iterator;
int ok;
+ int ignore_errno;
while ((ok = dir_iterator_advance(diter)) == ITER_OK) {
int flags;
@@ -2131,9 +2168,10 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
if (ends_with(diter->basename, ".lock"))
continue;
- if (refs_read_ref_full(iter->ref_store,
- diter->relative_path, 0,
- &iter->oid, &flags)) {
+ if (!refs_resolve_ref_unsafe(iter->ref_store,
+ diter->relative_path, 0,
+ &iter->oid, &flags,
+ &ignore_errno)) {
error("bad ref for %s", diter->path.buf);
continue;
}
@@ -2477,9 +2515,11 @@ static int lock_ref_for_update(struct files_ref_store *refs,
* the transaction, so we have to read it here
* to record and possibly check old_oid:
*/
- if (refs_read_ref_full(&refs->base,
- referent.buf, 0,
- &lock->old_oid, NULL)) {
+ int ignore_errno;
+ if (!refs_resolve_ref_unsafe(&refs->base,
+ referent.buf, 0,
+ &lock->old_oid, NULL,
+ &ignore_errno)) {
if (update->flags & REF_HAVE_OLD) {
strbuf_addf(err, "cannot lock ref '%s': "
"error reading reference",
@@ -3091,7 +3131,6 @@ static int files_reflog_expire(struct ref_store *ref_store,
struct strbuf log_file_sb = STRBUF_INIT;
char *log_file;
int status = 0;
- int type;
struct strbuf err = STRBUF_INIT;
const struct object_id *oid;
@@ -3105,7 +3144,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
* reference itself, plus we might need to update the
* reference if --updateref was specified:
*/
- lock = lock_ref_oid_basic(refs, refname, &type, &err);
+ lock = lock_ref_oid_basic(refs, refname, &err);
if (!lock) {
error("cannot lock ref '%s': %s", refname, err.buf);
strbuf_release(&err);
@@ -3167,9 +3206,20 @@ static int files_reflog_expire(struct ref_store *ref_store,
* a reference if there are no remaining reflog
* entries.
*/
- int update = (flags & EXPIRE_REFLOGS_UPDATE_REF) &&
- !(type & REF_ISSYMREF) &&
- !is_null_oid(&cb.last_kept_oid);
+ int update = 0;
+
+ if ((flags & EXPIRE_REFLOGS_UPDATE_REF) &&
+ !is_null_oid(&cb.last_kept_oid)) {
+ int ignore_errno;
+ int type;
+ const char *ref;
+
+ ref = refs_resolve_ref_unsafe(&refs->base, refname,
+ RESOLVE_REF_NO_RECURSE,
+ NULL, &type,
+ &ignore_errno);
+ update = !!(ref && !(type & REF_ISSYMREF));
+ }
if (close_lock_file_gently(&reflog_lock)) {
status |= error("couldn't write %s: %s", log_file,
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 1c5211b03e..67152c664e 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1354,6 +1354,7 @@ int is_packed_transaction_needed(struct ref_store *ref_store,
ret = 0;
for (i = 0; i < transaction->nr; i++) {
struct ref_update *update = transaction->updates[i];
+ int failure_errno;
unsigned int type;
struct object_id oid;
@@ -1364,9 +1365,9 @@ int is_packed_transaction_needed(struct ref_store *ref_store,
*/
continue;
- if (!refs_read_raw_ref(ref_store, update->refname,
- &oid, &referent, &type) ||
- errno != ENOENT) {
+ if (!refs_read_raw_ref(ref_store, update->refname, &oid,
+ &referent, &type, &failure_errno) ||
+ failure_errno != ENOENT) {
/*
* We have to actually delete that reference
* -> this transaction is needed.
@@ -1628,8 +1629,7 @@ static int packed_reflog_exists(struct ref_store *ref_store,
}
static int packed_create_reflog(struct ref_store *ref_store,
- const char *refname, int force_create,
- struct strbuf *err)
+ const char *refname, struct strbuf *err)
{
BUG("packed reference store does not support reflogs");
}
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 12224742ed..46a839539e 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -150,9 +150,9 @@ struct ref_update {
const char refname[FLEX_ARRAY];
};
-int refs_read_raw_ref(struct ref_store *ref_store,
- const char *refname, struct object_id *oid,
- struct strbuf *referent, unsigned int *type);
+int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
+ struct object_id *oid, struct strbuf *referent,
+ unsigned int *type, int *failure_errno);
/*
* Write an error to `err` and return a nonzero value iff the same
@@ -229,20 +229,6 @@ const char *find_descendant_ref(const char *dirname,
const struct string_list *extras,
const struct string_list *skip);
-/*
- * Check whether an attempt to rename old_refname to new_refname would
- * cause a D/F conflict with any existing reference (other than
- * possibly old_refname). If there would be a conflict, emit an error
- * message and return false; otherwise, return true.
- *
- * Note that this function is not safe against all races with other
- * processes (though rename_ref() catches some races that might get by
- * this check).
- */
-int refs_rename_ref_available(struct ref_store *refs,
- const char *old_refname,
- const char *new_refname);
-
/* We allow "recursive" symbolic refs. Only within reason, though */
#define SYMREF_MAXDEPTH 5
@@ -606,7 +592,7 @@ typedef int for_each_reflog_ent_reverse_fn(struct ref_store *ref_store,
void *cb_data);
typedef int reflog_exists_fn(struct ref_store *ref_store, const char *refname);
typedef int create_reflog_fn(struct ref_store *ref_store, const char *refname,
- int force_create, struct strbuf *err);
+ struct strbuf *err);
typedef int delete_reflog_fn(struct ref_store *ref_store, const char *refname);
typedef int reflog_expire_fn(struct ref_store *ref_store,
const char *refname,
@@ -713,10 +699,12 @@ struct ref_store {
};
/*
- * Parse contents of a loose ref file.
+ * Parse contents of a loose ref file. *failure_errno maybe be set to EINVAL for
+ * invalid contents.
*/
int parse_loose_ref_contents(const char *buf, struct object_id *oid,
- struct strbuf *referent, unsigned int *type);
+ struct strbuf *referent, unsigned int *type,
+ int *failure_errno);
/*
* Fill in the generic part of refs and add it to our collection of
diff --git a/remote.c b/remote.c
index f958543d70..a6d8ec6c1a 100644
--- a/remote.c
+++ b/remote.c
@@ -21,33 +21,6 @@ struct counted_string {
size_t len;
const char *s;
};
-struct rewrite {
- const char *base;
- size_t baselen;
- struct counted_string *instead_of;
- int instead_of_nr;
- int instead_of_alloc;
-};
-struct rewrites {
- struct rewrite **rewrite;
- int rewrite_alloc;
- int rewrite_nr;
-};
-
-static struct remote **remotes;
-static int remotes_alloc;
-static int remotes_nr;
-static struct hashmap remotes_hash;
-
-static struct branch **branches;
-static int branches_alloc;
-static int branches_nr;
-
-static struct branch *current_branch;
-static const char *pushremote_name;
-
-static struct rewrites rewrites;
-static struct rewrites rewrites_push;
static int valid_remote(const struct remote *remote)
{
@@ -92,17 +65,19 @@ static void add_pushurl(struct remote *remote, const char *pushurl)
remote->pushurl[remote->pushurl_nr++] = pushurl;
}
-static void add_pushurl_alias(struct remote *remote, const char *url)
+static void add_pushurl_alias(struct remote_state *remote_state,
+ struct remote *remote, const char *url)
{
- const char *pushurl = alias_url(url, &rewrites_push);
+ const char *pushurl = alias_url(url, &remote_state->rewrites_push);
if (pushurl != url)
add_pushurl(remote, pushurl);
}
-static void add_url_alias(struct remote *remote, const char *url)
+static void add_url_alias(struct remote_state *remote_state,
+ struct remote *remote, const char *url)
{
- add_url(remote, alias_url(url, &rewrites));
- add_pushurl_alias(remote, url);
+ add_url(remote, alias_url(url, &remote_state->rewrites));
+ add_pushurl_alias(remote_state, remote, url);
}
struct remotes_hash_key {
@@ -127,13 +102,8 @@ static int remotes_hash_cmp(const void *unused_cmp_data,
return strcmp(a->name, b->name);
}
-static inline void init_remotes_hash(void)
-{
- if (!remotes_hash.cmpfn)
- hashmap_init(&remotes_hash, remotes_hash_cmp, NULL, 0);
-}
-
-static struct remote *make_remote(const char *name, int len)
+static struct remote *make_remote(struct remote_state *remote_state,
+ const char *name, int len)
{
struct remote *ret;
struct remotes_hash_key lookup;
@@ -142,12 +112,11 @@ static struct remote *make_remote(const char *name, int len)
if (!len)
len = strlen(name);
- init_remotes_hash();
lookup.str = name;
lookup.len = len;
hashmap_entry_init(&lookup_entry, memhash(name, len));
- e = hashmap_get(&remotes_hash, &lookup_entry, &lookup);
+ e = hashmap_get(&remote_state->remotes_hash, &lookup_entry, &lookup);
if (e)
return container_of(e, struct remote, ent);
@@ -158,15 +127,38 @@ static struct remote *make_remote(const char *name, int len)
refspec_init(&ret->push, REFSPEC_PUSH);
refspec_init(&ret->fetch, REFSPEC_FETCH);
- ALLOC_GROW(remotes, remotes_nr + 1, remotes_alloc);
- remotes[remotes_nr++] = ret;
+ ALLOC_GROW(remote_state->remotes, remote_state->remotes_nr + 1,
+ remote_state->remotes_alloc);
+ remote_state->remotes[remote_state->remotes_nr++] = ret;
hashmap_entry_init(&ret->ent, lookup_entry.hash);
- if (hashmap_put_entry(&remotes_hash, ret, ent))
+ if (hashmap_put_entry(&remote_state->remotes_hash, ret, ent))
BUG("hashmap_put overwrote entry after hashmap_get returned NULL");
return ret;
}
+static void remote_clear(struct remote *remote)
+{
+ int i;
+
+ free((char *)remote->name);
+ free((char *)remote->foreign_vcs);
+
+ for (i = 0; i < remote->url_nr; i++) {
+ free((char *)remote->url[i]);
+ }
+ FREE_AND_NULL(remote->pushurl);
+
+ for (i = 0; i < remote->pushurl_nr; i++) {
+ free((char *)remote->pushurl[i]);
+ }
+ FREE_AND_NULL(remote->pushurl);
+ free((char *)remote->receivepack);
+ free((char *)remote->uploadpack);
+ FREE_AND_NULL(remote->http_proxy);
+ FREE_AND_NULL(remote->http_proxy_authmethod);
+}
+
static void add_merge(struct branch *branch, const char *name)
{
ALLOC_GROW(branch->merge_name, branch->merge_nr + 1,
@@ -174,23 +166,74 @@ static void add_merge(struct branch *branch, const char *name)
branch->merge_name[branch->merge_nr++] = name;
}
-static struct branch *make_branch(const char *name, size_t len)
+struct branches_hash_key {
+ const char *str;
+ int len;
+};
+
+static int branches_hash_cmp(const void *unused_cmp_data,
+ const struct hashmap_entry *eptr,
+ const struct hashmap_entry *entry_or_key,
+ const void *keydata)
+{
+ const struct branch *a, *b;
+ const struct branches_hash_key *key = keydata;
+
+ a = container_of(eptr, const struct branch, ent);
+ b = container_of(entry_or_key, const struct branch, ent);
+
+ if (key)
+ return strncmp(a->name, key->str, key->len) ||
+ a->name[key->len];
+ else
+ return strcmp(a->name, b->name);
+}
+
+static struct branch *find_branch(struct remote_state *remote_state,
+ const char *name, size_t len)
+{
+ struct branches_hash_key lookup;
+ struct hashmap_entry lookup_entry, *e;
+
+ if (!len)
+ len = strlen(name);
+
+ lookup.str = name;
+ lookup.len = len;
+ hashmap_entry_init(&lookup_entry, memhash(name, len));
+
+ e = hashmap_get(&remote_state->branches_hash, &lookup_entry, &lookup);
+ if (e)
+ return container_of(e, struct branch, ent);
+
+ return NULL;
+}
+
+static void die_on_missing_branch(struct repository *repo,
+ struct branch *branch)
+{
+ /* branch == NULL is always valid because it represents detached HEAD. */
+ if (branch &&
+ branch != find_branch(repo->remote_state, branch->name, 0))
+ die("branch %s was not found in the repository", branch->name);
+}
+
+static struct branch *make_branch(struct remote_state *remote_state,
+ const char *name, size_t len)
{
struct branch *ret;
- int i;
- for (i = 0; i < branches_nr; i++) {
- if (!strncmp(name, branches[i]->name, len) &&
- !branches[i]->name[len])
- return branches[i];
- }
+ ret = find_branch(remote_state, name, len);
+ if (ret)
+ return ret;
- ALLOC_GROW(branches, branches_nr + 1, branches_alloc);
CALLOC_ARRAY(ret, 1);
- branches[branches_nr++] = ret;
ret->name = xstrndup(name, len);
ret->refname = xstrfmt("refs/heads/%s", ret->name);
+ hashmap_entry_init(&ret->ent, memhash(name, len));
+ if (hashmap_put_entry(&remote_state->branches_hash, ret, ent))
+ BUG("hashmap_put overwrote entry after hashmap_get returned NULL");
return ret;
}
@@ -229,7 +272,8 @@ static const char *skip_spaces(const char *s)
return s;
}
-static void read_remotes_file(struct remote *remote)
+static void read_remotes_file(struct remote_state *remote_state,
+ struct remote *remote)
{
struct strbuf buf = STRBUF_INIT;
FILE *f = fopen_or_warn(git_path("remotes/%s", remote->name), "r");
@@ -244,7 +288,8 @@ static void read_remotes_file(struct remote *remote)
strbuf_rtrim(&buf);
if (skip_prefix(buf.buf, "URL:", &v))
- add_url_alias(remote, xstrdup(skip_spaces(v)));
+ add_url_alias(remote_state, remote,
+ xstrdup(skip_spaces(v)));
else if (skip_prefix(buf.buf, "Push:", &v))
refspec_append(&remote->push, skip_spaces(v));
else if (skip_prefix(buf.buf, "Pull:", &v))
@@ -254,7 +299,8 @@ static void read_remotes_file(struct remote *remote)
fclose(f);
}
-static void read_branches_file(struct remote *remote)
+static void read_branches_file(struct remote_state *remote_state,
+ struct remote *remote)
{
char *frag;
struct strbuf buf = STRBUF_INIT;
@@ -286,7 +332,7 @@ static void read_branches_file(struct remote *remote)
else
frag = (char *)git_default_branch_name(0);
- add_url_alias(remote, strbuf_detach(&buf, NULL));
+ add_url_alias(remote_state, remote, strbuf_detach(&buf, NULL));
refspec_appendf(&remote->fetch, "refs/heads/%s:refs/heads/%s",
frag, remote->name);
@@ -305,10 +351,12 @@ static int handle_config(const char *key, const char *value, void *cb)
const char *subkey;
struct remote *remote;
struct branch *branch;
+ struct remote_state *remote_state = cb;
+
if (parse_config_key(key, "branch", &name, &namelen, &subkey) >= 0) {
if (!name)
return 0;
- branch = make_branch(name, namelen);
+ branch = make_branch(remote_state, name, namelen);
if (!strcmp(subkey, "remote")) {
return git_config_string(&branch->remote_name, key, value);
} else if (!strcmp(subkey, "pushremote")) {
@@ -327,12 +375,14 @@ static int handle_config(const char *key, const char *value, void *cb)
if (!strcmp(subkey, "insteadof")) {
if (!value)
return config_error_nonbool(key);
- rewrite = make_rewrite(&rewrites, name, namelen);
+ rewrite = make_rewrite(&remote_state->rewrites, name,
+ namelen);
add_instead_of(rewrite, xstrdup(value));
} else if (!strcmp(subkey, "pushinsteadof")) {
if (!value)
return config_error_nonbool(key);
- rewrite = make_rewrite(&rewrites_push, name, namelen);
+ rewrite = make_rewrite(&remote_state->rewrites_push,
+ name, namelen);
add_instead_of(rewrite, xstrdup(value));
}
}
@@ -342,7 +392,8 @@ static int handle_config(const char *key, const char *value, void *cb)
/* Handle remote.* variables */
if (!name && !strcmp(subkey, "pushdefault"))
- return git_config_string(&pushremote_name, key, value);
+ return git_config_string(&remote_state->pushremote_name, key,
+ value);
if (!name)
return 0;
@@ -352,7 +403,7 @@ static int handle_config(const char *key, const char *value, void *cb)
name);
return 0;
}
- remote = make_remote(name, namelen);
+ remote = make_remote(remote_state, name, namelen);
remote->origin = REMOTE_CONFIG;
if (current_config_scope() == CONFIG_SCOPE_LOCAL ||
current_config_scope() == CONFIG_SCOPE_WORKTREE)
@@ -422,44 +473,52 @@ static int handle_config(const char *key, const char *value, void *cb)
return 0;
}
-static void alias_all_urls(void)
+static void alias_all_urls(struct remote_state *remote_state)
{
int i, j;
- for (i = 0; i < remotes_nr; i++) {
+ for (i = 0; i < remote_state->remotes_nr; i++) {
int add_pushurl_aliases;
- if (!remotes[i])
+ if (!remote_state->remotes[i])
continue;
- for (j = 0; j < remotes[i]->pushurl_nr; j++) {
- remotes[i]->pushurl[j] = alias_url(remotes[i]->pushurl[j], &rewrites);
+ for (j = 0; j < remote_state->remotes[i]->pushurl_nr; j++) {
+ remote_state->remotes[i]->pushurl[j] =
+ alias_url(remote_state->remotes[i]->pushurl[j],
+ &remote_state->rewrites);
}
- add_pushurl_aliases = remotes[i]->pushurl_nr == 0;
- for (j = 0; j < remotes[i]->url_nr; j++) {
+ add_pushurl_aliases = remote_state->remotes[i]->pushurl_nr == 0;
+ for (j = 0; j < remote_state->remotes[i]->url_nr; j++) {
if (add_pushurl_aliases)
- add_pushurl_alias(remotes[i], remotes[i]->url[j]);
- remotes[i]->url[j] = alias_url(remotes[i]->url[j], &rewrites);
+ add_pushurl_alias(
+ remote_state, remote_state->remotes[i],
+ remote_state->remotes[i]->url[j]);
+ remote_state->remotes[i]->url[j] =
+ alias_url(remote_state->remotes[i]->url[j],
+ &remote_state->rewrites);
}
}
}
-static void read_config(void)
+static void read_config(struct repository *repo)
{
- static int loaded;
int flag;
- if (loaded)
+ if (repo->remote_state->initialized)
return;
- loaded = 1;
+ repo->remote_state->initialized = 1;
- current_branch = NULL;
+ repo->remote_state->current_branch = NULL;
if (startup_info->have_repository) {
- const char *head_ref = resolve_ref_unsafe("HEAD", 0, NULL, &flag);
+ int ignore_errno;
+ const char *head_ref = refs_resolve_ref_unsafe(
+ get_main_ref_store(repo), "HEAD", 0, NULL, &flag, &ignore_errno);
if (head_ref && (flag & REF_ISSYMREF) &&
skip_prefix(head_ref, "refs/heads/", &head_ref)) {
- current_branch = make_branch(head_ref, strlen(head_ref));
+ repo->remote_state->current_branch = make_branch(
+ repo->remote_state, head_ref, strlen(head_ref));
}
}
- git_config(handle_config, NULL);
- alias_all_urls();
+ repo_config(repo, handle_config, repo->remote_state);
+ alias_all_urls(repo->remote_state);
}
static int valid_remote_nick(const char *name)
@@ -474,7 +533,9 @@ static int valid_remote_nick(const char *name)
return 1;
}
-const char *remote_for_branch(struct branch *branch, int *explicit)
+static const char *remotes_remote_for_branch(struct remote_state *remote_state,
+ struct branch *branch,
+ int *explicit)
{
if (branch && branch->remote_name) {
if (explicit)
@@ -486,32 +547,61 @@ const char *remote_for_branch(struct branch *branch, int *explicit)
return "origin";
}
-const char *pushremote_for_branch(struct branch *branch, int *explicit)
+const char *remote_for_branch(struct branch *branch, int *explicit)
+{
+ read_config(the_repository);
+ die_on_missing_branch(the_repository, branch);
+
+ return remotes_remote_for_branch(the_repository->remote_state, branch,
+ explicit);
+}
+
+static const char *
+remotes_pushremote_for_branch(struct remote_state *remote_state,
+ struct branch *branch, int *explicit)
{
if (branch && branch->pushremote_name) {
if (explicit)
*explicit = 1;
return branch->pushremote_name;
}
- if (pushremote_name) {
+ if (remote_state->pushremote_name) {
if (explicit)
*explicit = 1;
- return pushremote_name;
+ return remote_state->pushremote_name;
}
- return remote_for_branch(branch, explicit);
+ return remotes_remote_for_branch(remote_state, branch, explicit);
+}
+
+const char *pushremote_for_branch(struct branch *branch, int *explicit)
+{
+ read_config(the_repository);
+ die_on_missing_branch(the_repository, branch);
+
+ return remotes_pushremote_for_branch(the_repository->remote_state,
+ branch, explicit);
}
+static struct remote *remotes_remote_get(struct remote_state *remote_state,
+ const char *name);
+
const char *remote_ref_for_branch(struct branch *branch, int for_push)
{
+ read_config(the_repository);
+ die_on_missing_branch(the_repository, branch);
+
if (branch) {
if (!for_push) {
if (branch->merge_nr) {
return branch->merge_name[0];
}
} else {
- const char *dst, *remote_name =
- pushremote_for_branch(branch, NULL);
- struct remote *remote = remote_get(remote_name);
+ const char *dst,
+ *remote_name = remotes_pushremote_for_branch(
+ the_repository->remote_state, branch,
+ NULL);
+ struct remote *remote = remotes_remote_get(
+ the_repository->remote_state, remote_name);
if (remote && remote->push.nr &&
(dst = apply_refspecs(&remote->push,
@@ -523,41 +613,58 @@ const char *remote_ref_for_branch(struct branch *branch, int for_push)
return NULL;
}
-static struct remote *remote_get_1(const char *name,
- const char *(*get_default)(struct branch *, int *))
+static struct remote *
+remotes_remote_get_1(struct remote_state *remote_state, const char *name,
+ const char *(*get_default)(struct remote_state *,
+ struct branch *, int *))
{
struct remote *ret;
int name_given = 0;
- read_config();
-
if (name)
name_given = 1;
else
- name = get_default(current_branch, &name_given);
+ name = get_default(remote_state, remote_state->current_branch,
+ &name_given);
- ret = make_remote(name, 0);
+ ret = make_remote(remote_state, name, 0);
if (valid_remote_nick(name) && have_git_dir()) {
if (!valid_remote(ret))
- read_remotes_file(ret);
+ read_remotes_file(remote_state, ret);
if (!valid_remote(ret))
- read_branches_file(ret);
+ read_branches_file(remote_state, ret);
}
if (name_given && !valid_remote(ret))
- add_url_alias(ret, name);
+ add_url_alias(remote_state, ret, name);
if (!valid_remote(ret))
return NULL;
return ret;
}
+static inline struct remote *
+remotes_remote_get(struct remote_state *remote_state, const char *name)
+{
+ return remotes_remote_get_1(remote_state, name,
+ remotes_remote_for_branch);
+}
+
struct remote *remote_get(const char *name)
{
- return remote_get_1(name, remote_for_branch);
+ read_config(the_repository);
+ return remotes_remote_get(the_repository->remote_state, name);
+}
+
+static inline struct remote *
+remotes_pushremote_get(struct remote_state *remote_state, const char *name)
+{
+ return remotes_remote_get_1(remote_state, name,
+ remotes_pushremote_for_branch);
}
struct remote *pushremote_get(const char *name)
{
- return remote_get_1(name, pushremote_for_branch);
+ read_config(the_repository);
+ return remotes_pushremote_get(the_repository->remote_state, name);
}
int remote_is_configured(struct remote *remote, int in_repo)
@@ -572,12 +679,14 @@ int remote_is_configured(struct remote *remote, int in_repo)
int for_each_remote(each_remote_fn fn, void *priv)
{
int i, result = 0;
- read_config();
- for (i = 0; i < remotes_nr && !result; i++) {
- struct remote *r = remotes[i];
- if (!r)
+ read_config(the_repository);
+ for (i = 0; i < the_repository->remote_state->remotes_nr && !result;
+ i++) {
+ struct remote *remote =
+ the_repository->remote_state->remotes[i];
+ if (!remote)
continue;
- result = fn(r, priv);
+ result = fn(remote, priv);
}
return result;
}
@@ -1642,7 +1751,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
}
}
-static void set_merge(struct branch *ret)
+static void set_merge(struct remote_state *remote_state, struct branch *ret)
{
struct remote *remote;
char *ref;
@@ -1662,7 +1771,7 @@ static void set_merge(struct branch *ret)
return;
}
- remote = remote_get(ret->remote_name);
+ remote = remotes_remote_get(remote_state, ret->remote_name);
CALLOC_ARRAY(ret->merge, ret->merge_nr);
for (i = 0; i < ret->merge_nr; i++) {
@@ -1683,12 +1792,13 @@ struct branch *branch_get(const char *name)
{
struct branch *ret;
- read_config();
+ read_config(the_repository);
if (!name || !*name || !strcmp(name, "HEAD"))
- ret = current_branch;
+ ret = the_repository->remote_state->current_branch;
else
- ret = make_branch(name, strlen(name));
- set_merge(ret);
+ ret = make_branch(the_repository->remote_state, name,
+ strlen(name));
+ set_merge(the_repository->remote_state, ret);
return ret;
}
@@ -1759,11 +1869,14 @@ static const char *tracking_for_push_dest(struct remote *remote,
return ret;
}
-static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
+static const char *branch_get_push_1(struct remote_state *remote_state,
+ struct branch *branch, struct strbuf *err)
{
struct remote *remote;
- remote = remote_get(pushremote_for_branch(branch, NULL));
+ remote = remotes_remote_get(
+ remote_state,
+ remotes_pushremote_for_branch(remote_state, branch, NULL));
if (!remote)
return error_buf(err,
_("branch '%s' has no remote for pushing"),
@@ -1821,11 +1934,15 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
const char *branch_get_push(struct branch *branch, struct strbuf *err)
{
+ read_config(the_repository);
+ die_on_missing_branch(the_repository, branch);
+
if (!branch)
return error_buf(err, _("HEAD does not point to a branch"));
if (!branch->push_tracking_ref)
- branch->push_tracking_ref = branch_get_push_1(branch, err);
+ branch->push_tracking_ref = branch_get_push_1(
+ the_repository->remote_state, branch, err);
return branch->push_tracking_ref;
}
@@ -2585,3 +2702,29 @@ void apply_push_cas(struct push_cas_option *cas,
check_if_includes_upstream(ref);
}
}
+
+struct remote_state *remote_state_new(void)
+{
+ struct remote_state *r = xmalloc(sizeof(*r));
+
+ memset(r, 0, sizeof(*r));
+
+ hashmap_init(&r->remotes_hash, remotes_hash_cmp, NULL, 0);
+ hashmap_init(&r->branches_hash, branches_hash_cmp, NULL, 0);
+ return r;
+}
+
+void remote_state_clear(struct remote_state *remote_state)
+{
+ int i;
+
+ for (i = 0; i < remote_state->remotes_nr; i++) {
+ remote_clear(remote_state->remotes[i]);
+ }
+ FREE_AND_NULL(remote_state->remotes);
+ remote_state->remotes_alloc = 0;
+ remote_state->remotes_nr = 0;
+
+ hashmap_clear_and_free(&remote_state->remotes_hash, struct remote, ent);
+ hashmap_clear_and_free(&remote_state->branches_hash, struct remote, ent);
+}
diff --git a/remote.h b/remote.h
index 5a59198252..4a1209ae2c 100644
--- a/remote.h
+++ b/remote.h
@@ -23,6 +23,40 @@ enum {
REMOTE_BRANCHES
};
+struct rewrite {
+ const char *base;
+ size_t baselen;
+ struct counted_string *instead_of;
+ int instead_of_nr;
+ int instead_of_alloc;
+};
+
+struct rewrites {
+ struct rewrite **rewrite;
+ int rewrite_alloc;
+ int rewrite_nr;
+};
+
+struct remote_state {
+ struct remote **remotes;
+ int remotes_alloc;
+ int remotes_nr;
+ struct hashmap remotes_hash;
+
+ struct hashmap branches_hash;
+
+ struct branch *current_branch;
+ const char *pushremote_name;
+
+ struct rewrites rewrites;
+ struct rewrites rewrites_push;
+
+ int initialized;
+};
+
+void remote_state_clear(struct remote_state *remote_state);
+struct remote_state *remote_state_new(void);
+
struct remote {
struct hashmap_entry ent;
@@ -256,6 +290,7 @@ int remote_find_tracking(struct remote *remote, struct refspec_item *refspec);
* branch_get(name) for "refs/heads/{name}", or with branch_get(NULL) for HEAD.
*/
struct branch {
+ struct hashmap_entry ent;
/* The short name of the branch. */
const char *name;
diff --git a/repository.c b/repository.c
index c5b90ba93e..c7ea706c20 100644
--- a/repository.c
+++ b/repository.c
@@ -9,6 +9,7 @@
#include "config.h"
#include "object.h"
#include "lockfile.h"
+#include "remote.h"
#include "submodule-config.h"
#include "sparse-index.h"
#include "promisor-remote.h"
@@ -24,6 +25,7 @@ void initialize_the_repository(void)
the_repo.index = &the_index;
the_repo.objects = raw_object_store_new();
+ the_repo.remote_state = remote_state_new();
the_repo.parsed_objects = parsed_object_pool_new();
repo_set_hash_algo(&the_repo, GIT_HASH_SHA1);
@@ -164,6 +166,7 @@ int repo_init(struct repository *repo,
repo->objects = raw_object_store_new();
repo->parsed_objects = parsed_object_pool_new();
+ repo->remote_state = remote_state_new();
if (repo_init_gitdir(repo, gitdir))
goto error;
@@ -270,6 +273,11 @@ void repo_clear(struct repository *repo)
promisor_remote_clear(repo->promisor_remote_config);
FREE_AND_NULL(repo->promisor_remote_config);
}
+
+ if (repo->remote_state) {
+ remote_state_clear(repo->remote_state);
+ FREE_AND_NULL(repo->remote_state);
+ }
}
int repo_read_index(struct repository *repo)
diff --git a/repository.h b/repository.h
index a057653981..98f9583470 100644
--- a/repository.h
+++ b/repository.h
@@ -11,6 +11,7 @@ struct pathspec;
struct raw_object_store;
struct submodule_cache;
struct promisor_remote_config;
+struct remote_state;
enum untracked_cache_setting {
UNTRACKED_CACHE_KEEP,
@@ -127,6 +128,9 @@ struct repository {
*/
struct index_state *index;
+ /* Repository's remotes and associated structures. */
+ struct remote_state *remote_state;
+
/* Repository's current hash algorithm, as serialized on disk. */
const struct git_hash_algo *hash_algo;
diff --git a/run-command.c b/run-command.c
index f40df01c77..1f58c17b6c 100644
--- a/run-command.c
+++ b/run-command.c
@@ -552,20 +552,17 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)
while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
; /* nothing */
- if (in_signal) {
- if (WIFEXITED(status))
- code = WEXITSTATUS(status);
- return code;
- }
if (waiting < 0) {
failed_errno = errno;
- error_errno("waitpid for %s failed", argv0);
+ if (!in_signal)
+ error_errno("waitpid for %s failed", argv0);
} else if (waiting != pid) {
- error("waitpid is confused (%s)", argv0);
+ if (!in_signal)
+ error("waitpid is confused (%s)", argv0);
} else if (WIFSIGNALED(status)) {
code = WTERMSIG(status);
- if (code != SIGINT && code != SIGQUIT && code != SIGPIPE)
+ if (!in_signal && code != SIGINT && code != SIGQUIT && code != SIGPIPE)
error("%s died of signal %d", argv0, code);
/*
* This return value is chosen so that code & 0xff
@@ -576,10 +573,12 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)
} else if (WIFEXITED(status)) {
code = WEXITSTATUS(status);
} else {
- error("waitpid is confused (%s)", argv0);
+ if (!in_signal)
+ error("waitpid is confused (%s)", argv0);
}
- clear_child_for_cleanup(pid);
+ if (!in_signal)
+ clear_child_for_cleanup(pid);
errno = failed_errno;
return code;
diff --git a/sequencer.c b/sequencer.c
index ea96837cde..b4135a78c9 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1284,6 +1284,8 @@ void print_commit_summary(struct repository *r,
struct pretty_print_context pctx = {0};
struct strbuf author_ident = STRBUF_INIT;
struct strbuf committer_ident = STRBUF_INIT;
+ struct ref_store *refs;
+ int resolve_errno;
commit = lookup_commit(r, oid);
if (!commit)
@@ -1333,9 +1335,13 @@ void print_commit_summary(struct repository *r,
rev.diffopt.break_opt = 0;
diff_setup_done(&rev.diffopt);
- head = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
- if (!head)
+ refs = get_main_ref_store(the_repository);
+ head = refs_resolve_ref_unsafe(refs, "HEAD", 0, NULL, NULL,
+ &resolve_errno);
+ if (!head) {
+ errno = resolve_errno;
die_errno(_("unable to resolve HEAD after creating commit"));
+ }
if (!strcmp(head, "HEAD"))
head = _("detached HEAD");
else
diff --git a/sparse-index.c b/sparse-index.c
index 7b7ff79e04..a1d505d50e 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -122,17 +122,17 @@ static int index_has_unmerged_entries(struct index_state *istate)
return 0;
}
-int convert_to_sparse(struct index_state *istate, int flags)
+static int is_sparse_index_allowed(struct index_state *istate, int flags)
{
- int test_env;
- if (istate->sparse_index || !istate->cache_nr ||
- !core_apply_sparse_checkout || !core_sparse_checkout_cone)
+ if (!core_apply_sparse_checkout || !core_sparse_checkout_cone)
return 0;
if (!istate->repo)
istate->repo = the_repository;
if (!(flags & SPARSE_INDEX_MEMORY_ONLY)) {
+ int test_env;
+
/*
* The sparse index is not (yet) integrated with a split index.
*/
@@ -168,25 +168,41 @@ int convert_to_sparse(struct index_state *istate, int flags)
if (!istate->sparse_checkout_patterns->use_cone_patterns)
return 0;
+ return 1;
+}
+
+int convert_to_sparse(struct index_state *istate, int flags)
+{
/*
- * NEEDSWORK: If we have unmerged entries, then stay full.
- * Unmerged entries prevent the cache-tree extension from working.
+ * If the index is already sparse, empty, or otherwise
+ * cannot be converted to sparse, do not convert.
*/
- if (index_has_unmerged_entries(istate))
+ if (istate->sparse_index || !istate->cache_nr ||
+ !is_sparse_index_allowed(istate, flags))
return 0;
- /* Clear and recompute the cache-tree */
- cache_tree_free(&istate->cache_tree);
/*
- * Silently return if there is a problem with the cache tree update,
- * which might just be due to a conflict state in some entry.
- *
- * This might create new tree objects, so be sure to use
- * WRITE_TREE_MISSING_OK.
+ * NEEDSWORK: If we have unmerged entries, then stay full.
+ * Unmerged entries prevent the cache-tree extension from working.
*/
- if (cache_tree_update(istate, WRITE_TREE_MISSING_OK))
+ if (index_has_unmerged_entries(istate))
return 0;
+ if (!cache_tree_fully_valid(istate->cache_tree)) {
+ /* Clear and recompute the cache-tree */
+ cache_tree_free(&istate->cache_tree);
+
+ /*
+ * Silently return if there is a problem with the cache tree update,
+ * which might just be due to a conflict state in some entry.
+ *
+ * This might create new tree objects, so be sure to use
+ * WRITE_TREE_MISSING_OK.
+ */
+ if (cache_tree_update(istate, WRITE_TREE_MISSING_OK))
+ return 0;
+ }
+
remove_fsmonitor(istate);
trace2_region_enter("index", "convert_to_sparse", istate->repo);
@@ -313,6 +329,18 @@ void ensure_full_index(struct index_state *istate)
trace2_region_leave("index", "ensure_full_index", istate->repo);
}
+void ensure_correct_sparsity(struct index_state *istate)
+{
+ /*
+ * If the index can be sparse, make it sparse. Otherwise,
+ * ensure the index is full.
+ */
+ if (is_sparse_index_allowed(istate, 0))
+ convert_to_sparse(istate, 0);
+ else
+ ensure_full_index(istate);
+}
+
/*
* This static global helps avoid infinite recursion between
* expand_to_path() and index_file_exists().
diff --git a/sparse-index.h b/sparse-index.h
index 9f3d7bc7fa..656bd835b2 100644
--- a/sparse-index.h
+++ b/sparse-index.h
@@ -4,6 +4,7 @@
struct index_state;
#define SPARSE_INDEX_MEMORY_ONLY (1 << 0)
int convert_to_sparse(struct index_state *istate, int flags);
+void ensure_correct_sparsity(struct index_state *istate);
/*
* Some places in the codebase expect to search for a specific path.
diff --git a/strbuf.c b/strbuf.c
index b22e981655..613fee8c82 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1006,7 +1006,12 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
/*
* There is no portable way to pass timezone information to
- * strftime, so we handle %z and %Z here.
+ * strftime, so we handle %z and %Z here. Likewise '%s', because
+ * going back to an epoch time requires knowing the zone.
+ *
+ * Note that tz_offset is in the "[-+]HHMM" decimal form; this is what
+ * we want for %z, but the computation for %s has to convert to number
+ * of seconds.
*/
for (;;) {
const char *percent = strchrnul(fmt, '%');
@@ -1019,6 +1024,13 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
strbuf_addstr(&munged_fmt, "%%");
fmt++;
break;
+ case 's':
+ strbuf_addf(&munged_fmt, "%"PRItime,
+ (timestamp_t)tm_to_time_t(tm) -
+ 3600 * (tz_offset / 100) -
+ 60 * (tz_offset % 100));
+ fmt++;
+ break;
case 'z':
strbuf_addf(&munged_fmt, "%+05d", tz_offset);
fmt++;
diff --git a/t/helper/test-genzeros.c b/t/helper/test-genzeros.c
index 9532f5bac9..8ca988d621 100644
--- a/t/helper/test-genzeros.c
+++ b/t/helper/test-genzeros.c
@@ -3,18 +3,31 @@
int cmd__genzeros(int argc, const char **argv)
{
- long count;
+ /* static, so that it is NUL-initialized */
+ static const char zeros[256 * 1024];
+ intmax_t count;
+ ssize_t n;
if (argc > 2) {
fprintf(stderr, "usage: %s [<count>]\n", argv[0]);
return 1;
}
- count = argc > 1 ? strtol(argv[1], NULL, 0) : -1L;
+ count = argc > 1 ? strtoimax(argv[1], NULL, 0) : -1;
- while (count < 0 || count--) {
- if (putchar(0) == EOF)
+ /* Writing out individual NUL bytes is slow... */
+ while (count < 0)
+ if (write(1, zeros, ARRAY_SIZE(zeros)) < 0)
return -1;
+
+ while (count > 0) {
+ n = write(1, zeros, count < ARRAY_SIZE(zeros) ?
+ count : ARRAY_SIZE(zeros));
+
+ if (n < 0)
+ return -1;
+
+ count -= n;
}
return 0;
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index b52c174acc..0d9f08931a 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -39,8 +39,6 @@ int cmd__read_cache(int argc, const char **argv)
int table = 0, expand = 0;
initialize_the_repository();
- prepare_repo_settings(r);
- r->settings.command_requires_full_index = 0;
for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) {
if (skip_prefix(*argv, "--print-and-refresh=", &name))
@@ -56,6 +54,9 @@ int cmd__read_cache(int argc, const char **argv)
setup_git_directory();
git_config(git_default_config, NULL);
+ prepare_repo_settings(r);
+ r->settings.command_requires_full_index = 0;
+
for (i = 0; i < cnt; i++) {
repo_read_index(r);
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 9d6fa7a377..27072ba94d 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -55,9 +55,10 @@ static int read_midx_file(const char *object_dir, int show_objects)
printf("%s %"PRIu64"\t%s\n",
oid_to_hex(&oid), e.offset, e.p->pack_name);
}
- return 0;
}
+ close_midx(m);
+
return 0;
}
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index b314b81a45..73461c29d3 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -123,9 +123,10 @@ static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
int resolve_flags = arg_flags(*argv++, "resolve-flags");
int flags;
const char *ref;
+ int ignore_errno;
ref = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
- &oid, &flags);
+ &oid, &flags, &ignore_errno);
printf("%s %s 0x%x\n", oid_to_hex(&oid), ref ? ref : "(null)", flags);
return ref ? 0 : 1;
}
@@ -181,11 +182,10 @@ static int cmd_reflog_exists(struct ref_store *refs, const char **argv)
static int cmd_create_reflog(struct ref_store *refs, const char **argv)
{
const char *refname = notnull(*argv++, "refname");
- int force_create = arg_flags(*argv++, "force-create");
struct strbuf err = STRBUF_INIT;
int ret;
- ret = refs_create_reflog(refs, refname, force_create, &err);
+ ret = refs_create_reflog(refs, refname, &err);
if (err.len)
puts(err.buf);
return ret;
diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh
index 597626276f..bfd332120c 100755
--- a/t/perf/p2000-sparse-operations.sh
+++ b/t/perf/p2000-sparse-operations.sh
@@ -110,5 +110,8 @@ test_perf_on_all git add -A
test_perf_on_all git add .
test_perf_on_all git commit -a -m A
test_perf_on_all git checkout -f -
+test_perf_on_all git reset
+test_perf_on_all git reset --hard
+test_perf_on_all git reset -- does-not-exist
test_done
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
index 6b757d7169..794186961e 100755
--- a/t/t0006-date.sh
+++ b/t/t0006-date.sh
@@ -63,6 +63,10 @@ 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
+check_show 'format:%s' '123456789 +1234' 123456789
+check_show 'format:%s' '123456789 -1234' 123456789
+check_show 'format-local:%s' '123456789 -1234' 123456789
+
# 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/t0007-git-var.sh b/t/t0007-git-var.sh
index 53af92d571..e56f4b9ac5 100755
--- a/t/t0007-git-var.sh
+++ b/t/t0007-git-var.sh
@@ -27,6 +27,26 @@ test_expect_success !FAIL_PREREQS,!AUTOIDENT 'requested identities are strict' '
)
'
+test_expect_success 'get GIT_DEFAULT_BRANCH without configuration' '
+ (
+ sane_unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME &&
+ git init defbranch &&
+ git -C defbranch symbolic-ref --short HEAD >expect &&
+ git var GIT_DEFAULT_BRANCH >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'get GIT_DEFAULT_BRANCH with configuration' '
+ test_config init.defaultbranch foo &&
+ (
+ sane_unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME &&
+ echo foo >expect &&
+ git var GIT_DEFAULT_BRANCH >actual &&
+ test_cmp expect actual
+ )
+'
+
# For git var -l, we check only a representative variable;
# testing the whole output would make our test too brittle with
# respect to unrelated changes in the test suite's environment.
diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh
index f25ae8b5e1..4125ab8b88 100755
--- a/t/t0020-crlf.sh
+++ b/t/t0020-crlf.sh
@@ -5,6 +5,7 @@ test_description='CRLF conversion'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
has_cr() {
diff --git a/t/t0110-urlmatch-normalization.sh b/t/t0110-urlmatch-normalization.sh
index f99529d838..4dc9fecf72 100755
--- a/t/t0110-urlmatch-normalization.sh
+++ b/t/t0110-urlmatch-normalization.sh
@@ -47,7 +47,7 @@ test_expect_success 'url authority' '
test-tool urlmatch-normalization "scheme://@host" &&
test-tool urlmatch-normalization "scheme://%00@host" &&
! test-tool urlmatch-normalization "scheme://%%@host" &&
- ! test-tool urlmatch-normalization "scheme://host_" &&
+ test-tool urlmatch-normalization "scheme://host_" &&
test-tool urlmatch-normalization "scheme://user:pass@host/" &&
test-tool urlmatch-normalization "scheme://@host/" &&
test-tool urlmatch-normalization "scheme://host/" &&
diff --git a/t/t1005-read-tree-reset.sh b/t/t1005-read-tree-reset.sh
index 83b09e1310..12e30d77d0 100755
--- a/t/t1005-read-tree-reset.sh
+++ b/t/t1005-read-tree-reset.sh
@@ -2,6 +2,7 @@
test_description='read-tree -u --reset'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-read-tree.sh
diff --git a/t/t1008-read-tree-overlay.sh b/t/t1008-read-tree-overlay.sh
index 4512fb0b6e..ad5936e54d 100755
--- a/t/t1008-read-tree-overlay.sh
+++ b/t/t1008-read-tree-overlay.sh
@@ -5,6 +5,7 @@ test_description='test multi-tree read-tree without merging'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-read-tree.sh
diff --git a/t/t1051-large-conversion.sh b/t/t1051-large-conversion.sh
index 8b7640b3ba..042b0e4429 100755
--- a/t/t1051-large-conversion.sh
+++ b/t/t1051-large-conversion.sh
@@ -83,4 +83,30 @@ test_expect_success 'ident converts on output' '
test_cmp small.clean large.clean
'
+# This smudge filter prepends 5GB of zeros to the file it checks out. This
+# ensures that smudging doesn't mangle large files on 64-bit Windows.
+test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
+ 'files over 4GB convert on output' '
+ test_commit test small "a small file" &&
+ small_size=$(test_file_size small) &&
+ test_config filter.makelarge.smudge \
+ "test-tool genzeros $((5*1024*1024*1024)) && cat" &&
+ echo "small filter=makelarge" >.gitattributes &&
+ rm small &&
+ git checkout -- small &&
+ size=$(test_file_size small) &&
+ test "$size" -eq $((5 * 1024 * 1024 * 1024 + $small_size))
+'
+
+# This clean filter writes down the size of input it receives. By checking against
+# the actual size, we ensure that cleaning doesn't mangle large files on 64-bit Windows.
+test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
+ 'files over 4GB convert on input' '
+ test-tool genzeros $((5*1024*1024*1024)) >big &&
+ test_config filter.checklarge.clean "wc -c >big.size" &&
+ echo "big filter=checklarge" >.gitattributes &&
+ git add big &&
+ test $(test_file_size big) -eq $(cat big.size)
+'
+
test_done
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index 16fbd2c6db..0fe5b5f482 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -489,26 +489,118 @@ test_expect_failure 'blame with pathspec outside sparse definition' '
test_all_match git blame deep/deeper2/deepest/a
'
-# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
-# in this scenario, but it shouldn't.
-test_expect_failure 'checkout and reset (mixed)' '
+test_expect_success 'checkout and reset (mixed)' '
init_repos &&
test_all_match git checkout -b reset-test update-deep &&
test_all_match git reset deepest &&
- test_all_match git reset update-folder1 &&
- test_all_match git reset update-folder2
+
+ # Because skip-worktree is preserved, resetting to update-folder1
+ # will show worktree changes for folder1/a in full-checkout, but not
+ # in sparse-checkout or sparse-index.
+ git -C full-checkout reset update-folder1 >full-checkout-out &&
+ test_sparse_match git reset update-folder1 &&
+ grep "M folder1/a" full-checkout-out &&
+ ! grep "M folder1/a" sparse-checkout-out &&
+ run_on_sparse test_path_is_missing folder1
'
-# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
-# in this scenario, but it shouldn't.
-test_expect_success 'checkout and reset (mixed) [sparse]' '
+test_expect_success 'checkout and reset (merge)' '
init_repos &&
- test_sparse_match git checkout -b reset-test update-deep &&
- test_sparse_match git reset deepest &&
- test_sparse_match git reset update-folder1 &&
- test_sparse_match git reset update-folder2
+ write_script edit-contents <<-\EOF &&
+ echo text >>$1
+ EOF
+
+ test_all_match git checkout -b reset-test update-deep &&
+ run_on_all ../edit-contents a &&
+ test_all_match git reset --merge deepest &&
+ test_all_match git status --porcelain=v2 &&
+
+ test_all_match git reset --hard update-deep &&
+ run_on_all ../edit-contents deep/a &&
+ test_all_match test_must_fail git reset --merge deepest
+'
+
+test_expect_success 'checkout and reset (keep)' '
+ init_repos &&
+
+ write_script edit-contents <<-\EOF &&
+ echo text >>$1
+ EOF
+
+ test_all_match git checkout -b reset-test update-deep &&
+ run_on_all ../edit-contents a &&
+ test_all_match git reset --keep deepest &&
+ test_all_match git status --porcelain=v2 &&
+
+ test_all_match git reset --hard update-deep &&
+ run_on_all ../edit-contents deep/a &&
+ test_all_match test_must_fail git reset --keep deepest
+'
+
+test_expect_success 'reset with pathspecs inside sparse definition' '
+ init_repos &&
+
+ write_script edit-contents <<-\EOF &&
+ echo text >>$1
+ EOF
+
+ test_all_match git checkout -b reset-test update-deep &&
+ run_on_all ../edit-contents deep/a &&
+
+ test_all_match git reset base -- deep/a &&
+ test_all_match git status --porcelain=v2 &&
+
+ test_all_match git reset base -- nonexistent-file &&
+ test_all_match git status --porcelain=v2 &&
+
+ test_all_match git reset deepest -- deep &&
+ test_all_match git status --porcelain=v2
+'
+
+# Although the working tree differs between full and sparse checkouts after
+# reset, the state of the index is the same.
+test_expect_success 'reset with pathspecs outside sparse definition' '
+ init_repos &&
+ test_all_match git checkout -b reset-test base &&
+
+ test_sparse_match git reset update-folder1 -- folder1 &&
+ git -C full-checkout reset update-folder1 -- folder1 &&
+ test_sparse_match git status --porcelain=v2 &&
+ test_all_match git rev-parse HEAD:folder1 &&
+
+ test_sparse_match git reset update-folder2 -- folder2/a &&
+ git -C full-checkout reset update-folder2 -- folder2/a &&
+ test_sparse_match git status --porcelain=v2 &&
+ test_all_match git rev-parse HEAD:folder2/a
+'
+
+test_expect_success 'reset with wildcard pathspec' '
+ init_repos &&
+
+ test_all_match git reset update-deep -- deep\* &&
+ test_all_match git ls-files -s -- deep &&
+
+ test_all_match git reset deepest -- deep\*\*\* &&
+ test_all_match git ls-files -s -- deep &&
+
+ # The following `git reset`s result in updating the index on files with
+ # `skip-worktree` enabled. To avoid failing due to discrepencies in reported
+ # "modified" files, `test_sparse_match` reset is performed separately from
+ # "full-checkout" reset, then the index contents of all repos are verified.
+
+ test_sparse_match git reset update-folder1 -- \*/a &&
+ git -C full-checkout reset update-folder1 -- \*/a &&
+ test_all_match git ls-files -s -- deep/a folder1/a &&
+
+ test_sparse_match git reset update-folder2 -- folder\* &&
+ git -C full-checkout reset update-folder2 -- folder\* &&
+ test_all_match git ls-files -s -- folder10 folder1 folder2 &&
+
+ test_sparse_match git reset base -- folder1/\* &&
+ git -C full-checkout reset base -- folder1/\* &&
+ test_all_match git ls-files -s -- folder1
'
test_expect_success 'merge, cherry-pick, and rebase' '
@@ -685,15 +777,50 @@ test_expect_success 'submodule handling' '
grep "160000 commit $(git -C initial-repo rev-parse HEAD) modules/sub" cache
'
+# When working with a sparse index, some commands will need to expand the
+# index to operate properly. If those commands also write the index back
+# to disk, they need to convert the index to sparse before writing.
+# This test verifies that both of these events are logged in trace2 logs.
test_expect_success 'sparse-index is expanded and converted back' '
init_repos &&
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
- git -C sparse-index -c core.fsmonitor="" reset --hard &&
+ git -C sparse-index reset -- folder1/a &&
test_region index convert_to_sparse trace2.txt &&
test_region index ensure_full_index trace2.txt
'
+test_expect_success 'index.sparse disabled inline uses full index' '
+ init_repos &&
+
+ # When index.sparse is disabled inline with `git status`, the
+ # index is expanded at the beginning of the execution then never
+ # converted back to sparse. It is then written to disk as a full index.
+ rm -f trace2.txt &&
+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
+ git -C sparse-index -c index.sparse=false status &&
+ ! test_region index convert_to_sparse trace2.txt &&
+ test_region index ensure_full_index trace2.txt &&
+
+ # Since index.sparse is set to true at a repo level, the index
+ # is converted from full to sparse when read, then never expanded
+ # over the course of `git status`. It is written to disk as a sparse
+ # index.
+ rm -f trace2.txt &&
+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
+ git -C sparse-index status &&
+ test_region index convert_to_sparse trace2.txt &&
+ ! test_region index ensure_full_index trace2.txt &&
+
+ # Now that the index has been written to disk as sparse, it is not
+ # converted to sparse (or expanded to full) when read by `git status`.
+ rm -f trace2.txt &&
+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
+ git -C sparse-index status &&
+ ! test_region index convert_to_sparse trace2.txt &&
+ ! test_region index ensure_full_index trace2.txt
+'
+
ensure_not_expanded () {
rm -f trace2.txt &&
echo >>sparse-index/untracked.txt &&
@@ -726,9 +853,9 @@ test_expect_success 'sparse-index is not expanded' '
ensure_not_expanded checkout - &&
ensure_not_expanded switch rename-out-to-out &&
ensure_not_expanded switch - &&
- git -C sparse-index reset --hard &&
+ ensure_not_expanded reset --hard &&
ensure_not_expanded checkout rename-out-to-out -- deep/deeper1 &&
- git -C sparse-index reset --hard &&
+ ensure_not_expanded reset --hard &&
ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1 &&
echo >>sparse-index/README.md &&
@@ -738,6 +865,34 @@ test_expect_success 'sparse-index is not expanded' '
echo >>sparse-index/untracked.txt &&
ensure_not_expanded add . &&
+ for ref in update-deep update-folder1 update-folder2 update-deep
+ do
+ echo >>sparse-index/README.md &&
+ ensure_not_expanded reset --hard $ref || return 1
+ done &&
+
+ ensure_not_expanded reset --mixed base &&
+ ensure_not_expanded reset --hard update-deep &&
+ ensure_not_expanded reset --keep base &&
+ ensure_not_expanded reset --merge update-deep &&
+ ensure_not_expanded reset --hard &&
+
+ ensure_not_expanded reset base -- deep/a &&
+ ensure_not_expanded reset base -- nonexistent-file &&
+ ensure_not_expanded reset deepest -- deep &&
+
+ # Although folder1 is outside the sparse definition, it exists as a
+ # directory entry in the index, so the pathspec will not force the
+ # index to be expanded.
+ ensure_not_expanded reset deepest -- folder1 &&
+ ensure_not_expanded reset deepest -- folder1/ &&
+
+ # Wildcard identifies only in-cone files, no index expansion
+ ensure_not_expanded reset deepest -- deep/\* &&
+
+ # Wildcard identifies only full sparse directories, no index expansion
+ ensure_not_expanded reset deepest -- folder\* &&
+
ensure_not_expanded checkout -f update-deep &&
test_config -C sparse-index pull.twohead ort &&
(
diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh
index 17d3cc1405..4d261e80c6 100755
--- a/t/t1403-show-ref.sh
+++ b/t/t1403-show-ref.sh
@@ -4,6 +4,7 @@ test_description='show-ref'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '
diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh
index 49718b7ea7..c89cef2d26 100755
--- a/t/t1405-main-ref-store.sh
+++ b/t/t1405-main-ref-store.sh
@@ -108,7 +108,7 @@ test_expect_success 'delete_reflog(HEAD)' '
'
test_expect_success 'create-reflog(HEAD)' '
- $RUN create-reflog HEAD 1 &&
+ $RUN create-reflog HEAD &&
git reflog exists HEAD
'
diff --git a/t/t1406-submodule-ref-store.sh b/t/t1406-submodule-ref-store.sh
index 0a87058971..c95c5d47aa 100755
--- a/t/t1406-submodule-ref-store.sh
+++ b/t/t1406-submodule-ref-store.sh
@@ -5,6 +5,7 @@ test_description='test submodule ref store api'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
RUN="test-tool ref-store submodule:sub"
@@ -92,7 +93,7 @@ test_expect_success 'delete_reflog() not allowed' '
'
test_expect_success 'create-reflog() not allowed' '
- test_must_fail $RUN create-reflog HEAD 1
+ test_must_fail $RUN create-reflog HEAD
'
test_done
diff --git a/t/t1417-reflog-updateref.sh b/t/t1417-reflog-updateref.sh
new file mode 100755
index 0000000000..14f13b57c6
--- /dev/null
+++ b/t/t1417-reflog-updateref.sh
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+test_description='git reflog --updateref'
+
+TEST_PASSES_SANITIZE_LEAK=true
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ git init -b main repo &&
+ (
+ cd repo &&
+
+ test_commit A &&
+ test_commit B &&
+ test_commit C &&
+
+ cp .git/logs/HEAD HEAD.old &&
+ git reset --hard HEAD~ &&
+ cp HEAD.old .git/logs/HEAD
+ )
+'
+
+test_reflog_updateref () {
+ exp=$1
+ shift
+ args="$@"
+
+ test_expect_success REFFILES "get '$exp' with '$args'" '
+ test_when_finished "rm -rf copy" &&
+ cp -R repo copy &&
+
+ (
+ cd copy &&
+
+ $args &&
+ git rev-parse $exp >expect &&
+ git rev-parse HEAD >actual &&
+
+ test_cmp expect actual
+ )
+ '
+}
+
+test_reflog_updateref B git reflog delete --updateref HEAD@{0}
+test_reflog_updateref B git reflog delete --updateref HEAD@{1}
+test_reflog_updateref C git reflog delete --updateref main@{0}
+test_reflog_updateref B git reflog delete --updateref main@{1}
+test_reflog_updateref B git reflog delete --updateref --rewrite HEAD@{0}
+test_reflog_updateref B git reflog delete --updateref --rewrite HEAD@{1}
+test_reflog_updateref C git reflog delete --updateref --rewrite main@{0}
+test_reflog_updateref B git reflog delete --updateref --rewrite main@{1}
+test_reflog_updateref B test_must_fail git reflog expire HEAD@{0}
+test_reflog_updateref B test_must_fail git reflog expire HEAD@{1}
+test_reflog_updateref B test_must_fail git reflog expire main@{0}
+test_reflog_updateref B test_must_fail git reflog expire main@{1}
+test_reflog_updateref B test_must_fail git reflog expire --updateref HEAD@{0}
+test_reflog_updateref B test_must_fail git reflog expire --updateref HEAD@{1}
+test_reflog_updateref B test_must_fail git reflog expire --updateref main@{0}
+test_reflog_updateref B test_must_fail git reflog expire --updateref main@{1}
+test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite HEAD@{0}
+test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite HEAD@{1}
+test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite main@{0}
+test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite main@{1}
+
+test_done
diff --git a/t/t1505-rev-parse-last.sh b/t/t1505-rev-parse-last.sh
index 2803ca9489..4a5758f08a 100755
--- a/t/t1505-rev-parse-last.sh
+++ b/t/t1505-rev-parse-last.sh
@@ -5,6 +5,7 @@ test_description='test @{-N} syntax'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
diff --git a/t/t2007-checkout-symlink.sh b/t/t2007-checkout-symlink.sh
index 6f0b90ce12..bd9e9e7530 100755
--- a/t/t2007-checkout-symlink.sh
+++ b/t/t2007-checkout-symlink.sh
@@ -7,6 +7,7 @@ test_description='git checkout to switch between branches with symlink<->dir'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '
diff --git a/t/t2008-checkout-subdir.sh b/t/t2008-checkout-subdir.sh
index eadb9434ae..8a518a44ea 100755
--- a/t/t2008-checkout-subdir.sh
+++ b/t/t2008-checkout-subdir.sh
@@ -4,6 +4,7 @@
test_description='git checkout from subdirectories'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '
diff --git a/t/t2009-checkout-statinfo.sh b/t/t2009-checkout-statinfo.sh
index b0540636ae..71195dd28f 100755
--- a/t/t2009-checkout-statinfo.sh
+++ b/t/t2009-checkout-statinfo.sh
@@ -5,6 +5,7 @@ test_description='checkout should leave clean stat info'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t2010-checkout-ambiguous.sh b/t/t2010-checkout-ambiguous.sh
index 6e8757387d..9d4b37526a 100755
--- a/t/t2010-checkout-ambiguous.sh
+++ b/t/t2010-checkout-ambiguous.sh
@@ -5,6 +5,7 @@ test_description='checkout and pathspecs/refspecs ambiguities'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t2011-checkout-invalid-head.sh b/t/t2011-checkout-invalid-head.sh
index e52022e152..d9997e7b6b 100755
--- a/t/t2011-checkout-invalid-head.sh
+++ b/t/t2011-checkout-invalid-head.sh
@@ -5,6 +5,7 @@ test_description='checkout switching away from an invalid branch'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t2014-checkout-switch.sh b/t/t2014-checkout-switch.sh
index ccfb147113..c138bdde4f 100755
--- a/t/t2014-checkout-switch.sh
+++ b/t/t2014-checkout-switch.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='Peter MacMillan'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '
diff --git a/t/t2017-checkout-orphan.sh b/t/t2017-checkout-orphan.sh
index 88d6992a5e..f3371e2646 100755
--- a/t/t2017-checkout-orphan.sh
+++ b/t/t2017-checkout-orphan.sh
@@ -10,6 +10,7 @@ Main Tests for --orphan functionality.'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
TEST_FILE=foo
diff --git a/t/t2019-checkout-ambiguous-ref.sh b/t/t2019-checkout-ambiguous-ref.sh
index b99d5192a9..2c8c926b4d 100755
--- a/t/t2019-checkout-ambiguous-ref.sh
+++ b/t/t2019-checkout-ambiguous-ref.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='checkout handling of ambiguous (branch/tag) refs'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup ambiguous refs' '
diff --git a/t/t2021-checkout-overwrite.sh b/t/t2021-checkout-overwrite.sh
index 660132ff8d..713c3fa603 100755
--- a/t/t2021-checkout-overwrite.sh
+++ b/t/t2021-checkout-overwrite.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='checkout must not overwrite an untracked objects'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t2022-checkout-paths.sh b/t/t2022-checkout-paths.sh
index c49ba7f9bd..f1b709d58b 100755
--- a/t/t2022-checkout-paths.sh
+++ b/t/t2022-checkout-paths.sh
@@ -4,6 +4,7 @@ test_description='checkout $tree -- $paths'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '
diff --git a/t/t2026-checkout-pathspec-file.sh b/t/t2026-checkout-pathspec-file.sh
index 43d31d7948..9db11f86dd 100755
--- a/t/t2026-checkout-pathspec-file.sh
+++ b/t/t2026-checkout-pathspec-file.sh
@@ -2,6 +2,7 @@
test_description='checkout --pathspec-from-file'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_tick
diff --git a/t/t2106-update-index-assume-unchanged.sh b/t/t2106-update-index-assume-unchanged.sh
index 2d450daf5c..d943ddf47e 100755
--- a/t/t2106-update-index-assume-unchanged.sh
+++ b/t/t2106-update-index-assume-unchanged.sh
@@ -3,6 +3,7 @@
test_description='git update-index --assume-unchanged test.
'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t3040-subprojects-basic.sh b/t/t3040-subprojects-basic.sh
index 6abdcbbc94..bd65dfcffc 100755
--- a/t/t3040-subprojects-basic.sh
+++ b/t/t3040-subprojects-basic.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='Basic subproject functionality'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup: create superproject' '
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index e575ffb4ff..8c5c1ccf33 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -731,6 +731,28 @@ test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for
test_must_fail git branch -m u v
'
+test_expect_success SYMLINKS 'git branch -m with symlinked .git/refs' '
+ test_when_finished "rm -rf subdir" &&
+ git init --bare subdir &&
+
+ rm -rfv subdir/refs subdir/objects subdir/packed-refs &&
+ ln -s ../.git/refs subdir/refs &&
+ ln -s ../.git/objects subdir/objects &&
+ ln -s ../.git/packed-refs subdir/packed-refs &&
+
+ git -C subdir rev-parse --absolute-git-dir >subdir.dir &&
+ git rev-parse --absolute-git-dir >our.dir &&
+ ! test_cmp subdir.dir our.dir &&
+
+ git -C subdir log &&
+ git -C subdir branch rename-src &&
+ git rev-parse rename-src >expect &&
+ git -C subdir branch -m rename-src rename-dest &&
+ git rev-parse rename-dest >actual &&
+ test_cmp expect actual &&
+ git branch -D rename-dest
+'
+
test_expect_success 'test tracking setup via --track' '
git config remote.local.url . &&
git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
@@ -1418,7 +1440,17 @@ test_expect_success 'invalid sort parameter in configuration' '
(
cd sort &&
git config branch.sort "v:notvalid" &&
- test_must_fail git branch
+
+ # this works in the "listing" mode, so bad sort key
+ # is a dying offence.
+ test_must_fail git branch &&
+
+ # these do not need to use sorting, and should all
+ # succeed
+ git branch newone main &&
+ git branch -c newone newerone &&
+ git branch -m newone newestone &&
+ git branch -d newerone newestone
)
'
diff --git a/t/t3305-notes-fanout.sh b/t/t3305-notes-fanout.sh
index 94c1b02251..960d0587e1 100755
--- a/t/t3305-notes-fanout.sh
+++ b/t/t3305-notes-fanout.sh
@@ -2,6 +2,7 @@
test_description='Test that adding/removing many notes triggers automatic fanout restructuring'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
path_has_fanout() {
diff --git a/t/t3422-rebase-incompatible-options.sh b/t/t3422-rebase-incompatible-options.sh
index eb0a3d9d48..6dabb05a2a 100755
--- a/t/t3422-rebase-incompatible-options.sh
+++ b/t/t3422-rebase-incompatible-options.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='test if rebase detects and aborts on incompatible options'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index f0a82be9de..2c66cfbc3b 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -288,6 +288,17 @@ test_expect_success 'stash --no-keep-index' '
test bar,bar2 = $(cat file),$(cat file2)
'
+test_expect_success 'stash --staged' '
+ echo bar3 >file &&
+ echo bar4 >file2 &&
+ git add file2 &&
+ git stash --staged &&
+ test bar3,bar2 = $(cat file),$(cat file2) &&
+ git reset --hard &&
+ git stash pop &&
+ test bar,bar4 = $(cat file),$(cat file2)
+'
+
test_expect_success 'dont assume push with non-option args' '
test_must_fail git stash -q drop 2>err &&
test_i18ngrep -e "subcommand wasn'\''t specified; '\''push'\'' can'\''t be assumed due to unexpected token '\''drop'\''" err
diff --git a/t/t4115-apply-symlink.sh b/t/t4115-apply-symlink.sh
index 872fcda6cb..d0f3edef54 100755
--- a/t/t4115-apply-symlink.sh
+++ b/t/t4115-apply-symlink.sh
@@ -7,6 +7,7 @@ test_description='git apply symlinks and partial files
'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '
diff --git a/t/t4121-apply-diffs.sh b/t/t4121-apply-diffs.sh
index b45454aaf4..a80cec9d11 100755
--- a/t/t4121-apply-diffs.sh
+++ b/t/t4121-apply-diffs.sh
@@ -4,6 +4,7 @@ test_description='git apply for contextually independent diffs'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
echo '1
diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh
index f120857c20..e78d8097f3 100755
--- a/t/t4204-patch-id.sh
+++ b/t/t4204-patch-id.sh
@@ -5,6 +5,7 @@ test_description='git patch-id'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh
index 3f69e43178..a612e44547 100755
--- a/t/t5319-multi-pack-index.sh
+++ b/t/t5319-multi-pack-index.sh
@@ -482,8 +482,10 @@ test_expect_success 'corrupt MIDX is not reused' '
'
test_expect_success 'verify incorrect checksum' '
- pos=$(($(wc -c <$objdir/pack/multi-pack-index) - 1)) &&
- corrupt_midx_and_verify $pos "\377" $objdir "incorrect checksum"
+ pos=$(($(wc -c <$objdir/pack/multi-pack-index) - 10)) &&
+ corrupt_midx_and_verify $pos \
+ "\377\377\377\377\377\377\377\377\377\377" \
+ $objdir "incorrect checksum"
'
test_expect_success 'repack progress off for redirected stderr' '
diff --git a/t/t5410-receive-pack-alternates.sh b/t/t5410-receive-pack-alternates.sh
index 0b28e4e452..7a45d4c311 100755
--- a/t/t5410-receive-pack-alternates.sh
+++ b/t/t5410-receive-pack-alternates.sh
@@ -5,6 +5,7 @@ test_description='git receive-pack with alternate ref filtering'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 8212ca56dc..7831a38dde 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -541,6 +541,15 @@ do
done
+test_expect_success "push to remote with no explicit refspec and config remote.*.push = src:dest" '
+ mk_test testrepo heads/main &&
+ git checkout $the_first_commit &&
+ test_config remote.there.url testrepo &&
+ test_config remote.there.push refs/heads/main:refs/heads/main &&
+ git push there &&
+ check_push_result testrepo $the_commit heads/main
+'
+
test_expect_success 'push with remote.pushdefault' '
mk_test up_repo heads/main &&
mk_test down_repo heads/main &&
diff --git a/t/t5609-clone-branch.sh b/t/t5609-clone-branch.sh
index f86a674a03..252e1f7c20 100755
--- a/t/t5609-clone-branch.sh
+++ b/t/t5609-clone-branch.sh
@@ -4,6 +4,7 @@ test_description='clone --branch option'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
check_HEAD() {
diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh
index d527cf6c49..78f85b0714 100755
--- a/t/t5702-protocol-v2.sh
+++ b/t/t5702-protocol-v2.sh
@@ -1107,6 +1107,57 @@ test_expect_success 'packfile-uri with transfer.fsckobjects fails when .gitmodul
test_i18ngrep "disallowed submodule name" err
'
+test_expect_success 'packfile-uri path redacted in trace' '
+ P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+ rm -rf "$P" http_child log &&
+
+ git init "$P" &&
+ git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+ echo my-blob >"$P/my-blob" &&
+ git -C "$P" add my-blob &&
+ git -C "$P" commit -m x &&
+
+ git -C "$P" hash-object my-blob >objh &&
+ git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
+ git -C "$P" config --add \
+ "uploadpack.blobpackfileuri" \
+ "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
+
+ GIT_TRACE_PACKET="$(pwd)/log" \
+ git -c protocol.version=2 \
+ -c fetch.uriprotocols=http,https \
+ clone "$HTTPD_URL/smart/http_parent" http_child &&
+
+ grep -F "clone< \\1$(cat packh) $HTTPD_URL/<redacted>" log
+'
+
+test_expect_success 'packfile-uri path not redacted in trace when GIT_TRACE_REDACT=0' '
+ P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+ rm -rf "$P" http_child log &&
+
+ git init "$P" &&
+ git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+ echo my-blob >"$P/my-blob" &&
+ git -C "$P" add my-blob &&
+ git -C "$P" commit -m x &&
+
+ git -C "$P" hash-object my-blob >objh &&
+ git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
+ git -C "$P" config --add \
+ "uploadpack.blobpackfileuri" \
+ "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
+
+ GIT_TRACE_PACKET="$(pwd)/log" \
+ GIT_TRACE_REDACT=0 \
+ git -c protocol.version=2 \
+ -c fetch.uriprotocols=http,https \
+ clone "$HTTPD_URL/smart/http_parent" http_child &&
+
+ grep -F "clone< \\1$(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" log
+'
+
test_expect_success 'http:// --negotiate-only' '
SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
URI="$HTTPD_URL/smart/server" &&
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 80679d5e12..9f2c706c12 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -419,6 +419,11 @@ test_expect_success 'Verify descending sort' '
test_cmp expected actual
'
+test_expect_success 'Give help even with invalid sort atoms' '
+ test_expect_code 129 git for-each-ref --sort=bogus -h >actual 2>&1 &&
+ grep "^usage: git for-each-ref" actual
+'
+
cat >expected <<\EOF
refs/tags/testtag
refs/tags/testtag-2
@@ -1019,6 +1024,27 @@ test_expect_success 'equivalent sorts fall back on refname' '
test_cmp expected actual
'
+test_expect_success '--no-sort cancels the previous sort keys' '
+ cat >expected <<-\EOF &&
+ 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
+ 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
+ 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
+ 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
+ 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
+ 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
+ 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
+ 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
+ EOF
+ git for-each-ref \
+ --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
+ --sort=-refname \
+ --sort=taggeremail \
+ --no-sort \
+ --sort=taggerdate \
+ "refs/tags/multi-*" >actual &&
+ test_cmp expected actual
+'
+
test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
test_when_finished "git checkout main" &&
git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
diff --git a/t/t6407-merge-binary.sh b/t/t6407-merge-binary.sh
index d4273f2575..e34676c204 100755
--- a/t/t6407-merge-binary.sh
+++ b/t/t6407-merge-binary.sh
@@ -5,6 +5,7 @@ test_description='ask merge-recursive to merge binary files'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '
diff --git a/t/t6414-merge-rename-nocruft.sh b/t/t6414-merge-rename-nocruft.sh
index d7e3c1fa6e..69fc1c9e69 100755
--- a/t/t6414-merge-rename-nocruft.sh
+++ b/t/t6414-merge-rename-nocruft.sh
@@ -4,6 +4,7 @@ test_description='Merge-recursive merging renames'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
index 0e7cf75435..e56ca5b0fa 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -661,6 +661,13 @@ test_expect_success 'setup trace2' '
export GIT_TRACE2_BRIEF
'
+test_expect_success 'setup large log output' '
+ perl -e "
+ print \"this is a long commit message\" x 50000
+ " >commit-msg &&
+ git commit --allow-empty -F commit-msg
+'
+
test_expect_success TTY 'git returns SIGPIPE on early pager exit' '
test_when_finished "rm pager-used trace.normal" &&
test_config core.pager ">pager-used; head -n 1; exit 0" &&
@@ -670,7 +677,7 @@ test_expect_success TTY 'git returns SIGPIPE on early pager exit' '
if test_have_prereq !MINGW
then
- OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
+ { test_terminal git log >/dev/null; OUT=$?; } &&
test_match_signal 13 "$OUT"
else
test_terminal git log
@@ -691,7 +698,7 @@ test_expect_success TTY 'git returns SIGPIPE on early pager non-zero exit' '
if test_have_prereq !MINGW
then
- OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
+ { test_terminal git log >/dev/null; OUT=$?; } &&
test_match_signal 13 "$OUT"
else
test_terminal git log
@@ -710,13 +717,7 @@ test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' '
export GIT_TRACE2 &&
test_when_finished "unset GIT_TRACE2" &&
- if test_have_prereq !MINGW
- then
- OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
- test "$OUT" -eq 0
- else
- test_terminal git log
- fi &&
+ test_terminal git log &&
grep child_exit trace.normal >child-exits &&
test_line_count = 1 child-exits &&
@@ -724,41 +725,14 @@ test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' '
test_path_is_file pager-used
'
-test_expect_success TTY 'git discards nonexisting pager without SIGPIPE' '
- test_when_finished "rm pager-used trace.normal" &&
- test_config core.pager "wc >pager-used; does-not-exist" &&
- GIT_TRACE2="$(pwd)/trace.normal" &&
- export GIT_TRACE2 &&
- test_when_finished "unset GIT_TRACE2" &&
-
- if test_have_prereq !MINGW
- then
- OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
- test "$OUT" -eq 0
- else
- test_terminal git log
- fi &&
-
- grep child_exit trace.normal >child-exits &&
- test_line_count = 1 child-exits &&
- grep " code:127 " child-exits &&
- test_path_is_file pager-used
-'
-
-test_expect_success TTY 'git attempts to page to nonexisting pager command, gets SIGPIPE' '
+test_expect_success TTY 'git skips paging nonexisting command' '
test_when_finished "rm trace.normal" &&
test_config core.pager "does-not-exist" &&
GIT_TRACE2="$(pwd)/trace.normal" &&
export GIT_TRACE2 &&
test_when_finished "unset GIT_TRACE2" &&
- if test_have_prereq !MINGW
- then
- OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
- test_match_signal 13 "$OUT"
- else
- test_terminal git log
- fi &&
+ test_terminal git log &&
grep child_exit trace.normal >child-exits &&
test_line_count = 1 child-exits &&
@@ -767,14 +741,14 @@ test_expect_success TTY 'git attempts to page to nonexisting pager command, gets
test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
test_when_finished "rm pager-used trace.normal" &&
- test_config core.pager ">pager-used; test-tool sigchain" &&
+ test_config core.pager ">pager-used; exec test-tool sigchain" &&
GIT_TRACE2="$(pwd)/trace.normal" &&
export GIT_TRACE2 &&
test_when_finished "unset GIT_TRACE2" &&
if test_have_prereq !MINGW
then
- OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
+ { test_terminal git log >/dev/null; OUT=$?; } &&
test_match_signal 13 "$OUT"
else
test_terminal git log
@@ -786,4 +760,9 @@ test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
test_path_is_file pager-used
'
+test_expect_success TTY 'non-existent pager doesnt cause crash' '
+ test_config pager.show invalid-pager &&
+ test_terminal git show
+'
+
test_done
diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
index eeb0534163..47fc21d962 100755
--- a/t/t7064-wtstatus-pv2.sh
+++ b/t/t7064-wtstatus-pv2.sh
@@ -113,6 +113,21 @@ test_expect_success 'after first commit, create unstaged changes' '
test_cmp expect actual
'
+test_expect_success 'after first commit, stash existing changes' '
+ cat >expect <<-EOF &&
+ # branch.oid $H0
+ # branch.head initial-branch
+ # stash 2
+ EOF
+
+ test_when_finished "git stash pop && git stash pop" &&
+
+ git stash -- file_x &&
+ git stash &&
+ git status --porcelain=v2 --branch --show-stash --untracked-files=no >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'after first commit but omit untracked files and branch' '
cat >expect <<-EOF &&
1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 601b2bf97f..d05426062e 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -472,6 +472,23 @@ test_expect_success '--mixed refreshes the index' '
test_cmp expect output
'
+test_expect_success '--mixed preserves skip-worktree' '
+ echo 123 >>file2 &&
+ git add file2 &&
+ git update-index --skip-worktree file2 &&
+ git reset --mixed HEAD >output &&
+ test_must_be_empty output &&
+
+ cat >expect <<-\EOF &&
+ Unstaged changes after reset:
+ M file2
+ EOF
+ git update-index --no-skip-worktree file2 &&
+ git add file2 &&
+ git reset --mixed HEAD >output &&
+ test_cmp expect output
+'
+
test_expect_success 'resetting specific path that is unmerged' '
git rm --cached file2 &&
F1=$(git rev-parse HEAD:file1) &&
diff --git a/t/t7113-post-index-change-hook.sh b/t/t7113-post-index-change-hook.sh
index 688fa995c9..a21781d68a 100755
--- a/t/t7113-post-index-change-hook.sh
+++ b/t/t7113-post-index-change-hook.sh
@@ -5,6 +5,7 @@ test_description='post index change hook'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index cb1b8e35db..e7cec2e457 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -1182,18 +1182,17 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su
rmdir init example2
'
-test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
+test_expect_success 'submodule deinit absorbs .git directory if .git is a directory' '
git submodule update --init &&
(
cd init &&
rm .git &&
- cp -R ../.git/modules/example .git &&
+ mv ../.git/modules/example .git &&
GIT_WORK_TREE=. git config --unset core.worktree
) &&
- test_must_fail git submodule deinit init &&
- test_must_fail git submodule deinit -f init &&
- test -d init/.git &&
- test -n "$(git config --get-regexp "submodule\.example\.")"
+ git submodule deinit init &&
+ test_path_is_missing init/.git &&
+ test -z "$(git config --get-regexp "submodule\.example\.")"
'
test_expect_success 'submodule with UTF-8 name' '
diff --git a/t/t7509-commit-authorship.sh b/t/t7509-commit-authorship.sh
index d568593382..21c668f75e 100755
--- a/t/t7509-commit-authorship.sh
+++ b/t/t7509-commit-authorship.sh
@@ -5,6 +5,7 @@
test_description='commit tests of various authorhip options. '
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
author_header () {
diff --git a/t/t7815-grep-binary.sh b/t/t7815-grep-binary.sh
index 90ebb64f46..ac871287c0 100755
--- a/t/t7815-grep-binary.sh
+++ b/t/t7815-grep-binary.sh
@@ -2,6 +2,7 @@
test_description='git grep in binary files'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' "
diff --git a/t/t9102-git-svn-deep-rmdir.sh b/t/t9102-git-svn-deep-rmdir.sh
index 66cd51102c..7b2049caa0 100755
--- a/t/t9102-git-svn-deep-rmdir.sh
+++ b/t/t9102-git-svn-deep-rmdir.sh
@@ -1,5 +1,7 @@
#!/bin/sh
test_description='git svn rmdir'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./lib-git-svn.sh
test_expect_success 'initialize repo' '
diff --git a/t/t9123-git-svn-rebuild-with-rewriteroot.sh b/t/t9123-git-svn-rebuild-with-rewriteroot.sh
index ead404589e..3320b1f39c 100755
--- a/t/t9123-git-svn-rebuild-with-rewriteroot.sh
+++ b/t/t9123-git-svn-rebuild-with-rewriteroot.sh
@@ -5,6 +5,7 @@
test_description='git svn respects rewriteRoot during rebuild'
+TEST_PASSES_SANITIZE_LEAK=true
. ./lib-git-svn.sh
mkdir import
diff --git a/t/t9128-git-svn-cmd-branch.sh b/t/t9128-git-svn-cmd-branch.sh
index 4e95f791db..9871f5abc9 100755
--- a/t/t9128-git-svn-cmd-branch.sh
+++ b/t/t9128-git-svn-cmd-branch.sh
@@ -4,6 +4,8 @@
#
test_description='git svn partial-rebuild tests'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./lib-git-svn.sh
test_expect_success 'initialize svnrepo' '
diff --git a/t/t9167-git-svn-cmd-branch-subproject.sh b/t/t9167-git-svn-cmd-branch-subproject.sh
index ba35fc06fc..d9fd111c10 100755
--- a/t/t9167-git-svn-cmd-branch-subproject.sh
+++ b/t/t9167-git-svn-cmd-branch-subproject.sh
@@ -4,6 +4,8 @@
#
test_description='git svn branch for subproject clones'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./lib-git-svn.sh
test_expect_success 'initialize svnrepo' '
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 5decc3b269..518203fbe0 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -2148,6 +2148,9 @@ test_expect_success PERL 'send-email' '
--cover-from-description=Z
--cover-letter Z
EOF
+ test_completion "git send-email --val" <<-\EOF &&
+ --validate Z
+ EOF
test_completion "git send-email ma" "main "
'
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 2679a7596a..57efcc5e97 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1734,6 +1734,10 @@ build_option () {
sed -ne "s/^$1: //p"
}
+test_lazy_prereq SIZE_T_IS_64BIT '
+ test 8 -eq "$(build_option sizeof-size_t)"
+'
+
test_lazy_prereq LONG_IS_64BIT '
test 8 -le "$(build_option sizeof-long)"
'
diff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c
index bda283e7f4..8a21dd2972 100644
--- a/trace2/tr2_dst.c
+++ b/trace2/tr2_dst.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "sigchain.h"
#include "trace2/tr2_dst.h"
#include "trace2/tr2_sid.h"
#include "trace2/tr2_sysenv.h"
@@ -360,6 +361,7 @@ int tr2_dst_trace_want(struct tr2_dst *dst)
void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)
{
int fd = tr2_dst_get_trace_fd(dst);
+ ssize_t bytes;
strbuf_complete_line(buf_line); /* ensure final NL on buffer */
@@ -378,12 +380,15 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)
*
* If we get an IO error, just close the trace dst.
*/
- if (write(fd, buf_line->buf, buf_line->len) >= 0)
+ sigchain_push(SIGPIPE, SIG_IGN);
+ bytes = write(fd, buf_line->buf, buf_line->len);
+ sigchain_pop(SIGPIPE);
+ if (bytes >= 0)
return;
+ tr2_dst_trace_disable(dst);
if (tr2_dst_want_warning())
warning("unable to write trace to '%s': %s",
tr2_sysenv_display_name(dst->sysenv_var),
strerror(errno));
- tr2_dst_trace_disable(dst);
}
diff --git a/unpack-trees.c b/unpack-trees.c
index 89ca95ce90..b71fdab5e3 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -645,17 +645,24 @@ static void mark_ce_used_same_name(struct cache_entry *ce,
}
}
-static struct cache_entry *next_cache_entry(struct unpack_trees_options *o)
+static struct cache_entry *next_cache_entry(struct unpack_trees_options *o, int *hint)
{
const struct index_state *index = o->src_index;
int pos = o->cache_bottom;
+ if (*hint > pos)
+ pos = *hint;
+
while (pos < index->cache_nr) {
struct cache_entry *ce = index->cache[pos];
- if (!(ce->ce_flags & CE_UNPACKED))
+ if (!(ce->ce_flags & CE_UNPACKED)) {
+ *hint = pos + 1;
return ce;
+ }
pos++;
}
+
+ *hint = pos;
return NULL;
}
@@ -1365,12 +1372,13 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
/* Are we supposed to look at the index too? */
if (o->merge) {
+ int hint = -1;
while (1) {
int cmp;
struct cache_entry *ce;
if (o->diff_index_cached)
- ce = next_cache_entry(o);
+ ce = next_cache_entry(o, &hint);
else
ce = find_cache_entry(info, p);
@@ -1690,7 +1698,7 @@ static int verify_absent(const struct cache_entry *,
int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)
{
struct repository *repo = the_repository;
- int i, ret;
+ int i, hint, ret;
static struct cache_entry *dfc;
struct pattern_list pl;
int free_pattern_list = 0;
@@ -1779,13 +1787,15 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
info.pathspec = o->pathspec;
if (o->prefix) {
+ hint = -1;
+
/*
* Unpack existing index entries that sort before the
* prefix the tree is spliced into. Note that o->merge
* is always true in this case.
*/
while (1) {
- struct cache_entry *ce = next_cache_entry(o);
+ struct cache_entry *ce = next_cache_entry(o, &hint);
if (!ce)
break;
if (ce_in_traverse_path(ce, &info))
@@ -1806,8 +1816,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
/* Any left-over entries in the index? */
if (o->merge) {
+ hint = -1;
while (1) {
- struct cache_entry *ce = next_cache_entry(o);
+ struct cache_entry *ce = next_cache_entry(o, &hint);
if (!ce)
break;
if (unpack_index_entry(ce, o) < 0)
diff --git a/urlmatch.c b/urlmatch.c
index 33a2ccd306..03ad3f30a9 100644
--- a/urlmatch.c
+++ b/urlmatch.c
@@ -5,7 +5,7 @@
#define URL_DIGIT "0123456789"
#define URL_ALPHADIGIT URL_ALPHA URL_DIGIT
#define URL_SCHEME_CHARS URL_ALPHADIGIT "+.-"
-#define URL_HOST_CHARS URL_ALPHADIGIT ".-[:]" /* IPv6 literals need [:] */
+#define URL_HOST_CHARS URL_ALPHADIGIT ".-_[:]" /* IPv6 literals need [:] */
#define URL_UNSAFE_CHARS " <>\"%{}|\\^`" /* plus 0x00-0x1F,0x7F-0xFF */
#define URL_GEN_RESERVED ":/?#[]@"
#define URL_SUB_RESERVED "!$&'()*+,;="
diff --git a/worktree.c b/worktree.c
index 092a4f92ad..2c155b1015 100644
--- a/worktree.c
+++ b/worktree.c
@@ -28,11 +28,13 @@ static void add_head_info(struct worktree *wt)
{
int flags;
const char *target;
+ int ignore_errno;
target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),
"HEAD",
0,
- &wt->head_oid, &flags);
+ &wt->head_oid, &flags,
+ &ignore_errno);
if (!target)
return;
@@ -418,6 +420,7 @@ const struct worktree *find_shared_symref(const char *symref,
const char *symref_target;
struct ref_store *refs;
int flags;
+ int ignore_errno;
if (wt->is_bare)
continue;
@@ -435,7 +438,8 @@ const struct worktree *find_shared_symref(const char *symref,
refs = get_worktree_ref_store(wt);
symref_target = refs_resolve_ref_unsafe(refs, symref, 0,
- NULL, &flags);
+ NULL, &flags,
+ &ignore_errno);
if ((flags & REF_ISSYMREF) &&
symref_target && !strcmp(symref_target, target)) {
existing = wt;
@@ -563,16 +567,17 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
struct worktree *wt = *p;
struct object_id oid;
int flag;
+ int ignore_errno;
if (wt->is_current)
continue;
strbuf_reset(&refname);
strbuf_worktree_ref(wt, &refname, "HEAD");
- if (!refs_read_ref_full(get_main_ref_store(the_repository),
- refname.buf,
- RESOLVE_REF_READING,
- &oid, &flag))
+ if (refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
+ refname.buf,
+ RESOLVE_REF_READING,
+ &oid, &flag, &ignore_errno))
ret = fn(refname.buf, &oid, flag, cb_data);
if (ret)
break;
diff --git a/wt-status.c b/wt-status.c
index e4f29b2b4c..5d215f4e4f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -948,11 +948,17 @@ static int stash_count_refs(struct object_id *ooid, struct object_id *noid,
return 0;
}
+static int count_stash_entries(void)
+{
+ int n = 0;
+ for_each_reflog_ent("refs/stash", stash_count_refs, &n);
+ return n;
+}
+
static void wt_longstatus_print_stash_summary(struct wt_status *s)
{
- int stash_count = 0;
+ int stash_count = count_stash_entries();
- 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",
@@ -2177,6 +2183,18 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
}
/*
+ * Print the stash count in a porcelain-friendly format
+ */
+static void wt_porcelain_v2_print_stash(struct wt_status *s)
+{
+ int stash_count = count_stash_entries();
+ char eol = s->null_termination ? '\0' : '\n';
+
+ if (stash_count > 0)
+ fprintf(s->fp, "# stash %d%c", stash_count, eol);
+}
+
+/*
* Convert various submodule status values into a
* fixed-length string of characters in the buffer provided.
*/
@@ -2437,6 +2455,9 @@ static void wt_porcelain_v2_print(struct wt_status *s)
if (s->show_branch)
wt_porcelain_v2_print_tracking(s);
+ if (s->show_stash)
+ wt_porcelain_v2_print_stash(s);
+
for (i = 0; i < s->change.nr; i++) {
it = &(s->change.items[i]);
d = it->util;