This is an automated email from the ASF dual-hosted git repository.

masaori335 pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.2.x by this push:
     new d6052cbdcb [9.2.x] Backport format scripts fixes (#13267)
d6052cbdcb is described below

commit d6052cbdcbab2cdb89f98731ed4e8620f01e7eb0
Author: Masaori Koshiba <[email protected]>
AuthorDate: Tue Jun 23 06:59:20 2026 +0900

    [9.2.x] Backport format scripts fixes (#13267)
    
    * CMake: use --git-common-dir to find the git dir (#11015)
    
    (cherry picked from commit f180ea2b6f25f6922c881b60d70cef68db1acac5)
    
    * Use "git rev-parse --absolute-git-dir" in tools scripts. (#11495)
    
    The alternate way of getting this, that we are currently using,
    doesn't work in cmake version 3.28.
    
    (cherry picked from commit 2ef63fa5140d6baf119a07b0a3610eedab43d888)
    
    * tools/clang-format.sh: cache clang-format in the common git dir (#13302)
    
    clang-format.sh located its download cache with `git rev-parse
    --absolute-git-dir`, which in a linked worktree is the per-worktree git
    dir (.git/worktrees/<name>) rather than the shared .git.  clang-format
    is installed once under the common dir, so in a worktree the pre-commit
    hook and the format target could not find it and failed with "No
    clang-format found".
    
    Resolve the common git dir instead, matching how CMakeLists.txt already
    computes GIT_COMMON_DIR.  It is made absolute with `cd ... && pwd`
    rather than `git rev-parse --path-format=absolute`, avoiding a
    dependency on git 2.31+; that --path-format form was removed in #11495
    over a cmake 3.28 incompatibility.
    
    The no-argument default target now uses `git rev-parse --show-toplevel`
    so a bare run inside a worktree formats that worktree, not the main
    checkout.
    
    Co-authored-by: Claude Opus 4.8 <[email protected]>
    (cherry picked from commit 9eac80fc2d9af95cd37716dceed39e4bfe58c5e2)
    
    Conflicts:
      tools/clang-format.sh
    
    ---------
    
    Co-authored-by: Walt Karas <[email protected]>
    Co-authored-by: Mo Chen <[email protected]>
---
 tools/autopep8.sh     |  6 ++++--
 tools/clang-format.sh | 13 ++++++++++---
 tools/yapf.sh         |  6 ++++--
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/tools/autopep8.sh b/tools/autopep8.sh
index e489627a91..58e7fa06cb 100755
--- a/tools/autopep8.sh
+++ b/tools/autopep8.sh
@@ -40,7 +40,8 @@ function main() {
     pip install -q virtualenv
   fi
 
-  AUTOPEP8_VENV=${AUTOPEP8_VENV:-$(cd $(dirname $0) && git rev-parse 
--show-toplevel)/.git/fmt/autopep8_${AUTOPEP8_VERSION}_venv}
+  GIT_DIR=$(git rev-parse --absolute-git-dir)
+  
AUTOPEP8_VENV=${AUTOPEP8_VENV:-${GIT_DIR}/fmt/autopep8_${AUTOPEP8_VERSION}_venv}
   if [ ! -e ${AUTOPEP8_VENV} ]
   then
     virtualenv ${AUTOPEP8_VENV}
@@ -115,5 +116,6 @@ function main() {
 if [[ "$(basename -- "$0")" == 'autopep8.sh' ]]; then
   main "$@"
 else
-  AUTOPEP8_VENV=${AUTOPEP8_VENV:-$(git rev-parse 
--show-toplevel)/.git/fmt/autopep8_${AUTOPEP8_VERSION}_venv}
+  GIT_DIR=$(git rev-parse --absolute-git-dir)
+  
AUTOPEP8_VENV=${AUTOPEP8_VENV:-${GIT_DIR}/fmt/autopep8_${AUTOPEP8_VERSION}_venv}
 fi
diff --git a/tools/clang-format.sh b/tools/clang-format.sh
index b8063e1de9..5cca3173fb 100755
--- a/tools/clang-format.sh
+++ b/tools/clang-format.sh
@@ -23,7 +23,13 @@ PKGDATE="20200514"
 
 function main() {
   set -e # exit on error
-  ROOT=${ROOT:-$(cd $(dirname $0) && git rev-parse 
--show-toplevel)/.git/fmt/${PKGDATE}}
+
+  # Resolve the common git directory, which is shared by all linked worktrees, 
so the
+  # downloaded clang-format is cached and found in one place.  
--git-common-dir can return a
+  # relative path, so make it absolute without --path-format (which needs git 
2.31+); this
+  # matches how CMakeLists.txt resolves GIT_COMMON_DIR.
+  GIT_COMMON_DIR=$(cd "$(git rev-parse --git-common-dir)" && pwd)
+  ROOT=${ROOT:-${GIT_COMMON_DIR}/fmt/${PKGDATE}}
   # The presence of this file indicates clang-format was successfully 
installed.
   INSTALLED_SENTINEL=${ROOT}/.clang-format-installed
 
@@ -36,7 +42,7 @@ function main() {
       exit 2
     fi
   fi
-  DIR=${@:-.}
+  DIR=${@:-$(git rev-parse --show-toplevel)}
   PACKAGE="clang-format-${PKGDATE}.tar.bz2"
   VERSION="clang-format version 10.0.0 
(https://github.com/llvm/llvm-project.git 
d32170dbd5b0d54436537b6b75beaf44324e0c28)"
 
@@ -118,5 +124,6 @@ EOF
 if [[ "$(basename -- "$0")" == 'clang-format.sh' ]]; then
   main "$@"
 else
-  ROOT=${ROOT:-$(git rev-parse --show-toplevel)/.git/fmt/${PKGDATE}}
+  GIT_COMMON_DIR=$(cd "$(git rev-parse --git-common-dir)" && pwd)
+  ROOT=${ROOT:-${GIT_COMMON_DIR}/fmt/${PKGDATE}}
 fi
diff --git a/tools/yapf.sh b/tools/yapf.sh
index 41ef3af802..ba7eca57cb 100755
--- a/tools/yapf.sh
+++ b/tools/yapf.sh
@@ -47,7 +47,8 @@ _END_
   fi
 
   REPO_ROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
-  YAPF_VENV=${YAPF_VENV:-${REPO_ROOT}/.git/fmt/yapf_${YAPF_VERSION}_venv}
+  GIT_DIR=$(git rev-parse --absolute-git-dir)
+  YAPF_VENV=${YAPF_VENV:-${GIT_DIR}/fmt/yapf_${YAPF_VERSION}_venv}
   if [ ! -e ${YAPF_VENV} ]
   then
     python3 -m virtualenv ${YAPF_VENV}
@@ -105,5 +106,6 @@ _END_
 if [[ "$(basename -- "$0")" == 'yapf.sh' ]]; then
   main "$@"
 else
-  YAPF_VENV=${YAPF_VENV:-$(git rev-parse 
--show-toplevel)/.git/fmt/yapf_${YAPF_VERSION}_venv}
+  GIT_DIR=$(git rev-parse --absolute-git-dir)
+  YAPF_VENV=${YAPF_VENV:-${GIT_DIR}/fmt/yapf_${YAPF_VERSION}_venv}
 fi

Reply via email to