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 unified hunks with three context lines on each side, matching git show --format= --no-ext-diff -U3 piped to git patch-id in the corresponding mode. Unchanged lines outside those hunks do not contribute to the ID.

§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.