Skip to main content

compute_patch_id

Function compute_patch_id 

Source
pub fn compute_patch_id(
    algo: HashAlgo,
    odb: &Odb,
    commit_oid: &ObjectId,
    mode: PatchIdMode,
) -> Result<Option<ObjectId>>
Expand description

Compute the patch-ID for a single commit.

Returns None for merge commits (more than one parent), since those do not have a well-defined single-parent diff. Root commits (no parents) are compared against the empty tree. Text diffs use the hunks of Git’s default diff (Myers with change-compact and the indent heuristic, three context lines on each side), so the ID matches git show --format= --no-ext-diff piped to git patch-id in the corresponding mode, including where an ambiguous insertion or deletion is placed. Unchanged lines outside those hunks do not contribute to the ID. A gitlink side is hashed as its Subproject commit <oid> line without reading the submodule commit, and a type change is hashed as a deletion followed by an addition.

§Parameters

  • algo — object hash algorithm (must match odb’s configured format).
  • odb — object database used to read commit, tree, and blob objects.
  • commit_oid — OID of the commit to compute the patch-ID for.
  • mode — accumulation and whitespace rules for the patch-ID.

§Errors

Returns errors from object-database reads or object-parse failures.

Text blobs that are not valid UTF-8 are still diffed (lossy decode), matching git diff and git patch-id on the same commit.