Skip to content

Commit 0e88b7c

Browse files
committed
feat(parser): add deprecated tag
1 parent 6597e6d commit 0e88b7c

2 files changed

Lines changed: 7 additions & 31 deletions

File tree

lib/git_diff_parser.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
# Parse `git diff` into patches and lines
88
module GitDiffParser
9-
109
# @param contents [String] `git diff` result.
1110
#
1211
# @return [Patches<Patch>] parsed patches and lines
1312
def self.parse(contents)
14-
DiffParser.parse(contents)
13+
Patches.parse(contents)
1514
end
1615
end

lib/git_diff_parser/diff_parser.rb

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,18 @@
11
module GitDiffParser
22
# Parse entire `git diff` into Patches and Patch
3+
#
4+
# @deprecated
35
class DiffParser
46
# Parse entire `git diff` into Patches and Patch
57
#
8+
# @deprecated Use {Patches.parse} instead.
9+
#
610
# @param contents [String] `git diff` result
711
#
812
# @return [Patches<Patch>] parsed object
913
def self.parse(contents)
10-
body = false
11-
file_name = ''
12-
patch = []
13-
lines = contents.lines
14-
line_count = lines.count
15-
parsed = Patches.new
16-
lines.each_with_index do |line, count|
17-
case line.chomp
18-
when /^diff/
19-
unless patch.empty?
20-
parsed << Patch.new(patch.join("\n") + "\n", file: file_name)
21-
patch.clear
22-
file_name = ''
23-
end
24-
body = false
25-
when /^\-\-\-/
26-
when %r{^\+\+\+ b/(?<file_name>.*)}
27-
file_name = Regexp.last_match[:file_name]
28-
body = true
29-
when /^(?<body>[\ @\+\-\\].*)/
30-
patch << Regexp.last_match[:body] if body
31-
if !patch.empty? && body && line_count == count + 1
32-
parsed << Patch.new(patch.join("\n") + "\n", file: file_name)
33-
patch.clear
34-
file_name = ''
35-
end
36-
end
37-
end
38-
parsed
14+
warn '[DEPRECATION] `DiffParser.parse` is deprecated. Please use `Patches.parse` instead.'
15+
Patches.parse(contents)
3916
end
4017
end
4118
end

0 commit comments

Comments
 (0)