]> git.ipfire.org Git - thirdparty/git.git/blame - diff-helper.c
[PATCH] Unify usage strings declaration
[thirdparty/git.git] / diff-helper.c
CommitLineData
be3cfa85
JH
1/*
2 * Copyright (C) 2005 Junio C Hamano
3 */
d1df5743
JH
4#include "cache.h"
5#include "strbuf.h"
6#include "diff.h"
7
057c7d30 8static const char *pickaxe = NULL;
367cec1c 9static int pickaxe_opts = 0;
ce240675 10static const char *orderfile = NULL;
f2ce9fde 11static const char *diff_filter = NULL;
81e50eab
JH
12static int line_termination = '\n';
13static int inter_name_termination = '\t';
915838c3 14
ce240675
JH
15static void flush_them(int ac, const char **av)
16{
f2ce9fde
JH
17 diffcore_std_no_resolve(av + 1,
18 pickaxe, pickaxe_opts,
19 orderfile, diff_filter);
e68b6f15 20 diff_flush(DIFF_FORMAT_PATCH, '\n');
ce240675
JH
21}
22
4d1f1190 23static const char diff_helper_usage[] =
232b75ab 24"git-diff-helper [-z] [-O<orderfile>] [-S<string>] [--pickaxe-all] [<path>...]";
d1df5743 25
91a6eaa0 26int main(int ac, const char **av) {
b6d8f309 27 struct strbuf sb;
2bc25641 28 const char *garbage_flush_format;
d1df5743 29
b6d8f309 30 strbuf_init(&sb);
d1df5743
JH
31
32 while (1 < ac && av[1][0] == '-') {
b6d8f309 33 if (av[1][1] == 'z')
81e50eab 34 line_termination = inter_name_termination = 0;
52e95789
JH
35 else if (av[1][1] == 'S') {
36 pickaxe = av[1] + 2;
37 }
367cec1c
JH
38 else if (!strcmp(av[1], "--pickaxe-all"))
39 pickaxe_opts = DIFF_PICKAXE_ALL;
f2ce9fde
JH
40 else if (!strncmp(av[1], "--diff-filter=", 14))
41 diff_filter = av[1] + 14;
42 else if (!strncmp(av[1], "-O", 2))
43 orderfile = av[1] + 2;
d1df5743 44 else
902b92e0 45 usage(diff_helper_usage);
d1df5743
JH
46 ac--; av++;
47 }
2bc25641
JH
48 garbage_flush_format = (line_termination == 0) ? "%s" : "%s\n";
49
d1df5743
JH
50 /* the remaining parameters are paths patterns */
51
b6d8f309 52 diff_setup(0);
d1df5743 53 while (1) {
b6d8f309
JH
54 unsigned old_mode, new_mode;
55 unsigned char old_sha1[20], new_sha1[20];
56 char old_path[PATH_MAX];
57 int status, score, two_paths;
58 char new_path[PATH_MAX];
59
60 int ch;
61 char *cp, *ep;
62
63 read_line(&sb, stdin, line_termination);
64 if (sb.eof)
d1df5743 65 break;
b6d8f309 66 switch (sb.buf[0]) {
81e50eab 67 case ':':
b6d8f309
JH
68 /* parse the first part up to the status */
69 cp = sb.buf + 1;
70 old_mode = new_mode = 0;
71 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
72 old_mode = (old_mode << 3) | (ch - '0');
73 cp++;
74 }
75 if (*cp++ != ' ')
81e50eab 76 break;
b6d8f309
JH
77 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
78 new_mode = (new_mode << 3) | (ch - '0');
79 cp++;
80 }
81 if (*cp++ != ' ')
81e50eab 82 break;
b6d8f309
JH
83 if (get_sha1_hex(cp, old_sha1))
84 break;
85 cp += 40;
86 if (*cp++ != ' ')
87 break;
88 if (get_sha1_hex(cp, new_sha1))
89 break;
90 cp += 40;
91 if (*cp++ != ' ')
92 break;
93 status = *cp++;
94 if (!strchr("MCRNDU", status))
95 break;
96 two_paths = score = 0;
e7baa4f4
JH
97 if (status == DIFF_STATUS_RENAMED ||
98 status == DIFF_STATUS_COPIED)
b6d8f309 99 two_paths = 1;
b6d8f309 100
ddafa7e9
JH
101 /* pick up score if exists */
102 if (sscanf(cp, "%d", &score) != 1)
103 score = 0;
104 cp = strchr(cp,
105 inter_name_termination);
106 if (!cp)
107 break;
b6d8f309
JH
108 if (*cp++ != inter_name_termination)
109 break;
110
111 /* first pathname */
112 if (!line_termination) {
113 read_line(&sb, stdin, line_termination);
114 if (sb.eof)
115 break;
116 strcpy(old_path, sb.buf);
117 }
118 else if (!two_paths)
119 strcpy(old_path, cp);
120 else {
121 ep = strchr(cp, inter_name_termination);
122 if (!ep)
123 break;
124 strncpy(old_path, cp, ep-cp);
125 old_path[ep-cp] = 0;
126 cp = ep + 1;
127 }
128
129 /* second pathname */
130 if (!two_paths)
131 strcpy(new_path, old_path);
132 else {
133 if (!line_termination) {
134 read_line(&sb, stdin,
135 line_termination);
136 if (sb.eof)
137 break;
138 strcpy(new_path, sb.buf);
139 }
140 else
141 strcpy(new_path, cp);
142 }
143 diff_helper_input(old_mode, new_mode,
144 old_sha1, new_sha1,
145 old_path, status, score,
146 new_path);
147 continue;
e11b29c5 148 }
ce240675 149 flush_them(ac, av);
2bc25641 150 printf(garbage_flush_format, sb.buf);
d1df5743 151 }
ce240675 152 flush_them(ac, av);
d1df5743
JH
153 return 0;
154}