eric6/Plugins/VcsPlugins/vcsMercurial/StripExtension/strip.py

Wed, 01 Jan 2020 11:57:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 01 Jan 2020 11:57:23 +0100
changeset 7360
9190402e4505
parent 7229
53054eb5b15a
child 7759
51aa6c6b66f7
permissions
-rw-r--r--

Updated copyright for 2020.

5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
3 # Copyright (c) 2016 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the strip extension interface.
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import os
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt5.QtWidgets import QDialog
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from ..HgExtension import HgExtension
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from ..HgDialog import HgDialog
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 class Strip(HgExtension):
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Class implementing the strip extension interface.
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 def __init__(self, vcs):
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Constructor
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @param vcs reference to the Mercurial vcs object
5270
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
28 @type Hg
5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 super(Strip, self).__init__(vcs)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
5270
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
32 def hgStrip(self, name, rev=""):
5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 Public method to strip revisions from a repository.
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
5270
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
36 @param name file/directory name
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
37 @type str
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
38 @keyparam rev revision to strip from
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
39 @type str
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
40 @return flag indicating that the project should be reread
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
41 @rtype bool
5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 # find the root of the repo
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 repodir = self.vcs.splitPath(name)[0]
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 repodir = os.path.dirname(repodir)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 if os.path.splitdrive(repodir)[1] == os.sep:
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 return False
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 from .HgStripDialog import HgStripDialog
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 res = False
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 dlg = HgStripDialog(self.vcs.hgGetTagsList(repodir),
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.vcs.hgGetBranchesList(repodir),
5270
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
54 self.vcs.hgGetBookmarksList(repodir),
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
55 rev)
5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 if dlg.exec_() == QDialog.Accepted:
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 rev, bookmark, force, noBackup, keep = dlg.getData()
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 args = self.vcs.initCommand("strip")
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 if bookmark:
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 args.append("--bookmark")
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 args.append(bookmark)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 if force:
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 args.append("--force")
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 if noBackup:
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 args.append("--no-backup")
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 if keep:
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 args.append("--keep")
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 args.append("-v")
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 args.append(rev)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 dia = HgDialog(
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.tr("Stripping changesets from repository"),
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.vcs)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 res = dia.startProcess(args, repodir)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 if res:
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 dia.exec_()
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 res = dia.hasAddOrDelete()
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.vcs.checkVCSStatus()
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 return res

eric ide

mercurial