~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ignores.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-04-08 06:17:41 UTC
  • mfrom: (4797.33.16 apport)
  • Revision ID: pqm@pqm.ubuntu.com-20100408061741-m7vl6z97vu33riv7
(robertc) Make sure ExecutablePath and InterpreterPath are set in
        Apport. (Martin Pool, James Westby, lp:528114)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Lists of ignore files, etc."""
18
18
 
25
25
    globbing,
26
26
    )
27
27
 
 
28
from trace import warning
 
29
 
28
30
# This was the full ignore list for bzr 0.8
29
31
# please keep these sorted (in C locale order) to aid merging
30
32
OLD_DEFAULTS = [
100
102
]
101
103
 
102
104
 
 
105
 
103
106
def parse_ignore_file(f):
104
 
    """Read in all of the lines in the file and turn it into an ignore list"""
 
107
    """Read in all of the lines in the file and turn it into an ignore list
 
108
    
 
109
    Continue in the case of utf8 decoding errors, and emit a warning when 
 
110
    such and error is found. Optimise for the common case -- no decoding 
 
111
    errors.
 
112
    """
105
113
    ignored = set()
106
 
    for line in f.read().decode('utf8').split('\n'):
 
114
    ignore_file = f.read()
 
115
    try:
 
116
        # Try and parse whole ignore file at once.
 
117
        unicode_lines = ignore_file.decode('utf8').split('\n')
 
118
    except UnicodeDecodeError:
 
119
        # Otherwise go though line by line and pick out the 'good'
 
120
        # decodable lines
 
121
        lines = ignore_file.split('\n')
 
122
        unicode_lines = []    
 
123
        for line_number, line in enumerate(lines):
 
124
            try:
 
125
                unicode_lines.append(line.decode('utf-8'))
 
126
            except UnicodeDecodeError:
 
127
                # report error about line (idx+1)
 
128
                warning('.bzrignore: On Line #%d, malformed utf8 character. '
 
129
                        'Ignoring line.' % (line_number+1))
 
130
    
 
131
    # Append each line to ignore list if it's not a comment line
 
132
    for line in unicode_lines:
107
133
        line = line.rstrip('\r\n')
108
134
        if not line or line.startswith('#'):
109
135
            continue
213
239
    """Retrieve a list of ignores from the ignore file in a tree.
214
240
 
215
241
    :param tree: Tree to retrieve the ignore list from.
216
 
    :return: 
 
242
    :return:
217
243
    """
218
244
    ifn = tree.abspath(bzrlib.IGNORE_FILENAME)
219
245
    if tree.has_filename(ifn):