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

format/packfile: implement delta encoding #172

Merged
merged 3 commits into from
Dec 14, 2016
Merged

format/packfile: implement delta encoding #172

merged 3 commits into from
Dec 14, 2016

Conversation

ajnavarro
Copy link
Contributor

  • Added all the logic to the encoder to be able to encode ref-delta and offset-delta objects
  • Created plumbing.ObjectToPack to handle deltas and standard objects when we are writting them into a packfile
  • Added specific encoder delta tests, one standard object and one delta, and one standard object and two deltas

@codecov-io
Copy link

codecov-io commented Dec 9, 2016

Current coverage is 77.27% (diff: 82.14%)

Merging #172 into master will decrease coverage by 0.46%

@@             master       #172   diff @@
==========================================
  Files            91         92     +1   
  Lines          5823       5892    +69   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           4527       4553    +26   
- Misses          816        859    +43   
  Partials        480        480          

Powered by Codecov. Last update fb7b525...6799c8a

@smola smola requested a review from mcuadros December 9, 2016 16:35
func GetDelta(base, target plumbing.Object) ([]byte, error) {
// GetOfsDelta returns an offset delta that knows the way of how to transform
// base object to target object
func GetOfsDelta(base, target plumbing.Object) (*plumbing.ObjectToPack, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OFS should be capital leters

@@ -35,7 +51,17 @@ func GetDelta(base, target plumbing.Object) ([]byte, error) {
return nil, err
}

return DiffDelta(baseBuf, targetBuf), nil
deltaBuf := DiffDelta(baseBuf, targetBuf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a very long variable name to this such small scope

return err
}

if o.IsDelta() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very long function maybe you can split it

@@ -90,6 +115,20 @@ func (e *Encoder) entry(o plumbing.Object) error {
return e.zw.Close()
}

func (e *Encoder) writeRefDeltaHeader(source plumbing.Hash) error {
return binary.Write(e.w, source)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go fmt?


func (ow *offsetWriter) Write(p []byte) (n int, err error) {
n, err = ow.w.Write(p)
ow.offset = ow.offset + int64(n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+=

@@ -81,6 +81,8 @@ func (s *EncoderSuite) TestMaxObjectSize(c *C) {

func (s *EncoderSuite) TestDecodeEncodeDecode(c *C) {
fixtures.Basic().ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
c.Logf("Executing test case with repository %s "+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this information is already logged by the fixture package

// ObjectToPack is a representation of an object that is going to be into a
// pack file. If it is a delta, Source is the delta source and Original is the
// delta target
type ObjectToPack struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't understand the goal of this struct, is this struct useful for non-delta objects?

Original Object
}

func NewObjectToPack(o Object) *ObjectToPack {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all this functions are not tested

@@ -17,6 +17,20 @@ func Write(w io.Writer, data ...interface{}) error {
return nil
}

func WriteVariableWidthInt(w io.Writer, n int64) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not tested (or something wrong with codecov)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

- Added all the logic to the encoder to be able to encode ref-delta and offset-delta objects
- Created plumbing.ObjectToPack to handle deltas and standard objects when we are writting them into a packfile
- Added specific encoder delta tests, one standard object and one delta, and one standard object and two deltas
Copy link
Collaborator

@smola smola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test for:

  • Encode passing a hash to an object that does not exist, check that it returns the appropiate error.
  • Test GetOFSDelta or GetRefDelta, instead of getDelta.

@@ -12,6 +12,46 @@ var (
ErrInvalidType = errors.New("invalid object type")
)

// ObjectToPack is a representation of an object that is going to be into a
// pack file. If it is a delta, Base is the object that this delta is based on
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decide each field (Object, Base, Original, Depth) in their declaration, not in the common ObjectToPack docs.

@mcuadros mcuadros merged commit 1d78a9a into src-d:master Dec 14, 2016
@ajnavarro ajnavarro deleted the feature/encode-delta branch December 14, 2016 09:20
mcuadros pushed a commit that referenced this pull request Jan 31, 2017
* format/packfile: implement delta encoding

- Added all the logic to the encoder to be able to encode ref-delta and offset-delta objects
- Created plumbing.ObjectToPack to handle deltas and standard objects when we are writting them into a packfile
- Added specific encoder delta tests, one standard object and one delta, and one standard object and two deltas

* Requested changes.

* Requested changes
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants