builtin-log.con commit Merge branch 'jc/diff' into next (88a3d24)
   1/*
   2 * Builtin "git log" and related commands (show, whatchanged)
   3 *
   4 * (C) Copyright 2006 Linus Torvalds
   5 *               2006 Junio Hamano
   6 */
   7#include "cache.h"
   8#include "commit.h"
   9#include "diff.h"
  10#include "revision.h"
  11#include "log-tree.h"
  12#include "builtin.h"
  13
  14static int cmd_log_wc(int argc, const char **argv, char **envp,
  15                      struct rev_info *rev)
  16{
  17        struct commit *commit;
  18
  19        rev->abbrev = DEFAULT_ABBREV;
  20        rev->commit_format = CMIT_FMT_DEFAULT;
  21        rev->verbose_header = 1;
  22        argc = setup_revisions(argc, argv, rev, "HEAD");
  23
  24        if (argc > 1)
  25                die("unrecognized argument: %s", argv[1]);
  26
  27        prepare_revision_walk(rev);
  28        setup_pager();
  29        while ((commit = get_revision(rev)) != NULL) {
  30                log_tree_commit(rev, commit);
  31                free(commit->buffer);
  32                commit->buffer = NULL;
  33        }
  34        return 0;
  35}
  36
  37int cmd_whatchanged(int argc, const char **argv, char **envp)
  38{
  39        struct rev_info rev;
  40
  41        init_revisions(&rev);
  42        rev.diff = 1;
  43        rev.diffopt.recursive = 1;
  44        return cmd_log_wc(argc, argv, envp, &rev);
  45}
  46
  47int cmd_show(int argc, const char **argv, char **envp)
  48{
  49        struct rev_info rev;
  50
  51        init_revisions(&rev);
  52        rev.diff = 1;
  53        rev.diffopt.recursive = 1;
  54        rev.combine_merges = 1;
  55        rev.dense_combined_merges = 1;
  56        rev.always_show_header = 1;
  57        rev.ignore_merges = 0;
  58        rev.no_walk = 1;
  59        return cmd_log_wc(argc, argv, envp, &rev);
  60}
  61
  62int cmd_log(int argc, const char **argv, char **envp)
  63{
  64        struct rev_info rev;
  65
  66        init_revisions(&rev);
  67        rev.always_show_header = 1;
  68        rev.diffopt.recursive = 1;
  69        return cmd_log_wc(argc, argv, envp, &rev);
  70}
  71
  72int cmd_format_patch(int argc, const char **argv, char **envp)
  73{
  74        struct commit *commit;
  75        struct commit **list = NULL;
  76        struct rev_info rev;
  77        int nr = 0;
  78
  79        init_revisions(&rev);
  80        rev.commit_format = CMIT_FMT_EMAIL;
  81        rev.verbose_header = 1;
  82        rev.diff = 1;
  83        rev.diffopt.with_raw = 0;
  84        rev.diffopt.with_stat = 1;
  85        rev.combine_merges = 0;
  86        rev.ignore_merges = 1;
  87        rev.diffopt.output_format = DIFF_FORMAT_PATCH;
  88        argc = setup_revisions(argc, argv, &rev, "HEAD");
  89
  90        prepare_revision_walk(&rev);
  91        while ((commit = get_revision(&rev)) != NULL) {
  92                nr++;
  93                list = realloc(list, nr * sizeof(list[0]));
  94                list[nr - 1] = commit;
  95        }
  96        while (0 <= --nr) {
  97                int shown;
  98                commit = list[nr];
  99                shown = log_tree_commit(&rev, commit);
 100                free(commit->buffer);
 101                commit->buffer = NULL;
 102                if (shown)
 103                        printf("-- \n%s\n\n", git_version_string);
 104        }
 105        free(list);
 106        return 0;
 107}
 108