Merge branch 'jk/skip-prefix'
[gitweb.git] / sha1_name.c
index 2b6322fad064845f4c782286fe9764f6b958f30d..a91e0c924b8d3b40a280de92fdded2a04a961221 100644 (file)
@@ -862,27 +862,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);
@@ -911,10 +901,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;