eric6/Plugins/VcsPlugins/vcsMercurial/ShelveExtension/shelve.py

branch
maintenance
changeset 8043
0acf98cd089a
parent 7924
8a96736d465e
parent 8036
74b6a7be4f83
child 8176
31965986ecd1
equal deleted inserted replaced
7991:866adc8c315b 8043:0acf98cd089a
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the shelve extension interface. 7 Module implementing the shelve extension interface.
8 """ 8 """
9
10 import os
11 9
12 from PyQt5.QtWidgets import QDialog 10 from PyQt5.QtWidgets import QDialog
13 11
14 from E5Gui import E5MessageBox 12 from E5Gui import E5MessageBox
15 13
38 Public method used to shutdown the shelve interface. 36 Public method used to shutdown the shelve interface.
39 """ 37 """
40 if self.__shelveBrowserDialog is not None: 38 if self.__shelveBrowserDialog is not None:
41 self.__shelveBrowserDialog.close() 39 self.__shelveBrowserDialog.close()
42 40
43 def __hgGetShelveNamesList(self, repodir): 41 def __hgGetShelveNamesList(self):
44 """ 42 """
45 Private method to get the list of shelved changes. 43 Private method to get the list of shelved changes.
46 44
47 @param repodir directory name of the repository (string)
48 @return list of shelved changes (list of string) 45 @return list of shelved changes (list of string)
49 """ 46 """
50 args = self.vcs.initCommand("shelve") 47 args = self.vcs.initCommand("shelve")
51 args.append('--list') 48 args.append('--list')
52 args.append('--quiet') 49 args.append('--quiet')
66 63
67 @param name directory or file name (string) or list of directory 64 @param name directory or file name (string) or list of directory
68 or file names (list of string) 65 or file names (list of string)
69 @return flag indicating that the project should be reread (boolean) 66 @return flag indicating that the project should be reread (boolean)
70 """ 67 """
71 if isinstance(name, list):
72 dname = self.vcs.splitPathList(name)[0]
73 else:
74 dname = self.vcs.splitPath(name)[0]
75
76 # find the root of the repo
77 repodir = dname
78 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
79 repodir = os.path.dirname(repodir)
80 if os.path.splitdrive(repodir)[1] == os.sep:
81 return False
82
83 res = False 68 res = False
84 from .HgShelveDataDialog import HgShelveDataDialog 69 from .HgShelveDataDialog import HgShelveDataDialog
85 dlg = HgShelveDataDialog(self.vcs.version) 70 dlg = HgShelveDataDialog(self.vcs.version)
86 if dlg.exec() == QDialog.Accepted: 71 if dlg.exec() == QDialog.Accepted:
87 shelveName, dateTime, message, addRemove, keep = dlg.getData() 72 shelveName, dateTime, message, addRemove, keep = dlg.getData()
92 args.append(shelveName) 77 args.append(shelveName)
93 if message: 78 if message:
94 args.append("--message") 79 args.append("--message")
95 args.append(message) 80 args.append(message)
96 if addRemove: 81 if addRemove:
97 args.append("--addRemove") 82 args.append("--addremove")
98 if dateTime.isValid(): 83 if dateTime.isValid():
99 args.append("--date") 84 args.append("--date")
100 args.append(dateTime.toString("yyyy-MM-dd hh:mm:ss")) 85 args.append(dateTime.toString("yyyy-MM-dd hh:mm:ss"))
101 if self.vcs.version >= (5, 0, 0) and keep: 86 if self.vcs.version >= (5, 0, 0) and keep:
102 args.append("--keep") 87 args.append("--keep")
106 self.vcs.addArguments(args, name) 91 self.vcs.addArguments(args, name)
107 else: 92 else:
108 args.append(name) 93 args.append(name)
109 94
110 dia = HgDialog(self.tr('Shelve current changes'), self.vcs) 95 dia = HgDialog(self.tr('Shelve current changes'), self.vcs)
111 res = dia.startProcess(args, repodir) 96 res = dia.startProcess(args)
112 if res: 97 if res:
113 dia.exec() 98 dia.exec()
114 res = dia.hasAddOrDelete() 99 res = dia.hasAddOrDelete()
115 self.vcs.checkVCSStatus() 100 self.vcs.checkVCSStatus()
116 return res 101 return res
117 102
118 def hgShelveBrowser(self, projectDir): 103 def hgShelveBrowser(self):
119 """ 104 """
120 Public method to show the shelve browser dialog. 105 Public method to show the shelve browser dialog.
121
122 @param projectDir name of the project directory (string)
123 """ 106 """
124 if self.__shelveBrowserDialog is None: 107 if self.__shelveBrowserDialog is None:
125 from .HgShelveBrowserDialog import HgShelveBrowserDialog 108 from .HgShelveBrowserDialog import HgShelveBrowserDialog
126 self.__shelveBrowserDialog = HgShelveBrowserDialog( 109 self.__shelveBrowserDialog = HgShelveBrowserDialog(
127 self.vcs) 110 self.vcs)
128 self.__shelveBrowserDialog.show() 111 self.__shelveBrowserDialog.show()
129 self.__shelveBrowserDialog.start(projectDir) 112 self.__shelveBrowserDialog.start()
130 113
131 def hgUnshelve(self, name, shelveName=""): 114 def hgUnshelve(self, shelveName=""):
132 """ 115 """
133 Public method to restore shelved changes to the project directory. 116 Public method to restore shelved changes to the project directory.
134 117
135 @param name name of the project directory (string) 118 @param shelveName name of the shelve to restore (string)
136 @keyparam shelveName name of the shelve to restore (string) 119 @return flag indicating that the project should be reread (boolean)
137 @return flag indicating that the project should be reread (boolean) 120 """
138 """
139 # find the root of the repo
140 repodir = name
141 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
142 repodir = os.path.dirname(repodir)
143 if os.path.splitdrive(repodir)[1] == os.sep:
144 return False
145
146 res = False 121 res = False
147 from .HgUnshelveDataDialog import HgUnshelveDataDialog 122 from .HgUnshelveDataDialog import HgUnshelveDataDialog
148 dlg = HgUnshelveDataDialog(self.__hgGetShelveNamesList(repodir), 123 dlg = HgUnshelveDataDialog(self.__hgGetShelveNamesList(),
149 shelveName=shelveName) 124 shelveName=shelveName)
150 if dlg.exec() == QDialog.Accepted: 125 if dlg.exec() == QDialog.Accepted:
151 shelveName, keep = dlg.getData() 126 shelveName, keep = dlg.getData()
152 self.__unshelveKeep = keep # store for potential continue 127 self.__unshelveKeep = keep # store for potential continue
153 128
156 args.append("--keep") 131 args.append("--keep")
157 if shelveName: 132 if shelveName:
158 args.append(shelveName) 133 args.append(shelveName)
159 134
160 dia = HgDialog(self.tr('Restore shelved changes'), self.vcs) 135 dia = HgDialog(self.tr('Restore shelved changes'), self.vcs)
161 res = dia.startProcess(args, repodir) 136 res = dia.startProcess(args)
162 if res: 137 if res:
163 dia.exec() 138 dia.exec()
164 res = dia.hasAddOrDelete() 139 res = dia.hasAddOrDelete()
165 self.vcs.checkVCSStatus() 140 self.vcs.checkVCSStatus()
166 return res 141 return res
167 142
168 def hgUnshelveAbort(self, name): 143 def hgUnshelveAbort(self):
169 """ 144 """
170 Public method to abort the ongoing restore operation. 145 Public method to abort the ongoing restore operation.
171 146
172 @param name name of the project directory (string) 147 @return flag indicating that the project should be reread (boolean)
173 @return flag indicating that the project should be reread (boolean) 148 """
174 """
175 # find the root of the repo
176 repodir = name
177 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
178 repodir = os.path.dirname(repodir)
179 if os.path.splitdrive(repodir)[1] == os.sep:
180 return False
181
182 args = self.vcs.initCommand("unshelve") 149 args = self.vcs.initCommand("unshelve")
183 args.append("--abort") 150 args.append("--abort")
184 151
185 dia = HgDialog(self.tr('Abort restore operation'), self.vcs) 152 dia = HgDialog(self.tr('Abort restore operation'), self.vcs)
186 res = dia.startProcess(args, repodir) 153 res = dia.startProcess(args)
187 if res: 154 if res:
188 dia.exec() 155 dia.exec()
189 res = dia.hasAddOrDelete() 156 res = dia.hasAddOrDelete()
190 self.vcs.checkVCSStatus() 157 self.vcs.checkVCSStatus()
191 return res 158 return res
192 159
193 def hgUnshelveContinue(self, name): 160 def hgUnshelveContinue(self):
194 """ 161 """
195 Public method to continue the ongoing restore operation. 162 Public method to continue the ongoing restore operation.
196 163
197 @param name name of the project directory (string) 164 @return flag indicating that the project should be reread (boolean)
198 @return flag indicating that the project should be reread (boolean) 165 """
199 """
200 # find the root of the repo
201 repodir = name
202 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
203 repodir = os.path.dirname(repodir)
204 if os.path.splitdrive(repodir)[1] == os.sep:
205 return False
206
207 args = self.vcs.initCommand("unshelve") 166 args = self.vcs.initCommand("unshelve")
208 if self.__unshelveKeep: 167 if self.__unshelveKeep:
209 args.append("--keep") 168 args.append("--keep")
210 args.append("--continue") 169 args.append("--continue")
211 170
212 dia = HgDialog(self.tr('Continue restore operation'), self.vcs) 171 dia = HgDialog(self.tr('Continue restore operation'), self.vcs)
213 res = dia.startProcess(args, repodir) 172 res = dia.startProcess(args)
214 if res: 173 if res:
215 dia.exec() 174 dia.exec()
216 res = dia.hasAddOrDelete() 175 res = dia.hasAddOrDelete()
217 self.vcs.checkVCSStatus() 176 self.vcs.checkVCSStatus()
218 return res 177 return res
219 178
220 def hgDeleteShelves(self, name, shelveNames=None): 179 def hgDeleteShelves(self, shelveNames=None):
221 """ 180 """
222 Public method to delete named shelves. 181 Public method to delete named shelves.
223 182
224 @param name name of the project directory (string)
225 @param shelveNames name of shelves to delete (list of string) 183 @param shelveNames name of shelves to delete (list of string)
226 """ 184 """
227 # find the root of the repo
228 repodir = name
229 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
230 repodir = os.path.dirname(repodir)
231 if os.path.splitdrive(repodir)[1] == os.sep:
232 return
233
234 if not shelveNames: 185 if not shelveNames:
235 from .HgShelvesSelectionDialog import HgShelvesSelectionDialog 186 from .HgShelvesSelectionDialog import HgShelvesSelectionDialog
236 dlg = HgShelvesSelectionDialog( 187 dlg = HgShelvesSelectionDialog(
237 self.tr("Select the shelves to be deleted:"), 188 self.tr("Select the shelves to be deleted:"),
238 self.__hgGetShelveNamesList(repodir)) 189 self.__hgGetShelveNamesList())
239 if dlg.exec() == QDialog.Accepted: 190 if dlg.exec() == QDialog.Accepted:
240 shelveNames = dlg.getSelectedShelves() 191 shelveNames = dlg.getSelectedShelves()
241 else: 192 else:
242 return 193 return
243 194
253 args = self.vcs.initCommand("shelve") 204 args = self.vcs.initCommand("shelve")
254 args.append("--delete") 205 args.append("--delete")
255 args.extend(shelveNames) 206 args.extend(shelveNames)
256 207
257 dia = HgDialog(self.tr('Delete shelves'), self.vcs) 208 dia = HgDialog(self.tr('Delete shelves'), self.vcs)
258 res = dia.startProcess(args, repodir) 209 res = dia.startProcess(args)
259 if res: 210 if res:
260 dia.exec() 211 dia.exec()
261 212
262 def hgCleanupShelves(self, name): 213 def hgCleanupShelves(self):
263 """ 214 """
264 Public method to delete all shelves. 215 Public method to delete all shelves.
265 216 """
266 @param name name of the project directory (string)
267 """
268 # find the root of the repo
269 repodir = name
270 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
271 repodir = os.path.dirname(repodir)
272 if os.path.splitdrive(repodir)[1] == os.sep:
273 return
274
275 res = E5MessageBox.yesNo( 217 res = E5MessageBox.yesNo(
276 None, 218 None,
277 self.tr("Delete all shelves"), 219 self.tr("Delete all shelves"),
278 self.tr("""Do you really want to delete all shelved changes?""")) 220 self.tr("""Do you really want to delete all shelved changes?"""))
279 if res: 221 if res:
280 args = self.vcs.initCommand("shelve") 222 args = self.vcs.initCommand("shelve")
281 args.append("--cleanup") 223 args.append("--cleanup")
282 224
283 dia = HgDialog(self.tr('Delete all shelves'), self.vcs) 225 dia = HgDialog(self.tr('Delete all shelves'), self.vcs)
284 res = dia.startProcess(args, repodir) 226 res = dia.startProcess(args)
285 if res: 227 if res:
286 dia.exec() 228 dia.exec()

eric ide

mercurial