builtin / diff-index.con commit config: don't implicitly use gitdir or commondir (dc8441f)
   1#include "cache.h"
   2#include "config.h"
   3#include "diff.h"
   4#include "commit.h"
   5#include "revision.h"
   6#include "builtin.h"
   7#include "submodule.h"
   8
   9static const char diff_cache_usage[] =
  10"git diff-index [-m] [--cached] "
  11"[<common-diff-options>] <tree-ish> [<path>...]"
  12COMMON_DIFF_OPTIONS_HELP;
  13
  14int cmd_diff_index(int argc, const char **argv, const char *prefix)
  15{
  16        struct rev_info rev;
  17        int cached = 0;
  18        int i;
  19        int result;
  20
  21        init_revisions(&rev, prefix);
  22        gitmodules_config();
  23        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
  24        rev.abbrev = 0;
  25        precompose_argv(argc, argv);
  26
  27        argc = setup_revisions(argc, argv, &rev, NULL);
  28        for (i = 1; i < argc; i++) {
  29                const char *arg = argv[i];
  30
  31                if (!strcmp(arg, "--cached"))
  32                        cached = 1;
  33                else
  34                        usage(diff_cache_usage);
  35        }
  36        if (!rev.diffopt.output_format)
  37                rev.diffopt.output_format = DIFF_FORMAT_RAW;
  38
  39        /*
  40         * Make sure there is one revision (i.e. pending object),
  41         * and there is no revision filtering parameters.
  42         */
  43        if (rev.pending.nr != 1 ||
  44            rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)
  45                usage(diff_cache_usage);
  46        if (!cached) {
  47                setup_work_tree();
  48                if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
  49                        perror("read_cache_preload");
  50                        return -1;
  51                }
  52        } else if (read_cache() < 0) {
  53                perror("read_cache");
  54                return -1;
  55        }
  56        result = run_diff_index(&rev, cached);
  57        return diff_result_code(&rev.diffopt, result);
  58}