Extracts the commit hash from a resolved filename toward a cache file.
(resolved_file: Optional[str], commit_hash: Optional[str] = None)
| 149 | |
| 150 | |
| 151 | def extract_commit_hash(resolved_file: Optional[str], commit_hash: Optional[str] = None): |
| 152 | """ |
| 153 | Extracts the commit hash from a resolved filename toward a cache file. |
| 154 | """ |
| 155 | if resolved_file is None or commit_hash is not None: |
| 156 | return commit_hash |
| 157 | resolved_file = str(Path(resolved_file).as_posix()) |
| 158 | search = re.search(r"snapshots/([^/]+)/", resolved_file) |
| 159 | if search is None: |
| 160 | return None |
| 161 | commit_hash = search.groups()[0] |
| 162 | return commit_hash if REGEX_COMMIT_HASH.match(commit_hash) else None |
| 163 | |
| 164 | |
| 165 | # Old default cache path, potentially to be migrated. |