From: Tian Yuchen <cat@malon.dev>
To: git@vger.kernel.org
Cc: gitster@pobox.com, karthik.188@gmail.com,
phillip.wood@dunelm.org.uk, jltobler@gmail.com, ps@pks.im,
Tian Yuchen <cat@malon.dev>
Subject: [PATCH v1] builtin/mktree: remove USE_THE_REPOSITORY_VARIABLE
Date: Thu, 12 Mar 2026 02:17:03 +0800 [thread overview]
Message-ID: <20260311181704.958509-1-cat@malon.dev> (raw)
The 'cmd_mktree' already receives a 'struct repository *repo' but was
previously marked as UNUSED.
Pass the 'repo' down the 'mktree-line()' and 'write_tree()'.
Consequently, remove the 'USE_THE_REPOSITORY_VARIABLE' macro, and
replace 'parse_oid_hex()' with its context-aware version
'parse_oid_hex_algop()'.
Signed-off-by: Tian Yuchen <cat@malon.dev>
---
I originally intended to attempt the #FIXME in t1006-cat-file.sh.
I followed the clues all the way here, only to discover that the
FIXME required a level of expertise far beyond my capabilities,
so I gave up. However, I spot the global variable here, so I went
ahead and fixed it ;)
Two questions:
The 'oid_to_hex' function appears to use 'the_hash_algo' internally.
Seems that it also implicitly relying on global state. Is there
anything we should be aware of?
I've always been unsure about who to CC on domain-specific patches,
so I've only been sending them to Junio and the mailing list. Could
this be why my previous patch for a global variable refactor didn't
receive any review feedback? Here is the link:
https://lore.kernel.org/git/20260302085738.2510514-1-a3205153416@gmail.com/
I would be most grateful if you could provide any feedback. Thank you.
builtin/mktree.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 12772303f5..4084e32476 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -3,7 +3,6 @@
*
* Copyright (c) Junio C Hamano, 2006, 2009
*/
-#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h"
#include "gettext.h"
#include "hex.h"
@@ -46,7 +45,7 @@ static int ent_compare(const void *a_, const void *b_)
b->name, b->len, b->mode);
}
-static void write_tree(struct object_id *oid)
+static void write_tree(struct repository *repo, struct object_id *oid)
{
struct strbuf buf;
size_t size;
@@ -60,10 +59,10 @@ static void write_tree(struct object_id *oid)
for (i = 0; i < used; i++) {
struct treeent *ent = entries[i];
strbuf_addf(&buf, "%o %s%c", ent->mode, ent->name, '\0');
- strbuf_add(&buf, ent->oid.hash, the_hash_algo->rawsz);
+ strbuf_add(&buf, ent->oid.hash, repo->hash_algo->rawsz);
}
- odb_write_object(the_repository->objects, buf.buf, buf.len, OBJ_TREE, oid);
+ odb_write_object(repo->objects, buf.buf, buf.len, OBJ_TREE, oid);
strbuf_release(&buf);
}
@@ -72,7 +71,7 @@ static const char *const mktree_usage[] = {
NULL
};
-static void mktree_line(char *buf, int nul_term_line, int allow_missing)
+static void mktree_line(struct repository *repo, char *buf, int nul_term_line, int allow_missing)
{
char *ptr, *ntr;
const char *p;
@@ -93,7 +92,7 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
die("input format error: %s", buf);
ptr = ntr + 1; /* type */
ntr = strchr(ptr, ' ');
- if (!ntr || parse_oid_hex(ntr + 1, &oid, &p) ||
+ if (!ntr || parse_oid_hex_algop(ntr + 1, &oid, &p, repo->hash_algo) ||
*p != '\t')
die("input format error: %s", buf);
@@ -124,7 +123,7 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
/* Check the type of object identified by oid without fetching objects */
oi.typep = &obj_type;
- if (odb_read_object_info_extended(the_repository->objects, &oid, &oi,
+ if (odb_read_object_info_extended(repo->objects, &oid, &oi,
OBJECT_INFO_LOOKUP_REPLACE |
OBJECT_INFO_QUICK |
OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
@@ -155,7 +154,7 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
int cmd_mktree(int ac,
const char **av,
const char *prefix,
- struct repository *repo UNUSED)
+ struct repository *repo)
{
struct strbuf sb = STRBUF_INIT;
struct object_id oid;
@@ -187,7 +186,7 @@ int cmd_mktree(int ac,
break;
die("input format error: (blank line only valid in batch mode)");
}
- mktree_line(sb.buf, nul_term_line, allow_missing);
+ mktree_line(repo, sb.buf, nul_term_line, allow_missing);
}
if (is_batch_mode && got_eof && used < 1) {
/*
@@ -197,7 +196,7 @@ int cmd_mktree(int ac,
*/
; /* skip creating an empty tree */
} else {
- write_tree(&oid);
+ write_tree(repo, &oid);
puts(oid_to_hex(&oid));
fflush(stdout);
}
--
2.43.0
next reply other threads:[~2026-03-11 18:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 18:17 Tian Yuchen [this message]
2026-03-12 6:55 ` [PATCH v1] builtin/mktree: remove USE_THE_REPOSITORY_VARIABLE Patrick Steinhardt
2026-03-12 16:21 ` Tian Yuchen
2026-03-13 7:02 ` Patrick Steinhardt
2026-03-13 16:03 ` Junio C Hamano
2026-03-13 17:15 ` Tian Yuchen
2026-03-13 17:54 ` Junio C Hamano
2026-03-13 18:12 ` Tian Yuchen
2026-03-13 20:20 ` Junio C Hamano
2026-03-14 3:17 ` Tian Yuchen
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=20260311181704.958509-1-cat@malon.dev \
--to=cat@malon.dev \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jltobler@gmail.com \
--cc=karthik.188@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox