| 159 | }; |
| 160 | |
| 161 | int cmd_main(int argc, const char **argv) |
| 162 | { |
| 163 | char *prog; |
| 164 | const char **user_argv; |
| 165 | struct commands *cmd; |
| 166 | int count; |
| 167 | |
| 168 | /* |
| 169 | * Special hack to pretend to be a CVS server |
| 170 | */ |
| 171 | if (argc == 2 && !strcmp(argv[1], "cvs server")) { |
| 172 | argv--; |
| 173 | } else if (argc == 1) { |
| 174 | /* Allow the user to run an interactive shell */ |
| 175 | cd_to_homedir(); |
| 176 | if (access(COMMAND_DIR, R_OK | X_OK) == -1) { |
| 177 | die("Interactive git shell is not enabled.\n" |
| 178 | "hint: ~/" COMMAND_DIR " should exist " |
| 179 | "and have read and execute access."); |
| 180 | } |
| 181 | run_shell(); |
| 182 | exit(0); |
| 183 | } else if (argc != 3 || strcmp(argv[1], "-c")) { |
| 184 | /* |
| 185 | * We do not accept any other modes except "-c" followed by |
| 186 | * "cmd arg", where "cmd" is a very limited subset of git |
| 187 | * commands or a command in the COMMAND_DIR |
| 188 | */ |
| 189 | die("Run with no arguments or with -c cmd"); |
| 190 | } |
| 191 | |
| 192 | prog = xstrdup(argv[2]); |
| 193 | if (!strncmp(prog, "git", 3) && isspace(prog[3])) |
| 194 | /* Accept "git foo" as if the caller said "git-foo". */ |
| 195 | prog[3] = '-'; |
| 196 | |
| 197 | for (cmd = cmd_list ; cmd->name ; cmd++) { |
| 198 | int len = strlen(cmd->name); |
| 199 | char *arg; |
| 200 | if (strncmp(cmd->name, prog, len)) |
| 201 | continue; |
| 202 | arg = NULL; |
| 203 | switch (prog[len]) { |
| 204 | case '\0': |
| 205 | arg = NULL; |
| 206 | break; |
| 207 | case ' ': |
| 208 | arg = prog + len + 1; |
| 209 | break; |
| 210 | default: |
| 211 | continue; |
| 212 | } |
| 213 | return cmd->exec(cmd->name, arg); |
| 214 | } |
| 215 | |
| 216 | cd_to_homedir(); |
| 217 | count = split_cmdline(prog, &user_argv); |
| 218 | if (count >= 0) { |
nothing calls this directly
no test coverage detected