1 #define USE_THE_REPOSITORY_VARIABLE
2 #define DISABLE_SIGN_COMPARE_WARNINGS
7 #include "diff-merges.h"
9 #include "preload-index.h"
13 static const char diff_cache_usage
[] =
14 "git diff-index [-m] [--cached] [--merge-base] "
15 "[<common-diff-options>] <tree-ish> [<path>...]"
17 COMMON_DIFF_OPTIONS_HELP
;
19 int cmd_diff_index(int argc
,
22 struct repository
*repo UNUSED
)
25 unsigned int option
= 0;
29 show_usage_if_asked(argc
, argv
, diff_cache_usage
);
31 git_config(git_diff_basic_config
, NULL
); /* no "diff" UI options */
33 prepare_repo_settings(the_repository
);
34 the_repository
->settings
.command_requires_full_index
= 0;
36 repo_init_revisions(the_repository
, &rev
, prefix
);
38 prefix
= precompose_argv_prefix(argc
, argv
, prefix
);
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".
44 diff_merges_suppress_m_parsing();
46 argc
= setup_revisions(argc
, argv
, &rev
, NULL
);
47 for (i
= 1; i
< argc
; i
++) {
48 const char *arg
= argv
[i
];
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;
57 usage(diff_cache_usage
);
59 if (!rev
.diffopt
.output_format
)
60 rev
.diffopt
.output_format
= DIFF_FORMAT_RAW
;
62 rev
.diffopt
.rotate_to_strict
= 1;
65 * Make sure there is one revision (i.e. pending object),
66 * and there is no revision filtering parameters.
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
)) {
73 if (repo_read_index_preload(the_repository
, &rev
.diffopt
.pathspec
, 0) < 0) {
74 perror("repo_read_index_preload");
77 } else if (repo_read_index(the_repository
) < 0) {
78 perror("repo_read_index");
81 run_diff_index(&rev
, option
);
82 result
= diff_result_code(&rev
);
83 release_revisions(&rev
);