PatchMetadata.from_commit: make path optional
we are using this in d2s
@@ -115,7 +115,16 @@ class PatchMetadata:
return msg
@staticmethod
- def from_commit(commit: git.Commit, patch_path: Path) -> "PatchMetadata":
+ def from_commit(
+ commit: git.Commit, patch_path: Optional[Path] = None
+ ) -> "PatchMetadata":
+ """
+ Load PatchMetadata from an existing git.Commit
+
+ @param commit: the git.Commit to load the metadata from
+ @param patch_path: optional Path to an existing patch file present on the disk
+ @return: PatchMetadata instance
+ """
metadata = get_metadata_from_message(commit) or {}
if metadata:
logger.debug(
@@ -126,6 +135,7 @@ class PatchMetadata:
logger.debug(f"Commit {commit.hexsha:.8} does not contain any metadata.")
name = metadata.get("patch_name")
+ if patch_path:
if name:
new_path = patch_path.parent / name
logger.debug(f"Renaming the patch: {patch_path.name} -> {new_path}")
