From: Patrick Donnelly Date: Thu, 16 Jul 2026 16:27:11 +0000 (-0400) Subject: ptl-tool: keep .githubmap sorted when adding new contributors X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1085687ac0a3407fc41c1e5b5dc61da806916d34;p=ceph.git ptl-tool: keep .githubmap sorted when adding new contributors Signed-off-by: Patrick Donnelly --- diff --git a/src/script/ptl-tool.py b/src/script/ptl-tool.py index 83a96c9e20ab..9ba4314f5560 100755 --- a/src/script/ptl-tool.py +++ b/src/script/ptl-tool.py @@ -2190,12 +2190,44 @@ def build_branch(args): G.git.merge(tip.hexsha, '--no-ff', m=message) - if new_contributors: - # Check out the PR, add a commit adding to .githubmap + if new_contributors and base == 'main': log.info("adding new contributors to githubmap in merge commit") - with open(git_dir + "/.githubmap", "a") as f: - for c in new_contributors: - f.write("%s %s\n" % (c, new_contributors[c])) + githubmap_path = os.path.join(git_dir, ".githubmap") + + headers = [] + entries = [] + + # Read existing file and separate headers from data entries + with open(githubmap_path, "r", encoding="utf-8") as f: + for line in f: + line = line.strip() + if line.startswith("#"): + headers.append(line + "\n") + elif line: + # Read it again because our last read of githubmap may be out-of-date + entries.append(line + "\n") + + # Format and append new contributors + for c in new_contributors: + new_line = f"{c} {new_contributors[c]}\n" + entries.append(new_line) + + # Perform a stable, case-insensitive sort on the data entries. + # Empty/whitespace-only lines are pushed to the bottom of the block, + # while actual entries are sorted by their first word (the GitHub handle). + def sort_key(line): + # Sort actual lines first, case-insensitively by the handle (the first word) + handle = line.split()[0] + handle = "".join(char.lower() for char in handle if char.isalnum()) + return handle + + entries.sort(key=sort_key) + + # Write back the preserved headers and sorted data entries + with open(githubmap_path, "w", encoding="utf-8") as f: + f.writelines(headers) + f.writelines(entries) + G.index.add([".githubmap"]) G.git.commit("--amend", "--no-edit")