Teach git mergetool to use custom commands defined at config time
[gitweb.git] / sha1_name.c
index bd8fc05c4b9727ad4d14b20127012b53a9ef90ee..8358ba2069746943fcf45d35222d95fab7a8231d 100644 (file)
@@ -192,26 +192,25 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
 
 const char *find_unique_abbrev(const unsigned char *sha1, int len)
 {
-       int status, is_null;
+       int status, exists;
        static char hex[41];
 
-       is_null = is_null_sha1(sha1);
+       exists = has_sha1_file(sha1);
        memcpy(hex, sha1_to_hex(sha1), 40);
        if (len == 40 || !len)
                return hex;
        while (len < 40) {
                unsigned char sha1_ret[20];
                status = get_short_sha1(hex, len, sha1_ret, 1);
-               if (!status ||
-                   (is_null && status != SHORT_NAME_AMBIGUOUS)) {
+               if (exists
+                   ? !status
+                   : status == SHORT_NAME_NOT_FOUND) {
                        hex[len] = 0;
                        return hex;
                }
-               if (status != SHORT_NAME_AMBIGUOUS)
-                       return NULL;
                len++;
        }
-       return NULL;
+       return hex;
 }
 
 static int ambiguous_path(const char *path, int len)
@@ -239,23 +238,13 @@ static int ambiguous_path(const char *path, int len)
        return slash;
 }
 
-static const char *ref_fmt[] = {
-       "%.*s",
-       "refs/%.*s",
-       "refs/tags/%.*s",
-       "refs/heads/%.*s",
-       "refs/remotes/%.*s",
-       "refs/remotes/%.*s/HEAD",
-       NULL
-};
-
 int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
 {
        const char **p, *r;
        int refs_found = 0;
 
        *ref = NULL;
-       for (p = ref_fmt; *p; p++) {
+       for (p = ref_rev_parse_rules; *p; p++) {
                unsigned char sha1_from_ref[20];
                unsigned char *this_result;
 
@@ -277,7 +266,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
        int logs_found = 0;
 
        *log = NULL;
-       for (p = ref_fmt; *p; p++) {
+       for (p = ref_rev_parse_rules; *p; p++) {
                struct stat st;
                unsigned char hash[20];
                char path[PATH_MAX];
@@ -504,8 +493,11 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
                                return error("%.*s: expected %s type, but the object dereferences to %s type",
                                             len, name, typename(expected_type),
                                             typename(o->type));
+                       if (!o)
+                               return -1;
                        if (!o->parsed)
-                               parse_object(o->sha1);
+                               if (!parse_object(o->sha1))
+                                       return -1;
                }
        }
        return 0;
@@ -588,8 +580,11 @@ static int handle_one_ref(const char *path,
        struct object *object = parse_object(sha1);
        if (!object)
                return 0;
-       if (object->type == OBJ_TAG)
+       if (object->type == OBJ_TAG) {
                object = deref_tag(object, path, strlen(path));
+               if (!object)
+                       return 0;
+       }
        if (object->type != OBJ_COMMIT)
                return 0;
        insert_by_date((struct commit *)object, list);
@@ -627,9 +622,9 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
                unsigned long size;
 
                commit = pop_most_recent_commit(&list, ONELINE_SEEN);
-               parse_object(commit->object.sha1);
-               if (temp_commit_buffer)
-                       free(temp_commit_buffer);
+               if (!parse_object(commit->object.sha1))
+                       continue;
+               free(temp_commit_buffer);
                if (commit->buffer)
                        p = commit->buffer;
                else {
@@ -646,8 +641,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
                        break;
                }
        }
-       if (temp_commit_buffer)
-               free(temp_commit_buffer);
+       free(temp_commit_buffer);
        free_commit_list(list);
        for (l = backup; l; l = l->next)
                clear_commit_marks(l->item, ONELINE_SEEN);
@@ -705,7 +699,7 @@ int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned *mode)
                                break;
                        if (ce_stage(ce) == stage) {
                                hashcpy(sha1, ce->sha1);
-                               *mode = ntohl(ce->ce_mode);
+                               *mode = ce->ce_mode;
                                return 0;
                        }
                        pos++;