/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.205.34 by Jelmer Vernooij
s/get_revision/get_inventory.
1
# Copyright (C) 2008-2009 Jelmer Vernooij <jelmer@samba.org>
0.205.1 by Jelmer Vernooij
Import utility functions for foreign branches.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Foreign branch utilities."""
18
0.205.44 by Jelmer Vernooij
Fix formatting.
19
from bzrlib import (
20
    errors,
21
    )
22
from bzrlib.commands import (
23
    Command,
24
    Option,
25
    )
0.205.23 by Jelmer Vernooij
Add more docstrings.
26
0.205.6 by Jelmer Vernooij
Import FakeControlFiles.
27
0.227.1 by Jelmer Vernooij
Import foreign-mapping-upgrade.
28
class cmd_foreign_mapping_upgrade(Command):
0.205.42 by Jelmer Vernooij
Fix one-line summary.
29
    """Upgrade revisions mapped from a foreign version control system.
0.227.1 by Jelmer Vernooij
Import foreign-mapping-upgrade.
30
    
31
    This will change the identity of revisions whose parents 
32
    were mapped from revisions in the other version control system.
33
34
    You are recommended to run "bzr check" in the local repository 
35
    after running this command.
36
    """
37
    aliases = ['svn-upgrade']
38
    takes_args = ['from_repository?']
39
    takes_options = ['verbose', 
40
            Option("idmap-file", help="Write map with old and new revision ids.", type=str)]
41
42
    def run(self, from_repository=None, verbose=False, idmap_file=None):
43
        from upgrade import upgrade_branch, upgrade_workingtree
44
        from bzrlib.branch import Branch
45
        from bzrlib.errors import NoWorkingTree, BzrCommandError
46
        from bzrlib.repository import Repository
47
        from bzrlib.trace import info
48
        from bzrlib.workingtree import WorkingTree
49
        try:
50
            wt_to = WorkingTree.open(".")
51
            branch_to = wt_to.branch
52
        except NoWorkingTree:
53
            wt_to = None
54
            branch_to = Branch.open(".")
55
56
        stored_loc = branch_to.get_parent()
57
        if from_repository is None:
58
            if stored_loc is None:
59
                raise BzrCommandError("No pull location known or"
60
                                             " specified.")
61
            else:
62
                import bzrlib.urlutils as urlutils
63
                display_url = urlutils.unescape_for_display(stored_loc,
64
                        self.outf.encoding)
65
                self.outf.write("Using saved location: %s\n" % display_url)
66
                from_repository = Branch.open(stored_loc).repository
67
        else:
68
            from_repository = Repository.open(from_repository)
69
70
        vcs = getattr(from_repository, "vcs", None)
71
        if vcs is None:
72
            raise BzrCommandError("Repository at %s is not a foreign repository.a" % from_repository.base)
73
74
        new_mapping = from_repository.get_mapping()
75
76
        if wt_to is not None:
77
            renames = upgrade_workingtree(wt_to, from_repository, 
78
                                          new_mapping=new_mapping,
79
                                          allow_changes=True, verbose=verbose)
80
        else:
81
            renames = upgrade_branch(branch_to, from_repository, 
82
                                     new_mapping=new_mapping,
83
                                     allow_changes=True, verbose=verbose)
84
85
        if renames == {}:
86
            info("Nothing to do.")
87
88
        if idmap_file is not None:
89
            f = open(idmap_file, 'w')
90
            try:
91
                for oldid, newid in renames.iteritems():
92
                    f.write("%s\t%s\n" % (oldid, newid))
93
            finally:
94
                f.close()
95
96
        if wt_to is not None:
97
            wt_to.set_last_revision(branch_to.last_revision())
98
99
0.205.15 by Jelmer Vernooij
Add test_suite function.
100
def test_suite():
101
    from unittest import TestSuite
102
    from bzrlib.tests import TestUtil
103
    loader = TestUtil.TestLoader()
104
    suite = TestSuite()
0.205.19 by Jelmer Vernooij
import bzr-svn improvements.
105
    testmod_names = ['test_versionedfiles', ]
0.205.15 by Jelmer Vernooij
Add test_suite function.
106
    suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
107
    return suite