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.
11 #define USE_THE_REPOSITORY_VARIABLE
13 #include "test-tool.h"
16 #include "repository.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
,
27 printf("%s\n", sb
.buf
);
31 static int run_revision_walk(void)
34 struct commit
*commit
;
35 const char *argv
[] = {NULL
, "--all", NULL
};
36 int argc
= ARRAY_SIZE(argv
) - 1;
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
) {
49 reset_revision_walk();
50 release_revisions(&rev
);
54 int cmd__revision_walking(int argc
, const char **argv
)
59 setup_git_directory();
61 if (!strcmp(argv
[1], "run-twice")) {
63 if (!run_revision_walk())
66 if (!run_revision_walk())
72 fprintf(stderr
, "check usage\n");