Steve Borho avatar Steve Borho committed 0ff2308

status: detect MQ mode at refresh, make shelve aware of qdiffs

fixes #106. Cleaned up the refresh function while I was at it.

Comments (0)

Files changed (3)

 
     def init(self):
         GStatus.init(self)
+        self.mode = 'commit'
         self._last_commit_id = None
 
     def parse_opts(self):
         '''See if an MQ patch is applied, switch to qrefresh mode'''
         self.qheader = None
         if not hasattr(self.repo, 'mq'): return
-        if not self.repo.mq.applied: return
+        if not self.repo.mq.applied:
+            self.get_toolbutton('_Commit').set_label('_Commit')
+            return
         patch = self.repo.mq.lookup('qtip')
         ph = self.repo.mq.readheaders(patch)
         title = os.path.basename(self.repo.root) + ' qrefresh ' + patch
 import pango
 
 from mercurial.i18n import _
-from mercurial import cmdutil, util, ui, hg, commands, patch, mdiff
+from mercurial import cmdutil, util, ui, hg, commands, patch, mdiff, extensions
 from mercurial import merge as merge_
 from shlib import shell_notify
 from hglib import toutf, fromutf, rootpath, diffexpand
 
     def init(self):
         GDialog.init(self)
+        self.mode = 'status'
         
     def auto_check(self):
         if self.test_opt('check'):
         if revs:
             r = ':'.join(revs)
             return ' '.join([root, 'status', r]) + ' '.join(self.pats)
-        elif self.mqmode and hasattr(self, 'text'):
+        elif self.mqmode and self.mode != 'status':
             patch = self.repo.mq.lookup('qtip')
             return root + ' applied MQ patch ' + patch
         else:
     ### End of overrides ###
 
     def _do_reload_status(self):
-        """Clear out the existing ListStore model and reload it from the repository status. 
-        Also recheck and reselect files that remain in the list.
+        """Clear out the existing ListStore model and reload it from the
+        repository status.  Also recheck and reselect files that remain
+        in the list.
         """
-        self.repo.dirstate.invalidate()
-        self.repo.invalidate()
+        repo = self.repo
+        # TODO - SJB - just realloc the repository here
+        repo.dirstate.invalidate()
+        repo.invalidate()
+        if hasattr(repo, 'mq'):
+            mq = extensions.find('mq')
+            repo.mq = mq.queue(repo.ui, repo.join(""))
+            self.mqmode = repo.mq.applied
+            self.set_title(self.get_title())
 
-        # The following code was copied from the status function in
-        # mercurial\commands.py and modified slightly to work here
-        
-        if self.mqmode and not self.opts.get('rev') and hasattr(self, 'text'):
+        if self.mqmode and self.mode != 'status':
             # when a patch is applied, show diffs to parent of top patch
-            self._node1 = self.repo.lookup(-3)
-            self._node2 = None
+            n1, n2 = repo.lookup(-3), None
         else:
             # node2 is None (the working dir) when 0 or 1 rev is specificed
-            self._node1, self._node2 = cmdutil.revpair(self.repo, self.opts.get('rev'))
+            n1, n2 = cmdutil.revpair(repo, self.opts.get('rev'))
 
-        matcher = cmdutil.match(self.repo, self.pats, self.opts)
-        status = [n for n in self.repo.status(node1=self._node1, node2=self._node2,
-                                 match=matcher,
-                                 ignored=self.test_opt('ignored'),
-                                 clean=self.test_opt('clean'),
-                                 unknown=self.test_opt('unknown'))]
+        matcher = cmdutil.match(repo, self.pats, self.opts)
+        status = repo.status(node1=n1, node2=n2, match=matcher,
+                             ignored=self.test_opt('ignored'),
+                             clean=self.test_opt('clean'),
+                             unknown=self.test_opt('unknown'))
 
         (modified, added, removed, deleted, unknown, ignored, clean) = status
-        self.modified = modified
+        self._node1, self._node2, self.modified = n1, n2, modified
 
         changetypes = (('modified', 'M', modified),
                        ('added', 'A', added),
         reselect = [model[path][FM_PATH] for path in paths]
 
         # merge-state of files
-        ms = merge_.mergestate(self.repo)
+        ms = merge_.mergestate(repo)
         
         # Load the new data into the tree's model
         self.filetree.hide()
         self._show_diff_hunks(files)
 
         self.filetree.show()
-        if hasattr(self, 'text'):
+        if self.mode == 'commit':
             self.text.grab_focus()
         else:
             self.filetree.grab_focus()

hggtk/thgshelve.py

 
     def init(self):
         GStatus.init(self)
+        self.mode = 'shelve'
 
     def parse_opts(self):
         GStatus.parse_opts(self)
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.