Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Xuanwo
Copy link
Collaborator

@Xuanwo Xuanwo commented Dec 28, 2025

This PR allows users to parse a str into Ref.

For example:

("0", Ref::VersionNumber(0)),
("42", Ref::VersionNumber(42)),
("main", Ref::Version(None, None)),
("main:", Ref::Version(None, None)),
("main:latest", Ref::Version(None, None)),
("main:10", Ref::Version(None, Some(10))),
("feature/a", Ref::Version(Some("feature/a".to_string()), None)),
("feature/a:", Ref::Version(Some("feature/a".to_string()), None)),
("feature/a:latest", Ref::Version(Some("feature/a".to_string()), None)),
("feature/a:10", Ref::Version(Some("feature/a".to_string()), Some(10))),
("tag1", Ref::Tag("tag1".to_string()))

Parts of this PR were drafted with assistance from Codex (with gpt-5.2) and fully reviewed and edited by me. I take full responsibility for all changes.

@github-actions github-actions bot added the enhancement New feature or request label Dec 28, 2025
@github-actions
Copy link
Contributor

ACTION NEEDED
Lance follows the Conventional Commits specification for release automation.

The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification.

For details on the error please inspect the "PR Title Check" action.

@github-actions
Copy link
Contributor

Code Review

P0 - Ambiguity between tags and branches without "/":

The FromStr implementation uses the presence of / to distinguish between branches and tags when there is no : separator. This creates an ambiguity: how would a user specify a branch named "feature" (no slash) vs a tag named "feature"?

Currently "tag1".parse::<Ref>() returns Tag("tag1"), but there is no way to parse a branch name without a slash (e.g., "dev" branch) unless using the colon syntax ("dev:").

Consider either:

  1. Documenting this limitation clearly
  2. Requiring explicit syntax for disambiguation (e.g., tag:name vs branch:name)
  3. Adding methods like Ref::parse_as_branch() / Ref::parse_as_tag() for explicit parsing

P1 - Inconsistency with existing From<&str> impl:

The existing From<&str> impl (line 46-49) unconditionally converts to Tag:

impl From<&str> for Ref {
    fn from(reference: &str) -> Self {
        Tag(reference.to_string())
    }
}

But FromStr has different behavior - "42".parse::<Ref>() returns VersionNumber(42) while Ref::from("42") returns Tag("42"). This inconsistency could cause subtle bugs. Consider deprecating or removing the From<&str> impl, or documenting the behavioral difference prominently.

@codecov
Copy link

codecov bot commented Dec 28, 2025

Codecov Report

❌ Patch coverage is 78.72340% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance/src/dataset/refs.rs 78.26% 7 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@Xuanwo Xuanwo changed the title feat: Add FromStr for Ref feat: Allow version and version number been parsed into Ref Dec 28, 2025
@Xuanwo Xuanwo changed the title feat: Allow version and version number been parsed into Ref feat: parse Ref from version and version numbers Dec 28, 2025
@wjones127
Copy link
Contributor

I'd +1 the automated code review concern here: how do we differentiate from branches? We can maybe add some additional rules for what is a valid tag. It seems like this might be worth designing the API in an issue first before going into implementation.

There any background on this feature? Why did you decide to implement it?

@wjones127 wjones127 self-assigned this Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants