/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

Fix git-import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
    takes_args = ["src_location", "dest_location?"]
61
61
 
62
62
    def run(self, src_location, dest_location=None):
63
 
        from bzrlib.bzrdir import BzrDir, format_registry
 
63
        import os
 
64
        from bzrlib import (
 
65
            ui,
 
66
            urlutils,
 
67
            )
 
68
        from bzrlib.bzrdir import (
 
69
            BzrDir,
 
70
            format_registry,
 
71
            )
64
72
        from bzrlib.errors import (
65
73
            BzrCommandError,
66
74
            NoRepositoryPresent,
67
75
            NotBranchError,
68
76
            )
69
77
        from bzrlib.repository import Repository
70
 
        import os
 
78
        from bzrlib.plugins.git.fetch import InterGitNonGitRepository
71
79
        from bzrlib.plugins.git.repository import GitRepository
72
80
 
73
81
        if dest_location is None:
86
94
        except NoRepositoryPresent:
87
95
            target_repo = target_bzrdir.create_repository(shared=True)
88
96
 
89
 
        target_repo.fetch(source_repo)
90
 
        for name, ref in source_repo._git.heads().iteritems():
91
 
            head_loc = os.path.join(dest_location, name)
92
 
            try:
93
 
                head_bzrdir = BzrDir.open(head_loc)
94
 
            except NotBranchError:
95
 
                head_bzrdir = BzrDir.create(head_loc, format=format)
96
 
            try:
97
 
                head_branch = head_bzrdir.open_branch()
98
 
            except NotBranchError:
99
 
                head_branch = head_bzrdir.create_branch()
100
 
            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()
101
125