Don't crash/close when exploring an empty repository (closes #20996)

authorThibaut Girka <thib@sitedethib.com>
changesete0ad6f151b89
branchdefault
phasepublic
hiddenno
parent revision#34da9dee4e91 Remove mx.Datetime dependency (close #73687)
child revision#83e1f6d0ffa3 Propagate errors from mercurial.hg.repository() (closes: #73678)
files modified by this revision
hgviewlib/qt4/hgrepomodel.py
hgviewlib/qt4/hgrepoviewer.py
# HG changeset patch
# User Thibaut Girka <thib@sitedethib.com>
# Date 1313591288 -7200
# Wed Aug 17 16:28:08 2011 +0200
# Node ID e0ad6f151b891164f47daf0abe087fb530ed1378
# Parent 34da9dee4e91515cd0898c49e10b9cff072f5f0d
Don't crash/close when exploring an empty repository (closes #20996)

diff --git a/hgviewlib/qt4/hgrepomodel.py b/hgviewlib/qt4/hgrepomodel.py
@@ -106,11 +106,12 @@
1  _maxwidth = {'ID': lambda self, r: str(len(r.changelog)),
2               'Date': lambda self, r: cvrt_date(r.changectx(0).date()),
3               'Tags': lambda self, r: sorted(r.tags().keys(),
4                                              key=lambda x: len(x))[-1][:10],
5               'Branch': lambda self, r: sorted(r.branchtags().keys(),
6 -                                              key=lambda x: len(x))[-1],
7 +                                              key=lambda x: len(x))[-1]
8 +                                              if r.branchtags().keys() else None,
9               'Author': lambda self, r: 'author name',
10               'Filename': lambda self, r: self.filename,
11               }
12 
13  def datacached(meth):
diff --git a/hgviewlib/qt4/hgrepoviewer.py b/hgviewlib/qt4/hgrepoviewer.py
@@ -456,15 +456,16 @@
14              # filling is still running)
15              self._reload_rev = rev
16 
17      def _getrepomtime(self):
18          """Return the last modification time for the repo"""
19 -        watchedfiles = [(self.repo.root, ".hg", "store", "00changelog.i"),
20 +        watchedfiles = [(self.repo.root, ".hg", "store"),
21 +                        (self.repo.root, ".hg", "store", "00changelog.i"),
22                          (self.repo.root, ".hg", "dirstate")]
23          watchedfiles = [os.path.join(*wf) for wf in watchedfiles]
24          mtime = [os.path.getmtime(wf) for wf in watchedfiles \
25 -                 if os.path.isfile(wf)]
26 +                 if os.path.exists(wf)]
27          if mtime:
28              return max(mtime)
29          # humm, directory has probably been deleted, exiting...
30          self.close()
31