From patchwork Tue Nov 19 15:36:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13880145 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3E4D1D1507 for ; Tue, 19 Nov 2024 15:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030627; cv=none; b=u8pWPCbLJuaM+pVNugL3M0zztYx/8ZKc0f/+tMR77qcHz4VA6ffNEgjm/yzgXwAcqGSqXGUXTgW81nF5+fOlT16+y9XWKGPCEbXLPb6pqB95aKux35PAGtG9C7Fb7OgBW5nYsCCp1ke+UJpao5M1PTbW3hhJeQ8FENeh5m/9tpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030627; c=relaxed/simple; bh=cnYpYjLBTIDxdGMCq3ftfxN2ANuqhy1kTRobzTcW9PU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=csEBb594U7MsKEaHs1rYFmIZ/Oy1Sr9yJ+Iy7Q8E63Vthbhsxa3vmn2RpyI+xD1RlNqGl7i+f5CWWvgNXm1+FfY4sCEsOCxVbli+hawd0HHSq5FqYwA03TYWCnoWJwG639dDgku4bGPmKM0GTybkipbUWt3zXJnIxP4x95B7UHM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Bn17V7Ss; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bn17V7Ss" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a9ec86a67feso199518266b.1 for ; Tue, 19 Nov 2024 07:37:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732030620; x=1732635420; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Ovtm9gY84fKxE73HsC17sHE1y34He/t9h9sNO1xW/I4=; b=Bn17V7SsLUVsFqkGNcxS7S/YAHu1WIch5/i7FMMRb6SBVQY2kdgvW+vrGlmeycxuog bM4i+3WpE18I3mYkXKhtAYlLuvknMe5J8l5AegpjLsZhh4fIHK91CSPqWpc6eGSxneCW pQP9eJsuzoA4ebn1TebzUBdFA2KzztmkGvvcnkP71JA50aOJH2TM9FD4ehhEAwcIbUD6 VgW1TyQ2hreFU0JwZIDTx/oowR+tx3/8RssDZduZp+k0V5PimeyGbfurRRxbP86lqp7Y zEQ/zO8ORwcRvMGwKjt2vNfEIGKoFrtEOMztVuYwmYonWvdyBwsPAnInBaq9+L1X4MUm ehgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732030620; x=1732635420; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ovtm9gY84fKxE73HsC17sHE1y34He/t9h9sNO1xW/I4=; b=PIrd3GKESvqLniqp7Vr5cgogDa6XvF/L1LBTZ5ptzFQqZQD3E4qAcpmK9WSNoBl2YO eCKD6xDxuZ/f4/Plo9Wqur1xUzcvdfi7FBtE/I4oNYbEdsYqmFWyLdNM0WTPZK+7UOVI +wxwGV0HTMXy1+ZM7jAzP7JbFupdO3eCI1hubSUsdnzUVSV4jvZCOgl2UOpZCY7FRIK2 ltXi6d0p2DIBCaiBXP0yGyJUZMRyJPfQRdT1/Xa/M4076p9ESzdJNRxix+8VJ2k5eiv3 5SBLyMxtvTysgndoF1geBr/ACPCRkvdDYes0Owv3Mz/E+oD89SaTsYoNVqbKx79IO1Cz 8L3g== X-Gm-Message-State: AOJu0YzUcyiAbMMUBaxfAQwY6eTsTSD4Ap3K2TQ2XdrTR1IT8BKO7AOk 9Brjv62w2e2ZeLSYaxefteVLjY/1OE+8OZFhX0rYJqkxx62+ePZ+zo932+uu X-Google-Smtp-Source: AGHT+IFReoUyxiFzZBLxDrSowyxdAq5rbIiwf4cu3Che/YZLoPtMYLjbah19YhbCPRxncyVfD6J+cg== X-Received: by 2002:a17:907:6095:b0:a99:fc3d:7c76 with SMTP id a640c23a62f3a-aa483529883mr1325257966b.37.1732030619622; Tue, 19 Nov 2024 07:36:59 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df4e7bfsm661900566b.42.2024.11.19.07.36.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 07:36:59 -0800 (PST) From: Karthik Nayak Date: Tue, 19 Nov 2024 16:36:40 +0100 Subject: [PATCH v2 01/10] builtin: pass repository to sub commands Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-1-e2f607174efc@gmail.com> References: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> In-Reply-To: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, shejialuo@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=53123; i=karthik.188@gmail.com; h=from:subject:message-id; bh=cnYpYjLBTIDxdGMCq3ftfxN2ANuqhy1kTRobzTcW9PU=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnPLCXGtrnlbDehLzUHt6frLNsMh/5VPAQMHsig W9sj1EIxAqJAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZzywlwAKCRA+1Z8kjkaM f0wLC/9NKKELr+gdBJnDTuenxv0sZxyAXDW4pecgf6SSPXFNtQHYGiSrSZCJ+er6OcPLPcIoz8e vlteMluyHotHQ5vZw6lMkvMDJilpI5kgPVUr8S1X1VWPVrIi4etMT+Jq3pLQTF2mvhl4y0t2igc fcEyNKqU69kUxL5h02djqAdv/X0u6Y8n3jMe2WLyEsnAYL6KvnyfxrDCn2UWpd23Wi8j/1HNtU8 Io1VXCj96FT714cFpkr9c3v04nxSpr6nQsNCDU42tF8EulELBkBW8c7p7RxWLt000+FwCjuW86e RIeQUR56OeHHz79E+a1xA0whbUA0bOhOz+CQ8MkKwgVbDWFOyp0lcgW1FyxMifXAneLALtFtwkg m3U0R+/jSBO8+kQHxVWaHSj4qnI40SpJy3ieiFzApQLadFegzZZziElq4H9grMCMWYMZkue8UCW 1T1G9vY7eqEacu3gqKu5yyhQuKQnmZKVhuiNJuwsG+JtQa66vsYc0oiETr/GG11/H1E7Y= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F In 9b1cb5070f (builtin: add a repository parameter for builtin functions, 2024-09-13) the repository was passed down to all builtin commands. This allowed the repository to be passed down to lower layers without depending on the global `the_repository` variable. Continue this work by also passing down the repository parameter from the command to sub-commands. In the upcoming commit, utilize this to remove global variable usage in `midx-write.c`. Signed-off-by: Karthik Nayak --- builtin/bisect.c | 32 +++++++++++++++++++----------- builtin/bundle.c | 16 +++++++++------ builtin/commit-graph.c | 10 ++++++---- builtin/config.c | 25 ++++++++++++++--------- builtin/gc.c | 21 ++++++++++++-------- builtin/hook.c | 7 ++++--- builtin/multi-pack-index.c | 16 +++++++++------ builtin/notes.c | 36 +++++++++++++++++++++------------ builtin/reflog.c | 17 ++++++++++------ builtin/refs.c | 10 ++++++---- builtin/remote.c | 34 +++++++++++++++++++++----------- builtin/sparse-checkout.c | 25 ++++++++++++++--------- builtin/stash.c | 39 +++++++++++++++++++++++------------- builtin/submodule--helper.c | 46 ++++++++++++++++++++++++++++--------------- builtin/worktree.c | 28 ++++++++++++++++---------- parse-options.h | 4 +++- t/helper/test-parse-options.c | 8 +++++--- 17 files changed, 239 insertions(+), 135 deletions(-) diff --git a/builtin/bisect.c b/builtin/bisect.c index 21d17a6c1a83e51fb82b53703b95d89bd9028830..8166d4abf532fbc95aaac71198e9722684ccf7f5 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -1312,7 +1312,8 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv) 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) 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); } -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; 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; } -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; 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; } -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; 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; } -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(); } -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; 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; } -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; 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; } -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; struct bisect_terms terms = { 0 }; @@ -1399,7 +1408,8 @@ static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix 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; 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, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { int res = 0; parse_opt_subcommand_fn *fn = NULL; @@ -1451,7 +1461,7 @@ int cmd_bisect(int argc, } else { argc--; argv++; - res = fn(argc, argv, prefix); + res = fn(argc, argv, prefix, repo); } return is_bisect_success(res) ? 0 : -res; diff --git a/builtin/bundle.c b/builtin/bundle.c index 127518c2a8d3c4ec0bde62f1932e964ce9bcf66f..3f14754197c847e7a4e98b607c1a24df2b053daf 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -67,7 +67,8 @@ static int parse_options_cmd_bundle(int 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; int version = -1; int ret; @@ -123,7 +124,8 @@ static int open_bundle(const char *path, struct bundle_header *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; int bundle_fd = -1; int quiet = 0; @@ -164,7 +166,8 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) { 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; int bundle_fd = -1; int ret; @@ -189,7 +192,8 @@ static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix 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; int bundle_fd = -1; int ret; @@ -231,7 +235,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix) int cmd_bundle(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { parse_opt_subcommand_fn *fn = NULL; struct option options[] = { @@ -247,5 +251,5 @@ int cmd_bundle(int argc, packet_trace_identity("bundle"); - return !!fn(argc, argv, prefix); + return !!fn(argc, argv, prefix, repo); } diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 7c991db6eb48ad6e935727a079abac02bb358f8a..bd70d052e706b6e34b5aaaceef158c63ea4863d5 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -62,7 +62,8 @@ static struct option *add_common_options(struct option *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 object_directory *odb = NULL; @@ -214,7 +215,8 @@ static int git_commit_graph_write_config(const char *var, const char *value, 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 strbuf buf = STRBUF_INIT; @@ -333,7 +335,7 @@ static int graph_write(int argc, const char **argv, const char *prefix) int cmd_commit_graph(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { parse_opt_subcommand_fn *fn = NULL; struct option builtin_commit_graph_options[] = { @@ -352,5 +354,5 @@ int cmd_commit_graph(int argc, builtin_commit_graph_usage, 0); FREE_AND_NULL(options); - return fn(argc, argv, prefix); + return fn(argc, argv, prefix, repo); } diff --git a/builtin/config.c b/builtin/config.c index cba702210815b716a5c6c93ebb69d8c485901e43..16e6e3055598f1355714dc6de458b662870214c0 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -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_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; } -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_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; } -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; 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; } -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; const char *value_pattern = NULL; @@ -1010,7 +1014,8 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix) 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 option opts[] = { @@ -1039,7 +1044,8 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr 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 option opts[] = { @@ -1099,7 +1105,8 @@ static int show_editor(struct config_location_options *opts) 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 option opts[] = { @@ -1395,7 +1402,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) int cmd_config(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { parse_opt_subcommand_fn *subcommand = NULL; struct option subcommand_opts[] = { @@ -1422,7 +1429,7 @@ int cmd_config(int argc, if (subcommand) { argc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage, 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); diff --git a/builtin/gc.c b/builtin/gc.c index 09802eb989471be242a4b2d74606b0998fdd2b11..50ccab172365d22c8f89e9f6fb822fca948878e7 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1567,7 +1567,8 @@ static int task_option_parse(const struct option *opt UNUSED, 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; struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT; @@ -1629,7 +1630,8 @@ static char const * const builtin_maintenance_register_usage[] = { 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; struct option options[] = { @@ -1693,7 +1695,8 @@ static char const * const builtin_maintenance_unregister_usage[] = { 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; char *config_file = NULL; @@ -2923,7 +2926,8 @@ static const char *const builtin_maintenance_start_usage[] = { 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 option options[] = { @@ -2946,7 +2950,7 @@ static int maintenance_start(int argc, const char **argv, const char *prefix) if (update_background_schedule(&opts, 1)) 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")); return 0; } @@ -2956,7 +2960,8 @@ static const char *const builtin_maintenance_stop_usage[] = { 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[] = { OPT_END() @@ -2976,7 +2981,7 @@ static const char * const builtin_maintenance_usage[] = { int cmd_maintenance(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { parse_opt_subcommand_fn *fn = NULL; struct option builtin_maintenance_options[] = { @@ -2990,5 +2995,5 @@ int cmd_maintenance(int argc, argc = parse_options(argc, argv, prefix, builtin_maintenance_options, builtin_maintenance_usage, 0); - return fn(argc, argv, prefix); + return fn(argc, argv, prefix, repo); } diff --git a/builtin/hook.c b/builtin/hook.c index 367ef3e0b893fa16756880395151a82ed053acd8..672d2e37e845a2118aca1c4417a837138c250590 100644 --- a/builtin/hook.c +++ b/builtin/hook.c @@ -19,7 +19,8 @@ static const char * const builtin_hook_run_usage[] = { 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; struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; @@ -70,7 +71,7 @@ static int run(int argc, const char **argv, const char *prefix) int cmd_hook(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { parse_opt_subcommand_fn *fn = NULL; struct option builtin_hook_options[] = { @@ -81,5 +82,5 @@ int cmd_hook(int argc, argc = parse_options(argc, argv, NULL, builtin_hook_options, builtin_hook_usage, 0); - return fn(argc, argv, prefix); + return fn(argc, argv, prefix, repo); } diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index d159ed1314d912a390ed725659b3abe7c821b83f..85e40a4b6d3e47e9ec1ec27c094455e5ba75b5b0 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -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, - const char *prefix) + const char *prefix, + struct repository *repo UNUSED) { struct option *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, - const char *prefix) + const char *prefix, + struct repository *repo UNUSED) { struct option *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, - const char *prefix) + const char *prefix, + struct repository *repo UNUSED) { struct option *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, - const char *prefix) + const char *prefix, + struct repository *repo UNUSED) { struct option *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, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { int res; parse_opt_subcommand_fn *fn = NULL; @@ -297,7 +301,7 @@ int cmd_multi_pack_index(int argc, builtin_multi_pack_index_usage, 0); FREE_AND_NULL(options); - res = fn(argc, argv, prefix); + res = fn(argc, argv, prefix, repo); free(opts.object_dir); return res; diff --git a/builtin/notes.c b/builtin/notes.c index 72c8a51cfacf72e1f115774487311b3d4464d204..d051abf6dff8f2bce193fd52b4beda5060af3972 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -431,7 +431,8 @@ static struct notes_tree *init_notes_check(const char *subcommand, 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 object_id object; @@ -468,9 +469,11 @@ static int list(int argc, const char **argv, const char *prefix) 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; const char *object_ref; @@ -543,7 +546,7 @@ static int add(int argc, const char **argv, const char *prefix) * argv[0-1]. */ 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"), oid_to_hex(&object)); @@ -569,7 +572,8 @@ static int add(int argc, const char **argv, const char *prefix) 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; const struct object_id *from_note, *note; @@ -646,7 +650,8 @@ static int copy(int argc, const char **argv, const char *prefix) 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; const char *object_ref; @@ -749,7 +754,8 @@ static int append_edit(int argc, const char **argv, const char *prefix) 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; struct notes_tree *t; @@ -875,7 +881,8 @@ static int git_config_get_notes_strategy(const char *key, 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 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; } -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; int from_stdin = 0; @@ -1059,7 +1067,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix) 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; int show_only = 0, verbose = 0; @@ -1088,7 +1097,8 @@ static int prune(int argc, const char **argv, const char *prefix) 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() }; char *notes_ref; @@ -1109,7 +1119,7 @@ static int get_ref(int argc, const char **argv, const char *prefix) int cmd_notes(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { const char *override_notes_ref = NULL; parse_opt_subcommand_fn *fn = NULL; @@ -1148,5 +1158,5 @@ int cmd_notes(int argc, strbuf_release(&sb); } - return !!fn(argc, argv, prefix); + return !!fn(argc, argv, prefix, repo); } diff --git a/builtin/reflog.c b/builtin/reflog.c index 22df6834f71098ab8378e4423967f0fb87858340..5a0c22f2f7e58733ce636619f3f19265b394bde5 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -234,7 +234,8 @@ static int expire_total_callback(const struct option *opt, 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[] = { OPT_END() @@ -253,7 +254,8 @@ static int show_reflog(const char *refname, void *cb_data UNUSED) 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[] = { 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); } -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 }; timestamp_t now = time(NULL); @@ -394,7 +397,8 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) 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; unsigned int flags = 0; @@ -424,7 +428,8 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) 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[] = { OPT_END() @@ -467,7 +472,7 @@ int cmd_reflog(int argc, PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT); if (fn) - return fn(argc - 1, argv + 1, prefix); + return fn(argc - 1, argv + 1, prefix, repository); else return cmd_log_reflog(argc, argv, prefix, repository); } diff --git a/builtin/refs.c b/builtin/refs.c index 24978a7b7b081ac6ed8ca99016f201d34c0639f8..3502980d21d055d8fc5ef36d2165aae61bc4db62 100644 --- a/builtin/refs.c +++ b/builtin/refs.c @@ -12,7 +12,8 @@ #define REFS_VERIFY_USAGE \ 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[] = { REFS_MIGRATE_USAGE, @@ -63,7 +64,8 @@ static int cmd_refs_migrate(int argc, const char **argv, const char *prefix) 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; 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, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { const char * const refs_usage[] = { REFS_MIGRATE_USAGE, @@ -108,5 +110,5 @@ int cmd_refs(int argc, }; argc = parse_options(argc, argv, prefix, opts, refs_usage, 0); - return fn(argc, argv, prefix); + return fn(argc, argv, prefix, repo); } diff --git a/builtin/remote.c b/builtin/remote.c index 76670ddd8b44e5b118c76522613c445ad92c5364..56214775df4ce86bf5d8e4ddb8d19140f696aeef 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -155,7 +155,8 @@ static int parse_mirror_opt(const struct option *opt, const char *arg, int not) 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; unsigned mirror = MIRROR_NONE; @@ -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); struct option options[] = { @@ -881,7 +883,8 @@ static int mv(int argc, const char **argv, const char *prefix) 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[] = { OPT_END() @@ -1303,7 +1306,8 @@ static int show_all(void) 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; struct option options[] = { @@ -1399,7 +1403,8 @@ static int show(int argc, const char **argv, const char *prefix) 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; struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; @@ -1503,7 +1508,8 @@ static int prune_remote(const char *remote, int dry_run) 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; struct option options[] = { @@ -1534,7 +1540,8 @@ static int get_remote_default(const char *key, const char *value UNUSED, 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; struct option options[] = { @@ -1616,7 +1623,8 @@ static int set_remote_branches(const char *remotename, const char **branches, 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; 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); } -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; const char *remotename = NULL; @@ -1674,7 +1683,8 @@ static int get_url(int argc, const char **argv, const char *prefix) 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 matches = 0, negative_matches = 0; @@ -1765,7 +1775,7 @@ static int set_url(int argc, const char **argv, const char *prefix) int cmd_remote(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { parse_opt_subcommand_fn *fn = NULL; struct option options[] = { @@ -1788,7 +1798,7 @@ int cmd_remote(int argc, PARSE_OPT_SUBCOMMAND_OPTIONAL); if (fn) { - return !!fn(argc, argv, prefix); + return !!fn(argc, argv, prefix, repo); } else { if (argc) { error(_("unknown subcommand: `%s'"), argv[0]); diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 49aedc1de81a17b8b491cded7fa71b384e0e8be9..6f5fa5893b839fe21fef44ecbd837d132ebbac26 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -48,7 +48,8 @@ static char const * const builtin_sparse_checkout_list_usage[] = { 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[] = { OPT_END(), @@ -443,7 +444,8 @@ static struct sparse_checkout_init_opts { int sparse_index; } 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; char *sparse_filename; @@ -770,7 +772,8 @@ static struct sparse_checkout_add_opts { int use_stdin; } 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[] = { OPT_BOOL_F(0, "skip-checks", &add_opts.skip_checks, @@ -808,7 +811,8 @@ static struct sparse_checkout_set_opts { int use_stdin; } 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; const char *default_patterns[] = {"/*", "!/*/", NULL}; @@ -866,7 +870,8 @@ static struct sparse_checkout_reapply_opts { } reapply_opts; 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[] = { 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, - const char *prefix) + const char *prefix, + struct repository *repo UNUSED) { static struct option builtin_sparse_checkout_disable_options[] = { OPT_END(), @@ -989,7 +995,8 @@ static int check_rules(struct pattern_list *pl, int null_terminated) { 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[] = { 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, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { parse_opt_subcommand_fn *fn = NULL; struct option builtin_sparse_checkout_options[] = { @@ -1060,5 +1067,5 @@ int cmd_sparse_checkout(int argc, prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; - return fn(argc, argv, prefix); + return fn(argc, argv, prefix, repo); } diff --git a/builtin/stash.c b/builtin/stash.c index 1399a1bbe2c222ed3e1c33ac2dd17bd1148f709c..c212b1c0b2c7c55de2fdd5d7d7a247ce6f530960 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -249,7 +249,8 @@ static int do_clear_stash(void) 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[] = { OPT_END() @@ -652,7 +653,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, 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 quiet = 0; @@ -726,7 +728,8 @@ static int get_stash_info_assert(struct stash_info *info, int argc, 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 quiet = 0; @@ -748,7 +751,8 @@ static int drop_stash(int argc, const char **argv, const char *prefix) 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 index = 0; @@ -778,7 +782,8 @@ static int pop_stash(int argc, const char **argv, const char *prefix) 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; const char *branch = NULL; @@ -816,7 +821,8 @@ static int branch_stash(int argc, const char **argv, const char *prefix) 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 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); } -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 ret = -1; @@ -1017,7 +1024,8 @@ static int do_store_stash(const struct object_id *w_commit, const char *stash_ms 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; const char *stash_msg = NULL; @@ -1491,7 +1499,8 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b 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; 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; } -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); } -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 only_staged = 0; @@ -1878,7 +1889,7 @@ static int save_stash(int argc, const char **argv, const char *prefix) int cmd_stash(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { pid_t pid = getpid(); const char *index_file; @@ -1916,9 +1927,9 @@ int cmd_stash(int argc, (uintmax_t)pid); if (fn) - return !!fn(argc, argv, prefix); + return !!fn(argc, argv, prefix, repo); else if (!argc) - return !!push_stash_unassumed(0, NULL, prefix); + return !!push_stash_unassumed(0, NULL, prefix, repo); /* Assume 'stash push' */ strvec_push(&args, "push"); diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index b6b5f1ebde7c2e4780af4097a0c4d6d838948aee..19e587838132f26e2e10dc4a9f93f7b1c78cd49d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -399,7 +399,8 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, 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 pathspec pathspec = { 0 }; @@ -544,7 +545,8 @@ static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data 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 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); } -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 pathspec pathspec = { 0 }; @@ -1163,7 +1166,8 @@ static int compute_summary_module_list(struct object_id *head_oid, 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; int cached = 0; @@ -1339,7 +1343,8 @@ static void sync_submodule_cb(const struct cache_entry *list_item, void *cb_data 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 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); } -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 pathspec pathspec = { 0 }; @@ -1842,7 +1848,8 @@ static int clone_submodule(const struct module_clone_data *clone_data, 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; struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT; @@ -2779,7 +2786,8 @@ static int update_submodules(struct update_data *update_data) 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 pathspec2 = { 0 }; @@ -2911,7 +2919,8 @@ static int module_update(int argc, const char **argv, const char *prefix) 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; const char *superproject_head; @@ -2991,7 +3000,8 @@ static int push_check(int argc, const char **argv, const char *prefix UNUSED) 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; struct pathspec pathspec = { 0 }; @@ -3024,7 +3034,8 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) 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; const char *newurl; @@ -3063,7 +3074,8 @@ static int module_set_url(int argc, const char **argv, const char *prefix) 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; const char *opt_branch = NULL; @@ -3113,7 +3125,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) 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; 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); } -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; struct add_data add_data = ADD_DATA_INIT; @@ -3557,7 +3571,7 @@ static int module_add(int argc, const char **argv, const char *prefix) int cmd_submodule__helper(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { parse_opt_subcommand_fn *fn = NULL; const char *const usage[] = { @@ -3583,5 +3597,5 @@ int cmd_submodule__helper(int argc, }; argc = parse_options(argc, argv, prefix, options, usage, 0); - return fn(argc, argv, prefix); + return fn(argc, argv, prefix, repo); } diff --git a/builtin/worktree.c b/builtin/worktree.c index dae63dedf4cac2621f51f95a39aa456b33acd894..824dd71d643f112f384cde4de1373698c67de254 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -231,7 +231,8 @@ static void prune_worktrees(void) 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[] = { 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; } -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; const char *new_branch_force = NULL; @@ -1039,7 +1041,8 @@ static void pathsort(struct worktree **wt) 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 line_terminator = '\n'; @@ -1084,7 +1087,8 @@ static int list(int ac, const char **av, const char *prefix) 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; struct option options[] = { @@ -1119,7 +1123,8 @@ static int lock_worktree(int ac, const char **av, const char *prefix) 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[] = { 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")); } -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; struct option options[] = { @@ -1312,7 +1318,8 @@ static int delete_git_work_tree(struct worktree *wt) 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; 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 *self[] = { ".", NULL }; @@ -1397,7 +1405,7 @@ static int repair(int ac, const char **av, const char *prefix) int cmd_worktree(int ac, const char **av, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { parse_opt_subcommand_fn *fn = NULL; struct option options[] = { @@ -1422,5 +1430,5 @@ int cmd_worktree(int ac, prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; - return fn(ac, av, prefix); + return fn(ac, av, prefix, repo); } diff --git a/parse-options.h b/parse-options.h index ae15342390837c21503ab812648a7d8fd21432a8..f0801d4532a175b65783689f2a68fb56da2c8e87 100644 --- a/parse-options.h +++ b/parse-options.h @@ -3,6 +3,8 @@ #include "gettext.h" +struct repository; + /** * 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); typedef int parse_opt_subcommand_fn(int argc, const char **argv, - const char *prefix); + const char *prefix, struct repository *repo); /* * `type`:: diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c index 5250913d99eba18a28878d3904cb7b2399670d02..5da359486cdcb353b277653111bc201c5f82851e 100644 --- a/t/helper/test-parse-options.c +++ b/t/helper/test-parse-options.c @@ -282,14 +282,16 @@ int cmd__parse_options_flags(int argc, const char **argv) 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"); print_args(argc, argv); 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"); print_args(argc, argv); @@ -319,7 +321,7 @@ static int parse_subcommand__cmd(int argc, const char **argv, 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) From patchwork Tue Nov 19 15:36:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13880208 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 872261CF7C7 for ; Tue, 19 Nov 2024 15:45:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732031133; cv=none; b=Tz6N3FfCFpV+c6cKL2vGB5e4lYn3nGB6e/p7FDEz3rBgukl9hWGfLJvAUkHbAXBO54I7PZMpsaijxuyLC4wEAub14McLzpKD2J/UoUZZMfPDcZwuJuujfKW+QCQlqqbOriDtSVFE25+T+q8HhC1d5pri75jWoB/y/3RljcuZ1fk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732031133; c=relaxed/simple; bh=B12hGd6i9QWug35sLpT941ZcQmmggVfeXbG1Owv1U74=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uuaCXJWFu+GiKNrKMSu8UIBDYcjLa82vQ8Ao+wFRl7hwnvxGczsnsAJ9AISYJfECX4C+x645vmTU7M5C+IUyj4XbxUR8g8EYIVcGsz7BtjW73x8pHDGii0H1BCcrfT6kIWaEKzP1VX0XF2s1jPYyp6rI7atEUR1o/Jl50Qgf0Nk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YuneiaUI; arc=none smtp.client-ip=209.85.208.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YuneiaUI" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2ff3232ee75so12813691fa.0 for ; Tue, 19 Nov 2024 07:45:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732031126; x=1732635926; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7qFaL325BLK6UsmoH5bv64smidErvBPS90PwORCttv4=; b=YuneiaUIDpsPrNhtXr/ZP8VJOICjdXZbLMPLB0184YxXpRo2PoheZourrEVM58sP2p Wl7GeSc8X5mc1GiBnap9MOkJIiKrTZo84YA+L3pf2AZ3Oi87+G6Bux/o5epnP1YflaqS b/w062ArG0H+aPHijgoAPhahx0jYtFm+Tg2HX3R6GzBrEf+FnuDwI3FiQ4BX2DMJarLb k3ktnuqPQSvHxxcndW0utxO7T1rCf0WeKDbIYKKvWfDlELl6qcw3K9BiKGBLO4LdeASf i/OJDZsb2VxeDVTMZJyz+/bQ+kavwm8CnRJ2XJ0S8Hti9uCOTD7iKEe01pVM4Ib08I9w npdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732031126; x=1732635926; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7qFaL325BLK6UsmoH5bv64smidErvBPS90PwORCttv4=; b=AbCOeJWcHsgql4LP3dRDJRFMXX3G+JaAvLcheRluqB9QSukLFeyFTz8kZa2CVJKkqn 5pYEpC4tAAlyWE+b+B5fKJsEql/2QIM6Fj1c8+4gLR/j9K8m8QX7F+djvQpKCbKhPvOD KxMwTld1ELMXTTRSceV/wBLrvmhK5l3pJiYlX6kxkBffjrC7NHOT88plXxvqwXsOGaVM 4l/ZWschajHvfVGRgjeSy2Lot0PdP2J1FxVDwRsTU5VfRSzupbCFzANAXNHkBrk0naaX lYJz/NT8vwbjhtI230k/GfiwrwQiSC8pYUpRLF8TLw0ncG4HvVtK13z19s9ox/GLTJmT VoHQ== X-Gm-Message-State: AOJu0Yx616Ak2TT9zgNWPvWvI+N02TExKR5owRKj41INNNFolm5P81Iq mZT2nF0tWbswhljwDch61ktO/xtu6RJIaLSrqVFPrcdLQXqBg6+S8XgeUdAT X-Google-Smtp-Source: AGHT+IHIv172quwxQExX9gJyIk9FgeCovqlmREDlBAHBWf5A6S3nQjKzwNECITBEbVig5VREINVg+Q== X-Received: by 2002:a17:906:d108:b0:aa4:844d:e5ee with SMTP id a640c23a62f3a-aa4844dfe9fmr1304335466b.56.1732030620431; Tue, 19 Nov 2024 07:37:00 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df4e7bfsm661900566b.42.2024.11.19.07.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 07:37:00 -0800 (PST) From: Karthik Nayak Date: Tue, 19 Nov 2024 16:36:41 +0100 Subject: [PATCH v2 02/10] midx-write: pass down repository to static functions Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-2-e2f607174efc@gmail.com> References: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> In-Reply-To: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, shejialuo@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8735; i=karthik.188@gmail.com; h=from:subject:message-id; bh=B12hGd6i9QWug35sLpT941ZcQmmggVfeXbG1Owv1U74=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnPLCX21YoElqs5mQ00JtJ9v1pECp1/L+FmH+jl NQP2wfQfQuJAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZzywlwAKCRA+1Z8kjkaM f44kC/9sI0RWdfa0Z2oyRklnv3Ijlz2qyYJB5Pv3xk8Xy3kqXtw26uI7RyhFCZhJispSQZwOJHp gRokO30LcF5MJs14xvG87TjK97wYhH95fFCK5wrlIBWxQlKlI15jcvCWqDYoRhT22aF42XvepxO mPXmdEx9NDSsjwVTNg1p4IHquWhwHcWMC3fPV7cp+RESupyAIKhnV7ReEjsgtxBPaq17ToTngev DIauhX3uHPMoVSFPIsGIbM2VzcNS76aXJ5QrKsXrHnDaEbgxl55RS3HSQLPLFIJcp4SG5JCxkGR auKZIR8NAyJJcUN1XfpPYyaG+nQ/TUuJda7D1emy0H67ofKwLPYSfhz5hguv/O8glgrxxajS54q FVDB2xKG5LST/FKQUNhIhbfMvGTI0BvLt1JNotzuZfEWgGmosrfzq741YndLNT/iaRriQ5Z3BGr F/LeysAqlIqDvQ+ID/dgm58JdioHkBWBCjfrVbbJup7CLjUdJiACiK8124Bpwf61m4NV4= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F In 'midx-write.c' there are a lot of static functions which use global variables `the_repository` or `the_hash_algo`. In a follow up commit, the repository variable will be added to `write_midx_context`, which some of the functions can use. But for functions which do not have access to this struct, pass down the required information from non-static functions `write_midx_file` and `write_midx_file_only`. This ensures that the usage of global variables is limited to these non-static functions, which will be cleaned up in a follow up commits. Signed-off-by: Karthik Nayak --- midx-write.c | 57 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/midx-write.c b/midx-write.c index c57726ef9475df693890d61627ce91409c1def7c..22b5233f51ec6c6d99b8f9613818f1581dca5982 100644 --- a/midx-write.c +++ b/midx-write.c @@ -35,13 +35,13 @@ extern void clear_incremental_midx_files_ext(const char *object_dir, extern int cmp_idx_or_pack_name(const char *idx_or_pack_name, const char *idx_name); -static size_t write_midx_header(struct hashfile *f, - unsigned char num_chunks, +static size_t write_midx_header(const struct git_hash_algo *hash_algo, + struct hashfile *f, unsigned char num_chunks, uint32_t num_packs) { hashwrite_be32(f, MIDX_SIGNATURE); hashwrite_u8(f, MIDX_VERSION); - hashwrite_u8(f, oid_version(the_hash_algo)); + hashwrite_u8(f, oid_version(hash_algo)); hashwrite_u8(f, num_chunks); hashwrite_u8(f, 0); /* unused */ hashwrite_be32(f, num_packs); @@ -702,7 +702,7 @@ static int add_ref_to_pending(const char *refname, const char *referent UNUSED, return 0; } - if (!peel_iterated_oid(the_repository, oid, &peeled)) + if (!peel_iterated_oid(revs->repo, oid, &peeled)) oid = &peeled; object = parse_object_or_die(oid, refname); @@ -827,7 +827,7 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr return cb.commits; } -static int write_midx_bitmap(const char *midx_name, +static int write_midx_bitmap(struct repository *r, const char *midx_name, const unsigned char *midx_hash, struct packing_data *pdata, struct commit **commits, @@ -840,9 +840,9 @@ static int write_midx_bitmap(const char *midx_name, struct bitmap_writer writer; struct pack_idx_entry **index; char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name, - hash_to_hex(midx_hash)); + hash_to_hex_algop(midx_hash, r->hash_algo)); - trace2_region_enter("midx", "write_midx_bitmap", the_repository); + trace2_region_enter("midx", "write_midx_bitmap", r); if (flags & MIDX_WRITE_BITMAP_HASH_CACHE) options |= BITMAP_OPT_HASH_CACHE; @@ -859,7 +859,7 @@ static int write_midx_bitmap(const char *midx_name, for (i = 0; i < pdata->nr_objects; i++) index[i] = &pdata->objects[i].idx; - bitmap_writer_init(&writer, the_repository, pdata); + bitmap_writer_init(&writer, r, pdata); bitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS); bitmap_writer_build_type_index(&writer, index); @@ -892,7 +892,7 @@ static int write_midx_bitmap(const char *midx_name, free(bitmap_name); bitmap_writer_free(&writer); - trace2_region_leave("midx", "write_midx_bitmap", the_repository); + trace2_region_leave("midx", "write_midx_bitmap", r); return ret; } @@ -1049,7 +1049,7 @@ static void clear_midx_files(const char *object_dir, strbuf_release(&buf); } -static int write_midx_internal(const char *object_dir, +static int write_midx_internal(struct repository *r, const char *object_dir, struct string_list *packs_to_include, struct string_list *packs_to_drop, const char *preferred_pack_name, @@ -1070,7 +1070,8 @@ static int write_midx_internal(const char *object_dir, const char **keep_hashes = NULL; struct chunkfile *cf; - trace2_region_enter("midx", "write_midx_internal", the_repository); + trace2_region_enter("midx", "write_midx_internal", r); + ctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL); if (ctx.incremental && (flags & MIDX_WRITE_BITMAP)) @@ -1087,8 +1088,7 @@ static int write_midx_internal(const char *object_dir, midx_name.buf); if (!packs_to_include || ctx.incremental) { - struct multi_pack_index *m = lookup_multi_pack_index(the_repository, - object_dir); + struct multi_pack_index *m = lookup_multi_pack_index(r, object_dir); if (m && !midx_checksum_valid(m)) { warning(_("ignoring existing multi-pack-index; checksum mismatch")); m = NULL; @@ -1351,7 +1351,7 @@ static int write_midx_internal(const char *object_dir, add_chunk(cf, MIDX_CHUNKID_OIDFANOUT, MIDX_CHUNK_FANOUT_SIZE, write_midx_oid_fanout); add_chunk(cf, MIDX_CHUNKID_OIDLOOKUP, - st_mult(ctx.entries_nr, the_hash_algo->rawsz), + st_mult(ctx.entries_nr, r->hash_algo->rawsz), write_midx_oid_lookup); add_chunk(cf, MIDX_CHUNKID_OBJECTOFFSETS, st_mult(ctx.entries_nr, MIDX_CHUNK_OFFSET_WIDTH), @@ -1373,7 +1373,8 @@ static int write_midx_internal(const char *object_dir, write_midx_bitmapped_packs); } - write_midx_header(f, get_num_chunks(cf), ctx.nr - dropped_packs); + write_midx_header(r->hash_algo, f, get_num_chunks(cf), + ctx.nr - dropped_packs); write_chunkfile(cf, &ctx); finalize_hashfile(f, midx_hash, FSYNC_COMPONENT_PACK_METADATA, @@ -1405,7 +1406,7 @@ static int write_midx_internal(const char *object_dir, FREE_AND_NULL(ctx.entries); ctx.entries_nr = 0; - if (write_midx_bitmap(midx_name.buf, midx_hash, &pdata, + if (write_midx_bitmap(r, midx_name.buf, midx_hash, &pdata, commits, commits_nr, ctx.pack_order, flags) < 0) { error(_("could not write multi-pack bitmap")); @@ -1449,12 +1450,13 @@ static int write_midx_internal(const char *object_dir, strbuf_release(&final_midx_name); keep_hashes[ctx.num_multi_pack_indexes_before] = - xstrdup(hash_to_hex(midx_hash)); + xstrdup(hash_to_hex_algop(midx_hash, r->hash_algo)); for (i = 0; i < ctx.num_multi_pack_indexes_before; i++) { uint32_t j = ctx.num_multi_pack_indexes_before - i - 1; - keep_hashes[j] = xstrdup(hash_to_hex(get_midx_checksum(m))); + keep_hashes[j] = xstrdup(hash_to_hex_algop(get_midx_checksum(m), + r->hash_algo)); m = m->base_midx; } @@ -1462,7 +1464,7 @@ static int write_midx_internal(const char *object_dir, fprintf(get_lock_file_fp(&lk), "%s\n", keep_hashes[i]); } else { keep_hashes[ctx.num_multi_pack_indexes_before] = - xstrdup(hash_to_hex(midx_hash)); + xstrdup(hash_to_hex_algop(midx_hash, r->hash_algo)); } if (ctx.m || ctx.base_midx) @@ -1495,7 +1497,7 @@ static int write_midx_internal(const char *object_dir, } strbuf_release(&midx_name); - trace2_region_leave("midx", "write_midx_internal", the_repository); + trace2_region_leave("midx", "write_midx_internal", r); return result; } @@ -1505,8 +1507,8 @@ int write_midx_file(const char *object_dir, const char *refs_snapshot, unsigned flags) { - return write_midx_internal(object_dir, NULL, NULL, preferred_pack_name, - refs_snapshot, flags); + return write_midx_internal(the_repository, object_dir, NULL, NULL, + preferred_pack_name, refs_snapshot, flags); } int write_midx_file_only(const char *object_dir, @@ -1515,8 +1517,9 @@ int write_midx_file_only(const char *object_dir, const char *refs_snapshot, unsigned flags) { - return write_midx_internal(object_dir, packs_to_include, NULL, - preferred_pack_name, refs_snapshot, flags); + return write_midx_internal(the_repository, object_dir, packs_to_include, + NULL, preferred_pack_name, refs_snapshot, + flags); } int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags) @@ -1572,7 +1575,8 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla free(count); if (packs_to_drop.nr) - result = write_midx_internal(object_dir, NULL, &packs_to_drop, NULL, NULL, flags); + result = write_midx_internal(r, object_dir, NULL, + &packs_to_drop, NULL, NULL, flags); string_list_clear(&packs_to_drop, 0); @@ -1769,7 +1773,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, goto cleanup; } - result = write_midx_internal(object_dir, NULL, NULL, NULL, NULL, flags); + result = write_midx_internal(r, object_dir, NULL, NULL, NULL, NULL, + flags); cleanup: free(include_pack); From patchwork Tue Nov 19 15:36:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13880143 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B9991D04B9 for ; Tue, 19 Nov 2024 15:37:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030625; cv=none; b=S3qDzmqVIieODZzfCAmzvS5HdiVJq2CiZHbD0WyfPMP9RA0JJmDEViHezimcNKP6zyfFj8Ut0lwU9bfA/AkO4tthqkhxKxDI7pLb+WRaAv9Zhlhk6XpOdod6HCKQrV9d4EPg8llITTkpXqcIAdpvsCviU0nps+t3iDncCPi5FVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030625; c=relaxed/simple; bh=LhvQQIaMVCcThIn4EaY1K6mtOP/w3nRUIfnApwsDYBI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jctUaAyKohymo/pWQOSdgtRlC46xWh+om9ytH/GRZ+j1AOsnuEqoeBoThI97B4+iYS13RrTwXge/c16lNeYkPE8S9hsevJiAJgUpqM9yeFHX5r5PKRPNs6o4oeuCAkyaBzPVVNukXwbjMSdhnbqK2UHpRx5AD+TpuxPtEgF8rnM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=K/8TLUpR; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K/8TLUpR" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-539fb49c64aso4894472e87.0 for ; Tue, 19 Nov 2024 07:37:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732030621; x=1732635421; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=MZ6OjmwDs7/UnYGWlZ9cTp03IXDjXqOObzSId9Tg2sg=; b=K/8TLUpR3wK1/i5skQnkkKjzKqtbn/2rKd3yqxJqYEp1Kw1ITcOPlbZR9RgtdI7ZTC wZV3TzLPgkpUCobzeAdtLBxC/OmAfc4chxGGG8pkIQHi8ifD4Z9n8+NbUkRJX8WlU1/a QQf46MWlEK7S1zsci0lxoBsu7yDCekfFU1+OiGelETnjg/I6HxkGhuphM7swzV9IsLLq cfljWt97H8kEBJ9ufUxewRMO60QCRhcY9f2RE1Ttg6VsCNp2pfjTmeesymzM6bE94sWh jkfGr8h5eDiYd2wKlzc6NP9h5BY+PqGR2LgPiA1hrK961q/B+kgeLjnneIYeEH7SzsJd V7pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732030621; x=1732635421; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MZ6OjmwDs7/UnYGWlZ9cTp03IXDjXqOObzSId9Tg2sg=; b=QOnnI6zYu3RUABkD7f+lOtqVVL3ygQmtOYR2Bkv1UxC8Rk0ISw5KFihoUyKX9Bk7j3 Cy6tljsdQkHUltBwZMdOe3Z3fpX2xpD7torwQcfG+1zgRvlLxmKiBsn2S+K2NaqZqffM ntgoJh6kzPTnPr5olW++zKB9HA/bZtFxR8tm6YD8ZXXSIy9AnOkB1JdTmDFwK19RT+lc 4ps2Mo3Q85SWh/qFuiGbk01otNvwTsdRvUvmQpC5Y1ymaV1Ak/HNTqfjB/ZTIA1t27pl HQLFmq7PTnGrqe2wGAiwQsvL0W9qh6XtcHNRuk+LX/N5fjF6iMVLbhHx/cRygfymZ/W1 T4zA== X-Gm-Message-State: AOJu0YzQpNlOqmKoL9HtGnyVJnZk/k+ODtXkUZVdUkmqkB+t/MSehW6m rK77XsRtUgyhiOOuHA/mJJMN2RQJojDfn09B1QhS8iYulH1pHoif X-Google-Smtp-Source: AGHT+IEG0wyQygsJW7c5SHDkxBJYN6RJTk+g4/q7tRChG/aF7w5+iKOah4SlBmaYXdBJ452iiymugg== X-Received: by 2002:ac2:4c48:0:b0:536:a7a4:c3d4 with SMTP id 2adb3069b0e04-53dab3b176bmr11329410e87.39.1732030621170; Tue, 19 Nov 2024 07:37:01 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df4e7bfsm661900566b.42.2024.11.19.07.37.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 07:37:00 -0800 (PST) From: Karthik Nayak Date: Tue, 19 Nov 2024 16:36:42 +0100 Subject: [PATCH v2 03/10] midx-write: use `revs->repo` inside `read_refs_snapshot` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-3-e2f607174efc@gmail.com> References: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> In-Reply-To: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, shejialuo@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1218; i=karthik.188@gmail.com; h=from:subject:message-id; bh=LhvQQIaMVCcThIn4EaY1K6mtOP/w3nRUIfnApwsDYBI=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnPLCYZK1RT3nbQT+GIyV7e89kdtthHriUcfFOO 5dtppe+HmCJAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZzywmAAKCRA+1Z8kjkaM f36LC/98PdgjVo2YMkXti5SCZ5hTWz/YFtsw26hputJXXrSAd/wCM2qYtomp4hCzk5gQOQ6gc36 qWEJutmp+mCPN1L2S8SkUVZwzJjM+7Fe1VzTBvfQ+OQIjW2ZeMWyrnZOR08+yVfhi77t/vuPl8O DnBLE82nclRJ2yelgLd4wPC+cWyAI1j8adhc4zHhH0HaZ+nDWcz3j04e2FAuT2H26dUyXmqgdIF Nikv18YLHQQhfkPjx4ShCpRV7T4VTbL4cejWpdVvVYe/UR84+Hm0doG9SHj8z7HQUsEMaLDn6ID 49aSJmZsA5ebW27brPdQ/OHqveH2g9fqNkuzxKdgQbw2p4q2gxxE1T4Aar4rVLiFsVOIRBGmy20 bAAXHI3f4XIaSfbnm1ELKpZrDKNo54Qduf1xoAc+0D6SHQtwwHgxarFyMvCJReXZWeJlUa9SovP XdVAQTTWgBhmsLjgeqIPep4fQQNXCP4jo+nzfQdWJFkLrQpzg3Vgux1pDVX6mCjK5pKVI= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The `read_refs_snapshot` uses the `parse_oid_hex` function which internally uses global variables. Let's instead use `parse_oid_hex_algop` and provide the hash algo via `revs->repo`. Also, while here, fix a missing newline after the functions definition. Signed-off-by: Karthik Nayak --- midx-write.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/midx-write.c b/midx-write.c index 22b5233f51ec6c6d99b8f9613818f1581dca5982..564438f616f59cd24edda956e4af0e0acf167138 100644 --- a/midx-write.c +++ b/midx-write.c @@ -760,7 +760,7 @@ static int read_refs_snapshot(const char *refs_snapshot, hex = &buf.buf[1]; } - if (parse_oid_hex(hex, &oid, &end) < 0) + if (parse_oid_hex_algop(hex, &oid, &end, revs->repo->hash_algo) < 0) die(_("could not parse line: %s"), buf.buf); if (*end) die(_("malformed line: %s"), buf.buf); @@ -776,6 +776,7 @@ static int read_refs_snapshot(const char *refs_snapshot, strbuf_release(&buf); return 0; } + static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr_p, const char *refs_snapshot, struct write_midx_context *ctx) From patchwork Tue Nov 19 15:36:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13880209 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96C4F1D042D for ; Tue, 19 Nov 2024 15:46:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732031184; cv=none; b=LgQ3bJehqGzSRYg3FaWtFULJ7c4wfwxjsrcxUya49vYcPeFuDkUaGE1DQReNhhopYTgeejHsjG84nJ5+JaFt1Bkr5/eWRK+51A9ICwgp2bbUZST+7/tDqsib6BYpdKjBw+76U2GdeLM+9CDkzFPwSED0JlExMHcxOFNbOriAASE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732031184; c=relaxed/simple; bh=lQkwBZ3BUESBQ0IP0ctoA3UscK/gu30YNZWXDOpP2S0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=He1hEq5/x5W+hoTqzNXNrcMnrOUc8DqRnE+JqvBF6z2a7YFGUn93YRgD3ampYepBzal69sPfJO8o4+Vy+AqE8us1wwpGE5jkSid8A4cth5d41StGySCOP3S4WnU5uWt6ShZCKLq6w1nail8dXl8gsYoHXIj1u7X6Su12zE5+urc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LwNkFiZq; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LwNkFiZq" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-43168d9c6c9so9809185e9.3 for ; Tue, 19 Nov 2024 07:46:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732031181; x=1732635981; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZGnJJ5LpD9+Gdx/vWsZvUv4z5njsYrPhy3XbG3d5wcs=; b=LwNkFiZqeZQq4AiOJmsAJ2TiYS/WF4Pe5rOxBS1jPpUr11DZ4OGzTEWnP7AKzvRSqT BaS/IDBuku36Ph/nDyS2tgFGfxV7m8pYUy0Z000XAm3vpHEpNLJNtm19m2wu89Hmm5x2 V3RPJBaT7wVzsHJ34f14H8d4COWm5j2Elp057vy9zyrcLGf/6Yf55L3FayF/2D+g3a+w tzMJ6I90qhhvwgoRhSpN1hndGD6aMaghHLnaePIJ6TuV9ike+ic36RxBmtQvfggSRr/3 /TUPJlj0+Jg/HpipVsiDulV+EmMBK5IKXYrSIpa6bJwkNJ4fzyghOv4z68xsClk0Jhdb Yq2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732031181; x=1732635981; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZGnJJ5LpD9+Gdx/vWsZvUv4z5njsYrPhy3XbG3d5wcs=; b=T7+qmjAXc6hbgAH2oZcAW68yGZpDTt279yxx+OaWCWYgx1eNwgpqYdhNr2Kk22LT3v Y1/tXQm520AaBT0aX/SeC0+OhMXuUMYPgFOnSdK2elXK0eLJw0GPIAar7HS8B6zVdeUZ LbkulzBgSqKTgtqSCUs1jSaW4QI1de26IggjNsXZVRVUvi63bMWS6k2dE+QSaeOPbtXz FC2Z7NXFDVS2wMzeI9eYpvibe9W38aPi6+usq+U/06s0IEbxbXMvLG8Wy64Aqm9mm5iZ ggQTuBBqUSJim6oI0nMjnz/ociGraXyvXqhjJhacvQSgBsbbJm2MGuzAXp9SO/8GjNVG pDCw== X-Gm-Message-State: AOJu0YwVMt0NpJWWQOfg95FPmejlcgx/jkSs0VuTM21DttJF61xiqjPK 78ee0fliQmz60495+vQdDtCkDnXsIVBBfuVGr6gKjZXwp73xwPytCfNla5Vf X-Google-Smtp-Source: AGHT+IF+nv3kS94A8oBEXzi6sl0aYBNMrbQ3i+y4eLY3m4rmrLWEgSF1FcxOGD37JhrgG7IMuEQqmg== X-Received: by 2002:a17:906:fd88:b0:a9a:55dd:bc23 with SMTP id a640c23a62f3a-aa4833f6558mr1419332966b.8.1732030621886; Tue, 19 Nov 2024 07:37:01 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df4e7bfsm661900566b.42.2024.11.19.07.37.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 07:37:01 -0800 (PST) From: Karthik Nayak Date: Tue, 19 Nov 2024 16:36:43 +0100 Subject: [PATCH v2 04/10] write-midx: add repository field to `write_midx_context` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-4-e2f607174efc@gmail.com> References: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> In-Reply-To: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, shejialuo@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6085; i=karthik.188@gmail.com; h=from:subject:message-id; bh=lQkwBZ3BUESBQ0IP0ctoA3UscK/gu30YNZWXDOpP2S0=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnPLCYqAv9cYhVWrwYPcg82/Xd20ina4iQQscpE xVkELHmsbSJAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZzywmAAKCRA+1Z8kjkaM fz3ZDACMfhukitNfz6YP7DIjxjHQLqW/iXhWt+3dXTKZIexI2DOpu3NuTn3CB4XvtYO2vQ+z86j brwPXeI/nMDLjaA6FvgkFFFnhfGLIzNOEMuKdGMfJ+2l0USt44hXLqc2TO8bvcTlUWUD15FnOmA Z8+VsnZDOu07tcTVRwZRCDJhkm4kQ5c1lpnrXBbq7cNfiArIs8Ls9ezj0UVitCuMylP1ginG1J+ 9ExtWFw5vYByHNWtI8lbljL09rs6ceLyqlqgdZpAu42dx/EUkA3tK2DUSeBmmcgOrxq9S+MUqHl 8PKpdn2SgFGASwBwVLt509wnAlpiwO6d9ky+Gc1uajD2lvgzPfnBfrv86IFIojLvAw5IkuJiPBz yYbaQRRbykel3DfPGIHzvwpmFjml2YLYJXj31sgI1OqMTH6Ngr/6PfYUwlmmjL/R/gHE5Zz8Jg9 243f3I4TK7qJHoJSAuS0Yy/HcCAMyIm8Nl16Vn31aKpeAJNVW+ChwQ4N/1skngemhjDjw= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The struct `write_midx_context` is used to pass context for creating MIDX files. Add the repository field here to ensure that most functions within `midx-write.c` have access to the field and can use that instead of the global `the_repository` variable. Signed-off-by: Karthik Nayak --- midx-write.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/midx-write.c b/midx-write.c index 564438f616f59cd24edda956e4af0e0acf167138..1c355cdf8db4e9fed61a4aabf61a237ad26181ce 100644 --- a/midx-write.c +++ b/midx-write.c @@ -110,6 +110,8 @@ struct write_midx_context { uint32_t num_multi_pack_indexes_before; struct string_list *to_include; + + struct repository *repo; }; static int should_include_pack(const struct write_midx_context *ctx, @@ -154,7 +156,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len, return; ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc); - p = add_packed_git(the_repository, full_path, full_path_len, 0); + p = add_packed_git(ctx->repo, full_path, full_path_len, 0); if (!p) { warning(_("failed to add packfile '%s'"), full_path); @@ -480,7 +482,7 @@ static int write_midx_oid_lookup(struct hashfile *f, void *data) { struct write_midx_context *ctx = data; - unsigned char hash_len = the_hash_algo->rawsz; + unsigned char hash_len = ctx->repo->hash_algo->rawsz; struct pack_midx_entry *list = ctx->entries; uint32_t i; @@ -605,7 +607,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx) uint32_t *pack_order, base_objects = 0; uint32_t i; - trace2_region_enter("midx", "midx_pack_order", the_repository); + trace2_region_enter("midx", "midx_pack_order", ctx->repo); if (ctx->incremental && ctx->base_midx) base_objects = ctx->base_midx->num_objects + @@ -640,7 +642,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx) } free(data); - trace2_region_leave("midx", "midx_pack_order", the_repository); + trace2_region_leave("midx", "midx_pack_order", ctx->repo); return pack_order; } @@ -651,9 +653,10 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash, struct strbuf buf = STRBUF_INIT; char *tmp_file; - trace2_region_enter("midx", "write_midx_reverse_index", the_repository); + trace2_region_enter("midx", "write_midx_reverse_index", ctx->repo); - strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex(midx_hash)); + strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex_algop(midx_hash, + ctx->repo->hash_algo)); tmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr, midx_hash, WRITE_REV); @@ -664,7 +667,7 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash, strbuf_release(&buf); free(tmp_file); - trace2_region_leave("midx", "write_midx_reverse_index", the_repository); + trace2_region_leave("midx", "write_midx_reverse_index", ctx->repo); } static void prepare_midx_packing_data(struct packing_data *pdata, @@ -672,10 +675,10 @@ static void prepare_midx_packing_data(struct packing_data *pdata, { uint32_t i; - trace2_region_enter("midx", "prepare_midx_packing_data", the_repository); + trace2_region_enter("midx", "prepare_midx_packing_data", ctx->repo); memset(pdata, 0, sizeof(struct packing_data)); - prepare_packing_data(the_repository, pdata); + prepare_packing_data(ctx->repo, pdata); for (i = 0; i < ctx->entries_nr; i++) { uint32_t pos = ctx->pack_order[i]; @@ -686,7 +689,7 @@ static void prepare_midx_packing_data(struct packing_data *pdata, ctx->info[ctx->pack_perm[from->pack_int_id]].p); } - trace2_region_leave("midx", "prepare_midx_packing_data", the_repository); + trace2_region_leave("midx", "prepare_midx_packing_data", ctx->repo); } static int add_ref_to_pending(const char *refname, const char *referent UNUSED, @@ -784,17 +787,16 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr struct rev_info revs; struct bitmap_commit_cb cb = {0}; - trace2_region_enter("midx", "find_commits_for_midx_bitmap", - the_repository); + trace2_region_enter("midx", "find_commits_for_midx_bitmap", ctx->repo); cb.ctx = ctx; - repo_init_revisions(the_repository, &revs, NULL); + repo_init_revisions(ctx->repo, &revs, NULL); if (refs_snapshot) { read_refs_snapshot(refs_snapshot, &revs); } else { setup_revisions(0, NULL, &revs, NULL); - refs_for_each_ref(get_main_ref_store(the_repository), + refs_for_each_ref(get_main_ref_store(ctx->repo), add_ref_to_pending, &revs); } @@ -822,8 +824,7 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr release_revisions(&revs); - trace2_region_leave("midx", "find_commits_for_midx_bitmap", - the_repository); + trace2_region_leave("midx", "find_commits_for_midx_bitmap", ctx->repo); return cb.commits; } @@ -945,7 +946,7 @@ static int fill_packs_from_midx(struct write_midx_context *ctx, */ if (flags & MIDX_WRITE_REV_INDEX || preferred_pack_name) { - if (prepare_midx_pack(the_repository, m, + if (prepare_midx_pack(ctx->repo, m, m->num_packs_in_base + i)) { error(_("could not load pack")); return 1; @@ -1073,6 +1074,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir, trace2_region_enter("midx", "write_midx_internal", r); + ctx.repo = r; ctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL); if (ctx.incremental && (flags & MIDX_WRITE_BITMAP)) @@ -1469,7 +1471,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir, } if (ctx.m || ctx.base_midx) - close_object_store(the_repository->objects); + close_object_store(ctx.repo->objects); if (commit_lock_file(&lk) < 0) die_errno(_("could not write multi-pack-index")); From patchwork Tue Nov 19 15:36:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13880144 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91FE01D0B9B for ; Tue, 19 Nov 2024 15:37:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030626; cv=none; b=Zye4rL53wEZtgpEpfpDBxyvldJ73PhduPfCmV8MoxOo2cAQ4KYimdf5NkW8X87B30v1rYBsViC6fR9HtINkn4HywAsqFI/UpV50sV0qCbgSLJxfHOR3NwkzLUvHaeCjzOAwWuKsSLGhRKKJIMRmk7qyDN/QkShJGMFN+/w85Zf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030626; c=relaxed/simple; bh=4FGXJhrae13n8KrE5hoTfISREt6HbuuOZXqk7YgyJhw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KawvYXAtKZcc4AjFOXkuBozgc/4eLRUow4Tsv/1WjV80Ft5XFHNfVOWpChIXYbqXjcJqouYAVgTGInkTmKzEv0AXApl1FrZpAcK2ZKYkfH5Ze3/Fqw46Lv7KjC+BiGgxMpnSqIXkzHIK0qL9o8GgmDdy1iYM1K7omk0DUndwqFQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HsKfLCfD; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HsKfLCfD" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5cfc19065ffso1222263a12.3 for ; Tue, 19 Nov 2024 07:37:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732030623; x=1732635423; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=eSVcWDgZyHlNFFEtLuqEKQITPLwP2nkZyjPt23yFoBA=; b=HsKfLCfDXqSGNeH9BqBtCjEYtbLu7czGYTY9COg2YxGDSh7+KBprGoMQKyNuVkYJ/y pSO8Y9qOSOoUnwUU4AMYEHi+oVbtgbVr8BPfaklXWKhRpXdstOFCCEjbsbqktYgehxor TqUeDqMq6PrXRMtL58nybSEwJCMekrixaCapVX4VUoCzDHcKAvYFN87n3XS3bW3QJPJv 6UmiKHwLwHXUgglR0NqktchqLI5+sGN+yZVq/hg6wxBUwzsDXEBbLrk3lRxpt4Vtccr9 uIZRsVRMJa+v6vYcz17zSe1wZ2Howqymi0lV+LHgsR3+MQsvwP92szDZVd5qcs7rCH4I 7+Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732030623; x=1732635423; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eSVcWDgZyHlNFFEtLuqEKQITPLwP2nkZyjPt23yFoBA=; b=Rf0+MhBKpO2ulAv2jC3N3wgGIpVXl4uXGCYu/HcHsJdWqQtVDLnLv5NUtgiC5K7Ixy JeZirUcg2XfyEb4Y1guf3kghFPcWMl4NuHm65ZP5QmRABBfrnk4Pz2IiIiKbAG6TCmTB yU7cuWZJs4SVqE4SXRoH7rjTm9FuLFUxVNRfd30mCly4tJVrC1CKHX/zc3GzuUUyk+U+ cPbM5Ja3b6IB06mLvinB9io+TFf3ogCnIA8D3WcgkYoJ/LN6qdUMYiQvc+5yMQxByUYT KuChViU4ByDb+PoKoDSZI6VW+pQZSHslWqT/vUNR0HMgtzuYX/P6PGQ+vsiDTB/3IB3z KucA== X-Gm-Message-State: AOJu0Yy7Rs317nv8mNXz1ZfnTzOEYzds+sOyIQnVmq9+oYyW+zjiTsP0 hnkzcMVbymRrnxsa2CExfdH0+H+sTXv1CAKP7DT5w3cJZ1jlLJ1REsfHk7ud X-Google-Smtp-Source: AGHT+IGH+jJmDb7UkuZ9FrLBi+0g+LV/hKI0b8vbNNA+TyEiQbXYlhBw6FjQBt2ciz2VnEwCIZHZMg== X-Received: by 2002:a17:907:3d86:b0:a9f:508:5924 with SMTP id a640c23a62f3a-aa483525ef4mr1657315466b.43.1732030622791; Tue, 19 Nov 2024 07:37:02 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df4e7bfsm661900566b.42.2024.11.19.07.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 07:37:02 -0800 (PST) From: Karthik Nayak Date: Tue, 19 Nov 2024 16:36:44 +0100 Subject: [PATCH v2 05/10] midx-write: pass down repository to `write_midx_file[_only]` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-5-e2f607174efc@gmail.com> References: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> In-Reply-To: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, shejialuo@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5314; i=karthik.188@gmail.com; h=from:subject:message-id; bh=4FGXJhrae13n8KrE5hoTfISREt6HbuuOZXqk7YgyJhw=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnPLCYR3x4YxAGVA3+DgYVzCHFwMguEH7WjFaki ltB7Qd8XtOJAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZzywmAAKCRA+1Z8kjkaM f8B4C/4nSWbizeArB8p18kiXrJvf82TN2Zav50FNhMRqo3hc2OHDAuTxEDLnvMnShQhM/8TCOwH wKJmJyS30uE+ciBMOFtviAs7IHLYTby5T0CkGZc94tCQtoow1f44gxBaxILHwMvmySJNYVawQLi mhaOk4Bus2fE4w5+ixtkr4Jc9dhB0oFNS2oCNLP6Lj+gJhV1fGZ8/OEmTmQnMdmsoyP5SoIC5GX g7i5b6JqNcRyfCLNlyLcJaLaudPSEEZwu+ET23KDFYodGWtFqsaNpvqfv8POIxFo9aI/thkMilt 0CaceHtqAtuHzr09GuTiofMov+wEItqba8MKejWjjAskJCq7TToQLga2A1ro0qJkKeA1nLCO8Sx GClGEPUq7xUY2BZaO6S4YSK5Mc5QTLg/lsVEkeLYR3k2sr0CQWM9YDxbzf7g9vIymzxi/03Qk4j wXrM3slgA6GzroOUL3Hd5wVc4J55ILtrR1qsOu2T6UWMEuAPUc48Kp5hpLkKRPdiXqmqY= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F In a previous commit, we passed the repository field to all subcommands in the `builtin/` directory. Utilize this to pass the repository field down to the `write_midx_file[_only]` functions to remove the usage of `the_repository` global variables. With this, all usage of global variables in `midx-write.c` is removed, hence, remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file. Signed-off-by: Karthik Nayak --- builtin/multi-pack-index.c | 6 +++--- builtin/repack.c | 2 +- midx-write.c | 22 +++++++++------------- midx.h | 10 ++++------ 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index 85e40a4b6d3e47e9ec1ec27c094455e5ba75b5b0..2a938466f53aaa11096170554fe11a4ed46a25e4 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -120,7 +120,7 @@ static void read_packs_from_stdin(struct string_list *to) static int cmd_multi_pack_index_write(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { struct option *options; static struct option builtin_multi_pack_index_write_options[] = { @@ -165,7 +165,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv, read_packs_from_stdin(&packs); - ret = write_midx_file_only(opts.object_dir, &packs, + ret = write_midx_file_only(repo, opts.object_dir, &packs, opts.preferred_pack, opts.refs_snapshot, opts.flags); @@ -176,7 +176,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv, } - ret = write_midx_file(opts.object_dir, opts.preferred_pack, + ret = write_midx_file(repo, opts.object_dir, opts.preferred_pack, opts.refs_snapshot, opts.flags); free(opts.refs_snapshot); diff --git a/builtin/repack.c b/builtin/repack.c index 96a4fa234bddfd2b63c8d9733379d9b1012a4014..9c21fc482dfb387c818c0d0a74f781848b5a0953 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -1569,7 +1569,7 @@ int cmd_repack(int argc, unsigned flags = 0; if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0)) flags |= MIDX_WRITE_INCREMENTAL; - write_midx_file(repo_get_object_directory(the_repository), + write_midx_file(the_repository, repo_get_object_directory(the_repository), NULL, NULL, flags); } diff --git a/midx-write.c b/midx-write.c index 1c355cdf8db4e9fed61a4aabf61a237ad26181ce..1bc2f5256916e69924245951f654c1047ffeab84 100644 --- a/midx-write.c +++ b/midx-write.c @@ -1,5 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "abspath.h" #include "config.h" @@ -1505,24 +1503,22 @@ static int write_midx_internal(struct repository *r, const char *object_dir, return result; } -int write_midx_file(const char *object_dir, +int write_midx_file(struct repository *r, const char *object_dir, const char *preferred_pack_name, - const char *refs_snapshot, - unsigned flags) + const char *refs_snapshot, unsigned flags) { - return write_midx_internal(the_repository, object_dir, NULL, NULL, - preferred_pack_name, refs_snapshot, flags); + return write_midx_internal(r, object_dir, NULL, NULL, + preferred_pack_name, refs_snapshot, + flags); } -int write_midx_file_only(const char *object_dir, +int write_midx_file_only(struct repository *r, const char *object_dir, struct string_list *packs_to_include, const char *preferred_pack_name, - const char *refs_snapshot, - unsigned flags) + const char *refs_snapshot, unsigned flags) { - return write_midx_internal(the_repository, object_dir, packs_to_include, - NULL, preferred_pack_name, refs_snapshot, - flags); + return write_midx_internal(r, object_dir, packs_to_include, NULL, + preferred_pack_name, refs_snapshot, flags); } int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags) diff --git a/midx.h b/midx.h index 3b0ac4d8788b373c59fe69ca2d78e9d914702bc0..c37ad5b5242b56d21fd76bd59957a1bdb82786ec 100644 --- a/midx.h +++ b/midx.h @@ -123,15 +123,13 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i * Variant of write_midx_file which writes a MIDX containing only the packs * specified in packs_to_include. */ -int write_midx_file(const char *object_dir, - const char *preferred_pack_name, - const char *refs_snapshot, +int write_midx_file(struct repository *r, const char *object_dir, + const char *preferred_pack_name, const char *refs_snapshot, unsigned flags); -int write_midx_file_only(const char *object_dir, +int write_midx_file_only(struct repository *r, const char *object_dir, struct string_list *packs_to_include, const char *preferred_pack_name, - const char *refs_snapshot, - unsigned flags); + const char *refs_snapshot, unsigned flags); void clear_midx_file(struct repository *r); int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags); int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags); From patchwork Tue Nov 19 15:36:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13880146 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54D861D1514 for ; Tue, 19 Nov 2024 15:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030627; cv=none; b=Yl/BbgZTSrU/29Vxjy5IiA0fzyLN5CFVvz6cvZba2lG5VDiC2/tXPhO5plulruNTvyAkh29wMTP7JhsW8GuvvagOFzWSr47dDDbseb+Rdzeg2/VRE76oWN+VEh01ctOCEIVagLL+K6xHvotCwZ/c7JFPoJkudlvfyFqbFOs0Mbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030627; c=relaxed/simple; bh=hgMcM7RU+5OOznCJFeSrWwbcsDbQEcDGjBTNvWC4fI4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DH3ajkDi2pC069UIVYDAQa+iHbRT6pRJSptNz1/zLLLxTbeJCW/bCHVHk9+swSXOjRecVOcZ2/egiV4v19cRBm++SwbhKEOy+w43OCDreZJzB3LPHT3LKlPx2p/J7hMoIH6cFk4/i6ywySLDjDNjUHeu3+zCRdd8bYd0sHPrpKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=e0mMfhkO; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e0mMfhkO" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-aa3a79d4d59so181786566b.3 for ; Tue, 19 Nov 2024 07:37:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732030623; x=1732635423; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=FNScgfXDNZe14P6alytYLQFb9MHc0hfFQBIXj3QZLl4=; b=e0mMfhkOl57DuucAQh5jlbZb2La/HvrtMMlrVMlQp/l/jktB4k/XdzahXYGTX3fEcn 8ZzOs8RDgoWVLLgnYdk2wu/N2M1gjPlRm5I1ZE25tP+QDIl2kZw04gBmAXgAPCxdPrw0 bMX4Y3Q3Xpaeq8kdEZGDCWpUWYZTVBLMga3YePOePn257ecXTaVNAwVq2WPfh0BNbaRR w9FuKI619nIUn7R6ue1e8bvYTG5rXczuQMzwLPhUGcunHULsQqEwt023oERV2TB5xcnH jAEUWfQyhZOU8NfhbPyiNuKa7QNlzgtSQpXPBl8uR/GnCk0PMHtdTYpbK9+EHocjUFf6 GWuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732030623; x=1732635423; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FNScgfXDNZe14P6alytYLQFb9MHc0hfFQBIXj3QZLl4=; b=FoL7FZ/Ia7FxP2uZqXXwZaj4/Np73smKR8t8YJ7igq9mgdcQdnKS6VK5Vm4UL0mqFe Vx1uAa1sfXCr7K3J/CE9WdRzsTR0EfU4Me6fTfw/whkXiKXudmEMM3kvr9eJff+7dY4j qqkFMoO785BvZxgjB7LR3dF9ZNquj6Vod5bz9rdcSkLTBV1s7kehDCA2S7B3SLIGFpQK 00GMPDgtfRspwp/v6hma9qpAfvqeqhPejXm7esfzhMMF72XM6AiKLIQof7n35rtwl74b 8UpHFw82VdEBzucRKL5wjsuKs+zpnhT7TzQpJzm3tKaAGyuja3lEVJ6mPDzfX79t6pef UV9Q== X-Gm-Message-State: AOJu0YyK+RpIFzxdYxL3hWTIziU+KKYn3qM36RHa7pmyzAlCcH0x3CAg opejyd1nHQACstnwtDEwJzSignmrpI3kxoAmRIkttEqvIVu+iymcwQSFXWmH X-Google-Smtp-Source: AGHT+IHQm6bUO+MuA7ZclFYJwPK1/sf9CCPBpaNiU9rOx3TBUbG/VFjKPFC+yuvhqs8T5o7lY4Ve9Q== X-Received: by 2002:a17:907:2dac:b0:a9a:46:83ee with SMTP id a640c23a62f3a-aa483525d31mr1649668866b.48.1732030623500; Tue, 19 Nov 2024 07:37:03 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df4e7bfsm661900566b.42.2024.11.19.07.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 07:37:03 -0800 (PST) From: Karthik Nayak Date: Tue, 19 Nov 2024 16:36:45 +0100 Subject: [PATCH v2 06/10] midx: cleanup internal usage of `the_repository` and `the_hash_algo` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-6-e2f607174efc@gmail.com> References: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> In-Reply-To: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, shejialuo@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7347; i=karthik.188@gmail.com; h=from:subject:message-id; bh=hgMcM7RU+5OOznCJFeSrWwbcsDbQEcDGjBTNvWC4fI4=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnPLCYERFJCGdauPn+xYHXhkAqSvOmht2m8F596 T9jhrPxpy2JAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZzywmAAKCRA+1Z8kjkaM f5zmDACYhaVCvYGT0DSbbnxMWx/WxIBanYqGfp3Ikmloe6Dz1R1fcZjcQ2qKKxNnzkgROG18H6G ARnDY75igIavUrnvpaBQfJJsaIEZlpRmderbwabYzzs+Rmh3T5Ly1vzckh95qmZ7p0H2sSC4CAC 9vjWTRKENt1tnVewawCqw34PXrwWkPwmEQWS/n0PvFQ6qfGcdz0lel3chhZjXobMYeQquavYacs 1Oxgo3Xbe+p4L+dNA+EyBOR7R3kgxCNb3C3KeQzcT3CrXx4EkFqtX3PD0MlEcJ0MhKeoJkRSwA3 QI3CsWezj0sksoMLktt50PHJ2N5vXvMowrIHemFZoGipOhf74dz3bNrRyGl8gycoTR4nzL+uil3 +SKOrqTwRMTVjQgcpde4gjzvBeucqe7zPeACufCx4FvTo9ZoyYNU6RfQJaaLUCXwcTeUBStdVfG TCCLT3BNQnFrvPi1TdzzuQs+MVyoUpJZo9Bn2x/4/Pz8cH+cES+60ygtSgf4RLVE8lIgc= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F In the `midx.c` file, there are multiple usages of `the_repository` and `the_hash_algo` within static functions of the file. Some of the usages can be simply swapped out with the available `repository` struct. While some of them can be swapped out by passing the repository to the required functions. This leaves out only some other usages of `the_repository` and `the_hash_algo` in the file in non-static functions, which we'll tackle in upcoming commits. Signed-off-by: Karthik Nayak --- midx.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/midx.c b/midx.c index 079c45a1aafb658a7b887ac216cc6ecf5f0fb6ff..6f0fb8285af14843da132ef1b0c3a8bdd06732c9 100644 --- a/midx.c +++ b/midx.c @@ -25,7 +25,7 @@ int cmp_idx_or_pack_name(const char *idx_or_pack_name, const unsigned char *get_midx_checksum(struct multi_pack_index *m) { - return m->data + m->data_len - the_hash_algo->rawsz; + return m->data + m->data_len - m->repo->hash_algo->rawsz; } void get_midx_filename(struct strbuf *out, const char *object_dir) @@ -94,7 +94,8 @@ static int midx_read_object_offsets(const unsigned char *chunk_start, #define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz) -static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir, +static struct multi_pack_index *load_multi_pack_index_one(struct repository *r, + const char *object_dir, const char *midx_name, int local) { @@ -131,7 +132,7 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir m->data = midx_map; m->data_len = midx_size; m->local = local; - m->repo = the_repository; + m->repo = r; m->signature = get_be32(m->data); if (m->signature != MIDX_SIGNATURE) @@ -144,12 +145,12 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir m->version); hash_version = m->data[MIDX_BYTE_HASH_VERSION]; - if (hash_version != oid_version(the_hash_algo)) { + if (hash_version != oid_version(r->hash_algo)) { error(_("multi-pack-index hash version %u does not match version %u"), - hash_version, oid_version(the_hash_algo)); + hash_version, oid_version(r->hash_algo)); goto cleanup_fail; } - m->hash_len = the_hash_algo->rawsz; + m->hash_len = r->hash_algo->rawsz; m->num_chunks = m->data[MIDX_BYTE_NUM_CHUNKS]; @@ -206,8 +207,8 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir m->pack_names[i]); } - trace2_data_intmax("midx", the_repository, "load/num_packs", m->num_packs); - trace2_data_intmax("midx", the_repository, "load/num_objects", m->num_objects); + trace2_data_intmax("midx", r, "load/num_packs", m->num_packs); + trace2_data_intmax("midx", r, "load/num_objects", m->num_objects); free_chunkfile(cf); return m; @@ -240,8 +241,9 @@ void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir, strbuf_addf(buf, "/multi-pack-index-%s.%s", hash_to_hex(hash), ext); } -static int open_multi_pack_index_chain(const char *chain_file, - int *fd, struct stat *st) +static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo, + const char *chain_file, int *fd, + struct stat *st) { *fd = git_open(chain_file); if (*fd < 0) @@ -250,7 +252,7 @@ static int open_multi_pack_index_chain(const char *chain_file, close(*fd); return 0; } - if (st->st_size < the_hash_algo->hexsz) { + if (st->st_size < hash_algo->hexsz) { close(*fd); if (!st->st_size) { /* treat empty files the same as missing */ @@ -292,7 +294,8 @@ static int add_midx_to_chain(struct multi_pack_index *midx, return 1; } -static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir, +static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r, + const char *object_dir, int local, int fd, struct stat *st, int *incomplete_chain) @@ -303,7 +306,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir, uint32_t i, count; FILE *fp = xfdopen(fd, "r"); - count = st->st_size / (the_hash_algo->hexsz + 1); + count = st->st_size / (r->hash_algo->hexsz + 1); for (i = 0; i < count; i++) { struct multi_pack_index *m; @@ -312,7 +315,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir, if (strbuf_getline_lf(&buf, fp) == EOF) break; - if (get_oid_hex(buf.buf, &layer)) { + if (get_oid_hex_algop(buf.buf, &layer, r->hash_algo)) { warning(_("invalid multi-pack-index chain: line '%s' " "not a hash"), buf.buf); @@ -325,7 +328,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir, strbuf_reset(&buf); get_split_midx_filename_ext(&buf, object_dir, layer.hash, MIDX_EXT_MIDX); - m = load_multi_pack_index_one(object_dir, buf.buf, local); + m = load_multi_pack_index_one(r, object_dir, buf.buf, local); if (m) { if (add_midx_to_chain(m, midx_chain)) { @@ -348,7 +351,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir, return midx_chain; } -static struct multi_pack_index *load_multi_pack_index_chain(const char *object_dir, +static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r, + const char *object_dir, int local) { struct strbuf chain_file = STRBUF_INIT; @@ -357,10 +361,10 @@ static struct multi_pack_index *load_multi_pack_index_chain(const char *object_d struct multi_pack_index *m = NULL; get_midx_chain_filename(&chain_file, object_dir); - if (open_multi_pack_index_chain(chain_file.buf, &fd, &st)) { + if (open_multi_pack_index_chain(r->hash_algo, chain_file.buf, &fd, &st)) { int incomplete; /* ownership of fd is taken over by load function */ - m = load_midx_chain_fd_st(object_dir, local, fd, &st, + m = load_midx_chain_fd_st(r, object_dir, local, fd, &st, &incomplete); } @@ -376,9 +380,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, get_midx_filename(&midx_name, object_dir); - m = load_multi_pack_index_one(object_dir, midx_name.buf, local); + m = load_multi_pack_index_one(the_repository, object_dir, + midx_name.buf, local); if (!m) - m = load_multi_pack_index_chain(object_dir, local); + m = load_multi_pack_index_chain(the_repository, object_dir, local); strbuf_release(&midx_name); @@ -520,7 +525,7 @@ int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result) { int ret = bsearch_hash(oid->hash, m->chunk_oid_fanout, - m->chunk_oid_lookup, the_hash_algo->rawsz, + m->chunk_oid_lookup, m->repo->hash_algo->rawsz, result); if (result) *result += m->num_objects_in_base; @@ -551,7 +556,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid, n = midx_for_object(&m, n); oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n), - the_repository->hash_algo); + m->repo->hash_algo); return oid; } From patchwork Tue Nov 19 15:36:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13880147 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CA6F1D04B9 for ; Tue, 19 Nov 2024 15:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030628; cv=none; b=TS3S21XR0yGOnfHQEI8emQxXe+uO6lBoNYQX6Vs1ROu7bw1hxcTzhliosgzybcOmV08OV9bIXNp6m2Pjo5/Cf0AxZKRkaw8ZxYQX0yWRembQkeG8VtkHTMUCKBKaUQCpr7BGwgab9cDjSgn/fUH9lPdTB/w7AXMw+/LWc1/8KwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030628; c=relaxed/simple; bh=0Bk49L3zNr0ivHPQSUglzSBLCsWe699RCqd9yH/88sE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sAJButhJaA7Sq92KGpGdbEis3Cq13hTwdC5IsDOHkbpcWkOitHbvpJMVDRU7Y/F6h90zNg3hU9X20GuPg4d/+eq/+LVwBV8vaM7VMYxGDTZtLxNM9+Xu50aau1RGCm6tKHb/ZWmfp8JqRuMqOtzjOHCnmryCSn/BtX6w5EFJ0OE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LsKzSY8o; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LsKzSY8o" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-53d9ff92ee9so1452429e87.1 for ; Tue, 19 Nov 2024 07:37:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732030624; x=1732635424; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=PwG+HR2FAYkztAibkKtJ+EnXujqMAqHiNNdLjV8Qy4I=; b=LsKzSY8oqBUzf2BE8gjGDoQfaauzm2bpqVb2HX/AXzEQhsM1xV1mTUNm+T4A+GwTnz 6rns8XWI7OFq25gEZkOvR/O+Hz+1aCiEWMw4X5tOpoKgz0r1dR/H3tfgjJHxEC6ujtbz Jyuh+uE0b4d42P91La8cjmYqtSAuHnfeVxsE48vwct9wKVsTmiAlT2uDbucmufDRn2DZ L3CkNDWiigoX7fndU8I6VB7IJcLm7Gbkl8CkjmgKH416r+6vx1kjPYWViw9mJCFf0EqZ 25fFoUEnEKpzb6IyMAvqmlemo04/CAbfy6LX0+uSjEU0hcloTtDzZofLj/r3EI/7vOyU Jglg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732030624; x=1732635424; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PwG+HR2FAYkztAibkKtJ+EnXujqMAqHiNNdLjV8Qy4I=; b=C7i1wI6sSUlovFWVrJaK6/yM4Lr7Vj3OC4XaI/nPJN7xKtTzg4x8NA+8ozTnKdIkA8 iqKiukcDL07o8Oc35V/f2OgNMgB5jlW34p1FyukX2UB2Os7+srrYiKCaFGEfIYfs9N0q 8I8YG3j4+K79Y7GwG57FJ8VNxBxtfgd7Z2ll2yJX5D5aac8fGB5xaec5G2D8szQCnk9H kaacGa31TjIWSwYIdMr/3XFRCWUi0ev56y8u42H0gF3+pnhX3x3iqgKprE5ayOIaFq8b eAyggI7UmQ1S56mSePBbkev4NK+uy3Vi3l03mgb3ePrGyYGQS/b0cPF4GhEHMsMzQoj1 RkkA== X-Gm-Message-State: AOJu0Yy4s+kEvAvCO3N8uvoxeSJ6AB/nn8cCJwTfXtrgDky9iz/DCe3P Y0I6JdRfr3KIlV0pjQByP9KXuKiaNL+MBhSWSdDQ/nOksg9MK/Rj X-Google-Smtp-Source: AGHT+IGyD6Sg2L6vILtDxv7UsW/1NT+LFcpsBtmZOkGcKul+Qxx3pINNVPyoaIm2DBJ1/Inp9UD4Iw== X-Received: by 2002:a05:6512:1307:b0:539:f675:84d7 with SMTP id 2adb3069b0e04-53dab2a84bfmr9086851e87.32.1732030624327; Tue, 19 Nov 2024 07:37:04 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df4e7bfsm661900566b.42.2024.11.19.07.37.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 07:37:03 -0800 (PST) From: Karthik Nayak Date: Tue, 19 Nov 2024 16:36:46 +0100 Subject: [PATCH v2 07/10] midx: pass `repository` to `load_multi_pack_index` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-7-e2f607174efc@gmail.com> References: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> In-Reply-To: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, shejialuo@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4558; i=karthik.188@gmail.com; h=from:subject:message-id; bh=0Bk49L3zNr0ivHPQSUglzSBLCsWe699RCqd9yH/88sE=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnPLCYKeWoKBiPgszYPpKsxSYFWr+xvoDbJYO7X O4oDGtV9g6JAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZzywmAAKCRA+1Z8kjkaM f6Z+C/93B9uuDZPo1JeQ1wkEpENigo/1hEmrPbKSol/+r5U3BSAyTkqQHVSw05zZaV2KKDjVRDu k3yokiTusK3+4J/PN2q+exw5YoNxY+axCoXO6WyAA4SMYd6Y3O8IEUUfo3YgC5PVznachEPXUQL h+hoeGR4UXeSBxiJDtE2gMQlIJzEiPe0DlD/KZosxOMhYrNUZ8qr7GTz3N9RZQq3VCRQ8d1iM0Z jQnMfZGaloFEadZAhzeFimPFmXOIDL79PzvdIxpIEXqAlaIWRmrkINiw/OGxs4aoJwcu7VBfANL zf4NfpBm4g2EowAnvc8Hcr3dlE3cHTD+RzyMF/z6PoNsnXJlq2Dfhe0bI6rxKF/hkM4FRKa4hqN yRbwpqkwaSMT8rAWP4MhvBKtfVltS1Z8GOAcx0XwzyUb7BQUC/RWVMdIAnIFdbiq/Rl4v88I7N+ XDifhW2C1jVbd6Fn7iO4HkocoaumwqGoahwn5DPFtJHToZmMpNMt2FYQRdONwpYwnnP1A= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The `load_multi_pack_index` function in midx uses `the_repository` variable to access the `repository` struct. Modify the function and its callee's to send the `repository` field. This moves usage of `the_repository` to the `test-read-midx.c` file. While that is not optimal, it is okay, since the upcoming commits will slowly move the usage of `the_repository` up the layers and remove it eventually. Signed-off-by: Karthik Nayak --- midx.c | 11 ++++++----- midx.h | 4 +++- t/helper/test-read-midx.c | 8 ++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/midx.c b/midx.c index 6f0fb8285af14843da132ef1b0c3a8bdd06732c9..98ee84d4a8bf388906634ad695ff39acdaa2c6d5 100644 --- a/midx.c +++ b/midx.c @@ -372,7 +372,8 @@ static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r return m; } -struct multi_pack_index *load_multi_pack_index(const char *object_dir, +struct multi_pack_index *load_multi_pack_index(struct repository *r, + const char *object_dir, int local) { struct strbuf midx_name = STRBUF_INIT; @@ -380,10 +381,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, get_midx_filename(&midx_name, object_dir); - m = load_multi_pack_index_one(the_repository, object_dir, + m = load_multi_pack_index_one(r, object_dir, midx_name.buf, local); if (!m) - m = load_multi_pack_index_chain(the_repository, object_dir, local); + m = load_multi_pack_index_chain(r, object_dir, local); strbuf_release(&midx_name); @@ -727,7 +728,7 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i if (!strcmp(object_dir, m_search->object_dir)) return 1; - m = load_multi_pack_index(object_dir, local); + m = load_multi_pack_index(r, object_dir, local); if (m) { struct multi_pack_index *mp = r->objects->multi_pack_index; @@ -881,7 +882,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag struct pair_pos_vs_id *pairs = NULL; uint32_t i; struct progress *progress = NULL; - struct multi_pack_index *m = load_multi_pack_index(object_dir, 1); + struct multi_pack_index *m = load_multi_pack_index(r, object_dir, 1); struct multi_pack_index *curr; verify_midx_error = 0; diff --git a/midx.h b/midx.h index c37ad5b5242b56d21fd76bd59957a1bdb82786ec..78efa28d35371795fa33c68660278182debb60ab 100644 --- a/midx.h +++ b/midx.h @@ -97,7 +97,9 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir); void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir, const unsigned char *hash, const char *ext); -struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local); +struct multi_pack_index *load_multi_pack_index(struct repository *r, + const char *object_dir, + int local); int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id); struct packed_git *nth_midxed_pack(struct multi_pack_index *m, uint32_t pack_int_id); diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c index 438fb9fc6197fc465f79d9a65b719ae315fed373..fc632369618917e2d8cdcb77bd9073c61e1544c1 100644 --- a/t/helper/test-read-midx.c +++ b/t/helper/test-read-midx.c @@ -18,7 +18,7 @@ static int read_midx_file(const char *object_dir, const char *checksum, struct multi_pack_index *m; setup_git_directory(); - m = load_multi_pack_index(object_dir, 1); + m = load_multi_pack_index(the_repository, object_dir, 1); if (!m) return 1; @@ -82,7 +82,7 @@ static int read_midx_checksum(const char *object_dir) struct multi_pack_index *m; setup_git_directory(); - m = load_multi_pack_index(object_dir, 1); + m = load_multi_pack_index(the_repository, object_dir, 1); if (!m) return 1; printf("%s\n", hash_to_hex(get_midx_checksum(m))); @@ -98,7 +98,7 @@ static int read_midx_preferred_pack(const char *object_dir) setup_git_directory(); - midx = load_multi_pack_index(object_dir, 1); + midx = load_multi_pack_index(the_repository, object_dir, 1); if (!midx) return 1; @@ -121,7 +121,7 @@ static int read_midx_bitmapped_packs(const char *object_dir) setup_git_directory(); - midx = load_multi_pack_index(object_dir, 1); + midx = load_multi_pack_index(the_repository, object_dir, 1); if (!midx) return 1; From patchwork Tue Nov 19 15:36:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13880148 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7FD31D042D for ; Tue, 19 Nov 2024 15:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030628; cv=none; b=uSXOjMgHwmiM3rvqP3G0C9PgP8gAj6d7kylQCeui3qSAUzmiszyTUdNLRNDl1Ma4N6pTK1KcE9JHB+MLKusdtGyLhlC2KK9SpePmirdLJHmpL55E1ujyIwjJ1YoNV2vQKCo7sDU3Qwazy9/zCu0wIHOBFWaVuIz2bpV9Aw1JRxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030628; c=relaxed/simple; bh=nvMdXLRFqIklwPwvUKKFJCAc1KDQnhCh9LXOQ42dykU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FgzGFs3ravlpOhcdgZu/+F252nJq4RToFlOXXarxB2CdwP+Jcar8OqLuRC4qvk6/ISJkmivZBdrajYdIDpqrxyma3JfpUofAAHMZjSNT/qICTy7Q5nX5vwBBwsjs5HoMrZJKnfwldoQD3ZzThO4qt5Q1JePjjBXiNWWyUWapwPQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H0bs4u7f; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H0bs4u7f" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a9e8522445dso548505566b.1 for ; Tue, 19 Nov 2024 07:37:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732030625; x=1732635425; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QONasBt7Lh9rZxjHgidwnq6zhlpab2XHkPCYDl4vQAA=; b=H0bs4u7f7mWpSckDPLdkG6zMC4ZXgfsIi/wiOYM6MGSdUajIApcV5436DjgscHotkF OoWOH2XJMKUJg8bRrwhBta2fdKhTu+YuiNNiC3jCVbOyA5NuiVCGfMGswqYa+WpXLK+3 tRFXEL+Z27gxjM+K/OeGnpwl/tiXf9M7ACf/Rw9PKBgit69w0mNtMWYlPeExBvRTqPpy npTxI2fE9h/+hjnPFkRvFmWGsKWz5510qZqrMGHhwjR3tEo7ziEEb2F2oYvhRa/3GEXz o++zmsC8fIkXPyBy9JAVYXpzoxM8u8qoeCoPuzeY82ltRPkisvRXRqCo3lvb3XxKptjG dDAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732030625; x=1732635425; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QONasBt7Lh9rZxjHgidwnq6zhlpab2XHkPCYDl4vQAA=; b=jqOOVMtV5DdXkkwO5ePU9NnY0Z7jKJdFtv3zPdu0W2IfOx/9aI6CeUz8XRIk3NL5ob 3b6EcyayHaWAA1a4mOzJG/oGgXNF4L0/s+Zm3m5NqP0TlDcCdjEJMdujV/OoZ1WiJjPc ILbvi6FUUsr+f8oIPV1ye9yEN+EB1rx/Bm74vp1GF5enDqEXvKrsMtQAu3HOBa8+XSmg CmYtucX/jPhAiZk34C0vzZoF6zwZunssGFqpqto1mkAgRh6sd5ECY/cce7SnHTBZ+gI2 VgvulIrp9rSXgBlCnA2i40LNKKn78RQ7JBX1TZKEWbtCfcBRavVgEWd1ncmYa5yxrnDE rpRw== X-Gm-Message-State: AOJu0YyNcWwP8BSDFzQrDAPRioZPLovvAXlHz6zN4Ms8QQS/Ea5M+rB/ yMos1cpjDL/iPlJf/eK9SGiwwZ/JoI+gL8tx+trYgVtFaQGLSgLJ461RrZMc X-Google-Smtp-Source: AGHT+IEP7nnkJ/Bb/5p6fBYiUbCXW1d/sXEYwKDcYFd8mZts+6THi6npCQ152cELV/znDPnMv/pqqg== X-Received: by 2002:a17:906:f588:b0:aa1:e60e:6fe7 with SMTP id a640c23a62f3a-aa4833f6579mr1636134466b.11.1732030625114; Tue, 19 Nov 2024 07:37:05 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df4e7bfsm661900566b.42.2024.11.19.07.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 07:37:04 -0800 (PST) From: Karthik Nayak Date: Tue, 19 Nov 2024 16:36:47 +0100 Subject: [PATCH v2 08/10] midx: pass down `hash_algo` to `get_midx_filename[_ext]` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-8-e2f607174efc@gmail.com> References: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> In-Reply-To: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, shejialuo@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7687; i=karthik.188@gmail.com; h=from:subject:message-id; bh=nvMdXLRFqIklwPwvUKKFJCAc1KDQnhCh9LXOQ42dykU=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnPLCYTB/EvN/bwgnXZ7bjwIDlA6HO0RZPi/z/J DrZDixWOmSJAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZzywmAAKCRA+1Z8kjkaM f6xODACLrM2e7AHqwGI1ahzrwmp3fZU+tjh3P7PzdO/77MkochS7QFRCGFtGr3+IIfayI9nFHpc kvZmsFclVDoIYszFBjwF6zwZ+uOiLUUlfX/znWc1I8pEOIfxYeDHVEC/fhkUkwZTBSzRD7SeaHm fyaJFQ9Vc60hWBrDfbacel+mGMYCVRd9LNKqNiVOhHNs3pjKohBnwt/ka00r0ZBCAJqPPERYFap y6pwiEtmmkUZsjKe+x+oeJ3xji7gynQx4hLj0TVOOUmPxJce0dYhVRTIXs5AYbcRjQPeygBOCFg DWu75l/CetbB1N1IehYkDOQx7S/D0H+H94guQiZDQz8bIwFHmn/ZwY6nwGvBZSfZQKpa1eJQ3lY 8gNcXjv4UPcZqVqH59DVjNEnwWbR4NRoHdlFpHM+RTUqUoZxnsxU6ihp32RNr/VPeWERhQfitSe 1WMFWE3JWc7qSTabsixdmhl2SBbxVng8ql0PuKAN+nC0dMGnmiLTEzqHVgUtL6rZjLb+U= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The function `get_midx_filename_ext` uses `hash_to_hex` which internally uses the global variable `the_repository`. To remove this dependency, pass down the `hash_algo` to both `get_midx_filename` and `get_midx_filename_ext`. This adds `the_repository` variable usage to `midx-write.c`, which will be resolved in a future commit. Signed-off-by: Karthik Nayak --- midx-write.c | 15 +++++++-------- midx.c | 16 +++++++++------- midx.h | 7 +++++-- pack-bitmap.c | 6 +++--- pack-revindex.c | 2 +- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/midx-write.c b/midx-write.c index 1bc2f5256916e69924245951f654c1047ffeab84..2f0c09211282fa651af8f9a342f0564729468306 100644 --- a/midx-write.c +++ b/midx-write.c @@ -991,8 +991,8 @@ static int link_midx_to_chain(struct multi_pack_index *m) for (i = 0; i < ARRAY_SIZE(midx_exts); i++) { const unsigned char *hash = get_midx_checksum(m); - get_midx_filename_ext(&from, m->object_dir, hash, - midx_exts[i].non_split); + get_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir, + hash, midx_exts[i].non_split); get_split_midx_filename_ext(&to, m->object_dir, hash, midx_exts[i].split); @@ -1012,9 +1012,8 @@ static int link_midx_to_chain(struct multi_pack_index *m) return ret; } -static void clear_midx_files(const char *object_dir, - const char **hashes, - uint32_t hashes_nr, +static void clear_midx_files(struct repository *r, const char *object_dir, + const char **hashes, uint32_t hashes_nr, unsigned incremental) { /* @@ -1039,7 +1038,7 @@ static void clear_midx_files(const char *object_dir, } if (incremental) - get_midx_filename(&buf, object_dir); + get_midx_filename(r->hash_algo, &buf, object_dir); else get_midx_chain_filename(&buf, object_dir); @@ -1083,7 +1082,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir, "%s/pack/multi-pack-index.d/tmp_midx_XXXXXX", object_dir); else - get_midx_filename(&midx_name, object_dir); + get_midx_filename(r->hash_algo, &midx_name, object_dir); if (safe_create_leading_directories(midx_name.buf)) die_errno(_("unable to create leading directories of %s"), midx_name.buf); @@ -1474,7 +1473,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir, if (commit_lock_file(&lk) < 0) die_errno(_("could not write multi-pack-index")); - clear_midx_files(object_dir, keep_hashes, + clear_midx_files(r, object_dir, keep_hashes, ctx.num_multi_pack_indexes_before + 1, ctx.incremental); diff --git a/midx.c b/midx.c index 98ee84d4a8bf388906634ad695ff39acdaa2c6d5..9bed4185ff4d44602aedfe0329dd840ff9e85435 100644 --- a/midx.c +++ b/midx.c @@ -28,17 +28,19 @@ const unsigned char *get_midx_checksum(struct multi_pack_index *m) return m->data + m->data_len - m->repo->hash_algo->rawsz; } -void get_midx_filename(struct strbuf *out, const char *object_dir) +void get_midx_filename(const struct git_hash_algo *hash_algo, + struct strbuf *out, const char *object_dir) { - get_midx_filename_ext(out, object_dir, NULL, NULL); + get_midx_filename_ext(hash_algo, out, object_dir, NULL, NULL); } -void get_midx_filename_ext(struct strbuf *out, const char *object_dir, +void get_midx_filename_ext(const struct git_hash_algo *hash_algo, + struct strbuf *out, const char *object_dir, const unsigned char *hash, const char *ext) { strbuf_addf(out, "%s/pack/multi-pack-index", object_dir); if (ext) - strbuf_addf(out, "-%s.%s", hash_to_hex(hash), ext); + strbuf_addf(out, "-%s.%s", hash_to_hex_algop(hash, hash_algo), ext); } static int midx_read_oid_fanout(const unsigned char *chunk_start, @@ -379,7 +381,7 @@ struct multi_pack_index *load_multi_pack_index(struct repository *r, struct strbuf midx_name = STRBUF_INIT; struct multi_pack_index *m; - get_midx_filename(&midx_name, object_dir); + get_midx_filename(r->hash_algo, &midx_name, object_dir); m = load_multi_pack_index_one(r, object_dir, midx_name.buf, local); @@ -822,7 +824,7 @@ void clear_midx_file(struct repository *r) { struct strbuf midx = STRBUF_INIT; - get_midx_filename(&midx, r->objects->odb->path); + get_midx_filename(r->hash_algo, &midx, r->objects->odb->path); if (r->objects && r->objects->multi_pack_index) { close_midx(r->objects->multi_pack_index); @@ -891,7 +893,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag struct stat sb; struct strbuf filename = STRBUF_INIT; - get_midx_filename(&filename, object_dir); + get_midx_filename(r->hash_algo, &filename, object_dir); if (!stat(filename.buf, &sb)) { error(_("multi-pack-index file exists, but failed to parse")); diff --git a/midx.h b/midx.h index 78efa28d35371795fa33c68660278182debb60ab..7620820d4d0272926af9e4eeb68bfb73404c7ec2 100644 --- a/midx.h +++ b/midx.h @@ -7,6 +7,7 @@ struct object_id; struct pack_entry; struct repository; struct bitmapped_pack; +struct git_hash_algo; #define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */ #define MIDX_VERSION 1 @@ -89,8 +90,10 @@ struct multi_pack_index { #define MIDX_EXT_MIDX "midx" const unsigned char *get_midx_checksum(struct multi_pack_index *m); -void get_midx_filename(struct strbuf *out, const char *object_dir); -void get_midx_filename_ext(struct strbuf *out, const char *object_dir, +void get_midx_filename(const struct git_hash_algo *hash_algo, + struct strbuf *out, const char *object_dir); +void get_midx_filename_ext(const struct git_hash_algo *hash_algo, + struct strbuf *out, const char *object_dir, const unsigned char *hash, const char *ext); void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir); void get_midx_chain_filename(struct strbuf *buf, const char *object_dir); diff --git a/pack-bitmap.c b/pack-bitmap.c index 0cb1b56c9d5a55936ba53e2ff904ffe46cdcbafc..7b62d099cab5729a60a36b3ad15276fdc351aa97 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -375,8 +375,8 @@ static int load_bitmap_entries_v1(struct bitmap_index *index) char *midx_bitmap_filename(struct multi_pack_index *midx) { struct strbuf buf = STRBUF_INIT; - get_midx_filename_ext(&buf, midx->object_dir, get_midx_checksum(midx), - MIDX_EXT_BITMAP); + get_midx_filename_ext(midx->repo->hash_algo, &buf, midx->object_dir, + get_midx_checksum(midx), MIDX_EXT_BITMAP); return strbuf_detach(&buf, NULL); } @@ -415,7 +415,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git, if (bitmap_git->pack || bitmap_git->midx) { struct strbuf buf = STRBUF_INIT; - get_midx_filename(&buf, midx->object_dir); + get_midx_filename(midx->repo->hash_algo, &buf, midx->object_dir); trace2_data_string("bitmap", bitmap_repo(bitmap_git), "ignoring extra midx bitmap file", buf.buf); close(fd); diff --git a/pack-revindex.c b/pack-revindex.c index 22d3c2346488de6279b6f26a69fe611106c1365a..d3832478d99edffae17db0bbe85aa981c1a3ad30 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -383,7 +383,7 @@ int load_midx_revindex(struct multi_pack_index *m) trace2_data_string("load_midx_revindex", the_repository, "source", "rev"); - get_midx_filename_ext(&revindex_name, m->object_dir, + get_midx_filename_ext(m->repo->hash_algo, &revindex_name, m->object_dir, get_midx_checksum(m), MIDX_EXT_REV); ret = load_revindex_from_disk(revindex_name.buf, From patchwork Tue Nov 19 15:36:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13880192 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25A151D1305 for ; Tue, 19 Nov 2024 15:43:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732031004; cv=none; b=bltM5NUCmZgVaGhTHvzJFyPrb8cXi6oTHP70NMsM+AqPiFyFzX464HOauMpCOPT8PtCVC7zrwof8WwtTmzPREhm2AfuooG613IftTAcRNius7Oy56MrD4ZAl/7Z8z81aNvcX2g8Pfv7hqfKojbr3wIXilwZ9/RXWBd+YHl8NVFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732031004; c=relaxed/simple; bh=HxDtD8DknHPW8DXYsfgyPUUfTpU4z8NEOgyKhiksB8c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nGrIFvX2FxlemUfsJ1hZmmaE9F1I4Iy8d5WAHWvXVg8q5eCCKlDedQlGgg430TJS+5zTHoTRrDfAdIkcLEUePOr7SzXX0qv988NT4vIbi6Ur25yvG0OLGbzcjqStS2+dkA2zUJGOcuVC6SXjZlKgpxcELk1T1lJ0GGUFIDaZcJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KBjWrpla; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KBjWrpla" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5cfcf4df87aso2757564a12.1 for ; Tue, 19 Nov 2024 07:43:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732031001; x=1732635801; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Jpwe/28YZXBUxqjGOJAHRbt+/JfyYzxrWftlOOkswNo=; b=KBjWrplaA5y9SwAljXIR1a1aXdBhPl3gQOC184dA3OzIPGyfp5TFqvjzfkj0G5t7DK Wc+jpZdMZMfnh9B+E7Au6CblsAhfnboLXwWR7aFdFD2FdIJLf/KGoLg9V0W6nDVsTH56 sC+NMm5ryr5BLrczEWlrh9zIXZM/T/f4qu+BknOJQUyw0ys/j3f8xCAHK5LNov6HYj/O eKbO+O9LKI+8DHQY8EEdNm+FgBXgE0LhcCbPM2IYg2G97U86Lp+456oG09Bd1jcqv9Ww AGM9YmtoCJ60veSZc+XTwKVYBZCIWtcM9q0V3ZtoKrInFmred/aOFwu0msvA5YWJOVPC lBiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732031001; x=1732635801; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jpwe/28YZXBUxqjGOJAHRbt+/JfyYzxrWftlOOkswNo=; b=n91xAoW61FLY19cZD5vBOLB2bekuwkv85Y+pru4hTbcL0W30RNwSTjl6yxJjIja1lo YNqBMJyj6dvHJPxIGRQBh7+GyOle8lKA/dfMAEyHjD/4mHW2VT7RBfmZmzSY2ArrZMt2 M+ilD9jVpY7r+Wj7owVnbDsX/zJOBbbgNuWSAdNgDSOFX8xbhxWAjDsSHEIRiQG3/gFS DZB6s2nMR8vQRJC3u904EmN96V+ern+QLHl7JKkLz27hPWNr3lDum3FL8boEC6CsklZR GIRvTjE0pzn+k3kj8bobPuAJnb+QALxCCtAmmGmh0E7oARkywfTlcT/5NnW0ettuZWwz gj2g== X-Gm-Message-State: AOJu0Yx0WKy0Pjqj+OJQkbU4vquIF1VXTgl7eM06GySn3ET+ja2Hl1xX rvRjMFHu60mFHg2UMgjErpB+e2v+qOPGNPPVrp5mhdr6b8VZNRoeC6kP+MkS X-Google-Smtp-Source: AGHT+IEVsMTSUfZxVHHbVvnz4X4vVb9j2xI7JoydCgFBqZ/SeB7Kt2D1BMnmUNcm8LRrVSM7KwJYvA== X-Received: by 2002:a17:907:2d91:b0:a9e:b08e:b02d with SMTP id a640c23a62f3a-aa483412861mr1609434166b.18.1732030626012; Tue, 19 Nov 2024 07:37:06 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df4e7bfsm661900566b.42.2024.11.19.07.37.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 07:37:05 -0800 (PST) From: Karthik Nayak Date: Tue, 19 Nov 2024 16:36:48 +0100 Subject: [PATCH v2 09/10] midx: pass down `hash_algo` to `get_split_midx_filename_ext` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-9-e2f607174efc@gmail.com> References: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> In-Reply-To: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, shejialuo@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3506; i=karthik.188@gmail.com; h=from:subject:message-id; bh=HxDtD8DknHPW8DXYsfgyPUUfTpU4z8NEOgyKhiksB8c=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnPLCYJK0sZMXXbcrpghcd0g6FGNUuLSpJzKQD8 wAPmNvhnY+JAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZzywmAAKCRA+1Z8kjkaM f8DrC/0VkX0QeVtDJNDGlmU4t3Y3WAMT60UFnX7c9FLpsg/YdgkmDv5+eFi9Y9geF9s/VCThTea vRSWXKqUTmQBtHDyPctkqGnADtlZSEEqZQ9Q0fWZPRlE03z251LLnu/DbN7O9ifLzPwGDyzawR/ sNqp/CLIP/CcE0JrO6v91hL4Xf3DxcyKcCjtc2dk9mNDzZv9tQ085InMYeUpOrLHARBPmH3XY/x zlaMdgkr6Xg2Q6XDioAG1ChrgtCGPpDy353WZuUcmrjyn6e5U+KdV3g25tWgjuQ/we89awl4Vr0 1fxmot3c81ccXYlz4867imwfYk6CCqTYQk/SB8KTTxIF+QoGXyUE3XbUKPT0YBA+VwsywVbJk54 7zsNKEgsSk15XYl2YArAVwhg+SoqNF1EOR+1Gevv7y5+fU5OTjdc+EH0ic+Ma4BJMv/MEgZcCLz ZLr6kS4nsmiRcNgF778zZOwSCkEdT9eoYvRfu/QyFAon6ZwXfl/f3QoEHypydJkYiyFts= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F Similar to the previous commit, pass down `hash_algo` to `get_split_midx_filename_ext` and use `hash_to_hex_algop`. Signed-off-by: Karthik Nayak --- midx-write.c | 7 ++++--- midx.c | 10 ++++++---- midx.h | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/midx-write.c b/midx-write.c index 2f0c09211282fa651af8f9a342f0564729468306..bcd1d50eb0f5c292c904a38f13279b1ebec9c855 100644 --- a/midx-write.c +++ b/midx-write.c @@ -993,7 +993,8 @@ static int link_midx_to_chain(struct multi_pack_index *m) get_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir, hash, midx_exts[i].non_split); - get_split_midx_filename_ext(&to, m->object_dir, hash, + get_split_midx_filename_ext(m->repo->hash_algo, &to, + m->object_dir, hash, midx_exts[i].split); if (link(from.buf, to.buf) < 0 && errno != ENOENT) { @@ -1439,8 +1440,8 @@ static int write_midx_internal(struct repository *r, const char *object_dir, if (link_midx_to_chain(ctx.base_midx) < 0) return -1; - get_split_midx_filename_ext(&final_midx_name, object_dir, - midx_hash, MIDX_EXT_MIDX); + get_split_midx_filename_ext(r->hash_algo, &final_midx_name, + object_dir, midx_hash, MIDX_EXT_MIDX); if (rename_tempfile(&incr, final_midx_name.buf) < 0) { error_errno(_("unable to rename new multi-pack-index layer")); diff --git a/midx.c b/midx.c index 9bed4185ff4d44602aedfe0329dd840ff9e85435..f45ea842cd6eda23d2eadc9deaae43839aef24c1 100644 --- a/midx.c +++ b/midx.c @@ -236,11 +236,13 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir) strbuf_addstr(buf, "/multi-pack-index-chain"); } -void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir, +void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo, + struct strbuf *buf, const char *object_dir, const unsigned char *hash, const char *ext) { get_midx_chain_dirname(buf, object_dir); - strbuf_addf(buf, "/multi-pack-index-%s.%s", hash_to_hex(hash), ext); + strbuf_addf(buf, "/multi-pack-index-%s.%s", + hash_to_hex_algop(hash, hash_algo), ext); } static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo, @@ -328,8 +330,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r, valid = 0; strbuf_reset(&buf); - get_split_midx_filename_ext(&buf, object_dir, layer.hash, - MIDX_EXT_MIDX); + get_split_midx_filename_ext(r->hash_algo, &buf, object_dir, + layer.hash, MIDX_EXT_MIDX); m = load_multi_pack_index_one(r, object_dir, buf.buf, local); if (m) { diff --git a/midx.h b/midx.h index 7620820d4d0272926af9e4eeb68bfb73404c7ec2..9d1374cbd58d016bb82338337b2a4e5ba7234092 100644 --- a/midx.h +++ b/midx.h @@ -97,7 +97,8 @@ void get_midx_filename_ext(const struct git_hash_algo *hash_algo, const unsigned char *hash, const char *ext); void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir); void get_midx_chain_filename(struct strbuf *buf, const char *object_dir); -void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir, +void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo, + struct strbuf *buf, const char *object_dir, const unsigned char *hash, const char *ext); struct multi_pack_index *load_multi_pack_index(struct repository *r, From patchwork Tue Nov 19 15:36:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13880149 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1F5B1D1E81 for ; Tue, 19 Nov 2024 15:37:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030630; cv=none; b=Hlx5CHlp5Yc8v7gV/Ny4cXIVF3Y+ca3ogzg5fcsvhhc6bfLoYzlSSuX2No6PmpPjZtrFNQZlwX5cS9SEWz5/IoLYGOT/JurXnhxit7Ff3jfXa1xx3DWUPFlu1WcYeamrOtEtRMpQfQfjYYDxglNUaK8PnFizqQDAAzF+D0xNS/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732030630; c=relaxed/simple; bh=ibmaTxuTE4m97YVIP84v9QXFINbELDmM9VNgsBQkB2E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DnSueYhZjQbs/L1Ylg1EAX4ZU5o+mstok+mcG1wW8InMB7gScrAo023sJRDLISMLANgjrrTWzBNzp3H9S73XGhyvFv909BSok23SLurfnQDjgaAM6QjhgbRRIQw/WEl53pYU5dAT4EXHI7FBiUIrJFEEcWxHNTKr3JItlpD5K0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YZKkXAvo; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YZKkXAvo" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5cecbddb574so1258638a12.1 for ; Tue, 19 Nov 2024 07:37:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732030627; x=1732635427; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=dWZTAk5o0VG/+fgXNBcCRng07AR2WCFaM+PomdCWEsE=; b=YZKkXAvoQFhmnZlf7N+yjMsto6zH8Nav1cvSHT9sayhXqermWQmZmi47P0NghXZtI6 SpYoYjsxATp2SEBb3wG+sOJgJb/fqKLzUvj09/5c4WXamW45pkeAFO3CC/HWCjTjPggR yewPlTpKBovQjFur3OhT8J91hoAVwGpTyI5a6EX50vzYXm+B+IQVy+TRhcaE1kAufn8I yQszby4NhVFoStxKx6gsvrwZT2v32RFw6fZzOki8IiF5fPbbYIsUlGPTC1uKS1Rhchsf RkFZSsVqujsAwYhDWYE+1jjPKnkLaBqVFO/9VVrx+7+3qoOPSef4319wMkdXPu7//9uo NiSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732030627; x=1732635427; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dWZTAk5o0VG/+fgXNBcCRng07AR2WCFaM+PomdCWEsE=; b=VqUhMfv/ODLk4rw/NhObxceDWb4wAG8Mo1f5snQyhQnDwPfsJvvEVZpIfuqbGHQzAa wGaGa4lW/PAzRGQ/ID6Z+9WN7kjndpZ6+Zd20ukRIodij+8CdNtoAyle+D21R4b9ROxd Yp3RXiWxR7JsboQGyP7MIyVbMm9VPkaf1XBCb5br1YEeAF6p2dxhYnHpnuYnUNIbBn0P ouMLzUWyQAQnQvTWJTU6JEJKgexk9IxEGjnOCXdND6+F61t44gq5pTGV6x6HXb0H+es/ i/7bgemlR3kOD6FlY7+uO7ClfTO2YfrUxx8UzQSiRfgYoew9YyKUavGjjKVIFiyvOVv3 zh2Q== X-Gm-Message-State: AOJu0YwWnHCJE8+YyrYdJbLAF23iAgU0f0DNtXLFWP0uYcNhcQALgNEj KRkDerX08VXrQHckbW4m1KVUalHz5/V4MwgGWGTOKN8+GY8xjQMJ3GtkNDKT X-Google-Smtp-Source: AGHT+IElFmG38O7kNHEDfu73gNHM+k/K/6P/B63iQFYPzVTfBK2+jct6VcsnPqVE/oYae0vRXSdCoA== X-Received: by 2002:a17:907:7b88:b0:a99:ff2c:78fc with SMTP id a640c23a62f3a-aa483556b74mr1760350366b.57.1732030626667; Tue, 19 Nov 2024 07:37:06 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df4e7bfsm661900566b.42.2024.11.19.07.37.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 07:37:06 -0800 (PST) From: Karthik Nayak Date: Tue, 19 Nov 2024 16:36:49 +0100 Subject: [PATCH v2 10/10] midx: inline the `MIDX_MIN_SIZE` definition Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-10-e2f607174efc@gmail.com> References: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> In-Reply-To: <20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, shejialuo@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1382; i=karthik.188@gmail.com; h=from:subject:message-id; bh=ibmaTxuTE4m97YVIP84v9QXFINbELDmM9VNgsBQkB2E=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnPLCYxIgxs79BGzCbEKZJBq6d+19iYCj0MQhFF gX6uLMbsM2JAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZzywmAAKCRA+1Z8kjkaM f8OcDAChSrEKRcwiY3VkNwWKrHz7fuCvw8ziAedpxQuB3sFMS/k4KUXnTjA+2ws8QLZmSoZnVZ8 hL+BNglDK23RZyjjgR9M2y52l3j1kP7yQ8Ucak/Ksgn58exumNU4Oa7PXtnm+bl7gaPflRllAkf h6N8Mt8tE+GIgMED2spodItrXm6PwhQ9v/MLjYYpQnT2cf7KhXYkMCcYXDNcVFDqP5ZfPdnGdq4 4dPQMQI6gU6t8WdRN7i9GJ+KjEskrTHMF1MZQIpj8u0pVg9vY8F+eqjA05lRm5fBeogQg6/JzaQ CNRDDPa1sKG8XnaxYNX9kqO0gW05ylqlT2yQ+6q9E1tTy+zQ/bqZMmhwdmmNbKAbPJPSBS1X7BO uus2OKf9tWTsHym7kiytSxfE/Rw2w1h+PnFp+fQzfsJyM/wP2UMCGmczzpOdAIQgBznpwqHxLFO PqWGQmeKkW2C1eGDdyCaEOGSfh7taNHM0WFkiyeuEKloirD2f2Ers4oyKJcvvgE+GbuPE= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The `MIDX_MIN_SIZE` definition is used to check the midx_size in `local_multi_pack_index_one`. This definitions relies on the `the_hash_algo` global variable. Inline this and remove the global variable usage. With this, remove `USE_THE_REPOSITORY_VARIABLE` usage from `midx.c`. Signed-off-by: Karthik Nayak --- midx.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/midx.c b/midx.c index f45ea842cd6eda23d2eadc9deaae43839aef24c1..e0eae1c25ec91f7db5670ff9bacdf0e195c35795 100644 --- a/midx.c +++ b/midx.c @@ -1,5 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "config.h" #include "dir.h" @@ -94,8 +92,6 @@ static int midx_read_object_offsets(const unsigned char *chunk_start, return 0; } -#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz) - static struct multi_pack_index *load_multi_pack_index_one(struct repository *r, const char *object_dir, const char *midx_name, @@ -122,7 +118,7 @@ static struct multi_pack_index *load_multi_pack_index_one(struct repository *r, midx_size = xsize_t(st.st_size); - if (midx_size < MIDX_MIN_SIZE) { + if (midx_size < (MIDX_HEADER_SIZE + r->hash_algo->rawsz)) { error(_("multi-pack-index file %s is too small"), midx_name); goto cleanup_fail; }