]> git.proxmox.com Git - libgit2.git/blobdiff - src/revparse.c
treebuilder: fix memory leaks in `write_with_buffer`
[libgit2.git] / src / revparse.c
index 60872e1875cb220c644ace473397bd1dfd6d4ed5..d5511b47bcf9144cba7579814d0c5fe78f4a94c2 100644 (file)
@@ -46,11 +46,11 @@ static int build_regex(regex_t *regex, const char *pattern)
        int error;
 
        if (*pattern == '\0') {
-               giterr_set(GITERR_REGEX, "Empty pattern");
+               giterr_set(GITERR_REGEX, "empty pattern");
                return GIT_EINVALIDSPEC;
        }
 
-       error = regcomp(regex, pattern, REG_EXTENDED);
+       error = p_regcomp(regex, pattern, REG_EXTENDED);
        if (!error)
                return 0;
 
@@ -118,7 +118,7 @@ static int revparse_lookup_object(
        if ((error = maybe_describe(object_out, repo, spec)) != GIT_ENOTFOUND)
                return error;
 
-       giterr_set(GITERR_REFERENCE, "Revspec '%s' not found.", spec);
+       giterr_set(GITERR_REFERENCE, "revspec '%s' not found", spec);
        return GIT_ENOTFOUND;
 }
 
@@ -205,7 +205,6 @@ cleanup:
 static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t identifier)
 {
        git_reflog *reflog;
-       int error = -1;
        size_t numentries;
        const git_reflog_entry *entry;
        bool search_by_pos = (identifier <= 100000000);
@@ -216,21 +215,11 @@ static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t ide
        numentries = git_reflog_entrycount(reflog);
 
        if (search_by_pos) {
-               if (numentries < identifier + 1) {
-                       giterr_set(
-                               GITERR_REFERENCE,
-                               "Reflog for '%s' has only %"PRIuZ" entries, asked for %"PRIuZ,
-                               git_reference_name(ref), numentries, identifier);
-
-                       error = GIT_ENOTFOUND;
-                       goto cleanup;
-               }
+               if (numentries < identifier + 1)
+                       goto notfound;
 
                entry = git_reflog_entry_byindex(reflog, identifier);
                git_oid_cpy(oid, git_reflog_entry_id_new(entry));
-               error = 0;
-               goto cleanup;
-
        } else {
                size_t i;
                git_time commit_time;
@@ -243,16 +232,24 @@ static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t ide
                                continue;
 
                        git_oid_cpy(oid, git_reflog_entry_id_new(entry));
-                       error = 0;
-                       goto cleanup;
+                       break;
                }
 
-               error = GIT_ENOTFOUND;
+               if (i == numentries)
+                       goto notfound;
        }
 
-cleanup:
        git_reflog_free(reflog);
-       return error;
+       return 0;
+
+notfound:
+       giterr_set(
+               GITERR_REFERENCE,
+               "reflog for '%s' has only %"PRIuZ" entries, asked for %"PRIuZ,
+               git_reference_name(ref), numentries, identifier);
+
+       git_reflog_free(reflog);
+       return GIT_ENOTFOUND;
 }
 
 static int retrieve_revobject_from_reflog(git_object **out, git_reference **base_ref, git_repository *repo, const char *identifier, size_t position)
@@ -760,7 +757,7 @@ int revparse__ext(
                                         * TODO: support merge-stage path lookup (":2:Makefile")
                                         * and plain index blob lookup (:i-am/a/blob)
                                         */
-                                       giterr_set(GITERR_INVALID, "Unimplemented");
+                                       giterr_set(GITERR_INVALID, "unimplemented");
                                        error = GIT_ERROR;
                                        goto cleanup;
                                }
@@ -819,7 +816,7 @@ cleanup:
        if (error) {
                if (error == GIT_EINVALIDSPEC)
                        giterr_set(GITERR_INVALID,
-                               "Failed to parse revision specifier - Invalid pattern '%s'", spec);
+                               "failed to parse revision specifier - Invalid pattern '%s'", spec);
 
                git_object_free(base_rev);
                git_reference_free(reference);