Thread (2 messages) flat view 2 messages, 1 author, 5d ago
COOLING5d

[PATCH 1/2] environment: move grafts_keep_true_parents into repo_config_values

From: Yuvraj Singh Chauhan <hidden>
Date: 2026-09-02 11:31:16
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help