Re: [PATCH] Produce a nicer output in case of sha1_object_info failures in ls-tree -l

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] Produce a nicer output in case of sha1_object_info failures in ls-tree -l

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:46:25

Alex Riesen [off-list ref] writes:
quoted hunk
Initialize the size with 0. The error message is already printed
by sha1_object_info itself. Otherwise the uninitialized size is
printed, which does not make any sense at all.

Signed-off-by: Alex Riesen <redacted>
---

 builtin-ls-tree.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c
index fca4631..a8cdafb 100644
--- a/builtin-ls-tree.c
+++ b/builtin-ls-tree.c
@@ -60,7 +60,6 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
 {
 	int retval = 0;
 	const char *type = blob_type;
-	unsigned long size;
 
 	if (S_ISGITLINK(mode)) {
 		/*
@@ -91,6 +90,7 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
 	if (!(ls_options & LS_NAME_ONLY)) {
 		if (ls_options & LS_SHOW_SIZE) {
 			if (!strcmp(type, blob_type)) {
+				unsigned long size = 0;
 				sha1_object_info(sha1, &size);
 				printf("%06o %s %s %7lu\t", mode, type,
 				       abbrev ? find_unique_abbrev(sha1, abbrev)
Hmm, shouldn't you be checking the return value from sha1_object_info()
and skipping the printf() altogether instead?

Re: [PATCH] Produce a nicer output in case of sha1_object_info failures in ls-tree -l

From: Alex Riesen <hidden>
Date: 2016-06-15 22:46:25

Junio C Hamano, Thu, Mar 19, 2009 22:55:56 +0100:
Alex Riesen [off-list ref] writes:
quoted
@@ -91,6 +90,7 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
 	if (!(ls_options & LS_NAME_ONLY)) {
 		if (ls_options & LS_SHOW_SIZE) {
 			if (!strcmp(type, blob_type)) {
+				unsigned long size = 0;
 				sha1_object_info(sha1, &size);
 				printf("%06o %s %s %7lu\t", mode, type,
 				       abbrev ? find_unique_abbrev(sha1, abbrev)
Hmm, shouldn't you be checking the return value from sha1_object_info()
and skipping the printf() altogether instead?
But then I cannot know the name of the failed tree entry.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help