/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/add.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

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
 
24
22
from . import (
 
23
    errors,
25
24
    osutils,
26
25
    ui,
27
26
    )
28
27
from .i18n import gettext
29
28
 
 
29
 
30
30
class AddAction(object):
31
31
    """A class which defines what action to take when adding a file."""
32
32
 
57
57
            self._to_file.write('adding %s\n' % _quote(path))
58
58
        return None
59
59
 
60
 
    def skip_file(self, tree, path, kind, stat_value = None):
 
60
    def skip_file(self, tree, path, kind, stat_value=None):
61
61
        """Test whether the given file should be skipped or not.
62
 
        
 
62
 
63
63
        The default action never skips. Note this is only called during
64
64
        recursive adds
65
 
        
 
65
 
66
66
        :param tree: The tree we are working in
67
67
        :param path: The path being added
68
68
        :param kind: The kind of object being added.
77
77
 
78
78
    _maxSize = None
79
79
 
80
 
    def skip_file(self, tree, path, kind, stat_value = None):
 
80
    def skip_file(self, tree, path, kind, stat_value=None):
81
81
        if kind != 'file':
82
82
            return False
83
83
        opt_name = 'add.maximum_file_size'
85
85
            config = tree.get_config_stack()
86
86
            self._maxSize = config.get(opt_name)
87
87
        if stat_value is None:
88
 
            file_size = os.path.getsize(path);
 
88
            file_size = os.path.getsize(path)
89
89
        else:
90
 
            file_size = stat_value.st_size;
 
90
            file_size = stat_value.st_size
91
91
        if self._maxSize > 0 and file_size > self._maxSize:
92
92
            ui.ui_factory.show_warning(gettext(
93
93
                "skipping {0} (larger than {1} of {2} bytes)").format(
94
 
                path, opt_name,  self._maxSize))
 
94
                path, opt_name, self._maxSize))
95
95
            return True
96
96
        return False
97
97
 
117
117
            # we aren't doing anything special, so let the default
118
118
            # reporter happen
119
119
            file_id = super(AddFromBaseAction, self).__call__(
120
 
                        inv, parent_ie, path, kind)
 
120
                inv, parent_ie, path, kind)
121
121
        return file_id
122
122
 
123
123
    def _get_base_file_id(self, path, parent_ie):
127
127
        we look for a file with the same name in that directory.
128
128
        Else, we look for an entry in the base tree with the same path.
129
129
        """
130
 
        if self.base_tree.has_id(parent_ie.file_id):
131
 
            base_path = osutils.pathjoin(
132
 
                self.base_tree.id2path(parent_ie.file_id),
133
 
                osutils.basename(path))
 
130
        try:
 
131
            parent_path = self.base_tree.id2path(parent_ie.file_id)
 
132
        except errors.NoSuchId:
 
133
            pass
 
134
        else:
 
135
            base_path = osutils.pathjoin(parent_path, osutils.basename(path))
134
136
            base_id = self.base_tree.path2id(base_path)
135
137
            if base_id is not None:
136
138
                return (base_id, base_path)