Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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>
  • Loading branch information...
commit 3dd4e7320de037a5b0adf3c53fbf5baf94a6c540 1 parent f23c75a
Santi Béjar authored Junio C Hamano committed

Showing 1 changed file with 47 additions and 18 deletions. Show diff stats Hide diff stats

  1. +47 18 builtin-rev-parse.c
65 builtin-rev-parse.c
@@ -164,6 +164,51 @@ static int show_file(const char *arg)
164 164 return 0;
165 165 }
166 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 +
167 212 int cmd_rev_parse(int argc, const char **argv, char **envp)
168 213 {
169 214 int i, as_is = 0, verify = 0;
@@ -174,7 +219,6 @@ int cmd_rev_parse(int argc, const char **argv, char **envp)
174 219
175 220 for (i = 1; i < argc; i++) {
176 221 const char *arg = argv[i];
177   - char *dotdot;
178 222
179 223 if (as_is) {
180 224 if (show_file(arg) && as_is < 2)
@@ -326,23 +370,8 @@ int cmd_rev_parse(int argc, const char **argv, char **envp)
326 370 }
327 371
328 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;
346 375 if (!get_sha1(arg, sha1)) {
347 376 show_rev(NORMAL, sha1, arg);
348 377 continue;

0 comments on commit 3dd4e73

Please sign in to comment.
Something went wrong with that request. Please try again.