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



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

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



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

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

#extract_required_match(string, regexp) ⇒ Object



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

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



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

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



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

def next_log_entry
  read_until_matching_line(ENTRY_SEPARATOR)
end

#parse_file(file_entry) ⇒ Object



77
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
# File 'lib/rscm/scm/cvs_log_parser.rb', line 77

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



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

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



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

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

#parse_path(first_entry) ⇒ Object



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

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
# 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!
end

#split_entries(log_entry) ⇒ Object



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

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