remote: die if branch is not found in repository
commit4a2dcb1a08008bfc48c32f408e8622bd0c4ca297
authorGlen Choo <chooglen@google.com>
Thu, 18 Nov 2021 00:53:25 +0000 (17 16:53 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Nov 2021 06:31:19 +0000 (18 22:31 -0800)
tree3b9fe61405a94eae100acc8bc3cb79b55dada96a
parent56eed3422cb4605a616daab589b94a843a75651f
remote: die if branch is not found in repository

In a subsequent commit, we would like external-facing functions to be
able to accept "struct repository" and "struct branch" as a pair. This
is useful for functions like pushremote_for_branch(), which need to take
values from the remote_state and branch, even if branch == NULL.
However, a caller may supply an unrelated repository and branch, which
is not supported behavior.

To prevent misuse, add a die_on_missing_branch() helper function that
dies if a given branch is not from a given repository. Speed up the
existence check by replacing the branches list with a branches_hash
hashmap.

Like read_config(), die_on_missing_branch() is only called from
non-static functions; static functions are less prone to misuse because
they have strong conventions for keeping remote_state and branch in
sync.

Signed-off-by: Glen Choo <chooglen@google.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c
remote.h