1
1
# Copyright (C) 2005, 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
18
18
# XXX: Can we do any better about making interrupted commits change
19
# nothing? Perhaps the best approach is to integrate commit of
20
# AtomicFiles with releasing the lock on the Branch.
22
21
# TODO: Separate 'prepare' phase where we find a list of potentially
23
22
# committed files. We then can then pause the commit to prompt for a
72
70
from cStringIO import StringIO
74
from bzrlib.atomicfile import AtomicFile
75
72
import bzrlib.config
76
73
import bzrlib.errors as errors
77
74
from bzrlib.errors import (BzrError, PointlessCommit,
85
82
from bzrlib.trace import mutter, note, warning
86
83
from bzrlib.xml5 import serializer_v5
87
84
from bzrlib.inventory import Inventory, ROOT_ID, InventoryEntry
85
from bzrlib import symbol_versioning
88
86
from bzrlib.symbol_versioning import (deprecated_passed,
89
87
deprecated_function,
91
88
DEPRECATED_PARAMETER)
92
89
from bzrlib.workingtree import WorkingTree
95
@deprecated_function(zero_seven)
96
def commit(*args, **kwargs):
97
"""Commit a new revision to a branch.
99
Function-style interface for convenience of old callers.
101
New code should use the Commit class instead.
103
## XXX: Remove this in favor of WorkingTree.commit?
104
Commit().commit(*args, **kwargs)
107
92
class NullCommitReporter(object):
108
93
"""I report on progress of a commit."""
223
208
mutter('preparing to commit')
225
210
if deprecated_passed(branch):
226
warnings.warn("Commit.commit (branch, ...): The branch parameter is "
211
symbol_versioning.warn("Commit.commit (branch, ...): The branch parameter is "
227
212
"deprecated as of bzr 0.8. Please use working_tree= instead.",
228
213
DeprecationWarning, stacklevel=2)
229
214
self.branch = branch
308
293
raise PointlessCommit()
310
295
self._emit_progress_update()
311
# TODO: Now the new inventory is known, check for conflicts and prompt the
312
# user for a commit message.
296
# TODO: Now the new inventory is known, check for conflicts and
297
# prompt the user for a commit message.
298
# ADHB 2006-08-08: If this is done, populate_new_inv should not add
299
# weave lines, because nothing should be recorded until it is known
300
# that commit will succeed.
313
301
self.builder.finish_inventory()
314
302
self._emit_progress_update()
315
303
self.rev_id = self.builder.commit(self.message)
500
488
# ESEPARATIONOFCONCERNS: this function is diffing and using the diff
501
489
# results to create a new inventory at the same time, which results
502
# in bugs like #46635. Any reason not to use/enhance compare_trees?
490
# in bugs like #46635. Any reason not to use/enhance Tree.changes_from?
503
491
# ADHB 11-07-2006
504
492
mutter("Selecting files for commit with filter %s", self.specific_files)
505
# iter_entries does not visit the ROOT_ID node so we need to call
506
# self._emit_progress_update once by hand.
507
self._emit_progress_update()
508
for path, new_ie in self.work_inv.iter_entries():
493
entries = self.work_inv.iter_entries()
494
if not self.builder.record_root_entry:
495
symbol_versioning.warn('CommitBuilders should support recording'
496
' the root entry as of bzr 0.10.', DeprecationWarning,
498
self.builder.new_inventory.add(self.basis_inv.root.copy())
500
self._emit_progress_update()
501
for path, new_ie in entries:
509
502
self._emit_progress_update()
510
503
file_id = new_ie.file_id
511
mutter('check %s {%s}', path, file_id)
504
# mutter('check %s {%s}', path, file_id)
512
505
if (not self.specific_files or
513
506
is_inside_or_parent_of_any(self.specific_files, path)):
514
mutter('%s selected for commit', path)
507
# mutter('%s selected for commit', path)
515
508
ie = new_ie.copy()
516
509
ie.revision = None
518
mutter('%s not selected for commit', path)
511
# mutter('%s not selected for commit', path)
519
512
if self.basis_inv.has_id(file_id):
520
513
ie = self.basis_inv[file_id].copy()