Browse Source

Merge branch 'rc/http-push'

* rc/http-push:
  http-push: wrap signature of get_remote_object_url
  http-push: add back underscore separator before lock token
  http-push.c: get_remote_object_url() is only used under USE_CURL_MULTI
  http-push: refactor request url creation
maint
Junio C Hamano 16 years ago
parent
commit
7aa4e736b2
  1. 67
      http-push.c

67
http-push.c

@ -210,6 +210,15 @@ static struct curl_slist *get_dav_token_headers(struct remote_lock *lock, enum d
return dav_headers; return dav_headers;
} }


static void append_remote_object_url(struct strbuf *buf, const char *url,
const char *hex,
int only_two_digit_prefix)
{
strbuf_addf(buf, "%sobjects/%.*s/", url, 2, hex);
if (!only_two_digit_prefix)
strbuf_addf(buf, "%s", hex+2);
}

static void finish_request(struct transfer_request *request); static void finish_request(struct transfer_request *request);
static void release_request(struct transfer_request *request); static void release_request(struct transfer_request *request);


@ -222,6 +231,15 @@ static void process_response(void *callback_data)
} }


#ifdef USE_CURL_MULTI #ifdef USE_CURL_MULTI

static char *get_remote_object_url(const char *url, const char *hex,
int only_two_digit_prefix)
{
struct strbuf buf = STRBUF_INIT;
append_remote_object_url(&buf, url, hex, only_two_digit_prefix);
return strbuf_detach(&buf, NULL);
}

static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb, static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
void *data) void *data)
{ {
@ -256,7 +274,6 @@ static void start_fetch_loose(struct transfer_request *request)
char *filename; char *filename;
char prevfile[PATH_MAX]; char prevfile[PATH_MAX];
char *url; char *url;
char *posn;
int prevlocal; int prevlocal;
unsigned char prev_buf[PREV_BUF_SIZE]; unsigned char prev_buf[PREV_BUF_SIZE];
ssize_t prev_read = 0; ssize_t prev_read = 0;
@ -306,17 +323,8 @@ static void start_fetch_loose(struct transfer_request *request)


git_SHA1_Init(&request->c); git_SHA1_Init(&request->c);


url = xmalloc(strlen(remote->url) + 50); url = get_remote_object_url(remote->url, hex, 0);
request->url = xmalloc(strlen(remote->url) + 50); request->url = xstrdup(url);
strcpy(url, remote->url);
posn = url + strlen(remote->url);
strcpy(posn, "objects/");
posn += 8;
memcpy(posn, hex, 2);
posn += 2;
*(posn++) = '/';
strcpy(posn, hex + 2);
strcpy(request->url, url);


/* If a previous temp file is present, process what was already /* If a previous temp file is present, process what was already
fetched. */ fetched. */
@ -389,16 +397,8 @@ static void start_mkcol(struct transfer_request *request)
{ {
char *hex = sha1_to_hex(request->obj->sha1); char *hex = sha1_to_hex(request->obj->sha1);
struct active_request_slot *slot; struct active_request_slot *slot;
char *posn;


request->url = xmalloc(strlen(remote->url) + 13); request->url = get_remote_object_url(remote->url, hex, 1);
strcpy(request->url, remote->url);
posn = request->url + strlen(remote->url);
strcpy(posn, "objects/");
posn += 8;
memcpy(posn, hex, 2);
posn += 2;
strcpy(posn, "/");


slot = get_active_slot(); slot = get_active_slot();
slot->callback_func = process_response; slot->callback_func = process_response;
@ -513,7 +513,7 @@ static void start_put(struct transfer_request *request)
{ {
char *hex = sha1_to_hex(request->obj->sha1); char *hex = sha1_to_hex(request->obj->sha1);
struct active_request_slot *slot; struct active_request_slot *slot;
char *posn; struct strbuf buf = STRBUF_INIT;
enum object_type type; enum object_type type;
char hdr[50]; char hdr[50];
void *unpacked; void *unpacked;
@ -552,21 +552,14 @@ static void start_put(struct transfer_request *request)


request->buffer.buf.len = stream.total_out; request->buffer.buf.len = stream.total_out;


request->url = xmalloc(strlen(remote->url) + strbuf_addstr(&buf, "Destination: ");
strlen(request->lock->token) + 51); append_remote_object_url(&buf, remote->url, hex, 0);
strcpy(request->url, remote->url); request->dest = strbuf_detach(&buf, NULL);
posn = request->url + strlen(remote->url);
strcpy(posn, "objects/"); append_remote_object_url(&buf, remote->url, hex, 0);
posn += 8; strbuf_addstr(&buf, "_");
memcpy(posn, hex, 2); strbuf_addstr(&buf, request->lock->token);
posn += 2; request->url = strbuf_detach(&buf, NULL);
*(posn++) = '/';
strcpy(posn, hex + 2);
request->dest = xmalloc(strlen(request->url) + 14);
sprintf(request->dest, "Destination: %s", request->url);
posn += 38;
*(posn++) = '_';
strcpy(posn, request->lock->token);


slot = get_active_slot(); slot = get_active_slot();
slot->callback_func = process_response; slot->callback_func = process_response;

Loading…
Cancel
Save