support/scripts/pkg-stats: handle missing git repository
PATCH 1/1 support/scripts/pkg-stats: handle missing git repository
From: Raslen Ziadi <[email protected]>
pkg-stats can be run outside a Git repository. In this case, retrieving the current commit fails and aborts the script.
Handle this failure and omit the commit information from the HTML and JSON reports when the Git commit is unavailable.
--- support/scripts/pkg-stats | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
support/scripts/pkg-stats +15 -7
@@ -1260,7 +1260,10 @@ def dump_html_stats(f, stats): def dump_html_gen_info(f, date, commit): # Updated on Mon Feb 19 08:12:08 CET 2018, Git commit aa77030b8f5e41f1c53eb1c1ad664b8c814ba032 - f.write("<p><i>Updated on %s, git commit %s</i></p>\n" % (str(date), commit)) + if commit: + f.write("<p><i>Updated on %s, git commit %s</i></p>\n" % (str(date), commit)) + else: + f.write("<p><i>Updated on %s</i></p>\n" % str(date)) def dump_html(packages, stats, date, commit, output):
@@ -1300,9 +1303,10 @@ def dump_json(packages, defconfigs, stats, date, commit, output): final = {'packages': pkgs, 'stats': statistics, 'defconfigs': defconfigs, - 'package_status_checks': Package.status_checks, - 'commit': commit, - 'date': str(date)} + 'package_status_checks': Package.status_checks} + if commit: + final['commit'] = commit + final['date'] = str(date) with open(output, 'w') as f: json.dump(final, f, indent=2, separators=(',', ': '))
@@ -1371,9 +1375,13 @@ def main(): else: package_list = None date = datetime.datetime.now(datetime.timezone.utc) - commit = subprocess.check_output(['git', '-C', brpath, - 'rev-parse', - 'HEAD']).splitlines()[0].decode() + try: + commit = subprocess.check_output( + ['git', '-C', brpath, 'rev-parse', 'HEAD'], + stderr=subprocess.DEVNULL + ).splitlines()[0].decode() + except subprocess.CalledProcessError: + commit = None print("Build package list ...") all_trees = get_trees() packages = get_pkglist(all_trees, args.npackages, package_list)
Signature · 6 lines
2.43.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Hello Raslen Ziadi,
Quoted 7 lines · On Wed, 21 Oct 2026 14:46:55 +0100, [email protected] wrote:
From: Raslen Ziadi <[email protected]>
pkg-stats can be run outside a Git repository. In this case, retrieving the current commit fails and aborts the script.
Handle this failure and omit the commit information from the HTML and JSON reports when the Git commit is unavailable.
Stumbled some time ago over the same(?) failure and sent a slightly different fix as patch (see [1]):
[PATCH] support/scripts/pkg-stats: use BR2_VERSION_FULL instead of raw commit hash
Regards,
Peter
[1] https://lore.kernel.org/buildroot/[email protected]/T/#u
Quoted 43 lines
Signed-off-by Raslen Ziadi <[email protected]>--- support/scripts/pkg-stats | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)support/scripts/pkg-stats +8
-7@@ -1260,7 +1260,10 @@ def dump_html_stats(f, stats): def dump_html_gen_info(f, date, commit): # Updated on Mon Feb 19 08:12:08 CET 2018, Git commit aa77030b8f5e41f1c53eb1c1ad664b8c814ba032 - f.write("<p><i>Updated on %s, git commit %s</i></p>\n" % (str(date), commit)) + if commit: + f.write("<p><i>Updated on %s, git commit %s</i></p>\n" % (str(date), commit)) + else: + f.write("<p><i>Updated on %s</i></p>\n" % str(date)) def dump_html(packages, stats, date, commit, output):@@ -1300,9 +1303,10 @@ def dump_json(packages, defconfigs, stats, date, commit, output): final = {'packages': pkgs, 'stats': statistics, 'defconfigs': defconfigs, - 'package_status_checks': Package.status_checks, - 'commit': commit, - 'date': str(date)} + 'package_status_checks': Package.status_checks} + if commit: + final['commit'] = commit + final['date'] = str(date) with open(output, 'w') as f: json.dump(final, f, indent=2, separators=(',', ': '))@@ -1371,9 +1375,13 @@ def main(): else: package_list = None date = datetime.datetime.now(datetime.timezone.utc) - commit = subprocess.check_output(['git', '-C', brpath, - 'rev-parse', - 'HEAD']).splitlines()[0].decode()
support/scripts/pkg-stats def main(): · line 1387
Quoted 10 lines
support/scripts/pkg-stats +7
-0+ try: + commit = subprocess.check_output( + ['git', '-C', brpath, 'rev-parse', 'HEAD'], + stderr=subprocess.DEVNULL + ).splitlines()[0].decode() + except subprocess.CalledProcessError: + commit = None print("Build package list ...") all_trees = get_trees() packages = get_pkglist(all_trees, args.npackages, package_list)
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot