Changeset View
Changeset View
Standalone View
Standalone View
swh/model/git_objects.py
Show First 20 Lines • Show All 406 Lines • ▼ Show 20 Lines | def release_git_object(release: Union[Dict, model.Release]) -> bytes: | ||||
] | ] | ||||
if release.author is not None: | if release.author is not None: | ||||
headers.append((b"tagger", format_author_data(release.author, release.date))) | headers.append((b"tagger", format_author_data(release.author, release.date))) | ||||
return format_git_object_from_headers("tag", headers, release.message) | return format_git_object_from_headers("tag", headers, release.message) | ||||
def snapshot_git_object(snapshot: Union[Dict, model.Snapshot]) -> bytes: | def snapshot_git_object( | ||||
snapshot: Union[Dict, model.Snapshot], *, ignore_unresolved: bool = False | |||||
anlambert: Could you add a new sentence in the docstring explaining the purpose of that parameter ? | |||||
) -> bytes: | |||||
"""Formats a snapshot as a git-like object. | """Formats a snapshot as a git-like object. | ||||
Snapshots are a set of named branches, which are pointers to objects at any | Snapshots are a set of named branches, which are pointers to objects at any | ||||
level of the Software Heritage DAG. | level of the Software Heritage DAG. | ||||
As well as pointing to other objects in the Software Heritage DAG, branches | As well as pointing to other objects in the Software Heritage DAG, branches | ||||
can also be *alias*es, in which case their target is the name of another | can also be *alias*es, in which case their target is the name of another | ||||
branch in the same snapshot, or *dangling*, in which case the target is | branch in the same snapshot, or *dangling*, in which case the target is | ||||
Show All 29 Lines | 2. For each branch, the following bytes are output: | ||||
- for branch aliases, the name of the target branch (as raw bytes) | - for branch aliases, the name of the target branch (as raw bytes) | ||||
- for dangling branches, the empty string | - for dangling branches, the empty string | ||||
Note that, akin to directory manifests, there is no separator between | Note that, akin to directory manifests, there is no separator between | ||||
entries. Because of symbolic branches, identifiers are of arbitrary | entries. Because of symbolic branches, identifiers are of arbitrary | ||||
length but are length-encoded to avoid ambiguity. | length but are length-encoded to avoid ambiguity. | ||||
""" | """ | ||||
if isinstance(snapshot, dict): | if isinstance(snapshot, dict): | ||||
# For backward compatibility | # For backward compatibility | ||||
Not Done Inline ActionsLooks like there is an extra cause word here. anlambert: Looks like there is an extra cause word here. | |||||
Done Inline Actionsoops, fixed (committed directly to master) vlorentz: oops, fixed (committed directly to master) | |||||
warnings.warn( | warnings.warn( | ||||
"snapshot_git_object's argument should be a swh.model.model.Snapshot " | "snapshot_git_object's argument should be a swh.model.model.Snapshot " | ||||
"object.", | "object.", | ||||
DeprecationWarning, | DeprecationWarning, | ||||
stacklevel=2, | stacklevel=2, | ||||
) | ) | ||||
snapshot = model.Snapshot.from_dict(snapshot) | snapshot = model.Snapshot.from_dict(snapshot) | ||||
snapshot = cast(model.Snapshot, snapshot) | snapshot = cast(model.Snapshot, snapshot) | ||||
Show All 20 Lines | for name, target in sorted(snapshot.branches.items()): | ||||
b"\x20", | b"\x20", | ||||
name, | name, | ||||
b"\x00", | b"\x00", | ||||
("%d:" % len(target_id)).encode(), | ("%d:" % len(target_id)).encode(), | ||||
target_id, | target_id, | ||||
] | ] | ||||
) | ) | ||||
if unresolved: | if unresolved and not ignore_unresolved: | ||||
raise ValueError( | raise ValueError( | ||||
"Branch aliases unresolved: %s" | "Branch aliases unresolved: %s" | ||||
% ", ".join("%r -> %r" % x for x in unresolved), | % ", ".join("%r -> %r" % x for x in unresolved), | ||||
unresolved, | unresolved, | ||||
) | ) | ||||
return format_git_object_from_parts("snapshot", lines) | return format_git_object_from_parts("snapshot", lines) | ||||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |
Could you add a new sentence in the docstring explaining the purpose of that parameter ?