Re: [PATCH v3 2/2] Ensure git ls-tree exits with a non-zero exit code if read_tree_recursive fails.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fair point.

Everyone ok with this revision? If so, I will re-roll v4.

Jens: I added the variable back because the return statement with a
ternary operator needed a line break. Let me know
if there is a better way to format it.

jon.

diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index d96e9c4..990e1a3 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -120,7 +120,7 @@ int cmd_ls_tree(int argc, const char **argv, const
char *prefix)
 {
        unsigned char sha1[20];
        struct tree *tree;
-       int i, full_tree = 0;
+       int i, full_tree = 0, ret;
        const struct option ls_tree_options[] = {
                OPT_BIT('d', NULL, &ls_options, "only show trees",
                        LS_TREE_ONLY),
@@ -173,6 +173,7 @@ int cmd_ls_tree(int argc, const char **argv, const
char *prefix)
        tree = parse_tree_indirect(sha1);
        if (!tree)
                die("not a tree object");
-       return read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
+       ret = read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);

+       return ret ? 1 : 0;
 }


On Mon, Jul 25, 2011 at 11:31 AM, Nguyen Thai Ngoc Duy
<pclouds@xxxxxxxxx> wrote:
> On Sun, Jul 24, 2011 at 9:59 PM, Jon Seymour <jon.seymour@xxxxxxxxx> wrote:
>> @@ -173,7 +173,6 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
>>        tree = parse_tree_indirect(sha1);
>>        if (!tree)
>>                die("not a tree object");
>> -       read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
>> +       return read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
>>
>> -       return 0;
>
> Nit picking. Most programs return positive value (usually 1) for error
> cases here. read_tree_recursive may return -1 (which turns out to be
> 255). Also removing the last blank line in this function would be
> nice.
> --
> Duy
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]