Document the --(no-)edit switch of git-revert and git-cherry-pick
[git.git] / git.c
diff --git a/git.c b/git.c
index bdd3f8d..0975fc7 100644 (file)
--- a/git.c
+++ b/git.c
 # define PATH_MAX 4096
 #endif
 
+#ifdef NO_SETENV
+extern int gitsetenv(const char *, const char *, int);
+#endif
+
 static const char git_usage[] =
        "Usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--help] COMMAND [ ARGS ]";
 
@@ -188,7 +192,6 @@ static void prepend_to_path(const char *dir, int len)
        path_len = len + strlen(old_path) + 1;
 
        path = malloc(path_len + 1);
-       path[path_len + 1] = '\0';
 
        memcpy(path, dir, len);
        path[len] = ':';
@@ -273,7 +276,7 @@ int main(int argc, char **argv, char **envp)
                while (!strncmp(exec_path, "./", 2)) {
                        exec_path += 2;
                        while (*exec_path == '/')
-                               *exec_path++;
+                               exec_path++;
                }
                snprintf(git_command + len, sizeof(git_command) - len,
                         "/%s", exec_path);
@@ -283,16 +286,21 @@ int main(int argc, char **argv, char **envp)
        len = strlen(git_command);
        prepend_to_path(git_command, len);
 
-       strncat(&git_command[len], "/git-", sizeof(git_command) - len);
-       len += 5;
-       strncat(&git_command[len], argv[i], sizeof(git_command) - len);
-
-       if (access(git_command, X_OK))
-               usage(exec_path, "'%s' is not a git-command", argv[i]);
+       len += snprintf(git_command + len, sizeof(git_command) - len,
+                       "/git-%s", argv[i]);
+       if (sizeof(git_command) <= len) {
+               fprintf(stderr, "git: command name given is too long (%d)\n", len);
+               exit(1);
+       }
 
        /* execve() can only ever return if it fails */
        execve(git_command, &argv[i], envp);
-       printf("Failed to run command '%s': %s\n", git_command, strerror(errno));
+
+       if (errno == ENOENT)
+               usage(exec_path, "'%s' is not a git-command", argv[i]);
+
+       fprintf(stderr, "Failed to run command '%s': %s\n",
+               git_command, strerror(errno));
 
        return 1;
 }