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

More work on roundtrip push support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    PACKDIR,
31
31
    )
32
32
from dulwich.pack import (
 
33
    MemoryPackIndex,
33
34
    PackData,
34
35
    Pack,
 
36
    ThinPackData,
35
37
    iter_sha1,
36
38
    load_pack_index_file,
 
39
    write_pack_data,
37
40
    write_pack_index_v2,
38
41
    )
39
42
from dulwich.repo import (
282
285
            if self.transport.has(".git/%s" % OBJECTDIR):
283
286
                self.bare = False
284
287
                self._controltransport = self.transport.clone('.git')
285
 
            elif self.transport.has(OBJECTDIR) or self.transport.has(REFSDIR):
 
288
            elif self.transport.has_any(["info/refs", OBJECTDIR, REFSDIR]):
286
289
                self.bare = True
287
290
                self._controltransport = self.transport
288
291
            else:
327
330
        return not self.bare
328
331
 
329
332
    def __repr__(self):
330
 
        return "<TransportRepo for %r>" % self.transport
 
333
        return "<%s for %r>" % (self.__class__.__name__, self.transport)
331
334
 
332
335
 
333
336
class TransportObjectStore(PackBasedObjectStore):
341
344
        super(TransportObjectStore, self).__init__()
342
345
        self.transport = transport
343
346
        self.pack_transport = self.transport.clone(PACKDIR)
344
 
    
 
347
 
 
348
    def __repr__(self):
 
349
        return "%s(%r)" % (self.__class__.__name__, self.transport)
 
350
 
345
351
    def _pack_cache_stale(self):
346
352
        return False # FIXME
347
353
 
443
449
        self._add_known_pack(final_pack)
444
450
        return final_pack
445
451
 
 
452
    def add_thin_pack(self):
 
453
        """Add a new thin pack to this object store.
 
454
 
 
455
        Thin packs are packs that contain deltas with parents that exist
 
456
        in a different pack.
 
457
        """
 
458
        from cStringIO import StringIO
 
459
        f = StringIO()
 
460
        def commit():
 
461
            if len(f.getvalue()) > 0:
 
462
                return self.move_in_thin_pack(f)
 
463
            else:
 
464
                return None
 
465
        return f, commit
 
466
 
 
467
    def move_in_thin_pack(self, f):
 
468
        """Move a specific file containing a pack into the pack directory.
 
469
 
 
470
        :note: The file should be on the same file system as the
 
471
            packs directory.
 
472
 
 
473
        :param path: Path to the pack file.
 
474
        """
 
475
        f.seek(0)
 
476
        data = ThinPackData.from_file(self.get_raw, f, len(f.getvalue()))
 
477
        idx = MemoryPackIndex(data.sorted_entries(), data.get_stored_checksum())
 
478
        p = Pack.from_objects(data, idx)
 
479
 
 
480
        pack_sha = idx.objects_sha1()
 
481
 
 
482
        datafile = self.pack_transport.open_write_stream("pack-%s.pack" % pack_sha)
 
483
        try:
 
484
            entries, data_sum = write_pack_data(datafile, ((o, None) for o in p.iterobjects()), len(p))
 
485
        finally:
 
486
            datafile.close()
 
487
        entries.sort()
 
488
        idxfile = self.pack_transport.open_write_stream("pack-%s.idx" % pack_sha)
 
489
        try:
 
490
            write_pack_index_v2(idxfile, data.sorted_entries(), data_sum)
 
491
        finally:
 
492
            idxfile.close()
 
493
        final_pack = Pack("pack-%s" % pack_sha)
 
494
        self._add_known_pack(final_pack)
 
495
        return final_pack
 
496
 
 
497
 
 
498
 
446
499
    def add_pack(self):
447
500
        """Add a new pack to this object store. 
448
501