21
21
pygtk.require("2.0")
31
import olive.backend.commit as commit
32
import olive.backend.errors as errors
33
import olive.backend.info as info
29
import bzrlib.errors as errors
31
from olive import gladefile
36
34
""" Display Push dialog and perform the needed actions. """
37
def __init__(self, gladefile, comm, dialog):
35
def __init__(self, comm):
38
36
""" Initialize the Push dialog. """
39
self.gladefile = gladefile
40
self.glade = gtk.glade.XML(self.gladefile, 'window_push')
37
self.glade = gtk.glade.XML(gladefile, 'window_push')
42
39
# Communication object
47
42
self.window = self.glade.get_widget('window_push')
71
66
self.entry_location.set_sensitive(0)
72
67
self.check_remember.set_sensitive(0)
73
68
self.check_create.set_sensitive(0)
75
70
# Get stored location
76
71
self.notbranch = False
78
loc = info.get_push_location(self.comm.get_path())
73
from bzrlib.branch import Branch
75
branch = Branch.open_containing(self.comm.get_path())[0]
77
self.entry_stored.set_text(branch.get_push_location())
79
78
except errors.NotBranchError:
80
79
self.notbranch = True
84
self.entry_stored.set_text(loc)
87
83
""" Display the Push dialog. """
89
self.dialog.error_dialog(_('Directory is not a branch'),
85
error_dialog(_('Directory is not a branch'),
90
86
_('You can perform this action only in a branch.'))
122
118
self.comm.set_busy(self.window)
123
119
if self.radio_stored.get_active():
125
revs = commit.push(self.comm.get_path(),
126
overwrite=self.check_overwrite.get_active())
121
revs = do_push(self.comm.get_path(),
122
overwrite=self.check_overwrite.get_active())
127
123
except errors.NotBranchError:
128
self.dialog.error_dialog(_('Directory is not a branch'),
124
error_dialog(_('Directory is not a branch'),
129
125
_('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'),
127
except errors.DivergedBranches:
128
error_dialog(_('Branches have been diverged'),
141
129
_('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
145
133
elif self.radio_specific.get_active():
146
134
location = self.entry_location.get_text()
147
135
if location == '':
148
self.dialog.error_dialog(_('No location specified'),
136
error_dialog(_('No location specified'),
149
137
_('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())
141
revs = do_push(self.comm.get_path(), location,
142
self.check_remember.get_active(),
143
self.check_overwrite.get_active(),
144
self.check_create.get_active())
157
145
except errors.NotBranchError:
158
self.dialog.error_dialog(_('Directory is not a branch'),
146
error_dialog(_('Directory is not a branch'),
159
147
_('You can perform this action only in a branch.'))
160
148
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'),
150
except errors.DivergedBranches:
151
error_dialog(_('Branches have been diverged'),
169
152
_('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
170
153
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
191
def close(self, widget=None):
214
192
self.window.destroy()
194
def do_push(branch, location=None, remember=False, overwrite=False,
195
create_prefix=False):
196
""" Update a mirror of a branch.
198
:param branch: the source branch
200
:param location: the location of the branch that you'd like to update
202
:param remember: if set, the location will be stored
204
:param overwrite: overwrite target location if it diverged
206
:param create_prefix: create the path leading up to the branch if it doesn't exist
208
:return: number of revisions pushed
210
from bzrlib.branch import Branch
211
from bzrlib.bzrdir import BzrDir
212
from bzrlib.transport import get_transport
214
br_from = Branch.open_containing(branch)[0]
216
stored_loc = br_from.get_push_location()
218
if stored_loc is None:
219
error_dialog(_('Push location is unknown'),
220
_('Please specify a location manually.'))
223
location = stored_loc
225
transport = get_transport(location)
226
location_url = transport.base
228
if br_from.get_push_location() is None or remember:
229
br_from.set_push_location(location_url)
234
dir_to = BzrDir.open(location_url)
235
br_to = dir_to.open_branch()
236
except errors.NotBranchError:
238
transport = transport.clone('..')
239
if not create_prefix:
241
relurl = transport.relpath(location_url)
242
transport.mkdir(relurl)
243
except errors.NoSuchFile:
244
error_dialog(_('Non existing parent directory'),
245
_("The parent directory (%s)\ndoesn't exist.") % location)
248
current = transport.base
249
needed = [(transport, transport.relpath(location_url))]
252
transport, relpath = needed[-1]
253
transport.mkdir(relpath)
255
except errors.NoSuchFile:
256
new_transport = transport.clone('..')
257
needed.append((new_transport,
258
new_transport.relpath(transport.base)))
259
if new_transport.base == transport.base:
260
error_dialog(_('Path prefix not created'),
261
_("The path leading up to the specified location couldn't\nbe created."))
263
dir_to = br_from.bzrdir.clone(location_url,
264
revision_id=br_from.last_revision())
265
br_to = dir_to.open_branch()
266
count = len(br_to.revision_history())
268
old_rh = br_to.revision_history()
271
tree_to = dir_to.open_workingtree()
272
except errors.NotLocalUrl:
273
# FIXME - what to do here? how should we warn the user?
274
#warning('This transport does not update the working '
275
# 'tree of: %s' % (br_to.base,))
276
count = br_to.pull(br_from, overwrite)
277
except errors.NoWorkingTree:
278
count = br_to.pull(br_from, overwrite)
280
count = tree_to.pull(br_from, overwrite)
281
except errors.DivergedBranches: