Fix various problems (#37029)
1. Use "margin/padding inline" * Fix #37027 2. Make DetectWellKnownMimeType fallback to system mime types 3. Make catFileBatchCommunicator close pipes * Old behavior in 1.25: https://github.com/go-gitea/gitea/blob/release/v1.25/modules/git/batch_reader.go#L45-L55 * Try to fix #37028
This commit is contained in:
@@ -22,16 +22,16 @@ import (
|
|||||||
var catFileBatchDebugWaitClose atomic.Int64
|
var catFileBatchDebugWaitClose atomic.Int64
|
||||||
|
|
||||||
type catFileBatchCommunicator struct {
|
type catFileBatchCommunicator struct {
|
||||||
cancel context.CancelFunc
|
closeFunc func(err error)
|
||||||
reqWriter io.Writer
|
reqWriter io.Writer
|
||||||
respReader *bufio.Reader
|
respReader *bufio.Reader
|
||||||
debugGitCmd *gitcmd.Command
|
debugGitCmd *gitcmd.Command
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *catFileBatchCommunicator) Close() {
|
func (b *catFileBatchCommunicator) Close() {
|
||||||
if b.cancel != nil {
|
if b.closeFunc != nil {
|
||||||
b.cancel()
|
b.closeFunc(nil)
|
||||||
b.cancel = nil
|
b.closeFunc = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,10 +47,19 @@ func newCatFileBatch(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Co
|
|||||||
}
|
}
|
||||||
stdPipeClose()
|
stdPipeClose()
|
||||||
}
|
}
|
||||||
|
closeFunc := func(err error) {
|
||||||
|
ctxCancel(err)
|
||||||
|
pipeClose()
|
||||||
|
}
|
||||||
|
return newCatFileBatchWithCloseFunc(ctx, repoPath, cmdCatFile, stdinWriter, stdoutReader, closeFunc)
|
||||||
|
}
|
||||||
|
|
||||||
ret = &catFileBatchCommunicator{
|
func newCatFileBatchWithCloseFunc(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Command,
|
||||||
|
stdinWriter gitcmd.PipeWriter, stdoutReader gitcmd.PipeReader, closeFunc func(err error),
|
||||||
|
) *catFileBatchCommunicator {
|
||||||
|
ret := &catFileBatchCommunicator{
|
||||||
debugGitCmd: cmdCatFile,
|
debugGitCmd: cmdCatFile,
|
||||||
cancel: func() { ctxCancel(nil) },
|
closeFunc: closeFunc,
|
||||||
reqWriter: stdinWriter,
|
reqWriter: stdinWriter,
|
||||||
respReader: bufio.NewReaderSize(stdoutReader, 32*1024), // use a buffered reader for rich operations
|
respReader: bufio.NewReaderSize(stdoutReader, 32*1024), // use a buffered reader for rich operations
|
||||||
}
|
}
|
||||||
@@ -60,8 +69,7 @@ func newCatFileBatch(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Co
|
|||||||
log.Error("Unable to start git command %v: %v", cmdCatFile.LogString(), err)
|
log.Error("Unable to start git command %v: %v", cmdCatFile.LogString(), err)
|
||||||
// ideally here it should return the error, but it would require refactoring all callers
|
// ideally here it should return the error, but it would require refactoring all callers
|
||||||
// so just return a dummy communicator that does nothing, almost the same behavior as before, not bad
|
// so just return a dummy communicator that does nothing, almost the same behavior as before, not bad
|
||||||
ctxCancel(err)
|
closeFunc(err)
|
||||||
pipeClose()
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +78,7 @@ func newCatFileBatch(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Co
|
|||||||
if err != nil && !errors.Is(err, context.Canceled) {
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
log.Error("cat-file --batch command failed in repo %s, error: %v", repoPath, err)
|
log.Error("cat-file --batch command failed in repo %s, error: %v", repoPath, err)
|
||||||
}
|
}
|
||||||
ctxCancel(err)
|
closeFunc(err)
|
||||||
pipeClose()
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
@@ -4,11 +4,15 @@
|
|||||||
package public
|
package public
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"mime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// wellKnownMimeTypesLower comes from Golang's builtin mime package: `builtinTypesLower`, see the comment of DetectWellKnownMimeType
|
// wellKnownMimeTypesLower comes from Golang's builtin mime package: `builtinTypesLower`,
|
||||||
var wellKnownMimeTypesLower = map[string]string{
|
// see the comment of DetectWellKnownMimeType
|
||||||
|
var wellKnownMimeTypesLower = sync.OnceValue(func() map[string]string {
|
||||||
|
return map[string]string{
|
||||||
".avif": "image/avif",
|
".avif": "image/avif",
|
||||||
".css": "text/css; charset=utf-8",
|
".css": "text/css; charset=utf-8",
|
||||||
".gif": "image/gif",
|
".gif": "image/gif",
|
||||||
@@ -28,7 +32,8 @@ var wellKnownMimeTypesLower = map[string]string{
|
|||||||
|
|
||||||
// well, there are some types missing from the builtin list
|
// well, there are some types missing from the builtin list
|
||||||
".txt": "text/plain; charset=utf-8",
|
".txt": "text/plain; charset=utf-8",
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// DetectWellKnownMimeType will return the mime-type for a well-known file ext name
|
// DetectWellKnownMimeType will return the mime-type for a well-known file ext name
|
||||||
// The purpose of this function is to bypass the unstable behavior of Golang's mime.TypeByExtension
|
// The purpose of this function is to bypass the unstable behavior of Golang's mime.TypeByExtension
|
||||||
@@ -38,5 +43,8 @@ var wellKnownMimeTypesLower = map[string]string{
|
|||||||
// DetectWellKnownMimeType makes the Content-Type for well-known files stable.
|
// DetectWellKnownMimeType makes the Content-Type for well-known files stable.
|
||||||
func DetectWellKnownMimeType(ext string) string {
|
func DetectWellKnownMimeType(ext string) string {
|
||||||
ext = strings.ToLower(ext)
|
ext = strings.ToLower(ext)
|
||||||
return wellKnownMimeTypesLower[ext]
|
if s, ok := wellKnownMimeTypesLower()[ext]; ok {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return mime.TypeByExtension(ext)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,8 @@
|
|||||||
|
|
||||||
.markup .anchor {
|
.markup .anchor {
|
||||||
float: left;
|
float: left;
|
||||||
padding-right: 4px;
|
padding-inline-end: 4px;
|
||||||
margin-left: -20px;
|
margin-inline-start: -20px;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ In markup content, we always use bottom margin for all elements */
|
|||||||
|
|
||||||
.markup ul,
|
.markup ul,
|
||||||
.markup ol {
|
.markup ol {
|
||||||
padding-left: 2em;
|
padding-inline-start: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markup ul.no-list,
|
.markup ul.no-list,
|
||||||
@@ -173,13 +173,14 @@ In markup content, we always use bottom margin for all elements */
|
|||||||
}
|
}
|
||||||
|
|
||||||
.markup .task-list-item input[type="checkbox"] {
|
.markup .task-list-item input[type="checkbox"] {
|
||||||
margin: 0 .6em .25em -1.4em;
|
margin-bottom: 0.25em;
|
||||||
|
margin-inline: -1.4em 0.6em;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markup .task-list-item input[type="checkbox"] + p {
|
.markup .task-list-item input[type="checkbox"] + p {
|
||||||
margin-left: -0.2em;
|
margin-inline-start: -0.2em;
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +193,7 @@ In markup content, we always use bottom margin for all elements */
|
|||||||
}
|
}
|
||||||
|
|
||||||
.markup input[type="checkbox"] {
|
.markup input[type="checkbox"] {
|
||||||
margin-right: .25em;
|
margin-inline-end: .25em;
|
||||||
margin-bottom: .25em;
|
margin-bottom: .25em;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
opacity: 1 !important; /* override fomantic on edit preview */
|
opacity: 1 !important; /* override fomantic on edit preview */
|
||||||
@@ -239,7 +240,7 @@ In markup content, we always use bottom margin for all elements */
|
|||||||
}
|
}
|
||||||
|
|
||||||
.markup blockquote {
|
.markup blockquote {
|
||||||
margin-left: 0;
|
margin-inline-start: 0;
|
||||||
padding: 0 15px;
|
padding: 0 15px;
|
||||||
color: var(--color-text-light-2);
|
color: var(--color-text-light-2);
|
||||||
border-left: 0.25em solid var(--color-secondary);
|
border-left: 0.25em solid var(--color-secondary);
|
||||||
@@ -318,12 +319,12 @@ html[data-gitea-theme-dark="false"] .markup img[src*="#gh-dark-mode-only"] {
|
|||||||
|
|
||||||
.markup img[align="right"],
|
.markup img[align="right"],
|
||||||
.markup video[align="right"] {
|
.markup video[align="right"] {
|
||||||
padding-left: 20px;
|
padding-inline-start: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markup img[align="left"],
|
.markup img[align="left"],
|
||||||
.markup video[align="left"] {
|
.markup video[align="left"] {
|
||||||
padding-right: 28px;
|
padding-inline-end: 28px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markup span.frame {
|
.markup span.frame {
|
||||||
@@ -395,7 +396,7 @@ html[data-gitea-theme-dark="false"] .markup img[src*="#gh-dark-mode-only"] {
|
|||||||
.markup span.float-left {
|
.markup span.float-left {
|
||||||
display: block;
|
display: block;
|
||||||
float: left;
|
float: left;
|
||||||
margin-right: 13px;
|
margin-inline-end: 13px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,7 +407,7 @@ html[data-gitea-theme-dark="false"] .markup img[src*="#gh-dark-mode-only"] {
|
|||||||
.markup span.float-right {
|
.markup span.float-right {
|
||||||
display: block;
|
display: block;
|
||||||
float: right;
|
float: right;
|
||||||
margin-left: 13px;
|
margin-inline-start: 13px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,7 +509,7 @@ html[data-gitea-theme-dark="false"] .markup img[src*="#gh-dark-mode-only"] {
|
|||||||
.markup .ui.list .list,
|
.markup .ui.list .list,
|
||||||
.markup ol.ui.list ol,
|
.markup ol.ui.list ol,
|
||||||
.markup ul.ui.list ul {
|
.markup ul.ui.list ul {
|
||||||
padding-left: 2em;
|
padding-inline-start: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markup details.frontmatter-content summary {
|
.markup details.frontmatter-content summary {
|
||||||
|
|||||||
Reference in New Issue
Block a user