/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

Create cache dir if it doesn't exist yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
from bzrlib.plugins.git import (
32
32
    get_rich_root_format,
 
33
    lazy_check_versions,
33
34
    )
34
35
 
35
36
class cmd_git_import(Command):
47
48
            )
48
49
        from bzrlib.bzrdir import (
49
50
            BzrDir,
 
51
            format_registry,
50
52
            )
51
53
        from bzrlib.errors import (
52
54
            BzrCommandError,
57
59
            InterRepository,
58
60
            Repository,
59
61
            )
60
 
        from bzrlib.plugins.git.branch import (
61
 
            GitBranch,
62
 
            extract_tags,
63
 
            )
 
62
        from bzrlib.plugins.git.branch import GitBranch
64
63
        from bzrlib.plugins.git.repository import GitRepository
65
64
 
66
65
        if dest_location is None:
75
74
        except NotBranchError:
76
75
            target_bzrdir = BzrDir.create(dest_location, format=format)
77
76
        try:
78
 
            target_repo = target_bzrdir.find_repository()
 
77
            target_repo = target_bzrdir.open_repository()
79
78
        except NoRepositoryPresent:
80
79
            target_repo = target_bzrdir.create_repository(shared=True)
81
80
 
82
 
        if not target_repo.supports_rich_root():
83
 
            raise BzrCommandError("Target repository doesn't support rich roots")
84
 
 
85
81
        interrepo = InterRepository.get(source_repo, target_repo)
86
82
        mapping = source_repo.get_mapping()
87
83
        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)
91
84
        pb = ui.ui_factory.nested_progress_bar()
92
85
        try:
93
86
            for i, (name, ref) in enumerate(refs.iteritems()):
107
100
                except NotBranchError:
108
101
                    head_branch = head_bzrdir.create_branch()
109
102
                revid = mapping.revision_id_foreign_to_bzr(ref)
110
 
                source_branch = GitBranch(source_repo.bzrdir, source_repo,
111
 
                    name, None, tags)
 
103
                source_branch = GitBranch(source_repo.bzrdir, source_repo, 
 
104
                    name, None)
112
105
                source_branch.head = ref
113
 
                if head_branch.last_revision() != revid:
114
 
                    head_branch.generate_revision_history(revid)
 
106
                head_branch.generate_revision_history(revid)
115
107
                source_branch.tags.merge_to(head_branch.tags)
116
108
        finally:
117
109
            pb.finished()
119
111
 
120
112
class cmd_git_object(Command):
121
113
    """List or display Git objects by SHA.
122
 
 
 
114
    
123
115
    Cat a particular object's Git representation if a SHA is specified.
124
116
    List all available SHAs otherwise.
125
117
    """
128
120
 
129
121
    aliases = ["git-objects", "git-cat"]
130
122
    takes_args = ["sha1?"]
131
 
    takes_options = [Option('directory',
 
123
    takes_options = [Option('directory', 
132
124
        short_name='d',
133
125
        help='Location of repository.', type=unicode),
134
126
        Option('pretty', help='Pretty-print objects.')]
165
157
                    self.outf.write("%s\n" % sha1)
166
158
        finally:
167
159
            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()