~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mutabletree.py

  • Committer: Shannon Weyrick
  • Date: 2011-08-05 20:57:49 UTC
  • mto: This revision was merged to the branch mainline in revision 6086.
  • Revision ID: weyrick@mozek.us-20110805205749-kddqhz3vadaf1t03
Add support for skipping large files during add, based on configurable threshold (default 1M). Fixes bug #54624

Show diffs side-by-side

added added

removed removed

Lines of Context:
541
541
class _SmartAddHelper(object):
542
542
    """Helper for MutableTree.smart_add."""
543
543
 
 
544
    _DEFAULT_LARGE_FILE_THRESHOLD = 2<<20; # 1 MB
 
545
 
544
546
    def get_inventory_delta(self):
545
547
        return self._invdelta.values()
546
548
 
629
631
                yield (path, inv_path, this_ie, None)
630
632
            prev_dir = path
631
633
 
 
634
    def _large_file_threshold(self):
 
635
        """The largest size file we allow to be added, in bytes.
 
636
 
 
637
        :return: an integer. 0 means no limit.
 
638
        """
 
639
        config = self.tree.branch.get_config()
 
640
        val = config.get_user_option('large_file_threshold')
 
641
        if val is None:
 
642
            val = self._DEFAULT_LARGE_FILE_THRESHOLD
 
643
        else:
 
644
            try:
 
645
                val = int(val)
 
646
                if (val < 0):
 
647
                    val = self._DEFAULT_LARGE_FILE_THRESHOLD
 
648
            except ValueError, e:
 
649
                trace.warning('Invalid config value for'
 
650
                              ' "large_file_threshold"'
 
651
                              ' value %r is not an integer.'
 
652
                              % (val,))
 
653
                val = self._DEFAULT_LARGE_FILE_THRESHOLD
 
654
        return val
 
655
        
632
656
    def __init__(self, tree, action, conflicts_related=None):
633
657
        self.tree = tree
634
658
        if action is None:
688
712
 
689
713
        things_to_add = list(self._gather_dirs_to_add(user_dirs))
690
714
 
 
715
        large_threshold = self._large_file_threshold()
691
716
        illegalpath_re = re.compile(r'[\r\n]')
692
717
        for directory, inv_path, this_ie, parent_ie in things_to_add:
693
718
            # directory is tree-relative
701
726
            else:
702
727
                kind = this_ie.kind
703
728
 
 
729
            
 
730
            # if file size if greater than large_threshold, warn and skip
 
731
            if (kind == 'file') and (large_threshold > 0) and (
 
732
                os.path.getsize(abspath) > large_threshold):
 
733
                    trace.warning("skipping %s (larger than "
 
734
                    "large_file_threshold of %i bytes)",  
 
735
                    abspath, large_threshold)
 
736
                    continue
 
737
                
704
738
            if not InventoryEntry.versionable_kind(kind):
705
739
                trace.warning("skipping %s (can't add file of kind '%s')",
706
740
                              abspath, kind)