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