builtin-branch: fix -v for --[no-]merged
After the optimization to --[no-]merged logic, the calculation of the width of the longest refname to be shown might become inaccurate (since the matching against merge_filter is performed after adding refs to ref_list). This patch forces a recalculation of maxwidth when it might be needed. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Hjemli committed
Jul 26, 2008 at 12:27 UTC
b6f637d199fed238179865a38f180fccc37ee8cc
1 file changed
+15
builtin-branch.c
+15
@@ -363,6 +363,19 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
363
}
364
}
365
366
+static int calc_maxwidth(struct ref_list *refs)
367
+{
368
+ int i, l, w = 0;
369
+ for (i = 0; i < refs->index; i++) {
370
+ if (!matches_merge_filter(refs->list[i].commit))
371
+ continue;
372
+ l = strlen(refs->list[i].name);
373
+ if (l > w)
374
+ w = l;
375
+ }
376
+ return w;
377
+}
378
+
379
static void print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit)
380
{
381
int i;
@@ -383,6 +396,8 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
396
(struct object *) filter, "");
397
ref_list.revs.limited = 1;
398
prepare_revision_walk(&ref_list.revs);
399
+ if (verbose)
400
+ ref_list.maxwidth = calc_maxwidth(&ref_list);
401
}
402
403
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);