github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libgit/ephemeral_git_config_with_fixed_pack_window.go (about)

     1  // Copyright 2017 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package libgit
     6  
     7  import (
     8  	"io"
     9  	"time"
    10  
    11  	gogitcfg "gopkg.in/src-d/go-git.v4/config"
    12  	"gopkg.in/src-d/go-git.v4/plumbing"
    13  	"gopkg.in/src-d/go-git.v4/plumbing/storer"
    14  	"gopkg.in/src-d/go-git.v4/storage"
    15  )
    16  
    17  // ephemeralGitConfigWithFixedPackWindow always returns a fixed pack
    18  // window, regardless of what the underlying storage says.  It also
    19  // never persists any config changes to storage.
    20  type ephemeralGitConfigWithFixedPackWindow struct {
    21  	storage.Storer
    22  	initer     storer.Initializer
    23  	pfWriter   storer.PackfileWriter
    24  	los        storer.LooseObjectStorer
    25  	pos        storer.PackedObjectStorer
    26  	packWindow uint
    27  }
    28  
    29  // Init implements the `storer.Initializer` interface.
    30  func (e *ephemeralGitConfigWithFixedPackWindow) Init() error {
    31  	return e.initer.Init()
    32  }
    33  
    34  // PackfileWriter implements the `storer.PackfileWriter` interface.
    35  func (e *ephemeralGitConfigWithFixedPackWindow) PackfileWriter(
    36  	ch plumbing.StatusChan) (io.WriteCloser, error) {
    37  	return e.pfWriter.PackfileWriter(ch)
    38  }
    39  
    40  // Config implements the `storer.Storer` interface.
    41  func (e *ephemeralGitConfigWithFixedPackWindow) Config() (
    42  	*gogitcfg.Config, error) {
    43  	cfg, err := e.Storer.Config()
    44  	if err != nil {
    45  		return nil, err
    46  	}
    47  	cfg.Pack.Window = e.packWindow
    48  	return cfg, nil
    49  }
    50  
    51  // SetConfig implements the `storer.Storer` interface.
    52  func (e *ephemeralGitConfigWithFixedPackWindow) SetConfig(c *gogitcfg.Config) (
    53  	err error) {
    54  	// The config is "ephemeral", so don't persist any config
    55  	// changes to storage.
    56  	return nil
    57  }
    58  
    59  // ForEachObjectHash implements the `storer.LooseObjectStorer` interface.
    60  func (e *ephemeralGitConfigWithFixedPackWindow) ForEachObjectHash(
    61  	f func(plumbing.Hash) error) error {
    62  	return e.los.ForEachObjectHash(f)
    63  }
    64  
    65  // LooseObjectHash implements the `storer.LooseObjectStorer` interface.
    66  func (e *ephemeralGitConfigWithFixedPackWindow) LooseObjectTime(
    67  	h plumbing.Hash) (time.Time, error) {
    68  	return e.los.LooseObjectTime(h)
    69  }
    70  
    71  // DeleteLooseObject implements the `storer.LooseObjectStorer` interface.
    72  func (e *ephemeralGitConfigWithFixedPackWindow) DeleteLooseObject(
    73  	h plumbing.Hash) error {
    74  	return e.los.DeleteLooseObject(h)
    75  }
    76  
    77  // ObjectPacks implements the `storer.PackedObjectStorer` interface.
    78  func (e *ephemeralGitConfigWithFixedPackWindow) ObjectPacks() (
    79  	[]plumbing.Hash, error) {
    80  	return e.pos.ObjectPacks()
    81  }
    82  
    83  // DeleteOldObjectPackAndIndex implements the
    84  // `storer.PackedObjectStorer` interface.
    85  func (e *ephemeralGitConfigWithFixedPackWindow) DeleteOldObjectPackAndIndex(
    86  	h plumbing.Hash, t time.Time) error {
    87  	return e.pos.DeleteOldObjectPackAndIndex(h, t)
    88  }
    89  
    90  var _ storage.Storer = (*ephemeralGitConfigWithFixedPackWindow)(nil)
    91  var _ storer.Initializer = (*ephemeralGitConfigWithFixedPackWindow)(nil)
    92  var _ storer.PackfileWriter = (*ephemeralGitConfigWithFixedPackWindow)(nil)
    93  var _ storer.LooseObjectStorer = (*ephemeralGitConfigWithFixedPackWindow)(nil)
    94  var _ storer.PackedObjectStorer = (*ephemeralGitConfigWithFixedPackWindow)(nil)