Ejemplo n.º 1
0
static void show_detached(struct ref_list *ref_list)
{
	struct commit *head_commit = lookup_commit_reference_gently(head_sha1, 1);

	if (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {
		struct ref_item item;
		item.name = get_head_description();
		item.width = utf8_strwidth(item.name);
		item.kind = REF_LOCAL_BRANCH;
		item.dest = NULL;
		item.commit = head_commit;
		if (item.width > ref_list->maxwidth)
			ref_list->maxwidth = item.width;
		print_ref_item(&item, ref_list->maxwidth, ref_list->verbose, ref_list->abbrev, 1, "");
		free(item.name);
	}
}
Ejemplo n.º 2
0
static int calc_maxwidth(struct ref_array *refs, int remote_bonus)
{
	int i, max = 0;
	for (i = 0; i < refs->nr; i++) {
		struct ref_array_item *it = refs->items[i];
		const char *desc = it->refname;
		int w;

		skip_prefix(it->refname, "refs/heads/", &desc);
		skip_prefix(it->refname, "refs/remotes/", &desc);
		if (it->kind == FILTER_REFS_DETACHED_HEAD) {
			char *head_desc = get_head_description();
			w = utf8_strwidth(head_desc);
			free(head_desc);
		} else
			w = utf8_strwidth(desc);

		if (it->kind == FILTER_REFS_REMOTES)
			w += remote_bonus;
		if (w > max)
			max = w;
	}
	return max;
}
Ejemplo n.º 3
0
Archivo: branch.c Proyecto: 1tgr/git
static void format_and_print_ref_item(struct ref_array_item *item, int maxwidth,
				      struct ref_filter *filter, const char *remote_prefix)
{
	char c;
	int current = 0;
	int color;
	struct strbuf out = STRBUF_INIT, name = STRBUF_INIT;
	const char *prefix_to_show = "";
	const char *prefix_to_skip = NULL;
	const char *desc = item->refname;
	char *to_free = NULL;

	switch (item->kind) {
	case FILTER_REFS_BRANCHES:
		prefix_to_skip = "refs/heads/";
		skip_prefix(desc, prefix_to_skip, &desc);
		if (!filter->detached && !strcmp(desc, head))
			current = 1;
		else
			color = BRANCH_COLOR_LOCAL;
		break;
	case FILTER_REFS_REMOTES:
		prefix_to_skip = "refs/remotes/";
		skip_prefix(desc, prefix_to_skip, &desc);
		color = BRANCH_COLOR_REMOTE;
		prefix_to_show = remote_prefix;
		break;
	case FILTER_REFS_DETACHED_HEAD:
		desc = to_free = get_head_description();
		current = 1;
		break;
	default:
		color = BRANCH_COLOR_PLAIN;
		break;
	}

	c = ' ';
	if (current) {
		c = '*';
		color = BRANCH_COLOR_CURRENT;
	}

	strbuf_addf(&name, "%s%s", prefix_to_show, desc);
	if (filter->verbose) {
		int utf8_compensation = strlen(name.buf) - utf8_strwidth(name.buf);
		strbuf_addf(&out, "%c %s%-*s%s", c, branch_get_color(color),
			    maxwidth + utf8_compensation, name.buf,
			    branch_get_color(BRANCH_COLOR_RESET));
	} else
		strbuf_addf(&out, "%c %s%s%s", c, branch_get_color(color),
			    name.buf, branch_get_color(BRANCH_COLOR_RESET));

	if (item->symref) {
		const char *symref = item->symref;
		if (prefix_to_skip)
			skip_prefix(symref, prefix_to_skip, &symref);
		strbuf_addf(&out, " -> %s", symref);
	}
	else if (filter->verbose)
		/* " f7c0c00 [ahead 58, behind 197] vcs-svn: drop obj_pool.h" */
		add_verbose_info(&out, item, filter, desc);
	if (column_active(colopts)) {
		assert(!filter->verbose && "--column and --verbose are incompatible");
		string_list_append(&output, out.buf);
	} else {
		printf("%s\n", out.buf);
	}
	strbuf_release(&name);
	strbuf_release(&out);
	free(to_free);
}