test-revision-walking.con commit Merge branch 'va/i18n-remote-comment-to-align' into maint (6db5205)
   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 "cache.h"
  12#include "commit.h"
  13#include "diff.h"
  14#include "revision.h"
  15
  16static void print_commit(struct commit *commit)
  17{
  18        struct strbuf sb = STRBUF_INIT;
  19        struct pretty_print_context ctx = {0};
  20        ctx.date_mode.type = DATE_NORMAL;
  21        format_commit_message(commit, " %m %s", &sb, &ctx);
  22        printf("%s\n", sb.buf);
  23        strbuf_release(&sb);
  24}
  25
  26static int run_revision_walk(void)
  27{
  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;
  33
  34        init_revisions(&rev, NULL);
  35        setup_revisions(argc, argv, &rev, NULL);
  36        if (prepare_revision_walk(&rev))
  37                die("revision walk setup failed");
  38
  39        while ((commit = get_revision(&rev)) != NULL) {
  40                print_commit(commit);
  41                got_revision = 1;
  42        }
  43
  44        reset_revision_walk();
  45        return got_revision;
  46}
  47
  48int main(int argc, char **argv)
  49{
  50        if (argc < 2)
  51                return 1;
  52
  53        setup_git_directory();
  54
  55        if (!strcmp(argv[1], "run-twice")) {
  56                printf("1st\n");
  57                if (!run_revision_walk())
  58                        return 1;
  59                printf("2nd\n");
  60                if (!run_revision_walk())
  61                        return 1;
  62
  63                return 0;
  64        }
  65
  66        fprintf(stderr, "check usage\n");
  67        return 1;
  68}