[qt] always select the working directory at startup (closes #82231)

If working directory is clean, it's parent is selected (if the checked out revision is nullrev, we fallback on the first available changeset.)

Note: Merge are never clean, choosing first parent is safe.

authorPierre-Yves David <pierre-yves.david@logilab.fr>
changesetfb5ee4cf21dd
branchdefault
phasepublic
hiddenno
parent revision#2d2912f9a121 [qt4] do **not** display closed branches if not asked for
child revision#df0bd07d63bc [tui] enable "reselect currently visited rev and file on reload" (closes #93653)
files modified by this revision
hgviewlib/curses/hgrepoviewer.py
hgviewlib/qt4/hgrepoviewer.py
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1338821145 -7200
# Mon Jun 04 16:45:45 2012 +0200
# Node ID fb5ee4cf21dd7180aef991858bf2919e19781d9b
# Parent 2d2912f9a1215c4652f6c157230e1c710e9d4044
[qt] always select the working directory at startup (closes #82231)


If working directory is clean, it's parent is selected
(if the checked out revision is nullrev, we fallback on the first
available changeset.)

Note: Merge are never clean, choosing first parent is safe.

diff --git a/hgviewlib/curses/hgrepoviewer.py b/hgviewlib/curses/hgrepoviewer.py
@@ -48,10 +48,16 @@
1          body = ScrollableListBox(self.graphlog_walker)
2          super(GraphlogViewer, self).__init__(body=body, *args, **kwargs)
3          self.title = walker.repo.root
4          signals.connect_signal(self.graphlog_walker, 'focus changed',
5                                 self.update_title)
6 +        wc = walker.repo[None]
7 +        rev = None
8 +        if not wc.dirty() and wc.p1().rev() >= 0:
9 +            # parent of working directory is not nullrev
10 +            rev = wc.p1().rev()
11 +        self.graphlog_walker.rev = rev
12 
13      def update_title(self, ctx):
14          """update title depending on the given context ``ctx``."""
15          if ctx.node() is None:
16              hex_ = 'WORKING DIRECTORY'
diff --git a/hgviewlib/qt4/hgrepoviewer.py b/hgviewlib/qt4/hgrepoviewer.py
@@ -419,11 +419,16 @@
17                  self.tableView_filelist.selectFile(self._reload_file)
18                  self._reload_file = None
19                  return
20              except IndexError:
21                  pass
22 -        tv.setCurrentIndex(tv.model().index(0, 0))
23 +        wc = self.repo[None]
24 +        idx = tv.model().index(0, 0) # Working directory or tip
25 +        if not wc.dirty() and wc.p1().rev() >= 0:
26 +            # parent of working directory is not nullrev
27 +            idx = tv.model().indexFromRev(wc.p1().rev())
28 +        tv.setCurrentIndex(idx)
29 
30      def revision_activated(self, rev=None):
31          """
32          Callback called when a revision is double-clicked in the revisions table
33          """