]> git.99rst.org Git - git.git/commit
userdiff: add support for Swift
authorShlok Kulshreshtha <redacted>
Tue, 21 Jul 2026 06:57:36 +0000 (12:27 +0530)
committerJunio C Hamano <redacted>
Thu, 23 Jul 2026 14:14:34 +0000 (07:14 -0700)
commit113d62b141a80bf136268df51b4597dbec4355d0
tree62edfa72f582fbd34b91cf26664a018f8515aacd
parent41365c2a9ba347870b80881c0d67454edd22fd49
userdiff: add support for Swift

Add a built-in userdiff driver for the Swift programming language so that
diff hunk headers and word diffs work out of the box for ".swift" files.

The funcname pattern is built for Swift's own declaration grammar: an
optional run of attributes ("@objc", "@available(iOS 13, *)", ...),
followed by an optional run of lowercase modifiers ("public", "static",
"final", ...), followed by a declaration keyword (func, class, struct,
enum, protocol, extension, actor, init, deinit, subscript). The keyword
is followed by a boundary that allows whitespace, "(" (init/subscript),
"?" or "!" (failable init), or "<" (generics), while still acting as a
word boundary so e.g. "initialize(" does not match.

The word regex recognizes Swift identifiers, hexadecimal, octal, binary,
integer and floating-point literals, and the language's operators.

Signed-off-by: Shlok Kulshreshtha <redacted>
Acked-by: Johannes Sixt <redacted>
Signed-off-by: Junio C Hamano <redacted>
15 files changed:
Documentation/gitattributes.adoc
t/t4018/swift-actor [new file with mode: 0644]
t/t4018/swift-attribute-with-args [new file with mode: 0644]
t/t4018/swift-class [new file with mode: 0644]
t/t4018/swift-enum [new file with mode: 0644]
t/t4018/swift-extension [new file with mode: 0644]
t/t4018/swift-failable-init [new file with mode: 0644]
t/t4018/swift-func [new file with mode: 0644]
t/t4018/swift-generic-subscript [new file with mode: 0644]
t/t4018/swift-init [new file with mode: 0644]
t/t4018/swift-inline-attribute [new file with mode: 0644]
t/t4018/swift-modifiers [new file with mode: 0644]
t/t4018/swift-protocol [new file with mode: 0644]
t/t4018/swift-struct [new file with mode: 0644]
userdiff.c
git clone https://git.99rst.org/PROJECT