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

Set default pack window size in config #712

Merged
merged 3 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ type Config struct {

// NewConfig returns a new empty Config.
func NewConfig() *Config {
return &Config{
config := &Config{
Remotes: make(map[string]*RemoteConfig),
Submodules: make(map[string]*Submodule),
Raw: format.New(),
}

config.Pack.Window = DefaultPackWindow

return config
}

// Validate validates the fields and sets the default values.
Expand Down Expand Up @@ -97,7 +101,9 @@ const (
worktreeKey = "worktree"
windowKey = "window"

defaultPackWindow = uint(10)
// DefaultPackWindow holds the number of previous objects used to
// generate deltas. The value 10 is the same used by git command.
DefaultPackWindow = uint(10)
)

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

func (c *Config) marshalPack() {
s := c.Raw.Section(packSection)
if c.Pack.Window != defaultPackWindow {
if c.Pack.Window != DefaultPackWindow {
s.SetOption(windowKey, fmt.Sprintf("%d", c.Pack.Window))
}
}
Expand Down
9 changes: 9 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,12 @@ func (s *ConfigSuite) TestRemoteConfigValidateDefault(c *C) {
c.Assert(fetch, HasLen, 1)
c.Assert(fetch[0].String(), Equals, "+refs/heads/*:refs/remotes/foo/*")
}

func (s *ConfigSuite) TestRemoteConfigDefaultValues(c *C) {
config := NewConfig()

c.Assert(config.Remotes, HasLen, 0)
c.Assert(config.Submodules, HasLen, 0)
c.Assert(config.Raw, NotNil)
c.Assert(config.Pack.Window, Equals, DefaultPackWindow)
}