/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
        new_path = change[1][1]
100
100
 
101
101
        new_excluded = (new_path is not None and
102
 
            is_inside_any(exclude, new_path))
 
102
                        is_inside_any(exclude, new_path))
103
103
 
104
104
        old_excluded = (old_path is not None and
105
 
            is_inside_any(exclude, old_path))
 
105
                        is_inside_any(exclude, old_path))
106
106
 
107
107
        if old_excluded and new_excluded:
108
108
            continue
192
192
            the working directory; these should be removed from the
193
193
            working inventory.
194
194
    """
 
195
 
195
196
    def __init__(self,
196
197
                 reporter=None,
197
198
                 config_stack=None):
209
210
            revprops = {}
210
211
        if possible_master_transports is None:
211
212
            possible_master_transports = []
212
 
        if (not u'branch-nick' in revprops and
 
213
        if (u'branch-nick' not in revprops and
213
214
                branch.repository._format.supports_storing_branch_nick):
214
215
            revprops[u'branch-nick'] = branch._get_nick(
215
216
                local,
222
223
                for individual in authors:
223
224
                    if '\n' in individual:
224
225
                        raise AssertionError('\\n is not a valid character '
225
 
                                'in an author identity')
 
226
                                             'in an author identity')
226
227
                revprops[u'authors'] = '\n'.join(authors)
227
228
        return revprops
228
229
 
249
250
        """Commit working copy as a new revision.
250
251
 
251
252
        :param message: the commit message (it or message_callback is required)
252
 
        :param message_callback: A callback: message = message_callback(cmt_obj)
 
253
        :param message_callback: A callback: message =
 
254
            message_callback(cmt_obj)
253
255
 
254
256
        :param timestamp: if not None, seconds-since-epoch for a
255
257
            postdated/predated commit.
286
288
        # XXX: Can be set on __init__ or passed in - this is a bit ugly.
287
289
        self.config_stack = config or self.config_stack
288
290
        return operation.run(
289
 
               message=message,
290
 
               timestamp=timestamp,
291
 
               timezone=timezone,
292
 
               committer=committer,
293
 
               specific_files=specific_files,
294
 
               rev_id=rev_id,
295
 
               allow_pointless=allow_pointless,
296
 
               strict=strict,
297
 
               verbose=verbose,
298
 
               working_tree=working_tree,
299
 
               local=local,
300
 
               reporter=reporter,
301
 
               message_callback=message_callback,
302
 
               recursive=recursive,
303
 
               exclude=exclude,
304
 
               possible_master_transports=possible_master_transports,
305
 
               lossy=lossy)
 
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)
306
308
 
307
309
    def _commit(self, operation, message, timestamp, timezone, committer,
308
 
            specific_files, rev_id, allow_pointless, strict, verbose,
309
 
            working_tree, local, reporter, message_callback, recursive,
310
 
            exclude, possible_master_transports, lossy):
 
310
                specific_files, rev_id, allow_pointless, strict, verbose,
 
311
                working_tree, local, reporter, message_callback, recursive,
 
312
                exclude, possible_master_transports, lossy):
311
313
        mutter('preparing to commit')
312
314
 
313
315
        if working_tree is None:
322
324
            if message is not None:
323
325
                if isinstance(message, bytes):
324
326
                    message = message.decode(get_user_encoding())
325
 
                message_callback = lambda x: message
 
327
 
 
328
                def message_callback(x):
 
329
                    return message
326
330
            else:
327
331
                raise BzrError("The message or message_callback keyword"
328
332
                               " parameter is required for commit().")
409
413
        # Collect the changes
410
414
        self._set_progress_stage("Collecting changes", counter=True)
411
415
        self._lossy = lossy
412
 
        self.builder = self.branch.get_commit_builder(self.parents,
413
 
            self.config_stack, timestamp, timezone, committer, self.revprops,
414
 
            rev_id, lossy=lossy)
 
416
        self.builder = self.branch.get_commit_builder(
 
417
            self.parents, self.config_stack, timestamp, timezone, committer,
 
418
            self.revprops, rev_id, lossy=lossy)
415
419
 
416
420
        if self.builder.updates_branch and self.bound_branch:
417
421
            self.builder.abort()
446
450
            # Add revision data to the local branch
447
451
            self.rev_id = self.builder.commit(self.message)
448
452
 
449
 
        except Exception as e:
 
453
        except Exception:
450
454
            mutter("aborting commit write group because of exception:")
451
455
            trace.log_exception_quietly()
452
456
            self.builder.abort()
460
464
        self.work_tree.unversion(self.deleted_paths)
461
465
        self._set_progress_stage("Updating the working tree")
462
466
        self.work_tree.update_basis_by_delta(self.rev_id,
463
 
             self.builder.get_basis_delta())
 
467
                                             self.builder.get_basis_delta())
464
468
        self.reporter.completed(new_revno, self.rev_id)
465
469
        self._process_post_hooks(old_revno, new_revno)
466
470
        return self.rev_id
495
499
        else:
496
500
            try:
497
501
                self._process_pre_hooks(old_revno, new_revno)
498
 
            except:
 
502
            except BaseException:
499
503
                # The commit builder will already have updated the branch,
500
504
                # revert it.
501
505
                self.branch.set_last_revision_info(old_revno, old_revid)
508
512
                self.master_branch.tags)
509
513
            if tag_conflicts:
510
514
                warning_lines = ['    ' + name for name, _, _ in tag_conflicts]
511
 
                note( gettext("Conflicting tags in bound branch:\n{0}".format(
512
 
                    "\n".join(warning_lines))) )
 
515
                note(gettext("Conflicting tags in bound branch:\n{0}".format(
 
516
                    "\n".join(warning_lines))))
513
517
 
514
518
    def _select_reporter(self):
515
519
        """Select the CommitReporter to use."""
549
553
        # If the master branch is bound, we must fail
550
554
        master_bound_location = self.master_branch.get_bound_location()
551
555
        if master_bound_location:
552
 
            raise errors.CommitToDoubleBoundBranch(self.branch,
553
 
                    self.master_branch, master_bound_location)
 
556
            raise errors.CommitToDoubleBoundBranch(
 
557
                self.branch, self.master_branch, master_bound_location)
554
558
 
555
559
        # TODO: jam 20051230 We could automatically push local
556
560
        #       commits to the remote branch if they would fit.
562
566
        local_info = self.branch.last_revision_info()
563
567
        if local_info != master_info:
564
568
            raise errors.BoundBranchOutOfDate(self.branch,
565
 
                    self.master_branch)
 
569
                                              self.master_branch)
566
570
 
567
571
        # Now things are ready to change the master branch
568
572
        # so grab the lock
612
616
            # this would be nicer with twisted.python.reflect.namedAny
613
617
            for hook in hooks:
614
618
                result = eval(hook + '(branch, rev_id)',
615
 
                              {'branch':self.branch,
616
 
                               'breezy':breezy,
617
 
                               'rev_id':self.rev_id})
 
619
                              {'branch': self.branch,
 
620
                               'breezy': breezy,
 
621
                               'rev_id': self.rev_id})
618
622
        # process new style post commit hooks
619
623
        self._process_hooks("post_commit", old_revno, new_revno)
620
624
 
640
644
        if hook_name == "pre_commit":
641
645
            future_tree = self.builder.revision_tree()
642
646
            tree_delta = future_tree.changes_from(self.basis_tree,
643
 
                                             include_root=True)
 
647
                                                  include_root=True)
644
648
 
645
649
        for hook in Branch.hooks[hook_name]:
646
650
            # show the running hook in the progress bar. As hooks may
668
672
        mutter("Selecting files for commit with filter %r", specific_files)
669
673
 
670
674
        self._check_strict()
671
 
        iter_changes = self.work_tree.iter_changes(self.basis_tree,
672
 
            specific_files=specific_files)
 
675
        iter_changes = self.work_tree.iter_changes(
 
676
            self.basis_tree, specific_files=specific_files)
673
677
        if self.exclude:
674
678
            iter_changes = filter_excluded(iter_changes, self.exclude)
675
679
        iter_changes = self._filter_iter_changes(iter_changes)
680
684
    def _filter_iter_changes(self, iter_changes):
681
685
        """Process iter_changes.
682
686
 
683
 
        This method reports on the changes in iter_changes to the user, and 
 
687
        This method reports on the changes in iter_changes to the user, and
684
688
        converts 'missing' entries in the iter_changes iterator to 'deleted'
685
689
        entries. 'missing' entries have their
686
690
 
704
708
                deleted_paths.append(change[1][1])
705
709
                # Reset the new path (None) and new versioned flag (False)
706
710
                change = (change[0], (change[1][0], None), change[2],
707
 
                    (change[3][0], False)) + change[4:]
 
711
                          (change[3][0], False)) + change[4:]
708
712
                new_path = change[1][1]
709
713
                versioned = False
710
714
            elif kind == 'tree-reference':
718
722
                    elif old_path is None:
719
723
                        reporter.snapshot_change(gettext('added'), new_path)
720
724
                    elif old_path != new_path:
721
 
                        reporter.renamed(gettext('renamed'), old_path, new_path)
 
725
                        reporter.renamed(gettext('renamed'),
 
726
                                         old_path, new_path)
722
727
                    else:
723
 
                        if (new_path or 
724
 
                            self.work_tree.branch.repository._format.rich_root_data):
 
728
                        if (new_path
 
729
                                or self.work_tree.branch.repository._format.rich_root_data):
725
730
                            # Don't report on changes to '' in non rich root
726
731
                            # repositories.
727
 
                            reporter.snapshot_change(gettext('modified'), new_path)
 
732
                            reporter.snapshot_change(
 
733
                                gettext('modified'), new_path)
728
734
            self._next_progress_entry()
729
735
        # Unversion files that were found to be deleted
730
736
        self.deleted_paths = deleted_paths
748
754
        # finally implement the explicit-caches approach design
749
755
        # a while back - RBC 20070306.
750
756
        if sub_tree.branch.repository.has_same_location(
751
 
            self.work_tree.branch.repository):
 
757
                self.work_tree.branch.repository):
752
758
            sub_tree.branch.repository = \
753
759
                self.work_tree.branch.repository
754
760
        try:
755
761
            return sub_tree.commit(message=None, revprops=self.revprops,
756
 
                recursive=self.recursive,
757
 
                message_callback=self.message_callback,
758
 
                timestamp=self.timestamp, timezone=self.timezone,
759
 
                committer=self.committer,
760
 
                allow_pointless=self.allow_pointless,
761
 
                strict=self.strict, verbose=self.verbose,
762
 
                local=self.local, reporter=self.reporter)
 
762
                                   recursive=self.recursive,
 
763
                                   message_callback=self.message_callback,
 
764
                                   timestamp=self.timestamp,
 
765
                                   timezone=self.timezone,
 
766
                                   committer=self.committer,
 
767
                                   allow_pointless=self.allow_pointless,
 
768
                                   strict=self.strict, verbose=self.verbose,
 
769
                                   local=self.local, reporter=self.reporter)
763
770
        except PointlessCommit:
764
771
            return self.work_tree.get_reference_revision(path)
765
772
 
781
788
    def _emit_progress(self):
782
789
        if self.pb_entries_count is not None:
783
790
            text = gettext("{0} [{1}] - Stage").format(self.pb_stage_name,
784
 
                self.pb_entries_count)
 
791
                                                       self.pb_entries_count)
785
792
        else:
786
793
            text = gettext("%s - Stage") % (self.pb_stage_name, )
787
794
        self.pb.update(text, self.pb_stage_count, self.pb_stage_total)