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

[PATCH 07/19] commit: allow parse_commit* to handle arbitrary repositories

From
Stefan Beller <sbeller@google.com>
Date
Oct 16, 2018, 23:35 UTC
Message-ID
<20181016233550.251311-8-sbeller@google.com>
In-Reply-To
<20181016233550.251311-1-sbeller@google.com>

Just like the previous commit, parse_commit and friends are used a lot and are found in new patches, so we cannot change their signature easily.

Re-introduce these function prefixed with 'repo_' that take a repository argument and keep the original as a shallow macro.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 commit.c                                | 18 +++++++++++-------
 commit.h                                | 17 +++++++++++++----
 contrib/coccinelle/the_repository.cocci | 24 ++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/commit.c b/commit.c
index 5781f9bc67..fe942754e2 100644
--- a/commit.c
+++ b/commit.c
@@ -443,7 +443,10 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
 	return 0;
 }
 
-int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_commit_graph)
+int repo_parse_commit_internal(struct repository *r,
+			       struct commit *item,
+			       int quiet_on_missing,
+			       int use_commit_graph)
 {
 	enum object_type type;
 	void *buffer;
@@ -454,9 +457,9 @@ int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_com
 		return -1;
 	if (item->object.parsed)
 		return 0;
-	if (use_commit_graph && parse_commit_in_graph(the_repository, item))
+	if (use_commit_graph && parse_commit_in_graph(r, item))
 		return 0;
-	buffer = read_object_file(&item->object.oid, &type, &size);
+	buffer = repo_read_object_file(r, &item->object.oid, &type, &size);
 	if (!buffer)
 		return quiet_on_missing ? -1 :
 			error("Could not read %s",
@@ -467,18 +470,19 @@ int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_com
 			     oid_to_hex(&item->object.oid));
 	}
 
-	ret = parse_commit_buffer(the_repository, item, buffer, size, 0);
+	ret = parse_commit_buffer(r, item, buffer, size, 0);
 	if (save_commit_buffer && !ret) {
-		set_commit_buffer(the_repository, item, buffer, size);
+		set_commit_buffer(r, item, buffer, size);
 		return 0;
 	}
 	free(buffer);
 	return ret;
 }
 
-int parse_commit_gently(struct commit *item, int quiet_on_missing)
+int repo_parse_commit_gently(struct repository *r,
+			     struct commit *item, int quiet_on_missing)
 {
-	return parse_commit_internal(item, quiet_on_missing, 1);
+	return repo_parse_commit_internal(r, item, quiet_on_missing, 1);
 }
 
 void parse_commit_or_die(struct commit *item)
diff --git a/commit.h b/commit.h
index e2c99d9b04..58a0c5409b 100644
--- a/commit.h
+++ b/commit.h
@@ -79,12 +79,21 @@ struct commit *lookup_commit_reference_by_name(const char *name);
 struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name);
 
 int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size, int check_graph);
-int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_commit_graph);
-int parse_commit_gently(struct commit *item, int quiet_on_missing);
-static inline int parse_commit(struct commit *item)
+int repo_parse_commit_internal(struct repository *r, struct commit *item,
+			       int quiet_on_missing, int use_commit_graph);
+int repo_parse_commit_gently(struct repository *r,
+			     struct commit *item,
+			     int quiet_on_missing);
+static inline int repo_parse_commit(struct repository *r, struct commit *item)
 {
-	return parse_commit_gently(item, 0);
+	return repo_parse_commit_gently(r, item, 0);
 }
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define parse_commit_internal(item, quiet, use) repo_parse_commit_internal(the_repository, item, quiet, use)
+#define parse_commit_gently(item, quiet) repo_parse_commit_gently(the_repository, item, quiet)
+#define parse_commit(item) repo_parse_commit(the_repository, item)
+#endif
+
 void parse_commit_or_die(struct commit *item);
 
 struct buffer_slab;
diff --git a/contrib/coccinelle/the_repository.cocci b/contrib/coccinelle/the_repository.cocci
index 46f3a1b23a..b185fe0a1d 100644
--- a/contrib/coccinelle/the_repository.cocci
+++ b/contrib/coccinelle/the_repository.cocci
@@ -40,3 +40,27 @@ expression F;
 - has_object_file_with_flags(
 + repo_has_object_file_with_flags(the_repository,
   E)
+
+@@
+expression E;
+expression F;
+expression G;
+@@
+- parse_commit_internal(
++ repo_parse_commit_internal(the_repository,
+  E, F, G)
+
+@@
+expression E;
+expression F;
+@@
+- parse_commit_gently(
++ repo_parse_commit_gently(the_repository,
+  E, F)
+
+@@
+expression E;
+@@
+- parse_commit(
++ repo_parse_commit(the_repository,
+  E)
-- 
2.19.0
Previous: Stefan BellerNext: Stefan Beller
Message 8 of 46 in “Bring more repository handles into our code base”
  1. 00/19 Bring more repository handles into our code baseStefan Beller, Oct 16, 2018
  2. 01/19 sha1_file: allow read_object to read objects in arbitrary repositoriesStefan Beller, Oct 16, 2018
  3. 02/19 packfile: allow has_packed_and_bad to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  4. 03/19 object-store: allow read_object_file_extended to read from arbitrary repositoriesStefan Beller, Oct 16, 2018
  5. 04/19 object-store: prepare read_object_file to deal with arbitrary repositoriesStefan Beller, Oct 16, 2018
  6. 05/19 object-store: prepare has_{sha1, object}_file[_with_flags] to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  7. 06/19 object: parse_object to honor its repository argumentStefan Beller, Oct 16, 2018
  8. 07/19 commit: allow parse_commit* to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  9. 08/19 commit-reach.c: allow paint_down_to_common to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  10. 09/19 commit-reach.c: allow merge_bases_many to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  11. 10/19 commit-reach.c: allow remove_redundant to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  12. 11/19 commit-reach.c: allow get_merge_bases_many_0 to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  13. 12/19 commit-reach: prepare get_merge_bases to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  14. 13/19 commit-reach: prepare in_merge_bases[_many] to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  15. 14/19 commit: prepare get_commit_buffer to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  16. 15/19 commit: prepare repo_unuse_commit_buffer to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  17. 16/19 commit: prepare logmsg_reencode to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  18. 17/19 pretty: prepare format_commit_message to handle arbitrary repositoriesStefan Beller, Oct 16, 2018
  19. 18/19 submodule: use submodule repos for object lookupStefan Beller, Oct 16, 2018
  20. Jonathan TanOct 19, 2018
  21. SZEDER GáborOct 25, 2018
  22. Derrick StoleeOct 31, 2018
  23. Stefan BellerNov 1, 2018
  24. 19/19 submodule: don't add submodule as odb for pushStefan Beller, Oct 16, 2018
  25. Jonathan TanOct 19, 2018
  26. Derrick StoleeOct 17, 2018
  27. Stefan BellerOct 17, 2018
  28. 0/2 Bring the_repository into cmd_fooStefan Beller, Oct 18, 2018
  29. 1/2 repository: have get_the_repository() to remove the_repository dependencyStefan Beller, Oct 18, 2018
  30. 2/2 builtin/merge-base.c: do not rely on the_repository any moreStefan Beller, Oct 18, 2018
  31. Jonathan TanOct 18, 2018
  32. Stefan BellerOct 18, 2018
  33. Junio C HamanoOct 19, 2018
  34. New semantic patches vs. in-flight topics [was: Re: [PATCH 00/19] Bring more repository handles into our code base]SZEDER Gábor, Oct 22, 2018
  35. Stefan BellerOct 22, 2018
  36. SZEDER GáborOct 25, 2018
  37. Stefan BellerOct 25, 2018
  38. Junio C HamanoOct 22, 2018
  39. Stefan BellerOct 23, 2018
  40. Junio C HamanoOct 23, 2018
  41. Junio C HamanoOct 23, 2018
  42. Carlo ArenasOct 23, 2018
  43. Junio C HamanoOct 23, 2018
  44. Stefan BellerOct 23, 2018
  45. Junio C HamanoOct 24, 2018
  46. Jeff KingOct 25, 2018

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.