From 245fd3a05d6ee788ca057a8c602071d0348d16e7 Mon Sep 17 00:00:00 2001
From: Jonas Haag <jonas@lophus.org>
Date: Fri, 3 Jun 2011 14:01:05 +0200
Subject: [PATCH] History view: Don't crash on file deletions or additions

---
 repo.py                    | 15 +++++++++++----
 templates/view_commit.html |  2 +-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/repo.py b/repo.py
index 9699e0c..da30ca6 100644
--- a/repo.py
+++ b/repo.py
@@ -46,15 +46,22 @@ class RepoWrapper(dulwich.repo.Repo):
 
     def _path_changed_between(self, path, commit1, commit2):
         path, filename = os.path.split(path)
-        blob1 = self.get_tree(commit1, path)[filename]
-        blob2 = self.get_tree(commit2, path)[filename]
-        return blob1[1] != blob2[1]
+        tree1 = self.get_tree(commit1, path)
+        tree2 = self.get_tree(commit2, path)
+        try:
+            blob1 = tree1[filename]
+            blob2 = tree2[filename]
+            return blob1 == blob2
+        except KeyError:
+            # file new or deleted in tree2
+            return True
 
     def get_tree(self, commit, path):
         tree = self[commit.tree]
         if path:
             for directory in path.split('/'):
-                tree = self[tree[directory][1]]
+                if directory:
+                    tree = self[tree[directory][1]]
         return tree
 
     def listdir(self, commit, root=None):
diff --git a/templates/view_commit.html b/templates/view_commit.html
index a9a7b03..6849c9f 100644
--- a/templates/view_commit.html
+++ b/templates/view_commit.html
@@ -15,7 +15,7 @@
     <span class=datetime>{{ commit.commit_time|timesince }} ago</span>
   </div>
   <div class=changes>
-    {{ repo.commit_diff(commit)|pygmentize }}
+    {{ repo.commit_diff(commit)|pygmentize('udiff') }}
   </div>
 </div>
 
-- 
GitLab