Merge branch 'es/blame-commit-info-fix'
[gitweb.git] / git.c
diff --git a/git.c b/git.c
index a7d170c98e978981498dbe739536a9edc3b079fe..8c7ee9c83000765afa3808f3dd0941aa484ca1ec 100644 (file)
--- a/git.c
+++ b/git.c
@@ -6,7 +6,7 @@
 const char git_usage_string[] =
        "git [--version] [--help] [-C <path>] [-c name=value]\n"
        "           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n"
-       "           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\n"
+       "           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]\n"
        "           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
        "           <command> [<args>]";
 
@@ -484,15 +484,20 @@ static struct cmd_struct commands[] = {
        { "write-tree", cmd_write_tree, RUN_SETUP },
 };
 
-int is_builtin(const char *s)
+static struct cmd_struct *get_builtin(const char *s)
 {
        int i;
        for (i = 0; i < ARRAY_SIZE(commands); i++) {
-               struct cmd_struct *p = commands+i;
+               struct cmd_struct *p = commands + i;
                if (!strcmp(s, p->cmd))
-                       return 1;
+                       return p;
        }
-       return 0;
+       return NULL;
+}
+
+int is_builtin(const char *s)
+{
+       return !!get_builtin(s);
 }
 
 static void handle_builtin(int argc, const char **argv)
@@ -500,6 +505,7 @@ static void handle_builtin(int argc, const char **argv)
        const char *cmd = argv[0];
        int i;
        static const char ext[] = STRIP_EXTENSION;
+       struct cmd_struct *builtin;
 
        if (sizeof(ext) > 1) {
                i = strlen(argv[0]) - strlen(ext);
@@ -516,15 +522,12 @@ static void handle_builtin(int argc, const char **argv)
                argv[0] = cmd = "help";
        }
 
-       for (i = 0; i < ARRAY_SIZE(commands); i++) {
-               struct cmd_struct *p = commands+i;
-               if (strcmp(p->cmd, cmd))
-                       continue;
-               if (saved_environment && (p->option & NO_SETUP)) {
+       builtin = get_builtin(cmd);
+       if (builtin) {
+               if (saved_environment && (builtin->option & NO_SETUP))
                        restore_env();
-                       break;
-               }
-               exit(run_builtin(p, argc, argv));
+               else
+                       exit(run_builtin(builtin, argc, argv));
        }
 }