changeset 273:cad478edb1c7

added support for binary files, and, protection again unicode decode errors that might occure in changesets views
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 08 Jun 2010 23:48:41 +0200
parents a83e86e3f580
children 5db466f19b8d
files pylons_app/controllers/changeset.py
diffstat 1 files changed, 29 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/controllers/changeset.py	Tue Jun 08 23:02:24 2010 +0200
+++ b/pylons_app/controllers/changeset.py	Tue Jun 08 23:48:41 2010 +0200
@@ -48,17 +48,39 @@
                 
         for node in c.changeset.added:
             filenode_old = FileNode(node.path, '')
-            f_udiff = differ.get_udiff(filenode_old, node)
-            diff = differ.DiffProcessor(f_udiff).as_html()
-            c.changes.append(('added', node, diff))
+            if filenode_old.is_binary or node.is_binary:
+                diff = 'binary file'
+            else:    
+                f_udiff = differ.get_udiff(filenode_old, node)
+                diff = differ.DiffProcessor(f_udiff).as_html()
+                try:
+                    diff = unicode(diff)
+                except:
+                    log.warning('Decoding failed of %s', filenode_old)
+                    log.warning('Decoding failed of %s', node)
+                    diff = 'unsupported type'
+            cs1 = None
+            cs2 = node.last_changeset.raw_id                                        
+            c.changes.append(('added', node, diff, cs1, cs2))
             
         for node in c.changeset.changed:
             filenode_old = c.changeset_old.get_node(node.path)
-            f_udiff = differ.get_udiff(filenode_old, node)
-            diff = differ.DiffProcessor(f_udiff).as_html()
-            c.changes.append(('changed', node, diff))
+            if filenode_old.is_binary or node.is_binary:
+                diff = 'binary file'
+            else:    
+                f_udiff = differ.get_udiff(filenode_old, node)
+                diff = differ.DiffProcessor(f_udiff).as_html()
+                try:
+                    diff = unicode(diff)
+                except:
+                    log.warning('Decoding failed of %s', filenode_old)
+                    log.warning('Decoding failed of %s', node)                    
+                    diff = 'unsupported type'
+            cs1 = filenode_old.last_changeset.raw_id
+            cs2 = node.last_changeset.raw_id                    
+            c.changes.append(('changed', node, diff, cs1, cs2))
             
         for node in c.changeset.removed:
-            c.changes.append(('removed', node, None))            
+            c.changes.append(('removed', node, None, None, None))            
             
         return render('changeset/changeset.html')