summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authorMatthias Lederhofer <matled@gmx.net>2006-07-30 03:30:29 +0200
committerJunio C Hamano <junkio@cox.net>2006-07-30 17:45:57 -0700
commit0347a8c7648ea9504badce7bb4ed4c4f3dbacf16 (patch)
tree644e7defd096fd86c8b19761f03cc76dd452f293 /git.c
parent41e95f699088b14c6a949ec858499f98df4f34f6 (diff)
downloadgit-0347a8c7648ea9504badce7bb4ed4c4f3dbacf16.tar.gz
git.c: allow alias expansion without a git directory
With this, the configuration mechanism can be used to say: [alias] init = init-db --template=/path/to/template Signed-off-by: Matthias Lederhofer <matled@gmx.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git.c')
-rw-r--r--git.c76
1 files changed, 36 insertions, 40 deletions
diff --git a/git.c b/git.c
index 452180e23a..7321d6c3f6 100644
--- a/git.c
+++ b/git.c
@@ -156,52 +156,48 @@ static int handle_alias(int *argcp, const char ***argv)
{
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)