/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 commands.py

Merge bzr-foreign.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# along with this program; if not, write to the Free Software
19
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
20
 
21
 
 
22
21
"""Git-specific subcommands for Bazaar."""
23
22
 
24
23
from bzrlib.commands import Command
52
51
        server = TCPGitServer(backend, 'localhost')
53
52
        server.serve_forever()
54
53
 
 
54
 
55
55
class cmd_git_import(Command):
56
56
    """Import all branches from a git repository.
57
57
 
58
58
    """
59
59
 
60
 
    takes_args = ["src_location", "dest_location"]
 
60
    takes_args = ["src_location", "dest_location?"]
61
61
 
62
 
    def run(self, src_location, dest_location):
63
 
        from bzrlib.bzrdir import BzrDir, format_registry
64
 
        from bzrlib.errors import NoRepositoryPresent, NotBranchError
 
62
    def run(self, src_location, dest_location=None):
 
63
        import os
 
64
        from bzrlib import (
 
65
            ui,
 
66
            urlutils,
 
67
            )
 
68
        from bzrlib.bzrdir import (
 
69
            BzrDir,
 
70
            format_registry,
 
71
            )
 
72
        from bzrlib.errors import (
 
73
            BzrCommandError,
 
74
            NoRepositoryPresent,
 
75
            NotBranchError,
 
76
            )
65
77
        from bzrlib.repository import Repository
 
78
        from bzrlib.plugins.git.fetch import InterGitNonGitRepository
 
79
        from bzrlib.plugins.git.repository import GitRepository
 
80
 
 
81
        if dest_location is None:
 
82
            dest_location = os.path.basename(src_location.rstrip("/\\"))
 
83
 
66
84
        source_repo = Repository.open(src_location)
67
 
        format = format_registry.make_bzrdir('rich-root-pack')
 
85
        if not isinstance(source_repo, GitRepository):
 
86
            raise BzrCommandError("%r is not a git repository" % src_location)
 
87
        format = format_registry.make_bzrdir("1.9-rich-root")
68
88
        try:
69
89
            target_bzrdir = BzrDir.open(dest_location)
70
90
        except NotBranchError:
74
94
        except NoRepositoryPresent:
75
95
            target_repo = target_bzrdir.create_repository(shared=True)
76
96
 
77
 
        target_repo.fetch(source_repo)
78
 
        for name, ref in source_repo._git.heads().iteritems():
79
 
            head_loc = os.path.join(dest_location, name)
80
 
            try:
81
 
                head_bzrdir = BzrDir.open(head_loc)
82
 
            except NotBranchError:
83
 
                head_bzrdir = BzrDir.create(head_loc, format=format)
84
 
            try:
85
 
                head_branch = head_bzrdir.open_branch()
86
 
            except NotBranchError:
87
 
                head_branch = head_bzrdir.create_branch()
88
 
            head_branch.generate_revision_history(source_repo.get_mapping().revision_id_foreign_to_bzr(ref))
 
97
        interrepo = InterGitNonGitRepository(source_repo, target_repo)
 
98
        mapping = source_repo.get_mapping()
 
99
        refs = interrepo.fetch_refs()
 
100
        pb = ui.ui_factory.nested_progress_bar()
 
101
        try:
 
102
            for i, (name, ref) in enumerate(refs.iteritems()):
 
103
                pb.update("creating branches", i, len(refs))
 
104
                if name.endswith("^{}"):
 
105
                    continue
 
106
                head_loc = os.path.join(dest_location, name)
 
107
                try:
 
108
                    head_bzrdir = BzrDir.open(head_loc)
 
109
                except NotBranchError:
 
110
                    parent_path = urlutils.dirname(head_loc)
 
111
                    if not os.path.isdir(parent_path):
 
112
                        os.makedirs(parent_path)
 
113
                    head_bzrdir = BzrDir.create(head_loc, format=format)
 
114
                try:
 
115
                    head_branch = head_bzrdir.open_branch()
 
116
                except NotBranchError:
 
117
                    head_branch = head_bzrdir.create_branch()
 
118
                if ("%s^{}" % name) in refs:
 
119
                    revid = mapping.revision_id_foreign_to_bzr(refs["%s^{}" % name])
 
120
                else:
 
121
                    revid = mapping.revision_id_foreign_to_bzr(ref)
 
122
                head_branch.generate_revision_history(revid)
 
123
        finally:
 
124
            pb.finished()
89
125