Skip to content

Conversation

@knight42
Copy link
Contributor

@knight42 knight42 commented Jun 9, 2018

Close #5550.

It seems that updating the replaced registry before search has not been well considered in cargo and I have to add a function to trait core::source::Source to get the replaced SourceId.

I am not sure whether this is a good design, any advice is welcome.

@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@knight42 knight42 force-pushed the cargo-search-relaced-registry branch from c3525db to ce0f05d Compare June 11, 2018 11:53
@knight42
Copy link
Contributor Author

@alexcrichton just a friendly ping to keep this on your radar.

@alexcrichton
Copy link
Member

Thanks for the PR! Sorry I was away for a bit but am looking at this now. @Yanhao or @knight42 can y'all elaborate a bit on the use case here? I'm not sure how [source.replace-with] would affect other operations about searching and such?

@knight42
Copy link
Contributor Author

knight42 commented Jun 28, 2018

@alexcrichton I'm glad that you are back now!

At present, cargo search does not respect [source.replace-with] and always updates github.com/crates.io-index before search, because it only checks [registry.index] for altered registry index.

@alexcrichton
Copy link
Member

@knight42 the search API though isn't part of the replace-with business and is pretty specific to crates.io itself?

@knight42
Copy link
Contributor Author

Well yes.. but cargo now needs to update the local crates.io-index repository before search, and as you know people in some countries, like China, may not access GitHub and that's why an altered registry(a mirror) is needed.

In addition, is it necessary to update the local crates.io-index repo before search? Couldn't we just search directly?

@alexcrichton
Copy link
Member

Aha an excellent point! Hm though we don't necessarily want to stabilize the API of the registry yet, however. In that sense I wonder if this is a case where something like a proxy would be most useful? Is that possible to set up or is a dedicated registry server running inside of China?

Currently Cargo only knows about the git index, it doesn't actually know about crates.io's URL or server. A config.json in the root of the git index indicates where to find the API server, so Cargo updates it to find that server. This I feel like is a deficiency in Cargo, though. I'd prefer to implement a method where it doesn't involve first updating a git repo first!

@knight42
Copy link
Contributor Author

knight42 commented Jul 4, 2018

Pulling the git repo through a proxy is workable, but that would require extra work on client side. Currently, crates.io has not been blocked in China, so I think we need not to set up another registry server now.

If I understand correctly, @alexcrichton you do agree that we don't need to update a git repo before search, right? If so, I could implement such a method.

@alexcrichton
Copy link
Member

@knight42 yeah I think we should probably implement "don't update the registry before search". If you're interested in implementing that I can try to help out!

@knight42
Copy link
Contributor Author

knight42 commented Jul 6, 2018

@alexcrichton Now if I don't update first, I cannot pass the tests, and it sounds reasonable to fetch the repo if it is missing on local machine.

What if I update a repo only if it is missing? To be specific, I would call RegistrySource::update() only if RegistrySource::config() returns an Err.

@alexcrichton
Copy link
Member

@knight42 excactly my thinking as well! And yeah I'd only update in the case of a config access error

@knight42 knight42 force-pushed the cargo-search-relaced-registry branch from ce0f05d to 79d6228 Compare July 7, 2018 10:12
@knight42
Copy link
Contributor Author

knight42 commented Jul 7, 2018

@alexcrichton Done!

@knight42
Copy link
Contributor Author

knight42 commented Jul 7, 2018

The error seems spurious..

@alexcrichton
Copy link
Member

Thanks! Although this looks like it's still got the code to handle replaced registries, is that still needed? Additionally, could a test be added that the index isn't updated when it's already available?

@knight42
Copy link
Contributor Author

@alexcrichton I believe handling replaced registries is still necessary, because one may want to update the registry he specified in .cargo/config instead of github.com/crates.io-index.

As for the test, I don't know how to create a local registry with available index, does testsuite provide such a utility?

@alexcrichton
Copy link
Member

Ah ok I think I understand yeah, I think though in that case we'd want to move this logic to the registry function to affect other commands as well?

And yeah the test suite in places like tests/testsuite/registry.rs should have various utilities for creating dummy registries and indices.

@knight42 knight42 force-pushed the cargo-search-relaced-registry branch from 79d6228 to 0db28ca Compare July 17, 2018 15:35
@knight42
Copy link
Contributor Author

@alexcrichton Sorry for the delay, have been busy these days.

Now corresponding tests have been added, PTAL.

@bors
Copy link
Contributor

bors commented Jul 22, 2018

☔ The latest upstream changes (presumably #5762) made this pull request unmergeable. Please resolve the merge conflicts.

knight42 added 2 commits July 23, 2018 09:31
And update the replaced registry specified in `.cargo/config`
@knight42 knight42 force-pushed the cargo-search-relaced-registry branch from 0db28ca to 7d279fe Compare July 23, 2018 01:39
@knight42
Copy link
Contributor Author

@alexcrichton rebased

@alexcrichton
Copy link
Member

@knight42 hm are the tests here hitting the actual crates.io registry? We try to avoid that when possible, but I think with the new logic it'll see through the redirection and go to crates.io, right?

(sorry for the delay in taking a look!)

@knight42
Copy link
Contributor Author

@alexcrichton Of course not.

I have added two tests: search::replace_default and search::not_update, and they both replaced crates-io with dummy-registry by calling search::set_cargo_config.

@alexcrichton
Copy link
Member

@bors: r+

Ok!

@bors
Copy link
Contributor

bors commented Jul 24, 2018

📌 Commit 7d279fe has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jul 24, 2018

⌛ Testing commit 7d279fe with merge 5bb8501...

bors added a commit that referenced this pull request Jul 24, 2018
…richton

Update replaced registry before search

Close #5550.

It seems that updating the replaced registry before search has not been well considered in cargo and I have to add a function to trait `core::source::Source` to get the replaced `SourceId`.

I am not sure whether this is a good design, any advice is welcome.
@bors
Copy link
Contributor

bors commented Jul 24, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 5bb8501 to master...

@bors bors merged commit 7d279fe into rust-lang:master Jul 24, 2018
@knight42 knight42 deleted the cargo-search-relaced-registry branch July 25, 2018 00:51
@ehuss ehuss added this to the 1.29.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The search subcommand doesn't use [source.crates-io] replace-with config item.

5 participants