~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

[merge] bzr.dev 2255

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
# XXX: Can we do any better about making interrupted commits change
19
 
# nothing?  
20
 
 
21
 
# TODO: Separate 'prepare' phase where we find a list of potentially
22
 
# committed files.  We then can then pause the commit to prompt for a
23
 
# commit message, knowing the summary will be the same as what's
24
 
# actually used for the commit.  (But perhaps simpler to simply get
25
 
# the tree status, then use that for a selective commit?)
26
 
 
27
18
# The newly committed revision is going to have a shape corresponding
28
19
# to that of the working inventory.  Files that are not in the
29
20
# working tree and that were in the predecessor are reported as
55
46
# merges from, then it should still be reported as newly added
56
47
# relative to the basis revision.
57
48
 
58
 
# TODO: Do checks that the tree can be committed *before* running the 
59
 
# editor; this should include checks for a pointless commit and for 
60
 
# unknown or missing files.
61
 
 
62
 
# TODO: If commit fails, leave the message in a file somewhere.
63
 
 
64
49
# TODO: Change the parameter 'rev_id' to 'revision_id' to be consistent with
65
50
# the rest of the code; add a deprecation of the old name.
66
51
 
86
71
from bzrlib.testament import Testament
87
72
from bzrlib.trace import mutter, note, warning
88
73
from bzrlib.xml5 import serializer_v5
89
 
from bzrlib.inventory import Inventory, ROOT_ID, InventoryEntry
 
74
from bzrlib.inventory import Inventory, InventoryEntry
90
75
from bzrlib import symbol_versioning
91
76
from bzrlib.symbol_versioning import (deprecated_passed,
92
77
        deprecated_function,
93
78
        DEPRECATED_PARAMETER)
94
79
from bzrlib.workingtree import WorkingTree
 
80
import bzrlib.ui
95
81
 
96
82
 
97
83
class NullCommitReporter(object):
126
112
    def snapshot_change(self, change, path):
127
113
        if change == 'unchanged':
128
114
            return
 
115
        if change == 'added' and path == '':
 
116
            return
129
117
        note("%s %s", change, path)
130
118
 
131
119
    def completed(self, revno, rev_id):
182
170
               working_tree=None,
183
171
               local=False,
184
172
               reporter=None,
185
 
               config=None):
 
173
               config=None,
 
174
               message_callback=None):
186
175
        """Commit working copy as a new revision.
187
176
 
188
177
        branch -- the deprecated branch to commit to. New callers should pass in 
189
178
                  working_tree instead
190
179
 
191
 
        message -- the commit message, a mandatory parameter
 
180
        message -- the commit message (it or message_callback is required)
192
181
 
193
182
        timestamp -- if not None, seconds-since-epoch for a
194
183
             postdated/predated commit.
223
212
        else:
224
213
            self.work_tree = working_tree
225
214
            self.branch = self.work_tree.branch
226
 
        if message is None:
227
 
            raise BzrError("The message keyword parameter is required for commit().")
 
215
        if message_callback is None:
 
216
            if message is not None:
 
217
                if isinstance(message, str):
 
218
                    message = message.decode(bzrlib.user_encoding)
 
219
                message_callback = lambda x: message
 
220
            else:
 
221
                raise BzrError("The message or message_callback keyword"
 
222
                               " parameter is required for commit().")
228
223
 
229
224
        self.bound_branch = None
230
225
        self.local = local
270
265
                   
271
266
            if self.config is None:
272
267
                self.config = self.branch.get_config()
273
 
      
274
 
            if isinstance(message, str):
275
 
                message = message.decode(bzrlib.user_encoding)
276
 
            assert isinstance(message, unicode), type(message)
277
 
            self.message = message
278
 
            self._escape_commit_message()
279
268
 
280
269
            self.work_inv = self.work_tree.inventory
281
270
            self.basis_tree = self.work_tree.basis_tree()
315
304
            # that commit will succeed.
316
305
            self.builder.finish_inventory()
317
306
            self._emit_progress_update()
 
307
            message = message_callback(self)
 
308
            assert isinstance(message, unicode), type(message)
 
309
            self.message = message
 
310
            self._escape_commit_message()
 
311
 
318
312
            self.rev_id = self.builder.commit(self.message)
319
313
            self._emit_progress_update()
320
314
            # revision data is in the local branch now.
390
384
        # A merge with no effect on files
391
385
        if len(self.parents) > 1:
392
386
            return
 
387
        # work around the fact that a newly-initted tree does differ from its
 
388
        # basis
 
389
        if len(self.basis_inv) == 0 and len(self.builder.new_inventory) == 1:
 
390
            raise PointlessCommit()
393
391
        # Shortcut, if the number of entries changes, then we obviously have
394
392
        # a change
395
393
        if len(self.builder.new_inventory) != len(self.basis_inv):
550
548
        # in bugs like #46635.  Any reason not to use/enhance Tree.changes_from?
551
549
        # ADHB 11-07-2006
552
550
        mutter("Selecting files for commit with filter %s", self.specific_files)
 
551
        assert self.work_inv.root is not None
553
552
        entries = self.work_inv.iter_entries()
554
553
        if not self.builder.record_root_entry:
555
554
            symbol_versioning.warn('CommitBuilders should support recording'
574
573
                else:
575
574
                    # this entry is new and not being committed
576
575
                    continue
577
 
 
578
576
            self.builder.record_entry_contents(ie, self.parent_invs, 
579
577
                path, self.work_tree)
580
578
            # describe the nature of the change that has occurred relative to