22 |
22 |
23 class Largefiles(HgExtension): |
23 class Largefiles(HgExtension): |
24 """ |
24 """ |
25 Class implementing the largefiles extension interface. |
25 Class implementing the largefiles extension interface. |
26 """ |
26 """ |
|
27 |
27 def __init__(self, vcs): |
28 def __init__(self, vcs): |
28 """ |
29 """ |
29 Constructor |
30 Constructor |
30 |
31 |
31 @param vcs reference to the Mercurial vcs object |
32 @param vcs reference to the Mercurial vcs object |
32 """ |
33 """ |
33 super().__init__(vcs) |
34 super().__init__(vcs) |
34 |
35 |
35 def hgLfconvert(self, direction, projectFile): |
36 def hgLfconvert(self, direction, projectFile): |
36 """ |
37 """ |
37 Public slot to convert the repository format of the current project. |
38 Public slot to convert the repository format of the current project. |
38 |
39 |
39 @param direction direction of the conversion (string, one of |
40 @param direction direction of the conversion (string, one of |
40 'largefiles' or 'normal') |
41 'largefiles' or 'normal') |
41 @param projectFile file name of the current project file (string) |
42 @param projectFile file name of the current project file (string) |
42 @exception ValueError raised to indicate a bad value for the |
43 @exception ValueError raised to indicate a bad value for the |
43 'direction' parameter. |
44 'direction' parameter. |
44 """ |
45 """ |
45 if direction not in ["largefiles", "normal"]: |
46 if direction not in ["largefiles", "normal"]: |
46 raise ValueError("Bad value for 'direction' parameter.") |
47 raise ValueError("Bad value for 'direction' parameter.") |
47 |
48 |
48 projectDir = os.path.dirname(projectFile) |
49 projectDir = os.path.dirname(projectFile) |
49 |
50 |
50 from .LfConvertDataDialog import LfConvertDataDialog |
51 from .LfConvertDataDialog import LfConvertDataDialog |
|
52 |
51 dlg = LfConvertDataDialog(projectDir, direction) |
53 dlg = LfConvertDataDialog(projectDir, direction) |
52 if dlg.exec() == QDialog.DialogCode.Accepted: |
54 if dlg.exec() == QDialog.DialogCode.Accepted: |
53 newName, minSize, patterns = dlg.getData() |
55 newName, minSize, patterns = dlg.getData() |
54 newProjectFile = os.path.join( |
56 newProjectFile = os.path.join(newName, os.path.basename(projectFile)) |
55 newName, os.path.basename(projectFile)) |
57 |
56 |
|
57 # step 1: convert the current project to new project |
58 # step 1: convert the current project to new project |
58 args = self.vcs.initCommand("lfconvert") |
59 args = self.vcs.initCommand("lfconvert") |
59 if direction == 'normal': |
60 if direction == "normal": |
60 args.append('--to-normal') |
61 args.append("--to-normal") |
61 else: |
62 else: |
62 args.append("--size") |
63 args.append("--size") |
63 args.append(str(minSize)) |
64 args.append(str(minSize)) |
64 args.append(projectDir) |
65 args.append(projectDir) |
65 args.append(newName) |
66 args.append(newName) |
66 if direction == 'largefiles' and patterns: |
67 if direction == "largefiles" and patterns: |
67 args.extend(patterns) |
68 args.extend(patterns) |
68 |
69 |
69 dia = HgDialog(self.tr('Convert Project - Converting'), self.vcs) |
70 dia = HgDialog(self.tr("Convert Project - Converting"), self.vcs) |
70 res = dia.startProcess(args) |
71 res = dia.startProcess(args) |
71 if res: |
72 if res: |
72 dia.exec() |
73 dia.exec() |
73 res = dia.normalExit() and os.path.isdir( |
74 res = dia.normalExit() and os.path.isdir( |
74 os.path.join(newName, self.vcs.adminDir)) |
75 os.path.join(newName, self.vcs.adminDir) |
75 |
76 ) |
|
77 |
76 # step 2: create working directory contents |
78 # step 2: create working directory contents |
77 if res: |
79 if res: |
78 # step 2.1: start a command server client for the new repo |
80 # step 2.1: start a command server client for the new repo |
79 client = HgClient(newName, "utf-8", self.vcs) |
81 client = HgClient(newName, "utf-8", self.vcs) |
80 ok, err = client.startServer() |
82 ok, err = client.startServer() |
82 EricMessageBox.warning( |
84 EricMessageBox.warning( |
83 None, |
85 None, |
84 self.tr("Mercurial Command Server"), |
86 self.tr("Mercurial Command Server"), |
85 self.tr( |
87 self.tr( |
86 """<p>The Mercurial Command Server could not be""" |
88 """<p>The Mercurial Command Server could not be""" |
87 """ started.</p><p>Reason: {0}</p>""").format(err)) |
89 """ started.</p><p>Reason: {0}</p>""" |
|
90 ).format(err), |
|
91 ) |
88 return |
92 return |
89 |
93 |
90 # step 2.2: create working directory contents |
94 # step 2.2: create working directory contents |
91 args = self.vcs.initCommand("update") |
95 args = self.vcs.initCommand("update") |
92 args.append("--verbose") |
96 args.append("--verbose") |
93 dia = HgDialog(self.tr('Convert Project - Extracting'), |
97 dia = HgDialog( |
94 self.vcs, client=client) |
98 self.tr("Convert Project - Extracting"), self.vcs, client=client |
|
99 ) |
95 res = dia.startProcess(args) |
100 res = dia.startProcess(args) |
96 if res: |
101 if res: |
97 dia.exec() |
102 dia.exec() |
98 res = dia.normalExit() and os.path.isfile(newProjectFile) |
103 res = dia.normalExit() and os.path.isfile(newProjectFile) |
99 |
104 |
100 # step 2.3: stop the command server client for the new repo |
105 # step 2.3: stop the command server client for the new repo |
101 client.stopServer() |
106 client.stopServer() |
102 |
107 |
103 # step 3: close current project and open new one |
108 # step 3: close current project and open new one |
104 if res: |
109 if res: |
105 if direction == 'largefiles': |
110 if direction == "largefiles": |
106 self.vcs.hgEditConfig( |
111 self.vcs.hgEditConfig( |
107 repoName=newName, |
112 repoName=newName, |
108 largefilesData={"minsize": minSize, |
113 largefilesData={"minsize": minSize, "pattern": patterns}, |
109 "pattern": patterns} |
|
110 ) |
114 ) |
111 else: |
115 else: |
112 self.vcs.hgEditConfig( |
116 self.vcs.hgEditConfig(repoName=newName, withLargefiles=False) |
113 repoName=newName, |
|
114 withLargefiles=False |
|
115 ) |
|
116 QTimer.singleShot( |
117 QTimer.singleShot( |
117 0, lambda: ericApp().getObject("Project").openProject( |
118 0, |
118 newProjectFile)) |
119 lambda: ericApp().getObject("Project").openProject(newProjectFile), |
119 |
120 ) |
|
121 |
120 def hgAdd(self, names, mode): |
122 def hgAdd(self, names, mode): |
121 """ |
123 """ |
122 Public method used to add a file to the Mercurial repository. |
124 Public method used to add a file to the Mercurial repository. |
123 |
125 |
124 @param names file name(s) to be added (string or list of string) |
126 @param names file name(s) to be added (string or list of string) |
125 @param mode add mode (string one of 'normal' or 'large') |
127 @param mode add mode (string one of 'normal' or 'large') |
126 """ |
128 """ |
127 args = self.vcs.initCommand("add") |
129 args = self.vcs.initCommand("add") |
128 args.append("-v") |
130 args.append("-v") |
129 if mode == "large": |
131 if mode == "large": |
130 args.append("--large") |
132 args.append("--large") |
131 else: |
133 else: |
132 args.append("--normal") |
134 args.append("--normal") |
133 |
135 |
134 if isinstance(names, list): |
136 if isinstance(names, list): |
135 self.vcs.addArguments(args, names) |
137 self.vcs.addArguments(args, names) |
136 else: |
138 else: |
137 args.append(names) |
139 args.append(names) |
138 |
140 |
139 dia = HgDialog( |
141 dia = HgDialog(self.tr("Adding files to the Mercurial repository"), self.vcs) |
140 self.tr('Adding files to the Mercurial repository'), |
|
141 self.vcs) |
|
142 res = dia.startProcess(args) |
142 res = dia.startProcess(args) |
143 if res: |
143 if res: |
144 dia.exec() |
144 dia.exec() |
145 |
145 |
146 def hgLfPull(self, revisions=None): |
146 def hgLfPull(self, revisions=None): |
147 """ |
147 """ |
148 Public method to pull missing large files into the local repository. |
148 Public method to pull missing large files into the local repository. |
149 |
149 |
150 @param revisions list of revisions to pull (list of string) |
150 @param revisions list of revisions to pull (list of string) |
151 """ |
151 """ |
152 revs = [] |
152 revs = [] |
153 if revisions: |
153 if revisions: |
154 revs = revisions |
154 revs = revisions |
155 else: |
155 else: |
156 from .LfRevisionsInputDialog import LfRevisionsInputDialog |
156 from .LfRevisionsInputDialog import LfRevisionsInputDialog |
|
157 |
157 dlg = LfRevisionsInputDialog() |
158 dlg = LfRevisionsInputDialog() |
158 if dlg.exec() == QDialog.DialogCode.Accepted: |
159 if dlg.exec() == QDialog.DialogCode.Accepted: |
159 revs = dlg.getRevisions() |
160 revs = dlg.getRevisions() |
160 |
161 |
161 if revs: |
162 if revs: |
162 args = self.vcs.initCommand("lfpull") |
163 args = self.vcs.initCommand("lfpull") |
163 args.append("-v") |
164 args.append("-v") |
164 for rev in revs: |
165 for rev in revs: |
165 args.append("--rev") |
166 args.append("--rev") |
166 args.append(rev) |
167 args.append(rev) |
167 |
168 |
168 dia = HgDialog(self.tr("Pulling large files"), self.vcs) |
169 dia = HgDialog(self.tr("Pulling large files"), self.vcs) |
169 res = dia.startProcess(args) |
170 res = dia.startProcess(args) |
170 if res: |
171 if res: |
171 dia.exec() |
172 dia.exec() |
172 |
173 |
173 def hgLfVerify(self, mode): |
174 def hgLfVerify(self, mode): |
174 """ |
175 """ |
175 Public method to verify large files integrity. |
176 Public method to verify large files integrity. |
176 |
177 |
177 @param mode verify mode (string; one of 'large', 'lfa' or 'lfc') |
178 @param mode verify mode (string; one of 'large', 'lfa' or 'lfc') |
178 """ |
179 """ |
179 args = self.vcs.initCommand("verify") |
180 args = self.vcs.initCommand("verify") |
180 if mode == "large": |
181 if mode == "large": |
181 args.append("--large") |
182 args.append("--large") |