builtin / diff-files.con commit git-rebase.txt: address confusion between --no-ff vs --force-rebase (983f464)
   1/*
   2 * GIT - The information manager from hell
   3 *
   4 * Copyright (C) Linus Torvalds, 2005
   5 */
   6#include "cache.h"
   7#include "config.h"
   8#include "diff.h"
   9#include "commit.h"
  10#include "revision.h"
  11#include "builtin.h"
  12#include "submodule.h"
  13
  14static const char diff_files_usage[] =
  15"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]"
  16COMMON_DIFF_OPTIONS_HELP;
  17
  18int cmd_diff_files(int argc, const char **argv, const char *prefix)
  19{
  20        struct rev_info rev;
  21        int result;
  22        unsigned options = 0;
  23
  24        if (argc == 2 && !strcmp(argv[1], "-h"))
  25                usage(diff_files_usage);
  26
  27        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
  28        init_revisions(&rev, prefix);
  29        rev.abbrev = 0;
  30        precompose_argv(argc, argv);
  31
  32        argc = setup_revisions(argc, argv, &rev, NULL);
  33        while (1 < argc && argv[1][0] == '-') {
  34                if (!strcmp(argv[1], "--base"))
  35                        rev.max_count = 1;
  36                else if (!strcmp(argv[1], "--ours"))
  37                        rev.max_count = 2;
  38                else if (!strcmp(argv[1], "--theirs"))
  39                        rev.max_count = 3;
  40                else if (!strcmp(argv[1], "-q"))
  41                        options |= DIFF_SILENT_ON_REMOVED;
  42                else
  43                        usage(diff_files_usage);
  44                argv++; argc--;
  45        }
  46        if (!rev.diffopt.output_format)
  47                rev.diffopt.output_format = DIFF_FORMAT_RAW;
  48
  49        /*
  50         * Make sure there are NO revision (i.e. pending object) parameter,
  51         * rev.max_count is reasonable (0 <= n <= 3), and
  52         * there is no other revision filtering parameters.
  53         */
  54        if (rev.pending.nr ||
  55            rev.min_age != -1 || rev.max_age != -1 ||
  56            3 < rev.max_count)
  57                usage(diff_files_usage);
  58
  59        /*
  60         * "diff-files --base -p" should not combine merges because it
  61         * was not asked to.  "diff-files -c -p" should not densify
  62         * (the user should ask with "diff-files --cc" explicitly).
  63         */
  64        if (rev.max_count == -1 && !rev.combine_merges &&
  65            (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
  66                rev.combine_merges = rev.dense_combined_merges = 1;
  67
  68        if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
  69                perror("read_cache_preload");
  70                return -1;
  71        }
  72        result = run_diff_files(&rev, options);
  73        return diff_result_code(&rev.diffopt, result);
  74}