mirror of
https://github.com/git/git
synced 2024-08-25 02:35:46 +00:00
Merge branch 'nd/branch-v-alignment'
Output from "git branch -v" contains "(no branch)" that could be localized, but the code to align it along with the names of branches were counting in bytes, not in display columns. * nd/branch-v-alignment: branch -v: align even when branch names are in UTF-8
This commit is contained in:
commit
8023a42210
|
@ -55,6 +55,8 @@ when you run `git cherry-pick`.
|
||||||
+
|
+
|
||||||
Note that any of the 'refs/*' cases above may come either from
|
Note that any of the 'refs/*' cases above may come either from
|
||||||
the '$GIT_DIR/refs' directory or from the '$GIT_DIR/packed-refs' file.
|
the '$GIT_DIR/refs' directory or from the '$GIT_DIR/packed-refs' file.
|
||||||
|
While the ref name encoding is unspecified, UTF-8 is prefered as
|
||||||
|
some output processing may assume ref names in UTF-8.
|
||||||
|
|
||||||
'<refname>@\{<date>\}', e.g. 'master@\{yesterday\}', 'HEAD@\{5 minutes ago\}'::
|
'<refname>@\{<date>\}', e.g. 'master@\{yesterday\}', 'HEAD@\{5 minutes ago\}'::
|
||||||
A ref followed by the suffix '@' with a date specification
|
A ref followed by the suffix '@' with a date specification
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "revision.h"
|
#include "revision.h"
|
||||||
#include "string-list.h"
|
#include "string-list.h"
|
||||||
#include "column.h"
|
#include "column.h"
|
||||||
|
#include "utf8.h"
|
||||||
|
|
||||||
static const char * const builtin_branch_usage[] = {
|
static const char * const builtin_branch_usage[] = {
|
||||||
N_("git branch [options] [-r | -a] [--merged | --no-merged]"),
|
N_("git branch [options] [-r | -a] [--merged | --no-merged]"),
|
||||||
|
@ -249,7 +250,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
|
||||||
struct ref_item {
|
struct ref_item {
|
||||||
char *name;
|
char *name;
|
||||||
char *dest;
|
char *dest;
|
||||||
unsigned int kind, len;
|
unsigned int kind, width;
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -354,14 +355,14 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
|
||||||
newitem->name = xstrdup(refname);
|
newitem->name = xstrdup(refname);
|
||||||
newitem->kind = kind;
|
newitem->kind = kind;
|
||||||
newitem->commit = commit;
|
newitem->commit = commit;
|
||||||
newitem->len = strlen(refname);
|
newitem->width = utf8_strwidth(refname);
|
||||||
newitem->dest = resolve_symref(orig_refname, prefix);
|
newitem->dest = resolve_symref(orig_refname, prefix);
|
||||||
/* adjust for "remotes/" */
|
/* adjust for "remotes/" */
|
||||||
if (newitem->kind == REF_REMOTE_BRANCH &&
|
if (newitem->kind == REF_REMOTE_BRANCH &&
|
||||||
ref_list->kinds != REF_REMOTE_BRANCH)
|
ref_list->kinds != REF_REMOTE_BRANCH)
|
||||||
newitem->len += 8;
|
newitem->width += 8;
|
||||||
if (newitem->len > ref_list->maxwidth)
|
if (newitem->width > ref_list->maxwidth)
|
||||||
ref_list->maxwidth = newitem->len;
|
ref_list->maxwidth = newitem->width;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -490,11 +491,12 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_addf(&name, "%s%s", prefix, item->name);
|
strbuf_addf(&name, "%s%s", prefix, item->name);
|
||||||
if (verbose)
|
if (verbose) {
|
||||||
|
int utf8_compensation = strlen(name.buf) - utf8_strwidth(name.buf);
|
||||||
strbuf_addf(&out, "%c %s%-*s%s", c, branch_get_color(color),
|
strbuf_addf(&out, "%c %s%-*s%s", c, branch_get_color(color),
|
||||||
maxwidth, name.buf,
|
maxwidth + utf8_compensation, name.buf,
|
||||||
branch_get_color(BRANCH_COLOR_RESET));
|
branch_get_color(BRANCH_COLOR_RESET));
|
||||||
else
|
} else
|
||||||
strbuf_addf(&out, "%c %s%s%s", c, branch_get_color(color),
|
strbuf_addf(&out, "%c %s%s%s", c, branch_get_color(color),
|
||||||
name.buf, branch_get_color(BRANCH_COLOR_RESET));
|
name.buf, branch_get_color(BRANCH_COLOR_RESET));
|
||||||
|
|
||||||
|
@ -519,8 +521,8 @@ static int calc_maxwidth(struct ref_list *refs)
|
||||||
for (i = 0; i < refs->index; i++) {
|
for (i = 0; i < refs->index; i++) {
|
||||||
if (!matches_merge_filter(refs->list[i].commit))
|
if (!matches_merge_filter(refs->list[i].commit))
|
||||||
continue;
|
continue;
|
||||||
if (refs->list[i].len > w)
|
if (refs->list[i].width > w)
|
||||||
w = refs->list[i].len;
|
w = refs->list[i].width;
|
||||||
}
|
}
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
@ -533,12 +535,12 @@ static void show_detached(struct ref_list *ref_list)
|
||||||
if (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {
|
if (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {
|
||||||
struct ref_item item;
|
struct ref_item item;
|
||||||
item.name = xstrdup(_("(no branch)"));
|
item.name = xstrdup(_("(no branch)"));
|
||||||
item.len = strlen(item.name);
|
item.width = utf8_strwidth(item.name);
|
||||||
item.kind = REF_LOCAL_BRANCH;
|
item.kind = REF_LOCAL_BRANCH;
|
||||||
item.dest = NULL;
|
item.dest = NULL;
|
||||||
item.commit = head_commit;
|
item.commit = head_commit;
|
||||||
if (item.len > ref_list->maxwidth)
|
if (item.width > ref_list->maxwidth)
|
||||||
ref_list->maxwidth = item.len;
|
ref_list->maxwidth = item.width;
|
||||||
print_ref_item(&item, ref_list->maxwidth, ref_list->verbose, ref_list->abbrev, 1, "");
|
print_ref_item(&item, ref_list->maxwidth, ref_list->verbose, ref_list->abbrev, 1, "");
|
||||||
free(item.name);
|
free(item.name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue