]>
Commit | Line | Data |
---|---|---|
1 | #define USE_THE_REPOSITORY_VARIABLE | |
2 | #define DISABLE_SIGN_COMPARE_WARNINGS | |
3 | ||
4 | #include "builtin.h" | |
5 | #include "config.h" | |
6 | #include "diff.h" | |
7 | #include "diff-merges.h" | |
8 | #include "commit.h" | |
9 | #include "preload-index.h" | |
10 | #include "revision.h" | |
11 | #include "setup.h" | |
12 | ||
13 | static const char diff_cache_usage[] = | |
14 | "git diff-index [-m] [--cached] [--merge-base] " | |
15 | "[<common-diff-options>] <tree-ish> [<path>...]" | |
16 | "\n" | |
17 | COMMON_DIFF_OPTIONS_HELP; | |
18 | ||
19 | int cmd_diff_index(int argc, | |
20 | const char **argv, | |
21 | const char *prefix, | |
22 | struct repository *repo UNUSED) | |
23 | { | |
24 | struct rev_info rev; | |
25 | unsigned int option = 0; | |
26 | int i; | |
27 | int result; | |
28 | ||
29 | show_usage_if_asked(argc, argv, diff_cache_usage); | |
30 | ||
31 | git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ | |
32 | ||
33 | prepare_repo_settings(the_repository); | |
34 | the_repository->settings.command_requires_full_index = 0; | |
35 | ||
36 | repo_init_revisions(the_repository, &rev, prefix); | |
37 | rev.abbrev = 0; | |
38 | prefix = precompose_argv_prefix(argc, argv, prefix); | |
39 | ||
40 | /* | |
41 | * We need (some of) diff for merges options (e.g., --cc), and we need | |
42 | * to avoid conflict with our own meaning of "-m". | |
43 | */ | |
44 | diff_merges_suppress_m_parsing(); | |
45 | ||
46 | argc = setup_revisions(argc, argv, &rev, NULL); | |
47 | for (i = 1; i < argc; i++) { | |
48 | const char *arg = argv[i]; | |
49 | ||
50 | if (!strcmp(arg, "--cached")) | |
51 | option |= DIFF_INDEX_CACHED; | |
52 | else if (!strcmp(arg, "--merge-base")) | |
53 | option |= DIFF_INDEX_MERGE_BASE; | |
54 | else if (!strcmp(arg, "-m")) | |
55 | rev.match_missing = 1; | |
56 | else | |
57 | usage(diff_cache_usage); | |
58 | } | |
59 | if (!rev.diffopt.output_format) | |
60 | rev.diffopt.output_format = DIFF_FORMAT_RAW; | |
61 | ||
62 | rev.diffopt.rotate_to_strict = 1; | |
63 | ||
64 | /* | |
65 | * Make sure there is one revision (i.e. pending object), | |
66 | * and there is no revision filtering parameters. | |
67 | */ | |
68 | if (rev.pending.nr != 1 || | |
69 | rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1) | |
70 | usage(diff_cache_usage); | |
71 | if (!(option & DIFF_INDEX_CACHED)) { | |
72 | setup_work_tree(); | |
73 | if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) { | |
74 | perror("repo_read_index_preload"); | |
75 | return -1; | |
76 | } | |
77 | } else if (repo_read_index(the_repository) < 0) { | |
78 | perror("repo_read_index"); | |
79 | return -1; | |
80 | } | |
81 | run_diff_index(&rev, option); | |
82 | result = diff_result_code(&rev); | |
83 | release_revisions(&rev); | |
84 | return result; | |
85 | } |