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