diff options
-rw-r--r-- | config/config.go | 14 | ||||
-rw-r--r-- | config/config_test.go | 9 | ||||
-rw-r--r-- | plumbing/format/packfile/delta_selector.go | 32 |
3 files changed, 38 insertions, 17 deletions
diff --git a/config/config.go b/config/config.go index fc4cd28..87a847d 100644 --- a/config/config.go +++ b/config/config.go @@ -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. @@ -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. @@ -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 { @@ -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)) } } diff --git a/config/config_test.go b/config/config_test.go index 019cee6..1f120c0 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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) +} diff --git a/plumbing/format/packfile/delta_selector.go b/plumbing/format/packfile/delta_selector.go index 8792574..cd38c16 100644 --- a/plumbing/format/packfile/delta_selector.go +++ b/plumbing/format/packfile/delta_selector.go @@ -222,10 +222,16 @@ func (dw *deltaSelector) walk( ) error { indexMap := make(map[plumbing.Hash]*deltaIndex) for i := 0; i < len(objectsToPack); i++ { - // Clean up the index map for anything outside our pack - // window, to save memory. + // Clean up the index map and reconstructed delta objects for anything + // outside our pack window, to save memory. if i > int(packWindow) { - delete(indexMap, objectsToPack[i-int(packWindow)].Hash()) + obj := objectsToPack[i-int(packWindow)] + + delete(indexMap, obj.Hash()) + + if obj.IsDelta() { + obj.Original = nil + } } target := objectsToPack[i] @@ -261,6 +267,16 @@ func (dw *deltaSelector) walk( } func (dw *deltaSelector) tryToDeltify(indexMap map[plumbing.Hash]*deltaIndex, base, target *ObjectToPack) error { + // Original object might not be present if we're reusing a delta, so we + // ensure it is restored. + if err := dw.restoreOriginal(target); err != nil { + return err + } + + if err := dw.restoreOriginal(base); err != nil { + return err + } + // If the sizes are radically different, this is a bad pairing. if target.Size() < base.Size()>>4 { return nil @@ -283,16 +299,6 @@ func (dw *deltaSelector) tryToDeltify(indexMap map[plumbing.Hash]*deltaIndex, ba return nil } - // Original object might not be present if we're reusing a delta, so we - // ensure it is restored. - if err := dw.restoreOriginal(target); err != nil { - return err - } - - if err := dw.restoreOriginal(base); err != nil { - return err - } - if _, ok := indexMap[base.Hash()]; !ok { indexMap[base.Hash()] = new(deltaIndex) } |