commit 99e30d93bfe048c40e277fed11e065fdb420d51f from: Omar Polo via: Thomas Adam date: Wed Jan 31 22:01:31 2024 UTC allow remotes without urls in git config in gotd This is b624328edd but for the code used by gotd. ok stsp@ commit - 2eb6139c99c62e54720d434e6ab75a5b3b82c57b commit + 99e30d93bfe048c40e277fed11e065fdb420d51f blob - 652f3a8089f499bd882469d76a46f4643d670a75 blob + 2f0d8354033636a99c65040e57ebb2ebe81897e2 --- lib/read_gitconfig.c +++ lib/read_gitconfig.c @@ -50,6 +50,18 @@ get_boolean_val(char *val) strcmp(val, "1") == 0); } +static int +skip_node(struct got_gitconfig *gitconfig, + struct got_gitconfig_list_node *node) +{ + /* + * Skip config nodes which do not describe remotes, and remotes + * which do not have a fetch URL defined (as used by git-annex). + */ + return (strncasecmp("remote \"", node->field, 8) != 0 || + got_gitconfig_get_str(gitconfig, node->field, "url") == NULL); +} + const struct got_error * got_repo_read_gitconfig(int *gitconfig_repository_format_version, char **gitconfig_author_name, char **gitconfig_author_email, @@ -178,7 +190,7 @@ got_repo_read_gitconfig(int *gitconfig_repository_form if (err) return err; TAILQ_FOREACH(node, §ions->fields, link) { - if (strncasecmp("remote \"", node->field, 8) != 0) + if (skip_node(gitconfig, node)) continue; nalloc++; } @@ -195,7 +207,7 @@ got_repo_read_gitconfig(int *gitconfig_repository_form char *name, *end, *mirror; const char *fetch_url, *send_url; - if (strncasecmp("remote \"", node->field, 8) != 0) + if (skip_node(gitconfig, node) != 0) continue; remote = &(*remotes)[i]; @@ -212,12 +224,6 @@ got_repo_read_gitconfig(int *gitconfig_repository_form fetch_url = got_gitconfig_get_str(gitconfig, node->field, "url"); - if (fetch_url == NULL) { - err = got_error(GOT_ERR_GITCONFIG_SYNTAX); - free(remote->name); - remote->name = NULL; - goto done; - } remote->fetch_url = strdup(fetch_url); if (remote->fetch_url == NULL) { err = got_error_from_errno("strdup"); @@ -231,14 +237,6 @@ got_repo_read_gitconfig(int *gitconfig_repository_form if (send_url == NULL) send_url = got_gitconfig_get_str(gitconfig, node->field, "url"); - if (send_url == NULL) { - err = got_error(GOT_ERR_GITCONFIG_SYNTAX); - free(remote->name); - remote->name = NULL; - free(remote->fetch_url); - remote->fetch_url = NULL; - goto done; - } remote->send_url = strdup(send_url); if (remote->send_url == NULL) { err = got_error_from_errno("strdup");