Steve Borho avatar Steve Borho committed 56b42d0

status: catch LookupError and friends from patch.diff()

Try not to barf when file revisions are missing.

Closes #1102

Comments (0)

Files changed (1)

tortoisehg/hgtk/status.py

             opts.git = True
             wctx = self.repo[None]
             pctx1, pctx2 = wctx.parents()
-            difftext = [_('===== Diff to first parent %d:%s =====\n') % (
-                        pctx1.rev(), str(pctx1))]
-            for s in patch.diff(self.repo, pctx1.node(), None, opts=opts):
-                difftext.extend(s.splitlines(True))
-            difftext.append(_('\n===== Diff to second parent %d:%s =====\n') % (
-                            pctx2.rev(), str(pctx2)))
-            for s in patch.diff(self.repo, pctx2.node(), None, opts=opts):
-                difftext.extend(s.splitlines(True))
+            header = _('===== Diff to %s parent %d:%s =====\n')
+            difftext = [header % (_('first'), pctx1.rev(), str(pctx1))]
+            try:
+                for s in patch.diff(self.repo, pctx1.node(), None, opts=opts):
+                    difftext.extend(s.splitlines(True))
+                difftext.append('\n')
+                difftext.append(header % (_('second'), pctx2.rev(), str(pctx2)))
+                for s in patch.diff(self.repo, pctx2.node(), None, opts=opts):
+                    difftext.extend(s.splitlines(True))
+            except (IOError, error.RepoError, error.LookupError, util.Abort), e:
+                self.stbar.set_text(str(e))
         else:
             buf = cStringIO.StringIO()
             for row in self.filemodel:
         opts = patch.diffopts(self.ui, self.opts)
         opts.git = True
         difftext = []
+        header = _('===== Diff to %s parent %d:%s =====\n') 
         if self.is_merge():
             wctx = self.repo[None]
             pctx1, pctx2 = wctx.parents()
-            difftext = [_('===== Diff to first parent %d:%s =====\n') % (
-                        pctx1.rev(), str(pctx1))]
-            for s in patch.diff(self.repo, pctx1.node(), None,
-                                match=matcher, opts=opts):
-                difftext.extend(s.splitlines(True))
-            difftext.append(_('\n===== Diff to second parent %d:%s =====\n') % (
-                            pctx2.rev(), str(pctx2)))
-            for s in patch.diff(self.repo, pctx2.node(), None,
-                                match=matcher, opts=opts):
-                difftext.extend(s.splitlines(True))
+            difftext = [header % (_('first'), pctx1.rev(), str(pctx1))]
+            try:
+                for s in patch.diff(self.repo, pctx1.node(), None,
+                                    match=matcher, opts=opts):
+                    difftext.extend(s.splitlines(True))
+                difftext.append('\n')
+                difftext.append(header % (_('second'), pctx2.rev(), str(pctx2)))
+                for s in patch.diff(self.repo, pctx2.node(), None,
+                                    match=matcher, opts=opts):
+                    difftext.extend(s.splitlines(True))
+            except (IOError, error.RepoError, error.LookupError, util.Abort), e:
+                self.stbar.set_text(str(e))
         else:
-            for s in patch.diff(self.repo, self._node1, self._node2,
-                    match=matcher, opts=opts):
-                difftext.extend(s.splitlines(True))
+            try:
+                for s in patch.diff(self.repo, self._node1, self._node2,
+                        match=matcher, opts=opts):
+                    difftext.extend(s.splitlines(True))
+            except (IOError, error.RepoError, error.LookupError, util.Abort), e:
+                self.stbar.set_text(str(e))
         return self.diff_highlight_buffer(difftext)
 
 
         else:
             matcher = cmdutil.matchfiles(self.repo, [pfile])
             diffopts = mdiff.diffopts(git=True, nodates=True)
-            for s in patch.diff(self.repo, self._node1, self._node2,
-                    match=matcher, opts=diffopts):
-                difftext.writelines(s.splitlines(True))
+            try:
+                for s in patch.diff(self.repo, self._node1, self._node2,
+                        match=matcher, opts=diffopts):
+                    difftext.writelines(s.splitlines(True))
+            except (IOError, error.RepoError, error.LookupError, util.Abort), e:
+                self.stbar.set_text(str(e))
             difftext.seek(0)
         return hgshelve.parsepatch(difftext)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.