~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ignores.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-26 06:24:01 UTC
  • mto: This revision was merged to the branch mainline in revision 2376.
  • Revision ID: andrew.bennetts@canonical.com-20070326062401-k3nbefzje5332jaf
Deal with review comments from Robert:

  * Add my name to the NEWS file
  * Move the test case to a new module in branch_implementations
  * Remove revision_history cruft from identitymap and test_identitymap
  * Improve some docstrings

Also, this fixes a bug where revision_history was not returning a copy of the
cached data, allowing the cache to be corrupted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import errno
20
20
 
21
 
import bzrlib
22
21
from bzrlib import (
23
 
    atomicfile,
24
22
    config,
25
23
    globbing,
26
24
    )
207
205
def get_runtime_ignores():
208
206
    """Get the current set of runtime ignores."""
209
207
    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'])