2 * Copyright (C) 2005 Junio C Hamano
9 static int detect_rename
= 0;
11 static int parse_oneside_change(const char *cp
, int *mode
,
12 unsigned char *sha1
, char *path
)
17 while ((ch
= *cp
) && '0' <= ch
&& ch
<= '7') {
18 m
= (m
<< 3) | (ch
- '0');
22 if (strncmp(cp
, "\tblob\t", 6))
25 if (get_sha1_hex(cp
, sha1
))
34 static int parse_diff_raw_output(const char *buf
)
37 unsigned char old_sha1
[20], new_sha1
[20];
39 int ch
, old_mode
, new_mode
;
46 parse_oneside_change(cp
, &new_mode
, new_sha1
, path
);
47 diff_addremove('+', new_mode
, new_sha1
, path
, NULL
);
50 parse_oneside_change(cp
, &old_mode
, old_sha1
, path
);
51 diff_addremove('-', old_mode
, old_sha1
, path
, NULL
);
54 old_mode
= new_mode
= 0;
55 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
56 old_mode
= (old_mode
<< 3) | (ch
- '0');
59 if (strncmp(cp
, "->", 2))
62 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
63 new_mode
= (new_mode
<< 3) | (ch
- '0');
66 if (strncmp(cp
, "\tblob\t", 6))
69 if (get_sha1_hex(cp
, old_sha1
))
72 if (strncmp(cp
, "->", 2))
75 if (get_sha1_hex(cp
, new_sha1
))
81 diff_change(old_mode
, new_mode
, old_sha1
, new_sha1
, path
, 0);
89 static const char *diff_helper_usage
=
90 "git-diff-helper [-z] [-R] [-M] paths...";
92 int main(int ac
, const char **av
) {
95 int line_termination
= '\n';
99 while (1 < ac
&& av
[1][0] == '-') {
102 else if (av
[1][1] == 'z')
103 line_termination
= 0;
104 else if (av
[1][1] == 'M')
107 usage(diff_helper_usage
);
110 /* the remaining parameters are paths patterns */
112 diff_setup(detect_rename
, 0, reverse
, av
+1, ac
-1);
116 read_line(&sb
, stdin
, line_termination
);
119 status
= parse_diff_raw_output(sb
.buf
);
122 printf("%s%c", sb
.buf
, line_termination
);