class Commands::RevisionDiff

Summarizes changes between revisions

Public Class Methods

command_name() click to toggle source
# File lib/gdsh/revision_diff.rb, line 11
def self.command_name
  'diff'
end
function() click to toggle source
# File lib/gdsh/revision_diff.rb, line 19
def self.function
  'Compares and summarizes the changes between two revisions. If no ' \
  'revision numbers are provided, a consolidated summary is returned.'
end
new(client, params) click to toggle source
Calls superclass method Commands::GetFile::new
# File lib/gdsh/revision_diff.rb, line 24
def initialize(client, params)
  super(client, params)
  init_revisions
end
parameters() click to toggle source
# File lib/gdsh/revision_diff.rb, line 15
def self.parameters
  '(<file_id>[, <rev_1>, <rev_2>])'
end

Public Instance Methods

compare_and_print_change_count(low, high) click to toggle source
# File lib/gdsh/revision_diff.rb, line 60
def compare_and_print_change_count(low, high)
  changes = compare_two_revs(low, high)
  print_summary_of_changes(changes)
end
compare_two_revs(low, high) click to toggle source
# File lib/gdsh/revision_diff.rb, line 48
def compare_two_revs(low, high)
  first = download_revision_as_txt(low)
  second = download_revision_as_txt(high)
  Differ.diff_by_word(first, second)
end
consecutive_revisions() click to toggle source
# File lib/gdsh/revision_diff.rb, line 41
def consecutive_revisions
  return unless @all
  keys = modifying_users.keys.sort_by { |x| x.to_i }
  len = keys.length
  keys.first(len - 1).zip(keys.last(len - 1))
end
diff_author(pair) click to toggle source
# File lib/gdsh/revision_diff.rb, line 70
def diff_author(pair)
  "From rev #{pair[0]} to rev #{pair[1]} ".colorize(:green) +
  "modified by #{modifying_users[pair[0]]}".colorize(:green)
end
execute() click to toggle source
# File lib/gdsh/revision_diff.rb, line 75
def execute
  puts_diff_note
  if @all
    consecutive_revisions.each do |pair|
      puts diff_author(pair)
      compare_and_print_change_count(pair[0], pair[1])
    end
  else
    compare_and_print_change_count(@low_rev, @high_rev)
  end
end
init_revisions() click to toggle source
# File lib/gdsh/revision_diff.rb, line 29
def init_revisions
  @low_rev = (@params.length == 4) ? @params[2] : nil
  @high_rev = (@params.length == 4) ? @params[3] : nil
  @all = @low_rev.nil? && @high_rev.nil?
  return if @all || order_is_correct
  @low_rev, @high_rev = @high_rev, @low_rev
end
order_is_correct() click to toggle source
# File lib/gdsh/revision_diff.rb, line 37
def order_is_correct
  @high_rev.to_i > @low_rev.to_i
end
print_summary_of_changes(changes) click to toggle source
puts_diff_note() click to toggle source
# File lib/gdsh/revision_diff.rb, line 65
def puts_diff_note
  puts "Note: 'ab' -> 'ac' counts as both an insert and".colorize(:green) +
  ' a delete but counts as only one change.'.colorize(:green)
end