Class: Churn::SourceControl

Inherits:
Object
  • Object
show all
Defined in:
lib/churn/scm/source_control.rb

Overview

Base clase for analyzing various SCM systems like git, HG, and SVN

Direct Known Subclasses

BzrAnalyzer, GitAnalyzer, HgAnalyzer, SvnAnalyzer

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_date = nil) ⇒ SourceControl

Returns a new instance of SourceControl.



20
21
22
# File 'lib/churn/scm/source_control.rb', line 20

def initialize(start_date=nil)
  @start_date = start_date
end

Class Method Details

.set_source_control(start_date) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/churn/scm/source_control.rb', line 6

def self.set_source_control(start_date)
  analyzers = [GitAnalyzer, HgAnalyzer, BzrAnalyzer, SvnAnalyzer]
  analyzer = analyzers.detect(&:supported?)
  if analyzer
    analyzer.new(start_date)
  else
    raise "Churn requires a bazaar, git, mercurial, or subversion source control"
  end
end

.supported?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/churn/scm/source_control.rb', line 16

def self.supported?
  raise "child class must implement"
end

Instance Method Details

#generate_history(starting_point) ⇒ Object



32
33
34
# File 'lib/churn/scm/source_control.rb', line 32

def generate_history(starting_point)
  raise "child class must implement"
end

#get_logsObject



24
25
26
# File 'lib/churn/scm/source_control.rb', line 24

def get_logs
  raise "child class must implement"
end

#get_revisionsObject



28
29
30
# File 'lib/churn/scm/source_control.rb', line 28

def get_revisions
  raise "child class must implement"
end

#get_updated_files_change_info(revision, revisions) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/churn/scm/source_control.rb', line 36

def get_updated_files_change_info(revision, revisions)
  updated     = {}
  logs        = get_updated_files_from_log(revision, revisions)
  recent_file = nil
  logs.each do |line|
    if /^---|^\+\+\+/ =~ line
      # Remove the --- a/ and +++ b/ if present
      recent_file = get_recent_file(line)
      updated[recent_file] = [] unless updated.include?(recent_file)
    elsif /^@@/ =~ line
      # Now add the added/removed ranges for the line
      removed_range = get_changed_range(line, '-')
      added_range   = get_changed_range(line, '\+')
      updated[recent_file] << removed_range
      updated[recent_file] << added_range
    else
      puts /^---/ =~ line
      raise "diff lines that don't match the two patterns aren't expected: '#{line}'"
    end
  end
  updated
end

#get_updated_files_from_log(revision, revisions) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/churn/scm/source_control.rb', line 59

def get_updated_files_from_log(revision, revisions)
  current_index = revisions.index(revision)
  previous_index = current_index+1
  previous_revision = revisions[previous_index] unless revisions.length < previous_index
  if revision && previous_revision
    get_diff(revision, previous_revision)
  else
    []
  end
end