summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e8dc37e)
raw | patch | inline | side by side (parent: e8dc37e)
author | Mike Hommey <mh@glandium.org> | |
Sun, 9 Dec 2007 19:30:59 +0000 (20:30 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 15 Dec 2007 05:31:59 +0000 (21:31 -0800) |
Also, replace whitespaces with tabs in some places
Signed-off-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
http-push.c | patch | blob | history | |
http-walker.c | patch | blob | history | |
http.c | patch | blob | history | |
http.h | patch | blob | history | |
transport.c | patch | blob | history |
diff --git a/http-push.c b/http-push.c
index 176bb29fab011500e882d6fd6a3ed467b853bb18..0257291b9ba9258558632b1e428df6479a28b9db 100644 (file)
--- a/http-push.c
+++ b/http-push.c
memset(&stream, 0, sizeof(stream));
deflateInit(&stream, zlib_compression_level);
size = deflateBound(&stream, len + hdrlen);
- request->buffer.buffer = xmalloc(size);
+ strbuf_init(&request->buffer.buf, size);
+ request->buffer.posn = 0;
/* Compress it */
- stream.next_out = request->buffer.buffer;
+ stream.next_out = (unsigned char *)request->buffer.buf.buf;
stream.avail_out = size;
/* First header.. */
deflateEnd(&stream);
free(unpacked);
- request->buffer.size = stream.total_out;
- request->buffer.posn = 0;
+ request->buffer.buf.len = stream.total_out;
request->url = xmalloc(strlen(remote->url) +
strlen(request->lock->token) + 51);
slot->callback_func = process_response;
slot->callback_data = request;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &request->buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, request->buffer.size);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, request->buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
{
unsigned char sha1[20];
char *url;
- struct buffer buffer;
+ struct strbuf buffer = STRBUF_INIT;
char *data;
int i = 0;
struct active_request_slot *slot;
struct slot_results results;
- data = xcalloc(1, 4096);
- buffer.size = 4096;
- buffer.posn = 0;
- buffer.buffer = data;
-
if (push_verbosely)
fprintf(stderr, "Getting pack list\n");
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result != CURLE_OK) {
- free(buffer.buffer);
+ strbuf_release(&buffer);
free(url);
if (results.http_code == 404)
return 0;
return error("%s", curl_errorstr);
}
} else {
- free(buffer.buffer);
+ strbuf_release(&buffer);
free(url);
return error("Unable to start request");
}
free(url);
- data = buffer.buffer;
- while (i < buffer.posn) {
+ data = buffer.buf;
+ while (i < buffer.len) {
switch (data[i]) {
case 'P':
i++;
- if (i + 52 < buffer.posn &&
+ if (i + 52 < buffer.len &&
!prefixcmp(data + i, " pack-") &&
!prefixcmp(data + i + 46, ".pack\n")) {
get_sha1_hex(data + i + 6, sha1);
i++;
}
- free(buffer.buffer);
+ strbuf_release(&buffer);
return 0;
}
int fetch_ref(char *ref, unsigned char *sha1)
{
- char *url;
- char hex[42];
- struct buffer buffer;
+ char *url;
+ struct strbuf buffer = STRBUF_INIT;
char *base = remote->url;
struct active_request_slot *slot;
struct slot_results results;
- buffer.size = 41;
- buffer.posn = 0;
- buffer.buffer = hex;
- hex[41] = '\0';
url = quote_ref_url(base, ref);
slot = get_active_slot();
return error("Unable to start request");
}
- if (buffer.posn != 41)
+ strbuf_rtrim(&buffer);
+ if (buffer.len != 40)
return 1;
- hex[40] = '\0';
- return get_sha1_hex(hex, sha1);
+ return get_sha1_hex(buffer.buf, sha1);
}
static void one_remote_object(const char *hex)
{
struct active_request_slot *slot;
struct slot_results results;
- struct buffer out_buffer;
- struct buffer in_buffer;
- char *out_data;
- char *in_data;
+ struct buffer out_buffer = { STRBUF_INIT, 0 };
+ struct strbuf in_buffer = STRBUF_INIT;
char *url;
char *ep;
char timeout_header[25];
ep = strchr(ep + 1, '/');
}
- out_buffer.size = strlen(LOCK_REQUEST) + strlen(git_default_email) - 2;
- out_data = xmalloc(out_buffer.size + 1);
- snprintf(out_data, out_buffer.size + 1, LOCK_REQUEST, git_default_email);
- out_buffer.posn = 0;
- out_buffer.buffer = out_data;
-
- in_buffer.size = 4096;
- in_data = xmalloc(in_buffer.size);
- in_buffer.posn = 0;
- in_buffer.buffer = in_data;
+ strbuf_addf(&out_buffer.buf, LOCK_REQUEST, git_default_email);
sprintf(timeout_header, "Timeout: Second-%ld", timeout);
dav_headers = curl_slist_append(dav_headers, timeout_header);
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
XML_SetElementHandler(parser, xml_start_tag,
xml_end_tag);
XML_SetCharacterDataHandler(parser, xml_cdata);
- result = XML_Parse(parser, in_buffer.buffer,
- in_buffer.posn, 1);
+ result = XML_Parse(parser, in_buffer.buf,
+ in_buffer.len, 1);
free(ctx.name);
if (result != XML_STATUS_OK) {
fprintf(stderr, "XML error: %s\n",
}
curl_slist_free_all(dav_headers);
- free(out_data);
- free(in_data);
+ strbuf_release(&out_buffer.buf);
+ strbuf_release(&in_buffer);
if (lock->token == NULL || lock->timeout <= 0) {
if (lock->token != NULL)
char *url = xmalloc(strlen(remote->url) + strlen(path) + 1);
struct active_request_slot *slot;
struct slot_results results;
- struct buffer in_buffer;
- struct buffer out_buffer;
- char *in_data;
- char *out_data;
+ struct strbuf in_buffer = STRBUF_INIT;
+ struct buffer out_buffer = { STRBUF_INIT, 0 };
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
struct remote_ls_ctx ls;
sprintf(url, "%s%s", remote->url, path);
- out_buffer.size = strlen(PROPFIND_ALL_REQUEST);
- out_data = xmalloc(out_buffer.size + 1);
- snprintf(out_data, out_buffer.size + 1, PROPFIND_ALL_REQUEST);
- out_buffer.posn = 0;
- out_buffer.buffer = out_data;
-
- in_buffer.size = 4096;
- in_data = xmalloc(in_buffer.size);
- in_buffer.posn = 0;
- in_buffer.buffer = in_data;
+ strbuf_addf(&out_buffer.buf, PROPFIND_ALL_REQUEST);
dav_headers = curl_slist_append(dav_headers, "Depth: 1");
dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
XML_SetElementHandler(parser, xml_start_tag,
xml_end_tag);
XML_SetCharacterDataHandler(parser, xml_cdata);
- result = XML_Parse(parser, in_buffer.buffer,
- in_buffer.posn, 1);
+ result = XML_Parse(parser, in_buffer.buf,
+ in_buffer.len, 1);
free(ctx.name);
if (result != XML_STATUS_OK) {
free(ls.path);
free(url);
- free(out_data);
- free(in_buffer.buffer);
+ strbuf_release(&out_buffer.buf);
+ strbuf_release(&in_buffer);
curl_slist_free_all(dav_headers);
}
{
struct active_request_slot *slot;
struct slot_results results;
- struct buffer in_buffer;
- struct buffer out_buffer;
- char *in_data;
- char *out_data;
+ struct strbuf in_buffer = STRBUF_INIT;
+ struct buffer out_buffer = { STRBUF_INIT, 0 };
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
int lock_flags = 0;
- out_buffer.size =
- strlen(PROPFIND_SUPPORTEDLOCK_REQUEST) +
- strlen(remote->url) - 2;
- out_data = xmalloc(out_buffer.size + 1);
- snprintf(out_data, out_buffer.size + 1,
- PROPFIND_SUPPORTEDLOCK_REQUEST, remote->url);
- out_buffer.posn = 0;
- out_buffer.buffer = out_data;
-
- in_buffer.size = 4096;
- in_data = xmalloc(in_buffer.size);
- in_buffer.posn = 0;
- in_buffer.buffer = in_data;
+ strbuf_addf(&out_buffer.buf, PROPFIND_SUPPORTEDLOCK_REQUEST, remote->url);
dav_headers = curl_slist_append(dav_headers, "Depth: 0");
dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
XML_SetUserData(parser, &ctx);
XML_SetElementHandler(parser, xml_start_tag,
xml_end_tag);
- result = XML_Parse(parser, in_buffer.buffer,
- in_buffer.posn, 1);
+ result = XML_Parse(parser, in_buffer.buf,
+ in_buffer.len, 1);
free(ctx.name);
if (result != XML_STATUS_OK) {
fprintf(stderr, "Unable to start PROPFIND request\n");
}
- free(out_data);
- free(in_buffer.buffer);
+ strbuf_release(&out_buffer.buf);
+ strbuf_release(&in_buffer);
curl_slist_free_all(dav_headers);
return lock_flags;
{
struct active_request_slot *slot;
struct slot_results results;
- char *out_data;
char *if_header;
- struct buffer out_buffer;
+ struct buffer out_buffer = { STRBUF_INIT, 0 };
struct curl_slist *dav_headers = NULL;
- int i;
if_header = xmalloc(strlen(lock->token) + 25);
sprintf(if_header, "If: (<opaquelocktoken:%s>)", lock->token);
dav_headers = curl_slist_append(dav_headers, if_header);
- out_buffer.size = 41;
- out_data = xmalloc(out_buffer.size + 1);
- i = snprintf(out_data, out_buffer.size + 1, "%s\n", sha1_to_hex(sha1));
- if (i != out_buffer.size) {
- fprintf(stderr, "Unable to initialize PUT request body\n");
- return 0;
- }
- out_buffer.posn = 0;
- out_buffer.buffer = out_data;
+ strbuf_addf(&out_buffer.buf, "%s\n", sha1_to_hex(sha1));
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
if (start_active_slot(slot)) {
run_active_slot(slot);
- free(out_data);
+ strbuf_release(&out_buffer.buf);
free(if_header);
if (results.curl_result != CURLE_OK) {
fprintf(stderr,
return 0;
}
} else {
- free(out_data);
+ strbuf_release(&out_buffer.buf);
free(if_header);
fprintf(stderr, "Unable to start PUT request\n");
return 0;
static void add_remote_info_ref(struct remote_ls_ctx *ls)
{
- struct buffer *buf = (struct buffer *)ls->userData;
+ struct strbuf *buf = (struct strbuf *)ls->userData;
unsigned char remote_sha1[20];
struct object *o;
int len;
static void update_remote_info_refs(struct remote_lock *lock)
{
- struct buffer buffer;
+ struct buffer buffer = { STRBUF_INIT, 0 };
struct active_request_slot *slot;
struct slot_results results;
char *if_header;
struct curl_slist *dav_headers = NULL;
- buffer.buffer = xcalloc(1, 4096);
- buffer.size = 4096;
- buffer.posn = 0;
remote_ls("refs/", (PROCESS_FILES | RECURSIVE),
- add_remote_info_ref, &buffer);
+ add_remote_info_ref, &buffer.buf);
if (!aborted) {
if_header = xmalloc(strlen(lock->token) + 25);
sprintf(if_header, "If: (<opaquelocktoken:%s>)", lock->token);
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, buffer.posn);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
curl_easy_setopt(slot->curl, CURLOPT_PUT, 1);
curl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);
- buffer.posn = 0;
-
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result != CURLE_OK) {
}
free(if_header);
}
- free(buffer.buffer);
+ strbuf_release(&buffer.buf);
}
static int remote_exists(const char *path)
sprintf(url, "%s%s", remote->url, path);
- slot = get_active_slot();
+ slot = get_active_slot();
slot->results = &results;
- curl_easy_setopt(slot->curl, CURLOPT_URL, url);
- curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1);
+ curl_easy_setopt(slot->curl, CURLOPT_URL, url);
+ curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1);
- if (start_active_slot(slot)) {
+ if (start_active_slot(slot)) {
run_active_slot(slot);
free(url);
if (results.http_code == 404)
static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
{
char *url;
- struct buffer buffer;
+ struct strbuf buffer = STRBUF_INIT;
struct active_request_slot *slot;
struct slot_results results;
url = xmalloc(strlen(remote->url) + strlen(path) + 1);
sprintf(url, "%s%s", remote->url, path);
- buffer.size = 4096;
- buffer.posn = 0;
- buffer.buffer = xmalloc(buffer.size);
-
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
@@ -2165,17 +2100,17 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
*symref = NULL;
hashclr(sha1);
- if (buffer.posn == 0)
+ if (buffer.len == 0)
return;
/* If it's a symref, set the refname; otherwise try for a sha1 */
- if (!prefixcmp((char *)buffer.buffer, "ref: ")) {
- *symref = xmemdupz((char *)buffer.buffer + 5, buffer.posn - 6);
+ if (!prefixcmp((char *)buffer.buf, "ref: ")) {
+ *symref = xmemdupz((char *)buffer.buf + 5, buffer.len - 6);
} else {
- get_sha1_hex(buffer.buffer, sha1);
+ get_sha1_hex(buffer.buf, sha1);
}
- free(buffer.buffer);
+ strbuf_release(&buffer);
}
static int verify_merge_base(unsigned char *head_sha1, unsigned char *branch_sha1)
diff --git a/http-walker.c b/http-walker.c
index ad874b98cb5c76ef81a99607dc3630baf7a7f62a..8dbf9cc369c59d36930c6cf67fda8ed279d50922 100644 (file)
--- a/http-walker.c
+++ b/http-walker.c
struct walker *walker;
const char *base;
char *url;
- struct buffer *buffer;
+ struct strbuf *buffer;
struct active_request_slot *slot;
int http_specific;
};
if (alt_req->http_specific) {
if (slot->curl_result != CURLE_OK ||
- !alt_req->buffer->posn) {
+ !alt_req->buffer->len) {
/* Try reusing the slot to get non-http alternates */
alt_req->http_specific = 0;
}
fwrite_buffer(&null_byte, 1, 1, alt_req->buffer);
- alt_req->buffer->posn--;
- data = alt_req->buffer->buffer;
+ alt_req->buffer->len--;
+ data = alt_req->buffer->buf;
- while (i < alt_req->buffer->posn) {
+ while (i < alt_req->buffer->len) {
int posn = i;
- while (posn < alt_req->buffer->posn && data[posn] != '\n')
+ while (posn < alt_req->buffer->len && data[posn] != '\n')
posn++;
if (data[posn] == '\n') {
int okay = 0;
static void fetch_alternates(struct walker *walker, const char *base)
{
- struct buffer buffer;
+ struct strbuf buffer = STRBUF_INIT;
char *url;
- char *data;
struct active_request_slot *slot;
struct alternates_request alt_req;
struct walker_data *cdata = walker->data;
/* Start the fetch */
cdata->got_alternates = 0;
- data = xmalloc(4096);
- buffer.size = 4096;
- buffer.posn = 0;
- buffer.buffer = data;
-
if (walker->get_verbosely)
fprintf(stderr, "Getting alternates list for %s\n", base);
else
cdata->got_alternates = -1;
- free(data);
+ strbuf_release(&buffer);
free(url);
}
{
unsigned char sha1[20];
char *url;
- struct buffer buffer;
+ struct strbuf buffer = STRBUF_INIT;
char *data;
int i = 0;
if (repo->got_indices)
return 0;
- data = xmalloc(4096);
- buffer.size = 4096;
- buffer.posn = 0;
- buffer.buffer = data;
-
if (walker->get_verbosely)
fprintf(stderr, "Getting pack list for %s\n", repo->base);
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result != CURLE_OK) {
+ strbuf_release(&buffer);
if (missing_target(&results)) {
repo->got_indices = 1;
- free(buffer.buffer);
return 0;
} else {
repo->got_indices = 0;
- free(buffer.buffer);
return error("%s", curl_errorstr);
}
}
} else {
repo->got_indices = 0;
- free(buffer.buffer);
+ strbuf_release(&buffer);
return error("Unable to start request");
}
- data = buffer.buffer;
- while (i < buffer.posn) {
+ data = buffer.buf;
+ while (i < buffer.len) {
switch (data[i]) {
case 'P':
i++;
- if (i + 52 <= buffer.posn &&
+ if (i + 52 <= buffer.len &&
!prefixcmp(data + i, " pack-") &&
!prefixcmp(data + i + 46, ".pack\n")) {
get_sha1_hex(data + i + 6, sha1);
break;
}
default:
- while (i < buffer.posn && data[i] != '\n')
+ while (i < buffer.len && data[i] != '\n')
i++;
}
i++;
}
- free(buffer.buffer);
+ strbuf_release(&buffer);
repo->got_indices = 1;
return 0;
}
static int fetch_ref(struct walker *walker, char *ref, unsigned char *sha1)
{
- char *url;
- char hex[42];
- struct buffer buffer;
+ char *url;
+ struct strbuf buffer = STRBUF_INIT;
struct walker_data *data = walker->data;
const char *base = data->alt->base;
struct active_request_slot *slot;
struct slot_results results;
- buffer.size = 41;
- buffer.posn = 0;
- buffer.buffer = hex;
- hex[41] = '\0';
url = quote_ref_url(base, ref);
slot = get_active_slot();
return error("Unable to start request");
}
- if (buffer.posn != 41)
+ strbuf_rtrim(&buffer);
+ if (buffer.len != 40)
return 1;
- hex[40] = '\0';
- return get_sha1_hex(hex, sha1);
+ return get_sha1_hex(buffer.buf, sha1);
}
static void cleanup(struct walker *walker)
index ae57073a362ef7bc373855a132b9c25b3e60c154..dcc569343e20abfbf6df06fd7346a6a5bca5bba8 100644 (file)
--- a/http.c
+++ b/http.c
struct buffer *buffer)
{
size_t size = eltsize * nmemb;
- if (size > buffer->size - buffer->posn)
- size = buffer->size - buffer->posn;
- memcpy(ptr, (char *) buffer->buffer + buffer->posn, size);
+ if (size > buffer->buf.len - buffer->posn)
+ size = buffer->buf.len - buffer->posn;
+ memcpy(ptr, buffer->buf.buf + buffer->posn, size);
buffer->posn += size;
+
return size;
}
size_t fwrite_buffer(const void *ptr, size_t eltsize,
- size_t nmemb, struct buffer *buffer)
+ size_t nmemb, struct strbuf *buffer)
{
size_t size = eltsize * nmemb;
- if (size > buffer->size - buffer->posn) {
- buffer->size = buffer->size * 3 / 2;
- if (buffer->size < buffer->posn + size)
- buffer->size = buffer->posn + size;
- buffer->buffer = xrealloc(buffer->buffer, buffer->size);
- }
- memcpy((char *) buffer->buffer + buffer->posn, ptr, size);
- buffer->posn += size;
+ strbuf_add(buffer, ptr, size);
data_received++;
return size;
}
size_t fwrite_null(const void *ptr, size_t eltsize,
- size_t nmemb, struct buffer *buffer)
+ size_t nmemb, struct strbuf *buffer)
{
data_received++;
return eltsize * nmemb;
static void closedown_active_slot(struct active_request_slot *slot)
{
- active_requests--;
- slot->in_use = 0;
+ active_requests--;
+ slot->in_use = 0;
}
void release_active_slot(struct active_request_slot *slot)
static void finish_active_slot(struct active_request_slot *slot)
{
closedown_active_slot(slot);
- curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code);
+ curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code);
if (slot->finished != NULL)
(*slot->finished) = 1;
slot->results->http_code = slot->http_code;
}
- /* Run callback if appropriate */
- if (slot->callback_func != NULL) {
- slot->callback_func(slot->callback_data);
- }
+ /* Run callback if appropriate */
+ if (slot->callback_func != NULL) {
+ slot->callback_func(slot->callback_data);
+ }
}
void finish_all_active_slots(void)
index b9d6f4823d4a5318c6b7ac2f3d80bdce46e30d68..1528d4196fe91a62efedcc2f7664c27e1f3fac6c 100644 (file)
--- a/http.h
+++ b/http.h
#include <curl/curl.h>
#include <curl/easy.h>
+#include "strbuf.h"
+
#if LIBCURL_VERSION_NUM >= 0x071000
#define USE_CURL_MULTI
#define DEFAULT_MAX_REQUESTS 5
struct buffer
{
- size_t posn;
- size_t size;
- void *buffer;
+ struct strbuf buf;
+ size_t posn;
};
/* Curl request read/write callbacks */
extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
struct buffer *buffer);
extern size_t fwrite_buffer(const void *ptr, size_t eltsize,
- size_t nmemb, struct buffer *buffer);
+ size_t nmemb, struct strbuf *buffer);
extern size_t fwrite_null(const void *ptr, size_t eltsize,
- size_t nmemb, struct buffer *buffer);
+ size_t nmemb, struct strbuf *buffer);
/* Slot lifecycle functions */
extern struct active_request_slot *get_active_slot(void);
diff --git a/transport.c b/transport.c
index 1f840a0498f9fa013c4b10d874525fbca679b2de..4e151a9e878b402fd0b70c31057b9bcfcff7d9b7 100644 (file)
--- a/transport.c
+++ b/transport.c
@@ -428,7 +428,7 @@ static int curl_transport_push(struct transport *transport, int refspec_nr, cons
static struct ref *get_refs_via_curl(struct transport *transport)
{
- struct buffer buffer;
+ struct strbuf buffer = STRBUF_INIT;
char *data, *start, *mid;
char *ref_name;
char *refs_url;
struct ref *ref = NULL;
struct ref *last_ref = NULL;
- data = xmalloc(4096);
- buffer.size = 4096;
- buffer.posn = 0;
- buffer.buffer = data;
-
refs_url = xmalloc(strlen(transport->url) + 11);
sprintf(refs_url, "%s/info/refs", transport->url);
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result != CURLE_OK) {
+ strbuf_release(&buffer);
if (missing_target(&results)) {
- free(buffer.buffer);
return NULL;
} else {
- free(buffer.buffer);
error("%s", curl_errorstr);
return NULL;
}
}
} else {
- free(buffer.buffer);
+ strbuf_release(&buffer);
error("Unable to start request");
return NULL;
}
http_cleanup();
- data = buffer.buffer;
+ data = buffer.buf;
start = NULL;
mid = data;
- while (i < buffer.posn) {
+ while (i < buffer.len) {
if (!start)
start = &data[i];
if (data[i] == '\t')
i++;
}
- free(buffer.buffer);
+ strbuf_release(&buffer);
return refs;
}