From: Matthias Lederhofer <matled@gmx.net>
To: git@vger.kernel.org
Subject: [PATCH] allow alias expansion without a git directory
Date: Sun, 30 Jul 2006 03:30:29 +0200 [thread overview]
Message-ID: <E1G708T-00073m-Hg@moooo.ath.cx> (raw)
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
With this patch
[alias]
init = init-db --template=/path/to/template
is usable.
The change in setup_git_directory_gently is a bug which did not cause
any problems yet (afaict): setup_git_directory_gently did die even
though nongit_ok was not NULL. Without this GIT_DIR=.foo git init
will die.
---
git.c | 76 ++++++++++++++++++++++++++++++---------------------------------
setup.c | 4 +++
2 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/git.c b/git.c
index 452180e..7321d6c 100644
--- a/git.c
+++ b/git.c
@@ -156,52 +156,48 @@ static int handle_alias(int *argcp, cons
{
int nongit = 0, ret = 0, saved_errno = errno;
const char *subdir;
+ int count, option_count;
+ const char** new_argv;
subdir = setup_git_directory_gently(&nongit);
- if (!nongit) {
- int count, option_count;
- const char** new_argv;
-
- alias_command = (*argv)[0];
- git_config(git_alias_config);
- if (alias_string) {
-
- count = split_cmdline(alias_string, &new_argv);
- option_count = handle_options(&new_argv, &count);
- memmove(new_argv - option_count, new_argv,
- count * sizeof(char *));
- new_argv -= option_count;
-
- if (count < 1)
- die("empty alias for %s", alias_command);
-
- if (!strcmp(alias_command, new_argv[0]))
- die("recursive alias: %s", alias_command);
-
- if (getenv("GIT_TRACE")) {
- int i;
- fprintf(stderr, "trace: alias expansion: %s =>",
- alias_command);
- for (i = 0; i < count; ++i) {
- fputc(' ', stderr);
- sq_quote_print(stderr, new_argv[i]);
- }
- fputc('\n', stderr);
- fflush(stderr);
- }
- new_argv = realloc(new_argv, sizeof(char*) *
- (count + *argcp + 1));
- /* insert after command name */
- memcpy(new_argv + count, *argv + 1,
- sizeof(char*) * *argcp);
- new_argv[count+*argcp] = NULL;
+ alias_command = (*argv)[0];
+ git_config(git_alias_config);
+ if (alias_string) {
+ count = split_cmdline(alias_string, &new_argv);
+ option_count = handle_options(&new_argv, &count);
+ memmove(new_argv - option_count, new_argv,
+ count * sizeof(char *));
+ new_argv -= option_count;
+
+ if (count < 1)
+ die("empty alias for %s", alias_command);
- *argv = new_argv;
- *argcp += count - 1;
+ if (!strcmp(alias_command, new_argv[0]))
+ die("recursive alias: %s", alias_command);
- ret = 1;
+ if (getenv("GIT_TRACE")) {
+ int i;
+ fprintf(stderr, "trace: alias expansion: %s =>",
+ alias_command);
+ for (i = 0; i < count; ++i) {
+ fputc(' ', stderr);
+ sq_quote_print(stderr, new_argv[i]);
+ }
+ fputc('\n', stderr);
+ fflush(stderr);
}
+
+ new_argv = realloc(new_argv, sizeof(char*) *
+ (count + *argcp + 1));
+ /* insert after command name */
+ memcpy(new_argv + count, *argv + 1, sizeof(char*) * *argcp);
+ new_argv[count+*argcp] = NULL;
+
+ *argv = new_argv;
+ *argcp += count - 1;
+
+ ret = 1;
}
if (subdir)
diff --git a/setup.c b/setup.c
index 4612f11..358e139 100644
--- a/setup.c
+++ b/setup.c
@@ -184,6 +184,10 @@ const char *setup_git_directory_gently(i
}
return NULL;
bad_dir_environ:
+ if (!nongit_ok) {
+ *nongit_ok = 1;
+ return NULL;
+ }
path[len] = 0;
die("Not a git repository: '%s'", path);
}
--
1.4.2.rc2.g91b7
next reply other threads:[~2006-07-30 1:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-30 1:30 Matthias Lederhofer [this message]
2006-07-30 9:34 ` [PATCH] allow alias expansion without a git directory Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1G708T-00073m-Hg@moooo.ath.cx \
--to=matled@gmx.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox