~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ignores.py

  • Committer: Aaron Bentley
  • Date: 2007-02-06 14:52:16 UTC
  • mfrom: (2266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2268.
  • Revision ID: abentley@panoramicfeedback.com-20070206145216-fcpi8o3ufvuzwbp9
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import errno
20
20
 
21
 
import bzrlib
22
 
from bzrlib import (
23
 
    atomicfile,
24
 
    config,
25
 
    globbing,
26
 
    )
 
21
from bzrlib import config
27
22
 
28
23
# This was the full ignore list for bzr 0.8
29
24
# please keep these sorted (in C locale order) to aid merging
104
99
    """Read in all of the lines in the file and turn it into an ignore list"""
105
100
    ignored = set()
106
101
    for line in f.read().decode('utf8').split('\n'):
107
 
        line = line.rstrip('\r\n')
 
102
        line = line.rstrip('/\r\n')
108
103
        if not line or line.startswith('#'):
109
104
            continue
110
 
        ignored.add(globbing.normalize_pattern(line))
 
105
        ignored.add(line)
111
106
    return ignored
112
107
 
113
108
 
168
163
    ignored = get_user_ignores()
169
164
    to_add = []
170
165
    for ignore in new_ignores:
171
 
        ignore = globbing.normalize_pattern(ignore)
 
166
        ignore = ignore.rstrip('/')
172
167
        if ignore not in ignored:
173
168
            ignored.add(ignore)
174
169
            to_add.append(ignore)
207
202
def get_runtime_ignores():
208
203
    """Get the current set of runtime ignores."""
209
204
    return _runtime_ignores
210
 
 
211
 
 
212
 
def tree_ignores_add_patterns(tree, name_pattern_list):
213
 
    """Retrieve a list of ignores from the ignore file in a tree.
214
 
 
215
 
    :param tree: Tree to retrieve the ignore list from.
216
 
    :return: 
217
 
    """
218
 
    ifn = tree.abspath(bzrlib.IGNORE_FILENAME)
219
 
    if tree.has_filename(ifn):
220
 
        f = open(ifn, 'rt')
221
 
        try:
222
 
            igns = f.read().decode('utf-8')
223
 
        finally:
224
 
            f.close()
225
 
    else:
226
 
        igns = ""
227
 
 
228
 
    # TODO: If the file already uses crlf-style termination, maybe
229
 
    # we should use that for the newly added lines?
230
 
 
231
 
    if igns and igns[-1] != '\n':
232
 
        igns += '\n'
233
 
    for name_pattern in name_pattern_list:
234
 
        igns += name_pattern + '\n'
235
 
 
236
 
    f = atomicfile.AtomicFile(ifn, 'wb')
237
 
    try:
238
 
        f.write(igns.encode('utf-8'))
239
 
        f.commit()
240
 
    finally:
241
 
        f.close()
242
 
 
243
 
    if not tree.path2id('.bzrignore'):
244
 
        tree.add(['.bzrignore'])