~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ignores.py

  • Committer: Jelmer Vernooij
  • Date: 2008-07-07 21:54:04 UTC
  • mto: This revision was merged to the branch mainline in revision 3533.
  • Revision ID: jelmer@samba.org-20080707215404-09t83ot6mv02jr6w
Move functionality to add ignores to the ignore file into a separate function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import errno
20
20
 
21
21
from bzrlib import (
 
22
    atomicfile,
22
23
    config,
23
24
    globbing,
24
25
    )
205
206
def get_runtime_ignores():
206
207
    """Get the current set of runtime ignores."""
207
208
    return _runtime_ignores
 
209
 
 
210
 
 
211
def tree_ignores_add_patterns(tree, name_pattern_list):
 
212
    """Retrieve a list of ignores from the ignore file in a tree.
 
213
 
 
214
    :param tree: Tree to retrieve the ignore list from.
 
215
    :return: 
 
216
    """
 
217
    ifn = tree.abspath('.bzrignore')
 
218
    if tree.has_filename(ifn):
 
219
        f = open(ifn, 'rt')
 
220
        try:
 
221
            igns = f.read().decode('utf-8')
 
222
        finally:
 
223
            f.close()
 
224
    else:
 
225
        igns = ""
 
226
 
 
227
    # TODO: If the file already uses crlf-style termination, maybe
 
228
    # we should use that for the newly added lines?
 
229
 
 
230
    if igns and igns[-1] != '\n':
 
231
        igns += '\n'
 
232
    for name_pattern in name_pattern_list:
 
233
        igns += name_pattern + '\n'
 
234
 
 
235
    f = atomicfile.AtomicFile(ifn, 'wb')
 
236
    try:
 
237
        f.write(igns.encode('utf-8'))
 
238
        f.commit()
 
239
    finally:
 
240
        f.close()
 
241
 
 
242
    if not tree.path2id('.bzrignore'):
 
243
        tree.add(['.bzrignore'])