Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main:
  Add API to serve blob or LFS file content (go-gitea#19689)
  Disable unnecessary mirroring elements (go-gitea#18527)
  [skip ci] Updated translations via Crowdin
  Remove customized (unmaintained) dropdown, improve aria a11y for dropdown (go-gitea#19861)
  Set Setpgid on child git processes (go-gitea#19865)
  • Loading branch information
zjjhot committed Jun 4, 2022
2 parents 47430a5 + df9612b commit ed4bb80
Show file tree
Hide file tree
Showing 30 changed files with 509 additions and 4,471 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ fomantic:
cd $(FOMANTIC_WORK_DIR) && npm install --no-save
cp -f $(FOMANTIC_WORK_DIR)/theme.config.less $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/theme.config
cp -rf $(FOMANTIC_WORK_DIR)/_site $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/
cp -f web_src/js/vendor/dropdown.js $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/definitions/modules
cd $(FOMANTIC_WORK_DIR) && npx gulp -f node_modules/fomantic-ui/gulpfile.js build
rm -f $(FOMANTIC_WORK_DIR)/build/*.min.*

Expand Down
2 changes: 2 additions & 0 deletions cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/pprof"
"code.gitea.io/gitea/modules/private"
"code.gitea.io/gitea/modules/process"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/lfs"
Expand Down Expand Up @@ -306,6 +307,7 @@ func runServ(c *cli.Context) error {
}
}

process.SetSysProcAttribute(gitcmd)
gitcmd.Dir = setting.RepoRootPath
gitcmd.Stdout = os.Stdout
gitcmd.Stdin = os.Stdin
Expand Down
2 changes: 1 addition & 1 deletion custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ PATH =
;[mirror]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Enables the mirror functionality. Set to **false** to disable all mirrors.
;; Enables the mirror functionality. Set to **false** to disable all mirrors. Pre-existing mirrors remain valid but won't be updated; may be converted to regular repo.
;ENABLED = true
;; Disable the creation of **new** pull mirrors. Pre-existing mirrors remain valid. Will be ignored if `mirror.ENABLED` is `false`.
;DISABLE_NEW_PULL = false
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ Task queue configuration has been moved to `queue.task`. However, the below conf

## Mirror (`mirror`)

- `ENABLED`: **true**: Enables the mirror functionality. Set to **false** to disable all mirrors.
- `ENABLED`: **true**: Enables the mirror functionality. Set to **false** to disable all mirrors. Pre-existing mirrors remain valid but won't be updated; may be converted to regular repo.
- `DISABLE_NEW_PULL`: **false**: Disable the creation of **new** pull mirrors. Pre-existing mirrors remain valid. Will be ignored if `mirror.ENABLED` is `false`.
- `DISABLE_NEW_PUSH`: **false**: Disable the creation of **new** push mirrors. Pre-existing mirrors remain valid. Will be ignored if `mirror.ENABLED` is `false`.
- `DEFAULT_INTERVAL`: **8h**: Default interval between each check
Expand Down
56 changes: 56 additions & 0 deletions integrations/api_repo_file_get_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package integrations

import (
"net/http"
"net/url"
"os"
"testing"

api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"

"github.com/stretchr/testify/assert"
)

func TestAPIGetRawFileOrLFS(t *testing.T) {
defer prepareTestEnv(t)()

// Test with raw file
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/media/README.md")
resp := MakeRequest(t, req, http.StatusOK)
assert.Equal(t, "# repo1\n\nDescription for repo1", resp.Body.String())

// Test with LFS
onGiteaRun(t, func(t *testing.T, u *url.URL) {
httpContext := NewAPITestContext(t, "user2", "repo-lfs-test")
doAPICreateRepository(httpContext, false, func(t *testing.T, repository api.Repository) {
u.Path = httpContext.GitPath()
dstPath, err := os.MkdirTemp("", httpContext.Reponame)
assert.NoError(t, err)
defer util.RemoveAll(dstPath)

u.Path = httpContext.GitPath()
u.User = url.UserPassword("user2", userPassword)

t.Run("Clone", doGitClone(dstPath, u))

dstPath2, err := os.MkdirTemp("", httpContext.Reponame)
assert.NoError(t, err)
defer util.RemoveAll(dstPath2)

t.Run("Partial Clone", doPartialGitClone(dstPath2, u))

lfs, _ := lfsCommitAndPushTest(t, dstPath)

reqLFS := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/media/"+lfs)
respLFS := MakeRequestNilResponseRecorder(t, reqLFS, http.StatusOK)
assert.Equal(t, littleSize, respLFS.Length)

doAPIDeleteRepository(httpContext)
})
})
}
1 change: 1 addition & 0 deletions modules/git/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func createBlameReader(ctx context.Context, dir string, command ...string) (*Bla
cmd := exec.CommandContext(ctx, command[0], command[1:]...)
cmd.Dir = dir
cmd.Stderr = os.Stderr
process.SetSysProcAttribute(cmd)

stdout, err := cmd.StdoutPipe()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions modules/git/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (c *Command) Run(opts *RunOpts) error {
"GIT_NO_REPLACE_OBJECTS=1",
)

process.SetSysProcAttribute(cmd)
cmd.Dir = opts.Dir
cmd.Stdout = opts.Stdout
cmd.Stderr = opts.Stderr
Expand Down
2 changes: 2 additions & 0 deletions modules/markup/external/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.
cmd.Stdin = input
}
cmd.Stdout = output
process.SetSysProcAttribute(cmd)

if err := cmd.Run(); err != nil {
return fmt.Errorf("%s render run command %s %v failed: %v", p.Name(), commands[0], args, err)
}
Expand Down
1 change: 1 addition & 0 deletions modules/process/manager_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (pm *Manager) ExecDirEnvStdIn(ctx context.Context, timeout time.Duration, d
if stdIn != nil {
cmd.Stdin = stdIn
}
SetSysProcAttribute(cmd)

if err := cmd.Start(); err != nil {
return "", "", err
Expand Down
18 changes: 18 additions & 0 deletions modules/process/manager_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !windows

package process

import (
"os/exec"
"syscall"
)

// SetSysProcAttribute sets the common SysProcAttrs for commands
func SetSysProcAttribute(cmd *exec.Cmd) {
// When Gitea runs SubProcessA -> SubProcessB and SubProcessA gets killed by context timeout, use setpgid to make sure the sub processes can be reaped instead of leaving defunct(zombie) processes.
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
}
16 changes: 16 additions & 0 deletions modules/process/manager_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build windows

package process

import (
"os/exec"
)

// SetSysProcAttribute sets the common SysProcAttrs for commands
func SetSysProcAttribute(cmd *exec.Cmd) {
// Do nothing
}
2 changes: 2 additions & 0 deletions modules/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func sessionHandler(session ssh.Session) {
}
defer stdin.Close()

process.SetSysProcAttribute(cmd)

wg := &sync.WaitGroup{}
wg.Add(2)

Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,6 @@ need_auth = Authorization
migrate_options = Migration Options
migrate_service = Migration Service
migrate_options_mirror_helper = This repository will be a <span class="text blue">mirror</span>
migrate_options_mirror_disabled = Your site administrator has disabled new mirrors.
migrate_options_lfs = Migrate LFS files
migrate_options_lfs_endpoint.label = LFS Endpoint
migrate_options_lfs_endpoint.description = Migration will attempt to use your Git remote to <a target="_blank" rel="noopener noreferrer" href="%s">determine the LFS server</a>. You can also specify a custom endpoint if the repository LFS data is stored somewhere else.
Expand Down
14 changes: 13 additions & 1 deletion options/locale/locale_zh-TW.ini
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ error404=您正嘗試訪問的頁面 <strong>不存在</strong> 或 <strong>您

never=從來沒有

rss_feed=RSS 摘要

[error]
occurred=發生錯誤
Expand Down Expand Up @@ -496,7 +497,7 @@ target_branch_not_exist=目標分支不存在
[user]
change_avatar=更改大頭貼...
join_on=加入於
repositories=儲存庫列表
repositories=儲存庫
activity=公開動態
followers=追蹤者
starred=已加星號
Expand Down Expand Up @@ -775,6 +776,7 @@ webauthn_delete_key_desc=如果您移除安全金鑰,將不能再使用它登
manage_account_links=管理已連結的帳戶
manage_account_links_desc=這些外部帳戶已連結到您的 Gitea 帳戶。
account_links_not_available=目前沒有連結到您的 Gitea 帳戶的外部帳戶
link_account=連結帳戶
remove_account_link=刪除已連結的帳戶
remove_account_link_desc=刪除連結帳戶將撤銷其對 Gitea 帳戶的存取權限。是否繼續?
remove_account_link_success=已移除連結的帳戶。
Expand Down Expand Up @@ -1038,6 +1040,7 @@ line_unicode=`這一行有隱藏的 Unicode 字元`
escape_control_characters=Escape
unescape_control_characters=Unescape
file_copy_permalink=複製固定連結
view_git_blame=檢視 Git Blame
video_not_supported_in_browser=您的瀏覽器不支援使用 HTML5 播放影片。
audio_not_supported_in_browser=您的瀏覽器不支援 HTML5 的「audio」標籤
stored_lfs=已使用 Git LFS 儲存
Expand Down Expand Up @@ -1458,6 +1461,7 @@ issues.review.add_review_request=請求了 %s 來審核 %s
issues.review.remove_review_request=移除了對 %s 的審核請求 %s
issues.review.remove_review_request_self=拒絕了審核 %s
issues.review.pending=待處理
issues.review.pending.tooltip=目前其他使用者還不能看見此留言。要送出您待定的留言請在頁面最上方選擇「%s」->「%s/%s/%s」。
issues.review.review=審核
issues.review.reviewers=審核者
issues.review.outdated=過時的
Expand All @@ -1476,6 +1480,7 @@ issues.content_history.created=建立
issues.content_history.delete_from_history=刪除歷程記錄
issues.content_history.delete_from_history_confirm=刪除歷程記錄?
issues.content_history.options=選項
issues.reference_link=參考: %s

compare.compare_base=基底分支
compare.compare_head=比較
Expand All @@ -1484,6 +1489,9 @@ pulls.desc=啟用合併請求和程式碼審核。
pulls.new=建立合併請求
pulls.view=檢視合併請求
pulls.compare_changes=建立合併請求
pulls.allow_edits_from_maintainers=允許維護者編輯
pulls.allow_edits_from_maintainers_desc=對基礎分支有寫入權限的使用者也可以推送到此分支
pulls.allow_edits_from_maintainers_err=更新失敗
pulls.compare_changes_desc=選擇合併的目標分支和來源分支。
pulls.compare_base=合併到
pulls.compare_compare=拉取自
Expand Down Expand Up @@ -2391,6 +2399,7 @@ dashboard.new_version_hint=現已推出 Gitea %s,您正在執行 %s。查看<a
dashboard.statistic=摘要
dashboard.operations=維護作業
dashboard.system_status=系統狀態
dashboard.statistic_info=Gitea 資料庫統計: <b>%d</b> 位使用者,<b>%d</b> 個組織,<b>%d</b> 個公鑰,<b>%d</b> 個儲存庫,<b>%d</b> 個儲存庫關注,<b>%d</b> 個星號,~<b>%d</b> 次行為,<b>%d</b> 條權限記錄,<b>%d</b> 個問題,<b>%d</b> 則留言,<b>%d</b> 個社群帳戶,<b>%d</b> 個使用者關注,<b>%d</b> 個鏡像,<b>%d</b> 個版本發佈,<b>%d</b> 個認證來源,<b>%d</b> 個 Webhook ,<b>%d</b> 個里程碑,<b>%d</b> 個標籤,<b>%d</b> 個 Hook 任務,<b>%d</b> 個團隊,<b>%d</b> 個更新任務,<b>%d</b> 個附件。
dashboard.operation_name=作業名稱
dashboard.operation_switch=開關
dashboard.operation_run=執行
Expand Down Expand Up @@ -2496,6 +2505,7 @@ users.allow_import_local=可以匯入本地儲存庫
users.allow_create_organization=可以建立組織
users.update_profile=更新使用者帳戶
users.delete_account=刪除使用者帳戶
users.cannot_delete_self=您無法刪除您自己
users.still_own_repo=這個使用者還擁有一個或更多的儲存庫。請先刪除或是轉移這些儲存庫。
users.still_has_org=此使用者是組織的成員。請先將他從組織中移除。
users.deletion_success=使用者帳戶已被刪除。
Expand Down Expand Up @@ -2812,6 +2822,8 @@ monitor.next=下次執行時間
monitor.previous=上次執行時間
monitor.execute_times=執行次數
monitor.process=執行中的處理程序
monitor.stacktrace=堆疊追蹤
monitor.goroutines=%d 個 Goroutines
monitor.desc=描述
monitor.start=開始時間
monitor.execute_time=已執行時間
Expand Down
1 change: 1 addition & 0 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ func Routes() *web.Route {
Delete(reqAdmin(), repo.DeleteTeam)
}, reqToken())
m.Get("/raw/*", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFile)
m.Get("/media/*", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFileOrLFS)
m.Get("/archive/*", reqRepoReader(unit.TypeCode), repo.GetArchive)
m.Combo("/forks").Get(repo.ListForks).
Post(reqToken(), reqRepoReader(unit.TypeCode), bind(api.CreateForkOption{}), repo.CreateFork)
Expand Down
Loading

0 comments on commit ed4bb80

Please sign in to comment.