From: Jordan Justen Date: Thu, 10 Aug 2023 08:14:04 +0000 (-0700) Subject: intel/genxml: Don't rewrite sorted xml if the contents didn't change X-Git-Tag: upstream/23.3.3~3321 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=548a0bc7d2ab89732ddfcc77315a4798573589a3;p=platform%2Fupstream%2Fmesa.git intel/genxml: Don't rewrite sorted xml if the contents didn't change Rework: * Make better use of pathlib. (Dylan) Signed-off-by: Jordan Justen Reviewed-by: Dylan Baker Part-of: --- diff --git a/src/intel/genxml/intel_genxml.py b/src/intel/genxml/intel_genxml.py index 492bf69..8a3a7fa 100755 --- a/src/intel/genxml/intel_genxml.py +++ b/src/intel/genxml/intel_genxml.py @@ -5,6 +5,7 @@ from __future__ import annotations from collections import OrderedDict import copy +import io import pathlib import re import xml.etree.ElementTree as et @@ -202,7 +203,17 @@ class GenXml(object): for old, new in zip(self.et.getroot(), other.et.getroot())) def write_file(self): - tmp = self.filename.with_suffix(f'{self.filename.suffix}.tmp') + try: + old_genxml = GenXml(self.filename) + if self.is_equivalent_xml(old_genxml): + return + except Exception: + pass + + b_io = io.BytesIO() et.indent(self.et, space=' ') - self.et.write(tmp, encoding="utf-8", xml_declaration=True) + self.et.write(b_io, encoding="utf-8", xml_declaration=True) + + tmp = self.filename.with_suffix(f'{self.filename.suffix}.tmp') + tmp.write_bytes(b_io.getvalue()) tmp.replace(self.filename)