def add_file(self, filename, patch_name=None, ignore=False):
file = File(filename)<EOL>if patch_name:<EOL><INDENT>patch = Patch(patch_name)<EOL><DEDENT>else:<EOL><INDENT>patch = self.db.top_patch()<EOL>if not patch:<EOL><INDENT>raise NoAppliedPatch(self.db)<EOL><DEDENT><DEDENT>exists = self._file_in_patch(filename, patch, ignore)<EOL>if exists:<EOL><INDENT>return<EOL><DEDENT>self._file_in_next_patches(filename, patch)<EOL>if file.is_link():<EOL><INDENT>raise QuiltError("<STR_LIT>" % filename)<EOL><DEDENT>self._backup_file(file, patch)<EOL>if file.exists():<EOL><INDENT>os.chmod(filename, file.get_mode() | stat.S_IWUSR | stat.S_IRUSR)<EOL><DEDENT>self.file_added(file, patch)<EOL>
Add file to the patch with patch_name.
        If patch_name is None or empty the topmost patch will be used.
        Adding an already added patch will raise an QuiltError if ignore is
        False.