You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
20 years ago
|
#include "cache.h"
|
||
20 years ago
|
#include "diff.h"
|
||
19 years ago
|
#include "commit.h"
|
||
|
#include "revision.h"
|
||
19 years ago
|
#include "builtin.h"
|
||
20 years ago
|
|
||
20 years ago
|
static const char diff_cache_usage[] =
|
||
17 years ago
|
"git diff-index [-m] [--cached] "
|
||
20 years ago
|
"[<common diff options>] <tree-ish> [<path>...]"
|
||
|
COMMON_DIFF_OPTIONS_HELP;
|
||
20 years ago
|
|
||
19 years ago
|
int cmd_diff_index(int argc, const char **argv, const char *prefix)
|
||
20 years ago
|
{
|
||
19 years ago
|
struct rev_info rev;
|
||
|
int cached = 0;
|
||
20 years ago
|
int i;
|
||
18 years ago
|
int result;
|
||
20 years ago
|
|
||
19 years ago
|
init_revisions(&rev, prefix);
|
||
17 years ago
|
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
|
||
19 years ago
|
rev.abbrev = 0;
|
||
|
|
||
|
argc = setup_revisions(argc, argv, &rev, NULL);
|
||
20 years ago
|
for (i = 1; i < argc; i++) {
|
||
|
const char *arg = argv[i];
|
||
18 years ago
|
|
||
19 years ago
|
if (!strcmp(arg, "--cached"))
|
||
19 years ago
|
cached = 1;
|
||
|
else
|
||
20 years ago
|
usage(diff_cache_usage);
|
||
20 years ago
|
}
|
||
19 years ago
|
if (!rev.diffopt.output_format)
|
||
|
rev.diffopt.output_format = DIFF_FORMAT_RAW;
|
||
|
|
||
19 years ago
|
/*
|
||
|
* Make sure there is one revision (i.e. pending object),
|
||
|
* and there is no revision filtering parameters.
|
||
|
*/
|
||
19 years ago
|
if (rev.pending.nr != 1 ||
|
||
19 years ago
|
rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)
|
||
20 years ago
|
usage(diff_cache_usage);
|
||
17 years ago
|
if (!cached)
|
||
|
setup_work_tree();
|
||
18 years ago
|
if (read_cache() < 0) {
|
||
|
perror("read_cache");
|
||
|
return -1;
|
||
|
}
|
||
18 years ago
|
result = run_diff_index(&rev, cached);
|
||
17 years ago
|
return diff_result_code(&rev.diffopt, result);
|
||
20 years ago
|
}
|