~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Martin Pool
  • Date: 2010-02-25 06:17:27 UTC
  • mfrom: (5055 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5057.
  • Revision ID: mbp@sourcefrog.net-20100225061727-4sd9lt0qmdc6087t
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
29
29
 
30
30
import os
31
31
import sys
 
32
import warnings
32
33
 
33
34
from bzrlib.lazy_import import lazy_import
34
35
lazy_import(globals(), """
354
355
                for subdir in sorted(subdirs, reverse=True):
355
356
                    pending.append(current_transport.clone(subdir))
356
357
 
 
358
    def list_branches(self):
 
359
        """Return a sequence of all branches local to this control directory.
 
360
 
 
361
        """
 
362
        try:
 
363
            return [self.open_branch()]
 
364
        except errors.NotBranchError:
 
365
            return []
 
366
 
357
367
    @staticmethod
358
368
    def find_branches(transport):
359
369
        """Find all branches under a transport.
371
381
            except errors.NoRepositoryPresent:
372
382
                pass
373
383
            else:
374
 
                return False, (None, repository)
375
 
            try:
376
 
                branch = bzrdir.open_branch()
377
 
            except errors.NotBranchError:
378
 
                return True, (None, None)
379
 
            else:
380
 
                return True, (branch, None)
381
 
        branches = []
382
 
        for branch, repo in BzrDir.find_bzrdirs(transport, evaluate=evaluate):
 
384
                return False, ([], repository)
 
385
            return True, (bzrdir.list_branches(), None)
 
386
        ret = []
 
387
        for branches, repo in BzrDir.find_bzrdirs(transport,
 
388
                                                  evaluate=evaluate):
383
389
            if repo is not None:
384
 
                branches.extend(repo.find_branches())
385
 
            if branch is not None:
386
 
                branches.append(branch)
387
 
        return branches
 
390
                ret.extend(repo.find_branches())
 
391
            if branches is not None:
 
392
                ret.extend(branches)
 
393
        return ret
388
394
 
389
395
    def destroy_repository(self):
390
396
        """Destroy the repository in this BzrDir"""
574
580
 
575
581
        :return: Tuple with old path name and new path name
576
582
        """
 
583
        def name_gen(base='backup.bzr'):
 
584
            counter = 1
 
585
            name = "%s.~%d~" % (base, counter)
 
586
            while self.root_transport.has(name):
 
587
                counter += 1
 
588
                name = "%s.~%d~" % (base, counter)
 
589
            return name
 
590
 
 
591
        backup_dir=name_gen()
577
592
        pb = ui.ui_factory.nested_progress_bar()
578
593
        try:
579
594
            # FIXME: bug 300001 -- the backup fails if the backup directory
583
598
            # FIXME: bug 262450 -- the backup directory should have the same
584
599
            # permissions as the .bzr directory (probably a bug in copy_tree)
585
600
            old_path = self.root_transport.abspath('.bzr')
586
 
            new_path = self.root_transport.abspath('backup.bzr')
 
601
            new_path = self.root_transport.abspath(backup_dir)
587
602
            ui.ui_factory.note('making backup of %s\n  to %s' % (old_path, new_path,))
588
 
            self.root_transport.copy_tree('.bzr', 'backup.bzr')
 
603
            self.root_transport.copy_tree('.bzr', backup_dir)
589
604
            return (old_path, new_path)
590
605
        finally:
591
606
            pb.finished()
2609
2624
    def convert(self, to_convert, pb):
2610
2625
        """See Converter.convert()."""
2611
2626
        self.bzrdir = to_convert
2612
 
        self.pb = pb
2613
 
        ui.ui_factory.note('starting upgrade from format 4 to 5')
2614
 
        if isinstance(self.bzrdir.transport, local.LocalTransport):
2615
 
            self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
2616
 
        self._convert_to_weaves()
2617
 
        return BzrDir.open(self.bzrdir.root_transport.base)
 
2627
        if pb is not None:
 
2628
            warnings.warn("pb parameter to convert() is deprecated")
 
2629
        self.pb = ui.ui_factory.nested_progress_bar()
 
2630
        try:
 
2631
            ui.ui_factory.note('starting upgrade from format 4 to 5')
 
2632
            if isinstance(self.bzrdir.transport, local.LocalTransport):
 
2633
                self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
 
2634
            self._convert_to_weaves()
 
2635
            return BzrDir.open(self.bzrdir.root_transport.base)
 
2636
        finally:
 
2637
            self.pb.finished()
2618
2638
 
2619
2639
    def _convert_to_weaves(self):
2620
2640
        ui.ui_factory.note('note: upgrade may be faster if all store files are ungzipped first')
2861
2881
    def convert(self, to_convert, pb):
2862
2882
        """See Converter.convert()."""
2863
2883
        self.bzrdir = to_convert
2864
 
        self.pb = pb
2865
 
        ui.ui_factory.note('starting upgrade from format 5 to 6')
2866
 
        self._convert_to_prefixed()
2867
 
        return BzrDir.open(self.bzrdir.root_transport.base)
 
2884
        pb = ui.ui_factory.nested_progress_bar()
 
2885
        try:
 
2886
            ui.ui_factory.note('starting upgrade from format 5 to 6')
 
2887
            self._convert_to_prefixed()
 
2888
            return BzrDir.open(self.bzrdir.root_transport.base)
 
2889
        finally:
 
2890
            pb.finished()
2868
2891
 
2869
2892
    def _convert_to_prefixed(self):
2870
2893
        from bzrlib.store import TransportStore
2903
2926
        from bzrlib.repofmt.weaverepo import RepositoryFormat7
2904
2927
        from bzrlib.branch import BzrBranchFormat5
2905
2928
        self.bzrdir = to_convert
2906
 
        self.pb = pb
 
2929
        self.pb = ui.ui_factory.nested_progress_bar()
2907
2930
        self.count = 0
2908
2931
        self.total = 20 # the steps we know about
2909
2932
        self.garbage_inventories = []
2989
3012
            'branch-format',
2990
3013
            BzrDirMetaFormat1().get_format_string(),
2991
3014
            mode=self.file_mode)
 
3015
        self.pb.finished()
2992
3016
        return BzrDir.open(self.bzrdir.root_transport.base)
2993
3017
 
2994
3018
    def make_lock(self, name):
3030
3054
    def convert(self, to_convert, pb):
3031
3055
        """See Converter.convert()."""
3032
3056
        self.bzrdir = to_convert
3033
 
        self.pb = pb
 
3057
        self.pb = ui.ui_factory.nested_progress_bar()
3034
3058
        self.count = 0
3035
3059
        self.total = 1
3036
3060
        self.step('checking repository format')
3044
3068
                ui.ui_factory.note('starting repository conversion')
3045
3069
                converter = CopyConverter(self.target_format.repository_format)
3046
3070
                converter.convert(repo, pb)
3047
 
        try:
3048
 
            branch = self.bzrdir.open_branch()
3049
 
        except errors.NotBranchError:
3050
 
            pass
3051
 
        else:
 
3071
        for branch in self.bzrdir.list_branches():
3052
3072
            # TODO: conversions of Branch and Tree should be done by
3053
3073
            # InterXFormat lookups/some sort of registry.
3054
3074
            # Avoid circular imports
3096
3116
                isinstance(self.target_format.workingtree_format,
3097
3117
                    workingtree_4.WorkingTreeFormat6)):
3098
3118
                workingtree_4.Converter4or5to6().convert(tree)
 
3119
        self.pb.finished()
3099
3120
        return to_convert
3100
3121
 
3101
3122