commit d735340e74df3af82f7acd745d0145d7dd5e19b7a8468c3abf9a03a5488b16da from: Stefan Sperling date: Mon Nov 16 18:22:20 2026 UTC pass repository hash algorithm to libexec helpers on the command line For now, this is a purely mechanical non-functional change which ensures that the main process's idea of the hash algorithm is known to all helpers. This will allow us to reduce overhead by not having to send the hash algorithm along via a struct got_object_id in imsg buffers. Instead we could now send raw SHA1 or SHA256 hashes in messages since the hash algorithm is now known by all processes before messages are exchanged. commit - 8b548f3204aa9834989a33553110d2ec2a67191856812c836b5e0380f84839e8 commit + d735340e74df3af82f7acd745d0145d7dd5e19b7a8468c3abf9a03a5488b16da blob - 592ed765a8cc7623977e626f1ca581a01fbb9237d32322b3e1fc6f37ba0e29ad blob + d469f1d9a39a6707dde99f4579e58a5a8fded0ef601db30cdcbf47ad892f7f2f --- gotd/privsep_stub.c +++ gotd/privsep_stub.c @@ -53,7 +53,8 @@ got_privsep_wait_for_child(pid_t pid) } void -got_privsep_exec_child(int imsg_fds[2], const char *path, const char *repo_path) +got_privsep_exec_child(int imsg_fds[2], const char *path, const char *repo_path, + enum got_hash_algorithm algo) { fprintf(stderr, "%s: cannot run libexec helpers\n", getprogname()); exit(1); blob - 4a982d4dcb3edf1792545997c00381f251a42c4cff2b2a1f716b6a6887603622 blob + 2e6e762de8fecf0b1f6adf9c7f1411923e57ff5c92cf6789153c32e92d5f9a8a --- gotsys/privsep_stub.c +++ gotsys/privsep_stub.c @@ -53,7 +53,8 @@ got_privsep_wait_for_child(pid_t pid) } void -got_privsep_exec_child(int imsg_fds[2], const char *path, const char *repo_path) +got_privsep_exec_child(int imsg_fds[2], const char *path, const char *repo_path, + enum got_hash_algorithm algo) { fprintf(stderr, "%s: cannot run libexec helpers\n", getprogname()); abort(); blob - e5aed6a69e0e8fe283b1bfb4c63e9146bbc7d15ca4868e85eaf611200bb6efda blob + 51270ab5232e9ab13c9d438800ebfa5fa85b9029120f821ab662a8453d6bb021 --- lib/fetch.c +++ lib/fetch.c @@ -262,7 +262,8 @@ got_fetch_pack(struct got_object_id **pack_hash, struc goto done; } else if (fetchpid == 0){ got_privsep_exec_child(imsg_fetchfds, - GOT_PATH_PROG_FETCH_PACK, tmppackpath); + GOT_PATH_PROG_FETCH_PACK, tmppackpath, + repo ? got_repo_get_hash_algo(repo) : GOT_HASH_SHA1); } if (close(imsg_fetchfds[1]) == -1) { @@ -481,7 +482,8 @@ got_fetch_pack(struct got_object_id **pack_hash, struc goto done; } else if (idxpid == 0) got_privsep_exec_child(imsg_idxfds, - GOT_PATH_PROG_INDEX_PACK, tmppackpath); + GOT_PATH_PROG_INDEX_PACK, tmppackpath, + got_repo_get_hash_algo(repo)); if (close(imsg_idxfds[1]) == -1) { err = got_error_from_errno("close"); goto done; blob - 79daa2630a7c0f6536b8634bc9fe1bee9954d8d7c4de34c2c5bb95f8013814f4 blob + cecb8152c3b9fe8fb18a6eaf0e1d00931364d8b95de35a6b25877daf3fa58a1f --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -881,4 +881,5 @@ const struct got_error *got_privsep_recv_painted_commi struct got_object_id_queue *, got_privsep_recv_painted_commit_cb, void *, struct imsgbuf *); -void got_privsep_exec_child(int[2], const char *, const char *); +void got_privsep_exec_child(int[2], const char *, const char *, + enum got_hash_algorithm); blob - 8ae283e0b625fa52d814b536a31aba9a03f01e9ace183ef126b3e40d91390f04 blob + 4e9b733d9b7b62a036340aada2316206d75effb90d3ebe870dbcc68ec9e83e04 --- lib/load.c +++ lib/load.c @@ -475,7 +475,8 @@ got_repo_load(FILE *in, struct got_pathlist_head *refs goto done; } else if (idxpid == 0) got_privsep_exec_child(imsg_idxfds, - GOT_PATH_PROG_INDEX_PACK, tmppackpath); + GOT_PATH_PROG_INDEX_PACK, tmppackpath, + got_repo_get_hash_algo(repo)); if (close(imsg_idxfds[1]) == -1) { err = got_error_from_errno("close"); goto done; blob - 0e174251d607ace24ec639e21fe05b9a504191110dc41be3da5ad7280d6a4834 blob + 9aa29827721c2d057703092f2a82ef7a70ab41ccf23d9bd94375bb010814f5b2 --- lib/object_open_privsep.c +++ lib/object_open_privsep.c @@ -367,7 +367,8 @@ start_child(struct got_repository *repo, int type) return err; } else if (pid == 0) { - got_privsep_exec_child(imsg_fds, prog_path, repo->path); + got_privsep_exec_child(imsg_fds, prog_path, repo->path, + got_repo_get_hash_algo(repo)); /* not reached */ } blob - e1e718525f259d03609439b29bd15acf83836dc91a6f1a0b17f2a61d55733729 blob + 3bc401fd3ac8ba1fa11d09490834cac94dfe3e0879b78d515a6d22f4e92d4cea --- lib/pack.c +++ lib/pack.c @@ -772,7 +772,7 @@ got_pack_start_privsep_child(struct got_pack *pack, st } else if (pid == 0) { set_max_datasize(); got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_PACK, - pack->path_packfile); + pack->path_packfile, pack->algo); /* not reached */ } blob - ee7157fd1cb346734c75cf846e66368d17b860fbe848188a7a9f08d40c129b2b blob + 4080434222d2cd58d0fd86b67757359f71818888042e5ed766ec642deea3249d --- lib/patch.c +++ lib/patch.c @@ -1063,7 +1063,7 @@ got_patch(int fd, struct got_worktree *worktree, struc goto done; } else if (pid == 0) { got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_PATCH, - NULL); + NULL, got_repo_get_hash_algo(repo)); /* not reached */ } blob - 86fc260e730ccaa0f68118329659b7e9e850be2cad638765c51de3f3f57bce26 blob + 214a1a0b755fa5586a586fa314f60f36c69f3a7834268eddc4cd1b09a3f7feb9 --- lib/privsep.c +++ lib/privsep.c @@ -3831,7 +3831,8 @@ got_privsep_unveil_exec_helpers(void) } void -got_privsep_exec_child(int imsg_fds[2], const char *path, const char *repo_path) +got_privsep_exec_child(int imsg_fds[2], const char *path, const char *repo_path, + enum got_hash_algorithm algo) { if (close(imsg_fds[0]) == -1) { fprintf(stderr, "%s: %s\n", getprogname(), strerror(errno)); @@ -3845,7 +3846,8 @@ got_privsep_exec_child(int imsg_fds[2], const char *pa closefrom(GOT_IMSG_FD_CHILD + 1); - if (execl(path, path, repo_path, (char *)NULL) == -1) { + if (execl(path, path, "-A", got_hash_algo_name(algo), repo_path, + (char *)NULL) == -1) { fprintf(stderr, "%s: %s: %s\n", getprogname(), path, strerror(errno)); _exit(1); blob - 8051e5608281bc7277f83cc7128a4e9359fc4f0a068ceb3076f7ee26ccb16558 blob + 99d5330f503a80e4eb1d024586ccaae9bbbb5e875580cd11fcf1a20e6fa62f1a --- lib/read_gitconfig_privsep.c +++ lib/read_gitconfig_privsep.c @@ -95,7 +95,7 @@ got_repo_read_gitconfig(int *gitconfig_repository_form goto done; } else if (pid == 0) { got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_GITCONFIG, - gitconfig_path); + gitconfig_path, GOT_HASH_SHA1 /* not used */); /* not reached */ } blob - 92f8395d98994e6ed809f9a1717dab0fe3d2e9e0bed2e6ea2f909ac0d2795b1c blob + 30e65bb26a64cc73c10625db85ce84d9a78aa09f9e532886901b1502b427d60b --- lib/read_gotconfig_privsep.c +++ lib/read_gotconfig_privsep.c @@ -77,7 +77,7 @@ got_gotconfig_read(struct got_gotconfig **conf, const goto done; } else if (pid == 0) { got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_GOTCONFIG, - gotconfig_path); + gotconfig_path, GOT_HASH_SHA1 /* not used */); /* not reached */ } blob - 95949c9876ad06bf5fa87714843f64d00dfeac1fbbd6975f2283dce22739715b blob + 6f603f5b3407eae4057c956d7e6dbde068d1fdf306efc63e1ffbff9ca933486d --- lib/repository_admin.c +++ lib/repository_admin.c @@ -399,7 +399,8 @@ got_repo_index_pack(char **idxpath, FILE *packfile, goto done; } else if (idxpid == 0) got_privsep_exec_child(imsg_idxfds, - GOT_PATH_PROG_INDEX_PACK, packfile_path); + GOT_PATH_PROG_INDEX_PACK, packfile_path, + got_repo_get_hash_algo(repo)); if (close(imsg_idxfds[1]) == -1) { err = got_error_from_errno("close"); goto done; blob - a6c649203093458d2a1d23efc605ad338a4309a9af5bd003be94010d45834460 blob + 714ed05f2a4b59c817b08fd45a37fbe8e905bf4eabfb83b53fb13ca708efa1d9 --- lib/send.c +++ lib/send.c @@ -463,7 +463,8 @@ got_send_pack(const char *remote_name, struct got_path goto done; } else if (sendpid == 0) { got_privsep_exec_child(imsg_sendfds, - GOT_PATH_PROG_SEND_PACK, got_repo_get_path(repo)); + GOT_PATH_PROG_SEND_PACK, got_repo_get_path(repo), + got_repo_get_hash_algo(repo)); } if (close(imsg_sendfds[1]) == -1) { blob - 726ac28172bd932d6bfafe664ed5c0e0eb50c078d67ca006f73a1e933c4f45a8 blob + 65eccd78329a14d35a8a9ff2b32787176d523288f86ac7c855b88410ba7b61a7 --- libexec/got-fetch-http/got-fetch-http.c +++ libexec/got-fetch-http/got-fetch-http.c @@ -536,8 +536,11 @@ main(int argc, char **argv) err(1, "pledge"); #endif - while ((ch = getopt(argc, argv, "qv")) != -1) { + while ((ch = getopt(argc, argv, "A:qv")) != -1) { switch (ch) { + case 'A': + /* we do not need to know the hash algorithm */ + break; case 'q': verbose = -1; break; blob - 480775b584ed851a51d5afa06d8ab05f9dfc388a96a287296256360bcb883eef blob + a51c4d5d352733ad05781e0448c34a0b0447f3f44e849945714632f49270a0e8 --- libexec/got-fetch-pack/got-fetch-pack.c +++ libexec/got-fetch-pack/got-fetch-pack.c @@ -66,6 +66,7 @@ struct got_object *indexed; static int chattygot; +static enum got_hash_algorithm algo = GOT_NUM_HASH_ALGOS; static const struct got_capability got_capabilities[] = { { GOT_CAPA_AGENT, "got/" GOT_VERSION_STR }, @@ -973,12 +974,30 @@ main(int argc, char **argv) size_t datalen, i; struct got_pathlist_entry *new; char *remote_head = NULL, *worktree_branch = NULL; + int ch; #if 0 static int attached; while (!attached) sleep (1); #endif + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + if (strcasecmp(optarg, "sha1") == 0) + algo = GOT_HASH_SHA1; + else if (strcasecmp(optarg, "sha256") == 0) + algo = GOT_HASH_SHA256; + else + errx(1, "bad hash algorithm %s", optarg); + break; + default: + break; + } + } + if (algo == GOT_NUM_HASH_ALGOS) + errx(1, "no hash algorithm"); + RB_INIT(&have_refs); RB_INIT(&wanted_branches); RB_INIT(&wanted_refs); blob - 9747397a896f98857369d81ecadf8fb669c22ea8bcd96fbf5b822d6e1364c8af blob + 9f9f4957b03e8b617de70b66d2e5540e69b2a4c3e0dbf853dbb3f3ef9544af14 --- libexec/got-index-pack/got-index-pack.c +++ libexec/got-index-pack/got-index-pack.c @@ -50,6 +50,8 @@ #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) #endif +static enum got_hash_algorithm algo = GOT_NUM_HASH_ALGOS; + static const struct got_error * send_index_pack_progress(void *arg, uint32_t nobj_total, uint32_t nobj_indexed, uint32_t nobj_loose, uint32_t nobj_resolved) @@ -91,12 +93,30 @@ main(int argc, char **argv) struct got_pack pack; off_t packfile_size; struct got_ratelimit rl; + int ch; #if 0 static int attached; while (!attached) sleep(1); #endif + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + if (strcasecmp(optarg, "sha1") == 0) + algo = GOT_HASH_SHA1; + else if (strcasecmp(optarg, "sha256") == 0) + algo = GOT_HASH_SHA256; + else + errx(1, "bad hash algorithm %s", optarg); + break; + default: + break; + } + } + if (algo == GOT_NUM_HASH_ALGOS) + errx(1, "no hash algorithm"); + got_ratelimit_init(&rl, 0, 500); for (i = 0; i < nitems(tmpfiles); i++) blob - b85fdd9fac2e7de32f4a6b02245e4f1ac83974afaf26785d8db50961ff7fbc81 blob + 91bdca3ed057d6621da5c9d2dffd2276e3e8bcea76ed19b184d60469e35d1f03 --- libexec/got-read-blob/got-read-blob.c +++ libexec/got-read-blob/got-read-blob.c @@ -43,6 +43,7 @@ #include "got_lib_privsep.h" static volatile sig_atomic_t sigint_received; +static enum got_hash_algorithm algo = GOT_NUM_HASH_ALGOS; static void catch_sigint(int signo) @@ -56,9 +57,28 @@ main(int argc, char *argv[]) const struct got_error *err = NULL; struct imsgbuf ibuf; size_t datalen; + int ch; signal(SIGINT, catch_sigint); + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + if (strcasecmp(optarg, "sha1") == 0) + algo = GOT_HASH_SHA1; + else if (strcasecmp(optarg, "sha256") == 0) + algo = GOT_HASH_SHA256; + else + errx(1, "bad hash algorithm %s", optarg); + break; + default: + break; + } + } + + if (algo == GOT_NUM_HASH_ALGOS) + errx(1, "no hash algorithm"); + if (imsgbuf_init(&ibuf, GOT_IMSG_FD_CHILD) == -1) { warn("imsgbuf_init"); return 1; blob - b691f94ebb32cd35f3c89e944dfba0511e83158d546edcc4a2958c832f99bf85 blob + e85350977000c40f19abfb6ef3d5c09e7bdcd1388e600562809d0c37801adc37 --- libexec/got-read-commit/got-read-commit.c +++ libexec/got-read-commit/got-read-commit.c @@ -44,6 +44,7 @@ #include "got_lib_privsep.h" static volatile sig_atomic_t sigint_received; +static enum got_hash_algorithm algo = GOT_NUM_HASH_ALGOS; static void catch_sigint(int signo) @@ -57,7 +58,26 @@ main(int argc, char *argv[]) const struct got_error *err = NULL; struct imsgbuf ibuf; size_t datalen; + int ch; + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + if (strcasecmp(optarg, "sha1") == 0) + algo = GOT_HASH_SHA1; + else if (strcasecmp(optarg, "sha256") == 0) + algo = GOT_HASH_SHA256; + else + errx(1, "bad hash algorithm %s", optarg); + break; + default: + break; + } + } + + if (algo == GOT_NUM_HASH_ALGOS) + errx(1, "no hash algorithm"); + signal(SIGINT, catch_sigint); if (imsgbuf_init(&ibuf, GOT_IMSG_FD_CHILD) == -1) { blob - 8400669bd5450aacf6bd5f3a92fa35c5b544561940258f313f6da04ccbffd4ef blob + 671fcad2dce85801fd2087ff95cf1ff18ab80ab11be5627ec8d192f5fe5dd3fc --- libexec/got-read-gitconfig/got-read-gitconfig.c +++ libexec/got-read-gitconfig/got-read-gitconfig.c @@ -339,12 +339,23 @@ main(int argc, char *argv[]) struct imsgbuf ibuf; size_t datalen; struct got_gitconfig *gitconfig = NULL; + int ch; #if 0 static int attached; while (!attached) sleep(1); #endif + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + /* ignore hash algorithm parameter */ + break; + default: + break; + } + } + signal(SIGINT, catch_sigint); if (imsgbuf_init(&ibuf, GOT_IMSG_FD_CHILD) == -1) { blob - 7e6b72bc44ea8a96a55e06b6d5016385e6b4fb6ab65fc9ee1314633479f9051c blob + 32a280c951c77e03fedb359adfc99821fc6bdfee71b6e5949dc5ac22b9aa337a --- libexec/got-read-gotconfig/got-read-gotconfig.c +++ libexec/got-read-gotconfig/got-read-gotconfig.c @@ -484,12 +484,23 @@ main(int argc, char *argv[]) struct gotconfig *gotconfig = NULL; size_t datalen; const char *filename = "got.conf"; + int ch; #if 0 static int attached; while (!attached) sleep(1); #endif + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + /* ignore hash algorithm parameter */ + break; + default: + break; + } + } + signal(SIGINT, catch_sigint); if (imsgbuf_init(&ibuf, GOT_IMSG_FD_CHILD) == -1) { blob - bf22336430d8a990ed2a0003618d591678166973725366d1e73b8fa424295304 blob + 01fbc7ea298392445021c3f2e4e90c9b6784fbffabbd01160a57a2f255e6c09f --- libexec/got-read-object/got-read-object.c +++ libexec/got-read-object/got-read-object.c @@ -52,6 +52,7 @@ #define GOT_OBJ_TAG_TAG "tag" static volatile sig_atomic_t sigint_received; +static enum got_hash_algorithm algo = GOT_NUM_HASH_ALGOS; static void catch_sigint(int signo) @@ -96,7 +97,26 @@ main(int argc, char *argv[]) struct imsgbuf ibuf; size_t datalen; struct got_object_id expected_id; + int ch; + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + if (strcasecmp(optarg, "sha1") == 0) + algo = GOT_HASH_SHA1; + else if (strcasecmp(optarg, "sha256") == 0) + algo = GOT_HASH_SHA256; + else + errx(1, "bad hash algorithm %s", optarg); + break; + default: + break; + } + } + + if (algo == GOT_NUM_HASH_ALGOS) + errx(1, "no hash algorithm"); + signal(SIGINT, catch_sigint); if (imsgbuf_init(&ibuf, GOT_IMSG_FD_CHILD) == -1) { blob - 5939c96523bcb2fe537afdb18dcb5a949ae2d32f9353ea1e7e1d5bac6dc364e2 blob + 40693ce75d90836c0240a47919f01513be9ae7f43b47585189a9ce5ae6fbef47 --- libexec/got-read-pack/got-read-pack.c +++ libexec/got-read-pack/got-read-pack.c @@ -58,6 +58,7 @@ #endif static volatile sig_atomic_t sigint_received; +static enum got_hash_algorithm algo = GOT_NUM_HASH_ALGOS; static void catch_sigint(int signo) @@ -2019,10 +2020,29 @@ main(int argc, char *argv[]) struct got_object_idset *keep = NULL, *drop = NULL, *skip = NULL; struct got_parsed_tree_entry *entries = NULL; size_t nentries = 0, nentries_alloc = 0; + int ch; //static int attached; //while (!attached) sleep(1); + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + if (strcasecmp(optarg, "sha1") == 0) + algo = GOT_HASH_SHA1; + else if (strcasecmp(optarg, "sha256") == 0) + algo = GOT_HASH_SHA256; + else + errx(1, "bad hash algorithm %s", optarg); + break; + default: + break; + } + } + + if (algo == GOT_NUM_HASH_ALGOS) + errx(1, "no hash algorithm"); + signal(SIGINT, catch_sigint); if (imsgbuf_init(&ibuf, GOT_IMSG_FD_CHILD) == -1) { blob - 01508ab5a7961d85aeec9a44ddb338e8593d9dc9989f85f3b298dcd7149af69a blob + 386b013cb385224ec42530ced5d9d28170a894b8430c83b888c5263aa5271653 --- libexec/got-read-patch/got-read-patch.c +++ libexec/got-read-patch/got-read-patch.c @@ -61,6 +61,7 @@ #include "got_lib_privsep.h" struct imsgbuf ibuf; +static enum got_hash_algorithm algo = GOT_NUM_HASH_ALGOS; static const struct got_error * send_patch(const char *oldname, const char *newname, const char *commitid, @@ -647,13 +648,30 @@ main(int argc, char **argv) const struct got_error *err = NULL; struct imsg imsg; FILE *fp = NULL; - int fd = -1; + int fd = -1, ch; #if 0 static int attached; while (!attached) sleep(1); #endif + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + if (strcasecmp(optarg, "sha1") == 0) + algo = GOT_HASH_SHA1; + else if (strcasecmp(optarg, "sha256") == 0) + algo = GOT_HASH_SHA256; + else + errx(1, "bad hash algorithm %s", optarg); + break; + default: + break; + } + } + if (algo == GOT_NUM_HASH_ALGOS) + errx(1, "no hash algorithm"); + if (imsgbuf_init(&ibuf, GOT_IMSG_FD_CHILD) == -1) { warn("imsgbuf_init"); return 1; blob - b448f837408a8e94ba1d31045d026c15273f40e54238f16ca8c61f75c0d95df1 blob + 555931dd6b1d54029a52eb7b3a384c0c84ddafddddcaa453d5297c6ebfb3f867 --- libexec/got-read-tag/got-read-tag.c +++ libexec/got-read-tag/got-read-tag.c @@ -43,6 +43,7 @@ #include "got_lib_privsep.h" static volatile sig_atomic_t sigint_received; +static enum got_hash_algorithm algo = GOT_NUM_HASH_ALGOS; static void catch_sigint(int signo) @@ -56,7 +57,26 @@ main(int argc, char *argv[]) const struct got_error *err = NULL; struct imsgbuf ibuf; size_t datalen; + int ch; + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + if (strcasecmp(optarg, "sha1") == 0) + algo = GOT_HASH_SHA1; + else if (strcasecmp(optarg, "sha256") == 0) + algo = GOT_HASH_SHA256; + else + errx(1, "bad hash algorithm %s", optarg); + break; + default: + break; + } + } + + if (algo == GOT_NUM_HASH_ALGOS) + errx(1, "no hash algorithm"); + signal(SIGINT, catch_sigint); if (imsgbuf_init(&ibuf, GOT_IMSG_FD_CHILD) == -1) { blob - 2f15956b0a66f7f66a5d6f94b97334052537bd5429bca5bd6963efd08b35ef88 blob + 89dab67d2749f1de9c24a11723fd170c534adadde8355f36cc676c16cceb6001 --- libexec/got-read-tree/got-read-tree.c +++ libexec/got-read-tree/got-read-tree.c @@ -45,6 +45,7 @@ #include "got_lib_privsep.h" static volatile sig_atomic_t sigint_received; +static enum got_hash_algorithm algo = GOT_NUM_HASH_ALGOS; static void catch_sigint(int signo) @@ -60,7 +61,26 @@ main(int argc, char *argv[]) size_t datalen; struct got_parsed_tree_entry *entries = NULL; size_t nentries = 0, nentries_alloc = 0; + int ch; + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + if (strcasecmp(optarg, "sha1") == 0) + algo = GOT_HASH_SHA1; + else if (strcasecmp(optarg, "sha256") == 0) + algo = GOT_HASH_SHA256; + else + errx(1, "bad hash algorithm %s", optarg); + break; + default: + break; + } + } + + if (algo == GOT_NUM_HASH_ALGOS) + errx(1, "no hash algorithm"); + signal(SIGINT, catch_sigint); if (imsgbuf_init(&ibuf, GOT_IMSG_FD_CHILD) == -1) { blob - 893cec760128eb56a35da1ed5979bc90123183394f4b72253f5472f49379fee1 blob + f09b6e5c89820c56f6536dfcbc48a40a3fecaab702e5fa131efc76570d91f383 --- libexec/got-send-pack/got-send-pack.c +++ libexec/got-send-pack/got-send-pack.c @@ -64,6 +64,7 @@ struct got_object *indexed; static int chattygot; +static enum got_hash_algorithm algo = GOT_NUM_HASH_ALGOS; static const struct got_capability got_capabilities[] = { { GOT_CAPA_AGENT, "got/" GOT_VERSION_STR }, @@ -680,12 +681,30 @@ main(int argc, char **argv) struct got_imsg_send_request send_req; struct got_imsg_send_ref href; size_t datalen, i; + int ch; #if 0 static int attached; while (!attached) sleep (1); #endif + while ((ch = getopt(argc, argv, "A:")) != -1) { + switch (ch) { + case 'A': + if (strcasecmp(optarg, "sha1") == 0) + algo = GOT_HASH_SHA1; + else if (strcasecmp(optarg, "sha256") == 0) + algo = GOT_HASH_SHA256; + else + errx(1, "bad hash algorithm %s", optarg); + break; + default: + break; + } + } + if (algo == GOT_NUM_HASH_ALGOS) + errx(1, "no hash algorithm"); + RB_INIT(&refs); RB_INIT(&delete_refs);