~ubuntu-branches/debian/jessie/bzr-git/jessie

« back to all changes in this revision

Viewing changes to commands.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2011-12-15 19:06:37 UTC
  • mfrom: (1.1.25)
  • Revision ID: package-import@ubuntu.com-20111215190637-cd1n2iathdjg1u97
Tags: 0.6.6-1
* Use DEP5 format for copyright file.
* New upstream release.
 + Copes with new `possible_transports` argument for Branch.open added in
   bzr 2.5b4. Closes: #652178
 + Copes with removal of global options in bzr 2.5b4. LP: #903639
 + Fixes support for directories in `bzr add`. LP: #894195

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
            return head_bzrdir.create_branch()
59
59
 
60
60
    def run(self, src_location, dest_location=None):
61
 
        from collections import defaultdict
62
61
        import os
63
62
        import urllib
64
63
        from bzrlib import (
75
74
            NoRepositoryPresent,
76
75
            NotBranchError,
77
76
            )
 
77
        from bzrlib.plugins.git import gettext
78
78
        from bzrlib.repository import (
79
79
            InterRepository,
80
80
            Repository,
82
82
        from bzrlib.transport import get_transport
83
83
        from bzrlib.plugins.git.branch import (
84
84
            GitBranch,
85
 
            extract_tags,
86
 
            )
87
 
        from bzrlib.plugins.git.refs import ref_to_branch_name
 
85
            )
 
86
        from bzrlib.plugins.git.refs import (
 
87
            ref_to_branch_name,
 
88
            ref_to_tag_name,
 
89
            )
88
90
        from bzrlib.plugins.git.repository import GitRepository
89
91
 
90
92
        dest_format = controldir.ControlDirFormat.get_default_format()
96
98
 
97
99
        source_repo = Repository.open(src_location)
98
100
        if not isinstance(source_repo, GitRepository):
99
 
            raise BzrCommandError("%r is not a git repository" % src_location)
 
101
            raise BzrCommandError(gettext("%r is not a git repository") % src_location)
100
102
        try:
101
103
            target_bzrdir = BzrDir.open_from_transport(dest_transport)
102
104
        except NotBranchError:
108
110
            target_repo = target_bzrdir.create_repository(shared=True)
109
111
 
110
112
        if not target_repo.supports_rich_root():
111
 
            raise BzrCommandError("Target repository doesn't support rich roots")
 
113
            raise BzrCommandError(gettext("Target repository doesn't support rich roots"))
112
114
 
113
115
        interrepo = InterRepository.get(source_repo, target_repo)
114
116
        mapping = source_repo.get_mapping()
115
117
        refs = interrepo.fetch()
116
 
        unpeeled_tags = defaultdict(set)
117
 
        tags = {}
118
 
        for k, (peeled, unpeeled) in extract_tags(refs).iteritems():
119
 
            tags[k] = mapping.revision_id_foreign_to_bzr(peeled)
120
 
            if unpeeled is not None:
121
 
                unpeeled_tags[peeled].add(unpeeled)
122
 
        # FIXME: Store unpeeled tag map
 
118
        refs_dict = refs.as_dict()
123
119
        pb = ui.ui_factory.nested_progress_bar()
124
120
        try:
125
 
            for i, (name, ref) in enumerate(refs.iteritems()):
 
121
            for i, (name, sha) in enumerate(refs_dict.iteritems()):
126
122
                try:
127
123
                    branch_name = ref_to_branch_name(name)
128
124
                except ValueError:
129
125
                    # Not a branch, ignore
130
126
                    continue
131
 
                pb.update("creating branches", i, len(refs))
 
127
                pb.update(gettext("creating branches"), i, len(refs_dict))
132
128
                if getattr(target_bzrdir._format, "colocated_branches", False):
133
129
                    if name == "HEAD":
134
130
                        branch_name = None
135
131
                    head_branch = self._get_colocated_branch(target_bzrdir, branch_name)
136
132
                else:
137
133
                    head_branch = self._get_nested_branch(dest_transport, dest_format, branch_name)
138
 
                revid = mapping.revision_id_foreign_to_bzr(ref)
 
134
                revid = mapping.revision_id_foreign_to_bzr(sha)
139
135
                source_branch = GitBranch(source_repo.bzrdir, source_repo,
140
 
                    ref, tags)
141
 
                source_branch.head = ref
 
136
                    sha)
 
137
                source_branch.head = sha
142
138
                if head_branch.last_revision() != revid:
143
139
                    head_branch.generate_revision_history(revid)
144
140
                source_branch.tags.merge_to(head_branch.tags)
148
144
                    head_branch.set_parent(url)
149
145
        finally:
150
146
            pb.finished()
151
 
        trace.note("Use 'bzr checkout' to create a working tree in "
152
 
                   "the newly created branches.")
 
147
        trace.note(gettext(
 
148
            "Use 'bzr checkout' to create a working tree in "
 
149
            "the newly created branches."))
153
150
 
154
151
 
155
152
class cmd_git_object(Command):
177
174
        from bzrlib.bzrdir import (
178
175
            BzrDir,
179
176
            )
 
177
        from bzrlib.plugins.git.object_store import (
 
178
            get_object_store,
 
179
            )
 
180
        from bzrlib.plugins.git import gettext
180
181
        bzrdir, _ = BzrDir.open_containing(directory)
181
182
        repo = bzrdir.find_repository()
182
 
        from bzrlib.plugins.git.object_store import (
183
 
            get_object_store,
184
 
            )
185
183
        object_store = get_object_store(repo)
186
184
        object_store.lock_read()
187
185
        try:
189
187
                try:
190
188
                    obj = object_store[str(sha1)]
191
189
                except KeyError:
192
 
                    raise BzrCommandError("Object not found: %s" % sha1)
 
190
                    raise BzrCommandError(gettext("Object not found: %s") % sha1)
193
191
                if pretty:
194
192
                    text = obj.as_pretty_string()
195
193
                else:
219
217
            BzrDir,
220
218
            )
221
219
        from bzrlib.plugins.git.refs import (
222
 
            get_refs,
 
220
            get_refs_container,
223
221
            )
224
222
        from bzrlib.plugins.git.object_store import (
225
223
            get_object_store,
229
227
        object_store = get_object_store(repo)
230
228
        object_store.lock_read()
231
229
        try:
232
 
            refs = get_refs(bzrdir)
233
 
            for k, v in refs.iteritems():
 
230
            refs = get_refs_container(bzrdir)
 
231
            for k, v in refs.as_dict().iteritems():
234
232
                self.outf.write("%s -> %s\n" % (k, v))
235
233
        finally:
236
234
            object_store.unlock()
245
243
 
246
244
    takes_options = [
247
245
        Option('signoff', short_name='s', help='Add a Signed-off-by line.'),
248
 
        'force']
 
246
        Option('force',
 
247
            help='Apply patches even if tree has uncommitted changes.')
 
248
        ]
249
249
    takes_args = ["patches*"]
250
250
 
251
251
    def _apply_patch(self, wt, f, signoff):
266
266
        p.communicate(diff)
267
267
        exitcode = p.wait()
268
268
        if exitcode != 0:
269
 
            raise BzrCommandError("error running patch")
 
269
            raise BzrCommandError(gettext("error running patch"))
270
270
        message = c.message
271
271
        if signoff:
272
272
            signed_off_by = wt.branch.get_config().username()