285
283
:param lossy: When committing to a foreign VCS, ignore any
286
284
data that can not be natively represented.
288
with ExitStack() as stack:
289
self.revprops = revprops or {}
290
# XXX: Can be set on __init__ or passed in - this is a bit ugly.
291
self.config_stack = config or self.config_stack
292
mutter('preparing to commit')
294
if working_tree is None:
295
raise BzrError("working_tree must be passed into commit().")
297
self.work_tree = working_tree
298
self.branch = self.work_tree.branch
299
if getattr(self.work_tree, 'requires_rich_root', lambda: False)():
300
if not self.branch.repository.supports_rich_root():
301
raise errors.RootNotRich()
302
if message_callback is None:
303
if message is not None:
304
if isinstance(message, bytes):
305
message = message.decode(get_user_encoding())
307
def message_callback(x):
310
raise BzrError("The message or message_callback keyword"
311
" parameter is required for commit().")
313
self.bound_branch = None
314
self.any_entries_deleted = False
315
if exclude is not None:
316
self.exclude = sorted(
317
minimum_path_selection(exclude))
321
self.master_branch = None
322
self.recursive = recursive
324
# self.specific_files is None to indicate no filter, or any iterable to
325
# indicate a filter - [] means no files at all, as per iter_changes.
326
if specific_files is not None:
327
self.specific_files = sorted(
328
minimum_path_selection(specific_files))
330
self.specific_files = None
332
self.allow_pointless = allow_pointless
333
self.message_callback = message_callback
334
self.timestamp = timestamp
335
self.timezone = timezone
336
self.committer = committer
338
self.verbose = verbose
340
stack.enter_context(self.work_tree.lock_write())
341
self.parents = self.work_tree.get_parent_ids()
342
self.pb = ui.ui_factory.nested_progress_bar()
343
stack.callback(self.pb.finished)
344
self.basis_revid = self.work_tree.last_revision()
345
self.basis_tree = self.work_tree.basis_tree()
346
stack.enter_context(self.basis_tree.lock_read())
347
# Cannot commit with conflicts present.
348
if len(self.work_tree.conflicts()) > 0:
349
raise ConflictsInTree
351
# Setup the bound branch variables as needed.
352
self._check_bound_branch(stack, possible_master_transports)
353
if self.config_stack is None:
354
self.config_stack = self.work_tree.get_config_stack()
356
# Check that the working tree is up to date
357
old_revno, old_revid, new_revno = self._check_out_of_date_tree()
359
# Complete configuration setup
360
if reporter is not None:
361
self.reporter = reporter
362
elif self.reporter is None:
363
self.reporter = self._select_reporter()
365
# Setup the progress bar. As the number of files that need to be
366
# committed in unknown, progress is reported as stages.
367
# We keep track of entries separately though and include that
368
# information in the progress bar during the relevant stages.
369
self.pb_stage_name = ""
370
self.pb_stage_count = 0
371
self.pb_stage_total = 5
286
operation = OperationWithCleanups(self._commit)
287
self.revprops = revprops or {}
288
# XXX: Can be set on __init__ or passed in - this is a bit ugly.
289
self.config_stack = config or self.config_stack
290
return operation.run(
295
specific_files=specific_files,
297
allow_pointless=allow_pointless,
300
working_tree=working_tree,
303
message_callback=message_callback,
306
possible_master_transports=possible_master_transports,
309
def _commit(self, operation, message, timestamp, timezone, committer,
310
specific_files, rev_id, allow_pointless, strict, verbose,
311
working_tree, local, reporter, message_callback, recursive,
312
exclude, possible_master_transports, lossy):
313
mutter('preparing to commit')
315
if working_tree is None:
316
raise BzrError("working_tree must be passed into commit().")
318
self.work_tree = working_tree
319
self.branch = self.work_tree.branch
320
if getattr(self.work_tree, 'requires_rich_root', lambda: False)():
321
if not self.branch.repository.supports_rich_root():
322
raise errors.RootNotRich()
323
if message_callback is None:
324
if message is not None:
325
if isinstance(message, bytes):
326
message = message.decode(get_user_encoding())
327
message_callback = lambda x: message
329
raise BzrError("The message or message_callback keyword"
330
" parameter is required for commit().")
332
self.bound_branch = None
333
self.any_entries_deleted = False
334
if exclude is not None:
335
self.exclude = sorted(
336
minimum_path_selection(exclude))
340
self.master_branch = None
341
self.recursive = recursive
343
# self.specific_files is None to indicate no filter, or any iterable to
344
# indicate a filter - [] means no files at all, as per iter_changes.
345
if specific_files is not None:
346
self.specific_files = sorted(
347
minimum_path_selection(specific_files))
349
self.specific_files = None
351
self.allow_pointless = allow_pointless
352
self.message_callback = message_callback
353
self.timestamp = timestamp
354
self.timezone = timezone
355
self.committer = committer
357
self.verbose = verbose
359
self.work_tree.lock_write()
360
operation.add_cleanup(self.work_tree.unlock)
361
self.parents = self.work_tree.get_parent_ids()
362
self.pb = ui.ui_factory.nested_progress_bar()
363
operation.add_cleanup(self.pb.finished)
364
self.basis_revid = self.work_tree.last_revision()
365
self.basis_tree = self.work_tree.basis_tree()
366
self.basis_tree.lock_read()
367
operation.add_cleanup(self.basis_tree.unlock)
368
# Cannot commit with conflicts present.
369
if len(self.work_tree.conflicts()) > 0:
370
raise ConflictsInTree
372
# Setup the bound branch variables as needed.
373
self._check_bound_branch(operation, possible_master_transports)
375
# Check that the working tree is up to date
376
old_revno, old_revid, new_revno = self._check_out_of_date_tree()
378
# Complete configuration setup
379
if reporter is not None:
380
self.reporter = reporter
381
elif self.reporter is None:
382
self.reporter = self._select_reporter()
383
if self.config_stack is None:
384
self.config_stack = self.work_tree.get_config_stack()
386
# Setup the progress bar. As the number of files that need to be
387
# committed in unknown, progress is reported as stages.
388
# We keep track of entries separately though and include that
389
# information in the progress bar during the relevant stages.
390
self.pb_stage_name = ""
391
self.pb_stage_count = 0
392
self.pb_stage_total = 5
393
if self.bound_branch:
394
# 2 extra stages: "Uploading data to master branch" and "Merging
395
# tags to master branch"
396
self.pb_stage_total += 2
397
self.pb.show_pct = False
398
self.pb.show_spinner = False
399
self.pb.show_eta = False
400
self.pb.show_count = True
401
self.pb.show_bar = True
403
# After a merge, a selected file commit is not supported.
404
# See 'bzr help merge' for an explanation as to why.
405
if len(self.parents) > 1 and self.specific_files is not None:
406
raise CannotCommitSelectedFileMerge(self.specific_files)
407
# Excludes are a form of selected file commit.
408
if len(self.parents) > 1 and self.exclude:
409
raise CannotCommitSelectedFileMerge(self.exclude)
411
# Collect the changes
412
self._set_progress_stage("Collecting changes", counter=True)
414
self.builder = self.branch.get_commit_builder(self.parents,
415
self.config_stack, timestamp, timezone, committer, self.revprops,
418
if self.builder.updates_branch and self.bound_branch:
420
raise AssertionError(
421
"bound branches not supported for commit builders "
422
"that update the branch")
425
# find the location being committed to
372
426
if self.bound_branch:
373
# 2 extra stages: "Uploading data to master branch" and "Merging
374
# tags to master branch"
375
self.pb_stage_total += 2
376
self.pb.show_pct = False
377
self.pb.show_spinner = False
378
self.pb.show_eta = False
379
self.pb.show_count = True
380
self.pb.show_bar = True
382
# After a merge, a selected file commit is not supported.
383
# See 'bzr help merge' for an explanation as to why.
384
if len(self.parents) > 1 and self.specific_files is not None:
385
raise CannotCommitSelectedFileMerge(self.specific_files)
386
# Excludes are a form of selected file commit.
387
if len(self.parents) > 1 and self.exclude:
388
raise CannotCommitSelectedFileMerge(self.exclude)
390
# Collect the changes
391
self._set_progress_stage("Collecting changes", counter=True)
393
self.builder = self.branch.get_commit_builder(
394
self.parents, self.config_stack, timestamp, timezone, committer,
395
self.revprops, rev_id, lossy=lossy)
397
if self.builder.updates_branch and self.bound_branch:
399
raise AssertionError(
400
"bound branches not supported for commit builders "
401
"that update the branch")
404
# find the location being committed to
405
if self.bound_branch:
406
master_location = self.master_branch.base
408
master_location = self.branch.base
410
# report the start of the commit
411
self.reporter.started(new_revno, self.rev_id, master_location)
413
self._update_builder_with_changes()
414
self._check_pointless()
416
# TODO: Now the new inventory is known, check for conflicts.
417
# ADHB 2006-08-08: If this is done, populate_new_inv should not add
418
# weave lines, because nothing should be recorded until it is known
419
# that commit will succeed.
420
self._set_progress_stage("Saving data locally")
421
self.builder.finish_inventory()
423
# Prompt the user for a commit message if none provided
424
message = message_callback(self)
425
self.message = message
427
# Add revision data to the local branch
428
self.rev_id = self.builder.commit(self.message)
431
mutter("aborting commit write group because of exception:")
432
trace.log_exception_quietly()
436
self._update_branches(old_revno, old_revid, new_revno)
438
# Make the working tree be up to date with the branch. This
439
# includes automatic changes scheduled to be made to the tree, such
440
# as updating its basis and unversioning paths that were missing.
441
self.work_tree.unversion(self.deleted_paths)
442
self._set_progress_stage("Updating the working tree")
443
self.work_tree.update_basis_by_delta(self.rev_id,
444
self.builder.get_basis_delta())
445
self.reporter.completed(new_revno, self.rev_id)
446
self._process_post_hooks(old_revno, new_revno)
427
master_location = self.master_branch.base
429
master_location = self.branch.base
431
# report the start of the commit
432
self.reporter.started(new_revno, self.rev_id, master_location)
434
self._update_builder_with_changes()
435
self._check_pointless()
437
# TODO: Now the new inventory is known, check for conflicts.
438
# ADHB 2006-08-08: If this is done, populate_new_inv should not add
439
# weave lines, because nothing should be recorded until it is known
440
# that commit will succeed.
441
self._set_progress_stage("Saving data locally")
442
self.builder.finish_inventory()
444
# Prompt the user for a commit message if none provided
445
message = message_callback(self)
446
self.message = message
448
# Add revision data to the local branch
449
self.rev_id = self.builder.commit(self.message)
451
except Exception as e:
452
mutter("aborting commit write group because of exception:")
453
trace.log_exception_quietly()
457
self._update_branches(old_revno, old_revid, new_revno)
459
# Make the working tree be up to date with the branch. This
460
# includes automatic changes scheduled to be made to the tree, such
461
# as updating its basis and unversioning paths that were missing.
462
self.work_tree.unversion(self.deleted_paths)
463
self._set_progress_stage("Updating the working tree")
464
self.work_tree.update_basis_by_delta(self.rev_id,
465
self.builder.get_basis_delta())
466
self.reporter.completed(new_revno, self.rev_id)
467
self._process_post_hooks(old_revno, new_revno)
449
470
def _update_branches(self, old_revno, old_revid, new_revno):
450
471
"""Update the master and local branch to the new revision.