git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Fitzsimons <robfitz@273k.net>
To: Jakub Narebski <jnareb@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH] rev-list: Add a new option --skip.
Date: Wed, 20 Dec 2006 00:29:06 +0000	[thread overview]
Message-ID: <20061220002906.GB17864@localhost> (raw)
In-Reply-To: <em9oi5$72t$1@sea.gmane.org>

Added a new option --skip=<N> which is used to allow the caller to
specify how many commit items to skip before displaying the commit
output.  This option is most useful for programs which want to display
fixed length pages of commit items, i.e. gitweb.

Signed-off-by: Robert Fitzsimons <robfitz@273k.net>
---

> I'm also for --skip (not --start-count), although... --start-count with
> --max-count seems more natural; one place it can be confusing is that we
> count skipped commits or not? I.e. we use --start-count=10 --max-count=20
> to get second 10 of commits, or --skip=10 --max-count=10 to get second 10
> of commits?

Here's the patch with the renamed option.  It also does not count
skipped commits, so --skip=10 --max-count=10 will display 10 items.

Robert


 Documentation/git-rev-list.txt |    5 +++++
 builtin-rev-list.c             |   17 +++++++++++++++++
 list-objects.c                 |    8 ++++++--
 revision.c                     |    1 +
 revision.h                     |    1 +
 5 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
index ec43c0b..7c86abc 100644
--- a/Documentation/git-rev-list.txt
+++ b/Documentation/git-rev-list.txt
@@ -12,6 +12,7 @@ SYNOPSIS
 'git-rev-list' [ \--max-count=number ]
 	     [ \--max-age=timestamp ]
 	     [ \--min-age=timestamp ]
+	     [ \--skip=number ]
 	     [ \--sparse ]
 	     [ \--no-merges ]
 	     [ \--remove-empty ]
@@ -151,6 +152,10 @@ limiting may be applied.
 
 	Limit the commits output to specified time range.
 
+--skip='number'::
+
+	Skip 'number' commits before starting to display commit output.
+
 --author='pattern', --committer='pattern'::
 
 	Limit the commits output to ones with author/committer
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index fb7fc92..432f901 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -20,6 +20,7 @@ static const char rev_list_usage[] =
 "    --max-count=nr\n"
 "    --max-age=epoch\n"
 "    --min-age=epoch\n"
+"    --skip=nr\n"
 "    --sparse\n"
 "    --no-merges\n"
 "    --remove-empty\n"
@@ -219,6 +220,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 	struct commit_list *list;
 	int i;
 	int read_from_stdin = 0;
+	int skip = -1;
 
 	init_revisions(&revs, prefix);
 	revs.abbrev = 0;
@@ -246,6 +248,10 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 			read_revisions_from_stdin(&revs);
 			continue;
 		}
+		if (!strncmp(arg, "--skip=", 7)) {
+			skip = atoi(arg + 7);
+			continue;
+		}
 		usage(rev_list_usage);
 
 	}
@@ -261,6 +267,17 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 		/* Only --header was specified */
 		revs.commit_format = CMIT_FMT_RAW;
 
+	/*
+	 * If a skip value is specified set start_count appropriately,
+	 * and if max_count is set it should be adjusted to account
+	 * for the skip value.
+	 */
+	if (skip > 0) {
+		revs.start_count = skip;
+		if (revs.max_count > 0)
+			revs.max_count += skip;
+	}
+
 	list = revs.commits;
 
 	if ((!list &&
diff --git a/list-objects.c b/list-objects.c
index f1fa21c..d96c8bf 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -108,8 +108,12 @@ void traverse_commit_list(struct rev_info *revs,
 	struct object_array objects = { 0, 0, NULL };
 
 	while ((commit = get_revision(revs)) != NULL) {
-		process_tree(revs, commit->tree, &objects, NULL, "");
-		show_commit(commit);
+		if (revs->start_count <= 0) {
+			process_tree(revs, commit->tree, &objects, NULL, "");
+			show_commit(commit);
+		} else {
+			revs->start_count--;
+		}
 	}
 	for (i = 0; i < revs->pending.nr; i++) {
 		struct object_array_entry *pending = revs->pending.objects + i;
diff --git a/revision.c b/revision.c
index 993bb66..70f4861 100644
--- a/revision.c
+++ b/revision.c
@@ -524,6 +524,7 @@ void init_revisions(struct rev_info *revs, const char *prefix)
 	revs->prefix = prefix;
 	revs->max_age = -1;
 	revs->min_age = -1;
+	revs->start_count = -1;
 	revs->max_count = -1;
 
 	revs->prune_fn = NULL;
diff --git a/revision.h b/revision.h
index 3adab95..c2dce8c 100644
--- a/revision.h
+++ b/revision.h
@@ -75,6 +75,7 @@ struct rev_info {
 	struct grep_opt	*grep_filter;
 
 	/* special limits */
+	int start_count;
 	int max_count;
 	unsigned long max_age;
 	unsigned long min_age;
-- 
1.4.4.2.g80fef-dirty

  reply	other threads:[~2006-12-20  0:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-19 20:54 [RFC] Possible optimization for gitweb Robert Fitzsimons
2006-12-19 21:45 ` Jakub Narebski
2006-12-20  0:52   ` Robert Fitzsimons
2006-12-19 22:10 ` Junio C Hamano
2006-12-19 22:22   ` Jakub Narebski
2006-12-20  0:29     ` Robert Fitzsimons [this message]
2006-12-20  1:09       ` [PATCH] rev-list: Add a new option --skip Junio C Hamano
2006-12-20 14:59         ` [PATCH] rev-list: Document --skip and add test cases Robert Fitzsimons

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=20061220002906.GB17864@localhost \
    --to=robfitz@273k.net \
    --cc=git@vger.kernel.org \
    --cc=jnareb@gmail.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 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).