]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/diff-index.c
Merge branch 'jc/diffcore-rotate'
[thirdparty/git.git] / builtin / diff-index.c
CommitLineData
f8adbec9 1#define USE_THE_INDEX_COMPATIBILITY_MACROS
e74f8f6a 2#include "cache.h"
b2141fc1 3#include "config.h"
f92a4465 4#include "diff.h"
e09ad6e1
JH
5#include "commit.h"
6#include "revision.h"
e8cc9cd9 7#include "builtin.h"
302ad7a9 8#include "submodule.h"
b5af9107 9
4d1f1190 10static const char diff_cache_usage[] =
1b1dd23f 11"git diff-index [-m] [--cached] "
9c9b4f2f 12"[<common-diff-options>] <tree-ish> [<path>...]"
dda2d79a 13COMMON_DIFF_OPTIONS_HELP;
c5bac17a 14
a633fca0 15int cmd_diff_index(int argc, const char **argv, const char *prefix)
e74f8f6a 16{
e09ad6e1 17 struct rev_info rev;
4c3fe82e 18 unsigned int option = 0;
6c56c534 19 int i;
41bbf9d5 20 int result;
e74f8f6a 21
5a88f97c
JH
22 if (argc == 2 && !strcmp(argv[1], "-h"))
23 usage(diff_cache_usage);
24
37590ce3 25 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2abf3503 26 repo_init_revisions(the_repository, &rev, prefix);
e09ad6e1 27 rev.abbrev = 0;
5c327502 28 prefix = precompose_argv_prefix(argc, argv, prefix);
e09ad6e1
JH
29
30 argc = setup_revisions(argc, argv, &rev, NULL);
6c56c534
LT
31 for (i = 1; i < argc; i++) {
32 const char *arg = argv[i];
a6080a0a 33
5c21ac0e 34 if (!strcmp(arg, "--cached"))
4c3fe82e 35 option |= DIFF_INDEX_CACHED;
0f5a1d44
DL
36 else if (!strcmp(arg, "--merge-base"))
37 option |= DIFF_INDEX_MERGE_BASE;
e09ad6e1 38 else
6b5ee137 39 usage(diff_cache_usage);
e74f8f6a 40 }
c9b5ef99
TH
41 if (!rev.diffopt.output_format)
42 rev.diffopt.output_format = DIFF_FORMAT_RAW;
43
1eb4136a
JH
44 rev.diffopt.rotate_to_strict = 1;
45
e09ad6e1
JH
46 /*
47 * Make sure there is one revision (i.e. pending object),
48 * and there is no revision filtering parameters.
49 */
1f1e895f 50 if (rev.pending.nr != 1 ||
e09ad6e1 51 rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)
c5bac17a 52 usage(diff_cache_usage);
4c3fe82e 53 if (!(option & DIFF_INDEX_CACHED)) {
4f38f6b5 54 setup_work_tree();
5ab2a2da 55 if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
7349afd2
KB
56 perror("read_cache_preload");
57 return -1;
58 }
59 } else if (read_cache() < 0) {
b4e1e4a7
JH
60 perror("read_cache");
61 return -1;
62 }
4c3fe82e 63 result = run_diff_index(&rev, option);
886e1084 64 UNLEAK(rev);
da31b358 65 return diff_result_code(&rev.diffopt, result);
e74f8f6a 66}