/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.branch import (
23
    Branch,
24
    )
25
from bzrlib.commands import (
26
    Command,
27
    Option,
28
    )
0.205.23 by Jelmer Vernooij
Add more docstrings.
29
0.205.6 by Jelmer Vernooij
Import FakeControlFiles.
30
0.207.1 by Jelmer Vernooij
Add ForeignBranch class, make dpush fallback to regular push.
31
class ForeignBranch(Branch):
0.205.18 by Jelmer Vernooij
Add docstrings.
32
    """Branch that exists in a foreign version control system."""
0.207.1 by Jelmer Vernooij
Add ForeignBranch class, make dpush fallback to regular push.
33
34
    def __init__(self, mapping):
0.205.21 by Jelmer Vernooij
Only register foreign property show function once.
35
        self.mapping = mapping
0.207.1 by Jelmer Vernooij
Add ForeignBranch class, make dpush fallback to regular push.
36
        super(ForeignBranch, self).__init__()
37
38
    def dpull(self, source, stop_revision=None):
0.205.18 by Jelmer Vernooij
Add docstrings.
39
        """Pull deltas from another branch.
40
41
        :note: This does not, like pull, retain the revision ids from 
0.205.29 by Jelmer Vernooij
Fix updating of file ids.
42
            the source branch and will, rather than adding bzr-specific 
43
            metadata, push only those semantics of the revision that can be 
44
            natively represented in this branch.
0.205.18 by Jelmer Vernooij
Add docstrings.
45
46
        :param source: Source branch
47
        :param stop_revision: Revision to pull, defaults to last revision.
0.205.29 by Jelmer Vernooij
Fix updating of file ids.
48
        :return: Revision id map and file id map
0.205.18 by Jelmer Vernooij
Add docstrings.
49
        """
0.205.25 by Jelmer Vernooij
Fix function names.
50
        raise NotImplementedError(self.dpull)
0.205.22 by Jelmer Vernooij
Merge improvements from bzr-svn.
51
52
0.205.6 by Jelmer Vernooij
Import FakeControlFiles.
53
class FakeControlFiles(object):
54
    """Dummy implementation of ControlFiles.
55
    
56
    This is required as some code relies on controlfiles being 
57
    available."""
58
    def get_utf8(self, name):
59
        raise errors.NoSuchFile(name)
60
61
    def get(self, name):
62
        raise errors.NoSuchFile(name)
63
64
    def break_lock(self):
65
        pass
66
0.205.7 by Jelmer Vernooij
Import dpush.
67
0.227.1 by Jelmer Vernooij
Import foreign-mapping-upgrade.
68
class cmd_foreign_mapping_upgrade(Command):
0.205.42 by Jelmer Vernooij
Fix one-line summary.
69
    """Upgrade revisions mapped from a foreign version control system.
0.227.1 by Jelmer Vernooij
Import foreign-mapping-upgrade.
70
    
71
    This will change the identity of revisions whose parents 
72
    were mapped from revisions in the other version control system.
73
74
    You are recommended to run "bzr check" in the local repository 
75
    after running this command.
76
    """
77
    aliases = ['svn-upgrade']
78
    takes_args = ['from_repository?']
79
    takes_options = ['verbose', 
80
            Option("idmap-file", help="Write map with old and new revision ids.", type=str)]
81
82
    def run(self, from_repository=None, verbose=False, idmap_file=None):
83
        from upgrade import upgrade_branch, upgrade_workingtree
84
        from bzrlib.branch import Branch
85
        from bzrlib.errors import NoWorkingTree, BzrCommandError
86
        from bzrlib.repository import Repository
87
        from bzrlib.trace import info
88
        from bzrlib.workingtree import WorkingTree
89
        try:
90
            wt_to = WorkingTree.open(".")
91
            branch_to = wt_to.branch
92
        except NoWorkingTree:
93
            wt_to = None
94
            branch_to = Branch.open(".")
95
96
        stored_loc = branch_to.get_parent()
97
        if from_repository is None:
98
            if stored_loc is None:
99
                raise BzrCommandError("No pull location known or"
100
                                             " specified.")
101
            else:
102
                import bzrlib.urlutils as urlutils
103
                display_url = urlutils.unescape_for_display(stored_loc,
104
                        self.outf.encoding)
105
                self.outf.write("Using saved location: %s\n" % display_url)
106
                from_repository = Branch.open(stored_loc).repository
107
        else:
108
            from_repository = Repository.open(from_repository)
109
110
        vcs = getattr(from_repository, "vcs", None)
111
        if vcs is None:
112
            raise BzrCommandError("Repository at %s is not a foreign repository.a" % from_repository.base)
113
114
        new_mapping = from_repository.get_mapping()
115
116
        if wt_to is not None:
117
            renames = upgrade_workingtree(wt_to, from_repository, 
118
                                          new_mapping=new_mapping,
119
                                          allow_changes=True, verbose=verbose)
120
        else:
121
            renames = upgrade_branch(branch_to, from_repository, 
122
                                     new_mapping=new_mapping,
123
                                     allow_changes=True, verbose=verbose)
124
125
        if renames == {}:
126
            info("Nothing to do.")
127
128
        if idmap_file is not None:
129
            f = open(idmap_file, 'w')
130
            try:
131
                for oldid, newid in renames.iteritems():
132
                    f.write("%s\t%s\n" % (oldid, newid))
133
            finally:
134
                f.close()
135
136
        if wt_to is not None:
137
            wt_to.set_last_revision(branch_to.last_revision())
138
139
0.205.15 by Jelmer Vernooij
Add test_suite function.
140
def test_suite():
141
    from unittest import TestSuite
142
    from bzrlib.tests import TestUtil
143
    loader = TestUtil.TestLoader()
144
    suite = TestSuite()
0.205.19 by Jelmer Vernooij
import bzr-svn improvements.
145
    testmod_names = ['test_versionedfiles', ]
0.205.15 by Jelmer Vernooij
Add test_suite function.
146
    suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
147
    return suite
0.205.7 by Jelmer Vernooij
Import dpush.
148
0.205.18 by Jelmer Vernooij
Add docstrings.
149
0.207.2 by Jelmer Vernooij
Import escape commit message function.
150
def escape_commit_message(message):
151
    """Replace xml-incompatible control characters."""
152
    if message is None:
153
        return None
154
    import re
155
    # FIXME: RBC 20060419 this should be done by the revision
156
    # serialiser not by commit. Then we can also add an unescaper
157
    # in the deserializer and start roundtripping revision messages
158
    # precisely. See repository_implementations/test_repository.py
159
    
160
    # Python strings can include characters that can't be
161
    # represented in well-formed XML; escape characters that
162
    # aren't listed in the XML specification
163
    # (http://www.w3.org/TR/REC-xml/#NT-Char).
164
    message, _ = re.subn(
165
        u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]+',
166
        lambda match: match.group(0).encode('unicode_escape'),
167
        message)
168
    return message
169
0.205.19 by Jelmer Vernooij
import bzr-svn improvements.
170