~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mutabletree.py

  • Committer: Ian Clatworthy
  • Date: 2009-09-09 00:49:50 UTC
  • mto: (4634.37.2 prepare-2.0)
  • mto: This revision was merged to the branch mainline in revision 4689.
  • Revision ID: ian.clatworthy@canonical.com-20090909004950-43z4zdicb5u91iet
tweak quick reference naming to make it consistent with other PDFs

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib.lazy_import import lazy_import
24
24
lazy_import(globals(), """
25
25
import os
26
 
import re
27
26
 
28
27
from bzrlib import (
29
28
    add,
30
29
    bzrdir,
 
30
    hooks,
 
31
    symbol_versioning,
 
32
    )
 
33
from bzrlib.osutils import dirname
 
34
from bzrlib.revisiontree import RevisionTree
 
35
from bzrlib.trace import mutter, warning
 
36
""")
 
37
 
 
38
from bzrlib import (
31
39
    errors,
32
 
    hooks,
33
40
    osutils,
34
 
    revisiontree,
35
 
    symbol_versioning,
36
 
    trace,
37
41
    tree,
38
42
    )
39
 
""")
40
 
 
41
43
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
44
from bzrlib.osutils import splitpath
42
45
 
43
46
 
44
47
def needs_tree_write_lock(unbound):
126
129
            # generic constraint checks:
127
130
            if self.is_control_filename(f):
128
131
                raise errors.ForbiddenControlFileError(filename=f)
129
 
            fp = osutils.splitpath(f)
 
132
            fp = splitpath(f)
130
133
        # fill out file kinds for all files [not needed when we stop
131
134
        # caring about the instantaneous file kind within a uncommmitted tree
132
135
        #
233
236
        raise NotImplementedError(self._gather_kinds)
234
237
 
235
238
    @needs_read_lock
236
 
    def has_changes(self, _from_tree=None):
237
 
        """Quickly check that the tree contains at least one commitable change.
238
 
 
239
 
        :param _from_tree: tree to compare against to find changes (default to
240
 
            the basis tree and is intended to be used by tests).
 
239
    def has_changes(self, from_tree):
 
240
        """Quickly check that the tree contains at least one change.
241
241
 
242
242
        :return: True if a change is found. False otherwise
243
243
        """
244
 
        # Check pending merges
245
 
        if len(self.get_parent_ids()) > 1:
246
 
            return True
247
 
        if _from_tree is None:
248
 
            _from_tree = self.basis_tree()
249
 
        changes = self.iter_changes(_from_tree)
 
244
        changes = self.iter_changes(from_tree)
250
245
        try:
251
246
            change = changes.next()
252
247
            # Exclude root (talk about black magic... --vila 20090629)
380
375
 
381
376
        if not file_list:
382
377
            # no paths supplied: add the entire tree.
383
 
            # FIXME: this assumes we are running in a working tree subdir :-/
384
 
            # -- vila 20100208
385
378
            file_list = [u'.']
386
379
        # mutter("smart add of %r")
387
380
        inv = self.inventory
389
382
        ignored = {}
390
383
        dirs_to_add = []
391
384
        user_dirs = set()
392
 
        conflicts_related = set()
393
 
        # Not all mutable trees can have conflicts
394
 
        if getattr(self, 'conflicts', None) is not None:
395
 
            # Collect all related files without checking whether they exist or
396
 
            # are versioned. It's cheaper to do that once for all conflicts
397
 
            # than trying to find the relevant conflict for each added file.
398
 
            for c in self.conflicts():
399
 
                conflicts_related.update(c.associated_filenames())
400
385
 
401
386
        # validate user file paths and convert all paths to tree
402
387
        # relative : it's cheaper to make a tree relative path an abspath
404
389
        # perform the canonicalization in bulk.
405
390
        for filepath in osutils.canonical_relpaths(self.basedir, file_list):
406
391
            rf = _FastPath(filepath)
407
 
            # validate user parameters. Our recursive code avoids adding new
408
 
            # files that need such validation
 
392
            # validate user parameters. Our recursive code avoids adding new files
 
393
            # that need such validation
409
394
            if self.is_control_filename(rf.raw_path):
410
395
                raise errors.ForbiddenControlFileError(filename=rf.raw_path)
411
396
 
417
402
            else:
418
403
                if not InventoryEntry.versionable_kind(kind):
419
404
                    raise errors.BadFileKindError(filename=abspath, kind=kind)
420
 
            # ensure the named path is added, so that ignore rules in the later
421
 
            # directory walk dont skip it.
422
 
            # we dont have a parent ie known yet.: use the relatively slower
423
 
            # inventory probing method
 
405
            # ensure the named path is added, so that ignore rules in the later directory
 
406
            # walk dont skip it.
 
407
            # we dont have a parent ie known yet.: use the relatively slower inventory
 
408
            # probing method
424
409
            versioned = inv.has_filename(rf.raw_path)
425
410
            if versioned:
426
411
                continue
442
427
                dirs_to_add.append((path, None))
443
428
            prev_dir = path.raw_path
444
429
 
445
 
        illegalpath_re = re.compile(r'[\r\n]')
446
430
        # dirs_to_add is initialised to a list of directories, but as we scan
447
431
        # directories we append files to it.
448
432
        # XXX: We should determine kind of files when we scan them rather than
457
441
            kind = osutils.file_kind(abspath)
458
442
 
459
443
            if not InventoryEntry.versionable_kind(kind):
460
 
                trace.warning("skipping %s (can't add file of kind '%s')",
461
 
                              abspath, kind)
462
 
                continue
463
 
            if illegalpath_re.search(directory.raw_path):
464
 
                trace.warning("skipping %r (contains \\n or \\r)" % abspath)
465
 
                continue
466
 
            if directory.raw_path in conflicts_related:
467
 
                # If the file looks like one generated for a conflict, don't
468
 
                # add it.
469
 
                trace.warning(
470
 
                    'skipping %s (generated to help resolve conflicts)',
471
 
                    abspath)
 
444
                warning("skipping %s (can't add file of kind '%s')", abspath, kind)
472
445
                continue
473
446
 
474
447
            if parent_ie is not None:
497
470
                pass
498
471
                # mutter("%r is already versioned", abspath)
499
472
            elif sub_tree:
500
 
                # XXX: This is wrong; people *might* reasonably be trying to
501
 
                # add subtrees as subtrees.  This should probably only be done
502
 
                # in formats which can represent subtrees, and even then
503
 
                # perhaps only when the user asked to add subtrees.  At the
504
 
                # moment you can add them specially through 'join --reference',
505
 
                # which is perhaps reasonable: adding a new reference is a
506
 
                # special operation and can have a special behaviour.  mbp
507
 
                # 20070306
508
 
                trace.mutter("%r is a nested bzr tree", abspath)
 
473
                # XXX: This is wrong; people *might* reasonably be trying to add
 
474
                # subtrees as subtrees.  This should probably only be done in formats
 
475
                # which can represent subtrees, and even then perhaps only when
 
476
                # the user asked to add subtrees.  At the moment you can add them
 
477
                # specially through 'join --reference', which is perhaps
 
478
                # reasonable: adding a new reference is a special operation and
 
479
                # can have a special behaviour.  mbp 20070306
 
480
                mutter("%r is a nested bzr tree", abspath)
509
481
            else:
510
482
                _add_one(self, inv, parent_ie, directory, kind, action)
511
483
                added.append(directory.raw_path)
518
490
                    # without the parent ie, use the relatively slower inventory
519
491
                    # probing method
520
492
                    this_id = inv.path2id(
521
 
                        self._fix_case_of_inventory_path(directory.raw_path))
 
493
                            self._fix_case_of_inventory_path(directory.raw_path))
522
494
                    if this_id is None:
523
495
                        this_ie = None
524
496
                    else:
533
505
                    # faster - its impossible for a non root dir to have a
534
506
                    # control file.
535
507
                    if self.is_control_filename(subp):
536
 
                        trace.mutter("skip control directory %r", subp)
 
508
                        mutter("skip control directory %r", subp)
537
509
                    elif subf in this_ie.children:
538
510
                        # recurse into this already versioned subdir.
539
511
                        dirs_to_add.append((_FastPath(subp, subf), this_ie))
595
567
        inventory = basis.inventory._get_mutable_inventory()
596
568
        basis.unlock()
597
569
        inventory.apply_delta(delta)
598
 
        rev_tree = revisiontree.RevisionTree(self.branch.repository,
599
 
                                             inventory, new_revid)
 
570
        rev_tree = RevisionTree(self.branch.repository, inventory, new_revid)
600
571
        self.set_parent_trees([(new_revid, rev_tree)])
601
572
 
602
573
 
685
656
        # there are a limited number of dirs we can be nested under, it should
686
657
        # generally find it very fast and not recurse after that.
687
658
        added = _add_one_and_parent(tree, inv, None,
688
 
            _FastPath(osutils.dirname(path.raw_path)), 'directory', action)
689
 
        parent_id = inv.path2id(osutils.dirname(path.raw_path))
 
659
            _FastPath(dirname(path.raw_path)), 'directory', action)
 
660
        parent_id = inv.path2id(dirname(path.raw_path))
690
661
        parent_ie = inv[parent_id]
691
662
    _add_one(tree, inv, parent_ie, path, kind, action)
692
663
    return added + [path.raw_path]