Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_merge_req_mercurial.py @ 4332:71c939e34ca6
XEP-0373 (OX): Adjust to gpgme updates: generate with explicit algorithm and subkeys
author | Syndace <me@syndace.dev> |
---|---|
date | Sat, 13 Jul 2024 18:28:28 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
3368
e86b71b1aa31
core: minor typos, docstring/comments update
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
3 # SàT plugin managing Mercurial VCS |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
2793
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
19 import re |
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
20 from twisted.python.procutils import which |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
3876
diff
changeset
|
21 from libervia.backend.tools.common import async_process |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
3876
diff
changeset
|
22 from libervia.backend.tools import utils |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
3876
diff
changeset
|
23 from libervia.backend.core.i18n import _, D_ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
3876
diff
changeset
|
24 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
3876
diff
changeset
|
25 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
3876
diff
changeset
|
26 from libervia.backend.core.log import getLogger |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
27 |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 log = getLogger(__name__) |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 PLUGIN_INFO = { |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 C.PI_NAME: "Mercurial Merge Request handler", |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 C.PI_IMPORT_NAME: "MERGE_REQUEST_MERCURIAL", |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 C.PI_TYPE: C.PLUG_TYPE_MISC, |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 C.PI_DEPENDENCIES: ["MERGE_REQUESTS"], |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 C.PI_MAIN: "MercurialHandler", |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 C.PI_HANDLER: "no", |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
38 C.PI_DESCRIPTION: _("""Merge request handler for Mercurial"""), |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 } |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
3028 | 41 SHORT_DESC = D_("handle Mercurial repository") |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
42 CLEAN_RE = re.compile(r"[^\w -._]", flags=re.UNICODE) |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
2793
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
45 class MercurialProtocol(async_process.CommandProtocol): |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 """handle hg commands""" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
47 |
3028 | 48 name = "Mercurial" |
2793
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
49 command = None |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 @classmethod |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
52 def run(cls, path, command, *args, **kwargs): |
2620 | 53 """Create a new MercurialRegisterProtocol and execute the given mercurial command. |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 @param path(unicode): path to the repository |
2793
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
56 @param command(unicode): hg command to run |
3040 | 57 @return D(bytes): stdout of the command |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 """ |
3028 | 59 assert "path" not in kwargs |
2793
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
60 kwargs["path"] = path |
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
61 # FIXME: we have to use this workaround because Twisted's protocol.ProcessProtocol |
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
62 # is not using new style classes. This can be removed once moved to |
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
63 # Python 3 (super can be used normally then). |
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
64 d = async_process.CommandProtocol.run.__func__(cls, command, *args, **kwargs) |
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
65 d.addErrback(utils.logError) |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 return d |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 class MercurialHandler(object): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
70 data_types = ("mercurial_changeset",) |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 def __init__(self, host): |
3028 | 73 log.info(_("Mercurial merge request handler initialization")) |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 try: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
75 MercurialProtocol.command = which("hg")[0] |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 except IndexError: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
77 raise exceptions.NotFound( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
78 _("Mercurial executable (hg) not found, " "can't use Mercurial handler") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
79 ) |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 self.host = host |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
81 self._m = host.plugins["MERGE_REQUESTS"] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
82 self._m.register("mercurial", self, self.data_types, SHORT_DESC) |
2793
181735d1b062
plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
83 |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 def check(self, repository): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
85 d = MercurialProtocol.run(repository, "identify") |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2627
diff
changeset
|
86 d.addCallback(lambda __: True) |
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2627
diff
changeset
|
87 d.addErrback(lambda __: False) |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 return d |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 def export(self, repository): |
3876
e3c1f4736ab2
plugin mr mercurial: limit export to ancestors of working directory parent
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
91 d = MercurialProtocol.run( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
92 repository, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
93 "export", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
94 "-g", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
95 "-r", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
96 "outgoing() and ancestors(.)", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
97 "--encoding=utf-8", |
3876
e3c1f4736ab2
plugin mr mercurial: limit export to ancestors of working directory parent
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
98 ) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
99 d.addCallback(lambda data: data.decode("utf-8")) |
3040 | 100 return d |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
102 def import_(self, repository, data, data_type, item_id, service, node, extra): |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
103 parsed_data = self.parse(data) |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
104 try: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
105 parsed_name = parsed_data[0]["commit_msg"].split("\n")[0] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
106 parsed_name = CLEAN_RE.sub("", parsed_name)[:40] |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
107 except Exception: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
108 parsed_name = "" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
109 name = "mr_{item_id}_{parsed_name}".format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
110 item_id=CLEAN_RE.sub("", item_id), parsed_name=parsed_name |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
111 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
112 return MercurialProtocol.run( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
113 repository, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
114 "qimport", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
115 "-g", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
116 "--name", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
117 name, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
118 "--encoding=utf-8", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
119 "-", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
120 stdin=data, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
121 ) |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
122 |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 def parse(self, data, data_type=None): |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 lines = data.splitlines() |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 total_lines = len(lines) |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 patches = [] |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 while lines: |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 patch = {} |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 commit_msg = [] |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 diff = [] |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
131 state = "init" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
132 if lines[0] != "# HG changeset patch": |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
133 raise exceptions.DataError(_("invalid changeset signature")) |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 # line index of this patch in the whole data |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 patch_idx = total_lines - len(lines) |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 del lines[0] |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 for idx, line in enumerate(lines): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
139 if state == "init": |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
140 if line.startswith("# "): |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
141 if line.startswith("# User "): |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 elems = line[7:].split() |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 if not elems: |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 continue |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 last = elems[-1] |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
146 if ( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
147 last.startswith("<") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
148 and last.endswith(">") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
149 and "@" in last |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
150 ): |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 patch[self._m.META_EMAIL] = elems.pop()[1:-1] |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
152 patch[self._m.META_AUTHOR] = " ".join(elems) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
153 elif line.startswith("# Date "): |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 time_data = line[7:].split() |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 if len(time_data) != 2: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
156 log.warning( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
157 _("unexpected time data: {data}").format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
158 data=line[7:] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
159 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
160 ) |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 continue |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
162 patch[self._m.META_TIMESTAMP] = int(time_data[0]) + int( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
163 time_data[1] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
164 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
165 elif line.startswith("# Node ID "): |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 patch[self._m.META_HASH] = line[10:] |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
167 elif line.startswith("# Parent "): |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 patch[self._m.META_PARENT_HASH] = line[10:] |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 else: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
170 state = "commit_msg" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
171 if state == "commit_msg": |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
172 if line.startswith("diff --git a/"): |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
173 state = "diff" |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 patch[self._m.META_DIFF_IDX] = patch_idx + idx + 1 |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 else: |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 commit_msg.append(line) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
177 if state == "diff": |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
178 if line.startswith("# ") or idx == len(lines) - 1: |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 # a new patch is starting or we have reached end of patches |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
180 if idx == len(lines) - 1: |
2627
163aab916bcf
plugin merge-request/mercurial: fixed missing last line in diff while parsing patch
Goffi <goffi@goffi.org>
parents:
2623
diff
changeset
|
181 # end of patches, we need to keep the line |
163aab916bcf
plugin merge-request/mercurial: fixed missing last line in diff while parsing patch
Goffi <goffi@goffi.org>
parents:
2623
diff
changeset
|
182 diff.append(line) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
183 patch[self._m.META_COMMIT_MSG] = "\n".join(commit_msg) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
184 patch[self._m.META_DIFF] = "\n".join(diff) |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 patches.append(patch) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
186 if idx == len(lines) - 1: |
2449
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 del lines[:] |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 else: |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 del lines[:idx] |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 break |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 else: |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 diff.append(line) |
67942ba2ee55
plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 return patches |