/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 foreign/__init__.py

Simplify checks against base hex sha a bit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2009 Jelmer Vernooij <jelmer@samba.org>
 
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
 
 
19
from bzrlib import (
 
20
    errors,
 
21
    )
 
22
from bzrlib.commands import (
 
23
    Command,
 
24
    Option,
 
25
    )
 
26
 
 
27
 
 
28
class FakeControlFiles(object):
 
29
    """Dummy implementation of ControlFiles.
 
30
    
 
31
    This is required as some code relies on controlfiles being 
 
32
    available."""
 
33
    def get_utf8(self, name):
 
34
        raise errors.NoSuchFile(name)
 
35
 
 
36
    def get(self, name):
 
37
        raise errors.NoSuchFile(name)
 
38
 
 
39
    def break_lock(self):
 
40
        pass
 
41
 
 
42
 
 
43
class cmd_foreign_mapping_upgrade(Command):
 
44
    """Upgrade revisions mapped from a foreign version control system.
 
45
    
 
46
    This will change the identity of revisions whose parents 
 
47
    were mapped from revisions in the other version control system.
 
48
 
 
49
    You are recommended to run "bzr check" in the local repository 
 
50
    after running this command.
 
51
    """
 
52
    aliases = ['svn-upgrade']
 
53
    takes_args = ['from_repository?']
 
54
    takes_options = ['verbose', 
 
55
            Option("idmap-file", help="Write map with old and new revision ids.", type=str)]
 
56
 
 
57
    def run(self, from_repository=None, verbose=False, idmap_file=None):
 
58
        from upgrade import upgrade_branch, upgrade_workingtree
 
59
        from bzrlib.branch import Branch
 
60
        from bzrlib.errors import NoWorkingTree, BzrCommandError
 
61
        from bzrlib.repository import Repository
 
62
        from bzrlib.trace import info
 
63
        from bzrlib.workingtree import WorkingTree
 
64
        try:
 
65
            wt_to = WorkingTree.open(".")
 
66
            branch_to = wt_to.branch
 
67
        except NoWorkingTree:
 
68
            wt_to = None
 
69
            branch_to = Branch.open(".")
 
70
 
 
71
        stored_loc = branch_to.get_parent()
 
72
        if from_repository is None:
 
73
            if stored_loc is None:
 
74
                raise BzrCommandError("No pull location known or"
 
75
                                             " specified.")
 
76
            else:
 
77
                import bzrlib.urlutils as urlutils
 
78
                display_url = urlutils.unescape_for_display(stored_loc,
 
79
                        self.outf.encoding)
 
80
                self.outf.write("Using saved location: %s\n" % display_url)
 
81
                from_repository = Branch.open(stored_loc).repository
 
82
        else:
 
83
            from_repository = Repository.open(from_repository)
 
84
 
 
85
        vcs = getattr(from_repository, "vcs", None)
 
86
        if vcs is None:
 
87
            raise BzrCommandError("Repository at %s is not a foreign repository.a" % from_repository.base)
 
88
 
 
89
        new_mapping = from_repository.get_mapping()
 
90
 
 
91
        if wt_to is not None:
 
92
            renames = upgrade_workingtree(wt_to, from_repository, 
 
93
                                          new_mapping=new_mapping,
 
94
                                          allow_changes=True, verbose=verbose)
 
95
        else:
 
96
            renames = upgrade_branch(branch_to, from_repository, 
 
97
                                     new_mapping=new_mapping,
 
98
                                     allow_changes=True, verbose=verbose)
 
99
 
 
100
        if renames == {}:
 
101
            info("Nothing to do.")
 
102
 
 
103
        if idmap_file is not None:
 
104
            f = open(idmap_file, 'w')
 
105
            try:
 
106
                for oldid, newid in renames.iteritems():
 
107
                    f.write("%s\t%s\n" % (oldid, newid))
 
108
            finally:
 
109
                f.close()
 
110
 
 
111
        if wt_to is not None:
 
112
            wt_to.set_last_revision(branch_to.last_revision())
 
113
 
 
114
 
 
115
def test_suite():
 
116
    from unittest import TestSuite
 
117
    from bzrlib.tests import TestUtil
 
118
    loader = TestUtil.TestLoader()
 
119
    suite = TestSuite()
 
120
    testmod_names = ['test_versionedfiles', ]
 
121
    suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
 
122
    return suite