Fix possibly unbound Body by assigning preassigning them the else case and overriding them in the if case.

The current case will work until eiether the has_chunk_header above or below the _process_diff function changes, and then it will cause runtime crash as one cannot concat string and None.

Change-Id: I81737328f609e636bcee5087a2bc4aa96a6a6964
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7260374
Reviewed-by: Brian Egizi <begizi@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Alex Ovsienko <ovsienko@google.com>
This commit is contained in:
Alex Ovsienko
2025-12-17 16:09:22 -08:00
committed by LUCI CQ
parent 02f1c0f8b7
commit 30e928fe1c

View File

@@ -84,11 +84,10 @@ def _process_diff(diff: str, src_root: str, dst_root: str) -> str:
return "" return ""
has_chunk_header = HEADER_DELIMITER in diff has_chunk_header = HEADER_DELIMITER in diff
header, body = diff, ""
if has_chunk_header: if has_chunk_header:
header, body = diff.split(HEADER_DELIMITER, maxsplit=1) header, body = diff.split(HEADER_DELIMITER, maxsplit=1)
else:
# Only the file mode changed.
header = diff
norm_src = src_root.rstrip(os.sep) norm_src = src_root.rstrip(os.sep)
norm_dst = dst_root.rstrip(os.sep) norm_dst = dst_root.rstrip(os.sep)