~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/add.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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
 
19
21
import sys
20
22
import os
21
23
 
73
75
class AddWithSkipLargeAction(AddAction):
74
76
    """A class that can decide to skip a file if it's considered too large"""
75
77
 
76
 
    # default 20 MB
77
 
    _DEFAULT_MAX_FILE_SIZE = 20000000
78
 
    _optionName = 'add.maximum_file_size'
79
78
    _maxSize = None
80
79
 
81
80
    def skip_file(self, tree, path, kind, stat_value = None):
82
81
        if kind != 'file':
83
 
            return False            
 
82
            return False
 
83
        opt_name = 'add.maximum_file_size'
84
84
        if self._maxSize is None:
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)
 
85
            config = tree.get_config_stack()
 
86
            self._maxSize = config.get(opt_name)
89
87
        if stat_value is None:
90
88
            file_size = os.path.getsize(path);
91
89
        else:
93
91
        if self._maxSize > 0 and file_size > self._maxSize:
94
92
            ui.ui_factory.show_warning(gettext(
95
93
                "skipping {0} (larger than {1} of {2} bytes)").format(
96
 
                path, self._optionName,  self._maxSize))
 
94
                path, opt_name,  self._maxSize))
97
95
            return True
98
96
        return False
99
97
 
129
127
        we look for a file with the same name in that directory.
130
128
        Else, we look for an entry in the base tree with the same path.
131
129
        """
132
 
 
133
130
        if self.base_tree.has_id(parent_ie.file_id):
134
 
            base_parent_ie = self.base_tree.inventory[parent_ie.file_id]
135
 
            base_child_ie = base_parent_ie.children.get(
 
131
            base_path = osutils.pathjoin(
 
132
                self.base_tree.id2path(parent_ie.file_id),
136
133
                osutils.basename(path))
137
 
            if base_child_ie is not None:
138
 
                return (base_child_ie.file_id,
139
 
                        self.base_tree.id2path(base_child_ie.file_id))
 
134
            base_id = self.base_tree.path2id(base_path)
 
135
            if base_id is not None:
 
136
                return (base_id, base_path)
140
137
        full_base_path = osutils.pathjoin(self.base_path, path)
141
138
        # This may return None, but it is our last attempt
142
139
        return self.base_tree.path2id(full_base_path), full_base_path