+static int cmd_version(int argc, char **argv, char **envp)
+{
+ printf("git version %s\n", GIT_VERSION);
+ return 0;
+}
+
+static int cmd_help(int argc, char **argv, char **envp)
+{
+ char *help_cmd = argv[1];
+ if (!help_cmd)
+ cmd_usage(git_exec_path(), NULL);
+ show_man_page(help_cmd);
+ return 0;
+}
+
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+
+static void handle_internal_command(int argc, char **argv, char **envp)
+{
+ const char *cmd = argv[0];
+ static struct cmd_struct {
+ const char *cmd;
+ int (*fn)(int, char **, char **);
+ } commands[] = {
+ { "version", cmd_version },
+ { "help", cmd_help },
+ };
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(commands); i++) {
+ struct cmd_struct *p = commands+i;
+ if (strcmp(p->cmd, cmd))
+ continue;
+ exit(p->fn(argc, argv, envp));
+ }
+}
+