From 8e2da91cbb4a7ae49036911ca5df3a9ca430f8e0 Mon Sep 17 00:00:00 2001 From: Vadim Shtayura Date: Fri, 21 Oct 2022 10:37:37 +0000 Subject: [PATCH] Fix UnboundLocalError in CheckLicense. `current_year` wasn't initialized if `licence_re` is set. See e.g. https://ci.chromium.org/b/8799737896715431809 R=brucedawson@chromium.org, iannucci@chromium.org BUG=1098010 Change-Id: Idb1a320af7f4790f2dac0fba7a62e2990a3664e9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3969027 Reviewed-by: Bruce Dawson Commit-Queue: Harald Alvestrand --- presubmit_canned_checks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 8b23bb495..1800e324f 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -639,6 +639,8 @@ def CheckLicense(input_api, output_api, license_re=None, project_name=None, if license_re and license_re == '.*': return [] + current_year = int(input_api.time.strftime('%Y')) + if license_re: new_license_re = license_re else: @@ -647,7 +649,6 @@ def CheckLicense(input_api, output_api, license_re=None, project_name=None, # Accept any year number from 2006 to the current year, or the special # 2006-20xx string used on the oldest files. 2006-20xx is deprecated, but # tolerated on old files. On new files the current year must be specified. - current_year = int(input_api.time.strftime('%Y')) allowed_years = (str(s) for s in reversed(range(2006, current_year + 1))) years_re = '(' + '|'.join(allowed_years) + '|2006-2008|2006-2009|2006-2010)'