]> git.ipfire.org Git - thirdparty/git.git/commitdiff
connect: add function to detect supported v1 hash functions
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 25 May 2020 19:58:56 +0000 (19:58 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 May 2020 17:07:06 +0000 (10:07 -0700)
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>
connect.c
connect.h

index ad0e4e8e564a3c2c04219f9f5a69d8515fb34f9c..eaa13b41bbeb9d0a170baf044ae52d85c63fc85f 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -511,6 +511,28 @@ static const char *parse_feature_value(const char *feature_list, const char *fea
        return NULL;
 }
 
+int server_supports_hash(const char *desired, int *feature_supported)
+{
+       int offset = 0;
+       int len;
+       const char *hash;
+
+       hash = next_server_feature_value("object-format", &len, &offset);
+       if (feature_supported)
+               *feature_supported = !!hash;
+       if (!hash) {
+               hash = hash_algos[GIT_HASH_SHA1].name;
+               len = strlen(hash);
+       }
+       while (hash) {
+               if (!xstrncmpz(desired, hash, len))
+                       return 1;
+
+               hash = next_server_feature_value("object-format", &len, &offset);
+       }
+       return 0;
+}
+
 int parse_feature_request(const char *feature_list, const char *feature)
 {
        return !!parse_feature_value(feature_list, feature, NULL, NULL);
index 4d76a6017deafab2a3c250de2b56f1a8d423f3a7..fc75d6a45773af566c26925ce77a9f22fb7d4a94 100644 (file)
--- a/connect.h
+++ b/connect.h
@@ -18,6 +18,7 @@ int url_is_local_not_ssh(const char *url);
 struct packet_reader;
 enum protocol_version discover_version(struct packet_reader *reader);
 
+int server_supports_hash(const char *desired, int *feature_supported);
 int server_supports_v2(const char *c, int die_on_error);
 int server_feature_v2(const char *c, const char **v);
 int server_supports_feature(const char *c, const char *feature,