/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-06-14 17:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180614175916-a2e2xh5k533guq1x
Move breezy.plugins.git to breezy.git.

Show diffs side-by-side

added added

removed removed

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