Skip to main content

choir_queue/
identity.rs

1//! Stable change identity across rebase: a change is
2//! identified by the hash of its position-independent content — the
3//! normalized diff from [`choir_merge::normalized_diff`] — so the same
4//! logical edit authored against different bases (before and after the
5//! train rewrote the tip under it) carries the same identity. The queue
6//! uses it to recognize a resubmission of an already-landed change and
7//! refuse it instead of re-merging or duplicating it.
8
9use choir_hash::ContentHash;
10
11use crate::Change;
12
13/// The change's stable identity: hex digest of its normalized diff.
14///
15/// Position-independent by construction — hunk offsets and context are
16/// stripped before hashing — and content-sensitive: any differing added
17/// or removed line is a different change.
18pub fn change_identity(change: &Change) -> String {
19    let normalized = choir_merge::normalized_diff(&change.base, &change.proposed);
20    ContentHash::blake3(normalized.as_bytes()).to_hex()
21}