~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-10-29 22:17:03 UTC
  • mfrom: (2947.1.7 pack-progress)
  • Revision ID: pqm@pqm.ubuntu.com-20071029221703-zy7q7a0ehfvpybtn
(robertc) Add a progress bar has been added for knitpack -> knitpack fetching. (Robert Collins, #157789)

Show diffs side-by-side

added added

removed removed

Lines of Context:
623
623
                return None
624
624
            else:
625
625
                revision_ids = frozenset(revision_ids)
 
626
        pb = ui.ui_factory.nested_progress_bar()
 
627
        try:
 
628
            return self._create_pack_from_packs(packs, suffix, revision_ids,
 
629
                pb)
 
630
        finally:
 
631
            pb.finished()
 
632
 
 
633
    def _create_pack_from_packs(self, packs, suffix, revision_ids, pb):
 
634
        pb.update("Opening pack", 0, 5)
626
635
        new_pack = NewPack(self._upload_transport, self._index_transport,
627
636
            self._pack_transport, upload_suffix=suffix)
628
637
        # buffer data - we won't be reading-back during the pack creation and
650
659
            packs, 'revision_index')[0]
651
660
        revision_nodes = self._index_contents(revision_index_map, revision_keys)
652
661
        # copy revision keys and adjust values
 
662
        pb.update("Copying revision texts", 1)
653
663
        list(self._copy_nodes_graph(revision_nodes, revision_index_map,
654
664
            new_pack._writer, new_pack.revision_index))
655
665
        if 'pack' in debug.debug_flags:
668
678
        # copy inventory keys and adjust values
669
679
        # XXX: Should be a helper function to allow different inv representation
670
680
        # at this point.
 
681
        pb.update("Copying inventory texts", 2)
671
682
        inv_lines = self._copy_nodes_graph(inv_nodes, inventory_index_map,
672
683
            new_pack._writer, new_pack.inventory_index, output_lines=True)
673
684
        if revision_ids:
707
718
                raise errors.RevisionNotPresent(a_missing_key[1],
708
719
                    a_missing_key[0])
709
720
        # copy text keys and adjust values
 
721
        pb.update("Copying content texts", 3)
710
722
        list(self._copy_nodes_graph(text_nodes, text_index_map,
711
723
            new_pack._writer, new_pack.text_index))
712
724
        if 'pack' in debug.debug_flags:
721
733
        signature_nodes = self._index_contents(signature_index_map,
722
734
            signature_filter)
723
735
        # copy signature keys and adjust values
 
736
        pb.update("Copying signature texts", 4)
724
737
        self._copy_nodes(signature_nodes, signature_index_map, new_pack._writer,
725
738
            new_pack.signature_index)
726
739
        if 'pack' in debug.debug_flags:
731
744
        if not new_pack.data_inserted():
732
745
            new_pack.abort()
733
746
            return None
 
747
        pb.update("Finishing pack", 5)
734
748
        new_pack.finish()
735
749
        self.allocate(new_pack)
736
750
        return new_pack
828
842
        return pack_operations
829
843
 
830
844
    def _copy_nodes(self, nodes, index_map, writer, write_index):
 
845
        """Copy knit nodes between packs with no graph references."""
 
846
        pb = ui.ui_factory.nested_progress_bar()
 
847
        try:
 
848
            return self._do_copy_nodes(nodes, index_map, writer,
 
849
                write_index, pb)
 
850
        finally:
 
851
            pb.finished()
 
852
 
 
853
    def _do_copy_nodes(self, nodes, index_map, writer, write_index, pb):
 
854
        # for record verification
 
855
        knit_data = _KnitData(None)
831
856
        # plan a readv on each source pack:
832
857
        # group by pack
833
858
        nodes = sorted(nodes)
840
865
            if index not in request_groups:
841
866
                request_groups[index] = []
842
867
            request_groups[index].append((key, value))
 
868
        record_index = 0
 
869
        pb.update("Copied record", record_index, len(nodes))
843
870
        for index, items in request_groups.iteritems():
844
871
            pack_readv_requests = []
845
872
            for key, value in items:
856
883
            for (names, read_func), (_1, _2, (key, eol_flag)) in \
857
884
                izip(reader.iter_records(), pack_readv_requests):
858
885
                raw_data = read_func(None)
 
886
                # check the header only
 
887
                df, _ = knit_data._parse_record_header(key[-1], raw_data)
 
888
                df.close()
859
889
                pos, size = writer.add_bytes_record(raw_data, names)
860
890
                write_index.add_node(key, eol_flag + "%d %d" % (pos, size))
 
891
                pb.update("Copied record", record_index)
 
892
                record_index += 1
861
893
 
862
894
    def _copy_nodes_graph(self, nodes, index_map, writer, write_index,
863
895
        output_lines=False):
866
898
        :param output_lines: Return lines present in the copied data as
867
899
            an iterator.
868
900
        """
 
901
        pb = ui.ui_factory.nested_progress_bar()
 
902
        try:
 
903
            return self._do_copy_nodes_graph(nodes, index_map, writer,
 
904
                write_index, output_lines, pb)
 
905
        finally:
 
906
            pb.finished()
 
907
 
 
908
    def _do_copy_nodes_graph(self, nodes, index_map, writer, write_index,
 
909
        output_lines, pb):
869
910
        # for record verification
870
911
        knit_data = _KnitData(None)
871
912
        # for line extraction when requested (inventories only)
879
920
        # at this point - perhaps a helper library for the following code 
880
921
        # duplication points?
881
922
        request_groups = {}
 
923
        record_index = 0
 
924
        pb.update("Copied record", record_index, len(nodes))
882
925
        for index, key, value, references in nodes:
883
926
            if index not in request_groups:
884
927
                request_groups[index] = []
914
957
                    df.close()
915
958
                pos, size = writer.add_bytes_record(raw_data, names)
916
959
                write_index.add_node(key, eol_flag + "%d %d" % (pos, size), references)
 
960
                pb.update("Copied record", record_index)
 
961
                record_index += 1
917
962
 
918
963
    def ensure_loaded(self):
919
964
        # NB: if you see an assertion error here, its probably access against