bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
1 |
# Copyright (C) 2006-2009 Canonical Ltd
|
2 |
||
3 |
# Authors: Robert Collins <robert.collins@canonical.com>
|
|
4 |
# Jelmer Vernooij <jelmer@samba.org>
|
|
5 |
# John Carr <john.carr@unrouted.co.uk>
|
|
6 |
#
|
|
7 |
# This program is free software; you can redistribute it and/or modify
|
|
8 |
# it under the terms of the GNU General Public License as published by
|
|
9 |
# the Free Software Foundation; either version 2 of the License, or
|
|
10 |
# (at your option) any later version.
|
|
11 |
#
|
|
12 |
# This program is distributed in the hope that it will be useful,
|
|
13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
# GNU General Public License for more details.
|
|
16 |
#
|
|
17 |
# You should have received a copy of the GNU General Public License
|
|
18 |
# along with this program; if not, write to the Free Software
|
|
19 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 |
||
21 |
"""Git-specific subcommands for Bazaar."""
|
|
22 |
||
23 |
from bzrlib.commands import Command |
|
24 |
from bzrlib.option import Option |
|
25 |
||
0.228.1
by Jelmer Vernooij
Add basic tests for local fetch. |
26 |
from bzrlib.plugins.git import get_rich_root_format |
27 |
||
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
28 |
class cmd_git_serve(Command): |
29 |
"""Provide access to a Bazaar branch using the git protocol. |
|
30 |
||
31 |
This command is experimental and doesn't do much yet.
|
|
32 |
"""
|
|
33 |
takes_options = [ |
|
34 |
Option('directory', |
|
35 |
help='serve contents of directory', |
|
36 |
type=unicode) |
|
37 |
]
|
|
38 |
||
39 |
def run(self, directory=None): |
|
40 |
lazy_check_versions() |
|
41 |
from dulwich.server import TCPGitServer |
|
42 |
from bzrlib.plugins.git.server import BzrBackend |
|
43 |
from bzrlib.trace import warning |
|
44 |
import os |
|
45 |
||
46 |
warning("server support in bzr-git is experimental.") |
|
47 |
||
48 |
if directory is None: |
|
49 |
directory = os.getcwd() |
|
50 |
||
51 |
backend = BzrBackend(directory) |
|
52 |
||
53 |
server = TCPGitServer(backend, 'localhost') |
|
54 |
server.serve_forever() |
|
55 |
||
0.200.252
by Jelmer Vernooij
Clarify history, copyright. |
56 |
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
57 |
class cmd_git_import(Command): |
58 |
"""Import all branches from a git repository. |
|
59 |
||
60 |
"""
|
|
61 |
||
0.200.234
by Jelmer Vernooij
Derive to_location from from_location, simialr to bzr branch. |
62 |
takes_args = ["src_location", "dest_location?"] |
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
63 |
|
0.200.234
by Jelmer Vernooij
Derive to_location from from_location, simialr to bzr branch. |
64 |
def run(self, src_location, dest_location=None): |
0.200.247
by Jelmer Vernooij
Fix git-import. |
65 |
import os |
66 |
from bzrlib import ( |
|
67 |
ui, |
|
68 |
urlutils, |
|
69 |
)
|
|
70 |
from bzrlib.bzrdir import ( |
|
71 |
BzrDir, |
|
72 |
format_registry, |
|
73 |
)
|
|
0.200.243
by Jelmer Vernooij
Error out on non-git repositories. |
74 |
from bzrlib.errors import ( |
75 |
BzrCommandError, |
|
76 |
NoRepositoryPresent, |
|
77 |
NotBranchError, |
|
78 |
)
|
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
79 |
from bzrlib.repository import Repository |
0.200.273
by Jelmer Vernooij
Fix import of tags in git-import. |
80 |
from bzrlib.plugins.git.branch import GitBranch |
0.200.247
by Jelmer Vernooij
Fix git-import. |
81 |
from bzrlib.plugins.git.fetch import InterGitNonGitRepository |
0.200.243
by Jelmer Vernooij
Error out on non-git repositories. |
82 |
from bzrlib.plugins.git.repository import GitRepository |
0.200.234
by Jelmer Vernooij
Derive to_location from from_location, simialr to bzr branch. |
83 |
|
84 |
if dest_location is None: |
|
85 |
dest_location = os.path.basename(src_location.rstrip("/\\")) |
|
86 |
||
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
87 |
source_repo = Repository.open(src_location) |
0.200.243
by Jelmer Vernooij
Error out on non-git repositories. |
88 |
if not isinstance(source_repo, GitRepository): |
89 |
raise BzrCommandError("%r is not a git repository" % src_location) |
|
0.228.1
by Jelmer Vernooij
Add basic tests for local fetch. |
90 |
format = get_rich_root_format() |
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
91 |
try: |
92 |
target_bzrdir = BzrDir.open(dest_location) |
|
93 |
except NotBranchError: |
|
94 |
target_bzrdir = BzrDir.create(dest_location, format=format) |
|
95 |
try: |
|
96 |
target_repo = target_bzrdir.open_repository() |
|
97 |
except NoRepositoryPresent: |
|
98 |
target_repo = target_bzrdir.create_repository(shared=True) |
|
99 |
||
0.200.247
by Jelmer Vernooij
Fix git-import. |
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()): |
|
0.200.271
by Jelmer Vernooij
Stop importing tags as branches as part of git-import. |
106 |
if name.startswith("refs/tags/"): |
107 |
continue
|
|
0.200.247
by Jelmer Vernooij
Fix git-import. |
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() |
|
0.200.271
by Jelmer Vernooij
Stop importing tags as branches as part of git-import. |
121 |
revid = mapping.revision_id_foreign_to_bzr(ref) |
0.200.273
by Jelmer Vernooij
Fix import of tags in git-import. |
122 |
source_branch = GitBranch(source_repo.bzrdir, source_repo, |
123 |
name, ref, None) |
|
0.200.247
by Jelmer Vernooij
Fix git-import. |
124 |
head_branch.generate_revision_history(revid) |
0.200.273
by Jelmer Vernooij
Fix import of tags in git-import. |
125 |
source_branch.tags.merge_to(head_branch.tags) |
0.200.247
by Jelmer Vernooij
Fix git-import. |
126 |
finally: |
127 |
pb.finished() |
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
128 |