31
import olive.backend.commit as commit
32
import olive.backend.errors as errors
33
import olive.backend.info as info
31
import bzrlib.errors as errors
36
34
""" Display Push dialog and perform the needed actions. """
37
def __init__(self, gladefile, comm, dialog):
35
def __init__(self, gladefile, comm):
38
36
""" Initialize the Push dialog. """
39
37
self.gladefile = gladefile
40
38
self.glade = gtk.glade.XML(self.gladefile, 'window_push')
42
40
# Communication object
47
43
self.window = self.glade.get_widget('window_push')
71
67
self.entry_location.set_sensitive(0)
72
68
self.check_remember.set_sensitive(0)
73
69
self.check_create.set_sensitive(0)
75
71
# Get stored location
76
72
self.notbranch = False
78
loc = info.get_push_location(self.comm.get_path())
74
from bzrlib.branch import Branch
76
branch = Branch.open_containing(self.comm.get_path())[0]
78
self.entry_stored.set_text(branch.get_push_location())
79
79
except errors.NotBranchError:
80
80
self.notbranch = True
84
self.entry_stored.set_text(loc)
87
84
""" Display the Push dialog. """
89
self.dialog.error_dialog(_('Directory is not a branch'),
86
error_dialog(_('Directory is not a branch'),
90
87
_('You can perform this action only in a branch.'))
122
119
self.comm.set_busy(self.window)
123
120
if self.radio_stored.get_active():
125
revs = commit.push(self.comm.get_path(),
126
overwrite=self.check_overwrite.get_active())
122
revs = do_push(self.comm.get_path(),
123
overwrite=self.check_overwrite.get_active())
127
124
except errors.NotBranchError:
128
self.dialog.error_dialog(_('Directory is not a branch'),
125
error_dialog(_('Directory is not a branch'),
129
126
_('You can perform this action only in a branch.'))
131
except errors.NoLocationKnown:
132
self.dialog.error_dialog(_('Push location is unknown'),
133
_('Please specify a location manually.'))
135
except errors.NonExistingParent, errmsg:
136
self.dialog.error_dialog(_('Non existing parent directory'),
137
_("The parent directory (%s)\ndoesn't exist.") % errmsg)
139
except errors.DivergedBranchesError:
140
self.dialog.error_dialog(_('Branches have been diverged'),
128
except errors.DivergedBranches:
129
error_dialog(_('Branches have been diverged'),
141
130
_('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
145
134
elif self.radio_specific.get_active():
146
135
location = self.entry_location.get_text()
147
136
if location == '':
148
self.dialog.error_dialog(_('No location specified'),
137
error_dialog(_('No location specified'),
149
138
_('Please specify a location or use the default.'))
153
revs = commit.push(self.comm.get_path(), location,
154
self.check_remember.get_active(),
155
self.check_overwrite.get_active(),
156
self.check_create.get_active())
142
revs = do_push(self.comm.get_path(), location,
143
self.check_remember.get_active(),
144
self.check_overwrite.get_active(),
145
self.check_create.get_active())
157
146
except errors.NotBranchError:
158
self.dialog.error_dialog(_('Directory is not a branch'),
147
error_dialog(_('Directory is not a branch'),
159
148
_('You can perform this action only in a branch.'))
160
149
self.comm.set_busy(self.window, False)
162
except errors.NonExistingParent, errmsg:
163
self.dialog.error_dialog(_('Non existing parent directory'),
164
_("The parent directory (%s)\ndoesn't exist.") % errmsg)
165
self.comm.set_busy(self.window, False)
167
except errors.DivergedBranchesError:
168
self.dialog.error_dialog(_('Branches have been diverged'),
151
except errors.DivergedBranches:
152
error_dialog(_('Branches have been diverged'),
169
153
_('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
170
154
self.comm.set_busy(self.window, False)
172
except errors.PathPrefixNotCreated:
173
self.dialog.error_dialog(_('Path prefix not created'),
174
_("The path leading up to the specified location couldn't\nbe created."))
175
self.comm.set_busy(self.window, False)
213
192
def close(self, widget=None):
214
193
self.window.destroy()
195
def do_push(branch, location=None, remember=False, overwrite=False,
196
create_prefix=False):
197
""" Update a mirror of a branch.
199
:param branch: the source branch
201
:param location: the location of the branch that you'd like to update
203
:param remember: if set, the location will be stored
205
:param overwrite: overwrite target location if it diverged
207
:param create_prefix: create the path leading up to the branch if it doesn't exist
209
:return: number of revisions pushed
211
from bzrlib.branch import Branch
212
from bzrlib.bzrdir import BzrDir
213
from bzrlib.transport import get_transport
215
br_from = Branch.open_containing(branch)[0]
217
stored_loc = br_from.get_push_location()
219
if stored_loc is None:
220
error_dialog(_('Push location is unknown'),
221
_('Please specify a location manually.'))
224
location = stored_loc
226
transport = get_transport(location)
227
location_url = transport.base
229
if br_from.get_push_location() is None or remember:
230
br_from.set_push_location(location_url)
235
dir_to = BzrDir.open(location_url)
236
br_to = dir_to.open_branch()
237
except errors.NotBranchError:
239
transport = transport.clone('..')
240
if not create_prefix:
242
relurl = transport.relpath(location_url)
243
transport.mkdir(relurl)
244
except errors.NoSuchFile:
245
error_dialog(_('Non existing parent directory'),
246
_("The parent directory (%s)\ndoesn't exist.") % location)
249
current = transport.base
250
needed = [(transport, transport.relpath(location_url))]
253
transport, relpath = needed[-1]
254
transport.mkdir(relpath)
256
except errors.NoSuchFile:
257
new_transport = transport.clone('..')
258
needed.append((new_transport,
259
new_transport.relpath(transport.base)))
260
if new_transport.base == transport.base:
261
error_dialog(_('Path prefix not created'),
262
_("The path leading up to the specified location couldn't\nbe created."))
264
dir_to = br_from.bzrdir.clone(location_url,
265
revision_id=br_from.last_revision())
266
br_to = dir_to.open_branch()
267
count = len(br_to.revision_history())
269
old_rh = br_to.revision_history()
272
tree_to = dir_to.open_workingtree()
273
except errors.NotLocalUrl:
274
# FIXME - what to do here? how should we warn the user?
275
#warning('This transport does not update the working '
276
# 'tree of: %s' % (br_to.base,))
277
count = br_to.pull(br_from, overwrite)
278
except errors.NoWorkingTree:
279
count = br_to.pull(br_from, overwrite)
281
count = tree_to.pull(br_from, overwrite)
282
except errors.DivergedBranches: