]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/diff-index.c
The sixth batch
[thirdparty/git.git] / builtin / diff-index.c
CommitLineData
03eae9af 1#define USE_THE_REPOSITORY_VARIABLE
41f43b82
PS
2#define DISABLE_SIGN_COMPARE_WARNINGS
3
bc5c5ec0 4#include "builtin.h"
b2141fc1 5#include "config.h"
f92a4465 6#include "diff.h"
19b2517f 7#include "diff-merges.h"
e09ad6e1 8#include "commit.h"
fbffdfb1 9#include "preload-index.h"
e09ad6e1 10#include "revision.h"
e38da487 11#include "setup.h"
b5af9107 12
4d1f1190 13static const char diff_cache_usage[] =
8c9e292d 14"git diff-index [-m] [--cached] [--merge-base] "
9c9b4f2f 15"[<common-diff-options>] <tree-ish> [<path>...]"
acf7828e 16"\n"
dda2d79a 17COMMON_DIFF_OPTIONS_HELP;
c5bac17a 18
9b1cb507
JC
19int cmd_diff_index(int argc,
20 const char **argv,
21 const char *prefix,
22 struct repository *repo UNUSED)
e74f8f6a 23{
e09ad6e1 24 struct rev_info rev;
4c3fe82e 25 unsigned int option = 0;
6c56c534 26 int i;
41bbf9d5 27 int result;
e74f8f6a 28
f66d1423 29 show_usage_if_asked(argc, argv, diff_cache_usage);
5a88f97c 30
37590ce3 31 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
b44c926c
DS
32
33 prepare_repo_settings(the_repository);
34 the_repository->settings.command_requires_full_index = 0;
35
2abf3503 36 repo_init_revisions(the_repository, &rev, prefix);
e09ad6e1 37 rev.abbrev = 0;
5c327502 38 prefix = precompose_argv_prefix(argc, argv, prefix);
e09ad6e1 39
19b2517f 40 /*
5acffd34
SO
41 * We need (some of) diff for merges options (e.g., --cc), and we need
42 * to avoid conflict with our own meaning of "-m".
19b2517f 43 */
5acffd34 44 diff_merges_suppress_m_parsing();
19b2517f 45
e09ad6e1 46 argc = setup_revisions(argc, argv, &rev, NULL);
6c56c534
LT
47 for (i = 1; i < argc; i++) {
48 const char *arg = argv[i];
a6080a0a 49
5c21ac0e 50 if (!strcmp(arg, "--cached"))
4c3fe82e 51 option |= DIFF_INDEX_CACHED;
0f5a1d44
DL
52 else if (!strcmp(arg, "--merge-base"))
53 option |= DIFF_INDEX_MERGE_BASE;
19b2517f
SO
54 else if (!strcmp(arg, "-m"))
55 rev.match_missing = 1;
e09ad6e1 56 else
6b5ee137 57 usage(diff_cache_usage);
e74f8f6a 58 }
c9b5ef99
TH
59 if (!rev.diffopt.output_format)
60 rev.diffopt.output_format = DIFF_FORMAT_RAW;
61
1eb4136a
JH
62 rev.diffopt.rotate_to_strict = 1;
63
e09ad6e1
JH
64 /*
65 * Make sure there is one revision (i.e. pending object),
66 * and there is no revision filtering parameters.
67 */
1f1e895f 68 if (rev.pending.nr != 1 ||
e09ad6e1 69 rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)
c5bac17a 70 usage(diff_cache_usage);
4c3fe82e 71 if (!(option & DIFF_INDEX_CACHED)) {
4f38f6b5 72 setup_work_tree();
07047d68
ÆAB
73 if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
74 perror("repo_read_index_preload");
7349afd2
KB
75 return -1;
76 }
07047d68
ÆAB
77 } else if (repo_read_index(the_repository) < 0) {
78 perror("repo_read_index");
b4e1e4a7
JH
79 return -1;
80 }
25bd3acd 81 run_diff_index(&rev, option);
4460e052 82 result = diff_result_code(&rev);
bf1b32d0
ÆAB
83 release_revisions(&rev);
84 return result;
e74f8f6a 85}