Class: GitStore::Diff
- Inherits:
-
Object
- Object
- GitStore::Diff
- Defined in:
- lib/git_store/diff.rb
Overview
adapted from Grit
Instance Attribute Summary collapse
-
#a_blob ⇒ Object
readonly
Returns the value of attribute a_blob.
-
#a_mode ⇒ Object
readonly
Returns the value of attribute a_mode.
-
#a_path ⇒ Object
readonly
Returns the value of attribute a_path.
-
#b_blob ⇒ Object
readonly
Returns the value of attribute b_blob.
-
#b_mode ⇒ Object
readonly
Returns the value of attribute b_mode.
-
#b_path ⇒ Object
readonly
Returns the value of attribute b_path.
-
#deleted_file ⇒ Object
readonly
Returns the value of attribute deleted_file.
-
#diff ⇒ Object
readonly
Returns the value of attribute diff.
-
#new_file ⇒ Object
readonly
Returns the value of attribute new_file.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(store, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff) ⇒ Diff
constructor
A new instance of Diff.
Constructor Details
#initialize(store, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff) ⇒ Diff
Returns a new instance of Diff.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/git_store/diff.rb', line 12 def initialize(store, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff) @store = store @a_path = a_path @b_path = b_path @a_blob = a_blob =~ /^0{40}$/ ? nil : store.get(a_blob) @b_blob = b_blob =~ /^0{40}$/ ? nil : store.get(b_blob) @a_mode = a_mode @b_mode = b_mode @new_file = new_file @deleted_file = deleted_file @diff = diff end |
Instance Attribute Details
#a_blob ⇒ Object (readonly)
Returns the value of attribute a_blob.
7 8 9 |
# File 'lib/git_store/diff.rb', line 7 def a_blob @a_blob end |
#a_mode ⇒ Object (readonly)
Returns the value of attribute a_mode.
8 9 10 |
# File 'lib/git_store/diff.rb', line 8 def a_mode @a_mode end |
#a_path ⇒ Object (readonly)
Returns the value of attribute a_path.
6 7 8 |
# File 'lib/git_store/diff.rb', line 6 def a_path @a_path end |
#b_blob ⇒ Object (readonly)
Returns the value of attribute b_blob.
7 8 9 |
# File 'lib/git_store/diff.rb', line 7 def b_blob @b_blob end |
#b_mode ⇒ Object (readonly)
Returns the value of attribute b_mode.
8 9 10 |
# File 'lib/git_store/diff.rb', line 8 def b_mode @b_mode end |
#b_path ⇒ Object (readonly)
Returns the value of attribute b_path.
6 7 8 |
# File 'lib/git_store/diff.rb', line 6 def b_path @b_path end |
#deleted_file ⇒ Object (readonly)
Returns the value of attribute deleted_file.
9 10 11 |
# File 'lib/git_store/diff.rb', line 9 def deleted_file @deleted_file end |
#diff ⇒ Object (readonly)
Returns the value of attribute diff.
10 11 12 |
# File 'lib/git_store/diff.rb', line 10 def diff @diff end |
#new_file ⇒ Object (readonly)
Returns the value of attribute new_file.
9 10 11 |
# File 'lib/git_store/diff.rb', line 9 def new_file @new_file end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
5 6 7 |
# File 'lib/git_store/diff.rb', line 5 def store @store end |
Class Method Details
.exec(store, cmd) ⇒ Object
25 26 27 |
# File 'lib/git_store/diff.rb', line 25 def self.exec(store, cmd) list(store, IO.popen(cmd) { |io| io.read }) end |
.list(store, text) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/git_store/diff.rb', line 29 def self.list(store, text) lines = text.split("\n") diffs = [] while !lines.empty? m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(.+?) b/(.+)$}) if lines.first =~ /^old mode/ m, a_mode = *lines.shift.match(/^old mode (\d+)/) m, b_mode = *lines.shift.match(/^new mode (\d+)/) end if lines.empty? || lines.first =~ /^diff --git/ diffs << Diff.new(store, a_path, b_path, nil, nil, a_mode, b_mode, false, false, nil) next end new_file = false deleted_file = false if lines.first =~ /^new file/ m, b_mode = lines.shift.match(/^new file mode (.+)$/) a_mode = nil new_file = true elsif lines.first =~ /^deleted file/ m, a_mode = lines.shift.match(/^deleted file mode (.+)$/) b_mode = nil deleted_file = true end m, a_blob, b_blob, b_mode = *lines.shift.match(%r{^index ([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+) ?(.+)?$}) b_mode.strip! if b_mode diff_lines = [] while lines.first && lines.first !~ /^diff/ diff_lines << lines.shift end diff = diff_lines.join("\n") diffs << Diff.new(store, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff) end diffs end |