Skip to content

Commit 191d1ac

Browse files
torvaldsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6e4a47 commit 191d1ac

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

builtin-branch.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct ref_item {
191191

192192
struct ref_list {
193193
struct rev_info revs;
194-
int index, alloc, maxwidth;
194+
int index, alloc, maxwidth, verbose;
195195
struct ref_item *list;
196196
struct commit_list *with_commit;
197197
int kinds;
@@ -244,17 +244,20 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
244244
if ((kind & ref_list->kinds) == 0)
245245
return 0;
246246

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);
250252

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;
254256

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+
}
258261

259262
/* Resize buffer */
260263
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
423426

424427
memset(&ref_list, 0, sizeof(ref_list));
425428
ref_list.kinds = kinds;
429+
ref_list.verbose = verbose;
426430
ref_list.with_commit = with_commit;
427431
if (merge_filter != NO_FILTER)
428432
init_revisions(&ref_list.revs, NULL);

0 commit comments

Comments
 (0)