@@ -11,10 +11,10 @@ import (
11
11
"time"
12
12
13
13
"github.com/adrg/xdg"
14
+ "github.com/jesseduffield/generics/orderedset"
14
15
"github.com/jesseduffield/lazygit/pkg/utils"
15
16
"github.com/jesseduffield/lazygit/pkg/utils/yaml_utils"
16
17
"github.com/samber/lo"
17
- orderedmap "github.com/wk8/go-ordered-map/v2"
18
18
"gopkg.in/yaml.v3"
19
19
)
20
20
@@ -216,12 +216,18 @@ func loadUserConfig(configFiles []*ConfigFile, base *UserConfig, isGuiInitialize
216
216
return base , nil
217
217
}
218
218
219
+ type ChangesSet = orderedset.OrderedSet [string ]
220
+
221
+ func NewChangesSet () * ChangesSet {
222
+ return orderedset .New [string ]()
223
+ }
224
+
219
225
// Do any backward-compatibility migrations of things that have changed in the
220
226
// config over time; examples are renaming a key to a better name, moving a key
221
227
// from one container to another, or changing the type of a key (e.g. from bool
222
228
// to an enum).
223
229
func migrateUserConfig (path string , content []byte , isGuiInitialized bool ) ([]byte , error ) {
224
- changes := orderedmap . New [ string , bool ] ()
230
+ changes := NewChangesSet ()
225
231
226
232
changedContent , didChange , err := computeMigratedConfig (path , content , changes )
227
233
if err != nil {
@@ -234,9 +240,9 @@ func migrateUserConfig(path string, content []byte, isGuiInitialized bool) ([]by
234
240
}
235
241
236
242
changesText := "The following changes were made:\n \n "
237
- for pair := changes .Oldest (); pair != nil ; pair = pair . Next () {
238
- changesText += fmt .Sprintf ("- %s\n " , pair . Key )
239
- }
243
+ changesText += strings . Join ( lo . Map ( changes .ToSliceFromOldest (), func ( change string , _ int ) string {
244
+ return fmt .Sprintf ("- %s\n " , change )
245
+ }), "" )
240
246
241
247
// Write config back
242
248
if ! isGuiInitialized {
@@ -257,7 +263,7 @@ func migrateUserConfig(path string, content []byte, isGuiInitialized bool) ([]by
257
263
}
258
264
259
265
// A pure function helper for testing purposes
260
- func computeMigratedConfig (path string , content []byte , changes * orderedmap. OrderedMap [ string , bool ] ) ([]byte , bool , error ) {
266
+ func computeMigratedConfig (path string , content []byte , changes * ChangesSet ) ([]byte , bool , error ) {
261
267
var err error
262
268
var rootNode yaml.Node
263
269
err = yaml .Unmarshal (content , & rootNode )
@@ -285,7 +291,7 @@ func computeMigratedConfig(path string, content []byte, changes *orderedmap.Orde
285
291
return nil , false , fmt .Errorf ("Couldn't migrate config file at `%s` for key %s: %s" , path , strings .Join (pathToReplace .oldPath , "." ), err )
286
292
}
287
293
if didReplace {
288
- changes .Set (fmt .Sprintf ("Renamed '%s' to '%s'" , strings .Join (pathToReplace .oldPath , "." ), pathToReplace .newName ), true )
294
+ changes .Add (fmt .Sprintf ("Renamed '%s' to '%s'" , strings .Join (pathToReplace .oldPath , "." ), pathToReplace .newName ))
289
295
}
290
296
}
291
297
@@ -327,17 +333,17 @@ func computeMigratedConfig(path string, content []byte, changes *orderedmap.Orde
327
333
return newContent , true , nil
328
334
}
329
335
330
- func changeNullKeybindingsToDisabled (rootNode * yaml.Node , changes * orderedmap. OrderedMap [ string , bool ] ) error {
336
+ func changeNullKeybindingsToDisabled (rootNode * yaml.Node , changes * ChangesSet ) error {
331
337
return yaml_utils .Walk (rootNode , func (node * yaml.Node , path string ) {
332
338
if strings .HasPrefix (path , "keybinding." ) && node .Kind == yaml .ScalarNode && node .Tag == "!!null" {
333
339
node .Value = "<disabled>"
334
340
node .Tag = "!!str"
335
- changes .Set (fmt .Sprintf ("Changed 'null' to '<disabled>' for keybinding '%s'" , path ), true )
341
+ changes .Add (fmt .Sprintf ("Changed 'null' to '<disabled>' for keybinding '%s'" , path ))
336
342
}
337
343
})
338
344
}
339
345
340
- func changeElementToSequence (rootNode * yaml.Node , path []string , changes * orderedmap. OrderedMap [ string , bool ] ) error {
346
+ func changeElementToSequence (rootNode * yaml.Node , path []string , changes * ChangesSet ) error {
341
347
return yaml_utils .TransformNode (rootNode , path , func (node * yaml.Node ) error {
342
348
if node .Kind == yaml .MappingNode {
343
349
nodeContentCopy := node .Content
@@ -349,15 +355,15 @@ func changeElementToSequence(rootNode *yaml.Node, path []string, changes *ordere
349
355
Content : nodeContentCopy ,
350
356
}}
351
357
352
- changes .Set (fmt .Sprintf ("Changed '%s' to an array of strings" , strings .Join (path , "." )), true )
358
+ changes .Add (fmt .Sprintf ("Changed '%s' to an array of strings" , strings .Join (path , "." )))
353
359
354
360
return nil
355
361
}
356
362
return nil
357
363
})
358
364
}
359
365
360
- func changeCommitPrefixesMap (rootNode * yaml.Node , changes * orderedmap. OrderedMap [ string , bool ] ) error {
366
+ func changeCommitPrefixesMap (rootNode * yaml.Node , changes * ChangesSet ) error {
361
367
return yaml_utils .TransformNode (rootNode , []string {"git" , "commitPrefixes" }, func (prefixesNode * yaml.Node ) error {
362
368
if prefixesNode .Kind == yaml .MappingNode {
363
369
for _ , contentNode := range prefixesNode .Content {
@@ -370,15 +376,15 @@ func changeCommitPrefixesMap(rootNode *yaml.Node, changes *orderedmap.OrderedMap
370
376
Kind : yaml .MappingNode ,
371
377
Content : nodeContentCopy ,
372
378
}}
373
- changes .Set ("Changed 'git.commitPrefixes' elements to arrays of strings" , true )
379
+ changes .Add ("Changed 'git.commitPrefixes' elements to arrays of strings" )
374
380
}
375
381
}
376
382
}
377
383
return nil
378
384
})
379
385
}
380
386
381
- func changeCustomCommandStreamAndOutputToOutputEnum (rootNode * yaml.Node , changes * orderedmap. OrderedMap [ string , bool ] ) error {
387
+ func changeCustomCommandStreamAndOutputToOutputEnum (rootNode * yaml.Node , changes * ChangesSet ) error {
382
388
return yaml_utils .Walk (rootNode , func (node * yaml.Node , path string ) {
383
389
// We are being lazy here and rely on the fact that the only mapping
384
390
// nodes in the tree under customCommands are actual custom commands. If
@@ -389,25 +395,25 @@ func changeCustomCommandStreamAndOutputToOutputEnum(rootNode *yaml.Node, changes
389
395
if streamKey , streamValue := yaml_utils .RemoveKey (node , "subprocess" ); streamKey != nil {
390
396
if streamValue .Kind == yaml .ScalarNode && streamValue .Value == "true" {
391
397
output = "terminal"
392
- changes .Set ("Changed 'subprocess: true' to 'output: terminal' in custom command" , true )
398
+ changes .Add ("Changed 'subprocess: true' to 'output: terminal' in custom command" )
393
399
} else {
394
- changes .Set ("Deleted redundant 'subprocess: false' in custom command" , true )
400
+ changes .Add ("Deleted redundant 'subprocess: false' in custom command" )
395
401
}
396
402
}
397
403
if streamKey , streamValue := yaml_utils .RemoveKey (node , "stream" ); streamKey != nil {
398
404
if streamValue .Kind == yaml .ScalarNode && streamValue .Value == "true" && output == "" {
399
405
output = "log"
400
- changes .Set ("Changed 'stream: true' to 'output: log' in custom command" , true )
406
+ changes .Add ("Changed 'stream: true' to 'output: log' in custom command" )
401
407
} else {
402
- changes .Set (fmt .Sprintf ("Deleted redundant 'stream: %v' property in custom command" , streamValue .Value ), true )
408
+ changes .Add (fmt .Sprintf ("Deleted redundant 'stream: %v' property in custom command" , streamValue .Value ))
403
409
}
404
410
}
405
411
if streamKey , streamValue := yaml_utils .RemoveKey (node , "showOutput" ); streamKey != nil {
406
412
if streamValue .Kind == yaml .ScalarNode && streamValue .Value == "true" && output == "" {
407
- changes .Set ("Changed 'showOutput: true' to 'output: popup' in custom command" , true )
413
+ changes .Add ("Changed 'showOutput: true' to 'output: popup' in custom command" )
408
414
output = "popup"
409
415
} else {
410
- changes .Set (fmt .Sprintf ("Deleted redundant 'showOutput: %v' property in custom command" , streamValue .Value ), true )
416
+ changes .Add (fmt .Sprintf ("Deleted redundant 'showOutput: %v' property in custom command" , streamValue .Value ))
411
417
}
412
418
}
413
419
if output != "" {
@@ -431,7 +437,7 @@ func changeCustomCommandStreamAndOutputToOutputEnum(rootNode *yaml.Node, changes
431
437
// a single element at `allBranchesLogCmd` and the sequence at `allBranchesLogCmds`.
432
438
// Some users have explicitly set `allBranchesLogCmd` to be an empty string in order
433
439
// to remove it, so in that case we just delete the element, and add nothing to the list
434
- func migrateAllBranchesLogCmd (rootNode * yaml.Node , changes * orderedmap. OrderedMap [ string , bool ] ) error {
440
+ func migrateAllBranchesLogCmd (rootNode * yaml.Node , changes * ChangesSet ) error {
435
441
return yaml_utils .TransformNode (rootNode , []string {"git" }, func (gitNode * yaml.Node ) error {
436
442
cmdKeyNode , cmdValueNode := yaml_utils .LookupKey (gitNode , "allBranchesLogCmd" )
437
443
// Nothing to do if they do not have the deprecated item
@@ -462,12 +468,12 @@ func migrateAllBranchesLogCmd(rootNode *yaml.Node, changes *orderedmap.OrderedMa
462
468
if cmdValueNode .Value != "" {
463
469
// Prepending the individual element to make it show up first in the list, which was prior behavior
464
470
cmdsValueNode .Content = utils .Prepend (cmdsValueNode .Content , & yaml.Node {Kind : yaml .ScalarNode , Value : cmdValueNode .Value })
465
- changes .Set (change , true )
471
+ changes .Add (change )
466
472
}
467
473
468
474
// Clear out the existing allBranchesLogCmd, now that we have migrated it into the list
469
475
_ , _ = yaml_utils .RemoveKey (gitNode , "allBranchesLogCmd" )
470
- changes .Set ("Removed obsolete git.allBranchesLogCmd" , true )
476
+ changes .Add ("Removed obsolete git.allBranchesLogCmd" )
471
477
472
478
return nil
473
479
})
0 commit comments