Skip to content

Commit

Permalink
Added support for multiple PatchGroups per patch (closes #25)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Jul 17, 2019
1 parent a7411a2 commit cf8adbf
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions patchfile/kobopatch/kobopatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type PatchSet struct {
type parsedPatch struct {
Enabled bool
Description string
PatchGroup *string
PatchGroups []string
Instructions []*parsedInstruction
}

Expand Down Expand Up @@ -80,11 +80,8 @@ func Parse(buf []byte) (patchfile.PatchSet, error) {
}
ps.parsed[name].Description = string(sinst.(Description))
case PatchGroup:
if ps.parsed[name].PatchGroup != nil {
return nil, errors.Errorf("patch %#v: line %d: instruction %d: duplicate PatchGroup instruction", name, instNode.Line(node.Line), i+1)
}
g := string(sinst.(PatchGroup))
ps.parsed[name].PatchGroup = &g
ps.parsed[name].PatchGroups = append(ps.parsed[name].PatchGroups, g)
default:
patchfile.Log(" converting to PatchableInstruction\n")
if psinst, ok := sinst.(PatchableInstruction); ok {
Expand Down Expand Up @@ -168,11 +165,18 @@ func (ps *PatchSet) Validate() error {
for _, name := range ps.SortedNames() {
patch := ps.parsed[name]

if patch.PatchGroup != nil && patch.Enabled {
if r, ok := usedPatchGroups[*patch.PatchGroup]; ok {
return errors.Errorf("patch %#v: more than one patch enabled in PatchGroup %#v (other patch is %#v)", name, *patch.PatchGroup, r)
seenPatchGroups := map[string]bool{}
for _, g := range patch.PatchGroups {
if seenPatchGroups[g] {
return errors.Errorf("patch %#v: duplicate PatchGroup instruction for PatchGroup %#v", name, g)
}
seenPatchGroups[g] = true
if patch.Enabled {
if r, ok := usedPatchGroups[g]; ok {
return errors.Errorf("patch %#v: more than one patch enabled in PatchGroup %#v (other patch is %#v)", name, g, r)
}
usedPatchGroups[g] = name
}
usedPatchGroups[*patch.PatchGroup] = name
}

if len(patch.Instructions) == 0 {
Expand Down

0 comments on commit cf8adbf

Please sign in to comment.