All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Karthik Nayak via B4 Relay <devnull+karthik.188.gmail.com@kernel.org>
Cc: git@vger.kernel.org,  Karthik Nayak <karthik.188@gmail.com>
Subject: Re: [PATCH 2/5] pack-write: pass repository to `index_pack_lockfile()`
Date: Thu, 16 Jan 2025 11:05:07 -0800	[thread overview]
Message-ID: <xmqqo706r34s.fsf@gitster.g> (raw)
In-Reply-To: <20250116-kn-the-repo-cleanup-v1-2-a2f4c8e1c4c3@gmail.com> (Karthik Nayak via's message of "Thu, 16 Jan 2025 12:35:14 +0100")

Karthik Nayak via B4 Relay
<devnull+karthik.188.gmail.com@kernel.org> writes:

> From: Karthik Nayak <karthik.188@gmail.com>
>
> The `index_pack_lockfile()` function uses the global `the_repository`
> variable to access the repository. To avoid global variable usage, pass
> the repository from the layers above.
>
> Altough the layers above could have access to the hash function

I do not think the choice of the hash algorithm has much to do with
this change, though ;-)

> internally, simply pass in `the_hash_algo`. This avoids any
> compatibility issues and bubbles up global variable usage to upper
> layers which can be eventually resolved.
>
> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
> ---
>  builtin/receive-pack.c | 2 +-
>  fetch-pack.c           | 4 +++-
>  pack-write.c           | 6 +++---
>  pack.h                 | 2 +-
>  4 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
> index 56347a79633505efe8dc05acf1583b4c9995eefe..b83abe5d220cefd3707b701409dc5e6b67566599 100644
> --- a/builtin/receive-pack.c
> +++ b/builtin/receive-pack.c
> @@ -2304,7 +2304,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
>  		if (status)
>  			return "index-pack fork failed";
>  
> -		lockfile = index_pack_lockfile(child.out, NULL);
> +		lockfile = index_pack_lockfile(the_repository, child.out, NULL);
>  		if (lockfile) {
>  			pack_lockfile = register_tempfile(lockfile);
>  			free(lockfile);
> diff --git a/fetch-pack.c b/fetch-pack.c
> index 3a227721ed0935d1f9c40584c57f54043354c032..824f56ecbca11cd9e4da6a3e4c450c6b2e7078ab 100644
> --- a/fetch-pack.c
> +++ b/fetch-pack.c
> @@ -1036,7 +1036,9 @@ static int get_pack(struct fetch_pack_args *args,
>  		die(_("fetch-pack: unable to fork off %s"), cmd_name);
>  	if (do_keep && (pack_lockfiles || fsck_objects)) {
>  		int is_well_formed;
> -		char *pack_lockfile = index_pack_lockfile(cmd.out, &is_well_formed);
> +		char *pack_lockfile = index_pack_lockfile(the_repository,
> +							  cmd.out,
> +							  &is_well_formed);
>  
>  		if (!is_well_formed)
>  			die(_("fetch-pack: invalid index-pack output"));
> diff --git a/pack-write.c b/pack-write.c
> index fc887850dfb9789132b8642733c6472944dbe32d..0cd75d2e55419362a61cf981fc11117ea7a1d88a 100644
> --- a/pack-write.c
> +++ b/pack-write.c
> @@ -460,10 +460,10 @@ void fixup_pack_header_footer(const struct git_hash_algo *hash_algo,
>  	fsync_component_or_die(FSYNC_COMPONENT_PACK, pack_fd, pack_name);
>  }
>  
> -char *index_pack_lockfile(int ip_out, int *is_well_formed)
> +char *index_pack_lockfile(struct repository *r, int ip_out, int *is_well_formed)
>  {
>  	char packname[GIT_MAX_HEXSZ + 6];
> -	const int len = the_hash_algo->hexsz + 6;
> +	const int len = r->hash_algo->hexsz + 6;
>  
>  	/*
>  	 * The first thing we expect from index-pack's output
> @@ -480,7 +480,7 @@ char *index_pack_lockfile(int ip_out, int *is_well_formed)
>  		packname[len-1] = 0;
>  		if (skip_prefix(packname, "keep\t", &name))
>  			return xstrfmt("%s/pack/pack-%s.keep",
> -				       repo_get_object_directory(the_repository), name);
> +				       repo_get_object_directory(r), name);
>  		return NULL;
>  	}
>  	if (is_well_formed)
> diff --git a/pack.h b/pack.h
> index 6d9d477adc83e83d9e9175ccf699c100b4c147c6..46d85e5bec787c90af69700fd4b328b1ebf1d606 100644
> --- a/pack.h
> +++ b/pack.h
> @@ -94,7 +94,7 @@ off_t write_pack_header(struct hashfile *f, uint32_t);
>  void fixup_pack_header_footer(const struct git_hash_algo *, int,
>  			      unsigned char *, const char *, uint32_t,
>  			      unsigned char *, off_t);
> -char *index_pack_lockfile(int fd, int *is_well_formed);
> +char *index_pack_lockfile(struct repository *r, int fd, int *is_well_formed);
>  
>  struct ref;

  reply	other threads:[~2025-01-16 19:05 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-16 11:35 [PATCH 0/5] pack-write: cleanup usage of global variables Karthik Nayak
2025-01-16 11:35 ` Karthik Nayak via B4 Relay
2025-01-16 11:35 ` [PATCH 1/5] pack-write: pass hash_algo to `fixup_pack_header_footer()` Karthik Nayak
2025-01-16 11:35   ` Karthik Nayak via B4 Relay
2025-01-16 19:35   ` Junio C Hamano
2025-01-16 11:35 ` [PATCH 2/5] pack-write: pass repository to `index_pack_lockfile()` Karthik Nayak
2025-01-16 11:35   ` Karthik Nayak via B4 Relay
2025-01-16 19:05   ` Junio C Hamano [this message]
2025-01-17  8:47     ` Karthik Nayak
2025-01-16 11:35 ` [PATCH 3/5] pack-write: pass hash_algo to `write_idx_file()` Karthik Nayak
2025-01-16 11:35   ` Karthik Nayak via B4 Relay
2025-01-16 13:24   ` Patrick Steinhardt
2025-01-17  8:56     ` Karthik Nayak
2025-01-16 19:12   ` Junio C Hamano
2025-01-17  8:58     ` Karthik Nayak
2025-01-16 11:35 ` [PATCH 4/5] pack-write: pass hash_algo to `write_rev_file()` Karthik Nayak
2025-01-16 11:35   ` Karthik Nayak via B4 Relay
2025-01-16 13:24   ` Patrick Steinhardt
2025-01-16 19:35   ` Junio C Hamano
2025-01-16 11:35 ` [PATCH 5/5] pack-write: pass hash_algo to `write_rev_*()` Karthik Nayak
2025-01-16 11:35   ` Karthik Nayak via B4 Relay
2025-01-17  9:20 ` [PATCH v2 0/5] pack-write: cleanup usage of global variables Karthik Nayak
2025-01-17  9:20   ` [PATCH v2 1/5] pack-write: pass hash_algo to `fixup_pack_header_footer()` Karthik Nayak
2025-01-17 16:38     ` Toon Claes
2025-01-17 18:06       ` Junio C Hamano
2025-01-19 11:07         ` Karthik Nayak
2025-01-17  9:20   ` [PATCH v2 2/5] pack-write: pass repository to `index_pack_lockfile()` Karthik Nayak
2025-01-17  9:20   ` [PATCH v2 3/5] pack-write: pass hash_algo to `write_idx_file()` Karthik Nayak
2025-01-17 16:40     ` Toon Claes
2025-01-19 11:10       ` Karthik Nayak
2025-01-17  9:20   ` [PATCH v2 4/5] pack-write: pass hash_algo to `write_rev_file()` Karthik Nayak
2025-01-17  9:20   ` [PATCH v2 5/5] pack-write: pass hash_algo to internal functions Karthik Nayak
2025-01-17  9:46     ` Patrick Steinhardt
2025-01-17  9:55       ` Karthik Nayak
2025-01-19 11:19   ` [PATCH v3 0/5] pack-write: cleanup usage of global variables Karthik Nayak
2025-01-19 11:19     ` [PATCH v3 1/5] pack-write: pass hash_algo to `fixup_pack_header_footer()` Karthik Nayak
2025-01-19 11:19     ` [PATCH v3 2/5] pack-write: pass repository to `index_pack_lockfile()` Karthik Nayak
2025-01-19 11:19     ` [PATCH v3 3/5] pack-write: pass hash_algo to `write_idx_file()` Karthik Nayak
2025-01-19 11:19     ` [PATCH v3 4/5] pack-write: pass hash_algo to `write_rev_file()` Karthik Nayak
2025-01-19 11:19     ` [PATCH v3 5/5] pack-write: pass hash_algo to internal functions Karthik Nayak
2025-01-24  5:46     ` [PATCH v3 0/5] pack-write: cleanup usage of global variables Patrick Steinhardt
2025-01-24 15:47       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqo706r34s.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=devnull+karthik.188.gmail.com@kernel.org \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.