Skip to content

Commit 3dd4e73

Browse files
sbejarJunio C Hamano
authored andcommitted
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>
1 parent f23c75a commit 3dd4e73

File tree

1 file changed

+47
-18
lines changed

1 file changed

+47
-18
lines changed

builtin-rev-parse.c

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,51 @@ static int show_file(const char *arg)
164164
return 0;
165165
}
166166

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+
167212
int cmd_rev_parse(int argc, const char **argv, char **envp)
168213
{
169214
int i, as_is = 0, verify = 0;
@@ -174,7 +219,6 @@ int cmd_rev_parse(int argc, const char **argv, char **envp)
174219

175220
for (i = 1; i < argc; i++) {
176221
const char *arg = argv[i];
177-
char *dotdot;
178222

179223
if (as_is) {
180224
if (show_file(arg) && as_is < 2)
@@ -326,23 +370,8 @@ int cmd_rev_parse(int argc, const char **argv, char **envp)
326370
}
327371

328372
/* 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;
346375
if (!get_sha1(arg, sha1)) {
347376
show_rev(NORMAL, sha1, arg);
348377
continue;

0 commit comments

Comments
 (0)