@@ -13,24 +13,37 @@ const (
1313)
1414
1515// NewDiffFormat returns a format for use with a diff Context
16+ //
17+ // Deprecated: this function was only used internally and will be removed in the next release.
1618func NewDiffFormat (source string ) formatter.Format {
19+ return newDiffFormat (source )
20+ }
21+
22+ // newDiffFormat returns a format for use with a diff [formatter.Context].
23+ func newDiffFormat (source string ) formatter.Format {
1724 if source == formatter .TableFormatKey {
1825 return defaultDiffTableFormat
1926 }
2027 return formatter .Format (source )
2128}
2229
2330// DiffFormatWrite writes formatted diff using the Context
24- func DiffFormatWrite (ctx formatter.Context , changes []container.FilesystemChange ) error {
25- render := func (format func (subContext formatter.SubContext ) error ) error {
31+ //
32+ // Deprecated: this function was only used internally and will be removed in the next release.
33+ func DiffFormatWrite (fmtCtx formatter.Context , changes []container.FilesystemChange ) error {
34+ return diffFormatWrite (fmtCtx , changes )
35+ }
36+
37+ // diffFormatWrite writes formatted diff using the [formatter.Context].
38+ func diffFormatWrite (fmtCtx formatter.Context , changes []container.FilesystemChange ) error {
39+ return fmtCtx .Write (newDiffContext (), func (format func (subContext formatter.SubContext ) error ) error {
2640 for _ , change := range changes {
2741 if err := format (& diffContext {c : change }); err != nil {
2842 return err
2943 }
3044 }
3145 return nil
32- }
33- return ctx .Write (newDiffContext (), render )
46+ })
3447}
3548
3649type diffContext struct {
@@ -39,12 +52,14 @@ type diffContext struct {
3952}
4053
4154func newDiffContext () * diffContext {
42- diffCtx := diffContext {}
43- diffCtx .Header = formatter.SubHeaderContext {
44- "Type" : changeTypeHeader ,
45- "Path" : pathHeader ,
55+ return & diffContext {
56+ HeaderContext : formatter.HeaderContext {
57+ Header : formatter.SubHeaderContext {
58+ "Type" : changeTypeHeader ,
59+ "Path" : pathHeader ,
60+ },
61+ },
4662 }
47- return & diffCtx
4863}
4964
5065func (d * diffContext ) MarshalJSON () ([]byte , error ) {
0 commit comments