git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/2] for-each-ref: Do not lookup objects when they will not be used
@ 2009-05-27 19:23 Anders Kaseorg
  2009-05-27 19:24 ` [PATCH 2/2] branch: Do not lookup commits " Anders Kaseorg
  0 siblings, 1 reply; 2+ messages in thread
From: Anders Kaseorg @ 2009-05-27 19:23 UTC (permalink / raw
  To: gitster; +Cc: git

This makes commands such as `git for-each-ref --format='%(refname)'`, 
which are used heavily by the bash_completion code, run about 6 times 
faster on an uncached repository (3 s intead of 18 s on my linux-2.6 
repository with several remotes).

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
---
 builtin-for-each-ref.c |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index d091e04..1911cda 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -561,14 +561,6 @@ static void populate_value(struct refinfo *ref)
 
 	ref->value = xcalloc(sizeof(struct atom_value), used_atom_cnt);
 
-	buf = get_obj(ref->objectname, &obj, &size, &eaten);
-	if (!buf)
-		die("missing object %s for %s",
-		    sha1_to_hex(ref->objectname), ref->refname);
-	if (!obj)
-		die("parse_object_buffer failed on %s for %s",
-		    sha1_to_hex(ref->objectname), ref->refname);
-
 	/* Fill in specials first */
 	for (i = 0; i < used_atom_cnt; i++) {
 		const char *name = used_atom[i];
@@ -621,6 +613,22 @@ static void populate_value(struct refinfo *ref)
 		}
 	}
 
+	for (i = 0; i < used_atom_cnt; i++) {
+		struct atom_value *v = &ref->value[i];
+		if (v->s == NULL)
+			goto need_obj;
+	}
+	return;
+
+ need_obj:
+	buf = get_obj(ref->objectname, &obj, &size, &eaten);
+	if (!buf)
+		die("missing object %s for %s",
+		    sha1_to_hex(ref->objectname), ref->refname);
+	if (!obj)
+		die("parse_object_buffer failed on %s for %s",
+		    sha1_to_hex(ref->objectname), ref->refname);
+
 	grab_values(ref->value, 0, obj, buf, size);
 	if (!eaten)
 		free(buf);
@@ -926,7 +934,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
 
 	memset(&cbdata, 0, sizeof(cbdata));
 	cbdata.grab_pattern = argv;
-	for_each_ref(grab_single_ref, &cbdata);
+	for_each_rawref(grab_single_ref, &cbdata);
 	refs = cbdata.grab_array;
 	num_refs = cbdata.grab_cnt;
 
-- 
1.6.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] branch: Do not lookup commits when they will not be used
  2009-05-27 19:23 [PATCH 1/2] for-each-ref: Do not lookup objects when they will not be used Anders Kaseorg
@ 2009-05-27 19:24 ` Anders Kaseorg
  0 siblings, 0 replies; 2+ messages in thread
From: Anders Kaseorg @ 2009-05-27 19:24 UTC (permalink / raw
  To: gitster; +Cc: git

This makes `git branch` without -v, --merged, --no-merged, or --contains 
run about 5 times faster on an uncached repository (4 s intead of 18 s on 
my linux-2.6 repository with several remotes).

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
---
 builtin-branch.c |   33 ++++++++++++++++++++-------------
 1 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/builtin-branch.c b/builtin-branch.c
index 91098ca..7ca2834 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -195,6 +195,7 @@ struct ref_list {
 	struct ref_item *list;
 	struct commit_list *with_commit;
 	int kinds;
+	int lookup_commits;
 };
 
 static char *resolve_symref(const char *src, const char *prefix)
@@ -215,7 +216,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
 {
 	struct ref_list *ref_list = (struct ref_list*)(cb_data);
 	struct ref_item *newitem;
-	struct commit *commit;
+	struct commit *commit = NULL;
 	int kind, i;
 	const char *prefix, *orig_refname = refname;
 
@@ -240,21 +241,25 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
 	if (ARRAY_SIZE(ref_kind) <= i)
 		return 0;
 
-	commit = lookup_commit_reference_gently(sha1, 1);
-	if (!commit)
-		return error("branch '%s' does not point at a commit", refname);
-
-	/* Filter with with_commit if specified */
-	if (!is_descendant_of(commit, ref_list->with_commit))
-		return 0;
-
 	/* Don't add types the caller doesn't want */
 	if ((kind & ref_list->kinds) == 0)
 		return 0;
 
-	if (merge_filter != NO_FILTER)
-		add_pending_object(&ref_list->revs,
-				   (struct object *)commit, refname);
+
+	if (ref_list->lookup_commits) {
+		commit = lookup_commit_reference_gently(sha1, 1);
+		if (!commit)
+			return error("branch '%s' does not point at a commit",
+				     refname);
+
+		/* Filter with with_commit if specified */
+		if (!is_descendant_of(commit, ref_list->with_commit))
+			return 0;
+
+		if (merge_filter != NO_FILTER)
+			add_pending_object(&ref_list->revs,
+					   (struct object *)commit, refname);
+	}
 
 	/* Resize buffer */
 	if (ref_list->index >= ref_list->alloc) {
@@ -426,7 +431,9 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
 	ref_list.with_commit = with_commit;
 	if (merge_filter != NO_FILTER)
 		init_revisions(&ref_list.revs, NULL);
-	for_each_ref(append_ref, &ref_list);
+	ref_list.lookup_commits =
+	    with_commit || merge_filter != NO_FILTER || verbose;
+	for_each_rawref(append_ref, &ref_list);
 	if (merge_filter != NO_FILTER) {
 		struct commit *filter;
 		filter = lookup_commit_reference_gently(merge_filter_ref, 0);
-- 
1.6.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-05-27 19:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-27 19:23 [PATCH 1/2] for-each-ref: Do not lookup objects when they will not be used Anders Kaseorg
2009-05-27 19:24 ` [PATCH 2/2] branch: Do not lookup commits " Anders Kaseorg

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).