In Files

Parent

Namespace

Included Modules

Files

Git::Diff

object that holds the last X commits on given branch

Attributes

from[R]
to[R]

Public Class Methods

new(base, from = nil, to = nil) click to toggle source
    # File lib/git/diff.rb, line 7
 7:     def initialize(base, from = nil, to = nil)
 8:       @base = base
 9:       @from = from.to_s
10:       @to = to.to_s
11: 
12:       @path = nil
13:       @full_diff = nil
14:       @full_diff_files = nil
15:       @stats = nil
16:     end

Public Instance Methods

[](key) click to toggle source

enumerable methods

    # File lib/git/diff.rb, line 58
58:     def [](key)
59:       process_full
60:       @full_diff_files.assoc(key)[1]
61:     end
deletions() click to toggle source
    # File lib/git/diff.rb, line 34
34:     def deletions
35:       cache_stats
36:       @stats[:total][:deletions]
37:     end
each() click to toggle source
    # File lib/git/diff.rb, line 63
63:     def each(&block) # :yields: each Git::DiffFile in turn
64:       process_full
65:       @full_diff_files.map { |file| file[1] }.each(&block)
66:     end
insertions() click to toggle source
    # File lib/git/diff.rb, line 39
39:     def insertions
40:       cache_stats
41:       @stats[:total][:insertions]
42:     end
lines() click to toggle source
    # File lib/git/diff.rb, line 29
29:     def lines
30:       cache_stats
31:       @stats[:total][:lines]
32:     end
patch(file = nil) click to toggle source

if file is provided and is writable, it will write the patch into the file

    # File lib/git/diff.rb, line 50
50:     def patch(file = nil)
51:       cache_full
52:       @full_diff
53:     end
Also aliased as: to_s
path(path) click to toggle source
    # File lib/git/diff.rb, line 19
19:     def path(path)
20:       @path = path
21:       return self
22:     end
size() click to toggle source
    # File lib/git/diff.rb, line 24
24:     def size
25:       cache_stats
26:       @stats[:total][:files]
27:     end
stats() click to toggle source
    # File lib/git/diff.rb, line 44
44:     def stats
45:       cache_stats
46:       @stats
47:     end
to_s(file = nil) click to toggle source
Alias for: patch

Private Instance Methods

cache_full() click to toggle source
     # File lib/git/diff.rb, line 98
 98:       def cache_full
 99:         unless @full_diff
100:           @full_diff = @base.lib.diff_full(@from, @to, {:path_limiter => @path})
101:         end
102:       end
cache_stats() click to toggle source
     # File lib/git/diff.rb, line 111
111:       def cache_stats
112:         unless @stats
113:           @stats = @base.lib.diff_stats(@from, @to, {:path_limiter => @path})
114:         end
115:       end
process_full() click to toggle source
     # File lib/git/diff.rb, line 104
104:       def process_full
105:         unless @full_diff_files
106:           cache_full
107:           @full_diff_files = process_full_diff
108:         end
109:       end
process_full_diff() click to toggle source

break up @diff_full

     # File lib/git/diff.rb, line 118
118:       def process_full_diff
119:         final = {}
120:         current_file = nil
121:         @full_diff.split("\n").each do |line|
122:           if m = /diff --git a\/(.*?) b\/(.*?)/.match(line)
123:             current_file = m[1]
124:             final[current_file] = {:patch => line, :path => current_file, 
125:                                     :mode => '', :src => '', :dst => '', :type => 'modified'}
126:           else
127:             if m = /index (.......)\.\.(.......)( ......)*/.match(line)
128:               final[current_file][:src] = m[1]
129:               final[current_file][:dst] = m[2]
130:               final[current_file][:mode] = m[3].strip if m[3]
131:             end
132:             if m = /(.*?) file mode (......)/.match(line)
133:               final[current_file][:type] = m[1]
134:               final[current_file][:mode] = m[2]
135:             end
136:             if m = /^Binary files /.match(line)
137:               final[current_file][:binary] = true
138:             end
139:             final[current_file][:patch] << "\n" + line 
140:           end
141:         end
142:         final.map { |e| [e[0], DiffFile.new(@base, e[1])] }
143:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.