Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
345 additions
and
26 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,61 @@ | |||
module Grit | |||
|
|||
class Blame | |||
|
|||
attr_reader :lines | |||
|
|||
def initialize(repo, file, commit) | |||
@repo = repo | |||
@file = file | |||
@commit = commit | |||
@lines = [] | |||
load_blame | |||
end | |||
|
|||
def load_blame | |||
output = @repo.git.blame({'p' => true}, @commit, '--', @file) | |||
process_raw_blame(output) | |||
end | |||
|
|||
def process_raw_blame(output) | |||
lines, final = [], [] | |||
info, commits = {}, {} | |||
|
|||
# process the output | |||
output.split("\n").each do |line| | |||
if line[0, 1] == "\t" | |||
lines << line[1, line.size] | |||
elsif m = /^(\w{40}) (\d+) (\d+)/.match(line) | |||
if !commits[m[1]] | |||
commits[m[1]] = @repo.commit(m[1]) | |||
end | |||
info[m[3].to_i] = [commits[m[1]], m[2].to_i] | |||
end | |||
end | |||
|
|||
# get it together | |||
info.sort.each do |lineno, commit| | |||
final << BlameLine.new(lineno, commit[1], commit[0], lines[lineno - 1]) | |||
end | |||
|
|||
@lines = final | |||
end | |||
|
|||
# Pretty object inspection | |||
def inspect | |||
%Q{#<Grit::Blame "#{@file} <#{@commit}>">} | |||
end | |||
|
|||
class BlameLine | |||
attr_accessor :lineno, :oldlineno, :commit, :line | |||
def initialize(lineno, oldlineno, commit, line) | |||
@lineno = lineno | |||
@oldlineno = oldlineno | |||
@commit = commit | |||
@line = line | |||
end | |||
end | |||
|
|||
end # Blame | |||
|
|||
end # Grit |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
module Grit | |||
|
|||
class Merge | |||
|
|||
STATUS_BOTH = 'both' | |||
STATUS_OURS = 'ours' | |||
STATUS_THEIRS = 'theirs' | |||
|
|||
attr_reader :conflicts, :text, :sections | |||
|
|||
def initialize(str) | |||
status = STATUS_BOTH | |||
|
|||
section = 1 | |||
@conflicts = 0 | |||
@text = {} | |||
|
|||
lines = str.split("\n") | |||
lines.each do |line| | |||
if /^<<<<<<< (.*?)/.match(line) | |||
status = STATUS_OURS | |||
@conflicts += 1 | |||
section += 1 | |||
elsif line == '=======' | |||
status = STATUS_THEIRS | |||
elsif /^>>>>>>> (.*?)/.match(line) | |||
status = STATUS_BOTH | |||
section += 1 | |||
else | |||
@text[section] ||= {} | |||
@text[section][status] ||= [] | |||
@text[section][status] << line | |||
end | |||
end | |||
@text = @text.values | |||
@sections = @text.size | |||
end | |||
|
|||
# Pretty object inspection | |||
def inspect | |||
%Q{#<Grit::Merge} | |||
end | |||
end # Merge | |||
|
|||
end # Grit |
This file contains 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
Oops, something went wrong.