/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/push.py

  • Committer: Jelmer Vernooij
  • Date: 2006-09-13 20:19:31 UTC
  • mfrom: (0.8.79 main)
  • mto: (0.8.83 merge)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060913201931-23adba246d4d6529
Merge main branch.

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