]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/diff-files.c
The fifth batch
[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 */
41f43b82 6
03eae9af 7#define USE_THE_REPOSITORY_VARIABLE
41f43b82
PS
8#define DISABLE_SIGN_COMPARE_WARNINGS
9
bc5c5ec0 10#include "builtin.h"
b2141fc1 11#include "config.h"
4a6bf9e1 12#include "diff.h"
3b6c17b5 13#include "diff-merges.h"
91539833 14#include "commit.h"
fbffdfb1 15#include "preload-index.h"
91539833 16#include "revision.h"
c0fb976a 17
4d1f1190 18static const char diff_files_usage[] =
9c9b4f2f 19"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]"
acf7828e 20"\n"
dda2d79a 21COMMON_DIFF_OPTIONS_HELP;
b8f80925 22
9b1cb507
JC
23int cmd_diff_files(int argc,
24 const char **argv,
25 const char *prefix,
26 struct repository *repo UNUSED)
e83c5163 27{
6973dcae 28 struct rev_info rev;
41bbf9d5 29 int result;
6304c29d 30 unsigned options = 0;
e83c5163 31
f66d1423 32 show_usage_if_asked(argc, argv, diff_files_usage);
5a88f97c 33
37590ce3 34 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
8c30be91
SL
35
36 prepare_repo_settings(the_repository);
37 the_repository->settings.command_requires_full_index = 0;
38
2abf3503 39 repo_init_revisions(the_repository, &rev, prefix);
6973dcae 40 rev.abbrev = 0;
feea6946
SK
41
42 /*
43 * Consider "intent-to-add" files as new by default, unless
44 * explicitly specified in the command line or anywhere else.
45 */
46 rev.diffopt.ita_invisible_in_index = 1;
47
5c327502 48 prefix = precompose_argv_prefix(argc, argv, prefix);
6973dcae 49
6304c29d
JH
50 argc = setup_revisions(argc, argv, &rev, NULL);
51 while (1 < argc && argv[1][0] == '-') {
52 if (!strcmp(argv[1], "--base"))
53 rev.max_count = 1;
54 else if (!strcmp(argv[1], "--ours"))
55 rev.max_count = 2;
56 else if (!strcmp(argv[1], "--theirs"))
57 rev.max_count = 3;
58 else if (!strcmp(argv[1], "-q"))
59 options |= DIFF_SILENT_ON_REMOVED;
60 else
61 usage(diff_files_usage);
62 argv++; argc--;
63 }
c9b5ef99
TH
64 if (!rev.diffopt.output_format)
65 rev.diffopt.output_format = DIFF_FORMAT_RAW;
1eb4136a 66 rev.diffopt.rotate_to_strict = 1;
6304c29d
JH
67
68 /*
69 * Make sure there are NO revision (i.e. pending object) parameter,
70 * rev.max_count is reasonable (0 <= n <= 3), and
71 * there is no other revision filtering parameters.
72 */
73 if (rev.pending.nr ||
74 rev.min_age != -1 || rev.max_age != -1 ||
75 3 < rev.max_count)
76 usage(diff_files_usage);
77
903e09a3
JH
78 /*
79 * "diff-files --base -p" should not combine merges because it
80 * was not asked to. "diff-files -c -p" should not densify
81 * (the user should ask with "diff-files --cc" explicitly).
82 */
3b6c17b5 83 if (rev.max_count == -1 &&
6304c29d 84 (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
3b6c17b5 85 diff_merges_set_dense_combined_if_unset(&rev);
6304c29d 86
f126f6ec
JK
87 if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0)
88 die_errno("repo_read_index_preload");
25bd3acd 89 run_diff_files(&rev, options);
4460e052 90 result = diff_result_code(&rev);
0139c58a
ÆAB
91 release_revisions(&rev);
92 return result;
e83c5163 93}