]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/diff-files.c
Start the 2.46 cycle
[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 */
bc5c5ec0 6#include "builtin.h"
b2141fc1 7#include "config.h"
4a6bf9e1 8#include "diff.h"
3b6c17b5 9#include "diff-merges.h"
91539833 10#include "commit.h"
fbffdfb1 11#include "preload-index.h"
df6e8744 12#include "repository.h"
91539833 13#include "revision.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>...]"
acf7828e 17"\n"
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 */
8c30be91
SL
30
31 prepare_repo_settings(the_repository);
32 the_repository->settings.command_requires_full_index = 0;
33
2abf3503 34 repo_init_revisions(the_repository, &rev, prefix);
6973dcae 35 rev.abbrev = 0;
feea6946
SK
36
37 /*
38 * Consider "intent-to-add" files as new by default, unless
39 * explicitly specified in the command line or anywhere else.
40 */
41 rev.diffopt.ita_invisible_in_index = 1;
42
5c327502 43 prefix = precompose_argv_prefix(argc, argv, prefix);
6973dcae 44
6304c29d
JH
45 argc = setup_revisions(argc, argv, &rev, NULL);
46 while (1 < argc && argv[1][0] == '-') {
47 if (!strcmp(argv[1], "--base"))
48 rev.max_count = 1;
49 else if (!strcmp(argv[1], "--ours"))
50 rev.max_count = 2;
51 else if (!strcmp(argv[1], "--theirs"))
52 rev.max_count = 3;
53 else if (!strcmp(argv[1], "-q"))
54 options |= DIFF_SILENT_ON_REMOVED;
55 else
56 usage(diff_files_usage);
57 argv++; argc--;
58 }
c9b5ef99
TH
59 if (!rev.diffopt.output_format)
60 rev.diffopt.output_format = DIFF_FORMAT_RAW;
1eb4136a 61 rev.diffopt.rotate_to_strict = 1;
6304c29d
JH
62
63 /*
64 * Make sure there are NO revision (i.e. pending object) parameter,
65 * rev.max_count is reasonable (0 <= n <= 3), and
66 * there is no other revision filtering parameters.
67 */
68 if (rev.pending.nr ||
69 rev.min_age != -1 || rev.max_age != -1 ||
70 3 < rev.max_count)
71 usage(diff_files_usage);
72
903e09a3
JH
73 /*
74 * "diff-files --base -p" should not combine merges because it
75 * was not asked to. "diff-files -c -p" should not densify
76 * (the user should ask with "diff-files --cc" explicitly).
77 */
3b6c17b5 78 if (rev.max_count == -1 &&
6304c29d 79 (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
3b6c17b5 80 diff_merges_set_dense_combined_if_unset(&rev);
6304c29d 81
f126f6ec
JK
82 if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0)
83 die_errno("repo_read_index_preload");
25bd3acd 84 run_diff_files(&rev, options);
5cc6b2d7 85 result = diff_result_code(&rev.diffopt);
0139c58a
ÆAB
86 release_revisions(&rev);
87 return result;
e83c5163 88}