Skip to content
Snippets Groups Projects
Commit 9fdde369 authored by Alejandro Rodríguez's avatar Alejandro Rodríguez
Browse files

Move line code generation into Gitlab::Git

Having a distinct class just for that was a bit overkill
parent faa9bd40
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -186,7 +186,7 @@ module API
 
lines.each do |line|
next unless line.new_pos == params[:line] && line.type == params[:line_type]
break opts[:line_code] = Gitlab::Git::Conflict::LineCode.generate(diff.new_path, line.new_pos, line.old_pos)
break opts[:line_code] = Gitlab::Git.diff_line_code(diff.new_path, line.new_pos, line.old_pos)
end
 
break if opts[:line_code]
Loading
Loading
Loading
Loading
@@ -173,7 +173,7 @@ module API
 
lines.each do |line|
next unless line.new_pos == params[:line] && line.type == params[:line_type]
break opts[:line_code] = Gitlab::Git::Conflict::LineCode.generate(diff.new_path, line.new_pos, line.old_pos)
break opts[:line_code] = Gitlab::Git.diff_line_code(diff.new_path, line.new_pos, line.old_pos)
end
 
break if opts[:line_code]
Loading
Loading
Loading
Loading
@@ -23,7 +23,7 @@ module Github
private
 
def generate_line_code(line)
Gitlab::Git::Conflict::LineCode.generate(file_path, line.new_pos, line.old_pos)
Gitlab::Git.diff_line_code(file_path, line.new_pos, line.old_pos)
end
 
def on_diff?
Loading
Loading
Loading
Loading
@@ -241,7 +241,7 @@ module Gitlab
end
 
def generate_line_code(pr_comment)
Gitlab::Git::Conflict::LineCode.generate(pr_comment.file_path, pr_comment.new_pos, pr_comment.old_pos)
Gitlab::Git.diff_line_code(pr_comment.file_path, pr_comment.new_pos, pr_comment.old_pos)
end
 
def pull_request_comment_attributes(comment)
Loading
Loading
Loading
Loading
@@ -110,7 +110,7 @@ module Gitlab
end
 
def line_code(line)
Gitlab::Git::Conflict::LineCode.generate(our_path, line.new_pos, line.old_pos)
Gitlab::Git.diff_line_code(our_path, line.new_pos, line.old_pos)
end
 
def create_match_line(line)
Loading
Loading
@@ -174,17 +174,6 @@ module Gitlab
new_path: our_path)
end
 
# Don't try to print merge_request.
def inspect
instance_variables = [:content, :their_path, :our_path, :our_mode, :type].map do |instance_variable|
value = instance_variable_get("@#{instance_variable}")
"#{instance_variable}=\"#{value}\""
end
"#<#{self.class} #{instance_variables.join(' ')}>"
end
private
 
def map_raw_lines(raw_lines)
Loading
Loading
Loading
Loading
@@ -49,7 +49,7 @@ module Gitlab
def line_code(line)
return if line.meta?
 
Gitlab::Git::Conflict::LineCode.generate(file_path, line.new_pos, line.old_pos)
Gitlab::Git.diff_line_code(file_path, line.new_pos, line.old_pos)
end
 
def line_for_line_code(code)
Loading
Loading
Loading
Loading
@@ -66,6 +66,10 @@ module Gitlab
end
end
end
def diff_line_code(file_path, new_line_position, old_line_position)
"#{Digest::SHA1.hexdigest(file_path)}_#{old_line_position}_#{new_line_position}"
end
end
end
end
Loading
Loading
@@ -19,8 +19,8 @@ module Gitlab
begin
@type = 'text'
@lines = Gitlab::Git::Conflict::Parser.parse(content,
our_path: our_path,
their_path: their_path)
our_path: our_path,
their_path: their_path)
rescue Gitlab::Git::Conflict::Parser::ParserError
@type = 'text-editor'
@lines = nil
Loading
Loading
@@ -46,7 +46,7 @@ module Gitlab
end
 
def line_code(line)
Gitlab::Git::Conflict::LineCode.generate(our_path, line[:line_new], line[:line_old])
Gitlab::Git.diff_line_code(our_path, line[:line_new], line[:line_old])
end
 
def resolve_lines(resolution)
Loading
Loading
module Gitlab
module Git
module Conflict
class LineCode
def self.generate(file_path, new_line_position, old_line_position)
"#{Digest::SHA1.hexdigest(file_path)}_#{old_line_position}_#{new_line_position}"
end
end
end
end
end
Loading
Loading
@@ -38,7 +38,7 @@ module Gitlab
end
 
def generate_line_code(line)
Gitlab::Git::Conflict::LineCode.generate(file_path, line.new_pos, line.old_pos)
Gitlab::Git.diff_line_code(file_path, line.new_pos, line.old_pos)
end
 
def on_diff?
Loading
Loading
Loading
Loading
@@ -40,7 +40,7 @@ describe Gitlab::Diff::Position do
 
describe "#line_code" do
it "returns the correct line code" do
line_code = Gitlab::Git::Conflict::LineCode.generate(subject.file_path, subject.new_line, 0)
line_code = Gitlab::Git.diff_line_code(subject.file_path, subject.new_line, 0)
 
expect(subject.line_code(project.repository)).to eq(line_code)
end
Loading
Loading
@@ -108,7 +108,7 @@ describe Gitlab::Diff::Position do
 
describe "#line_code" do
it "returns the correct line code" do
line_code = Gitlab::Git::Conflict::LineCode.generate(subject.file_path, subject.new_line, 15)
line_code = Gitlab::Git.diff_line_code(subject.file_path, subject.new_line, 15)
 
expect(subject.line_code(project.repository)).to eq(line_code)
end
Loading
Loading
@@ -149,7 +149,7 @@ describe Gitlab::Diff::Position do
 
describe "#line_code" do
it "returns the correct line code" do
line_code = Gitlab::Git::Conflict::LineCode.generate(subject.file_path, subject.new_line, subject.old_line)
line_code = Gitlab::Git.diff_line_code(subject.file_path, subject.new_line, subject.old_line)
 
expect(subject.line_code(project.repository)).to eq(line_code)
end
Loading
Loading
@@ -189,7 +189,7 @@ describe Gitlab::Diff::Position do
 
describe "#line_code" do
it "returns the correct line code" do
line_code = Gitlab::Git::Conflict::LineCode.generate(subject.file_path, 13, subject.old_line)
line_code = Gitlab::Git.diff_line_code(subject.file_path, 13, subject.old_line)
 
expect(subject.line_code(project.repository)).to eq(line_code)
end
Loading
Loading
@@ -233,7 +233,7 @@ describe Gitlab::Diff::Position do
 
describe "#line_code" do
it "returns the correct line code" do
line_code = Gitlab::Git::Conflict::LineCode.generate(subject.file_path, subject.new_line, 5)
line_code = Gitlab::Git.diff_line_code(subject.file_path, subject.new_line, 5)
 
expect(subject.line_code(project.repository)).to eq(line_code)
end
Loading
Loading
@@ -274,7 +274,7 @@ describe Gitlab::Diff::Position do
 
describe "#line_code" do
it "returns the correct line code" do
line_code = Gitlab::Git::Conflict::LineCode.generate(subject.file_path, subject.new_line, subject.old_line)
line_code = Gitlab::Git.diff_line_code(subject.file_path, subject.new_line, subject.old_line)
 
expect(subject.line_code(project.repository)).to eq(line_code)
end
Loading
Loading
@@ -314,7 +314,7 @@ describe Gitlab::Diff::Position do
 
describe "#line_code" do
it "returns the correct line code" do
line_code = Gitlab::Git::Conflict::LineCode.generate(subject.file_path, 4, subject.old_line)
line_code = Gitlab::Git.diff_line_code(subject.file_path, 4, subject.old_line)
 
expect(subject.line_code(project.repository)).to eq(line_code)
end
Loading
Loading
@@ -357,7 +357,7 @@ describe Gitlab::Diff::Position do
 
describe "#line_code" do
it "returns the correct line code" do
line_code = Gitlab::Git::Conflict::LineCode.generate(subject.file_path, 0, subject.old_line)
line_code = Gitlab::Git.diff_line_code(subject.file_path, 0, subject.old_line)
 
expect(subject.line_code(project.repository)).to eq(line_code)
end
Loading
Loading
@@ -399,7 +399,7 @@ describe Gitlab::Diff::Position do
 
describe "#line_code" do
it "returns the correct line code" do
line_code = Gitlab::Git::Conflict::LineCode.generate(subject.file_path, subject.new_line, 0)
line_code = Gitlab::Git.diff_line_code(subject.file_path, subject.new_line, 0)
 
expect(subject.line_code(project.repository)).to eq(line_code)
end
Loading
Loading
@@ -447,7 +447,7 @@ describe Gitlab::Diff::Position do
 
describe "#line_code" do
it "returns the correct line code" do
line_code = Gitlab::Git::Conflict::LineCode.generate(subject.file_path, 0, subject.old_line)
line_code = Gitlab::Git.diff_line_code(subject.file_path, 0, subject.old_line)
 
expect(subject.line_code(project.repository)).to eq(line_code)
end
Loading
Loading
Loading
Loading
@@ -105,7 +105,7 @@ describe DiffNote do
 
describe "#line_code" do
it "returns the correct line code" do
line_code = Gitlab::Git::Conflict::LineCode.generate(position.file_path, position.formatter.new_line, 15)
line_code = Gitlab::Git.diff_line_code(position.file_path, position.formatter.new_line, 15)
 
expect(subject.line_code).to eq(line_code)
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment