Merge branch 'kn/pass-repo-to-builtin-sub-sub-commands' into kn/midx-wo-the-repository

* kn/pass-repo-to-builtin-sub-sub-commands:
  builtin: pass repository to sub commands
  Git 2.47.1
  Makefile(s): avoid recipe prefix in conditional statements
  doc: switch links to https
  doc: update links to current pages
  The eleventh batch
  pack-objects: only perform verbatim reuse on the preferred pack
  t5332-multi-pack-reuse.sh: demonstrate duplicate packing failure
  test-lib: move malloc-debug setup after $PATH setup
  builtin/difftool: intialize some hashmap variables
  refspec: store raw refspecs inside refspec_item
  refspec: drop separate raw_nr count
  fetch: adjust refspec->raw_nr when filtering prefetch refspecs
  test-lib: check malloc debug LD_PRELOAD before using
This commit is contained in:
Junio C Hamano
2024-12-04 10:32:02 +09:00
29 changed files with 406 additions and 279 deletions

View File

@@ -24,3 +24,8 @@ Fixes since Git 2.47
* A "git fetch" from the superproject going down to a submodule used * A "git fetch" from the superproject going down to a submodule used
a wrong remote when the default remote names are set differently a wrong remote when the default remote names are set differently
between them. between them.
* The "gitk" project tree has been synchronized again with its new
maintainer, Johannes Sixt.
Also contains minor documentation updates and code clean-ups.

View File

@@ -145,6 +145,20 @@ Fixes since v2.47
repository. Work it around by including these objects in the repository. Work it around by including these objects in the
referring promisor pack at the receiving end of the fetch. referring promisor pack at the receiving end of the fetch.
* Avoid build/test breakage on a system without working malloc debug
support dynamic library.
(merge 72ad6dc368 jk/test-malloc-debug-check later to maint).
* Double-free fix.
(merge fe17a25905 jk/fetch-prefetch-double-free-fix later to maint).
* Use of some uninitialized variables in "git difftool" has been
corrected.
* Object reuse code based on multi-pack-index sent an unwanted copy
of object.
(merge e199290592 tb/multi-pack-reuse-dupfix later to maint).
* Other code cleanup, docfix, build fix, etc. * Other code cleanup, docfix, build fix, etc.
(merge 1164e270b5 jk/output-prefix-cleanup later to maint). (merge 1164e270b5 jk/output-prefix-cleanup later to maint).
(merge f36b8cbaef jh/config-unset-doc-fix later to maint). (merge f36b8cbaef jh/config-unset-doc-fix later to maint).

View File

@@ -1312,7 +1312,8 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)
return res; return res;
} }
static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED) static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
if (argc > 1) if (argc > 1)
return error(_("'%s' requires either no argument or a commit"), return error(_("'%s' requires either no argument or a commit"),
@@ -1320,7 +1321,8 @@ static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNU
return bisect_reset(argc ? argv[0] : NULL); return bisect_reset(argc ? argv[0] : NULL);
} }
static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED) static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
int res; int res;
struct bisect_terms terms = { 0 }; struct bisect_terms terms = { 0 };
@@ -1333,7 +1335,8 @@ static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNU
return res; return res;
} }
static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNUSED) static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
int res; int res;
struct bisect_terms terms = { 0 }; struct bisect_terms terms = { 0 };
@@ -1344,7 +1347,8 @@ static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNU
return res; return res;
} }
static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *prefix) static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *prefix,
struct repository *repo UNUSED)
{ {
int res; int res;
struct bisect_terms terms = { 0 }; struct bisect_terms terms = { 0 };
@@ -1358,12 +1362,15 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref
return res; return res;
} }
static int cmd_bisect__log(int argc UNUSED, const char **argv UNUSED, const char *prefix UNUSED) static int cmd_bisect__log(int argc UNUSED, const char **argv UNUSED,
const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
return bisect_log(); return bisect_log();
} }
static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UNUSED) static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
int res; int res;
struct bisect_terms terms = { 0 }; struct bisect_terms terms = { 0 };
@@ -1376,7 +1383,8 @@ static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UN
return res; return res;
} }
static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUSED) static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
int res; int res;
struct bisect_terms terms = { 0 }; struct bisect_terms terms = { 0 };
@@ -1388,7 +1396,8 @@ static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUS
return res; return res;
} }
static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix UNUSED) static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
int res; int res;
struct bisect_terms terms = { 0 }; struct bisect_terms terms = { 0 };
@@ -1399,7 +1408,8 @@ static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix
return res; return res;
} }
static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSED) static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
int res; int res;
struct bisect_terms terms = { 0 }; struct bisect_terms terms = { 0 };
@@ -1415,7 +1425,7 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE
int cmd_bisect(int argc, int cmd_bisect(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
int res = 0; int res = 0;
parse_opt_subcommand_fn *fn = NULL; parse_opt_subcommand_fn *fn = NULL;
@@ -1451,7 +1461,7 @@ int cmd_bisect(int argc,
} else { } else {
argc--; argc--;
argv++; argv++;
res = fn(argc, argv, prefix); res = fn(argc, argv, prefix, repo);
} }
return is_bisect_success(res) ? 0 : -res; return is_bisect_success(res) ? 0 : -res;

View File

@@ -67,7 +67,8 @@ static int parse_options_cmd_bundle(int argc,
return argc; return argc;
} }
static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { static int cmd_bundle_create(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED) {
struct strvec pack_opts = STRVEC_INIT; struct strvec pack_opts = STRVEC_INIT;
int version = -1; int version = -1;
int ret; int ret;
@@ -123,7 +124,8 @@ static int open_bundle(const char *path, struct bundle_header *header,
return read_bundle_header(path, header); return read_bundle_header(path, header);
} }
static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) { static int cmd_bundle_verify(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED) {
struct bundle_header header = BUNDLE_HEADER_INIT; struct bundle_header header = BUNDLE_HEADER_INIT;
int bundle_fd = -1; int bundle_fd = -1;
int quiet = 0; int quiet = 0;
@@ -164,7 +166,8 @@ cleanup:
return ret; return ret;
} }
static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix) { static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED) {
struct bundle_header header = BUNDLE_HEADER_INIT; struct bundle_header header = BUNDLE_HEADER_INIT;
int bundle_fd = -1; int bundle_fd = -1;
int ret; int ret;
@@ -189,7 +192,8 @@ cleanup:
return ret; return ret;
} }
static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix) { static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED) {
struct bundle_header header = BUNDLE_HEADER_INIT; struct bundle_header header = BUNDLE_HEADER_INIT;
int bundle_fd = -1; int bundle_fd = -1;
int ret; int ret;
@@ -231,7 +235,7 @@ cleanup:
int cmd_bundle(int argc, int cmd_bundle(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
parse_opt_subcommand_fn *fn = NULL; parse_opt_subcommand_fn *fn = NULL;
struct option options[] = { struct option options[] = {
@@ -247,5 +251,5 @@ int cmd_bundle(int argc,
packet_trace_identity("bundle"); packet_trace_identity("bundle");
return !!fn(argc, argv, prefix); return !!fn(argc, argv, prefix, repo);
} }

View File

@@ -62,7 +62,8 @@ static struct option *add_common_options(struct option *to)
return parse_options_concat(common_opts, to); return parse_options_concat(common_opts, to);
} }
static int graph_verify(int argc, const char **argv, const char *prefix) static int graph_verify(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct commit_graph *graph = NULL; struct commit_graph *graph = NULL;
struct object_directory *odb = NULL; struct object_directory *odb = NULL;
@@ -214,7 +215,8 @@ static int git_commit_graph_write_config(const char *var, const char *value,
return 0; return 0;
} }
static int graph_write(int argc, const char **argv, const char *prefix) static int graph_write(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct string_list pack_indexes = STRING_LIST_INIT_DUP; struct string_list pack_indexes = STRING_LIST_INIT_DUP;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
@@ -333,7 +335,7 @@ cleanup:
int cmd_commit_graph(int argc, int cmd_commit_graph(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
parse_opt_subcommand_fn *fn = NULL; parse_opt_subcommand_fn *fn = NULL;
struct option builtin_commit_graph_options[] = { struct option builtin_commit_graph_options[] = {
@@ -352,5 +354,5 @@ int cmd_commit_graph(int argc,
builtin_commit_graph_usage, 0); builtin_commit_graph_usage, 0);
FREE_AND_NULL(options); FREE_AND_NULL(options);
return fn(argc, argv, prefix); return fn(argc, argv, prefix, repo);
} }

View File

@@ -826,7 +826,8 @@ static void display_options_init(struct config_display_options *opts)
} }
} }
static int cmd_config_list(int argc, const char **argv, const char *prefix) static int cmd_config_list(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT; struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT;
@@ -861,7 +862,8 @@ static int cmd_config_list(int argc, const char **argv, const char *prefix)
return 0; return 0;
} }
static int cmd_config_get(int argc, const char **argv, const char *prefix) static int cmd_config_get(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT; struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT;
@@ -915,7 +917,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix)
return ret; return ret;
} }
static int cmd_config_set(int argc, const char **argv, const char *prefix) static int cmd_config_set(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
const char *value_pattern = NULL, *comment_arg = NULL; const char *value_pattern = NULL, *comment_arg = NULL;
@@ -973,7 +976,8 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix)
return ret; return ret;
} }
static int cmd_config_unset(int argc, const char **argv, const char *prefix) static int cmd_config_unset(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
const char *value_pattern = NULL; const char *value_pattern = NULL;
@@ -1010,7 +1014,8 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix)
return ret; return ret;
} }
static int cmd_config_rename_section(int argc, const char **argv, const char *prefix) static int cmd_config_rename_section(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
struct option opts[] = { struct option opts[] = {
@@ -1039,7 +1044,8 @@ out:
return ret; return ret;
} }
static int cmd_config_remove_section(int argc, const char **argv, const char *prefix) static int cmd_config_remove_section(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
struct option opts[] = { struct option opts[] = {
@@ -1099,7 +1105,8 @@ static int show_editor(struct config_location_options *opts)
return 0; return 0;
} }
static int cmd_config_edit(int argc, const char **argv, const char *prefix) static int cmd_config_edit(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
struct option opts[] = { struct option opts[] = {
@@ -1395,7 +1402,7 @@ out:
int cmd_config(int argc, int cmd_config(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
parse_opt_subcommand_fn *subcommand = NULL; parse_opt_subcommand_fn *subcommand = NULL;
struct option subcommand_opts[] = { struct option subcommand_opts[] = {
@@ -1422,7 +1429,7 @@ int cmd_config(int argc,
if (subcommand) { if (subcommand) {
argc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage, argc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage,
PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT); PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT);
return subcommand(argc, argv, prefix); return subcommand(argc, argv, prefix, repo);
} }
return cmd_config_actions(argc, argv, prefix); return cmd_config_actions(argc, argv, prefix);

View File

@@ -376,7 +376,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
struct checkout lstate, rstate; struct checkout lstate, rstate;
int err = 0; int err = 0;
struct child_process cmd = CHILD_PROCESS_INIT; struct child_process cmd = CHILD_PROCESS_INIT;
struct hashmap wt_modified, tmp_modified; struct hashmap wt_modified = HASHMAP_INIT(path_entry_cmp, NULL);
struct hashmap tmp_modified = HASHMAP_INIT(path_entry_cmp, NULL);
int indices_loaded = 0; int indices_loaded = 0;
workdir = repo_get_work_tree(the_repository); workdir = repo_get_work_tree(the_repository);
@@ -601,9 +602,6 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
* in the common case of --symlinks and the difftool updating * in the common case of --symlinks and the difftool updating
* files through the symlink. * files through the symlink.
*/ */
hashmap_init(&wt_modified, path_entry_cmp, NULL, wtindex.cache_nr);
hashmap_init(&tmp_modified, path_entry_cmp, NULL, wtindex.cache_nr);
for (i = 0; i < wtindex.cache_nr; i++) { for (i = 0; i < wtindex.cache_nr; i++) {
struct hashmap_entry dummy; struct hashmap_entry dummy;
const char *name = wtindex.cache[i]->name; const char *name = wtindex.cache[i]->name;

View File

@@ -454,14 +454,10 @@ static void filter_prefetch_refspec(struct refspec *rs)
ref_namespace[NAMESPACE_TAGS].ref))) { ref_namespace[NAMESPACE_TAGS].ref))) {
int j; int j;
free(rs->items[i].src); refspec_item_clear(&rs->items[i]);
free(rs->items[i].dst);
free(rs->raw[i]);
for (j = i + 1; j < rs->nr; j++) { for (j = i + 1; j < rs->nr; j++)
rs->items[j - 1] = rs->items[j]; rs->items[j - 1] = rs->items[j];
rs->raw[j - 1] = rs->raw[j];
}
rs->nr--; rs->nr--;
i--; i--;
continue; continue;

View File

@@ -1571,7 +1571,8 @@ static int task_option_parse(const struct option *opt UNUSED,
return 0; return 0;
} }
static int maintenance_run(int argc, const char **argv, const char *prefix) static int maintenance_run(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int i; int i;
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT; struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
@@ -1633,7 +1634,8 @@ static char const * const builtin_maintenance_register_usage[] = {
NULL NULL
}; };
static int maintenance_register(int argc, const char **argv, const char *prefix) static int maintenance_register(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
char *config_file = NULL; char *config_file = NULL;
struct option options[] = { struct option options[] = {
@@ -1697,7 +1699,8 @@ static char const * const builtin_maintenance_unregister_usage[] = {
NULL NULL
}; };
static int maintenance_unregister(int argc, const char **argv, const char *prefix) static int maintenance_unregister(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int force = 0; int force = 0;
char *config_file = NULL; char *config_file = NULL;
@@ -2927,7 +2930,8 @@ static const char *const builtin_maintenance_start_usage[] = {
NULL NULL
}; };
static int maintenance_start(int argc, const char **argv, const char *prefix) static int maintenance_start(int argc, const char **argv, const char *prefix,
struct repository *repo)
{ {
struct maintenance_start_opts opts = { 0 }; struct maintenance_start_opts opts = { 0 };
struct option options[] = { struct option options[] = {
@@ -2950,7 +2954,7 @@ static int maintenance_start(int argc, const char **argv, const char *prefix)
if (update_background_schedule(&opts, 1)) if (update_background_schedule(&opts, 1))
die(_("failed to set up maintenance schedule")); die(_("failed to set up maintenance schedule"));
if (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL)) if (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL, repo))
warning(_("failed to add repo to global config")); warning(_("failed to add repo to global config"));
return 0; return 0;
} }
@@ -2960,7 +2964,8 @@ static const char *const builtin_maintenance_stop_usage[] = {
NULL NULL
}; };
static int maintenance_stop(int argc, const char **argv, const char *prefix) static int maintenance_stop(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct option options[] = { struct option options[] = {
OPT_END() OPT_END()
@@ -2980,7 +2985,7 @@ static const char * const builtin_maintenance_usage[] = {
int cmd_maintenance(int argc, int cmd_maintenance(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
parse_opt_subcommand_fn *fn = NULL; parse_opt_subcommand_fn *fn = NULL;
struct option builtin_maintenance_options[] = { struct option builtin_maintenance_options[] = {
@@ -2994,5 +2999,5 @@ int cmd_maintenance(int argc,
argc = parse_options(argc, argv, prefix, builtin_maintenance_options, argc = parse_options(argc, argv, prefix, builtin_maintenance_options,
builtin_maintenance_usage, 0); builtin_maintenance_usage, 0);
return fn(argc, argv, prefix); return fn(argc, argv, prefix, repo);
} }

View File

@@ -19,7 +19,8 @@ static const char * const builtin_hook_run_usage[] = {
NULL NULL
}; };
static int run(int argc, const char **argv, const char *prefix) static int run(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int i; int i;
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
@@ -70,7 +71,7 @@ usage:
int cmd_hook(int argc, int cmd_hook(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
parse_opt_subcommand_fn *fn = NULL; parse_opt_subcommand_fn *fn = NULL;
struct option builtin_hook_options[] = { struct option builtin_hook_options[] = {
@@ -81,5 +82,5 @@ int cmd_hook(int argc,
argc = parse_options(argc, argv, NULL, builtin_hook_options, argc = parse_options(argc, argv, NULL, builtin_hook_options,
builtin_hook_usage, 0); builtin_hook_usage, 0);
return fn(argc, argv, prefix); return fn(argc, argv, prefix, repo);
} }

View File

@@ -119,7 +119,8 @@ static void read_packs_from_stdin(struct string_list *to)
} }
static int cmd_multi_pack_index_write(int argc, const char **argv, static int cmd_multi_pack_index_write(int argc, const char **argv,
const char *prefix) const char *prefix,
struct repository *repo UNUSED)
{ {
struct option *options; struct option *options;
static struct option builtin_multi_pack_index_write_options[] = { static struct option builtin_multi_pack_index_write_options[] = {
@@ -183,7 +184,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
} }
static int cmd_multi_pack_index_verify(int argc, const char **argv, static int cmd_multi_pack_index_verify(int argc, const char **argv,
const char *prefix) const char *prefix,
struct repository *repo UNUSED)
{ {
struct option *options; struct option *options;
static struct option builtin_multi_pack_index_verify_options[] = { static struct option builtin_multi_pack_index_verify_options[] = {
@@ -210,7 +212,8 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
} }
static int cmd_multi_pack_index_expire(int argc, const char **argv, static int cmd_multi_pack_index_expire(int argc, const char **argv,
const char *prefix) const char *prefix,
struct repository *repo UNUSED)
{ {
struct option *options; struct option *options;
static struct option builtin_multi_pack_index_expire_options[] = { static struct option builtin_multi_pack_index_expire_options[] = {
@@ -237,7 +240,8 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
} }
static int cmd_multi_pack_index_repack(int argc, const char **argv, static int cmd_multi_pack_index_repack(int argc, const char **argv,
const char *prefix) const char *prefix,
struct repository *repo UNUSED)
{ {
struct option *options; struct option *options;
static struct option builtin_multi_pack_index_repack_options[] = { static struct option builtin_multi_pack_index_repack_options[] = {
@@ -271,7 +275,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
int cmd_multi_pack_index(int argc, int cmd_multi_pack_index(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
int res; int res;
parse_opt_subcommand_fn *fn = NULL; parse_opt_subcommand_fn *fn = NULL;
@@ -297,7 +301,7 @@ int cmd_multi_pack_index(int argc,
builtin_multi_pack_index_usage, 0); builtin_multi_pack_index_usage, 0);
FREE_AND_NULL(options); FREE_AND_NULL(options);
res = fn(argc, argv, prefix); res = fn(argc, argv, prefix, repo);
free(opts.object_dir); free(opts.object_dir);
return res; return res;

View File

@@ -431,7 +431,8 @@ static struct notes_tree *init_notes_check(const char *subcommand,
return t; return t;
} }
static int list(int argc, const char **argv, const char *prefix) static int list(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct notes_tree *t; struct notes_tree *t;
struct object_id object; struct object_id object;
@@ -468,9 +469,11 @@ static int list(int argc, const char **argv, const char *prefix)
return retval; return retval;
} }
static int append_edit(int argc, const char **argv, const char *prefix); static int append_edit(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED);
static int add(int argc, const char **argv, const char *prefix) static int add(int argc, const char **argv, const char *prefix,
struct repository *repo)
{ {
int force = 0, allow_empty = 0; int force = 0, allow_empty = 0;
const char *object_ref; const char *object_ref;
@@ -543,7 +546,7 @@ static int add(int argc, const char **argv, const char *prefix)
* argv[0-1]. * argv[0-1].
*/ */
argv[0] = "edit"; argv[0] = "edit";
return append_edit(argc, argv, prefix); return append_edit(argc, argv, prefix, repo);
} }
fprintf(stderr, _("Overwriting existing notes for object %s\n"), fprintf(stderr, _("Overwriting existing notes for object %s\n"),
oid_to_hex(&object)); oid_to_hex(&object));
@@ -569,7 +572,8 @@ static int add(int argc, const char **argv, const char *prefix)
return 0; return 0;
} }
static int copy(int argc, const char **argv, const char *prefix) static int copy(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int retval = 0, force = 0, from_stdin = 0; int retval = 0, force = 0, from_stdin = 0;
const struct object_id *from_note, *note; const struct object_id *from_note, *note;
@@ -646,7 +650,8 @@ out:
return retval; return retval;
} }
static int append_edit(int argc, const char **argv, const char *prefix) static int append_edit(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int allow_empty = 0; int allow_empty = 0;
const char *object_ref; const char *object_ref;
@@ -749,7 +754,8 @@ static int append_edit(int argc, const char **argv, const char *prefix)
return 0; return 0;
} }
static int show(int argc, const char **argv, const char *prefix) static int show(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
const char *object_ref; const char *object_ref;
struct notes_tree *t; struct notes_tree *t;
@@ -875,7 +881,8 @@ static int git_config_get_notes_strategy(const char *key,
return 0; return 0;
} }
static int merge(int argc, const char **argv, const char *prefix) static int merge(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT; struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
struct object_id result_oid; struct object_id result_oid;
@@ -1016,7 +1023,8 @@ static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag
return (flag & IGNORE_MISSING) ? 0 : status; return (flag & IGNORE_MISSING) ? 0 : status;
} }
static int remove_cmd(int argc, const char **argv, const char *prefix) static int remove_cmd(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
unsigned flag = 0; unsigned flag = 0;
int from_stdin = 0; int from_stdin = 0;
@@ -1059,7 +1067,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
return retval; return retval;
} }
static int prune(int argc, const char **argv, const char *prefix) static int prune(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct notes_tree *t; struct notes_tree *t;
int show_only = 0, verbose = 0; int show_only = 0, verbose = 0;
@@ -1088,7 +1097,8 @@ static int prune(int argc, const char **argv, const char *prefix)
return 0; return 0;
} }
static int get_ref(int argc, const char **argv, const char *prefix) static int get_ref(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct option options[] = { OPT_END() }; struct option options[] = { OPT_END() };
char *notes_ref; char *notes_ref;
@@ -1109,7 +1119,7 @@ static int get_ref(int argc, const char **argv, const char *prefix)
int cmd_notes(int argc, int cmd_notes(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
const char *override_notes_ref = NULL; const char *override_notes_ref = NULL;
parse_opt_subcommand_fn *fn = NULL; parse_opt_subcommand_fn *fn = NULL;
@@ -1148,5 +1158,5 @@ int cmd_notes(int argc,
strbuf_release(&sb); strbuf_release(&sb);
} }
return !!fn(argc, argv, prefix); return !!fn(argc, argv, prefix, repo);
} }

View File

@@ -1101,78 +1101,64 @@ static void write_reused_pack_one(struct packed_git *reuse_packfile,
static size_t write_reused_pack_verbatim(struct bitmapped_pack *reuse_packfile, static size_t write_reused_pack_verbatim(struct bitmapped_pack *reuse_packfile,
struct hashfile *out, struct hashfile *out,
off_t pack_start,
struct pack_window **w_curs) struct pack_window **w_curs)
{ {
size_t pos = reuse_packfile->bitmap_pos; size_t pos = 0;
size_t end; size_t end;
if (pos % BITS_IN_EWORD) { if (reuse_packfile->bitmap_pos) {
size_t word_pos = (pos / BITS_IN_EWORD); /*
size_t offset = pos % BITS_IN_EWORD; * We can't reuse whole chunks verbatim out of
size_t last; * non-preferred packs since we can't guarantee that
eword_t word = reuse_packfile_bitmap->words[word_pos]; * all duplicate objects were resolved in favor of
* that pack.
if (offset + reuse_packfile->bitmap_nr < BITS_IN_EWORD) *
last = offset + reuse_packfile->bitmap_nr; * Even if we have a whole eword_t worth of bits that
else * could be reused, there may be objects between the
last = BITS_IN_EWORD; * objects corresponding to the first and last bit of
* that word which were selected from a different
for (; offset < last; offset++) { * pack, causing us to send duplicate or unwanted
if (word >> offset == 0) * objects.
return word_pos; *
if (!bitmap_get(reuse_packfile_bitmap, * Handle non-preferred packs from within
word_pos * BITS_IN_EWORD + offset)) * write_reused_pack(), which inspects and reuses
return word_pos; * individual bits.
} */
return reuse_packfile->bitmap_pos / BITS_IN_EWORD;
pos += BITS_IN_EWORD - (pos % BITS_IN_EWORD);
} }
/* /*
* Now we're going to copy as many whole eword_t's as possible. * Only read through the last word whose bits all correspond
* "end" is the index of the last whole eword_t we copy, but * to objects in the given packfile, since we must stop at a
* there may be additional bits to process. Those are handled * word boundary.
* individually by write_reused_pack().
* *
* Begin by advancing to the first word boundary in range of the * If there is no whole word to read (i.e. the packfile
* bit positions occupied by objects in "reuse_packfile". Then * contains fewer than BITS_IN_EWORD objects), then we'll
* pick the last word boundary in the same range. If we have at * inspect bits one-by-one in write_reused_pack().
* least one word's worth of bits to process, continue on.
*/ */
end = reuse_packfile->bitmap_pos + reuse_packfile->bitmap_nr; end = reuse_packfile->bitmap_nr / BITS_IN_EWORD;
if (end % BITS_IN_EWORD) if (reuse_packfile_bitmap->word_alloc < end)
end -= end % BITS_IN_EWORD; BUG("fewer words than expected in reuse_packfile_bitmap");
if (pos >= end)
return reuse_packfile->bitmap_pos / BITS_IN_EWORD;
while (pos < end && while (pos < end && reuse_packfile_bitmap->words[pos] == (eword_t)~0)
reuse_packfile_bitmap->words[pos / BITS_IN_EWORD] == (eword_t)~0) pos++;
pos += BITS_IN_EWORD;
if (pos > end) if (pos) {
pos = end; off_t to_write;
if (reuse_packfile->bitmap_pos < pos) { written = (pos * BITS_IN_EWORD);
off_t pack_start_off = pack_pos_to_offset(reuse_packfile->p, 0); to_write = pack_pos_to_offset(reuse_packfile->p, written)
off_t pack_end_off = pack_pos_to_offset(reuse_packfile->p, - sizeof(struct pack_header);
pos - reuse_packfile->bitmap_pos);
written += pos - reuse_packfile->bitmap_pos;
/* We're recording one chunk, not one object. */ /* We're recording one chunk, not one object. */
record_reused_object(pack_start_off, record_reused_object(sizeof(struct pack_header), 0);
pack_start_off - (hashfile_total(out) - pack_start));
hashflush(out); hashflush(out);
copy_pack_data(out, reuse_packfile->p, w_curs, copy_pack_data(out, reuse_packfile->p, w_curs,
pack_start_off, pack_end_off - pack_start_off); sizeof(struct pack_header), to_write);
display_progress(progress_state, written); display_progress(progress_state, written);
} }
if (pos % BITS_IN_EWORD) return pos;
BUG("attempted to jump past a word boundary to %"PRIuMAX,
(uintmax_t)pos);
return pos / BITS_IN_EWORD;
} }
static void write_reused_pack(struct bitmapped_pack *reuse_packfile, static void write_reused_pack(struct bitmapped_pack *reuse_packfile,
@@ -1184,8 +1170,7 @@ static void write_reused_pack(struct bitmapped_pack *reuse_packfile,
struct pack_window *w_curs = NULL; struct pack_window *w_curs = NULL;
if (allow_ofs_delta) if (allow_ofs_delta)
i = write_reused_pack_verbatim(reuse_packfile, f, pack_start, i = write_reused_pack_verbatim(reuse_packfile, f, &w_curs);
&w_curs);
for (; i < reuse_packfile_bitmap->word_alloc; ++i) { for (; i < reuse_packfile_bitmap->word_alloc; ++i) {
eword_t word = reuse_packfile_bitmap->words[i]; eword_t word = reuse_packfile_bitmap->words[i];

View File

@@ -234,7 +234,8 @@ static int expire_total_callback(const struct option *opt,
return 0; return 0;
} }
static int cmd_reflog_show(int argc, const char **argv, const char *prefix) static int cmd_reflog_show(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct option options[] = { struct option options[] = {
OPT_END() OPT_END()
@@ -253,7 +254,8 @@ static int show_reflog(const char *refname, void *cb_data UNUSED)
return 0; return 0;
} }
static int cmd_reflog_list(int argc, const char **argv, const char *prefix) static int cmd_reflog_list(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct option options[] = { struct option options[] = {
OPT_END() OPT_END()
@@ -270,7 +272,8 @@ static int cmd_reflog_list(int argc, const char **argv, const char *prefix)
return refs_for_each_reflog(ref_store, show_reflog, NULL); return refs_for_each_reflog(ref_store, show_reflog, NULL);
} }
static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct cmd_reflog_expire_cb cmd = { 0 }; struct cmd_reflog_expire_cb cmd = { 0 };
timestamp_t now = time(NULL); timestamp_t now = time(NULL);
@@ -394,7 +397,8 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
return status; return status;
} }
static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) static int cmd_reflog_delete(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int i, status = 0; int i, status = 0;
unsigned int flags = 0; unsigned int flags = 0;
@@ -424,7 +428,8 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
return status; return status;
} }
static int cmd_reflog_exists(int argc, const char **argv, const char *prefix) static int cmd_reflog_exists(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct option options[] = { struct option options[] = {
OPT_END() OPT_END()
@@ -467,7 +472,7 @@ int cmd_reflog(int argc,
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 |
PARSE_OPT_KEEP_UNKNOWN_OPT); PARSE_OPT_KEEP_UNKNOWN_OPT);
if (fn) if (fn)
return fn(argc - 1, argv + 1, prefix); return fn(argc - 1, argv + 1, prefix, repository);
else else
return cmd_log_reflog(argc, argv, prefix, repository); return cmd_log_reflog(argc, argv, prefix, repository);
} }

View File

@@ -12,7 +12,8 @@
#define REFS_VERIFY_USAGE \ #define REFS_VERIFY_USAGE \
N_("git refs verify [--strict] [--verbose]") N_("git refs verify [--strict] [--verbose]")
static int cmd_refs_migrate(int argc, const char **argv, const char *prefix) static int cmd_refs_migrate(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
const char * const migrate_usage[] = { const char * const migrate_usage[] = {
REFS_MIGRATE_USAGE, REFS_MIGRATE_USAGE,
@@ -63,7 +64,8 @@ out:
return err; return err;
} }
static int cmd_refs_verify(int argc, const char **argv, const char *prefix) static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct fsck_options fsck_refs_options = FSCK_REFS_OPTIONS_DEFAULT; struct fsck_options fsck_refs_options = FSCK_REFS_OPTIONS_DEFAULT;
const char * const verify_usage[] = { const char * const verify_usage[] = {
@@ -93,7 +95,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix)
int cmd_refs(int argc, int cmd_refs(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
const char * const refs_usage[] = { const char * const refs_usage[] = {
REFS_MIGRATE_USAGE, REFS_MIGRATE_USAGE,
@@ -108,5 +110,5 @@ int cmd_refs(int argc,
}; };
argc = parse_options(argc, argv, prefix, opts, refs_usage, 0); argc = parse_options(argc, argv, prefix, opts, refs_usage, 0);
return fn(argc, argv, prefix); return fn(argc, argv, prefix, repo);
} }

View File

@@ -155,7 +155,8 @@ static int parse_mirror_opt(const struct option *opt, const char *arg, int not)
return 0; return 0;
} }
static int add(int argc, const char **argv, const char *prefix) static int add(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int fetch = 0, fetch_tags = TAGS_DEFAULT; int fetch = 0, fetch_tags = TAGS_DEFAULT;
unsigned mirror = MIRROR_NONE; unsigned mirror = MIRROR_NONE;
@@ -377,7 +378,7 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
for (i = 0; i < states->remote->fetch.nr; i++) for (i = 0; i < states->remote->fetch.nr; i++)
if (get_fetch_map(remote_refs, &states->remote->fetch.items[i], &tail, 1)) if (get_fetch_map(remote_refs, &states->remote->fetch.items[i], &tail, 1))
die(_("Could not get fetch map for refspec %s"), die(_("Could not get fetch map for refspec %s"),
states->remote->fetch.raw[i]); states->remote->fetch.items[i].raw);
for (ref = fetch_map; ref; ref = ref->next) { for (ref = fetch_map; ref; ref = ref->next) {
if (omit_name_by_refspec(ref->name, &states->remote->fetch)) if (omit_name_by_refspec(ref->name, &states->remote->fetch))
@@ -633,12 +634,12 @@ static int migrate_file(struct remote *remote)
git_config_set_multivar(buf.buf, remote->url.v[i], "^$", 0); git_config_set_multivar(buf.buf, remote->url.v[i], "^$", 0);
strbuf_reset(&buf); strbuf_reset(&buf);
strbuf_addf(&buf, "remote.%s.push", remote->name); strbuf_addf(&buf, "remote.%s.push", remote->name);
for (i = 0; i < remote->push.raw_nr; i++) for (i = 0; i < remote->push.nr; i++)
git_config_set_multivar(buf.buf, remote->push.raw[i], "^$", 0); git_config_set_multivar(buf.buf, remote->push.items[i].raw, "^$", 0);
strbuf_reset(&buf); strbuf_reset(&buf);
strbuf_addf(&buf, "remote.%s.fetch", remote->name); strbuf_addf(&buf, "remote.%s.fetch", remote->name);
for (i = 0; i < remote->fetch.raw_nr; i++) for (i = 0; i < remote->fetch.nr; i++)
git_config_set_multivar(buf.buf, remote->fetch.raw[i], "^$", 0); git_config_set_multivar(buf.buf, remote->fetch.items[i].raw, "^$", 0);
if (remote->origin == REMOTE_REMOTES) if (remote->origin == REMOTE_REMOTES)
unlink_or_warn(git_path("remotes/%s", remote->name)); unlink_or_warn(git_path("remotes/%s", remote->name));
else if (remote->origin == REMOTE_BRANCHES) else if (remote->origin == REMOTE_BRANCHES)
@@ -706,7 +707,8 @@ static void handle_push_default(const char* old_name, const char* new_name)
} }
static int mv(int argc, const char **argv, const char *prefix) static int mv(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int show_progress = isatty(2); int show_progress = isatty(2);
struct option options[] = { struct option options[] = {
@@ -759,16 +761,16 @@ static int mv(int argc, const char **argv, const char *prefix)
goto out; goto out;
} }
if (oldremote->fetch.raw_nr) { if (oldremote->fetch.nr) {
strbuf_reset(&buf); strbuf_reset(&buf);
strbuf_addf(&buf, "remote.%s.fetch", rename.new_name); strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE); git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE);
strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name); strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
for (i = 0; i < oldremote->fetch.raw_nr; i++) { for (i = 0; i < oldremote->fetch.nr; i++) {
char *ptr; char *ptr;
strbuf_reset(&buf2); strbuf_reset(&buf2);
strbuf_addstr(&buf2, oldremote->fetch.raw[i]); strbuf_addstr(&buf2, oldremote->fetch.items[i].raw);
ptr = strstr(buf2.buf, old_remote_context.buf); ptr = strstr(buf2.buf, old_remote_context.buf);
if (ptr) { if (ptr) {
refspec_updated = 1; refspec_updated = 1;
@@ -881,7 +883,8 @@ out:
return result; return result;
} }
static int rm(int argc, const char **argv, const char *prefix) static int rm(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct option options[] = { struct option options[] = {
OPT_END() OPT_END()
@@ -1303,7 +1306,8 @@ static int show_all(void)
return result; return result;
} }
static int show(int argc, const char **argv, const char *prefix) static int show(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int no_query = 0, result = 0, query_flag = 0; int no_query = 0, result = 0, query_flag = 0;
struct option options[] = { struct option options[] = {
@@ -1399,7 +1403,8 @@ static int show(int argc, const char **argv, const char *prefix)
return result; return result;
} }
static int set_head(int argc, const char **argv, const char *prefix) static int set_head(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int i, opt_a = 0, opt_d = 0, result = 0; int i, opt_a = 0, opt_d = 0, result = 0;
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
@@ -1503,7 +1508,8 @@ static int prune_remote(const char *remote, int dry_run)
return result; return result;
} }
static int prune(int argc, const char **argv, const char *prefix) static int prune(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int dry_run = 0, result = 0; int dry_run = 0, result = 0;
struct option options[] = { struct option options[] = {
@@ -1534,7 +1540,8 @@ static int get_remote_default(const char *key, const char *value UNUSED,
return 0; return 0;
} }
static int update(int argc, const char **argv, const char *prefix) static int update(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int i, prune = -1; int i, prune = -1;
struct option options[] = { struct option options[] = {
@@ -1616,7 +1623,8 @@ static int set_remote_branches(const char *remotename, const char **branches,
return 0; return 0;
} }
static int set_branches(int argc, const char **argv, const char *prefix) static int set_branches(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int add_mode = 0; int add_mode = 0;
struct option options[] = { struct option options[] = {
@@ -1635,7 +1643,8 @@ static int set_branches(int argc, const char **argv, const char *prefix)
return set_remote_branches(argv[0], argv + 1, add_mode); return set_remote_branches(argv[0], argv + 1, add_mode);
} }
static int get_url(int argc, const char **argv, const char *prefix) static int get_url(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int i, push_mode = 0, all_mode = 0; int i, push_mode = 0, all_mode = 0;
const char *remotename = NULL; const char *remotename = NULL;
@@ -1674,7 +1683,8 @@ static int get_url(int argc, const char **argv, const char *prefix)
return 0; return 0;
} }
static int set_url(int argc, const char **argv, const char *prefix) static int set_url(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int i, push_mode = 0, add_mode = 0, delete_mode = 0; int i, push_mode = 0, add_mode = 0, delete_mode = 0;
int matches = 0, negative_matches = 0; int matches = 0, negative_matches = 0;
@@ -1765,7 +1775,7 @@ out:
int cmd_remote(int argc, int cmd_remote(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
parse_opt_subcommand_fn *fn = NULL; parse_opt_subcommand_fn *fn = NULL;
struct option options[] = { struct option options[] = {
@@ -1788,7 +1798,7 @@ int cmd_remote(int argc,
PARSE_OPT_SUBCOMMAND_OPTIONAL); PARSE_OPT_SUBCOMMAND_OPTIONAL);
if (fn) { if (fn) {
return !!fn(argc, argv, prefix); return !!fn(argc, argv, prefix, repo);
} else { } else {
if (argc) { if (argc) {
error(_("unknown subcommand: `%s'"), argv[0]); error(_("unknown subcommand: `%s'"), argv[0]);

View File

@@ -48,7 +48,8 @@ static char const * const builtin_sparse_checkout_list_usage[] = {
NULL NULL
}; };
static int sparse_checkout_list(int argc, const char **argv, const char *prefix) static int sparse_checkout_list(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
static struct option builtin_sparse_checkout_list_options[] = { static struct option builtin_sparse_checkout_list_options[] = {
OPT_END(), OPT_END(),
@@ -443,7 +444,8 @@ static struct sparse_checkout_init_opts {
int sparse_index; int sparse_index;
} init_opts; } init_opts;
static int sparse_checkout_init(int argc, const char **argv, const char *prefix) static int sparse_checkout_init(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct pattern_list pl; struct pattern_list pl;
char *sparse_filename; char *sparse_filename;
@@ -770,7 +772,8 @@ static struct sparse_checkout_add_opts {
int use_stdin; int use_stdin;
} add_opts; } add_opts;
static int sparse_checkout_add(int argc, const char **argv, const char *prefix) static int sparse_checkout_add(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
static struct option builtin_sparse_checkout_add_options[] = { static struct option builtin_sparse_checkout_add_options[] = {
OPT_BOOL_F(0, "skip-checks", &add_opts.skip_checks, OPT_BOOL_F(0, "skip-checks", &add_opts.skip_checks,
@@ -808,7 +811,8 @@ static struct sparse_checkout_set_opts {
int use_stdin; int use_stdin;
} set_opts; } set_opts;
static int sparse_checkout_set(int argc, const char **argv, const char *prefix) static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int default_patterns_nr = 2; int default_patterns_nr = 2;
const char *default_patterns[] = {"/*", "!/*/", NULL}; const char *default_patterns[] = {"/*", "!/*/", NULL};
@@ -866,7 +870,8 @@ static struct sparse_checkout_reapply_opts {
} reapply_opts; } reapply_opts;
static int sparse_checkout_reapply(int argc, const char **argv, static int sparse_checkout_reapply(int argc, const char **argv,
const char *prefix) const char *prefix,
struct repository *repo UNUSED)
{ {
static struct option builtin_sparse_checkout_reapply_options[] = { static struct option builtin_sparse_checkout_reapply_options[] = {
OPT_BOOL(0, "cone", &reapply_opts.cone_mode, OPT_BOOL(0, "cone", &reapply_opts.cone_mode,
@@ -901,7 +906,8 @@ static char const * const builtin_sparse_checkout_disable_usage[] = {
}; };
static int sparse_checkout_disable(int argc, const char **argv, static int sparse_checkout_disable(int argc, const char **argv,
const char *prefix) const char *prefix,
struct repository *repo UNUSED)
{ {
static struct option builtin_sparse_checkout_disable_options[] = { static struct option builtin_sparse_checkout_disable_options[] = {
OPT_END(), OPT_END(),
@@ -989,7 +995,8 @@ static int check_rules(struct pattern_list *pl, int null_terminated) {
return 0; return 0;
} }
static int sparse_checkout_check_rules(int argc, const char **argv, const char *prefix) static int sparse_checkout_check_rules(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
static struct option builtin_sparse_checkout_check_rules_options[] = { static struct option builtin_sparse_checkout_check_rules_options[] = {
OPT_BOOL('z', NULL, &check_rules_opts.null_termination, OPT_BOOL('z', NULL, &check_rules_opts.null_termination,
@@ -1037,7 +1044,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char *
int cmd_sparse_checkout(int argc, int cmd_sparse_checkout(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
parse_opt_subcommand_fn *fn = NULL; parse_opt_subcommand_fn *fn = NULL;
struct option builtin_sparse_checkout_options[] = { struct option builtin_sparse_checkout_options[] = {
@@ -1060,5 +1067,5 @@ int cmd_sparse_checkout(int argc,
prepare_repo_settings(the_repository); prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0; the_repository->settings.command_requires_full_index = 0;
return fn(argc, argv, prefix); return fn(argc, argv, prefix, repo);
} }

View File

@@ -249,7 +249,8 @@ static int do_clear_stash(void)
ref_stash, &obj, 0); ref_stash, &obj, 0);
} }
static int clear_stash(int argc, const char **argv, const char *prefix) static int clear_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct option options[] = { struct option options[] = {
OPT_END() OPT_END()
@@ -652,7 +653,8 @@ restore_untracked:
return ret; return ret;
} }
static int apply_stash(int argc, const char **argv, const char *prefix) static int apply_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int ret = -1; int ret = -1;
int quiet = 0; int quiet = 0;
@@ -726,7 +728,8 @@ static int get_stash_info_assert(struct stash_info *info, int argc,
return 0; return 0;
} }
static int drop_stash(int argc, const char **argv, const char *prefix) static int drop_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int ret = -1; int ret = -1;
int quiet = 0; int quiet = 0;
@@ -748,7 +751,8 @@ cleanup:
return ret; return ret;
} }
static int pop_stash(int argc, const char **argv, const char *prefix) static int pop_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int ret = -1; int ret = -1;
int index = 0; int index = 0;
@@ -778,7 +782,8 @@ cleanup:
return ret; return ret;
} }
static int branch_stash(int argc, const char **argv, const char *prefix) static int branch_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int ret = -1; int ret = -1;
const char *branch = NULL; const char *branch = NULL;
@@ -816,7 +821,8 @@ cleanup:
return ret; return ret;
} }
static int list_stash(int argc, const char **argv, const char *prefix) static int list_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
struct option options[] = { struct option options[] = {
@@ -889,7 +895,8 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op
do_diff_cache(&info->b_commit, diff_opt); do_diff_cache(&info->b_commit, diff_opt);
} }
static int show_stash(int argc, const char **argv, const char *prefix) static int show_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int i; int i;
int ret = -1; int ret = -1;
@@ -1017,7 +1024,8 @@ static int do_store_stash(const struct object_id *w_commit, const char *stash_ms
return 0; return 0;
} }
static int store_stash(int argc, const char **argv, const char *prefix) static int store_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int quiet = 0; int quiet = 0;
const char *stash_msg = NULL; const char *stash_msg = NULL;
@@ -1491,7 +1499,8 @@ done:
return ret; return ret;
} }
static int create_stash(int argc, const char **argv, const char *prefix UNUSED) static int create_stash(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
int ret; int ret;
struct strbuf stash_msg_buf = STRBUF_INIT; struct strbuf stash_msg_buf = STRBUF_INIT;
@@ -1827,12 +1836,14 @@ static int push_stash(int argc, const char **argv, const char *prefix,
return ret; return ret;
} }
static int push_stash_unassumed(int argc, const char **argv, const char *prefix) static int push_stash_unassumed(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
return push_stash(argc, argv, prefix, 0); return push_stash(argc, argv, prefix, 0);
} }
static int save_stash(int argc, const char **argv, const char *prefix) static int save_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int keep_index = -1; int keep_index = -1;
int only_staged = 0; int only_staged = 0;
@@ -1878,7 +1889,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)
int cmd_stash(int argc, int cmd_stash(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
pid_t pid = getpid(); pid_t pid = getpid();
const char *index_file; const char *index_file;
@@ -1916,9 +1927,9 @@ int cmd_stash(int argc,
(uintmax_t)pid); (uintmax_t)pid);
if (fn) if (fn)
return !!fn(argc, argv, prefix); return !!fn(argc, argv, prefix, repo);
else if (!argc) else if (!argc)
return !!push_stash_unassumed(0, NULL, prefix); return !!push_stash_unassumed(0, NULL, prefix, repo);
/* Assume 'stash push' */ /* Assume 'stash push' */
strvec_push(&args, "push"); strvec_push(&args, "push");

View File

@@ -399,7 +399,8 @@ cleanup:
free(displaypath); free(displaypath);
} }
static int module_foreach(int argc, const char **argv, const char *prefix) static int module_foreach(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct foreach_cb info = FOREACH_CB_INIT; struct foreach_cb info = FOREACH_CB_INIT;
struct pathspec pathspec = { 0 }; struct pathspec pathspec = { 0 };
@@ -544,7 +545,8 @@ static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data
info->flags); info->flags);
} }
static int module_init(int argc, const char **argv, const char *prefix) static int module_init(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct init_cb info = INIT_CB_INIT; struct init_cb info = INIT_CB_INIT;
struct pathspec pathspec = { 0 }; struct pathspec pathspec = { 0 };
@@ -738,7 +740,8 @@ static void status_submodule_cb(const struct cache_entry *list_item,
info->prefix, info->super_prefix, info->flags); info->prefix, info->super_prefix, info->flags);
} }
static int module_status(int argc, const char **argv, const char *prefix) static int module_status(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct status_cb info = STATUS_CB_INIT; struct status_cb info = STATUS_CB_INIT;
struct pathspec pathspec = { 0 }; struct pathspec pathspec = { 0 };
@@ -1163,7 +1166,8 @@ cleanup:
return ret; return ret;
} }
static int module_summary(int argc, const char **argv, const char *prefix) static int module_summary(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct summary_cb info = SUMMARY_CB_INIT; struct summary_cb info = SUMMARY_CB_INIT;
int cached = 0; int cached = 0;
@@ -1339,7 +1343,8 @@ static void sync_submodule_cb(const struct cache_entry *list_item, void *cb_data
info->flags); info->flags);
} }
static int module_sync(int argc, const char **argv, const char *prefix) static int module_sync(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct sync_cb info = SYNC_CB_INIT; struct sync_cb info = SYNC_CB_INIT;
struct pathspec pathspec = { 0 }; struct pathspec pathspec = { 0 };
@@ -1485,7 +1490,8 @@ static void deinit_submodule_cb(const struct cache_entry *list_item,
deinit_submodule(list_item->name, info->prefix, info->flags); deinit_submodule(list_item->name, info->prefix, info->flags);
} }
static int module_deinit(int argc, const char **argv, const char *prefix) static int module_deinit(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct deinit_cb info = DEINIT_CB_INIT; struct deinit_cb info = DEINIT_CB_INIT;
struct pathspec pathspec = { 0 }; struct pathspec pathspec = { 0 };
@@ -1842,7 +1848,8 @@ static int clone_submodule(const struct module_clone_data *clone_data,
return 0; return 0;
} }
static int module_clone(int argc, const char **argv, const char *prefix) static int module_clone(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int dissociate = 0, quiet = 0, progress = 0, require_init = 0; int dissociate = 0, quiet = 0, progress = 0, require_init = 0;
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT; struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
@@ -2779,7 +2786,8 @@ cleanup:
return ret; return ret;
} }
static int module_update(int argc, const char **argv, const char *prefix) static int module_update(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
struct pathspec pathspec = { 0 }; struct pathspec pathspec = { 0 };
struct pathspec pathspec2 = { 0 }; struct pathspec pathspec2 = { 0 };
@@ -2911,7 +2919,8 @@ cleanup:
return ret; return ret;
} }
static int push_check(int argc, const char **argv, const char *prefix UNUSED) static int push_check(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
struct remote *remote; struct remote *remote;
const char *superproject_head; const char *superproject_head;
@@ -2991,7 +3000,8 @@ static int push_check(int argc, const char **argv, const char *prefix UNUSED)
return 0; return 0;
} }
static int absorb_git_dirs(int argc, const char **argv, const char *prefix) static int absorb_git_dirs(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int i; int i;
struct pathspec pathspec = { 0 }; struct pathspec pathspec = { 0 };
@@ -3024,7 +3034,8 @@ cleanup:
return ret; return ret;
} }
static int module_set_url(int argc, const char **argv, const char *prefix) static int module_set_url(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int quiet = 0, ret; int quiet = 0, ret;
const char *newurl; const char *newurl;
@@ -3063,7 +3074,8 @@ static int module_set_url(int argc, const char **argv, const char *prefix)
return !!ret; return !!ret;
} }
static int module_set_branch(int argc, const char **argv, const char *prefix) static int module_set_branch(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int opt_default = 0, ret; int opt_default = 0, ret;
const char *opt_branch = NULL; const char *opt_branch = NULL;
@@ -3113,7 +3125,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix)
return !!ret; return !!ret;
} }
static int module_create_branch(int argc, const char **argv, const char *prefix) static int module_create_branch(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
enum branch_track track; enum branch_track track;
int quiet = 0, force = 0, reflog = 0, dry_run = 0; int quiet = 0, force = 0, reflog = 0, dry_run = 0;
@@ -3424,7 +3437,8 @@ static void die_on_repo_without_commits(const char *path)
strbuf_release(&sb); strbuf_release(&sb);
} }
static int module_add(int argc, const char **argv, const char *prefix) static int module_add(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{ {
int force = 0, quiet = 0, progress = 0, dissociate = 0; int force = 0, quiet = 0, progress = 0, dissociate = 0;
struct add_data add_data = ADD_DATA_INIT; struct add_data add_data = ADD_DATA_INIT;
@@ -3557,7 +3571,7 @@ cleanup:
int cmd_submodule__helper(int argc, int cmd_submodule__helper(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
parse_opt_subcommand_fn *fn = NULL; parse_opt_subcommand_fn *fn = NULL;
const char *const usage[] = { const char *const usage[] = {
@@ -3583,5 +3597,5 @@ int cmd_submodule__helper(int argc,
}; };
argc = parse_options(argc, argv, prefix, options, usage, 0); argc = parse_options(argc, argv, prefix, options, usage, 0);
return fn(argc, argv, prefix); return fn(argc, argv, prefix, repo);
} }

View File

@@ -231,7 +231,8 @@ static void prune_worktrees(void)
strbuf_release(&reason); strbuf_release(&reason);
} }
static int prune(int ac, const char **av, const char *prefix) static int prune(int ac, const char **av, const char *prefix,
struct repository *repo UNUSED)
{ {
struct option options[] = { struct option options[] = {
OPT__DRY_RUN(&show_only, N_("do not remove, show only")), OPT__DRY_RUN(&show_only, N_("do not remove, show only")),
@@ -763,7 +764,8 @@ static char *dwim_branch(const char *path, char **new_branch)
return NULL; return NULL;
} }
static int add(int ac, const char **av, const char *prefix) static int add(int ac, const char **av, const char *prefix,
struct repository *repo UNUSED)
{ {
struct add_opts opts; struct add_opts opts;
const char *new_branch_force = NULL; const char *new_branch_force = NULL;
@@ -1039,7 +1041,8 @@ static void pathsort(struct worktree **wt)
QSORT(wt, n, pathcmp); QSORT(wt, n, pathcmp);
} }
static int list(int ac, const char **av, const char *prefix) static int list(int ac, const char **av, const char *prefix,
struct repository *repo UNUSED)
{ {
int porcelain = 0; int porcelain = 0;
int line_terminator = '\n'; int line_terminator = '\n';
@@ -1084,7 +1087,8 @@ static int list(int ac, const char **av, const char *prefix)
return 0; return 0;
} }
static int lock_worktree(int ac, const char **av, const char *prefix) static int lock_worktree(int ac, const char **av, const char *prefix,
struct repository *repo UNUSED)
{ {
const char *reason = "", *old_reason; const char *reason = "", *old_reason;
struct option options[] = { struct option options[] = {
@@ -1119,7 +1123,8 @@ static int lock_worktree(int ac, const char **av, const char *prefix)
return 0; return 0;
} }
static int unlock_worktree(int ac, const char **av, const char *prefix) static int unlock_worktree(int ac, const char **av, const char *prefix,
struct repository *repo UNUSED)
{ {
struct option options[] = { struct option options[] = {
OPT_END() OPT_END()
@@ -1182,7 +1187,8 @@ static void validate_no_submodules(const struct worktree *wt)
die(_("working trees containing submodules cannot be moved or removed")); die(_("working trees containing submodules cannot be moved or removed"));
} }
static int move_worktree(int ac, const char **av, const char *prefix) static int move_worktree(int ac, const char **av, const char *prefix,
struct repository *repo UNUSED)
{ {
int force = 0; int force = 0;
struct option options[] = { struct option options[] = {
@@ -1312,7 +1318,8 @@ static int delete_git_work_tree(struct worktree *wt)
return ret; return ret;
} }
static int remove_worktree(int ac, const char **av, const char *prefix) static int remove_worktree(int ac, const char **av, const char *prefix,
struct repository *repo UNUSED)
{ {
int force = 0; int force = 0;
struct option options[] = { struct option options[] = {
@@ -1377,7 +1384,8 @@ static void report_repair(int iserr, const char *path, const char *msg, void *cb
} }
} }
static int repair(int ac, const char **av, const char *prefix) static int repair(int ac, const char **av, const char *prefix,
struct repository *repo UNUSED)
{ {
const char **p; const char **p;
const char *self[] = { ".", NULL }; const char *self[] = { ".", NULL };
@@ -1397,7 +1405,7 @@ static int repair(int ac, const char **av, const char *prefix)
int cmd_worktree(int ac, int cmd_worktree(int ac,
const char **av, const char **av,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
parse_opt_subcommand_fn *fn = NULL; parse_opt_subcommand_fn *fn = NULL;
struct option options[] = { struct option options[] = {
@@ -1422,5 +1430,5 @@ int cmd_worktree(int ac,
prepare_repo_settings(the_repository); prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0; the_repository->settings.command_requires_full_index = 0;
return fn(ac, av, prefix); return fn(ac, av, prefix, repo);
} }

View File

@@ -3,6 +3,8 @@
#include "gettext.h" #include "gettext.h"
struct repository;
/** /**
* Refer to Documentation/technical/api-parse-options.txt for the API doc. * Refer to Documentation/technical/api-parse-options.txt for the API doc.
*/ */
@@ -73,7 +75,7 @@ typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
const char *arg, int unset); const char *arg, int unset);
typedef int parse_opt_subcommand_fn(int argc, const char **argv, typedef int parse_opt_subcommand_fn(int argc, const char **argv,
const char *prefix); const char *prefix, struct repository *repo);
/* /*
* `type`:: * `type`::

View File

@@ -153,6 +153,7 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet
int refspec_item_init(struct refspec_item *item, const char *refspec, int fetch) int refspec_item_init(struct refspec_item *item, const char *refspec, int fetch)
{ {
memset(item, 0, sizeof(*item)); memset(item, 0, sizeof(*item));
item->raw = xstrdup(refspec);
return parse_refspec(item, refspec, fetch); return parse_refspec(item, refspec, fetch);
} }
@@ -167,6 +168,7 @@ void refspec_item_clear(struct refspec_item *item)
{ {
FREE_AND_NULL(item->src); FREE_AND_NULL(item->src);
FREE_AND_NULL(item->dst); FREE_AND_NULL(item->dst);
FREE_AND_NULL(item->raw);
item->force = 0; item->force = 0;
item->pattern = 0; item->pattern = 0;
item->matching = 0; item->matching = 0;
@@ -179,31 +181,29 @@ void refspec_init(struct refspec *rs, int fetch)
rs->fetch = fetch; rs->fetch = fetch;
} }
static void refspec_append_nodup(struct refspec *rs, char *refspec) void refspec_append(struct refspec *rs, const char *refspec)
{ {
struct refspec_item item; struct refspec_item item;
refspec_item_init_or_die(&item, refspec, rs->fetch); refspec_item_init_or_die(&item, refspec, rs->fetch);
ALLOC_GROW(rs->items, rs->nr + 1, rs->alloc); ALLOC_GROW(rs->items, rs->nr + 1, rs->alloc);
rs->items[rs->nr++] = item; rs->items[rs->nr] = item;
ALLOC_GROW(rs->raw, rs->raw_nr + 1, rs->raw_alloc); rs->nr++;
rs->raw[rs->raw_nr++] = refspec;
}
void refspec_append(struct refspec *rs, const char *refspec)
{
refspec_append_nodup(rs, xstrdup(refspec));
} }
void refspec_appendf(struct refspec *rs, const char *fmt, ...) void refspec_appendf(struct refspec *rs, const char *fmt, ...)
{ {
va_list ap; va_list ap;
char *buf;
va_start(ap, fmt); va_start(ap, fmt);
refspec_append_nodup(rs, xstrvfmt(fmt, ap)); buf = xstrvfmt(fmt, ap);
va_end(ap); va_end(ap);
refspec_append(rs, buf);
free(buf);
} }
void refspec_appendn(struct refspec *rs, const char **refspecs, int nr) void refspec_appendn(struct refspec *rs, const char **refspecs, int nr)
@@ -224,12 +224,6 @@ void refspec_clear(struct refspec *rs)
rs->alloc = 0; rs->alloc = 0;
rs->nr = 0; rs->nr = 0;
for (i = 0; i < rs->raw_nr; i++)
free(rs->raw[i]);
FREE_AND_NULL(rs->raw);
rs->raw_alloc = 0;
rs->raw_nr = 0;
rs->fetch = 0; rs->fetch = 0;
} }

View File

@@ -26,6 +26,8 @@ struct refspec_item {
char *src; char *src;
char *dst; char *dst;
char *raw;
}; };
#define REFSPEC_FETCH 1 #define REFSPEC_FETCH 1
@@ -43,10 +45,6 @@ struct refspec {
int alloc; int alloc;
int nr; int nr;
char **raw;
int raw_alloc;
int raw_nr;
int fetch; int fetch;
}; };

View File

@@ -1174,8 +1174,8 @@ static int push_submodule(const char *path,
if (remote->origin != REMOTE_UNCONFIGURED) { if (remote->origin != REMOTE_UNCONFIGURED) {
int i; int i;
strvec_push(&cp.args, remote->name); strvec_push(&cp.args, remote->name);
for (i = 0; i < rs->raw_nr; i++) for (i = 0; i < rs->nr; i++)
strvec_push(&cp.args, rs->raw[i]); strvec_push(&cp.args, rs->items[i].raw);
} }
prepare_submodule_repo_env(&cp.env); prepare_submodule_repo_env(&cp.env);
@@ -1209,8 +1209,8 @@ static void submodule_push_check(const char *path, const char *head,
strvec_push(&cp.args, head); strvec_push(&cp.args, head);
strvec_push(&cp.args, remote->name); strvec_push(&cp.args, remote->name);
for (i = 0; i < rs->raw_nr; i++) for (i = 0; i < rs->nr; i++)
strvec_push(&cp.args, rs->raw[i]); strvec_push(&cp.args, rs->items[i].raw);
prepare_submodule_repo_env(&cp.env); prepare_submodule_repo_env(&cp.env);
cp.git_cmd = 1; cp.git_cmd = 1;

View File

@@ -282,14 +282,16 @@ int cmd__parse_options_flags(int argc, const char **argv)
return parse_options_flags__cmd(argc, argv, test_flags); return parse_options_flags__cmd(argc, argv, test_flags);
} }
static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED) static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
printf("fn: subcmd_one\n"); printf("fn: subcmd_one\n");
print_args(argc, argv); print_args(argc, argv);
return 0; return 0;
} }
static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED) static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{ {
printf("fn: subcmd_two\n"); printf("fn: subcmd_two\n");
print_args(argc, argv); print_args(argc, argv);
@@ -319,7 +321,7 @@ static int parse_subcommand__cmd(int argc, const char **argv,
printf("opt: %d\n", opt); printf("opt: %d\n", opt);
return fn(argc, argv, NULL); return fn(argc, argv, NULL, NULL);
} }
int cmd__parse_subcommand(int argc, const char **argv) int cmd__parse_subcommand(int argc, const char **argv)

View File

@@ -259,4 +259,26 @@ test_expect_success 'duplicate objects' '
) )
' '
test_expect_success 'duplicate objects with verbatim reuse' '
git init duplicate-objects-verbatim &&
(
cd duplicate-objects-verbatim &&
git config pack.allowPackReuse multi &&
test_commit_bulk 64 &&
# take the first object from the main pack...
git show-index <$(ls $packdir/pack-*.idx) >obj.raw &&
sort -nk1 <obj.raw | head -n1 | cut -d" " -f2 >in &&
# ...and create a separate pack containing just that object
p="$(git pack-objects $packdir/pack <in)" &&
git multi-pack-index write --bitmap --preferred-pack=pack-$p.idx &&
test_pack_objects_reused_all 192 2
)
'
test_done test_done

View File

@@ -283,4 +283,8 @@ test_expect_success '--prefetch succeeds when refspec becomes empty' '
git -C one fetch --prefetch git -C one fetch --prefetch
' '
test_expect_success '--prefetch succeeds with empty command line refspec' '
git -C one fetch --prefetch origin +refs/tags/extra
'
test_done test_done

View File

@@ -666,6 +666,10 @@ run_dir_diff_test 'difftool --dir-diff syncs worktree without unstaged change' '
test_cmp expect file test_cmp expect file
' '
run_dir_diff_test 'difftool --dir-diff with no diff' '
git difftool -d main main
'
write_script modify-file <<\EOF write_script modify-file <<\EOF
echo "new content" >file echo "new content" >file
EOF EOF

View File

@@ -577,53 +577,6 @@ case $GIT_TEST_FSYNC in
;; ;;
esac esac
# Add libc MALLOC and MALLOC_PERTURB test only if we are not executing
# the test with valgrind and have not compiled with conflict SANITIZE
# options.
if test -n "$valgrind" ||
test -n "$SANITIZE_ADDRESS" ||
test -n "$SANITIZE_LEAK" ||
test -n "$TEST_NO_MALLOC_CHECK"
then
setup_malloc_check () {
: nothing
}
teardown_malloc_check () {
: nothing
}
else
_USE_GLIBC_TUNABLES=
if _GLIBC_VERSION=$(getconf GNU_LIBC_VERSION 2>/dev/null) &&
_GLIBC_VERSION=${_GLIBC_VERSION#"glibc "} &&
expr 2.34 \<= "$_GLIBC_VERSION" >/dev/null
then
_USE_GLIBC_TUNABLES=YesPlease
fi
setup_malloc_check () {
local g
local t
MALLOC_CHECK_=3 MALLOC_PERTURB_=165
export MALLOC_CHECK_ MALLOC_PERTURB_
if test -n "$_USE_GLIBC_TUNABLES"
then
g=
LD_PRELOAD="libc_malloc_debug.so.0"
for t in \
glibc.malloc.check=1 \
glibc.malloc.perturb=165
do
g="${g#:}:$t"
done
GLIBC_TUNABLES=$g
export LD_PRELOAD GLIBC_TUNABLES
fi
}
teardown_malloc_check () {
unset MALLOC_CHECK_ MALLOC_PERTURB_
unset LD_PRELOAD GLIBC_TUNABLES
}
fi
# Protect ourselves from common misconfiguration to export # Protect ourselves from common misconfiguration to export
# CDPATH into the environment # CDPATH into the environment
unset CDPATH unset CDPATH
@@ -1483,6 +1436,56 @@ GIT_ATTR_NOSYSTEM=1
GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/.." GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/.."
export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES
# Add libc MALLOC and MALLOC_PERTURB test only if we are not executing
# the test with valgrind and have not compiled with conflict SANITIZE
# options.
if test -n "$valgrind" ||
test -n "$SANITIZE_ADDRESS" ||
test -n "$SANITIZE_LEAK" ||
test -n "$TEST_NO_MALLOC_CHECK"
then
setup_malloc_check () {
: nothing
}
teardown_malloc_check () {
: nothing
}
else
_USE_GLIBC_TUNABLES=
_USE_GLIBC_PRELOAD=libc_malloc_debug.so.0
if _GLIBC_VERSION=$(getconf GNU_LIBC_VERSION 2>/dev/null) &&
_GLIBC_VERSION=${_GLIBC_VERSION#"glibc "} &&
expr 2.34 \<= "$_GLIBC_VERSION" >/dev/null &&
stderr=$(LD_PRELOAD=$_USE_GLIBC_PRELOAD git version 2>&1 >/dev/null) &&
test -z "$stderr"
then
_USE_GLIBC_TUNABLES=YesPlease
fi
setup_malloc_check () {
local g
local t
MALLOC_CHECK_=3 MALLOC_PERTURB_=165
export MALLOC_CHECK_ MALLOC_PERTURB_
if test -n "$_USE_GLIBC_TUNABLES"
then
g=
LD_PRELOAD=$_USE_GLIBC_PRELOAD
for t in \
glibc.malloc.check=1 \
glibc.malloc.perturb=165
do
g="${g#:}:$t"
done
GLIBC_TUNABLES=$g
export LD_PRELOAD GLIBC_TUNABLES
fi
}
teardown_malloc_check () {
unset MALLOC_CHECK_ MALLOC_PERTURB_
unset LD_PRELOAD GLIBC_TUNABLES
}
fi
if test -z "$GIT_TEST_CMP" if test -z "$GIT_TEST_CMP"
then then
if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT" if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"