#1602: Fix & cleanup  for .bat and .com for commit hook launch on Windows
---------------------------------------+------------------------------------
 Reporter:  [EMAIL PROTECTED]  |        Owner:  jonas
     Type:  enhancement                |       Status:  new  
 Priority:  low                        |    Milestone:       
Component:  general                    |      Version:  devel
 Severity:  normal                     |   Resolution:       
 Keywords:  contrib hook windows       |  
---------------------------------------+------------------------------------
Comment (by cboos):

 {{{
 #!diff
 Index: api.py
 ===================================================================
 --- api.py      (revision 3216)
 +++ api.py      (working copy)
 @@ -258,7 +258,10 @@
              if hasattr(content, 'read'):
                  content = content.read(self.get_max_preview_size())
              full_mimetype = self.get_mimetype(filename, content)
 -        mimetype = full_mimetype.split(';')[0].strip() # split off
 charset
 +        if full_mimetype:
 +            mimetype = full_mimetype.split(';')[0].strip() # split off
 charset
 +        else:
 +            mimetype = full_mimetype = 'text/plain' # fallback if not
 binary

          # Determine candidate `IHTMLPreviewRenderer`s
          candidates = []
 }}}

 Do you think this would be OK?

 In last resort, the function `get_mimetype` returns
 `application/octet-stream` if the content is binary, but `None`
 otherwise.

 I'm not sure we can change the `get_mimetype` to return
 `text/plain` instead of `None`, as it's also used in `trac.web`.
 If you think we can change it, then the fix is even simpler:
 {{{
 #!diff
 Index: api.py
 ===================================================================
 --- api.py      (revision 3216)
 +++ api.py      (working copy)
 @@ -126,7 +126,7 @@
          if content and is_binary(content):
              return 'application/octet-stream'
          else:
 -            return None
 +            return 'text/plain'

  def is_binary(data):
      """Detect binary content by checking the first thousand bytes for
 zeroes.
 }}}

-- 
Ticket URL: <http://projects.edgewall.com/trac/ticket/1602>
The Trac Project <http://trac.edgewall.com/>
_______________________________________________
Trac-Tickets mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac-tickets

Reply via email to