@matheusbsbs / matheus-bagliano / commits / 3dd4e7320d
Fork 0

Teach rev-parse the ... syntax.

[jc: moved the difference code around into its own function.] Signed-off-by: Santi Béjar <sbejar@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Santi Béjar committed Jul 4, 2006 at 11:02 UTC 3dd4e7320de037a5b0adf3c53fbf5baf94a6c540
1 file changed +47 -18
builtin-rev-parse.c
+47 -18
@@ -164,6 +164,51 @@ static int show_file(const char *arg)
164 return 0;
165 }
166
167 +static int try_difference(char *arg)
168 +{
169 + char *dotdot;
170 + unsigned char sha1[20];
171 + unsigned char end[20];
172 + const char *next;
173 + const char *this;
174 + int symmetric;
175 +
176 + if (!(dotdot = strstr(arg, "..")))
177 + return 0;
178 + next = dotdot + 2;
179 + this = arg;
180 + symmetric = (*next == '.');
181 +
182 + *dotdot = 0;
183 + next += symmetric;
184 +
185 + if (!*next)
186 + next = "HEAD";
187 + if (dotdot == arg)
188 + this = "HEAD";
189 + if (!get_sha1(this, sha1) && !get_sha1(next, end)) {
190 + show_rev(NORMAL, end, next);
191 + show_rev(symmetric ? NORMAL : REVERSED, sha1, this);
192 + if (symmetric) {
193 + struct commit_list *exclude;
194 + struct commit *a, *b;
195 + a = lookup_commit_reference(sha1);
196 + b = lookup_commit_reference(end);
197 + exclude = get_merge_bases(a, b, 1);
198 + while (exclude) {
199 + struct commit_list *n = exclude->next;
200 + show_rev(REVERSED,
201 + exclude->item->object.sha1,NULL);
202 + free(exclude);
203 + exclude = n;
204 + }
205 + }
206 + return 1;
207 + }
208 + *dotdot = '.';
209 + return 0;
210 +}
211 +
212 int cmd_rev_parse(int argc, const char **argv, char **envp)
213 {
214 int i, as_is = 0, verify = 0;
@@ -174,7 +219,6 @@ int cmd_rev_parse(int argc, const char **argv, char **envp)
219
220 for (i = 1; i < argc; i++) {
221 const char *arg = argv[i];
177 - char *dotdot;
222
223 if (as_is) {
224 if (show_file(arg) && as_is < 2)
@@ -326,23 +370,8 @@ int cmd_rev_parse(int argc, const char **argv, char **envp)
370 }
371
372 /* Not a flag argument */
329 - dotdot = strstr(arg, "..");
330 - if (dotdot) {
331 - unsigned char end[20];
332 - const char *next = dotdot + 2;
333 - const char *this = arg;
334 - *dotdot = 0;
335 - if (!*next)
336 - next = "HEAD";
337 - if (dotdot == arg)
338 - this = "HEAD";
339 - if (!get_sha1(this, sha1) && !get_sha1(next, end)) {
340 - show_rev(NORMAL, end, next);
341 - show_rev(REVERSED, sha1, this);
342 - continue;
343 - }
344 - *dotdot = '.';
345 - }
373 + if (try_difference(arg))
374 + continue;
375 if (!get_sha1(arg, sha1)) {
376 show_rev(NORMAL, sha1, arg);
377 continue;