MCPcopy Index your code
hub / github.com/huggingface/diffusers / get_diff

Function get_diff

utils/tests_fetcher.py:235–274  ·  view source on GitHub ↗

Get the diff between a base commit and one or several commits. Args: repo (`git.Repo`): A git repository (for instance the Transformers repo). base_commit (`str`): The commit reference of where to compare for the diff. This is the current commit, not

(repo: Repo, base_commit: str, commits: List[str])

Source from the content-addressed store, hash-verified

233
234
235def get_diff(repo: Repo, base_commit: str, commits: List[str]) -> List[str]:
236 """
237 Get the diff between a base commit and one or several commits.
238
239 Args:
240 repo (`git.Repo`):
241 A git repository (for instance the Transformers repo).
242 base_commit (`str`):
243 The commit reference of where to compare for the diff. This is the current commit, not the branching point!
244 commits (`List[str]`):
245 The list of commits with which to compare the repo at `base_commit` (so the branching point).
246
247 Returns:
248 `List[str]`: The list of Python files with a diff (files added, renamed or deleted are always returned, files
249 modified are returned if the diff in the file is not only in docstrings or comments, see
250 `diff_is_docstring_only`).
251 """
252 print("\n### DIFF ###\n")
253 code_diff = []
254 for commit in commits:
255 for diff_obj in commit.diff(base_commit):
256 # We always add new python files
257 if diff_obj.change_type == "A" and diff_obj.b_path.endswith(".py"):
258 code_diff.append(diff_obj.b_path)
259 # We check that deleted python files won't break corresponding tests.
260 elif diff_obj.change_type == "D" and diff_obj.a_path.endswith(".py"):
261 code_diff.append(diff_obj.a_path)
262 # Now for modified files
263 elif diff_obj.change_type in ["M", "R"] and diff_obj.b_path.endswith(".py"):
264 # In case of renames, we'll look at the tests using both the old and new name.
265 if diff_obj.a_path != diff_obj.b_path:
266 code_diff.extend([diff_obj.a_path, diff_obj.b_path])
267 else:
268 # Otherwise, we check modifications are in code and not docstrings.
269 if diff_is_docstring_only(repo, commit, diff_obj.b_path):
270 print(f"Ignoring diff in {diff_obj.b_path} as it only concerns docstrings or comments.")
271 else:
272 code_diff.append(diff_obj.a_path)
273
274 return code_diff
275
276
277def get_modified_python_files(diff_with_last_commit: bool = False) -> List[str]:

Callers 1

Calls 1

diff_is_docstring_onlyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…