Code

Revert "unpack-objects: prevent writing of inconsistent objects"
[git.git] / sha1_name.c
index c2805e736b3086a0e33271a4b5c73cea7d2c55cd..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)
@@ -625,8 +624,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
                commit = pop_most_recent_commit(&list, ONELINE_SEEN);
                if (!parse_object(commit->object.sha1))
                        continue;
-               if (temp_commit_buffer)
-                       free(temp_commit_buffer);
+               free(temp_commit_buffer);
                if (commit->buffer)
                        p = commit->buffer;
                else {
@@ -643,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);