~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/repository.py

  • Committer: Parth Malwankar
  • Date: 2010-05-14 13:25:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5241.
  • Revision ID: parth.malwankar@gmail.com-20100514132505-ba9rxnpooifq4o5q
code cleanup and comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
502
502
    pack_writer = pack.ContainerSerialiser()
503
503
    yield pack_writer.begin()
504
504
    yield pack_writer.bytes_record(src_format.network_name(), '')
505
 
    #key_count = 0
506
 
    #rc = RecordCounter()
507
 
    #pb = ui.ui_factory.nested_progress_bar()
508
 
    #pb.update('', rc.current, rc.max)
509
505
    for substream_type, substream in stream:
510
 
        #counter = 0
511
506
        for record in substream:
512
 
            #counter +=1
513
 
            #if substream_type == 'revisions':
514
 
            #    key_count += 1
515
 
            #elif rc.is_initialized():
516
 
            #    if counter == rc.STEP:
517
 
            #        rc.increment(counter)
518
 
            #        pb.update('', rc.current, rc.max)
519
 
            #        counter = 0
520
507
            if record.storage_kind in ('chunked', 'fulltext'):
521
508
                serialised = record_to_fulltext_bytes(record)
522
509
            elif record.storage_kind == 'inventory-delta':
530
517
                # representation of the first record, which means that
531
518
                # later records have no wire representation: we skip them.
532
519
                yield pack_writer.bytes_record(serialised, [(substream_type,)])
533
 
        #if substream_type == 'revisions':
534
 
        #    rc.setup(key_count, current=key_count)
535
 
    #pb.update('', rc.max, rc.max)
536
 
    #pb.finished()
537
520
    yield pack_writer.end()
538
521
 
539
522
 
568
551
        self.current_type = None
569
552
        self.first_bytes = None
570
553
        self.byte_stream = byte_stream
571
 
        self.record_counter = record_counter
 
554
        self._record_counter = record_counter
572
555
        self.revisions_processed = False
573
556
        self.key_count = 0
574
557
 
578
561
        for record in self.stream_decoder.read_pending_records():
579
562
            yield record
580
563
 
581
 
        #key_count = 0
582
 
        #rc = RecordCounter()
583
 
        #pb = ui.ui_factory.nested_progress_bar()
584
564
        # Pull bytes of the wire, decode them to records, yield those records.
585
565
        for bytes in self.byte_stream:
586
566
            self.stream_decoder.accept_bytes(bytes)
587
 
            #counter = 0
588
567
            for record in self.stream_decoder.read_pending_records():
589
 
                #if self.current_type == 'revisions':
590
 
                #    pb.update('Estimating..', key_count)
591
 
                #    key_count += 1
592
 
                #elif rc.is_initialized():
593
 
                #    if counter == rc.STEP:
594
 
                #        rc.increment(counter)
595
 
                #        pb.update('Estimate', rc.current, rc.max)
596
 
                #        counter = 0
597
 
                #    counter += 1
598
568
                yield record
599
 
            #if self.current_type == 'revisions':
600
 
            #   rc.setup(key_count, current=key_count)
601
 
        #pb.update('Estimate', rc.max, rc.max)
602
 
        #pb.finished()
603
569
 
604
570
    def iter_substream_bytes(self):
605
571
        if self.first_bytes is not None:
619
585
 
620
586
    def record_stream(self):
621
587
        """Yield substream_type, substream from the byte stream."""
 
588
        def wrap_and_count(pb, rc, substream):
 
589
            """Yield records from stream while showing progress."""
 
590
            counter = 0
 
591
            if rc:
 
592
                if self.current_type != 'revisions' and self.key_count != 0:
 
593
                    # As we know the number of revisions now (in self.key_count)
 
594
                    # we can setup and use record_counter (rc).
 
595
                    if not rc.is_initialized():
 
596
                        rc.setup(self.key_count, self.key_count)
 
597
            for record in substream.read():
 
598
                if rc:
 
599
                    if rc.is_initialized() and counter == rc.STEP:
 
600
                        rc.increment(counter)
 
601
                        pb.update('Estimate', rc.current, rc.max)
 
602
                        counter = 0
 
603
                    if self.current_type == 'revisions':
 
604
                        # Total records is proportional to number of revs
 
605
                        # to fetch. With remote, we used self.key_count to
 
606
                        # track the number of revs. Once we have the revs
 
607
                        # counts in self.key_count, the progress bar changes
 
608
                        # from 'Estimating..' to 'Estimate' above.
 
609
                        self.key_count += 1
 
610
                        if counter == rc.STEP:
 
611
                            pb.update('Estimating..', self.key_count)
 
612
                            counter = 0
 
613
                counter += 1
 
614
                yield record
 
615
 
622
616
        self.seed_state()
623
617
        pb = ui.ui_factory.nested_progress_bar()
 
618
        rc = self._record_counter
624
619
        # Make and consume sub generators, one per substream type:
625
620
        while self.first_bytes is not None:
626
621
            substream = NetworkRecordStream(self.iter_substream_bytes())
627
622
            # after substream is fully consumed, self.current_type is set to
628
623
            # the next type, and self.first_bytes is set to the matching bytes.
629
 
            def wrap_and_count(substream):
630
 
                counter = 0
631
 
                if self.record_counter:
632
 
                    if self.current_type != 'revisions' and self.key_count != 0:
633
 
                        if not self.record_counter.is_initialized():
634
 
                            self.record_counter.setup(self.key_count,
635
 
                                self.key_count)
636
 
                for record in substream.read():
637
 
                    if self.record_counter:
638
 
                        if self.record_counter.is_initialized() and \
639
 
                                counter == self.record_counter.STEP:
640
 
                            self.record_counter.increment(counter)
641
 
                            pb.update('Estimate', self.record_counter.current,
642
 
                                self.record_counter.max)
643
 
                            counter = 0
644
 
                        if self.current_type == 'revisions':
645
 
                            self.key_count += 1
646
 
                            if counter == self.record_counter.STEP:
647
 
                                pb.update('Estimating..', self.key_count)
648
 
                                counter = 0
649
 
                    counter += 1
650
 
                    yield record
651
 
 
652
 
            yield self.current_type, wrap_and_count(substream)
653
 
        if self.record_counter:
654
 
            pb.update('Done', self.record_counter.max, self.record_counter.max)
 
624
            yield self.current_type, wrap_and_count(pb, rc, substream)
 
625
        if rc:
 
626
            pb.update('Done', rc.max, rc.max)
655
627
        pb.finished()
656
628
 
657
629
    def seed_state(self):