Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Link to tree views of submodules if possible#33424

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lunny merged 9 commits intogo-gitea:mainfrombohde:rb/submodule-adding
Jan 30, 2025

Conversation

@bohde
Copy link
Contributor

This is a follow-up to#33097.

When linking a submodule at a commit in either the repo view, or a diff when adding a new submodule, link to the tree view of that submodules intead of the individual commit. This shows the user the full tree, instead of the diff of the commit.

This makes the assumption that the tree for a given SHA is at<repo_url>/tree/<sha>. This URL format is supported by both Github & Gitlab, but not Gitea. To fix this, add a redirect from<username>/<repo>/tree/<ref> to<username>/<repo>/src/<ref>, so that Gitea can support this URL structure.

When linking a submodule at a commit in either the repo view, or adiff when adding a new submodule, link to the tree view of thatsubmodules intead of the individual commit. This shows the user thefull tree, instead of the diff of the commit.This makes the assumption that the tree for a given SHA is at`<repo_url>/tree/<sha>`. This URL format is supported by both Github &Gitlab, but not Gitea. To fix this, add a redirect from`<username>/<repo>/tree/<ref>` to `<username>/<repo>/src/<ref>`.
@GiteaBotGiteaBot added the lgtm/need 2This PR needs two approvals by maintainers to be considered for merging. labelJan 28, 2025
@github-actionsgithub-actionsbot added the modifies/goPull requests that update Go code labelJan 28, 2025
@GiteaBotGiteaBot added lgtm/need 1This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2This PR needs two approvals by maintainers to be considered for merging. labelsJan 28, 2025
@wxiaoguang
Copy link
Contributor

wxiaoguang commentedJan 29, 2025
edited
Loading

Thank you for the update, but I think we should avoid doing that .....

Sprintf("%s/%s/%s/src/%s", AppSubURL, PathEscape(username), PathEscape(reponame), PathEscapeSegments(*)) should be good enough and it's not worth to test it because it has been widely used everywhere. We can just keep code simple.

If you don't mind, I can help to make some improvements.

@bohde
Copy link
ContributorAuthor

bohde commentedJan 29, 2025
edited
Loading

Thank you for the update, but I think we should avoid doing that .....

Sprintf("%s/%s/%s/src/%s", AppSubURL, PathEscape(username), PathEscape(reponame), PathEscapeSegments(*)) should be good enough and it's not worth to test it because it has been widely used everywhere. We can just keep code simple.

If you don't mind, I can help to make some improvements.

Was in the process of responding to that one. I'm happy to make the change if you want, but before usingpaths.Join I looked through the existing code used to construct redirects to ensure the style was similar. It looked like there was a preference for using path.Join instead of fmt.Sprintf. (example).

If you still want me to replace it with fmt.Sprintf, I can.

@wxiaoguang
Copy link
Contributor

wxiaoguang commentedJan 29, 2025
edited
Loading

It looked like there was a preference for using path.Join instead of fmt.Sprintf. (example).

That's the only (maybe a few) legacy usages. Most other code doesn't usepath.Join.

Actually, you could also just useRepoLink here since you are in aRepoAssigment context.

Details

image

image

bohde reacted with thumbs up emoji

@wxiaoguang
Copy link
Contributor

wxiaoguang commentedJan 29, 2025
edited
Loading

Hmm, one more thing, I think the use of/tree/{CommitID} is wrong.

Because it redirects and routes to the deprecated handler/src/{CommitID} if I understand correctly.

image

@bohde
Copy link
ContributorAuthor

Actually, you could also just useRepoLink here since you are in aRepoAssigment context.

Used this method in92cb2a8

Because it redirects and routes to the deprecated handler /src/{CommitID} if I understand correctly.

This is correct, but intentional. Github's URL structure is<repo>/tree/<ref> not<repo>/tree/<sha>. A couple of examples:

When hitting this in Gitea, the user will have two separate redirects to get to the canonical URL. The flow would look like this:

@wxiaoguang
Copy link
Contributor

Then it comes to this question ....#33424 (comment)

Why we should support such/tree/ path? What's the benefit?

@bohde
Copy link
ContributorAuthor

Then it comes to this question ....#33424 (comment)

Why we should support such/tree/ path? What's the benefit?

The intent of this PR is so that when a user clicks on a submodule commit, either in the repo home view, or when adding a new submodule in a diff, that shows them the tree instead of the commit.

Right now if I add a submodule ofgitea.com/gitea/gitea-mirror@a89c73530327784ce99e1e07c269ea8ff1861fdc, it links tohttps://gitea.com/gitea/gitea-mirror/commit/a89c73530327784ce99e1e07c269ea8ff1861fdc. This updates that to show (after redirects)https://gitea.com/gitea/gitea-mirror/src/commit/a89c73530327784ce99e1e07c269ea8ff1861fdc, allowing them to browse the repo at that commit.

The issue of adding a/tree/ path comes in for submodules that are not hosted on Gitea. If I were to link out tohttps://github.com/go-gitea/gitea/src/commit/a89c73530327784ce99e1e07c269ea8ff1861fdc, that results in a 404 for the user, who would need to navigate to the repo, and then search for the commit. That content is instead available athttps://github.com/go-gitea/gitea/tree/a89c73530327784ce99e1e07c269ea8ff1861fdc.

We could try to guess what type of forge a given submodule links out to, and then either usesrc/commit for Gitea ortree for others, but self-hosted deployments would make that error-prone. Adding a redirect for thesetree paths allows using the same link across Gitea and other forges.

@wxiaoguang
Copy link
Contributor

Thank you for the explanation, it's clear to me now.

I think we need to add the background information to comments, otherwise the future readers would still have the same question: why/tree/ is used ....

@bohde
Copy link
ContributorAuthor

Thank you for the explanation, it's clear to me now.

I think we need to add the background information to comments, otherwise the future readers would still have the same question: why/tree/ is used ....

I updated the comment in7da9b01. Is that inline with what you are thinking?

@GiteaBotGiteaBot added lgtm/doneThis PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1This PR needs approval from one additional maintainer to be merged. labelsJan 29, 2025
@lunnylunny added the reviewed/wait-mergeThis pull request is part of the merge queue. It will be merged soon. labelJan 29, 2025
@lunnylunnyenabled auto-merge (squash)January 29, 2025 23:52
@lunnylunny added this to the1.24.0 milestoneJan 29, 2025
@lunnylunny merged commitac2d97c intogo-gitea:mainJan 30, 2025
26 checks passed
@GiteaBotGiteaBot removed the reviewed/wait-mergeThis pull request is part of the merge queue. It will be merged soon. labelJan 30, 2025
@wxiaoguang
Copy link
Contributor

-> Fix "redirect link" handling#33440

Improved the path handling logic and added some tests inlinks_test.go

@go-giteago-gitea locked asresolvedand limited conversation to collaboratorsApr 30, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@wxiaoguangwxiaoguangwxiaoguang approved these changes

@delvhdelvhdelvh approved these changes

Assignees

No one assigned

Labels

lgtm/doneThis PR has enough approvals to get merged. There are no important open reservations anymore.modifies/goPull requests that update Go code

Projects

None yet

Milestone

1.24.0

Development

Successfully merging this pull request may close these issues.

5 participants

@bohde@wxiaoguang@delvh@lunny@GiteaBot

[8]ページ先頭

©2009-2025 Movatter.jp