ls-tree: use "enum object_type", not {blob,tree,commit}_type
Change the ls-tree.c code to use type_name() on the enum instead of using the string constants. This doesn't matter either way for performance, but makes this a bit easier to read as we'll no longer need a strcmp() here. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
82e69b0cb5
commit
26f6d4d5a0
@ -66,17 +66,17 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
|
|||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
int baselen;
|
int baselen;
|
||||||
const char *type = blob_type;
|
enum object_type type = OBJ_BLOB;
|
||||||
|
|
||||||
if (S_ISGITLINK(mode)) {
|
if (S_ISGITLINK(mode)) {
|
||||||
type = commit_type;
|
type = OBJ_COMMIT;
|
||||||
} else if (S_ISDIR(mode)) {
|
} else if (S_ISDIR(mode)) {
|
||||||
if (show_recursive(base->buf, base->len, pathname)) {
|
if (show_recursive(base->buf, base->len, pathname)) {
|
||||||
retval = READ_TREE_RECURSIVE;
|
retval = READ_TREE_RECURSIVE;
|
||||||
if (!(ls_options & LS_SHOW_TREES))
|
if (!(ls_options & LS_SHOW_TREES))
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
type = tree_type;
|
type = OBJ_TREE;
|
||||||
}
|
}
|
||||||
else if (ls_options & LS_TREE_ONLY)
|
else if (ls_options & LS_TREE_ONLY)
|
||||||
return 0;
|
return 0;
|
||||||
@ -84,7 +84,7 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
|
|||||||
if (!(ls_options & LS_NAME_ONLY)) {
|
if (!(ls_options & LS_NAME_ONLY)) {
|
||||||
if (ls_options & LS_SHOW_SIZE) {
|
if (ls_options & LS_SHOW_SIZE) {
|
||||||
char size_text[24];
|
char size_text[24];
|
||||||
if (!strcmp(type, blob_type)) {
|
if (type == OBJ_BLOB) {
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
|
if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
|
||||||
xsnprintf(size_text, sizeof(size_text),
|
xsnprintf(size_text, sizeof(size_text),
|
||||||
@ -95,11 +95,11 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
|
|||||||
} else {
|
} else {
|
||||||
xsnprintf(size_text, sizeof(size_text), "-");
|
xsnprintf(size_text, sizeof(size_text), "-");
|
||||||
}
|
}
|
||||||
printf("%06o %s %s %7s\t", mode, type,
|
printf("%06o %s %s %7s\t", mode, type_name(type),
|
||||||
find_unique_abbrev(oid, abbrev),
|
find_unique_abbrev(oid, abbrev),
|
||||||
size_text);
|
size_text);
|
||||||
} else {
|
} else {
|
||||||
printf("%06o %s %s\t", mode, type,
|
printf("%06o %s %s\t", mode, type_name(type),
|
||||||
find_unique_abbrev(oid, abbrev));
|
find_unique_abbrev(oid, abbrev));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user