Skip to content

Commit

Permalink
Clean-up and other minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
silphid committed May 18, 2021
1 parent 6379024 commit 5e6b9df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
21 changes: 0 additions & 21 deletions src/internal/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,6 @@ var None = Context{
Mounts: make(map[string]string),
}

// Commented Load because we don't load a context from a file but will read a contextFile to get our Contexts

// Load loads the context from given file
// func Load(file string) (Context, error) {
// var context Context
// if !helpers.PathExists(file) {
// return context, nil
// }

// buf, err := ioutil.ReadFile(file)
// if err != nil {
// return context, fmt.Errorf("loading context file: %w", err)
// }
// err = yaml.Unmarshal(buf, &context)
// if err != nil {
// return context, fmt.Errorf("unmarshalling yaml of context file %q: %w", file, err)
// }

// return context, nil
// }

// Clone returns a deep-copy of this context
func (c Context) Clone() Context {
clone := c
Expand Down
13 changes: 5 additions & 8 deletions src/internal/contextFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,18 @@ func Load(file string) (ContextFile, error) {

// Clone returns a deep-copy of this context
func (cf ContextFile) Clone() ContextFile {
contextFile := ContextFile{
Version: cf.Version,
Parent: cf.Parent,
}
clone := cf
for key, value := range cf.NamedContexts {
contextFile.NamedContexts[key] = value.Clone()
clone.NamedContexts[key] = value.Clone()
}
return contextFile
return clone
}

// Merge creates a deep-copy of this context and copies values from given source context on top of it
func (cf ContextFile) Merge(source ContextFile) ContextFile {
clone := cf.Clone()
if source.Version != 0 {
clone.Version = source.Version
if source.Version != clone.Version {
panic(fmt.Errorf("trying to merge contexts with incompatible versions %d and %d", clone.Version, source.Version))
}
if source.Parent != "" {
clone.Parent = source.Parent
Expand Down

0 comments on commit 5e6b9df

Please sign in to comment.