builtin/apply: make check_apply_state() return -1 instead of die()ing
[gitweb.git] / reflog-walk.c
index d3cc5240f36ce54aa49c738616f93330bcd6ac67..a246af27678a76d37c87bb56959ac050dff1f97f 100644 (file)
@@ -56,12 +56,11 @@ static struct complete_reflogs *read_complete_reflog(const char *ref)
                }
        }
        if (reflogs->nr == 0) {
-               int len = strlen(ref);
-               char *refname = xmalloc(len + 12);
-               sprintf(refname, "refs/%s", ref);
+               char *refname = xstrfmt("refs/%s", ref);
                for_each_reflog_ent(refname, read_one_reflog, reflogs);
                if (reflogs->nr == 0) {
-                       sprintf(refname, "refs/heads/%s", ref);
+                       free(refname);
+                       refname = xstrfmt("refs/heads/%s", ref);
                        for_each_reflog_ent(refname, read_one_reflog, reflogs);
                }
                free(refname);
@@ -242,6 +241,12 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
                logobj = parse_object(reflog->osha1);
        } while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT));
 
+       if (!logobj && commit_reflog->recno >= 0 && is_null_sha1(reflog->osha1)) {
+               /* a root commit, but there are still more entries to show */
+               reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
+               logobj = parse_object(reflog->nsha1);
+       }
+
        if (!logobj || logobj->type != OBJ_COMMIT) {
                commit_info->commit = NULL;
                commit->parents = NULL;