2 * Copyright (C) 2005 Junio C Hamano
8 static const char *pickaxe = NULL;
9 static int line_termination = '\n';
10 static int inter_name_termination = '\t';
12 static const char *diff_helper_usage =
13 "git-diff-helper [-z] [-S<string>] paths...";
15 int main(int ac, const char **av) {
20 while (1 < ac && av[1][0] == '-') {
22 line_termination = inter_name_termination = 0;
23 else if (av[1][1] == 'S') {
27 usage(diff_helper_usage);
30 /* the remaining parameters are paths patterns */
34 unsigned old_mode, new_mode;
35 unsigned char old_sha1[20], new_sha1[20];
36 char old_path[PATH_MAX];
37 int status, score, two_paths;
38 char new_path[PATH_MAX];
43 read_line(&sb, stdin, line_termination);
48 /* parse the first part up to the status */
50 old_mode = new_mode = 0;
51 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
52 old_mode = (old_mode << 3) | (ch - '0');
57 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
58 new_mode = (new_mode << 3) | (ch - '0');
63 if (get_sha1_hex(cp, old_sha1))
68 if (get_sha1_hex(cp, new_sha1))
74 if (!strchr("MCRNDU", status))
76 two_paths = score = 0;
77 if (status == 'R' || status == 'C') {
79 sscanf(cp, "%d", &score);
80 if (line_termination) {
82 inter_name_termination);
88 if (*cp++ != inter_name_termination)
92 if (!line_termination) {
93 read_line(&sb, stdin, line_termination);
96 strcpy(old_path, sb.buf);
101 ep = strchr(cp, inter_name_termination);
104 strncpy(old_path, cp, ep-cp);
109 /* second pathname */
111 strcpy(new_path, old_path);
113 if (!line_termination) {
114 read_line(&sb, stdin,
118 strcpy(new_path, sb.buf);
121 strcpy(new_path, cp);
123 diff_helper_input(old_mode, new_mode,
125 old_path, status, score,
130 diffcore_pickaxe(pickaxe);
132 diffcore_pathspec(av + 1);
133 diff_flush(DIFF_FORMAT_PATCH, 0);
134 printf("%s\n", sb.buf);
137 diffcore_pickaxe(pickaxe);
139 diffcore_pathspec(av + 1);
140 diff_flush(DIFF_FORMAT_PATCH, 0);