From 4d27a88f6dc43186fe16deb21e48c8442a6df904 Mon Sep 17 00:00:00 2001 From: J23 Date: Mon, 23 Dec 2024 11:36:16 +0800 Subject: [PATCH] standardize some configuration parsing --- .gitignore | 1 + Makefile | 2 +- VERSION | 2 +- bali.toml | 2 +- cmd/zeta-mc/crate.toml | 2 +- cmd/zeta/crate.toml | 2 +- docs/config.md | 29 +++++++++++++++++++++++++++++ docs/env.md | 26 -------------------------- pkg/command/command_diff.go | 5 ++--- pkg/zeta/blame.go | 2 +- pkg/zeta/hastyhex_test.go | 2 +- pkg/zeta/merge_file.go | 10 +++++----- pkg/zeta/repository.go | 14 ++++++++++++++ pkg/zeta/worktree_diff.go | 11 ++++++----- 14 files changed, 64 insertions(+), 46 deletions(-) create mode 100644 docs/config.md delete mode 100644 docs/env.md diff --git a/.gitignore b/.gitignore index da16254..5453d16 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ local/* *.gop1 *.tomlp1 *.rej +*.mdp1 /out/ /.vscode/ .idea/* diff --git a/Makefile b/Makefile index cd58879..95acffc 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ SOURCE_DIR := $(abspath $(dir $(lastword ${MAKEFILE_LIST}))) BUILD_DIR := ${SOURCE_DIR}/_build BUILD_TIME := $(shell date +'%Y-%m-%dT%H:%M:%S%z') BUILD_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo 'none') -BUILD_VERSION := $(shell cat VERSION || echo '0.16.1') +BUILD_VERSION := $(shell cat VERSION || echo '0.16.2') GO_PACKAGES := $(shell go list ./... | grep -v '^${PKG}/mock/' | grep -v '^${PKG}/proto/') GO_LDFLAGS := -ldflags '-X ${PKG}/pkg/version.version=${BUILD_VERSION} -X ${PKG}/pkg/version.buildTime=${BUILD_TIME} -X ${PKG}/pkg/version.buildCommit=${BUILD_COMMIT}' diff --git a/VERSION b/VERSION index 92e0c74..3b7660a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.16.1 \ No newline at end of file +0.16.2 \ No newline at end of file diff --git a/bali.toml b/bali.toml index eacea3c..d66b634 100644 --- a/bali.toml +++ b/bali.toml @@ -3,7 +3,7 @@ name = "zeta" summary = "HugeSCM - A next generation cloud-based version control system" description = "HugeSCM - A next generation cloud-based version control system" package-name = "alipay-linkc-zeta" -version = "0.16.1" +version = "0.16.2" license = "MIT" prefix = "/usr/local" packager = "江二" diff --git a/cmd/zeta-mc/crate.toml b/cmd/zeta-mc/crate.toml index 4c2671a..627704a 100644 --- a/cmd/zeta-mc/crate.toml +++ b/cmd/zeta-mc/crate.toml @@ -1,7 +1,7 @@ name = "zeta-mc" description = "zeta-mc - Migrate Git repository to zeta" destination = "bin" -version = "0.16.1" +version = "0.16.2" goflags = [ "-ldflags", "-X github.com/antgroup/hugescm/pkg/version.version=$BUILD_VERSION -X github.com/antgroup/hugescm/pkg/version.buildTime=$BUILD_TIME -X github.com/antgroup/hugescm/pkg/version.buildCommit=$BUILD_COMMIT", diff --git a/cmd/zeta/crate.toml b/cmd/zeta/crate.toml index f6ca5a9..7f33da1 100644 --- a/cmd/zeta/crate.toml +++ b/cmd/zeta/crate.toml @@ -1,7 +1,7 @@ name = "zeta" description = "HugeSCM - A next generation cloud-based version control system" destination = "bin" -version = "0.16.1" +version = "0.16.2" goflags = [ "-ldflags", "-X github.com/antgroup/hugescm/pkg/version.version=$BUILD_VERSION -X github.com/antgroup/hugescm/pkg/version.buildTime=$BUILD_TIME -X github.com/antgroup/hugescm/pkg/version.buildCommit=$BUILD_COMMIT", diff --git a/docs/config.md b/docs/config.md new file mode 100644 index 0000000..73c6871 --- /dev/null +++ b/docs/config.md @@ -0,0 +1,29 @@ +# HugeSCM 支持的配置和环境变量备忘录 + +| 配置 | 环境变量 | 备注 | +| :--- | :--- | :--- | +| `core.sharingRoot` | `ZETA_CORE_SHARING_ROOT` | 该配置用于指定 blob 存储的 root,以表明用户试图在多个存储库中复用 blob 对象,用来降低磁盘存储。 | +| `core.sparse`||存储库稀疏检出配置,用户不应设置在全局修改该配置,可以在存储库级别修改| +| `core.remote`||存储库远程设置,通常不宜修改此配置| +| `user.name`
| `ZETA_AUTHOR_NAME` | 作者名 | +| | `ZETA_COMMITTER_NAME` | 提交者 | +| `user.email`
| `ZETA_AUTHOR_EMAIL` | 作者邮箱 | +| | `ZETA_COMMITTER_EMAIL` | 提交者邮箱 | +| | `ZETA_AUTHOR_DATE` | 作者签名时间 | +| | `ZETA_COMMITTER_DATE` | 提交时间 | +| `core.accelerator` | `ZETA_CORE_ACCELERATOR` | 下载加速器 | +| `core.optimizeStrategy` | `ZETA_CORE_OPTIMIZE_STRATEGY` | 存储库空间管理策略 | +| `core.concurrenttransfers` | `ZETA_CORE_CONCURRENT_TRANSFERS` | 大文件下载时的并发策略 | +| | `ZETA_CORE_PROMISOR` | 按需下载标志(默认开启,设置为 false 时关闭) | +| `core.editor` | `ZETA_EDITOR`,兼容 `GIT_EDITOR/EDITOR` | 提交信息/标签编辑时的编辑器,默认会搜索 VIM 等。 | +| | `ZETA_MERGE_TEXT_DRIVER` | 文本合并工具,未设置时是使用内置实现,可以设置为 `git`,设置后我们将使用 git merge-file 来做三路合并。 | +| | `ZETA_SSL_NO_VERIFY` | 是否禁用 SSL 验证 | +| `http.sslVerify` | | 与 `ZETA_SSL_NO_VERIFY`刚好相反,只有显式设置为 false 才会禁用 SSL 验证。 | +| `http.extraHeader` | | 设置 HTTP 附加头,如果设置了 `Authorization`,客户端会跳过自身的权限预验证,该机制可以实现一些自定义的能力。 | +| `transport.maxEntries`|`ZETA_TRANSPORT_MAX_ENTRIES`|设置 batch 下载对象数量限制,影响 batch 接口调用次数| +| `transport.largeSize`|`ZETA_TRANSPORT_LARGE_SIZE`|设置大文件大小,默认 10M| +| `transport.externalProxy`|`ZETA_TRANSPORT_EXTERNAL_PROXY`|为 `direct` 下载配置外部代理| +| `diff.algorithm`||diff 算法,支持:`histogram`,`onp`,`myers`,`patience`,`minimal`| +| `merge.conflictStyle`||指定在合并时将存在冲突的代码块写入工作区文件的样式,支持 `merge`,`diff3`,`zdiff3`| +||`ZETA_PAGER/PAGER`|终端分页工具,未设置时会搜索 less 命令行,可设置 `PAGER=""` 禁用分页,Windows 下请安装 less for windows。| +| | `ZETA_TERMINAL_PROMPT` | 显式设置 false 时禁用终端,此时客户端就失去 CUI 交互能力。 | diff --git a/docs/env.md b/docs/env.md deleted file mode 100644 index 900d1a4..0000000 --- a/docs/env.md +++ /dev/null @@ -1,26 +0,0 @@ -# HugeSCM 支持的环境变量备忘录 - -## 客户端行为 - -+ `ZETA_TERMINAL_PROMPT` 该环境变量控制是否开启终端提示符,对于需要在命令行交互的(如输入用户名和密码),未设置此值会影响该功能。 -+ `ZETA_TRACE` 开启 zeta 调试模式 -+ `ZETA_EXTENSION_DRAGONFLY_GET` 设置 `dfget` 路径。 -+ `ZETA_SHARING_ROOT` 设置 `core.shardingRoot` 目录,该配置存在时,zeta 会使用该变量设置的目录作为 BLOB 的存储目录。 -+ `ZETA_TRANSPORT_MAX_ENTRIES` 指定批量下载对象一次性下载数量,默认 32000,用户可以修改。 -+ `ZETA_TRANSPORT_LARGE_SIZE` 将指定大小的文件试为大文件,使用单个文件下载接口,默认为 10M,用户可以指定 `ZETA_TRANSPORT_LARGE_SIZE=512k`。 - -## 注入配置 - -请注意,通过环境修改的配置仅对当前进程有效,不会覆盖配置文件中的配置。 - -+ `ZETA_CORE_OPTIMIZE_STRATEGY` 存储库优化策略,支持 `heuristical`,`eager`,`extreme`,其中 `extreme` 模式会删除所有超过 50M 的 blob,该行为比较极端,多数情况无需开启。 -+ `ZETA_CORE_ACCELERATOR` 存储库下载加速器,目前只支持 `dragonfly` (dragonfly P2P 加速)和 `aria2`(aria2 加速) 以及 `direct` (oss 直连下载,不走 zeta), 可以使用 `ZETA_EXTENSION_DRAGONFLY_GET` 覆盖环境变量中的 dfget ,使用 `ZETA_EXTENSION_ARIA2C` 覆盖环境变量中的 `aria2c`,未设置 `ZETA_CORE_ACCELERATOR` 时,我们走 zeta 的大文件下载接口下载。 -+ `ZETA_CORE_CONCURRENT_TRANSFERS` 临时覆盖 `core.concurrenttransfers` 配置,下载并发数,有效值是 `0-50`。 -+ `ZETA_AUTHOR_NAME` commit 作者名称 -+ `ZETA_AUTHOR_EMAIL` commit 作者邮箱 -+ `ZETA_AUTHOR_DATE` commit 作者时间 -+ `ZETA_COMMITTER_NAME` commit 提交者名称 -+ `ZETA_COMMITTER_EMAIL` commit 提交者邮箱 -+ `ZETA_COMMITTER_DATE` commit 提交者时间 - -Committer 未显示设置时会使用 Author 的值。 \ No newline at end of file diff --git a/pkg/command/command_diff.go b/pkg/command/command_diff.go index 1f53a01..89897af 100644 --- a/pkg/command/command_diff.go +++ b/pkg/command/command_diff.go @@ -152,7 +152,7 @@ func (c *Diff) render(u *diferenco.Unified) error { if c.From != c.To { name = object.PathRenameCombine(c.From, c.To) } - opts.ShowStats(context.Background(), object.FileStats{ + return opts.ShowStats(context.Background(), object.FileStats{ object.FileStat{ Name: name, Addition: s.Addition, @@ -160,9 +160,8 @@ func (c *Diff) render(u *diferenco.Unified) error { }, }) default: - opts.ShowPatch(context.Background(), []*diferenco.Unified{u}) + return opts.ShowPatch(context.Background(), []*diferenco.Unified{u}) } - return nil } func (c *Diff) nameStatus() error { diff --git a/pkg/zeta/blame.go b/pkg/zeta/blame.go index cdc8a88..4f1cac2 100644 --- a/pkg/zeta/blame.go +++ b/pkg/zeta/blame.go @@ -251,7 +251,7 @@ func (b *blame) addBlames(ctx context.Context, curItems []*queueItem) (bool, err curItem.NeedsMap = newNeedsMap curItem.IdenticalToChild = false curItem.Child = nil - curItems = nil // free the memory + //curItems = nil // free the memory } parents, err := parentsContainingPath(ctx, curItem.path, curItem.Commit) diff --git a/pkg/zeta/hastyhex_test.go b/pkg/zeta/hastyhex_test.go index b5ecf04..de692e6 100644 --- a/pkg/zeta/hastyhex_test.go +++ b/pkg/zeta/hastyhex_test.go @@ -13,7 +13,7 @@ func TestProcessColor(t *testing.T) { if err != nil { return } - processColor(bytes.NewReader(b), os.Stdout, int64(len(b))) + _ = processColor(bytes.NewReader(b), os.Stdout, int64(len(b))) } func TestBorder(t *testing.T) { diff --git a/pkg/zeta/merge_file.go b/pkg/zeta/merge_file.go index fd7e5db..e7b41ad 100644 --- a/pkg/zeta/merge_file.go +++ b/pkg/zeta/merge_file.go @@ -31,12 +31,12 @@ func (r *Repository) resolveMergeDriver() odb.MergeDriver { } var diffAlgorithm diferenco.Algorithm var err error - if len(r.Diff.Algorithm) != 0 { - if diffAlgorithm, err = diferenco.AlgorithmFromName(r.Diff.Algorithm); err != nil { - warn("diff: bad config: diff.algorithm value: %s", r.Diff.Algorithm) + if algorithmName := r.diffAlgorithm(); len(algorithmName) != 0 { + if diffAlgorithm, err = diferenco.AlgorithmFromName(algorithmName); err != nil { + warn("diff: bad config: diff.algorithm value: %s", algorithmName) } } - mergeConflictStyle := diferenco.ParseConflictStyle(r.Merge.ConflictStyle) + mergeConflictStyle := diferenco.ParseConflictStyle(r.mergeConflictStyle()) return func(ctx context.Context, o, a, b, labelO, labelA, labelB string) (string, bool, error) { return diferenco.Merge(ctx, &diferenco.MergeOptions{ TextO: o, @@ -77,7 +77,7 @@ func (opts *MergeFileOptions) diffAlgorithmFromName(defaultDiffAlgorithm string) } func (r *Repository) MergeFile(ctx context.Context, opts *MergeFileOptions) error { - diffAlgorithm := opts.diffAlgorithmFromName(r.Diff.Algorithm) + diffAlgorithm := opts.diffAlgorithmFromName(r.diffAlgorithm()) r.DbgPrint("algorithm: %s conflict style: %v", diffAlgorithm, opts.Style) o, err := r.Revision(ctx, opts.O) if err != nil { diff --git a/pkg/zeta/repository.go b/pkg/zeta/repository.go index c12bae1..7e98ecb 100644 --- a/pkg/zeta/repository.go +++ b/pkg/zeta/repository.go @@ -649,6 +649,20 @@ func (r *Repository) coreEditor() string { return r.Core.Editor } +func (r *Repository) diffAlgorithm() string { + if a, ok := getStringFromValues("diff.algorithm", r.values); ok && len(a) > 0 { + return a + } + return r.Diff.Algorithm +} + +func (r *Repository) mergeConflictStyle() string { + if conflictStyle, ok := getStringFromValues("merge.conflictStyle", r.values); ok && len(conflictStyle) > 0 { + return conflictStyle + } + return r.Merge.ConflictStyle +} + func (r *Repository) Postflight(ctx context.Context) error { if !r.IsExtreme() { return nil diff --git a/pkg/zeta/worktree_diff.go b/pkg/zeta/worktree_diff.go index 5e45eb8..d9130bc 100644 --- a/pkg/zeta/worktree_diff.go +++ b/pkg/zeta/worktree_diff.go @@ -393,11 +393,12 @@ func (w *Worktree) between(ctx context.Context, opts *DiffOptions) error { } func (w *Worktree) DiffContext(ctx context.Context, opts *DiffOptions) error { - if opts.Algorithm == diferenco.Unspecified && len(w.Diff.Algorithm) != 0 { - if a, err := diferenco.AlgorithmFromName(w.Diff.Algorithm); err != nil { - warn("diff: bad config, key: diff.algorithm value: %s", w.Diff.Algorithm) - } else { - opts.Algorithm = a + if opts.Algorithm == diferenco.Unspecified { + if algorithmName := w.diffAlgorithm(); len(algorithmName) != 0 { + var err error + if opts.Algorithm, err = diferenco.AlgorithmFromName(algorithmName); err != nil { + warn("diff: bad config: diff.algorithm value: %s", algorithmName) + } } } if len(opts.From) != 0 && len(opts.To) != 0 {