]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-revision-walking.c
Merge branch 'mp/rebase-label-length-limit' into maint-2.42
[thirdparty/git.git] / t / helper / test-revision-walking.c
CommitLineData
bcc0a3ea
HV
1/*
2 * test-revision-walking.c: test revision walking API.
3 *
4 * (C) 2012 Heiko Voigt <hvoigt@hvoigt.net>
5 *
6 * This code is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
77d4b8c8 11#include "test-tool.h"
bcc0a3ea
HV
12#include "commit.h"
13#include "diff.h"
df6e8744 14#include "repository.h"
bcc0a3ea 15#include "revision.h"
e38da487 16#include "setup.h"
bcc0a3ea
HV
17
18static void print_commit(struct commit *commit)
19{
20 struct strbuf sb = STRBUF_INIT;
21 struct pretty_print_context ctx = {0};
a5481a6c 22 ctx.date_mode.type = DATE_NORMAL;
bab82164
ÆAB
23 repo_format_commit_message(the_repository, commit, " %m %s", &sb,
24 &ctx);
bcc0a3ea
HV
25 printf("%s\n", sb.buf);
26 strbuf_release(&sb);
27}
28
29static int run_revision_walk(void)
30{
31 struct rev_info rev;
32 struct commit *commit;
33 const char *argv[] = {NULL, "--all", NULL};
34 int argc = ARRAY_SIZE(argv) - 1;
35 int got_revision = 0;
36
2abf3503 37 repo_init_revisions(the_repository, &rev, NULL);
bcc0a3ea
HV
38 setup_revisions(argc, argv, &rev, NULL);
39 if (prepare_revision_walk(&rev))
40 die("revision walk setup failed");
41
42 while ((commit = get_revision(&rev)) != NULL) {
43 print_commit(commit);
44 got_revision = 1;
45 }
46
47 reset_revision_walk();
2108fe4a 48 release_revisions(&rev);
bcc0a3ea
HV
49 return got_revision;
50}
51
77d4b8c8 52int cmd__revision_walking(int argc, const char **argv)
bcc0a3ea
HV
53{
54 if (argc < 2)
55 return 1;
56
11e6b3f6
JK
57 setup_git_directory();
58
bcc0a3ea
HV
59 if (!strcmp(argv[1], "run-twice")) {
60 printf("1st\n");
61 if (!run_revision_walk())
62 return 1;
63 printf("2nd\n");
64 if (!run_revision_walk())
65 return 1;
66
67 return 0;
68 }
69
70 fprintf(stderr, "check usage\n");
71 return 1;
72}