Plugins/VcsPlugins/vcsMercurial/HisteditExtension/histedit.py

changeset 5283
06423d65a2b8
child 5291
e93d14b48c34
equal deleted inserted replaced
5282:898b0dda21e1 5283:06423d65a2b8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the histedit extension interface.
8 """
9
10 from __future__ import unicode_literals
11
12 import os
13 import sys
14
15 from PyQt5.QtWidgets import QDialog
16
17 from ..HgExtension import HgExtension
18 from ..HgDialog import HgDialog
19
20
21 class Histedit(HgExtension):
22 """
23 Class implementing the histedit extension interface.
24 """
25 def __init__(self, vcs):
26 """
27 Constructor
28
29 @param vcs reference to the Mercurial vcs object
30 @type Hg
31 """
32 super(Histedit, self).__init__(vcs)
33
34 def hgHisteditStart(self, name, rev=""):
35 """
36 Public method to start a histedit session.
37
38 @param name file/directory name
39 @type str
40 @keyparam rev revision to start histedit at
41 @type str
42 @return flag indicating that the project should be reread
43 @rtype bool
44 """
45 # find the root of the repo
46 repodir = self.vcs.splitPath(name)[0]
47 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
48 repodir = os.path.dirname(repodir)
49 if os.path.splitdrive(repodir)[1] == os.sep:
50 return False
51
52 from .HgHisteditConfigDialog import HgHisteditConfigDialog
53 res = False
54 dlg = HgHisteditConfigDialog(self.vcs.hgGetTagsList(repodir),
55 self.vcs.hgGetBranchesList(repodir),
56 self.vcs.hgGetBookmarksList(repodir),
57 rev)
58 if dlg.exec_() == QDialog.Accepted:
59 rev, force, keep = dlg.getData()
60
61 args = self.vcs.initCommand("histedit")
62 args.append("-v")
63 if keep:
64 args.append("--keep")
65 if rev:
66 if rev == "--outgoing":
67 if force:
68 args.append("--force")
69 else:
70 args.append("--rev")
71 args.append(rev)
72
73 editor = os.path.join(
74 os.path.dirname(__file__), "HgHisteditEditor.py")
75 env = {"HGEDITOR": "{0} {1}".format(sys.executable, editor)}
76
77 dia = HgDialog(
78 self.tr("Starting histedit session"),
79 self.vcs,
80 useClient=False)
81 res = dia.startProcess(args, repodir, environment=env)
82 if res:
83 dia.exec_()
84 res = dia.hasAddOrDelete()
85 self.vcs.checkVCSStatus()
86 return res
87
88 def hgHisteditContinue(self, name):
89 """
90 Public method to continue an interrupted histedit session.
91
92 @param name file/directory name
93 @type str
94 @return flag indicating that the project should be reread
95 @rtype bool
96 """
97 # find the root of the repo
98 repodir = self.vcs.splitPath(name)[0]
99 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
100 repodir = os.path.dirname(repodir)
101 if os.path.splitdrive(repodir)[1] == os.sep:
102 return False
103
104 args = self.vcs.initCommand("histedit")
105 args.append("--continue")
106 args.append("-v")
107
108 editor = os.path.join(
109 os.path.dirname(__file__), "HgHisteditEditor.py")
110 env = {"HGEDITOR": "{0} {1}".format(sys.executable, editor)}
111
112 dia = HgDialog(
113 self.tr("Continue histedit session"),
114 self.vcs,
115 useClient=False)
116 res = dia.startProcess(args, repodir, environment=env)
117 if res:
118 dia.exec_()
119 res = dia.hasAddOrDelete()
120 self.vcs.checkVCSStatus()
121 return res
122
123 def hgHisteditAbort(self, name):
124 """
125 Public method to abort an interrupted histedit session.
126
127 @param name file/directory name
128 @type str
129 @return flag indicating that the project should be reread
130 @rtype bool
131 """
132 # find the root of the repo
133 repodir = self.vcs.splitPath(name)[0]
134 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
135 repodir = os.path.dirname(repodir)
136 if os.path.splitdrive(repodir)[1] == os.sep:
137 return False
138
139 args = self.vcs.initCommand("histedit")
140 args.append("--abort")
141 args.append("-v")
142
143 editor = os.path.join(
144 os.path.dirname(__file__), "HgHisteditEditor.py")
145 env = {"HGEDITOR": "{0} {1}".format(sys.executable, editor)}
146
147 dia = HgDialog(
148 self.tr("Abort histedit session"),
149 self.vcs,
150 useClient=False)
151 res = dia.startProcess(args, repodir, environment=env)
152 if res:
153 dia.exec_()
154 res = dia.hasAddOrDelete()
155 self.vcs.checkVCSStatus()
156 return res
157
158 def hgHisteditEditPlan(self, name):
159 """
160 Public method to edit the remaining actions list of an interrupted
161 histedit session.
162
163 @param name file/directory name
164 @type str
165 @return flag indicating that the project should be reread
166 @rtype bool
167 """
168 # find the root of the repo
169 repodir = self.vcs.splitPath(name)[0]
170 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
171 repodir = os.path.dirname(repodir)
172 if os.path.splitdrive(repodir)[1] == os.sep:
173 return False
174
175 args = self.vcs.initCommand("histedit")
176 args.append("--edit-plan")
177 args.append("-v")
178
179 editor = os.path.join(
180 os.path.dirname(__file__), "HgHisteditEditor.py")
181 env = {"HGEDITOR": "{0} {1}".format(sys.executable, editor)}
182
183 dia = HgDialog(
184 self.tr("Edit Plan"),
185 self.vcs,
186 useClient=False)
187 res = dia.startProcess(args, repodir, environment=env)
188 if res:
189 dia.exec_()
190 res = dia.hasAddOrDelete()
191 self.vcs.checkVCSStatus()
192 return res

eric ide

mercurial