]>
Commit | Line | Data |
---|---|---|
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 | 10 | static const char diff_cache_usage[] = |
1b1dd23f | 11 | "git diff-index [-m] [--cached] " |
9c9b4f2f | 12 | "[<common-diff-options>] <tree-ish> [<path>...]" |
dda2d79a | 13 | COMMON_DIFF_OPTIONS_HELP; |
c5bac17a | 14 | |
a633fca0 | 15 | int cmd_diff_index(int argc, const char **argv, const char *prefix) |
e74f8f6a | 16 | { |
e09ad6e1 | 17 | struct rev_info rev; |
e09ad6e1 | 18 | int cached = 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; |
90a78b83 | 28 | precompose_argv(argc, argv); |
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")) |
e09ad6e1 JH |
35 | cached = 1; |
36 | else | |
6b5ee137 | 37 | usage(diff_cache_usage); |
e74f8f6a | 38 | } |
c9b5ef99 TH |
39 | if (!rev.diffopt.output_format) |
40 | rev.diffopt.output_format = DIFF_FORMAT_RAW; | |
41 | ||
e09ad6e1 JH |
42 | /* |
43 | * Make sure there is one revision (i.e. pending object), | |
44 | * and there is no revision filtering parameters. | |
45 | */ | |
1f1e895f | 46 | if (rev.pending.nr != 1 || |
e09ad6e1 | 47 | rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1) |
c5bac17a | 48 | usage(diff_cache_usage); |
7349afd2 | 49 | if (!cached) { |
4f38f6b5 | 50 | setup_work_tree(); |
5ab2a2da | 51 | if (read_cache_preload(&rev.diffopt.pathspec) < 0) { |
7349afd2 KB |
52 | perror("read_cache_preload"); |
53 | return -1; | |
54 | } | |
55 | } else if (read_cache() < 0) { | |
b4e1e4a7 JH |
56 | perror("read_cache"); |
57 | return -1; | |
58 | } | |
41bbf9d5 | 59 | result = run_diff_index(&rev, cached); |
886e1084 | 60 | UNLEAK(rev); |
da31b358 | 61 | return diff_result_code(&rev.diffopt, result); |
e74f8f6a | 62 | } |