Class: Churn::HgAnalyzer

### Home Classes Methods

### In Files

- lib/churn/hg_analyzer.rb

### Parent

Churn::SourceControl

### Methods

- #get_logs
- #get_revisions
- #get_updated_files_change_info
- #get_updated_files_from_log

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- Churn
- Churn::ChurnCalculator
- Churn::ChurnHistory
- Churn::GitAnalyzer
- Churn::HgAnalyzer
- Churn::LocationMapping
- Churn::SourceControl
- Churn::SvnAnalyzer
- Object

No matching classes.

# Churn::HgAnalyzer

### Public Instance Methods

get_logs() click to toggle source

    # File lib/churn/hg_analyzer.rb, line 3
    def get_logs
      `hg log -v#{date_range}`.split("\n").reject{|line| line !~ /^files:/}.map{|l| l.split(" ")[1..-1]}.flatten
    end

get_revisions() click to toggle source

    # File lib/churn/hg_analyzer.rb, line 7
    def get_revisions
      `hg log#{date_range}`.split("\n").reject{|line| line !~ /^changeset:/}.map{|l| l[/:(\S+)$/, 1] }
    end

get_updated_files_change_info(revision, revisions) click to toggle source

    # File lib/churn/hg_analyzer.rb, line 22
    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.match(/^---/) || line.match(/^\+\+\+/)
          # Remove the --- a/ and +++ b/ if present
          recent_file = get_recent_file(line)
          updated[recent_file] = [] unless updated.include?(recent_file)
        elsif line.match(/^@@/)
          # 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.match(/^---/)
          raise "hg diff lines that don't match the two patterns aren't expected: '#{line}'"
        end
      end
      updated
    end

get_updated_files_from_log(revision, revisions) click to toggle source

    # File lib/churn/hg_analyzer.rb, line 11
    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
        `hg diff -r #{revision}:#{previous_revision} -U 0`.split(/\n/).select{|line| line.match(/^@@/) || line.match(/^---/) || line.match(/^\+\+\+/) }
      else
        []
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.