Skip to content

Commit 7a50721

Browse files
committed
Remove duplicated Git diff header parsing logic from file path extraction
1 parent aa31f27 commit 7a50721

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/extract-diff-patches

packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/extract-diff-patches/extract-diff-patches.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ const extract_file_path_from_lines = (lines: string[]): string | undefined => {
192192
let to_path: string | undefined
193193

194194
for (const line of lines) {
195+
const git_diff_match = line.match(/^diff --git a\/(.+?) b\/(.+)$/)
196+
if (git_diff_match) {
197+
if (git_diff_match[2]) to_path = git_diff_match[2]
198+
if (git_diff_match[1]) from_path = git_diff_match[1]
199+
}
195200
const from_match = line.match(/^--- (?:a\/|"a\/)?([^\t"]+)"?(?:\t.*)?$/)
196201
if (from_match && from_match[1]) {
197202
from_path = from_match[1]
@@ -284,7 +289,7 @@ const format_hunk_headers = (lines: string[]): string[] => {
284289
const formatted_lines: string[] = []
285290
for (const line of lines) {
286291
const hunk_match = line.match(/^(@@ -\d+(?:,\d+)? \+\d+(?:,\d+)? @@)(.*)$/)
287-
if (hunk_match && hunk_match[2].trim() !== '') {
292+
if (hunk_match && hunk_match[2].trim() != '') {
288293
formatted_lines.push(hunk_match[1])
289294
if (hunk_match[2].length > 0) {
290295
formatted_lines.push(hunk_match[2])

0 commit comments

Comments
 (0)