/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

update copyright years

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib.commands import (
24
24
    Command,
 
25
    display_command,
25
26
    )
26
27
from bzrlib.option import (
27
28
    Option,
31
32
    get_rich_root_format,
32
33
    )
33
34
 
34
 
class cmd_git_serve(Command):
35
 
    """Provide access to a Bazaar branch using the git protocol.
36
 
 
37
 
    This command is experimental and doesn't do much yet.
38
 
    """
39
 
    takes_options = [
40
 
        Option('directory',
41
 
               help='serve contents of directory',
42
 
               type=unicode)
43
 
    ]
44
 
 
45
 
    def run(self, directory=None):
46
 
        lazy_check_versions()
47
 
        from dulwich.server import TCPGitServer
48
 
        from bzrlib.plugins.git.server import BzrBackend
49
 
        from bzrlib.trace import warning
50
 
        import os
51
 
 
52
 
        warning("server support in bzr-git is experimental.")
53
 
 
54
 
        if directory is None:
55
 
            directory = os.getcwd()
56
 
 
57
 
        backend = BzrBackend(directory)
58
 
 
59
 
        server = TCPGitServer(backend, 'localhost')
60
 
        server.serve_forever()
61
 
 
62
 
 
63
35
class cmd_git_import(Command):
64
36
    """Import all branches from a git repository.
65
37
 
75
47
            )
76
48
        from bzrlib.bzrdir import (
77
49
            BzrDir,
78
 
            format_registry,
79
50
            )
80
51
        from bzrlib.errors import (
81
52
            BzrCommandError,
86
57
            InterRepository,
87
58
            Repository,
88
59
            )
89
 
        from bzrlib.plugins.git.branch import GitBranch
 
60
        from bzrlib.plugins.git.branch import (
 
61
            GitBranch,
 
62
            extract_tags,
 
63
            )
90
64
        from bzrlib.plugins.git.repository import GitRepository
91
65
 
92
66
        if dest_location is None:
101
75
        except NotBranchError:
102
76
            target_bzrdir = BzrDir.create(dest_location, format=format)
103
77
        try:
104
 
            target_repo = target_bzrdir.open_repository()
 
78
            target_repo = target_bzrdir.find_repository()
105
79
        except NoRepositoryPresent:
106
80
            target_repo = target_bzrdir.create_repository(shared=True)
107
81
 
 
82
        if not target_repo.supports_rich_root():
 
83
            raise BzrCommandError("Target repository doesn't support rich roots")
 
84
 
108
85
        interrepo = InterRepository.get(source_repo, target_repo)
109
86
        mapping = source_repo.get_mapping()
110
87
        refs = interrepo.fetch_refs()
 
88
        tags = {}
 
89
        for k, v in extract_tags(refs).iteritems():
 
90
            tags[k] = mapping.revision_id_foreign_to_bzr(v)
111
91
        pb = ui.ui_factory.nested_progress_bar()
112
92
        try:
113
93
            for i, (name, ref) in enumerate(refs.iteritems()):
127
107
                except NotBranchError:
128
108
                    head_branch = head_bzrdir.create_branch()
129
109
                revid = mapping.revision_id_foreign_to_bzr(ref)
130
 
                source_branch = GitBranch(source_repo.bzrdir, source_repo, 
131
 
                    name, ref, None)
132
 
                head_branch.generate_revision_history(revid)
 
110
                source_branch = GitBranch(source_repo.bzrdir, source_repo,
 
111
                    name, None, tags)
 
112
                source_branch.head = ref
 
113
                if head_branch.last_revision() != revid:
 
114
                    head_branch.generate_revision_history(revid)
133
115
                source_branch.tags.merge_to(head_branch.tags)
134
116
        finally:
135
117
            pb.finished()
136
118
 
 
119
 
 
120
class cmd_git_object(Command):
 
121
    """List or display Git objects by SHA.
 
122
 
 
123
    Cat a particular object's Git representation if a SHA is specified.
 
124
    List all available SHAs otherwise.
 
125
    """
 
126
 
 
127
    hidden = True
 
128
 
 
129
    aliases = ["git-objects", "git-cat"]
 
130
    takes_args = ["sha1?"]
 
131
    takes_options = [Option('directory',
 
132
        short_name='d',
 
133
        help='Location of repository.', type=unicode),
 
134
        Option('pretty', help='Pretty-print objects.')]
 
135
    encoding_type = 'exact'
 
136
 
 
137
    @display_command
 
138
    def run(self, sha1=None, directory=".", pretty=False):
 
139
        from bzrlib.errors import (
 
140
            BzrCommandError,
 
141
            )
 
142
        from bzrlib.bzrdir import (
 
143
            BzrDir,
 
144
            )
 
145
        bzrdir, _ = BzrDir.open_containing(directory)
 
146
        repo = bzrdir.find_repository()
 
147
        from bzrlib.plugins.git.object_store import (
 
148
            get_object_store,
 
149
            )
 
150
        object_store = get_object_store(repo)
 
151
        repo.lock_read()
 
152
        try:
 
153
            if sha1 is not None:
 
154
                try:
 
155
                    obj = object_store[str(sha1)]
 
156
                except KeyError:
 
157
                    raise BzrCommandError("Object not found: %s" % sha1)
 
158
                if pretty:
 
159
                    text = obj.as_pretty_string()
 
160
                else:
 
161
                    text = obj.as_raw_string()
 
162
                self.outf.write(text)
 
163
            else:
 
164
                for sha1 in object_store:
 
165
                    self.outf.write("%s\n" % sha1)
 
166
        finally:
 
167
            repo.unlock()
 
168
 
 
169
 
 
170
class cmd_git_refs(Command):
 
171
    """Output all of the virtual refs for a repository.
 
172
 
 
173
    """
 
174
 
 
175
    hidden = True
 
176
 
 
177
    takes_options = [Option('directory',
 
178
        short_name='d',
 
179
        help='Location of repository.', type=unicode)]
 
180
 
 
181
    @display_command
 
182
    def run(self, directory="."):
 
183
        from bzrlib.bzrdir import (
 
184
            BzrDir,
 
185
            )
 
186
        from bzrlib.plugins.git.refs import (
 
187
            BazaarRefsContainer,
 
188
            )
 
189
        from bzrlib.plugins.git.object_store import (
 
190
            get_object_store,
 
191
            )
 
192
        bzrdir, _ = BzrDir.open_containing(directory)
 
193
        repo = bzrdir.find_repository()
 
194
        repo.lock_read()
 
195
        try:
 
196
            object_store = get_object_store(repo)
 
197
            refs = BazaarRefsContainer(bzrdir, object_store)
 
198
            for k, v in refs.as_dict().iteritems():
 
199
                self.outf.write("%s -> %s\n" % (k, v))
 
200
        finally:
 
201
            repo.unlock()
 
202
 
 
203
 
 
204
class cmd_git_apply(Command):
 
205
    """Apply a series of git-am style patches.
 
206
 
 
207
    This command will in the future probably be integrated into 
 
208
    "bzr pull".
 
209
    """
 
210
 
 
211
    takes_args = ["patches*"]
 
212
 
 
213
    def _apply_patch(self, wt, f):
 
214
        from dulwich.patch import git_am_patch_split
 
215
        (c, diff, version) = git_am_patch_split(f)
 
216
        # FIXME: Process diff
 
217
        wt.commit(committer=c.committer,
 
218
                  message=c.message)
 
219
 
 
220
    def run(self, patches_list=None):
 
221
        from bzrlib.workingtree import WorkingTree
 
222
        if patches_list is None:
 
223
            patches_list = []
 
224
        
 
225
        tree, _ = WorkingTree.open_containing(".")
 
226
        tree.lock_write()
 
227
        try:
 
228
            for patch in patches_list:
 
229
                f = open(patch, 'r')
 
230
                try:
 
231
                    self._apply_patch(tree, f)
 
232
                finally:
 
233
                    f.close()
 
234
        finally:
 
235
            tree.unlock()