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