github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/env/remotes.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package env 16 17 import ( 18 "context" 19 20 "github.com/dolthub/dolt/go/libraries/doltcore/dbfactory" 21 "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" 22 "github.com/dolthub/dolt/go/store/types" 23 ) 24 25 var NoRemote = Remote{} 26 27 func IsEmptyRemote(r Remote) bool { 28 return len(r.Name) == 0 && len(r.Url) == 0 && r.FetchSpecs == nil && r.Params == nil 29 } 30 31 type Remote struct { 32 Name string `json:"name"` 33 Url string `json:"url"` 34 FetchSpecs []string `json:"fetch_specs"` 35 Params map[string]string `json:"params"` 36 } 37 38 func NewRemote(name, url string, params map[string]string) Remote { 39 return Remote{name, url, []string{"refs/heads/*:refs/remotes/" + name + "/*"}, params} 40 } 41 42 func (r *Remote) GetParam(pName string) (string, bool) { 43 val, ok := r.Params[pName] 44 return val, ok 45 } 46 47 func (r *Remote) GetParamOrDefault(pName, defVal string) string { 48 val, ok := r.Params[pName] 49 50 if !ok { 51 return defVal 52 } 53 54 return val 55 } 56 57 func (r *Remote) GetRemoteDB(ctx context.Context, nbf *types.NomsBinFormat) (*doltdb.DoltDB, error) { 58 return doltdb.LoadDoltDBWithParams(ctx, nbf, r.Url, r.Params) 59 } 60 61 func (r *Remote) GetRemoteDBWithoutCaching(ctx context.Context, nbf *types.NomsBinFormat) (*doltdb.DoltDB, error) { 62 params := make(map[string]string) 63 for k, v := range r.Params { 64 params[k] = v 65 } 66 params[dbfactory.NoCachingParameter] = "true" 67 return doltdb.LoadDoltDBWithParams(ctx, nbf, r.Url, params) 68 }