]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/diff-files.c
Sync with maint
[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 */
f8adbec9 6#define USE_THE_INDEX_COMPATIBILITY_MACROS
e83c5163 7#include "cache.h"
b2141fc1 8#include "config.h"
4a6bf9e1 9#include "diff.h"
91539833
LT
10#include "commit.h"
11#include "revision.h"
e8cc9cd9 12#include "builtin.h"
302ad7a9 13#include "submodule.h"
c0fb976a 14
4d1f1190 15static const char diff_files_usage[] =
9c9b4f2f 16"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]"
dda2d79a 17COMMON_DIFF_OPTIONS_HELP;
b8f80925 18
a633fca0 19int cmd_diff_files(int argc, const char **argv, const char *prefix)
e83c5163 20{
6973dcae 21 struct rev_info rev;
41bbf9d5 22 int result;
6304c29d 23 unsigned options = 0;
e83c5163 24
5a88f97c
JH
25 if (argc == 2 && !strcmp(argv[1], "-h"))
26 usage(diff_files_usage);
27
37590ce3 28 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2abf3503 29 repo_init_revisions(the_repository, &rev, prefix);
6973dcae 30 rev.abbrev = 0;
90a78b83 31 precompose_argv(argc, argv);
6973dcae 32
6304c29d
JH
33 argc = setup_revisions(argc, argv, &rev, NULL);
34 while (1 < argc && argv[1][0] == '-') {
35 if (!strcmp(argv[1], "--base"))
36 rev.max_count = 1;
37 else if (!strcmp(argv[1], "--ours"))
38 rev.max_count = 2;
39 else if (!strcmp(argv[1], "--theirs"))
40 rev.max_count = 3;
41 else if (!strcmp(argv[1], "-q"))
42 options |= DIFF_SILENT_ON_REMOVED;
43 else
44 usage(diff_files_usage);
45 argv++; argc--;
46 }
c9b5ef99
TH
47 if (!rev.diffopt.output_format)
48 rev.diffopt.output_format = DIFF_FORMAT_RAW;
6304c29d
JH
49
50 /*
51 * Make sure there are NO revision (i.e. pending object) parameter,
52 * rev.max_count is reasonable (0 <= n <= 3), and
53 * there is no other revision filtering parameters.
54 */
55 if (rev.pending.nr ||
56 rev.min_age != -1 || rev.max_age != -1 ||
57 3 < rev.max_count)
58 usage(diff_files_usage);
59
903e09a3
JH
60 /*
61 * "diff-files --base -p" should not combine merges because it
62 * was not asked to. "diff-files -c -p" should not densify
63 * (the user should ask with "diff-files --cc" explicitly).
64 */
65 if (rev.max_count == -1 && !rev.combine_merges &&
6304c29d
JH
66 (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
67 rev.combine_merges = rev.dense_combined_merges = 1;
68
5ab2a2da 69 if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
671c9b7e 70 perror("read_cache_preload");
6304c29d
JH
71 return -1;
72 }
73 result = run_diff_files(&rev, options);
da31b358 74 return diff_result_code(&rev.diffopt, result);
e83c5163 75}