]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-revision-walking.c
rebase: allow overriding the maximal length of the generated labels
[thirdparty/git.git] / t / helper / test-revision-walking.c
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
11 #include "test-tool.h"
12 #include "commit.h"
13 #include "diff.h"
14 #include "revision.h"
15 #include "setup.h"
16
17 static void print_commit(struct commit *commit)
18 {
19 struct strbuf sb = STRBUF_INIT;
20 struct pretty_print_context ctx = {0};
21 ctx.date_mode.type = DATE_NORMAL;
22 repo_format_commit_message(the_repository, commit, " %m %s", &sb,
23 &ctx);
24 printf("%s\n", sb.buf);
25 strbuf_release(&sb);
26 }
27
28 static int run_revision_walk(void)
29 {
30 struct rev_info rev;
31 struct commit *commit;
32 const char *argv[] = {NULL, "--all", NULL};
33 int argc = ARRAY_SIZE(argv) - 1;
34 int got_revision = 0;
35
36 repo_init_revisions(the_repository, &rev, NULL);
37 setup_revisions(argc, argv, &rev, NULL);
38 if (prepare_revision_walk(&rev))
39 die("revision walk setup failed");
40
41 while ((commit = get_revision(&rev)) != NULL) {
42 print_commit(commit);
43 got_revision = 1;
44 }
45
46 reset_revision_walk();
47 release_revisions(&rev);
48 return got_revision;
49 }
50
51 int cmd__revision_walking(int argc, const char **argv)
52 {
53 if (argc < 2)
54 return 1;
55
56 setup_git_directory();
57
58 if (!strcmp(argv[1], "run-twice")) {
59 printf("1st\n");
60 if (!run_revision_walk())
61 return 1;
62 printf("2nd\n");
63 if (!run_revision_walk())
64 return 1;
65
66 return 0;
67 }
68
69 fprintf(stderr, "check usage\n");
70 return 1;
71 }