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