git branch: avoid unnecessary object lookups
They can be expensive in the cold-cache case, so don't bother looking up the commits for all branches unless we really need them for some reason. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Torvalds committed
Jul 23, 2009 at 12:05 UTC
191d1ac435c01e2a7acfb93fb9da8378da90214c
1 file changed
+14
-10
builtin-branch.c
+14
-10
@@ -191,7 +191,7 @@ struct ref_item {
191
192
struct ref_list {
193
struct rev_info revs;
194
- int index, alloc, maxwidth;
194
+ int index, alloc, maxwidth, verbose;
195
struct ref_item *list;
196
struct commit_list *with_commit;
197
int kinds;
@@ -244,17 +244,20 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
244
if ((kind & ref_list->kinds) == 0)
245
return 0;
246
247
- commit = lookup_commit_reference_gently(sha1, 1);
248
- if (!commit)
249
- return error("branch '%s' does not point at a commit", refname);
247
+ commit = NULL;
248
+ if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
249
+ commit = lookup_commit_reference_gently(sha1, 1);
250
+ if (!commit)
251
+ return error("branch '%s' does not point at a commit", refname);
252
251
- /* Filter with with_commit if specified */
252
- if (!is_descendant_of(commit, ref_list->with_commit))
253
- return 0;
253
+ /* Filter with with_commit if specified */
254
+ if (!is_descendant_of(commit, ref_list->with_commit))
255
+ return 0;
256
255
- if (merge_filter != NO_FILTER)
256
- add_pending_object(&ref_list->revs,
257
- (struct object *)commit, refname);
257
+ if (merge_filter != NO_FILTER)
258
+ add_pending_object(&ref_list->revs,
259
+ (struct object *)commit, refname);
260
+ }
261
262
/* Resize buffer */
263
if (ref_list->index >= ref_list->alloc) {
@@ -423,6 +426,7 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
426
427
memset(&ref_list, 0, sizeof(ref_list));
428
ref_list.kinds = kinds;
429
+ ref_list.verbose = verbose;
430
ref_list.with_commit = with_commit;
431
if (merge_filter != NO_FILTER)
432
init_revisions(&ref_list.revs, NULL);