summaryrefslogtreecommitdiff
path: root/connect.c
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2020-05-25 19:58:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-05-27 17:07:06 (GMT)
commit122037c2edec0c2bbcbfe52679fddc438165ab54 (patch)
tree0e08fcd17d2b713a34791c806c5b806f64e73d98 /connect.c
parent7c97af4d64100bf9ce4b335ee91e743378e2e181 (diff)
downloadgit-122037c2edec0c2bbcbfe52679fddc438165ab54.zip
git-122037c2edec0c2bbcbfe52679fddc438165ab54.tar.gz
git-122037c2edec0c2bbcbfe52679fddc438165ab54.tar.bz2
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>
Diffstat (limited to 'connect.c')
-rw-r--r--connect.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/connect.c b/connect.c
index ad0e4e8..eaa13b4 100644
--- 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);