2 * Copyright (C) 2005 Junio C Hamano
8 static const char *pickaxe
= NULL
;
9 static int pickaxe_opts
= 0;
10 static int line_termination
= '\n';
11 static int inter_name_termination
= '\t';
13 static const char *diff_helper_usage
=
14 "git-diff-helper [-z] [-S<string>] paths...";
16 int main(int ac
, const char **av
) {
18 const char *garbage_flush_format
;
22 while (1 < ac
&& av
[1][0] == '-') {
24 line_termination
= inter_name_termination
= 0;
25 else if (av
[1][1] == 'S') {
28 else if (!strcmp(av
[1], "--pickaxe-all"))
29 pickaxe_opts
= DIFF_PICKAXE_ALL
;
31 usage(diff_helper_usage
);
34 garbage_flush_format
= (line_termination
== 0) ? "%s" : "%s\n";
36 /* the remaining parameters are paths patterns */
40 unsigned old_mode
, new_mode
;
41 unsigned char old_sha1
[20], new_sha1
[20];
42 char old_path
[PATH_MAX
];
43 int status
, score
, two_paths
;
44 char new_path
[PATH_MAX
];
49 read_line(&sb
, stdin
, line_termination
);
54 /* parse the first part up to the status */
56 old_mode
= new_mode
= 0;
57 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
58 old_mode
= (old_mode
<< 3) | (ch
- '0');
63 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
64 new_mode
= (new_mode
<< 3) | (ch
- '0');
69 if (get_sha1_hex(cp
, old_sha1
))
74 if (get_sha1_hex(cp
, new_sha1
))
80 if (!strchr("MCRNDU", status
))
82 two_paths
= score
= 0;
83 if (status
== 'R' || status
== 'C')
86 /* pick up score if exists */
87 if (sscanf(cp
, "%d", &score
) != 1)
90 inter_name_termination
);
93 if (*cp
++ != inter_name_termination
)
97 if (!line_termination
) {
98 read_line(&sb
, stdin
, line_termination
);
101 strcpy(old_path
, sb
.buf
);
104 strcpy(old_path
, cp
);
106 ep
= strchr(cp
, inter_name_termination
);
109 strncpy(old_path
, cp
, ep
-cp
);
114 /* second pathname */
116 strcpy(new_path
, old_path
);
118 if (!line_termination
) {
119 read_line(&sb
, stdin
,
123 strcpy(new_path
, sb
.buf
);
126 strcpy(new_path
, cp
);
128 diff_helper_input(old_mode
, new_mode
,
130 old_path
, status
, score
,
135 diffcore_pathspec(av
+ 1);
137 diffcore_pickaxe(pickaxe
, pickaxe_opts
);
138 diff_flush(DIFF_FORMAT_PATCH
, 0);
139 printf(garbage_flush_format
, sb
.buf
);
142 diffcore_pathspec(av
+ 1);
144 diffcore_pickaxe(pickaxe
, pickaxe_opts
);
145 diff_flush(DIFF_FORMAT_PATCH
, 0);