send-pack: support pushing from a shallow clone via http

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Dec 5, 2013 at 20:02 UTC f2c681cf12c54ce3859b36693f8a13c36126577b
3 files changed +42 -5
builtin/send-pack.c
-3
@@ -209,9 +209,6 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
209 (send_all && args.send_mirror))
210 usage(send_pack_usage);
211
212 - if (is_repository_shallow() && args.stateless_rpc)
213 - die("attempt to push from a shallow repository");
214 -
212 if (remote_name) {
213 remote = remote_get(remote_name);
214 if (!remote_has_url(remote, dest)) {
send-pack.c
+17 -2
@@ -175,6 +175,21 @@ static int sideband_demux(int in, int out, void *data)
175 return ret;
176 }
177
178 +static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *cb)
179 +{
180 + struct strbuf *sb = cb;
181 + if (graft->nr_parent == -1)
182 + packet_buf_write(sb, "shallow %s\n", sha1_to_hex(graft->sha1));
183 + return 0;
184 +}
185 +
186 +void advertise_shallow_grafts_buf(struct strbuf *sb)
187 +{
188 + if (!is_repository_shallow())
189 + return;
190 + for_each_commit_graft(advertise_shallow_grafts_cb, sb);
191 +}
192 +
193 int send_pack(struct send_pack_args *args,
194 int fd[], struct child_process *conn,
195 struct ref *remote_refs,
@@ -215,7 +230,7 @@ int send_pack(struct send_pack_args *args,
230 }
231
232 if (!args->dry_run)
218 - advertise_shallow_grafts(out);
233 + advertise_shallow_grafts_buf(&req_buf);
234
235 /*
236 * Finally, tell the other end!
@@ -276,7 +291,7 @@ int send_pack(struct send_pack_args *args,
291 }
292
293 if (args->stateless_rpc) {
279 - if (!args->dry_run && cmds_sent) {
294 + if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
295 packet_buf_flush(&req_buf);
296 send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
297 }
t/t5538-push-shallow.sh
+25
@@ -154,5 +154,30 @@ EOF
154 )
155 '
156
157 +test_expect_success 'push from shallow repo via http' '
158 + mv "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" shallow-upstream.git &&
159 + git clone --bare --no-local full "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
160 + (
161 + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
162 + git config http.receivepack true
163 + ) &&
164 + commit 10 &&
165 + git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master &&
166 + (
167 + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
168 + git fsck &&
169 + git log --format=%s top/master >actual &&
170 + cat <<EOF >expect &&
171 +10
172 +1
173 +4
174 +3
175 +2
176 +1
177 +EOF
178 + test_cmp expect actual
179 + )
180 +'
181 +
182 stop_httpd
183 test_done