* [PATCH] loose: don't rely on repository global state
@ 2024-10-09 9:58 Karthik Nayak
2024-10-09 18:52 ` Junio C Hamano
2024-10-10 6:45 ` Patrick Steinhardt
0 siblings, 2 replies; 4+ messages in thread
From: Karthik Nayak @ 2024-10-09 9:58 UTC (permalink / raw)
To: git; +Cc: Karthik Nayak
In `loose.c`, we rely on the global variable `the_hash_algo`. As such we
have guarded the file with the 'USE_THE_REPOSITORY_VARIABLE' definition.
Let's derive the hash algorithm from the available repository variable
and remove this guard. This brings us one step closer to removing the
global 'the_repository' variable.
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
loose.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/loose.c b/loose.c
index 6d6a41b7e5..897ba389da 100644
--- a/loose.c
+++ b/loose.c
@@ -1,10 +1,9 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "hash.h"
#include "path.h"
#include "object-store.h"
#include "hex.h"
+#include "repository.h"
#include "wrapper.h"
#include "gettext.h"
#include "loose.h"
@@ -142,8 +141,8 @@ int repo_write_loose_object_map(struct repository *repo)
for (; iter != kh_end(map); iter++) {
if (kh_exist(map, iter)) {
- if (oideq(&kh_key(map, iter), the_hash_algo->empty_tree) ||
- oideq(&kh_key(map, iter), the_hash_algo->empty_blob))
+ if (oideq(&kh_key(map, iter), repo->hash_algo->empty_tree) ||
+ oideq(&kh_key(map, iter), repo->hash_algo->empty_blob))
continue;
strbuf_addf(&buf, "%s %s\n", oid_to_hex(&kh_key(map, iter)),
oid_to_hex(kh_value(map, iter)));
if (write_in_full(fd, buf.buf, buf.len) < 0)
--
2.46.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] loose: don't rely on repository global state
2024-10-09 9:58 [PATCH] loose: don't rely on repository global state Karthik Nayak
@ 2024-10-09 18:52 ` Junio C Hamano
2024-10-09 19:41 ` Karthik Nayak
2024-10-10 6:45 ` Patrick Steinhardt
1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2024-10-09 18:52 UTC (permalink / raw)
To: Karthik Nayak; +Cc: git
Karthik Nayak <karthik.188@gmail.com> writes:
> strbuf_addf(&buf, "%s %s\n", oid_to_hex(&kh_key(map, iter)),
> oid_to_hex(kh_value(map, iter)));
The line seems corrupt. Joining them with one SP in between makes
the patch cleanly apply.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] loose: don't rely on repository global state
2024-10-09 18:52 ` Junio C Hamano
@ 2024-10-09 19:41 ` Karthik Nayak
0 siblings, 0 replies; 4+ messages in thread
From: Karthik Nayak @ 2024-10-09 19:41 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Wed, Oct 9, 2024 at 8:52 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Karthik Nayak <karthik.188@gmail.com> writes:
>
> > strbuf_addf(&buf, "%s %s\n", oid_to_hex(&kh_key(map, iter)),
> > oid_to_hex(kh_value(map, iter)));
>
> The line seems corrupt. Joining them with one SP in between makes
> the patch cleanly apply.
Indeed. I used `format-patch` and `send-email` right after, I don't
remember messing with it, but perhaps I did. Thanks for fixing it up
and checking.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] loose: don't rely on repository global state
2024-10-09 9:58 [PATCH] loose: don't rely on repository global state Karthik Nayak
2024-10-09 18:52 ` Junio C Hamano
@ 2024-10-10 6:45 ` Patrick Steinhardt
1 sibling, 0 replies; 4+ messages in thread
From: Patrick Steinhardt @ 2024-10-10 6:45 UTC (permalink / raw)
To: Karthik Nayak; +Cc: git
On Wed, Oct 09, 2024 at 02:58:59AM -0700, Karthik Nayak wrote:
> In `loose.c`, we rely on the global variable `the_hash_algo`. As such we
> have guarded the file with the 'USE_THE_REPOSITORY_VARIABLE' definition.
> Let's derive the hash algorithm from the available repository variable
> and remove this guard. This brings us one step closer to removing the
> global 'the_repository' variable.
>
> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
> ---
> loose.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/loose.c b/loose.c
> index 6d6a41b7e5..897ba389da 100644
> --- a/loose.c
> +++ b/loose.c
> @@ -1,10 +1,9 @@
> -#define USE_THE_REPOSITORY_VARIABLE
> -
> #include "git-compat-util.h"
> #include "hash.h"
> #include "path.h"
> #include "object-store.h"
> #include "hex.h"
> +#include "repository.h"
> #include "wrapper.h"
> #include "gettext.h"
> #include "loose.h"
> @@ -142,8 +141,8 @@ int repo_write_loose_object_map(struct repository *repo)
>
> for (; iter != kh_end(map); iter++) {
> if (kh_exist(map, iter)) {
> - if (oideq(&kh_key(map, iter), the_hash_algo->empty_tree) ||
> - oideq(&kh_key(map, iter), the_hash_algo->empty_blob))
> + if (oideq(&kh_key(map, iter), repo->hash_algo->empty_tree) ||
> + oideq(&kh_key(map, iter), repo->hash_algo->empty_blob))
> continue;
> strbuf_addf(&buf, "%s %s\n", oid_to_hex(&kh_key(map, iter)),
> oid_to_hex(kh_value(map, iter)));
> if (write_in_full(fd, buf.buf, buf.len) < 0)
I've already had a look internally and couldn't spot any other things
that'd need to be converted in this file. So this looks good to me,
except for the whitespace-broken parts.
Thanks!
Patrick
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-10 6:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-09 9:58 [PATCH] loose: don't rely on repository global state Karthik Nayak
2024-10-09 18:52 ` Junio C Hamano
2024-10-09 19:41 ` Karthik Nayak
2024-10-10 6:45 ` Patrick Steinhardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).