From 822601e8303270aebed493b11e0988a75f2646b8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 9 Jul 2017 06:13:51 -0400 Subject: log: clarify comment about reflog cycles When we're walking reflogs, we leave the commit buffer and parents in place. A comment explains that this is due to "cycles". But the interesting thing is the unsaid implication: that the cycles (plus our clearing of the SEEN flag) will cause us to show commits multiple times. Let's spell it out. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/log.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/log.c b/builtin/log.c index 8ca1de9894..cf303b2c06 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -372,7 +372,10 @@ static int cmd_log_walk(struct rev_info *rev) */ rev->max_count++; if (!rev->reflog_info) { - /* we allow cycles in reflog ancestry */ + /* + * We may show a given commit multiple times when + * walking the reflogs. + */ free_commit_buffer(commit); } free_commit_list(commit->parents); -- cgit v1.2.1 From f35650dff6a4500e317803165b13cc087f48ee85 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 7 Jul 2017 05:07:34 -0400 Subject: log: do not free parents when walking reflog When we're doing a reflog walk (instead of walking the actual parent pointers), we may see commits multiple times. For this reason, we hold on to the commit buffer for each commit rather than freeing it after we've showed the commit. We should do the same for the parent list. Right now this is just a minor optimization. But once we refactor how reflog walks are performed, keeping the parents will avoid confusing us the second time we see the commit. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/log.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/log.c b/builtin/log.c index cf303b2c06..630d6cff2f 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -377,9 +377,9 @@ static int cmd_log_walk(struct rev_info *rev) * walking the reflogs. */ free_commit_buffer(commit); + free_commit_list(commit->parents); + commit->parents = NULL; } - free_commit_list(commit->parents); - commit->parents = NULL; if (saved_nrl < rev->diffopt.needed_rename_limit) saved_nrl = rev->diffopt.needed_rename_limit; if (rev->diffopt.degraded_cc_to_c) -- cgit v1.2.1 From 7f97de5ee1e1f9d28f45c8f7890e752f7b12bed1 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 7 Jul 2017 05:08:30 -0400 Subject: rev-list: check reflog_info before showing usage When git-rev-list sees no pending commits, it shows a usage message. This works even when reflog-walking is requested, because the reflog-walk code currently puts the reflog tips into the pending queue. In preparation for refactoring the reflog-walk code, let's explicitly check whether we have any reflogs to walk. For now this is a noop, but the existing reflog tests will make sure that it kicks in after the refactoring. Likewise, we'll add a test that "rev-list -g" without specifying any reflogs continues to fail (so that we know our check does not kick in too aggressively). Note that the implementation needs to go into its own sub-function, as the walk code does not expose its innards outside of reflog-walk.c. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/rev-list.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 95d84d5cda..53a746dd89 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -11,6 +11,7 @@ #include "graph.h" #include "bisect.h" #include "progress.h" +#include "reflog-walk.h" static const char rev_list_usage[] = "git rev-list [OPTION] ... [ -- paths... ]\n" @@ -348,7 +349,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) /* Only --header was specified */ revs.commit_format = CMIT_FMT_RAW; - if ((!revs.commits && + if ((!revs.commits && reflog_walk_empty(revs.reflog_info) && (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) && !revs.pending.nr)) || revs.diff) -- cgit v1.2.1