Code

Avoid unnecessary "if-before-free" tests.
[git.git] / sha1_name.c
index 13e11645e1fd6b61812cc3e88d2ad6cd42cad9ce..9d088cc2caa24ad79b927b9078771e4f0fb22a69 100644 (file)
@@ -494,8 +494,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;
@@ -578,8 +581,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);
@@ -617,9 +623,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 {
@@ -636,8 +642,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);
@@ -695,7 +700,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++;