~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
# The newly committed revision is going to have a shape corresponding
60
60
    debug,
61
61
    errors,
62
62
    revision,
63
 
    trace,
64
63
    tree,
65
 
    xml_serializer,
66
64
    )
67
65
from bzrlib.branch import Branch
68
66
import bzrlib.config
70
68
                           ConflictsInTree,
71
69
                           StrictCommitFailed
72
70
                           )
73
 
from bzrlib.osutils import (get_user_encoding,
74
 
                            kind_marker, isdir,isfile, is_inside_any,
 
71
from bzrlib.osutils import (kind_marker, isdir,isfile, is_inside_any,
75
72
                            is_inside_or_parent_of_any,
76
73
                            minimum_path_selection,
77
74
                            quotefn, sha_file, split_lines,
79
76
                            )
80
77
from bzrlib.testament import Testament
81
78
from bzrlib.trace import mutter, note, warning, is_quiet
82
 
from bzrlib.inventory import Inventory, InventoryEntry, make_entry
 
79
from bzrlib.xml5 import serializer_v5
 
80
from bzrlib.inventory import InventoryEntry, make_entry
83
81
from bzrlib import symbol_versioning
84
82
from bzrlib.symbol_versioning import (deprecated_passed,
85
83
        deprecated_function,
105
103
    def completed(self, revno, rev_id):
106
104
        pass
107
105
 
108
 
    def deleted(self, path):
 
106
    def deleted(self, file_id):
 
107
        pass
 
108
 
 
109
    def escaped(self, escape_count, message):
109
110
        pass
110
111
 
111
112
    def missing(self, path):
128
129
        note(format, *args)
129
130
 
130
131
    def snapshot_change(self, change, path):
131
 
        if path == '' and change in ('added', 'modified'):
 
132
        if change == 'unchanged':
 
133
            return
 
134
        if change == 'added' and path == '':
132
135
            return
133
136
        self._note("%s %s", change, path)
134
137
 
147
150
    def completed(self, revno, rev_id):
148
151
        self._note('Committed revision %d.', revno)
149
152
 
150
 
    def deleted(self, path):
151
 
        self._note('deleted %s', path)
 
153
    def deleted(self, file_id):
 
154
        self._note('deleted %s', file_id)
 
155
 
 
156
    def escaped(self, escape_count, message):
 
157
        self._note("replaced %d control characters in message", escape_count)
152
158
 
153
159
    def missing(self, path):
154
160
        self._note('missing %s', path)
199
205
               config=None,
200
206
               message_callback=None,
201
207
               recursive='down',
202
 
               exclude=None,
203
 
               possible_master_transports=None):
 
208
               exclude=None):
204
209
        """Commit working copy as a new revision.
205
210
 
206
211
        :param message: the commit message (it or message_callback is required)
207
 
        :param message_callback: A callback: message = message_callback(cmt_obj)
208
212
 
209
213
        :param timestamp: if not None, seconds-since-epoch for a
210
214
            postdated/predated commit.
231
235
            pending changes of any sort during this commit.
232
236
        :param exclude: None or a list of relative paths to exclude from the
233
237
            commit. Pending changes to excluded files will be ignored by the
234
 
            commit.
 
238
            commit. 
235
239
        """
236
240
        mutter('preparing to commit')
237
241
 
246
250
        if message_callback is None:
247
251
            if message is not None:
248
252
                if isinstance(message, str):
249
 
                    message = message.decode(get_user_encoding())
 
253
                    message = message.decode(bzrlib.user_encoding)
250
254
                message_callback = lambda x: message
251
255
            else:
252
256
                raise BzrError("The message or message_callback keyword"
253
257
                               " parameter is required for commit().")
254
258
 
255
259
        self.bound_branch = None
 
260
        self.any_entries_changed = False
256
261
        self.any_entries_deleted = False
257
262
        if exclude is not None:
258
263
            self.exclude = sorted(
269
274
                minimum_path_selection(specific_files))
270
275
        else:
271
276
            self.specific_files = None
272
 
            
 
277
        self.specific_file_ids = None
273
278
        self.allow_pointless = allow_pointless
274
279
        self.revprops = revprops
275
280
        self.message_callback = message_callback
278
283
        self.committer = committer
279
284
        self.strict = strict
280
285
        self.verbose = verbose
 
286
        # accumulates an inventory delta to the basis entry, so we can make
 
287
        # just the necessary updates to the workingtree's cached basis.
 
288
        self._basis_delta = []
281
289
 
282
290
        self.work_tree.lock_write()
283
 
        self.parents = self.work_tree.get_parent_ids()
284
 
        # We can use record_iter_changes IFF iter_changes is compatible with
285
 
        # the command line parameters, and the repository has fast delta
286
 
        # generation. See bug 347649.
287
 
        self.use_record_iter_changes = (
288
 
            not self.specific_files and
289
 
            not self.exclude and 
290
 
            not self.branch.repository._format.supports_tree_reference and
291
 
            (self.branch.repository._format.fast_deltas or
292
 
             len(self.parents) < 2))
293
291
        self.pb = bzrlib.ui.ui_factory.nested_progress_bar()
294
292
        self.basis_revid = self.work_tree.last_revision()
295
293
        self.basis_tree = self.work_tree.basis_tree()
300
298
                raise ConflictsInTree
301
299
 
302
300
            # Setup the bound branch variables as needed.
303
 
            self._check_bound_branch(possible_master_transports)
 
301
            self._check_bound_branch()
304
302
 
305
303
            # Check that the working tree is up to date
306
304
            old_revno, new_revno = self._check_out_of_date_tree()
313
311
            if self.config is None:
314
312
                self.config = self.branch.get_config()
315
313
 
316
 
            self._set_specific_file_ids()
 
314
            # If provided, ensure the specified files are versioned
 
315
            if self.specific_files is not None:
 
316
                # Note: This routine is being called because it raises
 
317
                # PathNotVersionedError as a side effect of finding the IDs. We
 
318
                # later use the ids we found as input to the working tree
 
319
                # inventory iterator, so we only consider those ids rather than
 
320
                # examining the whole tree again.
 
321
                # XXX: Dont we have filter_unversioned to do this more
 
322
                # cheaply?
 
323
                self.specific_file_ids = tree.find_ids_across_trees(
 
324
                    specific_files, [self.basis_tree, self.work_tree])
317
325
 
318
326
            # Setup the progress bar. As the number of files that need to be
319
327
            # committed in unknown, progress is reported as stages.
330
338
            self.pb.show_count = True
331
339
            self.pb.show_bar = True
332
340
 
 
341
            self.basis_inv = self.basis_tree.inventory
333
342
            self._gather_parents()
334
343
            # After a merge, a selected file commit is not supported.
335
344
            # See 'bzr help merge' for an explanation as to why.
340
349
                raise errors.CannotCommitSelectedFileMerge(self.exclude)
341
350
 
342
351
            # Collect the changes
343
 
            self._set_progress_stage("Collecting changes", counter=True)
 
352
            self._set_progress_stage("Collecting changes",
 
353
                    entries_title="Directory")
344
354
            self.builder = self.branch.get_commit_builder(self.parents,
345
355
                self.config, timestamp, timezone, committer, revprops, rev_id)
346
 
 
 
356
            
347
357
            try:
348
 
                self.builder.will_record_deletes()
349
358
                # find the location being committed to
350
359
                if self.bound_branch:
351
360
                    master_location = self.master_branch.base
356
365
                self.reporter.started(new_revno, self.rev_id, master_location)
357
366
 
358
367
                self._update_builder_with_changes()
 
368
                self._report_and_accumulate_deletes()
359
369
                self._check_pointless()
360
370
 
361
371
                # TODO: Now the new inventory is known, check for conflicts.
368
378
                # Prompt the user for a commit message if none provided
369
379
                message = message_callback(self)
370
380
                self.message = message
 
381
                self._escape_commit_message()
371
382
 
372
383
                # Add revision data to the local branch
373
384
                self.rev_id = self.builder.commit(self.message)
374
385
 
375
 
            except Exception, e:
376
 
                mutter("aborting commit write group because of exception:")
377
 
                trace.log_exception_quietly()
378
 
                note("aborting commit write group: %r" % (e,))
 
386
            except:
379
387
                self.builder.abort()
380
388
                raise
381
389
 
384
392
            # Upload revision data to the master.
385
393
            # this will propagate merged revisions too if needed.
386
394
            if self.bound_branch:
387
 
                self._set_progress_stage("Uploading data to master branch")
 
395
                if not self.master_branch.repository.has_same_location(
 
396
                        self.branch.repository):
 
397
                    self._set_progress_stage("Uploading data to master branch")
 
398
                    self.master_branch.repository.fetch(self.branch.repository,
 
399
                        revision_id=self.rev_id)
 
400
                # now the master has the revision data
388
401
                # 'commit' to the master first so a timeout here causes the
389
402
                # local branch to be out of date
390
 
                self.master_branch.import_last_revision_info(
391
 
                    self.branch.repository, new_revno, self.rev_id)
 
403
                self.master_branch.set_last_revision_info(new_revno,
 
404
                                                          self.rev_id)
392
405
 
393
406
            # and now do the commit locally.
394
407
            self.branch.set_last_revision_info(new_revno, self.rev_id)
395
408
 
396
 
            # Make the working tree be up to date with the branch. This
397
 
            # includes automatic changes scheduled to be made to the tree, such
398
 
            # as updating its basis and unversioning paths that were missing.
399
 
            self.work_tree.unversion(self.deleted_ids)
 
409
            # Make the working tree up to date with the branch
400
410
            self._set_progress_stage("Updating the working tree")
401
411
            self.work_tree.update_basis_by_delta(self.rev_id,
402
 
                 self.builder.get_basis_delta())
 
412
                 self._basis_delta)
403
413
            self.reporter.completed(new_revno, self.rev_id)
404
414
            self._process_post_hooks(old_revno, new_revno)
405
415
        finally:
418
428
        # A merge with no effect on files
419
429
        if len(self.parents) > 1:
420
430
            return
421
 
        # TODO: we could simplify this by using self.builder.basis_delta.
 
431
        # TODO: we could simplify this by using self._basis_delta.
422
432
 
423
433
        # The initial commit adds a root directory, but this in itself is not
424
434
        # a worthwhile commit.
425
435
        if (self.basis_revid == revision.NULL_REVISION and
426
 
            ((self.builder.new_inventory is not None and
427
 
             len(self.builder.new_inventory) == 1) or
428
 
            len(self.builder._basis_delta) == 1)):
 
436
            len(self.builder.new_inventory) == 1):
429
437
            raise PointlessCommit()
430
 
        if self.builder.any_changes():
 
438
        # If length == 1, then we only have the root entry. Which means
 
439
        # that there is no real difference (only the root could be different)
 
440
        # unless deletes occured, in which case the length is irrelevant.
 
441
        if (self.any_entries_deleted or 
 
442
            (len(self.builder.new_inventory) != 1 and
 
443
             self.any_entries_changed)):
431
444
            return
432
445
        raise PointlessCommit()
433
446
 
434
 
    def _check_bound_branch(self, possible_master_transports=None):
 
447
    def _check_bound_branch(self):
435
448
        """Check to see if the local branch is bound.
436
449
 
437
450
        If it is bound, then most of the commit will actually be
442
455
            raise errors.LocalRequiresBoundBranch()
443
456
 
444
457
        if not self.local:
445
 
            self.master_branch = self.branch.get_master_branch(
446
 
                possible_master_transports)
 
458
            self.master_branch = self.branch.get_master_branch()
447
459
 
448
460
        if not self.master_branch:
449
461
            # make this branch the reference branch for out of date checks.
460
472
        #       commits to the remote branch if they would fit.
461
473
        #       But for now, just require remote to be identical
462
474
        #       to local.
463
 
 
 
475
        
464
476
        # Make sure the local branch is identical to the master
465
477
        master_info = self.master_branch.last_revision_info()
466
478
        local_info = self.branch.last_revision_info()
523
535
    def _process_hooks(self, hook_name, old_revno, new_revno):
524
536
        if not Branch.hooks[hook_name]:
525
537
            return
526
 
 
 
538
        
527
539
        # new style commit hooks:
528
540
        if not self.bound_branch:
529
541
            hook_master = self.branch
538
550
            old_revid = self.parents[0]
539
551
        else:
540
552
            old_revid = bzrlib.revision.NULL_REVISION
541
 
 
 
553
        
542
554
        if hook_name == "pre_commit":
543
555
            future_tree = self.builder.revision_tree()
544
556
            tree_delta = future_tree.changes_from(self.basis_tree,
545
557
                                             include_root=True)
546
 
 
 
558
        
547
559
        for hook in Branch.hooks[hook_name]:
548
560
            # show the running hook in the progress bar. As hooks may
549
561
            # end up doing nothing (e.g. because they are not configured by
579
591
            # typically this will be useful enough.
580
592
            except Exception, e:
581
593
                found_exception = e
582
 
        if found_exception is not None:
 
594
        if found_exception is not None: 
583
595
            # don't do a plan raise, because the last exception may have been
584
596
            # trashed, e is our sure-to-work exception even though it loses the
585
597
            # full traceback. XXX: RBC 20060421 perhaps we could check the
586
 
            # exc_info and if its the same one do a plain raise otherwise
 
598
            # exc_info and if its the same one do a plain raise otherwise 
587
599
            # 'raise e' as we do now.
588
600
            raise e
589
601
 
599
611
        if self.master_locked:
600
612
            self.master_branch.unlock()
601
613
 
 
614
    def _escape_commit_message(self):
 
615
        """Replace xml-incompatible control characters."""
 
616
        # FIXME: RBC 20060419 this should be done by the revision
 
617
        # serialiser not by commit. Then we can also add an unescaper
 
618
        # in the deserializer and start roundtripping revision messages
 
619
        # precisely. See repository_implementations/test_repository.py
 
620
        
 
621
        # Python strings can include characters that can't be
 
622
        # represented in well-formed XML; escape characters that
 
623
        # aren't listed in the XML specification
 
624
        # (http://www.w3.org/TR/REC-xml/#NT-Char).
 
625
        self.message, escape_count = re.subn(
 
626
            u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]+',
 
627
            lambda match: match.group(0).encode('unicode_escape'),
 
628
            self.message)
 
629
        if escape_count:
 
630
            self.reporter.escaped(escape_count, self.message)
 
631
 
602
632
    def _gather_parents(self):
603
633
        """Record the parents of a merge for merge detection."""
604
 
        # TODO: Make sure that this list doesn't contain duplicate
 
634
        # TODO: Make sure that this list doesn't contain duplicate 
605
635
        # entries and the order is preserved when doing this.
606
 
        if self.use_record_iter_changes:
607
 
            return
608
 
        self.basis_inv = self.basis_tree.inventory
 
636
        self.parents = self.work_tree.get_parent_ids()
609
637
        self.parent_invs = [self.basis_inv]
610
638
        for revision in self.parents[1:]:
611
639
            if self.branch.repository.has_revision(revision):
618
646
    def _update_builder_with_changes(self):
619
647
        """Update the commit builder with the data about what has changed.
620
648
        """
 
649
        # Build the revision inventory.
 
650
        #
 
651
        # This starts by creating a new empty inventory. Depending on
 
652
        # which files are selected for commit, and what is present in the
 
653
        # current tree, the new inventory is populated. inventory entries 
 
654
        # which are candidates for modification have their revision set to
 
655
        # None; inventory entries that are carried over untouched have their
 
656
        # revision set to their prior value.
 
657
        #
 
658
        # ESEPARATIONOFCONCERNS: this function is diffing and using the diff
 
659
        # results to create a new inventory at the same time, which results
 
660
        # in bugs like #46635.  Any reason not to use/enhance Tree.changes_from?
 
661
        # ADHB 11-07-2006
 
662
 
621
663
        exclude = self.exclude
622
664
        specific_files = self.specific_files or []
623
665
        mutter("Selecting files for commit with filter %s", specific_files)
624
666
 
625
 
        self._check_strict()
626
 
        if self.use_record_iter_changes:
627
 
            iter_changes = self.work_tree.iter_changes(self.basis_tree)
628
 
            iter_changes = self._filter_iter_changes(iter_changes)
629
 
            for file_id, path, fs_hash in self.builder.record_iter_changes(
630
 
                self.work_tree, self.basis_revid, iter_changes):
631
 
                self.work_tree._observed_sha1(file_id, path, fs_hash)
632
 
        else:
633
 
            # Build the new inventory
634
 
            self._populate_from_inventory()
635
 
            self._record_unselected()
636
 
            self._report_and_accumulate_deletes()
637
 
 
638
 
    def _filter_iter_changes(self, iter_changes):
639
 
        """Process iter_changes.
640
 
 
641
 
        This method reports on the changes in iter_changes to the user, and 
642
 
        converts 'missing' entries in the iter_changes iterator to 'deleted'
643
 
        entries. 'missing' entries have their
644
 
 
645
 
        :param iter_changes: An iter_changes to process.
646
 
        :return: A generator of changes.
647
 
        """
648
 
        reporter = self.reporter
649
 
        report_changes = reporter.is_verbose()
650
 
        deleted_ids = []
651
 
        for change in iter_changes:
652
 
            if report_changes:
653
 
                old_path = change[1][0]
654
 
                new_path = change[1][1]
655
 
                versioned = change[3][1]
656
 
            kind = change[6][1]
657
 
            versioned = change[3][1]
658
 
            if kind is None and versioned:
659
 
                # 'missing' path
660
 
                if report_changes:
661
 
                    reporter.missing(new_path)
662
 
                deleted_ids.append(change[0])
663
 
                # Reset the new path (None) and new versioned flag (False)
664
 
                change = (change[0], (change[1][0], None), change[2],
665
 
                    (change[3][0], False)) + change[4:]
666
 
            elif kind == 'tree-reference':
667
 
                if self.recursive == 'down':
668
 
                    self._commit_nested_tree(change[0], change[1][1])
669
 
            if change[3][0] or change[3][1]:
670
 
                yield change
671
 
                if report_changes:
672
 
                    if new_path is None:
673
 
                        reporter.deleted(old_path)
674
 
                    elif old_path is None:
675
 
                        reporter.snapshot_change('added', new_path)
676
 
                    elif old_path != new_path:
677
 
                        reporter.renamed('renamed', old_path, new_path)
678
 
                    else:
679
 
                        if (new_path or 
680
 
                            self.work_tree.branch.repository._format.rich_root_data):
681
 
                            # Don't report on changes to '' in non rich root
682
 
                            # repositories.
683
 
                            reporter.snapshot_change('modified', new_path)
684
 
            self._next_progress_entry()
685
 
        # Unversion IDs that were found to be deleted
686
 
        self.deleted_ids = deleted_ids
687
 
 
688
 
    def _record_unselected(self):
 
667
        # Build the new inventory
 
668
        self._populate_from_inventory()
 
669
 
689
670
        # If specific files are selected, then all un-selected files must be
690
671
        # recorded in their previous state. For more details, see
691
672
        # https://lists.ubuntu.com/archives/bazaar/2007q3/028476.html.
692
 
        if self.specific_files or self.exclude:
693
 
            specific_files = self.specific_files or []
 
673
        if specific_files or exclude:
694
674
            for path, old_ie in self.basis_inv.iter_entries():
695
675
                if old_ie.file_id in self.builder.new_inventory:
696
676
                    # already added - skip.
697
677
                    continue
698
678
                if (is_inside_any(specific_files, path)
699
 
                    and not is_inside_any(self.exclude, path)):
 
679
                    and not is_inside_any(exclude, path)):
700
680
                    # was inside the selected path, and not excluded - if not
701
681
                    # present it has been deleted so skip.
702
682
                    continue
703
683
                # From here down it was either not selected, or was excluded:
 
684
                if old_ie.kind == 'directory':
 
685
                    self._next_progress_entry()
704
686
                # We preserve the entry unaltered.
705
687
                ie = old_ie.copy()
706
688
                # Note: specific file commits after a merge are currently
708
690
                # required after that changes.
709
691
                if len(self.parents) > 1:
710
692
                    ie.revision = None
711
 
                self.builder.record_entry_contents(ie, self.parent_invs, path,
712
 
                    self.basis_tree, None)
 
693
                delta, version_recorded = self.builder.record_entry_contents(
 
694
                    ie, self.parent_invs, path, self.basis_tree, None)
 
695
                if version_recorded:
 
696
                    self.any_entries_changed = True
 
697
                if delta: self._basis_delta.append(delta)
713
698
 
714
699
    def _report_and_accumulate_deletes(self):
715
 
        if (isinstance(self.basis_inv, Inventory)
716
 
            and isinstance(self.builder.new_inventory, Inventory)):
717
 
            # the older Inventory classes provide a _byid dict, and building a
718
 
            # set from the keys of this dict is substantially faster than even
719
 
            # getting a set of ids from the inventory
720
 
            #
721
 
            # <lifeless> set(dict) is roughly the same speed as
722
 
            # set(iter(dict)) and both are significantly slower than
723
 
            # set(dict.keys())
724
 
            deleted_ids = set(self.basis_inv._byid.keys()) - \
725
 
               set(self.builder.new_inventory._byid.keys())
726
 
        else:
727
 
            deleted_ids = set(self.basis_inv) - set(self.builder.new_inventory)
 
700
        # XXX: Could the list of deleted paths and ids be instead taken from
 
701
        # _populate_from_inventory?
 
702
        deleted_ids = set(self.basis_inv._byid.keys()) - \
 
703
            set(self.builder.new_inventory._byid.keys())
728
704
        if deleted_ids:
729
705
            self.any_entries_deleted = True
730
706
            deleted = [(self.basis_tree.id2path(file_id), file_id)
732
708
            deleted.sort()
733
709
            # XXX: this is not quite directory-order sorting
734
710
            for path, file_id in deleted:
735
 
                self.builder.record_delete(path, file_id)
 
711
                self._basis_delta.append((path, None, file_id, None))
736
712
                self.reporter.deleted(path)
737
713
 
738
 
    def _check_strict(self):
739
 
        # XXX: when we use iter_changes this would likely be faster if
740
 
        # iter_changes would check for us (even in the presence of
741
 
        # selected_files).
 
714
    def _populate_from_inventory(self):
 
715
        """Populate the CommitBuilder by walking the working tree inventory."""
742
716
        if self.strict:
743
717
            # raise an exception as soon as we find a single unknown.
744
718
            for unknown in self.work_tree.unknowns():
745
719
                raise StrictCommitFailed()
746
 
 
747
 
    def _populate_from_inventory(self):
748
 
        """Populate the CommitBuilder by walking the working tree inventory."""
749
 
        # Build the revision inventory.
750
 
        #
751
 
        # This starts by creating a new empty inventory. Depending on
752
 
        # which files are selected for commit, and what is present in the
753
 
        # current tree, the new inventory is populated. inventory entries
754
 
        # which are candidates for modification have their revision set to
755
 
        # None; inventory entries that are carried over untouched have their
756
 
        # revision set to their prior value.
757
 
        #
758
 
        # ESEPARATIONOFCONCERNS: this function is diffing and using the diff
759
 
        # results to create a new inventory at the same time, which results
760
 
        # in bugs like #46635.  Any reason not to use/enhance Tree.changes_from?
761
 
        # ADHB 11-07-2006
762
 
 
 
720
        
763
721
        specific_files = self.specific_files
764
722
        exclude = self.exclude
765
723
        report_changes = self.reporter.is_verbose()
779
737
            name = existing_ie.name
780
738
            parent_id = existing_ie.parent_id
781
739
            kind = existing_ie.kind
 
740
            if kind == 'directory':
 
741
                self._next_progress_entry()
782
742
            # Skip files that have been deleted from the working tree.
783
743
            # The deleted path ids are also recorded so they can be explicitly
784
744
            # unversioned later.
813
773
                    for segment in path_segments:
814
774
                        deleted_dict = deleted_dict.setdefault(segment, {})
815
775
                    self.reporter.missing(path)
816
 
                    self._next_progress_entry()
817
776
                    deleted_ids.append(file_id)
818
777
                    continue
819
778
            # TODO: have the builder do the nested commit just-in-time IF and
846
805
                content_summary)
847
806
 
848
807
        # Unversion IDs that were found to be deleted
849
 
        self.deleted_ids = deleted_ids
 
808
        self.work_tree.unversion(deleted_ids)
850
809
 
851
810
    def _commit_nested_tree(self, file_id, path):
852
811
        "Commit a nested tree."
854
813
        # FIXME: be more comprehensive here:
855
814
        # this works when both trees are in --trees repository,
856
815
        # but when both are bound to a different repository,
857
 
        # it fails; a better way of approaching this is to
 
816
        # it fails; a better way of approaching this is to 
858
817
        # finally implement the explicit-caches approach design
859
818
        # a while back - RBC 20070306.
860
819
        if sub_tree.branch.repository.has_same_location(
884
843
        else:
885
844
            ie = existing_ie.copy()
886
845
            ie.revision = None
887
 
        # For carried over entries we don't care about the fs hash - the repo
888
 
        # isn't generating a sha, so we're not saving computation time.
889
 
        _, _, fs_hash = self.builder.record_entry_contents(
890
 
            ie, self.parent_invs, path, self.work_tree, content_summary)
 
846
        delta, version_recorded = self.builder.record_entry_contents(ie,
 
847
            self.parent_invs, path, self.work_tree, content_summary)
 
848
        if delta:
 
849
            self._basis_delta.append(delta)
 
850
        if version_recorded:
 
851
            self.any_entries_changed = True
891
852
        if report_changes:
892
853
            self._report_change(ie, path)
893
 
        if fs_hash:
894
 
            self.work_tree._observed_sha1(ie.file_id, path, fs_hash)
895
854
        return ie
896
855
 
897
856
    def _report_change(self, ie, path):
905
864
        else:
906
865
            basis_ie = None
907
866
        change = ie.describe_change(basis_ie, ie)
908
 
        if change in (InventoryEntry.RENAMED,
 
867
        if change in (InventoryEntry.RENAMED, 
909
868
            InventoryEntry.MODIFIED_AND_RENAMED):
910
869
            old_path = self.basis_inv.id2path(ie.file_id)
911
870
            self.reporter.renamed(change, old_path, path)
912
 
            self._next_progress_entry()
913
871
        else:
914
 
            if change == 'unchanged':
915
 
                return
916
872
            self.reporter.snapshot_change(change, path)
917
 
            self._next_progress_entry()
918
873
 
919
 
    def _set_progress_stage(self, name, counter=False):
 
874
    def _set_progress_stage(self, name, entries_title=None):
920
875
        """Set the progress stage and emit an update to the progress bar."""
921
876
        self.pb_stage_name = name
922
877
        self.pb_stage_count += 1
923
 
        if counter:
 
878
        self.pb_entries_title = entries_title
 
879
        if entries_title is not None:
924
880
            self.pb_entries_count = 0
925
 
        else:
926
 
            self.pb_entries_count = None
 
881
            self.pb_entries_total = '?'
927
882
        self._emit_progress()
928
883
 
929
884
    def _next_progress_entry(self):
932
887
        self._emit_progress()
933
888
 
934
889
    def _emit_progress(self):
935
 
        if self.pb_entries_count is not None:
936
 
            text = "%s [%d] - Stage" % (self.pb_stage_name,
937
 
                self.pb_entries_count)
 
890
        if self.pb_entries_title:
 
891
            if self.pb_entries_total == '?':
 
892
                text = "%s [%s %d] - Stage" % (self.pb_stage_name,
 
893
                    self.pb_entries_title, self.pb_entries_count)
 
894
            else:
 
895
                text = "%s [%s %d/%s] - Stage" % (self.pb_stage_name,
 
896
                    self.pb_entries_title, self.pb_entries_count,
 
897
                    str(self.pb_entries_total))
938
898
        else:
939
 
            text = "%s - Stage" % (self.pb_stage_name, )
 
899
            text = "%s - Stage" % (self.pb_stage_name)
940
900
        self.pb.update(text, self.pb_stage_count, self.pb_stage_total)
941
901
 
942
 
    def _set_specific_file_ids(self):
943
 
        """populate self.specific_file_ids if we will use it."""
944
 
        if not self.use_record_iter_changes:
945
 
            # If provided, ensure the specified files are versioned
946
 
            if self.specific_files is not None:
947
 
                # Note: This routine is being called because it raises
948
 
                # PathNotVersionedError as a side effect of finding the IDs. We
949
 
                # later use the ids we found as input to the working tree
950
 
                # inventory iterator, so we only consider those ids rather than
951
 
                # examining the whole tree again.
952
 
                # XXX: Dont we have filter_unversioned to do this more
953
 
                # cheaply?
954
 
                self.specific_file_ids = tree.find_ids_across_trees(
955
 
                    self.specific_files, [self.basis_tree, self.work_tree])
956
 
            else:
957
 
                self.specific_file_ids = None