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