2 * Copyright (C) 2005 Junio C Hamano
8 static const char *pickaxe
= NULL
;
9 static int pickaxe_opts
= 0;
10 static const char *orderfile
= NULL
;
11 static int line_termination
= '\n';
12 static int inter_name_termination
= '\t';
14 static void flush_them(int ac
, const char **av
)
17 0, 0, /* no renames */
18 pickaxe
, pickaxe_opts
,
21 diff_flush(DIFF_FORMAT_PATCH
, 0);
24 static const char *diff_helper_usage
=
25 "git-diff-helper [-z] [-S<string>] [-O<orderfile>] paths...";
27 int main(int ac
, const char **av
) {
29 const char *garbage_flush_format
;
33 while (1 < ac
&& av
[1][0] == '-') {
35 line_termination
= inter_name_termination
= 0;
36 else if (av
[1][1] == 'S') {
39 else if (!strcmp(av
[1], "--pickaxe-all"))
40 pickaxe_opts
= DIFF_PICKAXE_ALL
;
42 usage(diff_helper_usage
);
45 garbage_flush_format
= (line_termination
== 0) ? "%s" : "%s\n";
47 /* the remaining parameters are paths patterns */
51 unsigned old_mode
, new_mode
;
52 unsigned char old_sha1
[20], new_sha1
[20];
53 char old_path
[PATH_MAX
];
54 int status
, score
, two_paths
;
55 char new_path
[PATH_MAX
];
60 read_line(&sb
, stdin
, line_termination
);
65 /* parse the first part up to the status */
67 old_mode
= new_mode
= 0;
68 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
69 old_mode
= (old_mode
<< 3) | (ch
- '0');
74 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
75 new_mode
= (new_mode
<< 3) | (ch
- '0');
80 if (get_sha1_hex(cp
, old_sha1
))
85 if (get_sha1_hex(cp
, new_sha1
))
91 if (!strchr("MCRNDU", status
))
93 two_paths
= score
= 0;
94 if (status
== 'R' || status
== 'C')
97 /* pick up score if exists */
98 if (sscanf(cp
, "%d", &score
) != 1)
101 inter_name_termination
);
104 if (*cp
++ != inter_name_termination
)
108 if (!line_termination
) {
109 read_line(&sb
, stdin
, line_termination
);
112 strcpy(old_path
, sb
.buf
);
115 strcpy(old_path
, cp
);
117 ep
= strchr(cp
, inter_name_termination
);
120 strncpy(old_path
, cp
, ep
-cp
);
125 /* second pathname */
127 strcpy(new_path
, old_path
);
129 if (!line_termination
) {
130 read_line(&sb
, stdin
,
134 strcpy(new_path
, sb
.buf
);
137 strcpy(new_path
, cp
);
139 diff_helper_input(old_mode
, new_mode
,
141 old_path
, status
, score
,
146 printf(garbage_flush_format
, sb
.buf
);