MCPcopy Index your code
hub / github.com/jetify-com/devbox / setPatch

Method setPatch

internal/devconfig/configfile/ast.go:250–283  ·  view source on GitHub ↗

setPatch sets the patch field of the named package.

(name string, mode PatchMode)

Source from the content-addressed store, hash-verified

248
249// setPatch sets the patch field of the named package.
250func (c *configAST) setPatch(name string, mode PatchMode) {
251 pkgObject := c.findPkgObject(name)
252 if pkgObject == nil {
253 return
254 }
255
256 glibcIndex := c.memberIndex(pkgObject, "patch_glibc") // deprecated
257 patchIndex := c.memberIndex(pkgObject, "patch")
258 switch {
259 // Neither patch_glibc or patch exist - append a new field.
260 case patchIndex == -1 && glibcIndex == -1:
261 pkgObject.Members = append(pkgObject.Members, hujson.ObjectMember{
262 Name: hujson.Value{
263 BeforeExtra: []byte{'\n'},
264 },
265 })
266 patchIndex = len(pkgObject.Members) - 1
267 defer c.root.Format()
268 // patch_glibc exists and patch doesn't - rename patch_glibc to
269 // preserve formatting/comments.
270 case patchIndex == -1 && glibcIndex != -1:
271 patchIndex = glibcIndex
272 // Both patch_glibc and patch exist - delete patch_glibc.
273 case patchIndex != -1 && glibcIndex != -1:
274 pkgObject.Members = slices.Delete(pkgObject.Members, glibcIndex, glibcIndex+1)
275 if patchIndex > glibcIndex {
276 patchIndex--
277 }
278 defer c.root.Format()
279 }
280
281 pkgObject.Members[patchIndex].Name.Value = hujson.String("patch")
282 pkgObject.Members[patchIndex].Value.Value = hujson.String(string(mode))
283}
284
285func (c *configAST) findPkgObject(name string) *hujson.Object {
286 pkgs := c.packagesField(true).Value.Value.(*hujson.Object)

Callers 1

SetPatchMethod · 0.80

Calls 4

findPkgObjectMethod · 0.95
memberIndexMethod · 0.95
FormatMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected