[clang] Fix filename parsing in clang-format-diff.py for paths with spaces (PR #135779)

2025-04-15 Thread Selim Keles via cfe-commits

https://github.com/selimkeles created 
https://github.com/llvm/llvm-project/pull/135779

Summary: This PR resolves an issue in clang-format-diff.py where filenames 
containing spaces were not correctly extracted from Git diffs. Due to the 
previous regex implementation, filenames were being truncated, causing the 
script to fail when processing diffs with such filenames.

**Details:**

- Adjusted the regex pattern to correctly capture the filename, including 
spaces.
- Ensured compatibility across Linux and Windows environments (tested on WSL 
and Windows).

**Steps to Reproduce:**

Modify a file with spaces in its name, stage the changes, and generate a diff.

Run git diff --cached -U0 --no-color | python3 clang-format-diff.py -p1.

Before the fix, filenames with spaces are incorrectly extracted or cause errors.

 After the fix, filenames with spaces are correctly recognized, and formatting 
differences are processed properly.

**Impact:**

Users relying on clang-format-diff.py in their automated workflows and 
pre-commit hooks will now be able to format files without filename parsing 
issues.

_No changes are made to formatting behavior—only improved filename handling in 
diffs._

_**Maintainer Mentions:**_ Tagging @mydeveloperday and @owenca for review since 
they maintain clang-format and also @owenca reviewed my 
[issue](https://github.com/llvm/llvm-project/issues/135619#issuecomment-2804148179)
 earlier.

_**Note: Also attached the patch file**_ 
[clang-format-space-fix.patch](https://github.com/user-attachments/files/19757014/clang-format-space-fix.patch)


Would love any feedback or suggestions for further refinements! 🚀

>From 606802b8703fa3c1affcc3e52afc22bc3422dcad Mon Sep 17 00:00:00 2001
From: "selim.keles" 
Date: Tue, 15 Apr 2025 14:24:08 +0300
Subject: [PATCH] Fix filename parsing in clang-format-diff.py for files or
 paths with spaces

---
 clang/tools/clang-format/clang-format-diff.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index c82b41e8bd031..e1d635fc85ffb 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -102,9 +102,9 @@ def main():
 filename = None
 lines_by_file = {}
 for line in sys.stdin:
-match = re.search(r"^\+\+\+\ (.*?/){%s}(\S*)" % args.p, line)
+match = re.search(r"^\+\+\+\s+(?:.*?/){%s}(.+)$" % args.p, line)
 if match:
-filename = match.group(2)
+filename = match.group(1).strip()
 if filename is None:
 continue
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] Fix filename parsing in clang-format-diff.py for paths with spaces (PR #135779)

2025-04-17 Thread Selim Keles via cfe-commits

https://github.com/selimkeles updated 
https://github.com/llvm/llvm-project/pull/135779

>From 235ef7b9d0e5f8cb9329400a01fa1b51c74626e7 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Tue, 15 Apr 2025 11:40:07 +0200
Subject: [PATCH] Fix filename parsing in clang-format-diff.py for paths with
 spaces

---
 clang/tools/clang-format/clang-format-diff.py | 2 +-
 lldb/source/Target/Process.cpp| 9 +
 lldb/source/Target/Target.cpp | 2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index c82b41e8bd031..3059982ba231f 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -102,7 +102,7 @@ def main():
 filename = None
 lines_by_file = {}
 for line in sys.stdin:
-match = re.search(r"^\+\+\+\ (.*?/){%s}(\S*)" % args.p, line)
+match = re.search(r"^\+\+\+\ (.*?/){%s}(.+)" % args.p, line.rstrip())
 if match:
 filename = match.group(2)
 if filename is None:
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 633f7488dc76a..73557eb767c72 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -1047,10 +1047,11 @@ bool Process::SetExitStatus(int status, llvm::StringRef 
exit_string) {
 info->exit_desc = {status, exit_string.str()};
   });
 
-  helper.DispatchOnExit([&](telemetry::ProcessExitInfo *info) {
-info->module_uuid = module_uuid;
-info->pid = m_pid;
-  });
+  helper.DispatchOnExit(
+  [module_uuid, pid = m_pid](telemetry::ProcessExitInfo *info) {
+info->module_uuid = module_uuid;
+info->pid = pid;
+  });
 
   m_exit_status = status;
   if (!exit_string.empty())
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 42b1561fb2993..b6186b76d6236 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -1578,7 +1578,7 @@ void Target::SetExecutableModule(ModuleSP &executable_sp,
   info->is_start_entry = true;
 });
 
-helper.DispatchOnExit([&](telemetry::ExecutableModuleInfo *info) {
+helper.DispatchOnExit([&, pid](telemetry::ExecutableModuleInfo *info) {
   info->exec_mod = executable_sp;
   info->uuid = executable_sp->GetUUID();
   info->pid = pid;

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix filename parsing in clang-format-diff.py for paths with spaces (PR #135779)

2025-04-17 Thread Selim Keles via cfe-commits


@@ -102,9 +102,9 @@ def main():
 filename = None
 lines_by_file = {}
 for line in sys.stdin:
-match = re.search(r"^\+\+\+\ (.*?/){%s}(\S*)" % args.p, line)
+match = re.search(r"^\+\+\+\s+(?:.*?/){%s}(.+)$" % args.p, line)

selimkeles wrote:

Made the change suggested, tested, working good. Messed up the PR with force 
push sorry about that.

https://github.com/llvm/llvm-project/pull/135779
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix filename parsing in clang-format-diff.py for paths with spaces (PR #135779)

2025-04-17 Thread Selim Keles via cfe-commits

https://github.com/selimkeles updated 
https://github.com/llvm/llvm-project/pull/135779

>From 92e47b84df20351e644deb38c8fc4c5d56a7e73f Mon Sep 17 00:00:00 2001
From: "selim.keles" 
Date: Fri, 18 Apr 2025 09:01:59 +0300
Subject: [PATCH] Fix filename parsing in clang-format-diff.py for paths with
 spaces

---
 clang/tools/clang-format/clang-format-diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index c82b41e8bd031..3059982ba231f 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -102,7 +102,7 @@ def main():
 filename = None
 lines_by_file = {}
 for line in sys.stdin:
-match = re.search(r"^\+\+\+\ (.*?/){%s}(\S*)" % args.p, line)
+match = re.search(r"^\+\+\+\ (.*?/){%s}(.+)" % args.p, line.rstrip())
 if match:
 filename = match.group(2)
 if filename is None:

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix filename parsing in clang-format-diff.py for paths with spaces (PR #135779)

2025-04-17 Thread Selim Keles via cfe-commits

https://github.com/selimkeles reopened 
https://github.com/llvm/llvm-project/pull/135779
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix filename parsing in clang-format-diff.py for paths with spaces (PR #135779)

2025-04-18 Thread Selim Keles via cfe-commits

https://github.com/selimkeles updated 
https://github.com/llvm/llvm-project/pull/135779

>From 92e47b84df20351e644deb38c8fc4c5d56a7e73f Mon Sep 17 00:00:00 2001
From: "selim.keles" 
Date: Fri, 18 Apr 2025 09:01:59 +0300
Subject: [PATCH] Fix filename parsing in clang-format-diff.py for paths with
 spaces

---
 clang/tools/clang-format/clang-format-diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index c82b41e8bd031..3059982ba231f 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -102,7 +102,7 @@ def main():
 filename = None
 lines_by_file = {}
 for line in sys.stdin:
-match = re.search(r"^\+\+\+\ (.*?/){%s}(\S*)" % args.p, line)
+match = re.search(r"^\+\+\+\ (.*?/){%s}(.+)" % args.p, line.rstrip())
 if match:
 filename = match.group(2)
 if filename is None:

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits