def add_file(self, filename, patch_name=None, ignore=False): """ 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. """ file = File(filename) if patch_name: patch = Patch(patch_name) else: patch = self.db.top_patch() if not patch: raise NoAppliedPatch(self.db) exists = self._file_in_patch(filename, patch, ignore) if exists: return self._file_in_next_patches(filename, patch) if file.is_link(): raise QuiltError("Cannot add symbolic link %s" % filename) self._backup_file(file, patch) if file.exists(): # be sure user can write original file os.chmod(filename, file.get_mode() | stat.S_IWUSR | stat.S_IRUSR) self.file_added(file, patch)
def _apply_patch(self, patch, force=False, quiet=False): patch_name = patch.get_name() pc_dir = self.quilt_pc + patch_name patch_file = self.quilt_patches + File(patch_name) refresh = File(pc_dir.get_name() + "~refresh") if refresh.exists(): raise QuiltError("Patch %s needs to be refreshed" % \ patch_name) forced = False self.applying_patch(patch) if patch_file.exists(): try: patch.run(self.cwd, patch_dir=self.quilt_patches, backup=True, prefix=pc_dir.get_name(), quiet=quiet) refresh.delete_if_exists() except SubprocessError, e: refresh.touch() if not force: patch = RollbackPatch(self.cwd, pc_dir) patch.rollback() patch.delete_backup() raise QuiltError("Patch %s does not apply" % patch_name) else: forced = True
def _check(self, force=False): if not self.db.exists() or not self.db.patches(): raise NoAppliedPatch(self.db) if not force: patch = self.db.top_patch() pc_dir = self.quilt_pc + patch.get_name() refresh = File(pc_dir.get_name() + "~refresh") if refresh.exists(): raise QuiltError("Patch %s needs to be refreshed first." % patch.get_name())
def revert_file(self, filename, patch_name=None): """ Revert not added changes of filename. If patch_name is None or empty the topmost patch will be used. """ file = File(filename) if patch_name: patch = Patch(patch_name) else: patch = self.db.top_patch() if not patch: raise QuiltError("No patch available. Nothing to revert.") self._file_in_patch(filename, patch) self._file_in_next_patches(filename, patch) pc_dir = self.quilt_pc + patch.get_name() pc_file = pc_dir + file if not file.exists() and pc_file.is_empty(): # new and empty file will be reverted pc_file.delete() self.file_reverted(file, patch) return with TmpDirectory(prefix="pquilt-") as tmpdir: # apply current patch in temporary directory to revert changes of # file that aren't committed in the patch tmp_file = self._apply_patch_temporary(tmpdir, pc_file, patch) if tmp_file and tmp_file.exists() and not tmp_file.is_empty(): diff = Diff(file, tmp_file) if diff.equal(self.cwd): self.file_unchanged(file, patch) return dir = file.get_directory() if not dir: dir = Directory(os.getcwd()) else: dir.create() tmp_file.copy(dir) self.file_reverted(file, patch) else: self.file_unchanged(file, patch)