/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

Initial work on supporting move_in_thin_pack.

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 (
443
446
        self._add_known_pack(final_pack)
444
447
        return final_pack
445
448
 
 
449
    def add_thin_pack(self):
 
450
        """Add a new thin pack to this object store.
 
451
 
 
452
        Thin packs are packs that contain deltas with parents that exist
 
453
        in a different pack.
 
454
        """
 
455
        from cStringIO import StringIO
 
456
        f = StringIO()
 
457
        def commit():
 
458
            if len(f.getvalue()) > 0:
 
459
                return self.move_in_thin_pack(f)
 
460
            else:
 
461
                return None
 
462
        return f, commit
 
463
 
 
464
    def move_in_thin_pack(self, f):
 
465
        """Move a specific file containing a pack into the pack directory.
 
466
 
 
467
        :note: The file should be on the same file system as the
 
468
            packs directory.
 
469
 
 
470
        :param path: Path to the pack file.
 
471
        """
 
472
        f.seek(0)
 
473
        data = ThinPackData.from_file(self.get_raw, f, len(f.getvalue()))
 
474
        idx = MemoryPackIndex(data.sorted_entries(), data.get_stored_checksum())
 
475
        p = Pack.from_objects(data, idx)
 
476
 
 
477
        pack_sha = idx.objects_sha1()
 
478
 
 
479
        datafile = self.pack_transport.open_write_stream("pack-%s.pack" % pack_sha)
 
480
        try:
 
481
            entries, data_sum = write_pack_data(datafile, ((o, None) for o in p.iterobjects()), len(p))
 
482
        finally:
 
483
            datafile.close()
 
484
        entries.sort()
 
485
        idxfile = self.pack_transport.open_write_stream("pack-%s.idx" % pack_sha)
 
486
        try:
 
487
            write_pack_index_v2(idxfile, data.sorted_entries(), data_sum)
 
488
        finally:
 
489
            idxfile.close()
 
490
        final_pack = Pack("pack-%s" % pack_sha)
 
491
        self._add_known_pack(final_pack)
 
492
        return final_pack
 
493
 
 
494
 
 
495
 
446
496
    def add_pack(self):
447
497
        """Add a new pack to this object store. 
448
498