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

RFC: provide insight into the status of gogit #570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ type FetchOptions struct {
Progress sideband.Progress
// Tags describe how the tags will be fetched from the remote repository,
// by default is TagFollowing.
Tags TagFetchMode
Tags TagFetchMode
StatusChan plumbing.StatusChan
}

// Validate validates the fields and sets the default values.
Expand All @@ -159,7 +160,8 @@ type PushOptions struct {
// object. A refspec with empty src can be used to delete a reference.
RefSpecs []config.RefSpec
// Auth credentials, if required, to use with the remote repository.
Auth transport.AuthMethod
Auth transport.AuthMethod
StatusChan plumbing.StatusChan
}

// Validate validates the fields and sets the default values.
Expand Down
43 changes: 34 additions & 9 deletions plumbing/format/idxfile/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"sort"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/utils/binary"
)

Expand All @@ -23,10 +24,10 @@ func NewEncoder(w io.Writer) *Encoder {
}

// Encode encodes an Idxfile to the encoder writer.
func (e *Encoder) Encode(idx *Idxfile) (int, error) {
func (e *Encoder) Encode(idx *Idxfile, statusChan plumbing.StatusChan) (int, error) {
idx.Entries.Sort()

flow := []func(*Idxfile) (int, error){
flow := []func(*Idxfile, plumbing.StatusChan) (int, error){
e.encodeHeader,
e.encodeFanout,
e.encodeHashes,
Expand All @@ -37,7 +38,7 @@ func (e *Encoder) Encode(idx *Idxfile) (int, error) {

sz := 0
for _, f := range flow {
i, err := f(idx)
i, err := f(idx, statusChan)
sz += i

if err != nil {
Expand All @@ -48,7 +49,7 @@ func (e *Encoder) Encode(idx *Idxfile) (int, error) {
return sz, nil
}

func (e *Encoder) encodeHeader(idx *Idxfile) (int, error) {
func (e *Encoder) encodeHeader(idx *Idxfile, _ plumbing.StatusChan) (int, error) {
c, err := e.Write(idxHeader)
if err != nil {
return c, err
Expand All @@ -57,7 +58,7 @@ func (e *Encoder) encodeHeader(idx *Idxfile) (int, error) {
return c + 4, binary.WriteUint32(e, idx.Version)
}

func (e *Encoder) encodeFanout(idx *Idxfile) (int, error) {
func (e *Encoder) encodeFanout(idx *Idxfile, _ plumbing.StatusChan) (int, error) {
fanout := idx.calculateFanout()
for _, c := range fanout {
if err := binary.WriteUint32(e, c); err != nil {
Expand All @@ -68,7 +69,13 @@ func (e *Encoder) encodeFanout(idx *Idxfile) (int, error) {
return 1024, nil
}

func (e *Encoder) encodeHashes(idx *Idxfile) (int, error) {
func (e *Encoder) encodeHashes(idx *Idxfile, statusChan plumbing.StatusChan) (int, error) {
update := plumbing.StatusUpdate{
Stage: plumbing.StatusIndexHash,
ObjectsTotal: len(idx.Entries),
}
statusChan.SendUpdate(update)

sz := 0
for _, ent := range idx.Entries {
i, err := e.Write(ent.Hash[:])
Expand All @@ -77,12 +84,20 @@ func (e *Encoder) encodeHashes(idx *Idxfile) (int, error) {
if err != nil {
return sz, err
}
update.ObjectsDone++
statusChan.SendUpdateIfPossible(update)
}

return sz, nil
}

func (e *Encoder) encodeCRC32(idx *Idxfile) (int, error) {
func (e *Encoder) encodeCRC32(idx *Idxfile, statusChan plumbing.StatusChan) (int, error) {
update := plumbing.StatusUpdate{
Stage: plumbing.StatusIndexCRC,
ObjectsTotal: len(idx.Entries),
}
statusChan.SendUpdate(update)

sz := 0
for _, ent := range idx.Entries {
err := binary.Write(e, ent.CRC32)
Expand All @@ -91,12 +106,20 @@ func (e *Encoder) encodeCRC32(idx *Idxfile) (int, error) {
if err != nil {
return sz, err
}
update.ObjectsDone++
statusChan.SendUpdateIfPossible(update)
}

return sz, nil
}

func (e *Encoder) encodeOffsets(idx *Idxfile) (int, error) {
func (e *Encoder) encodeOffsets(idx *Idxfile, statusChan plumbing.StatusChan) (int, error) {
update := plumbing.StatusUpdate{
Stage: plumbing.StatusIndexOffset,
ObjectsTotal: len(idx.Entries),
}
statusChan.SendUpdate(update)

sz := 0

var o64bits []uint64
Expand All @@ -112,6 +135,8 @@ func (e *Encoder) encodeOffsets(idx *Idxfile) (int, error) {
}

sz += 4
update.ObjectsDone++
statusChan.SendUpdateIfPossible(update)
}

for _, o := range o64bits {
Expand All @@ -125,7 +150,7 @@ func (e *Encoder) encodeOffsets(idx *Idxfile) (int, error) {
return sz, nil
}

func (e *Encoder) encodeChecksums(idx *Idxfile) (int, error) {
func (e *Encoder) encodeChecksums(idx *Idxfile, _ plumbing.StatusChan) (int, error) {
if _, err := e.Write(idx.PackfileChecksum[:]); err != nil {
return 0, err
}
Expand Down
17 changes: 12 additions & 5 deletions plumbing/format/packfile/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package packfile
import (
"io"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
)
Expand All @@ -23,9 +24,12 @@ const (

// UpdateObjectStorage updates the given storer.EncodedObjectStorer with the contents of the
// packfile.
func UpdateObjectStorage(s storer.EncodedObjectStorer, packfile io.Reader) error {
func UpdateObjectStorage(
s storer.EncodedObjectStorer,
packfile io.Reader,
statusChan plumbing.StatusChan) error {
if sw, ok := s.(storer.PackfileWriter); ok {
return writePackfileToObjectStorage(sw, packfile)
return writePackfileToObjectStorage(sw, packfile, statusChan)
}

stream := NewScanner(packfile)
Expand All @@ -34,13 +38,16 @@ func UpdateObjectStorage(s storer.EncodedObjectStorer, packfile io.Reader) error
return err
}

_, err = d.Decode()
_, err = d.Decode(statusChan)
return err
}

func writePackfileToObjectStorage(sw storer.PackfileWriter, packfile io.Reader) error {
func writePackfileToObjectStorage(
sw storer.PackfileWriter,
packfile io.Reader,
statusChan plumbing.StatusChan) error {
var err error
w, err := sw.PackfileWriter()
w, err := sw.PackfileWriter(statusChan)
if err != nil {
return err
}
Expand Down
50 changes: 41 additions & 9 deletions plumbing/format/packfile/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,39 @@ func canResolveDeltas(s *Scanner, o storer.EncodedObjectStorer) bool {

// Decode reads a packfile and stores it in the value pointed to by s. The
// offsets and the CRCs are calculated by this method
func (d *Decoder) Decode() (checksum plumbing.Hash, err error) {
func (d *Decoder) Decode(statusChan plumbing.StatusChan) (checksum plumbing.Hash, err error) {
defer func() { d.isDecoded = true }()

if d.isDecoded {
return plumbing.ZeroHash, ErrAlreadyDecoded
}

if err := d.doDecode(); err != nil {
if err := d.doDecode(statusChan); err != nil {
return plumbing.ZeroHash, err
}

return d.s.Checksum()
}

func (d *Decoder) doDecode() error {
func (d *Decoder) doDecode(statusChan plumbing.StatusChan) error {
statusChan.SendUpdate(plumbing.StatusUpdate{
Stage: plumbing.StatusCount,
})

_, count, err := d.s.Header()
if err != nil {
return err
}

statusChan.SendUpdate(plumbing.StatusUpdate{
Stage: plumbing.StatusCount,
ObjectsTotal: int(count),
})
statusChan.SendUpdate(plumbing.StatusUpdate{
Stage: plumbing.StatusFetch,
ObjectsTotal: int(count),
})

if !d.hasBuiltIndex {
d.idx = NewIndex(int(count))
}
Expand All @@ -144,25 +157,35 @@ func (d *Decoder) doDecode() error {
_, isTxStorer := d.o.(storer.Transactioner)
switch {
case d.o == nil:
return d.decodeObjects(int(count))
return d.decodeObjects(int(count), statusChan)
case isTxStorer:
return d.decodeObjectsWithObjectStorerTx(int(count))
return d.decodeObjectsWithObjectStorerTx(int(count), statusChan)
default:
return d.decodeObjectsWithObjectStorer(int(count))
return d.decodeObjectsWithObjectStorer(int(count), statusChan)
}
}

func (d *Decoder) decodeObjects(count int) error {
func (d *Decoder) decodeObjects(count int, statusChan plumbing.StatusChan) error {
update := plumbing.StatusUpdate{
Stage: plumbing.StatusFetch,
ObjectsTotal: count,
}
for i := 0; i < count; i++ {
if _, err := d.DecodeObject(); err != nil {
return err
}
update.ObjectsDone++
statusChan.SendUpdateIfPossible(update)
}

return nil
}

func (d *Decoder) decodeObjectsWithObjectStorer(count int) error {
func (d *Decoder) decodeObjectsWithObjectStorer(count int, statusChan plumbing.StatusChan) error {
update := plumbing.StatusUpdate{
Stage: plumbing.StatusFetch,
ObjectsTotal: count,
}
for i := 0; i < count; i++ {
obj, err := d.DecodeObject()
if err != nil {
Expand All @@ -172,12 +195,19 @@ func (d *Decoder) decodeObjectsWithObjectStorer(count int) error {
if _, err := d.o.SetEncodedObject(obj); err != nil {
return err
}
update.ObjectsDone++
statusChan.SendUpdateIfPossible(update)
}

return nil
}

func (d *Decoder) decodeObjectsWithObjectStorerTx(count int) error {
func (d *Decoder) decodeObjectsWithObjectStorerTx(count int, statusChan plumbing.StatusChan) error {
update := plumbing.StatusUpdate{
Stage: plumbing.StatusFetch,
ObjectsTotal: count,
}

d.tx = d.o.(storer.Transactioner).Begin()

for i := 0; i < count; i++ {
Expand All @@ -196,6 +226,8 @@ func (d *Decoder) decodeObjectsWithObjectStorerTx(count int) error {
return err
}

update.ObjectsDone++
statusChan.SendUpdateIfPossible(update)
}

return d.tx.Commit()
Expand Down
Loading