Class: RSCM::DarcsLogParser

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

Instance Method Summary collapse

Instance Method Details

#parse_revision(revision_io, path_revisions) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rscm/scm/darcs_log_parser.rb', line 31

def parse_revision(revision_io, path_revisions)
  revision = Revision.new

  doc = REXML::Document.new(revision_io)

  doc.elements.each("patch") do |element|
    revision.identifier =  element.attributes['hash']
    revision.developer = element.attributes['author']
    revision.time = Time.parse(element.attributes['local_date'])
    revision.message = element.elements["comment"].text
    revision.message.lstrip!
    revision.message.rstrip!

    element.elements["summary"].elements.each("add_file") do |file|
      add_changes(revision, file.text.strip, RevisionFile::ADDED, path_revisions)
    end
    element.elements["summary"].elements.each("modify_file") do |file|
      add_changes(revision, file.text.strip, RevisionFile::MODIFIED, path_revisions)
    end
  end

  revision
end

#parse_revisions(io, from_identifier = Time.epoch, to_identifier = Time.infinity) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rscm/scm/darcs_log_parser.rb', line 8

def parse_revisions(io, from_identifier=Time.epoch, to_identifier=Time.infinity)
  revisions = Revisions.new

  doc = REXML::Document.new(io)

  path_revisions = {}
  doc.elements.each("//patch") do |element|
    revision = parse_revision(element.to_s, path_revisions)
    if ((from_identifier <= revision.time) && (revision.time <= to_identifier))
      revisions.add(revision)
    end
  end

  revisions.each do |revision|
    revision.each do |change|
      current_index = path_revisions[change.path].index(change.native_revision_identifier)
      change.previous_native_revision_identifier = path_revisions[change.path][current_index + 1]
    end
  end

  revisions
end