~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Martin Pool
  • Date: 2005-05-09 04:50:11 UTC
  • Revision ID: mbp@sourcefrog.net-20050509045010-7c32d7e3e8942540
- New AtomicFile class
- bzr ignore: Write out ignore list using AtomicFile to break hardlinks

Show diffs side-by-side

added added

removed removed

Lines of Context:
486
486
    takes_args = ['name_pattern']
487
487
    
488
488
    def run(self, name_pattern):
 
489
        from bzrlib.atomicfile import AtomicFile
 
490
        import codecs
 
491
 
489
492
        b = Branch('.')
490
493
 
491
 
        # XXX: This will fail if it's a hardlink; should use an AtomicFile class.
492
 
        f = open(b.abspath('.bzrignore'), 'at')
493
 
        f.write(name_pattern + '\n')
494
 
        f.close()
 
494
        # FIXME: probably doesn't handle non-ascii patterns
 
495
 
 
496
        if os.path.exists(b.controlfilename('.bzrignore')):
 
497
            f = b.controlfile('.bzrignore', 'rt')
 
498
            igns = f.read()
 
499
            f.close()
 
500
        else:
 
501
            igns = ''
 
502
 
 
503
        if igns and igns[-1] != '\n':
 
504
            igns += '\n'
 
505
        igns += name_pattern + '\n'
 
506
 
 
507
        f = AtomicFile(b.controlfilename('.bzrignore'), 'wt')
 
508
        f.write(igns)
 
509
        f.commit()
495
510
 
496
511
        inv = b.working_tree().inventory
497
512
        if inv.path2id('.bzrignore'):