~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Jelmer Vernooij
  • Date: 2006-06-07 14:56:37 UTC
  • mto: This revision was merged to the branch mainline in revision 1753.
  • Revision ID: jelmer@samba.org-20060607145637-eeb5f28b78722502
Move inventory writing to the commit builder. 
Write ghost parents to knit repositories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
324
324
                        self.specific_files)
325
325
            self._check_parents_present()
326
326
            self.builder = self.branch.get_commit_builder(self.parents)
 
327
            self.builder.set_revision_id(self.rev_id)
327
328
            
328
329
            self._remove_deleted()
329
330
            self._populate_new_inv()
330
 
            self._store_snapshot()
331
331
            self._report_deletes()
332
332
 
333
333
            if not (self.allow_pointless
336
336
                raise PointlessCommit()
337
337
 
338
338
            self._emit_progress_update()
339
 
            self.inv_sha1 = self.branch.repository.add_inventory(
340
 
                self.rev_id,
341
 
                self.builder.new_inventory,
342
 
                self.present_parents
343
 
                )
 
339
            self.inv_sha1 = self.builder.finish_inventory()
344
340
            self._emit_progress_update()
345
341
            self._make_revision()
346
342
            # revision data is in the local branch now.
480
476
 
481
477
    def _gather_parents(self):
482
478
        """Record the parents of a merge for merge detection."""
 
479
        # TODO: Make sure that this list doesn't contain duplicate 
 
480
        # entries and the order is preserved when doing this.
483
481
        pending_merges = self.work_tree.pending_merges()
484
482
        self.parents = []
485
483
        self.parent_invs = []
486
 
        self.present_parents = []
487
484
        precursor_id = self.branch.last_revision()
488
485
        if precursor_id:
489
486
            self.parents.append(precursor_id)
492
489
            if self.branch.repository.has_revision(revision):
493
490
                inventory = self.branch.repository.get_inventory(revision)
494
491
                self.parent_invs.append(inventory)
495
 
                self.present_parents.append(revision)
496
492
 
497
493
    def _check_parents_present(self):
498
494
        for parent_id in self.parents:
542
538
                del self.work_inv[file_id]
543
539
            self.work_tree._write_inventory(self.work_inv)
544
540
 
545
 
    def _store_snapshot(self):
546
 
        """Pass over inventory and record a snapshot.
547
 
 
548
 
        Entries get a new revision when they are modified in 
549
 
        any way, which includes a merge with a new set of
550
 
        parents that have the same entry. 
551
 
        """
552
 
        # XXX: Need to think more here about when the user has
553
 
        # made a specific decision on a particular value -- c.f.
554
 
        # mark-merge.  
555
 
 
556
 
        # iter_entries does not visit the ROOT_ID node so we need to call
557
 
        # self._emit_progress_update once by hand.
558
 
        self._emit_progress_update()
559
 
        for path, ie in self.builder.new_inventory.iter_entries():
560
 
            self._emit_progress_update()
561
 
            self.builder.record_entry_contents(ie, self.parent_invs, 
562
 
                self.rev_id, path, self.work_tree)
563
 
            # describe the nature of the change that has occured relative to
564
 
            # the basis inventory.
565
 
            if (self.basis_inv.has_id(ie.file_id)):
566
 
                basis_ie = self.basis_inv[ie.file_id]
567
 
            else:
568
 
                basis_ie = None
569
 
            change = ie.describe_change(basis_ie, ie)
570
 
            if change in (InventoryEntry.RENAMED, 
571
 
                InventoryEntry.MODIFIED_AND_RENAMED):
572
 
                old_path = self.basis_inv.id2path(ie.file_id)
573
 
                self.reporter.renamed(change, old_path, path)
574
 
            else:
575
 
                self.reporter.snapshot_change(change, path)
576
 
 
577
541
    def _populate_new_inv(self):
578
542
        """Build revision inventory.
579
543
 
589
553
        # iter_entries does not visit the ROOT_ID node so we need to call
590
554
        # self._emit_progress_update once by hand.
591
555
        self._emit_progress_update()
 
556
        self._emit_progress_update()
592
557
        for path, new_ie in self.work_inv.iter_entries():
593
558
            self._emit_progress_update()
 
559
            self._emit_progress_update()
594
560
            file_id = new_ie.file_id
595
561
            mutter('check %s {%s}', path, new_ie.file_id)
596
562
            if (not self.specific_files or 
597
563
                is_inside_or_parent_of_any(self.specific_files, path)):
598
564
                    mutter('%s selected for commit', path)
599
 
                    self._select_entry(new_ie)
 
565
                    ie = new_ie.copy()
 
566
                    ie.revision = None
600
567
            else:
601
568
                mutter('%s not selected for commit', path)
602
 
                self._carry_entry(file_id)
 
569
                if self.basis_inv.has_id(file_id):
 
570
                    ie = self.basis_inv[file_id].copy()
 
571
                else:
 
572
                    # this entry is new and not being committed
 
573
                    continue
 
574
 
 
575
            self.builder.record_entry_contents(ie, self.parent_invs, 
 
576
                self.rev_id, path, self.work_tree)
 
577
            # describe the nature of the change that has occured relative to
 
578
            # the basis inventory.
 
579
            if (self.basis_inv.has_id(ie.file_id)):
 
580
                basis_ie = self.basis_inv[ie.file_id]
 
581
            else:
 
582
                basis_ie = None
 
583
            change = ie.describe_change(basis_ie, ie)
 
584
            if change in (InventoryEntry.RENAMED, 
 
585
                InventoryEntry.MODIFIED_AND_RENAMED):
 
586
                old_path = self.basis_inv.id2path(ie.file_id)
 
587
                self.reporter.renamed(change, old_path, path)
 
588
            else:
 
589
                self.reporter.snapshot_change(change, path)
603
590
 
604
591
    def _emit_progress_update(self):
605
592
        """Emit an update to the progress bar."""
606
593
        self.pb.update("Committing", self.pb_count, self.pb_total)
607
594
        self.pb_count += 1
608
595
 
609
 
    def _select_entry(self, new_ie):
610
 
        """Make new_ie be considered for committing."""
611
 
        ie = new_ie.copy()
612
 
        ie.revision = None
613
 
        self.builder.new_inventory.add(ie)
614
 
        return ie
615
 
 
616
 
    def _carry_entry(self, file_id):
617
 
        """Carry the file unchanged from the basis revision."""
618
 
        if self.basis_inv.has_id(file_id):
619
 
            self.builder.new_inventory.add(self.basis_inv[file_id].copy())
620
 
        else:
621
 
            # this entry is new and not being committed
622
 
            self.pb_total -= 1
623
 
 
624
596
    def _report_deletes(self):
625
597
        for path, ie in self.basis_inv.iter_entries():
626
598
            if ie.file_id not in self.builder.new_inventory: