Plugins/VcsPlugins/vcsMercurial/RebaseExtension/rebase.py

changeset 1093
47bc4ef30315
child 1249
77f836a883c1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/VcsPlugins/vcsMercurial/RebaseExtension/rebase.py	Tue May 31 16:35:45 2011 +0200
@@ -0,0 +1,140 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the rebase extension interface.
+"""
+
+import os
+
+from PyQt4.QtGui import QDialog
+
+from ..HgExtension import HgExtension
+from ..HgDialog import HgDialog
+
+from .HgRebaseDialog import HgRebaseDialog
+
+
+class Rebase(HgExtension):
+    """
+    Class implementing the rebase extension interface.
+    """
+    def __init__(self, vcs):
+        """
+        Constructor
+        
+        @param vcs reference to the Mercurial vcs object
+        """
+        super().__init__(vcs)
+    
+    def hgRebase(self, path):
+        """
+        Public method to rebase changesets to a different branch.
+        
+        @param path directory name of the project (string)
+        @return flag indicating that the project should be reread (boolean)
+        """
+        # find the root of the repo
+        repodir = self.vcs.splitPath(path)[0]
+        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
+            repodir = os.path.dirname(repodir)
+            if repodir == os.sep:
+                return False
+        
+        res = False
+        if self.vcs.isExtensionActive("bookmarks"):
+            bookmarksList = \
+                self.vcs.getExtensionObject("bookmarks").hgGetBookmarksList(repodir)
+        else:
+            bookmarksList = None
+        dlg = HgRebaseDialog(self.vcs.hgGetTagsList(repodir),
+                             self.vcs.hgGetBranchesList(repodir),
+                             bookmarksList)
+        if dlg.exec_() == QDialog.Accepted:
+            indicator, sourceRev, destRev, collapse, keep, keepBranches, detach = \
+                dlg.getData()
+            
+            args = []
+            args.append("rebase")
+            if indicator == "S":
+                args.append("--source")
+                args.append(sourceRev)
+            elif indicator == "B":
+                args.append("--base")
+                args.append(sourceRev)
+            if destRev:
+                args.append("--dest")
+                args.append(destRev)
+            if collapse:
+                args.append("--collapse")
+            if keep:
+                args.append("--keep")
+            if keepBranches:
+                args.append("--keepbranches")
+            if detach:
+                args.append("--detach")
+            args.append("--verbose")
+            
+            dia = HgDialog(self.trUtf8('Rebase Changesets'))
+            res = dia.startProcess(args, repodir)
+            if res:
+                dia.exec_()
+                res = dia.hasAddOrDelete()
+                self.vcs.checkVCSStatus()
+        return res
+    
+    def hgRebaseContinue(self, path):
+        """
+        Public method to continue rebasing changesets from another branch.
+        
+        @param path directory name of the project (string)
+        @return flag indicating that the project should be reread (boolean)
+        """
+        # find the root of the repo
+        repodir = self.vcs.splitPath(path)[0]
+        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
+            repodir = os.path.dirname(repodir)
+            if repodir == os.sep:
+                return False
+        
+        args = []
+        args.append("rebase")
+        args.append("--continue")
+        args.append("--verbose")
+        
+        dia = HgDialog(self.trUtf8('Rebase Changesets (Continue)'))
+        res = dia.startProcess(args, repodir)
+        if res:
+            dia.exec_()
+            res = dia.hasAddOrDelete()
+            self.vcs.checkVCSStatus()
+        return res
+    
+    def hgRebaseAbort(self, path):
+        """
+        Public method to abort rebasing changesets from another branch.
+        
+        @param path directory name of the project (string)
+        @return flag indicating that the project should be reread (boolean)
+        """
+        # find the root of the repo
+        repodir = self.vcs.splitPath(path)[0]
+        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
+            repodir = os.path.dirname(repodir)
+            if repodir == os.sep:
+                return False
+        
+        args = []
+        args.append("rebase")
+        args.append("--abort")
+        args.append("--verbose")
+        
+        dia = HgDialog(self.trUtf8('Rebase Changesets (Abort)'))
+        res = dia.startProcess(args, repodir)
+        if res:
+            dia.exec_()
+            res = dia.hasAddOrDelete()
+            self.vcs.checkVCSStatus()
+        return res

eric ide

mercurial