~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

Show diffs side-by-side

added added

removed removed

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