{"thread":{"id":"5042","subject":"[PATCH] allow alias expansion without a git directory","startedAt":"2006-07-30T01:30:29Z","lastAt":"2006-07-30T09:34:57Z","messageCount":2,"participants":["Matthias Lederhofer","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"24359","messageId":"E1G708T-00073m-Hg@moooo.ath.cx","threadId":"5042","inReplyTo":null,"subject":"[PATCH] allow alias expansion without a git directory","fromName":"Matthias Lederhofer","fromEmail":"matled@gmx.net","sentAt":"2006-07-30T01:30:29Z","receivedAt":"2006-07-30T01:30:29Z","isPatch":true,"sender":{"key":"matled@gmx.net","avatar":null},"body":"Signed-off-by: Matthias Lederhofer <matled@gmx.net>\n---\nWith this patch\n[alias]\n    init = init-db --template=/path/to/template\nis usable.\nThe change in setup_git_directory_gently is a bug which did not cause\nany problems yet (afaict): setup_git_directory_gently did die even\nthough nongit_ok was not NULL.  Without this GIT_DIR=.foo git init\nwill die.\n---\n git.c   |   76 ++++++++++++++++++++++++++++++---------------------------------\n setup.c |    4 +++\n 2 files changed, 40 insertions(+), 40 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 452180e..7321d6c 100644\n--- a/git.c\n+++ b/git.c\n@@ -156,52 +156,48 @@ static int handle_alias(int *argcp, cons\n {\n \tint nongit = 0, ret = 0, saved_errno = errno;\n \tconst char *subdir;\n+\tint count, option_count;\n+\tconst char** new_argv;\n \n \tsubdir = setup_git_directory_gently(&nongit);\n-\tif (!nongit) {\n-\t\tint count, option_count;\n-\t\tconst char** new_argv;\n-\n-\t\talias_command = (*argv)[0];\n-\t\tgit_config(git_alias_config);\n-\t\tif (alias_string) {\n-\n-\t\t\tcount = split_cmdline(alias_string, &new_argv);\n-\t\t\toption_count = handle_options(&new_argv, &count);\n-\t\t\tmemmove(new_argv - option_count, new_argv,\n-\t\t\t\t\tcount * sizeof(char *));\n-\t\t\tnew_argv -= option_count;\n-\n-\t\t\tif (count < 1)\n-\t\t\t\tdie(\"empty alias for %s\", alias_command);\n-\n-\t\t\tif (!strcmp(alias_command, new_argv[0]))\n-\t\t\t\tdie(\"recursive alias: %s\", alias_command);\n-\n-\t\t\tif (getenv(\"GIT_TRACE\")) {\n-\t\t\t\tint i;\n-\t\t\t\tfprintf(stderr, \"trace: alias expansion: %s =>\",\n-\t\t\t\t\talias_command);\n-\t\t\t\tfor (i = 0; i < count; ++i) {\n-\t\t\t\t\tfputc(' ', stderr);\n-\t\t\t\t\tsq_quote_print(stderr, new_argv[i]);\n-\t\t\t\t}\n-\t\t\t\tfputc('\\n', stderr);\n-\t\t\t\tfflush(stderr);\n-\t\t\t}\n \n-\t\t\tnew_argv = realloc(new_argv, sizeof(char*) *\n-\t\t\t\t\t   (count + *argcp + 1));\n-\t\t\t/* insert after command name */\n-\t\t\tmemcpy(new_argv + count, *argv + 1,\n-\t\t\t       sizeof(char*) * *argcp);\n-\t\t\tnew_argv[count+*argcp] = NULL;\n+\talias_command = (*argv)[0];\n+\tgit_config(git_alias_config);\n+\tif (alias_string) {\n+\t\tcount = split_cmdline(alias_string, &new_argv);\n+\t\toption_count = handle_options(&new_argv, &count);\n+\t\tmemmove(new_argv - option_count, new_argv,\n+\t\t\t\tcount * sizeof(char *));\n+\t\tnew_argv -= option_count;\n+\n+\t\tif (count < 1)\n+\t\t\tdie(\"empty alias for %s\", alias_command);\n \n-\t\t\t*argv = new_argv;\n-\t\t\t*argcp += count - 1;\n+\t\tif (!strcmp(alias_command, new_argv[0]))\n+\t\t\tdie(\"recursive alias: %s\", alias_command);\n \n-\t\t\tret = 1;\n+\t\tif (getenv(\"GIT_TRACE\")) {\n+\t\t\tint i;\n+\t\t\tfprintf(stderr, \"trace: alias expansion: %s =>\",\n+\t\t\t\talias_command);\n+\t\t\tfor (i = 0; i < count; ++i) {\n+\t\t\t\tfputc(' ', stderr);\n+\t\t\t\tsq_quote_print(stderr, new_argv[i]);\n+\t\t\t}\n+\t\t\tfputc('\\n', stderr);\n+\t\t\tfflush(stderr);\n \t\t}\n+\n+\t\tnew_argv = realloc(new_argv, sizeof(char*) *\n+\t\t\t\t   (count + *argcp + 1));\n+\t\t/* insert after command name */\n+\t\tmemcpy(new_argv + count, *argv + 1, sizeof(char*) * *argcp);\n+\t\tnew_argv[count+*argcp] = NULL;\n+\n+\t\t*argv = new_argv;\n+\t\t*argcp += count - 1;\n+\n+\t\tret = 1;\n \t}\n \n \tif (subdir)\ndiff --git a/setup.c b/setup.c\nindex 4612f11..358e139 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -184,6 +184,10 @@ const char *setup_git_directory_gently(i\n \t\t}\n \t\treturn NULL;\n \tbad_dir_environ:\n+\t\tif (!nongit_ok) {\n+\t\t\t*nongit_ok = 1;\n+\t\t\treturn NULL;\n+\t\t}\n \t\tpath[len] = 0;\n \t\tdie(\"Not a git repository: '%s'\", path);\n \t}\n-- \n1.4.2.rc2.g91b7\n"},{"id":"24364","messageId":"Pine.LNX.4.63.0607301133380.29667@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"5042","inReplyTo":"E1G708T-00073m-Hg@moooo.ath.cx","subject":"Re: [PATCH] allow alias expansion without a git directory","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-07-30T09:34:57Z","receivedAt":"2006-07-30T09:34:57Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 30 Jul 2006, Matthias Lederhofer wrote:\n\n> diff --git a/setup.c b/setup.c\n> index 4612f11..358e139 100644\n> --- a/setup.c\n> +++ b/setup.c\n> @@ -184,6 +184,10 @@ const char *setup_git_directory_gently(i\n>  \t\t}\n>  \t\treturn NULL;\n>  \tbad_dir_environ:\n> +\t\tif (!nongit_ok) {\n> +\t\t\t*nongit_ok = 1;\n> +\t\t\treturn NULL;\n> +\t\t}\n\nFunny. Yesterday, I looked through \"git diff next\", and decided to sync \nthis part, i.e. undo the change you just proposed...\n\nCiao,\nDscho\n"}]}