commit 2cd8863b9225d29955e9620edf5804d13d3eb5c3c5b509ef366629f2aecbb02b from: Stefan Sperling date: Sun Oct 25 09:47:50 2026 UTC allow the default hash algorithm to be changed to sha1 in gotsys.conf ok thomas_adam commit - 87bce16fa03b3a93c5dc056d4dcc90c01a553360536614722192b754ee669733 commit + 2cd8863b9225d29955e9620edf5804d13d3eb5c3c5b509ef366629f2aecbb02b blob - 5f65fb56c0d40625ec6b804c836298665b85829e05286b283ab8379748295695 blob + e0f32cd806789767a814b18fe26ddf4c9e246d9e845da13b81d86e2c49bef12d --- gotsys/gotsys.conf.5 +++ gotsys/gotsys.conf.5 @@ -43,6 +43,21 @@ are treated as comments and ignored. .Sh GLOBAL CONFIGURATION The available global configuration directives are as follows: .Bl -tag -width Ds +.It Ic hash algorithm Ar hashing-algorithm +Configure the default +.Ar hashing-algorithm +used for the computation of Git object IDs. +Possible values are +.Dq sha256 +.Pq the default +or +.Dq sha1 . +.Pp +This configuration directive only affects newly created repositories. +The hashing algorithm of existing repositories cannot be changed. +.Pp +The default hash algorithm can be overridden with per-repository +configuration directives described below. .It Ic group Ar name Declare a group with the given .Ar name . @@ -296,9 +311,11 @@ Configure the repository's used for the computation of Git object IDs. Possible values are .Dq sha256 -.Pq the default or .Dq sha1 . +If not set, the value set in the global configuration context will be used, +which defaults to +.Dq sha256 . .Pp This configuration directive only affects newly created repositories. The hashing algorithm of existing repositories cannot be changed. blob - 2b568ab8ec90874385848adc84b5694efea6e0800a86c013a6027a93857b3473 blob + 0775bf531dd533781222b438b08eeab27757ace0ddff5160d9072240b9e1986d --- gotsys/gotsys.h +++ gotsys/gotsys.h @@ -172,6 +172,7 @@ struct gotsys_conf { int nrepos; struct gotsys_webserverlist webservers; struct mediatypes mediatypes; + enum got_hash_algorithm default_algo; }; void gotsys_conf_init(struct gotsys_conf *); blob - 5c40e8e5af2f41cd914dd6ff4a1e49c31f1e0d6292f3e45f3207d372ec54b90b blob + 103c3256d8ad8aab1cb225132017f4a1dc4f4b5e9bfe934695084f186ead95ae --- gotsys/parse.y +++ gotsys/parse.y @@ -238,6 +238,27 @@ main : USER STRING { | MEDIA TYPES '{' optnl mediaopts_l '}' { new_mediatypes = &gotsysconf->mediatypes; } + | HASH ALGORITHM STRING { + const struct got_error *err; + enum got_hash_algorithm algo; + + err = gotsys_conf_validate_hash_algo(&algo, $3); + if (err) { + yyerror("%s", err->msg); + free($3); + YYERROR; + } + + if (gotsysconf->default_algo != GOT_NUM_HASH_ALGOS) { + yyerror("the default hash algorithm can only " + "be specified once"); + free($3); + YYERROR; + } + + gotsysconf->default_algo = algo; + free($3); + } ; useropts1 : GROUP STRING { @@ -1659,6 +1680,13 @@ gotsys_conf_parse(const char *filename, struct gotsys_ "repository %s.git", GOTSYS_SYSTEM_REPOSITORY_NAME); } + if (gotsysconf->default_algo == GOT_NUM_HASH_ALGOS) + gotsysconf->default_algo = GOT_HASH_SHA256; + TAILQ_FOREACH(repo, &gotsysconf->repos, entry) { + if (repo->algo == GOT_NUM_HASH_ALGOS) + repo->algo = gotsysconf->default_algo; + } + STAILQ_FOREACH(srv, &gotsysconf->webservers, entry) { struct gotsys_webrepo *webrepo; struct gotsys_repo *repo; blob - 5f65d7039af9568ce9ccb88dcbb3eb9b2e0e4364b38c9b705abdf2af5fa285e4 blob + f3d20fcec9f2944ede90b6ff963dce4dfc9f1e102f05efd64b633ddd59369ebf --- lib/gotsys_conf.c +++ lib/gotsys_conf.c @@ -59,6 +59,8 @@ gotsys_conf_init(struct gotsys_conf *gotsysconf) TAILQ_INIT(&gotsysconf->repos); STAILQ_INIT(&gotsysconf->webservers); RB_INIT(&gotsysconf->mediatypes); + + gotsysconf->default_algo = GOT_NUM_HASH_ALGOS; /* unset */ } const struct got_error * @@ -908,7 +910,7 @@ gotsys_conf_new_repo(struct gotsys_repo **new_repo, co "repository name too long: %s", name); } - repo->algo = GOT_HASH_SHA256; + repo->algo = GOT_NUM_HASH_ALGOS; /* unset */ *new_repo = repo; return NULL;