MCPcopy Create free account
hub / github.com/modelscope/modelscope / git_hash

Function git_hash

modelscope/utils/repo_utils.py:373–398  ·  view source on GitHub ↗

Computes the git-sha1 hash of the given bytes, using the same algorithm as git. This is equivalent to running `git hash-object`. See https://git-scm.com/docs/git-hash-object for more details. Note: this method is valid for regular files. For LFS files, the proper git hash is suppo

(data: bytes)

Source from the content-addressed store, hash-verified

371
372
373def git_hash(data: bytes) -> str:
374 """
375 Computes the git-sha1 hash of the given bytes, using the same algorithm as git.
376
377 This is equivalent to running `git hash-object`. See https://git-scm.com/docs/git-hash-object
378 for more details.
379
380 Note: this method is valid for regular files. For LFS files, the proper git hash is supposed to be computed on the
381 pointer file content, not the actual file content. However, for simplicity, we directly compare the sha256 of
382 the LFS file content when we want to compare LFS files.
383
384 Args:
385 data (`bytes`):
386 The data to compute the git-hash for.
387
388 Returns:
389 `str`: the git-hash of `data` as an hexadecimal string.
390 """
391 _kwargs = {'usedforsecurity': False} if sys.version_info >= (3, 9) else {}
392 sha1 = functools.partial(hashlib.sha1, **_kwargs)
393 sha = sha1()
394 sha.update(b'blob ')
395 sha.update(str(len(data)).encode())
396 sha.update(b'\0')
397 sha.update(data)
398 return sha.hexdigest()
399
400
401@dataclass

Callers 1

_local_oidMethod · 0.85

Calls 2

updateMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…