{"thread":{"id":"62291","subject":"[PATCH] loose: don't rely on repository global state","startedAt":"2024-10-09T09:59:01Z","lastAt":"2024-10-10T06:45:23Z","messageCount":4,"participants":["Karthik Nayak","Junio C Hamano","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"504533","messageId":"CAOLa=ZRMaw-PAsZ9s0zJ2zp_suMppi=ZrT67B__LU1tWZSvuUQ@mail.gmail.com","threadId":"62291","inReplyTo":null,"subject":"[PATCH] loose: don't rely on repository global state","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-09T09:58:59Z","receivedAt":"2024-10-09T09:59:01Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In `loose.c`, we rely on the global variable `the_hash_algo`. As such we\nhave guarded the file with the 'USE_THE_REPOSITORY_VARIABLE' definition.\nLet's derive the hash algorithm from the available repository variable\nand remove this guard. This brings us one step closer to removing the\nglobal 'the_repository' variable.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n loose.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/loose.c b/loose.c\nindex 6d6a41b7e5..897ba389da 100644\n--- a/loose.c\n+++ b/loose.c\n@@ -1,10 +1,9 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"hash.h\"\n #include \"path.h\"\n #include \"object-store.h\"\n #include \"hex.h\"\n+#include \"repository.h\"\n #include \"wrapper.h\"\n #include \"gettext.h\"\n #include \"loose.h\"\n@@ -142,8 +141,8 @@ int repo_write_loose_object_map(struct repository *repo)\n\n \tfor (; iter != kh_end(map); iter++) {\n \t\tif (kh_exist(map, iter)) {\n-\t\t\tif (oideq(&kh_key(map, iter), the_hash_algo->empty_tree) ||\n-\t\t\t    oideq(&kh_key(map, iter), the_hash_algo->empty_blob))\n+\t\t\tif (oideq(&kh_key(map, iter), repo->hash_algo->empty_tree) ||\n+\t\t\t    oideq(&kh_key(map, iter), repo->hash_algo->empty_blob))\n \t\t\t\tcontinue;\n \t\t\tstrbuf_addf(&buf, \"%s %s\\n\", oid_to_hex(&kh_key(map, iter)),\noid_to_hex(kh_value(map, iter)));\n \t\t\tif (write_in_full(fd, buf.buf, buf.len) < 0)\n-- \n2.46.2\n"},{"id":"504629","messageId":"xmqqcyk9rtwv.fsf@gitster.g","threadId":"62291","inReplyTo":"CAOLa=ZRMaw-PAsZ9s0zJ2zp_suMppi=ZrT67B__LU1tWZSvuUQ@mail.gmail.com","subject":"Re: [PATCH] loose: don't rely on repository global state","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-10-09T18:52:00Z","receivedAt":"2024-10-09T18:52:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Karthik Nayak <karthik.188@gmail.com> writes:\n\n>  \t\t\tstrbuf_addf(&buf, \"%s %s\\n\", oid_to_hex(&kh_key(map, iter)),\n> oid_to_hex(kh_value(map, iter)));\n\nThe line seems corrupt.  Joining them with one SP in between makes\nthe patch cleanly apply.\n\n"},{"id":"504635","messageId":"CAOLa=ZThTs=EzFEAHM+aLJ5Eq_E-RPfGrKiceDADsBGJQE859w@mail.gmail.com","threadId":"62291","inReplyTo":"xmqqcyk9rtwv.fsf@gitster.g","subject":"Re: [PATCH] loose: don't rely on repository global state","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-09T19:41:19Z","receivedAt":"2024-10-09T19:41:47Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"On Wed, Oct 9, 2024 at 8:52 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Karthik Nayak <karthik.188@gmail.com> writes:\n>\n> >                       strbuf_addf(&buf, \"%s %s\\n\", oid_to_hex(&kh_key(map, iter)),\n> > oid_to_hex(kh_value(map, iter)));\n>\n> The line seems corrupt.  Joining them with one SP in between makes\n> the patch cleanly apply.\n\nIndeed. I used `format-patch` and `send-email` right after, I don't\nremember messing with it, but perhaps I did. Thanks for fixing it up\nand checking.\n"},{"id":"504677","messageId":"Zwd393AHNAGQ_zAx@pks.im","threadId":"62291","inReplyTo":"CAOLa=ZRMaw-PAsZ9s0zJ2zp_suMppi=ZrT67B__LU1tWZSvuUQ@mail.gmail.com","subject":"Re: [PATCH] loose: don't rely on repository global state","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-10-10T06:45:17Z","receivedAt":"2024-10-10T06:45:23Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Oct 09, 2024 at 02:58:59AM -0700, Karthik Nayak wrote:\n> In `loose.c`, we rely on the global variable `the_hash_algo`. As such we\n> have guarded the file with the 'USE_THE_REPOSITORY_VARIABLE' definition.\n> Let's derive the hash algorithm from the available repository variable\n> and remove this guard. This brings us one step closer to removing the\n> global 'the_repository' variable.\n> \n> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n> ---\n>  loose.c | 7 +++----\n>  1 file changed, 3 insertions(+), 4 deletions(-)\n> \n> diff --git a/loose.c b/loose.c\n> index 6d6a41b7e5..897ba389da 100644\n> --- a/loose.c\n> +++ b/loose.c\n> @@ -1,10 +1,9 @@\n> -#define USE_THE_REPOSITORY_VARIABLE\n> -\n>  #include \"git-compat-util.h\"\n>  #include \"hash.h\"\n>  #include \"path.h\"\n>  #include \"object-store.h\"\n>  #include \"hex.h\"\n> +#include \"repository.h\"\n>  #include \"wrapper.h\"\n>  #include \"gettext.h\"\n>  #include \"loose.h\"\n> @@ -142,8 +141,8 @@ int repo_write_loose_object_map(struct repository *repo)\n> \n>  \tfor (; iter != kh_end(map); iter++) {\n>  \t\tif (kh_exist(map, iter)) {\n> -\t\t\tif (oideq(&kh_key(map, iter), the_hash_algo->empty_tree) ||\n> -\t\t\t    oideq(&kh_key(map, iter), the_hash_algo->empty_blob))\n> +\t\t\tif (oideq(&kh_key(map, iter), repo->hash_algo->empty_tree) ||\n> +\t\t\t    oideq(&kh_key(map, iter), repo->hash_algo->empty_blob))\n>  \t\t\t\tcontinue;\n>  \t\t\tstrbuf_addf(&buf, \"%s %s\\n\", oid_to_hex(&kh_key(map, iter)),\n> oid_to_hex(kh_value(map, iter)));\n>  \t\t\tif (write_in_full(fd, buf.buf, buf.len) < 0)\n\nI've already had a look internally and couldn't spot any other things\nthat'd need to be converted in this file. So this looks good to me,\nexcept for the whitespace-broken parts.\n\nThanks!\n\nPatrick\n"}]}