From: Tian Yuchen <cat@malon.dev>
To: git@vger.kernel.org
Cc: ps@pks.im, newren@gmail.com, Tian Yuchen <cat@malon.dev>,
Christian Couder <christian.couder@gmail.com>,
Ayush Chandekar <ayu.chandekar@gmail.com>,
Olamide Caleb Bello <belkid98@gmail.com>
Subject: [PATCH v1 1/3] environment: migrate minimum_abbrev and default_abbrev
Date: Sat, 25 Jul 2026 19:54:26 +0800 [thread overview]
Message-ID: <20260725115428.2214202-2-cat@malon.dev> (raw)
In-Reply-To: <20260725115428.2214202-1-cat@malon.dev>
Move the global 'minimum_abbrev' and 'default_abbrev' configurations
into the repository-specific 'repo_config_values'
struct.
To ensure code readability, the getter functions
'repo_minimum_abbrev()' and 'repo_default_abbrev()' have been introduced.
The existing MINIMUM_ABBREV and DEFAULT_ABBREV macros are redefined to
the corresponding getters.
Additionally, some subsystems forbid the direct use of 'the_repository'
and must pass their own local 'repo'. Let the getters explicitly intercept
these instances.
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>
Mentored-by: Olamide Caleb Bello <belkid98@gmail.com>
Signed-off-by: Tian Yuchen <cat@malon.dev>
---
environment.c | 31 ++++++++++++++++++++++++++-----
environment.h | 6 +++++-
merge-ort.c | 7 ++++---
object-name.h | 4 ++--
replay.c | 2 +-
sequencer.c | 5 +++--
6 files changed, 41 insertions(+), 14 deletions(-)
diff --git a/environment.c b/environment.c
index c663113e8a..2b44778b50 100644
--- a/environment.c
+++ b/environment.c
@@ -43,7 +43,6 @@ static int zlib_compression_seen;
int trust_executable_bit = 1;
int has_symlinks = 1;
-int minimum_abbrev = 4, default_abbrev = -1;
int assume_unchanged;
char *git_commit_encoding;
char *git_log_output_encoding;
@@ -148,6 +147,26 @@ int repo_ignore_case(struct repository *repo)
0;
}
+int repo_minimum_abbrev(struct repository *repo)
+{
+ if (repo != the_repository)
+ repo = the_repository;
+
+ return repo->initialized
+ ? repo_config_values(repo)->minimum_abbrev
+ : 4;
+}
+
+int repo_default_abbrev(struct repository *repo)
+{
+ if (repo != the_repository)
+ repo = the_repository;
+
+ return repo->initialized
+ ? repo_config_values(repo)->default_abbrev
+ : -1;
+}
+
int have_git_dir(void)
{
return startup_info->have_repository
@@ -364,14 +383,14 @@ int git_default_core_config(const char *var, const char *value,
if (!value)
return config_error_nonbool(var);
if (!strcasecmp(value, "auto"))
- default_abbrev = -1;
+ cfg->default_abbrev = -1;
else if (!git_parse_maybe_bool_text(value))
- default_abbrev = GIT_MAX_HEXSZ;
+ cfg->default_abbrev = GIT_MAX_HEXSZ;
else {
int abbrev = git_config_int(var, value, ctx->kvi);
- if (abbrev < minimum_abbrev)
+ if (abbrev < cfg->minimum_abbrev)
return error(_("abbrev length out of range: %d"), abbrev);
- default_abbrev = abbrev;
+ cfg->default_abbrev = abbrev;
}
return 0;
}
@@ -738,6 +757,8 @@ void repo_config_values_init(struct repo_config_values *cfg)
cfg->check_stat = 1;
cfg->zlib_compression_level = Z_BEST_SPEED;
cfg->pack_compression_level = Z_DEFAULT_COMPRESSION;
+ cfg->minimum_abbrev = 4;
+ cfg->default_abbrev = -1;
cfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
cfg->core_sparse_checkout_cone = 0;
cfg->sparse_expect_files_outside_of_patterns = 0;
diff --git a/environment.h b/environment.h
index acfb670be1..c5905d8b01 100644
--- a/environment.h
+++ b/environment.h
@@ -95,6 +95,8 @@ struct repo_config_values {
int check_stat;
int zlib_compression_level;
int pack_compression_level;
+ int minimum_abbrev;
+ int default_abbrev;
int precomposed_unicode;
int core_sparse_checkout_cone;
int warn_on_object_refname_ambiguity;
@@ -151,6 +153,9 @@ int repo_protect_ntfs(struct repository *repo);
*/
int repo_ignore_case(struct repository *repo);
+int repo_minimum_abbrev(struct repository *repo);
+int repo_default_abbrev(struct repository *repo);
+
void repo_config_values_init(struct repo_config_values *cfg);
int is_bare_repository(struct repository *repo);
@@ -180,7 +185,6 @@ int have_git_dir(void);
/* Environment bits from configuration mechanism */
extern int trust_executable_bit;
extern int has_symlinks;
-extern int minimum_abbrev, default_abbrev;
extern int assume_unchanged;
extern char *apply_default_whitespace;
extern char *apply_default_ignorewhitespace;
diff --git a/merge-ort.c b/merge-ort.c
index c410a5d353..b94ebcc2de 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -777,7 +777,7 @@ static void format_commit(struct strbuf *sb,
{
struct merge_remote_desc *desc;
struct pretty_print_context ctx = {0};
- ctx.abbrev = DEFAULT_ABBREV;
+ ctx.abbrev = repo_default_abbrev(repo);
strbuf_addchars(sb, ' ', indent);
desc = merge_remote_util(commit);
@@ -2035,7 +2035,8 @@ static int merge_submodule(struct merge_options *opt,
util->flag = sub_flag;
util->abbrev = NULL;
if (!sub_not_initialized) {
- abbrev = repo_find_unique_abbrev(&subrepo, b, DEFAULT_ABBREV);
+ abbrev = repo_find_unique_abbrev(&subrepo, b,
+ repo_default_abbrev(opt->repo));
util->abbrev = xstrdup(abbrev);
}
string_list_append(csub, path)->util = util;
@@ -5348,7 +5349,7 @@ static void merge_ort_internal(struct merge_options *opt,
} else {
strbuf_add_unique_abbrev(&merge_base_abbrev,
&merged_merge_bases->object.oid,
- DEFAULT_ABBREV);
+ repo_default_abbrev(opt->repo));
ancestor_name = merge_base_abbrev.buf;
}
diff --git a/object-name.h b/object-name.h
index 167a9154ea..a6d7206ed8 100644
--- a/object-name.h
+++ b/object-name.h
@@ -133,8 +133,8 @@ struct object *repo_peel_to_type(struct repository *r,
struct object *o, enum object_type);
/* Convert to/from hex/sha1 representation */
-#define MINIMUM_ABBREV minimum_abbrev
-#define DEFAULT_ABBREV default_abbrev
+#define MINIMUM_ABBREV repo_minimum_abbrev(the_repository)
+#define DEFAULT_ABBREV repo_default_abbrev(the_repository)
/* used when the code does not know or care what the default abbrev is */
#define FALLBACK_DEFAULT_ABBREV 7
diff --git a/replay.c b/replay.c
index 463c900d6c..cd41c7f507 100644
--- a/replay.c
+++ b/replay.c
@@ -27,7 +27,7 @@ static const char *short_commit_name(struct repository *repo,
struct commit *commit)
{
return repo_find_unique_abbrev(repo, &commit->object.oid,
- DEFAULT_ABBREV);
+ repo_default_abbrev(repo));
}
static struct commit *peel_committish(struct repository *repo,
diff --git a/sequencer.c b/sequencer.c
index 1355a99a09..2426c5e422 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -5813,7 +5813,7 @@ static const char *label_oid(struct object_id *oid, const char *label,
label = p = state->buf.buf;
repo_find_unique_abbrev_r(the_repository, p, oid,
- default_abbrev);
+ repo_default_abbrev(the_repository));
/*
* We may need to extend the abbreviated hash so that there is
@@ -5875,7 +5875,8 @@ static const char *label_oid(struct object_id *oid, const char *label,
strbuf_addch(buf, '-');
if (!buf->len) {
strbuf_addstr(buf, "rev-");
- strbuf_add_unique_abbrev(buf, oid, default_abbrev);
+ strbuf_add_unique_abbrev(buf, oid,
+ repo_default_abbrev(the_repository));
}
label = buf->buf;
--
2.43.0
next prev parent reply other threads:[~2026-07-25 11:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 11:54 [PATCH v1 0/3] environment: migrate more global variables, pt.2 Tian Yuchen
2026-07-25 11:54 ` Tian Yuchen [this message]
2026-07-25 11:54 ` [PATCH v1 2/3] environment: migrate pack_size_limit_cfg into repo_config_values Tian Yuchen
2026-07-25 11:54 ` [PATCH v1 3/3] environment: migrate assume_unchanged " 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=20260725115428.2214202-2-cat@malon.dev \
--to=cat@malon.dev \
--cc=ayu.chandekar@gmail.com \
--cc=belkid98@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=newren@gmail.com \
--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 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.