From patchwork Mon Oct 21 09:57: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: 13843787 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.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 F371C1E3DFC for ; Mon, 21 Oct 2024 09:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504691; cv=none; b=nWDebicGb+BkzPlSXGp5wt1MyMSrerAxcdj86GdlshrNk66snfFq+996QD7kxEfLzc8FH9OyOdtTIw3ceDLoqY8uvt2Sn2OFVOHkJ6EGraDeCW4a5g//dKgUdZE6hX1+xq2c/5TRvT9tLtzHA4RYwKzI8ObcVc8MW2TgN0sgMGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504691; c=relaxed/simple; bh=n28m+GQYfjSixgZq1JJew40wDnLGtMFxYB//OXbMhHQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RHQ4YEzJkKz/LtJ13vlaevcYTLQLUut6d9HH02+SKPCrWvPXI39HR/cPZbJoZkadtRLsmYYVV4/c8WIiTD7+bmp+P7NbnnaggJ8XqDSESjU+aJVRtGXKbBo+xq2uwcSRangkfkWyHjN9nHZh7e66t0bBG+pNWSk7f1/qkH9dyvg= 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=QFND+L2D; arc=none smtp.client-ip=209.85.218.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="QFND+L2D" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a99cc265e0aso620548766b.3 for ; Mon, 21 Oct 2024 02:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504687; x=1730109487; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HVYj84C5UlH3WT4p2T1nxT/NluhMqbJySawoGAMESzM=; b=QFND+L2D6uHrBFOwm9SxmEVhoB8Lvts8CSgn159OesEMI2GsWyZsqlhpAjznEg1VCN csY6I9BRL/Y7PEDZ5E/wD9Ld5wUyk3pypLv6eQ9vfXrGNqkJnOmuxHlXYku5QiGMeCz2 0C+wxaQYpnfEhf840cOH1KXTObxyi7Pg3VsQxB+Hq9I5FTbRYhj0+RkDp0o64bl7GFfa FdxQxgPjaZzBI9vkDzRfF/osKiqzq5XZLeuqzD0S6zL0VrSQEKATKuf/NMfOkUHIvseL F6g51Fq1zQw5nn10FgspL9h/6kpALnpdYh50tfSpPg5XooVdMbAzjjZravUA3Vo3igDG 6TdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504687; x=1730109487; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HVYj84C5UlH3WT4p2T1nxT/NluhMqbJySawoGAMESzM=; b=xU3PBqcu0+wZ9W8frWmLgxROB6Sw+Avac2+423bL/67L+GSGPW0oqEMAfeQWElpbkT MAn+KjyQbUwxZTijJYNPGhCo5vWRpzSQgW/wm3tXQjTRiJYngy0DKknhL3SQE73hZ5nC y8C42mvBBIDbMbUcb3ZPJqlgYeReenck+XDE69uiO87VXu+dyFdZyucbjrlgSE4FMlfu xHkSBpemkKbvLmpx0YuepP5WZDJQ8utPHNAfpDHqzQA+HXzG8lYpLS6sLJ5XW6Pck9W4 DhCgpvtJt1pmQmr7gDsQNt531yRllCBiMwSRT18lTJZhqqbxAax7Uijf5f6BsoJd3rWE PQvg== X-Gm-Message-State: AOJu0YzvQ+1FwR4f7eTKPDeVJaLkffWfMUxSjo8YEG7yXCXl4a+FxDXJ Bv43E+rt1IbiKX2W/IvdPsbrw3L9bHO+6eBTFgRzIjLgo4ufCWiv62yD90Q2 X-Google-Smtp-Source: AGHT+IGq1oarNVrSY2w+XsaDMkmnQ8pXYstc46Wn4oQ2DmlkvBJlm1MI66IBxXjgaveq0Z+m8KLsPw== X-Received: by 2002:a17:907:94c8:b0:a99:fb75:3ed7 with SMTP id a640c23a62f3a-a9a69a69349mr1078075966b.17.1729504686828; Mon, 21 Oct 2024 02:58:06 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:06 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 01/20] packfile: pass down repository to `odb_pack_name` Date: Mon, 21 Oct 2024 11:57:44 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `odb_pack_name` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/fast-import.c | 8 ++++---- builtin/index-pack.c | 4 ++-- builtin/pack-redundant.c | 2 +- http.c | 15 +++++++++------ packfile.c | 27 ++++++++++++++------------- packfile.h | 13 ++++++++----- 6 files changed, 38 insertions(+), 31 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 1e7ab67f6e..7ad950627c 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -805,7 +805,7 @@ static char *keep_pack(const char *curr_index_name) struct strbuf name = STRBUF_INIT; int keep_fd; - odb_pack_name(&name, pack_data->hash, "keep"); + odb_pack_name(the_repository, &name, pack_data->hash, "keep"); keep_fd = odb_pack_keep(name.buf); if (keep_fd < 0) die_errno("cannot create keep file"); @@ -813,11 +813,11 @@ static char *keep_pack(const char *curr_index_name) if (close(keep_fd)) die_errno("failed to write keep file"); - odb_pack_name(&name, pack_data->hash, "pack"); + odb_pack_name(the_repository, &name, pack_data->hash, "pack"); if (finalize_object_file(pack_data->pack_name, name.buf)) die("cannot store pack file"); - odb_pack_name(&name, pack_data->hash, "idx"); + odb_pack_name(the_repository, &name, pack_data->hash, "idx"); if (finalize_object_file(curr_index_name, name.buf)) die("cannot store index file"); free((void *)curr_index_name); @@ -831,7 +831,7 @@ static void unkeep_all_packs(void) for (k = 0; k < pack_id; k++) { struct packed_git *p = all_packs[k]; - odb_pack_name(&name, p->hash, "keep"); + odb_pack_name(the_repository, &name, p->hash, "keep"); unlink_or_warn(name.buf); } strbuf_release(&name); diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 9d23b41b3a..97afc69625 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1479,7 +1479,7 @@ static void write_special_file(const char *suffix, const char *msg, if (pack_name) filename = derive_filename(pack_name, "pack", suffix, &name_buf); else - filename = odb_pack_name(&name_buf, hash, suffix); + filename = odb_pack_name(the_repository, &name_buf, hash, suffix); fd = odb_pack_keep(filename); if (fd < 0) { @@ -1507,7 +1507,7 @@ static void rename_tmp_packfile(const char **final_name, { if (!*final_name || strcmp(*final_name, curr_name)) { if (!*final_name) - *final_name = odb_pack_name(name, hash, ext); + *final_name = odb_pack_name(the_repository, name, hash, ext); if (finalize_object_file(curr_name, *final_name)) die(_("unable to rename temporary '*.%s' file to '%s'"), ext, *final_name); diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index 5809613002..60f806e672 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -688,7 +688,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s pl = red = pack_list_difference(local_packs, min); while (pl) { printf("%s\n%s\n", - sha1_pack_index_name(pl->pack->hash), + sha1_pack_index_name(the_repository, pl->pack->hash), pl->pack->pack_name); pl = pl->next; } diff --git a/http.c b/http.c index d59e59f66b..309669c203 100644 --- a/http.c +++ b/http.c @@ -2388,7 +2388,7 @@ static char *fetch_pack_index(unsigned char *hash, const char *base_url) strbuf_addf(&buf, "objects/pack/pack-%s.idx", hash_to_hex(hash)); url = strbuf_detach(&buf, NULL); - strbuf_addf(&buf, "%s.temp", sha1_pack_index_name(hash)); + strbuf_addf(&buf, "%s.temp", sha1_pack_index_name(the_repository, hash)); tmp = strbuf_detach(&buf, NULL); if (http_get_file(url, tmp, NULL) != HTTP_OK) { @@ -2407,8 +2407,10 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head, char *tmp_idx = NULL; int ret; - if (has_pack_index(sha1)) { - new_pack = parse_pack_index(sha1, sha1_pack_index_name(sha1)); + if (has_pack_index(the_repository, sha1)) { + new_pack = parse_pack_index(the_repository, sha1, + sha1_pack_index_name(the_repository, + sha1)); if (!new_pack) return -1; /* parse_pack_index() already issued error message */ goto add_pack; @@ -2418,7 +2420,7 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head, if (!tmp_idx) return -1; - new_pack = parse_pack_index(sha1, tmp_idx); + new_pack = parse_pack_index(the_repository, sha1, tmp_idx); if (!new_pack) { unlink(tmp_idx); free(tmp_idx); @@ -2429,7 +2431,7 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head, ret = verify_pack_index(new_pack); if (!ret) { close_pack_index(new_pack); - ret = finalize_object_file(tmp_idx, sha1_pack_index_name(sha1)); + ret = finalize_object_file(tmp_idx, sha1_pack_index_name(the_repository, sha1)); } free(tmp_idx); if (ret) @@ -2563,7 +2565,8 @@ struct http_pack_request *new_direct_http_pack_request( preq->url = url; - strbuf_addf(&preq->tmpfile, "%s.temp", sha1_pack_name(packed_git_hash)); + strbuf_addf(&preq->tmpfile, "%s.temp", sha1_pack_name(the_repository, + packed_git_hash)); preq->packfile = fopen(preq->tmpfile.buf, "a"); if (!preq->packfile) { error("Unable to open local file %s for pack", diff --git a/packfile.c b/packfile.c index df4ba67719..e4569ea29d 100644 --- a/packfile.c +++ b/packfile.c @@ -25,26 +25,25 @@ #include "pack-revindex.h" #include "promisor-remote.h" -char *odb_pack_name(struct strbuf *buf, - const unsigned char *hash, - const char *ext) +char *odb_pack_name(struct repository *repo, struct strbuf *buf, + const unsigned char *hash, const char *ext) { strbuf_reset(buf); - strbuf_addf(buf, "%s/pack/pack-%s.%s", repo_get_object_directory(the_repository), + strbuf_addf(buf, "%s/pack/pack-%s.%s", repo_get_object_directory(repo), hash_to_hex(hash), ext); return buf->buf; } -char *sha1_pack_name(const unsigned char *sha1) +char *sha1_pack_name(struct repository *repo, const unsigned char *sha1) { static struct strbuf buf = STRBUF_INIT; - return odb_pack_name(&buf, sha1, "pack"); + return odb_pack_name(repo, &buf, sha1, "pack"); } -char *sha1_pack_index_name(const unsigned char *sha1) +char *sha1_pack_index_name(struct repository *repo, const unsigned char *sha1) { static struct strbuf buf = STRBUF_INIT; - return odb_pack_name(&buf, sha1, "idx"); + return odb_pack_name(repo, &buf, sha1, "idx"); } static unsigned int pack_used_ctr; @@ -237,14 +236,16 @@ static struct packed_git *alloc_packed_git(int extra) return p; } -struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path) +struct packed_git *parse_pack_index(struct repository *repo, + unsigned char *sha1, + const char *idx_path) { - const char *path = sha1_pack_name(sha1); + const char *path = sha1_pack_name(repo, sha1); size_t alloc = st_add(strlen(path), 1); struct packed_git *p = alloc_packed_git(alloc); memcpy(p->pack_name, path, alloc); /* includes NUL */ - hashcpy(p->hash, sha1, the_repository->hash_algo); + hashcpy(p->hash, sha1, repo->hash_algo); if (check_packed_git_idx(idx_path, p)) { free(p); return NULL; @@ -2151,10 +2152,10 @@ int has_object_kept_pack(const struct object_id *oid, unsigned flags) return find_kept_pack_entry(the_repository, oid, flags, &e); } -int has_pack_index(const unsigned char *sha1) +int has_pack_index(struct repository *repo, const unsigned char *sha1) { struct stat st; - if (stat(sha1_pack_index_name(sha1), &st)) + if (stat(sha1_pack_index_name(repo, sha1), &st)) return 0; return 1; } diff --git a/packfile.h b/packfile.h index 0f78658229..507ac602b5 100644 --- a/packfile.h +++ b/packfile.h @@ -29,21 +29,22 @@ struct pack_entry { * * Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx" */ -char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext); +char *odb_pack_name(struct repository *repo, struct strbuf *buf, + const unsigned char *sha1, const char *ext); /* * Return the name of the (local) packfile with the specified sha1 in * its name. The return value is a pointer to memory that is * overwritten each time this function is called. */ -char *sha1_pack_name(const unsigned char *sha1); +char *sha1_pack_name(struct repository *repo, const unsigned char *sha1); /* * Return the name of the (local) pack index file with the specified * sha1 in its name. The return value is a pointer to memory that is * overwritten each time this function is called. */ -char *sha1_pack_index_name(const unsigned char *sha1); +char *sha1_pack_index_name(struct repository *repo, const unsigned char *sha1); /* * Return the basename of the packfile, omitting any containing directory @@ -51,7 +52,9 @@ char *sha1_pack_index_name(const unsigned char *sha1); */ const char *pack_basename(struct packed_git *p); -struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path); +struct packed_git *parse_pack_index(struct repository *repo, + unsigned char *sha1, + const char *idx_path); typedef void each_file_in_pack_dir_fn(const char *full_path, size_t full_path_len, const char *file_name, void *data); @@ -193,7 +196,7 @@ int find_kept_pack_entry(struct repository *r, const struct object_id *oid, unsi int has_object_pack(const struct object_id *oid); int has_object_kept_pack(const struct object_id *oid, unsigned flags); -int has_pack_index(const unsigned char *sha1); +int has_pack_index(struct repository *repo, const unsigned char *sha1); /* * Return 1 if an object in a promisor packfile is or refers to the given From patchwork Mon Oct 21 09:57: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: 13843788 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 9B1651E3DFF for ; Mon, 21 Oct 2024 09:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504691; cv=none; b=J4uqfwLwvuw1YH4eg9fBqv+O/RY6k6KdhsiAAKIEePIjDQoPsRILbPi7hz5zl9Z4lPgbfghtdqyYOpqI5eP6aLERzHNYgWXMt2CP4HjwiqpFln0iJ5XMq8QlDYcH6ge42AgR5WFx5Woft8UN9Q1wMBvL/cet6t1PL5ELdryfoQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504691; c=relaxed/simple; bh=+IPMFTYMJo4dFOAzUebck09p0MRxXOxEyROrJt08l0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i84VWE0Ko54WVFkoYFqyvGPfX3Z9AqFMtoIRH0hAEHZ5BGhuDvF9wB05N8j/I/8l4zb8nugLURumhWveNDD4TSHEmfRAPeo3hgJTArhMDaM90sTag3c1IK5zEg2FzkCe+Qi0dzA0Fzm2lJrvHf6yeW6a+ZnXlKSxr6LvI13WWGk= 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=YzvYYlPp; arc=none smtp.client-ip=209.85.218.41 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="YzvYYlPp" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a99f3a5a44cso493032766b.3 for ; Mon, 21 Oct 2024 02:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504688; x=1730109488; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JZz+6XO0ODupHR0Vy4M57AZG1ytUr+sb/Wm3taRqKtI=; b=YzvYYlPp8LiWnw5sKaeHoCr/lCQTA6oQcAmqQDLzSJiBZY5hCdfn2Ry/YtkH1thcVD PCCX1koIYj1BJAXOGELTjvk3T/EuPDkRd/vp8QR74vTvL/gR7qd4nuCNabkw/WvKatEG GvaJzQ1eTI7A338WwGbXAMPoYxoQMGnUdpCXPyfenefKlOz+yH+f/uRr68VNd6NFhBVl hKnqimNMi5rhOr+BaX5jICwVi8HKj7BcP7GrIepfHun85ofnuHuE/e+Htv8vYRj3B6oN yWouzKjaOUKGFQMBsQdCEiIh4ZecQn7y2MpFjsvF8s0pD3ByQFpsfzyA//VhxqDdn7DK 438g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504688; x=1730109488; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JZz+6XO0ODupHR0Vy4M57AZG1ytUr+sb/Wm3taRqKtI=; b=azSS8DJ7lgolI8TKqc2hmfqfHog8BrOfTwYR/91mQgnMQZUr2fZBiErmTvAHLZNpOv IDR+AkoaAUx1pdNvm9d3hV8KYer5Coaz6W+wkLS4hKvzSTWoIzetD8evWwVGm3C847or +SOhk8ImEltJNiiTE49vIOkTMs/f1lWUOCrX5FdpveHs/LyOPSLgkTsYO4BZohaSt/RK DkBsT9j5LxkQTLTUNxOW+ihxL+nNKFHc0Xz0S98K/BmswegVymYE1rpBBbCDQIheOMAd 0x8UVqlTF2uTqM3bT4pRtTOFJKowFikumU5ht6jNDKPJTWBtXaVy9MPyIMFgOxcLzSn0 TEJw== X-Gm-Message-State: AOJu0YxsTpx8mJ7Z3bOciFX6RSb5U9hL6mFNRDma/PJxZv5hsEcdU9Ic FKSVIBQ3whlWFoBl0JsYSU0gmaSn4S8DcA9ctgqgVULDWBKfca6sVGsusEzV X-Google-Smtp-Source: AGHT+IEAa8DpzGJYb9/p7G9G5NHW/zrSnsl5VZ/IdUlOJCF/XHZWhX2rme69Qr3ZmoT6tGcTcPcM2Q== X-Received: by 2002:a17:907:728b:b0:a8d:4631:83b0 with SMTP id a640c23a62f3a-a9a69969af5mr1222922866b.5.1729504687534; Mon, 21 Oct 2024 02:58:07 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:07 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 02/20] packfile: pass down repository to `unuse_one_window` Date: Mon, 21 Oct 2024 11:57:45 +0200 Message-ID: <7ab2d08f354017ae20cc26c7078b7a38a7ab0ca5.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `unuse_one_window` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/pack-objects.c | 12 ++++++------ pack-check.c | 6 +++--- packfile.c | 25 +++++++++++++------------ packfile.h | 3 ++- streaming.c | 2 +- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 0fc0680b40..4dd6ada184 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -401,7 +401,7 @@ static int check_pack_inflate(struct packed_git *p, memset(&stream, 0, sizeof(stream)); git_inflate_init(&stream); do { - in = use_pack(p, w_curs, offset, &stream.avail_in); + in = use_pack(the_repository, p, w_curs, offset, &stream.avail_in); stream.next_in = in; stream.next_out = fakebuf; stream.avail_out = sizeof(fakebuf); @@ -424,7 +424,7 @@ static void copy_pack_data(struct hashfile *f, unsigned long avail; while (len) { - in = use_pack(p, w_curs, offset, &avail); + in = use_pack(the_repository, p, w_curs, offset, &avail); if (avail > len) avail = (unsigned long)len; hashwrite(f, in, avail); @@ -2071,7 +2071,7 @@ static void check_object(struct object_entry *entry, uint32_t object_index) enum object_type type; unsigned long in_pack_size; - buf = use_pack(p, &w_curs, entry->in_pack_offset, &avail); + buf = use_pack(the_repository, p, &w_curs, entry->in_pack_offset, &avail); /* * We want in_pack_type even if we do not reuse delta @@ -2105,7 +2105,7 @@ static void check_object(struct object_entry *entry, uint32_t object_index) case OBJ_REF_DELTA: if (reuse_delta && !entry->preferred_base) { oidread(&base_ref, - use_pack(p, &w_curs, + use_pack(the_repository, p, &w_curs, entry->in_pack_offset + used, NULL), the_repository->hash_algo); @@ -2114,7 +2114,7 @@ static void check_object(struct object_entry *entry, uint32_t object_index) entry->in_pack_header_size = used + the_hash_algo->rawsz; break; case OBJ_OFS_DELTA: - buf = use_pack(p, &w_curs, + buf = use_pack(the_repository, p, &w_curs, entry->in_pack_offset + used, NULL); used_0 = 0; c = buf[used_0++]; @@ -2574,7 +2574,7 @@ unsigned long oe_get_size_slow(struct packing_data *pack, packing_data_lock(&to_pack); w_curs = NULL; - buf = use_pack(p, &w_curs, e->in_pack_offset, &avail); + buf = use_pack(the_repository, p, &w_curs, e->in_pack_offset, &avail); used = unpack_object_header_buffer(buf, avail, &type, &size); if (used == 0) die(_("unable to parse object header of %s"), diff --git a/pack-check.c b/pack-check.c index e883dae3f2..e4636e9897 100644 --- a/pack-check.c +++ b/pack-check.c @@ -34,7 +34,7 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, do { unsigned long avail; - void *data = use_pack(p, w_curs, offset, &avail); + void *data = use_pack(the_repository, p, w_curs, offset, &avail); if (avail > len) avail = len; data_crc = crc32(data_crc, data, avail); @@ -70,7 +70,7 @@ static int verify_packfile(struct repository *r, r->hash_algo->init_fn(&ctx); do { unsigned long remaining; - unsigned char *in = use_pack(p, w_curs, offset, &remaining); + unsigned char *in = use_pack(the_repository, p, w_curs, offset, &remaining); offset += remaining; if (!pack_sig_ofs) pack_sig_ofs = p->pack_size - r->hash_algo->rawsz; @@ -79,7 +79,7 @@ static int verify_packfile(struct repository *r, r->hash_algo->update_fn(&ctx, in, remaining); } while (offset < pack_sig_ofs); r->hash_algo->final_fn(hash, &ctx); - pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL); + pack_sig = use_pack(the_repository, p, w_curs, pack_sig_ofs, NULL); if (!hasheq(hash, pack_sig, the_repository->hash_algo)) err = error("%s pack checksum mismatch", p->pack_name); diff --git a/packfile.c b/packfile.c index e4569ea29d..b0a3bfcd72 100644 --- a/packfile.c +++ b/packfile.c @@ -273,14 +273,14 @@ static void scan_windows(struct packed_git *p, } } -static int unuse_one_window(struct packed_git *current) +static int unuse_one_window(struct repository *repo, struct packed_git *current) { struct packed_git *p, *lru_p = NULL; struct pack_window *lru_w = NULL, *lru_l = NULL; if (current) scan_windows(current, &lru_p, &lru_w, &lru_l); - for (p = the_repository->objects->packed_git; p; p = p->next) + for (p = repo->objects->packed_git; p; p = p->next) scan_windows(p, &lru_p, &lru_w, &lru_l); if (lru_p) { munmap(lru_w->base, lru_w->len); @@ -625,10 +625,9 @@ static int in_window(struct pack_window *win, off_t offset) && (offset + the_hash_algo->rawsz) <= (win_off + win->len); } -unsigned char *use_pack(struct packed_git *p, - struct pack_window **w_cursor, - off_t offset, - unsigned long *left) +unsigned char *use_pack(struct repository *repo, struct packed_git *p, + struct pack_window **w_cursor, + off_t offset, unsigned long *left) { struct pack_window *win = *w_cursor; @@ -666,7 +665,7 @@ unsigned char *use_pack(struct packed_git *p, win->len = (size_t)len; pack_mapped += win->len; while (packed_git_limit < pack_mapped - && unuse_one_window(p)) + && unuse_one_window(repo, p)) ; /* nothing */ win->base = xmmap_gently(NULL, win->len, PROT_READ, MAP_PRIVATE, @@ -1129,7 +1128,7 @@ unsigned long get_size_from_delta(struct packed_git *p, git_inflate_init(&stream); do { - in = use_pack(p, w_curs, curpos, &stream.avail_in); + in = use_pack(the_repository, p, w_curs, curpos, &stream.avail_in); stream.next_in = in; /* * Note: the window section returned by use_pack() must be @@ -1185,7 +1184,7 @@ int unpack_object_header(struct packed_git *p, * the maximum deflated object size is 2^137, which is just * insane, so we know won't exceed what we have been given. */ - base = use_pack(p, w_curs, *curpos, &left); + base = use_pack(the_repository, p, w_curs, *curpos, &left); used = unpack_object_header_buffer(base, left, &type, sizep); if (!used) { type = OBJ_BAD; @@ -1217,7 +1216,7 @@ off_t get_delta_base(struct packed_git *p, enum object_type type, off_t delta_obj_offset) { - unsigned char *base_info = use_pack(p, w_curs, *curpos, NULL); + unsigned char *base_info = use_pack(the_repository, p, w_curs, *curpos, NULL); off_t base_offset; /* use_pack() assured us we have [base_info, base_info + 20) @@ -1264,7 +1263,8 @@ static int get_delta_base_oid(struct packed_git *p, off_t delta_obj_offset) { if (type == OBJ_REF_DELTA) { - unsigned char *base = use_pack(p, w_curs, curpos, NULL); + unsigned char *base = use_pack(the_repository, p, w_curs, + curpos, NULL); oidread(oid, base, the_repository->hash_algo); return 0; } else if (type == OBJ_OFS_DELTA) { @@ -1636,7 +1636,8 @@ static void *unpack_compressed_entry(struct packed_git *p, git_inflate_init(&stream); do { - in = use_pack(p, w_curs, curpos, &stream.avail_in); + in = use_pack(the_repository, p, w_curs, curpos, + &stream.avail_in); stream.next_in = in; /* * Note: we must ensure the window section returned by diff --git a/packfile.h b/packfile.h index 507ac602b5..90a1f2e1cf 100644 --- a/packfile.h +++ b/packfile.h @@ -110,7 +110,8 @@ uint32_t get_pack_fanout(struct packed_git *p, uint32_t value); struct raw_object_store; -unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *); +unsigned char *use_pack(struct repository *repo, struct packed_git *, + struct pack_window **, off_t, unsigned long *); void close_pack_windows(struct packed_git *); void close_pack(struct packed_git *); void close_object_store(struct raw_object_store *o); diff --git a/streaming.c b/streaming.c index 38839511af..58b3b3cff7 100644 --- a/streaming.c +++ b/streaming.c @@ -292,7 +292,7 @@ static ssize_t read_istream_pack_non_delta(struct git_istream *st, char *buf, struct pack_window *window = NULL; unsigned char *mapped; - mapped = use_pack(st->u.in_pack.pack, &window, + mapped = use_pack(the_repository, st->u.in_pack.pack, &window, st->u.in_pack.pos, &st->z.avail_in); st->z.next_out = (unsigned char *)buf + total_read; From patchwork Mon Oct 21 09:57: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: 13843789 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 49C4A1E412A for ; Mon, 21 Oct 2024 09:58:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504692; cv=none; b=dZwh07H66uEmo8G+eO22Yk4qo0EnWuKisQ6OiemSEGbxvvNqTW8PD/iA0jDB1jotFEbO72yd5dNgjqKctChwiVNiIehayta3NakaaYQcINeaILxL68KtQs3oH6b6NNLUg7Xu8GbIAJYelF9Vc+Jh0oe53w1w6UHcGAF1e/ru/Ak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504692; c=relaxed/simple; bh=bRg5dVFdlNFx2jDhtZ+PgddSGOJ8lD+uT3ybcklHLxc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tmI06aOjdVLPSaKh0Oi+3lqhxMxwxwcCUnoYcmhRxCnIL/U6WJqGW2b8ZCma23y/I+Xw1JRdxNhN9KYEKz3GbOQK+9CWX7pNXgVIQoSYo6rAsCOrhmau7cHtTZ/jh9u/p3665vLoo4U0m40PXjaELlfZxXNdbIjKHK6Gh0NsRSQ= 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=ft5HqsRL; arc=none smtp.client-ip=209.85.208.41 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="ft5HqsRL" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5c903f5bd0eso7777498a12.3 for ; Mon, 21 Oct 2024 02:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504688; x=1730109488; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P/pjs4M75WsEJNlNvE4dxxkcX3CE3/y/C+80FusxHJI=; b=ft5HqsRLwKmqu3/OMhbuBxnbgyFF8sLyVpxcwrowEQ77s5pBF1k7ZT2HRspb7Z2h/x W9i+eB5NSVUDsGUZ87bnoaO0shPIwtb32PZ+tH8Le76B6a19CWvijUvpyNe+gXpeMR9I heol5G30FdWsbqexvkh8YqMhBiwub2gLZwY7J+NPMxuRn0lztcekia0sv74eW/4jKcvt YFF8nfuzsN3EnQtYRbCnXIzKc2Yhw8/AGxv9xfTsaQRB7NDG0lu12GxcbmxfMz6vwioy i2DTBg1vOLEfKihuFillxzGiKQbF3GS7KoJ8lXa76nxHR0/VGEbrFQPCjPTFyHbA/RRl QUQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504688; x=1730109488; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P/pjs4M75WsEJNlNvE4dxxkcX3CE3/y/C+80FusxHJI=; b=sUUgk56DmluaedqgnwuXD0d3kJsgenqb0lJceKTKWsJ6OUUfHIL8G6NM0U0Nh7Cfa0 gTQOw59PH3pTmb1SVgFHYDrO80MgK2DUbTRWkQMCr3H6AwhNBoQTR0JToc17oPjeo8Ip kq1bp/1PqLSCEYxV/HsAjNEjzGc5YGWq2SPH2iUmuXyqK8O9GDe/zFcm6SIZdxn8+V+p PkaBSCgY2jWbKFtcClnR3C47h1L275ffCbyu/pNLN0/LjKcswYzdwQESCzL8tMfjaMJG cs5jSfubh2R/hIMK18RTRltKxTex42+Ybbtbhrc1R5tkuZrgKC+gBSoZ4xSUoEWgQdRC d0Yw== X-Gm-Message-State: AOJu0Yy14hnkFRP+Hu3G9s0ePIkvnBaZgoesv/O7dI4N41wfm4GOzgnc MBwdV0oH7EIRWZwnrf38KcfgpezAlRhwJT/LD0tWbwLPCLTPmBeqaSbOsnVD X-Google-Smtp-Source: AGHT+IF3rPsJPCzcCjGnxyOH45HCVx6Suci9HRpPFaPIQt5nOAzKIdVg9NcfXN+msJPCgjDGrAsnkQ== X-Received: by 2002:a17:907:e8d:b0:a9a:3d5b:dc1a with SMTP id a640c23a62f3a-a9a69a76297mr1101219766b.15.1729504688258; Mon, 21 Oct 2024 02:58:08 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:07 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 03/20] packfile: pass down repository to `close_one_pack` Date: Mon, 21 Oct 2024 11:57:46 +0200 Message-ID: <5160e79cbb67c0e7596bd0a48ecdedbf3e5236c9.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `close_one_pack` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/pack-objects.c | 6 +++--- midx.c | 2 +- pack-bitmap.c | 4 ++-- pack-check.c | 2 +- packfile.c | 24 ++++++++++++------------ packfile.h | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 4dd6ada184..ec321da8dc 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1482,7 +1482,7 @@ static int want_found_object(const struct object_id *oid, int exclude, if (incremental) return 0; - if (!is_pack_valid(p)) + if (!is_pack_valid(the_repository, p)) return -1; /* @@ -1560,7 +1560,7 @@ static int want_object_in_pack_one(struct packed_git *p, if (offset) { if (!*found_pack) { - if (!is_pack_valid(p)) + if (!is_pack_valid(the_repository, p)) return -1; *found_offset = offset; *found_pack = p; @@ -3513,7 +3513,7 @@ static void read_packs_list_from_stdin(void) struct packed_git *p = item->util; if (!p) die(_("could not find pack '%s'"), item->string); - if (!is_pack_valid(p)) + if (!is_pack_valid(the_repository, p)) die(_("packfile %s cannot be accessed"), p->pack_name); } diff --git a/midx.c b/midx.c index 67e0d64004..4a05f74606 100644 --- a/midx.c +++ b/midx.c @@ -597,7 +597,7 @@ int fill_midx_entry(struct repository *r, * answer, as it may have been deleted since the MIDX was * loaded! */ - if (!is_pack_valid(p)) + if (!is_pack_valid(r, p)) return 0; if (oidset_size(&p->bad_objects) && diff --git a/pack-bitmap.c b/pack-bitmap.c index 32b222a7af..067d1741d2 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -451,7 +451,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git, } preferred = bitmap_git->midx->packs[preferred_pack]; - if (!is_pack_valid(preferred)) { + if (!is_pack_valid(the_repository, preferred)) { warning(_("preferred pack (%s) is invalid"), preferred->pack_name); goto cleanup; @@ -498,7 +498,7 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git return -1; } - if (!is_pack_valid(packfile)) { + if (!is_pack_valid(the_repository, packfile)) { close(fd); return -1; } diff --git a/pack-check.c b/pack-check.c index e4636e9897..bb649edbc1 100644 --- a/pack-check.c +++ b/pack-check.c @@ -64,7 +64,7 @@ static int verify_packfile(struct repository *r, int err = 0; struct idx_entry *entries; - if (!is_pack_valid(p)) + if (!is_pack_valid(the_repository, p)) return error("packfile %s cannot be accessed", p->pack_name); r->hash_algo->init_fn(&ctx); diff --git a/packfile.c b/packfile.c index b0a3bfcd72..4588004223 100644 --- a/packfile.c +++ b/packfile.c @@ -462,13 +462,13 @@ static void find_lru_pack(struct packed_git *p, struct packed_git **lru_p, struc *accept_windows_inuse = has_windows_inuse; } -static int close_one_pack(void) +static int close_one_pack(struct repository *repo) { struct packed_git *p, *lru_p = NULL; struct pack_window *mru_w = NULL; int accept_windows_inuse = 1; - for (p = the_repository->objects->packed_git; p; p = p->next) { + for (p = repo->objects->packed_git; p; p = p->next) { if (p->pack_fd == -1) continue; find_lru_pack(p, &lru_p, &mru_w, &accept_windows_inuse); @@ -535,7 +535,7 @@ const char *pack_basename(struct packed_git *p) * Do not call this directly as this leaks p->pack_fd on error return; * call open_packed_git() instead. */ -static int open_packed_git_1(struct packed_git *p) +static int open_packed_git_1(struct repository *repo, struct packed_git *p) { struct stat st; struct pack_header hdr; @@ -557,7 +557,7 @@ static int open_packed_git_1(struct packed_git *p) pack_max_fds = 1; } - while (pack_max_fds <= pack_open_fds && close_one_pack()) + while (pack_max_fds <= pack_open_fds && close_one_pack(repo)) ; /* nothing */ p->pack_fd = git_open(p->pack_name); @@ -599,14 +599,14 @@ static int open_packed_git_1(struct packed_git *p) if (read_result != hashsz) return error("packfile %s signature is unavailable", p->pack_name); idx_hash = ((unsigned char *)p->index_data) + p->index_size - hashsz * 2; - if (!hasheq(hash, idx_hash, the_repository->hash_algo)) + if (!hasheq(hash, idx_hash, repo->hash_algo)) return error("packfile %s does not match index", p->pack_name); return 0; } -static int open_packed_git(struct packed_git *p) +static int open_packed_git(struct repository *repo, struct packed_git *p) { - if (!open_packed_git_1(p)) + if (!open_packed_git_1(repo, p)) return 0; close_pack_fd(p); return -1; @@ -636,7 +636,7 @@ unsigned char *use_pack(struct repository *repo, struct packed_git *p, * hash, and the in_window function above wouldn't match * don't allow an offset too close to the end of the file. */ - if (!p->pack_size && p->pack_fd == -1 && open_packed_git(p)) + if (!p->pack_size && p->pack_fd == -1 && open_packed_git(repo, p)) die("packfile %s cannot be accessed", p->pack_name); if (offset > (p->pack_size - the_hash_algo->rawsz)) die("offset beyond end of packfile (truncated pack?)"); @@ -654,7 +654,7 @@ unsigned char *use_pack(struct repository *repo, struct packed_git *p, size_t window_align = packed_git_window_size / 2; off_t len; - if (p->pack_fd == -1 && open_packed_git(p)) + if (p->pack_fd == -1 && open_packed_git(repo, p)) die("packfile %s cannot be accessed", p->pack_name); CALLOC_ARRAY(win, 1); @@ -1994,7 +1994,7 @@ off_t find_pack_entry_one(const unsigned char *sha1, return 0; } -int is_pack_valid(struct packed_git *p) +int is_pack_valid(struct repository *repo, struct packed_git *p) { /* An already open pack is known to be valid. */ if (p->pack_fd != -1) @@ -2012,7 +2012,7 @@ int is_pack_valid(struct packed_git *p) } /* Force the pack to open to prove its valid. */ - return !open_packed_git(p); + return !open_packed_git(repo, p); } struct packed_git *find_sha1_pack(const unsigned char *sha1, @@ -2049,7 +2049,7 @@ static int fill_pack_entry(const struct object_id *oid, * answer, as it may have been deleted since the index was * loaded! */ - if (!is_pack_valid(p)) + if (!is_pack_valid(the_repository, p)) return 0; e->offset = offset; e->p = p; diff --git a/packfile.h b/packfile.h index 90a1f2e1cf..b74d649c23 100644 --- a/packfile.h +++ b/packfile.h @@ -163,7 +163,7 @@ off_t nth_packed_object_offset(const struct packed_git *, uint32_t n); */ off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *); -int is_pack_valid(struct packed_git *); +int is_pack_valid(struct repository *repo, struct packed_git *); void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object_type *, unsigned long *); unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); From patchwork Mon Oct 21 09:57: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: 13843790 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 3EFE71E47AD for ; Mon, 21 Oct 2024 09:58:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504693; cv=none; b=p1n5PLG0882fkIRkHmFMMqzYlarxb2pzGXTFWiia8jxWPc9XIirC00qeeTMB4+I/q+ak6IRX6RFPkeXx/Zlvp6ijRCfN7YSJe9+2LvEEdqsmfyx2uiXfpuLKG6BTgXTtZkwOW+sBLYYMDp4vlugKdA9Q4+W62wM5msBMAqkgkvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504693; c=relaxed/simple; bh=EnjNR1tosf08JiZbLg80/9eTtM6vYqHcN6uV8BNbIyI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XgrYPDS4cVZaLadCG4tBqE6Wcx2pNPotic+QyoPM9JTkzDLTOTWBCl3tO0sOXxjCuqjuhyQEKnKlNCWZreRpjY/1t2F3xpi/Xa9WkEBlJUS4WeO5qvB2h8BvTCGS3MFFpTnSIq+KTcMx7dth+oiiJFFtFA1V0XokO6/SdbSUS7s= 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=i2q7K/T8; arc=none smtp.client-ip=209.85.208.45 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="i2q7K/T8" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5cb6b2b7127so1102947a12.1 for ; Mon, 21 Oct 2024 02:58:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504689; x=1730109489; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wYA+vHFljuEdY7y55LgPB5czkdkxY4NEHWpgPQVq/KI=; b=i2q7K/T8u+dLztNdNADQXPVWmI2hEwZ0BnLWaxsZrSV6fg1sUpvEjLdkYnLDODPjy2 k2psoeZfXuta1/rAMapPPHVSXW/GQWvfldFZntD4WFozDOCn33cG+k40Mhw1Uh8zmXCD 4ddt+ZJpdrAeQt/U8KvM6FTTkkbxaVx545EmRUM5WiLkOdEFmJec0ClNMTyP3w9Fz4Yp CERc2cUissUZgh1CKf+fnQsufA+NN/etmFTxb9v47yDFsr3taQWwS6/MKlTohpf1oVcm 1S82bJvfQW7rceIcDG2n6baAST+cG//PISd+OmCJYmogNJaOfbRFl/xjnt42iDLd/S5k b8LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504689; x=1730109489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wYA+vHFljuEdY7y55LgPB5czkdkxY4NEHWpgPQVq/KI=; b=koAmg1lkQTIYPMBdE0XviAyUigLXmUnvojqvkeZlGoBTk8zpMTpZ4AA1SNiQB5lG/D bRDRM+e5kUoIwVaBS4OO/w3iAb9ffI+Tav2N4nqAJr8G7cWFGFtK0QSBW7N8yuMfn8c7 jiYykRMYkuS4aujRfH7nv3zDjV8f0DxWCH/Z8EStH3oY88HcMHYZM3x+9+69d/Auroq2 01tTWv52JF08dGt/v0+ZadJ5eHIrUrst8QA5P6STLnm5tD7KM9jMxQKNsLQtaZXWdIoH h6eECNcmttyUNguhSMYl9Aij+SI8zc99CqVtpRCEqHx4sMNpa6V5ehZJE82A5OnVW2QR TQtA== X-Gm-Message-State: AOJu0YwzaY1I10rojPq/TGWhMh5e49xm342SGRldHwvjk5XRf/4btjzB tH+RpTQfThZeDKbS+lr+pJp6oF/D0zqrqav8qSpk/pFDuj0bm5F5GiQXM+cF X-Google-Smtp-Source: AGHT+IGUnrTTOk/pr509WGf2jMglKrfoSxj28/yU4x4zOCj6ZKC/h+mdbah89Tx7yo4qJwSApNlIsg== X-Received: by 2002:a17:907:7ea3:b0:a9a:14fc:9868 with SMTP id a640c23a62f3a-a9a6996a599mr1351817966b.4.1729504689211; Mon, 21 Oct 2024 02:58:09 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:08 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 04/20] packfile: pass down repository to `add_packed_git` Date: Mon, 21 Oct 2024 11:57:47 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `add_packed_git` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/fast-import.c | 2 +- builtin/index-pack.c | 6 ++++-- builtin/pack-objects.c | 2 +- commit-graph.c | 2 +- connected.c | 2 +- midx-write.c | 2 +- midx.c | 2 +- packfile.c | 21 +++++++++++---------- packfile.h | 6 ++++-- 9 files changed, 25 insertions(+), 20 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 7ad950627c..51d1cc0deb 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -888,7 +888,7 @@ static void end_packfile(void) idx_name = keep_pack(create_index()); /* Register the packfile with core git's machinery. */ - new_p = add_packed_git(idx_name, strlen(idx_name), 1); + new_p = add_packed_git(the_repository, idx_name, strlen(idx_name), 1); if (!new_p) die("core git rejected index %s", idx_name); all_packs[pack_id] = new_p; diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 97afc69625..eaefb41761 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1552,7 +1552,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name, if (do_fsck_object) { struct packed_git *p; - p = add_packed_git(final_index_name, strlen(final_index_name), 0); + p = add_packed_git(the_repository, final_index_name, + strlen(final_index_name), 0); if (p) install_packed_git(the_repository, p); } @@ -1650,7 +1651,8 @@ static void read_v2_anomalous_offsets(struct packed_git *p, static void read_idx_option(struct pack_idx_option *opts, const char *pack_name) { - struct packed_git *p = add_packed_git(pack_name, strlen(pack_name), 1); + struct packed_git *p = add_packed_git(the_repository, pack_name, + strlen(pack_name), 1); if (!p) die(_("Cannot open existing pack file '%s'"), pack_name); diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index ec321da8dc..26e3090c85 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -2174,7 +2174,7 @@ static void check_object(struct object_entry *entry, uint32_t object_index) * object size from the delta header. */ delta_pos = entry->in_pack_offset + entry->in_pack_header_size; - canonical_size = get_size_from_delta(p, &w_curs, delta_pos); + canonical_size = get_size_from_delta(the_repository, p, &w_curs, delta_pos); if (canonical_size == 0) goto give_up; SET_SIZE(entry, canonical_size); diff --git a/commit-graph.c b/commit-graph.c index 5bd89c0acd..1c333a9c52 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1914,7 +1914,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx, struct packed_git *p; strbuf_setlen(&packname, dirlen); strbuf_addstr(&packname, pack_indexes->items[i].string); - p = add_packed_git(packname.buf, packname.len, 1); + p = add_packed_git(the_repository, packname.buf, packname.len, 1); if (!p) { ret = error(_("error adding pack %s"), packname.buf); goto cleanup; diff --git a/connected.c b/connected.c index 87cc4b57a1..235890efd0 100644 --- a/connected.c +++ b/connected.c @@ -54,7 +54,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data, strbuf_add(&idx_file, transport->pack_lockfiles.items[0].string, base_len); strbuf_addstr(&idx_file, ".idx"); - new_pack = add_packed_git(idx_file.buf, idx_file.len, 1); + new_pack = add_packed_git(the_repository, idx_file.buf, idx_file.len, 1); strbuf_release(&idx_file); } diff --git a/midx-write.c b/midx-write.c index b3a5f6c516..c57726ef94 100644 --- a/midx-write.c +++ b/midx-write.c @@ -154,7 +154,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(full_path, full_path_len, 0); + p = add_packed_git(the_repository, full_path, full_path_len, 0); if (!p) { warning(_("failed to add packfile '%s'"), full_path); diff --git a/midx.c b/midx.c index 4a05f74606..94609456a2 100644 --- a/midx.c +++ b/midx.c @@ -455,7 +455,7 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, strbuf_addf(&pack_name, "%s/pack/%s", m->object_dir, m->pack_names[pack_int_id]); - p = add_packed_git(pack_name.buf, pack_name.len, m->local); + p = add_packed_git(r, pack_name.buf, pack_name.len, m->local); strbuf_release(&pack_name); if (!p) diff --git a/packfile.c b/packfile.c index 4588004223..f300119bb1 100644 --- a/packfile.c +++ b/packfile.c @@ -706,7 +706,8 @@ void unuse_pack(struct pack_window **w_cursor) } } -struct packed_git *add_packed_git(const char *path, size_t path_len, int local) +struct packed_git *add_packed_git(struct repository *repo, const char *path, + size_t path_len, int local) { struct stat st; size_t alloc; @@ -751,9 +752,9 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local) p->pack_size = st.st_size; p->pack_local = local; p->mtime = st.st_mtime; - if (path_len < the_hash_algo->hexsz || - get_hash_hex(path + path_len - the_hash_algo->hexsz, p->hash)) - hashclr(p->hash, the_repository->hash_algo); + if (path_len < repo->hash_algo->hexsz || + get_hash_hex(path + path_len - repo->hash_algo->hexsz, p->hash)) + hashclr(p->hash, repo->hash_algo); return p; } @@ -880,7 +881,8 @@ static void prepare_pack(const char *full_name, size_t full_name_len, /* Don't reopen a pack we already have. */ if (!hashmap_get(&data->r->objects->pack_map, &hent, pack_name)) { - p = add_packed_git(full_name, full_name_len, data->local); + p = add_packed_git(data->r, full_name, full_name_len, + data->local); if (p) install_packed_git(data->r, p); } @@ -1113,9 +1115,8 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf, return used; } -unsigned long get_size_from_delta(struct packed_git *p, - struct pack_window **w_curs, - off_t curpos) +unsigned long get_size_from_delta(struct repository *repo, struct packed_git *p, + struct pack_window **w_curs, off_t curpos) { const unsigned char *data; unsigned char delta_head[20], *in; @@ -1128,7 +1129,7 @@ unsigned long get_size_from_delta(struct packed_git *p, git_inflate_init(&stream); do { - in = use_pack(the_repository, p, w_curs, curpos, &stream.avail_in); + in = use_pack(repo, p, w_curs, curpos, &stream.avail_in); stream.next_in = in; /* * Note: the window section returned by use_pack() must be @@ -1559,7 +1560,7 @@ int packed_object_info(struct repository *r, struct packed_git *p, type = OBJ_BAD; goto out; } - *oi->sizep = get_size_from_delta(p, &w_curs, tmp_pos); + *oi->sizep = get_size_from_delta(r, p, &w_curs, tmp_pos); if (*oi->sizep == 0) { type = OBJ_BAD; goto out; diff --git a/packfile.h b/packfile.h index b74d649c23..22d053a3af 100644 --- a/packfile.h +++ b/packfile.h @@ -117,7 +117,8 @@ void close_pack(struct packed_git *); void close_object_store(struct raw_object_store *o); void unuse_pack(struct pack_window **); void clear_delta_base_cache(void); -struct packed_git *add_packed_git(const char *path, size_t path_len, int local); +struct packed_git *add_packed_git(struct repository *repo, const char *path, + size_t path_len, int local); /* * Unlink the .pack and associated extension files. @@ -166,7 +167,8 @@ off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *); int is_pack_valid(struct repository *repo, struct packed_git *); void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object_type *, unsigned long *); unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); -unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); +unsigned long get_size_from_delta(struct repository *repo, struct packed_git *, + struct pack_window **, off_t); int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *); off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs, off_t *curpos, enum object_type type, From patchwork Mon Oct 21 09:57: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: 13843791 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 D16431E47BD for ; Mon, 21 Oct 2024 09:58:11 +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=1729504694; cv=none; b=iuM/bdaK3uIF5Oc2GkiJ9CLnBb4rAaT0h37z2w2JRHXi1VX+lDw12ioaoVVAW+Xrp7Tch/63eFmR2z66PgpQvqKCuA68R2w9Pt+s3PSLwo2EGiZr5flM0N6wJ4dlQcuPcNDHaJIKDOgC3TP06VoE5THjy7GnX3JlJKE3MnvnxC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504694; c=relaxed/simple; bh=B0LPmqiQZmbIJ2g0ar0HuMFFvitzSjh1PgqH5XuHICs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uBgp7uSmHGdCMngajjKuC+Gs37CWzeoH6XPwbt3DvklBfTd7lBpSWuTmDftaq+A6X5WxQjFPg9rSkfo0pUTX6CiM5UJvpmQVxP4L7T+GgMu4He1fxz4anIv+DtA5oJq9n1b19enwuEpo8hvJ4QmFm+8JwAOP7A147PEERZVmXeM= 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=j9c6DPBl; 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="j9c6DPBl" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a9a0f198d38so593295666b.1 for ; Mon, 21 Oct 2024 02:58:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504690; x=1730109490; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fgOJLPuKYismiXzzTbTXEP0D3rDLowvO3vuFa975RDc=; b=j9c6DPBl5at+Omwsqc4vmvw8LyVD8xMJH9098NTXdLmQckVWxCv7/o2tlmHcqaGd38 IRptd8Z6HSV015KFlOvsb7HcMk3Z+OCaysQI40JBPQIWBeo9mrbUjkhDbV0VWvvcthC3 3qkcfgHheLIYPfmsP2LMIymXRVWZ441W9ZW6EKv+QUJ6kss2PvpciO6Ek/drcEfoQPOv tY1RO2fQtibg6hT/wLcdJf6sJNFXxn6cKsalX5bBIOmPFychla8a9cdPsjkvxfXR87ln W/DmSy+0B02+wKU0Zu8i2Vk+X7afXO6DoZ5GN0yW8Y0aWfd+zh+qJzoGdQIJhor9VHrT BUFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504690; x=1730109490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fgOJLPuKYismiXzzTbTXEP0D3rDLowvO3vuFa975RDc=; b=e8paNeTFjlf7UC0l2RkBvE2/PAYs/bGaNNm1afE6xFKfjd8yMDBz493JUD23aUAPP1 OHva8v29jrtz4qgXLyn9ZlG0x+2QC8q04Yl9V3bAFEDx4TQ/GGbhucQzbwV3uIyEaPf0 4V38lTuA7PI0RF4X/ASCseBXOHSGeop9NHaHQSnjXoipyhbnYmzpXYjZ+ByrDFmGfT2S ClNG/TMKT/PfPGsSmMUqMSQYLeI3jSos6iDoB4abbkTkQlSGwFzS/Emzt4NRQ1WYjJUL nFnucZQm1nMK5RAc/pncLiK0Suh1JmKmb/Hzr2CnGgSDaTHMMVk+TaOEP84jufym4Ez7 S2zw== X-Gm-Message-State: AOJu0Yzl9qsPAkvLpMse9ePj/6UMiXAs74RpI4kyGhNren7dROpcTABa UqTzW3pANQ0Dx/pM0twYMRUfUuHrYmWF3kAKavkjN879SsEqTSpsZKpsLltu X-Google-Smtp-Source: AGHT+IEF4+gVxipP89wtuRbu6Sl+DoaKt1OKI/cOG2EFA1s4ogeB+Eqq1FEwFZxz6KR2YUcSMPJAUA== X-Received: by 2002:a17:907:6e89:b0:a7a:9144:e23a with SMTP id a640c23a62f3a-a9a69c687d8mr1223505366b.43.1729504689822; Mon, 21 Oct 2024 02:58:09 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:09 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 05/20] packfile: pass down repository to `unpack_object_header` Date: Mon, 21 Oct 2024 11:57:48 +0200 Message-ID: <655cfebb9d56fe09835985657944f3550b608f3b.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `unpack_object_header` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/pack-objects.c | 3 ++- pack-bitmap.c | 3 ++- pack-check.c | 3 ++- packfile.c | 13 ++++++------- packfile.h | 3 ++- streaming.c | 4 ++-- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 26e3090c85..3893135b59 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1033,7 +1033,8 @@ static void write_reused_pack_one(struct packed_git *reuse_packfile, offset - (hashfile_total(out) - pack_start)); cur = offset; - type = unpack_object_header(reuse_packfile, w_curs, &cur, &size); + type = unpack_object_header(the_repository, reuse_packfile, w_curs, + &cur, &size); assert(type >= 0); if (type == OBJ_OFS_DELTA) { diff --git a/pack-bitmap.c b/pack-bitmap.c index 067d1741d2..96c91a080e 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -2067,7 +2067,8 @@ static int try_partial_reuse(struct bitmap_index *bitmap_git, return -1; /* not actually in the pack */ delta_obj_offset = offset; - type = unpack_object_header(pack->p, w_curs, &offset, &size); + type = unpack_object_header(the_repository, pack->p, w_curs, &offset, + &size); if (type < 0) return -1; /* broken packfile, punt */ diff --git a/pack-check.c b/pack-check.c index bb649edbc1..e2c3b264e7 100644 --- a/pack-check.c +++ b/pack-check.c @@ -127,7 +127,8 @@ static int verify_packfile(struct repository *r, } curpos = entries[i].offset; - type = unpack_object_header(p, w_curs, &curpos, &size); + type = unpack_object_header(the_repository, p, w_curs, &curpos, + &size); unuse_pack(w_curs); if (type == OBJ_BLOB && big_file_threshold <= size) { diff --git a/packfile.c b/packfile.c index f300119bb1..7a0d1957e9 100644 --- a/packfile.c +++ b/packfile.c @@ -1169,9 +1169,8 @@ unsigned long get_size_from_delta(struct repository *repo, struct packed_git *p, return get_delta_hdr_size(&data, delta_head+sizeof(delta_head)); } -int unpack_object_header(struct packed_git *p, - struct pack_window **w_curs, - off_t *curpos, +int unpack_object_header(struct repository *r, struct packed_git *p, + struct pack_window **w_curs, off_t *curpos, unsigned long *sizep) { unsigned char *base; @@ -1185,7 +1184,7 @@ int unpack_object_header(struct packed_git *p, * the maximum deflated object size is 2^137, which is just * insane, so we know won't exceed what we have been given. */ - base = use_pack(the_repository, p, w_curs, *curpos, &left); + base = use_pack(r, p, w_curs, *curpos, &left); used = unpack_object_header_buffer(base, left, &type, sizep); if (!used) { type = OBJ_BAD; @@ -1332,7 +1331,7 @@ static enum object_type packed_to_object_type(struct repository *r, if (!base_offset) goto unwind; curpos = obj_offset = base_offset; - type = unpack_object_header(p, w_curs, &curpos, &size); + type = unpack_object_header(r, p, w_curs, &curpos, &size); if (type <= OBJ_NONE) { /* If getting the base itself fails, we first * retry the base, otherwise unwind */ @@ -1548,7 +1547,7 @@ int packed_object_info(struct repository *r, struct packed_git *p, if (!*oi->contentp) type = OBJ_BAD; } else { - type = unpack_object_header(p, &w_curs, &curpos, &size); + type = unpack_object_header(r, p, &w_curs, &curpos, &size); } if (!oi->contentp && oi->sizep) { @@ -1736,7 +1735,7 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset, } } - type = unpack_object_header(p, &w_curs, &curpos, &size); + type = unpack_object_header(r, p, &w_curs, &curpos, &size); if (type != OBJ_OFS_DELTA && type != OBJ_REF_DELTA) break; diff --git a/packfile.h b/packfile.h index 22d053a3af..488d78ae9f 100644 --- a/packfile.h +++ b/packfile.h @@ -169,7 +169,8 @@ void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); unsigned long get_size_from_delta(struct repository *repo, struct packed_git *, struct pack_window **, off_t); -int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *); +int unpack_object_header(struct repository *repo, struct packed_git *, + struct pack_window **, off_t *, unsigned long *); off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs, off_t *curpos, enum object_type type, off_t delta_obj_offset); diff --git a/streaming.c b/streaming.c index 58b3b3cff7..56154349fa 100644 --- a/streaming.c +++ b/streaming.c @@ -334,7 +334,7 @@ static int close_istream_pack_non_delta(struct git_istream *st) } static int open_istream_pack_non_delta(struct git_istream *st, - struct repository *r UNUSED, + struct repository *r, const struct object_id *oid UNUSED, enum object_type *type UNUSED) { @@ -343,7 +343,7 @@ static int open_istream_pack_non_delta(struct git_istream *st, window = NULL; - in_pack_type = unpack_object_header(st->u.in_pack.pack, + in_pack_type = unpack_object_header(r, st->u.in_pack.pack, &window, &st->u.in_pack.pos, &st->size); From patchwork Mon Oct 21 09:57: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: 13843792 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 04D131E4929 for ; Mon, 21 Oct 2024 09:58:12 +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=1729504695; cv=none; b=lhVCxgsUK2J/u8AigbisF3TyTmHPivDBZZrNRKr3Ig1BURZhnXGJrSHaKKeZHqjwnggmQAR1HzVKBKLjfVZz4cC0JsXW7Jq42pXd4j/jpGcLbDUXmuVwRTmYtfEFuShXyZ93f8JysmEDBmj0bpWtF2Wtc/9EL8koDLZXPueGw8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504695; c=relaxed/simple; bh=niUINvO1vNuxjzBti+OmNsuy/SGu7NurEpumxp14UgQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nPxl78lp4DxCNRkcCMYobv/wflIZs0oe9whJzsLhR+qOYvCnJZqP+ihpMWjvNusibJFJYj5yK3oqabsYY1YZDQOg5iiQ2oYvnO2UAACE+0l9qggWcAfulvUhybzV1fuowbOHE4C9tp2j/3kDkR1cSn3R+E+HG2YP8C3byZTUT6g= 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=Lqgvs0is; 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="Lqgvs0is" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5c9709c9b0cso5632164a12.1 for ; Mon, 21 Oct 2024 02:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504691; x=1730109491; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q7jiJAi81XdzHW64+d9MwKxMmLDfXaobr0ej0UgT+EA=; b=Lqgvs0isyycuKzhMdbA74wLEHKPOPP6YYdf/Yf4SbywgwTm/Fd5NhXSMNosAg+f1jJ bDP82QI4BcEr+xHrxIkfU2wjuJbFJG/Pcc7g217qGUCcBNab4zGdyTkSYmgwbU4IG0ew HJWrqjhrBc7Z6TcN9sko+OpO81Or4h4E40hOt2U1vlKvGqO1Eas6eLW1fAuwwS3eSTnp ZkAzP6ghtDOapCUAO/02TZ53qSkRvqZZu6LAX3yeq9tv6Nr9HsgpH6g/qN4kPtzDlARV 6eQULEUFf21HW1Dr+kklJQRJKf2h7u5mA66U6i6OWLJVx3X8TMLUmEzGPNWUha8/RCwl b7+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504691; x=1730109491; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q7jiJAi81XdzHW64+d9MwKxMmLDfXaobr0ej0UgT+EA=; b=Q4g6e4jsYvfq6UfUaL7iu79qfD6eX1DBLjeEowqvm1UfGIlQGzhVicBK/nm/Pjaa2D GvJGqHj2nxZVDeHn44NZ2yCS9lMwiD+Dw6RUvoW1JWzNkDx/jCEpNMIs2QZzEqO7kwFd XNm3Z99fe4R11xz5Y4xsJ0IyjJTBi8ISly3sp1/M3acv8khZFlsTi2XKLlOn3iDRRtCa iHgl55gfdXY0Z5tVBNBuS1E+e0G1oKIweDTacI+JkoG4tetyvc7dP+gqLLZobS/5FYCb LGECVqcrWCxr9nLw+nn2RFF8l7X0gxupyDoGAVe4+4cBbRg5kje9IoKwE74KfZl58r7q jLmA== X-Gm-Message-State: AOJu0YxtK2dzXPedWLSdu7sETNzmWOxbK6lwK7FIZbe5PSHt1WiwLZaD eyDw/LPRh2Nm4WAtiaHqUlXToO23jLYmf6gcGmMG+UdzSS7dwtkLh3+5aMpN X-Google-Smtp-Source: AGHT+IFCpylEsgZch27huftmmCAzNC/oJkGbSyky4HaYkf/1sjJZu7Bx5vEDdrvexma7IXxSiHpVww== X-Received: by 2002:a17:907:3d88:b0:a99:f8a2:cd8f with SMTP id a640c23a62f3a-a9a69cdcacamr904314766b.64.1729504690953; Mon, 21 Oct 2024 02:58:10 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:10 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 06/20] packfile: pass down repository to `get_delta_base` Date: Mon, 21 Oct 2024 11:57:49 +0200 Message-ID: <18fa001e3a8c1ffa75b818d9918e8c8bbea261cf.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `get_delta_base` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/pack-objects.c | 3 ++- pack-bitmap.c | 4 ++-- packfile.c | 42 ++++++++++++++++++++---------------------- packfile.h | 6 +++--- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 3893135b59..a10eae239e 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1044,7 +1044,8 @@ static void write_reused_pack_one(struct packed_git *reuse_packfile, unsigned char header[MAX_PACK_OBJECT_HEADER]; unsigned len; - base_offset = get_delta_base(reuse_packfile, w_curs, &cur, type, offset); + base_offset = get_delta_base(the_repository, reuse_packfile, + w_curs, &cur, type, offset); assert(base_offset != 0); /* Convert to REF_DELTA if we must... */ diff --git a/pack-bitmap.c b/pack-bitmap.c index 96c91a080e..d959e30682 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -2085,8 +2085,8 @@ static int try_partial_reuse(struct bitmap_index *bitmap_git, * and the normal slow path will complain about it in * more detail. */ - base_offset = get_delta_base(pack->p, w_curs, &offset, type, - delta_obj_offset); + base_offset = get_delta_base(the_repository, pack->p, w_curs, + &offset, type, delta_obj_offset); if (!base_offset) return 0; diff --git a/packfile.c b/packfile.c index 7a0d1957e9..ee46898b35 100644 --- a/packfile.c +++ b/packfile.c @@ -1210,13 +1210,11 @@ const struct packed_git *has_packed_and_bad(struct repository *r, return NULL; } -off_t get_delta_base(struct packed_git *p, - struct pack_window **w_curs, - off_t *curpos, - enum object_type type, - off_t delta_obj_offset) +off_t get_delta_base(struct repository *repo, struct packed_git *p, + struct pack_window **w_curs, off_t *curpos, + enum object_type type, off_t delta_obj_offset) { - unsigned char *base_info = use_pack(the_repository, p, w_curs, *curpos, NULL); + unsigned char *base_info = use_pack(repo, p, w_curs, *curpos, NULL); off_t base_offset; /* use_pack() assured us we have [base_info, base_info + 20) @@ -1243,7 +1241,7 @@ off_t get_delta_base(struct packed_git *p, } else if (type == OBJ_REF_DELTA) { /* The base entry _must_ be in the same pack */ base_offset = find_pack_entry_one(base_info, p); - *curpos += the_hash_algo->rawsz; + *curpos += repo->hash_algo->rawsz; } else die("I am totally screwed"); return base_offset; @@ -1255,22 +1253,19 @@ off_t get_delta_base(struct packed_git *p, * the final object lookup), but more expensive for OFS deltas (we * have to load the revidx to convert the offset back into a sha1). */ -static int get_delta_base_oid(struct packed_git *p, - struct pack_window **w_curs, - off_t curpos, - struct object_id *oid, - enum object_type type, +static int get_delta_base_oid(struct repository *repo, struct packed_git *p, + struct pack_window **w_curs, off_t curpos, + struct object_id *oid, enum object_type type, off_t delta_obj_offset) { if (type == OBJ_REF_DELTA) { - unsigned char *base = use_pack(the_repository, p, w_curs, - curpos, NULL); - oidread(oid, base, the_repository->hash_algo); + unsigned char *base = use_pack(repo, p, w_curs, curpos, NULL); + oidread(oid, base, repo->hash_algo); return 0; } else if (type == OBJ_OFS_DELTA) { uint32_t base_pos; - off_t base_offset = get_delta_base(p, w_curs, &curpos, - type, delta_obj_offset); + off_t base_offset = get_delta_base(repo, p, w_curs, &curpos, type, + delta_obj_offset); if (!base_offset) return -1; @@ -1327,7 +1322,8 @@ static enum object_type packed_to_object_type(struct repository *r, } poi_stack[poi_stack_nr++] = obj_offset; /* If parsing the base offset fails, just unwind */ - base_offset = get_delta_base(p, w_curs, &curpos, type, obj_offset); + base_offset = get_delta_base(r, p, w_curs, &curpos, type, + obj_offset); if (!base_offset) goto unwind; curpos = obj_offset = base_offset; @@ -1553,8 +1549,9 @@ int packed_object_info(struct repository *r, struct packed_git *p, if (!oi->contentp && oi->sizep) { if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) { off_t tmp_pos = curpos; - off_t base_offset = get_delta_base(p, &w_curs, &tmp_pos, - type, obj_offset); + off_t base_offset = get_delta_base(r, p, &w_curs, + &tmp_pos, type, + obj_offset); if (!base_offset) { type = OBJ_BAD; goto out; @@ -1600,7 +1597,7 @@ int packed_object_info(struct repository *r, struct packed_git *p, if (oi->delta_base_oid) { if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) { - if (get_delta_base_oid(p, &w_curs, curpos, + if (get_delta_base_oid(r, p, &w_curs, curpos, oi->delta_base_oid, type, obj_offset) < 0) { type = OBJ_BAD; @@ -1739,7 +1736,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset, if (type != OBJ_OFS_DELTA && type != OBJ_REF_DELTA) break; - base_offset = get_delta_base(p, &w_curs, &curpos, type, obj_offset); + base_offset = get_delta_base(r, p, &w_curs, &curpos, type, + obj_offset); if (!base_offset) { error("failed to validate delta base reference " "at offset %"PRIuMAX" from %s", diff --git a/packfile.h b/packfile.h index 488d78ae9f..050dc516b1 100644 --- a/packfile.h +++ b/packfile.h @@ -171,9 +171,9 @@ unsigned long get_size_from_delta(struct repository *repo, struct packed_git *, struct pack_window **, off_t); int unpack_object_header(struct repository *repo, struct packed_git *, struct pack_window **, off_t *, unsigned long *); -off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs, - off_t *curpos, enum object_type type, - off_t delta_obj_offset); +off_t get_delta_base(struct repository *repo, struct packed_git *p, + struct pack_window **w_curs, off_t *curpos, + enum object_type type, off_t delta_obj_offset); void release_pack_memory(size_t); From patchwork Mon Oct 21 09:57:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843793 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 9950E1E47C8 for ; Mon, 21 Oct 2024 09:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504695; cv=none; b=PJYdv3x+4+EDGFpj4sOtIrxLU9e6FOlmEoh+bqPZxY19qpPPvLNmvm1pmtl/6HncLiE9p0gWG8WWC9m1NruuELLUN8HfmXjTKm/sSj39Tx05KONaKDELEez8m0OLIYH0pTNNVGSYDS6ILhiiF5+ZwaaeMsXbVfR5nT5NGPh+/0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504695; c=relaxed/simple; bh=5bb9Vgl+jYaPxtriVllETwB8YyW+hxEScXilwl7s2RQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HF+7ZB7dCWwJrTAKQm3vu3DjBTxMG1ZoZwLp7pHiIq6hgUw9mTeKGmeDCyNHahRv6sCMLF5gIDEGaQeXYHEVUuRGhnPiy9EaXHjhOCKxm0VYMz+5libaaEIIb/sYpp04RO2uuyCo8MNEZmgeBml09fcf048fWetKIR9NSmr2HpA= 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=CIr9DAFm; arc=none smtp.client-ip=209.85.167.53 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="CIr9DAFm" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-539e1543ab8so7034034e87.2 for ; Mon, 21 Oct 2024 02:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504692; x=1730109492; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s/jiWHo1D60Uhm7L875Asb1ENurKyQUKinkttkd7R6A=; b=CIr9DAFmxBl+H6hpaUx7voXgbMEVjdkDS4vBzAF9X+oe34uSa3q3weyMo6xOsvlQ+B J4G72TEGglhz6LfOvLJ3Xl4MjtO/VNVnZedPixIo2JSiOvwRLw7TXjUZINQ7jtZfqZvC boqbvaEav7dPBWMTw4S569y1f/Qc3Vz3MIWcPbE0ZimEb1aago+iQSFlZ8cNTQXrTE7J M6aroZfY+ab1YEDQgAPTFYXiwXjmv+4WjxFNQc1hql+/ZvGL09i5nfIGlct+ohkbkN3J rJtOiBYau0mVebnxEwdMXbyZGl0nwsGaG4geSTV19lrlzRQ96SsS6uRwk/6CPFbi8jxx JrNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504692; x=1730109492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s/jiWHo1D60Uhm7L875Asb1ENurKyQUKinkttkd7R6A=; b=A7X+Jzim5LeMSG3440MssvjZwce0OfLcLJO6QgrchsRuKXIqapE2QKZvdCRhTSRGM5 UBUmO2nNkNyfKIj4vW9f/Iq64FdC3RGWQqr6Wi5AEtAC57fU25RGiKWToJ0S6jEyTh8f tFvlZ7wyhlV56wppYqJfJaFp8bFRMCO7e1e/DGklK2lbbIu49FYID4Vs1zSH0L9bDAjV XNij3vhCrmPKW3nTi189p02N3/68M9wdZTc7TJYWUK8fzht54n+pLIoEcrWtYCzsh7a7 UHPuDIlMlL10dvAaMJKxTMXoibZJPVGy3xGGLkee8/3TFHVHBdchFGZws+0XGnM+4jej JwPQ== X-Gm-Message-State: AOJu0YyjSG+PoYiPgQNQb2+55ZyY6FxwmYfNnl2AKdqXKjBZSgxMGVmc schFiUdJ6oeTuwnqELwE8URTG0wqcoB8+2zVckLerdHR24rLn/C5URiA/gxf X-Google-Smtp-Source: AGHT+IFtetdTvbRA5UHXCuAJx6qLFIVlG/9uz7hYMiOXDDbBr7EPfoaFBaqBx+nMClpmv26x361tPQ== X-Received: by 2002:a05:6512:1091:b0:539:94f5:bf with SMTP id 2adb3069b0e04-53a154eb367mr8409081e87.59.1729504691578; Mon, 21 Oct 2024 02:58:11 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:11 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 07/20] packfile: use provided repository in `packed_object_info` Date: Mon, 21 Oct 2024 11:57:50 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `packed_object_info` receives a repository struct as an argument. Yet, it still uses the global 'the_repository' variable within, let's swap it with the provided repository variable. Signed-off-by: Karthik Nayak --- builtin/pack-objects.c | 2 +- packfile.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index a10eae239e..c2555d4986 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3383,7 +3383,7 @@ static int add_object_entry_from_pack(const struct object_id *oid, struct object_info oi = OBJECT_INFO_INIT; oi.typep = &type; - if (packed_object_info(the_repository, p, ofs, &oi) < 0) { + if (packed_object_info(revs->repo, p, ofs, &oi) < 0) { die(_("could not get type of object %s in pack %s"), oid_to_hex(oid), p->pack_name); } else if (type == OBJ_COMMIT) { diff --git a/packfile.c b/packfile.c index ee46898b35..458db59b3a 100644 --- a/packfile.c +++ b/packfile.c @@ -1604,7 +1604,7 @@ int packed_object_info(struct repository *r, struct packed_git *p, goto out; } } else - oidclr(oi->delta_base_oid, the_repository->hash_algo); + oidclr(oi->delta_base_oid, r->hash_algo); } oi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED : From patchwork Mon Oct 21 09:57:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843794 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.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 5EFF21E5709 for ; Mon, 21 Oct 2024 09:58:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504696; cv=none; b=QjnAorWSmeKSOG7kCBP0/gmhp4xgjGIiF64GcIVxwNiv99AHHcCESxyFyQY/TC2aZWM2Hxm3WJcpV/4BWQDw8rUkyMsUK2cOoFO8Y6o98gFVxrbo2n9zxHe7Syvew1Qx7+OE8Vnx6UW2WDFL88HeFYzB0b5viFcUmxNiOLpBjQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504696; c=relaxed/simple; bh=7R9D53vMveTBoquoK5KiAzyv7NbQGhCOWci7OAZjprc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QYzXwu/BwWJqAIaW7jUUsJbWQOSsbLblNZqphhMm1BnrWi0CuM1q150TgPSj7fbXA5s3CgbG/t0knIbHyXZrh1glHAWnQ42/af6dkGEF5Z7eomtPRohyAbwar+SZeoniDmp3erIUJ8HfO7NQu697p40tXu28Sdk/nwQsmOCQbRI= 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=FfLE2DeI; arc=none smtp.client-ip=209.85.218.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="FfLE2DeI" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a9a0c7abaa6so508832966b.2 for ; Mon, 21 Oct 2024 02:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504693; x=1730109493; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K07S/EzEEiacNTiHvYWjPNAW5dH16XFWmyLdObkYBxc=; b=FfLE2DeILGKu2GpylPBH38aWa7/JbHbYoCgrFiDA8/wYWqGVnrj7DtZQTKKRgPZpax I2oMb2mmqi3oNGW//nWYP5Cecd33egqyyRtQ3r9ATD+HgoA3Iyz3gDMY9Wy0m4c+DuXx SFnN/AoPhjXCpHhT3V/f+o2WXpaYem7ktm3dl61AmllF5wUqU4JFtflIrx1WlUEsiE6b fG9tOnGW6XyPLiw1s0Cz3+1spEnjPsMSh3CEurRGIMg7greIRrAF1Gsya1iZPb55TfMF GbugKdJdybDQm4ns2cT3MuxqVEHH02/wHyjJUyce8h19gXiexUSOoGxc2dOVXZJ7R49i REbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504693; x=1730109493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K07S/EzEEiacNTiHvYWjPNAW5dH16XFWmyLdObkYBxc=; b=enBKrMny4fHOBypFffQlTPolBfZZH5sdQX9lx6gbPEOr6FqBXnspm2elrHvukdskwp ZMYXQeskPXsgvV6KkckqiKlxXkVCqkKrOfUv5yYNWTOAXrYGtEEU3hlaI02h3G4cP/Sn IAQiTbEGo58Le2omeSwwY7dKboAbg+aWcX1m1ZwppFVwMGfyT4m++lLhqkodiApsLbfq o8cPmaLRaUnvOONvJFfCGQSAh/MfykiS6FMR4s/ix690piHgKzlZGPWbmKLh0rjJjxiN uWA6axXdKH6ori+MN5X1aKS35qWQDciEHL1szlG/p+adsfcnqpwcSMtdxRFk4hkPPTuI 4jBw== X-Gm-Message-State: AOJu0YxERbTHs7sfXjAnG5UipOFjFpyGVWQQcOQ0f+b/DrsR7KJq3Wnd zW0QWyD0/RwiEfZ19Z0yjWLaCkUE13aQj2rinw0/sllP5FtF8vNyDnCb8YJQ X-Google-Smtp-Source: AGHT+IEGD4swbFnoLSkoP6PB3253fmoA6ZkRtlKAU8t0zppjusOL5nPG3RjVUuJ4jqSBX8RyDwRXSA== X-Received: by 2002:a17:907:7250:b0:a99:3a3d:9611 with SMTP id a640c23a62f3a-a9a69ccc958mr1050310266b.50.1729504692407; Mon, 21 Oct 2024 02:58:12 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:12 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 08/20] packfile: pass down repository to `unpack_compressed_entry` Date: Mon, 21 Oct 2024 11:57:51 +0200 Message-ID: <72cdb128c17f3f87f2506b3158b09cfcb58206d3.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `unpack_compressed_entry` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function. Signed-off-by: Karthik Nayak --- packfile.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packfile.c b/packfile.c index 458db59b3a..54f3b9f0a7 100644 --- a/packfile.c +++ b/packfile.c @@ -1615,10 +1615,11 @@ int packed_object_info(struct repository *r, struct packed_git *p, return type; } -static void *unpack_compressed_entry(struct packed_git *p, - struct pack_window **w_curs, - off_t curpos, - unsigned long size) +static void *unpack_compressed_entry(struct repository *repo, + struct packed_git *p, + struct pack_window **w_curs, + off_t curpos, + unsigned long size) { int st; git_zstream stream; @@ -1633,8 +1634,7 @@ static void *unpack_compressed_entry(struct packed_git *p, git_inflate_init(&stream); do { - in = use_pack(the_repository, p, w_curs, curpos, - &stream.avail_in); + in = use_pack(repo, p, w_curs, curpos, &stream.avail_in); stream.next_in = in; /* * Note: we must ensure the window section returned by @@ -1777,7 +1777,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset, case OBJ_BLOB: case OBJ_TAG: if (!base_from_cache) - data = unpack_compressed_entry(p, &w_curs, curpos, size); + data = unpack_compressed_entry(r, p, &w_curs, curpos, + size); break; default: data = NULL; @@ -1838,7 +1839,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset, if (!base) continue; - delta_data = unpack_compressed_entry(p, &w_curs, curpos, delta_size); + delta_data = unpack_compressed_entry(r, p, &w_curs, curpos, + delta_size); if (!delta_data) { error("failed to unpack compressed delta " From patchwork Mon Oct 21 09:57:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843795 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 EC5EE1E5716 for ; Mon, 21 Oct 2024 09:58:14 +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=1729504697; cv=none; b=N4fk58X+yB1zIfjlbXFJdzzSzTCYQtroxa41UwtSFFU6aO9vMunpqfpEf8J3dbY8tK1RDkrl0jfJB/cxyKvrNoZJDbJEJEkT7taPpbL2z9TgbhllV14T8PdTwZ/dSBq4WskQqIim788byif2imw6a7Q/vJY3YtAlqgGUQ1qQcrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504697; c=relaxed/simple; bh=jK5Ud3UjBkMfpSOSLo6sp4JhblnX8Eu+mMUdU4nqX9E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PpZ//7QtK5MqUi1f051xUha5vG+zd5lVqukXbiagpFv00HaDYx5J9pzbGzX8vLZVUXuEB5bUCbW+/l7LtjJVc24UoTHb0LKlnLtIJ3AykqPiwxOc3PZ0CrBRTdWXB3hLdXlph5K1tQSqDrX4C4dTlJsuHJ8crP7r1Af5+xuOIQA= 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=dfpL6eYn; 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="dfpL6eYn" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a86e9db75b9so557231466b.1 for ; Mon, 21 Oct 2024 02:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504693; x=1730109493; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PVsxLA3IKQXCOUU+AB2r86BKiNH8MPzO1dv5XX2J17w=; b=dfpL6eYnz6MTZRwrx471NinnuXtc8r43W0bvwxPb3inKwNULzC1522ZeOzGcgAnOH5 ErEW7LpHV2MqN+DWM3oCPamgH8b7J3yPxv2yQvzMjlmoYxUeF/HQEKSzS1Xu4m/qF4IS s1ug5Pj5IanqnWOYDpZ6a3AnDuRfKAWhfE9X/qBb3i7iCnkhN3XXCtoNT/LA0lhgx8I5 9Wb8nzW6g2hNU2vVCO33o3JgwbIEeVixQDOwEJiV6fWX/T42mLAVitPNuHn0Jo5psFG4 s3nhjL5AWadsupnez74Qas8/EvDHalpIKbuVvLEt0rGWkSy5RwKIE1Hs+EU6Wa28u6av bIRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504693; x=1730109493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PVsxLA3IKQXCOUU+AB2r86BKiNH8MPzO1dv5XX2J17w=; b=KkBz6D9GA8Ipz94b0Mtw8K8GmjRtUn6TKvDY/8+wDjC+yxnJhbF9823llTy8LGdsu+ wgIk6G3oKYxUR2wiUdi2HQT+AWjYY7WR7+GEs0WiWRFELvkpIHZWmIG4WV18JvOxc9Br BNQJqT+IuH5HWiciwzE7pEmNPV4Px5NSQIlshs6VCxcTCPI4l/UurkoxNG4OA9J3ZYW7 J0CFWFJqi4CgXTQVfXraflw8/WnEU2GnJ6CrxNjtikqbsQIRtEe5eIrb4hn25urqsPTd VF+Q9XkvwOX6ljZFfBh38zUqbdwIz90Bmd2REFgz3mLVc10hTvD7eQraPXU++ckLDd+l /0hw== X-Gm-Message-State: AOJu0YyWx0OwPeGZntYAo6LLWoOUnnWJ7BXEXR4m+FGH5hccmB5iYt4t 8vorZL+hEuJEL6j5xJ5mSQf9Y4a0n8zzGhRXuvrmGZCq2oYHi6qh6XIIhBbu X-Google-Smtp-Source: AGHT+IEhy6L5CTPObrnUA7N8oFIFF0wIbshU4GWLsvovDX+H0n2S+OP4gkER6u01yvSiSn+VMlXitg== X-Received: by 2002:a17:907:3a95:b0:a9a:80f9:d4e0 with SMTP id a640c23a62f3a-a9a80f9d8bamr550164066b.34.1729504693089; Mon, 21 Oct 2024 02:58:13 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:12 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 09/20] packfile: pass down repository to `nth_packed_object_id` Date: Mon, 21 Oct 2024 11:57:52 +0200 Message-ID: <4f72ad569d004bc1401087254277b40301035106.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `nth_packed_object_id` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/pack-objects.c | 6 +++--- midx-write.c | 2 +- object-name.c | 8 ++++---- pack-bitmap.c | 2 +- pack-check.c | 2 +- packfile.c | 21 ++++++++++----------- packfile.h | 3 ++- t/helper/test-pack-mtimes.c | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index c2555d4986..adf55d892f 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1059,7 +1059,7 @@ static void write_reused_pack_one(struct packed_git *reuse_packfile, (uintmax_t)base_offset, reuse_packfile->pack_name); - nth_packed_object_id(&base_oid, reuse_packfile, + nth_packed_object_id(the_repository, &base_oid, reuse_packfile, pack_pos_to_index(reuse_packfile, base_pos)); len = encode_in_pack_object_header(header, sizeof(header), @@ -2141,7 +2141,7 @@ static void check_object(struct object_entry *entry, uint32_t object_index) uint32_t pos; if (offset_to_pack_pos(p, ofs, &pos) < 0) goto give_up; - if (!nth_packed_object_id(&base_ref, p, + if (!nth_packed_object_id(the_repository, &base_ref, p, pack_pos_to_index(p, pos))) have_base = 1; } @@ -4036,7 +4036,7 @@ static void loosen_unused_packed_objects(void) die(_("cannot open pack index")); for (i = 0; i < p->num_objects; i++) { - nth_packed_object_id(&oid, p, i); + nth_packed_object_id(the_repository, &oid, p, i); if (!packlist_find(&to_pack, &oid) && !has_sha1_pack_kept_or_nonlocal(&oid) && !loosened_object_can_be_discarded(&oid, p->mtime)) { diff --git a/midx-write.c b/midx-write.c index c57726ef94..4696b8326c 100644 --- a/midx-write.c +++ b/midx-write.c @@ -227,7 +227,7 @@ static void fill_pack_entry(uint32_t pack_int_id, struct pack_midx_entry *entry, int preferred) { - if (nth_packed_object_id(&entry->oid, p, cur_object) < 0) + if (nth_packed_object_id(the_repository, &entry->oid, p, cur_object) < 0) die(_("failed to locate object %d in packfile"), cur_object); entry->pack_int_id = pack_int_id; diff --git a/object-name.c b/object-name.c index c892fbe80a..43023884ef 100644 --- a/object-name.c +++ b/object-name.c @@ -188,7 +188,7 @@ static void unique_in_pack(struct packed_git *p, */ for (i = first; i < num && !ds->ambiguous; i++) { struct object_id oid; - nth_packed_object_id(&oid, p, i); + nth_packed_object_id(ds->repo, &oid, p, i); if (!match_hash(len, ds->bin_pfx.hash, oid.hash)) break; update_candidates(ds, &oid); @@ -776,14 +776,14 @@ static void find_abbrev_len_for_pack(struct packed_git *p, */ mad->init_len = 0; if (!match) { - if (!nth_packed_object_id(&oid, p, first)) + if (!nth_packed_object_id(mad->repo, &oid, p, first)) extend_abbrev_len(&oid, mad); } else if (first < num - 1) { - if (!nth_packed_object_id(&oid, p, first + 1)) + if (!nth_packed_object_id(mad->repo, &oid, p, first + 1)) extend_abbrev_len(&oid, mad); } if (first > 0) { - if (!nth_packed_object_id(&oid, p, first - 1)) + if (!nth_packed_object_id(mad->repo, &oid, p, first - 1)) extend_abbrev_len(&oid, mad); } mad->init_len = mad->cur_len; diff --git a/pack-bitmap.c b/pack-bitmap.c index d959e30682..96716c785b 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -318,7 +318,7 @@ static int nth_bitmap_object_oid(struct bitmap_index *index, { if (index->midx) return nth_midxed_object_oid(oid, index->midx, n) ? 0 : -1; - return nth_packed_object_id(oid, index->pack, n); + return nth_packed_object_id(the_repository, oid, index->pack, n); } static int load_bitmap_entries_v1(struct bitmap_index *index) diff --git a/pack-check.c b/pack-check.c index e2c3b264e7..a5551809c1 100644 --- a/pack-check.c +++ b/pack-check.c @@ -111,7 +111,7 @@ static int verify_packfile(struct repository *r, off_t curpos; int data_valid; - if (nth_packed_object_id(&oid, p, entries[i].nr) < 0) + if (nth_packed_object_id(r, &oid, p, entries[i].nr) < 0) BUG("unable to get oid of object %lu from %s", (unsigned long)entries[i].nr, p->pack_name); diff --git a/packfile.c b/packfile.c index 54f3b9f0a7..92c919d628 100644 --- a/packfile.c +++ b/packfile.c @@ -1273,7 +1273,7 @@ static int get_delta_base_oid(struct repository *repo, struct packed_git *p, if (offset_to_pack_pos(p, base_offset, &base_pos) < 0) return -1; - return nth_packed_object_id(oid, p, + return nth_packed_object_id(repo, oid, p, pack_pos_to_index(p, base_pos)); } else return -1; @@ -1288,7 +1288,7 @@ static int retry_bad_packed_offset(struct repository *r, struct object_id oid; if (offset_to_pack_pos(p, obj_offset, &pos) < 0) return OBJ_BAD; - nth_packed_object_id(&oid, p, pack_pos_to_index(p, pos)); + nth_packed_object_id(r, &oid, p, pack_pos_to_index(p, pos)); mark_bad_packed_object(p, &oid); type = oid_object_info(r, &oid, NULL); if (type <= OBJ_NONE) @@ -1723,7 +1723,7 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset, index_pos = pack_pos_to_index(p, pack_pos); if (check_pack_crc(p, &w_curs, obj_offset, len, index_pos)) { struct object_id oid; - nth_packed_object_id(&oid, p, index_pos); + nth_packed_object_id(r, &oid, p, index_pos); error("bad packed object CRC for %s", oid_to_hex(&oid)); mark_bad_packed_object(p, &oid); @@ -1813,7 +1813,7 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset, if (!(offset_to_pack_pos(p, obj_offset, &pos))) { struct object_info oi = OBJECT_INFO_INIT; - nth_packed_object_id(&base_oid, p, + nth_packed_object_id(r, &base_oid, p, pack_pos_to_index(p, pos)); error("failed to read delta base object %s" " at offset %"PRIuMAX" from %s", @@ -1917,12 +1917,11 @@ int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32 index_lookup, index_lookup_width, result); } -int nth_packed_object_id(struct object_id *oid, - struct packed_git *p, - uint32_t n) +int nth_packed_object_id(struct repository *repo, struct object_id *oid, + struct packed_git *p, uint32_t n) { const unsigned char *index = p->index_data; - const unsigned int hashsz = the_hash_algo->rawsz; + const unsigned int hashsz = repo->hash_algo->rawsz; if (!index) { if (open_pack_index(p)) return -1; @@ -1933,11 +1932,11 @@ int nth_packed_object_id(struct object_id *oid, index += 4 * 256; if (p->index_version == 1) { oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4), - the_repository->hash_algo); + repo->hash_algo); } else { index += 8; oidread(oid, index + st_mult(hashsz, n), - the_repository->hash_algo); + repo->hash_algo); } return 0; } @@ -2194,7 +2193,7 @@ int for_each_object_in_pack(struct packed_git *p, else index_pos = i; - if (nth_packed_object_id(&oid, p, index_pos) < 0) + if (nth_packed_object_id(the_repository, &oid, p, index_pos) < 0) return error("unable to get sha1 of object %u in %s", index_pos, p->pack_name); diff --git a/packfile.h b/packfile.h index 050dc516b1..f744af6e9b 100644 --- a/packfile.h +++ b/packfile.h @@ -150,7 +150,8 @@ int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32 * parameter. Open the index if it is not already open. Returns 0 on success, * negative otherwise. */ -int nth_packed_object_id(struct object_id *, struct packed_git *, uint32_t n); +int nth_packed_object_id(struct repository *repo, struct object_id *, + struct packed_git *, uint32_t n); /* * Return the offset of the nth object within the specified packfile. diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c index f8f9afbb5b..ebd980b308 100644 --- a/t/helper/test-pack-mtimes.c +++ b/t/helper/test-pack-mtimes.c @@ -16,7 +16,7 @@ static void dump_mtimes(struct packed_git *p) for (i = 0; i < p->num_objects; i++) { struct object_id oid; - if (nth_packed_object_id(&oid, p, i) < 0) + if (nth_packed_object_id(the_repository, &oid, p, i) < 0) die("could not load object id at position %"PRIu32, i); printf("%s %"PRIu32"\n", From patchwork Mon Oct 21 09:57:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843796 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.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 67FC81E5737 for ; Mon, 21 Oct 2024 09:58:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504698; cv=none; b=S+ZhHKs8t6Sj2ybKd1tavIz5hdP94kzjKE/44jOtcdq9/1HuKW9XPfnaRfXxxaWh0oJYYkPk3wu0Z0Vu3z8sZm16++t+4OrzNY//PDFGElBZ3TDuAFkWVW7EokONOUn0x9l5dKxFydqkd/x3lkahkAiMQ6taegUO4K9JVnaPsN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504698; c=relaxed/simple; bh=Bs0+qo+KoS4vWqvR13l8NYDd7KZrGwVeOUrElY/iXiQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z9rAgavHTYfYtW+vqPNPmz76Dxe+XQLoGh/nBffEQbt4/gt5Ph/a0VJ5PbK6U8rqUbFUHRnz7BJxdSYHLsPYfIazVUEFzJVdjurGAl94+sV1sWvhEaFZmmgl8nGm7qNqJNORH34pAbHZblMRUmeS9KGx/LV6Hyhg+lyrC/oKqhE= 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=CuYr8l0l; arc=none smtp.client-ip=209.85.218.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="CuYr8l0l" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a99ebb390a5so980340166b.1 for ; Mon, 21 Oct 2024 02:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504695; x=1730109495; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OMKFW4Slqtz/NTS5T7IDn73l4pmvI7vfqICtqFz1xbw=; b=CuYr8l0l1nIwmdIeBDzN9lwtyfqoW7HR8j82kjJjEhRRhRy2ipf4CyXua9xK+CQBqC XlZ+/VM4/TkX4zqBHeo6OefRnVOkoc4pQfuwL/EMNe0y2vBVvrmxAuqoJjaV+hsE6iCV WlfgcHjs0tAAyCpN7ve1/M2aJNI9ufjwkjHsWOlquuuYYYqLEcRcWadpiR/OWrVO/Tal zsxD5B/5KoTY71SDRO2VQtkJoX7IqOfp+ZHuWV/Ws0u4gret2/DZ/ZTV6o8+I679uGXS FRcLQdjz/PjBxaeDkIBpoC1nGw1QrSDdrjf3eq7fyvhkVzdGsCc8DblG9cKqjEe4Dr9B ZX1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504695; x=1730109495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OMKFW4Slqtz/NTS5T7IDn73l4pmvI7vfqICtqFz1xbw=; b=sYesBvOSTAinjX/5H9fEdf0hWrwkgdMw1hcPbO/xDfvGVYpCmhXrwPhIJf/QvCytoo UjyvafD5h8F0uKHi+DIzlAi/Z9MJJOeKuQo+gXasp/jEPI8Mm9tXlLSMlfyzdyTHdGFo zyrCp/m7wKeRgzZyKspQTorco5ys9gRffZaHJAsT7xday6GAb+frbyhcVDyYUEDJW3Gg vBOrbK8a3wA0pOxyzXNXIpYgDG2oEmyju1P43wDOjwAwmwhzRjZpMbZLd44X4MVrEnY2 bO33EhdFUa4rUr84tAFBycilDnj0XB9MCUc/nV94KAJaagcBIwYUh7/kGqImESuRL+dU hSPw== X-Gm-Message-State: AOJu0YzvXgxmny+fNiVgBq0744i+whAGDF4QQAYGB/JRZI3hA81i159m 8xLdqLx7dglS1wZ1Zu8U6C4gc7GH4nanrlfbnCqyFCNFw6KmVa9sNhRhTQB8 X-Google-Smtp-Source: AGHT+IER7OfEUr6HZLcKbKTWgko37VuaxTxXK88Y1wT5KLHx68hkXLFY9aVpauksAlr2XV3Ht6TxIA== X-Received: by 2002:a17:907:6ea9:b0:a99:f777:c6ef with SMTP id a640c23a62f3a-a9a6a3eb453mr1166810866b.3.1729504694325; Mon, 21 Oct 2024 02:58:14 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:13 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 10/20] packfile: pass down repository to `find_pack_entry_one` Date: Mon, 21 Oct 2024 11:57:53 +0200 Message-ID: <7d580c72ce97a822bacb082fa05b1e7e41bfc011.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `find_pack_entry_one` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/fast-import.c | 4 ++-- builtin/pack-objects.c | 4 ++-- connected.c | 5 +++-- http-push.c | 5 +++-- http-walker.c | 2 +- midx.c | 2 +- pack-bitmap.c | 6 ++++-- packfile.c | 15 ++++++++------- packfile.h | 6 ++++-- t/helper/test-find-pack.c | 2 +- 10 files changed, 29 insertions(+), 22 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 51d1cc0deb..a6743db85c 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -966,7 +966,7 @@ static int store_object( if (e->idx.offset) { duplicate_count_by_type[type]++; return 1; - } else if (find_sha1_pack(oid.hash, + } else if (find_sha1_pack(the_repository, oid.hash, get_all_packs(the_repository))) { e->type = type; e->pack_id = MAX_PACK_ID; @@ -1167,7 +1167,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) duplicate_count_by_type[OBJ_BLOB]++; truncate_pack(&checkpoint); - } else if (find_sha1_pack(oid.hash, + } else if (find_sha1_pack(the_repository, oid.hash, get_all_packs(the_repository))) { e->type = OBJ_BLOB; e->pack_id = MAX_PACK_ID; diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index adf55d892f..d41259a423 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1558,7 +1558,7 @@ static int want_object_in_pack_one(struct packed_git *p, if (p == *found_pack) offset = *found_offset; else - offset = find_pack_entry_one(oid->hash, p); + offset = find_pack_entry_one(the_repository, oid->hash, p); if (offset) { if (!*found_pack) { @@ -3986,7 +3986,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid) while (p) { if ((!p->pack_local || p->pack_keep || p->pack_keep_in_core) && - find_pack_entry_one(oid->hash, p)) { + find_pack_entry_one(the_repository, oid->hash, p)) { last_found = p; return 1; } diff --git a/connected.c b/connected.c index 235890efd0..00b7de34c6 100644 --- a/connected.c +++ b/connected.c @@ -78,7 +78,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data, for (p = get_all_packs(the_repository); p; p = p->next) { if (!p->pack_promisor) continue; - if (find_pack_entry_one(oid->hash, p)) + if (find_pack_entry_one(the_repository, oid->hash, p)) goto promisor_pack_found; } /* @@ -144,7 +144,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data, * are sure the ref is good and not sending it to * rev-list for verification. */ - if (new_pack && find_pack_entry_one(oid->hash, new_pack)) + if (new_pack && find_pack_entry_one(the_repository, oid->hash, + new_pack)) continue; if (fprintf(rev_list_in, "%s\n", oid_to_hex(oid)) < 0) diff --git a/http-push.c b/http-push.c index aad89f2eab..cb6cf1696e 100644 --- a/http-push.c +++ b/http-push.c @@ -309,7 +309,8 @@ static void start_fetch_packed(struct transfer_request *request) struct transfer_request *check_request = request_queue_head; struct http_pack_request *preq; - target = find_sha1_pack(request->obj->oid.hash, repo->packs); + target = find_sha1_pack(the_repository, request->obj->oid.hash, + repo->packs); if (!target) { fprintf(stderr, "Unable to fetch %s, will not be able to update server info refs\n", oid_to_hex(&request->obj->oid)); repo->can_update_info_refs = 0; @@ -681,7 +682,7 @@ static int add_send_request(struct object *obj, struct remote_lock *lock) get_remote_object_list(obj->oid.hash[0]); if (obj->flags & (REMOTE | PUSHING)) return 0; - target = find_sha1_pack(obj->oid.hash, repo->packs); + target = find_sha1_pack(the_repository, obj->oid.hash, repo->packs); if (target) { obj->flags |= REMOTE; return 0; diff --git a/http-walker.c b/http-walker.c index fb2d86d5e7..0a11ed6ecf 100644 --- a/http-walker.c +++ b/http-walker.c @@ -431,7 +431,7 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne if (fetch_indices(walker, repo)) return -1; - target = find_sha1_pack(sha1, repo->packs); + target = find_sha1_pack(the_repository, sha1, repo->packs); if (!target) return -1; close_pack_index(target); diff --git a/midx.c b/midx.c index 94609456a2..c76df95d6d 100644 --- a/midx.c +++ b/midx.c @@ -973,7 +973,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag } m_offset = e.offset; - p_offset = find_pack_entry_one(oid.hash, e.p); + p_offset = find_pack_entry_one(r, oid.hash, e.p); if (m_offset != p_offset) midx_report(_("incorrect object offset for oid[%d] = %s: %"PRIx64" != %"PRIx64), diff --git a/pack-bitmap.c b/pack-bitmap.c index 96716c785b..b699875555 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -935,7 +935,8 @@ static inline int bitmap_position_packfile(struct bitmap_index *bitmap_git, const struct object_id *oid) { uint32_t pos; - off_t offset = find_pack_entry_one(oid->hash, bitmap_git->pack); + off_t offset = find_pack_entry_one(the_repository, oid->hash, + bitmap_git->pack); if (!offset) return -1; @@ -1609,7 +1610,8 @@ static int in_bitmapped_pack(struct bitmap_index *bitmap_git, if (bsearch_midx(&object->oid, bitmap_git->midx, NULL)) return 1; } else { - if (find_pack_entry_one(object->oid.hash, bitmap_git->pack) > 0) + if (find_pack_entry_one(the_repository, object->oid.hash, + bitmap_git->pack) > 0) return 1; } } diff --git a/packfile.c b/packfile.c index 92c919d628..bf70fd60a8 100644 --- a/packfile.c +++ b/packfile.c @@ -1240,7 +1240,7 @@ off_t get_delta_base(struct repository *repo, struct packed_git *p, *curpos += used; } else if (type == OBJ_REF_DELTA) { /* The base entry _must_ be in the same pack */ - base_offset = find_pack_entry_one(base_info, p); + base_offset = find_pack_entry_one(repo, base_info, p); *curpos += repo->hash_algo->rawsz; } else die("I am totally screwed"); @@ -1975,8 +1975,8 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n) } } -off_t find_pack_entry_one(const unsigned char *sha1, - struct packed_git *p) +off_t find_pack_entry_one(struct repository *repo, const unsigned char *sha1, + struct packed_git *p) { const unsigned char *index = p->index_data; struct object_id oid; @@ -1987,7 +1987,7 @@ off_t find_pack_entry_one(const unsigned char *sha1, return 0; } - hashcpy(oid.hash, sha1, the_repository->hash_algo); + hashcpy(oid.hash, sha1, repo->hash_algo); if (bsearch_pack(&oid, p, &result)) return nth_packed_object_offset(p, result); return 0; @@ -2014,13 +2014,14 @@ int is_pack_valid(struct repository *repo, struct packed_git *p) return !open_packed_git(repo, p); } -struct packed_git *find_sha1_pack(const unsigned char *sha1, +struct packed_git *find_sha1_pack(struct repository *repo, + const unsigned char *sha1, struct packed_git *packs) { struct packed_git *p; for (p = packs; p; p = p->next) { - if (find_pack_entry_one(sha1, p)) + if (find_pack_entry_one(repo, sha1, p)) return p; } return NULL; @@ -2037,7 +2038,7 @@ static int fill_pack_entry(const struct object_id *oid, oidset_contains(&p->bad_objects, oid)) return 0; - offset = find_pack_entry_one(oid->hash, p); + offset = find_pack_entry_one(the_repository, oid->hash, p); if (!offset) return 0; diff --git a/packfile.h b/packfile.h index f744af6e9b..983d6df385 100644 --- a/packfile.h +++ b/packfile.h @@ -87,7 +87,8 @@ struct packed_git *get_all_packs(struct repository *r); */ unsigned long repo_approximate_object_count(struct repository *r); -struct packed_git *find_sha1_pack(const unsigned char *sha1, +struct packed_git *find_sha1_pack(struct repository *repo, + const unsigned char *sha1, struct packed_git *packs); void pack_report(void); @@ -163,7 +164,8 @@ off_t nth_packed_object_offset(const struct packed_git *, uint32_t n); * If the object named sha1 is present in the specified packfile, * return its offset within the packfile; otherwise, return 0. */ -off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *); +off_t find_pack_entry_one(struct repository *repo, const unsigned char *sha1, + struct packed_git *); int is_pack_valid(struct repository *repo, struct packed_git *); void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object_type *, unsigned long *); diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c index 14b2b0c12c..c5cdea98f6 100644 --- a/t/helper/test-find-pack.c +++ b/t/helper/test-find-pack.c @@ -40,7 +40,7 @@ int cmd__find_pack(int argc, const char **argv) die("cannot parse %s as an object name", argv[0]); for (p = get_all_packs(the_repository); p; p = p->next) - if (find_pack_entry_one(oid.hash, p)) { + if (find_pack_entry_one(the_repository, oid.hash, p)) { printf("%s\n", p->pack_name); actual_count++; } From patchwork Mon Oct 21 09:57:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843797 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.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 032EC1E571E for ; Mon, 21 Oct 2024 09:58:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504698; cv=none; b=JRgEA/apIcuUaZPpE/fFvRt4jQDAeBeCdhXXm6doKTOYN8t8fDSNxkwpGMXJFz63kh3KtIhpaY4nMsPhnx362It1YBhHqJPPsO9S4aM8SfzRuhXdyERc7N/xHNuLdrBhv1hs2YZvA4934yMnspUpguAEEumcOezo5+fHy0gqPXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504698; c=relaxed/simple; bh=CZzQ0MmakROjBrudbp65US8AUaz8Rc2whzrrsq2BLdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZFUCtK0fbzfb9Ftc4EHNEq+epmfR7gbIHEYQeP3GWwsJBQZpNf5YUryNRvd+G9e1cpbJN6dEz7jb4dViG66WerEE/BjaIre9PQllMubU1v9sNLBCEbJnlWWHvlDej14J3JtP1d5Uct4l0FRapSnGuukW5Glmc3jSlkqMUWk78gU= 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=ih4bGNmJ; arc=none smtp.client-ip=209.85.218.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="ih4bGNmJ" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a99eb8b607aso441518366b.2 for ; Mon, 21 Oct 2024 02:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504695; x=1730109495; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1egi0q3Z0yAC5qR00pLsZi766LDkZglc9y/WTWbkxXU=; b=ih4bGNmJYv8mi0Fwzl7YXHQjAetibaorvbQSDjLmcuAAkpAv6TtKVdHfEbTNhHzyq4 1hfFChKBRgxEHpsot70txNw8cIPmwppV39PvUteM9WT1uyrBMR78ouOhYCH5T7055EgZ F2vSEGDJ7VFZLJi7+Hj+ibO1IOIOjP76h7QUORKkR5YsB7KF9VgmxALkBIUve6J4OSjQ /zfXNmZTGm3b73Sofr7TMlxVHY8/s+1Du6xuVHwPBjv1xVdIsvEnh+UfHbAw/7t/Oa0D PaEMUiFkQlFrA2QU6jaSuGhgjF3hCyACbyGp3y5WjSaAWdCb0GRcR/XlRMuD4Cdut/uR mUeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504695; x=1730109495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1egi0q3Z0yAC5qR00pLsZi766LDkZglc9y/WTWbkxXU=; b=gB67Brt7aCxoZaObGxV7343zpe3BEMOvcpJg6OjTkf2EQPXIO08t0MA+z9+V87wg7s G+bx9He+P+j3bPGjdCVEfWaSvFtGeN1o++hoH2lTpKJr7BG9i3LEFf8aoVdvUakBS8s/ SwNJACpvPSXvOYQ64zJ67hAKIvGlU/lCxD/hkeN1/CwD4UwS/HwrxlRzhEeMhXSMQYt1 IrC41PF05ykkRO2f5Ou1ZmfR3Tbl1dIPXrSl399cNPK00WNIXm4Fi/xFZ1BzEkk+GKCG kzQi1m2xfcFB6VpasfVmPGztN2GI2t853d01FMLY1p1/YvKI2KB/4yEQNXis259zGXr7 YLtA== X-Gm-Message-State: AOJu0YxeelqRiisTYA9T8BAF8ST9jj4ymUFQJUQbc81ldrYPfvt69T4G p1eoer0bFSPd3K99FYWdX/ZQwVn6V57G7zHOgS30E6Hzq8qdW9DHuOvWsK5A X-Google-Smtp-Source: AGHT+IGyMKOjJCJQvcIDripDZKBbHuav+W/LSNWYryozRApGHuyaGmCRdaY9i6WjswNcoB66I/HBAw== X-Received: by 2002:a17:907:3f1e:b0:a99:60c8:f2c4 with SMTP id a640c23a62f3a-a9a69a668c1mr970294266b.15.1729504695113; Mon, 21 Oct 2024 02:58:15 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:14 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 11/20] packfile: pass down repository to `fill_pack_entry` Date: Mon, 21 Oct 2024 11:57:54 +0200 Message-ID: <11ddc363c27d93f0c716bfaf9ce2cecf71ed421e.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `fill_pack_entry` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- packfile.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packfile.c b/packfile.c index bf70fd60a8..236c5c0479 100644 --- a/packfile.c +++ b/packfile.c @@ -2028,9 +2028,8 @@ struct packed_git *find_sha1_pack(struct repository *repo, } -static int fill_pack_entry(const struct object_id *oid, - struct pack_entry *e, - struct packed_git *p) +static int fill_pack_entry(struct repository *repo, const struct object_id *oid, + struct pack_entry *e, struct packed_git *p) { off_t offset; @@ -2038,7 +2037,7 @@ static int fill_pack_entry(const struct object_id *oid, oidset_contains(&p->bad_objects, oid)) return 0; - offset = find_pack_entry_one(the_repository, oid->hash, p); + offset = find_pack_entry_one(repo, oid->hash, p); if (!offset) return 0; @@ -2049,7 +2048,7 @@ static int fill_pack_entry(const struct object_id *oid, * answer, as it may have been deleted since the index was * loaded! */ - if (!is_pack_valid(the_repository, p)) + if (!is_pack_valid(repo, p)) return 0; e->offset = offset; e->p = p; @@ -2072,7 +2071,7 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa list_for_each(pos, &r->objects->packed_git_mru) { struct packed_git *p = list_entry(pos, struct packed_git, mru); - if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) { + if (!p->multi_pack_index && fill_pack_entry(r, oid, e, p)) { list_move(&p->mru, &r->objects->packed_git_mru); return 1; } @@ -2134,7 +2133,7 @@ int find_kept_pack_entry(struct repository *r, for (cache = kept_pack_cache(r, flags); *cache; cache++) { struct packed_git *p = *cache; - if (fill_pack_entry(oid, e, p)) + if (fill_pack_entry(r, oid, e, p)) return 1; } From patchwork Mon Oct 21 09:57:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843798 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 C40AD1E6DE1 for ; Mon, 21 Oct 2024 09:58:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504700; cv=none; b=Q2Twaieu91FrUBuh948B1GV8fEXa5FV51oCW5gaOKnuCYB941tKZKObaZX9onrO45kWrj3Rm/v2RplggBvNUsXcieTfCm2YL8rpix2TDX6qHTScyI0smRO/wQ6QDv/cX0prBCW3ZzV3IopcDwJgTCP3aUFhpqRUVODRCL29L3c8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504700; c=relaxed/simple; bh=dwjaqQZokzR+fJC0zCR8xI24COjN1zQS5JdSgb+48sE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tjdFPqiedFRVwuz2fS71GSSJAp9kDXoFKpDk+UPpwr9BS91f3nItmM0fzomR9ZgaJPLv7UTbSiOSBbndCKdS/sQ6kUBpKLysDOjB2oRELONAgR5zCfSMN9i8J8TOPrEUU+xwVmjLc1HjT7PFX9FTBcLHX1TL/2KO4r/JzoSHIrE= 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=aMymjIh9; arc=none smtp.client-ip=209.85.208.53 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="aMymjIh9" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5c94c4ad9d8so5580893a12.2 for ; Mon, 21 Oct 2024 02:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504696; x=1730109496; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9fZ5KlnEKShfQCdJmmecWEjcRS7BjGIlTxJWAYZjQxw=; b=aMymjIh9GHNtr81mF1NnGyus4gLZrqwEESFls1gVmf4vFafQ18d1qLYLuq6WcSkJtl Iy1AkQVbvXbz9i+v/3Vkes7wgdvnZRCrYpfIWkwaRTvVI6YMszDDwfMPOyut4LbTIF6d YtvX6gLr39SwuTDy9lg3fVVJ71/WJ01UAg5t30stnHcOk3iWpeFhpMdYnWk6+4T8fzdo 03JARfCyXbMbGJYrOZDgMRcQKqWlrri14NQUa39vvcCq2eSMYsHoePYU9hPC6NEDWtPF X+EJEVh4j6ojrXyk+sSRoz+46t6/cP1ANjjL3aVrLr9VUy/B0wvkC8L+cBEpqO5T3ESf ucPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504696; x=1730109496; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9fZ5KlnEKShfQCdJmmecWEjcRS7BjGIlTxJWAYZjQxw=; b=OI5AaQeqDOnYyd58m3Rqc4zjvpucp3tptdJI4GyvC4Aki9pj2K7BUQd99RMAyBnFoM eUWAIWgwwB1QN3/qcVgz6axL/w+/4Bj3UENUje57kNkMl7Dh8/v4b91U7kTvhwkdbbi8 Mey6mnc4KWoJMInyeuvs6eMyFduRpODDNotzafa77DuvGy6jZjK/sinMJsj+ew3Xw0E/ jAlzwMT/iN9XAISIP2DywwFdGJSuPoymFDXFyjY/pRl6R8VAdE3tis2UsagTqmi2Yx0W d1Dae1pPElNTanxvVKquGSKRbXZqF9i7YGMOp8DPvAHj3Sv+MqjGjdqbzi9Nra8tF8is HAQQ== X-Gm-Message-State: AOJu0YydiAeG1sRPwSTM+uwzWpTQp8k2NAkSzXa/SUeQXh7z1m0hfk3d 72rOFQ3jWqfLoyY0EzcPNLxkQZheONj9J6fGnZCUjC8+UR7MxjQdOTZPqsC0 X-Google-Smtp-Source: AGHT+IEhIR6PPAHvnJwBa3fDa+eVvS5BkMkq04GnaQQka2Z6jG6OLu5ugHa2qutWxN0pIjGPmilA+Q== X-Received: by 2002:a17:907:948f:b0:a99:f0d0:4ce3 with SMTP id a640c23a62f3a-a9a69a746f2mr1002562366b.17.1729504695795; Mon, 21 Oct 2024 02:58:15 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:15 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 12/20] packfile: pass down repository to `has_object[_kept]_pack` Date: Mon, 21 Oct 2024 11:57:55 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The functions `has_object[_kept]_pack` currently rely on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from these functions and any related ones. Signed-off-by: Karthik Nayak --- builtin/count-objects.c | 2 +- builtin/fsck.c | 2 +- builtin/pack-objects.c | 4 ++-- diff.c | 3 ++- list-objects.c | 3 ++- pack-bitmap.c | 2 +- packfile.c | 9 +++++---- packfile.h | 5 +++-- prune-packed.c | 2 +- reachable.c | 2 +- revision.c | 4 ++-- 11 files changed, 21 insertions(+), 17 deletions(-) diff --git a/builtin/count-objects.c b/builtin/count-objects.c index 04d80887e0..1e89148ed7 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -67,7 +67,7 @@ static int count_loose(const struct object_id *oid, const char *path, else { loose_size += on_disk_bytes(st); loose++; - if (verbose && has_object_pack(oid)) + if (verbose && has_object_pack(the_repository, oid)) packed_loose++; } return 0; diff --git a/builtin/fsck.c b/builtin/fsck.c index 7f4e2f0414..bb56eb98ac 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -272,7 +272,7 @@ static void check_reachable_object(struct object *obj) if (!(obj->flags & HAS_OBJ)) { if (is_promisor_object(&obj->oid)) return; - if (has_object_pack(&obj->oid)) + if (has_object_pack(the_repository, &obj->oid)) return; /* it is in pack - forget about it */ printf_ln(_("missing %s %s"), printable_type(&obj->oid, obj->type), diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index d41259a423..321e77ebf3 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1531,7 +1531,7 @@ static int want_found_object(const struct object_id *oid, int exclude, return 0; if (ignore_packed_keep_in_core && p->pack_keep_in_core) return 0; - if (has_object_kept_pack(oid, flags)) + if (has_object_kept_pack(the_repository, oid, flags)) return 0; } @@ -3629,7 +3629,7 @@ static void show_cruft_commit(struct commit *commit, void *data) static int cruft_include_check_obj(struct object *obj, void *data UNUSED) { - return !has_object_kept_pack(&obj->oid, IN_CORE_KEEP_PACKS); + return !has_object_kept_pack(the_repository, &obj->oid, IN_CORE_KEEP_PACKS); } static int cruft_include_check(struct commit *commit, void *data) diff --git a/diff.c b/diff.c index dceac20d18..1d483bdf37 100644 --- a/diff.c +++ b/diff.c @@ -4041,7 +4041,8 @@ static int reuse_worktree_file(struct index_state *istate, * objects however would tend to be slower as they need * to be individually opened and inflated. */ - if (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid)) + if (!FAST_WORKING_DIRECTORY && !want_file && + has_object_pack(the_repository, oid)) return 0; /* diff --git a/list-objects.c b/list-objects.c index 985d008799..31236a8dc9 100644 --- a/list-objects.c +++ b/list-objects.c @@ -41,7 +41,8 @@ static void show_object(struct traversal_context *ctx, { if (!ctx->show_object) return; - if (ctx->revs->unpacked && has_object_pack(&object->oid)) + if (ctx->revs->unpacked && has_object_pack(ctx->revs->repo, + &object->oid)) return; ctx->show_object(object, name, ctx->show_data); diff --git a/pack-bitmap.c b/pack-bitmap.c index b699875555..97237acb24 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -1891,7 +1891,7 @@ static void filter_packed_objects_from_bitmap(struct bitmap_index *bitmap_git, bitmap_unset(result, i); for (i = 0; i < eindex->count; ++i) { - if (has_object_pack(&eindex->objects[i]->oid)) + if (has_object_pack(the_repository, &eindex->objects[i]->oid)) bitmap_unset(result, objects_nr + i); } } diff --git a/packfile.c b/packfile.c index 236c5c0479..6bc7b6e9eb 100644 --- a/packfile.c +++ b/packfile.c @@ -2140,16 +2140,17 @@ int find_kept_pack_entry(struct repository *r, return 0; } -int has_object_pack(const struct object_id *oid) +int has_object_pack(struct repository *repo, const struct object_id *oid) { struct pack_entry e; - return find_pack_entry(the_repository, oid, &e); + return find_pack_entry(repo, oid, &e); } -int has_object_kept_pack(const struct object_id *oid, unsigned flags) +int has_object_kept_pack(struct repository *repo, const struct object_id *oid, + unsigned flags) { struct pack_entry e; - return find_kept_pack_entry(the_repository, oid, flags, &e); + return find_kept_pack_entry(repo, oid, flags, &e); } int has_pack_index(struct repository *repo, const unsigned char *sha1) diff --git a/packfile.h b/packfile.h index 983d6df385..ec4aff63b4 100644 --- a/packfile.h +++ b/packfile.h @@ -200,8 +200,9 @@ const struct packed_git *has_packed_and_bad(struct repository *, const struct ob int find_pack_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e); int find_kept_pack_entry(struct repository *r, const struct object_id *oid, unsigned flags, struct pack_entry *e); -int has_object_pack(const struct object_id *oid); -int has_object_kept_pack(const struct object_id *oid, unsigned flags); +int has_object_pack(struct repository *repo, const struct object_id *oid); +int has_object_kept_pack(struct repository *repo, const struct object_id *oid, + unsigned flags); int has_pack_index(struct repository *repo, const unsigned char *sha1); diff --git a/prune-packed.c b/prune-packed.c index 2bb99c29df..d1c65ab10e 100644 --- a/prune-packed.c +++ b/prune-packed.c @@ -24,7 +24,7 @@ static int prune_object(const struct object_id *oid, const char *path, { int *opts = data; - if (!has_object_pack(oid)) + if (!has_object_pack(the_repository, oid)) return 0; if (*opts & PRUNE_PACKED_DRY_RUN) diff --git a/reachable.c b/reachable.c index 3e9b3dd0a4..09d2c50079 100644 --- a/reachable.c +++ b/reachable.c @@ -239,7 +239,7 @@ static int want_recent_object(struct recent_data *data, const struct object_id *oid) { if (data->ignore_in_core_kept_packs && - has_object_kept_pack(oid, IN_CORE_KEEP_PACKS)) + has_object_kept_pack(data->revs->repo, oid, IN_CORE_KEEP_PACKS)) return 0; return 1; } diff --git a/revision.c b/revision.c index f5f5b84f2b..d1d152a67b 100644 --- a/revision.c +++ b/revision.c @@ -4103,10 +4103,10 @@ enum commit_action get_commit_action(struct rev_info *revs, struct commit *commi { if (commit->object.flags & SHOWN) return commit_ignore; - if (revs->unpacked && has_object_pack(&commit->object.oid)) + if (revs->unpacked && has_object_pack(revs->repo, &commit->object.oid)) return commit_ignore; if (revs->no_kept_objects) { - if (has_object_kept_pack(&commit->object.oid, + if (has_object_kept_pack(revs->repo, &commit->object.oid, revs->keep_pack_cache_flags)) return commit_ignore; } From patchwork Mon Oct 21 09:57:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843799 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 91F331E5738 for ; Mon, 21 Oct 2024 09:58:18 +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=1729504700; cv=none; b=OyfmYMU2TVm1Jy00kGQEha/iDGe15/1dyxjrKtjLlITT9sGQYvAFhqwR1Z7vlKCaLO6zzlxpj8mSZGFbN1VFdmYMAEmg1xusqNArJ57cTpaHKgHj0Z6FGN9cgjAQBrjDg6R9oIsLC1gZJApIx8DzCTVjWS8pf1i+5hrPfcg/u3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504700; c=relaxed/simple; bh=3kCL4rieV6vIfPfDYMBuusTPWhwkNli0KVmsazh7hSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ei/QhVAbelasxStovn8VoGwxOo6KDMrTCRPxmtkeAGZXIs0ubFLqpppsTQ+OUPC4aQEoXFKEwLKATjvH0m2nSAmtucY3eFzyW8XeaH7frz9fZWTdA5SgXcpSs5xOGedfrh45sFuC4ASy30T28JxqUO59yF/x8BmvNA7B1YxFx6Q= 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=B2ar3lr5; 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="B2ar3lr5" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a99f646ff1bso530123366b.2 for ; Mon, 21 Oct 2024 02:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504697; x=1730109497; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yh39RwmTAv2Bn5DC37bJn6fA/uJ2zI7NaObHR8NVp5U=; b=B2ar3lr5h09F6XvpfiR8zQdgeobnr2aJcEJUR6/2Mh33SJqTWsTkC+8YpMKZIqp+8C kYENSBzUcGh5Yz6AYR4YOJ8joI2H4Jvwco7lAgEXV2p2jUynRkqhKS2wozFGnvbpimzc YcLv9y1mRgMllQnsEIl31E42FQM/J8bXW/viBmaEZ2wY9brU3Xb2KFdX3R9enNb5+2ri cUFRo1Yw/Q/FhWoU2LeM8cSqTW7bSMO1n9IxcyQT10Zq9J7Zxx6tkKEWfVq6stPwD3p6 38VyTDzwXZVnnw2/nEa6IBgn+QzzOX7QOdgNGYPoIc21z3uL0KNo2Q/fYaBzSevsYSnB KkVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504697; x=1730109497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yh39RwmTAv2Bn5DC37bJn6fA/uJ2zI7NaObHR8NVp5U=; b=q1JNYAWV4sueRAyUgtKvGWqnQ/IUsbJnZ8tXLEXmB8Uk/N7BQxtccclC2MNn6mEEFU PJBhoOVxR2k7AC2WTPS4hb6MAR6lQAS3+TmyR47g2qOBBSD+DpkenI/lz+fGgtwQxh5u M+4B/kLSXZZ91l74MfhWld5FoZOp4LyouOjYtddxWy+azYZ+Q60yAhSfwatBCD/AKAcb tOM5wl5pqzwSKiNyMZXeDdH+JuXIJCA9Qjrm/L9h2xTe8r7yUBUOYVa22V4xX442o3Ga gi7+2LPPiJUhLv3gS0X/5hlpNMrL2Psd4AyYHL4CnOWg8bOu46r1UHncaC+zKal8cIrd PvCQ== X-Gm-Message-State: AOJu0YzhR5JbAN4dNNeo+E587uEr4Aow0yGPz60dRDyNeOZ9E5BNn5gD /KExEF4cuQS3b7KjdE0wWQaUzslnKetOXEozbOAJ6ejbXEbxqJ0N7n1P2EXu X-Google-Smtp-Source: AGHT+IFjuz+ujx3B6aKJI1mwwX14mKYXeI45K9KSzA1RRI8sqoT2gxtWhmn1K1p4ArVPzUdT3OOR6A== X-Received: by 2002:a17:907:2d86:b0:a9a:29a9:70bb with SMTP id a640c23a62f3a-a9a69a7866amr988477266b.14.1729504696554; Mon, 21 Oct 2024 02:58:16 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:16 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 13/20] packfile: pass down repository to `for_each_packed_object` Date: Mon, 21 Oct 2024 11:57:56 +0200 Message-ID: <9e4624440e64c3d373dfd58b3d191467dc050e99.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `for_each_packed_object` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/cat-file.c | 9 +++++++-- builtin/fsck.c | 10 ++++++++-- builtin/pack-objects.c | 8 ++++---- builtin/repack.c | 2 +- commit-graph.c | 6 +++--- object-store-ll.h | 7 ++++--- packfile.c | 20 +++++++++++--------- reachable.c | 2 +- revision.c | 2 +- 9 files changed, 40 insertions(+), 26 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index bfdfb51c7c..f6afe67bef 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -827,7 +827,9 @@ static int batch_objects(struct batch_options *opt) cb.seen = &seen; for_each_loose_object(batch_unordered_loose, &cb, 0); - for_each_packed_object(batch_unordered_packed, &cb, + for_each_packed_object(the_repository, + batch_unordered_packed, + &cb, FOR_EACH_OBJECT_PACK_ORDER); oidset_clear(&seen); @@ -835,7 +837,10 @@ static int batch_objects(struct batch_options *opt) struct oid_array sa = OID_ARRAY_INIT; for_each_loose_object(collect_loose_object, &sa, 0); - for_each_packed_object(collect_packed_object, &sa, 0); + for_each_packed_object(the_repository, + collect_packed_object, + &sa, + 0); oid_array_for_each_unique(&sa, batch_object_cb, &cb); diff --git a/builtin/fsck.c b/builtin/fsck.c index bb56eb98ac..ccf6a8eab2 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -391,7 +391,10 @@ static void check_connectivity(void) * traversal. */ for_each_loose_object(mark_loose_unreachable_referents, NULL, 0); - for_each_packed_object(mark_packed_unreachable_referents, NULL, 0); + for_each_packed_object(the_repository, + mark_packed_unreachable_referents, + NULL, + 0); } /* Look up all the requirements, warn about missing objects.. */ @@ -966,7 +969,10 @@ int cmd_fsck(int argc, if (connectivity_only) { for_each_loose_object(mark_loose_for_connectivity, NULL, 0); - for_each_packed_object(mark_packed_for_connectivity, NULL, 0); + for_each_packed_object(the_repository, + mark_packed_for_connectivity, + NULL, + 0); } else { prepare_alt_odb(the_repository); for (odb = the_repository->objects->odb; odb; odb = odb->next) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 321e77ebf3..4b91dc0add 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3540,9 +3540,8 @@ static void read_packs_list_from_stdin(void) for_each_string_list_item(item, &include_packs) { struct packed_git *p = item->util; - for_each_object_in_pack(p, - add_object_entry_from_pack, - &revs, + for_each_object_in_pack(the_repository, p, + add_object_entry_from_pack, &revs, FOR_EACH_OBJECT_PACK_ORDER); } @@ -3929,7 +3928,8 @@ static int add_object_in_unpacked_pack(const struct object_id *oid, static void add_objects_in_unpacked_packs(void) { - if (for_each_packed_object(add_object_in_unpacked_pack, NULL, + if (for_each_packed_object(the_repository, + add_object_in_unpacked_pack, NULL, FOR_EACH_OBJECT_PACK_ORDER | FOR_EACH_OBJECT_LOCAL_ONLY | FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS | diff --git a/builtin/repack.c b/builtin/repack.c index d6bb37e84a..96a4fa234b 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -404,7 +404,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args, * {type -> existing pack order} ordering when computing deltas instead * of a {type -> size} ordering, which may produce better deltas. */ - for_each_packed_object(write_oid, &cmd, + for_each_packed_object(the_repository, write_oid, &cmd, FOR_EACH_OBJECT_PROMISOR_ONLY); if (cmd.in == -1) { diff --git a/commit-graph.c b/commit-graph.c index 1c333a9c52..8c72c3ac10 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1923,8 +1923,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx, ret = error(_("error opening index for %s"), packname.buf); goto cleanup; } - for_each_object_in_pack(p, add_packed_commits, ctx, - FOR_EACH_OBJECT_PACK_ORDER); + for_each_object_in_pack(the_repository, p, add_packed_commits, + ctx, FOR_EACH_OBJECT_PACK_ORDER); close_pack(p); free(p); } @@ -1960,7 +1960,7 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx) ctx->progress = start_delayed_progress( _("Finding commits for commit graph among packed objects"), ctx->approx_nr_objects); - for_each_packed_object(add_packed_commits, ctx, + for_each_packed_object(the_repository, add_packed_commits, ctx, FOR_EACH_OBJECT_PACK_ORDER); if (ctx->progress_done < ctx->approx_nr_objects) display_progress(ctx->progress, ctx->approx_nr_objects); diff --git a/object-store-ll.h b/object-store-ll.h index 53b8e693b1..710130cd06 100644 --- a/object-store-ll.h +++ b/object-store-ll.h @@ -542,10 +542,11 @@ typedef int each_packed_object_fn(const struct object_id *oid, struct packed_git *pack, uint32_t pos, void *data); -int for_each_object_in_pack(struct packed_git *p, +int for_each_object_in_pack(struct repository *repo, + struct packed_git *p, each_packed_object_fn, void *data, enum for_each_object_flags flags); -int for_each_packed_object(each_packed_object_fn, void *, - enum for_each_object_flags flags); +int for_each_packed_object(struct repository *repo, each_packed_object_fn, + void *, enum for_each_object_flags flags); #endif /* OBJECT_STORE_LL_H */ diff --git a/packfile.c b/packfile.c index 6bc7b6e9eb..aea8e9f429 100644 --- a/packfile.c +++ b/packfile.c @@ -2161,7 +2161,8 @@ int has_pack_index(struct repository *repo, const unsigned char *sha1) return 1; } -int for_each_object_in_pack(struct packed_git *p, +int for_each_object_in_pack(struct repository *repo, + struct packed_git *p, each_packed_object_fn cb, void *data, enum for_each_object_flags flags) { @@ -2169,7 +2170,7 @@ int for_each_object_in_pack(struct packed_git *p, int r = 0; if (flags & FOR_EACH_OBJECT_PACK_ORDER) { - if (load_pack_revindex(the_repository, p)) + if (load_pack_revindex(repo, p)) return -1; } @@ -2194,7 +2195,7 @@ int for_each_object_in_pack(struct packed_git *p, else index_pos = i; - if (nth_packed_object_id(the_repository, &oid, p, index_pos) < 0) + if (nth_packed_object_id(repo, &oid, p, index_pos) < 0) return error("unable to get sha1 of object %u in %s", index_pos, p->pack_name); @@ -2205,15 +2206,15 @@ int for_each_object_in_pack(struct packed_git *p, return r; } -int for_each_packed_object(each_packed_object_fn cb, void *data, - enum for_each_object_flags flags) +int for_each_packed_object(struct repository *repo, each_packed_object_fn cb, + void *data, enum for_each_object_flags flags) { struct packed_git *p; int r = 0; int pack_errors = 0; - prepare_packed_git(the_repository); - for (p = get_all_packs(the_repository); p; p = p->next) { + prepare_packed_git(repo); + for (p = get_all_packs(repo); p; p = p->next) { if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local) continue; if ((flags & FOR_EACH_OBJECT_PROMISOR_ONLY) && @@ -2229,7 +2230,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, pack_errors = 1; continue; } - r = for_each_object_in_pack(p, cb, data, flags); + r = for_each_object_in_pack(repo, p, cb, data, flags); if (r) break; } @@ -2298,7 +2299,8 @@ int is_promisor_object(const struct object_id *oid) if (!promisor_objects_prepared) { if (repo_has_promisor_remote(the_repository)) { - for_each_packed_object(add_promisor_object, + for_each_packed_object(the_repository, + add_promisor_object, &promisor_objects, FOR_EACH_OBJECT_PROMISOR_ONLY | FOR_EACH_OBJECT_PACK_ORDER); diff --git a/reachable.c b/reachable.c index 09d2c50079..ecf7ccf504 100644 --- a/reachable.c +++ b/reachable.c @@ -324,7 +324,7 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs, if (ignore_in_core_kept_packs) flags |= FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS; - r = for_each_packed_object(add_recent_packed, &data, flags); + r = for_each_packed_object(revs->repo, add_recent_packed, &data, flags); done: oidset_clear(&data.extra_recent_oids); diff --git a/revision.c b/revision.c index d1d152a67b..d7913d7608 100644 --- a/revision.c +++ b/revision.c @@ -3915,7 +3915,7 @@ int prepare_revision_walk(struct rev_info *revs) revs->treesame.name = "treesame"; if (revs->exclude_promisor_objects) { - for_each_packed_object(mark_uninteresting, revs, + for_each_packed_object(revs->repo, mark_uninteresting, revs, FOR_EACH_OBJECT_PROMISOR_ONLY); } From patchwork Mon Oct 21 09:57:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843800 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 467AD1E767D for ; Mon, 21 Oct 2024 09:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504701; cv=none; b=F/lb2lHMGczjs+aKt5AFrbYMDIlUxXc5v4/Kq3nzAbzntnkH2qSGPJiyyOivprs/d39qgreMsXzJkxqTUEWwLG4U2XlyM8nXk/7dXk3z6xsAoi85ltrHRI/Xr2qbN8/wo+L0K8ZQPXFGp+uVbp5QKmcHcEHuMktGLbpqQt+G9cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504701; c=relaxed/simple; bh=iEXb1i80hXTriYJBU1CPMsLk+70WIQAOZrDdxArRBvk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n7c38/I8ggDo7xp5vVQvLALCSrrC5+s98OuraE4w6yCbEka9MisTAbNfWBM/stKwyXRohn2RRCprl2RgxlU+dN3UKp42dUcHMBDrXwtM3k8DxBwF6kVOeVTzYEuymtrMA/l1w0xqYnyy9FHlpucMNhCbOSd2OZJctUfYDkgwCIc= 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=PRzdj1vi; arc=none smtp.client-ip=209.85.218.46 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="PRzdj1vi" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a9a1b71d7ffso686821566b.1 for ; Mon, 21 Oct 2024 02:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504697; x=1730109497; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pv3c4hZ8ZiDnAWqzt6ufoyHv4NvBi3U/UoTGVmnspoo=; b=PRzdj1viB95hdM4tWXIbEIb/gcAbE5TpqnwiQmr6LPO16Slct+yVyP78LrX72R6wJ6 JqCYc+CYiby5ij6fIlRPHxcck8qH+o/wfGH3mojC8vTGBO5Lelpg/oVAD3mvbDFPtDO6 RRBL+JQathh6dazUb1Y/3xtOGmrzsSCMHto+c4Ozbz0X27zBMYGo6TiHGI+/pux1gtk+ LBUTs1HTal5gSLMdSw8aZvaP1xlrU/ojdXAFAHjyvYXMacyqqecaj8eZNux3qDzZjWW4 ZhfWk/nWX2bPW2F4wOjNX7ndjzlM0aSJiVfn99PMxNocKvuZ/Dp6obWB09xuFea34gDj RR+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504697; x=1730109497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pv3c4hZ8ZiDnAWqzt6ufoyHv4NvBi3U/UoTGVmnspoo=; b=FyGqiPGFuQqRbvNmIEVCvXraNzjUO+B9mTEJEvJdyxC3de14okbAN+hlSkeT+SlTOc /bZ4aOhFdLwwCIeBZ/NubM8kzmWUdT63RLCRtSEPCXfTTrGBoIO1pAHPNtQaO/dyY66j B76Bm3pNq2/UFOEekZb0OAMy4926PldIj6G8/Db04uOt3t3hoTp1Ia32PWbgUsigE+bm kZpFPq7q8Ibw4wdksuPa0zmYx1eCLf65GC/DV1TAui65WbEWcIIFRaJq8IajfmVe8rNC gX5nxbgzV9UlCpCWD8v+Qmk3Bx9zDZMf42hPf4Pel+SBU70UNW7bfAIvBU0WjzJrfYPX aOpA== X-Gm-Message-State: AOJu0Yx3BPvM++JLVbe3Xffr8FcU2V9+hg49b4Q4BcjQ3lX3XFdjv1ei Qb9o33wJ4OC+ZBpe1AzFwT43gfVqvIJkXXNX882/eLhF/n1wMbVSjkMGQxPW X-Google-Smtp-Source: AGHT+IFYTOJv+htNnQiam0U9itcEeHnYczzXmGNHK09mpEsoM03Eipv1RKGmCsApwb3RuvkL9xBCcw== X-Received: by 2002:a17:907:7f8c:b0:a9a:24a2:180b with SMTP id a640c23a62f3a-a9a69cda11emr1002735566b.57.1729504697228; Mon, 21 Oct 2024 02:58:17 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:16 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 14/20] packfile: pass down repository to `is_promisor_object` Date: Mon, 21 Oct 2024 11:57:57 +0200 Message-ID: <355db54690d157216cc9f8e2c7d63e46c2812523.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `is_promisor_object` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/fsck.c | 10 +++++----- builtin/pack-objects.c | 3 ++- builtin/rev-list.c | 2 +- fsck.c | 2 +- list-objects.c | 4 ++-- packfile.c | 6 +++--- packfile.h | 2 +- promisor-remote.c | 2 +- revision.c | 6 +++--- tag.c | 2 +- 10 files changed, 20 insertions(+), 19 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index ccf6a8eab2..9c4e0622b5 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -150,7 +150,7 @@ static int mark_object(struct object *obj, enum object_type type, return 0; obj->flags |= REACHABLE; - if (is_promisor_object(&obj->oid)) + if (is_promisor_object(the_repository, &obj->oid)) /* * Further recursion does not need to be performed on this * object since it is a promisor object (so it does not need to @@ -270,7 +270,7 @@ static void check_reachable_object(struct object *obj) * do a full fsck */ if (!(obj->flags & HAS_OBJ)) { - if (is_promisor_object(&obj->oid)) + if (is_promisor_object(the_repository, &obj->oid)) return; if (has_object_pack(the_repository, &obj->oid)) return; /* it is in pack - forget about it */ @@ -491,7 +491,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid, refname, timestamp); obj->flags |= USED; mark_object_reachable(obj); - } else if (!is_promisor_object(oid)) { + } else if (!is_promisor_object(the_repository, oid)) { error(_("%s: invalid reflog entry %s"), refname, oid_to_hex(oid)); errors_found |= ERROR_REACHABLE; @@ -534,7 +534,7 @@ static int fsck_handle_ref(const char *refname, const char *referent UNUSED, con obj = parse_object(the_repository, oid); if (!obj) { - if (is_promisor_object(oid)) { + if (is_promisor_object(the_repository, oid)) { /* * Increment default_refs anyway, because this is a * valid ref. @@ -1017,7 +1017,7 @@ int cmd_fsck(int argc, &oid); if (!obj || !(obj->flags & HAS_OBJ)) { - if (is_promisor_object(&oid)) + if (is_promisor_object(the_repository, &oid)) continue; error(_("%s: object missing"), oid_to_hex(&oid)); errors_found |= ERROR_OBJECT; diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 4b91dc0add..16e7f5d4ec 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3859,7 +3859,8 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name, * Quietly ignore EXPECTED missing objects. This avoids problems with * staging them now and getting an odd error later. */ - if (!has_object(the_repository, &obj->oid, 0) && is_promisor_object(&obj->oid)) + if (!has_object(the_repository, &obj->oid, 0) && + is_promisor_object(the_repository, &obj->oid)) return; show_object(obj, name, data); diff --git a/builtin/rev-list.c b/builtin/rev-list.c index f62bcbf2b1..43c42621e3 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -121,7 +121,7 @@ static inline void finish_object__ma(struct object *obj) return; case MA_ALLOW_PROMISOR: - if (is_promisor_object(&obj->oid)) + if (is_promisor_object(the_repository, &obj->oid)) return; die("unexpected missing %s object '%s'", type_name(obj->type), oid_to_hex(&obj->oid)); diff --git a/fsck.c b/fsck.c index 3756f52459..87ce999a49 100644 --- a/fsck.c +++ b/fsck.c @@ -1295,7 +1295,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done, buf = repo_read_object_file(the_repository, oid, &type, &size); if (!buf) { - if (is_promisor_object(oid)) + if (is_promisor_object(the_repository, oid)) continue; ret |= report(options, oid, OBJ_BLOB, msg_missing, diff --git a/list-objects.c b/list-objects.c index 31236a8dc9..51c8c380d3 100644 --- a/list-objects.c +++ b/list-objects.c @@ -75,7 +75,7 @@ static void process_blob(struct traversal_context *ctx, */ if (ctx->revs->exclude_promisor_objects && !repo_has_object_file(the_repository, &obj->oid) && - is_promisor_object(&obj->oid)) + is_promisor_object(the_repository, &obj->oid)) return; pathlen = path->len; @@ -180,7 +180,7 @@ static void process_tree(struct traversal_context *ctx, * an incomplete list of missing objects. */ if (revs->exclude_promisor_objects && - is_promisor_object(&obj->oid)) + is_promisor_object(the_repository, &obj->oid)) return; if (!revs->do_not_die_on_missing_objects) diff --git a/packfile.c b/packfile.c index aea8e9f429..1867c2d844 100644 --- a/packfile.c +++ b/packfile.c @@ -2292,14 +2292,14 @@ static int add_promisor_object(const struct object_id *oid, return 0; } -int is_promisor_object(const struct object_id *oid) +int is_promisor_object(struct repository *repo, const struct object_id *oid) { static struct oidset promisor_objects; static int promisor_objects_prepared; if (!promisor_objects_prepared) { - if (repo_has_promisor_remote(the_repository)) { - for_each_packed_object(the_repository, + if (repo_has_promisor_remote(repo)) { + for_each_packed_object(repo, add_promisor_object, &promisor_objects, FOR_EACH_OBJECT_PROMISOR_ONLY | diff --git a/packfile.h b/packfile.h index ec4aff63b4..afec4bbd74 100644 --- a/packfile.h +++ b/packfile.h @@ -210,7 +210,7 @@ int has_pack_index(struct repository *repo, const unsigned char *sha1); * Return 1 if an object in a promisor packfile is or refers to the given * object, 0 otherwise. */ -int is_promisor_object(const struct object_id *oid); +int is_promisor_object(struct repository *repo, const struct object_id *oid); /* * Expose a function for fuzz testing. diff --git a/promisor-remote.c b/promisor-remote.c index 9345ae3db2..c714f4f007 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -283,7 +283,7 @@ void promisor_remote_get_direct(struct repository *repo, } for (i = 0; i < remaining_nr; i++) { - if (is_promisor_object(&remaining_oids[i])) + if (is_promisor_object(repo, &remaining_oids[i])) die(_("could not fetch %s from promisor remote"), oid_to_hex(&remaining_oids[i])); } diff --git a/revision.c b/revision.c index d7913d7608..df1037dcaa 100644 --- a/revision.c +++ b/revision.c @@ -390,7 +390,7 @@ static struct object *get_reference(struct rev_info *revs, const char *name, if (!object) { if (revs->ignore_missing) return NULL; - if (revs->exclude_promisor_objects && is_promisor_object(oid)) + if (revs->exclude_promisor_objects && is_promisor_object(revs->repo, oid)) return NULL; if (revs->do_not_die_on_missing_objects) { oidset_insert(&revs->missing_commits, oid); @@ -432,7 +432,7 @@ static struct commit *handle_commit(struct rev_info *revs, if (revs->ignore_missing_links || (flags & UNINTERESTING)) return NULL; if (revs->exclude_promisor_objects && - is_promisor_object(&tag->tagged->oid)) + is_promisor_object(revs->repo, &tag->tagged->oid)) return NULL; if (revs->do_not_die_on_missing_objects && oid) { oidset_insert(&revs->missing_commits, oid); @@ -1211,7 +1211,7 @@ static int process_parents(struct rev_info *revs, struct commit *commit, revs->do_not_die_on_missing_objects; if (repo_parse_commit_gently(revs->repo, p, gently) < 0) { if (revs->exclude_promisor_objects && - is_promisor_object(&p->object.oid)) { + is_promisor_object(revs->repo, &p->object.oid)) { if (revs->first_parent_only) break; continue; diff --git a/tag.c b/tag.c index d24170e340..beef9571b5 100644 --- a/tag.c +++ b/tag.c @@ -84,7 +84,7 @@ struct object *deref_tag(struct repository *r, struct object *o, const char *war o = NULL; } if (!o && warn) { - if (last_oid && is_promisor_object(last_oid)) + if (last_oid && is_promisor_object(r, last_oid)) return NULL; if (!warnlen) warnlen = strlen(warn); From patchwork Mon Oct 21 09:57:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843801 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 039661E7C0E for ; Mon, 21 Oct 2024 09:58:19 +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=1729504702; cv=none; b=KplJZzS+0vueseeFmttmkoB9Snk4z4opGxdCG0Xm1dP0VbjK3kjqzQ4RBHIPvfKb+lbrsY848y8fw+Dpjj6dPfLfXTQGriIDmPcUhGNUIWl0BpTPepQW0jlMyWQfiHyUqsbXUr6pG8dy+01U//FnJ+nWqZWnNzxV+Z/vJDVgZgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504702; c=relaxed/simple; bh=OP5PdLOiJKObcb1c8Y4K0E2ET6ylfdk5Gj1R0F5ECmA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kaVW7vkPYdORPjOWPf8np7AO67j8tg9BKCXoESZ2vZKKwK9fds6dsfcRlNC/eLXG27k/whbfXfqnWpG6N4PDUXjYTL1HUilCHxuEAiiSwrrT35MVzJ+0Pgm1SRk/z9TfY21jYfFdGkgywoPHfm5YAOhlh1lE8fDIJ1fpGMhLSA4= 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=JliATXhz; 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="JliATXhz" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a9a5b2f2026so489994366b.2 for ; Mon, 21 Oct 2024 02:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504698; x=1730109498; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QVYF4wTFpxLK9O+hKpd9LkTZxCJB0xdX+iu2VPTrzCI=; b=JliATXhzb3C1htG7x2oh0RYr8KRaEF4dwCHH7VCbNRQRmDwX1JfTkCYnXVg+TUB0lQ YBWMe/6JFjSMZsxBw/LYUkEOCKNG1tCFYYp3mzLcQqBW66paHK996URM4WRImTsbDMap YwO8nVH5L6vd4jHF6JL0SS14Tzsox4aJ1rBvjgtlAKNna9/gQOrz8XVGSDCrcm1A6QCT Kzm7Y2Fs7ierjS4BiKeJTbJJMBCdRH0DcSB431EmnJyzaPxsPUszLdMPgG+kIE2OCR34 A+a1qAoin3slNyb2J0tWK0WfCUIkPzSuvAerqLVGobmLJfoD3LgwhqT9bMvOzLct6OYA r+dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504698; x=1730109498; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QVYF4wTFpxLK9O+hKpd9LkTZxCJB0xdX+iu2VPTrzCI=; b=DTKT70wPFsyPEbbunUXIV93NAAsoyxtRNyW6HQqUcUky/QdWMa7lT1WWzEvhFjrnTN ISy9ltI3cuh1f+SOy6j69MO2XJ3WqlQ2oX/RMQclPmJG+Ec0b8v7Omg2G/nUvoTh6bBj UInRRSkRWI5JcyMqA6zaBKvSmf9K1WUfF4Pv16g2DYTT7SAcS2Bz4ax6phRvKub6VJE2 uw9qSfoyePrD9qV8/qltpeoWGlMnZU46usB34iFmNguvAapC1fbAM0oMJH3/O46hGzze 8zJDyl1hTv5spiuiHZZZPNN0WBKDCI0oP+i16jUnhmb2uY7yYECQDle6W2zUvD5qkPfu Xuvg== X-Gm-Message-State: AOJu0Yw5V0ryFNbPbPBMjijAVo5+iLcHCrRgW8p5qUVcsoqPWYTeMJY0 EBg4PjZ8U2/K0Ofugt1bimlrzH39iKM8wYj89/11+Pn5L+p6qrrTPsSxi4zY X-Google-Smtp-Source: AGHT+IF9W0XCVRBcfWgRzeH7Qp4dbzuCrrBjkc0cYWhloTQbjE+UgIv2brYp+T4gfFEoX+QY9zRmLw== X-Received: by 2002:a17:906:6a14:b0:a9a:8674:1739 with SMTP id a640c23a62f3a-a9a867417bbmr792187166b.53.1729504697952; Mon, 21 Oct 2024 02:58:17 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:17 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 15/20] object-store: pass down repository to `each_packed_object_fn` Date: Mon, 21 Oct 2024 11:57:58 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The `each_packed_object_fn` defines the type of the function called for each packed object. In some of the implementations, we require the repository state. So let's modify the function type to also include a repository object and modify all implementations to receive the object and utilize that instead of global state. Signed-off-by: Karthik Nayak --- builtin/cat-file.c | 6 ++++-- builtin/fsck.c | 6 ++++-- builtin/pack-objects.c | 6 ++++-- builtin/repack.c | 5 +++-- commit-graph.c | 3 ++- object-store-ll.h | 3 ++- packfile.c | 9 +++++---- reachable.c | 5 +++-- revision.c | 3 ++- 9 files changed, 29 insertions(+), 17 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index f6afe67bef..e5d774b097 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -600,7 +600,8 @@ static int collect_loose_object(const struct object_id *oid, return 0; } -static int collect_packed_object(const struct object_id *oid, +static int collect_packed_object(struct repository *repo UNUSED, + const struct object_id *oid, struct packed_git *pack UNUSED, uint32_t pos UNUSED, void *data) @@ -631,7 +632,8 @@ static int batch_unordered_loose(const struct object_id *oid, return batch_unordered_object(oid, NULL, 0, data); } -static int batch_unordered_packed(const struct object_id *oid, +static int batch_unordered_packed(struct repository *repo UNUSED, + const struct object_id *oid, struct packed_git *pack, uint32_t pos, void *data) diff --git a/builtin/fsck.c b/builtin/fsck.c index 9c4e0622b5..0e4b7ec3af 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -250,7 +250,8 @@ static int mark_loose_unreachable_referents(const struct object_id *oid, return 0; } -static int mark_packed_unreachable_referents(const struct object_id *oid, +static int mark_packed_unreachable_referents(struct repository *repo UNUSED, + const struct object_id *oid, struct packed_git *pack UNUSED, uint32_t pos UNUSED, void *data UNUSED) @@ -861,7 +862,8 @@ static int mark_loose_for_connectivity(const struct object_id *oid, return 0; } -static int mark_packed_for_connectivity(const struct object_id *oid, +static int mark_packed_for_connectivity(struct repository *repo UNUSED, + const struct object_id *oid, struct packed_git *pack UNUSED, uint32_t pos UNUSED, void *data UNUSED) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 16e7f5d4ec..bfe0197d12 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3361,7 +3361,8 @@ static int git_pack_config(const char *k, const char *v, static int stdin_packs_found_nr; static int stdin_packs_hints_nr; -static int add_object_entry_from_pack(const struct object_id *oid, +static int add_object_entry_from_pack(struct repository *repo UNUSED, + const struct object_id *oid, struct packed_git *p, uint32_t pos, void *_data) @@ -3901,7 +3902,8 @@ static void show_edge(struct commit *commit) add_preferred_base(&commit->object.oid); } -static int add_object_in_unpacked_pack(const struct object_id *oid, +static int add_object_in_unpacked_pack(struct repository *repo UNUSED, + const struct object_id *oid, struct packed_git *pack, uint32_t pos, void *data UNUSED) diff --git a/builtin/repack.c b/builtin/repack.c index 96a4fa234b..de03a3ecfc 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -321,7 +321,8 @@ static void prepare_pack_objects(struct child_process *cmd, * Write oid to the given struct child_process's stdin, starting it first if * necessary. */ -static int write_oid(const struct object_id *oid, +static int write_oid(struct repository *repo, + const struct object_id *oid, struct packed_git *pack UNUSED, uint32_t pos UNUSED, void *data) { @@ -332,7 +333,7 @@ static int write_oid(const struct object_id *oid, die(_("could not start pack-objects to repack promisor objects")); } - if (write_in_full(cmd->in, oid_to_hex(oid), the_hash_algo->hexsz) < 0 || + if (write_in_full(cmd->in, oid_to_hex(oid), repo->hash_algo->hexsz) < 0 || write_in_full(cmd->in, "\n", 1) < 0) die(_("failed to feed promisor objects to pack-objects")); return 0; diff --git a/commit-graph.c b/commit-graph.c index 8c72c3ac10..96d55f8885 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1487,7 +1487,8 @@ static int write_graph_chunk_bloom_data(struct hashfile *f, return 0; } -static int add_packed_commits(const struct object_id *oid, +static int add_packed_commits(struct repository *repo UNUSED, + const struct object_id *oid, struct packed_git *pack, uint32_t pos, void *data) diff --git a/object-store-ll.h b/object-store-ll.h index 710130cd06..a9904687d6 100644 --- a/object-store-ll.h +++ b/object-store-ll.h @@ -538,7 +538,8 @@ int for_each_loose_object(each_loose_object_fn, void *, * Each pack is visited in an unspecified order. By default, objects within a * pack are visited in pack-idx order (i.e., sorted by oid). */ -typedef int each_packed_object_fn(const struct object_id *oid, +typedef int each_packed_object_fn(struct repository *repo, + const struct object_id *oid, struct packed_git *pack, uint32_t pos, void *data); diff --git a/packfile.c b/packfile.c index 1867c2d844..831d2c2c74 100644 --- a/packfile.c +++ b/packfile.c @@ -2199,7 +2199,7 @@ int for_each_object_in_pack(struct repository *repo, return error("unable to get sha1 of object %u in %s", index_pos, p->pack_name); - r = cb(&oid, p, index_pos, data); + r = cb(repo, &oid, p, index_pos, data); if (r) break; } @@ -2237,7 +2237,8 @@ int for_each_packed_object(struct repository *repo, each_packed_object_fn cb, return r ? r : pack_errors; } -static int add_promisor_object(const struct object_id *oid, +static int add_promisor_object(struct repository *repo, + const struct object_id *oid, struct packed_git *pack UNUSED, uint32_t pos UNUSED, void *set_) @@ -2246,12 +2247,12 @@ static int add_promisor_object(const struct object_id *oid, struct object *obj; int we_parsed_object; - obj = lookup_object(the_repository, oid); + obj = lookup_object(repo, oid); if (obj && obj->parsed) { we_parsed_object = 0; } else { we_parsed_object = 1; - obj = parse_object(the_repository, oid); + obj = parse_object(repo, oid); } if (!obj) diff --git a/reachable.c b/reachable.c index ecf7ccf504..f8dc2731d6 100644 --- a/reachable.c +++ b/reachable.c @@ -274,7 +274,8 @@ static int add_recent_loose(const struct object_id *oid, return 0; } -static int add_recent_packed(const struct object_id *oid, +static int add_recent_packed(struct repository *repo, + const struct object_id *oid, struct packed_git *p, uint32_t pos, void *data) @@ -285,7 +286,7 @@ static int add_recent_packed(const struct object_id *oid, if (!want_recent_object(data, oid)) return 0; - obj = lookup_object(the_repository, oid); + obj = lookup_object(repo, oid); if (obj && obj->flags & SEEN) return 0; diff --git a/revision.c b/revision.c index df1037dcaa..97f5e59258 100644 --- a/revision.c +++ b/revision.c @@ -3603,7 +3603,8 @@ void reset_revision_walk(void) clear_object_flags(SEEN | ADDED | SHOWN | TOPO_WALK_EXPLORED | TOPO_WALK_INDEGREE); } -static int mark_uninteresting(const struct object_id *oid, +static int mark_uninteresting(struct repository *repo UNUSED, + const struct object_id *oid, struct packed_git *pack UNUSED, uint32_t pos UNUSED, void *cb) From patchwork Mon Oct 21 09:57:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843802 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 9FA371E571E for ; Mon, 21 Oct 2024 09:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504703; cv=none; b=fsWNxxiSATF2cTo5yD6e23rirsLVm5iOZoue+pOoT9wrLLGa80vDfvh/2ElKywbhwvhxCTGHwXvJhSSn6WzCNLqbKYc+tZe/X62CGHeHgP/aup70rihHDapTxSyhXXjmtxR8losJd2igfpOSUkwn5af1YGz59JSAQJycnJlXEWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504703; c=relaxed/simple; bh=MdLnNf8d3H0VU+1MdeJV/aZoETZLoPoAp0CRpB3B8a8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AzdoJnJY03Wk+VyFGIxcU4wxxDQXle9NHe410ZbEvw1aTkY8QLeMViQiu/ofkaJFUnMo94wZUEfh9w267JLvODVwu7QPKAnGOECgwchMfx1ULzQv12ujOn7t/8gvgAbTIihW6kidop3xH4X8rzDqdTU0rJHnQKGyeqD/M2oqHgI= 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=GRtx9O4j; arc=none smtp.client-ip=209.85.208.52 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="GRtx9O4j" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5c9362c26d8so9036965a12.1 for ; Mon, 21 Oct 2024 02:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504699; x=1730109499; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QfDcN9DIPN8ZxKshBiYdfhJgX0RPtSzhdXjy9KGp/zU=; b=GRtx9O4jA0z3XqE28JcZa0OZhl1VZXm54uacI76M4Bvx5RUKxlixUrkCUn8ztXGZTs G6/FDEycbj+RTB/M44pzyXb6Etbf1S89yOlJVJVFKzvMxsJ9jgszocrBnBXMR8XWMW1g gKkyfRpbfABbCTTvYOKPlxp2t2HGtLK9eBeTOfbeq0ChFrnFUsc8QhAJg3C+bgwWdvZ3 W/6FMS5xyQstnqWkk4f08EcAWZRXc7N1Dg2dqzp6kHlDDer1rO2dDhKe1o/4pMKTS0g+ 6AH63VWlQphyYlKt8OzXLJW3uPk+/dQv8GKE/bU2+ygtZpgXdMDmnuNdJsI2GAL+kakY wJaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504699; x=1730109499; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QfDcN9DIPN8ZxKshBiYdfhJgX0RPtSzhdXjy9KGp/zU=; b=c0UsX3MW967Lo4SVuRmJGBBlTR0Y/Lcp+LFYXDMJlQmXzWlgumvzNTcfEXRW4v7dMG NtKm16dOyET1z+OlFcjG26kdW25sButw4PrD9BCo4s9eCXI3ngYTA0jGLjMFlUplEEWs kvXt7xB6yDQzJWtGe+n361vWhpaPeU8ridp7nwHS4jN9js6t9sDT32trifYbfeGjelrU K63a1Tk+6Eyk5bLACFNYfIOfWCOx8lZ6sIP+v9O5QLcjAxIwNVMtEnIgudX9IngPPhVD OuvHX2UsuOXWGhdJWm04+DC2CAYm/sDr3O8LVAZ2qRsQFhGBUFdbD4xrjUX4Mcue24Gh xosA== X-Gm-Message-State: AOJu0YxNRNvQYMAJiP15QsIPnmIFQpJy3SH1kN1m6pPGgX4il/J0nsjv f6lDh4Ao7doPayZEX5IKdWTTyiOZGdy1agT/DlFnGXdf/qM/b/dZvUwvqwUT X-Google-Smtp-Source: AGHT+IHDk/lmAm7aArqFYSfEFKkDcKHNcP5+EVV4d/ax6MU8NJeC3Fe9Pr5nw2VJ1TzVkA0JmCvSYw== X-Received: by 2002:a17:907:1c87:b0:a99:f37c:f824 with SMTP id a640c23a62f3a-a9a4cc58c3dmr1452826566b.31.1729504698722; Mon, 21 Oct 2024 02:58:18 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:18 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 16/20] packfile: pass down repository to `open_pack_index` Date: Mon, 21 Oct 2024 11:57:59 +0200 Message-ID: <37cbd46efdc14203366a9017dcafc90cf3a938de.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `open_pack_index` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/count-objects.c | 2 +- builtin/fsck.c | 2 +- builtin/index-pack.c | 2 +- builtin/pack-objects.c | 6 +++--- builtin/pack-redundant.c | 2 +- builtin/repack.c | 2 +- commit-graph.c | 2 +- midx-write.c | 10 +++++----- midx.c | 2 +- object-name.c | 4 ++-- pack-check.c | 2 +- pack-mtimes.c | 4 ++-- pack-mtimes.h | 3 ++- pack-revindex.c | 4 ++-- packfile.c | 26 ++++++++++++++------------ packfile.h | 5 +++-- reachable.c | 2 +- t/helper/test-pack-mtimes.c | 2 +- 18 files changed, 43 insertions(+), 39 deletions(-) diff --git a/builtin/count-objects.c b/builtin/count-objects.c index 1e89148ed7..b122b51fe1 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -131,7 +131,7 @@ int cmd_count_objects(int argc, for (p = get_all_packs(the_repository); p; p = p->next) { if (!p->pack_local) continue; - if (open_pack_index(p)) + if (open_pack_index(the_repository, p)) continue; packed += p->num_objects; size_pack += p->pack_size + p->index_size; diff --git a/builtin/fsck.c b/builtin/fsck.c index 0e4b7ec3af..86006e5bbc 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -988,7 +988,7 @@ int cmd_fsck(int argc, if (show_progress) { for (p = get_all_packs(the_repository); p; p = p->next) { - if (open_pack_index(p)) + if (open_pack_index(the_repository, p)) continue; total += p->num_objects; } diff --git a/builtin/index-pack.c b/builtin/index-pack.c index eaefb41761..1898dc37a6 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1656,7 +1656,7 @@ static void read_idx_option(struct pack_idx_option *opts, const char *pack_name) if (!p) die(_("Cannot open existing pack file '%s'"), pack_name); - if (open_pack_index(p)) + if (open_pack_index(the_repository, p)) die(_("Cannot open existing pack idx file for '%s'"), pack_name); /* Read the attributes from the existing idx file */ diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index bfe0197d12..ffbd48c60c 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3902,7 +3902,7 @@ static void show_edge(struct commit *commit) add_preferred_base(&commit->object.oid); } -static int add_object_in_unpacked_pack(struct repository *repo UNUSED, +static int add_object_in_unpacked_pack(struct repository *repo, const struct object_id *oid, struct packed_git *pack, uint32_t pos, @@ -3913,7 +3913,7 @@ static int add_object_in_unpacked_pack(struct repository *repo UNUSED, time_t mtime; if (pack->is_cruft) { - if (load_pack_mtimes(pack) < 0) + if (load_pack_mtimes(repo, pack) < 0) die(_("could not load cruft pack .mtimes")); mtime = nth_packed_mtime(pack, pos); } else { @@ -4035,7 +4035,7 @@ static void loosen_unused_packed_objects(void) if (!p->pack_local || p->pack_keep || p->pack_keep_in_core) continue; - if (open_pack_index(p)) + if (open_pack_index(the_repository, p)) die(_("cannot open pack index")); for (i = 0; i < p->num_objects; i++) { diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index 60f806e672..bc3c3e9c4e 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -545,7 +545,7 @@ static struct pack_list * add_pack(struct packed_git *p) l.pack = p; llist_init(&l.remaining_objects); - if (open_pack_index(p)) + if (open_pack_index(the_repository, p)) return NULL; base = p->index_data; diff --git a/builtin/repack.c b/builtin/repack.c index de03a3ecfc..5f317ba224 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -461,7 +461,7 @@ struct pack_geometry { static uint32_t geometry_pack_weight(struct packed_git *p) { - if (open_pack_index(p)) + if (open_pack_index(the_repository, p)) die(_("cannot open index for %s"), p->pack_name); return p->num_objects; } diff --git a/commit-graph.c b/commit-graph.c index 96d55f8885..35e4e9d99d 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1920,7 +1920,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx, ret = error(_("error adding pack %s"), packname.buf); goto cleanup; } - if (open_pack_index(p)) { + if (open_pack_index(the_repository, p)) { ret = error(_("error opening index for %s"), packname.buf); goto cleanup; } diff --git a/midx-write.c b/midx-write.c index 4696b8326c..2b7c50d25c 100644 --- a/midx-write.c +++ b/midx-write.c @@ -161,7 +161,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len, return; } - if (open_pack_index(p)) { + if (open_pack_index(the_repository, p)) { warning(_("failed to open pack-index '%s'"), full_path); close_pack(p); @@ -301,8 +301,8 @@ static void midx_fanout_add_pack_fanout(struct midx_fanout *fanout, uint32_t cur_object; if (cur_fanout) - start = get_pack_fanout(pack, cur_fanout - 1); - end = get_pack_fanout(pack, cur_fanout); + start = get_pack_fanout(the_repository, pack, cur_fanout - 1); + end = get_pack_fanout(the_repository, pack, cur_fanout); for (cur_object = start; cur_object < end; cur_object++) { midx_fanout_grow(fanout, fanout->nr + 1); @@ -950,7 +950,7 @@ static int fill_packs_from_midx(struct write_midx_context *ctx, return 1; } - if (open_pack_index(m->packs[i])) + if (open_pack_index(the_repository, m->packs[i])) die(_("could not open index for %s"), m->packs[i]->pack_name); } @@ -1612,7 +1612,7 @@ static int want_included_pack(struct repository *r, return 0; if (p->is_cruft) return 0; - if (open_pack_index(p) || !p->num_objects) + if (open_pack_index(r, p) || !p->num_objects) return 0; return 1; } diff --git a/midx.c b/midx.c index c76df95d6d..edbd2008e3 100644 --- a/midx.c +++ b/midx.c @@ -966,7 +966,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag continue; } - if (open_pack_index(e.p)) { + if (open_pack_index(the_repository, e.p)) { midx_report(_("failed to load pack-index for packfile %s"), e.p->pack_name); break; diff --git a/object-name.c b/object-name.c index 43023884ef..368242133a 100644 --- a/object-name.c +++ b/object-name.c @@ -175,7 +175,7 @@ static void unique_in_pack(struct packed_git *p, if (p->multi_pack_index) return; - if (open_pack_index(p) || !p->num_objects) + if (open_pack_index(ds->repo, p) || !p->num_objects) return; num = p->num_objects; @@ -761,7 +761,7 @@ static void find_abbrev_len_for_pack(struct packed_git *p, if (p->multi_pack_index) return; - if (open_pack_index(p) || !p->num_objects) + if (open_pack_index(mad->repo, p) || !p->num_objects) return; num = p->num_objects; diff --git a/pack-check.c b/pack-check.c index a5551809c1..d93cf3f224 100644 --- a/pack-check.c +++ b/pack-check.c @@ -176,7 +176,7 @@ int verify_pack_index(struct packed_git *p) { int err = 0; - if (open_pack_index(p)) + if (open_pack_index(the_repository, p)) return error("packfile %s index not opened", p->pack_name); /* Verify SHA1 sum of the index file */ diff --git a/pack-mtimes.c b/pack-mtimes.c index cdf30b8d2b..a9fa8d55de 100644 --- a/pack-mtimes.c +++ b/pack-mtimes.c @@ -97,7 +97,7 @@ static int load_pack_mtimes_file(char *mtimes_file, return ret; } -int load_pack_mtimes(struct packed_git *p) +int load_pack_mtimes(struct repository *repo, struct packed_git *p) { char *mtimes_name = NULL; int ret = 0; @@ -107,7 +107,7 @@ int load_pack_mtimes(struct packed_git *p) if (p->mtimes_map) return ret; /* already loaded */ - ret = open_pack_index(p); + ret = open_pack_index(repo, p); if (ret < 0) goto cleanup; diff --git a/pack-mtimes.h b/pack-mtimes.h index 107327cec0..22ab6a8481 100644 --- a/pack-mtimes.h +++ b/pack-mtimes.h @@ -5,12 +5,13 @@ #define MTIMES_VERSION 1 struct packed_git; +struct repository; /* * Loads the .mtimes file corresponding to "p", if any, returning zero * on success. */ -int load_pack_mtimes(struct packed_git *p); +int load_pack_mtimes(struct repository *repo, struct packed_git *p); /* Returns the mtime associated with the object at position "pos" (in * lexicographic/index order) in pack "p". diff --git a/pack-revindex.c b/pack-revindex.c index 22d3c23464..c14ef971da 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -178,7 +178,7 @@ static int create_pack_revindex_in_memory(struct packed_git *p) if (git_env_bool(GIT_TEST_REV_INDEX_DIE_IN_MEMORY, 0)) die("dying as requested by '%s'", GIT_TEST_REV_INDEX_DIE_IN_MEMORY); - if (open_pack_index(p)) + if (open_pack_index(the_repository, p)) return -1; create_pack_revindex(p); return 0; @@ -274,7 +274,7 @@ int load_pack_revindex_from_disk(struct packed_git *p) { char *revindex_name; int ret; - if (open_pack_index(p)) + if (open_pack_index(the_repository, p)) return -1; revindex_name = pack_revindex_filename(p); diff --git a/packfile.c b/packfile.c index 831d2c2c74..b0147231cb 100644 --- a/packfile.c +++ b/packfile.c @@ -84,13 +84,14 @@ void pack_report(void) * consistency checks, then record its information to p. Return 0 on * success. */ -static int check_packed_git_idx(const char *path, struct packed_git *p) +static int check_packed_git_idx(struct repository *repo, const char *path, + struct packed_git *p) { void *idx_map; size_t idx_size; int fd = git_open(path), ret; struct stat st; - const unsigned int hashsz = the_hash_algo->rawsz; + const unsigned int hashsz = repo->hash_algo->rawsz; if (fd < 0) return -1; @@ -194,7 +195,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map, return 0; } -int open_pack_index(struct packed_git *p) +int open_pack_index(struct repository *repo, struct packed_git *p) { char *idx_name; size_t len; @@ -206,17 +207,18 @@ int open_pack_index(struct packed_git *p) if (!strip_suffix(p->pack_name, ".pack", &len)) BUG("pack_name does not end in .pack"); idx_name = xstrfmt("%.*s.idx", (int)len, p->pack_name); - ret = check_packed_git_idx(idx_name, p); + ret = check_packed_git_idx(repo, idx_name, p); free(idx_name); return ret; } -uint32_t get_pack_fanout(struct packed_git *p, uint32_t value) +uint32_t get_pack_fanout(struct repository *repo, struct packed_git *p, + uint32_t value) { const uint32_t *level1_ofs = p->index_data; if (!level1_ofs) { - if (open_pack_index(p)) + if (open_pack_index(repo, p)) return 0; level1_ofs = p->index_data; } @@ -246,7 +248,7 @@ struct packed_git *parse_pack_index(struct repository *repo, memcpy(p->pack_name, path, alloc); /* includes NUL */ hashcpy(p->hash, sha1, repo->hash_algo); - if (check_packed_git_idx(idx_path, p)) { + if (check_packed_git_idx(repo, idx_path, p)) { free(p); return NULL; } @@ -544,7 +546,7 @@ static int open_packed_git_1(struct repository *repo, struct packed_git *p) ssize_t read_result; const unsigned hashsz = the_hash_algo->rawsz; - if (open_pack_index(p)) + if (open_pack_index(repo, p)) return error("packfile %s index unavailable", p->pack_name); if (!pack_max_fds) { @@ -951,7 +953,7 @@ unsigned long repo_approximate_object_count(struct repository *r) for (m = get_multi_pack_index(r); m; m = m->next) count += m->num_objects; for (p = r->objects->packed_git; p; p = p->next) { - if (open_pack_index(p)) + if (open_pack_index(r, p)) continue; count += p->num_objects; } @@ -1923,7 +1925,7 @@ int nth_packed_object_id(struct repository *repo, struct object_id *oid, const unsigned char *index = p->index_data; const unsigned int hashsz = repo->hash_algo->rawsz; if (!index) { - if (open_pack_index(p)) + if (open_pack_index(repo, p)) return -1; index = p->index_data; } @@ -1983,7 +1985,7 @@ off_t find_pack_entry_one(struct repository *repo, const unsigned char *sha1, uint32_t result; if (!index) { - if (open_pack_index(p)) + if (open_pack_index(repo, p)) return 0; } @@ -2226,7 +2228,7 @@ int for_each_packed_object(struct repository *repo, each_packed_object_fn cb, if ((flags & FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS) && p->pack_keep) continue; - if (open_pack_index(p)) { + if (open_pack_index(repo, p)) { pack_errors = 1; continue; } diff --git a/packfile.h b/packfile.h index afec4bbd74..98ec3616b4 100644 --- a/packfile.h +++ b/packfile.h @@ -97,7 +97,7 @@ void pack_report(void); * mmap the index file for the specified packfile (if it is not * already mmapped). Return 0 on success. */ -int open_pack_index(struct packed_git *); +int open_pack_index(struct repository *repo, struct packed_git *); /* * munmap the index file for the specified packfile (if it is @@ -107,7 +107,8 @@ void close_pack_index(struct packed_git *); int close_pack_fd(struct packed_git *p); -uint32_t get_pack_fanout(struct packed_git *p, uint32_t value); +uint32_t get_pack_fanout(struct repository *repo, struct packed_git *p, + uint32_t value); struct raw_object_store; diff --git a/reachable.c b/reachable.c index f8dc2731d6..833013e7a3 100644 --- a/reachable.c +++ b/reachable.c @@ -291,7 +291,7 @@ static int add_recent_packed(struct repository *repo, if (obj && obj->flags & SEEN) return 0; if (p->is_cruft) { - if (load_pack_mtimes(p) < 0) + if (load_pack_mtimes(repo, p) < 0) die(_("could not load cruft pack .mtimes")); mtime = nth_packed_mtime(p, pos); } diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c index ebd980b308..b1caeba097 100644 --- a/t/helper/test-pack-mtimes.c +++ b/t/helper/test-pack-mtimes.c @@ -11,7 +11,7 @@ static void dump_mtimes(struct packed_git *p) { uint32_t i; - if (load_pack_mtimes(p) < 0) + if (load_pack_mtimes(the_repository, p) < 0) die("could not load pack .mtimes"); for (i = 0; i < p->num_objects; i++) { From patchwork Mon Oct 21 09:58:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843803 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 6D04E1E47D3 for ; Mon, 21 Oct 2024 09:58:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504703; cv=none; b=gZ96ICGhNE/1lhMyco5IYADt40hRwoetdAWFrCuWOJZpVZzhAhR7AdXzhy4XgmzY1hKgceFE2EZTl7JkY3uqPvXOE32TLUOHZ07jsXa+xoEdBx3aHfCPquHRSSDo96O87aeKUgrbW9dBaRSjnXIiNrmODHa0Hpl8FArPnI/pAfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504703; c=relaxed/simple; bh=ISgypjhvzcRaMqnVcWBLHVsYHiFdzX1HnAF+bxdDRsw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F+OtXm1SKu/RrD/TEK5M8/nopvdp7cbYWPFvakayttA2HdgBQdGq7G2kd0bGTPzpGpecEyRRGiijoxfeNBuoz3ayRp6LmuvUz3v3EbLmU23AWySOVbwtmqzmWHf9vYjFq7aERVC+hstHh34Mvej66obhp3hyzmNLR/GisaWigqI= 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=OToNivyC; arc=none smtp.client-ip=209.85.218.53 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="OToNivyC" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a99cc265e0aso620576666b.3 for ; Mon, 21 Oct 2024 02:58:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504700; x=1730109500; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B2LnPJzz+cQzYSiG278Ps7YoGhH9xVmXVzPeQLwEjY0=; b=OToNivyCkagNfhfsmnq+2kpeWRQSyUECIBTNJ2qb1FE9+F+jkwurM4GGvqvxuot46x YafENBD26LSw96/T8WJMjQMzR1yBuNrDAWkb330CuvhiHbcoy/NsPgfwXbOru91qSwi7 JsvZl5jev9r3dv2fdpgrJigRAi5CbJyYvSdPblPvob0r5cws1Lt7LGT9s+4A6DwpzsB3 nztJgBTb3k+UybQG0YtR4S4an4xZccb2LsNOba0EJZu2M6dKDoOVKFXF1yu9wG4GSbtM L+2n097+Y/Sse+62a9B/o+V91sVg/KsaukgjX1209OHaE9Fn6joK0SqJXD7lv14Mvq9A PMNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504700; x=1730109500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B2LnPJzz+cQzYSiG278Ps7YoGhH9xVmXVzPeQLwEjY0=; b=B1HPPnnqXXcaFCzLtUTFVS9DKGB30BMt/uQAo77svVI+/ekFSGHA1nepz8PFlisC5l up+ahGQIkd29n/bfx0Ap4h2uRQWMfojxkW4aFrt9I64OgVI7Ct/d+hv3PE8UHMSTBgTu uI++hhwamTteyKbDVZYSj5INzPXaXDxrNIZ1fB6zfF7xT0IV3YDoOWEETZEvcM+GVpiU N+kB5b7zk07hlu1caTIDia1Xc8PgtTSDQaswxrJJ/vv8wP3M8gC8OBAatoM7Dl4Q5R0Q Ew+9t6M7p/TuWfE1qzvGzC5gss5fNVizcTVmAHwniAS6AHQ/HmETwjd8o693LbD3FrTM q3NA== X-Gm-Message-State: AOJu0YwzQKy3ZtisjcfsTSFi3hYgqsjzB90F0hMZB32gRblWrnfZITHQ tdkQNY3edkXYPRdJPPabjIzOiUjPta2BnoiLJwZSIs+7nnfy/bs/Za7Ydrdr X-Google-Smtp-Source: AGHT+IGDZTfkpv8AY1EuPftivtrxDFHe3Kxeq8PTFEmcjw+eouQh24k28G0t+xerqFEQK0ZhGguajA== X-Received: by 2002:a17:907:7214:b0:a9a:2afc:e4e3 with SMTP id a640c23a62f3a-a9a69c55bdfmr868628866b.50.1729504699435; Mon, 21 Oct 2024 02:58:19 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:19 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 17/20] packfile: stop using 'the_hash_algo' Date: Mon, 21 Oct 2024 11:58:00 +0200 Message-ID: <9be98d3e1bfaabf725286cdefaf02e48568f7028.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make changes to functions in 'packfile.c' to stop using the global 'the_hash_algo'. This requires changing some of the functions to accept a repository variable and to modify layers above to pass this variable. Signed-off-by: Karthik Nayak --- object-name.c | 4 ++-- pack-bitmap.c | 2 +- packfile.c | 29 ++++++++++++++++++----------- packfile.h | 3 ++- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/object-name.c b/object-name.c index 368242133a..83a36915d6 100644 --- a/object-name.c +++ b/object-name.c @@ -179,7 +179,7 @@ static void unique_in_pack(struct packed_git *p, return; num = p->num_objects; - bsearch_pack(&ds->bin_pfx, p, &first); + bsearch_pack(ds->repo, &ds->bin_pfx, p, &first); /* * At this point, "first" is the location of the lowest object @@ -766,7 +766,7 @@ static void find_abbrev_len_for_pack(struct packed_git *p, num = p->num_objects; mad_oid = mad->oid; - match = bsearch_pack(mad_oid, p, &first); + match = bsearch_pack(mad->repo, mad_oid, p, &first); /* * first is now the position in the packfile where we would insert diff --git a/pack-bitmap.c b/pack-bitmap.c index 97237acb24..da2fc45f3f 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -741,7 +741,7 @@ static uint32_t bitmap_bsearch_pos(struct bitmap_index *bitmap_git, if (bitmap_is_midx(bitmap_git)) found = bsearch_midx(oid, bitmap_git->midx, result); else - found = bsearch_pack(oid, bitmap_git->pack, result); + found = bsearch_pack(the_repository, oid, bitmap_git->pack, result); return found; } diff --git a/packfile.c b/packfile.c index b0147231cb..e06931154f 100644 --- a/packfile.c +++ b/packfile.c @@ -30,7 +30,7 @@ char *odb_pack_name(struct repository *repo, struct strbuf *buf, { strbuf_reset(buf); strbuf_addf(buf, "%s/pack/pack-%s.%s", repo_get_object_directory(repo), - hash_to_hex(hash), ext); + hash_to_hex_algop(hash, repo->hash_algo), ext); return buf->buf; } @@ -544,7 +544,7 @@ static int open_packed_git_1(struct repository *repo, struct packed_git *p) unsigned char hash[GIT_MAX_RAWSZ]; unsigned char *idx_hash; ssize_t read_result; - const unsigned hashsz = the_hash_algo->rawsz; + const unsigned hashsz = repo->hash_algo->rawsz; if (open_pack_index(repo, p)) return error("packfile %s index unavailable", p->pack_name); @@ -614,7 +614,8 @@ static int open_packed_git(struct repository *repo, struct packed_git *p) return -1; } -static int in_window(struct pack_window *win, off_t offset) +static int in_window(struct repository *repo, struct pack_window *win, + off_t offset) { /* We must promise at least one full hash after the * offset is available from this window, otherwise the offset @@ -624,7 +625,7 @@ static int in_window(struct pack_window *win, off_t offset) */ off_t win_off = win->offset; return win_off <= offset - && (offset + the_hash_algo->rawsz) <= (win_off + win->len); + && (offset + repo->hash_algo->rawsz) <= (win_off + win->len); } unsigned char *use_pack(struct repository *repo, struct packed_git *p, @@ -640,16 +641,16 @@ unsigned char *use_pack(struct repository *repo, struct packed_git *p, */ if (!p->pack_size && p->pack_fd == -1 && open_packed_git(repo, p)) die("packfile %s cannot be accessed", p->pack_name); - if (offset > (p->pack_size - the_hash_algo->rawsz)) + if (offset > (p->pack_size - repo->hash_algo->rawsz)) die("offset beyond end of packfile (truncated pack?)"); if (offset < 0) die(_("offset before end of packfile (broken .idx?)")); - if (!win || !in_window(win, offset)) { + if (!win || !in_window(repo, win, offset)) { if (win) win->inuse_cnt--; for (win = p->windows; win; win = win->next) { - if (in_window(win, offset)) + if (in_window(repo, win, offset)) break; } if (!win) { @@ -714,6 +715,7 @@ struct packed_git *add_packed_git(struct repository *repo, const char *path, struct stat st; size_t alloc; struct packed_git *p; + struct object_id oid; /* * Make sure a corresponding .pack file exists and that @@ -755,8 +757,12 @@ struct packed_git *add_packed_git(struct repository *repo, const char *path, p->pack_local = local; p->mtime = st.st_mtime; if (path_len < repo->hash_algo->hexsz || - get_hash_hex(path + path_len - repo->hash_algo->hexsz, p->hash)) + get_oid_hex_algop(path + path_len - repo->hash_algo->hexsz, &oid, + repo->hash_algo)) hashclr(p->hash, repo->hash_algo); + else + memcpy(p->hash, oid.hash, repo->hash_algo->rawsz); + return p; } @@ -1895,11 +1901,12 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset, return data; } -int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32_t *result) +int bsearch_pack(struct repository *repo, const struct object_id *oid, + const struct packed_git *p, uint32_t *result) { const unsigned char *index_fanout = p->index_data; const unsigned char *index_lookup; - const unsigned int hashsz = the_hash_algo->rawsz; + const unsigned int hashsz = repo->hash_algo->rawsz; int index_lookup_width; if (!index_fanout) @@ -1990,7 +1997,7 @@ off_t find_pack_entry_one(struct repository *repo, const unsigned char *sha1, } hashcpy(oid.hash, sha1, repo->hash_algo); - if (bsearch_pack(&oid, p, &result)) + if (bsearch_pack(repo, &oid, p, &result)) return nth_packed_object_offset(p, result); return 0; } diff --git a/packfile.h b/packfile.h index 98ec3616b4..d145959480 100644 --- a/packfile.h +++ b/packfile.h @@ -145,7 +145,8 @@ void check_pack_index_ptr(const struct packed_git *p, const void *ptr); * * See 'bsearch_hash' for more information. */ -int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32_t *result); +int bsearch_pack(struct repository *repo, const struct object_id *oid, + const struct packed_git *p, uint32_t *result); /* * Write the oid of the nth object within the specified packfile into the first From patchwork Mon Oct 21 09:58:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843804 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 4F8041E7C0F for ; Mon, 21 Oct 2024 09:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504704; cv=none; b=JzD6QvJViJY0Uc9sOpB/l/eGxlni2qoeUNSUbdlX6L0iGU7/qug3WFnjXphhCmwsxovq/5d6xGp9k3pRKnoV9vBNVmMYFfC8JB8RUjKnBex4qXWti/nHr5z/iikIau+f3Cs91CsyxaSN9Vb6tBOJF39UEQOQfXKZSBugx5eF6iI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504704; c=relaxed/simple; bh=KhCX0GczazViNfbUy49HHxNBcC2NMjXVntKCV00SW6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fSD4OopFRue5Kn//Lu/yEEPl/c++41Qi+mEwyacSdDI8zneJhCdaIWLZqWuS5ywD8JY5HGm0RHpftmdBAz0cqW/p+bdr5T5e5Okm8BtU/L0xiF2/wHc4XGl90S7wi/WYNByY1En8E098z77alOWLD0+Xmj9901CNg1p6+ZYxT0I= 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=IxNh8Wfn; arc=none smtp.client-ip=209.85.218.54 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="IxNh8Wfn" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a9a628b68a7so539874866b.2 for ; Mon, 21 Oct 2024 02:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504700; x=1730109500; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Mq7BBr6N06celAmlSLi8Us45icUaYjmWxIT6FLOCszk=; b=IxNh8WfntwvKMSLbwLA/RhN6G9tkkN2gjr+F4NfaWmXjGKLDyyZMUeS/FkYPYc/dsL Sv1MnSHd7GW5/msg/0GrqLn1TnRYJxUJ3shJ8KAcvFsWsb6Pz0INdoRIYTOHy1G2fyde o/vHKW1YxgDAwzeExTvIweN/aGa+u3SyG3BeZzn97Ozm/GEDUl2Anw4Oq6jSMa3E1KeG E+EBLzz39VGnoOLoUC+QTgBl0+r/BmOGjxNTgdBfA+8lzSL62YG204lFjHWKmncCX+w2 8WoAN3n3prsK3lbV4bUXPSAMiqCBbll0YRQzq4GYXZ/wwBH+U0xAycwY01hImSFzNJB9 vc6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504700; x=1730109500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Mq7BBr6N06celAmlSLi8Us45icUaYjmWxIT6FLOCszk=; b=eThqgqvRRkS6OdENrABCm3Rkbuiwp3n00mWARBXb6SCx5Zuo84EVAANFYfqJZ7N9LJ 59prbExnGdmJRdFs1I+DFysKtyANuLsg3sVIfBv6kxJEcvd/4XqFWX0xlLnZa0uwb+gk Ov/6JS/2lRa3lS3mM6hIfrNBWk9sWVZBdn30DAsoZ60E77CRwMn/9QdIt90cZsfpl7VD Tx+ygJD33OEXbUFv+yIlfbY+076O3fGRfH5kx6Sun/1reLC9GbdPnGdaESgf7YreAK9k xH+Mq05AuAzs3KITq8dlS4jQkdRc/t6rEiSdNClGok1GaSv8yGQuBYo00FKuj3neDgW+ LTQw== X-Gm-Message-State: AOJu0YyyXhw2GXhIzZtTcNkfxn09QVwEzozqQnaGC4PJ8IdZgWfqFnR4 76ZbSD4HuBS6YAkvvFf65ni2m4Hchzfn5yyPYWYmB0DnD6QhbmPJ62jakLC5 X-Google-Smtp-Source: AGHT+IFiLMMvh8dQnEz83sl0Yc0tk1AwSQbf8vwLWOy9eZmjoC+9IynDR8vvn3MIoVpA36uYG3L9Bw== X-Received: by 2002:a17:907:6e89:b0:a8a:8cdb:83a7 with SMTP id a640c23a62f3a-a9a69ca05b0mr1130165566b.54.1729504700119; Mon, 21 Oct 2024 02:58:20 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:19 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 18/20] packfile: pass down repository to `nth_packed_object_offset` Date: Mon, 21 Oct 2024 11:58:01 +0200 Message-ID: <973e8a560d48343e07a02bab88b31bfb5d3e903a.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function `nth_packed_object_offset` currently relies on the global variable `the_repository`. To eliminate global variable usage in `packfile.c`, we should progressively shift the dependency on the_repository to higher layers. Let's remove its usage from this function and any related ones. Signed-off-by: Karthik Nayak --- builtin/cat-file.c | 4 ++-- builtin/pack-objects.c | 6 +++--- commit-graph.c | 2 +- midx-write.c | 2 +- pack-check.c | 2 +- pack-revindex.c | 3 ++- packfile.c | 8 +++++--- packfile.h | 4 +++- reachable.c | 3 ++- 9 files changed, 20 insertions(+), 14 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index e5d774b097..8aab7481b6 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -632,14 +632,14 @@ static int batch_unordered_loose(const struct object_id *oid, return batch_unordered_object(oid, NULL, 0, data); } -static int batch_unordered_packed(struct repository *repo UNUSED, +static int batch_unordered_packed(struct repository *repo, const struct object_id *oid, struct packed_git *pack, uint32_t pos, void *data) { return batch_unordered_object(oid, pack, - nth_packed_object_offset(pack, pos), + nth_packed_object_offset(repo, pack, pos), data); } diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index ffbd48c60c..8ab51eab8d 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3361,7 +3361,7 @@ static int git_pack_config(const char *k, const char *v, static int stdin_packs_found_nr; static int stdin_packs_hints_nr; -static int add_object_entry_from_pack(struct repository *repo UNUSED, +static int add_object_entry_from_pack(struct repository *repo, const struct object_id *oid, struct packed_git *p, uint32_t pos, @@ -3375,7 +3375,7 @@ static int add_object_entry_from_pack(struct repository *repo UNUSED, if (have_duplicate_entry(oid, 0)) return 0; - ofs = nth_packed_object_offset(p, pos); + ofs = nth_packed_object_offset(repo, p, pos); if (!want_object_in_pack(oid, 0, &p, &ofs)) return 0; @@ -3919,7 +3919,7 @@ static int add_object_in_unpacked_pack(struct repository *repo, } else { mtime = pack->mtime; } - offset = nth_packed_object_offset(pack, pos); + offset = nth_packed_object_offset(repo, pack, pos); add_cruft_object_entry(oid, OBJ_NONE, pack, offset, NULL, mtime); diff --git a/commit-graph.c b/commit-graph.c index 35e4e9d99d..24aae68195 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1495,7 +1495,7 @@ static int add_packed_commits(struct repository *repo UNUSED, { struct write_commit_graph_context *ctx = (struct write_commit_graph_context*)data; enum object_type type; - off_t offset = nth_packed_object_offset(pack, pos); + off_t offset = nth_packed_object_offset(ctx->r, pack, pos); struct object_info oi = OBJECT_INFO_INIT; if (ctx->progress) diff --git a/midx-write.c b/midx-write.c index 2b7c50d25c..69aada253f 100644 --- a/midx-write.c +++ b/midx-write.c @@ -233,7 +233,7 @@ static void fill_pack_entry(uint32_t pack_int_id, entry->pack_int_id = pack_int_id; entry->pack_mtime = p->mtime; - entry->offset = nth_packed_object_offset(p, cur_object); + entry->offset = nth_packed_object_offset(the_repository, p, cur_object); entry->preferred = !!preferred; } diff --git a/pack-check.c b/pack-check.c index d93cf3f224..01562267a4 100644 --- a/pack-check.c +++ b/pack-check.c @@ -98,7 +98,7 @@ static int verify_packfile(struct repository *r, entries[nr_objects].offset = pack_sig_ofs; /* first sort entries by pack offset, since unpacking them is more efficient that way */ for (i = 0; i < nr_objects; i++) { - entries[i].offset = nth_packed_object_offset(p, i); + entries[i].offset = nth_packed_object_offset(r, p, i); entries[i].nr = i; } QSORT(entries, nr_objects, compare_entries); diff --git a/pack-revindex.c b/pack-revindex.c index c14ef971da..03d8c39c94 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -466,7 +466,8 @@ off_t pack_pos_to_offset(struct packed_git *p, uint32_t pos) else if (pos == p->num_objects) return p->pack_size - the_hash_algo->rawsz; else - return nth_packed_object_offset(p, pack_pos_to_index(p, pos)); + return nth_packed_object_offset(the_repository, p, + pack_pos_to_index(p, pos)); } uint32_t pack_pos_to_midx(struct multi_pack_index *m, uint32_t pos) diff --git a/packfile.c b/packfile.c index e06931154f..1415df38e9 100644 --- a/packfile.c +++ b/packfile.c @@ -1964,10 +1964,12 @@ void check_pack_index_ptr(const struct packed_git *p, const void *vptr) p->pack_name); } -off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n) +off_t nth_packed_object_offset(struct repository *repo, + const struct packed_git *p, + uint32_t n) { const unsigned char *index = p->index_data; - const unsigned int hashsz = the_hash_algo->rawsz; + const unsigned int hashsz = repo->hash_algo->rawsz; index += 4 * 256; if (p->index_version == 1) { return ntohl(*((uint32_t *)(index + st_mult(hashsz + 4, n)))); @@ -1998,7 +2000,7 @@ off_t find_pack_entry_one(struct repository *repo, const unsigned char *sha1, hashcpy(oid.hash, sha1, repo->hash_algo); if (bsearch_pack(repo, &oid, p, &result)) - return nth_packed_object_offset(p, result); + return nth_packed_object_offset(repo, p, result); return 0; } diff --git a/packfile.h b/packfile.h index d145959480..9184560f0e 100644 --- a/packfile.h +++ b/packfile.h @@ -160,7 +160,9 @@ int nth_packed_object_id(struct repository *repo, struct object_id *, * Return the offset of the nth object within the specified packfile. * The index must already be opened. */ -off_t nth_packed_object_offset(const struct packed_git *, uint32_t n); +off_t nth_packed_object_offset(struct repository *repo, + const struct packed_git *, + uint32_t n); /* * If the object named sha1 is present in the specified packfile, diff --git a/reachable.c b/reachable.c index 833013e7a3..e347e2d6ca 100644 --- a/reachable.c +++ b/reachable.c @@ -295,7 +295,8 @@ static int add_recent_packed(struct repository *repo, die(_("could not load cruft pack .mtimes")); mtime = nth_packed_mtime(p, pos); } - add_recent_object(oid, p, nth_packed_object_offset(p, pos), mtime, data); + add_recent_object(oid, p, nth_packed_object_offset(repo, p, pos), mtime, + data); return 0; } From patchwork Mon Oct 21 09:58:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843805 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 CDDCA1E8826 for ; Mon, 21 Oct 2024 09:58:22 +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=1729504705; cv=none; b=SkKthg4cSG1Ejtw1bLm0gUZCCdxp3ZnrI9qUIzyBxGtLBky4dlLWY9KbkbUEchaI8TwRP7Pp1eWHK5i3M1qcklR6zhSVVMx9dZ4lfVdkJaJZNOoXIpr7jTiPLchQU7eUTrfsargKB8LdugZHJIbtmkTAuiinSTtdlcqtdxPeoz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504705; c=relaxed/simple; bh=OCg36hFeewasaQEA3iNtJ44ENuPFSBxeOSlB721BK9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TcchBa8VnPdeKl73qM+XC/HmoceXm1jvAjIHe7L1aVISHQ1RskTrtkhGdrnr5wvunKfC5t5TyJDGV7pQS1jbi+BMUrSYjcHzrrHfTjV5yf9qOjhtbQnxqUhamdTNGRamLSZ11C4W7kTUlflR6EJrHg+s+kwEFaDnWOiWC3KlzYU= 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=A3BUNCgt; 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="A3BUNCgt" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a93c1cc74fdso632677066b.3 for ; Mon, 21 Oct 2024 02:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504701; x=1730109501; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dWnn1wOSbxo76WjiRnaI5PmbDdmzTaf644Y7ccr05N8=; b=A3BUNCgta3oLQBNzrzaQ+0Tmm1G0g3e4RRT/k0r7Ba2NTfreshvuvkwmxt7R+qqb8B Mig2CmSFBt8a18qsuVe0uah3luT3OiPOqJ/fCFLm2wooVdAklYRy+nUw0DQUFrModudm +1kdsWmpJAvzqtIfUFeTpDHz93QHhTTWHKbf8px9Brr5MUIyXC0wv3D0SN6tLXuXz179 4wdBZAv2dt67GZrWfczPNpWKLdE5pi7zw+pcQValZZqt3K1qhRTNrfLs6LeXJhKodSel MOiR2I9AkStpc77zhp3w8hfsQFrdpoyq7NuVLg6e7rGg+yZCDY5znwR+3PKxUKNF7Co/ 6rNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504701; x=1730109501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dWnn1wOSbxo76WjiRnaI5PmbDdmzTaf644Y7ccr05N8=; b=sh87oRihrh/phNEZcX32DFl2Qjje0L+qCIHCpTuUeXW+en9uTKJvhbRigqBeQPhfIj JEsdiZCulnY48cXA6hlk1KfdClHkeQ4niFca4PGypOP2ofUMFerqS+xYahcY1AWOdWLY qc8g9ubHd4vTquCqMx8dKBGwL5SobATdXrXEiMx+99eiN9HpM5WSu6cbLKTHzfs8rqfy owCNxyyrY13cCWaHZJoLtLVyYzfO8/Aheyyz9R7uQYb+6p5YBsC9yzuZtkwMwFtKInC9 oSJBu1/fBEDNWVXL/IsJXMKQVms5VFfghkz0EbshGQiw7cowKe3rOz3rIBZH8s2V70Vu CM7Q== X-Gm-Message-State: AOJu0YyOqiTAuAyQBUnclR1RVS27UbWoSSXMvy+h+jL2iXmirBIB/X2h xbeUOdN23xtDe36m2huL2IXyzjkOr664+95LNSaQfAxmUFbwvx7eBVAEaghW X-Google-Smtp-Source: AGHT+IHsIFifYWznAC8umUIRZ+MUOZir++rdR2qo2TcZwMWdHhyZm1MdLVNoHdxTj4jAkO1t7+c+aw== X-Received: by 2002:a17:906:c102:b0:a9a:33c:f6e1 with SMTP id a640c23a62f3a-a9a69a639a3mr1032571466b.5.1729504700853; Mon, 21 Oct 2024 02:58:20 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:20 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 19/20] config: make `delta_base_cache_limit` a non-global variable Date: Mon, 21 Oct 2024 11:58:02 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The `delta_base_cache_limit` variable is a global config variable used by multiple subsystems. Let's make this non-global, by adding this variable to the stack of each of the subsystems where it is used. In `gc.c` we add it to the `gc_config` struct and also the constructor function. In `index-pack.c` we add it to the `pack_idx_option` struct and its constructor. Finally, in `packfile.c` we dynamically retrieve this value from the repository config, since the value is only used once in the entire subsystem. Signed-off-by: Karthik Nayak --- builtin/gc.c | 5 ++++- builtin/index-pack.c | 10 +++++++--- config.c | 5 ----- environment.c | 1 - environment.h | 1 - pack-objects.h | 3 ++- pack-write.c | 1 + pack.h | 1 + packfile.c | 13 +++++++++++-- 9 files changed, 26 insertions(+), 14 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index d52735354c..9a10eb58bc 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -138,6 +138,7 @@ struct gc_config { char *repack_filter_to; unsigned long big_pack_threshold; unsigned long max_delta_cache_size; + unsigned long delta_base_cache_limit; }; #define GC_CONFIG_INIT { \ @@ -153,6 +154,7 @@ struct gc_config { .prune_expire = xstrdup("2.weeks.ago"), \ .prune_worktrees_expire = xstrdup("3.months.ago"), \ .max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE, \ + .delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT, \ } static void gc_config_release(struct gc_config *cfg) @@ -205,6 +207,7 @@ static void gc_config(struct gc_config *cfg) git_config_get_ulong("gc.bigpackthreshold", &cfg->big_pack_threshold); git_config_get_ulong("pack.deltacachesize", &cfg->max_delta_cache_size); + git_config_get_ulong("core.deltabasecachelimit", &cfg->delta_base_cache_limit); if (!git_config_get_string("gc.repackfilter", &owned)) { free(cfg->repack_filter); @@ -416,7 +419,7 @@ static uint64_t estimate_repack_memory(struct gc_config *cfg, * read_sha1_file() (either at delta calculation phase, or * writing phase) also fills up the delta base cache */ - heap += delta_base_cache_limit; + heap += cfg->delta_base_cache_limit; /* and of course pack-objects has its own delta cache */ heap += cfg->max_delta_cache_size; diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 1898dc37a6..f1edf7068d 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1238,7 +1238,7 @@ static void parse_pack_objects(unsigned char *hash) * recursively checking if the resulting object is used as a base * for some more deltas. */ -static void resolve_deltas(void) +static void resolve_deltas(struct pack_idx_option *opts) { int i; @@ -1254,7 +1254,7 @@ static void resolve_deltas(void) nr_ref_deltas + nr_ofs_deltas); nr_dispatched = 0; - base_cache_limit = delta_base_cache_limit * nr_threads; + base_cache_limit = opts->delta_base_cache_limit * nr_threads; if (nr_threads > 1 || getenv("GIT_FORCE_THREADS")) { init_thread(); work_lock(); @@ -1604,6 +1604,10 @@ static int git_index_pack_config(const char *k, const char *v, else opts->flags &= ~WRITE_REV; } + if (!strcmp(k, "core.deltabasecachelimit")) { + opts->delta_base_cache_limit = git_config_ulong(k, v, ctx->kvi); + return 0; + } return git_default_config(k, v, ctx, cb); } @@ -1930,7 +1934,7 @@ int cmd_index_pack(int argc, parse_pack_objects(pack_hash); if (report_end_of_input) write_in_full(2, "\0", 1); - resolve_deltas(); + resolve_deltas(&opts); conclude_pack(fix_thin_pack, curr_pack, pack_hash); free(ofs_deltas); free(ref_deltas); diff --git a/config.c b/config.c index a11bb85da3..728ef98e42 100644 --- a/config.c +++ b/config.c @@ -1515,11 +1515,6 @@ static int git_default_core_config(const char *var, const char *value, return 0; } - if (!strcmp(var, "core.deltabasecachelimit")) { - delta_base_cache_limit = git_config_ulong(var, value, ctx->kvi); - return 0; - } - if (!strcmp(var, "core.autocrlf")) { if (value && !strcasecmp(value, "input")) { auto_crlf = AUTO_CRLF_INPUT; diff --git a/environment.c b/environment.c index a2ce998081..8e5022c282 100644 --- a/environment.c +++ b/environment.c @@ -51,7 +51,6 @@ enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT; enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT; size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE; size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT; -size_t delta_base_cache_limit = 96 * 1024 * 1024; unsigned long big_file_threshold = 512 * 1024 * 1024; char *editor_program; char *askpass_program; diff --git a/environment.h b/environment.h index 923e12661e..2f43340f0b 100644 --- a/environment.h +++ b/environment.h @@ -165,7 +165,6 @@ extern int zlib_compression_level; extern int pack_compression_level; extern size_t packed_git_window_size; extern size_t packed_git_limit; -extern size_t delta_base_cache_limit; extern unsigned long big_file_threshold; extern unsigned long pack_size_limit_cfg; extern int max_allowed_tree_depth; diff --git a/pack-objects.h b/pack-objects.h index b9898a4e64..3f6f504203 100644 --- a/pack-objects.h +++ b/pack-objects.h @@ -7,7 +7,8 @@ struct repository; -#define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024) +#define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024) +#define DEFAULT_DELTA_BASE_CACHE_LIMIT (96 * 1024 * 1024) #define OE_DFS_STATE_BITS 2 #define OE_DEPTH_BITS 12 diff --git a/pack-write.c b/pack-write.c index 8c7dfddc5a..98a8c0e785 100644 --- a/pack-write.c +++ b/pack-write.c @@ -21,6 +21,7 @@ void reset_pack_idx_option(struct pack_idx_option *opts) memset(opts, 0, sizeof(*opts)); opts->version = 2; opts->off32_limit = 0x7fffffff; + opts->delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT; } static int sha1_compare(const void *_a, const void *_b) diff --git a/pack.h b/pack.h index 02bbdfb19c..1a33751565 100644 --- a/pack.h +++ b/pack.h @@ -58,6 +58,7 @@ struct pack_idx_option { */ int anomaly_alloc, anomaly_nr; uint32_t *anomaly; + unsigned long delta_base_cache_limit; }; void reset_pack_idx_option(struct pack_idx_option *); diff --git a/packfile.c b/packfile.c index 1415df38e9..c9812eedad 100644 --- a/packfile.c +++ b/packfile.c @@ -24,6 +24,8 @@ #include "commit-graph.h" #include "pack-revindex.h" #include "promisor-remote.h" +#include "config.h" +#include "pack-objects.h" char *odb_pack_name(struct repository *repo, struct strbuf *buf, const unsigned char *hash, const char *ext) @@ -1494,7 +1496,9 @@ void clear_delta_base_cache(void) } static void add_delta_base_cache(struct packed_git *p, off_t base_offset, - void *base, unsigned long base_size, enum object_type type) + void *base, unsigned long base_size, + unsigned long delta_base_cache_limit, + enum object_type type) { struct delta_base_cache_entry *ent; struct list_head *lru, *tmp; @@ -1697,6 +1701,9 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset, struct unpack_entry_stack_ent *delta_stack = small_delta_stack; int delta_stack_nr = 0, delta_stack_alloc = UNPACK_ENTRY_STACK_PREALLOC; int base_from_cache = 0; + unsigned long delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT; + + repo_config_get_ulong(r, "core.deltabasecachelimit", &delta_base_cache_limit); write_pack_access_log(p, obj_offset); @@ -1881,7 +1888,9 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset, * before we are done using it. */ if (!external_base) - add_delta_base_cache(p, base_obj_offset, base, base_size, type); + add_delta_base_cache(p, base_obj_offset, base, + base_size, delta_base_cache_limit, + type); free(delta_data); free(external_base); From patchwork Mon Oct 21 09:58:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13843806 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 E23F91E8831 for ; Mon, 21 Oct 2024 09:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504706; cv=none; b=Fjo5GTkhnHw4L8yeQJqbiXul+9JfFoEugpLdQ/qNg1Np2cTdGbyepAaz3HnhSaSPscXbI7Pjp3sCnSLV1pCUCTIX6gzpYbojRkmZ6G6gNeTFoQf/Tk1Qgycy+vFXtgC2Y7Y7BISGIL/gnDkDVy7Ps/2uMXZ+IOunxNdXUM15vKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729504706; c=relaxed/simple; bh=/d6c96uLPEUN3tCIZzWb7e3Q7FtmtE5khCSIs+p2aBg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XFMmm35mwxenNKZfOf4bwspHKPUErTB0mifzZPVTSflxMfSqkiUoxO18JPkHfzaMKgbapSIsNVIeGSrpP94cg/yuFTZoB6FTclHt1fOwrk5FW82JTQX/TEGrxEXtWmu12U/UvCW/oJl2JLw2hPh5q5txkdM6EnbKGIZa8FJmRrI= 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=K9gYlzpz; arc=none smtp.client-ip=209.85.208.172 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="K9gYlzpz" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2fb5fa911aaso61997351fa.2 for ; Mon, 21 Oct 2024 02:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729504702; x=1730109502; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k4WDPl6CsurkH6Vn6s4wnu0DhHOYgLmJROy8hJK2hVI=; b=K9gYlzpzut2icC3PdYL/wAx6VliFvO7U/eY9IdrfWjveKKzFjODZBLHVkmqovrZU12 3ff2n1Ojcxn9CBdawSTa8s2bq9dEsxb1grxVJnvzfGu1wwpkyOzGH8//YmjQaqQ9vU1C oxVTYBEp7wSV03DQ57sNL52720h8GuHH7yoNxCwjsyKgQXvsyIr7Odswbfiq2mM0coca 7VLO88U40C4Fsvmivw7fjmDDL1Eq0hh0n/89WhdRgD3ioUbmLLPuYEdO7wvDV6GrDNQA h6HusE48CZanov4pYwkJjjJhfaQRHBa/Pr+Q7OrjngzMz2vygmV6jnWLZQzegzU7WlAv 2s/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729504702; x=1730109502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k4WDPl6CsurkH6Vn6s4wnu0DhHOYgLmJROy8hJK2hVI=; b=YhoBKv2mPSGC+JvqDK73Pyk39G+kHMct5LyuZ+OVvdIbZ7VUn19e9ZKGZXuwkQOlbD y5MP3Op4Kt1E/S9LzBVL7lR0Cl7KICyvY52xhufdO+Dw5fw7F/Sn6Xg+kBbW68gHxAAe d1X00RRxZYm0lD/cJ9vvYMqf7qPyTsoU+NZhYt/CZO631AXZpH+IICNJR5rox/VhE+/j GsPvP2Yxz2es+eVR+yyIYiTGAIRNrfFZQiDFP8rzidIN6pfTEm8UQ+MMPwBRZEOExqj9 k6QqT4Deio2hhOKuAx+84NmpFtNBspPxo3rEnq1UbtetvnnrkMfhj3xqHRCowOzfZa9B B3VQ== X-Gm-Message-State: AOJu0YxU1xEBK21Shi/nkk8JISYggxOWPWN654plnMBIrUUkQUZAyRY3 NC5Q3ZB67GwAC3YN2k7oHi+uHPVZhqZBq/fXGtUsK6Sc2ysgvcQr+W6QuNC8 X-Google-Smtp-Source: AGHT+IFbBZHDirb61InXq8AB45F60lCheD2CiY0qPSSDAQwowTe4aog0cODXKtKhaHAhqC2WdIjarw== X-Received: by 2002:a2e:80a:0:b0:2fb:5ae7:24e7 with SMTP id 38308e7fff4ca-2fb82e90ee3mr59747571fa.4.1729504701582; Mon, 21 Oct 2024 02:58:21 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d631dsm187122266b.17.2024.10.21.02.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 02:58:21 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org Subject: [PATCH 20/20] config: make `packed_git_(limit|window_size)` non-global variables Date: Mon, 21 Oct 2024 11:58:03 +0200 Message-ID: <6a6600698be06e2cd6bccda6df8cba41ee3540a2.1729504641.git.karthik.188@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The variables `packed_git_window_size` and `packed_git_limit` are global config variables used in the `packfile.c` file. Since it is only used in this file, let's change it from being a global config variable to a local variable for the subsystem. We do this by introducing a new local `packfile_config` struct in `packfile.c` and also adding the required function to parse the said config. We then use this within `packfile.c` to obtain the variables. With this, we rid `packfile.c` from all global variable usage and this means we can also remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file. Signed-off-by: Karthik Nayak --- builtin/fast-import.c | 4 +-- config.c | 17 ------------- environment.c | 2 -- packfile.c | 59 +++++++++++++++++++++++++++++++++++++------ packfile.h | 2 +- 5 files changed, 54 insertions(+), 30 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index a6743db85c..e8c814a07e 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -3540,7 +3540,7 @@ static void parse_argv(void) int cmd_fast_import(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { unsigned int i; @@ -3661,7 +3661,7 @@ int cmd_fast_import(int argc, fprintf(stderr, " pools: %10lu KiB\n", (unsigned long)((tree_entry_allocd + fi_mem_pool.pool_alloc) /1024)); fprintf(stderr, " objects: %10" PRIuMAX " KiB\n", (alloc_count*sizeof(struct object_entry))/1024); fprintf(stderr, "---------------------------------------------------------------------\n"); - pack_report(); + pack_report(repo); fprintf(stderr, "---------------------------------------------------------------------\n"); fprintf(stderr, "\n"); } diff --git a/config.c b/config.c index 728ef98e42..2c295f7430 100644 --- a/config.c +++ b/config.c @@ -1493,28 +1493,11 @@ static int git_default_core_config(const char *var, const char *value, return 0; } - if (!strcmp(var, "core.packedgitwindowsize")) { - int pgsz_x2 = getpagesize() * 2; - packed_git_window_size = git_config_ulong(var, value, ctx->kvi); - - /* This value must be multiple of (pagesize * 2) */ - packed_git_window_size /= pgsz_x2; - if (packed_git_window_size < 1) - packed_git_window_size = 1; - packed_git_window_size *= pgsz_x2; - return 0; - } - if (!strcmp(var, "core.bigfilethreshold")) { big_file_threshold = git_config_ulong(var, value, ctx->kvi); return 0; } - if (!strcmp(var, "core.packedgitlimit")) { - packed_git_limit = git_config_ulong(var, value, ctx->kvi); - return 0; - } - if (!strcmp(var, "core.autocrlf")) { if (value && !strcasecmp(value, "input")) { auto_crlf = AUTO_CRLF_INPUT; diff --git a/environment.c b/environment.c index 8e5022c282..8389a27270 100644 --- a/environment.c +++ b/environment.c @@ -49,8 +49,6 @@ int fsync_object_files = -1; int use_fsync = -1; enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT; enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT; -size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE; -size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT; unsigned long big_file_threshold = 512 * 1024 * 1024; char *editor_program; char *askpass_program; diff --git a/packfile.c b/packfile.c index c9812eedad..00a39036c9 100644 --- a/packfile.c +++ b/packfile.c @@ -1,4 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE #include "git-compat-util.h" #include "environment.h" @@ -27,6 +26,17 @@ #include "config.h" #include "pack-objects.h" +struct packfile_config { + unsigned long packed_git_window_size; + unsigned long packed_git_limit; +}; + +#define PACKFILE_CONFIG_INIT \ +{ \ + .packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE, \ + .packed_git_limit = DEFAULT_PACKED_GIT_LIMIT, \ +} + char *odb_pack_name(struct repository *repo, struct strbuf *buf, const unsigned char *hash, const char *ext) { @@ -60,15 +70,44 @@ static size_t pack_mapped; #define SZ_FMT PRIuMAX static inline uintmax_t sz_fmt(size_t s) { return s; } -void pack_report(void) +static int packfile_config(const char *var, const char *value, + const struct config_context *ctx, void *cb) +{ + struct packfile_config *config = cb; + + if (!strcmp(var, "core.packedgitwindowsize")) { + int pgsz_x2 = getpagesize() * 2; + config->packed_git_window_size = git_config_ulong(var, value, ctx->kvi); + + /* This value must be multiple of (pagesize * 2) */ + config->packed_git_window_size /= pgsz_x2; + if (config->packed_git_window_size < 1) + config->packed_git_window_size = 1; + config->packed_git_window_size *= pgsz_x2; + return 0; + } + + if (!strcmp(var, "core.packedgitlimit")) { + config->packed_git_limit = git_config_ulong(var, value, ctx->kvi); + return 0; + } + + return git_default_config(var, value, ctx, cb); +} + + +void pack_report(struct repository *repo) { + struct packfile_config config = PACKFILE_CONFIG_INIT; + repo_config(repo, packfile_config, &config); + fprintf(stderr, "pack_report: getpagesize() = %10" SZ_FMT "\n" "pack_report: core.packedGitWindowSize = %10" SZ_FMT "\n" "pack_report: core.packedGitLimit = %10" SZ_FMT "\n", sz_fmt(getpagesize()), - sz_fmt(packed_git_window_size), - sz_fmt(packed_git_limit)); + sz_fmt(config.packed_git_window_size), + sz_fmt(config.packed_git_limit)); fprintf(stderr, "pack_report: pack_used_ctr = %10u\n" "pack_report: pack_mmap_calls = %10u\n" @@ -656,20 +695,24 @@ unsigned char *use_pack(struct repository *repo, struct packed_git *p, break; } if (!win) { - size_t window_align = packed_git_window_size / 2; + struct packfile_config config = PACKFILE_CONFIG_INIT; + size_t window_align; off_t len; + repo_config(repo, packfile_config, &config); + window_align = config.packed_git_window_size / 2; + if (p->pack_fd == -1 && open_packed_git(repo, p)) die("packfile %s cannot be accessed", p->pack_name); CALLOC_ARRAY(win, 1); win->offset = (offset / window_align) * window_align; len = p->pack_size - win->offset; - if (len > packed_git_window_size) - len = packed_git_window_size; + if (len > config.packed_git_window_size) + len = config.packed_git_window_size; win->len = (size_t)len; pack_mapped += win->len; - while (packed_git_limit < pack_mapped + while (config.packed_git_limit < pack_mapped && unuse_one_window(repo, p)) ; /* nothing */ win->base = xmmap_gently(NULL, win->len, diff --git a/packfile.h b/packfile.h index 9184560f0e..1894d7db93 100644 --- a/packfile.h +++ b/packfile.h @@ -91,7 +91,7 @@ struct packed_git *find_sha1_pack(struct repository *repo, const unsigned char *sha1, struct packed_git *packs); -void pack_report(void); +void pack_report(struct repository *repo); /* * mmap the index file for the specified packfile (if it is not