/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

Implement InterTree.iter_changes() as well.

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,
 
21
    errors as bzr_errors,
25
22
    lockable_files,
26
23
    urlutils,
27
24
    )
28
25
 
29
 
lazy_import(globals(), """
30
 
from bzrlib.lockable_files import TransportLock
 
26
LockWarner = getattr(lockable_files, "_LockWarner", None)
 
27
 
31
28
from bzrlib.plugins.git import (
32
 
    errors,
33
 
    branch,
34
 
    repository,
35
 
    workingtree,
 
29
    LocalGitBzrDirFormat,
 
30
    get_rich_root_format,
36
31
    )
37
 
""")
38
 
 
39
 
from bzrlib.plugins.git import LocalGitBzrDirFormat
40
 
 
41
32
 
42
33
 
43
34
class GitLock(object):
66
57
        self._lock = lock
67
58
        self._transaction = None
68
59
        self._lock_mode = None
69
 
        self._lock_count = 0
70
60
        self._transport = transport
 
61
        if LockWarner is None:
 
62
            # Bzr 1.13
 
63
            self._lock_count = 0
 
64
        else:
 
65
            self._lock_warner = LockWarner(repr(self))
71
66
 
72
67
 
73
68
class GitDir(bzrdir.BzrDir):
77
72
        return True
78
73
 
79
74
    def cloning_metadir(self, stacked=False):
80
 
        return bzrlib.bzrdir.format_registry.make_bzrdir("1.9-rich-root")
 
75
        return get_rich_root_format(stacked)
81
76
 
82
77
 
83
78
class LocalGitDir(GitDir):
84
79
    """An adapter to the '.git' dir used by git."""
85
80
 
86
 
    _gitrepository_class = repository.LocalGitRepository
 
81
    def _get_gitrepository_class(self):
 
82
        from bzrlib.plugins.git.repository import LocalGitRepository
 
83
        return LocalGitRepository
 
84
 
 
85
    _gitrepository_class = property(_get_gitrepository_class)
87
86
 
88
87
    def __init__(self, transport, lockfiles, gitrepo, format):
89
88
        self._format = format
94
93
        else:
95
94
            self.transport = transport.clone('.git')
96
95
        self._lockfiles = lockfiles
 
96
        self._mode_check_done = None
 
97
 
 
98
    def is_control_filename(self, filename):
 
99
        return filename == '.git' or filename.startswith('.git/')
97
100
 
98
101
    def get_branch_transport(self, branch_format):
99
102
        if branch_format is None:
100
103
            return self.transport
101
104
        if isinstance(branch_format, LocalGitBzrDirFormat):
102
105
            return self.transport
103
 
        raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
 
106
        raise bzr_errors.IncompatibleFormat(branch_format, self._format)
104
107
 
105
108
    get_repository_transport = get_branch_transport
106
109
    get_workingtree_transport = get_branch_transport
107
110
 
108
 
    def open_branch(self, ignored=None):
 
111
    def open_branch(self, ignore_fallbacks=None):
109
112
        """'create' a branch for this dir."""
110
113
        repo = self.open_repository()
111
 
        return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(), self._lockfiles)
 
114
        from bzrlib.plugins.git.branch import LocalGitBranch
 
115
        return LocalGitBranch(self, repo, "HEAD", self._lockfiles)
112
116
 
113
117
    def open_repository(self, shared=False):
114
118
        """'open' a repository for this dir."""
115
119
        return self._gitrepository_class(self, self._lockfiles)
116
120
 
117
121
    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(), 
 
122
        if not self._git.bare and self._git.has_index():
 
123
            from bzrlib.plugins.git.workingtree import GitWorkingTree
 
124
            return GitWorkingTree(self, self.open_repository(), 
121
125
                                                  self.open_branch())
122
126
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
123
 
        raise errors.bzr_errors.NoWorkingTree(loc)
 
127
        raise bzr_errors.NoWorkingTree(loc)
124
128
 
125
129
    def create_repository(self, shared=False):
126
130
        return self.open_repository()
 
131
 
 
132
    def create_branch(self):
 
133
        return self.open_branch()
 
134
 
 
135
    def backup_bzrdir(self):
 
136
        if self._git.bare:
 
137
            self.root_transport.copy_tree(".git", ".git.backup")
 
138
            return (self.root_transport.abspath(".git"),
 
139
                    self.root_transport.abspath(".git.backup"))
 
140
        else:
 
141
            raise bzr_errors.BzrError("Unable to backup bare repositories")
 
142
 
 
143
    def create_workingtree(self, revision_id=None, from_branch=None,
 
144
        accelerator_tree=None, hardlink=False):
 
145
        if self._git.bare:
 
146
            raise bzr_errors.BzrError("Can't create working tree in a bare repo")
 
147
        from dulwich.index import write_index
 
148
        from dulwich.pack import SHA1Writer
 
149
        f = open(self.transport.local_abspath("index"), 'w+')
 
150
        try:
 
151
            f = SHA1Writer(f)
 
152
            write_index(f, [])
 
153
        finally:
 
154
            f.close()
 
155
        return self.open_workingtree()