~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/add.py

  • Committer: Jelmer Vernooij
  • Date: 2011-08-22 10:53:21 UTC
  • mto: This revision was merged to the branch mainline in revision 6094.
  • Revision ID: jelmer@samba.org-20110822105321-bxzxabfs6pl7lc43
Remove tags pointed at by uncommitted revisions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Helper functions for adding files to working trees."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
import sys
22
20
import os
23
21
 
25
23
    osutils,
26
24
    ui, 
27
25
    )
28
 
from bzrlib.i18n import gettext
 
26
 
29
27
 
30
28
class AddAction(object):
31
29
    """A class which defines what action to take when adding a file."""
75
73
class AddWithSkipLargeAction(AddAction):
76
74
    """A class that can decide to skip a file if it's considered too large"""
77
75
 
 
76
    # default 20 MB
 
77
    _DEFAULT_MAX_FILE_SIZE = 20000000
 
78
    _optionName = 'add.maximum_file_size'
78
79
    _maxSize = None
79
80
 
80
81
    def skip_file(self, tree, path, kind, stat_value = None):
81
82
        if kind != 'file':
82
 
            return False
83
 
        opt_name = 'add.maximum_file_size'
 
83
            return False            
84
84
        if self._maxSize is None:
85
 
            config = tree.get_config_stack()
86
 
            self._maxSize = config.get(opt_name)
 
85
            config = tree.branch.get_config()
 
86
            self._maxSize = config.get_user_option_as_int_from_SI(
 
87
                self._optionName,  
 
88
                self._DEFAULT_MAX_FILE_SIZE)
87
89
        if stat_value is None:
88
90
            file_size = os.path.getsize(path);
89
91
        else:
90
92
            file_size = stat_value.st_size;
91
93
        if self._maxSize > 0 and file_size > self._maxSize:
92
 
            ui.ui_factory.show_warning(gettext(
93
 
                "skipping {0} (larger than {1} of {2} bytes)").format(
94
 
                path, opt_name,  self._maxSize))
 
94
            ui.ui_factory.show_warning(
 
95
                "skipping %s (larger than %s of %d bytes)" % 
 
96
                (path, self._optionName,  self._maxSize))
95
97
            return True
96
98
        return False
97
99
 
129
131
        """
130
132
 
131
133
        if self.base_tree.has_id(parent_ie.file_id):
132
 
            # FIXME: Handle nested trees
133
 
            base_parent_ie = self.base_tree.root_inventory[parent_ie.file_id]
 
134
            base_parent_ie = self.base_tree.inventory[parent_ie.file_id]
134
135
            base_child_ie = base_parent_ie.children.get(
135
136
                osutils.basename(path))
136
137
            if base_child_ie is not None: