Get last git commit dates for all paths under Lib/ in one git call. Keys are Lib/-relative paths (e.g. "re/__init__.py", "test/test_os.py", "os.py"), plus directory rollups (e.g. "re", "test/test_zoneinfo"). Returns: Dict mapping Lib/-relative path to date string.
()
| 1124 | |
| 1125 | @functools.cache |
| 1126 | def _bulk_last_updated() -> dict[str, str]: |
| 1127 | """Get last git commit dates for all paths under Lib/ in one git call. |
| 1128 | |
| 1129 | Keys are Lib/-relative paths (e.g. "re/__init__.py", "test/test_os.py", |
| 1130 | "os.py"), plus directory rollups (e.g. "re", "test/test_zoneinfo"). |
| 1131 | |
| 1132 | Returns: |
| 1133 | Dict mapping Lib/-relative path to date string. |
| 1134 | """ |
| 1135 | file_map: dict[str, str] = {} |
| 1136 | try: |
| 1137 | result = subprocess.run( |
| 1138 | ["git", "log", "--format=%cd", "--date=short", "--name-only", "--", "Lib/"], |
| 1139 | capture_output=True, |
| 1140 | text=True, |
| 1141 | timeout=30, |
| 1142 | ) |
| 1143 | if result.returncode != 0: |
| 1144 | return file_map |
| 1145 | except Exception: |
| 1146 | return file_map |
| 1147 | |
| 1148 | current_date = None |
| 1149 | for line in result.stdout.splitlines(): |
| 1150 | line = line.strip() |
| 1151 | if not line: |
| 1152 | continue |
| 1153 | # Date lines are YYYY-MM-DD format |
| 1154 | if len(line) == 10 and line[4] == "-" and line[7] == "-": |
| 1155 | current_date = line |
| 1156 | elif current_date and line.startswith("Lib/"): |
| 1157 | # Strip "Lib/" prefix to get Lib-relative key |
| 1158 | rel = line[4:] |
| 1159 | if rel and rel not in file_map: |
| 1160 | file_map[rel] = current_date |
| 1161 | |
| 1162 | # Pre-compute directory rollups |
| 1163 | dir_map: dict[str, str] = {} |
| 1164 | for filepath, date in file_map.items(): |
| 1165 | parts = filepath.split("/") |
| 1166 | for i in range(1, len(parts)): |
| 1167 | dirpath = "/".join(parts[:i]) |
| 1168 | if dirpath not in dir_map or date > dir_map[dirpath]: |
| 1169 | dir_map[dirpath] = date |
| 1170 | |
| 1171 | dir_map.update(file_map) |
| 1172 | return dir_map |
| 1173 | |
| 1174 | |
| 1175 | @functools.cache |
no test coverage detected