git: allow validating remote from a cached list

Right now, every time we call `ValidateRemote`, we look up the list of
remotes by invoking `git remote`.  It would be nice if we could cache
the list of remotes so we could validate the remote multiple times
without the expense of calling Git multiple times, so let's add a
function, `ValidateRemoteFromList`, which can take a cached list and
perform the same computation.
This commit is contained in:
brian m. carlson 2023-10-26 18:42:21 +00:00
parent 3c353fb3e5
commit d2cdff0d68
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1

@ -531,13 +531,20 @@ func ValidateRemote(remote string) error {
if err != nil {
return err
}
return ValidateRemoteFromList(remotes, remote)
}
// ValidateRemote checks that a named remote is valid for use given a list from
// RemoteList. This is completely identical to ValidateRemote, except that it
// allows caching the remote list.
func ValidateRemoteFromList(remotes []string, remote string) error {
for _, r := range remotes {
if r == remote {
return nil
}
}
if err = ValidateRemoteURL(remote); err == nil {
if err := ValidateRemoteURL(remote); err == nil {
return nil
}