Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main:
  Fixed incorrect localization `explorer.go` (go-gitea#31348)
  Improve detecting empty files (go-gitea#31332)
  Fix hash render end with colon (go-gitea#31319)
  Fix line number widths (go-gitea#31341)
  Fix navbar `+` menu flashing on page load (go-gitea#31281)
  Reduce memory usage for chunked artifact uploads to MinIO (go-gitea#31325)
  Fix dates displaying in a wrong manner when we're close to the end of the month (go-gitea#31331)
  Fix adopt repository has empty object name in database (go-gitea#31333)
  Optimize profile layout to enhance visual experience (go-gitea#31278)
  • Loading branch information
zjjhot committed Jun 13, 2024
2 parents 66bf728 + fede3cb commit 5b45fc8
Show file tree
Hide file tree
Showing 26 changed files with 97 additions and 72 deletions.
2 changes: 1 addition & 1 deletion modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var (
// hashCurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae
// Although SHA1 hashes are 40 chars long, SHA256 are 64, the regex matches the hash from 7 to 64 chars in length
// so that abbreviated hash links can be used as well. This matches git and GitHub usability.
hashCurrentPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-f]{7,64})(?:\s|$|\)|\]|[.,](\s|$))`)
hashCurrentPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-f]{7,64})(?:\s|$|\)|\]|[.,:](\s|$))`)

// shortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax
shortLinkPattern = regexp.MustCompile(`\[\[(.*?)\]\](\w*)`)
Expand Down
1 change: 1 addition & 0 deletions modules/markup/html_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ func TestRegExp_sha1CurrentPattern(t *testing.T) {
"(abcdefabcdefabcdefabcdefabcdefabcdefabcd)",
"[abcdefabcdefabcdefabcdefabcdefabcdefabcd]",
"abcdefabcdefabcdefabcdefabcdefabcdefabcd.",
"abcdefabcdefabcdefabcdefabcdefabcdefabcd:",
}
falseTestCases := []string{
"test",
Expand Down
1 change: 1 addition & 0 deletions modules/repository/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository,
if err != nil {
return 0, fmt.Errorf("UpdateRepository: %w", err)
}
repo.ObjectFormatName = objFmt.Name() // keep consistent with db

allBranches := container.Set[string]{}
{
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ file_view_rendered = View Rendered
file_view_raw = View Raw
file_permalink = Permalink
file_too_large = The file is too large to be shown.
file_is_empty = The file is empty.
code_preview_line_from_to = Lines %[1]d to %[2]d in %[3]s
code_preview_line_in = Line %[1]d in %[2]s
invisible_runes_header = `This file contains invisible Unicode characters`
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@citation-js/plugin-csl": "0.7.11",
"@citation-js/plugin-software-formats": "0.6.1",
"@github/markdown-toolbar-element": "2.2.3",
"@github/relative-time-element": "4.4.1",
"@github/relative-time-element": "4.4.2",
"@github/text-expander-element": "2.6.1",
"@mcaptcha/vanilla-glue": "0.1.0-alpha-3",
"@primer/octicons": "19.9.0",
Expand Down
4 changes: 2 additions & 2 deletions routers/api/actions/artifacts_chunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func saveUploadChunkBase(st storage.ObjectStorage, ctx *ArtifactContext,
r = io.TeeReader(r, hasher)
}
// save chunk to storage
writtenSize, err := st.Save(storagePath, r, -1)
writtenSize, err := st.Save(storagePath, r, contentSize)
if err != nil {
return -1, fmt.Errorf("save chunk to storage error: %v", err)
}
Expand Down Expand Up @@ -208,7 +208,7 @@ func mergeChunksForArtifact(ctx *ArtifactContext, chunks []*chunkFileItem, st st

// save merged file
storagePath := fmt.Sprintf("%d/%d/%d.%s", artifact.RunID%255, artifact.ID%255, time.Now().UnixNano(), extension)
written, err := st.Save(storagePath, mergedReader, -1)
written, err := st.Save(storagePath, mergedReader, artifact.FileCompressedSize)
if err != nil {
return fmt.Errorf("save merged file error: %v", err)
}
Expand Down
2 changes: 0 additions & 2 deletions routers/web/repo/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ func RefBlame(ctx *context.Context) {
}

ctx.Data["NumLines"], err = blob.GetBlobLineCount()
ctx.Data["NumLinesSet"] = true

if err != nil {
ctx.NotFound("GetBlobLineCount", err)
return
Expand Down
1 change: 1 addition & 0 deletions routers/web/repo/setting/lfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func LFSFileGet(ctx *context.Context) {
rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{})

// Building code view blocks with line number on server side.
// FIXME: the logic is not right here: it first calls EscapeControlReader then calls HTMLEscapeString: double-escaping
escapedContent := &bytes.Buffer{}
ctx.Data["EscapeStatus"], _ = charset.EscapeControlReader(rd, escapedContent, ctx.Locale)

Expand Down
7 changes: 3 additions & 4 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func renderReadmeFile(ctx *context.Context, subfolder string, readmeFile *git.Tr

ctx.Data["FileIsText"] = fInfo.isTextFile
ctx.Data["FileName"] = path.Join(subfolder, readmeFile.Name())
ctx.Data["FileSize"] = fInfo.fileSize
ctx.Data["IsLFSFile"] = fInfo.isLFSFile

if fInfo.isLFSFile {
Expand All @@ -301,7 +302,6 @@ func renderReadmeFile(ctx *context.Context, subfolder string, readmeFile *git.Tr
// Pretend that this is a normal text file to display 'This file is too large to be shown'
ctx.Data["IsFileTooLarge"] = true
ctx.Data["IsTextFile"] = true
ctx.Data["FileSize"] = fInfo.fileSize
return
}

Expand Down Expand Up @@ -552,7 +552,6 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) {
} else {
ctx.Data["NumLines"] = bytes.Count(buf, []byte{'\n'}) + 1
}
ctx.Data["NumLinesSet"] = true

language, err := files_service.TryGetContentLanguage(ctx.Repo.GitRepo, ctx.Repo.CommitID, ctx.Repo.TreePath)
if err != nil {
Expand Down Expand Up @@ -606,8 +605,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) {
break
}

// TODO: this logic seems strange, it duplicates with "isRepresentableAsText=true", it is not the same as "LFSFileGet" in "lfs.go"
// maybe for this case, the file is a binary file, and shouldn't be rendered?
// TODO: this logic duplicates with "isRepresentableAsText=true", it is not the same as "LFSFileGet" in "lfs.go"
// It is used by "external renders", markupRender will execute external programs to get rendered content.
if markupType := markup.Type(blob.Name()); markupType != "" {
rd := io.MultiReader(bytes.NewReader(buf), dataRc)
ctx.Data["IsMarkup"] = true
Expand Down
6 changes: 3 additions & 3 deletions templates/base/head_navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{end}}

<nav id="navbar" aria-label="{{ctx.Locale.Tr "aria.navbar"}}">
<div class="navbar-left ui secondary menu">
<div class="navbar-left">
<!-- the logo -->
<a class="item" id="navbar-logo" href="{{AppSubUrl}}/" aria-label="{{if .IsSigned}}{{ctx.Locale.Tr "dashboard"}}{{else}}{{ctx.Locale.Tr "home"}}{{end}}">
<img width="30" height="30" src="{{AssetUrlPrefix}}/img/logo.svg" alt="{{ctx.Locale.Tr "logo"}}" aria-hidden="true">
Expand Down Expand Up @@ -63,7 +63,7 @@
</div>

<!-- the full dropdown menus -->
<div class="navbar-right ui secondary menu">
<div class="navbar-right">
{{if and .IsSigned .MustChangePassword}}
<div class="ui dropdown jump item" data-tooltip-content="{{ctx.Locale.Tr "user_profile_and_more"}}">
<span class="text tw-flex tw-items-center">
Expand Down Expand Up @@ -106,7 +106,7 @@
<span class="not-mobile">{{svg "octicon-triangle-down"}}</span>
<span class="only-mobile">{{ctx.Locale.Tr "create_new"}}</span>
</span>
<div class="menu left">
<div class="menu">
<a class="item" href="{{AppSubUrl}}/repo/create">
{{svg "octicon-plus"}} {{ctx.Locale.Tr "new_repo"}}
</a>
Expand Down
2 changes: 2 additions & 0 deletions templates/repo/blame.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<div class="file-view code-view unicode-escaped">
{{if .IsFileTooLarge}}
{{template "shared/filetoolarge" dict "RawFileLink" .RawFileLink}}
{{else if not .FileSize}}
{{template "shared/fileisempty"}}
{{else}}
<table>
<tbody>
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/file_info.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
{{ctx.Locale.Tr "repo.symbolic_link"}}
</div>
{{end}}
{{if .NumLinesSet}}{{/* Explicit attribute needed to show 0 line changes */}}
{{if ne .NumLines nil}}
<div class="file-info-entry">
{{.NumLines}} {{ctx.Locale.TrN .NumLines "repo.line" "repo.lines"}}
</div>
{{end}}
{{if .FileSize}}
{{if ne .FileSize nil}}
<div class="file-info-entry">
{{FileSize .FileSize}}{{if .IsLFSFile}} ({{ctx.Locale.Tr "repo.stored_lfs"}}){{end}}
</div>
Expand Down
24 changes: 11 additions & 13 deletions templates/repo/issue/labels/label_list.tmpl
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<h4 class="ui top attached header">
{{ctx.Locale.Tr "repo.issues.label_count" .NumLabels}}
<div class="ui right">
<div class="ui secondary menu">
<!-- Sort -->
<div class="item ui jump dropdown tw-py-2">
<span class="text">
{{ctx.Locale.Tr "repo.issues.filter_sort"}}
</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<a class="{{if or (eq .SortType "alphabetically") (not .SortType)}}active {{end}}item" href="?sort=alphabetically&state={{$.State}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
<a class="{{if eq .SortType "reversealphabetically"}}active {{end}}item" href="?sort=reversealphabetically&state={{$.State}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
<a class="{{if eq .SortType "leastissues"}}active {{end}}item" href="?sort=leastissues&state={{$.State}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.least_issues"}}</a>
<a class="{{if eq .SortType "mostissues"}}active {{end}}item" href="?sort=mostissues&state={{$.State}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.most_issues"}}</a>
</div>
<!-- Sort -->
<div class="item ui jump dropdown tw-py-2">
<span class="text">
{{ctx.Locale.Tr "repo.issues.filter_sort"}}
</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<a class="{{if or (eq .SortType "alphabetically") (not .SortType)}}active {{end}}item" href="?sort=alphabetically&state={{$.State}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
<a class="{{if eq .SortType "reversealphabetically"}}active {{end}}item" href="?sort=reversealphabetically&state={{$.State}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
<a class="{{if eq .SortType "leastissues"}}active {{end}}item" href="?sort=leastissues&state={{$.State}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.least_issues"}}</a>
<a class="{{if eq .SortType "mostissues"}}active {{end}}item" href="?sort=mostissues&state={{$.State}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.most_issues"}}</a>
</div>
</div>
</div> <!-- filter menu -->
Expand Down
6 changes: 2 additions & 4 deletions templates/repo/settings/lfs_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
<div class="file-view{{if .IsMarkup}} markup {{.MarkupType}}{{else if .IsPlainText}} plain-text{{else if .IsTextFile}} code-view{{end}}">
{{if .IsFileTooLarge}}
{{template "shared/filetoolarge" dict "RawFileLink" .RawFileLink}}
{{else if .IsMarkup}}
{{if .FileContent}}{{.FileContent | SafeHTML}}{{end}}
{{else if .IsPlainText}}
<pre>{{if .FileContent}}{{.FileContent | SafeHTML}}{{end}}</pre>
{{else if not .FileSize}}
{{template "shared/fileisempty"}}
{{else if not .IsTextFile}}
<div class="view-raw">
{{if .IsImageFile}}
Expand Down
2 changes: 2 additions & 0 deletions templates/repo/view_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
<div class="file-view{{if .IsMarkup}} markup {{.MarkupType}}{{else if .IsPlainText}} plain-text{{else if .IsTextSource}} code-view{{end}}">
{{if .IsFileTooLarge}}
{{template "shared/filetoolarge" dict "RawFileLink" .RawFileLink}}
{{else if not .FileSize}}
{{template "shared/fileisempty"}}
{{else if .IsMarkup}}
{{if .FileContent}}{{.FileContent}}{{end}}
{{else if .IsPlainText}}
Expand Down
3 changes: 3 additions & 0 deletions templates/shared/fileisempty.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="file-not-rendered-prompt">
{{ctx.Locale.Tr "repo.file_is_empty"}}
</div>
2 changes: 1 addition & 1 deletion templates/shared/filetoolarge.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="tw-p-4">
<div class="file-not-rendered-prompt">
{{ctx.Locale.Tr "repo.file_too_large"}}
{{if .RawFileLink}}<a href="{{.RawFileLink}}" rel="nofollow">{{ctx.Locale.Tr "repo.file_view_raw"}}</a>{{end}}
</div>
12 changes: 2 additions & 10 deletions templates/shared/user/profile_big_avatar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,8 @@
<li>
{{svg "octicon-mail"}}
<a class="tw-flex-1" href="mailto:{{.ContextUser.Email}}" rel="nofollow">{{.ContextUser.Email}}</a>
<a href="{{AppSubUrl}}/user/settings#privacy-user-settings">
{{if .ShowUserEmail}}
<i data-tooltip-content="{{ctx.Locale.Tr "user.email_visibility.limited"}}">
{{svg "octicon-unlock"}}
</i>
{{else}}
<i data-tooltip-content="{{ctx.Locale.Tr "user.email_visibility.private"}}">
{{svg "octicon-lock"}}
</i>
{{end}}
<a class="flex-text-inline" href="{{AppSubUrl}}/user/settings#privacy-user-settings" data-tooltip-content="{{ctx.Locale.Tr (Iif .ShowUserEmail "user.email_visibility.limited" "user.email_visibility.private")}}">
{{svg (Iif .ShowUserEmail "octicon-unlock" "octicon-lock")}}
</a>
</li>
{{else}}
Expand Down
6 changes: 1 addition & 5 deletions templates/user/dashboard/issues.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@
<input type="hidden" name="type" value="{{$.ViewType}}">
<input type="hidden" name="sort" value="{{$.SortType}}">
<input type="hidden" name="state" value="{{$.State}}">
{{if .PageIsPulls}}
{{template "shared/search/combo_fuzzy" dict "Value" $.Keyword "IsFuzzy" $.IsFuzzy "Placeholder" (ctx.Locale.Tr "search.pull_kind") "Tooltip" (ctx.Locale.Tr "explorer.go")}}
{{else}}
{{template "shared/search/combo_fuzzy" dict "Value" $.Keyword "IsFuzzy" $.IsFuzzy "Placeholder" (ctx.Locale.Tr "search.issue_kind") "Tooltip" (ctx.Locale.Tr "explorer.go")}}
{{end}}
{{template "shared/search/combo_fuzzy" dict "Value" $.Keyword "IsFuzzy" $.IsFuzzy "Placeholder" (ctx.Locale.Tr (Iif .PageIsPulls "search.pull_kind" "search.issue_kind")) "Tooltip" (ctx.Locale.Tr "explore.go_to")}}
</div>
</form>
<!-- Sort -->
Expand Down
9 changes: 9 additions & 0 deletions web_src/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,13 @@ overflow-menu .ui.label {
padding: 0 8px;
text-align: right !important;
color: var(--color-text-light-2);
width: 1%; /* this apparently needs to be a percentage so that code column stretches in diffs */
min-width: 72px;
white-space: nowrap;
}

.code-diff .lines-num {
min-width: 50px;
}

.lines-num span.bottom-line::after {
Expand All @@ -1020,6 +1027,7 @@ overflow-menu .ui.label {

.lines-type-marker {
vertical-align: top;
white-space: nowrap;
}

.lines-num,
Expand Down Expand Up @@ -1052,6 +1060,7 @@ overflow-menu .ui.label {

.lines-escape {
width: 0;
white-space: nowrap;
}

.lines-code {
Expand Down
6 changes: 0 additions & 6 deletions web_src/css/modules/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ h4.ui.header .sub.header {
font-weight: var(--font-weight-normal);
}

/* open dropdown menus to the left in right-attached headers */
.ui.attached.header > .ui.right .ui.dropdown .menu {
right: 0;
left: auto;
}

/* if a .top.attached.header is followed by a .segment, add some margin */
.ui.segments + .ui.top.attached.header,
.ui.attached.segment + .ui.top.attached.header {
Expand Down
20 changes: 15 additions & 5 deletions web_src/css/modules/navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,26 @@
margin: 0;
display: flex;
align-items: center;
gap: 5px;
}

#navbar-logo {
margin: 0;
}

.navbar-left > .item,
.navbar-right > .item {
color: var(--color-nav-text);
position: relative;
text-decoration: none;
line-height: var(--line-height-default);
flex: 0 0 auto;
font-weight: var(--font-weight-normal);
align-items: center;
padding: .78571429em .92857143em;
border-radius: .28571429rem;
}

#navbar .item {
min-height: 36px;
min-width: 36px;
Expand All @@ -33,10 +47,6 @@
display: flex;
}

#navbar > .menu > .item {
color: var(--color-nav-text);
}

#navbar .dropdown .item {
justify-content: stretch;
}
Expand Down Expand Up @@ -70,7 +80,7 @@
}
#navbar .navbar-mobile-right {
display: flex;
margin-left: auto !important;
margin: 0 0 0 auto !important;
width: auto !important;
}
#navbar .navbar-mobile-right > .item {
Expand Down
Loading

0 comments on commit 5b45fc8

Please sign in to comment.