git/t/helper/test-revision-walking.c
Junio C Hamano 6047b28eb7 Merge branch 'en/header-split-cleanup'
Split key function and data structure definitions out of cache.h to
new header files and adjust the users.

* en/header-split-cleanup:
  csum-file.h: remove unnecessary inclusion of cache.h
  write-or-die.h: move declarations for write-or-die.c functions from cache.h
  treewide: remove cache.h inclusion due to setup.h changes
  setup.h: move declarations for setup.c functions from cache.h
  treewide: remove cache.h inclusion due to environment.h changes
  environment.h: move declarations for environment.c functions from cache.h
  treewide: remove unnecessary includes of cache.h
  wrapper.h: move declarations for wrapper.c functions from cache.h
  path.h: move function declarations for path.c functions from cache.h
  cache.h: remove expand_user_path()
  abspath.h: move absolute path functions from cache.h
  environment: move comment_line_char from cache.h
  treewide: remove unnecessary cache.h inclusion from several sources
  treewide: remove unnecessary inclusion of gettext.h
  treewide: be explicit about dependence on gettext.h
  treewide: remove unnecessary cache.h inclusion from a few headers
2023-04-06 13:38:31 -07:00

72 lines
1.5 KiB
C

/*
* test-revision-walking.c: test revision walking API.
*
* (C) 2012 Heiko Voigt <hvoigt@hvoigt.net>
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include "test-tool.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
#include "setup.h"
static void print_commit(struct commit *commit)
{
struct strbuf sb = STRBUF_INIT;
struct pretty_print_context ctx = {0};
ctx.date_mode.type = DATE_NORMAL;
repo_format_commit_message(the_repository, commit, " %m %s", &sb,
&ctx);
printf("%s\n", sb.buf);
strbuf_release(&sb);
}
static int run_revision_walk(void)
{
struct rev_info rev;
struct commit *commit;
const char *argv[] = {NULL, "--all", NULL};
int argc = ARRAY_SIZE(argv) - 1;
int got_revision = 0;
repo_init_revisions(the_repository, &rev, NULL);
setup_revisions(argc, argv, &rev, NULL);
if (prepare_revision_walk(&rev))
die("revision walk setup failed");
while ((commit = get_revision(&rev)) != NULL) {
print_commit(commit);
got_revision = 1;
}
reset_revision_walk();
release_revisions(&rev);
return got_revision;
}
int cmd__revision_walking(int argc, const char **argv)
{
if (argc < 2)
return 1;
setup_git_directory();
if (!strcmp(argv[1], "run-twice")) {
printf("1st\n");
if (!run_revision_walk())
return 1;
printf("2nd\n");
if (!run_revision_walk())
return 1;
return 0;
}
fprintf(stderr, "check usage\n");
return 1;
}