int main(int argc, char **argv) { struct strbuf buf = STRBUF_INIT; unsigned char result_sha1[20]; if (argc != 1) usage("git mktag < signaturefile"); git_extract_argv0_path(argv[0]); setup_git_directory(); if (strbuf_read(&buf, 0, 4096) < 0) { die("could not read from stdin"); } /* Verify it for some basic sanity: it needs to start with "object <sha1>\ntype\ntagger " */ if (verify_tag(buf.buf, buf.len) < 0) die("invalid tag signature file"); if (write_sha1_file(buf.buf, buf.len, tag_type, result_sha1) < 0) die("unable to write tag file"); strbuf_release(&buf); printf("%s\n", sha1_to_hex(result_sha1)); return 0; }
int main(int argc, char **argv) { const char *val; int nongit; if (argc != 2) { usage(var_usage); } git_extract_argv0_path(argv[0]); setup_git_directory_gently(&nongit); val = NULL; if (strcmp(argv[1], "-l") == 0) { git_config(show_config, NULL); list_vars(); return 0; } git_config(git_default_config, NULL); val = read_var(argv[1]); if (!val) usage(var_usage); printf("%s\n", val); return 0; }
int git_init() { char path[MAX_PATH+1]; int ret; size_t homesize; _fmode = _O_BINARY; _setmode(_fileno(stdin), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY); _setmode(_fileno(stderr), _O_BINARY); // set HOME if not set already getenv_s(&homesize, NULL, 0, "HOME"); if (!homesize) { _wputenv_s(L"HOME", wget_windows_home_directory()); } GetModuleFileName(NULL, path, MAX_PATH); convert_slash(path); git_extract_argv0_path(path); g_prefix = setup_git_directory(); ret = git_config(git_default_config, NULL); if (!homesize) { _putenv_s("HOME","");/* clear home evironment to avoid affact third part software*/ } return ret; }
int main(int argc, char **argv) { struct strbuf buf = STRBUF_INIT, url_sb = STRBUF_INIT, private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT, notes_ref_sb = STRBUF_INIT; static struct remote *remote; const char *url_in; git_extract_argv0_path(argv[0]); setup_git_directory(); if (argc < 2 || argc > 3) { usage("git-remote-svn <remote-name> [<url>]"); return 1; } remote = remote_get(argv[1]); url_in = (argc == 3) ? argv[2] : remote->url[0]; if (starts_with(url_in, "file://")) { dump_from_file = 1; url = url_decode(url_in + sizeof("file://")-1); } else { dump_from_file = 0; end_url_with_slash(&url_sb, url_in); url = url_sb.buf; } strbuf_addf(&private_ref_sb, "refs/svn/%s/master", remote->name); private_ref = private_ref_sb.buf; strbuf_addf(¬es_ref_sb, "refs/notes/%s/revs", remote->name); notes_ref = notes_ref_sb.buf; strbuf_addf(&marksfilename_sb, "%s/info/fast-import/remote-svn/%s.marks", get_git_dir(), remote->name); marksfilename = marksfilename_sb.buf; while (1) { if (strbuf_getline(&buf, stdin, '\n') == EOF) { if (ferror(stdin)) die("Error reading command stream"); else die("Unexpected end of command stream"); } if (do_command(&buf)) break; strbuf_reset(&buf); } strbuf_release(&buf); strbuf_release(&url_sb); strbuf_release(&private_ref_sb); strbuf_release(¬es_ref_sb); strbuf_release(&marksfilename_sb); return 0; }
int main(int argc, char **argv) { char *dir; int i; int strict = 0; git_setup_gettext(); packet_trace_identity("upload-pack"); git_extract_argv0_path(argv[0]); read_replace_refs = 0; for (i = 1; i < argc; i++) { char *arg = argv[i]; if (arg[0] != '-') break; if (!strcmp(arg, "--advertise-refs")) { advertise_refs = 1; continue; } if (!strcmp(arg, "--stateless-rpc")) { stateless_rpc = 1; continue; } if (!strcmp(arg, "--strict")) { strict = 1; continue; } if (!prefixcmp(arg, "--timeout=")) { timeout = atoi(arg+10); daemon_mode = 1; continue; } if (!strcmp(arg, "--")) { i++; break; } } if (i != argc-1) usage(upload_pack_usage); setup_path(); dir = argv[i]; if (!enter_repo(dir, strict)) die("'%s' does not appear to be a git repository", dir); if (is_repository_shallow()) die("attempt to fetch/clone from a shallow repository"); git_config(upload_pack_config, NULL); upload_pack(); return 0; }
int main(int argc, char **argv) { int i, force_file = 0; /* Without this we cannot rely on waitpid() to tell * what happened to our children. */ signal(SIGCHLD, SIG_DFL); if (argc < 3) usage("git merge-index [-o] [-q] <merge-program> (-a | [--] <filename>*)"); git_extract_argv0_path(argv[0]); setup_git_directory(); read_cache(); i = 1; if (!strcmp(argv[i], "-o")) { one_shot = 1; i++; } if (!strcmp(argv[i], "-q")) { quiet = 1; i++; } pgm = argv[i++]; for (; i < argc; i++) { char *arg = argv[i]; if (!force_file && *arg == '-') { if (!strcmp(arg, "--")) { force_file = 1; continue; } if (!strcmp(arg, "-a")) { merge_all(); continue; } die("git merge-index: unknown option %s", arg); } merge_file(arg); } if (err && !quiet) die("merge program failed"); return err; }
int main(int argc, char **argv) { char *dir; int i; int strict = 0; git_extract_argv0_path(argv[0]); read_replace_refs = 0; for (i = 1; i < argc; i++) { char *arg = argv[i]; if (arg[0] != '-') break; if (!strcmp(arg, "--strict")) { strict = 1; continue; } if (!prefixcmp(arg, "--timeout=")) { timeout = atoi(arg+10); daemon_mode = 1; continue; } if (!strcmp(arg, "--")) { i++; break; } } if (i != argc-1) usage(upload_pack_usage); setup_path(); dir = argv[i]; if (!enter_repo(dir, strict)) die("'%s' does not appear to be a git repository", dir); if (is_repository_shallow()) die("attempt to fetch/clone from a shallow repository"); if (getenv("GIT_DEBUG_SEND_PACK")) debug_fd = atoi(getenv("GIT_DEBUG_SEND_PACK")); upload_pack(); return 0; }
int main(int argc, const char **argv) { /* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids messing up when the pipes are dup'ed * onto stdin/stdout/stderr in the child processes we spawn. */ sanitize_stdfds(); git_extract_argv0_path(argv[0]); git_setup_gettext(); attr_start(); restore_sigpipe_to_default(); return cmd_main(argc, argv); }
int main(int argc, const char **argv) { struct strbuf buf = STRBUF_INIT; int nongit; git_extract_argv0_path(argv[0]); setup_git_directory_gently(&nongit); if (argc < 2) { fprintf(stderr, "Remote needed\n"); return 1; } options.verbosity = 1; options.progress = !!isatty(2); options.thin = 1; remote = remote_get(argv[1]); if (argc > 2) { end_url_with_slash(&buf, argv[2]); } else { end_url_with_slash(&buf, remote->url[0]); } url = strbuf_detach(&buf, NULL); http_init(remote, url, 0); do { if (strbuf_getline(&buf, stdin, '\n') == EOF) { if (ferror(stdin)) fprintf(stderr, "Error reading command stream\n"); else fprintf(stderr, "Unexpected end of command stream\n"); return 1; } if (buf.len == 0) break; if (!prefixcmp(buf.buf, "fetch ")) { if (nongit) die("Fetch attempted without a local repo"); parse_fetch(&buf); } else if (!strcmp(buf.buf, "list") || !prefixcmp(buf.buf, "list ")) { int for_push = !!strstr(buf.buf + 4, "for-push"); output_refs(get_refs(for_push)); } else if (!prefixcmp(buf.buf, "push ")) { parse_push(&buf); } else if (!prefixcmp(buf.buf, "option ")) { char *name = buf.buf + strlen("option "); char *value = strchr(name, ' '); int result; if (value) *value++ = '\0'; else value = "true"; result = set_option(name, value); if (!result) printf("ok\n"); else if (result < 0) printf("error invalid value\n"); else printf("unsupported\n"); fflush(stdout); } else if (!strcmp(buf.buf, "capabilities")) { printf("fetch\n"); printf("option\n"); printf("push\n"); printf("\n"); fflush(stdout); } else { fprintf(stderr, "Unknown command '%s'\n", buf.buf); return 1; } strbuf_reset(&buf); } while (1); http_cleanup(); return 0; }
int main(int argc, char **argv) { int listen_port = 0; struct string_list listen_addr = STRING_LIST_INIT_NODUP; int serve_mode = 0, inetd_mode = 0; const char *pid_file = NULL, *user_name = NULL, *group_name = NULL; int detach = 0; struct credentials *cred = NULL; int i; git_setup_gettext(); git_extract_argv0_path(argv[0]); for (i = 1; i < argc; i++) { char *arg = argv[i]; if (!prefixcmp(arg, "--listen=")) { string_list_append(&listen_addr, xstrdup_tolower(arg + 9)); continue; } if (!prefixcmp(arg, "--port=")) { char *end; unsigned long n; n = strtoul(arg+7, &end, 0); if (arg[7] && !*end) { listen_port = n; continue; } } if (!strcmp(arg, "--serve")) { serve_mode = 1; continue; } if (!strcmp(arg, "--inetd")) { inetd_mode = 1; log_syslog = 1; continue; } if (!strcmp(arg, "--verbose")) { verbose = 1; continue; } if (!strcmp(arg, "--syslog")) { log_syslog = 1; continue; } if (!strcmp(arg, "--export-all")) { export_all_trees = 1; continue; } if (!prefixcmp(arg, "--access-hook=")) { access_hook = arg + 14; continue; } if (!prefixcmp(arg, "--timeout=")) { timeout = atoi(arg+10); continue; } if (!prefixcmp(arg, "--init-timeout=")) { init_timeout = atoi(arg+15); continue; } if (!prefixcmp(arg, "--max-connections=")) { max_connections = atoi(arg+18); if (max_connections < 0) max_connections = 0; /* unlimited */ continue; } if (!strcmp(arg, "--strict-paths")) { strict_paths = 1; continue; } if (!prefixcmp(arg, "--base-path=")) { base_path = arg+12; continue; } if (!strcmp(arg, "--base-path-relaxed")) { base_path_relaxed = 1; continue; } if (!prefixcmp(arg, "--interpolated-path=")) { interpolated_path = arg+20; continue; } if (!strcmp(arg, "--reuseaddr")) { reuseaddr = 1; continue; } if (!strcmp(arg, "--user-path")) { user_path = ""; continue; } if (!prefixcmp(arg, "--user-path=")) { user_path = arg + 12; continue; } if (!prefixcmp(arg, "--pid-file=")) { pid_file = arg + 11; continue; } if (!strcmp(arg, "--detach")) { detach = 1; log_syslog = 1; continue; } if (!prefixcmp(arg, "--user="******"--group=")) { group_name = arg + 8; continue; } if (!prefixcmp(arg, "--enable=")) { enable_service(arg + 9, 1); continue; } if (!prefixcmp(arg, "--disable=")) { enable_service(arg + 10, 0); continue; } if (!prefixcmp(arg, "--allow-override=")) { make_service_overridable(arg + 17, 1); continue; } if (!prefixcmp(arg, "--forbid-override=")) { make_service_overridable(arg + 18, 0); continue; } if (!prefixcmp(arg, "--informative-errors")) { informative_errors = 1; continue; } if (!prefixcmp(arg, "--no-informative-errors")) { informative_errors = 0; continue; } if (!strcmp(arg, "--")) { ok_paths = &argv[i+1]; break; } else if (arg[0] != '-') { ok_paths = &argv[i]; break; } usage(daemon_usage); } if (log_syslog) { openlog("git-daemon", LOG_PID, LOG_DAEMON); set_die_routine(daemon_die); } else /* avoid splitting a message in the middle */ setvbuf(stderr, NULL, _IOFBF, 4096); if (inetd_mode && (detach || group_name || user_name)) die("--detach, --user and --group are incompatible with --inetd"); if (inetd_mode && (listen_port || (listen_addr.nr > 0))) die("--listen= and --port= are incompatible with --inetd"); else if (listen_port == 0) listen_port = DEFAULT_GIT_PORT; if (group_name && !user_name) die("--group supplied without --user"); if (user_name) cred = prepare_credentials(user_name, group_name); if (strict_paths && (!ok_paths || !*ok_paths)) die("option --strict-paths requires a whitelist"); if (base_path && !is_directory(base_path)) die("base-path '%s' does not exist or is not a directory", base_path); if (inetd_mode) { if (!freopen("/dev/null", "w", stderr)) die_errno("failed to redirect stderr to /dev/null"); } if (inetd_mode || serve_mode) return execute(); if (detach) daemonize(); else sanitize_stdfds(); if (pid_file) store_pid(pid_file); /* prepare argv for serving-processes */ cld_argv = xmalloc(sizeof (char *) * (argc + 2)); cld_argv[0] = argv[0]; /* git-daemon */ cld_argv[1] = "--serve"; for (i = 1; i < argc; ++i) cld_argv[i+1] = argv[i]; cld_argv[argc+1] = NULL; return serve(&listen_addr, listen_port, cred); }
int main(int argc, char **argv) { int listen_port = 0; struct string_list listen_addr = STRING_LIST_INIT_NODUP; int inetd_mode = 0; const char *pid_file = NULL, *user_name = NULL, *group_name = NULL; int detach = 0; struct passwd *pass = NULL; struct group *group; gid_t gid = 0; int i; git_extract_argv0_path(argv[0]); for (i = 1; i < argc; i++) { char *arg = argv[i]; if (!prefixcmp(arg, "--listen=")) { string_list_append(&listen_addr, xstrdup_tolower(arg + 9)); continue; } if (!prefixcmp(arg, "--port=")) { char *end; unsigned long n; n = strtoul(arg+7, &end, 0); if (arg[7] && !*end) { listen_port = n; continue; } } if (!strcmp(arg, "--inetd")) { inetd_mode = 1; log_syslog = 1; continue; } if (!strcmp(arg, "--verbose")) { verbose = 1; continue; } if (!strcmp(arg, "--syslog")) { log_syslog = 1; continue; } if (!strcmp(arg, "--export-all")) { export_all_trees = 1; continue; } if (!prefixcmp(arg, "--timeout=")) { timeout = atoi(arg+10); continue; } if (!prefixcmp(arg, "--init-timeout=")) { init_timeout = atoi(arg+15); continue; } if (!prefixcmp(arg, "--max-connections=")) { max_connections = atoi(arg+18); if (max_connections < 0) max_connections = 0; /* unlimited */ continue; } if (!strcmp(arg, "--strict-paths")) { strict_paths = 1; continue; } if (!prefixcmp(arg, "--base-path=")) { base_path = arg+12; continue; } if (!strcmp(arg, "--base-path-relaxed")) { base_path_relaxed = 1; continue; } if (!prefixcmp(arg, "--interpolated-path=")) { interpolated_path = arg+20; continue; } if (!strcmp(arg, "--reuseaddr")) { reuseaddr = 1; continue; } if (!strcmp(arg, "--user-path")) { user_path = ""; continue; } if (!prefixcmp(arg, "--user-path=")) { user_path = arg + 12; continue; } if (!prefixcmp(arg, "--pid-file=")) { pid_file = arg + 11; continue; } if (!strcmp(arg, "--detach")) { detach = 1; log_syslog = 1; continue; } if (!prefixcmp(arg, "--user="******"--group=")) { group_name = arg + 8; continue; } if (!prefixcmp(arg, "--enable=")) { enable_service(arg + 9, 1); continue; } if (!prefixcmp(arg, "--disable=")) { enable_service(arg + 10, 0); continue; } if (!prefixcmp(arg, "--allow-override=")) { make_service_overridable(arg + 17, 1); continue; } if (!prefixcmp(arg, "--forbid-override=")) { make_service_overridable(arg + 18, 0); continue; } if (!strcmp(arg, "--")) { ok_paths = &argv[i+1]; break; } else if (arg[0] != '-') { ok_paths = &argv[i]; break; } usage(daemon_usage); } if (log_syslog) { openlog("git-daemon", LOG_PID, LOG_DAEMON); set_die_routine(daemon_die); } else /* avoid splitting a message in the middle */ setvbuf(stderr, NULL, _IOLBF, 0); if (inetd_mode && (group_name || user_name)) die("--user and --group are incompatible with --inetd"); if (inetd_mode && (listen_port || (listen_addr.nr > 0))) die("--listen= and --port= are incompatible with --inetd"); else if (listen_port == 0) listen_port = DEFAULT_GIT_PORT; if (group_name && !user_name) die("--group supplied without --user"); if (user_name) { pass = getpwnam(user_name); if (!pass) die("user not found - %s", user_name); if (!group_name) gid = pass->pw_gid; else { group = getgrnam(group_name); if (!group) die("group not found - %s", group_name); gid = group->gr_gid; } } if (strict_paths && (!ok_paths || !*ok_paths)) die("option --strict-paths requires a whitelist"); if (base_path && !is_directory(base_path)) die("base-path '%s' does not exist or is not a directory", base_path); if (inetd_mode) { struct sockaddr_storage ss; struct sockaddr *peer = (struct sockaddr *)&ss; socklen_t slen = sizeof(ss); if (!freopen("/dev/null", "w", stderr)) die_errno("failed to redirect stderr to /dev/null"); if (getpeername(0, peer, &slen)) peer = NULL; return execute(peer); } if (detach) { daemonize(); loginfo("Ready to rumble"); } else sanitize_stdfds(); if (pid_file) store_pid(pid_file); return serve(&listen_addr, listen_port, pass, gid); }
int main(int argc, const char **argv) { struct strbuf buf = STRBUF_INIT; int nongit; git_setup_gettext(); git_extract_argv0_path(argv[0]); setup_git_directory_gently(&nongit); if (argc < 2) { error("remote-curl: usage: git remote-curl <remote> [<url>]"); return 1; } options.verbosity = 1; options.progress = !!isatty(2); options.thin = 1; remote = remote_get(argv[1]); if (argc > 2) { end_url_with_slash(&url, argv[2]); } else { end_url_with_slash(&url, remote->url[0]); } http_init(remote, url.buf, 0); do { const char *arg; if (strbuf_getline_lf(&buf, stdin) == EOF) { if (ferror(stdin)) error("remote-curl: error reading command stream from git"); return 1; } if (buf.len == 0) break; if (starts_with(buf.buf, "fetch ")) { if (nongit) die("remote-curl: fetch attempted without a local repo"); parse_fetch(&buf); } else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) { int for_push = !!strstr(buf.buf + 4, "for-push"); output_refs(get_refs(for_push)); } else if (starts_with(buf.buf, "push ")) { parse_push(&buf); } else if (skip_prefix(buf.buf, "option ", &arg)) { char *value = strchr(arg, ' '); int result; if (value) *value++ = '\0'; else value = "true"; result = set_option(arg, value); if (!result) printf("ok\n"); else if (result < 0) printf("error invalid value\n"); else printf("unsupported\n"); fflush(stdout); } else if (!strcmp(buf.buf, "capabilities")) { printf("fetch\n"); printf("option\n"); printf("push\n"); printf("check-connectivity\n"); printf("\n"); fflush(stdout); } else { error("remote-curl: unknown command '%s' from git", buf.buf); return 1; } strbuf_reset(&buf); } while (1); http_cleanup(); return 0; }
int main(int argc, const char **argv) { const char *cmd; startup_info = &git_startup_info; cmd = git_extract_argv0_path(argv[0]); if (!cmd) cmd = "git-help"; /* * "git-xxxx" is the same as "git xxxx", but we obviously: * * - cannot take flags in between the "git" and the "xxxx". * - cannot execute it externally (since it would just do * the same thing over again) * * So we just directly call the internal command handler, and * die if that one cannot handle it. */ if (!prefixcmp(cmd, "git-")) { cmd += 4; argv[0] = cmd; handle_internal_command(argc, argv); die("cannot handle %s internally", cmd); } /* Look for flags.. */ argv++; argc--; handle_options(&argv, &argc, NULL); if (argc > 0) { if (!prefixcmp(argv[0], "--")) argv[0] += 2; } else { /* The user didn't specify a command; give them help */ commit_pager_choice(); printf("usage: %s\n\n", git_usage_string); list_common_cmds_help(); printf("\n%s\n", git_more_info_string); exit(1); } cmd = argv[0]; /* * We use PATH to find git commands, but we prepend some higher * precedence paths: the "--exec-path" option, the GIT_EXEC_PATH * environment, and the $(gitexecdir) from the Makefile at build * time. */ setup_path(); while (1) { static int done_help = 0; static int was_alias = 0; was_alias = run_argv(&argc, &argv); if (errno != ENOENT) break; if (was_alias) { fprintf(stderr, "Expansion of alias '%s' failed; " "'%s' is not a git command\n", cmd, argv[0]); exit(1); } if (!done_help) { cmd = argv[0] = help_unknown_cmd(cmd); done_help = 1; } else break; } fprintf(stderr, "Failed to run command '%s': %s\n", cmd, strerror(errno)); return 1; }
int main(int argc, char **argv) { char *prog; const char **user_argv; struct commands *cmd; int devnull_fd; int count; git_setup_gettext(); git_extract_argv0_path(argv[0]); /* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids not messing up when the pipes are * dup'ed onto stdin/stdout/stderr in the child processes we spawn. */ devnull_fd = open("/dev/null", O_RDWR); while (devnull_fd >= 0 && devnull_fd <= 2) devnull_fd = dup(devnull_fd); if (devnull_fd == -1) die_errno("opening /dev/null failed"); close (devnull_fd); /* * Special hack to pretend to be a CVS server */ if (argc == 2 && !strcmp(argv[1], "cvs server")) { argv--; } else if (argc == 1) { /* Allow the user to run an interactive shell */ cd_to_homedir(); if (access(COMMAND_DIR, R_OK | X_OK) == -1) { die("Interactive git shell is not enabled.\n" "hint: ~/" COMMAND_DIR " should exist " "and have read and execute access."); } run_shell(); exit(0); } else if (argc != 3 || strcmp(argv[1], "-c")) { /* * We do not accept any other modes except "-c" followed by * "cmd arg", where "cmd" is a very limited subset of git * commands or a command in the COMMAND_DIR */ die("Run with no arguments or with -c cmd"); } prog = xstrdup(argv[2]); if (!strncmp(prog, "git", 3) && isspace(prog[3])) /* Accept "git foo" as if the caller said "git-foo". */ prog[3] = '-'; for (cmd = cmd_list ; cmd->name ; cmd++) { int len = strlen(cmd->name); char *arg; if (strncmp(cmd->name, prog, len)) continue; arg = NULL; switch (prog[len]) { case '\0': arg = NULL; break; case ' ': arg = prog + len + 1; break; default: continue; } exit(cmd->exec(cmd->name, arg)); } cd_to_homedir(); count = split_cmdline(prog, &user_argv); if (count >= 0) { if (is_valid_cmd_name(user_argv[0])) { prog = make_cmd(user_argv[0]); user_argv[0] = prog; execv(user_argv[0], (char *const *) user_argv); } free(prog); free(user_argv); die("unrecognized command '%s'", argv[2]); } else { free(prog); die("invalid command format '%s': %s", argv[2], split_cmdline_strerror(count)); } }
int main(int argc, char **av) { const char **argv = (const char **) av; const char *cmd; startup_info = &git_startup_info; cmd = git_extract_argv0_path(argv[0]); if (!cmd) cmd = "git-help"; /* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids messing up when the pipes are dup'ed * onto stdin/stdout/stderr in the child processes we spawn. */ sanitize_stdfds(); git_setup_gettext(); /* * "git-xxxx" is the same as "git xxxx", but we obviously: * * - cannot take flags in between the "git" and the "xxxx". * - cannot execute it externally (since it would just do * the same thing over again) * * So we just directly call the builtin handler, and die if * that one cannot handle it. */ if (starts_with(cmd, "git-")) { cmd += 4; argv[0] = cmd; handle_builtin(argc, argv); die("cannot handle %s as a builtin", cmd); } /* Look for flags.. */ argv++; argc--; handle_options(&argv, &argc, NULL); if (argc > 0) { if (starts_with(argv[0], "--")) argv[0] += 2; } else { /* The user didn't specify a command; give them help */ commit_pager_choice(); printf("usage: %s\n\n", git_usage_string); list_common_cmds_help(); printf("\n%s\n", _(git_more_info_string)); exit(1); } cmd = argv[0]; /* * We use PATH to find git commands, but we prepend some higher * precedence paths: the "--exec-path" option, the GIT_EXEC_PATH * environment, and the $(gitexecdir) from the Makefile at build * time. */ setup_path(); while (1) { static int done_help = 0; static int was_alias = 0; was_alias = run_argv(&argc, &argv); if (errno != ENOENT) break; if (was_alias) { fprintf(stderr, "Expansion of alias '%s' failed; " "'%s' is not a git command\n", cmd, argv[0]); exit(1); } if (!done_help) { cmd = argv[0] = help_unknown_cmd(cmd); done_help = 1; } else break; } fprintf(stderr, "Failed to run command '%s': %s\n", cmd, strerror(errno)); return 1; }
int main(int argc, const char **argv) { const char *prefix; struct walker *walker; int commits_on_stdin = 0; int commits; const char **write_ref = NULL; char **commit_id; const char *url; char *rewritten_url = NULL; int arg = 1; int rc = 0; int get_tree = 0; int get_history = 0; int get_all = 0; int get_verbosely = 0; int get_recover = 0; git_extract_argv0_path(argv[0]); while (arg < argc && argv[arg][0] == '-') { if (argv[arg][1] == 't') { get_tree = 1; } else if (argv[arg][1] == 'c') { get_history = 1; } else if (argv[arg][1] == 'a') { get_all = 1; get_tree = 1; get_history = 1; } else if (argv[arg][1] == 'v') { get_verbosely = 1; } else if (argv[arg][1] == 'w') { write_ref = &argv[arg + 1]; arg++; } else if (argv[arg][1] == 'h') { usage(http_fetch_usage); } else if (!strcmp(argv[arg], "--recover")) { get_recover = 1; } else if (!strcmp(argv[arg], "--stdin")) { commits_on_stdin = 1; } arg++; } if (argc != arg + 2 - commits_on_stdin) usage(http_fetch_usage); if (commits_on_stdin) { commits = walker_targets_stdin(&commit_id, &write_ref); } else { commit_id = (char **) &argv[arg++]; commits = 1; } url = argv[arg]; prefix = setup_git_directory(); git_config(git_default_config, NULL); if (url && url[strlen(url)-1] != '/') { rewritten_url = xmalloc(strlen(url)+2); strcpy(rewritten_url, url); strcat(rewritten_url, "/"); url = rewritten_url; } walker = get_http_walker(url, NULL); walker->get_tree = get_tree; walker->get_history = get_history; walker->get_all = get_all; walker->get_verbosely = get_verbosely; walker->get_recover = get_recover; rc = walker_fetch(walker, commits, commit_id, write_ref, url); if (commits_on_stdin) walker_targets_free(commits, commit_id, write_ref); if (walker->corrupt_object_found) { fprintf(stderr, "Some loose object were found to be corrupt, but they might be just\n" "a false '404 Not Found' error message sent with incorrect HTTP\n" "status code. Suggest running 'git fsck'.\n"); } walker_free(walker); free(rewritten_url); return rc; }
int main(int argc, const char **argv) { struct walker *walker; int commits_on_stdin = 0; int commits; const char **write_ref = NULL; char **commit_id; char *url = NULL; int arg = 1; int rc = 0; int get_tree = 0; int get_history = 0; int get_all = 0; int get_verbosely = 0; int get_recover = 0; git_extract_argv0_path(argv[0]); while (arg < argc && argv[arg][0] == '-') { if (argv[arg][1] == 't') { get_tree = 1; } else if (argv[arg][1] == 'c') { get_history = 1; } else if (argv[arg][1] == 'a') { get_all = 1; get_tree = 1; get_history = 1; } else if (argv[arg][1] == 'v') { get_verbosely = 1; } else if (argv[arg][1] == 'w') { write_ref = &argv[arg + 1]; arg++; } else if (argv[arg][1] == 'h') { usage(http_fetch_usage); } else if (!strcmp(argv[arg], "--recover")) { get_recover = 1; } else if (!strcmp(argv[arg], "--stdin")) { commits_on_stdin = 1; } arg++; } if (argc != arg + 2 - commits_on_stdin) usage(http_fetch_usage); if (commits_on_stdin) { commits = walker_targets_stdin(&commit_id, &write_ref); } else { commit_id = (char **) &argv[arg++]; commits = 1; } if (get_all == 0) warning("http-fetch: use without -a is deprecated.\n" "In a future release, -a will become the default."); if (argv[arg]) str_end_url_with_slash(argv[arg], &url); setup_git_directory(); git_config(git_default_config, NULL); http_init(NULL, url); walker = get_http_walker(url); walker->get_tree = get_tree; walker->get_history = get_history; walker->get_all = get_all; walker->get_verbosely = get_verbosely; walker->get_recover = get_recover; rc = walker_fetch(walker, commits, commit_id, write_ref, url); if (commits_on_stdin) walker_targets_free(commits, commit_id, write_ref); if (walker->corrupt_object_found) { fprintf(stderr, "Some loose object were found to be corrupt, but they might be just\n" "a false '404 Not Found' error message sent with incorrect HTTP\n" "status code. Suggest running 'git fsck'.\n"); } walker_free(walker); http_cleanup(); free(url); return rc; }
int main(int argc, char **argv) { char *method = getenv("REQUEST_METHOD"); char *dir; struct service_cmd *cmd = NULL; char *cmd_arg = NULL; int i; git_setup_gettext(); git_extract_argv0_path(argv[0]); set_die_routine(die_webcgi); if (!method) die("No REQUEST_METHOD from server"); if (!strcmp(method, "HEAD")) method = "GET"; dir = getdir(); for (i = 0; i < ARRAY_SIZE(services); i++) { struct service_cmd *c = &services[i]; regex_t re; regmatch_t out[1]; if (regcomp(&re, c->pattern, REG_EXTENDED)) die("Bogus regex in service table: %s", c->pattern); if (!regexec(&re, dir, 1, out, 0)) { size_t n; if (strcmp(method, c->method)) { const char *proto = getenv("SERVER_PROTOCOL"); if (proto && !strcmp(proto, "HTTP/1.1")) { http_status(405, "Method Not Allowed"); hdr_str("Allow", !strcmp(c->method, "GET") ? "GET, HEAD" : c->method); } else http_status(400, "Bad Request"); hdr_nocache(); end_headers(); return 0; } cmd = c; n = out[0].rm_eo - out[0].rm_so; cmd_arg = xmemdupz(dir + out[0].rm_so + 1, n - 1); dir[out[0].rm_so] = 0; break; } regfree(&re); } if (!cmd) not_found("Request not supported: '%s'", dir); setup_path(); if (!enter_repo(dir, 0)) not_found("Not a git repository: '%s'", dir); if (!getenv("GIT_HTTP_EXPORT_ALL") && access("git-daemon-export-ok", F_OK) ) not_found("Repository not exported: '%s'", dir); git_config(http_config, NULL); cmd->imp(cmd_arg); return 0; }
int main(int argc, const char **argv) { int i; const char *prefix = NULL; int prefix_length = -1; const char *errstr = NULL; type = blob_type; git_extract_argv0_path(argv[0]); git_config(git_default_config, NULL); argc = parse_options(argc, argv, hash_object_options, hash_object_usage, 0); if (write_object) { prefix = setup_git_directory(); prefix_length = prefix ? strlen(prefix) : 0; if (vpath && prefix) vpath = prefix_filename(prefix, prefix_length, vpath); } if (stdin_paths) { if (hashstdin) errstr = "Can't use --stdin-paths with --stdin"; else if (argc) errstr = "Can't specify files with --stdin-paths"; else if (vpath) errstr = "Can't use --stdin-paths with --path"; else if (no_filters) errstr = "Can't use --stdin-paths with --no-filters"; } else { if (hashstdin > 1) errstr = "Multiple --stdin arguments are not supported"; if (vpath && no_filters) errstr = "Can't use --path with --no-filters"; } if (errstr) { error("%s", errstr); usage_with_options(hash_object_usage, hash_object_options); } if (hashstdin) hash_fd(0, type, write_object, vpath); for (i = 0 ; i < argc; i++) { const char *arg = argv[i]; if (0 <= prefix_length) arg = prefix_filename(prefix, prefix_length, arg); hash_object(arg, type, write_object, no_filters ? NULL : vpath ? vpath : arg); } if (stdin_paths) hash_stdin_paths(type, write_object); return 0; }