aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/RelNotes/2.49.0.txt62
-rw-r--r--Documentation/config/diff.txt2
-rw-r--r--Documentation/config/difftool.txt2
-rw-r--r--Documentation/git-credential-cache.txt17
-rw-r--r--Documentation/gitattributes.txt2
-rw-r--r--Documentation/gitcli.txt17
-rw-r--r--Documentation/gitcredentials.txt41
-rw-r--r--Documentation/technical/meson.build1
-rw-r--r--Makefile2
-rw-r--r--add-interactive.c19
-rw-r--r--add-patch.c2
-rw-r--r--bisect.c11
-rw-r--r--builtin/am.c9
-rw-r--r--builtin/blame.c6
-rw-r--r--builtin/branch.c4
-rw-r--r--builtin/bugreport.c2
-rw-r--r--builtin/check-ref-format.c4
-rw-r--r--builtin/checkout--worker.c6
-rw-r--r--builtin/checkout-index.c6
-rw-r--r--builtin/commit-graph.c1
-rw-r--r--builtin/commit-tree.c4
-rw-r--r--builtin/commit.c8
-rw-r--r--builtin/credential.c9
-rw-r--r--builtin/diagnose.c4
-rw-r--r--builtin/diff-files.c3
-rw-r--r--builtin/diff-index.c3
-rw-r--r--builtin/diff-tree.c3
-rw-r--r--builtin/fast-import.c3
-rw-r--r--builtin/fetch-pack.c2
-rw-r--r--builtin/fsck.c12
-rw-r--r--builtin/fsmonitor--daemon.c4
-rw-r--r--builtin/gc.c6
-rw-r--r--builtin/get-tar-commit-id.c4
-rw-r--r--builtin/grep.c4
-rw-r--r--builtin/help.c4
-rw-r--r--builtin/index-pack.c10
-rw-r--r--builtin/log.c57
-rw-r--r--builtin/ls-files.c4
-rw-r--r--builtin/mailinfo.c2
-rw-r--r--builtin/mailsplit.c4
-rw-r--r--builtin/merge-base.c4
-rw-r--r--builtin/merge-index.c7
-rw-r--r--builtin/merge-ours.c3
-rw-r--r--builtin/merge-recursive.c6
-rw-r--r--builtin/merge.c4
-rw-r--r--builtin/pack-objects.c21
-rw-r--r--builtin/pack-redundant.c3
-rw-r--r--builtin/prune.c3
-rw-r--r--builtin/rebase.c6
-rw-r--r--builtin/receive-pack.c6
-rw-r--r--builtin/remote-ext.c2
-rw-r--r--builtin/remote-fd.c1
-rw-r--r--builtin/remote.c3
-rw-r--r--builtin/repack.c2
-rw-r--r--builtin/rev-list.c6
-rw-r--r--builtin/rev-parse.c2
-rw-r--r--builtin/send-pack.c2
-rw-r--r--builtin/unpack-file.c8
-rw-r--r--builtin/unpack-objects.c5
-rw-r--r--builtin/update-index.c4
-rw-r--r--builtin/update-server-info.c2
-rw-r--r--builtin/upload-archive.c6
-rw-r--r--builtin/upload-pack.c6
-rw-r--r--builtin/var.c3
-rw-r--r--bulk-checkin.c2
-rw-r--r--commit-graph.c20
-rw-r--r--commit-reach.c75
-rw-r--r--commit-reach.h10
-rw-r--r--commit.c4
-rw-r--r--commit.h2
-rw-r--r--contrib/completion/git-completion.bash17
-rw-r--r--credential.c34
-rw-r--r--credential.h11
-rw-r--r--delta-islands.c3
-rw-r--r--diagnose.c15
-rw-r--r--diagnose.h5
-rw-r--r--diff.c4
-rw-r--r--diffcore-rename.c1
-rw-r--r--entry.c4
-rw-r--r--fetch-pack.c2
-rw-r--r--fsck.c2
-rw-r--r--git-compat-util.h2
-rwxr-xr-xgit-instaweb.sh4
-rwxr-xr-xgit-submodule.sh216
-rw-r--r--git.c10
-rw-r--r--graph.c3
-rw-r--r--http.c24
-rw-r--r--imap-send.c10
-rw-r--r--log-tree.c2
-rw-r--r--mailinfo.c5
-rw-r--r--mailinfo.h4
-rw-r--r--match-trees.c50
-rw-r--r--meson.build55
-rw-r--r--meson_options.txt8
-rw-r--r--midx-write.c11
-rw-r--r--midx.c13
-rw-r--r--object-file.c66
-rw-r--r--object-name.c63
-rw-r--r--oss-fuzz/fuzz-parse-attr-line.c2
-rw-r--r--pack-bitmap-write.c6
-rw-r--r--pack-bitmap.c4
-rw-r--r--pager.c14
-rw-r--r--pager.h7
-rw-r--r--parse-options.c53
-rw-r--r--parse-options.h4
-rw-r--r--preload-index.c4
-rw-r--r--prio-queue.h4
-rw-r--r--progress.c34
-rw-r--r--progress.h13
-rw-r--r--prune-packed.c3
-rw-r--r--pseudo-merge.c3
-rw-r--r--read-cache.c7
-rw-r--r--ref-filter.c2
-rw-r--r--reftable/stack.c4
-rw-r--r--remote-curl.c4
-rw-r--r--remote.c4
-rw-r--r--resolve-undo.c14
-rw-r--r--resolve-undo.h6
-rw-r--r--send-pack.c77
-rw-r--r--send-pack.h3
-rw-r--r--serve.c36
-rw-r--r--serve.h6
-rw-r--r--server-info.c40
-rw-r--r--server-info.h4
-rw-r--r--shallow.c40
-rw-r--r--shallow.h6
-rw-r--r--t/helper/test-csprng.c2
-rw-r--r--t/helper/test-progress.c6
-rw-r--r--t/helper/test-reach.c6
-rw-r--r--t/helper/test-serve-v2.c7
-rw-r--r--t/helper/test-simple-ipc.c4
-rw-r--r--t/meson.build2
-rwxr-xr-xt/t0012-help.sh3
-rwxr-xr-xt/t1006-cat-file.sh31
-rwxr-xr-xt/t5504-fetch-receive-strict.sh10
-rwxr-xr-xt/t6120-describe.sh24
-rwxr-xr-xt/t7110-reset-merge.sh12
-rwxr-xr-xt/t7407-submodule-foreach.sh4
-rwxr-xr-xt/t7600-merge.sh2
-rw-r--r--t/test-lib-functions.sh2
-rw-r--r--t/test-lib.sh20
-rw-r--r--t/unit-tests/t-reftable-readwrite.c6
-rw-r--r--t/unit-tests/u-hash.c (renamed from t/unit-tests/t-hash.c)71
-rw-r--r--tmp-objdir.c15
-rw-r--r--tmp-objdir.h5
-rw-r--r--trace.c9
-rw-r--r--trace.h4
-rw-r--r--transport.c2
-rw-r--r--unpack-trees.c4
-rw-r--r--usage.c27
-rw-r--r--version.c7
-rw-r--r--walker.c3
-rw-r--r--wrapper.c24
-rw-r--r--wrapper.h16
154 files changed, 1250 insertions, 720 deletions
diff --git a/Documentation/RelNotes/2.49.0.txt b/Documentation/RelNotes/2.49.0.txt
index b4a1f10a78..bc82217584 100644
--- a/Documentation/RelNotes/2.49.0.txt
+++ b/Documentation/RelNotes/2.49.0.txt
@@ -4,12 +4,74 @@ Git v2.49 Release Notes
UI, Workflows & Features
------------------------
+ * Completion script updates for zsh
+
Performance, Internal Implementation, Development Support etc.
--------------------------------------------------------------
+ * More -Wsign-compare fixes.
+
+ * meson-based build now supports the unsafe-sha1 build knob.
+
+ * The code to check LSan results has been simplified and made more
+ robust.
+ (merge 164a2516eb jk/lsan-race-ignore-false-positive later to maint).
+
+ * More code paths have a repository passed through the callchain,
+ instead of assuming the primary the_repository object.
+
Fixes since v2.48
-----------------
+ * "git submodule" learned various ways to spell the same option,
+ e.g. "--branch=B" can be spelled "--branch B" or "-bB".
+ (merge b86f0f9071 re/submodule-parse-opt later to maint).
+
+ * Tweak the help text used for the option value placeholders by
+ parse-options API so that translations can customize the "<>"
+ placeholder signal (e.g. "--option=<value>").
+ (merge 5b34dd08d0 as/long-option-help-i18n later to maint).
+
+ * CI jobs gave sporadic failures, which turns out that that the
+ object finalization code was giving an error when it did not have
+ to.
+ (merge d7fcbe2c56 ps/object-collision-check later to maint).
+
+ * The code to compute "unique" name used git_rand() which can fail or
+ get stuck; the callsite does not require cryptographic security.
+ Introduce the "insecure" mode and use it appropriately.
+ (merge 0b4f8afef6 ps/reftable-get-random-fix later to maint).
+
+ * A misconfigured "fsck.skiplist" configuration variable was not
+ diagnosed as an error, which has been corrected.
+ (merge ca7158076f jt/fsck-skiplist-parse-fix later to maint).
+
+ * Extended SHA-1 expression parser did not work well when a branch
+ with an unusual name (e.g. "foo{bar") is involved.
+ (merge 191f0c8db2 en/object-name-with-funny-refname-fix later to maint).
+
+ * The meson build procedure looked for the 'version-def.h' file in a
+ wrong directory, which has been corrected.
+ (merge 4771501c0a tc/meson-use-our-version-def-h later to maint).
+
+ * The meson build procedure for Documentation/technical/ hierarchy was
+ missing necessary dependencies, which has been corrected.
+ (merge 1dca492edd sj/meson-doc-technical-dependency-fix later to maint).
+
+ * The "instaweb" bound only to local IP address without "--local" and
+ to all addresses with "--local", which was the other way around, when
+ using Python's http.server class, which has been corrected.
+ (merge 76baf97fa1 ak/instaweb-python-port-binding-fix later to maint).
+
+ * Document that it is insecure to use Personal Access Tokens, which
+ some hosting providers take as username/password, embedded in URLs.
+ (merge a90ff409f0 mh/doc-credential-helpers-with-pat later to maint).
+
* Other code cleanup, docfix, build fix, etc.
+ (merge ddb5287894 jk/t7407-use-test-grep later to maint).
+ (merge 21e1b44865 aj/difftool-config-doc-fix later to maint).
+ (merge 6a63995335 mh/gitattr-doc-markup-fix later to maint).
+ (merge 43850dcf9c sk/unit-test-hash later to maint).
+ (merge 4ad47d2de3 jc/cli-doc-option-and-config later to maint).
diff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt
index fdae13a212..1135a62a0a 100644
--- a/Documentation/config/diff.txt
+++ b/Documentation/config/diff.txt
@@ -218,8 +218,6 @@ endif::git-diff[]
Set this option to `true` to make the diff driver cache the text
conversion outputs. See linkgit:gitattributes[5] for details.
-include::{build_dir}/mergetools-diff.txt[]
-
`diff.indentHeuristic`::
Set this option to `false` to disable the default heuristics
that shift diff hunk boundaries to make patches easier to read.
diff --git a/Documentation/config/difftool.txt b/Documentation/config/difftool.txt
index 447c40d85a..6cd47331a9 100644
--- a/Documentation/config/difftool.txt
+++ b/Documentation/config/difftool.txt
@@ -13,6 +13,8 @@ diff.guitool::
and requires that a corresponding difftool.<guitool>.cmd variable
is defined.
+include::{build_dir}/mergetools-diff.txt[]
+
difftool.<tool>.cmd::
Specify the command to invoke the specified diff tool.
The specified command is evaluated in shell with the following
diff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt
index 487cc557a8..54fa7a27e1 100644
--- a/Documentation/git-credential-cache.txt
+++ b/Documentation/git-credential-cache.txt
@@ -78,6 +78,23 @@ variable (this example increases the cache time to 1 hour):
$ git config credential.helper 'cache --timeout=3600'
-------------------------------------------------------
+PERSONAL ACCESS TOKENS
+----------------------
+
+Some remotes accept personal access tokens, which are randomly
+generated and hard to memorise. They typically have a lifetime of weeks
+or months.
+
+git-credential-cache is inherently unsuitable for persistent storage of
+personal access tokens. The credential will be forgotten after the cache
+timeout. Even if you configure a long timeout, credentials will be
+forgotten if the daemon dies.
+
+To avoid frequently regenerating personal access tokens, configure a
+credential helper with persistent storage. Alternatively, configure an
+OAuth credential helper to generate credentials automatically. See
+linkgit:gitcredentials[7], sections "Available helpers" and "OAuth".
+
GIT
---
Part of the linkgit:git[1] suite
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index e6150595af..5d12b78549 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -1166,7 +1166,7 @@ internal merge and the final merge.
The merge driver can learn the pathname in which the merged result
will be stored via placeholder `%P`. The conflict labels to be used
for the common ancestor, local head and other head can be passed by
-using '%S', '%X' and '%Y` respectively.
+using `%S`, `%X` and `%Y` respectively.
`conflict-marker-size`
^^^^^^^^^^^^^^^^^^^^^^
diff --git a/Documentation/gitcli.txt b/Documentation/gitcli.txt
index fcd86d2eee..04193ec907 100644
--- a/Documentation/gitcli.txt
+++ b/Documentation/gitcli.txt
@@ -161,6 +161,23 @@ can use `--no-track` to override that behaviour. The same goes for `--color`
and `--no-color`.
+Options trump configuration and environment
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+When there is a configuration variable or an environment variable
+that tweak the behaviour of an aspect of a Git command, and also a
+command line option that tweaks the same, the command line option
+overrides what the configuration and/or environment variable say.
+
+For example, the `user.name` configuration variable is used to
+specify the human-readable name used by the `git commit` command to
+record the author and the committer name in a newly created commit.
+The `GIT_AUTHOR_NAME` environment variable, if set, takes precedence
+when deciding what author name to record. The `--author=<author>`
+command line option of the `git commit` command, when given, takes
+precedence over these two sources of information.
+
+
Aggregating short options
~~~~~~~~~~~~~~~~~~~~~~~~~
Commands that support the enhanced option parser allow you to aggregate short
diff --git a/Documentation/gitcredentials.txt b/Documentation/gitcredentials.txt
index 35a7452c8f..3337bb475d 100644
--- a/Documentation/gitcredentials.txt
+++ b/Documentation/gitcredentials.txt
@@ -66,18 +66,7 @@ storage provided by the OS or other programs. Alternatively, a
credential-generating helper might generate credentials for certain servers via
some API.
-To use a helper, you must first select one to use. Git currently
-includes the following helpers:
-
-cache::
-
- Cache credentials in memory for a short period of time. See
- linkgit:git-credential-cache[1] for details.
-
-store::
-
- Store credentials indefinitely on disk. See
- linkgit:git-credential-store[1] for details.
+To use a helper, you must first select one to use (see below for a list).
You may also have third-party helpers installed; search for
`credential-*` in the output of `git help -a`, and consult the
@@ -106,6 +95,28 @@ $ git config --global credential.helper foo
=== Available helpers
+Git currently includes the following helpers:
+
+cache::
+
+ Cache credentials in memory for a short period of time. See
+ linkgit:git-credential-cache[1] for details.
+
+store::
+
+ Store credentials indefinitely on disk. See
+ linkgit:git-credential-store[1] for details.
+
+Popular helpers with secure persistent storage include:
+
+ - git-credential-libsecret (Linux)
+
+ - git-credential-osxkeychain (macOS)
+
+ - git-credential-wincred (Windows)
+
+ - https://github.com/git-ecosystem/git-credential-manager[Git Credential Manager] (cross platform, included in Git for Windows)
+
The community maintains a comprehensive list of Git credential helpers at
https://git-scm.com/doc/credential-helpers.
@@ -116,6 +127,12 @@ OAuth credential helper. Initial authentication opens a browser window to the
host. Subsequent authentication happens in the background. Many popular Git
hosts support OAuth.
+Popular helpers with OAuth support include:
+
+ - https://github.com/git-ecosystem/git-credential-manager[Git Credential Manager] (cross platform, included in Git for Windows)
+
+ - https://github.com/hickford/git-credential-oauth[git-credential-oauth] (cross platform, included in many Linux distributions)
+
CREDENTIAL CONTEXTS
-------------------
diff --git a/Documentation/technical/meson.build b/Documentation/technical/meson.build
index 21dfb8b5c9..3a65ee59b3 100644
--- a/Documentation/technical/meson.build
+++ b/Documentation/technical/meson.build
@@ -60,6 +60,7 @@ foreach article : api_docs + articles
command: asciidoc_html_options,
input: article,
output: fs.stem(article) + '.html',
+ depends: documentation_deps,
install: true,
install_dir: get_option('datadir') / 'doc/git-doc/technical',
)
diff --git a/Makefile b/Makefile
index 75dbb8e25f..b0cdc1fd4a 100644
--- a/Makefile
+++ b/Makefile
@@ -1338,6 +1338,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/%
THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%
CLAR_TEST_SUITES += u-ctype
+CLAR_TEST_SUITES += u-hash
CLAR_TEST_SUITES += u-mem-pool
CLAR_TEST_SUITES += u-prio-queue
CLAR_TEST_SUITES += u-reftable-tree
@@ -1348,7 +1349,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
UNIT_TEST_PROGRAMS += t-example-decorate
-UNIT_TEST_PROGRAMS += t-hash
UNIT_TEST_PROGRAMS += t-hashmap
UNIT_TEST_PROGRAMS += t-oid-array
UNIT_TEST_PROGRAMS += t-oidmap
diff --git a/add-interactive.c b/add-interactive.c
index d0f8c10e6f..97ff35b6f1 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
@@ -72,14 +71,14 @@ void init_add_i_state(struct add_i_state *s, struct repository *r)
s->use_color ? GIT_COLOR_RESET : "", COLOR_MAXLEN);
FREE_AND_NULL(s->interactive_diff_filter);
- git_config_get_string("interactive.difffilter",
- &s->interactive_diff_filter);
+ repo_config_get_string(r, "interactive.difffilter",
+ &s->interactive_diff_filter);
FREE_AND_NULL(s->interactive_diff_algorithm);
- git_config_get_string("diff.algorithm",
- &s->interactive_diff_algorithm);
+ repo_config_get_string(r, "diff.algorithm",
+ &s->interactive_diff_algorithm);
- git_config_get_bool("interactive.singlekey", &s->use_single_key);
+ repo_config_get_bool(r, "interactive.singlekey", &s->use_single_key);
if (s->use_single_key)
setbuf(stdin, NULL);
}
@@ -535,7 +534,7 @@ static int get_modified_files(struct repository *r,
size_t *binary_count)
{
struct object_id head_oid;
- int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
+ int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(r),
"HEAD", RESOLVE_REF_READING,
&head_oid, NULL);
struct collection_status s = { 0 };
@@ -560,7 +559,7 @@ static int get_modified_files(struct repository *r,
s.skip_unseen = filter && i;
opt.def = is_initial ?
- empty_tree_oid_hex(the_repository->hash_algo) : oid_to_hex(&head_oid);
+ empty_tree_oid_hex(r->hash_algo) : oid_to_hex(&head_oid);
repo_init_revisions(r, &rev, NULL);
setup_revisions(0, NULL, &rev, &opt);
@@ -765,7 +764,7 @@ static int run_revert(struct add_i_state *s, const struct pathspec *ps,
size_t count, i, j;
struct object_id oid;
- int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
+ int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(s->r),
"HEAD", RESOLVE_REF_READING,
&oid,
NULL);
@@ -996,7 +995,7 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
ssize_t count, i;
struct object_id oid;
- int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
+ int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(s->r),
"HEAD", RESOLVE_REF_READING,
&oid,
NULL);
diff --git a/add-patch.c b/add-patch.c
index 7b598e14df..95c67d8c80 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1464,7 +1464,7 @@ static int patch_update_file(struct add_p_state *s,
if (file_diff->hunk_nr) {
if (rendered_hunk_index != hunk_index) {
if (use_pager) {
- setup_pager();
+ setup_pager(the_repository);
sigchain_push(SIGPIPE, SIG_IGN);
}
render_hunk(s, hunk, 0, colored, &s->buf);
diff --git a/bisect.c b/bisect.c
index 1a9069c9ad..7a3c77c6d8 100644
--- a/bisect.c
+++ b/bisect.c
@@ -780,10 +780,10 @@ static struct commit *get_commit_reference(struct repository *r,
}
static struct commit **get_bad_and_good_commits(struct repository *r,
- int *rev_nr)
+ size_t *rev_nr)
{
struct commit **rev;
- int i, n = 0;
+ size_t i, n = 0;
ALLOC_ARRAY(rev, 1 + good_revs.nr);
rev[n++] = get_commit_reference(r, current_bad_oid);
@@ -855,7 +855,7 @@ static void handle_skipped_merge_base(const struct object_id *mb)
* for early success, this will be converted back to 0 in
* check_good_are_ancestors_of_bad().
*/
-static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
+static enum bisect_error check_merge_bases(size_t rev_nr, struct commit **rev, int no_checkout)
{
enum bisect_error res = BISECT_OK;
struct commit_list *result = NULL;
@@ -887,7 +887,7 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int
return res;
}
-static int check_ancestors(struct repository *r, int rev_nr,
+static int check_ancestors(struct repository *r, size_t rev_nr,
struct commit **rev, const char *prefix)
{
struct strvec rev_argv = STRVEC_INIT;
@@ -922,7 +922,8 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,
{
char *filename;
struct stat st;
- int fd, rev_nr;
+ int fd;
+ size_t rev_nr;
enum bisect_error res = BISECT_OK;
struct commit **rev;
diff --git a/builtin/am.c b/builtin/am.c
index 1338b606fe..390b463144 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1211,7 +1211,7 @@ static int parse_mail(struct am_state *state, const char *mail)
int ret = 0;
struct mailinfo mi;
- setup_mailinfo(&mi);
+ setup_mailinfo(the_repository, &mi);
if (state->utf8)
mi.metainfo_charset = get_commit_output_encoding();
@@ -1786,7 +1786,7 @@ static int do_interactive(struct am_state *state)
}
strbuf_release(&msg);
} else if (*reply == 'v' || *reply == 'V') {
- const char *pager = git_pager(1);
+ const char *pager = git_pager(the_repository, 1);
struct child_process cp = CHILD_PROCESS_INIT;
if (!pager)
@@ -2246,7 +2246,7 @@ static int show_patch(struct am_state *state, enum resume_type resume_mode)
if (len < 0)
die_errno(_("failed to read '%s'"), patch_path);
- setup_pager();
+ setup_pager(the_repository);
write_in_full(1, sb.buf, sb.len);
strbuf_release(&sb);
return 0;
@@ -2427,8 +2427,7 @@ int cmd_am(int argc,
OPT_END()
};
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(usage, options);
+ show_usage_with_options_if_asked(argc, argv, usage, options);
git_config(git_default_config, NULL);
diff --git a/builtin/blame.c b/builtin/blame.c
index 7555c445ab..c470654c7e 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1194,14 +1194,16 @@ parse_done:
sb.found_guilty_entry = &found_guilty_entry;
sb.found_guilty_entry_data = &pi;
if (show_progress)
- pi.progress = start_delayed_progress(_("Blaming lines"), num_lines);
+ pi.progress = start_delayed_progress(the_repository,
+ _("Blaming lines"),
+ num_lines);
assign_blame(&sb, opt);
stop_progress(&pi.progress);
if (!incremental)
- setup_pager();
+ setup_pager(the_repository);
else
goto cleanup;
diff --git a/builtin/branch.c b/builtin/branch.c
index 6e7b0cfddb..7c8b4b65b6 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -784,8 +784,8 @@ int cmd_branch(int argc,
filter.kind = FILTER_REFS_BRANCHES;
filter.abbrev = -1;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(builtin_branch_usage, options);
+ show_usage_with_options_if_asked(argc, argv,
+ builtin_branch_usage, options);
/*
* Try to set sort keys from config. If config does not set any,
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index 7c2df035c9..0ac59cc8dc 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -167,7 +167,7 @@ int cmd_bugreport(int argc,
strbuf_addftime(&zip_path, option_suffix, localtime_r(&now, &tm), 0, 0);
strbuf_addstr(&zip_path, ".zip");
- if (create_diagnostics_archive(&zip_path, diagnose))
+ if (create_diagnostics_archive(the_repository, &zip_path, diagnose))
die_errno(_("unable to create diagnostics archive %s"), zip_path.buf);
strbuf_release(&zip_path);
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index cef1ffe3ce..5d80afeec0 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -64,8 +64,8 @@ int cmd_check_ref_format(int argc,
BUG_ON_NON_EMPTY_PREFIX(prefix);
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage(builtin_check_ref_format_usage);
+ show_usage_if_asked(argc, argv,
+ builtin_check_ref_format_usage);
if (argc == 3 && !strcmp(argv[1], "--branch"))
return check_ref_format_branch(argv[2]);
diff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c
index b81002a1df..da9345a44b 100644
--- a/builtin/checkout--worker.c
+++ b/builtin/checkout--worker.c
@@ -128,9 +128,9 @@ int cmd_checkout__worker(int argc,
OPT_END()
};
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(checkout_worker_usage,
- checkout_worker_options);
+ show_usage_with_options_if_asked(argc, argv,
+ checkout_worker_usage,
+ checkout_worker_options);
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, checkout_worker_options,
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index a81501098d..e30086c7d4 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -250,9 +250,9 @@ int cmd_checkout_index(int argc,
OPT_END()
};
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(builtin_checkout_index_usage,
- builtin_checkout_index_options);
+ show_usage_with_options_if_asked(argc, argv,
+ builtin_checkout_index_usage,
+ builtin_checkout_index_options);
git_config(git_default_config, NULL);
prefix_length = prefix ? strlen(prefix) : 0;
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index bd70d052e7..8ca75262c5 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -305,6 +305,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
oidset_init(&commits, 0);
if (opts.progress)
progress = start_delayed_progress(
+ the_repository,
_("Collecting commits from input"), 0);
while (strbuf_getline(&buf, stdin) != EOF) {
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 2ca1a57ebb..38457600a4 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -119,8 +119,8 @@ int cmd_commit_tree(int argc,
git_config(git_default_config, NULL);
- if (argc < 2 || !strcmp(argv[1], "-h"))
- usage_with_options(commit_tree_usage, options);
+ show_usage_with_options_if_asked(argc, argv,
+ commit_tree_usage, options);
argc = parse_options(argc, argv, prefix, options, commit_tree_usage, 0);
diff --git a/builtin/commit.c b/builtin/commit.c
index ef5e622c07..c84062bfc1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1559,8 +1559,8 @@ struct repository *repo UNUSED)
OPT_END(),
};
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(builtin_status_usage, builtin_status_options);
+ show_usage_with_options_if_asked(argc, argv,
+ builtin_status_usage, builtin_status_options);
prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
@@ -1736,8 +1736,8 @@ int cmd_commit(int argc,
struct strbuf err = STRBUF_INIT;
int ret = 0;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(builtin_commit_usage, builtin_commit_options);
+ show_usage_with_options_if_asked(argc, argv,
+ builtin_commit_usage, builtin_commit_options);
prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
diff --git a/builtin/credential.c b/builtin/credential.c
index 14c8c6608b..2e11b15dde 100644
--- a/builtin/credential.c
+++ b/builtin/credential.c
@@ -18,7 +18,8 @@ int cmd_credential(int argc,
git_config(git_default_config, NULL);
- if (argc != 2 || !strcmp(argv[1], "-h"))
+ show_usage_if_asked(argc, argv, usage_msg);
+ if (argc != 2)
usage(usage_msg);
op = argv[1];
@@ -32,15 +33,15 @@ int cmd_credential(int argc,
die("unable to read credential from stdin");
if (!strcmp(op, "fill")) {
- credential_fill(&c, 0);
+ credential_fill(the_repository, &c, 0);
credential_next_state(&c);
credential_write(&c, stdout, CREDENTIAL_OP_RESPONSE);
} else if (!strcmp(op, "approve")) {
credential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);
- credential_approve(&c);
+ credential_approve(the_repository, &c);
} else if (!strcmp(op, "reject")) {
credential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);
- credential_reject(&c);
+ credential_reject(the_repository, &c);
} else {
usage(usage_msg);
}
diff --git a/builtin/diagnose.c b/builtin/diagnose.c
index 66a22d918e..33c39bd598 100644
--- a/builtin/diagnose.c
+++ b/builtin/diagnose.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "builtin.h"
#include "abspath.h"
#include "gettext.h"
@@ -58,7 +60,7 @@ int cmd_diagnose(int argc,
}
/* Prepare diagnostics */
- if (create_diagnostics_archive(&zip_path, mode))
+ if (create_diagnostics_archive(the_repository, &zip_path, mode))
die_errno(_("unable to create diagnostics archive %s"),
zip_path.buf);
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index 604b04bb2c..99b1749723 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -29,8 +29,7 @@ int cmd_diff_files(int argc,
int result;
unsigned options = 0;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage(diff_files_usage);
+ show_usage_if_asked(argc, argv, diff_files_usage);
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index ebc824602e..81c0bc8ed7 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -26,8 +26,7 @@ int cmd_diff_index(int argc,
int i;
int result;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage(diff_cache_usage);
+ show_usage_if_asked(argc, argv, diff_cache_usage);
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 40804e7b48..e31cc797fe 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -122,8 +122,7 @@ int cmd_diff_tree(int argc,
int read_stdin = 0;
int merge_base = 0;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage(diff_tree_usage);
+ show_usage_if_asked(argc, argv, diff_tree_usage);
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 0f86392761..2da46fecdc 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -3565,8 +3565,7 @@ int cmd_fast_import(int argc,
{
unsigned int i;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage(fast_import_usage);
+ show_usage_if_asked(argc, argv, fast_import_usage);
reset_pack_idx_option(&pack_idx_opts);
git_pack_config();
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index bed2816c2d..d07eec9e55 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -75,6 +75,8 @@ int cmd_fetch_pack(int argc,
list_objects_filter_init(&args.filter_options);
args.uploadpack = "git-upload-pack";
+ show_usage_if_asked(argc, argv, fetch_pack_usage);
+
for (i = 1; i < argc && *argv[i] == '-'; i++) {
const char *arg = argv[i];
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 0196c54eb6..7a4dcb0716 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -197,7 +197,8 @@ static int traverse_reachable(void)
unsigned int nr = 0;
int result = 0;
if (show_progress)
- progress = start_delayed_progress(_("Checking connectivity"), 0);
+ progress = start_delayed_progress(the_repository,
+ _("Checking connectivity"), 0);
while (pending.nr) {
result |= traverse_one_object(object_array_pop(&pending));
display_progress(progress, ++nr);
@@ -703,7 +704,8 @@ static void fsck_object_dir(const char *path)
fprintf_ln(stderr, _("Checking object directory"));
if (show_progress)
- progress = start_progress(_("Checking object directories"), 256);
+ progress = start_progress(the_repository,
+ _("Checking object directories"), 256);
for_each_loose_file_in_objdir(path, fsck_loose, fsck_cruft, fsck_subdir,
&cb_data);
@@ -879,7 +881,8 @@ static int check_pack_rev_indexes(struct repository *r, int show_progress)
if (show_progress) {
for (struct packed_git *p = get_all_packs(r); p; p = p->next)
pack_count++;
- progress = start_delayed_progress("Verifying reverse pack-indexes", pack_count);
+ progress = start_delayed_progress(the_repository,
+ "Verifying reverse pack-indexes", pack_count);
pack_count = 0;
}
@@ -989,7 +992,8 @@ int cmd_fsck(int argc,
total += p->num_objects;
}
- progress = start_progress(_("Checking objects"), total);
+ progress = start_progress(the_repository,
+ _("Checking objects"), total);
}
for (p = get_all_packs(the_repository); p;
p = p->next) {
diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index 029dc64d6c..0820e524f1 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -1598,8 +1598,8 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix UNUSED
OPT_END()
};
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(builtin_fsmonitor__daemon_usage, options);
+ show_usage_with_options_if_asked(argc, argv,
+ builtin_fsmonitor__daemon_usage, options);
die(_("fsmonitor--daemon not supported on this platform"));
}
diff --git a/builtin/gc.c b/builtin/gc.c
index a9b1c36de2..0bf3533494 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -710,8 +710,8 @@ struct repository *repo UNUSED)
OPT_END()
};
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(builtin_gc_usage, builtin_gc_options);
+ show_usage_with_options_if_asked(argc, argv,
+ builtin_gc_usage, builtin_gc_options);
strvec_pushl(&reflog, "reflog", "expire", "--all", NULL);
strvec_pushl(&repack, "repack", "-d", "-l", NULL);
@@ -1909,7 +1909,7 @@ static int get_random_minute(void)
if (getenv("GIT_TEST_MAINT_SCHEDULER"))
return 13;
- return git_rand() % 60;
+ return git_rand(0) % 60;
}
static int is_launchctl_available(void)
diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c
index 6bec0d1854..e4cd1627b4 100644
--- a/builtin/get-tar-commit-id.c
+++ b/builtin/get-tar-commit-id.c
@@ -13,7 +13,7 @@ static const char builtin_get_tar_commit_id_usage[] =
#define HEADERSIZE (2 * RECORDSIZE)
int cmd_get_tar_commit_id(int argc,
- const char **argv UNUSED,
+ const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
@@ -27,6 +27,8 @@ int cmd_get_tar_commit_id(int argc,
BUG_ON_NON_EMPTY_PREFIX(prefix);
+ show_usage_if_asked(argc, argv, builtin_get_tar_commit_id_usage);
+
if (argc != 1)
usage(builtin_get_tar_commit_id_usage);
diff --git a/builtin/grep.c b/builtin/grep.c
index d00ee76f24..d1427290f7 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1084,7 +1084,7 @@ int cmd_grep(int argc,
}
if (show_in_pager == default_pager)
- show_in_pager = git_pager(1);
+ show_in_pager = git_pager(the_repository, 1);
if (show_in_pager) {
opt.color = 0;
opt.name_only = 1;
@@ -1246,7 +1246,7 @@ int cmd_grep(int argc,
}
if (!show_in_pager && !opt.status_only)
- setup_pager();
+ setup_pager(the_repository);
die_for_incompatible_opt3(!use_index, "--no-index",
untracked, "--untracked",
diff --git a/builtin/help.c b/builtin/help.c
index 05136279cf..c257079ceb 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -658,7 +658,7 @@ int cmd_help(int argc,
case HELP_ACTION_ALL:
opt_mode_usage(argc, "--all", help_format);
if (verbose) {
- setup_pager();
+ setup_pager(the_repository);
list_all_cmds_help(show_external_commands,
show_aliases);
return 0;
@@ -692,7 +692,7 @@ int cmd_help(int argc,
return 0;
case HELP_ACTION_CONFIG:
opt_mode_usage(argc, "--config", help_format);
- setup_pager();
+ setup_pager(the_repository);
list_config_help(SHOW_CONFIG_HUMAN);
printf("\n%s\n", _("'git help config' for more information"));
return 0;
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 0b62b2589f..7025c32fbb 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -282,7 +282,8 @@ static unsigned check_objects(void)
max = get_max_object_index();
if (verbose)
- progress = start_delayed_progress(_("Checking objects"), max);
+ progress = start_delayed_progress(the_repository,
+ _("Checking objects"), max);
for (i = 0; i < max; i++) {
foreign_nr += check_object(get_indexed_object(i));
@@ -1249,6 +1250,7 @@ static void parse_pack_objects(unsigned char *hash)
if (verbose)
progress = start_progress(
+ the_repository,
progress_title ? progress_title :
from_stdin ? _("Receiving objects") : _("Indexing objects"),
nr_objects);
@@ -1329,7 +1331,8 @@ static void resolve_deltas(struct pack_idx_option *opts)
QSORT(ref_deltas, nr_ref_deltas, compare_ref_delta_entry);
if (verbose || show_resolving_progress)
- progress = start_progress(_("Resolving deltas"),
+ progress = start_progress(the_repository,
+ _("Resolving deltas"),
nr_ref_deltas + nr_ofs_deltas);
nr_dispatched = 0;
@@ -1897,8 +1900,7 @@ int cmd_index_pack(int argc,
*/
fetch_if_missing = 0;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage(index_pack_usage);
+ show_usage_if_asked(argc, argv, index_pack_usage);
disable_replace_refs();
fsck_options.walk = mark_link;
diff --git a/builtin/log.c b/builtin/log.c
index 75e1b34123..e41f88945e 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -6,7 +6,6 @@
*/
#define USE_THE_REPOSITORY_VARIABLE
-#define DISABLE_SIGN_COMPARE_WARNINGS
#include "builtin.h"
#include "abspath.h"
@@ -209,7 +208,6 @@ static void cmd_log_init_defaults(struct rev_info *rev,
static void set_default_decoration_filter(struct decoration_filter *decoration_filter)
{
- int i;
char *value = NULL;
struct string_list *include = decoration_filter->include_ref_pattern;
const struct string_list *config_exclude;
@@ -243,7 +241,7 @@ static void set_default_decoration_filter(struct decoration_filter *decoration_f
* No command-line or config options were given, so
* populate with sensible defaults.
*/
- for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
+ for (size_t i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
if (!ref_namespace[i].decoration)
continue;
@@ -369,7 +367,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
if (rev->line_level_traverse)
line_log_init(rev, line_cb.prefix, &line_cb.args);
- setup_pager();
+ setup_pager(the_repository);
}
static void cmd_log_init(int argc, const char **argv, const char *prefix,
@@ -717,14 +715,14 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
unsigned long size;
enum object_type type;
char *buf = repo_read_object_file(the_repository, oid, &type, &size);
- int offset = 0;
+ unsigned long offset = 0;
if (!buf)
return error(_("could not read object %s"), oid_to_hex(oid));
assert(type == OBJ_TAG);
while (offset < size && buf[offset] != '\n') {
- int new_offset = offset + 1;
+ unsigned long new_offset = offset + 1;
const char *ident;
while (new_offset < size && buf[new_offset++] != '\n')
; /* do nothing */
@@ -1316,24 +1314,25 @@ static void print_signature(const char *signature, FILE *file)
static char *find_branch_name(struct rev_info *rev)
{
- int i, positive = -1;
struct object_id branch_oid;
const struct object_id *tip_oid;
const char *ref, *v;
char *full_ref, *branch = NULL;
+ int interesting_found = 0;
+ size_t idx;
- for (i = 0; i < rev->cmdline.nr; i++) {
+ for (size_t i = 0; i < rev->cmdline.nr; i++) {
if (rev->cmdline.rev[i].flags & UNINTERESTING)
continue;
- if (positive < 0)
- positive = i;
- else
+ if (interesting_found)
return NULL;
+ interesting_found = 1;
+ idx = i;
}
- if (positive < 0)
+ if (!interesting_found)
return NULL;
- ref = rev->cmdline.rev[positive].name;
- tip_oid = &rev->cmdline.rev[positive].item->oid;
+ ref = rev->cmdline.rev[idx].name;
+ tip_oid = &rev->cmdline.rev[idx].item->oid;
if (repo_dwim_ref(the_repository, ref, strlen(ref), &branch_oid,
&full_ref, 0) &&
skip_prefix(full_ref, "refs/heads/", &v) &&
@@ -1746,11 +1745,12 @@ struct base_tree_info {
static struct commit *get_base_commit(const struct format_config *cfg,
struct commit **list,
- int total)
+ size_t total)
{
struct commit *base = NULL;
struct commit **rev;
- int i = 0, rev_nr = 0, auto_select, die_on_failure, ret;
+ int auto_select, die_on_failure, ret;
+ size_t i = 0, rev_nr = 0;
switch (cfg->auto_base) {
case AUTO_BASE_NEVER:
@@ -1885,13 +1885,12 @@ define_commit_slab(commit_base, int);
static void prepare_bases(struct base_tree_info *bases,
struct commit *base,
struct commit **list,
- int total)
+ size_t total)
{
struct commit *commit;
struct rev_info revs;
struct diff_options diffopt;
struct commit_base commit_base;
- int i;
if (!base)
return;
@@ -1906,7 +1905,7 @@ static void prepare_bases(struct base_tree_info *bases,
repo_init_revisions(the_repository, &revs, NULL);
revs.max_parents = 1;
revs.topo_order = 1;
- for (i = 0; i < total; i++) {
+ for (size_t i = 0; i < total; i++) {
list[i]->object.flags &= ~UNINTERESTING;
add_pending_object(&revs, &list[i]->object, "rev_list");
*commit_base_at(&commit_base, list[i]) = 1;
@@ -2007,7 +2006,7 @@ int cmd_format_patch(int argc,
struct rev_info rev;
char *to_free = NULL;
struct setup_revision_opt s_r_opt;
- int nr = 0, total, i;
+ size_t nr = 0, total, i;
int use_stdout = 0;
int start_number = -1;
int just_numbers = 0;
@@ -2183,7 +2182,7 @@ int cmd_format_patch(int argc,
fmt_patch_suffix = cfg.fmt_patch_suffix;
/* Make sure "0000-$sub.patch" gives non-negative length for $sub */
- if (cfg.log.fmt_patch_name_max <= strlen("0000-") + strlen(fmt_patch_suffix))
+ if (cfg.log.fmt_patch_name_max <= cast_size_t_to_int(strlen("0000-") + strlen(fmt_patch_suffix)))
cfg.log.fmt_patch_name_max = strlen("0000-") + strlen(fmt_patch_suffix);
if (cover_from_description_arg)
@@ -2296,7 +2295,7 @@ int cmd_format_patch(int argc,
rev.commit_format = CMIT_FMT_MBOXRD;
if (use_stdout) {
- setup_pager();
+ setup_pager(the_repository);
} else if (!rev.diffopt.close_file) {
int saved;
@@ -2499,12 +2498,16 @@ int cmd_format_patch(int argc,
rev.add_signoff = cfg.do_signoff;
if (show_progress)
- progress = start_delayed_progress(_("Generating patches"), total);
- while (0 <= --nr) {
+ progress = start_delayed_progress(the_repository,
+ _("Generating patches"), total);
+ for (i = 0; i < nr; i++) {
+ size_t idx = nr - i - 1;
int shown;
- display_progress(progress, total - nr);
- commit = list[nr];
- rev.nr = total - nr + (start_number - 1);
+
+ display_progress(progress, total - idx);
+ commit = list[idx];
+ rev.nr = total - idx + (start_number - 1);
+
/* Make the second and subsequent mails replies to the first */
if (cfg.thread) {
/* Have we already had a message ID? */
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 15499cd12b..a4431429b7 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -644,8 +644,8 @@ int cmd_ls_files(int argc,
};
int ret = 0;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(ls_files_usage, builtin_ls_files_options);
+ show_usage_with_options_if_asked(argc, argv,
+ ls_files_usage, builtin_ls_files_options);
prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index e17dec27b1..8de7ba7de1 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -83,7 +83,7 @@ int cmd_mailinfo(int argc,
OPT_END()
};
- setup_mailinfo(&mi);
+ setup_mailinfo(the_repository, &mi);
meta_charset.policy = CHARSET_DEFAULT;
argc = parse_options(argc, argv, prefix, options, mailinfo_usage, 0);
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 41dd304731..264df6259a 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -284,6 +284,8 @@ int cmd_mailsplit(int argc,
BUG_ON_NON_EMPTY_PREFIX(prefix);
+ show_usage_if_asked(argc, argv, git_mailsplit_usage);
+
for (argp = argv+1; *argp; argp++) {
const char *arg = *argp;
@@ -297,8 +299,6 @@ int cmd_mailsplit(int argc,
continue;
} else if ( arg[1] == 'f' ) {
nr = strtol(arg+2, NULL, 10);
- } else if ( arg[1] == 'h' ) {
- usage(git_mailsplit_usage);
} else if ( arg[1] == 'b' && !arg[2] ) {
allow_bare = 1;
} else if (!strcmp(arg, "--keep-cr")) {
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index a20c93b11a..123c81515e 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -8,7 +8,7 @@
#include "parse-options.h"
#include "commit-reach.h"
-static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
+static int show_merge_base(struct commit **rev, size_t rev_nr, int show_all)
{
struct commit_list *result = NULL, *r;
@@ -149,7 +149,7 @@ int cmd_merge_base(int argc,
struct repository *repo UNUSED)
{
struct commit **rev;
- int rev_nr = 0;
+ size_t rev_nr = 0;
int show_all = 0;
int cmdmode = 0;
int ret;
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index 342699edb7..3314fb1336 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -75,6 +75,9 @@ static void merge_all(void)
}
}
+static const char usage_string[] =
+"git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])";
+
int cmd_merge_index(int argc,
const char **argv,
const char *prefix UNUSED,
@@ -87,8 +90,10 @@ int cmd_merge_index(int argc,
*/
signal(SIGCHLD, SIG_DFL);
+ show_usage_if_asked(argc, argv, usage_string);
+
if (argc < 3)
- usage("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])");
+ usage(usage_string);
repo_read_index(the_repository);
diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
index 3ecd9172f1..97b8a792c7 100644
--- a/builtin/merge-ours.c
+++ b/builtin/merge-ours.c
@@ -23,8 +23,7 @@ int cmd_merge_ours(int argc,
const char *prefix UNUSED,
struct repository *repo UNUSED)
{
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage(builtin_merge_ours_usage);
+ show_usage_if_asked(argc, argv, builtin_merge_ours_usage);
/*
* The contents of the current index becomes the tree we
diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c
index 1dd295558b..abfc060e28 100644
--- a/builtin/merge-recursive.c
+++ b/builtin/merge-recursive.c
@@ -38,6 +38,12 @@ int cmd_merge_recursive(int argc,
if (argv[0] && ends_with(argv[0], "-subtree"))
o.subtree_shift = "";
+ if (argc == 2 && !strcmp(argv[1], "-h")) {
+ struct strbuf msg = STRBUF_INIT;
+ strbuf_addf(&msg, builtin_merge_recursive_usage, argv[0]);
+ show_usage_if_asked(argc, argv, msg.buf);
+ }
+
if (argc < 4)
usagef(builtin_merge_recursive_usage, argv[0]);
diff --git a/builtin/merge.c b/builtin/merge.c
index 5f67007bba..ba9faf126a 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1300,8 +1300,8 @@ int cmd_merge(int argc,
void *branch_to_free;
int orig_argc = argc;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(builtin_merge_usage, builtin_merge_options);
+ show_usage_with_options_if_asked(argc, argv,
+ builtin_merge_usage, builtin_merge_options);
prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 1c3b842651..d51c021d99 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1264,7 +1264,8 @@ static void write_pack_file(void)
struct object_entry **write_order;
if (progress > pack_to_stdout)
- progress_state = start_progress(_("Writing objects"), nr_result);
+ progress_state = start_progress(the_repository,
+ _("Writing objects"), nr_result);
ALLOC_ARRAY(written_list, to_pack.nr_objects);
write_order = compute_write_order();
@@ -2400,7 +2401,8 @@ static void get_object_details(void)
struct object_entry **sorted_by_offset;
if (progress)
- progress_state = start_progress(_("Counting objects"),
+ progress_state = start_progress(the_repository,
+ _("Counting objects"),
to_pack.nr_objects);
CALLOC_ARRAY(sorted_by_offset, to_pack.nr_objects);
@@ -3220,7 +3222,8 @@ static void prepare_pack(int window, int depth)
unsigned nr_done = 0;
if (progress)
- progress_state = start_progress(_("Compressing objects"),
+ progress_state = start_progress(the_repository,
+ _("Compressing objects"),
nr_deltas);
QSORT(delta_list, n, type_size_sort);
ll_find_deltas(delta_list, n, window+1, depth, &nr_done);
@@ -3648,7 +3651,8 @@ static void add_objects_in_unpacked_packs(void);
static void enumerate_cruft_objects(void)
{
if (progress)
- progress_state = start_progress(_("Enumerating cruft objects"), 0);
+ progress_state = start_progress(the_repository,
+ _("Enumerating cruft objects"), 0);
add_objects_in_unpacked_packs();
add_unreachable_loose_objects();
@@ -3674,7 +3678,8 @@ static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs
revs.ignore_missing_links = 1;
if (progress)
- progress_state = start_progress(_("Enumerating cruft objects"), 0);
+ progress_state = start_progress(the_repository,
+ _("Enumerating cruft objects"), 0);
ret = add_unseen_recent_objects_to_traversal(&revs, cruft_expiration,
set_cruft_mtime, 1);
stop_progress(&progress_state);
@@ -3693,7 +3698,8 @@ static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs
if (prepare_revision_walk(&revs))
die(_("revision walk setup failed"));
if (progress)
- progress_state = start_progress(_("Traversing cruft objects"), 0);
+ progress_state = start_progress(the_repository,
+ _("Traversing cruft objects"), 0);
nr_seen = 0;
traverse_commit_list(&revs, show_cruft_commit, show_cruft_object, NULL);
@@ -4625,7 +4631,8 @@ int cmd_pack_objects(int argc,
prepare_packing_data(the_repository, &to_pack);
if (progress && !cruft)
- progress_state = start_progress(_("Enumerating objects"), 0);
+ progress_state = start_progress(the_repository,
+ _("Enumerating objects"), 0);
if (stdin_packs) {
/* avoids adding objects in excluded packs */
ignore_packed_keep_in_core = 1;
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index e046575871..3febe732f8 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -595,8 +595,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
struct strbuf idx_name = STRBUF_INIT;
char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage(pack_redundant_usage);
+ show_usage_if_asked(argc, argv, pack_redundant_usage);
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
diff --git a/builtin/prune.c b/builtin/prune.c
index aeff9ca1b3..1c357fffd8 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -64,7 +64,8 @@ static void perform_reachability_traversal(struct rev_info *revs)
return;
if (show_progress)
- progress = start_delayed_progress(_("Checking connectivity"), 0);
+ progress = start_delayed_progress(the_repository,
+ _("Checking connectivity"), 0);
mark_reachable_objects(revs, 1, expire, progress);
stop_progress(&progress);
initialized = 1;
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 0498fff3c9..6c9eaf3788 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1223,9 +1223,9 @@ int cmd_rebase(int argc,
};
int i;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(builtin_rebase_usage,
- builtin_rebase_options);
+ show_usage_with_options_if_asked(argc, argv,
+ builtin_rebase_usage,
+ builtin_rebase_options);
prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index c2e9103f11..0fb0266cfd 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -174,7 +174,7 @@ static int receive_pack_config(const char *var, const char *value,
char *path;
if (git_config_pathname(&path, var, value))
- return 1;
+ return -1;
strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
fsck_msg_types.len ? ',' : '=', path);
free(path);
@@ -2239,7 +2239,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
strvec_push(&child.args, alt_shallow_file);
}
- tmp_objdir = tmp_objdir_create("incoming");
+ tmp_objdir = tmp_objdir_create(the_repository, "incoming");
if (!tmp_objdir) {
if (err_fd > 0)
close(err_fd);
@@ -2628,7 +2628,7 @@ int cmd_receive_pack(int argc,
}
}
if (auto_update_server_info)
- update_server_info(0);
+ update_server_info(the_repository, 0);
clear_shallow_info(&si);
}
if (use_sideband)
diff --git a/builtin/remote-ext.c b/builtin/remote-ext.c
index 33c8ae0fc7..bd2037f27d 100644
--- a/builtin/remote-ext.c
+++ b/builtin/remote-ext.c
@@ -202,6 +202,8 @@ int cmd_remote_ext(int argc,
{
BUG_ON_NON_EMPTY_PREFIX(prefix);
+ show_usage_if_asked(argc, argv, usage_msg);
+
if (argc != 3)
usage(usage_msg);
diff --git a/builtin/remote-fd.c b/builtin/remote-fd.c
index ae896eda57..39908546ba 100644
--- a/builtin/remote-fd.c
+++ b/builtin/remote-fd.c
@@ -64,6 +64,7 @@ int cmd_remote_fd(int argc,
BUG_ON_NON_EMPTY_PREFIX(prefix);
+ show_usage_if_asked(argc, argv, usage_msg);
if (argc != 3)
usage(usage_msg);
diff --git a/builtin/remote.c b/builtin/remote.c
index 0435963286..315cbb88e6 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -820,7 +820,8 @@ static int mv(int argc, const char **argv, const char *prefix,
* Count symrefs twice, since "renaming" them is done by
* deleting and recreating them in two separate passes.
*/
- progress = start_progress(_("Renaming remote references"),
+ progress = start_progress(the_repository,
+ _("Renaming remote references"),
rename.remote_branches->nr + rename.symrefs_nr);
}
for (i = 0; i < remote_branches.nr; i++) {
diff --git a/builtin/repack.c b/builtin/repack.c
index 0c6dad7df4..81d13630ea 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1565,7 +1565,7 @@ int cmd_repack(int argc,
}
if (run_update_server_info)
- update_server_info(0);
+ update_server_info(the_repository, 0);
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) {
unsigned flags = 0;
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 3196da7b2d..beb8c2529d 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -542,8 +542,7 @@ int cmd_rev_list(int argc,
const char *show_progress = NULL;
int ret = 0;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage(rev_list_usage);
+ show_usage_if_asked(argc, argv, rev_list_usage);
git_config(git_default_config, NULL);
repo_init_revisions(the_repository, &revs, prefix);
@@ -735,7 +734,8 @@ int cmd_rev_list(int argc,
revs.limited = 1;
if (show_progress)
- progress = start_delayed_progress(show_progress, 0);
+ progress = start_delayed_progress(the_repository,
+ show_progress, 0);
if (use_bitmap_index) {
if (!try_bitmap_count(&revs, filter_provided_objects))
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 949747a6b6..428c866c05 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -713,6 +713,8 @@ int cmd_rev_parse(int argc,
int seen_end_of_options = 0;
enum format_type format = FORMAT_DEFAULT;
+ show_usage_if_asked(argc, argv, builtin_rev_parse_usage);
+
if (argc > 1 && !strcmp("--parseopt", argv[1]))
return cmd_parseopt(argc - 1, argv + 1, prefix);
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index 59b626aae8..8d461008e2 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -317,7 +317,7 @@ int cmd_send_pack(int argc,
set_ref_status_for_push(remote_refs, args.send_mirror,
args.force_update);
- ret = send_pack(&args, fd, conn, remote_refs, &extra_have);
+ ret = send_pack(the_repository, &args, fd, conn, remote_refs, &extra_have);
if (helper_status)
print_helper_status(remote_refs);
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index 6da2825753..fb5fcbc40a 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -26,6 +26,9 @@ static char *create_temp_file(struct object_id *oid)
return path;
}
+static const char usage_msg[] =
+"git unpack-file <blob>";
+
int cmd_unpack_file(int argc,
const char **argv,
const char *prefix UNUSED,
@@ -33,8 +36,9 @@ int cmd_unpack_file(int argc,
{
struct object_id oid;
- if (argc != 2 || !strcmp(argv[1], "-h"))
- usage("git unpack-file <blob>");
+ show_usage_if_asked(argc, argv, usage_msg);
+ if (argc != 2)
+ usage(usage_msg);
if (repo_get_oid(the_repository, argv[1], &oid))
die("Not a valid object name %s", argv[1]);
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 2197d6d933..a1c28e97e7 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -590,7 +590,8 @@ static void unpack_all(void)
use(sizeof(struct pack_header));
if (!quiet)
- progress = start_progress(_("Unpacking objects"), nr_objects);
+ progress = start_progress(the_repository,
+ _("Unpacking objects"), nr_objects);
CALLOC_ARRAY(obj_list, nr_objects);
begin_odb_transaction();
for (i = 0; i < nr_objects; i++) {
@@ -619,6 +620,8 @@ int cmd_unpack_objects(int argc,
quiet = !isatty(2);
+ show_usage_if_asked(argc, argv, unpack_usage);
+
for (i = 1 ; i < argc; i++) {
const char *arg = argv[i];
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 74bbad9f87..b2f6b1a3fb 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -1045,8 +1045,8 @@ int cmd_update_index(int argc,
OPT_END()
};
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(update_index_usage, options);
+ show_usage_with_options_if_asked(argc, argv,
+ update_index_usage, options);
git_config(git_default_config, NULL);
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index 6769611a02..47a3f0bdd9 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -27,5 +27,5 @@ int cmd_update_server_info(int argc,
if (argc > 0)
usage_with_options(update_server_info_usage, options);
- return !!update_server_info(force);
+ return !!update_server_info(the_repository, force);
}
diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index 9e9343f121..97d7c9522f 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -27,7 +27,8 @@ int cmd_upload_archive_writer(int argc,
const char *arg_cmd = "argument ";
int ret;
- if (argc != 2 || !strcmp(argv[1], "-h"))
+ show_usage_if_asked(argc, argv, upload_archive_usage);
+ if (argc != 2)
usage(upload_archive_usage);
if (!enter_repo(argv[1], 0))
@@ -92,8 +93,7 @@ struct repository *repo UNUSED)
BUG_ON_NON_EMPTY_PREFIX(prefix);
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage(upload_archive_usage);
+ show_usage_if_asked(argc, argv, upload_archive_usage);
/*
* Set up sideband subprocess.
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index dd63d6eadf..c2bbc035ab 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "builtin.h"
#include "exec-cmd.h"
#include "gettext.h"
@@ -63,9 +65,9 @@ int cmd_upload_pack(int argc,
switch (determine_protocol_version_server()) {
case protocol_v2:
if (advertise_refs)
- protocol_v2_advertise_capabilities();
+ protocol_v2_advertise_capabilities(the_repository);
else
- protocol_v2_serve_loop(stateless_rpc);
+ protocol_v2_serve_loop(the_repository, stateless_rpc);
break;
case protocol_v1:
/*
diff --git a/builtin/var.c b/builtin/var.c
index 1449656cc9..ada642a9fe 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -42,7 +42,7 @@ static char *sequence_editor(int ident_flag UNUSED)
static char *pager(int ident_flag UNUSED)
{
- const char *pgm = git_pager(1);
+ const char *pgm = git_pager(the_repository, 1);
if (!pgm)
pgm = "cat";
@@ -221,6 +221,7 @@ int cmd_var(int argc,
const struct git_var *git_var;
char *val;
+ show_usage_if_asked(argc, argv, var_usage);
if (argc != 2)
usage(var_usage);
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 433070a3bd..5044cb7fa0 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -333,7 +333,7 @@ void prepare_loose_object_bulk_checkin(void)
if (!odb_transaction_nesting || bulk_fsync_objdir)
return;
- bulk_fsync_objdir = tmp_objdir_create("bulk-fsync");
+ bulk_fsync_objdir = tmp_objdir_create(the_repository, "bulk-fsync");
if (bulk_fsync_objdir)
tmp_objdir_replace_primary_odb(bulk_fsync_objdir, 0);
}
diff --git a/commit-graph.c b/commit-graph.c
index 0df66e5a24..2a2999a6b8 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1534,6 +1534,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Loading known commits in commit graph"),
ctx->oids.nr);
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1551,6 +1552,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
*/
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Expanding reachable commits in commit graph"),
0);
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1571,6 +1573,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Clearing commit marks in commit graph"),
ctx->oids.nr);
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1688,6 +1691,7 @@ static void compute_topological_levels(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
info.progress = ctx->progress
= start_delayed_progress(
+ the_repository,
_("Computing commit graph topological levels"),
ctx->commits.nr);
@@ -1722,6 +1726,7 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
info.progress = ctx->progress
= start_delayed_progress(
+ the_repository,
_("Computing commit graph generation numbers"),
ctx->commits.nr);
@@ -1798,6 +1803,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
progress = start_delayed_progress(
+ the_repository,
_("Computing commit changed paths Bloom filters"),
ctx->commits.nr);
@@ -1877,6 +1883,7 @@ int write_commit_graph_reachable(struct object_directory *odb,
data.commits = &commits;
if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
data.progress = start_delayed_progress(
+ the_repository,
_("Collecting referenced commits"), 0);
refs_for_each_ref(get_main_ref_store(the_repository), add_ref_to_set,
@@ -1908,7 +1915,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
"Finding commits for commit graph in %"PRIuMAX" packs",
pack_indexes->nr),
(uintmax_t)pack_indexes->nr);
- ctx->progress = start_delayed_progress(progress_title.buf, 0);
+ ctx->progress = start_delayed_progress(the_repository,
+ progress_title.buf, 0);
ctx->progress_done = 0;
}
for (i = 0; i < pack_indexes->nr; i++) {
@@ -1959,6 +1967,7 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
{
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Finding commits for commit graph among packed objects"),
ctx->approx_nr_objects);
for_each_packed_object(ctx->r, add_packed_commits, ctx,
@@ -1977,6 +1986,7 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
ctx->num_extra_edges = 0;
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Finding extra edges in commit graph"),
ctx->oids.nr);
oid_array_sort(&ctx->oids);
@@ -2136,6 +2146,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
get_num_chunks(cf)),
get_num_chunks(cf));
ctx->progress = start_delayed_progress(
+ the_repository,
progress_title.buf,
st_mult(get_num_chunks(cf), ctx->commits.nr));
}
@@ -2348,6 +2359,7 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Scanning merged commits"),
ctx->commits.nr);
@@ -2392,7 +2404,8 @@ static void merge_commit_graphs(struct write_commit_graph_context *ctx)
current_graph_number--;
if (ctx->report_progress)
- ctx->progress = start_delayed_progress(_("Merging commit-graph"), 0);
+ ctx->progress = start_delayed_progress(the_repository,
+ _("Merging commit-graph"), 0);
merge_commit_graph(ctx, g);
stop_progress(&ctx->progress);
@@ -2874,7 +2887,8 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW))
total += g->num_commits_in_base;
- progress = start_progress(_("Verifying commits in commit graph"),
+ progress = start_progress(the_repository,
+ _("Verifying commits in commit graph"),
total);
}
diff --git a/commit-reach.c b/commit-reach.c
index e3edd11995..a339e41aa4 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -1,5 +1,4 @@
#define USE_THE_REPOSITORY_VARIABLE
-#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
#include "commit.h"
@@ -42,8 +41,7 @@ static int compare_commits_by_gen(const void *_a, const void *_b)
static int queue_has_nonstale(struct prio_queue *queue)
{
- int i;
- for (i = 0; i < queue->nr; i++) {
+ for (size_t i = 0; i < queue->nr; i++) {
struct commit *commit = queue->array[i].data;
if (!(commit->object.flags & STALE))
return 1;
@@ -213,12 +211,13 @@ int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result)
}
static int remove_redundant_no_gen(struct repository *r,
- struct commit **array, int cnt)
+ struct commit **array,
+ size_t cnt, size_t *dedup_cnt)
{
struct commit **work;
unsigned char *redundant;
- int *filled_index;
- int i, j, filled;
+ size_t *filled_index;
+ size_t i, j, filled;
CALLOC_ARRAY(work, cnt);
redundant = xcalloc(cnt, 1);
@@ -268,20 +267,22 @@ static int remove_redundant_no_gen(struct repository *r,
for (i = filled = 0; i < cnt; i++)
if (!redundant[i])
array[filled++] = work[i];
+ *dedup_cnt = filled;
free(work);
free(redundant);
free(filled_index);
- return filled;
+ return 0;
}
static int remove_redundant_with_gen(struct repository *r,
- struct commit **array, int cnt)
+ struct commit **array, size_t cnt,
+ size_t *dedup_cnt)
{
- int i, count_non_stale = 0, count_still_independent = cnt;
+ size_t i, count_non_stale = 0, count_still_independent = cnt;
timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
struct commit **walk_start, **sorted;
size_t walk_start_nr = 0, walk_start_alloc = cnt;
- int min_gen_pos = 0;
+ size_t min_gen_pos = 0;
/*
* Sort the input by generation number, ascending. This allows
@@ -327,12 +328,12 @@ static int remove_redundant_with_gen(struct repository *r,
* terminate early. Otherwise, we will do the same amount of work
* as before.
*/
- for (i = walk_start_nr - 1; i >= 0 && count_still_independent > 1; i--) {
+ for (i = walk_start_nr; i && count_still_independent > 1; i--) {
/* push the STALE bits up to min generation */
struct commit_list *stack = NULL;
- commit_list_insert(walk_start[i], &stack);
- walk_start[i]->object.flags |= STALE;
+ commit_list_insert(walk_start[i - 1], &stack);
+ walk_start[i - 1]->object.flags |= STALE;
while (stack) {
struct commit_list *parents;
@@ -389,10 +390,12 @@ static int remove_redundant_with_gen(struct repository *r,
clear_commit_marks_many(walk_start_nr, walk_start, STALE);
free(walk_start);
- return count_non_stale;
+ *dedup_cnt = count_non_stale;
+ return 0;
}
-static int remove_redundant(struct repository *r, struct commit **array, int cnt)
+static int remove_redundant(struct repository *r, struct commit **array,
+ size_t cnt, size_t *dedup_cnt)
{
/*
* Some commit in the array may be an ancestor of
@@ -402,31 +405,30 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
* that number.
*/
if (generation_numbers_enabled(r)) {
- int i;
-
/*
* If we have a single commit with finite generation
* number, then the _with_gen algorithm is preferred.
*/
- for (i = 0; i < cnt; i++) {
+ for (size_t i = 0; i < cnt; i++) {
if (commit_graph_generation(array[i]) < GENERATION_NUMBER_INFINITY)
- return remove_redundant_with_gen(r, array, cnt);
+ return remove_redundant_with_gen(r, array, cnt, dedup_cnt);
}
}
- return remove_redundant_no_gen(r, array, cnt);
+ return remove_redundant_no_gen(r, array, cnt, dedup_cnt);
}
static int get_merge_bases_many_0(struct repository *r,
struct commit *one,
- int n,
+ size_t n,
struct commit **twos,
int cleanup,
struct commit_list **result)
{
struct commit_list *list;
struct commit **rslt;
- int cnt, i;
+ size_t cnt, i;
+ int ret;
if (merge_bases_many(r, one, n, twos, result) < 0)
return -1;
@@ -453,8 +455,8 @@ static int get_merge_bases_many_0(struct repository *r,
clear_commit_marks(one, all_flags);
clear_commit_marks_many(n, twos, all_flags);
- cnt = remove_redundant(r, rslt, cnt);
- if (cnt < 0) {
+ ret = remove_redundant(r, rslt, cnt, &cnt);
+ if (ret < 0) {
free(rslt);
return -1;
}
@@ -466,7 +468,7 @@ static int get_merge_bases_many_0(struct repository *r,
int repo_get_merge_bases_many(struct repository *r,
struct commit *one,
- int n,
+ size_t n,
struct commit **twos,
struct commit_list **result)
{
@@ -475,7 +477,7 @@ int repo_get_merge_bases_many(struct repository *r,
int repo_get_merge_bases_many_dirty(struct repository *r,
struct commit *one,
- int n,
+ size_t n,
struct commit **twos,
struct commit_list **result)
{
@@ -583,7 +585,8 @@ struct commit_list *reduce_heads(struct commit_list *heads)
struct commit_list *p;
struct commit_list *result = NULL, **tail = &result;
struct commit **array;
- int num_head, i;
+ size_t num_head, i;
+ int ret;
if (!heads)
return NULL;
@@ -604,11 +607,13 @@ struct commit_list *reduce_heads(struct commit_list *heads)
p->item->object.flags &= ~STALE;
}
}
- num_head = remove_redundant(the_repository, array, num_head);
- if (num_head < 0) {
+
+ ret = remove_redundant(the_repository, array, num_head, &num_head);
+ if (ret < 0) {
free(array);
return NULL;
}
+
for (i = 0; i < num_head; i++)
tail = &commit_list_insert(array[i], tail)->next;
free(array);
@@ -781,12 +786,12 @@ int commit_contains(struct ref_filter *filter, struct commit *commit,
int can_all_from_reach_with_flag(struct object_array *from,
unsigned int with_flag,
unsigned int assign_flag,
- time_t min_commit_date,
+ timestamp_t min_commit_date,
timestamp_t min_generation)
{
struct commit **list = NULL;
- int i;
- int nr_commits;
+ size_t i;
+ size_t nr_commits;
int result = 1;
ALLOC_ARRAY(list, from->nr);
@@ -884,9 +889,9 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
int cutoff_by_min_date)
{
struct object_array from_objs = OBJECT_ARRAY_INIT;
- time_t min_commit_date = cutoff_by_min_date ? from->item->date : 0;
struct commit_list *from_iter = from, *to_iter = to;
int result;
+ timestamp_t min_commit_date = cutoff_by_min_date ? from->item->date : 0;
timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
while (from_iter) {
@@ -938,8 +943,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
return result;
}
-struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
- struct commit **to, int nr_to,
+struct commit_list *get_reachable_subset(struct commit **from, size_t nr_from,
+ struct commit **to, size_t nr_to,
unsigned int reachable_flag)
{
struct commit **item;
diff --git a/commit-reach.h b/commit-reach.h
index 9a745b7e17..6012402dfc 100644
--- a/commit-reach.h
+++ b/commit-reach.h
@@ -14,12 +14,12 @@ int repo_get_merge_bases(struct repository *r,
struct commit *rev2,
struct commit_list **result);
int repo_get_merge_bases_many(struct repository *r,
- struct commit *one, int n,
+ struct commit *one, size_t n,
struct commit **twos,
struct commit_list **result);
/* To be used only when object flags after this call no longer matter */
int repo_get_merge_bases_many_dirty(struct repository *r,
- struct commit *one, int n,
+ struct commit *one, size_t n,
struct commit **twos,
struct commit_list **result);
@@ -81,7 +81,7 @@ int commit_contains(struct ref_filter *filter, struct commit *commit,
int can_all_from_reach_with_flag(struct object_array *from,
unsigned int with_flag,
unsigned int assign_flag,
- time_t min_commit_date,
+ timestamp_t min_commit_date,
timestamp_t min_generation);
int can_all_from_reach(struct commit_list *from, struct commit_list *to,
int commit_date_cutoff);
@@ -95,8 +95,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
* This method uses the PARENT1 and PARENT2 flags during its operation,
* so be sure these flags are not set before calling the method.
*/
-struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
- struct commit **to, int nr_to,
+struct commit_list *get_reachable_subset(struct commit **from, size_t nr_from,
+ struct commit **to, size_t nr_to,
unsigned int reachable_flag);
struct ahead_behind_count {
diff --git a/commit.c b/commit.c
index a127fe60c5..540660359d 100644
--- a/commit.c
+++ b/commit.c
@@ -778,11 +778,11 @@ static void clear_commit_marks_1(struct commit_list **plist,
}
}
-void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark)
+void clear_commit_marks_many(size_t nr, struct commit **commit, unsigned int mark)
{
struct commit_list *list = NULL;
- while (nr--) {
+ for (size_t i = 0; i < nr; i++) {
clear_commit_marks_1(&list, *commit, mark);
commit++;
}
diff --git a/commit.h b/commit.h
index 943e3d74b2..70c870dae4 100644
--- a/commit.h
+++ b/commit.h
@@ -210,7 +210,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,
struct commit *pop_commit(struct commit_list **stack);
void clear_commit_marks(struct commit *commit, unsigned int mark);
-void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark);
+void clear_commit_marks_many(size_t nr, struct commit **commit, unsigned int mark);
enum rev_sort_order {
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b3b6aa3bae..413911be3b 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2737,12 +2737,17 @@ __git_compute_config_vars_all ()
__git_config_vars_all="$(git --no-pager help --config)"
}
+__git_indirect()
+{
+ eval printf '%s' "\"\$$1\""
+}
+
__git_compute_first_level_config_vars_for_section ()
{
local section="$1"
__git_compute_config_vars
local this_section="__git_first_level_config_vars_for_section_${section}"
- test -n "${!this_section}" ||
+ test -n "$(__git_indirect "${this_section}")" ||
printf -v "__git_first_level_config_vars_for_section_${section}" %s \
"$(echo "$__git_config_vars" | awk -F. "/^${section}\.[a-z]/ { print \$2 }")"
}
@@ -2752,7 +2757,7 @@ __git_compute_second_level_config_vars_for_section ()
local section="$1"
__git_compute_config_vars_all
local this_section="__git_second_level_config_vars_for_section_${section}"
- test -n "${!this_section}" ||
+ test -n "$(__git_indirect "${this_section}")" ||
printf -v "__git_second_level_config_vars_for_section_${section}" %s \
"$(echo "$__git_config_vars_all" | awk -F. "/^${section}\.</ { print \$3 }")"
}
@@ -2907,7 +2912,7 @@ __git_complete_config_variable_name ()
local section="${pfx%.*.}"
__git_compute_second_level_config_vars_for_section "${section}"
local this_section="__git_second_level_config_vars_for_section_${section}"
- __gitcomp "${!this_section}" "$pfx" "$cur_" "$sfx"
+ __gitcomp "$(__git_indirect "${this_section}")" "$pfx" "$cur_" "$sfx"
return
;;
branch.*)
@@ -2917,7 +2922,7 @@ __git_complete_config_variable_name ()
__gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
__git_compute_first_level_config_vars_for_section "${section}"
local this_section="__git_first_level_config_vars_for_section_${section}"
- __gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
+ __gitcomp_nl_append "$(__git_indirect "${this_section}")" "$pfx" "$cur_" "${sfx:- }"
return
;;
pager.*)
@@ -2934,7 +2939,7 @@ __git_complete_config_variable_name ()
__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
__git_compute_first_level_config_vars_for_section "${section}"
local this_section="__git_first_level_config_vars_for_section_${section}"
- __gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
+ __gitcomp_nl_append "$(__git_indirect "${this_section}")" "$pfx" "$cur_" "${sfx:- }"
return
;;
submodule.*)
@@ -2944,7 +2949,7 @@ __git_complete_config_variable_name ()
__gitcomp_nl "$(__git config -f "$(__git rev-parse --show-toplevel)/.gitmodules" --get-regexp 'submodule.*.path' | awk -F. '{print $2}')" "$pfx" "$cur_" "."
__git_compute_first_level_config_vars_for_section "${section}"
local this_section="__git_first_level_config_vars_for_section_${section}"
- __gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
+ __gitcomp_nl_append "$(__git_indirect "${this_section}")" "$pfx" "$cur_" "${sfx:- }"
return
;;
*.*)
diff --git a/credential.c b/credential.c
index 6e6e81c4cb..2594c0c422 100644
--- a/credential.c
+++ b/credential.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
@@ -170,7 +169,7 @@ static int match_partial_url(const char *url, void *cb)
return matches;
}
-static void credential_apply_config(struct credential *c)
+static void credential_apply_config(struct repository *r, struct credential *c)
{
char *normalized_url;
struct urlmatch_config config = URLMATCH_CONFIG_INIT;
@@ -195,7 +194,7 @@ static void credential_apply_config(struct credential *c)
credential_format(c, &url);
normalized_url = url_normalize(url.buf, &config.url);
- git_config(urlmatch_config_entry, &config);
+ repo_config(r, urlmatch_config_entry, &config);
string_list_clear(&config.vars, 1);
free(normalized_url);
urlmatch_config_release(&config);
@@ -262,34 +261,34 @@ static char *credential_ask_one(const char *what, struct credential *c,
return xstrdup(r);
}
-static int credential_getpass(struct credential *c)
+static int credential_getpass(struct repository *r, struct credential *c)
{
int interactive;
char *value;
- if (!git_config_get_maybe_bool("credential.interactive", &interactive) &&
+ if (!repo_config_get_maybe_bool(r, "credential.interactive", &interactive) &&
!interactive) {
- trace2_data_intmax("credential", the_repository,
+ trace2_data_intmax("credential", r,
"interactive/skipped", 1);
return -1;
}
- if (!git_config_get_string("credential.interactive", &value)) {
+ if (!repo_config_get_string(r, "credential.interactive", &value)) {
int same = !strcmp(value, "never");
free(value);
if (same) {
- trace2_data_intmax("credential", the_repository,
+ trace2_data_intmax("credential", r,
"interactive/skipped", 1);
return -1;
}
}
- trace2_region_enter("credential", "interactive", the_repository);
+ trace2_region_enter("credential", "interactive", r);
if (!c->username)
c->username = credential_ask_one("Username", c,
PROMPT_ASKPASS|PROMPT_ECHO);
if (!c->password)
c->password = credential_ask_one("Password", c,
PROMPT_ASKPASS);
- trace2_region_leave("credential", "interactive", the_repository);
+ trace2_region_leave("credential", "interactive", r);
return 0;
}
@@ -502,7 +501,8 @@ static int credential_do(struct credential *c, const char *helper,
return r;
}
-void credential_fill(struct credential *c, int all_capabilities)
+void credential_fill(struct repository *r,
+ struct credential *c, int all_capabilities)
{
int i;
@@ -512,7 +512,7 @@ void credential_fill(struct credential *c, int all_capabilities)
credential_next_state(c);
c->multistage = 0;
- credential_apply_config(c);
+ credential_apply_config(r, c);
if (all_capabilities)
credential_set_all_capabilities(c, CREDENTIAL_OP_INITIAL);
@@ -539,12 +539,12 @@ void credential_fill(struct credential *c, int all_capabilities)
c->helpers.items[i].string);
}
- if (credential_getpass(c) ||
+ if (credential_getpass(r, c) ||
(!c->username && !c->password && !c->credential))
die("unable to get password from user");
}
-void credential_approve(struct credential *c)
+void credential_approve(struct repository *r, struct credential *c)
{
int i;
@@ -555,20 +555,20 @@ void credential_approve(struct credential *c)
credential_next_state(c);
- credential_apply_config(c);
+ credential_apply_config(r, c);
for (i = 0; i < c->helpers.nr; i++)
credential_do(c, c->helpers.items[i].string, "store");
c->approved = 1;
}
-void credential_reject(struct credential *c)
+void credential_reject(struct repository *r, struct credential *c)
{
int i;
credential_next_state(c);
- credential_apply_config(c);
+ credential_apply_config(r, c);
for (i = 0; i < c->helpers.nr; i++)
credential_do(c, c->helpers.items[i].string, "erase");
diff --git a/credential.h b/credential.h
index 63fef3e2ea..c78b72d110 100644
--- a/credential.h
+++ b/credential.h
@@ -4,6 +4,8 @@
#include "string-list.h"
#include "strvec.h"
+struct repository;
+
/**
* The credentials API provides an abstracted way of gathering
* authentication credentials from the user.
@@ -65,7 +67,7 @@
* // Fill in the username and password fields by contacting
* // helpers and/or asking the user. The function will die if it
* // fails.
- * credential_fill(&c);
+ * credential_fill(repo, &c);
*
* // Otherwise, we have a username and password. Try to use it.
*
@@ -222,7 +224,8 @@ void credential_clear(struct credential *);
* If all_capabilities is set, this is an internal user that is prepared
* to deal with all known capabilities, and we should advertise that fact.
*/
-void credential_fill(struct credential *, int all_capabilities);
+void credential_fill(struct repository *, struct credential *,
+ int all_capabilities);
/**
* Inform the credential subsystem that the provided credentials
@@ -231,7 +234,7 @@ void credential_fill(struct credential *, int all_capabilities);
* that they may store the result to be used again. Any errors
* from helpers are ignored.
*/
-void credential_approve(struct credential *);
+void credential_approve(struct repository *, struct credential *);
/**
* Inform the credential subsystem that the provided credentials
@@ -243,7 +246,7 @@ void credential_approve(struct credential *);
* for another call to `credential_fill`). Any errors from helpers
* are ignored.
*/
-void credential_reject(struct credential *);
+void credential_reject(struct repository *, struct credential *);
/**
* Enable all of the supported credential flags in this credential.
diff --git a/delta-islands.c b/delta-islands.c
index 1c465a6041..3aec43fada 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -267,7 +267,8 @@ void resolve_tree_islands(struct repository *r,
QSORT(todo, nr, tree_depth_compare);
if (progress)
- progress_state = start_progress(_("Propagating island marks"), nr);
+ progress_state = start_progress(the_repository,
+ _("Propagating island marks"), nr);
for (i = 0; i < nr; i++) {
struct object_entry *ent = todo[i].entry;
diff --git a/diagnose.c b/diagnose.c
index b11931df86..bd485effea 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "diagnose.h"
#include "compat/disk.h"
@@ -12,6 +10,7 @@
#include "object-store-ll.h"
#include "packfile.h"
#include "parse-options.h"
+#include "repository.h"
#include "write-or-die.h"
struct archive_dir {
@@ -179,7 +178,9 @@ static int add_directory_to_archiver(struct strvec *archiver_args,
return res;
}
-int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
+int create_diagnostics_archive(struct repository *r,
+ struct strbuf *zip_path,
+ enum diagnose_mode mode)
{
struct strvec archiver_args = STRVEC_INIT;
char **argv_copy = NULL;
@@ -218,7 +219,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
strbuf_addstr(&buf, "Collecting diagnostic info\n\n");
get_version_info(&buf, 1);
- strbuf_addf(&buf, "Repository root: %s\n", the_repository->worktree);
+ strbuf_addf(&buf, "Repository root: %s\n", r->worktree);
get_disk_info(&buf);
write_or_die(stdout_fd, buf.buf, buf.len);
strvec_pushf(&archiver_args,
@@ -227,7 +228,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
- dir_file_stats(the_repository->objects->odb, &buf);
+ dir_file_stats(r->objects->odb, &buf);
foreach_alt_odb(dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
@@ -250,13 +251,13 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
}
strvec_pushl(&archiver_args, "--prefix=",
- oid_to_hex(the_hash_algo->empty_tree), "--", NULL);
+ oid_to_hex(r->hash_algo->empty_tree), "--", NULL);
/* `write_archive()` modifies the `argv` passed to it. Let it. */
argv_copy = xmemdupz(archiver_args.v,
sizeof(char *) * archiver_args.nr);
res = write_archive(archiver_args.nr, (const char **)argv_copy, NULL,
- the_repository, NULL, 0);
+ r, NULL, 0);
if (res) {
error(_("failed to write archive"));
goto diagnose_cleanup;
diff --git a/diagnose.h b/diagnose.h
index f525219ab0..f7b38f49f5 100644
--- a/diagnose.h
+++ b/diagnose.h
@@ -4,6 +4,7 @@
#include "strbuf.h"
struct option;
+struct repository;
enum diagnose_mode {
DIAGNOSE_NONE,
@@ -13,6 +14,8 @@ enum diagnose_mode {
int option_parse_diagnose(const struct option *opt, const char *arg, int unset);
-int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode);
+int create_diagnostics_archive(struct repository *r,
+ struct strbuf *zip_path,
+ enum diagnose_mode mode);
#endif /* DIAGNOSE_H */
diff --git a/diff.c b/diff.c
index d28b4114c8..0822ae4433 100644
--- a/diff.c
+++ b/diff.c
@@ -7386,6 +7386,6 @@ void setup_diff_pager(struct diff_options *opt)
* --exit-code" in hooks and other scripts, we do not do so.
*/
if (!opt->flags.exit_with_status &&
- check_pager_config("diff") != 0)
- setup_pager();
+ check_pager_config(the_repository, "diff") != 0)
+ setup_pager(the_repository);
}
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 10bb0321b1..91b77993c7 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -1567,6 +1567,7 @@ void diffcore_rename_extended(struct diff_options *options,
trace2_region_enter("diff", "inexact renames", options->repo);
if (options->show_rename_progress) {
progress = start_delayed_progress(
+ the_repository,
_("Performing inexact rename detection"),
(uint64_t)num_destinations * (uint64_t)num_sources);
}
diff --git a/entry.c b/entry.c
index 53a1c39358..81b321e53d 100644
--- a/entry.c
+++ b/entry.c
@@ -188,7 +188,9 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
dco->state = CE_RETRY;
if (show_progress)
- progress = start_delayed_progress(_("Filtering content"), dco->paths.nr);
+ progress = start_delayed_progress(the_repository,
+ _("Filtering content"),
+ dco->paths.nr);
while (dco->filters.nr > 0) {
for_each_string_list_item(filter, &dco->filters) {
struct string_list available_paths = STRING_LIST_INIT_DUP;
diff --git a/fetch-pack.c b/fetch-pack.c
index 3a227721ed..055e8c3643 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1867,7 +1867,7 @@ int fetch_pack_fsck_config(const char *var, const char *value,
char *path ;
if (git_config_pathname(&path, var, value))
- return 0;
+ return -1;
strbuf_addf(msg_types, "%cskiplist=%s",
msg_types->len ? ',' : '=', path);
free(path);
diff --git a/fsck.c b/fsck.c
index 87ce999a49..9fc4c25ffd 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1353,7 +1353,7 @@ int git_fsck_config(const char *var, const char *value,
struct strbuf sb = STRBUF_INIT;
if (git_config_pathname(&path, var, value))
- return 1;
+ return -1;
strbuf_addf(&sb, "skiplist=%s", path);
free(path);
fsck_set_msg_types(options, sb.buf);
diff --git a/git-compat-util.h b/git-compat-util.h
index e283c46c6f..d43dd248c4 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -701,6 +701,8 @@ int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
+void show_usage_if_asked(int ac, const char **av, const char *err);
+
#ifndef NO_OPENSSL
#ifdef APPLE_COMMON_CRYPTO
#include "compat/apple-common-crypto.h"
diff --git a/git-instaweb.sh b/git-instaweb.sh
index 5ad50160bb..7b44f70789 100755
--- a/git-instaweb.sh
+++ b/git-instaweb.sh
@@ -694,9 +694,9 @@ class GitWebRequestHandler(CGIHTTPRequestHandler):
return result
-bind = "127.0.0.1"
+bind = "0.0.0.0"
if "$local" == "true":
- bind = "0.0.0.0"
+ bind = "127.0.0.1"
# Set our http root directory
# This is a work around for a missing directory argument in older Python versions
diff --git a/git-submodule.sh b/git-submodule.sh
index 03c5a220a2..2999b31fad 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -40,11 +40,11 @@ init=
require_init=
files=
remote=
-nofetch=
+no_fetch=
rebase=
merge=
checkout=
-custom_name=
+name=
depth=
progress=
dissociate=
@@ -52,11 +52,10 @@ single_branch=
jobs=
recommend_shallow=
filter=
-
-isnumber()
-{
- n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1"
-}
+all=
+default=
+summary_limit=
+for_status=
#
# Add a new submodule to the working tree, .gitmodules and the index
@@ -68,31 +67,33 @@ isnumber()
cmd_add()
{
# parse $args after "submodule ... add".
- reference_path=
while test $# -ne 0
do
case "$1" in
-b | --branch)
case "$2" in '') usage ;; esac
- branch=$2
+ branch="--branch=$2"
shift
;;
+ -b* | --branch=*)
+ branch="$1"
+ ;;
-f | --force)
force=$1
;;
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--progress)
- progress=1
+ progress=$1
;;
--reference)
case "$2" in '') usage ;; esac
- reference_path=$2
+ reference="--reference=$2"
shift
;;
--reference=*)
- reference_path="${1#--reference=}"
+ reference="$1"
;;
--ref-format)
case "$2" in '') usage ;; esac
@@ -103,20 +104,23 @@ cmd_add()
ref_format="$1"
;;
--dissociate)
- dissociate=1
+ dissociate=$1
;;
--name)
case "$2" in '') usage ;; esac
- custom_name=$2
+ name="--name=$2"
shift
;;
+ --name=*)
+ name="$1"
+ ;;
--depth)
case "$2" in '') usage ;; esac
depth="--depth=$2"
shift
;;
--depth=*)
- depth=$1
+ depth="$1"
;;
--)
shift
@@ -138,14 +142,14 @@ cmd_add()
fi
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add \
- ${quiet:+--quiet} \
- ${force:+--force} \
- ${progress:+"--progress"} \
- ${branch:+--branch "$branch"} \
- ${reference_path:+--reference "$reference_path"} \
+ $quiet \
+ $force \
+ $progress \
+ ${branch:+"$branch"} \
+ ${reference:+"$reference"} \
${ref_format:+"$ref_format"} \
- ${dissociate:+--dissociate} \
- ${custom_name:+--name "$custom_name"} \
+ $dissociate \
+ ${name:+"$name"} \
${depth:+"$depth"} \
-- \
"$@"
@@ -164,10 +168,10 @@ cmd_foreach()
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--recursive)
- recursive=1
+ recursive=$1
;;
-*)
usage
@@ -180,8 +184,8 @@ cmd_foreach()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach \
- ${quiet:+--quiet} \
- ${recursive:+--recursive} \
+ $quiet \
+ $recursive \
-- \
"$@"
}
@@ -198,7 +202,7 @@ cmd_init()
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--)
shift
@@ -215,7 +219,7 @@ cmd_init()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init \
- ${quiet:+--quiet} \
+ $quiet \
-- \
"$@"
}
@@ -226,7 +230,6 @@ cmd_init()
cmd_deinit()
{
# parse $args after "submodule ... deinit".
- deinit_all=
while test $# -ne 0
do
case "$1" in
@@ -234,10 +237,10 @@ cmd_deinit()
force=$1
;;
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--all)
- deinit_all=t
+ all=$1
;;
--)
shift
@@ -254,9 +257,9 @@ cmd_deinit()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit \
- ${quiet:+--quiet} \
- ${force:+--force} \
- ${deinit_all:+--all} \
+ $quiet \
+ $force \
+ $all \
-- \
"$@"
}
@@ -273,31 +276,31 @@ cmd_update()
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
;;
-v|--verbose)
- quiet=0
+ quiet=
;;
--progress)
- progress=1
+ progress=$1
;;
-i|--init)
- init=1
+ init=$1
;;
--require-init)
- require_init=1
+ require_init=$1
;;
--remote)
- remote=1
+ remote=$1
;;
-N|--no-fetch)
- nofetch=1
+ no_fetch=$1
;;
-f|--force)
force=$1
;;
-r|--rebase)
- rebase=1
+ rebase=$1
;;
--ref-format)
case "$2" in '') usage ;; esac
@@ -316,22 +319,19 @@ cmd_update()
reference="$1"
;;
--dissociate)
- dissociate=1
+ dissociate=$1
;;
-m|--merge)
- merge=1
+ merge=$1
;;
--recursive)
- recursive=1
+ recursive=$1
;;
--checkout)
- checkout=1
- ;;
- --recommend-shallow)
- recommend_shallow="--recommend-shallow"
+ checkout=$1
;;
- --no-recommend-shallow)
- recommend_shallow="--no-recommend-shallow"
+ --recommend-shallow|--no-recommend-shallow)
+ recommend_shallow=$1
;;
--depth)
case "$2" in '') usage ;; esac
@@ -339,21 +339,18 @@ cmd_update()
shift
;;
--depth=*)
- depth=$1
+ depth="$1"
;;
-j|--jobs)
case "$2" in '') usage ;; esac
jobs="--jobs=$2"
shift
;;
- --jobs=*)
- jobs=$1
+ -j*|--jobs=*)
+ jobs="$1"
;;
- --single-branch)
- single_branch="--single-branch"
- ;;
- --no-single-branch)
- single_branch="--no-single-branch"
+ --single-branch|--no-single-branch)
+ single_branch=$1
;;
--filter)
case "$2" in '') usage ;; esac
@@ -378,22 +375,21 @@ cmd_update()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
- ${quiet:+--quiet} \
- ${force:+--force} \
- ${progress:+"--progress"} \
- ${remote:+--remote} \
- ${recursive:+--recursive} \
- ${init:+--init} \
- ${nofetch:+--no-fetch} \
- ${rebase:+--rebase} \
- ${merge:+--merge} \
- ${checkout:+--checkout} \
+ $quiet \
+ $force \
+ $progress \
+ $remote \
+ $recursive \
+ $init \
+ $no_fetch \
+ $rebase \
+ $merge \
+ $checkout \
${ref_format:+"$ref_format"} \
${reference:+"$reference"} \
- ${dissociate:+"--dissociate"} \
+ $dissociate \
${depth:+"$depth"} \
- ${require_init:+--require-init} \
- ${dissociate:+"--dissociate"} \
+ $require_init \
$single_branch \
$recommend_shallow \
$jobs \
@@ -408,9 +404,7 @@ cmd_update()
# $@ = requested path
#
cmd_set_branch() {
- default=
- branch=
-
+ # parse $args after "submodule ... set-branch".
while test $# -ne 0
do
case "$1" in
@@ -418,13 +412,16 @@ cmd_set_branch() {
# we don't do anything with this but we need to accept it
;;
-d|--default)
- default=1
+ default=$1
;;
-b|--branch)
case "$2" in '') usage ;; esac
- branch=$2
+ branch="--branch=$2"
shift
;;
+ -b*|--branch=*)
+ branch="$1"
+ ;;
--)
shift
break
@@ -440,9 +437,9 @@ cmd_set_branch() {
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch \
- ${quiet:+--quiet} \
- ${branch:+--branch "$branch"} \
- ${default:+--default} \
+ $quiet \
+ ${branch:+"$branch"} \
+ $default \
-- \
"$@"
}
@@ -453,11 +450,12 @@ cmd_set_branch() {
# $@ = requested path, requested url
#
cmd_set_url() {
+ # parse $args after "submodule ... set-url".
while test $# -ne 0
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--)
shift
@@ -474,7 +472,7 @@ cmd_set_url() {
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url \
- ${quiet:+--quiet} \
+ $quiet \
-- \
"$@"
}
@@ -488,31 +486,26 @@ cmd_set_url() {
# $@ = [commit (default 'HEAD'),] requested paths (default all)
#
cmd_summary() {
- summary_limit=-1
- for_status=
- diff_cmd=diff-index
-
# parse $args after "submodule ... summary".
while test $# -ne 0
do
case "$1" in
--cached)
- cached=1
+ cached=$1
;;
--files)
- files="$1"
+ files=$1
;;
--for-status)
- for_status="$1"
+ for_status=$1
;;
-n|--summary-limit)
- summary_limit="$2"
- isnumber "$summary_limit" || usage
+ case "$2" in '') usage ;; esac
+ summary_limit="--summary-limit=$2"
shift
;;
- --summary-limit=*)
- summary_limit="${1#--summary-limit=}"
- isnumber "$summary_limit" || usage
+ -n*|--summary-limit=*)
+ summary_limit="$1"
;;
--)
shift
@@ -529,10 +522,10 @@ cmd_summary() {
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper summary \
- ${files:+--files} \
- ${cached:+--cached} \
- ${for_status:+--for-status} \
- ${summary_limit:+-n $summary_limit} \
+ $files \
+ $cached \
+ $for_status \
+ ${summary_limit:+"$summary_limit"} \
-- \
"$@"
}
@@ -553,13 +546,13 @@ cmd_status()
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--cached)
- cached=1
+ cached=$1
;;
--recursive)
- recursive=1
+ recursive=$1
;;
--)
shift
@@ -576,9 +569,9 @@ cmd_status()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status \
- ${quiet:+--quiet} \
- ${cached:+--cached} \
- ${recursive:+--recursive} \
+ $quiet \
+ $cached \
+ $recursive \
-- \
"$@"
}
@@ -590,15 +583,16 @@ cmd_status()
#
cmd_sync()
{
+ # parse $args after "submodule ... sync".
while test $# -ne 0
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
shift
;;
--recursive)
- recursive=1
+ recursive=$1
shift
;;
--)
@@ -615,8 +609,8 @@ cmd_sync()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync \
- ${quiet:+--quiet} \
- ${recursive:+--recursive} \
+ $quiet \
+ $recursive \
-- \
"$@"
}
@@ -639,10 +633,10 @@ do
command=$1
;;
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--cached)
- cached=1
+ cached=$1
;;
--)
break
diff --git a/git.c b/git.c
index 71d644dc1c..a94dab3770 100644
--- a/git.c
+++ b/git.c
@@ -125,7 +125,7 @@ static void commit_pager_choice(void)
setenv("GIT_PAGER", "cat", 1);
break;
case 1:
- setup_pager();
+ setup_pager(the_repository);
break;
default:
break;
@@ -136,7 +136,7 @@ void setup_auto_pager(const char *cmd, int def)
{
if (use_pager != -1 || pager_in_use())
return;
- use_pager = check_pager_config(cmd);
+ use_pager = check_pager_config(the_repository, cmd);
if (use_pager == -1)
use_pager = def;
commit_pager_choice();
@@ -462,12 +462,12 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
precompose_argv_prefix(argc, argv, NULL);
if (use_pager == -1 && run_setup &&
!(p->option & DELAY_PAGER_CONFIG))
- use_pager = check_pager_config(p->cmd);
+ use_pager = check_pager_config(the_repository, p->cmd);
if (use_pager == -1 && p->option & USE_PAGER)
use_pager = 1;
if (run_setup && startup_info->have_repository)
/* get_git_dir() may set up repo, avoid that */
- trace_repo_setup();
+ trace_repo_setup(the_repository);
commit_pager_choice();
if (!help && p->option & NEED_WORK_TREE)
@@ -750,7 +750,7 @@ static void execv_dashed_external(const char **argv)
int status;
if (use_pager == -1 && !is_builtin(argv[0]))
- use_pager = check_pager_config(argv[0]);
+ use_pager = check_pager_config(the_repository, argv[0]);
commit_pager_choice();
strvec_pushf(&cmd.args, "git-%s", argv[0]);
diff --git a/graph.c b/graph.c
index 52205f75c3..26f6fbf000 100644
--- a/graph.c
+++ b/graph.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
@@ -351,7 +350,7 @@ struct git_graph *graph_init(struct rev_info *opt)
if (!column_colors) {
char *string;
- if (git_config_get_string("log.graphcolors", &string)) {
+ if (repo_config_get_string(opt->repo, "log.graphcolors", &string)) {
/* not configured -- use default */
graph_set_column_colors(column_colors_ansi,
column_colors_ansi_max);
diff --git a/http.c b/http.c
index c8fc15aa11..f08b2ae474 100644
--- a/http.c
+++ b/http.c
@@ -609,7 +609,7 @@ static void init_curl_http_auth(CURL *result)
}
}
- credential_fill(&http_auth, 1);
+ credential_fill(the_repository, &http_auth, 1);
if (http_auth.password) {
if (always_auth_proactively()) {
@@ -652,7 +652,7 @@ static void init_curl_proxy_auth(CURL *result)
{
if (proxy_auth.username) {
if (!proxy_auth.password && !proxy_auth.credential)
- credential_fill(&proxy_auth, 1);
+ credential_fill(the_repository, &proxy_auth, 1);
set_proxyauth_name_password(result);
}
@@ -686,7 +686,7 @@ static int has_cert_password(void)
cert_auth.host = xstrdup("");
cert_auth.username = xstrdup("");
cert_auth.path = xstrdup(ssl_cert);
- credential_fill(&cert_auth, 0);
+ credential_fill(the_repository, &cert_auth, 0);
}
return 1;
}
@@ -700,7 +700,7 @@ static int has_proxy_cert_password(void)
proxy_cert_auth.host = xstrdup("");
proxy_cert_auth.username = xstrdup("");
proxy_cert_auth.path = xstrdup(http_proxy_ssl_cert);
- credential_fill(&proxy_cert_auth, 0);
+ credential_fill(the_repository, &proxy_cert_auth, 0);
}
return 1;
}
@@ -1784,9 +1784,9 @@ static int handle_curl_result(struct slot_results *results)
curl_errorstr, sizeof(curl_errorstr));
if (results->curl_result == CURLE_OK) {
- credential_approve(&http_auth);
- credential_approve(&proxy_auth);
- credential_approve(&cert_auth);
+ credential_approve(the_repository, &http_auth);
+ credential_approve(the_repository, &proxy_auth);
+ credential_approve(the_repository, &cert_auth);
return HTTP_OK;
} else if (results->curl_result == CURLE_SSL_CERTPROBLEM) {
/*
@@ -1795,7 +1795,7 @@ static int handle_curl_result(struct slot_results *results)
* with the certificate. So we reject the credential to
* avoid caching or saving a bad password.
*/
- credential_reject(&cert_auth);
+ credential_reject(the_repository, &cert_auth);
return HTTP_NOAUTH;
} else if (results->curl_result == CURLE_SSL_PINNEDPUBKEYNOTMATCH) {
return HTTP_NOMATCHPUBLICKEY;
@@ -1808,7 +1808,7 @@ static int handle_curl_result(struct slot_results *results)
credential_clear_secrets(&http_auth);
return HTTP_REAUTH;
}
- credential_reject(&http_auth);
+ credential_reject(the_repository, &http_auth);
if (always_auth_proactively())
http_proactive_auth = PROACTIVE_AUTH_NONE;
return HTTP_NOAUTH;
@@ -1822,7 +1822,7 @@ static int handle_curl_result(struct slot_results *results)
}
} else {
if (results->http_connectcode == 407)
- credential_reject(&proxy_auth);
+ credential_reject(the_repository, &proxy_auth);
if (!curl_errorstr[0])
strlcpy(curl_errorstr,
curl_easy_strerror(results->curl_result),
@@ -2210,7 +2210,7 @@ static int http_request_reauth(const char *url,
int ret;
if (always_auth_proactively())
- credential_fill(&http_auth, 1);
+ credential_fill(the_repository, &http_auth, 1);
ret = http_request(url, result, target, options);
@@ -2251,7 +2251,7 @@ static int http_request_reauth(const char *url,
BUG("Unknown http_request target");
}
- credential_fill(&http_auth, 1);
+ credential_fill(the_repository, &http_auth, 1);
ret = http_request(url, result, target, options);
}
diff --git a/imap-send.c b/imap-send.c
index 68ab1aea83..6c8f84e836 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -922,7 +922,7 @@ static void server_fill_credential(struct imap_server_conf *srvc, struct credent
cred->username = xstrdup_or_null(srvc->user);
cred->password = xstrdup_or_null(srvc->pass);
- credential_fill(cred, 1);
+ credential_fill(the_repository, cred, 1);
if (!srvc->user)
srvc->user = xstrdup(cred->username);
@@ -1123,7 +1123,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
} /* !preauth */
if (cred.username)
- credential_approve(&cred);
+ credential_approve(the_repository, &cred);
credential_clear(&cred);
/* check the target mailbox exists */
@@ -1150,7 +1150,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
bail:
if (cred.username)
- credential_reject(&cred);
+ credential_reject(the_repository, &cred);
credential_clear(&cred);
out:
@@ -1492,9 +1492,9 @@ static int curl_append_msgs_to_imap(struct imap_server_conf *server,
if (cred.username) {
if (res == CURLE_OK)
- credential_approve(&cred);
+ credential_approve(the_repository, &cred);
else if (res == CURLE_LOGIN_DENIED)
- credential_reject(&cred);
+ credential_reject(the_repository, &cred);
}
credential_clear(&cred);
diff --git a/log-tree.c b/log-tree.c
index d08eb672a9..8b184d6776 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1042,7 +1042,7 @@ static int do_remerge_diff(struct rev_info *opt,
* into the alternative object store list as the primary.
*/
if (opt->remerge_diff && !opt->remerge_objdir) {
- opt->remerge_objdir = tmp_objdir_create("remerge-diff");
+ opt->remerge_objdir = tmp_objdir_create(the_repository, "remerge-diff");
if (!opt->remerge_objdir)
return error(_("unable to create temporary object directory"));
tmp_objdir_replace_primary_odb(opt->remerge_objdir, 1);
diff --git a/mailinfo.c b/mailinfo.c
index aa263bf490..7b001fa5db 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
@@ -1269,7 +1268,7 @@ static int git_mailinfo_config(const char *var, const char *value,
return 0;
}
-void setup_mailinfo(struct mailinfo *mi)
+void setup_mailinfo(struct repository *r, struct mailinfo *mi)
{
memset(mi, 0, sizeof(*mi));
strbuf_init(&mi->name, 0);
@@ -1281,7 +1280,7 @@ void setup_mailinfo(struct mailinfo *mi)
mi->header_stage = 1;
mi->use_inbody_headers = 1;
mi->content_top = mi->content;
- git_config(git_mailinfo_config, mi);
+ repo_config(r, git_mailinfo_config, mi);
}
void clear_mailinfo(struct mailinfo *mi)
diff --git a/mailinfo.h b/mailinfo.h
index f2ffd0349e..1f20664165 100644
--- a/mailinfo.h
+++ b/mailinfo.h
@@ -5,6 +5,8 @@
#define MAX_BOUNDARIES 5
+struct repository;
+
enum quoted_cr_action {
quoted_cr_unset = -1,
quoted_cr_nowarn,
@@ -49,7 +51,7 @@ struct mailinfo {
};
int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action);
-void setup_mailinfo(struct mailinfo *);
+void setup_mailinfo(struct repository *r, struct mailinfo *);
int mailinfo(struct mailinfo *, const char *msg, const char *patch);
void clear_mailinfo(struct mailinfo *);
diff --git a/match-trees.c b/match-trees.c
index a1c8b91eae..ef14ceb594 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
@@ -8,6 +7,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object-store-ll.h"
+#include "repository.h"
static int score_missing(unsigned mode)
{
@@ -54,14 +54,15 @@ static int score_matches(unsigned mode1, unsigned mode2)
return score;
}
-static void *fill_tree_desc_strict(struct tree_desc *desc,
+static void *fill_tree_desc_strict(struct repository *r,
+ struct tree_desc *desc,
const struct object_id *hash)
{
void *buffer;
enum object_type type;
unsigned long size;
- buffer = repo_read_object_file(the_repository, hash, &type, &size);
+ buffer = repo_read_object_file(r, hash, &type, &size);
if (!buffer)
die("unable to read tree (%s)", oid_to_hex(hash));
if (type != OBJ_TREE)
@@ -80,12 +81,13 @@ static int base_name_entries_compare(const struct name_entry *a,
/*
* Inspect two trees, and give a score that tells how similar they are.
*/
-static int score_trees(const struct object_id *hash1, const struct object_id *hash2)
+static int score_trees(struct repository *r,
+ const struct object_id *hash1, const struct object_id *hash2)
{
struct tree_desc one;
struct tree_desc two;
- void *one_buf = fill_tree_desc_strict(&one, hash1);
- void *two_buf = fill_tree_desc_strict(&two, hash2);
+ void *one_buf = fill_tree_desc_strict(r, &one, hash1);
+ void *two_buf = fill_tree_desc_strict(r, &two, hash2);
int score = 0;
for (;;) {
@@ -133,7 +135,8 @@ static int score_trees(const struct object_id *hash1, const struct object_id *ha
/*
* Match one itself and its subtrees with two and pick the best match.
*/
-static void match_trees(const struct object_id *hash1,
+static void match_trees(struct repository *r,
+ const struct object_id *hash1,
const struct object_id *hash2,
int *best_score,
char **best_match,
@@ -141,7 +144,7 @@ static void match_trees(const struct object_id *hash1,
int recurse_limit)
{
struct tree_desc one;
- void *one_buf = fill_tree_desc_strict(&one, hash1);
+ void *one_buf = fill_tree_desc_strict(r, &one, hash1);
while (one.size) {
const char *path;
@@ -152,7 +155,7 @@ static void match_trees(const struct object_id *hash1,
elem = tree_entry_extract(&one, &path, &mode);
if (!S_ISDIR(mode))
goto next;
- score = score_trees(elem, hash2);
+ score = score_trees(r, elem, hash2);
if (*best_score < score) {
free(*best_match);
*best_match = xstrfmt("%s%s", base, path);
@@ -160,7 +163,7 @@ static void match_trees(const struct object_id *hash1,
}
if (recurse_limit) {
char *newbase = xstrfmt("%s%s/", base, path);
- match_trees(elem, hash2, best_score, best_match,
+ match_trees(r, elem, hash2, best_score, best_match,
newbase, recurse_limit - 1);
free(newbase);
}
@@ -175,7 +178,8 @@ static void match_trees(const struct object_id *hash1,
* A tree "oid1" has a subdirectory at "prefix". Come up with a tree object by
* replacing it with another tree "oid2".
*/
-static int splice_tree(const struct object_id *oid1, const char *prefix,
+static int splice_tree(struct repository *r,
+ const struct object_id *oid1, const char *prefix,
const struct object_id *oid2, struct object_id *result)
{
char *subpath;
@@ -194,7 +198,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
if (*subpath)
subpath++;
- buf = repo_read_object_file(the_repository, oid1, &type, &sz);
+ buf = repo_read_object_file(r, oid1, &type, &sz);
if (!buf)
die("cannot read tree %s", oid_to_hex(oid1));
init_tree_desc(&desc, oid1, buf, sz);
@@ -232,15 +236,15 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
oid_to_hex(oid1));
if (*subpath) {
struct object_id tree_oid;
- oidread(&tree_oid, rewrite_here, the_repository->hash_algo);
- status = splice_tree(&tree_oid, subpath, oid2, &subtree);
+ oidread(&tree_oid, rewrite_here, r->hash_algo);
+ status = splice_tree(r, &tree_oid, subpath, oid2, &subtree);
if (status)
return status;
rewrite_with = &subtree;
} else {
rewrite_with = oid2;
}
- hashcpy(rewrite_here, rewrite_with->hash, the_repository->hash_algo);
+ hashcpy(rewrite_here, rewrite_with->hash, r->hash_algo);
status = write_object_file(buf, sz, OBJ_TREE, result);
free(buf);
return status;
@@ -271,7 +275,7 @@ void shift_tree(struct repository *r,
if (!depth_limit)
depth_limit = 2;
- add_score = del_score = score_trees(hash1, hash2);
+ add_score = del_score = score_trees(r, hash1, hash2);
add_prefix = xcalloc(1, 1);
del_prefix = xcalloc(1, 1);
@@ -279,13 +283,13 @@ void shift_tree(struct repository *r,
* See if one's subtree resembles two; if so we need to prefix
* two with a few fake trees to match the prefix.
*/
- match_trees(hash1, hash2, &add_score, &add_prefix, "", depth_limit);
+ match_trees(r, hash1, hash2, &add_score, &add_prefix, "", depth_limit);
/*
* See if two's subtree resembles one; if so we need to
* pick only subtree of two.
*/
- match_trees(hash2, hash1, &del_score, &del_prefix, "", depth_limit);
+ match_trees(r, hash2, hash1, &del_score, &del_prefix, "", depth_limit);
/* Assume we do not have to do any shifting */
oidcpy(shifted, hash2);
@@ -306,7 +310,7 @@ void shift_tree(struct repository *r,
if (!*add_prefix)
goto out;
- splice_tree(hash1, add_prefix, hash2, shifted);
+ splice_tree(r, hash1, add_prefix, hash2, shifted);
out:
free(add_prefix);
@@ -340,16 +344,16 @@ void shift_tree_by(struct repository *r,
if (candidate == 3) {
/* Both are plausible -- we need to evaluate the score */
- int best_score = score_trees(hash1, hash2);
+ int best_score = score_trees(r, hash1, hash2);
int score;
candidate = 0;
- score = score_trees(&sub1, hash2);
+ score = score_trees(r, &sub1, hash2);
if (score > best_score) {
candidate = 1;
best_score = score;
}
- score = score_trees(&sub2, hash1);
+ score = score_trees(r, &sub2, hash1);
if (score > best_score)
candidate = 2;
}
@@ -365,7 +369,7 @@ void shift_tree_by(struct repository *r,
* shift tree2 down by adding shift_prefix above it
* to match tree1.
*/
- splice_tree(hash1, shift_prefix, hash2, shifted);
+ splice_tree(r, hash1, shift_prefix, hash2, shifted);
else
/*
* shift tree2 up by removing shift_prefix from it
diff --git a/meson.build b/meson.build
index 0064eb64f5..623caf7d5e 100644
--- a/meson.build
+++ b/meson.build
@@ -1326,14 +1326,17 @@ if not meson.is_cross_build() and fs.exists('/dev/tty')
endif
https_backend = get_option('https_backend')
+sha1_backend = get_option('sha1_backend')
+sha1_unsafe_backend = get_option('sha1_unsafe_backend')
+sha256_backend = get_option('sha256_backend')
-security_framework = dependency('Security', required: https_backend == 'CommonCrypto')
+security_framework = dependency('Security', required: 'CommonCrypto' in [https_backend, sha1_backend, sha1_unsafe_backend])
core_foundation_framework = dependency('CoreFoundation', required: security_framework.found())
if https_backend == 'auto' and security_framework.found()
https_backend = 'CommonCrypto'
endif
-openssl_required = https_backend == 'openssl' or get_option('sha1_backend') == 'openssl' or get_option('sha256_backend') == 'openssl'
+openssl_required = 'openssl' in [https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
openssl = dependency('openssl', required: openssl_required, default_options: ['default_library=static'])
if https_backend == 'auto' and openssl.found()
https_backend = 'openssl'
@@ -1354,7 +1357,6 @@ if https_backend != 'openssl'
libgit_c_args += '-DNO_OPENSSL'
endif
-sha1_backend = get_option('sha1_backend')
if sha1_backend == 'sha1dc'
libgit_c_args += '-DSHA1_DC'
libgit_c_args += '-DSHA1DC_NO_STANDARD_INCLUDES=1'
@@ -1367,22 +1369,40 @@ if sha1_backend == 'sha1dc'
'sha1dc/sha1.c',
'sha1dc/ubc_check.c',
]
-elif sha1_backend == 'common-crypto'
+endif
+if sha1_backend == 'CommonCrypto' or sha1_unsafe_backend == 'CommonCrypto'
+ if sha1_backend == 'CommonCrypto'
+ libgit_c_args += '-DSHA1_APPLE'
+ endif
+ if sha1_unsafe_backend == 'CommonCrypto'
+ libgit_c_args += '-DSHA1_APPLE_UNSAFE'
+ endif
+
libgit_c_args += '-DCOMMON_DIGEST_FOR_OPENSSL'
- libgit_c_args += '-DSHA1_APPLE'
# Apple CommonCrypto requires chunking
libgit_c_args += '-DSHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L'
-elif sha1_backend == 'openssl'
- libgit_c_args += '-DSHA1_OPENSSL'
+endif
+if sha1_backend == 'openssl' or sha1_unsafe_backend == 'openssl'
+ if sha1_backend == 'openssl'
+ libgit_c_args += '-DSHA1_OPENSSL'
+ endif
+ if sha1_unsafe_backend == 'openssl'
+ libgit_c_args += '-DSHA1_OPENSSL_UNSAFE'
+ endif
+
libgit_dependencies += openssl
-elif sha1_backend == 'block'
- libgit_c_args += '-DSHA1_BLK'
+endif
+if sha1_backend == 'block' or sha1_unsafe_backend == 'block'
+ if sha1_backend == 'block'
+ libgit_c_args += '-DSHA1_BLK'
+ endif
+ if sha1_unsafe_backend == 'block'
+ libgit_c_args += '-DSHA1_BLK_UNSAFE'
+ endif
+
libgit_sources += 'block-sha1/sha1.c'
-else
- error('Unhandled SHA1 backend ' + sha1_backend)
endif
-sha256_backend = get_option('sha256_backend')
if sha256_backend == 'openssl'
libgit_c_args += '-DSHA256_OPENSSL'
libgit_dependencies += openssl
@@ -1493,7 +1513,9 @@ libgit_version_library = static_library('git-version',
'version.c',
version_def_h,
],
- c_args: libgit_c_args,
+ c_args: libgit_c_args + [
+ '-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
+ ],
dependencies: libgit_dependencies,
include_directories: libgit_include_directories,
)
@@ -1923,3 +1945,10 @@ summary({
'perl': perl_features_enabled,
'python': python.found(),
}, section: 'Auto-detected features')
+
+summary({
+ 'https': https_backend,
+ 'sha1': sha1_backend,
+ 'sha1_unsafe': sha1_unsafe_backend,
+ 'sha256': sha256_backend,
+}, section: 'Backends')
diff --git a/meson_options.txt b/meson_options.txt
index f50bb40cdf..89b01bad04 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -49,10 +49,12 @@ option('regex', type: 'feature', value: 'auto',
# Backends.
option('https_backend', type: 'combo', value: 'auto', choices: ['auto', 'openssl', 'CommonCrypto', 'none'],
description: 'The HTTPS backend to use when connecting to remotes.')
-option('sha1_backend', type: 'combo', choices: ['openssl', 'block', 'sha1dc', 'common-crypto'], value: 'sha1dc',
- description: 'The backend used for hashing objects with the SHA1 object format')
+option('sha1_backend', type: 'combo', choices: ['openssl', 'block', 'sha1dc', 'CommonCrypto'], value: 'sha1dc',
+ description: 'The backend used for hashing objects with the SHA1 object format.')
+option('sha1_unsafe_backend', type: 'combo', choices: ['openssl', 'block', 'CommonCrypto', 'none'], value: 'none',
+ description: 'The backend used for hashing data with the SHA1 object format in case no cryptographic security is needed.')
option('sha256_backend', type: 'combo', choices: ['openssl', 'nettle', 'gcrypt', 'block'], value: 'block',
- description: 'The backend used for hashing objects with the SHA256 object format')
+ description: 'The backend used for hashing objects with the SHA256 object format.')
# Build tweaks.
option('macos_use_homebrew_gettext', type: 'boolean', value: true,
diff --git a/midx-write.c b/midx-write.c
index 0066594fa6..b3827b936b 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -1131,7 +1131,8 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
ctx.pack_paths_checked = 0;
if (flags & MIDX_PROGRESS)
- ctx.progress = start_delayed_progress(_("Adding packfiles to multi-pack-index"), 0);
+ ctx.progress = start_delayed_progress(r,
+ _("Adding packfiles to multi-pack-index"), 0);
else
ctx.progress = NULL;
@@ -1539,7 +1540,9 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
CALLOC_ARRAY(count, m->num_packs);
if (flags & MIDX_PROGRESS)
- progress = start_delayed_progress(_("Counting referenced objects"),
+ progress = start_delayed_progress(
+ r,
+ _("Counting referenced objects"),
m->num_objects);
for (i = 0; i < m->num_objects; i++) {
int pack_int_id = nth_midxed_pack_int_id(m, i);
@@ -1549,7 +1552,9 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
stop_progress(&progress);
if (flags & MIDX_PROGRESS)
- progress = start_delayed_progress(_("Finding and deleting unreferenced packfiles"),
+ progress = start_delayed_progress(
+ r,
+ _("Finding and deleting unreferenced packfiles"),
m->num_packs);
for (i = 0; i < m->num_packs; i++) {
char *pack_name;
diff --git a/midx.c b/midx.c
index f8a75cafd4..d91088efb8 100644
--- a/midx.c
+++ b/midx.c
@@ -907,7 +907,8 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
midx_report(_("incorrect checksum"));
if (flags & MIDX_PROGRESS)
- progress = start_delayed_progress(_("Looking for referenced packfiles"),
+ progress = start_delayed_progress(r,
+ _("Looking for referenced packfiles"),
m->num_packs + m->num_packs_in_base);
for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
if (prepare_midx_pack(r, m, i))
@@ -927,7 +928,8 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
}
if (flags & MIDX_PROGRESS)
- progress = start_sparse_progress(_("Verifying OID order in multi-pack-index"),
+ progress = start_sparse_progress(r,
+ _("Verifying OID order in multi-pack-index"),
m->num_objects - 1);
for (curr = m; curr; curr = curr->base_midx) {
@@ -959,14 +961,17 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
}
if (flags & MIDX_PROGRESS)
- progress = start_sparse_progress(_("Sorting objects by packfile"),
+ progress = start_sparse_progress(r,
+ _("Sorting objects by packfile"),
m->num_objects);
display_progress(progress, 0); /* TODO: Measure QSORT() progress */
QSORT(pairs, m->num_objects, compare_pair_pos_vs_id);
stop_progress(&progress);
if (flags & MIDX_PROGRESS)
- progress = start_sparse_progress(_("Verifying object offsets"), m->num_objects);
+ progress = start_sparse_progress(r,
+ _("Verifying object offsets"),
+ m->num_objects);
for (i = 0; i < m->num_objects + m->num_objects_in_base; i++) {
struct object_id oid;
struct pack_entry e;
diff --git a/object-file.c b/object-file.c
index 5b792b3dd4..aeca61b8ae 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1970,54 +1970,59 @@ static void write_object_file_prepare_literally(const struct git_hash_algo *algo
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
}
-static int check_collision(const char *filename_a, const char *filename_b)
+#define CHECK_COLLISION_DEST_VANISHED -2
+
+static int check_collision(const char *source, const char *dest)
{
- char buf_a[4096], buf_b[4096];
- int fd_a = -1, fd_b = -1;
+ char buf_source[4096], buf_dest[4096];
+ int fd_source = -1, fd_dest = -1;
int ret = 0;
- fd_a = open(filename_a, O_RDONLY);
- if (fd_a < 0) {
- ret = error_errno(_("unable to open %s"), filename_a);
+ fd_source = open(source, O_RDONLY);
+ if (fd_source < 0) {
+ ret = error_errno(_("unable to open %s"), source);
goto out;
}
- fd_b = open(filename_b, O_RDONLY);
- if (fd_b < 0) {
- ret = error_errno(_("unable to open %s"), filename_b);
+ fd_dest = open(dest, O_RDONLY);
+ if (fd_dest < 0) {
+ if (errno != ENOENT)
+ ret = error_errno(_("unable to open %s"), dest);
+ else
+ ret = CHECK_COLLISION_DEST_VANISHED;
goto out;
}
while (1) {
ssize_t sz_a, sz_b;
- sz_a = read_in_full(fd_a, buf_a, sizeof(buf_a));
+ sz_a = read_in_full(fd_source, buf_source, sizeof(buf_source));
if (sz_a < 0) {
- ret = error_errno(_("unable to read %s"), filename_a);
+ ret = error_errno(_("unable to read %s"), source);
goto out;
}
- sz_b = read_in_full(fd_b, buf_b, sizeof(buf_b));
+ sz_b = read_in_full(fd_dest, buf_dest, sizeof(buf_dest));
if (sz_b < 0) {
- ret = error_errno(_("unable to read %s"), filename_b);
+ ret = error_errno(_("unable to read %s"), dest);
goto out;
}
- if (sz_a != sz_b || memcmp(buf_a, buf_b, sz_a)) {
+ if (sz_a != sz_b || memcmp(buf_source, buf_dest, sz_a)) {
ret = error(_("files '%s' and '%s' differ in contents"),
- filename_a, filename_b);
+ source, dest);
goto out;
}
- if (sz_a < sizeof(buf_a))
+ if (sz_a < sizeof(buf_source))
break;
}
out:
- if (fd_a > -1)
- close(fd_a);
- if (fd_b > -1)
- close(fd_b);
+ if (fd_source > -1)
+ close(fd_source);
+ if (fd_dest > -1)
+ close(fd_dest);
return ret;
}
@@ -2032,8 +2037,11 @@ int finalize_object_file(const char *tmpfile, const char *filename)
int finalize_object_file_flags(const char *tmpfile, const char *filename,
enum finalize_object_file_flags flags)
{
- struct stat st;
- int ret = 0;
+ unsigned retries = 0;
+ int ret;
+
+retry:
+ ret = 0;
if (object_creation_mode == OBJECT_CREATION_USES_RENAMES)
goto try_rename;
@@ -2054,6 +2062,8 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
* left to unlink.
*/
if (ret && ret != EEXIST) {
+ struct stat st;
+
try_rename:
if (!stat(filename, &st))
ret = EEXIST;
@@ -2069,9 +2079,17 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
errno = saved_errno;
return error_errno(_("unable to write file %s"), filename);
}
- if (!(flags & FOF_SKIP_COLLISION_CHECK) &&
- check_collision(tmpfile, filename))
+ if (!(flags & FOF_SKIP_COLLISION_CHECK)) {
+ ret = check_collision(tmpfile, filename);
+ if (ret == CHECK_COLLISION_DEST_VANISHED) {
+ if (retries++ > 5)
+ return error(_("unable to write repeatedly vanishing file %s"),
+ filename);
+ goto retry;
+ }
+ else if (ret)
return -1;
+ }
unlink_or_warn(tmpfile);
}
diff --git a/object-name.c b/object-name.c
index 88d1313028..945d5bdef2 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1272,6 +1272,58 @@ static int peel_onion(struct repository *r, const char *name, int len,
return 0;
}
+/*
+ * Documentation/revisions.txt says:
+ * '<describeOutput>', e.g. 'v1.7.4.2-679-g3bee7fb'::
+ * Output from `git describe`; i.e. a closest tag, optionally
+ * followed by a dash and a number of commits, followed by a dash, a
+ * 'g', and an abbreviated object name.
+ *
+ * which means that the stuff before '-g${HASH}' needs to be a valid
+ * refname, a dash, and a non-negative integer. This function verifies
+ * that.
+ *
+ * In particular, we do not want to treat
+ * branchname:path/to/file/named/i-gaffed
+ * as a request for commit affed.
+ *
+ * More generally, we should probably not treat
+ * 'refs/heads/./../.../ ~^:/?*[////\\\&}/busted.lock-g050e0ef6ead'
+ * as a request for object 050e0ef6ead either.
+ *
+ * We are called with name[len] == '-' and name[len+1] == 'g', i.e.
+ * we are verifying ${REFNAME}-{INTEGER} part of the name.
+ */
+static int ref_and_count_parts_valid(const char *name, int len)
+{
+ struct strbuf sb;
+ const char *cp;
+ int flags = REFNAME_ALLOW_ONELEVEL;
+ int ret = 1;
+
+ /* Ensure we have at least one digit */
+ if (!isxdigit(name[len-1]))
+ return 0;
+
+ /* Skip over digits backwards until we get to the dash */
+ for (cp = name + len - 2; name < cp; cp--) {
+ if (*cp == '-')
+ break;
+ if (!isxdigit(*cp))
+ return 0;
+ }
+ /* Ensure we found the leading dash */
+ if (*cp != '-')
+ return 0;
+
+ len = cp - name;
+ strbuf_init(&sb, len);
+ strbuf_add(&sb, name, len);
+ ret = !check_refname_format(sb.buf, flags);
+ strbuf_release(&sb);
+ return ret;
+}
+
static int get_describe_name(struct repository *r,
const char *name, int len,
struct object_id *oid)
@@ -1285,7 +1337,8 @@ static int get_describe_name(struct repository *r,
/* We must be looking at g in "SOMETHING-g"
* for it to be describe output.
*/
- if (ch == 'g' && cp[-1] == '-') {
+ if (ch == 'g' && cp[-1] == '-' &&
+ ref_and_count_parts_valid(name, cp - 1 - name)) {
cp++;
len -= cp - name;
return get_short_oid(r,
@@ -2052,12 +2105,14 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
return -1;
}
for (cp = name, bracket_depth = 0; *cp; cp++) {
- if (*cp == '{')
+ if (strchr("@^", *cp) && cp[1] == '{') {
+ cp++;
bracket_depth++;
- else if (bracket_depth && *cp == '}')
+ } else if (bracket_depth && *cp == '}') {
bracket_depth--;
- else if (!bracket_depth && *cp == ':')
+ } else if (!bracket_depth && *cp == ':') {
break;
+ }
}
if (*cp == ':') {
struct object_id tree_oid;
diff --git a/oss-fuzz/fuzz-parse-attr-line.c b/oss-fuzz/fuzz-parse-attr-line.c
index e0e4bc6358..315198505c 100644
--- a/oss-fuzz/fuzz-parse-attr-line.c
+++ b/oss-fuzz/fuzz-parse-attr-line.c
@@ -24,7 +24,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
res = parse_attr_line(buf, "dummy", 0, 0);
if (res) {
- int j;
+ size_t j;
for (j = 0; j < res->num_attr; j++) {
const char *setto = res->state[j].setto;
if (ATTR_TRUE(setto) || ATTR_FALSE(setto) ||
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 4f8be53c2b..a06a1f35c6 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -590,7 +590,8 @@ int bitmap_writer_build(struct bitmap_writer *writer)
int closed = 1; /* until proven otherwise */
if (writer->show_progress)
- writer->progress = start_progress("Building bitmaps",
+ writer->progress = start_progress(the_repository,
+ "Building bitmaps",
writer->selected_nr);
trace2_region_enter("pack-bitmap-write", "building_bitmaps_total",
the_repository);
@@ -710,7 +711,8 @@ void bitmap_writer_select_commits(struct bitmap_writer *writer,
}
if (writer->show_progress)
- writer->progress = start_progress("Selecting bitmap commits", 0);
+ writer->progress = start_progress(the_repository,
+ "Selecting bitmap commits", 0);
for (;;) {
struct commit *chosen = NULL;
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 60b5da9d0b..6406953d32 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -2573,7 +2573,9 @@ void test_bitmap_walk(struct rev_info *revs)
tdata.trees = ewah_to_bitmap(bitmap_git->trees);
tdata.blobs = ewah_to_bitmap(bitmap_git->blobs);
tdata.tags = ewah_to_bitmap(bitmap_git->tags);
- tdata.prg = start_progress("Verifying bitmap entries", result_popcnt);
+ tdata.prg = start_progress(revs->repo,
+ "Verifying bitmap entries",
+ result_popcnt);
tdata.seen = 0;
traverse_commit_list(revs, &test_show_commit, &test_show_object, &tdata);
diff --git a/pager.c b/pager.c
index 40b664f893..5531fff50e 100644
--- a/pager.c
+++ b/pager.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "config.h"
#include "editor.h"
@@ -84,7 +82,7 @@ static int core_pager_config(const char *var, const char *value,
return 0;
}
-const char *git_pager(int stdout_is_tty)
+const char *git_pager(struct repository *r, int stdout_is_tty)
{
const char *pager;
@@ -94,7 +92,7 @@ const char *git_pager(int stdout_is_tty)
pager = getenv("GIT_PAGER");
if (!pager) {
if (!pager_program)
- read_early_config(the_repository,
+ read_early_config(r,
core_pager_config, NULL);
pager = pager_program;
}
@@ -143,10 +141,10 @@ void prepare_pager_args(struct child_process *pager_process, const char *pager)
pager_process->trace2_child_class = "pager";
}
-void setup_pager(void)
+void setup_pager(struct repository *r)
{
static int once = 0;
- const char *pager = git_pager(isatty(1));
+ const char *pager = git_pager(r, isatty(1));
if (!pager)
return;
@@ -293,7 +291,7 @@ static int pager_command_config(const char *var, const char *value,
}
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
-int check_pager_config(const char *cmd)
+int check_pager_config(struct repository *r, const char *cmd)
{
struct pager_command_config_data data;
@@ -301,7 +299,7 @@ int check_pager_config(const char *cmd)
data.want = -1;
data.value = NULL;
- read_early_config(the_repository, pager_command_config, &data);
+ read_early_config(r, pager_command_config, &data);
if (data.value)
pager_program = data.value;
diff --git a/pager.h b/pager.h
index 103ecac476..d070be6348 100644
--- a/pager.h
+++ b/pager.h
@@ -2,15 +2,16 @@
#define PAGER_H
struct child_process;
+struct repository;
-const char *git_pager(int stdout_is_tty);
-void setup_pager(void);
+const char *git_pager(struct repository *r, int stdout_is_tty);
+void setup_pager(struct repository *r);
void wait_for_pager(void);
int pager_in_use(void);
int term_columns(void);
void term_clear_line(void);
int decimal_width(uintmax_t);
-int check_pager_config(const char *cmd);
+int check_pager_config(struct repository *r, const char *cmd);
void prepare_pager_args(struct child_process *, const char *pager);
extern int pager_use_color;
diff --git a/parse-options.c b/parse-options.c
index 33bfba0ed4..35fbb3b0d6 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1076,11 +1076,48 @@ static int usage_argh(const struct option *opts, FILE *outfile)
!opts->argh || !!strpbrk(opts->argh, "()<>[]|");
if (opts->flags & PARSE_OPT_OPTARG)
if (opts->long_name)
- s = literal ? "[=%s]" : "[=<%s>]";
+ /*
+ * TRANSLATORS: The "<%s>" part of this string
+ * stands for an optional value given to a command
+ * line option in the long form, and "<>" is there
+ * as a convention to signal that it is a
+ * placeholder (i.e. the user should substitute it
+ * with the real value). If your language uses a
+ * different convention, you can change "<%s>" part
+ * to match yours, e.g. it might use "|%s|" instead,
+ * or if the alphabet is different enough it may use
+ * "%s" without any placeholder signal. Most
+ * translations leave this message as is.
+ */
+ s = literal ? "[=%s]" : _("[=<%s>]");
else
- s = literal ? "[%s]" : "[<%s>]";
+ /*
+ * TRANSLATORS: The "<%s>" part of this string
+ * stands for an optional value given to a command
+ * line option in the short form, and "<>" is there
+ * as a convention to signal that it is a
+ * placeholder (i.e. the user should substitute it
+ * with the real value). If your language uses a
+ * different convention, you can change "<%s>" part
+ * to match yours, e.g. it might use "|%s|" instead,
+ * or if the alphabet is different enough it may use
+ * "%s" without any placeholder signal. Most
+ * translations leave this message as is.
+ */
+ s = literal ? "[%s]" : _("[<%s>]");
else
- s = literal ? " %s" : " <%s>";
+ /*
+ * TRANSLATORS: The "<%s>" part of this string stands for a
+ * value given to a command line option, and "<>" is there
+ * as a convention to signal that it is a placeholder
+ * (i.e. the user should substitute it with the real value).
+ * If your language uses a different convention, you can
+ * change "<%s>" part to match yours, e.g. it might use
+ * "|%s|" instead, or if the alphabet is different enough it
+ * may use "%s" without any placeholder signal. Most
+ * translations leave this message as is.
+ */
+ s = literal ? " %s" : _(" <%s>");
return utf8_fprintf(outfile, s, opts->argh ? _(opts->argh) : _("..."));
}
@@ -1282,6 +1319,16 @@ void NORETURN usage_with_options(const char * const *usagestr,
exit(129);
}
+void show_usage_with_options_if_asked(int ac, const char **av,
+ const char * const *usagestr,
+ const struct option *opts)
+{
+ if (ac == 2 && !strcmp(av[1], "-h")) {
+ usage_with_options_internal(NULL, usagestr, opts, 0, 0);
+ exit(129);
+ }
+}
+
void NORETURN usage_msg_opt(const char *msg,
const char * const *usagestr,
const struct option *options)
diff --git a/parse-options.h b/parse-options.h
index d01361ca97..39f0886254 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -402,6 +402,10 @@ int parse_options(int argc, const char **argv, const char *prefix,
NORETURN void usage_with_options(const char * const *usagestr,
const struct option *options);
+void show_usage_with_options_if_asked(int ac, const char **av,
+ const char * const *usage,
+ const struct option *options);
+
NORETURN void usage_msg_opt(const char *msg,
const char * const *usagestr,
const struct option *options);
diff --git a/preload-index.c b/preload-index.c
index ab94d6f399..40ab2abafb 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -132,7 +132,9 @@ void preload_index(struct index_state *index,
memset(&pd, 0, sizeof(pd));
if (refresh_flags & REFRESH_PROGRESS && isatty(2)) {
- pd.progress = start_delayed_progress(_("Refreshing index"), index->cache_nr);
+ pd.progress = start_delayed_progress(the_repository,
+ _("Refreshing index"),
+ index->cache_nr);
pthread_mutex_init(&pd.mutex, NULL);
}
diff --git a/prio-queue.h b/prio-queue.h
index 36f370625f..38d032636d 100644
--- a/prio-queue.h
+++ b/prio-queue.h
@@ -22,13 +22,13 @@
typedef int (*prio_queue_compare_fn)(const void *one, const void *two, void *cb_data);
struct prio_queue_entry {
- unsigned ctr;
+ size_t ctr;
void *data;
};
struct prio_queue {
prio_queue_compare_fn compare;
- unsigned insertion_ctr;
+ size_t insertion_ctr;
void *cb_data;
size_t alloc, nr;
struct prio_queue_entry *array;
diff --git a/progress.c b/progress.c
index a8fdfceb5c..8d5ae70f3a 100644
--- a/progress.c
+++ b/progress.c
@@ -9,7 +9,6 @@
*/
#define GIT_TEST_PROGRESS_ONLY
-#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
@@ -37,6 +36,7 @@ struct throughput {
};
struct progress {
+ struct repository *repo;
const char *title;
uint64_t last_value;
uint64_t total;
@@ -254,10 +254,12 @@ void display_progress(struct progress *progress, uint64_t n)
display(progress, n, NULL);
}
-static struct progress *start_progress_delay(const char *title, uint64_t total,
+static struct progress *start_progress_delay(struct repository *r,
+ const char *title, uint64_t total,
unsigned delay, unsigned sparse)
{
struct progress *progress = xmalloc(sizeof(*progress));
+ progress->repo = r;
progress->title = title;
progress->total = total;
progress->last_value = -1;
@@ -270,7 +272,7 @@ static struct progress *start_progress_delay(const char *title, uint64_t total,
progress->title_len = utf8_strwidth(title);
progress->split = 0;
set_progress_signal();
- trace2_region_enter("progress", title, the_repository);
+ trace2_region_enter("progress", title, r);
return progress;
}
@@ -284,14 +286,16 @@ static int get_default_delay(void)
return delay_in_secs;
}
-struct progress *start_delayed_progress(const char *title, uint64_t total)
+struct progress *start_delayed_progress(struct repository *r,
+ const char *title, uint64_t total)
{
- return start_progress_delay(title, total, get_default_delay(), 0);
+ return start_progress_delay(r, title, total, get_default_delay(), 0);
}
-struct progress *start_progress(const char *title, uint64_t total)
+struct progress *start_progress(struct repository *r,
+ const char *title, uint64_t total)
{
- return start_progress_delay(title, total, 0, 0);
+ return start_progress_delay(r, title, total, 0, 0);
}
/*
@@ -303,15 +307,17 @@ struct progress *start_progress(const char *title, uint64_t total)
* When "sparse" is set, stop_progress() will automatically force the done
* message to show 100%.
*/
-struct progress *start_sparse_progress(const char *title, uint64_t total)
+struct progress *start_sparse_progress(struct repository *r,
+ const char *title, uint64_t total)
{
- return start_progress_delay(title, total, 0, 1);
+ return start_progress_delay(r, title, total, 0, 1);
}
-struct progress *start_delayed_sparse_progress(const char *title,
+struct progress *start_delayed_sparse_progress(struct repository *r,
+ const char *title,
uint64_t total)
{
- return start_progress_delay(title, total, get_default_delay(), 1);
+ return start_progress_delay(r, title, total, get_default_delay(), 1);
}
static void finish_if_sparse(struct progress *progress)
@@ -341,14 +347,14 @@ static void force_last_update(struct progress *progress, const char *msg)
static void log_trace2(struct progress *progress)
{
- trace2_data_intmax("progress", the_repository, "total_objects",
+ trace2_data_intmax("progress", progress->repo, "total_objects",
progress->total);
if (progress->throughput)
- trace2_data_intmax("progress", the_repository, "total_bytes",
+ trace2_data_intmax("progress", progress->repo, "total_bytes",
progress->throughput->curr_total);
- trace2_region_leave("progress", progress->title, the_repository);
+ trace2_region_leave("progress", progress->title, progress->repo);
}
void stop_progress_msg(struct progress **p_progress, const char *msg)
diff --git a/progress.h b/progress.h
index 3a945637c8..ed068c7bab 100644
--- a/progress.h
+++ b/progress.h
@@ -3,6 +3,7 @@
#include "gettext.h"
struct progress;
+struct repository;
#ifdef GIT_TEST_PROGRESS_ONLY
@@ -14,10 +15,14 @@ void progress_test_force_update(void);
void display_throughput(struct progress *progress, uint64_t total);
void display_progress(struct progress *progress, uint64_t n);
-struct progress *start_progress(const char *title, uint64_t total);
-struct progress *start_sparse_progress(const char *title, uint64_t total);
-struct progress *start_delayed_progress(const char *title, uint64_t total);
-struct progress *start_delayed_sparse_progress(const char *title,
+struct progress *start_progress(struct repository *r,
+ const char *title, uint64_t total);
+struct progress *start_sparse_progress(struct repository *r,
+ const char *title, uint64_t total);
+struct progress *start_delayed_progress(struct repository *r,
+ const char *title, uint64_t total);
+struct progress *start_delayed_sparse_progress(struct repository *r,
+ const char *title,
uint64_t total);
void stop_progress_msg(struct progress **p_progress, const char *msg);
static inline void stop_progress(struct progress **p_progress)
diff --git a/prune-packed.c b/prune-packed.c
index d1c65ab10e..7dad2fc0c1 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -37,7 +37,8 @@ static int prune_object(const struct object_id *oid, const char *path,
void prune_packed_objects(int opts)
{
if (opts & PRUNE_PACKED_VERBOSE)
- progress = start_delayed_progress(_("Removing duplicate objects"), 256);
+ progress = start_delayed_progress(the_repository,
+ _("Removing duplicate objects"), 256);
for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
prune_object, NULL, prune_subdir, &opts);
diff --git a/pseudo-merge.c b/pseudo-merge.c
index 971f54cfe1..893b763fe4 100644
--- a/pseudo-merge.c
+++ b/pseudo-merge.c
@@ -459,7 +459,8 @@ void select_pseudo_merges(struct bitmap_writer *writer)
return;
if (writer->show_progress)
- progress = start_progress("Selecting pseudo-merge commits",
+ progress = start_progress(the_repository,
+ "Selecting pseudo-merge commits",
writer->pseudo_merge_groups.nr);
refs_for_each_ref(get_main_ref_store(the_repository),
diff --git a/read-cache.c b/read-cache.c
index 15d79839c2..d54be2c172 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1523,7 +1523,8 @@ int refresh_index(struct index_state *istate, unsigned int flags,
int t2_sum_scan = 0;
if (flags & REFRESH_PROGRESS && isatty(2))
- progress = start_delayed_progress(_("Refresh index"),
+ progress = start_delayed_progress(the_repository,
+ _("Refresh index"),
istate->cache_nr);
trace_performance_enter();
@@ -1753,7 +1754,7 @@ static int read_index_extension(struct index_state *istate,
istate->cache_tree = cache_tree_read(data, sz);
break;
case CACHE_EXT_RESOLVE_UNDO:
- istate->resolve_undo = resolve_undo_read(data, sz);
+ istate->resolve_undo = resolve_undo_read(data, sz, the_hash_algo);
break;
case CACHE_EXT_LINK:
if (read_link_extension(istate, data, sz))
@@ -3032,7 +3033,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
istate->resolve_undo) {
strbuf_reset(&sb);
- resolve_undo_write(&sb, istate->resolve_undo);
+ resolve_undo_write(&sb, istate->resolve_undo, the_hash_algo);
err = write_index_ext_header(f, eoie_c, CACHE_EXT_RESOLVE_UNDO,
sb.len) < 0;
hashwrite(f, sb.buf, sb.len);
diff --git a/ref-filter.c b/ref-filter.c
index 23054694c2..bf5534605e 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -3041,7 +3041,7 @@ static void reach_filter(struct ref_array *array,
struct commit_list **check_reachable,
int include_reached)
{
- int i, old_nr;
+ size_t i, old_nr;
struct commit **to_clear;
if (!*check_reachable)
diff --git a/reftable/stack.c b/reftable/stack.c
index 531660a49f..572a74e00f 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -493,7 +493,7 @@ static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st,
close(fd);
fd = -1;
- delay = delay + (delay * rand()) / RAND_MAX + 1;
+ delay = delay + (delay * git_rand(CSPRNG_BYTES_INSECURE)) / UINT32_MAX + 1;
sleep_millisec(delay);
}
@@ -659,7 +659,7 @@ int reftable_stack_add(struct reftable_stack *st,
static int format_name(struct reftable_buf *dest, uint64_t min, uint64_t max)
{
char buf[100];
- uint32_t rnd = (uint32_t)git_rand();
+ uint32_t rnd = git_rand(CSPRNG_BYTES_INSECURE);
snprintf(buf, sizeof(buf), "0x%012" PRIx64 "-0x%012" PRIx64 "-%08x",
min, max, rnd);
reftable_buf_reset(dest);
diff --git a/remote-curl.c b/remote-curl.c
index a24e3a8b9a..1273507a96 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -942,7 +942,7 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
do {
err = probe_rpc(rpc, &results);
if (err == HTTP_REAUTH)
- credential_fill(&http_auth, 0);
+ credential_fill(the_repository, &http_auth, 0);
} while (err == HTTP_REAUTH);
if (err != HTTP_OK)
return -1;
@@ -1064,7 +1064,7 @@ retry:
rpc->any_written = 0;
err = run_slot(slot, NULL);
if (err == HTTP_REAUTH && !large_request) {
- credential_fill(&http_auth, 0);
+ credential_fill(the_repository, &http_auth, 0);
curl_slist_free_all(headers);
goto retry;
}
diff --git a/remote.c b/remote.c
index 18e5ccf391..0f6fba8562 100644
--- a/remote.c
+++ b/remote.c
@@ -1535,7 +1535,7 @@ static struct ref **tail_ref(struct ref **head)
struct tips {
struct commit **tip;
- int nr, alloc;
+ size_t nr, alloc;
};
static void add_to_tips(struct tips *tips, const struct object_id *oid)
@@ -1602,7 +1602,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
const int reachable_flag = 1;
struct commit_list *found_commits;
struct commit **src_commits;
- int nr_src_commits = 0, alloc_src_commits = 16;
+ size_t nr_src_commits = 0, alloc_src_commits = 16;
ALLOC_ARRAY(src_commits, alloc_src_commits);
for_each_string_list_item(item, &src_tag) {
diff --git a/resolve-undo.c b/resolve-undo.c
index b5a9dfb4ac..52c45e5a49 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
@@ -34,7 +33,8 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce)
ui->mode[stage - 1] = ce->ce_mode;
}
-void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo)
+void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo,
+ const struct git_hash_algo *algop)
{
struct string_list_item *item;
for_each_string_list_item(item, resolve_undo) {
@@ -50,18 +50,19 @@ void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo)
for (i = 0; i < 3; i++) {
if (!ui->mode[i])
continue;
- strbuf_add(sb, ui->oid[i].hash, the_hash_algo->rawsz);
+ strbuf_add(sb, ui->oid[i].hash, algop->rawsz);
}
}
}
-struct string_list *resolve_undo_read(const char *data, unsigned long size)
+struct string_list *resolve_undo_read(const char *data, unsigned long size,
+ const struct git_hash_algo *algop)
{
struct string_list *resolve_undo;
size_t len;
char *endptr;
int i;
- const unsigned rawsz = the_hash_algo->rawsz;
+ const unsigned rawsz = algop->rawsz;
CALLOC_ARRAY(resolve_undo, 1);
resolve_undo->strdup_strings = 1;
@@ -96,8 +97,7 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
continue;
if (size < rawsz)
goto error;
- oidread(&ui->oid[i], (const unsigned char *)data,
- the_repository->hash_algo);
+ oidread(&ui->oid[i], (const unsigned char *)data, algop);
size -= rawsz;
data += rawsz;
}
diff --git a/resolve-undo.h b/resolve-undo.h
index 89a3227262..7ed11a1c59 100644
--- a/resolve-undo.h
+++ b/resolve-undo.h
@@ -14,8 +14,10 @@ struct resolve_undo_info {
};
void record_resolve_undo(struct index_state *, struct cache_entry *);
-void resolve_undo_write(struct strbuf *, struct string_list *);
-struct string_list *resolve_undo_read(const char *, unsigned long);
+void resolve_undo_write(struct strbuf *, struct string_list *,
+ const struct git_hash_algo *algop);
+struct string_list *resolve_undo_read(const char *, unsigned long,
+ const struct git_hash_algo *algop);
void resolve_undo_clear_index(struct index_state *);
int unmerge_index_entry(struct index_state *, const char *, struct resolve_undo_info *, unsigned);
void unmerge_index(struct index_state *, const struct pathspec *, unsigned);
diff --git a/send-pack.c b/send-pack.c
index 7e83213683..772c7683a0 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
@@ -44,10 +42,11 @@ int option_parse_push_signed(const struct option *opt,
die("bad %s argument: %s", opt->long_name, arg);
}
-static void feed_object(const struct object_id *oid, FILE *fh, int negative)
+static void feed_object(struct repository *r,
+ const struct object_id *oid, FILE *fh, int negative)
{
if (negative &&
- !repo_has_object_file_with_flags(the_repository, oid,
+ !repo_has_object_file_with_flags(r, oid,
OBJECT_INFO_SKIP_FETCH_OBJECT |
OBJECT_INFO_QUICK))
return;
@@ -61,7 +60,8 @@ static void feed_object(const struct object_id *oid, FILE *fh, int negative)
/*
* Make a pack stream and spit it out into file descriptor fd
*/
-static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
+static int pack_objects(struct repository *r,
+ int fd, struct ref *refs, struct oid_array *advertised,
struct oid_array *negotiated,
struct send_pack_args *args)
{
@@ -74,7 +74,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
FILE *po_in;
int rc;
- trace2_region_enter("send_pack", "pack_objects", the_repository);
+ trace2_region_enter("send_pack", "pack_objects", r);
strvec_push(&po.args, "pack-objects");
strvec_push(&po.args, "--all-progress-implied");
strvec_push(&po.args, "--revs");
@@ -87,7 +87,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
strvec_push(&po.args, "-q");
if (args->progress)
strvec_push(&po.args, "--progress");
- if (is_repository_shallow(the_repository))
+ if (is_repository_shallow(r))
strvec_push(&po.args, "--shallow");
if (args->disable_bitmaps)
strvec_push(&po.args, "--no-use-bitmap-index");
@@ -104,15 +104,15 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
*/
po_in = xfdopen(po.in, "w");
for (size_t i = 0; i < advertised->nr; i++)
- feed_object(&advertised->oid[i], po_in, 1);
+ feed_object(r, &advertised->oid[i], po_in, 1);
for (size_t i = 0; i < negotiated->nr; i++)
- feed_object(&negotiated->oid[i], po_in, 1);
+ feed_object(r, &negotiated->oid[i], po_in, 1);
while (refs) {
if (!is_null_oid(&refs->old_oid))
- feed_object(&refs->old_oid, po_in, 1);
+ feed_object(r, &refs->old_oid, po_in, 1);
if (!is_null_oid(&refs->new_oid))
- feed_object(&refs->new_oid, po_in, 0);
+ feed_object(r, &refs->new_oid, po_in, 0);
refs = refs->next;
}
@@ -146,10 +146,10 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
*/
if (rc > 128 && rc != 141)
error("pack-objects died of signal %d", rc - 128);
- trace2_region_leave("send_pack", "pack_objects", the_repository);
+ trace2_region_leave("send_pack", "pack_objects", r);
return -1;
}
- trace2_region_leave("send_pack", "pack_objects", the_repository);
+ trace2_region_leave("send_pack", "pack_objects", r);
return 0;
}
@@ -164,7 +164,8 @@ static int receive_unpack_status(struct packet_reader *reader)
return 0;
}
-static int receive_status(struct packet_reader *reader, struct ref *refs)
+static int receive_status(struct repository *r,
+ struct packet_reader *reader, struct ref *refs)
{
struct ref *hint;
int ret;
@@ -172,7 +173,7 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
int new_report = 0;
int once = 0;
- trace2_region_enter("send_pack", "receive_status", the_repository);
+ trace2_region_enter("send_pack", "receive_status", r);
hint = NULL;
ret = receive_unpack_status(reader);
while (1) {
@@ -221,10 +222,10 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
if (!strcmp(key, "refname"))
report->ref_name = xstrdup_or_null(val);
else if (!strcmp(key, "old-oid") && val &&
- !parse_oid_hex(val, &old_oid, &val))
+ !parse_oid_hex_algop(val, &old_oid, &val, r->hash_algo))
report->old_oid = oiddup(&old_oid);
else if (!strcmp(key, "new-oid") && val &&
- !parse_oid_hex(val, &new_oid, &val))
+ !parse_oid_hex_algop(val, &new_oid, &val, r->hash_algo))
report->new_oid = oiddup(&new_oid);
else if (!strcmp(key, "forced-update"))
report->forced_update = 1;
@@ -271,7 +272,7 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
new_report = 1;
}
}
- trace2_region_leave("send_pack", "receive_status", the_repository);
+ trace2_region_leave("send_pack", "receive_status", r);
return ret;
}
@@ -293,9 +294,9 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
return 0;
}
-static void advertise_shallow_grafts_buf(struct strbuf *sb)
+static void advertise_shallow_grafts_buf(struct repository *r, struct strbuf *sb)
{
- if (!is_repository_shallow(the_repository))
+ if (!is_repository_shallow(r))
return;
for_each_commit_graft(advertise_shallow_grafts_cb, sb);
}
@@ -426,13 +427,14 @@ static void reject_invalid_nonce(const char *nonce, int len)
}
}
-static void get_commons_through_negotiation(const char *url,
+static void get_commons_through_negotiation(struct repository *r,
+ const char *url,
const struct ref *remote_refs,
struct oid_array *commons)
{
struct child_process child = CHILD_PROCESS_INIT;
const struct ref *ref;
- int len = the_hash_algo->hexsz + 1; /* hash + NL */
+ int len = r->hash_algo->hexsz + 1; /* hash + NL */
int nr_negotiation_tip = 0;
child.git_cmd = 1;
@@ -466,7 +468,7 @@ static void get_commons_through_negotiation(const char *url,
break;
if (read_len != len)
die("invalid length read %d", read_len);
- if (parse_oid_hex(hex_hash, &oid, &end) || *end != '\n')
+ if (parse_oid_hex_algop(hex_hash, &oid, &end, r->hash_algo) || *end != '\n')
die("invalid hash");
oid_array_append(commons, &oid);
} while (1);
@@ -480,7 +482,8 @@ static void get_commons_through_negotiation(const char *url,
}
}
-int send_pack(struct send_pack_args *args,
+int send_pack(struct repository *r,
+ struct send_pack_args *args,
int fd[], struct child_process *conn,
struct ref *remote_refs,
struct oid_array *extra_have)
@@ -518,17 +521,17 @@ int send_pack(struct send_pack_args *args,
goto out;
}
- git_config_get_bool("push.negotiate", &push_negotiate);
+ repo_config_get_bool(r, "push.negotiate", &push_negotiate);
if (push_negotiate) {
- trace2_region_enter("send_pack", "push_negotiate", the_repository);
- get_commons_through_negotiation(args->url, remote_refs, &commons);
- trace2_region_leave("send_pack", "push_negotiate", the_repository);
+ trace2_region_enter("send_pack", "push_negotiate", r);
+ get_commons_through_negotiation(r, args->url, remote_refs, &commons);
+ trace2_region_leave("send_pack", "push_negotiate", r);
}
- if (!git_config_get_bool("push.usebitmaps", &use_bitmaps))
+ if (!repo_config_get_bool(r, "push.usebitmaps", &use_bitmaps))
args->disable_bitmaps = !use_bitmaps;
- git_config_get_bool("transfer.advertisesid", &advertise_sid);
+ repo_config_get_bool(r, "transfer.advertisesid", &advertise_sid);
/* Does the other end support the reporting? */
if (server_supports("report-status-v2"))
@@ -554,7 +557,7 @@ int send_pack(struct send_pack_args *args,
if (server_supports("push-options"))
push_options_supported = 1;
- if (!server_supports_hash(the_hash_algo->name, &object_format_supported))
+ if (!server_supports_hash(r->hash_algo->name, &object_format_supported))
die(_("the receiving end does not support this repository's hash algorithm"));
if (args->push_cert != SEND_PACK_PUSH_CERT_NEVER) {
@@ -596,7 +599,7 @@ int send_pack(struct send_pack_args *args,
if (use_push_options)
strbuf_addstr(&cap_buf, " push-options");
if (object_format_supported)
- strbuf_addf(&cap_buf, " object-format=%s", the_hash_algo->name);
+ strbuf_addf(&cap_buf, " object-format=%s", r->hash_algo->name);
if (agent_supported)
strbuf_addf(&cap_buf, " agent=%s", git_user_agent_sanitized());
if (advertise_sid)
@@ -646,7 +649,7 @@ int send_pack(struct send_pack_args *args,
}
if (!args->dry_run)
- advertise_shallow_grafts_buf(&req_buf);
+ advertise_shallow_grafts_buf(r, &req_buf);
/*
* Finally, tell the other end!
@@ -686,7 +689,7 @@ int send_pack(struct send_pack_args *args,
}
if (args->stateless_rpc) {
- if (!args->dry_run && (cmds_sent || is_repository_shallow(the_repository))) {
+ if (!args->dry_run && (cmds_sent || is_repository_shallow(r))) {
packet_buf_flush(&req_buf);
send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
}
@@ -711,7 +714,7 @@ int send_pack(struct send_pack_args *args,
PACKET_READ_DIE_ON_ERR_PACKET);
if (need_pack_data && cmds_sent) {
- if (pack_objects(out, remote_refs, extra_have, &commons, args) < 0) {
+ if (pack_objects(r, out, remote_refs, extra_have, &commons, args) < 0) {
if (args->stateless_rpc)
close(out);
if (git_connection_is_socket(conn))
@@ -724,7 +727,7 @@ int send_pack(struct send_pack_args *args,
* we get one).
*/
if (status_report)
- receive_status(&reader, remote_refs);
+ receive_status(r, &reader, remote_refs);
if (use_sideband) {
close(demux.out);
@@ -743,7 +746,7 @@ int send_pack(struct send_pack_args *args,
packet_flush(out);
if (status_report && cmds_sent)
- ret = receive_status(&reader, remote_refs);
+ ret = receive_status(r, &reader, remote_refs);
else
ret = 0;
if (args->stateless_rpc)
diff --git a/send-pack.h b/send-pack.h
index 7edb80596c..d256715681 100644
--- a/send-pack.h
+++ b/send-pack.h
@@ -6,6 +6,7 @@
struct child_process;
struct oid_array;
struct ref;
+struct repository;
/* Possible values for push_cert field in send_pack_args. */
#define SEND_PACK_PUSH_CERT_NEVER 0
@@ -35,7 +36,7 @@ struct option;
int option_parse_push_signed(const struct option *opt,
const char *arg, int unset);
-int send_pack(struct send_pack_args *args,
+int send_pack(struct repository *r, struct send_pack_args *args,
int fd[], struct child_process *conn,
struct ref *remote_refs, struct oid_array *extra_have);
diff --git a/serve.c b/serve.c
index c8694e3751..f6dfe34a2b 100644
--- a/serve.c
+++ b/serve.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
@@ -159,7 +157,7 @@ static struct protocol_capability capabilities[] = {
},
};
-void protocol_v2_advertise_capabilities(void)
+void protocol_v2_advertise_capabilities(struct repository *r)
{
struct strbuf capability = STRBUF_INIT;
struct strbuf value = STRBUF_INIT;
@@ -170,7 +168,7 @@ void protocol_v2_advertise_capabilities(void)
for (size_t i = 0; i < ARRAY_SIZE(capabilities); i++) {
struct protocol_capability *c = &capabilities[i];
- if (c->advertise(the_repository, &value)) {
+ if (c->advertise(r, &value)) {
strbuf_addstr(&capability, c->name);
if (value.len) {
@@ -214,20 +212,20 @@ static struct protocol_capability *get_capability(const char *key, const char **
return NULL;
}
-static int receive_client_capability(const char *key)
+static int receive_client_capability(struct repository *r, const char *key)
{
const char *value;
const struct protocol_capability *c = get_capability(key, &value);
- if (!c || c->command || !c->advertise(the_repository, NULL))
+ if (!c || c->command || !c->advertise(r, NULL))
return 0;
if (c->receive)
- c->receive(the_repository, value);
+ c->receive(r, value);
return 1;
}
-static int parse_command(const char *key, struct protocol_capability **command)
+static int parse_command(struct repository *r, const char *key, struct protocol_capability **command)
{
const char *out;
@@ -238,7 +236,7 @@ static int parse_command(const char *key, struct protocol_capability **command)
if (*command)
die("command '%s' requested after already requesting command '%s'",
out, (*command)->name);
- if (!cmd || !cmd->advertise(the_repository, NULL) || !cmd->command || value)
+ if (!cmd || !cmd->advertise(r, NULL) || !cmd->command || value)
die("invalid command '%s'", out);
*command = cmd;
@@ -253,7 +251,7 @@ enum request_state {
PROCESS_REQUEST_DONE,
};
-static int process_request(void)
+static int process_request(struct repository *r)
{
enum request_state state = PROCESS_REQUEST_KEYS;
struct packet_reader reader;
@@ -278,8 +276,8 @@ static int process_request(void)
case PACKET_READ_EOF:
BUG("Should have already died when seeing EOF");
case PACKET_READ_NORMAL:
- if (parse_command(reader.line, &command) ||
- receive_client_capability(reader.line))
+ if (parse_command(r, reader.line, &command) ||
+ receive_client_capability(r, reader.line))
seen_capability_or_command = 1;
else
die("unknown capability '%s'", reader.line);
@@ -319,30 +317,30 @@ static int process_request(void)
if (!command)
die("no command requested");
- if (client_hash_algo != hash_algo_by_ptr(the_repository->hash_algo))
+ if (client_hash_algo != hash_algo_by_ptr(r->hash_algo))
die("mismatched object format: server %s; client %s",
- the_repository->hash_algo->name,
+ r->hash_algo->name,
hash_algos[client_hash_algo].name);
- command->command(the_repository, &reader);
+ command->command(r, &reader);
return 0;
}
-void protocol_v2_serve_loop(int stateless_rpc)
+void protocol_v2_serve_loop(struct repository *r, int stateless_rpc)
{
if (!stateless_rpc)
- protocol_v2_advertise_capabilities();
+ protocol_v2_advertise_capabilities(r);
/*
* If stateless-rpc was requested then exit after
* a single request/response exchange
*/
if (stateless_rpc) {
- process_request();
+ process_request(r);
} else {
for (;;)
- if (process_request())
+ if (process_request(r))
break;
}
}
diff --git a/serve.h b/serve.h
index f946cf904a..85bf73cfe5 100644
--- a/serve.h
+++ b/serve.h
@@ -1,7 +1,9 @@
#ifndef SERVE_H
#define SERVE_H
-void protocol_v2_advertise_capabilities(void);
-void protocol_v2_serve_loop(int stateless_rpc);
+struct repository;
+
+void protocol_v2_advertise_capabilities(struct repository *r);
+void protocol_v2_serve_loop(struct repository *r, int stateless_rpc);
#endif /* SERVE_H */
diff --git a/server-info.c b/server-info.c
index ef2f3f4b5c..31c3fdc118 100644
--- a/server-info.c
+++ b/server-info.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
@@ -18,6 +17,7 @@
#include "tempfile.h"
struct update_info_ctx {
+ struct repository *repo;
FILE *cur_fp;
FILE *old_fp; /* becomes NULL if it differs from cur_fp */
struct strbuf cur_sb;
@@ -73,7 +73,7 @@ static int uic_printf(struct update_info_ctx *uic, const char *fmt, ...)
* it into place. The contents of the file come from "generate", which
* should return non-zero if it encounters an error.
*/
-static int update_info_file(char *path,
+static int update_info_file(struct repository *r, char *path,
int (*generate)(struct update_info_ctx *),
int force)
{
@@ -81,6 +81,7 @@ static int update_info_file(char *path,
struct tempfile *f = NULL;
int ret = -1;
struct update_info_ctx uic = {
+ .repo = r,
.cur_fp = NULL,
.old_fp = NULL,
.cur_sb = STRBUF_INIT,
@@ -152,7 +153,7 @@ static int add_info_ref(const char *path, const char *referent UNUSED, const str
void *cb_data)
{
struct update_info_ctx *uic = cb_data;
- struct object *o = parse_object(the_repository, oid);
+ struct object *o = parse_object(uic->repo, oid);
if (!o)
return -1;
@@ -160,7 +161,7 @@ static int add_info_ref(const char *path, const char *referent UNUSED, const str
return -1;
if (o->type == OBJ_TAG) {
- o = deref_tag(the_repository, o, path, 0);
+ o = deref_tag(uic->repo, o, path, 0);
if (o)
if (uic_printf(uic, "%s %s^{}\n",
oid_to_hex(&o->oid), path) < 0)
@@ -171,14 +172,14 @@ static int add_info_ref(const char *path, const char *referent UNUSED, const str
static int generate_info_refs(struct update_info_ctx *uic)
{
- return refs_for_each_ref(get_main_ref_store(the_repository),
+ return refs_for_each_ref(get_main_ref_store(uic->repo),
add_info_ref, uic);
}
-static int update_info_refs(int force)
+static int update_info_refs(struct repository *r, int force)
{
- char *path = git_pathdup("info/refs");
- int ret = update_info_file(path, generate_info_refs, force);
+ char *path = repo_git_path(r, "info/refs");
+ int ret = update_info_file(r, path, generate_info_refs, force);
free(path);
return ret;
}
@@ -284,14 +285,14 @@ static int compare_info(const void *a_, const void *b_)
return 1;
}
-static void init_pack_info(const char *infofile, int force)
+static void init_pack_info(struct repository *r, const char *infofile, int force)
{
struct packed_git *p;
int stale;
int i;
size_t alloc = 0;
- for (p = get_all_packs(the_repository); p; p = p->next) {
+ for (p = get_all_packs(r); p; p = p->next) {
/* we ignore things on alternate path since they are
* not available to the pullers in general.
*/
@@ -340,33 +341,36 @@ static int write_pack_info_file(struct update_info_ctx *uic)
return 0;
}
-static int update_info_packs(int force)
+static int update_info_packs(struct repository *r, int force)
{
char *infofile = mkpathdup("%s/info/packs",
- repo_get_object_directory(the_repository));
+ repo_get_object_directory(r));
int ret;
- init_pack_info(infofile, force);
- ret = update_info_file(infofile, write_pack_info_file, force);
+ init_pack_info(r, infofile, force);
+ ret = update_info_file(r, infofile, write_pack_info_file, force);
free_pack_info();
free(infofile);
return ret;
}
/* public */
-int update_server_info(int force)
+int update_server_info(struct repository *r, int force)
{
/* We would add more dumb-server support files later,
* including index of available pack files and their
* intended audiences.
*/
int errs = 0;
+ char *path;
- errs = errs | update_info_refs(force);
- errs = errs | update_info_packs(force);
+ errs = errs | update_info_refs(r, force);
+ errs = errs | update_info_packs(r, force);
/* remove leftover rev-cache file if there is any */
- unlink_or_warn(git_path("info/rev-cache"));
+ path = repo_git_path(r, "info/rev-cache");
+ unlink_or_warn(path);
+ free(path);
return errs;
}
diff --git a/server-info.h b/server-info.h
index 13bbde2c55..e634d1722b 100644
--- a/server-info.h
+++ b/server-info.h
@@ -1,7 +1,9 @@
#ifndef SERVER_INFO_H
#define SERVER_INFO_H
+struct repository;
+
/* Dumb servers support */
-int update_server_info(int);
+int update_server_info(struct repository *r, int force);
#endif /* SERVER_INFO_H */
diff --git a/shallow.c b/shallow.c
index 82a8da3d73..b54244ffa9 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,5 +1,4 @@
#define USE_THE_REPOSITORY_VARIABLE
-#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
#include "hex.h"
@@ -134,7 +133,8 @@ static void free_depth_in_slab(int **ptr)
struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
int shallow_flag, int not_shallow_flag)
{
- int i = 0, cur_depth = 0;
+ size_t i = 0;
+ int cur_depth = 0;
struct commit_list *result = NULL;
struct object_array stack = OBJECT_ARRAY_INIT;
struct commit *commit = NULL;
@@ -335,16 +335,16 @@ static int write_shallow_commits_1(struct strbuf *out, int use_pack_protocol,
const struct oid_array *extra,
unsigned flags)
{
- struct write_shallow_data data;
- int i;
- data.out = out;
- data.use_pack_protocol = use_pack_protocol;
- data.count = 0;
- data.flags = flags;
+ struct write_shallow_data data = {
+ .out = out,
+ .use_pack_protocol = use_pack_protocol,
+ .flags = flags,
+ };
+
for_each_commit_graft(write_one_shallow, &data);
if (!extra)
return data.count;
- for (i = 0; i < extra->nr; i++) {
+ for (size_t i = 0; i < extra->nr; i++) {
strbuf_addstr(out, oid_to_hex(extra->oid + i));
strbuf_addch(out, '\n');
data.count++;
@@ -466,7 +466,6 @@ struct trace_key trace_shallow = TRACE_KEY_INIT(SHALLOW);
*/
void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
{
- int i;
trace_printf_key(&trace_shallow, "shallow: prepare_shallow_info\n");
memset(info, 0, sizeof(*info));
info->shallow = sa;
@@ -474,7 +473,7 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
return;
ALLOC_ARRAY(info->ours, sa->nr);
ALLOC_ARRAY(info->theirs, sa->nr);
- for (i = 0; i < sa->nr; i++) {
+ for (size_t i = 0; i < sa->nr; i++) {
if (repo_has_object_file(the_repository, sa->oid + i)) {
struct commit_graft *graft;
graft = lookup_commit_graft(the_repository,
@@ -507,7 +506,7 @@ void clear_shallow_info(struct shallow_info *info)
void remove_nonexistent_theirs_shallow(struct shallow_info *info)
{
struct object_id *oid = info->shallow->oid;
- int i, dst;
+ size_t i, dst;
trace_printf_key(&trace_shallow, "shallow: remove_nonexistent_theirs_shallow\n");
for (i = dst = 0; i < info->nr_theirs; i++) {
if (i != dst)
@@ -535,7 +534,7 @@ static uint32_t *paint_alloc(struct paint_info *info)
unsigned nr = DIV_ROUND_UP(info->nr_bits, 32);
unsigned size = nr * sizeof(uint32_t);
void *p;
- if (!info->pool_count || size > info->end - info->free) {
+ if (!info->pool_count || info->end < info->free + size) {
if (size > POOL_SIZE)
BUG("pool size too small for %d in paint_alloc()",
size);
@@ -560,7 +559,7 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
{
unsigned int i, nr;
struct commit_list *head = NULL;
- int bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32);
+ size_t bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32);
size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
struct commit *c = lookup_commit_reference_gently(the_repository, oid,
1);
@@ -660,7 +659,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
struct object_id *oid = info->shallow->oid;
struct oid_array *ref = info->ref;
unsigned int i, nr;
- int *shallow, nr_shallow = 0;
+ size_t *shallow, nr_shallow = 0;
struct paint_info pi;
trace_printf_key(&trace_shallow, "shallow: assign_shallow_commits_to_refs\n");
@@ -735,7 +734,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
struct commit_array {
struct commit **commits;
- int nr, alloc;
+ size_t nr, alloc;
};
static int add_ref(const char *refname UNUSED,
@@ -753,12 +752,11 @@ static int add_ref(const char *refname UNUSED,
return 0;
}
-static void update_refstatus(int *ref_status, int nr, uint32_t *bitmap)
+static void update_refstatus(int *ref_status, size_t nr, uint32_t *bitmap)
{
- unsigned int i;
if (!ref_status)
return;
- for (i = 0; i < nr; i++)
+ for (size_t i = 0; i < nr; i++)
if (bitmap[i / 32] & (1U << (i % 32)))
ref_status[i]++;
}
@@ -773,8 +771,8 @@ static void post_assign_shallow(struct shallow_info *info,
struct object_id *oid = info->shallow->oid;
struct commit *c;
uint32_t **bitmap;
- int dst, i, j;
- int bitmap_nr = DIV_ROUND_UP(info->ref->nr, 32);
+ size_t dst, i, j;
+ size_t bitmap_nr = DIV_ROUND_UP(info->ref->nr, 32);
struct commit_array ca;
trace_printf_key(&trace_shallow, "shallow: post_assign_shallow\n");
diff --git a/shallow.h b/shallow.h
index e9ca7e4bc8..9bfeade93e 100644
--- a/shallow.h
+++ b/shallow.h
@@ -59,8 +59,8 @@ void prune_shallow(unsigned options);
*/
struct shallow_info {
struct oid_array *shallow;
- int *ours, nr_ours;
- int *theirs, nr_theirs;
+ size_t *ours, nr_ours;
+ size_t *theirs, nr_theirs;
struct oid_array *ref;
/* for receive-pack */
@@ -69,7 +69,7 @@ struct shallow_info {
int *reachable;
int *shallow_ref;
struct commit **commits;
- int nr_commits;
+ size_t nr_commits;
};
void prepare_shallow_info(struct shallow_info *, struct oid_array *);
diff --git a/t/helper/test-csprng.c b/t/helper/test-csprng.c
index a4a0aca617..c86dcc4870 100644
--- a/t/helper/test-csprng.c
+++ b/t/helper/test-csprng.c
@@ -15,7 +15,7 @@ int cmd__csprng(int argc, const char **argv)
while (count) {
unsigned long chunk = count < sizeof(buf) ? count : sizeof(buf);
- if (csprng_bytes(buf, chunk) < 0) {
+ if (csprng_bytes(buf, chunk, 0) < 0) {
perror("failed to read");
return 5;
}
diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c
index 44be2645e9..1f75b7bd19 100644
--- a/t/helper/test-progress.c
+++ b/t/helper/test-progress.c
@@ -17,10 +17,14 @@
*
* See 't0500-progress-display.sh' for examples.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
#define GIT_TEST_PROGRESS_ONLY
+
#include "test-tool.h"
#include "parse-options.h"
#include "progress.h"
+#include "repository.h"
#include "strbuf.h"
#include "string-list.h"
@@ -64,7 +68,7 @@ int cmd__progress(int argc, const char **argv)
else
die("invalid input: '%s'", line.buf);
- progress = start_progress(title, total);
+ progress = start_progress(the_repository, title, total);
} else if (skip_prefix(line.buf, "progress ", (const char **) &end)) {
uint64_t item_count = strtoull(end, &end, 10);
if (*end != '\0')
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 01cf77ae65..028ec00306 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -35,7 +35,7 @@ int cmd__reach(int ac, const char **av)
struct commit_list *X, *Y;
struct object_array X_obj = OBJECT_ARRAY_INIT;
struct commit **X_array, **Y_array;
- int X_nr, X_alloc, Y_nr, Y_alloc;
+ size_t X_nr, X_alloc, Y_nr, Y_alloc;
struct strbuf buf = STRBUF_INIT;
struct repository *r = the_repository;
@@ -157,7 +157,7 @@ int cmd__reach(int ac, const char **av)
clear_contains_cache(&cache);
} else if (!strcmp(av[1], "get_reachable_subset")) {
const int reachable_flag = 1;
- int i, count = 0;
+ int count = 0;
struct commit_list *current;
struct commit_list *list = get_reachable_subset(X_array, X_nr,
Y_array, Y_nr,
@@ -169,7 +169,7 @@ int cmd__reach(int ac, const char **av)
oid_to_hex(&list->item->object.oid));
count++;
}
- for (i = 0; i < Y_nr; i++) {
+ for (size_t i = 0; i < Y_nr; i++) {
if (Y_array[i]->object.flags & reachable_flag)
count--;
}
diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c
index 054cbcf5d8..63a200b8d4 100644
--- a/t/helper/test-serve-v2.c
+++ b/t/helper/test-serve-v2.c
@@ -1,6 +1,9 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "gettext.h"
#include "parse-options.h"
+#include "repository.h"
#include "serve.h"
#include "setup.h"
@@ -28,9 +31,9 @@ int cmd__serve_v2(int argc, const char **argv)
PARSE_OPT_KEEP_UNKNOWN_OPT);
if (advertise_capabilities)
- protocol_v2_advertise_capabilities();
+ protocol_v2_advertise_capabilities(the_repository);
else
- protocol_v2_serve_loop(stateless_rpc);
+ protocol_v2_serve_loop(the_repository, stateless_rpc);
return 0;
}
diff --git a/t/helper/test-simple-ipc.c b/t/helper/test-simple-ipc.c
index fb5927775d..03cc5eea2c 100644
--- a/t/helper/test-simple-ipc.c
+++ b/t/helper/test-simple-ipc.c
@@ -612,8 +612,8 @@ int cmd__simple_ipc(int argc, const char **argv)
if (argc < 2)
usage_with_options(simple_ipc_usage, options);
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(simple_ipc_usage, options);
+ show_usage_with_options_if_asked(argc, argv,
+ simple_ipc_usage, options);
if (argc == 2 && !strcmp(argv[1], "SUPPORTS_SIMPLE_IPC"))
return 0;
diff --git a/t/meson.build b/t/meson.build
index 6dd41216ef..14fea8dddf 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -1,5 +1,6 @@
clar_test_suites = [
'unit-tests/u-ctype.c',
+ 'unit-tests/u-hash.c',
'unit-tests/u-mem-pool.c',
'unit-tests/u-prio-queue.c',
'unit-tests/u-reftable-tree.c',
@@ -44,7 +45,6 @@ test('unit-tests', clar_unit_tests)
unit_test_programs = [
'unit-tests/t-example-decorate.c',
- 'unit-tests/t-hash.c',
'unit-tests/t-hashmap.c',
'unit-tests/t-oid-array.c',
'unit-tests/t-oidmap.c',
diff --git a/t/t0012-help.sh b/t/t0012-help.sh
index 1d273d91c2..d3a0967e9d 100755
--- a/t/t0012-help.sh
+++ b/t/t0012-help.sh
@@ -255,8 +255,9 @@ do
(
GIT_CEILING_DIRECTORIES=$(pwd) &&
export GIT_CEILING_DIRECTORIES &&
- test_expect_code 129 git -C sub $builtin -h >output 2>&1
+ test_expect_code 129 git -C sub $builtin -h >output 2>err
) &&
+ test_must_be_empty err &&
test_grep usage output
'
done <builtins
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index ff9bf213aa..398865d6eb 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -240,7 +240,8 @@ test_expect_success "setup" '
git config extensions.objectformat $test_hash_algo &&
git config extensions.compatobjectformat $test_compat_hash_algo &&
echo_without_newline "$hello_content" > hello &&
- git update-index --add hello
+ git update-index --add hello &&
+ git commit -m "add hello file"
'
run_blob_tests () {
@@ -602,6 +603,34 @@ test_expect_success FUNNYNAMES '--batch-check, -Z with newline in input' '
test_cmp expect actual
'
+test_expect_success 'setup with curly braches in input' '
+ git branch "foo{bar" HEAD &&
+ git branch "foo@" HEAD
+'
+
+test_expect_success 'object reference with curly brace' '
+ git cat-file -p "foo{bar:hello" >actual &&
+ git cat-file -p HEAD:hello >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'object reference with at-sign' '
+ git cat-file -p "foo@@{0}:hello" >actual &&
+ git cat-file -p HEAD:hello >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'setup with commit with colon' '
+ git commit-tree -m "testing: just a bunch of junk" HEAD^{tree} >out &&
+ git branch other $(cat out)
+'
+
+test_expect_success 'object reference via commit text search' '
+ git cat-file -p "other^{/testing:}:hello" >actual &&
+ git cat-file -p HEAD:hello >expect &&
+ test_cmp expect actual
+'
+
test_expect_success 'setup blobs which are likely to delta' '
test-tool genrandom foo 10240 >foo &&
{ cat foo && echo plus; } >foo-plus &&
diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh
index 8212a70be8..e273ab29c7 100755
--- a/t/t5504-fetch-receive-strict.sh
+++ b/t/t5504-fetch-receive-strict.sh
@@ -167,6 +167,8 @@ test_expect_success 'fsck with unsorted skipList' '
test_expect_success 'fsck with invalid or bogus skipList input' '
git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
+ test_must_fail git -c fsck.skipList -c fsck.missingEmail=ignore fsck 2>err &&
+ test_grep "unable to parse '\'fsck.skiplist\'' from command-line config" err &&
test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err &&
test_grep "could not open.*: does-not-exist" err &&
test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
@@ -213,6 +215,11 @@ test_expect_success 'fsck with exhaustive accepted skipList input (various types
test_must_be_empty err
'
+test_expect_success 'receive-pack with missing receive.fsck.skipList path' '
+ test_must_fail git -c receive.fsck.skipList receive-pack dst 2>err &&
+ test_grep "unable to parse '\'receive.fsck.skiplist\'' from command-line config" err
+'
+
test_expect_success 'push with receive.fsck.skipList' '
git push . $commit:refs/heads/bogus &&
rm -rf dst &&
@@ -255,6 +262,9 @@ test_expect_success 'fetch with fetch.fsck.skipList' '
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
# Invalid and/or bogus skipList input
+ test_must_fail git --git-dir=dst/.git -c fetch.fsck.skipList fetch \
+ "file://$(pwd)" $refspec 2>err &&
+ test_grep "unable to parse '\'fetch.fsck.skiplist\'' from command-line config" err &&
git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index 3f6160d702..76843a6169 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -82,11 +82,13 @@ check_describe R-2-gHASH HEAD^^
check_describe A-3-gHASH HEAD^^2
check_describe B HEAD^^2^
check_describe R-1-gHASH HEAD^^^
+check_describe R-1-gHASH R-1-g$(git rev-parse --short HEAD^^)~1
check_describe c-7-gHASH --tags HEAD
check_describe c-6-gHASH --tags HEAD^
check_describe e-1-gHASH --tags HEAD^^
check_describe c-2-gHASH --tags HEAD^^2
+check_describe c-2-gHASH --tags c-2-g$(git rev-parse --short HEAD^^2)^0
check_describe B --tags HEAD^^2^
check_describe e --tags HEAD^^^
check_describe e --tags --exact-match HEAD^^^
@@ -725,4 +727,26 @@ test_expect_success '--exact-match does not show --always fallback' '
test_must_fail git describe --exact-match --always
'
+test_expect_success 'avoid being fooled by describe-like filename' '
+ test_when_finished rm out &&
+
+ git rev-parse --short HEAD >out &&
+ FILENAME=filename-g$(cat out) &&
+ touch $FILENAME &&
+ git add $FILENAME &&
+ git commit -m "Add $FILENAME" &&
+
+ git cat-file -t HEAD:$FILENAME >actual &&
+
+ echo blob >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'do not be fooled by invalid describe format ' '
+ test_when_finished rm out &&
+
+ git rev-parse --short HEAD >out &&
+ test_must_fail git cat-file -t "refs/tags/super-invalid/./../...../ ~^:/?*[////\\\\\\&}/busted.lock-42-g"$(cat out)
+'
+
test_done
diff --git a/t/t7110-reset-merge.sh b/t/t7110-reset-merge.sh
index 61669a2d21..9a335071af 100755
--- a/t/t7110-reset-merge.sh
+++ b/t/t7110-reset-merge.sh
@@ -270,13 +270,13 @@ test_expect_success '--merge is ok with added/deleted merge' '
git reset --hard third &&
rm -f file2 &&
test_must_fail git merge branch3 &&
- ! test -f file2 &&
- test -f file3 &&
+ test_path_is_missing file2 &&
+ test_path_is_file file3 &&
git diff --exit-code file3 &&
git diff --exit-code branch3 file3 &&
git reset --merge HEAD &&
- ! test -f file3 &&
- ! test -f file2 &&
+ test_path_is_missing file3 &&
+ test_path_is_missing file2 &&
git diff --exit-code --cached
'
@@ -284,8 +284,8 @@ test_expect_success '--keep fails with added/deleted merge' '
git reset --hard third &&
rm -f file2 &&
test_must_fail git merge branch3 &&
- ! test -f file2 &&
- test -f file3 &&
+ test_path_is_missing file2 &&
+ test_path_is_file file3 &&
git diff --exit-code file3 &&
git diff --exit-code branch3 file3 &&
test_must_fail git reset --keep HEAD 2>err.log &&
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index 8d7b234beb..77b6d0040e 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -426,14 +426,14 @@ test_expect_success 'option-like arguments passed to foreach commands are not lo
git submodule foreach "echo be --quiet" > ../expected &&
git submodule foreach echo be --quiet > ../actual
) &&
- grep -sq -e "--quiet" expected &&
+ test_grep -e "--quiet" expected &&
test_cmp expected actual
'
test_expect_success 'option-like arguments passed to foreach recurse correctly' '
git -C clone2 submodule foreach --recursive "echo be --an-option" >expect &&
git -C clone2 submodule foreach --recursive echo be --an-option >actual &&
- grep -e "--an-option" expect &&
+ test_grep -e "--an-option" expect &&
test_cmp expect actual
'
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index ef54cff4fa..2a8df29219 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -173,7 +173,7 @@ test_expect_success 'merge -h with invalid index' '
cd broken &&
git init &&
>.git/index &&
- test_expect_code 129 git merge -h 2>usage
+ test_expect_code 129 git merge -h >usage
) &&
test_grep "[Uu]sage: git merge" broken/usage
'
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 78e054ab50..c25cee0ad8 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -927,7 +927,7 @@ test_expect_success () {
test -n "$test_skip_test_preamble" ||
say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $test_body"
if test_run_ "$test_body" &&
- check_test_results_san_file_empty_
+ ! check_test_results_san_file_has_entries_
then
test_ok_ "$1"
else
diff --git a/t/test-lib.sh b/t/test-lib.sh
index d1f62adbf8..9f27a49995 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1169,20 +1169,20 @@ test_atexit_handler () {
teardown_malloc_check
}
-check_test_results_san_file_empty_ () {
- test -z "$TEST_RESULTS_SAN_FILE" && return 0
-
- # stderr piped to /dev/null because the directory may have
- # been "rmdir"'d already.
- ! find "$TEST_RESULTS_SAN_DIR" \
- -type f \
- -name "$TEST_RESULTS_SAN_FILE_PFX.*" 2>/dev/null |
- xargs grep ^DEDUP_TOKEN |
+check_test_results_san_file_has_entries_ () {
+ test -z "$TEST_RESULTS_SAN_FILE" && return 1
+
+ # Lines marked with DEDUP_TOKEN show unique leaks. We only care that we
+ # found at least one.
+ #
+ # But also suppress any false positives caused by bugs or races in the
+ # sanitizer itself.
+ grep -s ^DEDUP_TOKEN "$TEST_RESULTS_SAN_FILE".* |
grep -qv sanitizer::GetThreadStackTopAndBottom
}
check_test_results_san_file_ () {
- if check_test_results_san_file_empty_
+ if ! check_test_results_san_file_has_entries_
then
return
fi &&
diff --git a/t/unit-tests/t-reftable-readwrite.c b/t/unit-tests/t-reftable-readwrite.c
index 6b75a419b9..f22b977563 100644
--- a/t/unit-tests/t-reftable-readwrite.c
+++ b/t/unit-tests/t-reftable-readwrite.c
@@ -108,8 +108,8 @@ static void t_log_buffer_size(void)
hash, to ensure that the compressed part is larger than the original.
*/
for (i = 0; i < REFTABLE_HASH_SIZE_SHA1; i++) {
- log.value.update.old_hash[i] = (uint8_t)(git_rand() % 256);
- log.value.update.new_hash[i] = (uint8_t)(git_rand() % 256);
+ log.value.update.old_hash[i] = (uint8_t)(git_rand(0) % 256);
+ log.value.update.new_hash[i] = (uint8_t)(git_rand(0) % 256);
}
reftable_writer_set_limits(w, update_index, update_index);
err = reftable_writer_add_log(w, &log);
@@ -325,7 +325,7 @@ static void t_log_zlib_corruption(void)
};
for (i = 0; i < sizeof(message) - 1; i++)
- message[i] = (uint8_t)(git_rand() % 64 + ' ');
+ message[i] = (uint8_t)(git_rand(0) % 64 + ' ');
reftable_writer_set_limits(w, 1, 1);
diff --git a/t/unit-tests/t-hash.c b/t/unit-tests/u-hash.c
index e62647019b..a0320efe4b 100644
--- a/t/unit-tests/t-hash.c
+++ b/t/unit-tests/u-hash.c
@@ -1,14 +1,11 @@
-#include "test-lib.h"
+#include "unit-test.h"
#include "hex.h"
#include "strbuf.h"
static void check_hash_data(const void *data, size_t data_length,
const char *expected_hashes[])
{
- if (!check(data != NULL)) {
- test_msg("BUG: NULL data pointer provided");
- return;
- }
+ cl_assert(data != NULL);
for (size_t i = 1; i < ARRAY_SIZE(hash_algos); i++) {
git_hash_ctx ctx;
@@ -19,66 +16,94 @@ static void check_hash_data(const void *data, size_t data_length,
algop->update_fn(&ctx, data, data_length);
algop->final_fn(hash, &ctx);
- if (!check_str(hash_to_hex_algop(hash, algop), expected_hashes[i - 1]))
- test_msg("result does not match with the expected for %s\n", hash_algos[i].name);
+ cl_assert_equal_s(hash_to_hex_algop(hash,algop), expected_hashes[i - 1]);
}
}
/* Works with a NUL terminated string. Doesn't work if it should contain a NUL character. */
#define TEST_HASH_STR(data, expected_sha1, expected_sha256) do { \
const char *expected_hashes[] = { expected_sha1, expected_sha256 }; \
- TEST(check_hash_data(data, strlen(data), expected_hashes), \
- "SHA1 and SHA256 (%s) works", #data); \
+ check_hash_data(data, strlen(data), expected_hashes); \
} while (0)
/* Only works with a literal string, useful when it contains a NUL character. */
#define TEST_HASH_LITERAL(literal, expected_sha1, expected_sha256) do { \
const char *expected_hashes[] = { expected_sha1, expected_sha256 }; \
- TEST(check_hash_data(literal, (sizeof(literal) - 1), expected_hashes), \
- "SHA1 and SHA256 (%s) works", #literal); \
+ check_hash_data(literal, (sizeof(literal) - 1), expected_hashes); \
} while (0)
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
+void test_hash__empty_string(void)
{
- struct strbuf aaaaaaaaaa_100000 = STRBUF_INIT;
- struct strbuf alphabet_100000 = STRBUF_INIT;
-
- strbuf_addstrings(&aaaaaaaaaa_100000, "aaaaaaaaaa", 100000);
- strbuf_addstrings(&alphabet_100000, "abcdefghijklmnopqrstuvwxyz", 100000);
-
TEST_HASH_STR("",
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+}
+
+void test_hash__single_character(void)
+{
TEST_HASH_STR("a",
"86f7e437faa5a7fce15d1ddcb9eaeaea377667b8",
"ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb");
+}
+
+void test_hash__multi_character(void)
+{
TEST_HASH_STR("abc",
"a9993e364706816aba3e25717850c26c9cd0d89d",
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
+}
+
+void test_hash__message_digest(void)
+{
TEST_HASH_STR("message digest",
"c12252ceda8be8994d5fa0290a47231c1d16aae3",
"f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650");
+}
+
+void test_hash__alphabet(void)
+{
TEST_HASH_STR("abcdefghijklmnopqrstuvwxyz",
"32d10c7b8cf96570ca04ce37f2a19d84240d3a89",
"71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73");
+}
+
+void test_hash__aaaaaaaaaa_100000(void)
+{
+ struct strbuf aaaaaaaaaa_100000 = STRBUF_INIT;
+ strbuf_addstrings(&aaaaaaaaaa_100000, "aaaaaaaaaa", 100000);
TEST_HASH_STR(aaaaaaaaaa_100000.buf,
"34aa973cd4c4daa4f61eeb2bdbad27316534016f",
"cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0");
+ strbuf_release(&aaaaaaaaaa_100000);
+}
+
+void test_hash__alphabet_100000(void)
+{
+ struct strbuf alphabet_100000 = STRBUF_INIT;
+ strbuf_addstrings(&alphabet_100000, "abcdefghijklmnopqrstuvwxyz", 100000);
TEST_HASH_STR(alphabet_100000.buf,
"e7da7c55b3484fdf52aebec9cbe7b85a98f02fd4",
"e406ba321ca712ad35a698bf0af8d61fc4dc40eca6bdcea4697962724ccbde35");
+ strbuf_release(&alphabet_100000);
+}
+
+void test_hash__zero_blob_literal(void)
+{
TEST_HASH_LITERAL("blob 0\0",
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
"473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813");
+}
+
+void test_hash__three_blob_literal(void)
+{
TEST_HASH_LITERAL("blob 3\0abc",
"f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f",
"c1cf6e465077930e88dc5136641d402f72a229ddd996f627d60e9639eaba35a6");
+}
+
+void test_hash__zero_tree_literal(void)
+{
TEST_HASH_LITERAL("tree 0\0",
"4b825dc642cb6eb9a060e54bf8d69288fbee4904",
"6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321");
-
- strbuf_release(&aaaaaaaaaa_100000);
- strbuf_release(&alphabet_100000);
-
- return test_done();
}
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 659fcdcc29..0ea078a5c5 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "tmp-objdir.h"
#include "abspath.h"
@@ -16,6 +14,7 @@
#include "repository.h"
struct tmp_objdir {
+ struct repository *repo;
struct strbuf path;
struct strvec env;
struct object_directory *prev_odb;
@@ -116,7 +115,8 @@ static int setup_tmp_objdir(const char *root)
return ret;
}
-struct tmp_objdir *tmp_objdir_create(const char *prefix)
+struct tmp_objdir *tmp_objdir_create(struct repository *r,
+ const char *prefix)
{
static int installed_handlers;
struct tmp_objdir *t;
@@ -125,6 +125,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
BUG("only one tmp_objdir can be used at a time");
t = xcalloc(1, sizeof(*t));
+ t->repo = r;
strbuf_init(&t->path, 0);
strvec_init(&t->env);
@@ -134,7 +135,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
* them.
*/
strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX",
- repo_get_object_directory(the_repository), prefix);
+ repo_get_object_directory(r), prefix);
if (!mkdtemp(t->path.buf)) {
/* free, not destroy, as we never touched the filesystem */
@@ -154,7 +155,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
}
env_append(&t->env, ALTERNATE_DB_ENVIRONMENT,
- absolute_path(repo_get_object_directory(the_repository)));
+ absolute_path(repo_get_object_directory(r)));
env_replace(&t->env, DB_ENVIRONMENT, absolute_path(t->path.buf));
env_replace(&t->env, GIT_QUARANTINE_ENVIRONMENT,
absolute_path(t->path.buf));
@@ -273,14 +274,14 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
return 0;
if (t->prev_odb) {
- if (the_repository->objects->odb->will_destroy)
+ if (t->repo->objects->odb->will_destroy)
BUG("migrating an ODB that was marked for destruction");
restore_primary_odb(t->prev_odb, t->path.buf);
t->prev_odb = NULL;
}
strbuf_addbuf(&src, &t->path);
- strbuf_addstr(&dst, repo_get_object_directory(the_repository));
+ strbuf_addstr(&dst, repo_get_object_directory(t->repo));
ret = migrate_paths(&src, &dst, 0);
diff --git a/tmp-objdir.h b/tmp-objdir.h
index 237d96b660..fceda14979 100644
--- a/tmp-objdir.h
+++ b/tmp-objdir.h
@@ -11,7 +11,7 @@
* Example:
*
* struct child_process child = CHILD_PROCESS_INIT;
- * struct tmp_objdir *t = tmp_objdir_create("incoming");
+ * struct tmp_objdir *t = tmp_objdir_create(repo, "incoming");
* strvec_push(&child.args, cmd);
* strvec_pushv(&child.env, tmp_objdir_env(t));
* if (!run_command(&child)) && !tmp_objdir_migrate(t))
@@ -21,13 +21,14 @@
*
*/
+struct repository;
struct tmp_objdir;
/*
* Create a new temporary object directory with the specified prefix;
* returns NULL on failure.
*/
-struct tmp_objdir *tmp_objdir_create(const char *prefix);
+struct tmp_objdir *tmp_objdir_create(struct repository *r, const char *prefix);
/*
* Return a list of environment strings, suitable for use with
diff --git a/trace.c b/trace.c
index 2cfd25942e..9b99460db8 100644
--- a/trace.c
+++ b/trace.c
@@ -21,7 +21,6 @@
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
-#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
@@ -298,7 +297,7 @@ static const char *quote_crnl(const char *path)
return new_path.buf;
}
-void trace_repo_setup(void)
+void trace_repo_setup(struct repository *r)
{
const char *git_work_tree, *prefix = startup_info->prefix;
char *cwd;
@@ -308,14 +307,14 @@ void trace_repo_setup(void)
cwd = xgetcwd();
- if (!(git_work_tree = repo_get_work_tree(the_repository)))
+ if (!(git_work_tree = repo_get_work_tree(r)))
git_work_tree = "(null)";
if (!startup_info->prefix)
prefix = "(null)";
- trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(repo_get_git_dir(the_repository)));
- trace_printf_key(&trace_setup_key, "setup: git_common_dir: %s\n", quote_crnl(repo_get_common_dir(the_repository)));
+ trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(repo_get_git_dir(r)));
+ trace_printf_key(&trace_setup_key, "setup: git_common_dir: %s\n", quote_crnl(repo_get_common_dir(r)));
trace_printf_key(&trace_setup_key, "setup: worktree: %s\n", quote_crnl(git_work_tree));
trace_printf_key(&trace_setup_key, "setup: cwd: %s\n", quote_crnl(cwd));
trace_printf_key(&trace_setup_key, "setup: prefix: %s\n", quote_crnl(prefix));
diff --git a/trace.h b/trace.h
index d304d55aa1..9152fe9b3e 100644
--- a/trace.h
+++ b/trace.h
@@ -92,7 +92,9 @@ extern struct trace_key trace_default_key;
extern struct trace_key trace_perf_key;
extern struct trace_key trace_setup_key;
-void trace_repo_setup(void);
+struct repository;
+
+void trace_repo_setup(struct repository *r);
/**
* Checks whether the trace key is enabled. Used to prevent expensive
diff --git a/transport.c b/transport.c
index 10d820c333..81ae8243b9 100644
--- a/transport.c
+++ b/transport.c
@@ -932,7 +932,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
break;
case protocol_v1:
case protocol_v0:
- ret = send_pack(&args, data->fd, data->conn, remote_refs,
+ ret = send_pack(the_repository, &args, data->fd, data->conn, remote_refs,
&data->extra_have);
break;
case protocol_unknown_version:
diff --git a/unpack-trees.c b/unpack-trees.c
index b3be5d542f..334cb84f65 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -372,7 +372,8 @@ static struct progress *get_progress(struct unpack_trees_options *o,
total++;
}
- return start_delayed_progress(_("Updating files"), total);
+ return start_delayed_progress(the_repository,
+ _("Updating files"), total);
}
static void setup_collided_checkout_detection(struct checkout *state,
@@ -1773,6 +1774,7 @@ static int clear_ce_flags(struct index_state *istate,
strbuf_reset(&prefix);
if (show_progress)
istate->progress = start_delayed_progress(
+ the_repository,
_("Updating index flags"),
istate->cache_nr);
diff --git a/usage.c b/usage.c
index 47709006c1..38b46bbbfe 100644
--- a/usage.c
+++ b/usage.c
@@ -8,7 +8,7 @@
#include "gettext.h"
#include "trace2.h"
-static void vreportf(const char *prefix, const char *err, va_list params)
+static void vfreportf(FILE *f, const char *prefix, const char *err, va_list params)
{
char msg[4096];
char *p, *pend = msg + sizeof(msg);
@@ -32,8 +32,13 @@ static void vreportf(const char *prefix, const char *err, va_list params)
}
*(p++) = '\n'; /* we no longer need a NUL */
- fflush(stderr);
- write_in_full(2, msg, p - msg);
+ fflush(f);
+ write_in_full(fileno(f), msg, p - msg);
+}
+
+static void vreportf(const char *prefix, const char *err, va_list params)
+{
+ vfreportf(stderr, prefix, err, params);
}
static NORETURN void usage_builtin(const char *err, va_list params)
@@ -173,6 +178,22 @@ void NORETURN usage(const char *err)
usagef("%s", err);
}
+static void show_usage_if_asked_helper(const char *err, ...)
+{
+ va_list params;
+
+ va_start(params, err);
+ vfreportf(stdout, _("usage: "), err, params);
+ va_end(params);
+ exit(129);
+}
+
+void show_usage_if_asked(int ac, const char **av, const char *err)
+{
+ if (ac == 2 && !strcmp(av[1], "-h"))
+ show_usage_if_asked_helper(err);
+}
+
void NORETURN die(const char *err, ...)
{
va_list params;
diff --git a/version.c b/version.c
index 4d763ab48d..4786c4e0a5 100644
--- a/version.c
+++ b/version.c
@@ -1,8 +1,13 @@
#include "git-compat-util.h"
#include "version.h"
-#include "version-def.h"
#include "strbuf.h"
+#ifndef GIT_VERSION_H
+# include "version-def.h"
+#else
+# include GIT_VERSION_H
+#endif
+
const char git_version_string[] = GIT_VERSION;
const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT;
diff --git a/walker.c b/walker.c
index 7cc9dbea46..1cf3da0219 100644
--- a/walker.c
+++ b/walker.c
@@ -172,7 +172,8 @@ static int loop(struct walker *walker)
uint64_t nr = 0;
if (walker->get_progress)
- progress = start_delayed_progress(_("Fetching objects"), 0);
+ progress = start_delayed_progress(the_repository,
+ _("Fetching objects"), 0);
while (process_queue) {
struct object *obj = process_queue->item;
diff --git a/wrapper.c b/wrapper.c
index fa79fd6ec9..8b98593149 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -479,7 +479,7 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
for (count = 0; count < TMP_MAX; ++count) {
int i;
uint64_t v;
- if (csprng_bytes(&v, sizeof(v)) < 0)
+ if (csprng_bytes(&v, sizeof(v), 0) < 0)
return error_errno("unable to get random bytes for temporary file");
/* Fill in the random bits. */
@@ -750,7 +750,7 @@ int open_nofollow(const char *path, int flags)
#endif
}
-int csprng_bytes(void *buf, size_t len)
+int csprng_bytes(void *buf, size_t len, MAYBE_UNUSED unsigned flags)
{
#if defined(HAVE_ARC4RANDOM) || defined(HAVE_ARC4RANDOM_LIBBSD)
/* This function never returns an error. */
@@ -785,14 +785,18 @@ int csprng_bytes(void *buf, size_t len)
return -1;
return 0;
#elif defined(HAVE_OPENSSL_CSPRNG)
- int res = RAND_bytes(buf, len);
- if (res == 1)
+ switch (RAND_pseudo_bytes(buf, len)) {
+ case 1:
return 0;
- if (res == -1)
- errno = ENOTSUP;
- else
+ case 0:
+ if (flags & CSPRNG_BYTES_INSECURE)
+ return 0;
errno = EIO;
- return -1;
+ return -1;
+ default:
+ errno = ENOTSUP;
+ return -1;
+ }
#else
ssize_t res;
char *p = buf;
@@ -816,11 +820,11 @@ int csprng_bytes(void *buf, size_t len)
#endif
}
-uint32_t git_rand(void)
+uint32_t git_rand(unsigned flags)
{
uint32_t result;
- if (csprng_bytes(&result, sizeof(result)) < 0)
+ if (csprng_bytes(&result, sizeof(result), flags) < 0)
die(_("unable to get random bytes"));
return result;
diff --git a/wrapper.h b/wrapper.h
index a6b3e1f09e..7df824e34a 100644
--- a/wrapper.h
+++ b/wrapper.h
@@ -127,18 +127,26 @@ int open_nofollow(const char *path, int flags);
void sleep_millisec(int millisec);
+enum {
+ /*
+ * Accept insecure bytes, which some CSPRNG implementations may return
+ * in case the entropy pool has been exhausted.
+ */
+ CSPRNG_BYTES_INSECURE = (1 << 0),
+};
+
/*
* Generate len bytes from the system cryptographically secure PRNG.
* Returns 0 on success and -1 on error, setting errno. The inability to
- * satisfy the full request is an error.
+ * satisfy the full request is an error. Accepts CSPRNG flags.
*/
-int csprng_bytes(void *buf, size_t len);
+int csprng_bytes(void *buf, size_t len, unsigned flags);
/*
* Returns a random uint32_t, uniformly distributed across all possible
- * values.
+ * values. Accepts CSPRNG flags.
*/
-uint32_t git_rand(void);
+uint32_t git_rand(unsigned flags);
/* Provide log2 of the given `size_t`. */
static inline unsigned log2u(uintmax_t sz)