2 * Copyright (C) 2005 Junio C Hamano
7 #include "diffcore.h" /* just for MAX_SCORE */
9 static const char *pickaxe = NULL;
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') {
28 usage(diff_helper_usage);
31 /* the remaining parameters are paths patterns */
35 unsigned old_mode, new_mode;
36 unsigned char old_sha1[20], new_sha1[20];
37 char old_path[PATH_MAX];
38 int status, score, two_paths;
39 char new_path[PATH_MAX];
44 read_line(&sb, stdin, line_termination);
49 /* parse the first part up to the status */
51 old_mode = new_mode = 0;
52 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
53 old_mode = (old_mode << 3) | (ch - '0');
58 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
59 new_mode = (new_mode << 3) | (ch - '0');
64 if (get_sha1_hex(cp, old_sha1))
69 if (get_sha1_hex(cp, new_sha1))
75 if (!strchr("MCRNDU", status))
77 two_paths = score = 0;
78 if (status == 'R' || status == 'C') {
80 sscanf(cp, "%d", &score);
81 score = score * MAX_SCORE / 100;
82 if (line_termination) {
84 inter_name_termination);
90 if (*cp++ != inter_name_termination)
94 if (!line_termination) {
95 read_line(&sb, stdin, line_termination);
98 strcpy(old_path, sb.buf);
101 strcpy(old_path, cp);
103 ep = strchr(cp, inter_name_termination);
106 strncpy(old_path, cp, ep-cp);
111 /* second pathname */
113 strcpy(new_path, old_path);
115 if (!line_termination) {
116 read_line(&sb, stdin,
120 strcpy(new_path, sb.buf);
123 strcpy(new_path, cp);
125 diff_helper_input(old_mode, new_mode,
127 old_path, status, score,
132 diffcore_pickaxe(pickaxe);
134 diffcore_pathspec(av + 1);
135 diff_flush(DIFF_FORMAT_PATCH, 0);
136 printf("%s\n", sb.buf);
139 diffcore_pickaxe(pickaxe);
141 diffcore_pathspec(av + 1);
142 diff_flush(DIFF_FORMAT_PATCH, 0);