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.
106 lines
2.5 KiB
106 lines
2.5 KiB
20 years ago
|
/*
|
||
|
* Copyright (c) 2005 Junio C Hamano
|
||
|
*/
|
||
|
|
||
|
#include "cache.h"
|
||
|
#include "diff.h"
|
||
19 years ago
|
#include "builtin.h"
|
||
20 years ago
|
|
||
19 years ago
|
static struct diff_options diff_options;
|
||
20 years ago
|
|
||
20 years ago
|
static const char diff_stages_usage[] =
|
||
20 years ago
|
"git-diff-stages [<common diff options>] <stage1> <stage2> [<path>...]"
|
||
|
COMMON_DIFF_OPTIONS_HELP;
|
||
20 years ago
|
|
||
19 years ago
|
static void diff_stages(int stage1, int stage2, const char **pathspec)
|
||
20 years ago
|
{
|
||
|
int i = 0;
|
||
|
while (i < active_nr) {
|
||
|
struct cache_entry *ce, *stages[4] = { NULL, };
|
||
|
struct cache_entry *one, *two;
|
||
|
const char *name;
|
||
19 years ago
|
int len, skip;
|
||
|
|
||
20 years ago
|
ce = active_cache[i];
|
||
19 years ago
|
skip = !ce_path_match(ce, pathspec);
|
||
20 years ago
|
len = ce_namelen(ce);
|
||
|
name = ce->name;
|
||
|
for (;;) {
|
||
|
int stage = ce_stage(ce);
|
||
|
stages[stage] = ce;
|
||
|
if (active_nr <= ++i)
|
||
|
break;
|
||
|
ce = active_cache[i];
|
||
|
if (ce_namelen(ce) != len ||
|
||
|
memcmp(name, ce->name, len))
|
||
|
break;
|
||
|
}
|
||
|
one = stages[stage1];
|
||
|
two = stages[stage2];
|
||
19 years ago
|
|
||
|
if (skip || (!one && !two))
|
||
20 years ago
|
continue;
|
||
|
if (!one)
|
||
19 years ago
|
diff_addremove(&diff_options, '+', ntohl(two->ce_mode),
|
||
20 years ago
|
two->sha1, name, NULL);
|
||
|
else if (!two)
|
||
19 years ago
|
diff_addremove(&diff_options, '-', ntohl(one->ce_mode),
|
||
20 years ago
|
one->sha1, name, NULL);
|
||
|
else if (memcmp(one->sha1, two->sha1, 20) ||
|
||
20 years ago
|
(one->ce_mode != two->ce_mode) ||
|
||
19 years ago
|
diff_options.find_copies_harder)
|
||
|
diff_change(&diff_options,
|
||
|
ntohl(one->ce_mode), ntohl(two->ce_mode),
|
||
20 years ago
|
one->sha1, two->sha1, name, NULL);
|
||
20 years ago
|
}
|
||
|
}
|
||
|
|
||
19 years ago
|
int cmd_diff_stages(int ac, const char **av, char **envp)
|
||
20 years ago
|
{
|
||
20 years ago
|
int stage1, stage2;
|
||
19 years ago
|
const char *prefix = setup_git_directory();
|
||
|
const char **pathspec = NULL;
|
||
19 years ago
|
|
||
|
git_config(git_diff_config);
|
||
20 years ago
|
read_cache();
|
||
19 years ago
|
diff_setup(&diff_options);
|
||
20 years ago
|
while (1 < ac && av[1][0] == '-') {
|
||
|
const char *arg = av[1];
|
||
|
if (!strcmp(arg, "-r"))
|
||
|
; /* as usual */
|
||
19 years ago
|
else {
|
||
|
int diff_opt_cnt;
|
||
|
diff_opt_cnt = diff_opt_parse(&diff_options,
|
||
|
av+1, ac-1);
|
||
|
if (diff_opt_cnt < 0)
|
||
20 years ago
|
usage(diff_stages_usage);
|
||
19 years ago
|
else if (diff_opt_cnt) {
|
||
|
av += diff_opt_cnt;
|
||
|
ac -= diff_opt_cnt;
|
||
|
continue;
|
||
|
}
|
||
|
else
|
||
20 years ago
|
usage(diff_stages_usage);
|
||
|
}
|
||
|
ac--; av++;
|
||
|
}
|
||
|
|
||
|
if (ac < 3 ||
|
||
|
sscanf(av[1], "%d", &stage1) != 1 ||
|
||
|
! (0 <= stage1 && stage1 <= 3) ||
|
||
|
sscanf(av[2], "%d", &stage2) != 1 ||
|
||
19 years ago
|
! (0 <= stage2 && stage2 <= 3))
|
||
20 years ago
|
usage(diff_stages_usage);
|
||
|
|
||
|
av += 3; /* The rest from av[0] are for paths restriction. */
|
||
19 years ago
|
pathspec = get_pathspec(prefix, av);
|
||
20 years ago
|
|
||
19 years ago
|
if (diff_setup_done(&diff_options) < 0)
|
||
|
usage(diff_stages_usage);
|
||
20 years ago
|
|
||
19 years ago
|
diff_stages(stage1, stage2, pathspec);
|
||
19 years ago
|
diffcore_std(&diff_options);
|
||
|
diff_flush(&diff_options);
|
||
20 years ago
|
return 0;
|
||
|
}
|