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) {
21 while (1 < ac && av[1][0] == '-') {
23 line_termination = inter_name_termination = 0;
24 else if (av[1][1] == 'S') {
27 else if (!strcmp(av[1], "--pickaxe-all"))
28 pickaxe_opts = DIFF_PICKAXE_ALL;
30 usage(diff_helper_usage);
33 /* the remaining parameters are paths patterns */
37 unsigned old_mode, new_mode;
38 unsigned char old_sha1[20], new_sha1[20];
39 char old_path[PATH_MAX];
40 int status, score, two_paths;
41 char new_path[PATH_MAX];
46 read_line(&sb, stdin, line_termination);
51 /* parse the first part up to the status */
53 old_mode = new_mode = 0;
54 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
55 old_mode = (old_mode << 3) | (ch - '0');
60 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
61 new_mode = (new_mode << 3) | (ch - '0');
66 if (get_sha1_hex(cp, old_sha1))
71 if (get_sha1_hex(cp, new_sha1))
77 if (!strchr("MCRNDU", status))
79 two_paths = score = 0;
80 if (status == 'R' || status == 'C') {
82 sscanf(cp, "%d", &score);
83 if (line_termination) {
85 inter_name_termination);
91 if (*cp++ != inter_name_termination)
95 if (!line_termination) {
96 read_line(&sb, stdin, line_termination);
99 strcpy(old_path, sb.buf);
102 strcpy(old_path, cp);
104 ep = strchr(cp, inter_name_termination);
107 strncpy(old_path, cp, ep-cp);
112 /* second pathname */
114 strcpy(new_path, old_path);
116 if (!line_termination) {
117 read_line(&sb, stdin,
121 strcpy(new_path, sb.buf);
124 strcpy(new_path, cp);
126 diff_helper_input(old_mode, new_mode,
128 old_path, status, score,
133 diffcore_pickaxe(pickaxe, pickaxe_opts);
135 diffcore_pathspec(av + 1);
136 diff_flush(DIFF_FORMAT_PATCH, 0);
137 printf("%s\n", sb.buf);
140 diffcore_pickaxe(pickaxe, pickaxe_opts);
142 diffcore_pathspec(av + 1);
143 diff_flush(DIFF_FORMAT_PATCH, 0);