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

plumbing: format, packfile fix issue #129, related #124, and documentation improvements #130

Merged
merged 2 commits into from
Nov 23, 2016
Merged

Conversation

mcuadros
Copy link
Contributor

This issue fix issue #129 and is related to #124.

I made a test that covers exactly the problem happening, we have four types of decodings:

  • Decode without OjectStorer, was ok
  • Decode over a ObjectStorer with a Seekable scanner, was ok
  • Decode over a ObjectStorer with Transationer support without a Seekable scanner, was ok
  • Decode over a ObjectStorer without Transationer support without a Seekable scanner, was failing

// returned.
//
// If the ObjectStorer implements storer.Transactioner, a transation is created
// during the Decode execution, if something fails the Rollback is called
Copy link
Contributor

Choose a reason for hiding this comment

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

This comments need improvements.

NewDecoder returns a new Decoder that reads from s and store the objects in o.

This line is OK, but does not clearly explain the purpose and usage of the type, as we will see in the next sentence.

ObjectStorer can be nil, in this case the objects are not stored but Offsets can be call to retrieve the objets offset in the packfile being scan.

This line is confusing for several reasons:

  1. English has to be improved.
  2. The documentation of the Offsets method has to be improved, and it should probably call Decode internally.
  3. The purpose of a Decoder without an ObjectStorer is not clear. According to the first line, the main purpose of a Decoder is to store objects from a packfile into an ObjectStorer, so what happens when no ObjectStorer is available? how is this useful?

If ObjectStorer is nil and the Scanner is not Seekable, ErrNonSeekable is returned.

This is OK, once the previous line is clarified.

If the ObjectStorer implements storer.Transactioner, a transation is created during the Decode execution, if something fails the Rollback is called.

s/transation/transaction/

This is not true, a Rollback is only called when the setObject operation fails on the transaction, but not when other operations fails. See my comments below.

Overall, the purpose of this type is not clear, we should redesign it and clarify its purpose and usage.

We should start by explaining the problem, how the type is expected to be used. Then explain the possible decoders we support (seekable-transactioner, seekable-non-transactioner, ...). As this is very relevant for it use, the cause of a lot of code repetitions and has been the cause of several bugs in the past.

Copy link
Contributor

Choose a reason for hiding this comment

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

It will be nice to explain all the possible combinations of ObjectStorers and seekable scanners, from the very beginning, just to make it easier later to document the internal parts.

}

// recallByHashNonSeekable read from a object from a Tx, if we are in a
// transaction, we should read from there, if not we read from the ObjectStorer
Copy link
Contributor

Choose a reason for hiding this comment

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

This sentence needs to be rewritten.

// returned.
//
// If the ObjectStorer implements storer.Transactioner, a transation is created
// during the Decode execution, if something fails the Rollback is called
func NewDecoder(s *Scanner, o storer.ObjectStorer) (*Decoder, error) {
if !s.IsSeekable && o == nil {
return nil, ErrNonSeekable
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve the name of the error and use a function to clarify the reason behind the if condition.

if err != plumbing.ErrObjectNotFound {
return obj, err
}

return nil, plumbing.ErrObjectNotFound

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this line.

@@ -1,4 +1,4 @@
package packfile
package packfile_test
Copy link
Contributor

Choose a reason for hiding this comment

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

I like public testing, but why?

Copy link
Contributor

Choose a reason for hiding this comment

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

It may be nice to begin the test files with constructor of the 4 (or more) kinds of Decoder where are going to need:

  • seekable-transactioner
  • seekable-non-transactioner
  • no-seekable-non-transactioner
  • non-seekable-non-transactioner

Just for general clarity and sanity. It will help a lot with the testing, simplicity and coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then you will have the same complexity in the other end. Then before use it (in several lines) you need to put the switch (in the better of the cases)

The package is public due to a circular dependency

})
}

func (s *ReaderSuite) TestDecodeNoSeekableWithNoTxStorer(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

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

s/WithNot/Without/

}

scanner := packfile.NewScanner(reader)
storage, _ := filesystem.NewStorage(fs.New())
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you know this storage is not a TxStorer? It should be explicitly asserted in the test. Also the opposite should be asserted in the previous test.

@mcuadros mcuadros changed the title plumbing: format, packfile fix issue #129, related #124 plumbing: format, packfile fix issue #129, related #124, and documentation improvements Nov 22, 2016
@euforia euforia mentioned this pull request Nov 23, 2016
@mcuadros mcuadros merged commit 0737406 into src-d:master Nov 23, 2016
@powerman
Copy link

When do you plan to merge these changes into v4 branch?

@mcuadros mcuadros deleted the packfile-tx branch December 13, 2016 10:14
mcuadros added a commit that referenced this pull request Jan 31, 2017
…ation improvements (#130)

* plumbing: format, packfile fix issue #129, related #124

* plumbing: format, packfile documentation improvements
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.

3 participants