commit 0dd7613ce65424868ec86f0623e38eb70d9a9321 from: Mark Jamsek date: Mon Feb 13 13:20:54 2023 UTC special case 'got fetch -b ' to only fetch As discussed on irc, this drops the implicit remote HEAD fetch when -b is used. got.1 has been updated to make the new fetch behaviour clear. ok stsp@ commit - 7b771fb638e62245e029bcceaa32c0dce315b23c commit + 0dd7613ce65424868ec86f0623e38eb70d9a9321 blob - d3ce58fd68ab0a1ef9be75ee3b113fb0080db8db blob + e074f7da3728404dc7163c7f239e256bf44a522c --- got/got.1 +++ got/got.1 @@ -354,15 +354,15 @@ If .Cm got fetch is invoked in a work tree then this work tree's current branch will be fetched, too, provided it is present on the server. +If no branches to fetch can be found in +.Xr got.conf 5 +or via a work tree, or said branches are not found on the server, a branch +resolved via the remote repository's HEAD reference will be fetched. This default behaviour can be overridden with the .Fl a and .Fl b options. -If no branches to fetch can be found in -.Xr got.conf 5 , -on the command line, or via a work tree, a branch resolved via the remote -repository's HEAD reference will be fetched. .Pp New changes will be stored in a separate pack file downloaded from the server. Optionally, separate pack files stored in the repository can be combined with blob - 127b86675c2322fd21f0849b2a7f9df339621c75 blob + 2c1701bd7583e22c83fc62c3bfca5fb2a5492585 --- got/got.c +++ got/got.c @@ -1716,7 +1716,7 @@ cmd_clone(int argc, char *argv[]) error = got_fetch_pack(&pack_hash, &refs, &symrefs, GOT_FETCH_DEFAULT_REMOTE_NAME, mirror_references, fetch_all_branches, &wanted_branches, &wanted_refs, - list_refs_only, verbosity, fetchfd, repo, NULL, + list_refs_only, verbosity, fetchfd, repo, NULL, 0, fetch_progress, &fpa); if (error) goto done; @@ -2546,10 +2546,11 @@ cmd_fetch(int argc, char *argv[]) fpa.create_configs = 0; fpa.configs_created = 0; memset(&fpa.config_info, 0, sizeof(fpa.config_info)); + error = got_fetch_pack(&pack_hash, &refs, &symrefs, remote->name, remote->mirror_references, fetch_all_branches, &wanted_branches, &wanted_refs, list_refs_only, verbosity, fetchfd, repo, - worktree_branch, fetch_progress, &fpa); + worktree_branch, have_bflag, fetch_progress, &fpa); if (error) goto done; blob - 5703d1fbe97e2c2bfcb5c6c2095c9653f5ee5e6e blob + 5768c9157c81ca12b00f65491c540dd712c37e6a --- include/got_fetch.h +++ include/got_fetch.h @@ -46,5 +46,5 @@ typedef const struct got_error *(*got_fetch_progress_c const struct got_error *got_fetch_pack(struct got_object_id **, struct got_pathlist_head *, struct got_pathlist_head *, const char *, int, int, struct got_pathlist_head *, struct got_pathlist_head *, - int, int, int, struct got_repository *, const char *, + int, int, int, struct got_repository *, const char *, int, got_fetch_progress_cb, void *); blob - bfa126b8fabcca280af94961030dcae5aae3e6e6 blob + e37808ed2a0bf37771cbf76e39cfa92b60ad43cc --- lib/fetch.c +++ lib/fetch.c @@ -105,7 +105,7 @@ got_fetch_pack(struct got_object_id **pack_hash, struc struct got_pathlist_head *wanted_branches, struct got_pathlist_head *wanted_refs, int list_refs_only, int verbosity, int fetchfd, struct got_repository *repo, const char *worktree_refname, - got_fetch_progress_cb progress_cb, void *progress_arg) + int no_head, got_fetch_progress_cb progress_cb, void *progress_arg) { size_t i; int imsg_fetchfds[2], imsg_idxfds[2]; @@ -261,7 +261,7 @@ got_fetch_pack(struct got_object_id **pack_hash, struc } err = got_privsep_send_fetch_req(&fetchibuf, nfetchfd, &have_refs, fetch_all_branches, wanted_branches, wanted_refs, - list_refs_only, worktree_refname, verbosity); + list_refs_only, worktree_refname, no_head, verbosity); if (err != NULL) goto done; nfetchfd = -1; blob - 09e7cb7ce6e9cf826f667d69280ad2dab4b4d161 blob + b8170cb9afee37b2625c705535e43662ca7dd06c --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -404,6 +404,7 @@ struct got_imsg_fetch_wanted_ref { /* Structure for GOT_IMSG_FETCH_REQUEST data. */ struct got_imsg_fetch_request { + int no_head; int fetch_all_branches; int list_refs_only; int verbosity; @@ -700,7 +701,7 @@ const struct got_error *got_privsep_recv_index_progres int *, int *, struct imsgbuf *ibuf); const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int, struct got_pathlist_head *, int, struct got_pathlist_head *, - struct got_pathlist_head *, int, const char *, int); + struct got_pathlist_head *, int, const char *, int, int); const struct got_error *got_privsep_send_fetch_outfd(struct imsgbuf *, int); const struct got_error *got_privsep_recv_fetch_progress(int *, struct got_object_id **, char **, struct got_pathlist_head *, char **, blob - 8954b4c42e443bbd5ba01b707de2fd26e6410d19 blob + 45186fa65020450414f58d1089a1b4ee158eeff9 --- lib/privsep.c +++ lib/privsep.c @@ -532,7 +532,7 @@ got_privsep_send_fetch_req(struct imsgbuf *ibuf, int f struct got_pathlist_head *have_refs, int fetch_all_branches, struct got_pathlist_head *wanted_branches, struct got_pathlist_head *wanted_refs, int list_refs_only, - const char *worktree_branch, int verbosity) + const char *worktree_branch, int no_head, int verbosity) { const struct got_error *err = NULL; struct ibuf *wbuf; @@ -556,6 +556,7 @@ got_privsep_send_fetch_req(struct imsgbuf *ibuf, int f return got_error_from_errno("imsg_create FETCH_HAVE_REF"); memset(&fetchreq, 0, sizeof(fetchreq)); + fetchreq.no_head = no_head; fetchreq.fetch_all_branches = fetch_all_branches; fetchreq.list_refs_only = list_refs_only; fetchreq.verbosity = verbosity; blob - f21581a8de91fa478a72e20f422c81a342ce59e8 blob + c8d35d7046be5e229cbdc28ec23f311320cfef70 --- libexec/got-fetch-pack/got-fetch-pack.c +++ libexec/got-fetch-pack/got-fetch-pack.c @@ -333,7 +333,7 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1, struct got_pathlist_head *have_refs, int fetch_all_branches, struct got_pathlist_head *wanted_branches, struct got_pathlist_head *wanted_refs, int list_refs_only, - const char *worktree_branch, struct imsgbuf *ibuf) + const char *worktree_branch, int no_head, struct imsgbuf *ibuf) { const struct got_error *err = NULL; char buf[GOT_PKT_MAX]; @@ -501,7 +501,7 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1, if (list_refs_only) goto done; - if (!found_branch && default_branch && default_id_str && + if (!found_branch && !no_head && default_branch && default_id_str && strncmp(default_branch, "refs/heads/", 11) == 0) { err = fetch_ref(ibuf, have_refs, &have[nref], &want[nref], default_branch, default_id_str); @@ -1026,7 +1026,7 @@ main(int argc, char **argv) err = fetch_pack(fetchfd, packfd, pack_sha1, &have_refs, fetch_req.fetch_all_branches, &wanted_branches, &wanted_refs, fetch_req.list_refs_only, - worktree_branch, &ibuf); + worktree_branch, fetch_req.no_head, &ibuf); done: free(worktree_branch); got_pathlist_free(&have_refs, GOT_PATHLIST_FREE_ALL);