From: Jonathan Tan Date: Mon, 15 Nov 2021 18:50:29 GMT Subject: Re: [PATCH v4 5/6] remote: die if branch is not found in repository Message-ID: <20211115185029.1081720-1-jonathantanmy@google.com> In-Reply-To: <20211028183101.41013-6-chooglen@google.com> > 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 using a new branches_hash hashmap to remote_state, > and use the hashmap to remove the branch array iteration in > make_branch(). > > 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. This makes sense, but how often would this be called? Couldn't we just iterate over the array (instead of making a hashmap)? If speed is important, I think we could just sort the array and do a binary search.