From: Junio C Hamano Date: Fri, 17 Jan 2014 20:21:14 +0000 (-0800) Subject: Merge branch 'nd/shallow-clone' X-Git-Tag: v1.9-rc0~3 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/92251b1b5b5e53ac9de890105e2a2bd9d15e2ecb Merge branch 'nd/shallow-clone' Fetching from a shallow-cloned repository used to be forbidden, primarily because the codepaths involved were not carefully vetted and we did not bother supporting such usage. This attempts to allow object transfer out of a shallow-cloned repository in a controlled way (i.e. the receiver become a shallow repository with truncated history). * nd/shallow-clone: (31 commits) t5537: fix incorrect expectation in test case 10 shallow: remove unused code send-pack.c: mark a file-local function static git-clone.txt: remove shallow clone limitations prune: clean .git/shallow after pruning objects clone: use git protocol for cloning shallow repo locally send-pack: support pushing from a shallow clone via http receive-pack: support pushing to a shallow clone via http smart-http: support shallow fetch/clone remote-curl: pass ref SHA-1 to fetch-pack as well send-pack: support pushing to a shallow clone receive-pack: allow pushes that update .git/shallow connected.c: add new variant that runs with --shallow-file add GIT_SHALLOW_FILE to propagate --shallow-file to subprocesses receive/send-pack: support pushing from a shallow clone receive-pack: reorder some code in unpack() fetch: add --update-shallow to accept refs that update .git/shallow upload-pack: make sure deepening preserves shallow roots fetch: support fetching from a shallow repository clone: support remote shallow repository ... --- 92251b1b5b5e53ac9de890105e2a2bd9d15e2ecb diff --cc builtin/fetch-pack.c index 8b8978a252,81fae380e8..1262b405f8 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@@ -150,18 -163,14 +167,18 @@@ int cmd_fetch_pack(int argc, const cha fd[0] = 0; fd[1] = 1; } else { + int flags = args.verbose ? CONNECT_VERBOSE : 0; + if (args.diag_url) + flags |= CONNECT_DIAG_URL; conn = git_connect(fd, dest, args.uploadpack, - args.verbose ? CONNECT_VERBOSE : 0); + flags); + if (!conn) + return args.diag_url ? 0 : 1; } - get_remote_heads(fd[0], NULL, 0, &ref, 0, NULL); - + get_remote_heads(fd[0], NULL, 0, &ref, 0, NULL, &shallow); - ref = fetch_pack(&args, fd, conn, ref, dest, - sought, nr_sought, pack_lockfile_ptr); + ref = fetch_pack(&args, fd, conn, ref, dest, sought, nr_sought, + &shallow, pack_lockfile_ptr); if (pack_lockfile) { printf("lock %s\n", pack_lockfile); fflush(stdout); diff --cc builtin/receive-pack.c index e09994f4df,bc4f5dc463..85bba356fa --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@@ -766,6 -852,14 +852,14 @@@ static struct command *read_head_info(s line = packet_read_line(0, &len); if (!line) break; + - if (len == 48 && !prefixcmp(line, "shallow ")) { ++ if (len == 48 && starts_with(line, "shallow ")) { + if (get_sha1_hex(line + 8, old_sha1)) + die("protocol error: expected shallow sha, got '%s'", line + 8); + sha1_array_append(shallow, old_sha1); + continue; + } + if (len < 83 || line[40] != ' ' || line[81] != ' ' || diff --cc connect.c index c763eeda86,efadd3cbeb..4150412e2c --- a/connect.c +++ b/connect.c @@@ -145,9 -140,18 +140,18 @@@ struct ref **get_remote_heads(int in, c if (!len) break; - if (len > 4 && !prefixcmp(buffer, "ERR ")) + if (len > 4 && starts_with(buffer, "ERR ")) die("remote error: %s", buffer + 4); - if (len == 48 && !prefixcmp(buffer, "shallow ")) { ++ if (len == 48 && starts_with(buffer, "shallow ")) { + if (get_sha1_hex(buffer + 8, old_sha1)) + die("protocol error: expected shallow sha-1, got '%s'", buffer + 8); + if (!shallow_points) + die("repository on the other end cannot be shallow"); + sha1_array_append(shallow_points, old_sha1); + continue; + } + if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ') die("protocol error: expected sha/ref, got '%s'", buffer); name = buffer + 41; diff --cc fetch-pack.h index 20ccc12e57,ada02f51c1..bb7fd76e59 --- a/fetch-pack.h +++ b/fetch-pack.h @@@ -8,19 -10,20 +10,21 @@@ struct fetch_pack_args const char *uploadpack; int unpacklimit; int depth; - unsigned quiet:1, - keep_pack:1, - lock_pack:1, - use_thin_pack:1, - fetch_all:1, - stdin_refs:1, - diag_url:1, - verbose:1, - no_progress:1, - include_tag:1, - stateless_rpc:1, - check_self_contained_and_connected:1, - self_contained_and_connected:1; + unsigned quiet:1; + unsigned keep_pack:1; + unsigned lock_pack:1; + unsigned use_thin_pack:1; + unsigned fetch_all:1; + unsigned stdin_refs:1; ++ unsigned diag_url:1; + unsigned verbose:1; + unsigned no_progress:1; + unsigned include_tag:1; + unsigned stateless_rpc:1; + unsigned check_self_contained_and_connected:1; + unsigned self_contained_and_connected:1; + unsigned cloning:1; + unsigned update_shallow:1; }; /* diff --cc shallow.c index 961cf6f024,e483780d49..bbc98b55c0 --- a/shallow.c +++ b/shallow.c @@@ -90,9 -99,13 +99,12 @@@ struct commit_list *get_shallow_commits cur_depth = *(int *)commit->util; } } - if (parse_commit(commit)) - die("invalid commit"); + parse_commit_or_die(commit); cur_depth++; - if (cur_depth >= depth) { + if ((depth != INFINITE_DEPTH && cur_depth >= depth) || + (is_repository_shallow() && !commit->parents && + (graft = lookup_commit_graft(commit->object.sha1)) != NULL && + graft->nr_parent < 0)) { commit_list_insert(commit, &result); commit->object.flags |= shallow_flag; commit = NULL;