]>
Commit | Line | Data |
---|---|---|
bc5c5ec0 | 1 | #include "builtin.h" |
b2141fc1 | 2 | #include "config.h" |
f92a4465 | 3 | #include "diff.h" |
19b2517f | 4 | #include "diff-merges.h" |
e09ad6e1 | 5 | #include "commit.h" |
fbffdfb1 | 6 | #include "preload-index.h" |
df6e8744 | 7 | #include "repository.h" |
e09ad6e1 | 8 | #include "revision.h" |
e38da487 | 9 | #include "setup.h" |
a1264a08 | 10 | #include "sparse-index.h" |
302ad7a9 | 11 | #include "submodule.h" |
b5af9107 | 12 | |
4d1f1190 | 13 | static const char diff_cache_usage[] = |
8c9e292d | 14 | "git diff-index [-m] [--cached] [--merge-base] " |
9c9b4f2f | 15 | "[<common-diff-options>] <tree-ish> [<path>...]" |
acf7828e | 16 | "\n" |
dda2d79a | 17 | COMMON_DIFF_OPTIONS_HELP; |
c5bac17a | 18 | |
a633fca0 | 19 | int cmd_diff_index(int argc, const char **argv, const char *prefix) |
e74f8f6a | 20 | { |
e09ad6e1 | 21 | struct rev_info rev; |
4c3fe82e | 22 | unsigned int option = 0; |
6c56c534 | 23 | int i; |
41bbf9d5 | 24 | int result; |
e74f8f6a | 25 | |
5a88f97c JH |
26 | if (argc == 2 && !strcmp(argv[1], "-h")) |
27 | usage(diff_cache_usage); | |
28 | ||
37590ce3 | 29 | git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ |
2abf3503 | 30 | repo_init_revisions(the_repository, &rev, prefix); |
e09ad6e1 | 31 | rev.abbrev = 0; |
5c327502 | 32 | prefix = precompose_argv_prefix(argc, argv, prefix); |
e09ad6e1 | 33 | |
19b2517f | 34 | /* |
5acffd34 SO |
35 | * We need (some of) diff for merges options (e.g., --cc), and we need |
36 | * to avoid conflict with our own meaning of "-m". | |
19b2517f | 37 | */ |
5acffd34 | 38 | diff_merges_suppress_m_parsing(); |
19b2517f | 39 | |
e09ad6e1 | 40 | argc = setup_revisions(argc, argv, &rev, NULL); |
6c56c534 LT |
41 | for (i = 1; i < argc; i++) { |
42 | const char *arg = argv[i]; | |
a6080a0a | 43 | |
5c21ac0e | 44 | if (!strcmp(arg, "--cached")) |
4c3fe82e | 45 | option |= DIFF_INDEX_CACHED; |
0f5a1d44 DL |
46 | else if (!strcmp(arg, "--merge-base")) |
47 | option |= DIFF_INDEX_MERGE_BASE; | |
19b2517f SO |
48 | else if (!strcmp(arg, "-m")) |
49 | rev.match_missing = 1; | |
e09ad6e1 | 50 | else |
6b5ee137 | 51 | usage(diff_cache_usage); |
e74f8f6a | 52 | } |
c9b5ef99 TH |
53 | if (!rev.diffopt.output_format) |
54 | rev.diffopt.output_format = DIFF_FORMAT_RAW; | |
55 | ||
1eb4136a JH |
56 | rev.diffopt.rotate_to_strict = 1; |
57 | ||
e09ad6e1 JH |
58 | /* |
59 | * Make sure there is one revision (i.e. pending object), | |
60 | * and there is no revision filtering parameters. | |
61 | */ | |
1f1e895f | 62 | if (rev.pending.nr != 1 || |
e09ad6e1 | 63 | rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1) |
c5bac17a | 64 | usage(diff_cache_usage); |
4c3fe82e | 65 | if (!(option & DIFF_INDEX_CACHED)) { |
4f38f6b5 | 66 | setup_work_tree(); |
07047d68 ÆAB |
67 | if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) { |
68 | perror("repo_read_index_preload"); | |
7349afd2 KB |
69 | return -1; |
70 | } | |
07047d68 ÆAB |
71 | } else if (repo_read_index(the_repository) < 0) { |
72 | perror("repo_read_index"); | |
b4e1e4a7 JH |
73 | return -1; |
74 | } | |
25bd3acd | 75 | run_diff_index(&rev, option); |
5cc6b2d7 | 76 | result = diff_result_code(&rev.diffopt); |
bf1b32d0 ÆAB |
77 | release_revisions(&rev); |
78 | return result; | |
e74f8f6a | 79 | } |