{"thread":{"id":"12856","subject":"[PATCH] shortlog: initialize nongit variable","startedAt":"2008-03-25T14:46:17Z","lastAt":"2008-03-25T21:06:26Z","messageCount":5,"participants":["SZEDER Gábor","Nguyen Thai Ngoc Duy","Jonas Fonseca"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"73042","messageId":"1206456377-2735-1-git-send-email-szeder@ira.uka.de","threadId":"12856","inReplyTo":null,"subject":"[PATCH] shortlog: initialize nongit variable","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2008-03-25T14:46:17Z","receivedAt":"2008-03-25T14:46:17Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"setup_git_directory_gently() only modifies the value of the nongit\nvariable if we are not in a git repository, therefore nongit is left\nuninitialized if we are in a git repository.  This sometimes broke\nshortlog when it was not fed with a log on its standard input.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n builtin-shortlog.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-shortlog.c b/builtin-shortlog.c\nindex bd795b1..60a6d45 100644\n--- a/builtin-shortlog.c\n+++ b/builtin-shortlog.c\n@@ -229,7 +229,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)\n {\n \tstruct shortlog log;\n \tstruct rev_info rev;\n-\tint nongit;\n+\tint nongit = 0;\n \n \tprefix = setup_git_directory_gently(&nongit);\n \tshortlog_init(&log);\n-- \n1.5.5.rc1\n"},{"id":"73046","messageId":"fcaeb9bf0803250839p721e1870l8fbc8715b3c6e7cb@mail.gmail.com","threadId":"12856","inReplyTo":"1206456377-2735-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH] shortlog: initialize nongit variable","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-25T15:39:38Z","receivedAt":"2008-03-25T15:39:38Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Mar 25, 2008 at 9:46 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> setup_git_directory_gently() only modifies the value of the nongit\n>  variable if we are not in a git repository, therefore nongit is left\n>  uninitialized if we are in a git repository.  This sometimes broke\n>  shortlog when it was not fed with a log on its standard input.\n\ncmd_help() has the same problem. Can you make a similar patch for\ncmd_help as well?\n\nThanks\n-- \nDuy\n"},{"id":"73048","messageId":"20080325160356.GC6506@neumann","threadId":"12856","inReplyTo":"fcaeb9bf0803250839p721e1870l8fbc8715b3c6e7cb@mail.gmail.com","subject":"Re: [PATCH] shortlog: initialize nongit variable","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2008-03-25T16:03:56Z","receivedAt":"2008-03-25T16:03:56Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Mar 25, 2008 at 10:39:38PM +0700, Nguyen Thai Ngoc Duy wrote:\n> On Tue, Mar 25, 2008 at 9:46 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> > setup_git_directory_gently() only modifies the value of the nongit\n> >  variable if we are not in a git repository, therefore nongit is left\n> >  uninitialized if we are in a git repository.  This sometimes broke\n> >  shortlog when it was not fed with a log on its standard input.\n> \n> cmd_help() has the same problem. Can you make a similar patch for\n> cmd_help as well?\nYes, I saw that, too, but:\n\nWhile it's true that cmd_help()'s nongit variable will not be\ninitialized if we are in a git repository, cmd_help() never touches\nnongit after calling setup_git_directory_gently(), so there is no\nproblem after all.\n\nHowever, it might be better to let setup_git_directory_gently() set\n*nongit_ok to 0 if we are in a git repository.  Patch appended.\n\n\nRegards,\nGábor\n\n\n\nAlways set *nongit_ok in setup_git_directory_gently()\n\nsetup_git_directory_gently() only modified the value of its *nongit_ok\nargument if we were not in a git repository.  Now it will always set it\nto 0 when we are inside a repository.\n\nAlso remove now unnecessary initializations in the callers of this\nfunction.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n builtin-bundle.c     |    2 +-\n builtin-config.c     |    2 +-\n builtin-diff-files.c |    2 +-\n builtin-ls-remote.c  |    2 +-\n git.c                |    2 +-\n setup.c              |    8 ++++++++\n 6 files changed, 13 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-bundle.c b/builtin-bundle.c\nindex 9f38e21..ac476e7 100644\n--- a/builtin-bundle.c\n+++ b/builtin-bundle.c\n@@ -14,7 +14,7 @@ static const char *bundle_usage=\"git-bundle (create <bundle> <git-rev-list args>\n int cmd_bundle(int argc, const char **argv, const char *prefix)\n {\n \tstruct bundle_header header;\n-\tint nongit = 0;\n+\tint nongit;\n \tconst char *cmd, *bundle_file;\n \tint bundle_fd = -1;\n \tchar buffer[PATH_MAX];\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 2b9a426..c34bc8b 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -264,7 +264,7 @@ static int get_colorbool(int argc, const char **argv)\n \n int cmd_config(int argc, const char **argv, const char *prefix)\n {\n-\tint nongit = 0;\n+\tint nongit;\n \tchar* value;\n \tconst char *file = setup_git_directory_gently(&nongit);\n \ndiff --git a/builtin-diff-files.c b/builtin-diff-files.c\nindex 4abe3c2..e2306c1 100644\n--- a/builtin-diff-files.c\n+++ b/builtin-diff-files.c\n@@ -16,7 +16,7 @@ COMMON_DIFF_OPTIONS_HELP;\n int cmd_diff_files(int argc, const char **argv, const char *prefix)\n {\n \tstruct rev_info rev;\n-\tint nongit = 0;\n+\tint nongit;\n \tint result;\n \n \tprefix = setup_git_directory_gently(&nongit);\ndiff --git a/builtin-ls-remote.c b/builtin-ls-remote.c\nindex 8907a89..06ab8da 100644\n--- a/builtin-ls-remote.c\n+++ b/builtin-ls-remote.c\n@@ -31,7 +31,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)\n {\n \tint i;\n \tconst char *dest = NULL;\n-\tint nongit = 0;\n+\tint nongit;\n \tunsigned flags = 0;\n \tconst char *uploadpack = NULL;\n \tconst char **pattern = NULL;\ndiff --git a/git.c b/git.c\nindex 13de801..70458af 100644\n--- a/git.c\n+++ b/git.c\n@@ -142,7 +142,7 @@ static int split_cmdline(char *cmdline, const char ***argv)\n \n static int handle_alias(int *argcp, const char ***argv)\n {\n-\tint nongit = 0, envchanged = 0, ret = 0, saved_errno = errno;\n+\tint nongit, envchanged = 0, ret = 0, saved_errno = errno;\n \tconst char *subdir;\n \tint count, option_count;\n \tconst char** new_argv;\ndiff --git a/setup.c b/setup.c\nindex 41e298b..3d2d958 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -326,6 +326,14 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \tint len, offset;\n \n \t/*\n+\t * Let's assume that we are in a git repository.\n+\t * If it turns out later that we are somewhere else, the value will be\n+\t * updated accordingly.\n+\t */\n+\tif (nongit_ok)\n+\t\t*nongit_ok = 0;\n+\n+\t/*\n \t * If GIT_DIR is set explicitly, we're not going\n \t * to do any discovery, but we still do repository\n \t * validation.\n-- \n1.5.5.rc1\n"},{"id":"73070","messageId":"2c6b72b30803251258j313e0d94qe290b8b7c7b377f0@mail.gmail.com","threadId":"12856","inReplyTo":"20080325160356.GC6506@neumann","subject":"Re: [PATCH] shortlog: initialize nongit variable","fromName":"Jonas Fonseca","fromEmail":"jonas.fonseca@gmail.com","sentAt":"2008-03-25T19:58:50Z","receivedAt":"2008-03-25T19:58:50Z","isPatch":true,"sender":{"key":"jonas.fonseca@gmail.com","avatar":"https://gravatar.com/avatar/9b7fa23cce50269e5d164312b6ac5ae818a180f837b38f28f3bdf689dd7f96cd?d=mp&s=160"},"body":"2008/3/25 SZEDER Gábor <szeder@ira.uka.de>:\n>  However, it might be better to let setup_git_directory_gently() set\n>  *nongit_ok to 0 if we are in a git repository.  Patch appended.\n\nAs the one responsible for introducing this bug into shortlog, I can only agree.\n\n>   builtin-bundle.c     |    2 +-\n>   builtin-config.c     |    2 +-\n>   builtin-diff-files.c |    2 +-\n>   builtin-ls-remote.c  |    2 +-\n>   git.c                |    2 +-\n>   setup.c              |    8 ++++++++\n>   6 files changed, 13 insertions(+), 5 deletions(-)\n\ngit grep reveals that builtin-{apply,diff}.c, help.c and var.c also\nbelongs on this list.\n\n-- \nJonas Fonseca\n"},{"id":"73075","messageId":"20080325210600.GE6506@neumann","threadId":"12856","inReplyTo":"2c6b72b30803251258j313e0d94qe290b8b7c7b377f0@mail.gmail.com","subject":"Re: [PATCH] shortlog: initialize nongit variable","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2008-03-25T21:06:26Z","receivedAt":"2008-03-25T21:06:26Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Mar 25, 2008 at 08:58:50PM +0100, Jonas Fonseca wrote:\n> 2008/3/25 SZEDER Gábor <szeder@ira.uka.de>:\n> >   builtin-bundle.c     |    2 +-\n> >   builtin-config.c     |    2 +-\n> >   builtin-diff-files.c |    2 +-\n> >   builtin-ls-remote.c  |    2 +-\n> >   git.c                |    2 +-\n> >   setup.c              |    8 ++++++++\n> >   6 files changed, 13 insertions(+), 5 deletions(-)\n> \n> git grep reveals that builtin-{apply,diff}.c,\nRight, I have overseen them.  Updated patch appended.\n\n> help.c and var.c also belongs on this list.\nThey don't initialize (and use) their nongit variable.\n\nRegards,\nGábor\n\n\nAlways set *nongit_ok in setup_git_directory_gently()\n\nsetup_git_directory_gently() only modified the value of its *nongit_ok\nargument if we were not in a git repository.  Now it will always set it\nto 0 when we are inside a repository.\n\nAlso remove now unnecessary initializations in the callers of this\nfunction.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n builtin-apply.c      |    2 +-\n builtin-bundle.c     |    2 +-\n builtin-config.c     |    2 +-\n builtin-diff-files.c |    2 +-\n builtin-diff.c       |    2 +-\n builtin-ls-remote.c  |    2 +-\n git.c                |    2 +-\n setup.c              |    8 ++++++++\n 8 files changed, 15 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex a3f075d..b5f78ac 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -2994,7 +2994,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)\n \tint read_stdin = 1;\n \tint inaccurate_eof = 0;\n \tint errs = 0;\n-\tint is_not_gitdir = 0;\n+\tint is_not_gitdir;\n \n \tconst char *whitespace_option = NULL;\n \ndiff --git a/builtin-bundle.c b/builtin-bundle.c\nindex 9f38e21..ac476e7 100644\n--- a/builtin-bundle.c\n+++ b/builtin-bundle.c\n@@ -14,7 +14,7 @@ static const char *bundle_usage=\"git-bundle (create <bundle> <git-rev-list args>\n int cmd_bundle(int argc, const char **argv, const char *prefix)\n {\n \tstruct bundle_header header;\n-\tint nongit = 0;\n+\tint nongit;\n \tconst char *cmd, *bundle_file;\n \tint bundle_fd = -1;\n \tchar buffer[PATH_MAX];\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 2b9a426..c34bc8b 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -264,7 +264,7 @@ static int get_colorbool(int argc, const char **argv)\n \n int cmd_config(int argc, const char **argv, const char *prefix)\n {\n-\tint nongit = 0;\n+\tint nongit;\n \tchar* value;\n \tconst char *file = setup_git_directory_gently(&nongit);\n \ndiff --git a/builtin-diff-files.c b/builtin-diff-files.c\nindex 4abe3c2..e2306c1 100644\n--- a/builtin-diff-files.c\n+++ b/builtin-diff-files.c\n@@ -16,7 +16,7 @@ COMMON_DIFF_OPTIONS_HELP;\n int cmd_diff_files(int argc, const char **argv, const char *prefix)\n {\n \tstruct rev_info rev;\n-\tint nongit = 0;\n+\tint nongit;\n \tint result;\n \n \tprefix = setup_git_directory_gently(&nongit);\ndiff --git a/builtin-diff.c b/builtin-diff.c\nindex 444ff2f..7c2a841 100644\n--- a/builtin-diff.c\n+++ b/builtin-diff.c\n@@ -210,7 +210,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \tint ents = 0, blobs = 0, paths = 0;\n \tconst char *path = NULL;\n \tstruct blobinfo blob[2];\n-\tint nongit = 0;\n+\tint nongit;\n \tint result = 0;\n \n \t/*\ndiff --git a/builtin-ls-remote.c b/builtin-ls-remote.c\nindex 8907a89..06ab8da 100644\n--- a/builtin-ls-remote.c\n+++ b/builtin-ls-remote.c\n@@ -31,7 +31,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)\n {\n \tint i;\n \tconst char *dest = NULL;\n-\tint nongit = 0;\n+\tint nongit;\n \tunsigned flags = 0;\n \tconst char *uploadpack = NULL;\n \tconst char **pattern = NULL;\ndiff --git a/git.c b/git.c\nindex 13de801..70458af 100644\n--- a/git.c\n+++ b/git.c\n@@ -142,7 +142,7 @@ static int split_cmdline(char *cmdline, const char ***argv)\n \n static int handle_alias(int *argcp, const char ***argv)\n {\n-\tint nongit = 0, envchanged = 0, ret = 0, saved_errno = errno;\n+\tint nongit, envchanged = 0, ret = 0, saved_errno = errno;\n \tconst char *subdir;\n \tint count, option_count;\n \tconst char** new_argv;\ndiff --git a/setup.c b/setup.c\nindex 41e298b..3d2d958 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -326,6 +326,14 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \tint len, offset;\n \n \t/*\n+\t * Let's assume that we are in a git repository.\n+\t * If it turns out later that we are somewhere else, the value will be\n+\t * updated accordingly.\n+\t */\n+\tif (nongit_ok)\n+\t\t*nongit_ok = 0;\n+\n+\t/*\n \t * If GIT_DIR is set explicitly, we're not going\n \t * to do any discovery, but we still do repository\n \t * validation.\n-- \n1.5.5.rc1.7.g249d1\n"}]}