doc: describe git svn init --ignore-refs
[git/git-svn.git] / builtin / diff-index.c
blobf084826a293f96870d0cf6be05e3e346672fc5dc
1 #include "cache.h"
2 #include "diff.h"
3 #include "commit.h"
4 #include "revision.h"
5 #include "builtin.h"
6 #include "submodule.h"
8 static const char diff_cache_usage[] =
9 "git diff-index [-m] [--cached] "
10 "[<common-diff-options>] <tree-ish> [<path>...]"
11 COMMON_DIFF_OPTIONS_HELP;
13 int cmd_diff_index(int argc, const char **argv, const char *prefix)
15 struct rev_info rev;
16 int cached = 0;
17 int i;
18 int result;
20 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
21 init_revisions(&rev, prefix);
22 gitmodules_config();
23 rev.abbrev = 0;
24 precompose_argv(argc, argv);
26 argc = setup_revisions(argc, argv, &rev, NULL);
27 for (i = 1; i < argc; i++) {
28 const char *arg = argv[i];
30 if (!strcmp(arg, "--cached"))
31 cached = 1;
32 else
33 usage(diff_cache_usage);
35 if (!rev.diffopt.output_format)
36 rev.diffopt.output_format = DIFF_FORMAT_RAW;
39 * Make sure there is one revision (i.e. pending object),
40 * and there is no revision filtering parameters.
42 if (rev.pending.nr != 1 ||
43 rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)
44 usage(diff_cache_usage);
45 if (!cached) {
46 setup_work_tree();
47 if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
48 perror("read_cache_preload");
49 return -1;
51 } else if (read_cache() < 0) {
52 perror("read_cache");
53 return -1;
55 result = run_diff_index(&rev, cached);
56 return diff_result_code(&rev.diffopt, result);