class 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/arpm/vendor/ruby-git/git/diff.rb, line 7
def initialize(base, from = nil, to = nil)
  @base = base
  @from = from.to_s
  @to = to.to_s

  @path = nil
  @full_diff = nil
  @full_diff_files = nil
  @stats = nil
end

Public Instance Methods

[](key) click to toggle source

enumerable methods

# File lib/arpm/vendor/ruby-git/git/diff.rb, line 58
def [](key)
  process_full
  @full_diff_files.assoc(key)[1]
end
deletions() click to toggle source
# File lib/arpm/vendor/ruby-git/git/diff.rb, line 34
def deletions
  cache_stats
  @stats[:total][:deletions]
end
each() { |each DiffFile in turn| ... } click to toggle source
# File lib/arpm/vendor/ruby-git/git/diff.rb, line 63
def each(&block) # :yields: each Git::DiffFile in turn
  process_full
  @full_diff_files.map { |file| file[1] }.each(&block)
end
insertions() click to toggle source
# File lib/arpm/vendor/ruby-git/git/diff.rb, line 39
def insertions
  cache_stats
  @stats[:total][:insertions]
end
lines() click to toggle source
# File lib/arpm/vendor/ruby-git/git/diff.rb, line 29
def lines
  cache_stats
  @stats[:total][:lines]
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/arpm/vendor/ruby-git/git/diff.rb, line 50
def patch(file = nil)
  cache_full
  @full_diff
end
Also aliased as: to_s
path(path) click to toggle source
# File lib/arpm/vendor/ruby-git/git/diff.rb, line 19
def path(path)
  @path = path
  return self
end
size() click to toggle source
# File lib/arpm/vendor/ruby-git/git/diff.rb, line 24
def size
  cache_stats
  @stats[:total][:files]
end
stats() click to toggle source
# File lib/arpm/vendor/ruby-git/git/diff.rb, line 44
def stats
  cache_stats
  @stats
end
to_s(file = nil)
Alias for: patch

Private Instance Methods

cache_full() click to toggle source
# File lib/arpm/vendor/ruby-git/git/diff.rb, line 98
def cache_full
  unless @full_diff
    @full_diff = @base.lib.diff_full(@from, @to, {:path_limiter => @path})
  end
end
cache_stats() click to toggle source
# File lib/arpm/vendor/ruby-git/git/diff.rb, line 111
def cache_stats
  unless @stats
    @stats = @base.lib.diff_stats(@from, @to, {:path_limiter => @path})
  end
end
process_full() click to toggle source
# File lib/arpm/vendor/ruby-git/git/diff.rb, line 104
def process_full
  unless @full_diff_files
    cache_full
    @full_diff_files = process_full_diff
  end
end
process_full_diff() click to toggle source

break up @diff_full

# File lib/arpm/vendor/ruby-git/git/diff.rb, line 118
def process_full_diff
  final = {}
  current_file = nil
  @full_diff.split("\n").each do |line|
    if m = /diff --git a\/(.*?) b\/(.*?)/.match(line)
      current_file = m[1]
      final[current_file] = {:patch => line, :path => current_file, 
                              :mode => '', :src => '', :dst => '', :type => 'modified'}
    else
      if m = /index (.......)\.\.(.......)( ......)*/.match(line)
        final[current_file][:src] = m[1]
        final[current_file][:dst] = m[2]
        final[current_file][:mode] = m[3].strip if m[3]
      end
      if m = /(.*?) file mode (......)/.match(line)
        final[current_file][:type] = m[1]
        final[current_file][:mode] = m[2]
      end
      if m = /^Binary files /.match(line)
        final[current_file][:binary] = true
      end
      final[current_file][:patch] << "\n" + line 
    end
  end
  final.map { |e| [e[0], DiffFile.new(@base, e[1])] }
end