-
Notifications
You must be signed in to change notification settings - Fork 534
format/packfile: implement delta encoding #172
Conversation
ajnavarro
commented
Dec 9, 2016
- 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
Current coverage is 77.27% (diff: 82.14%)@@ 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
|
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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) | |||
} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 "+ |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
* 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