Skip to content

Commit

Permalink
Convert git-check-ref-format logic into a single regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
purcell committed Jul 30, 2011
1 parent ff6ad5b commit 8f171f7
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions darcs-to-git
Expand Up @@ -287,26 +287,16 @@ class DarcsPatch
self.name = patch_xml.get_elements('name').first.get_text.value.darcs_unescape rescue 'Unnamed patch'
self.comment = patch_xml.get_elements('comment').first.get_text.value.darcs_unescape rescue nil
if (self.is_tag = (self.name =~ /^TAG (.*)/))
self.git_tag_name = $1.gsub(/[\s:*]+/, '_')
# git tag names cannot start or end with a period
if (self.git_tag_name[0] == ?.)
self.git_tag_name[0] = ?_
end
if (self.git_tag_name[self.git_tag_name.length - 1] == ?.)
self.git_tag_name[self.git_tag_name.length - 1] = ?_
end
# git tag names cannot contain two successive periods
while (i = self.git_tag_name.index('..'))
self.git_tag_name[i + 1] = ?_
end
# git tag names cannot contain #{
while (i = self.git_tag_name.index('#{'))
self.git_tag_name[i + 1] = ?_
end
self.git_tag_name = self.safe_patch_name($1)
end
@git_author_name, @git_author_email = AUTHOR_MAP[author]
end

def safe_patch_name(darcs_name)
# See 'man git-check-ref-format'
darcs_name.gsub(/(?:[\s:*]+|\.{2,}|\#\{|^.|\.$)/, '_')
end

def <=>(other)
self.identifier <=> other.identifier
end
Expand Down

0 comments on commit 8f171f7

Please sign in to comment.