|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the closehead extension interface. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
|
13 |
|
14 from PyQt5.QtWidgets import QDialog |
|
15 |
|
16 from ..HgExtension import HgExtension |
|
17 from ..HgDialog import HgDialog |
|
18 |
|
19 |
|
20 class Closehead(HgExtension): |
|
21 """ |
|
22 Class implementing the strip 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(Closehead, self).__init__(vcs) |
|
32 |
|
33 def hgCloseheads(self, name, revisions=None): |
|
34 """ |
|
35 Public method to close arbitrary heads. |
|
36 |
|
37 @param name file/directory name |
|
38 @type str |
|
39 @param revisions revisions of branch heads to be closed |
|
40 @type str |
|
41 """ |
|
42 # find the root of the repo |
|
43 repodir = self.vcs.splitPath(name)[0] |
|
44 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
45 repodir = os.path.dirname(repodir) |
|
46 if os.path.splitdrive(repodir)[1] == os.sep: |
|
47 return |
|
48 |
|
49 message = "" |
|
50 if not revisions: |
|
51 from .HgCloseHeadSelectionDialog import HgCloseHeadSelectionDialog |
|
52 dlg = HgCloseHeadSelectionDialog(self.vcs, name) |
|
53 if dlg.exec_() == QDialog.Accepted: |
|
54 revisions, message = dlg.getData() |
|
55 |
|
56 if not revisions: |
|
57 # still no revisions given; abort... |
|
58 return |
|
59 |
|
60 args = self.vcs.initCommand("close-head") |
|
61 if not message: |
|
62 if len(revisions) == 1: |
|
63 message = self.tr("Revision <{0}> closed.").format( |
|
64 revisions[0]) |
|
65 else: |
|
66 message = self.tr("Revisions <{0}> closed.").format( |
|
67 ", ".join(revisions)) |
|
68 args += ["--message", message] |
|
69 for revision in revisions: |
|
70 args += ["--rev", revision] |
|
71 |
|
72 dia = HgDialog(self.tr("Closing Heads"), self.vcs) |
|
73 res = dia.startProcess(args, repodir) |
|
74 if res: |
|
75 dia.exec_() |