git-ents.gitmain
⌘K
foforge
commit 36a2949
refactor: derive genesis keys through a shared git_store::new_id

The origin-or-content-hash rule lived as identical copies in issues and git-comment; one generic helper next to content_hash keeps the identity scheme from drifting between collections.

Assisted-by: Claude:claude-fable-5

Joseph D. Carpinelli · 1 month ago

Reviews

No reviews of this commit yet — record a verdict below.

Start a review

verdict

crates/git-comment/src/lib.rs @@ -50,10 +50,7 @@ /// comment derives from one, otherwise the hash of the comment's own initial /// content — every comment is a git object, so it always has one. pub fn new_id(origin: Option<&str>, content: &Comment) -> Result<String, git_store::Error> { - match origin { - Some(origin) => Ok(origin.to_owned()), - None => git_store::content_hash(content), - } + git_store::new_id(origin, content) } /// Load the comment recorded at `refs/meta/comments/<id>` in `repo`, or `None`
crates/git-ents/src/issues.rs @@ -87,10 +87,7 @@ /// provenance — otherwise the hash of the issue's own initial content, since /// every issue is a git object and so always has one. pub fn new_id(origin: Option<&str>, content: &Issue) -> Result<String, git_store::Error> { - match origin { - Some(origin) => Ok(origin.to_owned()), - None => git_store::content_hash(content), - } + git_store::new_id(origin, content) } /// Load the issue recorded at `refs/meta/issues/<id>` in `repo`, or `None` when
crates/git-store/src/lib.rs @@ -117,6 +117,18 @@ Ok(oid.to_string()) } +/// Derive a document's stable genesis key: `origin`'s object id (hex) when the +/// document derives from one — one origin, one document, deduplicated on +/// provenance — otherwise its own [`content_hash`], since every document is a +/// git object and so always has one. The key is computed once and never +/// renamed; cross-references key off it. +pub fn new_id<T: for<'a> Facet<'a>>(origin: Option<&str>, content: &T) -> Result<String, Error> { + match origin { + Some(origin) => Ok(origin.to_owned()), + None => content_hash(content), + } +} + /// A repository's typed `refs/meta/*` store. /// /// Refs are read and updated through the high-level [`gix`] API, while all