module documentation

Git rerere (reuse recorded resolution) implementation.

This module implements Git's rerere functionality, which records and reuses manual conflict resolutions. When a merge conflict occurs, rerere records the conflict and the resolution. If the same conflict happens again, rerere can automatically apply the recorded resolution.

Class RerereCache Manages the rerere cache in .git/rr-cache/.
Function is_rerere_autoupdate Check if rerere.autoupdate is enabled in the config.
Function is_rerere_enabled Check if rerere is enabled in the config.
Function rerere_auto Automatically record conflicts and apply known resolutions.
Function _compute_conflict_id Compute a unique ID for a conflict based on its preimage.
Function _extract_conflict_regions Extract conflict regions from file content.
Function _has_conflict_markers Check if content contains conflict markers.
Function _normalize_conflict_markers Normalize conflict markers to a canonical form.
Function _remove_conflict_markers Remove all conflict markers from resolved content.
def is_rerere_autoupdate(config: StackedConfig) -> bool:

Check if rerere.autoupdate is enabled in the config.

Parameters
config:StackedConfigGit configuration
Returns
boolTrue if rerere.autoupdate is enabled
def is_rerere_enabled(config: StackedConfig) -> bool:

Check if rerere is enabled in the config.

Parameters
config:StackedConfigGit configuration
Returns
boolTrue if rerere is enabled
def rerere_auto(repo: Repo, working_tree_path: bytes | str, conflicts: list[bytes]) -> tuple[list[tuple[bytes, str]], list[bytes]]:

Automatically record conflicts and apply known resolutions.

This is the main entry point for rerere integration with merge operations. It should be called after a merge that resulted in conflicts.

Parameters
repo:RepoRepository object
working_tree_path:bytes | strPath to the working tree
conflicts:list[bytes]List of conflicted file paths
Returns
Tuple of
  • List of tuples (path, conflict_id) for recorded conflicts
  • List of paths where resolutions were automatically applied
def _compute_conflict_id(preimage: bytes) -> str:

Compute a unique ID for a conflict based on its preimage.

The preimage is the conflict with all conflict markers normalized to a canonical form (without side names).

Parameters
preimage:bytesThe normalized conflict content
Returns
strHex digest of the SHA-1 hash
def _extract_conflict_regions(content: bytes) -> list[tuple[bytes, bytes, bytes]]:

Extract conflict regions from file content.

Parameters
content:bytesFile content with conflict markers
Returns
list[tuple[bytes, bytes, bytes]]List of tuples (ours, separator, theirs) for each conflict region
def _has_conflict_markers(content: bytes) -> bool:

Check if content contains conflict markers.

Parameters
content:bytesFile content to check
Returns
boolTrue if conflict markers are present
def _normalize_conflict_markers(content: bytes) -> bytes:

Normalize conflict markers to a canonical form.

This removes the side names (ours/theirs) from conflict markers to create a preimage that only depends on the structure of the conflict.

Parameters
content:bytesFile content with conflict markers
Returns
bytesNormalized content with generic conflict markers
def _remove_conflict_markers(content: bytes) -> bytes:

Remove all conflict markers from resolved content.

This is used to extract the resolution from a file that has been manually resolved by the user.

Parameters
content:bytesResolved file content
Returns
bytesContent with conflict markers removed