/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 remote.py

Pass repository object to versionedfiles.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib.trace import info
24
24
from bzrlib.transport import Transport
25
25
 
26
 
from bzrlib.plugins.git import git
 
26
from bzrlib.plugins.git import lazy_check_versions
 
27
lazy_check_versions()
 
28
 
27
29
from bzrlib.plugins.git.branch import GitBranch
28
30
from bzrlib.plugins.git.errors import NoSuchRef
29
31
from bzrlib.plugins.git.dir import GitDir
35
37
import urllib
36
38
import urlparse
37
39
 
 
40
import dulwich as git
38
41
from dulwich.pack import PackData, Pack
39
42
 
 
43
# Don't run any tests on GitSmartTransport as it is not intended to be 
 
44
# a full implementation of Transport
 
45
def get_test_permutations():
 
46
    return []
 
47
 
40
48
 
41
49
class GitSmartTransport(Transport):
42
50
 
89
97
    def open_repository(self):
90
98
        return RemoteGitRepository(self, self._lockfiles)
91
99
 
92
 
    def open_branch(self):
 
100
    def open_branch(self, _unsupported=False):
93
101
        repo = self.open_repository()
94
102
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
95
103
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
98
106
        raise NotLocalUrl(self.transport.base)
99
107
 
100
108
 
 
109
class TemporaryPackIterator(object):
 
110
 
 
111
    def __init__(self, path):
 
112
        self.path_data = path
 
113
        basename = path[:-len(".pack")]
 
114
        p = PackData(path)
 
115
        self.path_idx = basename+".idx"
 
116
        p.create_index_v2(self.path_idx)
 
117
        self.pack = Pack(basename)
 
118
        self._iter = self.pack.iterobjects()
 
119
 
 
120
    def __del__(self):
 
121
        os.remove(self.path_data)
 
122
        os.remove(self.path_idx)
 
123
 
 
124
    def next(self):
 
125
        return (self._iter.next(), None)
 
126
 
 
127
    def __len__(self):
 
128
        return len(self.pack)
 
129
 
 
130
 
101
131
class RemoteGitRepository(GitRepository):
102
132
 
103
133
    def __init__(self, gitdir, lockfiles):
112
142
        fd, path = tempfile.mkstemp(suffix=".pack")
113
143
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
114
144
        os.close(fd)
115
 
        try:
116
 
            basename = path[:-len(".pack")]
117
 
            p = PackData(path)
118
 
            p.create_index_v2(basename+".idx")
119
 
            for o in Pack(basename).iterobjects():
120
 
                yield o
121
 
        finally:
122
 
            os.remove(path)
 
145
        ret = TemporaryPackIterator(path)
 
146
        return (len(ret), iter(ret.next, None))
123
147
 
124
148
 
125
149
class RemoteGitBranch(GitBranch):