Class: Perforce2Svn::Perforce::CommitBuilder

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/perforce2svn/perforce/commit_builder.rb

Overview

Used to build commit information from the pretty much crazy data the P4 library returns

Instance Method Summary collapse

Methods included from Logging

configure, log, #log

Constructor Details

#initialize(mappings) ⇒ CommitBuilder

Returns a new instance of CommitBuilder.



55
56
57
58
# File 'lib/perforce2svn/perforce/commit_builder.rb', line 55

def initialize(mappings)
  @mappings = mappings
  @log_converter = Iconv.new('UTF-8//IGNORE/TRANSLIT', 'UTF-8')
end

Instance Method Details

#build_from(raw_commit) ⇒ Object

Builds from a raw P4 library return



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/perforce2svn/perforce/commit_builder.rb', line 97

def build_from(raw_commit)
  changes = unpack_file_changes(raw_commit)
  return nil unless changes

  revision = raw_commit['change'].to_i
  author = raw_commit['user']
  commit_log = @log_converter.iconv(raw_commit['desc'].gsub(/\r/, ''))
  time = Time.at(raw_commit['time'].to_i)
  
  PerforceCommit.new(revision, author, commit_log, time, changes)
end

#commit_at(revision) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/perforce2svn/perforce/commit_builder.rb', line 88

def commit_at(revision)
  P4Depot.instance.query do |p4|
    log.debug "PERFORCE: Inspecting revision: #{revision}"
    raw_commit = p4.run('describe', '-s', "#{revision}")[0]
    return build_from(raw_commit)
  end
end

#commits_in(version_range, &block) ⇒ Object

Raises:

  • (ArgumentError)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/perforce2svn/perforce/commit_builder.rb', line 60

def commits_in(version_range, &block)
  raise ArgumentError, "Requires a block" unless block_given?
  if version_range.synced_to_head?
    version_range.reset_to_head(P4Depot.instance.latest_revision)
  end

  skipped_previous = false
  version_range.min.upto(version_range.max) do |revision|
    commit = commit_at(revision)
    if commit
      if skipped_previous
        print "\n"
      end
      skipped_previous = false
      yield commit
    else
      if log.debug? 
        log.info "Skipping irrelevant revision: #{revision}"
      elsif skipped_previous
        print "\r[INFO]  Skipping irrelevant revision: #{revision}"
      else
        print "[INFO]  Skipping irrelevant revision: #{revision}"
      end
      skipped_previous = true
    end
  end
end