Skip to content

Conversation

@lunny
Copy link
Member

@lunny lunny commented Jan 15, 2026

Fix #35226

@lunny lunny added the type/bug label Jan 15, 2026
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 15, 2026
@github-actions github-actions bot added modifies/go Pull requests that update Go code and removed backport/v1.25 labels Jan 15, 2026
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 16, 2026
Comment on lines 56 to 110
func normalizeLFSRefName(raw string) string {
ref := strings.TrimSpace(raw)
if ref == "" {
return ""
}
prefixes := []string{"refs/heads/", "refs/remotes/", "refs/"}
for _, prefix := range prefixes {
if trimmed, ok := strings.CutPrefix(ref, prefix); ok {
ref = trimmed
break
}
}
return ref
}

func refNameFromBatchRequest(br *lfs_module.BatchRequest) string {
if br == nil || br.Ref == nil {
return ""
}
return normalizeLFSRefName(br.Ref.Name)
}

func setLFSRefInContext(ctx *context.Context, ref string) {
ref = normalizeLFSRefName(ref)
if ref == "" {
return
}
if ctx.Data == nil {
ctx.Data = make(map[string]any)
}
ctx.Data[lfsRefContextKey] = ref
}

func getLFSRefFromContext(ctx *context.Context) string {
if ctx.Data == nil {
return ""
}
if ref, ok := ctx.Data[lfsRefContextKey].(string); ok {
return ref
}
return ""
}

func setLFSRefFromQuery(ctx *context.Context) {
ref := ctx.Req.URL.Query().Get(lfsRefQueryKey)
setLFSRefInContext(ctx, ref)
}

func appendRefQuery(baseURL, ref string) string {
if ref == "" {
return baseURL
}
return baseURL + "?" + lfsRefQueryKey + "=" + url.QueryEscape(ref)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I really don't understand why these newly added function can be right or necessary.

@wxiaoguang wxiaoguang marked this pull request as draft January 16, 2026 11:01
@wxiaoguang
Copy link
Contributor

I really don't understand what you are doing.

You always have the ctx *context.Context for these functions, why you still use ctx.Data to pass the value from query parameter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/v1.25 lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/go Pull requests that update Go code type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to Push to PRs with "Allow Edits from Maintainers" and LFS usage

4 participants