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