2 * Copyright (c) 2005 Junio C Hamano
8 static struct diff_options diff_options
;
10 static const char diff_stages_usage
[] =
11 "git-diff-stages [<common diff options>] <stage1> <stage2> [<path>...]"
12 COMMON_DIFF_OPTIONS_HELP
;
14 static void diff_stages(int stage1
, int stage2
)
17 while (i
< active_nr
) {
18 struct cache_entry
*ce
, *stages
[4] = { NULL
, };
19 struct cache_entry
*one
, *two
;
26 int stage
= ce_stage(ce
);
31 if (ce_namelen(ce
) != len
||
32 memcmp(name
, ce
->name
, len
))
40 diff_addremove(&diff_options
, '+', ntohl(two
->ce_mode
),
41 two
->sha1
, name
, NULL
);
43 diff_addremove(&diff_options
, '-', ntohl(one
->ce_mode
),
44 one
->sha1
, name
, NULL
);
45 else if (memcmp(one
->sha1
, two
->sha1
, 20) ||
46 (one
->ce_mode
!= two
->ce_mode
) ||
47 diff_options
.find_copies_harder
)
48 diff_change(&diff_options
,
49 ntohl(one
->ce_mode
), ntohl(two
->ce_mode
),
50 one
->sha1
, two
->sha1
, name
, NULL
);
54 int main(int ac
, const char **av
)
58 setup_git_directory();
60 git_config(git_diff_config
);
62 diff_setup(&diff_options
);
63 while (1 < ac
&& av
[1][0] == '-') {
64 const char *arg
= av
[1];
65 if (!strcmp(arg
, "-r"))
69 diff_opt_cnt
= diff_opt_parse(&diff_options
,
72 usage(diff_stages_usage
);
73 else if (diff_opt_cnt
) {
79 usage(diff_stages_usage
);
85 sscanf(av
[1], "%d", &stage1
) != 1 ||
86 ! (0 <= stage1
&& stage1
<= 3) ||
87 sscanf(av
[2], "%d", &stage2
) != 1 ||
88 ! (0 <= stage2
&& stage2
<= 3))
89 usage(diff_stages_usage
);
91 av
+= 3; /* The rest from av[0] are for paths restriction. */
92 diff_options
.paths
= av
;
94 if (diff_setup_done(&diff_options
) < 0)
95 usage(diff_stages_usage
);
97 diff_stages(stage1
, stage2
);
98 diffcore_std(&diff_options
);
99 diff_flush(&diff_options
);