Permalink
Browse files

Adds support for parsing and fetching patch filenames.

  • Loading branch information...
1 parent 55a82a6 commit 100274e6f0ba401785e38cf7343366bc08d2c149 @zlandau committed Apr 9, 2006
Showing with 15 additions and 8 deletions.
  1. +3 −3 patchwatch.rb
  2. +12 −5 patchwatch_parse.rb
View
@@ -123,8 +123,8 @@ def get patch_id
end
end
- class Download < R '/download/(\d+)'
- def get patch_id
+ class Download < R '/download/(\d+)/(.*)'
+ def get(patch_id, name)
@patch = Patch.find patch_id
@headers["Content-Type"] = "text/x-patch"
@body = @patch.content
@@ -300,7 +300,7 @@ def _patch_header
tr { th 'Submitter' ; td { a author.display_name, :href => "mailto:#{author.email}" } }
tr { th 'Date' ; td @patch.date.strftime(DATEFORMAT) }
tr { th 'Message ID'; td @patch.msgid }
- tr { th 'Download' ; td { a @patch.filename, :href => R(Download, @patch.id) } }
+ tr { th 'Download' ; td { a @patch.filename, :href => R(Download, @patch.id, @patch.filename) } }
if @logged_in
tr { th 'State' ; td do
tag! :select, :name => 'state_id' do
View
@@ -36,6 +36,11 @@ def parse_references(refs)
refs.split("\n\t")
end
+def parse_filename(contenttype)
+ ma = contenttype.match(/name="([^"]*)"/)
+ return ma ? ma[1] : "unamed"
+end
+
def parse_message(message)
patches = []
comments = []
@@ -84,6 +89,7 @@ def parse_message(message)
if is_patch?(part)
data.name = subject
+ data.filename = parse_filename(part.header["Content-Type"])
patches << data
elsif is_comment?(part)
comments << data
@@ -106,11 +112,12 @@ def add_patch(patch)
# If the patch exists, we silently ignore it
if not PatchWatch::Models::Patch.find_by_msgid(patch.msgid)
- PatchWatch::Models::Patch.create!(:name => patch.name,
- :date => patch.date,
- :content => patch.content,
- :msgid => patch.msgid,
- :author => author)
+ PatchWatch::Models::Patch.create!(:name => patch.name,
+ :filename => patch.filename,
+ :date => patch.date,
+ :content => patch.content,
+ :msgid => patch.msgid,
+ :author => author)
end
end
end

0 comments on commit 100274e

Please sign in to comment.