bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
1 |
# __init__.py -- Quilt support for breezy
|
2 |
#
|
|
3 |
# Breezy is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# Breezy is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with Breezy; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
#
|
|
17 |
||
|
7321.2.3
by Jelmer Vernooij
Fix flake8 errors. |
18 |
from __future__ import absolute_import |
19 |
||
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
20 |
"""Quilt patch integration.
|
21 |
||
22 |
This plugin adds support for three configuration options:
|
|
23 |
||
24 |
* quilt.commit_policy
|
|
25 |
* quilt.smart_merge
|
|
26 |
* quilt.tree_policy
|
|
27 |
||
28 |
"""
|
|
29 |
||
30 |
from ...errors import BzrError |
|
31 |
from ... import trace |
|
32 |
||
33 |
||
34 |
class QuiltUnapplyError(BzrError): |
|
35 |
||
36 |
_fmt = ("Unable to unapply quilt patches for %(kind)r tree: %(msg)s") |
|
37 |
||
38 |
def __init__(self, kind, msg): |
|
39 |
BzrError.__init__(self) |
|
40 |
self.kind = kind |
|
41 |
if msg is not None and msg.count("\n") == 1: |
|
42 |
msg = msg.strip() |
|
43 |
self.msg = msg |
|
44 |
||
45 |
||
46 |
def pre_merge_quilt(merger): |
|
47 |
if getattr(merger, "_no_quilt_unapplying", False): |
|
48 |
return
|
|
49 |
||
50 |
config = merger.working_tree.get_config_stack() |
|
51 |
merger.debuild_config = config |
|
52 |
if not config.get('quilt.smart_merge'): |
|
53 |
trace.mutter("skipping smart quilt merge, not enabled.") |
|
54 |
return
|
|
55 |
||
56 |
if (not merger.other_tree.is_versioned(".pc") and |
|
57 |
not merger.this_tree.is_versioned(".pc") and |
|
58 |
not merger.working_tree.is_versioned(".pc")): |
|
59 |
return
|
|
60 |
||
61 |
from .quilt import QuiltPatches, QuiltError |
|
62 |
quilt = QuiltPatches(merger.working_tree) |
|
63 |
from .merge import tree_unapply_patches |
|
64 |
trace.note("Unapplying quilt patches to prevent spurious conflicts") |
|
65 |
merger._quilt_tempdirs = [] |
|
66 |
merger._old_quilt_series = quilt.series() |
|
67 |
if merger._old_quilt_series: |
|
68 |
quilt.pop_all() |
|
69 |
try: |
|
70 |
merger.this_tree, this_dir = tree_unapply_patches( |
|
71 |
merger.this_tree, merger.this_branch, force=True) |
|
72 |
except QuiltError as e: |
|
73 |
raise QuiltUnapplyError("this", e.stderr) |
|
74 |
else: |
|
75 |
if this_dir is not None: |
|
76 |
merger._quilt_tempdirs.append(this_dir) |
|
77 |
try: |
|
78 |
merger.base_tree, base_dir = tree_unapply_patches( |
|
79 |
merger.base_tree, merger.this_branch, force=True) |
|
80 |
except QuiltError as e: |
|
81 |
raise QuiltUnapplyError("base", e.stderr) |
|
82 |
else: |
|
83 |
if base_dir is not None: |
|
84 |
merger._quilt_tempdirs.append(base_dir) |
|
85 |
other_branch = getattr(merger, "other_branch", None) |
|
86 |
if other_branch is None: |
|
87 |
other_branch = merger.this_branch |
|
88 |
try: |
|
89 |
merger.other_tree, other_dir = tree_unapply_patches( |
|
90 |
merger.other_tree, other_branch, force=True) |
|
91 |
except QuiltError as e: |
|
92 |
raise QuiltUnapplyError("other", e.stderr) |
|
93 |
else: |
|
94 |
if other_dir is not None: |
|
95 |
merger._quilt_tempdirs.append(other_dir) |
|
96 |
||
97 |
||
98 |
def post_merge_quilt_cleanup(merger): |
|
99 |
import shutil |
|
100 |
for dir in getattr(merger, "_quilt_tempdirs", []): |
|
101 |
shutil.rmtree(dir) |
|
102 |
config = merger.working_tree.get_config_stack() |
|
103 |
policy = config.get('quilt.tree_policy') |
|
104 |
if policy is None: |
|
105 |
return
|
|
106 |
from .merge import post_process_quilt_patches |
|
107 |
post_process_quilt_patches( |
|
108 |
merger.working_tree, |
|
109 |
getattr(merger, "_old_quilt_series", []), policy) |
|
110 |
||
111 |
||
112 |
def start_commit_check_quilt(tree): |
|
113 |
"""start_commit hook which checks the state of quilt patches. |
|
114 |
"""
|
|
115 |
config = tree.get_config_stack() |
|
116 |
policy = config.get('quilt.commit_policy') |
|
117 |
from .merge import start_commit_quilt_patches |
|
118 |
start_commit_quilt_patches(tree, policy) |
|
119 |
||
120 |
||
121 |
def post_build_tree_quilt(tree): |
|
122 |
config = tree.get_config_stack() |
|
123 |
policy = config.get('quilt.tree_policy') |
|
124 |
if policy is None: |
|
125 |
return
|
|
126 |
from .merge import post_process_quilt_patches |
|
127 |
post_process_quilt_patches(tree, [], policy) |
|
128 |
||
129 |
||
130 |
from ...hooks import install_lazy_named_hook |
|
131 |
install_lazy_named_hook( |
|
132 |
"breezy.merge", "Merger.hooks", |
|
133 |
'pre_merge_quilt', pre_merge_quilt, |
|
134 |
'Quilt patch (un)applying') |
|
135 |
install_lazy_named_hook( |
|
136 |
"breezy.mutabletree", "MutableTree.hooks", |
|
137 |
"start_commit", start_commit_check_quilt, |
|
138 |
"Check for (un)applied quilt patches") |
|
139 |
install_lazy_named_hook( |
|
140 |
"breezy.merge", "Merger.hooks", |
|
141 |
'post_merge', post_merge_quilt_cleanup, |
|
142 |
'Cleaning up quilt temporary directories') |
|
143 |
install_lazy_named_hook( |
|
144 |
"breezy.mutabletree", "MutableTree.hooks", |
|
145 |
'post_build_tree', post_build_tree_quilt, |
|
146 |
'Applying quilt patches.') |
|
147 |
||
148 |
||
149 |
from ...config import option_registry, Option, bool_from_store |
|
150 |
option_registry.register( |
|
151 |
Option('quilt.smart_merge', default=True, from_unicode=bool_from_store, |
|
152 |
help="Unapply quilt patches before merging.")) |
|
153 |
||
|
7321.2.3
by Jelmer Vernooij
Fix flake8 errors. |
154 |
|
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
155 |
def policy_from_store(s): |
|
7321.2.3
by Jelmer Vernooij
Fix flake8 errors. |
156 |
if s not in ('applied', 'unapplied'): |
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
157 |
raise ValueError('Invalid quilt.commit_policy: %s' % s) |
158 |
return s |
|
159 |
||
160 |
option_registry.register( |
|
161 |
Option('quilt.commit_policy', default=None, from_unicode=policy_from_store, |
|
|
7321.2.3
by Jelmer Vernooij
Fix flake8 errors. |
162 |
help="Whether to apply or unapply all patches in commits.")) |
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
163 |
|
164 |
option_registry.register( |
|
165 |
Option('quilt.tree_policy', default=None, from_unicode=policy_from_store, |
|
|
7321.2.3
by Jelmer Vernooij
Fix flake8 errors. |
166 |
help="Whether to apply or unapply all patches after checkout/update.")) |
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
167 |
|
168 |
||
169 |
def load_tests(loader, basic_tests, pattern): |
|
170 |
basic_tests.addTest( |
|
171 |
loader.loadTestsFromModuleNames([__name__ + '.tests'])) |
|
172 |
return basic_tests |