* --orphan erases HEAD reflog @ 2016-06-03 11:28 Patrik Gustafsson 2016-06-03 20:38 ` SZEDER Gábor 2016-06-03 20:42 ` [PATCH] reflog: continue walking the reflog past root commits SZEDER Gábor 0 siblings, 2 replies; 4+ messages in thread From: Patrik Gustafsson @ 2016-06-03 11:28 UTC (permalink / raw) To: git after running the command: git checkout --orphan fuleFix my HEAD reflog is emptied. I would like to have my reflog intact :) git version 2.8.3 dist: Manjaro thanx for being awesome ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: --orphan erases HEAD reflog 2016-06-03 11:28 --orphan erases HEAD reflog Patrik Gustafsson @ 2016-06-03 20:38 ` SZEDER Gábor 2016-06-03 20:42 ` [PATCH] reflog: continue walking the reflog past root commits SZEDER Gábor 1 sibling, 0 replies; 4+ messages in thread From: SZEDER Gábor @ 2016-06-03 20:38 UTC (permalink / raw) To: Patrik Gustafsson; +Cc: SZEDER Gábor, git > after running the command: > > git checkout --orphan fuleFix > > my HEAD reflog is emptied. > I would like to have my reflog intact :) No worries, your reflog is still intact :) It's just the reflog walker stopping prematurely upon encountering the null sha1 of the new root commit's reflog entry. Patch follows in a minute. Of course you still won't be able to list the reflog right after 'git checkout --orphan', because HEAD is invalid. You have to create a new root commit or switch to an existing branch first. Gábor ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] reflog: continue walking the reflog past root commits 2016-06-03 11:28 --orphan erases HEAD reflog Patrik Gustafsson 2016-06-03 20:38 ` SZEDER Gábor @ 2016-06-03 20:42 ` SZEDER Gábor 2016-06-04 1:54 ` Eric Sunshine 1 sibling, 1 reply; 4+ messages in thread From: SZEDER Gábor @ 2016-06-03 20:42 UTC (permalink / raw) To: Junio C Hamano; +Cc: Patrik Gustafsson, git, SZEDER Gábor If a repository contains more than one root commit, then its HEAD reflog may contain multiple "creation events", i.e. entries whose "from" value is the null sha1. Listing such a reflog currently stops prematurely at the first such entry, even when the reflog still contains older entries. This can scare users into thinking that their reflog got truncated after 'git checkout --orphan'. Continue walking the reflog past such creation evens based on the preceeding reflog entry's "new" value. The test 'symbolic-ref writes reflog entry' in t1401-symbolic-ref implicitly relies on the current behavior of the reflog walker to stop at a root commit and thus to list only the reflog entries that are relevant for that test. Adjust the test to explicitly specify the number of relevant reflog entries to be listed. Reported-by: Patrik Gustafsson <pvn@textalk.se> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> --- reflog-walk.c | 6 ++++++ t/t1401-symbolic-ref.sh | 2 +- t/t1410-reflog.sh | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/reflog-walk.c b/reflog-walk.c index 0ebd1da5ceb8..a246af27678a 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -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; diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh index 417eecc3af2a..ca3fa406c34f 100755 --- a/t/t1401-symbolic-ref.sh +++ b/t/t1401-symbolic-ref.sh @@ -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 ' diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 9cf91dc6d217..dd2be049ecf6 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -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 -- 2.9.0.rc1.66.ge2c3978 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] reflog: continue walking the reflog past root commits 2016-06-03 20:42 ` [PATCH] reflog: continue walking the reflog past root commits SZEDER Gábor @ 2016-06-04 1:54 ` Eric Sunshine 0 siblings, 0 replies; 4+ messages in thread From: Eric Sunshine @ 2016-06-04 1:54 UTC (permalink / raw) To: SZEDER Gábor; +Cc: Junio C Hamano, Patrik Gustafsson, Git List On Fri, Jun 3, 2016 at 4:42 PM, SZEDER Gábor <szeder@ira.uka.de> wrote: > If a repository contains more than one root commit, then its HEAD > reflog may contain multiple "creation events", i.e. entries whose > "from" value is the null sha1. Listing such a reflog currently stops > prematurely at the first such entry, even when the reflog still > contains older entries. This can scare users into thinking that their > reflog got truncated after 'git checkout --orphan'. > > Continue walking the reflog past such creation evens based on the s/evens/events/ > preceeding reflog entry's "new" value. > > The test 'symbolic-ref writes reflog entry' in t1401-symbolic-ref > implicitly relies on the current behavior of the reflog walker to stop > at a root commit and thus to list only the reflog entries that are > relevant for that test. Adjust the test to explicitly specify the > number of relevant reflog entries to be listed. > > Reported-by: Patrik Gustafsson <pvn@textalk.se> > Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-06-04 1:54 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-06-03 11:28 --orphan erases HEAD reflog Patrik Gustafsson 2016-06-03 20:38 ` SZEDER Gábor 2016-06-03 20:42 ` [PATCH] reflog: continue walking the reflog past root commits SZEDER Gábor 2016-06-04 1:54 ` Eric Sunshine
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).