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

moonchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 9eac80fc2d tools/clang-format.sh: cache clang-format in the common git 
dir (#13302)
9eac80fc2d is described below

commit 9eac80fc2d9af95cd37716dceed39e4bfe58c5e2
Author: Mo Chen <[email protected]>
AuthorDate: Sat Jun 20 15:59:54 2026 -0500

    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]>
---
 tools/clang-format.sh | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/tools/clang-format.sh b/tools/clang-format.sh
index 23e17bb6a4..6f9ee6a78e 100755
--- a/tools/clang-format.sh
+++ b/tools/clang-format.sh
@@ -24,8 +24,12 @@ PKGDATE="20240430"
 function main() {
   set -e # exit on error
 
-  GIT_DIR=$(git rev-parse --absolute-git-dir)
-  ROOT=${ROOT:-${GIT_DIR}/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
 
@@ -38,7 +42,7 @@ function main() {
       exit 2
     fi
   fi
-  DIR=${@:-$(dirname ${GIT_DIR})}
+  DIR=${@:-$(git rev-parse --show-toplevel)}
   PACKAGE="clang-format-${PKGDATE}.tar.bz2"
   VERSION="clang-format version 18.1.2 
(https://github.com/llvm/llvm-project.git 
26a1d6601d727a96f4301d0d8647b5a42760ae0c)"
 
@@ -119,6 +123,6 @@ EOF
 if [[ "$(basename -- "$0")" == 'clang-format.sh' ]]; then
   main "$@"
 else
-  GIT_DIR=$(git rev-parse --absolute-git-dir)
-  ROOT=${ROOT:-${GIT_DIR}/fmt/${PKGDATE}}
+  GIT_COMMON_DIR=$(cd "$(git rev-parse --git-common-dir)" && pwd)
+  ROOT=${ROOT:-${GIT_COMMON_DIR}/fmt/${PKGDATE}}
 fi

Reply via email to