http-push: convert to use the_hash_algo
Switch the lock token code to use the_hash_algo and increase its buffers to be allocated using GIT_MAX_* constants. Update the parsing of object paths to use the_hash_algo as well. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Feb 19, 2019 at 00:05 UTC
f024b87a086643bbe6c869af11eee27aaaebb074
1 file changed
+10
-10
http-push.c
+10
-10
@@ -145,7 +145,7 @@ struct remote_lock {
145
char *url;
146
char *owner;
147
char *token;
148
- char tmpfile_suffix[41];
148
+ char tmpfile_suffix[GIT_MAX_HEXSZ + 1];
149
time_t start_time;
150
long timeout;
151
int refreshing;
@@ -399,7 +399,7 @@ static void start_put(struct transfer_request *request)
399
request->dest = strbuf_detach(&buf, NULL);
400
401
append_remote_object_url(&buf, repo->url, hex, 0);
402
- strbuf_add(&buf, request->lock->tmpfile_suffix, 41);
402
+ strbuf_add(&buf, request->lock->tmpfile_suffix, the_hash_algo->hexsz + 1);
403
request->url = strbuf_detach(&buf, NULL);
404
405
slot = get_active_slot();
@@ -758,8 +758,8 @@ static void handle_lockprop_ctx(struct xml_ctx *ctx, int tag_closed)
758
static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
759
{
760
struct remote_lock *lock = (struct remote_lock *)ctx->userData;
761
- git_SHA_CTX sha_ctx;
762
- unsigned char lock_token_sha1[20];
761
+ git_hash_ctx hash_ctx;
762
+ unsigned char lock_token_hash[GIT_MAX_RAWSZ];
763
764
if (tag_closed && ctx->cdata) {
765
if (!strcmp(ctx->name, DAV_ACTIVELOCK_OWNER)) {
@@ -771,12 +771,12 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
771
} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
772
lock->token = xstrdup(ctx->cdata);
773
774
- git_SHA1_Init(&sha_ctx);
775
- git_SHA1_Update(&sha_ctx, lock->token, strlen(lock->token));
776
- git_SHA1_Final(lock_token_sha1, &sha_ctx);
774
+ the_hash_algo->init_fn(&hash_ctx);
775
+ the_hash_algo->update_fn(&hash_ctx, lock->token, strlen(lock->token));
776
+ the_hash_algo->final_fn(lock_token_hash, &hash_ctx);
777
778
lock->tmpfile_suffix[0] = '_';
779
- memcpy(lock->tmpfile_suffix + 1, sha1_to_hex(lock_token_sha1), 40);
779
+ memcpy(lock->tmpfile_suffix + 1, hash_to_hex(lock_token_hash), the_hash_algo->hexsz);
780
}
781
}
782
}
@@ -1018,7 +1018,7 @@ static void remote_ls(const char *path, int flags,
1018
/* extract hex from sharded "xx/x{38}" filename */
1019
static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
1020
{
1021
- if (strlen(path) != GIT_SHA1_HEXSZ + 1)
1021
+ if (strlen(path) != the_hash_algo->hexsz + 1)
1022
return -1;
1023
1024
if (hex_to_bytes(oid->hash, path, 1))
@@ -1026,7 +1026,7 @@ static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
1026
path += 2;
1027
path++; /* skip '/' */
1028
1029
- return hex_to_bytes(oid->hash + 1, path, GIT_SHA1_RAWSZ - 1);
1029
+ return hex_to_bytes(oid->hash + 1, path, the_hash_algo->rawsz - 1);
1030
}
1031
1032
static void process_ls_object(struct remote_ls_ctx *ls)