17
#include "revision.h"
18
#include "string-list.h"
19
#include "column.h"
20
+#include "utf8.h"
21
22
static const char * const builtin_branch_usage[] = {
23
"git branch [options] [-r | -a] [--merged | --no-merged]",
250
struct ref_item {
251
char *name;
252
char *dest;
252
- unsigned int kind, len;
253
+ unsigned int kind, width;
254
struct commit *commit;
255
};
256
355
newitem->name = xstrdup(refname);
356
newitem->kind = kind;
357
newitem->commit = commit;
357
- newitem->len = strlen(refname);
358
+ newitem->width = utf8_strwidth(refname);
359
newitem->dest = resolve_symref(orig_refname, prefix);
360
/* adjust for "remotes/" */
361
if (newitem->kind == REF_REMOTE_BRANCH &&
362
ref_list->kinds != REF_REMOTE_BRANCH)
362
- newitem->len += 8;
363
- if (newitem->len > ref_list->maxwidth)
364
- ref_list->maxwidth = newitem->len;
363
+ newitem->width += 8;
364
+ if (newitem->width > ref_list->maxwidth)
365
+ ref_list->maxwidth = newitem->width;
366
367
return 0;
368
}
491
}
492
493
strbuf_addf(&name, "%s%s", prefix, item->name);
493
- if (verbose)
494
+ if (verbose) {
495
+ int utf8_compensation = strlen(name.buf) - utf8_strwidth(name.buf);
496
strbuf_addf(&out, "%c %s%-*s%s", c, branch_get_color(color),
495
- maxwidth, name.buf,
497
+ maxwidth + utf8_compensation, name.buf,
498
branch_get_color(BRANCH_COLOR_RESET));
497
- else
499
+ } else
500
strbuf_addf(&out, "%c %s%s%s", c, branch_get_color(color),
501
name.buf, branch_get_color(BRANCH_COLOR_RESET));
502
521
for (i = 0; i < refs->index; i++) {
522
if (!matches_merge_filter(refs->list[i].commit))
523
continue;
522
- if (refs->list[i].len > w)
523
- w = refs->list[i].len;
524
+ if (refs->list[i].width > w)
525
+ w = refs->list[i].width;
526
}
527
return w;
528
}
535
if (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {
536
struct ref_item item;
537
item.name = xstrdup(_("(no branch)"));
536
- item.len = strlen(item.name);
538
+ item.width = utf8_strwidth(item.name);
539
item.kind = REF_LOCAL_BRANCH;
540
item.dest = NULL;
541
item.commit = head_commit;
540
- if (item.len > ref_list->maxwidth)
541
- ref_list->maxwidth = item.len;
542
+ if (item.width > ref_list->maxwidth)
543
+ ref_list->maxwidth = item.width;
544
print_ref_item(&item, ref_list->maxwidth, ref_list->verbose, ref_list->abbrev, 1, "");
545
free(item.name);
546
}