commit: allow parse_commit* to handle any repo

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>

Stefan Beller committed Nov 13, 2018 at 16:12 UTC 9e5252abd1239215c36f86704e84ba06dc30583f
3 files changed +48 -11
commit.c
+11 -7
@@ -443,7 +443,10 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
443 return 0;
444 }
445
446 -int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_commit_graph)
446 +int repo_parse_commit_internal(struct repository *r,
447 + struct commit *item,
448 + int quiet_on_missing,
449 + int use_commit_graph)
450 {
451 enum object_type type;
452 void *buffer;
@@ -454,9 +457,9 @@ int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_com
457 return -1;
458 if (item->object.parsed)
459 return 0;
457 - if (use_commit_graph && parse_commit_in_graph(the_repository, item))
460 + if (use_commit_graph && parse_commit_in_graph(r, item))
461 return 0;
459 - buffer = read_object_file(&item->object.oid, &type, &size);
462 + buffer = repo_read_object_file(r, &item->object.oid, &type, &size);
463 if (!buffer)
464 return quiet_on_missing ? -1 :
465 error("Could not read %s",
@@ -467,18 +470,19 @@ int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_com
470 oid_to_hex(&item->object.oid));
471 }
472
470 - ret = parse_commit_buffer(the_repository, item, buffer, size, 0);
473 + ret = parse_commit_buffer(r, item, buffer, size, 0);
474 if (save_commit_buffer && !ret) {
472 - set_commit_buffer(the_repository, item, buffer, size);
475 + set_commit_buffer(r, item, buffer, size);
476 return 0;
477 }
478 free(buffer);
479 return ret;
480 }
481
479 -int parse_commit_gently(struct commit *item, int quiet_on_missing)
482 +int repo_parse_commit_gently(struct repository *r,
483 + struct commit *item, int quiet_on_missing)
484 {
481 - return parse_commit_internal(item, quiet_on_missing, 1);
485 + return repo_parse_commit_internal(r, item, quiet_on_missing, 1);
486 }
487
488 void parse_commit_or_die(struct commit *item)
commit.h
+13 -4
@@ -79,12 +79,21 @@ struct commit *lookup_commit_reference_by_name(const char *name);
79 struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name);
80
81 int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size, int check_graph);
82 -int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_commit_graph);
83 -int parse_commit_gently(struct commit *item, int quiet_on_missing);
84 -static inline int parse_commit(struct commit *item)
82 +int repo_parse_commit_internal(struct repository *r, struct commit *item,
83 + int quiet_on_missing, int use_commit_graph);
84 +int repo_parse_commit_gently(struct repository *r,
85 + struct commit *item,
86 + int quiet_on_missing);
87 +static inline int repo_parse_commit(struct repository *r, struct commit *item)
88 {
86 - return parse_commit_gently(item, 0);
89 + return repo_parse_commit_gently(r, item, 0);
90 }
91 +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
92 +#define parse_commit_internal(item, quiet, use) repo_parse_commit_internal(the_repository, item, quiet, use)
93 +#define parse_commit_gently(item, quiet) repo_parse_commit_gently(the_repository, item, quiet)
94 +#define parse_commit(item) repo_parse_commit(the_repository, item)
95 +#endif
96 +
97 void parse_commit_or_die(struct commit *item);
98
99 struct buffer_slab;
contrib/coccinelle/the_repository.pending.cocci
+24
@@ -40,3 +40,27 @@ expression F;
40 - has_object_file_with_flags(
41 + repo_has_object_file_with_flags(the_repository,
42 E)
43 +
44 +@@
45 +expression E;
46 +expression F;
47 +expression G;
48 +@@
49 +- parse_commit_internal(
50 ++ repo_parse_commit_internal(the_repository,
51 + E, F, G)
52 +
53 +@@
54 +expression E;
55 +expression F;
56 +@@
57 +- parse_commit_gently(
58 ++ repo_parse_commit_gently(the_repository,
59 + E, F)
60 +
61 +@@
62 +expression E;
63 +@@
64 +- parse_commit(
65 ++ repo_parse_commit(the_repository,
66 + E)