summaryrefslogtreecommitdiff
path: root/http-push.c
diff options
context:
space:
mode:
Diffstat (limited to 'http-push.c')
-rw-r--r--http-push.c61
1 files changed, 42 insertions, 19 deletions
diff --git a/http-push.c b/http-push.c
index a704f490fd..4d24e6b8d4 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
@@ -6,10 +8,8 @@
#include "tag.h"
#include "blob.h"
#include "http.h"
-#include "refs.h"
#include "diff.h"
#include "revision.h"
-#include "exec-cmd.h"
#include "remote.h"
#include "list-objects.h"
#include "setup.h"
@@ -17,6 +17,7 @@
#include "strvec.h"
#include "tree.h"
#include "tree-walk.h"
+#include "url.h"
#include "packfile.h"
#include "object-store-ll.h"
#include "commit-reach.h"
@@ -274,7 +275,7 @@ static void start_fetch_loose(struct transfer_request *request)
if (!start_active_slot(slot)) {
fprintf(stderr, "Unable to start GET request\n");
repo->can_update_info_refs = 0;
- release_http_object_request(obj_req);
+ release_http_object_request(&obj_req);
release_request(request);
}
}
@@ -308,7 +309,7 @@ static void start_fetch_packed(struct transfer_request *request)
struct transfer_request *check_request = request_queue_head;
struct http_pack_request *preq;
- target = find_sha1_pack(request->obj->oid.hash, repo->packs);
+ target = find_oid_pack(&request->obj->oid, repo->packs);
if (!target) {
fprintf(stderr, "Unable to fetch %s, will not be able to update server info refs\n", oid_to_hex(&request->obj->oid));
repo->can_update_info_refs = 0;
@@ -374,7 +375,7 @@ static void start_put(struct transfer_request *request)
/* Set it up */
git_deflate_init(&stream, zlib_compression_level);
size = git_deflate_bound(&stream, len + hdrlen);
- strbuf_init(&request->buffer.buf, size);
+ strbuf_grow(&request->buffer.buf, size);
request->buffer.posn = 0;
/* Compress it */
@@ -436,9 +437,11 @@ static void start_move(struct transfer_request *request)
if (start_active_slot(slot)) {
request->slot = slot;
request->state = RUN_MOVE;
+ request->headers = dav_headers;
} else {
request->state = ABORTED;
FREE_AND_NULL(request->url);
+ curl_slist_free_all(dav_headers);
}
}
@@ -511,6 +514,8 @@ static void release_request(struct transfer_request *request)
}
free(request->url);
+ free(request->dest);
+ strbuf_release(&request->buffer.buf);
free(request);
}
@@ -577,9 +582,10 @@ static void finish_request(struct transfer_request *request)
if (obj_req->rename == 0)
request->obj->flags |= (LOCAL | REMOTE);
+ release_http_object_request(&obj_req);
+
/* Try fetching packed if necessary */
if (request->obj->flags & LOCAL) {
- release_http_object_request(obj_req);
release_request(request);
} else
start_fetch_packed(request);
@@ -648,12 +654,10 @@ static void add_fetch_request(struct object *obj)
return;
obj->flags |= FETCHING;
- request = xmalloc(sizeof(*request));
+ CALLOC_ARRAY(request, 1);
request->obj = obj;
- request->url = NULL;
- request->lock = NULL;
- request->headers = NULL;
request->state = NEED_FETCH;
+ strbuf_init(&request->buffer.buf, 0);
request->next = request_queue_head;
request_queue_head = request;
@@ -677,19 +681,18 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)
get_remote_object_list(obj->oid.hash[0]);
if (obj->flags & (REMOTE | PUSHING))
return 0;
- target = find_sha1_pack(obj->oid.hash, repo->packs);
+ target = find_oid_pack(&obj->oid, repo->packs);
if (target) {
obj->flags |= REMOTE;
return 0;
}
obj->flags |= PUSHING;
- request = xmalloc(sizeof(*request));
+ CALLOC_ARRAY(request, 1);
request->obj = obj;
- request->url = NULL;
request->lock = lock;
- request->headers = NULL;
request->state = NEED_PUSH;
+ strbuf_init(&request->buffer.buf, 0);
request->next = request_queue_head;
request_queue_head = request;
@@ -911,6 +914,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
result = XML_Parse(parser, in_buffer.buf,
in_buffer.len, 1);
free(ctx.name);
+ free(ctx.cdata);
if (result != XML_STATUS_OK) {
fprintf(stderr, "XML error: %s\n",
XML_ErrorString(
@@ -1017,6 +1021,7 @@ static void remote_ls(const char *path, int flags,
/* extract hex from sharded "xx/x{38}" filename */
static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
{
+ memset(oid->hash, 0, GIT_MAX_RAWSZ);
oid->algo = hash_algo_by_ptr(the_hash_algo);
if (strlen(path) != the_hash_algo->hexsz + 1)
@@ -1167,6 +1172,7 @@ static void remote_ls(const char *path, int flags,
result = XML_Parse(parser, in_buffer.buf,
in_buffer.len, 1);
free(ctx.name);
+ free(ctx.cdata);
if (result != XML_STATUS_OK) {
fprintf(stderr, "XML error: %s\n",
@@ -1180,6 +1186,7 @@ static void remote_ls(const char *path, int flags,
}
free(ls.path);
+ free(ls.dentry_name);
free(url);
strbuf_release(&out_buffer.buf);
strbuf_release(&in_buffer);
@@ -1308,7 +1315,7 @@ static struct object_list **process_tree(struct tree *tree,
obj->flags |= SEEN;
p = add_one_object(obj, p);
- init_tree_desc(&desc, tree->buffer, tree->size);
+ init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
while (tree_entry(&desc, &entry))
switch (object_type(entry.mode)) {
@@ -1368,9 +1375,13 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
}
while (objects) {
+ struct object_list *next = objects->next;
+
if (!(objects->item->flags & UNINTERESTING))
count += add_send_request(objects->item, lock);
- objects = objects->next;
+
+ free(objects);
+ objects = next;
}
return count;
@@ -1396,6 +1407,7 @@ static int update_remote(const struct object_id *oid, struct remote_lock *lock)
if (start_active_slot(slot)) {
run_active_slot(slot);
strbuf_release(&out_buffer.buf);
+ curl_slist_free_all(dav_headers);
if (results.curl_result != CURLE_OK) {
fprintf(stderr,
"PUT error: curl result=%d, HTTP code=%ld\n",
@@ -1405,6 +1417,7 @@ static int update_remote(const struct object_id *oid, struct remote_lock *lock)
}
} else {
strbuf_release(&out_buffer.buf);
+ curl_slist_free_all(dav_headers);
fprintf(stderr, "Unable to start PUT request\n");
return 0;
}
@@ -1514,6 +1527,7 @@ static void update_remote_info_refs(struct remote_lock *lock)
results.curl_result, results.http_code);
}
}
+ curl_slist_free_all(dav_headers);
}
strbuf_release(&buffer.buf);
}
@@ -1553,7 +1567,7 @@ static void fetch_symref(const char *path, char **symref, struct object_id *oid)
free(url);
FREE_AND_NULL(*symref);
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
if (buffer.len == 0)
return;
@@ -1576,8 +1590,11 @@ static int verify_merge_base(struct object_id *head_oid, struct ref *remote)
struct commit *head = lookup_commit_or_die(head_oid, "HEAD");
struct commit *branch = lookup_commit_or_die(&remote->old_oid,
remote->name);
+ int ret = repo_in_merge_bases(the_repository, branch, head);
- return repo_in_merge_bases(the_repository, branch, head);
+ if (ret < 0)
+ exit(128);
+ return ret;
}
static int delete_remote_branch(const char *pattern, int force)
@@ -1702,7 +1719,7 @@ int cmd_main(int argc, const char **argv)
int rc = 0;
int i;
int new_refs;
- struct ref *ref, *local_refs;
+ struct ref *ref, *local_refs = NULL;
CALLOC_ARRAY(repo, 1);
@@ -1852,6 +1869,7 @@ int cmd_main(int argc, const char **argv)
if (oideq(&ref->old_oid, &ref->peer_ref->new_oid)) {
if (push_verbosely)
+ /* stable plumbing output; do not modify or localize */
fprintf(stderr, "'%s': up-to-date\n", ref->name);
if (helper_status)
printf("ok %s up to date\n", ref->name);
@@ -1872,6 +1890,7 @@ int cmd_main(int argc, const char **argv)
* commits at the remote end and likely
* we were not up to date to begin with.
*/
+ /* stable plumbing output; do not modify or localize */
error("remote '%s' is not an ancestor of\n"
"local '%s'.\n"
"Maybe you are not up-to-date and "
@@ -1965,6 +1984,7 @@ int cmd_main(int argc, const char **argv)
cleanup:
if (info_ref_lock)
unlock_remote(info_ref_lock);
+ free(repo->url);
free(repo);
http_cleanup();
@@ -1976,5 +1996,8 @@ int cmd_main(int argc, const char **argv)
request = next_request;
}
+ refspec_clear(&rs);
+ free_refs(local_refs);
+
return rc;
}