~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to bzrtools.py

  • Committer: Aaron Bentley
  • Date: 2007-11-02 01:46:04 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20071102014604-m8l88pwuglbntz7l
rspush requires standalone trees

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import bzrlib
27
27
from bzrlib import urlutils
28
28
import bzrlib.errors
29
 
from bzrlib.errors import (BzrCommandError, NotBranchError, NoSuchFile,
30
 
                           UnsupportedFormatError, TransportError,
31
 
                           NoWorkingTree, PermissionDenied, ConnectionError)
 
29
from bzrlib.errors import (
 
30
    BzrCommandError,
 
31
    BzrError,
 
32
    ConnectionError,
 
33
    NotBranchError,
 
34
    NoSuchFile,
 
35
    NoWorkingTree,
 
36
    PermissionDenied,
 
37
    UnsupportedFormatError,
 
38
    TransportError,
 
39
    )
32
40
from bzrlib.bzrdir import BzrDir, BzrDirFormat
33
41
from bzrlib.transport import get_transport
34
42
 
101
109
    def __init__(self, rsync_name):
102
110
        Exception.__init__(self, "%s not found." % rsync_name)
103
111
 
 
112
 
104
113
def rsync(source, target, ssh=False, excludes=(), silent=False,
105
114
          rsync_name="rsync"):
106
115
    """
196
205
    def __init__(self):
197
206
        Exception.__init__(self, "Error in rsync protocol data stream.")
198
207
 
199
 
def get_revision_history(location):
 
208
 
 
209
class NotStandalone(BzrError):
 
210
 
 
211
    _format = '%(location) is not a standalone tree.'
 
212
    _internal = False
 
213
 
 
214
    def __init__(self, location):
 
215
        BzrError.__init__(self, location=location)
 
216
 
 
217
 
 
218
def get_revision_history(location, _rsync):
200
219
    tempdir = tempfile.mkdtemp('push')
 
220
    my_rsync = _rsync
 
221
    if my_rsync is None:
 
222
        my_rsync = rsync
201
223
    try:
202
224
        history_fname = os.path.join(tempdir, 'revision-history')
203
225
        try:
204
 
            cmd = rsync(location+'.bzr/revision-history', history_fname,
 
226
            cmd = my_rsync(location+'.bzr/revision-history', history_fname,
205
227
                        silent=True)
206
228
        except RsyncNoFile:
207
229
            cmd = rsync(location+'.bzr/branch/revision-history', history_fname,
211
233
        shutil.rmtree(tempdir)
212
234
    return history
213
235
 
214
 
def history_subset(location, branch):
215
 
    remote_history = get_revision_history(location)
 
236
 
 
237
def history_subset(location, branch, _rsync=None):
 
238
    remote_history = get_revision_history(location, _rsync)
216
239
    local_history = branch.revision_history()
217
240
    if len(remote_history) > len(local_history):
218
241
        return False
228
251
    except RsyncNoFile:
229
252
        return True
230
253
 
231
 
def rspush(tree, location=None, overwrite=False, working_tree=True):
 
254
def rspush(tree, location=None, overwrite=False, working_tree=True,
 
255
    _rsync=None):
 
256
    my_rsync = _rsync
 
257
    if my_rsync is None:
 
258
        my_rsync = rsync
 
259
    if (tree.bzrdir.root_transport.base !=
 
260
        tree.branch.bzrdir.root_transport.base):
 
261
        raise NotStandalone(tree.bzrdir.root_transport.base)
 
262
    if (tree.branch.get_bound_location() is not None):
 
263
        raise NotStandalone(tree.bzrdir.root_transport.base)
 
264
    if (tree.branch.repository.is_shared()):
 
265
        raise NotStandalone(tree.bzrdir.root_transport.base)
232
266
    push_location = get_push_data(tree)
233
267
    if location is not None:
234
268
        if not location.endswith('/'):
263
297
    final_exclusions.extend(exclusions)
264
298
    if not overwrite:
265
299
        try:
266
 
            if not history_subset(push_location, tree.branch):
 
300
            if not history_subset(push_location, tree.branch, _rsync=my_rsync):
267
301
                raise bzrlib.errors.BzrCommandError("Local branch is not a"
268
302
                                                    " newer version of remote"
269
303
                                                    " branch.")
277
311
                " specified location.  Please ensure that"
278
312
                ' "%s" is of the form "machine:/path".' % push_location)
279
313
    print "Pushing to %s" % push_location
280
 
    rsync(tree.basedir+'/', push_location, ssh=usessh,
 
314
    my_rsync(tree.basedir+'/', push_location, ssh=usessh,
281
315
          excludes=final_exclusions)
282
316
 
283
317
    set_push_data(tree, push_location)