/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
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
0.200.123 by Jelmer Vernooij
Use central git module.
19
import os
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
20
0.200.109 by Jelmer Vernooij
Cope with new argument to cloning_metadir.
21
import bzrlib
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
22
from bzrlib.lazy_import import lazy_import
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
23
from bzrlib import (
24
    bzrdir,
25
    lockable_files,
26
    urlutils,
27
    )
28
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
29
lazy_import(globals(), """
0.200.248 by Jelmer Vernooij
Fix locking.
30
from bzrlib.lockable_files import (
31
    TransportLock,
32
    )
0.200.27 by David Allouche
Flat is better than nested, remove the gitlib hierarchy.
33
from bzrlib.plugins.git import (
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
34
    errors,
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
35
    branch,
36
    repository,
37
    workingtree,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
38
    )
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
39
""")
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
40
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
41
from bzrlib.plugins.git import LocalGitBzrDirFormat
42
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
43
0.200.123 by Jelmer Vernooij
Use central git module.
44
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
45
class GitLock(object):
46
    """A lock that thunks through to Git."""
47
0.200.84 by Jelmer Vernooij
Fix lock_write argument.
48
    def lock_write(self, token=None):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
49
        pass
50
51
    def lock_read(self):
52
        pass
53
54
    def unlock(self):
55
        pass
56
0.200.73 by Jelmer Vernooij
Implement GitLock.peek().
57
    def peek(self):
58
        pass
59
0.200.130 by Jelmer Vernooij
Make most tree inspection tests succeed.
60
    def validate_token(self, token):
61
        pass
62
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
63
64
class GitLockableFiles(lockable_files.LockableFiles):
65
    """Git specific lockable files abstraction."""
66
0.200.129 by Jelmer Vernooij
merge dulwich.
67
    def __init__(self, transport, lock):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
68
        self._lock = lock
69
        self._transaction = None
70
        self._lock_mode = None
0.200.129 by Jelmer Vernooij
merge dulwich.
71
        self._transport = transport
0.200.251 by Jelmer Vernooij
Revert locking fixes for now, as they break bzr 1.13 compatibility.
72
        self._lock_count = 0
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
73
74
75
class GitDir(bzrdir.BzrDir):
76
    """An adapter to the '.git' dir used by git."""
77
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
78
    def is_supported(self):
79
        return True
80
0.200.155 by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories.
81
    def cloning_metadir(self, stacked=False):
0.200.156 by Jelmer Vernooij
Use rich root formats.
82
        return bzrlib.bzrdir.format_registry.make_bzrdir("1.9-rich-root")
0.200.155 by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories.
83
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
84
85
class LocalGitDir(GitDir):
86
    """An adapter to the '.git' dir used by git."""
87
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
88
    _gitrepository_class = repository.LocalGitRepository
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
89
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
90
    def __init__(self, transport, lockfiles, gitrepo, format):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
91
        self._format = format
92
        self.root_transport = transport
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
93
        self._git = gitrepo
94
        if gitrepo.bare:
95
            self.transport = transport
96
        else:
97
            self.transport = transport.clone('.git')
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
98
        self._lockfiles = lockfiles
99
100
    def get_branch_transport(self, branch_format):
101
        if branch_format is None:
102
            return self.transport
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
103
        if isinstance(branch_format, LocalGitBzrDirFormat):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
104
            return self.transport
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
105
        raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
106
107
    get_repository_transport = get_branch_transport
108
    get_workingtree_transport = get_branch_transport
109
110
    def open_branch(self, ignored=None):
0.200.57 by Jelmer Vernooij
Fix more tests.
111
        """'create' a branch for this dir."""
112
        repo = self.open_repository()
0.200.147 by Jelmer Vernooij
Merge new dulwich; fetching objects from local repository works now; they aren't converted yet though.
113
        return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(), self._lockfiles)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
114
115
    def open_repository(self, shared=False):
116
        """'open' a repository for this dir."""
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
117
        return self._gitrepository_class(self, self._lockfiles)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
118
0.203.1 by Aaron Bentley
Make checkouts work
119
    def open_workingtree(self, recommend_upgrade=True):
0.200.250 by Jelmer Vernooij
Remove support for working trees for now.
120
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
121
        raise errors.bzr_errors.NoWorkingTree(loc)
0.200.173 by Jelmer Vernooij
Merge changes, open index.
122
        if (not self._git.bare and 
123
            os.path.exists(os.path.join(self._git.controldir(), "index"))):
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
124
            return workingtree.GitWorkingTree(self, self.open_repository(), 
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
125
                                                  self.open_branch())
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
126
0.200.108 by Jelmer Vernooij
Support bzr init --git.
127
    def create_repository(self, shared=False):
128
        return self.open_repository()