summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Santi Béjar <sbejar@gmail.com>2006-07-04 11:02:22 +0200
committerLibravatar Junio C Hamano <junkio@cox.net>2006-07-04 03:14:23 -0700
commit3dd4e7320de037a5b0adf3c53fbf5baf94a6c540 (patch)
tree413e2b40f975040e98a21db8d4634aa6dd5e3171
parentMerge branch 'master' into js/merge-base (diff)
downloadtgif-3dd4e7320de037a5b0adf3c53fbf5baf94a6c540.tar.xz
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>
-rw-r--r--builtin-rev-parse.c65
1 files changed, 47 insertions, 18 deletions
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 5f5ade45ae..4377d357c4 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -164,6 +164,51 @@ static int show_file(const char *arg)
return 0;
}
+static int try_difference(char *arg)
+{
+ char *dotdot;
+ unsigned char sha1[20];
+ unsigned char end[20];
+ const char *next;
+ const char *this;
+ int symmetric;
+
+ if (!(dotdot = strstr(arg, "..")))
+ return 0;
+ next = dotdot + 2;
+ this = arg;
+ symmetric = (*next == '.');
+
+ *dotdot = 0;
+ next += symmetric;
+
+ if (!*next)
+ next = "HEAD";
+ if (dotdot == arg)
+ this = "HEAD";
+ if (!get_sha1(this, sha1) && !get_sha1(next, end)) {
+ show_rev(NORMAL, end, next);
+ show_rev(symmetric ? NORMAL : REVERSED, sha1, this);
+ if (symmetric) {
+ struct commit_list *exclude;
+ struct commit *a, *b;
+ a = lookup_commit_reference(sha1);
+ b = lookup_commit_reference(end);
+ exclude = get_merge_bases(a, b, 1);
+ while (exclude) {
+ struct commit_list *n = exclude->next;
+ show_rev(REVERSED,
+ exclude->item->object.sha1,NULL);
+ free(exclude);
+ exclude = n;
+ }
+ }
+ return 1;
+ }
+ *dotdot = '.';
+ return 0;
+}
+
int cmd_rev_parse(int argc, const char **argv, char **envp)
{
int i, as_is = 0, verify = 0;
@@ -174,7 +219,6 @@ int cmd_rev_parse(int argc, const char **argv, char **envp)
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
- char *dotdot;
if (as_is) {
if (show_file(arg) && as_is < 2)
@@ -326,23 +370,8 @@ int cmd_rev_parse(int argc, const char **argv, char **envp)
}
/* Not a flag argument */
- dotdot = strstr(arg, "..");
- if (dotdot) {
- unsigned char end[20];
- const char *next = dotdot + 2;
- const char *this = arg;
- *dotdot = 0;
- if (!*next)
- next = "HEAD";
- if (dotdot == arg)
- this = "HEAD";
- if (!get_sha1(this, sha1) && !get_sha1(next, end)) {
- show_rev(NORMAL, end, next);
- show_rev(REVERSED, sha1, this);
- continue;
- }
- *dotdot = '.';
- }
+ if (try_difference(arg))
+ continue;
if (!get_sha1(arg, sha1)) {
show_rev(NORMAL, sha1, arg);
continue;