Merge lp:~jelmer/brz/lossy-push into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/lossy-push
Merge into: lp:brz
Diff against target: 194 lines (+33/-19)
6 files modified
breezy/branch.py (+3/-1)
breezy/builtins.py (+5/-2)
breezy/bzr/bzrdir.py (+3/-2)
breezy/controldir.py (+10/-11)
breezy/push.py (+4/-3)
breezy/tests/per_controldir/test_push.py (+8/-0)
To merge this branch: bzr merge lp:~jelmer/brz/lossy-push
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+345125@code.launchpad.net

Commit message

Add a --lossy option to push.

Description of the change

Add a --lossy option to push.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/branch.py'
2--- breezy/branch.py 2018-03-25 14:35:12 +0000
3+++ breezy/branch.py 2018-05-05 13:44:08 +0000
4@@ -1201,7 +1201,7 @@
5 return result
6
7 def sprout(self, to_controldir, revision_id=None, repository_policy=None,
8- repository=None):
9+ repository=None, lossy=False):
10 """Create a new line of development from the branch, into to_controldir.
11
12 to_controldir controls the branch format.
13@@ -1213,6 +1213,8 @@
14 repository_policy.requires_stacking()):
15 to_controldir._format.require_stacking(_skip_repo=True)
16 result = to_controldir.create_branch(repository=repository)
17+ if lossy:
18+ raise errors.LossyPushToSameVCS(self, result)
19 with self.lock_read(), result.lock_write():
20 if repository_policy is not None:
21 repository_policy.configure_branch(result)
22
23=== modified file 'breezy/builtins.py'
24--- breezy/builtins.py 2018-05-05 01:50:26 +0000
25+++ breezy/builtins.py 2018-05-05 13:44:08 +0000
26@@ -1313,6 +1313,8 @@
27 " that support it."),
28 Option('overwrite-tags',
29 help="Overwrite tags only."),
30+ Option('lossy', help="Allow lossy push, i.e. dropping metadata "
31+ "that can't be represented in the target.")
32 ]
33 takes_args = ['location?']
34 encoding_type = 'replace'
35@@ -1321,7 +1323,7 @@
36 create_prefix=False, verbose=False, revision=None,
37 use_existing_dir=False, directory=None, stacked_on=None,
38 stacked=False, strict=None, no_tree=False,
39- overwrite_tags=False):
40+ overwrite_tags=False, lossy=False):
41 from .push import _show_push_branch
42
43 if overwrite:
44@@ -1388,7 +1390,8 @@
45 _show_push_branch(br_from, revision_id, location, self.outf,
46 verbose=verbose, overwrite=overwrite, remember=remember,
47 stacked_on=stacked_on, create_prefix=create_prefix,
48- use_existing_dir=use_existing_dir, no_tree=no_tree)
49+ use_existing_dir=use_existing_dir, no_tree=no_tree,
50+ lossy=lossy)
51
52
53 class cmd_branch(Command):
54
55=== modified file 'breezy/bzr/bzrdir.py'
56--- breezy/bzr/bzrdir.py 2018-04-12 16:37:48 +0000
57+++ breezy/bzr/bzrdir.py 2018-05-05 13:44:08 +0000
58@@ -348,7 +348,8 @@
59 def sprout(self, url, revision_id=None, force_new_repo=False,
60 recurse='down', possible_transports=None,
61 accelerator_tree=None, hardlink=False, stacked=False,
62- source_branch=None, create_tree_if_local=True):
63+ source_branch=None, create_tree_if_local=True,
64+ lossy=False):
65 """Create a copy of this controldir prepared for use as a new line of
66 development.
67
68@@ -385,7 +386,7 @@
69 def _sprout(self, op, url, revision_id=None, force_new_repo=False,
70 recurse='down', possible_transports=None,
71 accelerator_tree=None, hardlink=False, stacked=False,
72- source_branch=None, create_tree_if_local=True):
73+ source_branch=None, create_tree_if_local=True, lossy=False):
74 add_cleanup = op.add_cleanup
75 fetch_spec_factory = fetch.FetchSpecFactory()
76 if revision_id is not None:
77
78=== modified file 'breezy/controldir.py'
79--- breezy/controldir.py 2018-04-15 12:14:06 +0000
80+++ breezy/controldir.py 2018-05-05 13:44:08 +0000
81@@ -375,7 +375,8 @@
82 def sprout(self, url, revision_id=None, force_new_repo=False,
83 recurse='down', possible_transports=None,
84 accelerator_tree=None, hardlink=False, stacked=False,
85- source_branch=None, create_tree_if_local=True):
86+ source_branch=None, create_tree_if_local=True,
87+ lossy=False):
88 """Create a copy of this controldir prepared for use as a new line of
89 development.
90
91@@ -401,8 +402,8 @@
92 """
93 raise NotImplementedError(self.sprout)
94
95- def push_branch(self, source, revision_id=None, overwrite=False,
96- remember=False, create_prefix=False):
97+ def push_branch(self, source, revision_id=None, overwrite=False,
98+ remember=False, create_prefix=False, lossy=False):
99 """Push the source branch into this ControlDir."""
100 br_to = None
101 # If we can open a branch, use its direct repository, otherwise see
102@@ -426,7 +427,7 @@
103 # revision
104 revision_id = source.last_revision()
105 repository_to.fetch(source.repository, revision_id=revision_id)
106- br_to = source.sprout(self, revision_id=revision_id)
107+ br_to = source.sprout(self, revision_id=revision_id, lossy=lossy)
108 if source.get_push_location() is None or remember:
109 # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
110 source.set_push_location(br_to.base)
111@@ -446,20 +447,18 @@
112 tree_to = self.open_workingtree()
113 except errors.NotLocalUrl:
114 push_result.branch_push_result = source.push(br_to,
115- overwrite, stop_revision=revision_id)
116+ overwrite, stop_revision=revision_id, lossy=lossy)
117 push_result.workingtree_updated = False
118 except errors.NoWorkingTree:
119 push_result.branch_push_result = source.push(br_to,
120- overwrite, stop_revision=revision_id)
121+ overwrite, stop_revision=revision_id, lossy=lossy)
122 push_result.workingtree_updated = None # Not applicable
123 else:
124- tree_to.lock_write()
125- try:
126+ with tree_to.lock_write():
127 push_result.branch_push_result = source.push(
128- tree_to.branch, overwrite, stop_revision=revision_id)
129+ tree_to.branch, overwrite, stop_revision=revision_id,
130+ lossy=lossy)
131 tree_to.update()
132- finally:
133- tree_to.unlock()
134 push_result.workingtree_updated = True
135 push_result.old_revno = push_result.branch_push_result.old_revno
136 push_result.old_revid = push_result.branch_push_result.old_revid
137
138=== modified file 'breezy/push.py'
139--- breezy/push.py 2017-07-23 17:17:18 +0000
140+++ breezy/push.py 2018-05-05 13:44:08 +0000
141@@ -61,7 +61,7 @@
142
143 def _show_push_branch(br_from, revision_id, location, to_file, verbose=False,
144 overwrite=False, remember=False, stacked_on=None, create_prefix=False,
145- use_existing_dir=False, no_tree=False):
146+ use_existing_dir=False, no_tree=False, lossy=False):
147 """Push a branch to a location.
148
149 :param br_from: the source branch
150@@ -79,6 +79,7 @@
151 at the destination if they don't already exist
152 :param use_existing_dir: if True, proceed even if the destination
153 directory exists without a current control directory in it
154+ :param lossy: Allow lossy push
155 """
156 to_transport = transport.get_transport(location)
157 try:
158@@ -143,8 +144,8 @@
159 warning("Ignoring request for a stacked branch as repository "
160 "already exists at the destination location.")
161 try:
162- push_result = dir_to.push_branch(br_from, revision_id, overwrite,
163- remember, create_prefix)
164+ push_result = dir_to.push_branch(br_from, revision_id, overwrite,
165+ remember, create_prefix, lossy=lossy)
166 except errors.DivergedBranches:
167 raise errors.BzrCommandError(gettext('These branches have diverged.'
168 ' See "brz help diverged-branches"'
169
170=== modified file 'breezy/tests/per_controldir/test_push.py'
171--- breezy/tests/per_controldir/test_push.py 2017-08-07 21:14:18 +0000
172+++ breezy/tests/per_controldir/test_push.py 2018-05-05 13:44:08 +0000
173@@ -16,6 +16,8 @@
174
175 """Tests for bzrdir implementations - push."""
176
177+from ...errors import LossyPushToSameVCS
178+
179 from breezy.tests.per_controldir import (
180 TestCaseWithControlDir,
181 )
182@@ -39,6 +41,12 @@
183 self.assertEqual(dir.open_branch().base,
184 tree.branch.get_push_location())
185
186+ def test_push_new_branch_lossy(self):
187+ tree, rev_1 = self.create_simple_tree()
188+ dir = self.make_repository('dir').controldir
189+ self.assertRaises(LossyPushToSameVCS, dir.push_branch,
190+ tree.branch, lossy=True)
191+
192 def test_push_new_empty(self):
193 tree = self.make_branch_and_tree('tree')
194 dir = self.make_repository('dir').controldir

Subscribers

People subscribed via source and target branches