All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 3/4] commit: add infrastructure for priority queues of commits
Date: Thu, 19 May 2011 17:25:17 -0400	[thread overview]
Message-ID: <20110519212517.GC29584@sigill.intra.peff.net> (raw)
In-Reply-To: <20110519212349.GA28589@sigill.intra.peff.net>

Using a priority queue to store date-ordered commits can be
algorithmically faster than the current implementation
(which uses sorted linked lists).

The previous commit introduced a generic priority queue.
This commit adds some infrastructure for using it with
commits. Specifically:

  1. A date-comparison function and queue-initializer, so
     you can create a queue like:

       struct queue pq = COMMIT_QUEUE_INIT;

  2. A function to pop the most recent commit from the
     queue, adding its parents to the queue unless a
     particular mark is seen on them. This is equivalent to
     the current pop_most_recent_commit, which operates on
     commit_list structs.

Signed-off-by: Jeff King <peff@peff.net>
---
 commit.c |   27 +++++++++++++++++++++++++++
 commit.h |    5 +++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/commit.c b/commit.c
index ac337c7..9d0a182 100644
--- a/commit.c
+++ b/commit.c
@@ -419,6 +419,33 @@ struct commit *pop_most_recent_commit(struct commit_list **list,
 	return ret;
 }
 
+int commit_datecmp(const void *va, const void *vb)
+{
+	const struct commit *a = va, *b = vb;
+	if (a->date < b->date)
+		return -1;
+	else if (a->date > b->date)
+		return 1;
+	return 0;
+}
+
+struct commit *pop_commit_from_queue(struct queue *pq, unsigned int mark)
+{
+	struct commit *ret = queue_pop(pq);
+	struct commit_list *parents = ret ? ret->parents : NULL;
+
+	while (parents) {
+		struct commit *commit = parents->item;
+		if (!parse_commit(commit) && !(commit->object.flags & mark)) {
+			commit->object.flags |= mark;
+			queue_insert(pq, commit);
+		}
+		parents = parents->next;
+	}
+
+	return ret;
+}
+
 void clear_commit_marks(struct commit *commit, unsigned int mark)
 {
 	while (commit) {
diff --git a/commit.h b/commit.h
index 43940e2..87c9b4a 100644
--- a/commit.h
+++ b/commit.h
@@ -5,6 +5,7 @@
 #include "tree.h"
 #include "strbuf.h"
 #include "decorate.h"
+#include "queue.h"
 
 struct commit_list {
 	struct commit *item;
@@ -121,6 +122,10 @@ void pp_remainder(enum cmit_fmt fmt,
 struct commit *pop_most_recent_commit(struct commit_list **list,
 				      unsigned int mark);
 
+#define COMMIT_QUEUE_INIT { commit_datecmp }
+int commit_datecmp(const void *a, const void *b);
+struct commit *pop_commit_from_queue(struct queue *pq, unsigned int mark);
+
 struct commit *pop_commit(struct commit_list **stack);
 
 void clear_commit_marks(struct commit *commit, unsigned int mark);
-- 
1.7.5.8.ga95ab

  parent reply	other threads:[~2011-05-19 21:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-19 20:48 [PATCH] fetch: avoid repeated commits in mark_complete Jeff King
2011-05-19 21:23 ` [RFC/PATCH 0/4] commit lists as priority queues Jeff King
2011-05-19 21:24   ` [PATCH 1/4] Makefile: sort TEST_PROGRAMS list Jeff King
2011-05-19 21:24   ` [PATCH 2/4] basic priority queue implementation Jeff King
2011-05-20  0:47     ` Thiago Farina
2011-05-20  7:38       ` Jeff King
2011-05-20 13:13         ` Thiago Farina
2011-05-20 13:23           ` Jeff King
2011-05-19 21:25   ` Jeff King [this message]
2011-05-19 21:26   ` [PATCH 4/4] fetch-pack: use priority queue for mark_complete Jeff King
2011-05-20 22:03   ` [RFC/PATCH 0/4] commit lists as priority queues Junio C Hamano
2011-05-20  1:42 ` [PATCH] fetch: avoid repeated commits in mark_complete 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=20110519212517.GC29584@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /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.