changeset 152:0c00fbaff55a

Fixed differ to properly extract filenames, and dates from diff file. and swaped order of columns with lines nr in diff html
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 15 May 2010 19:53:23 +0200
parents 988477a05db6
children a5a3bcc5ee89
files pylons_app/controllers/files.py pylons_app/lib/differ.py pylons_app/templates/files/file_diff.html
diffstat 3 files changed, 22 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/controllers/files.py	Sat May 15 19:05:13 2010 +0200
+++ b/pylons_app/controllers/files.py	Sat May 15 19:53:23 2010 +0200
@@ -83,15 +83,19 @@
         c.repo = hg_model.get_repo(c.repo_name)
         c.changeset_1 = c.repo.get_changeset(diff1)
         c.changeset_2 = c.repo.get_changeset(diff2)
-        
-        c.file_1 = c.changeset_1.get_file_content(f_path)
-        c.file_2 = c.changeset_2.get_file_content(f_path)
+        f1 = c.changeset_1.get_node(f_path)
+        f2 = c.changeset_2.get_node(f_path)
+
         c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1._short)
         c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2._short)
 
-        d2 = unified_diff(c.file_1.splitlines(1), c.file_2.splitlines(1))
-        c.diff_files = render_udiff(udiff=d2)
+        f_udiff = unified_diff(f1.content.splitlines(True),
+                               f2.content.splitlines(True),
+                               f1.name,
+                               f2.name)
         
+        c.diff_files = render_udiff(udiff=f_udiff, differ='difflib')
+        print c.diff_files
         if len(c.diff_files) < 1:
             c.no_changes = True
         return render('files/file_diff.html')
--- a/pylons_app/lib/differ.py	Sat May 15 19:05:13 2010 +0200
+++ b/pylons_app/lib/differ.py	Sat May 15 19:53:23 2010 +0200
@@ -40,11 +40,18 @@
         """Extract the filename and revision hint from a line."""
         try:
             if line1.startswith('--- ') and line2.startswith('+++ '):
-                filename, old_rev = line1[4:].split(None, 1)
-                new_rev = line2[4:].split(None, 1)[1]
-                return filename, 'old', 'new'
+                l1 = line1[4:].split(None, 1)
+                old_filename = l1[0] if len(l1) >= 1 else None
+                old_rev = l1[1] if len(l1) == 2 else 'old'
+                
+                l2 = line1[4:].split(None, 1)
+                new_filename = l2[0] if len(l2) >= 1 else None
+                new_rev = l2[1] if len(l2) == 2 else 'new'
+                                 
+                return old_filename, new_rev, old_rev
         except (ValueError, IndexError):
             pass
+        
         return None, None, None
 
     def _highlight_line_difflib(self, line, next):
--- a/pylons_app/templates/files/file_diff.html	Sat May 15 19:05:13 2010 +0200
+++ b/pylons_app/templates/files/file_diff.html	Sat May 15 19:53:23 2010 +0200
@@ -39,11 +39,11 @@
 		            %for x in diff['chunks']:
 		                %for y in x:
 		                    <tr class="line ${y['action']}">
+		                        <td id="#${diff['filename']}_O${y['old_lineno']}" class="lineno old">
+		                              <pre><a href="#${diff['filename']}_O${y['old_lineno']}">${y['old_lineno']}</a></pre>
+		                        </td>		                    
 		                        <td id="#${diff['filename']}_N${y['new_lineno']}"class="lineno new">
 		                              <pre><a href="#${diff['filename']}_N${y['new_lineno']}">${y['new_lineno']}</a></pre>
-		                        </td>
-		                        <td id="#${diff['filename']}_O${y['old_lineno']}" class="lineno old">
-		                              <pre><a href="#${diff['filename']}_O${y['old_lineno']}">${y['old_lineno']}</a></pre>
 		                        </td>                        
 		                       <td class="code">
 		                           <pre>${y['line']|n}</pre>