@matheusbsbs / matheus-bagliano / commits / e392a85236
Fork 0

Produce a nicer output in case of sha1_object_info failures in ls-tree -l

An error message is already printed by sha1_object_info itself, and the failed entries are additionally marked in the listing. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alex Riesen committed Mar 19, 2009 at 23:54 UTC e392a852364e375e916c1dd4f87a7584b348410a
1 file changed +12 -10
builtin-ls-tree.c
+12 -10
@@ -60,7 +60,6 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
60 {
61 int retval = 0;
62 const char *type = blob_type;
63 - unsigned long size;
63
64 if (S_ISGITLINK(mode)) {
65 /*
@@ -90,17 +89,20 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
89
90 if (!(ls_options & LS_NAME_ONLY)) {
91 if (ls_options & LS_SHOW_SIZE) {
92 + char size_text[24];
93 if (!strcmp(type, blob_type)) {
94 - sha1_object_info(sha1, &size);
95 - printf("%06o %s %s %7lu\t", mode, type,
96 - abbrev ? find_unique_abbrev(sha1, abbrev)
97 - : sha1_to_hex(sha1),
98 - size);
94 + unsigned long size;
95 + if (sha1_object_info(sha1, &size) == OBJ_BAD)
96 + strcpy(size_text, "BAD");
97 + else
98 + snprintf(size_text, sizeof(size_text),
99 + "%lu", size);
100 } else
100 - printf("%06o %s %s %7c\t", mode, type,
101 - abbrev ? find_unique_abbrev(sha1, abbrev)
102 - : sha1_to_hex(sha1),
103 - '-');
101 + strcpy(size_text, "-");
102 + printf("%06o %s %s %7s\t", mode, type,
103 + abbrev ? find_unique_abbrev(sha1, abbrev)
104 + : sha1_to_hex(sha1),
105 + size_text);
106 } else
107 printf("%06o %s %s\t", mode, type,
108 abbrev ? find_unique_abbrev(sha1, abbrev)