Merge branch 'np/types'
[git/git.git] / builtin-diff-index.c
CommitLineData
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 7static const char diff_cache_usage[] =
215a7ad1 8"git-diff-index [-m] [--cached] "
dda2d79a
JH
9"[<common diff options>] <tree-ish> [<path>...]"
10COMMON_DIFF_OPTIONS_HELP;
c5bac17a 11
a633fca0 12int 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;
e74f8f6a 17
a633fca0 18 init_revisions(&rev, prefix);
ef1d9c5a 19 git_config(git_default_config); /* no "diff" UI options */
e09ad6e1
JH
20 rev.abbrev = 0;
21
22 argc = setup_revisions(argc, argv, &rev, NULL);
6c56c534
LT
23 for (i = 1; i < argc; i++) {
24 const char *arg = argv[i];
6c56c534 25
5c21ac0e 26 if (!strcmp(arg, "--cached"))
e09ad6e1
JH
27 cached = 1;
28 else
6b5ee137 29 usage(diff_cache_usage);
e74f8f6a 30 }
c9b5ef99
TH
31 if (!rev.diffopt.output_format)
32 rev.diffopt.output_format = DIFF_FORMAT_RAW;
33
e09ad6e1
JH
34 /*
35 * Make sure there is one revision (i.e. pending object),
36 * and there is no revision filtering parameters.
37 */
1f1e895f 38 if (rev.pending.nr != 1 ||
e09ad6e1 39 rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)
c5bac17a 40 usage(diff_cache_usage);
b4e1e4a7
JH
41 if (read_cache() < 0) {
42 perror("read_cache");
43 return -1;
44 }
5c21ac0e 45 return run_diff_index(&rev, cached);
e74f8f6a 46}