Skip to content

Commit 26f6d4d

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 82e69b0 commit 26f6d4d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

builtin/ls-tree.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,25 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
6666
{
6767
int retval = 0;
6868
int baselen;
69-
const char *type = blob_type;
69+
enum object_type type = OBJ_BLOB;
7070

7171
if (S_ISGITLINK(mode)) {
72-
type = commit_type;
72+
type = OBJ_COMMIT;
7373
} else if (S_ISDIR(mode)) {
7474
if (show_recursive(base->buf, base->len, pathname)) {
7575
retval = READ_TREE_RECURSIVE;
7676
if (!(ls_options & LS_SHOW_TREES))
7777
return retval;
7878
}
79-
type = tree_type;
79+
type = OBJ_TREE;
8080
}
8181
else if (ls_options & LS_TREE_ONLY)
8282
return 0;
8383

8484
if (!(ls_options & LS_NAME_ONLY)) {
8585
if (ls_options & LS_SHOW_SIZE) {
8686
char size_text[24];
87-
if (!strcmp(type, blob_type)) {
87+
if (type == OBJ_BLOB) {
8888
unsigned long size;
8989
if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
9090
xsnprintf(size_text, sizeof(size_text),
@@ -95,11 +95,11 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
9595
} else {
9696
xsnprintf(size_text, sizeof(size_text), "-");
9797
}
98-
printf("%06o %s %s %7s\t", mode, type,
98+
printf("%06o %s %s %7s\t", mode, type_name(type),
9999
find_unique_abbrev(oid, abbrev),
100100
size_text);
101101
} else {
102-
printf("%06o %s %s\t", mode, type,
102+
printf("%06o %s %s\t", mode, type_name(type),
103103
find_unique_abbrev(oid, abbrev));
104104
}
105105
}

0 commit comments

Comments
 (0)