/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
0.200.261 by Jelmer Vernooij
More formatting fixes.
17
"""An adapter between a Git control dir and a Bazaar BzrDir."""
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
18
19
from bzrlib import (
20
    bzrdir,
21
    lockable_files,
22
    urlutils,
23
    )
24
0.200.280 by Jelmer Vernooij
Support bzr.dev.
25
LockWarner = getattr(lockable_files, "_LockWarner", None)
26
0.200.27 by David Allouche
Flat is better than nested, remove the gitlib hierarchy.
27
from bzrlib.plugins.git import (
0.200.280 by Jelmer Vernooij
Support bzr.dev.
28
    LocalGitBzrDirFormat,
0.200.292 by Jelmer Vernooij
Fix formatting.
29
    branch,
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
30
    errors,
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
31
    get_rich_root_format,
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
32
    repository,
33
    workingtree,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
34
    )
35
0.200.123 by Jelmer Vernooij
Use central git module.
36
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
37
class GitLock(object):
38
    """A lock that thunks through to Git."""
39
0.200.84 by Jelmer Vernooij
Fix lock_write argument.
40
    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.
41
        pass
42
43
    def lock_read(self):
44
        pass
45
46
    def unlock(self):
47
        pass
48
0.200.73 by Jelmer Vernooij
Implement GitLock.peek().
49
    def peek(self):
50
        pass
51
0.200.130 by Jelmer Vernooij
Make most tree inspection tests succeed.
52
    def validate_token(self, token):
53
        pass
54
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
55
56
class GitLockableFiles(lockable_files.LockableFiles):
57
    """Git specific lockable files abstraction."""
58
0.200.129 by Jelmer Vernooij
merge dulwich.
59
    def __init__(self, transport, lock):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
60
        self._lock = lock
61
        self._transaction = None
62
        self._lock_mode = None
0.200.129 by Jelmer Vernooij
merge dulwich.
63
        self._transport = transport
0.200.280 by Jelmer Vernooij
Support bzr.dev.
64
        if LockWarner is None:
65
            # Bzr 1.13
66
            self._lock_count = 0
67
        else:
68
            self._lock_warner = LockWarner(repr(self))
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
69
70
71
class GitDir(bzrdir.BzrDir):
72
    """An adapter to the '.git' dir used by git."""
73
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
74
    def is_supported(self):
75
        return True
76
0.200.155 by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories.
77
    def cloning_metadir(self, stacked=False):
0.200.328 by Jelmer Vernooij
Support stacking, depend on bzr 1.15.
78
        return get_rich_root_format(stacked)
0.200.155 by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories.
79
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
80
81
class LocalGitDir(GitDir):
82
    """An adapter to the '.git' dir used by git."""
83
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
84
    _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.
85
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
86
    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.
87
        self._format = format
88
        self.root_transport = transport
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
89
        self._git = gitrepo
90
        if gitrepo.bare:
91
            self.transport = transport
92
        else:
93
            self.transport = transport.clone('.git')
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
94
        self._lockfiles = lockfiles
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
95
        self._mode_check_done = None
96
97
    def is_control_filename(self, filename):
98
        return filename == '.git' or filename.startswith('.git/')
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
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
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
110
    def open_branch(self, ignore_fallbacks=None):
0.200.57 by Jelmer Vernooij
Fix more tests.
111
        """'create' a branch for this dir."""
112
        repo = self.open_repository()
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
113
        return branch.LocalGitBranch(self, repo, "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.535 by Jelmer Vernooij
use standard version to check for index.
120
        if not self._git.bare and self._git.has_index():
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
121
            return workingtree.GitWorkingTree(self, self.open_repository(), 
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
122
                                                  self.open_branch())
0.200.392 by Jelmer Vernooij
Fix some tests now that working trees are supported.
123
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
124
        raise errors.bzr_errors.NoWorkingTree(loc)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
125
0.200.108 by Jelmer Vernooij
Support bzr init --git.
126
    def create_repository(self, shared=False):
127
        return self.open_repository()
0.200.288 by Jelmer Vernooij
Add test for init-repo.
128
129
    def create_branch(self):
130
        return self.open_branch()
0.200.535 by Jelmer Vernooij
use standard version to check for index.
131
132
    def backup_bzrdir(self):
133
        if self._git.bare:
134
            self.root_transport.copy_tree(".git", ".git.backup")
135
            return (self.root_transport.abspath(".git"),
136
                    self.root_transport.abspath(".git.backup"))
137
        else:
138
            raise errors.bzr_errors.BzrError("Unable to backup bare repositories")
139
140
    def create_workingtree(self, revision_id=None, from_branch=None,
141
        accelerator_tree=None, hardlink=False):
142
        if self._git.bare:
143
            raise errors.bzr_errors.BzrError("Can't create working tree in a bare repo")
144
        from dulwich.index import write_index
145
        write_index(self.root_transport.abspath(".git/index"), [])
146
        return self.open_workingtree()