From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>
Subject: [PATCH 1/2] Clean up reflog unreachability pruning decision
Date: Tue, 31 Mar 2009 10:09:55 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.2.00.0903311003490.4093@localhost.localdomain> (raw)
In-Reply-To: <alpine.LFD.2.00.0903310958000.4093@localhost.localdomain>
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Tue, 31 Mar 2009 09:45:22 -0700
This clarifies the pruning rules for unreachable commits by having a
separate helpder function for the unreachability decision.
It's preparation for actual bigger changes to come to speed up the
decision when the reachability calculations become a bottleneck.
In the process it also _does_ change behavior, although in a way that I
think is much saner than the old behavior (which was in my opinion not
designed, just a result of how the tests were written). It now will prune
reflog entries that are older than that 'prune_unreacable' time _and_ that
have commit references that can't be even looked up.
Of course, "--stale-fix" also does that, and does it regardless of the age
of the reflog entry is, but I really think this is the right thing to do.
If we can't even look it up, we should consider it to be unreachable.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
builtin-reflog.c | 32 ++++++++++++++++++++++++++------
1 files changed, 26 insertions(+), 6 deletions(-)
Note the behavioural change. I think it's sane and "ObviouslyCorrect(tm)",
but maybe somebody disagrees.
diff --git a/builtin-reflog.c b/builtin-reflog.c
index d95f515..0355ce6 100644
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
@@ -209,6 +209,31 @@ static int keep_entry(struct commit **it, unsigned char *sha1)
return 1;
}
+static int unreachable(struct expire_reflog_cb *cb, struct commit *commit, unsigned char *sha1)
+{
+ /*
+ * We may or may not have the commit yet - if not, look it
+ * up using the supplied sha1.
+ */
+ if (!commit) {
+ if (is_null_sha1(sha1))
+ return 0;
+
+ commit = lookup_commit_reference_gently(sha1, 1);
+
+ /* We can't even look it up - consider it unreachable */
+ if (!commit)
+ return 1;
+ }
+
+ /* Reachable from the current reflog top? Don't prune */
+ if (in_merge_bases(commit, &cb->ref_commit, 1))
+ return 0;
+
+ /* We can't reach it - prune it. */
+ return 1;
+}
+
static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
const char *email, unsigned long timestamp, int tz,
const char *message, void *cb_data)
@@ -230,12 +255,7 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
if (timestamp < cb->cmd->expire_unreachable) {
if (!cb->ref_commit)
goto prune;
- if (!old && !is_null_sha1(osha1))
- old = lookup_commit_reference_gently(osha1, 1);
- if (!new && !is_null_sha1(nsha1))
- new = lookup_commit_reference_gently(nsha1, 1);
- if ((old && !in_merge_bases(old, &cb->ref_commit, 1)) ||
- (new && !in_merge_bases(new, &cb->ref_commit, 1)))
+ if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1))
goto prune;
}
--
1.6.2.1.404.gb0085.dirty
next prev parent reply other threads:[~2009-03-31 17:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-31 17:03 [PATCH 0/2] speed up reflog unreachability pruning Linus Torvalds
2009-03-31 17:09 ` Linus Torvalds [this message]
2009-03-31 17:11 ` [PATCH 2/2] Speed up reflog pruning of unreachable commits Linus Torvalds
2009-03-31 17:46 ` Junio C Hamano
2009-03-31 17:58 ` Linus Torvalds
2009-03-31 17:44 ` [PATCH 1/2] Clean up reflog unreachability pruning decision Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.2.00.0903311003490.4093@localhost.localdomain \
--to=torvalds@linux-foundation.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.