/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: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

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