|
@@ -117,7 +117,6 @@ if TYPE_CHECKING:
|
|
|
ZERO_SHA = b"0" * 40 # SHA1 - kept for backward compatibility
|
|
ZERO_SHA = b"0" * 40 # SHA1 - kept for backward compatibility
|
|
|
|
|
|
|
|
|
|
|
|
|
->>>>>>> 063bbc0c (Update more hardcoded sha length)
|
|
|
|
|
# Header fields for commits
|
|
# Header fields for commits
|
|
|
_TREE_HEADER = b"tree"
|
|
_TREE_HEADER = b"tree"
|
|
|
_PARENT_HEADER = b"parent"
|
|
_PARENT_HEADER = b"parent"
|
|
@@ -459,10 +458,7 @@ class ShaFile:
|
|
|
type_name: bytes
|
|
type_name: bytes
|
|
|
type_num: int
|
|
type_num: int
|
|
|
_chunked_text: list[bytes] | None
|
|
_chunked_text: list[bytes] | None
|
|
|
-<<<<<<< HEAD
|
|
|
|
|
_sha: "FixedSha | None | HASH"
|
|
_sha: "FixedSha | None | HASH"
|
|
|
-=======
|
|
|
|
|
- _sha: Union[FixedSha, None, "HASH"]
|
|
|
|
|
object_format: ObjectFormat
|
|
object_format: ObjectFormat
|
|
|
|
|
|
|
|
def __init__(self) -> None:
|
|
def __init__(self) -> None:
|
|
@@ -566,7 +562,11 @@ class ShaFile:
|
|
|
self.set_raw_chunks([text], sha)
|
|
self.set_raw_chunks([text], sha)
|
|
|
|
|
|
|
|
def set_raw_chunks(
|
|
def set_raw_chunks(
|
|
|
- self, chunks: list[bytes], sha: ObjectID | RawObjectID | None = None, *, object_format=None
|
|
|
|
|
|
|
+ self,
|
|
|
|
|
+ chunks: list[bytes],
|
|
|
|
|
+ sha: ObjectID | RawObjectID | None = None,
|
|
|
|
|
+ *,
|
|
|
|
|
+ object_format: ObjectFormat | None = None,
|
|
|
) -> None:
|
|
) -> None:
|
|
|
"""Set the contents of this object from a list of chunks."""
|
|
"""Set the contents of this object from a list of chunks."""
|
|
|
self._chunked_text = chunks
|
|
self._chunked_text = chunks
|
|
@@ -613,7 +613,10 @@ class ShaFile:
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
|
def _parse_file(
|
|
def _parse_file(
|
|
|
- cls, f: BufferedIOBase | IO[bytes] | "_GitFile", *, object_format=None
|
|
|
|
|
|
|
+ cls,
|
|
|
|
|
+ f: BufferedIOBase | IO[bytes] | "_GitFile",
|
|
|
|
|
+ *,
|
|
|
|
|
+ object_format: ObjectFormat | None = None,
|
|
|
) -> "ShaFile":
|
|
) -> "ShaFile":
|
|
|
map = f.read()
|
|
map = f.read()
|
|
|
if not map:
|
|
if not map:
|
|
@@ -639,7 +642,11 @@ class ShaFile:
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
|
def from_path(
|
|
def from_path(
|
|
|
- cls, path: str | bytes, sha: ObjectID | None = None, *, object_format=None
|
|
|
|
|
|
|
+ cls,
|
|
|
|
|
+ path: str | bytes,
|
|
|
|
|
+ sha: ObjectID | None = None,
|
|
|
|
|
+ *,
|
|
|
|
|
+ object_format: ObjectFormat | None = None,
|
|
|
) -> "ShaFile":
|
|
) -> "ShaFile":
|
|
|
"""Open a SHA file from disk."""
|
|
"""Open a SHA file from disk."""
|
|
|
with GitFile(path, "rb") as f:
|
|
with GitFile(path, "rb") as f:
|
|
@@ -651,7 +658,7 @@ class ShaFile:
|
|
|
f: BufferedIOBase | IO[bytes] | "_GitFile",
|
|
f: BufferedIOBase | IO[bytes] | "_GitFile",
|
|
|
sha: ObjectID | None = None,
|
|
sha: ObjectID | None = None,
|
|
|
*,
|
|
*,
|
|
|
- object_format=None,
|
|
|
|
|
|
|
+ object_format: ObjectFormat | None = None,
|
|
|
) -> "ShaFile":
|
|
) -> "ShaFile":
|
|
|
"""Get the contents of a SHA file on disk."""
|
|
"""Get the contents of a SHA file on disk."""
|
|
|
try:
|
|
try:
|
|
@@ -679,7 +686,7 @@ class ShaFile:
|
|
|
string: bytes,
|
|
string: bytes,
|
|
|
sha: ObjectID | RawObjectID | None = None,
|
|
sha: ObjectID | RawObjectID | None = None,
|
|
|
*,
|
|
*,
|
|
|
- object_format=None,
|
|
|
|
|
|
|
+ object_format: ObjectFormat | None = None,
|
|
|
) -> "ShaFile":
|
|
) -> "ShaFile":
|
|
|
"""Creates an object of the indicated type from the raw string given.
|
|
"""Creates an object of the indicated type from the raw string given.
|
|
|
|
|
|
|
@@ -765,7 +772,7 @@ class ShaFile:
|
|
|
"""Returns the length of the raw string of this object."""
|
|
"""Returns the length of the raw string of this object."""
|
|
|
return sum(map(len, self.as_raw_chunks()))
|
|
return sum(map(len, self.as_raw_chunks()))
|
|
|
|
|
|
|
|
- def sha(self, object_format=None) -> "FixedSha | HASH":
|
|
|
|
|
|
|
+ def sha(self, object_format: ObjectFormat | None = None) -> "FixedSha | HASH":
|
|
|
"""The SHA object that is the name of this object.
|
|
"""The SHA object that is the name of this object.
|
|
|
|
|
|
|
|
Args:
|
|
Args:
|
|
@@ -805,7 +812,7 @@ class ShaFile:
|
|
|
"""
|
|
"""
|
|
|
return ObjectID(self.sha().hexdigest().encode("ascii"))
|
|
return ObjectID(self.sha().hexdigest().encode("ascii"))
|
|
|
|
|
|
|
|
- def get_id(self, object_format=None) -> bytes:
|
|
|
|
|
|
|
+ def get_id(self, object_format: ObjectFormat | None = None) -> bytes:
|
|
|
"""Get the hex SHA of this object using the specified hash algorithm.
|
|
"""Get the hex SHA of this object using the specified hash algorithm.
|
|
|
|
|
|
|
|
Args:
|
|
Args:
|
|
@@ -894,12 +901,19 @@ class Blob(ShaFile):
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
|
- def from_path(cls, path: str | bytes, sha: ObjectID | None = None) -> "Blob":
|
|
|
|
|
|
|
+ def from_path(
|
|
|
|
|
+ cls,
|
|
|
|
|
+ path: str | bytes,
|
|
|
|
|
+ sha: ObjectID | None = None,
|
|
|
|
|
+ *,
|
|
|
|
|
+ object_format: ObjectFormat | None = None,
|
|
|
|
|
+ ) -> "Blob":
|
|
|
"""Read a blob from a file on disk.
|
|
"""Read a blob from a file on disk.
|
|
|
|
|
|
|
|
Args:
|
|
Args:
|
|
|
path: Path to the blob file
|
|
path: Path to the blob file
|
|
|
sha: Optional known SHA for the object
|
|
sha: Optional known SHA for the object
|
|
|
|
|
+ object_format: Optional object format to use
|
|
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
|
A Blob object
|
|
A Blob object
|
|
@@ -907,7 +921,7 @@ class Blob(ShaFile):
|
|
|
Raises:
|
|
Raises:
|
|
|
NotBlobError: If the file is not a blob
|
|
NotBlobError: If the file is not a blob
|
|
|
"""
|
|
"""
|
|
|
- blob = ShaFile.from_path(path, sha)
|
|
|
|
|
|
|
+ blob = ShaFile.from_path(path, sha, object_format=object_format)
|
|
|
if not isinstance(blob, cls):
|
|
if not isinstance(blob, cls):
|
|
|
raise NotBlobError(_path_to_bytes(path))
|
|
raise NotBlobError(_path_to_bytes(path))
|
|
|
return blob
|
|
return blob
|
|
@@ -1056,12 +1070,19 @@ class Tag(ShaFile):
|
|
|
self._signature: bytes | None = None
|
|
self._signature: bytes | None = None
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
|
- def from_path(cls, filename: str | bytes, sha: ObjectID | None = None) -> "Tag":
|
|
|
|
|
|
|
+ def from_path(
|
|
|
|
|
+ cls,
|
|
|
|
|
+ filename: str | bytes,
|
|
|
|
|
+ sha: ObjectID | None = None,
|
|
|
|
|
+ *,
|
|
|
|
|
+ object_format: ObjectFormat | None = None,
|
|
|
|
|
+ ) -> "Tag":
|
|
|
"""Read a tag from a file on disk.
|
|
"""Read a tag from a file on disk.
|
|
|
|
|
|
|
|
Args:
|
|
Args:
|
|
|
filename: Path to the tag file
|
|
filename: Path to the tag file
|
|
|
sha: Optional known SHA for the object
|
|
sha: Optional known SHA for the object
|
|
|
|
|
+ object_format: Optional object format to use
|
|
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
|
A Tag object
|
|
A Tag object
|
|
@@ -1069,7 +1090,7 @@ class Tag(ShaFile):
|
|
|
Raises:
|
|
Raises:
|
|
|
NotTagError: If the file is not a tag
|
|
NotTagError: If the file is not a tag
|
|
|
"""
|
|
"""
|
|
|
- tag = ShaFile.from_path(filename, sha)
|
|
|
|
|
|
|
+ tag = ShaFile.from_path(filename, sha, object_format=object_format)
|
|
|
if not isinstance(tag, cls):
|
|
if not isinstance(tag, cls):
|
|
|
raise NotTagError(_path_to_bytes(filename))
|
|
raise NotTagError(_path_to_bytes(filename))
|
|
|
return tag
|
|
return tag
|
|
@@ -1365,6 +1386,8 @@ def parse_tree(
|
|
|
name_end = text.index(b"\0", mode_end)
|
|
name_end = text.index(b"\0", mode_end)
|
|
|
name = text[mode_end + 1 : name_end]
|
|
name = text[mode_end + 1 : name_end]
|
|
|
|
|
|
|
|
|
|
+ if sha_len is None:
|
|
|
|
|
+ raise ObjectFormatException("sha_len must be specified")
|
|
|
count = name_end + 1 + sha_len
|
|
count = name_end + 1 + sha_len
|
|
|
if count > length:
|
|
if count > length:
|
|
|
raise ObjectFormatException(
|
|
raise ObjectFormatException(
|
|
@@ -1487,12 +1510,19 @@ class Tree(ShaFile):
|
|
|
self._entries: dict[bytes, tuple[int, ObjectID]] = {}
|
|
self._entries: dict[bytes, tuple[int, ObjectID]] = {}
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
|
- def from_path(cls, filename: str | bytes, sha: ObjectID | None = None) -> "Tree":
|
|
|
|
|
|
|
+ def from_path(
|
|
|
|
|
+ cls,
|
|
|
|
|
+ filename: str | bytes,
|
|
|
|
|
+ sha: ObjectID | None = None,
|
|
|
|
|
+ *,
|
|
|
|
|
+ object_format: ObjectFormat | None = None,
|
|
|
|
|
+ ) -> "Tree":
|
|
|
"""Read a tree from a file on disk.
|
|
"""Read a tree from a file on disk.
|
|
|
|
|
|
|
|
Args:
|
|
Args:
|
|
|
filename: Path to the tree file
|
|
filename: Path to the tree file
|
|
|
sha: Optional known SHA for the object
|
|
sha: Optional known SHA for the object
|
|
|
|
|
+ object_format: Optional object format to use
|
|
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
|
A Tree object
|
|
A Tree object
|
|
@@ -1500,7 +1530,7 @@ class Tree(ShaFile):
|
|
|
Raises:
|
|
Raises:
|
|
|
NotTreeError: If the file is not a tree
|
|
NotTreeError: If the file is not a tree
|
|
|
"""
|
|
"""
|
|
|
- tree = ShaFile.from_path(filename, sha)
|
|
|
|
|
|
|
+ tree = ShaFile.from_path(filename, sha, object_format=object_format)
|
|
|
if not isinstance(tree, cls):
|
|
if not isinstance(tree, cls):
|
|
|
raise NotTreeError(_path_to_bytes(filename))
|
|
raise NotTreeError(_path_to_bytes(filename))
|
|
|
return tree
|
|
return tree
|
|
@@ -1876,12 +1906,19 @@ class Commit(ShaFile):
|
|
|
self._commit_timezone_neg_utc: bool | None = False
|
|
self._commit_timezone_neg_utc: bool | None = False
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
|
- def from_path(cls, path: str | bytes, sha: ObjectID | None = None) -> "Commit":
|
|
|
|
|
|
|
+ def from_path(
|
|
|
|
|
+ cls,
|
|
|
|
|
+ path: str | bytes,
|
|
|
|
|
+ sha: ObjectID | None = None,
|
|
|
|
|
+ *,
|
|
|
|
|
+ object_format: ObjectFormat | None = None,
|
|
|
|
|
+ ) -> "Commit":
|
|
|
"""Read a commit from a file on disk.
|
|
"""Read a commit from a file on disk.
|
|
|
|
|
|
|
|
Args:
|
|
Args:
|
|
|
path: Path to the commit file
|
|
path: Path to the commit file
|
|
|
sha: Optional known SHA for the object
|
|
sha: Optional known SHA for the object
|
|
|
|
|
+ object_format: Optional object format to use
|
|
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
|
A Commit object
|
|
A Commit object
|
|
@@ -1889,7 +1926,7 @@ class Commit(ShaFile):
|
|
|
Raises:
|
|
Raises:
|
|
|
NotCommitError: If the file is not a commit
|
|
NotCommitError: If the file is not a commit
|
|
|
"""
|
|
"""
|
|
|
- commit = ShaFile.from_path(path, sha)
|
|
|
|
|
|
|
+ commit = ShaFile.from_path(path, sha, object_format=object_format)
|
|
|
if not isinstance(commit, cls):
|
|
if not isinstance(commit, cls):
|
|
|
raise NotCommitError(_path_to_bytes(path))
|
|
raise NotCommitError(_path_to_bytes(path))
|
|
|
return commit
|
|
return commit
|