/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

Properly set InventoryEntry revision when changing symlink targets.

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
import bzrlib
17
18
from bzrlib import (
18
 
    config,
 
19
    branch,
19
20
    tag,
20
 
    trace,
21
21
    ui,
22
22
    urlutils,
23
23
    )
55
55
    mapping_registry,
56
56
    )
57
57
from bzrlib.plugins.git.repository import (
 
58
    GitRepositoryFormat,
58
59
    GitRepository,
59
60
    )
60
61
 
71
72
import urllib
72
73
import urlparse
73
74
 
74
 
from dulwich.pack import load_pack_index
75
 
 
76
 
 
77
 
# Don't run any tests on GitSmartTransport as it is not intended to be
 
75
try:
 
76
    from dulwich.pack import load_pack_index
 
77
except ImportError:
 
78
    from dulwich.pack import PackIndex as load_pack_index
 
79
 
 
80
 
 
81
# Don't run any tests on GitSmartTransport as it is not intended to be 
78
82
# a full implementation of Transport
79
83
def get_test_permutations():
80
84
    return []
85
89
    def __init__(self, url, _client=None):
86
90
        Transport.__init__(self, url)
87
91
        (scheme, _, loc, _, _) = urlparse.urlsplit(url)
88
 
        hostport, escaped_path = urllib.splithost(loc)
89
 
        self._path = urllib.unquote(escaped_path)
 
92
        hostport, self._path = urllib.splithost(loc)
90
93
        (self._username, hostport) = urllib.splituser(hostport)
91
94
        (self._host, self._port) = urllib.splitnport(hostport, None)
92
95
        self._client = _client
97
100
    def has(self, relpath):
98
101
        return False
99
102
 
100
 
    def _get_client(self, thin_packs):
 
103
    def _get_client(self):
101
104
        raise NotImplementedError(self._get_client)
102
105
 
103
106
    def _get_path(self):
107
110
        if progress is None:
108
111
            def progress(text):
109
112
                info("git: %s" % text)
110
 
        client = self._get_client(thin_packs=False)
 
113
        client = self._get_client()
111
114
        try:
112
 
            return client.fetch_pack(self._get_path(), determine_wants,
 
115
            return client.fetch_pack(self._get_path(), determine_wants, 
113
116
                graph_walker, pack_data, progress)
114
117
        except GitProtocolError, e:
115
118
            raise BzrError(e)
116
119
 
117
120
    def send_pack(self, get_changed_refs, generate_pack_contents):
118
 
        client = self._get_client(thin_packs=False)
 
121
        client = self._get_client()
119
122
        try:
120
 
            return client.send_pack(self._get_path(), get_changed_refs,
 
123
            return client.send_pack(self._get_path(), get_changed_refs, 
121
124
                generate_pack_contents)
122
125
        except GitProtocolError, e:
123
126
            raise BzrError(e)
142
145
 
143
146
    _scheme = 'git'
144
147
 
145
 
    def _get_client(self, thin_packs):
 
148
    def _get_client(self):
146
149
        if self._client is not None:
147
150
            ret = self._client
148
151
            self._client = None
149
152
            return ret
150
 
        return git.client.TCPGitClient(self._host, self._port, thin_packs=thin_packs,
 
153
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False,
151
154
            report_activity=self._report_activity)
152
155
 
153
156
 
160
163
            return self._path[3:]
161
164
        return self._path
162
165
 
163
 
    def _get_client(self, thin_packs):
 
166
    def _get_client(self):
164
167
        if self._client is not None:
165
168
            ret = self._client
166
169
            self._client = None
167
170
            return ret
168
171
        return git.client.SSHGitClient(self._host, self._port, self._username,
169
 
            thin_packs=thin_packs, report_activity=self._report_activity)
 
172
            thin_packs=False, report_activity=self._report_activity)
170
173
 
171
174
 
172
175
class RemoteGitDir(GitDir):
186
189
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
187
190
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
188
191
 
189
 
    def open_workingtree(self, recommend_upgrade=False):
 
192
    def open_workingtree(self):
190
193
        raise NotLocalUrl(self.transport.base)
191
194
 
192
195
 
203
206
        self.resolve_ext_ref = resolve_ext_ref
204
207
 
205
208
    @property
206
 
    def data(self):
207
 
        if self._data is None:
208
 
            self._data = PackData(self._data_path)
209
 
        return self._data
210
 
 
211
 
    @property
212
209
    def index(self):
213
210
        if self._idx is None:
214
 
            if not os.path.exists(self._idx_path):
215
 
                pb = ui.ui_factory.nested_progress_bar()
216
 
                try:
217
 
                    def report_progress(cur, total):
218
 
                        pb.update("generating index", cur, total)
219
 
                    self.data.create_index(self._idx_path, self.resolve_ext_ref,
220
 
                        progress=report_progress)
221
 
                finally:
222
 
                    pb.finished()
 
211
            pb = ui.ui_factory.nested_progress_bar()
 
212
            try:
 
213
                def report_progress(cur, total):
 
214
                    pb.update("generating index", cur, total)
 
215
                self.data.create_index(self._idx_path, self.resolve_ext_ref,
 
216
                    progress=report_progress)
 
217
            finally:
 
218
                pb.finished()
223
219
            self._idx = load_pack_index(self._idx_path)
224
220
        return self._idx
225
221
 
226
222
    def __del__(self):
227
 
        if self._idx is not None:
228
 
            self._idx.close()
229
 
            os.remove(self._idx_path)
230
 
        if self._data is not None:
231
 
            self._data.close()
232
 
            os.remove(self._data_path)
 
223
        os.remove(self._data_path)
 
224
        os.remove(self._idx_path)
233
225
 
234
226
 
235
227
class RemoteGitRepository(GitRepository):
253
245
    def get_refs(self):
254
246
        if self._refs is not None:
255
247
            return self._refs
256
 
        self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None,
257
 
            lambda x: None, lambda x: trace.mutter("git: %s" % x))
 
248
        self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None, 
 
249
            lambda x: None, lambda x: mutter("git: %s" % x))
258
250
        return self._refs
259
251
 
260
 
    def fetch_pack(self, determine_wants, graph_walker, pack_data,
 
252
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
261
253
                   progress=None):
262
254
        return self._transport.fetch_pack(determine_wants, graph_walker,
263
255
                                          pack_data, progress)
265
257
    def send_pack(self, get_changed_refs, generate_pack_contents):
266
258
        return self._transport.send_pack(get_changed_refs, generate_pack_contents)
267
259
 
268
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
269
 
                      progress=None):
 
260
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
270
261
        fd, path = tempfile.mkstemp(suffix=".pack")
271
 
        self.fetch_pack(determine_wants, graph_walker,
272
 
            lambda x: os.write(fd, x), progress)
 
262
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
273
263
        os.close(fd)
274
264
        if os.path.getsize(path) == 0:
275
265
            return EmptyObjectStoreIterator()
276
266
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
277
267
 
278
 
    def lookup_bzr_revision_id(self, bzr_revid):
 
268
    def lookup_git_revid(self, bzr_revid):
279
269
        # This won't work for any round-tripped bzr revisions, but it's a start..
280
270
        try:
281
271
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
290
280
        self.repository = branch.repository
291
281
 
292
282
    def get_tag_dict(self):
293
 
        tags = {}
294
 
        for k, v in extract_tags(self.repository.get_refs()).iteritems():
295
 
            tags[k] = self.branch.mapping.revision_id_foreign_to_bzr(v)
296
 
        return tags
 
283
        return extract_tags(self.repository.get_refs(), self.branch.mapping)
297
284
 
298
285
    def set_tag(self, name, revid):
299
286
        # FIXME: Not supported yet, should do a push of a new ref
304
291
 
305
292
    def __init__(self, bzrdir, repository, name, lockfiles):
306
293
        self._ref = None
307
 
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
 
294
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, 
308
295
                lockfiles)
309
296
 
310
297
    def revision_history(self):
313
300
    def last_revision(self):
314
301
        return self.mapping.revision_id_foreign_to_bzr(self.head)
315
302
 
316
 
    def _get_config(self):
317
 
        class EmptyConfig(object):
318
 
 
319
 
            def _get_configobj(self):
320
 
                return config.ConfigObj()
321
 
 
322
 
        return EmptyConfig()
323
 
 
324
303
    @property
325
304
    def head(self):
326
305
        if self._ref is not None:
327
306
            return self._ref
328
307
        heads = self.repository.get_refs()
329
308
        if not self.name in heads:
330
 
            raise NoSuchRef(self.name)
 
309
            raise NoSuchRef(name)
331
310
        self._ref = heads[self.name]
332
311
        return self._ref
333
312
 
334
313
    def _synchronize_history(self, destination, revision_id):
335
314
        """See Branch._synchronize_history()."""
336
315
        destination.generate_revision_history(self.last_revision())
337
 
 
 
316
 
338
317
    def get_push_location(self):
339
318
        return None
340
319