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