Class Grit::Diff
In: lib/grit/diff.rb
Parent: Object

Methods

Attributes

a_blob  [R] 
a_mode  [R] 
a_path  [R] 
b_blob  [R] 
b_mode  [R] 
b_path  [R] 
deleted_file  [R] 
diff  [R] 
new_file  [R] 

Public Class methods

[Source]

    # File lib/grit/diff.rb, line 23
23:     def self.list_from_string(repo, text)
24:       lines = text.split("\n")
25:       
26:       diffs = []
27:       
28:       while !lines.empty?
29:         m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(.+?) b/(.+)$})
30:         
31:         if lines.first =~ /^old mode/
32:           m, a_mode = *lines.shift.match(/^old mode (\d+)/)
33:           m, b_mode = *lines.shift.match(/^new mode (\d+)/)
34:         end
35:         
36:         if lines.empty? || lines.first =~ /^diff --git/
37:           diffs << Diff.new(repo, a_path, b_path, nil, nil, a_mode, b_mode, false, false, nil)
38:           next
39:         end
40:         
41:         new_file = false
42:         deleted_file = false
43:         
44:         if lines.first =~ /^new file/
45:           m, b_mode = lines.shift.match(/^new file mode (.+)$/)
46:           a_mode = nil
47:           new_file = true
48:         elsif lines.first =~ /^deleted file/
49:           m, a_mode = lines.shift.match(/^deleted file mode (.+)$/)
50:           b_mode = nil
51:           deleted_file = true
52:         end
53:         
54:         m, a_blob, b_blob, b_mode = *lines.shift.match(%r{^index ([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+) ?(.+)?$})
55:         b_mode.strip! if b_mode
56:         
57:         diff_lines = []
58:         while lines.first && lines.first !~ /^diff/
59:           diff_lines << lines.shift
60:         end
61:         diff = diff_lines.join("\n")
62:         
63:         diffs << Diff.new(repo, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff)
64:       end
65:       
66:       diffs
67:     end

[Source]

    # File lib/grit/diff.rb, line 10
10:     def initialize(repo, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff)
11:       @repo = repo
12:       @a_path = a_path
13:       @b_path = b_path
14:       @a_blob = a_blob =~ /^0{40}$/ ? nil : Blob.create(repo, :id => a_blob)
15:       @b_blob = b_blob =~ /^0{40}$/ ? nil : Blob.create(repo, :id => b_blob)
16:       @a_mode = a_mode
17:       @b_mode = b_mode
18:       @new_file = new_file
19:       @deleted_file = deleted_file
20:       @diff = diff
21:     end

[Validate]