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