Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlen Choo <chooglen@google.com>2021-11-18 03:53:25 +0300
committerJunio C Hamano <gitster@pobox.com>2021-11-19 09:31:19 +0300
commit4a2dcb1a08008bfc48c32f408e8622bd0c4ca297 (patch)
tree3b9fe61405a94eae100acc8bc3cb79b55dada96a /remote.h
parent56eed3422cb4605a616daab589b94a843a75651f (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.h5
1 files changed, 2 insertions, 3 deletions
diff --git a/remote.h b/remote.h
index 85a730b8ef..4a1209ae2c 100644
--- a/remote.h
+++ b/remote.h
@@ -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;