Skip to content

*: use buf as formatter#1422

Open
lance6716 wants to merge 2 commits intorelease-8.5from
lance6716/port-buf-formatter-to-8.5
Open

*: use buf as formatter#1422
lance6716 wants to merge 2 commits intorelease-8.5from
lance6716/port-buf-formatter-to-8.5

Conversation

@lance6716
Copy link
Contributor

@lance6716 lance6716 commented Feb 26, 2026

this PR can be reproduced by

  1. checkout script file changes from master PR *: use buf as formatter #1408
image
git checkout master -- Makefile scripts/proto_format.sh scripts/check.sh scripts/common.sh scripts/generate_cpp.sh .editorconfig README.md
  1. run formatter
make proto-fmt
  1. golang code generation
make go

Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
Copilot AI review requested due to automatic review settings February 26, 2026 06:20
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 26, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign bb7133, bornchanger, cfzjywxk, overvenus, rleungx, you06, yudongusa for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes .proto formatting across the repo by adopting buf format, updates CI/local checks to enforce the formatting, and applies the formatter output to existing proto sources (including regenerated Go outputs where applicable).

Changes:

  • Add a pinned buf-based formatter script plus make proto-fmt / make proto-fmt-check targets.
  • Update check/codegen scripts to incorporate formatting checks and handle buf’s multi-line option formatting for C++ generation.
  • Reformat many .proto files and update generated Go descriptor blobs accordingly.

Reviewed changes

Copilot reviewed 56 out of 61 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
scripts/proto_format.sh New pinned buf download + buf format runner for --check/--write.
scripts/check.sh Runs proto formatting check as part of make check; adds proto option checks (currently problematic).
scripts/common.sh Reworks clean_gogo_proto to strip gogoproto options robustly under buf formatting.
scripts/generate_cpp.sh Uses clean_gogo_proto per file after copying protos for C++ generation.
Makefile Adds proto-fmt and proto-fmt-check targets wired to the formatter script.
README.md Documents the new formatting workflow and how to fix formatting failures.
.editorconfig Enforces 2-space indentation for *.proto files in editors.
proto/tsopb.proto Reformatted via buf format.
proto/tracepb.proto Reformatted via buf format.
proto/schedulingpb.proto Reformatted via buf format.
proto/resource_usage_agent.proto Reformatted via buf format.
proto/resource_manager.proto Reformatted via buf format.
proto/replication_modepb.proto Reformatted via buf format.
proto/recoverdatapb.proto Reformatted via buf format.
proto/raft_serverpb.proto Reformatted via buf format.
proto/raft_cmdpb.proto Reformatted via buf format.
proto/mpp.proto Reformatted via buf format.
proto/metapb.proto Reformatted via buf format.
proto/meta_storagepb.proto Reformatted via buf format.
proto/logbackuppb.proto Reformatted via buf format.
proto/keyspacepb.proto Reformatted via buf format.
proto/import_kvpb.proto Reformatted via buf format.
proto/gcpb.proto Reformatted via buf format.
proto/errorpb.proto Reformatted via buf format.
proto/enginepb.proto Reformatted via buf format.
proto/encryptionpb.proto Reformatted via buf format.
proto/disk_usage.proto Reformatted via buf format.
proto/disaggregated.proto Reformatted via buf format.
proto/diagnosticspb.proto Reformatted via buf format.
proto/debugpb.proto Reformatted via buf format.
proto/deadlock.proto Reformatted via buf format.
proto/coprocessor.proto Reformatted via buf format (notably multi-line field options formatting).
proto/configpb.proto Reformatted via buf format.
proto/cdcpb.proto Reformatted via buf format.
proto/autoid.proto Reformatted via buf format.
include/rustproto.proto Reformatted via buf format.
include/eraftpb.proto Reformatted via buf format.
pkg/logbackuppb/logbackuppb.pb.go Updated generated descriptor blob due to proto formatting/re-ordering effects.
pkg/keyspacepb/keyspacepb.pb.go Updated generated descriptor blob due to proto formatting/re-ordering effects.
pkg/configpb/configpb.pb.go Updated generated descriptor blob due to proto formatting/re-ordering effects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +83 to +86
for option in "${options[@]}"; do
if ! grep -q "$option" "$pb"; then
echo "Please add option \"$option\" to $pb"
return 1
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep -q "$option" treats the option string as a regex (so . matches any character, etc.). Since you’re searching for exact lines, use fixed-string matching (e.g. grep -Fq -- "$option") to avoid false positives/negatives.

Copilot uses AI. Check for mistakes.
Comment on lines +59 to +61
install_buf() {
local found_version url tmp_buf expected_sha actual_sha

Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install_buf declares expected_sha and actual_sha but never uses them. This looks like leftover scaffolding; please remove unused locals to keep the script easy to maintain (or implement checksum verification if that was the intent).

Copilot uses AI. Check for mistakes.
Comment on lines +60 to +77
check-protos-options() {
local options=(
'import "gogoproto/gogo.proto";'
'import "rustproto.proto";'

'option (gogoproto.sizer_all) = true;'
'option (gogoproto.marshaler_all) = true;'
'option (gogoproto.unmarshaler_all) = true;'
# Remove unnecessary fields from pb structs.
# XXX_NoUnkeyedLiteral struct{} `json:"-"`
# XXX_unrecognized []byte `json:"-"`
# XXX_sizecache int32 `json:"-"`
'option (gogoproto.goproto_unkeyed_all) = false;'
'option (gogoproto.goproto_unrecognized_all) = false;'
'option (gogoproto.goproto_sizecache_all) = false;'
# TiKV does not need reflection and descriptor data.
'option (rustproto.lite_runtime_all) = true;'
)
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check-protos-options enforces several gogoproto options (e.g. goproto_unkeyed_all, goproto_unrecognized_all, goproto_sizecache_all) that are not present in any current proto/*.proto files, so make check will fail unconditionally. Either remove this check, or scope it to only the protos that actually require these options / update the protos to include them consistently (and keep the list in sync with reality).

Copilot uses AI. Check for mistakes.
Comment on lines +83 to +90
if ! curl -sSfL --retry "${BUF_CURL_RETRY}" --retry-delay 1 "${url}" -o "${tmp_buf}"; then
echo "Failed to download buf from: ${url}" >&2
rm -f "${tmp_buf}"
return 1
fi

chmod +x "${tmp_buf}"
mv "${tmp_buf}" "${BUF_BIN}"
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install_buf downloads and executes a prebuilt buf binary directly from GitHub via curl without any checksum or signature verification. If the GitHub release, network path, or TLS trust chain are compromised, an attacker could deliver a malicious binary that will be marked executable and run as part of your build/check tooling. To harden the supply chain, fetch buf via a mechanism that verifies integrity (for example, pinned checksums or signatures for the specific version) before chmod +x and mv-ing it into BUF_BIN.

Copilot uses AI. Check for mistakes.
@lance6716
Copy link
Contributor Author

Just to avoid the formatting causing some problems, I want to wait some weeks after master branch's merging before continue release branch formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants