def refresh(self, patch_name=None, edit=False): """ Refresh patch with patch_name or applied top patch if patch_name is None """ if patch_name: patch = Patch(patch_name) else: patch = self.db.top_patch() if not patch: raise QuiltError("No patch applied. Nothing to refresh.") pc_dir = self.quilt_pc + patch.get_name() patch_file = self.quilt_patches + File(patch.get_name()) files = pc_dir.content()[1] with TmpFile(prefix="pquilt-") as tmpfile: f = tmpfile.open() if patch_file.exists(): header = patch.get_header(self.quilt_patches) tmpfile.write(header) for file_name in files: if file_name == ".timestamp": continue orig_file = pc_dir + File(file_name) new_file = File(file_name) left_label, right_label, index = self._get_labels( file_name, orig_file, new_file) self._write_index(tmpfile, index) diff = Diff(orig_file, new_file) diff.run(self.cwd, fd=f, left_label=left_label, right_label=right_label) if tmpfile.is_empty(): raise QuiltError("Nothing to refresh.") if edit: self.edit_patch(tmpfile) tpatch = Patch(tmpfile.get_name()) tpatch.run(pc_dir.get_name(), dry_run=True, quiet=True) if patch_file.exists(): diff = Diff(patch_file, tmpfile) if diff.equal(self.cwd): raise QuiltError("Nothing to refresh.") tmpfile.copy(patch_file) timestamp = pc_dir + File(".timestamp") timestamp.touch() refresh = self.quilt_pc + File(patch.get_name() + "~refresh") refresh.delete_if_exists() self.refreshed(patch)
def refresh(self, patch_name=None, edit=False): """ Refresh patch with patch_name or applied top patch if patch_name is None """ if patch_name: patch = Patch(patch_name) else: patch = self.db.top_patch() if not patch: raise QuiltError("No patch applied. Nothing to refresh.") pc_dir = self.quilt_pc + patch.get_name() patch_file = self.quilt_patches + File(patch.get_name()) files = pc_dir.content()[1] with TmpFile(prefix="pquilt-") as tmpfile: f = tmpfile.open() if patch_file.exists(): header = patch.get_header(self.quilt_patches) tmpfile.write(header) for file_name in files: if file_name == ".timestamp": continue orig_file = pc_dir + File(file_name) new_file = File(file_name) left_label, right_label, index = self._get_labels(file_name, orig_file, new_file) self._write_index(tmpfile, index) diff = Diff(orig_file, new_file) diff.run(self.cwd, fd=f, left_label=left_label, right_label=right_label) if tmpfile.is_empty(): raise QuiltError("Nothing to refresh.") if edit: self.edit_patch(tmpfile) tpatch = Patch(tmpfile.get_name()) tpatch.run(pc_dir.get_name(), dry_run=True, quiet=True) if patch_file.exists(): diff = Diff(patch_file, tmpfile) if diff.equal(self.cwd): raise QuiltError("Nothing to refresh.") tmpfile.copy(patch_file) timestamp = pc_dir + File(".timestamp") timestamp.touch() refresh = self.quilt_pc + File(patch.get_name() + "~refresh") refresh.delete_if_exists() self.refreshed(patch)