diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2013-04-29 01:49:40 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2013-04-29 01:49:40 +0200 |
commit | 51e4da6d8aa4a3a961d49197b004dbf7ccee8612 (patch) | |
tree | 6d9c5337d47e20d83aa5cf9ffc1c084340da35b4 | |
parent | 78bf2944ed0512f38dfcb56f590373a904ca29c0 (diff) | |
download | libgit2-51e4da6d8aa4a3a961d49197b004dbf7ccee8612.tar.gz |
push: don't send a packfile when only issuing delete commands
For update and create commands where all the objects are known to
exist in the remote, we must send an empty packfile. However, if all
we issue are delete commands, no packfile must be sent.
Take this into consideration for push.
-rw-r--r-- | src/transports/smart_protocol.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c index 90851980c..a5ad1e422 100644 --- a/src/transports/smart_protocol.c +++ b/src/transports/smart_protocol.c @@ -807,13 +807,13 @@ int git_smart__push(git_transport *transport, git_push *push) transport_smart *t = (transport_smart *)transport; git_smart_subtransport_stream *s; git_buf pktline = GIT_BUF_INIT; - int error = -1; + int error = -1, need_pack = 0; + push_spec *spec; + unsigned int i; #ifdef PUSH_DEBUG { git_remote_head *head; - push_spec *spec; - unsigned int i; char hex[41]; hex[40] = '\0'; git_vector_foreach(&push->remote->refs, i, head) { @@ -831,10 +831,23 @@ int git_smart__push(git_transport *transport, git_push *push) } #endif + /* + * Figure out if we need to send a packfile; which is in all + * cases except when we only send delete commands + */ + git_vector_foreach(&push->specs, i, spec) { + if (spec->lref) { + need_pack = 1; + break; + } + } + if (git_smart__get_push_stream(t, &s) < 0 || gen_pktline(&pktline, push) < 0 || - s->write(s, git_buf_cstr(&pktline), git_buf_len(&pktline)) < 0 || - git_packbuilder_foreach(push->pb, &stream_thunk, s) < 0) + s->write(s, git_buf_cstr(&pktline), git_buf_len(&pktline)) < 0) + goto on_error; + + if (need_pack && git_packbuilder_foreach(push->pb, &stream_thunk, s) < 0) goto on_error; /* If we sent nothing or the server doesn't support report-status, then |