Merge branch 'dk/version-gen-gitdir'
[git/mingw.git] / test-revision-walking.c
blob3ade02c72d8801a4965431518f796df4835dc473
1 /*
2 * test-revision-walking.c: test revision walking API.
4 * (C) 2012 Heiko Voigt <hvoigt@hvoigt.net>
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 */
11 #include "cache.h"
12 #include "commit.h"
13 #include "diff.h"
14 #include "revision.h"
16 static void print_commit(struct commit *commit)
18 struct strbuf sb = STRBUF_INIT;
19 struct pretty_print_context ctx = {0};
20 ctx.date_mode = DATE_NORMAL;
21 format_commit_message(commit, " %m %s", &sb, &ctx);
22 printf("%s\n", sb.buf);
23 strbuf_release(&sb);
26 static int run_revision_walk(void)
28 struct rev_info rev;
29 struct commit *commit;
30 const char *argv[] = {NULL, "--all", NULL};
31 int argc = ARRAY_SIZE(argv) - 1;
32 int got_revision = 0;
34 init_revisions(&rev, NULL);
35 setup_revisions(argc, argv, &rev, NULL);
36 if (prepare_revision_walk(&rev))
37 die("revision walk setup failed");
39 while ((commit = get_revision(&rev)) != NULL) {
40 print_commit(commit);
41 got_revision = 1;
44 reset_revision_walk();
45 return got_revision;
48 int main(int argc, char **argv)
50 if (argc < 2)
51 return 1;
53 if (!strcmp(argv[1], "run-twice")) {
54 printf("1st\n");
55 if (!run_revision_walk())
56 return 1;
57 printf("2nd\n");
58 if (!run_revision_walk())
59 return 1;
61 return 0;
64 fprintf(stderr, "check usage\n");
65 return 1;