From patchwork Mon Oct 28 13:43:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13853480 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 1B61B1DD539 for ; Mon, 28 Oct 2024 13:43:51 +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=1730123034; cv=none; b=Eg0uYCMrbEL1FxerANrzC9cOm2DAGMEUco0BRm5DYtisPLPFHKUj+/07AhJ3LLgpKEi9qCluJlYpZJvId74PHcP8Bgq2cOTfw3JGUPrjzKTSMQ6no2aWM9CDueFCWbQVsc+gJ1xmzwqBIpoNFQqj8/4jLIqso9ydOiF6mvlr9SU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730123034; c=relaxed/simple; bh=z19Oq4pnZz7ppxOBH38zLkvw77SaE17qbsAQu1uI+5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qTSQXUtuWWjmHs3xuCRixr72LDI39JIG8CPcY2Ny16xn9bm0L7SsDN+3lvIDCpDS85qehoqCuqkWNbjpbDq0pxbXB4Ryk3GEbzMI+IzR+pX4Ty9pzlcOz24C3TbUcGvE/wo2RJ0TlbMEn4f9z/J/lht7dDdQ0f4RD028pWSlJQw= 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=gn597m42; 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="gn597m42" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a9a3dc089d8so642337766b.3 for ; Mon, 28 Oct 2024 06:43:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730123030; x=1730727830; 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=pAuvSPeqFzuf7N0J+GgrXDDctr3GZBniB+C01KKKdUI=; b=gn597m4224YwcM527/7ER12oahKcNgpPISlt5owJez4aB/2vuRxHxbwku5k0A5AttF 0YWV9hWIUbgle+LEpqlmfV8+y8R6zvt/ilcHAlLZ33Hjv7D007ufNLgdtrF7soWlVold viqiWHNeee3bBbz+m5a73ufNRkDJVJdrJp7uLyOgI8GnKGKWQI+aUY0yrbPNU9/Q0ahb 048K2Zo5UDfCclVPqEnuG40LWIqaOPif0lxWFmxfEYONYwdktqfV0tVA94boEQGYfF8L 71C2FgYoEaINbTCTOtuBEmz1GxK3RYAoDvx2qMz/fCAElEhCT3QrvQ/fOKSlvQ6nnhsZ Hebg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730123030; x=1730727830; 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=pAuvSPeqFzuf7N0J+GgrXDDctr3GZBniB+C01KKKdUI=; b=dtohpzDQXbE5dT/qgyidHHn39IcZz1oaOKpkfVqRnshVtxriZlJ2mr0tnWJ7e2RXo3 6B19584pBHlxkPSWy5r34VO6Awkjlf5pzcp/gkjGwkIrYwG56KUhGSIF+E50Yz6X3aSs N7+mH8QwhmxjocF8951pP355fKmiXk8u9e4u2EfM0kbuHuCg03SP6eUkz9QbDkmdrKGG 8DbcFdwN46qfTXoUc/WVhiEO/wzBxIbVPrwm7rkET16TrHl3bfv46SVlcZNJBj0Fb1R6 5DL2tNXWh3sSupcF9LUUuShqvN27UjfJ1BDHss3YyMVJO9wNZkmg4AQg43QPKWl5LPpJ M9lA== X-Gm-Message-State: AOJu0Ywmy7sA9qDqmshLksYobxa1zVQhXgVZpfpUlQZMTzYuEYPPqml9 RmY2rSf2cMmA266qrWMET2n/aa7F02BaUiwQDZ78RjqMYtfVermf X-Google-Smtp-Source: AGHT+IF/mJ13dNVDm7lYLagy+00KxThs9ay03kuUi2IE+cP0O4GTCD4PO2ejYPz7wTBt3EfrvFK5qQ== X-Received: by 2002:a17:907:980e:b0:a9a:a5a:1d47 with SMTP id a640c23a62f3a-a9de5cfc5e3mr684653266b.2.1730123029882; Mon, 28 Oct 2024 06:43:49 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f2971e8sm376647466b.125.2024.10.28.06.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 06:43:49 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, me@ttaylorr.com Subject: [PATCH v2 1/8] packfile: add repository to struct `packed_git` Date: Mon, 28 Oct 2024 14:43:39 +0100 Message-ID: <26d2461cc349c14b05d2713ee411bb058251f45f.1730122499.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 struct `packed_git` holds information regarding a packed object file. Let's add the repository variable to this object, to represent the repository that this packfile belongs to. This helps remove dependency on the global `the_repository` object in `packfile.c` by simply using repository information now readily available in the struct. We also modify `alloc_packed_git` to ensure that the repository is added to newly created `packed_git` structs. This requires modifying the function and all its callee to pass the repository object down the levels. Signed-off-by: Karthik Nayak --- builtin/fast-import.c | 3 ++- builtin/index-pack.c | 6 ++++-- commit-graph.c | 2 +- connected.c | 3 ++- http.c | 2 +- midx-write.c | 2 +- midx.c | 2 +- object-store-ll.h | 5 +++++ packfile.c | 15 +++++++++------ packfile.h | 6 ++++-- 10 files changed, 30 insertions(+), 16 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 76d5c20f14..ffee7d3abd 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -765,6 +765,7 @@ static void start_packfile(void) p->pack_fd = pack_fd; p->do_not_close = 1; + p->repo = the_repository; pack_file = hashfd(pack_fd, p->pack_name); pack_data = p; @@ -888,7 +889,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 9d23b41b3a..be2f99625e 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/commit-graph.c b/commit-graph.c index 5bd89c0acd..83dd69bfeb 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(ctx->r, 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 a9e2e13995..3099da84f3 100644 --- a/connected.c +++ b/connected.c @@ -54,7 +54,8 @@ 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/http.c b/http.c index 510332ab04..7e5be05207 100644 --- a/http.c +++ b/http.c @@ -2437,7 +2437,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); 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 e82d4f2e65..8edb75f51d 100644 --- a/midx.c +++ b/midx.c @@ -464,7 +464,7 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, strhash(key.buf), key.buf, struct packed_git, packmap_ent); if (!p) { - 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); if (p) { install_packed_git(r, p); list_add_tail(&p->mru, &r->objects->packed_git_mru); diff --git a/object-store-ll.h b/object-store-ll.h index 53b8e693b1..8b31072b09 100644 --- a/object-store-ll.h +++ b/object-store-ll.h @@ -4,6 +4,7 @@ #include "hashmap.h" #include "object.h" #include "list.h" +#include "repository.h" #include "thread-utils.h" #include "oidset.h" @@ -135,6 +136,10 @@ struct packed_git { */ const uint32_t *mtimes_map; size_t mtimes_size; + + /* repo dentoes the repository this packed file belongs to */ + struct repository *repo; + /* something like ".git/objects/pack/xxxxx.pack" */ char pack_name[FLEX_ARRAY]; /* more */ }; diff --git a/packfile.c b/packfile.c index 9560f0a33c..45f300e5e1 100644 --- a/packfile.c +++ b/packfile.c @@ -217,11 +217,12 @@ uint32_t get_pack_fanout(struct packed_git *p, uint32_t value) return ntohl(level1_ofs[value]); } -static struct packed_git *alloc_packed_git(int extra) +static struct packed_git *alloc_packed_git(struct repository *repo, int extra) { struct packed_git *p = xmalloc(st_add(sizeof(*p), extra)); memset(p, 0, sizeof(*p)); p->pack_fd = -1; + p->repo = repo; return p; } @@ -233,11 +234,12 @@ static char *pack_path_from_idx(const char *idx_path) return xstrfmt("%.*s.pack", (int)len, idx_path); } -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) { char *path = pack_path_from_idx(idx_path); size_t alloc = st_add(strlen(path), 1); - struct packed_git *p = alloc_packed_git(alloc); + struct packed_git *p = alloc_packed_git(repo, alloc); memcpy(p->pack_name, path, alloc); /* includes NUL */ free(path); @@ -703,7 +705,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; @@ -721,7 +724,7 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local) * the use xsnprintf double-checks that) */ alloc = st_add3(path_len, strlen(".promisor"), 1); - p = alloc_packed_git(alloc); + p = alloc_packed_git(repo, alloc); memcpy(p->pack_name, path, path_len); xsnprintf(p->pack_name + path_len, alloc - path_len, ".keep"); @@ -877,7 +880,7 @@ 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); } diff --git a/packfile.h b/packfile.h index 08f88a7ff5..344da905c2 100644 --- a/packfile.h +++ b/packfile.h @@ -46,7 +46,8 @@ const char *pack_basename(struct packed_git *p); * and does not add the resulting packed_git struct to the internal list of * packs. You probably want add_packed_git() instead. */ -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); @@ -113,7 +114,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. From patchwork Mon Oct 28 13:43:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13853482 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.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 6CC4D1DD523 for ; Mon, 28 Oct 2024 13:43:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730123037; cv=none; b=I6cTELwUHTLT1EoK1ux+4I2L7IqOoAgwmwY4QY7KfgqqfDKo44sTQNwRKcKCA9cObPUA6uAkxE6SUkw66CybqMIKGRj6Xbo4zoEmMVPETlLWX+HQT7hfKZu8LoaM25YpA1kGfH6JKX3UqptKcx4ITK/Al/FIoDX0NK9dPSnW4Mk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730123037; c=relaxed/simple; bh=z5U0h0hktph+85m2EmVTfi6eZUOEIkP22Gmf7YLac+4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dmnZQRMIgIXD3arr4P4w6lYJ43kaj2xSqg6l/fKroZ4zNGa+FXal573jzZSIUc/vWiPdKp/8IXTPIVw/tJzk/SAwjJbAmDRj7tMWf8GWmeKFW6EhO6KA6Z0X3nWXZhQ1cwOWh8jJm0X0V1hDB0QSwszX6q85wv7FcnIwM5ECJ7Y= 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=hw+bZ2Y2; arc=none smtp.client-ip=209.85.208.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="hw+bZ2Y2" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5c9634c9160so4962139a12.2 for ; Mon, 28 Oct 2024 06:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730123032; x=1730727832; 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=Q+L5Kslsvu7vn5D7pHhGoHpIglr21MfLUAGZjgHDEXg=; b=hw+bZ2Y2eP3KjfruawvHsoi52FFthT7t0DNZue20cAC9vktZiBIKhQQR8DHw/sdi8g PltqFOC/xUz3JDxOXt5fXFq4zVjeSlqXBPuS7cTgFa7c+preECgjy82yOfK7jkeamkOx Yy/tUHmnvpX+d+Ss23d5+zmILDa7iuIdMsM5sxYjq40ulxcSw0182YROYWSTzvXm+RZO hjm0p4c5yzSgXAnrgAQEc9XdVYehlApiM/VbhbTqb+w4sPzlqJgnXj9rwjGuf8aZvpls NQq/5pTJHfnUzP1PnanaELYj1206gpucV4bwuifedy4OPEl+L63jTZeDG79KymwGCuEL jWCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730123032; x=1730727832; 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=Q+L5Kslsvu7vn5D7pHhGoHpIglr21MfLUAGZjgHDEXg=; b=Wh+kfs4bpprgY7aczie6VHx5va2mjzH8onSRjy8ivsrTE+3PKTnUdGTSKQPy/Wf/I1 KU4eiv4siiXmEUe7b2231CJVa2/twBuoPQjVgVztTCSqS43gU+O32apjKVwx1ezWMKX8 yYBz8SBbzqjOltwjTABvE4Mg+z7tUUJNHejGA/XPfTsPxDPYYsbU9UuJIrOsQGzuWgR5 5Ik8PuVCnbPE+gGgh0eBz+gkHIU4OTXtSx40F8Oogut9QZwILzgJQQTtxUbt50lNhtr5 jYEC6NE95oI6NuBKzjvfd3HCAQkXauJkrvsrSO5D6lymxKasOY3mR3YuagP56HvfPVfu b/8Q== X-Gm-Message-State: AOJu0YycdCffWjkiM9xe+34tebdMnHyvKRG6JcHqXOnfQKAushDqj84n K+bNZq0netCxohpF46uFYn8YkV9rlagNm6zEiLzPigMP8OVWW1cC X-Google-Smtp-Source: AGHT+IG7vh9OUvPZAC7fKCo3GqtsLqRENpJmQiaOUjUESb4cCriZ3ZB/MN4RK37GExg7v2OQOKMI/A== X-Received: by 2002:a17:906:c153:b0:a99:e600:7e06 with SMTP id a640c23a62f3a-a9de61ced14mr797218466b.51.1730123031405; Mon, 28 Oct 2024 06:43:51 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f2971e8sm376647466b.125.2024.10.28.06.43.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 06:43:50 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, me@ttaylorr.com Subject: [PATCH v2 2/8] packfile: use `repository` from `packed_git` directly Date: Mon, 28 Oct 2024 14:43:40 +0100 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 In the previous commit, we introduced the `repository` structure inside `packed_git`. This provides an alternative route instead of using the global `the_repository` variable. Let's modify `packfile.c` now to use this field wherever possible instead of relying on the global state. There are still a few instances of `the_repository` usage in the file, where there is no struct `packed_git` locally available, which will be fixed in the following commits. Signed-off-by: Karthik Nayak --- packfile.c | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/packfile.c b/packfile.c index 45f300e5e1..9b353db331 100644 --- a/packfile.c +++ b/packfile.c @@ -79,7 +79,7 @@ static int check_packed_git_idx(const char *path, struct packed_git *p) 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 = p->repo->hash_algo->rawsz; if (fd < 0) return -1; @@ -243,7 +243,7 @@ struct packed_git *parse_pack_index(struct repository *repo, memcpy(p->pack_name, path, alloc); /* includes NUL */ free(path); - hashcpy(p->hash, sha1, the_repository->hash_algo); + hashcpy(p->hash, sha1, p->repo->hash_algo); if (check_packed_git_idx(idx_path, p)) { free(p); return NULL; @@ -278,7 +278,7 @@ static int unuse_one_window(struct packed_git *current) if (current) scan_windows(current, &lru_p, &lru_w, &lru_l); - for (p = the_repository->objects->packed_git; p; p = p->next) + for (p = current->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); @@ -540,7 +540,7 @@ static int open_packed_git_1(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 = p->repo->hash_algo->rawsz; if (open_pack_index(p)) return error("packfile %s index unavailable", p->pack_name); @@ -597,7 +597,7 @@ 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, p->repo->hash_algo)) return error("packfile %s does not match index", p->pack_name); return 0; } @@ -637,7 +637,7 @@ unsigned char *use_pack(struct packed_git *p, */ if (!p->pack_size && p->pack_fd == -1 && open_packed_git(p)) die("packfile %s cannot be accessed", p->pack_name); - if (offset > (p->pack_size - the_hash_algo->rawsz)) + if (offset > (p->pack_size - p->repo->hash_algo->rawsz)) die("offset beyond end of packfile (truncated pack?)"); if (offset < 0) die(_("offset before end of packfile (broken .idx?)")); @@ -711,6 +711,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 @@ -751,9 +752,13 @@ struct packed_git *add_packed_git(struct repository *repo, const char *path, 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_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; } @@ -1243,9 +1248,9 @@ off_t get_delta_base(struct packed_git *p, } else if (type == OBJ_REF_DELTA) { /* The base entry _must_ be in the same pack */ struct object_id oid; - oidread(&oid, base_info, the_repository->hash_algo); + oidread(&oid, base_info, p->repo->hash_algo); base_offset = find_pack_entry_one(&oid, p); - *curpos += the_hash_algo->rawsz; + *curpos += p->repo->hash_algo->rawsz; } else die("I am totally screwed"); return base_offset; @@ -1266,7 +1271,7 @@ static int get_delta_base_oid(struct packed_git *p, { if (type == OBJ_REF_DELTA) { unsigned char *base = use_pack(p, w_curs, curpos, NULL); - oidread(oid, base, the_repository->hash_algo); + oidread(oid, base, p->repo->hash_algo); return 0; } else if (type == OBJ_OFS_DELTA) { uint32_t base_pos; @@ -1608,7 +1613,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, p->repo->hash_algo); } oi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED : @@ -1897,7 +1902,7 @@ int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32 { 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 = p->repo->hash_algo->rawsz; int index_lookup_width; if (!index_fanout) @@ -1922,7 +1927,7 @@ int nth_packed_object_id(struct object_id *oid, uint32_t n) { const unsigned char *index = p->index_data; - const unsigned int hashsz = the_hash_algo->rawsz; + const unsigned int hashsz = p->repo->hash_algo->rawsz; if (!index) { if (open_pack_index(p)) return -1; @@ -1933,11 +1938,10 @@ 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); + p->repo->hash_algo); } else { index += 8; - oidread(oid, index + st_mult(hashsz, n), - the_repository->hash_algo); + oidread(oid, index + st_mult(hashsz, n), p->repo->hash_algo); } return 0; } @@ -1959,7 +1963,7 @@ void check_pack_index_ptr(const struct packed_git *p, const void *vptr) off_t nth_packed_object_offset(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 = p->repo->hash_algo->rawsz; index += 4 * 256; if (p->index_version == 1) { return ntohl(*((uint32_t *)(index + st_mult(hashsz + 4, n)))); @@ -2159,7 +2163,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(p->repo, p)) return -1; } @@ -2227,7 +2231,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, } static int add_promisor_object(const struct object_id *oid, - struct packed_git *pack UNUSED, + struct packed_git *pack, uint32_t pos UNUSED, void *set_) { @@ -2235,12 +2239,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(pack->repo, oid); if (obj && obj->parsed) { we_parsed_object = 0; } else { we_parsed_object = 1; - obj = parse_object(the_repository, oid); + obj = parse_object(pack->repo, oid); } if (!obj) From patchwork Mon Oct 28 13:43:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13853481 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.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 753D91DDC19 for ; Mon, 28 Oct 2024 13:43:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730123036; cv=none; b=ZTowrXZk+Qq8NA4MZ9CjGlcpkeBNGgk9G7aCu52FTWOOLW7Sf8bMs3TPdOMBLSzsG7ZCzttT2qs8T6wIiiuyEs87gqCrToFrmz/XkNl+0f4cv7NvhDmqoi62ANTJQ/caybjOk3rLBnqvnukV9JTxo+DTIUu3Bz8S/Juz6ZFyvBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730123036; c=relaxed/simple; bh=0G5luLv3bh0IMXQILYSNwCvRzAdZi2qi/ZjIXvHHdwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mpBHkWns7NA4x+APl9xbTp0BbzYfw16CIuYR3yydWwSbW3JaZqHXcva0YDR/XECnNK+SBgIV6SaJGv+sPgMmk8lBoMM8+GQpgn1/mBfNqYG65egWpgNLjmVHUD2rpdFWEvDeyFHbQGiF0ua8QPOZisi1/la0SWKDkpd97NtvavE= 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=Nmn1zA6E; arc=none smtp.client-ip=209.85.167.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="Nmn1zA6E" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-539fb49c64aso7112509e87.0 for ; Mon, 28 Oct 2024 06:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730123033; x=1730727833; 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=W25BJHhYpzR0se69lc4edDADkzL8AzcOYDQHN+H7t0w=; b=Nmn1zA6E2WJEuDJkysJ+tIEP0gMsMs3RkK7OAMVuD/0cv/eKkKpAtRLNEHOf/nzKra VrBcDPWxcHaJoL55+UPsUOHQz9AvRnaidOVpR9f7RDHaL/vFwlUoUc6cWpTcEn8xGHyt Gfw9P7dh7VIkow54PppfFvV/wjmPutPa4B9rucWINygS3SwoiZnRzesyXasaAXGd6dQN C6qwxJfq2y+H3TlLjrwAWeFOmJQEajXP6fIJP4L7Dtcg2GgYbmbtMz/wIFZLk3sUVJpx 0IAIPm8WWcJLtJR2gZ3Vp88T4BgWqoW4iWJkXRMF/Psh8/87NZ5QKuaXMOs9W3zd8Xlo 6lzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730123033; x=1730727833; 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=W25BJHhYpzR0se69lc4edDADkzL8AzcOYDQHN+H7t0w=; b=vISv6uOLzJxTFlnV97Q8RVa0/rD+4VmF4R2b8NGztnFPxzpMAplw2bnDCV2/J1yKdV BZdgK4DgIE7+r9pMM45qjqc2W95YGVhyN75z3sALkikzD0Pay0qX+Kimf4zy4WPkOULR WhlN1OZE0+KgxDOXNht36kr22h0CecUdtdClSThMcYVgvIiViQqt0dY1YyLk7UVjF1mv EtLPO9TfeqoLQYw0mYU9K7tm5jXggJJZMqQ5vSsQ+EoXQcoeFpmNA8dVCjldIZa3Xddv XBCxqtKUl4yuNvlqSVPxI0TO4zJUFXCYdHDUT5eFeyMyP0dqfp1BiP9Qp8knZw/iqIwa u7Zg== X-Gm-Message-State: AOJu0YzAnSwzo6Q3N2jBgPPY3T2QlNgqYQvZUx/zHyrpsehp0wz8Drt2 FmhRxwhE97O/sSS2ncOvIPUwzkXUAoV2Dq9FCd1x37E5J5Gi0MQh9u9inCM9 X-Google-Smtp-Source: AGHT+IGFrSFu72ZhR4irWBUqhxj9k9hCkqhtFBvGrjvGOgkI0Na3Zcgk39Z2gxRGwZ6BpMAWdQJtIA== X-Received: by 2002:a05:6512:6c5:b0:533:4785:82ab with SMTP id 2adb3069b0e04-53b348ba0e0mr5345483e87.1.1730123032471; Mon, 28 Oct 2024 06:43:52 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f2971e8sm376647466b.125.2024.10.28.06.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 06:43:51 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, me@ttaylorr.com Subject: [PATCH v2 3/8] packfile: pass `repository` to static function in the file Date: Mon, 28 Oct 2024 14:43:41 +0100 Message-ID: <1f8ef580e5a62ac145501c124407f9bf399b5da2.1730122499.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 Some of the static functions in the `packfile.c` access global variables, which can simply be avoiding by passing the `repository` struct down to them. Let's do that. Signed-off-by: Karthik Nayak --- packfile.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packfile.c b/packfile.c index 9b353db331..cc558f06cc 100644 --- a/packfile.c +++ b/packfile.c @@ -460,13 +460,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); @@ -555,7 +555,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(p->repo)) ; /* nothing */ p->pack_fd = git_open(p->pack_name); @@ -610,7 +610,8 @@ static int open_packed_git(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 @@ -620,7 +621,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 packed_git *p, @@ -642,11 +643,11 @@ unsigned char *use_pack(struct packed_git *p, if (offset < 0) die(_("offset before end of packfile (broken .idx?)")); - if (!win || !in_window(win, offset)) { + if (!win || !in_window(p->repo, win, offset)) { if (win) win->inuse_cnt--; for (win = p->windows; win; win = win->next) { - if (in_window(win, offset)) + if (in_window(p->repo, win, offset)) break; } if (!win) { From patchwork Mon Oct 28 13:43:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13853484 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 089731DDC30 for ; Mon, 28 Oct 2024 13:43:56 +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=1730123039; cv=none; b=UVnczJTBrY9iwuHrIMicYL4W0Yxinz2717R84sIfjC3R9vlXoTVMDkW3kDGxLGP0IhLeBRL2j1A9ooNo+KAaLWEKwBNe+1LaVcQSy0804FreC7OZ47A+dumvObZG41Um/VpTcuvoCoW40s1XBFLitSskcVFCiBoacNCb61YITd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730123039; c=relaxed/simple; bh=YG8mlZ8SDnpplVSwdTcNtTMTQ7yEw2D/xuA540AaOFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gV1wHGfczxT5U4FbNklihVICPu3sBh+K0iBbr6//r1tYWYhjFYAnkH/d8lZTRXcYdx62YhFRSBhUgaaXfllHHpjHXmlV4elwd+gxxAzjughJEXlZ78l6sQbO4JkcTSwoHjgqtHvNrtPv+OdphpbWzzQ0kFzsYRB6RaNDEi8CzCI= 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=NBFiq6xj; 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="NBFiq6xj" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a9a6b4ca29bso534595266b.3 for ; Mon, 28 Oct 2024 06:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730123035; x=1730727835; 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=rRLWMCvziaP1oOWGmB649amlajM49uqxp22hhOUUrJc=; b=NBFiq6xjCTtvXtGC71HhaQ3DcpeiVOh6rKhVq/5Oi4biJ1TzsFG6S64Hu11PVdXZ5F nfBilubAPtsBqM3RQ8VD/48qFY52j4E3a/z6t4Zd0SsjcOVQ+ZatV9o2xLl+7HvD/HKj uBT1hdVtKJHUYF3DMJeFfy7bID7KgpW4ROVWL2Hbtd1BfFHdHEWGXXQHJE5dD4+nDAjx 9lCw9tfDK5jXRa6fvXOmlXXNbjStKnIkZoHaiSjzUcvITuM0XowlAZs/hWHsbpCYRmAg 0ADtqKO/5efSdAZAApZ72PuuUvvgdRG3s0sAG1n4C0x8CK1HDwSVLN6UMuHNQtdcwVwi KixA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730123035; x=1730727835; 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=rRLWMCvziaP1oOWGmB649amlajM49uqxp22hhOUUrJc=; b=HR7NzgNCwnDBu5b8HUtiUVKelVl36Nkyg99BaYUezdaBIT3iRDHTIrpvqjWUaFfqxm UYgjpbtnhAaBnAQoEpweijxCO9lYwqWiM9XOFKjVq9Z3R5jl+ii+f/igABkPyEXTx/wp SnkJAKUrV9KacJW3bxCFdc834Gw2F25NBG/IPDQwnb6IVxFSOb6Uhy5Lz1sGfu4RIovd t3tXFQiczsrbzrBMo8EndTn7GdMxr9QPnx4QL3TaywDFSSU0Em7Fs0ouRD13q8HpbfRR yeU9vGRcOvIHq5mYHDDl6jSRAYR4NEBMyzLNnHWYVtTEMf1OWNGBzUObuLEDqCoXpcZP ydGw== X-Gm-Message-State: AOJu0YxC8iWrr+ar5lLXhK+dBv3gbooAFESbY91HMlmplZNp06dMYQvC YDeSPK0kfSenoKcSveMP0nI2PEQzStLVqAm9glaWky9g6gorSyaS X-Google-Smtp-Source: AGHT+IGI4KDGqApdNFWppXA91HG9zBjjr6bonqCYZjwuoJo1lGedflz5idy/YyIGS35BwrvpMa3LkA== X-Received: by 2002:a17:907:ea4:b0:a9a:123d:3f1a with SMTP id a640c23a62f3a-a9de5ce2676mr891277866b.17.1730123033604; Mon, 28 Oct 2024 06:43:53 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f2971e8sm376647466b.125.2024.10.28.06.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 06:43:53 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, me@ttaylorr.com Subject: [PATCH v2 4/8] packfile: pass down repository to `odb_pack_name` Date: Mon, 28 Oct 2024 14:43:42 +0100 Message-ID: <73ba9945a7b7ec69e4ea29116c473b88e5c2a916.1730122499.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 `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. Signed-off-by: Karthik Nayak --- builtin/fast-import.c | 8 ++++---- builtin/index-pack.c | 4 ++-- builtin/pack-redundant.c | 4 ++-- http.c | 2 +- packfile.c | 9 ++++----- packfile.h | 3 ++- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index ffee7d3abd..f4892d7f37 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -806,7 +806,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"); @@ -814,11 +814,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); @@ -832,7 +832,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(p->repo, &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 be2f99625e..eaefb41761 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 d2c1c4e5ec..7d6c47ffd9 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -589,7 +589,7 @@ static void load_all(void) } } -int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) { +int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo) { int i; int i_still_use_this = 0; struct pack_list *min = NULL, *red, *pl; struct llist *ignore; struct strbuf idx_name = STRBUF_INIT; @@ -690,7 +690,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", - odb_pack_name(&idx_name, pl->pack->hash, "idx"), + odb_pack_name(repo, &idx_name, pl->pack->hash, "idx"), pl->pack->pack_name); pl = pl->next; } diff --git a/http.c b/http.c index 7e5be05207..50d8811cea 100644 --- a/http.c +++ b/http.c @@ -2579,7 +2579,7 @@ struct http_pack_request *new_direct_http_pack_request( preq->url = url; - odb_pack_name(&preq->tmpfile, packed_git_hash, "pack"); + odb_pack_name(the_repository, &preq->tmpfile, packed_git_hash, "pack"); strbuf_addstr(&preq->tmpfile, ".temp"); preq->packfile = fopen(preq->tmpfile.buf, "a"); if (!preq->packfile) { diff --git a/packfile.c b/packfile.c index cc558f06cc..096a0cd6ba 100644 --- a/packfile.c +++ b/packfile.c @@ -25,13 +25,12 @@ #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), - hash_to_hex(hash), ext); + strbuf_addf(buf, "%s/pack/pack-%s.%s", repo_get_object_directory(repo), + hash_to_hex_algop(hash, repo->hash_algo), ext); return buf->buf; } diff --git a/packfile.h b/packfile.h index 344da905c2..48d058699d 100644 --- a/packfile.h +++ b/packfile.h @@ -29,7 +29,8 @@ 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 *hash, const char *ext); /* * Return the basename of the packfile, omitting any containing directory From patchwork Mon Oct 28 13:43:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13853483 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 416F01DDC2B for ; Mon, 28 Oct 2024 13:43:56 +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=1730123038; cv=none; b=u2vnMevZ4GRCRfGbiNAfaDUDApNjnHWq3au3GOwXJn0ybpPQPuP4LYa7b1yenoW4iIHd30k9gvatrEz7GD8BqlkJfjr6J+VVxSpGLe9D/CjpZI00SZ8GPkxVJmCKfkG8C1BIG9LEDe+4OFIoKvWULudkcIJ6eFP9KUea+xaFSaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730123038; c=relaxed/simple; bh=HlVJca9WRHbA2LVAnVjlYDcwGIZ4bNtQvlJu22s6nRA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tkzXRuW6hkQU+1z8nwkgnJvTV4cY+XSXa1fmk4IaGvXPcGD114bPfKofiXT8EeLaqRxGDPTu1RFQSjs68AOtrD8mzb+4NIjef4aW9nxf9NAQJTQnDmdvrejgNHrmVsqjK7CN+9fzgAF4VoVwcRDVAREhwhZEBjfSzOdGCD8qero= 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=ivcGyw/5; 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="ivcGyw/5" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a9a628b68a7so669134666b.2 for ; Mon, 28 Oct 2024 06:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730123035; x=1730727835; 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=IHw+lGEDKSRuPBQLADGRH3+m8bVFjyRU1u2tu08Zju4=; b=ivcGyw/5XyA7oDz+8JYwTJqsl+sEH5yj+Yyte3P5a7Uwzi3pPcuTFBnxHiaa97+xQR 4cN6WADqTKGCxl/Q3qEcVG79lX2hbRN9G91sOuyxCjDU7hTraX8ES1Bbd4/3Qof1beQO uGko2ODbVY9linnlIhVhpcKKVuKVL8N2sVv6tWkeZ2wjhNT+jqxuEE3UTlGi7pnEc8US /zV/tPhEPHalU+BeShn3ZrrRswoV1Y5r0FDUEpnWmJriDAnRnfR+JwOFX+oPwkO5/1Sh qvXXGGteetou5eul4dBWTsdG5Vl9eyaxn+cYkhQfiuidx7sQgPtmKguh8fUkLpJ7gXPb m35A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730123035; x=1730727835; 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=IHw+lGEDKSRuPBQLADGRH3+m8bVFjyRU1u2tu08Zju4=; b=H/hoLb+GU3DjJM19etP0L11ntavJQap6PUixkgXxBHmeqq+DO7NuE6ZPxGTULPINwr +/p/HFnXkp5WAVRp5RtFp/Y97yVRrF5FECuz65enT/338Si/ek5y/9cDDGSYXWQv3L6i xxd/0AXkXFiU/OJ/RVSkMTdwLc94I9Wsn0s4Dc+QTt2YkbOH2mPqJRO+dRWeebsnm9g2 Bd+akd3H4jAOtI0K3atPm2S3JfuB7RbrBM7e3PGZRwC3wTYZw+Qq4y2AxPLV/hHzTn3C Kg6f8Ul+1XTgxnhS8qG8f1Tq6UpwYx2NJG+kNWQFrwlD52J8vqwddZpl0AJd9g7wI0iH aGJw== X-Gm-Message-State: AOJu0YzqSmu5ewspQVIWRHskZu9jtxvCvZoNrPuMDlYrahb/iyDkNB9j IsjffTjVwfpKuGYuDqMh+lbb4Qm0DqrmNIY8/WUgS3NVZrYECVXK X-Google-Smtp-Source: AGHT+IEWLX1OlIfGHAmnXDG4m07/xyK0GG50cH+sVIaVnhcHIn0UrmNlYZtU8TRsiXP5afqjbzUdjg== X-Received: by 2002:a17:907:3f04:b0:a9a:11f5:8cd9 with SMTP id a640c23a62f3a-a9de61ea9f8mr804132866b.56.1730123034412; Mon, 28 Oct 2024 06:43:54 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f2971e8sm376647466b.125.2024.10.28.06.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 06:43:54 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, me@ttaylorr.com Subject: [PATCH v2 5/8] packfile: pass down repository to `has_object[_kept]_pack` Date: Mon, 28 Oct 2024 14:43:43 +0100 Message-ID: <4e883a4d1ccabb35cc6d122f23a475fca0d71ce1.1730122499.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 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 0800714267..2b2816c243 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1529,7 +1529,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; } @@ -3627,7 +3627,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 4fa9dfc771..d34ba9909a 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -1889,7 +1889,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 096a0cd6ba..c6d7ed38f6 100644 --- a/packfile.c +++ b/packfile.c @@ -2143,16 +2143,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 for_each_object_in_pack(struct packed_git *p, diff --git a/packfile.h b/packfile.h index 48d058699d..ac4f2210c5 100644 --- a/packfile.h +++ b/packfile.h @@ -193,8 +193,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); /* * Return 1 if an object in a promisor packfile is or refers to the given 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 28 13:43: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: 13853485 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 4AFB11DC19D for ; Mon, 28 Oct 2024 13:43:57 +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=1730123040; cv=none; b=EDweoR/8Qo/ePcW50XKVt/mOEjVoKI6Yz4K5tHoHz19utAKK/CUirXBgjYmYeam7KVFTzHsa3cgmMsJXg+FlwLHrMte51dNnMr1nUqAl6HuyGwTC8SZDBIbEWhWvik0dCqXiVIlyGiw4Qvh4TTgvWTxPfSbqb5FapKp7wf9ZuVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730123040; c=relaxed/simple; bh=29NktVRS7BDcJvAIZiQdLl+YUZxlxmUswIrWlokgpEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Va6tyQIeqdcmQc0wBfKvzZY74uEIUJN3IKccF8cRVAepkIjePl+g3t5b3iOKCdMInhiu3SCFYGuRTEsKc2C7+8P8Yzl1cEe5bBhDwZNsUCAbzGmeh8W0lPGu0rQ66h2fNd2pwG53HPL4b4ToyiHBut8dhizOAmMyM7GKX5GydLw= 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=D9+jTRpN; 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="D9+jTRpN" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a9a1b71d7ffso654631666b.1 for ; Mon, 28 Oct 2024 06:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730123035; x=1730727835; 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=RRCz/qV1QVQ6e9ttFF+c8lue0LbbnseeINmK7vY3E4E=; b=D9+jTRpNS8NOs62rvXsGuWZ8E0fYsqVeDf6zCnUnIegcartDR9oDFlEMTuZk3CNO+z qG1s/s9rB4yWu7sjYKdOujRtBF5b63Uq7zaoHtlV8Pe5ASLCgOIFrQHDmKLGP2V+1tHi XFfmSi2iTOaxrhE48Rqdiwslarg/V5Y9S3JkZl1d429j83aFVosvCCO36b4lLco6adZ/ tXqA9XVZ58bCV9boTsCtrEgysLDk/MTkvpSwHxLlxg1fF1JNA5GRPBWyQD2H1uJPk3c+ nGdj1UFI/9GACcquBuDQW68H0aKdw3DhDsOR+kDXtgwW22+oXLIh+updWAIsRqwsL4yK d1EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730123035; x=1730727835; 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=RRCz/qV1QVQ6e9ttFF+c8lue0LbbnseeINmK7vY3E4E=; b=OQk7/VlFPMW9oyQLIjTUAXExdC0l3SDB8OFAmlzY4m0E5lsnUKCIohvdB+pcniVL63 5fMVj2leFT3qJIeuEl1n6FP117ehAEWV71agsnNemk9S239nk+TrszgCU6L7V/LGTHMs 6wtUyxt/PBr/atJNeXCIj8GSSAgwTT4UoHhlhO9GJbYb6cuxSdKyin/0LMk00ep9dEJm 955EHNUQnSWwaAIi88M1SKbtWuOUgipVThNj1Vmu5dDVcMfrDIKGUT6j/l+8EuWe00qY qJsTMVQbs8KdMVT1wGkCKi0+YNfJKhg/pmFSZgfdsEhi6ikTArTiMpc/NTWWUvLXQz5F oA9w== X-Gm-Message-State: AOJu0YzVz9xin+tPLnBHlnJKMU3r5kehvdtG4VRp2ctSF5GnGy44hOst NlZ8qzkU0+91l7gc9OQDFOlhxpKYx1yGuUyTYKP5aysUO8odZ6SBAaIn0S8D X-Google-Smtp-Source: AGHT+IFdcYYU1Ra9poo2G8TDqSU/UoYzp7jnNJjzcjCUnZ3p+Jjse/R0nc3/lMb4u4y/yajBHempzg== X-Received: by 2002:a17:907:928b:b0:a9a:c769:5a5 with SMTP id a640c23a62f3a-a9de6157232mr784628266b.50.1730123035198; Mon, 28 Oct 2024 06:43:55 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f2971e8sm376647466b.125.2024.10.28.06.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 06:43:54 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, me@ttaylorr.com Subject: [PATCH v2 6/8] packfile: pass down repository to `for_each_packed_object` Date: Mon, 28 Oct 2024 14:43:44 +0100 Message-ID: <7c599e16f61993fbbcc2c05e58981e638cb96f27.1730122499.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 closely related function `is_promisor_object`. Signed-off-by: Karthik Nayak --- builtin/cat-file.c | 7 ++++--- builtin/fsck.c | 18 +++++++++++------- builtin/pack-objects.c | 7 +++++-- builtin/repack.c | 2 +- builtin/rev-list.c | 2 +- commit-graph.c | 2 +- fsck.c | 2 +- list-objects.c | 4 ++-- object-store-ll.h | 4 ++-- packfile.c | 14 +++++++------- packfile.h | 2 +- promisor-remote.c | 2 +- reachable.c | 2 +- revision.c | 9 +++++---- tag.c | 2 +- 15 files changed, 44 insertions(+), 35 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index bfdfb51c7c..d67b101c20 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -827,15 +827,16 @@ 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_OBJECT_PACK_ORDER); + for_each_packed_object(the_repository, batch_unordered_packed, + &cb, FOR_EACH_OBJECT_PACK_ORDER); oidset_clear(&seen); } else { 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..0196c54eb6 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 */ @@ -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.. */ @@ -488,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; @@ -531,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. @@ -966,7 +969,8 @@ 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) @@ -1011,7 +1015,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 2b2816c243..3635b2c84c 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3858,7 +3858,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); @@ -3927,7 +3928,9 @@ 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/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/commit-graph.c b/commit-graph.c index 83dd69bfeb..e2e2083951 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -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(ctx->r, 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/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..d11a389b3a 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(ctx->revs->repo, &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(revs->repo, &obj->oid)) return; if (!revs->do_not_die_on_missing_objects) diff --git a/object-store-ll.h b/object-store-ll.h index 8b31072b09..6f9f4276e6 100644 --- a/object-store-ll.h +++ b/object-store-ll.h @@ -550,7 +550,7 @@ typedef int each_packed_object_fn(const struct object_id *oid, int for_each_object_in_pack(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 cb, + void *data, enum for_each_object_flags flags); #endif /* OBJECT_STORE_LL_H */ diff --git a/packfile.c b/packfile.c index c6d7ed38f6..74ac6d793b 100644 --- a/packfile.c +++ b/packfile.c @@ -2200,15 +2200,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) && @@ -2286,14 +2286,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(add_promisor_object, + if (repo_has_promisor_remote(repo)) { + for_each_packed_object(repo, add_promisor_object, &promisor_objects, FOR_EACH_OBJECT_PROMISOR_ONLY | FOR_EACH_OBJECT_PACK_ORDER); diff --git a/packfile.h b/packfile.h index ac4f2210c5..c1883e60ef 100644 --- a/packfile.h +++ b/packfile.h @@ -201,7 +201,7 @@ int has_object_kept_pack(struct repository *repo, const struct object_id *oid, * 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/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..45dc6d2819 100644 --- a/revision.c +++ b/revision.c @@ -390,7 +390,8 @@ 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 +433,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 +1212,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; @@ -3915,7 +3916,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); } 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 28 13:43: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: 13853486 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E6A11DE2A2 for ; Mon, 28 Oct 2024 13:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730123041; cv=none; b=dkfzT1pNvwSTULUWQJAjz/DnFJts1ei+KVp1g4bkJim/s77GmDyRGcVgsKwoGWNYMJDjFKWBZvO7EkdaQnvAWQdpXakA7JHFSFS/3QYn3d4t3SxJrPmvXLlyHw/Gdu61aG++RSQiWcWIAUqDNwGtPm3pXFfFa87yYkGhIWak2V8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730123041; c=relaxed/simple; bh=4jsu2avaWsAOhlNRBCPJxT5dxsP7+A5hMtC4yVPBTI8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hsNHp3/fdG2cvM9LxFGnkBV6keMl3i6SwK7R7LlsuaoykoOcEV9SvjT9CaLfIa85V98wbMwMD3wUAhM1jMc8VVmqv3AYiTgmuD0WDwMjXsmKJ3ydkHNOCx4Y92erJKAdXfcF0Zvk5MQy2UNhczb40eyBTHuSw8sYUb44lYfOhOM= 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=VBGXK9KL; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VBGXK9KL" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a9a1b71d7ffso654633666b.1 for ; Mon, 28 Oct 2024 06:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730123037; x=1730727837; 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=hwy5rCwOCC4gSFH82M192kCV5wclpRjQ6TNQvLmYnaE=; b=VBGXK9KL9l5rP+c2EkdniQtfvG8bNn1orsaYzoINbngwWx87dzQZnTSkzF0kvey76P QdApMiTqJY0UeMNnkZzfxeVWaohGLULhcJt9pZ08Uias+j7eSKoijvIPgRDuxvqyMi04 d9ZmDfo2sVsEF0DPE3+pMkoghIyYqW26eGq6PJcYRYGFHSJ0dvcooOhSbL0HHiEO7T/X S3NuLfT+1F7shK6iqH3EQ5RKjl2B5D1CDNDdb9R/cKB+k2lLH2iQMzvEcyVkAzzFk473 +jGRs4lV3FkLnkjkSdr/PnrkN4+otUx/rvma1/+tJDv40ZmOq+u8Ffwy0yG3O4Kc6AJE uJ6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730123037; x=1730727837; 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=hwy5rCwOCC4gSFH82M192kCV5wclpRjQ6TNQvLmYnaE=; b=rF+Om58cW+C6bD5pKGqM0wRmcF6kKzk4T+VcF6Xz+iGIldIBY2DvcDySHXYFPGyTGd AkSoLk5fqeow7IMXwNZdQUEKCd0gDFxR/YcG3YPt6bsNNh11O7QNJImPCYsJIf/m5CA7 weimL5Hjx+aLO8Do9eEy1yTEaIi2lX3mRlleCaML4IqyBcssaqiUa2BLKVot4jBjwf17 OBhvnjD8HB+Y672AYloq4M9X+6mxlzKFVPPi4IGRqQG6k+nxoiixqmAxqVPs+SffRaO3 HZp2++4kclD75nj8DYurAX8hUZvRpxrazWenVDN4OEN+NMiXryjsFHeEujql0FrPc6hC b0Lg== X-Gm-Message-State: AOJu0Yz++cvnifT0+R8q1Ad35MjwtYzukxva0d7ZVPXpr1de2hzRLK5d 1UGxZgbnFXJc1Q4snWUTd7ppoAyRBNG/9I6G5PoNWwzTk7a7qo4d X-Google-Smtp-Source: AGHT+IEShkCvfXVAep0kHdyPOQYYTTlXqXlnsFczZXxEZOxRvWF2a4ESXO89M5J7uufC1Bt02Q3S+w== X-Received: by 2002:a17:907:9449:b0:a99:f92a:7a66 with SMTP id a640c23a62f3a-a9de5d783e5mr789917066b.30.1730123036449; Mon, 28 Oct 2024 06:43:56 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f2971e8sm376647466b.125.2024.10.28.06.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 06:43:55 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, me@ttaylorr.com Subject: [PATCH v2 7/8] config: make `delta_base_cache_limit` a non-global variable Date: Mon, 28 Oct 2024 14:43:45 +0100 Message-ID: <89ee3f48ce982236dd7841fa1a5cb15aa256b901.1730122499.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 `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 eaefb41761..23bfa45403 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 74ac6d793b..93b0d6af31 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) @@ -1496,7 +1498,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); @@ -1878,7 +1885,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 28 13:43: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: 13853487 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 441EE1DD523 for ; Mon, 28 Oct 2024 13:43:59 +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=1730123041; cv=none; b=bPax56E40YfBgZnGPxau3Jh3ojeANA00HoiE1K/hAp3+X/g8olVs7alDc3PJGb9NLQFOHXCDUsOD+Lt7t81oDqrBHipVj5QlahzQvFLIdbGl1JWfiBxFGTwsvTQ0fITLDaHGJymNs5WC8+ofn/KK8gFaK/t8WRrWpSHWQHCBJQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730123041; c=relaxed/simple; bh=+xYmEI/kPdSy/HBx54XisLXhJsgButGLCqzr7zcRIeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ks0w4Fy4ZZjZGMM9f/ScpDv/K/1uT9KM5hjCMOXw/oJl27sFPyiYRx1cWKKenDoelaMzLkwXsFdjWuYhkVPa09bOvhyHSVPvxyTSTWv6VMRPoXvntFTeLt+NglcoNz9srch5/qUH4KeQjfXoRYcXRIXnA8VWNEL3dETxjtdRdZo= 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=KeTpLAZB; 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="KeTpLAZB" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a9a2209bd7fso644689766b.2 for ; Mon, 28 Oct 2024 06:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730123038; x=1730727838; 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=LUv2dyMQ/e/SM+CHRcXtmVAQnljwMyN1ueTOhhsoklM=; b=KeTpLAZBd43WqRW4l0i/di8m1r3tNd2JoCCZuhEcDM3ONLbfKbuuiw50d89hcjrpqc aO3yfWFf4mKK8lim9vCAfb8vt33BUAAY7wXMa8YHoizBMLXEx2XEsnkJO50NkMCm3UgG NhjiZCYQFSbEahLaXqnV9DehoDchm2ztqS5ZQnVq+DY3DyCKdXLNJwko+g3ulmgAOKeL 5F3C9W8VIZEsuPc7TTv1ui3qVebAdwTqHR8n27SDCH3gTPvui4vjNteFBbyEI6yI4R08 esL/r0CHBN8qOEql9Z+lfPILXs5TyqkuGGyMbofUxnG/FzMNsY2SR5cvauRwDoI27uXF DYjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730123038; x=1730727838; 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=LUv2dyMQ/e/SM+CHRcXtmVAQnljwMyN1ueTOhhsoklM=; b=t4Bmtz8OeWuI3gF1a8XBVVtS1hBlIfuIK4ceMfjldmgFpFn09AVN1OEoAhq5q3CpyA UWzXZN35yOp/Me2BN8B0BIaSMn16iFFhew8lnQP83K1Kex29QsVzWxaFq8mVAocMqJHB qTKvv+/WoEslSTJQ5NC7kkwq37NTBPgcpWkk6uW44qWwPYly80dDCEpNsQ1F9Qd8Klx4 InXNdtuWkY2ghcmT18YLkOU81uZ92yXZcAeZeoKTz58tcsvuhdPH0Gugy7r5McbtaAy1 oZvPQ/xjL7N+xsaCHiIi8QWKxa786Y0JkLOae/LGJ9enpF7ZNfISXRxpfEBIcnhVqGr8 1U9A== X-Gm-Message-State: AOJu0YzRpGptUggAM/Y3Swgus6ROA7W12rkr0l0AkzcNJ9ObhiLa5jaJ PXeZNWDmGR/ZEK6kDKgbuapzpK3JHV04HCuROJ/G1tnYguQpcqkXcuyOoi1i X-Google-Smtp-Source: AGHT+IHDNqARU8GTk9ab+kJjH1+LpWTFPlkPT29jFDGPqZVYam7N/h9OgksFW6hnADyFhP0oi7oKdw== X-Received: by 2002:a17:907:944f:b0:a9a:825:4c39 with SMTP id a640c23a62f3a-a9de5d00e3emr853515766b.20.1730123037559; Mon, 28 Oct 2024 06:43:57 -0700 (PDT) Received: from archlinux.fritz.box ([2a02:2455:825d:6a00:6bb4:436f:5699:ff21]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f2971e8sm376647466b.125.2024.10.28.06.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 06:43:57 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, me@ttaylorr.com Subject: [PATCH v2 8/8] config: make `packed_git_(limit|window_size)` non-global variables Date: Mon, 28 Oct 2024 14:43:46 +0100 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 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 | 60 +++++++++++++++++++++++++++++++++++++------ packfile.h | 2 +- 5 files changed, 55 insertions(+), 30 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index f4892d7f37..9056447bd0 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -3539,7 +3539,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; @@ -3660,7 +3660,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 93b0d6af31..cfbfcdc2b8 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) { @@ -48,15 +58,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" @@ -652,20 +691,25 @@ unsigned char *use_pack(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(p->repo, packfile_config, &config); + window_align = config.packed_git_window_size / 2; + if (p->pack_fd == -1 && open_packed_git(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(p)) ; /* nothing */ win->base = xmmap_gently(NULL, win->len, diff --git a/packfile.h b/packfile.h index c1883e60ef..3409aef35d 100644 --- a/packfile.h +++ b/packfile.h @@ -89,7 +89,7 @@ unsigned long repo_approximate_object_count(struct repository *r); struct packed_git *find_oid_pack(const struct object_id *oid, 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