]> git.ipfire.org Git - thirdparty/git.git/blobdiff - sha1_name.c
t1503: use test_must_be_empty
[thirdparty/git.git] / sha1_name.c
index cc3941eb084863045e3af5de78d685465c26102d..7098b10e3db0caef02ae2daef8f0624e641aada4 100644 (file)
@@ -839,7 +839,7 @@ static int handle_one_ref(const char *path,
        }
        if (object->type != OBJ_COMMIT)
                return 0;
-       commit_list_insert_by_date((struct commit *)object, list);
+       commit_list_insert((struct commit *)object, list);
        return 0;
 }
 
@@ -864,27 +864,17 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
                commit_list_insert(l->item, &backup);
        }
        while (list) {
-               char *p, *to_free = NULL;
+               const char *p, *buf;
                struct commit *commit;
-               enum object_type type;
-               unsigned long size;
                int matches;
 
                commit = pop_most_recent_commit(&list, ONELINE_SEEN);
                if (!parse_object(commit->object.sha1))
                        continue;
-               if (commit->buffer)
-                       p = commit->buffer;
-               else {
-                       p = read_sha1_file(commit->object.sha1, &type, &size);
-                       if (!p)
-                               continue;
-                       to_free = p;
-               }
-
-               p = strstr(p, "\n\n");
+               buf = get_commit_buffer(commit, NULL);
+               p = strstr(buf, "\n\n");
                matches = p && !regexec(&regex, p + 2, 0, NULL, 0);
-               free(to_free);
+               unuse_commit_buffer(commit, buf);
 
                if (matches) {
                        hashcpy(sha1, commit->object.sha1);
@@ -913,10 +903,8 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
        const char *match = NULL, *target = NULL;
        size_t len;
 
-       if (starts_with(message, "checkout: moving from ")) {
-               match = message + strlen("checkout: moving from ");
+       if (skip_prefix(message, "checkout: moving from ", &match))
                target = strstr(match, " to ");
-       }
 
        if (!match || !target)
                return 0;
@@ -960,7 +948,7 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,
        retval = 0;
        if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch, &cb)) {
                strbuf_reset(buf);
-               strbuf_add(buf, cb.buf.buf, cb.buf.len);
+               strbuf_addbuf(buf, &cb.buf);
                retval = brace - name + 1;
        }
 
@@ -1254,10 +1242,7 @@ static void diagnose_invalid_sha1_path(const char *prefix,
                die("Path '%s' exists on disk, but not in '%.*s'.",
                    filename, object_name_len, object_name);
        if (errno == ENOENT || errno == ENOTDIR) {
-               char *fullname = xmalloc(strlen(filename)
-                                            + strlen(prefix) + 1);
-               strcpy(fullname, prefix);
-               strcat(fullname, filename);
+               char *fullname = xstrfmt("%s%s", prefix, filename);
 
                if (!get_tree_entry(tree_sha1, fullname,
                                    sha1, &mode)) {
@@ -1381,6 +1366,7 @@ static int get_sha1_with_context_1(const char *name,
                if (!only_to_die && namelen > 2 && name[1] == '/') {
                        struct commit_list *list = NULL;
                        for_each_ref(handle_one_ref, &list);
+                       commit_list_sort_by_date(&list);
                        return get_sha1_oneline(name + 2, sha1, list);
                }
                if (namelen < 3 ||