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

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2019-02-14 02:18:20 UTC
  • mfrom: (7268.1.1 dulwich-compat)
  • Revision ID: breezy.the.bot@gmail.com-20190214021820-dguuvpfwt68nkvuy
Fix compatibility with newer versions of Dulwich.

Merged from https://code.launchpad.net/~jelmer/brz/dulwich-compat/+merge/362765

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
from dulwich.object_store import (
37
37
    PackBasedObjectStore,
38
38
    PACKDIR,
 
39
    read_packs_file,
39
40
    )
40
41
from dulwich.pack import (
41
42
    MemoryPackIndex,
587
588
                ret.append(l)
588
589
            return ret
589
590
 
590
 
    @property
591
 
    def packs(self):
592
 
        # FIXME: Never invalidates.
593
 
        if not self._pack_cache:
594
 
            self._update_pack_cache()
595
 
        return self._pack_cache.values()
596
 
 
597
591
    def _update_pack_cache(self):
598
 
        for pack in self._load_packs():
599
 
            self._pack_cache[pack._basename] = pack
 
592
        pack_files = set()
 
593
        pack_dir_contents = self._pack_names()
 
594
        for name in pack_dir_contents:
 
595
            if name.startswith("pack-") and name.endswith(".pack"):
 
596
                # verify that idx exists first (otherwise the pack was not yet
 
597
                # fully written)
 
598
                idx_name = os.path.splitext(name)[0] + ".idx"
 
599
                if idx_name in pack_dir_contents:
 
600
                    pack_files.add(os.path.splitext(name)[0])
 
601
 
 
602
        new_packs = []
 
603
        for basename in pack_files:
 
604
            pack_name = basename + ".pack"
 
605
            if basename not in self._pack_cache:
 
606
                try:
 
607
                    size = self.pack_transport.stat(pack_name).st_size
 
608
                except TransportNotPossible:
 
609
                    f = self.pack_transport.get(pack_name)
 
610
                    pd = PackData(pack_name, f)
 
611
                else:
 
612
                    pd = PackData(
 
613
                        pack_name, self.pack_transport.get(pack_name),
 
614
                        size=size)
 
615
                idxname = basename + ".idx"
 
616
                idx = load_pack_index_file(
 
617
                    idxname, self.pack_transport.get(idxname))
 
618
                pack = Pack.from_objects(pd, idx)
 
619
                pack._basename = basename
 
620
                self._pack_cache[basename] = pack
 
621
                new_packs.append(pack)
 
622
        # Remove disappeared pack files
 
623
        for f in set(self._pack_cache) - pack_files:
 
624
            self._pack_cache.pop(f).close()
 
625
        return new_packs
600
626
 
601
627
    def _pack_names(self):
602
628
        try:
608
634
                # Hmm, warn about running 'git update-server-info' ?
609
635
                return iter([])
610
636
            else:
611
 
                # TODO(jelmer): Move to top-level after dulwich
612
 
                # 0.19.7 is released.
613
 
                from dulwich.object_store import read_packs_file
614
637
                with f:
615
638
                    return read_packs_file(f)
616
639
        except NoSuchFile:
619
642
    def _remove_pack(self, pack):
620
643
        self.pack_transport.delete(os.path.basename(pack.index.path))
621
644
        self.pack_transport.delete(pack.data.filename)
622
 
 
623
 
    def _load_packs(self):
624
 
        ret = []
625
 
        for name in self._pack_names():
626
 
            if name.startswith("pack-") and name.endswith(".pack"):
627
 
                try:
628
 
                    size = self.pack_transport.stat(name).st_size
629
 
                except TransportNotPossible:
630
 
                    f = self.pack_transport.get(name)
631
 
                    pd = PackData(name, f)
632
 
                else:
633
 
                    pd = PackData(name, self.pack_transport.get(name),
634
 
                                  size=size)
635
 
                idxname = name.replace(".pack", ".idx")
636
 
                idx = load_pack_index_file(
637
 
                    idxname, self.pack_transport.get(idxname))
638
 
                pack = Pack.from_objects(pd, idx)
639
 
                pack._basename = idxname[:-4]
640
 
                ret.append(pack)
641
 
        return ret
 
645
        try:
 
646
            del self._pack_cache[os.path.basename(pack._basename)]
 
647
        except KeyError:
 
648
            pass
642
649
 
643
650
    def _iter_loose_objects(self):
644
651
        for base in self.transport.list_dir('.'):
702
709
        idx = load_pack_index_file(basename + ".idx", idxfile)
703
710
        final_pack = Pack.from_objects(p, idx)
704
711
        final_pack._basename = basename
705
 
        self._add_known_pack(basename, final_pack)
 
712
        self._add_cached_pack(basename, final_pack)
706
713
        return final_pack
707
714
 
708
715
    def move_in_thin_pack(self, f):
735
742
            write_pack_index_v2(idxfile, entries, data_sum)
736
743
        finally:
737
744
            idxfile.close()
738
 
        # TODO(jelmer): Just add new pack to the cache
739
 
        self._flush_pack_cache()
740
745
 
741
746
    def add_pack(self):
742
747
        """Add a new pack to this object store.