Sync with 'maint' for Windows+VS build jobs used at CI
[git.git] / t / helper / test-revision-walking.c
blob071f5bd1e21974ba2104a76305a5156ee2c2961f
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 #define USE_THE_REPOSITORY_VARIABLE
13 #include "test-tool.h"
14 #include "commit.h"
15 #include "diff.h"
16 #include "repository.h"
17 #include "revision.h"
18 #include "setup.h"
20 static void print_commit(struct commit *commit)
22 struct strbuf sb = STRBUF_INIT;
23 struct pretty_print_context ctx = {0};
24 ctx.date_mode.type = DATE_NORMAL;
25 repo_format_commit_message(the_repository, commit, " %m %s", &sb,
26 &ctx);
27 printf("%s\n", sb.buf);
28 strbuf_release(&sb);
31 static int run_revision_walk(void)
33 struct rev_info rev;
34 struct commit *commit;
35 const char *argv[] = {NULL, "--all", NULL};
36 int argc = ARRAY_SIZE(argv) - 1;
37 int got_revision = 0;
39 repo_init_revisions(the_repository, &rev, NULL);
40 setup_revisions(argc, argv, &rev, NULL);
41 if (prepare_revision_walk(&rev))
42 die("revision walk setup failed");
44 while ((commit = get_revision(&rev)) != NULL) {
45 print_commit(commit);
46 got_revision = 1;
49 reset_revision_walk();
50 release_revisions(&rev);
51 return got_revision;
54 int cmd__revision_walking(int argc, const char **argv)
56 if (argc < 2)
57 return 1;
59 setup_git_directory();
61 if (!strcmp(argv[1], "run-twice")) {
62 printf("1st\n");
63 if (!run_revision_walk())
64 return 1;
65 printf("2nd\n");
66 if (!run_revision_walk())
67 return 1;
69 return 0;
72 fprintf(stderr, "check usage\n");
73 return 1;