/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 dir.py

Implement Tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""An adapter between a Git control dir and a Bazaar BzrDir"""
 
18
 
 
19
import os
 
20
 
 
21
import bzrlib
 
22
from bzrlib.lazy_import import lazy_import
 
23
from bzrlib import (
 
24
    bzrdir,
 
25
    lockable_files,
 
26
    urlutils,
 
27
    )
 
28
 
 
29
lazy_import(globals(), """
 
30
from bzrlib.lockable_files import (
 
31
    _LockWarner,
 
32
    TransportLock,
 
33
    )
 
34
from bzrlib.plugins.git import (
 
35
    errors,
 
36
    branch,
 
37
    repository,
 
38
    workingtree,
 
39
    )
 
40
""")
 
41
 
 
42
from bzrlib.plugins.git import LocalGitBzrDirFormat
 
43
 
 
44
 
 
45
 
 
46
class GitLock(object):
 
47
    """A lock that thunks through to Git."""
 
48
 
 
49
    def lock_write(self, token=None):
 
50
        pass
 
51
 
 
52
    def lock_read(self):
 
53
        pass
 
54
 
 
55
    def unlock(self):
 
56
        pass
 
57
 
 
58
    def peek(self):
 
59
        pass
 
60
 
 
61
    def validate_token(self, token):
 
62
        pass
 
63
 
 
64
 
 
65
class GitLockableFiles(lockable_files.LockableFiles):
 
66
    """Git specific lockable files abstraction."""
 
67
 
 
68
    def __init__(self, transport, lock):
 
69
        self._lock = lock
 
70
        self._transaction = None
 
71
        self._lock_mode = None
 
72
        self._transport = transport
 
73
        self._lock_warner = _LockWarner(repr(self))
 
74
 
 
75
 
 
76
class GitDir(bzrdir.BzrDir):
 
77
    """An adapter to the '.git' dir used by git."""
 
78
 
 
79
    def is_supported(self):
 
80
        return True
 
81
 
 
82
    def cloning_metadir(self, stacked=False):
 
83
        return bzrlib.bzrdir.format_registry.make_bzrdir("1.9-rich-root")
 
84
 
 
85
 
 
86
class LocalGitDir(GitDir):
 
87
    """An adapter to the '.git' dir used by git."""
 
88
 
 
89
    _gitrepository_class = repository.LocalGitRepository
 
90
 
 
91
    def __init__(self, transport, lockfiles, gitrepo, format):
 
92
        self._format = format
 
93
        self.root_transport = transport
 
94
        self._git = gitrepo
 
95
        if gitrepo.bare:
 
96
            self.transport = transport
 
97
        else:
 
98
            self.transport = transport.clone('.git')
 
99
        self._lockfiles = lockfiles
 
100
 
 
101
    def get_branch_transport(self, branch_format):
 
102
        if branch_format is None:
 
103
            return self.transport
 
104
        if isinstance(branch_format, LocalGitBzrDirFormat):
 
105
            return self.transport
 
106
        raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
 
107
 
 
108
    get_repository_transport = get_branch_transport
 
109
    get_workingtree_transport = get_branch_transport
 
110
 
 
111
    def open_branch(self, ignored=None):
 
112
        """'create' a branch for this dir."""
 
113
        repo = self.open_repository()
 
114
        return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(), self._lockfiles)
 
115
 
 
116
    def open_repository(self, shared=False):
 
117
        """'open' a repository for this dir."""
 
118
        return self._gitrepository_class(self, self._lockfiles)
 
119
 
 
120
    def open_workingtree(self, recommend_upgrade=True):
 
121
        if (not self._git.bare and 
 
122
            os.path.exists(os.path.join(self._git.controldir(), "index"))):
 
123
            return workingtree.GitWorkingTree(self, self.open_repository(), 
 
124
                                                  self.open_branch())
 
125
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
 
126
        raise errors.bzr_errors.NoWorkingTree(loc)
 
127
 
 
128
    def create_repository(self, shared=False):
 
129
        return self.open_repository()