X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=clone-pack.c;h=960921903eaa712523af0b03098970127729f363;hb=2c4ed386e8861e730037abe4f4d9e032c5c46242;hp=9567900aab1ce477a2c748cf1ce3d47c169b9c78;hpb=11dcec07a4815b7a37e009df1e8007d7ec08becf;p=git.git diff --git a/clone-pack.c b/clone-pack.c index 9567900a..96092190 100644 --- a/clone-pack.c +++ b/clone-pack.c @@ -3,9 +3,8 @@ #include "pkt-line.h" #include -static int quiet; -static int keep_pack; -static const char clone_pack_usage[] = "git-clone-pack [-q] [--exec=] [:] []*"; +static const char clone_pack_usage[] = +"git-clone-pack [--exec=] [:] []*"; static const char *exec = "git-upload-pack"; static void clone_handshake(int fd[2], struct ref *ref) @@ -35,6 +34,12 @@ static void write_one_ref(struct ref *ref) int fd; char *hex; + if (!strncmp(ref->name, "refs/", 5) && + check_ref_format(ref->name + 5)) { + error("refusing to create funny ref '%s' locally", ref->name); + return; + } + if (safe_create_leading_directories(path)) die("unable to create leading directory for %s", ref->name); fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0666); @@ -107,41 +112,6 @@ static void write_refs(struct ref *ref) free(head_path); } -static int clone_by_unpack(int fd[2]) -{ - int status; - pid_t pid; - - pid = fork(); - if (pid < 0) - die("git-clone-pack: unable to fork off git-unpack-objects"); - if (!pid) { - dup2(fd[0], 0); - close(fd[0]); - close(fd[1]); - execlp("git-unpack-objects", "git-unpack-objects", - quiet ? "-q" : NULL, NULL); - die("git-unpack-objects exec failed"); - } - close(fd[0]); - close(fd[1]); - while (waitpid(pid, &status, 0) < 0) { - if (errno != EINTR) - die("waiting for git-unpack-objects: %s", strerror(errno)); - } - if (WIFEXITED(status)) { - int code = WEXITSTATUS(status); - if (code) - die("git-unpack-objects died with error code %d", code); - return 0; - } - if (WIFSIGNALED(status)) { - int sig = WTERMSIG(status); - die("git-unpack-objects died of signal %d", sig); - } - die("Sherlock Holmes! git-unpack-objects died of unnatural causes %d!", status); -} - static int finish_pack(const char *pack_tmp_name) { int pipe_fd[2]; @@ -221,9 +191,11 @@ static int finish_pack(const char *pack_tmp_name) snprintf(final, sizeof(final), "%s/pack/pack-%s.pack", get_object_directory(), hash); move_temp_to_file(pack_tmp_name, final); + chmod(final, 0444); snprintf(final, sizeof(final), "%s/pack/pack-%s.idx", get_object_directory(), hash); move_temp_to_file(idx, final); + chmod(final, 0444); return 0; error_die: @@ -239,7 +211,7 @@ static int clone_without_unpack(int fd[2]) ifd = fd[0]; snprintf(tmpfile, sizeof(tmpfile), - "%s/pack-XXXXXX", get_object_directory()); + "%s/pack/tmp-XXXXXX", get_object_directory()); ofd = mkstemp(tmpfile); if (ofd < 0) return error("unable to create temporary file %s", tmpfile); @@ -278,42 +250,20 @@ static int clone_pack(int fd[2], int nr_match, char **match) struct ref *refs; int status; - get_remote_heads(fd[0], &refs, nr_match, match); + get_remote_heads(fd[0], &refs, nr_match, match, 1); if (!refs) { packet_flush(fd[1]); die("no matching remote head"); } clone_handshake(fd, refs); - if (keep_pack) - status = clone_without_unpack(fd); - else - status = clone_by_unpack(fd); + status = clone_without_unpack(fd); if (!status) write_refs(refs); return status; } -static int clone_options(const char *var, const char *value) -{ - if (!strcmp("clone.keeppack", var)) { - keep_pack = git_config_bool(var, value); - return 0; - } - if (!strcmp("clone.quiet", var)) { - quiet = git_config_bool(var, value); - return 0; - } - /* - * Put other local option parsing for this program - * here ... - */ - - /* Fall back on the default ones */ - return git_default_config(var, value); -} - int main(int argc, char **argv) { int i, ret, nr_heads; @@ -321,25 +271,20 @@ int main(int argc, char **argv) int fd[2]; pid_t pid; - git_config(clone_options); nr_heads = 0; heads = NULL; for (i = 1; i < argc; i++) { char *arg = argv[i]; if (*arg == '-') { - if (!strcmp("-q", arg)) { - quiet = 1; + if (!strcmp("-q", arg)) continue; - } if (!strncmp("--exec=", arg, 7)) { exec = arg + 7; continue; } - if (!strcmp("--keep", arg)) { - keep_pack = 1; + if (!strcmp("--keep", arg)) continue; - } usage(clone_pack_usage); } dest = arg;