~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ignores.py

  • Committer: Robert Collins
  • Date: 2009-07-07 04:32:13 UTC
  • mto: This revision was merged to the branch mainline in revision 4524.
  • Revision ID: robertc@robertcollins.net-20090707043213-4hjjhgr40iq7gk2d
More informative assertions in xml serialisation.

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