Update gitweb README: gitweb is now included with git
[gitweb.git] / git.c
diff --git a/git.c b/git.c
index 88544724532b61e408cb6bb01caa11b626c7f74c..329ebec78cd057a14a22cca2e89a9cb09a53f5dd 100644 (file)
--- a/git.c
+++ b/git.c
@@ -122,9 +122,9 @@ static int handle_alias(int *argcp, const char ***argv)
                        /* insert after command name */
                        if (*argcp > 1) {
                                new_argv = realloc(new_argv, sizeof(char*) *
-                                               (count + *argcp - 1));
-                               memcpy(new_argv + count, *argv, sizeof(char*) *
-                                               (*argcp - 1));
+                                                  (count + *argcp));
+                               memcpy(new_argv + count, *argv + 1,
+                                      sizeof(char*) * *argcp);
                        }
 
                        *argv = new_argv;
@@ -163,7 +163,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
                { "add", cmd_add },
                { "rev-list", cmd_rev_list },
                { "init-db", cmd_init_db },
-               { "tar-tree", cmd_tar_tree },
+               { "get-tar-commit-id", cmd_get_tar_commit_id },
                { "upload-tar", cmd_upload_tar },
                { "check-ref-format", cmd_check_ref_format },
                { "ls-files", cmd_ls_files },
@@ -202,6 +202,7 @@ int main(int argc, const char **argv, char **envp)
        char *slash = strrchr(cmd, '/');
        char git_command[PATH_MAX + 1];
        const char *exec_path = NULL;
+       int done_alias = 0;
 
        /*
         * Take the basename of argv[0] as the command
@@ -229,7 +230,6 @@ int main(int argc, const char **argv, char **envp)
        if (!strncmp(cmd, "git-", 4)) {
                cmd += 4;
                argv[0] = cmd;
-               handle_alias(&argc, &argv);
                handle_internal_command(argc, argv, envp);
                die("cannot handle %s internally", cmd);
        }
@@ -287,13 +287,21 @@ int main(int argc, const char **argv, char **envp)
        exec_path = git_exec_path();
        prepend_to_path(exec_path, strlen(exec_path));
 
-       handle_alias(&argc, &argv);
+       while (1) {
+               /* See if it's an internal command */
+               handle_internal_command(argc, argv, envp);
 
-       /* See if it's an internal command */
-       handle_internal_command(argc, argv, envp);
+               /* .. then try the external ones */
+               execv_git_cmd(argv);
 
-       /* .. then try the external ones */
-       execv_git_cmd(argv);
+               /* It could be an alias -- this works around the insanity
+                * of overriding "git log" with "git show" by having
+                * alias.log = show
+                */
+               if (done_alias || !handle_alias(&argc, &argv))
+                       break;
+               done_alias = 1;
+       }
 
        if (errno == ENOENT)
                cmd_usage(0, exec_path, "'%s' is not a git-command", cmd);