~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.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:
1976
1976
        ]
1977
1977
    
1978
1978
    def run(self, name_pattern_list=None, old_default_rules=None):
1979
 
        from bzrlib.atomicfile import AtomicFile
 
1979
        from bzrlib import ignores
1980
1980
        if old_default_rules is not None:
1981
1981
            # dump the rules and exit
1982
1982
            for pattern in ignores.OLD_DEFAULTS:
1993
1993
                raise errors.BzrCommandError(
1994
1994
                    "NAME_PATTERN should not be an absolute path")
1995
1995
        tree, relpath = WorkingTree.open_containing(u'.')
1996
 
        ifn = tree.abspath('.bzrignore')
1997
 
        if os.path.exists(ifn):
1998
 
            f = open(ifn, 'rt')
1999
 
            try:
2000
 
                igns = f.read().decode('utf-8')
2001
 
            finally:
2002
 
                f.close()
2003
 
        else:
2004
 
            igns = ''
2005
 
 
2006
 
        # TODO: If the file already uses crlf-style termination, maybe
2007
 
        # we should use that for the newly added lines?
2008
 
 
2009
 
        if igns and igns[-1] != '\n':
2010
 
            igns += '\n'
2011
 
        for name_pattern in name_pattern_list:
2012
 
            igns += name_pattern + '\n'
2013
 
 
2014
 
        f = AtomicFile(ifn, 'wb')
2015
 
        try:
2016
 
            f.write(igns.encode('utf-8'))
2017
 
            f.commit()
2018
 
        finally:
2019
 
            f.close()
2020
 
 
2021
 
        if not tree.path2id('.bzrignore'):
2022
 
            tree.add(['.bzrignore'])
2023
 
 
 
1996
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2024
1997
        ignored = globbing.Globster(name_pattern_list)
2025
1998
        matches = []
2026
1999
        tree.lock_read()