/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: 2007-10-05 02:41:37 UTC
  • mto: (2592.3.166 repository)
  • mto: This revision was merged to the branch mainline in revision 2896.
  • Revision ID: robertc@robertcollins.net-20071005024137-kn7brcu07nu8cwl1
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into
  ``KnitRepository`` by parameters to the constructor. (Robert Collins)
* ``bzrlib.xml_serializer.Serializer`` is now responsible for checking that
  mandatory attributes are present on serialisation and deserialisation.
  This fixes some holes in API usage and allows better separation between
  physical storage and object serialisation. (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 import (
23
 
    bzrdir,
24
 
    lockable_files,
25
 
    urlutils,
26
 
    )
27
 
 
28
 
LockWarner = getattr(lockable_files, "_LockWarner", None)
29
 
 
30
 
from bzrlib.plugins.git import (
31
 
    LocalGitBzrDirFormat,
32
 
    branch,
33
 
    errors,
34
 
    get_rich_root_format,
35
 
    repository,
36
 
    workingtree,
37
 
    )
38
 
 
39
 
 
40
 
class GitLock(object):
41
 
    """A lock that thunks through to Git."""
42
 
 
43
 
    def lock_write(self, token=None):
44
 
        pass
45
 
 
46
 
    def lock_read(self):
47
 
        pass
48
 
 
49
 
    def unlock(self):
50
 
        pass
51
 
 
52
 
    def peek(self):
53
 
        pass
54
 
 
55
 
    def validate_token(self, token):
56
 
        pass
57
 
 
58
 
 
59
 
class GitLockableFiles(lockable_files.LockableFiles):
60
 
    """Git specific lockable files abstraction."""
61
 
 
62
 
    def __init__(self, transport, lock):
63
 
        self._lock = lock
64
 
        self._transaction = None
65
 
        self._lock_mode = None
66
 
        self._transport = transport
67
 
        if LockWarner is None:
68
 
            # Bzr 1.13
69
 
            self._lock_count = 0
70
 
        else:
71
 
            self._lock_warner = LockWarner(repr(self))
72
 
 
73
 
 
74
 
class GitDir(bzrdir.BzrDir):
75
 
    """An adapter to the '.git' dir used by git."""
76
 
 
77
 
    def is_supported(self):
78
 
        return True
79
 
 
80
 
    def cloning_metadir(self, stacked=False):
81
 
        return get_rich_root_format()
82
 
 
83
 
 
84
 
class LocalGitDir(GitDir):
85
 
    """An adapter to the '.git' dir used by git."""
86
 
 
87
 
    _gitrepository_class = repository.LocalGitRepository
88
 
 
89
 
    def __init__(self, transport, lockfiles, gitrepo, format):
90
 
        self._format = format
91
 
        self.root_transport = transport
92
 
        self._git = gitrepo
93
 
        if gitrepo.bare:
94
 
            self.transport = transport
95
 
        else:
96
 
            self.transport = transport.clone('.git')
97
 
        self._lockfiles = lockfiles
98
 
 
99
 
    def get_branch_transport(self, branch_format):
100
 
        if branch_format is None:
101
 
            return self.transport
102
 
        if isinstance(branch_format, LocalGitBzrDirFormat):
103
 
            return self.transport
104
 
        raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
105
 
 
106
 
    get_repository_transport = get_branch_transport
107
 
    get_workingtree_transport = get_branch_transport
108
 
 
109
 
    def open_branch(self, ignore_fallbacks=None):
110
 
        """'create' a branch for this dir."""
111
 
        repo = self.open_repository()
112
 
        return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(),
113
 
            self._lockfiles)
114
 
 
115
 
    def open_repository(self, shared=False):
116
 
        """'open' a repository for this dir."""
117
 
        return self._gitrepository_class(self, self._lockfiles)
118
 
 
119
 
    def open_workingtree(self, recommend_upgrade=True):
120
 
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
121
 
        raise errors.bzr_errors.NoWorkingTree(loc)
122
 
        if (not self._git.bare and 
123
 
            os.path.exists(os.path.join(self._git.controldir(), "index"))):
124
 
            return workingtree.GitWorkingTree(self, self.open_repository(), 
125
 
                                                  self.open_branch())
126
 
 
127
 
    def create_repository(self, shared=False):
128
 
        return self.open_repository()
129
 
 
130
 
    def create_branch(self):
131
 
        return self.open_branch()