diff options
author | Glen Choo <chooglen@google.com> | 2021-11-18 03:53:25 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-11-19 09:31:19 +0300 |
commit | 4a2dcb1a08008bfc48c32f408e8622bd0c4ca297 (patch) | |
tree | 3b9fe61405a94eae100acc8bc3cb79b55dada96a /remote.h | |
parent | 56eed3422cb4605a616daab589b94a843a75651f (diff) |
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>
Diffstat (limited to 'remote.h')
-rw-r--r-- | remote.h | 5 |
1 files changed, 2 insertions, 3 deletions
@@ -43,9 +43,7 @@ struct remote_state { int remotes_nr; struct hashmap remotes_hash; - struct branch **branches; - int branches_alloc; - int branches_nr; + struct hashmap branches_hash; struct branch *current_branch; const char *pushremote_name; @@ -292,6 +290,7 @@ int remote_find_tracking(struct remote *remote, struct refspec_item *refspec); * branch_get(name) for "refs/heads/{name}", or with branch_get(NULL) for HEAD. */ struct branch { + struct hashmap_entry ent; /* The short name of the branch. */ const char *name; |