connect: add function to detect supported v1 hash functions
Add a function, server_supports_hash, to see if the remote server supports a particular hash algorithm when speaking protocol v1. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 25, 2020 at 19:58 UTC
122037c2edec0c2bbcbfe52679fddc438165ab54
2 files changed
+23
connect.c
+22
@@ -511,6 +511,28 @@ static const char *parse_feature_value(const char *feature_list, const char *fea
511
return NULL;
512
}
513
514
+int server_supports_hash(const char *desired, int *feature_supported)
515
+{
516
+ int offset = 0;
517
+ int len;
518
+ const char *hash;
519
+
520
+ hash = next_server_feature_value("object-format", &len, &offset);
521
+ if (feature_supported)
522
+ *feature_supported = !!hash;
523
+ if (!hash) {
524
+ hash = hash_algos[GIT_HASH_SHA1].name;
525
+ len = strlen(hash);
526
+ }
527
+ while (hash) {
528
+ if (!xstrncmpz(desired, hash, len))
529
+ return 1;
530
+
531
+ hash = next_server_feature_value("object-format", &len, &offset);
532
+ }
533
+ return 0;
534
+}
535
+
536
int parse_feature_request(const char *feature_list, const char *feature)
537
{
538
return !!parse_feature_value(feature_list, feature, NULL, NULL);
connect.h
+1
@@ -18,6 +18,7 @@ int url_is_local_not_ssh(const char *url);
18
struct packet_reader;
19
enum protocol_version discover_version(struct packet_reader *reader);
20
21
+int server_supports_hash(const char *desired, int *feature_supported);
22
int server_supports_v2(const char *c, int die_on_error);
23
int server_feature_v2(const char *c, const char **v);
24
int server_supports_feature(const char *c, const char *feature,