~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Martin Packman
  • Date: 2012-03-27 17:32:19 UTC
  • mto: (6437.54.3 2.5)
  • mto: This revision was merged to the branch mainline in revision 6525.
  • Revision ID: martin.packman@canonical.com-20120327173219-401pil42gke8j0xh
Fall back to sys.prefix not /usr when looking for .mo files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
17
18
 
18
19
# The newly committed revision is going to have a shape corresponding
19
20
# to that of the working tree.  Files that are not in the
49
50
# TODO: Change the parameter 'rev_id' to 'revision_id' to be consistent with
50
51
# the rest of the code; add a deprecation of the old name.
51
52
 
52
 
import os
53
 
import re
54
 
import sys
55
 
import time
56
 
 
57
 
from cStringIO import StringIO
58
 
 
59
53
from bzrlib import (
60
54
    debug,
61
55
    errors,
62
 
    revision,
63
56
    trace,
64
57
    tree,
65
 
    xml_serializer,
 
58
    ui,
66
59
    )
67
60
from bzrlib.branch import Branch
 
61
from bzrlib.cleanup import OperationWithCleanups
68
62
import bzrlib.config
69
63
from bzrlib.errors import (BzrError, PointlessCommit,
70
64
                           ConflictsInTree,
71
65
                           StrictCommitFailed
72
66
                           )
73
67
from bzrlib.osutils import (get_user_encoding,
74
 
                            kind_marker, isdir,isfile, is_inside_any,
75
 
                            is_inside_or_parent_of_any,
 
68
                            is_inside_any,
76
69
                            minimum_path_selection,
77
 
                            quotefn, sha_file, split_lines,
78
70
                            splitpath,
79
71
                            )
80
 
from bzrlib.testament import Testament
81
 
from bzrlib.trace import mutter, note, warning, is_quiet
 
72
from bzrlib.trace import mutter, note, is_quiet
82
73
from bzrlib.inventory import Inventory, InventoryEntry, make_entry
83
74
from bzrlib import symbol_versioning
84
 
from bzrlib.symbol_versioning import (deprecated_passed,
85
 
        deprecated_function,
86
 
        DEPRECATED_PARAMETER)
87
 
from bzrlib.workingtree import WorkingTree
88
75
from bzrlib.urlutils import unescape_for_display
89
 
import bzrlib.ui
90
 
 
 
76
from bzrlib.i18n import gettext
91
77
 
92
78
class NullCommitReporter(object):
93
79
    """I report on progress of a commit."""
128
114
        note(format, *args)
129
115
 
130
116
    def snapshot_change(self, change, path):
131
 
        if path == '' and change in ('added', 'modified'):
 
117
        if path == '' and change in (gettext('added'), gettext('modified')):
132
118
            return
133
119
        self._note("%s %s", change, path)
134
120
 
142
128
                                   "to started.", DeprecationWarning,
143
129
                                   stacklevel=2)
144
130
            location = ''
145
 
        self._note('Committing%s', location)
 
131
        self._note(gettext('Committing%s'), location)
146
132
 
147
133
    def completed(self, revno, rev_id):
148
 
        self._note('Committed revision %d.', revno)
 
134
        self._note(gettext('Committed revision %d.'), revno)
 
135
        # self._note goes to the console too; so while we want to log the
 
136
        # rev_id, we can't trivially only log it. (See bug 526425). Long
 
137
        # term we should rearrange the reporting structure, but for now
 
138
        # we just mutter seperately. We mutter the revid and revno together
 
139
        # so that concurrent bzr invocations won't lead to confusion.
 
140
        mutter('Committed revid %s as revno %d.', rev_id, revno)
149
141
 
150
142
    def deleted(self, path):
151
 
        self._note('deleted %s', path)
 
143
        self._note(gettext('deleted %s'), path)
152
144
 
153
145
    def missing(self, path):
154
 
        self._note('missing %s', path)
 
146
        self._note(gettext('missing %s'), path)
155
147
 
156
148
    def renamed(self, change, old_path, new_path):
157
149
        self._note('%s %s => %s', change, old_path, new_path)
174
166
    """
175
167
    def __init__(self,
176
168
                 reporter=None,
177
 
                 config=None):
 
169
                 config_stack=None):
178
170
        """Create a Commit object.
179
171
 
180
172
        :param reporter: the default reporter to use or None to decide later
181
173
        """
182
174
        self.reporter = reporter
183
 
        self.config = config
 
175
        self.config_stack = config_stack
 
176
 
 
177
    @staticmethod
 
178
    def update_revprops(revprops, branch, authors=None, author=None,
 
179
                        local=False, possible_master_transports=None):
 
180
        if revprops is None:
 
181
            revprops = {}
 
182
        if possible_master_transports is None:
 
183
            possible_master_transports = []
 
184
        if not 'branch-nick' in revprops:
 
185
            revprops['branch-nick'] = branch._get_nick(
 
186
                local,
 
187
                possible_master_transports)
 
188
        if authors is not None:
 
189
            if author is not None:
 
190
                raise AssertionError('Specifying both author and authors '
 
191
                        'is not allowed. Specify just authors instead')
 
192
            if 'author' in revprops or 'authors' in revprops:
 
193
                # XXX: maybe we should just accept one of them?
 
194
                raise AssertionError('author property given twice')
 
195
            if authors:
 
196
                for individual in authors:
 
197
                    if '\n' in individual:
 
198
                        raise AssertionError('\\n is not a valid character '
 
199
                                'in an author identity')
 
200
                revprops['authors'] = '\n'.join(authors)
 
201
        if author is not None:
 
202
            symbol_versioning.warn('The parameter author was deprecated'
 
203
                   ' in version 1.13. Use authors instead',
 
204
                   DeprecationWarning)
 
205
            if 'author' in revprops or 'authors' in revprops:
 
206
                # XXX: maybe we should just accept one of them?
 
207
                raise AssertionError('author property given twice')
 
208
            if '\n' in author:
 
209
                raise AssertionError('\\n is not a valid character '
 
210
                        'in an author identity')
 
211
            revprops['authors'] = author
 
212
        return revprops
184
213
 
185
214
    def commit(self,
186
215
               message=None,
200
229
               message_callback=None,
201
230
               recursive='down',
202
231
               exclude=None,
203
 
               possible_master_transports=None):
 
232
               possible_master_transports=None,
 
233
               lossy=False):
204
234
        """Commit working copy as a new revision.
205
235
 
206
236
        :param message: the commit message (it or message_callback is required)
 
237
        :param message_callback: A callback: message = message_callback(cmt_obj)
207
238
 
208
239
        :param timestamp: if not None, seconds-since-epoch for a
209
240
            postdated/predated commit.
210
241
 
211
 
        :param specific_files: If true, commit only those files.
 
242
        :param specific_files: If not None, commit only those files. An empty
 
243
            list means 'commit no files'.
212
244
 
213
245
        :param rev_id: If set, use this as the new revision id.
214
246
            Useful for test or import commands that need to tightly
231
263
        :param exclude: None or a list of relative paths to exclude from the
232
264
            commit. Pending changes to excluded files will be ignored by the
233
265
            commit.
 
266
        :param lossy: When committing to a foreign VCS, ignore any
 
267
            data that can not be natively represented.
234
268
        """
 
269
        operation = OperationWithCleanups(self._commit)
 
270
        self.revprops = revprops or {}
 
271
        # XXX: Can be set on __init__ or passed in - this is a bit ugly.
 
272
        self.config_stack = config or self.config_stack
 
273
        return operation.run(
 
274
               message=message,
 
275
               timestamp=timestamp,
 
276
               timezone=timezone,
 
277
               committer=committer,
 
278
               specific_files=specific_files,
 
279
               rev_id=rev_id,
 
280
               allow_pointless=allow_pointless,
 
281
               strict=strict,
 
282
               verbose=verbose,
 
283
               working_tree=working_tree,
 
284
               local=local,
 
285
               reporter=reporter,
 
286
               message_callback=message_callback,
 
287
               recursive=recursive,
 
288
               exclude=exclude,
 
289
               possible_master_transports=possible_master_transports,
 
290
               lossy=lossy)
 
291
 
 
292
    def _commit(self, operation, message, timestamp, timezone, committer,
 
293
            specific_files, rev_id, allow_pointless, strict, verbose,
 
294
            working_tree, local, reporter, message_callback, recursive,
 
295
            exclude, possible_master_transports, lossy):
235
296
        mutter('preparing to commit')
236
297
 
237
298
        if working_tree is None:
260
321
            self.exclude = []
261
322
        self.local = local
262
323
        self.master_branch = None
263
 
        self.master_locked = False
264
324
        self.recursive = recursive
265
325
        self.rev_id = None
 
326
        # self.specific_files is None to indicate no filter, or any iterable to
 
327
        # indicate a filter - [] means no files at all, as per iter_changes.
266
328
        if specific_files is not None:
267
329
            self.specific_files = sorted(
268
330
                minimum_path_selection(specific_files))
269
331
        else:
270
332
            self.specific_files = None
271
 
            
 
333
 
272
334
        self.allow_pointless = allow_pointless
273
 
        self.revprops = revprops
274
335
        self.message_callback = message_callback
275
336
        self.timestamp = timestamp
276
337
        self.timezone = timezone
279
340
        self.verbose = verbose
280
341
 
281
342
        self.work_tree.lock_write()
 
343
        operation.add_cleanup(self.work_tree.unlock)
282
344
        self.parents = self.work_tree.get_parent_ids()
283
345
        # We can use record_iter_changes IFF iter_changes is compatible with
284
346
        # the command line parameters, and the repository has fast delta
285
347
        # generation. See bug 347649.
286
348
        self.use_record_iter_changes = (
287
 
            not self.specific_files and
288
349
            not self.exclude and 
289
350
            not self.branch.repository._format.supports_tree_reference and
290
351
            (self.branch.repository._format.fast_deltas or
291
352
             len(self.parents) < 2))
292
 
        self.pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
353
        self.pb = ui.ui_factory.nested_progress_bar()
 
354
        operation.add_cleanup(self.pb.finished)
293
355
        self.basis_revid = self.work_tree.last_revision()
294
356
        self.basis_tree = self.work_tree.basis_tree()
295
357
        self.basis_tree.lock_read()
 
358
        operation.add_cleanup(self.basis_tree.unlock)
 
359
        # Cannot commit with conflicts present.
 
360
        if len(self.work_tree.conflicts()) > 0:
 
361
            raise ConflictsInTree
 
362
 
 
363
        # Setup the bound branch variables as needed.
 
364
        self._check_bound_branch(operation, possible_master_transports)
 
365
 
 
366
        # Check that the working tree is up to date
 
367
        old_revno, old_revid, new_revno = self._check_out_of_date_tree()
 
368
 
 
369
        # Complete configuration setup
 
370
        if reporter is not None:
 
371
            self.reporter = reporter
 
372
        elif self.reporter is None:
 
373
            self.reporter = self._select_reporter()
 
374
        if self.config_stack is None:
 
375
            self.config_stack = self.branch.get_config_stack()
 
376
 
 
377
        self._set_specific_file_ids()
 
378
 
 
379
        # Setup the progress bar. As the number of files that need to be
 
380
        # committed in unknown, progress is reported as stages.
 
381
        # We keep track of entries separately though and include that
 
382
        # information in the progress bar during the relevant stages.
 
383
        self.pb_stage_name = ""
 
384
        self.pb_stage_count = 0
 
385
        self.pb_stage_total = 5
 
386
        if self.bound_branch:
 
387
            # 2 extra stages: "Uploading data to master branch" and "Merging
 
388
            # tags to master branch"
 
389
            self.pb_stage_total += 2
 
390
        self.pb.show_pct = False
 
391
        self.pb.show_spinner = False
 
392
        self.pb.show_eta = False
 
393
        self.pb.show_count = True
 
394
        self.pb.show_bar = True
 
395
 
 
396
        self._gather_parents()
 
397
        # After a merge, a selected file commit is not supported.
 
398
        # See 'bzr help merge' for an explanation as to why.
 
399
        if len(self.parents) > 1 and self.specific_files is not None:
 
400
            raise errors.CannotCommitSelectedFileMerge(self.specific_files)
 
401
        # Excludes are a form of selected file commit.
 
402
        if len(self.parents) > 1 and self.exclude:
 
403
            raise errors.CannotCommitSelectedFileMerge(self.exclude)
 
404
 
 
405
        # Collect the changes
 
406
        self._set_progress_stage("Collecting changes", counter=True)
 
407
        self._lossy = lossy
 
408
        self.builder = self.branch.get_commit_builder(self.parents,
 
409
            self.config_stack, timestamp, timezone, committer, self.revprops,
 
410
            rev_id, lossy=lossy)
 
411
        if not self.builder.supports_record_entry_contents and self.exclude:
 
412
            self.builder.abort()
 
413
            raise errors.ExcludesUnsupported(self.branch.repository)
 
414
 
 
415
        if self.builder.updates_branch and self.bound_branch:
 
416
            self.builder.abort()
 
417
            raise AssertionError(
 
418
                "bound branches not supported for commit builders "
 
419
                "that update the branch")
 
420
 
296
421
        try:
297
 
            # Cannot commit with conflicts present.
298
 
            if len(self.work_tree.conflicts()) > 0:
299
 
                raise ConflictsInTree
300
 
 
301
 
            # Setup the bound branch variables as needed.
302
 
            self._check_bound_branch(possible_master_transports)
303
 
 
304
 
            # Check that the working tree is up to date
305
 
            old_revno, new_revno = self._check_out_of_date_tree()
306
 
 
307
 
            # Complete configuration setup
308
 
            if reporter is not None:
309
 
                self.reporter = reporter
310
 
            elif self.reporter is None:
311
 
                self.reporter = self._select_reporter()
312
 
            if self.config is None:
313
 
                self.config = self.branch.get_config()
314
 
 
315
 
            self._set_specific_file_ids()
316
 
 
317
 
            # Setup the progress bar. As the number of files that need to be
318
 
            # committed in unknown, progress is reported as stages.
319
 
            # We keep track of entries separately though and include that
320
 
            # information in the progress bar during the relevant stages.
321
 
            self.pb_stage_name = ""
322
 
            self.pb_stage_count = 0
323
 
            self.pb_stage_total = 5
 
422
            self.builder.will_record_deletes()
 
423
            # find the location being committed to
324
424
            if self.bound_branch:
325
 
                self.pb_stage_total += 1
326
 
            self.pb.show_pct = False
327
 
            self.pb.show_spinner = False
328
 
            self.pb.show_eta = False
329
 
            self.pb.show_count = True
330
 
            self.pb.show_bar = True
331
 
 
332
 
            self._gather_parents()
333
 
            # After a merge, a selected file commit is not supported.
334
 
            # See 'bzr help merge' for an explanation as to why.
335
 
            if len(self.parents) > 1 and self.specific_files:
336
 
                raise errors.CannotCommitSelectedFileMerge(self.specific_files)
337
 
            # Excludes are a form of selected file commit.
338
 
            if len(self.parents) > 1 and self.exclude:
339
 
                raise errors.CannotCommitSelectedFileMerge(self.exclude)
340
 
 
341
 
            # Collect the changes
342
 
            self._set_progress_stage("Collecting changes", counter=True)
343
 
            self.builder = self.branch.get_commit_builder(self.parents,
344
 
                self.config, timestamp, timezone, committer, revprops, rev_id)
345
 
 
346
 
            try:
347
 
                self.builder.will_record_deletes()
348
 
                # find the location being committed to
349
 
                if self.bound_branch:
350
 
                    master_location = self.master_branch.base
351
 
                else:
352
 
                    master_location = self.branch.base
353
 
 
354
 
                # report the start of the commit
355
 
                self.reporter.started(new_revno, self.rev_id, master_location)
356
 
 
357
 
                self._update_builder_with_changes()
358
 
                self._check_pointless()
359
 
 
360
 
                # TODO: Now the new inventory is known, check for conflicts.
361
 
                # ADHB 2006-08-08: If this is done, populate_new_inv should not add
362
 
                # weave lines, because nothing should be recorded until it is known
363
 
                # that commit will succeed.
364
 
                self._set_progress_stage("Saving data locally")
365
 
                self.builder.finish_inventory()
366
 
 
367
 
                # Prompt the user for a commit message if none provided
368
 
                message = message_callback(self)
369
 
                self.message = message
370
 
 
371
 
                # Add revision data to the local branch
372
 
                self.rev_id = self.builder.commit(self.message)
373
 
 
374
 
            except Exception, e:
375
 
                mutter("aborting commit write group because of exception:")
376
 
                trace.log_exception_quietly()
377
 
                note("aborting commit write group: %r" % (e,))
378
 
                self.builder.abort()
379
 
                raise
380
 
 
 
425
                master_location = self.master_branch.base
 
426
            else:
 
427
                master_location = self.branch.base
 
428
 
 
429
            # report the start of the commit
 
430
            self.reporter.started(new_revno, self.rev_id, master_location)
 
431
 
 
432
            self._update_builder_with_changes()
 
433
            self._check_pointless()
 
434
 
 
435
            # TODO: Now the new inventory is known, check for conflicts.
 
436
            # ADHB 2006-08-08: If this is done, populate_new_inv should not add
 
437
            # weave lines, because nothing should be recorded until it is known
 
438
            # that commit will succeed.
 
439
            self._set_progress_stage("Saving data locally")
 
440
            self.builder.finish_inventory()
 
441
 
 
442
            # Prompt the user for a commit message if none provided
 
443
            message = message_callback(self)
 
444
            self.message = message
 
445
 
 
446
            # Add revision data to the local branch
 
447
            self.rev_id = self.builder.commit(self.message)
 
448
 
 
449
        except Exception, e:
 
450
            mutter("aborting commit write group because of exception:")
 
451
            trace.log_exception_quietly()
 
452
            self.builder.abort()
 
453
            raise
 
454
 
 
455
        self._update_branches(old_revno, old_revid, new_revno)
 
456
 
 
457
        # Make the working tree be up to date with the branch. This
 
458
        # includes automatic changes scheduled to be made to the tree, such
 
459
        # as updating its basis and unversioning paths that were missing.
 
460
        self.work_tree.unversion(self.deleted_ids)
 
461
        self._set_progress_stage("Updating the working tree")
 
462
        self.work_tree.update_basis_by_delta(self.rev_id,
 
463
             self.builder.get_basis_delta())
 
464
        self.reporter.completed(new_revno, self.rev_id)
 
465
        self._process_post_hooks(old_revno, new_revno)
 
466
        return self.rev_id
 
467
 
 
468
    def _update_branches(self, old_revno, old_revid, new_revno):
 
469
        """Update the master and local branch to the new revision.
 
470
 
 
471
        This will try to make sure that the master branch is updated
 
472
        before the local branch.
 
473
 
 
474
        :param old_revno: Revision number of master branch before the
 
475
            commit
 
476
        :param old_revid: Tip of master branch before the commit
 
477
        :param new_revno: Revision number of the new commit
 
478
        """
 
479
        if not self.builder.updates_branch:
381
480
            self._process_pre_hooks(old_revno, new_revno)
382
481
 
383
482
            # Upload revision data to the master.
386
485
                self._set_progress_stage("Uploading data to master branch")
387
486
                # 'commit' to the master first so a timeout here causes the
388
487
                # local branch to be out of date
389
 
                self.master_branch.import_last_revision_info(
390
 
                    self.branch.repository, new_revno, self.rev_id)
 
488
                (new_revno, self.rev_id) = self.master_branch.import_last_revision_info_and_tags(
 
489
                    self.branch, new_revno, self.rev_id, lossy=self._lossy)
 
490
                if self._lossy:
 
491
                    self.branch.fetch(self.master_branch, self.rev_id)
391
492
 
392
493
            # and now do the commit locally.
393
494
            self.branch.set_last_revision_info(new_revno, self.rev_id)
 
495
        else:
 
496
            try:
 
497
                self._process_pre_hooks(old_revno, new_revno)
 
498
            except:
 
499
                # The commit builder will already have updated the branch,
 
500
                # revert it.
 
501
                self.branch.set_last_revision_info(old_revno, old_revid)
 
502
                raise
394
503
 
395
 
            # Make the working tree up to date with the branch
396
 
            self._set_progress_stage("Updating the working tree")
397
 
            self.work_tree.update_basis_by_delta(self.rev_id,
398
 
                 self.builder.get_basis_delta())
399
 
            self.reporter.completed(new_revno, self.rev_id)
400
 
            self._process_post_hooks(old_revno, new_revno)
401
 
        finally:
402
 
            self._cleanup()
403
 
        return self.rev_id
 
504
        # Merge local tags to remote
 
505
        if self.bound_branch:
 
506
            self._set_progress_stage("Merging tags to master branch")
 
507
            tag_updates, tag_conflicts = self.branch.tags.merge_to(
 
508
                self.master_branch.tags)
 
509
            if tag_conflicts:
 
510
                warning_lines = ['    ' + name for name, _, _ in tag_conflicts]
 
511
                note( gettext("Conflicting tags in bound branch:\n{0}".format(
 
512
                    "\n".join(warning_lines))) )
404
513
 
405
514
    def _select_reporter(self):
406
515
        """Select the CommitReporter to use."""
414
523
        # A merge with no effect on files
415
524
        if len(self.parents) > 1:
416
525
            return
417
 
        # TODO: we could simplify this by using self.builder.basis_delta.
418
 
 
419
 
        # The initial commit adds a root directory, but this in itself is not
420
 
        # a worthwhile commit.
421
 
        if (self.basis_revid == revision.NULL_REVISION and
422
 
            ((self.builder.new_inventory is not None and
423
 
             len(self.builder.new_inventory) == 1) or
424
 
            len(self.builder._basis_delta) == 1)):
425
 
            raise PointlessCommit()
426
526
        if self.builder.any_changes():
427
527
            return
428
528
        raise PointlessCommit()
429
529
 
430
 
    def _check_bound_branch(self, possible_master_transports=None):
 
530
    def _check_bound_branch(self, operation, possible_master_transports=None):
431
531
        """Check to see if the local branch is bound.
432
532
 
433
533
        If it is bound, then most of the commit will actually be
468
568
        # so grab the lock
469
569
        self.bound_branch = self.branch
470
570
        self.master_branch.lock_write()
471
 
        self.master_locked = True
 
571
        operation.add_cleanup(self.master_branch.unlock)
472
572
 
473
573
    def _check_out_of_date_tree(self):
474
574
        """Check that the working tree is up to date.
475
575
 
476
 
        :return: old_revision_number,new_revision_number tuple
 
576
        :return: old_revision_number, old_revision_id, new_revision_number
 
577
            tuple
477
578
        """
478
579
        try:
479
580
            first_tree_parent = self.work_tree.get_parent_ids()[0]
492
593
        else:
493
594
            # ghost parents never appear in revision history.
494
595
            new_revno = 1
495
 
        return old_revno,new_revno
 
596
        return old_revno, master_last, new_revno
496
597
 
497
598
    def _process_pre_hooks(self, old_revno, new_revno):
498
599
        """Process any registered pre commit hooks."""
504
605
        # Process the post commit hooks, if any
505
606
        self._set_progress_stage("Running post_commit hooks")
506
607
        # old style commit hooks - should be deprecated ? (obsoleted in
507
 
        # 0.15)
508
 
        if self.config.post_commit() is not None:
509
 
            hooks = self.config.post_commit().split(' ')
 
608
        # 0.15^H^H^H^H 2.5.0)
 
609
        post_commit = self.config_stack.get('post_commit')
 
610
        if post_commit is not None:
 
611
            hooks = post_commit.split(' ')
510
612
            # this would be nicer with twisted.python.reflect.namedAny
511
613
            for hook in hooks:
512
614
                result = eval(hook + '(branch, rev_id)',
559
661
                     old_revno, old_revid, new_revno, self.rev_id,
560
662
                     tree_delta, future_tree)
561
663
 
562
 
    def _cleanup(self):
563
 
        """Cleanup any open locks, progress bars etc."""
564
 
        cleanups = [self._cleanup_bound_branch,
565
 
                    self.basis_tree.unlock,
566
 
                    self.work_tree.unlock,
567
 
                    self.pb.finished]
568
 
        found_exception = None
569
 
        for cleanup in cleanups:
570
 
            try:
571
 
                cleanup()
572
 
            # we want every cleanup to run no matter what.
573
 
            # so we have a catchall here, but we will raise the
574
 
            # last encountered exception up the stack: and
575
 
            # typically this will be useful enough.
576
 
            except Exception, e:
577
 
                found_exception = e
578
 
        if found_exception is not None:
579
 
            # don't do a plan raise, because the last exception may have been
580
 
            # trashed, e is our sure-to-work exception even though it loses the
581
 
            # full traceback. XXX: RBC 20060421 perhaps we could check the
582
 
            # exc_info and if its the same one do a plain raise otherwise
583
 
            # 'raise e' as we do now.
584
 
            raise e
585
 
 
586
 
    def _cleanup_bound_branch(self):
587
 
        """Executed at the end of a try/finally to cleanup a bound branch.
588
 
 
589
 
        If the branch wasn't bound, this is a no-op.
590
 
        If it was, it resents self.branch to the local branch, instead
591
 
        of being the master.
592
 
        """
593
 
        if not self.bound_branch:
594
 
            return
595
 
        if self.master_locked:
596
 
            self.master_branch.unlock()
597
 
 
598
664
    def _gather_parents(self):
599
665
        """Record the parents of a merge for merge detection."""
600
666
        # TODO: Make sure that this list doesn't contain duplicate
615
681
        """Update the commit builder with the data about what has changed.
616
682
        """
617
683
        exclude = self.exclude
618
 
        specific_files = self.specific_files or []
 
684
        specific_files = self.specific_files
619
685
        mutter("Selecting files for commit with filter %s", specific_files)
620
686
 
621
687
        self._check_strict()
622
688
        if self.use_record_iter_changes:
623
 
            iter_changes = self.work_tree.iter_changes(self.basis_tree)
 
689
            iter_changes = self.work_tree.iter_changes(self.basis_tree,
 
690
                specific_files=specific_files)
624
691
            iter_changes = self._filter_iter_changes(iter_changes)
625
692
            for file_id, path, fs_hash in self.builder.record_iter_changes(
626
693
                self.work_tree, self.basis_revid, iter_changes):
659
726
                # Reset the new path (None) and new versioned flag (False)
660
727
                change = (change[0], (change[1][0], None), change[2],
661
728
                    (change[3][0], False)) + change[4:]
 
729
                new_path = change[1][1]
 
730
                versioned = False
662
731
            elif kind == 'tree-reference':
663
732
                if self.recursive == 'down':
664
733
                    self._commit_nested_tree(change[0], change[1][1])
668
737
                    if new_path is None:
669
738
                        reporter.deleted(old_path)
670
739
                    elif old_path is None:
671
 
                        reporter.snapshot_change('added', new_path)
 
740
                        reporter.snapshot_change(gettext('added'), new_path)
672
741
                    elif old_path != new_path:
673
 
                        reporter.renamed('renamed', old_path, new_path)
 
742
                        reporter.renamed(gettext('renamed'), old_path, new_path)
674
743
                    else:
675
744
                        if (new_path or 
676
745
                            self.work_tree.branch.repository._format.rich_root_data):
677
746
                            # Don't report on changes to '' in non rich root
678
747
                            # repositories.
679
 
                            reporter.snapshot_change('modified', new_path)
 
748
                            reporter.snapshot_change(gettext('modified'), new_path)
680
749
            self._next_progress_entry()
681
750
        # Unversion IDs that were found to be deleted
682
 
        self.work_tree.unversion(deleted_ids)
 
751
        self.deleted_ids = deleted_ids
683
752
 
684
753
    def _record_unselected(self):
685
754
        # If specific files are selected, then all un-selected files must be
688
757
        if self.specific_files or self.exclude:
689
758
            specific_files = self.specific_files or []
690
759
            for path, old_ie in self.basis_inv.iter_entries():
691
 
                if old_ie.file_id in self.builder.new_inventory:
 
760
                if self.builder.new_inventory.has_id(old_ie.file_id):
692
761
                    # already added - skip.
693
762
                    continue
694
763
                if (is_inside_any(specific_files, path)
798
867
                # _update_builder_with_changes.
799
868
                continue
800
869
            content_summary = self.work_tree.path_content_summary(path)
 
870
            kind = content_summary[0]
801
871
            # Note that when a filter of specific files is given, we must only
802
872
            # skip/record deleted files matching that filter.
803
873
            if not specific_files or is_inside_any(specific_files, path):
804
 
                if content_summary[0] == 'missing':
 
874
                if kind == 'missing':
805
875
                    if not deleted_paths:
806
876
                        # path won't have been split yet.
807
877
                        path_segments = splitpath(path)
814
884
                    continue
815
885
            # TODO: have the builder do the nested commit just-in-time IF and
816
886
            # only if needed.
817
 
            if content_summary[0] == 'tree-reference':
 
887
            if kind == 'tree-reference':
818
888
                # enforce repository nested tree policy.
819
889
                if (not self.work_tree.supports_tree_reference() or
820
890
                    # repository does not support it either.
821
891
                    not self.branch.repository._format.supports_tree_reference):
822
 
                    content_summary = ('directory',) + content_summary[1:]
823
 
            kind = content_summary[0]
824
 
            # TODO: specific_files filtering before nested tree processing
825
 
            if kind == 'tree-reference':
826
 
                if self.recursive == 'down':
 
892
                    kind = 'directory'
 
893
                    content_summary = (kind, None, None, None)
 
894
                elif self.recursive == 'down':
827
895
                    nested_revision_id = self._commit_nested_tree(
828
896
                        file_id, path)
829
 
                    content_summary = content_summary[:3] + (
830
 
                        nested_revision_id,)
 
897
                    content_summary = (kind, None, None, nested_revision_id)
831
898
                else:
832
 
                    content_summary = content_summary[:3] + (
833
 
                        self.work_tree.get_reference_revision(file_id),)
 
899
                    nested_revision_id = self.work_tree.get_reference_revision(file_id)
 
900
                    content_summary = (kind, None, None, nested_revision_id)
834
901
 
835
902
            # Record an entry for this item
836
903
            # Note: I don't particularly want to have the existing_ie
842
909
                content_summary)
843
910
 
844
911
        # Unversion IDs that were found to be deleted
845
 
        self.work_tree.unversion(deleted_ids)
 
912
        self.deleted_ids = deleted_ids
846
913
 
847
914
    def _commit_nested_tree(self, file_id, path):
848
915
        "Commit a nested tree."
907
974
            self.reporter.renamed(change, old_path, path)
908
975
            self._next_progress_entry()
909
976
        else:
910
 
            if change == 'unchanged':
 
977
            if change == gettext('unchanged'):
911
978
                return
912
979
            self.reporter.snapshot_change(change, path)
913
980
            self._next_progress_entry()
929
996
 
930
997
    def _emit_progress(self):
931
998
        if self.pb_entries_count is not None:
932
 
            text = "%s [%d] - Stage" % (self.pb_stage_name,
 
999
            text = gettext("{0} [{1}] - Stage").format(self.pb_stage_name,
933
1000
                self.pb_entries_count)
934
1001
        else:
935
 
            text = "%s - Stage" % (self.pb_stage_name, )
 
1002
            text = gettext("%s - Stage") % (self.pb_stage_name, )
936
1003
        self.pb.update(text, self.pb_stage_count, self.pb_stage_total)
937
1004
 
938
1005
    def _set_specific_file_ids(self):