Permalink
Browse files

more bug fixes introduced after all of the refactoring

  • Loading branch information...
freshtonic committed Jun 9, 2008
1 parent d8c9729 commit edebcc6190fc0abc485b15e1c4813cfc0ed1b7ba
Showing with 35 additions and 33 deletions.
  1. +9 −11 darcs-fast-export.rb
  2. +26 −22 patch_parser.rb
View
@@ -285,8 +285,8 @@ def initialize(gitrepo, patch_name, logger, skip_binaries, authors)
def metadata author, short_msg, long_msg, timestamp, inverted
@author = author
- @git_message = "#{short_msg}\n#{@long_msg}\n\n" +
- "Exported from Darcs patch: #{@patch_name}".gsub("[']", '["]')
+ @git_message = ("#{short_msg}\n#{long_msg}\n\n" +
+ "Exported from Darcs patch: #{@patch_name}").gsub(/[']/, '"')
@timestamp = timestamp
@inverted = inverted
end
@@ -309,12 +309,11 @@ def move file, to
# a file that's not yet on disk, let's just simply remove
# the name from 'added_files' if it's there, and replace
# it with the new name.
+ File.rename "#{@gitrepo}/#{file}", "#{@gitrepo}/#{to}"
if @added.include? file
@added.delete(file)
- @added<< to
- else
- File.rename "#{@gitrepo}/#{file}", "#{@gitrepo}/#{to}"
end
+ @added << to
@renamed[file] = to
end
@@ -340,13 +339,12 @@ def hunk file, line_number, inserted_lines, deleted_lines
if inserted_lines.size == 0
log "No lines were inserted"
else
- log "lines were supposed to be inserted - something bad has happened"
- exit 1
+ raise "lines were supposed to be inserted - something bad has happened"
end
end
end
- def changepref pref, value
+ def changepref
# do nothing. No equivalent exists in Git
end
@@ -382,15 +380,15 @@ def merger
# do nothing (the parser currently skips over them)
end
- def replace file, to_replace, replacement
+ def replace file, regexp, oldtext, newtext
command = "sed -i 's/#{oldtext}/#{newtext}/g' #{@gitrepo}/#{file}"
Open3.popen3("(#{command})") do |sin,sout,serr|
log "executing command '#{command}'"
sinlines = sout.readlines
serrlines = serr.readlines
if serrlines.size > 0
serrlines.each {|line| $stderr.puts line }
- exit 1
+ raise "error executing command '#{command}'"
end
end
end
@@ -420,7 +418,7 @@ def run_git(command)
if serrlines.size > 0
serrlines.each {|line| $stderr.puts line }
log "in patch #{@current_patch}"
- exit 1
+ raise "executing command '#{command}'"
end
end
end
View
@@ -1,5 +1,10 @@
#!/usr/bin/ruby
+# Parses Darcs 1 patches.
+# Will not handle Darcs 2 repositories.
+# NOTE: this class assumes that IO#ungetc can be invoked more than
+# once (enough times to push back a line of text). This is not
+# guaranteed by the Ruby docs, but works for me.
class DarcsPatchParser
def initialize(instream, handler = PatchHandler.new)
@@ -65,6 +70,7 @@ def parse_body
to = fix_file_name(to)
@handler.move from, to
elsif token == "merger"
+ unread_line("merger")
parse_merger
@handler.merger # currently we ignore mergers
elsif token == "changepref"
@@ -127,9 +133,14 @@ def parse_changepref
# consume it only. Not interested in the values.
read_line
read_line
+ read_line
end
def parse_merger
+ # FIXME: this doesn't seem to work for deeply nexted merges.
+ # SEE: 20070329070647-40eb8-55ed38a7c409671953f1306f4d69538addf296d1.gz
+ # fails trying to apply hunk to file:
+ # ./adminapp/src/java/com/mooter/admanager/priv/bucket/ui/CreateSearchBucketController.java
depth = 0
begin
line = read_line
@@ -194,27 +205,20 @@ def parse_header
header_regexp =
/^\[([^\n]+)\n([^\*]+)\*([-\*])(\d{14})(?:\n((?:^\ [^\n]*\n)+))?\]/
-
- first_few_lines = ""
- 8.times {|i| first_few_lines += read_line }
-
- match_data = header_regexp.match(first_few_lines)
- if !match_data.nil?
- short_message = $1
- author_email = $2
- inverted = $3 == "-" ? true : false
- timestamp = $4
- long_message = $5
-
- length_of_match = match_data[0].size
-
- # push the remaining part of the last 10 lines back onto the stream.
- first_few_lines[length_of_match..-1].reverse.each_byte {|b| @in.ungetc b}
-
- return author_email, short_message, long_message, timestamp, inverted
- else
- raise PatchParseException, "could not parse patch header: '#{first_few_lines}'"
+ lines = read_line
+ until match_data = header_regexp.match(lines)
+ lines += read_line
end
+
+ short_message = $1
+ author_email = $2
+ inverted = $3 == "-" ? true : false
+ timestamp = $4
+ long_message = $5
+ length_of_match = match_data[0].size
+ # push the remaining part of the last 10 lines back onto the stream.
+ lines[length_of_match..-1].reverse.each_byte {|b| @in.ungetc b}
+ return author_email, short_message, long_message, timestamp, inverted
end
def expect_char(expected_ch)
@@ -241,7 +245,7 @@ def move file, to
def hunk file, line_number, inserted_lines, deleted_lines
puts "hunk: file: '#{file}' line: #{line_number}"
end
- def changepref pref, value
+ def changepref
puts "changepref"
end
def rmfile file
@@ -256,7 +260,7 @@ def binary file, datastream
def merger
puts "merger:"
end
- def replace file, to_replace, replacement
+ def replace file, regexp, to_replace, replacement
puts "replace: file '#{file}' replace: '#{to_replace}' with '#{replacement}'"
end
def skip_binaries?

0 comments on commit edebcc6

Please sign in to comment.