git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 7/9] archive: remove global repository from archive_args

From
HGHeather Lapointe via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 17, 2022, 02:23 UTC
Message-ID
<2443c9b1b6efce4340f01930c179d2fafbc5bbb3.1665973401.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1359.v3.git.git.1665973401.gitgitgadget@gmail.com>
From: Heather Lapointe <alpha@alphaservcomputing.solutions>

Remove archive_args.repo to ensure all functions are using local repository instances. Since all functions now have access to repo, this access isn't needed anymore.

The main issue is that submodules do not use the same repo as the subproject repo that is being passed around contextually.

Signed-off-by: Heather Lapointe <alpha@alphaservcomputing.solutions>
---
 archive.c | 51 +++++++++++++++++++++++++++++----------------------
 archive.h |  1 -
 2 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/archive.c b/archive.c
index 2cca7bc5c8a..34549d849f1 100644
--- a/archive.c
+++ b/archive.c
@@ -36,7 +36,9 @@ void init_archivers(void)
 	init_zip_archiver();
 }
 
-static void format_subst(const struct commit *commit,
+static void format_subst(
+			 struct repository *repo,
+			 const struct commit *commit,
 			 const char *src, size_t len,
 			 struct strbuf *buf, struct pretty_print_context *ctx)
 {
@@ -59,7 +61,7 @@ static void format_subst(const struct commit *commit,
 		strbuf_add(&fmt, b + 8, c - b - 8);
 
 		strbuf_add(buf, src, b - src);
-		format_commit_message(commit, fmt.buf, buf, ctx);
+		repo_format_commit_message(repo, commit, fmt.buf, buf, ctx);
 		len -= c + 1 - src;
 		src  = c + 1;
 	}
@@ -68,7 +70,9 @@ static void format_subst(const struct commit *commit,
 	free(to_free);
 }
 
-static void *object_file_to_archive(const struct archiver_args *args,
+static void *object_file_to_archive(
+				    struct repository *repo,
+				    const struct archiver_args *args,
 				    const char *path,
 				    const struct object_id *oid,
 				    unsigned int mode,
@@ -84,15 +88,15 @@ static void *object_file_to_archive(const struct archiver_args *args,
 			       (args->tree ? &args->tree->object.oid : NULL), oid);
 
 	path += args->baselen;
-	buffer = read_object_file(oid, type, sizep);
+	buffer = repo_read_object_file(repo, oid, type, sizep);
 	if (buffer && S_ISREG(mode)) {
 		struct strbuf buf = STRBUF_INIT;
 		size_t size = 0;
 
 		strbuf_attach(&buf, buffer, *sizep, *sizep + 1);
-		convert_to_working_tree(args->repo->index, path, buf.buf, buf.len, &buf, &meta);
+		convert_to_working_tree(repo->index, path, buf.buf, buf.len, &buf, &meta);
 		if (commit)
-			format_subst(commit, buf.buf, buf.len, &buf, args->pretty_ctx);
+			format_subst(repo, commit, buf.buf, buf.len, &buf, args->pretty_ctx);
 		buffer = strbuf_detach(&buf, &size);
 		*sizep = size;
 	}
@@ -186,7 +190,7 @@ static int write_archive_entry(
 	    size > big_file_threshold)
 		return write_entry(repo, args, oid, path.buf, path.len, mode, NULL, size);
 
-	buffer = object_file_to_archive(args, path.buf, oid, mode, &type, &size);
+	buffer = object_file_to_archive(repo, args, path.buf, oid, mode, &type, &size);
 	if (!buffer)
 		return error(_("cannot read '%s'"), oid_to_hex(oid));
 	err = write_entry(repo, args, oid, path.buf, path.len, mode, buffer, size);
@@ -313,8 +317,8 @@ int write_archive_entries(
 		memset(&opts, 0, sizeof(opts));
 		opts.index_only = 1;
 		opts.head_idx = -1;
-		opts.src_index = args->repo->index;
-		opts.dst_index = args->repo->index;
+		opts.src_index = repo->index;
+		opts.dst_index = repo->index;
 		opts.fn = oneway_merge;
 		init_tree_desc(&t, args->tree->buffer, args->tree->size);
 		if (unpack_trees(1, &t, &opts))
@@ -322,7 +326,7 @@ int write_archive_entries(
 		git_attr_set_direction(GIT_ATTR_INDEX);
 	}
 
-	err = read_tree(args->repo, args->tree,
+	err = read_tree(repo, args->tree,
 			&args->pathspec,
 			queue_or_write_archive_entry,
 			&context);
@@ -412,7 +416,7 @@ static int reject_entry(
 	return ret;
 }
 
-static int path_exists(struct archiver_args *args, const char *path)
+static int path_exists(struct repository *repo, struct archiver_args *args, const char *path)
 {
 	const char *paths[] = { path, NULL };
 	struct path_exists_context ctx;
@@ -421,14 +425,16 @@ static int path_exists(struct archiver_args *args, const char *path)
 	ctx.args = args;
 	parse_pathspec(&ctx.pathspec, 0, 0, "", paths);
 	ctx.pathspec.recursive = 1;
-	ret = read_tree(args->repo, args->tree,
+	ret = read_tree(repo, args->tree,
 			&ctx.pathspec,
 			reject_entry, &ctx);
 	clear_pathspec(&ctx.pathspec);
 	return ret != 0;
 }
 
-static void parse_pathspec_arg(const char **pathspec,
+static void parse_pathspec_arg(
+		struct repository *repo,
+		const char **pathspec,
 		struct archiver_args *ar_args)
 {
 	/*
@@ -442,14 +448,16 @@ static void parse_pathspec_arg(const char **pathspec,
 	ar_args->pathspec.recursive = 1;
 	if (pathspec) {
 		while (*pathspec) {
-			if (**pathspec && !path_exists(ar_args, *pathspec))
+			if (**pathspec && !path_exists(repo, ar_args, *pathspec))
 				die(_("pathspec '%s' did not match any files"), *pathspec);
 			pathspec++;
 		}
 	}
 }
 
-static void parse_treeish_arg(const char **argv,
+static void parse_treeish_arg(
+		struct repository *repo,
+		const char **argv,
 		struct archiver_args *ar_args, const char *prefix,
 		int remote)
 {
@@ -475,7 +483,7 @@ static void parse_treeish_arg(const char **argv,
 	if (get_oid(name, &oid))
 		die(_("not a valid object name: %s"), name);
 
-	commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1);
+	commit = lookup_commit_reference_gently(repo, &oid, 1);
 	if (commit) {
 		commit_oid = &commit->object.oid;
 		archive_time = commit->date;
@@ -484,7 +492,7 @@ static void parse_treeish_arg(const char **argv,
 		archive_time = time(NULL);
 	}
 
-	tree = parse_tree_indirect(&oid);
+	tree = repo_parse_tree_indirect(repo, &oid);
 	if (!tree)
 		die(_("not a tree object: %s"), oid_to_hex(&oid));
 
@@ -493,14 +501,14 @@ static void parse_treeish_arg(const char **argv,
 		unsigned short mode;
 		int err;
 
-		err = get_tree_entry(ar_args->repo,
+		err = get_tree_entry(repo,
 				     &tree->object.oid,
 				     prefix, &tree_oid,
 				     &mode);
 		if (err || !S_ISDIR(mode))
 			die(_("current working directory is untracked"));
 
-		tree = parse_tree_indirect(&tree_oid);
+		tree = repo_parse_tree_indirect(repo, &tree_oid);
 	}
 	ar_args->refname = ref;
 	ar_args->tree = tree;
@@ -701,7 +709,6 @@ int write_archive(int argc, const char **argv, const char *prefix,
 	ctx.abbrev = DEFAULT_ABBREV;
 	ctx.describe_status = &describe_status;
 	args.pretty_ctx = &ctx;
-	args.repo = repo;
 	args.prefix = prefix;
 	string_list_init_dup(&args.extra_files);
 	argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote);
@@ -714,8 +721,8 @@ int write_archive(int argc, const char **argv, const char *prefix,
 		setup_git_directory();
 	}
 
-	parse_treeish_arg(argv, &args, prefix, remote);
-	parse_pathspec_arg(argv + 1, &args);
+	parse_treeish_arg(repo, argv, &args, prefix, remote);
+	parse_pathspec_arg(repo, argv + 1, &args);
 
 	rc = ar->write_archive(ar, repo, &args);
 
diff --git a/archive.h b/archive.h
index bfbbd3274bd..540a3b12130 100644
--- a/archive.h
+++ b/archive.h
@@ -8,7 +8,6 @@ struct repository;
 struct pretty_print_context;
 
 struct archiver_args {
-	struct repository *repo;
 	char *refname;
 	const char *prefix;
 	const char *base;
-- 
gitgitgadget
Previous: Phillip WoodNext: Heather Lapointe via GitGitGadget
Message 29 of 48 in “archive: add --recurse-submodules to git-archive command”
  1. archive: add --recurse-submodules to git-archive commandHeather Lapointe via GitGitGadget, Oct 12, 2022
  2. 0/2 archive: Add --recurse-submodules to git-archive commandHeather Lapointe via GitGitGadget, Oct 13, 2022
  3. 2/2 archive: fix a case of submodule in submodule traversalAlphadelta14 via GitGitGadget, Oct 13, 2022
  4. 1/2 archive: add --recurse-submodules to git-archive commandAlphadelta14 via GitGitGadget, Oct 13, 2022
  5. René ScharfeOct 13, 2022
  6. Heather LapointeOct 13, 2022
  7. René ScharfeOct 13, 2022
  8. Heather LapointeOct 13, 2022
  9. René ScharfeOct 14, 2022
  10. 0/9 archive: Add --recurse-submodules to git-archive commandHeather Lapointe via GitGitGadget, Oct 17, 2022
  11. 1/9 tree: do not use the_repository for tree traversal methods.Alphadelta14 via GitGitGadget, Oct 17, 2022
  12. Junio C HamanoOct 17, 2022
  13. Glen ChooOct 26, 2022
  14. Jonathan TanOct 27, 2022
  15. Junio C HamanoOct 27, 2022
  16. 2/9 tree: update cases to use repo_ tree methodsHeather Lapointe via GitGitGadget, Oct 17, 2022
  17. 3/9 tree: increase test coverage for tree.cHeather Lapointe via GitGitGadget, Oct 17, 2022
  18. Phillip WoodOct 17, 2022
  19. Junio C HamanoOct 17, 2022
  20. Jonathan TanOct 27, 2022
  21. 4/9 tree: handle submodule case for read_tree_at properlyHeather Lapointe via GitGitGadget, Oct 17, 2022
  22. Phillip WoodOct 17, 2022
  23. Junio C HamanoOct 17, 2022
  24. Glen ChooOct 26, 2022
  25. Jonathan TanOct 27, 2022
  26. 5/9 tree: add repository parameter to read_tree_fn_tHeather Lapointe via GitGitGadget, Oct 17, 2022
  27. 6/9 archive: pass repo objects to write_archive handlersHeather Lapointe via GitGitGadget, Oct 17, 2022
  28. Phillip WoodOct 17, 2022
  29. 7/9 archive: remove global repository from archive_argsHeather Lapointe via GitGitGadget, Oct 17, 2022
  30. 9/9 archive: add tests for git archive --recurse-submodulesHeather Lapointe via GitGitGadget, Oct 17, 2022
  31. Jonathan TanOct 27, 2022
  32. Glen ChooOct 27, 2022
  33. Ævar Arnfjörð BjarmasonOct 28, 2022
  34. 8/9 archive: add --recurse-submodules to git-archive commandHeather Lapointe via GitGitGadget, Oct 17, 2022
  35. Glen ChooOct 26, 2022
  36. René ScharfeOct 27, 2022
  37. Glen ChooOct 27, 2022
  38. Glen ChooOct 27, 2022
  39. Glen ChooOct 27, 2022
  40. Phillip WoodOct 17, 2022
  41. Junio C HamanoOct 18, 2022
  42. Heather LapointeOct 18, 2022
  43. Junio C HamanoOct 19, 2022
  44. Junio C HamanoOct 19, 2022
  45. Junio C HamanoOct 20, 2022
  46. Junio C HamanoOct 21, 2022
  47. Glen ChooOct 26, 2022
  48. Heather LapointeOct 28, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.