|
22 | 22 | AffiliationAnalysisError, |
23 | 23 | AffiliationFileNotFoundError, |
24 | 24 | AffiliationIntervalNotElapsedError, |
| 25 | + CommandExecutionError, |
25 | 26 | CrowdGitError, |
26 | 27 | ) |
27 | 28 | from crowdgit.models import CloneBatchInfo, Repository |
@@ -97,46 +98,50 @@ def path_matches_known_name(relative_path: str, known_name: str) -> bool: |
97 | 98 | stem, _ = os.path.splitext(basename) |
98 | 99 | return stem == known_name |
99 | 100 |
|
100 | | - async def find_files_by_known_name(self, repo_path: str, known_name: str) -> list[str]: |
101 | | - """Find repo paths whose basename matches a known affiliation filename.""" |
102 | | - glob_patterns = [f"**/{known_name}"] |
103 | | - if not known_name.startswith("."): |
104 | | - for extension in self.TEXT_FILE_EXTENSIONS: |
105 | | - if extension: |
106 | | - glob_patterns.append(f"**/{known_name}{extension}") |
| 101 | + @classmethod |
| 102 | + def is_known_affiliation_filename(cls, relative_path: str) -> bool: |
| 103 | + return any( |
| 104 | + cls.path_matches_known_name(relative_path, known_name) |
| 105 | + for known_name in cls.KNOWN_FILE_NAMES |
| 106 | + ) |
107 | 107 |
|
| 108 | + async def find_known_file_matches(self, repo_path: str) -> list[str]: |
| 109 | + """Find repo paths whose basename matches a known affiliation filename.""" |
108 | 110 | glob_args = ["--glob", "!.git/"] |
109 | | - for pattern in glob_patterns: |
110 | | - glob_args.extend(["--iglob", pattern]) |
| 111 | + for known_name in self.KNOWN_FILE_NAMES: |
| 112 | + glob_patterns = [f"**/{known_name}"] |
| 113 | + if not known_name.startswith("."): |
| 114 | + for extension in self.TEXT_FILE_EXTENSIONS: |
| 115 | + if extension: |
| 116 | + glob_patterns.append(f"**/{known_name}{extension}") |
| 117 | + for pattern in glob_patterns: |
| 118 | + glob_args.extend(["--iglob", pattern]) |
111 | 119 |
|
112 | 120 | try: |
113 | 121 | output = await run_shell_command( |
114 | 122 | ["rg", "--files", "--hidden", *glob_args, "."], |
115 | 123 | cwd=repo_path, |
116 | 124 | ) |
| 125 | + except CommandExecutionError: |
| 126 | + self.logger.info("Ripgrep found no affiliation files by filename") |
| 127 | + return [] |
117 | 128 | except FileNotFoundError: |
118 | 129 | self.logger.warning("Ripgrep not found, known filename search is unavailable") |
119 | 130 | return [] |
120 | 131 | except Exception as e: |
121 | | - self.logger.warning(f"Known filename search failed for {known_name!r}: {repr(e)}") |
| 132 | + self.logger.warning(f"Known filename search failed: {repr(e)}") |
122 | 133 | return [] |
123 | 134 |
|
124 | | - matches: list[str] = [] |
| 135 | + matches: set[str] = set() |
125 | 136 | for line in output.strip().split("\n"): |
126 | 137 | line = line.strip() |
127 | 138 | if not line: |
128 | 139 | continue |
129 | 140 | if line.startswith("./"): |
130 | 141 | line = line[2:] |
131 | | - if self.path_matches_known_name(line, known_name) and self.is_text_file_path(line): |
132 | | - matches.append(line) |
133 | | - |
134 | | - return matches |
| 142 | + if self.is_known_affiliation_filename(line) and self.is_text_file_path(line): |
| 143 | + matches.add(line) |
135 | 144 |
|
136 | | - async def find_known_file_matches(self, repo_path: str) -> list[str]: |
137 | | - matches: set[str] = set() |
138 | | - for known_name in self.KNOWN_FILE_NAMES: |
139 | | - matches.update(await self.find_files_by_known_name(repo_path, known_name)) |
140 | 145 | return sorted(matches) |
141 | 146 |
|
142 | 147 | @classmethod |
|
0 commit comments