Skip to content

Commit

Permalink
standardize some configuration parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Dec 23, 2024
1 parent ab91a45 commit 4d27a88
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local/*
*.gop1
*.tomlp1
*.rej
*.mdp1
/out/
/.vscode/
.idea/*
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}'

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.16.1
0.16.2
2 changes: 1 addition & 1 deletion bali.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "江二"
Expand Down
2 changes: 1 addition & 1 deletion cmd/zeta-mc/crate.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion cmd/zeta/crate.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
29 changes: 29 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# HugeSCM 支持的配置和环境变量备忘录

| 配置 | 环境变量 | 备注 |
| :--- | :--- | :--- |
| `core.sharingRoot` | `ZETA_CORE_SHARING_ROOT` | 该配置用于指定 blob 存储的 root,以表明用户试图在多个存储库中复用 blob 对象,用来降低磁盘存储。 |
| `core.sparse`||存储库稀疏检出配置,用户不应设置在全局修改该配置,可以在存储库级别修改|
| `core.remote`||存储库远程设置,通常不宜修改此配置|
| `user.name`<br/> | `ZETA_AUTHOR_NAME` | 作者名 |
| | `ZETA_COMMITTER_NAME` | 提交者 |
| `user.email`<br/> | `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 交互能力。 |
26 changes: 0 additions & 26 deletions docs/env.md

This file was deleted.

5 changes: 2 additions & 3 deletions pkg/command/command_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,16 @@ 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,
Deletion: s.Deletion,
},
})
default:
opts.ShowPatch(context.Background(), []*diferenco.Unified{u})
return opts.ShowPatch(context.Background(), []*diferenco.Unified{u})
}
return nil
}

func (c *Diff) nameStatus() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/zeta/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/zeta/hastyhex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions pkg/zeta/merge_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions pkg/zeta/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions pkg/zeta/worktree_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4d27a88

Please sign in to comment.