/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

  • Committer: Robert Collins
  • Date: 2010-05-06 07:48:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506074822-0bsgf2j4h8jx0xkk
Added ``bzrlib.tests.matchers`` as a place to put matchers, along with
our first in-tree matcher. See the module docstring for details.
(Robert Collins)

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 TransportLock
31
 
from bzrlib.plugins.git import (
32
 
    errors,
33
 
    branch,
34
 
    repository,
35
 
    workingtree,
36
 
    )
37
 
""")
38
 
 
39
 
from bzrlib.plugins.git import LocalGitBzrDirFormat
40
 
 
41
 
 
42
 
 
43
 
class GitLock(object):
44
 
    """A lock that thunks through to Git."""
45
 
 
46
 
    def lock_write(self, token=None):
47
 
        pass
48
 
 
49
 
    def lock_read(self):
50
 
        pass
51
 
 
52
 
    def unlock(self):
53
 
        pass
54
 
 
55
 
    def peek(self):
56
 
        pass
57
 
 
58
 
    def validate_token(self, token):
59
 
        pass
60
 
 
61
 
 
62
 
class GitLockableFiles(lockable_files.LockableFiles):
63
 
    """Git specific lockable files abstraction."""
64
 
 
65
 
    def __init__(self, transport, lock):
66
 
        self._lock = lock
67
 
        self._transaction = None
68
 
        self._lock_mode = None
69
 
        self._lock_count = 0
70
 
        self._transport = transport
71
 
 
72
 
 
73
 
class GitDir(bzrdir.BzrDir):
74
 
    """An adapter to the '.git' dir used by git."""
75
 
 
76
 
    def is_supported(self):
77
 
        return True
78
 
 
79
 
    def cloning_metadir(self, stacked=False):
80
 
        return bzrlib.bzrdir.format_registry.make_bzrdir("1.9-rich-root")
81
 
 
82
 
 
83
 
class LocalGitDir(GitDir):
84
 
    """An adapter to the '.git' dir used by git."""
85
 
 
86
 
    _gitrepository_class = repository.LocalGitRepository
87
 
 
88
 
    def __init__(self, transport, lockfiles, gitrepo, format):
89
 
        self._format = format
90
 
        self.root_transport = transport
91
 
        self._git = gitrepo
92
 
        if gitrepo.bare:
93
 
            self.transport = transport
94
 
        else:
95
 
            self.transport = transport.clone('.git')
96
 
        self._lockfiles = lockfiles
97
 
 
98
 
    def get_branch_transport(self, branch_format):
99
 
        if branch_format is None:
100
 
            return self.transport
101
 
        if isinstance(branch_format, LocalGitBzrDirFormat):
102
 
            return self.transport
103
 
        raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
104
 
 
105
 
    get_repository_transport = get_branch_transport
106
 
    get_workingtree_transport = get_branch_transport
107
 
 
108
 
    def open_branch(self, ignored=None):
109
 
        """'create' a branch for this dir."""
110
 
        repo = self.open_repository()
111
 
        return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(), self._lockfiles)
112
 
 
113
 
    def open_repository(self, shared=False):
114
 
        """'open' a repository for this dir."""
115
 
        return self._gitrepository_class(self, self._lockfiles)
116
 
 
117
 
    def open_workingtree(self, recommend_upgrade=True):
118
 
        if (not self._git.bare and 
119
 
            os.path.exists(os.path.join(self._git.controldir(), "index"))):
120
 
            return workingtree.GitWorkingTree(self, self.open_repository(), 
121
 
                                                  self.open_branch())
122
 
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
123
 
        raise errors.bzr_errors.NoWorkingTree(loc)
124
 
 
125
 
    def create_repository(self, shared=False):
126
 
        return self.open_repository()