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

Commit 2547d1d

Browse files
authored
Merge pull request #712 from jfontan/fix/set-default-window-size
Set default pack window size in config
2 parents bf3b1f1 + a4ea96f commit 2547d1d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

config/config.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ type Config struct {
6464

6565
// NewConfig returns a new empty Config.
6666
func NewConfig() *Config {
67-
return &Config{
67+
config := &Config{
6868
Remotes: make(map[string]*RemoteConfig),
6969
Submodules: make(map[string]*Submodule),
7070
Raw: format.New(),
7171
}
72+
73+
config.Pack.Window = DefaultPackWindow
74+
75+
return config
7276
}
7377

7478
// Validate validates the fields and sets the default values.
@@ -97,7 +101,9 @@ const (
97101
worktreeKey = "worktree"
98102
windowKey = "window"
99103

100-
defaultPackWindow = uint(10)
104+
// DefaultPackWindow holds the number of previous objects used to
105+
// generate deltas. The value 10 is the same used by git command.
106+
DefaultPackWindow = uint(10)
101107
)
102108

103109
// Unmarshal parses a git-config file and stores it.
@@ -131,7 +137,7 @@ func (c *Config) unmarshalPack() error {
131137
s := c.Raw.Section(packSection)
132138
window := s.Options.Get(windowKey)
133139
if window == "" {
134-
c.Pack.Window = defaultPackWindow
140+
c.Pack.Window = DefaultPackWindow
135141
} else {
136142
winUint, err := strconv.ParseUint(window, 10, 32)
137143
if err != nil {
@@ -192,7 +198,7 @@ func (c *Config) marshalCore() {
192198

193199
func (c *Config) marshalPack() {
194200
s := c.Raw.Section(packSection)
195-
if c.Pack.Window != defaultPackWindow {
201+
if c.Pack.Window != DefaultPackWindow {
196202
s.SetOption(windowKey, fmt.Sprintf("%d", c.Pack.Window))
197203
}
198204
}

config/config_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,12 @@ func (s *ConfigSuite) TestRemoteConfigValidateDefault(c *C) {
156156
c.Assert(fetch, HasLen, 1)
157157
c.Assert(fetch[0].String(), Equals, "+refs/heads/*:refs/remotes/foo/*")
158158
}
159+
160+
func (s *ConfigSuite) TestRemoteConfigDefaultValues(c *C) {
161+
config := NewConfig()
162+
163+
c.Assert(config.Remotes, HasLen, 0)
164+
c.Assert(config.Submodules, HasLen, 0)
165+
c.Assert(config.Raw, NotNil)
166+
c.Assert(config.Pack.Window, Equals, DefaultPackWindow)
167+
}

0 commit comments

Comments
 (0)