Created
November 29, 2013 13:31
-
-
Save txus/7705718 to your computer and use it in GitHub Desktop.
this could very well be the ugliest, shittiest, most procedural code I've ever written in my life
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#TODO: kill me plz | |
def find_change(filename, subjective_line, type) | |
find = Regexp.escape(type == :addition ? '+' : '-') | |
skip = Regexp.escape(type == :addition ? '-' : '+') | |
line = 1 | |
commit = @patch[line].scan(/From ([a-z0-9]+)/).first.first | |
line += 1 until @patch[line] =~ /\+\+\+ b\/#{filename}/ | |
line += 1 | |
header = @patch[line] | |
starts = header.scan(/@@ -(\d)/).first.first.to_i | |
offset = (subjective_line - starts + 1) | |
(subjective_line - starts + 1).times do |i| | |
line +=1 | |
if @patch[line] =~ /^#{skip}/ | |
line += 1 | |
offset += 1 | |
end | |
end | |
while(@patch[line] !~ /^#{find}/) | |
(line += 1 && offset += 1) until ((header = @patch[line]) =~ /@@/) | |
starts = header.scan(/@@ -(\d)/).first.first.to_i | |
new_offset = (subjective_line - starts + 1) | |
(subjective_line - starts + 1).times do |i| | |
line +=1 | |
if @patch[line] =~ /^#{skip}/ | |
line +=1 | |
new_offset += 1 | |
end | |
end | |
offset += new_offset | |
end | |
Location.new(commit, filename, offset) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🚢 that 💩