summaryrefslogtreecommitdiffstats
path: root/send-pack.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-01-17 12:21:14 -0800
committerJunio C Hamano <gitster@pobox.com>2014-01-17 12:21:20 -0800
commit92251b1b5b5e53ac9de890105e2a2bd9d15e2ecb (patch)
treeed77d1e0ceaf2142ce14583a1b60c4af204571a0 /send-pack.c
parentd8cf714c0edf261a2bcc126fc240b10ed04a5b8d (diff)
parent3b32a7ca90b9c63f2306feb2a66b62b94c1a640f (diff)
downloadgit-92251b1b5b5e53ac9de890105e2a2bd9d15e2ecb.tar.gz
git-92251b1b5b5e53ac9de890105e2a2bd9d15e2ecb.tar.xz
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 ...
Diffstat (limited to 'send-pack.c')
-rw-r--r--send-pack.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/send-pack.c b/send-pack.c
index ac14a4d09..6129b0fd8 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -10,6 +10,7 @@
#include "quote.h"
#include "transport.h"
#include "version.h"
+#include "sha1-array.h"
static int feed_object(const unsigned char *sha1, int fd, int negative)
{
@@ -28,7 +29,7 @@ static int feed_object(const unsigned char *sha1, int fd, int negative)
/*
* Make a pack stream and spit it out into file descriptor fd
*/
-static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *extra, struct send_pack_args *args)
+static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, struct send_pack_args *args)
{
/*
* The child becomes pack-objects --revs; we feed
@@ -71,7 +72,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
* parameters by writing to the pipe.
*/
for (i = 0; i < extra->nr; i++)
- if (!feed_object(extra->array[i], po.in, 1))
+ if (!feed_object(extra->sha1[i], po.in, 1))
break;
while (refs) {
@@ -174,10 +175,25 @@ static int sideband_demux(int in, int out, void *data)
return ret;
}
+static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *cb)
+{
+ struct strbuf *sb = cb;
+ if (graft->nr_parent == -1)
+ packet_buf_write(sb, "shallow %s\n", sha1_to_hex(graft->sha1));
+ return 0;
+}
+
+static void advertise_shallow_grafts_buf(struct strbuf *sb)
+{
+ if (!is_repository_shallow())
+ return;
+ for_each_commit_graft(advertise_shallow_grafts_cb, sb);
+}
+
int send_pack(struct send_pack_args *args,
int fd[], struct child_process *conn,
struct ref *remote_refs,
- struct extra_have_objects *extra_have)
+ struct sha1_array *extra_have)
{
int in = fd[0];
int out = fd[1];
@@ -215,6 +231,9 @@ int send_pack(struct send_pack_args *args,
return 0;
}
+ if (!args->dry_run)
+ advertise_shallow_grafts_buf(&req_buf);
+
/*
* Finally, tell the other end!
*/
@@ -274,7 +293,7 @@ int send_pack(struct send_pack_args *args,
}
if (args->stateless_rpc) {
- if (!args->dry_run && cmds_sent) {
+ if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
packet_buf_flush(&req_buf);
send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
}