{"thread":{"id":"35756","subject":"[PATCH 5/5] builtin/commit.c: reduce scope of variables","startedAt":"2014-01-29T13:48:31Z","lastAt":"2014-01-29T20:17:07Z","messageCount":2,"participants":["Elia Pinto","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"233891","messageId":"1391003311-11126-1-git-send-email-gitter.spiros@gmail.com","threadId":"35756","inReplyTo":null,"subject":"[PATCH 5/5] builtin/commit.c: reduce scope of variables","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2014-01-29T13:48:31Z","receivedAt":"2014-01-29T13:48:31Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>\n---\n builtin/commit.c |   11 ++++++-----\n 1 file changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 3767478..eea4421 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -307,7 +307,6 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,\n \tint fd;\n \tstruct string_list partial;\n \tstruct pathspec pathspec;\n-\tchar *old_index_env = NULL;\n \tint refresh_flags = REFRESH_QUIET;\n \n \tif (is_status)\n@@ -320,6 +319,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,\n \t\tdie(_(\"index file corrupt\"));\n \n \tif (interactive) {\n+\t\tchar *old_index_env = NULL;\n \t\tfd = hold_locked_index(&index_lock, 1);\n \n \t\trefresh_cache_or_die(refresh_flags);\n@@ -600,12 +600,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n {\n \tstruct stat statbuf;\n \tstruct strbuf committer_ident = STRBUF_INIT;\n-\tint commitable, saved_color_setting;\n+\tint commitable;\n \tstruct strbuf sb = STRBUF_INIT;\n-\tchar *buffer;\n \tconst char *hook_arg1 = NULL;\n \tconst char *hook_arg2 = NULL;\n-\tint ident_shown = 0;\n \tint clean_message_contents = (cleanup_mode != CLEANUP_NONE);\n \tint old_display_comment_prefix;\n \n@@ -649,6 +647,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\t\t\t  logfile);\n \t\thook_arg1 = \"message\";\n \t} else if (use_message) {\n+\t\tchar *buffer;\n \t\tbuffer = strstr(use_message_buffer, \"\\n\\n\");\n \t\tif (!use_editor && (!buffer || buffer[2] == '\\0'))\n \t\t\tdie(_(\"commit has empty message\"));\n@@ -753,6 +752,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t/* This checks if committer ident is explicitly given */\n \tstrbuf_addstr(&committer_ident, git_committer_info(IDENT_STRICT));\n \tif (use_editor && include_status) {\n+\t\tint ident_shown = 0;\n+\t\tint saved_color_setting;\n \t\tchar *ai_tmp, *ci_tmp;\n \t\tif (whence != FROM_COMMIT)\n \t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL,\n@@ -1510,7 +1511,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \tstruct ref_lock *ref_lock;\n \tstruct commit_list *parents = NULL, **pptr = &parents;\n \tstruct stat statbuf;\n-\tint allow_fast_forward = 1;\n \tstruct commit *current_head = NULL;\n \tstruct commit_extra_header *extra = NULL;\n \n@@ -1576,6 +1576,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\t}\n \t\tfclose(fp);\n \t\tstrbuf_release(&m);\n+\t\tint allow_fast_forward = 1;\n \t\tif (!stat(git_path(\"MERGE_MODE\"), &statbuf)) {\n \t\t\tif (strbuf_read_file(&sb, git_path(\"MERGE_MODE\"), 0) < 0)\n \t\t\t\tdie_errno(_(\"could not read MERGE_MODE\"));\n-- \n1.7.10.4\n"},{"id":"233900","messageId":"CAPig+cR3DdPS3W_FNPnXG+NO0gUG2PSLH0qNmFUsoxJcy0MVsQ@mail.gmail.com","threadId":"35756","inReplyTo":"1391003311-11126-1-git-send-email-gitter.spiros@gmail.com","subject":"Re: [PATCH 5/5] builtin/commit.c: reduce scope of variables","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-01-29T20:17:07Z","receivedAt":"2014-01-29T20:17:07Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Jan 29, 2014 at 8:48 AM, Elia Pinto <gitter.spiros@gmail.com> wrote:\n> diff --git a/builtin/commit.c b/builtin/commit.c\n> index 3767478..eea4421 100644\n> --- a/builtin/commit.c\n> +++ b/builtin/commit.c\n> @@ -1510,7 +1511,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n>         struct ref_lock *ref_lock;\n>         struct commit_list *parents = NULL, **pptr = &parents;\n>         struct stat statbuf;\n> -       int allow_fast_forward = 1;\n>         struct commit *current_head = NULL;\n>         struct commit_extra_header *extra = NULL;\n>\n> @@ -1576,6 +1576,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n>                 }\n>                 fclose(fp);\n>                 strbuf_release(&m);\n> +               int allow_fast_forward = 1;\n\nThis introduces a declaration-after-statement, which is frowned upon\nin this project.\n\n>                 if (!stat(git_path(\"MERGE_MODE\"), &statbuf)) {\n>                         if (strbuf_read_file(&sb, git_path(\"MERGE_MODE\"), 0) < 0)\n>                                 die_errno(_(\"could not read MERGE_MODE\"));\n> --\n> 1.7.10.4\n"}]}