Refactor print-functions in builtin-branch

This moves the guts of print_ref_list() into a revamped print_ref_info(),
which at the same time gets renamed to print_ref_item().

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Lars Hjemli 2007-01-03 21:10:09 +01:00 committed by Junio C Hamano
parent 1ebb948f65
commit af0e4ac0ec

View File

@ -231,38 +231,15 @@ static int ref_cmp(const void *r1, const void *r2)
return strcmp(c1->name, c2->name); return strcmp(c1->name, c2->name);
} }
static void print_ref_info(const unsigned char *sha1, int abbrev) static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
int abbrev, int current)
{ {
char c;
int color;
struct commit *commit; struct commit *commit;
char subject[256]; char subject[256];
switch (item->kind) {
commit = lookup_commit(sha1);
if (commit && !parse_commit(commit))
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
subject, sizeof(subject), 0,
NULL, NULL, 0);
else
strcpy(subject, " **** invalid ref ****");
printf(" %s %s\n", find_unique_abbrev(sha1, abbrev), subject);
}
static void print_ref_list(int kinds, int verbose, int abbrev)
{
int i;
char c;
struct ref_list ref_list;
int color;
memset(&ref_list, 0, sizeof(ref_list));
ref_list.kinds = kinds;
for_each_ref(append_ref, &ref_list);
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
for (i = 0; i < ref_list.index; i++) {
switch( ref_list.list[i].kind ) {
case REF_LOCAL_BRANCH: case REF_LOCAL_BRANCH:
color = COLOR_BRANCH_LOCAL; color = COLOR_BRANCH_LOCAL;
break; break;
@ -275,26 +252,46 @@ static void print_ref_list(int kinds, int verbose, int abbrev)
} }
c = ' '; c = ' ';
if (ref_list.list[i].kind == REF_LOCAL_BRANCH && if (current) {
!strcmp(ref_list.list[i].name, head)) {
c = '*'; c = '*';
color = COLOR_BRANCH_CURRENT; color = COLOR_BRANCH_CURRENT;
} }
if (verbose) { if (verbose) {
printf("%c %s%-*s%s", c, commit = lookup_commit(item->sha1);
branch_get_color(color), if (commit && !parse_commit(commit))
ref_list.maxwidth, pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
ref_list.list[i].name, subject, sizeof(subject), 0,
branch_get_color(COLOR_BRANCH_RESET)); NULL, NULL, 0);
print_ref_info(ref_list.list[i].sha1, abbrev);
}
else else
printf("%c %s%s%s\n", c, strcpy(subject, " **** invalid ref ****");
branch_get_color(color), printf("%c %s%-*s%s %s %s\n", c, branch_get_color(color),
ref_list.list[i].name, maxwidth, item->name,
branch_get_color(COLOR_BRANCH_RESET),
find_unique_abbrev(item->sha1, abbrev), subject);
} else {
printf("%c %s%s%s\n", c, branch_get_color(color), item->name,
branch_get_color(COLOR_BRANCH_RESET)); branch_get_color(COLOR_BRANCH_RESET));
} }
}
static void print_ref_list(int kinds, int verbose, int abbrev)
{
int i;
struct ref_list ref_list;
memset(&ref_list, 0, sizeof(ref_list));
ref_list.kinds = kinds;
for_each_ref(append_ref, &ref_list);
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
for (i = 0; i < ref_list.index; i++) {
int current = (ref_list.list[i].kind == REF_LOCAL_BRANCH) &&
!strcmp(ref_list.list[i].name, head);
print_ref_item(&ref_list.list[i], ref_list.maxwidth, verbose,
abbrev, current);
}
free_ref_list(&ref_list); free_ref_list(&ref_list);
} }