{"thread":{"id":"38333","subject":"[PATCH] cat-file: remove definition of already defined variables","startedAt":"2015-01-10T18:13:23Z","lastAt":"2015-01-12T21:27:17Z","messageCount":2,"participants":["Alexander Kuleshov","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"254535","messageId":"1420913603-794-1-git-send-email-kuleshovmail@gmail.com","threadId":"38333","inReplyTo":null,"subject":"[PATCH] cat-file: remove definition of already defined variables","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-01-10T18:13:23Z","receivedAt":"2015-01-10T18:13:23Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"'enum object_type type' and 'unsigned long size' are already defined\nat the top of cat_one_file routine\n\nSigned-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n---\n builtin/cat-file.c | 2 --\n 1 file changed, 2 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 750b5a2..31b133b 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -75,8 +75,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)\n \t\tif (type_from_string(exp_type) == OBJ_BLOB) {\n \t\t\tunsigned char blob_sha1[20];\n \t\t\tif (sha1_object_info(sha1, NULL) == OBJ_TAG) {\n-\t\t\t\tenum object_type type;\n-\t\t\t\tunsigned long size;\n \t\t\t\tchar *buffer = read_sha1_file(sha1, &type, &size);\n \t\t\t\tconst char *target;\n \t\t\t\tif (!skip_prefix(buffer, \"object \", &target) ||\n-- \n2.2.1.532.g168b885.dirty\n"},{"id":"254563","messageId":"xmqqd26j7kqy.fsf@gitster.dls.corp.google.com","threadId":"38333","inReplyTo":"1420913603-794-1-git-send-email-kuleshovmail@gmail.com","subject":"Re: [PATCH] cat-file: remove definition of already defined variables","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-01-12T21:27:17Z","receivedAt":"2015-01-12T21:27:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Kuleshov <kuleshovmail@gmail.com> writes:\n\n> 'enum object_type type' and 'unsigned long size' are already defined\n> at the top of cat_one_file routine\n\nTrue.  That description applies to two completely different\nsituations, though, and does not help judging if the change is\ncorrect.\n\nScenario #1:\n\n\tunsigned long size;\n\n        size = something;\n        if (...) {\n        \tunsigned long size = something else;\n\t}\n\tuse(size);\n\nScenario #2:\n\n\tunsigned long size;\n\n        size = something;\n        if (...) {\n        \tunsigned long size = something else;\n\t}\n\tsize = yet another something else;\n\tuse(size);\n\nIn either case, the variable definition in the inner block hides the\nvariable that happens to share the same name, but in Scenario #1,\nthe hiding is deliberate and reusing the variable from outside would\nbreak the later use of the variable.\n\nIn the code in question, the outer variable's value before the block\nis not used after the block, so it is safe to remove the inner\ndefinition and reuse the variable from the outer block.\n\n\"already defined at the top\" does not help the readers to tell that\nwe are dealing with the Scenario #2 here.\n\nThanks, will apply after trying to come up with a better way to\nphrase this.\n\n> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n> ---\n>  builtin/cat-file.c | 2 --\n>  1 file changed, 2 deletions(-)\n>\n> diff --git a/builtin/cat-file.c b/builtin/cat-file.c\n> index 750b5a2..31b133b 100644\n> --- a/builtin/cat-file.c\n> +++ b/builtin/cat-file.c\n> @@ -75,8 +75,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)\n>  \t\tif (type_from_string(exp_type) == OBJ_BLOB) {\n>  \t\t\tunsigned char blob_sha1[20];\n>  \t\t\tif (sha1_object_info(sha1, NULL) == OBJ_TAG) {\n> -\t\t\t\tenum object_type type;\n> -\t\t\t\tunsigned long size;\n>  \t\t\t\tchar *buffer = read_sha1_file(sha1, &type, &size);\n>  \t\t\t\tconst char *target;\n>  \t\t\t\tif (!skip_prefix(buffer, \"object \", &target) ||\n"}]}