2 * Copyright (c) 2005 Junio C Hamano
8 static int diff_output_format = DIFF_FORMAT_HUMAN;
9 static int detect_rename = 0;
10 static int diff_setup_opt = 0;
11 static int diff_score_opt = 0;
12 static const char *pickaxe = NULL;
13 static int pickaxe_opts = 0;
14 static int diff_break_opt = -1;
15 static const char *orderfile = NULL;
17 static char *diff_stages_usage =
18 "git-diff-stages [-p] [-r] [-z] [-M] [-C] [-R] [-S<string>] [-O<orderfile>] <stage1> <stage2> [<path>...]";
20 int main(int ac, const char **av)
22 int stage1, stage2, i;
25 while (1 < ac && av[1][0] == '-') {
26 const char *arg = av[1];
27 if (!strcmp(arg, "-r"))
29 else if (!strcmp(arg, "-p"))
30 diff_output_format = DIFF_FORMAT_PATCH;
31 else if (!strncmp(arg, "-B", 2)) {
32 if ((diff_break_opt = diff_scoreopt_parse(arg)) == -1)
33 usage(diff_stages_usage);
35 else if (!strncmp(arg, "-M", 2)) {
36 detect_rename = DIFF_DETECT_RENAME;
37 if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
38 usage(diff_stages_usage);
40 else if (!strncmp(arg, "-C", 2)) {
41 detect_rename = DIFF_DETECT_COPY;
42 if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
43 usage(diff_stages_usage);
45 else if (!strcmp(arg, "-z"))
46 diff_output_format = DIFF_FORMAT_MACHINE;
47 else if (!strcmp(arg, "-R"))
48 diff_setup_opt |= DIFF_SETUP_REVERSE;
49 else if (!strncmp(arg, "-S", 2))
51 else if (!strncmp(arg, "-O", 2))
53 else if (!strcmp(arg, "--pickaxe-all"))
54 pickaxe_opts = DIFF_PICKAXE_ALL;
56 usage(diff_stages_usage);
61 sscanf(av[1], "%d", &stage1) != 1 ||
62 ! (0 <= stage1 && stage1 <= 3) ||
63 sscanf(av[2], "%d", &stage2) != 1 ||
64 ! (0 <= stage2 && stage2 <= 3))
65 usage(diff_stages_usage);
67 av += 3; /* The rest from av[0] are for paths restriction. */
68 diff_setup(diff_setup_opt);
71 while (i < active_nr) {
72 struct cache_entry *ce, *stages[4] = { NULL, };
73 struct cache_entry *one, *two;
80 int stage = ce_stage(ce);
85 if (ce_namelen(ce) != len ||
86 memcmp(name, ce->name, len))
94 diff_addremove('+', ntohl(two->ce_mode),
95 two->sha1, name, NULL);
97 diff_addremove('-', ntohl(one->ce_mode),
98 one->sha1, name, NULL);
99 else if (memcmp(one->sha1, two->sha1, 20) ||
100 (one->ce_mode != two->ce_mode))
101 diff_change(ntohl(one->ce_mode), ntohl(two->ce_mode),
102 one->sha1, two->sha1, name, NULL);
106 detect_rename, diff_score_opt,
107 pickaxe, pickaxe_opts,
110 diff_flush(diff_output_format, 1);