Merge branch 'sg/reflog-past-root'
authorJunio C Hamano <gitster@pobox.com>
Mon, 27 Jun 2016 16:56:46 +0000 (09:56 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Jun 2016 16:56:46 +0000 (09:56 -0700)
"git reflog" stopped upon seeing an entry that denotes a branch
creation event (aka "unborn"), which made it appear as if the
reflog was truncated.

* sg/reflog-past-root:
reflog: continue walking the reflog past root commits

reflog-walk.c
t/t1401-symbolic-ref.sh
t/t1410-reflog.sh
index 0ebd1da5ceb835066cf4eccd81eda4fba2cc0ac2..a246af27678a76d37c87bb56959ac050dff1f97f 100644 (file)
@@ -241,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;
index 417eecc3af2a30c3544ddd2f83b7ccecc540eaf1..ca3fa406c34f1d41ac5d2be67804af234b996654 100755 (executable)
@@ -110,7 +110,7 @@ test_expect_success 'symbolic-ref writes reflog entry' '
        update
        create
        EOF
-       git log --format=%gs -g >actual &&
+       git log --format=%gs -g -2 >actual &&
        test_cmp expect actual
 '
 
index 9cf91dc6d217f8d92dea0125e37b03f6a6938124..dd2be049ecf6302dfa3d052a14095b3278d58f03 100755 (executable)
@@ -348,4 +348,26 @@ test_expect_success 'reflog expire operates on symref not referrent' '
        git reflog expire --expire=all the_symref
 '
 
+test_expect_success 'continue walking past root commits' '
+       git init orphanage &&
+       (
+               cd orphanage &&
+               cat >expect <<-\EOF &&
+               HEAD@{0} commit (initial): orphan2-1
+               HEAD@{1} commit: orphan1-2
+               HEAD@{2} commit (initial): orphan1-1
+               HEAD@{3} commit (initial): initial
+               EOF
+               test_commit initial &&
+               git reflog &&
+               git checkout --orphan orphan1 &&
+               test_commit orphan1-1 &&
+               test_commit orphan1-2 &&
+               git checkout --orphan orphan2 &&
+               test_commit orphan2-1 &&
+               git log -g --format="%gd %gs" >actual &&
+               test_cmp expect actual
+       )
+'
+
 test_done