Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 777dcd5

Browse files
authored
Merge pull request #334 from taralx/rawConfig
Export raw config
2 parents 48dec88 + fef4594 commit 777dcd5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

config/config.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ type Config struct {
4646
// of the submodule, should equal to Submodule.Name.
4747
Submodules map[string]*Submodule
4848

49-
// contains the raw information of a config file, the main goal is preserve
50-
// the parsed information from the original format, to avoid missing
51-
// unsupported features.
52-
raw *format.Config
49+
// Raw contains the raw information of a config file. The main goal is
50+
// preserve the parsed information from the original format, to avoid
51+
// dropping unsupported fields.
52+
Raw *format.Config
5353
}
5454

5555
// NewConfig returns a new empty Config.
5656
func NewConfig() *Config {
5757
return &Config{
5858
Remotes: make(map[string]*RemoteConfig, 0),
5959
Submodules: make(map[string]*Submodule, 0),
60-
raw: format.New(),
60+
Raw: format.New(),
6161
}
6262
}
6363

@@ -91,8 +91,8 @@ func (c *Config) Unmarshal(b []byte) error {
9191
r := bytes.NewBuffer(b)
9292
d := format.NewDecoder(r)
9393

94-
c.raw = format.New()
95-
if err := d.Decode(c.raw); err != nil {
94+
c.Raw = format.New()
95+
if err := d.Decode(c.Raw); err != nil {
9696
return err
9797
}
9898

@@ -102,7 +102,7 @@ func (c *Config) Unmarshal(b []byte) error {
102102
}
103103

104104
func (c *Config) unmarshalCore() {
105-
s := c.raw.Section(coreSection)
105+
s := c.Raw.Section(coreSection)
106106
if s.Options.Get(bareKey) == "true" {
107107
c.Core.IsBare = true
108108
}
@@ -111,7 +111,7 @@ func (c *Config) unmarshalCore() {
111111
}
112112

113113
func (c *Config) unmarshalRemotes() error {
114-
s := c.raw.Section(remoteSection)
114+
s := c.Raw.Section(remoteSection)
115115
for _, sub := range s.Subsections {
116116
r := &RemoteConfig{}
117117
if err := r.unmarshal(sub); err != nil {
@@ -125,7 +125,7 @@ func (c *Config) unmarshalRemotes() error {
125125
}
126126

127127
func (c *Config) unmarshalSubmodules() {
128-
s := c.raw.Section(submoduleSection)
128+
s := c.Raw.Section(submoduleSection)
129129
for _, sub := range s.Subsections {
130130
m := &Submodule{}
131131
m.unmarshal(sub)
@@ -141,15 +141,15 @@ func (c *Config) Marshal() ([]byte, error) {
141141
c.marshalSubmodules()
142142

143143
buf := bytes.NewBuffer(nil)
144-
if err := format.NewEncoder(buf).Encode(c.raw); err != nil {
144+
if err := format.NewEncoder(buf).Encode(c.Raw); err != nil {
145145
return nil, err
146146
}
147147

148148
return buf.Bytes(), nil
149149
}
150150

151151
func (c *Config) marshalCore() {
152-
s := c.raw.Section(coreSection)
152+
s := c.Raw.Section(coreSection)
153153
s.SetOption(bareKey, fmt.Sprintf("%t", c.Core.IsBare))
154154

155155
if c.Core.Worktree != "" {
@@ -158,7 +158,7 @@ func (c *Config) marshalCore() {
158158
}
159159

160160
func (c *Config) marshalRemotes() {
161-
s := c.raw.Section(remoteSection)
161+
s := c.Raw.Section(remoteSection)
162162
s.Subsections = make(format.Subsections, len(c.Remotes))
163163

164164
var i int
@@ -169,7 +169,7 @@ func (c *Config) marshalRemotes() {
169169
}
170170

171171
func (c *Config) marshalSubmodules() {
172-
s := c.raw.Section(submoduleSection)
172+
s := c.Raw.Section(submoduleSection)
173173
s.Subsections = make(format.Subsections, len(c.Submodules))
174174

175175
var i int

0 commit comments

Comments
 (0)