Class RSCM::MonotoneLogParser
In: lib/rscm/scm/monotone_log_parser.rb
Parent: Object

Methods

Public Instance methods

[Source]

    # File lib/rscm/scm/monotone_log_parser.rb, line 49
49:     def parse_revision(revision_io, path_revisions)
50:       revision = Revision.new
51:       state = nil
52:       revision_io.each_line do |line|
53:         if(line =~ /^Revision: (.*)$/ && revision.identifier.nil?)
54:           revision.identifier =  $1
55:         elsif(line =~ /^Author: (.*)$/ && revision.developer.nil?)
56:           revision.developer = $1
57:         elsif(line =~ /^Date: (.*)$/ && revision.time.nil?)
58:           revision.time = Time.utc(
59:             $1[0..3].to_i,
60:             $1[5..6].to_i,
61:             $1[8..9].to_i,
62:             $1[11..12].to_i,
63:             $1[14..15].to_i,
64:             $1[17..18].to_i
65:           )
66:         elsif(line =~ /^ChangeLog:\s*$/ && revision.message.nil?)
67:           state = :message
68:         elsif(state == :message && revision.message.nil?)
69:           revision.message = ""
70:         elsif(state == :message && revision.message)
71:           revision.message << line
72:         elsif(line =~ /^Added files:\s*$/)
73:           state = :added
74:         elsif(state == :added)
75:           add_changes(revision, line, RevisionFile::ADDED, path_revisions)
76:         elsif(line =~ /^Modified files:\s*$/)
77:           state = :modified
78:         elsif(state == :modified)
79:           add_changes(revision, line, RevisionFile::MODIFIED, path_revisions)
80:         end
81:       end
82:       revision.message.chomp! rescue revision.message = ''
83:       revision
84:     end

[Source]

    # File lib/rscm/scm/monotone_log_parser.rb, line 9
 9:     def parse_revisions(io, from_identifier=Time.epoch, to_identifier=Time.infinity)
10:       # skip first separator

11:       io.readline
12:       
13:       all_revisions = []
14:       revision_string = ""
15:       
16:       # hash of path => [array of revisions]

17:       path_revisions = {}
18:       io.each_line do |line|
19:         if(line =~ /-----------------------------------------------------------------/)
20:           revision = parse_revision(StringIO.new(revision_string), path_revisions)
21:           all_revisions << revision
22:           revision_string = ""
23:         else
24:           revision_string << line
25:         end
26:       end
27:       revision = parse_revision(StringIO.new(revision_string), path_revisions)
28:       all_revisions << revision
29:       
30:       # Filter out the revisions and set the previous revisions, knowing that most recent is at index 0.

31: 
32:       from_time = time(all_revisions, from_identifier, Time.epoch)
33:       to_time = time(all_revisions, to_identifier, Time.infinity)
34: 
35:       revisions = Revisions.new
36: 
37:       all_revisions.each do |revision|
38:         if((from_time < revision.time) && (revision.time <= to_time))
39:           revisions.add(revision)
40:           revision.each do |change|
41:             current_index = path_revisions[change.path].index(change.native_revision_identifier)
42:             change.previous_native_revision_identifier = path_revisions[change.path][current_index + 1]
43:           end
44:         end
45:       end
46:       revisions
47:     end

[Validate]