/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: Jelmer Vernooij
  • Date: 2009-09-10 13:13:15 UTC
  • mto: (0.200.602 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090910131315-6890xg58pl2jseml
Allow serving remote URLs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
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
 
17
"""An adapter between a Git control dir and a Bazaar BzrDir."""
 
18
 
23
19
from bzrlib import (
24
20
    bzrdir,
25
21
    lockable_files,
26
22
    urlutils,
27
23
    )
28
24
 
29
 
lazy_import(globals(), """
30
 
from bzrlib.lockable_files import TransportLock
 
25
LockWarner = getattr(lockable_files, "_LockWarner", None)
 
26
 
31
27
from bzrlib.plugins.git import (
 
28
    LocalGitBzrDirFormat,
 
29
    branch,
32
30
    errors,
33
 
    branch,
 
31
    get_rich_root_format,
34
32
    repository,
35
33
    workingtree,
36
34
    )
37
 
""")
38
 
 
39
 
from bzrlib.plugins.git import LocalGitBzrDirFormat
40
 
 
41
35
 
42
36
 
43
37
class GitLock(object):
66
60
        self._lock = lock
67
61
        self._transaction = None
68
62
        self._lock_mode = None
69
 
        self._lock_count = 0
70
63
        self._transport = transport
 
64
        if LockWarner is None:
 
65
            # Bzr 1.13
 
66
            self._lock_count = 0
 
67
        else:
 
68
            self._lock_warner = LockWarner(repr(self))
71
69
 
72
70
 
73
71
class GitDir(bzrdir.BzrDir):
77
75
        return True
78
76
 
79
77
    def cloning_metadir(self, stacked=False):
80
 
        return bzrlib.bzrdir.format_registry.make_bzrdir("1.9-rich-root")
 
78
        return get_rich_root_format(stacked)
81
79
 
82
80
 
83
81
class LocalGitDir(GitDir):
94
92
        else:
95
93
            self.transport = transport.clone('.git')
96
94
        self._lockfiles = lockfiles
 
95
        self._mode_check_done = None
 
96
 
 
97
    def is_control_filename(self, filename):
 
98
        return filename == '.git' or filename.startswith('.git/')
97
99
 
98
100
    def get_branch_transport(self, branch_format):
99
101
        if branch_format is None:
105
107
    get_repository_transport = get_branch_transport
106
108
    get_workingtree_transport = get_branch_transport
107
109
 
108
 
    def open_branch(self, ignored=None):
 
110
    def open_branch(self, ignore_fallbacks=None):
109
111
        """'create' a branch for this dir."""
110
112
        repo = self.open_repository()
111
 
        return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(), self._lockfiles)
 
113
        return branch.LocalGitBranch(self, repo, "HEAD", self._lockfiles)
112
114
 
113
115
    def open_repository(self, shared=False):
114
116
        """'open' a repository for this dir."""
115
117
        return self._gitrepository_class(self, self._lockfiles)
116
118
 
117
119
    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
        if not self._git.bare and self._git.has_index():
120
121
            return workingtree.GitWorkingTree(self, self.open_repository(), 
121
122
                                                  self.open_branch())
122
123
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
124
125
 
125
126
    def create_repository(self, shared=False):
126
127
        return self.open_repository()
 
128
 
 
129
    def create_branch(self):
 
130
        return self.open_branch()
 
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()