commit 2624d1656867df76d9de1103980ebe112bd5d6a9 from: Omar Polo via: Thomas Adam date: Tue Feb 07 20:14:55 2023 UTC replace got_repo_get_gitconfig_extensions with got_repo_has_extension got_repo_get_gitconfig_extensions is only used in gotadmin to check if the preciousObjects extension is active; let's replace it with a function that just checks whether a certain extension is active. It simplifies future changes to the extensions handling. ok stsp@ commit - 7a2222c7f09e34fad3eb3be24a72f7e10bcbedd4 commit + 2624d1656867df76d9de1103980ebe112bd5d6a9 blob - e56af526574e829f6648d2978d85ee8b14af9cd2 blob + 52aa7491c5c27ef8be99eeaa1d4046e6b92610bf --- gotadmin/gotadmin.c +++ gotadmin/gotadmin.c @@ -1218,8 +1218,6 @@ cmd_cleanup(int argc, char *argv[]) char scaled_before[FMT_SCALED_STRSIZE]; char scaled_after[FMT_SCALED_STRSIZE]; char scaled_diff[FMT_SCALED_STRSIZE]; - char **extensions; - int nextensions, i; int *pack_fds = NULL; while ((ch = getopt(argc, argv, "anpqr:")) != -1) { @@ -1273,15 +1271,11 @@ cmd_cleanup(int argc, char *argv[]) if (error) goto done; - got_repo_get_gitconfig_extensions(&extensions, &nextensions, - repo); - for (i = 0; i < nextensions; i++) { - if (strcasecmp(extensions[i], "preciousObjects") == 0) { - error = got_error_msg(GOT_ERR_GIT_REPO_EXT, - "the preciousObjects Git extension is enabled; " - "this implies that objects must not be deleted"); - goto done; - } + if (got_repo_has_extension(repo, "preciousObjects")) { + error = got_error_msg(GOT_ERR_GIT_REPO_EXT, + "the preciousObjects Git extension is enabled; " + "this implies that objects must not be deleted"); + goto done; } if (remove_lonely_packidx) { blob - b507b207a3c163a0492722f3e42ea689dacbf7e6 blob + 53e99801ab01ad8804d048c5f59a94930e5ef10a --- include/got_repository.h +++ include/got_repository.h @@ -50,9 +50,8 @@ const char *got_repo_get_global_gitconfig_author_email /* Obtain repository owner name if parsed from gitconfig, else NULL. */ const char *got_repo_get_gitconfig_owner(struct got_repository *); -/* Obtain the list of enabled Git extensions parsed from gitconfig. */ -void got_repo_get_gitconfig_extensions(char ***, int *, - struct got_repository *); +/* Query if a given Git extension is enabled in gitconfig. */ +int got_repo_has_extension(struct got_repository *, const char *); /* Information about one remote repository. */ struct got_remote_repo { blob - b0c3b7094e4b1c970d1cda630bbf40c4862d3c6f blob + c9f770d505436eed7a5216d43275ed7014742655 --- lib/repository.c +++ lib/repository.c @@ -117,12 +117,17 @@ got_repo_get_gitconfig_owner(struct got_repository *re return repo->gitconfig_owner; } -void -got_repo_get_gitconfig_extensions(char ***extensions, int *nextensions, - struct got_repository *repo) +int +got_repo_has_extension(struct got_repository *repo, const char *ext) { - *extensions = repo->extensions; - *nextensions = repo->nextensions; + int i; + + for (i = 0; i < repo->nextensions; ++i) { + if (!strcasecmp(ext, repo->extensions[i])) + return 1; + } + + return 0; } int