[libcxx-commits] [libcxx] [libc++] Add a merge driver that can apply clang-format (PR #73712)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 28 15:11:29 PST 2023
ldionne wrote:
This PR was tested with the following script:
```
#!/usr/bin/env bash
#
# This test sets up artificial branches with artificial changes
# to test that the clang-format merge driver works as intended.
#
# First, checkout a WIP branch with some random changes on it.
git checkout wip/format/to-rebase
git reset --hard review/clang-format-merge-driver
# Apply a change to a non-formatted file
cat <<EOF | git apply -
diff --git a/libcxx/include/__chrono/calendar.h b/libcxx/include/__chrono/calendar.h
index 91aaf6325389..5345e2c6027f 100644
--- a/libcxx/include/__chrono/calendar.h
+++ b/libcxx/include/__chrono/calendar.h
@@ -26,8 +26,8 @@ namespace chrono
{
struct local_t {};
-template<class _Duration>
-using local_time = time_point<local_t, _Duration>;
+template<class _DurationType>
+using local_time = time_point<local_t, _DurationType>;
using local_seconds = local_time<seconds>;
using local_days = local_time<days>;
EOF
git add libcxx/include/__chrono/calendar.h
git commit -m "[chrono] Rename DurationType"
# Apply a change to an already-formatted file
cat <<EOF | git apply -
diff --git a/libcxx/include/__chrono/concepts.h b/libcxx/include/__chrono/concepts.h
index 61ec256b23ab..33cad4d0ef38 100644
--- a/libcxx/include/__chrono/concepts.h
+++ b/libcxx/include/__chrono/concepts.h
@@ -23,8 +23,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
-template <class _Tp>
-concept __is_hh_mm_ss = __is_specialization_v<_Tp, chrono::hh_mm_ss>;
+template <class _Type>
+concept __is_hh_mm_ss = __is_specialization_v<_Type, chrono::hh_mm_ss>;
template <class _Tp>
concept __is_time_point = __is_specialization_v<_Tp, chrono::time_point>;
EOF
git add libcxx/include/__chrono/concepts.h
git commit -m "[concepts] Rename template parameter"
# Apply a change outside of libc++ (this one should not be resolved by the merge driver)
cat <<EOF | git apply -
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 1f61bb02c6ae..4c334d9a7a28 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2423,7 +2423,7 @@ void DarwinClang::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs
bool DarwinClang::AddGnuCPlusPlusIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
- llvm::SmallString<128> Base,
+ llvm::SmallString<256> Base,
llvm::StringRef Version,
llvm::StringRef ArchDir,
llvm::StringRef BitDir) const {
EOF
git add clang/lib/Driver/ToolChains/Darwin.cpp
git commit -m "[clang] Use larger SmallString"
# Create a formatted branch on top of main
git checkout wip/format/formatted-main
git reset --hard review/clang-format-merge-driver
find libcxx/include clang/lib/Driver/ToolChains -type f | xargs clang-format -i
cat <<EOF > .gitattributes
libcxx/**/*.cpp merge=libcxx-reformat
libcxx/**/*.h merge=libcxx-reformat
EOF
git add libcxx clang .gitattributes
git commit -m "Reformat the whole codebase and setup optional merge driver for formatted files"
# Try rebasing the changes on top of the formatted main
#
# There should be no conflicts due to formatting in libcxx/.
# There should be one conflict due to formatting in clang/, since the
# merge driver is not supposed to be in effect there (via .gitattributes).
git rebase wip/format/formatted-main wip/format/to-rebase
```
https://github.com/llvm/llvm-project/pull/73712
More information about the libcxx-commits
mailing list