Merge branch 'ks/branch-set-upstream'
[gitweb.git] / builtin / rev-parse.c
index 7f965fe74e5e98496522eddb3ef87fa831265e17..4f49e96bfd0166aeb6f9875a688ff0dd83d631b5 100644 (file)
@@ -133,7 +133,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
                        struct object_id discard;
                        char *full;
 
-                       switch (dwim_ref(name, strlen(name), discard.hash, &full)) {
+                       switch (dwim_ref(name, strlen(name), &discard, &full)) {
                        case 0:
                                /*
                                 * Not found -- not a ref.  We could
@@ -159,7 +159,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
                }
        }
        else if (abbrev)
-               show_with_type(type, find_unique_abbrev(oid->hash, abbrev));
+               show_with_type(type, find_unique_abbrev(oid, abbrev));
        else
                show_with_type(type, oid_to_hex(oid));
 }
@@ -243,28 +243,28 @@ static int show_file(const char *arg, int output_prefix)
 static int try_difference(const char *arg)
 {
        char *dotdot;
-       struct object_id oid;
-       struct object_id end;
-       const char *next;
-       const char *this;
+       struct object_id start_oid;
+       struct object_id end_oid;
+       const char *end;
+       const char *start;
        int symmetric;
        static const char head_by_default[] = "HEAD";
 
        if (!(dotdot = strstr(arg, "..")))
                return 0;
-       next = dotdot + 2;
-       this = arg;
-       symmetric = (*next == '.');
+       end = dotdot + 2;
+       start = arg;
+       symmetric = (*end == '.');
 
        *dotdot = 0;
-       next += symmetric;
+       end += symmetric;
 
-       if (!*next)
-               next = head_by_default;
+       if (!*end)
+               end = head_by_default;
        if (dotdot == arg)
-               this = head_by_default;
+               start = head_by_default;
 
-       if (this == head_by_default && next == head_by_default &&
+       if (start == head_by_default && end == head_by_default &&
            !symmetric) {
                /*
                 * Just ".."?  That is not a range but the
@@ -274,14 +274,18 @@ static int try_difference(const char *arg)
                return 0;
        }
 
-       if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, end.hash)) {
-               show_rev(NORMAL, &end, next);
-               show_rev(symmetric ? NORMAL : REVERSED, &oid, this);
+       if (!get_oid_committish(start, &start_oid) && !get_oid_committish(end, &end_oid)) {
+               show_rev(NORMAL, &end_oid, end);
+               show_rev(symmetric ? NORMAL : REVERSED, &start_oid, start);
                if (symmetric) {
                        struct commit_list *exclude;
                        struct commit *a, *b;
-                       a = lookup_commit_reference(&oid);
-                       b = lookup_commit_reference(&end);
+                       a = lookup_commit_reference(&start_oid);
+                       b = lookup_commit_reference(&end_oid);
+                       if (!a || !b) {
+                               *dotdot = '.';
+                               return 0;
+                       }
                        exclude = get_merge_bases(a, b);
                        while (exclude) {
                                struct commit *commit = pop_commit(&exclude);
@@ -328,12 +332,12 @@ static int try_parent_shorthands(const char *arg)
                return 0;
 
        *dotdot = 0;
-       if (get_sha1_committish(arg, oid.hash)) {
+       if (get_oid_committish(arg, &oid) ||
+           !(commit = lookup_commit_reference(&oid))) {
                *dotdot = '^';
                return 0;
        }
 
-       commit = lookup_commit_reference(&oid);
        if (exclude_parent &&
            exclude_parent > commit_list_count(commit->parents)) {
                *dotdot = '^';
@@ -387,6 +391,14 @@ static const char *skipspaces(const char *s)
        return s;
 }
 
+static char *findspace(const char *s)
+{
+       for (; *s; s++)
+               if (isspace(*s))
+                       return (char*)s;
+       return NULL;
+}
+
 static int cmd_parseopt(int argc, const char **argv, const char *prefix)
 {
        static int keep_dashdash = 0, stop_at_non_option = 0;
@@ -434,7 +446,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
        /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
        while (strbuf_getline(&sb, stdin) != EOF) {
                const char *s;
-               const char *help;
+               char *help;
                struct option *o;
 
                if (!sb.len)
@@ -444,15 +456,17 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
                memset(opts + onb, 0, sizeof(opts[onb]));
 
                o = &opts[onb++];
-               help = strchr(sb.buf, ' ');
-               if (!help || *sb.buf == ' ') {
+               help = findspace(sb.buf);
+               if (!help || sb.buf == help) {
                        o->type = OPTION_GROUP;
                        o->help = xstrdup(skipspaces(sb.buf));
                        continue;
                }
 
+               *help = '\0';
+
                o->type = OPTION_CALLBACK;
-               o->help = xstrdup(skipspaces(help));
+               o->help = xstrdup(skipspaces(help+1));
                o->value = &parsed;
                o->flags = PARSE_OPT_NOARG;
                o->callback = &parseopt_dump;
@@ -506,7 +520,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
                        PARSE_OPT_SHELL_EVAL);
 
        strbuf_addstr(&parsed, " --");
-       sq_quote_argv(&parsed, argv, 0);
+       sq_quote_argv(&parsed, argv);
        puts(parsed.buf);
        return 0;
 }
@@ -516,7 +530,7 @@ static int cmd_sq_quote(int argc, const char **argv)
        struct strbuf buf = STRBUF_INIT;
 
        if (argc)
-               sq_quote_argv(&buf, argv, 0);
+               sq_quote_argv(&buf, argv);
        printf("%s\n", buf.buf);
        strbuf_release(&buf);
 
@@ -702,7 +716,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                        }
                        if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) {
                                quiet = 1;
-                               flags |= GET_SHA1_QUIETLY;
+                               flags |= GET_OID_QUIETLY;
                                continue;
                        }
                        if (opt_with_value(arg, "--short", &arg)) {
@@ -868,12 +882,17 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                                : "false");
                                continue;
                        }
+                       if (!strcmp(arg, "--is-shallow-repository")) {
+                               printf("%s\n", is_repository_shallow() ? "true"
+                                               : "false");
+                               continue;
+                       }
                        if (!strcmp(arg, "--shared-index-path")) {
                                if (read_cache() < 0)
                                        die(_("Could not read the index"));
                                if (the_index.split_index) {
-                                       const unsigned char *sha1 = the_index.split_index->base_sha1;
-                                       const char *path = git_path("sharedindex.%s", sha1_to_hex(sha1));
+                                       const struct object_id *oid = &the_index.split_index->base_oid;
+                                       const char *path = git_path("sharedindex.%s", oid_to_hex(oid));
                                        strbuf_reset(&buf);
                                        puts(relative_path(path, prefix, &buf));
                                }
@@ -911,7 +930,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                        name++;
                        type = REVERSED;
                }
-               if (!get_sha1_with_context(name, flags, oid.hash, &unused)) {
+               if (!get_oid_with_context(name, flags, &oid, &unused)) {
                        if (verify)
                                revs_count++;
                        else