Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow any ref of a Git repo in the fragment #11147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Leonidas-from-XIV
Copy link
Collaborator

This reverses the split of branches and tags from #11127, instead putting all possible references (e.g. also pull requests) in the same map and implements short-hands for looking up unqualified refs.

Fixes #11140

@@ -32,8 +32,7 @@ module Remote = struct
type nonrec t =
{ url : string
; default_branch : Object.resolved option Fiber.t
; branches : Object.resolved String.Map.t Fiber.t
; tags : Object.resolved String.Map.t Fiber.t
; refs : Object.resolved String.Map.t Fiber.t
Copy link
Member

Choose a reason for hiding this comment

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

Tbh, this doesn't seem like an improvement in readability. I think you could just as easily just parse the refs/{heads,tags} out of the query and then know which map you need to look in.

Opinions aside, I think this makes it a bit harder to implement the "did you mean" hint. That one would be rather useful when a user typos a branch or a tag. IMO you should hold off this refactoring until we have that useful hint ready.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem is with other types of refs like pull refs for heads and merges. The dune repo itself has at least 4 types of refs and we don't even do anything particularly unusual with Git.

Git refs are basically just a Object.resolved String.Map.t and the string is just refs/{heads,tags} by convention, so to me this seems like the best way to represent them aligned with how Git treats them, thus fewer concepts to keep in mind and less ways for repos to break our assumptions.

Copy link
Member

@rgrinberg rgrinberg left a comment

Choose a reason for hiding this comment

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

Approving as this PR fixes the issue reliably like it advertises. Not a fan of keeping map where everything is prefixed with refs/{heads,tags} - I would prefer the types to reflect the structure, and help improve the hints.

@Leonidas-from-XIV
Copy link
Collaborator Author

Not a fan of keeping map where everything is prefixed with refs/{heads,tags}

I understand, however the way it works in opam is that every ref in ls-remote can be used. In particular that means that it can use refs like refs/pull/9306/head and refs/pull/9306/merge (these are taken from git ls-remote [email protected]:ocaml/dune.git), whereas if we create a map for each type this becomes an ongoing maintenance process of adding more and more types of references as github/git/users add more references.

We could of course also say that we only support branch and tag references because it's unlikely someone would use them, however that feels like an easy feature to support at the cost of a slightly messy map.

This reverses the split of branches and tags from ocaml#11127, instead
putting all possible references (e.g. also pull requests) in the same
map and implements short-hands for looking up unqualified refs.

Fixes ocaml#11140

Signed-off-by: Marek Kubica <[email protected]>
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.

URLs should allow picking a branch or tag explicitely
3 participants