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