/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/workingtree.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:
101
101
        self.controldir = _controldir
102
102
        if not _internal:
103
103
            raise errors.BzrError("Please use controldir.open_workingtree or "
104
 
                "WorkingTree.open() to obtain a WorkingTree.")
 
104
                                  "WorkingTree.open() to obtain a WorkingTree.")
105
105
        basedir = osutils.safe_unicode(basedir)
106
106
        mutter("opening working tree %r", basedir)
107
107
        if branch is not None:
273
273
        # self.relpath exists as a "thunk" to osutils, but canonical_relpath
274
274
        # doesn't - fix that up here before we enter the loop.
275
275
        if canonicalize:
276
 
            fixer = lambda p: osutils.canonical_relpath(self.basedir, p)
 
276
            def fixer(p):
 
277
                return osutils.canonical_relpath(self.basedir, p)
277
278
        else:
278
279
            fixer = self.relpath
279
280
        for filename in file_list:
296
297
        def list_current(transport):
297
298
            return [d for d in transport.list_dir('')
298
299
                    if not controldir.is_control_filename(d)]
 
300
 
299
301
        def evaluate(controldir):
300
302
            try:
301
303
                tree = controldir.open_workingtree()
305
307
                return True, tree
306
308
        t = transport.get_transport(location)
307
309
        iterator = controldir.ControlDir.find_controldirs(t, evaluate=evaluate,
308
 
                                              list_current=list_current)
 
310
                                                          list_current=list_current)
309
311
        return [tr for tr in iterator if tr is not None]
310
312
 
311
313
    def __repr__(self):
329
331
            # in the future this should return the tree for
330
332
            # 'empty:' - the implicit root empty tree.
331
333
            return self.branch.repository.revision_tree(
332
 
                       _mod_revision.NULL_REVISION)
 
334
                _mod_revision.NULL_REVISION)
333
335
        try:
334
336
            return self.revision_tree(revision_id)
335
337
        except errors.NoSuchRevision:
347
349
                raise
348
350
            # the basis tree is a ghost so return an empty tree.
349
351
            return self.branch.repository.revision_tree(
350
 
                       _mod_revision.NULL_REVISION)
 
352
                _mod_revision.NULL_REVISION)
351
353
 
352
354
    def relpath(self, path):
353
355
        """Return the local path portion from a given path.
445
447
                    other_tree = self.revision_tree(revision_id)
446
448
                except errors.NoSuchRevision:
447
449
                    other_tree = self.branch.repository.revision_tree(
448
 
                            revision_id)
 
450
                        revision_id)
449
451
 
450
452
                merge.transform_tree(tree, other_tree)
451
453
                if revision_id == _mod_revision.NULL_REVISION:
492
494
        with self.lock_write():
493
495
            parents = self.get_parent_ids() + [revision_id]
494
496
            self.set_parent_ids(parents, allow_leftmost_as_ghost=len(parents) > 1
495
 
                or allow_leftmost_as_ghost)
 
497
                                or allow_leftmost_as_ghost)
496
498
 
497
499
    def add_parent_tree(self, parent_tuple, allow_leftmost_as_ghost=False):
498
500
        """Add revision_id, tree tuple as a parent.
514
516
                # was.
515
517
                allow_leftmost_as_ghost = True
516
518
            self.set_parent_ids(parent_ids,
517
 
                allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
519
                                allow_leftmost_as_ghost=allow_leftmost_as_ghost)
518
520
 
519
521
    def add_pending_merge(self, *revision_ids):
520
522
        with self.lock_tree_write():
531
533
                self.set_parent_ids(parents, allow_leftmost_as_ghost=True)
532
534
 
533
535
    def path_content_summary(self, path, _lstat=os.lstat,
534
 
        _mapper=osutils.file_kind_from_stat_mode):
 
536
                             _mapper=osutils.file_kind_from_stat_mode):
535
537
        """See Tree.path_content_summary."""
536
538
        abspath = self.abspath(path)
537
539
        try:
573
575
        if len(revision_ids) > 0:
574
576
            leftmost_id = revision_ids[0]
575
577
            if (not allow_leftmost_as_ghost and not
576
 
                self.branch.repository.has_revision(leftmost_id)):
 
578
                    self.branch.repository.has_revision(leftmost_id)):
577
579
                raise errors.GhostRevisionUnusableHere(leftmost_id)
578
580
 
579
581
    def _set_merges_from_parent_ids(self, parent_ids):
580
582
        merges = parent_ids[1:]
581
583
        self._transport.put_bytes('pending-merges', b'\n'.join(merges),
582
 
            mode=self.controldir._get_file_mode())
 
584
                                  mode=self.controldir._get_file_mode())
583
585
 
584
586
    def _filter_parent_ids_by_ancestry(self, revision_ids):
585
587
        """Check that all merged revisions are proper 'heads'.
597
599
                new_revision_ids.append(revision_id)
598
600
        if new_revision_ids != revision_ids:
599
601
            mutter('requested to set revision_ids = %s,'
600
 
                         ' but filtered to %s', revision_ids, new_revision_ids)
 
602
                   ' but filtered to %s', revision_ids, new_revision_ids)
601
603
        return new_revision_ids
602
604
 
603
605
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
614
616
        """
615
617
        with self.lock_tree_write():
616
618
            self._check_parents_for_ghosts(revision_ids,
617
 
                allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
619
                                           allow_leftmost_as_ghost=allow_leftmost_as_ghost)
618
620
            for revision_id in revision_ids:
619
621
                _mod_revision.check_not_reserved_id(revision_id)
620
622
 
869
871
                with basis_tree.lock_read():
870
872
                    new_basis_tree = self.branch.basis_tree()
871
873
                    merge.merge_inner(
872
 
                                self.branch,
873
 
                                new_basis_tree,
874
 
                                basis_tree,
875
 
                                this_tree=self,
876
 
                                change_reporter=change_reporter,
877
 
                                show_base=show_base)
 
874
                        self.branch,
 
875
                        new_basis_tree,
 
876
                        basis_tree,
 
877
                        this_tree=self,
 
878
                        change_reporter=change_reporter,
 
879
                        show_base=show_base)
878
880
                    basis_root_id = basis_tree.get_root_id()
879
881
                    new_root_id = new_basis_tree.get_root_id()
880
882
                    if new_root_id is not None and basis_root_id != new_root_id:
894
896
                merges = self.get_parent_ids()[1:]
895
897
                parent_trees.extend([
896
898
                    (parent, repository.revision_tree(parent)) for
897
 
                     parent in merges])
 
899
                    parent in merges])
898
900
                self.set_parent_trees(parent_trees)
899
901
            return count
900
902
 
901
903
    def put_file_bytes_non_atomic(self, path, bytes, file_id=None):
902
904
        """See MutableTree.put_file_bytes_non_atomic."""
903
905
        with self.lock_write(), open(self.abspath(path), 'wb') as stream:
904
 
                stream.write(bytes)
 
906
            stream.write(bytes)
905
907
 
906
908
    def extras(self):
907
909
        """Yield all unversioned files in this WorkingTree.
1188
1190
            if not _mod_revision.is_null(old_tip) and old_tip != last_rev:
1189
1191
                # the branch we are bound to was updated
1190
1192
                # merge those changes in first
1191
 
                base_tree  = self.basis_tree()
 
1193
                base_tree = self.basis_tree()
1192
1194
                other_tree = self.branch.repository.revision_tree(old_tip)
1193
1195
                nb_conflicts = merge.merge_inner(self.branch, other_tree,
1194
1196
                                                 base_tree, this_tree=self,
1283
1285
            for conflict in self.conflicts():
1284
1286
                path = self.id2path(conflict.file_id)
1285
1287
                if (conflict.typestring != 'text conflict' or
1286
 
                    self.kind(path) != 'file'):
 
1288
                        self.kind(path) != 'file'):
1287
1289
                    un_resolved.append(conflict)
1288
1290
                    continue
1289
1291
                with open(self.abspath(path), 'rb') as my_file:
1324
1326
        """See Tree._get_rules_searcher."""
1325
1327
        if self._rules_searcher is None:
1326
1328
            self._rules_searcher = super(WorkingTree,
1327
 
                self)._get_rules_searcher(default_searcher)
 
1329
                                         self)._get_rules_searcher(default_searcher)
1328
1330
        return self._rules_searcher
1329
1331
 
1330
1332
    def get_shelf_manager(self):
1379
1381
    def get_default(self):
1380
1382
        """Return the current default format."""
1381
1383
        if (self._default_format_key is not None and
1382
 
            self._default_format is None):
 
1384
                self._default_format is None):
1383
1385
            self._default_format = self.get(self._default_format_key)
1384
1386
        return self._default_format
1385
1387
 
1498
1500
 
1499
1501
 
1500
1502
format_registry.register_lazy(b"Bazaar Working Tree Format 4 (bzr 0.15)\n",
1501
 
    "breezy.bzr.workingtree_4", "WorkingTreeFormat4")
 
1503
                              "breezy.bzr.workingtree_4", "WorkingTreeFormat4")
1502
1504
format_registry.register_lazy(b"Bazaar Working Tree Format 5 (bzr 1.11)\n",
1503
 
    "breezy.bzr.workingtree_4", "WorkingTreeFormat5")
 
1505
                              "breezy.bzr.workingtree_4", "WorkingTreeFormat5")
1504
1506
format_registry.register_lazy(b"Bazaar Working Tree Format 6 (bzr 1.14)\n",
1505
 
    "breezy.bzr.workingtree_4", "WorkingTreeFormat6")
 
1507
                              "breezy.bzr.workingtree_4", "WorkingTreeFormat6")
1506
1508
format_registry.register_lazy(b"Bazaar-NG Working Tree format 3",
1507
 
    "breezy.bzr.workingtree_3", "WorkingTreeFormat3")
 
1509
                              "breezy.bzr.workingtree_3", "WorkingTreeFormat3")
1508
1510
format_registry.set_default_key(b"Bazaar Working Tree Format 6 (bzr 1.14)\n")