/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

Simplify TemporaryPack implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
import urlparse
39
39
 
40
40
import dulwich as git
41
 
from dulwich.pack import PackData, Pack
 
41
from dulwich.pack import PackData, Pack, PackIndex
42
42
 
43
43
# Don't run any tests on GitSmartTransport as it is not intended to be 
44
44
# a full implementation of Transport
106
106
        raise NotLocalUrl(self.transport.base)
107
107
 
108
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
 
        self.iterobjects = self.pack.iterobjects
120
 
 
121
 
    def __getitem__(self, key):
122
 
        return self.pack[key]
123
 
 
124
 
    def __contains__(self, key):
125
 
        return key in self.pack
 
109
class TemporaryPackIterator(Pack):
 
110
 
 
111
    @property
 
112
    def idx(self):
 
113
        if self._idx is None:
 
114
            self._data.create_index_v2(self._idx_path)
 
115
            self._idx = PackIndex(self._idx_path)
 
116
        return self._idx
126
117
 
127
118
    def __del__(self):
128
 
        os.remove(self.path_data)
129
 
        os.remove(self.path_idx)
130
 
 
131
 
    def next(self):
132
 
        return (self._iter.next(), None)
133
 
 
134
 
    def __len__(self):
135
 
        return len(self.pack)
 
119
        os.remove(self._data_path)
 
120
        os.remove(self._idx_path)
136
121
 
137
122
 
138
123
class RemoteGitRepository(GitRepository):
149
134
        fd, path = tempfile.mkstemp(suffix=".pack")
150
135
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
151
136
        os.close(fd)
152
 
        return TemporaryPackIterator(path)
 
137
        return TemporaryPackIterator(path[:-len(".pack")])
153
138
 
154
139
 
155
140
class RemoteGitBranch(GitBranch):