Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/bookmarks.py

changeset 3302
e92f0dd51979
parent 3190
a9a94491c4fd
child 3484
645c12de6b0c
equal deleted inserted replaced
3300:734353e7d679 3302:e92f0dd51979
12 from PyQt4.QtCore import QProcess 12 from PyQt4.QtCore import QProcess
13 from PyQt4.QtGui import QDialog, QInputDialog 13 from PyQt4.QtGui import QDialog, QInputDialog
14 14
15 from ..HgExtension import HgExtension 15 from ..HgExtension import HgExtension
16 from ..HgDialog import HgDialog 16 from ..HgDialog import HgDialog
17
18 import Preferences
19 17
20 18
21 class Bookmarks(HgExtension): 19 class Bookmarks(HgExtension):
22 """ 20 """
23 Class implementing the bookmarks extension interface. 21 Class implementing the bookmarks extension interface.
61 Public method to get the list of bookmarks. 59 Public method to get the list of bookmarks.
62 60
63 @param repodir directory name of the repository (string) 61 @param repodir directory name of the repository (string)
64 @return list of bookmarks (list of string) 62 @return list of bookmarks (list of string)
65 """ 63 """
66 args = [] 64 args = self.vcs.initCommand("bookmarks")
67 args.append('bookmarks')
68 65
69 client = self.vcs.getClient() 66 client = self.vcs.getClient()
70 output = "" 67 output = ""
71 if client: 68 if client:
72 output = client.runcommand(args)[0] 69 output = client.runcommand(args)[0]
73 else: 70 else:
74 ioEncoding = Preferences.getSystem("IOEncoding")
75 process = QProcess() 71 process = QProcess()
76 process.setWorkingDirectory(repodir) 72 process.setWorkingDirectory(repodir)
77 process.start('hg', args) 73 process.start('hg', args)
78 procStarted = process.waitForStarted(5000) 74 procStarted = process.waitForStarted(5000)
79 if procStarted: 75 if procStarted:
80 finished = process.waitForFinished(30000) 76 finished = process.waitForFinished(30000)
81 if finished and process.exitCode() == 0: 77 if finished and process.exitCode() == 0:
82 output = str( 78 output = str(process.readAllStandardOutput(),
83 process.readAllStandardOutput(), ioEncoding, 79 self.vcs.getEncoding(), 'replace')
84 'replace')
85 80
86 self.bookmarksList = [] 81 self.bookmarksList = []
87 for line in output.splitlines(): 82 for line in output.splitlines():
88 li = line.strip().split() 83 li = line.strip().split()
89 if li[-1][0] in "1234567890": 84 if li[-1][0] in "1234567890":
115 self.vcs.hgGetBranchesList(repodir), 110 self.vcs.hgGetBranchesList(repodir),
116 self.hgGetBookmarksList(repodir)) 111 self.hgGetBookmarksList(repodir))
117 if dlg.exec_() == QDialog.Accepted: 112 if dlg.exec_() == QDialog.Accepted:
118 rev, bookmark = dlg.getData() 113 rev, bookmark = dlg.getData()
119 114
120 args = [] 115 args = self.vcs.initCommand("bookmarks")
121 args.append("bookmarks")
122 if rev: 116 if rev:
123 args.append("--rev") 117 args.append("--rev")
124 args.append(rev) 118 args.append(rev)
125 args.append(bookmark) 119 args.append(bookmark)
126 120
147 self.tr("Delete Bookmark"), 141 self.tr("Delete Bookmark"),
148 self.tr("Select the bookmark to be deleted:"), 142 self.tr("Select the bookmark to be deleted:"),
149 [""] + sorted(self.hgGetBookmarksList(repodir)), 143 [""] + sorted(self.hgGetBookmarksList(repodir)),
150 0, True) 144 0, True)
151 if ok and bookmark: 145 if ok and bookmark:
152 args = [] 146 args = self.vcs.initCommand("bookmarks")
153 args.append("bookmarks")
154 args.append("--delete") 147 args.append("--delete")
155 args.append(bookmark) 148 args.append(bookmark)
156 149
157 dia = HgDialog(self.tr('Delete Mercurial Bookmark'), self.vcs) 150 dia = HgDialog(self.tr('Delete Mercurial Bookmark'), self.vcs)
158 res = dia.startProcess(args, repodir) 151 res = dia.startProcess(args, repodir)
175 from .HgBookmarkRenameDialog import HgBookmarkRenameDialog 168 from .HgBookmarkRenameDialog import HgBookmarkRenameDialog
176 dlg = HgBookmarkRenameDialog(self.hgGetBookmarksList(repodir)) 169 dlg = HgBookmarkRenameDialog(self.hgGetBookmarksList(repodir))
177 if dlg.exec_() == QDialog.Accepted: 170 if dlg.exec_() == QDialog.Accepted:
178 newName, oldName = dlg.getData() 171 newName, oldName = dlg.getData()
179 172
180 args = [] 173 args = self.vcs.initCommand("bookmarks")
181 args.append("bookmarks")
182 args.append("--rename") 174 args.append("--rename")
183 args.append(oldName) 175 args.append(oldName)
184 args.append(newName) 176 args.append(newName)
185 177
186 dia = HgDialog(self.tr('Rename Mercurial Bookmark'), self.vcs) 178 dia = HgDialog(self.tr('Rename Mercurial Bookmark'), self.vcs)
207 self.vcs.hgGetBranchesList(repodir), 199 self.vcs.hgGetBranchesList(repodir),
208 self.hgGetBookmarksList(repodir)) 200 self.hgGetBookmarksList(repodir))
209 if dlg.exec_() == QDialog.Accepted: 201 if dlg.exec_() == QDialog.Accepted:
210 rev, bookmark = dlg.getData() 202 rev, bookmark = dlg.getData()
211 203
212 args = [] 204 args = self.vcs.initCommand("bookmarks")
213 args.append("bookmarks")
214 args.append("--force") 205 args.append("--force")
215 if rev: 206 if rev:
216 args.append("--rev") 207 args.append("--rev")
217 args.append(rev) 208 args.append(rev)
218 args.append(bookmark) 209 args.append(bookmark)
254 @param incoming flag indicating to get incoming bookmarks (boolean) 245 @param incoming flag indicating to get incoming bookmarks (boolean)
255 @return list of bookmarks (list of string) 246 @return list of bookmarks (list of string)
256 """ 247 """
257 bookmarksList = [] 248 bookmarksList = []
258 249
259 args = []
260 if incoming: 250 if incoming:
261 args.append('incoming') 251 args = self.vcs.initCommand("incoming")
262 else: 252 else:
263 args.append('outgoing') 253 args = self.vcs.initCommand("outgoing")
264 args.append('--bookmarks') 254 args.append('--bookmarks')
265 255
266 client = self.vcs.getClient() 256 client = self.vcs.getClient()
267 output = "" 257 output = ""
268 if client: 258 if client:
269 output = client.runcommand(args)[0] 259 output = client.runcommand(args)[0]
270 else: 260 else:
271 ioEncoding = Preferences.getSystem("IOEncoding")
272 process = QProcess() 261 process = QProcess()
273 process.setWorkingDirectory(repodir) 262 process.setWorkingDirectory(repodir)
274 process.start('hg', args) 263 process.start('hg', args)
275 procStarted = process.waitForStarted(5000) 264 procStarted = process.waitForStarted(5000)
276 if procStarted: 265 if procStarted:
277 finished = process.waitForFinished(30000) 266 finished = process.waitForFinished(30000)
278 if finished and process.exitCode() == 0: 267 if finished and process.exitCode() == 0:
279 output = str( 268 output = str(process.readAllStandardOutput(),
280 process.readAllStandardOutput(), ioEncoding, 269 self.vcs.getEncoding(), 'replace')
281 'replace')
282 270
283 for line in output.splitlines(): 271 for line in output.splitlines():
284 if line.startswith(" "): 272 if line.startswith(" "):
285 li = line.strip().split() 273 li = line.strip().split()
286 del li[-1] 274 del li[-1]
309 self.tr("Pull Bookmark"), 297 self.tr("Pull Bookmark"),
310 self.tr("Select the bookmark to be pulled:"), 298 self.tr("Select the bookmark to be pulled:"),
311 [""] + sorted(bookmarks), 299 [""] + sorted(bookmarks),
312 0, True) 300 0, True)
313 if ok and bookmark: 301 if ok and bookmark:
314 args = [] 302 args = self.vcs.initCommand("pull")
315 args.append('pull')
316 args.append('--bookmark') 303 args.append('--bookmark')
317 args.append(bookmark) 304 args.append(bookmark)
318 305
319 dia = HgDialog(self.tr( 306 dia = HgDialog(self.tr(
320 'Pulling bookmark from a remote Mercurial repository'), 307 'Pulling bookmark from a remote Mercurial repository'),
343 self.tr("Push Bookmark"), 330 self.tr("Push Bookmark"),
344 self.tr("Select the bookmark to be push:"), 331 self.tr("Select the bookmark to be push:"),
345 [""] + sorted(bookmarks), 332 [""] + sorted(bookmarks),
346 0, True) 333 0, True)
347 if ok and bookmark: 334 if ok and bookmark:
348 args = [] 335 args = self.vcs.initCommand("push")
349 args.append('push')
350 args.append('--bookmark') 336 args.append('--bookmark')
351 args.append(bookmark) 337 args.append(bookmark)
352 338
353 dia = HgDialog(self.tr( 339 dia = HgDialog(self.tr(
354 'Pushing bookmark to a remote Mercurial repository'), 340 'Pushing bookmark to a remote Mercurial repository'),

eric ide

mercurial