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

Remove duplicate root projects when importing from glide #898

Merged
merged 4 commits into from
Aug 11, 2017

Conversation

carolynvs
Copy link
Collaborator

@carolynvs carolynvs commented Jul 25, 2017

I (naively) assumed that since glide supports listing the subpackages used, that it people's glide.yaml/lock wouldn't have multiple entries for the same root package...

The glide importer now checks for duplicate root projects. I've introduced a cache of the resolution from import path to root project, because it's guaranteed that paths will be double resolved (for glide and any other future importer that uses a config + lock).

// source manager, which is quite helpful when repeatedly converting from
// import paths to root projects.
type ProjectRootCache struct {
prs map[string]ProjectRoot
Copy link
Member

Choose a reason for hiding this comment

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

this information should already be cached inside of a SourceManager (or, at least, it definitely is in sourceMgr) - what's the benefit of layering this on top?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It didn't seem to me that it was caching the result in the source manager?

The source manager calls out to the deducer:

func (dc *deductionCoordinator) deduceRootPath(ctx context.Context, path string) (pathDeduction, error) {

Then the deducer figures it out fresh each time:

func (dc *deductionCoordinator) deduceRootPath(ctx context.Context, path string) (pathDeduction, error) {

Copy link
Member

@sdboyer sdboyer Jul 26, 2017

Choose a reason for hiding this comment

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

that logic is definitely complex, because it has to be concurrency-safe, but yes, the deductionCoordinator.rootxt radix tree is the cache, and this is basically the cache "get".

we use the radix tree, rather than a map, so that we only ever have to actually deduce a project root once, even if we haven't seen a literal path before. so, the sequence goes something like this:

  1. a call comes in to deduce k8s.io/kubernetes/pkg/foo
  2. we make the necessary HTTP call and find that k8s.io/kubernetes is the root, and record that in the radix tree
  3. a subsequent call comes in to deduce k8s.io/kubernetes/pkg/bar

even though no exact call happened for k8s.io/kubernetes/pkg/bar before, or even for its actual root, k8s.io/kubernetes, a deduction call to k8s.io/kubernetes/pkg/bar after an earlier, completed one to k8s.io/kubernetes/pkg/foo still results in a cache hit.

this is one of the things afforded to us by the assumption that projects are repo root-only, and therefore necessarily cannot be nested.

@sdboyer
Copy link
Member

sdboyer commented Aug 5, 2017

i'm guessing this is just backburnered a bit, right?

@carolynvs
Copy link
Collaborator Author

Yup! I'll jump back on this (and others) next week.

@carolynvs
Copy link
Collaborator Author

I've removed the unnecessary cache and rebased.


if result != c.want {
t.Fatalf("projectExistsInLock result is not as expected: \n\t(GOT) %v \n\t(WNT) %v", result, c.want)
t.Errorf("projectExistsInLock result is not as expected: \n\t(GOT) %v \n\t(WNT) %v", result, c.want)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move this whole test function TestGodepConfig_ProjectExistsInLock() as part of root_analyzer_test.go?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, any reason for using Errorf here? Just curious to know when to use which one 😊

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test isn't using proper subtests, so I was using Errorf (which allows the other testcases to execute after a failure). I'll switch to a subtest and fatalf.

Copy link
Member

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

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

after rebase + those test changes are made, this LGTM

@carolynvs
Copy link
Collaborator Author

Rebased and fixed that one test.

@sdboyer
Copy link
Member

sdboyer commented Aug 11, 2017

weee!

@sdboyer sdboyer merged commit f79cf02 into golang:master Aug 11, 2017
@carolynvs carolynvs deleted the root-imported-constraints branch August 11, 2017 17:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants