40
50
def is_clean(cur_tree):
42
52
Return true if no files are modifed or unknown
44
>>> tree = temp_tree()
47
>>> fooname = os.path.join(tree.basedir, "foo")
48
>>> file(fooname, "wb").write("bar")
51
>>> bzrlib.add.smart_add_tree(tree, [tree.basedir])
55
>>> tree.commit("added file", rev_id='commit-id')
61
54
old_tree = cur_tree.basis_tree()
62
55
new_tree = cur_tree
64
for path, file_class, kind, file_id, entry in new_tree.list_files():
65
if file_class in ('?', 'I'):
66
non_source.append(path)
67
delta = new_tree.changes_from(old_tree, want_unchanged=False)
59
for path, file_class, kind, file_id, entry in new_tree.list_files():
60
if file_class in ('?', 'I'):
61
non_source.append(path)
62
delta = new_tree.changes_from(old_tree, want_unchanged=False)
68
65
return not delta.has_changed(), non_source
70
67
def set_push_data(tree, location):
189
187
raise RsyncUnknownStatus(proc.returncode)
190
188
return [l.split(' ')[-1].rstrip('\n') for l in result.splitlines(True)]
192
exclusions = ('.bzr/x-push-data', '.bzr/branch/x-push/data', '.bzr/parent',
190
exclusions = ('.bzr/x-push-data', '.bzr/branch/x-push/data', '.bzr/parent',
193
191
'.bzr/branch/parent', '.bzr/x-pull-data', '.bzr/x-pull',
194
192
'.bzr/pull', '.bzr/stat-cache', '.bzr/x-rsync-data',
195
193
'.bzr/basis-inventory', '.bzr/inventory.backup.weave')
207
205
def __init__(self):
208
206
Exception.__init__(self, "Error in rsync protocol data stream.")
210
def get_revision_history(location):
209
class NotStandalone(BzrError):
211
_format = '%(location) is not a standalone tree.'
214
def __init__(self, location):
215
BzrError.__init__(self, location=location)
218
def get_revision_history(location, _rsync):
211
219
tempdir = tempfile.mkdtemp('push')
213
224
history_fname = os.path.join(tempdir, 'revision-history')
215
cmd = rsync(location+'.bzr/revision-history', history_fname,
226
cmd = my_rsync(location+'.bzr/revision-history', history_fname,
217
228
except RsyncNoFile:
218
229
cmd = rsync(location+'.bzr/branch/revision-history', history_fname,
239
251
except RsyncNoFile:
242
def rspush(tree, location=None, overwrite=False, working_tree=True):
243
push_location = get_push_data(tree)
244
if location is not None:
245
if not location.endswith('/'):
247
push_location = location
249
if push_location is None:
250
raise BzrCommandError("No rspush location known or specified.")
252
if (push_location.find('::') != -1):
257
if (push_location.find('://') != -1 or
258
push_location.find(':') == -1):
259
raise BzrCommandError("Invalid rsync path %r." % push_location)
262
clean, non_source = is_clean(tree)
264
print """Error: This tree has uncommitted changes or unknown (?) files.
265
Use "bzr status" to list them."""
267
final_exclusions = non_source[:]
270
final_exclusions = []
271
for path, status, kind, file_id, entry in wt.list_files():
272
final_exclusions.append(path)
274
final_exclusions.extend(exclusions)
277
if not history_subset(push_location, tree.branch):
278
raise bzrlib.errors.BzrCommandError("Local branch is not a"
279
" newer version of remote"
282
if not empty_or_absent(push_location):
283
raise bzrlib.errors.BzrCommandError("Remote location is not a"
284
" bzr branch (or empty"
286
except RsyncStreamIO:
287
raise bzrlib.errors.BzrCommandError("Rsync could not use the"
288
" specified location. Please ensure that"
289
' "%s" is of the form "machine:/path".' % push_location)
290
print "Pushing to %s" % push_location
291
rsync(tree.basedir+'/', push_location, ssh=usessh,
292
excludes=final_exclusions)
294
set_push_data(tree, push_location)
254
def rspush(tree, location=None, overwrite=False, working_tree=True,
261
if (tree.bzrdir.root_transport.base !=
262
tree.branch.bzrdir.root_transport.base):
263
raise NotStandalone(tree.bzrdir.root_transport.base)
264
if (tree.branch.get_bound_location() is not None):
265
raise NotStandalone(tree.bzrdir.root_transport.base)
266
if (tree.branch.repository.is_shared()):
267
raise NotStandalone(tree.bzrdir.root_transport.base)
268
push_location = get_push_data(tree)
269
if location is not None:
270
if not location.endswith('/'):
272
push_location = location
274
if push_location is None:
275
raise BzrCommandError("No rspush location known or specified.")
277
if (push_location.find('::') != -1):
282
if (push_location.find('://') != -1 or
283
push_location.find(':') == -1):
284
raise BzrCommandError("Invalid rsync path %r." % push_location)
287
clean, non_source = is_clean(tree)
289
print ('Error: This tree has uncommitted changes or unknown'
290
' (?) files. Use "bzr status" to list them.')
292
final_exclusions = non_source[:]
295
final_exclusions = []
296
for path, status, kind, file_id, entry in wt.list_files():
297
final_exclusions.append(path)
299
final_exclusions.extend(exclusions)
302
if not history_subset(push_location, tree.branch,
304
raise bzrlib.errors.BzrCommandError(
305
"Local branch is not a newer version of remote"
308
if not empty_or_absent(push_location):
309
raise bzrlib.errors.BzrCommandError(
310
"Remote location is not a bzr branch (or empty"
312
except RsyncStreamIO:
313
raise bzrlib.errors.BzrCommandError("Rsync could not use the"
314
" specified location. Please ensure that"
315
' "%s" is of the form "machine:/path".' % push_location)
316
print "Pushing to %s" % push_location
317
my_rsync(tree.basedir+'/', push_location, ssh=usessh,
318
excludes=final_exclusions)
320
set_push_data(tree, push_location)
297
325
def short_committer(committer):