annotate sat/plugins/plugin_merge_req_mercurial.py @ 4007:1d5a81e3c9e8

plugin XEP-0384: skip MessageReceived trigger when in a component: OMEMO is not used in components so far, but the trigger is trying to request OMEMO PEP nodes, which causes an error with virtual pubsub service of AP component.
author Goffi <goffi@goffi.org>
date Thu, 16 Mar 2023 12:31:24 +0100
parents e3c1f4736ab2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
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
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3368
diff changeset
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
181735d1b062 plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
21 from sat.tools.common import async_process
181735d1b062 plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
22 from sat.tools import utils
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.i18n import _, D_
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.core.constants import Const as C
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core import exceptions
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.core.log import getLogger
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 log = getLogger(__name__)
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
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 PLUGIN_INFO = {
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 C.PI_NAME: "Mercurial Merge Request handler",
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 C.PI_IMPORT_NAME: "MERGE_REQUEST_MERCURIAL",
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 C.PI_TYPE: C.PLUG_TYPE_MISC,
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 C.PI_DEPENDENCIES: ["MERGE_REQUESTS"],
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 C.PI_MAIN: "MercurialHandler",
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 C.PI_HANDLER: "no",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
37 C.PI_DESCRIPTION: _("""Merge request handler for Mercurial""")
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 }
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
40 SHORT_DESC = D_("handle Mercurial repository")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
41 CLEAN_RE = re.compile(r'[^\w -._]', flags=re.UNICODE)
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
2793
181735d1b062 plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
44 class MercurialProtocol(async_process.CommandProtocol):
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 """handle hg commands"""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
46 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
47 command = None
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 @classmethod
2544
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
50 def run(cls, path, command, *args, **kwargs):
2620
72f6f37ab648 core: some more line limiting
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 """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
52
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 @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
54 @param command(unicode): hg command to run
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
55 @return D(bytes): stdout of the command
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
57 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
58 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
59 # 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
60 # 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
61 # 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
62 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
63 d.addErrback(utils.logError)
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 return d
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 class MercurialHandler(object):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
68 data_types = ('mercurial_changeset',)
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
71 log.info(_("Mercurial merge request handler initialization"))
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 try:
2793
181735d1b062 plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
73 MercurialProtocol.command = which('hg')[0]
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 except IndexError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
75 raise exceptions.NotFound(_("Mercurial executable (hg) not found, "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
76 "can't use Mercurial handler"))
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 self.host = host
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self._m = host.plugins['MERGE_REQUESTS']
2544
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
79 self._m.register('mercurial', self, self.data_types, SHORT_DESC)
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80
2793
181735d1b062 plugin mr mercurial, tools(common/utils): moved command protocol to a new module
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
81
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 def check(self, repository):
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 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
84 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
85 d.addErrback(lambda __: False)
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 return d
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 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
89 d = MercurialProtocol.run(
e3c1f4736ab2 plugin mr mercurial: limit export to ancestors of working directory parent
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
90 repository, 'export', '-g', '-r', 'outgoing() and ancestors(.)',
e3c1f4736ab2 plugin mr mercurial: limit export to ancestors of working directory parent
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
91 '--encoding=utf-8'
e3c1f4736ab2 plugin mr mercurial: limit export to ancestors of working directory parent
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
92 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
93 d.addCallback(lambda data: data.decode('utf-8'))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
94 return d
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95
2544
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
96 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
97 parsed_data = self.parse(data)
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
98 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
99 parsed_name = parsed_data[0]['commit_msg'].split('\n')[0]
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
100 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
101 except Exception:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
102 parsed_name = ''
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
103 name = 'mr_{item_id}_{parsed_name}'.format(item_id=CLEAN_RE.sub('', item_id),
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
104 parsed_name=parsed_name)
2620
72f6f37ab648 core: some more line limiting
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
105 return MercurialProtocol.run(repository, 'qimport', '-g', '--name', name,
72f6f37ab648 core: some more line limiting
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
106 '--encoding=utf-8', '-', stdin=data)
2544
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
107
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 def parse(self, data, data_type=None):
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 lines = data.splitlines()
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 total_lines = len(lines)
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 patches = []
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 while lines:
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 patch = {}
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 commit_msg = []
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 diff = []
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 state = 'init'
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 if lines[0] != '# HG changeset patch':
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
118 raise exceptions.DataError(_('invalid changeset signature'))
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 # line index of this patch in the whole data
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 patch_idx = total_lines - len(lines)
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 del lines[0]
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 for idx, line in enumerate(lines):
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 if state == 'init':
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
125 if line.startswith('# '):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
126 if line.startswith('# User '):
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 elems = line[7:].split()
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 if not elems:
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 continue
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 last = elems[-1]
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
131 if (last.startswith('<') and last.endswith('>')
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
132 and '@' in last):
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 patch[self._m.META_EMAIL] = elems.pop()[1:-1]
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
134 patch[self._m.META_AUTHOR] = ' '.join(elems)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
135 elif line.startswith('# Date '):
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 time_data = line[7:].split()
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 if len(time_data) != 2:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
138 log.warning(_('unexpected time data: {data}')
2620
72f6f37ab648 core: some more line limiting
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 .format(data=line[7:]))
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 continue
2620
72f6f37ab648 core: some more line limiting
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 patch[self._m.META_TIMESTAMP] = (int(time_data[0])
72f6f37ab648 core: some more line limiting
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
142 + int(time_data[1]))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
143 elif line.startswith('# Node ID '):
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 patch[self._m.META_HASH] = line[10:]
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
145 elif line.startswith('# Parent '):
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 patch[self._m.META_PARENT_HASH] = line[10:]
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 else:
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 state = 'commit_msg'
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 if state == 'commit_msg':
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
150 if line.startswith('diff --git a/'):
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 state = 'diff'
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 patch[self._m.META_DIFF_IDX] = patch_idx + idx + 1
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 else:
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 commit_msg.append(line)
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 if state == 'diff':
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
156 if line.startswith('# ') or idx == len(lines)-1:
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 # a new patch is starting or we have reached end of patches
2627
163aab916bcf plugin merge-request/mercurial: fixed missing last line in diff while parsing patch
Goffi <goffi@goffi.org>
parents: 2623
diff changeset
158 if idx == len(lines)-1:
163aab916bcf plugin merge-request/mercurial: fixed missing last line in diff while parsing patch
Goffi <goffi@goffi.org>
parents: 2623
diff changeset
159 # 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
160 diff.append(line)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
161 patch[self._m.META_COMMIT_MSG] = '\n'.join(commit_msg)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2793
diff changeset
162 patch[self._m.META_DIFF] = '\n'.join(diff)
2449
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 patches.append(patch)
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 if idx == len(lines)-1:
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 del lines[:]
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 else:
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 del lines[:idx]
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 break
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 else:
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 diff.append(line)
67942ba2ee55 plugin merge requests Mercurial: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 return patches