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

Refactor git attributes #29356

Merged
merged 4 commits into from Feb 24, 2024
Merged

Refactor git attributes #29356

merged 4 commits into from Feb 24, 2024

Conversation

KN4CK3R
Copy link
Member

@KN4CK3R KN4CK3R commented Feb 23, 2024

No description provided.

@KN4CK3R KN4CK3R added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Feb 23, 2024
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 23, 2024
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 23, 2024
Comment on lines +1200 to +1205
if !isVendored.Has() {
isVendored = optional.Some(analyze.IsVendor(diffFile.Name))
}
if !gotGenerated {
diffFile.IsGenerated = analyze.IsGenerated(diffFile.Name)
diffFile.IsVendored = isVendored.Value()

if !isGenerated.Has() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Both ifs are changed to be consistent with the repo language stats. If the .gitattribute tells a file is not vendored, this should not be overridden by analyse.IsVendor.

@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 Feb 24, 2024
language = AttributeToString(attrs, AttributeGitlabLanguage)
if language.Has() {
raw := language.Value()
if idx := strings.IndexByte(raw, '?'); idx >= 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see it is from old code ... I am quite curious that why checking ? here ... feel free to add a comment or dismiss this question if it is still unclear.

Copy link
Member

Choose a reason for hiding this comment

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

I've seen in the tests that the format can be something like
*.md gitlab-language=Go?parent=Markdown.
But yes, it is a weird mechanism…

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we should add a comment for it.

Copy link
Member Author

Choose a reason for hiding this comment

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

The syntax is shown here: https://docs.gitlab.com/ee/user/project/highlighting.html#override-syntax-highlighting-for-a-file-type

You can also extend the highlighting with Common Gateway Interface (CGI) options, such as:

Whatever that means.

generated, has := attrs["linguist-generated"]
ctx.Data["IsGenerated"] = has && (generated == "set" || generated == "true")
ctx.Data["IsVendored"] = git.AttributeToBool(attrs, git.AttributeLinguistVendored).Value()
ctx.Data["IsGenerated"] = git.AttributeToBool(attrs, git.AttributeLinguistGenerated).Value()
Copy link
Member

Choose a reason for hiding this comment

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

By the way, since we now support more attributes, shouldn't they be added here as well?
But perhaps in a follow up PR…

language = AttributeToString(attrs, AttributeGitlabLanguage)
if language.Has() {
raw := language.Value()
if idx := strings.IndexByte(raw, '?'); idx >= 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I've seen in the tests that the format can be something like
*.md gitlab-language=Go?parent=Markdown.
But yes, it is a weird mechanism…

@@ -1181,41 +1182,30 @@ func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, fi

for _, diffFile := range diff.Files {

gotVendor := false
gotGenerated := false
isVendored := optional.None[bool]()
Copy link
Member

Choose a reason for hiding this comment

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

See two comments above

language = AttributeToString(attrs, AttributeGitlabLanguage)
if language.Has() {
raw := language.Value()
if idx := strings.IndexByte(raw, '?'); idx >= 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we should add a comment for it.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 24, 2024
@KN4CK3R KN4CK3R enabled auto-merge (squash) February 24, 2024 12:26
@yardenshoham yardenshoham added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 24, 2024
@KN4CK3R KN4CK3R merged commit 4197e28 into go-gitea:main Feb 24, 2024
26 checks passed
@GiteaBot GiteaBot added this to the 1.22.0 milestone Feb 24, 2024
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 24, 2024
@KN4CK3R KN4CK3R deleted the refactor-attributes branch February 24, 2024 22:49
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants