From 87e1b9f0b5682cd2094b18bb633c2112c84ecc6b Mon Sep 17 00:00:00 2001 From: Minecrell Date: Sat, 14 Mar 2020 12:17:50 +0100 Subject: [PATCH] CI: common: get_changed_files: return set, add "removed" parameter (!1069) All users of get_changed_files() check if the file was removed, so it seems like most of them do not need files that were removed. Also, there is no need to have files listed twice, so we should return a set instead of a list. --- .gitlab-ci/common.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci/common.py b/.gitlab-ci/common.py index f7c846e26..f8f02c064 100755 --- a/.gitlab-ci/common.py +++ b/.gitlab-ci/common.py @@ -45,10 +45,11 @@ def run_pmbootstrap(parameters): exit(1) -def get_changed_files(): +def get_changed_files(removed=True): """ Get all changed files and print them, as well as the branch and the commit that was used for the diff. - :returns: list of changed files + :param removed: also return removed files (default: True) + :returns: set of changed files """ commit_head = run_git(["rev-parse", "HEAD"])[:-1] commit_upstream_master = run_git(["rev-parse", "upstream/master"])[:-1] @@ -65,12 +66,16 @@ def get_changed_files(): print("comparing HEAD with: " + commit) # Changed files - ret = run_git(["diff", "--name-only", commit, "HEAD"]).splitlines() + ret = set() print("changed file(s):") - for file in ret: + for file in run_git(["diff", "--name-only", commit, "HEAD"]).splitlines(): message = " " + file if not os.path.exists(file): message += " (deleted)" + if removed: + ret.add(file) + else: + ret.add(file) print(message) return ret