Class: RSCM::CvsLogParser

Inherits:
AbstractLogParser show all
Defined in:
lib/rscm/scm/cvs_log_parser.rb

Constant Summary collapse

REVISION_SEPARATOR =
/^----------------------------$/
ENTRY_SEPARATOR =
/^=============================================================================$/
STATES =

The state field is “Exp” both for added and modified files. retards! We need some additional logic to figure out whether it is added or not. Maybe look at the revision. (1.1 means new I think. - deal with it later)

{"dead" => RevisionFile::DELETED, "Exp" => RevisionFile::MODIFIED}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractLogParser

#convert_all_slashes_to_forward_slashes, #read_until_matching_line

Constructor Details

#initialize(io) ⇒ CvsLogParser

Returns a new instance of CvsLogParser.



15
16
17
# File 'lib/rscm/scm/cvs_log_parser.rb', line 15

def initialize(io)
  super(io)
end

Instance Attribute Details

#cvsmoduleObject

Returns the value of attribute cvsmodule.



13
14
15
# File 'lib/rscm/scm/cvs_log_parser.rb', line 13

def cvsmodule
  @cvsmodule
end

#cvspathObject

Returns the value of attribute cvspath.



12
13
14
# File 'lib/rscm/scm/cvs_log_parser.rb', line 12

def cvspath
  @cvspath
end

Instance Method Details

#determine_previous_native_revision_identifier(revision) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/rscm/scm/cvs_log_parser.rb', line 115

def determine_previous_native_revision_identifier(revision)
  if revision =~ /(.*)\.(.*)/
    big_version_number = $1
    small_version_number = $2.to_i
    if small_version_number == 1
      nil
    else
      "#{big_version_number}.#{small_version_number - 1}"
    end
  else
    nil
  end
end

#extract_match(string, regexp) ⇒ Object



137
138
139
140
141
142
143
# File 'lib/rscm/scm/cvs_log_parser.rb', line 137

def extract_match(string, regexp)
  if string=~regexp
    return($1)
  else
    ""
  end
end

#extract_required_match(string, regexp) ⇒ Object



129
130
131
132
133
134
135
# File 'lib/rscm/scm/cvs_log_parser.rb', line 129

def extract_required_match(string, regexp)
  if(string =~ regexp)
    return($1)
  else
    $stderr.puts("can't parse: '#{string}'\nexpected to match regexp: #{regexp.to_s}")
  end
end

#make_relative_to_module(file) ⇒ Object



72
73
74
75
76
# File 'lib/rscm/scm/cvs_log_parser.rb', line 72

def make_relative_to_module(file)
  return file if cvspath.nil? || cvsmodule.nil? || file.nil?
  cvspath = convert_all_slashes_to_forward_slashes(self.cvspath)
  convert_all_slashes_to_forward_slashes(file).gsub(/^#{cvspath}\/#{cvsmodule}\//, "")
end

#next_log_entryObject



33
34
35
# File 'lib/rscm/scm/cvs_log_parser.rb', line 33

def next_log_entry
  read_until_matching_line(ENTRY_SEPARATOR)
end

#parse_file(file_entry) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rscm/scm/cvs_log_parser.rb', line 78

def parse_file(file_entry)
  raise "can't parse: #{file_entry}" if file_entry =~ REVISION_SEPARATOR
     
  file_entry_lines = file_entry.split(/\r?\n/)

  file = RevisionFile.new
  file.native_revision_identifier =  extract_match(file_entry_lines[0], /revision (.*)$/)
  file.previous_native_revision_identifier = determine_previous_native_revision_identifier(file.native_revision_identifier)

  time = extract_required_match(file_entry_lines[1], /date: (.*?)(;|$)/)
  if(time.strip.length == 19)
    # CVS 1.11.x doesn't specify timezone (but assumes UTC), so we'll add it here.
    time += " +0000"
  end
  file.time = Time.parse(time).utc
  file.developer = extract_match(file_entry_lines[1], /author: (.*?);/)
  
  state = extract_match(file_entry_lines[1], /state: (.*?);/)
  file.status = STATES[state]
  
  message_start = 2
  branches = nil
  if(file_entry_lines[2] =~ /^branches:\s+(.*);/)
    message_start = 3
    branches = $1
  end

  file.message = file_entry_lines[message_start..-1].join("\n")
     
  # Ignore the initial revision from import - we will have two of them
  if(file.message == "Initial revision" && branches == "1.1.1")
    return nil
  end

  file
end

#parse_files(log_entry, revisions) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rscm/scm/cvs_log_parser.rb', line 49

def parse_files(log_entry, revisions)
  entries = split_entries(log_entry)

  entries[1..entries.length].each do |entry|
    file = parse_file(entry)
    next if file.nil?
    file.path = parse_path(entries[0])
    file.status = RevisionFile::ADDED if file.native_revision_identifier =~ /1\.1$/
    revisions.add(file)
  end
  nil
end

#parse_head_revision(first_entry) ⇒ Object



62
63
64
# File 'lib/rscm/scm/cvs_log_parser.rb', line 62

def parse_head_revision(first_entry)
  head_revision = extract_match(first_entry, /^head: (.*?)$/m)
end

#parse_path(first_entry) ⇒ Object



66
67
68
69
70
# File 'lib/rscm/scm/cvs_log_parser.rb', line 66

def parse_path(first_entry)
  working_file = extract_match(first_entry, /^Working file: (.*?)$/m)
  return convert_all_slashes_to_forward_slashes(working_file) unless working_file.nil? || working_file == ""
  make_relative_to_module(extract_required_match(first_entry, /^RCS file: (.*?)(,v|$)/m))
end

#parse_revisionsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rscm/scm/cvs_log_parser.rb', line 19

def parse_revisions
  revisions = Revisions.new
  while(log_entry = next_log_entry)
    begin
      parse_files(log_entry, revisions)
    rescue Exception => e
      $stderr.puts("could not parse log entry: #{log_entry}\ndue to: #{e.message}\n\t")
      $stderr.puts(e.backtrace.join("\n\t"))
    end
  end
  revisions.sort!
  revisions
end

#split_entries(log_entry) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rscm/scm/cvs_log_parser.rb', line 37

def split_entries(log_entry)
  entries = [""]
  log_entry.each_line do |line|
    if line=~REVISION_SEPARATOR
      entries << ""
    else
      entries[entries.length-1] << line
    end
  end
  entries
end