commit: add for_each_mergetag()
In the same way as there is for_each_ref() to iterate on refs, for_each_mergetag() allows the caller to iterate on the mergetags of a given commit. Use it to rewrite show_mergetag() used in "git log". Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Jul 7, 2014 at 08:35 UTC
063da62b02aeafe58fdacce0ea48c0761b06df60
3 files changed
+22
-11
commit.c
+13
@@ -1316,6 +1316,19 @@ struct commit_extra_header *read_commit_extra_headers(struct commit *commit,
1316
return extra;
1317
}
1318
1319
+void for_each_mergetag(each_mergetag_fn fn, struct commit *commit, void *data)
1320
+{
1321
+ struct commit_extra_header *extra, *to_free;
1322
+
1323
+ to_free = read_commit_extra_headers(commit, NULL);
1324
+ for (extra = to_free; extra; extra = extra->next) {
1325
+ if (strcmp(extra->key, "mergetag"))
1326
+ continue; /* not a merge tag */
1327
+ fn(commit, extra, data);
1328
+ }
1329
+ free_commit_extra_headers(to_free);
1330
+}
1331
+
1332
static inline int standard_header_field(const char *field, size_t len)
1333
{
1334
return ((len == 4 && !memcmp(field, "tree ", 5)) ||
commit.h
+5
@@ -312,6 +312,11 @@ extern struct commit_extra_header *read_commit_extra_headers(struct commit *, co
312
313
extern void free_commit_extra_headers(struct commit_extra_header *extra);
314
315
+typedef void (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra,
316
+ void *cb_data);
317
+
318
+extern void for_each_mergetag(each_mergetag_fn fn, struct commit *commit, void *data);
319
+
320
struct merge_remote_desc {
321
struct object *obj; /* the named object, could be a tag */
322
const char *name;
log-tree.c
+4
-11
@@ -413,10 +413,11 @@ static int is_common_merge(const struct commit *commit)
413
&& !commit->parents->next->next);
414
}
415
416
-static void show_one_mergetag(struct rev_info *opt,
416
+static void show_one_mergetag(struct commit *commit,
417
struct commit_extra_header *extra,
418
- struct commit *commit)
418
+ void *data)
419
{
420
+ struct rev_info *opt = (struct rev_info *)data;
421
unsigned char sha1[20];
422
struct tag *tag;
423
struct strbuf verify_message;
@@ -463,15 +464,7 @@ static void show_one_mergetag(struct rev_info *opt,
464
465
static void show_mergetag(struct rev_info *opt, struct commit *commit)
466
{
466
- struct commit_extra_header *extra, *to_free;
467
-
468
- to_free = read_commit_extra_headers(commit, NULL);
469
- for (extra = to_free; extra; extra = extra->next) {
470
- if (strcmp(extra->key, "mergetag"))
471
- continue; /* not a merge tag */
472
- show_one_mergetag(opt, extra, commit);
473
- }
474
- free_commit_extra_headers(to_free);
467
+ for_each_mergetag(show_one_mergetag, commit, opt);
468
}
469
470
void show_log(struct rev_info *opt)