Class: RSCM::Perforce

Inherits:
Base
  • Object
show all
Defined in:
lib/rscm/scm/perforce.rb

Constant Summary collapse

DATE_FORMAT =
"%Y/%m/%d:%H:%M:%S"
CHANGELIST_PATTERN =

Doesn’t work for empty messages, (Like 21358 in Aslak’s P4 repo)

/^Change \d+ by (.*)@.* on (.*)\n\n(.*)\n\nAffected files ...\n\n(.*)/m
CHANGELIST_PATTERN_NO_MSG =

But this one does

/^Change \d+ by (.*)@.* on (.*)\n\nAffected files ...\n\n(.*)/m

Constants inherited from Base

Base::DEFAULT_QUIET_PERIOD, Base::THIRTY_TWO_WEEKS_AGO, Base::TWO_WEEKS_AGO

Instance Attribute Summary

Attributes inherited from Base

#default_options, #logger

Instance Method Summary collapse

Methods inherited from Base

#==, #add, #can_create_central?, #central_exists?, #checked_out?, #checked_out_files, #checkout, #checkout_commandline, #checkout_dir, #checkout_dir=, #commit, #create_central, #destroy_central, #destroy_working_copy, #diff, #edit, #file, #import_central, #install_trigger, #move, #open, #poll_new_revisions, #rootdir, #supports_trigger?, #to_identifier, #to_yaml_properties, #transactional?, #trigger_installed?, #trigger_mechanism, #uninstall_trigger, #update_commandline, #uptodate?

Constructor Details

#initialize(user = nil, password = nil, view = nil) ⇒ Perforce

Returns a new instance of Perforce.



21
22
23
# File 'lib/rscm/scm/perforce.rb', line 21

def initialize(user=nil, password=nil, view=nil)
  @user, @password = user, password
end

Instance Method Details

#revisions(from_identifier, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rscm/scm/perforce.rb', line 25

def revisions(from_identifier, options={})
  from_identifier = Time.epoch unless from_identifier
  from_identifier = Time.epoch if (from_identifier.is_a? Time and from_identifier < Time.epoch)
  from = revision_spec(from_identifier+1) # We have to add 1 because of the constract of this method.

  to_identifier = options[:to_identifier] ? options[:to_identifier] : Time.infinity
  to = revision_spec(to_identifier)

  changes = execute("p4 #{p4_opts(false)} changes //...@#{from},#{to}", options) do |io|
    io.read
  end
  
  revs = changes.collect do |line|
    revision = Revision.new
    revision.identifier = line.match(/^Change (\d+)/)[1].to_i

    execute("p4 #{p4_opts(false)} describe -s #{revision.identifier}", options) do |io|
      log = io.read

      if log =~ CHANGELIST_PATTERN
        revision.developer, time, revision.message, files = $1, $2, $3, $4
      elsif log =~ CHANGELIST_PATTERN_NO_MSG
        revision.developer, time, files = $1, $2, $3
      else
        puts "PARSE ERROR:"
        puts log
        puts "\nDIDN'T MATCH:"
        puts CHANGELIST_PATTERN
      end

      revision.time = Time.parse(time)

      files.each_line do |line|
        if line =~ /^\.\.\. (\/\/.+)#(\d+) (.+)/
          if(STATES[$3.strip])
            file = RevisionFile.new
            file.path = $1
            file.native_revision_identifier = $2.to_i
            file.previous_native_revision_identifier = file.native_revision_identifier-1
            file.status = STATES[$3.strip]
            file.time = revision.time
            file.message = revision.message
            file.developer = revision.developer
            revision << file
          end
        end
      end

    end

    revision
  end
  Revisions.new(revs.reverse)
end