/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

Add simple HACKING document.

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
25
24
from bzrlib.option import Option
26
25
 
 
26
from bzrlib.plugins.git import get_rich_root_format
 
27
 
27
28
class cmd_git_serve(Command):
28
29
    """Provide access to a Bazaar branch using the git protocol.
29
30
 
52
53
        server = TCPGitServer(backend, 'localhost')
53
54
        server.serve_forever()
54
55
 
 
56
 
55
57
class cmd_git_import(Command):
56
58
    """Import all branches from a git repository.
57
59
 
58
60
    """
59
61
 
60
 
    takes_args = ["src_location", "dest_location"]
 
62
    takes_args = ["src_location", "dest_location?"]
61
63
 
62
 
    def run(self, src_location, dest_location):
63
 
        from bzrlib.bzrdir import BzrDir, format_registry
64
 
        from bzrlib.errors import NoRepositoryPresent, NotBranchError
 
64
    def run(self, src_location, dest_location=None):
 
65
        import os
 
66
        from bzrlib import (
 
67
            ui,
 
68
            urlutils,
 
69
            )
 
70
        from bzrlib.bzrdir import (
 
71
            BzrDir,
 
72
            format_registry,
 
73
            )
 
74
        from bzrlib.errors import (
 
75
            BzrCommandError,
 
76
            NoRepositoryPresent,
 
77
            NotBranchError,
 
78
            )
65
79
        from bzrlib.repository import Repository
 
80
        from bzrlib.plugins.git.branch import GitBranch
 
81
        from bzrlib.plugins.git.fetch import InterGitNonGitRepository
 
82
        from bzrlib.plugins.git.repository import GitRepository
 
83
 
 
84
        if dest_location is None:
 
85
            dest_location = os.path.basename(src_location.rstrip("/\\"))
 
86
 
66
87
        source_repo = Repository.open(src_location)
67
 
        format = format_registry.make_bzrdir('rich-root-pack')
 
88
        if not isinstance(source_repo, GitRepository):
 
89
            raise BzrCommandError("%r is not a git repository" % src_location)
 
90
        format = get_rich_root_format()
68
91
        try:
69
92
            target_bzrdir = BzrDir.open(dest_location)
70
93
        except NotBranchError:
74
97
        except NoRepositoryPresent:
75
98
            target_repo = target_bzrdir.create_repository(shared=True)
76
99
 
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))
 
100
        interrepo = InterGitNonGitRepository(source_repo, target_repo)
 
101
        mapping = source_repo.get_mapping()
 
102
        refs = interrepo.fetch_refs()
 
103
        pb = ui.ui_factory.nested_progress_bar()
 
104
        try:
 
105
            for i, (name, ref) in enumerate(refs.iteritems()):
 
106
                if name.startswith("refs/tags/"):
 
107
                    continue
 
108
                pb.update("creating branches", i, len(refs))
 
109
                head_loc = os.path.join(dest_location, name)
 
110
                try:
 
111
                    head_bzrdir = BzrDir.open(head_loc)
 
112
                except NotBranchError:
 
113
                    parent_path = urlutils.dirname(head_loc)
 
114
                    if not os.path.isdir(parent_path):
 
115
                        os.makedirs(parent_path)
 
116
                    head_bzrdir = BzrDir.create(head_loc, format=format)
 
117
                try:
 
118
                    head_branch = head_bzrdir.open_branch()
 
119
                except NotBranchError:
 
120
                    head_branch = head_bzrdir.create_branch()
 
121
                revid = mapping.revision_id_foreign_to_bzr(ref)
 
122
                source_branch = GitBranch(source_repo.bzrdir, source_repo, 
 
123
                    name, ref, None)
 
124
                head_branch.generate_revision_history(revid)
 
125
                source_branch.tags.merge_to(head_branch.tags)
 
126
        finally:
 
127
            pb.finished()
89
128