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