config: don't include config.h by default
[git] / builtin / diff-files.c
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
14 static const char diff_files_usage[] =
15 "git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]"
16 COMMON_DIFF_OPTIONS_HELP;
17
18 int 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         init_revisions(&rev, prefix);
25         gitmodules_config();
26         git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
27         rev.abbrev = 0;
28         precompose_argv(argc, argv);
29
30         argc = setup_revisions(argc, argv, &rev, NULL);
31         while (1 < argc && argv[1][0] == '-') {
32                 if (!strcmp(argv[1], "--base"))
33                         rev.max_count = 1;
34                 else if (!strcmp(argv[1], "--ours"))
35                         rev.max_count = 2;
36                 else if (!strcmp(argv[1], "--theirs"))
37                         rev.max_count = 3;
38                 else if (!strcmp(argv[1], "-q"))
39                         options |= DIFF_SILENT_ON_REMOVED;
40                 else
41                         usage(diff_files_usage);
42                 argv++; argc--;
43         }
44         if (!rev.diffopt.output_format)
45                 rev.diffopt.output_format = DIFF_FORMAT_RAW;
46
47         /*
48          * Make sure there are NO revision (i.e. pending object) parameter,
49          * rev.max_count is reasonable (0 <= n <= 3), and
50          * there is no other revision filtering parameters.
51          */
52         if (rev.pending.nr ||
53             rev.min_age != -1 || rev.max_age != -1 ||
54             3 < rev.max_count)
55                 usage(diff_files_usage);
56
57         /*
58          * "diff-files --base -p" should not combine merges because it
59          * was not asked to.  "diff-files -c -p" should not densify
60          * (the user should ask with "diff-files --cc" explicitly).
61          */
62         if (rev.max_count == -1 && !rev.combine_merges &&
63             (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
64                 rev.combine_merges = rev.dense_combined_merges = 1;
65
66         if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
67                 perror("read_cache_preload");
68                 return -1;
69         }
70         result = run_diff_files(&rev, options);
71         return diff_result_code(&rev.diffopt, result);
72 }