]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/diff-files.c
config: don't include config.h by default
[thirdparty/git.git] / builtin / diff-files.c
CommitLineData
8bc9a0c7
LT
1/*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
e83c5163 6#include "cache.h"
b2141fc1 7#include "config.h"
4a6bf9e1 8#include "diff.h"
91539833
LT
9#include "commit.h"
10#include "revision.h"
e8cc9cd9 11#include "builtin.h"
302ad7a9 12#include "submodule.h"
c0fb976a 13
4d1f1190 14static const char diff_files_usage[] =
9c9b4f2f 15"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]"
dda2d79a 16COMMON_DIFF_OPTIONS_HELP;
b8f80925 17
a633fca0 18int cmd_diff_files(int argc, const char **argv, const char *prefix)
e83c5163 19{
6973dcae 20 struct rev_info rev;
41bbf9d5 21 int result;
6304c29d 22 unsigned options = 0;
e83c5163 23
a633fca0 24 init_revisions(&rev, prefix);
302ad7a9 25 gitmodules_config();
ef90d6d4 26 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
6973dcae 27 rev.abbrev = 0;
90a78b83 28 precompose_argv(argc, argv);
6973dcae 29
6304c29d
JH
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 }
c9b5ef99
TH
44 if (!rev.diffopt.output_format)
45 rev.diffopt.output_format = DIFF_FORMAT_RAW;
6304c29d
JH
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
903e09a3
JH
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 &&
6304c29d
JH
63 (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
64 rev.combine_merges = rev.dense_combined_merges = 1;
65
5ab2a2da 66 if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
671c9b7e 67 perror("read_cache_preload");
6304c29d
JH
68 return -1;
69 }
70 result = run_diff_files(&rev, options);
da31b358 71 return diff_result_code(&rev.diffopt, result);
e83c5163 72}