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