/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/commit.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
    debug,
55
55
    errors,
56
56
    trace,
 
57
    tree,
57
58
    ui,
58
59
    )
59
60
from .branch import Branch
60
 
from .cleanup import ExitStack
 
61
from .cleanup import OperationWithCleanups
61
62
import breezy.config
62
63
from .errors import (BzrError,
63
64
                     ConflictsInTree,
64
65
                     StrictCommitFailed
65
66
                     )
66
67
from .osutils import (get_user_encoding,
67
 
                      has_symlinks,
68
68
                      is_inside_any,
69
69
                      minimum_path_selection,
 
70
                      splitpath,
70
71
                      )
71
72
from .trace import mutter, note, is_quiet
72
 
from .tree import TreeChange
73
73
from .urlutils import unescape_for_display
74
74
from .i18n import gettext
75
75
 
97
97
    :return: iter_changes function
98
98
    """
99
99
    for change in iter_changes:
100
 
        new_excluded = (change.path[1] is not None and
101
 
                        is_inside_any(exclude, change.path[1]))
102
 
 
103
 
        old_excluded = (change.path[0] is not None and
104
 
                        is_inside_any(exclude, change.path[0]))
 
100
        old_path = change[1][0]
 
101
        new_path = change[1][1]
 
102
 
 
103
        new_excluded = (new_path is not None and
 
104
            is_inside_any(exclude, new_path))
 
105
 
 
106
        old_excluded = (old_path is not None and
 
107
            is_inside_any(exclude, old_path))
105
108
 
106
109
        if old_excluded and new_excluded:
107
110
            continue
158
161
            unescape_for_display(location, 'utf-8'))
159
162
 
160
163
    def completed(self, revno, rev_id):
161
 
        if revno is not None:
162
 
            self._note(gettext('Committed revision %d.'), revno)
163
 
            # self._note goes to the console too; so while we want to log the
164
 
            # rev_id, we can't trivially only log it. (See bug 526425). Long
165
 
            # term we should rearrange the reporting structure, but for now
166
 
            # we just mutter seperately. We mutter the revid and revno together
167
 
            # so that concurrent bzr invocations won't lead to confusion.
168
 
            mutter('Committed revid %s as revno %d.', rev_id, revno)
169
 
        else:
170
 
            self._note(gettext('Committed revid %s.'), rev_id)
 
164
        self._note(gettext('Committed revision %d.'), revno)
 
165
        # self._note goes to the console too; so while we want to log the
 
166
        # rev_id, we can't trivially only log it. (See bug 526425). Long
 
167
        # term we should rearrange the reporting structure, but for now
 
168
        # we just mutter seperately. We mutter the revid and revno together
 
169
        # so that concurrent bzr invocations won't lead to confusion.
 
170
        mutter('Committed revid %s as revno %d.', rev_id, revno)
171
171
 
172
172
    def deleted(self, path):
173
173
        self._note(gettext('deleted %s'), path)
194
194
            the working directory; these should be removed from the
195
195
            working inventory.
196
196
    """
197
 
 
198
197
    def __init__(self,
199
198
                 reporter=None,
200
199
                 config_stack=None):
212
211
            revprops = {}
213
212
        if possible_master_transports is None:
214
213
            possible_master_transports = []
215
 
        if (u'branch-nick' not in revprops and
 
214
        if (not 'branch-nick' in revprops and
216
215
                branch.repository._format.supports_storing_branch_nick):
217
 
            revprops[u'branch-nick'] = branch._get_nick(
 
216
            revprops['branch-nick'] = branch._get_nick(
218
217
                local,
219
218
                possible_master_transports)
220
219
        if authors is not None:
221
 
            if u'author' in revprops or u'authors' in revprops:
 
220
            if 'author' in revprops or 'authors' in revprops:
222
221
                # XXX: maybe we should just accept one of them?
223
222
                raise AssertionError('author property given twice')
224
223
            if authors:
225
224
                for individual in authors:
226
225
                    if '\n' in individual:
227
226
                        raise AssertionError('\\n is not a valid character '
228
 
                                             'in an author identity')
229
 
                revprops[u'authors'] = '\n'.join(authors)
 
227
                                'in an author identity')
 
228
                revprops['authors'] = '\n'.join(authors)
230
229
        return revprops
231
230
 
232
231
    def commit(self,
252
251
        """Commit working copy as a new revision.
253
252
 
254
253
        :param message: the commit message (it or message_callback is required)
255
 
        :param message_callback: A callback: message =
256
 
            message_callback(cmt_obj)
 
254
        :param message_callback: A callback: message = message_callback(cmt_obj)
257
255
 
258
256
        :param timestamp: if not None, seconds-since-epoch for a
259
257
            postdated/predated commit.
285
283
        :param lossy: When committing to a foreign VCS, ignore any
286
284
            data that can not be natively represented.
287
285
        """
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')
293
 
 
294
 
            if working_tree is None:
295
 
                raise BzrError("working_tree must be passed into commit().")
296
 
            else:
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())
306
 
 
307
 
                    def message_callback(x):
308
 
                        return message
309
 
                else:
310
 
                    raise BzrError("The message or message_callback keyword"
311
 
                                   " parameter is required for commit().")
312
 
 
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))
318
 
            else:
319
 
                self.exclude = []
320
 
            self.local = local
321
 
            self.master_branch = None
322
 
            self.recursive = recursive
323
 
            self.rev_id = None
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))
329
 
            else:
330
 
                self.specific_files = None
331
 
 
332
 
            self.allow_pointless = allow_pointless
333
 
            self.message_callback = message_callback
334
 
            self.timestamp = timestamp
335
 
            self.timezone = timezone
336
 
            self.committer = committer
337
 
            self.strict = strict
338
 
            self.verbose = verbose
339
 
 
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
350
 
 
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()
355
 
 
356
 
            # Check that the working tree is up to date
357
 
            old_revno, old_revid, new_revno = self._check_out_of_date_tree()
358
 
 
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()
364
 
 
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(
 
291
               message=message,
 
292
               timestamp=timestamp,
 
293
               timezone=timezone,
 
294
               committer=committer,
 
295
               specific_files=specific_files,
 
296
               rev_id=rev_id,
 
297
               allow_pointless=allow_pointless,
 
298
               strict=strict,
 
299
               verbose=verbose,
 
300
               working_tree=working_tree,
 
301
               local=local,
 
302
               reporter=reporter,
 
303
               message_callback=message_callback,
 
304
               recursive=recursive,
 
305
               exclude=exclude,
 
306
               possible_master_transports=possible_master_transports,
 
307
               lossy=lossy)
 
308
 
 
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')
 
314
 
 
315
        if working_tree is None:
 
316
            raise BzrError("working_tree must be passed into commit().")
 
317
        else:
 
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
 
328
            else:
 
329
                raise BzrError("The message or message_callback keyword"
 
330
                               " parameter is required for commit().")
 
331
 
 
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))
 
337
        else:
 
338
            self.exclude = []
 
339
        self.local = local
 
340
        self.master_branch = None
 
341
        self.recursive = recursive
 
342
        self.rev_id = None
 
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))
 
348
        else:
 
349
            self.specific_files = None
 
350
 
 
351
        self.allow_pointless = allow_pointless
 
352
        self.message_callback = message_callback
 
353
        self.timestamp = timestamp
 
354
        self.timezone = timezone
 
355
        self.committer = committer
 
356
        self.strict = strict
 
357
        self.verbose = verbose
 
358
 
 
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
 
371
 
 
372
        # Setup the bound branch variables as needed.
 
373
        self._check_bound_branch(operation, possible_master_transports)
 
374
 
 
375
        # Check that the working tree is up to date
 
376
        old_revno, old_revid, new_revno = self._check_out_of_date_tree()
 
377
 
 
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()
 
385
 
 
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
 
402
 
 
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)
 
410
 
 
411
        # Collect the changes
 
412
        self._set_progress_stage("Collecting changes", counter=True)
 
413
        self._lossy = lossy
 
414
        self.builder = self.branch.get_commit_builder(self.parents,
 
415
            self.config_stack, timestamp, timezone, committer, self.revprops,
 
416
            rev_id, lossy=lossy)
 
417
 
 
418
        if self.builder.updates_branch and self.bound_branch:
 
419
            self.builder.abort()
 
420
            raise AssertionError(
 
421
                "bound branches not supported for commit builders "
 
422
                "that update the branch")
 
423
 
 
424
        try:
 
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
381
 
 
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)
389
 
 
390
 
            # Collect the changes
391
 
            self._set_progress_stage("Collecting changes", counter=True)
392
 
            self._lossy = lossy
393
 
            self.builder = self.branch.get_commit_builder(
394
 
                self.parents, self.config_stack, timestamp, timezone, committer,
395
 
                self.revprops, rev_id, lossy=lossy)
396
 
 
397
 
            if self.builder.updates_branch and self.bound_branch:
398
 
                self.builder.abort()
399
 
                raise AssertionError(
400
 
                    "bound branches not supported for commit builders "
401
 
                    "that update the branch")
402
 
 
403
 
            try:
404
 
                # find the location being committed to
405
 
                if self.bound_branch:
406
 
                    master_location = self.master_branch.base
407
 
                else:
408
 
                    master_location = self.branch.base
409
 
 
410
 
                # report the start of the commit
411
 
                self.reporter.started(new_revno, self.rev_id, master_location)
412
 
 
413
 
                self._update_builder_with_changes()
414
 
                self._check_pointless()
415
 
 
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()
422
 
 
423
 
                # Prompt the user for a commit message if none provided
424
 
                message = message_callback(self)
425
 
                self.message = message
426
 
 
427
 
                # Add revision data to the local branch
428
 
                self.rev_id = self.builder.commit(self.message)
429
 
 
430
 
            except Exception:
431
 
                mutter("aborting commit write group because of exception:")
432
 
                trace.log_exception_quietly()
433
 
                self.builder.abort()
434
 
                raise
435
 
 
436
 
            self._update_branches(old_revno, old_revid, new_revno)
437
 
 
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)
447
 
            return self.rev_id
 
427
                master_location = self.master_branch.base
 
428
            else:
 
429
                master_location = self.branch.base
 
430
 
 
431
            # report the start of the commit
 
432
            self.reporter.started(new_revno, self.rev_id, master_location)
 
433
 
 
434
            self._update_builder_with_changes()
 
435
            self._check_pointless()
 
436
 
 
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()
 
443
 
 
444
            # Prompt the user for a commit message if none provided
 
445
            message = message_callback(self)
 
446
            self.message = message
 
447
 
 
448
            # Add revision data to the local branch
 
449
            self.rev_id = self.builder.commit(self.message)
 
450
 
 
451
        except Exception as e:
 
452
            mutter("aborting commit write group because of exception:")
 
453
            trace.log_exception_quietly()
 
454
            self.builder.abort()
 
455
            raise
 
456
 
 
457
        self._update_branches(old_revno, old_revid, new_revno)
 
458
 
 
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)
 
468
        return self.rev_id
448
469
 
449
470
    def _update_branches(self, old_revno, old_revid, new_revno):
450
471
        """Update the master and local branch to the new revision.
472
493
                    self.branch.fetch(self.master_branch, self.rev_id)
473
494
 
474
495
            # and now do the commit locally.
475
 
            if new_revno is None:
476
 
                # Keep existing behaviour around ghosts
477
 
                new_revno = 1
478
496
            self.branch.set_last_revision_info(new_revno, self.rev_id)
479
497
        else:
480
498
            try:
481
499
                self._process_pre_hooks(old_revno, new_revno)
482
 
            except BaseException:
 
500
            except:
483
501
                # The commit builder will already have updated the branch,
484
502
                # revert it.
485
503
                self.branch.set_last_revision_info(old_revno, old_revid)
492
510
                self.master_branch.tags)
493
511
            if tag_conflicts:
494
512
                warning_lines = ['    ' + name for name, _, _ in tag_conflicts]
495
 
                note(gettext("Conflicting tags in bound branch:\n{0}".format(
496
 
                    "\n".join(warning_lines))))
 
513
                note( gettext("Conflicting tags in bound branch:\n{0}".format(
 
514
                    "\n".join(warning_lines))) )
497
515
 
498
516
    def _select_reporter(self):
499
517
        """Select the CommitReporter to use."""
511
529
            return
512
530
        raise PointlessCommit()
513
531
 
514
 
    def _check_bound_branch(self, stack, possible_master_transports=None):
 
532
    def _check_bound_branch(self, operation, possible_master_transports=None):
515
533
        """Check to see if the local branch is bound.
516
534
 
517
535
        If it is bound, then most of the commit will actually be
533
551
        # If the master branch is bound, we must fail
534
552
        master_bound_location = self.master_branch.get_bound_location()
535
553
        if master_bound_location:
536
 
            raise errors.CommitToDoubleBoundBranch(
537
 
                self.branch, self.master_branch, master_bound_location)
 
554
            raise errors.CommitToDoubleBoundBranch(self.branch,
 
555
                    self.master_branch, master_bound_location)
538
556
 
539
557
        # TODO: jam 20051230 We could automatically push local
540
558
        #       commits to the remote branch if they would fit.
542
560
        #       to local.
543
561
 
544
562
        # Make sure the local branch is identical to the master
545
 
        master_revid = self.master_branch.last_revision()
546
 
        local_revid = self.branch.last_revision()
547
 
        if local_revid != master_revid:
 
563
        master_info = self.master_branch.last_revision_info()
 
564
        local_info = self.branch.last_revision_info()
 
565
        if local_info != master_info:
548
566
            raise errors.BoundBranchOutOfDate(self.branch,
549
 
                                              self.master_branch)
 
567
                    self.master_branch)
550
568
 
551
569
        # Now things are ready to change the master branch
552
570
        # so grab the lock
553
571
        self.bound_branch = self.branch
554
 
        stack.enter_context(self.master_branch.lock_write())
 
572
        self.master_branch.lock_write()
 
573
        operation.add_cleanup(self.master_branch.unlock)
555
574
 
556
575
    def _check_out_of_date_tree(self):
557
576
        """Check that the working tree is up to date.
567
586
            # - in a checkout scenario the tree may have no
568
587
            # parents but the branch may do.
569
588
            first_tree_parent = breezy.revision.NULL_REVISION
570
 
        if (self.master_branch._format.stores_revno() or
571
 
                self.config_stack.get('calculate_revnos')):
572
 
            try:
573
 
                old_revno, master_last = self.master_branch.last_revision_info()
574
 
            except errors.UnsupportedOperation:
575
 
                master_last = self.master_branch.last_revision()
576
 
                old_revno = self.branch.revision_id_to_revno(master_last)
577
 
        else:
578
 
            master_last = self.master_branch.last_revision()
579
 
            old_revno = None
 
589
        old_revno, master_last = self.master_branch.last_revision_info()
580
590
        if master_last != first_tree_parent:
581
591
            if master_last != breezy.revision.NULL_REVISION:
582
592
                raise errors.OutOfDateTree(self.work_tree)
583
 
        if (old_revno is not None and
584
 
                self.branch.repository.has_revision(first_tree_parent)):
 
593
        if self.branch.repository.has_revision(first_tree_parent):
585
594
            new_revno = old_revno + 1
586
595
        else:
587
596
            # ghost parents never appear in revision history.
588
 
            new_revno = None
 
597
            new_revno = 1
589
598
        return old_revno, master_last, new_revno
590
599
 
591
600
    def _process_pre_hooks(self, old_revno, new_revno):
605
614
            # this would be nicer with twisted.python.reflect.namedAny
606
615
            for hook in hooks:
607
616
                result = eval(hook + '(branch, rev_id)',
608
 
                              {'branch': self.branch,
609
 
                               'breezy': breezy,
610
 
                               'rev_id': self.rev_id})
 
617
                              {'branch':self.branch,
 
618
                               'breezy':breezy,
 
619
                               'rev_id':self.rev_id})
611
620
        # process new style post commit hooks
612
621
        self._process_hooks("post_commit", old_revno, new_revno)
613
622
 
633
642
        if hook_name == "pre_commit":
634
643
            future_tree = self.builder.revision_tree()
635
644
            tree_delta = future_tree.changes_from(self.basis_tree,
636
 
                                                  include_root=True)
 
645
                                             include_root=True)
637
646
 
638
647
        for hook in Branch.hooks[hook_name]:
639
648
            # show the running hook in the progress bar. As hooks may
661
670
        mutter("Selecting files for commit with filter %r", specific_files)
662
671
 
663
672
        self._check_strict()
664
 
        iter_changes = self.work_tree.iter_changes(
665
 
            self.basis_tree, specific_files=specific_files)
 
673
        iter_changes = self.work_tree.iter_changes(self.basis_tree,
 
674
            specific_files=specific_files)
666
675
        if self.exclude:
667
676
            iter_changes = filter_excluded(iter_changes, self.exclude)
668
677
        iter_changes = self._filter_iter_changes(iter_changes)
669
 
        for path, fs_hash in self.builder.record_iter_changes(
670
 
                self.work_tree, self.basis_revid, iter_changes):
671
 
            self.work_tree._observed_sha1(path, fs_hash)
 
678
        for file_id, path, fs_hash in self.builder.record_iter_changes(
 
679
            self.work_tree, self.basis_revid, iter_changes):
 
680
            self.work_tree._observed_sha1(file_id, path, fs_hash)
672
681
 
673
682
    def _filter_iter_changes(self, iter_changes):
674
683
        """Process iter_changes.
675
684
 
676
 
        This method reports on the changes in iter_changes to the user, and
 
685
        This method reports on the changes in iter_changes to the user, and 
677
686
        converts 'missing' entries in the iter_changes iterator to 'deleted'
678
687
        entries. 'missing' entries have their
679
688
 
685
694
        deleted_paths = []
686
695
        for change in iter_changes:
687
696
            if report_changes:
688
 
                old_path = change.path[0]
689
 
                new_path = change.path[1]
690
 
                versioned = change.versioned[1]
691
 
            kind = change.kind[1]
692
 
            versioned = change.versioned[1]
 
697
                old_path = change[1][0]
 
698
                new_path = change[1][1]
 
699
                versioned = change[3][1]
 
700
            kind = change[6][1]
 
701
            versioned = change[3][1]
693
702
            if kind is None and versioned:
694
703
                # 'missing' path
695
704
                if report_changes:
696
705
                    reporter.missing(new_path)
697
 
                if change.kind[0] == 'symlink' and not self.work_tree.supports_symlinks():
698
 
                    trace.warning('Ignoring "%s" as symlinks are not '
699
 
                                  'supported on this filesystem.' % (change.path[0],))
700
 
                    continue
701
 
                deleted_paths.append(change.path[1])
 
706
                deleted_paths.append(change[1][1])
702
707
                # Reset the new path (None) and new versioned flag (False)
703
 
                change = change.discard_new()
704
 
                new_path = change.path[1]
 
708
                change = (change[0], (change[1][0], None), change[2],
 
709
                    (change[3][0], False)) + change[4:]
 
710
                new_path = change[1][1]
705
711
                versioned = False
706
712
            elif kind == 'tree-reference':
707
713
                if self.recursive == 'down':
708
 
                    self._commit_nested_tree(change.path[1])
709
 
            if change.versioned[0] or change.versioned[1]:
 
714
                    self._commit_nested_tree(change[0], change[1][1])
 
715
            if change[3][0] or change[3][1]:
710
716
                yield change
711
717
                if report_changes:
712
718
                    if new_path is None:
714
720
                    elif old_path is None:
715
721
                        reporter.snapshot_change(gettext('added'), new_path)
716
722
                    elif old_path != new_path:
717
 
                        reporter.renamed(gettext('renamed'),
718
 
                                         old_path, new_path)
 
723
                        reporter.renamed(gettext('renamed'), old_path, new_path)
719
724
                    else:
720
 
                        if (new_path
721
 
                                or self.work_tree.branch.repository._format.rich_root_data):
 
725
                        if (new_path or 
 
726
                            self.work_tree.branch.repository._format.rich_root_data):
722
727
                            # Don't report on changes to '' in non rich root
723
728
                            # repositories.
724
 
                            reporter.snapshot_change(
725
 
                                gettext('modified'), new_path)
 
729
                            reporter.snapshot_change(gettext('modified'), new_path)
726
730
            self._next_progress_entry()
727
731
        # Unversion files that were found to be deleted
728
732
        self.deleted_paths = deleted_paths
736
740
            for unknown in self.work_tree.unknowns():
737
741
                raise StrictCommitFailed()
738
742
 
739
 
    def _commit_nested_tree(self, path):
 
743
    def _commit_nested_tree(self, file_id, path):
740
744
        "Commit a nested tree."
741
 
        sub_tree = self.work_tree.get_nested_tree(path)
 
745
        sub_tree = self.work_tree.get_nested_tree(path, file_id)
742
746
        # FIXME: be more comprehensive here:
743
747
        # this works when both trees are in --trees repository,
744
748
        # but when both are bound to a different repository,
746
750
        # finally implement the explicit-caches approach design
747
751
        # a while back - RBC 20070306.
748
752
        if sub_tree.branch.repository.has_same_location(
749
 
                self.work_tree.branch.repository):
 
753
            self.work_tree.branch.repository):
750
754
            sub_tree.branch.repository = \
751
755
                self.work_tree.branch.repository
752
756
        try:
753
757
            return sub_tree.commit(message=None, revprops=self.revprops,
754
 
                                   recursive=self.recursive,
755
 
                                   message_callback=self.message_callback,
756
 
                                   timestamp=self.timestamp,
757
 
                                   timezone=self.timezone,
758
 
                                   committer=self.committer,
759
 
                                   allow_pointless=self.allow_pointless,
760
 
                                   strict=self.strict, verbose=self.verbose,
761
 
                                   local=self.local, reporter=self.reporter)
 
758
                recursive=self.recursive,
 
759
                message_callback=self.message_callback,
 
760
                timestamp=self.timestamp, timezone=self.timezone,
 
761
                committer=self.committer,
 
762
                allow_pointless=self.allow_pointless,
 
763
                strict=self.strict, verbose=self.verbose,
 
764
                local=self.local, reporter=self.reporter)
762
765
        except PointlessCommit:
763
 
            return self.work_tree.get_reference_revision(path)
 
766
            return self.work_tree.get_reference_revision(path, file_id)
764
767
 
765
768
    def _set_progress_stage(self, name, counter=False):
766
769
        """Set the progress stage and emit an update to the progress bar."""
780
783
    def _emit_progress(self):
781
784
        if self.pb_entries_count is not None:
782
785
            text = gettext("{0} [{1}] - Stage").format(self.pb_stage_name,
783
 
                                                       self.pb_entries_count)
 
786
                self.pb_entries_count)
784
787
        else:
785
788
            text = gettext("%s - Stage") % (self.pb_stage_name, )
786
789
        self.pb.update(text, self.pb_stage_count, self.pb_stage_total)