File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77# Parse `git diff` into patches and lines
88module 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
1615end
Original file line number Diff line number Diff line change 11module 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
4118end
You can’t perform that action at this time.
0 commit comments