From: Yuvraj Singh Chauhan <ysinghcin@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH 1/2] environment: move grafts_keep_true_parents into repo_config_values
Date: Wed, 2 Sep 2026 17:00:45 +0530 [thread overview]
Message-ID: <20260902113109.686014-1-ysinghcin@gmail.com> (raw)
Move the global 'grafts_keep_true_parents' configuration variable into
the repository-specific 'repo_config_values' struct.
Introduce the getter function 'repo_grafts_keep_true_parents(repo)'
which checks whether 'repo->initialized' is set, falling back to 0
when uninitialized.
Update call sites in commit.c to use 'repo_grafts_keep_true_parents(r)'
with the existing repository context 'r'. In builtin/pack-objects.c,
bind the '--keep-true-parents' option directly to
'cfg->grafts_keep_true_parents'.
When accessing 'repo_config_values' in cmd_pack_objects, use a NULL
guard 'repo ? repo : the_repository'. This ensures that invocations
without a repository context (e.g. 'git pack-objects -h' outside a repo)
do not dereference a NULL pointer.
Signed-off-by: Yuvraj Singh Chauhan <ysinghcin@gmail.com>
---
builtin/pack-objects.c | 6 +++---
commit.c | 2 +-
environment.c | 9 ++++++++-
environment.h | 5 +++--
4 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 65c2ad9a86..0d213dead1 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -5120,7 +5120,7 @@ static int parse_stdin_packs_mode(const struct option *opt, const char *arg,
int cmd_pack_objects(int argc,
const char **argv,
const char *prefix,
- struct repository *repo UNUSED)
+ struct repository *repo)
{
int use_internal_rev_list = 0;
int all_progress_implied = 0;
@@ -5131,7 +5131,7 @@ int cmd_pack_objects(int argc,
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
struct list_objects_filter_options filter_options =
LIST_OBJECTS_FILTER_INIT;
- struct repo_config_values *cfg = repo_config_values(the_repository);
+ struct repo_config_values *cfg = repo_config_values(repo ? repo : the_repository);
struct option pack_objects_options[] = {
OPT_CALLBACK_F('q', "quiet", &progress, NULL,
@@ -5215,7 +5215,7 @@ int cmd_pack_objects(int argc,
N_("ignore this pack")),
OPT_INTEGER(0, "compression", &cfg->pack_compression_level,
N_("pack compression level")),
- OPT_BOOL(0, "keep-true-parents", &grafts_keep_true_parents,
+ OPT_BOOL(0, "keep-true-parents", &cfg->grafts_keep_true_parents,
N_("do not hide commits by grafts")),
OPT_BOOL(0, "use-bitmap-index", &use_bitmap_index,
N_("use a bitmap index if available to speed up counting objects")),
diff --git a/commit.c b/commit.c
index ad26f0b40a..5a7ae0696c 100644
--- a/commit.c
+++ b/commit.c
@@ -566,7 +566,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
* The clone is shallow if nr_parent < 0, and we must
* not traverse its real parents even when we unhide them.
*/
- if (graft && (graft->nr_parent < 0 || !grafts_keep_true_parents))
+ if (graft && (graft->nr_parent < 0 || !repo_grafts_keep_true_parents(r)))
continue;
new_parent = lookup_commit(r, &parent);
if (!new_parent)
diff --git a/environment.c b/environment.c
index 76ee65e62b..53e8ab1255 100644
--- a/environment.c
+++ b/environment.c
@@ -56,7 +56,6 @@ char *check_roundtrip_encoding;
#ifndef OBJECT_CREATION_MODE
#define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
#endif
-int grafts_keep_true_parents;
unsigned long pack_size_limit_cfg;
#ifndef PROTECT_HFS_DEFAULT
@@ -152,6 +151,13 @@ int repo_has_symlinks(struct repository *repo)
: platform_has_symlinks();
}
+int repo_grafts_keep_true_parents(struct repository *repo)
+{
+ return repo->initialized
+ ? repo_config_values(repo)->grafts_keep_true_parents
+ : 0;
+}
+
const char *repo_excludes_file(struct repository *repo)
{
struct repo_config_values *cfg = repo_config_values(repo);
@@ -770,6 +776,7 @@ void repo_config_values_init(struct repo_config_values *cfg)
cfg->core_sparse_checkout_cone = 0;
cfg->sparse_expect_files_outside_of_patterns = 0;
cfg->warn_on_object_refname_ambiguity = 1;
+ cfg->grafts_keep_true_parents = 0;
}
void repo_config_values_clear(struct repo_config_values *cfg)
diff --git a/environment.h b/environment.h
index e7ec5b0437..b9f31a0aef 100644
--- a/environment.h
+++ b/environment.h
@@ -139,6 +139,7 @@ struct repo_config_values {
int ignore_case;
int trust_executable_bit;
int has_symlinks;
+ int grafts_keep_true_parents;
/* section "sparse" config values */
int sparse_expect_files_outside_of_patterns;
@@ -193,6 +194,8 @@ int repo_trust_executable_bit(struct repository *repo);
int repo_has_symlinks(struct repository *repo);
+int repo_grafts_keep_true_parents(struct repository *repo);
+
const char *repo_excludes_file(struct repository *repo);
void repo_config_values_init(struct repo_config_values *cfg);
@@ -235,8 +238,6 @@ extern int minimum_abbrev, default_abbrev;
extern int assume_unchanged;
extern unsigned long pack_size_limit_cfg;
-extern int grafts_keep_true_parents;
-
const char *get_log_output_encoding(void);
const char *get_commit_output_encoding(void);
--
2.43.0
next reply other threads:[~2026-09-02 11:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 11:30 Yuvraj Singh Chauhan [this message]
2026-09-02 11:30 ` [PATCH 2/2] pack-objects: add tests for keep-true-parents Yuvraj Singh Chauhan
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=20260902113109.686014-1-ysinghcin@gmail.com \
--to=ysinghcin@gmail.com \
--cc=git@vger.kernel.org \
/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.