/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/frontend/gtk/push.py

  • Committer: Jelmer Vernooij
  • Date: 2006-09-05 01:51:53 UTC
  • mto: (0.8.83 merge)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060905015153-e779872d12e94f47
Remove last few bits from backend and integrate them where necessary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
except:
29
29
    sys.exit(1)
30
30
 
31
 
import olive.backend.commit as commit
32
31
import bzrlib.errors as errors
33
 
import olive.backend.info as info
34
32
 
35
33
class OlivePush:
36
34
    """ Display Push dialog and perform the needed actions. """
70
68
        # Get stored location
71
69
        self.notbranch = False
72
70
        try:
73
 
            loc = info.get_push_location(self.comm.get_path())
 
71
            from bzrlib.branch import Branch
 
72
    
 
73
            branch = Branch.open_containing(self.comm.get_path())[0]
 
74
    
 
75
            self.entry_stored.set_text(branch.get_push_location())
74
76
        except errors.NotBranchError:
75
77
            self.notbranch = True
76
78
            return
77
 
 
78
 
        if loc is not None:
79
 
            self.entry_stored.set_text(loc)
80
79
    
81
80
    def display(self):
82
81
        """ Display the Push dialog. """
118
117
        self.comm.set_busy(self.window)
119
118
        if self.radio_stored.get_active():
120
119
            try:
121
 
                revs = commit.push(self.comm.get_path(),
 
120
                revs = do_push(self.comm.get_path(),
122
121
                                   overwrite=self.check_overwrite.get_active())
123
122
            except errors.NotBranchError:
124
123
                self.dialog.error_dialog(_('Directory is not a branch'),
146
145
                return
147
146
            
148
147
            try:
149
 
                revs = commit.push(self.comm.get_path(), location,
 
148
                revs = do_push(self.comm.get_path(), location,
150
149
                                   self.check_remember.get_active(),
151
150
                                   self.check_overwrite.get_active(),
152
151
                                   self.check_create.get_active())
208
207
    
209
208
    def close(self, widget=None):
210
209
        self.window.destroy()
 
210
 
 
211
def do_push(branch, location=None, remember=False, overwrite=False,
 
212
         create_prefix=False):
 
213
    """ Update a mirror of a branch.
 
214
    
 
215
    :param branch: the source branch
 
216
    
 
217
    :param location: the location of the branch that you'd like to update
 
218
    
 
219
    :param remember: if set, the location will be stored
 
220
    
 
221
    :param overwrite: overwrite target location if it diverged
 
222
    
 
223
    :param create_prefix: create the path leading up to the branch if it doesn't exist
 
224
    
 
225
    :return: number of revisions pushed
 
226
    """
 
227
    from bzrlib.branch import Branch
 
228
    from bzrlib.transport import get_transport
 
229
        
 
230
    br_from = Branch.open_containing(branch)[0]
 
231
    
 
232
    stored_loc = br_from.get_push_location()
 
233
    if location is None:
 
234
        if stored_loc is None:
 
235
            raise NoLocationKnown
 
236
        else:
 
237
            location = stored_loc
 
238
 
 
239
    transport = get_transport(location)
 
240
    location_url = transport.base
 
241
 
 
242
    if br_from.get_push_location() is None or remember:
 
243
        br_from.set_push_location(location_url)
 
244
 
 
245
    old_rh = []
 
246
 
 
247
    try:
 
248
        dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
 
249
        br_to = dir_to.open_branch()
 
250
    except NotBranchError:
 
251
        # create a branch.
 
252
        transport = transport.clone('..')
 
253
        if not create_prefix:
 
254
            try:
 
255
                relurl = transport.relpath(location_url)
 
256
                transport.mkdir(relurl)
 
257
            except NoSuchFile:
 
258
                raise NonExistingParent(location)
 
259
        else:
 
260
            current = transport.base
 
261
            needed = [(transport, transport.relpath(location_url))]
 
262
            while needed:
 
263
                try:
 
264
                    transport, relpath = needed[-1]
 
265
                    transport.mkdir(relpath)
 
266
                    needed.pop()
 
267
                except NoSuchFile:
 
268
                    new_transport = transport.clone('..')
 
269
                    needed.append((new_transport,
 
270
                                   new_transport.relpath(transport.base)))
 
271
                    if new_transport.base == transport.base:
 
272
                        raise PathPrefixNotCreated
 
273
        dir_to = br_from.bzrdir.clone(location_url,
 
274
            revision_id=br_from.last_revision())
 
275
        br_to = dir_to.open_branch()
 
276
        count = len(br_to.revision_history())
 
277
    else:
 
278
        old_rh = br_to.revision_history()
 
279
        try:
 
280
            try:
 
281
                tree_to = dir_to.open_workingtree()
 
282
            except NotLocalUrl:
 
283
                # FIXME - what to do here? how should we warn the user?
 
284
                #warning('This transport does not update the working '
 
285
                #        'tree of: %s' % (br_to.base,))
 
286
                count = br_to.pull(br_from, overwrite)
 
287
            except NoWorkingTree:
 
288
                count = br_to.pull(br_from, overwrite)
 
289
            else:
 
290
                count = tree_to.pull(br_from, overwrite)
 
291
        except DivergedBranches:
 
292
            raise DivergedBranchesError
 
293
    
 
294
    return count