Skip to content

Commit

Permalink
Better handling for darcs changeset authors in rfc822 format ("blah <…
Browse files Browse the repository at this point in the history
…foo@bar.baz>")
  • Loading branch information
Steve authored and Steve committed Oct 17, 2007
1 parent 648f1b6 commit f76d7f2
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions darcs-to-git
Expand Up @@ -32,17 +32,19 @@ end

class DarcsPatch
attr_accessor :source_repo, :author, :date, :inverted, :identifier, :name, :is_tag, :git_tag_name
attr_reader :author_name, :author_email

def initialize(source_repo, patch_xml)
self.source_repo = source_repo
self.author = patch_xml.attribute('author').to_s
self.author = patch_xml.attribute('author').value
self.date = darcs_date_to_git_date(patch_xml.attribute('date').to_s)
self.inverted = (patch_xml.attribute('inverted').to_s == 'True')
self.identifier = patch_xml.attribute('hash').to_s
self.name = REXML::Text.unnormalize(patch_xml.get_elements('name').first.get_text.to_s)
self.name = patch_xml.get_elements('name').first.get_text.value
if (self.is_tag = (self.name =~ /^TAG (.*)/))
self.git_tag_name = $1.gsub(/[\s:]+/, '_')
end
author_scan
end

def <=>(other)
Expand All @@ -66,7 +68,10 @@ class DarcsPatch

def pull_and_apply
puts "\n" + ("=" * 80)
puts "PATCH: #{name} (#{date})"
puts "PATCH : #{name}"
puts "DATE : #{date}"
puts "AUTHOR: #{author_name}"
puts "EMAIL : #{author_email}"
puts "=" * 80

if id_in_git_repo
Expand All @@ -81,6 +86,16 @@ class DarcsPatch

private

def author_scan
@author_name, @author_email = if (author =~ /^\s*(\S.*?)\s*\<(\S+@\S+?)\>\s*$/)
[$1, $2]
elsif (author =~ /^\s*\<?(\S+@\S+?)\>?\s*$/)
[$1.split('@').first, $1]
else
[author, ''] # Could manufacture or insert email address here
end
end

def pull
run("darcs", "pull", "--all", "--quiet", "--match", "hash #{identifier}", "--set-scripts-executable", source_repo)
unless `darcs whatsnew -sl` =~ /^No changes!$/
Expand All @@ -90,7 +105,8 @@ class DarcsPatch
end

def apply_to_git_repo
ENV['GIT_AUTHOR_EMAIL'] = ENV['GIT_COMMITTER_EMAIL'] = author
ENV['GIT_AUTHOR_NAME'] = ENV['GIT_COMMITTER_NAME'] = author_name
ENV['GIT_AUTHOR_EMAIL'] = ENV['GIT_COMMITTER_EMAIL'] = author_email
ENV['GIT_AUTHOR_DATE'] = ENV['GIT_COMMITTER_DATE'] = date
if is_tag
run("git-tag", "-a", "-m", git_commit_message, git_tag_name)
Expand Down

0 comments on commit f76d7f2

Please sign in to comment.