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

storage/filesystem: call initialization explicitly, fixes #408 #409

Merged
merged 1 commit into from
Jun 5, 2017
Merged

storage/filesystem: call initialization explicitly, fixes #408 #409

merged 1 commit into from
Jun 5, 2017

Conversation

smola
Copy link
Collaborator

@smola smola commented May 31, 2017

filesystem.Storage was initializing the gitdir (creating objects
and refs) on NewStorage. But this should be done only on init and
clone operations, not on open.

Now there is a new interface storer.Initializer that storers can
implement if they need any initialization step before init or clone.
filesystem.Storage is one of such implementations.

git.Init and git.Clone now call to the storer Init() method if it
does implement it. Otherwise, it just ignores initialization.

@smola smola requested review from ajnavarro, mcuadros and alcortesm May 31, 2017 07:05
@smola
Copy link
Collaborator Author

smola commented May 31, 2017

Fixes #408

Copy link
Contributor

@ajnavarro ajnavarro left a comment

Choose a reason for hiding this comment

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

@smola CI is failing:

FAIL: storage_test.go:31: StorageSuite.TestNewStorage
storage_test.go:38:
    c.Assert(err, IsNil)
... value *errors.errorString = &errors.errorString{s:"file does not exist"} ("file does not exist")

)

func Test(t *testing.T) { TestingT(t) }

type StorageSuite struct {
test.BaseStorageSuite
Dir string
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make this attribute private rather than public.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

@@ -42,3 +45,9 @@ func (s *StorageSuite) TestFilesystem(c *C) {

c.Assert(storage.Filesystem(), Equals, fs)
}

func (s *StorageSuite) TestStructureShouldBeCreatedLazily(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.

The test name is misleading, what Structure?, and we are also not testing that contents are created lazily, just that the dir is created empty.

I suggest a new name for the test: TestNewStorageShouldNotAddAnyContentsToDir.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed.

@alcortesm
Copy link
Contributor

Of course storage_test.go:31: StorageSuite.TestNewStorage is failing now, that was the whole point of the patch :). By the way, the name of that test was not very informative :).

@ajnavarro
Copy link
Contributor

@alcortesm What I meant is, if the behavior has changed, this test should not test if the directories are created, so this test should pass too (removing the Stats line, the entire test because now does not make sense, or whatever)

@alcortesm
Copy link
Contributor

alcortesm commented May 31, 2017

@ajnavarro yes, I understood you and I think you are right. My comment was just to point out that the name of the test and the things it tested were not aligned.

I also agree with you that that whole test makes no sense now.

@smola
Copy link
Collaborator Author

smola commented Jun 1, 2017

@alcortesm @ajnavarro Right. I removed TestNewStorage, we want exactly the oposite behavior.

Copy link
Contributor

@mcuadros mcuadros left a comment

Choose a reason for hiding this comment

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

The structure should be created as soon as a repository is initialized, doesn't matter if the repository is empty. So even before having any object the structure should be there.

@alcortesm
Copy link
Contributor

@mcuadros

What do you mean by "the structure" and why it should be there?

Can you write a test to illustrate exactly what has to be there and what is not really needed until we use it for something?

@codecov
Copy link

codecov bot commented Jun 1, 2017

Codecov Report

Merging #409 into master will decrease coverage by 0.64%.
The diff coverage is 45.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #409      +/-   ##
==========================================
- Coverage   77.68%   77.03%   -0.65%     
==========================================
  Files         124      124              
  Lines        8998     9010      +12     
==========================================
- Hits         6990     6941      -49     
- Misses       1233     1307      +74     
+ Partials      775      762      -13
Impacted Files Coverage Δ
storage/filesystem/storage.go 87.5% <ø> (+9.72%) ⬆️
storage/filesystem/internal/dotgit/dotgit.go 73.01% <45.45%> (-1.26%) ⬇️
plumbing/transport/ssh/common.go 0% <0%> (-50.91%) ⬇️
plumbing/transport/ssh/auth_method.go 32.4% <0%> (-25.69%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 87d2475...88f88ea. Read the comment docs.

filesystem.Storage was initializing the gitdir (creating objects
and refs) on NewStorage. But this should be done only on init and
clone operations, not on open.

Now there is a new interface storer.Initializer that storers can
implement if they need any initialization step before init or clone.
filesystem.Storage is one of such implementations.

git.Init and git.Clone now call to the storer Init() method if it
does implement it. Otherwise, it just ignores initialization.
@smola smola changed the title storage/filesystem: create structure lazily, fixes #408 storage/filesystem: call initialization explicitly, fixes #408 Jun 1, 2017
@smola
Copy link
Collaborator Author

smola commented Jun 1, 2017

@mcuadros and me talked about this offline and agreed that this should be done explicitly. That is: a storer needs a way to get called when initialization is being done.

The end result is essentially the same: as you see, the test has not changed.
The difference, however, is that now git.Init (and git.Clone indirectly) explicitly calls Init() on the storer if it implements it.

@alcortesm
Copy link
Contributor

I see, thanks!


_, err = fs.Stat("refs/tags")
Copy link
Contributor

Choose a reason for hiding this comment

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

why we delete this test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its only purpose was checking that refs/tags was created before any action. This is no longer the case, so it's enough if we check the other cases.

@smola smola dismissed ajnavarro’s stale review June 5, 2017 16:09

issues addressed; @ajnavarro is on holidays now

@smola smola merged commit 2a00316 into src-d:master Jun 5, 2017
@smola smola deleted the dirty-plainopen branch June 5, 2017 16:10
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