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
, const char **pathspec
)
17 while (i
< active_nr
) {
18 struct cache_entry
*ce
, *stages
[4] = { NULL
, };
19 struct cache_entry
*one
, *two
;
24 skip
= !ce_path_match(ce
, pathspec
);
28 int stage
= ce_stage(ce
);
33 if (ce_namelen(ce
) != len
||
34 memcmp(name
, ce
->name
, len
))
40 if (skip
|| (!one
&& !two
))
43 diff_addremove(&diff_options
, '+', ntohl(two
->ce_mode
),
44 two
->sha1
, name
, NULL
);
46 diff_addremove(&diff_options
, '-', ntohl(one
->ce_mode
),
47 one
->sha1
, name
, NULL
);
48 else if (memcmp(one
->sha1
, two
->sha1
, 20) ||
49 (one
->ce_mode
!= two
->ce_mode
) ||
50 diff_options
.find_copies_harder
)
51 diff_change(&diff_options
,
52 ntohl(one
->ce_mode
), ntohl(two
->ce_mode
),
53 one
->sha1
, two
->sha1
, name
, NULL
);
57 int main(int ac
, const char **av
)
60 const char *prefix
= setup_git_directory();
61 const char **pathspec
= NULL
;
63 git_config(git_diff_config
);
65 diff_setup(&diff_options
);
66 while (1 < ac
&& av
[1][0] == '-') {
67 const char *arg
= av
[1];
68 if (!strcmp(arg
, "-r"))
72 diff_opt_cnt
= diff_opt_parse(&diff_options
,
75 usage(diff_stages_usage
);
76 else if (diff_opt_cnt
) {
82 usage(diff_stages_usage
);
88 sscanf(av
[1], "%d", &stage1
) != 1 ||
89 ! (0 <= stage1
&& stage1
<= 3) ||
90 sscanf(av
[2], "%d", &stage2
) != 1 ||
91 ! (0 <= stage2
&& stage2
<= 3))
92 usage(diff_stages_usage
);
94 av
+= 3; /* The rest from av[0] are for paths restriction. */
95 pathspec
= get_pathspec(prefix
, av
);
97 if (diff_setup_done(&diff_options
) < 0)
98 usage(diff_stages_usage
);
100 diff_stages(stage1
, stage2
, pathspec
);
101 diffcore_std(&diff_options
);
102 diff_flush(&diff_options
);