Merge branch 'rc/http-push'

* rc/http-push:
  use a hash of the lock token as the suffix for PUT/MOVE
This commit is contained in:
Junio C Hamano 2009-02-15 01:43:57 -08:00
commit c42b04bbb0
2 changed files with 18 additions and 2 deletions

View File

@ -153,6 +153,7 @@ struct remote_lock
char *url; char *url;
char *owner; char *owner;
char *token; char *token;
char tmpfile_suffix[41];
time_t start_time; time_t start_time;
long timeout; long timeout;
int refreshing; int refreshing;
@ -557,8 +558,7 @@ static void start_put(struct transfer_request *request)
request->dest = strbuf_detach(&buf, NULL); request->dest = strbuf_detach(&buf, NULL);
append_remote_object_url(&buf, remote->url, hex, 0); append_remote_object_url(&buf, remote->url, hex, 0);
strbuf_addstr(&buf, "_"); strbuf_add(&buf, request->lock->tmpfile_suffix, 41);
strbuf_addstr(&buf, request->lock->token);
request->url = strbuf_detach(&buf, NULL); request->url = strbuf_detach(&buf, NULL);
slot = get_active_slot(); slot = get_active_slot();
@ -1130,6 +1130,8 @@ static void handle_lockprop_ctx(struct xml_ctx *ctx, int tag_closed)
static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed) static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
{ {
struct remote_lock *lock = (struct remote_lock *)ctx->userData; struct remote_lock *lock = (struct remote_lock *)ctx->userData;
git_SHA_CTX sha_ctx;
unsigned char lock_token_sha1[20];
if (tag_closed && ctx->cdata) { if (tag_closed && ctx->cdata) {
if (!strcmp(ctx->name, DAV_ACTIVELOCK_OWNER)) { if (!strcmp(ctx->name, DAV_ACTIVELOCK_OWNER)) {
@ -1142,6 +1144,13 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) { } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
lock->token = xmalloc(strlen(ctx->cdata) + 1); lock->token = xmalloc(strlen(ctx->cdata) + 1);
strcpy(lock->token, ctx->cdata); strcpy(lock->token, ctx->cdata);
git_SHA1_Init(&sha_ctx);
git_SHA1_Update(&sha_ctx, lock->token, strlen(lock->token));
git_SHA1_Final(lock_token_sha1, &sha_ctx);
lock->tmpfile_suffix[0] = '_';
memcpy(lock->tmpfile_suffix + 1, sha1_to_hex(lock_token_sha1), 40);
} }
} }
} }

View File

@ -94,6 +94,13 @@ test_expect_success 'MKCOL sends directory names with trailing slashes' '
' '
test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
grep -P "\"(?:PUT|MOVE) .+objects/[\da-z]{2}/[\da-z]{38}_[\da-z\-]{40} HTTP/[0-9.]+\" 20\d" \
< "$HTTPD_ROOT_PATH"/access.log
'
stop_httpd stop_httpd
test_done test_done